json-schema-library 11.0.5 → 11.2.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/.mocharc.js +1 -0
- package/CHANGELOG.md +17 -0
- package/README.md +120 -0
- package/bowtie/.editorconfig +21 -0
- package/bowtie/.prettierrc +6 -0
- package/bowtie/BOWTIE.md +54 -0
- package/bowtie/Dockerfile +6 -0
- package/bowtie/bowtie-api.ts +101 -0
- package/bowtie/bowtie.test.ts +76 -0
- package/bowtie/bowtie.ts +156 -0
- package/bowtie/package.json +11 -0
- package/bowtie/tsconfig.json +12 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +39 -470
- package/dist/index.d.mts +39 -470
- package/dist/index.mjs +1 -1
- package/dist/jlib.js +2 -13
- package/dist/remotes/index.cjs +1 -0
- package/dist/remotes/index.d.cts +7 -0
- package/dist/remotes/index.d.mts +7 -0
- package/dist/remotes/index.mjs +1 -0
- package/dist/types-B2wwNWyo.d.cts +513 -0
- package/dist/types-BhTU1l2h.d.mts +513 -0
- package/index.ts +10 -4
- package/package.json +14 -8
- package/src/Keyword.ts +37 -12
- package/src/SchemaNode.ts +84 -16
- package/src/compileSchema.ts +56 -4
- package/src/draft04/keywords/$ref.ts +22 -14
- package/src/draft04/keywords/exclusiveMaximum.ts +14 -0
- package/src/draft04/keywords/exclusiveMinimum.ts +14 -0
- package/src/draft04/validateSchema.test.ts +20 -0
- package/src/draft06/keywords/$ref.ts +15 -5
- package/src/draft2019-09/keywords/$ref.test.ts +3 -1
- package/src/draft2019-09/keywords/$ref.ts +40 -16
- package/src/draft2019-09/keywords/additionalItems.ts +33 -10
- package/src/draft2019-09/keywords/items.ts +32 -10
- package/src/draft2019-09/keywords/unevaluatedItems.ts +19 -6
- package/src/draft2019-09/methods/getData.ts +1 -1
- package/src/draft2019-09/validateSchema.test.ts +28 -0
- package/src/errors/errors.ts +8 -1
- package/src/formats/formats.ts +35 -28
- package/src/formats/hyperjump.d.ts +172 -0
- package/src/keywords/$defs.ts +34 -8
- package/src/keywords/$ref.ts +59 -13
- package/src/keywords/additionalProperties.ts +19 -8
- package/src/keywords/allOf.ts +44 -18
- package/src/keywords/anyOf.ts +38 -19
- package/src/keywords/contains.ts +21 -9
- package/src/keywords/dependencies.ts +37 -17
- package/src/keywords/dependentRequired.ts +56 -38
- package/src/keywords/dependentSchemas.ts +37 -13
- package/src/keywords/deprecated.ts +32 -8
- package/src/keywords/enum.ts +30 -8
- package/src/keywords/exclusiveMaximum.ts +21 -2
- package/src/keywords/exclusiveMinimum.ts +22 -3
- package/src/keywords/format.ts +21 -2
- package/src/keywords/ifthenelse.ts +49 -5
- package/src/keywords/items.ts +27 -13
- package/src/keywords/maxItems.ts +22 -2
- package/src/keywords/maxLength.ts +30 -9
- package/src/keywords/maxProperties.ts +30 -9
- package/src/keywords/maximum.ts +28 -8
- package/src/keywords/minItems.ts +30 -9
- package/src/keywords/minLength.ts +30 -9
- package/src/keywords/minProperties.ts +26 -5
- package/src/keywords/minimum.ts +32 -13
- package/src/keywords/multipleOf.ts +33 -12
- package/src/keywords/not.ts +23 -10
- package/src/keywords/oneOf.ts +29 -9
- package/src/keywords/pattern.ts +35 -9
- package/src/keywords/properties.ts +34 -11
- package/src/keywords/propertyDependencies.test.ts +180 -0
- package/src/keywords/propertyDependencies.ts +173 -0
- package/src/keywords/propertyNames.ts +26 -14
- package/src/keywords/required.ts +31 -8
- package/src/keywords/type.ts +53 -16
- package/src/keywords/unevaluatedItems.ts +24 -8
- package/src/keywords/unevaluatedProperties.ts +24 -7
- package/src/keywords/uniqueItems.ts +23 -4
- package/src/mergeNode.ts +9 -4
- package/src/methods/getData.ts +1 -1
- package/src/settings.ts +2 -1
- package/src/types.ts +1 -1
- package/src/utils/isListOfStrings.ts +3 -0
- package/src/validate.test.ts +0 -2
- package/src/validateNode.ts +6 -3
- package/src/validateSchema.test.ts +312 -0
- package/tsconfig.json +11 -4
- package/tsconfig.test.json +9 -2
- package/tsdown.config.ts +1 -1
- package/Dockerfile +0 -6
- package/bowtie_jlib.js +0 -140
- package/remotes/draft04.json +0 -150
- package/remotes/draft06.json +0 -155
- package/remotes/draft07.json +0 -155
- package/remotes/draft2019-09.json +0 -42
- package/remotes/draft2019-09_meta_applicator.json +0 -53
- package/remotes/draft2019-09_meta_content.json +0 -14
- package/remotes/draft2019-09_meta_core.json +0 -54
- package/remotes/draft2019-09_meta_format.json +0 -11
- package/remotes/draft2019-09_meta_meta-data.json +0 -34
- package/remotes/draft2019-09_meta_validation.json +0 -95
- package/remotes/draft2020-12.json +0 -55
- package/remotes/draft2020-12_meta_applicator.json +0 -45
- package/remotes/draft2020-12_meta_content.json +0 -14
- package/remotes/draft2020-12_meta_core.json +0 -48
- package/remotes/draft2020-12_meta_format_annotation.json +0 -11
- package/remotes/draft2020-12_meta_format_assertion.json +0 -11
- package/remotes/draft2020-12_meta_meta_data.json +0 -34
- package/remotes/draft2020-12_meta_unevaluated.json +0 -12
- package/remotes/draft2020-12_meta_validation.json +0 -87
- package/remotes/index.ts +0 -48
package/dist/index.d.mts
CHANGED
|
@@ -1,479 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
pointer: string;
|
|
4
|
-
node: SchemaNode;
|
|
5
|
-
}[];
|
|
6
|
-
type JsonSchemaReducerParams = {
|
|
7
|
-
/** data of current node */data: unknown; /** optional key to used to resolve by property without having data */
|
|
8
|
-
key: string | number; /** node to reduce */
|
|
9
|
-
node: SchemaNode; /** JSON pointer to data */
|
|
10
|
-
pointer: string; /** passed through path for schema resolution, will be changed by reference */
|
|
11
|
-
path: ValidationPath;
|
|
12
|
-
};
|
|
13
|
-
interface JsonSchemaReducer {
|
|
14
|
-
toJSON?: () => string;
|
|
15
|
-
order?: number;
|
|
16
|
-
(options: JsonSchemaReducerParams): SchemaNode | JsonError | undefined;
|
|
17
|
-
}
|
|
18
|
-
type JsonSchemaResolverParams = {
|
|
19
|
-
key: string | number;
|
|
20
|
-
data: unknown;
|
|
21
|
-
node: SchemaNode;
|
|
22
|
-
};
|
|
23
|
-
interface JsonSchemaResolver {
|
|
24
|
-
toJSON?: () => string;
|
|
25
|
-
order?: number;
|
|
26
|
-
(options: JsonSchemaResolverParams): SchemaNode | JsonError | undefined;
|
|
27
|
-
}
|
|
28
|
-
type Maybe<T> = T | undefined;
|
|
29
|
-
type ValidationAnnotation = JsonError | JsonAnnotation | Promise<Maybe<ValidationAnnotation>[]>;
|
|
30
|
-
type ValidationResult = Maybe<ValidationAnnotation>;
|
|
31
|
-
type ValidationReturnType = ValidationResult | ValidationResult[];
|
|
32
|
-
type JsonSchemaValidatorParams = {
|
|
33
|
-
pointer: string;
|
|
34
|
-
data: unknown;
|
|
35
|
-
node: SchemaNode;
|
|
36
|
-
path: ValidationPath;
|
|
37
|
-
};
|
|
38
|
-
interface JsonSchemaValidator {
|
|
39
|
-
toJSON?: () => string;
|
|
40
|
-
order?: number;
|
|
41
|
-
(options: JsonSchemaValidatorParams): ValidationReturnType;
|
|
42
|
-
}
|
|
43
|
-
type Keyword = {
|
|
44
|
-
id: string; /** unique keyword corresponding to JSON Schema keywords (or custom) */
|
|
45
|
-
keyword: string; /** sort order of keyword. Lower numbers will be processed last. Default is 0 */
|
|
46
|
-
order?: number; /** called with compileSchema */
|
|
47
|
-
parse?: (node: SchemaNode) => void;
|
|
48
|
-
addResolve?: (node: SchemaNode) => boolean; /** return node corresponding to passed in key or do nothing */
|
|
49
|
-
resolve?: JsonSchemaResolver;
|
|
50
|
-
addValidate?: (node: SchemaNode) => boolean; /** validate data using node */
|
|
51
|
-
validate?: JsonSchemaValidator;
|
|
52
|
-
addReduce?: (node: SchemaNode) => boolean; /** remove dynamic schema-keywords by merging valid sub-schemas */
|
|
53
|
-
reduce?: JsonSchemaReducer;
|
|
54
|
-
};
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region src/methods/createSchema.d.ts
|
|
57
|
-
/**
|
|
58
|
-
* Create a simple json schema for the given input data
|
|
59
|
-
* @param data - data to get json schema for
|
|
60
|
-
*/
|
|
61
|
-
declare function createSchema(data: unknown): JsonSchema;
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/methods/toDataNodes.d.ts
|
|
64
|
-
type DataNode = {
|
|
65
|
-
node: SchemaNode;
|
|
66
|
-
value: unknown;
|
|
67
|
-
pointer: string;
|
|
68
|
-
};
|
|
69
|
-
declare function toDataNodes(node: SchemaNode, data: unknown, pointer?: string, dataNodes?: DataNode[]): DataNode[];
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/methods/getChildSelection.d.ts
|
|
72
|
-
/**
|
|
73
|
-
* Returns a list of possible child-schemas for the given property key. In case of a oneOf selection, multiple schemas
|
|
74
|
-
* could be added at the given property (e.g. item-index), thus an array of options is returned. In all other cases
|
|
75
|
-
* a list with a single item will be returned
|
|
76
|
-
*/
|
|
77
|
-
declare function getChildSelection(node: SchemaNode, property: string | number): JsonError | SchemaNode[];
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/methods/getData.d.ts
|
|
80
|
-
type TemplateOptions = {
|
|
81
|
-
/** Add all properties (required and optional) to the generated data */addOptionalProps?: boolean; /** Remove data that does not match input schema. Defaults to false */
|
|
82
|
-
removeInvalidData?: boolean;
|
|
83
|
-
/** Set to false to take default values as they are and not extend them.
|
|
84
|
-
* Defaults to true.
|
|
85
|
-
* This allows to control template data e.g. enforcing arrays to be empty,
|
|
86
|
-
* regardless of minItems settings.
|
|
87
|
-
*/
|
|
88
|
-
extendDefaults?: boolean;
|
|
89
|
-
/**
|
|
90
|
-
* Set to false to not use type specific initial values.Defaults to true
|
|
91
|
-
*/
|
|
92
|
-
useTypeDefaults?: boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Limits how often a $ref should be followed before aborting. Prevents infinite data-structure.
|
|
95
|
-
* Defaults to 1
|
|
96
|
-
*/
|
|
97
|
-
recursionLimit?: number; /** @internal disables recursion limit for next call */
|
|
98
|
-
disableRecursionLimit?: boolean; /** @internal context to track recursion limit */
|
|
99
|
-
cache?: Record<string, Record<string, number>>;
|
|
100
|
-
};
|
|
101
|
-
declare function getData(node: SchemaNode, data?: unknown, opts?: TemplateOptions): any;
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/Draft.d.ts
|
|
104
|
-
type DraftVersion = "draft-04" | "draft-06" | "draft-07" | "draft-2019-09" | "draft-2020-12" | "latest";
|
|
105
|
-
interface Draft {
|
|
106
|
-
/** test-string if draft can be used with $schema-url */
|
|
107
|
-
$schemaRegEx: string;
|
|
108
|
-
/** draft-version of this draft, e.g. draft-2020-12 */
|
|
109
|
-
version: DraftVersion;
|
|
110
|
-
/** supported keywords and implementation */
|
|
111
|
-
keywords: Keyword[];
|
|
112
|
-
/** draft-dependent methods */
|
|
113
|
-
methods: {
|
|
114
|
-
createSchema: typeof createSchema;
|
|
115
|
-
getChildSelection: typeof getChildSelection;
|
|
116
|
-
getData: typeof getData;
|
|
117
|
-
toDataNodes: typeof toDataNodes;
|
|
118
|
-
};
|
|
119
|
-
/** meta-schema url associated with this draft */
|
|
120
|
-
$schema?: string;
|
|
121
|
-
/** draft errors (this can still be global) */
|
|
122
|
-
errors: ErrorConfig;
|
|
123
|
-
formats: Record<string, JsonSchemaValidator>;
|
|
124
|
-
}
|
|
125
|
-
type PartialDraft = Partial<Omit<Draft, "errors" | "formats">> & {
|
|
126
|
-
errors?: Partial<Draft["errors"]>;
|
|
127
|
-
formats?: Partial<Draft["formats"]>;
|
|
128
|
-
};
|
|
129
|
-
declare function extendDraft(draft: Draft, extension: PartialDraft): Draft;
|
|
130
|
-
declare function addKeywords(draft: Draft, ...keywords: Keyword[]): Draft;
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/errors/errors.d.ts
|
|
133
|
-
declare const errors: {
|
|
134
|
-
"additional-items-error": string;
|
|
135
|
-
"additional-properties-error": string;
|
|
136
|
-
"all-of-error": string;
|
|
137
|
-
"any-of-error": string;
|
|
138
|
-
"const-error": string;
|
|
139
|
-
"contains-any-error": string;
|
|
140
|
-
"contains-array-error": string;
|
|
141
|
-
"contains-error": string;
|
|
142
|
-
"contains-min-error": string;
|
|
143
|
-
"contains-max-error": string;
|
|
144
|
-
"enum-error": string;
|
|
145
|
-
"exclusive-maximum-error": string;
|
|
146
|
-
"exclusive-minimum-error": string;
|
|
147
|
-
"forbidden-property-error": string;
|
|
148
|
-
"format-date-error": string;
|
|
149
|
-
"format-date-time-error": string;
|
|
150
|
-
"format-duration-error": string;
|
|
151
|
-
"format-email-error": string;
|
|
152
|
-
"format-hostname-error": string;
|
|
153
|
-
"format-ipv4-error": string;
|
|
154
|
-
"format-ipv4-leading-zero-error": string;
|
|
155
|
-
"format-ipv6-error": string;
|
|
156
|
-
"format-ipv6-leading-zero-error": string;
|
|
157
|
-
"format-json-pointer-error": string;
|
|
158
|
-
"format-regex-error": string;
|
|
159
|
-
"format-time-error": string;
|
|
160
|
-
"format-uri-error": string;
|
|
161
|
-
"format-uri-reference-error": string;
|
|
162
|
-
"format-uri-template-error": string;
|
|
163
|
-
"format-url-error": string;
|
|
164
|
-
"format-uuid-error": string;
|
|
165
|
-
"invalid-data-error": string;
|
|
166
|
-
"invalid-property-name-error": string;
|
|
167
|
-
"maximum-error": string;
|
|
168
|
-
"max-items-error": string;
|
|
169
|
-
"max-length-error": string;
|
|
170
|
-
"max-properties-error": string;
|
|
171
|
-
"minimum-error": string;
|
|
172
|
-
"min-items-error": string;
|
|
173
|
-
"min-items-one-error": string;
|
|
174
|
-
"min-length-error": string;
|
|
175
|
-
"min-length-one-error": string;
|
|
176
|
-
"missing-one-of-declarator-error": string;
|
|
177
|
-
"min-properties-error": string;
|
|
178
|
-
"missing-array-item-error": string;
|
|
179
|
-
"missing-dependency-error": string;
|
|
180
|
-
"missing-one-of-property-error": string;
|
|
181
|
-
"multiple-of-error": string;
|
|
182
|
-
"multiple-one-of-error": string;
|
|
183
|
-
"no-additional-properties-error": string;
|
|
184
|
-
"not-error": string;
|
|
185
|
-
"one-of-error": string;
|
|
186
|
-
"one-of-property-error": string;
|
|
187
|
-
"pattern-error": string;
|
|
188
|
-
"pattern-properties-error": string;
|
|
189
|
-
"required-property-error": string; /** return schema-warning with createSchemaWarning:true when a valid, but undefined property was found */
|
|
190
|
-
"schema-warning": string;
|
|
191
|
-
"type-error": string;
|
|
192
|
-
"undefined-value-error": string;
|
|
193
|
-
"unevaluated-property-error": string;
|
|
194
|
-
"unevaluated-items-error": string;
|
|
195
|
-
"unique-items-error": string;
|
|
196
|
-
"unknown-property-error": string;
|
|
197
|
-
"value-not-empty-error": string;
|
|
198
|
-
"deprecated-warning": string;
|
|
199
|
-
};
|
|
200
|
-
//#endregion
|
|
201
|
-
//#region src/SchemaNode.d.ts
|
|
202
|
-
declare function isSchemaNode(value: unknown): value is SchemaNode;
|
|
203
|
-
declare function isReduceable(node: SchemaNode): boolean;
|
|
204
|
-
type Context = {
|
|
205
|
-
/** root node of this JSON Schema */rootNode: SchemaNode; /** available draft configurations */
|
|
206
|
-
drafts: Draft[]; /** [SHARED ACROSS REMOTES] root nodes of registered remote JSON Schema, stored by id/url */
|
|
207
|
-
remotes: Record<string, SchemaNode>; /** references stored by fully resolved schema-$id + local-pointer */
|
|
208
|
-
refs: Record<string, SchemaNode>; /** anchors stored by fully resolved schema-$id + $anchor */
|
|
209
|
-
anchors: Record<string, SchemaNode>; /** [SHARED ACROSS REMOTES] dynamicAnchors stored by fully resolved schema-$id + $anchor */
|
|
210
|
-
dynamicAnchors: Record<string, SchemaNode>; /** JSON Schema parser, validator, reducer and resolver for this JSON Schema (root schema and its child nodes) */
|
|
211
|
-
keywords: Draft["keywords"]; /** JSON Schema draft dependend methods */
|
|
212
|
-
methods: Draft["methods"]; /** draft version */
|
|
213
|
-
version: Draft["version"]; /** draft errors & template-strings */
|
|
214
|
-
errors: Draft["errors"]; /** draft formats & validators */
|
|
215
|
-
formats: Draft["formats"]; /** [SHARED USING ADD REMOTE] getData default options */
|
|
216
|
-
getDataDefaultOptions?: TemplateOptions;
|
|
217
|
-
};
|
|
218
|
-
interface SchemaNode extends SchemaNodeMethodsType {
|
|
219
|
-
/** shared context across nodes of JSON schema and shared properties across all remotes */
|
|
220
|
-
context: Context;
|
|
221
|
-
/** JSON Schema of node */
|
|
222
|
-
schema: JsonSchema;
|
|
223
|
-
/**
|
|
224
|
-
* Evaluation Path - The location of the keyword that produced the annotation or error.
|
|
225
|
-
* The purpose of this data is to show the resolution path which resulted in the subschema
|
|
226
|
-
* that contains the keyword.
|
|
227
|
-
*
|
|
228
|
-
* - relative to the root of the principal schema; should include (inline) any $ref segments in the path
|
|
229
|
-
* - JSON pointer
|
|
230
|
-
*/
|
|
231
|
-
evaluationPath: string;
|
|
232
|
-
/**
|
|
233
|
-
* Schema Location - The direct location to the keyword that produced the annotation
|
|
234
|
-
* or error. This is provided as a convenience to the user so that they don't have to resolve
|
|
235
|
-
* the keyword's subschema, which may not be trivial task. It is only provided if the relative
|
|
236
|
-
* location contains $refs (otherwise, the two locations will be the same).
|
|
237
|
-
*
|
|
238
|
-
* - absolute URI
|
|
239
|
-
* - may not have any association to the principal schema
|
|
240
|
-
*/
|
|
241
|
-
schemaLocation: string;
|
|
242
|
-
/** id created when combining subschemas */
|
|
243
|
-
dynamicId: string;
|
|
244
|
-
/** reference to parent node (node used to compile this node) */
|
|
245
|
-
parent?: SchemaNode | undefined;
|
|
246
|
-
/** JSON Pointer from last $id ~~to this location~~ to resolve $refs to $id#/idLocalPointer */
|
|
247
|
-
lastIdPointer: string;
|
|
248
|
-
/** when reduced schema containing `oneOf` schema, `oneOfIndex` stores `oneOf`-item used for merge */
|
|
249
|
-
oneOfIndex?: number;
|
|
250
|
-
reducers: JsonSchemaReducer[];
|
|
251
|
-
resolvers: JsonSchemaResolver[];
|
|
252
|
-
validators: JsonSchemaValidator[];
|
|
253
|
-
$id?: string;
|
|
254
|
-
$defs?: Record<string, SchemaNode>;
|
|
255
|
-
$ref?: string;
|
|
256
|
-
additionalProperties?: SchemaNode;
|
|
257
|
-
allOf?: SchemaNode[];
|
|
258
|
-
anyOf?: SchemaNode[];
|
|
259
|
-
contains?: SchemaNode;
|
|
260
|
-
dependentRequired?: Record<string, string[]>;
|
|
261
|
-
dependentSchemas?: Record<string, SchemaNode | boolean>;
|
|
262
|
-
else?: SchemaNode;
|
|
263
|
-
if?: SchemaNode;
|
|
264
|
-
/**
|
|
265
|
-
* # Items-array schema - for all drafts
|
|
266
|
-
*
|
|
267
|
-
* - for drafts prior 2020-12 `schema.items[]`-schema stored as `node.prefixItems`
|
|
268
|
-
*
|
|
269
|
-
* Validation succeeds if each element of the instance validates against the schema at the
|
|
270
|
-
* same position, if any.
|
|
271
|
-
*
|
|
272
|
-
* The `prefixItems` keyword restricts a number of items from the start of an array instance
|
|
273
|
-
* to validate against the given sequence of subschemas, where the item at a given index in
|
|
274
|
-
* the array instance is evaluated against the subschema at the given index in the `prefixItems`
|
|
275
|
-
* array, if any. Array items outside the range described by the `prefixItems` keyword is
|
|
276
|
-
* evaluated against the items keyword, if present.
|
|
277
|
-
*
|
|
278
|
-
* [Docs](https://www.learnjsonschema.com/2020-12/applicator/prefixitems/)
|
|
279
|
-
* | [Examples](https://json-schema.org/understanding-json-schema/reference/array#tupleValidation)
|
|
280
|
-
*/
|
|
281
|
-
prefixItems?: SchemaNode[];
|
|
282
|
-
/**
|
|
283
|
-
* # Items-object schema for additional array item - for all drafts
|
|
284
|
-
*
|
|
285
|
-
* - for drafts prior 2020-12 `schema.additionalItems` object-schema stored as `node.items`
|
|
286
|
-
*
|
|
287
|
-
* Validation succeeds if each element of the instance not covered by `prefixItems` validates
|
|
288
|
-
* against this schema.
|
|
289
|
-
*
|
|
290
|
-
* The items keyword restricts array instance items not described by the sibling `prefixItems`
|
|
291
|
-
* keyword (if any), to validate against the given subschema. Whetherthis keyword was evaluated
|
|
292
|
-
* against any item of the array instance is reported using annotations.
|
|
293
|
-
*
|
|
294
|
-
* [Docs](https://www.learnjsonschema.com/2020-12/applicator/items/)
|
|
295
|
-
* | [Examples](https://json-schema.org/understanding-json-schema/reference/array#items)
|
|
296
|
-
* | [AdditionalItems Specification](https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#additionalItems)
|
|
297
|
-
*/
|
|
298
|
-
items?: SchemaNode;
|
|
299
|
-
not?: SchemaNode;
|
|
300
|
-
oneOf?: SchemaNode[];
|
|
301
|
-
patternProperties?: {
|
|
302
|
-
name: string;
|
|
303
|
-
pattern: RegExp;
|
|
304
|
-
node: SchemaNode;
|
|
305
|
-
}[];
|
|
306
|
-
properties?: Record<string, SchemaNode>;
|
|
307
|
-
propertyNames?: SchemaNode;
|
|
308
|
-
then?: SchemaNode;
|
|
309
|
-
unevaluatedItems?: SchemaNode;
|
|
310
|
-
unevaluatedProperties?: SchemaNode;
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Fixed SchemaNode mixin methods
|
|
314
|
-
*/
|
|
315
|
-
interface SchemaNodeMethodsType {
|
|
316
|
-
compileSchema(schema: JsonSchema | BooleanSchema, evaluationPath?: string, schemaLocation?: string, dynamicId?: string): SchemaNode;
|
|
317
|
-
createError<T extends string = DefaultErrors>(code: T, data: AnnotationData, message?: string): JsonError;
|
|
318
|
-
createAnnotation<T extends string = DefaultErrors>(code: T, data: AnnotationData, message?: string): JsonAnnotation;
|
|
319
|
-
createSchema(data?: unknown): JsonSchema;
|
|
320
|
-
/**
|
|
321
|
-
* Returns a node matching the given location (pointer) in data
|
|
322
|
-
*
|
|
323
|
-
* - the returned node will have a **reduced schema** based on given input data
|
|
324
|
-
* - return returned node $ref is resolved
|
|
325
|
-
*
|
|
326
|
-
* To resolve dynamic schema where the type of JSON Schema is evaluated by
|
|
327
|
-
* its value, a data object has to be passed in options.
|
|
328
|
-
*
|
|
329
|
-
* Per default this function will return `undefined` schema for valid properties
|
|
330
|
-
* that do not have a defined schema. Use the option `withSchemaWarning: true` to
|
|
331
|
-
* receive an error with `code: schema-warning` containing the location of its
|
|
332
|
-
* last evaluated json-schema.
|
|
333
|
-
*
|
|
334
|
-
* @returns { node } or { error } where node can also be undefined (valid but undefined)
|
|
335
|
-
*/
|
|
336
|
-
getNode(pointer: string, data: unknown, options: {
|
|
337
|
-
withSchemaWarning: true;
|
|
338
|
-
} & GetNodeOptions): NodeOrError;
|
|
339
|
-
getNode(pointer: string, data: unknown, options: {
|
|
340
|
-
createSchema: true;
|
|
341
|
-
} & GetNodeOptions): NodeOrError;
|
|
342
|
-
getNode(pointer: string, data?: unknown, options?: GetNodeOptions): OptionalNodeOrError;
|
|
343
|
-
/**
|
|
344
|
-
* Returns the child for the given property-name or array-index
|
|
345
|
-
*
|
|
346
|
-
* - the returned child node is **not reduced**
|
|
347
|
-
* - a child node $ref is resolved
|
|
348
|
-
*
|
|
349
|
-
* @returns { node } or { error } where node can also be undefined (valid but undefined)
|
|
350
|
-
*/
|
|
351
|
-
getNodeChild(key: string | number, data: unknown, options: {
|
|
352
|
-
withSchemaWarning: true;
|
|
353
|
-
} & GetNodeOptions): NodeOrError;
|
|
354
|
-
getNodeChild(key: string | number, data: unknown, options: {
|
|
355
|
-
createSchema: true;
|
|
356
|
-
} & GetNodeOptions): NodeOrError;
|
|
357
|
-
getNodeChild(key: string | number, data?: unknown, options?: GetNodeOptions): OptionalNodeOrError;
|
|
358
|
-
getChildSelection(property: string | number): JsonError | SchemaNode[];
|
|
359
|
-
getNodeRef($ref: string): SchemaNode | undefined;
|
|
360
|
-
getNodeRoot(): SchemaNode;
|
|
361
|
-
getDraftVersion(): string;
|
|
362
|
-
getData(data?: unknown, options?: TemplateOptions): any;
|
|
363
|
-
reduceNode(data: unknown, options?: {
|
|
364
|
-
key?: string | number;
|
|
365
|
-
pointer?: string;
|
|
366
|
-
path?: ValidationPath;
|
|
367
|
-
}): OptionalNodeOrError;
|
|
368
|
-
resolveRef: (args?: {
|
|
369
|
-
pointer?: string;
|
|
370
|
-
path?: ValidationPath;
|
|
371
|
-
}) => SchemaNode;
|
|
372
|
-
validate(data: unknown, pointer?: string, path?: ValidationPath): ValidateReturnType;
|
|
373
|
-
addRemoteSchema(url: string, schema: JsonSchema | BooleanSchema): SchemaNode;
|
|
374
|
-
toSchemaNodes(): SchemaNode[];
|
|
375
|
-
toDataNodes(data: unknown, pointer?: string): DataNode[];
|
|
376
|
-
toJSON(): unknown;
|
|
377
|
-
}
|
|
378
|
-
type GetNodeOptions = {
|
|
379
|
-
/**
|
|
380
|
-
* Per default `undefined` is returned for valid data, but undefined schema.
|
|
381
|
-
*
|
|
382
|
-
* - Using `withSchemaWarning:true` will return an error instead: `{ type: "error", code: "schema-warning" }`
|
|
383
|
-
*/
|
|
384
|
-
withSchemaWarning?: boolean;
|
|
385
|
-
/**
|
|
386
|
-
* Per default `undefined` is returned for valid data, but undefined schema.
|
|
387
|
-
*
|
|
388
|
-
* - Using `createSchema:true` will create a schema instead
|
|
389
|
-
*/
|
|
390
|
-
createSchema?: boolean;
|
|
391
|
-
path?: ValidationPath;
|
|
392
|
-
pointer?: string;
|
|
393
|
-
};
|
|
394
|
-
type ValidateReturnType = {
|
|
395
|
-
/**
|
|
396
|
-
* True, if data is valid to the compiled schema.
|
|
397
|
-
* Does not include async errors.
|
|
398
|
-
*/
|
|
399
|
-
valid: boolean;
|
|
400
|
-
/**
|
|
401
|
-
* List of validation errors or empty
|
|
402
|
-
*/
|
|
403
|
-
errors: JsonError[];
|
|
404
|
-
/**
|
|
405
|
-
* List of annotations from validators
|
|
406
|
-
*/
|
|
407
|
-
annotations: JsonAnnotation[];
|
|
408
|
-
/**
|
|
409
|
-
* List of Promises resolving to `JsonError|undefined` or empty.
|
|
410
|
-
*/
|
|
411
|
-
errorsAsync: Promise<Maybe<ValidationAnnotation>[]>[];
|
|
412
|
-
};
|
|
413
|
-
//#endregion
|
|
414
|
-
//#region src/types.d.ts
|
|
415
|
-
type BooleanSchema = boolean;
|
|
416
|
-
interface JsonSchema {
|
|
417
|
-
[keyword: string]: any;
|
|
418
|
-
}
|
|
419
|
-
declare function isJsonSchema(value: unknown): value is JsonSchema;
|
|
420
|
-
declare function isBooleanSchema(value: unknown): value is BooleanSchema;
|
|
421
|
-
type JsonPointer = string;
|
|
422
|
-
type AnnotationData<D extends Record<string, unknown> = Record<string, unknown>> = D & {
|
|
423
|
-
pointer: string;
|
|
424
|
-
schema: JsonSchema;
|
|
425
|
-
value: unknown;
|
|
426
|
-
};
|
|
427
|
-
type Annotation<T = string, D extends AnnotationData = AnnotationData, S = string> = {
|
|
428
|
-
type: T;
|
|
429
|
-
code: S;
|
|
430
|
-
message: string;
|
|
431
|
-
data: D;
|
|
432
|
-
[p: string]: unknown;
|
|
433
|
-
};
|
|
434
|
-
type DefaultErrors = keyof typeof errors;
|
|
435
|
-
type ErrorConfig = Record<DefaultErrors | string, string | ((error: AnnotationData) => void)>;
|
|
436
|
-
type OptionalNodeOrError = {
|
|
437
|
-
node?: SchemaNode;
|
|
438
|
-
error: undefined;
|
|
439
|
-
} | {
|
|
440
|
-
node: undefined;
|
|
441
|
-
error?: JsonError;
|
|
442
|
-
};
|
|
443
|
-
type NodeOrError = {
|
|
444
|
-
node: SchemaNode;
|
|
445
|
-
error: undefined;
|
|
446
|
-
} | {
|
|
447
|
-
node: undefined;
|
|
448
|
-
error: JsonError;
|
|
449
|
-
};
|
|
450
|
-
type JsonError<D extends AnnotationData = AnnotationData> = Annotation<"error", D, ErrorConfig | string>;
|
|
451
|
-
type JsonAnnotation<D extends AnnotationData = AnnotationData> = Annotation<"annotation", D>;
|
|
452
|
-
declare function isAnnotation(value: any): value is Annotation;
|
|
453
|
-
/**
|
|
454
|
-
* ts type guard for json error
|
|
455
|
-
* @returns true if passed type is a JsonError
|
|
456
|
-
*/
|
|
457
|
-
declare function isJsonAnnotation(error: unknown): error is JsonAnnotation;
|
|
458
|
-
/**
|
|
459
|
-
* ts type guard for json error
|
|
460
|
-
* @returns true if passed type is a JsonError
|
|
461
|
-
*/
|
|
462
|
-
declare function isJsonError(error: unknown): error is JsonError;
|
|
463
|
-
//#endregion
|
|
1
|
+
import { A as JsonSchemaResolver, C as DraftVersion, D as DataNode, E as TemplateOptions, F as Maybe, I as ValidationAnnotation, L as ValidationPath, M as JsonSchemaValidator, N as JsonSchemaValidatorParams, O as JsonSchemaReducer, P as Keyword, R as ValidationReturnType, S as Draft, T as extendDraft, _ as GetNodeOptions, a as JsonAnnotation, b as isReduceable, c as JsonSchema, d as isAnnotation, f as isBooleanSchema, g as Context, h as isJsonSchema, i as ErrorConfig, j as JsonSchemaResolverParams, k as JsonSchemaReducerParams, l as NodeOrError, m as isJsonError, n as AnnotationData, o as JsonError, p as isJsonAnnotation, r as BooleanSchema, s as JsonPointer, t as Annotation, u as OptionalNodeOrError, v as SchemaNode, w as addKeywords, x as isSchemaNode, y as ValidateReturnType } from "./types-BhTU1l2h.mjs";
|
|
2
|
+
|
|
464
3
|
//#region src/compileSchema.d.ts
|
|
465
4
|
type CompileOptions = {
|
|
466
5
|
drafts?: Draft[];
|
|
467
6
|
remote?: SchemaNode;
|
|
468
7
|
formatAssertion?: boolean | "meta-schema" | undefined;
|
|
469
|
-
getDataDefaultOptions?: TemplateOptions;
|
|
8
|
+
getDataDefaultOptions?: TemplateOptions; /** set to true to throw an Error on errors in input schema. Defaults to false */
|
|
9
|
+
throwOnInvalidSchema?: boolean; /** set to true to collect unknown keywords of input schema in `node.schemaAnnotations`. Defaults to false */
|
|
10
|
+
withSchemaAnnotations?: boolean; /** set to true to throw an Error when encountering an unresolvable ref */
|
|
11
|
+
throwOnInvalidRef?: boolean;
|
|
470
12
|
};
|
|
471
13
|
/**
|
|
472
14
|
* With compileSchema we replace the schema and all sub-schemas with a schemaNode,
|
|
473
15
|
* wrapping each schema with utilities and as much preevaluation as possible. Each
|
|
474
16
|
* node will be reused for each task, but will create a compiledNode for bound data.
|
|
475
17
|
*/
|
|
476
|
-
declare function compileSchema(schema: JsonSchema | BooleanSchema, options?: CompileOptions): SchemaNode
|
|
18
|
+
declare function compileSchema(schema: JsonSchema | BooleanSchema, options?: CompileOptions): SchemaNode & {
|
|
19
|
+
schemaErrors?: JsonError[];
|
|
20
|
+
schemaAnnotations: JsonAnnotation[];
|
|
21
|
+
};
|
|
477
22
|
//#endregion
|
|
478
23
|
//#region src/settings.d.ts
|
|
479
24
|
declare const _default: {
|
|
@@ -601,6 +146,34 @@ declare const draftEditor: Draft;
|
|
|
601
146
|
declare const oneOfKeyword: Keyword;
|
|
602
147
|
declare const oneOfFuzzyKeyword: Keyword;
|
|
603
148
|
//#endregion
|
|
149
|
+
//#region src/keywords/propertyDependencies.d.ts
|
|
150
|
+
/**
|
|
151
|
+
* @experimental `propertyDependencies` to resolve schema by nested name and value
|
|
152
|
+
* @reference https://docs.google.com/presentation/d/1ajXlCQcsjjiMLsluFIILR7sN5aDRBnfqQ9DLbcFbqjI/mobilepresent?slide=id.p
|
|
153
|
+
*
|
|
154
|
+
* - matching schemas are resolved and validiated
|
|
155
|
+
* - multiple matching schemas are resolved and validiated
|
|
156
|
+
* - ignores keyword if no schema is matched
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* {
|
|
160
|
+
* type: "object",
|
|
161
|
+
* propertyDependencies: {
|
|
162
|
+
* propertyName: {
|
|
163
|
+
* propertyValue: { $ref: "#/$defs/schema" }
|
|
164
|
+
* }
|
|
165
|
+
* }
|
|
166
|
+
* }
|
|
167
|
+
*
|
|
168
|
+
* matches
|
|
169
|
+
*
|
|
170
|
+
* {
|
|
171
|
+
* "propertyName": "propertyValue",
|
|
172
|
+
* "otherData": 123
|
|
173
|
+
* } with "#/$defs/schema"
|
|
174
|
+
*/
|
|
175
|
+
declare const propertyDependenciesKeyword: Keyword;
|
|
176
|
+
//#endregion
|
|
604
177
|
//#region src/errors/render.d.ts
|
|
605
178
|
declare function render(template: string, data?: Record<string, unknown>): string;
|
|
606
179
|
//#endregion
|
|
@@ -630,8 +203,4 @@ declare function getSchemaType(node: SchemaNode, data: unknown): SchemaType | un
|
|
|
630
203
|
*/
|
|
631
204
|
declare function sanitizeErrors(list: ValidationReturnType | ValidationReturnType[] | ValidationAnnotation[], result?: ValidationAnnotation[]): ValidationAnnotation[];
|
|
632
205
|
//#endregion
|
|
633
|
-
|
|
634
|
-
/** remote meta-schema stored by schema $id */
|
|
635
|
-
declare const remotes: Record<string, any>;
|
|
636
|
-
//#endregion
|
|
637
|
-
export { type Annotation, type AnnotationData, type BooleanSchema, type CompileOptions, type Context, type DataNode, type Draft, type DraftVersion, type ErrorConfig, type GetNodeOptions, type JsonAnnotation, type JsonError, type JsonPointer, type JsonSchema, type JsonSchemaReducer, type JsonSchemaReducerParams, type JsonSchemaResolver, type JsonSchemaResolverParams, type JsonSchemaValidator, type JsonSchemaValidatorParams, type Keyword, type Maybe, type NodeOrError, type OptionalNodeOrError, type SchemaNode, type ValidateReturnType, type ValidationAnnotation, type ValidationPath, type ValidationReturnType, addKeywords, compileSchema, draft04, draft06, draft07, draft2019, draft2020, draftEditor, extendDraft, getSchemaType, getTypeOf, isAnnotation, isBooleanSchema, isJsonAnnotation, isJsonError, isJsonSchema, isReduceable, isSchemaNode, mergeNode, mergeSchema, oneOfFuzzyKeyword, oneOfKeyword, remotes, render, sanitizeErrors, _default as settings };
|
|
206
|
+
export { type Annotation, type AnnotationData, type BooleanSchema, type CompileOptions, type Context, type DataNode, type Draft, type DraftVersion, type ErrorConfig, type GetNodeOptions, type JsonAnnotation, type JsonError, type JsonPointer, type JsonSchema, type JsonSchemaReducer, type JsonSchemaReducerParams, type JsonSchemaResolver, type JsonSchemaResolverParams, type JsonSchemaValidator, type JsonSchemaValidatorParams, type Keyword, type Maybe, type NodeOrError, type OptionalNodeOrError, type SchemaNode, type ValidateReturnType, type ValidationAnnotation, type ValidationPath, type ValidationReturnType, addKeywords, compileSchema, draft04, draft06, draft07, draft2019, draft2020, draftEditor, extendDraft, getSchemaType, getTypeOf, isAnnotation, isBooleanSchema, isJsonAnnotation, isJsonError, isJsonSchema, isReduceable, isSchemaNode, mergeNode, mergeSchema, oneOfFuzzyKeyword, oneOfKeyword, propertyDependenciesKeyword, render, sanitizeErrors, _default as settings };
|