@amazon/vinyl-validation 1.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.
Files changed (109) hide show
  1. package/dist/index.cjs +1325 -0
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/index.js +1308 -0
  4. package/dist/index.js.map +7 -0
  5. package/dist/types/current/index.d.ts +18 -0
  6. package/dist/types/current/index.d.ts.map +1 -0
  7. package/dist/types/current/index.js +17 -0
  8. package/dist/types/current/tsconfig.tsbuildinfo +1 -0
  9. package/dist/types/current/validation/ArraySchema.d.ts +82 -0
  10. package/dist/types/current/validation/ArraySchema.d.ts.map +1 -0
  11. package/dist/types/current/validation/ArraySchema.js +148 -0
  12. package/dist/types/current/validation/FunctionSchema.d.ts +21 -0
  13. package/dist/types/current/validation/FunctionSchema.d.ts.map +1 -0
  14. package/dist/types/current/validation/FunctionSchema.js +42 -0
  15. package/dist/types/current/validation/NumberSchema.d.ts +100 -0
  16. package/dist/types/current/validation/NumberSchema.d.ts.map +1 -0
  17. package/dist/types/current/validation/NumberSchema.js +146 -0
  18. package/dist/types/current/validation/ObjectSchema.d.ts +54 -0
  19. package/dist/types/current/validation/ObjectSchema.d.ts.map +1 -0
  20. package/dist/types/current/validation/ObjectSchema.js +125 -0
  21. package/dist/types/current/validation/PropertyValidator.d.ts +23 -0
  22. package/dist/types/current/validation/PropertyValidator.d.ts.map +1 -0
  23. package/dist/types/current/validation/PropertyValidator.js +5 -0
  24. package/dist/types/current/validation/RecordSchema.d.ts +58 -0
  25. package/dist/types/current/validation/RecordSchema.d.ts.map +1 -0
  26. package/dist/types/current/validation/RecordSchema.js +101 -0
  27. package/dist/types/current/validation/SchemaBase.d.ts +65 -0
  28. package/dist/types/current/validation/SchemaBase.d.ts.map +1 -0
  29. package/dist/types/current/validation/SchemaBase.js +90 -0
  30. package/dist/types/current/validation/SetSchema.d.ts +38 -0
  31. package/dist/types/current/validation/SetSchema.d.ts.map +1 -0
  32. package/dist/types/current/validation/SetSchema.js +74 -0
  33. package/dist/types/current/validation/StringSchema.d.ts +68 -0
  34. package/dist/types/current/validation/StringSchema.d.ts.map +1 -0
  35. package/dist/types/current/validation/StringSchema.js +109 -0
  36. package/dist/types/current/validation/Validator.d.ts +88 -0
  37. package/dist/types/current/validation/Validator.d.ts.map +1 -0
  38. package/dist/types/current/validation/Validator.js +95 -0
  39. package/dist/types/current/validation/ValidatorWithPartial.d.ts +26 -0
  40. package/dist/types/current/validation/ValidatorWithPartial.d.ts.map +1 -0
  41. package/dist/types/current/validation/ValidatorWithPartial.js +31 -0
  42. package/dist/types/current/validation/ValueSchema.d.ts +52 -0
  43. package/dist/types/current/validation/ValueSchema.d.ts.map +1 -0
  44. package/dist/types/current/validation/ValueSchema.js +81 -0
  45. package/dist/types/current/validation/andValidators.d.ts +19 -0
  46. package/dist/types/current/validation/andValidators.d.ts.map +1 -0
  47. package/dist/types/current/validation/andValidators.js +48 -0
  48. package/dist/types/current/validation/orValidators.d.ts +19 -0
  49. package/dist/types/current/validation/orValidators.d.ts.map +1 -0
  50. package/dist/types/current/validation/orValidators.js +74 -0
  51. package/dist/types/current/validation/typeOfValidators.d.ts +15 -0
  52. package/dist/types/current/validation/typeOfValidators.d.ts.map +1 -0
  53. package/dist/types/current/validation/typeOfValidators.js +58 -0
  54. package/dist/types/current/validation/validators.d.ts +127 -0
  55. package/dist/types/current/validation/validators.d.ts.map +1 -0
  56. package/dist/types/current/validation/validators.js +168 -0
  57. package/dist/types/ts3.7/index.d.ts +18 -0
  58. package/dist/types/ts3.7/validation/ArraySchema.d.ts +86 -0
  59. package/dist/types/ts3.7/validation/FunctionSchema.d.ts +21 -0
  60. package/dist/types/ts3.7/validation/NumberSchema.d.ts +100 -0
  61. package/dist/types/ts3.7/validation/ObjectSchema.d.ts +56 -0
  62. package/dist/types/ts3.7/validation/PropertyValidator.d.ts +23 -0
  63. package/dist/types/ts3.7/validation/RecordSchema.d.ts +58 -0
  64. package/dist/types/ts3.7/validation/SchemaBase.d.ts +65 -0
  65. package/dist/types/ts3.7/validation/SetSchema.d.ts +38 -0
  66. package/dist/types/ts3.7/validation/StringSchema.d.ts +68 -0
  67. package/dist/types/ts3.7/validation/Validator.d.ts +88 -0
  68. package/dist/types/ts3.7/validation/ValidatorWithPartial.d.ts +26 -0
  69. package/dist/types/ts3.7/validation/ValueSchema.d.ts +52 -0
  70. package/dist/types/ts3.7/validation/andValidators.d.ts +19 -0
  71. package/dist/types/ts3.7/validation/orValidators.d.ts +19 -0
  72. package/dist/types/ts3.7/validation/typeOfValidators.d.ts +15 -0
  73. package/dist/types/ts3.7/validation/validators.d.ts +127 -0
  74. package/dist/types/ts4.1/index.d.ts +18 -0
  75. package/dist/types/ts4.1/validation/ArraySchema.d.ts +86 -0
  76. package/dist/types/ts4.1/validation/FunctionSchema.d.ts +21 -0
  77. package/dist/types/ts4.1/validation/NumberSchema.d.ts +100 -0
  78. package/dist/types/ts4.1/validation/ObjectSchema.d.ts +56 -0
  79. package/dist/types/ts4.1/validation/PropertyValidator.d.ts +23 -0
  80. package/dist/types/ts4.1/validation/RecordSchema.d.ts +58 -0
  81. package/dist/types/ts4.1/validation/SchemaBase.d.ts +65 -0
  82. package/dist/types/ts4.1/validation/SetSchema.d.ts +38 -0
  83. package/dist/types/ts4.1/validation/StringSchema.d.ts +68 -0
  84. package/dist/types/ts4.1/validation/Validator.d.ts +88 -0
  85. package/dist/types/ts4.1/validation/ValidatorWithPartial.d.ts +26 -0
  86. package/dist/types/ts4.1/validation/ValueSchema.d.ts +52 -0
  87. package/dist/types/ts4.1/validation/andValidators.d.ts +19 -0
  88. package/dist/types/ts4.1/validation/orValidators.d.ts +19 -0
  89. package/dist/types/ts4.1/validation/typeOfValidators.d.ts +15 -0
  90. package/dist/types/ts4.1/validation/validators.d.ts +128 -0
  91. package/dist/types/ts4.7/index.d.ts +18 -0
  92. package/dist/types/ts4.7/validation/ArraySchema.d.ts +86 -0
  93. package/dist/types/ts4.7/validation/FunctionSchema.d.ts +21 -0
  94. package/dist/types/ts4.7/validation/NumberSchema.d.ts +100 -0
  95. package/dist/types/ts4.7/validation/ObjectSchema.d.ts +56 -0
  96. package/dist/types/ts4.7/validation/PropertyValidator.d.ts +23 -0
  97. package/dist/types/ts4.7/validation/RecordSchema.d.ts +58 -0
  98. package/dist/types/ts4.7/validation/SchemaBase.d.ts +65 -0
  99. package/dist/types/ts4.7/validation/SetSchema.d.ts +38 -0
  100. package/dist/types/ts4.7/validation/StringSchema.d.ts +68 -0
  101. package/dist/types/ts4.7/validation/Validator.d.ts +88 -0
  102. package/dist/types/ts4.7/validation/ValidatorWithPartial.d.ts +26 -0
  103. package/dist/types/ts4.7/validation/ValueSchema.d.ts +52 -0
  104. package/dist/types/ts4.7/validation/andValidators.d.ts +19 -0
  105. package/dist/types/ts4.7/validation/orValidators.d.ts +19 -0
  106. package/dist/types/ts4.7/validation/typeOfValidators.d.ts +15 -0
  107. package/dist/types/ts4.7/validation/validators.d.ts +127 -0
  108. package/docs/VALIDATION.md +344 -0
  109. package/package.json +82 -0
