@bemedev/typings 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/lib/constants.cjs +4 -2
  2. package/lib/constants.d.ts +7 -5
  3. package/lib/constants.js +3 -3
  4. package/lib/helpers/any.cjs +4 -5
  5. package/lib/helpers/any.d.ts +4 -2
  6. package/lib/helpers/any.js +5 -5
  7. package/lib/helpers/array.cjs +6 -6
  8. package/lib/helpers/array.d.ts +4 -2
  9. package/lib/helpers/array.js +6 -6
  10. package/lib/helpers/custom.cjs +21 -4
  11. package/lib/helpers/custom.d.ts +20 -3
  12. package/lib/helpers/custom.js +22 -4
  13. package/lib/helpers/index.cjs +4 -30
  14. package/lib/helpers/index.d.ts +1 -0
  15. package/lib/helpers/index.js +4 -25
  16. package/lib/helpers/intersection.cjs +2 -8
  17. package/lib/helpers/intersection.d.ts +1 -2
  18. package/lib/helpers/intersection.js +2 -8
  19. package/lib/helpers/litterals.cjs +7 -3
  20. package/lib/helpers/litterals.d.ts +4 -2
  21. package/lib/helpers/litterals.js +7 -3
  22. package/lib/helpers/object.cjs +10 -0
  23. package/lib/helpers/object.d.ts +5 -0
  24. package/lib/helpers/object.js +9 -0
  25. package/lib/helpers/optional.cjs +4 -4
  26. package/lib/helpers/optional.d.ts +2 -3
  27. package/lib/helpers/optional.js +4 -4
  28. package/lib/helpers/partial.cjs +2 -9
  29. package/lib/helpers/partial.d.ts +1 -2
  30. package/lib/helpers/partial.js +2 -9
  31. package/lib/helpers/primitive.cjs +21 -20
  32. package/lib/helpers/primitive.d.ts +25 -7
  33. package/lib/helpers/primitive.js +21 -21
  34. package/lib/helpers/primitiveObject.cjs +8 -7
  35. package/lib/helpers/primitiveObject.d.ts +8 -3
  36. package/lib/helpers/primitiveObject.js +8 -8
  37. package/lib/helpers/readonly.cjs +0 -2
  38. package/lib/helpers/readonly.js +0 -2
  39. package/lib/helpers/record.cjs +7 -6
  40. package/lib/helpers/record.d.ts +4 -2
  41. package/lib/helpers/record.js +7 -6
  42. package/lib/helpers/soa.cjs +2 -4
  43. package/lib/helpers/soa.d.ts +1 -2
  44. package/lib/helpers/soa.js +2 -4
  45. package/lib/helpers/sv.cjs +6 -3
  46. package/lib/helpers/sv.d.ts +4 -2
  47. package/lib/helpers/sv.js +6 -3
  48. package/lib/helpers/tuple.cjs +6 -3
  49. package/lib/helpers/tuple.d.ts +4 -2
  50. package/lib/helpers/tuple.js +6 -3
  51. package/lib/helpers/union.cjs +3 -3
  52. package/lib/helpers/union.d.ts +2 -2
  53. package/lib/helpers/union.js +3 -3
  54. package/lib/index.cjs +2 -9
  55. package/lib/index.d.ts +0 -1
  56. package/lib/index.js +2 -4
  57. package/lib/standard.cjs +21 -0
  58. package/lib/standard.d.ts +7 -0
  59. package/lib/standard.js +19 -0
  60. package/lib/standard.types.d.ts +59 -0
  61. package/lib/type.cjs +49 -0
  62. package/lib/type.js +48 -0
  63. package/lib/type.types.d.ts +3 -2
  64. package/lib/types.cjs +0 -0
  65. package/lib/types.d.ts +13 -6
  66. package/lib/types.js +1 -0
  67. package/lib/utils/expandFn.cjs +8 -2
  68. package/lib/utils/expandFn.d.ts +5 -1
  69. package/lib/utils/expandFn.js +8 -3
  70. package/lib/utils/index.cjs +8 -0
  71. package/lib/utils/index.d.ts +3 -0
  72. package/lib/utils/index.js +5 -0
  73. package/package.json +16 -2
  74. package/lib/_virtual/_rolldown/runtime.cjs +0 -13
  75. package/lib/_virtual/_rolldown/runtime.js +0 -13
  76. package/lib/constants.cjs.map +0 -1
  77. package/lib/constants.js.map +0 -1
  78. package/lib/helpers/any.cjs.map +0 -1
  79. package/lib/helpers/any.js.map +0 -1
  80. package/lib/helpers/array.cjs.map +0 -1
  81. package/lib/helpers/array.js.map +0 -1
  82. package/lib/helpers/custom.cjs.map +0 -1
  83. package/lib/helpers/custom.js.map +0 -1
  84. package/lib/helpers/index.cjs.map +0 -1
  85. package/lib/helpers/index.js.map +0 -1
  86. package/lib/helpers/intersection.cjs.map +0 -1
  87. package/lib/helpers/intersection.js.map +0 -1
  88. package/lib/helpers/litterals.cjs.map +0 -1
  89. package/lib/helpers/litterals.js.map +0 -1
  90. package/lib/helpers/optional.cjs.map +0 -1
  91. package/lib/helpers/optional.js.map +0 -1
  92. package/lib/helpers/partial.cjs.map +0 -1
  93. package/lib/helpers/partial.js.map +0 -1
  94. package/lib/helpers/primitive.cjs.map +0 -1
  95. package/lib/helpers/primitive.js.map +0 -1
  96. package/lib/helpers/primitiveObject.cjs.map +0 -1
  97. package/lib/helpers/primitiveObject.js.map +0 -1
  98. package/lib/helpers/readonly.cjs.map +0 -1
  99. package/lib/helpers/readonly.js.map +0 -1
  100. package/lib/helpers/record.cjs.map +0 -1
  101. package/lib/helpers/record.js.map +0 -1
  102. package/lib/helpers/soa.cjs.map +0 -1
  103. package/lib/helpers/soa.js.map +0 -1
  104. package/lib/helpers/sv.cjs.map +0 -1
  105. package/lib/helpers/sv.js.map +0 -1
  106. package/lib/helpers/tuple.cjs.map +0 -1
  107. package/lib/helpers/tuple.js.map +0 -1
  108. package/lib/helpers/union.cjs.map +0 -1
  109. package/lib/helpers/union.js.map +0 -1
  110. package/lib/utils/expandFn.cjs.map +0 -1
  111. package/lib/utils/expandFn.js.map +0 -1
