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