z-schema 6.0.1 → 7.0.0-beta.1

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 (47) hide show
  1. package/README.md +154 -137
  2. package/bin/z-schema +128 -124
  3. package/dist/Errors.js +50 -0
  4. package/dist/FormatValidators.js +136 -0
  5. package/{src → dist}/JsonValidation.js +186 -212
  6. package/dist/Report.js +220 -0
  7. package/{src → dist}/SchemaCache.js +67 -82
  8. package/{src → dist}/SchemaCompilation.js +89 -129
  9. package/dist/SchemaValidation.js +631 -0
  10. package/{src → dist}/Utils.js +96 -104
  11. package/dist/ZSchema-umd-min.js +1 -0
  12. package/dist/ZSchema-umd.js +13791 -0
  13. package/dist/ZSchema.cjs +13785 -0
  14. package/dist/ZSchema.js +366 -0
  15. package/dist/schemas/hyper-schema.json +156 -0
  16. package/dist/schemas/schema.json +151 -0
  17. package/dist/types/Errors.d.ts +44 -0
  18. package/dist/types/FormatValidators.d.ts +12 -0
  19. package/dist/types/JsonValidation.d.ts +37 -0
  20. package/dist/types/Report.d.ts +87 -0
  21. package/dist/types/SchemaCache.d.ts +26 -0
  22. package/dist/types/SchemaCompilation.d.ts +1 -0
  23. package/dist/types/SchemaValidation.d.ts +6 -0
  24. package/dist/types/Utils.d.ts +64 -0
  25. package/dist/types/ZSchema.d.ts +97 -0
  26. package/package.json +54 -43
  27. package/src/Errors.ts +56 -0
  28. package/src/FormatValidators.ts +136 -0
  29. package/src/JsonValidation.ts +624 -0
  30. package/src/Report.ts +337 -0
  31. package/src/SchemaCache.ts +189 -0
  32. package/src/SchemaCompilation.ts +293 -0
  33. package/src/SchemaValidation.ts +629 -0
  34. package/src/Utils.ts +286 -0
  35. package/src/ZSchema.ts +469 -0
  36. package/src/schemas/_ +0 -0
  37. package/dist/ZSchema-browser-min.js +0 -2
  38. package/dist/ZSchema-browser-min.js.map +0 -1
  39. package/dist/ZSchema-browser-test.js +0 -30633
  40. package/dist/ZSchema-browser.js +0 -13429
  41. package/index.d.ts +0 -175
  42. package/src/Errors.js +0 -60
  43. package/src/FormatValidators.js +0 -129
  44. package/src/Polyfills.js +0 -16
  45. package/src/Report.js +0 -299
  46. package/src/SchemaValidation.js +0 -619
  47. package/src/ZSchema.js +0 -409
