typetify 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +327 -0
  3. package/dist/async/index.d.mts +152 -0
  4. package/dist/async/index.d.ts +152 -0
  5. package/dist/async/index.js +49 -0
  6. package/dist/async/index.js.map +1 -0
  7. package/dist/async/index.mjs +4 -0
  8. package/dist/async/index.mjs.map +1 -0
  9. package/dist/chunk-2LJ6NZ6K.js +108 -0
  10. package/dist/chunk-2LJ6NZ6K.js.map +1 -0
  11. package/dist/chunk-44Y5JSGU.js +145 -0
  12. package/dist/chunk-44Y5JSGU.js.map +1 -0
  13. package/dist/chunk-4NXETABV.mjs +116 -0
  14. package/dist/chunk-4NXETABV.mjs.map +1 -0
  15. package/dist/chunk-6ZBTL74K.js +129 -0
  16. package/dist/chunk-6ZBTL74K.js.map +1 -0
  17. package/dist/chunk-CN3GYRJN.mjs +137 -0
  18. package/dist/chunk-CN3GYRJN.mjs.map +1 -0
  19. package/dist/chunk-CNTE6ZVH.js +359 -0
  20. package/dist/chunk-CNTE6ZVH.js.map +1 -0
  21. package/dist/chunk-DBENOSTA.js +156 -0
  22. package/dist/chunk-DBENOSTA.js.map +1 -0
  23. package/dist/chunk-DWIG5GF2.js +135 -0
  24. package/dist/chunk-DWIG5GF2.js.map +1 -0
  25. package/dist/chunk-EAUTTWTQ.mjs +231 -0
  26. package/dist/chunk-EAUTTWTQ.mjs.map +1 -0
  27. package/dist/chunk-FXWYPHA3.mjs +13 -0
  28. package/dist/chunk-FXWYPHA3.mjs.map +1 -0
  29. package/dist/chunk-GS3PP67B.js +200 -0
  30. package/dist/chunk-GS3PP67B.js.map +1 -0
  31. package/dist/chunk-J5LGTIGS.mjs +9 -0
  32. package/dist/chunk-J5LGTIGS.mjs.map +1 -0
  33. package/dist/chunk-JAOGY4JO.mjs +1007 -0
  34. package/dist/chunk-JAOGY4JO.mjs.map +1 -0
  35. package/dist/chunk-JB6UXRKD.mjs +97 -0
  36. package/dist/chunk-JB6UXRKD.mjs.map +1 -0
  37. package/dist/chunk-JQHUBZ4M.js +88 -0
  38. package/dist/chunk-JQHUBZ4M.js.map +1 -0
  39. package/dist/chunk-L3M7LGKL.mjs +128 -0
  40. package/dist/chunk-L3M7LGKL.mjs.map +1 -0
  41. package/dist/chunk-LT7JK7RJ.js +87 -0
  42. package/dist/chunk-LT7JK7RJ.js.map +1 -0
  43. package/dist/chunk-OEJK37LO.mjs +328 -0
  44. package/dist/chunk-OEJK37LO.mjs.map +1 -0
  45. package/dist/chunk-OPVES6W2.js +16 -0
  46. package/dist/chunk-OPVES6W2.js.map +1 -0
  47. package/dist/chunk-OWNUKWXV.js +291 -0
  48. package/dist/chunk-OWNUKWXV.js.map +1 -0
  49. package/dist/chunk-PQTXSQ4P.js +369 -0
  50. package/dist/chunk-PQTXSQ4P.js.map +1 -0
  51. package/dist/chunk-PZ5AY32C.js +11 -0
  52. package/dist/chunk-PZ5AY32C.js.map +1 -0
  53. package/dist/chunk-QFR7DVAJ.mjs +63 -0
  54. package/dist/chunk-QFR7DVAJ.mjs.map +1 -0
  55. package/dist/chunk-SGQNLTRK.js +73 -0
  56. package/dist/chunk-SGQNLTRK.js.map +1 -0
  57. package/dist/chunk-SIA5BSVY.js +1054 -0
  58. package/dist/chunk-SIA5BSVY.js.map +1 -0
  59. package/dist/chunk-SRDWUHDY.mjs +188 -0
  60. package/dist/chunk-SRDWUHDY.mjs.map +1 -0
  61. package/dist/chunk-TXU7NTT4.js +249 -0
  62. package/dist/chunk-TXU7NTT4.js.map +1 -0
  63. package/dist/chunk-TZEWREAC.mjs +277 -0
  64. package/dist/chunk-TZEWREAC.mjs.map +1 -0
  65. package/dist/chunk-V6CWFDIJ.mjs +123 -0
  66. package/dist/chunk-V6CWFDIJ.mjs.map +1 -0
  67. package/dist/chunk-YBJC5WMX.mjs +341 -0
  68. package/dist/chunk-YBJC5WMX.mjs.map +1 -0
  69. package/dist/chunk-YOPAXITF.mjs +75 -0
  70. package/dist/chunk-YOPAXITF.mjs.map +1 -0
  71. package/dist/chunk-ZE4FDBRI.mjs +79 -0
  72. package/dist/chunk-ZE4FDBRI.mjs.map +1 -0
  73. package/dist/collection/index.d.mts +291 -0
  74. package/dist/collection/index.d.ts +291 -0
  75. package/dist/collection/index.js +125 -0
  76. package/dist/collection/index.js.map +1 -0
  77. package/dist/collection/index.mjs +4 -0
  78. package/dist/collection/index.mjs.map +1 -0
  79. package/dist/core/index.d.mts +85 -0
  80. package/dist/core/index.d.ts +85 -0
  81. package/dist/core/index.js +41 -0
  82. package/dist/core/index.js.map +1 -0
  83. package/dist/core/index.mjs +4 -0
  84. package/dist/core/index.mjs.map +1 -0
  85. package/dist/decorator/index.d.mts +165 -0
  86. package/dist/decorator/index.d.ts +165 -0
  87. package/dist/decorator/index.js +57 -0
  88. package/dist/decorator/index.js.map +1 -0
  89. package/dist/decorator/index.mjs +4 -0
  90. package/dist/decorator/index.mjs.map +1 -0
  91. package/dist/dx/index.d.mts +125 -0
  92. package/dist/dx/index.d.ts +125 -0
  93. package/dist/dx/index.js +53 -0
  94. package/dist/dx/index.js.map +1 -0
  95. package/dist/dx/index.mjs +4 -0
  96. package/dist/dx/index.mjs.map +1 -0
  97. package/dist/flow/index.d.mts +165 -0
  98. package/dist/flow/index.d.ts +165 -0
  99. package/dist/flow/index.js +50 -0
  100. package/dist/flow/index.js.map +1 -0
  101. package/dist/flow/index.mjs +5 -0
  102. package/dist/flow/index.mjs.map +1 -0
  103. package/dist/fn/index.d.mts +77 -0
  104. package/dist/fn/index.d.ts +77 -0
  105. package/dist/fn/index.js +37 -0
  106. package/dist/fn/index.js.map +1 -0
  107. package/dist/fn/index.mjs +4 -0
  108. package/dist/fn/index.mjs.map +1 -0
  109. package/dist/guards/index.d.mts +165 -0
  110. package/dist/guards/index.d.ts +165 -0
  111. package/dist/guards/index.js +69 -0
  112. package/dist/guards/index.js.map +1 -0
  113. package/dist/guards/index.mjs +4 -0
  114. package/dist/guards/index.mjs.map +1 -0
  115. package/dist/index.d.mts +228 -0
  116. package/dist/index.d.ts +228 -0
  117. package/dist/index.js +775 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/index.mjs +51 -0
  120. package/dist/index.mjs.map +1 -0
  121. package/dist/input/index.d.mts +185 -0
  122. package/dist/input/index.d.ts +185 -0
  123. package/dist/input/index.js +74 -0
  124. package/dist/input/index.js.map +1 -0
  125. package/dist/input/index.mjs +5 -0
  126. package/dist/input/index.mjs.map +1 -0
  127. package/dist/iterator/index.d.mts +209 -0
  128. package/dist/iterator/index.d.ts +209 -0
  129. package/dist/iterator/index.js +522 -0
  130. package/dist/iterator/index.js.map +1 -0
  131. package/dist/iterator/index.mjs +502 -0
  132. package/dist/iterator/index.mjs.map +1 -0
  133. package/dist/logic/index.d.mts +531 -0
  134. package/dist/logic/index.d.ts +531 -0
  135. package/dist/logic/index.js +416 -0
  136. package/dist/logic/index.js.map +1 -0
  137. package/dist/logic/index.mjs +367 -0
  138. package/dist/logic/index.mjs.map +1 -0
  139. package/dist/math/index.d.mts +86 -0
  140. package/dist/math/index.d.ts +86 -0
  141. package/dist/math/index.js +45 -0
  142. package/dist/math/index.js.map +1 -0
  143. package/dist/math/index.mjs +4 -0
  144. package/dist/math/index.mjs.map +1 -0
  145. package/dist/narrowing/index.d.mts +429 -0
  146. package/dist/narrowing/index.d.ts +429 -0
  147. package/dist/narrowing/index.js +220 -0
  148. package/dist/narrowing/index.js.map +1 -0
  149. package/dist/narrowing/index.mjs +186 -0
  150. package/dist/narrowing/index.mjs.map +1 -0
  151. package/dist/object/index.d.mts +327 -0
  152. package/dist/object/index.d.ts +327 -0
  153. package/dist/object/index.js +113 -0
  154. package/dist/object/index.js.map +1 -0
  155. package/dist/object/index.mjs +4 -0
  156. package/dist/object/index.mjs.map +1 -0
  157. package/dist/result/index.d.mts +201 -0
  158. package/dist/result/index.d.ts +201 -0
  159. package/dist/result/index.js +86 -0
  160. package/dist/result/index.js.map +1 -0
  161. package/dist/result/index.mjs +5 -0
  162. package/dist/result/index.mjs.map +1 -0
  163. package/dist/schema/index.d.mts +216 -0
  164. package/dist/schema/index.d.ts +216 -0
  165. package/dist/schema/index.js +410 -0
  166. package/dist/schema/index.js.map +1 -0
  167. package/dist/schema/index.mjs +384 -0
  168. package/dist/schema/index.mjs.map +1 -0
  169. package/dist/string/index.d.mts +102 -0
  170. package/dist/string/index.d.ts +102 -0
  171. package/dist/string/index.js +49 -0
  172. package/dist/string/index.js.map +1 -0
  173. package/dist/string/index.mjs +4 -0
  174. package/dist/string/index.mjs.map +1 -0
  175. package/dist/typed/index.d.mts +1962 -0
  176. package/dist/typed/index.d.ts +1962 -0
  177. package/dist/typed/index.js +193 -0
  178. package/dist/typed/index.js.map +1 -0
  179. package/dist/typed/index.mjs +4 -0
  180. package/dist/typed/index.mjs.map +1 -0
  181. package/dist/types-Db0vauC3.d.mts +258 -0
  182. package/dist/types-Db0vauC3.d.ts +258 -0
  183. package/dist/types-VsDp2t8s.d.mts +30 -0
  184. package/dist/types-VsDp2t8s.d.ts +30 -0
  185. package/package.json +157 -0
