@texaryn/schema-json 0.7.0 → 0.8.0

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +33 -1
  3. package/THIRD-PARTY-NOTICES.md +7 -0
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +479 -24
  6. package/dist/adapter.js.map +1 -1
  7. package/dist/bare-maps.d.ts +3 -0
  8. package/dist/bare-maps.d.ts.map +1 -0
  9. package/dist/bare-maps.js +44 -0
  10. package/dist/bare-maps.js.map +1 -0
  11. package/dist/identity.d.ts +11 -2
  12. package/dist/identity.d.ts.map +1 -1
  13. package/dist/identity.js +103 -22
  14. package/dist/identity.js.map +1 -1
  15. package/dist/index.d.ts +4 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/instance-pointer.d.ts +9 -0
  20. package/dist/instance-pointer.d.ts.map +1 -0
  21. package/dist/instance-pointer.js +115 -0
  22. package/dist/instance-pointer.js.map +1 -0
  23. package/dist/local-pointer-aliases.d.ts +4 -0
  24. package/dist/local-pointer-aliases.d.ts.map +1 -0
  25. package/dist/local-pointer-aliases.js +345 -0
  26. package/dist/local-pointer-aliases.js.map +1 -0
  27. package/dist/normalize.d.ts +1 -1
  28. package/dist/normalize.d.ts.map +1 -1
  29. package/dist/normalize.js +3 -1
  30. package/dist/normalize.js.map +1 -1
  31. package/dist/projection-shape.d.ts +25 -0
  32. package/dist/projection-shape.d.ts.map +1 -0
  33. package/dist/projection-shape.js +74 -0
  34. package/dist/projection-shape.js.map +1 -0
  35. package/dist/projection-validation-coherence.d.ts +11 -0
  36. package/dist/projection-validation-coherence.d.ts.map +1 -0
  37. package/dist/projection-validation-coherence.js +213 -0
  38. package/dist/projection-validation-coherence.js.map +1 -0
  39. package/dist/projection.d.ts +2 -2
  40. package/dist/projection.d.ts.map +1 -1
  41. package/dist/projection.js +922 -243
  42. package/dist/projection.js.map +1 -1
  43. package/dist/resources.d.ts +19 -0
  44. package/dist/resources.d.ts.map +1 -0
  45. package/dist/resources.js +730 -0
  46. package/dist/resources.js.map +1 -0
  47. package/dist/root-reference.js +1 -1
  48. package/dist/schema-graph.d.ts +7 -0
  49. package/dist/schema-graph.d.ts.map +1 -1
  50. package/dist/schema-graph.js +79 -20
  51. package/dist/schema-graph.js.map +1 -1
  52. package/dist/submission-projection.d.ts +5 -0
  53. package/dist/submission-projection.d.ts.map +1 -0
  54. package/dist/submission-projection.js +233 -0
  55. package/dist/submission-projection.js.map +1 -0
  56. package/dist/types.d.ts +6 -1
  57. package/dist/types.d.ts.map +1 -1
  58. package/dist/vendor/json-schema-library/LICENSE.md +9 -0
  59. package/dist/vendor/json-schema-library/index.mjs +2 -0
  60. package/dist/vendor/json-schema-library/index.mjs.map +1 -0
  61. package/package.json +9 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @texaryn/schema-json
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8605d64: Adds opt-in projected submissions and rejects reference scope collisions that give validation and projection different assertions. The runtime validates and submits the same independent snapshot while retaining live form data.
8
+ - 82f38e9: Add explicit view expansion for recursion and budget boundaries.
9
+ - 8605d64: Adds host supplied external schema resolution with a configurable resource limit.
10
+ - 82f38e9: Adds opt in dynamic scope projection for supported local references and host supplied external resources.
11
+
12
+ ### Patch Changes
13
+
14
+ - 1adb31d: Patches dependent schema reduction and includes the fixed runtime in published adapter builds, so invalid `oneOf` dependencies remain projectable for installed consumers.
15
+ - 8605d64: Corrects projection through `allOf` references and applies dialect-specific defaults beside `$ref`.
16
+ - 8605d64: Preserves inherited dialects and Draft 7 identifiers when compiling retrieved schemas.
17
+ - 6f6bd70: Projects fields from retained inactive conditional branches and keeps them aligned with Hyperjump.
18
+ - 8605d64: Projects fields from the selected Draft 7 `then` or `else` reference.
19
+ - 82f38e9: Reuse static property candidates across data projections and skip reductions that cannot change an object's projected shape.
20
+ - 82f38e9: Avoid repeated branch validation for missing values during a single schema projection.
21
+ - 8605d64: Projects existing and required fields governed by `additionalProperties`.
22
+ - Updated dependencies [8605d64]
23
+ - Updated dependencies [82f38e9]
24
+ - Updated dependencies [8605d64]
25
+ - @texaryn/core@0.14.0
26
+
27
+ ## 0.7.1
28
+
29
+ ### Patch Changes
30
+
31
+ - 3af1cf7: Projecting a schema whose `items` is the boolean `false` no longer throws in 2020-12. A tuple closed with `prefixItems` and `items: false` projects as an array.
32
+ - d959520: Validation and projection no longer throw for a data key named like an `Object.prototype` member, such as `__proto__`, `constructor` or `toString`. The key is validated like any other key.
33
+ - eab920a: Validation errors report RFC 6901 pointers for property names that contain `/` or `~`. A missing required field named `a/b` is reported at `/a~1b`, so `validateAt` and the association of an error with its field find it.
34
+
3
35
  ## 0.7.0
