uniku 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/build/cuid2/cuid2.d.mts +1 -1
  2. package/build/cuid2/cuid2.d.mts.map +1 -1
  3. package/build/cuid2/cuid2.mjs +1 -1
  4. package/build/cuid2/cuid2.mjs.map +1 -1
  5. package/build/errors-Da-8dh4J.d.mts +67 -0
  6. package/build/errors-Da-8dh4J.d.mts.map +1 -0
  7. package/build/errors.d.mts +2 -2
  8. package/build/errors.mjs +1 -1
  9. package/build/errors.mjs.map +1 -1
  10. package/build/generators-BfJLt7Qf.d.mts +17 -0
  11. package/build/generators-BfJLt7Qf.d.mts.map +1 -0
  12. package/build/generators.d.mts +2 -17
  13. package/build/ksuid/ksuid.d.mts +10 -4
  14. package/build/ksuid/ksuid.d.mts.map +1 -1
  15. package/build/ksuid/ksuid.mjs +1 -1
  16. package/build/ksuid/ksuid.mjs.map +1 -1
  17. package/build/nanoid/nanoid.d.mts +13 -7
  18. package/build/nanoid/nanoid.d.mts.map +1 -1
  19. package/build/nanoid/nanoid.mjs +1 -1
  20. package/build/nanoid/nanoid.mjs.map +1 -1
  21. package/build/objectid/objectid.d.mts +10 -3
  22. package/build/objectid/objectid.d.mts.map +1 -1
  23. package/build/objectid/objectid.mjs +1 -1
  24. package/build/objectid/objectid.mjs.map +1 -1
  25. package/build/timestamp-ChrSuQCR.mjs +2 -0
  26. package/build/timestamp-ChrSuQCR.mjs.map +1 -0
  27. package/build/tsid/tsid.d.mts +1 -1
  28. package/build/tsid/tsid.d.mts.map +1 -1
  29. package/build/tsid/tsid.mjs +1 -1
  30. package/build/tsid/tsid.mjs.map +1 -1
  31. package/build/typeid/typeid.d.mts +4 -2
  32. package/build/typeid/typeid.d.mts.map +1 -1
  33. package/build/typeid/typeid.mjs +1 -1
  34. package/build/typeid/typeid.mjs.map +1 -1
  35. package/build/ulid/ulid.d.mts +1 -1
  36. package/build/ulid/ulid.d.mts.map +1 -1
  37. package/build/ulid/ulid.mjs +1 -1
  38. package/build/ulid/ulid.mjs.map +1 -1
  39. package/build/uuid/v4.d.mts +1 -1
  40. package/build/uuid/v4.d.mts.map +1 -1
  41. package/build/uuid/v4.mjs +1 -1
  42. package/build/uuid/v4.mjs.map +1 -1
  43. package/build/uuid/v7.d.mts +8 -2
  44. package/build/uuid/v7.d.mts.map +1 -1
  45. package/build/uuid/v7.mjs +1 -1
  46. package/build/uuid/v7.mjs.map +1 -1
  47. package/build/uuid-BPebYihz.mjs +2 -0
  48. package/build/uuid-BPebYihz.mjs.map +1 -0
  49. package/build/xid/xid.d.mts +12 -2
  50. package/build/xid/xid.d.mts.map +1 -1
  51. package/build/xid/xid.mjs +1 -1
  52. package/build/xid/xid.mjs.map +1 -1
  53. package/package.json +1 -1
  54. package/src/common/timestamp.ts +70 -0
  55. package/src/cuid2/cuid2.ts +5 -2
  56. package/src/errors.ts +75 -10
  57. package/src/ksuid/base62.ts +7 -7
  58. package/src/ksuid/ksuid.ts +19 -15
  59. package/src/nanoid/nanoid.ts +41 -18
  60. package/src/objectid/hex.ts +6 -4
  61. package/src/objectid/objectid.ts +24 -11
  62. package/src/tsid/crockford64.ts +7 -6
  63. package/src/tsid/tsid.ts +20 -13
  64. package/src/typeid/typeid.ts +106 -16
  65. package/src/ulid/crockford.ts +8 -6
  66. package/src/ulid/ulid.ts +11 -7
  67. package/src/uuid/common/uuid.ts +12 -4
  68. package/src/uuid/v4.ts +5 -2
  69. package/src/uuid/v7.ts +25 -9
  70. package/src/xid/base32hex.ts +8 -7
  71. package/src/xid/xid.ts +25 -12
  72. package/build/errors-Dgoyi-ci.d.mts +0 -38
  73. package/build/errors-Dgoyi-ci.d.mts.map +0 -1
  74. package/build/generators.d.mts.map +0 -1
  75. package/build/uuid-CnQIYoQi.mjs +0 -2
  76. package/build/uuid-CnQIYoQi.mjs.map +0 -1
