@tsgonest/types 0.4.2 → 0.4.4
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 +31 -27
- package/dist/tags.d.cts.map +1 -1
- package/dist/tags.d.mts +31 -27
- 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
|
@@ -7,6 +7,10 @@ declare namespace tags_d_exports {
|
|
|
7
7
|
* These types exist purely at compile time. They produce NO runtime code.
|
|
8
8
|
* The tsgonest compiler reads phantom properties (`__tsgonest_*`) to generate validators.
|
|
9
9
|
*
|
|
10
|
+
* All phantom properties are optional (`?`) so that branded types remain
|
|
11
|
+
* assignable from their base types (e.g. `string` → `string & Email`).
|
|
12
|
+
* This follows the same pattern as typia's optional `"typia.tag"` property.
|
|
13
|
+
*
|
|
10
14
|
* Every constraint supports two forms:
|
|
11
15
|
* - Simple: Min<0> — clean, no custom error
|
|
12
16
|
* - Extended: Min<{value: 0, error: "Must be positive"}> — with per-constraint error
|
|
@@ -50,10 +54,10 @@ type StrVal<S extends string | {
|
|
|
50
54
|
type TypeVal<T, Base> = T extends {
|
|
51
55
|
type: infer V;
|
|
52
56
|
} ? V : T;
|
|
53
|
-
/** Conditionally add
|
|
57
|
+
/** Conditionally add an optional _error phantom property. */
|
|
54
58
|
type WithErr<Prefix extends string, C> = C extends {
|
|
55
59
|
error: infer E extends string;
|
|
56
|
-
} ? { readonly [K in `${Prefix}_error`]
|
|
60
|
+
} ? { readonly [K in `${Prefix}_error`]?: E } : {};
|
|
57
61
|
/** All supported string format values. */
|
|
58
62
|
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";
|
|
59
63
|
/**
|
|
@@ -67,7 +71,7 @@ type Format<F extends FormatValue | {
|
|
|
67
71
|
type: FormatValue;
|
|
68
72
|
error?: string;
|
|
69
73
|
}> = {
|
|
70
|
-
readonly __tsgonest_format
|
|
74
|
+
readonly __tsgonest_format?: TypeVal<F, FormatValue>;
|
|
71
75
|
} & WithErr<"__tsgonest_format", F>;
|
|
72
76
|
/**
|
|
73
77
|
* Minimum string length.
|
|
@@ -77,7 +81,7 @@ type MinLength<N extends number | {
|
|
|
77
81
|
value: number;
|
|
78
82
|
error?: string;
|
|
79
83
|
}> = {
|
|
80
|
-
readonly __tsgonest_minLength
|
|
84
|
+
readonly __tsgonest_minLength?: NumVal<N>;
|
|
81
85
|
} & WithErr<"__tsgonest_minLength", N>;
|
|
82
86
|
/**
|
|
83
87
|
* Maximum string length.
|
|
@@ -87,7 +91,7 @@ type MaxLength<N extends number | {
|
|
|
87
91
|
value: number;
|
|
88
92
|
error?: string;
|
|
89
93
|
}> = {
|
|
90
|
-
readonly __tsgonest_maxLength
|
|
94
|
+
readonly __tsgonest_maxLength?: NumVal<N>;
|
|
91
95
|
} & WithErr<"__tsgonest_maxLength", N>;
|
|
92
96
|
/**
|
|
93
97
|
* Regex pattern constraint.
|
|
@@ -97,7 +101,7 @@ type Pattern<P extends string | {
|
|
|
97
101
|
value: string;
|
|
98
102
|
error?: string;
|
|
99
103
|
}> = {
|
|
100
|
-
readonly __tsgonest_pattern
|
|
104
|
+
readonly __tsgonest_pattern?: StrVal<P>;
|
|
101
105
|
} & WithErr<"__tsgonest_pattern", P>;
|
|
102
106
|
/**
|
|
103
107
|
* String must start with prefix.
|
|
@@ -107,7 +111,7 @@ type StartsWith<S extends string | {
|
|
|
107
111
|
value: string;
|
|
108
112
|
error?: string;
|
|
109
113
|
}> = {
|
|
110
|
-
readonly __tsgonest_startsWith
|
|
114
|
+
readonly __tsgonest_startsWith?: StrVal<S>;
|
|
111
115
|
} & WithErr<"__tsgonest_startsWith", S>;
|
|
112
116
|
/**
|
|
113
117
|
* String must end with suffix.
|
|
@@ -117,7 +121,7 @@ type EndsWith<S extends string | {
|
|
|
117
121
|
value: string;
|
|
118
122
|
error?: string;
|
|
119
123
|
}> = {
|
|
120
|
-
readonly __tsgonest_endsWith
|
|
124
|
+
readonly __tsgonest_endsWith?: StrVal<S>;
|
|
121
125
|
} & WithErr<"__tsgonest_endsWith", S>;
|
|
122
126
|
/**
|
|
123
127
|
* String must contain substring.
|
|
@@ -127,7 +131,7 @@ type Includes<S extends string | {
|
|
|
127
131
|
value: string;
|
|
128
132
|
error?: string;
|
|
129
133
|
}> = {
|
|
130
|
-
readonly __tsgonest_includes
|
|
134
|
+
readonly __tsgonest_includes?: StrVal<S>;
|
|
131
135
|
} & WithErr<"__tsgonest_includes", S>;
|
|
132
136
|
/**
|
|
133
137
|
* Minimum value (inclusive): value >= N.
|
|
@@ -137,7 +141,7 @@ type Minimum<N extends number | {
|
|
|
137
141
|
value: number;
|
|
138
142
|
error?: string;
|
|
139
143
|
}> = {
|
|
140
|
-
readonly __tsgonest_minimum
|
|
144
|
+
readonly __tsgonest_minimum?: NumVal<N>;
|
|
141
145
|
} & WithErr<"__tsgonest_minimum", N>;
|
|
142
146
|
/**
|
|
143
147
|
* Maximum value (inclusive): value <= N.
|
|
@@ -147,7 +151,7 @@ type Maximum<N extends number | {
|
|
|
147
151
|
value: number;
|
|
148
152
|
error?: string;
|
|
149
153
|
}> = {
|
|
150
|
-
readonly __tsgonest_maximum
|
|
154
|
+
readonly __tsgonest_maximum?: NumVal<N>;
|
|
151
155
|
} & WithErr<"__tsgonest_maximum", N>;
|
|
152
156
|
/**
|
|
153
157
|
* Exclusive minimum: value > N.
|
|
@@ -157,7 +161,7 @@ type ExclusiveMinimum<N extends number | {
|
|
|
157
161
|
value: number;
|
|
158
162
|
error?: string;
|
|
159
163
|
}> = {
|
|
160
|
-
readonly __tsgonest_exclusiveMinimum
|
|
164
|
+
readonly __tsgonest_exclusiveMinimum?: NumVal<N>;
|
|
161
165
|
} & WithErr<"__tsgonest_exclusiveMinimum", N>;
|
|
162
166
|
/**
|
|
163
167
|
* Exclusive maximum: value < N.
|
|
@@ -167,7 +171,7 @@ type ExclusiveMaximum<N extends number | {
|
|
|
167
171
|
value: number;
|
|
168
172
|
error?: string;
|
|
169
173
|
}> = {
|
|
170
|
-
readonly __tsgonest_exclusiveMaximum
|
|
174
|
+
readonly __tsgonest_exclusiveMaximum?: NumVal<N>;
|
|
171
175
|
} & WithErr<"__tsgonest_exclusiveMaximum", N>;
|
|
172
176
|
/**
|
|
173
177
|
* Value must be a multiple of N.
|
|
@@ -177,7 +181,7 @@ type MultipleOf<N extends number | {
|
|
|
177
181
|
value: number;
|
|
178
182
|
error?: string;
|
|
179
183
|
}> = {
|
|
180
|
-
readonly __tsgonest_multipleOf
|
|
184
|
+
readonly __tsgonest_multipleOf?: NumVal<N>;
|
|
181
185
|
} & WithErr<"__tsgonest_multipleOf", N>;
|
|
182
186
|
/** Valid numeric type values. */
|
|
183
187
|
type NumericTypeValue = "int32" | "uint32" | "int64" | "uint64" | "float" | "double";
|
|
@@ -189,7 +193,7 @@ type Type<T extends NumericTypeValue | {
|
|
|
189
193
|
type: NumericTypeValue;
|
|
190
194
|
error?: string;
|
|
191
195
|
}> = {
|
|
192
|
-
readonly __tsgonest_type
|
|
196
|
+
readonly __tsgonest_type?: TypeVal<T, NumericTypeValue>;
|
|
193
197
|
} & WithErr<"__tsgonest_type", T>;
|
|
194
198
|
/**
|
|
195
199
|
* Minimum array length.
|
|
@@ -199,7 +203,7 @@ type MinItems<N extends number | {
|
|
|
199
203
|
value: number;
|
|
200
204
|
error?: string;
|
|
201
205
|
}> = {
|
|
202
|
-
readonly __tsgonest_minItems
|
|
206
|
+
readonly __tsgonest_minItems?: NumVal<N>;
|
|
203
207
|
} & WithErr<"__tsgonest_minItems", N>;
|
|
204
208
|
/**
|
|
205
209
|
* Maximum array length.
|
|
@@ -209,7 +213,7 @@ type MaxItems<N extends number | {
|
|
|
209
213
|
value: number;
|
|
210
214
|
error?: string;
|
|
211
215
|
}> = {
|
|
212
|
-
readonly __tsgonest_maxItems
|
|
216
|
+
readonly __tsgonest_maxItems?: NumVal<N>;
|
|
213
217
|
} & WithErr<"__tsgonest_maxItems", N>;
|
|
214
218
|
/**
|
|
215
219
|
* Array items must be unique.
|
|
@@ -218,7 +222,7 @@ type MaxItems<N extends number | {
|
|
|
218
222
|
type UniqueItems<C extends {
|
|
219
223
|
error?: string;
|
|
220
224
|
} = {}> = {
|
|
221
|
-
readonly __tsgonest_uniqueItems
|
|
225
|
+
readonly __tsgonest_uniqueItems?: true;
|
|
222
226
|
} & WithErr<"__tsgonest_uniqueItems", C>;
|
|
223
227
|
/**
|
|
224
228
|
* String must be all uppercase.
|
|
@@ -227,7 +231,7 @@ type UniqueItems<C extends {
|
|
|
227
231
|
type Uppercase<C extends {
|
|
228
232
|
error?: string;
|
|
229
233
|
} = {}> = {
|
|
230
|
-
readonly __tsgonest_uppercase
|
|
234
|
+
readonly __tsgonest_uppercase?: true;
|
|
231
235
|
} & WithErr<"__tsgonest_uppercase", C>;
|
|
232
236
|
/**
|
|
233
237
|
* String must be all lowercase.
|
|
@@ -236,19 +240,19 @@ type Uppercase<C extends {
|
|
|
236
240
|
type Lowercase<C extends {
|
|
237
241
|
error?: string;
|
|
238
242
|
} = {}> = {
|
|
239
|
-
readonly __tsgonest_lowercase
|
|
243
|
+
readonly __tsgonest_lowercase?: true;
|
|
240
244
|
} & WithErr<"__tsgonest_lowercase", C>;
|
|
241
245
|
/** Trim whitespace before validation. */
|
|
242
246
|
type Trim = {
|
|
243
|
-
readonly __tsgonest_transform_trim
|
|
247
|
+
readonly __tsgonest_transform_trim?: true;
|
|
244
248
|
};
|
|
245
249
|
/** Convert to lowercase before validation. */
|
|
246
250
|
type ToLowerCase = {
|
|
247
|
-
readonly __tsgonest_transform_toLowerCase
|
|
251
|
+
readonly __tsgonest_transform_toLowerCase?: true;
|
|
248
252
|
};
|
|
249
253
|
/** Convert to uppercase before validation. */
|
|
250
254
|
type ToUpperCase = {
|
|
251
|
-
readonly __tsgonest_transform_toUpperCase
|
|
255
|
+
readonly __tsgonest_transform_toUpperCase?: true;
|
|
252
256
|
};
|
|
253
257
|
/**
|
|
254
258
|
* Coerce string inputs to the declared type before validation.
|
|
@@ -260,7 +264,7 @@ type ToUpperCase = {
|
|
|
260
264
|
* active: boolean & Coerce
|
|
261
265
|
*/
|
|
262
266
|
type Coerce = {
|
|
263
|
-
readonly __tsgonest_coerce
|
|
267
|
+
readonly __tsgonest_coerce?: true;
|
|
264
268
|
};
|
|
265
269
|
/**
|
|
266
270
|
* Validate using a custom function. The function must be a predicate:
|
|
@@ -279,7 +283,7 @@ type Validate<F extends ((...args: any[]) => boolean) | {
|
|
|
279
283
|
fn: (...args: any[]) => boolean;
|
|
280
284
|
error?: string;
|
|
281
285
|
}> = {
|
|
282
|
-
readonly __tsgonest_validate
|
|
286
|
+
readonly __tsgonest_validate?: F extends {
|
|
283
287
|
fn: infer Fn;
|
|
284
288
|
} ? Fn : F;
|
|
285
289
|
} & WithErr<"__tsgonest_validate", F>;
|
|
@@ -289,14 +293,14 @@ type Validate<F extends ((...args: any[]) => boolean) | {
|
|
|
289
293
|
* @example string & Format<"email"> & Error<"Invalid email">
|
|
290
294
|
*/
|
|
291
295
|
type Error<M extends string> = {
|
|
292
|
-
readonly __tsgonest_error
|
|
296
|
+
readonly __tsgonest_error?: M;
|
|
293
297
|
};
|
|
294
298
|
/**
|
|
295
299
|
* Default value for optional properties. Assigned when value is undefined.
|
|
296
300
|
* @example theme?: string & Default<"light">
|
|
297
301
|
*/
|
|
298
302
|
type Default<V extends string | number | boolean> = {
|
|
299
|
-
readonly __tsgonest_default
|
|
303
|
+
readonly __tsgonest_default?: V;
|
|
300
304
|
};
|
|
301
305
|
/**
|
|
302
306
|
* Exact length (sets both MinLength and MaxLength).
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAyCK,MAAA;EAA4B,KAAA;EAAe,KAAA;AAAA,KAC9C,CAAA;EAAY,KAAA;AAAA,IAAmB,CAAA,GAAI,CAAA;;KAGhC,MAAA;EAA4B,KAAA;EAAe,KAAA;AAAA,KAC9C,CAAA;EAAY,KAAA;AAAA,IAAmB,CAAA,GAAI,CAAA;;KAGhC,OAAA,YACH,CAAA;EAAY,IAAA;AAAA,IAAkB,CAAA,GAAI,CAAA;;KAG/B,OAAA,6BACH,CAAA;EAAY,KAAA;AAAA,wBACY,MAAA,YAAkB,CAAA;;KAQhC,WAAA;;;;;;;;KAoBA,MAAA,WAAiB,WAAA;EAAgB,IAAA,EAAM,WAAA;EAAa,KAAA;AAAA;EAAA,SACrD,iBAAA,GAAoB,OAAA,CAAQ,CAAA,EAAG,WAAA;AAAA,IACtC,OAAA,sBAA6B,CAAA;;;;;KAUrB,SAAA;EAA+B,KAAA;EAAe,KAAA;AAAA;EAAA,SAC/C,oBAAA,GAAuB,MAAA,CAAO,CAAA;AAAA,IACrC,OAAA,yBAAgC,CAAA;;;;;KAMxB,SAAA;EAA+B,KAAA;EAAe,KAAA;AAAA;EAAA,SAC/C,oBAAA,GAAuB,MAAA,CAAO,CAAA;AAAA,IACrC,OAAA,yBAAgC,CAAA;;AA3DE;;;KAiE1B,OAAA;EAA6B,KAAA;EAAe,KAAA;AAAA;EAAA,SAC7C,kBAAA,GAAqB,MAAA,CAAO,CAAA;AAAA,IACnC,OAAA,uBAA8B,CAAA;;;;;KAMtB,UAAA;EAAgC,KAAA;EAAe,KAAA;AAAA;EAAA,SAChD,qBAAA,GAAwB,MAAA,CAAO,CAAA;A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AAM,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
|
@@ -7,6 +7,10 @@ declare namespace tags_d_exports {
|
|
|
7
7
|
* These types exist purely at compile time. They produce NO runtime code.
|
|
8
8
|
* The tsgonest compiler reads phantom properties (`__tsgonest_*`) to generate validators.
|
|
9
9
|
*
|
|
10
|
+
* All phantom properties are optional (`?`) so that branded types remain
|
|
11
|
+
* assignable from their base types (e.g. `string` → `string & Email`).
|
|
12
|
+
* This follows the same pattern as typia's optional `"typia.tag"` property.
|
|
13
|
+
*
|
|
10
14
|
* Every constraint supports two forms:
|
|
11
15
|
* - Simple: Min<0> — clean, no custom error
|
|
12
16
|
* - Extended: Min<{value: 0, error: "Must be positive"}> — with per-constraint error
|
|
@@ -50,10 +54,10 @@ type StrVal<S extends string | {
|
|
|
50
54
|
type TypeVal<T, Base> = T extends {
|
|
51
55
|
type: infer V;
|
|
52
56
|
} ? V : T;
|
|
53
|
-
/** Conditionally add
|
|
57
|
+
/** Conditionally add an optional _error phantom property. */
|
|
54
58
|
type WithErr<Prefix extends string, C> = C extends {
|
|
55
59
|
error: infer E extends string;
|
|
56
|
-
} ? { readonly [K in `${Prefix}_error`]
|
|
60
|
+
} ? { readonly [K in `${Prefix}_error`]?: E } : {};
|
|
57
61
|
/** All supported string format values. */
|
|
58
62
|
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";
|
|
59
63
|
/**
|
|
@@ -67,7 +71,7 @@ type Format<F extends FormatValue | {
|
|
|
67
71
|
type: FormatValue;
|
|
68
72
|
error?: string;
|
|
69
73
|
}> = {
|
|
70
|
-
readonly __tsgonest_format
|
|
74
|
+
readonly __tsgonest_format?: TypeVal<F, FormatValue>;
|
|
71
75
|
} & WithErr<"__tsgonest_format", F>;
|
|
72
76
|
/**
|
|
73
77
|
* Minimum string length.
|
|
@@ -77,7 +81,7 @@ type MinLength<N extends number | {
|
|
|
77
81
|
value: number;
|
|
78
82
|
error?: string;
|
|
79
83
|
}> = {
|
|
80
|
-
readonly __tsgonest_minLength
|
|
84
|
+
readonly __tsgonest_minLength?: NumVal<N>;
|
|
81
85
|
} & WithErr<"__tsgonest_minLength", N>;
|
|
82
86
|
/**
|
|
83
87
|
* Maximum string length.
|
|
@@ -87,7 +91,7 @@ type MaxLength<N extends number | {
|
|
|
87
91
|
value: number;
|
|
88
92
|
error?: string;
|
|
89
93
|
}> = {
|
|
90
|
-
readonly __tsgonest_maxLength
|
|
94
|
+
readonly __tsgonest_maxLength?: NumVal<N>;
|
|
91
95
|
} & WithErr<"__tsgonest_maxLength", N>;
|
|
92
96
|
/**
|
|
93
97
|
* Regex pattern constraint.
|
|
@@ -97,7 +101,7 @@ type Pattern<P extends string | {
|
|
|
97
101
|
value: string;
|
|
98
102
|
error?: string;
|
|
99
103
|
}> = {
|
|
100
|
-
readonly __tsgonest_pattern
|
|
104
|
+
readonly __tsgonest_pattern?: StrVal<P>;
|
|
101
105
|
} & WithErr<"__tsgonest_pattern", P>;
|
|
102
106
|
/**
|
|
103
107
|
* String must start with prefix.
|
|
@@ -107,7 +111,7 @@ type StartsWith<S extends string | {
|
|
|
107
111
|
value: string;
|
|
108
112
|
error?: string;
|
|
109
113
|
}> = {
|
|
110
|
-
readonly __tsgonest_startsWith
|
|
114
|
+
readonly __tsgonest_startsWith?: StrVal<S>;
|
|
111
115
|
} & WithErr<"__tsgonest_startsWith", S>;
|
|
112
116
|
/**
|
|
113
117
|
* String must end with suffix.
|
|
@@ -117,7 +121,7 @@ type EndsWith<S extends string | {
|
|
|
117
121
|
value: string;
|
|
118
122
|
error?: string;
|
|
119
123
|
}> = {
|
|
120
|
-
readonly __tsgonest_endsWith
|
|
124
|
+
readonly __tsgonest_endsWith?: StrVal<S>;
|
|
121
125
|
} & WithErr<"__tsgonest_endsWith", S>;
|
|
122
126
|
/**
|
|
123
127
|
* String must contain substring.
|
|
@@ -127,7 +131,7 @@ type Includes<S extends string | {
|
|
|
127
131
|
value: string;
|
|
128
132
|
error?: string;
|
|
129
133
|
}> = {
|
|
130
|
-
readonly __tsgonest_includes
|
|
134
|
+
readonly __tsgonest_includes?: StrVal<S>;
|
|
131
135
|
} & WithErr<"__tsgonest_includes", S>;
|
|
132
136
|
/**
|
|
133
137
|
* Minimum value (inclusive): value >= N.
|
|
@@ -137,7 +141,7 @@ type Minimum<N extends number | {
|
|
|
137
141
|
value: number;
|
|
138
142
|
error?: string;
|
|
139
143
|
}> = {
|
|
140
|
-
readonly __tsgonest_minimum
|
|
144
|
+
readonly __tsgonest_minimum?: NumVal<N>;
|
|
141
145
|
} & WithErr<"__tsgonest_minimum", N>;
|
|
142
146
|
/**
|
|
143
147
|
* Maximum value (inclusive): value <= N.
|
|
@@ -147,7 +151,7 @@ type Maximum<N extends number | {
|
|
|
147
151
|
value: number;
|
|
148
152
|
error?: string;
|
|
149
153
|
}> = {
|
|
150
|
-
readonly __tsgonest_maximum
|
|
154
|
+
readonly __tsgonest_maximum?: NumVal<N>;
|
|
151
155
|
} & WithErr<"__tsgonest_maximum", N>;
|
|
152
156
|
/**
|
|
153
157
|
* Exclusive minimum: value > N.
|
|
@@ -157,7 +161,7 @@ type ExclusiveMinimum<N extends number | {
|
|
|
157
161
|
value: number;
|
|
158
162
|
error?: string;
|
|
159
163
|
}> = {
|
|
160
|
-
readonly __tsgonest_exclusiveMinimum
|
|
164
|
+
readonly __tsgonest_exclusiveMinimum?: NumVal<N>;
|
|
161
165
|
} & WithErr<"__tsgonest_exclusiveMinimum", N>;
|
|
162
166
|
/**
|
|
163
167
|
* Exclusive maximum: value < N.
|
|
@@ -167,7 +171,7 @@ type ExclusiveMaximum<N extends number | {
|
|
|
167
171
|
value: number;
|
|
168
172
|
error?: string;
|
|
169
173
|
}> = {
|
|
170
|
-
readonly __tsgonest_exclusiveMaximum
|
|
174
|
+
readonly __tsgonest_exclusiveMaximum?: NumVal<N>;
|
|
171
175
|
} & WithErr<"__tsgonest_exclusiveMaximum", N>;
|
|
172
176
|
/**
|
|
173
177
|
* Value must be a multiple of N.
|
|
@@ -177,7 +181,7 @@ type MultipleOf<N extends number | {
|
|
|
177
181
|
value: number;
|
|
178
182
|
error?: string;
|
|
179
183
|
}> = {
|
|
180
|
-
readonly __tsgonest_multipleOf
|
|
184
|
+
readonly __tsgonest_multipleOf?: NumVal<N>;
|
|
181
185
|
} & WithErr<"__tsgonest_multipleOf", N>;
|
|
182
186
|
/** Valid numeric type values. */
|
|
183
187
|
type NumericTypeValue = "int32" | "uint32" | "int64" | "uint64" | "float" | "double";
|
|
@@ -189,7 +193,7 @@ type Type<T extends NumericTypeValue | {
|
|
|
189
193
|
type: NumericTypeValue;
|
|
190
194
|
error?: string;
|
|
191
195
|
}> = {
|
|
192
|
-
readonly __tsgonest_type
|
|
196
|
+
readonly __tsgonest_type?: TypeVal<T, NumericTypeValue>;
|
|
193
197
|
} & WithErr<"__tsgonest_type", T>;
|
|
194
198
|
/**
|
|
195
199
|
* Minimum array length.
|
|
@@ -199,7 +203,7 @@ type MinItems<N extends number | {
|
|
|
199
203
|
value: number;
|
|
200
204
|
error?: string;
|
|
201
205
|
}> = {
|
|
202
|
-
readonly __tsgonest_minItems
|
|
206
|
+
readonly __tsgonest_minItems?: NumVal<N>;
|
|
203
207
|
} & WithErr<"__tsgonest_minItems", N>;
|
|
204
208
|
/**
|
|
205
209
|
* Maximum array length.
|
|
@@ -209,7 +213,7 @@ type MaxItems<N extends number | {
|
|
|
209
213
|
value: number;
|
|
210
214
|
error?: string;
|
|
211
215
|
}> = {
|
|
212
|
-
readonly __tsgonest_maxItems
|
|
216
|
+
readonly __tsgonest_maxItems?: NumVal<N>;
|
|
213
217
|
} & WithErr<"__tsgonest_maxItems", N>;
|
|
214
218
|
/**
|
|
215
219
|
* Array items must be unique.
|
|
@@ -218,7 +222,7 @@ type MaxItems<N extends number | {
|
|
|
218
222
|
type UniqueItems<C extends {
|
|
219
223
|
error?: string;
|
|
220
224
|
} = {}> = {
|
|
221
|
-
readonly __tsgonest_uniqueItems
|
|
225
|
+
readonly __tsgonest_uniqueItems?: true;
|
|
222
226
|
} & WithErr<"__tsgonest_uniqueItems", C>;
|
|
223
227
|
/**
|
|
224
228
|
* String must be all uppercase.
|
|
@@ -227,7 +231,7 @@ type UniqueItems<C extends {
|
|
|
227
231
|
type Uppercase<C extends {
|
|
228
232
|
error?: string;
|
|
229
233
|
} = {}> = {
|
|
230
|
-
readonly __tsgonest_uppercase
|
|
234
|
+
readonly __tsgonest_uppercase?: true;
|
|
231
235
|
} & WithErr<"__tsgonest_uppercase", C>;
|
|
232
236
|
/**
|
|
233
237
|
* String must be all lowercase.
|
|
@@ -236,19 +240,19 @@ type Uppercase<C extends {
|
|
|
236
240
|
type Lowercase<C extends {
|
|
237
241
|
error?: string;
|
|
238
242
|
} = {}> = {
|
|
239
|
-
readonly __tsgonest_lowercase
|
|
243
|
+
readonly __tsgonest_lowercase?: true;
|
|
240
244
|
} & WithErr<"__tsgonest_lowercase", C>;
|
|
241
245
|
/** Trim whitespace before validation. */
|
|
242
246
|
type Trim = {
|
|
243
|
-
readonly __tsgonest_transform_trim
|
|
247
|
+
readonly __tsgonest_transform_trim?: true;
|
|
244
248
|
};
|
|
245
249
|
/** Convert to lowercase before validation. */
|
|
246
250
|
type ToLowerCase = {
|
|
247
|
-
readonly __tsgonest_transform_toLowerCase
|
|
251
|
+
readonly __tsgonest_transform_toLowerCase?: true;
|
|
248
252
|
};
|
|
249
253
|
/** Convert to uppercase before validation. */
|
|
250
254
|
type ToUpperCase = {
|
|
251
|
-
readonly __tsgonest_transform_toUpperCase
|
|
255
|
+
readonly __tsgonest_transform_toUpperCase?: true;
|
|
252
256
|
};
|
|
253
257
|
/**
|
|
254
258
|
* Coerce string inputs to the declared type before validation.
|
|
@@ -260,7 +264,7 @@ type ToUpperCase = {
|
|
|
260
264
|
* active: boolean & Coerce
|
|
261
265
|
*/
|
|
262
266
|
type Coerce = {
|
|
263
|
-
readonly __tsgonest_coerce
|
|
267
|
+
readonly __tsgonest_coerce?: true;
|
|
264
268
|
};
|
|
265
269
|
/**
|
|
266
270
|
* Validate using a custom function. The function must be a predicate:
|
|
@@ -279,7 +283,7 @@ type Validate<F extends ((...args: any[]) => boolean) | {
|
|
|
279
283
|
fn: (...args: any[]) => boolean;
|
|
280
284
|
error?: string;
|
|
281
285
|
}> = {
|
|
282
|
-
readonly __tsgonest_validate
|
|
286
|
+
readonly __tsgonest_validate?: F extends {
|
|
283
287
|
fn: infer Fn;
|
|
284
288
|
} ? Fn : F;
|
|
285
289
|
} & WithErr<"__tsgonest_validate", F>;
|
|
@@ -289,14 +293,14 @@ type Validate<F extends ((...args: any[]) => boolean) | {
|
|
|
289
293
|
* @example string & Format<"email"> & Error<"Invalid email">
|
|
290
294
|
*/
|
|
291
295
|
type Error<M extends string> = {
|
|
292
|
-
readonly __tsgonest_error
|
|
296
|
+
readonly __tsgonest_error?: M;
|
|
293
297
|
};
|
|
294
298
|
/**
|
|
295
299
|
* Default value for optional properties. Assigned when value is undefined.
|
|
296
300
|
* @example theme?: string & Default<"light">
|
|
297
301
|
*/
|
|
298
302
|
type Default<V extends string | number | boolean> = {
|
|
299
|
-
readonly __tsgonest_default
|
|
303
|
+
readonly __tsgonest_default?: V;
|
|
300
304
|
};
|
|
301
305
|
/**
|
|
302
306
|
* Exact length (sets both MinLength and MaxLength).
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAyCK,MAAA;EAA4B,KAAA;EAAe,KAAA;AAAA,KAC9C,CAAA;EAAY,KAAA;AAAA,IAAmB,CAAA,GAAI,CAAA;;KAGhC,MAAA;EAA4B,KAAA;EAAe,KAAA;AAAA,KAC9C,CAAA;EAAY,KAAA;AAAA,IAAmB,CAAA,GAAI,CAAA;;KAGhC,OAAA,YACH,CAAA;EAAY,IAAA;AAAA,IAAkB,CAAA,GAAI,CAAA;;KAG/B,OAAA,6BACH,CAAA;EAAY,KAAA;AAAA,wBACY,MAAA,YAAkB,CAAA;;KAQhC,WAAA;;;;;;;;KAoBA,MAAA,WAAiB,WAAA;EAAgB,IAAA,EAAM,WAAA;EAAa,KAAA;AAAA;EAAA,SACrD,iBAAA,GAAoB,OAAA,CAAQ,CAAA,EAAG,WAAA;AAAA,IACtC,OAAA,sBAA6B,CAAA;;;;;KAUrB,SAAA;EAA+B,KAAA;EAAe,KAAA;AAAA;EAAA,SAC/C,oBAAA,GAAuB,MAAA,CAAO,CAAA;AAAA,IACrC,OAAA,yBAAgC,CAAA;;;;;KAMxB,SAAA;EAA+B,KAAA;EAAe,KAAA;AAAA;EAAA,SAC/C,oBAAA,GAAuB,MAAA,CAAO,CAAA;AAAA,IACrC,OAAA,yBAAgC,CAAA;;AA3DE;;;KAiE1B,OAAA;EAA6B,KAAA;EAAe,KAAA;AAAA;EAAA,SAC7C,kBAAA,GAAqB,MAAA,CAAO,CAAA;AAAA,IACnC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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 * 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 a _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 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":""}
|
package/package.json
CHANGED