speexjs 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +555 -0
  2. package/dist/cli/index.d.ts +1 -0
  3. package/dist/cli/index.js +1017 -0
  4. package/dist/cli/index.js.map +1 -0
  5. package/dist/client/index.d.ts +73 -0
  6. package/dist/client/index.js +927 -0
  7. package/dist/client/index.js.map +1 -0
  8. package/dist/client/signals/index.d.ts +62 -0
  9. package/dist/client/signals/index.js +248 -0
  10. package/dist/client/signals/index.js.map +1 -0
  11. package/dist/client/vdom/index.d.ts +50 -0
  12. package/dist/client/vdom/index.js +540 -0
  13. package/dist/client/vdom/index.js.map +1 -0
  14. package/dist/client/vdom/jsx-runtime.d.ts +9 -0
  15. package/dist/client/vdom/jsx-runtime.js +203 -0
  16. package/dist/client/vdom/jsx-runtime.js.map +1 -0
  17. package/dist/index-CMkhSDh7.d.ts +97 -0
  18. package/dist/index.d.ts +18 -0
  19. package/dist/index.js +6402 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/jsx-DGrnv8QB.d.ts +8 -0
  22. package/dist/response-Ca8KWK5_.d.ts +173 -0
  23. package/dist/rpc/index.d.ts +70 -0
  24. package/dist/rpc/index.js +136 -0
  25. package/dist/rpc/index.js.map +1 -0
  26. package/dist/schema/index.d.ts +231 -0
  27. package/dist/schema/index.js +1160 -0
  28. package/dist/schema/index.js.map +1 -0
  29. package/dist/server/auth/index.d.ts +61 -0
  30. package/dist/server/auth/index.js +462 -0
  31. package/dist/server/auth/index.js.map +1 -0
  32. package/dist/server/cache/index.d.ts +45 -0
  33. package/dist/server/cache/index.js +238 -0
  34. package/dist/server/cache/index.js.map +1 -0
  35. package/dist/server/container/index.d.ts +20 -0
  36. package/dist/server/container/index.js +62 -0
  37. package/dist/server/container/index.js.map +1 -0
  38. package/dist/server/controller/index.d.ts +37 -0
  39. package/dist/server/controller/index.js +139 -0
  40. package/dist/server/controller/index.js.map +1 -0
  41. package/dist/server/database/index.d.ts +461 -0
  42. package/dist/server/database/index.js +1977 -0
  43. package/dist/server/database/index.js.map +1 -0
  44. package/dist/server/events/index.d.ts +29 -0
  45. package/dist/server/events/index.js +159 -0
  46. package/dist/server/events/index.js.map +1 -0
  47. package/dist/server/gate/index.d.ts +36 -0
  48. package/dist/server/gate/index.js +169 -0
  49. package/dist/server/gate/index.js.map +1 -0
  50. package/dist/server/http/index.d.ts +45 -0
  51. package/dist/server/http/index.js +871 -0
  52. package/dist/server/http/index.js.map +1 -0
  53. package/dist/server/index.d.ts +79 -0
  54. package/dist/server/index.js +4185 -0
  55. package/dist/server/index.js.map +1 -0
  56. package/dist/server/middleware/index.d.ts +5 -0
  57. package/dist/server/middleware/index.js +416 -0
  58. package/dist/server/middleware/index.js.map +1 -0
  59. package/dist/server/router/index.d.ts +5 -0
  60. package/dist/server/router/index.js +231 -0
  61. package/dist/server/router/index.js.map +1 -0
  62. package/dist/server/storage/index.d.ts +66 -0
  63. package/dist/server/storage/index.js +244 -0
  64. package/dist/server/storage/index.js.map +1 -0
  65. package/dist/session-guard-CZeN87L9.d.ts +48 -0
  66. package/dist/types-CXH8hPei.d.ts +38 -0
  67. package/package.json +138 -0
