Skip to content

Commit e34eea7

Browse files
author
Daniel Beeke
committed
expose parsed prefixes
1 parent 13bb9d7 commit e34eea7

3 files changed

Lines changed: 6 additions & 1 deletion

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.13",
3+
"version": "0.1.14",
44
"license": "MIT",
55
"exports": "./lib/LocalStore.ts"
66
}

lib/LocalStore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type LocalStoreOptions = {
1818
* Each of these files can have relative IRIs such as <> or <#lorem> or </ipsum>.
1919
*/
2020
export class LocalStore implements Source, RdfJsStore {
21+
public prefixes: Record<string, string> = {}
2122
#directoryHandle?: FileSystemDirectoryHandle
2223
#baseUri: URL
2324
#cache: Store = new Store()
@@ -354,6 +355,9 @@ export class LocalStore implements Source, RdfJsStore {
354355
const contents = await (await fileHandle.getFile()).text()
355356
const strippedContents = contents.replace(/<(.|\/)(.*)\.ttl(.*)>/g, '<$1$2>')
356357
const quads = await parser.parse(strippedContents)
358+
/** @ts-expect-error an internal property of the parser */
359+
const prefixes = parser._prefixes
360+
this.prefixes = { ...this.prefixes, ...prefixes }
357361
this.#cache.addQuads(quads.map(quad => factory.quad(quad.subject, quad.predicate, quad.object, graph)))
358362
} catch (error: any) {
359363
throw new Error(`Error while parsing graph ${graph.value}:` + error.message)

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,5 @@ document.querySelector('#query-2')?.addEventListener('click', async () => {
9191
for (const binding of bindings) {
9292
console.log(binding.get('g'))
9393
}
94+
console.log(store.prefixes)
9495
})

0 commit comments

Comments
 (0)