Skip to content

Commit 6c8dde5

Browse files
author
Daniel Beeke
committed
rewrite
1 parent ccad8d2 commit 6c8dde5

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shapething/localstore",
3-
"version": "0.1.10",
3+
"version": "0.1.11",
44
"license": "MIT",
55
"exports": "./lib/LocalStore.ts"
66
}

lib/LocalStore.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ export class LocalStore implements Source, RdfJsStore {
273273
for await (const graph of graphIterator) {
274274
if (hasEnded) return
275275
graphIterations++
276-
277276
if (!this.#graphIsCached(graph)) await this.#cacheGraph(graph)
278277
const graphStream = this.#cache.match(
279278
/** @ts-ignore */
@@ -319,7 +318,7 @@ export class LocalStore implements Source, RdfJsStore {
319318
*/
320319
#graphIsCached(graph: NamedNode | DefaultGraph) {
321320
/** @ts-expect-error we are using N3s internal API */
322-
return this.#cache._termToNumericId(graph) !== undefined
321+
return this.#cache._graphs[this.#cache._termToNumericId(graph)] !== undefined
323322
}
324323

325324
/**
@@ -345,11 +344,15 @@ export class LocalStore implements Source, RdfJsStore {
345344
* The actual function that parses a file on disk and puts it into the N3 store.
346345
*/
347346
async #parseAndStoreGraph(graph: NamedNode | DefaultGraph, fileHandle: FileSystemFileHandle) {
348-
const parser = new Parser({ baseIRI: graph.value })
349-
const contents = await (await fileHandle.getFile()).text()
350-
const strippedContents = contents.replace(/\<([a-z.\/#]*)\.ttl([a-z.\/#]*)\>/g, '<$1$2>')
351-
const quads = await parser.parse(strippedContents)
352-
this.#cache.addQuads(quads.map(quad => factory.quad(quad.subject, quad.predicate, quad.object, graph)))
347+
try {
348+
const parser = new Parser({ baseIRI: graph.value })
349+
const contents = await (await fileHandle.getFile()).text()
350+
const strippedContents = contents.replace(/<(.|\/)(.*)\.ttl(.*)>/g, '<$1$2>')
351+
const quads = await parser.parse(strippedContents)
352+
this.#cache.addQuads(quads.map(quad => factory.quad(quad.subject, quad.predicate, quad.object, graph)))
353+
} catch (error: any) {
354+
throw new Error(`Error while parsing graph ${graph.value}:` + error.message)
355+
}
353356
}
354357

355358
/**

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ document.querySelector('#query-2')?.addEventListener('click', async () => {
8787
})
8888

8989
const bindings = await bindingStream.toArray()
90+
console.log(bindings.length)
9091
for (const binding of bindings) {
9192
console.log(binding.get('g'))
9293
}

0 commit comments

Comments
 (0)