z-schema 12.0.4 → 12.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/z-schema +7 -2
- package/cjs/index.d.ts +541 -530
- package/cjs/index.js +3963 -7740
- package/dist/errors.d.mts +64 -0
- package/dist/errors.mjs +67 -0
- package/dist/format-validators.d.mts +14 -0
- package/dist/format-validators.mjs +261 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +7 -0
- package/dist/json-schema-versions.d.mts +137 -0
- package/dist/json-schema-versions.mjs +11 -0
- package/dist/json-schema.d.mts +61 -0
- package/dist/json-schema.mjs +53 -0
- package/dist/json-validation.mjs +441 -0
- package/dist/report.d.mts +97 -0
- package/dist/report.mjs +194 -0
- package/dist/schema-cache.d.mts +23 -0
- package/dist/schema-cache.mjs +144 -0
- package/dist/schema-compiler.d.mts +23 -0
- package/dist/schema-compiler.mjs +265 -0
- package/dist/schema-validator.d.mts +15 -0
- package/dist/schema-validator.mjs +446 -0
- package/dist/schemas/draft-04-schema.mjs +125 -0
- package/dist/schemas/draft-06-schema.mjs +126 -0
- package/dist/schemas/draft-07-schema.mjs +141 -0
- package/dist/schemas/draft-2019-09-meta-applicator.mjs +46 -0
- package/dist/schemas/draft-2019-09-meta-content.mjs +15 -0
- package/dist/schemas/draft-2019-09-meta-core.mjs +52 -0
- package/dist/schemas/draft-2019-09-meta-format.mjs +11 -0
- package/dist/schemas/draft-2019-09-meta-meta-data.mjs +31 -0
- package/dist/schemas/draft-2019-09-meta-validation.mjs +80 -0
- package/dist/schemas/draft-2019-09-schema.mjs +39 -0
- package/dist/schemas/draft-2020-12-meta-applicator.mjs +45 -0
- package/dist/schemas/draft-2020-12-meta-content.mjs +15 -0
- package/dist/schemas/draft-2020-12-meta-core.mjs +46 -0
- package/dist/schemas/draft-2020-12-meta-format-annotation.mjs +11 -0
- package/dist/schemas/draft-2020-12-meta-format-assertion.mjs +11 -0
- package/dist/schemas/draft-2020-12-meta-meta-data.mjs +31 -0
- package/dist/schemas/draft-2020-12-meta-unevaluated.mjs +14 -0
- package/dist/schemas/draft-2020-12-meta-validation.mjs +80 -0
- package/dist/schemas/draft-2020-12-schema.mjs +55 -0
- package/dist/utils/array.mjs +54 -0
- package/dist/utils/base64.mjs +21 -0
- package/dist/utils/clone.mjs +42 -0
- package/dist/utils/constants.mjs +16 -0
- package/dist/utils/date.mjs +19 -0
- package/dist/utils/hostname.mjs +73 -0
- package/dist/utils/json.mjs +34 -0
- package/dist/utils/properties.mjs +11 -0
- package/dist/utils/schema-regex.mjs +49 -0
- package/dist/utils/symbols.mjs +5 -0
- package/dist/utils/time.mjs +42 -0
- package/dist/utils/unicode.mjs +12 -0
- package/dist/utils/uri.mjs +12 -0
- package/dist/utils/what-is.mjs +23 -0
- package/dist/validation/array.mjs +57 -0
- package/dist/validation/combinators.mjs +62 -0
- package/dist/validation/numeric.mjs +38 -0
- package/dist/validation/object.mjs +109 -0
- package/dist/validation/ref.mjs +49 -0
- package/dist/validation/shared.mjs +97 -0
- package/dist/validation/string.mjs +88 -0
- package/dist/validation/type.mjs +32 -0
- package/dist/z-schema-base.d.mts +85 -0
- package/dist/z-schema-base.mjs +230 -0
- package/dist/z-schema-options.d.mts +35 -0
- package/dist/z-schema-options.mjs +55 -0
- package/dist/z-schema-reader.d.mts +6 -0
- package/dist/z-schema-reader.mjs +10 -0
- package/dist/z-schema-versions.mjs +67 -0
- package/dist/z-schema.d.mts +193 -0
- package/dist/z-schema.mjs +300 -0
- package/package.json +49 -64
- package/src/index.ts +3 -3
- package/src/schema-compiler.ts +30 -10
- package/src/schema-validator.ts +1 -1
- package/src/utils/schema-regex.ts +13 -2
- package/src/z-schema-base.ts +1 -1
- package/src/z-schema-versions.ts +1 -2
- package/src/z-schema.ts +0 -1
- package/umd/ZSchema.js +5934 -8110
- package/umd/ZSchema.min.js +2 -1
- package/dist/errors.js +0 -72
- package/dist/format-validators.js +0 -392
- package/dist/index.js +0 -5
- package/dist/json-schema-versions.js +0 -8
- package/dist/json-schema.js +0 -84
- package/dist/json-validation.js +0 -728
- package/dist/package.json +0 -3
- package/dist/report.js +0 -265
- package/dist/schema-cache.js +0 -211
- package/dist/schema-compiler.js +0 -415
- package/dist/schema-validator.js +0 -721
- package/dist/schemas/draft-04-schema.json +0 -149
- package/dist/schemas/draft-06-schema.json +0 -155
- package/dist/schemas/draft-07-schema.json +0 -172
- package/dist/schemas/draft-2019-09-meta-applicator.json +0 -52
- package/dist/schemas/draft-2019-09-meta-content.json +0 -12
- package/dist/schemas/draft-2019-09-meta-core.json +0 -53
- package/dist/schemas/draft-2019-09-meta-format.json +0 -10
- package/dist/schemas/draft-2019-09-meta-meta-data.json +0 -32
- package/dist/schemas/draft-2019-09-meta-validation.json +0 -94
- package/dist/schemas/draft-2019-09-schema.json +0 -41
- package/dist/schemas/draft-2020-12-meta-applicator.json +0 -44
- package/dist/schemas/draft-2020-12-meta-content.json +0 -12
- package/dist/schemas/draft-2020-12-meta-core.json +0 -47
- package/dist/schemas/draft-2020-12-meta-format-annotation.json +0 -10
- package/dist/schemas/draft-2020-12-meta-format-assertion.json +0 -10
- package/dist/schemas/draft-2020-12-meta-meta-data.json +0 -32
- package/dist/schemas/draft-2020-12-meta-unevaluated.json +0 -11
- package/dist/schemas/draft-2020-12-meta-validation.json +0 -94
- package/dist/schemas/draft-2020-12-schema.json +0 -57
- package/dist/types/errors.d.ts +0 -64
- package/dist/types/format-validators.d.ts +0 -11
- package/dist/types/index.d.ts +0 -14
- package/dist/types/json-schema-versions.d.ts +0 -142
- package/dist/types/json-schema.d.ts +0 -66
- package/dist/types/json-validation.d.ts +0 -6
- package/dist/types/report.d.ts +0 -94
- package/dist/types/schema-cache.d.ts +0 -27
- package/dist/types/schema-compiler.d.ts +0 -31
- package/dist/types/schema-validator.d.ts +0 -10
- package/dist/types/utils/array.d.ts +0 -9
- package/dist/types/utils/base64.d.ts +0 -2
- package/dist/types/utils/clone.d.ts +0 -2
- package/dist/types/utils/constants.d.ts +0 -19
- package/dist/types/utils/date.d.ts +0 -1
- package/dist/types/utils/hostname.d.ts +0 -2
- package/dist/types/utils/json.d.ts +0 -9
- package/dist/types/utils/properties.d.ts +0 -1
- package/dist/types/utils/schema-regex.d.ts +0 -10
- package/dist/types/utils/symbols.d.ts +0 -2
- package/dist/types/utils/time.d.ts +0 -12
- package/dist/types/utils/unicode.d.ts +0 -5
- package/dist/types/utils/uri.d.ts +0 -4
- package/dist/types/utils/what-is.d.ts +0 -4
- package/dist/types/validation/array.d.ts +0 -12
- package/dist/types/validation/combinators.d.ts +0 -10
- package/dist/types/validation/numeric.d.ts +0 -8
- package/dist/types/validation/object.d.ts +0 -13
- package/dist/types/validation/ref.d.ts +0 -11
- package/dist/types/validation/shared.d.ts +0 -26
- package/dist/types/validation/string.d.ts +0 -9
- package/dist/types/validation/type.d.ts +0 -6
- package/dist/types/z-schema-base.d.ts +0 -87
- package/dist/types/z-schema-options.d.ts +0 -35
- package/dist/types/z-schema-reader.d.ts +0 -4
- package/dist/types/z-schema-versions.d.ts +0 -1
- package/dist/types/z-schema.d.ts +0 -191
- package/dist/utils/array.js +0 -69
- package/dist/utils/base64.js +0 -29
- package/dist/utils/clone.js +0 -59
- package/dist/utils/constants.js +0 -19
- package/dist/utils/date.js +0 -21
- package/dist/utils/hostname.js +0 -146
- package/dist/utils/json.js +0 -70
- package/dist/utils/properties.js +0 -10
- package/dist/utils/schema-regex.js +0 -52
- package/dist/utils/symbols.js +0 -2
- package/dist/utils/time.js +0 -50
- package/dist/utils/unicode.js +0 -12
- package/dist/utils/uri.js +0 -15
- package/dist/utils/what-is.js +0 -32
- package/dist/validation/array.js +0 -127
- package/dist/validation/combinators.js +0 -106
- package/dist/validation/numeric.js +0 -97
- package/dist/validation/object.js +0 -237
- package/dist/validation/ref.js +0 -70
- package/dist/validation/shared.js +0 -136
- package/dist/validation/string.js +0 -170
- package/dist/validation/type.js +0 -55
- package/dist/z-schema-base.js +0 -286
- package/dist/z-schema-options.js +0 -99
- package/dist/z-schema-reader.js +0 -7
- package/dist/z-schema-versions.js +0 -110
- package/dist/z-schema.js +0 -287
package/dist/z-schema.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import './z-schema-versions.js';
|
|
2
|
-
import { getRegisteredFormats, registerFormat, unregisterFormat } from './format-validators.js';
|
|
3
|
-
import { prepareRemoteSchema, SchemaCache } from './schema-cache.js';
|
|
4
|
-
import { deepClone } from './utils/clone.js';
|
|
5
|
-
import { jsonSymbol, schemaSymbol } from './utils/symbols.js';
|
|
6
|
-
import { FACTORY_TOKEN, ZSchemaBase } from './z-schema-base.js';
|
|
7
|
-
import { defaultOptions } from './z-schema-options.js';
|
|
8
|
-
import { getSchemaReader, setSchemaReader } from './z-schema-reader.js';
|
|
9
|
-
export class ZSchema extends ZSchemaBase {
|
|
10
|
-
/** @internal Use ZSchema.create() instead. */
|
|
11
|
-
constructor(options, token) {
|
|
12
|
-
super(options, token);
|
|
13
|
-
}
|
|
14
|
-
// ----- static methods start -----
|
|
15
|
-
// class scoped format functions
|
|
16
|
-
/**
|
|
17
|
-
* Register a global format validator available to all instances.
|
|
18
|
-
* @param name - The format name (e.g. `'email'`, `'date'`).
|
|
19
|
-
* @param validatorFunction - A sync or async function `(value: unknown) => boolean | Promise<boolean>`.
|
|
20
|
-
*/
|
|
21
|
-
static registerFormat(name, validatorFunction) {
|
|
22
|
-
return registerFormat(name, validatorFunction);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Remove a globally registered format validator.
|
|
26
|
-
* @param name - The format name to unregister.
|
|
27
|
-
*/
|
|
28
|
-
static unregisterFormat(name) {
|
|
29
|
-
return unregisterFormat(name);
|
|
30
|
-
}
|
|
31
|
-
/** Returns the names of all globally registered format validators. */
|
|
32
|
-
static getRegisteredFormats() {
|
|
33
|
-
return getRegisteredFormats();
|
|
34
|
-
}
|
|
35
|
-
/** Returns a deep clone of the default options. */
|
|
36
|
-
static getDefaultOptions() {
|
|
37
|
-
return deepClone(defaultOptions);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Register a remote schema in the global cache so any instance can resolve `$ref` to it.
|
|
41
|
-
* @param uri - The URI the schema will be known by.
|
|
42
|
-
* @param schema - The schema object or JSON string.
|
|
43
|
-
* @param validationOptions - Optional options used for schema preparation.
|
|
44
|
-
*/
|
|
45
|
-
static setRemoteReference(uri, schema, validationOptions) {
|
|
46
|
-
const _schema = prepareRemoteSchema(schema, uri, validationOptions);
|
|
47
|
-
SchemaCache.cacheSchemaByUri(uri, _schema);
|
|
48
|
-
}
|
|
49
|
-
/** Returns the current global schema reader, or `undefined` if none is set. */
|
|
50
|
-
static getSchemaReader() {
|
|
51
|
-
return getSchemaReader();
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Set a global schema reader function used to resolve remote `$ref` URIs.
|
|
55
|
-
* @param schemaReader - A function `(uri: string) => JsonSchema | undefined`, or `undefined` to clear.
|
|
56
|
-
*/
|
|
57
|
-
static setSchemaReader(schemaReader) {
|
|
58
|
-
return setSchemaReader(schemaReader);
|
|
59
|
-
}
|
|
60
|
-
static schemaSymbol = schemaSymbol;
|
|
61
|
-
static jsonSymbol = jsonSymbol;
|
|
62
|
-
static create(options = {}) {
|
|
63
|
-
const isAsync = options.async;
|
|
64
|
-
const isSafe = options.safe;
|
|
65
|
-
delete options.async;
|
|
66
|
-
delete options.safe;
|
|
67
|
-
if (isAsync && isSafe) {
|
|
68
|
-
return new ZSchemaAsyncSafe(options, FACTORY_TOKEN);
|
|
69
|
-
}
|
|
70
|
-
if (isAsync) {
|
|
71
|
-
return new ZSchemaAsync(options, FACTORY_TOKEN);
|
|
72
|
-
}
|
|
73
|
-
if (isSafe) {
|
|
74
|
-
return new ZSchemaSafe(options, FACTORY_TOKEN);
|
|
75
|
-
}
|
|
76
|
-
return new ZSchema(options, FACTORY_TOKEN);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Validate JSON data against a schema.
|
|
80
|
-
* @param json - The data to validate.
|
|
81
|
-
* @param schema - A JSON Schema object or a schema id string (previously registered via `validateSchema`).
|
|
82
|
-
* @param options - Per-call options (`schemaPath`, `includeErrors`, `excludeErrors`).
|
|
83
|
-
* @returns `true` if valid.
|
|
84
|
-
* @throws {@link ValidateError} if validation fails, with a `details` array of structured errors.
|
|
85
|
-
*/
|
|
86
|
-
validate(json, schema, options = {}) {
|
|
87
|
-
return this._validate(json, schema, options);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Validate JSON data against a schema, returning a result object instead of throwing.
|
|
91
|
-
* @param json - The data to validate.
|
|
92
|
-
* @param schema - A JSON Schema object or a schema id string.
|
|
93
|
-
* @param options - Per-call options.
|
|
94
|
-
* @returns `{ valid: true }` on success, or `{ valid: false, err: ValidateError }` on failure.
|
|
95
|
-
*/
|
|
96
|
-
validateSafe(json, schema, options) {
|
|
97
|
-
try {
|
|
98
|
-
this._validate(json, schema, options ?? {});
|
|
99
|
-
return { valid: true };
|
|
100
|
-
}
|
|
101
|
-
catch (err) {
|
|
102
|
-
return { valid: false, err: err };
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Validate JSON data against a schema asynchronously (supports async format validators).
|
|
107
|
-
* @param json - The data to validate.
|
|
108
|
-
* @param schema - A JSON Schema object or a schema id string.
|
|
109
|
-
* @param options - Per-call options.
|
|
110
|
-
* @returns A promise that resolves to `true` if valid.
|
|
111
|
-
* @throws {@link ValidateError} if validation fails (the promise rejects).
|
|
112
|
-
*/
|
|
113
|
-
validateAsync(json, schema, options) {
|
|
114
|
-
return new Promise((resolve, reject) => {
|
|
115
|
-
try {
|
|
116
|
-
this._validate(json, schema, options || {}, (err, valid) => err || valid !== true ? reject(err) : resolve(valid));
|
|
117
|
-
}
|
|
118
|
-
catch (err) {
|
|
119
|
-
reject(err);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Validate JSON data against a schema asynchronously, returning a result object.
|
|
125
|
-
* The promise always resolves (never rejects).
|
|
126
|
-
* @param json - The data to validate.
|
|
127
|
-
* @param schema - A JSON Schema object or a schema id string.
|
|
128
|
-
* @param options - Per-call options.
|
|
129
|
-
* @returns A promise resolving to `{ valid: true }` or `{ valid: false, err: ValidateError }`.
|
|
130
|
-
*/
|
|
131
|
-
validateAsyncSafe(json, schema, options) {
|
|
132
|
-
return new Promise((resolve) => {
|
|
133
|
-
try {
|
|
134
|
-
this._validate(json, schema, options || {}, (err, valid) => {
|
|
135
|
-
resolve({ valid, err });
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
catch (err) {
|
|
139
|
-
resolve({ valid: false, err: err });
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Validate one or more JSON Schemas, compiling and caching them for later use with `validate()`.
|
|
145
|
-
* @param schemaOrArr - A single schema or an array of schemas (for cross-referencing).
|
|
146
|
-
* @returns `true` if all schemas are valid.
|
|
147
|
-
* @throws {@link ValidateError} if any schema is invalid.
|
|
148
|
-
*/
|
|
149
|
-
validateSchema(schemaOrArr) {
|
|
150
|
-
return this._validateSchema(schemaOrArr);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Validate one or more JSON Schemas, returning a result object instead of throwing.
|
|
154
|
-
* @param schemaOrArr - A single schema or an array of schemas.
|
|
155
|
-
* @returns `{ valid: true }` on success, or `{ valid: false, err: ValidateError }` on failure.
|
|
156
|
-
*/
|
|
157
|
-
validateSchemaSafe(schemaOrArr) {
|
|
158
|
-
try {
|
|
159
|
-
this._validateSchema(schemaOrArr);
|
|
160
|
-
return { valid: true };
|
|
161
|
-
}
|
|
162
|
-
catch (err) {
|
|
163
|
-
return { valid: false, err: err };
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Synchronous safe validator — `validate()` returns `{ valid, err? }` instead of throwing.
|
|
169
|
-
* Created via `ZSchema.create({ safe: true })`.
|
|
170
|
-
*/
|
|
171
|
-
export class ZSchemaSafe extends ZSchemaBase {
|
|
172
|
-
/** @internal Use ZSchema.create() instead. */
|
|
173
|
-
constructor(options, token) {
|
|
174
|
-
super(options, token);
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Validate JSON data against a schema.
|
|
178
|
-
* @param json - The data to validate.
|
|
179
|
-
* @param schema - A JSON Schema object or a schema id string.
|
|
180
|
-
* @param options - Per-call options.
|
|
181
|
-
* @returns `{ valid: true }` on success, or `{ valid: false, err: ValidateError }` on failure.
|
|
182
|
-
*/
|
|
183
|
-
validate(json, schema, options = {}) {
|
|
184
|
-
try {
|
|
185
|
-
this._validate(json, schema, options);
|
|
186
|
-
return { valid: true };
|
|
187
|
-
}
|
|
188
|
-
catch (err) {
|
|
189
|
-
return { valid: false, err: err };
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Validate one or more JSON Schemas.
|
|
194
|
-
* @param schemaOrArr - A single schema or an array of schemas.
|
|
195
|
-
* @returns `{ valid: true }` on success, or `{ valid: false, err: ValidateError }` on failure.
|
|
196
|
-
*/
|
|
197
|
-
validateSchema(schemaOrArr) {
|
|
198
|
-
try {
|
|
199
|
-
this._validateSchema(schemaOrArr);
|
|
200
|
-
return { valid: true };
|
|
201
|
-
}
|
|
202
|
-
catch (err) {
|
|
203
|
-
return { valid: false, err: err };
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Asynchronous throw validator — `validate()` returns `Promise<true>` or rejects.
|
|
209
|
-
* Created via `ZSchema.create({ async: true })`.
|
|
210
|
-
*/
|
|
211
|
-
export class ZSchemaAsync extends ZSchemaBase {
|
|
212
|
-
/** @internal Use ZSchema.create() instead. */
|
|
213
|
-
constructor(options, token) {
|
|
214
|
-
super(options, token);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Validate JSON data against a schema asynchronously.
|
|
218
|
-
* @param json - The data to validate.
|
|
219
|
-
* @param schema - A JSON Schema object or a schema id string.
|
|
220
|
-
* @param options - Per-call options.
|
|
221
|
-
* @returns A promise that resolves to `true` if valid.
|
|
222
|
-
* @throws {@link ValidateError} if validation fails (the promise rejects).
|
|
223
|
-
*/
|
|
224
|
-
validate(json, schema, options = {}) {
|
|
225
|
-
return new Promise((resolve, reject) => {
|
|
226
|
-
try {
|
|
227
|
-
this._validate(json, schema, options, (err, valid) => (err || valid !== true ? reject(err) : resolve(valid)));
|
|
228
|
-
}
|
|
229
|
-
catch (err) {
|
|
230
|
-
reject(err);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Validate one or more JSON Schemas (synchronous, throws on error).
|
|
236
|
-
* @param schemaOrArr - A single schema or an array of schemas.
|
|
237
|
-
* @returns `true` if all schemas are valid.
|
|
238
|
-
* @throws {@link ValidateError} if any schema is invalid.
|
|
239
|
-
*/
|
|
240
|
-
validateSchema(schemaOrArr) {
|
|
241
|
-
return this._validateSchema(schemaOrArr);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Asynchronous safe validator — `validate()` returns `Promise<{ valid, err? }>` (never rejects).
|
|
246
|
-
* Created via `ZSchema.create({ async: true, safe: true })`.
|
|
247
|
-
*/
|
|
248
|
-
export class ZSchemaAsyncSafe extends ZSchemaBase {
|
|
249
|
-
/** @internal Use ZSchema.create() instead. */
|
|
250
|
-
constructor(options, token) {
|
|
251
|
-
super(options, token);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Validate JSON data against a schema asynchronously.
|
|
255
|
-
* The promise always resolves (never rejects).
|
|
256
|
-
* @param json - The data to validate.
|
|
257
|
-
* @param schema - A JSON Schema object or a schema id string.
|
|
258
|
-
* @param options - Per-call options.
|
|
259
|
-
* @returns A promise resolving to `{ valid: true }` or `{ valid: false, err: ValidateError }`.
|
|
260
|
-
*/
|
|
261
|
-
validate(json, schema, options = {}) {
|
|
262
|
-
return new Promise((resolve) => {
|
|
263
|
-
try {
|
|
264
|
-
this._validate(json, schema, options, (err, valid) => {
|
|
265
|
-
resolve({ valid, err });
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
catch (err) {
|
|
269
|
-
resolve({ valid: false, err: err });
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Validate one or more JSON Schemas.
|
|
275
|
-
* @param schemaOrArr - A single schema or an array of schemas.
|
|
276
|
-
* @returns `{ valid: true }` on success, or `{ valid: false, err: ValidateError }` on failure.
|
|
277
|
-
*/
|
|
278
|
-
validateSchema(schemaOrArr) {
|
|
279
|
-
try {
|
|
280
|
-
this._validateSchema(schemaOrArr);
|
|
281
|
-
return { valid: true };
|
|
282
|
-
}
|
|
283
|
-
catch (err) {
|
|
284
|
-
return { valid: false, err: err };
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|