@nmtjs/type 0.2.1 → 0.3.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 +2 -2
- package/dist/compiler.js.map +1 -1
- package/dist/constants.js +2 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/temporal.js +3 -1
- package/dist/temporal.js.map +1 -1
- package/dist/types/any.js +37 -5
- package/dist/types/any.js.map +1 -1
- package/dist/types/array.js +55 -24
- package/dist/types/array.js.map +1 -1
- package/dist/types/base.js +31 -62
- package/dist/types/base.js.map +1 -1
- package/dist/types/boolean.js +37 -5
- package/dist/types/boolean.js.map +1 -1
- package/dist/types/custom.js +37 -8
- package/dist/types/custom.js.map +1 -1
- package/dist/types/datetime.js +41 -22
- package/dist/types/datetime.js.map +1 -1
- package/dist/types/enum.js +74 -16
- package/dist/types/enum.js.map +1 -1
- package/dist/types/literal.js +35 -8
- package/dist/types/literal.js.map +1 -1
- package/dist/types/never.js +17 -2
- package/dist/types/never.js.map +1 -1
- package/dist/types/number.js +116 -62
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +58 -17
- package/dist/types/object.js.map +1 -1
- package/dist/types/string.js +57 -21
- package/dist/types/string.js.map +1 -1
- package/dist/types/temporal.js +292 -74
- package/dist/types/temporal.js.map +1 -1
- package/dist/types/union.js +75 -17
- package/dist/types/union.js.map +1 -1
- package/package.json +3 -3
- package/src/compiler.ts +2 -2
- package/src/constants.ts +5 -0
- package/src/index.ts +5 -6
- package/src/temporal.ts +4 -2
- package/src/types/any.ts +32 -9
- package/src/types/array.ts +59 -28
- package/src/types/base.ts +59 -112
- package/src/types/boolean.ts +31 -9
- package/src/types/custom.ts +61 -24
- package/src/types/datetime.ts +40 -35
- package/src/types/enum.ts +78 -21
- package/src/types/literal.ts +42 -12
- package/src/types/never.ts +24 -11
- package/src/types/number.ts +103 -67
- package/src/types/object.ts +87 -32
- package/src/types/string.ts +38 -30
- package/src/types/temporal.ts +378 -118
- package/src/types/union.ts +103 -31
package/dist/types/temporal.js
CHANGED
|
@@ -1,144 +1,362 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
2
|
import { Temporal } from 'temporal-polyfill';
|
|
3
3
|
import { BaseType } from "./base.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
|
+
};
|
|
14
|
+
};
|
|
4
15
|
export class PlainDateType extends BaseType {
|
|
5
|
-
|
|
6
|
-
|
|
16
|
+
static transformer = createTemporalTransformer('PlainDate');
|
|
17
|
+
constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
|
|
18
|
+
super(options, isNullable, isOptional, hasDefault);
|
|
19
|
+
}
|
|
20
|
+
_constructSchema(options) {
|
|
21
|
+
return Type.Transform(Type.String({
|
|
22
|
+
...options,
|
|
7
23
|
format: 'iso-date'
|
|
8
|
-
})).Decode(
|
|
9
|
-
calendarName: 'never'
|
|
10
|
-
})), nullable, optional);
|
|
24
|
+
})).Decode(PlainDateType.transformer.decode).Encode(PlainDateType.transformer.encode);
|
|
11
25
|
}
|
|
12
26
|
nullable() {
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
return new PlainDateType(...this._with({
|
|
28
|
+
isNullable: true
|
|
29
|
+
}));
|
|
15
30
|
}
|
|
16
31
|
optional() {
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
return new PlainDateType(...this._with({
|
|
33
|
+
isOptional: true
|
|
34
|
+
}));
|
|
19
35
|
}
|
|
20
36
|
nullish() {
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
}));
|
|
23
63
|
}
|
|
24
64
|
}
|
|
25
65
|
export class PlainDateTimeType extends BaseType {
|
|
26
|
-
|
|
27
|
-
|
|
66
|
+
static transformer = createTemporalTransformer('PlainDateTime');
|
|
67
|
+
constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
|
|
68
|
+
super(options, isNullable, isOptional, hasDefault);
|
|
69
|
+
}
|
|
70
|
+
_constructSchema(options) {
|
|
71
|
+
return Type.Transform(Type.String({
|
|
72
|
+
...options,
|
|
28
73
|
format: 'iso-date-time'
|
|
29
|
-
})).Decode(
|
|
30
|
-
calendarName: 'never'
|
|
31
|
-
})), nullable, optional);
|
|
74
|
+
})).Decode(PlainDateTimeType.transformer.decode).Encode(PlainDateTimeType.transformer.encode);
|
|
32
75
|
}
|
|
33
76
|
nullable() {
|
|
34
|
-
|
|
35
|
-
|
|
77
|
+
return new PlainDateTimeType(...this._with({
|
|
78
|
+
isNullable: true
|
|
79
|
+
}));
|
|
36
80
|
}
|
|
37
81
|
optional() {
|
|
38
|
-
|
|
39
|
-
|
|
82
|
+
return new PlainDateTimeType(...this._with({
|
|
83
|
+
isOptional: true
|
|
84
|
+
}));
|
|
40
85
|
}
|
|
41
86
|
nullish() {
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
}));
|
|
44
113
|
}
|
|
45
114
|
}
|
|
46
115
|
export class ZonedDateTimeType extends BaseType {
|
|
47
|
-
|
|
48
|
-
|
|
116
|
+
static transformer = createTemporalTransformer('ZonedDateTime', (value)=>Temporal.Instant.from(value).toZonedDateTimeISO('UTC'));
|
|
117
|
+
constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
|
|
118
|
+
super(options, isNullable, isOptional, hasDefault);
|
|
119
|
+
}
|
|
120
|
+
_constructSchema(options) {
|
|
121
|
+
return Type.Transform(Type.String({
|
|
122
|
+
...options,
|
|
49
123
|
format: 'date-time'
|
|
50
|
-
})).Decode(
|
|
51
|
-
calendarName: 'never'
|
|
52
|
-
})), nullable, optional);
|
|
124
|
+
})).Decode(ZonedDateTimeType.transformer.decode).Encode(ZonedDateTimeType.transformer.encode);
|
|
53
125
|
}
|
|
54
126
|
nullable() {
|
|
55
|
-
|
|
56
|
-
|
|
127
|
+
return new ZonedDateTimeType(...this._with({
|
|
128
|
+
isNullable: true
|
|
129
|
+
}));
|
|
57
130
|
}
|
|
58
131
|
optional() {
|
|
59
|
-
|
|
60
|
-
|
|
132
|
+
return new ZonedDateTimeType(...this._with({
|
|
133
|
+
isOptional: true
|
|
134
|
+
}));
|
|
61
135
|
}
|
|
62
136
|
nullish() {
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
}));
|
|
65
163
|
}
|
|
66
164
|
}
|
|
67
165
|
export class PlainTimeType extends BaseType {
|
|
68
|
-
|
|
69
|
-
|
|
166
|
+
static transformer = createTemporalTransformer('PlainTime');
|
|
167
|
+
constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
|
|
168
|
+
super(options, isNullable, isOptional, hasDefault);
|
|
169
|
+
}
|
|
170
|
+
_constructSchema(options) {
|
|
171
|
+
return Type.Transform(Type.String({
|
|
172
|
+
...options,
|
|
70
173
|
format: 'time'
|
|
71
|
-
})).Decode(
|
|
72
|
-
smallestUnit: 'microsecond'
|
|
73
|
-
})), nullable, optional);
|
|
174
|
+
})).Decode(PlainTimeType.transformer.decode).Encode(PlainTimeType.transformer.encode);
|
|
74
175
|
}
|
|
75
176
|
nullable() {
|
|
76
|
-
|
|
77
|
-
|
|
177
|
+
return new PlainTimeType(...this._with({
|
|
178
|
+
isNullable: true
|
|
179
|
+
}));
|
|
78
180
|
}
|
|
79
181
|
optional() {
|
|
80
|
-
|
|
81
|
-
|
|
182
|
+
return new PlainTimeType(...this._with({
|
|
183
|
+
isOptional: true
|
|
184
|
+
}));
|
|
82
185
|
}
|
|
83
186
|
nullish() {
|
|
84
|
-
|
|
85
|
-
|
|
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
|
+
}));
|
|
86
213
|
}
|
|
87
214
|
}
|
|
88
215
|
export class DurationType extends BaseType {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
216
|
+
static transformer = createTemporalTransformer('Duration');
|
|
217
|
+
constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
|
|
218
|
+
super(options, isNullable, isOptional, hasDefault);
|
|
219
|
+
}
|
|
220
|
+
_constructSchema(options) {
|
|
221
|
+
return Type.Transform(Type.String({
|
|
222
|
+
...options,
|
|
223
|
+
format: 'duration'
|
|
224
|
+
})).Decode(DurationType.transformer.decode).Encode(DurationType.transformer.encode);
|
|
93
225
|
}
|
|
94
226
|
nullable() {
|
|
95
|
-
|
|
96
|
-
|
|
227
|
+
return new DurationType(...this._with({
|
|
228
|
+
isNullable: true
|
|
229
|
+
}));
|
|
97
230
|
}
|
|
98
231
|
optional() {
|
|
99
|
-
|
|
100
|
-
|
|
232
|
+
return new DurationType(...this._with({
|
|
233
|
+
isOptional: true
|
|
234
|
+
}));
|
|
101
235
|
}
|
|
102
236
|
nullish() {
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
}));
|
|
105
263
|
}
|
|
106
264
|
}
|
|
107
265
|
export class PlainYearMonthType extends BaseType {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
266
|
+
static transformer = createTemporalTransformer('PlainYearMonth');
|
|
267
|
+
constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
|
|
268
|
+
super(options, isNullable, isOptional, hasDefault);
|
|
269
|
+
}
|
|
270
|
+
_constructSchema(options) {
|
|
271
|
+
return Type.Transform(Type.String({
|
|
272
|
+
...options
|
|
273
|
+
})).Decode(PlainYearMonthType.transformer.decode).Encode(PlainYearMonthType.transformer.encode);
|
|
112
274
|
}
|
|
113
275
|
nullable() {
|
|
114
|
-
|
|
115
|
-
|
|
276
|
+
return new PlainYearMonthType(...this._with({
|
|
277
|
+
isNullable: true
|
|
278
|
+
}));
|
|
116
279
|
}
|
|
117
280
|
optional() {
|
|
118
|
-
|
|
119
|
-
|
|
281
|
+
return new PlainYearMonthType(...this._with({
|
|
282
|
+
isOptional: true
|
|
283
|
+
}));
|
|
120
284
|
}
|
|
121
285
|
nullish() {
|
|
122
|
-
|
|
123
|
-
|
|
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
|
+
}));
|
|
124
312
|
}
|
|
125
313
|
}
|
|
126
314
|
export class PlainMonthDayType extends BaseType {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
315
|
+
static transformer = createTemporalTransformer('PlainMonthDay');
|
|
316
|
+
constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
|
|
317
|
+
super(options, isNullable, isOptional, hasDefault);
|
|
318
|
+
}
|
|
319
|
+
_constructSchema(options) {
|
|
320
|
+
return Type.Transform(Type.String({
|
|
321
|
+
...options
|
|
322
|
+
})).Decode(PlainMonthDayType.transformer.decode).Encode(PlainMonthDayType.transformer.encode);
|
|
131
323
|
}
|
|
132
324
|
nullable() {
|
|
133
|
-
|
|
134
|
-
|
|
325
|
+
return new PlainMonthDayType(...this._with({
|
|
326
|
+
isNullable: true
|
|
327
|
+
}));
|
|
135
328
|
}
|
|
136
329
|
optional() {
|
|
137
|
-
|
|
138
|
-
|
|
330
|
+
return new PlainMonthDayType(...this._with({
|
|
331
|
+
isOptional: true
|
|
332
|
+
}));
|
|
139
333
|
}
|
|
140
334
|
nullish() {
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
}));
|
|
143
361
|
}
|
|
144
362
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/temporal.ts"],"sourcesContent":["import { type TString, type TTransform, Type } from '@sinclair/typebox'\nimport { Temporal } from 'temporal-polyfill'\nimport { BaseType } from './base.ts'\n\nexport class PlainDateType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TString, Temporal.PlainDate>, N, O> {\n constructor(nullable: N = false as N, optional: O = false as O) {\n super(\n Type.Transform(Type.String({ format: 'iso-date' }))\n .Decode((value) => Temporal.PlainDate.from(value))\n .Encode((value) => value.toString({ calendarName: 'never' })),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new PlainDateType(...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new PlainDateType(...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new PlainDateType(...args)\n }\n}\n\nexport class PlainDateTimeType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TString, Temporal.PlainDateTime>, N, O> {\n constructor(nullable: N = false as N, optional: O = false as O) {\n super(\n Type.Transform(Type.String({ format: 'iso-date-time' }))\n .Decode((value) => Temporal.PlainDateTime.from(value))\n .Encode((value) => value.toString({ calendarName: 'never' })),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new PlainDateTimeType(...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new PlainDateTimeType(...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new PlainDateTimeType(...args)\n }\n}\n\nexport class ZonedDateTimeType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TString, Temporal.ZonedDateTime>, N, O> {\n constructor(nullable: N = false as N, optional: O = false as O) {\n super(\n Type.Transform(Type.String({ format: 'date-time' }))\n .Decode((value) =>\n Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),\n )\n .Encode((value) => value.toString({ calendarName: 'never' })),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new ZonedDateTimeType(...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new ZonedDateTimeType(...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new ZonedDateTimeType(...args)\n }\n}\n\nexport class PlainTimeType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TString, Temporal.PlainTime>, N, O> {\n constructor(nullable: N = false as N, optional: O = false as O) {\n super(\n Type.Transform(Type.String({ format: 'time' }))\n .Decode((value) => Temporal.PlainTime.from(value))\n .Encode((value) => value.toString({ smallestUnit: 'microsecond' })),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new PlainTimeType(...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new PlainTimeType(...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new PlainTimeType(...args)\n }\n}\n\nexport class DurationType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TString, Temporal.Duration>, N, O> {\n constructor(nullable: N = false as N, optional: O = false as O) {\n super(\n Type.Transform(\n Type.String({\n /* TODO: duration format, or regex? */\n }),\n )\n .Decode((value) => Temporal.Duration.from(value))\n .Encode((value) => value.toString({ smallestUnit: 'microsecond' })),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new DurationType(...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new DurationType(...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new DurationType(...args)\n }\n}\n\nexport class PlainYearMonthType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TString, Temporal.PlainYearMonth>, N, O> {\n constructor(nullable: N = false as N, optional: O = false as O) {\n super(\n Type.Transform(\n Type.String({\n /* TODO: duration format, or regex? */\n }),\n )\n .Decode((value) => Temporal.PlainYearMonth.from(value))\n .Encode((value) => value.toString({ calendarName: 'never' })),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new PlainYearMonthType(...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new PlainYearMonthType(...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new PlainYearMonthType(...args)\n }\n}\n\nexport class PlainMonthDayType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TString, Temporal.PlainMonthDay>, N, O> {\n constructor(nullable: N = false as N, optional: O = false as O) {\n super(\n Type.Transform(\n Type.String({\n /* TODO: duration format, or regex? */\n }),\n )\n .Decode((value) => Temporal.PlainMonthDay.from(value))\n .Encode((value) => value.toString({ calendarName: 'never' })),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new PlainMonthDayType(...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new PlainMonthDayType(...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new PlainMonthDayType(...args)\n }\n}\n"],"names":["Type","Temporal","BaseType","PlainDateType","constructor","nullable","optional","Transform","String","format","Decode","value","PlainDate","from","Encode","toString","calendarName","_","args","_nullable","_optional","nullish","_nullish","PlainDateTimeType","PlainDateTime","ZonedDateTimeType","Instant","toZonedDateTimeISO","PlainTimeType","PlainTime","smallestUnit","DurationType","Duration","PlainYearMonthType","PlainYearMonth","PlainMonthDayType","PlainMonthDay"],"mappings":"AAAA,SAAwCA,IAAI,QAAQ,oBAAmB;AACvE,SAASC,QAAQ,QAAQ,oBAAmB;AAC5C,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,sBAGHD;IACRE,YAAYC,WAAc,KAAU,EAAEC,WAAc,KAAU,CAAE;QAC9D,KAAK,CACHN,KAAKO,SAAS,CAACP,KAAKQ,MAAM,CAAC;YAAEC,QAAQ;QAAW,IAC7CC,MAAM,CAAC,CAACC,QAAUV,SAASW,SAAS,CAACC,IAAI,CAACF,QAC1CG,MAAM,CAAC,CAACH,QAAUA,MAAMI,QAAQ,CAAC;gBAAEC,cAAc;YAAQ,KAC5DX,UACAC;IAEJ;IAEAD,WAAW;QACT,MAAM,CAACY,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACC,SAAS;QACnC,OAAO,IAAIhB,iBAAiBe;IAC9B;IAEAZ,WAAW;QACT,MAAM,CAACW,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACE,SAAS;QACnC,OAAO,IAAIjB,iBAAiBe;IAC9B;IAEAG,UAAU;QACR,MAAM,CAACJ,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACI,QAAQ;QAClC,OAAO,IAAInB,iBAAiBe;IAC9B;AACF;AAEA,OAAO,MAAMK,0BAGHrB;IACRE,YAAYC,WAAc,KAAU,EAAEC,WAAc,KAAU,CAAE;QAC9D,KAAK,CACHN,KAAKO,SAAS,CAACP,KAAKQ,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AM,CAACJ,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACI,QAAQ;QAClC,OAAO,IAAIa,qBAAqBjB;IAClC;AACF"}
|
|
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,YAAYC;IACzC;IAEUC,iBACRJ,OAAsB,EACmB;QACzC,OAAOhB,KAAKqB,SAAS,CAACrB,KAAKsB,MAAM,CAAC;YAAE,GAAGN,OAAO;YAAEO,QAAQ;QAAW,IAChEC,MAAM,CAACX,cAAcC,WAAW,CAACT,MAAM,EACvCoB,MAAM,CAACZ,cAAcC,WAAW,CAACN,MAAM;IAC5C;IAEAkB,WAAW;QACT,OAAO,I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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"}
|
package/dist/types/union.js
CHANGED
|
@@ -1,40 +1,98 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
|
-
import { BaseType,
|
|
2
|
+
import { BaseType, getTypeSchema } from "./base.js";
|
|
3
3
|
export class UnionType extends BaseType {
|
|
4
4
|
types;
|
|
5
|
-
constructor(types,
|
|
6
|
-
super(
|
|
5
|
+
constructor(types, options = {}, isNullable = false, isOptional = false, hasDefault = false){
|
|
6
|
+
super(options, isNullable, isOptional, hasDefault);
|
|
7
7
|
this.types = types;
|
|
8
8
|
}
|
|
9
|
+
_constructSchema(options) {
|
|
10
|
+
return Type.Union(this.types.map(getTypeSchema), options);
|
|
11
|
+
}
|
|
9
12
|
nullable() {
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
return new UnionType(this.types, ...this._with({
|
|
14
|
+
isNullable: true
|
|
15
|
+
}));
|
|
12
16
|
}
|
|
13
17
|
optional() {
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
return new UnionType(this.types, ...this._with({
|
|
19
|
+
isOptional: true
|
|
20
|
+
}));
|
|
16
21
|
}
|
|
17
22
|
nullish() {
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
}));
|
|
20
49
|
}
|
|
21
50
|
}
|
|
22
51
|
export class IntersactionType extends BaseType {
|
|
23
52
|
types;
|
|
24
|
-
constructor(types,
|
|
25
|
-
super(
|
|
53
|
+
constructor(types, options = {}, isNullable = false, isOptional = false, hasDefault = false){
|
|
54
|
+
super(options, isNullable, isOptional, hasDefault);
|
|
26
55
|
this.types = types;
|
|
27
56
|
}
|
|
57
|
+
_constructSchema(options) {
|
|
58
|
+
return Type.Intersect(this.types.map(getTypeSchema), options);
|
|
59
|
+
}
|
|
28
60
|
nullable() {
|
|
29
|
-
|
|
30
|
-
|
|
61
|
+
return new IntersactionType(this.types, ...this._with({
|
|
62
|
+
isNullable: true
|
|
63
|
+
}));
|
|
31
64
|
}
|
|
32
65
|
optional() {
|
|
33
|
-
|
|
34
|
-
|
|
66
|
+
return new IntersactionType(this.types, ...this._with({
|
|
67
|
+
isOptional: true
|
|
68
|
+
}));
|
|
35
69
|
}
|
|
36
70
|
nullish() {
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
}));
|
|
39
97
|
}
|
|
40
98
|
}
|