@@ -0,0 +1,44 @@
1
+ export declare const Errors: {
2
+ INVALID_TYPE: string;
3
+ INVALID_FORMAT: string;
4
+ ENUM_MISMATCH: string;
5
+ ENUM_CASE_MISMATCH: string;
6
+ ANY_OF_MISSING: string;
7
+ ONE_OF_MISSING: string;
8
+ ONE_OF_MULTIPLE: string;
9
+ NOT_PASSED: string;
10
+ ARRAY_LENGTH_SHORT: string;
11
+ ARRAY_LENGTH_LONG: string;
12
+ ARRAY_UNIQUE: string;
13
+ ARRAY_ADDITIONAL_ITEMS: string;
14
+ MULTIPLE_OF: string;
15
+ MINIMUM: string;
16
+ MINIMUM_EXCLUSIVE: string;
17
+ MAXIMUM: string;
18
+ MAXIMUM_EXCLUSIVE: string;
19
+ OBJECT_PROPERTIES_MINIMUM: string;
20
+ OBJECT_PROPERTIES_MAXIMUM: string;
21
+ OBJECT_MISSING_REQUIRED_PROPERTY: string;
22
+ OBJECT_ADDITIONAL_PROPERTIES: string;
23
+ OBJECT_DEPENDENCY_KEY: string;
24
+ MIN_LENGTH: string;
25
+ MAX_LENGTH: string;
26
+ PATTERN: string;
27
+ KEYWORD_TYPE_EXPECTED: string;
28
+ KEYWORD_UNDEFINED_STRICT: string;
29
+ KEYWORD_UNEXPECTED: string;
30
+ KEYWORD_MUST_BE: string;
31
+ KEYWORD_DEPENDENCY: string;
32
+ KEYWORD_PATTERN: string;
33
+ KEYWORD_VALUE_TYPE: string;
34
+ UNKNOWN_FORMAT: string;
35
+ CUSTOM_MODE_FORCE_PROPERTIES: string;
36
+ REF_UNRESOLVED: string;
37
+ UNRESOLVABLE_REFERENCE: string;
38
+ SCHEMA_NOT_REACHABLE: string;
39
+ SCHEMA_TYPE_EXPECTED: string;
40
+ SCHEMA_NOT_AN_OBJECT: string;
41
+ ASYNC_TIMEOUT: string;
42
+ PARENT_SCHEMA_VALIDATION_FAILED: string;
43
+ REMOTE_NOT_VALID: string;
44
+ };
@@ -0,0 +1,12 @@
1
+ export declare const FormatValidators: {
2
+ date: (date: any) => boolean;
3
+ 'date-time': (dateTime: any) => boolean;
4
+ email: (email: any) => any;
5
+ hostname: (hostname: any) => boolean;
6
+ 'host-name': (hostname: any) => any;
7
+ ipv4: (ipv4: any) => any;
8
+ ipv6: (ipv6: any) => any;
9
+ regex: (str: any) => boolean;
10
+ uri: (args_0: string) => any;
11
+ 'strict-uri': (uri: any) => any;
12
+ };
@@ -0,0 +1,37 @@
1
+ export declare const JsonValidators: {
2
+ multipleOf: (report: any, schema: any, json: any) => void;
3
+ maximum: (report: any, schema: any, json: any) => void;
4
+ exclusiveMaximum: () => void;
5
+ minimum: (report: any, schema: any, json: any) => void;
6
+ exclusiveMinimum: () => void;
7
+ maxLength: (report: any, schema: any, json: any) => void;
8
+ minLength: (report: any, schema: any, json: any) => void;
9
+ pattern: (report: any, schema: any, json: any) => void;
10
+ additionalItems: (report: any, schema: any, json: any) => void;
11
+ items: () => void;
12
+ maxItems: (report: any, schema: any, json: any) => void;
13
+ minItems: (report: any, schema: any, json: any) => void;
14
+ uniqueItems: (report: any, schema: any, json: any) => void;
15
+ maxProperties: (report: any, schema: any, json: any) => void;
16
+ minProperties: (report: any, schema: any, json: any) => void;
17
+ required: (report: any, schema: any, json: any) => void;
18
+ additionalProperties: (report: any, schema: any, json: any) => any;
19
+ patternProperties: (report: any, schema: any, json: any) => any;
20
+ properties: (report: any, schema: any, json: any) => void;
21
+ dependencies: (report: any, schema: any, json: any) => void;
22
+ enum: (report: any, schema: any, json: any) => void;
23
+ type: (report: any, schema: any, json: any) => void;
24
+ allOf: (report: any, schema: any, json: any) => void;
25
+ anyOf: (report: any, schema: any, json: any) => void;
26
+ oneOf: (report: any, schema: any, json: any) => void;
27
+ not: (report: any, schema: any, json: any) => void;
28
+ definitions: () => void;
29
+ format: (report: any, schema: any, json: any) => void;
30
+ };
31
+ /**
32
+ *
33
+ * @param {Report} report
34
+ * @param {*} schema
35
+ * @param {*} json
36
+ */
37
+ export declare function validate(report: any, schema: any, json: any): boolean;
@@ -0,0 +1,87 @@
1
+ import { ZSchemaOptions } from './ZSchema.js';
2
+ export interface SchemaError extends Error {
3
+ /**
4
+ * Implements the Error.name contract. The value is always "z-schema validation error".
5
+ */
6
+ name: string;
7
+ /**
8
+ * An identifier indicating the type of error.
9
+ * Example: "JSON_OBJECT_VALIDATION_FAILED"
10
+ */
11
+ message: string;
12
+ /**
13
+ * Returns details for each error that occurred during validation.
14
+ * See Options.breakOnFirstError.
15
+ */
16
+ details?: SchemaErrorDetail[];
17
+ }
18
+ export interface SchemaErrorDetail {
19
+ /**
20
+ * Example: "Expected type string but found type array"
21
+ */
22
+ message: string;
23
+ /**
24
+ * An error identifier that can be used to format a custom error message.
25
+ * Example: "INVALID_TYPE"
26
+ */
27
+ code: string;
28
+ /**
29
+ * Format parameters that can be used to format a custom error message.
30
+ * Example: ["string","array"]
31
+ */
32
+ params: Array<string>;
33
+ /**
34
+ * A JSON path indicating the location of the error.
35
+ * Example: "#/projects/1"
36
+ */
37
+ path: string | string[];
38
+ /**
39
+ * The schema rule description, which is included for certain errors where
40
+ * this information is useful (e.g. to describe a constraint).
41
+ */
42
+ title?: string;
43
+ description?: string;
44
+ /**
45
+ * Returns details for sub-schemas that failed to match. For example, if the schema
46
+ * uses the "oneOf" constraint to accept several alternative possibilities, each
47
+ * alternative will have its own inner detail object explaining why it failed to match.
48
+ */
49
+ inner?: SchemaErrorDetail[];
50
+ schemaId?: string;
51
+ }
52
+ export interface ReportOptions {
53
+ maxErrors?: number;
54
+ }
55
+ type TaskResult = unknown;
56
+ type TaskFn = (...args: unknown[]) => TaskResult;
57
+ type TaskFnArgs = Parameters<TaskFn>;
58
+ type TaskProcessFn = (result: ReturnType<TaskFn>) => void;
59
+ type AsyncTask = [TaskFn, TaskFnArgs, TaskProcessFn];
60
+ export declare class Report {
61
+ errors: SchemaErrorDetail[];
62
+ parentReport?: Report;
63
+ options: ZSchemaOptions;
64
+ reportOptions: ReportOptions;
65
+ path: string[];
66
+ asyncTasks: AsyncTask[];
67
+ rootSchema?: {
68
+ id?: string;
69
+ };
70
+ commonErrorMessage?: string;
71
+ json?: unknown;
72
+ constructor(parentOrOptions: any, reportOptions?: any);
73
+ isValid(): boolean;
74
+ addAsyncTask(fn: any, args: any, asyncTaskResultProcessFn: any): void;
75
+ getAncestor(id: any): any;
76
+ processAsyncTasks(timeout: any, callback: any): void;
77
+ getPath(returnPathAsString: any): string | any[];
78
+ getSchemaId(): any;
79
+ hasError(errorCode: any, params: any): boolean;
80
+ addError(errorCode: any, params: any, subReports?: any, schema?: any): void;
81
+ getJson(): any;
82
+ addCustomError(errorCode: string, errorMessage: string, params: string[], subReports?: Report[] | Report, schema?: {
83
+ title?: string;
84
+ description?: string;
85
+ }): void;
86
+ }
87
+ export {};
@@ -0,0 +1,26 @@
1
+ export declare function getRemotePath(uri: any): any;
2
+ /**
3
+ *
4
+ * @param {*} uri
5
+ * @param {*} schema
6
+ *
7
+ * @returns {void}
8
+ */
9
+ export declare function cacheSchemaByUri(uri: any, schema: any): void;
10
+ /**
11
+ *
12
+ * @param {*} uri
13
+ *
14
+ * @returns {void}
15
+ */
16
+ export declare function removeFromCacheByUri(uri: any): void;
17
+ /**
18
+ *
19
+ * @param {*} uri
20
+ *
21
+ * @returns {boolean}
22
+ */
23
+ export declare function checkCacheForUri(uri: any): boolean;
24
+ export declare function getSchema(report: any, schema: any): any;
25
+ export declare function getSchemaByReference(report: any, key: any): any;
26
+ export declare function getSchemaByUri(report: any, uri: any, root: any): any;
@@ -0,0 +1 @@
1
+ export declare function compileSchema(report: any, schema: any): any;
@@ -0,0 +1,6 @@
1
+ /**
2
+ *
3
+ * @param {Report} report
4
+ * @param {*} schema
5
+ */
6
+ export declare function validateSchema(report: any, schema: any): any;
@@ -0,0 +1,64 @@
1
+ export declare const jsonSymbol: unique symbol;
2
+ export declare const schemaSymbol: unique symbol;
3
+ /**
4
+ * @param {object} obj
5
+ *
6
+ * @returns {string[]}
7
+ */
8
+ export declare function sortedKeys(obj: any): string[];
9
+ /**
10
+ *
11
+ * @param {string} uri
12
+ *
13
+ * @returns {boolean}
14
+ */
15
+ export declare function isAbsoluteUri(uri: any): boolean;
16
+ /**
17
+ *
18
+ * @param {string} uri
19
+ *
20
+ * @returns {boolean}
21
+ */
22
+ export declare function isRelativeUri(uri: any): boolean;
23
+ export declare function whatIs(what: any): "string" | "bigint" | "boolean" | "symbol" | "undefined" | "function" | "object" | "null" | "array" | "integer" | "number" | "not-a-number" | "unknown-number";
24
+ /**
25
+ *
26
+ * @param {*} json1
27
+ * @param {*} json2
28
+ * @param {*} [options]
29
+ *
30
+ * @returns {boolean}
31
+ */
32
+ export declare function areEqual(json1: any, json2: any, options?: any): boolean;
33
+ /**
34
+ *
35
+ * @param {*[]} arr
36
+ * @param {number[]} [indexes]
37
+ *
38
+ * @returns {boolean}
39
+ */
40
+ export declare function isUniqueArray(arr: any, indexes?: any): boolean;
41
+ /**
42
+ *
43
+ * @param {*} bigSet
44
+ * @param {*} subSet
45
+ *
46
+ * @returns {*[]}
47
+ */
48
+ export declare function difference(bigSet: any, subSet: any): any[];
49
+ export declare function clone(src: any): any;
50
+ export declare function cloneDeep(src: any): any;
51
+ /**
52
+ * Creates an array containing the numeric code points of each Unicode
53
+ * character in the string. While JavaScript uses UCS-2 internally,
54
+ * this function will convert a pair of surrogate halves (each of which
55
+ * UCS-2 exposes as separate characters) into a single code point,
56
+ * matching UTF-16.
57
+ * @see `punycode.ucs2.encode`
58
+ * @see <https://mathiasbynens.be/notes/javascript-encoding>
59
+ * @memberOf punycode.ucs2
60
+ * @name decode
61
+ * @param {String} string The Unicode input string (UCS-2).
62
+ * @returns {Array} The new array of code points.
63
+ */
64
+ export declare function ucs2decode(string: any): any[];
@@ -0,0 +1,97 @@
1
+ import { Report, SchemaError, SchemaErrorDetail } from './Report.js';
2
+ import type { Errors } from './Errors.js';
3
+ export interface ZSchemaOptions {
4
+ asyncTimeout?: number;
5
+ forceAdditional?: boolean;
6
+ assumeAdditional?: boolean;
7
+ forceItems?: boolean;
8
+ forceMinItems?: boolean;
9
+ forceMaxItems?: boolean;
10
+ forceMinLength?: boolean;
11
+ forceMaxLength?: boolean;
12
+ forceProperties?: boolean;
13
+ ignoreUnresolvableReferences?: boolean;
14
+ noExtraKeywords?: boolean;
15
+ noTypeless?: boolean;
16
+ noEmptyStrings?: boolean;
17
+ noEmptyArrays?: boolean;
18
+ strictUris?: boolean;
19
+ strictMode?: boolean;
20
+ reportPathAsArray?: boolean;
21
+ breakOnFirstError?: boolean;
22
+ pedanticCheck?: boolean;
23
+ ignoreUnknownFormats?: boolean;
24
+ customValidator?: (report: Report, schema: unknown, json: unknown) => void;
25
+ }
26
+ export interface ValidateOptions {
27
+ schemaPath?: string;
28
+ includeErrors?: Array<keyof typeof Errors>;
29
+ }
30
+ type ValidateCallback = (e: Error, valid: boolean) => void;
31
+ type SchemaReader = (uri: string) => unknown;
32
+ declare class ZSchema {
33
+ lastReport: Report | undefined;
34
+ /**
35
+ * Register a custom format.
36
+ *
37
+ * @param name - name of the custom format
38
+ * @param validatorFunction - custom format validator function.
39
+ * Returns `true` if `value` matches the custom format.
40
+ */
41
+ static registerFormat(formatName: string, validatorFunction: (value: unknown) => boolean): void;
42
+ /**
43
+ * Unregister a format.
44
+ *
45
+ * @param name - name of the custom format
46
+ */
47
+ static unregisterFormat(name: string): void;
48
+ /**
49
+ * Get the list of all registered formats.
50
+ *
51
+ * Both the names of the burned-in formats and the custom format names are
52
+ * returned by this function.
53
+ *
54
+ * @returns {string[]} the list of all registered format names.
55
+ */
56
+ static getRegisteredFormats(): string[];
57
+ static getDefaultOptions(): ZSchemaOptions;
58
+ private cache;
59
+ private referenceCache;
60
+ private validateOptions;
61
+ options: ZSchemaOptions;
62
+ constructor(options?: ZSchemaOptions);
63
+ /**
64
+ * @param schema - JSON object representing schema
65
+ * @returns {boolean} true if schema is valid.
66
+ */
67
+ validateSchema(schema: unknown): boolean;
68
+ /**
69
+ * @param json - either a JSON string or a parsed JSON object
70
+ * @param schema - the JSON object representing the schema
71
+ * @returns true if json matches schema
72
+ */
73
+ validate(json: any, schema: any, options?: ValidateOptions, callback?: ValidateCallback): boolean;
74
+ validate(json: any, schema: any, callback?: any): boolean;
75
+ validate(json: any, schema: any): boolean;
76
+ /**
77
+ * Returns an Error object for the most recent failed validation, or null if the validation was successful.
78
+ */
79
+ getLastError(): SchemaError;
80
+ /**
81
+ * Returns the error details for the most recent validation, or undefined if the validation was successful.
82
+ * This is the same list as the SchemaError.details property.
83
+ */
84
+ getLastErrors(): SchemaErrorDetail[];
85
+ setRemoteReference(uri: any, schema: any, validationOptions: any): void;
86
+ compileSchema(schema: any): boolean;
87
+ getMissingReferences(arr?: any): any[];
88
+ getMissingRemoteReferences(): any[];
89
+ getResolvedSchema(schema: any): any;
90
+ static schemaReader: SchemaReader;
91
+ setSchemaReader(schemaReader: any): void;
92
+ getSchemaReader(): SchemaReader;
93
+ static setSchemaReader(schemaReader: any): void;
94
+ static schemaSymbol: symbol;
95
+ static jsonSymbol: symbol;
96
+ }
97
+ export default ZSchema;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "z-schema",
3
- "version": "6.0.1",
3
+ "version": "7.0.0-beta.1",
4
4
  "engines": {
5
- "node": ">=16.0.0"
5
+ "node": ">=22.0.0"
6
6
  },
