@jarenjs/validate 0.43.1 → 0.43.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/dist/types/index.d.ts +22 -9
- package/package.json +3 -3
- package/src/index.js +18 -5
package/dist/types/index.d.ts
CHANGED
|
@@ -330,6 +330,7 @@ export type JSONSchemaKeywords = {
|
|
|
330
330
|
data?: DataKeywordSchema;
|
|
331
331
|
};
|
|
332
332
|
export type JSONSchema = JSONSchemaKeywords & Record<string, unknown>;
|
|
333
|
+
export type JSONSchemaLike = JSONSchema | Record<string, unknown>;
|
|
333
334
|
export type FormatCompiler = (schemaObj: ValidationObject, jsonSchema: JSONSchema & {
|
|
334
335
|
format?: string;
|
|
335
336
|
}) => ((data: unknown, dataPath?: string) => boolean) | undefined;
|
|
@@ -447,6 +448,18 @@ export type FormatCompiler = (schemaObj: ValidationObject, jsonSchema: JSONSchem
|
|
|
447
448
|
* forms accept everything (`true`) or nothing (`false`).
|
|
448
449
|
* @typedef {JSONSchemaKeywords & Record<string, unknown>} JSONSchema
|
|
449
450
|
*/
|
|
451
|
+
/**
|
|
452
|
+
* A schema as a validator boundary ACCEPTS it. {@link JSONSchema}
|
|
453
|
+
* documents what a schema IS — typed keywords, open for extensions —
|
|
454
|
+
* but a schema held as a plain `Record<string, unknown>` map (the
|
|
455
|
+
* natural type for a document that crossed a wire or a package
|
|
456
|
+
* boundary) does not assign to that keyword intersection under strict
|
|
457
|
+
* TypeScript, and forcing the consumer to cast at every `compile` and
|
|
458
|
+
* `addSchema` call site teaches them to cast, which is worse than the
|
|
459
|
+
* looser parameter. The boundary methods accept this union; both arms
|
|
460
|
+
* are treated identically at runtime, which was always true.
|
|
461
|
+
* @typedef {JSONSchema | Record<string, unknown>} JSONSchemaLike
|
|
462
|
+
*/
|
|
450
463
|
/**
|
|
451
464
|
* A format compiler function.
|
|
452
465
|
* Called once per schema location at compile time with the compiling
|
|
@@ -893,7 +906,7 @@ export declare class JarenValidator<TCollect extends boolean = false> {
|
|
|
893
906
|
* Adds schema(s) to the validator instance.
|
|
894
907
|
* This method does not compile schemas - it only registers them for reference.
|
|
895
908
|
* Dependencies can be added in any order, and circular dependencies are supported.
|
|
896
|
-
* @param {
|
|
909
|
+
* @param {JSONSchemaLike | boolean | (JSONSchemaLike | boolean)[]} schema - The schema(s) to add
|
|
897
910
|
* @param {string} [key] - Optional key/URI to register the schema under
|
|
898
911
|
* @returns {this} This validator instance for chaining (the polymorphic `this` keeps the collectErrors type parameter across a chain)
|
|
899
912
|
* @example
|
|
@@ -906,18 +919,18 @@ export declare class JarenValidator<TCollect extends boolean = false> {
|
|
|
906
919
|
* // Add with explicit key
|
|
907
920
|
* validator.addSchema({ type: 'string' }, 'http://example.com/name');
|
|
908
921
|
*/
|
|
909
|
-
addSchema(schema:
|
|
922
|
+
addSchema(schema: JSONSchemaLike | boolean | (JSONSchemaLike | boolean)[], key?: string): this;
|
|
910
923
|
static normalizeUriKey(key: any): any;
|
|
911
924
|
/**
|
|
912
925
|
* Adds meta-schema(s) that can be used to validate schemas.
|
|
913
926
|
* Meta-schemas are schemas that describe the structure of valid JSON schemas.
|
|
914
|
-
* @param {
|
|
927
|
+
* @param {JSONSchemaLike | boolean | (JSONSchemaLike | boolean)[]} schema - The meta-schema(s) to add
|
|
915
928
|
* @param {string} [key] - Optional key/URI for the meta-schema
|
|
916
929
|
* @returns {this} This validator instance for chaining (the polymorphic `this` keeps the collectErrors type parameter across a chain)
|
|
917
930
|
* @example
|
|
918
931
|
* validator.addMetaSchema(draft7MetaSchema, 'http://json-schema.org/draft-07/schema');
|
|
919
932
|
*/
|
|
920
|
-
addMetaSchema(schema:
|
|
933
|
+
addMetaSchema(schema: JSONSchemaLike | boolean | (JSONSchemaLike | boolean)[], key?: string): this;
|
|
921
934
|
/**
|
|
922
935
|
* Retrieves a registered schema by its key/URI.
|
|
923
936
|
* @param {string} key - The schema URI/key
|
|
@@ -927,13 +940,13 @@ export declare class JarenValidator<TCollect extends boolean = false> {
|
|
|
927
940
|
/**
|
|
928
941
|
* Validates a schema against a registered meta-schema.
|
|
929
942
|
* This is used to ensure schemas are valid according to the JSON Schema specification.
|
|
930
|
-
* @param {
|
|
943
|
+
* @param {JSONSchemaLike | boolean} schema - The schema to validate
|
|
931
944
|
* @returns {boolean} True if the schema is valid
|
|
932
945
|
* @example
|
|
933
946
|
* validator.addMetaSchema(draft7MetaSchema);
|
|
934
947
|
* const isValid = validator.validateSchema({ type: 'string' }); // true
|
|
935
948
|
*/
|
|
936
|
-
validateSchema(schema:
|
|
949
|
+
validateSchema(schema: JSONSchemaLike | boolean): boolean;
|
|
937
950
|
/**
|
|
938
951
|
* Compiles a schema into a validation function.
|
|
939
952
|
* This is the main method for creating validators. It resolves all $ref references,
|
|
@@ -945,8 +958,8 @@ export declare class JarenValidator<TCollect extends boolean = false> {
|
|
|
945
958
|
* what a checked contract wrapper wants; pair it with a schema-to-type
|
|
946
959
|
* generator if you need the shape derived mechanically.
|
|
947
960
|
* @template [T=unknown]
|
|
948
|
-
* @param {
|
|
949
|
-
* @param {(
|
|
961
|
+
* @param {JSONSchemaLike | boolean} schema - The schema to compile
|
|
962
|
+
* @param {(JSONSchemaLike | boolean)[]} [schemas] - Additional schemas to reference during compilation
|
|
950
963
|
* @returns {TCollect extends true ? CompiledCollector : CompiledPredicate<T>} A validation function
|
|
951
964
|
* @example
|
|
952
965
|
* const validate = validator.compile({
|
|
@@ -968,5 +981,5 @@ export declare class JarenValidator<TCollect extends boolean = false> {
|
|
|
968
981
|
* const result = collecting.compile(schema)({ name: 123 });
|
|
969
982
|
* // result = { valid: false, errors: [...] }
|
|
970
983
|
*/
|
|
971
|
-
compile<T = unknown>(schema:
|
|
984
|
+
compile<T = unknown>(schema: JSONSchemaLike | boolean, schemas?: (JSONSchemaLike | boolean)[]): TCollect extends true ? CompiledCollector : CompiledPredicate<T>;
|
|
972
985
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jarenjs/validate",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.43.
|
|
4
|
+
"version": "0.43.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"types": "./dist/types/index.d.ts",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"prepack": "npm run build:types"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@jarenjs/core": "^0.43.
|
|
59
|
-
"@jarenjs/json": "^0.43.
|
|
58
|
+
"@jarenjs/core": "^0.43.3",
|
|
59
|
+
"@jarenjs/json": "^0.43.3"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/src/index.js
CHANGED
|
@@ -168,6 +168,19 @@ export { TraverseOptions };
|
|
|
168
168
|
* @typedef {JSONSchemaKeywords & Record<string, unknown>} JSONSchema
|
|
169
169
|
*/
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* A schema as a validator boundary ACCEPTS it. {@link JSONSchema}
|
|
173
|
+
* documents what a schema IS — typed keywords, open for extensions —
|
|
174
|
+
* but a schema held as a plain `Record<string, unknown>` map (the
|
|
175
|
+
* natural type for a document that crossed a wire or a package
|
|
176
|
+
* boundary) does not assign to that keyword intersection under strict
|
|
177
|
+
* TypeScript, and forcing the consumer to cast at every `compile` and
|
|
178
|
+
* `addSchema` call site teaches them to cast, which is worse than the
|
|
179
|
+
* looser parameter. The boundary methods accept this union; both arms
|
|
180
|
+
* are treated identically at runtime, which was always true.
|
|
181
|
+
* @typedef {JSONSchema | Record<string, unknown>} JSONSchemaLike
|
|
182
|
+
*/
|
|
183
|
+
|
|
171
184
|
/**
|
|
172
185
|
* A format compiler function.
|
|
173
186
|
* Called once per schema location at compile time with the compiling
|
|
@@ -1420,7 +1433,7 @@ export class JarenValidator {
|
|
|
1420
1433
|
* Adds schema(s) to the validator instance.
|
|
1421
1434
|
* This method does not compile schemas - it only registers them for reference.
|
|
1422
1435
|
* Dependencies can be added in any order, and circular dependencies are supported.
|
|
1423
|
-
* @param {
|
|
1436
|
+
* @param {JSONSchemaLike | boolean | (JSONSchemaLike | boolean)[]} schema - The schema(s) to add
|
|
1424
1437
|
* @param {string} [key] - Optional key/URI to register the schema under
|
|
1425
1438
|
* @returns {this} This validator instance for chaining (the polymorphic `this` keeps the collectErrors type parameter across a chain)
|
|
1426
1439
|
* @example
|
|
@@ -1569,7 +1582,7 @@ export class JarenValidator {
|
|
|
1569
1582
|
/**
|
|
1570
1583
|
* Adds meta-schema(s) that can be used to validate schemas.
|
|
1571
1584
|
* Meta-schemas are schemas that describe the structure of valid JSON schemas.
|
|
1572
|
-
* @param {
|
|
1585
|
+
* @param {JSONSchemaLike | boolean | (JSONSchemaLike | boolean)[]} schema - The meta-schema(s) to add
|
|
1573
1586
|
* @param {string} [key] - Optional key/URI for the meta-schema
|
|
1574
1587
|
* @returns {this} This validator instance for chaining (the polymorphic `this` keeps the collectErrors type parameter across a chain)
|
|
1575
1588
|
* @example
|
|
@@ -1623,7 +1636,7 @@ export class JarenValidator {
|
|
|
1623
1636
|
/**
|
|
1624
1637
|
* Validates a schema against a registered meta-schema.
|
|
1625
1638
|
* This is used to ensure schemas are valid according to the JSON Schema specification.
|
|
1626
|
-
* @param {
|
|
1639
|
+
* @param {JSONSchemaLike | boolean} schema - The schema to validate
|
|
1627
1640
|
* @returns {boolean} True if the schema is valid
|
|
1628
1641
|
* @example
|
|
1629
1642
|
* validator.addMetaSchema(draft7MetaSchema);
|
|
@@ -1806,8 +1819,8 @@ export class JarenValidator {
|
|
|
1806
1819
|
* what a checked contract wrapper wants; pair it with a schema-to-type
|
|
1807
1820
|
* generator if you need the shape derived mechanically.
|
|
1808
1821
|
* @template [T=unknown]
|
|
1809
|
-
* @param {
|
|
1810
|
-
* @param {(
|
|
1822
|
+
* @param {JSONSchemaLike | boolean} schema - The schema to compile
|
|
1823
|
+
* @param {(JSONSchemaLike | boolean)[]} [schemas] - Additional schemas to reference during compilation
|
|
1811
1824
|
* @returns {TCollect extends true ? CompiledCollector : CompiledPredicate<T>} A validation function
|
|
1812
1825
|
* @example
|
|
1813
1826
|
* const validate = validator.compile({
|