@@ -0,0 +1,1007 @@
1
+ // src/typed/defineConst.ts
2
+ function defineConst(obj) {
3
+ return Object.freeze(obj);
4
+ }
5
+
6
+ // src/typed/defineEnum.ts
7
+ function defineEnum(values) {
8
+ const result = {};
9
+ for (const value of values) {
10
+ result[value] = value;
11
+ }
12
+ return Object.freeze(result);
13
+ }
14
+
15
+ // src/typed/defineTuple.ts
16
+ function defineTuple(...args) {
17
+ return args;
18
+ }
19
+
20
+ // src/typed/createMap.ts
21
+ function createMap(entries) {
22
+ return new Map(entries);
23
+ }
24
+
25
+ // src/typed/createSet.ts
26
+ function createSet(values) {
27
+ return new Set(values);
28
+ }
29
+
30
+ // src/typed/brand.ts
31
+ function brand(value) {
32
+ return value;
33
+ }
34
+
35
+ // src/typed/narrow.ts
36
+ function narrow(value, guard) {
37
+ return guard(value) ? value : void 0;
38
+ }
39
+
40
+ // src/typed/builder.ts
41
+ function createBuilder(initial = {}) {
42
+ return {
43
+ set(key, value) {
44
+ return createBuilder({ ...initial, [key]: value });
45
+ },
46
+ build() {
47
+ return initial;
48
+ },
49
+ current() {
50
+ return initial;
51
+ }
52
+ };
53
+ }
54
+ function defineStateMachine(config) {
55
+ return {
56
+ config,
57
+ getInitialState: () => config.initial,
58
+ transition: (state, event) => {
59
+ const stateConfig = config.states[state];
60
+ if (stateConfig && "on" in stateConfig) {
61
+ const nextState = stateConfig.on[event];
62
+ return nextState ?? state;
63
+ }
64
+ return state;
65
+ }
66
+ };
67
+ }
68
+ function createActions() {
69
+ return new Proxy({}, {
70
+ get: (_, type) => {
71
+ return (payload) => ({ type, ...payload });
72
+ }
73
+ });
74
+ }
75
+ function createTypedEmitter() {
76
+ const listeners = /* @__PURE__ */ new Map();
77
+ return {
78
+ on(event, handler) {
79
+ if (!listeners.has(event)) {
80
+ listeners.set(event, /* @__PURE__ */ new Set());
81
+ }
82
+ listeners.get(event).add(handler);
83
+ return () => {
84
+ listeners.get(event)?.delete(handler);
85
+ };
86
+ },
87
+ emit(event, data) {
88
+ listeners.get(event)?.forEach((handler) => handler(data));
89
+ },
90
+ off(event, handler) {
91
+ listeners.get(event)?.delete(handler);
92
+ },
93
+ clear() {
94
+ listeners.clear();
95
+ }
96
+ };
97
+ }
98
+ function createReducer(initialState, handlers) {
99
+ return {
100
+ initialState,
101
+ reduce: (state, action) => {
102
+ const handler = handlers[action.type];
103
+ if (handler) {
104
+ return handler(state, action);
105
+ }
106
+ return state;
107
+ }
108
+ };
109
+ }
110
+
111
+ // src/typed/model.ts
112
+ var STRING_MARKER = /* @__PURE__ */ Symbol("string");
113
+ var NUMBER_MARKER = /* @__PURE__ */ Symbol("number");
114
+ var BOOLEAN_MARKER = /* @__PURE__ */ Symbol("boolean");
115
+ var DATE_MARKER = /* @__PURE__ */ Symbol("date");
116
+ var BIGINT_MARKER = /* @__PURE__ */ Symbol("bigint");
117
+ var SYMBOL_MARKER = /* @__PURE__ */ Symbol("symbol");
118
+ var ANY_MARKER = /* @__PURE__ */ Symbol("any");
119
+ var UNKNOWN_MARKER = /* @__PURE__ */ Symbol("unknown");
120
+ var NULL_MARKER = /* @__PURE__ */ Symbol("null");
121
+ var UNDEFINED_MARKER = /* @__PURE__ */ Symbol("undefined");
122
+ var t = {
123
+ string: { [STRING_MARKER]: true },
124
+ number: { [NUMBER_MARKER]: true },
125
+ boolean: { [BOOLEAN_MARKER]: true },
126
+ date: { [DATE_MARKER]: true },
127
+ bigint: { [BIGINT_MARKER]: true },
128
+ symbol: { [SYMBOL_MARKER]: true },
129
+ any: { [ANY_MARKER]: true },
130
+ unknown: { [UNKNOWN_MARKER]: true },
131
+ null: { [NULL_MARKER]: true },
132
+ undefined: { [UNDEFINED_MARKER]: true },
133
+ /** Array of a type */
134
+ array: (item) => ({ __array: item }),
135
+ /** Optional field */
136
+ optional: (type) => ({ __optional: type }),
137
+ /** Nullable field */
138
+ nullable: (type) => ({ __nullable: type }),
139
+ /** Literal value */
140
+ literal: (value) => ({ __literal: value }),
141
+ /** Union of literals (enum-like) */
142
+ enum: (...values) => ({ __enum: values }),
143
+ /** Union of types */
144
+ union: (...types) => ({ __union: types }),
145
+ /** Record/Dictionary */
146
+ record: (valueType) => ({ __record: valueType }),
147
+ /** Tuple */
148
+ tuple: (...types) => ({ __tuple: types }),
149
+ /** Reference to another model */
150
+ ref: () => ({ __ref: null })
151
+ };
152
+ function defineModel(definition) {
153
+ const model2 = {
154
+ __schema: null,
155
+ __definition: definition,
156
+ create(data) {
157
+ return data;
158
+ },
159
+ partial(data) {
160
+ return data;
161
+ },
162
+ is(value) {
163
+ if (typeof value !== "object" || value === null) return false;
164
+ for (const key of Object.keys(definition)) {
165
+ if (!(key in value)) {
166
+ const fieldDef = definition[key];
167
+ if (fieldDef && typeof fieldDef === "object" && "__optional" in fieldDef) {
168
+ continue;
169
+ }
170
+ return false;
171
+ }
172
+ }
173
+ return true;
174
+ },
175
+ extend(extension) {
176
+ return defineModel({ ...definition, ...extension });
177
+ },
178
+ pick(...keys) {
179
+ const picked = {};
180
+ for (const key of keys) {
181
+ picked[key] = definition[key];
182
+ }
183
+ return defineModel(picked);
184
+ },
185
+ omit(...keys) {
186
+ const omitted = { ...definition };
187
+ for (const key of keys) {
188
+ delete omitted[key];
189
+ }
190
+ return defineModel(omitted);
191
+ },
192
+ asPartial() {
193
+ const partial = {};
194
+ for (const key of Object.keys(definition)) {
195
+ partial[key] = { __optional: definition[key] };
196
+ }
197
+ return defineModel(partial);
198
+ },
199
+ asRequired() {
200
+ const required = {};
201
+ for (const key of Object.keys(definition)) {
202
+ const field = definition[key];
203
+ if (field && typeof field === "object" && "__optional" in field) {
204
+ required[key] = field.__optional;
205
+ } else {
206
+ required[key] = field;
207
+ }
208
+ }
209
+ return defineModel(required);
210
+ }
211
+ };
212
+ return model2;
213
+ }
214
+ function model(definition) {
215
+ return defineModel(definition);
216
+ }
217
+ function mergeModels(a, b) {
218
+ return defineModel({
219
+ ...a.__definition,
220
+ ...b.__definition
221
+ });
222
+ }
223
+ function pickModel(model2, ...keys) {
224
+ return model2.pick(...keys);
225
+ }
226
+ function omitModel(model2, ...keys) {
227
+ return model2.omit(...keys);
228
+ }
229
+
230
+ // src/typed/v.ts
231
+ function createValidator(parser, checker) {
232
+ const validator = {
233
+ parse: parser,
234
+ safeParse(value) {
235
+ try {
236
+ return { ok: true, value: parser(value) };
237
+ } catch (e) {
238
+ return { ok: false, error: e instanceof Error ? e : new Error(String(e)) };
239
+ }
240
+ },
241
+ is(value) {
242
+ if (checker) return checker(value);
243
+ try {
244
+ parser(value);
245
+ return true;
246
+ } catch {
247
+ return false;
248
+ }
249
+ },
250
+ T: void 0,
251
+ optional() {
252
+ return createValidator(
253
+ (val) => val === void 0 ? void 0 : parser(val),
254
+ (val) => val === void 0 || (checker ? checker(val) : true)
255
+ );
256
+ },
257
+ nullable() {
258
+ return createValidator(
259
+ (val) => val === null ? null : parser(val),
260
+ (val) => val === null || (checker ? checker(val) : true)
261
+ );
262
+ },
263
+ default(defaultValue) {
264
+ return createValidator(
265
+ (val) => val === void 0 || val === null ? defaultValue : parser(val)
266
+ );
267
+ },
268
+ transform(fn) {
269
+ return createValidator((val) => fn(parser(val)));
270
+ },
271
+ refine(fn, message = "Validation failed") {
272
+ return createValidator((val) => {
273
+ const parsed = parser(val);
274
+ if (!fn(parsed)) throw new Error(message);
275
+ return parsed;
276
+ });
277
+ }
278
+ };
279
+ return validator;
280
+ }
281
+ function stringValidator() {
282
+ return createValidator(
283
+ (val) => {
284
+ if (typeof val !== "string") throw new Error(`Expected string, got ${typeof val}`);
285
+ return val;
286
+ },
287
+ (val) => typeof val === "string"
288
+ );
289
+ }
290
+ function numberValidator() {
291
+ return createValidator(
292
+ (val) => {
293
+ if (typeof val !== "number" || Number.isNaN(val)) {
294
+ throw new Error(`Expected number, got ${typeof val}`);
295
+ }
296
+ return val;
297
+ },
298
+ (val) => typeof val === "number" && !Number.isNaN(val)
299
+ );
300
+ }
301
+ function booleanValidator() {
302
+ return createValidator(
303
+ (val) => {
304
+ if (typeof val !== "boolean") throw new Error(`Expected boolean, got ${typeof val}`);
305
+ return val;
306
+ },
307
+ (val) => typeof val === "boolean"
308
+ );
309
+ }
310
+ function dateValidator() {
311
+ return createValidator(
312
+ (val) => {
313
+ if (val instanceof Date) return val;
314
+ if (typeof val === "string" || typeof val === "number") {
315
+ const date = new Date(val);
316
+ if (Number.isNaN(date.getTime())) throw new Error("Invalid date");
317
+ return date;
318
+ }
319
+ throw new Error(`Expected date, got ${typeof val}`);
320
+ },
321
+ (val) => val instanceof Date && !Number.isNaN(val.getTime())
322
+ );
323
+ }
324
+ function literalValidator(value) {
325
+ return createValidator(
326
+ (val) => {
327
+ if (val !== value) throw new Error(`Expected ${String(value)}, got ${String(val)}`);
328
+ return value;
329
+ },
330
+ (val) => val === value
331
+ );
332
+ }
333
+ function enumValidator(...values) {
334
+ return createValidator(
335
+ (val) => {
336
+ if (!values.includes(val)) {
337
+ throw new Error(`Expected one of [${values.join(", ")}], got ${String(val)}`);
338
+ }
339
+ return val;
340
+ },
341
+ (val) => values.includes(val)
342
+ );
343
+ }
344
+ function emailValidator() {
345
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
346
+ return stringValidator().refine((val) => emailRegex.test(val), "Invalid email");
347
+ }
348
+ function urlValidator() {
349
+ return stringValidator().refine((val) => {
350
+ try {
351
+ new URL(val);
352
+ return true;
353
+ } catch {
354
+ return false;
355
+ }
356
+ }, "Invalid URL");
357
+ }
358
+ function uuidValidator() {
359
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
360
+ return stringValidator().refine((val) => uuidRegex.test(val), "Invalid UUID");
361
+ }
362
+ function objectValidator(schema) {
363
+ const base = createValidator(
364
+ (val) => {
365
+ if (typeof val !== "object" || val === null) {
366
+ throw new Error(`Expected object, got ${typeof val}`);
367
+ }
368
+ const result = {};
369
+ const schemaRecord = schema;
370
+ for (const key of Object.keys(schemaRecord)) {
371
+ const fieldValidator = schemaRecord[key];
372
+ if (fieldValidator) {
373
+ result[key] = fieldValidator.parse(val[key]);
374
+ }
375
+ }
376
+ return result;
377
+ },
378
+ (val) => {
379
+ if (typeof val !== "object" || val === null) return false;
380
+ const schemaRec = schema;
381
+ for (const key of Object.keys(schemaRec)) {
382
+ const fieldVal = schemaRec[key];
383
+ if (fieldVal && !fieldVal.is(val[key])) return false;
384
+ }
385
+ return true;
386
+ }
387
+ );
388
+ const validator = base;
389
+ validator.schema = schema;
390
+ validator.pick = (...keys) => {
391
+ const picked = {};
392
+ for (const key of keys) picked[key] = schema[key];
393
+ return objectValidator(picked);
394
+ };
395
+ validator.omit = (...keys) => {
396
+ const omitted = { ...schema };
397
+ for (const key of keys) delete omitted[key];
398
+ return objectValidator(omitted);
399
+ };
400
+ validator.extend = (ext) => {
401
+ return objectValidator({ ...schema, ...ext });
402
+ };
403
+ validator.partial = () => {
404
+ const partial = {};
405
+ const schemaRec = schema;
406
+ for (const key of Object.keys(schemaRec)) {
407
+ const fieldVal = schemaRec[key];
408
+ if (fieldVal) partial[key] = fieldVal.optional();
409
+ }
410
+ return objectValidator(partial);
411
+ };
412
+ validator.merge = (other) => {
413
+ return objectValidator({ ...schema, ...other.schema });
414
+ };
415
+ return validator;
416
+ }
417
+ function arrayValidator(itemValidator) {
418
+ return createValidator(
419
+ (val) => {
420
+ if (!Array.isArray(val)) throw new Error(`Expected array, got ${typeof val}`);
421
+ return val.map((item, i) => {
422
+ try {
423
+ return itemValidator.parse(item);
424
+ } catch (e) {
425
+ throw new Error(`[${i}]: ${e instanceof Error ? e.message : String(e)}`);
426
+ }
427
+ });
428
+ },
429
+ (val) => Array.isArray(val) && val.every((item) => itemValidator.is(item))
430
+ );
431
+ }
432
+ function tupleValidator(...validators) {
433
+ return createValidator(
434
+ (val) => {
435
+ if (!Array.isArray(val)) throw new Error(`Expected tuple, got ${typeof val}`);
436
+ if (val.length !== validators.length) {
437
+ throw new Error(`Expected ${validators.length} elements, got ${val.length}`);
438
+ }
439
+ return validators.map((v2, i) => v2.parse(val[i]));
440
+ },
441
+ (val) => Array.isArray(val) && val.length === validators.length && validators.every((v2, i) => v2.is(val[i]))
442
+ );
443
+ }
444
+ function recordValidator(valueValidator) {
445
+ return createValidator(
446
+ (val) => {
447
+ if (typeof val !== "object" || val === null || Array.isArray(val)) {
448
+ throw new Error(`Expected record, got ${typeof val}`);
449
+ }
450
+ const result = {};
451
+ for (const [key, value] of Object.entries(val)) {
452
+ result[key] = valueValidator.parse(value);
453
+ }
454
+ return result;
455
+ },
456
+ (val) => {
457
+ if (typeof val !== "object" || val === null || Array.isArray(val)) return false;
458
+ return Object.values(val).every((v2) => valueValidator.is(v2));
459
+ }
460
+ );
461
+ }
462
+ function unionValidator(...validators) {
463
+ return createValidator(
464
+ (val) => {
465
+ for (const v2 of validators) {
466
+ const result = v2.safeParse(val);
467
+ if (result.ok) return result.value;
468
+ }
469
+ throw new Error("Value does not match any union member");
470
+ },
471
+ (val) => validators.some((v2) => v2.is(val))
472
+ );
473
+ }
474
+ function intersectionValidator(a, b) {
475
+ return createValidator(
476
+ (val) => {
477
+ const parsedA = a.parse(val);
478
+ const parsedB = b.parse(val);
479
+ return { ...parsedA, ...parsedB };
480
+ },
481
+ (val) => a.is(val) && b.is(val)
482
+ );
483
+ }
484
+ var v = {
485
+ // Primitives
486
+ string: stringValidator,
487
+ number: numberValidator,
488
+ boolean: booleanValidator,
489
+ date: dateValidator,
490
+ // String refinements
491
+ email: emailValidator,
492
+ url: urlValidator,
493
+ uuid: uuidValidator,
494
+ // Literals & Enums
495
+ literal: literalValidator,
496
+ enum: enumValidator,
497
+ // Compound types
498
+ object: objectValidator,
499
+ array: arrayValidator,
500
+ tuple: tupleValidator,
501
+ record: recordValidator,
502
+ union: unionValidator,
503
+ intersection: intersectionValidator,
504
+ // Special
505
+ any: () => createValidator((val) => val),
506
+ unknown: () => createValidator((val) => val),
507
+ null: () => createValidator((val) => {
508
+ if (val !== null) throw new Error("Expected null");
509
+ return null;
510
+ }),
511
+ undefined: () => createValidator((val) => {
512
+ if (val !== void 0) throw new Error("Expected undefined");
513
+ return void 0;
514
+ })
515
+ };
516
+
517
+ // src/typed/collection.ts
518
+ var CollectionImpl = class {
519
+ _items = [];
520
+ _listeners = /* @__PURE__ */ new Set();
521
+ get items() {
522
+ return this._items;
523
+ }
524
+ get length() {
525
+ return this._items.length;
526
+ }
527
+ notify() {
528
+ for (const listener of this._listeners) {
529
+ listener(this._items);
530
+ }
531
+ }
532
+ add(item) {
533
+ this._items.push(item);
534
+ this.notify();
535
+ return item;
536
+ }
537
+ addMany(items) {
538
+ this._items.push(...items);
539
+ this.notify();
540
+ return items;
541
+ }
542
+ update(predicate, updates) {
543
+ const index = this._items.findIndex(predicate);
544
+ if (index === -1) return void 0;
545
+ this._items[index] = { ...this._items[index], ...updates };
546
+ this.notify();
547
+ return this._items[index];
548
+ }
549
+ updateWhere(key, value, updates) {
550
+ return this.update((item) => item[key] === value, updates);
551
+ }
552
+ remove(predicate) {
553
+ const removed = [];
554
+ this._items = this._items.filter((item) => {
555
+ if (predicate(item)) {
556
+ removed.push(item);
557
+ return false;
558
+ }
559
+ return true;
560
+ });
561
+ if (removed.length > 0) this.notify();
562
+ return removed;
563
+ }
564
+ removeWhere(key, value) {
565
+ const removed = this.remove((item) => item[key] === value);
566
+ return removed[0];
567
+ }
568
+ clear() {
569
+ this._items = [];
570
+ this.notify();
571
+ }
572
+ findOne(predicate) {
573
+ return this._items.find(predicate);
574
+ }
575
+ find(key, value) {
576
+ return this._items.find((item) => item[key] === value);
577
+ }
578
+ findMany(predicate) {
579
+ return this._items.filter(predicate);
580
+ }
581
+ where(predicate) {
582
+ return this.findMany(predicate);
583
+ }
584
+ whereEquals(key, value) {
585
+ return this._items.filter((item) => item[key] === value);
586
+ }
587
+ some(predicate) {
588
+ return this._items.some(predicate);
589
+ }
590
+ every(predicate) {
591
+ return this._items.every(predicate);
592
+ }
593
+ has(key, value) {
594
+ return this._items.some((item) => item[key] === value);
595
+ }
596
+ first() {
597
+ return this._items[0];
598
+ }
599
+ last() {
600
+ return this._items[this._items.length - 1];
601
+ }
602
+ at(index) {
603
+ return this._items.at(index);
604
+ }
605
+ map(fn) {
606
+ return this._items.map(fn);
607
+ }
608
+ pluck(key) {
609
+ return this._items.map((item) => item[key]);
610
+ }
611
+ pick(...keys) {
612
+ return this._items.map((item) => {
613
+ const picked = {};
614
+ for (const key of keys) {
615
+ picked[key] = item[key];
616
+ }
617
+ return picked;
618
+ });
619
+ }
620
+ omit(...keys) {
621
+ return this._items.map((item) => {
622
+ const omitted = { ...item };
623
+ for (const key of keys) {
624
+ delete omitted[key];
625
+ }
626
+ return omitted;
627
+ });
628
+ }
629
+ sortBy(key, order = "asc") {
630
+ return [...this._items].sort((a, b) => {
631
+ const aVal = a[key];
632
+ const bVal = b[key];
633
+ if (aVal < bVal) return order === "asc" ? -1 : 1;
634
+ if (aVal > bVal) return order === "asc" ? 1 : -1;
635
+ return 0;
636
+ });
637
+ }
638
+ groupBy(key) {
639
+ const groups = /* @__PURE__ */ new Map();
640
+ for (const item of this._items) {
641
+ const groupKey = item[key];
642
+ const group = groups.get(groupKey) || [];
643
+ group.push(item);
644
+ groups.set(groupKey, group);
645
+ }
646
+ return groups;
647
+ }
648
+ unique(key) {
649
+ return [...new Set(this._items.map((item) => item[key]))];
650
+ }
651
+ count(predicate) {
652
+ if (!predicate) return this._items.length;
653
+ return this._items.filter(predicate).length;
654
+ }
655
+ subscribe(listener) {
656
+ this._listeners.add(listener);
657
+ return () => this._listeners.delete(listener);
658
+ }
659
+ toArray() {
660
+ return [...this._items];
661
+ }
662
+ toJSON() {
663
+ return JSON.stringify(this._items);
664
+ }
665
+ fromJSON(json) {
666
+ this._items = JSON.parse(json);
667
+ this.notify();
668
+ }
669
+ };
670
+ var CollectionWithIdImpl = class extends CollectionImpl {
671
+ constructor(idKey) {
672
+ super();
673
+ this.idKey = idKey;
674
+ }
675
+ byId(id) {
676
+ return this.find(this.idKey, id);
677
+ }
678
+ updateById(id, updates) {
679
+ return this.updateWhere(this.idKey, id, updates);
680
+ }
681
+ removeById(id) {
682
+ return this.removeWhere(this.idKey, id);
683
+ }
684
+ hasId(id) {
685
+ return this.has(this.idKey, id);
686
+ }
687
+ };
688
+ var localStorageAdapter = {
689
+ async get(key) {
690
+ if (typeof localStorage === "undefined") return null;
691
+ return localStorage.getItem(key);
692
+ },
693
+ async set(key, value) {
694
+ if (typeof localStorage === "undefined") return;
695
+ localStorage.setItem(key, value);
696
+ },
697
+ async remove(key) {
698
+ if (typeof localStorage === "undefined") return;
699
+ localStorage.removeItem(key);
700
+ }
701
+ };
702
+ var PersistentCollectionImpl = class extends CollectionImpl {
703
+ constructor(storageKey, storage = localStorageAdapter) {
704
+ super();
705
+ this.storageKey = storageKey;
706
+ this.storage = storage;
707
+ }
708
+ autoSaveEnabled = false;
709
+ unsubscribe;
710
+ async save() {
711
+ await this.storage.set(this.storageKey, this.toJSON());
712
+ }
713
+ async load() {
714
+ const data = await this.storage.get(this.storageKey);
715
+ if (data) {
716
+ this.fromJSON(data);
717
+ }
718
+ }
719
+ enableAutoSave() {
720
+ if (this.autoSaveEnabled) return;
721
+ this.autoSaveEnabled = true;
722
+ this.unsubscribe = this.subscribe(() => {
723
+ void this.save();
724
+ });
725
+ }
726
+ disableAutoSave() {
727
+ this.autoSaveEnabled = false;
728
+ this.unsubscribe?.();
729
+ }
730
+ };
731
+ function collection(_validator) {
732
+ return new CollectionImpl();
733
+ }
734
+ function collectionWithId(_validator, idKey) {
735
+ return new CollectionWithIdImpl(idKey);
736
+ }
737
+ function persistentCollection(_validator, storageKey, storage) {
738
+ return new PersistentCollectionImpl(storageKey, storage);
739
+ }
740
+ function createCollection(_validator, options) {
741
+ if (options?.persist) {
742
+ const col = new PersistentCollectionImpl(options.persist, options.storage);
743
+ if (options.autoSave) col.enableAutoSave();
744
+ return col;
745
+ }
746
+ if (options?.idKey) {
747
+ return new CollectionWithIdImpl(options.idKey);
748
+ }
749
+ return new CollectionImpl();
750
+ }
751
+
752
+ // src/typed/states.ts
753
+ function asyncData() {
754
+ return {
755
+ idle: () => ({ status: "idle" }),
756
+ loading: () => ({ status: "loading" }),
757
+ success: (data) => ({ status: "success", data }),
758
+ error: (error) => ({ status: "error", error }),
759
+ isIdle: (state) => state.status === "idle",
760
+ isLoading: (state) => state.status === "loading",
761
+ isSuccess: (state) => state.status === "success",
762
+ isError: (state) => state.status === "error",
763
+ map: (state, fn) => {
764
+ if (state.status === "success") {
765
+ return { status: "success", data: fn(state.data) };
766
+ }
767
+ return state;
768
+ },
769
+ getOrElse: (state, defaultValue) => {
770
+ if (state.status === "success") {
771
+ return state.data;
772
+ }
773
+ return defaultValue;
774
+ }
775
+ };
776
+ }
777
+ function formState(initialValues) {
778
+ return {
779
+ pristine: () => ({ status: "pristine", values: initialValues }),
780
+ dirty: (values, touched) => ({ status: "dirty", values, touched }),
781
+ validating: (values) => ({ status: "validating", values }),
782
+ invalid: (values, errors) => ({ status: "invalid", values, errors }),
783
+ submitting: (values) => ({ status: "submitting", values }),
784
+ submitted: (values) => ({ status: "submitted", values }),
785
+ error: (values, error) => ({ status: "error", values, error }),
786
+ canSubmit: (state) => state.status === "dirty" || state.status === "pristine",
787
+ isSubmitting: (state) => state.status === "submitting",
788
+ hasErrors: (state) => state.status === "invalid"
789
+ };
790
+ }
791
+ function modalState() {
792
+ return {
793
+ closed: () => ({ isOpen: false }),
794
+ open: (data) => ({ isOpen: true, data }),
795
+ isOpen: (state) => state.isOpen
796
+ };
797
+ }
798
+ function undoable(initial) {
799
+ return {
800
+ init: () => ({
801
+ current: initial,
802
+ past: [],
803
+ future: [],
804
+ canUndo: false,
805
+ canRedo: false
806
+ }),
807
+ push: (state, value) => ({
808
+ current: value,
809
+ past: [...state.past, state.current],
810
+ future: [],
811
+ canUndo: true,
812
+ canRedo: false
813
+ }),
814
+ undo: (state) => {
815
+ if (state.past.length === 0) return state;
816
+ const previous = state.past[state.past.length - 1];
817
+ return {
818
+ current: previous,
819
+ past: state.past.slice(0, -1),
820
+ future: [state.current, ...state.future],
821
+ canUndo: state.past.length > 1,
822
+ canRedo: true
823
+ };
824
+ },
825
+ redo: (state) => {
826
+ if (state.future.length === 0) return state;
827
+ const next = state.future[0];
828
+ return {
829
+ current: next,
830
+ past: [...state.past, state.current],
831
+ future: state.future.slice(1),
832
+ canUndo: true,
833
+ canRedo: state.future.length > 1
834
+ };
835
+ }
836
+ };
837
+ }
838
+
839
+ // src/typed/match.ts
840
+ function match(value, discriminant) {
841
+ return new MatchBuilderImpl(value, discriminant, {});
842
+ }
843
+ var MatchBuilderImpl = class _MatchBuilderImpl {
844
+ value;
845
+ discriminant;
846
+ handlers;
847
+ result = void 0;
848
+ matched = false;
849
+ constructor(value, discriminant, handlers) {
850
+ this.value = value;
851
+ this.discriminant = discriminant;
852
+ this.handlers = handlers;
853
+ }
854
+ with(matchValue2, handler) {
855
+ const newHandlers = { ...this.handlers, [matchValue2]: handler };
856
+ const builder = new _MatchBuilderImpl(this.value, this.discriminant, newHandlers);
857
+ const discriminantValue = this.value[this.discriminant];
858
+ if (!this.matched && discriminantValue === matchValue2) {
859
+ builder.result = handler(this.value);
860
+ builder.matched = true;
861
+ } else {
862
+ builder.result = this.result;
863
+ builder.matched = this.matched;
864
+ }
865
+ return builder;
866
+ }
867
+ exhaustive() {
868
+ if (this.matched) {
869
+ return this.result;
870
+ }
871
+ throw new Error(`No handler matched for discriminant value: ${String(this.value[this.discriminant])}`);
872
+ }
873
+ otherwise(handler) {
874
+ if (this.matched) {
875
+ return this.result;
876
+ }
877
+ return handler(this.value);
878
+ }
879
+ run() {
880
+ return this.exhaustive();
881
+ }
882
+ };
883
+ function matchValue(value, cases) {
884
+ const handler = cases[value];
885
+ if (!handler) {
886
+ throw new Error(`No handler for value: ${String(value)}`);
887
+ }
888
+ return handler();
889
+ }
890
+ function matchUnion(value, discriminant, handlers) {
891
+ const discriminantValue = value[discriminant];
892
+ const handler = handlers[discriminantValue];
893
+ return handler(value);
894
+ }
895
+ function createMatcher() {
896
+ return (discriminant) => {
897
+ return (value, handlers) => {
898
+ return matchUnion(value, discriminant, handlers);
899
+ };
900
+ };
901
+ }
902
+
903
+ // src/typed/debug.ts
904
+ function showType(_value) {
905
+ return _value;
906
+ }
907
+ function assertType(_value) {
908
+ }
909
+ function impossible(value) {
910
+ throw new Error(`Unexpected value: ${JSON.stringify(value)}`);
911
+ }
912
+ function identity(value) {
913
+ return value;
914
+ }
915
+ function narrow2(guard) {
916
+ return guard;
917
+ }
918
+
919
+ // src/typed/merge.ts
920
+ function merge(a, b) {
921
+ return { ...a, ...b };
922
+ }
923
+ function mergeAll(...objects) {
924
+ return Object.assign({}, ...objects);
925
+ }
926
+ function deepMerge(a, b) {
927
+ const result = { ...a };
928
+ for (const key of Object.keys(b)) {
929
+ const bValue = b[key];
930
+ const aValue = a[key];
931
+ if (isPlainObject(bValue) && isPlainObject(aValue)) {
932
+ result[key] = deepMerge(
933
+ aValue,
934
+ bValue
935
+ );
936
+ } else {
937
+ result[key] = bValue;
938
+ }
939
+ }
940
+ return result;
941
+ }
942
+ function isPlainObject(value) {
943
+ return typeof value === "object" && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
944
+ }
945
+ function mergeWith(a, b, resolvers) {
946
+ const result = { ...a, ...b };
947
+ for (const key of Object.keys(resolvers)) {
948
+ const resolver = resolvers[key];
949
+ if (resolver && key in a && key in b) {
950
+ result[key] = resolver(
951
+ a[key],
952
+ b[key]
953
+ );
954
+ }
955
+ }
956
+ return result;
957
+ }
958
+ function pick(obj, keys) {
959
+ const result = {};
960
+ for (const key of keys) {
961
+ if (key in obj) {
962
+ result[key] = obj[key];
963
+ }
964
+ }
965
+ return result;
966
+ }
967
+ function omit(obj, keys) {
968
+ const result = { ...obj };
969
+ for (const key of keys) {
970
+ delete result[key];
971
+ }
972
+ return result;
973
+ }
974
+ function renameKeys(obj, mapping) {
975
+ const result = {};
976
+ for (const key of Object.keys(obj)) {
977
+ const newKey = mapping[key];
978
+ if (newKey !== void 0) {
979
+ result[newKey] = obj[key];
980
+ } else {
981
+ result[key] = obj[key];
982
+ }
983
+ }
984
+ return result;
985
+ }
986
+ function fromEntries(entries) {
987
+ return Object.fromEntries(entries);
988
+ }
989
+ function mapValues(obj, fn) {
990
+ const result = {};
991
+ for (const key of Object.keys(obj)) {
992
+ result[key] = fn(obj[key], key);
993
+ }
994
+ return result;
995
+ }
996
+ function mapKeys(obj, fn) {
997
+ const result = {};
998
+ for (const key of Object.keys(obj)) {
999
+ const newKey = fn(key);
1000
+ result[newKey] = obj[key];
1001
+ }
1002
+ return result;
1003
+ }
1004
+
1005
+ export { assertType, asyncData, brand, collection, collectionWithId, createActions, createBuilder, createCollection, createMap, createMatcher, createReducer, createSet, createTypedEmitter, deepMerge, defineConst, defineEnum, defineModel, defineStateMachine, defineTuple, formState, fromEntries, identity, impossible, mapKeys, mapValues, match, matchUnion, matchValue, merge, mergeAll, mergeModels, mergeWith, modalState, model, narrow, narrow2, omit, omitModel, persistentCollection, pick, pickModel, renameKeys, showType, t, undoable, v };
1006
+ //# sourceMappingURL=chunk-JAOGY4JO.mjs.map
1007
+ //# sourceMappingURL=chunk-JAOGY4JO.mjs.map