@@ -0,0 +1,128 @@
1
+ import type { AnyRecord, Fun, Primitive, ReadonlyRecord } from '@amazon/vinyl-util';
2
+ import { ArraySchema } from './ArraySchema';
3
+ import { FunctionSchema } from './FunctionSchema';
4
+ import { SetSchema } from './SetSchema';
5
+ import { ValueSchema } from './ValueSchema';
6
+ import { NumberSchema } from './NumberSchema';
7
+ import type { ExtendedPropertyValidators } from './ObjectSchema';
8
+ import { ObjectSchema } from './ObjectSchema';
9
+ import { RecordSchema } from './RecordSchema';
10
+ import { StringSchema } from './StringSchema';
11
+ import type { Validator } from './Validator';
12
+ /**
13
+ * Creates a no-op validator. The value can be any type.
14
+ */
15
+ export declare function any(): ValueSchema<any>;
16
+ /**
17
+ * Creates a validator that asserts that the input is an array.
18
+ */
19
+ export declare function array(): ArraySchema<unknown[]>;
20
+ /**
21
+ * Creates a validator that asserts that the input is an array and every element passes the
22
+ * given validator.
23
+ *
24
+ * @param elementValidator
25
+ */
26
+ export declare function array<U>(elementValidator: Validator<U>): ArraySchema<U[]>;
27
+ /**
28
+ * Creates a validator that asserts that the input is a boolean.
29
+ */
30
+ export declare function boolean(): ValueSchema<boolean>;
31
+ /**
32
+ * Creates a validator that asserts that the input is a function.
33
+ */
34
+ export declare function func(): FunctionSchema<Fun>;
35
+ /**
36
+ * Validates that the input is an instanceof the given prototype.
37
+ * @param clazz
38
+ */
39
+ export declare function instanceOf<T>(clazz: new (...args: any[]) => T): ValueSchema<T>;
40
+ /**
41
+ * Creates a validator that asserts that the input is nullish or one of the given possible values.
42
+ *
43
+ * @param possibleValues
44
+ */
45
+ export declare function isOneOf<U extends readonly Primitive[]>(...possibleValues: U): ValueSchema<U[number]>;
46
+ /**
47
+ * Creates a validator that asserts that the input is one of the values of the given enum.
48
+ *
49
+ * @param enumObject The enum to validate against.
50
+ */
51
+ export declare function enumOf<T extends Record<string, Primitive>>(enumObject: T): ValueSchema<T[keyof T]>;
52
+ /**
53
+ * Creates a validator that asserts that the input is null.
54
+ */
55
+ export declare function exactlyNull(): Validator<null>;
56
+ /**
57
+ * Creates a validator that asserts that the input is nullish.
58
+ */
59
+ export declare function nullish(): Validator<null | undefined>;
60
+ /**
61
+ * Creates a validator that asserts that the input is a number.
62
+ */
63
+ export declare function number(): NumberSchema;
64
+ /**
65
+ * Creates a validator that validates the input has properties that pass their respective
66
+ * validators.
67
+ */
68
+ export declare function object<U extends object>(propertyValidators: ExtendedPropertyValidators<AnyRecord, U>): ObjectSchema<U>;
69
+ /**
70
+ * Returns a validator that asserts that the object's own enumerable properties has keys and
71
+ * values that match their respective validators.
72
+ *
73
+ * Prototype members are not included.
74
+ * Numeric keys are validated as strings. For example the object `{ [0]: 1 }` will be passed
75
+ * to the key validator as '0'.
76
+ *
77
+ * To assume string keys, use {@link recordValues}
78
+ *
79
+ * @param keyValidator Validates each key.
80
+ * @param valueValidator Validates each value.
81
+ */
82
+ export declare function record<K extends string | symbol, V>(keyValidator: Validator<K>, valueValidator: Validator<V>): RecordSchema<ReadonlyRecord<K, V>>;
83
+ /**
84
+ * Returns a validator that asserts that the input object's own enumerable properties has
85
+ * string keys and values that match the given validator.
86
+ *
87
+ * Prototype members are not included.
88
+ *
89
+ * @param valueValidator Validates each value.
90
+ */
91
+ export declare function recordValues<V>(valueValidator: Validator<V>): RecordSchema<Record<string, V>>;
92
+ /**
93
+ * Returns a validator that asserts the input is a set with elements that match the given
94
+ * element validator.
95
+ * @param elementValidator
96
+ */
97
+ export declare function set<U>(elementValidator: Validator<U>): SetSchema<Set<U>>;
98
+ /**
99
+ * Creates a validator that asserts that the input is type 'string'.
100
+ */
101
+ export declare function string(): StringSchema;
102
+ /**
103
+ * Creates a validator that asserts that the input array is a tuple whose elements match
104
+ * the given validators.
105
+ *
106
+ * @param validators
107
+ */
108
+ export declare function tuple<U extends readonly any[]>(...validators: {
109
+ [Index in keyof U]: Validator<U[Index]>;
110
+ }): ArraySchema<{
111
+ [Index in keyof U]: U[Index];
112
+ }>;
113
+ /**
114
+ * Creates a validator that asserts that the input is type 'symbol'.
115
+ */
116
+ export declare function symbol(): ValueSchema<symbol>;
117
+ /**
118
+ * Creates a validator that asserts that the input is strictly undefined.
119
+ */
120
+ export declare function exactlyUndefined(): ValueSchema<undefined>;
121
+ /**
122
+ * Returns a custom
123
+ * @param expectationMessage
124
+ * @param isValid
125
+ * @param inputStringify
126
+ */
127
+ export declare function custom<T>(expectationMessage: string, isValid: (input: unknown) => boolean, inputStringify?: (input: unknown) => string): ValueSchema<T>;
128
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1,18 @@
1
+ /** Auto-generated from build scripts */
2
+ export * from './validation/validators';
3
+ export * from './validation/typeOfValidators';
4
+ export * from './validation/orValidators';
5
+ export * from './validation/andValidators';
6
+ export * from './validation/ValueSchema';
7
+ export * from './validation/ValidatorWithPartial';
8
+ export * from './validation/Validator';
9
+ export * from './validation/StringSchema';
10
+ export * from './validation/SetSchema';
11
+ export * from './validation/SchemaBase';
12
+ export * from './validation/RecordSchema';
13
+ export * from './validation/PropertyValidator';
14
+ export * from './validation/ObjectSchema';
15
+ export * from './validation/NumberSchema';
16
+ export * from './validation/FunctionSchema';
17
+ export * from './validation/ArraySchema';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,86 @@
1
+ import type { ElementType } from '@amazon/vinyl-util';
2
+ import { ValueSchema } from './ValueSchema';
3
+ import type { Validator } from './Validator';
4
+ export declare const arrayValidators: {
5
+ /**
6
+ * Creates a validator that asserts that the input is an array.
7
+ *
8
+ * Note: arrays can only be readonly by type system, there is no native readonly
9
+ * js array. This validator assumes mutability, use the ArraySchema readonly() method
10
+ * to cast to a readonly array.
11
+ */
12
+ readonly isArray: () => Validator<unknown[]>;
13
+ /**
14
+ * Creates a validator that asserts that every element passes the given validator.
15
+ *
16
+ * @param elementValidator
17
+ */
18
+ readonly withElements: <U>(elementValidator: Validator<U>) => Validator<U[], readonly unknown[]>;
19
+ /**
20
+ * Creates a validator that asserts that the input array is a tuple whose elements match
21
+ * the given validators.
22
+ *
23
+ * @param validators
24
+ */
25
+ readonly tuple: <U extends readonly any[]>(...validators: {
26
+ [Index in keyof U]: Validator<U[Index]>;
27
+ }) => Validator<{
28
+ [Index in keyof U]: U[Index];
29
+ }, readonly unknown[]>;
30
+ /**
31
+ * Creates a validator that validates the input array has the given minimum length.
32
+ * @param min The minimum number of elements (inclusive)
33
+ */
34
+ readonly minLength: (min: number) => Validator<readonly unknown[], readonly unknown[]>;
35
+ /**
36
+ *
37
+ * Creates a validator that validates the input array has the given maximum length.
38
+ * @param max The maximum number of elements (inclusive)
39
+ */
40
+ readonly maxLength: (max: number) => Validator<readonly unknown[], readonly unknown[]>;
41
+ };
42
+ export declare class ArraySchema<T extends readonly unknown[]> extends ValueSchema<T> {
43
+ private static _base;
44
+ /**
45
+ * The base ArraySchema instance validating that the input is an Array.
46
+ */
47
+ static get base(): ArraySchema<unknown[]>;
48
+ /**
49
+ * Creates a validator that asserts that every element passes the given validator.
50
+ *
51
+ * @param elementValidator
52
+ */
53
+ withElements<U>(elementValidator: Validator<U>): ArraySchema<(ElementType<T> & U)[]>;
54
+ /**
55
+ * Creates a validator that asserts that the input array is a tuple whose elements match
56
+ * the given validators.
57
+ *
58
+ * @param validators
59
+ */
60
+ tuple<U extends readonly any[]>(...validators: {
61
+ [Index in keyof U]: Validator<U[Index]>;
62
+ }): ArraySchema<{
63
+ [Index in keyof U]: U[Index];
64
+ }>;
65
+ /**
66
+ * Creates a validator that validates the input array has the given minimum length.
67
+ * @param min The minimum number of elements (inclusive)
68
+ */
69
+ minLength(min: number): ArraySchema<T>;
70
+ /**
71
+ *
72
+ * Creates a validator that validates the input array has the given maximum length.
73
+ * @param max The maximum number of elements (inclusive)
74
+ */
75
+ maxLength(max: number): ArraySchema<T>;
76
+ /**
77
+ * Casts to a readonly array.
78
+ * This is a shallow cast, elements of the array will not be changed.
79
+ */
80
+ readonly(): ArraySchema<Readonly<T>>;
81
+ /**
82
+ * Casts the type parameter.
83
+ */
84
+ cast<T extends readonly unknown[]>(): ArraySchema<T>;
85
+ }
86
+ //# sourceMappingURL=ArraySchema.d.ts.map
@@ -0,0 +1,21 @@
1
+ import type { Fun } from '@amazon/vinyl-util';
2
+ import { ValueSchema } from './ValueSchema';
3
+ import type { Validator } from './Validator';
4
+ export declare const functionValidators: {
5
+ readonly length: (max: number) => Validator<Fun, Fun>;
6
+ };
7
+ export declare class FunctionSchema<T extends Fun> extends ValueSchema<T> {
8
+ private static _base;
9
+ /**
10
+ * The base Function validator validating that the input is a function.
11
+ */
12
+ static get base(): FunctionSchema<Fun>;
13
+ length(max: number): FunctionSchema<T>;
14
+ /**
15
+ * Casts the function signature.
16
+ * Function signatures, except for their required number of parameters, cannot be
17
+ * meaningfully validated.
18
+ */
19
+ cast<T extends Fun>(): FunctionSchema<T>;
20
+ }
21
+ //# sourceMappingURL=FunctionSchema.d.ts.map
@@ -0,0 +1,100 @@
1
+ import { ValueSchema } from './ValueSchema';
2
+ import type { Validator } from './Validator';
3
+ export declare const numberValidators: {
4
+ /**
5
+ * Creates a validator that asserts that the input number is at least the provided minimum
6
+ * value.
7
+ *
8
+ * @param min The minimum (inclusive) the value may be.
9
+ */
10
+ readonly gte: (min: number) => Validator<number, number>;
11
+ /**
12
+ * Creates a validator that asserts that the input number is greater than the provided minimum
13
+ * value.
14
+ *
15
+ * @param min The minimum (exclusive) the value may be.
16
+ */
17
+ readonly gt: (min: number) => Validator<number, number>;
18
+ /**
19
+ * Creates a validator that asserts that the input number is at most the provided maximum
20
+ * value.
21
+ *
22
+ * @param max The maximum (inclusive) the value may be.
23
+ */
24
+ readonly lte: (max: number) => Validator<number, number>;
25
+ /**
26
+ * Creates a validator that asserts that the input number is less than the provided maximum
27
+ * value.
28
+ *
29
+ * @param max The maximum (exclusive) the value may be.
30
+ */
31
+ readonly lt: (max: number) => Validator<number, number>;
32
+ /**
33
+ * Creates a validator that asserts that the input number is at least the provided minimum
34
+ * and at most the provided maximum values.
35
+ *
36
+ * @param min The minimum (inclusive) value the input may be.
37
+ * @param max The maximum (inclusive) value the input may be.
38
+ */
39
+ readonly within: (min: number, max: number) => Validator<number, number>;
40
+ /**
41
+ * Creates a validator that asserts that the input number is finite.
42
+ */
43
+ readonly finite: () => Validator<number, number>;
44
+ /**
45
+ * Creates a validator that asserts that the input number is a safe integer.
46
+ */
47
+ readonly safeInteger: () => Validator<number, number>;
48
+ };
49
+ export declare class NumberSchema extends ValueSchema<number> {
50
+ private static _base;
51
+ /**
52
+ * The base Object validator validating that the input is an object.
53
+ */
54
+ static get base(): NumberSchema;
55
+ /**
56
+ * Creates a validator that asserts that the input number is at least the provided minimum
57
+ * value.
58
+ *
59
+ * @param min The minimum (inclusive) the value may be.
60
+ */
61
+ gte(min: number): this;
62
+ /**
63
+ * Creates a validator that asserts that the input number is greater than the provided minimum
64
+ * value.
65
+ *
66
+ * @param min The minimum (exclusive) the value may be.
67
+ */
68
+ gt(min: number): this;
69
+ /**
70
+ * Creates a validator that asserts that the input number is at most the provided maximum
71
+ * value.
72
+ *
73
+ * @param max The maximum (inclusive) the value may be.
74
+ */
75
+ lte(max: number): this;
76
+ /**
77
+ * Creates a validator that asserts that the input number is less than the provided maximum
78
+ * value.
79
+ *
80
+ * @param max The maximum (exclusive) the value may be.
81
+ */
82
+ lt(max: number): this;
83
+ /**
84
+ * Creates a validator that asserts that the input number is at least the provided minimum
85
+ * and at most the provided maximum values.
86
+ *
87
+ * @param min The minimum (inclusive) value the input may be.
88
+ * @param max The maximum (inclusive) value the input may be.
89
+ */
90
+ within(min: number, max: number): this;
91
+ /**
92
+ * Creates a validator that asserts that the input number is finite.
93
+ */
94
+ finite(): this;
95
+ /**
96
+ * Creates a validator that asserts that the input number is a safe integer.
97
+ */
98
+ safeInteger(): this;
99
+ }
100
+ //# sourceMappingURL=NumberSchema.d.ts.map
@@ -0,0 +1,56 @@
1
+ import type { AnyRecord, IsPropertyOptional, PartialDeep } from '@amazon/vinyl-util';
2
+ import type { ValidatorWithPartial } from './ValidatorWithPartial';
3
+ import { ValueSchema } from './ValueSchema';
4
+ import type { PropertyValidator } from '../validation/PropertyValidator';
5
+ import type { Equal } from '@amazon/vinyl-util/browserTestUtil';
6
+ export declare const objectValidators: {
7
+ /**
8
+ * Creates a validator that validates the input has properties that pass their respective
9
+ * validators.
10
+ *
11
+ * @param propertyValidators
12
+ */
13
+ readonly properties: <U extends object>(propertyValidators: {
14
+ readonly [P in keyof U]-?: PropertyValidator<Required<U>[P], {
15
+ optional: IsPropertyOptional<U, P>;
16
+ }>;
17
+ }) => ValidatorWithPartial<U, object>;
18
+ };
19
+ /**
20
+ * Chainable object validators.
21
+ */
22
+ export declare class ObjectSchema<T extends object> extends ValueSchema<T> implements ValidatorWithPartial<T, unknown> {
23
+ private static _base;
24
+ /**
25
+ * The base Object validator validating that the input is an object.
26
+ */
27
+ static get base(): ObjectSchema<AnyRecord>;
28
+ /**
29
+ * Creates a validator that validates the input has properties that pass their respective
30
+ * validators.
31
+ *
32
+ * @param propertyValidators
33
+ */
34
+ extend<U extends object>(propertyValidators: ExtendedPropertyValidators<T, U>): ObjectSchema<U>;
35
+ /**
36
+ * Allows all properties to be undefined.
37
+ */
38
+ partial(): ObjectSchema<Partial<T>>;
39
+ /**
40
+ * Allows all recursive properties to be undefined.
41
+ */
42
+ partialDeep(): ObjectSchema<PartialDeep<T>>;
43
+ /**
44
+ * Casts the type parameter.
45
+ */
46
+ cast<T extends object>(): ObjectSchema<T>;
47
+ }
48
+ export type ExtendedPropertyValidators<T extends object, U extends object> = {
49
+ [K in keyof U as K extends keyof T ? Equal<U[K], T[K]> extends true ? never : K : K]-?: ExtendedPropertyValidator<U & T, K>;
50
+ } & {
51
+ [K in keyof U as K extends keyof T ? Equal<U[K], T[K]> extends true ? K : never : never]?: ExtendedPropertyValidator<U & T, K>;
52
+ };
53
+ export type ExtendedPropertyValidator<U extends object, P extends keyof U> = PropertyValidator<Required<U>[P], {
54
+ optional: IsPropertyOptional<U, P>;
55
+ }>;
56
+ //# sourceMappingURL=ObjectSchema.d.ts.map
@@ -0,0 +1,23 @@
1
+ import type { Validator } from '../validation/Validator';
2
+ import type { Merge } from '@amazon/vinyl-util';
3
+ export interface PropertyValidatorOptions {
4
+ /**
5
+ * If true, when the property is omitted, the object schema should not fail validation.
6
+ */
7
+ readonly optional: boolean;
8
+ }
9
+ /**
10
+ * A utility type for overriding the options type on a validator.
11
+ * This will strip the types of the overridden options and set to the new types.
12
+ */
13
+ export type PropertyValidatorWithOptions<ValidatorType extends PropertyValidator<any, any>, T, Options extends PropertyValidatorOptions> = Omit<ValidatorType, keyof PropertyValidator<any, any>> & PropertyValidator<T, Merge<ValidatorType['options'], Options>>;
14
+ export interface PropertyValidator<T, PropertyOptionsType extends PropertyValidatorOptions> extends Validator<T> {
15
+ readonly options: PropertyOptionsType;
16
+ optional(): PropertyValidatorWithOptions<this, T, {
17
+ readonly optional: true;
18
+ }>;
19
+ required(): PropertyValidatorWithOptions<this, T, {
20
+ readonly optional: false;
21
+ }>;
22
+ }
23
+ //# sourceMappingURL=PropertyValidator.d.ts.map
@@ -0,0 +1,58 @@
1
+ import type { ReadonlyRecord } from '@amazon/vinyl-util';
2
+ import { ValueSchema } from './ValueSchema';
3
+ import type { Validator } from './Validator';
4
+ export declare const recordValidators: {
5
+ /**
6
+ * Returns a validator that asserts that the object's own enumerable properties has keys and
7
+ * values that match their respective validators.
8
+ *
9
+ * Prototype members are not included.
10
+ * Numeric keys are validated as strings. For example the object `{ [0]: 1 }` will be passed
11
+ * to the key validator as '0'.
12
+ *
13
+ * @param keyValidator Validates each key.
14
+ * @param valueValidator Validates each value.
15
+ */
16
+ readonly record: <K extends string | symbol, V>(keyValidator: Validator<K>, valueValidator: Validator<V>) => Validator<Record<K, V>, object>;
17
+ };
18
+ /**
19
+ * Chainable object validators for the Record type.
20
+ */
21
+ export declare class RecordSchema<T extends ReadonlyRecord<keyof any, any>> extends ValueSchema<T> {
22
+ private static _base;
23
+ /**
24
+ * The base Object validator validating that the input is an object.
25
+ */
26
+ static get base(): RecordSchema<Record<keyof any, unknown>>;
27
+ private static get defaultKeyValidator();
28
+ /**
29
+ * Returns a validator that asserts that the object's own enumerable properties has keys and
30
+ * values that match their respective validators.
31
+ *
32
+ * Prototype members are not included.
33
+ * Numeric keys are validated as strings. For example the object `{ [0]: 1 }` will be passed
34
+ * to the key validator as '0'.
35
+ *
36
+ * @param keyValidator Validates each key.
37
+ * @param valueValidator Validates each value.
38
+ */
39
+ record<K extends string | symbol, V>(keyValidator: Validator<K>, valueValidator: Validator<V>): RecordSchema<ReadonlyRecord<K, V>>;
40
+ /**
41
+ * Returns a validator that asserts that the object's own enumerable properties has
42
+ * string keys and values that match the given validator.
43
+ *
44
+ * Prototype members are not included.
45
+ *
46
+ * @param valueValidator Validates each value.
47
+ */
48
+ recordValues<V>(valueValidator: Validator<V>): RecordSchema<Record<string, V>>;
49
+ /**
50
+ * Casts to a ReadonlyRecord
51
+ */
52
+ readonly(): RecordSchema<T extends Record<infer K, infer V> ? ReadonlyRecord<K, V> : never>;
53
+ /**
54
+ * Casts the type parameter.
55
+ */
56
+ cast<T extends ReadonlyRecord<keyof any, unknown>>(): RecordSchema<T>;
57
+ }
58
+ //# sourceMappingURL=RecordSchema.d.ts.map
@@ -0,0 +1,65 @@
1
+ import type { ValidationErrorMessage, ValidationOptions, Validator } from './Validator';
2
+ import type { PropertyValidator, PropertyValidatorWithOptions } from './PropertyValidator';
3
+ /**
4
+ * A base class for validation state.
5
+ * Provides methods for chaining.
6
+ *
7
+ * Subclasses should not override constructors.
8
+ */
9
+ export declare abstract class SchemaBase<T> implements PropertyValidator<T, {
10
+ readonly optional: false;
11
+ }> {
12
+ private readonly currentValidator;
13
+ private readonly previousSchema?;
14
+ private readonly operation?;
15
+ __type: import("@amazon/vinyl-util").Invariant<T>;
16
+ private readonly validator;
17
+ private _options;
18
+ get options(): {
19
+ readonly optional: false;
20
+ };
21
+ /**
22
+ * Constructs the first link in a schema chain.
23
+ *
24
+ * @param currentValidator
25
+ */
26
+ constructor(currentValidator: Validator<any, any>);
27
+ /**
28
+ * Constructs linking to the given previous schema.
29
+ *
30
+ * @param currentValidator
31
+ * @param previousSchema
32
+ * @param operation
33
+ */
34
+ constructor(currentValidator: Validator<any, any>, previousSchema: SchemaBase<any>, operation: (validatorA: Validator<any>, validatorB: Validator<any, any>) => Validator<T>);
35
+ get description(): string;
36
+ readonly assert: (input: unknown, origin?: string, path?: readonly string[]) => asserts input is T;
37
+ readonly isValid: (input: unknown) => input is T;
38
+ readonly validate: (input: unknown, options?: ValidationOptions, path?: readonly string[]) => readonly ValidationErrorMessage[];
39
+ /**
40
+ * Clones this schema, transforming all validators with the given mutator.
41
+ *
42
+ * @param transform A transformer which takes an existing validator in the chain and returns
43
+ * a new one. Validators should be considered to be immutable; transform should not change the
44
+ * input but instead return a new validator.
45
+ */
46
+ protected clone(transform?: (validator: Validator<any>) => Validator<any>): any;
47
+ protected self(current: Validator<any, any>): any;
48
+ protected self(currentValidator: Validator<any, any>, previousSchema: SchemaBase<any> | undefined, operation: ((validatorA: Validator<any>, validatorB: Validator<any, any>) => Validator<T>) | undefined): any;
49
+ /**
50
+ * Constructs a new schema with a validator chaining the current validator with the
51
+ * provided next in an AND operation.
52
+ *
53
+ * @param nextValidator The validator to run after the current.
54
+ * @return Returns a new Schema instance the same class with a new validator chaining the
55
+ * current validator with the given next in an AND operation.
56
+ */
57
+ protected chain(nextValidator: Validator<any, any>): any;
58
+ optional(): PropertyValidatorWithOptions<this, T, {
59
+ readonly optional: true;
60
+ }>;
61
+ required(): PropertyValidatorWithOptions<this, T, {
62
+ readonly optional: false;
63
+ }>;
64
+ }
65
+ //# sourceMappingURL=SchemaBase.d.ts.map
@@ -0,0 +1,38 @@
1
+ import type { SetElementType } from '@amazon/vinyl-util';
2
+ import type { Validator } from './Validator';
3
+ import { ValueSchema } from './ValueSchema';
4
+ export declare const setValidators: {
5
+ /**
6
+ * Creates a validator that asserts that the input is a set.
7
+ */
8
+ readonly isSet: () => Validator<Set<unknown>>;
9
+ /**
10
+ * Creates a validator that asserts that every element passes the given validator.
11
+ *
12
+ * @param elementValidator
13
+ */
14
+ readonly withElements: <U>(elementValidator: Validator<U>) => Validator<Set<U>, ReadonlySet<unknown>>;
15
+ };
16
+ export declare class SetSchema<T extends ReadonlySet<unknown>> extends ValueSchema<T> {
17
+ private static _base;
18
+ /**
19
+ * The base SetSchema instance validating that the input is a Set.
20
+ */
21
+ static get base(): SetSchema<Set<unknown>>;
22
+ /**
23
+ * Creates a validator that asserts that every element passes the given validator.
24
+ *
25
+ * @param elementValidator
26
+ */
27
+ withElements<U>(elementValidator: Validator<U>): SetSchema<Set<SetElementType<T> & U>>;
28
+ /**
29
+ * Casts to a readonly set.
30
+ * This is a shallow cast, elements of the array will not be changed.
31
+ */
32
+ readonly(): SetSchema<ReadonlySet<SetElementType<T>>>;
33
+ /**
34
+ * Casts the parameter type.
35
+ */
36
+ cast<T extends ReadonlySet<unknown>>(): SetSchema<T>;
37
+ }
38
+ //# sourceMappingURL=SetSchema.d.ts.map
@@ -0,0 +1,68 @@
1
+ import { ValueSchema } from './ValueSchema';
2
+ import type { Validator } from './Validator';
3
+ export declare const stringValidators: {
4
+ /**
5
+ * Creates a validator that asserts that the input is not empty.
6
+ */
7
+ readonly notEmpty: () => Validator<string, string>;
8
+ /**
9
+ * Creates a validator that asserts that the input string has at least the given minimum
10
+ * length.
11
+ *
12
+ * @param min The string must be at least this length.
13
+ */
14
+ readonly minLength: (min: number) => Validator<string, string>;
15
+ /**
16
+ * Creates a validator that asserts that the input string has at most the given maximum
17
+ * length.
18
+ *
19
+ * @param max The string must be at most this length.
20
+ */
21
+ readonly maxLength: (max: number) => Validator<string, string>;
22
+ /**
23
+ * Creates a validator that asserts that the input string has no whitespace characters.
24
+ * Whitespace characters include space, new line, carriage return, and tab.
25
+ */
26
+ readonly noWhitespace: () => Validator<string, string>;
27
+ /**
28
+ * Creates a validator that asserts that the input string matches the given regex.
29
+ * @param regex
30
+ */
31
+ readonly matches: (regex: RegExp) => Validator<string, string>;
32
+ };
33
+ export declare class StringSchema extends ValueSchema<string> {
34
+ private static _base;
35
+ /**
36
+ * The base SetSchema instance validating that the input is a Set.
37
+ */
38
+ static get base(): StringSchema;
39
+ /**
40
+ * Creates a validator that asserts that the input is not empty.
41
+ */
42
+ notEmpty(): StringSchema;
43
+ /**
44
+ * Creates a validator that asserts that the input string has at least the given minimum
45
+ * length.
46
+ *
47
+ * @param min The string must be at least this length.
48
+ */
49
+ minLength(min: number): StringSchema;
50
+ /**
51
+ * Creates a validator that asserts that the input string has at most the given maximum
52
+ * length.
53
+ *
54
+ * @param max The string must be at most this length.
55
+ */
56
+ maxLength(max: number): StringSchema;
57
+ /**
58
+ * Creates a validator that asserts that the input string has no whitespace characters.
59
+ * Whitespace characters include space, new line, carriage return, and tab.
60
+ */
61
+ noWhitespace(): StringSchema;
62
+ /**
63
+ * Creates a validator that asserts that the input string matches the given regex.
64
+ * @param regex
65
+ */
66
+ matches(regex: RegExp): StringSchema;
67
+ }
68
+ //# sourceMappingURL=StringSchema.d.ts.map