@vertekum/schema-builder 0.3.11 → 0.3.12

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @vertekum/schema-builder
2
2
 
3
+ ## 0.3.12
4
+
5
+ ### Patch Changes
6
+
7
+ - [`bcb1f46`](https://github.com/moros-oxus/vertekum/commit/bcb1f46b9491f24560d88d7a1b416bd13dd553a4) Thanks [@tschemmer](https://github.com/tschemmer)! - A configured schema that compiles but crashes during validation (a ref cycle, a validator too large for the stack) now surfaces as a `schema/invalid-schema` diagnostic naming the binding and file instead of taking every command down — so `schema build` can always regenerate a broken artifact. The builder's emit dedupe also hoists subtrees repeated as a single shared object reference, which previously escaped structural sharing entirely.
8
+ - Updated dependencies [[`bcb1f46`](https://github.com/moros-oxus/vertekum/commit/bcb1f46b9491f24560d88d7a1b416bd13dd553a4)]:
9
+ - @vertekum/core@0.3.12
10
+
3
11
  ## 0.3.11
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertekum/schema-builder",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "description": "Declare token vocabularies as grammar; build them into JSON Schema files",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -37,13 +37,13 @@
37
37
  "./cli": "./src/cli.ts"
38
38
  },
39
39
  "peerDependencies": {
40
- "@vertekum/core": "0.3.11"
40
+ "@vertekum/core": "0.3.12"
41
41
  },
42
42
  "dependencies": {
43
43
  "zod": "^3.25.76"
44
44
  },
45
45
  "devDependencies": {
46
- "@vertekum/core": "0.3.11",
46
+ "@vertekum/core": "0.3.12",
47
47
  "@vertekum/schema-vocabulary": "0.3.0"
48
48
  }
49
49
  }
package/src/dedupe.ts CHANGED
@@ -84,11 +84,35 @@ function visitChildren(
84
84
  }
85
85
  }
86
86
 
87
+ /**
88
+ * Break object-identity sharing: a subtree reachable from two schema positions as the SAME
89
+ * reference serializes twice but signs once (the memo is identity-keyed), so it would land in
90
+ * a bucket of one and never hoist. Copying the re-encountered node makes every position a
91
+ * distinct object, after which occurrence counting is simply object counting.
92
+ */
93
+ function unshare(document: Json): void {
94
+ const seen = new Set<Json>();
95
+ const walk = (node: Json): void => {
96
+ visitChildren(node, (child, replace) => {
97
+ if (seen.has(child)) {
98
+ const copy = JSON.parse(JSON.stringify(child)) as Json;
99
+ replace(copy);
100
+ walk(copy);
101
+ return;
102
+ }
103
+ seen.add(child);
104
+ walk(child);
105
+ });
106
+ };
107
+ walk(document);
108
+ }
109
+
87
110
  /**
88
111
  * Hoist repeated subtrees of `document` into its `$defs`, in place. Iterates to a fixpoint:
89
112
  * hoisting inner duplicates makes outer subtrees identical, which the next round catches.
90
113
  */
91
114
  export function dedupeSubtrees(document: Json): void {
115
+ unshare(document);
92
116
  const defs = (): Json => {
93
117
  if (!document.$defs || typeof document.$defs !== 'object') {
94
118
  document.$defs = {};