@tsgonest/types 0.7.4 → 0.7.5
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/tags.d.cts +194 -75
- package/dist/tags.d.cts.map +1 -1
- package/dist/tags.d.mts +194 -75
- package/dist/tags.d.mts.map +1 -1
- package/dist/tags.mjs.map +1 -1
- package/package.json +1 -1
package/dist/tags.d.cts
CHANGED
|
@@ -36,28 +36,6 @@ declare namespace tags_d_exports {
|
|
|
36
36
|
* active: boolean & Coerce;
|
|
37
37
|
* }
|
|
38
38
|
*/
|
|
39
|
-
/** Extract the value from a dual-form number constraint. */
|
|
40
|
-
type NumVal<N extends number | {
|
|
41
|
-
value: number;
|
|
42
|
-
error?: string;
|
|
43
|
-
}> = N extends {
|
|
44
|
-
value: infer V;
|
|
45
|
-
} ? V : N;
|
|
46
|
-
/** Extract the value from a dual-form string constraint. */
|
|
47
|
-
type StrVal<S extends string | {
|
|
48
|
-
value: string;
|
|
49
|
-
error?: string;
|
|
50
|
-
}> = S extends {
|
|
51
|
-
value: infer V;
|
|
52
|
-
} ? V : S;
|
|
53
|
-
/** Extract the type from a dual-form type constraint (Format, Type). */
|
|
54
|
-
type TypeVal<T, Base> = T extends {
|
|
55
|
-
type: infer V;
|
|
56
|
-
} ? V : T;
|
|
57
|
-
/** Conditionally add an optional _error phantom property. */
|
|
58
|
-
type WithErr<Prefix extends string, C> = C extends {
|
|
59
|
-
error: infer E extends string;
|
|
60
|
-
} ? { readonly [K in `${Prefix}_error`]?: E } : {};
|
|
61
39
|
/** All supported string format values. */
|
|
62
40
|
type FormatValue = "email" | "idn-email" | "url" | "uri" | "uri-reference" | "uri-template" | "iri" | "iri-reference" | "uuid" | "ipv4" | "ipv6" | "hostname" | "idn-hostname" | "date-time" | "date" | "time" | "duration" | "json-pointer" | "relative-json-pointer" | "byte" | "password" | "regex" | "nanoid" | "cuid" | "cuid2" | "ulid" | "jwt" | "base64url" | "hex" | "mac" | "cidrv4" | "cidrv6" | "emoji";
|
|
63
41
|
/**
|
|
@@ -70,9 +48,17 @@ type FormatValue = "email" | "idn-email" | "url" | "uri" | "uri-reference" | "ur
|
|
|
70
48
|
type Format<F extends FormatValue | {
|
|
71
49
|
type: FormatValue;
|
|
72
50
|
error?: string;
|
|
73
|
-
}> = {
|
|
74
|
-
|
|
75
|
-
|
|
51
|
+
}> = F extends {
|
|
52
|
+
type: infer V;
|
|
53
|
+
error: infer E extends string;
|
|
54
|
+
} ? {
|
|
55
|
+
readonly __tsgonest_format?: V;
|
|
56
|
+
readonly __tsgonest_format_error?: E;
|
|
57
|
+
} : {
|
|
58
|
+
readonly __tsgonest_format?: F extends {
|
|
59
|
+
type: infer V;
|
|
60
|
+
} ? V : F;
|
|
61
|
+
};
|
|
76
62
|
/**
|
|
77
63
|
* Minimum string length.
|
|
78
64
|
* @example MinLength<1> or MinLength<{value: 1, error: "Cannot be empty"}>
|
|
@@ -80,9 +66,17 @@ type Format<F extends FormatValue | {
|
|
|
80
66
|
type MinLength<N extends number | {
|
|
81
67
|
value: number;
|
|
82
68
|
error?: string;
|
|
83
|
-
}> = {
|
|
84
|
-
|
|
85
|
-
|
|
69
|
+
}> = N extends {
|
|
70
|
+
value: infer V extends number;
|
|
71
|
+
error: infer E extends string;
|
|
72
|
+
} ? {
|
|
73
|
+
readonly __tsgonest_minLength?: V;
|
|
74
|
+
readonly __tsgonest_minLength_error?: E;
|
|
75
|
+
} : {
|
|
76
|
+
readonly __tsgonest_minLength?: N extends {
|
|
77
|
+
value: infer V;
|
|
78
|
+
} ? V : N;
|
|
79
|
+
};
|
|
86
80
|
/**
|
|
87
81
|
* Maximum string length.
|
|
88
82
|
* @example MaxLength<255> or MaxLength<{value: 255, error: "Too long"}>
|
|
@@ -90,9 +84,17 @@ type MinLength<N extends number | {
|
|
|
90
84
|
type MaxLength<N extends number | {
|
|
91
85
|
value: number;
|
|
92
86
|
error?: string;
|
|
93
|
-
}> = {
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
}> = N extends {
|
|
88
|
+
value: infer V extends number;
|
|
89
|
+
error: infer E extends string;
|
|
90
|
+
} ? {
|
|
91
|
+
readonly __tsgonest_maxLength?: V;
|
|
92
|
+
readonly __tsgonest_maxLength_error?: E;
|
|
93
|
+
} : {
|
|
94
|
+
readonly __tsgonest_maxLength?: N extends {
|
|
95
|
+
value: infer V;
|
|
96
|
+
} ? V : N;
|
|
97
|
+
};
|
|
96
98
|
/**
|
|
97
99
|
* Regex pattern constraint.
|
|
98
100
|
* @example Pattern<"^[a-z]+$"> or Pattern<{value: "^[a-z]+$", error: "Letters only"}>
|
|
@@ -100,9 +102,17 @@ type MaxLength<N extends number | {
|
|
|
100
102
|
type Pattern<P extends string | {
|
|
101
103
|
value: string;
|
|
102
104
|
error?: string;
|
|
103
|
-
}> = {
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
}> = P extends {
|
|
106
|
+
value: infer V extends string;
|
|
107
|
+
error: infer E extends string;
|
|
108
|
+
} ? {
|
|
109
|
+
readonly __tsgonest_pattern?: V;
|
|
110
|
+
readonly __tsgonest_pattern_error?: E;
|
|
111
|
+
} : {
|
|
112
|
+
readonly __tsgonest_pattern?: P extends {
|
|
113
|
+
value: infer V;
|
|
114
|
+
} ? V : P;
|
|
115
|
+
};
|
|
106
116
|
/**
|
|
107
117
|
* String must start with prefix.
|
|
108
118
|
* @example StartsWith<"https://">
|
|
@@ -110,9 +120,17 @@ type Pattern<P extends string | {
|
|
|
110
120
|
type StartsWith<S extends string | {
|
|
111
121
|
value: string;
|
|
112
122
|
error?: string;
|
|
113
|
-
}> = {
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
}> = S extends {
|
|
124
|
+
value: infer V extends string;
|
|
125
|
+
error: infer E extends string;
|
|
126
|
+
} ? {
|
|
127
|
+
readonly __tsgonest_startsWith?: V;
|
|
128
|
+
readonly __tsgonest_startsWith_error?: E;
|
|
129
|
+
} : {
|
|
130
|
+
readonly __tsgonest_startsWith?: S extends {
|
|
131
|
+
value: infer V;
|
|
132
|
+
} ? V : S;
|
|
133
|
+
};
|
|
116
134
|
/**
|
|
117
135
|
* String must end with suffix.
|
|
118
136
|
* @example EndsWith<".json">
|
|
@@ -120,9 +138,17 @@ type StartsWith<S extends string | {
|
|
|
120
138
|
type EndsWith<S extends string | {
|
|
121
139
|
value: string;
|
|
122
140
|
error?: string;
|
|
123
|
-
}> = {
|
|
124
|
-
|
|
125
|
-
|
|
141
|
+
}> = S extends {
|
|
142
|
+
value: infer V extends string;
|
|
143
|
+
error: infer E extends string;
|
|
144
|
+
} ? {
|
|
145
|
+
readonly __tsgonest_endsWith?: V;
|
|
146
|
+
readonly __tsgonest_endsWith_error?: E;
|
|
147
|
+
} : {
|
|
148
|
+
readonly __tsgonest_endsWith?: S extends {
|
|
149
|
+
value: infer V;
|
|
150
|
+
} ? V : S;
|
|
151
|
+
};
|
|
126
152
|
/**
|
|
127
153
|
* String must contain substring.
|
|
128
154
|
* @example Includes<"@">
|
|
@@ -130,9 +156,17 @@ type EndsWith<S extends string | {
|
|
|
130
156
|
type Includes<S extends string | {
|
|
131
157
|
value: string;
|
|
132
158
|
error?: string;
|
|
133
|
-
}> = {
|
|
134
|
-
|
|
135
|
-
|
|
159
|
+
}> = S extends {
|
|
160
|
+
value: infer V extends string;
|
|
161
|
+
error: infer E extends string;
|
|
162
|
+
} ? {
|
|
163
|
+
readonly __tsgonest_includes?: V;
|
|
164
|
+
readonly __tsgonest_includes_error?: E;
|
|
165
|
+
} : {
|
|
166
|
+
readonly __tsgonest_includes?: S extends {
|
|
167
|
+
value: infer V;
|
|
168
|
+
} ? V : S;
|
|
169
|
+
};
|
|
136
170
|
/**
|
|
137
171
|
* Minimum value (inclusive): value >= N.
|
|
138
172
|
* @example Minimum<0> or Min<0> or Min<{value: 0, error: "Must be non-negative"}>
|
|
@@ -140,9 +174,17 @@ type Includes<S extends string | {
|
|
|
140
174
|
type Minimum<N extends number | {
|
|
141
175
|
value: number;
|
|
142
176
|
error?: string;
|
|
143
|
-
}> = {
|
|
144
|
-
|
|
145
|
-
|
|
177
|
+
}> = N extends {
|
|
178
|
+
value: infer V extends number;
|
|
179
|
+
error: infer E extends string;
|
|
180
|
+
} ? {
|
|
181
|
+
readonly __tsgonest_minimum?: V;
|
|
182
|
+
readonly __tsgonest_minimum_error?: E;
|
|
183
|
+
} : {
|
|
184
|
+
readonly __tsgonest_minimum?: N extends {
|
|
185
|
+
value: infer V;
|
|
186
|
+
} ? V : N;
|
|
187
|
+
};
|
|
146
188
|
/**
|
|
147
189
|
* Maximum value (inclusive): value <= N.
|
|
148
190
|
* @example Maximum<100> or Max<100>
|
|
@@ -150,9 +192,17 @@ type Minimum<N extends number | {
|
|
|
150
192
|
type Maximum<N extends number | {
|
|
151
193
|
value: number;
|
|
152
194
|
error?: string;
|
|
153
|
-
}> = {
|
|
154
|
-
|
|
155
|
-
|
|
195
|
+
}> = N extends {
|
|
196
|
+
value: infer V extends number;
|
|
197
|
+
error: infer E extends string;
|
|
198
|
+
} ? {
|
|
199
|
+
readonly __tsgonest_maximum?: V;
|
|
200
|
+
readonly __tsgonest_maximum_error?: E;
|
|
201
|
+
} : {
|
|
202
|
+
readonly __tsgonest_maximum?: N extends {
|
|
203
|
+
value: infer V;
|
|
204
|
+
} ? V : N;
|
|
205
|
+
};
|
|
156
206
|
/**
|
|
157
207
|
* Exclusive minimum: value > N.
|
|
158
208
|
* @example ExclusiveMinimum<0> or Gt<0>
|
|
@@ -160,9 +210,17 @@ type Maximum<N extends number | {
|
|
|
160
210
|
type ExclusiveMinimum<N extends number | {
|
|
161
211
|
value: number;
|
|
162
212
|
error?: string;
|
|
163
|
-
}> = {
|
|
164
|
-
|
|
165
|
-
|
|
213
|
+
}> = N extends {
|
|
214
|
+
value: infer V extends number;
|
|
215
|
+
error: infer E extends string;
|
|
216
|
+
} ? {
|
|
217
|
+
readonly __tsgonest_exclusiveMinimum?: V;
|
|
218
|
+
readonly __tsgonest_exclusiveMinimum_error?: E;
|
|
219
|
+
} : {
|
|
220
|
+
readonly __tsgonest_exclusiveMinimum?: N extends {
|
|
221
|
+
value: infer V;
|
|
222
|
+
} ? V : N;
|
|
223
|
+
};
|
|
166
224
|
/**
|
|
167
225
|
* Exclusive maximum: value < N.
|
|
168
226
|
* @example ExclusiveMaximum<100> or Lt<100>
|
|
@@ -170,9 +228,17 @@ type ExclusiveMinimum<N extends number | {
|
|
|
170
228
|
type ExclusiveMaximum<N extends number | {
|
|
171
229
|
value: number;
|
|
172
230
|
error?: string;
|
|
173
|
-
}> = {
|
|
174
|
-
|
|
175
|
-
|
|
231
|
+
}> = N extends {
|
|
232
|
+
value: infer V extends number;
|
|
233
|
+
error: infer E extends string;
|
|
234
|
+
} ? {
|
|
235
|
+
readonly __tsgonest_exclusiveMaximum?: V;
|
|
236
|
+
readonly __tsgonest_exclusiveMaximum_error?: E;
|
|
237
|
+
} : {
|
|
238
|
+
readonly __tsgonest_exclusiveMaximum?: N extends {
|
|
239
|
+
value: infer V;
|
|
240
|
+
} ? V : N;
|
|
241
|
+
};
|
|
176
242
|
/**
|
|
177
243
|
* Value must be a multiple of N.
|
|
178
244
|
* @example MultipleOf<2> or Step<0.01>
|
|
@@ -180,9 +246,17 @@ type ExclusiveMaximum<N extends number | {
|
|
|
180
246
|
type MultipleOf<N extends number | {
|
|
181
247
|
value: number;
|
|
182
248
|
error?: string;
|
|
183
|
-
}> = {
|
|
184
|
-
|
|
185
|
-
|
|
249
|
+
}> = N extends {
|
|
250
|
+
value: infer V extends number;
|
|
251
|
+
error: infer E extends string;
|
|
252
|
+
} ? {
|
|
253
|
+
readonly __tsgonest_multipleOf?: V;
|
|
254
|
+
readonly __tsgonest_multipleOf_error?: E;
|
|
255
|
+
} : {
|
|
256
|
+
readonly __tsgonest_multipleOf?: N extends {
|
|
257
|
+
value: infer V;
|
|
258
|
+
} ? V : N;
|
|
259
|
+
};
|
|
186
260
|
/** Valid numeric type values. */
|
|
187
261
|
type NumericTypeValue = "int32" | "uint32" | "int64" | "uint64" | "float" | "double";
|
|
188
262
|
/**
|
|
@@ -192,9 +266,17 @@ type NumericTypeValue = "int32" | "uint32" | "int64" | "uint64" | "float" | "dou
|
|
|
192
266
|
type Type<T extends NumericTypeValue | {
|
|
193
267
|
type: NumericTypeValue;
|
|
194
268
|
error?: string;
|
|
195
|
-
}> = {
|
|
196
|
-
|
|
197
|
-
|
|
269
|
+
}> = T extends {
|
|
270
|
+
type: infer V;
|
|
271
|
+
error: infer E extends string;
|
|
272
|
+
} ? {
|
|
273
|
+
readonly __tsgonest_type?: V;
|
|
274
|
+
readonly __tsgonest_type_error?: E;
|
|
275
|
+
} : {
|
|
276
|
+
readonly __tsgonest_type?: T extends {
|
|
277
|
+
type: infer V;
|
|
278
|
+
} ? V : T;
|
|
279
|
+
};
|
|
198
280
|
/**
|
|
199
281
|
* Minimum array length.
|
|
200
282
|
* @example MinItems<1>
|
|
@@ -202,9 +284,17 @@ type Type<T extends NumericTypeValue | {
|
|
|
202
284
|
type MinItems<N extends number | {
|
|
203
285
|
value: number;
|
|
204
286
|
error?: string;
|
|
205
|
-
}> = {
|
|
206
|
-
|
|
207
|
-
|
|
287
|
+
}> = N extends {
|
|
288
|
+
value: infer V extends number;
|
|
289
|
+
error: infer E extends string;
|
|
290
|
+
} ? {
|
|
291
|
+
readonly __tsgonest_minItems?: V;
|
|
292
|
+
readonly __tsgonest_minItems_error?: E;
|
|
293
|
+
} : {
|
|
294
|
+
readonly __tsgonest_minItems?: N extends {
|
|
295
|
+
value: infer V;
|
|
296
|
+
} ? V : N;
|
|
297
|
+
};
|
|
208
298
|
/**
|
|
209
299
|
* Maximum array length.
|
|
210
300
|
* @example MaxItems<100>
|
|
@@ -212,36 +302,59 @@ type MinItems<N extends number | {
|
|
|
212
302
|
type MaxItems<N extends number | {
|
|
213
303
|
value: number;
|
|
214
304
|
error?: string;
|
|
215
|
-
}> = {
|
|
216
|
-
|
|
217
|
-
|
|
305
|
+
}> = N extends {
|
|
306
|
+
value: infer V extends number;
|
|
307
|
+
error: infer E extends string;
|
|
308
|
+
} ? {
|
|
309
|
+
readonly __tsgonest_maxItems?: V;
|
|
310
|
+
readonly __tsgonest_maxItems_error?: E;
|
|
311
|
+
} : {
|
|
312
|
+
readonly __tsgonest_maxItems?: N extends {
|
|
313
|
+
value: infer V;
|
|
314
|
+
} ? V : N;
|
|
315
|
+
};
|
|
218
316
|
/**
|
|
219
317
|
* Array items must be unique.
|
|
220
318
|
* @example UniqueItems or Unique or Unique<{error: "No duplicates"}>
|
|
221
319
|
*/
|
|
222
320
|
type UniqueItems<C extends {
|
|
223
321
|
error?: string;
|
|
224
|
-
} = {}> = {
|
|
322
|
+
} = {}> = C extends {
|
|
323
|
+
error: infer E extends string;
|
|
324
|
+
} ? {
|
|
325
|
+
readonly __tsgonest_uniqueItems?: true;
|
|
326
|
+
readonly __tsgonest_uniqueItems_error?: E;
|
|
327
|
+
} : {
|
|
225
328
|
readonly __tsgonest_uniqueItems?: true;
|
|
226
|
-
}
|
|
329
|
+
};
|
|
227
330
|
/**
|
|
228
331
|
* String must be all uppercase.
|
|
229
332
|
* @example Uppercase or Uppercase<{error: "Must be uppercase"}>
|
|
230
333
|
*/
|
|
231
334
|
type Uppercase<C extends {
|
|
232
335
|
error?: string;
|
|
233
|
-
} = {}> = {
|
|
336
|
+
} = {}> = C extends {
|
|
337
|
+
error: infer E extends string;
|
|
338
|
+
} ? {
|
|
339
|
+
readonly __tsgonest_uppercase?: true;
|
|
340
|
+
readonly __tsgonest_uppercase_error?: E;
|
|
341
|
+
} : {
|
|
234
342
|
readonly __tsgonest_uppercase?: true;
|
|
235
|
-
}
|
|
343
|
+
};
|
|
236
344
|
/**
|
|
237
345
|
* String must be all lowercase.
|
|
238
346
|
* @example Lowercase or Lowercase<{error: "Must be lowercase"}>
|
|
239
347
|
*/
|
|
240
348
|
type Lowercase<C extends {
|
|
241
349
|
error?: string;
|
|
242
|
-
} = {}> = {
|
|
350
|
+
} = {}> = C extends {
|
|
351
|
+
error: infer E extends string;
|
|
352
|
+
} ? {
|
|
243
353
|
readonly __tsgonest_lowercase?: true;
|
|
244
|
-
|
|
354
|
+
readonly __tsgonest_lowercase_error?: E;
|
|
355
|
+
} : {
|
|
356
|
+
readonly __tsgonest_lowercase?: true;
|
|
357
|
+
};
|
|
245
358
|
/** Trim whitespace before validation. */
|
|
246
359
|
type Trim = {
|
|
247
360
|
readonly __tsgonest_transform_trim?: true;
|
|
@@ -282,11 +395,17 @@ type Coerce = {
|
|
|
282
395
|
type Validate<F extends ((...args: any[]) => boolean) | {
|
|
283
396
|
fn: (...args: any[]) => boolean;
|
|
284
397
|
error?: string;
|
|
285
|
-
}> = {
|
|
398
|
+
}> = F extends {
|
|
399
|
+
fn: infer Fn;
|
|
400
|
+
error: infer E extends string;
|
|
401
|
+
} ? {
|
|
402
|
+
readonly __tsgonest_validate?: Fn;
|
|
403
|
+
readonly __tsgonest_validate_error?: E;
|
|
404
|
+
} : {
|
|
286
405
|
readonly __tsgonest_validate?: F extends {
|
|
287
406
|
fn: infer Fn;
|
|
288
407
|
} ? Fn : F;
|
|
289
|
-
}
|
|
408
|
+
};
|
|
290
409
|
/**
|
|
291
410
|
* Global error message — applies to all validation failures on this property.
|
|
292
411
|
* Per-constraint errors (via `error` field) take precedence.
|
package/dist/tags.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.d.cts","names":[],"sources":["../src/tags.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"tags.d.cts","names":[],"sources":["../src/tags.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoDY,WAAA;;;;;;;;KAoBA,MAAA,WAAiB,WAAA;EAAgB,IAAA,EAAM,WAAA;EAAa,KAAA;AAAA,KAC9D,CAAA;EAAY,IAAA;EAAe,KAAA;AAAA;EAAA,SACZ,iBAAA,GAAoB,CAAA;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,MAAA;AAAA,KACP,QAAA,GAAW,MAAA;AAAA,KACX,GAAA,GAAM,MAAA;AAAA,KACN,IAAA,GAAO,MAAA;AAAA,KACP,IAAA,GAAO,MAAA;AAAA,KACP,KAAA,GAAQ,MAAA;AAAA,KACR,MAAA,GAAS,MAAA;;KAOT,QAAA,GAAW,gBAAA;;KAGX,QAAA,GAAW,gBAAA;;KAGX,WAAA,GAAc,OAAA;;KAGd,WAAA,GAAc,OAAA;;KAGd,GAAA,GAAM,IAAA;;KAGN,OAAA,GAAU,IAAA;;KAGV,MAAA,GAAS,IAAA;;KAGT,IAAA,GAAO,IAAA;;KAGP,MAAA,GAAS,IAAA"}
|
package/dist/tags.d.mts
CHANGED
|
@@ -36,28 +36,6 @@ declare namespace tags_d_exports {
|
|
|
36
36
|
* active: boolean & Coerce;
|
|
37
37
|
* }
|
|
38
38
|
*/
|
|
39
|
-
/** Extract the value from a dual-form number constraint. */
|
|
40
|
-
type NumVal<N extends number | {
|
|
41
|
-
value: number;
|
|
42
|
-
error?: string;
|
|
43
|
-
}> = N extends {
|
|
44
|
-
value: infer V;
|
|
45
|
-
} ? V : N;
|
|
46
|
-
/** Extract the value from a dual-form string constraint. */
|
|
47
|
-
type StrVal<S extends string | {
|
|
48
|
-
value: string;
|
|
49
|
-
error?: string;
|
|
50
|
-
}> = S extends {
|
|
51
|
-
value: infer V;
|
|
52
|
-
} ? V : S;
|
|
53
|
-
/** Extract the type from a dual-form type constraint (Format, Type). */
|
|
54
|
-
type TypeVal<T, Base> = T extends {
|
|
55
|
-
type: infer V;
|
|
56
|
-
} ? V : T;
|
|
57
|
-
/** Conditionally add an optional _error phantom property. */
|
|
58
|
-
type WithErr<Prefix extends string, C> = C extends {
|
|
59
|
-
error: infer E extends string;
|
|
60
|
-
} ? { readonly [K in `${Prefix}_error`]?: E } : {};
|
|
61
39
|
/** All supported string format values. */
|
|
62
40
|
type FormatValue = "email" | "idn-email" | "url" | "uri" | "uri-reference" | "uri-template" | "iri" | "iri-reference" | "uuid" | "ipv4" | "ipv6" | "hostname" | "idn-hostname" | "date-time" | "date" | "time" | "duration" | "json-pointer" | "relative-json-pointer" | "byte" | "password" | "regex" | "nanoid" | "cuid" | "cuid2" | "ulid" | "jwt" | "base64url" | "hex" | "mac" | "cidrv4" | "cidrv6" | "emoji";
|
|
63
41
|
/**
|
|
@@ -70,9 +48,17 @@ type FormatValue = "email" | "idn-email" | "url" | "uri" | "uri-reference" | "ur
|
|
|
70
48
|
type Format<F extends FormatValue | {
|
|
71
49
|
type: FormatValue;
|
|
72
50
|
error?: string;
|
|
73
|
-
}> = {
|
|
74
|
-
|
|
75
|
-
|
|
51
|
+
}> = F extends {
|
|
52
|
+
type: infer V;
|
|
53
|
+
error: infer E extends string;
|
|
54
|
+
} ? {
|
|
55
|
+
readonly __tsgonest_format?: V;
|
|
56
|
+
readonly __tsgonest_format_error?: E;
|
|
57
|
+
} : {
|
|
58
|
+
readonly __tsgonest_format?: F extends {
|
|
59
|
+
type: infer V;
|
|
60
|
+
} ? V : F;
|
|
61
|
+
};
|
|
76
62
|
/**
|
|
77
63
|
* Minimum string length.
|
|
78
64
|
* @example MinLength<1> or MinLength<{value: 1, error: "Cannot be empty"}>
|
|
@@ -80,9 +66,17 @@ type Format<F extends FormatValue | {
|
|
|
80
66
|
type MinLength<N extends number | {
|
|
81
67
|
value: number;
|
|
82
68
|
error?: string;
|
|
83
|
-
}> = {
|
|
84
|
-
|
|
85
|
-
|
|
69
|
+
}> = N extends {
|
|
70
|
+
value: infer V extends number;
|
|
71
|
+
error: infer E extends string;
|
|
72
|
+
} ? {
|
|
73
|
+
readonly __tsgonest_minLength?: V;
|
|
74
|
+
readonly __tsgonest_minLength_error?: E;
|
|
75
|
+
} : {
|
|
76
|
+
readonly __tsgonest_minLength?: N extends {
|
|
77
|
+
value: infer V;
|
|
78
|
+
} ? V : N;
|
|
79
|
+
};
|
|
86
80
|
/**
|
|
87
81
|
* Maximum string length.
|
|
88
82
|
* @example MaxLength<255> or MaxLength<{value: 255, error: "Too long"}>
|
|
@@ -90,9 +84,17 @@ type MinLength<N extends number | {
|
|
|
90
84
|
type MaxLength<N extends number | {
|
|
91
85
|
value: number;
|
|
92
86
|
error?: string;
|
|
93
|
-
}> = {
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
}> = N extends {
|
|
88
|
+
value: infer V extends number;
|
|
89
|
+
error: infer E extends string;
|
|
90
|
+
} ? {
|
|
91
|
+
readonly __tsgonest_maxLength?: V;
|
|
92
|
+
readonly __tsgonest_maxLength_error?: E;
|
|
93
|
+
} : {
|
|
94
|
+
readonly __tsgonest_maxLength?: N extends {
|
|
95
|
+
value: infer V;
|
|
96
|
+
} ? V : N;
|
|
97
|
+
};
|
|
96
98
|
/**
|
|
97
99
|
* Regex pattern constraint.
|
|
98
100
|
* @example Pattern<"^[a-z]+$"> or Pattern<{value: "^[a-z]+$", error: "Letters only"}>
|
|
@@ -100,9 +102,17 @@ type MaxLength<N extends number | {
|
|
|
100
102
|
type Pattern<P extends string | {
|
|
101
103
|
value: string;
|
|
102
104
|
error?: string;
|
|
103
|
-
}> = {
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
}> = P extends {
|
|
106
|
+
value: infer V extends string;
|
|
107
|
+
error: infer E extends string;
|
|
108
|
+
} ? {
|
|
109
|
+
readonly __tsgonest_pattern?: V;
|
|
110
|
+
readonly __tsgonest_pattern_error?: E;
|
|
111
|
+
} : {
|
|
112
|
+
readonly __tsgonest_pattern?: P extends {
|
|
113
|
+
value: infer V;
|
|
114
|
+
} ? V : P;
|
|
115
|
+
};
|
|
106
116
|
/**
|
|
107
117
|
* String must start with prefix.
|
|
108
118
|
* @example StartsWith<"https://">
|
|
@@ -110,9 +120,17 @@ type Pattern<P extends string | {
|
|
|
110
120
|
type StartsWith<S extends string | {
|
|
111
121
|
value: string;
|
|
112
122
|
error?: string;
|
|
113
|
-
}> = {
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
}> = S extends {
|
|
124
|
+
value: infer V extends string;
|
|
125
|
+
error: infer E extends string;
|
|
126
|
+
} ? {
|
|
127
|
+
readonly __tsgonest_startsWith?: V;
|
|
128
|
+
readonly __tsgonest_startsWith_error?: E;
|
|
129
|
+
} : {
|
|
130
|
+
readonly __tsgonest_startsWith?: S extends {
|
|
131
|
+
value: infer V;
|
|
132
|
+
} ? V : S;
|
|
133
|
+
};
|
|
116
134
|
/**
|
|
117
135
|
* String must end with suffix.
|
|
118
136
|
* @example EndsWith<".json">
|
|
@@ -120,9 +138,17 @@ type StartsWith<S extends string | {
|
|
|
120
138
|
type EndsWith<S extends string | {
|
|
121
139
|
value: string;
|
|
122
140
|
error?: string;
|
|
123
|
-
}> = {
|
|
124
|
-
|
|
125
|
-
|
|
141
|
+
}> = S extends {
|
|
142
|
+
value: infer V extends string;
|
|
143
|
+
error: infer E extends string;
|
|
144
|
+
} ? {
|
|
145
|
+
readonly __tsgonest_endsWith?: V;
|
|
146
|
+
readonly __tsgonest_endsWith_error?: E;
|
|
147
|
+
} : {
|
|
148
|
+
readonly __tsgonest_endsWith?: S extends {
|
|
149
|
+
value: infer V;
|
|
150
|
+
} ? V : S;
|
|
151
|
+
};
|
|
126
152
|
/**
|
|
127
153
|
* String must contain substring.
|
|
128
154
|
* @example Includes<"@">
|
|
@@ -130,9 +156,17 @@ type EndsWith<S extends string | {
|
|
|
130
156
|
type Includes<S extends string | {
|
|
131
157
|
value: string;
|
|
132
158
|
error?: string;
|
|
133
|
-
}> = {
|
|
134
|
-
|
|
135
|
-
|
|
159
|
+
}> = S extends {
|
|
160
|
+
value: infer V extends string;
|
|
161
|
+
error: infer E extends string;
|
|
162
|
+
} ? {
|
|
163
|
+
readonly __tsgonest_includes?: V;
|
|
164
|
+
readonly __tsgonest_includes_error?: E;
|
|
165
|
+
} : {
|
|
166
|
+
readonly __tsgonest_includes?: S extends {
|
|
167
|
+
value: infer V;
|
|
168
|
+
} ? V : S;
|
|
169
|
+
};
|
|
136
170
|
/**
|
|
137
171
|
* Minimum value (inclusive): value >= N.
|
|
138
172
|
* @example Minimum<0> or Min<0> or Min<{value: 0, error: "Must be non-negative"}>
|
|
@@ -140,9 +174,17 @@ type Includes<S extends string | {
|
|
|
140
174
|
type Minimum<N extends number | {
|
|
141
175
|
value: number;
|
|
142
176
|
error?: string;
|
|
143
|
-
}> = {
|
|
144
|
-
|
|
145
|
-
|
|
177
|
+
}> = N extends {
|
|
178
|
+
value: infer V extends number;
|
|
179
|
+
error: infer E extends string;
|
|
180
|
+
} ? {
|
|
181
|
+
readonly __tsgonest_minimum?: V;
|
|
182
|
+
readonly __tsgonest_minimum_error?: E;
|
|
183
|
+
} : {
|
|
184
|
+
readonly __tsgonest_minimum?: N extends {
|
|
185
|
+
value: infer V;
|
|
186
|
+
} ? V : N;
|
|
187
|
+
};
|
|
146
188
|
/**
|
|
147
189
|
* Maximum value (inclusive): value <= N.
|
|
148
190
|
* @example Maximum<100> or Max<100>
|
|
@@ -150,9 +192,17 @@ type Minimum<N extends number | {
|
|
|
150
192
|
type Maximum<N extends number | {
|
|
151
193
|
value: number;
|
|
152
194
|
error?: string;
|
|
153
|
-
}> = {
|
|
154
|
-
|
|
155
|
-
|
|
195
|
+
}> = N extends {
|
|
196
|
+
value: infer V extends number;
|
|
197
|
+
error: infer E extends string;
|
|
198
|
+
} ? {
|
|
199
|
+
readonly __tsgonest_maximum?: V;
|
|
200
|
+
readonly __tsgonest_maximum_error?: E;
|
|
201
|
+
} : {
|
|
202
|
+
readonly __tsgonest_maximum?: N extends {
|
|
203
|
+
value: infer V;
|
|
204
|
+
} ? V : N;
|
|
205
|
+
};
|
|
156
206
|
/**
|
|
157
207
|
* Exclusive minimum: value > N.
|
|
158
208
|
* @example ExclusiveMinimum<0> or Gt<0>
|
|
@@ -160,9 +210,17 @@ type Maximum<N extends number | {
|
|
|
160
210
|
type ExclusiveMinimum<N extends number | {
|
|
161
211
|
value: number;
|
|
162
212
|
error?: string;
|
|
163
|
-
}> = {
|
|
164
|
-
|
|
165
|
-
|
|
213
|
+
}> = N extends {
|
|
214
|
+
value: infer V extends number;
|
|
215
|
+
error: infer E extends string;
|
|
216
|
+
} ? {
|
|
217
|
+
readonly __tsgonest_exclusiveMinimum?: V;
|
|
218
|
+
readonly __tsgonest_exclusiveMinimum_error?: E;
|
|
219
|
+
} : {
|
|
220
|
+
readonly __tsgonest_exclusiveMinimum?: N extends {
|
|
221
|
+
value: infer V;
|
|
222
|
+
} ? V : N;
|
|
223
|
+
};
|
|
166
224
|
/**
|
|
167
225
|
* Exclusive maximum: value < N.
|
|
168
226
|
* @example ExclusiveMaximum<100> or Lt<100>
|
|
@@ -170,9 +228,17 @@ type ExclusiveMinimum<N extends number | {
|
|
|
170
228
|
type ExclusiveMaximum<N extends number | {
|
|
171
229
|
value: number;
|
|
172
230
|
error?: string;
|
|
173
|
-
}> = {
|
|
174
|
-
|
|
175
|
-
|
|
231
|
+
}> = N extends {
|
|
232
|
+
value: infer V extends number;
|
|
233
|
+
error: infer E extends string;
|
|
234
|
+
} ? {
|
|
235
|
+
readonly __tsgonest_exclusiveMaximum?: V;
|
|
236
|
+
readonly __tsgonest_exclusiveMaximum_error?: E;
|
|
237
|
+
} : {
|
|
238
|
+
readonly __tsgonest_exclusiveMaximum?: N extends {
|
|
239
|
+
value: infer V;
|
|
240
|
+
} ? V : N;
|
|
241
|
+
};
|
|
176
242
|
/**
|
|
177
243
|
* Value must be a multiple of N.
|
|
178
244
|
* @example MultipleOf<2> or Step<0.01>
|
|
@@ -180,9 +246,17 @@ type ExclusiveMaximum<N extends number | {
|
|
|
180
246
|
type MultipleOf<N extends number | {
|
|
181
247
|
value: number;
|
|
182
248
|
error?: string;
|
|
183
|
-
}> = {
|
|
184
|
-
|
|
185
|
-
|
|
249
|
+
}> = N extends {
|
|
250
|
+
value: infer V extends number;
|
|
251
|
+
error: infer E extends string;
|
|
252
|
+
} ? {
|
|
253
|
+
readonly __tsgonest_multipleOf?: V;
|
|
254
|
+
readonly __tsgonest_multipleOf_error?: E;
|
|
255
|
+
} : {
|
|
256
|
+
readonly __tsgonest_multipleOf?: N extends {
|
|
257
|
+
value: infer V;
|
|
258
|
+
} ? V : N;
|
|
259
|
+
};
|
|
186
260
|
/** Valid numeric type values. */
|
|
187
261
|
type NumericTypeValue = "int32" | "uint32" | "int64" | "uint64" | "float" | "double";
|
|
188
262
|
/**
|
|
@@ -192,9 +266,17 @@ type NumericTypeValue = "int32" | "uint32" | "int64" | "uint64" | "float" | "dou
|
|
|
192
266
|
type Type<T extends NumericTypeValue | {
|
|
193
267
|
type: NumericTypeValue;
|
|
194
268
|
error?: string;
|
|
195
|
-
}> = {
|
|
196
|
-
|
|
197
|
-
|
|
269
|
+
}> = T extends {
|
|
270
|
+
type: infer V;
|
|
271
|
+
error: infer E extends string;
|
|
272
|
+
} ? {
|
|
273
|
+
readonly __tsgonest_type?: V;
|
|
274
|
+
readonly __tsgonest_type_error?: E;
|
|
275
|
+
} : {
|
|
276
|
+
readonly __tsgonest_type?: T extends {
|
|
277
|
+
type: infer V;
|
|
278
|
+
} ? V : T;
|
|
279
|
+
};
|
|
198
280
|
/**
|
|
199
281
|
* Minimum array length.
|
|
200
282
|
* @example MinItems<1>
|
|
@@ -202,9 +284,17 @@ type Type<T extends NumericTypeValue | {
|
|
|
202
284
|
type MinItems<N extends number | {
|
|
203
285
|
value: number;
|
|
204
286
|
error?: string;
|
|
205
|
-
}> = {
|
|
206
|
-
|
|
207
|
-
|
|
287
|
+
}> = N extends {
|
|
288
|
+
value: infer V extends number;
|
|
289
|
+
error: infer E extends string;
|
|
290
|
+
} ? {
|
|
291
|
+
readonly __tsgonest_minItems?: V;
|
|
292
|
+
readonly __tsgonest_minItems_error?: E;
|
|
293
|
+
} : {
|
|
294
|
+
readonly __tsgonest_minItems?: N extends {
|
|
295
|
+
value: infer V;
|
|
296
|
+
} ? V : N;
|
|
297
|
+
};
|
|
208
298
|
/**
|
|
209
299
|
* Maximum array length.
|
|
210
300
|
* @example MaxItems<100>
|
|
@@ -212,36 +302,59 @@ type MinItems<N extends number | {
|
|
|
212
302
|
type MaxItems<N extends number | {
|
|
213
303
|
value: number;
|
|
214
304
|
error?: string;
|
|
215
|
-
}> = {
|
|
216
|
-
|
|
217
|
-
|
|
305
|
+
}> = N extends {
|
|
306
|
+
value: infer V extends number;
|
|
307
|
+
error: infer E extends string;
|
|
308
|
+
} ? {
|
|
309
|
+
readonly __tsgonest_maxItems?: V;
|
|
310
|
+
readonly __tsgonest_maxItems_error?: E;
|
|
311
|
+
} : {
|
|
312
|
+
readonly __tsgonest_maxItems?: N extends {
|
|
313
|
+
value: infer V;
|
|
314
|
+
} ? V : N;
|
|
315
|
+
};
|
|
218
316
|
/**
|
|
219
317
|
* Array items must be unique.
|
|
220
318
|
* @example UniqueItems or Unique or Unique<{error: "No duplicates"}>
|
|
221
319
|
*/
|
|
222
320
|
type UniqueItems<C extends {
|
|
223
321
|
error?: string;
|
|
224
|
-
} = {}> = {
|
|
322
|
+
} = {}> = C extends {
|
|
323
|
+
error: infer E extends string;
|
|
324
|
+
} ? {
|
|
325
|
+
readonly __tsgonest_uniqueItems?: true;
|
|
326
|
+
readonly __tsgonest_uniqueItems_error?: E;
|
|
327
|
+
} : {
|
|
225
328
|
readonly __tsgonest_uniqueItems?: true;
|
|
226
|
-
}
|
|
329
|
+
};
|
|
227
330
|
/**
|
|
228
331
|
* String must be all uppercase.
|
|
229
332
|
* @example Uppercase or Uppercase<{error: "Must be uppercase"}>
|
|
230
333
|
*/
|
|
231
334
|
type Uppercase<C extends {
|
|
232
335
|
error?: string;
|
|
233
|
-
} = {}> = {
|
|
336
|
+
} = {}> = C extends {
|
|
337
|
+
error: infer E extends string;
|
|
338
|
+
} ? {
|
|
339
|
+
readonly __tsgonest_uppercase?: true;
|
|
340
|
+
readonly __tsgonest_uppercase_error?: E;
|
|
341
|
+
} : {
|
|
234
342
|
readonly __tsgonest_uppercase?: true;
|
|
235
|
-
}
|
|
343
|
+
};
|
|
236
344
|
/**
|
|
237
345
|
* String must be all lowercase.
|
|
238
346
|
* @example Lowercase or Lowercase<{error: "Must be lowercase"}>
|
|
239
347
|
*/
|
|
240
348
|
type Lowercase<C extends {
|
|
241
349
|
error?: string;
|
|
242
|
-
} = {}> = {
|
|
350
|
+
} = {}> = C extends {
|
|
351
|
+
error: infer E extends string;
|
|
352
|
+
} ? {
|
|
243
353
|
readonly __tsgonest_lowercase?: true;
|
|
244
|
-
|
|
354
|
+
readonly __tsgonest_lowercase_error?: E;
|
|
355
|
+
} : {
|
|
356
|
+
readonly __tsgonest_lowercase?: true;
|
|
357
|
+
};
|
|
245
358
|
/** Trim whitespace before validation. */
|
|
246
359
|
type Trim = {
|
|
247
360
|
readonly __tsgonest_transform_trim?: true;
|
|
@@ -282,11 +395,17 @@ type Coerce = {
|
|
|
282
395
|
type Validate<F extends ((...args: any[]) => boolean) | {
|
|
283
396
|
fn: (...args: any[]) => boolean;
|
|
284
397
|
error?: string;
|
|
285
|
-
}> = {
|
|
398
|
+
}> = F extends {
|
|
399
|
+
fn: infer Fn;
|
|
400
|
+
error: infer E extends string;
|
|
401
|
+
} ? {
|
|
402
|
+
readonly __tsgonest_validate?: Fn;
|
|
403
|
+
readonly __tsgonest_validate_error?: E;
|
|
404
|
+
} : {
|
|
286
405
|
readonly __tsgonest_validate?: F extends {
|
|
287
406
|
fn: infer Fn;
|
|
288
407
|
} ? Fn : F;
|
|
289
|
-
}
|
|
408
|
+
};
|
|
290
409
|
/**
|
|
291
410
|
* Global error message — applies to all validation failures on this property.
|
|
292
411
|
* Per-constraint errors (via `error` field) take precedence.
|
package/dist/tags.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.d.mts","names":[],"sources":["../src/tags.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"tags.d.mts","names":[],"sources":["../src/tags.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAA;AAAA,KACN,GAAA,GAAM,MAAA;AAAA,KACN,IAAA,GAAO,MAAA;AAAA,KACP,IAAA,GAAO,MAAA;AAAA,KACP,QAAA,GAAW,MAAA;AAAA,KACX,QAAA,GAAW,MAAA;AAAA,KACX,IAAA,GAAO,MAAA;AAAA,KACP,QAAA,GAAW,MAAA;AAAA,KACX,GAAA,GAAM,MAAA;AAAA,KACN,IAAA,GAAO,MAAA;AAAA,KACP,IAAA,GAAO,MAAA;AAAA,KACP,KAAA,GAAQ,MAAA;AAAA,KACR,MAAA,GAAS,MAAA;;KAOT,QAAA,GAAW,gBAAA;;KAGX,QAAA,GAAW,gBAAA;;KAGX,WAAA,GAAc,OAAA;;KAGd,WAAA,GAAc,OAAA;;KAGd,GAAA,GAAM,IAAA;;KAGN,OAAA,GAAU,IAAA;;KAGV,MAAA,GAAS,IAAA;;KAGT,IAAA,GAAO,IAAA;;KAGP,MAAA,GAAS,IAAA"}
|
package/dist/tags.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.mjs","names":[],"sources":["../src/tags.ts"],"sourcesContent":["/**\n * @tsgonest/types — Zero-runtime branded types for type-safe validation.\n *\n * These types exist purely at compile time. They produce NO runtime code.\n * The tsgonest compiler reads phantom properties (`__tsgonest_*`) to generate validators.\n *\n * All phantom properties are optional (`?`) so that branded types remain\n * assignable from their base types (e.g. `string` → `string & Email`).\n * This follows the same pattern as typia's optional `\"typia.tag\"` property.\n *\n * Every constraint supports two forms:\n * - Simple: Min<0> — clean, no custom error\n * - Extended: Min<{value: 0, error: \"Must be positive\"}> — with per-constraint error\n *\n * @example\n * import { Email, Min, Max, Trim, Coerce } from \"@tsgonest/types\";\n *\n * interface CreateUserDto {\n * email: string & Email;\n * name: string & Trim & Min<1> & Max<255>;\n * age: number & Min<0> & Max<150>;\n * }\n *\n * // With per-constraint errors:\n * interface StrictDto {\n * email: string & Format<{type: \"email\", error: \"Must be a valid email\"}>;\n * age: number & Min<{value: 0, error: \"Age cannot be negative\"}>;\n * }\n *\n * // Query params with coercion:\n * interface QueryDto {\n * page: number & Coerce;\n * active: boolean & Coerce;\n * }\n */\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Internal helpers (not exported)\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** Extract the value from a dual-form number constraint. */\ntype NumVal<N extends number | { value: number; error?: string }> =\n N extends { value: infer V } ? V : N;\n\n/** Extract the value from a dual-form string constraint. */\ntype StrVal<S extends string | { value: string; error?: string }> =\n S extends { value: infer V } ? V : S;\n\n/** Extract the type from a dual-form type constraint (Format, Type). */\ntype TypeVal<T, Base> =\n T extends { type: infer V } ? V : T;\n\n/** Conditionally add an optional _error phantom property. */\ntype WithErr<Prefix extends string, C> =\n C extends { error: infer E extends string }\n ? { readonly [K in `${Prefix}_error`]?: E }\n : {};\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// String Format\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** All supported string format values. */\nexport type FormatValue =\n | \"email\" | \"idn-email\"\n | \"url\" | \"uri\" | \"uri-reference\" | \"uri-template\" | \"iri\" | \"iri-reference\"\n | \"uuid\"\n | \"ipv4\" | \"ipv6\"\n | \"hostname\" | \"idn-hostname\"\n | \"date-time\" | \"date\" | \"time\" | \"duration\"\n | \"json-pointer\" | \"relative-json-pointer\"\n | \"byte\" | \"password\" | \"regex\"\n | \"nanoid\" | \"cuid\" | \"cuid2\" | \"ulid\" | \"jwt\"\n | \"base64url\" | \"hex\" | \"mac\"\n | \"cidrv4\" | \"cidrv6\" | \"emoji\";\n\n/**\n * Validate a string matches a specific format.\n *\n * @example\n * Format<\"email\">\n * Format<{type: \"email\", error: \"Must be a valid email\"}>\n */\nexport type Format<F extends FormatValue | { type: FormatValue; error?: string }> = {\n readonly __tsgonest_format?: TypeVal<F, FormatValue>;\n} & WithErr<\"__tsgonest_format\", F>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// String Constraints\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Minimum string length.\n * @example MinLength<1> or MinLength<{value: 1, error: \"Cannot be empty\"}>\n */\nexport type MinLength<N extends number | { value: number; error?: string }> = {\n readonly __tsgonest_minLength?: NumVal<N>;\n} & WithErr<\"__tsgonest_minLength\", N>;\n\n/**\n * Maximum string length.\n * @example MaxLength<255> or MaxLength<{value: 255, error: \"Too long\"}>\n */\nexport type MaxLength<N extends number | { value: number; error?: string }> = {\n readonly __tsgonest_maxLength?: NumVal<N>;\n} & WithErr<\"__tsgonest_maxLength\", N>;\n\n/**\n * Regex pattern constraint.\n * @example Pattern<\"^[a-z]+$\"> or Pattern<{value: \"^[a-z]+$\", error: \"Letters only\"}>\n */\nexport type Pattern<P extends string | { value: string; error?: string }> = {\n readonly __tsgonest_pattern?: StrVal<P>;\n} & WithErr<\"__tsgonest_pattern\", P>;\n\n/**\n * String must start with prefix.\n * @example StartsWith<\"https://\">\n */\nexport type StartsWith<S extends string | { value: string; error?: string }> = {\n readonly __tsgonest_startsWith?: StrVal<S>;\n} & WithErr<\"__tsgonest_startsWith\", S>;\n\n/**\n * String must end with suffix.\n * @example EndsWith<\".json\">\n */\nexport type EndsWith<S extends string | { value: string; error?: string }> = {\n readonly __tsgonest_endsWith?: StrVal<S>;\n} & WithErr<\"__tsgonest_endsWith\", S>;\n\n/**\n * String must contain substring.\n * @example Includes<\"@\">\n */\nexport type Includes<S extends string | { value: string; error?: string }> = {\n readonly __tsgonest_includes?: StrVal<S>;\n} & WithErr<\"__tsgonest_includes\", S>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Numeric Constraints\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Minimum value (inclusive): value >= N.\n * @example Minimum<0> or Min<0> or Min<{value: 0, error: \"Must be non-negative\"}>\n */\nexport type Minimum<N extends number | { value: number; error?: string }> = {\n readonly __tsgonest_minimum?: NumVal<N>;\n} & WithErr<\"__tsgonest_minimum\", N>;\n\n/**\n * Maximum value (inclusive): value <= N.\n * @example Maximum<100> or Max<100>\n */\nexport type Maximum<N extends number | { value: number; error?: string }> = {\n readonly __tsgonest_maximum?: NumVal<N>;\n} & WithErr<\"__tsgonest_maximum\", N>;\n\n/**\n * Exclusive minimum: value > N.\n * @example ExclusiveMinimum<0> or Gt<0>\n */\nexport type ExclusiveMinimum<N extends number | { value: number; error?: string }> = {\n readonly __tsgonest_exclusiveMinimum?: NumVal<N>;\n} & WithErr<\"__tsgonest_exclusiveMinimum\", N>;\n\n/**\n * Exclusive maximum: value < N.\n * @example ExclusiveMaximum<100> or Lt<100>\n */\nexport type ExclusiveMaximum<N extends number | { value: number; error?: string }> = {\n readonly __tsgonest_exclusiveMaximum?: NumVal<N>;\n} & WithErr<\"__tsgonest_exclusiveMaximum\", N>;\n\n/**\n * Value must be a multiple of N.\n * @example MultipleOf<2> or Step<0.01>\n */\nexport type MultipleOf<N extends number | { value: number; error?: string }> = {\n readonly __tsgonest_multipleOf?: NumVal<N>;\n} & WithErr<\"__tsgonest_multipleOf\", N>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Numeric Type Constraints\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** Valid numeric type values. */\nexport type NumericTypeValue =\n | \"int32\" | \"uint32\" | \"int64\" | \"uint64\" | \"float\" | \"double\";\n\n/**\n * Constrain number to a specific numeric type.\n * @example Type<\"int32\"> or Type<{type: \"int32\", error: \"Must be integer\"}>\n */\nexport type Type<T extends NumericTypeValue | { type: NumericTypeValue; error?: string }> = {\n readonly __tsgonest_type?: TypeVal<T, NumericTypeValue>;\n} & WithErr<\"__tsgonest_type\", T>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Array Constraints\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Minimum array length.\n * @example MinItems<1>\n */\nexport type MinItems<N extends number | { value: number; error?: string }> = {\n readonly __tsgonest_minItems?: NumVal<N>;\n} & WithErr<\"__tsgonest_minItems\", N>;\n\n/**\n * Maximum array length.\n * @example MaxItems<100>\n */\nexport type MaxItems<N extends number | { value: number; error?: string }> = {\n readonly __tsgonest_maxItems?: NumVal<N>;\n} & WithErr<\"__tsgonest_maxItems\", N>;\n\n/**\n * Array items must be unique.\n * @example UniqueItems or Unique or Unique<{error: \"No duplicates\"}>\n */\nexport type UniqueItems<C extends { error?: string } = {}> = {\n readonly __tsgonest_uniqueItems?: true;\n} & WithErr<\"__tsgonest_uniqueItems\", C>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// String Case Validation\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * String must be all uppercase.\n * @example Uppercase or Uppercase<{error: \"Must be uppercase\"}>\n */\nexport type Uppercase<C extends { error?: string } = {}> = {\n readonly __tsgonest_uppercase?: true;\n} & WithErr<\"__tsgonest_uppercase\", C>;\n\n/**\n * String must be all lowercase.\n * @example Lowercase or Lowercase<{error: \"Must be lowercase\"}>\n */\nexport type Lowercase<C extends { error?: string } = {}> = {\n readonly __tsgonest_lowercase?: true;\n} & WithErr<\"__tsgonest_lowercase\", C>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Transforms (applied before validation, never fail)\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** Trim whitespace before validation. */\nexport type Trim = { readonly __tsgonest_transform_trim?: true };\n\n/** Convert to lowercase before validation. */\nexport type ToLowerCase = { readonly __tsgonest_transform_toLowerCase?: true };\n\n/** Convert to uppercase before validation. */\nexport type ToUpperCase = { readonly __tsgonest_transform_toUpperCase?: true };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Coercion\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Coerce string inputs to the declared type before validation.\n * - \"123\" → 123 (string to number)\n * - \"true\"/\"false\" → true/false (string to boolean)\n *\n * @example\n * page: number & Coerce\n * active: boolean & Coerce\n */\nexport type Coerce = { readonly __tsgonest_coerce?: true };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Custom Validators (function reference)\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Validate using a custom function. The function must be a predicate:\n * `(value: T) => boolean`. tsgonest resolves the function's source file\n * and emits an import + call in the generated validator.\n *\n * @example\n * import { isValidCard } from \"./validators/credit-card\";\n *\n * interface PaymentDto {\n * card: string & Validate<typeof isValidCard>;\n * card: string & Validate<{fn: typeof isValidCard, error: \"Invalid card\"}>;\n * }\n */\nexport type Validate<\n F extends ((...args: any[]) => boolean) | { fn: (...args: any[]) => boolean; error?: string }\n> = {\n readonly __tsgonest_validate?: F extends { fn: infer Fn } ? Fn : F;\n} & WithErr<\"__tsgonest_validate\", F>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Meta Types\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Global error message — applies to all validation failures on this property.\n * Per-constraint errors (via `error` field) take precedence.\n * @example string & Format<\"email\"> & Error<\"Invalid email\">\n */\nexport type Error<M extends string> = { readonly __tsgonest_error?: M };\n\n/**\n * Default value for optional properties. Assigned when value is undefined.\n * @example theme?: string & Default<\"light\">\n */\nexport type Default<V extends string | number | boolean> = {\n readonly __tsgonest_default?: V;\n};\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Compound Constraints\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Exact length (sets both MinLength and MaxLength).\n * @example Length<2> or Length<{value: 2, error: \"Must be exactly 2 chars\"}>\n */\nexport type Length<N extends number | { value: number; error?: string }> =\n MinLength<N> & MaxLength<N>;\n\n/**\n * Numeric range (inclusive). Sets Minimum and Maximum.\n * @example Range<{min: 0, max: 100}> or Range<{min: 0, max: 100, error: \"Out of range\"}>\n */\nexport type Range<R extends { min: number; max: number; error?: string }> =\n Minimum<R extends { error: string } ? { value: R[\"min\"]; error: R[\"error\"] } : R[\"min\"]>\n & Maximum<R extends { error: string } ? { value: R[\"max\"]; error: R[\"error\"] } : R[\"max\"]>;\n\n/**\n * String length range. Sets MinLength and MaxLength.\n * @example Between<{min: 1, max: 255}> or Between<{min: 1, max: 255, error: \"Bad length\"}>\n */\nexport type Between<R extends { min: number; max: number; error?: string }> =\n MinLength<R extends { error: string } ? { value: R[\"min\"]; error: R[\"error\"] } : R[\"min\"]>\n & MaxLength<R extends { error: string } ? { value: R[\"max\"]; error: R[\"error\"] } : R[\"max\"]>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Short Aliases (Zod-style)\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** Alias for Minimum. `Min<0>` = `Minimum<0>` */\nexport type Min<N extends number | { value: number; error?: string }> = Minimum<N>;\n\n/** Alias for Maximum. `Max<100>` = `Maximum<100>` */\nexport type Max<N extends number | { value: number; error?: string }> = Maximum<N>;\n\n/** Alias for ExclusiveMinimum. `Gt<0>` = \"greater than 0\" */\nexport type Gt<N extends number | { value: number; error?: string }> = ExclusiveMinimum<N>;\n\n/** Alias for ExclusiveMaximum. `Lt<100>` = \"less than 100\" */\nexport type Lt<N extends number | { value: number; error?: string }> = ExclusiveMaximum<N>;\n\n/** Alias for Minimum + ExclusiveMinimum combo. `Gte<0>` = `Min<0>` */\nexport type Gte<N extends number | { value: number; error?: string }> = Minimum<N>;\n\n/** Alias for Maximum + ExclusiveMaximum combo. `Lte<100>` = `Max<100>` */\nexport type Lte<N extends number | { value: number; error?: string }> = Maximum<N>;\n\n/** Alias for MultipleOf. `Step<0.01>` */\nexport type Step<N extends number | { value: number; error?: string }> = MultipleOf<N>;\n\n/** Alias for UniqueItems. `Unique` */\nexport type Unique<C extends { error?: string } = {}> = UniqueItems<C>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Format Aliases (direct exports, no namespace needed)\n// ═══════════════════════════════════════════════════════════════════════════════\n\nexport type Email = Format<\"email\">;\nexport type Uuid = Format<\"uuid\">;\nexport type Url = Format<\"url\">;\nexport type Uri = Format<\"uri\">;\nexport type IPv4 = Format<\"ipv4\">;\nexport type IPv6 = Format<\"ipv6\">;\nexport type DateTime = Format<\"date-time\">;\nexport type DateOnly = Format<\"date\">;\nexport type Time = Format<\"time\">;\nexport type Duration = Format<\"duration\">;\nexport type Jwt = Format<\"jwt\">;\nexport type Ulid = Format<\"ulid\">;\nexport type Cuid = Format<\"cuid\">;\nexport type Cuid2 = Format<\"cuid2\">;\nexport type NanoId = Format<\"nanoid\">;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Numeric Aliases\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** number & Gt<0> */\nexport type Positive = ExclusiveMinimum<0>;\n\n/** number & Lt<0> */\nexport type Negative = ExclusiveMaximum<0>;\n\n/** number & Min<0> */\nexport type NonNegative = Minimum<0>;\n\n/** number & Max<0> */\nexport type NonPositive = Maximum<0>;\n\n/** number & Type<\"int32\"> */\nexport type Int = Type<\"int32\">;\n\n/** number & Type<\"int64\"> (JS safe integer range) */\nexport type SafeInt = Type<\"int64\">;\n\n/** number & Type<\"float\"> (finite, no Infinity/NaN) */\nexport type Finite = Type<\"float\">;\n\n/** number & Type<\"uint32\"> */\nexport type Uint = Type<\"uint32\">;\n\n/** number & Type<\"double\"> */\nexport type Double = Type<\"double\">;\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"tags.mjs","names":[],"sources":["../src/tags.ts"],"sourcesContent":["/**\n * @tsgonest/types — Zero-runtime branded types for type-safe validation.\n *\n * These types exist purely at compile time. They produce NO runtime code.\n * The tsgonest compiler reads phantom properties (`__tsgonest_*`) to generate validators.\n *\n * All phantom properties are optional (`?`) so that branded types remain\n * assignable from their base types (e.g. `string` → `string & Email`).\n * This follows the same pattern as typia's optional `\"typia.tag\"` property.\n *\n * Every constraint supports two forms:\n * - Simple: Min<0> — clean, no custom error\n * - Extended: Min<{value: 0, error: \"Must be positive\"}> — with per-constraint error\n *\n * @example\n * import { Email, Min, Max, Trim, Coerce } from \"@tsgonest/types\";\n *\n * interface CreateUserDto {\n * email: string & Email;\n * name: string & Trim & Min<1> & Max<255>;\n * age: number & Min<0> & Max<150>;\n * }\n *\n * // With per-constraint errors:\n * interface StrictDto {\n * email: string & Format<{type: \"email\", error: \"Must be a valid email\"}>;\n * age: number & Min<{value: 0, error: \"Age cannot be negative\"}>;\n * }\n *\n * // Query params with coercion:\n * interface QueryDto {\n * page: number & Coerce;\n * active: boolean & Coerce;\n * }\n */\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Internal note on phantom type structure\n// ═══════════════════════════════════════════════════════════════════════════════\n//\n// Each constraint type uses a single top-level conditional instead of\n// `{ __prop?: Val<N> } & WithErr<\"__prop\", N>`. The intersection-with-conditional\n// pattern triggers a tsgo (TypeScript Go port) checker bug where mapped types\n// (Partial<T>, Omit<T,K>, Pick<T,K>) return `any` for branded intersection\n// properties. Using a single conditional avoids intersecting with the\n// conditionally-typed WithErr, keeping each constraint as a plain object type.\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// String Format\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** All supported string format values. */\nexport type FormatValue =\n | \"email\" | \"idn-email\"\n | \"url\" | \"uri\" | \"uri-reference\" | \"uri-template\" | \"iri\" | \"iri-reference\"\n | \"uuid\"\n | \"ipv4\" | \"ipv6\"\n | \"hostname\" | \"idn-hostname\"\n | \"date-time\" | \"date\" | \"time\" | \"duration\"\n | \"json-pointer\" | \"relative-json-pointer\"\n | \"byte\" | \"password\" | \"regex\"\n | \"nanoid\" | \"cuid\" | \"cuid2\" | \"ulid\" | \"jwt\"\n | \"base64url\" | \"hex\" | \"mac\"\n | \"cidrv4\" | \"cidrv6\" | \"emoji\";\n\n/**\n * Validate a string matches a specific format.\n *\n * @example\n * Format<\"email\">\n * Format<{type: \"email\", error: \"Must be a valid email\"}>\n */\nexport type Format<F extends FormatValue | { type: FormatValue; error?: string }> =\n F extends { type: infer V; error: infer E extends string }\n ? { readonly __tsgonest_format?: V; readonly __tsgonest_format_error?: E }\n : { readonly __tsgonest_format?: F extends { type: infer V } ? V : F };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// String Constraints\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Minimum string length.\n * @example MinLength<1> or MinLength<{value: 1, error: \"Cannot be empty\"}>\n */\nexport type MinLength<N extends number | { value: number; error?: string }> =\n N extends { value: infer V extends number; error: infer E extends string }\n ? { readonly __tsgonest_minLength?: V; readonly __tsgonest_minLength_error?: E }\n : { readonly __tsgonest_minLength?: N extends { value: infer V } ? V : N };\n\n/**\n * Maximum string length.\n * @example MaxLength<255> or MaxLength<{value: 255, error: \"Too long\"}>\n */\nexport type MaxLength<N extends number | { value: number; error?: string }> =\n N extends { value: infer V extends number; error: infer E extends string }\n ? { readonly __tsgonest_maxLength?: V; readonly __tsgonest_maxLength_error?: E }\n : { readonly __tsgonest_maxLength?: N extends { value: infer V } ? V : N };\n\n/**\n * Regex pattern constraint.\n * @example Pattern<\"^[a-z]+$\"> or Pattern<{value: \"^[a-z]+$\", error: \"Letters only\"}>\n */\nexport type Pattern<P extends string | { value: string; error?: string }> =\n P extends { value: infer V extends string; error: infer E extends string }\n ? { readonly __tsgonest_pattern?: V; readonly __tsgonest_pattern_error?: E }\n : { readonly __tsgonest_pattern?: P extends { value: infer V } ? V : P };\n\n/**\n * String must start with prefix.\n * @example StartsWith<\"https://\">\n */\nexport type StartsWith<S extends string | { value: string; error?: string }> =\n S extends { value: infer V extends string; error: infer E extends string }\n ? { readonly __tsgonest_startsWith?: V; readonly __tsgonest_startsWith_error?: E }\n : { readonly __tsgonest_startsWith?: S extends { value: infer V } ? V : S };\n\n/**\n * String must end with suffix.\n * @example EndsWith<\".json\">\n */\nexport type EndsWith<S extends string | { value: string; error?: string }> =\n S extends { value: infer V extends string; error: infer E extends string }\n ? { readonly __tsgonest_endsWith?: V; readonly __tsgonest_endsWith_error?: E }\n : { readonly __tsgonest_endsWith?: S extends { value: infer V } ? V : S };\n\n/**\n * String must contain substring.\n * @example Includes<\"@\">\n */\nexport type Includes<S extends string | { value: string; error?: string }> =\n S extends { value: infer V extends string; error: infer E extends string }\n ? { readonly __tsgonest_includes?: V; readonly __tsgonest_includes_error?: E }\n : { readonly __tsgonest_includes?: S extends { value: infer V } ? V : S };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Numeric Constraints\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Minimum value (inclusive): value >= N.\n * @example Minimum<0> or Min<0> or Min<{value: 0, error: \"Must be non-negative\"}>\n */\nexport type Minimum<N extends number | { value: number; error?: string }> =\n N extends { value: infer V extends number; error: infer E extends string }\n ? { readonly __tsgonest_minimum?: V; readonly __tsgonest_minimum_error?: E }\n : { readonly __tsgonest_minimum?: N extends { value: infer V } ? V : N };\n\n/**\n * Maximum value (inclusive): value <= N.\n * @example Maximum<100> or Max<100>\n */\nexport type Maximum<N extends number | { value: number; error?: string }> =\n N extends { value: infer V extends number; error: infer E extends string }\n ? { readonly __tsgonest_maximum?: V; readonly __tsgonest_maximum_error?: E }\n : { readonly __tsgonest_maximum?: N extends { value: infer V } ? V : N };\n\n/**\n * Exclusive minimum: value > N.\n * @example ExclusiveMinimum<0> or Gt<0>\n */\nexport type ExclusiveMinimum<N extends number | { value: number; error?: string }> =\n N extends { value: infer V extends number; error: infer E extends string }\n ? { readonly __tsgonest_exclusiveMinimum?: V; readonly __tsgonest_exclusiveMinimum_error?: E }\n : { readonly __tsgonest_exclusiveMinimum?: N extends { value: infer V } ? V : N };\n\n/**\n * Exclusive maximum: value < N.\n * @example ExclusiveMaximum<100> or Lt<100>\n */\nexport type ExclusiveMaximum<N extends number | { value: number; error?: string }> =\n N extends { value: infer V extends number; error: infer E extends string }\n ? { readonly __tsgonest_exclusiveMaximum?: V; readonly __tsgonest_exclusiveMaximum_error?: E }\n : { readonly __tsgonest_exclusiveMaximum?: N extends { value: infer V } ? V : N };\n\n/**\n * Value must be a multiple of N.\n * @example MultipleOf<2> or Step<0.01>\n */\nexport type MultipleOf<N extends number | { value: number; error?: string }> =\n N extends { value: infer V extends number; error: infer E extends string }\n ? { readonly __tsgonest_multipleOf?: V; readonly __tsgonest_multipleOf_error?: E }\n : { readonly __tsgonest_multipleOf?: N extends { value: infer V } ? V : N };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Numeric Type Constraints\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** Valid numeric type values. */\nexport type NumericTypeValue =\n | \"int32\" | \"uint32\" | \"int64\" | \"uint64\" | \"float\" | \"double\";\n\n/**\n * Constrain number to a specific numeric type.\n * @example Type<\"int32\"> or Type<{type: \"int32\", error: \"Must be integer\"}>\n */\nexport type Type<T extends NumericTypeValue | { type: NumericTypeValue; error?: string }> =\n T extends { type: infer V; error: infer E extends string }\n ? { readonly __tsgonest_type?: V; readonly __tsgonest_type_error?: E }\n : { readonly __tsgonest_type?: T extends { type: infer V } ? V : T };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Array Constraints\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Minimum array length.\n * @example MinItems<1>\n */\nexport type MinItems<N extends number | { value: number; error?: string }> =\n N extends { value: infer V extends number; error: infer E extends string }\n ? { readonly __tsgonest_minItems?: V; readonly __tsgonest_minItems_error?: E }\n : { readonly __tsgonest_minItems?: N extends { value: infer V } ? V : N };\n\n/**\n * Maximum array length.\n * @example MaxItems<100>\n */\nexport type MaxItems<N extends number | { value: number; error?: string }> =\n N extends { value: infer V extends number; error: infer E extends string }\n ? { readonly __tsgonest_maxItems?: V; readonly __tsgonest_maxItems_error?: E }\n : { readonly __tsgonest_maxItems?: N extends { value: infer V } ? V : N };\n\n/**\n * Array items must be unique.\n * @example UniqueItems or Unique or Unique<{error: \"No duplicates\"}>\n */\nexport type UniqueItems<C extends { error?: string } = {}> =\n C extends { error: infer E extends string }\n ? { readonly __tsgonest_uniqueItems?: true; readonly __tsgonest_uniqueItems_error?: E }\n : { readonly __tsgonest_uniqueItems?: true };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// String Case Validation\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * String must be all uppercase.\n * @example Uppercase or Uppercase<{error: \"Must be uppercase\"}>\n */\nexport type Uppercase<C extends { error?: string } = {}> =\n C extends { error: infer E extends string }\n ? { readonly __tsgonest_uppercase?: true; readonly __tsgonest_uppercase_error?: E }\n : { readonly __tsgonest_uppercase?: true };\n\n/**\n * String must be all lowercase.\n * @example Lowercase or Lowercase<{error: \"Must be lowercase\"}>\n */\nexport type Lowercase<C extends { error?: string } = {}> =\n C extends { error: infer E extends string }\n ? { readonly __tsgonest_lowercase?: true; readonly __tsgonest_lowercase_error?: E }\n : { readonly __tsgonest_lowercase?: true };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Transforms (applied before validation, never fail)\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** Trim whitespace before validation. */\nexport type Trim = { readonly __tsgonest_transform_trim?: true };\n\n/** Convert to lowercase before validation. */\nexport type ToLowerCase = { readonly __tsgonest_transform_toLowerCase?: true };\n\n/** Convert to uppercase before validation. */\nexport type ToUpperCase = { readonly __tsgonest_transform_toUpperCase?: true };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Coercion\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Coerce string inputs to the declared type before validation.\n * - \"123\" → 123 (string to number)\n * - \"true\"/\"false\" → true/false (string to boolean)\n *\n * @example\n * page: number & Coerce\n * active: boolean & Coerce\n */\nexport type Coerce = { readonly __tsgonest_coerce?: true };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Custom Validators (function reference)\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Validate using a custom function. The function must be a predicate:\n * `(value: T) => boolean`. tsgonest resolves the function's source file\n * and emits an import + call in the generated validator.\n *\n * @example\n * import { isValidCard } from \"./validators/credit-card\";\n *\n * interface PaymentDto {\n * card: string & Validate<typeof isValidCard>;\n * card: string & Validate<{fn: typeof isValidCard, error: \"Invalid card\"}>;\n * }\n */\nexport type Validate<\n F extends ((...args: any[]) => boolean) | { fn: (...args: any[]) => boolean; error?: string }\n> = F extends { fn: infer Fn; error: infer E extends string }\n ? { readonly __tsgonest_validate?: Fn; readonly __tsgonest_validate_error?: E }\n : { readonly __tsgonest_validate?: F extends { fn: infer Fn } ? Fn : F };\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Meta Types\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Global error message — applies to all validation failures on this property.\n * Per-constraint errors (via `error` field) take precedence.\n * @example string & Format<\"email\"> & Error<\"Invalid email\">\n */\nexport type Error<M extends string> = { readonly __tsgonest_error?: M };\n\n/**\n * Default value for optional properties. Assigned when value is undefined.\n * @example theme?: string & Default<\"light\">\n */\nexport type Default<V extends string | number | boolean> = {\n readonly __tsgonest_default?: V;\n};\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Compound Constraints\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Exact length (sets both MinLength and MaxLength).\n * @example Length<2> or Length<{value: 2, error: \"Must be exactly 2 chars\"}>\n */\nexport type Length<N extends number | { value: number; error?: string }> =\n MinLength<N> & MaxLength<N>;\n\n/**\n * Numeric range (inclusive). Sets Minimum and Maximum.\n * @example Range<{min: 0, max: 100}> or Range<{min: 0, max: 100, error: \"Out of range\"}>\n */\nexport type Range<R extends { min: number; max: number; error?: string }> =\n Minimum<R extends { error: string } ? { value: R[\"min\"]; error: R[\"error\"] } : R[\"min\"]>\n & Maximum<R extends { error: string } ? { value: R[\"max\"]; error: R[\"error\"] } : R[\"max\"]>;\n\n/**\n * String length range. Sets MinLength and MaxLength.\n * @example Between<{min: 1, max: 255}> or Between<{min: 1, max: 255, error: \"Bad length\"}>\n */\nexport type Between<R extends { min: number; max: number; error?: string }> =\n MinLength<R extends { error: string } ? { value: R[\"min\"]; error: R[\"error\"] } : R[\"min\"]>\n & MaxLength<R extends { error: string } ? { value: R[\"max\"]; error: R[\"error\"] } : R[\"max\"]>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Short Aliases (Zod-style)\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** Alias for Minimum. `Min<0>` = `Minimum<0>` */\nexport type Min<N extends number | { value: number; error?: string }> = Minimum<N>;\n\n/** Alias for Maximum. `Max<100>` = `Maximum<100>` */\nexport type Max<N extends number | { value: number; error?: string }> = Maximum<N>;\n\n/** Alias for ExclusiveMinimum. `Gt<0>` = \"greater than 0\" */\nexport type Gt<N extends number | { value: number; error?: string }> = ExclusiveMinimum<N>;\n\n/** Alias for ExclusiveMaximum. `Lt<100>` = \"less than 100\" */\nexport type Lt<N extends number | { value: number; error?: string }> = ExclusiveMaximum<N>;\n\n/** Alias for Minimum + ExclusiveMinimum combo. `Gte<0>` = `Min<0>` */\nexport type Gte<N extends number | { value: number; error?: string }> = Minimum<N>;\n\n/** Alias for Maximum + ExclusiveMaximum combo. `Lte<100>` = `Max<100>` */\nexport type Lte<N extends number | { value: number; error?: string }> = Maximum<N>;\n\n/** Alias for MultipleOf. `Step<0.01>` */\nexport type Step<N extends number | { value: number; error?: string }> = MultipleOf<N>;\n\n/** Alias for UniqueItems. `Unique` */\nexport type Unique<C extends { error?: string } = {}> = UniqueItems<C>;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Format Aliases (direct exports, no namespace needed)\n// ═══════════════════════════════════════════════════════════════════════════════\n\nexport type Email = Format<\"email\">;\nexport type Uuid = Format<\"uuid\">;\nexport type Url = Format<\"url\">;\nexport type Uri = Format<\"uri\">;\nexport type IPv4 = Format<\"ipv4\">;\nexport type IPv6 = Format<\"ipv6\">;\nexport type DateTime = Format<\"date-time\">;\nexport type DateOnly = Format<\"date\">;\nexport type Time = Format<\"time\">;\nexport type Duration = Format<\"duration\">;\nexport type Jwt = Format<\"jwt\">;\nexport type Ulid = Format<\"ulid\">;\nexport type Cuid = Format<\"cuid\">;\nexport type Cuid2 = Format<\"cuid2\">;\nexport type NanoId = Format<\"nanoid\">;\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Numeric Aliases\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** number & Gt<0> */\nexport type Positive = ExclusiveMinimum<0>;\n\n/** number & Lt<0> */\nexport type Negative = ExclusiveMaximum<0>;\n\n/** number & Min<0> */\nexport type NonNegative = Minimum<0>;\n\n/** number & Max<0> */\nexport type NonPositive = Maximum<0>;\n\n/** number & Type<\"int32\"> */\nexport type Int = Type<\"int32\">;\n\n/** number & Type<\"int64\"> (JS safe integer range) */\nexport type SafeInt = Type<\"int64\">;\n\n/** number & Type<\"float\"> (finite, no Infinity/NaN) */\nexport type Finite = Type<\"float\">;\n\n/** number & Type<\"uint32\"> */\nexport type Uint = Type<\"uint32\">;\n\n/** number & Type<\"double\"> */\nexport type Double = Type<\"double\">;\n"],"mappings":""}
|
package/package.json
CHANGED