@jarenjs/validate 0.8.4 → 0.9.2

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 (48) hide show
  1. package/ARCHITECTURE.md +1067 -0
  2. package/LICENSE +21 -0
  3. package/README.md +339 -2
  4. package/dist/types/array.d.ts +2 -0
  5. package/dist/types/bigint.d.ts +1 -0
  6. package/dist/types/combine.d.ts +1 -0
  7. package/dist/types/condition.d.ts +1 -0
  8. package/dist/types/content.d.ts +3 -0
  9. package/dist/types/data.d.ts +7 -0
  10. package/dist/types/dollar-data.d.ts +20 -0
  11. package/dist/types/dynamic-ref.d.ts +44 -0
  12. package/dist/types/enum.d.ts +1 -0
  13. package/dist/types/format.d.ts +21 -0
  14. package/dist/types/index.d.ts +874 -0
  15. package/dist/types/number.d.ts +1 -0
  16. package/dist/types/object.d.ts +3 -0
  17. package/dist/types/query-keyword.d.ts +19 -0
  18. package/dist/types/query.d.ts +29 -0
  19. package/dist/types/schema.d.ts +1 -0
  20. package/dist/types/string.d.ts +1 -0
  21. package/dist/types/tools.d.ts +51 -0
  22. package/dist/types/traverse.d.ts +32 -0
  23. package/dist/types/unevaluated.d.ts +12 -0
  24. package/package.json +32 -7
  25. package/src/array.js +565 -0
  26. package/src/bigint.js +97 -0
  27. package/src/combine.js +226 -0
  28. package/src/condition.js +109 -0
  29. package/src/content.js +83 -0
  30. package/src/data.js +477 -0
  31. package/src/dollar-data.js +629 -0
  32. package/src/dynamic-ref.js +121 -0
  33. package/src/enum.js +148 -0
  34. package/src/format.js +66 -0
  35. package/src/index.js +1854 -0
  36. package/src/number.js +159 -0
  37. package/src/object.js +755 -0
  38. package/src/query-keyword.js +99 -0
  39. package/src/query.js +59 -0
  40. package/src/schema.js +645 -0
  41. package/src/string.js +152 -0
  42. package/src/tools.js +205 -0
  43. package/src/traverse.js +433 -0
  44. package/src/unevaluated.js +151 -0
  45. package/dist/index.js +0 -1998
  46. package/dist/index.js.map +0 -7
  47. package/dist/index.min.js +0 -2
  48. package/dist/index.min.js.map +0 -7
