@nmtjs/type 0.6.4 → 0.7.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 (76) hide show
  1. package/dist/index.js +31 -31
  2. package/dist/index.js.map +1 -1
  3. package/dist/temporal.js +7 -8
  4. package/dist/temporal.js.map +1 -1
  5. package/dist/types/any.js +4 -4
  6. package/dist/types/any.js.map +1 -1
  7. package/dist/types/array.js +23 -23
  8. package/dist/types/array.js.map +1 -1
  9. package/dist/types/base.js +65 -66
  10. package/dist/types/base.js.map +1 -1
  11. package/dist/types/boolean.js +4 -4
  12. package/dist/types/boolean.js.map +1 -1
  13. package/dist/types/custom.js +10 -9
  14. package/dist/types/custom.js.map +1 -1
  15. package/dist/types/date.js +6 -13
  16. package/dist/types/date.js.map +1 -1
  17. package/dist/types/enum.js +7 -16
  18. package/dist/types/enum.js.map +1 -1
  19. package/dist/types/literal.js +7 -6
  20. package/dist/types/literal.js.map +1 -1
  21. package/dist/types/never.js +4 -4
  22. package/dist/types/never.js.map +1 -1
  23. package/dist/types/number.js +26 -93
  24. package/dist/types/number.js.map +1 -1
  25. package/dist/types/object.js +42 -31
  26. package/dist/types/object.js.map +1 -1
  27. package/dist/types/string.js +31 -47
  28. package/dist/types/string.js.map +1 -1
  29. package/dist/types/temporal.js +40 -41
  30. package/dist/types/temporal.js.map +1 -1
  31. package/dist/types/union.js +25 -18
  32. package/dist/types/union.js.map +1 -1
  33. package/dist/utils.js +0 -1
  34. package/dist/utils.js.map +1 -1
  35. package/package.json +7 -19
  36. package/src/index.ts +24 -25
  37. package/src/temporal.ts +8 -8
  38. package/src/types/any.ts +5 -3
  39. package/src/types/array.ts +24 -22
  40. package/src/types/base.ts +148 -81
  41. package/src/types/boolean.ts +5 -3
  42. package/src/types/custom.ts +43 -24
  43. package/src/types/date.ts +17 -16
  44. package/src/types/enum.ts +12 -22
  45. package/src/types/literal.ts +9 -6
  46. package/src/types/never.ts +5 -3
  47. package/src/types/number.ts +31 -93
  48. package/src/types/object.ts +44 -37
  49. package/src/types/string.ts +41 -39
  50. package/src/types/temporal.ts +72 -32
  51. package/src/types/union.ts +59 -50
  52. package/src/utils.ts +22 -22
  53. package/dist/compiler.js +0 -55
  54. package/dist/compiler.js.map +0 -1
  55. package/dist/formats.js +0 -127
  56. package/dist/formats.js.map +0 -1
  57. package/dist/inference.js +0 -1
  58. package/dist/inference.js.map +0 -1
  59. package/dist/parse.js +0 -145
  60. package/dist/parse.js.map +0 -1
  61. package/dist/runtime.js +0 -73
  62. package/dist/runtime.js.map +0 -1
  63. package/dist/schemas/default.js +0 -6
  64. package/dist/schemas/default.js.map +0 -1
  65. package/dist/schemas/discriminated-union.js +0 -9
  66. package/dist/schemas/discriminated-union.js.map +0 -1
  67. package/dist/schemas/nullable.js +0 -11
  68. package/dist/schemas/nullable.js.map +0 -1
  69. package/src/compiler.ts +0 -100
  70. package/src/formats.ts +0 -182
  71. package/src/inference.ts +0 -128
  72. package/src/parse.ts +0 -217
  73. package/src/runtime.ts +0 -137
  74. package/src/schemas/default.ts +0 -12
  75. package/src/schemas/discriminated-union.ts +0 -49
  76. package/src/schemas/nullable.ts +0 -20
@@ -1,97 +1,30 @@
1
- import { Type } from '@sinclair/typebox';
1
+ import { gt, gte, int, lt, lte, number } from "@zod/mini";
2
2
  import { BaseType } from "./base.js";
3
3
  export class NumberType extends BaseType {
4
- static factory(options = {}) {
5
- return new NumberType(Type.Number(options), {
6
- options
7
- });
8
- }
9
- positive() {
10
- return this.min(0, true);
11
- }
12
- negative() {
13
- return this.max(0, true);
14
- }
15
- max(value, exclusive) {
16
- return NumberType.factory({
17
- ...this.props.options,
18
- maximum: value,
19
- ...!exclusive ? {} : {
20
- exclusiveMaximum: value
21
- }
22
- });
23
- }
24
- min(value, exclusive) {
25
- return NumberType.factory({
26
- ...this.props.options,
27
- minimum: value,
28
- ...!exclusive ? {} : {
29
- exclusiveMinimum: value
30
- }
31
- });
32
- }
4
+ static factory(...checks) {
5
+ return new NumberType({ encodedZodType: number().check(...checks) });
6
+ }
7
+ positive() {
8
+ return NumberType.factory(...this.props.checks, gte(0));
9
+ }
10
+ negative() {
11
+ return NumberType.factory(...this.props.checks, lte(0));
12
+ }
13
+ lt(value) {
14
+ return NumberType.factory(...this.props.checks, lt(value));
15
+ }
16
+ lte(value) {
17
+ return NumberType.factory(...this.props.checks, lte(value));
18
+ }
19
+ gte(value) {
20
+ return NumberType.factory(...this.props.checks, gte(value));
21
+ }
22
+ gt(value) {
23
+ return NumberType.factory(...this.props.checks, gt(value));
24
+ }
33
25
  }
