umt 2.19.0 → 2.20.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/module/Validate/any/core.d.ts +21 -0
- package/module/Validate/any/core.js +19 -0
- package/module/Validate/any/core.js.map +1 -0
- package/module/Validate/any/index.d.ts +1 -0
- package/module/Validate/any/index.js +2 -0
- package/module/Validate/any/index.js.map +1 -0
- package/module/Validate/array/arrayOf.d.ts +6 -1
- package/module/Validate/array/arrayOf.js +1 -0
- package/module/Validate/array/arrayOf.js.map +1 -1
- package/module/Validate/bigint/core.d.ts +24 -0
- package/module/Validate/bigint/core.js +37 -0
- package/module/Validate/bigint/core.js.map +1 -0
- package/module/Validate/bigint/index.d.ts +1 -0
- package/module/Validate/bigint/index.js +2 -0
- package/module/Validate/bigint/index.js.map +1 -0
- package/module/Validate/date/core.d.ts +14 -0
- package/module/Validate/date/core.js +29 -0
- package/module/Validate/date/core.js.map +1 -0
- package/module/Validate/date/index.d.ts +1 -0
- package/module/Validate/date/index.js +2 -0
- package/module/Validate/date/index.js.map +1 -0
- package/module/Validate/file/core.d.ts +13 -0
- package/module/Validate/file/core.js +32 -0
- package/module/Validate/file/core.js.map +1 -0
- package/module/Validate/file/index.d.ts +1 -0
- package/module/Validate/file/index.js +2 -0
- package/module/Validate/file/index.js.map +1 -0
- package/module/Validate/function/core.d.ts +75 -0
- package/module/Validate/function/core.js +66 -0
- package/module/Validate/function/core.js.map +1 -0
- package/module/Validate/function/index.d.ts +1 -0
- package/module/Validate/function/index.js +2 -0
- package/module/Validate/function/index.js.map +1 -0
- package/module/Validate/index.d.ts +11 -0
- package/module/Validate/index.js +11 -0
- package/module/Validate/index.js.map +1 -1
- package/module/Validate/instanceof/core.d.ts +19 -0
- package/module/Validate/instanceof/core.js +32 -0
- package/module/Validate/instanceof/core.js.map +1 -0
- package/module/Validate/instanceof/index.d.ts +1 -0
- package/module/Validate/instanceof/index.js +2 -0
- package/module/Validate/instanceof/index.js.map +1 -0
- package/module/Validate/map/core.d.ts +24 -0
- package/module/Validate/map/core.js +57 -0
- package/module/Validate/map/core.js.map +1 -0
- package/module/Validate/map/index.d.ts +1 -0
- package/module/Validate/map/index.js +2 -0
- package/module/Validate/map/index.js.map +1 -0
- package/module/Validate/never/core.d.ts +22 -0
- package/module/Validate/never/core.js +23 -0
- package/module/Validate/never/core.js.map +1 -0
- package/module/Validate/never/index.d.ts +1 -0
- package/module/Validate/never/index.js +2 -0
- package/module/Validate/never/index.js.map +1 -0
- package/module/Validate/object/core.d.ts +22 -4
- package/module/Validate/object/core.js +5 -3
- package/module/Validate/object/core.js.map +1 -1
- package/module/Validate/object/index.d.ts +4 -0
- package/module/Validate/object/index.js +4 -0
- package/module/Validate/object/index.js.map +1 -1
- package/module/Validate/object/nullable.d.ts +12 -2
- package/module/Validate/object/nullable.js +2 -2
- package/module/Validate/object/nullable.js.map +1 -1
- package/module/Validate/object/omit.d.ts +22 -0
- package/module/Validate/object/omit.js +33 -0
- package/module/Validate/object/omit.js.map +1 -0
- package/module/Validate/object/optional.d.ts +31 -3
- package/module/Validate/object/optional.js +7 -5
- package/module/Validate/object/optional.js.map +1 -1
- package/module/Validate/object/partial.d.ts +25 -0
- package/module/Validate/object/partial.js +29 -0
- package/module/Validate/object/partial.js.map +1 -0
- package/module/Validate/object/pick.d.ts +21 -0
- package/module/Validate/object/pick.js +29 -0
- package/module/Validate/object/pick.js.map +1 -0
- package/module/Validate/object/required.d.ts +22 -0
- package/module/Validate/object/required.js +30 -0
- package/module/Validate/object/required.js.map +1 -0
- package/module/Validate/set/core.d.ts +24 -0
- package/module/Validate/set/core.js +47 -0
- package/module/Validate/set/core.js.map +1 -0
- package/module/Validate/set/index.d.ts +1 -0
- package/module/Validate/set/index.js +2 -0
- package/module/Validate/set/index.js.map +1 -0
- package/module/Validate/templateLiteral/core.d.ts +55 -0
- package/module/Validate/templateLiteral/core.js +68 -0
- package/module/Validate/templateLiteral/core.js.map +1 -0
- package/module/Validate/templateLiteral/index.d.ts +1 -0
- package/module/Validate/templateLiteral/index.js +2 -0
- package/module/Validate/templateLiteral/index.js.map +1 -0
- package/module/Validate/type.d.ts +7 -5
- package/module/Validate/unknown/core.d.ts +21 -0
- package/module/Validate/unknown/core.js +16 -0
- package/module/Validate/unknown/core.js.map +1 -0
- package/module/Validate/unknown/index.d.ts +1 -0
- package/module/Validate/unknown/index.js +2 -0
- package/module/Validate/unknown/index.js.map +1 -0
- package/module/es5/Validate/any/core.d.ts +21 -0
- package/module/es5/Validate/any/core.js +36 -0
- package/module/es5/Validate/any/index.d.ts +1 -0
- package/module/es5/Validate/any/index.js +16 -0
- package/module/es5/Validate/array/arrayOf.d.ts +6 -1
- package/module/es5/Validate/array/arrayOf.js +1 -0
- package/module/es5/Validate/bigint/core.d.ts +24 -0
- package/module/es5/Validate/bigint/core.js +65 -0
- package/module/es5/Validate/bigint/index.d.ts +1 -0
- package/module/es5/Validate/bigint/index.js +16 -0
- package/module/es5/Validate/date/core.d.ts +14 -0
- package/module/es5/Validate/date/core.js +35 -0
- package/module/es5/Validate/date/index.d.ts +1 -0
- package/module/es5/Validate/date/index.js +16 -0
- package/module/es5/Validate/file/core.d.ts +13 -0
- package/module/es5/Validate/file/core.js +39 -0
- package/module/es5/Validate/file/index.d.ts +1 -0
- package/module/es5/Validate/file/index.js +16 -0
- package/module/es5/Validate/function/core.d.ts +75 -0
- package/module/es5/Validate/function/core.js +125 -0
- package/module/es5/Validate/function/index.d.ts +1 -0
- package/module/es5/Validate/function/index.js +16 -0
- package/module/es5/Validate/index.d.ts +11 -0
- package/module/es5/Validate/index.js +121 -0
- package/module/es5/Validate/instanceof/core.d.ts +19 -0
- package/module/es5/Validate/instanceof/core.js +40 -0
- package/module/es5/Validate/instanceof/index.d.ts +1 -0
- package/module/es5/Validate/instanceof/index.js +16 -0
- package/module/es5/Validate/map/core.d.ts +24 -0
- package/module/es5/Validate/map/core.js +81 -0
- package/module/es5/Validate/map/index.d.ts +1 -0
- package/module/es5/Validate/map/index.js +16 -0
- package/module/es5/Validate/never/core.d.ts +22 -0
- package/module/es5/Validate/never/core.js +35 -0
- package/module/es5/Validate/never/index.d.ts +1 -0
- package/module/es5/Validate/never/index.js +16 -0
- package/module/es5/Validate/object/core.d.ts +22 -4
- package/module/es5/Validate/object/core.js +14 -2
- package/module/es5/Validate/object/index.d.ts +4 -0
- package/module/es5/Validate/object/index.js +44 -0
- package/module/es5/Validate/object/nullable.d.ts +12 -2
- package/module/es5/Validate/object/nullable.js +2 -2
- package/module/es5/Validate/object/omit.d.ts +22 -0
- package/module/es5/Validate/object/omit.js +39 -0
- package/module/es5/Validate/object/optional.d.ts +31 -3
- package/module/es5/Validate/object/optional.js +12 -3
- package/module/es5/Validate/object/partial.d.ts +25 -0
- package/module/es5/Validate/object/partial.js +33 -0
- package/module/es5/Validate/object/pick.d.ts +21 -0
- package/module/es5/Validate/object/pick.js +45 -0
- package/module/es5/Validate/object/required.d.ts +22 -0
- package/module/es5/Validate/object/required.js +33 -0
- package/module/es5/Validate/set/core.d.ts +24 -0
- package/module/es5/Validate/set/core.js +65 -0
- package/module/es5/Validate/set/index.d.ts +1 -0
- package/module/es5/Validate/set/index.js +16 -0
- package/module/es5/Validate/templateLiteral/core.d.ts +55 -0
- package/module/es5/Validate/templateLiteral/core.js +114 -0
- package/module/es5/Validate/templateLiteral/index.d.ts +1 -0
- package/module/es5/Validate/templateLiteral/index.js +16 -0
- package/module/es5/Validate/type.d.ts +7 -5
- package/module/es5/Validate/unknown/core.d.ts +21 -0
- package/module/es5/Validate/unknown/core.js +34 -0
- package/module/es5/Validate/unknown/index.d.ts +1 -0
- package/module/es5/Validate/unknown/index.js +16 -0
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map validation core module
|
|
3
|
+
* Provides validation for `Map` instances. The validator can optionally
|
|
4
|
+
* delegate to per-entry validators for keys and values, mirroring how
|
|
5
|
+
* `arrayOf()` validates each element of an array.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Creates a Map validator. The validator can optionally accept per-entry key
|
|
9
|
+
* and value validators that are applied to every entry of the map. When the
|
|
10
|
+
* value-side validator is provided, the entry validators short-circuit on the
|
|
11
|
+
* first failure and surface the failing message, mirroring `arrayOf()`.
|
|
12
|
+
* @template KV - Validator for the map key
|
|
13
|
+
* @template VV - Validator for the map value
|
|
14
|
+
* @param {KV} [keyValidator] - Validator applied to every key
|
|
15
|
+
* @param {VV} [valueValidator] - Validator applied to every value
|
|
16
|
+
* @param {string} [message] - Custom error message for type validation
|
|
17
|
+
* @returns {Function} - Validator function for Map instances
|
|
18
|
+
*/
|
|
19
|
+
export const map = (keyValidator, valueValidator, message) => {
|
|
20
|
+
return (value) => {
|
|
21
|
+
if (!(value instanceof Map)) {
|
|
22
|
+
return {
|
|
23
|
+
validate: false,
|
|
24
|
+
message: message ?? "",
|
|
25
|
+
type: value,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
for (const [entryKey, entryValue] of value) {
|
|
29
|
+
if (keyValidator) {
|
|
30
|
+
const keyResult = keyValidator(entryKey);
|
|
31
|
+
if (!keyResult.validate) {
|
|
32
|
+
return {
|
|
33
|
+
validate: false,
|
|
34
|
+
message: keyResult.message,
|
|
35
|
+
type: value,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (valueValidator) {
|
|
40
|
+
const valueResult = valueValidator(entryValue);
|
|
41
|
+
if (!valueResult.validate) {
|
|
42
|
+
return {
|
|
43
|
+
validate: false,
|
|
44
|
+
message: valueResult.message,
|
|
45
|
+
type: value,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
validate: true,
|
|
52
|
+
message: "",
|
|
53
|
+
type: value,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/Validate/map/core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAYjB,YAAiB,EACjB,cAAmB,EACnB,OAAgB,EAChB,EAAE;IACF,OAAO,CAAC,KAAgB,EAAqC,EAAE;QAC7D,IAAI,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,OAAO,IAAI,EAAE;gBACtB,IAAI,EAAE,KAAK;aACZ,CAAC;QACJ,CAAC;QACD,KAAK,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,KAAK,EAAE,CAAC;YAC3C,IAAI,YAAY,EAAE,CAAC;gBACjB,MAAM,SAAS,GACb,YACD,CAAC,QAAQ,CAAC,CAAC;gBACZ,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;oBACxB,OAAO;wBACL,QAAQ,EAAE,KAAK;wBACf,OAAO,EAAE,SAAS,CAAC,OAAO;wBAC1B,IAAI,EAAE,KAAK;qBACZ,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,IAAI,cAAc,EAAE,CAAC;gBACnB,MAAM,WAAW,GACf,cAID,CAAC,UAAU,CAAC,CAAC;gBACd,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;oBAC1B,OAAO;wBACL,QAAQ,EAAE,KAAK;wBACf,OAAO,EAAE,WAAW,CAAC,OAAO;wBAC5B,IAAI,EAAE,KAAK;qBACZ,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,KAAK;SACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/map/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Never validation core module
|
|
3
|
+
* Provides a validator that fails for every input, useful for marking
|
|
4
|
+
* positions in a schema that must never be filled (for example, exhaustive
|
|
5
|
+
* union members that should be unreachable at the type level).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Return type produced by a `never` validator. Exposes the literal `"never"`
|
|
9
|
+
* tag through the `type` field so `ValidateType<"never">` can map it back to
|
|
10
|
+
* the `never` runtime type when consumed by downstream helpers.
|
|
11
|
+
*/
|
|
12
|
+
export interface NeverReturnType {
|
|
13
|
+
validate: boolean;
|
|
14
|
+
message: string;
|
|
15
|
+
type: "never";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a validator that always fails
|
|
19
|
+
* @param {string} [message] - Custom error message for validation failure
|
|
20
|
+
* @returns {Function} - Validator that always returns a failing result
|
|
21
|
+
*/
|
|
22
|
+
export declare const never: (message?: string) => ((value: any) => NeverReturnType);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Never validation core module
|
|
3
|
+
* Provides a validator that fails for every input, useful for marking
|
|
4
|
+
* positions in a schema that must never be filled (for example, exhaustive
|
|
5
|
+
* union members that should be unreachable at the type level).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Creates a validator that always fails
|
|
9
|
+
* @param {string} [message] - Custom error message for validation failure
|
|
10
|
+
* @returns {Function} - Validator that always returns a failing result
|
|
11
|
+
*/
|
|
12
|
+
// biome-ignore lint/suspicious/noExplicitAny: never() is widened to accept any input from union/intersection
|
|
13
|
+
export const never = (message) => {
|
|
14
|
+
// biome-ignore lint/suspicious/noExplicitAny: signature mirrors the public type
|
|
15
|
+
return (_value) => {
|
|
16
|
+
return {
|
|
17
|
+
validate: false,
|
|
18
|
+
message: message ?? "",
|
|
19
|
+
type: "never",
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/Validate/never/core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH;;;;GAIG;AACH,6GAA6G;AAC7G,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAAgB,EAAqC,EAAE;IAC3E,gFAAgF;IAChF,OAAO,CAAC,MAAW,EAAmB,EAAE;QACtC,OAAO;YACL,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,OAAO,IAAI,EAAE;YACtB,IAAI,EAAE,OAAO;SACd,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/never/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -4,13 +4,31 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { PickPartial } from "../../types/object";
|
|
6
6
|
import type { OptionalKeys, ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
7
|
+
/**
|
|
8
|
+
* Shape map describing per-property validators consumed by `object()`
|
|
9
|
+
*/
|
|
10
|
+
export interface ObjectShape {
|
|
11
|
+
[key: string]: (value: any) => ValidateCoreReturnType<unknown>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Object validator augmented with the original `shape` map. The shape map is
|
|
15
|
+
* exposed so derived helpers such as `pick()`, `omit()`, `partial()`, and
|
|
16
|
+
* `required()` can compose new object validators from existing ones.
|
|
17
|
+
*/
|
|
18
|
+
export type ObjectValidator<T extends ObjectShape, U = {
|
|
19
|
+
[key in keyof T]: ValidateType<ReturnType<T[key]>["type"]>;
|
|
20
|
+
}> = ((value: {
|
|
21
|
+
[key in keyof PickPartial<U, OptionalKeys<U>>]: PickPartial<U, OptionalKeys<U>>[key];
|
|
22
|
+
}) => ValidateCoreReturnType<{
|
|
23
|
+
[key in keyof PickPartial<U, OptionalKeys<U>>]: PickPartial<U, OptionalKeys<U>>[key];
|
|
24
|
+
}>) & {
|
|
25
|
+
shape: T;
|
|
26
|
+
};
|
|
7
27
|
/**
|
|
8
28
|
* Creates an object validator with property-specific validation rules
|
|
9
29
|
* @template T - Object type containing validation functions for each property
|
|
10
30
|
* @param {T} [option] - Object containing validation functions for each property
|
|
11
31
|
* @param {string} [message] - Custom error message for object type validation
|
|
12
|
-
* @returns {
|
|
32
|
+
* @returns {ObjectValidator<T>} - Validator function with `.shape` attached so it can compose with `pick()`, `omit()`, `partial()`, and `required()`
|
|
13
33
|
*/
|
|
14
|
-
export declare const object: <T extends
|
|
15
|
-
[key: string]: (value: any) => ValidateCoreReturnType<any>;
|
|
16
|
-
}, U = { [key in keyof T]: ValidateType<ReturnType<T[key]>["type"]>; }>(option?: T, message?: string) => (value: { [key in keyof PickPartial<U, OptionalKeys<U>>]: PickPartial<U, OptionalKeys<U>>[key]; }) => ValidateCoreReturnType<{ [key in keyof PickPartial<U, OptionalKeys<U>>]: PickPartial<U, OptionalKeys<U>>[key]; }>;
|
|
34
|
+
export declare const object: <T extends ObjectShape>(option?: T, message?: string) => ObjectValidator<T>;
|
|
@@ -8,10 +8,10 @@ import { isDictionaryObject } from "../../Validate/isDictionaryObject";
|
|
|
8
8
|
* @template T - Object type containing validation functions for each property
|
|
9
9
|
* @param {T} [option] - Object containing validation functions for each property
|
|
10
10
|
* @param {string} [message] - Custom error message for object type validation
|
|
11
|
-
* @returns {
|
|
11
|
+
* @returns {ObjectValidator<T>} - Validator function with `.shape` attached so it can compose with `pick()`, `omit()`, `partial()`, and `required()`
|
|
12
12
|
*/
|
|
13
13
|
export const object = (option = {}, message) => {
|
|
14
|
-
|
|
14
|
+
const validator = ((value) => {
|
|
15
15
|
if (!isDictionaryObject(value)) {
|
|
16
16
|
return {
|
|
17
17
|
validate: false,
|
|
@@ -37,6 +37,8 @@ export const object = (option = {}, message) => {
|
|
|
37
37
|
// biome-ignore lint/suspicious/noExplicitAny: Type assertion needed for return type compatibility
|
|
38
38
|
type: value,
|
|
39
39
|
};
|
|
40
|
-
};
|
|
40
|
+
});
|
|
41
|
+
validator.shape = option;
|
|
42
|
+
return validator;
|
|
41
43
|
};
|
|
42
44
|
//# sourceMappingURL=core.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/Validate/object/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/Validate/object/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAyCnE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,SAAY,EAAO,EACnB,OAAgB,EACI,EAAE;IAWtB,MAAM,SAAS,GAAG,CAAC,CAAC,KAAe,EAAoC,EAAE;QACvE,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,OAAO,IAAI,EAAE;gBACtB,IAAI,EAAE,KAAK;aACZ,CAAC;QACJ,CAAC;QACD,KAAK,MAAM,QAAQ,IAAI,MAAM,EAAE,CAAC;YAC9B,6EAA6E;YAC7E,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAE,KAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;gBACzD,OAAO;oBACL,QAAQ,EAAE,KAAK;oBACf,6EAA6E;oBAC7E,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAY,CAAC,CAAC,OAAO;oBAC/C,kGAAkG;oBAClG,IAAI,EAAE,KAAY;iBACnB,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;YACX,kGAAkG;YAClG,IAAI,EAAE,KAAY;SACnB,CAAC;IACJ,CAAC,CAAuB,CAAC;IAEzB,SAAS,CAAC,KAAK,GAAG,MAAM,CAAC;IACzB,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export * from "./core";
|
|
2
2
|
export * from "./intersection";
|
|
3
3
|
export * from "./nullable";
|
|
4
|
+
export * from "./omit";
|
|
4
5
|
export * from "./optional";
|
|
6
|
+
export * from "./partial";
|
|
7
|
+
export * from "./pick";
|
|
8
|
+
export * from "./required";
|
|
5
9
|
export * from "./union";
|
|
6
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -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,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,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
interface NullReturn {
|
|
2
|
+
validate: boolean;
|
|
3
|
+
message: string;
|
|
4
|
+
type: "null";
|
|
5
|
+
}
|
|
2
6
|
/**
|
|
3
7
|
* Wraps a validator to accept null values
|
|
4
8
|
* @template T - The type of value the wrapped validator expects
|
|
9
|
+
* @template R - The return type of the wrapped validator (preserved so the inner type tag flows through)
|
|
5
10
|
* @param {Function} validator - Validator function to make nullable
|
|
6
11
|
* @returns {Function} - Validator that passes for null or delegates to the wrapped validator
|
|
7
12
|
*/
|
|
8
|
-
export declare const nullable: <T
|
|
13
|
+
export declare const nullable: <T, R extends {
|
|
14
|
+
type: unknown;
|
|
15
|
+
message: string;
|
|
16
|
+
validate: boolean;
|
|
17
|
+
}>(validator: (value: T) => R) => ((value: T | null) => R | NullReturn);
|
|
18
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wraps a validator to accept null values
|
|
3
3
|
* @template T - The type of value the wrapped validator expects
|
|
4
|
+
* @template R - The return type of the wrapped validator (preserved so the inner type tag flows through)
|
|
4
5
|
* @param {Function} validator - Validator function to make nullable
|
|
5
6
|
* @returns {Function} - Validator that passes for null or delegates to the wrapped validator
|
|
6
7
|
*/
|
|
@@ -13,8 +14,7 @@ export const nullable = (validator) => {
|
|
|
13
14
|
type: "null",
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
return result;
|
|
17
|
+
return validator(value);
|
|
18
18
|
};
|
|
19
19
|
return nullableValidator;
|
|
20
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nullable.js","sourceRoot":"","sources":["../../../src/Validate/object/nullable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nullable.js","sourceRoot":"","sources":["../../../src/Validate/object/nullable.ts"],"names":[],"mappings":"AAMA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAItB,SAA0B,EACa,EAAE;IACzC,MAAM,iBAAiB,GAAG,CAAC,KAAe,EAAkB,EAAE;QAC5D,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,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC,CAAC;IAEF,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object validation - omit
|
|
3
|
+
* Returns a new object validator that drops the specified keys from the
|
|
4
|
+
* source validator. Mirrors `Omit<T, K>` at the type level so consumers
|
|
5
|
+
* like `union()`, `intersection()`, and `SchemaToInterface` see the
|
|
6
|
+
* narrowed shape.
|
|
7
|
+
*
|
|
8
|
+
* The function is exported as `omit_` because the top-level `Object` module
|
|
9
|
+
* already exposes an `omit` runtime helper.
|
|
10
|
+
*/
|
|
11
|
+
import { type ObjectShape, type ObjectValidator } from "./core";
|
|
12
|
+
/**
|
|
13
|
+
* Removes the given keys from an existing object validator and returns a new
|
|
14
|
+
* object validator covering the remaining keys.
|
|
15
|
+
* @template T - Original object shape
|
|
16
|
+
* @template K - Tuple of keys to omit from the original shape
|
|
17
|
+
* @param {ObjectValidator<T>} validator - Source object validator
|
|
18
|
+
* @param {K} keys - Keys to drop from the new validator
|
|
19
|
+
* @param {string} [message] - Custom error message for the omitted validator
|
|
20
|
+
* @returns {ObjectValidator<Omit<T, K[number]>>} - New validator without omitted keys
|
|
21
|
+
*/
|
|
22
|
+
export declare const omit_: <T extends ObjectShape, K extends readonly (keyof T)[]>(validator: ObjectValidator<T>, keys: K, message?: string) => ObjectValidator<Omit<T, K[number]>>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object validation - omit
|
|
3
|
+
* Returns a new object validator that drops the specified keys from the
|
|
4
|
+
* source validator. Mirrors `Omit<T, K>` at the type level so consumers
|
|
5
|
+
* like `union()`, `intersection()`, and `SchemaToInterface` see the
|
|
6
|
+
* narrowed shape.
|
|
7
|
+
*
|
|
8
|
+
* The function is exported as `omit_` because the top-level `Object` module
|
|
9
|
+
* already exposes an `omit` runtime helper.
|
|
10
|
+
*/
|
|
11
|
+
import { object } from "./core";
|
|
12
|
+
/**
|
|
13
|
+
* Removes the given keys from an existing object validator and returns a new
|
|
14
|
+
* object validator covering the remaining keys.
|
|
15
|
+
* @template T - Original object shape
|
|
16
|
+
* @template K - Tuple of keys to omit from the original shape
|
|
17
|
+
* @param {ObjectValidator<T>} validator - Source object validator
|
|
18
|
+
* @param {K} keys - Keys to drop from the new validator
|
|
19
|
+
* @param {string} [message] - Custom error message for the omitted validator
|
|
20
|
+
* @returns {ObjectValidator<Omit<T, K[number]>>} - New validator without omitted keys
|
|
21
|
+
*/
|
|
22
|
+
export const omit_ = (validator, keys, message) => {
|
|
23
|
+
const sourceShape = validator.shape;
|
|
24
|
+
const omittedKeys = new Set(keys);
|
|
25
|
+
const nextShape = {};
|
|
26
|
+
for (const key in sourceShape) {
|
|
27
|
+
if (!omittedKeys.has(key)) {
|
|
28
|
+
nextShape[key] = sourceShape[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return object(nextShape, message);
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=omit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../../src/Validate/object/omit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAA0C,MAAM,QAAQ,CAAC;AAExE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,SAA6B,EAC7B,IAAO,EACP,OAAgB,EACqB,EAAE;IACvC,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC;IACpC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAU,IAAI,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,EAAiB,CAAC;IACpC,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,SAAS,EAAE,OAAO,CAE/B,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,8 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
interface UndefinedReturn {
|
|
2
|
+
validate: boolean;
|
|
3
|
+
message: string;
|
|
4
|
+
type: "undefined";
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Optional validator augmented with a reference to the wrapped validator,
|
|
8
|
+
* used by `required()` to unwrap optional layers when rebuilding a shape
|
|
9
|
+
* @template T - The type of value the wrapped validator expects
|
|
10
|
+
* @template R - The return type of the wrapped validator (preserved so the inner type tag flows through)
|
|
11
|
+
*/
|
|
12
|
+
export type OptionalValidator<T, R extends {
|
|
13
|
+
type: unknown;
|
|
14
|
+
message: string;
|
|
15
|
+
validate: boolean;
|
|
16
|
+
} = {
|
|
17
|
+
type: unknown;
|
|
18
|
+
message: string;
|
|
19
|
+
validate: boolean;
|
|
20
|
+
}> = ((value?: T) => R | UndefinedReturn) & {
|
|
21
|
+
inner: (value: T) => R;
|
|
22
|
+
isOptional: true;
|
|
23
|
+
};
|
|
2
24
|
/**
|
|
3
25
|
* Wraps a validator to accept undefined values
|
|
4
26
|
* @template T - The type of value the wrapped validator expects
|
|
27
|
+
* @template R - The return type of the wrapped validator (preserved so the inner type tag flows through)
|
|
5
28
|
* @param {Function} validator - Validator function to make optional
|
|
6
|
-
* @returns {
|
|
29
|
+
* @returns {OptionalValidator<T, R>} - Validator that passes for undefined or delegates to the wrapped validator
|
|
7
30
|
*/
|
|
8
|
-
export declare const optional: <T
|
|
31
|
+
export declare const optional: <T, R extends {
|
|
32
|
+
type: unknown;
|
|
33
|
+
message: string;
|
|
34
|
+
validate: boolean;
|
|
35
|
+
}>(validator: (value: T) => R) => OptionalValidator<T, R>;
|
|
36
|
+
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wraps a validator to accept undefined values
|
|
3
3
|
* @template T - The type of value the wrapped validator expects
|
|
4
|
+
* @template R - The return type of the wrapped validator (preserved so the inner type tag flows through)
|
|
4
5
|
* @param {Function} validator - Validator function to make optional
|
|
5
|
-
* @returns {
|
|
6
|
+
* @returns {OptionalValidator<T, R>} - Validator that passes for undefined or delegates to the wrapped validator
|
|
6
7
|
*/
|
|
7
8
|
export const optional = (validator) => {
|
|
8
|
-
const optionalValidator = (value) => {
|
|
9
|
+
const optionalValidator = ((value) => {
|
|
9
10
|
if (value === undefined) {
|
|
10
11
|
return {
|
|
11
12
|
validate: true,
|
|
@@ -13,9 +14,10 @@ export const optional = (validator) => {
|
|
|
13
14
|
type: "undefined",
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
return validator(value);
|
|
18
|
+
});
|
|
19
|
+
optionalValidator.inner = validator;
|
|
20
|
+
optionalValidator.isOptional = true;
|
|
19
21
|
return optionalValidator;
|
|
20
22
|
};
|
|
21
23
|
//# sourceMappingURL=optional.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional.js","sourceRoot":"","sources":["../../../src/Validate/object/optional.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"optional.js","sourceRoot":"","sources":["../../../src/Validate/object/optional.ts"],"names":[],"mappings":"AAwBA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAItB,SAA0B,EACD,EAAE;IAC3B,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAS,EAAuB,EAAE;QAC5D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,EAAE;gBACX,IAAI,EAAE,WAAW;aAClB,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC,CAA4B,CAAC;IAE9B,iBAAiB,CAAC,KAAK,GAAG,SAAS,CAAC;IACpC,iBAAiB,CAAC,UAAU,GAAG,IAAI,CAAC;IAEpC,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object validation - partial
|
|
3
|
+
* Returns a new object validator where every key is wrapped in `optional()`,
|
|
4
|
+
* mirroring `Partial<T>` at the type level so consumers see all properties as
|
|
5
|
+
* optional.
|
|
6
|
+
*/
|
|
7
|
+
import { type ObjectShape, type ObjectValidator } from "./core";
|
|
8
|
+
import { type OptionalValidator } from "./optional";
|
|
9
|
+
type PartialShape<T extends ObjectShape> = {
|
|
10
|
+
[K in keyof T]: OptionalValidator<Parameters<T[K]>[0], ReturnType<T[K]> extends {
|
|
11
|
+
type: unknown;
|
|
12
|
+
message: string;
|
|
13
|
+
validate: boolean;
|
|
14
|
+
} ? ReturnType<T[K]> : never>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Wraps every property validator of `validator` with `optional()`. Validators
|
|
18
|
+
* that are already optional are kept as-is so the wrapper stays idempotent.
|
|
19
|
+
* @template T - Original object shape
|
|
20
|
+
* @param {ObjectValidator<T>} validator - Source object validator
|
|
21
|
+
* @param {string} [message] - Custom error message for the new validator
|
|
22
|
+
* @returns {ObjectValidator<PartialShape<T>>} - New validator where every key accepts undefined
|
|
23
|
+
*/
|
|
24
|
+
export declare const partial: <T extends ObjectShape>(validator: ObjectValidator<T>, message?: string) => ObjectValidator<PartialShape<T>>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object validation - partial
|
|
3
|
+
* Returns a new object validator where every key is wrapped in `optional()`,
|
|
4
|
+
* mirroring `Partial<T>` at the type level so consumers see all properties as
|
|
5
|
+
* optional.
|
|
6
|
+
*/
|
|
7
|
+
import { object } from "./core";
|
|
8
|
+
import { optional } from "./optional";
|
|
9
|
+
/**
|
|
10
|
+
* Wraps every property validator of `validator` with `optional()`. Validators
|
|
11
|
+
* that are already optional are kept as-is so the wrapper stays idempotent.
|
|
12
|
+
* @template T - Original object shape
|
|
13
|
+
* @param {ObjectValidator<T>} validator - Source object validator
|
|
14
|
+
* @param {string} [message] - Custom error message for the new validator
|
|
15
|
+
* @returns {ObjectValidator<PartialShape<T>>} - New validator where every key accepts undefined
|
|
16
|
+
*/
|
|
17
|
+
export const partial = (validator, message) => {
|
|
18
|
+
const sourceShape = validator.shape;
|
|
19
|
+
const nextShape = {};
|
|
20
|
+
for (const key of Object.keys(sourceShape)) {
|
|
21
|
+
const current = sourceShape[key];
|
|
22
|
+
nextShape[key] =
|
|
23
|
+
current.isOptional === true
|
|
24
|
+
? current
|
|
25
|
+
: optional(current);
|
|
26
|
+
}
|
|
27
|
+
return object(nextShape, message);
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=partial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"partial.js","sourceRoot":"","sources":["../../../src/Validate/object/partial.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAA0C,MAAM,QAAQ,CAAC;AACxE,OAAO,EAAE,QAAQ,EAA0B,MAAM,YAAY,CAAC;AAe9D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,SAA6B,EAC7B,OAAgB,EACkB,EAAE;IACpC,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC;IACpC,MAAM,SAAS,GAAG,EAAiB,CAAC;IACpC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QAC3C,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QACjC,SAAS,CAAC,GAAG,CAAC;YACX,OAAoC,CAAC,UAAU,KAAK,IAAI;gBACvD,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,MAAM,CAAC,SAAS,EAAE,OAAO,CAE/B,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object validation - pick
|
|
3
|
+
* Returns a new object validator that only checks the specified keys of the
|
|
4
|
+
* source validator. Mirrors `Pick<T, K>` at the type level so consumers like
|
|
5
|
+
* `union()`, `intersection()`, and `SchemaToInterface` see the narrowed shape.
|
|
6
|
+
*
|
|
7
|
+
* The function is exported as `pick_` because the top-level `Object` module
|
|
8
|
+
* already exposes a `pick` runtime helper.
|
|
9
|
+
*/
|
|
10
|
+
import { type ObjectShape, type ObjectValidator } from "./core";
|
|
11
|
+
/**
|
|
12
|
+
* Picks the given keys from an existing object validator and returns a new
|
|
13
|
+
* object validator covering only those keys.
|
|
14
|
+
* @template T - Original object shape
|
|
15
|
+
* @template K - Tuple of keys to pick from the original shape
|
|
16
|
+
* @param {ObjectValidator<T>} validator - Source object validator
|
|
17
|
+
* @param {K} keys - Keys to retain on the new validator
|
|
18
|
+
* @param {string} [message] - Custom error message for the picked validator
|
|
19
|
+
* @returns {ObjectValidator<Pick<T, K[number]>>} - New validator scoped to picked keys
|
|
20
|
+
*/
|
|
21
|
+
export declare const pick_: <T extends ObjectShape, K extends readonly (keyof T)[]>(validator: ObjectValidator<T>, keys: K, message?: string) => ObjectValidator<Pick<T, K[number]>>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object validation - pick
|
|
3
|
+
* Returns a new object validator that only checks the specified keys of the
|
|
4
|
+
* source validator. Mirrors `Pick<T, K>` at the type level so consumers like
|
|
5
|
+
* `union()`, `intersection()`, and `SchemaToInterface` see the narrowed shape.
|
|
6
|
+
*
|
|
7
|
+
* The function is exported as `pick_` because the top-level `Object` module
|
|
8
|
+
* already exposes a `pick` runtime helper.
|
|
9
|
+
*/
|
|
10
|
+
import { object } from "./core";
|
|
11
|
+
/**
|
|
12
|
+
* Picks the given keys from an existing object validator and returns a new
|
|
13
|
+
* object validator covering only those keys.
|
|
14
|
+
* @template T - Original object shape
|
|
15
|
+
* @template K - Tuple of keys to pick from the original shape
|
|
16
|
+
* @param {ObjectValidator<T>} validator - Source object validator
|
|
17
|
+
* @param {K} keys - Keys to retain on the new validator
|
|
18
|
+
* @param {string} [message] - Custom error message for the picked validator
|
|
19
|
+
* @returns {ObjectValidator<Pick<T, K[number]>>} - New validator scoped to picked keys
|
|
20
|
+
*/
|
|
21
|
+
export const pick_ = (validator, keys, message) => {
|
|
22
|
+
const sourceShape = validator.shape;
|
|
23
|
+
const nextShape = {};
|
|
24
|
+
for (const key of keys) {
|
|
25
|
+
nextShape[key] = sourceShape[key];
|
|
26
|
+
}
|
|
27
|
+
return object(nextShape, message);
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=pick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pick.js","sourceRoot":"","sources":["../../../src/Validate/object/pick.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAA0C,MAAM,QAAQ,CAAC;AAExE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,SAA6B,EAC7B,IAAO,EACP,OAAgB,EACqB,EAAE;IACvC,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC;IACpC,MAAM,SAAS,GAAG,EAAwB,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object validation - required
|
|
3
|
+
* Returns a new object validator where every key is unwrapped from any
|
|
4
|
+
* `optional()` layer, mirroring `Required<T>` at the type level so consumers
|
|
5
|
+
* see all properties as required again.
|
|
6
|
+
*/
|
|
7
|
+
import { type ObjectShape, type ObjectValidator } from "./core";
|
|
8
|
+
import type { OptionalValidator } from "./optional";
|
|
9
|
+
type UnwrapOptional<V> = V extends OptionalValidator<infer Inner, infer R> ? (value: Inner) => R : V;
|
|
10
|
+
type RequiredShape<T extends ObjectShape> = {
|
|
11
|
+
[K in keyof T]: UnwrapOptional<T[K]> extends ObjectShape[string] ? UnwrapOptional<T[K]> : T[K];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Strips `optional()` wrappers from every property validator of `validator`.
|
|
15
|
+
* Validators that are not wrapped in `optional()` are kept as-is.
|
|
16
|
+
* @template T - Original object shape
|
|
17
|
+
* @param {ObjectValidator<T>} validator - Source object validator
|
|
18
|
+
* @param {string} [message] - Custom error message for the new validator
|
|
19
|
+
* @returns {ObjectValidator<RequiredShape<T>>} - New validator where every optional layer is removed
|
|
20
|
+
*/
|
|
21
|
+
export declare const required: <T extends ObjectShape>(validator: ObjectValidator<T>, message?: string) => ObjectValidator<RequiredShape<T>>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object validation - required
|
|
3
|
+
* Returns a new object validator where every key is unwrapped from any
|
|
4
|
+
* `optional()` layer, mirroring `Required<T>` at the type level so consumers
|
|
5
|
+
* see all properties as required again.
|
|
6
|
+
*/
|
|
7
|
+
import { object } from "./core";
|
|
8
|
+
/**
|
|
9
|
+
* Strips `optional()` wrappers from every property validator of `validator`.
|
|
10
|
+
* Validators that are not wrapped in `optional()` are kept as-is.
|
|
11
|
+
* @template T - Original object shape
|
|
12
|
+
* @param {ObjectValidator<T>} validator - Source object validator
|
|
13
|
+
* @param {string} [message] - Custom error message for the new validator
|
|
14
|
+
* @returns {ObjectValidator<RequiredShape<T>>} - New validator where every optional layer is removed
|
|
15
|
+
*/
|
|
16
|
+
export const required = (validator, message) => {
|
|
17
|
+
const sourceShape = validator.shape;
|
|
18
|
+
const nextShape = {};
|
|
19
|
+
for (const key of Object.keys(sourceShape)) {
|
|
20
|
+
const current = sourceShape[key];
|
|
21
|
+
const optionalLike = current;
|
|
22
|
+
nextShape[key] =
|
|
23
|
+
optionalLike.isOptional === true &&
|
|
24
|
+
typeof optionalLike.inner === "function"
|
|
25
|
+
? optionalLike.inner
|
|
26
|
+
: current;
|
|
27
|
+
}
|
|
28
|
+
return object(nextShape, message);
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=required.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"required.js","sourceRoot":"","sources":["../../../src/Validate/object/required.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAA0C,MAAM,QAAQ,CAAC;AAYxE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,SAA6B,EAC7B,OAAgB,EACmB,EAAE;IACrC,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC;IACpC,MAAM,SAAS,GAAG,EAAiB,CAAC;IACpC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QAC3C,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,YAAY,GAAG,OAGpB,CAAC;QACF,SAAS,CAAC,GAAG,CAAC;YACZ,YAAY,CAAC,UAAU,KAAK,IAAI;gBAChC,OAAO,YAAY,CAAC,KAAK,KAAK,UAAU;gBACtC,CAAC,CAAC,YAAY,CAAC,KAAK;gBACpB,CAAC,CAAC,OAAO,CAAC;IAChB,CAAC;IACD,OAAO,MAAM,CAAC,SAAS,EAAE,OAAO,CAE/B,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set validation core module
|
|
3
|
+
* Provides validation for `Set` instances. The validator can optionally
|
|
4
|
+
* delegate to a per-element validator, mirroring how `arrayOf()` validates
|
|
5
|
+
* each element of an array.
|
|
6
|
+
*
|
|
7
|
+
* The function is exported as `set_` because the top-level `Object` module
|
|
8
|
+
* already exposes a `set` runtime helper.
|
|
9
|
+
*/
|
|
10
|
+
import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
11
|
+
type ExtractValidatedType<V> = V extends (value: never) => {
|
|
12
|
+
type: infer T;
|
|
13
|
+
} ? ValidateType<T> : never;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Set validator. When a per-element validator is supplied, every
|
|
16
|
+
* element of the set must satisfy it; iteration short-circuits at the first
|
|
17
|
+
* failure and surfaces the failing message.
|
|
18
|
+
* @template IV - Validator for set elements
|
|
19
|
+
* @param {IV} [itemValidator] - Validator applied to every element
|
|
20
|
+
* @param {string} [message] - Custom error message for type validation
|
|
21
|
+
* @returns {Function} - Validator function for Set instances
|
|
22
|
+
*/
|
|
23
|
+
export declare const set_: <IV extends (value: any) => ValidateCoreReturnType<unknown> = (value: unknown) => ValidateCoreReturnType<unknown>, T = ExtractValidatedType<IV>>(itemValidator?: IV, message?: string) => (value: Set<T>) => ValidateCoreReturnType<Set<T>>;
|
|
24
|
+
export {};
|