opencode-graphiti 0.2.0-canary.f9dde2d.20260319200335 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/README.md +81 -24
  2. package/esm/_dnt.polyfills.d.ts +6 -6
  3. package/esm/_dnt.polyfills.d.ts.map +1 -1
  4. package/esm/deno.d.ts +0 -1
  5. package/esm/deno.js +0 -1
  6. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts +14 -0
  7. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts.map +1 -0
  8. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.js +65 -0
  9. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts +20 -0
  10. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.js +43 -0
  12. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts +44 -0
  13. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts.map +1 -0
  14. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.js +47 -0
  15. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts +44 -0
  16. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts.map +1 -0
  17. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.js +51 -0
  18. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts +31 -0
  19. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts.map +1 -0
  20. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.js +37 -0
  21. package/esm/src/config.d.ts.map +1 -1
  22. package/esm/src/config.js +67 -25
  23. package/esm/src/handlers/chat.d.ts.map +1 -1
  24. package/esm/src/handlers/chat.js +2 -5
  25. package/esm/src/handlers/event.d.ts.map +1 -1
  26. package/esm/src/handlers/event.js +92 -1
  27. package/esm/src/handlers/messages.d.ts.map +1 -1
  28. package/esm/src/handlers/messages.js +39 -14
  29. package/esm/src/handlers/tool-after.d.ts +9 -0
  30. package/esm/src/handlers/tool-after.d.ts.map +1 -0
  31. package/esm/src/handlers/tool-after.js +15 -0
  32. package/esm/src/handlers/tool-before.d.ts +15 -0
  33. package/esm/src/handlers/tool-before.d.ts.map +1 -0
  34. package/esm/src/handlers/tool-before.js +70 -0
  35. package/esm/src/index.d.ts.map +1 -1
  36. package/esm/src/index.js +183 -89
  37. package/esm/src/services/batch-drain.d.ts +12 -0
  38. package/esm/src/services/batch-drain.d.ts.map +1 -1
  39. package/esm/src/services/batch-drain.js +237 -19
  40. package/esm/src/services/connection-manager.d.ts +7 -1
  41. package/esm/src/services/connection-manager.d.ts.map +1 -1
  42. package/esm/src/services/connection-manager.js +55 -5
  43. package/esm/src/services/context-limit.d.ts +2 -3
  44. package/esm/src/services/context-limit.d.ts.map +1 -1
  45. package/esm/src/services/context-limit.js +19 -7
  46. package/esm/src/services/endpoint-redaction.d.ts +2 -0
  47. package/esm/src/services/endpoint-redaction.d.ts.map +1 -0
  48. package/esm/src/services/endpoint-redaction.js +13 -0
  49. package/esm/src/services/graphiti-async.d.ts.map +1 -1
  50. package/esm/src/services/graphiti-async.js +1 -3
  51. package/esm/src/services/graphiti-mcp.js +4 -4
  52. package/esm/src/services/redis-client.d.ts +34 -0
  53. package/esm/src/services/redis-client.d.ts.map +1 -1
  54. package/esm/src/services/redis-client.js +320 -0
  55. package/esm/src/services/redis-events.d.ts +1 -0
  56. package/esm/src/services/redis-events.d.ts.map +1 -1
  57. package/esm/src/services/redis-events.js +24 -0
  58. package/esm/src/services/session-corpus.d.ts +90 -0
  59. package/esm/src/services/session-corpus.d.ts.map +1 -0
  60. package/esm/src/services/session-corpus.js +1356 -0
  61. package/esm/src/services/session-executor.d.ts +53 -0
  62. package/esm/src/services/session-executor.d.ts.map +1 -0
  63. package/esm/src/services/session-executor.js +312 -0
  64. package/esm/src/services/session-mcp-runtime.d.ts +33 -0
  65. package/esm/src/services/session-mcp-runtime.d.ts.map +1 -0
  66. package/esm/src/services/session-mcp-runtime.js +616 -0
  67. package/esm/src/services/session-mcp-types.d.ts +504 -0
  68. package/esm/src/services/session-mcp-types.d.ts.map +1 -0
  69. package/esm/src/services/session-mcp-types.js +212 -0
  70. package/esm/src/services/tool-guidance-cache.d.ts +8 -0
  71. package/esm/src/services/tool-guidance-cache.d.ts.map +1 -0
  72. package/esm/src/services/tool-guidance-cache.js +25 -0
  73. package/esm/src/services/tool-guidance.d.ts +29 -0
  74. package/esm/src/services/tool-guidance.d.ts.map +1 -0
  75. package/esm/src/services/tool-guidance.js +34 -0
  76. package/esm/src/services/tool-routing-outcome-cache.d.ts +14 -0
  77. package/esm/src/services/tool-routing-outcome-cache.d.ts.map +1 -0
  78. package/esm/src/services/tool-routing-outcome-cache.js +21 -0
  79. package/esm/src/services/tool-routing.d.ts +38 -0
  80. package/esm/src/services/tool-routing.d.ts.map +1 -0
  81. package/esm/src/services/tool-routing.js +122 -0
  82. package/esm/src/session.d.ts +26 -1
  83. package/esm/src/session.d.ts.map +1 -1
  84. package/esm/src/session.js +98 -8
  85. package/esm/src/types/index.d.ts +2 -0
  86. package/esm/src/types/index.d.ts.map +1 -1
  87. package/esm/src/utils.d.ts +8 -0
  88. package/esm/src/utils.d.ts.map +1 -1
  89. package/esm/src/utils.js +20 -0
  90. package/package.json +2 -1
  91. package/script/_dnt.polyfills.d.ts +6 -6
  92. package/script/_dnt.polyfills.d.ts.map +1 -1
  93. package/script/deno.d.ts +0 -1
  94. package/script/deno.js +0 -1
  95. package/script/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts +14 -0
  96. package/script/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts.map +1 -0
  97. package/script/deps/jsr.io/@std/ulid/1.0.0/_util.js +72 -0
  98. package/script/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts +20 -0
  99. package/script/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts.map +1 -0
  100. package/script/deps/jsr.io/@std/ulid/1.0.0/decode_time.js +46 -0
  101. package/script/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts +44 -0
  102. package/script/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts.map +1 -0
  103. package/script/deps/jsr.io/@std/ulid/1.0.0/mod.js +63 -0
  104. package/script/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts +44 -0
  105. package/script/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts.map +1 -0
  106. package/script/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.js +54 -0
  107. package/script/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts +31 -0
  108. package/script/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts.map +1 -0
  109. package/script/deps/jsr.io/@std/ulid/1.0.0/ulid.js +40 -0
  110. package/script/src/config.d.ts.map +1 -1
  111. package/script/src/config.js +67 -25
  112. package/script/src/handlers/chat.d.ts.map +1 -1
  113. package/script/src/handlers/chat.js +2 -5
  114. package/script/src/handlers/event.d.ts.map +1 -1
  115. package/script/src/handlers/event.js +92 -1
  116. package/script/src/handlers/messages.d.ts.map +1 -1
  117. package/script/src/handlers/messages.js +38 -13
  118. package/script/src/handlers/tool-after.d.ts +9 -0
  119. package/script/src/handlers/tool-after.d.ts.map +1 -0
  120. package/script/src/handlers/tool-after.js +18 -0
  121. package/script/src/handlers/tool-before.d.ts +15 -0
  122. package/script/src/handlers/tool-before.d.ts.map +1 -0
  123. package/script/src/handlers/tool-before.js +73 -0
  124. package/script/src/index.d.ts.map +1 -1
  125. package/script/src/index.js +183 -89
  126. package/script/src/services/batch-drain.d.ts +12 -0
  127. package/script/src/services/batch-drain.d.ts.map +1 -1
  128. package/script/src/services/batch-drain.js +270 -19
  129. package/script/src/services/connection-manager.d.ts +7 -1
  130. package/script/src/services/connection-manager.d.ts.map +1 -1
  131. package/script/src/services/connection-manager.js +55 -5
  132. package/script/src/services/context-limit.d.ts +2 -3
  133. package/script/src/services/context-limit.d.ts.map +1 -1
  134. package/script/src/services/context-limit.js +19 -7
  135. package/script/src/services/endpoint-redaction.d.ts +2 -0
  136. package/script/src/services/endpoint-redaction.d.ts.map +1 -0
  137. package/script/src/services/endpoint-redaction.js +17 -0
  138. package/script/src/services/graphiti-async.d.ts.map +1 -1
  139. package/script/src/services/graphiti-async.js +1 -3
  140. package/script/src/services/graphiti-mcp.js +4 -4
  141. package/script/src/services/redis-client.d.ts +34 -0
  142. package/script/src/services/redis-client.d.ts.map +1 -1
  143. package/script/src/services/redis-client.js +320 -0
  144. package/script/src/services/redis-events.d.ts +1 -0
  145. package/script/src/services/redis-events.d.ts.map +1 -1
  146. package/script/src/services/redis-events.js +24 -0
  147. package/script/src/services/session-corpus.d.ts +90 -0
  148. package/script/src/services/session-corpus.d.ts.map +1 -0
  149. package/script/src/services/session-corpus.js +1360 -0
  150. package/script/src/services/session-executor.d.ts +53 -0
  151. package/script/src/services/session-executor.d.ts.map +1 -0
  152. package/script/src/services/session-executor.js +352 -0
  153. package/script/src/services/session-mcp-runtime.d.ts +33 -0
  154. package/script/src/services/session-mcp-runtime.d.ts.map +1 -0
  155. package/script/src/services/session-mcp-runtime.js +656 -0
  156. package/script/src/services/session-mcp-types.d.ts +504 -0
  157. package/script/src/services/session-mcp-types.d.ts.map +1 -0
  158. package/script/src/services/session-mcp-types.js +215 -0
  159. package/script/src/services/tool-guidance-cache.d.ts +8 -0
  160. package/script/src/services/tool-guidance-cache.d.ts.map +1 -0
  161. package/script/src/services/tool-guidance-cache.js +29 -0
  162. package/script/src/services/tool-guidance.d.ts +29 -0
  163. package/script/src/services/tool-guidance.d.ts.map +1 -0
  164. package/script/src/services/tool-guidance.js +38 -0
  165. package/script/src/services/tool-routing-outcome-cache.d.ts +14 -0
  166. package/script/src/services/tool-routing-outcome-cache.d.ts.map +1 -0
  167. package/script/src/services/tool-routing-outcome-cache.js +25 -0
  168. package/script/src/services/tool-routing.d.ts +38 -0
  169. package/script/src/services/tool-routing.d.ts.map +1 -0
  170. package/script/src/services/tool-routing.js +128 -0
  171. package/script/src/session.d.ts +26 -1
  172. package/script/src/session.d.ts.map +1 -1
  173. package/script/src/session.js +98 -8
  174. package/script/src/types/index.d.ts +2 -0
  175. package/script/src/types/index.d.ts.map +1 -1
  176. package/script/src/utils.d.ts +8 -0
  177. package/script/src/utils.d.ts.map +1 -1
  178. package/script/src/utils.js +23 -1
