@lostgradient/weft 0.24.1 → 0.24.2

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.
Files changed (97) hide show
  1. package/README.md +1 -1
  2. package/dist/core/engine/bulk-operations-purge.d.ts +1 -1
  3. package/dist/core/engine/bulk-operations-purge.js +3 -2
  4. package/dist/core/engine/bulk-operations-retry.d.ts +16 -1
  5. package/dist/core/engine/bulk-operations-retry.js +19 -6
  6. package/dist/core/engine/bulk-operations.d.ts +3 -2
  7. package/dist/core/engine/bulk-operations.js +2 -2
  8. package/dist/core/engine/callback-creators-bundles.js +1 -1
  9. package/dist/core/engine/callback-creators-schedule.js +2 -2
  10. package/dist/core/engine/child-workflow.d.ts +13 -1
  11. package/dist/core/engine/child-workflow.js +22 -4
  12. package/dist/core/engine/generation-codec.d.ts +22 -0
  13. package/dist/core/engine/generation-codec.js +2 -0
  14. package/dist/core/engine/index.js +1 -1
  15. package/dist/core/engine/lifecycle/recovery-isolation.d.ts +20 -0
  16. package/dist/core/engine/lifecycle/recovery-isolation.js +26 -0
  17. package/dist/core/engine/lifecycle/resume-body.d.ts +44 -0
  18. package/dist/core/engine/lifecycle/resume-body.js +211 -0
  19. package/dist/core/engine/lifecycle/resume.d.ts +46 -3
  20. package/dist/core/engine/lifecycle/resume.js +21 -210
  21. package/dist/core/engine/lifecycle/standalone-claim-acquire.d.ts +68 -2
  22. package/dist/core/engine/lifecycle/standalone-claim-acquire.js +14 -4
  23. package/dist/core/engine/lifecycle/start-commit.d.ts +2 -0
  24. package/dist/core/engine/lifecycle/start-commit.js +16 -8
  25. package/dist/core/engine/lifecycle/start-or-signal-resolution.d.ts +8 -2
  26. package/dist/core/engine/lifecycle/start-or-signal-resolution.js +11 -3
  27. package/dist/core/engine/lifecycle/start-precondition-attribution.d.ts +10 -4
  28. package/dist/core/engine/lifecycle/start-schedule-timing.d.ts +11 -0
  29. package/dist/core/engine/lifecycle/start-schedule-timing.js +21 -0
  30. package/dist/core/engine/lifecycle/start-terminal-conflict-purge.d.ts +90 -11
  31. package/dist/core/engine/lifecycle/start-terminal-conflict-purge.js +24 -5
  32. package/dist/core/engine/lifecycle/start.d.ts +40 -3
  33. package/dist/core/engine/lifecycle/start.js +19 -26
  34. package/dist/core/engine/lifecycle/transition.d.ts +9 -0
  35. package/dist/core/engine/lifecycle/transition.js +20 -25
  36. package/dist/core/engine/lifecycle.d.ts +2 -1
  37. package/dist/core/engine/lifecycle.js +2 -1
  38. package/dist/core/engine/schedule-overlap.js +2 -1
  39. package/dist/core/engine/schedule-run.d.ts +10 -0
  40. package/dist/core/engine/schedule-run.js +1 -1
  41. package/dist/core/engine/schedules.d.ts +11 -2
  42. package/dist/core/engine/termination/complete.js +1 -1
  43. package/dist/core/engine/termination/suspend.js +3 -0
  44. package/dist/core/engine/validation/schedule.d.ts +25 -1
  45. package/dist/core/engine/validation/schedule.js +4 -10
  46. package/dist/core/engine/validation.js +10 -17
  47. package/dist/core/engine/workflow-claim-reclaim-target.js +6 -6
  48. package/dist/core/engine/workflow-claim-registry.d.ts +79 -75
  49. package/dist/core/engine/workflow-claim-registry.js +15 -2
  50. package/dist/core/engine/workflow-generation-fence.d.ts +74 -0
  51. package/dist/core/engine/workflow-generation-fence.js +19 -0
  52. package/dist/core/start-workflow-validation.d.ts +15 -0
  53. package/dist/core/start-workflow-validation.js +11 -1
  54. package/dist/core/workflow-identifiers.d.ts +37 -0
  55. package/dist/core/workflow-identifiers.js +19 -1
  56. package/dist/http.js +2 -2
  57. package/dist/indexeddb.js +1 -1
  58. package/dist/server/fleet-event-feed.js +6 -6
  59. package/dist/server/rest-binding.d.ts +11 -0
  60. package/dist/server/runtime/task-dispatch-envelope.d.ts +32 -5
  61. package/dist/server/runtime/task-dispatch-envelope.js +23 -1
  62. package/dist/server/runtime/task-dispatch.d.ts +3 -1
  63. package/dist/server/runtime/task-dispatch.js +9 -8
  64. package/dist/server/task-ledger-codec.d.ts +19 -0
  65. package/dist/server/task-ledger-codec.js +3 -0
  66. package/dist/server/task-ledger.d.ts +1 -1
  67. package/dist/server/task-ledger.js +1 -0
  68. package/dist/storage/bun-sql.js +132 -99
  69. package/dist/storage/compressed-storage.js +1 -1
  70. package/dist/storage/generation-keys.d.ts +52 -0
  71. package/dist/storage/generation-keys.js +4 -0
  72. package/dist/storage/index.d.ts +76 -65
  73. package/dist/storage/interface.d.ts +24 -232
  74. package/dist/storage/interface.js +1 -1
  75. package/dist/storage/key-prefixes.d.ts +1 -1
  76. package/dist/storage/key-prefixes.js +1 -0
  77. package/dist/storage/lease-keys.d.ts +48 -0
  78. package/dist/storage/lease-keys.js +8 -0
  79. package/dist/storage/lmdb.js +1 -1
  80. package/dist/storage/memory.js +1 -1
  81. package/dist/storage/neon.js +3 -3
  82. package/dist/storage/node-sqlite.js +132 -99
  83. package/dist/storage/postgres.js +3 -3
  84. package/dist/storage/resolve.js +1 -1
  85. package/dist/storage/scoped-storage.js +1 -1
  86. package/dist/storage/signal-keys.d.ts +23 -0
  87. package/dist/storage/signal-keys.js +9 -0
  88. package/dist/storage/testing.js +1 -1
  89. package/dist/storage/turso.js +2 -2
  90. package/dist/storage/workflow-lifecycle-keys.d.ts +128 -0
  91. package/dist/storage/workflow-lifecycle-keys.js +46 -0
  92. package/dist/storage/workflow-record-keys.d.ts +98 -0
  93. package/dist/storage/workflow-record-keys.js +47 -0
  94. package/dist/version.d.ts +1 -1
  95. package/dist/version.js +1 -1
  96. package/dist/web-extension.js +1 -1
  97. package/package.json +1 -1
@@ -1,5 +1,14 @@
1
1
  import { type StorageCapabilities } from './capabilities.ts';
2
+ import { WORKFLOW_CATALOG_KEYS } from './catalog-keys.ts';
2
3
  import type { DeleteRangeOptions } from './delete-range.ts';
4
+ import { GENERATION_KEYS } from './generation-keys.ts';
5
+ import { LEASE_KEYS } from './lease-keys.ts';
6
+ import { MAILBOX_KEYS } from './mailbox-keys.ts';
7
+ import { OUTBOX_KEYS } from './outbox-keys.ts';
8
+ import { OWNERSHIP_CLAIM_KEYS } from './ownership-keys.ts';
9
+ import { SIGNAL_KEYS } from './signal-keys.ts';
10
+ import { WORKFLOW_LIFECYCLE_KEYS_CORE, WORKFLOW_LIFECYCLE_KEYS_EXTENDED } from './workflow-lifecycle-keys.ts';
11
+ import { WORKFLOW_RECORD_KEYS_CORE, WORKFLOW_RECORD_KEYS_EXTENDED } from './workflow-record-keys.ts';
3
12
  export { assertDurableStorageForRecovery, requireStorageCapability } from './capabilities.ts';
4
13
  export type { GatedStorageCapabilityKey, StorageCapabilities } from './capabilities.ts';
5
14
  export { DEFAULT_SCOPE } from './default-scope.ts';
