@amazon/vinyl-validation 1.1.1 → 2.0.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/README.md +42 -0
- package/dist/index.cjs +337 -174
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +325 -162
- package/dist/index.js.map +4 -4
- package/dist/types/current/index.d.ts +15 -14
- package/dist/types/current/index.d.ts.map +1 -1
- package/dist/types/current/index.js +15 -14
- package/dist/types/current/tsconfig.tsbuildinfo +1 -1
- package/dist/types/current/validation/ArraySchema.d.ts.map +1 -1
- package/dist/types/current/validation/ArraySchema.js +11 -4
- package/dist/types/current/validation/FunctionSchema.js +1 -1
- package/dist/types/current/validation/JsonSchema.d.ts +63 -0
- package/dist/types/current/validation/JsonSchema.d.ts.map +1 -0
- package/dist/types/current/validation/JsonSchema.js +59 -0
- package/dist/types/current/validation/NumberSchema.d.ts.map +1 -1
- package/dist/types/current/validation/NumberSchema.js +6 -6
- package/dist/types/current/validation/ObjectSchema.d.ts +2 -2
- package/dist/types/current/validation/ObjectSchema.d.ts.map +1 -1
- package/dist/types/current/validation/ObjectSchema.js +12 -1
- package/dist/types/current/validation/PropertyValidator.d.ts +1 -1
- package/dist/types/current/validation/PropertyValidator.d.ts.map +1 -1
- package/dist/types/current/validation/RecordSchema.d.ts.map +1 -1
- package/dist/types/current/validation/RecordSchema.js +4 -0
- package/dist/types/current/validation/SchemaBase.d.ts +23 -1
- package/dist/types/current/validation/SchemaBase.d.ts.map +1 -1
- package/dist/types/current/validation/SchemaBase.js +36 -0
- package/dist/types/current/validation/SetSchema.d.ts.map +1 -1
- package/dist/types/current/validation/SetSchema.js +6 -1
- package/dist/types/current/validation/StringSchema.d.ts.map +1 -1
- package/dist/types/current/validation/StringSchema.js +4 -4
- package/dist/types/current/validation/Validator.d.ts +14 -2
- package/dist/types/current/validation/Validator.d.ts.map +1 -1
- package/dist/types/current/validation/Validator.js +6 -2
- package/dist/types/current/validation/ValueSchema.d.ts +1 -0
- package/dist/types/current/validation/ValueSchema.d.ts.map +1 -1
- package/dist/types/current/validation/ValueSchema.js +7 -2
- package/dist/types/current/validation/andValidators.d.ts.map +1 -1
- package/dist/types/current/validation/andValidators.js +2 -1
- package/dist/types/current/validation/orValidators.d.ts.map +1 -1
- package/dist/types/current/validation/orValidators.js +18 -1
- package/dist/types/current/validation/typeOfValidators.d.ts.map +1 -1
- package/dist/types/current/validation/typeOfValidators.js +13 -1
- package/dist/types/current/validation/validators.d.ts.map +1 -1
- package/dist/types/current/validation/validators.js +1 -1
- package/dist/types/ts3.7/index.d.ts +15 -14
- package/dist/types/ts3.7/validation/JsonSchema.d.ts +63 -0
- package/dist/types/ts3.7/validation/ObjectSchema.d.ts +2 -2
- package/dist/types/ts3.7/validation/PropertyValidator.d.ts +1 -1
- package/dist/types/ts3.7/validation/SchemaBase.d.ts +18 -1
- package/dist/types/ts3.7/validation/Validator.d.ts +14 -2
- package/dist/types/ts3.7/validation/ValueSchema.d.ts +1 -0
- package/dist/types/ts4.1/index.d.ts +15 -14
- package/dist/types/ts4.1/validation/JsonSchema.d.ts +63 -0
- package/dist/types/ts4.1/validation/ObjectSchema.d.ts +2 -2
- package/dist/types/ts4.1/validation/PropertyValidator.d.ts +1 -1
- package/dist/types/ts4.1/validation/SchemaBase.d.ts +18 -1
- package/dist/types/ts4.1/validation/Validator.d.ts +14 -2
- package/dist/types/ts4.1/validation/ValueSchema.d.ts +1 -0
- package/dist/types/ts4.7/index.d.ts +15 -14
- package/dist/types/ts4.7/validation/JsonSchema.d.ts +63 -0
- package/dist/types/ts4.7/validation/ObjectSchema.d.ts +2 -2
- package/dist/types/ts4.7/validation/PropertyValidator.d.ts +1 -1
- package/dist/types/ts4.7/validation/SchemaBase.d.ts +23 -1
- package/dist/types/ts4.7/validation/Validator.d.ts +14 -2
- package/dist/types/ts4.7/validation/ValueSchema.d.ts +1 -0
- package/dist/unit/types/current/tsconfig.tsbuildinfo +1 -0
- package/package.json +14 -17
|
@@ -23,7 +23,7 @@ export const numberValidators = {
|
|
|
23
23
|
* @param min The minimum (inclusive) the value may be.
|
|
24
24
|
*/
|
|
25
25
|
gte(min) {
|
|
26
|
-
return createValidator(substitute(locale.gte, { value: min }), (input) => input >= min);
|
|
26
|
+
return createValidator(substitute(locale.gte, { value: min }), (input) => input >= min, undefined, { minimum: min });
|
|
27
27
|
},
|
|
28
28
|
/**
|
|
29
29
|
* Creates a validator that asserts that the input number is greater than the provided minimum
|
|
@@ -32,7 +32,7 @@ export const numberValidators = {
|
|
|
32
32
|
* @param min The minimum (exclusive) the value may be.
|
|
33
33
|
*/
|
|
34
34
|
gt(min) {
|
|
35
|
-
return createValidator(substitute(locale.gt, { value: min }), (input) => input > min);
|
|
35
|
+
return createValidator(substitute(locale.gt, { value: min }), (input) => input > min, undefined, { exclusiveMinimum: min });
|
|
36
36
|
},
|
|
37
37
|
/**
|
|
38
38
|
* Creates a validator that asserts that the input number is at most the provided maximum
|
|
@@ -41,7 +41,7 @@ export const numberValidators = {
|
|
|
41
41
|
* @param max The maximum (inclusive) the value may be.
|
|
42
42
|
*/
|
|
43
43
|
lte(max) {
|
|
44
|
-
return createValidator(substitute(locale.lte, { value: max }), (input) => input <= max);
|
|
44
|
+
return createValidator(substitute(locale.lte, { value: max }), (input) => input <= max, undefined, { maximum: max });
|
|
45
45
|
},
|
|
46
46
|
/**
|
|
47
47
|
* Creates a validator that asserts that the input number is less than the provided maximum
|
|
@@ -50,7 +50,7 @@ export const numberValidators = {
|
|
|
50
50
|
* @param max The maximum (exclusive) the value may be.
|
|
51
51
|
*/
|
|
52
52
|
lt(max) {
|
|
53
|
-
return createValidator(substitute(locale.lt, { value: max }), (input) => input < max);
|
|
53
|
+
return createValidator(substitute(locale.lt, { value: max }), (input) => input < max, undefined, { exclusiveMaximum: max });
|
|
54
54
|
},
|
|
55
55
|
/**
|
|
56
56
|
* Creates a validator that asserts that the input number is at least the provided minimum
|
|
@@ -60,7 +60,7 @@ export const numberValidators = {
|
|
|
60
60
|
* @param max The maximum (inclusive) value the input may be.
|
|
61
61
|
*/
|
|
62
62
|
within(min, max) {
|
|
63
|
-
return createValidator(substitute(locale.within, { min, max }), (input) => input >= min && input <= max);
|
|
63
|
+
return createValidator(substitute(locale.within, { min, max }), (input) => input >= min && input <= max, undefined, { minimum: min, maximum: max });
|
|
64
64
|
},
|
|
65
65
|
/**
|
|
66
66
|
* Creates a validator that asserts that the input number is finite.
|
|
@@ -72,7 +72,7 @@ export const numberValidators = {
|
|
|
72
72
|
* Creates a validator that asserts that the input number is a safe integer.
|
|
73
73
|
*/
|
|
74
74
|
safeInteger() {
|
|
75
|
-
return createValidator(locale.safeInteger, (input) => Number.isSafeInteger(input));
|
|
75
|
+
return createValidator(locale.safeInteger, (input) => Number.isSafeInteger(input), undefined, { type: 'integer' });
|
|
76
76
|
},
|
|
77
77
|
};
|
|
78
78
|
export class NumberSchema extends ValueSchema {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AnyRecord, IsPropertyOptional, PartialDeep } from '@amazon/vinyl-util';
|
|
2
2
|
import type { ValidatorWithPartial } from './ValidatorWithPartial';
|
|
3
3
|
import { ValueSchema } from './ValueSchema';
|
|
4
|
-
import type { PropertyValidator } from '
|
|
5
|
-
import type { Equal } from '@amazon/vinyl-util
|
|
4
|
+
import type { PropertyValidator } from './PropertyValidator';
|
|
5
|
+
import type { Equal } from '@amazon/vinyl-util';
|
|
6
6
|
export declare const objectValidators: {
|
|
7
7
|
/**
|
|
8
8
|
* Creates a validator that validates the input has properties that pass their respective
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectSchema.d.ts","sourceRoot":"","sources":["../../../../src/validation/ObjectSchema.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACR,SAAS,EACT,kBAAkB,EAClB,WAAW,EACd,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAElE,OAAO,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AC,CAAC;IAIlB;;OAEG;IACH,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAInC;;OAEG;IACH,WAAW,IAAI,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAI3C;;OAEG;IACH,IAAI,CAAC,CAAC,SAAS,MAAM,KAAK,YAAY,CAAC,CAAC,CAAC;CAG5C;AAED,MAAM,MAAM,0BAA0B,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI;KAIxE,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GAC5B,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAC1B,KAAK,GACL,CAAC,GACL,CAAC,CAAC,CAAC,GAAG,yBAAyB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;CAClD,GAAG;KAGC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GAC5B,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAC1B,CAAC,GACD,KAAK,GACT,KAAK,CAAC,CAAC,EAAE,yBAAyB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;CACrD,CAAA;AAED,MAAM,MAAM,yBAAyB,CACjC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAC,IACjB,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;IAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CAAE,CAAC,CAAA"}
|
|
@@ -7,6 +7,7 @@ import { maybeToDeepPartial, maybeToPartial } from './ValidatorWithPartial';
|
|
|
7
7
|
import { ValueSchema } from './ValueSchema';
|
|
8
8
|
import { typeOfValidators } from './typeOfValidators';
|
|
9
9
|
import { createDeepValidator } from './Validator';
|
|
10
|
+
import { toJsonSchema } from './JsonSchema';
|
|
10
11
|
/**
|
|
11
12
|
* @private
|
|
12
13
|
*/
|
|
@@ -27,12 +28,17 @@ export const objectValidators = {
|
|
|
27
28
|
properties(propertyValidators) {
|
|
28
29
|
const propertiesDescriptions = [];
|
|
29
30
|
const keys = ownKeys(propertyValidators);
|
|
31
|
+
const jsonProperties = {};
|
|
32
|
+
const requiredKeys = [];
|
|
30
33
|
for (const key of keys) {
|
|
31
34
|
const validator = propertyValidators[key];
|
|
32
35
|
propertiesDescriptions.push(substitute(locale.prop, {
|
|
33
36
|
key: String(key) + (validator.options.optional ? '?' : ''),
|
|
34
37
|
value: validator.description,
|
|
35
38
|
}));
|
|
39
|
+
jsonProperties[String(key)] = toJsonSchema(validator);
|
|
40
|
+
if (!validator.options.optional)
|
|
41
|
+
requiredKeys.push(String(key));
|
|
36
42
|
}
|
|
37
43
|
const description = substitute(locale.extend, {
|
|
38
44
|
body: propertiesDescriptions
|
|
@@ -41,6 +47,11 @@ export const objectValidators = {
|
|
|
41
47
|
.map((line) => locale.indent + line)
|
|
42
48
|
.join('\n'),
|
|
43
49
|
});
|
|
50
|
+
const jsonSchema = {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: jsonProperties,
|
|
53
|
+
...(requiredKeys.length ? { required: requiredKeys } : {}),
|
|
54
|
+
};
|
|
44
55
|
const validator = createDeepValidator(description, (input, options, path) => {
|
|
45
56
|
const errors = [];
|
|
46
57
|
for (const key of keys) {
|
|
@@ -62,7 +73,7 @@ export const objectValidators = {
|
|
|
62
73
|
return errors;
|
|
63
74
|
}
|
|
64
75
|
return errors;
|
|
65
|
-
});
|
|
76
|
+
}, jsonSchema);
|
|
66
77
|
return merge(validator, {
|
|
67
78
|
partial() {
|
|
68
79
|
const optionalPropertyValidators = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyValidator.d.ts","sourceRoot":"","sources":["../../../../src/validation/PropertyValidator.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"PropertyValidator.d.ts","sourceRoot":"","sources":["../../../../src/validation/PropertyValidator.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE/C,MAAM,WAAW,wBAAwB;IACrC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAC7B;AAED;;;GAGG;AACH,MAAM,MAAM,4BAA4B,CACpC,aAAa,SAAS,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,EACjD,CAAC,EACD,OAAO,SAAS,wBAAwB,IACxC,IAAI,CAAC,aAAa,EAAE,MAAM,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GACtD,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC,CAAA;AAElE,MAAM,WAAW,iBAAiB,CAC9B,CAAC,EACD,mBAAmB,SAAS,wBAAwB,CACtD,SAAQ,SAAS,CAAC,CAAC,CAAC;IAClB,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAA;IAErC,QAAQ,IAAI,4BAA4B,CACpC,IAAI,EACJ,CAAC,EACD;QAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAA;KAAE,CAC9B,CAAA;IAED,QAAQ,IAAI,4BAA4B,CACpC,IAAI,EACJ,CAAC,EACD;QAAE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAA;KAAE,CAC/B,CAAA;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecordSchema.d.ts","sourceRoot":"","sources":["../../../../src/validation/RecordSchema.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EA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V,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC,GAC7B,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAIlC;;OAEG;IACH,QAAQ,IAAI,YAAY,CACpB,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CACpE;IAID;;OAEG;IACH,IAAI,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM,GAAG,EAAE,OAAO,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC;CAGxE"}
|
|
@@ -7,6 +7,7 @@ import { ValueSchema } from './ValueSchema';
|
|
|
7
7
|
import { StringSchema } from './StringSchema';
|
|
8
8
|
import { typeOfValidators } from './typeOfValidators';
|
|
9
9
|
import { createDeepValidator } from './Validator';
|
|
10
|
+
import { toJsonSchema } from './JsonSchema';
|
|
10
11
|
/**
|
|
11
12
|
* @private
|
|
12
13
|
*/
|
|
@@ -42,6 +43,9 @@ export const recordValidators = {
|
|
|
42
43
|
return errors;
|
|
43
44
|
}
|
|
44
45
|
return errors;
|
|
46
|
+
}, {
|
|
47
|
+
type: 'object',
|
|
48
|
+
additionalProperties: toJsonSchema(valueValidator),
|
|
45
49
|
});
|
|
46
50
|
},
|
|
47
51
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ValidationErrorMessage, ValidationOptions, Validator } from './Validator';
|
|
2
2
|
import type { PropertyValidator, PropertyValidatorWithOptions } from './PropertyValidator';
|
|
3
|
+
import type { JsonSchema, JsonSchemaProvider } from './JsonSchema';
|
|
3
4
|
/**
|
|
4
5
|
* A base class for validation state.
|
|
5
6
|
* Provides methods for chaining.
|
|
@@ -8,13 +9,14 @@ import type { PropertyValidator, PropertyValidatorWithOptions } from './Property
|
|
|
8
9
|
*/
|
|
9
10
|
export declare abstract class SchemaBase<T> implements PropertyValidator<T, {
|
|
10
11
|
readonly optional: false;
|
|
11
|
-
}
|
|
12
|
+
}>, JsonSchemaProvider {
|
|
12
13
|
private readonly currentValidator;
|
|
13
14
|
private readonly previousSchema?;
|
|
14
15
|
private readonly operation?;
|
|
15
16
|
__type: import("@amazon/vinyl-util").Invariant<T>;
|
|
16
17
|
private readonly validator;
|
|
17
18
|
private _options;
|
|
19
|
+
private _jsonSchemaDescription?;
|
|
18
20
|
get options(): {
|
|
19
21
|
readonly optional: false;
|
|
20
22
|
};
|
|
@@ -33,6 +35,26 @@ export declare abstract class SchemaBase<T> implements PropertyValidator<T, {
|
|
|
33
35
|
*/
|
|
34
36
|
constructor(currentValidator: Validator<any, any>, previousSchema: SchemaBase<any>, operation: (validatorA: Validator<any>, validatorB: Validator<any, any>) => Validator<T>);
|
|
35
37
|
get description(): string;
|
|
38
|
+
/**
|
|
39
|
+
* The composed JSON Schema fragment for this schema, including any {@link describe} description.
|
|
40
|
+
* Composes through chaining the same way {@link description} does; serialize a complete
|
|
41
|
+
* definition with {@link toJsonSchema}.
|
|
42
|
+
*/
|
|
43
|
+
get jsonSchema(): JsonSchema | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Attaches a human-readable description to this schema, akin to zod's `describe`.
|
|
46
|
+
* The description is metadata only; it does not affect validation, and surfaces in the output
|
|
47
|
+
* of {@link toJsonSchema}.
|
|
48
|
+
*
|
|
49
|
+
* @param description The description to attach.
|
|
50
|
+
* @return A clone of this schema carrying the description.
|
|
51
|
+
*/
|
|
52
|
+
describe(description: string): this;
|
|
53
|
+
/**
|
|
54
|
+
* Serializes this schema to a JSON Schema definition, suitable for describing the shape to an
|
|
55
|
+
* LLM or other consumer. Works similarly to zod-to-json-schema.
|
|
56
|
+
*/
|
|
57
|
+
toJsonSchema(): JsonSchema;
|
|
36
58
|
readonly assert: (input: unknown, origin?: string, path?: readonly string[]) => asserts input is T;
|
|
37
59
|
readonly isValid: (input: unknown) => input is T;
|
|
38
60
|
readonly validate: (input: unknown, options?: ValidationOptions, path?: readonly string[]) => readonly ValidationErrorMessage[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaBase.d.ts","sourceRoot":"","sources":["../../../../src/validation/SchemaBase.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,sBAAsB,EACtB,iBAAiB,EACjB,SAAS,EACZ,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EACR,iBAAiB,EAEjB,4BAA4B,EAC/B,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"SchemaBase.d.ts","sourceRoot":"","sources":["../../../../src/validation/SchemaBase.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,sBAAsB,EACtB,iBAAiB,EACjB,SAAS,EACZ,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EACR,iBAAiB,EAEjB,4BAA4B,EAC/B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAOlE;;;;;GAKG;AACH,8BAAsB,UAAU,CAAC,CAAC,CAC9B,YACI,iBAAiB,CAAC,CAAC,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAA;CAAE,CAAC,EAClD,kBAAkB;IAoClB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;IApC/B,MAAM,4CAAiB;IAEvB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;IACxC,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,sBAAsB,CAAC,CAAQ;IAEvC,IAAI,OAAO;;MAEV;IAED;;;;OAIG;gBACS,gBAAgB,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAEjD;;;;;;OAMG;gBAEC,gBAAgB,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,EACrC,cAAc,EAAE,UAAU,CAA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C,KAC9B,SAAS,CAAC,CAAC,CAAC,CAAC,GAClB,SAAS,GAChB,GAAG;IAkBN;;;;;;;OAOG;IACH,SAAS,CAAC,KAAK,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG;IAIxD,QAAQ,IAAI,4BAA4B,CACpC,IAAI,EACJ,CAAC,EACD;QAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAA;KAAE,CAC9B;IASD,QAAQ,IAAI,4BAA4B,CACpC,IAAI,EACJ,CAAC,EACD;QAAE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAA;KAAE,CAC/B;CAQJ"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { IllegalArgumentError, invariant } from '@amazon/vinyl-util';
|
|
6
6
|
import { andValidators } from './andValidators';
|
|
7
|
+
import { mergeJsonSchema } from './JsonSchema';
|
|
7
8
|
const requiredValidationOptions = {
|
|
8
9
|
optional: false,
|
|
9
10
|
};
|
|
@@ -20,6 +21,7 @@ export class SchemaBase {
|
|
|
20
21
|
__type = invariant();
|
|
21
22
|
validator;
|
|
22
23
|
_options = requiredValidationOptions;
|
|
24
|
+
_jsonSchemaDescription;
|
|
23
25
|
get options() {
|
|
24
26
|
return this._options;
|
|
25
27
|
}
|
|
@@ -35,6 +37,39 @@ export class SchemaBase {
|
|
|
35
37
|
get description() {
|
|
36
38
|
return this.validator.description;
|
|
37
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* The composed JSON Schema fragment for this schema, including any {@link describe} description.
|
|
42
|
+
* Composes through chaining the same way {@link description} does; serialize a complete
|
|
43
|
+
* definition with {@link toJsonSchema}.
|
|
44
|
+
*/
|
|
45
|
+
get jsonSchema() {
|
|
46
|
+
const base = this.validator.jsonSchema;
|
|
47
|
+
if (this._jsonSchemaDescription == null)
|
|
48
|
+
return base;
|
|
49
|
+
return mergeJsonSchema(base, {
|
|
50
|
+
description: this._jsonSchemaDescription,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Attaches a human-readable description to this schema, akin to zod's `describe`.
|
|
55
|
+
* The description is metadata only; it does not affect validation, and surfaces in the output
|
|
56
|
+
* of {@link toJsonSchema}.
|
|
57
|
+
*
|
|
58
|
+
* @param description The description to attach.
|
|
59
|
+
* @return A clone of this schema carrying the description.
|
|
60
|
+
*/
|
|
61
|
+
describe(description) {
|
|
62
|
+
const cloned = this.clone();
|
|
63
|
+
cloned._jsonSchemaDescription = description;
|
|
64
|
+
return cloned;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Serializes this schema to a JSON Schema definition, suitable for describing the shape to an
|
|
68
|
+
* LLM or other consumer. Works similarly to zod-to-json-schema.
|
|
69
|
+
*/
|
|
70
|
+
toJsonSchema() {
|
|
71
|
+
return this.jsonSchema ?? {};
|
|
72
|
+
}
|
|
38
73
|
assert = (input, origin, path) => {
|
|
39
74
|
this.validator.assert(input, origin, path);
|
|
40
75
|
};
|
|
@@ -52,6 +87,7 @@ export class SchemaBase {
|
|
|
52
87
|
? this.self(transform(this.currentValidator), this.previousSchema.clone(transform), this.operation)
|
|
53
88
|
: this.self(transform(this.currentValidator));
|
|
54
89
|
cloned._options = this._options;
|
|
90
|
+
cloned._jsonSchemaDescription = this._jsonSchemaDescription;
|
|
55
91
|
return cloned;
|
|
56
92
|
}
|
|
57
93
|
self(current, previous, operation) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetSchema.d.ts","sourceRoot":"","sources":["../../../../src/validation/SetSchema.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,KAAK,EAA0B,SAAS,EAAE,MAAM,aAAa,CAAA;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"SetSchema.d.ts","sourceRoot":"","sources":["../../../../src/validation/SetSchema.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,KAAK,EAA0B,SAAS,EAAE,MAAM,aAAa,CAAA;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAW3C,eAAO,MAAM,aAAa;IACtB;;OAEG;0BACM,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAShC;;;;OAIG;4BACU,CAAC,oBACQ,SAAS,CAAC,CAAC,CAAC,KAC/B,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CA4BpC,CAAA;AAEV,qBAAa,SAAS,CAAC,CAAC,SAAS,WAAW,CAAC,OAAO,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IACzE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAuC;IAE3D;;OAEG;IACH,MAAM,KAAK,IAAI,IAAI,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAIzC;IAED;;;;OAIG;IACH,YAAY,CAAC,CAAC,EACV,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC,GAC/B,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAIxC;;;OAGG;IACH,QAAQ,IAAI,SAAS,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAIrD;;OAEG;IACH,IAAI,CAAC,CAAC,SAAS,WAAW,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;CAGvD"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { substitute } from '@amazon/vinyl-util';
|
|
6
6
|
import { createDeepValidator, createValidator } from './Validator';
|
|
7
7
|
import { ValueSchema } from './ValueSchema';
|
|
8
|
+
import { toJsonSchema } from './JsonSchema';
|
|
8
9
|
/**
|
|
9
10
|
* @private
|
|
10
11
|
*/
|
|
@@ -17,7 +18,7 @@ export const setValidators = {
|
|
|
17
18
|
* Creates a validator that asserts that the input is a set.
|
|
18
19
|
*/
|
|
19
20
|
isSet() {
|
|
20
|
-
return createValidator(locale.set, (input) => input instanceof Set);
|
|
21
|
+
return createValidator(locale.set, (input) => input instanceof Set, undefined, { type: 'array', uniqueItems: true });
|
|
21
22
|
},
|
|
22
23
|
/**
|
|
23
24
|
* Creates a validator that asserts that every element passes the given validator.
|
|
@@ -37,6 +38,10 @@ export const setValidators = {
|
|
|
37
38
|
i++;
|
|
38
39
|
}
|
|
39
40
|
return errors;
|
|
41
|
+
}, {
|
|
42
|
+
type: 'array',
|
|
43
|
+
uniqueItems: true,
|
|
44
|
+
items: toJsonSchema(elementValidator),
|
|
40
45
|
});
|
|
41
46
|
},
|
|
42
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringSchema.d.ts","sourceRoot":"","sources":["../../../../src/validation/StringSchema.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAc5C,eAAO,MAAM,gBAAgB;IACzB;;OAEG;6BACS,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"StringSchema.d.ts","sourceRoot":"","sources":["../../../../src/validation/StringSchema.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAc5C,eAAO,MAAM,gBAAgB;IACzB;;OAEG;6BACS,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IASrC;;;;;OAKG;8BACY,MAAM,KAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IASjD;;;;;OAKG;8BACY,MAAM,KAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IASjD;;;OAGG;iCACa,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IAOzC;;;OAGG;8BACY,MAAM,KAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;CAU3C,CAAA;AAEV,qBAAa,YAAa,SAAQ,WAAW,CAAC,MAAM,CAAC;IACjD,OAAO,CAAC,MAAM,CAAC,KAAK,CAA4B;IAEhD;;OAEG;IACH,MAAM,KAAK,IAAI,IAAI,YAAY,CAI9B;IAED;;OAEG;IACH,QAAQ,IAAI,YAAY;IAIxB;;;;;OAKG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IAIpC;;;;;OAKG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IAIpC;;;OAGG;IACH,YAAY,IAAI,YAAY;IAI5B;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY;CAGvC"}
|
|
@@ -21,7 +21,7 @@ export const stringValidators = {
|
|
|
21
21
|
* Creates a validator that asserts that the input is not empty.
|
|
22
22
|
*/
|
|
23
23
|
notEmpty() {
|
|
24
|
-
return createValidator(locale.notEmpty, (input) => input !== '');
|
|
24
|
+
return createValidator(locale.notEmpty, (input) => input !== '', undefined, { minLength: 1 });
|
|
25
25
|
},
|
|
26
26
|
/**
|
|
27
27
|
* Creates a validator that asserts that the input string has at least the given minimum
|
|
@@ -30,7 +30,7 @@ export const stringValidators = {
|
|
|
30
30
|
* @param min The string must be at least this length.
|
|
31
31
|
*/
|
|
32
32
|
minLength(min) {
|
|
33
|
-
return createValidator(substitute(locale.minLength, { value: min }), (input) => input.length >= min);
|
|
33
|
+
return createValidator(substitute(locale.minLength, { value: min }), (input) => input.length >= min, undefined, { minLength: min });
|
|
34
34
|
},
|
|
35
35
|
/**
|
|
36
36
|
* Creates a validator that asserts that the input string has at most the given maximum
|
|
@@ -39,7 +39,7 @@ export const stringValidators = {
|
|
|
39
39
|
* @param max The string must be at most this length.
|
|
40
40
|
*/
|
|
41
41
|
maxLength(max) {
|
|
42
|
-
return createValidator(substitute(locale.maxLength, { value: max }), (input) => input.length <= max);
|
|
42
|
+
return createValidator(substitute(locale.maxLength, { value: max }), (input) => input.length <= max, undefined, { maxLength: max });
|
|
43
43
|
},
|
|
44
44
|
/**
|
|
45
45
|
* Creates a validator that asserts that the input string has no whitespace characters.
|
|
@@ -55,7 +55,7 @@ export const stringValidators = {
|
|
|
55
55
|
matches(regex) {
|
|
56
56
|
return createValidator(substitute(locale.matches, { value: regex.toString() }), (input) => {
|
|
57
57
|
return regex.test(input);
|
|
58
|
-
});
|
|
58
|
+
}, undefined, { pattern: regex.source });
|
|
59
59
|
},
|
|
60
60
|
};
|
|
61
61
|
export class StringSchema extends ValueSchema {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Invariant } from '@amazon/vinyl-util';
|
|
2
|
+
import type { JsonSchema } from './JsonSchema';
|
|
2
3
|
/**
|
|
3
4
|
* Represents a validation failure.
|
|
4
5
|
*/
|
|
@@ -27,6 +28,15 @@ export interface Validator<Output extends Input, in Input = unknown> {
|
|
|
27
28
|
* A short description of the validator.
|
|
28
29
|
*/
|
|
29
30
|
readonly description: string;
|
|
31
|
+
/**
|
|
32
|
+
* The JSON Schema fragment this validator contributes, if any.
|
|
33
|
+
*
|
|
34
|
+
* Fragments compose the same way the {@link description} does: chaining validators with `and`
|
|
35
|
+
* merges their fragments, and `or` unions them into an `anyOf`. Serialize a full schema with
|
|
36
|
+
* {@link toJsonSchema}. A validator with no meaningful shape (for example a bare type check)
|
|
37
|
+
* may omit this.
|
|
38
|
+
*/
|
|
39
|
+
readonly jsonSchema?: JsonSchema | undefined;
|
|
30
40
|
/**
|
|
31
41
|
* Returns true if the input is valid according to this validator.
|
|
32
42
|
*
|
|
@@ -74,8 +84,9 @@ export declare function createValidationExpectationMessage<Input>(expectationMes
|
|
|
74
84
|
* @param isValid Returns true if the given input is valid.
|
|
75
85
|
* @param inputStringify Stringifies the input for use as the actual `{actual}` token in the validation
|
|
76
86
|
* expectation template. Default is `stringifyForPrint` with a 500 character max length.
|
|
87
|
+
* @param jsonSchema The JSON Schema fragment this validator contributes, if any.
|
|
77
88
|
*/
|
|
78
|
-
export declare function createValidator<Output extends Input, Input = unknown>(expectationMessage: string, isValid: (input: Input) => boolean, inputStringify?: (input: Input) => string): Validator<Output, Input>;
|
|
89
|
+
export declare function createValidator<Output extends Input, Input = unknown>(expectationMessage: string, isValid: (input: Input) => boolean, inputStringify?: (input: Input) => string, jsonSchema?: JsonSchema): Validator<Output, Input>;
|
|
79
90
|
/**
|
|
80
91
|
* Creates a new deep validator.
|
|
81
92
|
*
|
|
@@ -83,6 +94,7 @@ export declare function createValidator<Output extends Input, Input = unknown>(e
|
|
|
83
94
|
*
|
|
84
95
|
* @param description Describes the validator.
|
|
85
96
|
* @param validate Returns an array of validation failures.
|
|
97
|
+
* @param jsonSchema The JSON Schema fragment this validator contributes, if any.
|
|
86
98
|
*/
|
|
87
|
-
export declare function createDeepValidator<Output extends Input, Input = unknown>(description: string, validate: (input: Input, options: ValidationOptions, path: readonly string[]) => readonly ValidationErrorMessage[]): Validator<Output, Input>;
|
|
99
|
+
export declare function createDeepValidator<Output extends Input, Input = unknown>(description: string, validate: (input: Input, options: ValidationOptions, path: readonly string[]) => readonly ValidationErrorMessage[], jsonSchema?: JsonSchema): Validator<Output, Input>;
|
|
88
100
|
//# sourceMappingURL=Validator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../../src/validation/Validator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../../src/validation/Validator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,oBAAoB,CAAA;AAEpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM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ClC,MAAM,CAMR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,MAAM,SAAS,KAAK,EAAE,KAAK,GAAG,OAAO,EACjE,kBAAkB,EAAE,MAAM,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,EAClC,cAAc,GAAE,CAAC,KAAK,EAAE,KAAK,KAAK,MACD,EACjC,UAAU,CAAC,EAAE,UAAU,GACxB,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAiD1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,SAAS,KAAK,EAAE,KAAK,GAAG,OAAO,EACrE,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,CACN,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,SAAS,MAAM,EAAE,KACtB,SAAS,sBAAsB,EAAE,EACtC,UAAU,CAAC,EAAE,UAAU,GACxB,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CA6B1B"}
|
|
@@ -42,10 +42,12 @@ export function createValidationExpectationMessage(expectationMessage, input, pa
|
|
|
42
42
|
* @param isValid Returns true if the given input is valid.
|
|
43
43
|
* @param inputStringify Stringifies the input for use as the actual `{actual}` token in the validation
|
|
44
44
|
* expectation template. Default is `stringifyForPrint` with a 500 character max length.
|
|
45
|
+
* @param jsonSchema The JSON Schema fragment this validator contributes, if any.
|
|
45
46
|
*/
|
|
46
|
-
export function createValidator(expectationMessage, isValid, inputStringify = (input) => stringifyForPrint(input, 500)) {
|
|
47
|
+
export function createValidator(expectationMessage, isValid, inputStringify = (input) => stringifyForPrint(input, 500), jsonSchema) {
|
|
47
48
|
return {
|
|
48
49
|
description: expectationMessage,
|
|
50
|
+
jsonSchema,
|
|
49
51
|
isValid(input) {
|
|
50
52
|
return isValid(input);
|
|
51
53
|
},
|
|
@@ -74,10 +76,12 @@ export function createValidator(expectationMessage, isValid, inputStringify = (i
|
|
|
74
76
|
*
|
|
75
77
|
* @param description Describes the validator.
|
|
76
78
|
* @param validate Returns an array of validation failures.
|
|
79
|
+
* @param jsonSchema The JSON Schema fragment this validator contributes, if any.
|
|
77
80
|
*/
|
|
78
|
-
export function createDeepValidator(description, validate) {
|
|
81
|
+
export function createDeepValidator(description, validate, jsonSchema) {
|
|
79
82
|
return {
|
|
80
83
|
description,
|
|
84
|
+
jsonSchema,
|
|
81
85
|
isValid(input) {
|
|
82
86
|
return validate(input, { all: false }, []).length === 0;
|
|
83
87
|
},
|
|
@@ -4,6 +4,7 @@ export declare const valueValidators: {
|
|
|
4
4
|
readonly any: () => Validator<any>;
|
|
5
5
|
/**
|
|
6
6
|
* Creates a validator that asserts that the input is nullish.
|
|
7
|
+
* JSON Schema has no representation for `undefined`, so only `null` is expressed.
|
|
7
8
|
*/
|
|
8
9
|
readonly nullish: () => Validator<null | undefined>;
|
|
9
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValueSchema.d.ts","sourceRoot":"","sources":["../../../../src/validation/ValueSchema.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAS5C,eAAO,MAAM,eAAe;wBACjB,SAAS,CAAC,GAAG,CAAC;IAKrB
|
|
1
|
+
{"version":3,"file":"ValueSchema.d.ts","sourceRoot":"","sources":["../../../../src/validation/ValueSchema.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAS5C,eAAO,MAAM,eAAe;wBACjB,SAAS,CAAC,GAAG,CAAC;IAKrB;;;OAGG;4BACQ,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC;IAWtC;;OAEG;yBACK,SAAS,CAAC,IAAI,CAAC;IAWvB;;OAEG;8BACU,SAAS,CAAC,SAAS,CAAC;CAG3B,CAAA;AAEV,qBAAa,WAAW,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IAC7C;;OAEG;IACH,KAAK,IAAI,WAAW,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC;IAI1C;;OAEG;IACH,MAAM,IAAI,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC;IAI/B;;OAEG;IACH,WAAW,IAAI,WAAW,CAAC,CAAC,GAAG,SAAS,CAAC;IAIzC;;;;;;;OAOG;IACH,GAAG,CAAC,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC;IAIvD;;;;;;;;;OASG;IACH,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC;CAG9D"}
|
|
@@ -18,15 +18,20 @@ export const valueValidators = {
|
|
|
18
18
|
},
|
|
19
19
|
/**
|
|
20
20
|
* Creates a validator that asserts that the input is nullish.
|
|
21
|
+
* JSON Schema has no representation for `undefined`, so only `null` is expressed.
|
|
21
22
|
*/
|
|
22
23
|
nullish() {
|
|
23
|
-
return createValidator(locale.nullish, (input) => input == null
|
|
24
|
+
return createValidator(locale.nullish, (input) => input == null, undefined, {
|
|
25
|
+
type: 'null',
|
|
26
|
+
});
|
|
24
27
|
},
|
|
25
28
|
/**
|
|
26
29
|
* Creates a validator that asserts that the input is strictly null.
|
|
27
30
|
*/
|
|
28
31
|
null() {
|
|
29
|
-
return createValidator(locale.null, (input) => input === null
|
|
32
|
+
return createValidator(locale.null, (input) => input === null, undefined, {
|
|
33
|
+
type: 'null',
|
|
34
|
+
});
|
|
30
35
|
},
|
|
31
36
|
/**
|
|
32
37
|
* Creates a validator that asserts that the input is strictly undefined.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"andValidators.d.ts","sourceRoot":"","sources":["../../../../src/validation/andValidators.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"andValidators.d.ts","sourceRoot":"","sources":["../../../../src/validation/andValidators.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAqC5C;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,EAAE,KAAK,EACnD,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EAC/B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAC9B,SAAS,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;AAE1B;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EACtD,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EAC/B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAC7B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAC9B,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;AAE9B;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EACzD,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EAC/B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAC7B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAC7B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAC9B,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;AAEhC;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAC5D,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EAC/B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAC7B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAC7B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAC7B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAC9B,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;AAEpC,wBAAgB,aAAa,CACzB,GAAG,UAAU,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GACrC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { substitute } from '@amazon/vinyl-util';
|
|
6
6
|
import { createDeepValidator } from './Validator';
|
|
7
|
+
import { mergeJsonSchema } from './JsonSchema';
|
|
7
8
|
/*
|
|
8
9
|
* @brief
|
|
9
10
|
* andValidators will intersect an arbitrary number of validators.
|
|
@@ -44,5 +45,5 @@ export function andValidators(...validators) {
|
|
|
44
45
|
return errors;
|
|
45
46
|
}
|
|
46
47
|
return [];
|
|
47
|
-
});
|
|
48
|
+
}, mergeJsonSchema(...validators.map((v) => v.jsonSchema)));
|
|
48
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orValidators.d.ts","sourceRoot":"","sources":["../../../../src/validation/orValidators.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAA0B,SAAS,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"orValidators.d.ts","sour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EAC7B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAC7B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAC7B,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAC9B,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;AAEpC,wBAAgB,YAAY,CACxB,GAAG,UAAU,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GACrC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA"}
|
|
@@ -26,6 +26,23 @@ const locale = {
|
|
|
26
26
|
*/
|
|
27
27
|
separator: ' | ',
|
|
28
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Composes the child validators' JSON Schema fragments into a union.
|
|
31
|
+
*
|
|
32
|
+
* Branches with no fragment are skipped: JSON Schema has no representation for `undefined`, and a
|
|
33
|
+
* value's optionality is instead conveyed by an object's `required` list. A single remaining branch
|
|
34
|
+
* collapses to that branch rather than a redundant `anyOf`.
|
|
35
|
+
*/
|
|
36
|
+
function unionJsonSchema(validators) {
|
|
37
|
+
const branches = validators
|
|
38
|
+
.map((v) => v.jsonSchema)
|
|
39
|
+
.filter((fragment) => fragment != null);
|
|
40
|
+
if (branches.length === 0)
|
|
41
|
+
return undefined;
|
|
42
|
+
if (branches.length === 1)
|
|
43
|
+
return branches[0];
|
|
44
|
+
return { anyOf: branches };
|
|
45
|
+
}
|
|
29
46
|
/**
|
|
30
47
|
* Validates that one of the given validators pass.
|
|
31
48
|
*
|
|
@@ -70,5 +87,5 @@ export function orValidators(...validators) {
|
|
|
70
87
|
path,
|
|
71
88
|
},
|
|
72
89
|
];
|
|
73
|
-
});
|
|
90
|
+
}, unionJsonSchema(validators));
|
|
74
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeOfValidators.d.ts","sourceRoot":"","sources":["../../../../src/validation/typeOfValidators.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"typeOfValidators.d.ts","sourceRoot":"","sources":["../../../../src/validation/typeOfValidators.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AA0D5C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;;;;;;;CAmBnB,CAAA"}
|
|
@@ -10,6 +10,16 @@ import { createValidator } from './Validator';
|
|
|
10
10
|
const locale = {
|
|
11
11
|
template: 'type {value}',
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* The JSON Schema `type` for each JavaScript `typeof` value that has a JSON representation.
|
|
15
|
+
* Types with no JSON equivalent (`function`, `symbol`) are absent and contribute no fragment.
|
|
16
|
+
*/
|
|
17
|
+
const jsonSchemaTypeByTypeof = {
|
|
18
|
+
string: 'string',
|
|
19
|
+
number: 'number',
|
|
20
|
+
boolean: 'boolean',
|
|
21
|
+
object: 'object',
|
|
22
|
+
};
|
|
13
23
|
/**
|
|
14
24
|
* Creates a validator that validates that the input is not nullish and its `typeof` matches the
|
|
15
25
|
* expected value.
|
|
@@ -20,9 +30,11 @@ const locale = {
|
|
|
20
30
|
* @param expected
|
|
21
31
|
*/
|
|
22
32
|
function typeOfValidator(expected) {
|
|
33
|
+
const jsonType = jsonSchemaTypeByTypeof[expected];
|
|
34
|
+
const jsonSchema = jsonType == null ? undefined : { type: jsonType };
|
|
23
35
|
return createValidator(substitute(locale.template, { value: expected }), (input) => {
|
|
24
36
|
return input != null && typeof input === expected;
|
|
25
|
-
});
|
|
37
|
+
}, undefined, jsonSchema);
|
|
26
38
|
}
|
|
27
39
|
const typeOfValidatorCache = {};
|
|
28
40
|
function cachedTypeOfValidator(type) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../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AAS,CAAC,CAAC,CAAC,GAC7B,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAEjC;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,KAAK,CAAC,CAAC,EACvB,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC,GAC/B,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAEnB;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,YAAY,CAErC;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,EAC1C,GAAG,UAAU,EAAE;KACV,KAAK,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;CAC1C,GACF,WAAW,CAAC;KACV,KAAK,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;CAC/B,CAAC,CAED;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,CAE5C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,WAAW,CAAC,SAAS,CAAC,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACpB,kBAAkB,EAAE,MAAM,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,EACpC,cAAc,GAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MACH,GAClC,WAAW,CAAC,CAAC,CAAC,CAIhB"}
|
|
@@ -60,7 +60,7 @@ export function instanceOf(clazz) {
|
|
|
60
60
|
export function isOneOf(...possibleValues) {
|
|
61
61
|
return new ValueSchema(createValidator(substitute(locale.isOneOf, {
|
|
62
62
|
value: possibleValues.join(locale.oneOfSeparator),
|
|
63
|
-
}), (input) => possibleValues.includes(input)));
|
|
63
|
+
}), (input) => possibleValues.includes(input), undefined, { enum: [...possibleValues] }));
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Creates a validator that asserts that the input is one of the values of the given enum.
|