7
7
  "description": "JSON schema validator",
8
8
  "homepage": "https://github.com/zaggino/z-schema",
@@ -22,48 +22,39 @@
22
22
  "bugs": {
23
23
  "url": "https://github.com/zaggino/z-schema/issues"
24
24
  },
25
- "main": "src/ZSchema.js",
25
+ "type": "module",
26
+ "main": "dist/ZSchema.js",
27
+ "types": "dist/types/ZSchema.d.ts",
26
28
  "bin": {
27
29
  "z-schema": "./bin/z-schema"
28
30
  },
29
31
  "files": [
30
- "bin",
31
- "src",
32
- "dist",
32
+ "bin/",
33
+ "dist/",
34
+ "src/",
33
35
  "LICENSE",
34
- "README.md",
35
- "index.d.ts"
36
+ "README.md"
36
37
  ],
37
- "types": "index.d.ts",
38
38
  "scripts": {
39
- "prepare": "grunt",
40
- "prepublishOnly": "npm test",
41
- "test": "jasmine-node test/ && grunt lint",
42
- "test-z": "jasmine-node test/spec/ZSchemaTestSuiteSpec.js",
43
- "grunt": "grunt"
44
- },
45
- "testling": {
46
- "scripts": [
47
- "test/lib/jasmine-2.0.1/jasmine.js",
48
- "test/lib/jasmine-2.0.1/jasmine-html.js",
49
- "test/lib/jasmine-2.0.1/boot.js",
50
- "test/lib/jasmine-2.0.1/tap_reporter.js",
51
- "test/Runner.js",
52
- "dist/ZSchema-browser-min.js",
53
- "dist/ZSchema-browser-test.js"
54
- ],
55
- "browsers": [
56
- "iexplore/9..latest",
57
- "chrome/4",
58
- "chrome/28..latest",
59
- "firefox/3.5",
60
- "firefox/23..latest",
61
- "safari/5.1..latest",
62
- "opera/12..latest",
63
- "iphone/6..latest",
64
- "ipad/6..latest",
65
- "android-browser/4.2..latest"
66
- ]
39
+ "prepare": "husky",
40
+ "pre-commit": "npx lint-staged",
41
+ "pre-push": "",
42
+ "format": "prettier --write .",
43
+ "format:check": "prettier --check .",
44
+ "lint": "eslint --fix",
45
+ "lint:check": "eslint",
46
+ "clean": "rimraf ./dist && rimraf --glob \"./src/schemas/*.json\"",
47
+ "build": "npm run copy:schemas && tsc && rollup -c",
48
+ "build:browser": "rollup -c --environment BROWSER",
49
+ "build:watch": "rollup -c -w",
50
+ "copy:schemas": "npm run copy:schema && npm run copy:hyper-schema",
51
+ "copy:schema": "node -e \"fs.copyFileSync('./json-schema/draft-04/schema', './src/schemas/schema.json')\"",
52
+ "copy:hyper-schema": "node -e \"fs.copyFileSync('./json-schema/draft-04/hyper-schema', './src/schemas/hyper-schema.json')\"",
53
+ "prepublishOnly": "npm run clean && npm run build && npm test",
54
+ "test": "vitest run",
55
+ "test:browsers": "vitest run --project browsers --silent=true",
56
+ "test:node": "vitest run --project node --silent=true",
57
+ "test:sample": "npx vitest run --silent=false --hideSkippedTests --project node -t \"invalid definition\""
67
58
  },