4
36
 
5
37
  ### Minor Changes
package/README.md CHANGED
@@ -85,6 +85,7 @@ The adapter currently handles the schema features required by Texaryn's runtime
85
85
  - arrays
86
86
  - enums
87
87
  - local `$ref`, including recursive references
88
+ - opt-in dynamic scope projection for supported `$dynamicRef` and `$recursiveRef` paths
88
89
  - `if` / `then` / `else`
89
90
  - `oneOf`
90
91
  - `anyOf`
@@ -101,13 +102,32 @@ A local `$ref` may point back to a schema that contains it, such as `{ propertie
101
102
 
102
103
  `boundaries` on an object's `NodeProjection` says why the projection withheld something beneath it: `recursion` when a descendant would repeat the object's schemas, `budget` when a fixed per-projection limit withheld members. The limits are 16 objects and 512 nodes, counted only over locations that exist because of the recursion, two or more levels below the data; they never cut a member of a location that holds data. A node the projection reached only by expanding the recursion carries `recursiveExpansion`, and `schema-defaults` initialization never writes there.
103
104
 
105
+ `boundaryTargets` has the next withheld instance pointer for each boundary reason, with a generation scoped token. Pass selected tokens to `project(data, { expandedBoundaryTokens })` to reveal those locations. The runtime also supplies `boundaryGeneration`; direct adapter callers can leave it at zero or increment it whenever replacing a container changes pointer ownership. Each token admits one target. The built in renderers show one action per boundary reason on an object and advance one target per click, so a large budget boundary does not create a button for every withheld field. Expansion changes the view only. It does not write form data, affect validation, or change initialization. React, React Bootstrap, React MUI, Vue, and Web Components provide these actions by default.
106
+
104
107
  A schema that applies itself at one instance location without crossing into a property or item, such as `{ allOf: [{ $ref: '#' }] }`, makes the evaluator recurse without end, so `createJsonSchemaAdapter` rejects it with `SameLocationCycleError`. Its `positions` field lists the schema positions of each cycle, and the message names one of them and the path through the cycle. The check reads the schema, not the data: a cycle behind an `if` is rejected even while the `if` does not hold, except the branches the specification never evaluates. It is conservative for dynamic references, treating a `$dynamicRef` to a `$dynamicAnchor` as reaching every `$dynamicAnchor` of that name and a `$recursiveRef` as reaching every schema that declares `$recursiveAnchor: true`, so a schema whose dynamic references could close such a cycle is rejected even when no evaluation selects it.
105
108
 
106
109
  The [JSON Schema support guide](https://texaryn.github.io/texaryn/guides/json-schema-support/#recursive-references) has the details, and ADR-007 records the decision.
107
110
 
111
+ ## Dynamic reference projection
112
+
113
+ Dynamic scope aware form projection is opt in with `dynamicReferenceProjection: 'local'`. It supports Draft 2020-12 `$dynamicRef` and Draft 2019-09 `$recursiveRef: '#'` under object properties or homogeneous array items, including references reached through `allOf`, `anyOf`, `oneOf`, conditionals and `dependentSchemas`.
114
+
115
+ External dynamic references use the host supplied `resolveResource` callback. The adapter does not fetch schemas. Without the option, the projector does not follow the active dynamic scope. The option rejects references below unsupported applicators and array keywords, root relative resource identifiers, and unsupported reference siblings. See [ADR-010](../../docs/adr/010-local-dynamic-reference-projection.md) for the exact boundaries.
116
+
117
+ ```ts
118
+ const adapter = await createJsonSchemaAdapter(schema, {
119
+ dynamicReferenceProjection: 'local',
120
+ resolveResource: (uri) => schemaResources.get(uri),
121
+ })
122
+ ```
123
+
124
+ Adapter creation also rejects a retained static `$ref` when json-schema-library resolves it to different declarations with different validation assertions in the validation tree and the normalised projection tree. The check covers the dialect's supported assertions, including boolean subschemas. The error is `ProjectionValidationDivergenceError`.
125
+
126
+ The adapter exposes `projectSubmission(data)` for supported schemas. It removes values declared only by inactive branches, keeps provisional fields, and preserves undeclared data so validation can still reject it. This opt-in treats an inactive declaration as form data to omit even when an enclosing object allows additional properties. `createFormRuntime` selects the mode with `submission: 'projected'`; it validates and submits the same independent snapshot, while the form's live data stays unchanged. Schemas with dynamic references or `unevaluatedProperties` or `unevaluatedItems` do not expose this capability yet. The private Hyperjump adapter also does not expose it. Runtime creation fails if projected submission is requested without the capability.
127
+
108
128
  ## json-schema-library version
109
129
 
110
- The dependency range is `~11.6.2`. In Draft 7, json-schema-library 11.6.2 overwrites the registry entry that `"$ref": "#"` resolves through, so without a fix the reference reaches another node and validation is wrong. The adapter pins that entry to the document root, and every other entry the library files for its own location to the node compiled there, so a reduction during projection cannot replace a definition with a reduced copy. Because the fix depends on the library's internal registry, adapter creation throws an error naming json-schema-library 11.6.2 when the registry is shaped differently, or when a self-test on two probe schemas shows the fix no longer repairs validation. A new json-schema-library minor needs a Texaryn release that verifies the internal again.
130
+ The dependency is pinned to exactly `11.6.2`. In Draft 7, json-schema-library 11.6.2 overwrites the registry entry that `"$ref": "#"` resolves through, so without a fix the reference reaches another node and validation is wrong. The adapter pins that entry to the document root, and every other entry the library files for its own location to the node compiled there, so a reduction during projection cannot replace a definition with a reduced copy. Because the fix depends on the library's internal registry, adapter creation throws an error naming json-schema-library 11.6.2 when the registry is shaped differently, or when a self-test on two probe schemas shows the fix no longer repairs validation. A newer json-schema-library release is not installed until a Texaryn release raises the pin after the registry fix and its self-test pass against it.
111
131
 
112
132
  ## Validation
113
133
 
@@ -134,6 +154,10 @@ interface ValidationError {
134
154
 
135
155
  Required-property errors are located at the missing property pointer rather than only at the parent object.
136
156
 
157
+ `instancePointer` is an RFC 6901 pointer: a property named `a/b` is `/a~1b`, and `a~b` is `/a~0b`. json-schema-library joins property names into its own error pointers without escaping, so the adapter recovers the real keys from the validated data. Two locations whose keys read the same once joined, such as `a/b` holding `c` next to `a` holding `b/c`, are told apart by the value the error reports. When both hold equal values and only one fails, the error is located at the first of them in key order, until json-schema-library escapes at the source (sagold/json-schema-library#130). `params` is json-schema-library's raw error data, and its pointers are not escaped.
158
+
159
+ A data key named like an `Object.prototype` member (`__proto__`, `constructor`, `toString`) validates and projects like any other key. The one exception is a schema that combines `patternProperties` with `additionalProperties: false`: json-schema-library reads that schema's plain `properties` object, so it treats such an undeclared key as declared.
160
+
137
161
  ## Scoped validation
138
162
 
139
163
  This adapter also implements the optional `validateAt()` port method:
@@ -149,6 +173,7 @@ The result contains validation errors at that pointer or below it.
149
173
  ```ts
