z-schema 7.0.0-beta.1 → 7.0.0-beta.3
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 +1 -1
- package/{dist → cjs}/ZSchema.cjs +1 -1
- package/cjs/ZSchema.cjs.d.ts +227 -0
- package/dist/ZSchema.js +1 -2
- package/dist/index.js +2 -0
- package/dist/types/ZSchema.d.ts +2 -2
- package/dist/types/index.d.ts +2 -0
- package/package.json +14 -6
- package/src/ZSchema.ts +1 -3
- package/src/index.ts +3 -0
- package/{dist/ZSchema-umd.js → umd/ZSchema.js} +5 -5
- package/umd/ZSchema.min.js +1 -0
- package/dist/ZSchema-umd-min.js +0 -1
package/bin/z-schema
CHANGED
|
@@ -8,7 +8,7 @@ import path from 'path';
|
|
|
8
8
|
import { program } from 'commander';
|
|
9
9
|
import { request } from 'https';
|
|
10
10
|
import pkg from '../package.json' with { type: 'json' };
|
|
11
|
-
import ZSchema from '../dist/
|
|
11
|
+
import ZSchema from '../dist/index.js';
|
|
12
12
|
|
|
13
13
|
program
|
|
14
14
|
.version(pkg.version)
|
package/{dist → cjs}/ZSchema.cjs
RENAMED
|
@@ -13782,4 +13782,4 @@ class ZSchema {
|
|
|
13782
13782
|
static jsonSymbol = jsonSymbol;
|
|
13783
13783
|
}
|
|
13784
13784
|
|
|
13785
|
-
|
|
13785
|
+
exports.ZSchema = ZSchema;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
interface SchemaError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* Implements the Error.name contract. The value is always "z-schema validation error".
|
|
4
|
+
*/
|
|
5
|
+
name: string;
|
|
6
|
+
/**
|
|
7
|
+
* An identifier indicating the type of error.
|
|
8
|
+
* Example: "JSON_OBJECT_VALIDATION_FAILED"
|
|
9
|
+
*/
|
|
10
|
+
message: string;
|
|
11
|
+
/**
|
|
12
|
+
* Returns details for each error that occurred during validation.
|
|
13
|
+
* See Options.breakOnFirstError.
|
|
14
|
+
*/
|
|
15
|
+
details?: SchemaErrorDetail[];
|
|
16
|
+
}
|
|
17
|
+
interface SchemaErrorDetail {
|
|
18
|
+
/**
|
|
19
|
+
* Example: "Expected type string but found type array"
|
|
20
|
+
*/
|
|
21
|
+
message: string;
|
|
22
|
+
/**
|
|
23
|
+
* An error identifier that can be used to format a custom error message.
|
|
24
|
+
* Example: "INVALID_TYPE"
|
|
25
|
+
*/
|
|
26
|
+
code: string;
|
|
27
|
+
/**
|
|
28
|
+
* Format parameters that can be used to format a custom error message.
|
|
29
|
+
* Example: ["string","array"]
|
|
30
|
+
*/
|
|
31
|
+
params: Array<string>;
|
|
32
|
+
/**
|
|
33
|
+
* A JSON path indicating the location of the error.
|
|
34
|
+
* Example: "#/projects/1"
|
|
35
|
+
*/
|
|
36
|
+
path: string | string[];
|
|
37
|
+
/**
|
|
38
|
+
* The schema rule description, which is included for certain errors where
|
|
39
|
+
* this information is useful (e.g. to describe a constraint).
|
|
40
|
+
*/
|
|
41
|
+
title?: string;
|
|
42
|
+
description?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Returns details for sub-schemas that failed to match. For example, if the schema
|
|
45
|
+
* uses the "oneOf" constraint to accept several alternative possibilities, each
|
|
46
|
+
* alternative will have its own inner detail object explaining why it failed to match.
|
|
47
|
+
*/
|
|
48
|
+
inner?: SchemaErrorDetail[];
|
|
49
|
+
schemaId?: string;
|
|
50
|
+
}
|
|
51
|
+
interface ReportOptions {
|
|
52
|
+
maxErrors?: number;
|
|
53
|
+
}
|
|
54
|
+
type TaskResult = unknown;
|
|
55
|
+
type TaskFn = (...args: unknown[]) => TaskResult;
|
|
56
|
+
type TaskFnArgs = Parameters<TaskFn>;
|
|
57
|
+
type TaskProcessFn = (result: ReturnType<TaskFn>) => void;
|
|
58
|
+
type AsyncTask = [TaskFn, TaskFnArgs, TaskProcessFn];
|
|
59
|
+
declare class Report {
|
|
60
|
+
errors: SchemaErrorDetail[];
|
|
61
|
+
parentReport?: Report;
|
|
62
|
+
options: ZSchemaOptions;
|
|
63
|
+
reportOptions: ReportOptions;
|
|
64
|
+
path: string[];
|
|
65
|
+
asyncTasks: AsyncTask[];
|
|
66
|
+
rootSchema?: {
|
|
67
|
+
id?: string;
|
|
68
|
+
};
|
|
69
|
+
commonErrorMessage?: string;
|
|
70
|
+
json?: unknown;
|
|
71
|
+
constructor(parentOrOptions: any, reportOptions?: any);
|
|
72
|
+
isValid(): boolean;
|
|
73
|
+
addAsyncTask(fn: any, args: any, asyncTaskResultProcessFn: any): void;
|
|
74
|
+
getAncestor(id: any): any;
|
|
75
|
+
processAsyncTasks(timeout: any, callback: any): void;
|
|
76
|
+
getPath(returnPathAsString: any): string | any[];
|
|
77
|
+
getSchemaId(): any;
|
|
78
|
+
hasError(errorCode: any, params: any): boolean;
|
|
79
|
+
addError(errorCode: any, params: any, subReports?: any, schema?: any): void;
|
|
80
|
+
getJson(): any;
|
|
81
|
+
addCustomError(errorCode: string, errorMessage: string, params: string[], subReports?: Report[] | Report, schema?: {
|
|
82
|
+
title?: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
}): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare const Errors: {
|
|
88
|
+
INVALID_TYPE: string;
|
|
89
|
+
INVALID_FORMAT: string;
|
|
90
|
+
ENUM_MISMATCH: string;
|
|
91
|
+
ENUM_CASE_MISMATCH: string;
|
|
92
|
+
ANY_OF_MISSING: string;
|
|
93
|
+
ONE_OF_MISSING: string;
|
|
94
|
+
ONE_OF_MULTIPLE: string;
|
|
95
|
+
NOT_PASSED: string;
|
|
96
|
+
ARRAY_LENGTH_SHORT: string;
|
|
97
|
+
ARRAY_LENGTH_LONG: string;
|
|
98
|
+
ARRAY_UNIQUE: string;
|
|
99
|
+
ARRAY_ADDITIONAL_ITEMS: string;
|
|
100
|
+
MULTIPLE_OF: string;
|
|
101
|
+
MINIMUM: string;
|
|
102
|
+
MINIMUM_EXCLUSIVE: string;
|
|
103
|
+
MAXIMUM: string;
|
|
104
|
+
MAXIMUM_EXCLUSIVE: string;
|
|
105
|
+
OBJECT_PROPERTIES_MINIMUM: string;
|
|
106
|
+
OBJECT_PROPERTIES_MAXIMUM: string;
|
|
107
|
+
OBJECT_MISSING_REQUIRED_PROPERTY: string;
|
|
108
|
+
OBJECT_ADDITIONAL_PROPERTIES: string;
|
|
109
|
+
OBJECT_DEPENDENCY_KEY: string;
|
|
110
|
+
MIN_LENGTH: string;
|
|
111
|
+
MAX_LENGTH: string;
|
|
112
|
+
PATTERN: string;
|
|
113
|
+
KEYWORD_TYPE_EXPECTED: string;
|
|
114
|
+
KEYWORD_UNDEFINED_STRICT: string;
|
|
115
|
+
KEYWORD_UNEXPECTED: string;
|
|
116
|
+
KEYWORD_MUST_BE: string;
|
|
117
|
+
KEYWORD_DEPENDENCY: string;
|
|
118
|
+
KEYWORD_PATTERN: string;
|
|
119
|
+
KEYWORD_VALUE_TYPE: string;
|
|
120
|
+
UNKNOWN_FORMAT: string;
|
|
121
|
+
CUSTOM_MODE_FORCE_PROPERTIES: string;
|
|
122
|
+
REF_UNRESOLVED: string;
|
|
123
|
+
UNRESOLVABLE_REFERENCE: string;
|
|
124
|
+
SCHEMA_NOT_REACHABLE: string;
|
|
125
|
+
SCHEMA_TYPE_EXPECTED: string;
|
|
126
|
+
SCHEMA_NOT_AN_OBJECT: string;
|
|
127
|
+
ASYNC_TIMEOUT: string;
|
|
128
|
+
PARENT_SCHEMA_VALIDATION_FAILED: string;
|
|
129
|
+
REMOTE_NOT_VALID: string;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
interface ZSchemaOptions {
|
|
133
|
+
asyncTimeout?: number;
|
|
134
|
+
forceAdditional?: boolean;
|
|
135
|
+
assumeAdditional?: boolean;
|
|
136
|
+
forceItems?: boolean;
|
|
137
|
+
forceMinItems?: boolean;
|
|
138
|
+
forceMaxItems?: boolean;
|
|
139
|
+
forceMinLength?: boolean;
|
|
140
|
+
forceMaxLength?: boolean;
|
|
141
|
+
forceProperties?: boolean;
|
|
142
|
+
ignoreUnresolvableReferences?: boolean;
|
|
143
|
+
noExtraKeywords?: boolean;
|
|
144
|
+
noTypeless?: boolean;
|
|
145
|
+
noEmptyStrings?: boolean;
|
|
146
|
+
noEmptyArrays?: boolean;
|
|
147
|
+
strictUris?: boolean;
|
|
148
|
+
strictMode?: boolean;
|
|
149
|
+
reportPathAsArray?: boolean;
|
|
150
|
+
breakOnFirstError?: boolean;
|
|
151
|
+
pedanticCheck?: boolean;
|
|
152
|
+
ignoreUnknownFormats?: boolean;
|
|
153
|
+
customValidator?: (report: Report, schema: unknown, json: unknown) => void;
|
|
154
|
+
}
|
|
155
|
+
interface ValidateOptions {
|
|
156
|
+
schemaPath?: string;
|
|
157
|
+
includeErrors?: Array<keyof typeof Errors>;
|
|
158
|
+
}
|
|
159
|
+
type ValidateCallback = (e: Error, valid: boolean) => void;
|
|
160
|
+
type SchemaReader = (uri: string) => unknown;
|
|
161
|
+
declare class ZSchema {
|
|
162
|
+
lastReport: Report | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* Register a custom format.
|
|
165
|
+
*
|
|
166
|
+
* @param name - name of the custom format
|
|
167
|
+
* @param validatorFunction - custom format validator function.
|
|
168
|
+
* Returns `true` if `value` matches the custom format.
|
|
169
|
+
*/
|
|
170
|
+
static registerFormat(formatName: string, validatorFunction: (value: unknown) => boolean): void;
|
|
171
|
+
/**
|
|
172
|
+
* Unregister a format.
|
|
173
|
+
*
|
|
174
|
+
* @param name - name of the custom format
|
|
175
|
+
*/
|
|
176
|
+
static unregisterFormat(name: string): void;
|
|
177
|
+
/**
|
|
178
|
+
* Get the list of all registered formats.
|
|
179
|
+
*
|
|
180
|
+
* Both the names of the burned-in formats and the custom format names are
|
|
181
|
+
* returned by this function.
|
|
182
|
+
*
|
|
183
|
+
* @returns {string[]} the list of all registered format names.
|
|
184
|
+
*/
|
|
185
|
+
static getRegisteredFormats(): string[];
|
|
186
|
+
static getDefaultOptions(): ZSchemaOptions;
|
|
187
|
+
private cache;
|
|
188
|
+
private referenceCache;
|
|
189
|
+
private validateOptions;
|
|
190
|
+
options: ZSchemaOptions;
|
|
191
|
+
constructor(options?: ZSchemaOptions);
|
|
192
|
+
/**
|
|
193
|
+
* @param schema - JSON object representing schema
|
|
194
|
+
* @returns {boolean} true if schema is valid.
|
|
195
|
+
*/
|
|
196
|
+
validateSchema(schema: unknown): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* @param json - either a JSON string or a parsed JSON object
|
|
199
|
+
* @param schema - the JSON object representing the schema
|
|
200
|
+
* @returns true if json matches schema
|
|
201
|
+
*/
|
|
202
|
+
validate(json: any, schema: any, options?: ValidateOptions, callback?: ValidateCallback): boolean;
|
|
203
|
+
validate(json: any, schema: any, callback?: any): boolean;
|
|
204
|
+
validate(json: any, schema: any): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Returns an Error object for the most recent failed validation, or null if the validation was successful.
|
|
207
|
+
*/
|
|
208
|
+
getLastError(): SchemaError;
|
|
209
|
+
/**
|
|
210
|
+
* Returns the error details for the most recent validation, or undefined if the validation was successful.
|
|
211
|
+
* This is the same list as the SchemaError.details property.
|
|
212
|
+
*/
|
|
213
|
+
getLastErrors(): SchemaErrorDetail[];
|
|
214
|
+
setRemoteReference(uri: any, schema: any, validationOptions: any): void;
|
|
215
|
+
compileSchema(schema: any): boolean;
|
|
216
|
+
getMissingReferences(arr?: any): any[];
|
|
217
|
+
getMissingRemoteReferences(): any[];
|
|
218
|
+
getResolvedSchema(schema: any): any;
|
|
219
|
+
static schemaReader: SchemaReader;
|
|
220
|
+
setSchemaReader(schemaReader: any): void;
|
|
221
|
+
getSchemaReader(): SchemaReader;
|
|
222
|
+
static setSchemaReader(schemaReader: any): void;
|
|
223
|
+
static schemaSymbol: symbol;
|
|
224
|
+
static jsonSymbol: symbol;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export { ZSchema as default };
|
package/dist/ZSchema.js
CHANGED
|
@@ -95,7 +95,7 @@ function normalizeOptions(options) {
|
|
|
95
95
|
}
|
|
96
96
|
return normalized;
|
|
97
97
|
}
|
|
98
|
-
class ZSchema {
|
|
98
|
+
export class ZSchema {
|
|
99
99
|
lastReport;
|
|
100
100
|
/**
|
|
101
101
|
* Register a custom format.
|
|
@@ -363,4 +363,3 @@ class ZSchema {
|
|
|
363
363
|
static schemaSymbol = Utils.schemaSymbol;
|
|
364
364
|
static jsonSymbol = Utils.jsonSymbol;
|
|
365
365
|
}
|
|
366
|
-
export default ZSchema;
|
package/dist/index.js
ADDED
package/dist/types/ZSchema.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface ValidateOptions {
|
|
|
29
29
|
}
|
|
30
30
|
type ValidateCallback = (e: Error, valid: boolean) => void;
|
|
31
31
|
type SchemaReader = (uri: string) => unknown;
|
|
32
|
-
declare class ZSchema {
|
|
32
|
+
export declare class ZSchema {
|
|
33
33
|
lastReport: Report | undefined;
|
|
34
34
|
/**
|
|
35
35
|
* Register a custom format.
|
|
@@ -94,4 +94,4 @@ declare class ZSchema {
|
|
|
94
94
|
static schemaSymbol: symbol;
|
|
95
95
|
static jsonSymbol: symbol;
|
|
96
96
|
}
|
|
97
|
-
export
|
|
97
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "z-schema",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.3",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22.0.0"
|
|
6
6
|
},
|
|
@@ -17,21 +17,28 @@
|
|
|
17
17
|
],
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "https://github.com/zaggino/z-schema.git"
|
|
20
|
+
"url": "git+https://github.com/zaggino/z-schema.git"
|
|
21
21
|
},
|
|
22
22
|
"bugs": {
|
|
23
23
|
"url": "https://github.com/zaggino/z-schema/issues"
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
|
-
"
|
|
27
|
-
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"types": "./dist/types/index.d.ts",
|
|
30
|
+
"require": "./cjs/ZSchema.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
28
33
|
"bin": {
|
|
29
|
-
"z-schema": "
|
|
34
|
+
"z-schema": "bin/z-schema"
|
|
30
35
|
},
|
|
31
36
|
"files": [
|
|
32
37
|
"bin/",
|
|
38
|
+
"cjs/",
|
|
33
39
|
"dist/",
|
|
34
40
|
"src/",
|
|
41
|
+
"umd/",
|
|
35
42
|
"LICENSE",
|
|
36
43
|
"README.md"
|
|
37
44
|
],
|
|
@@ -43,7 +50,7 @@
|
|
|
43
50
|
"format:check": "prettier --check .",
|
|
44
51
|
"lint": "eslint --fix",
|
|
45
52
|
"lint:check": "eslint",
|
|
46
|
-
"clean": "rimraf ./dist && rimraf --glob \"./src/schemas/*.json\"",
|
|
53
|
+
"clean": "rimraf ./cjs && rimraf ./dist && rimraf ./umd && rimraf --glob \"./src/schemas/*.json\"",
|
|
47
54
|
"build": "npm run copy:schemas && tsc && rollup -c",
|
|
48
55
|
"build:browser": "rollup -c --environment BROWSER",
|
|
49
56
|
"build:watch": "rollup -c -w",
|
|
@@ -95,6 +102,7 @@
|
|
|
95
102
|
"remapify": "^2.2.0",
|
|
96
103
|
"rimraf": "^6.1.2",
|
|
97
104
|
"rollup": "^4.57.0",
|
|
105
|
+
"rollup-plugin-dts": "^6.3.0",
|
|
98
106
|
"tslib": "^2.8.1",
|
|
99
107
|
"typescript": "^5.9.3",
|
|
100
108
|
"typescript-eslint": "^8.54.0",
|
package/src/ZSchema.ts
CHANGED
|
@@ -140,7 +140,7 @@ type ValidateCallback = (e: Error, valid: boolean) => void;
|
|
|
140
140
|
// a sync function that loads schemas for future use, for example from schemas directory, during server startup
|
|
141
141
|
type SchemaReader = (uri: string) => unknown;
|
|
142
142
|
|
|
143
|
-
class ZSchema {
|
|
143
|
+
export class ZSchema {
|
|
144
144
|
public lastReport: Report | undefined;
|
|
145
145
|
|
|
146
146
|
/**
|
|
@@ -465,5 +465,3 @@ class ZSchema {
|
|
|
465
465
|
|
|
466
466
|
static jsonSymbol = Utils.jsonSymbol;
|
|
467
467
|
}
|
|
468
|
-
|
|
469
|
-
export default ZSchema;
|
package/src/index.ts
ADDED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ?
|
|
3
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ZSchema =
|
|
5
|
-
})(this, (function () { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ZSchema = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
8
8
|
|
|
@@ -13786,6 +13786,6 @@
|
|
|
13786
13786
|
static jsonSymbol = jsonSymbol;
|
|
13787
13787
|
}
|
|
13788
13788
|
|
|
13789
|
-
|
|
13789
|
+
exports.ZSchema = ZSchema;
|
|
13790
13790
|
|
|
13791
13791
|
}));
|