@@ -1,25 +1,25 @@
1
- import { expandFn } from "../utils/expandFn.js";
1
+ import { standardize2 } from "../standard.js";
2
+ import { expandFn2 } from "../utils/expandFn.js";
3
+ import { _const } from "../utils/index.js";
2
4
  //#region src/helpers/primitive.ts
3
- const primitive = expandFn((value) => value, {
4
- boolean: (value) => {
5
- return value;
6
- },
7
- string: (value) => {
8
- return value;
9
- },
10
- number: (value) => {
11
- return value;
12
- },
13
- bigint: (value) => {
14
- return value;
15
- },
16
- symbol: (value) => {
17
- return value;
18
- },
19
- never: () => {},
20
- undefined: () => {}
5
+ const primitive = expandFn2((value) => standardize2(value), _const(), {
6
+ boolean: expandFn2((value) => {
7
+ return standardize2(value);
8
+ }, "boolean"),
9
+ string: expandFn2((value) => {
10
+ return standardize2(value);
11
+ }, "string"),
12
+ number: expandFn2((value) => {
13
+ return standardize2(value);
14
+ }, "number"),
15
+ bigint: expandFn2((value) => {
16
+ return standardize2(value);
17
+ }, "bigint"),
18
+ symbol: expandFn2((value) => {
19
+ return standardize2(value);
20
+ }, "symbol"),
21
+ never: standardize2(),
22
+ undefined: standardize2()
21
23
  });
22
24
  //#endregion
23
25
  export { primitive };
24
-
25
- //# sourceMappingURL=primitive.js.map
@@ -1,11 +1,12 @@
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/primitiveObject.ts
3
- const primitiveObject = require("../utils/expandFn.cjs").expandFn((value) => {
4
- return value || {};
5
- }, { map: (value) => {
6
- return value || {};
7
- } });
6
+ const primitiveObject = require_utils_expandFn.expandFn2((value) => {
7
+ return require_standard.standardize2(value);
8
+ }, require_utils_index._const(), { map: require_utils_expandFn.expandFn2((value) => {
9
+ return require_standard.standardize2(value);
10
+ }, require_utils_index._const()) });
8
11
  //#endregion
9
12
  exports.primitiveObject = primitiveObject;
10
-
11
- //# sourceMappingURL=primitiveObject.cjs.map
@@ -1,5 +1,10 @@
1
1
  import type { IntersectionCustom, NotReadonly, PrimitiveObjectMapS, PrimitiveObjectT } from "../types";
2
- declare const primitiveObject: import("..").FnBasic<(<const T extends PrimitiveObjectT | IntersectionCustom<PrimitiveObjectMapS[]> = PrimitiveObjectT>(value?: T) => NotReadonly<T>), {
3
- readonly map: <const T extends PrimitiveObjectMapS | IntersectionCustom<PrimitiveObjectMapS[]> = PrimitiveObjectMapS>(value?: T) => NotReadonly<T>;
2
+ export declare const primitiveObject: import("..").FnBasic<(<const T extends PrimitiveObjectT | IntersectionCustom<PrimitiveObjectMapS[]> = PrimitiveObjectT>(value?: T) => NotReadonly<T>), {
3
+ readonly map: import("..").FnBasic<(<const T extends PrimitiveObjectMapS | IntersectionCustom<PrimitiveObjectMapS[]> = PrimitiveObjectMapS>(value?: T) => NotReadonly<T>), object & {
4
+ const: PrimitiveObjectMapS;
5
+ type: PrimitiveObjectMapS;
6
+ }>;
7
+ } & {
8
+ const: PrimitiveObjectT;
9
+ type: PrimitiveObjectT;
4
10
  }>;
5
- export { primitiveObject };
@@ -1,11 +1,11 @@
1
- import { expandFn } from "../utils/expandFn.js";
1
+ import { standardize2 } from "../standard.js";
2
+ import { expandFn2 } from "../utils/expandFn.js";
3
+ import { _const } from "../utils/index.js";
2
4
  //#region src/helpers/primitiveObject.ts
3
- const primitiveObject = expandFn((value) => {
4
- return value || {};
5
- }, { map: (value) => {
6
- return value || {};
7
- } });
5
+ const primitiveObject = expandFn2((value) => {
6
+ return standardize2(value);
7
+ }, _const(), { map: expandFn2((value) => {
8
+ return standardize2(value);
9
+ }, _const()) });
8
10
  //#endregion
9
11
  export { primitiveObject };
10
-
11
- //# sourceMappingURL=primitiveObject.js.map
@@ -3,5 +3,3 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const readonly = (value) => value;
4
4
  //#endregion
5
5
  exports.readonly = readonly;
6
-
7
- //# sourceMappingURL=readonly.cjs.map
@@ -2,5 +2,3 @@
2
2
  const readonly = (value) => value;
3
3
  //#endregion
4
4
  export { readonly };
5
-
6
- //# sourceMappingURL=readonly.js.map
@@ -1,12 +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;
11
-
12
- //# sourceMappingURL=record.cjs.map
@@ -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 ? Keys : K[number], V>;
3
- export { record };
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
+ }>;
@@ -1,11 +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 };
10
-
11
- //# sourceMappingURL=record.js.map
@@ -1,10 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_constants = require("../constants.cjs");
2
+ const require_standard = require("../standard.cjs");
3
3
  //#region src/helpers/soa.ts
4
4
  const soa = (value) => {
5
- return { [require_constants.SOA]: value };
5
+ return require_standard.standardize2(value);
6
6
  };
7
7
  //#endregion
8
8
  exports.soa = soa;
9
-
10
- //# sourceMappingURL=soa.cjs.map
@@ -1,3 +1,2 @@
1
1
  import type { NotReadonly, ObjectT, SoaCustom } from "../types";
2
- declare const soa: <const T extends ObjectT>(value: T) => SoaCustom<NotReadonly<T>>;
3
- export { soa };
2
+ export declare const soa: <const T extends ObjectT>(value?: T) => ObjectT extends NotReadonly<T> ? "any" : SoaCustom<NotReadonly<T>>;
@@ -1,9 +1,7 @@
1
- import { SOA } from "../constants.js";
1
+ import { standardize2 } from "../standard.js";
2
2
  //#region src/helpers/soa.ts
3
3
  const soa = (value) => {
4
- return { [SOA]: value };
4
+ return standardize2(value);
5
5
  };
6
6
  //#endregion
7
7
  export { soa };
8
-
9
- //# sourceMappingURL=soa.js.map
@@ -1,7 +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;
6
-
7
- //# sourceMappingURL=sv.cjs.map
@@ -1,3 +1,5 @@
1
1
  import type { Custom, StateValue } from "../types";
2
- declare const sv: Custom<StateValue>;
3
- export { sv };
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,6 +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 };
5
-
6
- //# sourceMappingURL=sv.js.map
@@ -1,7 +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) => 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;
6
-
7
- //# sourceMappingURL=tuple.cjs.map
@@ -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
- export { tuple };
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
+ }>;
@@ -1,6 +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) => values;
5
+ const tuple = expandFn2((...values) => {
6
+ return standardize2(values);
7
+ }, array.type);
3
8
  //#endregion
