@nmtjs/type 0.4.8 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler.js +84 -38
- package/dist/compiler.js.map +1 -1
- package/dist/index.js +53 -22
- package/dist/index.js.map +1 -1
- package/dist/schemas/discriminated-union.js +9 -0
- package/dist/schemas/discriminated-union.js.map +1 -0
- package/dist/schemas/nullable.js +1 -6
- package/dist/schemas/nullable.js.map +1 -1
- package/dist/temporal.js +7 -7
- package/dist/temporal.js.map +1 -1
- package/dist/types/any.js +3 -43
- package/dist/types/any.js.map +1 -1
- package/dist/types/array.js +17 -63
- package/dist/types/array.js.map +1 -1
- package/dist/types/base.js +78 -41
- package/dist/types/base.js.map +1 -1
- package/dist/types/boolean.js +3 -43
- package/dist/types/boolean.js.map +1 -1
- package/dist/types/custom.js +8 -48
- package/dist/types/custom.js.map +1 -1
- package/dist/types/date.js +8 -0
- package/dist/types/date.js.map +1 -0
- package/dist/types/enum.js +10 -94
- package/dist/types/enum.js.map +1 -1
- package/dist/types/literal.js +3 -43
- package/dist/types/literal.js.map +1 -1
- package/dist/types/never.js +3 -26
- package/dist/types/never.js.map +1 -1
- package/dist/types/number.js +52 -186
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +10 -131
- package/dist/types/object.js.map +1 -1
- package/dist/types/string.js +25 -65
- package/dist/types/string.js.map +1 -1
- package/dist/types/temporal.js +23 -328
- package/dist/types/temporal.js.map +1 -1
- package/dist/types/union.js +16 -90
- package/dist/types/union.js.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/compiler.ts +124 -41
- package/src/index.ts +145 -63
- package/src/schemas/discriminated-union.ts +49 -0
- package/src/schemas/nullable.ts +7 -13
- package/src/temporal.ts +8 -7
- package/src/types/any.ts +6 -46
- package/src/types/array.ts +38 -86
- package/src/types/base.ts +205 -81
- package/src/types/boolean.ts +13 -47
- package/src/types/custom.ts +21 -79
- package/src/types/date.ts +10 -0
- package/src/types/enum.ts +18 -107
- package/src/types/literal.ts +7 -63
- package/src/types/never.ts +6 -36
- package/src/types/number.ts +52 -188
- package/src/types/object.ts +61 -202
- package/src/types/string.ts +25 -61
- package/src/types/temporal.ts +53 -410
- package/src/types/union.ts +98 -138
- package/src/utils.ts +8 -0
- package/dist/constants.js +0 -2
- package/dist/constants.js.map +0 -1
- package/dist/types/datetime.js +0 -53
- package/dist/types/datetime.js.map +0 -1
- package/src/constants.ts +0 -5
- package/src/types/datetime.ts +0 -65
package/dist/types/temporal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
2
|
import { Temporal } from 'temporal-polyfill';
|
|
3
|
-
import {
|
|
3
|
+
import { CustomType, TransformType } from "./custom.js";
|
|
4
4
|
const createTemporalTransformer = (type, decode = (value)=>Temporal[type].from(value))=>{
|
|
5
5
|
const encode = (value)=>value.toString({
|
|
6
6
|
calendarName: 'never',
|
|
@@ -12,351 +12,46 @@ const createTemporalTransformer = (type, decode = (value)=>Temporal[type].from(v
|
|
|
12
12
|
encode
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
export class PlainDateType extends
|
|
15
|
+
export class PlainDateType extends TransformType {
|
|
16
16
|
static transformer = createTemporalTransformer('PlainDate');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
_constructSchema(options) {
|
|
21
|
-
return Type.Transform(Type.String({
|
|
22
|
-
...options,
|
|
23
|
-
format: 'iso-date'
|
|
24
|
-
})).Decode(PlainDateType.transformer.decode).Encode(PlainDateType.transformer.encode);
|
|
25
|
-
}
|
|
26
|
-
nullable() {
|
|
27
|
-
return new PlainDateType(...this._with({
|
|
28
|
-
isNullable: true
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
optional() {
|
|
32
|
-
return new PlainDateType(...this._with({
|
|
33
|
-
isOptional: true
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
nullish() {
|
|
37
|
-
return new PlainDateType(...this._with({
|
|
38
|
-
isNullable: true,
|
|
39
|
-
isOptional: true
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
default(value) {
|
|
43
|
-
return new PlainDateType(...this._with({
|
|
44
|
-
options: {
|
|
45
|
-
default: PlainDateType.transformer.encode(value)
|
|
46
|
-
},
|
|
47
|
-
hasDefault: true
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
description(description) {
|
|
51
|
-
return new PlainDateType(...this._with({
|
|
52
|
-
options: {
|
|
53
|
-
description
|
|
54
|
-
}
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
examples(...examples) {
|
|
58
|
-
return new PlainDateType(...this._with({
|
|
59
|
-
options: {
|
|
60
|
-
examples: examples.map(PlainDateType.transformer.encode)
|
|
61
|
-
}
|
|
62
|
-
}));
|
|
17
|
+
static factory() {
|
|
18
|
+
return CustomType.factory(PlainDateType.transformer.decode, PlainDateType.transformer.encode, Type.String());
|
|
63
19
|
}
|
|
64
20
|
}
|
|
65
|
-
export class PlainDateTimeType extends
|
|
21
|
+
export class PlainDateTimeType extends TransformType {
|
|
66
22
|
static transformer = createTemporalTransformer('PlainDateTime');
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
_constructSchema(options) {
|
|
71
|
-
return Type.Transform(Type.String({
|
|
72
|
-
...options,
|
|
73
|
-
format: 'iso-date-time'
|
|
74
|
-
})).Decode(PlainDateTimeType.transformer.decode).Encode(PlainDateTimeType.transformer.encode);
|
|
75
|
-
}
|
|
76
|
-
nullable() {
|
|
77
|
-
return new PlainDateTimeType(...this._with({
|
|
78
|
-
isNullable: true
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
optional() {
|
|
82
|
-
return new PlainDateTimeType(...this._with({
|
|
83
|
-
isOptional: true
|
|
84
|
-
}));
|
|
85
|
-
}
|
|
86
|
-
nullish() {
|
|
87
|
-
return new PlainDateTimeType(...this._with({
|
|
88
|
-
isNullable: true,
|
|
89
|
-
isOptional: true
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
default(value) {
|
|
93
|
-
return new PlainDateTimeType(...this._with({
|
|
94
|
-
options: {
|
|
95
|
-
default: PlainDateTimeType.transformer.encode(value)
|
|
96
|
-
},
|
|
97
|
-
hasDefault: true
|
|
98
|
-
}));
|
|
99
|
-
}
|
|
100
|
-
description(description) {
|
|
101
|
-
return new PlainDateTimeType(...this._with({
|
|
102
|
-
options: {
|
|
103
|
-
description
|
|
104
|
-
}
|
|
105
|
-
}));
|
|
106
|
-
}
|
|
107
|
-
examples(...examples) {
|
|
108
|
-
return new PlainDateTimeType(...this._with({
|
|
109
|
-
options: {
|
|
110
|
-
examples
|
|
111
|
-
}
|
|
112
|
-
}));
|
|
23
|
+
_encode = PlainDateTimeType.transformer.encode;
|
|
24
|
+
static factory() {
|
|
25
|
+
return CustomType.factory(PlainDateTimeType.transformer.decode, PlainDateTimeType.transformer.encode, Type.String());
|
|
113
26
|
}
|
|
114
27
|
}
|
|
115
|
-
export class ZonedDateTimeType extends
|
|
28
|
+
export class ZonedDateTimeType extends TransformType {
|
|
116
29
|
static transformer = createTemporalTransformer('ZonedDateTime', (value)=>Temporal.Instant.from(value).toZonedDateTimeISO('UTC'));
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
_constructSchema(options) {
|
|
121
|
-
return Type.Transform(Type.String({
|
|
122
|
-
...options,
|
|
123
|
-
format: 'date-time'
|
|
124
|
-
})).Decode(ZonedDateTimeType.transformer.decode).Encode(ZonedDateTimeType.transformer.encode);
|
|
125
|
-
}
|
|
126
|
-
nullable() {
|
|
127
|
-
return new ZonedDateTimeType(...this._with({
|
|
128
|
-
isNullable: true
|
|
129
|
-
}));
|
|
130
|
-
}
|
|
131
|
-
optional() {
|
|
132
|
-
return new ZonedDateTimeType(...this._with({
|
|
133
|
-
isOptional: true
|
|
134
|
-
}));
|
|
135
|
-
}
|
|
136
|
-
nullish() {
|
|
137
|
-
return new ZonedDateTimeType(...this._with({
|
|
138
|
-
isNullable: true,
|
|
139
|
-
isOptional: true
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
default(value) {
|
|
143
|
-
return new ZonedDateTimeType(...this._with({
|
|
144
|
-
options: {
|
|
145
|
-
default: ZonedDateTimeType.transformer.encode(value)
|
|
146
|
-
},
|
|
147
|
-
hasDefault: true
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
description(description) {
|
|
151
|
-
return new ZonedDateTimeType(...this._with({
|
|
152
|
-
options: {
|
|
153
|
-
description
|
|
154
|
-
}
|
|
155
|
-
}));
|
|
156
|
-
}
|
|
157
|
-
examples(...examples) {
|
|
158
|
-
return new ZonedDateTimeType(...this._with({
|
|
159
|
-
options: {
|
|
160
|
-
examples
|
|
161
|
-
}
|
|
162
|
-
}));
|
|
30
|
+
static factory() {
|
|
31
|
+
return CustomType.factory(ZonedDateTimeType.transformer.decode, ZonedDateTimeType.transformer.encode, Type.String());
|
|
163
32
|
}
|
|
164
33
|
}
|
|
165
|
-
export class PlainTimeType extends
|
|
34
|
+
export class PlainTimeType extends TransformType {
|
|
166
35
|
static transformer = createTemporalTransformer('PlainTime');
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
_constructSchema(options) {
|
|
171
|
-
return Type.Transform(Type.String({
|
|
172
|
-
...options,
|
|
173
|
-
format: 'time'
|
|
174
|
-
})).Decode(PlainTimeType.transformer.decode).Encode(PlainTimeType.transformer.encode);
|
|
175
|
-
}
|
|
176
|
-
nullable() {
|
|
177
|
-
return new PlainTimeType(...this._with({
|
|
178
|
-
isNullable: true
|
|
179
|
-
}));
|
|
180
|
-
}
|
|
181
|
-
optional() {
|
|
182
|
-
return new PlainTimeType(...this._with({
|
|
183
|
-
isOptional: true
|
|
184
|
-
}));
|
|
185
|
-
}
|
|
186
|
-
nullish() {
|
|
187
|
-
return new PlainTimeType(...this._with({
|
|
188
|
-
isNullable: true,
|
|
189
|
-
isOptional: true
|
|
190
|
-
}));
|
|
191
|
-
}
|
|
192
|
-
default(value) {
|
|
193
|
-
return new PlainTimeType(...this._with({
|
|
194
|
-
options: {
|
|
195
|
-
default: PlainTimeType.transformer.encode(value)
|
|
196
|
-
},
|
|
197
|
-
hasDefault: true
|
|
198
|
-
}));
|
|
199
|
-
}
|
|
200
|
-
description(description) {
|
|
201
|
-
return new PlainTimeType(...this._with({
|
|
202
|
-
options: {
|
|
203
|
-
description
|
|
204
|
-
}
|
|
205
|
-
}));
|
|
206
|
-
}
|
|
207
|
-
examples(...examples) {
|
|
208
|
-
return new PlainTimeType(...this._with({
|
|
209
|
-
options: {
|
|
210
|
-
examples
|
|
211
|
-
}
|
|
212
|
-
}));
|
|
36
|
+
static factory() {
|
|
37
|
+
return CustomType.factory(PlainTimeType.transformer.decode, PlainTimeType.transformer.encode, Type.String());
|
|
213
38
|
}
|
|
214
39
|
}
|
|
215
|
-
export class DurationType extends
|
|
40
|
+
export class DurationType extends TransformType {
|
|
216
41
|
static transformer = createTemporalTransformer('Duration');
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
_constructSchema(options) {
|
|
221
|
-
return Type.Transform(Type.String({
|
|
222
|
-
...options,
|
|
223
|
-
format: 'duration'
|
|
224
|
-
})).Decode(DurationType.transformer.decode).Encode(DurationType.transformer.encode);
|
|
225
|
-
}
|
|
226
|
-
nullable() {
|
|
227
|
-
return new DurationType(...this._with({
|
|
228
|
-
isNullable: true
|
|
229
|
-
}));
|
|
230
|
-
}
|
|
231
|
-
optional() {
|
|
232
|
-
return new DurationType(...this._with({
|
|
233
|
-
isOptional: true
|
|
234
|
-
}));
|
|
235
|
-
}
|
|
236
|
-
nullish() {
|
|
237
|
-
return new DurationType(...this._with({
|
|
238
|
-
isNullable: true,
|
|
239
|
-
isOptional: true
|
|
240
|
-
}));
|
|
241
|
-
}
|
|
242
|
-
default(value) {
|
|
243
|
-
return new DurationType(...this._with({
|
|
244
|
-
options: {
|
|
245
|
-
default: DurationType.transformer.encode(value)
|
|
246
|
-
},
|
|
247
|
-
hasDefault: true
|
|
248
|
-
}));
|
|
249
|
-
}
|
|
250
|
-
description(description) {
|
|
251
|
-
return new DurationType(...this._with({
|
|
252
|
-
options: {
|
|
253
|
-
description
|
|
254
|
-
}
|
|
255
|
-
}));
|
|
256
|
-
}
|
|
257
|
-
examples(...examples) {
|
|
258
|
-
return new DurationType(...this._with({
|
|
259
|
-
options: {
|
|
260
|
-
examples
|
|
261
|
-
}
|
|
262
|
-
}));
|
|
42
|
+
static factory() {
|
|
43
|
+
return CustomType.factory(DurationType.transformer.decode, DurationType.transformer.encode, Type.String());
|
|
263
44
|
}
|
|
264
45
|
}
|
|
265
|
-
export class PlainYearMonthType extends
|
|
46
|
+
export class PlainYearMonthType extends TransformType {
|
|
266
47
|
static transformer = createTemporalTransformer('PlainYearMonth');
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
_constructSchema(options) {
|
|
271
|
-
return Type.Transform(Type.String({
|
|
272
|
-
...options
|
|
273
|
-
})).Decode(PlainYearMonthType.transformer.decode).Encode(PlainYearMonthType.transformer.encode);
|
|
274
|
-
}
|
|
275
|
-
nullable() {
|
|
276
|
-
return new PlainYearMonthType(...this._with({
|
|
277
|
-
isNullable: true
|
|
278
|
-
}));
|
|
279
|
-
}
|
|
280
|
-
optional() {
|
|
281
|
-
return new PlainYearMonthType(...this._with({
|
|
282
|
-
isOptional: true
|
|
283
|
-
}));
|
|
284
|
-
}
|
|
285
|
-
nullish() {
|
|
286
|
-
return new PlainYearMonthType(...this._with({
|
|
287
|
-
isNullable: true,
|
|
288
|
-
isOptional: true
|
|
289
|
-
}));
|
|
290
|
-
}
|
|
291
|
-
default(value) {
|
|
292
|
-
return new PlainYearMonthType(...this._with({
|
|
293
|
-
options: {
|
|
294
|
-
default: PlainYearMonthType.transformer.encode(value)
|
|
295
|
-
},
|
|
296
|
-
hasDefault: true
|
|
297
|
-
}));
|
|
298
|
-
}
|
|
299
|
-
description(description) {
|
|
300
|
-
return new PlainYearMonthType(...this._with({
|
|
301
|
-
options: {
|
|
302
|
-
description
|
|
303
|
-
}
|
|
304
|
-
}));
|
|
305
|
-
}
|
|
306
|
-
examples(...examples) {
|
|
307
|
-
return new PlainYearMonthType(...this._with({
|
|
308
|
-
options: {
|
|
309
|
-
examples
|
|
310
|
-
}
|
|
311
|
-
}));
|
|
48
|
+
static factory() {
|
|
49
|
+
return CustomType.factory(PlainYearMonthType.transformer.decode, PlainYearMonthType.transformer.encode, Type.String());
|
|
312
50
|
}
|
|
313
51
|
}
|
|
314
|
-
export class PlainMonthDayType extends
|
|
52
|
+
export class PlainMonthDayType extends TransformType {
|
|
315
53
|
static transformer = createTemporalTransformer('PlainMonthDay');
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
_constructSchema(options) {
|
|
320
|
-
return Type.Transform(Type.String({
|
|
321
|
-
...options
|
|
322
|
-
})).Decode(PlainMonthDayType.transformer.decode).Encode(PlainMonthDayType.transformer.encode);
|
|
323
|
-
}
|
|
324
|
-
nullable() {
|
|
325
|
-
return new PlainMonthDayType(...this._with({
|
|
326
|
-
isNullable: true
|
|
327
|
-
}));
|
|
328
|
-
}
|
|
329
|
-
optional() {
|
|
330
|
-
return new PlainMonthDayType(...this._with({
|
|
331
|
-
isOptional: true
|
|
332
|
-
}));
|
|
333
|
-
}
|
|
334
|
-
nullish() {
|
|
335
|
-
return new PlainMonthDayType(...this._with({
|
|
336
|
-
isNullable: true,
|
|
337
|
-
isOptional: true
|
|
338
|
-
}));
|
|
339
|
-
}
|
|
340
|
-
default(value) {
|
|
341
|
-
return new PlainMonthDayType(...this._with({
|
|
342
|
-
options: {
|
|
343
|
-
default: PlainMonthDayType.transformer.encode(value)
|
|
344
|
-
},
|
|
345
|
-
hasDefault: true
|
|
346
|
-
}));
|
|
347
|
-
}
|
|
348
|
-
description(description) {
|
|
349
|
-
return new PlainMonthDayType(...this._with({
|
|
350
|
-
options: {
|
|
351
|
-
description
|
|
352
|
-
}
|
|
353
|
-
}));
|
|
354
|
-
}
|
|
355
|
-
examples(...examples) {
|
|
356
|
-
return new PlainMonthDayType(...this._with({
|
|
357
|
-
options: {
|
|
358
|
-
examples
|
|
359
|
-
}
|
|
360
|
-
}));
|
|
54
|
+
static factory() {
|
|
55
|
+
return CustomType.factory(PlainMonthDayType.transformer.decode, PlainMonthDayType.transformer.encode, Type.String());
|
|
361
56
|
}
|
|
362
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/temporal.ts"],"sourcesContent":["import {\n type SchemaOptions,\n type StringOptions,\n type TString,\n type TTransform,\n Type,\n} from '@sinclair/typebox'\nimport { Temporal } from 'temporal-polyfill'\nimport { BaseType } from './base.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<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TTransform<TString, Temporal.PlainDate>,\n N,\n O,\n D,\n StringOptions\n> {\n static readonly transformer = createTemporalTransformer('PlainDate')\n\n constructor(\n options: StringOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n ): TTransform<TString, Temporal.PlainDate> {\n return Type.Transform(Type.String({ ...options, format: 'iso-date' }))\n .Decode(PlainDateType.transformer.decode)\n .Encode(PlainDateType.transformer.encode)\n }\n\n nullable() {\n return new PlainDateType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new PlainDateType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new PlainDateType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: Temporal.PlainDate) {\n return new PlainDateType(\n ...this._with({\n options: { default: PlainDateType.transformer.encode(value) },\n hasDefault: true,\n }),\n )\n }\n\n description(description: string) {\n return new PlainDateType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [Temporal.PlainDate, ...Temporal.PlainDate[]]) {\n return new PlainDateType(\n ...this._with({\n options: { examples: examples.map(PlainDateType.transformer.encode) },\n }),\n )\n }\n}\n\nexport class PlainDateTimeType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TTransform<TString, Temporal.PlainDateTime>,\n N,\n O,\n D,\n StringOptions\n> {\n static readonly transformer = createTemporalTransformer('PlainDateTime')\n\n constructor(\n options: StringOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n ): TTransform<TString, Temporal.PlainDateTime> {\n return Type.Transform(Type.String({ ...options, format: 'iso-date-time' }))\n .Decode(PlainDateTimeType.transformer.decode)\n .Encode(PlainDateTimeType.transformer.encode)\n }\n\n nullable() {\n return new PlainDateTimeType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new PlainDateTimeType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new PlainDateTimeType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: Temporal.PlainDateTime) {\n return new PlainDateTimeType(\n ...this._with({\n options: { default: PlainDateTimeType.transformer.encode(value) },\n hasDefault: true,\n }),\n )\n }\n\n description(description: string) {\n return new PlainDateTimeType(...this._with({ options: { description } }))\n }\n\n examples(...examples: string[]) {\n return new PlainDateTimeType(...this._with({ options: { examples } }))\n }\n}\n\nexport class ZonedDateTimeType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TTransform<TString, Temporal.ZonedDateTime>,\n N,\n O,\n D,\n StringOptions\n> {\n static readonly transformer = createTemporalTransformer(\n 'ZonedDateTime',\n (value) => Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),\n )\n\n constructor(\n options: StringOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n ): TTransform<TString, Temporal.ZonedDateTime> {\n return Type.Transform(Type.String({ ...options, format: 'date-time' }))\n .Decode(ZonedDateTimeType.transformer.decode)\n .Encode(ZonedDateTimeType.transformer.encode)\n }\n\n nullable() {\n return new ZonedDateTimeType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new ZonedDateTimeType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new ZonedDateTimeType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: Temporal.ZonedDateTime) {\n return new ZonedDateTimeType(\n ...this._with({\n options: { default: ZonedDateTimeType.transformer.encode(value) },\n hasDefault: true,\n }),\n )\n }\n\n description(description: string) {\n return new ZonedDateTimeType(...this._with({ options: { description } }))\n }\n\n examples(...examples: string[]) {\n return new ZonedDateTimeType(...this._with({ options: { examples } }))\n }\n}\n\nexport class PlainTimeType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TTransform<TString, Temporal.PlainTime>,\n N,\n O,\n D,\n StringOptions\n> {\n static readonly transformer = createTemporalTransformer('PlainTime')\n\n constructor(\n options: StringOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n ): TTransform<TString, Temporal.PlainTime> {\n return Type.Transform(Type.String({ ...options, format: 'time' }))\n .Decode(PlainTimeType.transformer.decode)\n .Encode(PlainTimeType.transformer.encode)\n }\n\n nullable() {\n return new PlainTimeType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new PlainTimeType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new PlainTimeType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: Temporal.PlainTime) {\n return new PlainTimeType(\n ...this._with({\n options: { default: PlainTimeType.transformer.encode(value) },\n hasDefault: true,\n }),\n )\n }\n\n description(description: string) {\n return new PlainTimeType(...this._with({ options: { description } }))\n }\n\n examples(...examples: string[]) {\n return new PlainTimeType(...this._with({ options: { examples } }))\n }\n}\n\nexport class DurationType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TTransform<TString, Temporal.Duration>,\n N,\n O,\n D,\n StringOptions\n> {\n static readonly transformer = createTemporalTransformer('Duration')\n\n constructor(\n options: StringOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n ): TTransform<TString, Temporal.Duration> {\n return Type.Transform(Type.String({ ...options, format: 'duration' }))\n .Decode(DurationType.transformer.decode)\n .Encode(DurationType.transformer.encode)\n }\n\n nullable() {\n return new DurationType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new DurationType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new DurationType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: Temporal.Duration) {\n return new DurationType(\n ...this._with({\n options: { default: DurationType.transformer.encode(value) },\n hasDefault: true,\n }),\n )\n }\n\n description(description: string) {\n return new DurationType(...this._with({ options: { description } }))\n }\n\n examples(...examples: string[]) {\n return new DurationType(...this._with({ options: { examples } }))\n }\n}\n\nexport class PlainYearMonthType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TTransform<TString, Temporal.PlainYearMonth>,\n N,\n O,\n D,\n StringOptions\n> {\n static readonly transformer = createTemporalTransformer('PlainYearMonth')\n\n constructor(\n options: StringOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n ): TTransform<TString, Temporal.PlainYearMonth> {\n return Type.Transform(\n Type.String({\n ...options,\n // TODO: duration format, or regex?\n }),\n )\n .Decode(PlainYearMonthType.transformer.decode)\n .Encode(PlainYearMonthType.transformer.encode)\n }\n\n nullable() {\n return new PlainYearMonthType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new PlainYearMonthType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new PlainYearMonthType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: Temporal.PlainYearMonth) {\n return new PlainYearMonthType(\n ...this._with({\n options: { default: PlainYearMonthType.transformer.encode(value) },\n hasDefault: true,\n }),\n )\n }\n\n description(description: string) {\n return new PlainYearMonthType(...this._with({ options: { description } }))\n }\n\n examples(...examples: string[]) {\n return new PlainYearMonthType(...this._with({ options: { examples } }))\n }\n}\n\nexport class PlainMonthDayType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TTransform<TString, Temporal.PlainMonthDay>,\n N,\n O,\n D,\n StringOptions\n> {\n static readonly transformer = createTemporalTransformer('PlainMonthDay')\n\n constructor(\n options: StringOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n ): TTransform<TString, Temporal.PlainMonthDay> {\n return Type.Transform(\n Type.String({\n ...options,\n // TODO: duration format, or regex?\n }),\n )\n .Decode(PlainMonthDayType.transformer.decode)\n .Encode(PlainMonthDayType.transformer.encode)\n }\n\n nullable() {\n return new PlainMonthDayType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new PlainMonthDayType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new PlainMonthDayType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: Temporal.PlainMonthDay) {\n return new PlainMonthDayType(\n ...this._with({\n options: { default: PlainMonthDayType.transformer.encode(value) },\n hasDefault: true,\n }),\n )\n }\n\n description(description: string) {\n return new PlainMonthDayType(...this._with({ options: { description } }))\n }\n\n examples(...examples: string[]) {\n return new PlainMonthDayType(...this._with({ options: { examples } }))\n }\n}\n"],"names":["Type","Temporal","BaseType","createTemporalTransformer","type","decode","value","from","encode","toString","calendarName","smallestUnit","timeZoneName","PlainDateType","transformer","constructor","options","isNullable","isOptional","hasDefault","_constructSchema","Transform","String","format","Decode","Encode","nullable","_with","optional","nullish","default","description","examples","map","PlainDateTimeType","ZonedDateTimeType","Instant","toZonedDateTimeISO","PlainTimeType","DurationType","PlainYearMonthType","PlainMonthDayType"],"mappings":"AAAA,SAKEA,IAAI,QACC,oBAAmB;AAC1B,SAASC,QAAQ,QAAQ,oBAAmB;AAC5C,SAASC,QAAQ,QAAQ,YAAW;AAYpC,MAAMC,4BAA4B,CAChCC,MACAC,SAAS,CAACC,QAAkBL,QAAQ,CAACG,KAAK,CAACG,IAAI,CAACD,MAAM;IAEtD,MAAME,SAAS,CAACF,QACdA,MAAMG,QAAQ,CAAC;YACbC,cAAc;YACdC,cAAc;YACdC,cAAc;QAChB;IAEF,OAAO;QACLP;QACAG;IACF;AACF;AAEA,OAAO,MAAMK,sBAIHX;IAOR,OAAgBY,cAAcX,0BAA0B,aAAY;IAEpEY,YACEC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,Y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AC;YAAET,YAAY;QAAK;IAChE;IAEAW,UAAU;QACR,OAAO,IAAIY,qBACN,IAAI,CAACd,KAAK,CAAC;YAAEV,YAAY;YAAMC,YAAY;QAAK;IAEvD;IAEAY,QAAQxB,KAA6B,EAAE;QACrC,OAAO,IAAImC,qBACN,IAAI,CAACd,KAAK,CAAC;YACZX,SAAS;gBAAEc,SAASW,kBAAkB3B,WAAW,CAACN,MAAM,CAACF;YAAO;YAChEa,YAAY;QACd;IAEJ;IAEAY,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAIU,qBAAqB,IAAI,CAACd,KAAK,CAAC;YAAEX,SAAS;gBAAEe;YAAY;QAAE;IACxE;IAEAC,SAAS,GAAGA,QAAkB,EAAE;QAC9B,OAAO,IAAIS,qBAAqB,IAAI,CAACd,KAAK,CAAC;YAAEX,SAAS;gBAAEgB;YAAS;QAAE;IACrE;AACF"}
|
|
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,4BAA4B,CAChCC,MACAC,SAAS,CAACC,QAAkBN,QAAQ,CAACI,KAAK,CAACG,IAAI,CAACD,MAAM;IAEtD,MAAME,SAAS,CAACF,QACdA,MAAMG,QAAQ,CAAC;YACbC,cAAc;YACdC,cAAc;YACdC,cAAc;QAChB;IAEF,OAAO;QACLP;QACAG;IACF;AACF;AAEA,OAAO,MAAMK,sBAAsBX;IACjC,OAAgBY,cAAcX,0BAA0B,aAAY;IAEpE,OAAOY,UAAU;QACf,OAAOd,WAAWc,OAAO,CACvBF,cAAcC,WAAW,CAACT,MAAM,EAChCQ,cAAcC,WAAW,CAACN,MAAM,EAChCT,KAAKiB,MAAM;IAEf;AACF;AAEA,OAAO,MAAMC,0BAA0Bf;IAIrC,OAAgBY,cAAcX,0BAA0B,iBAAgB;IAC9De,UAAUD,kBAAkBH,WAAW,CAACN,MAAM,CAAA;IAExD,OAAOO,UAAU;QACf,OAAOd,WAAWc,OAAO,CACvBE,kBAAkBH,WAAW,CAACT,MAAM,EACpCY,kBAAkBH,WAAW,CAACN,MAAM,EACpCT,KAAKiB,MAAM;IAEf;AACF;AAEA,OAAO,MAAMG,0BAA0BjB;IAIrC,OAAgBY,cAAcX,0BAC5B,iBACA,CAACG,QAAUN,SAASoB,OAAO,CAACb,IAAI,CAACD,OAAOe,kBAAkB,CAAC,QAC5D;IAED,OAAON,UAAU;QACf,OAAOd,WAAWc,OAAO,CACvBI,kBAAkBL,WAAW,CAACT,MAAM,EACpCc,kBAAkBL,WAAW,CAACN,MAAM,EACpCT,KAAKiB,MAAM;IAEf;AACF;AAEA,OAAO,MAAMM,sBAAsBpB;IACjC,OAAgBY,cAAcX,0BAA0B,aAAY;IAEpE,OAAOY,UAAU;QACf,OAAOd,WAAWc,OAAO,CACvBO,cAAcR,WAAW,CAACT,MAAM,EAChCiB,cAAcR,WAAW,CAACN,MAAM,EAChCT,KAAKiB,MAAM;IAEf;AACF;AAEA,OAAO,MAAMO,qBAAqBrB;IAChC,OAAgBY,cAAcX,0BAA0B,YAAW;IAEnE,OAAOY,UAAU;QACf,OAAOd,WAAWc,OAAO,CACvBQ,aAAaT,WAAW,CAACT,MAAM,EAC/BkB,aAAaT,WAAW,CAACN,MAAM,EAC/BT,KAAKiB,MAAM;IAEf;AACF;AAEA,OAAO,MAAMQ,2BAA2BtB;IAItC,OAAgBY,cAAcX,0BAA0B,kBAAiB;IAEzE,OAAOY,UAAU;QACf,OAAOd,WAAWc,OAAO,CACvBS,mBAAmBV,WAAW,CAACT,MAAM,EACrCmB,mBAAmBV,WAAW,CAACN,MAAM,EACrCT,KAAKiB,MAAM;IAEf;AACF;AAEA,OAAO,MAAMS,0BAA0BvB;IAIrC,OAAgBY,cAAcX,0BAA0B,iBAAgB;IAExE,OAAOY,UAAU;QACf,OAAOd,WAAWc,OAAO,CACvBU,kBAAkBX,WAAW,CAACT,MAAM,EACpCoB,kBAAkBX,WAAW,CAACN,MAAM,EACpCT,KAAKiB,MAAM;IAEf;AACF"}
|
package/dist/types/union.js
CHANGED
|
@@ -1,98 +1,24 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
|
-
import {
|
|
2
|
+
import { DiscriminatedUnion } from "../schemas/discriminated-union.js";
|
|
3
|
+
import { BaseType } from "./base.js";
|
|
3
4
|
export class UnionType extends BaseType {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.types = types;
|
|
8
|
-
}
|
|
9
|
-
_constructSchema(options, types) {
|
|
10
|
-
return Type.Union(types.map(getTypeSchema), options);
|
|
11
|
-
}
|
|
12
|
-
nullable() {
|
|
13
|
-
return new UnionType(this.types, ...this._with({
|
|
14
|
-
isNullable: true
|
|
15
|
-
}));
|
|
16
|
-
}
|
|
17
|
-
optional() {
|
|
18
|
-
return new UnionType(this.types, ...this._with({
|
|
19
|
-
isOptional: true
|
|
20
|
-
}));
|
|
21
|
-
}
|
|
22
|
-
nullish() {
|
|
23
|
-
return new UnionType(this.types, ...this._with({
|
|
24
|
-
isNullable: true,
|
|
25
|
-
isOptional: true
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
default(value) {
|
|
29
|
-
return new UnionType(this.types, ...this._with({
|
|
30
|
-
options: {
|
|
31
|
-
default: value
|
|
32
|
-
},
|
|
33
|
-
hasDefault: true
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
description(description) {
|
|
37
|
-
return new UnionType(this.types, ...this._with({
|
|
38
|
-
options: {
|
|
39
|
-
description
|
|
40
|
-
}
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
examples(...examples) {
|
|
44
|
-
return new UnionType(this.types, ...this._with({
|
|
45
|
-
options: {
|
|
46
|
-
examples
|
|
47
|
-
}
|
|
48
|
-
}));
|
|
5
|
+
_;
|
|
6
|
+
static factory(...types) {
|
|
7
|
+
return new UnionType(Type.Union(types.map((t)=>t.schema)));
|
|
49
8
|
}
|
|
50
9
|
}
|
|
51
10
|
export class IntersactionType extends BaseType {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.types = types;
|
|
11
|
+
_;
|
|
12
|
+
static factory(...types) {
|
|
13
|
+
return new IntersactionType(Type.Intersect(types.map((t)=>t.schema)));
|
|
56
14
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return new
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
optional() {
|
|
66
|
-
return new IntersactionType(this.types, ...this._with({
|
|
67
|
-
isOptional: true
|
|
68
|
-
}));
|
|
69
|
-
}
|
|
70
|
-
nullish() {
|
|
71
|
-
return new IntersactionType(this.types, ...this._with({
|
|
72
|
-
isNullable: true,
|
|
73
|
-
isOptional: true
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
default(value) {
|
|
77
|
-
return new IntersactionType(this.types, ...this._with({
|
|
78
|
-
options: {
|
|
79
|
-
default: value
|
|
80
|
-
},
|
|
81
|
-
hasDefault: true
|
|
82
|
-
}));
|
|
83
|
-
}
|
|
84
|
-
description(description) {
|
|
85
|
-
return new IntersactionType(this.types, ...this._with({
|
|
86
|
-
options: {
|
|
87
|
-
description
|
|
88
|
-
}
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
examples(...values) {
|
|
92
|
-
return new IntersactionType(this.types, ...this._with({
|
|
93
|
-
options: {
|
|
94
|
-
examples: values
|
|
95
|
-
}
|
|
96
|
-
}));
|
|
15
|
+
}
|
|
16
|
+
export class DiscriminatedUnionType extends BaseType {
|
|
17
|
+
_;
|
|
18
|
+
static factory(key, ...options) {
|
|
19
|
+
return new DiscriminatedUnionType(DiscriminatedUnion(key, options.map((t)=>t.schema)), {
|
|
20
|
+
key,
|
|
21
|
+
options
|
|
22
|
+
});
|
|
97
23
|
}
|
|
98
24
|
}
|
package/dist/types/union.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/union.ts"],"sourcesContent":["import {\n type
|
|
1
|
+
{"version":3,"sources":["../../../src/types/union.ts"],"sourcesContent":["import {\n type TIntersect,\n type TUnion,\n Type,\n type UnionToTuple,\n} from '@sinclair/typebox'\nimport {\n DiscriminatedUnion,\n type TDiscriminatedUnion,\n} from '../schemas/discriminated-union.ts'\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<TUnion<UnionToTuple<T[number]['schema']>>> {\n _!: {\n encoded: {\n input: TUnion<UnionToTuple<T[number]['_']['encoded']['input']>>\n output: TUnion<UnionToTuple<T[number]['_']['encoded']['output']>>\n }\n decoded: {\n input: TUnion<UnionToTuple<T[number]['_']['decoded']['input']>>\n output: TUnion<UnionToTuple<T[number]['_']['decoded']['output']>>\n }\n }\n\n static factory<T extends readonly BaseType[] = readonly BaseType[]>(\n ...types: T\n ) {\n return new UnionType<T>(Type.Union(types.map((t) => t.schema)) as any)\n }\n}\n\nexport class IntersactionType<\n T extends readonly BaseType[] = readonly BaseType[],\n> extends BaseType<TIntersect<UnionToTuple<T[number]['schema']>>> {\n _!: {\n encoded: {\n input: TIntersect<UnionToTuple<T[number]['_']['encoded']['input']>>\n output: TIntersect<UnionToTuple<T[number]['_']['encoded']['output']>>\n }\n decoded: {\n input: TIntersect<UnionToTuple<T[number]['_']['decoded']['input']>>\n output: TIntersect<UnionToTuple<T[number]['_']['decoded']['output']>>\n }\n }\n\n static factory<T extends readonly BaseType[] = readonly BaseType[]>(\n ...types: T\n ) {\n return new IntersactionType<T>(\n Type.Intersect(types.map((t) => t.schema)) as any,\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,\n T extends readonly [\n DiscriminatedUnionOptionType<K>,\n ...DiscriminatedUnionOptionType<K>[],\n ],\n> extends BaseType<\n TDiscriminatedUnion<\n K,\n //@ts-expect-error\n UnionToTuple<T[number]['schema']>\n >,\n {\n key: K\n options: T\n }\n> {\n _!: {\n encoded: {\n input: TDiscriminatedUnion<\n K,\n //@ts-expect-error\n UnionToTuple<T[number]['_']['encoded']['input']>\n >\n output: TDiscriminatedUnion<\n K,\n //@ts-expect-error\n UnionToTuple<T[number]['_']['encoded']['output']>\n >\n }\n decoded: {\n input: TDiscriminatedUnion<\n K,\n //@ts-expect-error\n UnionToTuple<T[number]['_']['decoded']['input']>\n >\n output: TDiscriminatedUnion<\n K,\n //@ts-expect-error\n UnionToTuple<T[number]['_']['decoded']['output']>\n >\n }\n }\n\n static factory<\n K extends string,\n T extends readonly [\n DiscriminatedUnionOptionType<K>,\n ...DiscriminatedUnionOptionType<K>[],\n ],\n >(key: K, ...options: T) {\n return new DiscriminatedUnionType<K, T>(\n DiscriminatedUnion(key, options.map((t) => t.schema) as any),\n { key, options },\n )\n }\n}\n"],"names":["Type","DiscriminatedUnion","BaseType","UnionType","_","factory","types","Union","map","t","schema","IntersactionType","Intersect","DiscriminatedUnionType","key","options"],"mappings":"AAAA,SAGEA,IAAI,QAEC,oBAAmB;AAC1B,SACEC,kBAAkB,QAEb,oCAAmC;AAC1C,SAASC,QAAQ,QAA0B,YAAW;AAItD,OAAO,MAAMC,kBAEHD;IACRE,EASC;IAED,OAAOC,QACL,GAAGC,KAAQ,EACX;QACA,OAAO,IAAIH,UAAaH,KAAKO,KAAK,CAACD,MAAME,GAAG,CAAC,CAACC,IAAMA,EAAEC,MAAM;IAC9D;AACF;AAEA,OAAO,MAAMC,yBAEHT;IACRE,EASC;IAED,OAAOC,QACL,GAAGC,KAAQ,EACX;QACA,OAAO,IAAIK,iBACTX,KAAKY,SAAS,CAACN,MAAME,GAAG,CAAC,CAACC,IAAMA,EAAEC,MAAM;IAE5C;AACF;AAMA,OAAO,MAAMG,+BAMHX;IAWRE,EAyBC;IAED,OAAOC,QAMLS,GAAM,EAAE,GAAGC,OAAU,EAAE;QACvB,OAAO,IAAIF,uBACTZ,mBAAmBa,KAAKC,QAAQP,GAAG,CAAC,CAACC,IAAMA,EAAEC,MAAM,IACnD;YAAEI;YAAKC;QAAQ;IAEnB;AACF"}
|
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"],"names":[],"mappings":"
|
|
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"}
|
package/package.json
CHANGED
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@sinclair/typebox": "^0.34.13",
|
|
23
23
|
"temporal-polyfill": "^0.2.5",
|
|
24
|
-
"@nmtjs/common": "0.
|
|
24
|
+
"@nmtjs/common": "0.5.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@sinclair/typebox": "^0.34.13",
|
|
28
28
|
"temporal-polyfill": "^0.2.5",
|
|
29
|
-
"@nmtjs/common": "0.
|
|
29
|
+
"@nmtjs/common": "0.5.0"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"src",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"LICENSE.md",
|
|
36
36
|
"README.md"
|
|
37
37
|
],
|
|
38
|
-
"version": "0.
|
|
38
|
+
"version": "0.5.0",
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "neemata-build -p neutral --root=./src './**/*.ts'",
|
|
41
41
|
"type-check": "tsc --noEmit"
|