@@ -303,11 +312,20 @@ export { decodeStorageKeyComponent, encodeStorageKeyComponent, formatSortableSto
303
312
  * Key layout constants for hierarchical key encoding. Timestamps are
304
313
  * zero-padded to 16 digits for lexicographic ordering.
305
314
  *
306
- * This registry grows as storage features are added, which is why this file
307
- * carries a `max-lines` override in `.oxlintrc.json` above the repository
308
- * default of 500. Extracting `KEYS` into its own module and dropping the
309
- * override is tracked in WFT-90. Prefer adding new key families as a separate
310
- * module spread into `KEYS` (see `ownership-keys.ts`) over growing this file.
315
+ * The registry itself is assembled from feature-specific modules `KEYS` is
316
+ * the spread merge of the workflow record, lifecycle, signal, lease, mailbox,
317
+ * outbox, ownership, and catalog key modules so this file stays under the
318
+ * repository's default 500-line ceiling (WFT-90). Prefer adding a new key
319
+ * family as its own module spread into `KEYS` (see `ownership-keys.ts`) over
320
+ * growing this file directly.
321
+ *
322
+ * `KEYS` is typed as an explicit intersection of each source module's own
323
+ * `typeof` type rather than left to plain spread inference: TypeScript's
324
+ * declaration emit does not propagate per-member JSDoc through an inferred
325
+ * spread type, so hovering `KEYS.scheduleRunLink` would otherwise lose the
326
+ * documentation on `scheduleRunLink` itself. The intersection keeps each
327
+ * module's per-member docs as the single source of truth while still
328
+ * surfacing them through `KEYS`.
311
329
  *
312
330
  * @example
313
331
  * ```ts
@@ -315,230 +333,4 @@ export { decodeStorageKeyComponent, encodeStorageKeyComponent, formatSortableSto
315
333
  * KEYS.workflow('workflow-id');
316
334
  * ```
317
335
  */
318
- export declare const KEYS: {
319
- readonly budget: (namespace: string, period: string, date: string) => string;
320
- readonly review: (workflowId: string, reviewId: string) => string;
321
- readonly workflowHeaders: (workflowId: string) => string;
322
- readonly childCancellationPrefix: (workflowId: string) => string;
323
- readonly childCancellation: (workflowId: string, childWorkflowId: string) => string;
324
- readonly childWorkflowByParentPrefix: (parentWorkflowId: string, parentWorkflowExecutionToken?: string) => string;
325
- readonly childWorkflowByParent: (parentWorkflowId: string, parentWorkflowExecutionToken: string | undefined, childWorkflowId: string) => string;
326
- readonly terminalCleanupNeeded: (workflowId: string) => string;
327
- readonly workflowConcurrency: (workflowType: string, partitionKey: string) => string;
328
- readonly workflowConcurrencyHolder: (workflowId: string) => string;
329
- /**
330
- * Presence-only marker written at start only when a run is launched with a
331
- * non-serialized `services` value (see `start-batch.ts`). It lets a
332
- * fresh-process recovery tell a run whose services were lost on crash apart
333
- * from one that never had any — the services value itself is never persisted,
334
- * so this bit is the only durable trace. Cleared on terminal cleanup.
335
- */
336
- readonly workflowHasServices: (workflowId: string) => string;
337
- /**
338
- * Last-write-wins payload that `ctx.setFinalizerState(value)` records for a
339
- * workflow's definition-level `finalizer` activity (issue #446). Staged as a
340
- * pending atomic side-effect so it commits with the next checkpoint or the
341
- * terminal batch, and swept on terminal cleanup.
342
- *
343
- * **Current behavior (this release): recorded only.** Nothing reads this value
344
- * yet. **Planned behavior (future release):** the engine will pass the decoded
345
- * value as the finalizer's input when driving teardown after a
346
- * `cancelled`/`timed-out` terminal, where presence means "a resource was
347
- * recorded" and absence means the finalizer is skipped.
348
- */
349
- readonly finalizerState: (workflowId: string) => string;
350
- /**
351
- * Durable execution-claim + attempt marker for a workflow that owes a finalizer
352
- * run after a `cancelled`/`timed-out` terminal (issue #446 Phase 2). Mirrors the
353
- * `wf-cleanup-needed:` lifecycle. The value is the encoded claim record
354
- * `{ status: 'owed' | 'running'; attempts: number; token: string; claimedAt?: number }`:
355
- * the engine fenced-CAS's `owed → running` (stamping `claimedAt`) before invoking the
356
- * finalizer, and settle-CAS's the exact `running` bytes it wrote when clearing or
357
- * rescheduling. Liveness is decided purely by TIME: a `running` claim is reclaimable
358
- * once `claimedAt` is older than the finalizer's per-attempt timeout plus a margin
359
- * (see `teardownStaleThresholdMs`), so crash recovery is an ordinary stale-claim retry
360
- * driven by the timer that survived the terminal batch — there is no in-memory liveness
361
- * set and no epoch in the record. The cost is that a finalizer running past the stale
362
- * threshold may be re-driven concurrently, which is why workflow finalizers must be
363
- * idempotent. Present while teardown is outstanding; deleted by the finalizer on
364
- * success or when it dead-letters, which is what unblocks purge.
365
- */
366
- readonly teardownOwed: (workflowId: string) => string;
367
- /** Durable successful finalizer outcome, retained until workflow purge or retention. */
368
- readonly teardownSucceeded: (workflowId: string) => string;
369
- /**
370
- * Durable audit record written when a workflow's finalizer permanently fails — the
371
- * retry horizon is reached, or the recorded resource state vanished so the finalizer
372
- * can never run (issue #446 Phase 2). Holds the `TeardownDeadLetterRecord` shape
373
- * `{ type, lastError, attempts, deadLetteredAt, workflowExecutionToken?, finalizerInput? }`.
374
- * **Excluded from the workflow purge delete-set** so it survives as the operator's
375
- * evidence of a leaked external resource and remains queryable through the durable
376
- * finalizer-status API after purge.
377
- */
378
- readonly teardownDeadLetter: (workflowId: string) => string;
379
- readonly offload: (workflowId: string, key: string) => string;
380
- readonly archive: (workflowId: string, key: string) => string;
381
- readonly stateExecution: (ownerWorkflowId: string, key: string) => string;
382
- readonly stateWorkflow: (workflowType: string, key: string) => string;
383
- readonly streamChunkPrefix: (workflowId: string, key: string) => string;
384
- readonly streamChunk: (workflowId: string, key: string, chunkIndex: number) => string;
385
- readonly streamTail: (workflowId: string, key: string) => string;
386
- readonly streamMetadata: (workflowId: string, key: string) => string;
387
- readonly budgetCharged: (operationId: string) => string;
388
- readonly toolEffect: (workflowId: string, agentId: string, semanticHash: string) => string;
389
- readonly workflowVisibilityStatus: (status: string, workflowId: string) => string;
390
- readonly workflowVisibilityType: (type: string, workflowId: string) => string;
391
- readonly workflowVisibilityCreated: (createdAt: number, workflowId: string) => string;
392
- readonly workflowVisibilityUpdated: (updatedAt: number, workflowId: string) => string;
393
- readonly workflowVisibilityDeadline: (deadline: number, workflowId: string) => string;
394
- readonly workflowVisibilityManifest: (workflowId: string) => string;
395
- readonly workflowVisibilityMetaVersion: () => string;
396
- readonly workflowVisibilityMetaBuiltAt: () => string;
397
- readonly workflowVisibilityMetaCursor: () => string;
398
- readonly catalogEntry: (name: string, revision: string) => string;
399
- readonly catalogEntryPrefix: (name: string) => string;
400
- readonly catalogActive: (name: string) => string;
401
- readonly catalogTombstone: (name: string, revision: string) => string;
402
- readonly catalogTombstonePrefix: () => string;
403
- readonly workflowOwnerEpoch: (workflowId: string) => string;
404
- readonly workflowOwnerHolder: (workflowId: string) => string;
405
- readonly ownershipModeMarker: () => string;
406
- readonly applicationOutbox: (namespace: string, ownerId: string) => string;
407
- readonly applicationOutboxSinkProbe: (namespace: string, ownerId: string, nonce: string) => string;
408
- readonly applicationDeliveryPrefix: (namespace: string, ownerId: string) => string;
409
- readonly applicationDelivery: (namespace: string, ownerId: string, deliveryId: string) => string;
410
- readonly applicationDeliveryDuePrefix: (namespace: string, ownerId: string) => string;
411
- readonly applicationDeliveryDue: (namespace: string, ownerId: string, availableAt: number, deliveryId: string) => string;
412
- readonly applicationDeliveryIdempotency: (namespace: string, ownerId: string, key: string) => string;
413
- readonly applicationDeliveryBySequencePrefix: (namespace: string, ownerId: string) => string;
414
- readonly applicationDeliveryBySequence: (namespace: string, ownerId: string, sequence: number) => string;
415
- readonly applicationDeliveryTerminalPrefix: (namespace: string, ownerId: string) => string;
416
- readonly applicationDeliveryTerminal: (namespace: string, ownerId: string, terminalAt: number, deliveryId: string) => string;
417
- readonly applicationMailbox: (namespace: string, resourceId: string) => string;
418
- readonly applicationMailboxSinkProbe: (namespace: string, resourceId: string, nonce: string) => string;
419
- readonly applicationCommandPrefix: (namespace: string, resourceId: string) => string;
420
- readonly applicationCommand: (namespace: string, resourceId: string, commandId: string) => string;
421
- readonly applicationCommandReadyPrefix: (namespace: string, resourceId: string) => string;
422
- readonly applicationCommandReady: (namespace: string, resourceId: string, sequence: number) => string;
423
- readonly applicationCommandIdempotency: (namespace: string, resourceId: string, key: string) => string;
424
- readonly applicationCommandBySequencePrefix: (namespace: string, resourceId: string) => string;
425
- readonly applicationCommandBySequence: (namespace: string, resourceId: string, sequence: number) => string;
426
- readonly applicationCommandTerminalPrefix: (namespace: string, resourceId: string) => string;
427
- readonly applicationCommandTerminal: (namespace: string, resourceId: string, terminalAt: number, commandId: string) => string;
428
- readonly workflow: (id: string) => string;
429
- readonly checkpoint: (id: string) => string;
430
- readonly checkpointHistory: (id: string, step: number) => string;
431
- readonly timelinePrefix: (id: string) => string;
432
- readonly timeline: (id: string, step: number) => string;
433
- readonly schedule: (id: string) => string;
434
- readonly scheduleTick: (fireAt: number, id: string) => string;
435
- readonly scheduleRun: (workflowId: string) => string;
436
- /**
437
- * Durable per-workflow manifest for the schedule that launched a run. Unlike
438
- * `scheduleRun`, this link survives terminal cleanup so schedule history can
439
- * be queried until the workflow itself is purged.
440
- */
441
- readonly scheduleRunLink: (workflowId: string) => string;
442
- readonly scheduleRunBySchedulePrefix: (scheduleId: string) => string;
443
- readonly scheduleRunBySchedule: (scheduleId: string, workflowId: string) => string;
444
- readonly operation: (queue: string, scheduledAt: number, id: string) => string;
445
- readonly operationInflight: (id: string) => string;
446
- readonly operationQueued: (id: string) => string;
447
- readonly operationResolved: (id: string) => string;
448
- readonly bulkOperationAuditPrefix: () => string;
449
- readonly bulkOperationAudit: (timestamp: number, requestId: string, confirmationToken: string) => string;
450
- readonly operationResolvedByTimePrefix: () => string;
451
- readonly operationResolvedByTime: (resolvedAt: number, id: string) => string;
452
- readonly asyncActivity: (workflowId: string, token: string) => string;
453
- readonly asyncActivityResolution: (workflowId: string, token: string) => string;
454
- readonly activityReconciliationPrefix: (workflowId: string) => string;
455
- readonly activityReconciliation: (workflowId: string, activityName: string, idempotencyKeyDigest: string) => string;
456
- readonly eventPrefix: (workflowId: string) => string;
457
- readonly event: (workflowId: string, sequence: number) => string;
458
- readonly eventHead: (workflowId: string) => string;
459
- readonly eventWatermark: (workflowId: string) => string;
460
- readonly fleetEventPrefix: () => string;
461
- readonly fleetEvent: (sequence: number) => string;
462
- readonly fleetEventTail: () => string;
463
- readonly fleetEventWatermark: () => string;
464
- readonly fleetEventByWorkflowPrefix: (workflowId: string) => string;
465
- readonly fleetEventByWorkflow: (workflowId: string, sequence: number) => string;
466
- readonly signal: (workflowId: string, name: string, id: string) => string;
467
- readonly startSignal: (workflowId: string, name: string, id: string) => string;
468
- readonly signalSequence: (workflowId: string) => string;
469
- readonly signalAcceptedResponsePrefix: (workflowId: string) => string;
470
- readonly signalAcceptedResponse: (workflowId: string, name: string, signalId: string) => string;
471
- readonly deadline: (deadline: number, workflowId: string) => string;
472
- readonly terminalCleanup: (fireAt: number, timerId: string) => string;
473
- /**
474
- * Durable timer that drives a workflow's finalizer after a `cancelled`/`timed-out`
475
- * terminal (issue #446 Phase 2). Sortable by `fireAt` and scanned by its own
476
- * source (`wf-teardown:`) so it dispatches as the `teardown` timer kind rather
477
- * than `terminal-cleanup`. Re-armed with exponential backoff on a failed finalizer
478
- * attempt; the scheduler deletes the fired entry after the drive returns without
479
- * throwing, so a backoff reschedule is a write of a new entry at the later `fireAt`.
480
- */
481
- readonly teardownTimer: (fireAt: number, timerId: string) => string;
482
- readonly delayedStart: (startAt: number, workflowId: string) => string;
483
- readonly terminalWorkflowPrefix: () => string;
484
- readonly terminalWorkflow: (updatedAt: number, workflowId: string) => string;
485
- readonly attribute: (workflowId: string) => string;
486
- readonly attributeIndex: (attributeName: string, encodedValue: string, workflowId: string) => string;
487
- readonly tagIndex: (tag: string, workflowId: string) => string;
488
- readonly updatePrefix: (workflowId: string) => string;
489
- readonly update: (workflowId: string, updateId: string) => string;
490
- readonly updateResponse: (updateId: string) => string;
491
- readonly updateIdempotency: (workflowId: string, key: string) => string;
492
- /**
493
- * Maps a start `idempotencyKey` to the workflow id created for it. Written
494
- * atomically with the workflow record under a `conditionalBatch` gated on this
495
- * key being absent, so concurrent same-key starts converge on one workflow.
496
- * Unlike `updateIdempotency`, it is keyed by the idempotency key alone (no
497
- * workflow id) because the workflow id is the value it resolves to. It is
498
- * intentionally NOT swept on terminal cleanup: it must outlive the run so a
499
- * post-completion `startOrSignal` sees a terminal workflow (and conflicts)
500
- * rather than missing the mapping and creating a fresh run.
501
- */
502
- readonly startIdempotency: (key: string) => string;
503
- /**
504
- * The convergence signal id that `startOrSignal` derives from an idempotency
505
- * key so independent same-key callers deliver ONE signal. Deliberately uses the
506
- * RAW key (not `encodeStorageKeyComponent`): unlike `startIdempotency` this is a
507
- * signal id, not a storage key, and `validateSignalId` is character-agnostic, so
508
- * the raw key is always a valid id as long as it fits the byte cap (enforced as
509
- * ≤117 bytes so `"start-idem:"` + key stays within the 128-byte signal-id
510
- * ceiling). The two derivations are independent namespaces; both are individually
511
- * correct, so the raw-vs-encoded difference is harmless.
512
- */
513
- readonly startIdempotencySignalId: (key: string) => string;
514
- /** Scan prefix for engine liveness heartbeats (best-effort second-instance detection). */
515
- readonly livenessPrefix: () => string;
516
- /** Per-engine liveness heartbeat key. One key per engine instance under the shared store. */
517
- readonly liveness: (instanceId: string) => string;
518
- /**
519
- * Scan/match prefix for the lease-fenced single-writer ownership keys
520
- * ({@link KEYS.leaseEpoch} and {@link KEYS.leaseHolder}). Reserved so a
521
- * caller can recognize lease-owned keys; the lease itself uses the two exact
522
- * keys below, not a scan.
523
- */
524
- readonly leasePrefix: () => string;
525
- /**
526
- * The fencing epoch for lease-fenced ownership. A single shared key (one lease
527
- * per durable store) holding an 8-byte big-endian uint64. It changes ONLY on
528
- * ownership transfer (initial acquire or a steal after expiry), never on a
529
- * renewal — so a holder's cached epoch stays stable across heartbeats and can
530
- * be used unchanged as a `conditionalBatch` fencing condition. Kept separate
531
- * from {@link KEYS.leaseHolder} precisely because `conditionalBatch` compares
532
- * the whole stored value as bytes: folding the churning holder fields into the
533
- * fencing token would make every renewal invalidate the fence.
534
- */
535
- readonly leaseEpoch: () => string;
536
- /**
537
- * The current lease holder record for lease-fenced ownership. A single shared
538
- * key (one lease per durable store) holding a JSON `{ holderId, expiresAt,
539
- * epoch }`. Renewed every heartbeat tick (the `expiresAt` field advances), so
540
- * its bytes churn and it must NOT be used as the fencing token — see
541
- * {@link KEYS.leaseEpoch}.
542
- */
543
- readonly leaseHolder: () => string;
544
- };
336
+ export declare const KEYS: typeof WORKFLOW_RECORD_KEYS_CORE & typeof SIGNAL_KEYS & typeof WORKFLOW_LIFECYCLE_KEYS_CORE & typeof WORKFLOW_RECORD_KEYS_EXTENDED & typeof LEASE_KEYS & typeof MAILBOX_KEYS & typeof OUTBOX_KEYS & typeof OWNERSHIP_CLAIM_KEYS & typeof WORKFLOW_CATALOG_KEYS & typeof GENERATION_KEYS & typeof WORKFLOW_LIFECYCLE_KEYS_EXTENDED;
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- var E=import.meta.require;function l(e,t,n){if(!e.capabilities()[t])throw Error(`Feature "${n}" requires storage capability "${t}", but this storage backend does not provide it.`)}function x(e){let t=e.capabilities(),n=[];if(t.persistence!=="local"&&t.persistence!=="remote")n.push(`persistence must be "local" or "remote" (got "${t.persistence}")`);if(t.readAfterWrite!=="linearizable")n.push(`readAfterWrite must be "linearizable" (got "${t.readAfterWrite}")`);if(t.scanConsistency!=="snapshot")n.push(`scanConsistency must be "snapshot" (got "${t.scanConsistency}")`);if(!t.atomicBatch)n.push("atomicBatch must be true");if(!t.conditionalBatch)n.push("conditionalBatch must be true");if(n.length>0)throw Error(`Storage is not durable enough for recovery: ${n.join("; ")}.`)}function r(e){return encodeURIComponent(e)}function C(e){return decodeURIComponent(e)}function P(e){try{return decodeURIComponent(e)}catch{return null}}function o(e){return String(e).padStart(16,"0")}var d={catalogEntry:(e,t)=>`catalog-entry:${r(e)}:${r(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${r(e)}:`,catalogActive:(e)=>`catalog-active:${r(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${r(e)}:${r(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};var g="default";async function u(e,t){return await e.get(t)!==null}async function*s(e,t,n){for await(let[i]of e.scan(t,n))yield i}async function f(e,t){let n=0;for await(let i of s(e,t))n++;return n}async function m(e,t){let n=[];for await(let i of s(e,t))n.push({type:"delete",key:i});if(n.length===0)return 0;return await e.batch(n),n.length}async function I(e,t,n){let i=[];for await(let v of s(e,t,n))i.push({type:"delete",key:v});if(i.length===0)return 0;return await e.batch(i),i.length}var y={applicationMailbox:(e,t)=>`appmbx:v1:${r(e)}:${r(t)}`,applicationMailboxSinkProbe:(e,t,n)=>`appprobe:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${r(e)}:${r(t)}:`,applicationCommand:(e,t,n)=>`appcmd:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${r(e)}:${r(t)}:`,applicationCommandReady:(e,t,n)=>`appready:v1:${r(e)}:${r(t)}:${o(n)}`,applicationCommandIdempotency:(e,t,n)=>`appidem:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${r(e)}:${r(t)}:`,applicationCommandBySequence:(e,t,n)=>`appseq:v1:${r(e)}:${r(t)}:${o(n)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${r(e)}:${r(t)}:`,applicationCommandTerminal:(e,t,n,i)=>`appterm:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`};var b={applicationOutbox:(e,t)=>`appobx:v1:${r(e)}:${r(t)}`,applicationOutboxSinkProbe:(e,t,n)=>`appprobe:v1:outbox:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${r(e)}:${r(t)}:`,applicationDelivery:(e,t,n)=>`appdlv:v1:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${r(e)}:${r(t)}:`,applicationDeliveryDue:(e,t,n,i)=>`appdue:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`,applicationDeliveryIdempotency:(e,t,n)=>`appdidem:v1:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${r(e)}:${r(t)}:`,applicationDeliveryBySequence:(e,t,n)=>`appdseq:v1:${r(e)}:${r(t)}:${o(n)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${r(e)}:${r(t)}:`,applicationDeliveryTerminal:(e,t,n,i)=>`appdterm:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`};var h={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${r(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${r(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var k=["actrec:","appcmd:","appdidem:","appdlv:","appdseq:","appdterm:","appdue:","appidem:","appmbx:","appobx:","appprobe:","appready:","appseq:","appterm:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","catalog-active:","catalog-entry:","catalog-tombstone:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","fleet-event-watermark","idx:","lease:","liveness:","offload:","ownership-mode-marker","op:","review:","schedule:","schedule-due:","schedule-run-by-schedule:","schedule-run-link:","schedule-run:","sig:","sigres:","sigseq:","start-idem:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-concurrency:","wf-concurrency-holder:","wf-deadline:","wf-delayed:","wf-finalizer-state:","wf-has-services:","wf-headers:","wf-idx-","wf-owner-epoch:","wf-owner-holder:","wf-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var c=1e4,Z=1e4;class S extends Error{code="StorageBatchOperationLimitExceededError";cap=c;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${c}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function p(e,t){if(t>c)throw new S(e,t)}function ee(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"\xFF"}function te(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function re(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}async function ne(e,t){if(e.has)return e.has(t);return u(e,t)}function ie(e,t,n){if(e.keys)return e.keys(t,n);return s(e,t,n)}async function oe(e,t){if(e.count)return e.count(t);return f(e,t)}async function ae(e,t){if(e.deletePrefix)return e.deletePrefix(t);return m(e,t)}async function se(e,t){p("batch operations",t.length),await e.batch(t)}async function le(e,t,n){if(p("conditionalBatch conditions",t.length),p("conditionalBatch operations",n.length),l(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,n)}var a=o,O="0",B="1",w=(e,t,n,i)=>`sig:${r(e)}:${r(t)}:${i}:${r(n)}`,ge={workflow:(e)=>`wf:${r(e)}`,checkpoint:(e)=>`wf:${r(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${r(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${r(e)}:timeline:`,timeline:(e,t)=>`wf:${r(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${r(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${r(t)}`,scheduleRun:(e)=>`schedule-run:${r(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${r(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${r(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${r(e)}:${r(t)}`,operation:(e,t,n)=>`op:${e}:${a(t)}:${n}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,n)=>`audit:bulk:${a(e)}:${r(t)}:${r(n)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${a(e)}:${r(t)}`,asyncActivity:(e,t)=>`async-act:v1:${r(e)}:${r(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${r(e)}:${r(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${r(e)}:`,activityReconciliation:(e,t,n)=>`actrec:v1:${r(e)}:${r(t)}:${n}`,eventPrefix:(e)=>`ev:${r(e)}:`,event:(e,t)=>`ev:${r(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${r(e)}:head`,eventWatermark:(e)=>`ev:${r(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${r(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${r(e)}:${String(t).padStart(10,"0")}`,signal:(e,t,n)=>w(e,t,n,B),startSignal:(e,t,n)=>w(e,t,n,O),signalSequence:(e)=>`sigseq:v1:${r(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${r(e)}:`,signalAcceptedResponse:(e,t,n)=>`sigres:v1:${r(e)}:${r(t)}:${r(n)}`,deadline:(e,t)=>`wf-deadline:${a(e)}:${r(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${a(e)}:${r(t)}`,teardownTimer:(e,t)=>`wf-teardown:${a(e)}:${r(t)}`,delayedStart:(e,t)=>`wf-delayed:${a(e)}:${r(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${a(e)}:${r(t)}`,attribute:(e)=>`attr:${r(e)}`,attributeIndex:(e,t,n)=>`idx:${e}:${t}:${r(n)}`,tagIndex:(e,t)=>`tag:${r(e)}:${r(t)}`,updatePrefix:(e)=>`upd:${r(e)}:`,update:(e,t)=>`upd:${r(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${r(e)}:${t}`,startIdempotency:(e)=>`start-idem:${r(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`,livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${r(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",...y,...b,...h,...d,budget:(e,t,n)=>`budget:${e}:${t}:${n}`,review:(e,t)=>`review:${r(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${r(e)}`,childCancellationPrefix:(e)=>`child-cancel:${r(e)}:`,childCancellation:(e,t)=>`child-cancel:${r(e)}:${r(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${r(e)}:${t===void 0?"":`${r(t)}:`}`,childWorkflowByParent:(e,t,n)=>`child-by-parent:${r(e)}:${t===void 0?"":`${r(t)}:`}${r(n)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${r(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${r(e)}:${r(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${r(e)}`,workflowHasServices:(e)=>`wf-has-services:${r(e)}`,finalizerState:(e)=>`wf-finalizer-state:${r(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${r(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${r(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${r(e)}`,offload:(e,t)=>`offload:${r(e)}:${t}`,archive:(e,t)=>`archive:${r(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${r(e)}:${r(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${g}:${r(e)}:${r(t)}`,streamChunkPrefix:(e,t)=>`blob:${r(e)}:${t}:chunk:`,streamChunk:(e,t,n)=>`blob:${r(e)}:${t}:chunk:${String(n).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${r(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${r(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,n)=>`tool-effect:${r(e)}:${t}:${n}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${r(e)}:${r(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${r(e)}:${r(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${a(e)}:${r(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${a(e)}:${r(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${a(e)}:${r(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${r(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};export{g as DEFAULT_SCOPE,ge as KEYS,c as MAX_BATCH_OPERATIONS,Z as MAX_SCAN_LIMIT,S as StorageBatchOperationLimitExceededError,k as WEFT_RESERVED_KEY_PREFIXES,x as assertDurableStorageForRecovery,p as assertStorageBatchOperationCount,C as decodeStorageKeyComponent,r as encodeStorageKeyComponent,o as formatSortableStorageTimestamp,te as matchesScanOptions,l as requireStorageCapability,ee as resolvePrefixRangeEnd,se as storageBatch,le as storageConditionalBatch,oe as storageCount,ae as storageDeletePrefix,ne as storageHas,ie as storageKeys,re as storageValuesEqual,P as tryDecodeStorageKeyComponent};
2
+ var W=import.meta.require;function g(e,t,n){if(!e.capabilities()[t])throw Error(`Feature "${n}" requires storage capability "${t}", but this storage backend does not provide it.`)}function k(e){let t=e.capabilities(),n=[];if(t.persistence!=="local"&&t.persistence!=="remote")n.push(`persistence must be "local" or "remote" (got "${t.persistence}")`);if(t.readAfterWrite!=="linearizable")n.push(`readAfterWrite must be "linearizable" (got "${t.readAfterWrite}")`);if(t.scanConsistency!=="snapshot")n.push(`scanConsistency must be "snapshot" (got "${t.scanConsistency}")`);if(!t.atomicBatch)n.push("atomicBatch must be true");if(!t.conditionalBatch)n.push("conditionalBatch must be true");if(n.length>0)throw Error(`Storage is not durable enough for recovery: ${n.join("; ")}.`)}function r(e){return encodeURIComponent(e)}function A(e){return decodeURIComponent(e)}function L(e){try{return decodeURIComponent(e)}catch{return null}}function o(e){return String(e).padStart(16,"0")}var f={catalogEntry:(e,t)=>`catalog-entry:${r(e)}:${r(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${r(e)}:`,catalogActive:(e)=>`catalog-active:${r(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${r(e)}:${r(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};async function m(e,t){return await e.get(t)!==null}async function*s(e,t,n){for await(let[i]of e.scan(t,n))yield i}async function u(e,t){let n=0;for await(let i of s(e,t))n++;return n}async function y(e,t){let n=[];for await(let i of s(e,t))n.push({type:"delete",key:i});if(n.length===0)return 0;return await e.batch(n),n.length}async function M(e,t,n){let i=[];for await(let P of s(e,t,n))i.push({type:"delete",key:P});if(i.length===0)return 0;return await e.batch(i),i.length}var S={workflowGeneration:(e)=>`wf-gen:${r(e)}`};var b={livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${r(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder"};var h={applicationMailbox:(e,t)=>`appmbx:v1:${r(e)}:${r(t)}`,applicationMailboxSinkProbe:(e,t,n)=>`appprobe:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${r(e)}:${r(t)}:`,applicationCommand:(e,t,n)=>`appcmd:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${r(e)}:${r(t)}:`,applicationCommandReady:(e,t,n)=>`appready:v1:${r(e)}:${r(t)}:${o(n)}`,applicationCommandIdempotency:(e,t,n)=>`appidem:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${r(e)}:${r(t)}:`,applicationCommandBySequence:(e,t,n)=>`appseq:v1:${r(e)}:${r(t)}:${o(n)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${r(e)}:${r(t)}:`,applicationCommandTerminal:(e,t,n,i)=>`appterm:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`};var w={applicationOutbox:(e,t)=>`appobx:v1:${r(e)}:${r(t)}`,applicationOutboxSinkProbe:(e,t,n)=>`appprobe:v1:outbox:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${r(e)}:${r(t)}:`,applicationDelivery:(e,t,n)=>`appdlv:v1:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${r(e)}:${r(t)}:`,applicationDeliveryDue:(e,t,n,i)=>`appdue:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`,applicationDeliveryIdempotency:(e,t,n)=>`appdidem:v1:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${r(e)}:${r(t)}:`,applicationDeliveryBySequence:(e,t,n)=>`appdseq:v1:${r(e)}:${r(t)}:${o(n)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${r(e)}:${r(t)}:`,applicationDeliveryTerminal:(e,t,n,i)=>`appdterm:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`};var E={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${r(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${r(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var B="0",T="1",x=(e,t,n,i)=>`sig:${r(e)}:${r(t)}:${i}:${r(n)}`,C={signal:(e,t,n)=>x(e,t,n,T),startSignal:(e,t,n)=>x(e,t,n,B),signalSequence:(e)=>`sigseq:v1:${r(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${r(e)}:`,signalAcceptedResponse:(e,t,n)=>`sigres:v1:${r(e)}:${r(t)}:${r(n)}`};var c="default";var a=o,v={deadline:(e,t)=>`wf-deadline:${a(e)}:${r(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${a(e)}:${r(t)}`,teardownTimer:(e,t)=>`wf-teardown:${a(e)}:${r(t)}`,delayedStart:(e,t)=>`wf-delayed:${a(e)}:${r(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${a(e)}:${r(t)}`},O={budget:(e,t,n)=>`budget:${e}:${t}:${n}`,review:(e,t)=>`review:${r(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${r(e)}`,childCancellationPrefix:(e)=>`child-cancel:${r(e)}:`,childCancellation:(e,t)=>`child-cancel:${r(e)}:${r(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${r(e)}:${t===void 0?"":`${r(t)}:`}`,childWorkflowByParent:(e,t,n)=>`child-by-parent:${r(e)}:${t===void 0?"":`${r(t)}:`}${r(n)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${r(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${r(e)}:${r(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${r(e)}`,workflowHasServices:(e)=>`wf-has-services:${r(e)}`,finalizerState:(e)=>`wf-finalizer-state:${r(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${r(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${r(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${r(e)}`,offload:(e,t)=>`offload:${r(e)}:${t}`,archive:(e,t)=>`archive:${r(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${r(e)}:${r(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${c}:${r(e)}:${r(t)}`,streamChunkPrefix:(e,t)=>`blob:${r(e)}:${t}:chunk:`,streamChunk:(e,t,n)=>`blob:${r(e)}:${t}:chunk:${String(n).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${r(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${r(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,n)=>`tool-effect:${r(e)}:${t}:${n}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${r(e)}:${r(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${r(e)}:${r(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${a(e)}:${r(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${a(e)}:${r(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${a(e)}:${r(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${r(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};var l=o,_={workflow:(e)=>`wf:${r(e)}`,checkpoint:(e)=>`wf:${r(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${r(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${r(e)}:timeline:`,timeline:(e,t)=>`wf:${r(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${r(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${r(t)}`,scheduleRun:(e)=>`schedule-run:${r(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${r(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${r(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${r(e)}:${r(t)}`,operation:(e,t,n)=>`op:${e}:${l(t)}:${n}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,n)=>`audit:bulk:${l(e)}:${r(t)}:${r(n)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${l(e)}:${r(t)}`,asyncActivity:(e,t)=>`async-act:v1:${r(e)}:${r(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${r(e)}:${r(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${r(e)}:`,activityReconciliation:(e,t,n)=>`actrec:v1:${r(e)}:${r(t)}:${n}`,eventPrefix:(e)=>`ev:${r(e)}:`,event:(e,t)=>`ev:${r(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${r(e)}:head`,eventWatermark:(e)=>`ev:${r(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${r(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${r(e)}:${String(t).padStart(10,"0")}`},R={attribute:(e)=>`attr:${r(e)}`,attributeIndex:(e,t,n)=>`idx:${e}:${t}:${r(n)}`,tagIndex:(e,t)=>`tag:${r(e)}:${r(t)}`,updatePrefix:(e)=>`upd:${r(e)}:`,update:(e,t)=>`upd:${r(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${r(e)}:${t}`,startIdempotency:(e)=>`start-idem:${r(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`};var D=["actrec:","appcmd:","appdidem:","appdlv:","appdseq:","appdterm:","appdue:","appidem:","appmbx:","appobx:","appprobe:","appready:","appseq:","appterm:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","catalog-active:","catalog-entry:","catalog-tombstone:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","fleet-event-watermark","idx:","lease:","liveness:","offload:","ownership-mode-marker","op:","review:","schedule:","schedule-due:","schedule-run-by-schedule:","schedule-run-link:","schedule-run:","sig:","sigres:","sigseq:","start-idem:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-concurrency:","wf-concurrency-holder:","wf-deadline:","wf-delayed:","wf-finalizer-state:","wf-gen:","wf-has-services:","wf-headers:","wf-idx-","wf-owner-epoch:","wf-owner-holder:","wf-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var p=1e4,we=1e4;class K extends Error{code="StorageBatchOperationLimitExceededError";cap=p;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${p}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function d(e,t){if(t>p)throw new K(e,t)}function Ee(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"\xFF"}function xe(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function Ce(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}async function ve(e,t){if(e.has)return e.has(t);return m(e,t)}function Oe(e,t,n){if(e.keys)return e.keys(t,n);return s(e,t,n)}async function _e(e,t){if(e.count)return e.count(t);return u(e,t)}async function Re(e,t){if(e.deletePrefix)return e.deletePrefix(t);return y(e,t)}async function Ke(e,t){d("batch operations",t.length),await e.batch(t)}async function Pe(e,t,n){if(d("conditionalBatch conditions",t.length),d("conditionalBatch operations",n.length),g(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,n)}var ke={..._,...C,...v,...R,...b,...h,...w,...E,...f,...S,...O};export{c as DEFAULT_SCOPE,ke as KEYS,p as MAX_BATCH_OPERATIONS,we as MAX_SCAN_LIMIT,K as StorageBatchOperationLimitExceededError,D as WEFT_RESERVED_KEY_PREFIXES,k as assertDurableStorageForRecovery,d as assertStorageBatchOperationCount,A as decodeStorageKeyComponent,r as encodeStorageKeyComponent,o as formatSortableStorageTimestamp,xe as matchesScanOptions,g as requireStorageCapability,Ee as resolvePrefixRangeEnd,Ke as storageBatch,Pe as storageConditionalBatch,_e as storageCount,Re as storageDeletePrefix,ve as storageHas,Oe as storageKeys,Ce as storageValuesEqual,L as tryDecodeStorageKeyComponent};
@@ -16,4 +16,4 @@
16
16
  * console.log(isWeftKey); // true
17
17
  * ```
18
18
  */
19
- export declare const WEFT_RESERVED_KEY_PREFIXES: readonly ["actrec:", "appcmd:", "appdidem:", "appdlv:", "appdseq:", "appdterm:", "appdue:", "appidem:", "appmbx:", "appobx:", "appprobe:", "appready:", "appseq:", "appterm:", "archive:", "async-act:", "attr:", "audit:bulk:", "blob:", "budget:", "budget-charged:", "catalog-active:", "catalog-entry:", "catalog-tombstone:", "child-by-parent:", "ev:", "fleet-event-by-workflow:", "fleet-event:", "fleet-event-tail", "fleet-event-watermark", "idx:", "lease:", "liveness:", "offload:", "ownership-mode-marker", "op:", "review:", "schedule:", "schedule-due:", "schedule-run-by-schedule:", "schedule-run-link:", "schedule-run:", "sig:", "sigres:", "sigseq:", "start-idem:", "state:", "tag:", "tool-effect:", "upd:", "upk:", "upr:", "wf:", "wf-cleanup:", "wf-cleanup-needed:", "wf-concurrency:", "wf-concurrency-holder:", "wf-deadline:", "wf-delayed:", "wf-finalizer-state:", "wf-has-services:", "wf-headers:", "wf-idx-", "wf-owner-epoch:", "wf-owner-holder:", "wf-teardown:", "wf-teardown-deadletter:", "wf-teardown-needed:", "wf-teardown-succeeded:", "wf-terminal:"];
19
+ export declare const WEFT_RESERVED_KEY_PREFIXES: readonly ["actrec:", "appcmd:", "appdidem:", "appdlv:", "appdseq:", "appdterm:", "appdue:", "appidem:", "appmbx:", "appobx:", "appprobe:", "appready:", "appseq:", "appterm:", "archive:", "async-act:", "attr:", "audit:bulk:", "blob:", "budget:", "budget-charged:", "catalog-active:", "catalog-entry:", "catalog-tombstone:", "child-by-parent:", "ev:", "fleet-event-by-workflow:", "fleet-event:", "fleet-event-tail", "fleet-event-watermark", "idx:", "lease:", "liveness:", "offload:", "ownership-mode-marker", "op:", "review:", "schedule:", "schedule-due:", "schedule-run-by-schedule:", "schedule-run-link:", "schedule-run:", "sig:", "sigres:", "sigseq:", "start-idem:", "state:", "tag:", "tool-effect:", "upd:", "upk:", "upr:", "wf:", "wf-cleanup:", "wf-cleanup-needed:", "wf-concurrency:", "wf-concurrency-holder:", "wf-deadline:", "wf-delayed:", "wf-finalizer-state:", "wf-gen:", "wf-has-services:", "wf-headers:", "wf-idx-", "wf-owner-epoch:", "wf-owner-holder:", "wf-teardown:", "wf-teardown-deadletter:", "wf-teardown-needed:", "wf-teardown-succeeded:", "wf-terminal:"];
@@ -59,6 +59,7 @@ export const WEFT_RESERVED_KEY_PREFIXES = [
59
59
  "wf-deadline:",
60
60
  "wf-delayed:",
61
61
  "wf-finalizer-state:",
62
+ "wf-gen:",
62
63
  "wf-has-services:",
63
64
  "wf-headers:",
64
65
  "wf-idx-",
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Storage key builders for engine liveness heartbeats and the store-wide
3
+ * lease-fenced single-writer lock.
4
+ *
5
+ * These are spread into `KEYS` in `interface.ts` rather than declared there, so
6
+ * the liveness and lease keyspace can carry its full rationale without pushing
7
+ * that file's documented line ceiling. Callers still reach them through `KEYS`,
8
+ * which keeps one import contract for storage keys.
9
+ *
10
+ * @module storage/lease-keys
11
+ */
12
+ /**
13
+ * Engine liveness heartbeat keys plus the lease-fenced single-writer ownership
14
+ * keys (`ownership: 'lease'`).
15
+ *
16
+ * Spread into `KEYS`; not intended to be imported directly by engine code.
17
+ */
18
+ export declare const LEASE_KEYS: {
19
+ /** Scan prefix for engine liveness heartbeats (best-effort second-instance detection). */
20
+ readonly livenessPrefix: () => string;
21
+ /** Per-engine liveness heartbeat key. One key per engine instance under the shared store. */
22
+ readonly liveness: (instanceId: string) => string;
23
+ /**
24
+ * Scan/match prefix for the lease-fenced single-writer ownership keys
25
+ * (`leaseEpoch` and `leaseHolder`). Reserved so a caller can recognize
26
+ * lease-owned keys; the lease itself uses the two exact keys below, not a scan.
27
+ */
28
+ readonly leasePrefix: () => string;
29
+ /**
30
+ * The fencing epoch for lease-fenced ownership. A single shared key (one lease
31
+ * per durable store) holding an 8-byte big-endian uint64. It changes ONLY on
32
+ * ownership transfer (initial acquire or a steal after expiry), never on a
33
+ * renewal — so a holder's cached epoch stays stable across heartbeats and can
34
+ * be used unchanged as a `conditionalBatch` fencing condition. Kept separate
35
+ * from `leaseHolder` precisely because `conditionalBatch` compares the whole
36
+ * stored value as bytes: folding the churning holder fields into the fencing
37
+ * token would make every renewal invalidate the fence.
38
+ */
39
+ readonly leaseEpoch: () => string;
40
+ /**
41
+ * The current lease holder record for lease-fenced ownership. A single shared
42
+ * key (one lease per durable store) holding a JSON `{ holderId, expiresAt,
43
+ * epoch }`. Renewed every heartbeat tick (the `expiresAt` field advances), so
44
+ * its bytes churn and it must NOT be used as the fencing token — see
45
+ * `leaseEpoch`.
46
+ */
47
+ readonly leaseHolder: () => string;
48
+ };
@@ -0,0 +1,8 @@
1
+ import { encodeStorageKeyComponent } from "./key-encoding.js";
2
+ export const LEASE_KEYS = {
3
+ livenessPrefix: () => "liveness:",
4
+ liveness: (instanceId) => `liveness:${encodeStorageKeyComponent(instanceId)}`,
5
+ leasePrefix: () => "lease:",
6
+ leaseEpoch: () => "lease:epoch",
7
+ leaseHolder: () => "lease:holder"
8
+ };
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- var Q=import.meta.require;function y(e,t,r){if(!e.capabilities()[t])throw Error(`Feature "${r}" requires storage capability "${t}", but this storage backend does not provide it.`)}function V(e){let t=e.capabilities(),r=[];if(t.persistence!=="local"&&t.persistence!=="remote")r.push(`persistence must be "local" or "remote" (got "${t.persistence}")`);if(t.readAfterWrite!=="linearizable")r.push(`readAfterWrite must be "linearizable" (got "${t.readAfterWrite}")`);if(t.scanConsistency!=="snapshot")r.push(`scanConsistency must be "snapshot" (got "${t.scanConsistency}")`);if(!t.atomicBatch)r.push("atomicBatch must be true");if(!t.conditionalBatch)r.push("conditionalBatch must be true");if(r.length>0)throw Error(`Storage is not durable enough for recovery: ${r.join("; ")}.`)}function n(e){return encodeURIComponent(e)}function N(e){return decodeURIComponent(e)}function H(e){try{return decodeURIComponent(e)}catch{return null}}function a(e){return String(e).padStart(16,"0")}var x={catalogEntry:(e,t)=>`catalog-entry:${n(e)}:${n(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${n(e)}:`,catalogActive:(e)=>`catalog-active:${n(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${n(e)}:${n(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};var h="default";async function O(e,t){return await e.get(t)!==null}async function*u(e,t,r){for await(let[i]of e.scan(t,r))yield i}async function k(e,t){let r=0;for await(let i of u(e,t))r++;return r}async function B(e,t){let r=[];for await(let i of u(e,t))r.push({type:"delete",key:i});if(r.length===0)return 0;return await e.batch(r),r.length}async function P(e,t,r){let i=[];for await(let o of u(e,t,r))i.push({type:"delete",key:o});if(i.length===0)return 0;return await e.batch(i),i.length}var C={applicationMailbox:(e,t)=>`appmbx:v1:${n(e)}:${n(t)}`,applicationMailboxSinkProbe:(e,t,r)=>`appprobe:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${n(e)}:${n(t)}:`,applicationCommand:(e,t,r)=>`appcmd:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${n(e)}:${n(t)}:`,applicationCommandReady:(e,t,r)=>`appready:v1:${n(e)}:${n(t)}:${a(r)}`,applicationCommandIdempotency:(e,t,r)=>`appidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${n(e)}:${n(t)}:`,applicationCommandBySequence:(e,t,r)=>`appseq:v1:${n(e)}:${n(t)}:${a(r)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${n(e)}:${n(t)}:`,applicationCommandTerminal:(e,t,r,i)=>`appterm:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`};var R={applicationOutbox:(e,t)=>`appobx:v1:${n(e)}:${n(t)}`,applicationOutboxSinkProbe:(e,t,r)=>`appprobe:v1:outbox:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${n(e)}:${n(t)}:`,applicationDelivery:(e,t,r)=>`appdlv:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${n(e)}:${n(t)}:`,applicationDeliveryDue:(e,t,r,i)=>`appdue:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`,applicationDeliveryIdempotency:(e,t,r)=>`appdidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${n(e)}:${n(t)}:`,applicationDeliveryBySequence:(e,t,r)=>`appdseq:v1:${n(e)}:${n(t)}:${a(r)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${n(e)}:${n(t)}:`,applicationDeliveryTerminal:(e,t,r,i)=>`appdterm:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`};var D={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${n(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${n(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var F=["actrec:","appcmd:","appdidem:","appdlv:","appdseq:","appdterm:","appdue:","appidem:","appmbx:","appobx:","appprobe:","appready:","appseq:","appterm:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","catalog-active:","catalog-entry:","catalog-tombstone:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","fleet-event-watermark","idx:","lease:","liveness:","offload:","ownership-mode-marker","op:","review:","schedule:","schedule-due:","schedule-run-by-schedule:","schedule-run-link:","schedule-run:","sig:","sigres:","sigseq:","start-idem:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-concurrency:","wf-concurrency-holder:","wf-deadline:","wf-delayed:","wf-finalizer-state:","wf-has-services:","wf-headers:","wf-idx-","wf-owner-epoch:","wf-owner-holder:","wf-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var b=1e4,we=1e4;class E extends Error{code="StorageBatchOperationLimitExceededError";cap=b;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${b}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function g(e,t){if(t>b)throw new E(e,t)}function m(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"\xFF"}function S(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function L(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}async function T(e,t){if(e.has)return e.has(t);return O(e,t)}function I(e,t,r){if(e.keys)return e.keys(t,r);return u(e,t,r)}async function K(e,t){if(e.count)return e.count(t);return k(e,t)}async function _(e,t){if(e.deletePrefix)return e.deletePrefix(t);return B(e,t)}async function ve(e,t){g("batch operations",t.length),await e.batch(t)}async function M(e,t,r){if(g("conditionalBatch conditions",t.length),g("conditionalBatch operations",r.length),y(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,r)}var s=a,Y="0",X="1",A=(e,t,r,i)=>`sig:${n(e)}:${n(t)}:${i}:${n(r)}`,xe={workflow:(e)=>`wf:${n(e)}`,checkpoint:(e)=>`wf:${n(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${n(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${n(e)}:timeline:`,timeline:(e,t)=>`wf:${n(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${n(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${n(t)}`,scheduleRun:(e)=>`schedule-run:${n(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${n(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${n(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${n(e)}:${n(t)}`,operation:(e,t,r)=>`op:${e}:${s(t)}:${r}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,r)=>`audit:bulk:${s(e)}:${n(t)}:${n(r)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${s(e)}:${n(t)}`,asyncActivity:(e,t)=>`async-act:v1:${n(e)}:${n(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${n(e)}:${n(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${n(e)}:`,activityReconciliation:(e,t,r)=>`actrec:v1:${n(e)}:${n(t)}:${r}`,eventPrefix:(e)=>`ev:${n(e)}:`,event:(e,t)=>`ev:${n(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${n(e)}:head`,eventWatermark:(e)=>`ev:${n(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${n(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${n(e)}:${String(t).padStart(10,"0")}`,signal:(e,t,r)=>A(e,t,r,X),startSignal:(e,t,r)=>A(e,t,r,Y),signalSequence:(e)=>`sigseq:v1:${n(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${n(e)}:`,signalAcceptedResponse:(e,t,r)=>`sigres:v1:${n(e)}:${n(t)}:${n(r)}`,deadline:(e,t)=>`wf-deadline:${s(e)}:${n(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${s(e)}:${n(t)}`,teardownTimer:(e,t)=>`wf-teardown:${s(e)}:${n(t)}`,delayedStart:(e,t)=>`wf-delayed:${s(e)}:${n(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${s(e)}:${n(t)}`,attribute:(e)=>`attr:${n(e)}`,attributeIndex:(e,t,r)=>`idx:${e}:${t}:${n(r)}`,tagIndex:(e,t)=>`tag:${n(e)}:${n(t)}`,updatePrefix:(e)=>`upd:${n(e)}:`,update:(e,t)=>`upd:${n(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${n(e)}:${t}`,startIdempotency:(e)=>`start-idem:${n(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`,livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${n(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",...C,...R,...D,...x,budget:(e,t,r)=>`budget:${e}:${t}:${r}`,review:(e,t)=>`review:${n(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${n(e)}`,childCancellationPrefix:(e)=>`child-cancel:${n(e)}:`,childCancellation:(e,t)=>`child-cancel:${n(e)}:${n(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}`,childWorkflowByParent:(e,t,r)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}${n(r)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${n(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${n(e)}:${n(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${n(e)}`,workflowHasServices:(e)=>`wf-has-services:${n(e)}`,finalizerState:(e)=>`wf-finalizer-state:${n(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${n(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${n(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${n(e)}`,offload:(e,t)=>`offload:${n(e)}:${t}`,archive:(e,t)=>`archive:${n(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${n(e)}:${n(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${h}:${n(e)}:${n(t)}`,streamChunkPrefix:(e,t)=>`blob:${n(e)}:${t}:chunk:`,streamChunk:(e,t,r)=>`blob:${n(e)}:${t}:chunk:${String(r).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${n(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${n(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,r)=>`tool-effect:${n(e)}:${t}:${r}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${n(e)}:${n(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${n(e)}:${n(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${s(e)}:${n(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${s(e)}:${n(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${s(e)}:${n(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${n(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function G(e){if(e===void 0)return;if(typeof e!=="number"||!Number.isInteger(e)||e<0)throw Error("deleteRange limit must be a finite non-negative integer");return e===0?0:e}function f(e){let t={},r=!1;for(let o of["gt","gte","lt","lte"]){let l=e[o];if(l===void 0)continue;if(typeof l!=="string")throw Error("deleteRange bounds must be strings");t[o]=l,r=!0}if(!r)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let i=G(e.limit);if(i!==void 0)t.limit=i;return t}async function U(e,t,r){let i=f(r);if(e.deleteRange)return e.deleteRange(t,i);return P(e,t,i)}function w(e){return e.replaceAll(/:+$/g,"")}function j(e,t){let r=w(e),i=w(t);if(r.length===0)return i;if(i.length===0)return r;return`${r}:${i}`}class v{#e;#r;constructor(e,t){this.#e=e,this.#r=w(t)}#t(e){if(this.#r.length===0)return e;return e.length===0?`${this.#r}:`:`${this.#r}:${e}`}#i(e){return e.map((t)=>{if(t.type==="put")return{type:"put",key:this.#t(t.key),value:t.value};return{type:"delete",key:this.#t(t.key)}})}#n(e){if(this.#r.length===0)return e;return e.slice(this.#r.length+1)}#o(e){let t={};if(e.limit!==void 0)t.limit=e.limit;if(e.gt!==void 0)t.gt=this.#t(e.gt);if(e.gte!==void 0)t.gte=this.#t(e.gte);if(e.lt!==void 0)t.lt=this.#t(e.lt);if(e.lte!==void 0)t.lte=this.#t(e.lte);return t}#a(e={}){let t=this.#o(e);if(e.reverse!==void 0)t.reverse=e.reverse;return t}#s(e){return this.#o(e)}capabilities(){return this.#e.capabilities()}scoped(e){return new v(this.#e,j(this.#r,e))}async get(e){return this.#e.get(this.#t(e))}async put(e,t){await this.#e.put(this.#t(e),t)}async delete(e){await this.#e.delete(this.#t(e))}async*scan(e,t){for await(let[r,i]of this.#e.scan(this.#t(e),this.#a(t)))yield[this.#n(r),i]}async batch(e){g("batch operations",e.length),await this.#e.batch(this.#i(e))}async conditionalBatch(e,t){return M(this.#e,e.map((r)=>({key:this.#t(r.key),expectedValue:r.expectedValue})),this.#i(t))}async has(e){return T(this.#e,this.#t(e))}async deletePrefix(e){return _(this.#e,this.#t(e))}async deleteRange(e,t){let r=this.#s(f(t));return U(this.#e,this.#t(e),r)}async*keys(e,t){for await(let r of I(this.#e,this.#t(e),this.#a(t)))yield this.#n(r)}async count(e){return K(this.#e,this.#t(e))}[Symbol.dispose](){this.#e[Symbol.dispose]()}}function z(e,t){return new v(e,t)}import*as q from"lmdb";class J{#e;#r;#t=!1;#i=null;constructor(e,t,r=q.open){let i=t?.durability??"full";if(i!=="full"&&i!=="relaxed")throw Error(`LMDBStorage durability must be "full" or "relaxed", received ${JSON.stringify(i)}.`);this.#r=i,this.#e=r({path:e,encoding:"binary",...i==="relaxed"?{noSync:!0,noMetaSync:!0}:{}})}#n(){if(this.#t)throw Error("LMDBStorage is closed")}capabilities(){return{persistence:this.#r==="relaxed"?"ephemeral":"local",readAfterWrite:"linearizable",scanConsistency:"snapshot",atomicBatch:!0,conditionalBatch:!0,boundedRangeDelete:!1}}async get(e){this.#n();let t=this.#e.get(e);if(t===void 0)return null;return new Uint8Array(t)}async put(e,t){this.#n(),await this.#e.put(e,Buffer.from(t))}async delete(e){this.#n(),await this.#e.remove(e)}async has(e){return this.#n(),this.#e.doesExist(e)}async deletePrefix(e){this.#n();let t=[];for await(let r of this.keys(e))t.push(r);if(t.length===0)return 0;return await this.#e.batch(()=>{for(let r of t)this.#e.remove(r)}),t.length}async deleteRange(e,t){this.#n();let r=f(t),i=[];for await(let o of this.keys(e,r))i.push(o);if(i.length===0)return 0;return await this.#e.batch(()=>{for(let o of i)this.#e.remove(o)}),i.length}async*scan(e,t={}){this.#n();let{limit:r,reverse:i}=t,o=m(e),l=i?this.#e.getRange({start:o,end:e,reverse:!0}):this.#e.getRange({start:e,end:o}),d=0,p=!1;for(let{key:c,value:W}of l){if(!c.startsWith(e)){if(i&&!p)continue;break}if(p=!0,!S(c,t))continue;if(r!==void 0&&d>=r)break;yield[c,new Uint8Array(W)],d++}}async*keys(e,t={}){this.#n();let{limit:r,reverse:i}=t,o=m(e),l=i?this.#e.getKeys({start:o,end:e,reverse:!0}):this.#e.getKeys({start:e,end:o}),d=0,p=!1;for(let c of l){if(!c.startsWith(e)){if(i&&!p)continue;break}if(p=!0,!S(c,t))continue;if(r!==void 0&&d>=r)break;yield c,d++}}async count(e){this.#n();let t=m(e);return this.#e.getKeysCount({start:e,end:t})}scoped(e){return this.#n(),z(this,e)}async batch(e){if(this.#n(),g("batch operations",e.length),e.length===0)return;await this.#e.batch(()=>{for(let t of e)if(t.type==="put")this.#e.put(t.key,Buffer.from(t.value));else this.#e.remove(t.key)})}async conditionalBatch(e,t){return this.#n(),g("conditionalBatch conditions",e.length),g("conditionalBatch operations",t.length),this.#e.transactionSync(()=>{for(let i of e){let o=this.#e.get(i.key),l=o===void 0?null:new Uint8Array(o);if(!L(l,i.expectedValue))return!1}for(let i of t)if(i.type==="put")this.#e.putSync(i.key,Buffer.from(i.value));else this.#e.removeSync(i.key);return!0})}close(){return this.#t=!0,this.#i??=(async()=>{await Promise.resolve(),await this.#e.close()})(),this.#i}[Symbol.dispose](){this.close()}}export{J as LMDBStorage};
2
+ var ae=import.meta.require;function y(e,t,r){if(!e.capabilities()[t])throw Error(`Feature "${r}" requires storage capability "${t}", but this storage backend does not provide it.`)}function J(e){let t=e.capabilities(),r=[];if(t.persistence!=="local"&&t.persistence!=="remote")r.push(`persistence must be "local" or "remote" (got "${t.persistence}")`);if(t.readAfterWrite!=="linearizable")r.push(`readAfterWrite must be "linearizable" (got "${t.readAfterWrite}")`);if(t.scanConsistency!=="snapshot")r.push(`scanConsistency must be "snapshot" (got "${t.scanConsistency}")`);if(!t.atomicBatch)r.push("atomicBatch must be true");if(!t.conditionalBatch)r.push("conditionalBatch must be true");if(r.length>0)throw Error(`Storage is not durable enough for recovery: ${r.join("; ")}.`)}function n(e){return encodeURIComponent(e)}function Q(e){return decodeURIComponent(e)}function Z(e){try{return decodeURIComponent(e)}catch{return null}}function a(e){return String(e).padStart(16,"0")}var E={catalogEntry:(e,t)=>`catalog-entry:${n(e)}:${n(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${n(e)}:`,catalogActive:(e)=>`catalog-active:${n(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${n(e)}:${n(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};async function x(e,t){return await e.get(t)!==null}async function*u(e,t,r){for await(let[i]of e.scan(t,r))yield i}async function R(e,t){let r=0;for await(let i of u(e,t))r++;return r}async function C(e,t){let r=[];for await(let i of u(e,t))r.push({type:"delete",key:i});if(r.length===0)return 0;return await e.batch(r),r.length}async function k(e,t,r){let i=[];for await(let o of u(e,t,r))i.push({type:"delete",key:o});if(i.length===0)return 0;return await e.batch(i),i.length}var B={workflowGeneration:(e)=>`wf-gen:${n(e)}`};var P={livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${n(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder"};var D={applicationMailbox:(e,t)=>`appmbx:v1:${n(e)}:${n(t)}`,applicationMailboxSinkProbe:(e,t,r)=>`appprobe:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${n(e)}:${n(t)}:`,applicationCommand:(e,t,r)=>`appcmd:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${n(e)}:${n(t)}:`,applicationCommandReady:(e,t,r)=>`appready:v1:${n(e)}:${n(t)}:${a(r)}`,applicationCommandIdempotency:(e,t,r)=>`appidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${n(e)}:${n(t)}:`,applicationCommandBySequence:(e,t,r)=>`appseq:v1:${n(e)}:${n(t)}:${a(r)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${n(e)}:${n(t)}:`,applicationCommandTerminal:(e,t,r,i)=>`appterm:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`};var _={applicationOutbox:(e,t)=>`appobx:v1:${n(e)}:${n(t)}`,applicationOutboxSinkProbe:(e,t,r)=>`appprobe:v1:outbox:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${n(e)}:${n(t)}:`,applicationDelivery:(e,t,r)=>`appdlv:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${n(e)}:${n(t)}:`,applicationDeliveryDue:(e,t,r,i)=>`appdue:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`,applicationDeliveryIdempotency:(e,t,r)=>`appdidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${n(e)}:${n(t)}:`,applicationDeliveryBySequence:(e,t,r)=>`appdseq:v1:${n(e)}:${n(t)}:${a(r)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${n(e)}:${n(t)}:`,applicationDeliveryTerminal:(e,t,r,i)=>`appdterm:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`};var A={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${n(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${n(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var ee="0",te="1",K=(e,t,r,i)=>`sig:${n(e)}:${n(t)}:${i}:${n(r)}`,L={signal:(e,t,r)=>K(e,t,r,te),startSignal:(e,t,r)=>K(e,t,r,ee),signalSequence:(e)=>`sigseq:v1:${n(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${n(e)}:`,signalAcceptedResponse:(e,t,r)=>`sigres:v1:${n(e)}:${n(t)}:${n(r)}`};var h="default";var g=a,T={deadline:(e,t)=>`wf-deadline:${g(e)}:${n(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${g(e)}:${n(t)}`,teardownTimer:(e,t)=>`wf-teardown:${g(e)}:${n(t)}`,delayedStart:(e,t)=>`wf-delayed:${g(e)}:${n(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${g(e)}:${n(t)}`},I={budget:(e,t,r)=>`budget:${e}:${t}:${r}`,review:(e,t)=>`review:${n(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${n(e)}`,childCancellationPrefix:(e)=>`child-cancel:${n(e)}:`,childCancellation:(e,t)=>`child-cancel:${n(e)}:${n(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}`,childWorkflowByParent:(e,t,r)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}${n(r)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${n(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${n(e)}:${n(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${n(e)}`,workflowHasServices:(e)=>`wf-has-services:${n(e)}`,finalizerState:(e)=>`wf-finalizer-state:${n(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${n(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${n(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${n(e)}`,offload:(e,t)=>`offload:${n(e)}:${t}`,archive:(e,t)=>`archive:${n(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${n(e)}:${n(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${h}:${n(e)}:${n(t)}`,streamChunkPrefix:(e,t)=>`blob:${n(e)}:${t}:chunk:`,streamChunk:(e,t,r)=>`blob:${n(e)}:${t}:chunk:${String(r).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${n(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${n(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,r)=>`tool-effect:${n(e)}:${t}:${r}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${n(e)}:${n(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${n(e)}:${n(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${g(e)}:${n(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${g(e)}:${n(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${g(e)}:${n(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${n(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};var b=a,W={workflow:(e)=>`wf:${n(e)}`,checkpoint:(e)=>`wf:${n(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${n(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${n(e)}:timeline:`,timeline:(e,t)=>`wf:${n(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${n(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${n(t)}`,scheduleRun:(e)=>`schedule-run:${n(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${n(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${n(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${n(e)}:${n(t)}`,operation:(e,t,r)=>`op:${e}:${b(t)}:${r}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,r)=>`audit:bulk:${b(e)}:${n(t)}:${n(r)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${b(e)}:${n(t)}`,asyncActivity:(e,t)=>`async-act:v1:${n(e)}:${n(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${n(e)}:${n(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${n(e)}:`,activityReconciliation:(e,t,r)=>`actrec:v1:${n(e)}:${n(t)}:${r}`,eventPrefix:(e)=>`ev:${n(e)}:`,event:(e,t)=>`ev:${n(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${n(e)}:head`,eventWatermark:(e)=>`ev:${n(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${n(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${n(e)}:${String(t).padStart(10,"0")}`},Y={attribute:(e)=>`attr:${n(e)}`,attributeIndex:(e,t,r)=>`idx:${e}:${t}:${n(r)}`,tagIndex:(e,t)=>`tag:${n(e)}:${n(t)}`,updatePrefix:(e)=>`upd:${n(e)}:`,update:(e,t)=>`upd:${n(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${n(e)}:${t}`,startIdempotency:(e)=>`start-idem:${n(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`};var ne=["actrec:","appcmd:","appdidem:","appdlv:","appdseq:","appdterm:","appdue:","appidem:","appmbx:","appobx:","appprobe:","appready:","appseq:","appterm:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","catalog-active:","catalog-entry:","catalog-tombstone:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","fleet-event-watermark","idx:","lease:","liveness:","offload:","ownership-mode-marker","op:","review:","schedule:","schedule-due:","schedule-run-by-schedule:","schedule-run-link:","schedule-run:","sig:","sigres:","sigseq:","start-idem:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-concurrency:","wf-concurrency-holder:","wf-deadline:","wf-delayed:","wf-finalizer-state:","wf-gen:","wf-has-services:","wf-headers:","wf-idx-","wf-owner-epoch:","wf-owner-holder:","wf-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var S=1e4,Ue=1e4;class M extends Error{code="StorageBatchOperationLimitExceededError";cap=S;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${S}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function l(e,t){if(t>S)throw new M(e,t)}function m(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"\xFF"}function w(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function N(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}async function F(e,t){if(e.has)return e.has(t);return x(e,t)}function U(e,t,r){if(e.keys)return e.keys(t,r);return u(e,t,r)}async function z(e,t){if(e.count)return e.count(t);return R(e,t)}async function q(e,t){if(e.deletePrefix)return e.deletePrefix(t);return C(e,t)}async function ze(e,t){l("batch operations",t.length),await e.batch(t)}async function V(e,t,r){if(l("conditionalBatch conditions",t.length),l("conditionalBatch operations",r.length),y(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,r)}var qe={...W,...L,...T,...Y,...P,...D,..._,...A,...E,...B,...I};function re(e){if(e===void 0)return;if(typeof e!=="number"||!Number.isInteger(e)||e<0)throw Error("deleteRange limit must be a finite non-negative integer");return e===0?0:e}function f(e){let t={},r=!1;for(let o of["gt","gte","lt","lte"]){let s=e[o];if(s===void 0)continue;if(typeof s!=="string")throw Error("deleteRange bounds must be strings");t[o]=s,r=!0}if(!r)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let i=re(e.limit);if(i!==void 0)t.limit=i;return t}async function X(e,t,r){let i=f(r);if(e.deleteRange)return e.deleteRange(t,i);return k(e,t,i)}function O(e){return e.replaceAll(/:+$/g,"")}function ie(e,t){let r=O(e),i=O(t);if(r.length===0)return i;if(i.length===0)return r;return`${r}:${i}`}class v{#e;#r;constructor(e,t){this.#e=e,this.#r=O(t)}#t(e){if(this.#r.length===0)return e;return e.length===0?`${this.#r}:`:`${this.#r}:${e}`}#i(e){return e.map((t)=>{if(t.type==="put")return{type:"put",key:this.#t(t.key),value:t.value};return{type:"delete",key:this.#t(t.key)}})}#n(e){if(this.#r.length===0)return e;return e.slice(this.#r.length+1)}#o(e){let t={};if(e.limit!==void 0)t.limit=e.limit;if(e.gt!==void 0)t.gt=this.#t(e.gt);if(e.gte!==void 0)t.gte=this.#t(e.gte);if(e.lt!==void 0)t.lt=this.#t(e.lt);if(e.lte!==void 0)t.lte=this.#t(e.lte);return t}#a(e={}){let t=this.#o(e);if(e.reverse!==void 0)t.reverse=e.reverse;return t}#s(e){return this.#o(e)}capabilities(){return this.#e.capabilities()}scoped(e){return new v(this.#e,ie(this.#r,e))}async get(e){return this.#e.get(this.#t(e))}async put(e,t){await this.#e.put(this.#t(e),t)}async delete(e){await this.#e.delete(this.#t(e))}async*scan(e,t){for await(let[r,i]of this.#e.scan(this.#t(e),this.#a(t)))yield[this.#n(r),i]}async batch(e){l("batch operations",e.length),await this.#e.batch(this.#i(e))}async conditionalBatch(e,t){return V(this.#e,e.map((r)=>({key:this.#t(r.key),expectedValue:r.expectedValue})),this.#i(t))}async has(e){return F(this.#e,this.#t(e))}async deletePrefix(e){return q(this.#e,this.#t(e))}async deleteRange(e,t){let r=this.#s(f(t));return X(this.#e,this.#t(e),r)}async*keys(e,t){for await(let r of U(this.#e,this.#t(e),this.#a(t)))yield this.#n(r)}async count(e){return z(this.#e,this.#t(e))}[Symbol.dispose](){this.#e[Symbol.dispose]()}}function H(e,t){return new v(e,t)}import*as G from"lmdb";class oe{#e;#r;#t=!1;#i=null;constructor(e,t,r=G.open){let i=t?.durability??"full";if(i!=="full"&&i!=="relaxed")throw Error(`LMDBStorage durability must be "full" or "relaxed", received ${JSON.stringify(i)}.`);this.#r=i,this.#e=r({path:e,encoding:"binary",...i==="relaxed"?{noSync:!0,noMetaSync:!0}:{}})}#n(){if(this.#t)throw Error("LMDBStorage is closed")}capabilities(){return{persistence:this.#r==="relaxed"?"ephemeral":"local",readAfterWrite:"linearizable",scanConsistency:"snapshot",atomicBatch:!0,conditionalBatch:!0,boundedRangeDelete:!1}}async get(e){this.#n();let t=this.#e.get(e);if(t===void 0)return null;return new Uint8Array(t)}async put(e,t){this.#n(),await this.#e.put(e,Buffer.from(t))}async delete(e){this.#n(),await this.#e.remove(e)}async has(e){return this.#n(),this.#e.doesExist(e)}async deletePrefix(e){this.#n();let t=[];for await(let r of this.keys(e))t.push(r);if(t.length===0)return 0;return await this.#e.batch(()=>{for(let r of t)this.#e.remove(r)}),t.length}async deleteRange(e,t){this.#n();let r=f(t),i=[];for await(let o of this.keys(e,r))i.push(o);if(i.length===0)return 0;return await this.#e.batch(()=>{for(let o of i)this.#e.remove(o)}),i.length}async*scan(e,t={}){this.#n();let{limit:r,reverse:i}=t,o=m(e),s=i?this.#e.getRange({start:o,end:e,reverse:!0}):this.#e.getRange({start:e,end:o}),p=0,d=!1;for(let{key:c,value:j}of s){if(!c.startsWith(e)){if(i&&!d)continue;break}if(d=!0,!w(c,t))continue;if(r!==void 0&&p>=r)break;yield[c,new Uint8Array(j)],p++}}async*keys(e,t={}){this.#n();let{limit:r,reverse:i}=t,o=m(e),s=i?this.#e.getKeys({start:o,end:e,reverse:!0}):this.#e.getKeys({start:e,end:o}),p=0,d=!1;for(let c of s){if(!c.startsWith(e)){if(i&&!d)continue;break}if(d=!0,!w(c,t))continue;if(r!==void 0&&p>=r)break;yield c,p++}}async count(e){this.#n();let t=m(e);return this.#e.getKeysCount({start:e,end:t})}scoped(e){return this.#n(),H(this,e)}async batch(e){if(this.#n(),l("batch operations",e.length),e.length===0)return;await this.#e.batch(()=>{for(let t of e)if(t.type==="put")this.#e.put(t.key,Buffer.from(t.value));else this.#e.remove(t.key)})}async conditionalBatch(e,t){return this.#n(),l("conditionalBatch conditions",e.length),l("conditionalBatch operations",t.length),this.#e.transactionSync(()=>{for(let i of e){let o=this.#e.get(i.key),s=o===void 0?null:new Uint8Array(o);if(!N(s,i.expectedValue))return!1}for(let i of t)if(i.type==="put")this.#e.putSync(i.key,Buffer.from(i.value));else this.#e.removeSync(i.key);return!0})}close(){return this.#t=!0,this.#i??=(async()=>{await Promise.resolve(),await this.#e.close()})(),this.#i}[Symbol.dispose](){this.close()}}export{oe as LMDBStorage};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- var j=import.meta.require;function y(e,t,r){if(!e.capabilities()[t])throw Error(`Feature "${r}" requires storage capability "${t}", but this storage backend does not provide it.`)}function M(e){let t=e.capabilities(),r=[];if(t.persistence!=="local"&&t.persistence!=="remote")r.push(`persistence must be "local" or "remote" (got "${t.persistence}")`);if(t.readAfterWrite!=="linearizable")r.push(`readAfterWrite must be "linearizable" (got "${t.readAfterWrite}")`);if(t.scanConsistency!=="snapshot")r.push(`scanConsistency must be "snapshot" (got "${t.scanConsistency}")`);if(!t.atomicBatch)r.push("atomicBatch must be true");if(!t.conditionalBatch)r.push("conditionalBatch must be true");if(r.length>0)throw Error(`Storage is not durable enough for recovery: ${r.join("; ")}.`)}function n(e){return encodeURIComponent(e)}function W(e){return decodeURIComponent(e)}function V(e){try{return decodeURIComponent(e)}catch{return null}}function s(e){return String(e).padStart(16,"0")}var x={catalogEntry:(e,t)=>`catalog-entry:${n(e)}:${n(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${n(e)}:`,catalogActive:(e)=>`catalog-active:${n(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${n(e)}:${n(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};var h="default";async function O(e,t){return await e.get(t)!==null}async function*u(e,t,r){for await(let[i]of e.scan(t,r))yield i}async function k(e,t){let r=0;for await(let i of u(e,t))r++;return r}async function C(e,t){let r=[];for await(let i of u(e,t))r.push({type:"delete",key:i});if(r.length===0)return 0;return await e.batch(r),r.length}async function P(e,t,r){let i=[];for await(let a of u(e,t,r))i.push({type:"delete",key:a});if(i.length===0)return 0;return await e.batch(i),i.length}var R={applicationMailbox:(e,t)=>`appmbx:v1:${n(e)}:${n(t)}`,applicationMailboxSinkProbe:(e,t,r)=>`appprobe:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${n(e)}:${n(t)}:`,applicationCommand:(e,t,r)=>`appcmd:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${n(e)}:${n(t)}:`,applicationCommandReady:(e,t,r)=>`appready:v1:${n(e)}:${n(t)}:${s(r)}`,applicationCommandIdempotency:(e,t,r)=>`appidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${n(e)}:${n(t)}:`,applicationCommandBySequence:(e,t,r)=>`appseq:v1:${n(e)}:${n(t)}:${s(r)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${n(e)}:${n(t)}:`,applicationCommandTerminal:(e,t,r,i)=>`appterm:v1:${n(e)}:${n(t)}:${s(r)}:${n(i)}`};var B={applicationOutbox:(e,t)=>`appobx:v1:${n(e)}:${n(t)}`,applicationOutboxSinkProbe:(e,t,r)=>`appprobe:v1:outbox:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${n(e)}:${n(t)}:`,applicationDelivery:(e,t,r)=>`appdlv:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${n(e)}:${n(t)}:`,applicationDeliveryDue:(e,t,r,i)=>`appdue:v1:${n(e)}:${n(t)}:${s(r)}:${n(i)}`,applicationDeliveryIdempotency:(e,t,r)=>`appdidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${n(e)}:${n(t)}:`,applicationDeliveryBySequence:(e,t,r)=>`appdseq:v1:${n(e)}:${n(t)}:${s(r)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${n(e)}:${n(t)}:`,applicationDeliveryTerminal:(e,t,r,i)=>`appdterm:v1:${n(e)}:${n(t)}:${s(r)}:${n(i)}`};var D={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${n(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${n(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var N=["actrec:","appcmd:","appdidem:","appdlv:","appdseq:","appdterm:","appdue:","appidem:","appmbx:","appobx:","appprobe:","appready:","appseq:","appterm:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","catalog-active:","catalog-entry:","catalog-tombstone:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","fleet-event-watermark","idx:","lease:","liveness:","offload:","ownership-mode-marker","op:","review:","schedule:","schedule-due:","schedule-run-by-schedule:","schedule-run-link:","schedule-run:","sig:","sigres:","sigseq:","start-idem:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-concurrency:","wf-concurrency-holder:","wf-deadline:","wf-delayed:","wf-finalizer-state:","wf-has-services:","wf-headers:","wf-idx-","wf-owner-epoch:","wf-owner-holder:","wf-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var b=1e4,be=1e4;class E extends Error{code="StorageBatchOperationLimitExceededError";cap=b;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${b}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function c(e,t){if(t>b)throw new E(e,t)}function d(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"\xFF"}function m(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function T(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}async function I(e,t){if(e.has)return e.has(t);return O(e,t)}function _(e,t,r){if(e.keys)return e.keys(t,r);return u(e,t,r)}async function K(e,t){if(e.count)return e.count(t);return k(e,t)}async function L(e,t){if(e.deletePrefix)return e.deletePrefix(t);return C(e,t)}async function Se(e,t){c("batch operations",t.length),await e.batch(t)}async function z(e,t,r){if(c("conditionalBatch conditions",t.length),c("conditionalBatch operations",r.length),y(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,r)}var l=s,H="0",F="1",A=(e,t,r,i)=>`sig:${n(e)}:${n(t)}:${i}:${n(r)}`,we={workflow:(e)=>`wf:${n(e)}`,checkpoint:(e)=>`wf:${n(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${n(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${n(e)}:timeline:`,timeline:(e,t)=>`wf:${n(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${n(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${n(t)}`,scheduleRun:(e)=>`schedule-run:${n(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${n(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${n(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${n(e)}:${n(t)}`,operation:(e,t,r)=>`op:${e}:${l(t)}:${r}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,r)=>`audit:bulk:${l(e)}:${n(t)}:${n(r)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${l(e)}:${n(t)}`,asyncActivity:(e,t)=>`async-act:v1:${n(e)}:${n(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${n(e)}:${n(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${n(e)}:`,activityReconciliation:(e,t,r)=>`actrec:v1:${n(e)}:${n(t)}:${r}`,eventPrefix:(e)=>`ev:${n(e)}:`,event:(e,t)=>`ev:${n(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${n(e)}:head`,eventWatermark:(e)=>`ev:${n(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${n(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${n(e)}:${String(t).padStart(10,"0")}`,signal:(e,t,r)=>A(e,t,r,F),startSignal:(e,t,r)=>A(e,t,r,H),signalSequence:(e)=>`sigseq:v1:${n(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${n(e)}:`,signalAcceptedResponse:(e,t,r)=>`sigres:v1:${n(e)}:${n(t)}:${n(r)}`,deadline:(e,t)=>`wf-deadline:${l(e)}:${n(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${l(e)}:${n(t)}`,teardownTimer:(e,t)=>`wf-teardown:${l(e)}:${n(t)}`,delayedStart:(e,t)=>`wf-delayed:${l(e)}:${n(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${l(e)}:${n(t)}`,attribute:(e)=>`attr:${n(e)}`,attributeIndex:(e,t,r)=>`idx:${e}:${t}:${n(r)}`,tagIndex:(e,t)=>`tag:${n(e)}:${n(t)}`,updatePrefix:(e)=>`upd:${n(e)}:`,update:(e,t)=>`upd:${n(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${n(e)}:${t}`,startIdempotency:(e)=>`start-idem:${n(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`,livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${n(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",...R,...B,...D,...x,budget:(e,t,r)=>`budget:${e}:${t}:${r}`,review:(e,t)=>`review:${n(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${n(e)}`,childCancellationPrefix:(e)=>`child-cancel:${n(e)}:`,childCancellation:(e,t)=>`child-cancel:${n(e)}:${n(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}`,childWorkflowByParent:(e,t,r)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}${n(r)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${n(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${n(e)}:${n(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${n(e)}`,workflowHasServices:(e)=>`wf-has-services:${n(e)}`,finalizerState:(e)=>`wf-finalizer-state:${n(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${n(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${n(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${n(e)}`,offload:(e,t)=>`offload:${n(e)}:${t}`,archive:(e,t)=>`archive:${n(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${n(e)}:${n(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${h}:${n(e)}:${n(t)}`,streamChunkPrefix:(e,t)=>`blob:${n(e)}:${t}:chunk:`,streamChunk:(e,t,r)=>`blob:${n(e)}:${t}:chunk:${String(r).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${n(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${n(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,r)=>`tool-effect:${n(e)}:${t}:${r}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${n(e)}:${n(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${n(e)}:${n(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${l(e)}:${n(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${l(e)}:${n(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${l(e)}:${n(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${n(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function Y(e){if(e===void 0)return;if(typeof e!=="number"||!Number.isInteger(e)||e<0)throw Error("deleteRange limit must be a finite non-negative integer");return e===0?0:e}function f(e){let t={},r=!1;for(let a of["gt","gte","lt","lte"]){let o=e[a];if(o===void 0)continue;if(typeof o!=="string")throw Error("deleteRange bounds must be strings");t[a]=o,r=!0}if(!r)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let i=Y(e.limit);if(i!==void 0)t.limit=i;return t}async function U(e,t,r){let i=f(r);if(e.deleteRange)return e.deleteRange(t,i);return P(e,t,i)}function S(e){return e.replaceAll(/:+$/g,"")}function X(e,t){let r=S(e),i=S(t);if(r.length===0)return i;if(i.length===0)return r;return`${r}:${i}`}class w{#e;#n;constructor(e,t){this.#e=e,this.#n=S(t)}#t(e){if(this.#n.length===0)return e;return e.length===0?`${this.#n}:`:`${this.#n}:${e}`}#r(e){return e.map((t)=>{if(t.type==="put")return{type:"put",key:this.#t(t.key),value:t.value};return{type:"delete",key:this.#t(t.key)}})}#i(e){if(this.#n.length===0)return e;return e.slice(this.#n.length+1)}#o(e){let t={};if(e.limit!==void 0)t.limit=e.limit;if(e.gt!==void 0)t.gt=this.#t(e.gt);if(e.gte!==void 0)t.gte=this.#t(e.gte);if(e.lt!==void 0)t.lt=this.#t(e.lt);if(e.lte!==void 0)t.lte=this.#t(e.lte);return t}#a(e={}){let t=this.#o(e);if(e.reverse!==void 0)t.reverse=e.reverse;return t}#s(e){return this.#o(e)}capabilities(){return this.#e.capabilities()}scoped(e){return new w(this.#e,X(this.#n,e))}async get(e){return this.#e.get(this.#t(e))}async put(e,t){await this.#e.put(this.#t(e),t)}async delete(e){await this.#e.delete(this.#t(e))}async*scan(e,t){for await(let[r,i]of this.#e.scan(this.#t(e),this.#a(t)))yield[this.#i(r),i]}async batch(e){c("batch operations",e.length),await this.#e.batch(this.#r(e))}async conditionalBatch(e,t){return z(this.#e,e.map((r)=>({key:this.#t(r.key),expectedValue:r.expectedValue})),this.#r(t))}async has(e){return I(this.#e,this.#t(e))}async deletePrefix(e){return L(this.#e,this.#t(e))}async deleteRange(e,t){let r=this.#s(f(t));return U(this.#e,this.#t(e),r)}async*keys(e,t){for await(let r of _(this.#e,this.#t(e),this.#a(t)))yield this.#i(r)}async count(e){return K(this.#e,this.#t(e))}[Symbol.dispose](){this.#e[Symbol.dispose]()}}function q(e,t){return new w(e,t)}class G{#e;constructor(){this.#e=new Map}capabilities(){return{persistence:"ephemeral",readAfterWrite:"linearizable",scanConsistency:"snapshot",atomicBatch:!0,conditionalBatch:!0,boundedRangeDelete:!0}}#n(e,t,r){return e>=t&&e<r}#t(e,t){let r=[];for(let i of this.#e.keys())if(this.#n(i,e,t))r.push(i);return r.toSorted()}async get(e){return this.#e.get(e)??null}async put(e,t){this.#e.set(e,t)}async delete(e){this.#e.delete(e)}async*scan(e,t={}){let{limit:r,reverse:i}=t,a=d(e),o=this.#t(e,a);if(o=o.filter((p)=>m(p,t)),i)o.reverse();let g=0;for(let p of o){if(r!==void 0&&g>=r)break;let v=this.#e.get(p);if(v!==void 0)yield[p,v],g++}}async batch(e){c("batch operations",e.length),this.#r(e)}#r(e){for(let t of e)if(t.type==="put")this.#e.set(t.key,t.value);else this.#e.delete(t.key)}async conditionalBatch(e,t){c("conditionalBatch conditions",e.length),c("conditionalBatch operations",t.length);for(let r of e){let i=this.#e.get(r.key)??null;if(!T(i,r.expectedValue))return!1}return this.#r(t),!0}async has(e){return this.#e.has(e)}async deletePrefix(e){let t=d(e),r=this.#t(e,t);for(let i of r)this.#e.delete(i);return r.length}async deleteRange(e,t){let r=f(t),i=d(e),a=this.#t(e,i).filter((g)=>m(g,r)),o=r.limit===void 0?a:a.slice(0,r.limit);for(let g of o)this.#e.delete(g);return o.length}async*keys(e,t={}){let{limit:r,reverse:i}=t,a=d(e),o=this.#t(e,a);if(o=o.filter((p)=>m(p,t)),i)o.reverse();let g=0;for(let p of o){if(r!==void 0&&g>=r)break;yield p,g++}}async count(e){let t=d(e);return this.#t(e,t).length}scoped(e){return q(this,e)}get size(){return this.#e.size}clear(){this.#e.clear()}snapshot(){let e=new Map;for(let[t,r]of this.#e)e.set(t,new Uint8Array(r));return e}[Symbol.dispose](){this.#e.clear()}}export{G as MemoryStorage};
2
+ var ie=import.meta.require;function y(e,t,r){if(!e.capabilities()[t])throw Error(`Feature "${r}" requires storage capability "${t}", but this storage backend does not provide it.`)}function G(e){let t=e.capabilities(),r=[];if(t.persistence!=="local"&&t.persistence!=="remote")r.push(`persistence must be "local" or "remote" (got "${t.persistence}")`);if(t.readAfterWrite!=="linearizable")r.push(`readAfterWrite must be "linearizable" (got "${t.readAfterWrite}")`);if(t.scanConsistency!=="snapshot")r.push(`scanConsistency must be "snapshot" (got "${t.scanConsistency}")`);if(!t.atomicBatch)r.push("atomicBatch must be true");if(!t.conditionalBatch)r.push("conditionalBatch must be true");if(r.length>0)throw Error(`Storage is not durable enough for recovery: ${r.join("; ")}.`)}function n(e){return encodeURIComponent(e)}function j(e){return decodeURIComponent(e)}function Q(e){try{return decodeURIComponent(e)}catch{return null}}function a(e){return String(e).padStart(16,"0")}var v={catalogEntry:(e,t)=>`catalog-entry:${n(e)}:${n(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${n(e)}:`,catalogActive:(e)=>`catalog-active:${n(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${n(e)}:${n(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};async function x(e,t){return await e.get(t)!==null}async function*u(e,t,r){for await(let[i]of e.scan(t,r))yield i}async function C(e,t){let r=0;for await(let i of u(e,t))r++;return r}async function R(e,t){let r=[];for await(let i of u(e,t))r.push({type:"delete",key:i});if(r.length===0)return 0;return await e.batch(r),r.length}async function k(e,t,r){let i=[];for await(let s of u(e,t,r))i.push({type:"delete",key:s});if(i.length===0)return 0;return await e.batch(i),i.length}var P={workflowGeneration:(e)=>`wf-gen:${n(e)}`};var B={livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${n(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder"};var D={applicationMailbox:(e,t)=>`appmbx:v1:${n(e)}:${n(t)}`,applicationMailboxSinkProbe:(e,t,r)=>`appprobe:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${n(e)}:${n(t)}:`,applicationCommand:(e,t,r)=>`appcmd:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${n(e)}:${n(t)}:`,applicationCommandReady:(e,t,r)=>`appready:v1:${n(e)}:${n(t)}:${a(r)}`,applicationCommandIdempotency:(e,t,r)=>`appidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${n(e)}:${n(t)}:`,applicationCommandBySequence:(e,t,r)=>`appseq:v1:${n(e)}:${n(t)}:${a(r)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${n(e)}:${n(t)}:`,applicationCommandTerminal:(e,t,r,i)=>`appterm:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`};var _={applicationOutbox:(e,t)=>`appobx:v1:${n(e)}:${n(t)}`,applicationOutboxSinkProbe:(e,t,r)=>`appprobe:v1:outbox:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${n(e)}:${n(t)}:`,applicationDelivery:(e,t,r)=>`appdlv:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${n(e)}:${n(t)}:`,applicationDeliveryDue:(e,t,r,i)=>`appdue:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`,applicationDeliveryIdempotency:(e,t,r)=>`appdidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${n(e)}:${n(t)}:`,applicationDeliveryBySequence:(e,t,r)=>`appdseq:v1:${n(e)}:${n(t)}:${a(r)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${n(e)}:${n(t)}:`,applicationDeliveryTerminal:(e,t,r,i)=>`appdterm:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`};var A={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${n(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${n(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var J="0",Z="1",K=(e,t,r,i)=>`sig:${n(e)}:${n(t)}:${i}:${n(r)}`,L={signal:(e,t,r)=>K(e,t,r,Z),startSignal:(e,t,r)=>K(e,t,r,J),signalSequence:(e)=>`sigseq:v1:${n(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${n(e)}:`,signalAcceptedResponse:(e,t,r)=>`sigres:v1:${n(e)}:${n(t)}:${n(r)}`};var h="default";var p=a,I={deadline:(e,t)=>`wf-deadline:${p(e)}:${n(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${p(e)}:${n(t)}`,teardownTimer:(e,t)=>`wf-teardown:${p(e)}:${n(t)}`,delayedStart:(e,t)=>`wf-delayed:${p(e)}:${n(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${p(e)}:${n(t)}`},T={budget:(e,t,r)=>`budget:${e}:${t}:${r}`,review:(e,t)=>`review:${n(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${n(e)}`,childCancellationPrefix:(e)=>`child-cancel:${n(e)}:`,childCancellation:(e,t)=>`child-cancel:${n(e)}:${n(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}`,childWorkflowByParent:(e,t,r)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}${n(r)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${n(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${n(e)}:${n(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${n(e)}`,workflowHasServices:(e)=>`wf-has-services:${n(e)}`,finalizerState:(e)=>`wf-finalizer-state:${n(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${n(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${n(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${n(e)}`,offload:(e,t)=>`offload:${n(e)}:${t}`,archive:(e,t)=>`archive:${n(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${n(e)}:${n(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${h}:${n(e)}:${n(t)}`,streamChunkPrefix:(e,t)=>`blob:${n(e)}:${t}:chunk:`,streamChunk:(e,t,r)=>`blob:${n(e)}:${t}:chunk:${String(r).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${n(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${n(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,r)=>`tool-effect:${n(e)}:${t}:${r}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${n(e)}:${n(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${n(e)}:${n(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${p(e)}:${n(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${p(e)}:${n(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${p(e)}:${n(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${n(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};var b=a,W={workflow:(e)=>`wf:${n(e)}`,checkpoint:(e)=>`wf:${n(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${n(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${n(e)}:timeline:`,timeline:(e,t)=>`wf:${n(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${n(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${n(t)}`,scheduleRun:(e)=>`schedule-run:${n(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${n(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${n(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${n(e)}:${n(t)}`,operation:(e,t,r)=>`op:${e}:${b(t)}:${r}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,r)=>`audit:bulk:${b(e)}:${n(t)}:${n(r)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${b(e)}:${n(t)}`,asyncActivity:(e,t)=>`async-act:v1:${n(e)}:${n(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${n(e)}:${n(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${n(e)}:`,activityReconciliation:(e,t,r)=>`actrec:v1:${n(e)}:${n(t)}:${r}`,eventPrefix:(e)=>`ev:${n(e)}:`,event:(e,t)=>`ev:${n(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${n(e)}:head`,eventWatermark:(e)=>`ev:${n(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${n(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${n(e)}:${String(t).padStart(10,"0")}`},Y={attribute:(e)=>`attr:${n(e)}`,attributeIndex:(e,t,r)=>`idx:${e}:${t}:${n(r)}`,tagIndex:(e,t)=>`tag:${n(e)}:${n(t)}`,updatePrefix:(e)=>`upd:${n(e)}:`,update:(e,t)=>`upd:${n(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${n(e)}:${t}`,startIdempotency:(e)=>`start-idem:${n(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`};var ee=["actrec:","appcmd:","appdidem:","appdlv:","appdseq:","appdterm:","appdue:","appidem:","appmbx:","appobx:","appprobe:","appready:","appseq:","appterm:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","catalog-active:","catalog-entry:","catalog-tombstone:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","fleet-event-watermark","idx:","lease:","liveness:","offload:","ownership-mode-marker","op:","review:","schedule:","schedule-due:","schedule-run-by-schedule:","schedule-run-link:","schedule-run:","sig:","sigres:","sigseq:","start-idem:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-concurrency:","wf-concurrency-holder:","wf-deadline:","wf-delayed:","wf-finalizer-state:","wf-gen:","wf-has-services:","wf-headers:","wf-idx-","wf-owner-epoch:","wf-owner-holder:","wf-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var S=1e4,Fe=1e4;class N extends Error{code="StorageBatchOperationLimitExceededError";cap=S;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${S}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function g(e,t){if(t>S)throw new N(e,t)}function d(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"\xFF"}function m(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function F(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}async function z(e,t){if(e.has)return e.has(t);return x(e,t)}function U(e,t,r){if(e.keys)return e.keys(t,r);return u(e,t,r)}async function M(e,t){if(e.count)return e.count(t);return C(e,t)}async function q(e,t){if(e.deletePrefix)return e.deletePrefix(t);return R(e,t)}async function ze(e,t){g("batch operations",t.length),await e.batch(t)}async function V(e,t,r){if(g("conditionalBatch conditions",t.length),g("conditionalBatch operations",r.length),y(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,r)}var Ue={...W,...L,...I,...Y,...B,...D,..._,...A,...v,...P,...T};function te(e){if(e===void 0)return;if(typeof e!=="number"||!Number.isInteger(e)||e<0)throw Error("deleteRange limit must be a finite non-negative integer");return e===0?0:e}function f(e){let t={},r=!1;for(let s of["gt","gte","lt","lte"]){let o=e[s];if(o===void 0)continue;if(typeof o!=="string")throw Error("deleteRange bounds must be strings");t[s]=o,r=!0}if(!r)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let i=te(e.limit);if(i!==void 0)t.limit=i;return t}async function X(e,t,r){let i=f(r);if(e.deleteRange)return e.deleteRange(t,i);return k(e,t,i)}function w(e){return e.replaceAll(/:+$/g,"")}function ne(e,t){let r=w(e),i=w(t);if(r.length===0)return i;if(i.length===0)return r;return`${r}:${i}`}class O{#e;#n;constructor(e,t){this.#e=e,this.#n=w(t)}#t(e){if(this.#n.length===0)return e;return e.length===0?`${this.#n}:`:`${this.#n}:${e}`}#r(e){return e.map((t)=>{if(t.type==="put")return{type:"put",key:this.#t(t.key),value:t.value};return{type:"delete",key:this.#t(t.key)}})}#i(e){if(this.#n.length===0)return e;return e.slice(this.#n.length+1)}#o(e){let t={};if(e.limit!==void 0)t.limit=e.limit;if(e.gt!==void 0)t.gt=this.#t(e.gt);if(e.gte!==void 0)t.gte=this.#t(e.gte);if(e.lt!==void 0)t.lt=this.#t(e.lt);if(e.lte!==void 0)t.lte=this.#t(e.lte);return t}#a(e={}){let t=this.#o(e);if(e.reverse!==void 0)t.reverse=e.reverse;return t}#s(e){return this.#o(e)}capabilities(){return this.#e.capabilities()}scoped(e){return new O(this.#e,ne(this.#n,e))}async get(e){return this.#e.get(this.#t(e))}async put(e,t){await this.#e.put(this.#t(e),t)}async delete(e){await this.#e.delete(this.#t(e))}async*scan(e,t){for await(let[r,i]of this.#e.scan(this.#t(e),this.#a(t)))yield[this.#i(r),i]}async batch(e){g("batch operations",e.length),await this.#e.batch(this.#r(e))}async conditionalBatch(e,t){return V(this.#e,e.map((r)=>({key:this.#t(r.key),expectedValue:r.expectedValue})),this.#r(t))}async has(e){return z(this.#e,this.#t(e))}async deletePrefix(e){return q(this.#e,this.#t(e))}async deleteRange(e,t){let r=this.#s(f(t));return X(this.#e,this.#t(e),r)}async*keys(e,t){for await(let r of U(this.#e,this.#t(e),this.#a(t)))yield this.#i(r)}async count(e){return M(this.#e,this.#t(e))}[Symbol.dispose](){this.#e[Symbol.dispose]()}}function H(e,t){return new O(e,t)}class re{#e;constructor(){this.#e=new Map}capabilities(){return{persistence:"ephemeral",readAfterWrite:"linearizable",scanConsistency:"snapshot",atomicBatch:!0,conditionalBatch:!0,boundedRangeDelete:!0}}#n(e,t,r){return e>=t&&e<r}#t(e,t){let r=[];for(let i of this.#e.keys())if(this.#n(i,e,t))r.push(i);return r.toSorted()}async get(e){return this.#e.get(e)??null}async put(e,t){this.#e.set(e,t)}async delete(e){this.#e.delete(e)}async*scan(e,t={}){let{limit:r,reverse:i}=t,s=d(e),o=this.#t(e,s);if(o=o.filter((c)=>m(c,t)),i)o.reverse();let l=0;for(let c of o){if(r!==void 0&&l>=r)break;let E=this.#e.get(c);if(E!==void 0)yield[c,E],l++}}async batch(e){g("batch operations",e.length),this.#r(e)}#r(e){for(let t of e)if(t.type==="put")this.#e.set(t.key,t.value);else this.#e.delete(t.key)}async conditionalBatch(e,t){g("conditionalBatch conditions",e.length),g("conditionalBatch operations",t.length);for(let r of e){let i=this.#e.get(r.key)??null;if(!F(i,r.expectedValue))return!1}return this.#r(t),!0}async has(e){return this.#e.has(e)}async deletePrefix(e){let t=d(e),r=this.#t(e,t);for(let i of r)this.#e.delete(i);return r.length}async deleteRange(e,t){let r=f(t),i=d(e),s=this.#t(e,i).filter((l)=>m(l,r)),o=r.limit===void 0?s:s.slice(0,r.limit);for(let l of o)this.#e.delete(l);return o.length}async*keys(e,t={}){let{limit:r,reverse:i}=t,s=d(e),o=this.#t(e,s);if(o=o.filter((c)=>m(c,t)),i)o.reverse();let l=0;for(let c of o){if(r!==void 0&&l>=r)break;yield c,l++}}async count(e){let t=d(e);return this.#t(e,t).length}scoped(e){return H(this,e)}get size(){return this.#e.size}clear(){this.#e.clear()}snapshot(){let e=new Map;for(let[t,r]of this.#e)e.set(t,new Uint8Array(r));return e}[Symbol.dispose](){this.#e.clear()}}export{re as MemoryStorage};