4
9
  export { tuple };
5
-
6
- //# sourceMappingURL=tuple.js.map
@@ -1,11 +1,11 @@
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 values[0];
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
9
11
  exports.union = union;
10
-
11
- //# sourceMappingURL=union.cjs.map
@@ -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 { union };
6
+ export {};
@@ -1,10 +1,10 @@
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 values[0];
6
+ return standardize2({ [UNION]: values });
5
7
  };
6
8
  const union = expandFn(_union, { discriminated: (_key, ...values) => _union(...values) });
7
9
  //#endregion
8
10
  export { union };
9
-
10
- //# sourceMappingURL=union.js.map
package/lib/index.cjs CHANGED
@@ -1,20 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_types = require("./types.cjs");
3
2
  const require_constants = require("./constants.cjs");
4
- const require_helpers_index = require("./helpers/index.cjs");
5
3
  const require_type = require("./type.cjs");
6
4
  exports.ARRAY = require_constants.ARRAY;
7
5
  exports.CUSTOM = require_constants.CUSTOM;
6
+ exports.LITTERALS = require_constants.LITTERALS;
8
7
  exports.OPTIONAL = require_constants.OPTIONAL;
9
- exports.OptionalHelperClass = require_types.OptionalHelperClass;
10
8
  exports.PARTIAL = require_constants.PARTIAL;
