@anizoptera/uuid-slug 0.3.0 → 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 (202) hide show
  1. package/LICENSE +54 -31
  2. package/README.md +373 -324
  3. package/dist/alphabet.d.ts +5 -17
  4. package/dist/alphabet.d.ts.map +1 -1
  5. package/dist/alphabet.js +146 -112
  6. package/dist/alphabet.js.map +1 -1
  7. package/dist/base64url-name.d.ts +7 -0
  8. package/dist/base64url-name.d.ts.map +1 -0
  9. package/dist/base64url-name.js +8 -0
  10. package/dist/base64url-name.js.map +1 -0
  11. package/dist/errors.d.ts +50 -9
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/errors.js +145 -63
  14. package/dist/errors.js.map +1 -1
  15. package/dist/feistel.js +29 -95
  16. package/dist/feistel.js.map +1 -1
  17. package/dist/generation-options.js +20 -0
  18. package/dist/generation-options.js.map +1 -0
  19. package/dist/index.d.ts +22 -10
  20. package/dist/index.js +21 -9
  21. package/dist/instant.js +83 -0
  22. package/dist/instant.js.map +1 -0
  23. package/dist/mask-handle.d.ts +16 -0
  24. package/dist/mask-handle.d.ts.map +1 -0
  25. package/dist/mask-handle.js +60 -0
  26. package/dist/mask-handle.js.map +1 -0
  27. package/dist/mask.d.ts +27 -0
  28. package/dist/mask.d.ts.map +1 -0
  29. package/dist/mask.js +151 -95
  30. package/dist/mask.js.map +1 -1
  31. package/dist/masking-codec-protocol.js +23 -0
  32. package/dist/masking-codec-protocol.js.map +1 -0
  33. package/dist/masking-codec-types.d.ts +245 -0
  34. package/dist/masking-codec-types.d.ts.map +1 -0
  35. package/dist/masking-codec.d.ts +19 -0
  36. package/dist/masking-codec.d.ts.map +1 -0
  37. package/dist/masking-codec.js +391 -0
  38. package/dist/masking-codec.js.map +1 -0
  39. package/dist/migration.js +114 -51
  40. package/dist/migration.js.map +1 -1
  41. package/dist/node/runtime.js +39 -0
  42. package/dist/node/runtime.js.map +1 -0
  43. package/dist/payload.d.ts +7 -0
  44. package/dist/payload.d.ts.map +1 -0
  45. package/dist/payload.js +118 -0
  46. package/dist/payload.js.map +1 -0
  47. package/dist/runtime/pool.js +21 -46
  48. package/dist/runtime/pool.js.map +1 -1
  49. package/dist/runtime/portable.js +27 -0
  50. package/dist/runtime/portable.js.map +1 -0
  51. package/dist/sentinel.js +10 -0
  52. package/dist/sentinel.js.map +1 -0
  53. package/dist/siphash.js +20 -99
  54. package/dist/siphash.js.map +1 -1
  55. package/dist/slug.d.ts +169 -0
  56. package/dist/slug.d.ts.map +1 -0
  57. package/dist/slug.js +268 -0
  58. package/dist/slug.js.map +1 -0
  59. package/dist/timestamp.d.ts +19 -0
  60. package/dist/timestamp.d.ts.map +1 -0
  61. package/dist/timestamp.js +44 -0
  62. package/dist/timestamp.js.map +1 -0
  63. package/dist/types.d.ts +480 -200
  64. package/dist/types.d.ts.map +1 -1
  65. package/dist/types.js +8 -0
  66. package/dist/types.js.map +1 -0
  67. package/dist/uuid-value-protocol.js +46 -0
  68. package/dist/uuid-value-protocol.js.map +1 -0
  69. package/dist/uuid-value.d.ts +17 -0
  70. package/dist/uuid-value.d.ts.map +1 -0
  71. package/dist/uuid-value.js +127 -0
  72. package/dist/uuid-value.js.map +1 -0
  73. package/dist/uuid.d.ts +51 -64
  74. package/dist/uuid.d.ts.map +1 -1
  75. package/dist/uuid.js +203 -199
  76. package/dist/uuid.js.map +1 -1
  77. package/dist/v4-slug.d.ts +16 -0
  78. package/dist/v4-slug.d.ts.map +1 -0
  79. package/dist/v4-slug.js +16 -0
  80. package/dist/v4-slug.js.map +1 -0
  81. package/dist/v4.d.ts +42 -0
  82. package/dist/v4.d.ts.map +1 -0
  83. package/dist/v4.js +85 -0
  84. package/dist/v4.js.map +1 -0
  85. package/dist/v7-bounds.d.ts +36 -0
  86. package/dist/v7-bounds.d.ts.map +1 -0
  87. package/dist/v7-bounds.js +49 -0
  88. package/dist/v7-bounds.js.map +1 -0
  89. package/dist/v7-generator-input.js +75 -0
  90. package/dist/v7-generator-input.js.map +1 -0
  91. package/dist/v7-generator.d.ts +43 -0
  92. package/dist/v7-generator.d.ts.map +1 -0
  93. package/dist/v7-generator.js +105 -0
  94. package/dist/v7-generator.js.map +1 -0
  95. package/dist/v7-keyless.d.ts +46 -0
  96. package/dist/v7-keyless.d.ts.map +1 -0
  97. package/dist/v7-keyless.js +106 -0
  98. package/dist/v7-keyless.js.map +1 -0
  99. package/dist/v7-payload.js +54 -0
  100. package/dist/v7-payload.js.map +1 -0
  101. package/dist/v7-slug.d.ts +46 -0
  102. package/dist/v7-slug.d.ts.map +1 -0
  103. package/dist/v7-slug.js +127 -0
  104. package/dist/v7-slug.js.map +1 -0
  105. package/dist/v7-timestamp.js +9 -0
  106. package/dist/v7-timestamp.js.map +1 -0
  107. package/dist/v7-value-options.js +28 -0
  108. package/dist/v7-value-options.js.map +1 -0
  109. package/dist/v7-value.d.ts +23 -0
  110. package/dist/v7-value.d.ts.map +1 -0
  111. package/dist/v7-value.js +31 -0
  112. package/dist/v7-value.js.map +1 -0
  113. package/dist/v7.js +127 -171
  114. package/dist/v7.js.map +1 -1
  115. package/package.json +15 -8
  116. package/src/alphabet.ts +456 -27
  117. package/src/base64url-name.ts +5 -0
  118. package/src/errors.ts +373 -37
  119. package/src/feistel.ts +69 -56
  120. package/src/generation-options.ts +48 -0
  121. package/src/index.ts +134 -80
  122. package/src/instant.ts +196 -0
  123. package/src/keyless.ts +7 -134
  124. package/src/mask-handle.ts +141 -0
  125. package/src/mask.ts +354 -129
  126. package/src/masking-codec-protocol.ts +29 -0
  127. package/src/masking-codec-types.ts +380 -0
  128. package/src/masking-codec.ts +923 -0
  129. package/src/migration.ts +195 -42
  130. package/src/payload.ts +321 -0
  131. package/src/runtime/bun.ts +30 -49
  132. package/src/runtime/node.ts +43 -24
  133. package/src/runtime/pool.ts +49 -21
  134. package/src/runtime/portable.ts +68 -0
  135. package/src/runtime/types.ts +23 -35
  136. package/src/sentinel.ts +13 -0
  137. package/src/siphash.ts +5 -4
  138. package/src/slug.ts +884 -0
  139. package/src/timestamp.ts +122 -0
  140. package/src/types.ts +759 -205
  141. package/src/uuid-value-protocol.ts +77 -0
  142. package/src/uuid-value.ts +341 -0
  143. package/src/uuid.ts +514 -234
  144. package/src/v4-slug.ts +27 -0
  145. package/src/v4.ts +234 -0
  146. package/src/v7-bounds.ts +171 -0
  147. package/src/v7-generator-input.ts +169 -0
  148. package/src/v7-generator.ts +245 -0
  149. package/src/v7-keyless.ts +354 -0
  150. package/src/v7-payload.ts +121 -0
  151. package/src/v7-slug.ts +293 -0
  152. package/src/v7-timestamp.ts +21 -0
  153. package/src/v7-value-options.ts +62 -0
  154. package/src/v7-value.ts +54 -0
  155. package/src/v7.ts +377 -200
  156. package/dist/base64url.d.ts +0 -20
  157. package/dist/base64url.d.ts.map +0 -1
  158. package/dist/base64url.js +0 -33
  159. package/dist/base64url.js.map +0 -1
  160. package/dist/codec.d.ts +0 -17
  161. package/dist/codec.d.ts.map +0 -1
  162. package/dist/codec.js +0 -192
  163. package/dist/codec.js.map +0 -1
  164. package/dist/keyless.d.ts +0 -31
  165. package/dist/keyless.d.ts.map +0 -1
  166. package/dist/keyless.js +0 -93
  167. package/dist/keyless.js.map +0 -1
  168. package/dist/legacy-mask.js +0 -55
  169. package/dist/legacy-mask.js.map +0 -1
  170. package/dist/node/alphabet.js +0 -130
  171. package/dist/node/base64url.js +0 -31
  172. package/dist/node/codec.js +0 -190
  173. package/dist/node/errors.js +0 -78
  174. package/dist/node/feistel.js +0 -103
  175. package/dist/node/index.js +0 -10
  176. package/dist/node/keyless.js +0 -91
  177. package/dist/node/legacy-mask.js +0 -53
  178. package/dist/node/mask.js +0 -106
  179. package/dist/node/migration.js +0 -64
  180. package/dist/node/runtime/node.js +0 -33
  181. package/dist/node/runtime/pool.js +0 -53
  182. package/dist/node/schema.js +0 -214
  183. package/dist/node/siphash.js +0 -106
  184. package/dist/node/uuid.js +0 -226
  185. package/dist/node/v7.js +0 -185
  186. package/dist/node/yield.js +0 -20
  187. package/dist/runtime/web.js +0 -39
  188. package/dist/runtime/web.js.map +0 -1
  189. package/dist/schema.d.ts +0 -20
  190. package/dist/schema.d.ts.map +0 -1
  191. package/dist/schema.js +0 -216
  192. package/dist/schema.js.map +0 -1
  193. package/dist/v7.d.ts +0 -12
  194. package/dist/v7.d.ts.map +0 -1
  195. package/dist/yield.js +0 -22
  196. package/dist/yield.js.map +0 -1
  197. package/src/base64url.ts +0 -41
  198. package/src/codec.ts +0 -320
  199. package/src/legacy-mask.ts +0 -25
  200. package/src/runtime/web.ts +0 -48
  201. package/src/schema.ts +0 -300
  202. package/src/yield.ts +0 -22
