@kakilangit/id-generator 0.1.0 → 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.
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # @kakilangit/id-generator
2
+
3
+ WebAssembly bindings for ID Generator tool - Generate UUID, NULID, and NanoID identifiers.
4
+
5
+ ## Overview
6
+
7
+ This package provides fast ID generation and decoding functionality compiled to WebAssembly from Rust. It supports:
8
+
9
+ - **UUID v1** (time-based) - Time-based with MAC address
10
+ - **UUID v4** (random) - Randomly generated UUIDs
11
+ - **UUID v6** (time-ordered) - Time-ordered for better database locality
12
+ - **UUID v7** (time-based) - Time-ordered UUIDs with millisecond precision
13
+ - **UUID v8** (custom) - Custom format for experimental use
14
+ - **NULID** (nanosecond ULID) - Lexicographically sortable IDs with nanosecond precision
15
+ - **NanoID** - URL-friendly, cryptographically secure random ID
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @kakilangit/id-generator
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```javascript
26
+ import init, { generate_ids, decode_id, JsIdFormat, JsIdCase } from '@kakilangit/id-generator';
27
+
28
+ // Initialize the WASM module
29
+ await init();
30
+
31
+ // Generate 5 UUID v4 IDs in lowercase
32
+ const uuids = generate_ids(JsIdFormat.UuidV4, 5, JsIdCase.Lower);
33
+ console.log(uuids); // ["a1b2c3d4-...", "e5f6g7h8-...", ...]
34
+
35
+ // Generate time-based UUID v7
36
+ const uuid7s = generate_ids(JsIdFormat.UuidV7, 1, JsIdCase.Lower);
37
+
38
+ // Generate NULIDs (nanosecond precision)
39
+ const nulids = generate_ids(JsIdFormat.Nulid, 3, JsIdCase.Upper);
40
+
41
+ // Generate NanoIDs (URL-safe, 21 characters by default)
42
+ const nanoids = generate_ids(JsIdFormat.NanoId, 5, JsIdCase.Lower);
43
+
44
+ // Decode an ID to get metadata
45
+ const decoded = decode_id("01hny0qzcw8a5v8z...");
46
+ console.log(decoded.format); // "NULID"
47
+ console.log(decoded.time); // "2024-01-15T10:30:45.123456789Z"
48
+ console.log(decoded.timestamp); // { precision: "ns", value: "1705315845123456789" }
49
+ console.log(decoded.hex); // Hex representation
50
+ console.log(decoded.bytes); // Byte representation (colon-separated)
51
+ ```
52
+
53
+ ## API
54
+
55
+ ### Functions
56
+
57
+ #### `generate_ids(format, count, case)`
58
+ Generates multiple IDs of the specified format.
59
+
60
+ - `format` (JsIdFormat): The ID format to generate
61
+ - `count` (number): Number of IDs to generate (1-10000)
62
+ - `case` (JsIdCase): Case format for alphabetic characters (ignored for NanoID)
63
+
64
+ Returns: `string[]` - Array of generated IDs
65
+
66
+ #### `decode_id(id)`
67
+ Decodes an ID string and returns its metadata.
68
+
69
+ - `id` (string): The ID to decode
70
+
71
+ Returns `JsDecodedId`:
72
+ - `original`: The original ID string
73
+ - `format`: Detected format name ("UUID v1", "UUID v4", "UUID v6", "UUID v7", "UUID v8", "NULID")
74
+ - `time`: RFC 3339 formatted time string (if time-based: UUID v1, v6, v7, NULID)
75
+ - `timestamp`: Object with `precision` ("ms" or "ns") and `value`
76
+ - `randomness`: Random component as decimal string (if applicable)
77
+ - `hex`: Full ID as hex string
78
+ - `bytes`: Full ID as colon-separated hex bytes
79
+
80
+ #### `get_available_formats()`
81
+ Returns all available ID format names.
82
+
83
+ ### Enums
84
+
85
+ #### `JsIdFormat`
86
+ - `UuidV1 = 0` - UUID version 1 (time-based with MAC address)
87
+ - `UuidV4 = 1` - UUID version 4 (random)
88
+ - `UuidV6 = 2` - UUID version 6 (time-ordered for database locality)
89
+ - `UuidV7 = 3` - UUID version 7 (time-based, millisecond precision)
90
+ - `UuidV8 = 4` - UUID version 8 (custom/experimental)
91
+ - `Nulid = 5` - NULID (nanosecond-precision ULID)
92
+ - `NanoId = 6` - NanoID (URL-friendly, cryptographically secure)
93
+
94
+ #### `JsIdCase`
95
+ - `Lower = 0` - Lowercase output
96
+ - `Upper = 1` - Uppercase output
97
+
98
+ ## ID Format Details
99
+
100
+ ### UUID v1
101
+ - Time-based UUID with MAC address
102
+ - 36 characters (with hyphens)
103
+ - Includes timestamp and MAC address (privacy concern)
104
+ - Example: `6ba7b810-9dad-11d1-80b4-00c04fd430c8`
105
+
106
+ ### UUID v4
107
+ - Randomly generated 128-bit UUID
108
+ - 36 characters (with hyphens)
109
+ - Example: `550e8400-e29b-41d4-a716-446655440000`
110
+
111
+ ### UUID v6
112
+ - Time-ordered UUID for better database index locality
113
+ - 36 characters (with hyphens)
114
+ - Similar to UUID v1 but with reordered bytes
115
+ - Example: `0166e6b8-9dad-7b80-80b4-00c04fd430c8`
116
+
117
+ ### UUID v7
118
+ - Time-ordered UUID with Unix timestamp (milliseconds)
119
+ - 36 characters (with hyphens)
120
+ - Sortable by generation time
121
+ - Example: `018e1234-5678-7abc-8def-0123456789ab`
122
+
123
+ ### UUID v8
124
+ - Custom format for experimental use
125
+ - 36 characters (with hyphens)
126
+ - No specific structure enforced
127
+ - Example: `123e4567-e89b-87c5-d012-3456789abcdef`
128
+
129
+ ### NULID
130
+ - Nanosecond-precision lexicographically sortable ID
131
+ - 26 characters (Crockford Base32)
132
+ - Sortable by generation time with nanosecond precision
133
+ - Example: `01hny0qzcw8a5v8z7g6f4d2b9j`
134
+
135
+ ### NanoID
136
+ - URL-friendly, cryptographically secure random ID
137
+ - Uses unreserved URL characters (A-Za-z0-9_-)
138
+ - Default length: 21 characters
139
+ - Example: `NVUp3WKdn2KwW-8S8XYz`
140
+
141
+ ## License
142
+
143
+ MIT
package/id_generator.d.ts CHANGED
@@ -16,10 +16,6 @@ export class JsDecodedId {
16
16
  * The detected format name.
17
17
  */
18
18
  format: string;
19
- /**
20
- * Full ID as hex string.
21
- */
22
- hex: string;
23
19
  /**
24
20
  * The original ID string.
25
21
  */
@@ -68,18 +64,34 @@ export enum JsIdCase {
68
64
  * ID format options for JavaScript.
69
65
  */
70
66
  export enum JsIdFormat {
67
+ /**
68
+ * UUID version 1 (time-based with MAC address).
69
+ */
70
+ UuidV1 = 0,
71
71
  /**
72
72
  * UUID version 4 (random).
73
73
  */
74
- UuidV4 = 0,
74
+ UuidV4 = 1,
75
+ /**
76
+ * UUID version 6 (time-ordered for better database locality).
77
+ */
78
+ UuidV6 = 2,
79
+ /**
80
+ * UUID version 7 (time-based with millisecond precision).
81
+ */
82
+ UuidV7 = 3,
75
83
  /**
76
- * UUID version 7 (time-based).
84
+ * UUID version 8 (custom format for experimental use).
77
85
  */
78
- UuidV7 = 1,
86
+ UuidV8 = 4,
79
87
  /**
80
88
  * NULID (Nanosecond-precision Universally Lexicographically Sortable Identifier).
81
89
  */
82
- Nulid = 2,
90
+ Nulid = 5,
91
+ /**
92
+ * `NanoID` (URL-friendly, cryptographically secure random ID).
93
+ */
94
+ NanoId = 6,
83
95
  }
84
96
 
85
97
  /**
@@ -130,7 +142,6 @@ export interface InitOutput {
130
142
  readonly memory: WebAssembly.Memory;
131
143
  readonly __wbg_get_jsdecodedid_bytes: (a: number, b: number) => void;
132
144
  readonly __wbg_get_jsdecodedid_format: (a: number, b: number) => void;
133
- readonly __wbg_get_jsdecodedid_hex: (a: number, b: number) => void;
134
145
  readonly __wbg_get_jsdecodedid_original: (a: number, b: number) => void;
135
146
  readonly __wbg_get_jsdecodedid_randomness: (a: number, b: number) => void;
136
147
  readonly __wbg_get_jsdecodedid_time: (a: number, b: number) => void;
@@ -139,7 +150,6 @@ export interface InitOutput {
139
150
  readonly __wbg_jstimestamp_free: (a: number, b: number) => void;
140
151
  readonly __wbg_set_jsdecodedid_bytes: (a: number, b: number, c: number) => void;
141
152
  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
153
  readonly __wbg_set_jsdecodedid_original: (a: number, b: number, c: number) => void;
144
154
  readonly __wbg_set_jsdecodedid_randomness: (a: number, b: number, c: number) => void;
145
155
  readonly __wbg_set_jsdecodedid_time: (a: number, b: number, c: number) => void;
package/id_generator.js CHANGED
@@ -61,26 +61,6 @@ export class JsDecodedId {
61
61
  wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
62
62
  }
63
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
64
  /**
85
65
  * The original ID string.
86
66
  * @returns {string}
@@ -167,15 +147,6 @@ export class JsDecodedId {
167
147
  const len0 = WASM_VECTOR_LEN;
168
148
  wasm.__wbg_set_jsdecodedid_format(this.__wbg_ptr, ptr0, len0);
169
149
  }
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
150
  /**
180
151
  * The original ID string.
181
152
  * @param {string} arg0
@@ -235,21 +206,37 @@ export const JsIdCase = Object.freeze({
235
206
 
236
207
  /**
237
208
  * ID format options for JavaScript.
238
- * @enum {0 | 1 | 2}
209
+ * @enum {0 | 1 | 2 | 3 | 4 | 5 | 6}
239
210
  */
240
211
  export const JsIdFormat = Object.freeze({
212
+ /**
213
+ * UUID version 1 (time-based with MAC address).
214
+ */
215
+ UuidV1: 0, "0": "UuidV1",
241
216
  /**
242
217
  * UUID version 4 (random).
243
218
  */
244
- UuidV4: 0, "0": "UuidV4",
219
+ UuidV4: 1, "1": "UuidV4",
220
+ /**
221
+ * UUID version 6 (time-ordered for better database locality).
222
+ */
223
+ UuidV6: 2, "2": "UuidV6",
245
224
  /**
246
- * UUID version 7 (time-based).
225
+ * UUID version 7 (time-based with millisecond precision).
247
226
  */
248
- UuidV7: 1, "1": "UuidV7",
227
+ UuidV7: 3, "3": "UuidV7",
228
+ /**
229
+ * UUID version 8 (custom format for experimental use).
230
+ */
231
+ UuidV8: 4, "4": "UuidV8",
249
232
  /**
250
233
  * NULID (Nanosecond-precision Universally Lexicographically Sortable Identifier).
251
234
  */
252
- Nulid: 2, "2": "Nulid",
235
+ Nulid: 5, "5": "Nulid",
236
+ /**
237
+ * `NanoID` (URL-friendly, cryptographically secure random ID).
238
+ */
239
+ NanoId: 6, "6": "NanoId",
253
240
  });
254
241
 
255
242
  /**
@@ -414,6 +401,19 @@ export function get_available_formats() {
414
401
  function __wbg_get_imports() {
415
402
  const import0 = {
416
403
  __proto__: null,
404
+ __wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
405
+ const ret = typeof(getObject(arg0)) === 'function';
406
+ return ret;
407
+ },
408
+ __wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
409
+ const val = getObject(arg0);
410
+ const ret = typeof(val) === 'object' && val !== null;
411
+ return ret;
412
+ },
413
+ __wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
414
+ const ret = typeof(getObject(arg0)) === 'string';
415
+ return ret;
416
+ },
417
417
  __wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
418
418
  const ret = getObject(arg0) === undefined;
419
419
  return ret;
@@ -425,16 +425,43 @@ function __wbg_get_imports() {
425
425
  const ret = getObject(arg0).call(getObject(arg1));
426
426
  return addHeapObject(ret);
427
427
  }, arguments); },
428
+ __wbg_call_4708e0c13bdc8e95: function() { return handleError(function (arg0, arg1, arg2) {
429
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
430
+ return addHeapObject(ret);
431
+ }, arguments); },
432
+ __wbg_crypto_86f2631e91b51511: function(arg0) {
433
+ const ret = getObject(arg0).crypto;
434
+ return addHeapObject(ret);
435
+ },
428
436
  __wbg_getRandomValues_1c61fac11405ffdc: function() { return handleError(function (arg0, arg1) {
429
437
  globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
430
438
  }, arguments); },
431
439
  __wbg_getRandomValues_9c5c1b115e142bb8: function() { return handleError(function (arg0, arg1) {
432
440
  globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
433
441
  }, arguments); },
442
+ __wbg_getRandomValues_b3f15fcbfabb0f8b: function() { return handleError(function (arg0, arg1) {
443
+ getObject(arg0).getRandomValues(getObject(arg1));
444
+ }, arguments); },
445
+ __wbg_length_32ed9a279acd054c: function(arg0) {
446
+ const ret = getObject(arg0).length;
447
+ return ret;
448
+ },
449
+ __wbg_msCrypto_d562bbe83e0d4b91: function(arg0) {
450
+ const ret = getObject(arg0).msCrypto;
451
+ return addHeapObject(ret);
452
+ },
434
453
  __wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
435
454
  const ret = new Function(getStringFromWasm0(arg0, arg1));
436
455
  return addHeapObject(ret);
437
456
  },
457
+ __wbg_new_with_length_a2c39cbe88fd8ff1: function(arg0) {
458
+ const ret = new Uint8Array(arg0 >>> 0);
459
+ return addHeapObject(ret);
460
+ },
461
+ __wbg_node_e1f24f89a7336c2e: function(arg0) {
462
+ const ret = getObject(arg0).node;
463
+ return addHeapObject(ret);
464
+ },
438
465
  __wbg_now_2c95c9de01293173: function(arg0) {
439
466
  const ret = getObject(arg0).now();
440
467
  return ret;
@@ -451,6 +478,20 @@ function __wbg_get_imports() {
451
478
  const ret = getObject(arg0).performance;
452
479
  return addHeapObject(ret);
453
480
  },
481
+ __wbg_process_3975fd6c72f520aa: function(arg0) {
482
+ const ret = getObject(arg0).process;
483
+ return addHeapObject(ret);
484
+ },
485
+ __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
486
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
487
+ },
488
+ __wbg_randomFillSync_f8c153b79f285817: function() { return handleError(function (arg0, arg1) {
489
+ getObject(arg0).randomFillSync(takeObject(arg1));
490
+ }, arguments); },
491
+ __wbg_require_b74f47fc2d022fd6: function() { return handleError(function () {
492
+ const ret = module.require;
493
+ return addHeapObject(ret);
494
+ }, arguments); },
454
495
  __wbg_static_accessor_GLOBAL_12837167ad935116: function() {
455
496
  const ret = typeof global === 'undefined' ? null : global;
456
497
  return isLikeNone(ret) ? 0 : addHeapObject(ret);
@@ -467,7 +508,20 @@ function __wbg_get_imports() {
467
508
  const ret = typeof window === 'undefined' ? null : window;
468
509
  return isLikeNone(ret) ? 0 : addHeapObject(ret);
469
510
  },
511
+ __wbg_subarray_a96e1fef17ed23cb: function(arg0, arg1, arg2) {
512
+ const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
513
+ return addHeapObject(ret);
514
+ },
515
+ __wbg_versions_4e31226f5e8dc909: function(arg0) {
516
+ const ret = getObject(arg0).versions;
517
+ return addHeapObject(ret);
518
+ },
470
519
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
520
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
521
+ const ret = getArrayU8FromWasm0(arg0, arg1);
522
+ return addHeapObject(ret);
523
+ },
524
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
471
525
  // Cast intrinsic for `Ref(String) -> Externref`.
472
526
  const ret = getStringFromWasm0(arg0, arg1);
473
527
  return addHeapObject(ret);
Binary file
package/package.json CHANGED
@@ -1,26 +1,30 @@
1
1
  {
2
2
  "name": "@kakilangit/id-generator",
3
- "version": "0.1.0",
4
- "description": "WebAssembly bindings for ID Generator tool (UUID v4, UUID v7, NULID)",
5
3
  "type": "module",
6
- "main": "id_generator.js",
7
- "types": "id_generator.d.ts",
4
+ "collaborators": [
5
+ "kakilangit"
6
+ ],
7
+ "description": "WebAssembly bindings for ID Generator tool",
8
+ "version": "0.2.0",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://dev.kakilangit.com"
13
+ },
8
14
  "files": [
9
15
  "id_generator_bg.wasm",
10
16
  "id_generator.js",
11
17
  "id_generator.d.ts"
12
18
  ],
19
+ "main": "id_generator.js",
20
+ "types": "id_generator.d.ts",
21
+ "sideEffects": [
22
+ "./snippets/*"
23
+ ],
13
24
  "keywords": [
14
25
  "wasm",
15
- "webassembly",
16
- "rust",
17
26
  "id-generator",
18
27
  "uuid",
19
- "uuid-v4",
20
- "uuid-v7",
21
28
  "nulid"
22
- ],
23
- "author": "kakilangit",
24
- "license": "MIT",
25
- "homepage": "https://dev.kakilangit.com"
26
- }
29
+ ]
30
+ }