package/README.md CHANGED
@@ -77,6 +77,44 @@ Graphiti stays off the steady-state hook path entirely: hook-time injection uses
77
77
  only Redis/local cached recall, while fresh Graphiti data arrives through the
78
78
  existing background refresh path on later turns.
79
79
 
80
+ ### MCP-First Execution Surface
81
+
82
+ The plugin exposes a set of `session_*` MCP tools as the **primary execution
83
+ surface** for data-heavy work. These tools run in-process alongside the plugin
84
+ hooks and share the same canonical root-session identity and Redis/FalkorDB hot
85
+ tier.
86
+
87
+ The `session_*` tools also write into the same local continuity model as the
88
+ rest of the session: their bounded summaries are recorded as structured events,
89
+ folded into the local snapshot, and preserved through compaction under the same
90
+ `<session_memory>` envelope used for ordinary chat continuity.
91
+
92
+ - **Bounded execution** (`session_execute`, `session_execute_file`,
93
+ `session_batch_execute`) — run commands or process files locally, store full
94
+ output in the local corpus, and return only a bounded summary to the model.
95
+ `session_batch_execute` supports ordered mixed steps, so one request can
96
+ combine bounded command execution with local corpus search.
97
+ - **Local indexing and search** (`session_index`, `session_search`,
98
+ `session_fetch_and_index`) — index content into a per-session local corpus in
99
+ Redis/FalkorDB and search it with bounded result sets. The local corpus stays
100
+ local-first: indexing and retrieval happen against the session's local store,
101
+ while any Graphiti augmentation remains asynchronous and cache-backed.
102
+ `session_index` accepts either inline `content` or a local `path`; when the
103
+ same `source` and `label` are indexed again for one root session, the prior
104
+ logical document is replaced instead of appended.
105
+ - **Diagnostics** (`session_stats`, `session_doctor`) — inspect session state
106
+ and corpus health.
107
+
108
+ The plugin hooks enforce this preference: when the model falls back to risky
109
+ native tools (e.g. unbounded `WebFetch` or raw `curl`), the hook layer may
110
+ redirect or deny the call and suggest the corresponding `session_*` tool. Hooks
111
+ remain secondary — they handle enforcement, continuity capture, snapshot
112
+ assembly, and `<session_memory>` injection, but are not the primary execution
113
+ path.
114
+
115
+ For the full MCP-first architecture, see
116
+ `docs/superpowers/plans/2026-03-20-context-mode-mcp-first.md`.
117
+
80
118
  ## Prerequisites