34
- export class IntegerType extends BaseType {
35
- static factory(options = {}) {
36
- return new IntegerType(Type.Integer(options), {
37
- options
38
- });
39
- }
40
- positive() {
41
- return this.min(0, true);
42
- }
43
- negative() {
44
- return this.max(0, true);
45
- }
46
- max(value, exclusive) {
47
- return IntegerType.factory({
48
- ...this.props.options,
49
- maximum: value,
50
- ...!exclusive ? {} : {
51
- exclusiveMaximum: value
52
- }
53
- });
54
- }
55
- min(value, exclusive) {
56
- return IntegerType.factory({
57
- ...this.props.options,
58
- minimum: value,
59
- ...!exclusive ? {} : {
60
- exclusiveMinimum: value
61
- }
62
- });
63
- }
64
- }
65
- export class BigIntType extends BaseType {
66
- static factory(options = {}) {
67
- return new BigIntType(Type.BigInt(options), {
68
- options
69
- }, {
70
- encode: (value)=>`${value}`
71
- });
72
- }
73
- positive() {
74
- return this.min(0n, true);
75
- }
76
- negative() {
77
- return this.max(0n, true);
78
- }
79
- max(value, exclusive) {
80
- return BigIntType.factory({
81
- ...this.props.options,
82
- maximum: value,
83
- ...!exclusive ? {} : {
84
- exclusiveMaximum: value
85
- }
86
- });
87
- }
88
- min(value, exclusive) {
89
- return BigIntType.factory({
90
- ...this.props.options,
91
- minimum: value,
92
- ...!exclusive ? {} : {
93
- exclusiveMinimum: value
94
- }
95
- });
96
- }
26
+ export class IntegerType extends NumberType {
27
+ static factory(...checks) {
28
+ return NumberType.factory(...checks, int());
29
+ }
97
30
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/number.ts"],"sourcesContent":["import {\n type BigIntOptions,\n type IntegerOptions,\n type NumberOptions,\n type TBigInt,\n type TInteger,\n type TNumber,\n Type,\n} from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class NumberType extends BaseType<\n TNumber,\n { options: NumberOptions },\n number\n> {\n static factory(options: NumberOptions = {}) {\n return new NumberType(Type.Number(options), { options })\n }\n\n positive() {\n return this.min(0, true)\n }\n\n negative() {\n return this.max(0, true)\n }\n\n max(value: number, exclusive?: true) {\n return NumberType.factory({\n ...this.props.options,\n maximum: value,\n ...(!exclusive ? {} : { exclusiveMaximum: value }),\n })\n }\n\n min(value: number, exclusive?: true) {\n return NumberType.factory({\n ...this.props.options,\n minimum: value,\n ...(!exclusive ? {} : { exclusiveMinimum: value }),\n })\n }\n}\n\nexport class IntegerType extends BaseType<\n TInteger,\n { options: IntegerOptions },\n number\n> {\n static factory(options: IntegerOptions = {}) {\n return new IntegerType(Type.Integer(options), { options })\n }\n\n positive() {\n return this.min(0, true)\n }\n\n negative() {\n return this.max(0, true)\n }\n\n max(value: number, exclusive?: true) {\n return IntegerType.factory({\n ...this.props.options,\n maximum: value,\n ...(!exclusive ? {} : { exclusiveMaximum: value }),\n })\n }\n\n min(value: number, exclusive?: true) {\n return IntegerType.factory({\n ...this.props.options,\n minimum: value,\n ...(!exclusive ? {} : { exclusiveMinimum: value }),\n })\n }\n}\n\n// TODO: this is not json schema compatible\nexport class BigIntType extends BaseType<\n TBigInt,\n { options: BigIntOptions },\n bigint\n> {\n static factory(options: BigIntOptions = {}) {\n return new BigIntType(\n Type.BigInt(options),\n { options },\n { encode: (value) => `${value}` },\n )\n }\n\n positive() {\n return this.min(0n, true)\n }\n\n negative() {\n return this.max(0n, true)\n }\n\n max(value: bigint, exclusive?: true) {\n return BigIntType.factory({\n ...this.props.options,\n maximum: value,\n ...(!exclusive ? {} : { exclusiveMaximum: value }),\n })\n }\n\n min(value: bigint, exclusive?: true) {\n return BigIntType.factory({\n ...this.props.options,\n minimum: value,\n ...(!exclusive ? {} : { exclusiveMinimum: value }),\n })\n }\n}\n"],"names":["Type","BaseType","NumberType","factory","options","Number","positive","min","negative","max","value","exclusive","props","maximum","exclusiveMaximum","minimum","exclusiveMinimum","IntegerType","Integer","BigIntType","BigInt","encode"],"mappings":"AAAA,SAOEA,IAAI,QACC,oBAAmB;AAC1B,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAAmBD;IAK9B,OAAOE,QAAQC,UAAyB,CAAC,CAAC,EAAE;QAC1C,OAAO,IAAIF,WAAWF,KAAKK,MAAM,CAACD,UAAU;YAAEA;QAAQ;IACxD;IAEAE,WAAW;QACT,OAAO,IAAI,CAACC,GAAG,CAAC,GAAG;IACrB;IAEAC,WAAW;QACT,OAAO,IAAI,CAACC,GAAG,CAAC,GAAG;IACrB;IAEAA,IAAIC,KAAa,EAAEC,SAAgB,EAAE;QACnC,OAAOT,WAAWC,OAAO,CAAC;YACxB,GAAG,IAAI,CAACS,KAAK,CAACR,OAAO;YACrBS,SAASH;YACT,GAAI,CAACC,YAAY,CAAC,IAAI;gBAAEG,kBAAkBJ;YAAM,CAAC;QACnD;IACF;IAEAH,IAAIG,KAAa,EAAEC,SAAgB,EAAE;QACnC,OAAOT,WAAWC,OAAO,CAAC;YACxB,GAAG,IAAI,CAACS,KAAK,CAACR,OAAO;YACrBW,SAASL;YACT,GAAI,CAACC,YAAY,CAAC,IAAI;gBAAEK,kBAAkBN;YAAM,CAAC;QACnD;IACF;AACF;AAEA,OAAO,MAAMO,oBAAoBhB;IAK/B,OAAOE,QAAQC,UAA0B,CAAC,CAAC,EAAE;QAC3C,OAAO,IAAIa,YAAYjB,KAAKkB,OAAO,CAACd,UAAU;YAAEA;QAAQ;IAC1D;IAEAE,WAAW;QACT,OAAO,IAAI,CAACC,GAAG,CAAC,GAAG;IACrB;IAEAC,WAAW;QACT,OAAO,IAAI,CA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AA,SAEE,IACA,KACA,KACA,IACA,KACA,cAEK,WAAW;AAClB,SAAS,gBAAgB,WAAW;AAIpC,OAAO,MAAM,mBAAmB,SAI9B;CACA,OAAO,QAAQ,GAAG,QAAiB;AACjC,SAAO,IAAI,WAAW,EACpB,gBAAgB,QAAQ,CAAC,MAAM,GAAG,OAAO,CAC1C;CACF;CAED,WAAW;AACT,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,IAAI,EAAE,CAAC;CACxD;CAED,WAAW;AACT,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,IAAI,EAAE,CAAC;CACxD;CAED,GAAGA,OAAe;AAChB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,GAAG,MAAM,CAAC;CAC3D;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC;CAC5D;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC;CAC5D;CAED,GAAGA,OAAe;AAChB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,GAAG,MAAM,CAAC;CAC3D;AACF;AAED,OAAO,MAAM,oBAAoB,WAAW;CAC1C,OAAO,QAAQ,GAAG,QAAiB;AACjC,SAAO,WAAW,QAAQ,GAAG,QAAQ,KAAK,CAAC;CAC5C;AACF","names":["value: number"],"sources":["src/types/number.ts"],"sourcesContent":["import {\n type core,\n gt,\n gte,\n int,\n lt,\n lte,\n number,\n type ZodMiniNumber,\n} from '@zod/mini'\nimport { BaseType } from './base.ts'\n\ntype Check = core.CheckFn<number> | core.$ZodCheck<number>\n\nexport class NumberType extends BaseType<\n ZodMiniNumber<number>,\n ZodMiniNumber<number>,\n { checks: Check[] }\n> {\n static factory(...checks: Check[]) {\n return new NumberType({\n encodedZodType: number().check(...checks),\n })\n }\n\n positive() {\n return NumberType.factory(...this.props.checks, gte(0))\n }\n\n negative() {\n return NumberType.factory(...this.props.checks, lte(0))\n }\n\n lt(value: number) {\n return NumberType.factory(...this.props.checks, lt(value))\n }\n\n lte(value: number) {\n return NumberType.factory(...this.props.checks, lte(value))\n }\n\n gte(value: number) {\n return NumberType.factory(...this.props.checks, gte(value))\n }\n\n gt(value: number) {\n return NumberType.factory(...this.props.checks, gt(value))\n }\n}\n\nexport class IntegerType extends NumberType {\n static factory(...checks: Check[]) {\n return NumberType.factory(...checks, int())\n }\n}\n"],"version":3}
@@ -1,49 +1,60 @@
1
- import { Type } from '@sinclair/typebox';
1
+ import { object, record } from "@zod/mini";
2
2
  import { BaseType } from "./base.js";
3
3
  import { EnumType } from "./enum.js";
4
4
  export class ObjectType extends BaseType {
5
- static factory(properties, options = {}) {
6
- const schemaProperties = {};
7
- for(const key in properties){
8
- schemaProperties[key] = properties[key].schema;
9
- }
10
- return new ObjectType(Type.Object(schemaProperties, options), {
11
- properties
12
- });
13
- }
5
+ static factory(properties) {
6
+ const encodeProperties = {};
7
+ const decodeProperties = {};
8
+ for (const key in properties) {
9
+ encodeProperties[key] = properties[key].encodedZodType;
10
+ decodeProperties[key] = properties[key].decodedZodType;
11
+ }
12
+ return new ObjectType({
13
+ encodedZodType: object(encodeProperties),
14
+ decodedZodType: object(decodeProperties),
15
+ props: { properties }
16
+ });
17
+ }
14
18
  }
15
19
  export class RecordType extends BaseType {
16
- static factory(key, element, options = {}) {
17
- return new RecordType(Type.Record(key.schema, element.schema, options));
18
- }
20
+ static factory(key, element) {
21
+ return new RecordType({
22
+ encodedZodType: record(key.encodedZodType, element.encodedZodType),
23
+ decodedZodType: record(key.decodedZodType, element.decodedZodType),
24
+ props: {
25
+ key,
26
+ element
27
+ }
28
+ });
29
+ }
19
30
  }
20
31
  export function keyof(type) {
21
- return EnumType.factory(Object.keys(type.props.properties));
32
+ return EnumType.factory(Object.keys(type.props.properties));
22
33
  }
23
34
  export function pick(source, pick) {
24
- const properties = Object.fromEntries(Object.entries(source.props.properties).filter(([key])=>pick[key]));
25
- return ObjectType.factory(properties);
35
+ const properties = Object.fromEntries(Object.entries(source.props.properties).filter(([key]) => pick[key]));
36
+ return ObjectType.factory(properties);
26
37
  }
27
38
  export function omit(source, omit) {
28
- const properties = Object.fromEntries(Object.entries(source.props.properties).filter(([key])=>!omit[key]));
29
- return ObjectType.factory(properties);
39
+ const properties = Object.fromEntries(Object.entries(source.props.properties).filter(([key]) => !omit[key]));
40
+ return ObjectType.factory(properties);
30
41
  }
31
42
  export function extend(object1, properties) {
32
- return ObjectType.factory({
33
- ...object1.props.properties,
34
- ...properties
35
- });
43
+ return ObjectType.factory({
44
+ ...object1.props.properties,
45
+ ...properties
46
+ });
36
47
  }
37
48
  export function merge(object1, object2) {
38
- return ObjectType.factory({
39
- ...object1.props.properties,
40
- ...object2.props.properties
41
- });
49
+ return ObjectType.factory({
50
+ ...object1.props.properties,
51
+ ...object2.props.properties
52
+ });
42
53
  }
43
54
  export function partial(object) {
44
- const properties = {};
45
- for (const [key, value] of Object.entries(object.props.properties)){
46
- properties[key] = value.optional();
47
- }
48
- return ObjectType.factory(properties, {});
55
+ const properties = {};
56
+ for (const [key, value] of Object.entries(object.props.properties)) {
57
+ properties[key] = value.optional();
58
+ }
59
+ return ObjectType.factory(properties);
49
60
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/object.ts"],"sourcesContent":["import {\n type ObjectOptions,\n type TObject,\n type TRecordOrObject,\n type TSchema,\n Type,\n} from '@sinclair/typebox'\nimport type { StaticInputDecode } from '../inference.ts'\nimport type { UnionToTupleString } from '../utils.ts'\nimport { BaseType, type BaseTypeAny, type OptionalType } from './base.ts'\nimport { EnumType, type ObjectEnumType } from './enum.ts'\nimport type { LiteralType } from './literal.ts'\nimport type { StringType } from './string.ts'\n\nexport type ObjectTypeProps = { [k: string]: BaseTypeAny }\nexport type AnyObjectType = ObjectType<ObjectTypeProps>\nexport class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<\n TObject<{ [K in keyof T]: T[K]['schema'] }>,\n { properties: T },\n StaticInputDecode<TObject<{ [K in keyof T]: T[K]['schema'] }>>\n> {\n static factory<T extends ObjectTypeProps = {}>(\n properties: T,\n options: ObjectOptions = {},\n ) {\n const schemaProperties = {} as {\n [K in keyof T]: T[K]['schema']\n }\n\n for (const key in properties) {\n schemaProperties[key] = properties[key].schema\n }\n\n return new ObjectType<T>(Type.Object(schemaProperties, options) as any, {\n properties,\n })\n }\n}\n\nexport class RecordType<\n K extends LiteralType | EnumType | ObjectEnumType | StringType,\n E extends BaseType,\n> extends BaseType<TRecordOrObject<K['schema'], E['schema']>> {\n static factory<\n K extends\n | LiteralType<any>\n | EnumType<any>\n | ObjectEnumType<any>\n | StringType,\n E extends BaseType,\n >(key: K, element: E, options: ObjectOptions = {}) {\n return new RecordType<K, E>(\n Type.Record(key.schema, element.schema, options) as any,\n )\n }\n}\n\nexport function keyof<T extends ObjectType>(\n type: T,\n): EnumType<\n UnionToTupleString<T extends ObjectType<infer Props> ? keyof Props : never>\n> {\n return EnumType.factory(Object.keys(type.props.properties) as any)\n}\n\nexport function pick<\n T extends AnyObjectType,\n P extends { [K in keyof T['props']['properties']]?: true },\n>(\n source: T,\n pick: P,\n): ObjectType<{\n [K in keyof P]: P[K] extends true\n ? K extends keyof T['props']['properties']\n ? T['props']['properties'][K]\n : never\n : never\n}> {\n const properties = Object.fromEntries(\n Object.entries(source.props.properties).filter(([key]) => pick[key]),\n )\n return ObjectType.factory(properties) as any\n}\n\nexport function omit<\n T extends AnyObjectType,\n P extends { [K in keyof T['props']['properties']]?: true },\n>(\n source: T,\n omit: P,\n): ObjectType<{\n [K in keyof T['props']['properties'] as K extends keyof P\n ? never\n : K]: T['props']['properties'][K]\n}> {\n const properties = Object.fromEntries(\n Object.entries(source.props.properties).filter(([key]) => !omit[key]),\n )\n return ObjectType.factory(properties) as any\n}\n\nexport function extend<T extends AnyObjectType, P extends ObjectTypeProps>(\n object1: T,\n properties: P,\n): ObjectType<{\n [K in keyof T['props']['properties'] | keyof P]: K extends keyof P\n ? P[K]\n : K extends keyof T['props']['properties']\n ? T['props']['properties'][K]\n : never\n}> {\n return ObjectType.factory({\n ...object1.props.properties,\n ...properties,\n }) as any\n}\n\nexport function merge<T1 extends AnyObjectType, T2 extends AnyObjectType>(\n object1: T1,\n object2: T2,\n): ObjectType<{\n [K in\n | keyof T1['props']['properties']\n | keyof T2['props']['properties']]: K extends keyof T2['props']['properties']\n ? T2['props']['properties'][K]\n : K extends keyof T1['props']['properties']\n ? T1['props']['properties'][K]\n : never\n}> {\n return ObjectType.factory({\n ...object1.props.properties,\n ...object2.props.properties,\n }) as any\n}\n\nexport function partial<\n T extends AnyObjectType,\n P extends T extends ObjectType<infer Props> ? Props : never,\n>(\n object: T,\n): ObjectType<{\n [K in keyof P]: P[K] extends BaseType<any, any, infer T>\n ? OptionalType<P[K], T>\n : never\n}> {\n const properties = {} as any\n\n for (const [key, value] of Object.entries(object.props.properties)) {\n properties[key] = value.optional()\n }\n\n return ObjectType.factory(properties, {}) as any\n}\n"],"names":["Type","BaseType","EnumType","ObjectType","factory","properties","options","schemaProperties","key","schema","Object","RecordType","element","Record","keyof","type","keys","props","pick","source","fromEntries","entries","filter","omit","extend","object1","merge","object2","partial","object","value","optional"],"mappings":"AAAA,SAKEA,IAAI,QACC,oBAAmB;AAG1B,SAASC,QAAQ,QAA6C,YAAW;AACzE,SAASC,QAAQ,QAA6B,YAAW;AAMzD,OAAO,MAAMC,mBAAmDF;IAK9D,OAAOG,QACLC,UAAa,EACbC,UAAyB,CAAC,CAAC,EAC3B;QACA,MAAMC,mBAAmB,CAAC;QAI1B,IAAK,MAAMC,OAAOH,WAAY;YAC5BE,gBAAgB,CAACC,IAAI,GAAGH,UAAU,CAACG,IAAI,CAACC,MAAM;QAChD;QAEA,OAAO,IAAIN,WAAcH,KAAKU,MAAM,CAACH,kBAAkBD,UAAiB;YACtED;QACF;IACF;AACF;AAEA,OAAO,MAAMM,mBAGHV;IAC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ACtC;AAED,OAAO,SAAS,OACdC,SACAC,YAOC;AACD,QAAO,WAAW,QAAQ;EACxB,GAAG,QAAQ,MAAM;EACjB,GAAG;CACJ,EAAC;AACH;AAED,OAAO,SAAS,MACdC,SACAC,SASC;AACD,QAAO,WAAW,QAAQ;EACxB,GAAG,QAAQ,MAAM;EACjB,GAAG,QAAQ,MAAM;CAClB,EAAC;AACH;AAED,OAAO,SAAS,QAIdC,QAGC;CACD,MAAM,aAAa,CAAE;AAErB,MAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,OAAO,MAAM,WAAW,EAAE;AAClE,aAAW,OAAO,MAAM,UAAU;CACnC;AAED,QAAO,WAAW,QAAQ,WAAW;AACtC","names":["properties: T","key: K","element: E","type: T","source: T","pick: P","omit: P","object1: T","properties: P","object1: T1","object2: T2","object: T"],"sources":["src/types/object.ts"],"sourcesContent":["import {\n type core,\n object,\n record,\n type ZodMiniObject,\n type ZodMiniRecord,\n} from '@zod/mini'\n\nimport { BaseType, type BaseTypeAny, type OptionalType } from './base.ts'\nimport { EnumType } from './enum.ts'\nimport type { LiteralType } from './literal.ts'\nimport type { StringType } from './string.ts'\n\nexport type ObjectTypeProps = { [k: string]: BaseTypeAny }\nexport type AnyObjectType = ObjectType<ObjectTypeProps>\nexport class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<\n ZodMiniObject<{ [K in keyof T]: T[K]['encodedZodType'] }>,\n ZodMiniObject<{ [K in keyof T]: T[K]['decodedZodType'] }>,\n { properties: T }\n> {\n static factory<T extends ObjectTypeProps = {}>(properties: T) {\n const encodeProperties = {} as {\n [K in keyof T]: T[K]['encodedZodType']\n }\n const decodeProperties = {} as {\n [K in keyof T]: T[K]['decodedZodType']\n }\n\n for (const key in properties) {\n encodeProperties[key] = properties[key].encodedZodType\n decodeProperties[key] = properties[key].decodedZodType\n }\n\n return new ObjectType<T>({\n encodedZodType: object(encodeProperties),\n decodedZodType: object(decodeProperties),\n props: { properties },\n })\n }\n}\n\nexport class RecordType<\n K extends LiteralType<string | number> | EnumType | StringType,\n E extends BaseType,\n> extends BaseType<\n ZodMiniRecord<K['encodedZodType'], E['encodedZodType']>,\n ZodMiniRecord<K['decodedZodType'], E['decodedZodType']>\n> {\n static factory<\n K extends LiteralType<string | number> | EnumType | StringType,\n E extends BaseType,\n >(key: K, element: E) {\n return new RecordType<K, E>({\n encodedZodType: record(\n (key as any).encodedZodType,\n element.encodedZodType,\n ),\n decodedZodType: record(\n (key as any).decodedZodType,\n element.decodedZodType,\n ),\n props: { key, element },\n })\n }\n}\n\nexport function keyof<T extends ObjectType>(\n type: T,\n): EnumType<\n core.utils.ToEnum<Extract<keyof T['props']['properties'], string>>\n> {\n return EnumType.factory(Object.keys(type.props.properties) as any)\n}\n\nexport function pick<\n T extends AnyObjectType,\n P extends { [K in keyof T['props']['properties']]?: true },\n>(\n source: T,\n pick: P,\n): ObjectType<{\n [K in keyof P]: P[K] extends true\n ? K extends keyof T['props']['properties']\n ? T['props']['properties'][K]\n : never\n : never\n}> {\n const properties = Object.fromEntries(\n Object.entries(source.props.properties).filter(([key]) => pick[key]),\n )\n return ObjectType.factory(properties) as any\n}\n\nexport function omit<\n T extends AnyObjectType,\n P extends { [K in keyof T['props']['properties']]?: true },\n>(\n source: T,\n omit: P,\n): ObjectType<{\n [K in keyof T['props']['properties'] as K extends keyof P\n ? never\n : K]: T['props']['properties'][K]\n}> {\n const properties = Object.fromEntries(\n Object.entries(source.props.properties).filter(([key]) => !omit[key]),\n )\n return ObjectType.factory(properties) as any\n}\n\nexport function extend<T extends AnyObjectType, P extends ObjectTypeProps>(\n object1: T,\n properties: P,\n): ObjectType<{\n [K in keyof T['props']['properties'] | keyof P]: K extends keyof P\n ? P[K]\n : K extends keyof T['props']['properties']\n ? T['props']['properties'][K]\n : never\n}> {\n return ObjectType.factory({\n ...object1.props.properties,\n ...properties,\n }) as any\n}\n\nexport function merge<T1 extends AnyObjectType, T2 extends AnyObjectType>(\n object1: T1,\n object2: T2,\n): ObjectType<{\n [K in\n | keyof T1['props']['properties']\n | keyof T2['props']['properties']]: K extends keyof T2['props']['properties']\n ? T2['props']['properties'][K]\n : K extends keyof T1['props']['properties']\n ? T1['props']['properties'][K]\n : never\n}> {\n return ObjectType.factory({\n ...object1.props.properties,\n ...object2.props.properties,\n }) as any\n}\n\nexport function partial<\n T extends AnyObjectType,\n P extends T extends ObjectType<infer Props> ? Props : never,\n>(\n object: T,\n): ObjectType<{\n [K in keyof P]: OptionalType<P[K]>\n}> {\n const properties = {} as any\n\n for (const [key, value] of Object.entries(object.props.properties)) {\n properties[key] = value.optional()\n }\n\n return ObjectType.factory(properties)\n}\n"],"version":3}
@@ -1,50 +1,34 @@
1
- import { Type } from '@sinclair/typebox';
1
+ import { email, ipv4, ipv6, maxLength, minLength, regex, string, url, uuid } from "@zod/mini";
2
2
  import { BaseType } from "./base.js";
3
3
  export class StringType extends BaseType {
4
- static factory(options = {}) {
5
- return new StringType(Type.String(options), {
6
- options
7
- });
8
- }
9
- max(value) {
10
- return StringType.factory({
11
- ...this.props.options,
12
- maxLength: value
13
- });
14
- }
15
- min(value) {
16
- return StringType.factory({
17
- ...this.props.options,
18
- minLength: value
19
- });
20
- }
21
- format(format) {
22
- return StringType.factory({
23
- ...this.props.options,
24
- pattern: undefined,
25
- format
26
- });
27
- }
28
- pattern(pattern) {
29
- return StringType.factory({
30
- ...this.props.options,
31
- format: undefined,
32
- pattern
33
- });
34
- }
35
- email() {
36
- return this.format('email');
37
- }
38
- url() {
39
- return this.format('uri');
40
- }
41
- ipv4() {
42
- return this.format('ipv4');
43
- }
44
- ipv6() {
45
- return this.format('ipv6');
46
- }
47
- uuid() {
48
- return this.format('uuid');
49
- }
4
+ static factory(...checks) {
5
+ return new StringType({
6
+ encodedZodType: string().check(...checks),
7
+ props: { checks }
8
+ });
9
+ }
10
+ max(value) {
11
+ return StringType.factory(...this.props.checks, maxLength(value));
12
+ }
13
+ min(value) {
14
+ return StringType.factory(...this.props.checks, minLength(value));
15
+ }
16
+ pattern(pattern) {
17
+ return StringType.factory(...this.props.checks, regex(typeof pattern === "string" ? new RegExp(pattern) : pattern));
18
+ }
19
+ email(options) {
20
+ return StringType.factory(...this.props.checks, email(options));
21
+ }
22
+ url(options) {
23
+ return StringType.factory(...this.props.checks, url(options));
24
+ }
25
+ ipv4(options) {
26
+ return StringType.factory(...this.props.checks, ipv4(options));
27
+ }
28
+ ipv6(options) {
29
+ return StringType.factory(...this.props.checks, ipv6(options));
30
+ }
31
+ uuid(options) {
32
+ return StringType.factory(...this.props.checks, uuid(options));
33
+ }
50
34
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/string.ts"],"sourcesContent":["import { type StringOptions, type TString, Type } from '@sinclair/typebox'\nimport type { StaticOutputDecode } from '../inference.ts'\nimport { BaseType } from './base.ts'\n\nexport class StringType extends BaseType<\n TString,\n { options: StringOptions },\n string\n> {\n static factory(options: StringOptions = {}) {\n return new StringType(Type.String(options), { options })\n }\n\n max(value: number) {\n return StringType.factory({\n ...this.props.options,\n maxLength: value,\n })\n }\n\n min(value: number) {\n return StringType.factory({\n ...this.props.options,\n minLength: value,\n })\n }\n\n format(format: TString['format']) {\n return StringType.factory({\n ...this.props.options,\n pattern: undefined,\n format,\n })\n }\n\n pattern(pattern: string) {\n return StringType.factory({\n ...this.props.options,\n format: undefined,\n pattern,\n })\n }\n\n email() {\n return this.format('email')\n }\n\n url() {\n return this.format('uri')\n }\n\n ipv4() {\n return this.format('ipv4')\n }\n\n ipv6() {\n return this.format('ipv6')\n }\n\n uuid() {\n return this.format('uuid')\n }\n}\n"],"names":["Type","BaseType","StringType","factory","options","String","max","value","props","maxLength","min","minLength","format","pattern","undefined","email","url","ipv4","ipv6","uuid"],"mappings":"AAAA,SAA2CA,IAAI,QAAQ,oBAAmB;AAE1E,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAAmBD;IAK9B,OAAOE,QAAQC,UAAyB,CAAC,CAAC,EAAE;QA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;CAClE;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,UAAU,MAAM,CAAC;CAClE;CAED,QAAQC,SAA0B;AAChC,SAAO,WAAW,QAChB,GAAG,KAAK,MAAM,QACd,aAAa,YAAY,WAAW,IAAI,OAAO,WAAW,QAAQ,CACnE;CACF;CAED,MAAMC,SAAgC;AACpC,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,MAAM,QAAQ,CAAC;CAChE;CAED,IAAIC,SAA8B;AAChC,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,IAAI,QAAQ,CAAC;CAC9D;CAED,KAAKC,SAA+B;AAClC,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,KAAK,QAAQ,CAAC;CAC/D;CAED,KAAKC,SAA+B;AAClC,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,KAAK,QAAQ,CAAC;CAC/D;CAED,KAAKC,SAA+B;AAClC,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,KAAK,QAAQ,CAAC;CAC/D;AACF","names":["value: number","pattern: string | RegExp","options?: core.$ZodEmailParams","options?: core.$ZodURLParams","options?: core.$ZodIPv4Params","options?: core.$ZodIPv6Params","options?: core.$ZodUUIDParams"],"sources":["src/types/string.ts"],"sourcesContent":["import {\n type core,\n email,\n ipv4,\n ipv6,\n maxLength,\n minLength,\n regex,\n string,\n url,\n uuid,\n type ZodMiniString,\n} from '@zod/mini'\n\nimport { BaseType } from './base.ts'\n\ntype Check = core.CheckFn<string> | core.$ZodCheck<string>\n\nexport class StringType extends BaseType<\n ZodMiniString<string>,\n ZodMiniString<string>,\n { checks: Check[] }\n> {\n static factory(...checks: Check[]) {\n return new StringType({\n encodedZodType: string().check(...checks),\n props: { checks },\n })\n }\n\n max(value: number) {\n return StringType.factory(...this.props.checks, maxLength(value))\n }\n\n min(value: number) {\n return StringType.factory(...this.props.checks, minLength(value))\n }\n\n pattern(pattern: string | RegExp) {\n return StringType.factory(\n ...this.props.checks,\n regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern),\n )\n }\n\n email(options?: core.$ZodEmailParams) {\n return StringType.factory(...this.props.checks, email(options))\n }\n\n url(options?: core.$ZodURLParams) {\n return StringType.factory(...this.props.checks, url(options))\n }\n\n ipv4(options?: core.$ZodIPv4Params) {\n return StringType.factory(...this.props.checks, ipv4(options))\n }\n\n ipv6(options?: core.$ZodIPv6Params) {\n return StringType.factory(...this.props.checks, ipv6(options))\n }\n\n uuid(options?: core.$ZodUUIDParams) {\n return StringType.factory(...this.props.checks, uuid(options))\n }\n}\n"],"version":3}
@@ -1,57 +1,56 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { Temporal } from 'temporal-polyfill';
1
+ import { custom, string } from "@zod/mini";
2
+ import { Temporal } from "temporal-polyfill";
3
3
  import { CustomType, TransformType } from "./custom.js";
4
- const createTemporalTransformer = (type, decode = (value)=>Temporal[type].from(value))=>{
5
- const encode = (value)=>value.toString({
6
- calendarName: 'never',
7
- smallestUnit: 'microsecond',
8
- timeZoneName: 'never'
9
- });
10
- return {
11
- decode,
12
- encode
13
- };
4
+ const createTemporalTransformer = (type, decode = (value) => Temporal[type].from(value)) => {
5
+ const encode = (value) => value.toString({
6
+ calendarName: "never",
7
+ smallestUnit: "microsecond",
8
+ timeZoneName: "never"
9
+ });
10
+ return {
11
+ decode,
12
+ encode
13
+ };
14
14
  };
15
15
  export class PlainDateType extends TransformType {
16
- static transformer = createTemporalTransformer('PlainDate');
17
- static factory() {
18
- return CustomType.factory(PlainDateType.transformer.decode, PlainDateType.transformer.encode, Type.String());
19
- }
16
+ static transformer = createTemporalTransformer("PlainDate");
17
+ static factory() {
18
+ return CustomType.factory(PlainDateType.transformer.decode, PlainDateType.transformer.encode, string());
19
+ }
20
20
  }
21
21
  export class PlainDateTimeType extends TransformType {
22
- static transformer = createTemporalTransformer('PlainDateTime');
23
- _encode = PlainDateTimeType.transformer.encode;
24
- static factory() {
25
- return CustomType.factory(PlainDateTimeType.transformer.decode, PlainDateTimeType.transformer.encode, Type.String());
26
- }
22
+ static transformer = createTemporalTransformer("PlainDateTime");
23
+ static factory() {
24
+ return CustomType.factory(PlainDateTimeType.transformer.decode, PlainDateTimeType.transformer.encode, string());
25
+ }
27
26
  }
28
27
  export class ZonedDateTimeType extends TransformType {
29
- static transformer = createTemporalTransformer('ZonedDateTime', (value)=>Temporal.Instant.from(value).toZonedDateTimeISO('UTC'));
30
- static factory() {
31
- return CustomType.factory(ZonedDateTimeType.transformer.decode, ZonedDateTimeType.transformer.encode, Type.String());
32
- }
28
+ static transformer = createTemporalTransformer("ZonedDateTime", (value) => Temporal.Instant.from(value).toZonedDateTimeISO("UTC"));
29
+ static factory() {
30
+ return CustomType.factory(ZonedDateTimeType.transformer.decode, ZonedDateTimeType.transformer.encode, string());
31
+ }
33
32
  }
34
33
  export class PlainTimeType extends TransformType {
35
- static transformer = createTemporalTransformer('PlainTime');
36
- static factory() {
37
- return CustomType.factory(PlainTimeType.transformer.decode, PlainTimeType.transformer.encode, Type.String());
38
- }
34
+ static transformer = createTemporalTransformer("PlainTime");
35
+ static factory() {
36
+ return CustomType.factory(PlainTimeType.transformer.decode, PlainTimeType.transformer.encode, string());
37
+ }
39
38
  }
40
39
  export class DurationType extends TransformType {
41
- static transformer = createTemporalTransformer('Duration');
42
- static factory() {
43
- return CustomType.factory(DurationType.transformer.decode, DurationType.transformer.encode, Type.String());
44
- }
40
+ static transformer = createTemporalTransformer("Duration");
41
+ static factory() {
42
+ return CustomType.factory(DurationType.transformer.decode, DurationType.transformer.encode, string());
43
+ }
45
44
  }
46
45
  export class PlainYearMonthType extends TransformType {
47
- static transformer = createTemporalTransformer('PlainYearMonth');
48
- static factory() {
49
- return CustomType.factory(PlainYearMonthType.transformer.decode, PlainYearMonthType.transformer.encode, Type.String());
50
- }
46
+ static transformer = createTemporalTransformer("PlainYearMonth");
47
+ static factory() {
48
+ return CustomType.factory(PlainYearMonthType.transformer.decode, PlainYearMonthType.transformer.encode, string());
49
+ }
51
50
  }
52
51
  export class PlainMonthDayType extends TransformType {
53
- static transformer = createTemporalTransformer('PlainMonthDay');
54
- static factory() {
55
- return CustomType.factory(PlainMonthDayType.transformer.decode, PlainMonthDayType.transformer.encode, Type.String());
56
- }
52
+ static transformer = createTemporalTransformer("PlainMonthDay");
53
+ static factory() {
54
+ return CustomType.factory(PlainMonthDayType.transformer.decode, PlainMonthDayType.transformer.encode, string());
55
+ }
57
56
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/temporal.ts"],"sourcesContent":["import { type TString, Type } from '@sinclair/typebox'\nimport { Temporal } from 'temporal-polyfill'\nimport { CustomType, TransformType } from './custom.ts'\n\ntype Types = Exclude<\n keyof typeof Temporal,\n 'Now' | 'Instant' | 'Calendar' | 'TimeZone'\n>\n\ntype TemporalTransformer<T extends Types> = {\n decode: (value: string) => ReturnType<(typeof Temporal)[T]['from']>\n encode: (value: ReturnType<(typeof Temporal)[T]['from']>) => string\n}\n\nconst createTemporalTransformer = <T extends Types>(\n type: T,\n decode = (value: string) => Temporal[type].from(value),\n) => {\n const encode = (value: ReturnType<(typeof Temporal)[T]['from']>) =>\n value.toString({\n calendarName: 'never',\n smallestUnit: 'microsecond',\n timeZoneName: 'never',\n })\n\n return {\n decode,\n encode,\n } as TemporalTransformer<T>\n}\n\nexport class PlainDateType extends TransformType<Temporal.PlainDate, TString> {\n static readonly transformer = createTemporalTransformer('PlainDate')\n\n static factory() {\n return CustomType.factory(\n PlainDateType.transformer.decode,\n PlainDateType.transformer.encode,\n Type.String(),\n )\n }\n}\n\nexport class PlainDateTimeType extends TransformType<\n Temporal.PlainDateTime,\n TString\n> {\n static readonly transformer = createTemporalTransformer('PlainDateTime')\n protected _encode = PlainDateTimeType.transformer.encode\n\n static factory() {\n return CustomType.factory(\n PlainDateTimeType.transformer.decode,\n PlainDateTimeType.transformer.encode,\n Type.String(),\n )\n }\n}\n\nexport class ZonedDateTimeType extends TransformType<\n Temporal.ZonedDateTime,\n TString\n> {\n static readonly transformer = createTemporalTransformer(\n 'ZonedDateTime',\n (value) => Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),\n )\n\n static factory() {\n return CustomType.factory(\n ZonedDateTimeType.transformer.decode,\n ZonedDateTimeType.transformer.encode,\n Type.String(),\n )\n }\n}\n\nexport class PlainTimeType extends TransformType<Temporal.PlainTime, TString> {\n static readonly transformer = createTemporalTransformer('PlainTime')\n\n static factory() {\n return CustomType.factory(\n PlainTimeType.transformer.decode,\n PlainTimeType.transformer.encode,\n Type.String(),\n )\n }\n}\n\nexport class DurationType extends TransformType<Temporal.Duration, TString> {\n static readonly transformer = createTemporalTransformer('Duration')\n\n static factory() {\n return CustomType.factory(\n DurationType.transformer.decode,\n DurationType.transformer.encode,\n Type.String(),\n )\n }\n}\n\nexport class PlainYearMonthType extends TransformType<\n Temporal.PlainYearMonth,\n TString\n> {\n static readonly transformer = createTemporalTransformer('PlainYearMonth')\n\n static factory() {\n return CustomType.factory(\n PlainYearMonthType.transformer.decode,\n PlainYearMonthType.transformer.encode,\n Type.String(),\n )\n }\n}\n\nexport class PlainMonthDayType extends TransformType<\n Temporal.PlainMonthDay,\n TString\n> {\n static readonly transformer = createTemporalTransformer('PlainMonthDay')\n\n static factory() {\n return CustomType.factory(\n PlainMonthDayType.transformer.decode,\n PlainMonthDayType.transformer.encode,\n Type.String(),\n )\n }\n}\n"],"names":["Type","Temporal","CustomType","TransformType","createTemporalTransformer","type","decode","value","from","encode","toString","calendarName","smallestUnit","timeZoneName","PlainDateType","transformer","factory","String","PlainDateTimeType","_encode","ZonedDateTimeType","Instant","toZonedDateTimeISO","PlainTimeType","DurationType","PlainYearMonthType","PlainMonthDayType"],"mappings":"AAAA,SAAuBA,IAAI,QAAQ,oBAAmB;AACtD,SAASC,QAAQ,QAAQ,oBAAmB;AAC5C,SAASC,UAAU,EAAEC,aAAa,QAAQ,cAAa;AAYvD,MAAMC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,CACT;CACF;AACF;AAED,OAAO,MAAM,0BAA0B,cAGrC;CACA,OAAO,cAAc,0BAA0B,iBAAiB,CAAC,UAC/D,SAAS,QAAQ,KAAK,MAAM,CAAC,mBAAmB,MAAM,CACvD;CAED,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,kBAAkB,YAAY,QAC9B,kBAAkB,YAAY,QAC9B,QAAQ,CACT;CACF;AACF;AAED,OAAO,MAAM,sBAAsB,cAGjC;CACA,OAAO,cAAc,0BAA0B,YAAY;CAE3D,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,cAAc,YAAY,QAC1B,cAAc,YAAY,QAC1B,QAAQ,CACT;CACF;AACF;AAED,OAAO,MAAM,qBAAqB,cAGhC;CACA,OAAO,cAAc,0BAA0B,WAAW;CAE1D,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,aAAa,YAAY,QACzB,aAAa,YAAY,QACzB,QAAQ,CACT;CACF;AACF;AAED,OAAO,MAAM,2BAA2B,cAGtC;CACA,OAAO,cAAc,0BAA0B,iBAAiB;CAEhE,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,mBAAmB,YAAY,QAC/B,mBAAmB,YAAY,QAC/B,QAAQ,CACT;CACF;AACF;AAED,OAAO,MAAM,0BAA0B,cAGrC;CACA,OAAO,cAAc,0BAA0B,gBAAgB;CAE/D,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,kBAAkB,YAAY,QAC9B,kBAAkB,YAAY,QAC9B,QAAQ,CACT;CACF;AACF","names":["type: T","value: string","value: ReturnType<(typeof Temporal)[T]['from']>"],"sources":["src/types/temporal.ts"],"sourcesContent":["import {\n custom,\n string,\n type ZodMiniCustom,\n type ZodMiniString,\n} from '@zod/mini'\nimport { Temporal } from 'temporal-polyfill'\nimport { CustomType, TransformType } from './custom.ts'\n\ntype Types = Exclude<\n keyof typeof Temporal,\n 'Now' | 'Instant' | 'Calendar' | 'TimeZone'\n>\n\ntype TemporalTransformer<T extends Types> = {\n decode: (value: string) => ReturnType<(typeof Temporal)[T]['from']>\n encode: (value: ReturnType<(typeof Temporal)[T]['from']>) => string\n}\n\nconst createTemporalTransformer = <T extends Types>(\n type: T,\n decode = (value: string) => Temporal[type].from(value),\n) => {\n const encode = (value: ReturnType<(typeof Temporal)[T]['from']>) =>\n value.toString({\n calendarName: 'never',\n smallestUnit: 'microsecond',\n timeZoneName: 'never',\n })\n\n return {\n decode,\n encode,\n } as TemporalTransformer<T>\n}\n\nexport class PlainDateType extends TransformType<\n Temporal.PlainDate,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('PlainDate')\n\n static factory() {\n return CustomType.factory<\n Temporal.PlainDate,\n ZodMiniString,\n ZodMiniCustom<Temporal.PlainDate, Temporal.PlainDate>\n >(\n PlainDateType.transformer.decode,\n PlainDateType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class PlainDateTimeType extends TransformType<\n Temporal.PlainDateTime,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('PlainDateTime')\n\n static factory() {\n return CustomType.factory<\n Temporal.PlainDateTime,\n ZodMiniString,\n ZodMiniCustom<Temporal.PlainDateTime, Temporal.PlainDateTime>\n >(\n PlainDateTimeType.transformer.decode,\n PlainDateTimeType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class ZonedDateTimeType extends TransformType<\n Temporal.ZonedDateTime,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('ZonedDateTime', (value) =>\n Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),\n )\n\n static factory() {\n return CustomType.factory<\n Temporal.ZonedDateTime,\n ZodMiniString,\n ZodMiniCustom<Temporal.ZonedDateTime, Temporal.ZonedDateTime>\n >(\n ZonedDateTimeType.transformer.decode,\n ZonedDateTimeType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class PlainTimeType extends TransformType<\n Temporal.PlainTime,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('PlainTime')\n\n static factory() {\n return CustomType.factory<\n Temporal.PlainTime,\n ZodMiniString,\n ZodMiniCustom<Temporal.PlainTime, Temporal.PlainTime>\n >(\n PlainTimeType.transformer.decode,\n PlainTimeType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class DurationType extends TransformType<\n Temporal.Duration,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('Duration')\n\n static factory() {\n return CustomType.factory<\n Temporal.Duration,\n ZodMiniString,\n ZodMiniCustom<Temporal.Duration, Temporal.Duration>\n >(\n DurationType.transformer.decode,\n DurationType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class PlainYearMonthType extends TransformType<\n Temporal.PlainYearMonth,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('PlainYearMonth')\n\n static factory() {\n return CustomType.factory<\n Temporal.PlainYearMonth,\n ZodMiniString,\n ZodMiniCustom<Temporal.PlainYearMonth, Temporal.PlainYearMonth>\n >(\n PlainYearMonthType.transformer.decode,\n PlainYearMonthType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class PlainMonthDayType extends TransformType<\n Temporal.PlainMonthDay,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('PlainMonthDay')\n\n static factory() {\n return CustomType.factory<\n Temporal.PlainMonthDay,\n ZodMiniString,\n ZodMiniCustom<Temporal.PlainMonthDay, Temporal.PlainMonthDay>\n >(\n PlainMonthDayType.transformer.decode,\n PlainMonthDayType.transformer.encode,\n string(),\n )\n }\n}\n"],"version":3}
@@ -1,25 +1,32 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { DiscriminatedUnion } from "../schemas/discriminated-union.js";
1
+ import { discriminatedUnion, intersection, union } from "@zod/mini";
3
2
  import { BaseType } from "./base.js";
4
3
  export class UnionType extends BaseType {
5
- static factory(...options) {
6
- return new UnionType(Type.Union(options.map((t)=>t.schema)), {
7
- options
8
- });
9
- }
4
+ static factory(...options) {
5
+ return new UnionType({
6
+ encodedZodType: union(options.map((t) => t.encodedZodType)),
7
+ decodedZodType: union(options.map((t) => t.decodedZodType)),
8
+ props: { options }
9
+ });
10
+ }
10
11
  }
11
12
  export class IntersactionType extends BaseType {
12
- static factory(...options) {
13
- return new IntersactionType(Type.Intersect(options.map((t)=>t.schema)), {
14
- options
15
- });
16
- }
13
+ static factory(...options) {
14
+ return new IntersactionType({
15
+ encodedZodType: intersection(options[0].encodedZodType, options[1].encodedZodType),
16
+ decodedZodType: intersection(options[0].decodedZodType, options[1].decodedZodType),
17
+ props: { options }
18
+ });
19
+ }
17
20
  }
18
21
  export class DiscriminatedUnionType extends BaseType {
19
- static factory(key, ...options) {
20
- return new DiscriminatedUnionType(DiscriminatedUnion(key, options.map((t)=>t.schema)), {
21
- key,
22
- options
23
- });
24
- }
22
+ static factory(key, ...options) {
23
+ return new DiscriminatedUnionType({
24
+ encodedZodType: discriminatedUnion(options.map((t) => t.encodedZodType)),
25
+ decodedZodType: discriminatedUnion(options.map((t) => t.decodedZodType)),
26
+ props: {
27
+ key,
28
+ options
29
+ }
30
+ });
31
+ }
25
32
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/union.ts"],"sourcesContent":["import {\n type TIntersect,\n type TObject,\n type TSchema,\n type TUnion,\n Type,\n type UnionToTuple,\n} from '@sinclair/typebox'\nimport type { StaticInputDecode } from '../inference.ts'\nimport {\n DiscriminatedUnion,\n type DiscriminatedUnionProperties,\n type TDiscriminatedUnion,\n} from '../schemas/discriminated-union.ts'\nimport { BaseType, type BaseTypeAny } from './base.ts'\nimport type { ObjectType, ObjectTypeProps } from './object.ts'\n\nexport class UnionType<\n T extends readonly BaseType[] = readonly BaseType[],\n S extends TSchema[] = UnionToTuple<T[number]['schema']>,\n> extends BaseType<TUnion<S>, { options: T }, StaticInputDecode<TUnion<S>>> {\n static factory<\n T extends readonly BaseType[] = readonly BaseType[],\n S extends TSchema[] = UnionToTuple<T[number]['schema']>,\n >(...options: T) {\n return new UnionType<T, S>(\n Type.Union(options.map((t) => t.schema)) as any,\n {\n options,\n },\n )\n }\n}\n\nexport class IntersactionType<\n T extends readonly BaseType[] = readonly BaseType[],\n S extends TSchema[] = UnionToTuple<T[number]['schema']>,\n> extends BaseType<\n TIntersect<S>,\n { options: T },\n StaticInputDecode<TIntersect<S>>\n> {\n static factory<\n T extends readonly BaseType[] = readonly BaseType[],\n S extends TSchema[] = UnionToTuple<T[number]['schema']>,\n >(...options: T) {\n return new IntersactionType<T, S>(\n Type.Intersect(options.map((t) => t.schema)) as any,\n { options },\n )\n }\n}\n\nexport type DiscriminatedUnionOptionType<K extends string> = ObjectType<\n ObjectTypeProps & { [_ in K]: BaseTypeAny }\n>\n\nexport class DiscriminatedUnionType<\n K extends string = string,\n T extends\n readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],\n S extends TObject<DiscriminatedUnionProperties<K>>[] = [],\n> extends BaseType<\n TDiscriminatedUnion<K, S>,\n {\n key: K\n options: T\n },\n StaticInputDecode<TDiscriminatedUnion<K, S>>\n> {\n static factory<\n K extends string,\n T extends readonly DiscriminatedUnionOptionType<K>[],\n //@ts-expect-error\n S extends TObject<DiscriminatedUnionProperties<K>>[] = UnionToTuple<\n T[number]['schema']\n >,\n >(key: K, ...options: T) {\n return new DiscriminatedUnionType<K, T, S>(\n DiscriminatedUnion(key, options.map((t) => t.schema) as any),\n { key, options },\n )\n }\n}\n"],"names":["Type","DiscriminatedUnion","BaseType","UnionType","factory","options","Union","map","t","schema","IntersactionType","Intersect","DiscriminatedUnionType","key"],"mappings":"AAAA,SAKEA,IAAI,QAEC,oBAAmB;AAE1B,SACEC,kBAAkB,QAGb,oCAAmC;AAC1C,SAASC,QAAQ,QAA0B,YAAW;AAGtD,OAAO,MAAMC,kBAGHD;IACR,OAAOE,QAGL,GAAGC,OAAU,EAAE;QACf,OAAO,IAAIF,UACTH,KAAKM,KAAK,CAACD,QAAQE,GAAG,CAAC,CAACC,IAAMA,EAAEC,MAAM,IACtC;YACEJ;QACF;IAEJ;AACF;AAEA,OAAO,MAAMK,yBAGHR;IAKR,OAAOE,QAGL,GAAGC,OAAU,EAAE;QACf,OAAO,IAAIK,iBACTV,KAAKW,SAAS,CAACN,QAAQE,GAAG,CAAC,CAACC,IAAMA,EAAEC,MAAM,IAC1C;YAAEJ;QAAQ;IAEd;AACF;AAMA,OAAO,MAAMO,+BAKHV;IAQR,OAAOE,QAOLS,GAAM,EAAE,GAAGR,OAAU,EAAE;QACvB,OAAO,IAAIO,uBACTX,mBAAmBY,KAAKR,QAAQE,GAAG,CAAC,CAACC,IAAMA,EAAEC,MAAM,IACnD;YAAEI;YAAKR;QAAQ;IAEnB;AACF"}
1
+ {"mappings":"AAAA,SAEE,oBACA,cACA,aAIK,WAAW;AAClB,SAAS,gBAAkC,WAAW;AAItD,OAAO,MAAM,kBAEH,SAIR;CACA,OAAO,QACL,GAAG,SACH;AACA,SAAO,IAAI,UAAa;GACtB,gBAAgB,MAAM,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC;GAC3D,gBAAgB,MAAM,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC;GAC3D,OAAO,EAAE,QAAS;EACnB;CACF;AACF;AAED,OAAO,MAAM,yBAEH,SAIR;CACA,OAAO,QAEL,GAAG,SAAY;AACf,SAAO,IAAI,iBAAoB;GAC7B,gBAAgB,aACd,QAAQ,GAAG,gBACX,QAAQ,GAAG,eACZ;GACD,gBAAgB,aACd,QAAQ,GAAG,gBACX,QAAQ,GAAG,eACZ;GACD,OAAO,EAAE,QAAS;EACnB;CACF;AACF;AAYD,OAAO,MAAM,+BAIH,SAOR;CACA,OAAO,QAILA,KAAQ,GAAG,SAAY;AACvB,SAAO,IAAI,uBAA6B;GACtC,gBAAgB,mBACd,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CACrC;GACD,gBAAgB,mBACd,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CACrC;GACD,OAAO;IAAE;IAAK;GAAS;EACxB;CACF;AACF","names":["key: K"],"sources":["src/types/union.ts"],"sourcesContent":["import {\n type core,\n discriminatedUnion,\n intersection,\n union,\n type ZodMiniDiscriminatedUnion,\n type ZodMiniIntersection,\n type ZodMiniUnion,\n} from '@zod/mini'\nimport { BaseType, type BaseTypeAny } from './base.ts'\nimport type { LiteralType } from './literal.ts'\nimport type { ObjectType, ObjectTypeProps } from './object.ts'\n\nexport class UnionType<\n T extends readonly BaseType[] = readonly BaseType[],\n> extends BaseType<\n ZodMiniUnion<core.utils.Flatten<T[number]['encodedZodType'][]>>,\n ZodMiniUnion<core.utils.Flatten<T[number]['decodedZodType'][]>>,\n { options: T }\n> {\n static factory<T extends readonly BaseType[] = readonly BaseType[]>(\n ...options: T\n ) {\n return new UnionType<T>({\n encodedZodType: union(options.map((t) => t.encodedZodType)),\n decodedZodType: union(options.map((t) => t.decodedZodType)),\n props: { options },\n })\n }\n}\n\nexport class IntersactionType<\n T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],\n> extends BaseType<\n ZodMiniIntersection<T[0]['encodedZodType'], T[1]['encodedZodType']>,\n ZodMiniIntersection<T[0]['decodedZodType'], T[1]['decodedZodType']>,\n { options: T }\n> {\n static factory<\n T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],\n >(...options: T) {\n return new IntersactionType<T>({\n encodedZodType: intersection(\n options[0].encodedZodType,\n options[1].encodedZodType,\n ),\n decodedZodType: intersection(\n options[0].decodedZodType,\n options[1].decodedZodType,\n ),\n props: { options },\n })\n }\n}\n\nexport type DiscriminatedUnionProperties<K extends string = string> = {\n [OK in K]: LiteralType<string>\n} & {\n [OK in string]: any\n}\n\nexport type DiscriminatedUnionOptionType<K extends string> = ObjectType<\n ObjectTypeProps & { [_ in K]: BaseTypeAny }\n>\n\nexport class DiscriminatedUnionType<\n K extends string = string,\n T extends\n readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],\n> extends BaseType<\n ZodMiniDiscriminatedUnion<core.utils.Flatten<T[number]['encodedZodType'][]>>,\n ZodMiniDiscriminatedUnion<core.utils.Flatten<T[number]['decodedZodType'][]>>,\n {\n key: K\n options: T\n }\n> {\n static factory<\n K extends string = string,\n T extends\n readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],\n >(key: K, ...options: T) {\n return new DiscriminatedUnionType<K, T>({\n encodedZodType: discriminatedUnion(\n options.map((t) => t.encodedZodType) as any,\n ),\n decodedZodType: discriminatedUnion(\n options.map((t) => t.decodedZodType) as any,\n ),\n props: { key, options },\n })\n }\n}\n"],"version":3}
package/dist/utils.js CHANGED
@@ -1 +0,0 @@
1
- export { };
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["export type UnionToIntersectionFn<T> = (\n T extends unknown\n ? (k: () => T) => void\n : never\n) extends (k: infer Intersection) => void\n ? Intersection\n : never\nexport type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last\n ? Last\n : never\nexport type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never]\n ? Tuple\n : UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>\nexport type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never\n\nexport type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>\n\nexport type Merge<T, U> = {\n [K in keyof T | keyof U]: K extends keyof U\n ? U[K]\n : K extends keyof T\n ? T[K]\n : never\n}\n"],"names":[],"mappings":"AAiBA,WAMC"}
1
+ {"mappings":"","names":[],"sources":["src/utils.ts"],"sourcesContent":["// export type UnionToIntersectionFn<T> = (\n// T extends unknown\n// ? (k: () => T) => void\n// : never\n// ) extends (k: infer Intersection) => void\n// ? Intersection\n// : never\n// export type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last\n// ? Last\n// : never\n// export type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never]\n// ? Tuple\n// : UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>\n// export type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never\n\n// export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>\n\n// export type Merge<T, U> = {\n// [K in keyof T | keyof U]: K extends keyof U\n// ? U[K]\n// : K extends keyof T\n// ? T[K]\n// : never\n// }\n"],"version":3}