package/src/ulid/ulid.ts CHANGED
@@ -75,8 +75,9 @@ function writeUlidBytesUnchecked(time: number, random: Uint8Array, buf: Uint8Arr
75
75
  function writeUlidBytes(time: number, random: Uint8Array, buf: Uint8Array, offset: number): void {
76
76
  if (!isWritableRange(buf, offset, ULID_BYTES)) {
77
77
  throw new BufferError(
78
- 'ULID_BUFFER_OUT_OF_BOUNDS',
78
+ 'BUFFER_OUT_OF_BOUNDS',
79
79
  `ULID byte range ${offset}:${offset + ULID_BYTES - 1} is out of buffer bounds`,
80
+ { strategy: 'ulid' },
80
81
  )
81
82
  }
82
83
  writeUlidBytesUnchecked(time, random, buf, offset)
@@ -110,18 +111,20 @@ function ulidFn<TBuf extends Uint8Array = Uint8Array>(options?: UlidOptions, buf
110
111
  // Explicit options provided - use them directly without monotonic state
111
112
  const optMsecs = options.msecs
112
113
  if (optMsecs !== undefined && !isIntegerInRange(optMsecs, 0, MAX_MSECS)) {
113
- throw new InvalidInputError(
114
- 'ULID_TIMESTAMP_OUT_OF_RANGE',
115
- `Timestamp must be an integer between 0 and ${MAX_MSECS}`,
116
- )
114
+ throw new InvalidInputError('TIMESTAMP_OUT_OF_RANGE', `Timestamp must be an integer between 0 and ${MAX_MSECS}`, {
115
+ strategy: 'ulid',
116
+ })
117
117
  }
118
118
  time = optMsecs ?? Date.now()
119
119
  const optRandom = options.random
120
120
  if (optRandom) {
121
121
  if (optRandom.length < RANDOM_BYTES) {
122
122
  throw new InvalidInputError(
123
- 'ULID_RANDOM_BYTES_TOO_SHORT',
123
+ 'RANDOM_BYTES_TOO_SHORT',
124
124
  `Random bytes length must be >= ${RANDOM_BYTES} for ULID`,
125
+ {
126
+ strategy: 'ulid',
127
+ },
125
128
  )
126
129
  }
127
130
  random = optRandom
@@ -142,8 +145,9 @@ function ulidFn<TBuf extends Uint8Array = Uint8Array>(options?: UlidOptions, buf
142
145
  if (!incrementBytesInPlace(state.lastRandom)) {
143
146
  state.lastRandom.fill(0xff)
144
147
  throw new InvalidInputError(
145
- 'ULID_RANDOM_OVERFLOW',
148
+ 'RANDOM_OVERFLOW',
146
149
  'ULID random component overflowed while preserving monotonic order',
150
+ { strategy: 'ulid' },
147
151
  )
148
152
  }
149
153
  random = state.lastRandom
@@ -95,8 +95,11 @@ const HEX_TABLE: string[] = Array.from({ length: 256 }, (_, i) => i.toString(16)
95
95
  export function formatUuid(bytes: Uint8Array): string {
96
96
  if (bytes.length !== UUID_BYTE_LENGTH) {
97
97
  throw new BufferError(
98
- 'UUID_BYTES_INVALID_LENGTH',
98
+ 'BYTES_INVALID_LENGTH',
99
99
  `UUID bytes must be exactly ${UUID_BYTE_LENGTH} bytes, got ${bytes.length}`,
100
+ {
101
+ strategy: 'uuid',
102
+ },
100
103
  )
101
104
  }
102
105
 
@@ -133,14 +136,17 @@ export function formatUuidUnchecked(bytes: Uint8Array): string {
133
136
 
134
137
  export function parseUuid(value: string): Uint8Array {
135
138
  if (value.length !== UUID_STRING_LENGTH) {
136
- throw new ParseError('UUID_INVALID_LENGTH', `UUID string must be 36 characters, got ${value.length}`)
139
+ throw new ParseError('INVALID_LENGTH', `UUID string must be 36 characters, got ${value.length}`, {
140
+ strategy: 'uuid',
141
+ })
137
142
  }
138
143
 
139
144
  // Validate separator positions directly (more efficient than full loop)
140
145
  if (value[8] !== '-' || value[13] !== '-' || value[18] !== '-' || value[23] !== '-') {
141
146
  throw new ParseError(
142
- 'UUID_INVALID_SEPARATORS',
147
+ 'INVALID_FORMAT',
143
148
  `UUID string has invalid separators at positions 8, 13, 18, 23. Received: "${value}"`,
149
+ { strategy: 'uuid' },
144
150
  )
145
151
  }
146
152
 
@@ -154,7 +160,9 @@ export function parseUuid(value: string): Uint8Array {
154
160
 
155
161
  const nibble = hexValue(value.charCodeAt(i))
156
162
  if (nibble === -1) {
157
- throw new ParseError('UUID_INVALID_HEX_CHAR', `UUID string contains invalid hex character at position ${i}`)
163
+ throw new ParseError('INVALID_CHAR', `UUID string contains invalid hex character at position ${i}`, {
164
+ strategy: 'uuid',
165
+ })
158
166
  }
159
167
 
160
168
  if (UUID_CHAR_IS_HIGH[i]) {
package/src/uuid/v4.ts CHANGED
@@ -69,14 +69,17 @@ function _v4<TBuf extends Uint8Array = Uint8Array>(
69
69
  ): string | TBuf {
70
70
  const random = options?.random
71
71
  if (random && random.length < UUID_BYTES) {
72
- throw new InvalidInputError('UUID_RANDOM_BYTES_TOO_SHORT', `Random bytes length must be >= ${UUID_BYTES}`)
72
+ throw new InvalidInputError('RANDOM_BYTES_TOO_SHORT', `Random bytes length must be >= ${UUID_BYTES}`, {
73
+ strategy: 'uuid',
74
+ })
73
75
  }
74
76
 
75
77
  const outputOffset = buf ? (offset ?? 0) : 0
76
78
  if (buf && !isWritableRange(buf, outputOffset, UUID_BYTES)) {
77
79
  throw new BufferError(
78
- 'UUID_BUFFER_OUT_OF_BOUNDS',
80
+ 'BUFFER_OUT_OF_BOUNDS',
79
81
  `UUID byte range ${outputOffset}:${outputOffset + UUID_BYTES - 1} is out of buffer bounds`,
82
+ { strategy: 'uuid' },
80
83
  )
81
84
  }
82
85
 
package/src/uuid/v7.ts CHANGED
@@ -14,9 +14,16 @@ export type UuidV7Options = {
14
14
  * Defaults to Date.now().
15
15
  */
16
16
  msecs?: number
17
+ /**
18
+ * Unsigned 32-bit counter value.
19
+ */
20
+ counter?: number
17
21
  /**
18
22
  * Unsigned 32-bit sequence value.
23
+ *
24
+ * @deprecated Use `counter` instead. Will be removed at v1-rc.
19
25
  */
26
+ // TODO(v1-rc): remove this alias (tracked in docs/STABILITY.md).
20
27
  seq?: number
21
28
  }
22
29
 
@@ -25,7 +32,7 @@ export type UuidV7 = {
25
32
  (): string
26
33
  /** Generate a UUID v7 with explicit options or write its 16 canonical bytes into a caller-owned buffer. */
27
34
  <TBuf extends Uint8Array = Uint8Array>(options: UuidV7Options | undefined, buf: TBuf, offset?: number): TBuf
28
- /** Generate a UUID v7 string with optional timestamp, sequence, or random bytes. */
35
+ /** Generate a UUID v7 string with optional timestamp, counter, or random bytes. */
29
36
  (options?: UuidV7Options, buf?: undefined, offset?: number): string
30
37
  /** Convert a UUID v7 string to its canonical 16-byte representation. */
31
38
  toBytes(id: string): Uint8Array
@@ -92,8 +99,9 @@ function writeV7BytesUnchecked(rnds: Uint8Array, msecs: number, seq: number, buf
92
99
  function writeV7Bytes(rnds: Uint8Array, msecs: number, seq: number, buf: Uint8Array, offset: number): void {
93
100
  if (!isWritableRange(buf, offset, UUID_BYTES)) {
94
101
  throw new BufferError(
95
- 'UUID_BUFFER_OUT_OF_BOUNDS',
102
+ 'BUFFER_OUT_OF_BOUNDS',
96
103
  `UUID byte range ${offset}:${offset + UUID_BYTES - 1} is out of buffer bounds`,
104
+ { strategy: 'uuid' },
97
105
  )
98
106
  }
99
107
  writeV7BytesUnchecked(rnds, msecs, seq, buf, offset)
@@ -106,18 +114,26 @@ function v7WithOptions<TBuf extends Uint8Array = Uint8Array>(
106
114
  ): string | TBuf {
107
115
  const optMsecs = options.msecs
108
116
  if (optMsecs !== undefined && !isIntegerInRange(optMsecs, 0, MAX_MSECS)) {
109
- throw new InvalidInputError(
110
- 'UUID_TIMESTAMP_OUT_OF_RANGE',
111
- `Timestamp must be an integer between 0 and ${MAX_MSECS}`,
112
- )
117
+ throw new InvalidInputError('TIMESTAMP_OUT_OF_RANGE', `Timestamp must be an integer between 0 and ${MAX_MSECS}`, {
118
+ strategy: 'uuid',
119
+ })
120
+ }
121
+ if (options.counter !== undefined && options.seq !== undefined) {
122
+ throw new InvalidInputError('CONFLICTING_OPTIONS', 'Pass only one of `counter` or `seq`, not both', {
123
+ strategy: 'uuid',
124
+ })
113
125
  }
114
- const optSeq = options.seq
126
+ const optSeq = options.counter ?? options.seq
115
127
  if (optSeq !== undefined && !isIntegerInRange(optSeq, 0, MAX_SEQ)) {
116
- throw new InvalidInputError('UUID_SEQUENCE_OUT_OF_RANGE', `Sequence must be an integer between 0 and ${MAX_SEQ}`)
128
+ throw new InvalidInputError('COUNTER_OUT_OF_RANGE', `Counter must be an integer between 0 and ${MAX_SEQ}`, {
129
+ strategy: 'uuid',
130
+ })
117
131
  }
118
132
  const optRandom = options.random
119
133
  if (optRandom && optRandom.length < UUID_BYTES) {
120
- throw new InvalidInputError('UUID_RANDOM_BYTES_TOO_SHORT', `Random bytes length must be >= ${UUID_BYTES}`)
134
+ throw new InvalidInputError('RANDOM_BYTES_TOO_SHORT', `Random bytes length must be >= ${UUID_BYTES}`, {
135
+ strategy: 'uuid',
136
+ })
121
137
  }
122
138
 
123
139
  const rnds = optRandom ?? rng()
@@ -16,10 +16,9 @@ for (let i = 0; i < ENCODING.length; i += 1) {
16
16
  /** Encode the 12 canonical XID bytes as lowercase base32hex. */
17
17
  export function encodeBase32Hex(bytes: Uint8Array): string {
18
18
  if (bytes.length !== XID_BYTES) {
19
- throw new BufferError(
20
- 'XID_BYTES_INVALID_LENGTH',
21
- `XID bytes must be exactly ${XID_BYTES} bytes, got ${bytes.length}`,
22
- )
19
+ throw new BufferError('BYTES_INVALID_LENGTH', `XID bytes must be exactly ${XID_BYTES} bytes, got ${bytes.length}`, {
20
+ strategy: 'xid',
21
+ })
23
22
  }
24
23
 
25
24
  ENCODED[0] = ENCODING_CODES[bytes[0] >> 3]
@@ -62,20 +61,22 @@ export function encodeCounterSuffix(lastIdentityByte: number, counter: number):
62
61
  /** Decode a canonical lowercase base32hex XID string to its 12 bytes. */
63
62
  export function decodeBase32Hex(id: string): Uint8Array {
64
63
  if (id.length !== XID_LENGTH) {
65
- throw new ParseError('XID_INVALID_LENGTH', `XID string must be ${XID_LENGTH} characters, got ${id.length}`)
64
+ throw new ParseError('INVALID_LENGTH', `XID string must be ${XID_LENGTH} characters, got ${id.length}`, {
65
+ strategy: 'xid',
66
+ })
66
67
  }
67
68
 
68
69
  const values = new Uint8Array(XID_LENGTH)
69
70
  for (let i = 0; i < XID_LENGTH; i += 1) {
70
71
  const value = DECODING[id.charCodeAt(i)]
71
72
  if (value === 255) {
72
- throw new ParseError('XID_INVALID_CHAR', `Invalid XID character: ${id[i]}`)
73
+ throw new ParseError('INVALID_CHAR', `Invalid XID character: ${id[i]}`, { strategy: 'xid' })
73
74
  }
74
75
  values[i] = value
75
76
  }
76
77
 
77
78
  if (values[19] !== 0 && values[19] !== 16) {
78
- throw new ParseError('XID_NON_CANONICAL', 'XID trailing bits must be canonically encoded')
79
+ throw new ParseError('NON_CANONICAL', 'XID trailing bits must be canonically encoded', { strategy: 'xid' })
79
80
  }
80
81
 
81
82
  return new Uint8Array([
package/src/xid/xid.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { writeTimestamp32 } from '../common/bytes'
2
2
  import { randomBytes, randomUint32 } from '../common/random'
3
+ import { resolveTimestampSecs } from '../common/timestamp'
3
4
  import { isIntegerInRange, isWritableRange } from '../common/validation'
4
5
  import { BufferError, InvalidInputError } from '../errors'
5
6
  import { decodeBase32Hex, encodeBase32Hex, encodeCounterSuffix } from './base32hex'
@@ -19,7 +20,17 @@ export type XidOptions = {
19
20
  machineId?: Uint8Array
20
21
  /** 16-bit process identity. */
21
22
  processId?: number
22
- /** Unix timestamp in seconds. Defaults to the current second. */
23
+ /**
24
+ * Unix timestamp in milliseconds. Defaults to Date.now().
25
+ * XID stores whole seconds, so sub-second precision is truncated.
26
+ */
27
+ msecs?: number
28
+ /**
29
+ * Unix timestamp in seconds.
30
+ *
31
+ * @deprecated Use `msecs` instead. Will be removed at v1-rc.
32
+ */
33
+ // TODO(v1-rc): remove this alias (tracked in docs/STABILITY.md).
23
34
  secs?: number
24
35
  /** 24-bit counter. Explicit values do not consume shared state. */
25
36
  counter?: number
@@ -81,18 +92,20 @@ function writeXidBytesUnchecked(
81
92
  function validateOptions(options: XidOptions): void {
82
93
  if (options.machineId !== undefined && options.machineId.length < MACHINE_ID_BYTES) {
83
94
  throw new InvalidInputError(
84
- 'XID_MACHINE_ID_BYTES_TOO_SHORT',
95
+ 'MACHINE_ID_BYTES_TOO_SHORT',
85
96
  `Machine ID bytes length must be >= ${MACHINE_ID_BYTES} for XID`,
97
+ { strategy: 'xid' },
86
98
  )
87
99
  }
88
100
  if (options.processId !== undefined && !isIntegerInRange(options.processId, 0, MAX_PROCESS_ID)) {
89
- throw new InvalidInputError('XID_PROCESS_ID_OUT_OF_RANGE', `Process ID must be between 0 and ${MAX_PROCESS_ID}`)
90
- }
91
- if (options.secs !== undefined && !isIntegerInRange(options.secs, 0, MAX_SECS)) {
92
- throw new InvalidInputError('XID_TIMESTAMP_OUT_OF_RANGE', `Timestamp must be between 0 and ${MAX_SECS}`)
101
+ throw new InvalidInputError('PROCESS_ID_OUT_OF_RANGE', `Process ID must be between 0 and ${MAX_PROCESS_ID}`, {
102
+ strategy: 'xid',
103
+ })
93
104
  }
94
105
  if (options.counter !== undefined && !isIntegerInRange(options.counter, 0, MAX_COUNTER)) {
95
- throw new InvalidInputError('XID_COUNTER_OUT_OF_RANGE', `Counter must be between 0 and ${MAX_COUNTER}`)
106
+ throw new InvalidInputError('COUNTER_OUT_OF_RANGE', `Counter must be between 0 and ${MAX_COUNTER}`, {
107
+ strategy: 'xid',
108
+ })
96
109
  }
97
110
  }
98
111
 
@@ -113,7 +126,8 @@ function xidFn<TBuf extends Uint8Array = Uint8Array>(options?: XidOptions, buf?:
113
126
 
114
127
  if (options !== undefined) validateOptions(options)
115
128
 
116
- const secs = options?.secs ?? Math.floor(Date.now() / 1000)
129
+ const resolvedSecs = options === undefined ? undefined : resolveTimestampSecs(options, 0, MAX_SECS, 'xid')
130
+ const secs = resolvedSecs ?? Math.floor(Date.now() / 1000)
117
131
  if (options?.machineId === undefined || options.processId === undefined) {
118
132
  initializeIdentity()
119
133
  }
@@ -123,10 +137,9 @@ function xidFn<TBuf extends Uint8Array = Uint8Array>(options?: XidOptions, buf?:
123
137
 
124
138
  if (buf !== undefined) {
125
139
  if (!isWritableRange(buf, offset, XID_BYTES)) {
126
- throw new BufferError(
127
- 'XID_BUFFER_OUT_OF_BOUNDS',
128
- `XID byte range ${offset}:${offset + 11} is out of buffer bounds`,
129
- )
140
+ throw new BufferError('BUFFER_OUT_OF_BOUNDS', `XID byte range ${offset}:${offset + 11} is out of buffer bounds`, {
141
+ strategy: 'xid',
142
+ })
130
143
  }
131
144
  writeXidBytesUnchecked(secs, machineId, processId, counter, buf, offset)
132
145
  return buf
@@ -1,38 +0,0 @@
1
- //#region src/errors.d.ts
2
- /**
3
- * Base error for all uniku errors.
4
- * Provides `_tag` for discriminated matching (compatible with Effect's `catchTag`)
5
- * and `code` for machine-readable error identification.
6
- */
7
- declare abstract class UniqueIdError extends Error {
8
- abstract readonly _tag: string;
9
- abstract readonly code: string;
10
- constructor(message: string);
11
- }
12
- /**
13
- * Thrown when generator arguments are invalid (bad size, alphabet, length, timestamp, version).
14
- */
15
- declare class InvalidInputError extends UniqueIdError {
16
- readonly code: string;
17
- readonly _tag = "InvalidInputError";
18
- constructor(code: string, message: string);
19
- }
20
- /**
21
- * Thrown when parsing/decoding an ID string that has invalid format or characters.
22
- */
23
- declare class ParseError extends UniqueIdError {
24
- readonly code: string;
25
- readonly _tag = "ParseError";
26
- constructor(code: string, message: string);
27
- }
28
- /**
29
- * Thrown when a byte array or buffer is too short or an offset is out of bounds.
30
- */
31
- declare class BufferError extends UniqueIdError {
32
- readonly code: string;
33
- readonly _tag = "BufferError";
34
- constructor(code: string, message: string);
35
- }
36
- //#endregion
37
- export { UniqueIdError as i, InvalidInputError as n, ParseError as r, BufferError as t };
38
- //# sourceMappingURL=errors-Dgoyi-ci.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors-Dgoyi-ci.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";;AAKA;;;;uBAAsB,aAAA,SAAsB,KAAA;EAAA,kBACxB,IAAA;EAAA,kBACA,IAAA;EAElB,WAAA,CAAY,OAAA;AAAA;;AAAA;AASd;cAAa,iBAAA,SAA0B,aAAA;EAAA,SAInC,IAAA;EAAA,SAHO,IAAA;EAET,WAAA,CACE,IAAA,UACA,OAAA;AAAA;;;;cASS,UAAA,SAAmB,aAAA;EAAA,SAI5B,IAAA;EAAA,SAHO,IAAA;EAET,WAAA,CACE,IAAA,UACA,OAAA;AAAA;;;;cASS,WAAA,SAAoB,aAAA;EAAA,SAI7B,IAAA;EAAA,SAHO,IAAA;EAET,WAAA,CACE,IAAA,UACA,OAAA;AAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators.d.mts","names":[],"sources":["../src/generators.ts"],"mappings":";;AAWA;;;;AAAuG;AAKvG;;cALa,aAAA;;AAKqB;;KAAtB,WAAA,WAAsB,aAAA"}
@@ -1,2 +0,0 @@
1
- import{BufferError as e,ParseError as t}from"./errors.mjs";function n(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-65+10:e>=97&&e<=102?e-97+10:-1}const r=[0,0,1,1,2,2,3,3,-1,4,4,5,5,-1,6,6,7,7,-1,8,8,9,9,-1,10,10,11,11,12,12,13,13,14,14,15,15],i=[!0,!1,!0,!1,!0,!1,!0,!1,!1,!0,!1,!0,!1,!1,!0,!1,!0,!1,!1,!0,!1,!0,!1,!1,!0,!1,!0,!1,!0,!1,!0,!1,!0,!1,!0,!1],a=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function o(t){if(t.length!==16)throw new e(`UUID_BYTES_INVALID_LENGTH`,`UUID bytes must be exactly 16 bytes, got ${t.length}`);return s(t)}function s(e){return a[e[0]]+a[e[1]]+a[e[2]]+a[e[3]]+`-`+a[e[4]]+a[e[5]]+`-`+a[e[6]]+a[e[7]]+`-`+a[e[8]]+a[e[9]]+`-`+a[e[10]]+a[e[11]]+a[e[12]]+a[e[13]]+a[e[14]]+a[e[15]]}function c(e){if(e.length!==36)throw new t(`UUID_INVALID_LENGTH`,`UUID string must be 36 characters, got ${e.length}`);if(e[8]!==`-`||e[13]!==`-`||e[18]!==`-`||e[23]!==`-`)throw new t(`UUID_INVALID_SEPARATORS`,`UUID string has invalid separators at positions 8, 13, 18, 23. Received: "${e}"`);let a=new Uint8Array(16);for(let o=0;o<36;o+=1){let s=r[o];if(s===-1)continue;let c=n(e.charCodeAt(o));if(c===-1)throw new t(`UUID_INVALID_HEX_CHAR`,`UUID string contains invalid hex character at position ${o}`);i[o]?a[s]=c<<4:a[s]|=c}return a}export{s as n,c as r,o as t};
2
- //# sourceMappingURL=uuid-CnQIYoQi.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uuid-CnQIYoQi.mjs","names":[],"sources":["../src/uuid/common/hex.ts","../src/uuid/common/uuid.ts"],"sourcesContent":["// ASCII code ranges for hex character validation\nconst ASCII_0 = 48 // '0'\nconst ASCII_9 = 57 // '9'\nconst ASCII_A = 65 // 'A'\nconst ASCII_F = 70 // 'F'\nconst ASCII_a = 97 // 'a'\nconst ASCII_f = 102 // 'f'\n\n/**\n * Convert a hex character ASCII code to its numeric value (0-15).\n * Returns -1 for invalid hex characters.\n */\nexport function hexValue(code: number): number {\n if (code >= ASCII_0 && code <= ASCII_9) {\n return code - ASCII_0\n }\n if (code >= ASCII_A && code <= ASCII_F) {\n return code - ASCII_A + 10\n }\n if (code >= ASCII_a && code <= ASCII_f) {\n return code - ASCII_a + 10\n }\n return -1 // Invalid hex character\n}\n","import { BufferError, ParseError } from '../../errors'\nimport { hexValue } from './hex'\n\nconst UUID_BYTE_LENGTH = 16\nconst UUID_STRING_LENGTH = 36\n\n// Mapping from UUID string position to byte index.\n// -1 indicates a dash position that should be skipped.\n// This avoids intermediate string allocations during parsing.\nconst UUID_CHAR_TO_BYTE: number[] = [\n 0,\n 0,\n 1,\n 1,\n 2,\n 2,\n 3,\n 3, // chars 0-7 → bytes 0-3\n -1, // char 8 is '-'\n 4,\n 4,\n 5,\n 5, // chars 9-12 → bytes 4-5\n -1, // char 13 is '-'\n 6,\n 6,\n 7,\n 7, // chars 14-17 → bytes 6-7\n -1, // char 18 is '-'\n 8,\n 8,\n 9,\n 9, // chars 19-22 → bytes 8-9\n -1, // char 23 is '-'\n 10,\n 10,\n 11,\n 11,\n 12,\n 12,\n 13,\n 13,\n 14,\n 14,\n 15,\n 15, // chars 24-35 → bytes 10-15\n]\n\n// Whether each position is the high nibble (true) or low nibble (false)\nconst UUID_CHAR_IS_HIGH: boolean[] = [\n true,\n false,\n true,\n false,\n true,\n false,\n true,\n false, // chars 0-7\n false, // dash (ignored)\n true,\n false,\n true,\n false, // chars 9-12\n false, // dash\n true,\n false,\n true,\n false, // chars 14-17\n false, // dash\n true,\n false,\n true,\n false, // chars 19-22\n false, // dash\n true,\n false,\n true,\n false,\n true,\n false,\n true,\n false,\n true,\n false,\n true,\n false, // chars 24-35\n]\n\n// Pre-computed lookup table for byte-to-hex conversion (0x00 -> \"00\", 0xff -> \"ff\")\n//\n// Note: this table must remain defined in the same module as `formatUuid`, otherwise the v8 optimizer\n// will cause a performance drop of ~36%.\nconst HEX_TABLE: string[] = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'))\n\nexport function formatUuid(bytes: Uint8Array): string {\n if (bytes.length !== UUID_BYTE_LENGTH) {\n throw new BufferError(\n 'UUID_BYTES_INVALID_LENGTH',\n `UUID bytes must be exactly ${UUID_BYTE_LENGTH} bytes, got ${bytes.length}`,\n )\n }\n\n return formatUuidUnchecked(bytes)\n}\n\nexport function formatUuidUnchecked(bytes: Uint8Array): string {\n // Direct string concatenation - optimized for V8's string builder.\n // This approach avoids loop overhead and intermediate allocations.\n // See: https://github.com/uuidjs/uuid/pull/434\n return (\n HEX_TABLE[bytes[0]] +\n HEX_TABLE[bytes[1]] +\n HEX_TABLE[bytes[2]] +\n HEX_TABLE[bytes[3]] +\n '-' +\n HEX_TABLE[bytes[4]] +\n HEX_TABLE[bytes[5]] +\n '-' +\n HEX_TABLE[bytes[6]] +\n HEX_TABLE[bytes[7]] +\n '-' +\n HEX_TABLE[bytes[8]] +\n HEX_TABLE[bytes[9]] +\n '-' +\n HEX_TABLE[bytes[10]] +\n HEX_TABLE[bytes[11]] +\n HEX_TABLE[bytes[12]] +\n HEX_TABLE[bytes[13]] +\n HEX_TABLE[bytes[14]] +\n HEX_TABLE[bytes[15]]\n )\n}\n\nexport function parseUuid(value: string): Uint8Array {\n if (value.length !== UUID_STRING_LENGTH) {\n throw new ParseError('UUID_INVALID_LENGTH', `UUID string must be 36 characters, got ${value.length}`)\n }\n\n // Validate separator positions directly (more efficient than full loop)\n if (value[8] !== '-' || value[13] !== '-' || value[18] !== '-' || value[23] !== '-') {\n throw new ParseError(\n 'UUID_INVALID_SEPARATORS',\n `UUID string has invalid separators at positions 8, 13, 18, 23. Received: \"${value}\"`,\n )\n }\n\n // Parse bytes directly from UUID string without intermediate string allocations.\n // This avoids the 9 allocations (5 slices + 4 concatenations) of the naive approach.\n const bytes = new Uint8Array(UUID_BYTE_LENGTH)\n\n for (let i = 0; i < UUID_STRING_LENGTH; i += 1) {\n const byteIdx = UUID_CHAR_TO_BYTE[i]\n if (byteIdx === -1) continue // Skip dash positions\n\n const nibble = hexValue(value.charCodeAt(i))\n if (nibble === -1) {\n throw new ParseError('UUID_INVALID_HEX_CHAR', `UUID string contains invalid hex character at position ${i}`)\n }\n\n if (UUID_CHAR_IS_HIGH[i]) {\n bytes[byteIdx] = nibble << 4\n } else {\n bytes[byteIdx] |= nibble\n }\n }\n\n return bytes\n}\n"],"mappings":"2DAYA,SAAgB,EAAS,EAAsB,CAU7C,OATI,GAAQ,IAAW,GAAQ,GACtB,EAAO,GAEZ,GAAQ,IAAW,GAAQ,GACtB,EAAO,GAAU,GAEtB,GAAQ,IAAW,GAAQ,IACtB,EAAO,GAAU,GAEnB,EACT,CCpBA,MAMM,EAA8B,CAClC,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,GACA,EACA,EACA,EACA,EACA,GACA,EACA,EACA,EACA,EACA,GACA,EACA,EACA,EACA,EACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,EACF,EAGM,EAA+B,CACnC,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,EACF,EAMM,EAAsB,MAAM,KAAK,CAAE,OAAQ,GAAI,GAAI,EAAG,IAAM,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAG,GAAG,CAAC,EAEjG,SAAgB,EAAW,EAA2B,CACpD,GAAI,EAAM,SAAW,GACnB,MAAM,IAAI,EACR,4BACA,4CAA6D,EAAM,QACrE,EAGF,OAAO,EAAoB,CAAK,CAClC,CAEA,SAAgB,EAAoB,EAA2B,CAI7D,OACE,EAAU,EAAM,IAChB,EAAU,EAAM,IAChB,EAAU,EAAM,IAChB,EAAU,EAAM,IAChB,IACA,EAAU,EAAM,IAChB,EAAU,EAAM,IAChB,IACA,EAAU,EAAM,IAChB,EAAU,EAAM,IAChB,IACA,EAAU,EAAM,IAChB,EAAU,EAAM,IAChB,IACA,EAAU,EAAM,KAChB,EAAU,EAAM,KAChB,EAAU,EAAM,KAChB,EAAU,EAAM,KAChB,EAAU,EAAM,KAChB,EAAU,EAAM,IAEpB,CAEA,SAAgB,EAAU,EAA2B,CACnD,GAAI,EAAM,SAAW,GACnB,MAAM,IAAI,EAAW,sBAAuB,0CAA0C,EAAM,QAAQ,EAItG,GAAI,EAAM,KAAO,KAAO,EAAM,MAAQ,KAAO,EAAM,MAAQ,KAAO,EAAM,MAAQ,IAC9E,MAAM,IAAI,EACR,0BACA,6EAA6E,EAAM,EACrF,EAKF,IAAM,EAAQ,IAAI,WAAW,EAAgB,EAE7C,IAAK,IAAI,EAAI,EAAG,EAAI,GAAoB,GAAK,EAAG,CAC9C,IAAM,EAAU,EAAkB,GAClC,GAAI,IAAY,GAAI,SAEpB,IAAM,EAAS,EAAS,EAAM,WAAW,CAAC,CAAC,EAC3C,GAAI,IAAW,GACb,MAAM,IAAI,EAAW,wBAAyB,0DAA0D,GAAG,EAGzG,EAAkB,GACpB,EAAM,GAAW,GAAU,EAE3B,EAAM,IAAY,CAEtB,CAEA,OAAO,CACT"}