@@ -0,0 +1 @@
1
+ export declare function compileNumberBasic(schemaObj: any, jsonSchema: any): ((data: any, dataPath: any) => any) | undefined;
@@ -0,0 +1,3 @@
1
+ export declare function compileObjectPrimitives(schemaObj: any, jsonSchema: any): ((data: any, dataPath: any, dataRoot: any, dataKeys: any) => any) | undefined;
2
+ export declare function compileObjectChildren(schemaObj: any, jsonSchema: any): ((data: any, dataPath: any, dataRoot: any, dataKeys: any) => boolean) | undefined;
3
+ export declare function compileObjectSchema(schemaObj: any, jsonSchema: any): ((data: any, dataPath: any, dataRoot: any) => any) | undefined;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Compile the '$query' keyword of a schema into a validator.
3
+ *
4
+ * The query document compiles with a `compileTypeTest` hook backed by the
5
+ * owning `JarenValidator` instance (threaded through `ValidationRoot`), so
6
+ * schema literals inside the query (`$valid`/`$assert`/`$as`) may `$ref`
7
+ * schemas registered on that instance with `addSchema`. Malformed query
8
+ * documents (`JQ0xxx`) and externals other than `root`/`path` throw here,
9
+ * at schema compile time. At validation time the query never throws:
10
+ * a `JsonQueryRuntimeError` (`JQ2xxx` - a data-shaped failure such as the
11
+ * EBV of a multi-item result or arithmetic on a non-number) reports as a
12
+ * validation failure whose error params carry the `code` and the query
13
+ * `docPath`.
14
+ *
15
+ * @param {object} schemaObj - The validation object
16
+ * @param {object} jsonSchema - The JSON schema containing the '$query' keyword
17
+ * @returns {function|undefined} The compiled validator function or undefined
18
+ */
19
+ export declare function compileQuerySchema(schemaObj: object, jsonSchema: object): Function | undefined;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Create a `compileTypeTest` hook for `compileJsonQuery` (see
3
+ * `@jarenjs/json/query`), backed by a `JarenValidator`.
4
+ *
5
+ * The hook compiles each schema literal with the validator and returns
6
+ * its boolean-mode validation function - errors off, the fast path of
7
+ * this package's architecture. Schema compile failures (an invalid
8
+ * schema literal, an unresolvable `$ref`) propagate as plain errors; the
9
+ * query engine wraps them into `JsonQueryCompileError` `JQ0009` with the
10
+ * operator's document pointer.
11
+ *
12
+ * @param {object | (() => object)} [validator] - a `JarenValidator`
13
+ * instance to compile with, or a zero-argument factory producing one.
14
+ * Supply an instance with registered schemas (`addSchema`) so `$ref`s
15
+ * in query schema literals resolve against them. Omitted, a fresh
16
+ * default (boolean-mode) instance is created.
17
+ * @returns {(schemaJson: any, docPath: string) => ((value: any) => boolean)}
18
+ * a hook suitable for `compileJsonQuery(doc, { compileTypeTest })`
19
+ * @example
20
+ * import { compileJsonQuery } from '@jarenjs/json/query';
21
+ * import { createTypeTestCompiler } from '@jarenjs/validate/query';
22
+ *
23
+ * const query = compileJsonQuery({
24
+ * "$for": { "b": "$.store.book[*]" },
25
+ * "$as": { "b": { "type": "object", "required": ["price"] } },
26
+ * "$return": "$b.title"
27
+ * }, { compileTypeTest: createTypeTestCompiler() });
28
+ */
29
+ export declare function createTypeTestCompiler(validator?: object | (() => object)): (schemaJson: any, docPath: string) => ((value: any) => boolean);
@@ -0,0 +1 @@
1
+ export declare function compileSchemaObject(schemaObj: any, jsonSchema: any): any;
@@ -0,0 +1 @@
1
+ export declare function compileStringBasic(schemaObj: any, jsonSchema: any): ((data: any, dataPath: any) => any) | undefined;
@@ -0,0 +1,51 @@
1
+ import { isBooleanType } from '@jarenjs/core';
2
+ import { isRegExpType } from '@jarenjs/core/string';
3
+ export declare function isBoolOrObjectClass(obj: any): boolean;
4
+ /**
5
+ * getBoolOrObjectClass
6
+ * extract the data of first parameter if data is boolean or object type otherwise return default
7
+ * @param {any} obj any data data has to be tested on boolean or object type
8
+ * @param {boolean | object | undefined} def default return type if not boolean or object type
9
+ * @returns {boolean | undefined} return value when boolean or object otherwise def
10
+ */
11
+ export declare function getBoolOrObjectClass(obj: any, def?: boolean | object | undefined): boolean | undefined;
12
+ export declare function getArrayClassMinItems(obj: any, len?: number, def?: undefined): any;
13
+ export declare function isOfSchemaType(schema: any, type: any): boolean;
14
+ export declare function hasSchemaRef(schema: any): boolean;
15
+ export declare function hasSchemaRecursiveRef(schema: any): boolean;
16
+ export declare function hasSchemaDynamicRef(schema: any): boolean;
17
+ export declare function createIsSchemaTypeHandler(type: any, isStrict?: boolean): typeof isBooleanType | typeof isRegExpType | undefined;
18
+ /**
19
+ * Records which properties (string keys) and items (numeric indexes) of a
20
+ * data instance were successfully evaluated during validation, so that
21
+ * unevaluatedProperties/unevaluatedItems can be checked afterwards.
22
+ *
23
+ * Entries are (data reference, key) pairs appended in application order.
24
+ * Applicators that discard annotations (failed anyOf/oneOf branches, not,
25
+ * failed if) take a mark() before running and rollback(mark) afterwards.
26
+ * The numeric key -1 means "all items of this array were evaluated".
27
+ */
28
+ export declare class EvalLog {
29
+ #private;
30
+ /** Clears the log; called at the start of each root validation. */
31
+ reset(): void;
32
+ /** @returns {number} The current log position */
33
+ mark(): number;
34
+ /** Discards all entries recorded after the given mark. */
35
+ rollback(mark: any): void;
36
+ /** Records that `key` of instance `data` was evaluated. */
37
+ add(data: any, key: any): void;
38
+ /** @returns {boolean} True when property `key` of `data` was evaluated at or after `from` */
39
+ hasKey(data: any, key: any, from: any): boolean;
40
+ /** @returns {boolean} True when item `index` of `data` was evaluated at or after `from` (-1 entries cover all items) */
41
+ hasItem(data: any, index: any, from: any): boolean;
42
+ }
43
+ export declare class ValidationResult {
44
+ match: boolean;
45
+ errors: number;
46
+ static undefThat(): ValidationResult;
47
+ constructor(match?: boolean, errors?: number);
48
+ addValid(valid?: boolean): this;
49
+ addMatch(valid?: boolean): this;
50
+ addResult(result?: ValidationResult): this;
51
+ }
@@ -0,0 +1,32 @@
1
+ export declare function encodeJsonPointerPath(path: any, key: any, index: any): string;
2
+ export declare function decodeJsonPointerPath(path: any): any;
3
+ declare class JsonPointerOptions {
4
+ anchorsGlobal: boolean;
5
+ anchorsAllowed: boolean;
6
+ skipErrors: boolean;
7
+ constructor(anchorsGlobal?: boolean, anchorsAllowed?: boolean, skipErrors?: boolean);
8
+ }
9
+ declare class JsonPointer {
10
+ id: any;
11
+ search: any;
12
+ leftUri: any;
13
+ fragment: any;
14
+ constructor(id: any, search: any, leftUri: any, fragment: any);
15
+ }
16
+ export declare function createJsonPointer(refUri: any, baseUri: any, opts?: JsonPointerOptions): JsonPointer;
17
+ export declare function storeSchemaIdsInMap(schemas: any, baseUri: any, schema: any, opts?: JsonPointerOptions): any;
18
+ export declare function resolveRefSchemaShallow(schemas: any, refUri: any, baseUri: any, opts?: JsonPointerOptions): {
19
+ id: any;
20
+ schema: any;
21
+ };
22
+ export declare function restoreSchemaRefsInMap(schemas: any, opts?: JsonPointerOptions): void;
23
+ export declare class TraverseOptions extends JsonPointerOptions {
24
+ origin: string;
25
+ mergeSchemas: boolean;
26
+ constructor(origin?: string, mergeSchemas?: boolean, anchorsGlobal?: boolean, anchorsAllowed?: boolean, skipErrors?: boolean);
27
+ }
28
+ export declare function resolveRefSchemaDeep(schemas: any, baseUri: any, refschema: any, opts?: TraverseOptions): {
29
+ id: any;
30
+ schema: any;
31
+ };
32
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Wraps a compiled schema validator so unevaluatedProperties/unevaluatedItems
3
+ * run last, seeing every annotation produced on this instance by the schema's
4
+ * own keywords and its in-place applicators (allOf/anyOf/oneOf/if/$ref/...).
5
+ * Returns the validator unchanged when evaluation tracking is off or the
6
+ * schema has no unevaluated* keywords.
7
+ * @param {import('./index.js').ValidationObject} schemaObj
8
+ * @param {object} jsonSchema
9
+ * @param {function} validator - The compiled validator for all other keywords
10
+ * @returns {function} The wrapped (or original) validator
11
+ */
12
+ export declare function wrapUnevaluated(schemaObj: import('./index.js').ValidationObject, jsonSchema: object, validator: Function): Function;
package/package.json CHANGED
@@ -1,20 +1,42 @@
1
1
  {
2
2
  "name": "@jarenjs/validate",
3
3
  "private": false,
4
- "version": "0.8.4",
4
+ "version": "0.9.2",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
6
+ "main": "./src/index.js",
7
+ "types": "./dist/types/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "default": "./src/index.js"
13
+ },
14
+ "./query": {
15
+ "types": "./dist/types/query.d.ts",
16
+ "default": "./src/query.js"
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
7
20
  "files": [
8
- "dist"
21
+ "dist/types/",
22
+ "src/",
23
+ "ARCHITECTURE.md"
9
24
  ],
10
25
  "description": "Jaren is a JavaScript JSON Schema Validator",
11
26
  "author": "joham",
12
27
  "repository": {
13
28
  "type": "git",
14
- "url": "https://github.com/jklarenbeek/jarenjs.git",
29
+ "url": "git+https://github.com/jklarenbeek/jarenjs.git",
15
30
  "directory": "packages/validate"
16
31
  },
17
32
  "license": "MIT",
33
+ "engines": {
34
+ "node": ">=22"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "registry": "https://registry.npmjs.org/"
39
+ },
18
40
  "keywords": [
19
41
  "jaren",
20
42
  "json",
@@ -23,9 +45,12 @@
23
45
  "validator"
24
46
  ],
25
47
  "scripts": {
26
- "build": "node esbuild.config.js"
48
+ "build": "node esbuild.config.js && npm run build:types",
49
+ "build:types": "tsc -p tsconfig.json",
50
+ "prepack": "npm run build:types"
27
51
  },
28
- "devDependencies": {
29
- "esbuild": "^0.23.1"
52
+ "dependencies": {
53
+ "@jarenjs/core": "^0.9.2",
54
+ "@jarenjs/json": "^0.9.2"
30
55
  }
31
56
  }