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.
- package/README.md +81 -24
- package/esm/_dnt.polyfills.d.ts +6 -6
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/deno.d.ts +0 -1
- package/esm/deno.js +0 -1
- package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts +14 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.js +65 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts +20 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.js +43 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts +44 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.js +47 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts +44 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.js +51 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts +31 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.js +37 -0
- package/esm/src/config.d.ts.map +1 -1
- package/esm/src/config.js +67 -25
- package/esm/src/handlers/chat.d.ts.map +1 -1
- package/esm/src/handlers/chat.js +2 -5
- package/esm/src/handlers/event.d.ts.map +1 -1
- package/esm/src/handlers/event.js +92 -1
- package/esm/src/handlers/messages.d.ts.map +1 -1
- package/esm/src/handlers/messages.js +39 -14
- package/esm/src/handlers/tool-after.d.ts +9 -0
- package/esm/src/handlers/tool-after.d.ts.map +1 -0
- package/esm/src/handlers/tool-after.js +15 -0
- package/esm/src/handlers/tool-before.d.ts +15 -0
- package/esm/src/handlers/tool-before.d.ts.map +1 -0
- package/esm/src/handlers/tool-before.js +70 -0
- package/esm/src/index.d.ts.map +1 -1
- package/esm/src/index.js +183 -89
- package/esm/src/services/batch-drain.d.ts +12 -0
- package/esm/src/services/batch-drain.d.ts.map +1 -1
- package/esm/src/services/batch-drain.js +237 -19
- package/esm/src/services/connection-manager.d.ts +7 -1
- package/esm/src/services/connection-manager.d.ts.map +1 -1
- package/esm/src/services/connection-manager.js +55 -5
- package/esm/src/services/context-limit.d.ts +2 -3
- package/esm/src/services/context-limit.d.ts.map +1 -1
- package/esm/src/services/context-limit.js +19 -7
- package/esm/src/services/endpoint-redaction.d.ts +2 -0
- package/esm/src/services/endpoint-redaction.d.ts.map +1 -0
- package/esm/src/services/endpoint-redaction.js +13 -0
- package/esm/src/services/graphiti-async.d.ts.map +1 -1
- package/esm/src/services/graphiti-async.js +1 -3
- package/esm/src/services/graphiti-mcp.js +4 -4
- package/esm/src/services/redis-client.d.ts +34 -0
- package/esm/src/services/redis-client.d.ts.map +1 -1
- package/esm/src/services/redis-client.js +320 -0
- package/esm/src/services/redis-events.d.ts +1 -0
- package/esm/src/services/redis-events.d.ts.map +1 -1
- package/esm/src/services/redis-events.js +24 -0
- package/esm/src/services/session-corpus.d.ts +90 -0
- package/esm/src/services/session-corpus.d.ts.map +1 -0
- package/esm/src/services/session-corpus.js +1356 -0
- package/esm/src/services/session-executor.d.ts +53 -0
- package/esm/src/services/session-executor.d.ts.map +1 -0
- package/esm/src/services/session-executor.js +312 -0
- package/esm/src/services/session-mcp-runtime.d.ts +33 -0
- package/esm/src/services/session-mcp-runtime.d.ts.map +1 -0
- package/esm/src/services/session-mcp-runtime.js +616 -0
- package/esm/src/services/session-mcp-types.d.ts +504 -0
- package/esm/src/services/session-mcp-types.d.ts.map +1 -0
- package/esm/src/services/session-mcp-types.js +212 -0
- package/esm/src/services/tool-guidance-cache.d.ts +8 -0
- package/esm/src/services/tool-guidance-cache.d.ts.map +1 -0
- package/esm/src/services/tool-guidance-cache.js +25 -0
- package/esm/src/services/tool-guidance.d.ts +29 -0
- package/esm/src/services/tool-guidance.d.ts.map +1 -0
- package/esm/src/services/tool-guidance.js +34 -0
- package/esm/src/services/tool-routing-outcome-cache.d.ts +14 -0
- package/esm/src/services/tool-routing-outcome-cache.d.ts.map +1 -0
- package/esm/src/services/tool-routing-outcome-cache.js +21 -0
- package/esm/src/services/tool-routing.d.ts +38 -0
- package/esm/src/services/tool-routing.d.ts.map +1 -0
- package/esm/src/services/tool-routing.js +122 -0
- package/esm/src/session.d.ts +26 -1
- package/esm/src/session.d.ts.map +1 -1
- package/esm/src/session.js +98 -8
- package/esm/src/types/index.d.ts +2 -0
- package/esm/src/types/index.d.ts.map +1 -1
- package/esm/src/utils.d.ts +8 -0
- package/esm/src/utils.d.ts.map +1 -1
- package/esm/src/utils.js +20 -0
- package/package.json +2 -1
- package/script/_dnt.polyfills.d.ts +6 -6
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/deno.d.ts +0 -1
- package/script/deno.js +0 -1
- package/script/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts +14 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/_util.js +72 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts +20 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/decode_time.js +46 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts +44 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/mod.js +63 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts +44 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.js +54 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts +31 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/ulid/1.0.0/ulid.js +40 -0
- package/script/src/config.d.ts.map +1 -1
- package/script/src/config.js +67 -25
- package/script/src/handlers/chat.d.ts.map +1 -1
- package/script/src/handlers/chat.js +2 -5
- package/script/src/handlers/event.d.ts.map +1 -1
- package/script/src/handlers/event.js +92 -1
- package/script/src/handlers/messages.d.ts.map +1 -1
- package/script/src/handlers/messages.js +38 -13
- package/script/src/handlers/tool-after.d.ts +9 -0
- package/script/src/handlers/tool-after.d.ts.map +1 -0
- package/script/src/handlers/tool-after.js +18 -0
- package/script/src/handlers/tool-before.d.ts +15 -0
- package/script/src/handlers/tool-before.d.ts.map +1 -0
- package/script/src/handlers/tool-before.js +73 -0
- package/script/src/index.d.ts.map +1 -1
- package/script/src/index.js +183 -89
- package/script/src/services/batch-drain.d.ts +12 -0
- package/script/src/services/batch-drain.d.ts.map +1 -1
- package/script/src/services/batch-drain.js +270 -19
- package/script/src/services/connection-manager.d.ts +7 -1
- package/script/src/services/connection-manager.d.ts.map +1 -1
- package/script/src/services/connection-manager.js +55 -5
- package/script/src/services/context-limit.d.ts +2 -3
- package/script/src/services/context-limit.d.ts.map +1 -1
- package/script/src/services/context-limit.js +19 -7
- package/script/src/services/endpoint-redaction.d.ts +2 -0
- package/script/src/services/endpoint-redaction.d.ts.map +1 -0
- package/script/src/services/endpoint-redaction.js +17 -0
- package/script/src/services/graphiti-async.d.ts.map +1 -1
- package/script/src/services/graphiti-async.js +1 -3
- package/script/src/services/graphiti-mcp.js +4 -4
- package/script/src/services/redis-client.d.ts +34 -0
- package/script/src/services/redis-client.d.ts.map +1 -1
- package/script/src/services/redis-client.js +320 -0
- package/script/src/services/redis-events.d.ts +1 -0
- package/script/src/services/redis-events.d.ts.map +1 -1
- package/script/src/services/redis-events.js +24 -0
- package/script/src/services/session-corpus.d.ts +90 -0
- package/script/src/services/session-corpus.d.ts.map +1 -0
- package/script/src/services/session-corpus.js +1360 -0
- package/script/src/services/session-executor.d.ts +53 -0
- package/script/src/services/session-executor.d.ts.map +1 -0
- package/script/src/services/session-executor.js +352 -0
- package/script/src/services/session-mcp-runtime.d.ts +33 -0
- package/script/src/services/session-mcp-runtime.d.ts.map +1 -0
- package/script/src/services/session-mcp-runtime.js +656 -0
- package/script/src/services/session-mcp-types.d.ts +504 -0
- package/script/src/services/session-mcp-types.d.ts.map +1 -0
- package/script/src/services/session-mcp-types.js +215 -0
- package/script/src/services/tool-guidance-cache.d.ts +8 -0
- package/script/src/services/tool-guidance-cache.d.ts.map +1 -0
- package/script/src/services/tool-guidance-cache.js +29 -0
- package/script/src/services/tool-guidance.d.ts +29 -0
- package/script/src/services/tool-guidance.d.ts.map +1 -0
- package/script/src/services/tool-guidance.js +38 -0
- package/script/src/services/tool-routing-outcome-cache.d.ts +14 -0
- package/script/src/services/tool-routing-outcome-cache.d.ts.map +1 -0
- package/script/src/services/tool-routing-outcome-cache.js +25 -0
- package/script/src/services/tool-routing.d.ts +38 -0
- package/script/src/services/tool-routing.d.ts.map +1 -0
- package/script/src/services/tool-routing.js +128 -0
- package/script/src/session.d.ts +26 -1
- package/script/src/session.d.ts.map +1 -1
- package/script/src/session.js +98 -8
- package/script/src/types/index.d.ts +2 -0
- package/script/src/types/index.d.ts.map +1 -1
- package/script/src/utils.d.ts +8 -0
- package/script/src/utils.d.ts.map +1 -1
- 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
|
-
|
|
121
|
-
|
|
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
|
|
213
|
-
user message.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
|
241
|
-
sources:
|
|
295
|
+
On each user message the plugin assembles the current session memory from
|
|
296
|
+
local-only sources:
|
|
242
297
|
|
|
243
|
-
-
|
|
244
|
-
-
|
|
245
|
-
- Cached
|
|
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.
|
|
249
|
-
Graphiti lookup remains on the existing background
|
|
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
|
-
- **
|
|
285
|
-
|
|
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 `
|
|
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
|
package/esm/_dnt.polyfills.d.ts
CHANGED
|
@@ -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":"
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC;AAEV,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,EAAE,UAAU,KAAK,OAAO,EACvE,OAAO,CAAC,EAAE,GAAG,GACd,MAAM,GAAG,SAAS,CAAC;QAEtB;;;;;;;;WAQG;QACH,aAAa,CACT,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,EACvE,OAAO,CAAC,EAAE,GAAG,GACd,MAAM,CAAC;KACX;CACF;AA4CD,OAAO,EAAE,CAAC;AAgBV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC;AACV;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;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
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
|
+
}
|
package/esm/src/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/src/config.ts"],"names":[],"mappings":"AAKA,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;CAiB1D;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,GAAG,MAAM,qBAAqB,CAAC;AAuPzD,eAAO,MAAM,kCAAkC,GAC7C,SAAS,qBAAqB,KAC7B,IAEF,CAAC;AAEF,eAAO,MAAM,oCAAoC,QAAO,IAEvD,CAAC;AA6EF,wBAAgB,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,cAAc,CAgB7D"}
|