From a522b2d119cfc6ef14abe0f9ed82f50528117a43 Mon Sep 17 00:00:00 2001 From: josip-marketer Date: Tue, 12 May 2026 13:13:30 +0200 Subject: [PATCH 1/3] fix(shacl-to-script): emit createNamespace import from ldkit/namespaces --- scripts/extract_namespace.ts | 2 +- scripts/schema_to_script.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/extract_namespace.ts b/scripts/extract_namespace.ts index 0e6e9b3..ce88c8d 100644 --- a/scripts/extract_namespace.ts +++ b/scripts/extract_namespace.ts @@ -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( { diff --git a/scripts/schema_to_script.ts b/scripts/schema_to_script.ts index dfda53b..03168f4 100644 --- a/scripts/schema_to_script.ts +++ b/scripts/schema_to_script.ts @@ -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) { From c55cacef8e8307f3cc77bf0c0679183b331e4b37 Mon Sep 17 00:00:00 2001 From: renan m Date: Wed, 13 May 2026 08:04:37 -0300 Subject: [PATCH 2/3] fix: complete workerd-friendly createNamespace import sweep --- scripts/schema_to_package.ts | 2 +- tests/scripts/schema_to_script.test.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/schema_to_package.ts b/scripts/schema_to_package.ts index b2de65b..7602034 100644 --- a/scripts/schema_to_package.ts +++ b/scripts/schema_to_package.ts @@ -76,7 +76,7 @@ function buildNamespacesFile( extras: ExtraNamespace[], termsByPrefix: Map>, ): 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())] diff --git a/tests/scripts/schema_to_script.test.ts b/tests/scripts/schema_to_script.test.ts index a163db1..a3bf3fb 100644 --- a/tests/scripts/schema_to_script.test.ts +++ b/tests/scripts/schema_to_script.test.ts @@ -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( @@ -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( { @@ -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( { @@ -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( { From c336d8786ca759b3383687cb16c19876ea9481f3 Mon Sep 17 00:00:00 2001 From: renan m Date: Wed, 13 May 2026 08:04:46 -0300 Subject: [PATCH 3/3] fix: deterministic property order in SHACL-generated schemas --- scripts/shacl_to_schema.ts | 6 +++++- tests/scripts/shacl_to_schema.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/scripts/shacl_to_schema.ts b/scripts/shacl_to_schema.ts index 1d266c2..35386cb 100644 --- a/scripts/shacl_to_schema.ts +++ b/scripts/shacl_to_schema.ts @@ -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 diff --git a/tests/scripts/shacl_to_schema.test.ts b/tests/scripts/shacl_to_schema.test.ts index 0e7d9bd..74568c2 100644 --- a/tests/scripts/shacl_to_schema.test.ts +++ b/tests/scripts/shacl_to_schema.test.ts @@ -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"]); + }, +);