@texaryn/schema-json 0.1.0-alpha.0 → 0.1.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 (3) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +196 -0
  3. package/package.json +4 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # @texaryn/schema-json
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 18f74ea: First public alpha: JSON Schema to React form pipeline.
8
+
9
+ Schema evaluation, IR compiler, headless runtime, React bindings, default widgets, and prop getters.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [afa1f81]
14
+ - Updated dependencies [e8807f4]
15
+ - Updated dependencies [65d58b2]
16
+ - Updated dependencies [18f74ea]
17
+ - @texaryn/core@0.1.0
18
+
19
+ ## 0.1.0-alpha.0
20
+
21
+ ### Minor Changes
22
+
23
+ - 18f74ea: First public alpha: JSON Schema to React form pipeline.
24
+
25
+ Schema evaluation, IR compiler, headless runtime, React bindings, default widgets, and prop getters.
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [18f74ea]
30
+ - @texaryn/core@0.1.0-alpha.0
package/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # @texaryn/schema-json
2
+
3
+ JSON Schema evaluation and validation adapter for Texaryn, backed by `json-schema-library`.
4
+
5
+ > Status: pre-1.0. Public APIs may change before 1.0.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @texaryn/core @texaryn/schema-json
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ts
16
+ import { createJsonSchemaAdapter } from '@texaryn/schema-json'
17
+
18
+ const schema = {
19
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
20
+ type: 'object',
21
+ properties: {
22
+ name: {
23
+ type: 'string',
24
+ title: 'Name',
25
+ minLength: 2,
26
+ },
27
+ },
28
+ required: ['name'],
29
+ }
30
+
31
+ const adapter = await createJsonSchemaAdapter(schema)
32
+
33
+ const projection = adapter.project({ name: '' })
34
+ const validation = await adapter.validate({ name: '' })
35
+
36
+ console.log(projection.nodes.get('/name'))
37
+ console.log(validation.valid, validation.errors)
38
+ ```
39
+
40
+ The returned object implements `SchemaEvaluationPort` from `@texaryn/core`.
41
+
42
+ ## JSON Schema dialect support
43
+
44
+ | Dialect | Support |
45
+ | --------- | ----------------- |
46
+ | Draft 4 | Not yet supported |
47
+ | Draft 6 | Not yet supported |
48
+ | Draft 7 | Supported |
49
+ | 2019-09 | Supported |
50
+ | 2020-12 | Supported |
51
+
52
+ The adapter detects the dialect from `$schema`. If `$schema` is absent or unrecognized, the adapter uses `draft-07` by default. You can override the fallback:
53
+
54
+ ```ts
55
+ const adapter = await createJsonSchemaAdapter(schema, {
56
+ defaultDialect: '2020-12',
57
+ })
58
+ ```
59
+
60
+ ## Projection
61
+
62
+ `project(data)` turns the schema plus current instance data into a framework-neutral `SchemaProjection`.
63
+
64
+ The projection contains one `NodeProjection` per JSON Pointer and includes information such as:
65
+
66
+ - JSON Schema type
67
+ - format
68
+ - constraints
69
+ - enum values
70
+ - annotations
71
+ - object children and required flags
72
+ - whether a node is active for the current data
73
+
74
+ This allows Texaryn to render fields that are declared by the schema even when they have not been filled yet.
75
+
76
+ ## Dynamic schema behavior
77
+
78
+ The adapter currently handles the schema features required by Texaryn's runtime and renderer, including:
79
+
80
+ - objects and primitive fields
81
+ - arrays
82
+ - enums
83
+ - local `$ref`
84
+ - `if` / `then` / `else`
85
+ - `oneOf`
86
+ - `anyOf`
87
+ - `dependentSchemas`
88
+ - `dependentRequired`
89
+ - Draft 7 `dependencies`
90
+ - annotations and field constraints
91
+
92
+ Inactive conditional fields remain represented in the projection with `active: false`, allowing the runtime and renderer to preserve a deterministic UI structure across branch changes.
93
+
94
+ ## Validation
95
+
96
+ ```ts
97
+ const result = await adapter.validate(data)
98
+
99
+ if (!result.valid) {
100
+ for (const error of result.errors) {
101
+ console.log(error.instancePointer, error.keyword, error.message)
102
+ }
103
+ }
104
+ ```
105
+
106
+ Validation errors are normalized to Texaryn's `ValidationError` contract:
107
+
108
+ ```ts
109
+ interface ValidationError {
110
+ instancePointer: string
111
+ keyword: string
112
+ message?: string
113
+ params: Record<string, unknown>
114
+ }
115
+ ```
116
+
117
+ Required-property errors are located at the missing property pointer rather than only at the parent object.
118
+
119
+ ## Scoped validation
120
+
121
+ This adapter also implements the optional `validateAt()` port method:
122
+
123
+ ```ts
124
+ const result = await adapter.validateAt(data, '/profile')
125
+ ```
126
+
127
+ The result contains validation errors at that pointer or below it.
128
+
129
+ ## API
130
+
131
+ ```ts
132
+ import {
133
+ createJsonSchemaAdapter,
134
+ type AdapterConfig,
135
+ type Dialect,
136
+ } from '@texaryn/schema-json'
137
+ ```
138
+
139
+ ### `createJsonSchemaAdapter(schema, config?)`
140
+
141
+ Creates a prepared adapter for one schema.
142
+
143
+ ```ts
144
+ const adapter = await createJsonSchemaAdapter(schema, {
145
+ defaultDialect: 'draft-07',
146
+ })
147
+ ```
148
+
149
+ ### `AdapterConfig`
150
+
151
+ ```ts
152
+ interface AdapterConfig {
153
+ defaultDialect?: Dialect
154
+ }
155
+ ```
156
+
157
+ ### `Dialect`
158
+
159
+ The union of dialect identifiers the adapter recognizes:
160
+
161
+ ```ts
162
+ type Dialect = 'draft-07' | '2019-09' | '2020-12'
163
+ ```
164
+
165
+ ## Architecture
166
+
167
+ The adapter is deliberately separate from `@texaryn/core`:
168
+
169
+ ```text
170
+ JSON Schema
171
+ |
172
+ v
173
+ @texaryn/schema-json
174
+ |
175
+ v
176
+ SchemaEvaluationPort
177
+ |
178
+ v
179
+ @texaryn/core
180
+ ```
181
+
182
+ The core runtime does not know which JSON Schema library produced the projection or validation result.
183
+
184
+ That boundary allows additional implementations to satisfy the same port without changing the runtime or renderer.
185
+
186
+ ## Related packages
187
+
188
+ - [`@texaryn/core`](../core/README.md), runtime and framework-neutral contracts
189
+ - [`@texaryn/react`](../react/README.md), React bindings and renderer
190
+ - [`@texaryn/schema-json-hyperjump`](../schema-json-hyperjump/README.md), private alternate adapter used to validate the port abstraction
191
+
192
+ See the [repository README](../../README.md) for a complete example.
193
+
194
+ ## License
195
+
196
+ Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@texaryn/schema-json",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "0.1.0",
4
4
  "description": "JSON Schema evaluation and validation adapter for Texaryn",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -25,11 +25,12 @@
25
25
  }
26
26
  },
27
27
  "files": [
28
- "dist"
28
+ "dist",
29
+ "CHANGELOG.md"
29
30
  ],
30
31
  "dependencies": {
31
32
  "json-schema-library": "^11.6.2",
32
- "@texaryn/core": "0.1.0-alpha.0"
33
+ "@texaryn/core": "0.1.0"
33
34
  },
34
35
  "devDependencies": {
35
36
  "tsx": "^4.23.12",