umt 2.17.0 → 2.19.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 +341 -347
- package/module/Validate/array/arrayOf.d.ts +9 -0
- package/module/Validate/array/arrayOf.js +35 -0
- package/module/Validate/array/arrayOf.js.map +1 -0
- package/module/Validate/array/index.d.ts +1 -0
- package/module/Validate/array/index.js +1 -0
- package/module/Validate/array/index.js.map +1 -1
- package/module/Validate/object/index.d.ts +1 -0
- package/module/Validate/object/index.js +1 -0
- package/module/Validate/object/index.js.map +1 -1
- package/module/Validate/object/intersection.d.ts +4 -2
- package/module/Validate/object/intersection.js.map +1 -1
- package/module/Validate/object/nullable.d.ts +8 -0
- package/module/Validate/object/nullable.js +21 -0
- package/module/Validate/object/nullable.js.map +1 -0
- package/module/Validate/object/union.d.ts +4 -2
- package/module/Validate/object/union.js.map +1 -1
- package/module/Validate/string/index.d.ts +1 -0
- package/module/Validate/string/index.js +1 -0
- package/module/Validate/string/index.js.map +1 -1
- package/module/Validate/string/oneOf.d.ts +32 -0
- package/module/Validate/string/oneOf.js +32 -0
- package/module/Validate/string/oneOf.js.map +1 -0
- package/module/Validate/type.d.ts +1 -1
- package/module/es5/Validate/array/arrayOf.d.ts +9 -0
- package/module/es5/Validate/array/arrayOf.js +52 -0
- package/module/es5/Validate/array/index.d.ts +1 -0
- package/module/es5/Validate/array/index.js +11 -0
- package/module/es5/Validate/object/index.d.ts +1 -0
- package/module/es5/Validate/object/index.js +11 -0
- package/module/es5/Validate/object/intersection.d.ts +4 -2
- package/module/es5/Validate/object/intersection.js +6 -0
- package/module/es5/Validate/object/nullable.d.ts +8 -0
- package/module/es5/Validate/object/nullable.js +26 -0
- package/module/es5/Validate/object/union.d.ts +4 -2
- package/module/es5/Validate/object/union.js +6 -0
- package/module/es5/Validate/string/index.d.ts +1 -0
- package/module/es5/Validate/string/index.js +11 -0
- package/module/es5/Validate/string/oneOf.d.ts +32 -0
- package/module/es5/Validate/string/oneOf.js +45 -0
- package/module/es5/Validate/type.d.ts +1 -1
- package/package.json +14 -11
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidateCoreReturnType } from "../../Validate/type";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an array validator that validates every element with a single validator
|
|
4
|
+
* @template T - Element type validated by the wrapped validator
|
|
5
|
+
* @param {Function} validator - Validator applied to each element (e.g. an object validator)
|
|
6
|
+
* @param {string} [message] - Custom error message for array type validation
|
|
7
|
+
* @returns {Function} - Validator function for arrays whose elements satisfy the given validator
|
|
8
|
+
*/
|
|
9
|
+
export declare const arrayOf: <T>(validator: (value: T) => ValidateCoreReturnType<T>, message?: string) => (values: T[]) => ValidateCoreReturnType<T[]>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isArray } from "../../Validate/isArray";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an array validator that validates every element with a single validator
|
|
4
|
+
* @template T - Element type validated by the wrapped validator
|
|
5
|
+
* @param {Function} validator - Validator applied to each element (e.g. an object validator)
|
|
6
|
+
* @param {string} [message] - Custom error message for array type validation
|
|
7
|
+
* @returns {Function} - Validator function for arrays whose elements satisfy the given validator
|
|
8
|
+
*/
|
|
9
|
+
export const arrayOf = (validator, message) => {
|
|
10
|
+
return (values) => {
|
|
11
|
+
if (!isArray(values)) {
|
|
12
|
+
return {
|
|
13
|
+
validate: false,
|
|
14
|
+
message: message ?? "",
|
|
15
|
+
type: values,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
for (const value of values) {
|
|
19
|
+
const result = validator(value);
|
|
20
|
+
if (!result.validate) {
|
|
21
|
+
return {
|
|
22
|
+
validate: false,
|
|
23
|
+
message: result.message,
|
|
24
|
+
type: values,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
validate: true,
|
|
30
|
+
message: "",
|
|
31
|
+
type: values,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=arrayOf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrayOf.js","sourceRoot":"","sources":["../../../src/Validate/array/arrayOf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,SAAkD,EAClD,OAAgB,EAChB,EAAE;IACF,OAAO,CAAC,MAAW,EAA+B,EAAE;QAClD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACrB,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,OAAO,IAAI,EAAE;gBACtB,IAAI,EAAE,MAAM;aACb,CAAC;QACJ,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACrB,OAAO;oBACL,QAAQ,EAAE,KAAK;oBACf,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,IAAI,EAAE,MAAM;iBACb,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,MAAM;SACb,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/array/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/array/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/object/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/object/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { UnionToIntersection } from "../../types/logic";
|
|
2
|
-
import type { ValidateCoreReturnType } from "../../Validate/type";
|
|
3
|
-
type ExtractValidatedType<V> = V extends (value: never) =>
|
|
2
|
+
import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
3
|
+
type ExtractValidatedType<V> = V extends (value: never) => {
|
|
4
|
+
type: infer T;
|
|
5
|
+
} ? ValidateType<T> : never;
|
|
4
6
|
/**
|
|
5
7
|
* Creates an intersection validator that passes only if all given validators pass
|
|
6
8
|
* @param validators - Validator functions to compose as an intersection (logical AND)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../../src/Validate/object/intersection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../../src/Validate/object/intersection.ts"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAG1B,GAAG,UAAmB,EACtB,EAAE;IACF,OAAO,CACL,KAA4D,EAG5D,EAAE;QACF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,MAAM,GACV,SAKD,CAAC,KAAK,CAAC,CAAC;YACT,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACrB,OAAO;oBACL,QAAQ,EAAE,KAAK;oBACf,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,IAAI,EAAE,KAEL;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,KAEL;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ValidateCoreReturnType } from "../../Validate/type";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a validator to accept null values
|
|
4
|
+
* @template T - The type of value the wrapped validator expects
|
|
5
|
+
* @param {Function} validator - Validator function to make nullable
|
|
6
|
+
* @returns {Function} - Validator that passes for null or delegates to the wrapped validator
|
|
7
|
+
*/
|
|
8
|
+
export declare const nullable: <T>(validator: (value: T) => ValidateCoreReturnType<T>) => ((value: T | null) => ValidateCoreReturnType<T | null>);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a validator to accept null values
|
|
3
|
+
* @template T - The type of value the wrapped validator expects
|
|
4
|
+
* @param {Function} validator - Validator function to make nullable
|
|
5
|
+
* @returns {Function} - Validator that passes for null or delegates to the wrapped validator
|
|
6
|
+
*/
|
|
7
|
+
export const nullable = (validator) => {
|
|
8
|
+
const nullableValidator = (value) => {
|
|
9
|
+
if (value === null) {
|
|
10
|
+
return {
|
|
11
|
+
validate: true,
|
|
12
|
+
message: "",
|
|
13
|
+
type: "null",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const result = validator(value);
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
return nullableValidator;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=nullable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nullable.js","sourceRoot":"","sources":["../../../src/Validate/object/nullable.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,SAAkD,EACO,EAAE;IAC3D,MAAM,iBAAiB,GAAG,CACxB,KAAe,EACmB,EAAE;QACpC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,EAAE;gBACX,IAAI,EAAE,MAAM;aACb,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { ValidateCoreReturnType } from "../../Validate/type";
|
|
2
|
-
type ExtractValidatedType<V> = V extends (value: never) =>
|
|
1
|
+
import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
2
|
+
type ExtractValidatedType<V> = V extends (value: never) => {
|
|
3
|
+
type: infer T;
|
|
4
|
+
} ? ValidateType<T> : never;
|
|
3
5
|
/**
|
|
4
6
|
* Creates a union validator that passes if any of the given validators pass
|
|
5
7
|
* @param validators - Validator functions to compose as a union (logical OR)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union.js","sourceRoot":"","sources":["../../../src/Validate/object/union.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"union.js","sourceRoot":"","sources":["../../../src/Validate/object/union.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAGnB,GAAG,UAAmB,EACtB,EAAE;IACF,OAAO,CACL,KAAuC,EACmB,EAAE;QAC5D,IAAI,WAAW,GAAG,EAAE,CAAC;QACrB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,MAAM,GACV,SAGD,CAAC,KAAK,CAAC,CAAC;YACT,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACpB,OAAO;oBACL,QAAQ,EAAE,IAAI;oBACd,OAAO,EAAE,EAAE;oBACX,IAAI,EAAE,KAA2D;iBAClE,CAAC;YACJ,CAAC;YACD,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,WAAW;YACpB,IAAI,EAAE,KAA2D;SAClE,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String validation module for literal union (allowed values) check
|
|
3
|
+
* Provides validation functionality for checking if a string is one of the
|
|
4
|
+
* allowed literal values, useful for validating string literal union types
|
|
5
|
+
* such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
|
|
6
|
+
*
|
|
7
|
+
* The validator's return type carries the literal union through its `type`
|
|
8
|
+
* field directly (instead of going through `Types<T>` which would collapse
|
|
9
|
+
* to `"string"`), so consumers like `object()`, `union()`, and `intersection()`
|
|
10
|
+
* can preserve the literal union in their inferred types.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Return type produced by a `oneOf` validator. Structurally compatible with
|
|
14
|
+
* `ValidateCoreReturnType<unknown>`, but exposes the literal union directly
|
|
15
|
+
* via the `type` field so the inferred type can flow through `object()`,
|
|
16
|
+
* `union()`, and `intersection()` without being collapsed to `string`.
|
|
17
|
+
*/
|
|
18
|
+
export interface OneOfReturnType<T extends string> {
|
|
19
|
+
validate: boolean;
|
|
20
|
+
message: string;
|
|
21
|
+
type: T;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a top-level validator that checks if a string value is one of the
|
|
25
|
+
* given allowed literal values. The literal union is captured via `const T`
|
|
26
|
+
* and exposed through the `OneOfReturnType<T[number]>` return type.
|
|
27
|
+
* @template T - The tuple of allowed string literals
|
|
28
|
+
* @param {T} values - The tuple of allowed string values
|
|
29
|
+
* @param {string} [message] - Custom error message for validation failure
|
|
30
|
+
* @returns A validator function from `string` to `OneOfReturnType<T[number]>`
|
|
31
|
+
*/
|
|
32
|
+
export declare const oneOf: <const T extends readonly string[]>(values: T, message?: string) => (value: string) => OneOfReturnType<T[number]>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String validation module for literal union (allowed values) check
|
|
3
|
+
* Provides validation functionality for checking if a string is one of the
|
|
4
|
+
* allowed literal values, useful for validating string literal union types
|
|
5
|
+
* such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
|
|
6
|
+
*
|
|
7
|
+
* The validator's return type carries the literal union through its `type`
|
|
8
|
+
* field directly (instead of going through `Types<T>` which would collapse
|
|
9
|
+
* to `"string"`), so consumers like `object()`, `union()`, and `intersection()`
|
|
10
|
+
* can preserve the literal union in their inferred types.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Creates a top-level validator that checks if a string value is one of the
|
|
14
|
+
* given allowed literal values. The literal union is captured via `const T`
|
|
15
|
+
* and exposed through the `OneOfReturnType<T[number]>` return type.
|
|
16
|
+
* @template T - The tuple of allowed string literals
|
|
17
|
+
* @param {T} values - The tuple of allowed string values
|
|
18
|
+
* @param {string} [message] - Custom error message for validation failure
|
|
19
|
+
* @returns A validator function from `string` to `OneOfReturnType<T[number]>`
|
|
20
|
+
*/
|
|
21
|
+
export const oneOf = (values, message) => {
|
|
22
|
+
const allowed = new Set(values);
|
|
23
|
+
return (value) => {
|
|
24
|
+
const isValid = allowed.has(value);
|
|
25
|
+
return {
|
|
26
|
+
validate: isValid,
|
|
27
|
+
message: isValid ? "" : (message ?? ""),
|
|
28
|
+
type: value,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=oneOf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oneOf.js","sourceRoot":"","sources":["../../../src/Validate/string/oneOf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAcH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,MAAS,EACT,OAAgB,EAChB,EAAE;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,CAAC;IACxC,OAAO,CAAC,KAAa,EAA8B,EAAE;QACnD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO;YACL,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC;YACvC,IAAI,EAAE,KAAK;SACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -37,7 +37,7 @@ export type _ValidateType2<T> = T extends "undefined" ? undefined : T extends "n
|
|
|
37
37
|
* @returns The corresponding TypeScript type (string, number, boolean) or the original type T
|
|
38
38
|
*/
|
|
39
39
|
export type ValidateType<T> = T extends "string" | "number" | "boolean" ? _ValidateType<T> : T extends "undefined" | "null" ? _ValidateType2<T> : T;
|
|
40
|
-
export type SchemaToInterface<T extends (value: any) => ValidateCoreReturnType<any>> = ReturnType<T>["type"]
|
|
40
|
+
export type SchemaToInterface<T extends (value: any) => ValidateCoreReturnType<any>> = ValidateType<ReturnType<T>["type"]>;
|
|
41
41
|
export type OptionalKeys<T> = {
|
|
42
42
|
[K in keyof T]: undefined extends T[K] ? K : never;
|
|
43
43
|
}[keyof T];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidateCoreReturnType } from "../../Validate/type";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an array validator that validates every element with a single validator
|
|
4
|
+
* @template T - Element type validated by the wrapped validator
|
|
5
|
+
* @param {Function} validator - Validator applied to each element (e.g. an object validator)
|
|
6
|
+
* @param {string} [message] - Custom error message for array type validation
|
|
7
|
+
* @returns {Function} - Validator function for arrays whose elements satisfy the given validator
|
|
8
|
+
*/
|
|
9
|
+
export declare const arrayOf: <T>(validator: (value: T) => ValidateCoreReturnType<T>, message?: string) => (values: T[]) => ValidateCoreReturnType<T[]>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.arrayOf = void 0;
|
|
7
|
+
var _isArray = require("../../Validate/isArray");
|
|
8
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
9
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
11
|
+
/**
|
|
12
|
+
* Creates an array validator that validates every element with a single validator
|
|
13
|
+
* @template T - Element type validated by the wrapped validator
|
|
14
|
+
* @param {Function} validator - Validator applied to each element (e.g. an object validator)
|
|
15
|
+
* @param {string} [message] - Custom error message for array type validation
|
|
16
|
+
* @returns {Function} - Validator function for arrays whose elements satisfy the given validator
|
|
17
|
+
*/
|
|
18
|
+
var arrayOf = exports.arrayOf = function arrayOf(validator, message) {
|
|
19
|
+
return function (values) {
|
|
20
|
+
if (!(0, _isArray.isArray)(values)) {
|
|
21
|
+
return {
|
|
22
|
+
validate: false,
|
|
23
|
+
message: message !== null && message !== void 0 ? message : "",
|
|
24
|
+
type: values
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var _iterator = _createForOfIteratorHelper(values),
|
|
28
|
+
_step;
|
|
29
|
+
try {
|
|
30
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
31
|
+
var value = _step.value;
|
|
32
|
+
var result = validator(value);
|
|
33
|
+
if (!result.validate) {
|
|
34
|
+
return {
|
|
35
|
+
validate: false,
|
|
36
|
+
message: result.message,
|
|
37
|
+
type: values
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} catch (err) {
|
|
42
|
+
_iterator.e(err);
|
|
43
|
+
} finally {
|
|
44
|
+
_iterator.f();
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
validate: true,
|
|
48
|
+
message: "",
|
|
49
|
+
type: values
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _arrayOf = require("./arrayOf");
|
|
7
|
+
Object.keys(_arrayOf).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _arrayOf[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _arrayOf[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
6
17
|
var _core = require("./core");
|
|
7
18
|
Object.keys(_core).forEach(function (key) {
|
|
8
19
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -25,6 +25,17 @@ Object.keys(_intersection).forEach(function (key) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
+
var _nullable = require("./nullable");
|
|
29
|
+
Object.keys(_nullable).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _nullable[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _nullable[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
28
39
|
var _optional = require("./optional");
|
|
29
40
|
Object.keys(_optional).forEach(function (key) {
|
|
30
41
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { UnionToIntersection } from "../../types/logic";
|
|
2
|
-
import type { ValidateCoreReturnType } from "../../Validate/type";
|
|
3
|
-
type ExtractValidatedType<V> = V extends (value: never) =>
|
|
2
|
+
import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
3
|
+
type ExtractValidatedType<V> = V extends (value: never) => {
|
|
4
|
+
type: infer T;
|
|
5
|
+
} ? ValidateType<T> : never;
|
|
4
6
|
/**
|
|
5
7
|
* Creates an intersection validator that passes only if all given validators pass
|
|
6
8
|
* @param validators - Validator functions to compose as an intersection (logical AND)
|
|
@@ -4,6 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.intersection = void 0;
|
|
7
|
+
// Extract the validated value type by reading the validator's `type` field
|
|
8
|
+
// (and applying `ValidateType` to map type tags like "string" back to the
|
|
9
|
+
// runtime type). Reading the field directly lets validators that expose the
|
|
10
|
+
// literal union via the `type` field (such as `oneOf`) flow through
|
|
11
|
+
// intersection without being collapsed by `Types<T>`.
|
|
12
|
+
|
|
7
13
|
/**
|
|
8
14
|
* Creates an intersection validator that passes only if all given validators pass
|
|
9
15
|
* @param validators - Validator functions to compose as an intersection (logical AND)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ValidateCoreReturnType } from "../../Validate/type";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a validator to accept null values
|
|
4
|
+
* @template T - The type of value the wrapped validator expects
|
|
5
|
+
* @param {Function} validator - Validator function to make nullable
|
|
6
|
+
* @returns {Function} - Validator that passes for null or delegates to the wrapped validator
|
|
7
|
+
*/
|
|
8
|
+
export declare const nullable: <T>(validator: (value: T) => ValidateCoreReturnType<T>) => ((value: T | null) => ValidateCoreReturnType<T | null>);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.nullable = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a validator to accept null values
|
|
9
|
+
* @template T - The type of value the wrapped validator expects
|
|
10
|
+
* @param {Function} validator - Validator function to make nullable
|
|
11
|
+
* @returns {Function} - Validator that passes for null or delegates to the wrapped validator
|
|
12
|
+
*/
|
|
13
|
+
var nullable = exports.nullable = function nullable(validator) {
|
|
14
|
+
var nullableValidator = function nullableValidator(value) {
|
|
15
|
+
if (value === null) {
|
|
16
|
+
return {
|
|
17
|
+
validate: true,
|
|
18
|
+
message: "",
|
|
19
|
+
type: "null"
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
var result = validator(value);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
return nullableValidator;
|
|
26
|
+
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { ValidateCoreReturnType } from "../../Validate/type";
|
|
2
|
-
type ExtractValidatedType<V> = V extends (value: never) =>
|
|
1
|
+
import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
2
|
+
type ExtractValidatedType<V> = V extends (value: never) => {
|
|
3
|
+
type: infer T;
|
|
4
|
+
} ? ValidateType<T> : never;
|
|
3
5
|
/**
|
|
4
6
|
* Creates a union validator that passes if any of the given validators pass
|
|
5
7
|
* @param validators - Validator functions to compose as a union (logical OR)
|
|
@@ -4,6 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.union = void 0;
|
|
7
|
+
// Extract the validated value type by reading the validator's `type` field
|
|
8
|
+
// (and applying `ValidateType` to map type tags like "string" back to the
|
|
9
|
+
// runtime type). Reading the field directly lets validators that expose the
|
|
10
|
+
// literal union via the `type` field (such as `oneOf`) flow through union
|
|
11
|
+
// without being collapsed by `Types<T>`.
|
|
12
|
+
|
|
7
13
|
/**
|
|
8
14
|
* Creates a union validator that passes if any of the given validators pass
|
|
9
15
|
* @param validators - Validator functions to compose as a union (logical OR)
|
|
@@ -69,6 +69,17 @@ Object.keys(_numberString).forEach(function (key) {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
|
+
var _oneOf = require("./oneOf");
|
|
73
|
+
Object.keys(_oneOf).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _oneOf[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function get() {
|
|
79
|
+
return _oneOf[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
72
83
|
var _regexMatch = require("./regexMatch");
|
|
73
84
|
Object.keys(_regexMatch).forEach(function (key) {
|
|
74
85
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String validation module for literal union (allowed values) check
|
|
3
|
+
* Provides validation functionality for checking if a string is one of the
|
|
4
|
+
* allowed literal values, useful for validating string literal union types
|
|
5
|
+
* such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
|
|
6
|
+
*
|
|
7
|
+
* The validator's return type carries the literal union through its `type`
|
|
8
|
+
* field directly (instead of going through `Types<T>` which would collapse
|
|
9
|
+
* to `"string"`), so consumers like `object()`, `union()`, and `intersection()`
|
|
10
|
+
* can preserve the literal union in their inferred types.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Return type produced by a `oneOf` validator. Structurally compatible with
|
|
14
|
+
* `ValidateCoreReturnType<unknown>`, but exposes the literal union directly
|
|
15
|
+
* via the `type` field so the inferred type can flow through `object()`,
|
|
16
|
+
* `union()`, and `intersection()` without being collapsed to `string`.
|
|
17
|
+
*/
|
|
18
|
+
export interface OneOfReturnType<T extends string> {
|
|
19
|
+
validate: boolean;
|
|
20
|
+
message: string;
|
|
21
|
+
type: T;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a top-level validator that checks if a string value is one of the
|
|
25
|
+
* given allowed literal values. The literal union is captured via `const T`
|
|
26
|
+
* and exposed through the `OneOfReturnType<T[number]>` return type.
|
|
27
|
+
* @template T - The tuple of allowed string literals
|
|
28
|
+
* @param {T} values - The tuple of allowed string values
|
|
29
|
+
* @param {string} [message] - Custom error message for validation failure
|
|
30
|
+
* @returns A validator function from `string` to `OneOfReturnType<T[number]>`
|
|
31
|
+
*/
|
|
32
|
+
export declare const oneOf: <const T extends readonly string[]>(values: T, message?: string) => (value: string) => OneOfReturnType<T[number]>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.oneOf = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* String validation module for literal union (allowed values) check
|
|
9
|
+
* Provides validation functionality for checking if a string is one of the
|
|
10
|
+
* allowed literal values, useful for validating string literal union types
|
|
11
|
+
* such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
|
|
12
|
+
*
|
|
13
|
+
* The validator's return type carries the literal union through its `type`
|
|
14
|
+
* field directly (instead of going through `Types<T>` which would collapse
|
|
15
|
+
* to `"string"`), so consumers like `object()`, `union()`, and `intersection()`
|
|
16
|
+
* can preserve the literal union in their inferred types.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Return type produced by a `oneOf` validator. Structurally compatible with
|
|
21
|
+
* `ValidateCoreReturnType<unknown>`, but exposes the literal union directly
|
|
22
|
+
* via the `type` field so the inferred type can flow through `object()`,
|
|
23
|
+
* `union()`, and `intersection()` without being collapsed to `string`.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a top-level validator that checks if a string value is one of the
|
|
28
|
+
* given allowed literal values. The literal union is captured via `const T`
|
|
29
|
+
* and exposed through the `OneOfReturnType<T[number]>` return type.
|
|
30
|
+
* @template T - The tuple of allowed string literals
|
|
31
|
+
* @param {T} values - The tuple of allowed string values
|
|
32
|
+
* @param {string} [message] - Custom error message for validation failure
|
|
33
|
+
* @returns A validator function from `string` to `OneOfReturnType<T[number]>`
|
|
34
|
+
*/
|
|
35
|
+
var oneOf = exports.oneOf = function oneOf(values, message) {
|
|
36
|
+
var allowed = new Set(values);
|
|
37
|
+
return function (value) {
|
|
38
|
+
var isValid = allowed.has(value);
|
|
39
|
+
return {
|
|
40
|
+
validate: isValid,
|
|
41
|
+
message: isValid ? "" : message !== null && message !== void 0 ? message : "",
|
|
42
|
+
type: value
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -37,7 +37,7 @@ export type _ValidateType2<T> = T extends "undefined" ? undefined : T extends "n
|
|
|
37
37
|
* @returns The corresponding TypeScript type (string, number, boolean) or the original type T
|
|
38
38
|
*/
|
|
39
39
|
export type ValidateType<T> = T extends "string" | "number" | "boolean" ? _ValidateType<T> : T extends "undefined" | "null" ? _ValidateType2<T> : T;
|
|
40
|
-
export type SchemaToInterface<T extends (value: any) => ValidateCoreReturnType<any>> = ReturnType<T>["type"]
|
|
40
|
+
export type SchemaToInterface<T extends (value: any) => ValidateCoreReturnType<any>> = ValidateType<ReturnType<T>["type"]>;
|
|
41
41
|
export type OptionalKeys<T> = {
|
|
42
42
|
[K in keyof T]: undefined extends T[K] ? K : never;
|
|
43
43
|
}[keyof T];
|