@coji/durably 0.4.0 → 0.6.1
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 +15 -44
- package/dist/chunk-UCUP6NMJ.js +22 -0
- package/dist/chunk-UCUP6NMJ.js.map +1 -0
- package/dist/index-CHQw-b_O.d.ts +632 -0
- package/dist/index.d.ts +98 -499
- package/dist/index.js +591 -75
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.d.ts +3 -8
- package/dist/plugins/index.js +3 -6
- package/dist/plugins/index.js.map +1 -1
- package/docs/llms.md +129 -17
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -4,65 +4,36 @@ Step-oriented resumable batch execution for Node.js and browsers using SQLite.
|
|
|
4
4
|
|
|
5
5
|
**[Documentation](https://coji.github.io/durably/)** | **[GitHub](https://github.com/coji/durably)** | **[Live Demo](https://durably-demo.vercel.app)**
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- Resumable batch processing with step-level persistence
|
|
10
|
-
- Works in both Node.js and browsers
|
|
11
|
-
- Uses SQLite for state management (better-sqlite3/libsql for Node.js, SQLite WASM for browsers)
|
|
12
|
-
- Minimal dependencies - just Kysely and Zod as peer dependencies
|
|
13
|
-
- Event system for monitoring and extensibility
|
|
14
|
-
- Type-safe input/output with Zod schemas
|
|
7
|
+
> **Note:** This package is ESM-only. CommonJS is not supported.
|
|
15
8
|
|
|
16
9
|
## Installation
|
|
17
10
|
|
|
18
11
|
```bash
|
|
19
|
-
# Node.js with better-sqlite3
|
|
20
12
|
npm install @coji/durably kysely zod better-sqlite3
|
|
21
|
-
|
|
22
|
-
# Node.js with libsql
|
|
23
|
-
npm install @coji/durably kysely zod @libsql/client @libsql/kysely-libsql
|
|
24
|
-
|
|
25
|
-
# Browser with SQLocal
|
|
26
|
-
npm install @coji/durably kysely zod sqlocal
|
|
27
13
|
```
|
|
28
14
|
|
|
29
|
-
|
|
15
|
+
See the [Getting Started Guide](https://coji.github.io/durably/guide/getting-started) for other SQLite backends (libsql, SQLocal for browsers).
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
30
18
|
|
|
31
19
|
```ts
|
|
32
|
-
import { createDurably } from '@coji/durably'
|
|
33
|
-
import SQLite from 'better-sqlite3'
|
|
34
|
-
import { SqliteDialect } from 'kysely'
|
|
20
|
+
import { createDurably, defineJob } from '@coji/durably'
|
|
35
21
|
import { z } from 'zod'
|
|
36
22
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const syncUsers = durably.defineJob(
|
|
44
|
-
{
|
|
45
|
-
name: 'sync-users',
|
|
46
|
-
input: z.object({ orgId: z.string() }),
|
|
47
|
-
output: z.object({ syncedCount: z.number() }),
|
|
48
|
-
},
|
|
49
|
-
async (step, payload) => {
|
|
50
|
-
const users = await step.run('fetch-users', async () => {
|
|
51
|
-
return api.fetchUsers(payload.orgId)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
await step.run('save-to-db', async () => {
|
|
55
|
-
await db.upsertUsers(users)
|
|
23
|
+
const myJob = defineJob({
|
|
24
|
+
name: 'my-job',
|
|
25
|
+
input: z.object({ id: z.string() }),
|
|
26
|
+
run: async (step, payload) => {
|
|
27
|
+
await step.run('step-1', async () => {
|
|
28
|
+
/* ... */
|
|
56
29
|
})
|
|
57
|
-
|
|
58
|
-
return { syncedCount: users.length }
|
|
59
30
|
},
|
|
60
|
-
)
|
|
31
|
+
})
|
|
61
32
|
|
|
62
|
-
|
|
63
|
-
durably.start()
|
|
33
|
+
const durably = createDurably({ dialect }).register({ myJob })
|
|
64
34
|
|
|
65
|
-
await
|
|
35
|
+
await durably.init() // migrate + start
|
|
36
|
+
await durably.jobs.myJob.trigger({ id: '123' })
|
|
66
37
|
```
|
|
67
38
|
|
|
68
39
|
## Documentation
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/plugins/log-persistence.ts
|
|
2
|
+
function withLogPersistence() {
|
|
3
|
+
return {
|
|
4
|
+
name: "log-persistence",
|
|
5
|
+
install(durably) {
|
|
6
|
+
durably.on("log:write", async (event) => {
|
|
7
|
+
await durably.storage.createLog({
|
|
8
|
+
runId: event.runId,
|
|
9
|
+
stepName: event.stepName,
|
|
10
|
+
level: event.level,
|
|
11
|
+
message: event.message,
|
|
12
|
+
data: event.data
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
withLogPersistence
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=chunk-UCUP6NMJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|