68
59
  "dependencies": {
69
60
  "lodash.get": "^4.4.2",
@@ -71,22 +62,42 @@
71
62
  "validator": "^13.7.0"
72
63
  },
73
64
  "optionalDependencies": {
74
- "commander": "^10.0.0"
65
+ "commander": "^14.0.2"
75
66
  },
76
67
  "devDependencies": {
68
+ "@eslint/js": "^9.39.2",
69
+ "@eslint/json": "^0.14.0",
70
+ "@eslint/markdown": "^7.5.1",
71
+ "@rollup/plugin-commonjs": "^29.0.0",
72
+ "@rollup/plugin-json": "^6.1.0",
73
+ "@rollup/plugin-node-resolve": "^16.0.3",
74
+ "@rollup/plugin-terser": "^0.4.4",
75
+ "@rollup/plugin-typescript": "^12.3.0",
76
+ "@types/lodash.get": "^4.4.9",
77
+ "@types/node": "^25.1.0",
78
+ "@vitest/browser-playwright": "^4.0.18",
79
+ "@vitest/eslint-plugin": "^1.6.6",
77
80
  "browserify": "^17.0.0",
78
81
  "coveralls": "^3.1.1",
79
- "grunt": "^1.4.1",
82
+ "eslint": "^9.39.2",
83
+ "globals": "^17.2.0",
80
84
  "grunt-browserify": "^6.0.0",
81
85
  "grunt-cli": "^1.4.3",
82
86
  "grunt-contrib-copy": "^1.0.0",
83
- "grunt-contrib-jasmine": "^4.0.0",
84
87
  "grunt-contrib-jshint": "^3.2.0",
85
88
  "grunt-contrib-uglify": "^5.2.2",
86
89
  "grunt-jscs": "^3.0.1",
87
90
  "grunt-lineending": "^1.0.0",
88
- "jasmine-node": "^3.0.0",
89
- "jasmine-reporters": "^2.5.0",
90
- "remapify": "^2.2.0"
91
+ "husky": "^9.1.7",
92
+ "jsdom": "^27.4.0",
93
+ "lint-staged": "^16.2.7",
94
+ "prettier": "^3.8.1",
95
+ "remapify": "^2.2.0",
96
+ "rimraf": "^6.1.2",
97
+ "rollup": "^4.57.0",
98
+ "tslib": "^2.8.1",
99
+ "typescript": "^5.9.3",
100
+ "typescript-eslint": "^8.54.0",
101
+ "vitest": "^4.0.18"
91
102
  }
