@canonical/design-system 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/PULL_REQUEST_TEMPLATE.md +13 -0
- package/.github/workflows/ci.yml +39 -0
- package/.mcp.json +1 -3
- package/biome.json +1 -1
- package/bun.lock +38 -35
- package/data/apps_launchpad/component/badge.ttl +2 -1
- package/data/apps_launchpad/component/button.ttl +2 -1
- package/data/apps_launchpad/component/combobox.ttl +2 -1
- package/data/apps_launchpad/component/text_input.ttl +2 -1
- package/data/apps_launchpad/component/tooltip.ttl +2 -1
- package/data/global/component/announcement.ttl +1 -1
- package/data/global/component/button.ttl +3 -1
- package/data/global/component/code_snippet.ttl +1 -1
- package/data/global/component/heading.ttl +3 -2
- package/data/global/component/tile.ttl +1 -1
- package/data/global/component/tooltip.ttl +38 -19
- package/data/global/pattern/dropdown_button.ttl +1 -1
- package/data/global/pattern/timeline.ttl +8 -4
- package/definitions/ontology.ttl +108 -161
- package/package.json +1 -1
- package/skills/anatomy-author/SKILL.md +5 -0
- package/skills/component-specifier/SKILL.md +5 -2
- package/skills/design-auditor/SKILL.md +5 -0
- package/source.json +7 -2
- package/src/cli.ts +33 -33
- package/src/collect/generateTurtle.tests.ts +181 -176
- package/src/collect/generateTurtle.ts +189 -138
- package/src/collect/index.ts +5 -2
- package/src/collect/scanAnnotations.tests.ts +116 -110
- package/src/collect/scanAnnotations.ts +35 -33
- package/src/collect/types.ts +34 -33
- package/src/collect/validateCollectConfig.tests.ts +135 -112
- package/src/collect/validateCollectConfig.ts +60 -54
- package/src/collect-implementations.ts +101 -88
- package/src/commands/extract.tests.ts +31 -32
- package/src/commands/extract.ts +29 -27
- package/src/commands/index.ts +1 -1
- package/src/commands/list.tests.ts +13 -14
- package/src/commands/list.ts +9 -9
- package/src/commands/transform.tests.ts +21 -21
- package/src/commands/transform.ts +118 -114
- package/src/config/types.ts +40 -40
- package/src/config/validateConfig.tests.ts +31 -31
- package/src/config/validateConfig.ts +9 -9
- package/src/constants.ts +7 -8
- package/src/graph/GraphStore.tests.ts +111 -111
- package/src/graph/GraphStore.ts +205 -189
- package/src/graph/PrefixMap.tests.ts +124 -122
- package/src/graph/PrefixMap.ts +77 -77
- package/src/graph/buildUri.tests.ts +116 -116
- package/src/graph/buildUri.ts +45 -45
- package/src/graph/index.ts +2 -2
- package/src/graph/types.ts +3 -3
- package/src/providers/CodaProvider.tests.ts +233 -233
- package/src/providers/CodaProvider.ts +145 -145
- package/src/providers/CodaProvider.types.generated.ts +12484 -12123
- package/src/providers/index.ts +13 -13
- package/src/serializers/JSONSerializer.tests.ts +64 -64
- package/src/serializers/JSONSerializer.ts +51 -51
- package/src/serializers/TTLSerializer.tests.ts +45 -45
- package/src/serializers/TTLSerializer.ts +64 -57
- package/src/serializers/index.ts +4 -1
- package/src/serializers/types.ts +3 -3
- package/src/transform/resolveReferences.tests.ts +47 -43
- package/src/transform/resolveReferences.ts +18 -18
- package/src/transform/resolveValue.tests.ts +55 -49
- package/src/transform/resolveValue.ts +48 -48
- package/src/transform/transform.tests.ts +90 -77
- package/src/transform/transform.ts +77 -77
- package/src/transform/transformRow.tests.ts +372 -356
- package/src/transform/transformRow.ts +222 -191
- package/src/transform/types.ts +4 -4
- package/tsconfig.json +2 -1
- package/.gemini/settings.json +0 -14
package/src/providers/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export { default as CodaProvider } from "./CodaProvider.js";
|
|
2
1
|
export type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
CodaCellValue,
|
|
3
|
+
CodaColumn,
|
|
4
|
+
CodaColumnList,
|
|
5
|
+
CodaRow,
|
|
6
|
+
CodaRowList,
|
|
7
|
+
// Generated Coda API types
|
|
8
|
+
CodaTable,
|
|
9
|
+
CodaTableList,
|
|
10
|
+
CodaTableReference,
|
|
11
|
+
ColumnMetadata,
|
|
12
|
+
TableMetadata,
|
|
13
|
+
TableRow,
|
|
15
14
|
} from "./CodaProvider.js";
|
|
15
|
+
export { default as CodaProvider } from "./CodaProvider.js";
|
|
16
16
|
|
|
17
17
|
// Re-export full generated types for advanced usage
|
|
18
18
|
export type * from "./CodaProvider.types.generated.js";
|
|
@@ -9,68 +9,68 @@ const inputUri = `${NAMESPACES.ds}global.component.input`;
|
|
|
9
9
|
const componentType = `${NAMESPACES.ds}Component`;
|
|
10
10
|
|
|
11
11
|
describe("serializeToJsonLd", () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
12
|
+
it("should serialize a single subject to JSON-LD with compact URIs", async () => {
|
|
13
|
+
const store = new GraphStore();
|
|
14
|
+
store.addQuad(buttonUri, PREDICATES.type, componentType);
|
|
15
|
+
store.addLiteral(buttonUri, PREDICATES.name, "Button");
|
|
16
|
+
|
|
17
|
+
const prefixes = new PrefixMap();
|
|
18
|
+
prefixes.add("ds", NAMESPACES.ds);
|
|
19
|
+
|
|
20
|
+
const doc = await serializeToJsonLd(store, {
|
|
21
|
+
prefixes,
|
|
22
|
+
subject: buttonUri,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// JSON-LD compact uses prefixed URIs
|
|
26
|
+
expect(doc["@id"]).toBe("ds:global.component.button");
|
|
27
|
+
// @type can be a string or array in JSON-LD
|
|
28
|
+
const type = doc["@type"];
|
|
29
|
+
expect(Array.isArray(type) ? type[0] : type).toBe("ds:Component");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should include context from prefixes", async () => {
|
|
33
|
+
const store = new GraphStore();
|
|
34
|
+
store.addLiteral(buttonUri, PREDICATES.name, "Button");
|
|
35
|
+
|
|
36
|
+
const prefixes = new PrefixMap();
|
|
37
|
+
prefixes.add("ds", NAMESPACES.ds);
|
|
38
|
+
|
|
39
|
+
const doc = await serializeToJsonLd(store, {
|
|
40
|
+
prefixes,
|
|
41
|
+
subject: buttonUri,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(doc["@context"]).toBeDefined();
|
|
45
|
+
expect((doc["@context"] as Record<string, string>).ds).toBe(NAMESPACES.ds);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should return empty object for unknown subject", async () => {
|
|
49
|
+
const store = new GraphStore();
|
|
50
|
+
store.addLiteral(buttonUri, PREDICATES.name, "Button");
|
|
51
|
+
|
|
52
|
+
const prefixes = new PrefixMap();
|
|
53
|
+
const unknownUri = `${NAMESPACES.ds}global.component.unknown`;
|
|
54
|
+
|
|
55
|
+
const doc = await serializeToJsonLd(store, {
|
|
56
|
+
prefixes,
|
|
57
|
+
subject: unknownUri,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Unknown subject returns full URI since no data to compact
|
|
61
|
+
expect(doc["@id"]).toBe(unknownUri);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should serialize all subjects when no subject specified", async () => {
|
|
65
|
+
const store = new GraphStore();
|
|
66
|
+
store.addLiteral(buttonUri, PREDICATES.name, "Button");
|
|
67
|
+
store.addLiteral(inputUri, PREDICATES.name, "Input");
|
|
68
|
+
|
|
69
|
+
const prefixes = new PrefixMap();
|
|
70
|
+
prefixes.add("ds", NAMESPACES.ds);
|
|
71
|
+
|
|
72
|
+
const docs = await serializeToJsonLd(store, { prefixes });
|
|
73
|
+
|
|
74
|
+
expect(Array.isArray(docs) || docs["@graph"]).toBeTruthy();
|
|
75
|
+
});
|
|
76
76
|
});
|
|
@@ -6,8 +6,8 @@ import type { GraphStore, PrefixMap } from "../graph/index.js";
|
|
|
6
6
|
* Options for JSON-LD serialization
|
|
7
7
|
*/
|
|
8
8
|
export interface JsonLdSerializeOptions {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
prefixes: PrefixMap;
|
|
10
|
+
subject?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -17,71 +17,71 @@ export interface JsonLdSerializeOptions {
|
|
|
17
17
|
* Otherwise, returns all subjects as a graph.
|
|
18
18
|
*/
|
|
19
19
|
export default async function serializeToJsonLd(
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
store: GraphStore,
|
|
21
|
+
options: JsonLdSerializeOptions,
|
|
22
22
|
): Promise<Record<string, unknown>> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const quads = options.subject
|
|
24
|
+
? store.getQuadsForSubject(options.subject)
|
|
25
|
+
: store.getQuads();
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
// Convert quads to N-Quads string format for jsonld.fromRDF
|
|
28
|
+
const nquads = await quadsToNQuads(quads);
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
if (!nquads.trim()) {
|
|
31
|
+
// No quads found, return minimal document
|
|
32
|
+
const context = options.prefixes.toRecord();
|
|
33
|
+
return {
|
|
34
|
+
"@context": context,
|
|
35
|
+
"@id": options.subject || "",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
// Convert N-Quads to JSON-LD
|
|
40
|
+
const jsonldDoc = await jsonld.fromRDF(nquads, {
|
|
41
|
+
format: "application/n-quads",
|
|
42
|
+
});
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
// Build context from prefixes
|
|
45
|
+
const context = options.prefixes.toRecord();
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
// Frame the document to embed blank nodes inline
|
|
48
|
+
if (options.subject) {
|
|
49
|
+
const framed = await jsonld.frame(jsonldDoc, {
|
|
50
|
+
"@context": context,
|
|
51
|
+
"@id": options.subject,
|
|
52
|
+
"@embed": "@always",
|
|
53
|
+
});
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
// Compact to use prefixed URIs
|
|
56
|
+
const compacted = await jsonld.compact(framed, context);
|
|
57
|
+
return compacted as Record<string, unknown>;
|
|
58
|
+
}
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
// Compact the full document
|
|
61
|
+
const compacted = await jsonld.compact(
|
|
62
|
+
{ "@context": context, "@graph": jsonldDoc },
|
|
63
|
+
context,
|
|
64
|
+
);
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
return compacted as Record<string, unknown>;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Convert n3 quads to N-Quads string format
|
|
71
71
|
*/
|
|
72
72
|
function quadsToNQuads(
|
|
73
|
-
|
|
73
|
+
quads: ReturnType<GraphStore["getQuads"]>,
|
|
74
74
|
): Promise<string> {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
const writer = new Writer({ format: "N-Quads" });
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
for (const quad of quads) {
|
|
79
|
+
writer.addQuad(quad);
|
|
80
|
+
}
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
writer.end((error, result) => {
|
|
83
|
+
if (error) reject(error);
|
|
84
|
+
else resolve(result);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
87
|
}
|
|
@@ -8,66 +8,66 @@ const globalUri = `${NAMESPACES.ds}global`;
|
|
|
8
8
|
const componentType = `${NAMESPACES.ds}Component`;
|
|
9
9
|
|
|
10
10
|
function createPrefixMap(): PrefixMap {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const prefixes = new PrefixMap();
|
|
12
|
+
prefixes.add("ds", NAMESPACES.ds);
|
|
13
|
+
prefixes.add("rdf", NAMESPACES.rdf);
|
|
14
|
+
return prefixes;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
describe("serializeToTurtle", () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
it("should serialize empty store", async () => {
|
|
19
|
+
const store = new GraphStore();
|
|
20
|
+
const prefixes = new PrefixMap();
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const ttl = await serializeToTurtle(store, { prefixes });
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
expect(ttl).toBe("");
|
|
25
|
+
});
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
it("should include prefix declarations", async () => {
|
|
28
|
+
const store = new GraphStore();
|
|
29
|
+
store.addQuad(buttonUri, PREDICATES.type, componentType);
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const prefixes = createPrefixMap();
|
|
32
|
+
const ttl = await serializeToTurtle(store, { prefixes });
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
expect(ttl).toContain("@prefix ds:");
|
|
35
|
+
expect(ttl).toContain("@prefix rdf:");
|
|
36
|
+
});
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
it("should serialize quads with URI objects", async () => {
|
|
39
|
+
const store = new GraphStore();
|
|
40
|
+
store.addQuad(buttonUri, PREDICATES.type, componentType);
|
|
41
|
+
store.addQuad(buttonUri, PREDICATES.tier, globalUri);
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const prefixes = createPrefixMap();
|
|
44
|
+
const ttl = await serializeToTurtle(store, { prefixes });
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
expect(ttl).toContain("ds:button");
|
|
47
|
+
// n3 uses 'a' shorthand for rdf:type in Turtle
|
|
48
|
+
expect(ttl).toMatch(/a |rdf:type/);
|
|
49
|
+
expect(ttl).toContain("ds:Component");
|
|
50
|
+
});
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
it("should serialize quads with literal objects", async () => {
|
|
53
|
+
const store = new GraphStore();
|
|
54
|
+
store.addLiteral(buttonUri, PREDICATES.name, "Button");
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
const prefixes = createPrefixMap();
|
|
57
|
+
const ttl = await serializeToTurtle(store, { prefixes });
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
expect(ttl).toContain('"Button"');
|
|
60
|
+
});
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
it("should group statements by subject with semicolons", async () => {
|
|
63
|
+
const store = new GraphStore();
|
|
64
|
+
store.addQuad(buttonUri, PREDICATES.type, componentType);
|
|
65
|
+
store.addLiteral(buttonUri, PREDICATES.name, "Button");
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const prefixes = createPrefixMap();
|
|
68
|
+
const ttl = await serializeToTurtle(store, { prefixes });
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
// n3 Writer groups by subject and uses semicolons
|
|
71
|
+
expect(ttl).toContain(";");
|
|
72
|
+
});
|
|
73
73
|
});
|
|
@@ -7,17 +7,17 @@ import type { SerializeOptions } from "./types.js";
|
|
|
7
7
|
* Handles URIs with slashes that n3 won't auto-compact
|
|
8
8
|
*/
|
|
9
9
|
function compactUris(turtle: string, prefixes: Record<string, string>): string {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
let result = turtle;
|
|
11
|
+
for (const [prefix, namespace] of Object.entries(prefixes)) {
|
|
12
|
+
// Replace <namespace...> with prefix:...
|
|
13
|
+
const regex = new RegExp(`<${escapeRegex(namespace)}([^>]+)>`, "g");
|
|
14
|
+
result = result.replace(regex, `${prefix}:$1`);
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function escapeRegex(str: string): string {
|
|
20
|
-
|
|
20
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -26,35 +26,42 @@ function escapeRegex(str: string): string {
|
|
|
26
26
|
* Into: `ds:hasProperty [ a ds:Property; ... ]`
|
|
27
27
|
*/
|
|
28
28
|
function inlineBlankNodes(turtle: string): string {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
// Find all blank node definitions (blocks starting with _:... and ending with .)
|
|
30
|
+
// Pattern matches: _:id followed by content until a line ending with just "."
|
|
31
|
+
const bnPattern = /^(_:[\w-]+)\s+([\s\S]*?)\.\n/gm;
|
|
32
|
+
const blankNodes = new Map<string, string>();
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
let match: RegExpExecArray | null = bnPattern.exec(turtle);
|
|
35
|
+
while (match !== null) {
|
|
36
|
+
const bnId = match[1];
|
|
37
|
+
const content = match[2].trim();
|
|
38
|
+
// Format for inline: wrap in brackets with proper indentation
|
|
39
|
+
const indentedContent = content.replace(/\n\s+/g, "\n ");
|
|
40
|
+
blankNodes.set(bnId, `[\n ${indentedContent}\n ]`);
|
|
41
|
+
match = bnPattern.exec(turtle);
|
|
42
|
+
}
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
if (blankNodes.size === 0) {
|
|
45
|
+
return turtle;
|
|
46
|
+
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
let result = turtle;
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
// Replace references to blank nodes with inline syntax
|
|
51
|
+
for (const [bnId, inlineContent] of blankNodes) {
|
|
52
|
+
// Replace references like "_:n3-0" or "_:n3-0," or "_:n3-0."
|
|
53
|
+
result = result.replace(
|
|
54
|
+
new RegExp(`${escapeRegex(bnId)}([,.;])`, "g"),
|
|
55
|
+
`${inlineContent}$1`,
|
|
56
|
+
);
|
|
57
|
+
// Remove the standalone blank node definition block
|
|
58
|
+
result = result.replace(
|
|
59
|
+
new RegExp(`^${escapeRegex(bnId)}\\s+[\\s\\S]*?\\.\n`, "gm"),
|
|
60
|
+
"",
|
|
61
|
+
);
|
|
62
|
+
}
|
|
56
63
|
|
|
57
|
-
|
|
64
|
+
return `${result.trim()}\n`;
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
/**
|
|
@@ -66,34 +73,34 @@ function inlineBlankNodes(turtle: string): string {
|
|
|
66
73
|
* - Proper indentation
|
|
67
74
|
*/
|
|
68
75
|
export default function serializeToTurtle(
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
store: GraphStore,
|
|
77
|
+
options: SerializeOptions,
|
|
71
78
|
): Promise<string> {
|
|
72
|
-
|
|
73
|
-
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
const quads = store.getQuads();
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
if (quads.length === 0) {
|
|
83
|
+
resolve("");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
79
86
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
const writer = new Writer({
|
|
88
|
+
prefixes: options.prefixes.toRecord(),
|
|
89
|
+
});
|
|
83
90
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
for (const quad of quads) {
|
|
92
|
+
writer.addQuad(quad);
|
|
93
|
+
}
|
|
87
94
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
writer.end((error, result) => {
|
|
96
|
+
if (error) {
|
|
97
|
+
reject(error);
|
|
98
|
+
} else {
|
|
99
|
+
// Post-process: compact URIs and inline blank nodes
|
|
100
|
+
let processed = compactUris(result, options.prefixes.toRecord());
|
|
101
|
+
processed = inlineBlankNodes(processed);
|
|
102
|
+
resolve(processed);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
99
106
|
}
|
package/src/serializers/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export {
|
|
2
|
+
default as serializeToJsonLd,
|
|
3
|
+
type JsonLdSerializeOptions,
|
|
4
|
+
} from "./JSONSerializer.js";
|
|
1
5
|
export { default as serializeToTurtle } from "./TTLSerializer.js";
|
|
2
|
-
export { default as serializeToJsonLd, type JsonLdSerializeOptions } from "./JSONSerializer.js";
|
|
3
6
|
export type { SerializeOptions, Serializer } from "./types.js";
|
package/src/serializers/types.ts
CHANGED
|
@@ -4,13 +4,13 @@ import type { GraphStore, PrefixMap } from "../graph/index.js";
|
|
|
4
4
|
* Options for serialization
|
|
5
5
|
*/
|
|
6
6
|
export interface SerializeOptions {
|
|
7
|
-
|
|
7
|
+
prefixes: PrefixMap;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Serializer function type
|
|
12
12
|
*/
|
|
13
13
|
export type Serializer = (
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
store: GraphStore,
|
|
15
|
+
options: SerializeOptions,
|
|
16
16
|
) => Promise<string>;
|