@kakilangit/id-generator 0.1.0 → 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.
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, IdFormat, IdCase } 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(IdFormat.UuidV4, 5, IdCase.Lower);
33
+ console.log(uuids); // ["a1b2c3d4-...", "e5f6g7h8-...", ...]
34
+
35
+ // Generate time-based UUID v7
36
+ const uuid7s = generate_ids(IdFormat.UuidV7, 1, IdCase.Lower);
37
+
38
+ // Generate NULIDs (nanosecond precision)
39
+ const nulids = generate_ids(IdFormat.Nulid, 3, IdCase.Upper);
40
+
41
+ // Generate NanoIDs (URL-safe, 21 characters by default)
42
+ const nanoids = generate_ids(IdFormat.NanoId, 5, IdCase.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` (IdFormat): The ID format to generate
61
+ - `count` (number): Number of IDs to generate (1-10000)
62
+ - `case` (IdCase): 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 `DecodedId`:
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
+ #### `IdFormat`
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
+ #### `IdCase`
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
@@ -4,7 +4,7 @@
4
4
  /**
5
5
  * Decoded ID result for JavaScript.
6
6
  */
7
- export class JsDecodedId {
7
+ export class DecodedId {
8
8
  private constructor();
9
9
  free(): void;
10
10
  [Symbol.dispose](): void;
@@ -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
  */
@@ -43,17 +39,17 @@ export class JsDecodedId {
43
39
  /**
44
40
  * Timestamp (if applicable).
45
41
  */
46
- get timestamp(): JsTimestamp | undefined;
42
+ get timestamp(): Timestamp | undefined;
47
43
  /**
48
44
  * Timestamp (if applicable).
49
45
  */
50
- set timestamp(value: JsTimestamp | null | undefined);
46
+ set timestamp(value: Timestamp | null | undefined);
51
47
  }
52
48
 
53
49
  /**
54
50
  * Case format options for JavaScript.
55
51
  */
56
- export enum JsIdCase {
52
+ export enum IdCase {
57
53
  /**
58
54
  * Lowercase output.
59
55
  */
@@ -67,25 +63,41 @@ export enum JsIdCase {
67
63
  /**
68
64
  * ID format options for JavaScript.
69
65
  */
70
- export enum JsIdFormat {
66
+ export enum IdFormat {
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
  /**
86
98
  * Timestamp precision for JavaScript.
87
99
  */
88
- export class JsTimestamp {
100
+ export class Timestamp {
89
101
  private constructor();
90
102
  free(): void;
91
103
  [Symbol.dispose](): void;
@@ -106,7 +118,7 @@ export class JsTimestamp {
106
118
  *
107
119
  * Returns an error string if the ID format is not recognized.
108
120
  */
109
- export function decode_id(id: string): JsDecodedId;
121
+ export function decode_id(id: string): DecodedId;
110
122
 
111
123
  /**
112
124
  * Generates IDs based on the specified format, count, and case.
@@ -117,7 +129,7 @@ export function decode_id(id: string): JsDecodedId;
117
129
  *
118
130
  * Returns an error string if generation fails (e.g., invalid count).
119
131
  */
120
- export function generate_ids(format: JsIdFormat, count: number, _case: JsIdCase): string[];
132
+ export function generate_ids(format: IdFormat, count: number, _case: IdCase): string[];
121
133
 
122
134
  /**
123
135
  * Returns all available ID format names.
@@ -128,29 +140,27 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
128
140
 
129
141
  export interface InitOutput {
130
142
  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;
143
+ readonly __wbg_decodedid_free: (a: number, b: number) => void;
144
+ readonly __wbg_get_decodedid_bytes: (a: number, b: number) => void;
145
+ readonly __wbg_get_decodedid_format: (a: number, b: number) => void;
146
+ readonly __wbg_get_decodedid_original: (a: number, b: number) => void;
147
+ readonly __wbg_get_decodedid_randomness: (a: number, b: number) => void;
148
+ readonly __wbg_get_decodedid_time: (a: number, b: number) => void;
149
+ readonly __wbg_get_decodedid_timestamp: (a: number) => number;
150
+ readonly __wbg_set_decodedid_bytes: (a: number, b: number, c: number) => void;
151
+ readonly __wbg_set_decodedid_format: (a: number, b: number, c: number) => void;
152
+ readonly __wbg_set_decodedid_original: (a: number, b: number, c: number) => void;
153
+ readonly __wbg_set_decodedid_randomness: (a: number, b: number, c: number) => void;
154
+ readonly __wbg_set_decodedid_time: (a: number, b: number, c: number) => void;
155
+ readonly __wbg_set_decodedid_timestamp: (a: number, b: number) => void;
156
+ readonly __wbg_timestamp_free: (a: number, b: number) => void;
147
157
  readonly decode_id: (a: number, b: number, c: number) => void;
148
158
  readonly generate_ids: (a: number, b: number, c: number, d: number) => void;
149
159
  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;
160
+ readonly __wbg_set_timestamp_value: (a: number, b: number, c: number) => void;
161
+ readonly __wbg_set_timestamp_precision: (a: number, b: number, c: number) => void;
162
+ readonly __wbg_get_timestamp_value: (a: number, b: number) => void;
163
+ readonly __wbg_get_timestamp_precision: (a: number, b: number) => void;
154
164
  readonly __wbindgen_export: (a: number) => void;
155
165
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
156
166
  readonly __wbindgen_export2: (a: number, b: number) => number;
package/id_generator.js CHANGED
@@ -3,23 +3,23 @@
3
3
  /**
4
4
  * Decoded ID result for JavaScript.
5
5
  */
6
- export class JsDecodedId {
6
+ export class DecodedId {
7
7
  static __wrap(ptr) {
8
8
  ptr = ptr >>> 0;
9
- const obj = Object.create(JsDecodedId.prototype);
9
+ const obj = Object.create(DecodedId.prototype);
10
10
  obj.__wbg_ptr = ptr;
11
- JsDecodedIdFinalization.register(obj, obj.__wbg_ptr, obj);
11
+ DecodedIdFinalization.register(obj, obj.__wbg_ptr, obj);
12
12
  return obj;
13
13
  }
14
14
  __destroy_into_raw() {
15
15
  const ptr = this.__wbg_ptr;
16
16
  this.__wbg_ptr = 0;
17
- JsDecodedIdFinalization.unregister(this);
17
+ DecodedIdFinalization.unregister(this);
18
18
  return ptr;
19
19
  }
20
20
  free() {
21
21
  const ptr = this.__destroy_into_raw();
22
- wasm.__wbg_jsdecodedid_free(ptr, 0);
22
+ wasm.__wbg_decodedid_free(ptr, 0);
23
23
  }
24
24
  /**
25
25
  * Full ID as bytes (as comma-separated string for JS).
@@ -30,7 +30,7 @@ export class JsDecodedId {
30
30
  let deferred1_1;
31
31
  try {
32
32
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
33
- wasm.__wbg_get_jsdecodedid_bytes(retptr, this.__wbg_ptr);
33
+ wasm.__wbg_get_decodedid_bytes(retptr, this.__wbg_ptr);
34
34
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
35
35
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
36
36
  deferred1_0 = r0;
@@ -50,27 +50,7 @@ export class JsDecodedId {
50
50
  let deferred1_1;
51
51
  try {
52
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);
53
+ wasm.__wbg_get_decodedid_format(retptr, this.__wbg_ptr);
74
54
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
75
55
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
76
56
  deferred1_0 = r0;
@@ -90,7 +70,7 @@ export class JsDecodedId {
90
70
  let deferred1_1;
91
71
  try {
92
72
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
93
- wasm.__wbg_get_jsdecodedid_original(retptr, this.__wbg_ptr);
73
+ wasm.__wbg_get_decodedid_original(retptr, this.__wbg_ptr);
94
74
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
95
75
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
96
76
  deferred1_0 = r0;
@@ -108,7 +88,7 @@ export class JsDecodedId {
108
88
  get randomness() {
109
89
  try {
110
90
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
111
- wasm.__wbg_get_jsdecodedid_randomness(retptr, this.__wbg_ptr);
91
+ wasm.__wbg_get_decodedid_randomness(retptr, this.__wbg_ptr);
112
92
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
113
93
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
114
94
  let v1;
@@ -128,7 +108,7 @@ export class JsDecodedId {
128
108
  get time() {
129
109
  try {
130
110
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
131
- wasm.__wbg_get_jsdecodedid_time(retptr, this.__wbg_ptr);
111
+ wasm.__wbg_get_decodedid_time(retptr, this.__wbg_ptr);
132
112
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
133
113
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
134
114
  let v1;
@@ -143,11 +123,11 @@ export class JsDecodedId {
143
123
  }
144
124
  /**
145
125
  * Timestamp (if applicable).
146
- * @returns {JsTimestamp | undefined}
126
+ * @returns {Timestamp | undefined}
147
127
  */
148
128
  get timestamp() {
149
- const ret = wasm.__wbg_get_jsdecodedid_timestamp(this.__wbg_ptr);
150
- return ret === 0 ? undefined : JsTimestamp.__wrap(ret);
129
+ const ret = wasm.__wbg_get_decodedid_timestamp(this.__wbg_ptr);
130
+ return ret === 0 ? undefined : Timestamp.__wrap(ret);
151
131
  }
152
132
  /**
153
133
  * Full ID as bytes (as comma-separated string for JS).
@@ -156,7 +136,7 @@ export class JsDecodedId {
156
136
  set bytes(arg0) {
157
137
  const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
158
138
  const len0 = WASM_VECTOR_LEN;
159
- wasm.__wbg_set_jsdecodedid_bytes(this.__wbg_ptr, ptr0, len0);
139
+ wasm.__wbg_set_decodedid_bytes(this.__wbg_ptr, ptr0, len0);
160
140
  }
161
141
  /**
162
142
  * The detected format name.
@@ -165,16 +145,7 @@ export class JsDecodedId {
165
145
  set format(arg0) {
166
146
  const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
167
147
  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);
148
+ wasm.__wbg_set_decodedid_format(this.__wbg_ptr, ptr0, len0);
178
149
  }
179
150
  /**
180
151
  * The original ID string.
@@ -183,7 +154,7 @@ export class JsDecodedId {
183
154
  set original(arg0) {
184
155
  const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
185
156
  const len0 = WASM_VECTOR_LEN;
186
- wasm.__wbg_set_jsdecodedid_original(this.__wbg_ptr, ptr0, len0);
157
+ wasm.__wbg_set_decodedid_original(this.__wbg_ptr, ptr0, len0);
187
158
  }
188
159
  /**
189
160
  * Random component as string (decimal).
@@ -192,7 +163,7 @@ export class JsDecodedId {
192
163
  set randomness(arg0) {
193
164
  var ptr0 = isLikeNone(arg0) ? 0 : passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
194
165
  var len0 = WASM_VECTOR_LEN;
195
- wasm.__wbg_set_jsdecodedid_randomness(this.__wbg_ptr, ptr0, len0);
166
+ wasm.__wbg_set_decodedid_randomness(this.__wbg_ptr, ptr0, len0);
196
167
  }
197
168
  /**
198
169
  * RFC 3339 formatted time string with timezone (if applicable).
@@ -201,28 +172,28 @@ export class JsDecodedId {
201
172
  set time(arg0) {
202
173
  var ptr0 = isLikeNone(arg0) ? 0 : passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
203
174
  var len0 = WASM_VECTOR_LEN;
204
- wasm.__wbg_set_jsdecodedid_time(this.__wbg_ptr, ptr0, len0);
175
+ wasm.__wbg_set_decodedid_time(this.__wbg_ptr, ptr0, len0);
205
176
  }
206
177
  /**
207
178
  * Timestamp (if applicable).
208
- * @param {JsTimestamp | null} [arg0]
179
+ * @param {Timestamp | null} [arg0]
209
180
  */
210
181
  set timestamp(arg0) {
211
182
  let ptr0 = 0;
212
183
  if (!isLikeNone(arg0)) {
213
- _assertClass(arg0, JsTimestamp);
184
+ _assertClass(arg0, Timestamp);
214
185
  ptr0 = arg0.__destroy_into_raw();
215
186
  }
216
- wasm.__wbg_set_jsdecodedid_timestamp(this.__wbg_ptr, ptr0);
187
+ wasm.__wbg_set_decodedid_timestamp(this.__wbg_ptr, ptr0);
217
188
  }
218
189
  }
219
- if (Symbol.dispose) JsDecodedId.prototype[Symbol.dispose] = JsDecodedId.prototype.free;
190
+ if (Symbol.dispose) DecodedId.prototype[Symbol.dispose] = DecodedId.prototype.free;
220
191
 
221
192
  /**
222
193
  * Case format options for JavaScript.
223
194
  * @enum {0 | 1}
224
195
  */
225
- export const JsIdCase = Object.freeze({
196
+ export const IdCase = Object.freeze({
226
197
  /**
227
198
  * Lowercase output.
228
199
  */
@@ -235,43 +206,59 @@ 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
- export const JsIdFormat = Object.freeze({
211
+ export const IdFormat = 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
  /**
256
243
  * Timestamp precision for JavaScript.
257
244
  */
258
- export class JsTimestamp {
245
+ export class Timestamp {
259
246
  static __wrap(ptr) {
260
247
  ptr = ptr >>> 0;
261
- const obj = Object.create(JsTimestamp.prototype);
248
+ const obj = Object.create(Timestamp.prototype);
262
249
  obj.__wbg_ptr = ptr;
263
- JsTimestampFinalization.register(obj, obj.__wbg_ptr, obj);
250
+ TimestampFinalization.register(obj, obj.__wbg_ptr, obj);
264
251
  return obj;
265
252
  }
266
253
  __destroy_into_raw() {
267
254
  const ptr = this.__wbg_ptr;
268
255
  this.__wbg_ptr = 0;
269
- JsTimestampFinalization.unregister(this);
256
+ TimestampFinalization.unregister(this);
270
257
  return ptr;
271
258
  }
272
259
  free() {
273
260
  const ptr = this.__destroy_into_raw();
274
- wasm.__wbg_jstimestamp_free(ptr, 0);
261
+ wasm.__wbg_timestamp_free(ptr, 0);
275
262
  }
276
263
  /**
277
264
  * Precision type: "ms" for milliseconds, "ns" for nanoseconds.
@@ -282,7 +269,7 @@ export class JsTimestamp {
282
269
  let deferred1_1;
283
270
  try {
284
271
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
285
- wasm.__wbg_get_jsdecodedid_original(retptr, this.__wbg_ptr);
272
+ wasm.__wbg_get_decodedid_original(retptr, this.__wbg_ptr);
286
273
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
287
274
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
288
275
  deferred1_0 = r0;
@@ -302,7 +289,7 @@ export class JsTimestamp {
302
289
  let deferred1_1;
303
290
  try {
304
291
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
305
- wasm.__wbg_get_jsdecodedid_format(retptr, this.__wbg_ptr);
292
+ wasm.__wbg_get_decodedid_format(retptr, this.__wbg_ptr);
306
293
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
307
294
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
308
295
  deferred1_0 = r0;
@@ -320,7 +307,7 @@ export class JsTimestamp {
320
307
  set precision(arg0) {
321
308
  const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
322
309
  const len0 = WASM_VECTOR_LEN;
323
- wasm.__wbg_set_jsdecodedid_original(this.__wbg_ptr, ptr0, len0);
310
+ wasm.__wbg_set_decodedid_original(this.__wbg_ptr, ptr0, len0);
324
311
  }
325
312
  /**
326
313
  * Timestamp value as string (to support u128 for nanoseconds).
@@ -329,10 +316,10 @@ export class JsTimestamp {
329
316
  set value(arg0) {
330
317
  const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
331
318
  const len0 = WASM_VECTOR_LEN;
332
- wasm.__wbg_set_jsdecodedid_format(this.__wbg_ptr, ptr0, len0);
319
+ wasm.__wbg_set_decodedid_format(this.__wbg_ptr, ptr0, len0);
333
320
  }
334
321
  }
335
- if (Symbol.dispose) JsTimestamp.prototype[Symbol.dispose] = JsTimestamp.prototype.free;
322
+ if (Symbol.dispose) Timestamp.prototype[Symbol.dispose] = Timestamp.prototype.free;
336
323
 
337
324
  /**
338
325
  * Decodes an ID string and returns its metadata.
@@ -341,7 +328,7 @@ if (Symbol.dispose) JsTimestamp.prototype[Symbol.dispose] = JsTimestamp.prototyp
341
328
  *
342
329
  * Returns an error string if the ID format is not recognized.
343
330
  * @param {string} id
344
- * @returns {JsDecodedId}
331
+ * @returns {DecodedId}
345
332
  */
346
333
  export function decode_id(id) {
347
334
  try {
@@ -355,7 +342,7 @@ export function decode_id(id) {
355
342
  if (r2) {
356
343
  throw takeObject(r1);
357
344
  }
358
- return JsDecodedId.__wrap(r0);
345
+ return DecodedId.__wrap(r0);
359
346
  } finally {
360
347
  wasm.__wbindgen_add_to_stack_pointer(16);
361
348
  }
@@ -369,9 +356,9 @@ export function decode_id(id) {
369
356
  * # Errors
370
357
  *
371
358
  * Returns an error string if generation fails (e.g., invalid count).
372
- * @param {JsIdFormat} format
359
+ * @param {IdFormat} format
373
360
  * @param {number} count
374
- * @param {JsIdCase} _case
361
+ * @param {IdCase} _case
375
362
  * @returns {string[]}
376
363
  */
377
364
  export function generate_ids(format, count, _case) {
@@ -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);
@@ -486,12 +540,12 @@ function __wbg_get_imports() {
486
540
  };
487
541
  }
488
542
 
489
- const JsDecodedIdFinalization = (typeof FinalizationRegistry === 'undefined')
543
+ const DecodedIdFinalization = (typeof FinalizationRegistry === 'undefined')
490
544
  ? { register: () => {}, unregister: () => {} }
491
- : new FinalizationRegistry(ptr => wasm.__wbg_jsdecodedid_free(ptr >>> 0, 1));
492
- const JsTimestampFinalization = (typeof FinalizationRegistry === 'undefined')
545
+ : new FinalizationRegistry(ptr => wasm.__wbg_decodedid_free(ptr >>> 0, 1));
546
+ const TimestampFinalization = (typeof FinalizationRegistry === 'undefined')
493
547
  ? { register: () => {}, unregister: () => {} }
494
- : new FinalizationRegistry(ptr => wasm.__wbg_jstimestamp_free(ptr >>> 0, 1));
548
+ : new FinalizationRegistry(ptr => wasm.__wbg_timestamp_free(ptr >>> 0, 1));
495
549
 
496
550
  function addHeapObject(obj) {
497
551
  if (heap_next === heap.length) heap.push(heap.length + 1);
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.3.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
+ }