@coji/durably 0.12.0 → 0.13.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/dist/{index-hM7-oiyj.d.ts → index-DWsJlgyh.d.ts} +146 -56
- package/dist/index.d.ts +9 -3
- package/dist/index.js +953 -421
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/docs/llms.md +35 -17
- package/package.json +27 -21
- package/LICENSE +0 -21
package/dist/plugins/index.d.ts
CHANGED
package/docs/llms.md
CHANGED
|
@@ -32,10 +32,11 @@ const dialect = new LibsqlDialect({ client })
|
|
|
32
32
|
// Option 1: With jobs (1-step initialization, returns typed instance)
|
|
33
33
|
const durably = createDurably({
|
|
34
34
|
dialect,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
pollingIntervalMs: 1000, // Job polling interval (ms)
|
|
36
|
+
leaseRenewIntervalMs: 5000, // Lease renewal interval (ms)
|
|
37
|
+
leaseMs: 30000, // Lease duration (ms); expired leases are reclaimed
|
|
38
|
+
preserveSteps: false, // Set to true to keep step output data after terminal state (default: false = cleanup)
|
|
39
|
+
retainRuns: '30d', // Auto-delete terminal runs older than 30 days (runs during worker polling; supports 'd', 'h', 'm' units)
|
|
39
40
|
// Optional: type-safe labels with Zod schema
|
|
40
41
|
// labels: z.object({ organizationId: z.string(), env: z.string() }),
|
|
41
42
|
jobs: {
|
|
@@ -210,7 +211,9 @@ const typedRuns = await durably.getRuns<MyRun>({ jobName: 'my-job' })
|
|
|
210
211
|
### Retrigger Failed Runs
|
|
211
212
|
|
|
212
213
|
```ts
|
|
213
|
-
// Creates a fresh run (new ID) with the same input
|
|
214
|
+
// Creates a fresh run (new ID) with the same input and labels
|
|
215
|
+
// Input is validated against the current job schema — throws if incompatible
|
|
216
|
+
// Note: idempotencyKey is not carried forward
|
|
214
217
|
const newRun = await durably.retrigger(runId)
|
|
215
218
|
console.log(newRun.id) // new run ID
|
|
216
219
|
```
|
|
@@ -227,6 +230,21 @@ await durably.cancel(runId)
|
|
|
227
230
|
await durably.deleteRun(runId)
|
|
228
231
|
```
|
|
229
232
|
|
|
233
|
+
### Purge Old Runs
|
|
234
|
+
|
|
235
|
+
Batch-delete terminal runs (completed, failed, cancelled) older than a cutoff date.
|
|
236
|
+
Pending and leased runs are never deleted.
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
// Delete terminal runs older than 30 days
|
|
240
|
+
const deleted = await durably.purgeRuns({
|
|
241
|
+
olderThan: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
|
|
242
|
+
limit: 500, // optional batch size (default: 500)
|
|
243
|
+
})
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
For automatic cleanup, use the `retainRuns` option (see Core Concepts). Cleanup runs during idle worker polling cycles, at most once per minute, in batches of 100.
|
|
247
|
+
|
|
230
248
|
## Events
|
|
231
249
|
|
|
232
250
|
Subscribe to job execution events:
|
|
@@ -234,7 +252,7 @@ Subscribe to job execution events:
|
|
|
234
252
|
```ts
|
|
235
253
|
// Run lifecycle events
|
|
236
254
|
durably.on('run:trigger', (e) => console.log('Triggered:', e.runId))
|
|
237
|
-
durably.on('run:
|
|
255
|
+
durably.on('run:leased', (e) => console.log('Leased:', e.runId))
|
|
238
256
|
durably.on('run:complete', (e) => console.log('Done:', e.output))
|
|
239
257
|
durably.on('run:fail', (e) => console.error('Failed:', e.error))
|
|
240
258
|
durably.on('run:cancel', (e) => console.log('Cancelled:', e.runId))
|
|
@@ -279,8 +297,8 @@ while (true) {
|
|
|
279
297
|
if (done) break
|
|
280
298
|
|
|
281
299
|
switch (value.type) {
|
|
282
|
-
case 'run:
|
|
283
|
-
console.log('
|
|
300
|
+
case 'run:leased':
|
|
301
|
+
console.log('Leased')
|
|
284
302
|
break
|
|
285
303
|
case 'run:complete':
|
|
286
304
|
console.log('Completed:', value.output)
|
|
@@ -367,7 +385,7 @@ GET /runs?label.organizationId=org_123
|
|
|
367
385
|
GET /runs/subscribe?label.organizationId=org_123&label.env=prod
|
|
368
386
|
```
|
|
369
387
|
|
|
370
|
-
**Response Shape:** The `/runs` and `/run` endpoints return `ClientRun` objects (internal fields like `
|
|
388
|
+
**Response Shape:** The `/runs` and `/run` endpoints return `ClientRun` objects (internal fields like `leaseOwner`, `leaseExpiresAt`, `idempotencyKey`, `concurrencyKey`, `updatedAt` are stripped). Use `toClientRun()` to apply the same projection in custom code:
|
|
371
389
|
|
|
372
390
|
```ts
|
|
373
391
|
import { toClientRun } from '@coji/durably'
|
|
@@ -460,9 +478,9 @@ const { dialect } = new SQLocalKysely('app.sqlite3')
|
|
|
460
478
|
|
|
461
479
|
const durably = createDurably({
|
|
462
480
|
dialect,
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
481
|
+
pollingIntervalMs: 100,
|
|
482
|
+
leaseRenewIntervalMs: 500,
|
|
483
|
+
leaseMs: 3000,
|
|
466
484
|
jobs: {
|
|
467
485
|
myJob: defineJob({
|
|
468
486
|
name: 'my-job',
|
|
@@ -481,13 +499,13 @@ await durably.init()
|
|
|
481
499
|
## Run Lifecycle
|
|
482
500
|
|
|
483
501
|
```text
|
|
484
|
-
trigger() → pending →
|
|
485
|
-
↘
|
|
502
|
+
trigger() → pending → leased → completed
|
|
503
|
+
↘ ↗
|
|
486
504
|
→ failed
|
|
487
505
|
```
|
|
488
506
|
|
|
489
507
|
- **pending**: Waiting for worker to pick up
|
|
490
|
-
- **
|
|
508
|
+
- **leased**: Worker has acquired a lease and is executing steps
|
|
491
509
|
- **completed**: All steps finished successfully
|
|
492
510
|
- **failed**: A step threw an error
|
|
493
511
|
- **cancelled**: Manually cancelled via `cancel()`
|
|
@@ -528,7 +546,7 @@ interface StepContext {
|
|
|
528
546
|
interface Run<TLabels extends Record<string, string> = Record<string, string>> {
|
|
529
547
|
id: string
|
|
530
548
|
jobName: string
|
|
531
|
-
status: 'pending' | '
|
|
549
|
+
status: 'pending' | 'leased' | 'completed' | 'failed' | 'cancelled'
|
|
532
550
|
input: unknown
|
|
533
551
|
labels: TLabels
|
|
534
552
|
output: unknown | null
|
|
@@ -603,7 +621,7 @@ interface LogData {
|
|
|
603
621
|
interface RunFilter<
|
|
604
622
|
TLabels extends Record<string, string> = Record<string, string>,
|
|
605
623
|
> {
|
|
606
|
-
status?: 'pending' | '
|
|
624
|
+
status?: 'pending' | 'leased' | 'completed' | 'failed' | 'cancelled'
|
|
607
625
|
jobName?: string | string[]
|
|
608
626
|
labels?: Partial<TLabels>
|
|
609
627
|
limit?: number
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coji/durably",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Step-oriented resumable batch execution for Node.js and browsers using SQLite",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,6 +20,20 @@
|
|
|
20
20
|
"docs",
|
|
21
21
|
"README.md"
|
|
22
22
|
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"test": "pnpm test:node && pnpm test:react && pnpm test:browser",
|
|
26
|
+
"test:node": "vitest run --config vitest.config.ts --exclude 'tests/node/**/*.postgres.test.ts'",
|
|
27
|
+
"test:node:postgres": "vitest run --config vitest.config.ts postgres",
|
|
28
|
+
"test:node:all": "vitest run --config vitest.config.ts",
|
|
29
|
+
"test:react": "vitest run --config vitest.react.config.ts",
|
|
30
|
+
"test:browser": "vitest run --config vitest.browser.config.ts",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"lint": "biome lint .",
|
|
33
|
+
"lint:fix": "biome lint --write .",
|
|
34
|
+
"format": "prettier --experimental-cli --check .",
|
|
35
|
+
"format:fix": "prettier --experimental-cli --write ."
|
|
36
|
+
},
|
|
23
37
|
"keywords": [
|
|
24
38
|
"batch",
|
|
25
39
|
"job",
|
|
@@ -45,20 +59,24 @@
|
|
|
45
59
|
"zod": "^4.0.0"
|
|
46
60
|
},
|
|
47
61
|
"dependencies": {
|
|
62
|
+
"better-sqlite3": "12.6.2",
|
|
48
63
|
"ulidx": "^2.4.1"
|
|
49
64
|
},
|
|
50
65
|
"devDependencies": {
|
|
51
|
-
"@biomejs/biome": "^2.4.
|
|
66
|
+
"@biomejs/biome": "^2.4.7",
|
|
52
67
|
"@libsql/client": "^0.17.0",
|
|
53
68
|
"@libsql/kysely-libsql": "^0.4.1",
|
|
54
69
|
"@testing-library/react": "^16.3.2",
|
|
70
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
71
|
+
"@types/pg": "^8.15.6",
|
|
55
72
|
"@types/react": "^19.2.14",
|
|
56
73
|
"@types/react-dom": "^19.2.3",
|
|
57
|
-
"@vitejs/plugin-react": "^
|
|
58
|
-
"@vitest/browser": "^4.0
|
|
59
|
-
"@vitest/browser-playwright": "4.0
|
|
60
|
-
"jsdom": "^
|
|
61
|
-
"kysely": "^0.28.
|
|
74
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
75
|
+
"@vitest/browser": "^4.1.0",
|
|
76
|
+
"@vitest/browser-playwright": "4.1.0",
|
|
77
|
+
"jsdom": "^29.0.0",
|
|
78
|
+
"kysely": "^0.28.12",
|
|
79
|
+
"pg": "^8.16.3",
|
|
62
80
|
"playwright": "^1.58.2",
|
|
63
81
|
"prettier": "^3.8.1",
|
|
64
82
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
@@ -67,19 +85,7 @@
|
|
|
67
85
|
"sqlocal": "^0.17.0",
|
|
68
86
|
"tsup": "^8.5.1",
|
|
69
87
|
"typescript": "^5.9.3",
|
|
70
|
-
"vitest": "^4.0
|
|
88
|
+
"vitest": "^4.1.0",
|
|
71
89
|
"zod": "^4.3.6"
|
|
72
|
-
},
|
|
73
|
-
"scripts": {
|
|
74
|
-
"build": "tsup",
|
|
75
|
-
"test": "pnpm test:node && pnpm test:react && pnpm test:browser",
|
|
76
|
-
"test:node": "vitest run --config vitest.config.ts",
|
|
77
|
-
"test:react": "vitest run --config vitest.react.config.ts",
|
|
78
|
-
"test:browser": "vitest run --config vitest.browser.config.ts",
|
|
79
|
-
"typecheck": "tsc --noEmit",
|
|
80
|
-
"lint": "biome lint .",
|
|
81
|
-
"lint:fix": "biome lint --write .",
|
|
82
|
-
"format": "prettier --experimental-cli --check .",
|
|
83
|
-
"format:fix": "prettier --experimental-cli --write ."
|
|
84
90
|
}
|
|
85
|
-
}
|
|
91
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 coji
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|