speexjs 0.2.2 → 0.3.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.
@@ -1,4 +1,4 @@
1
- import { S as Schema } from '../types-CXH8hPei.js';
1
+ import { S as Schema } from '../types-aW38f63o.js';
2
2
 
3
3
  interface RpcProcedure<TInput = unknown, TOutput = unknown> {
4
4
  input?: Schema<TInput>;
@@ -1,8 +1,8 @@
1
- import { S as Schema, I as Infer } from '../types-CXH8hPei.js';
2
- export { a as SchemaError } from '../types-CXH8hPei.js';
1
+ import { S as Schema, I as Infer } from '../types-aW38f63o.js';
2
+ export { a as SchemaError } from '../types-aW38f63o.js';
3
3
 
4
- declare function setLocale(locale: 'id' | 'en'): void;
5
- declare function getLocale(): 'id' | 'en';
4
+ declare function setLocale(_locale: 'en'): void;
5
+ declare function getLocale(): 'en';
6
6
 
7
7
  declare class StringSchema extends Schema<string> {
8
8
  private checks;
@@ -154,25 +154,6 @@ declare class UnknownSchema extends Schema<unknown> {
154
154
  _parse(value: unknown): unknown;
155
155
  }
156
156
 
157
- declare class NIKSchema extends Schema<string> {
158
- _parse(value: unknown): string;
159
- }
160
- declare class NPWPSchema extends Schema<string> {
161
- _parse(value: unknown): string;
162
- }
163
- declare class PhoneSchema extends Schema<string> {
164
- _parse(value: unknown): string;
165
- }
166
- declare class AlamatSchema extends Schema<string> {
167
- _parse(value: unknown): string;
168
- }
169
- declare class KodeposSchema extends Schema<string> {
170
- _parse(value: unknown): string;
171
- }
172
- declare class RekeningSchema extends Schema<string> {
173
- _parse(value: unknown): string;
174
- }
175
-
176
157
  declare class CoerceStringSchema extends Schema<string> {
177
158
  _parse(value: unknown): string;
178
159
  }
@@ -191,6 +172,37 @@ declare class StandaloneTransformSchema<T> extends Schema<T> {
191
172
  _parse(value: unknown): T;
192
173
  }
193
174
 
175
+ declare const schema: {
176
+ readonly string: () => StringSchema;
177
+ readonly number: () => NumberSchema;
178
+ readonly boolean: () => BooleanSchema;
179
+ readonly bigint: () => BigIntSchema;
180
+ readonly symbol: () => SymbolSchema;
181
+ readonly undefined: () => UndefinedSchema;
182
+ readonly null: () => NullSchema;
183
+ readonly nan: () => NaNSchema;
184
+ readonly object: <T extends Record<string, Schema<unknown>>>(shape: T) => ObjectSchema<T>;
185
+ readonly array: <T>(itemSchema: Schema<T>) => ArraySchema<T>;
186
+ readonly tuple: <T extends Schema<unknown>[]>(...schemas: T) => TupleSchema<T>;
187
+ readonly enum: <T extends string>(values: readonly T[]) => EnumSchema<T>;
188
+ readonly union: <T extends Schema<unknown>[]>(...schemas: T) => UnionSchema<T[number] extends Schema<infer U> ? U : never>;
189
+ readonly intersection: <A, B>(left: Schema<A>, right: Schema<B>) => IntersectionSchema<A, B>;
190
+ readonly record: <V>(valueSchema: Schema<V>) => RecordSchema<V>;
191
+ readonly map: <K, V>(keySchema: Schema<K>, valueSchema: Schema<V>) => MapSchema<K, V>;
192
+ readonly set: <T>(itemSchema: Schema<T>) => SetSchema<T>;
193
+ readonly date: () => DateSchema;
194
+ readonly literal: <T extends string | number | boolean | null | undefined>(value: T) => LiteralSchema<T>;
195
+ readonly any: () => AnySchema;
196
+ readonly unknown: () => UnknownSchema;
197
+ readonly coerce: {
198
+ readonly string: () => CoerceStringSchema;
199
+ readonly number: () => CoerceNumberSchema;
200
+ readonly boolean: () => CoerceBooleanSchema;
201
+ readonly date: () => CoerceDateSchema;
202
+ };
203
+ readonly transform: <T>(fn: (value: unknown) => T) => StandaloneTransformSchema<T>;
204
+ };
205
+ /** @deprecated Use `schema` instead. Will be removed in v1.0.0 */
194
206
  declare const s: {
195
207
  readonly string: () => StringSchema;
196
208
  readonly number: () => NumberSchema;
@@ -213,12 +225,6 @@ declare const s: {
213
225
  readonly literal: <T extends string | number | boolean | null | undefined>(value: T) => LiteralSchema<T>;
214
226
  readonly any: () => AnySchema;
215
227
  readonly unknown: () => UnknownSchema;
216
- readonly nik: () => NIKSchema;
217
- readonly npwp: () => NPWPSchema;
218
- readonly phone: () => PhoneSchema;
219
- readonly alamat: () => AlamatSchema;
220
- readonly kodepos: () => KodeposSchema;
221
- readonly rekening: () => RekeningSchema;
222
228
  readonly coerce: {
223
229
  readonly string: () => CoerceStringSchema;
224
230
  readonly number: () => CoerceNumberSchema;
@@ -228,4 +234,4 @@ declare const s: {
228
234
  readonly transform: <T>(fn: (value: unknown) => T) => StandaloneTransformSchema<T>;
229
235
  };
230
236
 
231
- export { AlamatSchema, AnySchema, ArraySchema, BigIntSchema, BooleanSchema, CoerceBooleanSchema, CoerceDateSchema, CoerceNumberSchema, CoerceStringSchema, DateSchema, EnumSchema, Infer, IntersectionSchema, KodeposSchema, LiteralSchema, MapSchema, NIKSchema, NPWPSchema, NaNSchema, NullSchema, NumberSchema, ObjectSchema, PhoneSchema, RecordSchema, RekeningSchema, Schema, SetSchema, StringSchema, SymbolSchema, TupleSchema, UndefinedSchema, UnionSchema, UnknownSchema, getLocale, s, setLocale };
237
+ export { AnySchema, ArraySchema, BigIntSchema, BooleanSchema, CoerceBooleanSchema, CoerceDateSchema, CoerceNumberSchema, CoerceStringSchema, DateSchema, EnumSchema, Infer, IntersectionSchema, LiteralSchema, MapSchema, NaNSchema, NullSchema, NumberSchema, ObjectSchema, RecordSchema, Schema, SetSchema, StringSchema, SymbolSchema, TupleSchema, UndefinedSchema, UnionSchema, UnknownSchema, getLocale, s, schema, setLocale };
@@ -1,61 +1,4 @@
1
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
2
  var EN = {
60
3
  required: "Value is required",
61
4
  type_string: "Expected a string",
@@ -101,18 +44,12 @@ var EN = {
101
44
  refine_fail: "{message}",
102
45
  date_invalid: "Invalid date",
103
46
  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
47
  coerce_number_fail: "Value cannot be coerced to a number",
111
48
  coerce_date_fail: "Value cannot be coerced to a date",
112
49
  map_not_map: "Expected a Map",
113
50
  set_not_set: "Expected a Set"
114
51
  };
115
- var store = { ...ID };
52
+ var store = { ...EN };
116
53
  function msg(key, params) {
117
54
  let template = store[key];
118
55
  if (!template) return key;
@@ -123,9 +60,8 @@ function msg(key, params) {
123
60
  }
124
61
  return template;
125
62
  }
126
- function setLocale(locale) {
127
- currentLocale = locale;
128
- const source = locale === "id" ? ID : EN;
63
+ function setLocale(_locale) {
64
+ const source = EN;
129
65
  for (const key in source) {
130
66
  if (Object.prototype.hasOwnProperty.call(source, key)) {
131
67
  store[key] = source[key];
@@ -133,7 +69,7 @@ function setLocale(locale) {
133
69
  }
134
70
  }
135
71
  function getLocale() {
136
- return currentLocale;
72
+ return "en";
137
73
  }
138
74
 
139
75
  // src/schema/types.ts
@@ -183,7 +119,7 @@ var Schema = class {
183
119
  transform(fn) {
184
120
  return new TransformSchema(this, fn);
185
121
  }
186
- /** @internal used by s.enum() etc */
122
+ /** @internal used by schema.enum() etc */
187
123
  get _internal() {
188
124
  return this;
189
125
  }
@@ -561,9 +497,9 @@ var ObjectSchema = class _ObjectSchema extends Schema {
561
497
  const result = {};
562
498
  for (const key in this.shape) {
563
499
  if (Object.prototype.hasOwnProperty.call(this.shape, key)) {
564
- const schema = this.shape[key];
500
+ const schema2 = this.shape[key];
565
501
  try {
566
- result[key] = schema._parse(obj[key]);
502
+ result[key] = schema2._parse(obj[key]);
567
503
  } catch (e) {
568
504
  if (e instanceof SchemaError) {
569
505
  throw new SchemaError(e.message, {
@@ -706,9 +642,9 @@ var UnionSchema = class extends Schema {
706
642
  schemas;
707
643
  _parse(value) {
708
644
  const errors = [];
709
- for (const schema of this.schemas) {
645
+ for (const schema2 of this.schemas) {
710
646
  try {
711
- return schema._parse(value);
647
+ return schema2._parse(value);
712
648
  } catch (e) {
713
649
  errors.push(e instanceof SchemaError ? e.message : String(e));
714
650
  }
@@ -826,136 +762,6 @@ var UnknownSchema = class extends Schema {
826
762
  }
827
763
  };
828
764
 
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
765
  // src/schema/transform.ts
960
766
  var CoerceStringSchema = class extends Schema {
961
767
  _parse(value) {
@@ -1016,7 +822,7 @@ var StandaloneTransformSchema = class extends Schema {
1016
822
  };
1017
823
 
1018
824
  // src/schema/index.ts
1019
- var s = {
825
+ var schema = {
1020
826
  string() {
1021
827
  return new StringSchema();
1022
828
  },
@@ -1080,25 +886,6 @@ var s = {
1080
886
  unknown() {
1081
887
  return new UnknownSchema();
1082
888
  },
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
889
  // ─── Coerce ─────────────────────────────────────────────
1103
890
  coerce: {
1104
891
  string() {
@@ -1119,8 +906,8 @@ var s = {
1119
906
  return new StandaloneTransformSchema(fn);
1120
907
  }
1121
908
  };
909
+ var s = schema;
1122
910
  export {
1123
- AlamatSchema,
1124
911
  AnySchema,
1125
912
  ArraySchema,
1126
913
  BigIntSchema,
@@ -1132,18 +919,13 @@ export {
1132
919
  DateSchema,
1133
920
  EnumSchema,
1134
921
  IntersectionSchema,
1135
- KodeposSchema,
1136
922
  LiteralSchema,
1137
923
  MapSchema,
1138
- NIKSchema,
1139
- NPWPSchema,
1140
924
  NaNSchema,
1141
925
  NullSchema,
1142
926
  NumberSchema,
1143
927
  ObjectSchema,
1144
- PhoneSchema,
1145
928
  RecordSchema,
1146
- RekeningSchema,
1147
929
  Schema,
1148
930
  SchemaError,
1149
931
  SetSchema,
@@ -1155,6 +937,7 @@ export {
1155
937
  UnknownSchema,
1156
938
  getLocale,
1157
939
  s,
940
+ schema,
1158
941
  setLocale
1159
942
  };
1160
943
  //# sourceMappingURL=index.js.map