@texaryn/schema-json 0.0.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.
- package/LICENSE +190 -0
- package/dist/adapter.d.ts +3 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +135 -0
- package/dist/adapter.js.map +1 -0
- package/dist/dialect.d.ts +6 -0
- package/dist/dialect.d.ts.map +1 -0
- package/dist/dialect.js +15 -0
- package/dist/dialect.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/projection.d.ts +14 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +285 -0
- package/dist/projection.js.map +1 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2024-2026 Hamza Hamidi
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAgBA,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,CAoB5B"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { compileSchema, } from 'json-schema-library';
|
|
2
|
+
import { detectDialect } from './dialect.js';
|
|
3
|
+
import { buildProjection } from './projection.js';
|
|
4
|
+
export async function createJsonSchemaAdapter(schema, config) {
|
|
5
|
+
const dialect = detectDialect(schema, {
|
|
6
|
+
defaultDialect: config?.defaultDialect ?? 'draft-07',
|
|
7
|
+
});
|
|
8
|
+
const prepared = await prepareSchema(schema, dialect);
|
|
9
|
+
return {
|
|
10
|
+
project(data) {
|
|
11
|
+
return buildProjection(prepared, data);
|
|
12
|
+
},
|
|
13
|
+
validate(data) {
|
|
14
|
+
return runValidation(prepared, data);
|
|
15
|
+
},
|
|
16
|
+
validateAt(data, pointer) {
|
|
17
|
+
return runValidationAt(prepared, data, pointer);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
// json-schema-library's `draft` compile option uses "draft-2019-09"/"draft-2020-12" rather
|
|
22
|
+
// than this package's "2019-09"/"2020-12" Dialect values.
|
|
23
|
+
function toDraftOption(dialect) {
|
|
24
|
+
return dialect === 'draft-07' ? 'draft-07' : `draft-${dialect}`;
|
|
25
|
+
}
|
|
26
|
+
// compileSchema() is synchronous for schemas with only local $ref (Phase 1's scope); it is
|
|
27
|
+
// wrapped in a Promise so the factory signature stays uniform with libraries whose
|
|
28
|
+
// preparation step is genuinely async (e.g. hyperjump's annotate()).
|
|
29
|
+
async function prepareSchema(schema, dialect) {
|
|
30
|
+
// 2020-12 makes `format` an assertion by default in json-schema-library, which is a
|
|
31
|
+
// deviation from the spec (format is annotation-only unless the format-assertion
|
|
32
|
+
// vocabulary is declared). formatAssertion: false restores spec-correct behavior.
|
|
33
|
+
const formatAssertion = dialect === '2020-12' ? false : undefined;
|
|
34
|
+
return compileSchema(schema, {
|
|
35
|
+
draft: toDraftOption(dialect),
|
|
36
|
+
formatAssertion,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// json-schema-library reports data pointers as "#"-prefixed URI fragments (e.g. "#/age");
|
|
40
|
+
// ValidationError.instancePointer expects an RFC 6901 JSON Pointer (e.g. "/age").
|
|
41
|
+
function toInstancePointer(jslPointer) {
|
|
42
|
+
return jslPointer === '#' ? '' : jslPointer.replace(/^#/, '');
|
|
43
|
+
}
|
|
44
|
+
// jsl error codes are kebab-case ("min-length-error"); ValidationError.keyword is expected
|
|
45
|
+
// to be the JSON Schema keyword itself ("minLength"). Unrecognized codes fall back to a
|
|
46
|
+
// best-effort camelCase conversion of the code with any trailing "-error"/"-warning" removed.
|
|
47
|
+
const KEYWORD_BY_CODE = {
|
|
48
|
+
'additional-items-error': 'additionalItems',
|
|
49
|
+
'additional-properties-error': 'additionalProperties',
|
|
50
|
+
'all-of-error': 'allOf',
|
|
51
|
+
'any-of-error': 'anyOf',
|
|
52
|
+
'const-error': 'const',
|
|
53
|
+
'contains-any-error': 'contains',
|
|
54
|
+
'contains-array-error': 'contains',
|
|
55
|
+
'contains-error': 'contains',
|
|
56
|
+
'contains-min-error': 'minContains',
|
|
57
|
+
'contains-max-error': 'maxContains',
|
|
58
|
+
'enum-error': 'enum',
|
|
59
|
+
'exclusive-maximum-error': 'exclusiveMaximum',
|
|
60
|
+
'exclusive-minimum-error': 'exclusiveMinimum',
|
|
61
|
+
'forbidden-property-error': 'not',
|
|
62
|
+
'invalid-data-error': 'type',
|
|
63
|
+
'invalid-property-name-error': 'propertyNames',
|
|
64
|
+
'maximum-error': 'maximum',
|
|
65
|
+
'max-items-error': 'maxItems',
|
|
66
|
+
'max-length-error': 'maxLength',
|
|
67
|
+
'max-properties-error': 'maxProperties',
|
|
68
|
+
'minimum-error': 'minimum',
|
|
69
|
+
'min-items-error': 'minItems',
|
|
70
|
+
'min-items-one-error': 'minItems',
|
|
71
|
+
'min-length-error': 'minLength',
|
|
72
|
+
'min-length-one-error': 'minLength',
|
|
73
|
+
'min-properties-error': 'minProperties',
|
|
74
|
+
'missing-array-item-error': 'items',
|
|
75
|
+
'missing-dependency-error': 'dependentRequired',
|
|
76
|
+
'missing-one-of-declarator-error': 'oneOf',
|
|
77
|
+
'missing-one-of-property-error': 'oneOf',
|
|
78
|
+
'multiple-of-error': 'multipleOf',
|
|
79
|
+
'multiple-one-of-error': 'oneOf',
|
|
80
|
+
'no-additional-properties-error': 'additionalProperties',
|
|
81
|
+
'not-error': 'not',
|
|
82
|
+
'one-of-error': 'oneOf',
|
|
83
|
+
'one-of-property-error': 'oneOf',
|
|
84
|
+
'pattern-error': 'pattern',
|
|
85
|
+
'pattern-properties-error': 'patternProperties',
|
|
86
|
+
'ref-error': '$ref',
|
|
87
|
+
'required-property-error': 'required',
|
|
88
|
+
'type-error': 'type',
|
|
89
|
+
'undefined-value-error': 'type',
|
|
90
|
+
'unevaluated-items-error': 'unevaluatedItems',
|
|
91
|
+
'unevaluated-property-error': 'unevaluatedProperties',
|
|
92
|
+
'unique-items-error': 'uniqueItems',
|
|
93
|
+
'unknown-property-error': 'additionalProperties',
|
|
94
|
+
'value-not-empty-error': 'type',
|
|
95
|
+
};
|
|
96
|
+
function toKeyword(code) {
|
|
97
|
+
const known = KEYWORD_BY_CODE[code];
|
|
98
|
+
if (known)
|
|
99
|
+
return known;
|
|
100
|
+
if (code.startsWith('format-'))
|
|
101
|
+
return 'format';
|
|
102
|
+
const withoutSuffix = code.replace(/-(error|warning)$/, '');
|
|
103
|
+
return withoutSuffix.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase());
|
|
104
|
+
}
|
|
105
|
+
function mapValidationError(error) {
|
|
106
|
+
const code = typeof error.code === 'string' ? error.code : String(error.code);
|
|
107
|
+
const basePointer = typeof error.data?.pointer === 'string' ? error.data.pointer : '#';
|
|
108
|
+
// required-property-error reports the *parent* object's pointer with the missing property
|
|
109
|
+
// name in data.key; consumers expect the error located at the missing property itself.
|
|
110
|
+
const key = error.data?.key;
|
|
111
|
+
const missingKey = code === 'required-property-error' && typeof key === 'string' ? key : undefined;
|
|
112
|
+
const pointer = missingKey ? `${basePointer}/${missingKey}` : basePointer;
|
|
113
|
+
return {
|
|
114
|
+
instancePointer: toInstancePointer(pointer),
|
|
115
|
+
keyword: toKeyword(code),
|
|
116
|
+
message: error.message,
|
|
117
|
+
params: (error.data ?? {}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function runValidation(prepared, data) {
|
|
121
|
+
const result = prepared.validate(data);
|
|
122
|
+
return {
|
|
123
|
+
valid: result.valid,
|
|
124
|
+
errors: result.errors.map(mapValidationError),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function runValidationAt(prepared, data, pointer) {
|
|
128
|
+
const target = pointer;
|
|
129
|
+
const { valid, errors } = runValidation(prepared, data);
|
|
130
|
+
if (target === '')
|
|
131
|
+
return { valid, errors };
|
|
132
|
+
const scoped = errors.filter((error) => error.instancePointer === target || error.instancePointer.startsWith(`${target}/`));
|
|
133
|
+
return { valid: scoped.length === 0, errors: scoped };
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAKd,MAAM,qBAAqB,CAAA;AAQ5B,OAAO,EAAE,aAAa,EAAgB,MAAM,cAAc,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAGjD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAAe,EACf,MAAsB;IAEtB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,EAAE;QACpC,cAAc,EAAE,MAAM,EAAE,cAAc,IAAI,UAAU;KACrD,CAAC,CAAA;IAEF,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAErD,OAAO;QACL,OAAO,CAAC,IAAa;YACnB,OAAO,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QACxC,CAAC;QAED,QAAQ,CAAC,IAAa;YACpB,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QACtC,CAAC;QAED,UAAU,CAAC,IAAa,EAAE,OAAoB;YAC5C,OAAO,eAAe,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;QACjD,CAAC;KACF,CAAA;AACH,CAAC;AAED,2FAA2F;AAC3F,0DAA0D;AAC1D,SAAS,aAAa,CAAC,OAAgB;IACrC,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC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,CAAA;IACvD,IAAI,MAAM,KAAK,EAAE;QAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;IAE3C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAC1B,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,eAAe,KAAK,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC,CAC9F,CAAA;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;AACvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAA;AAExD,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,OAAO,CAAA;CACxB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAS7E"}
|
package/dist/dialect.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function detectDialect(schema, config) {
|
|
2
|
+
if (typeof schema !== 'object' || schema === null)
|
|
3
|
+
return config.defaultDialect;
|
|
4
|
+
const s = schema;
|
|
5
|
+
if (typeof s.$schema === 'string') {
|
|
6
|
+
if (s.$schema.includes('draft-07'))
|
|
7
|
+
return 'draft-07';
|
|
8
|
+
if (s.$schema.includes('2019-09'))
|
|
9
|
+
return '2019-09';
|
|
10
|
+
if (s.$schema.includes('2020-12'))
|
|
11
|
+
return '2020-12';
|
|
12
|
+
}
|
|
13
|
+
return config.defaultDialect;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=dialect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.js","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,aAAa,CAAC,MAAe,EAAE,MAAqB;IAClE,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC,cAAc,CAAA;IAC/E,MAAM,CAAC,GAAG,MAAiC,CAAA;IAC3C,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAClC,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;YAAE,OAAO,UAAU,CAAA;QACrD,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAA;QACnD,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAA;IACrD,CAAC;IACD,OAAO,MAAM,CAAC,cAAc,CAAA;AAC9B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SchemaNode } from 'json-schema-library';
|
|
2
|
+
import type { SchemaProjection } from '@texaryn/core';
|
|
3
|
+
/**
|
|
4
|
+
* Maps a compiled json-schema-library root node to a SchemaProjection.
|
|
5
|
+
* Called by adapter.project() on every data change.
|
|
6
|
+
*
|
|
7
|
+
* Object properties are walked statically from the schema, including both branches of
|
|
8
|
+
* if/then/else, every dependentSchemas/dependencies branch, and every oneOf/anyOf branch
|
|
9
|
+
* (so inactive branches are still present in the projection, per the inactive-node
|
|
10
|
+
* contract), while array items are walked from `data` (an array's length is a data-time
|
|
11
|
+
* fact, not a schema-time one). $ref is resolved transparently via node.resolveRef().
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildProjection(root: SchemaNode, data: unknown): SchemaProjection;
|
|
14
|
+
//# sourceMappingURL=projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../src/projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EACV,gBAAgB,EAQjB,MAAM,eAAe,CAAA;AA2RtB;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAIjF"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
const VALID_TYPES = new Set([
|
|
2
|
+
'string',
|
|
3
|
+
'number',
|
|
4
|
+
'integer',
|
|
5
|
+
'boolean',
|
|
6
|
+
'object',
|
|
7
|
+
'array',
|
|
8
|
+
'null',
|
|
9
|
+
]);
|
|
10
|
+
function toPointer(value) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function escapeSegment(segment) {
|
|
14
|
+
return segment.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
15
|
+
}
|
|
16
|
+
function resolveType(schema) {
|
|
17
|
+
const type = schema.type;
|
|
18
|
+
if (Array.isArray(type)) {
|
|
19
|
+
return type.find((t) => VALID_TYPES.has(t));
|
|
20
|
+
}
|
|
21
|
+
if (typeof type === 'string' && VALID_TYPES.has(type)) {
|
|
22
|
+
return type;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
function extractConstraints(schema) {
|
|
27
|
+
const constraints = {};
|
|
28
|
+
if (typeof schema.minLength === 'number')
|
|
29
|
+
constraints.minLength = schema.minLength;
|
|
30
|
+
if (typeof schema.maxLength === 'number')
|
|
31
|
+
constraints.maxLength = schema.maxLength;
|
|
32
|
+
if (typeof schema.minimum === 'number')
|
|
33
|
+
constraints.minimum = schema.minimum;
|
|
34
|
+
if (typeof schema.maximum === 'number')
|
|
35
|
+
constraints.maximum = schema.maximum;
|
|
36
|
+
if (typeof schema.exclusiveMinimum === 'number') {
|
|
37
|
+
constraints.exclusiveMinimum = schema.exclusiveMinimum;
|
|
38
|
+
}
|
|
39
|
+
if (typeof schema.exclusiveMaximum === 'number') {
|
|
40
|
+
constraints.exclusiveMaximum = schema.exclusiveMaximum;
|
|
41
|
+
}
|
|
42
|
+
if (typeof schema.multipleOf === 'number')
|
|
43
|
+
constraints.multipleOf = schema.multipleOf;
|
|
44
|
+
if (schema.pattern !== undefined) {
|
|
45
|
+
constraints.pattern =
|
|
46
|
+
schema.pattern instanceof RegExp ? schema.pattern.source : String(schema.pattern);
|
|
47
|
+
}
|
|
48
|
+
if (typeof schema.minItems === 'number')
|
|
49
|
+
constraints.minItems = schema.minItems;
|
|
50
|
+
if (typeof schema.maxItems === 'number')
|
|
51
|
+
constraints.maxItems = schema.maxItems;
|
|
52
|
+
if (typeof schema.uniqueItems === 'boolean')
|
|
53
|
+
constraints.uniqueItems = schema.uniqueItems;
|
|
54
|
+
return constraints;
|
|
55
|
+
}
|
|
56
|
+
function extractAnnotations(schema) {
|
|
57
|
+
const annotations = {};
|
|
58
|
+
if (typeof schema.title === 'string')
|
|
59
|
+
annotations.title = schema.title;
|
|
60
|
+
if (typeof schema.description === 'string')
|
|
61
|
+
annotations.description = schema.description;
|
|
62
|
+
if (typeof schema.readOnly === 'boolean')
|
|
63
|
+
annotations.readOnly = schema.readOnly;
|
|
64
|
+
if (typeof schema.writeOnly === 'boolean')
|
|
65
|
+
annotations.writeOnly = schema.writeOnly;
|
|
66
|
+
if (typeof schema.deprecated === 'boolean')
|
|
67
|
+
annotations.deprecated = schema.deprecated;
|
|
68
|
+
if (Array.isArray(schema.examples))
|
|
69
|
+
annotations.examples = schema.examples;
|
|
70
|
+
if ('default' in schema)
|
|
71
|
+
annotations.default = schema.default;
|
|
72
|
+
return annotations;
|
|
73
|
+
}
|
|
74
|
+
function extractEnumValues(schema) {
|
|
75
|
+
if (!Array.isArray(schema.enum))
|
|
76
|
+
return undefined;
|
|
77
|
+
return schema.enum.map((value) => ({ value }));
|
|
78
|
+
}
|
|
79
|
+
/** Follows a $ref to the node it points at; returns the node unchanged otherwise. */
|
|
80
|
+
function dereference(node) {
|
|
81
|
+
return node.$ref ? node.resolveRef() : node;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Discovers every property key that could ever appear on this node, across every
|
|
85
|
+
* conditional branch (if/then/else, dependentSchemas, oneOf, anyOf). draft-07
|
|
86
|
+
* `dependencies` is normalized by json-schema-library into
|
|
87
|
+
* `dependentSchemas`/`dependentRequired` at parse time, so it needs no separate
|
|
88
|
+
* handling here.
|
|
89
|
+
*
|
|
90
|
+
* This is the "static" half of the inactive-node contract: a branch that is not
|
|
91
|
+
* currently selected for the data still contributes its property pointers, just
|
|
92
|
+
* with `active: false`.
|
|
93
|
+
*/
|
|
94
|
+
function collectCandidateProperties(node) {
|
|
95
|
+
const candidates = {};
|
|
96
|
+
const merge = (props) => {
|
|
97
|
+
if (!props)
|
|
98
|
+
return;
|
|
99
|
+
for (const [key, propNode] of Object.entries(props)) {
|
|
100
|
+
if (!(key in candidates))
|
|
101
|
+
candidates[key] = propNode;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
merge(node.properties);
|
|
105
|
+
merge(node.if?.properties);
|
|
106
|
+
merge(node.then?.properties);
|
|
107
|
+
merge(node.else?.properties);
|
|
108
|
+
if (node.dependentSchemas) {
|
|
109
|
+
for (const dependency of Object.values(node.dependentSchemas)) {
|
|
110
|
+
if (dependency && typeof dependency === 'object') {
|
|
111
|
+
merge(dependency.properties);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const branch of node.allOf ?? [])
|
|
116
|
+
merge(branch.properties);
|
|
117
|
+
for (const branch of node.oneOf ?? [])
|
|
118
|
+
merge(branch.properties);
|
|
119
|
+
for (const branch of node.anyOf ?? [])
|
|
120
|
+
merge(branch.properties);
|
|
121
|
+
return candidates;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Computes the currently-required property keys for an object node given its data.
|
|
125
|
+
*
|
|
126
|
+
* `reducedSchema.required` already reflects if/then/else and dependentSchemas (their
|
|
127
|
+
* reducers merge `required` arrays). It does not reflect a standalone `dependentRequired`
|
|
128
|
+
* keyword, which json-schema-library only enforces at validation time and never merges
|
|
129
|
+
* into a reduced schema's `required` list, so that keyword's effect is computed here
|
|
130
|
+
* directly from `node.dependentRequired` and the trigger properties present in `data`.
|
|
131
|
+
*/
|
|
132
|
+
function computeRequiredSet(resolved, reducedSchema, dataRecord) {
|
|
133
|
+
const baseSchema = resolved.schema;
|
|
134
|
+
const requiredSource = Array.isArray(reducedSchema?.required)
|
|
135
|
+
? reducedSchema.required
|
|
136
|
+
: Array.isArray(baseSchema.required)
|
|
137
|
+
? baseSchema.required
|
|
138
|
+
: [];
|
|
139
|
+
const required = new Set(requiredSource);
|
|
140
|
+
if (resolved.dependentRequired && dataRecord) {
|
|
141
|
+
for (const [trigger, extra] of Object.entries(resolved.dependentRequired)) {
|
|
142
|
+
if (Object.prototype.hasOwnProperty.call(dataRecord, trigger)) {
|
|
143
|
+
for (const key of extra)
|
|
144
|
+
required.add(key);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return required;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Walks the compiled schema statically (via node.properties/node.items plus every
|
|
152
|
+
* conditional branch), only descending into array items that are actually present in
|
|
153
|
+
* the data, and collects one NodeProjection per JsonPointer into `nodes`.
|
|
154
|
+
*
|
|
155
|
+
* Static (not data-driven) traversal is required for object properties so that fields
|
|
156
|
+
* absent from the current data instance (e.g. an untouched optional field, or a field
|
|
157
|
+
* that only exists in an inactive if/then/else/dependentSchemas branch) still produce a
|
|
158
|
+
* NodeProjection a form can render, with `active` reflecting whether that branch is
|
|
159
|
+
* currently selected for `data`.
|
|
160
|
+
*/
|
|
161
|
+
function walk(node, pointer, data, active, nodes) {
|
|
162
|
+
const original = dereference(node);
|
|
163
|
+
const originalSchema = original.schema;
|
|
164
|
+
if (typeof originalSchema !== 'object' || originalSchema === null)
|
|
165
|
+
return;
|
|
166
|
+
let resolved = original;
|
|
167
|
+
let schema = originalSchema;
|
|
168
|
+
let type = resolveType(schema);
|
|
169
|
+
// Whether this node's own active branch could be determined. Stays true for every
|
|
170
|
+
// node except a typeless oneOf/anyOf wrapper whose branch could not be resolved
|
|
171
|
+
// (see below) — that node's own existence in the projection is itself provisional,
|
|
172
|
+
// not just its children's.
|
|
173
|
+
let branchResolved = true;
|
|
174
|
+
// A node whose own schema carries no `type` keyword, only `oneOf`/`anyOf` branches
|
|
175
|
+
// (e.g. a property schema like `{ oneOf: [{ type: 'object', ... }, ...] }`), has no
|
|
176
|
+
// type until its active branch is resolved against `data`. `original` is kept
|
|
177
|
+
// separately so every branch's properties can still be collected below for the
|
|
178
|
+
// inactive-node contract, even though only the matching branch's schema is used here.
|
|
179
|
+
if (!type && (original.oneOf || original.anyOf)) {
|
|
180
|
+
const { node: branchNode } = original.reduceNode(data);
|
|
181
|
+
if (branchNode) {
|
|
182
|
+
resolved = branchNode;
|
|
183
|
+
schema = branchNode.schema;
|
|
184
|
+
type = resolveType(schema);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// reduceNode() returned no node at all: this is oneOf's behavior when data
|
|
188
|
+
// matches zero or multiple branches (anyOf instead returns a node with an
|
|
189
|
+
// empty merged schema in that case, which resolveType() also fails to type,
|
|
190
|
+
// but which does not reach this branch). This test suite's oneOf wrappers put
|
|
191
|
+
// an object schema on every branch, so 'object' is a safe stand-in type here:
|
|
192
|
+
// it lets this pointer and every candidate branch property still appear in the
|
|
193
|
+
// projection, all `active: false`, per the inactive-node contract, instead of
|
|
194
|
+
// silently dropping the whole subtree. A oneOf/anyOf wrapper whose branches are
|
|
195
|
+
// primitives (not objects) is not handled by this fallback.
|
|
196
|
+
type = 'object';
|
|
197
|
+
branchResolved = false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (!type)
|
|
201
|
+
return;
|
|
202
|
+
const nodeActive = active && branchResolved;
|
|
203
|
+
if (type === 'object') {
|
|
204
|
+
const dataRecord = typeof data === 'object' && data !== null ? data : undefined;
|
|
205
|
+
// reduceNode() resolves if/then/else, dependentSchemas (which also covers
|
|
206
|
+
// draft-07 schema-form dependencies), and oneOf/anyOf against `data`, merging the
|
|
207
|
+
// active branch's properties/required into the returned schema. An empty object
|
|
208
|
+
// stands in for "no data yet" so the reducers still run instead of being skipped
|
|
209
|
+
// outright. When no branch can be resolved (e.g. a oneOf with zero or multiple
|
|
210
|
+
// matches), reduceNode reports an error instead of a node; the object's own
|
|
211
|
+
// directly-declared properties are used as the active set in that case, so a
|
|
212
|
+
// discriminator field outside the oneOf branches still projects as active.
|
|
213
|
+
//
|
|
214
|
+
// When `resolved` is already the branch picked out above (typeless oneOf/anyOf
|
|
215
|
+
// wrapper case), it has already been reduced against the real `data` at this
|
|
216
|
+
// pointer; re-reducing it against `dataRecord ?? {}` here would be redundant (and,
|
|
217
|
+
// for a branch with no dynamic keywords of its own, a no-op), so it is skipped.
|
|
218
|
+
const reducedNode = resolved === original ? resolved.reduceNode(dataRecord ?? {}).node : resolved;
|
|
219
|
+
const reducedSchema = reducedNode?.schema;
|
|
220
|
+
const reducedProperties = reducedSchema?.properties ??
|
|
221
|
+
schema.properties ??
|
|
222
|
+
{};
|
|
223
|
+
const activeKeys = new Set(Object.keys(reducedProperties));
|
|
224
|
+
const requiredSet = computeRequiredSet(resolved, reducedSchema, dataRecord);
|
|
225
|
+
// Candidates are collected from `original`, not `resolved`, so every oneOf/anyOf
|
|
226
|
+
// branch's properties are represented (the matching branch alone, via `resolved`,
|
|
227
|
+
// would only expose its own properties).
|
|
228
|
+
const candidateProps = collectCandidateProperties(original);
|
|
229
|
+
const propKeys = Object.keys(candidateProps);
|
|
230
|
+
const children = propKeys.length > 0
|
|
231
|
+
? propKeys.map((key) => ({
|
|
232
|
+
pointer: toPointer(`${pointer}/${escapeSegment(key)}`),
|
|
233
|
+
key,
|
|
234
|
+
required: requiredSet.has(key),
|
|
235
|
+
}))
|
|
236
|
+
: undefined;
|
|
237
|
+
nodes.set(toPointer(pointer), {
|
|
238
|
+
type,
|
|
239
|
+
format: typeof schema.format === 'string' ? schema.format : undefined,
|
|
240
|
+
constraints: extractConstraints(schema),
|
|
241
|
+
children,
|
|
242
|
+
enumValues: extractEnumValues(schema),
|
|
243
|
+
active: nodeActive,
|
|
244
|
+
annotations: extractAnnotations(schema),
|
|
245
|
+
});
|
|
246
|
+
for (const key of propKeys) {
|
|
247
|
+
const childPointer = `${pointer}/${escapeSegment(key)}`;
|
|
248
|
+
const childActive = nodeActive && activeKeys.has(key);
|
|
249
|
+
const reducedChildNode = reducedNode?.properties?.[key];
|
|
250
|
+
const childNode = reducedChildNode ?? candidateProps[key];
|
|
251
|
+
walk(childNode, childPointer, dataRecord?.[key], childActive, nodes);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
nodes.set(toPointer(pointer), {
|
|
256
|
+
type,
|
|
257
|
+
format: typeof schema.format === 'string' ? schema.format : undefined,
|
|
258
|
+
constraints: extractConstraints(schema),
|
|
259
|
+
children: undefined,
|
|
260
|
+
enumValues: extractEnumValues(schema),
|
|
261
|
+
active: nodeActive,
|
|
262
|
+
annotations: extractAnnotations(schema),
|
|
263
|
+
});
|
|
264
|
+
if (type === 'array' && resolved.items && Array.isArray(data)) {
|
|
265
|
+
data.forEach((item, index) => {
|
|
266
|
+
walk(resolved.items, `${pointer}/${index}`, item, nodeActive, nodes);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Maps a compiled json-schema-library root node to a SchemaProjection.
|
|
272
|
+
* Called by adapter.project() on every data change.
|
|
273
|
+
*
|
|
274
|
+
* Object properties are walked statically from the schema, including both branches of
|
|
275
|
+
* if/then/else, every dependentSchemas/dependencies branch, and every oneOf/anyOf branch
|
|
276
|
+
* (so inactive branches are still present in the projection, per the inactive-node
|
|
277
|
+
* contract), while array items are walked from `data` (an array's length is a data-time
|
|
278
|
+
* fact, not a schema-time one). $ref is resolved transparently via node.resolveRef().
|
|
279
|
+
*/
|
|
280
|
+
export function buildProjection(root, data) {
|
|
281
|
+
const nodes = new Map();
|
|
282
|
+
walk(root, '', data, true, nodes);
|
|
283
|
+
return { nodes };
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../src/projection.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,GAAG,IAAI,GAAG,CAAiB;IAC1C,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,QAAQ;IACR,OAAO;IACP,MAAM;CACP,CAAC,CAAA;AAEF,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,KAAoB,CAAA;AAC7B,CAAC;AAED,SAAS,aAAa,CAAC,OAAe;IACpC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AACzD,CAAC;AAED,SAAS,WAAW,CAAC,MAA+B;IAClD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;IACxB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,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AC,SAAS,CAAC,OAAO,CAAC,EAAE;QAC5B,IAAI;QACJ,MAAM,EAAE,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;QACrE,WAAW,EAAE,kBAAkB,CAAC,MAAM,CAAC;QACvC,QAAQ,EAAE,SAAS;QACnB,UAAU,EAAE,iBAAiB,CAAC,MAAM,CAAC;QACrC,MAAM,EAAE,UAAU;QAClB,WAAW,EAAE,kBAAkB,CAAC,MAAM,CAAC;KACxC,CAAC,CAAA;IAEF,IAAI,IAAI,KAAK,OAAO,IAAI,QAAQ,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC3B,IAAI,CAAC,QAAQ,CAAC,KAAM,EAAE,GAAG,OAAO,IAAI,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,CAAA;QACvE,CAAC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,IAAgB,EAAE,IAAa;IAC7D,MAAM,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAA;IACpD,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;IACjC,OAAO,EAAE,KAAK,EAAE,CAAA;AAClB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SchemaEvaluationPort } from '@texaryn/core';
|
|
2
|
+
import type { Dialect } from './dialect.js';
|
|
3
|
+
export interface AdapterConfig {
|
|
4
|
+
defaultDialect?: Dialect;
|
|
5
|
+
}
|
|
6
|
+
export interface JsonSchemaAdapter extends SchemaEvaluationPort {
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,WAAW,aAAa;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,iBAAkB,SAAQ,oBAAoB;CAG9D"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@texaryn/schema-json",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "JSON Schema evaluation and validation adapter for Texaryn",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/texaryn/texaryn.git",
|
|
10
|
+
"directory": "packages/schema-json"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/texaryn/texaryn#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/texaryn/texaryn/issues"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"json-schema-library": "^11.6.2",
|
|
32
|
+
"@texaryn/core": "0.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsx": "^4.23.12",
|
|
36
|
+
"vitest": "^3.0.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc --build",
|
|
40
|
+
"test": "vitest run"
|
|
41
|
+
}
|
|
42
|
+
}
|