11
9
  exports.PRIMITIVES = require_constants.PRIMITIVES;
12
10
  exports.PRIMITIVE_OBJECTS = require_constants.PRIMITIVE_OBJECTS;
13
11
  exports.SOA = require_constants.SOA;
14
- Object.defineProperty(exports, "helpers", {
15
- enumerable: true,
16
- get: function() {
17
- return require_helpers_index.helpers_exports;
18
- }
19
- });
12
+ exports.UNION = require_constants.UNION;
20
13
  exports.type = require_type.type;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./constants";
2
- export * as helpers from "./helpers";
3
2
  export * from "./type";
4
3
  export * from "./types";
package/lib/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import { OptionalHelperClass } from "./types.js";
2
- import { ARRAY, CUSTOM, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA } from "./constants.js";
3
- import { helpers_exports } from "./helpers/index.js";
1
+ import { ARRAY, CUSTOM, LITTERALS, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, UNION } from "./constants.js";
4
2
  import { type } from "./type.js";
5
- export { ARRAY, CUSTOM, OPTIONAL, OptionalHelperClass, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, helpers_exports as helpers, type };
3
+ export { ARRAY, CUSTOM, LITTERALS, OPTIONAL, PARTIAL, PRIMITIVES, PRIMITIVE_OBJECTS, SOA, UNION, type };
@@ -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 {};
@@ -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 ADDED
@@ -0,0 +1,49 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_standard = require("./standard.cjs");
3
+ const require_helpers_any = require("./helpers/any.cjs");
4
+ const require_helpers_array = require("./helpers/array.cjs");
5
+ const require_helpers_custom = require("./helpers/custom.cjs");
6
+ const require_helpers_intersection = require("./helpers/intersection.cjs");
7
+ const require_helpers_union = require("./helpers/union.cjs");
8
+ const require_helpers_litterals = require("./helpers/litterals.cjs");
9
+ const require_helpers_optional = require("./helpers/optional.cjs");
10
+ const require_helpers_partial = require("./helpers/partial.cjs");
11
+ const require_helpers_primitive = require("./helpers/primitive.cjs");
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");
15
+ const require_helpers_record = require("./helpers/record.cjs");
16
+ const require_helpers_soa = require("./helpers/soa.cjs");
17
+ const require_helpers_sv = require("./helpers/sv.cjs");
18
+ const require_helpers_tuple = require("./helpers/tuple.cjs");
19
+ require("./helpers/index.cjs");
20
+ //#region src/type.ts
21
+ const _transform = (obj) => {
22
+ return obj;
23
+ };
24
+ const type = (option) => {
25
+ let out;
26
+ if (!option) out = option;
27
+ else if (typeof option === "function") out = _transform(option({
28
+ any: require_helpers_any.any,
29
+ custom: require_helpers_custom.custom,
30
+ intersection: require_helpers_intersection.intersection,
31
+ litterals: require_helpers_litterals.litterals,
32
+ optional: require_helpers_optional.optional,
33
+ partial: require_helpers_partial.partial,
34
+ record: require_helpers_record.record,
35
+ soa: require_helpers_soa.soa,
36
+ sv: require_helpers_sv.sv,
37
+ union: require_helpers_union.union,
38
+ array: require_helpers_array.array,
39
+ tuple: require_helpers_tuple.tuple,
40
+ primitiveObject: require_helpers_primitiveObject.primitiveObject,
41
+ primitive: require_helpers_primitive.primitive,
42
+ readonly: require_helpers_readonly.readonly,
43
+ object: require_helpers_object.object
44
+ }));
45
+ else out = _transform(option);
46
+ return require_standard.standardize(out);
47
+ };
48
+ //#endregion
49
+ exports.type = type;
package/lib/type.js ADDED
@@ -0,0 +1,48 @@
1
+ import { standardize } from "./standard.js";
2
+ import { any } from "./helpers/any.js";
3
+ import { array } from "./helpers/array.js";
4
+ import { custom } from "./helpers/custom.js";
5
+ import { intersection } from "./helpers/intersection.js";
6
+ import { union } from "./helpers/union.js";
7
+ import { litterals } from "./helpers/litterals.js";
8
+ import { optional } from "./helpers/optional.js";
9
+ import { partial } from "./helpers/partial.js";
10
+ import { primitive } from "./helpers/primitive.js";
11
+ import { primitiveObject } from "./helpers/primitiveObject.js";
12
+ import { readonly } from "./helpers/readonly.js";
13
+ import { object } from "./helpers/object.js";
14
+ import { record } from "./helpers/record.js";
15
+ import { soa } from "./helpers/soa.js";
16
+ import { sv } from "./helpers/sv.js";
17
+ import { tuple } from "./helpers/tuple.js";
18
+ import "./helpers/index.js";
19
+ //#region src/type.ts
20
+ const _transform = (obj) => {
21
+ return obj;
22
+ };
23
+ const type = (option) => {
24
+ let out;
25
+ if (!option) out = option;
26
+ else if (typeof option === "function") out = _transform(option({
27
+ any,
28
+ custom,
29
+ intersection,
30
+ litterals,
31
+ optional,
32
+ partial,
33
+ record,
34
+ soa,
35
+ sv,
36
+ union,
37
+ array,
38
+ tuple,
39
+ primitiveObject,
40
+ primitive,
41
+ readonly,
42
+ object
43
+ }));
44
+ else out = _transform(option);
45
+ return standardize(out);
46
+ };
47
+ //#endregion
48
+ export { type };
@@ -1,5 +1,5 @@
1
- import type { inferT, ObjectT } from "./types";
2
- import type { any, array, custom, intersection, litterals, optional, partial, primitive, primitiveObject, readonly, record, soa, sv, tuple, union } from "./helpers";
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, inferT } 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
21
  export type Transform_F = <T extends ObjectT = ObjectT>(option?: ((helpers: Helpers) => T) | T) => inferT<T>;
