@coji/durably 0.13.0 → 0.14.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 +7 -3
- package/dist/{chunk-UCUP6NMJ.js → chunk-L42OCQEV.js} +3 -3
- package/dist/chunk-L42OCQEV.js.map +1 -0
- package/dist/{index-DWsJlgyh.d.ts → index-CDCdrLgw.d.ts} +4 -2
- package/dist/index.d.ts +23 -3
- package/dist/index.js +295 -210
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +1 -1
- package/docs/llms.md +50 -5
- package/package.json +1 -1
- package/dist/chunk-UCUP6NMJ.js.map +0 -1
package/dist/plugins/index.d.ts
CHANGED
package/dist/plugins/index.js
CHANGED
package/docs/llms.md
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
# Durably - LLM Documentation
|
|
2
2
|
|
|
3
|
-
> Step-oriented resumable batch execution for Node.js and browsers using SQLite.
|
|
3
|
+
> Step-oriented resumable batch execution for Node.js and browsers using SQLite or PostgreSQL.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
Durably is a minimal workflow engine that persists step results to SQLite. If a job is interrupted (server restart, browser tab close, crash), it automatically resumes from the last successful step.
|
|
7
|
+
Durably is a minimal workflow engine that persists step results to SQLite or PostgreSQL. If a job is interrupted (server restart, browser tab close, crash), it automatically resumes from the last successful step. Supports libSQL/Turso (single-server or serverless), PostgreSQL (recommended for multi-worker), and SQLocal (browser/OPFS).
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
# Node.js with
|
|
12
|
+
# Node.js with libSQL (recommended for single-server / Turso)
|
|
13
13
|
pnpm add @coji/durably kysely zod @libsql/client @libsql/kysely-libsql
|
|
14
14
|
|
|
15
|
-
#
|
|
15
|
+
# Node.js with better-sqlite3 (lightweight local alternative)
|
|
16
|
+
pnpm add @coji/durably kysely zod better-sqlite3
|
|
17
|
+
|
|
18
|
+
# Node.js with PostgreSQL (recommended for multi-worker)
|
|
19
|
+
pnpm add @coji/durably kysely zod pg
|
|
20
|
+
|
|
21
|
+
# Browser with SQLocal (OPFS-backed)
|
|
16
22
|
pnpm add @coji/durably kysely zod sqlocal
|
|
17
23
|
```
|
|
18
24
|
|
|
@@ -26,9 +32,31 @@ import { LibsqlDialect } from '@libsql/kysely-libsql'
|
|
|
26
32
|
import { createClient } from '@libsql/client'
|
|
27
33
|
import { z } from 'zod'
|
|
28
34
|
|
|
35
|
+
// --- libSQL local (single-server) ---
|
|
29
36
|
const client = createClient({ url: 'file:local.db' })
|
|
30
37
|
const dialect = new LibsqlDialect({ client })
|
|
31
38
|
|
|
39
|
+
// --- Turso remote (serverless/edge) ---
|
|
40
|
+
// const client = createClient({
|
|
41
|
+
// url: process.env.TURSO_DATABASE_URL!,
|
|
42
|
+
// authToken: process.env.TURSO_AUTH_TOKEN!,
|
|
43
|
+
// })
|
|
44
|
+
// const dialect = new LibsqlDialect({ client })
|
|
45
|
+
|
|
46
|
+
// --- better-sqlite3 (lightweight local) ---
|
|
47
|
+
// import Database from 'better-sqlite3'
|
|
48
|
+
// import { SqliteDialect } from 'kysely'
|
|
49
|
+
// const dialect = new SqliteDialect({
|
|
50
|
+
// database: new Database('local.db'),
|
|
51
|
+
// })
|
|
52
|
+
|
|
53
|
+
// --- PostgreSQL (multi-worker) ---
|
|
54
|
+
// import pg from 'pg'
|
|
55
|
+
// import { PostgresDialect } from 'kysely'
|
|
56
|
+
// const dialect = new PostgresDialect({
|
|
57
|
+
// pool: new pg.Pool({ connectionString: process.env.DATABASE_URL }),
|
|
58
|
+
// })
|
|
59
|
+
|
|
32
60
|
// Option 1: With jobs (1-step initialization, returns typed instance)
|
|
33
61
|
const durably = createDurably({
|
|
34
62
|
dialect,
|
|
@@ -247,7 +275,7 @@ For automatic cleanup, use the `retainRuns` option (see Core Concepts). Cleanup
|
|
|
247
275
|
|
|
248
276
|
## Events
|
|
249
277
|
|
|
250
|
-
Subscribe to job execution events
|
|
278
|
+
Subscribe to job execution events. **Listeners run synchronously** in the worker's hot path — keep them fast and non-blocking. Use fire-and-forget (`void asyncFn()`) for expensive work.
|
|
251
279
|
|
|
252
280
|
```ts
|
|
253
281
|
// Run lifecycle events
|
|
@@ -629,6 +657,23 @@ interface RunFilter<
|
|
|
629
657
|
}
|
|
630
658
|
```
|
|
631
659
|
|
|
660
|
+
## Error Classes
|
|
661
|
+
|
|
662
|
+
Durably exports typed error classes for programmatic error handling:
|
|
663
|
+
|
|
664
|
+
```ts
|
|
665
|
+
import {
|
|
666
|
+
DurablyError, // Base class with statusCode (extends Error)
|
|
667
|
+
NotFoundError, // 404 — resource not found
|
|
668
|
+
ValidationError, // 400 — invalid input or request
|
|
669
|
+
ConflictError, // 409 — operation conflicts with current state
|
|
670
|
+
CancelledError, // Run was cancelled during execution
|
|
671
|
+
LeaseLostError, // Worker lost lease ownership
|
|
672
|
+
} from '@coji/durably'
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
`DurablyError` subclasses (`NotFoundError`, `ValidationError`, `ConflictError`) carry a `statusCode` property and are used by the HTTP handler to return appropriate responses.
|
|
676
|
+
|
|
632
677
|
## License
|
|
633
678
|
|
|
634
679
|
MIT
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugins/log-persistence.ts"],"sourcesContent":["import type { DurablyPlugin } from '../durably'\n\n/**\n * Plugin that persists log events to the database\n */\nexport function withLogPersistence(): DurablyPlugin {\n return {\n name: 'log-persistence',\n install(durably) {\n durably.on('log:write', async (event) => {\n await durably.storage.createLog({\n runId: event.runId,\n stepName: event.stepName,\n level: event.level,\n message: event.message,\n data: event.data,\n })\n })\n },\n }\n}\n"],"mappings":";AAKO,SAAS,qBAAoC;AAClD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,SAAS;AACf,cAAQ,GAAG,aAAa,OAAO,UAAU;AACvC,cAAM,QAAQ,QAAQ,UAAU;AAAA,UAC9B,OAAO,MAAM;AAAA,UACb,UAAU,MAAM;AAAA,UAChB,OAAO,MAAM;AAAA,UACb,SAAS,MAAM;AAAA,UACf,MAAM,MAAM;AAAA,QACd,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|