92
103
  }
package/src/Errors.ts ADDED
@@ -0,0 +1,56 @@
1
+ export const Errors = {
2
+ INVALID_TYPE: 'Expected type {0} but found type {1}',
3
+ INVALID_FORMAT: "Object didn't pass validation for format {0}: {1}",
4
+ ENUM_MISMATCH: 'No enum match for: {0}',
5
+ ENUM_CASE_MISMATCH: 'Enum does not match case for: {0}',
6
+ ANY_OF_MISSING: "Data does not match any schemas from 'anyOf'",
7
+ ONE_OF_MISSING: "Data does not match any schemas from 'oneOf'",
8
+ ONE_OF_MULTIPLE: "Data is valid against more than one schema from 'oneOf'",
9
+ NOT_PASSED: "Data matches schema from 'not'",
10
+
11
+ // Array errors
12
+ ARRAY_LENGTH_SHORT: 'Array is too short ({0}), minimum {1}',
13
+ ARRAY_LENGTH_LONG: 'Array is too long ({0}), maximum {1}',
14
+ ARRAY_UNIQUE: 'Array items are not unique (indexes {0} and {1})',
15
+ ARRAY_ADDITIONAL_ITEMS: 'Additional items not allowed',
16
+
17
+ // Numeric errors
18
+ MULTIPLE_OF: 'Value {0} is not a multiple of {1}',
19
+ MINIMUM: 'Value {0} is less than minimum {1}',
20
+ MINIMUM_EXCLUSIVE: 'Value {0} is equal or less than exclusive minimum {1}',
21
+ MAXIMUM: 'Value {0} is greater than maximum {1}',
22
+ MAXIMUM_EXCLUSIVE: 'Value {0} is equal or greater than exclusive maximum {1}',
23
+
24
+ // Object errors
25
+ OBJECT_PROPERTIES_MINIMUM: 'Too few properties defined ({0}), minimum {1}',
26
+ OBJECT_PROPERTIES_MAXIMUM: 'Too many properties defined ({0}), maximum {1}',
27
+ OBJECT_MISSING_REQUIRED_PROPERTY: 'Missing required property: {0}',
28
+ OBJECT_ADDITIONAL_PROPERTIES: 'Additional properties not allowed: {0}',
29
+ OBJECT_DEPENDENCY_KEY: 'Dependency failed - key must exist: {0} (due to key: {1})',
30
+
31
+ // String errors
32
+ MIN_LENGTH: 'String is too short ({0} chars), minimum {1}',
33
+ MAX_LENGTH: 'String is too long ({0} chars), maximum {1}',
34
+ PATTERN: 'String does not match pattern {0}: {1}',
35
+
36
+ // Schema validation errors
37
+ KEYWORD_TYPE_EXPECTED: "Keyword '{0}' is expected to be of type '{1}'",
38
+ KEYWORD_UNDEFINED_STRICT: "Keyword '{0}' must be defined in strict mode",
39
+ KEYWORD_UNEXPECTED: "Keyword '{0}' is not expected to appear in the schema",
40
+ KEYWORD_MUST_BE: "Keyword '{0}' must be {1}",
41
+ KEYWORD_DEPENDENCY: "Keyword '{0}' requires keyword '{1}'",
42
+ KEYWORD_PATTERN: "Keyword '{0}' is not a valid RegExp pattern: {1}",
43
+ KEYWORD_VALUE_TYPE: "Each element of keyword '{0}' array must be a '{1}'",
44
+ UNKNOWN_FORMAT: "There is no validation function for format '{0}'",
45
+ CUSTOM_MODE_FORCE_PROPERTIES: '{0} must define at least one property if present',
46
+
47
+ // Remote errors
48
+ REF_UNRESOLVED: 'Reference has not been resolved during compilation: {0}',
49
+ UNRESOLVABLE_REFERENCE: 'Reference could not be resolved: {0}',
50
+ SCHEMA_NOT_REACHABLE: 'Validator was not able to read schema with uri: {0}',
51
+ SCHEMA_TYPE_EXPECTED: "Schema is expected to be of type 'object'",
52
+ SCHEMA_NOT_AN_OBJECT: 'Schema is not an object: {0}',
53
+ ASYNC_TIMEOUT: '{0} asynchronous task(s) have timed out after {1} ms',
54
+ PARENT_SCHEMA_VALIDATION_FAILED: 'Schema failed to validate against its parent schema, see inner errors for details.',
55
+ REMOTE_NOT_VALID: "Remote reference didn't compile successfully: {0}",
56
+ };