@coji/durably 0.12.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @coji/durably
2
2
 
3
- Step-oriented resumable batch execution for Node.js and browsers using SQLite.
3
+ Steps that survive crashes. SQLite to PostgreSQL.
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
 
@@ -9,10 +9,14 @@ Step-oriented resumable batch execution for Node.js and browsers using SQLite.
9
9
  ## Installation
10
10
 
11
11
  ```bash
12
- npm install @coji/durably kysely zod better-sqlite3
12
+ # libSQL (recommended default)
13
+ npm install @coji/durably kysely zod @libsql/client @libsql/kysely-libsql
14
+
15
+ # PostgreSQL (multi-worker)
16
+ npm install @coji/durably kysely zod pg
13
17
  ```
14
18
 
15
- See the [Quick Start](https://coji.github.io/durably/guide/quick-start) for other SQLite backends (libsql, SQLocal for browsers).
19
+ See [Choosing a Database](https://coji.github.io/durably/guide/databases) for all backends.
16
20
 
17
21
  ## Quick Start
18
22
 
@@ -3,8 +3,8 @@ function withLogPersistence() {
3
3
  return {
4
4
  name: "log-persistence",
5
5
  install(durably) {
6
- durably.on("log:write", async (event) => {
7
- await durably.storage.createLog({
6
+ durably.on("log:write", (event) => {
7
+ void durably.storage.createLog({
8
8
  runId: event.runId,
9
9
  stepName: event.stepName,
10
10
  level: event.level,
@@ -19,4 +19,4 @@ function withLogPersistence() {
19
19
  export {
20
20
  withLogPersistence
21
21
  };
22
- //# sourceMappingURL=chunk-UCUP6NMJ.js.map
22
+ //# sourceMappingURL=chunk-L42OCQEV.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 * Uses fire-and-forget writes — log persistence is best-effort.\n */\nexport function withLogPersistence(): DurablyPlugin {\n return {\n name: 'log-persistence',\n install(durably) {\n durably.on('log:write', (event) => {\n void 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":";AAMO,SAAS,qBAAoC;AAClD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,SAAS;AACf,cAAQ,GAAG,aAAa,CAAC,UAAU;AACjC,aAAK,QAAQ,QAAQ,UAAU;AAAA,UAC7B,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":[]}
@@ -20,13 +20,23 @@ interface RunTriggerEvent extends BaseEvent {
20
20
  labels: Record<string, string>;
21
21
  }
22
22
  /**
23
- * Run start event
23
+ * Run leased event
24
24
  */
25
- interface RunStartEvent extends BaseEvent {
26
- type: 'run:start';
25
+ interface RunLeasedEvent extends BaseEvent {
26
+ type: 'run:leased';
27
27
  runId: string;
28
28
  jobName: string;
29
29
  input: unknown;
30
+ leaseOwner: string;
31
+ leaseExpiresAt: string;
32
+ labels: Record<string, string>;
33
+ }
34
+ interface RunLeaseRenewedEvent extends BaseEvent {
35
+ type: 'run:lease-renewed';
36
+ runId: string;
37
+ jobName: string;
38
+ leaseOwner: string;
39
+ leaseExpiresAt: string;
30
40
  labels: Record<string, string>;
31
41
  }
32
42
  /**
@@ -72,7 +82,7 @@ interface RunDeleteEvent extends BaseEvent {
72
82
  /**
73
83
  * Progress data reported by step.progress()
74
84
  */
75
- interface ProgressData {
85
+ interface ProgressData$1 {
76
86
  current: number;
77
87
  total?: number;
78
88
  message?: string;
@@ -84,7 +94,7 @@ interface RunProgressEvent extends BaseEvent {
84
94
  type: 'run:progress';
85
95
  runId: string;
86
96
  jobName: string;
87
- progress: ProgressData;
97
+ progress: ProgressData$1;
88
98
  labels: Record<string, string>;
89
99
  }
90
100
  /**
@@ -163,7 +173,7 @@ interface WorkerErrorEvent extends BaseEvent {
163
173
  /**
164
174
  * All event types as discriminated union
165
175
  */
166
- type DurablyEvent = RunTriggerEvent | RunStartEvent | RunCompleteEvent | RunFailEvent | RunCancelEvent | RunDeleteEvent | RunProgressEvent | StepStartEvent | StepCompleteEvent | StepFailEvent | StepCancelEvent | LogWriteEvent | WorkerErrorEvent;
176
+ type DurablyEvent = RunTriggerEvent | RunLeasedEvent | RunLeaseRenewedEvent | RunCompleteEvent | RunFailEvent | RunCancelEvent | RunDeleteEvent | RunProgressEvent | StepStartEvent | StepCompleteEvent | StepFailEvent | StepCancelEvent | LogWriteEvent | WorkerErrorEvent;
167
177
  /**
168
178
  * Event types for type-safe event names
169
179
  */
@@ -181,7 +191,7 @@ type EventInput<T extends EventType> = Omit<EventByType<T>, 'timestamp' | 'seque
181
191
  /**
182
192
  * All possible event inputs as a union (properly distributed)
183
193
  */
184
- type AnyEventInput = EventInput<'run:trigger'> | EventInput<'run:start'> | EventInput<'run:complete'> | EventInput<'run:fail'> | EventInput<'run:cancel'> | EventInput<'run:delete'> | EventInput<'run:progress'> | EventInput<'step:start'> | EventInput<'step:complete'> | EventInput<'step:fail'> | EventInput<'step:cancel'> | EventInput<'log:write'> | EventInput<'worker:error'>;
194
+ type AnyEventInput = EventInput<'run:trigger'> | EventInput<'run:leased'> | EventInput<'run:lease-renewed'> | EventInput<'run:complete'> | EventInput<'run:fail'> | EventInput<'run:cancel'> | EventInput<'run:delete'> | EventInput<'run:progress'> | EventInput<'step:start'> | EventInput<'step:complete'> | EventInput<'step:fail'> | EventInput<'step:cancel'> | EventInput<'log:write'> | EventInput<'worker:error'>;
185
195
  /**
186
196
  * Event listener function
187
197
  */
@@ -202,15 +212,18 @@ interface RunsTable {
202
212
  id: string;
203
213
  job_name: string;
204
214
  input: string;
205
- status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
215
+ status: 'pending' | 'leased' | 'completed' | 'failed' | 'cancelled';
206
216
  idempotency_key: string | null;
207
217
  concurrency_key: string | null;
208
218
  current_step_index: number;
219
+ completed_step_count: number;
209
220
  progress: string | null;
210
221
  output: string | null;
211
222
  error: string | null;
212
223
  labels: string;
213
- heartbeat_at: string;
224
+ lease_owner: string | null;
225
+ lease_expires_at: string | null;
226
+ lease_generation: number;
214
227
  started_at: string | null;
215
228
  completed_at: string | null;
216
229
  created_at: string;
@@ -236,17 +249,24 @@ interface LogsTable {
236
249
  data: string | null;
237
250
  created_at: string;
238
251
  }
252
+ interface RunLabelsTable {
253
+ run_id: string;
254
+ key: string;
255
+ value: string;
256
+ }
239
257
  interface SchemaVersionsTable {
240
258
  version: number;
241
259
  applied_at: string;
242
260
  }
243
261
  interface Database {
244
262
  durably_runs: RunsTable;
263
+ durably_run_labels: RunLabelsTable;
245
264
  durably_steps: StepsTable;
246
265
  durably_logs: LogsTable;
247
266
  durably_schema_versions: SchemaVersionsTable;
248
267
  }
249
268
 
269
+ type RunStatus = 'pending' | 'leased' | 'completed' | 'failed' | 'cancelled';
250
270
  /**
251
271
  * Run data for creating a new run
252
272
  */
@@ -264,11 +284,11 @@ interface Run<TLabels extends Record<string, string> = Record<string, string>> {
264
284
  id: string;
265
285
  jobName: string;
266
286
  input: unknown;
267
- status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
287
+ status: RunStatus;
268
288
  idempotencyKey: string | null;
269
289
  concurrencyKey: string | null;
270
290
  currentStepIndex: number;
271
- stepCount: number;
291
+ completedStepCount: number;
272
292
  progress: {
273
293
  current: number;
274
294
  total?: number;
@@ -277,34 +297,19 @@ interface Run<TLabels extends Record<string, string> = Record<string, string>> {
277
297
  output: unknown | null;
278
298
  error: string | null;
279
299
  labels: TLabels;
280
- heartbeatAt: string;
300
+ leaseOwner: string | null;
301
+ leaseExpiresAt: string | null;
302
+ leaseGeneration: number;
281
303
  startedAt: string | null;
282
304
  completedAt: string | null;
283
305
  createdAt: string;
284
306
  updatedAt: string;
285
307
  }
286
- /**
287
- * Run update data
288
- */
289
- interface UpdateRunInput {
290
- status?: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
291
- currentStepIndex?: number;
292
- progress?: {
293
- current: number;
294
- total?: number;
295
- message?: string;
296
- } | null;
297
- output?: unknown;
298
- error?: string | null;
299
- heartbeatAt?: string;
300
- startedAt?: string;
301
- completedAt?: string;
302
- }
303
308
  /**
304
309
  * Run filter options
305
310
  */
306
311
  interface RunFilter<TLabels extends Record<string, string> = Record<string, string>> {
307
- status?: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
312
+ status?: RunStatus;
308
313
  /** Filter by job name(s). Pass a string for one, or an array for multiple (OR). */
309
314
  jobName?: string | string[];
310
315
  /** Filter by labels (all specified labels must match) */
@@ -317,10 +322,9 @@ interface RunFilter<TLabels extends Record<string, string> = Record<string, stri
317
322
  offset?: number;
318
323
  }
319
324
  /**
320
- * Step data for creating a new step
325
+ * Step data for persisting a step checkpoint
321
326
  */
322
327
  interface CreateStepInput {
323
- runId: string;
324
328
  name: string;
325
329
  index: number;
326
330
  status: 'completed' | 'failed' | 'cancelled';
@@ -364,33 +368,73 @@ interface Log {
364
368
  data: unknown | null;
365
369
  createdAt: string;
366
370
  }
371
+ interface ProgressData {
372
+ current: number;
373
+ total?: number;
374
+ message?: string;
375
+ }
376
+ type DatabaseBackend = 'generic' | 'postgres';
367
377
  /**
368
- * A client-safe subset of Run, excluding internal fields like
369
- * heartbeatAt, idempotencyKey, concurrencyKey, and updatedAt.
370
- */
371
- type ClientRun<TLabels extends Record<string, string> = Record<string, string>> = Omit<Run<TLabels>, 'idempotencyKey' | 'concurrencyKey' | 'heartbeatAt' | 'updatedAt'>;
372
- /**
373
- * Project a full Run to a ClientRun by stripping internal fields.
378
+ * Data for updating a run
374
379
  */
375
- declare function toClientRun<TLabels extends Record<string, string> = Record<string, string>>(run: Run<TLabels>): ClientRun<TLabels>;
380
+ interface UpdateRunData {
381
+ status?: RunStatus;
382
+ currentStepIndex?: number;
383
+ progress?: ProgressData | null;
384
+ output?: unknown;
385
+ error?: string | null;
386
+ leaseOwner?: string | null;
387
+ leaseExpiresAt?: string | null;
388
+ startedAt?: string;
389
+ completedAt?: string;
390
+ }
376
391
  /**
377
- * Storage interface for database operations
392
+ * Unified storage interface used by the runtime.
378
393
  */
379
- interface Storage {
380
- createRun(input: CreateRunInput): Promise<Run>;
381
- batchCreateRuns(inputs: CreateRunInput[]): Promise<Run[]>;
382
- updateRun(runId: string, data: UpdateRunInput): Promise<void>;
394
+ interface Store<TLabels extends Record<string, string> = Record<string, string>> {
395
+ enqueue(input: CreateRunInput<TLabels>): Promise<Run<TLabels>>;
396
+ enqueueMany(inputs: CreateRunInput<TLabels>[]): Promise<Run<TLabels>[]>;
397
+ getRun<T extends Run<TLabels> = Run<TLabels>>(runId: string): Promise<T | null>;
398
+ getRuns<T extends Run<TLabels> = Run<TLabels>>(filter?: RunFilter<TLabels>): Promise<T[]>;
399
+ updateRun(runId: string, data: UpdateRunData): Promise<void>;
383
400
  deleteRun(runId: string): Promise<void>;
384
- getRun<T extends Run = Run>(runId: string): Promise<T | null>;
385
- getRuns<T extends Run = Run>(filter?: RunFilter): Promise<T[]>;
386
- claimNextPendingRun(excludeConcurrencyKeys: string[]): Promise<Run | null>;
387
- createStep(input: CreateStepInput): Promise<Step>;
388
- deleteSteps(runId: string): Promise<void>;
401
+ claimNext(workerId: string, now: string, leaseMs: number): Promise<Run<TLabels> | null>;
402
+ renewLease(runId: string, leaseGeneration: number, now: string, leaseMs: number): Promise<boolean>;
403
+ releaseExpiredLeases(now: string): Promise<number>;
404
+ completeRun(runId: string, leaseGeneration: number, output: unknown, completedAt: string): Promise<boolean>;
405
+ failRun(runId: string, leaseGeneration: number, error: string, completedAt: string): Promise<boolean>;
406
+ cancelRun(runId: string, now: string): Promise<boolean>;
407
+ /**
408
+ * Atomically persist a step checkpoint, guarded by lease generation.
409
+ * Inserts the step record and advances currentStepIndex (for completed
410
+ * steps only) in a single transaction. Returns null if the generation
411
+ * does not match (lease was lost).
412
+ */
413
+ persistStep(runId: string, leaseGeneration: number, input: CreateStepInput): Promise<Step | null>;
389
414
  getSteps(runId: string): Promise<Step[]>;
390
415
  getCompletedStep(runId: string, name: string): Promise<Step | null>;
416
+ deleteSteps(runId: string): Promise<void>;
417
+ updateProgress(runId: string, leaseGeneration: number, progress: ProgressData | null): Promise<void>;
418
+ purgeRuns(options: {
419
+ olderThan: string;
420
+ limit?: number;
421
+ }): Promise<number>;
391
422
  createLog(input: CreateLogInput): Promise<Log>;
392
423
  getLogs(runId: string): Promise<Log[]>;
393
424
  }
425
+ /**
426
+ * A client-safe subset of Run, excluding internal fields like
427
+ * leaseOwner, leaseExpiresAt, idempotencyKey, concurrencyKey, and updatedAt.
428
+ */
429
+ type ClientRun<TLabels extends Record<string, string> = Record<string, string>> = Omit<Run<TLabels>, 'idempotencyKey' | 'concurrencyKey' | 'leaseOwner' | 'leaseExpiresAt' | 'leaseGeneration' | 'updatedAt'>;
430
+ /**
431
+ * Project a full Run to a ClientRun by stripping internal fields.
432
+ */
433
+ declare function toClientRun<TLabels extends Record<string, string> = Record<string, string>>(run: Run<TLabels>): ClientRun<TLabels>;
434
+ /**
435
+ * Create a Kysely-based Store implementation
436
+ */
437
+ declare function createKyselyStore(db: Kysely<Database>, backend?: DatabaseBackend): Store<Record<string, string>>;
394
438
 
395
439
  /**
396
440
  * Step context passed to the job function
@@ -400,6 +444,18 @@ interface StepContext {
400
444
  * The ID of the current run
401
445
  */
402
446
  readonly runId: string;
447
+ /**
448
+ * AbortSignal for cooperative cancellation or lease-loss handling.
449
+ */
450
+ readonly signal: AbortSignal;
451
+ /**
452
+ * Whether this execution should stop cooperatively.
453
+ */
454
+ isAborted(): boolean;
455
+ /**
456
+ * Throw if execution has been cancelled or lease ownership was lost.
457
+ */
458
+ throwIfAborted(): void;
403
459
  /**
404
460
  * Execute a step with automatic persistence and replay
405
461
  */
@@ -432,7 +488,7 @@ interface TriggerAndWaitOptions<TLabels extends Record<string, string> = Record<
432
488
  /** Timeout in milliseconds */
433
489
  timeout?: number;
434
490
  /** Called when step.progress() is invoked during execution */
435
- onProgress?: (progress: ProgressData) => void | Promise<void>;
491
+ onProgress?: (progress: ProgressData$1) => void | Promise<void>;
436
492
  /** Called when step.log is invoked during execution */
437
493
  onLog?: (log: LogData) => void | Promise<void>;
438
494
  }
@@ -550,10 +606,15 @@ declare function defineJob<TName extends string, TInputSchema extends z.ZodType,
550
606
  */
551
607
  interface DurablyOptions<TLabels extends Record<string, string> = Record<string, string>, TJobs extends Record<string, JobDefinition<string, any, any>> = Record<string, never>> {
552
608
  dialect: Dialect;
553
- pollingInterval?: number;
554
- heartbeatInterval?: number;
555
- staleThreshold?: number;
556
- cleanupSteps?: boolean;
609
+ /**
610
+ * Browser-local singleton key used to detect multiple runtimes against the same local database in one tab.
611
+ * When omitted, Durably will use browser-local dialect metadata if available.
612
+ */
613
+ singletonKey?: string;
614
+ pollingIntervalMs?: number;
615
+ leaseRenewIntervalMs?: number;
616
+ leaseMs?: number;
617
+ preserveSteps?: boolean;
557
618
  /**
558
619
  * Zod schema for labels. When provided:
559
620
  * - Labels are type-checked at compile time
@@ -571,6 +632,12 @@ interface DurablyOptions<TLabels extends Record<string, string> = Record<string,
571
632
  * ```
572
633
  */
573
634
  jobs?: TJobs;
635
+ /**
636
+ * Auto-delete terminal runs older than the specified duration.
637
+ * Only runs in terminal states (completed, failed, cancelled) are purged.
638
+ * @example '30d' (30 days), '24h' (24 hours), '60m' (60 minutes)
639
+ */
640
+ retainRuns?: string;
574
641
  }
575
642
  /**
576
643
  * Plugin interface for extending Durably
@@ -617,7 +684,7 @@ interface Durably<TJobs extends Record<string, JobHandle<string, unknown, unknow
617
684
  /**
618
685
  * Storage layer for database operations
619
686
  */
620
- readonly storage: Storage;
687
+ readonly storage: Store<TLabels>;
621
688
  /**
622
689
  * Register an event listener
623
690
  * @returns Unsubscribe function
@@ -645,10 +712,25 @@ interface Durably<TJobs extends Record<string, JobHandle<string, unknown, unknow
645
712
  * ```
646
713
  */
647
714
  register<TNewJobs extends Record<string, JobDefinition<string, any, any>>>(jobDefs: TNewJobs): Durably<TJobs & TransformToHandles<TNewJobs, TLabels>, TLabels>;
715
+ /**
716
+ * Process a single claimable run.
717
+ */
718
+ processOne(options?: {
719
+ workerId?: string;
720
+ }): Promise<boolean>;
721
+ /**
722
+ * Process runs until the queue appears idle.
723
+ */
724
+ processUntilIdle(options?: {
725
+ workerId?: string;
726
+ maxRuns?: number;
727
+ }): Promise<number>;
648
728
  /**
649
729
  * Start the worker polling loop
650
730
  */
651
- start(): void;
731
+ start(options?: {
732
+ workerId?: string;
733
+ }): void;
652
734
  /**
653
735
  * Stop the worker after current run completes
654
736
  */
@@ -668,6 +750,15 @@ interface Durably<TJobs extends Record<string, JobHandle<string, unknown, unknow
668
750
  * @throws Error if run is pending or running, or does not exist
669
751
  */
670
752
  deleteRun(runId: string): Promise<void>;
753
+ /**
754
+ * Delete terminal runs older than the specified cutoff.
755
+ * Only runs in terminal states (completed, failed, cancelled) are purged.
756
+ * @returns Number of deleted runs
757
+ */
758
+ purgeRuns(options: {
759
+ olderThan: Date;
760
+ limit?: number;
761
+ }): Promise<number>;
671
762
  /**
672
763
  * Get a run by ID
673
764
  * @example
@@ -718,8 +809,9 @@ declare function createDurably<TLabels extends Record<string, string> = Record<s
718
809
  declare function createDurably<TLabels extends Record<string, string> = Record<string, string>>(options: DurablyOptions<TLabels>): Durably<Record<string, never>, TLabels>;
719
810
 
720
811
  /**
721
- * Plugin that persists log events to the database
812
+ * Plugin that persists log events to the database.
813
+ * Uses fire-and-forget writes — log persistence is best-effort.
722
814
  */
723
815
  declare function withLogPersistence(): DurablyPlugin;
724
816
 
725
- export { type StepsTable as A, type BatchTriggerInput as B, type ClientRun as C, type Durably as D, type ErrorHandler as E, type TriggerAndWaitResult as F, type TriggerOptions as G, createDurably as H, defineJob as I, type JobDefinition as J, toClientRun as K, type Log as L, withLogPersistence as M, type ProgressData as P, type Run as R, type SchemaVersionsTable as S, type TriggerAndWaitOptions as T, type WorkerErrorEvent as W, type RunFilter as a, type Database as b, type DurablyEvent as c, type DurablyOptions as d, type DurablyPlugin as e, type EventType as f, type JobHandle as g, type JobInput as h, type JobOutput as i, type LogData as j, type LogWriteEvent as k, type LogsTable as l, type RunCancelEvent as m, type RunCompleteEvent as n, type RunDeleteEvent as o, type RunFailEvent as p, type RunProgressEvent as q, type RunStartEvent as r, type RunTriggerEvent as s, type RunsTable as t, type Step as u, type StepCancelEvent as v, type StepCompleteEvent as w, type StepContext as x, type StepFailEvent as y, type StepStartEvent as z };
817
+ export { type StepFailEvent as A, type BatchTriggerInput as B, type ClientRun as C, type Durably as D, type ErrorHandler as E, type StepStartEvent as F, type StepsTable as G, type Store as H, type TriggerAndWaitResult as I, type JobDefinition as J, type TriggerOptions as K, type Log as L, createDurably as M, createKyselyStore as N, defineJob as O, type ProgressData$1 as P, toClientRun as Q, type Run as R, type SchemaVersionsTable as S, type TriggerAndWaitOptions as T, type UpdateRunData as U, withLogPersistence as V, type WorkerErrorEvent as W, type RunFilter as a, type Database as b, type DurablyEvent as c, type DurablyOptions as d, type DurablyPlugin as e, type EventType as f, type JobHandle as g, type JobInput as h, type JobOutput as i, type LogData as j, type LogWriteEvent as k, type LogsTable as l, type RunCancelEvent as m, type RunCompleteEvent as n, type RunDeleteEvent as o, type RunFailEvent as p, type RunLeaseRenewedEvent as q, type RunLeasedEvent as r, type RunProgressEvent as s, type RunStatus as t, type RunTriggerEvent as u, type RunsTable as v, type Step as w, type StepCancelEvent as x, type StepCompleteEvent as y, type StepContext as z };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as Run, a as RunFilter, D as Durably } from './index-hM7-oiyj.js';
2
- export { B as BatchTriggerInput, C as ClientRun, b as Database, c as DurablyEvent, d as DurablyOptions, e as DurablyPlugin, E as ErrorHandler, f as EventType, J as JobDefinition, g as JobHandle, h as JobInput, i as JobOutput, L as Log, j as LogData, k as LogWriteEvent, l as LogsTable, P as ProgressData, m as RunCancelEvent, n as RunCompleteEvent, o as RunDeleteEvent, p as RunFailEvent, q as RunProgressEvent, r as RunStartEvent, s as RunTriggerEvent, t as RunsTable, S as SchemaVersionsTable, u as Step, v as StepCancelEvent, w as StepCompleteEvent, x as StepContext, y as StepFailEvent, z as StepStartEvent, A as StepsTable, T as TriggerAndWaitOptions, F as TriggerAndWaitResult, G as TriggerOptions, W as WorkerErrorEvent, H as createDurably, I as defineJob, K as toClientRun, M as withLogPersistence } from './index-hM7-oiyj.js';
1
+ import { R as Run, a as RunFilter, D as Durably } from './index-CDCdrLgw.js';
2
+ export { B as BatchTriggerInput, C as ClientRun, b as Database, c as DurablyEvent, d as DurablyOptions, e as DurablyPlugin, E as ErrorHandler, f as EventType, J as JobDefinition, g as JobHandle, h as JobInput, i as JobOutput, L as Log, j as LogData, k as LogWriteEvent, l as LogsTable, P as ProgressData, m as RunCancelEvent, n as RunCompleteEvent, o as RunDeleteEvent, p as RunFailEvent, q as RunLeaseRenewedEvent, r as RunLeasedEvent, s as RunProgressEvent, t as RunStatus, u as RunTriggerEvent, v as RunsTable, S as SchemaVersionsTable, w as Step, x as StepCancelEvent, y as StepCompleteEvent, z as StepContext, A as StepFailEvent, F as StepStartEvent, G as StepsTable, H as Store, T as TriggerAndWaitOptions, I as TriggerAndWaitResult, K as TriggerOptions, U as UpdateRunData, W as WorkerErrorEvent, M as createDurably, N as createKyselyStore, O as defineJob, Q as toClientRun, V as withLogPersistence } from './index-CDCdrLgw.js';
3
3
  import 'kysely';
4
4
  import 'zod';
5
5
 
@@ -11,6 +11,32 @@ import 'zod';
11
11
  declare class CancelledError extends Error {
12
12
  constructor(runId: string);
13
13
  }
14
+ /**
15
+ * Error thrown when a worker loses lease ownership during execution.
16
+ */
17
+ declare class LeaseLostError extends Error {
18
+ constructor(runId: string);
19
+ }
20
+ /**
21
+ * Base class for errors that map to specific HTTP status codes.
22
+ * Used by the HTTP handler to return appropriate responses.
23
+ */
24
+ declare class DurablyError extends Error {
25
+ readonly statusCode: number;
26
+ constructor(message: string, statusCode: number);
27
+ }
28
+ /** 404 — Resource not found */
29
+ declare class NotFoundError extends DurablyError {
30
+ constructor(message: string);
31
+ }
32
+ /** 400 — Invalid input or request */
33
+ declare class ValidationError extends DurablyError {
34
+ constructor(message: string);
35
+ }
36
+ /** 409 — Operation conflicts with current state */
37
+ declare class ConflictError extends DurablyError {
38
+ constructor(message: string);
39
+ }
14
40
 
15
41
  /**
16
42
  * Run operation types for onRunAccess
@@ -101,4 +127,4 @@ interface CreateDurablyHandlerOptions<TContext = undefined, TLabels extends Reco
101
127
  */
102
128
  declare function createDurablyHandler<TContext = undefined, TLabels extends Record<string, string> = Record<string, string>>(durably: Durably<any, TLabels>, options?: CreateDurablyHandlerOptions<TContext, TLabels>): DurablyHandler;
103
129
 
104
- export { type AuthConfig, CancelledError, type CreateDurablyHandlerOptions, Durably, type DurablyHandler, Run, RunFilter, type RunOperation, type RunsSubscribeFilter, type TriggerRequest, type TriggerResponse, createDurablyHandler };
130
+ export { type AuthConfig, CancelledError, ConflictError, type CreateDurablyHandlerOptions, Durably, DurablyError, type DurablyHandler, LeaseLostError, NotFoundError, Run, RunFilter, type RunOperation, type RunsSubscribeFilter, type TriggerRequest, type TriggerResponse, ValidationError, createDurablyHandler };