package/lib/types.cjs ADDED
File without changes
package/lib/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
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,9 +25,9 @@ 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 Primiive = string | number | boolean | bigint | null | undefined | symbol | never;
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 "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 : Primiive;
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
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> = {
@@ -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
  };
@@ -48,7 +50,7 @@ export type ArrayCustom<T extends ObjectT = any> = {
48
50
  export type ObjectMapS = {
49
51
  [key: Keys]: SoRa<_ObjectT>;
50
52
  };
51
- export declare class OptionalHelperClass {
53
+ declare class OptionalHelperClass {
52
54
  readonly __NO_TYPE__ = "@bemedev/addons/NO_TYPE";
53
55
  private constructor();
54
56
  }
@@ -66,7 +68,7 @@ export interface PrimitiveObjectMapS {
66
68
  *
67
69
  * @remark
68
70
  */
69
- export type ObjectT = SoRa<_ObjectT | PrimitiveObjectT>;
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,
@@ -89,6 +91,11 @@ 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 inferT<T extends ObjectT = ObjectT> = ObjectT extends T ? unknown : TransformT<T>;
94
+ export type StandardHelper<T = any> = {
95
+ value: T;
96
+ } & StandardSchemaV1<T, T>;
97
+ export type Sh<T = any> = StandardHelper<T>;
98
+ export type inferT<T extends ObjectT = ObjectT> = ObjectT extends T ? Sh<unknown> : Sh<TransformT<T>>;
99
+ export type infer<T extends Sh> = T["value"];
93
100
  export type FnBasic<Main extends Fn, Tr extends object> = Tr & Main;
94
101
  export {};