@kakilangit/id-generator 0.1.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.
@@ -0,0 +1,181 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Decoded ID result for JavaScript.
6
+ */
7
+ export class JsDecodedId {
8
+ private constructor();
9
+ free(): void;
10
+ [Symbol.dispose](): void;
11
+ /**
12
+ * Full ID as bytes (as comma-separated string for JS).
13
+ */
14
+ bytes: string;
15
+ /**
16
+ * The detected format name.
17
+ */
18
+ format: string;
19
+ /**
20
+ * Full ID as hex string.
21
+ */
22
+ hex: string;
23
+ /**
24
+ * The original ID string.
25
+ */
26
+ original: string;
27
+ /**
28
+ * Random component as string (decimal).
29
+ */
30
+ get randomness(): string | undefined;
31
+ /**
32
+ * Random component as string (decimal).
33
+ */
34
+ set randomness(value: string | null | undefined);
35
+ /**
36
+ * RFC 3339 formatted time string with timezone (if applicable).
37
+ */
38
+ get time(): string | undefined;
39
+ /**
40
+ * RFC 3339 formatted time string with timezone (if applicable).
41
+ */
42
+ set time(value: string | null | undefined);
43
+ /**
44
+ * Timestamp (if applicable).
45
+ */
46
+ get timestamp(): JsTimestamp | undefined;
47
+ /**
48
+ * Timestamp (if applicable).
49
+ */
50
+ set timestamp(value: JsTimestamp | null | undefined);
51
+ }
52
+
53
+ /**
54
+ * Case format options for JavaScript.
55
+ */
56
+ export enum JsIdCase {
57
+ /**
58
+ * Lowercase output.
59
+ */
60
+ Lower = 0,
61
+ /**
62
+ * Uppercase output.
63
+ */
64
+ Upper = 1,
65
+ }
66
+
67
+ /**
68
+ * ID format options for JavaScript.
69
+ */
70
+ export enum JsIdFormat {
71
+ /**
72
+ * UUID version 4 (random).
73
+ */
74
+ UuidV4 = 0,
75
+ /**
76
+ * UUID version 7 (time-based).
77
+ */
78
+ UuidV7 = 1,
79
+ /**
80
+ * NULID (Nanosecond-precision Universally Lexicographically Sortable Identifier).
81
+ */
82
+ Nulid = 2,
83
+ }
84
+
85
+ /**
86
+ * Timestamp precision for JavaScript.
87
+ */
88
+ export class JsTimestamp {
89
+ private constructor();
90
+ free(): void;
91
+ [Symbol.dispose](): void;
92
+ /**
93
+ * Precision type: "ms" for milliseconds, "ns" for nanoseconds.
94
+ */
95
+ precision: string;
96
+ /**
97
+ * Timestamp value as string (to support u128 for nanoseconds).
98
+ */
99
+ value: string;
100
+ }
101
+
102
+ /**
103
+ * Decodes an ID string and returns its metadata.
104
+ *
105
+ * # Errors
106
+ *
107
+ * Returns an error string if the ID format is not recognized.
108
+ */
109
+ export function decode_id(id: string): JsDecodedId;
110
+
111
+ /**
112
+ * Generates IDs based on the specified format, count, and case.
113
+ *
114
+ * Returns a JavaScript array of ID strings.
115
+ *
116
+ * # Errors
117
+ *
118
+ * Returns an error string if generation fails (e.g., invalid count).
119
+ */
120
+ export function generate_ids(format: JsIdFormat, count: number, _case: JsIdCase): string[];
121
+
122
+ /**
123
+ * Returns all available ID format names.
124
+ */
125
+ export function get_available_formats(): string[];
126
+
127
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
128
+
129
+ export interface InitOutput {
130
+ readonly memory: WebAssembly.Memory;
131
+ readonly __wbg_get_jsdecodedid_bytes: (a: number, b: number) => void;
132
+ readonly __wbg_get_jsdecodedid_format: (a: number, b: number) => void;
133
+ readonly __wbg_get_jsdecodedid_hex: (a: number, b: number) => void;
134
+ readonly __wbg_get_jsdecodedid_original: (a: number, b: number) => void;
135
+ readonly __wbg_get_jsdecodedid_randomness: (a: number, b: number) => void;
136
+ readonly __wbg_get_jsdecodedid_time: (a: number, b: number) => void;
137
+ readonly __wbg_get_jsdecodedid_timestamp: (a: number) => number;
138
+ readonly __wbg_jsdecodedid_free: (a: number, b: number) => void;
139
+ readonly __wbg_jstimestamp_free: (a: number, b: number) => void;
140
+ readonly __wbg_set_jsdecodedid_bytes: (a: number, b: number, c: number) => void;
141
+ readonly __wbg_set_jsdecodedid_format: (a: number, b: number, c: number) => void;
142
+ readonly __wbg_set_jsdecodedid_hex: (a: number, b: number, c: number) => void;
143
+ readonly __wbg_set_jsdecodedid_original: (a: number, b: number, c: number) => void;
144
+ readonly __wbg_set_jsdecodedid_randomness: (a: number, b: number, c: number) => void;
145
+ readonly __wbg_set_jsdecodedid_time: (a: number, b: number, c: number) => void;
146
+ readonly __wbg_set_jsdecodedid_timestamp: (a: number, b: number) => void;
147
+ readonly decode_id: (a: number, b: number, c: number) => void;
148
+ readonly generate_ids: (a: number, b: number, c: number, d: number) => void;
149
+ readonly get_available_formats: (a: number) => void;
150
+ readonly __wbg_set_jstimestamp_value: (a: number, b: number, c: number) => void;
151
+ readonly __wbg_set_jstimestamp_precision: (a: number, b: number, c: number) => void;
152
+ readonly __wbg_get_jstimestamp_value: (a: number, b: number) => void;
153
+ readonly __wbg_get_jstimestamp_precision: (a: number, b: number) => void;
154
+ readonly __wbindgen_export: (a: number) => void;
155
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
156
+ readonly __wbindgen_export2: (a: number, b: number) => number;
157
+ readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
158
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
159
+ }
160
+
161
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
162
+
163
+ /**
164
+ * Instantiates the given `module`, which can either be bytes or
165
+ * a precompiled `WebAssembly.Module`.
166
+ *
167
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
168
+ *
169
+ * @returns {InitOutput}
170
+ */
171
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
172
+
173
+ /**
174
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
175
+ * for everything else, calls `WebAssembly.instantiate` directly.
176
+ *
177
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
178
+ *
179
+ * @returns {Promise<InitOutput>}
180
+ */
181
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,734 @@
1
+ /* @ts-self-types="./id_generator.d.ts" */
2
+
3
+ /**
4
+ * Decoded ID result for JavaScript.
5
+ */
6
+ export class JsDecodedId {
7
+ static __wrap(ptr) {
8
+ ptr = ptr >>> 0;
9
+ const obj = Object.create(JsDecodedId.prototype);
10
+ obj.__wbg_ptr = ptr;
11
+ JsDecodedIdFinalization.register(obj, obj.__wbg_ptr, obj);
12
+ return obj;
13
+ }
14
+ __destroy_into_raw() {
15
+ const ptr = this.__wbg_ptr;
16
+ this.__wbg_ptr = 0;
17
+ JsDecodedIdFinalization.unregister(this);
18
+ return ptr;
19
+ }
20
+ free() {
21
+ const ptr = this.__destroy_into_raw();
22
+ wasm.__wbg_jsdecodedid_free(ptr, 0);
23
+ }
24
+ /**
25
+ * Full ID as bytes (as comma-separated string for JS).
26
+ * @returns {string}
27
+ */
28
+ get bytes() {
29
+ let deferred1_0;
30
+ let deferred1_1;
31
+ try {
32
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
33
+ wasm.__wbg_get_jsdecodedid_bytes(retptr, this.__wbg_ptr);
34
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
35
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
36
+ deferred1_0 = r0;
37
+ deferred1_1 = r1;
38
+ return getStringFromWasm0(r0, r1);
39
+ } finally {
40
+ wasm.__wbindgen_add_to_stack_pointer(16);
41
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
42
+ }
43
+ }
44
+ /**
45
+ * The detected format name.
46
+ * @returns {string}
47
+ */
48
+ get format() {
49
+ let deferred1_0;
50
+ let deferred1_1;
51
+ try {
52
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
53
+ wasm.__wbg_get_jsdecodedid_format(retptr, this.__wbg_ptr);
54
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
55
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
56
+ deferred1_0 = r0;
57
+ deferred1_1 = r1;
58
+ return getStringFromWasm0(r0, r1);
59
+ } finally {
60
+ wasm.__wbindgen_add_to_stack_pointer(16);
61
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
62
+ }
63
+ }
64
+ /**
65
+ * Full ID as hex string.
66
+ * @returns {string}
67
+ */
68
+ get hex() {
69
+ let deferred1_0;
70
+ let deferred1_1;
71
+ try {
72
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
73
+ wasm.__wbg_get_jsdecodedid_hex(retptr, this.__wbg_ptr);
74
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
75
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
76
+ deferred1_0 = r0;
77
+ deferred1_1 = r1;
78
+ return getStringFromWasm0(r0, r1);
79
+ } finally {
80
+ wasm.__wbindgen_add_to_stack_pointer(16);
81
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
82
+ }
83
+ }
84
+ /**
85
+ * The original ID string.
86
+ * @returns {string}
87
+ */
88
+ get original() {
89
+ let deferred1_0;
90
+ let deferred1_1;
91
+ try {
92
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
93
+ wasm.__wbg_get_jsdecodedid_original(retptr, this.__wbg_ptr);
94
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
95
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
96
+ deferred1_0 = r0;
97
+ deferred1_1 = r1;
98
+ return getStringFromWasm0(r0, r1);
99
+ } finally {
100
+ wasm.__wbindgen_add_to_stack_pointer(16);
101
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
102
+ }
103
+ }
104
+ /**
105
+ * Random component as string (decimal).
106
+ * @returns {string | undefined}
107
+ */
108
+ get randomness() {
109
+ try {
110
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
111
+ wasm.__wbg_get_jsdecodedid_randomness(retptr, this.__wbg_ptr);
112
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
113
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
114
+ let v1;
115
+ if (r0 !== 0) {
116
+ v1 = getStringFromWasm0(r0, r1).slice();
117
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
118
+ }
119
+ return v1;
120
+ } finally {
121
+ wasm.__wbindgen_add_to_stack_pointer(16);
122
+ }
123
+ }
124
+ /**
125
+ * RFC 3339 formatted time string with timezone (if applicable).
126
+ * @returns {string | undefined}
127
+ */
128
+ get time() {
129
+ try {
130
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
131
+ wasm.__wbg_get_jsdecodedid_time(retptr, this.__wbg_ptr);
132
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
133
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
134
+ let v1;
135
+ if (r0 !== 0) {
136
+ v1 = getStringFromWasm0(r0, r1).slice();
137
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
138
+ }
139
+ return v1;
140
+ } finally {
141
+ wasm.__wbindgen_add_to_stack_pointer(16);
142
+ }
143
+ }
144
+ /**
145
+ * Timestamp (if applicable).
146
+ * @returns {JsTimestamp | undefined}
147
+ */
148
+ get timestamp() {
149
+ const ret = wasm.__wbg_get_jsdecodedid_timestamp(this.__wbg_ptr);
150
+ return ret === 0 ? undefined : JsTimestamp.__wrap(ret);
151
+ }
152
+ /**
153
+ * Full ID as bytes (as comma-separated string for JS).
154
+ * @param {string} arg0
155
+ */
156
+ set bytes(arg0) {
157
+ const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
158
+ const len0 = WASM_VECTOR_LEN;
159
+ wasm.__wbg_set_jsdecodedid_bytes(this.__wbg_ptr, ptr0, len0);
160
+ }
161
+ /**
162
+ * The detected format name.
163
+ * @param {string} arg0
164
+ */
165
+ set format(arg0) {
166
+ const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
167
+ const len0 = WASM_VECTOR_LEN;
168
+ wasm.__wbg_set_jsdecodedid_format(this.__wbg_ptr, ptr0, len0);
169
+ }
170
+ /**
171
+ * Full ID as hex string.
172
+ * @param {string} arg0
173
+ */
174
+ set hex(arg0) {
175
+ const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
176
+ const len0 = WASM_VECTOR_LEN;
177
+ wasm.__wbg_set_jsdecodedid_hex(this.__wbg_ptr, ptr0, len0);
178
+ }
179
+ /**
180
+ * The original ID string.
181
+ * @param {string} arg0
182
+ */
183
+ set original(arg0) {
184
+ const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
185
+ const len0 = WASM_VECTOR_LEN;
186
+ wasm.__wbg_set_jsdecodedid_original(this.__wbg_ptr, ptr0, len0);
187
+ }
188
+ /**
189
+ * Random component as string (decimal).
190
+ * @param {string | null} [arg0]
191
+ */
192
+ set randomness(arg0) {
193
+ var ptr0 = isLikeNone(arg0) ? 0 : passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
194
+ var len0 = WASM_VECTOR_LEN;
195
+ wasm.__wbg_set_jsdecodedid_randomness(this.__wbg_ptr, ptr0, len0);
196
+ }
197
+ /**
198
+ * RFC 3339 formatted time string with timezone (if applicable).
199
+ * @param {string | null} [arg0]
200
+ */
201
+ set time(arg0) {
202
+ var ptr0 = isLikeNone(arg0) ? 0 : passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
203
+ var len0 = WASM_VECTOR_LEN;
204
+ wasm.__wbg_set_jsdecodedid_time(this.__wbg_ptr, ptr0, len0);
205
+ }
206
+ /**
207
+ * Timestamp (if applicable).
208
+ * @param {JsTimestamp | null} [arg0]
209
+ */
210
+ set timestamp(arg0) {
211
+ let ptr0 = 0;
212
+ if (!isLikeNone(arg0)) {
213
+ _assertClass(arg0, JsTimestamp);
214
+ ptr0 = arg0.__destroy_into_raw();
215
+ }
216
+ wasm.__wbg_set_jsdecodedid_timestamp(this.__wbg_ptr, ptr0);
217
+ }
218
+ }
219
+ if (Symbol.dispose) JsDecodedId.prototype[Symbol.dispose] = JsDecodedId.prototype.free;
220
+
221
+ /**
222
+ * Case format options for JavaScript.
223
+ * @enum {0 | 1}
224
+ */
225
+ export const JsIdCase = Object.freeze({
226
+ /**
227
+ * Lowercase output.
228
+ */
229
+ Lower: 0, "0": "Lower",
230
+ /**
231
+ * Uppercase output.
232
+ */
233
+ Upper: 1, "1": "Upper",
234
+ });
235
+
236
+ /**
237
+ * ID format options for JavaScript.
238
+ * @enum {0 | 1 | 2}
239
+ */
240
+ export const JsIdFormat = Object.freeze({
241
+ /**
242
+ * UUID version 4 (random).
243
+ */
244
+ UuidV4: 0, "0": "UuidV4",
245
+ /**
246
+ * UUID version 7 (time-based).
247
+ */
248
+ UuidV7: 1, "1": "UuidV7",
249
+ /**
250
+ * NULID (Nanosecond-precision Universally Lexicographically Sortable Identifier).
251
+ */
252
+ Nulid: 2, "2": "Nulid",
253
+ });
254
+
255
+ /**
256
+ * Timestamp precision for JavaScript.
257
+ */
258
+ export class JsTimestamp {
259
+ static __wrap(ptr) {
260
+ ptr = ptr >>> 0;
261
+ const obj = Object.create(JsTimestamp.prototype);
262
+ obj.__wbg_ptr = ptr;
263
+ JsTimestampFinalization.register(obj, obj.__wbg_ptr, obj);
264
+ return obj;
265
+ }
266
+ __destroy_into_raw() {
267
+ const ptr = this.__wbg_ptr;
268
+ this.__wbg_ptr = 0;
269
+ JsTimestampFinalization.unregister(this);
270
+ return ptr;
271
+ }
272
+ free() {
273
+ const ptr = this.__destroy_into_raw();
274
+ wasm.__wbg_jstimestamp_free(ptr, 0);
275
+ }
276
+ /**
277
+ * Precision type: "ms" for milliseconds, "ns" for nanoseconds.
278
+ * @returns {string}
279
+ */
280
+ get precision() {
281
+ let deferred1_0;
282
+ let deferred1_1;
283
+ try {
284
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
285
+ wasm.__wbg_get_jsdecodedid_original(retptr, this.__wbg_ptr);
286
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
287
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
288
+ deferred1_0 = r0;
289
+ deferred1_1 = r1;
290
+ return getStringFromWasm0(r0, r1);
291
+ } finally {
292
+ wasm.__wbindgen_add_to_stack_pointer(16);
293
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
294
+ }
295
+ }
296
+ /**
297
+ * Timestamp value as string (to support u128 for nanoseconds).
298
+ * @returns {string}
299
+ */
300
+ get value() {
301
+ let deferred1_0;
302
+ let deferred1_1;
303
+ try {
304
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
305
+ wasm.__wbg_get_jsdecodedid_format(retptr, this.__wbg_ptr);
306
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
307
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
308
+ deferred1_0 = r0;
309
+ deferred1_1 = r1;
310
+ return getStringFromWasm0(r0, r1);
311
+ } finally {
312
+ wasm.__wbindgen_add_to_stack_pointer(16);
313
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
314
+ }
315
+ }
316
+ /**
317
+ * Precision type: "ms" for milliseconds, "ns" for nanoseconds.
318
+ * @param {string} arg0
319
+ */
320
+ set precision(arg0) {
321
+ const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
322
+ const len0 = WASM_VECTOR_LEN;
323
+ wasm.__wbg_set_jsdecodedid_original(this.__wbg_ptr, ptr0, len0);
324
+ }
325
+ /**
326
+ * Timestamp value as string (to support u128 for nanoseconds).
327
+ * @param {string} arg0
328
+ */
329
+ set value(arg0) {
330
+ const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
331
+ const len0 = WASM_VECTOR_LEN;
332
+ wasm.__wbg_set_jsdecodedid_format(this.__wbg_ptr, ptr0, len0);
333
+ }
334
+ }
335
+ if (Symbol.dispose) JsTimestamp.prototype[Symbol.dispose] = JsTimestamp.prototype.free;
336
+
337
+ /**
338
+ * Decodes an ID string and returns its metadata.
339
+ *
340
+ * # Errors
341
+ *
342
+ * Returns an error string if the ID format is not recognized.
343
+ * @param {string} id
344
+ * @returns {JsDecodedId}
345
+ */
346
+ export function decode_id(id) {
347
+ try {
348
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
349
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
350
+ const len0 = WASM_VECTOR_LEN;
351
+ wasm.decode_id(retptr, ptr0, len0);
352
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
353
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
354
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
355
+ if (r2) {
356
+ throw takeObject(r1);
357
+ }
358
+ return JsDecodedId.__wrap(r0);
359
+ } finally {
360
+ wasm.__wbindgen_add_to_stack_pointer(16);
361
+ }
362
+ }
363
+
364
+ /**
365
+ * Generates IDs based on the specified format, count, and case.
366
+ *
367
+ * Returns a JavaScript array of ID strings.
368
+ *
369
+ * # Errors
370
+ *
371
+ * Returns an error string if generation fails (e.g., invalid count).
372
+ * @param {JsIdFormat} format
373
+ * @param {number} count
374
+ * @param {JsIdCase} _case
375
+ * @returns {string[]}
376
+ */
377
+ export function generate_ids(format, count, _case) {
378
+ try {
379
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
380
+ wasm.generate_ids(retptr, format, count, _case);
381
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
382
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
383
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
384
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
385
+ if (r3) {
386
+ throw takeObject(r2);
387
+ }
388
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
389
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
390
+ return v1;
391
+ } finally {
392
+ wasm.__wbindgen_add_to_stack_pointer(16);
393
+ }
394
+ }
395
+
396
+ /**
397
+ * Returns all available ID format names.
398
+ * @returns {string[]}
399
+ */
400
+ export function get_available_formats() {
401
+ try {
402
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
403
+ wasm.get_available_formats(retptr);
404
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
405
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
406
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
407
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
408
+ return v1;
409
+ } finally {
410
+ wasm.__wbindgen_add_to_stack_pointer(16);
411
+ }
412
+ }
413
+
414
+ function __wbg_get_imports() {
415
+ const import0 = {
416
+ __proto__: null,
417
+ __wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
418
+ const ret = getObject(arg0) === undefined;
419
+ return ret;
420
+ },
421
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
422
+ throw new Error(getStringFromWasm0(arg0, arg1));
423
+ },
424
+ __wbg_call_389efe28435a9388: function() { return handleError(function (arg0, arg1) {
425
+ const ret = getObject(arg0).call(getObject(arg1));
426
+ return addHeapObject(ret);
427
+ }, arguments); },
428
+ __wbg_getRandomValues_1c61fac11405ffdc: function() { return handleError(function (arg0, arg1) {
429
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
430
+ }, arguments); },
431
+ __wbg_getRandomValues_9c5c1b115e142bb8: function() { return handleError(function (arg0, arg1) {
432
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
433
+ }, arguments); },
434
+ __wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
435
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
436
+ return addHeapObject(ret);
437
+ },
438
+ __wbg_now_2c95c9de01293173: function(arg0) {
439
+ const ret = getObject(arg0).now();
440
+ return ret;
441
+ },
442
+ __wbg_now_59d5a9197dfbe39f: function() { return handleError(function () {
443
+ const ret = Date.now();
444
+ return ret;
445
+ }, arguments); },
446
+ __wbg_now_a3af9a2f4bbaa4d1: function() {
447
+ const ret = Date.now();
448
+ return ret;
449
+ },
450
+ __wbg_performance_7a3ffd0b17f663ad: function(arg0) {
451
+ const ret = getObject(arg0).performance;
452
+ return addHeapObject(ret);
453
+ },
454
+ __wbg_static_accessor_GLOBAL_12837167ad935116: function() {
455
+ const ret = typeof global === 'undefined' ? null : global;
456
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
457
+ },
458
+ __wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function() {
459
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
460
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
461
+ },
462
+ __wbg_static_accessor_SELF_a621d3dfbb60d0ce: function() {
463
+ const ret = typeof self === 'undefined' ? null : self;
464
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
465
+ },
466
+ __wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function() {
467
+ const ret = typeof window === 'undefined' ? null : window;
468
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
469
+ },
470
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
471
+ // Cast intrinsic for `Ref(String) -> Externref`.
472
+ const ret = getStringFromWasm0(arg0, arg1);
473
+ return addHeapObject(ret);
474
+ },
475
+ __wbindgen_object_clone_ref: function(arg0) {
476
+ const ret = getObject(arg0);
477
+ return addHeapObject(ret);
478
+ },
479
+ __wbindgen_object_drop_ref: function(arg0) {
480
+ takeObject(arg0);
481
+ },
482
+ };
483
+ return {
484
+ __proto__: null,
485
+ "./id_generator_bg.js": import0,
486
+ };
487
+ }
488
+
489
+ const JsDecodedIdFinalization = (typeof FinalizationRegistry === 'undefined')
490
+ ? { register: () => {}, unregister: () => {} }
491
+ : new FinalizationRegistry(ptr => wasm.__wbg_jsdecodedid_free(ptr >>> 0, 1));
492
+ const JsTimestampFinalization = (typeof FinalizationRegistry === 'undefined')
493
+ ? { register: () => {}, unregister: () => {} }
494
+ : new FinalizationRegistry(ptr => wasm.__wbg_jstimestamp_free(ptr >>> 0, 1));
495
+
496
+ function addHeapObject(obj) {
497
+ if (heap_next === heap.length) heap.push(heap.length + 1);
498
+ const idx = heap_next;
499
+ heap_next = heap[idx];
500
+
501
+ heap[idx] = obj;
502
+ return idx;
503
+ }
504
+
505
+ function _assertClass(instance, klass) {
506
+ if (!(instance instanceof klass)) {
507
+ throw new Error(`expected instance of ${klass.name}`);
508
+ }
509
+ }
510
+
511
+ function dropObject(idx) {
512
+ if (idx < 132) return;
513
+ heap[idx] = heap_next;
514
+ heap_next = idx;
515
+ }
516
+
517
+ function getArrayJsValueFromWasm0(ptr, len) {
518
+ ptr = ptr >>> 0;
519
+ const mem = getDataViewMemory0();
520
+ const result = [];
521
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
522
+ result.push(takeObject(mem.getUint32(i, true)));
523
+ }
524
+ return result;
525
+ }
526
+
527
+ function getArrayU8FromWasm0(ptr, len) {
528
+ ptr = ptr >>> 0;
529
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
530
+ }
531
+
532
+ let cachedDataViewMemory0 = null;
533
+ function getDataViewMemory0() {
534
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
535
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
536
+ }
537
+ return cachedDataViewMemory0;
538
+ }
539
+
540
+ function getStringFromWasm0(ptr, len) {
541
+ ptr = ptr >>> 0;
542
+ return decodeText(ptr, len);
543
+ }
544
+
545
+ let cachedUint8ArrayMemory0 = null;
546
+ function getUint8ArrayMemory0() {
547
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
548
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
549
+ }
550
+ return cachedUint8ArrayMemory0;
551
+ }
552
+
553
+ function getObject(idx) { return heap[idx]; }
554
+
555
+ function handleError(f, args) {
556
+ try {
557
+ return f.apply(this, args);
558
+ } catch (e) {
559
+ wasm.__wbindgen_export(addHeapObject(e));
560
+ }
561
+ }
562
+
563
+ let heap = new Array(128).fill(undefined);
564
+ heap.push(undefined, null, true, false);
565
+
566
+ let heap_next = heap.length;
567
+
568
+ function isLikeNone(x) {
569
+ return x === undefined || x === null;
570
+ }
571
+
572
+ function passStringToWasm0(arg, malloc, realloc) {
573
+ if (realloc === undefined) {
574
+ const buf = cachedTextEncoder.encode(arg);
575
+ const ptr = malloc(buf.length, 1) >>> 0;
576
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
577
+ WASM_VECTOR_LEN = buf.length;
578
+ return ptr;
579
+ }
580
+
581
+ let len = arg.length;
582
+ let ptr = malloc(len, 1) >>> 0;
583
+
584
+ const mem = getUint8ArrayMemory0();
585
+
586
+ let offset = 0;
587
+
588
+ for (; offset < len; offset++) {
589
+ const code = arg.charCodeAt(offset);
590
+ if (code > 0x7F) break;
591
+ mem[ptr + offset] = code;
592
+ }
593
+ if (offset !== len) {
594
+ if (offset !== 0) {
595
+ arg = arg.slice(offset);
596
+ }
597
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
598
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
599
+ const ret = cachedTextEncoder.encodeInto(arg, view);
600
+
601
+ offset += ret.written;
602
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
603
+ }
604
+
605
+ WASM_VECTOR_LEN = offset;
606
+ return ptr;
607
+ }
608
+
609
+ function takeObject(idx) {
610
+ const ret = getObject(idx);
611
+ dropObject(idx);
612
+ return ret;
613
+ }
614
+
615
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
616
+ cachedTextDecoder.decode();
617
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
618
+ let numBytesDecoded = 0;
619
+ function decodeText(ptr, len) {
620
+ numBytesDecoded += len;
621
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
622
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
623
+ cachedTextDecoder.decode();
624
+ numBytesDecoded = len;
625
+ }
626
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
627
+ }
628
+
629
+ const cachedTextEncoder = new TextEncoder();
630
+
631
+ if (!('encodeInto' in cachedTextEncoder)) {
632
+ cachedTextEncoder.encodeInto = function (arg, view) {
633
+ const buf = cachedTextEncoder.encode(arg);
634
+ view.set(buf);
635
+ return {
636
+ read: arg.length,
637
+ written: buf.length
638
+ };
639
+ };
640
+ }
641
+
642
+ let WASM_VECTOR_LEN = 0;
643
+
644
+ let wasmModule, wasm;
645
+ function __wbg_finalize_init(instance, module) {
646
+ wasm = instance.exports;
647
+ wasmModule = module;
648
+ cachedDataViewMemory0 = null;
649
+ cachedUint8ArrayMemory0 = null;
650
+ return wasm;
651
+ }
652
+
653
+ async function __wbg_load(module, imports) {
654
+ if (typeof Response === 'function' && module instanceof Response) {
655
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
656
+ try {
657
+ return await WebAssembly.instantiateStreaming(module, imports);
658
+ } catch (e) {
659
+ const validResponse = module.ok && expectedResponseType(module.type);
660
+
661
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
662
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
663
+
664
+ } else { throw e; }
665
+ }
666
+ }
667
+
668
+ const bytes = await module.arrayBuffer();
669
+ return await WebAssembly.instantiate(bytes, imports);
670
+ } else {
671
+ const instance = await WebAssembly.instantiate(module, imports);
672
+
673
+ if (instance instanceof WebAssembly.Instance) {
674
+ return { instance, module };
675
+ } else {
676
+ return instance;
677
+ }
678
+ }
679
+
680
+ function expectedResponseType(type) {
681
+ switch (type) {
682
+ case 'basic': case 'cors': case 'default': return true;
683
+ }
684
+ return false;
685
+ }
686
+ }
687
+
688
+ function initSync(module) {
689
+ if (wasm !== undefined) return wasm;
690
+
691
+
692
+ if (module !== undefined) {
693
+ if (Object.getPrototypeOf(module) === Object.prototype) {
694
+ ({module} = module)
695
+ } else {
696
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
697
+ }
698
+ }
699
+
700
+ const imports = __wbg_get_imports();
701
+ if (!(module instanceof WebAssembly.Module)) {
702
+ module = new WebAssembly.Module(module);
703
+ }
704
+ const instance = new WebAssembly.Instance(module, imports);
705
+ return __wbg_finalize_init(instance, module);
706
+ }
707
+
708
+ async function __wbg_init(module_or_path) {
709
+ if (wasm !== undefined) return wasm;
710
+
711
+
712
+ if (module_or_path !== undefined) {
713
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
714
+ ({module_or_path} = module_or_path)
715
+ } else {
716
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
717
+ }
718
+ }
719
+
720
+ if (module_or_path === undefined) {
721
+ module_or_path = new URL('id_generator_bg.wasm', import.meta.url);
722
+ }
723
+ const imports = __wbg_get_imports();
724
+
725
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
726
+ module_or_path = fetch(module_or_path);
727
+ }
728
+
729
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
730
+
731
+ return __wbg_finalize_init(instance, module);
732
+ }
733
+
734
+ export { initSync, __wbg_init as default };
Binary file
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@kakilangit/id-generator",
3
+ "version": "0.1.0",
4
+ "description": "WebAssembly bindings for ID Generator tool (UUID v4, UUID v7, NULID)",
5
+ "type": "module",
6
+ "main": "id_generator.js",
7
+ "types": "id_generator.d.ts",
8
+ "files": [
9
+ "id_generator_bg.wasm",
10
+ "id_generator.js",
11
+ "id_generator.d.ts"
12
+ ],
13
+ "keywords": [
14
+ "wasm",
15
+ "webassembly",
16
+ "rust",
17
+ "id-generator",
18
+ "uuid",
19
+ "uuid-v4",
20
+ "uuid-v7",
21
+ "nulid"
22
+ ],
23
+ "author": "kakilangit",
24
+ "license": "MIT",
25
+ "homepage": "https://dev.kakilangit.com"
26
+ }