@@ -0,0 +1,1160 @@
1
+ // src/schema/messages.ts
2
+ var currentLocale = "id";
3
+ var ID = {
4
+ required: "Nilai wajib diisi",
5
+ type_string: "Nilai harus berupa teks",
6
+ type_number: "Nilai harus berupa angka",
7
+ type_boolean: "Nilai harus berupa boolean",
8
+ type_bigint: "Nilai harus berupa BigInt",
9
+ type_symbol: "Nilai harus berupa Symbol",
10
+ type_undefined: "Nilai harus berupa undefined",
11
+ type_null: "Nilai harus berupa null",
12
+ type_nan: "Nilai harus berupa NaN",
13
+ type_object: "Nilai harus berupa objek",
14
+ type_array: "Nilai harus berupa array",
15
+ type_date: "Nilai harus berupa tanggal yang valid",
16
+ type_function: "Nilai harus berupa fungsi",
17
+ type_string_or_number: "Nilai harus berupa teks atau angka",
18
+ string_min: "Panjang minimal {min} karakter",
19
+ string_max: "Panjang maksimal {max} karakter",
20
+ string_length: "Panjang harus tepat {length} karakter",
21
+ string_email: "Format email tidak valid",
22
+ string_url: "Format URL tidak valid",
23
+ string_regex: "Format tidak sesuai dengan pola yang diharapkan",
24
+ string_includes: 'Teks harus mengandung "{substring}"',
25
+ string_starts_with: 'Teks harus diawali dengan "{prefix}"',
26
+ string_ends_with: 'Teks harus diakhiri dengan "{suffix}"',
27
+ number_min: "Nilai minimal {min}",
28
+ number_max: "Nilai maksimal {max}",
29
+ number_int: "Nilai harus bilangan bulat",
30
+ number_positive: "Nilai harus positif",
31
+ number_negative: "Nilai harus negatif",
32
+ number_finite: "Nilai harus terbatas (finite)",
33
+ number_safe: "Nilai harus dalam batas safe integer",
34
+ array_min: "Panjang array minimal {min}",
35
+ array_max: "Panjang array maksimal {max}",
36
+ array_length: "Panjang array harus tepat {length}",
37
+ array_nonempty: "Array tidak boleh kosong",
38
+ array_unique: "Semua elemen array harus unik",
39
+ object_strict: 'Key "{key}" tidak dikenal',
40
+ enum_invalid: "Nilai harus salah satu dari: {values}",
41
+ tuple_length: "Tuple harus memiliki tepat {length} elemen",
42
+ union_fail: "Nilai tidak cocok dengan skema apapun",
43
+ intersection_fail: "Nilai tidak cocok dengan interseksi skema",
44
+ literal_fail: "Nilai harus tepat {expected}",
45
+ refine_fail: "{message}",
46
+ date_invalid: "Tanggal tidak valid",
47
+ date_not_date: "Nilai harus berupa tanggal yang valid",
48
+ indonesia_nik: "NIK harus 16 digit dan memenuhi format yang valid",
49
+ indonesia_npwp: "NPWP tidak valid",
50
+ indonesia_phone: "Nomor telepon Indonesia tidak valid",
51
+ indonesia_alamat: "Alamat tidak valid (minimal 10 karakter, harus mengandung unsur jalan/RT/RW)",
52
+ indonesia_kodepos: "Kode pos harus 5 digit angka",
53
+ indonesia_rekening: "Nomor rekening harus 10-16 digit angka",
54
+ coerce_number_fail: "Nilai tidak dapat dikonversi menjadi angka",
55
+ coerce_date_fail: "Nilai tidak dapat dikonversi menjadi tanggal",
56
+ map_not_map: "Nilai harus berupa Map",
57
+ set_not_set: "Nilai harus berupa Set"
58
+ };
59
+ var EN = {
60
+ required: "Value is required",
61
+ type_string: "Expected a string",
62
+ type_number: "Expected a number",
63
+ type_boolean: "Expected a boolean",
64
+ type_bigint: "Expected a BigInt",
65
+ type_symbol: "Expected a Symbol",
66
+ type_undefined: "Expected undefined",
67
+ type_null: "Expected null",
68
+ type_nan: "Expected NaN",
69
+ type_object: "Expected an object",
70
+ type_array: "Expected an array",
71
+ type_date: "Expected a valid date",
72
+ type_function: "Expected a function",
73
+ type_string_or_number: "Expected a string or number",
74
+ string_min: "Minimum {min} characters",
75
+ string_max: "Maximum {max} characters",
76
+ string_length: "Exactly {length} characters required",
77
+ string_email: "Invalid email format",
78
+ string_url: "Invalid URL format",
79
+ string_regex: "Format does not match expected pattern",
80
+ string_includes: 'Must contain "{substring}"',
81
+ string_starts_with: 'Must start with "{prefix}"',
82
+ string_ends_with: 'Must end with "{suffix}"',
83
+ number_min: "Minimum value is {min}",
84
+ number_max: "Maximum value is {max}",
85
+ number_int: "Expected an integer",
86
+ number_positive: "Expected a positive number",
87
+ number_negative: "Expected a negative number",
88
+ number_finite: "Expected a finite number",
89
+ number_safe: "Expected a safe integer",
90
+ array_min: "Minimum {min} items",
91
+ array_max: "Maximum {max} items",
92
+ array_length: "Exactly {length} items required",
93
+ array_nonempty: "Array must not be empty",
94
+ array_unique: "All items must be unique",
95
+ object_strict: 'Unexpected key: "{key}"',
96
+ enum_invalid: "Value must be one of: {values}",
97
+ tuple_length: "Tuple must have exactly {length} items",
98
+ union_fail: "Value does not match any schema",
99
+ intersection_fail: "Value does not match intersection schema",
100
+ literal_fail: "Value must be {expected}",
101
+ refine_fail: "{message}",
102
+ date_invalid: "Invalid date",
103
+ date_not_date: "Value must be a valid date",
104
+ indonesia_nik: "NIK must be 16 digits with valid format",
105
+ indonesia_npwp: "Invalid NPWP format",
106
+ indonesia_phone: "Invalid Indonesian phone number",
107
+ indonesia_alamat: "Invalid address (min 10 characters, must contain street/RT/RW elements)",
108
+ indonesia_kodepos: "Postal code must be 5 digits",
109
+ indonesia_rekening: "Bank account number must be 10-16 digits",
110
+ coerce_number_fail: "Value cannot be coerced to a number",
111
+ coerce_date_fail: "Value cannot be coerced to a date",
112
+ map_not_map: "Expected a Map",
113
+ set_not_set: "Expected a Set"
114
+ };
115
+ var store = { ...ID };
116
+ function msg(key, params) {
117
+ let template = store[key];
118
+ if (!template) return key;
119
+ if (params) {
120
+ for (const [k, v] of Object.entries(params)) {
121
+ template = template.replace(`{${k}}`, v !== void 0 ? String(v) : "");
122
+ }
123
+ }
124
+ return template;
125
+ }
126
+ function setLocale(locale) {
127
+ currentLocale = locale;
128
+ const source = locale === "id" ? ID : EN;
129
+ for (const key in source) {
130
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
131
+ store[key] = source[key];
132
+ }
133
+ }
134
+ }
135
+ function getLocale() {
136
+ return currentLocale;
137
+ }
138
+
139
+ // src/schema/types.ts
140
+ var SchemaError = class extends Error {
141
+ path;
142
+ received;
143
+ constructor(message, options) {
144
+ super(message);
145
+ this.name = "SchemaError";
146
+ this.path = options?.path ?? "";
147
+ this.received = options?.received;
148
+ }
149
+ toJSON() {
150
+ return { name: this.name, message: this.message, path: this.path, received: this.received };
151
+ }
152
+ };
153
+ var Schema = class {
154
+ parse(value) {
155
+ return this._parse(value);
156
+ }
157
+ safeParse(value) {
158
+ try {
159
+ const data = this._parse(value);
160
+ return { success: true, data };
161
+ } catch (e) {
162
+ if (e instanceof SchemaError) {
163
+ return { success: false, error: e.message };
164
+ }
165
+ return { success: false, error: String(e) };
166
+ }
167
+ }
168
+ optional() {
169
+ return new OptionalSchema(this);
170
+ }
171
+ nullable() {
172
+ return new NullableSchema(this);
173
+ }
174
+ default(defaultValue) {
175
+ return new DefaultSchema(this, defaultValue);
176
+ }
177
+ describe(_description) {
178
+ return this;
179
+ }
180
+ refine(fn, message) {
181
+ return new RefineSchema(this, fn, message);
182
+ }
183
+ transform(fn) {
184
+ return new TransformSchema(this, fn);
185
+ }
186
+ /** @internal used by s.enum() etc */
187
+ get _internal() {
188
+ return this;
189
+ }
190
+ };
191
+ var OptionalSchema = class extends Schema {
192
+ constructor(inner) {
193
+ super();
194
+ this.inner = inner;
195
+ }
196
+ inner;
197
+ _parse(value) {
198
+ if (value === void 0) return void 0;
199
+ return this.inner._parse(value);
200
+ }
201
+ };
202
+ var NullableSchema = class extends Schema {
203
+ constructor(inner) {
204
+ super();
205
+ this.inner = inner;
206
+ }
207
+ inner;
208
+ _parse(value) {
209
+ if (value === null) return null;
210
+ return this.inner._parse(value);
211
+ }
212
+ };
213
+ var DefaultSchema = class extends Schema {
214
+ constructor(inner, defaultValue) {
215
+ super();
216
+ this.inner = inner;
217
+ this.defaultValue = defaultValue;
218
+ }
219
+ inner;
220
+ defaultValue;
221
+ _parse(value) {
222
+ if (value === void 0) return this.defaultValue;
223
+ return this.inner._parse(value);
224
+ }
225
+ };
226
+ var RefineSchema = class extends Schema {
227
+ constructor(inner, fn, errorMsg) {
228
+ super();
229
+ this.inner = inner;
230
+ this.fn = fn;
231
+ this.errorMsg = errorMsg;
232
+ }
233
+ inner;
234
+ fn;
235
+ errorMsg;
236
+ _parse(value) {
237
+ const result = this.inner._parse(value);
238
+ if (!this.fn(result)) {
239
+ throw new SchemaError(msg("refine_fail", { message: this.errorMsg }));
240
+ }
241
+ return result;
242
+ }
243
+ };
244
+ var TransformSchema = class extends Schema {
245
+ constructor(inner, fn) {
246
+ super();
247
+ this.inner = inner;
248
+ this.fn = fn;
249
+ }
250
+ inner;
251
+ fn;
252
+ _parse(value) {
253
+ const result = this.inner._parse(value);
254
+ return this.fn(result);
255
+ }
256
+ };
257
+
258
+ // src/schema/primitives.ts
259
+ var StringSchema = class extends Schema {
260
+ checks = [];
261
+ min(n) {
262
+ this.checks.push((val) => {
263
+ if (val.length < n) throw new SchemaError(msg("string_min", { min: n }));
264
+ });
265
+ return this;
266
+ }
267
+ max(n) {
268
+ this.checks.push((val) => {
269
+ if (val.length > n) throw new SchemaError(msg("string_max", { max: n }));
270
+ });
271
+ return this;
272
+ }
273
+ length(n) {
274
+ this.checks.push((val) => {
275
+ if (val.length !== n) throw new SchemaError(msg("string_length", { length: n }));
276
+ });
277
+ return this;
278
+ }
279
+ email() {
280
+ this.checks.push((val) => {
281
+ if (!isValidEmail(val)) throw new SchemaError(msg("string_email"));
282
+ });
283
+ return this;
284
+ }
285
+ url() {
286
+ this.checks.push((val) => {
287
+ try {
288
+ const url = new URL(val);
289
+ if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error();
290
+ } catch {
291
+ throw new SchemaError(msg("string_url"));
292
+ }
293
+ });
294
+ return this;
295
+ }
296
+ regex(pattern) {
297
+ this.checks.push((val) => {
298
+ if (!pattern.test(val)) throw new SchemaError(msg("string_regex"));
299
+ });
300
+ return this;
301
+ }
302
+ includes(substring) {
303
+ this.checks.push((val) => {
304
+ if (!val.includes(substring)) throw new SchemaError(msg("string_includes", { substring }));
305
+ });
306
+ return this;
307
+ }
308
+ startsWith(prefix) {
309
+ this.checks.push((val) => {
310
+ if (!val.startsWith(prefix)) throw new SchemaError(msg("string_starts_with", { prefix }));
311
+ });
312
+ return this;
313
+ }
314
+ endsWith(suffix) {
315
+ this.checks.push((val) => {
316
+ if (!val.endsWith(suffix)) throw new SchemaError(msg("string_ends_with", { suffix }));
317
+ });
318
+ return this;
319
+ }
320
+ trim() {
321
+ return new StringTrimSchema(this);
322
+ }
323
+ lowercase() {
324
+ return new StringLowercaseSchema(this);
325
+ }
326
+ uppercase() {
327
+ return new StringUppercaseSchema(this);
328
+ }
329
+ _parse(value) {
330
+ if (typeof value !== "string") throw new SchemaError(msg("type_string"));
331
+ for (const check of this.checks) check(value);
332
+ return value;
333
+ }
334
+ };
335
+ var StringTrimSchema = class extends Schema {
336
+ constructor(inner) {
337
+ super();
338
+ this.inner = inner;
339
+ }
340
+ inner;
341
+ _parse(value) {
342
+ const result = this.inner._parse(value);
343
+ return result.trim();
344
+ }
345
+ };
346
+ var StringLowercaseSchema = class extends Schema {
347
+ constructor(inner) {
348
+ super();
349
+ this.inner = inner;
350
+ }
351
+ inner;
352
+ _parse(value) {
353
+ const result = this.inner._parse(value);
354
+ return result.toLowerCase();
355
+ }
356
+ };
357
+ var StringUppercaseSchema = class extends Schema {
358
+ constructor(inner) {
359
+ super();
360
+ this.inner = inner;
361
+ }
362
+ inner;
363
+ _parse(value) {
364
+ const result = this.inner._parse(value);
365
+ return result.toUpperCase();
366
+ }
367
+ };
368
+ var NumberSchema = class extends Schema {
369
+ checks = [];
370
+ min(n) {
371
+ this.checks.push((val) => {
372
+ if (val < n) throw new SchemaError(msg("number_min", { min: n }));
373
+ });
374
+ return this;
375
+ }
376
+ max(n) {
377
+ this.checks.push((val) => {
378
+ if (val > n) throw new SchemaError(msg("number_max", { max: n }));
379
+ });
380
+ return this;
381
+ }
382
+ int() {
383
+ this.checks.push((val) => {
384
+ if (!Number.isInteger(val)) throw new SchemaError(msg("number_int"));
385
+ });
386
+ return this;
387
+ }
388
+ positive() {
389
+ this.checks.push((val) => {
390
+ if (val <= 0) throw new SchemaError(msg("number_positive"));
391
+ });
392
+ return this;
393
+ }
394
+ negative() {
395
+ this.checks.push((val) => {
396
+ if (val >= 0) throw new SchemaError(msg("number_negative"));
397
+ });
398
+ return this;
399
+ }
400
+ finite() {
401
+ this.checks.push((val) => {
402
+ if (!Number.isFinite(val)) throw new SchemaError(msg("number_finite"));
403
+ });
404
+ return this;
405
+ }
406
+ safe() {
407
+ this.checks.push((val) => {
408
+ if (!Number.isSafeInteger(val)) throw new SchemaError(msg("number_safe"));
409
+ });
410
+ return this;
411
+ }
412
+ _parse(value) {
413
+ if (typeof value !== "number" || Number.isNaN(value)) {
414
+ throw new SchemaError(msg("type_number"));
415
+ }
416
+ for (const check of this.checks) check(value);
417
+ return value;
418
+ }
419
+ };
420
+ var BooleanSchema = class extends Schema {
421
+ _parse(value) {
422
+ if (typeof value !== "boolean") throw new SchemaError(msg("type_boolean"));
423
+ return value;
424
+ }
425
+ };
426
+ var BigIntSchema = class extends Schema {
427
+ _parse(value) {
428
+ if (typeof value !== "bigint") throw new SchemaError(msg("type_bigint"));
429
+ return value;
430
+ }
431
+ };
432
+ var SymbolSchema = class extends Schema {
433
+ _parse(value) {
434
+ if (typeof value !== "symbol") throw new SchemaError(msg("type_symbol"));
435
+ return value;
436
+ }
437
+ };
438
+ var UndefinedSchema = class extends Schema {
439
+ _parse(value) {
440
+ if (value !== void 0) throw new SchemaError(msg("type_undefined"));
441
+ return void 0;
442
+ }
443
+ };
444
+ var NullSchema = class extends Schema {
445
+ _parse(value) {
446
+ if (value !== null) throw new SchemaError(msg("type_null"));
447
+ return null;
448
+ }
449
+ };
450
+ var NaNSchema = class extends Schema {
451
+ _parse(value) {
452
+ if (typeof value !== "number" || !Number.isNaN(value)) {
453
+ throw new SchemaError(msg("type_nan"));
454
+ }
455
+ return value;
456
+ }
457
+ };
458
+ function isValidEmail(value) {
459
+ if (value.length > 254) return false;
460
+ const atIndex = value.lastIndexOf("@");
461
+ if (atIndex < 1 || atIndex === value.length - 1) return false;
462
+ const localPart = value.slice(0, atIndex);
463
+ const domainPart = value.slice(atIndex + 1);
464
+ if (localPart.length > 64) return false;
465
+ if (domainPart.length > 255) return false;
466
+ if (domainPart.split(".").length < 2) return false;
467
+ if (localPart.startsWith('"') && localPart.endsWith('"')) {
468
+ if (localPart.length < 2) return false;
469
+ let i = 1;
470
+ while (i < localPart.length - 1) {
471
+ const ch = localPart[i];
472
+ if (ch === "\\") {
473
+ i++;
474
+ if (i >= localPart.length - 1) return false;
475
+ } else if (ch === '"') {
476
+ return false;
477
+ }
478
+ i++;
479
+ }
480
+ return true;
481
+ }
482
+ if (localPart.length === 0 || localPart.startsWith(".") || localPart.endsWith(".")) return false;
483
+ for (let i = 0; i < localPart.length; i++) {
484
+ const ch = localPart[i];
485
+ if ('<>=()[]\\,;:@"'.includes(ch)) return false;
486
+ }
487
+ for (let i = 1; i < localPart.length; i++) {
488
+ if (localPart[i] === "." && localPart[i - 1] === ".") return false;
489
+ }
490
+ for (const label of domainPart.split(".")) {
491
+ if (label.length === 0 || label.length > 63) return false;
492
+ if (label.startsWith("-") || label.endsWith("-")) return false;
493
+ for (let i = 0; i < label.length; i++) {
494
+ const ch = label[i];
495
+ if (!(ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9" || ch === "-")) {
496
+ return false;
497
+ }
498
+ }
499
+ }
500
+ return true;
501
+ }
502
+
503
+ // src/schema/complex.ts
504
+ var ObjectSchema = class _ObjectSchema extends Schema {
505
+ shape;
506
+ isStrictMode = false;
507
+ isPassthroughMode = false;
508
+ constructor(shape) {
509
+ super();
510
+ this.shape = shape;
511
+ }
512
+ strict() {
513
+ this.isStrictMode = true;
514
+ this.isPassthroughMode = false;
515
+ return this;
516
+ }
517
+ passthrough() {
518
+ this.isPassthroughMode = true;
519
+ this.isStrictMode = false;
520
+ return this;
521
+ }
522
+ partial() {
523
+ const newShape = {};
524
+ for (const key in this.shape) {
525
+ if (Object.prototype.hasOwnProperty.call(this.shape, key)) {
526
+ newShape[key] = new OptionalSchema(this.shape[key]);
527
+ }
528
+ }
529
+ return new _ObjectSchema(newShape);
530
+ }
531
+ pick(keys) {
532
+ const newShape = {};
533
+ for (const key of keys) {
534
+ const strKey = key;
535
+ if (Object.prototype.hasOwnProperty.call(this.shape, strKey)) {
536
+ newShape[strKey] = this.shape[strKey];
537
+ }
538
+ }
539
+ return new _ObjectSchema(newShape);
540
+ }
541
+ omit(keys) {
542
+ const newShape = {};
543
+ for (const key in this.shape) {
544
+ if (Object.prototype.hasOwnProperty.call(this.shape, key) && !keys.includes(key)) {
545
+ newShape[key] = this.shape[key];
546
+ }
547
+ }
548
+ return new _ObjectSchema(newShape);
549
+ }
550
+ extend(shape) {
551
+ return new _ObjectSchema({ ...this.shape, ...shape });
552
+ }
553
+ merge(other) {
554
+ return new _ObjectSchema({ ...this.shape, ...other.shape });
555
+ }
556
+ _parse(value) {
557
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
558
+ throw new SchemaError(msg("type_object"));
559
+ }
560
+ const obj = value;
561
+ const result = {};
562
+ for (const key in this.shape) {
563
+ if (Object.prototype.hasOwnProperty.call(this.shape, key)) {
564
+ const schema = this.shape[key];
565
+ try {
566
+ result[key] = schema._parse(obj[key]);
567
+ } catch (e) {
568
+ if (e instanceof SchemaError) {
569
+ throw new SchemaError(e.message, {
570
+ path: e.path ? `${key}.${e.path}` : key,
571
+ received: obj[key]
572
+ });
573
+ }
574
+ throw e;
575
+ }
576
+ }
577
+ }
578
+ if (this.isStrictMode) {
579
+ for (const key in obj) {
580
+ if (Object.prototype.hasOwnProperty.call(obj, key) && !(key in this.shape)) {
581
+ throw new SchemaError(msg("object_strict", { key }));
582
+ }
583
+ }
584
+ }
585
+ if (this.isPassthroughMode) {
586
+ for (const key in obj) {
587
+ if (Object.prototype.hasOwnProperty.call(obj, key) && !(key in this.shape)) {
588
+ result[key] = obj[key];
589
+ }
590
+ }
591
+ }
592
+ return result;
593
+ }
594
+ };
595
+ var ArraySchema = class extends Schema {
596
+ constructor(itemSchema) {
597
+ super();
598
+ this.itemSchema = itemSchema;
599
+ }
600
+ itemSchema;
601
+ checks = [];
602
+ min(n) {
603
+ this.checks.push((val) => {
604
+ if (val.length < n) throw new SchemaError(msg("array_min", { min: n }));
605
+ });
606
+ return this;
607
+ }
608
+ max(n) {
609
+ this.checks.push((val) => {
610
+ if (val.length > n) throw new SchemaError(msg("array_max", { max: n }));
611
+ });
612
+ return this;
613
+ }
614
+ length(n) {
615
+ this.checks.push((val) => {
616
+ if (val.length !== n) throw new SchemaError(msg("array_length", { length: n }));
617
+ });
618
+ return this;
619
+ }
620
+ nonempty() {
621
+ this.checks.push((val) => {
622
+ if (val.length === 0) throw new SchemaError(msg("array_nonempty"));
623
+ });
624
+ return this;
625
+ }
626
+ unique() {
627
+ this.checks.push((val) => {
628
+ const seen = /* @__PURE__ */ new Set();
629
+ for (const item of val) {
630
+ if (seen.has(item)) throw new SchemaError(msg("array_unique"));
631
+ seen.add(item);
632
+ }
633
+ });
634
+ return this;
635
+ }
636
+ _parse(value) {
637
+ if (!Array.isArray(value)) throw new SchemaError(msg("type_array"));
638
+ const result = [];
639
+ for (let i = 0; i < value.length; i++) {
640
+ try {
641
+ result.push(this.itemSchema._parse(value[i]));
642
+ } catch (e) {
643
+ if (e instanceof SchemaError) {
644
+ throw new SchemaError(e.message, {
645
+ path: e.path ? `[${i}].${e.path}` : `[${i}]`,
646
+ received: value[i]
647
+ });
648
+ }
649
+ throw e;
650
+ }
651
+ }
652
+ for (const check of this.checks) check(result);
653
+ return result;
654
+ }
655
+ };
656
+ var TupleSchema = class extends Schema {
657
+ constructor(schemas) {
658
+ super();
659
+ this.schemas = schemas;
660
+ }
661
+ schemas;
662
+ _parse(value) {
663
+ if (!Array.isArray(value)) throw new SchemaError(msg("type_array"));
664
+ if (value.length !== this.schemas.length) {
665
+ throw new SchemaError(msg("tuple_length", { length: this.schemas.length }));
666
+ }
667
+ const result = [];
668
+ for (let i = 0; i < this.schemas.length; i++) {
669
+ try {
670
+ result.push(this.schemas[i]._parse(value[i]));
671
+ } catch (e) {
672
+ if (e instanceof SchemaError) {
673
+ throw new SchemaError(e.message, {
674
+ path: e.path ? `[${i}].${e.path}` : `[${i}]`,
675
+ received: value[i]
676
+ });
677
+ }
678
+ throw e;
679
+ }
680
+ }
681
+ return result;
682
+ }
683
+ };
684
+ var EnumSchema = class extends Schema {
685
+ constructor(values) {
686
+ super();
687
+ this.values = values;
688
+ }
689
+ values;
690
+ _parse(value) {
691
+ if (typeof value !== "string") throw new SchemaError(msg("type_string"));
692
+ for (const v of this.values) {
693
+ if (v === value) return value;
694
+ }
695
+ throw new SchemaError(msg("enum_invalid", { values: this.values.join(", ") }));
696
+ }
697
+ get enum() {
698
+ return this.values;
699
+ }
700
+ };
701
+ var UnionSchema = class extends Schema {
702
+ constructor(schemas) {
703
+ super();
704
+ this.schemas = schemas;
705
+ }
706
+ schemas;
707
+ _parse(value) {
708
+ const errors = [];
709
+ for (const schema of this.schemas) {
710
+ try {
711
+ return schema._parse(value);
712
+ } catch (e) {
713
+ errors.push(e instanceof SchemaError ? e.message : String(e));
714
+ }
715
+ }
716
+ throw new SchemaError(msg("union_fail"));
717
+ }
718
+ };
719
+ var IntersectionSchema = class extends Schema {
720
+ constructor(left, right) {
721
+ super();
722
+ this.left = left;
723
+ this.right = right;
724
+ }
725
+ left;
726
+ right;
727
+ _parse(value) {
728
+ const a = this.left._parse(value);
729
+ const b = this.right._parse(value);
730
+ if (typeof a === "object" && a !== null && typeof b === "object" && b !== null) {
731
+ return { ...a, ...b };
732
+ }
733
+ if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
734
+ if (a === b) return a;
735
+ }
736
+ throw new SchemaError(msg("intersection_fail"));
737
+ }
738
+ };
739
+ var RecordSchema = class extends Schema {
740
+ constructor(valueSchema) {
741
+ super();
742
+ this.valueSchema = valueSchema;
743
+ }
744
+ valueSchema;
745
+ _parse(value) {
746
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
747
+ throw new SchemaError(msg("type_object"));
748
+ }
749
+ const result = {};
750
+ const obj = value;
751
+ for (const key in obj) {
752
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
753
+ result[key] = this.valueSchema._parse(obj[key]);
754
+ }
755
+ }
756
+ return result;
757
+ }
758
+ };
759
+ var MapSchema = class extends Schema {
760
+ constructor(keySchema, valueSchema) {
761
+ super();
762
+ this.keySchema = keySchema;
763
+ this.valueSchema = valueSchema;
764
+ }
765
+ keySchema;
766
+ valueSchema;
767
+ _parse(value) {
768
+ if (!(value instanceof Map)) throw new SchemaError(msg("map_not_map"));
769
+ const result = /* @__PURE__ */ new Map();
770
+ for (const [k, v] of value) {
771
+ result.set(this.keySchema._parse(k), this.valueSchema._parse(v));
772
+ }
773
+ return result;
774
+ }
775
+ };
776
+ var SetSchema = class extends Schema {
777
+ constructor(itemSchema) {
778
+ super();
779
+ this.itemSchema = itemSchema;
780
+ }
781
+ itemSchema;
782
+ _parse(value) {
783
+ if (!(value instanceof Set)) throw new SchemaError(msg("set_not_set"));
784
+ const result = /* @__PURE__ */ new Set();
785
+ for (const item of value) {
786
+ result.add(this.itemSchema._parse(item));
787
+ }
788
+ return result;
789
+ }
790
+ };
791
+ var DateSchema = class extends Schema {
792
+ _parse(value) {
793
+ if (value instanceof Date) {
794
+ if (Number.isNaN(value.getTime())) throw new SchemaError(msg("date_invalid"));
795
+ return value;
796
+ }
797
+ if (typeof value === "number" || typeof value === "string") {
798
+ const date = new Date(value);
799
+ if (Number.isNaN(date.getTime())) throw new SchemaError(msg("date_invalid"));
800
+ return date;
801
+ }
802
+ throw new SchemaError(msg("type_date"));
803
+ }
804
+ };
805
+ var LiteralSchema = class extends Schema {
806
+ constructor(expected) {
807
+ super();
808
+ this.expected = expected;
809
+ }
810
+ expected;
811
+ _parse(value) {
812
+ if (value !== this.expected) {
813
+ throw new SchemaError(msg("literal_fail", { expected: String(this.expected) }));
814
+ }
815
+ return value;
816
+ }
817
+ };
818
+ var AnySchema = class extends Schema {
819
+ _parse(value) {
820
+ return value;
821
+ }
822
+ };
823
+ var UnknownSchema = class extends Schema {
824
+ _parse(value) {
825
+ return value;
826
+ }
827
+ };
828
+
829
+ // src/schema/indonesia.ts
830
+ function isNIK(value) {
831
+ const digits = value.replace(/\D/g, "");
832
+ if (digits.length !== 16) return false;
833
+ const rawDay = Number.parseInt(digits.slice(6, 8), 10);
834
+ const month = Number.parseInt(digits.slice(8, 10), 10);
835
+ const year = Number.parseInt(digits.slice(10, 12), 10);
836
+ if (rawDay < 1 || rawDay > 71) return false;
837
+ if (month < 1 || month > 12) return false;
838
+ let day = rawDay;
839
+ if (day >= 41) day -= 40;
840
+ const fullYear = year < 70 ? 2e3 + year : 1900 + year;
841
+ const date = new Date(fullYear, month - 1, day);
842
+ return date.getFullYear() === fullYear && date.getMonth() === month - 1 && date.getDate() === day;
843
+ }
844
+ function isNPWP(value) {
845
+ const digits = value.replace(/\D/g, "");
846
+ if (digits.length !== 15 && digits.length !== 16) return false;
847
+ const nums = [];
848
+ for (let i = 0; i < digits.length; i++) {
849
+ nums.push(Number.parseInt(digits[i], 10));
850
+ }
851
+ const checkDigit = nums[nums.length - 1];
852
+ let sum = 0;
853
+ for (let i = 0; i < nums.length - 1; i++) {
854
+ sum += nums[i] * [3, 7, 1][i % 3];
855
+ }
856
+ const computed = (11 - sum % 11) % 10;
857
+ return computed === checkDigit;
858
+ }
859
+ var INDONESIAN_PREFIXES = [
860
+ [11, 19],
861
+ [21, 29],
862
+ [51, 59],
863
+ [77, 79],
864
+ [95, 99]
865
+ ];
866
+ function isValidIndonesianPrefix(prefix) {
867
+ for (const [min, max] of INDONESIAN_PREFIXES) {
868
+ if (prefix >= min && prefix <= max) return true;
869
+ }
870
+ return false;
871
+ }
872
+ function isPhone(value, country = "id") {
873
+ const digits = value.replace(/\D/g, "");
874
+ if (country === "any") {
875
+ return digits.length >= 10 && digits.length <= 15;
876
+ }
877
+ if (digits.length < 10) return false;
878
+ let normalized;
879
+ if (digits.startsWith("62")) {
880
+ normalized = digits.slice(2);
881
+ } else if (digits.startsWith("0")) {
882
+ normalized = digits.slice(1);
883
+ } else {
884
+ normalized = digits;
885
+ }
886
+ if (normalized.length < 10 || normalized.length > 13) return false;
887
+ if (!normalized.startsWith("8")) return false;
888
+ const prefix = Number.parseInt(normalized.slice(1, 3), 10);
889
+ return isValidIndonesianPrefix(prefix);
890
+ }
891
+ var NIKSchema = class extends Schema {
892
+ _parse(value) {
893
+ if (typeof value !== "string") throw new SchemaError(msg("type_string"));
894
+ if (!isNIK(value)) throw new SchemaError(msg("indonesia_nik"));
895
+ return value;
896
+ }
897
+ };
898
+ var NPWPSchema = class extends Schema {
899
+ _parse(value) {
900
+ if (typeof value !== "string") throw new SchemaError(msg("type_string"));
901
+ if (!isNPWP(value)) throw new SchemaError(msg("indonesia_npwp"));
902
+ return value;
903
+ }
904
+ };
905
+ var PhoneSchema = class extends Schema {
906
+ _parse(value) {
907
+ if (typeof value !== "string") throw new SchemaError(msg("type_string"));
908
+ if (!isPhone(value, "id")) throw new SchemaError(msg("indonesia_phone"));
909
+ return value;
910
+ }
911
+ };
912
+ var ALAMAT_KEYWORDS = [
913
+ /^jl[.\s]/i,
914
+ /^jalan\s/i,
915
+ /^gg[.\s]/i,
916
+ /^gang\s/i,
917
+ /rt\s*\d/i,
918
+ /rw\s*\d/i,
919
+ /dsn/i,
920
+ /dusun/i,
921
+ /kec/i,
922
+ /kelurahan/i,
923
+ /desa/i,
924
+ /perum/i,
925
+ /komplek/i
926
+ ];
927
+ var AlamatSchema = class extends Schema {
928
+ _parse(value) {
929
+ if (typeof value !== "string") throw new SchemaError(msg("type_string"));
930
+ if (value.length < 10) throw new SchemaError(msg("indonesia_alamat"));
931
+ let hasKeyword = false;
932
+ for (const pattern of ALAMAT_KEYWORDS) {
933
+ if (pattern.test(value)) {
934
+ hasKeyword = true;
935
+ break;
936
+ }
937
+ }
938
+ if (!hasKeyword) throw new SchemaError(msg("indonesia_alamat"));
939
+ return value;
940
+ }
941
+ };
942
+ var KodeposSchema = class extends Schema {
943
+ _parse(value) {
944
+ if (typeof value !== "string") throw new SchemaError(msg("type_string"));
945
+ const digits = value.replace(/\s/g, "");
946
+ if (!/^\d{5}$/.test(digits)) throw new SchemaError(msg("indonesia_kodepos"));
947
+ return digits;
948
+ }
949
+ };
950
+ var RekeningSchema = class extends Schema {
951
+ _parse(value) {
952
+ if (typeof value !== "string") throw new SchemaError(msg("type_string"));
953
+ const digits = value.replace(/\s/g, "");
954
+ if (!/^\d{10,16}$/.test(digits)) throw new SchemaError(msg("indonesia_rekening"));
955
+ return digits;
956
+ }
957
+ };
958
+
959
+ // src/schema/transform.ts
960
+ var CoerceStringSchema = class extends Schema {
961
+ _parse(value) {
962
+ if (value === null || value === void 0) throw new SchemaError(msg("type_string"));
963
+ return String(value);
964
+ }
965
+ };
966
+ var CoerceNumberSchema = class extends Schema {
967
+ _parse(value) {
968
+ if (typeof value === "number") return value;
969
+ if (typeof value === "string") {
970
+ const trimmed = value.trim();
971
+ if (trimmed.length === 0) throw new SchemaError(msg("coerce_number_fail"));
972
+ const num = Number(trimmed);
973
+ if (Number.isNaN(num)) throw new SchemaError(msg("coerce_number_fail"));
974
+ return num;
975
+ }
976
+ if (typeof value === "bigint") return Number(value);
977
+ if (value instanceof Date) return value.getTime();
978
+ throw new SchemaError(msg("coerce_number_fail"));
979
+ }
980
+ };
981
+ var CoerceBooleanSchema = class extends Schema {
982
+ _parse(value) {
983
+ if (typeof value === "boolean") return value;
984
+ if (value === 0 || value === 1) return value === 1;
985
+ if (typeof value === "string") {
986
+ const lower = value.toLowerCase().trim();
987
+ if (lower === "true" || lower === "1" || lower === "yes" || lower === "on") return true;
988
+ if (lower === "false" || lower === "0" || lower === "no" || lower === "off") return false;
989
+ }
990
+ return Boolean(value);
991
+ }
992
+ };
993
+ var CoerceDateSchema = class extends Schema {
994
+ _parse(value) {
995
+ if (value instanceof Date) {
996
+ if (Number.isNaN(value.getTime())) throw new SchemaError(msg("coerce_date_fail"));
997
+ return value;
998
+ }
999
+ if (typeof value === "number" || typeof value === "string") {
1000
+ const date = new Date(value);
1001
+ if (Number.isNaN(date.getTime())) throw new SchemaError(msg("coerce_date_fail"));
1002
+ return date;
1003
+ }
1004
+ throw new SchemaError(msg("coerce_date_fail"));
1005
+ }
1006
+ };
1007
+ var StandaloneTransformSchema = class extends Schema {
1008
+ constructor(fn) {
1009
+ super();
1010
+ this.fn = fn;
1011
+ }
1012
+ fn;
1013
+ _parse(value) {
1014
+ return this.fn(value);
1015
+ }
1016
+ };
1017
+
1018
+ // src/schema/index.ts
1019
+ var s = {
1020
+ string() {
1021
+ return new StringSchema();
1022
+ },
1023
+ number() {
1024
+ return new NumberSchema();
1025
+ },
1026
+ boolean() {
1027
+ return new BooleanSchema();
1028
+ },
1029
+ bigint() {
1030
+ return new BigIntSchema();
1031
+ },
1032
+ symbol() {
1033
+ return new SymbolSchema();
1034
+ },
1035
+ undefined() {
1036
+ return new UndefinedSchema();
1037
+ },
1038
+ null() {
1039
+ return new NullSchema();
1040
+ },
1041
+ nan() {
1042
+ return new NaNSchema();
1043
+ },
1044
+ object(shape) {
1045
+ return new ObjectSchema(shape);
1046
+ },
1047
+ array(itemSchema) {
1048
+ return new ArraySchema(itemSchema);
1049
+ },
1050
+ tuple(...schemas) {
1051
+ return new TupleSchema(schemas);
1052
+ },
1053
+ enum(values) {
1054
+ return new EnumSchema(values);
1055
+ },
1056
+ union(...schemas) {
1057
+ return new UnionSchema(schemas);
1058
+ },
1059
+ intersection(left, right) {
1060
+ return new IntersectionSchema(left, right);
1061
+ },
1062
+ record(valueSchema) {
1063
+ return new RecordSchema(valueSchema);
1064
+ },
1065
+ map(keySchema, valueSchema) {
1066
+ return new MapSchema(keySchema, valueSchema);
1067
+ },
1068
+ set(itemSchema) {
1069
+ return new SetSchema(itemSchema);
1070
+ },
1071
+ date() {
1072
+ return new DateSchema();
1073
+ },
1074
+ literal(value) {
1075
+ return new LiteralSchema(value);
1076
+ },
1077
+ any() {
1078
+ return new AnySchema();
1079
+ },
1080
+ unknown() {
1081
+ return new UnknownSchema();
1082
+ },
1083
+ // ─── Indonesia ──────────────────────────────────────────
1084
+ nik() {
1085
+ return new NIKSchema();
1086
+ },
1087
+ npwp() {
1088
+ return new NPWPSchema();
1089
+ },
1090
+ phone() {
1091
+ return new PhoneSchema();
1092
+ },
1093
+ alamat() {
1094
+ return new AlamatSchema();
1095
+ },
1096
+ kodepos() {
1097
+ return new KodeposSchema();
1098
+ },
1099
+ rekening() {
1100
+ return new RekeningSchema();
1101
+ },
1102
+ // ─── Coerce ─────────────────────────────────────────────
1103
+ coerce: {
1104
+ string() {
1105
+ return new CoerceStringSchema();
1106
+ },
1107
+ number() {
1108
+ return new CoerceNumberSchema();
1109
+ },
1110
+ boolean() {
1111
+ return new CoerceBooleanSchema();
1112
+ },
1113
+ date() {
1114
+ return new CoerceDateSchema();
1115
+ }
1116
+ },
1117
+ // ─── Transform ──────────────────────────────────────────
1118
+ transform(fn) {
1119
+ return new StandaloneTransformSchema(fn);
1120
+ }
1121
+ };
1122
+ export {
1123
+ AlamatSchema,
1124
+ AnySchema,
1125
+ ArraySchema,
1126
+ BigIntSchema,
1127
+ BooleanSchema,
1128
+ CoerceBooleanSchema,
1129
+ CoerceDateSchema,
1130
+ CoerceNumberSchema,
1131
+ CoerceStringSchema,
1132
+ DateSchema,
1133
+ EnumSchema,
1134
+ IntersectionSchema,
1135
+ KodeposSchema,
1136
+ LiteralSchema,
1137
+ MapSchema,
1138
+ NIKSchema,
1139
+ NPWPSchema,
1140
+ NaNSchema,
1141
+ NullSchema,
1142
+ NumberSchema,
1143
+ ObjectSchema,
1144
+ PhoneSchema,
1145
+ RecordSchema,
1146
+ RekeningSchema,
1147
+ Schema,
1148
+ SchemaError,
1149
+ SetSchema,
1150
+ StringSchema,
1151
+ SymbolSchema,
1152
+ TupleSchema,
1153
+ UndefinedSchema,
1154
+ UnionSchema,
1155
+ UnknownSchema,
1156
+ getLocale,
1157
+ s,
1158
+ setLocale
1159
+ };
1160
+ //# sourceMappingURL=index.js.map