@bemedev/typings 0.3.0 → 0.4.1
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/lib/constants.cjs +4 -0
- package/lib/constants.d.ts +7 -5
- package/lib/constants.js +3 -1
- package/lib/helpers/any.cjs +4 -3
- package/lib/helpers/any.d.ts +4 -2
- package/lib/helpers/any.js +5 -3
- package/lib/helpers/array.cjs +6 -4
- package/lib/helpers/array.d.ts +4 -2
- package/lib/helpers/array.js +6 -4
- package/lib/helpers/custom.cjs +21 -2
- package/lib/helpers/custom.d.ts +20 -3
- package/lib/helpers/custom.js +22 -2
- package/lib/helpers/index.cjs +4 -2
- package/lib/helpers/index.d.ts +1 -0
- package/lib/helpers/index.js +4 -3
- package/lib/helpers/intersection.cjs +2 -6
- package/lib/helpers/intersection.d.ts +1 -2
- package/lib/helpers/intersection.js +2 -6
- package/lib/helpers/litterals.cjs +7 -1
- package/lib/helpers/litterals.d.ts +4 -2
- package/lib/helpers/litterals.js +7 -1
- package/lib/helpers/object.cjs +10 -0
- package/lib/helpers/object.d.ts +5 -0
- package/lib/helpers/object.js +9 -0
- package/lib/helpers/optional.cjs +4 -2
- package/lib/helpers/optional.d.ts +2 -3
- package/lib/helpers/optional.js +4 -2
- package/lib/helpers/partial.cjs +2 -7
- package/lib/helpers/partial.d.ts +1 -2
- package/lib/helpers/partial.js +2 -7
- package/lib/helpers/primitive.cjs +21 -18
- package/lib/helpers/primitive.d.ts +25 -7
- package/lib/helpers/primitive.js +21 -19
- package/lib/helpers/primitiveObject.cjs +8 -5
- package/lib/helpers/primitiveObject.d.ts +8 -3
- package/lib/helpers/primitiveObject.js +8 -6
- package/lib/helpers/record.cjs +7 -4
- package/lib/helpers/record.d.ts +4 -2
- package/lib/helpers/record.js +7 -4
- package/lib/helpers/soa.cjs +2 -2
- package/lib/helpers/soa.d.ts +1 -2
- package/lib/helpers/soa.js +2 -2
- package/lib/helpers/sv.cjs +6 -1
- package/lib/helpers/sv.d.ts +4 -2
- package/lib/helpers/sv.js +6 -1
- package/lib/helpers/tuple.cjs +6 -1
- package/lib/helpers/tuple.d.ts +4 -2
- package/lib/helpers/tuple.js +6 -1
- package/lib/helpers/union.cjs +3 -1
- package/lib/helpers/union.d.ts +2 -2
- package/lib/helpers/union.js +3 -1
- package/lib/index.cjs +2 -0
- package/lib/index.js +2 -2
- package/lib/standard.cjs +21 -0
- package/lib/standard.d.ts +7 -0
- package/lib/standard.js +19 -0
- package/lib/standard.types.d.ts +59 -0
- package/lib/type.cjs +12 -21
- package/lib/type.js +12 -21
- package/lib/type.types.d.ts +4 -3
- package/lib/types.d.ts +16 -8
- package/lib/utils/expandFn.cjs +8 -0
- package/lib/utils/expandFn.d.ts +5 -1
- package/lib/utils/expandFn.js +8 -1
- package/lib/utils/index.cjs +8 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.js +5 -0
- package/package.json +2 -2
package/lib/helpers/record.cjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_standard = require("../standard.cjs");
|
|
3
|
+
const require_utils_expandFn = require("../utils/expandFn.cjs");
|
|
4
|
+
const require_helpers_object = require("./object.cjs");
|
|
2
5
|
//#region src/helpers/record.ts
|
|
3
|
-
const record = (value, ...keys) => {
|
|
4
|
-
return keys.reduce((acc, key) => {
|
|
6
|
+
const record = require_utils_expandFn.expandFn2((value, ...keys) => {
|
|
7
|
+
return require_standard.standardize2(keys.reduce((acc, key) => {
|
|
5
8
|
acc[key] = value;
|
|
6
9
|
return acc;
|
|
7
|
-
}, {});
|
|
8
|
-
};
|
|
10
|
+
}, {}));
|
|
11
|
+
}, require_helpers_object.object.const);
|
|
9
12
|
//#endregion
|
|
10
13
|
exports.record = record;
|
package/lib/helpers/record.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Keys, ObjectT } from "../types";
|
|
2
|
-
declare const record: <const K extends Keys[], V extends ObjectT>(value: V, ...keys: K) => Record<K[number] extends never ?
|
|
3
|
-
|
|
2
|
+
export declare const record: import("..").FnBasic<(<const K extends Keys[], V extends ObjectT>(value: V, ...keys: K) => Record<K[number] extends never ? string | number | symbol : K[number], V>), object & {
|
|
3
|
+
const: import("..").ObjectMapS;
|
|
4
|
+
type: import("..").ObjectMapS;
|
|
5
|
+
}>;
|
package/lib/helpers/record.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { standardize2 } from "../standard.js";
|
|
2
|
+
import { expandFn2 } from "../utils/expandFn.js";
|
|
3
|
+
import { object } from "./object.js";
|
|
1
4
|
//#region src/helpers/record.ts
|
|
2
|
-
const record = (value, ...keys) => {
|
|
3
|
-
return keys.reduce((acc, key) => {
|
|
5
|
+
const record = expandFn2((value, ...keys) => {
|
|
6
|
+
return standardize2(keys.reduce((acc, key) => {
|
|
4
7
|
acc[key] = value;
|
|
5
8
|
return acc;
|
|
6
|
-
}, {});
|
|
7
|
-
};
|
|
9
|
+
}, {}));
|
|
10
|
+
}, object.const);
|
|
8
11
|
//#endregion
|
|
9
12
|
export { record };
|
package/lib/helpers/soa.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_standard = require("../standard.cjs");
|
|
3
3
|
//#region src/helpers/soa.ts
|
|
4
4
|
const soa = (value) => {
|
|
5
|
-
return
|
|
5
|
+
return require_standard.standardize2(value);
|
|
6
6
|
};
|
|
7
7
|
//#endregion
|
|
8
8
|
exports.soa = soa;
|
package/lib/helpers/soa.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import type { NotReadonly, ObjectT, SoaCustom } from "../types";
|
|
2
|
-
declare const soa: <const T extends ObjectT>(value
|
|
3
|
-
export { soa };
|
|
2
|
+
export declare const soa: <const T extends ObjectT>(value?: T) => ObjectT extends NotReadonly<T> ? "any" : SoaCustom<NotReadonly<T>>;
|
package/lib/helpers/soa.js
CHANGED
package/lib/helpers/sv.cjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_standard = require("../standard.cjs");
|
|
3
|
+
const require_utils_expandFn = require("../utils/expandFn.cjs");
|
|
4
|
+
const require_utils_index = require("../utils/index.cjs");
|
|
2
5
|
//#region src/helpers/sv.ts
|
|
3
|
-
const sv = {
|
|
6
|
+
const sv = require_utils_expandFn.expandFn2((value) => {
|
|
7
|
+
return require_standard.standardize2(value);
|
|
8
|
+
}, require_utils_index._const());
|
|
4
9
|
//#endregion
|
|
5
10
|
exports.sv = sv;
|
package/lib/helpers/sv.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Custom, StateValue } from "../types";
|
|
2
|
-
declare const sv: Custom<StateValue
|
|
3
|
-
|
|
2
|
+
export declare const sv: import("..").FnBasic<(<const T extends StateValue = StateValue>(value?: T) => StateValue extends T ? Custom<StateValue> : Custom<T>), object & {
|
|
3
|
+
const: Custom<StateValue>;
|
|
4
|
+
type: Custom<StateValue>;
|
|
5
|
+
}>;
|
package/lib/helpers/sv.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { standardize2 } from "../standard.js";
|
|
2
|
+
import { expandFn2 } from "../utils/expandFn.js";
|
|
3
|
+
import { _const } from "../utils/index.js";
|
|
1
4
|
//#region src/helpers/sv.ts
|
|
2
|
-
const sv = {
|
|
5
|
+
const sv = expandFn2((value) => {
|
|
6
|
+
return standardize2(value);
|
|
7
|
+
}, _const());
|
|
3
8
|
//#endregion
|
|
4
9
|
export { sv };
|
package/lib/helpers/tuple.cjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_standard = require("../standard.cjs");
|
|
3
|
+
const require_utils_expandFn = require("../utils/expandFn.cjs");
|
|
4
|
+
const require_helpers_array = require("./array.cjs");
|
|
2
5
|
//#region src/helpers/tuple.ts
|
|
3
|
-
const tuple = (...values) =>
|
|
6
|
+
const tuple = require_utils_expandFn.expandFn2((...values) => {
|
|
7
|
+
return require_standard.standardize2(values);
|
|
8
|
+
}, require_helpers_array.array.type);
|
|
4
9
|
//#endregion
|
|
5
10
|
exports.tuple = tuple;
|
package/lib/helpers/tuple.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { NotReadonly, ObjectT } from "../types";
|
|
2
|
-
declare const tuple: <const T extends [ObjectT, ...ObjectT[]]>(...values: T) => NotReadonly<T
|
|
3
|
-
|
|
2
|
+
export declare const tuple: import("..").FnBasic<(<const T extends [ObjectT, ...ObjectT[]]>(...values: T) => NotReadonly<T>), object & {
|
|
3
|
+
const: import("..").ArrayCustom;
|
|
4
|
+
type: import("..").ArrayCustom;
|
|
5
|
+
}>;
|
package/lib/helpers/tuple.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { standardize2 } from "../standard.js";
|
|
2
|
+
import { expandFn2 } from "../utils/expandFn.js";
|
|
3
|
+
import { array } from "./array.js";
|
|
1
4
|
//#region src/helpers/tuple.ts
|
|
2
|
-
const tuple = (...values) =>
|
|
5
|
+
const tuple = expandFn2((...values) => {
|
|
6
|
+
return standardize2(values);
|
|
7
|
+
}, array.type);
|
|
3
8
|
//#endregion
|
|
4
9
|
export { tuple };
|
package/lib/helpers/union.cjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_standard = require("../standard.cjs");
|
|
2
3
|
const require_utils_expandFn = require("../utils/expandFn.cjs");
|
|
4
|
+
const require_constants = require("../constants.cjs");
|
|
3
5
|
//#region src/helpers/union.ts
|
|
4
6
|
const _union = (...values) => {
|
|
5
|
-
return
|
|
7
|
+
return require_standard.standardize2({ [require_constants.UNION]: values });
|
|
6
8
|
};
|
|
7
9
|
const union = require_utils_expandFn.expandFn(_union, { discriminated: (_key, ...values) => _union(...values) });
|
|
8
10
|
//#endregion
|
package/lib/helpers/union.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Keys, ObjectMapS, ObjectT } from "../types";
|
|
2
2
|
type Discriminated<K extends Keys> = ObjectMapS & Record<K, ObjectT>;
|
|
3
|
-
declare const union: import("..").FnBasic<(<T extends [ObjectT, ObjectT, ...ObjectT[]]>(...values: T) => T[number]), {
|
|
3
|
+
export declare const union: import("..").FnBasic<(<T extends [ObjectT, ObjectT, ...ObjectT[]]>(...values: T) => T[number]), {
|
|
4
4
|
readonly discriminated: <const K extends Keys, T extends [Discriminated<K>, Discriminated<K>, ...Discriminated<K>[]]>(_key: K, ...values: T) => T[number];
|
|
5
5
|
}>;
|
|
6
|
-
export {
|
|
6
|
+
export {};
|
package/lib/helpers/union.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { standardize2 } from "../standard.js";
|
|
1
2
|
import { expandFn } from "../utils/expandFn.js";
|
|
3
|
+
import { UNION } from "../constants.js";
|
|
2
4
|
//#region src/helpers/union.ts
|
|
3
5
|
const _union = (...values) => {
|
|
4
|
-
return
|
|
6
|
+
return standardize2({ [UNION]: values });
|
|
5
7
|
};
|
|
6
8
|
const union = expandFn(_union, { discriminated: (_key, ...values) => _union(...values) });
|
|
7
9
|
//#endregion
|
package/lib/index.cjs
CHANGED
|
@@ -3,9 +3,11 @@ const require_constants = require("./constants.cjs");
|
|
|
3
3
|
const require_type = require("./type.cjs");
|
|
4
4
|
exports.ARRAY = require_constants.ARRAY;
|
|
5
5
|
exports.CUSTOM = require_constants.CUSTOM;
|
|
6
|
+
exports.LITTERALS = require_constants.LITTERALS;
|
|
6
7
|
exports.OPTIONAL = require_constants.OPTIONAL;
|
|
7
8
|
exports.PARTIAL = require_constants.PARTIAL;
|
|
8
9
|
exports.PRIMITIVES = require_constants.PRIMITIVES;
|
|
9
10
|
exports.PRIMITIVE_OBJECTS = require_constants.PRIMITIVE_OBJECTS;
|
|
10
11
|
exports.SOA = require_constants.SOA;
|
|
12
|
+
exports.UNION = require_constants.UNION;
|
|
11
13
|
exports.type = require_type.type;
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ARRAY, CUSTOM, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA } from "./constants.js";
|
|
1
|
+
import { ARRAY, CUSTOM, LITTERALS, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, UNION } from "./constants.js";
|
|
2
2
|
import { type } from "./type.js";
|
|
3
|
-
export { ARRAY, CUSTOM, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, type };
|
|
3
|
+
export { ARRAY, CUSTOM, LITTERALS, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, UNION, type };
|
package/lib/standard.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/standard.ts
|
|
3
|
+
const _standardize = (value) => {
|
|
4
|
+
return {
|
|
5
|
+
value,
|
|
6
|
+
"~standard": {
|
|
7
|
+
version: 1,
|
|
8
|
+
vendor: "@bemedev/typings",
|
|
9
|
+
types: {
|
|
10
|
+
input: value,
|
|
11
|
+
output: value
|
|
12
|
+
},
|
|
13
|
+
validate: () => ({ value })
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const standardize = _standardize;
|
|
18
|
+
const standardize2 = (value) => value;
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.standardize = standardize;
|
|
21
|
+
exports.standardize2 = standardize2;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "./standard.types";
|
|
2
|
+
type Standardize_F = <T>(value: T) => {
|
|
3
|
+
value: T;
|
|
4
|
+
} & StandardSchemaV1<T, T>;
|
|
5
|
+
export declare const standardize: Standardize_F;
|
|
6
|
+
export declare const standardize2: <T>(value?: unknown) => T;
|
|
7
|
+
export {};
|
package/lib/standard.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/standard.ts
|
|
2
|
+
const _standardize = (value) => {
|
|
3
|
+
return {
|
|
4
|
+
value,
|
|
5
|
+
"~standard": {
|
|
6
|
+
version: 1,
|
|
7
|
+
vendor: "@bemedev/typings",
|
|
8
|
+
types: {
|
|
9
|
+
input: value,
|
|
10
|
+
output: value
|
|
11
|
+
},
|
|
12
|
+
validate: () => ({ value })
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const standardize = _standardize;
|
|
17
|
+
const standardize2 = (value) => value;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { standardize, standardize2 };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** The Standard Schema interface. */
|
|
2
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
3
|
+
/** The Standard Schema properties. */
|
|
4
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
5
|
+
}
|
|
6
|
+
export declare namespace StandardSchemaV1 {
|
|
7
|
+
/** The Standard Schema properties interface. */
|
|
8
|
+
interface Props<Input = unknown, Output = Input> {
|
|
9
|
+
/** The version number of the standard. */
|
|
10
|
+
readonly version: 1;
|
|
11
|
+
/** The vendor name of the schema library. */
|
|
12
|
+
readonly vendor: "@bemedev/typings";
|
|
13
|
+
/** Validates unknown input values. */
|
|
14
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
15
|
+
/** Inferred types associated with the schema. */
|
|
16
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** The result interface of the validate function. */
|
|
19
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
20
|
+
/** The result interface if validation succeeds. */
|
|
21
|
+
interface SuccessResult<Output> {
|
|
22
|
+
/** The typed output value. */
|
|
23
|
+
readonly value: Output;
|
|
24
|
+
/** A falsy value for `issues` indicates success. */
|
|
25
|
+
readonly issues?: undefined;
|
|
26
|
+
}
|
|
27
|
+
interface Options {
|
|
28
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
29
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
30
|
+
}
|
|
31
|
+
/** The result interface if validation fails. */
|
|
32
|
+
interface FailureResult {
|
|
33
|
+
/** The issues of failed validation. */
|
|
34
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
35
|
+
}
|
|
36
|
+
/** The issue interface of the failure output. */
|
|
37
|
+
interface Issue {
|
|
38
|
+
/** The error message of the issue. */
|
|
39
|
+
readonly message: string;
|
|
40
|
+
/** The path of the issue, if any. */
|
|
41
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
42
|
+
}
|
|
43
|
+
/** The path segment interface of the issue. */
|
|
44
|
+
interface PathSegment {
|
|
45
|
+
/** The key representing a path segment. */
|
|
46
|
+
readonly key: PropertyKey;
|
|
47
|
+
}
|
|
48
|
+
/** The Standard Schema types interface. */
|
|
49
|
+
interface Types<Input = unknown, Output = Input> {
|
|
50
|
+
/** The input type of the schema. */
|
|
51
|
+
readonly input: Input;
|
|
52
|
+
/** The output type of the schema. */
|
|
53
|
+
readonly output: Output;
|
|
54
|
+
}
|
|
55
|
+
/** Infers the input type of a Standard Schema. */
|
|
56
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
57
|
+
/** Infers the output type of a Standard Schema. */
|
|
58
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
59
|
+
}
|
package/lib/type.cjs
CHANGED
|
@@ -1,41 +1,30 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const require_helpers_readonly = require("./helpers/readonly.cjs");
|
|
2
|
+
const require_standard = require("./standard.cjs");
|
|
4
3
|
const require_helpers_any = require("./helpers/any.cjs");
|
|
5
4
|
const require_helpers_array = require("./helpers/array.cjs");
|
|
6
5
|
const require_helpers_custom = require("./helpers/custom.cjs");
|
|
7
6
|
const require_helpers_intersection = require("./helpers/intersection.cjs");
|
|
7
|
+
const require_helpers_union = require("./helpers/union.cjs");
|
|
8
8
|
const require_helpers_litterals = require("./helpers/litterals.cjs");
|
|
9
9
|
const require_helpers_optional = require("./helpers/optional.cjs");
|
|
10
10
|
const require_helpers_partial = require("./helpers/partial.cjs");
|
|
11
11
|
const require_helpers_primitive = require("./helpers/primitive.cjs");
|
|
12
12
|
const require_helpers_primitiveObject = require("./helpers/primitiveObject.cjs");
|
|
13
|
+
const require_helpers_readonly = require("./helpers/readonly.cjs");
|
|
14
|
+
const require_helpers_object = require("./helpers/object.cjs");
|
|
13
15
|
const require_helpers_record = require("./helpers/record.cjs");
|
|
14
16
|
const require_helpers_soa = require("./helpers/soa.cjs");
|
|
15
17
|
const require_helpers_sv = require("./helpers/sv.cjs");
|
|
16
18
|
const require_helpers_tuple = require("./helpers/tuple.cjs");
|
|
17
|
-
const require_helpers_union = require("./helpers/union.cjs");
|
|
18
19
|
require("./helpers/index.cjs");
|
|
19
20
|
//#region src/type.ts
|
|
20
|
-
const transformTypes = (_) => {};
|
|
21
21
|
const _transform = (obj) => {
|
|
22
|
-
|
|
23
|
-
if (Array.isArray(obj)) return obj.map(_transform);
|
|
24
|
-
if (typeof obj === "object") {
|
|
25
|
-
if ("$$app-ts => optional$$" in _obj) return _transform(_obj[require_constants.OPTIONAL]);
|
|
26
|
-
const isCustom = Object.keys(obj).every((key) => key === require_constants.CUSTOM);
|
|
27
|
-
const out = {};
|
|
28
|
-
if (isCustom) return out;
|
|
29
|
-
Object.entries(obj).filter(([key]) => key !== require_constants.PARTIAL).forEach(([key, value]) => {
|
|
30
|
-
out[key] = _transform(value);
|
|
31
|
-
});
|
|
32
|
-
return out;
|
|
33
|
-
}
|
|
34
|
-
return transformTypes(_obj);
|
|
22
|
+
return obj;
|
|
35
23
|
};
|
|
36
24
|
const type = (option) => {
|
|
37
|
-
|
|
38
|
-
if (
|
|
25
|
+
let out;
|
|
26
|
+
if (!option) out = option;
|
|
27
|
+
else if (typeof option === "function") out = _transform(option({
|
|
39
28
|
any: require_helpers_any.any,
|
|
40
29
|
custom: require_helpers_custom.custom,
|
|
41
30
|
intersection: require_helpers_intersection.intersection,
|
|
@@ -50,9 +39,11 @@ const type = (option) => {
|
|
|
50
39
|
tuple: require_helpers_tuple.tuple,
|
|
51
40
|
primitiveObject: require_helpers_primitiveObject.primitiveObject,
|
|
52
41
|
primitive: require_helpers_primitive.primitive,
|
|
53
|
-
readonly: require_helpers_readonly.readonly
|
|
42
|
+
readonly: require_helpers_readonly.readonly,
|
|
43
|
+
object: require_helpers_object.object
|
|
54
44
|
}));
|
|
55
|
-
|
|
45
|
+
else out = _transform(option);
|
|
46
|
+
return require_standard.standardize(out);
|
|
56
47
|
};
|
|
57
48
|
//#endregion
|
|
58
49
|
exports.type = type;
|
package/lib/type.js
CHANGED
|
@@ -1,40 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readonly } from "./helpers/readonly.js";
|
|
1
|
+
import { standardize } from "./standard.js";
|
|
3
2
|
import { any } from "./helpers/any.js";
|
|
4
3
|
import { array } from "./helpers/array.js";
|
|
5
4
|
import { custom } from "./helpers/custom.js";
|
|
6
5
|
import { intersection } from "./helpers/intersection.js";
|
|
6
|
+
import { union } from "./helpers/union.js";
|
|
7
7
|
import { litterals } from "./helpers/litterals.js";
|
|
8
8
|
import { optional } from "./helpers/optional.js";
|
|
9
9
|
import { partial } from "./helpers/partial.js";
|
|
10
10
|
import { primitive } from "./helpers/primitive.js";
|
|
11
11
|
import { primitiveObject } from "./helpers/primitiveObject.js";
|
|
12
|
+
import { readonly } from "./helpers/readonly.js";
|
|
13
|
+
import { object } from "./helpers/object.js";
|
|
12
14
|
import { record } from "./helpers/record.js";
|
|
13
15
|
import { soa } from "./helpers/soa.js";
|
|
14
16
|
import { sv } from "./helpers/sv.js";
|
|
15
17
|
import { tuple } from "./helpers/tuple.js";
|
|
16
|
-
import { union } from "./helpers/union.js";
|
|
17
18
|
import "./helpers/index.js";
|
|
18
19
|
//#region src/type.ts
|
|
19
|
-
const transformTypes = (_) => {};
|
|
20
20
|
const _transform = (obj) => {
|
|
21
|
-
|
|
22
|
-
if (Array.isArray(obj)) return obj.map(_transform);
|
|
23
|
-
if (typeof obj === "object") {
|
|
24
|
-
if ("$$app-ts => optional$$" in _obj) return _transform(_obj[OPTIONAL]);
|
|
25
|
-
const isCustom = Object.keys(obj).every((key) => key === CUSTOM);
|
|
26
|
-
const out = {};
|
|
27
|
-
if (isCustom) return out;
|
|
28
|
-
Object.entries(obj).filter(([key]) => key !== PARTIAL).forEach(([key, value]) => {
|
|
29
|
-
out[key] = _transform(value);
|
|
30
|
-
});
|
|
31
|
-
return out;
|
|
32
|
-
}
|
|
33
|
-
return transformTypes(_obj);
|
|
21
|
+
return obj;
|
|
34
22
|
};
|
|
35
23
|
const type = (option) => {
|
|
36
|
-
|
|
37
|
-
if (
|
|
24
|
+
let out;
|
|
25
|
+
if (!option) out = option;
|
|
26
|
+
else if (typeof option === "function") out = _transform(option({
|
|
38
27
|
any,
|
|
39
28
|
custom,
|
|
40
29
|
intersection,
|
|
@@ -49,9 +38,11 @@ const type = (option) => {
|
|
|
49
38
|
tuple,
|
|
50
39
|
primitiveObject,
|
|
51
40
|
primitive,
|
|
52
|
-
readonly
|
|
41
|
+
readonly,
|
|
42
|
+
object
|
|
53
43
|
}));
|
|
54
|
-
|
|
44
|
+
else out = _transform(option);
|
|
45
|
+
return standardize(out);
|
|
55
46
|
};
|
|
56
47
|
//#endregion
|
|
57
48
|
export { type };
|
package/lib/type.types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { any, array, custom, intersection, litterals, optional, partial, primitive, primitiveObject, readonly, record, soa, sv, tuple, union, object } from "./helpers";
|
|
2
|
+
import type { ObjectT, inferSh } from "./types";
|
|
3
3
|
export type Helpers = {
|
|
4
4
|
any: typeof any;
|
|
5
5
|
custom: typeof custom;
|
|
@@ -16,5 +16,6 @@ export type Helpers = {
|
|
|
16
16
|
primitiveObject: typeof primitiveObject;
|
|
17
17
|
primitive: typeof primitive;
|
|
18
18
|
readonly: typeof readonly;
|
|
19
|
+
object: typeof object;
|
|
19
20
|
};
|
|
20
|
-
export type Transform_F = <T extends ObjectT = ObjectT>(option?: ((helpers: Helpers) => T) | T) =>
|
|
21
|
+
export type Transform_F = <T extends ObjectT = ObjectT>(option?: ((helpers: Helpers) => T) | T) => inferSh<T>;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ARRAY, CUSTOM, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA } from
|
|
1
|
+
import type { ARRAY, CUSTOM, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA } from './constants';
|
|
2
|
+
import type { StandardSchemaV1 } from './standard.types';
|
|
2
3
|
export type Ru = Record<Keys, unknown>;
|
|
3
4
|
export type TrueObject = Ru & {
|
|
4
5
|
[Symbol.iterator]?: never;
|
|
@@ -24,11 +25,11 @@ type RecursiveArrayOf<T> = Array<_SingleOrRecursiveArrayOf<T>> | ReadonlyArray<_
|
|
|
24
25
|
type _SingleOrRecursiveArrayOf<T> = T | RecursiveArrayOf<T>;
|
|
25
26
|
export type SingleOrRecursiveArrayOf<T> = T | RecursiveArrayOf<T>;
|
|
26
27
|
export type SoRa<T> = SingleOrRecursiveArrayOf<T>;
|
|
27
|
-
export type
|
|
28
|
+
export type Primitive = string | number | boolean | bigint | null | undefined | symbol | never;
|
|
28
29
|
export type PrimitiveT = (typeof PRIMITIVES)[number];
|
|
29
|
-
type TransformPrimitiveS<T extends PrimitiveT> = T extends
|
|
30
|
+
type TransformPrimitiveS<T extends PrimitiveT> = T extends 'string' ? string : T extends 'number' ? number : T extends 'boolean' ? boolean : T extends 'bigint' ? bigint : T extends 'null' ? null : T extends 'undefined' ? undefined : T extends 'symbol' ? symbol : T extends 'never' ? never : Primitive;
|
|
30
31
|
export type Types = PrimitiveT | (typeof PRIMITIVE_OBJECTS)[number];
|
|
31
|
-
export type TransformTypes<T extends Types> = T extends PrimitiveT ? TransformPrimitiveS<T> : T extends
|
|
32
|
+
export type TransformTypes<T extends Types> = T extends PrimitiveT ? TransformPrimitiveS<T> : T extends 'date' ? Date : T extends 'any' ? any : T extends 'unknown' ? unknown : object;
|
|
32
33
|
export type Custom<T = any> = {
|
|
33
34
|
[CUSTOM]: T;
|
|
34
35
|
};
|
|
@@ -38,7 +39,8 @@ export type SoaCustom<T extends ObjectT = any> = {
|
|
|
38
39
|
export type PartialCustom = {
|
|
39
40
|
[PARTIAL]: undefined;
|
|
40
41
|
};
|
|
41
|
-
export type __ObjectT = Types | ObjectMapS | Custom | PartialCustom;
|
|
42
|
+
export type __ObjectT = Types | ObjectMapS | Custom | PartialCustom | PrimitiveObjectT;
|
|
43
|
+
export type CanOptional = __ObjectT | ArrayCustom | AnyArray<__ObjectT>;
|
|
42
44
|
export type Optional<T extends __ObjectT | ArrayCustom | AnyArray<__ObjectT> = __ObjectT> = {
|
|
43
45
|
[OPTIONAL]: T;
|
|
44
46
|
};
|
|
@@ -66,7 +68,7 @@ export interface PrimitiveObjectMapS {
|
|
|
66
68
|
*
|
|
67
69
|
* @remark
|
|
68
70
|
*/
|
|
69
|
-
export type ObjectT = SoRa<_ObjectT
|
|
71
|
+
export type ObjectT = SoRa<_ObjectT>;
|
|
70
72
|
export type POS = ObjectT;
|
|
71
73
|
type ReduceTuple2<T extends AnyArray<ObjectT>> = T extends [
|
|
72
74
|
infer First,
|
|
@@ -75,7 +77,7 @@ type ReduceTuple2<T extends AnyArray<ObjectT>> = T extends [
|
|
|
75
77
|
type ReduceTupleU<T extends AnyArray> = T extends [
|
|
76
78
|
infer First,
|
|
77
79
|
...infer Rest extends AnyArray
|
|
78
|
-
] ? [Undefiny<First>, ...ReduceTupleU<Rest>] : T[number] extends never ? [] : T[
|
|
80
|
+
] ? [Undefiny<First>, ...ReduceTupleU<Rest>] : T[number] extends never ? [] : T['length'] extends 0 ? [] : number extends T['length'] ? T : Undefiny<T[number]>[];
|
|
79
81
|
type __TransformPrimitiveObject<T> = T extends Types ? TransformTypes<T> : T extends ArrayCustom<infer A> ? TransformT<A>[] : T extends SoaCustom<infer TSoA> ? SoA<__TransformPrimitiveObject<TSoA>> : T extends Custom<infer TCustom> ? TCustom : T extends AnyArray<ObjectT> ? ReduceTuple2<T> : T extends PartialCustom ? Partial<__TransformPrimitiveObject<NOmit<T, typeof PARTIAL>>> : T extends Optional<infer TOptional> ? __TransformPrimitiveObject<TOptional> | OptionalHelperClass : {
|
|
80
82
|
[K in keyof T]: __TransformPrimitiveObject<T[K]>;
|
|
81
83
|
};
|
|
@@ -89,6 +91,12 @@ type UndefinyObject<T extends object> = {
|
|
|
89
91
|
} : never;
|
|
90
92
|
type Undefiny<T, U = Exclude<T, OptionalHelperClass>> = U extends AnyArray ? ReduceTupleU<U> : U extends Ru ? UndefinyObject<U> : U;
|
|
91
93
|
type TransformT<T> = Undefiny<__TransformPrimitiveObject<T>>;
|
|
92
|
-
export type
|
|
94
|
+
export type StandardHelper<T = any> = {
|
|
95
|
+
value: T;
|
|
96
|
+
} & StandardSchemaV1<T, T>;
|
|
97
|
+
export type Sh<T = any> = StandardHelper<T>;
|
|
98
|
+
export type inferO<T extends ObjectT = ObjectT> = ObjectT extends T ? unknown : TransformT<T>;
|
|
99
|
+
export type inferSh<T extends ObjectT = ObjectT> = Sh<inferO<T>>;
|
|
100
|
+
export type inferT<T extends Sh> = T['value'];
|
|
93
101
|
export type FnBasic<Main extends Fn, Tr extends object> = Tr & Main;
|
|
94
102
|
export {};
|
package/lib/utils/expandFn.cjs
CHANGED
|
@@ -7,5 +7,13 @@ const expandFn = (main, extensions) => {
|
|
|
7
7
|
/* v8 ignore stop -- @preserve */
|
|
8
8
|
return out;
|
|
9
9
|
};
|
|
10
|
+
const expandFn2 = (main, type, extensions) => {
|
|
11
|
+
return expandFn(main, {
|
|
12
|
+
...extensions,
|
|
13
|
+
const: type,
|
|
14
|
+
type
|
|
15
|
+
});
|
|
16
|
+
};
|
|
10
17
|
//#endregion
|
|
11
18
|
exports.expandFn = expandFn;
|
|
19
|
+
exports.expandFn2 = expandFn2;
|
package/lib/utils/expandFn.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import type { Fn, FnBasic } from "../types";
|
|
1
|
+
import type { Fn, FnBasic, ObjectT } from "../types";
|
|
2
2
|
export declare const expandFn: <Main extends Fn, const Tr extends object = object>(main: Main, extensions?: Tr) => FnBasic<Main, Tr>;
|
|
3
|
+
export declare const expandFn2: <Main extends Fn, C extends ObjectT, const Tr extends object = object>(main: Main, type: C, extensions?: Tr) => FnBasic<Main, Tr & {
|
|
4
|
+
const: C;
|
|
5
|
+
type: C;
|
|
6
|
+
}>;
|
package/lib/utils/expandFn.js
CHANGED
|
@@ -6,5 +6,12 @@ const expandFn = (main, extensions) => {
|
|
|
6
6
|
/* v8 ignore stop -- @preserve */
|
|
7
7
|
return out;
|
|
8
8
|
};
|
|
9
|
+
const expandFn2 = (main, type, extensions) => {
|
|
10
|
+
return expandFn(main, {
|
|
11
|
+
...extensions,
|
|
12
|
+
const: type,
|
|
13
|
+
type
|
|
14
|
+
});
|
|
15
|
+
};
|
|
9
16
|
//#endregion
|
|
10
|
-
export { expandFn };
|
|
17
|
+
export { expandFn, expandFn2 };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils_expandFn = require("./expandFn.cjs");
|
|
3
|
+
//#region src/utils/index.ts
|
|
4
|
+
const _const = (value) => value;
|
|
5
|
+
//#endregion
|
|
6
|
+
exports._const = _const;
|
|
7
|
+
exports.expandFn = require_utils_expandFn.expandFn;
|
|
8
|
+
exports.expandFn2 = require_utils_expandFn.expandFn2;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemedev/typings",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Typings by variables",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "bri_lvi@icloud.com",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"p-q": "pretty-quick",
|
|
77
77
|
"rinit": "pnpm run rm && pnpm run config",
|
|
78
78
|
"rinit:off": "pnpm run rm && pnpm run config:off",
|
|
79
|
-
"rimraf": "
|
|
79
|
+
"rimraf": "pnpm dlx rimraf -rf",
|
|
80
80
|
"rm": "pnpm run rimraf -- node_modules pnpm-lock.yaml",
|
|
81
81
|
"rm:lib": "pnpm run rimraf -- lib",
|
|
82
82
|
"rolldown": "rolldown -c",
|