81
119
 
82
120
  Start the
@@ -107,6 +145,10 @@ long-term knowledge graph on top of the same backend.
107
145
 
108
146
  Add the plugin to your `opencode.json` (or `opencode.jsonc`):
109
147
 
148
+ The package root intentionally exports only the `graphiti` plugin entrypoint.
149
+ Helper symbols under `src/` are internal implementation details and are not a
150
+ supported public import surface.
151
+
110
152
  ```jsonc
111
153
  {
112
154
  "plugin": ["opencode-graphiti"]
@@ -117,8 +159,9 @@ Add the plugin to your `opencode.json` (or `opencode.jsonc`):
117
159
 
118
160
  Local distributable builds are not a routine local setup step: `deno task
119
161
  build`
120
- requires an explicit `VERSION` via `dnt.ts`. If you already have a built
121
- artifact, add it to your `opencode.json`:
162
+ uses the `VERSION` environment variable when set and otherwise falls back to the
163
+ `version` in `deno.json` via `dnt.ts`. If you already have a built artifact, add
164
+ it to your `opencode.json`:
122
165
 
123
166
  ```jsonc
124
167
  {
@@ -192,6 +235,15 @@ top-level aliases remain supported for backward compatibility. Precedence is:
192
235
  1. `redis.*` (canonical)
193
236
  2. top-level Graphiti aliases such as `endpoint` and `groupIdPrefix`
194
237
 
238
+ Endpoint values must resolve to valid URLs. The loader applies best-effort
239
+ coercion for endpoint-like inputs by trimming whitespace, adding the expected
240
+ scheme when omitted, and filling the default port only when a missing-scheme
241
+ input also omits a port. For example, `localhost` under `redis.endpoint`
242
+ resolves to `redis://localhost:6379`, `cache.internal:6380` resolves to
243
+ `redis://cache.internal:6380`, and `graphiti.internal/mcp` under
244
+ `graphiti.endpoint` resolves to `http://graphiti.internal:8000/mcp`. Inputs that
245
+ still fail URL parsing, or that use a disallowed explicit scheme, are rejected.
246
+
195
247
  ### Legacy Top-Level Keys
196
248
 
197
249
  For backward compatibility, the following original Graphiti top-level keys are
@@ -209,17 +261,20 @@ Removed top-level Redis aliases are no longer supported.
209
261
 
210
262
  ### Injection Format
211
263
 
212
- The plugin currently injects a `<session_memory>` XML envelope into the last
213
- user message. This envelope is assembled from short-term memory in Redis and can
214
- contain structured sections such as `<last_request>`, `<active_tasks>`,
215
- `<key_decisions>`, `<files_in_play>`, `<project_rules>`, and an optional
216
- `<session_snapshot>`.
217
-
218
- When long-term memory is available, a nested `<persistent_memory>` section is
219
- included with a `node_refs` attribute naming the emitted cached entities. On a
220
- cold first turn or when Graphiti is unreachable, `<persistent_memory>` is simply
221
- absent the rest of the session memory is always available from short-term
222
- storage in FalkorDB/Redis.
264
+ The plugin injects a **local-first** `<session_memory>` XML envelope into the
265
+ last user message. Every section except `<persistent_memory>` is assembled
266
+ entirely from Redis/FalkorDB state no external service is on the synchronous
267
+ path.
268
+
269
+ - **Local continuity sections** (`<last_request>`, `<active_tasks>`,
270
+ `<key_decisions>`, `<files_in_play>`, `<project_rules>`, etc.) are derived
271
+ from structured session events stored in Redis/FalkorDB.
272
+ - **`<session_snapshot>`** is produced by the local snapshot service, which
273
+ continuously rebuilds a priority-tiered summary from those events.
274
+ - **`<persistent_memory>`** is an **optional, cache-only** augmentation. When
275
+ Graphiti-sourced facts are cached locally, they are included; on a cold first
276
+ turn or when Graphiti is unreachable, this section is simply absent. It never
277
+ blocks the current turn.
223
278
 
224
279
  ```xml
225
280
  <session_memory source="graphiti" version="1">
@@ -237,17 +292,18 @@ storage in FalkorDB/Redis.
237
292
 
238
293
  ### Session Memory Preparation (`chat.message`)
239
294
 
240
- On each user message the plugin assembles the current session memory from three
241
- sources:
295
+ On each user message the plugin assembles the current session memory from
296
+ local-only sources:
242
297
 
243
- - Recent structured session events
244
- - The continuously rebuilt priority-tiered snapshot
245
- - Cached long-term facts from Graphiti
298
+ - **Session events** stored in Redis/FalkorDB
299
+ - **Priority-tiered snapshot** rebuilt by the local snapshot service
300
+ - **Cached Graphiti facts** (optional; read from the local Redis cache, never
301
+ from a synchronous Graphiti call)
246
302
 
247
303
  These are composed into a `<session_memory>` envelope and staged for the
248
- transform hook. The hook-time reads are local/cache-backed only; any fresh
249
- Graphiti lookup remains on the existing background refresh path and benefits the
250
- next turn instead of blocking the current one.
304
+ transform hook. All reads are local/cache-backed; Graphiti is never called
305
+ synchronously. Any fresh Graphiti lookup remains on the existing background
306
+ refresh path and benefits the next turn instead of blocking the current one.
251
307
 
252
308
  ### User Message Injection (`experimental.chat.messages.transform`)
253
309
 
@@ -281,8 +337,9 @@ Events are also queued for background ingestion into long-term memory:
281
337
 
282
338
  - **On idle** (`session.idle`): buffered events are sent to Graphiti and the
283
339
  priority-tiered snapshot is rebuilt.
284
- - **Before compaction** (`session.compacted`): all pending events are sent
285
- immediately so nothing is lost.
340
+ - **After compaction** (`session.compacted`): the compaction summary and any
341
+ pending continuity are scheduled for background Graphiti ingestion so nothing
342
+ is lost across compaction boundaries.
286
343
 
287
344
  ### Compaction Preservation
288
345
 
@@ -308,7 +365,7 @@ regardless of how aggressively the conversation was summarized.
308
365
  > work as summarized tool events. This plugin promotes child sessions to
309
366
  > first-class participants in the root session's state so that decisions, file
310
367
  > edits, and errors from delegated work are fully visible to the parent session.
311
- > See `plans/ContextOverhaul.md` §10.1 for the design rationale.
368
+ > See `docs/ContextOverhaul.md` §11.1 for the design rationale.
312
369
 
313
370
  When OpenCode spawns a child session (e.g. a subagent or delegated task), the
314
371
  plugin resolves the child's `sessionID` to the root/parent session by walking
@@ -1,3 +1,9 @@
1
+ declare global {
2
+ interface Error {
3
+ cause?: unknown;
4
+ }
5
+ }
6
+ export {};
1
7
  declare global {
2
8
  interface Array<T> {
3
9
  /**
@@ -58,12 +64,6 @@ declare global {
58
64
  }
59
65
  }
60
66
  export {};
61
- declare global {
62
- interface Error {
63
- cause?: unknown;
64
- }
65
- }
66
- export {};
67
67
  /**
68
68
  * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
69
69
  * but instead of using npm to install additional dependencies,
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC,CAAC;QACf;;;;;;;;WAQG;QACH,QAAQ,CAAC,CAAC,SAAS,CAAC,EAClB,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,EACxE,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QACjB,QAAQ,CACN,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EACzD,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QAEjB;;;;;;;;WAQG;QACH,aAAa,CACX,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EACzD,OAAO,CAAC,EAAE,GAAG,GACZ,MAAM,CAAC;KACX;IACD,UAAU,UAAU;QAClB;;;;;;;;WAQG;QACH,QAAQ,CAAC,CAAC,SAAS,MAAM,EACvB,SAAS,EAAE,CACP,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,KAChB,KAAK,IAAI,CAAC,EACf,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QACjB,QAAQ,CACJ,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAA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tE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC"}
package/esm/deno.d.ts CHANGED
@@ -6,7 +6,6 @@ declare namespace _default {
6
6
  export namespace tasks {
7
7
  let build: string;
8
8
  let check: string;
9
- let deploy: string;
10
9
  let dev: string;
11
10
  let lint: string;
12
11
  let fmt: string;
package/esm/deno.js CHANGED
@@ -6,7 +6,6 @@ export default {
6
6
  "tasks": {
7
7
  "build": "deno run -A dnt.ts",
8
8
  "check": "deno check src/index.ts",
9
- "deploy": "deno eval \"throw new Error('Manual publish is disabled. Use the GitHub Actions publish workflow for releases.')\"",
10
9
  "dev": "deno run --allow-all src/index.ts",
11
10
  "lint": "deno lint",
12
11
  "fmt": "deno fmt"
@@ -0,0 +1,14 @@
1
+ /** Type for a ULID generator function. */
2
+ export type ULID = (seedTime?: number) => string;
3
+ export declare const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
4
+ export declare const ENCODING_LEN: number;
5
+ export declare const TIME_MAX: number;
6
+ export declare const TIME_LEN = 10;
7
+ export declare const RANDOM_LEN = 16;
8
+ export declare const ULID_LEN: number;
9
+ export declare function encodeTime(timestamp: number): string;
10
+ export declare function encodeRandom(): string;
11
+ export declare function incrementBase32(str: string): string;
12
+ /** Generates a monotonically increasing ULID. */
13
+ export declare function monotonicFactory(encodeRand?: typeof encodeRandom): ULID;
14
+ //# sourceMappingURL=_util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_util.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/ulid/1.0.0/_util.ts"],"names":[],"mappings":"AAEA,0CAA0C;AAC1C,MAAM,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAIjD,eAAO,MAAM,QAAQ,qCAAqC,CAAC;AAC3D,eAAO,MAAM,YAAY,QAAkB,CAAC;AAC5C,eAAO,MAAM,QAAQ,QAAsB,CAAC;AAC5C,eAAO,MAAM,QAAQ,KAAK,CAAC;AAC3B,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,QAAQ,QAAwB,CAAC;AAM9C,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAapD;AAED,wBAAgB,YAAY,IAAI,MAAM,CAOrC;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAkBnD;AAED,iDAAiD;AACjD,wBAAgB,gBAAgB,CAAC,UAAU,sBAAe,GAAG,IAAI,CAYhE"}
@@ -0,0 +1,65 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // These values should NEVER change. If
3
+ // they do, we're no longer making ulids!
4
+ export const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"; // Crockford's Base32
5
+ export const ENCODING_LEN = ENCODING.length;
6
+ export const TIME_MAX = Math.pow(2, 48) - 1;
7
+ export const TIME_LEN = 10;
8
+ export const RANDOM_LEN = 16;
9
+ export const ULID_LEN = TIME_LEN + RANDOM_LEN;
10
+ function replaceCharAt(str, index, char) {
11
+ return str.substring(0, index) + char + str.substring(index + 1);
12
+ }
13
+ export function encodeTime(timestamp) {
14
+ if (!Number.isInteger(timestamp) || timestamp < 0 || timestamp > TIME_MAX) {
15
+ throw new RangeError(`Time must be a positive integer less than ${TIME_MAX}`);
16
+ }
17
+ let str = "";
18
+ for (let len = TIME_LEN; len > 0; len--) {
19
+ const mod = timestamp % ENCODING_LEN;
20
+ str = ENCODING[mod] + str;
21
+ timestamp = Math.floor(timestamp / ENCODING_LEN);
22
+ }
23
+ return str;
24
+ }
25
+ export function encodeRandom() {
26
+ let str = "";
27
+ const bytes = crypto.getRandomValues(new Uint8Array(RANDOM_LEN));
28
+ for (const byte of bytes) {
29
+ str += ENCODING[byte % ENCODING_LEN];
30
+ }
31
+ return str;
32
+ }
33
+ export function incrementBase32(str) {
34
+ let index = str.length;
35
+ let char;
36
+ let charIndex;
37
+ const maxCharIndex = ENCODING_LEN - 1;
38
+ while (--index >= 0) {
39
+ char = str[index];
40
+ charIndex = ENCODING.indexOf(char);
41
+ if (charIndex === -1) {
42
+ throw new TypeError("Incorrectly encoded string");
43
+ }
44
+ if (charIndex === maxCharIndex) {
45
+ str = replaceCharAt(str, index, ENCODING[0]);
46
+ continue;
47
+ }
48
+ return replaceCharAt(str, index, ENCODING[charIndex + 1]);
49
+ }
50
+ throw new Error("Cannot increment this string");
51
+ }
52
+ /** Generates a monotonically increasing ULID. */
53
+ export function monotonicFactory(encodeRand = encodeRandom) {
54
+ let lastTime = 0;
55
+ let lastRandom;
56
+ return function ulid(seedTime = Date.now()) {
57
+ if (seedTime <= lastTime) {
58
+ const incrementedRandom = (lastRandom = incrementBase32(lastRandom));
59
+ return encodeTime(lastTime) + incrementedRandom;
60
+ }
61
+ lastTime = seedTime;
62
+ const newRandom = (lastRandom = encodeRand());
63
+ return encodeTime(seedTime) + newRandom;
64
+ };
65
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Extracts the number of milliseconds since the Unix epoch that had passed when
3
+ * the ULID was generated. If the ULID is malformed, an error will be thrown.
4
+ *
5
+ * @example Decode the time from a ULID
6
+ * ```ts
7
+ * import { decodeTime, ulid } from "@std/ulid";
8
+ * import { assertEquals } from "@std/assert";
9
+ *
10
+ * const timestamp = 150_000;
11
+ * const ulidString = ulid(timestamp);
12
+ *
13
+ * assertEquals(decodeTime(ulidString), timestamp);
14
+ * ```
15
+ *
16
+ * @param ulid The ULID to extract the timestamp from.
17
+ * @returns The number of milliseconds since the Unix epoch that had passed when the ULID was generated.
18
+ */
19
+ export declare function decodeTime(ulid: string): number;
20
+ //# sourceMappingURL=decode_time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode_time.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/ulid/1.0.0/decode_time.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqB/C"}
@@ -0,0 +1,43 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright 2023 Yoshiya Hinosawa. All rights reserved. MIT license.
3
+ // Copyright 2017 Alizain Feerasta. All rights reserved. MIT license.
4
+ // This module is browser compatible.
5
+ import { ENCODING, ENCODING_LEN, TIME_LEN, TIME_MAX, ULID_LEN, } from "./_util.js";
6
+ /**
7
+ * Extracts the number of milliseconds since the Unix epoch that had passed when
8
+ * the ULID was generated. If the ULID is malformed, an error will be thrown.
9
+ *
10
+ * @example Decode the time from a ULID
11
+ * ```ts
12
+ * import { decodeTime, ulid } from "@std/ulid";
13
+ * import { assertEquals } from "@std/assert";
14
+ *
15
+ * const timestamp = 150_000;
16
+ * const ulidString = ulid(timestamp);
17
+ *
18
+ * assertEquals(decodeTime(ulidString), timestamp);
19
+ * ```
20
+ *
21
+ * @param ulid The ULID to extract the timestamp from.
22
+ * @returns The number of milliseconds since the Unix epoch that had passed when the ULID was generated.
23
+ */
24
+ export function decodeTime(ulid) {
25
+ if (ulid.length !== ULID_LEN) {
26
+ throw new Error(`ULID must be exactly ${ULID_LEN} characters long`);
27
+ }
28
+ const time = ulid
29
+ .substring(0, TIME_LEN)
30
+ .split("")
31
+ .reverse()
32
+ .reduce((carry, char, index) => {
33
+ const encodingIndex = ENCODING.indexOf(char);
34
+ if (encodingIndex === -1) {
35
+ throw new Error(`Invalid ULID character found: ${char}`);
36
+ }
37
+ return (carry += encodingIndex * Math.pow(ENCODING_LEN, index));
38
+ }, 0);
39
+ if (time > TIME_MAX) {
40
+ throw new RangeError(`ULID timestamp component exceeds maximum value of ${TIME_MAX}`);
41
+ }
42
+ return time;
43
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Utilities for generating and working with
3
+ * {@link https://github.com/ulid/spec | Universally Unique Lexicographically Sortable Identifiers (ULIDs)}.
4
+ *
5
+ * To generate a ULID use the {@linkcode ulid} function. This will generate a
6
+ * ULID based on the current time.
7
+ *
8
+ * ```ts no-assert
9
+ * import { ulid } from "@std/ulid";
10
+ *
11
+ * ulid(); // 01HYFKMDF3HVJ4J3JZW8KXPVTY
12
+ * ```
13
+ *
14
+ * {@linkcode ulid} does not guarantee that the ULIDs will be strictly
15
+ * increasing for the same current time. If you need to guarantee that the ULIDs
16
+ * will be strictly increasing, even for the same current time, use the
17
+ * {@linkcode monotonicUlid} function.
18
+ *
19
+ * ```ts no-assert
20
+ * import { monotonicUlid } from "@std/ulid";
21
+ *
22
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAS
23
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAT
24
+ * ```
25
+ *
26
+ * Because each ULID encodes the time it was generated, you can extract the
27
+ * timestamp from a ULID using the {@linkcode decodeTime} function.
28
+ *
29
+ * ```ts
30
+ * import { decodeTime, ulid } from "@std/ulid";
31
+ * import { assertEquals } from "@std/assert";
32
+ *
33
+ * const timestamp = 150_000;
34
+ * const ulidString = ulid(timestamp);
35
+ *
36
+ * assertEquals(decodeTime(ulidString), timestamp);
37
+ * ```
38
+ *
39
+ * @module
40
+ */
41
+ export * from "./decode_time.js";
42
+ export * from "./monotonic_ulid.js";
43
+ export * from "./ulid.js";
44
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/ulid/1.0.0/mod.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC"}
@@ -0,0 +1,47 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright 2023 Yoshiya Hinosawa. All rights reserved. MIT license.
3
+ // Copyright 2017 Alizain Feerasta. All rights reserved. MIT license.
4
+ // This module is browser compatible.
5
+ /**
6
+ * Utilities for generating and working with
7
+ * {@link https://github.com/ulid/spec | Universally Unique Lexicographically Sortable Identifiers (ULIDs)}.
8
+ *
9
+ * To generate a ULID use the {@linkcode ulid} function. This will generate a
10
+ * ULID based on the current time.
11
+ *
12
+ * ```ts no-assert
13
+ * import { ulid } from "@std/ulid";
14
+ *
15
+ * ulid(); // 01HYFKMDF3HVJ4J3JZW8KXPVTY
16
+ * ```
17
+ *
18
+ * {@linkcode ulid} does not guarantee that the ULIDs will be strictly
19
+ * increasing for the same current time. If you need to guarantee that the ULIDs
20
+ * will be strictly increasing, even for the same current time, use the
21
+ * {@linkcode monotonicUlid} function.
22
+ *
23
+ * ```ts no-assert
24
+ * import { monotonicUlid } from "@std/ulid";
25
+ *
26
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAS
27
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAT
28
+ * ```
29
+ *
30
+ * Because each ULID encodes the time it was generated, you can extract the
31
+ * timestamp from a ULID using the {@linkcode decodeTime} function.
32
+ *
33
+ * ```ts
34
+ * import { decodeTime, ulid } from "@std/ulid";
35
+ * import { assertEquals } from "@std/assert";
36
+ *
37
+ * const timestamp = 150_000;
38
+ * const ulidString = ulid(timestamp);
39
+ *
40
+ * assertEquals(decodeTime(ulidString), timestamp);
41
+ * ```
42
+ *
43
+ * @module
44
+ */
45
+ export * from "./decode_time.js";
46
+ export * from "./monotonic_ulid.js";
47
+ export * from "./ulid.js";
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Generate a ULID that monotonically increases even for the same millisecond,
3
+ * optionally passing the current time. If the current time is not passed, it
4
+ * will default to `Date.now()`.
5
+ *
6
+ * Unlike the {@linkcode ulid} function, this function is guaranteed to return
7
+ * strictly increasing ULIDs, even for the same seed time, but only if the seed
8
+ * time only ever increases. If the seed time ever goes backwards, the ULID will
9
+ * still be generated, but it will not be guaranteed to be monotonic with
10
+ * previous ULIDs for that same seed time.
11
+ *
12
+ * @example Generate a monotonic ULID
13
+ * ```ts no-assert
14
+ * import { monotonicUlid } from "@std/ulid";
15
+ *
16
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAS
17
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAT
18
+ * monotonicUlid(); // 01HYFKHHX8H4BRY8BYHAV1BZ2T
19
+ * ```
20
+ *
21
+ * @example Generate a monotonic ULID with a seed time
22
+ * ```ts no-assert
23
+ * import { monotonicUlid } from "@std/ulid";
24
+ *
25
+ * // Strict ordering for the same timestamp, by incrementing the least-significant random bit by 1
26
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1Q
27
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1R
28
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1S
29
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1T
30
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1U
31
+ *
32
+ * // A different timestamp will reset the random bits
33
+ * monotonicUlid(150001); // 0000004JFHJJ2Z7X64FN2B4F1P
34
+ *
35
+ * // A previous seed time will not guarantee ordering, and may result in a
36
+ * // ULID lower than one with the same seed time generated previously
37
+ * monotonicUlid(150000); // 0000004JFJ7XF6D76ES95SZR0X
38
+ * ```
39
+ *
40
+ * @param seedTime The time to base the ULID on, in milliseconds since the Unix epoch. Defaults to `Date.now()`.
41
+ * @returns A ULID that is guaranteed to be strictly increasing for the same seed time.
42
+ */
43
+ export declare function monotonicUlid(seedTime?: number): string;
44
+ //# sourceMappingURL=monotonic_ulid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monotonic_ulid.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,aAAa,CAAC,QAAQ,GAAE,MAAmB,GAAG,MAAM,CAEnE"}
@@ -0,0 +1,51 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright 2023 Yoshiya Hinosawa. All rights reserved. MIT license.
3
+ // Copyright 2017 Alizain Feerasta. All rights reserved. MIT license.
4
+ // This module is browser compatible.
5
+ import { monotonicFactory } from "./_util.js";
6
+ const defaultMonotonicUlid = monotonicFactory();
7
+ /**
8
+ * Generate a ULID that monotonically increases even for the same millisecond,
9
+ * optionally passing the current time. If the current time is not passed, it
10
+ * will default to `Date.now()`.
11
+ *
12
+ * Unlike the {@linkcode ulid} function, this function is guaranteed to return
13
+ * strictly increasing ULIDs, even for the same seed time, but only if the seed
14
+ * time only ever increases. If the seed time ever goes backwards, the ULID will
15
+ * still be generated, but it will not be guaranteed to be monotonic with
16
+ * previous ULIDs for that same seed time.
17
+ *
18
+ * @example Generate a monotonic ULID
19
+ * ```ts no-assert
20
+ * import { monotonicUlid } from "@std/ulid";
21
+ *
22
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAS
23
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAT
24
+ * monotonicUlid(); // 01HYFKHHX8H4BRY8BYHAV1BZ2T
25
+ * ```
26
+ *
27
+ * @example Generate a monotonic ULID with a seed time
28
+ * ```ts no-assert
29
+ * import { monotonicUlid } from "@std/ulid";
30
+ *
31
+ * // Strict ordering for the same timestamp, by incrementing the least-significant random bit by 1
32
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1Q
33
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1R
34
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1S
35
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1T
36
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1U
37
+ *
38
+ * // A different timestamp will reset the random bits
39
+ * monotonicUlid(150001); // 0000004JFHJJ2Z7X64FN2B4F1P
40
+ *
41
+ * // A previous seed time will not guarantee ordering, and may result in a
42
+ * // ULID lower than one with the same seed time generated previously
43
+ * monotonicUlid(150000); // 0000004JFJ7XF6D76ES95SZR0X
44
+ * ```
45
+ *
46
+ * @param seedTime The time to base the ULID on, in milliseconds since the Unix epoch. Defaults to `Date.now()`.
47
+ * @returns A ULID that is guaranteed to be strictly increasing for the same seed time.
48
+ */
49
+ export function monotonicUlid(seedTime = Date.now()) {
50
+ return defaultMonotonicUlid(seedTime);
51
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Generate a ULID, optionally based on a given timestamp. If the timestamp is
3
+ * not passed, it will default to `Date.now()`.
4
+ *
5
+ * Multiple calls to this function with the same seed time will not guarantee
6
+ * that the ULIDs will be strictly increasing, even if the seed time is the
7
+ * same. For that, use the {@linkcode monotonicUlid} function.
8
+ *
9
+ * @example Generate a ULID
10
+ * ```ts no-assert
11
+ * import { ulid } from "@std/ulid";
12
+ *
13
+ * ulid(); // 01HYFKMDF3HVJ4J3JZW8KXPVTY
14
+ * ulid(); // 01HYFKMDF3D2P7G502B9Z2VKV0
15
+ * ulid(); // 01HYFKMDZQ7JD17CRKDXQSZ3Z4
16
+ * ```
17
+ *
18
+ * @example Generate a ULID with a seed time
19
+ * ```ts no-assert
20
+ * import { ulid } from "@std/ulid";
21
+ *
22
+ * ulid(150000); // 0000004JFG3EKDRE04TVVDJW7K
23
+ * ulid(150000); // 0000004JFGN0KHBH0447AK895X
24
+ * ulid(150000); // 0000004JFGMRDH0PN7SM8BZN06
25
+ * ```
26
+ *
27
+ * @param seedTime The time to base the ULID on, in milliseconds since the Unix epoch. Defaults to `Date.now()`.
28
+ * @returns A ULID.
29
+ */
30
+ export declare function ulid(seedTime?: number): string;
31
+ //# sourceMappingURL=ulid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ulid.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/ulid/1.0.0/ulid.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,IAAI,CAAC,QAAQ,GAAE,MAAmB,GAAG,MAAM,CAE1D"}
@@ -0,0 +1,37 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright 2023 Yoshiya Hinosawa. All rights reserved. MIT license.
3
+ // Copyright 2017 Alizain Feerasta. All rights reserved. MIT license.
4
+ // This module is browser compatible.
5
+ import { encodeRandom, encodeTime } from "./_util.js";
6
+ /**
7
+ * Generate a ULID, optionally based on a given timestamp. If the timestamp is
8
+ * not passed, it will default to `Date.now()`.
9
+ *
10
+ * Multiple calls to this function with the same seed time will not guarantee
11
+ * that the ULIDs will be strictly increasing, even if the seed time is the
12
+ * same. For that, use the {@linkcode monotonicUlid} function.
13
+ *
14
+ * @example Generate a ULID
15
+ * ```ts no-assert
16
+ * import { ulid } from "@std/ulid";
17
+ *
18
+ * ulid(); // 01HYFKMDF3HVJ4J3JZW8KXPVTY
19
+ * ulid(); // 01HYFKMDF3D2P7G502B9Z2VKV0
20
+ * ulid(); // 01HYFKMDZQ7JD17CRKDXQSZ3Z4
21
+ * ```
22
+ *
23
+ * @example Generate a ULID with a seed time
24
+ * ```ts no-assert
25
+ * import { ulid } from "@std/ulid";
26
+ *
27
+ * ulid(150000); // 0000004JFG3EKDRE04TVVDJW7K
28
+ * ulid(150000); // 0000004JFGN0KHBH0447AK895X
29
+ * ulid(150000); // 0000004JFGMRDH0PN7SM8BZN06
30
+ * ```
31
+ *
32
+ * @param seedTime The time to base the ULID on, in milliseconds since the Unix epoch. Defaults to `Date.now()`.
33
+ * @returns A ULID.
34
+ */
35
+ export function ulid(seedTime = Date.now()) {
36
+ return encodeTime(seedTime) + encodeRandom();
37
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/src/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,kBAAkB,CAAC;AAkB1E,KAAK,gBAAgB,GAAG;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAEnD,KAAK,mBAAmB,GACpB,uBAAuB,GACvB,yBAAyB,GACzB,kBAAkB,GAClB,gBAAgB,CAAC;AAErB,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;gBAGjC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,mBAAmB,CAAA;KAAE;CAc1D;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACxC,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAAC;CAC1C;AAED,KAAK,qBAAqB,GA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