@bemedev/typings 0.5.4 → 0.5.6
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 +5 -0
- package/lib/constants.cjs +4 -0
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +3 -1
- package/lib/helpers/any.d.ts +1 -1
- package/lib/helpers/index.cjs +4 -0
- package/lib/helpers/index.d.ts +2 -0
- package/lib/helpers/index.js +3 -1
- package/lib/helpers/object.d.ts +2 -2
- package/lib/helpers/omit.cjs +12 -0
- package/lib/helpers/omit.d.ts +7 -0
- package/lib/helpers/omit.js +11 -0
- package/lib/helpers/partial.d.ts +1 -1
- package/lib/helpers/sora.cjs +8 -0
- package/lib/helpers/sora.d.ts +2 -0
- package/lib/helpers/sora.js +7 -0
- package/lib/helpers/union.cjs +1 -1
- package/lib/helpers/union.js +1 -1
- package/lib/index.cjs +3 -0
- package/lib/index.js +3 -3
- package/lib/standard.cjs +8 -6
- package/lib/standard.d.ts +2 -1
- package/lib/standard.js +8 -6
- package/lib/standard.types.d.ts +5 -3
- package/lib/type.cjs +7 -1
- package/lib/type.d.ts +5 -1
- package/lib/type.js +7 -2
- package/lib/types.d.ts +25 -17
- package/package.json +15 -16
package/README.md
CHANGED
|
@@ -47,11 +47,16 @@ expectTypeOf(result).toEqualTypeOf<{
|
|
|
47
47
|
- `custom`: Custom type
|
|
48
48
|
- `intersection`: Intersection of types
|
|
49
49
|
- `litterals`: Literal types
|
|
50
|
+
- `object`: Object schema helper
|
|
51
|
+
- `omit`: Omit specific keys from an object
|
|
50
52
|
- `optional`: Optional types
|
|
51
53
|
- `partial`: Partial types
|
|
52
54
|
- `primitiveObject`: Primitive object schema
|
|
55
|
+
- `readonly`: Readonly object types
|
|
53
56
|
- `record`: Record types
|
|
54
57
|
- `soa`: Single or Array types
|
|
58
|
+
- `sora`: Single or Array types, with recursive support, (soa with
|
|
59
|
+
recursion)
|
|
55
60
|
- `sv`: State Value
|
|
56
61
|
- `tuple`: Tuple types
|
|
57
62
|
- `union`: Union types
|
package/lib/constants.cjs
CHANGED
|
@@ -23,7 +23,9 @@ const CUSTOM = "$$app-ts => custom$$";
|
|
|
23
23
|
const PARTIAL = "$$app-ts => partial$$";
|
|
24
24
|
const ARRAY = "$$app-ts => array$$";
|
|
25
25
|
const SOA = "$$app-ts => soa$$";
|
|
26
|
+
const SORA = "$$app-ts => sora$$";
|
|
26
27
|
const LITTERALS = "$$app-ts => litterals$$";
|
|
28
|
+
const STANDARD_KEY = "~standard";
|
|
27
29
|
//#endregion
|
|
28
30
|
exports.ARRAY = ARRAY;
|
|
29
31
|
exports.CUSTOM = CUSTOM;
|
|
@@ -33,4 +35,6 @@ exports.PARTIAL = PARTIAL;
|
|
|
33
35
|
exports.PRIMITIVES = PRIMITIVES;
|
|
34
36
|
exports.PRIMITIVE_OBJECTS = PRIMITIVE_OBJECTS;
|
|
35
37
|
exports.SOA = SOA;
|
|
38
|
+
exports.SORA = SORA;
|
|
39
|
+
exports.STANDARD_KEY = STANDARD_KEY;
|
|
36
40
|
exports.UNION = UNION;
|
package/lib/constants.d.ts
CHANGED
|
@@ -6,4 +6,6 @@ export declare const CUSTOM = "$$app-ts => custom$$";
|
|
|
6
6
|
export declare const PARTIAL = "$$app-ts => partial$$";
|
|
7
7
|
export declare const ARRAY = "$$app-ts => array$$";
|
|
8
8
|
export declare const SOA = "$$app-ts => soa$$";
|
|
9
|
+
export declare const SORA = "$$app-ts => sora$$";
|
|
9
10
|
export declare const LITTERALS = "$$app-ts => litterals$$";
|
|
11
|
+
export declare const STANDARD_KEY = "~standard";
|
package/lib/constants.js
CHANGED
|
@@ -22,6 +22,8 @@ const CUSTOM = "$$app-ts => custom$$";
|
|
|
22
22
|
const PARTIAL = "$$app-ts => partial$$";
|
|
23
23
|
const ARRAY = "$$app-ts => array$$";
|
|
24
24
|
const SOA = "$$app-ts => soa$$";
|
|
25
|
+
const SORA = "$$app-ts => sora$$";
|
|
25
26
|
const LITTERALS = "$$app-ts => litterals$$";
|
|
27
|
+
const STANDARD_KEY = "~standard";
|
|
26
28
|
//#endregion
|
|
27
|
-
export { ARRAY, CUSTOM, LITTERALS, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, UNION };
|
|
29
|
+
export { ARRAY, CUSTOM, LITTERALS, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, SORA, STANDARD_KEY, UNION };
|
package/lib/helpers/any.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NotReadonly, ObjectT } from '../types';
|
|
2
|
-
export declare const any: import("..").FnBasic<(<const T extends ObjectT = ObjectT>(value?: T) => ObjectT extends
|
|
2
|
+
export declare const any: import("..").FnBasic<(<const T extends ObjectT = ObjectT>(value?: T) => ObjectT extends T ? "any" : NotReadonly<T>), object & {
|
|
3
3
|
const: "any";
|
|
4
4
|
type: "any";
|
|
5
5
|
}>;
|
package/lib/helpers/index.cjs
CHANGED
|
@@ -13,14 +13,17 @@ const require_helpers_readonly = require("./readonly.cjs");
|
|
|
13
13
|
const require_helpers_object = require("./object.cjs");
|
|
14
14
|
const require_helpers_record = require("./record.cjs");
|
|
15
15
|
const require_helpers_soa = require("./soa.cjs");
|
|
16
|
+
const require_helpers_sora = require("./sora.cjs");
|
|
16
17
|
const require_helpers_sv = require("./sv.cjs");
|
|
17
18
|
const require_helpers_tuple = require("./tuple.cjs");
|
|
19
|
+
const require_helpers_omit = require("./omit.cjs");
|
|
18
20
|
exports.any = require_helpers_any.any;
|
|
19
21
|
exports.array = require_helpers_array.array;
|
|
20
22
|
exports.custom = require_helpers_custom.custom;
|
|
21
23
|
exports.intersection = require_helpers_intersection.intersection;
|
|
22
24
|
exports.litterals = require_helpers_litterals.litterals;
|
|
23
25
|
exports.object = require_helpers_object.object;
|
|
26
|
+
exports.omit = require_helpers_omit.omit;
|
|
24
27
|
exports.optional = require_helpers_optional.optional;
|
|
25
28
|
exports.partial = require_helpers_partial.partial;
|
|
26
29
|
exports.primitive = require_helpers_primitive.primitive;
|
|
@@ -28,6 +31,7 @@ exports.primitiveObject = require_helpers_primitiveObject.primitiveObject;
|
|
|
28
31
|
exports.readonly = require_helpers_readonly.readonly;
|
|
29
32
|
exports.record = require_helpers_record.record;
|
|
30
33
|
exports.soa = require_helpers_soa.soa;
|
|
34
|
+
exports.sora = require_helpers_sora.sora;
|
|
31
35
|
exports.sv = require_helpers_sv.sv;
|
|
32
36
|
exports.tuple = require_helpers_tuple.tuple;
|
|
33
37
|
exports.union = require_helpers_union.union;
|
package/lib/helpers/index.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ export * from './primitiveObject';
|
|
|
10
10
|
export * from './readonly';
|
|
11
11
|
export * from './record';
|
|
12
12
|
export * from './soa';
|
|
13
|
+
export * from './sora';
|
|
13
14
|
export * from './sv';
|
|
14
15
|
export * from './tuple';
|
|
15
16
|
export * from './union';
|
|
16
17
|
export * from './object';
|
|
18
|
+
export * from './omit';
|
package/lib/helpers/index.js
CHANGED
|
@@ -12,6 +12,8 @@ import { readonly } from "./readonly.js";
|
|
|
12
12
|
import { object } from "./object.js";
|
|
13
13
|
import { record } from "./record.js";
|
|
14
14
|
import { soa } from "./soa.js";
|
|
15
|
+
import { sora } from "./sora.js";
|
|
15
16
|
import { sv } from "./sv.js";
|
|
16
17
|
import { tuple } from "./tuple.js";
|
|
17
|
-
|
|
18
|
+
import { omit } from "./omit.js";
|
|
19
|
+
export { any, array, custom, intersection, litterals, object, omit, optional, partial, primitive, primitiveObject, readonly, record, soa, sora, sv, tuple, union };
|
package/lib/helpers/object.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NotReadonly, ObjectMapS } from
|
|
2
|
-
export declare const object: import("..").FnBasic<(<const T extends ObjectMapS>(value?: T) => ObjectMapS extends
|
|
1
|
+
import type { NotReadonly, ObjectMapS } from "../types";
|
|
2
|
+
export declare const object: import("..").FnBasic<(<const T extends ObjectMapS>(value?: T) => ObjectMapS extends T ? ObjectMapS : NotReadonly<T>), object & {
|
|
3
3
|
const: ObjectMapS;
|
|
4
4
|
type: ObjectMapS;
|
|
5
5
|
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
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");
|
|
5
|
+
//#region src/helpers/omit.ts
|
|
6
|
+
const omit = require_utils_expandFn.expandFn2((value, _) => {
|
|
7
|
+
return require_standard.standardize2(value);
|
|
8
|
+
}, require_utils_index._const(), { strict: (value, _) => {
|
|
9
|
+
return require_standard.standardize2(value);
|
|
10
|
+
} });
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.omit = omit;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Keys, NOmit, NotReadonly, ObjectMapS } from "../types";
|
|
2
|
+
export declare const omit: import("..").FnBasic<(<const T extends ObjectMapS, K extends Keys>(value: T, _: K) => ObjectMapS extends T ? ObjectMapS : Omit<NotReadonly<T>, K>), {
|
|
3
|
+
readonly strict: <const T extends ObjectMapS, const K extends keyof T = keyof T>(value: T, _: K) => ObjectMapS extends T ? ObjectMapS : NOmit<NotReadonly<T>, K>;
|
|
4
|
+
} & {
|
|
5
|
+
const: ObjectMapS;
|
|
6
|
+
type: ObjectMapS;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { standardize2 } from "../standard.js";
|
|
2
|
+
import { expandFn2 } from "../utils/expandFn.js";
|
|
3
|
+
import { _const } from "../utils/index.js";
|
|
4
|
+
//#region src/helpers/omit.ts
|
|
5
|
+
const omit = expandFn2((value, _) => {
|
|
6
|
+
return standardize2(value);
|
|
7
|
+
}, _const(), { strict: (value, _) => {
|
|
8
|
+
return standardize2(value);
|
|
9
|
+
} });
|
|
10
|
+
//#endregion
|
|
11
|
+
export { omit };
|
package/lib/helpers/partial.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { NotReadonly, ObjectT, PartialCustom } from '../types';
|
|
2
|
-
export declare const partial: <const T extends ObjectT>(value: T) => NotReadonly<T
|
|
2
|
+
export declare const partial: <const T extends ObjectT>(value: T) => PartialCustom<NotReadonly<T>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_standard = require("../standard.cjs");
|
|
3
|
+
//#region src/helpers/sora.ts
|
|
4
|
+
const sora = (value) => {
|
|
5
|
+
return require_standard.standardize2(value);
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.sora = sora;
|
package/lib/helpers/union.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_constants = require("../constants.cjs");
|
|
2
3
|
const require_standard = require("../standard.cjs");
|
|
3
4
|
const require_utils_expandFn = require("../utils/expandFn.cjs");
|
|
4
|
-
const require_constants = require("../constants.cjs");
|
|
5
5
|
//#region src/helpers/union.ts
|
|
6
6
|
const _union = (...values) => {
|
|
7
7
|
return require_standard.standardize2({ [require_constants.UNION]: values });
|
package/lib/helpers/union.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { UNION } from "../constants.js";
|
|
1
2
|
import { standardize2 } from "../standard.js";
|
|
2
3
|
import { expandFn } from "../utils/expandFn.js";
|
|
3
|
-
import { UNION } from "../constants.js";
|
|
4
4
|
//#region src/helpers/union.ts
|
|
5
5
|
const _union = (...values) => {
|
|
6
6
|
return standardize2({ [UNION]: values });
|
package/lib/index.cjs
CHANGED
|
@@ -9,5 +9,8 @@ exports.PARTIAL = require_constants.PARTIAL;
|
|
|
9
9
|
exports.PRIMITIVES = require_constants.PRIMITIVES;
|
|
10
10
|
exports.PRIMITIVE_OBJECTS = require_constants.PRIMITIVE_OBJECTS;
|
|
11
11
|
exports.SOA = require_constants.SOA;
|
|
12
|
+
exports.SORA = require_constants.SORA;
|
|
13
|
+
exports.STANDARD_KEY = require_constants.STANDARD_KEY;
|
|
12
14
|
exports.UNION = require_constants.UNION;
|
|
15
|
+
exports.pretype = require_type.pretype;
|
|
13
16
|
exports.type = require_type.type;
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ARRAY, CUSTOM, LITTERALS, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, UNION } from "./constants.js";
|
|
2
|
-
import { type } from "./type.js";
|
|
3
|
-
export { ARRAY, CUSTOM, LITTERALS, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, UNION, type };
|
|
1
|
+
import { ARRAY, CUSTOM, LITTERALS, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, SORA, STANDARD_KEY, UNION } from "./constants.js";
|
|
2
|
+
import { pretype, type } from "./type.js";
|
|
3
|
+
export { ARRAY, CUSTOM, LITTERALS, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, SORA, STANDARD_KEY, UNION, pretype, type };
|
package/lib/standard.cjs
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_constants = require("./constants.cjs");
|
|
2
3
|
//#region src/standard.ts
|
|
3
|
-
const _standardize = (
|
|
4
|
+
const _standardize = (__type) => {
|
|
4
5
|
return {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
__type,
|
|
7
|
+
type: __type,
|
|
8
|
+
[require_constants.STANDARD_KEY]: {
|
|
7
9
|
version: 1,
|
|
8
10
|
vendor: "@bemedev/typings",
|
|
9
11
|
types: {
|
|
10
|
-
input:
|
|
11
|
-
output:
|
|
12
|
+
input: __type,
|
|
13
|
+
output: __type
|
|
12
14
|
},
|
|
13
|
-
validate: () => ({ value })
|
|
15
|
+
validate: () => ({ value: __type })
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
};
|
package/lib/standard.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from './standard.types';
|
|
2
2
|
type Standardize_F = <T>(value: T) => {
|
|
3
|
-
|
|
3
|
+
__type: T;
|
|
4
|
+
type: T;
|
|
4
5
|
} & StandardSchemaV1<T, T>;
|
|
5
6
|
export declare const standardize: Standardize_F;
|
|
6
7
|
export declare const standardize2: <T>(value?: unknown) => T;
|
package/lib/standard.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import { STANDARD_KEY } from "./constants.js";
|
|
1
2
|
//#region src/standard.ts
|
|
2
|
-
const _standardize = (
|
|
3
|
+
const _standardize = (__type) => {
|
|
3
4
|
return {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
__type,
|
|
6
|
+
type: __type,
|
|
7
|
+
[STANDARD_KEY]: {
|
|
6
8
|
version: 1,
|
|
7
9
|
vendor: "@bemedev/typings",
|
|
8
10
|
types: {
|
|
9
|
-
input:
|
|
10
|
-
output:
|
|
11
|
+
input: __type,
|
|
12
|
+
output: __type
|
|
11
13
|
},
|
|
12
|
-
validate: () => ({ value })
|
|
14
|
+
validate: () => ({ value: __type })
|
|
13
15
|
}
|
|
14
16
|
};
|
|
15
17
|
};
|
package/lib/standard.types.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { STANDARD_KEY } from './constants';
|
|
2
|
+
export type StandardKey = typeof STANDARD_KEY;
|
|
1
3
|
/** The Standard Schema interface. */
|
|
2
4
|
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
3
5
|
/** The Standard Schema properties. */
|
|
4
|
-
readonly
|
|
6
|
+
readonly [STANDARD_KEY]: StandardSchemaV1.Props<Input, Output>;
|
|
5
7
|
}
|
|
6
8
|
export declare namespace StandardSchemaV1 {
|
|
7
9
|
/** The Standard Schema properties interface. */
|
|
@@ -53,7 +55,7 @@ export declare namespace StandardSchemaV1 {
|
|
|
53
55
|
readonly output: Output;
|
|
54
56
|
}
|
|
55
57
|
/** Infers the input type of a Standard Schema. */
|
|
56
|
-
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema[
|
|
58
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema[StandardKey]['types']>['input'];
|
|
57
59
|
/** Infers the output type of a Standard Schema. */
|
|
58
|
-
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema[
|
|
60
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema[StandardKey]['types']>['output'];
|
|
59
61
|
}
|
package/lib/type.cjs
CHANGED
|
@@ -14,8 +14,10 @@ const require_helpers_readonly = require("./helpers/readonly.cjs");
|
|
|
14
14
|
const require_helpers_object = require("./helpers/object.cjs");
|
|
15
15
|
const require_helpers_record = require("./helpers/record.cjs");
|
|
16
16
|
const require_helpers_soa = require("./helpers/soa.cjs");
|
|
17
|
+
const require_helpers_sora = require("./helpers/sora.cjs");
|
|
17
18
|
const require_helpers_sv = require("./helpers/sv.cjs");
|
|
18
19
|
const require_helpers_tuple = require("./helpers/tuple.cjs");
|
|
20
|
+
const require_helpers_omit = require("./helpers/omit.cjs");
|
|
19
21
|
require("./helpers/index.cjs");
|
|
20
22
|
//#region src/type.ts
|
|
21
23
|
const _transform = (obj) => {
|
|
@@ -30,6 +32,7 @@ const type = (option) => {
|
|
|
30
32
|
intersection: require_helpers_intersection.intersection,
|
|
31
33
|
litterals: require_helpers_litterals.litterals,
|
|
32
34
|
optional: require_helpers_optional.optional,
|
|
35
|
+
omit: require_helpers_omit.omit,
|
|
33
36
|
partial: require_helpers_partial.partial,
|
|
34
37
|
record: require_helpers_record.record,
|
|
35
38
|
soa: require_helpers_soa.soa,
|
|
@@ -40,10 +43,13 @@ const type = (option) => {
|
|
|
40
43
|
primitiveObject: require_helpers_primitiveObject.primitiveObject,
|
|
41
44
|
primitive: require_helpers_primitive.primitive,
|
|
42
45
|
readonly: require_helpers_readonly.readonly,
|
|
43
|
-
object: require_helpers_object.object
|
|
46
|
+
object: require_helpers_object.object,
|
|
47
|
+
sora: require_helpers_sora.sora
|
|
44
48
|
}));
|
|
45
49
|
else out = _transform(option);
|
|
46
50
|
return require_standard.standardize(out);
|
|
47
51
|
};
|
|
52
|
+
const pretype = () => type;
|
|
48
53
|
//#endregion
|
|
54
|
+
exports.pretype = pretype;
|
|
49
55
|
exports.type = type;
|
package/lib/type.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { inferSh, ObjectT } from './types';
|
|
2
|
-
import { any, array, custom, intersection, litterals, object, optional, partial, primitive, primitiveObject, readonly, record, soa, sv, tuple, union } from './helpers';
|
|
2
|
+
import { any, array, custom, intersection, litterals, object, omit, optional, partial, primitive, primitiveObject, readonly, record, soa, sv, tuple, union, sora } from './helpers';
|
|
3
3
|
type Helpers = {
|
|
4
4
|
any: typeof any;
|
|
5
5
|
custom: typeof custom;
|
|
@@ -17,7 +17,11 @@ type Helpers = {
|
|
|
17
17
|
primitive: typeof primitive;
|
|
18
18
|
readonly: typeof readonly;
|
|
19
19
|
object: typeof object;
|
|
20
|
+
omit: typeof omit;
|
|
21
|
+
sora: typeof sora;
|
|
20
22
|
};
|
|
21
23
|
export type Transform_F = <T extends ObjectT = ObjectT>(option?: ((helpers: Helpers) => T) | T) => inferSh<T>;
|
|
24
|
+
export type PreTransform = <U extends ObjectT>() => <T extends U = U>(option?: ((helpers: Helpers) => T) | T) => inferSh<T>;
|
|
22
25
|
export declare const type: Transform_F;
|
|
26
|
+
export declare const pretype: PreTransform;
|
|
23
27
|
export {};
|
package/lib/type.js
CHANGED
|
@@ -13,8 +13,10 @@ import { readonly } from "./helpers/readonly.js";
|
|
|
13
13
|
import { object } from "./helpers/object.js";
|
|
14
14
|
import { record } from "./helpers/record.js";
|
|
15
15
|
import { soa } from "./helpers/soa.js";
|
|
16
|
+
import { sora } from "./helpers/sora.js";
|
|
16
17
|
import { sv } from "./helpers/sv.js";
|
|
17
18
|
import { tuple } from "./helpers/tuple.js";
|
|
19
|
+
import { omit } from "./helpers/omit.js";
|
|
18
20
|
import "./helpers/index.js";
|
|
19
21
|
//#region src/type.ts
|
|
20
22
|
const _transform = (obj) => {
|
|
@@ -29,6 +31,7 @@ const type = (option) => {
|
|
|
29
31
|
intersection,
|
|
30
32
|
litterals,
|
|
31
33
|
optional,
|
|
34
|
+
omit,
|
|
32
35
|
partial,
|
|
33
36
|
record,
|
|
34
37
|
soa,
|
|
@@ -39,10 +42,12 @@ const type = (option) => {
|
|
|
39
42
|
primitiveObject,
|
|
40
43
|
primitive,
|
|
41
44
|
readonly,
|
|
42
|
-
object
|
|
45
|
+
object,
|
|
46
|
+
sora
|
|
43
47
|
}));
|
|
44
48
|
else out = _transform(option);
|
|
45
49
|
return standardize(out);
|
|
46
50
|
};
|
|
51
|
+
const pretype = () => type;
|
|
47
52
|
//#endregion
|
|
48
|
-
export { type };
|
|
53
|
+
export { pretype, type };
|
package/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ARRAY, CUSTOM, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, UNION } from
|
|
2
|
-
import type { StandardSchemaV1 } from
|
|
1
|
+
import type { ARRAY, CUSTOM, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, SORA, UNION } from "./constants";
|
|
2
|
+
import type { StandardKey, StandardSchemaV1 } from "./standard.types";
|
|
3
3
|
export type Ru = Record<Keys, unknown>;
|
|
4
|
+
type Equals<T, U> = T extends U ? (U extends T ? true : false) : false;
|
|
4
5
|
export type TrueObject = Ru & {
|
|
5
6
|
[Symbol.iterator]?: never;
|
|
6
7
|
};
|
|
@@ -27,21 +28,24 @@ export type SingleOrRecursiveArrayOf<T> = T | RecursiveArrayOf<T>;
|
|
|
27
28
|
export type SoRa<T> = SingleOrRecursiveArrayOf<T>;
|
|
28
29
|
export type Primitive = string | number | boolean | bigint | null | undefined | symbol | never;
|
|
29
30
|
export type PrimitiveT = (typeof PRIMITIVES)[number];
|
|
30
|
-
type TransformPrimitiveS<T extends PrimitiveT> = T extends
|
|
31
|
+
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;
|
|
31
32
|
export type Types = PrimitiveT | (typeof PRIMITIVE_OBJECTS)[number];
|
|
32
|
-
export type TransformTypes<T extends Types> = T extends PrimitiveT ? TransformPrimitiveS<T> : T extends
|
|
33
|
+
export type TransformTypes<T extends Types> = T extends PrimitiveT ? TransformPrimitiveS<T> : T extends "date" ? Date : T extends "any" ? any : T extends "unknown" ? unknown : object;
|
|
33
34
|
export type Custom<T = any> = {
|
|
34
35
|
[CUSTOM]: T;
|
|
35
36
|
};
|
|
36
37
|
export type SoaCustom<T extends ObjectT = ObjectT> = {
|
|
37
38
|
[SOA]: T;
|
|
38
39
|
};
|
|
40
|
+
export type SoRaCustom<T extends ObjectT = ObjectT> = {
|
|
41
|
+
[SORA]: T;
|
|
42
|
+
};
|
|
39
43
|
export type UnionCustom<T extends ObjectT[] = ObjectT[]> = {
|
|
40
44
|
[UNION]: T;
|
|
41
45
|
};
|
|
42
|
-
export
|
|
43
|
-
[PARTIAL]:
|
|
44
|
-
}
|
|
46
|
+
export interface PartialCustom<T extends ObjectT = ObjectT> {
|
|
47
|
+
[PARTIAL]: T;
|
|
48
|
+
}
|
|
45
49
|
export type __ObjectT = Types | ObjectMapS | Custom | PartialCustom | PrimitiveObjectT;
|
|
46
50
|
export type CanOptional = __ObjectT | ArrayCustom | AnyArray<__ObjectT>;
|
|
47
51
|
export type Optional<T extends __ObjectT | ArrayCustom | AnyArray<__ObjectT> = __ObjectT> = {
|
|
@@ -62,7 +66,7 @@ export type IntersectionCustom<T extends ObjectMapS[]> = T extends [
|
|
|
62
66
|
...infer Rest extends ObjectMapS[]
|
|
63
67
|
] ? First & IntersectionCustom<Rest> : unknown;
|
|
64
68
|
type _ObjectT = __ObjectT | Optional | ArrayCustom;
|
|
65
|
-
export type PrimitiveObjectT = SoRa<Types | PrimitiveObjectMapS | ArrayCustom<Types | PrimitiveObjectMapS> | Optional<Types | PrimitiveObjectMapS> | UnionCustom<Types[] | PrimitiveObjectMapS[]> |
|
|
69
|
+
export type PrimitiveObjectT = SoRa<Types | (PrimitiveObjectMapS & Partial<Record<typeof PARTIAL, never>>) | ArrayCustom<Types | PrimitiveObjectMapS> | Optional<Types | PrimitiveObjectMapS> | UnionCustom<Types[] | PrimitiveObjectMapS[]> | PartialCustom<PrimitiveObjectMapS>>;
|
|
66
70
|
export interface PrimitiveObjectMapS {
|
|
67
71
|
[key: Keys]: PrimitiveObjectT;
|
|
68
72
|
}
|
|
@@ -76,12 +80,14 @@ export type POS = ObjectT;
|
|
|
76
80
|
type ReduceTuple2<T extends AnyArray<ObjectT>> = T extends [
|
|
77
81
|
infer First,
|
|
78
82
|
...infer Rest extends AnyArray<ObjectT>
|
|
79
|
-
] ? [TransformT<First>, ...ReduceTuple2<Rest>] :
|
|
83
|
+
] ? [TransformT<First>, ...ReduceTuple2<Rest>] : [];
|
|
80
84
|
type ReduceTupleU<T extends AnyArray> = T extends [
|
|
81
85
|
infer First,
|
|
82
86
|
...infer Rest extends AnyArray
|
|
83
|
-
] ? [Undefiny<First>, ...ReduceTupleU<Rest>] : T[number] extends never ? [] : T[
|
|
84
|
-
type
|
|
87
|
+
] ? [Undefiny<First>, ...ReduceTupleU<Rest>] : T[number] extends never ? [] : T["length"] extends 0 ? [] : number extends T["length"] ? T : Undefiny<T[number]>[];
|
|
88
|
+
type EmptyObject = {};
|
|
89
|
+
type __TransformUnion<T extends UnionCustom> = T extends UnionCustom<infer TCustom> ? Omit<T, typeof UNION> extends infer Ot ? Equals<Ot, EmptyObject> extends true ? TransformT<TCustom[number]> : TransformT<TCustom[number]> & TransformT<Ot> : never : never;
|
|
90
|
+
type __TransformPrimitiveObject<T> = Equals<ObjectMapS, T> extends true ? object : T extends Types ? TransformTypes<T> : T extends ArrayCustom<infer A> ? TransformT<A>[] : T extends UnionCustom ? __TransformUnion<T> : T extends SoRaCustom<infer TSoA> ? SoRa<__TransformPrimitiveObject<TSoA>> : T extends SoaCustom<infer TSoA> ? SoA<__TransformPrimitiveObject<TSoA>> : T extends Custom<infer TCustom> ? TCustom : T extends AnyArray<ObjectT> ? ReduceTuple2<T> : T extends PartialCustom<infer TPartial> ? Partial<__TransformPrimitiveObject<TPartial>> : T extends Optional<infer TOptional> ? __TransformPrimitiveObject<TOptional> | OptionalHelperClass : {
|
|
85
91
|
[K in keyof T]: __TransformPrimitiveObject<T[K]>;
|
|
86
92
|
};
|
|
87
93
|
type HasUndefined<T> = unknown extends T ? false : OptionalHelperClass extends T ? true : false;
|
|
@@ -94,14 +100,16 @@ type UndefinyObject<T extends object> = {
|
|
|
94
100
|
} : never;
|
|
95
101
|
type Undefiny<T, U = Exclude<T, OptionalHelperClass>> = U extends AnyArray ? ReduceTupleU<U> : U extends Ru ? UndefinyObject<U> : U;
|
|
96
102
|
type TransformT<T> = Undefiny<__TransformPrimitiveObject<T>>;
|
|
97
|
-
export type StandardHelper<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
export type StandardHelper<T1 = any, T2 = any> = {
|
|
104
|
+
__type: T1;
|
|
105
|
+
type: T2;
|
|
106
|
+
} & StandardSchemaV1<T2, T2>;
|
|
107
|
+
type _Sh<T1 = any, T2 = any> = StandardHelper<T1, T2>;
|
|
108
|
+
export type Sh<T extends ObjectT> = StandardHelper<T, inferO<T>>;
|
|
101
109
|
export type StandardOutput<T = any> = StandardSchemaV1<any, T>;
|
|
102
110
|
export type inferO<T extends ObjectT = ObjectT> = ObjectT extends T ? unknown : TransformT<T>;
|
|
103
|
-
export type inferSh<T extends ObjectT = ObjectT> =
|
|
104
|
-
export type inferT<T extends StandardOutput = StandardOutput> = Exclude<T[
|
|
111
|
+
export type inferSh<T extends ObjectT = ObjectT> = _Sh<T, inferO<T>>;
|
|
112
|
+
export type inferT<T extends StandardOutput = StandardOutput> = Exclude<T[StandardKey]["types"], undefined>["output"];
|
|
105
113
|
export type ProduceObject<T extends ObjectT = ObjectT> = T;
|
|
106
114
|
export type FnBasic<Main extends Fn, Tr extends object> = Tr & Main;
|
|
107
115
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemedev/typings",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "Typings by variables",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "bri_lvi@icloud.com",
|
|
@@ -28,7 +28,10 @@
|
|
|
28
28
|
"types": "./lib/helpers/index.d.ts"
|
|
29
29
|
},
|
|
30
30
|
"./package.json": "./package.json",
|
|
31
|
-
"./tsconfig.json": "./tsconfig.json"
|
|
31
|
+
"./tsconfig.json": "./tsconfig.json",
|
|
32
|
+
"./types": {
|
|
33
|
+
"types": "./lib/index.d.ts"
|
|
34
|
+
}
|
|
32
35
|
},
|
|
33
36
|
"maintainers": [
|
|
34
37
|
{
|
|
@@ -100,28 +103,24 @@
|
|
|
100
103
|
}
|
|
101
104
|
],
|
|
102
105
|
"devDependencies": {
|
|
103
|
-
"@bemedev/dev-utils": "^0.
|
|
106
|
+
"@bemedev/dev-utils": "^0.7.0",
|
|
104
107
|
"@bemedev/fsf": "^1.0.1",
|
|
105
108
|
"@size-limit/file": "^12.1.0",
|
|
106
|
-
"@types/node": "^25.
|
|
107
|
-
"@vitest/coverage-v8": "^4.1.
|
|
108
|
-
"@vitest/ui": "4.1.
|
|
109
|
+
"@types/node": "^25.9.1",
|
|
110
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
111
|
+
"@vitest/ui": "4.1.7",
|
|
109
112
|
"glob": "^13.0.6",
|
|
110
|
-
"globals": "^17.
|
|
113
|
+
"globals": "^17.6.0",
|
|
111
114
|
"husky": "^9.1.7",
|
|
112
115
|
"onchange": "^7.1.0",
|
|
113
|
-
"oxfmt": "^0.
|
|
114
|
-
"oxlint": "^1.
|
|
116
|
+
"oxfmt": "^0.51.0",
|
|
117
|
+
"oxlint": "^1.66.0",
|
|
115
118
|
"pretty-quick": "^4.2.2",
|
|
116
|
-
"rolldown": "1.0.
|
|
119
|
+
"rolldown": "1.0.2",
|
|
117
120
|
"size-limit": "^12.1.0",
|
|
118
121
|
"tslib": "^2.8.1",
|
|
119
122
|
"typescript": "^6.0.3",
|
|
120
|
-
"vitest": "^4.1.
|
|
123
|
+
"vitest": "^4.1.7"
|
|
121
124
|
},
|
|
122
|
-
"
|
|
123
|
-
"onlyBuiltDependencies": [
|
|
124
|
-
"esbuild"
|
|
125
|
-
]
|
|
126
|
-
}
|
|
125
|
+
"packageManager": "pnpm@11.2.2+sha512.36e6621fad506178936455e70247b8808ef4ec25797a9f437a93281a020484e2607f6a469a22e982987c3dbb8866e3071514ab10a4a1749e06edcd1ec118436f"
|
|
127
126
|
}
|