package/dist/errors.js CHANGED
@@ -1,80 +1,162 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- // @anizoptera/uuid-slug 0.3.0 | https://github.com/Anizoptera/uuid-slug#readme
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
3
  //#region src/errors.ts
4
- /** Consumers can enumerate error codes at runtime without duplicating the type's vocabulary. */
5
- const UUID_SLUG_ERROR_CODES = [
6
- "aborted",
7
- "invalid_base32",
8
- "invalid_base64url",
9
- "invalid_buffer",
10
- "invalid_mask_schema",
11
- "invalid_timestamp",
12
- "invalid_uuid",
13
- "invalid_uuid_slug",
14
- "invalid_uuid_version",
15
- "rng_unavailable",
16
- "stale_uuid"
17
- ];
4
+ const e = "aborted", t = "invalid_base32hex", n = "invalid_base64url", r = "invalid_buffer", i = "invalid_mask", a = "invalid_options", o = "invalid_sentinel", s = "invalid_timestamp", c = "invalid_uuid", l = "invalid_uuid_slug", u = "invalid_uuid_version", d = "rng_unavailable", f = "timestamp_outside_window", p = /*#__PURE__*/ Object.freeze([
5
+ e,
6
+ t,
7
+ n,
8
+ r,
9
+ i,
10
+ a,
11
+ o,
12
+ s,
13
+ c,
14
+ l,
15
+ u,
16
+ d,
17
+ f
18
+ ]), m = /*#__PURE__*/ new Set(p), h = "UuidSlugError", g = "__failure", _ = "object", v = "byteLength", y = "Random byte generation failed.", b = Error.isError, x = /*#__PURE__*/ Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag), S = /*#__PURE__*/ Object.getOwnPropertyDescriptor(DataView.prototype, v), C = /*#__PURE__*/ Object.getOwnPropertyDescriptor(DataView.prototype, "byteOffset"), w = /*#__PURE__*/ Object.getOwnPropertyDescriptor(DataView.prototype, "buffer"), T = /*#__PURE__*/ Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, v);
18
19
  var UuidSlugError = class extends Error {
19
20
  code;
20
- constructor(code, message, options) {
21
- super(message, options);
22
- this.name = "UuidSlugError";
23
- this.code = code;
21
+ constructor(e, t, n) {
22
+ super(t, n), this.name = h, this.code = e;
24
23
  }
25
24
  };
26
- var UuidRuntimeError = class extends UuidSlugError {
27
- constructor(message, options) {
28
- super("rng_unavailable", message, options);
29
- this.name = "UuidRuntimeError";
25
+ Object.defineProperty(UuidSlugError.prototype, g, { value: !0 });
26
+ /*#__NO_SIDE_EFFECTS__*/
27
+ function hasErrorBrand(e) {
28
+ try {
29
+ if (e instanceof Error) return !0;
30
+ } catch {}
31
+ try {
32
+ return b ? b(e) : Object.prototype.toString.call(e) === "[object Error]";
33
+ } catch {
34
+ return !1;
30
35
  }
31
- };
32
- /**
33
- * The bridge from this package's `Error | T` return convention to the generator convention, where
34
- * a failure throws. Shared rather than repeated because every module that has both conventions
35
- * meeting in it needs exactly this, and a local copy is one `instanceof` away from being written
36
- * as a truthiness test that swallows a legitimate falsy result.
37
- */
38
- function errorOrThrow(value) {
39
- if (value instanceof Error) throw value;
40
- return value;
41
- }
42
- /**
43
- * The one range check for every entry point that reads or writes a caller's buffer at an offset.
44
- *
45
- * `Number.isInteger` is the load-bearing half and the reason this is shared rather than repeated.
46
- * The obvious spelling — `offset < 0 || offset + need > capacity` — passes a fractional or
47
- * NaN offset, because both of its comparisons are false for NaN and neither notices `0.5`. What
48
- * follows is worse than a wrong answer: `bytes[0.5] = x` is not a store, so the write SILENTLY does
49
- * nothing while the guard reports success, and an id can come back half-written with the caller's
50
- * stale bytes in the rest of it. A string offset defeats the same test from the other side, by
51
- * concatenation: `"4" + 16` is `"416"`, which is not greater than any plausible length.
52
- *
53
- * Seven near-identical copies of that test existed across this package and not one checked
54
- * integrality — the copying is why. One copy is what stops the class returning.
55
- */
56
- function checkRange(capacity, offset, need) {
57
- if (!Number.isInteger(offset)) return new UuidSlugError("invalid_buffer", `Buffer offset must be a whole number, got ${typeof offset} ${String(offset)}.`);
58
- if (offset < 0 || offset + need > capacity) return new UuidSlugError("invalid_buffer", `Buffer needs ${need} bytes at offset ${offset}, but holds ${capacity}.`);
59
- }
60
- /** Preserve failures from an injected or platform entropy source without changing successful draws. */
61
- function fillRandomBytes(fill, bytes) {
36
+ }
37
+ /*#__NO_SIDE_EFFECTS__*/
38
+ function isUuidSlugError(e) {
39
+ if (typeof e != _ || e === null) return !1;
40
+ let t = e;
41
+ try {
42
+ if (t.__failure === !0) return !0;
43
+ } catch {}
44
+ if (!/* @__PURE__ */ hasErrorBrand(t)) return !1;
62
45
  try {
63
- fill(bytes);
46
+ return Reflect.get(t, "name") === h && m.has(Reflect.get(t, "code"));
47
+ } catch {
48
+ return !1;
49
+ }
50
+ }
51
+ /*#__NO_SIDE_EFFECTS__*/
52
+ function exactLocalUuidBytes(e) {
53
+ try {
54
+ return e instanceof Uint8Array && e.length === 16 ? e : void 0;
55
+ } catch {
56
+ return;
57
+ }
58
+ }
59
+ /*#__NO_SIDE_EFFECTS__*/
60
+ function isError(e) {
61
+ return typeof e != _ || e === null ? !1 : /* @__PURE__ */ hasErrorBrand(e);
62
+ }
63
+ /*#__NO_SIDE_EFFECTS__*/
64
+ function isTagged(e, t) {
65
+ return Object.prototype.toString.call(e) === t || typeof e == "object" && !!e && Object.hasOwn(e, Symbol.toStringTag);
66
+ }
67
+ /*#__NO_SIDE_EFFECTS__*/
68
+ function stringInput(e) {
69
+ if (typeof e == "string") return e;
70
+ if (typeof e == "object" && e) try {
71
+ return String.prototype.valueOf.call(e);
72
+ } catch {
64
73
  return;
65
- } catch (cause) {
66
- return new UuidRuntimeError("Random byte generation failed.", { cause });
67
74
  }
68
75
  }
69
- /** Read once so a failing clock keeps its original cause and successful clocks have one observation. */
70
- function readClock(clock) {
76
+ function normalizeUuidStringInput(e) {
77
+ return typeof e == "string" ? e : /* @__PURE__ */ stringInput(e) ?? /* @__PURE__ */ invalidUuidStringInput(e);
78
+ }
79
+ function normalizeUuidSlugInput(e) {
80
+ return typeof e == "string" ? e : /* @__PURE__ */ stringInput(e) ?? /* @__PURE__ */ invalidUuidSlugInput(e);
81
+ }
82
+ function diagnosticValue(e) {
83
+ return typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" || typeof e == "boolean" || typeof e == "symbol" ? String(e) : e === null ? "null" : typeof e;
84
+ }
85
+ function isPlainRecord(e) {
86
+ if (Array.isArray(e)) return !1;
87
+ let t = Object.getPrototypeOf(e);
88
+ return t === null || Object.getPrototypeOf(t) === null;
89
+ }
90
+ /*#__NO_SIDE_EFFECTS__*/
91
+ function isUint8Array(e) {
92
+ return ArrayBuffer.isView(e) && (e instanceof Uint8Array || x?.get?.call(e) === "Uint8Array");
93
+ }
94
+ function isSuccessfulUuidBytes(e) {
95
+ if (!ArrayBuffer.isView(e)) return !1;
96
+ try {
97
+ return e[g] !== !0;
98
+ } catch {
99
+ return !0;
100
+ }
101
+ }
102
+ function uuidByteView(e) {
103
+ if (/* @__PURE__ */ isUint8Array(e)) return e;
104
+ try {
105
+ if (ArrayBuffer.isView(e) && (e instanceof DataView || /* @__PURE__ */ isTagged(e, "[object DataView]")) && S?.get?.call(e) !== void 0) return new Uint8Array(w?.get?.call(e), C?.get?.call(e), S.get.call(e));
106
+ if ((e instanceof ArrayBuffer || /* @__PURE__ */ isTagged(e, "[object ArrayBuffer]")) && T?.get?.call(e) !== void 0) return new Uint8Array(e);
107
+ } catch {}
108
+ }
109
+ /*#__NO_SIDE_EFFECTS__*/
110
+ function findUnknownOption(e, t) {
111
+ for (let n of Object.keys(e)) if (!Object.hasOwn(t, n)) return n;
112
+ }
113
+ /*#__NO_SIDE_EFFECTS__*/
114
+ function checkRange(e, t, n) {
115
+ if (!Number.isInteger(t)) return new UuidSlugError(r, `Buffer offset must be a whole number, got ${typeof t} ${diagnosticValue(t)}.`);
116
+ if (t < 0 || t + n > e) return new UuidSlugError(r, `Buffer needs ${n} bytes at offset ${t}, but holds ${e}.`);
117
+ }
118
+ /*#__NO_SIDE_EFFECTS__*/
119
+ function checkByteRange(e, t, n) {
120
+ return /* @__PURE__ */ isUint8Array(e) ? /* @__PURE__ */ checkRange(e.length, t, n) : /* @__PURE__ */ isUuidSlugError(e) ? e : new UuidSlugError(r, "Buffer must be a Uint8Array.");
121
+ }
122
+ /*#__NO_SIDE_EFFECTS__*/
123
+ function invalidUuidStringInput(e) {
124
+ return /* @__PURE__ */ isUuidSlugError(e) ? e : new UuidSlugError(c, "UUID must be text.");
125
+ }
126
+ /*#__NO_SIDE_EFFECTS__*/
127
+ function invalidUuidSlugInput(e) {
128
+ return /* @__PURE__ */ isUuidSlugError(e) ? e : new UuidSlugError(l, "UUID slug must be a string.");
129
+ }
130
+ const randomFailure = /* @__NO_SIDE_EFFECTS__ */ (e) => {
131
+ if (e !== void 0) return /* @__PURE__ */ isUuidSlugError(e) ? e : /* @__PURE__ */ isError(e) ? new UuidSlugError(d, y, { cause: e }) : void 0;
132
+ };
133
+ function fillRandomBytes(e, t) {
134
+ try {
135
+ return /* @__PURE__ */ randomFailure(e(t));
136
+ } catch (e) {
137
+ return new UuidSlugError(d, y, { cause: e });
138
+ }
139
+ }
140
+ function generatedOrThrow(e) {
141
+ if (e instanceof Error) throw e;
142
+ return e;
143
+ }
144
+ /*#__NO_SIDE_EFFECTS__*/
145
+ function failedFallback(e, t, n) {
146
+ return new UuidSlugError(t.code, t.message, { cause: AggregateError([e, t], n) });
147
+ }
148
+ function portableAfterNative(e, t, n, r) {
149
+ let i = t(n);
150
+ return i instanceof Error ? /* @__PURE__ */ failedFallback(e, i, `Native and portable ${r} failed.`) : i;
151
+ }
152
+ function readClock(e) {
71
153
  try {
72
- return clock();
73
- } catch (cause) {
74
- return new UuidSlugError("invalid_timestamp", "Clock reading failed.", { cause });
154
+ return e();
155
+ } catch (e) {
156
+ return new UuidSlugError(s, "Clock reading failed.", { cause: e });
75
157
  }
76
158
  }
77
159
  //#endregion
78
- export { UUID_SLUG_ERROR_CODES, UuidRuntimeError, UuidSlugError, checkRange, errorOrThrow, fillRandomBytes, readClock };
160
+ export { e as ABORTED, p as ERROR_CODES, g as ERROR_MARKER, t as INVALID_BASE32HEX, n as INVALID_BASE64URL, r as INVALID_BUFFER, i as INVALID_MASK, a as INVALID_OPTIONS, o as INVALID_SENTINEL, s as INVALID_TIMESTAMP, c as INVALID_UUID, l as INVALID_UUID_SLUG, u as INVALID_UUID_VERSION, d as RNG_UNAVAILABLE, f as TIMESTAMP_OUTSIDE_WINDOW, UuidSlugError, checkByteRange, checkRange, diagnosticValue, exactLocalUuidBytes, failedFallback, fillRandomBytes, findUnknownOption, generatedOrThrow, invalidUuidSlugInput, invalidUuidStringInput, isError, isPlainRecord, isSuccessfulUuidBytes, isUint8Array, isUuidSlugError, normalizeUuidSlugInput, normalizeUuidStringInput, portableAfterNative, randomFailure, readClock, stringInput, uuidByteView };
79
161
 
80
162
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** Consumers can enumerate error codes at runtime without duplicating the type's vocabulary. */\nexport const UUID_SLUG_ERROR_CODES = [\n \"aborted\",\n \"invalid_base32\",\n \"invalid_base64url\",\n \"invalid_buffer\",\n \"invalid_mask_schema\",\n \"invalid_timestamp\",\n \"invalid_uuid\",\n \"invalid_uuid_slug\",\n \"invalid_uuid_version\",\n \"rng_unavailable\",\n \"stale_uuid\",\n] as const;\n\nexport type UuidSlugErrorCode = (typeof UUID_SLUG_ERROR_CODES)[number];\n\nexport class UuidSlugError extends Error {\n readonly code: UuidSlugErrorCode;\n\n constructor(code: UuidSlugErrorCode, message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = \"UuidSlugError\";\n this.code = code;\n }\n}\n\nexport class UuidRuntimeError extends UuidSlugError {\n constructor(message: string, options?: ErrorOptions) {\n super(\"rng_unavailable\", message, options);\n this.name = \"UuidRuntimeError\";\n }\n}\n\n/**\n * The bridge from this package's `Error | T` return convention to the generator convention, where\n * a failure throws. Shared rather than repeated because every module that has both conventions\n * meeting in it needs exactly this, and a local copy is one `instanceof` away from being written\n * as a truthiness test that swallows a legitimate falsy result.\n */\nexport function errorOrThrow<T>(value: UuidSlugError | T): T {\n if (value instanceof Error) throw value;\n return value;\n}\n\n/**\n * The one range check for every entry point that reads or writes a caller's buffer at an offset.\n *\n * `Number.isInteger` is the load-bearing half and the reason this is shared rather than repeated.\n * The obvious spelling — `offset < 0 || offset + need > capacity` — passes a fractional or\n * NaN offset, because both of its comparisons are false for NaN and neither notices `0.5`. What\n * follows is worse than a wrong answer: `bytes[0.5] = x` is not a store, so the write SILENTLY does\n * nothing while the guard reports success, and an id can come back half-written with the caller's\n * stale bytes in the rest of it. A string offset defeats the same test from the other side, by\n * concatenation: `\"4\" + 16` is `\"416\"`, which is not greater than any plausible length.\n *\n * Seven near-identical copies of that test existed across this package and not one checked\n * integrality — the copying is why. One copy is what stops the class returning.\n */\nexport function checkRange(\n capacity: number,\n offset: number,\n need: number,\n): undefined | UuidSlugError {\n if (!Number.isInteger(offset))\n return new UuidSlugError(\n \"invalid_buffer\",\n `Buffer offset must be a whole number, got ${typeof offset} ${String(offset)}.`,\n );\n if (offset < 0 || offset + need > capacity)\n return new UuidSlugError(\n \"invalid_buffer\",\n `Buffer needs ${need} bytes at offset ${offset}, but holds ${capacity}.`,\n );\n return undefined;\n}\n\n/** Preserve failures from an injected or platform entropy source without changing successful draws. */\nexport function fillRandomBytes(\n fill: (bytes: Uint8Array<ArrayBuffer>) => void,\n bytes: Uint8Array<ArrayBuffer>,\n): UuidRuntimeError | undefined {\n try {\n fill(bytes);\n return undefined;\n } catch (cause) {\n return new UuidRuntimeError(\"Random byte generation failed.\", { cause });\n }\n}\n\n/** Read once so a failing clock keeps its original cause and successful clocks have one observation. */\nexport function readClock(clock: () => number): number | UuidSlugError {\n try {\n return clock();\n } catch (cause) {\n return new UuidSlugError(\"invalid_timestamp\", \"Clock reading failed.\", { cause });\n }\n}\n"],"mappings":";;;;AAGA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,IAAa,gBAAb,cAAmC,MAAM;CACvC;CAEA,YAAY,MAAyB,SAAiB,SAAwB;EAC5E,MAAM,SAAS,OAAO;EACtB,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;AAEA,IAAa,mBAAb,cAAsC,cAAc;CAClD,YAAY,SAAiB,SAAwB;EACnD,MAAM,mBAAmB,SAAS,OAAO;EACzC,KAAK,OAAO;CACd;AACF;;;;;;;AAQA,SAAgB,aAAgB,OAA6B;CAC3D,IAAI,iBAAiB,OAAO,MAAM;CAClC,OAAO;AACT;;;;;;;;;;;;;;;AAgBA,SAAgB,WACd,UACA,QACA,MAC2B;CAC3B,IAAI,CAAC,OAAO,UAAU,MAAM,GAC1B,OAAO,IAAI,cACT,kBACA,6CAA6C,OAAO,OAAO,GAAG,OAAO,MAAM,EAAE,EAC/E;CACF,IAAI,SAAS,KAAK,SAAS,OAAO,UAChC,OAAO,IAAI,cACT,kBACA,gBAAgB,KAAK,mBAAmB,OAAO,cAAc,SAAS,EACxE;AAEJ;;AAGA,SAAgB,gBACd,MACA,OAC8B;CAC9B,IAAI;EACF,KAAK,KAAK;EACV;CACF,SAAS,OAAO;EACd,OAAO,IAAI,iBAAiB,kCAAkC,EAAE,MAAM,CAAC;CACzE;AACF;;AAGA,SAAgB,UAAU,OAA6C;CACrE,IAAI;EACF,OAAO,MAAM;CACf,SAAS,OAAO;EACd,OAAO,IAAI,cAAc,qBAAqB,yBAAyB,EAAE,MAAM,CAAC;CAClF;AACF"}
1
+ {"version":3,"file":"errors.js","names":["ABORTED","INVALID_BASE32HEX","INVALID_BASE64URL","INVALID_BUFFER","INVALID_MASK","INVALID_OPTIONS","INVALID_SENTINEL","INVALID_TIMESTAMP","INVALID_UUID","INVALID_UUID_SLUG","INVALID_UUID_VERSION","RNG_UNAVAILABLE","TIMESTAMP_OUTSIDE_WINDOW","ERROR_CODES","ERROR_CODE_SET","ERROR_NAME","ERROR_MARKER","OBJECT_TYPE","BYTE_LENGTH_PROPERTY","RANDOM_FAILURE_MESSAGE","nativeIsError","typedArrayTagDescriptor","dataViewByteLengthDescriptor","dataViewByteOffsetDescriptor","dataViewBufferDescriptor","arrayBufferByteLengthDescriptor","message","options","code","candidate","value","\"__failure\"","tag","prototype","option","accepted","offset","need","capacity","bytes","fill","cause","result","fallback","nativeCause","fallbackArgument","operation","clock"],"sources":["../src/errors.ts"],"mappings":";;;AAGA,MAAaA,IAAU,WAEVC,IAAoB,qBAEpBC,IAAoB,qBAEpBC,IAAiB,kBAEjBC,IAAe,gBAEfC,IAAkB,mBAElBC,IAAmB,oBAEnBC,IAAoB,qBAEpBC,IAAe,gBAEfC,IAAoB,qBAEpBC,IAAuB,wBAEvBC,IAAkB,mBAElBC,IAA2B,4BAkB3BC,IAA0D,qBAAO,OAAO;CACnFb;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;AACF,CAAC,GAEKE,kBAAqD,IAAI,IAAID,CAAW,GACxEE,IAAa,iBAENC,IAAe,aACtBC,IAAc,UAIdC,IAAuB,cAEvBC,IAAyB,kCACzBC,IAAiB,MAAoD,SAErEC,IAAwC,qBAAO,yBACnD,OAAO,eAAe,WAAW,SAAS,GAC1C,OAAO,WACT,GACMC,IAA6C,qBAAO,yB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CAC9B,IAAIqB,MAAU,KAAA,GAEd,OADI,gCAAgBA,CAAK,IAAUA,IAC5B,wBAAQA,CAAK,IAChB,IAAI,cAAcnB,GAAiBQ,GAAwB,EAAE,OAAOW,EAAM,CAAC,IAC3E,KAAA;AACN;AAEA,SAAgB,gBACd,GACA,GAC2B;CAC3B,IAAI;EACF,OAAO,8BAAcU,EAAKD,CAAK,CAAC;CAClC,SAASE,GAAO;EACd,OAAO,IAAI,cAAc9B,GAAiBQ,GAAwB,EAAE,SAAM,CAAC;CAC7E;AACF;AAOA,SAAgB,iBAAwB,GAAsC;CAC5E,IAAIuB,aAAkB,OAAO,MAAMA;CACnC,OAAOA;AACT;;AAIA,SAAgB,eACd,GACA,GACA,GACe;CACf,OAAO,IAAI,cAAcC,EAAS,MAAMA,EAAS,SAAS,EACxD,OAAW,eAAe,CAACC,GAAaD,CAAQ,GAAGjB,CAAO,EAC5D,CAAC;AACH;AAGA,SAAgB,oBACd,GACA,GACA,GACA,GACwB;CACxB,IAAMgB,IAASC,EAASE,CAAgB;CACxC,OAAOH,aAAkB,QACrB,+BAAeE,GAAaF,GAAQ,uBAAuBI,EAAU,SAAS,IAC9EJ;AACN;AAGA,SAAgB,UAAU,GAA6C;CACrE,IAAI;EACF,OAAOK,EAAM;CACf,SAASN,GAAO;EACd,OAAO,IAAI,cAAclC,GAAmB,yBAAyB,EAAE,SAAM,CAAC;CAChF;AACF"}
package/dist/feistel.js CHANGED
@@ -1,103 +1,37 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- // @anizoptera/uuid-slug 0.3.0 | https://github.com/Anizoptera/uuid-slug#readme
3
- import { halfSipHash } from "./siphash.js";
4
- //#region src/feistel.ts
5
- /**
6
- * A 4-round Feistel network over the 16 UUID bytes, used as the mask's mixing step.
7
- *
8
- * Why a Feistel rather than the byte permutation plus XOR it replaces: that construction is a
9
- * monoalphabetic substitution — one output byte per input byte — so bytes the inputs share, the
10
- * outputs share too. Measured over 3000 ids, masked slugs of UUIDv7s created in the same second
11
- * held 4 of 16 bytes constant, the same hour 3, the same day 2. The timestamp the mask exists to
12
- * hide was still legible in the output. A Feistel diffuses every input bit across the whole
13
- * block, so no output byte is a function of one input byte: the same measurement yields 0 of 16.
14
- *
15
- * The bijection is the property being bought, and it holds whatever the round function does: 16
16
- * bytes map to 16 bytes and the inverse is the same routine with the round keys reversed, so
17
- * `mask` and `unmask` cannot drift apart.
18
- *
19
- * The round function is HalfSipHash-2-4 keyed per round. What that fixes: the previous round
20
- * function was `mix32(word ^ roundKey)` — a FIXED, PUBLIC, UNKEYED bijection with the key merely
21
- * XORed in front, so an attacker inverts it and reads `word ^ roundKey` directly. Luby-Rackoff
22
- * makes a four-round Feistel a strong pseudorandom permutation only when the round functions are
23
- * pseudorandom functions, which `mix32` is not, so the theorem said nothing about what shipped and
24
- * an earlier version of this comment cited it wrongly. A keyed PRF meets that hypothesis in kind,
25
- * which is what makes ROUNDS = 4 a justified number rather than an unexamined margin. It is still
26
- * NOT a proof about what ships: the theorem wants four INDEPENDENTLY sampled round functions, and
27
- * `schema.ts` derives all four key pairs from one 128-bit key. Read it as the design rationale it
28
- * is, and see `docs/design.md` for what masking does and does not promise.
29
- *
30
- * Measured 2026-08-12 on Bun, both directions, medians of 9: the swap costs 2.5x on the mixing step
31
- * alone (30.85M -> 12.43M mixes/s) and about a quarter of end-to-end masking throughput, because
32
- * mixing is roughly a fifth of a mask. HalfSipHash is FASTER per round than `mix32` — pure
33
- * add/xor/rotate against two `Math.imul` calls — and loses only by doing 14 rounds where the old
34
- * function did the equivalent of 4.
35
- *
36
- * Nor does any measurement in this repository grade the round count or the round function. Strict
37
- * avalanche across all input/output bit pairs, a same-millisecond burst where only a 12-bit counter
38
- * varies, and a single-difference differential all PASS a TWO-round network, so none of them can
39
- * separate a weak setting from a strong one. Their agreement is evidence about the instruments.
40
- * `test/siphash.test.ts` is the exception and the reason a published primitive was worth taking:
41
- * it checks the round function against 64 vectors somebody else computed, and that CAN fail.
42
- */
43
- /**
44
- * Round count. Wire-format-bearing: changing it changes every masked slug this package has ever
45
- * issued, so it moves only alongside a deliberate format change. Four is Luby-Rackoff's number,
46
- * which the round function now makes relevant — see the note above for why that is a rationale
47
- * rather than a proof.
48
- */
49
- const ROUNDS = 4;
50
- /**
51
- * The `lowbias32` finalizer: an integer hash with near-ideal avalanche for its size. No longer the
52
- * round function — see above — but still what `mask.ts` derives its check tag with, where the input
53
- * is public and an unkeyed mixer is the right tool.
54
- */
55
- function mix32(value) {
56
- let x = (value ^ value >>> 16) >>> 0;
57
- x = Math.imul(x, 2146121005);
58
- x = (x ^ x >>> 15) >>> 0;
59
- x = Math.imul(x, 2221713035);
60
- return (x ^ x >>> 16) >>> 0;
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ /*#__NO_SIDE_EFFECTS__*/
4
+ function mix32(e) {
5
+ let t = (e ^ e >>> 16) >>> 0;
6
+ return t = Math.imul(t, 2146121005), t = (t ^ t >>> 15) >>> 0, t = Math.imul(t, 2221713035), (t ^ t >>> 16) >>> 0;
61
7
  }
62
- /** Big-endian on purpose: the wire format must not depend on the host's byte order. */
63
- function read32(bytes, offset) {
64
- return bytes[offset] << 24 | bytes[offset + 1] << 16 | bytes[offset + 2] << 8 | bytes[offset + 3] | 0;
8
+ /*#__NO_SIDE_EFFECTS__*/
9
+ function read32(e, t) {
10
+ return e[t] << 24 | e[t + 1] << 16 | e[t + 2] << 8 | e[t + 3];
65
11
  }
66
- function write32(bytes, offset, value) {
67
- bytes[offset] = value >>> 24;
68
- bytes[offset + 1] = value >>> 16 & 255;
69
- bytes[offset + 2] = value >>> 8 & 255;
70
- bytes[offset + 3] = value & 255;
12
+ function write32(e, t, n) {
13
+ e[t] = n >>> 24, e[t + 1] = n >>> 16 & 255, e[t + 2] = n >>> 8 & 255, e[t + 3] = n & 255;
71
14
  }
72
- const roundInput = /* @__PURE__ */ new Int32Array(2);
73
- const roundOutput = /* @__PURE__ */ new Int32Array(2);
74
- /**
75
- * Transform 16 bytes from `input` into `output`, which may be the same array.
76
- *
77
- * `forward: false` is the exact inverse — the rounds are identical and only the key order
78
- * differs, which is why the final swap below is undone rather than performed.
79
- */
80
- function feistel16(input, inputOffset, keys, forward, output, outputOffset) {
81
- let left0 = read32(input, inputOffset);
82
- let left1 = read32(input, inputOffset + 4);
83
- let right0 = read32(input, inputOffset + 8);
84
- let right1 = read32(input, inputOffset + 12);
85
- for (let round = 0; round < ROUNDS; round += 1) {
86
- const key = (forward ? round : 3 - round) * 2;
87
- roundInput[0] = right0;
88
- roundInput[1] = right1;
89
- halfSipHash(keys[key], keys[key + 1], roundInput, 8, roundOutput);
90
- const next0 = left0 ^ roundOutput[0];
91
- const next1 = left1 ^ roundOutput[1];
92
- left0 = right0;
93
- left1 = right1;
94
- right0 = next0;
95
- right1 = next1;
15
+ function feistel16(e, t, n, r, i, a) {
16
+ let o = /* @__PURE__ */ read32(e, t), s = /* @__PURE__ */ read32(e, t + 4), c = /* @__PURE__ */ read32(e, t + 8), l = /* @__PURE__ */ read32(e, t + 12);
17
+ for (let e = 0; e < 4; e += 1) {
18
+ let t = (r === "mask" ? e : 3 - e) * 2, i = n[t], a = n[t + 1], u = i | 0, d = a ^ 238, f = i ^ 1819895653, p = a ^ 1952801890;
19
+ for (let e = 0; e < 3; e += 1) {
20
+ let t = e === 0 ? c : e === 1 ? l : 8 << 24;
21
+ p ^= t;
22
+ for (let e = 0; e < 2; e += 1) u = u + d | 0, d = d << 5 | d >>> 27, d ^= u, u = u << 16 | u >>> 16, f = f + p | 0, p = p << 8 | p >>> 24, p ^= f, u = u + p | 0, p = p << 7 | p >>> 25, p ^= u, f = f + d | 0, d = d << 13 | d >>> 19, d ^= f, f = f << 16 | f >>> 16;
23
+ u ^= t;
24
+ }
25
+ f ^= 238;
26
+ let m = 0;
27
+ for (let e = 0; e < 2; e += 1) {
28
+ for (let e = 0; e < 4; e += 1) u = u + d | 0, d = d << 5 | d >>> 27, d ^= u, u = u << 16 | u >>> 16, f = f + p | 0, p = p << 8 | p >>> 24, p ^= f, u = u + p | 0, p = p << 7 | p >>> 25, p ^= u, f = f + d | 0, d = d << 13 | d >>> 19, d ^= f, f = f << 16 | f >>> 16;
29
+ e === 0 && (m = d ^ p, d ^= 221);
30
+ }
31
+ let h = o ^ m, g = s ^ d ^ p;
32
+ o = c, s = l, c = h, l = g;
96
33
  }
97
- write32(output, outputOffset, right0);
98
- write32(output, outputOffset + 4, right1);
99
- write32(output, outputOffset + 8, left0);
100
- write32(output, outputOffset + 12, left1);
34
+ write32(i, a, c), write32(i, a + 4, l), write32(i, a + 8, o), write32(i, a + 12, s);
101
35
  }
102
36
  //#endregion
103
37
  export { feistel16, mix32, read32 };
@@ -1 +1 @@
1
- {"version":3,"file":"feistel.js","names":[],"sources":["../src/feistel.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport { halfSipHash } from \"./siphash\";\n\n/**\n * A 4-round Feistel network over the 16 UUID bytes, used as the mask's mixing step.\n *\n * Why a Feistel rather than the byte permutation plus XOR it replaces: that construction is a\n * monoalphabetic substitution — one output byte per input byte — so bytes the inputs share, the\n * outputs share too. Measured over 3000 ids, masked slugs of UUIDv7s created in the same second\n * held 4 of 16 bytes constant, the same hour 3, the same day 2. The timestamp the mask exists to\n * hide was still legible in the output. A Feistel diffuses every input bit across the whole\n * block, so no output byte is a function of one input byte: the same measurement yields 0 of 16.\n *\n * The bijection is the property being bought, and it holds whatever the round function does: 16\n * bytes map to 16 bytes and the inverse is the same routine with the round keys reversed, so\n * `mask` and `unmask` cannot drift apart.\n *\n * The round function is HalfSipHash-2-4 keyed per round. What that fixes: the previous round\n * function was `mix32(word ^ roundKey)` — a FIXED, PUBLIC, UNKEYED bijection with the key merely\n * XORed in front, so an attacker inverts it and reads `word ^ roundKey` directly. Luby-Rackoff\n * makes a four-round Feistel a strong pseudorandom permutation only when the round functions are\n * pseudorandom functions, which `mix32` is not, so the theorem said nothing about what shipped and\n * an earlier version of this comment cited it wrongly. A keyed PRF meets that hypothesis in kind,\n * which is what makes ROUNDS = 4 a justified number rather than an unexamined margin. It is still\n * NOT a proof about what ships: the theorem wants four INDEPENDENTLY sampled round functions, and\n * `schema.ts` derives all four key pairs from one 128-bit key. Read it as the design rationale it\n * is, and see `docs/design.md` for what masking does and does not promise.\n *\n * Measured 2026-08-12 on Bun, both directions, medians of 9: the swap costs 2.5x on the mixing step\n * alone (30.85M -> 12.43M mixes/s) and about a quarter of end-to-end masking throughput, because\n * mixing is roughly a fifth of a mask. HalfSipHash is FASTER per round than `mix32` — pure\n * add/xor/rotate against two `Math.imul` calls — and loses only by doing 14 rounds where the old\n * function did the equivalent of 4.\n *\n * Nor does any measurement in this repository grade the round count or the round function. Strict\n * avalanche across all input/output bit pairs, a same-millisecond burst where only a 12-bit counter\n * varies, and a single-difference differential all PASS a TWO-round network, so none of them can\n * separate a weak setting from a strong one. Their agreement is evidence about the instruments.\n * `test/siphash.test.ts` is the exception and the reason a published primitive was worth taking:\n * it checks the round function against 64 vectors somebody else computed, and that CAN fail.\n */\n\n/**\n * Round count. Wire-format-bearing: changing it changes every masked slug this package has ever\n * issued, so it moves only alongside a deliberate format change. Four is Luby-Rackoff's number,\n * which the round function now makes relevant — see the note above for why that is a rationale\n * rather than a proof.\n */\nconst ROUNDS = 4;\n\n/** Two 32-bit round keys per round, consumed as one flat array to keep the hot loop indexed. */\nexport const FEISTEL_KEY_WORDS = ROUNDS * 2;\n\n/**\n * The `lowbias32` finalizer: an integer hash with near-ideal avalanche for its size. No longer the\n * round function — see above — but still what `mask.ts` derives its check tag with, where the input\n * is public and an unkeyed mixer is the right tool.\n */\nexport function mix32(value: number): number {\n let x = (value ^ (value >>> 16)) >>> 0;\n x = Math.imul(x, 0x7feb352d);\n x = (x ^ (x >>> 15)) >>> 0;\n x = Math.imul(x, 0x846ca68b);\n return (x ^ (x >>> 16)) >>> 0;\n}\n\n/** Big-endian on purpose: the wire format must not depend on the host's byte order. */\nexport function read32(bytes: Uint8Array, offset: number): number {\n return (\n ((bytes[offset] as number) << 24) |\n ((bytes[offset + 1] as number) << 16) |\n ((bytes[offset + 2] as number) << 8) |\n (bytes[offset + 3] as number) |\n 0\n );\n}\n\nfunction write32(bytes: Uint8Array, offset: number, value: number) {\n bytes[offset] = value >>> 24;\n bytes[offset + 1] = (value >>> 16) & 0xff;\n bytes[offset + 2] = (value >>> 8) & 0xff;\n bytes[offset + 3] = value & 0xff;\n}\n\n// Scratch for the round function, at module scope because allocating two 2-word arrays per call\n// dominated the mix. Safe because nothing here is reentrant: `feistel16` is synchronous, calls only\n// `halfSipHash`, and that calls nothing.\nconst roundInput = new Int32Array(2);\nconst roundOutput = new Int32Array(2);\n\n/**\n * Transform 16 bytes from `input` into `output`, which may be the same array.\n *\n * `forward: false` is the exact inverse — the rounds are identical and only the key order\n * differs, which is why the final swap below is undone rather than performed.\n */\nexport function feistel16(\n input: Uint8Array,\n inputOffset: number,\n keys: Int32Array,\n forward: boolean,\n output: Uint8Array,\n outputOffset: number,\n) {\n let left0 = read32(input, inputOffset);\n let left1 = read32(input, inputOffset + 4);\n let right0 = read32(input, inputOffset + 8);\n let right1 = read32(input, inputOffset + 12);\n for (let round = 0; round < ROUNDS; round += 1) {\n const key = (forward ? round : ROUNDS - 1 - round) * 2;\n roundInput[0] = right0;\n roundInput[1] = right1;\n halfSipHash(keys[key] as number, keys[key + 1] as number, roundInput, 8, roundOutput);\n const next0 = left0 ^ (roundOutput[0] as number);\n const next1 = left1 ^ (roundOutput[1] as number);\n left0 = right0;\n left1 = right1;\n right0 = next0;\n right1 = next1;\n }\n // Undoing the last round's swap is what collapses encode and decode into one routine. Perform\n // it, and decoding would need its own mirrored loop that can silently disagree with this one.\n write32(output, outputOffset, right0);\n write32(output, outputOffset + 4, right1);\n write32(output, outputOffset + 8, left0);\n write32(output, outputOffset + 12, left1);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,M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Q,QAAQ,eAAe,GAAG,KAAK;CACvC,QAAQ,QAAQ,eAAe,IAAI,KAAK;AAC1C"}
1
+ {"version":3,"file":"feistel.js","names":["x","value","bytes","offset","left0","input","inputOffset","left1","right0","right1","round","key","direction","key0","keys","key1","v0","v1","v2","v3","block","m","sipRound","hash0","half","next0","next1","output","outputOffset"],"sources":["../src/feistel.ts"],"mappings":";;;AAuBA,SAAgB,MAAM,GAAuB;CAC3C,IAAIA,KAAKC,IAASA,MAAU,QAAS;CAIrC,OAHA,IAAI,KAAK,KAAKD,GAAG,UAAU,GAC3B,KAAKA,IAAKA,MAAM,QAAS,GACzB,IAAI,KAAK,KAAKA,GAAG,UAAU,IACnBA,IAAKA,MAAM,QAAS;AAC9B;;AAIA,SAAgB,OAAO,GAAmB,GAAwB;CAChE,OACIE,EAAMC,MAAsB,KAC5BD,EAAMC,IAAS,MAAiB,KAChCD,EAAMC,IAAS,MAAiB,IACjCD,EAAMC,IAAS;AAGpB;AAEA,SAAS,QAAQ,GAAmB,GAAgB,GAAe;CAIjE,AAHA,EAAMA,KAAUF,MAAU,IAC1B,EAAME,IAAS,KAAMF,MAAU,KAAM,KACrC,EAAME,IAAS,KAAMF,MAAU,IAAK,KACpC,EAAME,IAAS,KAAKF,IAAQ;AAC9B;AAQA,SAAgB,UACd,GACA,GACA,GACA,GACA,GACA,GACA;CACA,IAAIG,IAAQ,uBAAOC,GAAOC,CAAW,GACjCC,IAAQ,uBAAOF,GAAOC,IAAc,CAAC,GACrCE,IAAS,uBAAOH,GAAOC,IAAc,CAAC,GACtCG,IAAS,uBAAOJ,GAAOC,IAAc,EAAE;CAC3C,KAAK,IAAII,IAAQ,GAAGA,IAAQ,GAAQ,KAAS,GAAG;EAC9C,IAAMC,KAAOC,MAAc,SAASF,IAAQ,IAAaA,KAAS,GAK5DG,IAAOC,EAAKH,IACZI,IAAOD,EAAKH,IAAM,IACpBK,IAAKH,IAAO,GACZI,IAAMF,IAAO,KACbG,IAAML,IAAO,YACbM,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B,GACT,IAASC;CACX;CAMA,AAHA,QAAQC,GAAQC,GAAcpB,CAAM,GACpC,QAAQmB,GAAQC,IAAe,GAAGnB,CAAM,GACxC,QAAQkB,GAAQC,IAAe,GAAGxB,CAAK,GACvC,QAAQuB,GAAQC,IAAe,IAAIrB,CAAK;AAC1C"}
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ import { INVALID_OPTIONS as e, UuidSlugError as t, findUnknownOption as n, isPlainRecord as r } from "./errors.js";
4
+ //#region src/generation-options.ts
5
+ function readGenerationOptions(i, a, o) {
6
+ if (typeof i != "object" || !i) return new t(e, `${o} options must be a plain object.`);
7
+ try {
8
+ if (!r(i)) return new t(e, `${o} options must be a plain object.`);
9
+ let s = /* @__PURE__ */ n(i, a);
10
+ if (s !== void 0) return new t(e, `Unknown ${o} option: ${s}.`);
11
+ let c = i, l = {};
12
+ return a.alphabet && Object.hasOwn(c, "alphabet") && (l.alphabet = c.alphabet), a.at && Object.hasOwn(c, "at") && (l.at = c.at), a.generator && Object.hasOwn(c, "generator") && (l.generator = c.generator), a.maskingCodec && Object.hasOwn(c, "maskingCodec") && (l.maskingCodec = c.maskingCodec), a.output && Object.hasOwn(c, "output") && (l.output = c.output), a.outputOffset && Object.hasOwn(c, "outputOffset") && (l.outputOffset = c.outputOffset), a.textCase && Object.hasOwn(c, "textCase") && (l.textCase = c.textCase), l;
13
+ } catch (n) {
14
+ return new t(e, `Reading ${o} options failed.`, { cause: n });
15
+ }
16
+ }
17
+ //#endregion
18
+ export { readGenerationOptions };
19
+
20
+ //# sourceMappingURL=generation-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generation-options.js","names":["options","UuidSlugError","INVALID_OPTIONS","operation","isPlainRecord","unknown","accepted","source","values","cause"],"sources":["../src/generation-options.ts"],"mappings":";;;;AAeA,SAAgB,sBACd,GACA,GACA,GACwC;CACxC,IAAwB,OAAOA,KAAY,aAAvCA,GACF,OAAO,IAAIC,EAAcC,GAAiB,GAAGC,EAAU,iCAAiC;CAC1F,IAAI;EACF,IAAI,CAACC,EAAcJ,CAAO,GACxB,OAAO,IAAIC,EAAcC,GAAiB,GAAGC,EAAU,iCAAiC;EAC1F,IAAME,IAAU,kBAAkBL,GAASM,CAAQ;EACnD,IAAID,MAAY,KAAA,GACd,OAAO,IAAIJ,EAAcC,GAAiB,WAAWC,EAAU,WAAWE,EAAQ,EAAE;EACtF,IAAME,IAASP,GAITQ,IAAuE,CAAC;EAW9E,OAVIF,EAAS,YAAY,OAAO,OAAOC,GAAQ,UAAU,MAAG,EAAO,WAAWA,EAAO,WACjFD,EAAS,MAAM,OAAO,OAAOC,GAAQ,IAAI,MAAG,EAAO,KAAKA,EAAO,KAC/DD,EAAS,aAAa,OAAO,OAAOC,GAAQ,WAAW,MACzD,EAAO,YAAYA,EAAO,YACxBD,EAAS,gBAAgB,OAAO,OAAOC,GAAQ,cAAc,MAC/D,EAAO,eAAeA,EAAO,eAC3BD,EAAS,UAAU,OAAO,OAAOC,GAAQ,QAAQ,MAAG,EAAO,SAASA,EAAO,SAC3ED,EAAS,gBAAgB,OAAO,OAAOC,GAAQ,cAAc,MAC/D,EAAO,eAAeA,EAAO,eAC3BD,EAAS,YAAY,OAAO,OAAOC,GAAQ,UAAU,MAAG,EAAO,WAAWA,EAAO,WAC9EC;CACT,SAASC,GAAO;EACd,OAAO,IAAIR,EAAcC,GAAiB,WAAWC,EAAU,mBAAmB,EAAE,SAAM,CAAC;CAC7F;AACF"}
package/dist/index.d.ts CHANGED
@@ -1,11 +1,23 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- // @anizoptera/uuid-slug 0.3.0 | https://github.com/Anizoptera/uuid-slug#readme
3
- import { UUID_SLUG_ERROR_CODES, UuidRuntimeError, UuidSlugError, UuidSlugErrorCode } from "./errors.js";
4
- import { SlugAlphabet, extractUuidV7Timestamp, formatUuid, formatUuidSlug, hasUuidV7Entropy, isUuidSlug, isUuidString, isUuidV4Slug, isUuidV4String, isUuidV7Bytes, isUuidV7Slug, isUuidV7String, parseUuid, parseUuidSlug, slugToUuid, uuidToSlug } from "./uuid.js";
5
- import { AsyncMaskSchemaOptions, Base64UrlString, FreshValidationOptions, MaskSchema, MaskSchemaOptions, MaskedUuidSlug, MaskedUuidV7Slug, MigrationFormat, PublicUuidV7Slug, SentinelUuidV7Slug, UuidBytes, UuidSlug, UuidSlugCodec, UuidSlugCodecOptions, UuidSlugMigration, UuidSlugMigrationOptions, UuidString, UuidV4Slug, UuidV4String, UuidV7Generator, UuidV7Sentinel, UuidV7SentinelDefinition, UuidV7Slug, UuidV7String } from "./types.js";
6
- import { decodeBase64Url, encodeBase64Url, isBase64Url } from "./base64url.js";
7
- import { UUID_V7_SENTINEL_DEFINITIONS, createUuidSlugCodec, defaultCodec, validateUuidV7Fresh, validateUuidV7SlugFresh } from "./codec.js";
8
- import { DEFAULT_MASK_SCHEMA, createMaskSchema, createMaskSchemaAsync } from "./schema.js";
9
- import { UuidV7GeneratorOptions, createUuidV7Generator } from "./v7.js";
10
- import { uuidV4, uuidV4Bytes, uuidV4Slug, uuidV7, uuidV7At, uuidV7Bytes, uuidV7BytesAt, uuidV7Slug } from "./keyless.js";
11
- export { type AsyncMaskSchemaOptions, type Base64UrlString, DEFAULT_MASK_SCHEMA, type FreshValidationOptions, type MaskSchema, type MaskSchemaOptions, type MaskedUuidSlug, type MaskedUuidV7Slug, type MigrationFormat, type PublicUuidV7Slug, type SentinelUuidV7Slug, type SlugAlphabet, UUID_SLUG_ERROR_CODES, UUID_V7_SENTINEL_DEFINITIONS, type UuidBytes, UuidRuntimeError, type UuidSlug, type UuidSlugCodec, type UuidSlugCodecOptions, UuidSlugError, type UuidSlugErrorCode, type UuidSlugMigration, type UuidSlugMigrationOptions, type UuidString, type UuidV4Slug, type UuidV4String, type UuidV7Generator, type UuidV7GeneratorOptions, type UuidV7Sentinel, type UuidV7SentinelDefinition, type UuidV7Slug, type UuidV7String, createMaskSchema, createMaskSchemaAsync, createUuidSlugCodec, createUuidV7Generator, decodeBase64Url, defaultCodec, encodeBase64Url, extractUuidV7Timestamp, formatUuid, formatUuidSlug, hasUuidV7Entropy, isBase64Url, isUuidSlug, isUuidString, isUuidV4Slug, isUuidV4String, isUuidV7Bytes, isUuidV7Slug, isUuidV7String, parseUuid, parseUuidSlug, slugToUuid, uuidToSlug, uuidV4, uuidV4Bytes, uuidV4Slug, uuidV7, uuidV7At, uuidV7Bytes, uuidV7BytesAt, uuidV7Slug, validateUuidV7Fresh, validateUuidV7SlugFresh };
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ import { ABORTED, INVALID_BASE32HEX, INVALID_BASE64URL, INVALID_BUFFER, INVALID_MASK, INVALID_OPTIONS, INVALID_SENTINEL, INVALID_TIMESTAMP, INVALID_UUID, INVALID_UUID_SLUG, INVALID_UUID_VERSION, RNG_UNAVAILABLE, TIMESTAMP_OUTSIDE_WINDOW, UuidSlugError, UuidSlugErrorCode, isUuidSlugError } from "./errors.js";
4
+ import { BASE64URL_NAME } from "./base64url-name.js";
5
+ import { BASE32HEX_NAME } from "./alphabet.js";
6
+ import { SlugAlphabet, extractUuidV7Payload, extractUuidV7UnixMs, extractUuidVersion, isPlainUuidSlug, isPlainUuidV4Slug, isPlainUuidV7Slug, plainSlugToUuidBytes, plainSlugToUuidString, uuidBytesToPlainSlug, uuidStringToPlainSlug, uuidToBytes, uuidToPlainSlug, uuidToString, validatePlainUuidV7SlugUnixMs } from "./slug.js";
7
+ import { UuidV7MaskingCodec, UuidV7MaskingCodecOptions, UuidV7PreviousMask } from "./masking-codec-types.js";
8
+ import { AsyncUuidV7MaskOptions, CustomUuidV7MaskOptions, FIXED_MASK_FORMAT, GeneratePlainUuidV7SlugOptions, GenerateUuidV7BytesIntoOptions, GenerateUuidV7BytesOptions, GenerateUuidV7Options, GenerateUuidV7WithMaskedSlugOptions, GenerateUuidV7WithPlainSlugOptions, GeneratedUuidV7, MaskedOrSentinelUuidV7Slug, MaskedUuidV7Slug, PLAIN_SLUG_FORMAT, PlainUuidSlug, PlainUuidSlugResult, PlainUuidV4Slug, PlainUuidV7Slug, SEEDED_MASK_FORMAT, SentinelUuidV7Slug, UUID_TEXT_LOWERCASE, UUID_TEXT_UPPERCASE, UUID_V7_ROLLBACK_ERROR, UUID_V7_ROLLBACK_PRESERVE, UUID_V7_ROLLBACK_RESET, UUID_VARIANT_FUTURE, UUID_VARIANT_MICROSOFT, UUID_VARIANT_NCS, UUID_VARIANT_RFC, UppercaseUuidString, UppercaseUuidV4String, UppercaseUuidV7String, Uuid, UuidByteInput, UuidBytes, UuidBytesResult, UuidInput, UuidInspection, UuidRandomFill, UuidSlugMigrationDecoder, UuidSlugMigrationFormat, UuidSlugMigrationOptions, UuidString, UuidStringFor, UuidStringResult, UuidText, UuidTextCase, UuidV4Bytes, UuidV4String, UuidV4StringFor, UuidV4Text, UuidV7Bounds, UuidV7Bytes, UuidV7ClockRollbackPolicy, UuidV7Generator, UuidV7GeneratorValueOptions, UuidV7Instant, UuidV7Mask, UuidV7MaskOptions, UuidV7MaskingCodecValueOptions, UuidV7Payload, UuidV7PayloadLayout, UuidV7Sentinel, UuidV7SentinelConfig, UuidV7String, UuidV7StringFor, UuidV7Text, UuidV7TimestampWindow, UuidV7ValueOptions, UuidVariant, UuidVersion } from "./types.js";
9
+ import { createUuidV7MaskingCodec } from "./masking-codec.js";
10
+ import { MAX_MASKED_UUID_V7_TIMESTAMP_OFFSET_MS } from "./payload.js";
11
+ import { validateUuidV7StringUnixMs } from "./timestamp.js";
12
+ import { UUID_V7_TEST_MASK, deriveUuidV7Mask, deriveUuidV7MaskAsync } from "./mask.js";
13
+ import { createCustomUuidV7Mask } from "./mask-handle.js";
14
+ import { uuidV7ByteBounds, uuidV7StringBounds } from "./v7-bounds.js";
15
+ import { MAX_UUID, NIL_UUID, bytesToUuidString, isUuidBytes, isUuidString, isUuidText, isUuidV4Bytes, isUuidV4String, isUuidV4Text, isUuidV7Bytes, isUuidV7String, isUuidV7Text, uuidStringToBytes } from "./uuid.js";
16
+ import { parseUuid } from "./uuid-value.js";
17
+ import { UuidV7GeneratorOptions, createUuidV7Generator, createUuidV7GeneratorWithRandomFill } from "./v7-generator.js";
18
+ import { generateUuidV4, generateUuidV4Bytes, generateUuidV4WithRandomFill } from "./v4.js";
19
+ import { generateUuidV7, generateUuidV7Bytes } from "./v7-keyless.js";
20
+ import { generateUuidV7Value } from "./v7-value.js";
21
+ import { generatePlainUuidV4Slug } from "./v4-slug.js";
22
+ import { generatePlainUuidV7Slug, generateUuidV7WithPlainSlug } from "./v7-slug.js";
23
+ export { ABORTED, type AsyncUuidV7MaskOptions, BASE32HEX_NAME as BASE32HEX, BASE64URL_NAME as BASE64URL, type CustomUuidV7MaskOptions, FIXED_MASK_FORMAT, type GeneratePlainUuidV7SlugOptions, type GenerateUuidV7BytesIntoOptions, type GenerateUuidV7BytesOptions, type GenerateUuidV7Options, type GenerateUuidV7WithMaskedSlugOptions, type GenerateUuidV7WithPlainSlugOptions, type GeneratedUuidV7, INVALID_BASE32HEX, INVALID_BASE64URL, INVALID_BUFFER, INVALID_MASK, INVALID_OPTIONS, INVALID_SENTINEL, INVALID_TIMESTAMP, INVALID_UUID, INVALID_UUID_SLUG, INVALID_UUID_VERSION, MAX_MASKED_UUID_V7_TIMESTAMP_OFFSET_MS, MAX_UUID, type MaskedOrSentinelUuidV7Slug, type MaskedUuidV7Slug, NIL_UUID, PLAIN_SLUG_FORMAT, type PlainUuidSlug, type PlainUuidSlugResult, type PlainUuidV4Slug, type PlainUuidV7Slug, RNG_UNAVAILABLE, SEEDED_MASK_FORMAT, type SentinelUuidV7Slug, type SlugAlphabet, TIMESTAMP_OUTSIDE_WINDOW, UUID_TEXT_LOWERCASE, UUID_TEXT_UPPERCASE, UUID_V7_ROLLBACK_ERROR, UUID_V7_ROLLBACK_PRESERVE, UUID_V7_ROLLBACK_RESET, UUID_V7_TEST_MASK, UUID_VARIANT_FUTURE, UUID_VARIANT_MICROSOFT, UUID_VARIANT_NCS, UUID_VARIANT_RFC, type UppercaseUuidString, type UppercaseUuidV4String, type UppercaseUuidV7String, type Uuid, type UuidByteInput, type UuidBytes, type UuidBytesResult, type UuidInput, type UuidInspection, type UuidRandomFill, UuidSlugError, type UuidSlugErrorCode, type UuidSlugMigrationDecoder, type UuidSlugMigrationFormat, type UuidSlugMigrationOptions, type UuidString, type UuidStringFor, type UuidStringResult, type UuidText, type UuidTextCase, type UuidV4Bytes, type UuidV4String, type UuidV4StringFor, type UuidV4Text, type UuidV7Bounds, type UuidV7Bytes, type UuidV7ClockRollbackPolicy, type UuidV7Generator, type UuidV7GeneratorOptions, type UuidV7GeneratorValueOptions, type UuidV7Instant, type UuidV7Mask, type UuidV7MaskOptions, type UuidV7MaskingCodec, type UuidV7MaskingCodecOptions, type UuidV7MaskingCodecValueOptions, type UuidV7Payload, type UuidV7PayloadLayout, type UuidV7PreviousMask, type UuidV7Sentinel, type UuidV7SentinelConfig, type UuidV7String, type UuidV7StringFor, type UuidV7Text, type UuidV7TimestampWindow, type UuidV7ValueOptions, type UuidVariant, type UuidVersion, bytesToUuidString, createCustomUuidV7Mask, createUuidV7Generator, createUuidV7GeneratorWithRandomFill, createUuidV7MaskingCodec, deriveUuidV7Mask, deriveUuidV7MaskAsync, extractUuidV7Payload, extractUuidV7UnixMs, extractUuidVersion, generatePlainUuidV4Slug, generatePlainUuidV7Slug, generateUuidV4, generateUuidV4Bytes, generateUuidV4WithRandomFill, generateUuidV7, generateUuidV7Bytes, generateUuidV7Value, generateUuidV7WithPlainSlug, isPlainUuidSlug, isPlainUuidV4Slug, isPlainUuidV7Slug, isUuidBytes, isUuidSlugError, isUuidString, isUuidText, isUuidV4Bytes, isUuidV4String, isUuidV4Text, isUuidV7Bytes, isUuidV7String, isUuidV7Text, parseUuid, plainSlugToUuidBytes, plainSlugToUuidString, uuidBytesToPlainSlug, uuidStringToBytes, uuidStringToPlainSlug, uuidToBytes, uuidToPlainSlug, uuidToString, uuidV7ByteBounds, uuidV7StringBounds, validatePlainUuidV7SlugUnixMs, validateUuidV7StringUnixMs };
package/dist/index.js CHANGED
@@ -1,10 +1,22 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- // @anizoptera/uuid-slug 0.3.0 | https://github.com/Anizoptera/uuid-slug#readme
3
- import { UUID_SLUG_ERROR_CODES, UuidRuntimeError, UuidSlugError } from "./errors.js";
4
- import { decodeBase64Url, encodeBase64Url, isBase64Url } from "./base64url.js";
5
- import { extractUuidV7Timestamp, formatUuid, formatUuidSlug, hasUuidV7Entropy, isUuidSlug, isUuidString, isUuidV4Slug, isUuidV4String, isUuidV7Bytes, isUuidV7Slug, isUuidV7String, parseUuid, parseUuidSlug, slugToUuid, uuidToSlug } from "./uuid.js";
6
- import { createUuidV7Generator } from "./v7.js";
7
- import { uuidV4, uuidV4Bytes, uuidV4Slug, uuidV7, uuidV7At, uuidV7Bytes, uuidV7BytesAt, uuidV7Slug } from "./keyless.js";
8
- import { DEFAULT_MASK_SCHEMA, createMaskSchema, createMaskSchemaAsync } from "./schema.js";
9
- import { UUID_V7_SENTINEL_DEFINITIONS, createUuidSlugCodec, defaultCodec, validateUuidV7Fresh, validateUuidV7SlugFresh } from "./codec.js";
10
- export { DEFAULT_MASK_SCHEMA, UUID_SLUG_ERROR_CODES, UUID_V7_SENTINEL_DEFINITIONS, UuidRuntimeError, UuidSlugError, createMaskSchema, createMaskSchemaAsync, createUuidSlugCodec, createUuidV7Generator, decodeBase64Url, defaultCodec, encodeBase64Url, extractUuidV7Timestamp, formatUuid, formatUuidSlug, hasUuidV7Entropy, isBase64Url, isUuidSlug, isUuidString, isUuidV4Slug, isUuidV4String, isUuidV7Bytes, isUuidV7Slug, isUuidV7String, parseUuid, parseUuidSlug, slugToUuid, uuidToSlug, uuidV4, uuidV4Bytes, uuidV4Slug, uuidV7, uuidV7At, uuidV7Bytes, uuidV7BytesAt, uuidV7Slug, validateUuidV7Fresh, validateUuidV7SlugFresh };
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ import { ABORTED as e, INVALID_BASE32HEX as t, INVALID_BASE64URL as n, INVALID_BUFFER as r, INVALID_MASK as i, INVALID_OPTIONS as a, INVALID_SENTINEL as o, INVALID_TIMESTAMP as s, INVALID_UUID as c, INVALID_UUID_SLUG as l, INVALID_UUID_VERSION as u, RNG_UNAVAILABLE as d, TIMESTAMP_OUTSIDE_WINDOW as f, UuidSlugError as p, isUuidSlugError as m } from "./errors.js";
4
+ import { BASE64URL_NAME as h } from "./base64url-name.js";
5
+ import { BASE32HEX_NAME as g } from "./alphabet.js";
6
+ import { FIXED_MASK_FORMAT as _, PLAIN_SLUG_FORMAT as v, SEEDED_MASK_FORMAT as y, UUID_TEXT_LOWERCASE as b, UUID_TEXT_UPPERCASE as x, UUID_V7_ROLLBACK_ERROR as S, UUID_V7_ROLLBACK_PRESERVE as C, UUID_V7_ROLLBACK_RESET as w, UUID_VARIANT_FUTURE as T, UUID_VARIANT_MICROSOFT as E, UUID_VARIANT_NCS as D, UUID_VARIANT_RFC as O } from "./types.js";
7
+ import { MAX_UUID as k, NIL_UUID as A, bytesToUuidString as j, isUuidBytes as M, isUuidString as N, isUuidText as P, isUuidV4Bytes as F, isUuidV4String as I, isUuidV4Text as L, isUuidV7Bytes as R, isUuidV7String as z, isUuidV7Text as B, uuidStringToBytes as V } from "./uuid.js";
8
+ import { generateUuidV7 as H, generateUuidV7Bytes as U } from "./v7-keyless.js";
9
+ import { createCustomUuidV7Mask as W } from "./mask-handle.js";
10
+ import { MAX_MASKED_UUID_V7_TIMESTAMP_OFFSET_MS as G } from "./payload.js";
11
+ import { UUID_V7_TEST_MASK as K, deriveUuidV7Mask as q, deriveUuidV7MaskAsync as J } from "./mask.js";
12
+ import { validateUuidV7StringUnixMs as Y } from "./timestamp.js";
13
+ import { extractUuidV7Payload as X, extractUuidV7UnixMs as Z, extractUuidVersion as Q, isPlainUuidSlug as $, isPlainUuidV4Slug as ee, isPlainUuidV7Slug as te, plainSlugToUuidBytes as ne, plainSlugToUuidString as re, uuidBytesToPlainSlug as ie, uuidStringToPlainSlug as ae, uuidToBytes as oe, uuidToPlainSlug as se, uuidToString as ce, validatePlainUuidV7SlugUnixMs as le } from "./slug.js";
14
+ import { parseUuid as ue } from "./uuid-value.js";
15
+ import { createUuidV7MaskingCodec as de } from "./masking-codec.js";
16
+ import { uuidV7ByteBounds as fe, uuidV7StringBounds as pe } from "./v7-bounds.js";
17
+ import { generatePlainUuidV7Slug as me, generateUuidV7WithPlainSlug as he } from "./v7-slug.js";
18
+ import { createUuidV7Generator as ge, createUuidV7GeneratorWithRandomFill as _e } from "./v7-generator.js";
19
+ import { generateUuidV4 as ve, generateUuidV4Bytes as ye, generateUuidV4WithRandomFill as be } from "./v4.js";
20
+ import { generateUuidV7Value as xe } from "./v7-value.js";
21
+ import { generatePlainUuidV4Slug as Se } from "./v4-slug.js";
22
+ export { e as ABORTED, g as BASE32HEX, h as BASE64URL, _ as FIXED_MASK_FORMAT, t as INVALID_BASE32HEX, n as INVALID_BASE64URL, r as INVALID_BUFFER, i as INVALID_MASK, a as INVALID_OPTIONS, o as INVALID_SENTINEL, s as INVALID_TIMESTAMP, c as INVALID_UUID, l as INVALID_UUID_SLUG, u as INVALID_UUID_VERSION, G as MAX_MASKED_UUID_V7_TIMESTAMP_OFFSET_MS, k as MAX_UUID, A as NIL_UUID, v as PLAIN_SLUG_FORMAT, d as RNG_UNAVAILABLE, y as SEEDED_MASK_FORMAT, f as TIMESTAMP_OUTSIDE_WINDOW, b as UUID_TEXT_LOWERCASE, x as UUID_TEXT_UPPERCASE, S as UUID_V7_ROLLBACK_ERROR, C as UUID_V7_ROLLBACK_PRESERVE, w as UUID_V7_ROLLBACK_RESET, K as UUID_V7_TEST_MASK, T as UUID_VARIANT_FUTURE, E as UUID_VARIANT_MICROSOFT, D as UUID_VARIANT_NCS, O as UUID_VARIANT_RFC, p as UuidSlugError, j as bytesToUuidString, W as createCustomUuidV7Mask, ge as createUuidV7Generator, _e as createUuidV7GeneratorWithRandomFill, de as createUuidV7MaskingCodec, q as deriveUuidV7Mask, J as deriveUuidV7MaskAsync, X as extractUuidV7Payload, Z as extractUuidV7UnixMs, Q as extractUuidVersion, Se as generatePlainUuidV4Slug, me as generatePlainUuidV7Slug, ve as generateUuidV4, ye as generateUuidV4Bytes, be as generateUuidV4WithRandomFill, H as generateUuidV7, U as generateUuidV7Bytes, xe as generateUuidV7Value, he as generateUuidV7WithPlainSlug, $ as isPlainUuidSlug, ee as isPlainUuidV4Slug, te as isPlainUuidV7Slug, M as isUuidBytes, m as isUuidSlugError, N as isUuidString, P as isUuidText, F as isUuidV4Bytes, I as isUuidV4String, L as isUuidV4Text, R as isUuidV7Bytes, z as isUuidV7String, B as isUuidV7Text, ue as parseUuid, ne as plainSlugToUuidBytes, re as plainSlugToUuidString, ie as uuidBytesToPlainSlug, V as uuidStringToBytes, ae as uuidStringToPlainSlug, oe as uuidToBytes, se as uuidToPlainSlug, ce as uuidToString, fe as uuidV7ByteBounds, pe as uuidV7StringBounds, le as validatePlainUuidV7SlugUnixMs, Y as validateUuidV7StringUnixMs };