Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/extract_namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const outputFile = `${inputFile}.ts`;

const outputTerms = sortedTerms.map((i) => ` "${i}",`).join("\n");

const output = `import { createNamespace } from "ldkit";
const output = `import { createNamespace } from "ldkit/namespaces";

export default createNamespace(
{
Expand Down
2 changes: 1 addition & 1 deletion scripts/schema_to_package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function buildNamespacesFile(
extras: ExtraNamespace[],
termsByPrefix: Map<string, Set<string>>,
): string {
const lines: string[] = [`import { createNamespace } from "ldkit";`, ""];
const lines: string[] = [`import { createNamespace } from "ldkit/namespaces";`, ""];
const sorted = [...extras].sort((a, b) => a.prefix.localeCompare(b.prefix));
for (const ns of sorted) {
const terms = [...(termsByPrefix.get(ns.prefix) ?? new Set<string>())]
Expand Down
2 changes: 1 addition & 1 deletion scripts/schema_to_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class SchemaPrinter {
}

if (declaredExtras.length > 0) {
lines.push(`import { createNamespace } from "ldkit";`);
lines.push(`import { createNamespace } from "ldkit/namespaces";`);
}

if (this.usedNamespaces.size > 0) {
Expand Down
6 changes: 5 additions & 1 deletion scripts/shacl_to_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ class ShaclConverter {
}
}

return properties;
// Sort by key so re-runs against the same SHACL produce diff-free output.
// n3 Store quad iteration order is not guaranteed stable across parses.
return Object.fromEntries(
Object.entries(properties).toSorted(([a], [b]) => a.localeCompare(b)),
);
}

// SHACL conjoins multiple property shapes on the same path (AND). LDkit's
Expand Down
8 changes: 4 additions & 4 deletions tests/scripts/schema_to_script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Deno.test("Scripts / Schema To Script / Extra namespace emits createNamespace bl
];

const script = s`
import { createNamespace } from "ldkit";
import { createNamespace } from "ldkit/namespaces";
import { xsd } from "ldkit/namespaces";

export const ex = createNamespace(
Expand Down Expand Up @@ -378,7 +378,7 @@ Deno.test("Scripts / Schema To Script / Extra namespace bracket access for non-i
];

const script = s`
import { createNamespace } from "ldkit";
import { createNamespace } from "ldkit/namespaces";

export const ex = createNamespace(
{
Expand Down Expand Up @@ -419,7 +419,7 @@ Deno.test("Scripts / Schema To Script / Extra namespaces sorted by IRI length de
];

const script = s`
import { createNamespace } from "ldkit";
import { createNamespace } from "ldkit/namespaces";

export const exsub = createNamespace(
{
Expand Down Expand Up @@ -496,7 +496,7 @@ Deno.test("Scripts / Schema To Script / Extra namespace shadowing a built-in: bu
];

const script = s`
import { createNamespace } from "ldkit";
import { createNamespace } from "ldkit/namespaces";

export const schema = createNamespace(
{
Expand Down
22 changes: 22 additions & 0 deletions tests/scripts/shacl_to_schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,25 @@ ex:CustomerShape a sh:NodeShape ;
}
},
);

Deno.test(
"Scripts / SHACL to Schema / Properties emitted in deterministic (alphabetical) order regardless of source order",
() => {
// Re-running the codegen against the same SHACL input must produce zero
// diff. n3 Store quad iteration order is not guaranteed stable across
// parses, so we sort property keys before returning the schema spec.
const input = `${PREFIXES}
ex:ThingShape a sh:NodeShape ;
sh:targetClass ex:Thing ;
sh:property [ sh:path ex:zeta ; sh:datatype xsd:string ] ;
sh:property [ sh:path ex:alpha ; sh:datatype xsd:string ] ;
sh:property [ sh:path ex:mu ; sh:datatype xsd:integer ] ;
sh:property [ sh:path ex:beta ; sh:datatype xsd:string ] .
`;

const result = shaclToSchema(input);
const keys = Object.keys(result.schemas[0].properties);

assertEquals(keys, ["alpha", "beta", "mu", "zeta"]);
},
);
Loading