@nmtjs/type 0.2.1 → 0.3.1
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/src/types/temporal.ts
CHANGED
|
@@ -1,227 +1,487 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type SchemaOptions,
|
|
3
|
+
type StringOptions,
|
|
4
|
+
type TString,
|
|
5
|
+
type TTransform,
|
|
6
|
+
Type,
|
|
7
|
+
} from '@sinclair/typebox'
|
|
2
8
|
import { Temporal } from 'temporal-polyfill'
|
|
3
9
|
import { BaseType } from './base.ts'
|
|
4
10
|
|
|
11
|
+
type Types = Exclude<
|
|
12
|
+
keyof typeof Temporal,
|
|
13
|
+
'Now' | 'Instant' | 'Calendar' | 'TimeZone'
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
type TemporalTransformer<T extends Types> = {
|
|
17
|
+
decode: (value: string) => ReturnType<(typeof Temporal)[T]['from']>
|
|
18
|
+
encode: (value: ReturnType<(typeof Temporal)[T]['from']>) => string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const createTemporalTransformer = <T extends Types>(
|
|
22
|
+
type: T,
|
|
23
|
+
decode = (value: string) => Temporal[type].from(value),
|
|
24
|
+
) => {
|
|
25
|
+
const encode = (value: ReturnType<(typeof Temporal)[T]['from']>) =>
|
|
26
|
+
value.toString({
|
|
27
|
+
calendarName: 'never',
|
|
28
|
+
smallestUnit: 'microsecond',
|
|
29
|
+
timeZoneName: 'never',
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
decode,
|
|
34
|
+
encode,
|
|
35
|
+
} as TemporalTransformer<T>
|
|
36
|
+
}
|
|
37
|
+
|
|
5
38
|
export class PlainDateType<
|
|
6
39
|
N extends boolean = false,
|
|
7
40
|
O extends boolean = false,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
41
|
+
D extends boolean = false,
|
|
42
|
+
> extends BaseType<
|
|
43
|
+
TTransform<TString, Temporal.PlainDate>,
|
|
44
|
+
N,
|
|
45
|
+
O,
|
|
46
|
+
D,
|
|
47
|
+
StringOptions
|
|
48
|
+
> {
|
|
49
|
+
static readonly transformer = createTemporalTransformer('PlainDate')
|
|
50
|
+
|
|
51
|
+
constructor(
|
|
52
|
+
options: StringOptions = {},
|
|
53
|
+
isNullable: N = false as N,
|
|
54
|
+
isOptional: O = false as O,
|
|
55
|
+
hasDefault: D = false as D,
|
|
56
|
+
) {
|
|
57
|
+
super(options, isNullable, isOptional, hasDefault)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
protected _constructSchema(
|
|
61
|
+
options: SchemaOptions,
|
|
62
|
+
): TTransform<TString, Temporal.PlainDate> {
|
|
63
|
+
return Type.Transform(Type.String({ ...options, format: 'iso-date' }))
|
|
64
|
+
.Decode(PlainDateType.transformer.decode)
|
|
65
|
+
.Encode(PlainDateType.transformer.encode)
|
|
17
66
|
}
|
|
18
67
|
|
|
19
68
|
nullable() {
|
|
20
|
-
|
|
21
|
-
return new PlainDateType(...args)
|
|
69
|
+
return new PlainDateType(...this._with({ isNullable: true }))
|
|
22
70
|
}
|
|
23
71
|
|
|
24
72
|
optional() {
|
|
25
|
-
|
|
26
|
-
return new PlainDateType(...args)
|
|
73
|
+
return new PlainDateType(...this._with({ isOptional: true }))
|
|
27
74
|
}
|
|
28
75
|
|
|
29
76
|
nullish() {
|
|
30
|
-
|
|
31
|
-
|
|
77
|
+
return new PlainDateType(
|
|
78
|
+
...this._with({ isNullable: true, isOptional: true }),
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
default(value: Temporal.PlainDate) {
|
|
83
|
+
return new PlainDateType(
|
|
84
|
+
...this._with({
|
|
85
|
+
options: { default: PlainDateType.transformer.encode(value) },
|
|
86
|
+
hasDefault: true,
|
|
87
|
+
}),
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
description(description: string) {
|
|
92
|
+
return new PlainDateType(...this._with({ options: { description } }))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
examples(...examples: [Temporal.PlainDate, ...Temporal.PlainDate[]]) {
|
|
96
|
+
return new PlainDateType(
|
|
97
|
+
...this._with({
|
|
98
|
+
options: { examples: examples.map(PlainDateType.transformer.encode) },
|
|
99
|
+
}),
|
|
100
|
+
)
|
|
32
101
|
}
|
|
33
102
|
}
|
|
34
103
|
|
|
35
104
|
export class PlainDateTimeType<
|
|
36
105
|
N extends boolean = false,
|
|
37
106
|
O extends boolean = false,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
107
|
+
D extends boolean = false,
|
|
108
|
+
> extends BaseType<
|
|
109
|
+
TTransform<TString, Temporal.PlainDateTime>,
|
|
110
|
+
N,
|
|
111
|
+
O,
|
|
112
|
+
D,
|
|
113
|
+
StringOptions
|
|
114
|
+
> {
|
|
115
|
+
static readonly transformer = createTemporalTransformer('PlainDateTime')
|
|
116
|
+
|
|
117
|
+
constructor(
|
|
118
|
+
options: StringOptions = {},
|
|
119
|
+
isNullable: N = false as N,
|
|
120
|
+
isOptional: O = false as O,
|
|
121
|
+
hasDefault: D = false as D,
|
|
122
|
+
) {
|
|
123
|
+
super(options, isNullable, isOptional, hasDefault)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
protected _constructSchema(
|
|
127
|
+
options: SchemaOptions,
|
|
128
|
+
): TTransform<TString, Temporal.PlainDateTime> {
|
|
129
|
+
return Type.Transform(Type.String({ ...options, format: 'iso-date-time' }))
|
|
130
|
+
.Decode(PlainDateTimeType.transformer.decode)
|
|
131
|
+
.Encode(PlainDateTimeType.transformer.encode)
|
|
47
132
|
}
|
|
48
133
|
|
|
49
134
|
nullable() {
|
|
50
|
-
|
|
51
|
-
return new PlainDateTimeType(...args)
|
|
135
|
+
return new PlainDateTimeType(...this._with({ isNullable: true }))
|
|
52
136
|
}
|
|
53
137
|
|
|
54
138
|
optional() {
|
|
55
|
-
|
|
56
|
-
return new PlainDateTimeType(...args)
|
|
139
|
+
return new PlainDateTimeType(...this._with({ isOptional: true }))
|
|
57
140
|
}
|
|
58
141
|
|
|
59
142
|
nullish() {
|
|
60
|
-
|
|
61
|
-
|
|
143
|
+
return new PlainDateTimeType(
|
|
144
|
+
...this._with({ isNullable: true, isOptional: true }),
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
default(value: Temporal.PlainDateTime) {
|
|
149
|
+
return new PlainDateTimeType(
|
|
150
|
+
...this._with({
|
|
151
|
+
options: { default: PlainDateTimeType.transformer.encode(value) },
|
|
152
|
+
hasDefault: true,
|
|
153
|
+
}),
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
description(description: string) {
|
|
158
|
+
return new PlainDateTimeType(...this._with({ options: { description } }))
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
examples(...examples: string[]) {
|
|
162
|
+
return new PlainDateTimeType(...this._with({ options: { examples } }))
|
|
62
163
|
}
|
|
63
164
|
}
|
|
64
165
|
|
|
65
166
|
export class ZonedDateTimeType<
|
|
66
167
|
N extends boolean = false,
|
|
67
168
|
O extends boolean = false,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
)
|
|
169
|
+
D extends boolean = false,
|
|
170
|
+
> extends BaseType<
|
|
171
|
+
TTransform<TString, Temporal.ZonedDateTime>,
|
|
172
|
+
N,
|
|
173
|
+
O,
|
|
174
|
+
D,
|
|
175
|
+
StringOptions
|
|
176
|
+
> {
|
|
177
|
+
static readonly transformer = createTemporalTransformer(
|
|
178
|
+
'ZonedDateTime',
|
|
179
|
+
(value) => Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
constructor(
|
|
183
|
+
options: StringOptions = {},
|
|
184
|
+
isNullable: N = false as N,
|
|
185
|
+
isOptional: O = false as O,
|
|
186
|
+
hasDefault: D = false as D,
|
|
187
|
+
) {
|
|
188
|
+
super(options, isNullable, isOptional, hasDefault)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
protected _constructSchema(
|
|
192
|
+
options: SchemaOptions,
|
|
193
|
+
): TTransform<TString, Temporal.ZonedDateTime> {
|
|
194
|
+
return Type.Transform(Type.String({ ...options, format: 'date-time' }))
|
|
195
|
+
.Decode(ZonedDateTimeType.transformer.decode)
|
|
196
|
+
.Encode(ZonedDateTimeType.transformer.encode)
|
|
79
197
|
}
|
|
80
198
|
|
|
81
199
|
nullable() {
|
|
82
|
-
|
|
83
|
-
return new ZonedDateTimeType(...args)
|
|
200
|
+
return new ZonedDateTimeType(...this._with({ isNullable: true }))
|
|
84
201
|
}
|
|
85
202
|
|
|
86
203
|
optional() {
|
|
87
|
-
|
|
88
|
-
return new ZonedDateTimeType(...args)
|
|
204
|
+
return new ZonedDateTimeType(...this._with({ isOptional: true }))
|
|
89
205
|
}
|
|
90
206
|
|
|
91
207
|
nullish() {
|
|
92
|
-
|
|
93
|
-
|
|
208
|
+
return new ZonedDateTimeType(
|
|
209
|
+
...this._with({ isNullable: true, isOptional: true }),
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
default(value: Temporal.ZonedDateTime) {
|
|
214
|
+
return new ZonedDateTimeType(
|
|
215
|
+
...this._with({
|
|
216
|
+
options: { default: ZonedDateTimeType.transformer.encode(value) },
|
|
217
|
+
hasDefault: true,
|
|
218
|
+
}),
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
description(description: string) {
|
|
223
|
+
return new ZonedDateTimeType(...this._with({ options: { description } }))
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
examples(...examples: string[]) {
|
|
227
|
+
return new ZonedDateTimeType(...this._with({ options: { examples } }))
|
|
94
228
|
}
|
|
95
229
|
}
|
|
96
230
|
|
|
97
231
|
export class PlainTimeType<
|
|
98
232
|
N extends boolean = false,
|
|
99
233
|
O extends boolean = false,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
234
|
+
D extends boolean = false,
|
|
235
|
+
> extends BaseType<
|
|
236
|
+
TTransform<TString, Temporal.PlainTime>,
|
|
237
|
+
N,
|
|
238
|
+
O,
|
|
239
|
+
D,
|
|
240
|
+
StringOptions
|
|
241
|
+
> {
|
|
242
|
+
static readonly transformer = createTemporalTransformer('PlainTime')
|
|
243
|
+
|
|
244
|
+
constructor(
|
|
245
|
+
options: StringOptions = {},
|
|
246
|
+
isNullable: N = false as N,
|
|
247
|
+
isOptional: O = false as O,
|
|
248
|
+
hasDefault: D = false as D,
|
|
249
|
+
) {
|
|
250
|
+
super(options, isNullable, isOptional, hasDefault)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
protected _constructSchema(
|
|
254
|
+
options: SchemaOptions,
|
|
255
|
+
): TTransform<TString, Temporal.PlainTime> {
|
|
256
|
+
return Type.Transform(Type.String({ ...options, format: 'time' }))
|
|
257
|
+
.Decode(PlainTimeType.transformer.decode)
|
|
258
|
+
.Encode(PlainTimeType.transformer.encode)
|
|
109
259
|
}
|
|
110
260
|
|
|
111
261
|
nullable() {
|
|
112
|
-
|
|
113
|
-
return new PlainTimeType(...args)
|
|
262
|
+
return new PlainTimeType(...this._with({ isNullable: true }))
|
|
114
263
|
}
|
|
115
264
|
|
|
116
265
|
optional() {
|
|
117
|
-
|
|
118
|
-
return new PlainTimeType(...args)
|
|
266
|
+
return new PlainTimeType(...this._with({ isOptional: true }))
|
|
119
267
|
}
|
|
120
268
|
|
|
121
269
|
nullish() {
|
|
122
|
-
|
|
123
|
-
|
|
270
|
+
return new PlainTimeType(
|
|
271
|
+
...this._with({ isNullable: true, isOptional: true }),
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
default(value: Temporal.PlainTime) {
|
|
276
|
+
return new PlainTimeType(
|
|
277
|
+
...this._with({
|
|
278
|
+
options: { default: PlainTimeType.transformer.encode(value) },
|
|
279
|
+
hasDefault: true,
|
|
280
|
+
}),
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
description(description: string) {
|
|
285
|
+
return new PlainTimeType(...this._with({ options: { description } }))
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
examples(...examples: string[]) {
|
|
289
|
+
return new PlainTimeType(...this._with({ options: { examples } }))
|
|
124
290
|
}
|
|
125
291
|
}
|
|
126
292
|
|
|
127
293
|
export class DurationType<
|
|
128
294
|
N extends boolean = false,
|
|
129
295
|
O extends boolean = false,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
296
|
+
D extends boolean = false,
|
|
297
|
+
> extends BaseType<
|
|
298
|
+
TTransform<TString, Temporal.Duration>,
|
|
299
|
+
N,
|
|
300
|
+
O,
|
|
301
|
+
D,
|
|
302
|
+
StringOptions
|
|
303
|
+
> {
|
|
304
|
+
static readonly transformer = createTemporalTransformer('Duration')
|
|
305
|
+
|
|
306
|
+
constructor(
|
|
307
|
+
options: StringOptions = {},
|
|
308
|
+
isNullable: N = false as N,
|
|
309
|
+
isOptional: O = false as O,
|
|
310
|
+
hasDefault: D = false as D,
|
|
311
|
+
) {
|
|
312
|
+
super(options, isNullable, isOptional, hasDefault)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
protected _constructSchema(
|
|
316
|
+
options: SchemaOptions,
|
|
317
|
+
): TTransform<TString, Temporal.Duration> {
|
|
318
|
+
return Type.Transform(Type.String({ ...options, format: 'duration' }))
|
|
319
|
+
.Decode(DurationType.transformer.decode)
|
|
320
|
+
.Encode(DurationType.transformer.encode)
|
|
143
321
|
}
|
|
144
322
|
|
|
145
323
|
nullable() {
|
|
146
|
-
|
|
147
|
-
return new DurationType(...args)
|
|
324
|
+
return new DurationType(...this._with({ isNullable: true }))
|
|
148
325
|
}
|
|
149
326
|
|
|
150
327
|
optional() {
|
|
151
|
-
|
|
152
|
-
return new DurationType(...args)
|
|
328
|
+
return new DurationType(...this._with({ isOptional: true }))
|
|
153
329
|
}
|
|
154
330
|
|
|
155
331
|
nullish() {
|
|
156
|
-
|
|
157
|
-
|
|
332
|
+
return new DurationType(
|
|
333
|
+
...this._with({ isNullable: true, isOptional: true }),
|
|
334
|
+
)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
default(value: Temporal.Duration) {
|
|
338
|
+
return new DurationType(
|
|
339
|
+
...this._with({
|
|
340
|
+
options: { default: DurationType.transformer.encode(value) },
|
|
341
|
+
hasDefault: true,
|
|
342
|
+
}),
|
|
343
|
+
)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
description(description: string) {
|
|
347
|
+
return new DurationType(...this._with({ options: { description } }))
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
examples(...examples: string[]) {
|
|
351
|
+
return new DurationType(...this._with({ options: { examples } }))
|
|
158
352
|
}
|
|
159
353
|
}
|
|
160
354
|
|
|
161
355
|
export class PlainYearMonthType<
|
|
162
356
|
N extends boolean = false,
|
|
163
357
|
O extends boolean = false,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
358
|
+
D extends boolean = false,
|
|
359
|
+
> extends BaseType<
|
|
360
|
+
TTransform<TString, Temporal.PlainYearMonth>,
|
|
361
|
+
N,
|
|
362
|
+
O,
|
|
363
|
+
D,
|
|
364
|
+
StringOptions
|
|
365
|
+
> {
|
|
366
|
+
static readonly transformer = createTemporalTransformer('PlainYearMonth')
|
|
367
|
+
|
|
368
|
+
constructor(
|
|
369
|
+
options: StringOptions = {},
|
|
370
|
+
isNullable: N = false as N,
|
|
371
|
+
isOptional: O = false as O,
|
|
372
|
+
hasDefault: D = false as D,
|
|
373
|
+
) {
|
|
374
|
+
super(options, isNullable, isOptional, hasDefault)
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
protected _constructSchema(
|
|
378
|
+
options: SchemaOptions,
|
|
379
|
+
): TTransform<TString, Temporal.PlainYearMonth> {
|
|
380
|
+
return Type.Transform(
|
|
381
|
+
Type.String({
|
|
382
|
+
...options,
|
|
383
|
+
// TODO: duration format, or regex?
|
|
384
|
+
}),
|
|
176
385
|
)
|
|
386
|
+
.Decode(PlainYearMonthType.transformer.decode)
|
|
387
|
+
.Encode(PlainYearMonthType.transformer.encode)
|
|
177
388
|
}
|
|
178
389
|
|
|
179
390
|
nullable() {
|
|
180
|
-
|
|
181
|
-
return new PlainYearMonthType(...args)
|
|
391
|
+
return new PlainYearMonthType(...this._with({ isNullable: true }))
|
|
182
392
|
}
|
|
183
393
|
|
|
184
394
|
optional() {
|
|
185
|
-
|
|
186
|
-
return new PlainYearMonthType(...args)
|
|
395
|
+
return new PlainYearMonthType(...this._with({ isOptional: true }))
|
|
187
396
|
}
|
|
188
397
|
|
|
189
398
|
nullish() {
|
|
190
|
-
|
|
191
|
-
|
|
399
|
+
return new PlainYearMonthType(
|
|
400
|
+
...this._with({ isNullable: true, isOptional: true }),
|
|
401
|
+
)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
default(value: Temporal.PlainYearMonth) {
|
|
405
|
+
return new PlainYearMonthType(
|
|
406
|
+
...this._with({
|
|
407
|
+
options: { default: PlainYearMonthType.transformer.encode(value) },
|
|
408
|
+
hasDefault: true,
|
|
409
|
+
}),
|
|
410
|
+
)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
description(description: string) {
|
|
414
|
+
return new PlainYearMonthType(...this._with({ options: { description } }))
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
examples(...examples: string[]) {
|
|
418
|
+
return new PlainYearMonthType(...this._with({ options: { examples } }))
|
|
192
419
|
}
|
|
193
420
|
}
|
|
194
421
|
|
|
195
422
|
export class PlainMonthDayType<
|
|
196
423
|
N extends boolean = false,
|
|
197
424
|
O extends boolean = false,
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
425
|
+
D extends boolean = false,
|
|
426
|
+
> extends BaseType<
|
|
427
|
+
TTransform<TString, Temporal.PlainMonthDay>,
|
|
428
|
+
N,
|
|
429
|
+
O,
|
|
430
|
+
D,
|
|
431
|
+
StringOptions
|
|
432
|
+
> {
|
|
433
|
+
static readonly transformer = createTemporalTransformer('PlainMonthDay')
|
|
434
|
+
|
|
435
|
+
constructor(
|
|
436
|
+
options: StringOptions = {},
|
|
437
|
+
isNullable: N = false as N,
|
|
438
|
+
isOptional: O = false as O,
|
|
439
|
+
hasDefault: D = false as D,
|
|
440
|
+
) {
|
|
441
|
+
super(options, isNullable, isOptional, hasDefault)
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
protected _constructSchema(
|
|
445
|
+
options: SchemaOptions,
|
|
446
|
+
): TTransform<TString, Temporal.PlainMonthDay> {
|
|
447
|
+
return Type.Transform(
|
|
448
|
+
Type.String({
|
|
449
|
+
...options,
|
|
450
|
+
// TODO: duration format, or regex?
|
|
451
|
+
}),
|
|
210
452
|
)
|
|
453
|
+
.Decode(PlainMonthDayType.transformer.decode)
|
|
454
|
+
.Encode(PlainMonthDayType.transformer.encode)
|
|
211
455
|
}
|
|
212
456
|
|
|
213
457
|
nullable() {
|
|
214
|
-
|
|
215
|
-
return new PlainMonthDayType(...args)
|
|
458
|
+
return new PlainMonthDayType(...this._with({ isNullable: true }))
|
|
216
459
|
}
|
|
217
460
|
|
|
218
461
|
optional() {
|
|
219
|
-
|
|
220
|
-
return new PlainMonthDayType(...args)
|
|
462
|
+
return new PlainMonthDayType(...this._with({ isOptional: true }))
|
|
221
463
|
}
|
|
222
464
|
|
|
223
465
|
nullish() {
|
|
224
|
-
|
|
225
|
-
|
|
466
|
+
return new PlainMonthDayType(
|
|
467
|
+
...this._with({ isNullable: true, isOptional: true }),
|
|
468
|
+
)
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
default(value: Temporal.PlainMonthDay) {
|
|
472
|
+
return new PlainMonthDayType(
|
|
473
|
+
...this._with({
|
|
474
|
+
options: { default: PlainMonthDayType.transformer.encode(value) },
|
|
475
|
+
hasDefault: true,
|
|
476
|
+
}),
|
|
477
|
+
)
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
description(description: string) {
|
|
481
|
+
return new PlainMonthDayType(...this._with({ options: { description } }))
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
examples(...examples: string[]) {
|
|
485
|
+
return new PlainMonthDayType(...this._with({ options: { examples } }))
|
|
226
486
|
}
|
|
227
487
|
}
|