150
174
  import {
151
175
  createJsonSchemaAdapter,
176
+ ProjectionValidationDivergenceError,
152
177
  SameLocationCycleError,
153
178
  type AdapterConfig,
154
179
  type Dialect,
@@ -170,6 +195,9 @@ const adapter = await createJsonSchemaAdapter(schema, {
170
195
  ```ts
171
196
  interface AdapterConfig {
172
197
  defaultDialect?: Dialect
198
+ dynamicReferenceProjection?: 'local'
199
+ resolveResource?: (uri: string) => unknown | undefined | Promise<unknown | undefined>
200
+ maxExternalResources?: number
173
201
  }
174
202
  ```
175
203
 
@@ -194,6 +222,10 @@ try {
194
222
  }
195
223
  ```
196
224
 
225
+ ### `ProjectionValidationDivergenceError`
226
+
227
+ Thrown by `createJsonSchemaAdapter` when one retained static `$ref` resolves to different declarations with different validation assertions for validation and projection. Its `reference` and `sourcePosition` identify the reference site. `validationPosition` and `projectionPosition` identify the two resolved schema positions.
228
+
197
229
  ## Architecture
198
230
 
199
231
  The adapter is deliberately separate from `@texaryn/core`:
@@ -1,5 +1,12 @@
1
1
  # Third-party notices
2
2
 
3
+ ## json-schema-library
4
+
5
+ The ESM runtime at `dist/vendor/json-schema-library/` is adapted from
6
+ `json-schema-library` 11.6.2 by Sascha Goldhofer and is distributed under the
7
+ MIT License. Its full license is included at
8
+ `dist/vendor/json-schema-library/LICENSE.md`.
9
+
3
10
  ## JSON Schema metaschemas
4
11
 
5
12
  `src/metaschemas/` contains the published JSON Schema metaschema documents for
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAmC,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIxF,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAElE,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,OAAO,EACf,MAAM,CAAC,EAAE,aAAa,GACrB,OAAO,CAAC,iBAAiB,CAAC,CAE5B;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,aAAa,GAAG,SAAS,EACjC,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,iBAAiB,CAAC,CA8B5B"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAmC,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAQxF,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAElE,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,OAAO,EACf,MAAM,CAAC,EAAE,aAAa,GACrB,OAAO,CAAC,iBAAiB,CAAC,CAE5B;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,aAAa,GAAG,SAAS,EACjC,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,iBAAiB,CAAC,CAwF5B"}