@lostgradient/weft 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +2 -2
  2. package/dist/core/engine/activity-reconciliation.d.ts +2 -2
  3. package/dist/core/engine/activity-reconciliation.js +12 -8
  4. package/dist/core/engine/async-activity-completion.js +12 -4
  5. package/dist/core/engine/async-activity-records.d.ts +11 -1
  6. package/dist/core/engine/async-activity-records.js +4 -3
  7. package/dist/core/engine/attributes-tags.d.ts +11 -1
  8. package/dist/core/engine/attributes-tags.js +4 -3
  9. package/dist/core/engine/bulk-operations-purge.js +5 -2
  10. package/dist/core/engine/bulk-operations.js +17 -5
  11. package/dist/core/engine/callback-creators-bundles.js +1 -1
  12. package/dist/core/engine/callback-creators-core.js +4 -2
  13. package/dist/core/engine/checkpoint-io.js +1 -1
  14. package/dist/core/engine/child-workflow.js +2 -1
  15. package/dist/core/engine/completed-review-storage.js +1 -1
  16. package/dist/core/engine/condition-waiters.d.ts +45 -3
  17. package/dist/core/engine/condition-waiters.js +12 -3
  18. package/dist/core/engine/disposal.js +6 -0
  19. package/dist/core/engine/engine-internal-types.d.ts +12 -4
  20. package/dist/core/engine/fenced-write.d.ts +46 -15
  21. package/dist/core/engine/fenced-write.js +39 -6
  22. package/dist/core/engine/finalizer-state.d.ts +3 -1
  23. package/dist/core/engine/handle-result.d.ts +49 -1
  24. package/dist/core/engine/handle-result.js +95 -20
  25. package/dist/core/engine/index.d.ts +13 -5
  26. package/dist/core/engine/index.js +155 -5
  27. package/dist/core/engine/inline-launch-queue.js +9 -0
  28. package/dist/core/engine/internals.d.ts +73 -0
  29. package/dist/core/engine/invoke-update-handler.d.ts +19 -0
  30. package/dist/core/engine/invoke-update-handler.js +7 -0
  31. package/dist/core/engine/lease-deposition.d.ts +132 -0
  32. package/dist/core/engine/lease-deposition.js +31 -0
  33. package/dist/core/engine/lease-errors.d.ts +80 -9
  34. package/dist/core/engine/lease-errors.js +28 -2
  35. package/dist/core/engine/lifecycle/resume.js +3 -1
  36. package/dist/core/engine/lifecycle/standalone-claim-acquire.d.ts +33 -0
  37. package/dist/core/engine/lifecycle/standalone-claim-acquire.js +25 -0
  38. package/dist/core/engine/lifecycle/start-commit.js +20 -6
  39. package/dist/core/engine/lifecycle/transition.d.ts +15 -1
  40. package/dist/core/engine/lifecycle/transition.js +6 -3
  41. package/dist/core/engine/operations-activity.js +1 -1
  42. package/dist/core/engine/operations-time.js +21 -7
  43. package/dist/core/engine/owner-side-signal-poll.d.ts +132 -0
  44. package/dist/core/engine/owner-side-signal-poll.js +22 -0
  45. package/dist/core/engine/owner-side-update-poll.d.ts +116 -0
  46. package/dist/core/engine/owner-side-update-poll.js +22 -0
  47. package/dist/core/engine/ownership-bootstrap.d.ts +280 -0
  48. package/dist/core/engine/ownership-bootstrap.js +89 -0
  49. package/dist/core/engine/ownership-mode-marker.d.ts +82 -0
  50. package/dist/core/engine/ownership-mode-marker.js +52 -0
  51. package/dist/core/engine/ownership-options.d.ts +22 -6
  52. package/dist/core/engine/ownership-options.js +42 -12
  53. package/dist/core/engine/pending-updates.js +35 -24
  54. package/dist/core/engine/queries.d.ts +70 -0
  55. package/dist/core/engine/queries.js +58 -4
  56. package/dist/core/engine/schedules.js +1 -1
  57. package/dist/core/engine/signals.d.ts +11 -1
  58. package/dist/core/engine/signals.js +11 -7
  59. package/dist/core/engine/sleep-timer-acknowledgements.d.ts +68 -0
  60. package/dist/core/engine/sleep-timer-acknowledgements.js +19 -0
  61. package/dist/core/engine/storage-io.d.ts +58 -10
  62. package/dist/core/engine/storage-io.js +27 -9
  63. package/dist/core/engine/termination/cleanup.d.ts +5 -4
  64. package/dist/core/engine/termination/complete.js +23 -4
  65. package/dist/core/engine/termination/finalizer-claim.js +4 -4
  66. package/dist/core/engine/termination/state-commit-callbacks.d.ts +15 -0
  67. package/dist/core/engine/termination/state-commit-callbacks.js +0 -0
  68. package/dist/core/engine/termination/suspend.js +1 -1
  69. package/dist/core/engine/update-validation.d.ts +28 -0
  70. package/dist/core/engine/update-validation.js +37 -0
  71. package/dist/core/engine/updates.d.ts +17 -16
  72. package/dist/core/engine/updates.js +24 -47
  73. package/dist/core/engine/wake-ownership-check.d.ts +86 -0
  74. package/dist/core/engine/wake-ownership-check.js +19 -0
  75. package/dist/core/engine/wake-ownership-guard.d.ts +46 -0
  76. package/dist/core/engine/wake-ownership-guard.js +23 -0
  77. package/dist/core/engine/workflow-claim-codec.d.ts +64 -0
  78. package/dist/core/engine/workflow-claim-codec.js +44 -0
  79. package/dist/core/engine/workflow-claim-cooldown.d.ts +60 -0
  80. package/dist/core/engine/workflow-claim-cooldown.js +17 -0
  81. package/dist/core/engine/workflow-claim-fold.d.ts +82 -0
  82. package/dist/core/engine/workflow-claim-fold.js +53 -0
  83. package/dist/core/engine/workflow-claim-metrics.d.ts +131 -0
  84. package/dist/core/engine/workflow-claim-metrics.js +62 -0
  85. package/dist/core/engine/workflow-claim-reclaim-scan.d.ts +96 -0
  86. package/dist/core/engine/workflow-claim-reclaim-scan.js +66 -0
  87. package/dist/core/engine/workflow-claim-reclaim-target.d.ts +107 -0
  88. package/dist/core/engine/workflow-claim-reclaim-target.js +155 -0
  89. package/dist/core/engine/workflow-claim-registry.d.ts +227 -0
  90. package/dist/core/engine/workflow-claim-registry.js +198 -0
  91. package/dist/core/engine/workflow-claim-renewal-interval.d.ts +50 -0
  92. package/dist/core/engine/workflow-claim-renewal-interval.js +132 -0
  93. package/dist/core/engine/workflow-claim-renewal-subpasses.d.ts +265 -0
  94. package/dist/core/engine/workflow-claim-renewal-subpasses.js +104 -0
  95. package/dist/core/engine/workflow-claim-renewal-task.d.ts +159 -0
  96. package/dist/core/engine/workflow-claim-renewal-task.js +65 -0
  97. package/dist/core/engine/workflow-claim-transitions.d.ts +186 -0
  98. package/dist/core/engine/workflow-claim-transitions.js +120 -0
  99. package/dist/core/inline-execution-strategy.d.ts +20 -0
  100. package/dist/core/inline-execution-strategy.js +15 -4
  101. package/dist/core/scheduler/scheduler-class.js +3 -3
  102. package/dist/core/scheduler/timer-sources.d.ts +13 -0
  103. package/dist/core/scheduler/timer-sources.js +1 -1
  104. package/dist/core/types/options.d.ts +17 -1
  105. package/dist/core/weft-error.d.ts +1 -1
  106. package/dist/core/weft-error.js +2 -1
  107. package/dist/http.js +2 -2
  108. package/dist/index.d.ts +2 -1
  109. package/dist/index.js +8 -0
  110. package/dist/indexeddb.js +1 -1
  111. package/dist/json-schema.js +3 -3
  112. package/dist/observability/index.js +2 -2
  113. package/dist/storage/auto.js +1 -1
  114. package/dist/storage/bun-sql.js +113 -0
  115. package/dist/storage/compressed-storage.js +1 -1
  116. package/dist/storage/index.d.ts +38 -35
  117. package/dist/storage/interface.d.ts +87 -125
  118. package/dist/storage/interface.js +1 -1
  119. package/dist/storage/key-encoding.d.ts +51 -0
  120. package/dist/storage/key-encoding.js +13 -0
  121. package/dist/storage/key-prefixes.d.ts +1 -1
  122. package/dist/storage/key-prefixes.js +3 -0
  123. package/dist/storage/lmdb.js +1 -1
  124. package/dist/storage/memory.js +1 -1
  125. package/dist/storage/neon.js +2 -2
  126. package/dist/storage/node-sqlite.js +113 -0
  127. package/dist/storage/ownership-keys.d.ts +55 -0
  128. package/dist/storage/ownership-keys.js +6 -0
  129. package/dist/storage/postgres.js +2 -2
  130. package/dist/storage/resolve.js +1 -1
  131. package/dist/storage/scoped-storage.js +1 -1
  132. package/dist/storage/testing.js +1 -1
  133. package/dist/storage/turso.js +2 -2
  134. package/dist/version.d.ts +1 -1
  135. package/dist/version.js +1 -1
  136. package/dist/web-extension.js +1 -1
  137. package/dist/worker/protocol.js +1 -1
  138. package/package.json +1 -1
@@ -298,57 +298,16 @@ export declare function storageBatch(storage: Storage, operations: BatchOperatio
298
298
  * ```
299
299
  */
300
300
  export declare function storageConditionalBatch(storage: Storage, conditions: ConditionalBatchCondition[], operations: BatchOperation[]): Promise<boolean>;
301
- /**
302
- * Encode an untrusted string so it is safe to embed in a colon-delimited storage key.
303
- *
304
- * @example
305
- * ```ts
306
- * import { encodeStorageKeyComponent } from '@lostgradient/weft/storage/interface';
307
- *
308
- * const safe = encodeStorageKeyComponent('user:123/profile');
309
- * console.log(safe); // 'user%3A123%2Fprofile'
310
- * ```
311
- */
312
- export declare function encodeStorageKeyComponent(value: string): string;
313
- /**
314
- * Decode a storage-key component produced by {@link encodeStorageKeyComponent}.
315
- * Throws when `value` is malformed percent-encoded text. Callers handling
316
- * untrusted input should prefer {@link tryDecodeStorageKeyComponent}.
317
- *
318
- * @throws {URIError} When `value` contains malformed percent-encoded data.
319
- *
320
- * @example
321
- * ```ts
322
- * import { encodeStorageKeyComponent, decodeStorageKeyComponent } from '@lostgradient/weft/storage/interface';
323
- *
324
- * const encoded = encodeStorageKeyComponent('user:123');
325
- * const decoded = decodeStorageKeyComponent(encoded);
326
- * console.log(decoded); // 'user:123'
327
- * ```
328
- */
329
- export declare function decodeStorageKeyComponent(value: string): string;
330
- /**
331
- * Decode a storage-key component produced by {@link encodeStorageKeyComponent}.
332
- * Returns `null` when the component is malformed instead of throwing.
333
- *
334
- * @example
335
- * ```ts
336
- * import { tryDecodeStorageKeyComponent } from '@lostgradient/weft/storage/interface';
337
- *
338
- * console.log(tryDecodeStorageKeyComponent('user%3A123')); // 'user:123'
339
- * console.log(tryDecodeStorageKeyComponent('%GG')); // null
340
- * ```
341
- */
342
- export declare function tryDecodeStorageKeyComponent(value: string): string | null;
301
+ export { decodeStorageKeyComponent, encodeStorageKeyComponent, tryDecodeStorageKeyComponent, } from './key-encoding.ts';
343
302
  /**
344
303
  * Key layout constants for hierarchical key encoding. Timestamps are
345
304
  * zero-padded to 16 digits for lexicographic ordering.
346
305
  *
347
306
  * This registry grows as storage features are added, which is why this file
348
- * carries a `max-lines: 600` override (above the repo default ceiling) in
349
- * `.oxlintrc.json` 600 matches the documented split threshold in
350
- * `.claude/rules/conventions.md`. When `KEYS` next approaches that line, extract
351
- * it into its own module rather than raising the ceiling again.
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.
352
311
  *
353
312
  * @example
354
313
  * ```ts
@@ -357,6 +316,88 @@ export declare function tryDecodeStorageKeyComponent(value: string): string | nu
357
316
  * ```
358
317
  */
359
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 workflowOwnerEpoch: (workflowId: string) => string;
399
+ readonly workflowOwnerHolder: (workflowId: string) => string;
400
+ readonly ownershipModeMarker: () => string;
360
401
  readonly workflow: (id: string) => string;
361
402
  readonly checkpoint: (id: string) => string;
362
403
  readonly checkpointHistory: (id: string, step: number) => string;
@@ -472,83 +513,4 @@ export declare const KEYS: {
472
513
  * {@link KEYS.leaseEpoch}.
473
514
  */
474
515
  readonly leaseHolder: () => string;
475
- readonly budget: (namespace: string, period: string, date: string) => string;
476
- readonly review: (workflowId: string, reviewId: string) => string;
477
- readonly workflowHeaders: (workflowId: string) => string;
478
- readonly childCancellationPrefix: (workflowId: string) => string;
479
- readonly childCancellation: (workflowId: string, childWorkflowId: string) => string;
480
- readonly childWorkflowByParentPrefix: (parentWorkflowId: string, parentWorkflowExecutionToken?: string) => string;
481
- readonly childWorkflowByParent: (parentWorkflowId: string, parentWorkflowExecutionToken: string | undefined, childWorkflowId: string) => string;
482
- readonly terminalCleanupNeeded: (workflowId: string) => string;
483
- readonly workflowConcurrency: (workflowType: string, partitionKey: string) => string;
484
- readonly workflowConcurrencyHolder: (workflowId: string) => string;
485
- /**
486
- * Presence-only marker written at start only when a run is launched with a
487
- * non-serialized `services` value (see `start-batch.ts`). It lets a
488
- * fresh-process recovery tell a run whose services were lost on crash apart
489
- * from one that never had any — the services value itself is never persisted,
490
- * so this bit is the only durable trace. Cleared on terminal cleanup.
491
- */
492
- readonly workflowHasServices: (workflowId: string) => string;
493
- /**
494
- * Last-write-wins payload that `ctx.setFinalizerState(value)` records for a
495
- * workflow's definition-level `finalizer` activity (issue #446). Staged as a
496
- * pending atomic side-effect so it commits with the next checkpoint or the
497
- * terminal batch, and swept on terminal cleanup.
498
- *
499
- * **Current behavior (this release): recorded only.** Nothing reads this value
500
- * yet. **Planned behavior (future release):** the engine will pass the decoded
501
- * value as the finalizer's input when driving teardown after a
502
- * `cancelled`/`timed-out` terminal, where presence means "a resource was
503
- * recorded" and absence means the finalizer is skipped.
504
- */
505
- readonly finalizerState: (workflowId: string) => string;
506
- /**
507
- * Durable execution-claim + attempt marker for a workflow that owes a finalizer
508
- * run after a `cancelled`/`timed-out` terminal (issue #446 Phase 2). Mirrors the
509
- * `wf-cleanup-needed:` lifecycle. The value is the encoded claim record
510
- * `{ status: 'owed' | 'running'; attempts: number; token: string; claimedAt?: number }`:
511
- * the engine fenced-CAS's `owed → running` (stamping `claimedAt`) before invoking the
512
- * finalizer, and settle-CAS's the exact `running` bytes it wrote when clearing or
513
- * rescheduling. Liveness is decided purely by TIME: a `running` claim is reclaimable
514
- * once `claimedAt` is older than the finalizer's per-attempt timeout plus a margin
515
- * (see `teardownStaleThresholdMs`), so crash recovery is an ordinary stale-claim retry
516
- * driven by the timer that survived the terminal batch — there is no in-memory liveness
517
- * set and no epoch in the record. The cost is that a finalizer running past the stale
518
- * threshold may be re-driven concurrently, which is why workflow finalizers must be
519
- * idempotent. Present while teardown is outstanding; deleted by the finalizer on
520
- * success or when it dead-letters, which is what unblocks purge.
521
- */
522
- readonly teardownOwed: (workflowId: string) => string;
523
- /** Durable successful finalizer outcome, retained until workflow purge or retention. */
524
- readonly teardownSucceeded: (workflowId: string) => string;
525
- /**
526
- * Durable audit record written when a workflow's finalizer permanently fails — the
527
- * retry horizon is reached, or the recorded resource state vanished so the finalizer
528
- * can never run (issue #446 Phase 2). Holds the `TeardownDeadLetterRecord` shape
529
- * `{ type, lastError, attempts, deadLetteredAt, workflowExecutionToken?, finalizerInput? }`.
530
- * **Excluded from the workflow purge delete-set** so it survives as the operator's
531
- * evidence of a leaked external resource and remains queryable through the durable
532
- * finalizer-status API after purge.
533
- */
534
- readonly teardownDeadLetter: (workflowId: string) => string;
535
- readonly offload: (workflowId: string, key: string) => string;
536
- readonly archive: (workflowId: string, key: string) => string;
537
- readonly stateExecution: (ownerWorkflowId: string, key: string) => string;
538
- readonly stateWorkflow: (workflowType: string, key: string) => string;
539
- readonly streamChunkPrefix: (workflowId: string, key: string) => string;
540
- readonly streamChunk: (workflowId: string, key: string, chunkIndex: number) => string;
541
- readonly streamTail: (workflowId: string, key: string) => string;
542
- readonly streamMetadata: (workflowId: string, key: string) => string;
543
- readonly budgetCharged: (operationId: string) => string;
544
- readonly toolEffect: (workflowId: string, agentId: string, semanticHash: string) => string;
545
- readonly workflowVisibilityStatus: (status: string, workflowId: string) => string;
546
- readonly workflowVisibilityType: (type: string, workflowId: string) => string;
547
- readonly workflowVisibilityCreated: (createdAt: number, workflowId: string) => string;
548
- readonly workflowVisibilityUpdated: (updatedAt: number, workflowId: string) => string;
549
- readonly workflowVisibilityDeadline: (deadline: number, workflowId: string) => string;
550
- readonly workflowVisibilityManifest: (workflowId: string) => string;
551
- readonly workflowVisibilityMetaVersion: () => string;
552
- readonly workflowVisibilityMetaBuiltAt: () => string;
553
- readonly workflowVisibilityMetaCursor: () => string;
554
516
  };
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- var H=import.meta.require,C=(E,_,F)=>{if(_!=null){if(typeof _!=="object"&&typeof _!=="function")throw TypeError('Object expected to be assigned to "using" declaration');let P;if(F)P=_[Symbol.asyncDispose];if(P===void 0)P=_[Symbol.dispose];if(typeof P!=="function")throw TypeError("Object not disposable");E.push([F,P,_])}else if(F)E.push([F]);return _},N=(E,_,F)=>{let P=(Y)=>_=F?new SuppressedError(Y,_,"An error was suppressed during disposal"):(F=!0,Y),U=(Y)=>{while(Y=E.pop())try{var $=Y[1]&&Y[1].call(Y[2]);if(Y[0])return Promise.resolve($).then(U,(D)=>(P(D),U()))}catch(D){P(D)}if(F)throw _};return U()};function L(E,_,F){if(!E.capabilities()[_])throw Error(`Feature "${F}" requires storage capability "${_}", but this storage backend does not provide it.`)}function j(E){let _=E.capabilities(),F=[];if(_.persistence!=="local"&&_.persistence!=="remote")F.push(`persistence must be "local" or "remote" (got "${_.persistence}")`);if(_.readAfterWrite!=="linearizable")F.push(`readAfterWrite must be "linearizable" (got "${_.readAfterWrite}")`);if(_.scanConsistency!=="snapshot")F.push(`scanConsistency must be "snapshot" (got "${_.scanConsistency}")`);if(!_.atomicBatch)F.push("atomicBatch must be true");if(!_.conditionalBatch)F.push("conditionalBatch must be true");if(F.length>0)throw Error(`Storage is not durable enough for recovery: ${F.join("; ")}.`)}var V="default";async function K(E,_){return await E.get(_)!==null}async function*X(E,_,F){for await(let[P]of E.scan(_,F))yield P}async function M(E,_){let F=0;for await(let P of X(E,_))F++;return F}async function O(E,_){let F=[];for await(let P of X(E,_))F.push({type:"delete",key:P});if(F.length===0)return 0;return await E.batch(F),F.length}async function W(E,_,F){let P=[];for await(let U of X(E,_,F))P.push({type:"delete",key:U});if(P.length===0)return 0;return await E.batch(P),P.length}var z=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","idx:","lease:","liveness:","offload:","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-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var G=1e4,u=1e4;class Z extends Error{code="StorageBatchOperationLimitExceededError";cap=G;count;target;constructor(E,_){super(`${E} count ${_} exceeds MAX_BATCH_OPERATIONS (${G}).`);this.name="StorageBatchOperationLimitExceededError",this.target=E,this.count=_}}function J(E,_){if(_>G)throw new Z(E,_)}function y(E){return E.length>0?E.slice(0,-1)+String.fromCharCode(E.charCodeAt(E.length-1)+1):"\xFF"}function g(E,_={}){if(_.gt!==void 0&&E<=_.gt)return!1;if(_.gte!==void 0&&E<_.gte)return!1;if(_.lt!==void 0&&E>=_.lt)return!1;if(_.lte!==void 0&&E>_.lte)return!1;return!0}function p(E,_){if(E===null||_===null)return E===_;if(E.byteLength!==_.byteLength)return!1;for(let F=0;F<E.byteLength;F++)if(E[F]!==_[F])return!1;return!0}async function n(E,_){if(E.has)return E.has(_);return K(E,_)}function s(E,_,F){if(E.keys)return E.keys(_,F);return X(E,_,F)}async function a(E,_){if(E.count)return E.count(_);return M(E,_)}async function f(E,_){if(E.deletePrefix)return E.deletePrefix(_);return O(E,_)}async function I(E,_){J("batch operations",_.length),await E.batch(_)}async function l(E,_,F){if(J("conditionalBatch conditions",_.length),J("conditionalBatch operations",F.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(_,F)}function S(E){return encodeURIComponent(E)}function k(E){return decodeURIComponent(E)}function t(E){try{return decodeURIComponent(E)}catch{return null}}var R=(E)=>String(E).padStart(16,"0"),B="0",v="1",Q=(E,_,F,P)=>`sig:${S(E)}:${S(_)}:${P}:${S(F)}`,i={workflow:(E)=>`wf:${S(E)}`,checkpoint:(E)=>`wf:${S(E)}:ckpt`,checkpointHistory:(E,_)=>`wf:${S(E)}:ckpt:${String(_).padStart(10,"0")}`,timelinePrefix:(E)=>`wf:${S(E)}:timeline:`,timeline:(E,_)=>`wf:${S(E)}:timeline:${String(_).padStart(10,"0")}`,schedule:(E)=>`schedule:${S(E)}`,scheduleTick:(E,_)=>`schedule-due:${String(E).padStart(16,"0")}:${S(_)}`,scheduleRun:(E)=>`schedule-run:${S(E)}`,scheduleRunLink:(E)=>`schedule-run-link:${S(E)}`,scheduleRunBySchedulePrefix:(E)=>`schedule-run-by-schedule:${S(E)}:`,scheduleRunBySchedule:(E,_)=>`schedule-run-by-schedule:${S(E)}:${S(_)}`,operation:(E,_,F)=>`op:${E}:${R(_)}:${F}`,operationInflight:(E)=>`op:inflight:${E}`,operationQueued:(E)=>`op:queued:${E}`,operationResolved:(E)=>`op:resolved:${E}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(E,_,F)=>`audit:bulk:${R(E)}:${S(_)}:${S(F)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(E,_)=>`op:resolved-by-time:${R(E)}:${S(_)}`,asyncActivity:(E,_)=>`async-act:v1:${S(E)}:${S(_)}`,asyncActivityResolution:(E,_)=>`async-act:v1:${S(E)}:${S(_)}:resolution`,activityReconciliationPrefix:(E)=>`actrec:v1:${S(E)}:`,activityReconciliation:(E,_,F)=>`actrec:v1:${S(E)}:${S(_)}:${F}`,eventPrefix:(E)=>`ev:${S(E)}:`,event:(E,_)=>`ev:${S(E)}:${String(_).padStart(10,"0")}`,eventHead:(E)=>`ev:${S(E)}:head`,eventWatermark:(E)=>`ev:${S(E)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(E)=>`fleet-event:${String(E).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventByWorkflowPrefix:(E)=>`fleet-event-by-workflow:${S(E)}:`,fleetEventByWorkflow:(E,_)=>`fleet-event-by-workflow:${S(E)}:${String(_).padStart(10,"0")}`,signal:(E,_,F)=>Q(E,_,F,v),startSignal:(E,_,F)=>Q(E,_,F,B),signalSequence:(E)=>`sigseq:v1:${S(E)}`,signalAcceptedResponsePrefix:(E)=>`sigres:v1:${S(E)}:`,signalAcceptedResponse:(E,_,F)=>`sigres:v1:${S(E)}:${S(_)}:${S(F)}`,deadline:(E,_)=>`wf-deadline:${R(E)}:${S(_)}`,terminalCleanup:(E,_)=>`wf-cleanup:${R(E)}:${S(_)}`,teardownTimer:(E,_)=>`wf-teardown:${R(E)}:${S(_)}`,delayedStart:(E,_)=>`wf-delayed:${R(E)}:${S(_)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(E,_)=>`wf-terminal:${R(E)}:${S(_)}`,attribute:(E)=>`attr:${S(E)}`,attributeIndex:(E,_,F)=>`idx:${E}:${_}:${S(F)}`,tagIndex:(E,_)=>`tag:${S(E)}:${S(_)}`,updatePrefix:(E)=>`upd:${S(E)}:`,update:(E,_)=>`upd:${S(E)}:${_}`,updateResponse:(E)=>`upr:${E}`,updateIdempotency:(E,_)=>`upk:${S(E)}:${_}`,startIdempotency:(E)=>`start-idem:${S(E)}`,startIdempotencySignalId:(E)=>`start-idem:${E}`,livenessPrefix:()=>"liveness:",liveness:(E)=>`liveness:${S(E)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",budget:(E,_,F)=>`budget:${E}:${_}:${F}`,review:(E,_)=>`review:${S(E)}:${_}`,workflowHeaders:(E)=>`wf-headers:${S(E)}`,childCancellationPrefix:(E)=>`child-cancel:${S(E)}:`,childCancellation:(E,_)=>`child-cancel:${S(E)}:${S(_)}`,childWorkflowByParentPrefix:(E,_)=>`child-by-parent:${S(E)}:${_===void 0?"":`${S(_)}:`}`,childWorkflowByParent:(E,_,F)=>`child-by-parent:${S(E)}:${_===void 0?"":`${S(_)}:`}${S(F)}`,terminalCleanupNeeded:(E)=>`wf-cleanup-needed:${S(E)}`,workflowConcurrency:(E,_)=>`wf-concurrency:${S(E)}:${S(_)}`,workflowConcurrencyHolder:(E)=>`wf-concurrency-holder:${S(E)}`,workflowHasServices:(E)=>`wf-has-services:${S(E)}`,finalizerState:(E)=>`wf-finalizer-state:${S(E)}`,teardownOwed:(E)=>`wf-teardown-needed:${S(E)}`,teardownSucceeded:(E)=>`wf-teardown-succeeded:${S(E)}`,teardownDeadLetter:(E)=>`wf-teardown-deadletter:${S(E)}`,offload:(E,_)=>`offload:${S(E)}:${_}`,archive:(E,_)=>`archive:${S(E)}:${_}`,stateExecution:(E,_)=>`state:execution:${S(E)}:${S(_)}`,stateWorkflow:(E,_)=>`state:workflow-scope:${V}:${S(E)}:${S(_)}`,streamChunkPrefix:(E,_)=>`blob:${S(E)}:${_}:chunk:`,streamChunk:(E,_,F)=>`blob:${S(E)}:${_}:chunk:${String(F).padStart(10,"0")}`,streamTail:(E,_)=>`blob:${S(E)}:${_}:tail`,streamMetadata:(E,_)=>`blob:${S(E)}:${_}:meta`,budgetCharged:(E)=>`budget-charged:${E}`,toolEffect:(E,_,F)=>`tool-effect:${S(E)}:${_}:${F}`,workflowVisibilityStatus:(E,_)=>`wf-idx-status:${S(E)}:${S(_)}`,workflowVisibilityType:(E,_)=>`wf-idx-type:${S(E)}:${S(_)}`,workflowVisibilityCreated:(E,_)=>`wf-idx-created:${R(E)}:${S(_)}`,workflowVisibilityUpdated:(E,_)=>`wf-idx-updated:${R(E)}:${S(_)}`,workflowVisibilityDeadline:(E,_)=>`wf-idx-deadline:${R(E)}:${S(_)}`,workflowVisibilityManifest:(E)=>`wf-idx-manifest:${S(E)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};export{t as tryDecodeStorageKeyComponent,p as storageValuesEqual,s as storageKeys,n as storageHas,f as storageDeletePrefix,a as storageCount,l as storageConditionalBatch,I as storageBatch,y as resolvePrefixRangeEnd,L as requireStorageCapability,g as matchesScanOptions,S as encodeStorageKeyComponent,k as decodeStorageKeyComponent,J as assertStorageBatchOperationCount,j as assertDurableStorageForRecovery,z as WEFT_RESERVED_KEY_PREFIXES,Z as StorageBatchOperationLimitExceededError,u as MAX_SCAN_LIMIT,G as MAX_BATCH_OPERATIONS,i as KEYS,V as DEFAULT_SCOPE};
2
+ var K=import.meta.require;function X(E,_,P){if(!E.capabilities()[_])throw Error(`Feature "${P}" requires storage capability "${_}", but this storage backend does not provide it.`)}function J(E){let _=E.capabilities(),P=[];if(_.persistence!=="local"&&_.persistence!=="remote")P.push(`persistence must be "local" or "remote" (got "${_.persistence}")`);if(_.readAfterWrite!=="linearizable")P.push(`readAfterWrite must be "linearizable" (got "${_.readAfterWrite}")`);if(_.scanConsistency!=="snapshot")P.push(`scanConsistency must be "snapshot" (got "${_.scanConsistency}")`);if(!_.atomicBatch)P.push("atomicBatch must be true");if(!_.conditionalBatch)P.push("conditionalBatch must be true");if(P.length>0)throw Error(`Storage is not durable enough for recovery: ${P.join("; ")}.`)}var S="default";async function M(E,_){return await E.get(_)!==null}async function*U(E,_,P){for await(let[R]of E.scan(_,P))yield R}async function Q(E,_){let P=0;for await(let R of U(E,_))P++;return P}async function Z(E,_){let P=[];for await(let R of U(E,_))P.push({type:"delete",key:R});if(P.length===0)return 0;return await E.batch(P),P.length}async function W(E,_,P){let R=[];for await(let B of U(E,_,P))R.push({type:"delete",key:B});if(R.length===0)return 0;return await E.batch(R),R.length}function F(E){return encodeURIComponent(E)}function O(E){return decodeURIComponent(E)}function G(E){try{return decodeURIComponent(E)}catch{return null}}var $={workflowOwnerEpoch:(E)=>`wf-owner-epoch:${F(E)}`,workflowOwnerHolder:(E)=>`wf-owner-holder:${F(E)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var H=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","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 L=1e4,p=1e4;class z extends Error{code="StorageBatchOperationLimitExceededError";cap=L;count;target;constructor(E,_){super(`${E} count ${_} exceeds MAX_BATCH_OPERATIONS (${L}).`);this.name="StorageBatchOperationLimitExceededError",this.target=E,this.count=_}}function V(E,_){if(_>L)throw new z(E,_)}function I(E){return E.length>0?E.slice(0,-1)+String.fromCharCode(E.charCodeAt(E.length-1)+1):"\xFF"}function f(E,_={}){if(_.gt!==void 0&&E<=_.gt)return!1;if(_.gte!==void 0&&E<_.gte)return!1;if(_.lt!==void 0&&E>=_.lt)return!1;if(_.lte!==void 0&&E>_.lte)return!1;return!0}function s(E,_){if(E===null||_===null)return E===_;if(E.byteLength!==_.byteLength)return!1;for(let P=0;P<E.byteLength;P++)if(E[P]!==_[P])return!1;return!0}async function n(E,_){if(E.has)return E.has(_);return M(E,_)}function a(E,_,P){if(E.keys)return E.keys(_,P);return U(E,_,P)}async function l(E,_){if(E.count)return E.count(_);return Q(E,_)}async function k(E,_){if(E.deletePrefix)return E.deletePrefix(_);return Z(E,_)}async function i(E,_){V("batch operations",_.length),await E.batch(_)}async function d(E,_,P){if(V("conditionalBatch conditions",_.length),V("conditionalBatch operations",P.length),X(E,"conditionalBatch","storageConditionalBatch"),!E.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return E.conditionalBatch(_,P)}var Y=(E)=>String(E).padStart(16,"0"),D="0",v="1",j=(E,_,P,R)=>`sig:${F(E)}:${F(_)}:${R}:${F(P)}`,w={workflow:(E)=>`wf:${F(E)}`,checkpoint:(E)=>`wf:${F(E)}:ckpt`,checkpointHistory:(E,_)=>`wf:${F(E)}:ckpt:${String(_).padStart(10,"0")}`,timelinePrefix:(E)=>`wf:${F(E)}:timeline:`,timeline:(E,_)=>`wf:${F(E)}:timeline:${String(_).padStart(10,"0")}`,schedule:(E)=>`schedule:${F(E)}`,scheduleTick:(E,_)=>`schedule-due:${String(E).padStart(16,"0")}:${F(_)}`,scheduleRun:(E)=>`schedule-run:${F(E)}`,scheduleRunLink:(E)=>`schedule-run-link:${F(E)}`,scheduleRunBySchedulePrefix:(E)=>`schedule-run-by-schedule:${F(E)}:`,scheduleRunBySchedule:(E,_)=>`schedule-run-by-schedule:${F(E)}:${F(_)}`,operation:(E,_,P)=>`op:${E}:${Y(_)}:${P}`,operationInflight:(E)=>`op:inflight:${E}`,operationQueued:(E)=>`op:queued:${E}`,operationResolved:(E)=>`op:resolved:${E}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(E,_,P)=>`audit:bulk:${Y(E)}:${F(_)}:${F(P)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(E,_)=>`op:resolved-by-time:${Y(E)}:${F(_)}`,asyncActivity:(E,_)=>`async-act:v1:${F(E)}:${F(_)}`,asyncActivityResolution:(E,_)=>`async-act:v1:${F(E)}:${F(_)}:resolution`,activityReconciliationPrefix:(E)=>`actrec:v1:${F(E)}:`,activityReconciliation:(E,_,P)=>`actrec:v1:${F(E)}:${F(_)}:${P}`,eventPrefix:(E)=>`ev:${F(E)}:`,event:(E,_)=>`ev:${F(E)}:${String(_).padStart(10,"0")}`,eventHead:(E)=>`ev:${F(E)}:head`,eventWatermark:(E)=>`ev:${F(E)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(E)=>`fleet-event:${String(E).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventByWorkflowPrefix:(E)=>`fleet-event-by-workflow:${F(E)}:`,fleetEventByWorkflow:(E,_)=>`fleet-event-by-workflow:${F(E)}:${String(_).padStart(10,"0")}`,signal:(E,_,P)=>j(E,_,P,v),startSignal:(E,_,P)=>j(E,_,P,D),signalSequence:(E)=>`sigseq:v1:${F(E)}`,signalAcceptedResponsePrefix:(E)=>`sigres:v1:${F(E)}:`,signalAcceptedResponse:(E,_,P)=>`sigres:v1:${F(E)}:${F(_)}:${F(P)}`,deadline:(E,_)=>`wf-deadline:${Y(E)}:${F(_)}`,terminalCleanup:(E,_)=>`wf-cleanup:${Y(E)}:${F(_)}`,teardownTimer:(E,_)=>`wf-teardown:${Y(E)}:${F(_)}`,delayedStart:(E,_)=>`wf-delayed:${Y(E)}:${F(_)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(E,_)=>`wf-terminal:${Y(E)}:${F(_)}`,attribute:(E)=>`attr:${F(E)}`,attributeIndex:(E,_,P)=>`idx:${E}:${_}:${F(P)}`,tagIndex:(E,_)=>`tag:${F(E)}:${F(_)}`,updatePrefix:(E)=>`upd:${F(E)}:`,update:(E,_)=>`upd:${F(E)}:${_}`,updateResponse:(E)=>`upr:${E}`,updateIdempotency:(E,_)=>`upk:${F(E)}:${_}`,startIdempotency:(E)=>`start-idem:${F(E)}`,startIdempotencySignalId:(E)=>`start-idem:${E}`,livenessPrefix:()=>"liveness:",liveness:(E)=>`liveness:${F(E)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",...$,budget:(E,_,P)=>`budget:${E}:${_}:${P}`,review:(E,_)=>`review:${F(E)}:${_}`,workflowHeaders:(E)=>`wf-headers:${F(E)}`,childCancellationPrefix:(E)=>`child-cancel:${F(E)}:`,childCancellation:(E,_)=>`child-cancel:${F(E)}:${F(_)}`,childWorkflowByParentPrefix:(E,_)=>`child-by-parent:${F(E)}:${_===void 0?"":`${F(_)}:`}`,childWorkflowByParent:(E,_,P)=>`child-by-parent:${F(E)}:${_===void 0?"":`${F(_)}:`}${F(P)}`,terminalCleanupNeeded:(E)=>`wf-cleanup-needed:${F(E)}`,workflowConcurrency:(E,_)=>`wf-concurrency:${F(E)}:${F(_)}`,workflowConcurrencyHolder:(E)=>`wf-concurrency-holder:${F(E)}`,workflowHasServices:(E)=>`wf-has-services:${F(E)}`,finalizerState:(E)=>`wf-finalizer-state:${F(E)}`,teardownOwed:(E)=>`wf-teardown-needed:${F(E)}`,teardownSucceeded:(E)=>`wf-teardown-succeeded:${F(E)}`,teardownDeadLetter:(E)=>`wf-teardown-deadletter:${F(E)}`,offload:(E,_)=>`offload:${F(E)}:${_}`,archive:(E,_)=>`archive:${F(E)}:${_}`,stateExecution:(E,_)=>`state:execution:${F(E)}:${F(_)}`,stateWorkflow:(E,_)=>`state:workflow-scope:${S}:${F(E)}:${F(_)}`,streamChunkPrefix:(E,_)=>`blob:${F(E)}:${_}:chunk:`,streamChunk:(E,_,P)=>`blob:${F(E)}:${_}:chunk:${String(P).padStart(10,"0")}`,streamTail:(E,_)=>`blob:${F(E)}:${_}:tail`,streamMetadata:(E,_)=>`blob:${F(E)}:${_}:meta`,budgetCharged:(E)=>`budget-charged:${E}`,toolEffect:(E,_,P)=>`tool-effect:${F(E)}:${_}:${P}`,workflowVisibilityStatus:(E,_)=>`wf-idx-status:${F(E)}:${F(_)}`,workflowVisibilityType:(E,_)=>`wf-idx-type:${F(E)}:${F(_)}`,workflowVisibilityCreated:(E,_)=>`wf-idx-created:${Y(E)}:${F(_)}`,workflowVisibilityUpdated:(E,_)=>`wf-idx-updated:${Y(E)}:${F(_)}`,workflowVisibilityDeadline:(E,_)=>`wf-idx-deadline:${Y(E)}:${F(_)}`,workflowVisibilityManifest:(E)=>`wf-idx-manifest:${F(E)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};export{G as tryDecodeStorageKeyComponent,s as storageValuesEqual,a as storageKeys,n as storageHas,k as storageDeletePrefix,l as storageCount,d as storageConditionalBatch,i as storageBatch,I as resolvePrefixRangeEnd,X as requireStorageCapability,f as matchesScanOptions,F as encodeStorageKeyComponent,O as decodeStorageKeyComponent,V as assertStorageBatchOperationCount,J as assertDurableStorageForRecovery,H as WEFT_RESERVED_KEY_PREFIXES,z as StorageBatchOperationLimitExceededError,p as MAX_SCAN_LIMIT,L as MAX_BATCH_OPERATIONS,w as KEYS,S as DEFAULT_SCOPE};
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Encoding helpers for colon-delimited storage key components.
3
+ *
4
+ * Split out of `interface.ts` so the ownership key builders can reuse them
5
+ * without an import cycle: `interface.ts` re-exports everything here, so the
6
+ * public surface (`@lostgradient/weft/storage/interface`) is unchanged.
7
+ *
8
+ * @module storage/key-encoding
9
+ */
10
+ /**
11
+ * Encode an untrusted string so it is safe to embed in a colon-delimited storage key.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { encodeStorageKeyComponent } from '@lostgradient/weft/storage/interface';
16
+ *
17
+ * const safe = encodeStorageKeyComponent('user:123/profile');
18
+ * console.log(safe); // 'user%3A123%2Fprofile'
19
+ * ```
20
+ */
21
+ export declare function encodeStorageKeyComponent(value: string): string;
22
+ /**
23
+ * Decode a storage-key component produced by {@link encodeStorageKeyComponent}.
24
+ * Throws when `value` is malformed percent-encoded text. Callers handling
25
+ * untrusted input should prefer {@link tryDecodeStorageKeyComponent}.
26
+ *
27
+ * @throws {URIError} When `value` contains malformed percent-encoded data.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { encodeStorageKeyComponent, decodeStorageKeyComponent } from '@lostgradient/weft/storage/interface';
32
+ *
33
+ * const encoded = encodeStorageKeyComponent('user:123');
34
+ * const decoded = decodeStorageKeyComponent(encoded);
35
+ * console.log(decoded); // 'user:123'
36
+ * ```
37
+ */
38
+ export declare function decodeStorageKeyComponent(value: string): string;
39
+ /**
40
+ * Decode a storage-key component produced by {@link encodeStorageKeyComponent}.
41
+ * Returns `null` when the component is malformed instead of throwing.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import { tryDecodeStorageKeyComponent } from '@lostgradient/weft/storage/interface';
46
+ *
47
+ * console.log(tryDecodeStorageKeyComponent('user%3A123')); // 'user:123'
48
+ * console.log(tryDecodeStorageKeyComponent('%GG')); // null
49
+ * ```
50
+ */
51
+ export declare function tryDecodeStorageKeyComponent(value: string): string | null;
@@ -0,0 +1,13 @@
1
+ export function encodeStorageKeyComponent(value) {
2
+ return encodeURIComponent(value);
3
+ }
4
+ export function decodeStorageKeyComponent(value) {
5
+ return decodeURIComponent(value);
6
+ }
7
+ export function tryDecodeStorageKeyComponent(value) {
8
+ try {
9
+ return decodeURIComponent(value);
10
+ } catch {
11
+ return null;
12
+ }
13
+ }
@@ -16,4 +16,4 @@
16
16
  * console.log(isWeftKey); // true
17
17
  * ```
18
18
  */
19
- export declare const WEFT_RESERVED_KEY_PREFIXES: readonly ["actrec:", "archive:", "async-act:", "attr:", "audit:bulk:", "blob:", "budget:", "budget-charged:", "child-by-parent:", "ev:", "fleet-event-by-workflow:", "fleet-event:", "fleet-event-tail", "idx:", "lease:", "liveness:", "offload:", "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-teardown:", "wf-teardown-deadletter:", "wf-teardown-needed:", "wf-teardown-succeeded:", "wf-terminal:"];
19
+ export declare const WEFT_RESERVED_KEY_PREFIXES: readonly ["actrec:", "archive:", "async-act:", "attr:", "audit:bulk:", "blob:", "budget:", "budget-charged:", "child-by-parent:", "ev:", "fleet-event-by-workflow:", "fleet-event:", "fleet-event-tail", "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:"];
@@ -16,6 +16,7 @@ export const WEFT_RESERVED_KEY_PREFIXES = [
16
16
  "lease:",
17
17
  "liveness:",
18
18
  "offload:",
19
+ "ownership-mode-marker",
19
20
  "op:",
20
21
  "review:",
21
22
  "schedule:",
@@ -44,6 +45,8 @@ export const WEFT_RESERVED_KEY_PREFIXES = [
44
45
  "wf-has-services:",
45
46
  "wf-headers:",
46
47
  "wf-idx-",
48
+ "wf-owner-epoch:",
49
+ "wf-owner-holder:",
47
50
  "wf-teardown:",
48
51
  "wf-teardown-deadletter:",
49
52
  "wf-teardown-needed:",
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- var d=import.meta.require,p=(_,F,E)=>{if(F!=null){if(typeof F!=="object"&&typeof F!=="function")throw TypeError('Object expected to be assigned to "using" declaration');let X;if(E)X=F[Symbol.asyncDispose];if(X===void 0)X=F[Symbol.dispose];if(typeof X!=="function")throw TypeError("Object not disposable");_.push([E,X,F])}else if(E)_.push([E]);return F},a=(_,F,E)=>{let X=(G)=>F=E?new SuppressedError(G,F,"An error was suppressed during disposal"):(E=!0,G),U=(G)=>{while(G=_.pop())try{var Z=G[1]&&G[1].call(G[2]);if(G[0])return Promise.resolve(Z).then(U,(M)=>(X(M),U()))}catch(M){X(M)}if(E)throw F};return U()};function L(_,F,E){if(!_.capabilities()[F])throw Error(`Feature "${E}" requires storage capability "${F}", but this storage backend does not provide it.`)}function x(_){let F=_.capabilities(),E=[];if(F.persistence!=="local"&&F.persistence!=="remote")E.push(`persistence must be "local" or "remote" (got "${F.persistence}")`);if(F.readAfterWrite!=="linearizable")E.push(`readAfterWrite must be "linearizable" (got "${F.readAfterWrite}")`);if(F.scanConsistency!=="snapshot")E.push(`scanConsistency must be "snapshot" (got "${F.scanConsistency}")`);if(!F.atomicBatch)E.push("atomicBatch must be true");if(!F.conditionalBatch)E.push("conditionalBatch must be true");if(E.length>0)throw Error(`Storage is not durable enough for recovery: ${E.join("; ")}.`)}var D="default";async function W(_,F){return await _.get(F)!==null}async function*j(_,F,E){for await(let[X]of _.scan(F,E))yield X}async function B(_,F){let E=0;for await(let X of j(_,F))E++;return E}async function R(_,F){let E=[];for await(let X of j(_,F))E.push({type:"delete",key:X});if(E.length===0)return 0;return await _.batch(E),E.length}async function C(_,F,E){let X=[];for await(let U of j(_,F,E))X.push({type:"delete",key:U});if(X.length===0)return 0;return await _.batch(X),X.length}var g=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","idx:","lease:","liveness:","offload:","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-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var N=1e4,F_=1e4;class K extends Error{code="StorageBatchOperationLimitExceededError";cap=N;count;target;constructor(_,F){super(`${_} count ${F} exceeds MAX_BATCH_OPERATIONS (${N}).`);this.name="StorageBatchOperationLimitExceededError",this.target=_,this.count=F}}function Q(_,F){if(F>N)throw new K(_,F)}function V(_){return _.length>0?_.slice(0,-1)+String.fromCharCode(_.charCodeAt(_.length-1)+1):"\xFF"}function S(_,F={}){if(F.gt!==void 0&&_<=F.gt)return!1;if(F.gte!==void 0&&_<F.gte)return!1;if(F.lt!==void 0&&_>=F.lt)return!1;if(F.lte!==void 0&&_>F.lte)return!1;return!0}function z(_,F){if(_===null||F===null)return _===F;if(_.byteLength!==F.byteLength)return!1;for(let E=0;E<_.byteLength;E++)if(_[E]!==F[E])return!1;return!0}async function v(_,F){if(_.has)return _.has(F);return W(_,F)}function h(_,F,E){if(_.keys)return _.keys(F,E);return j(_,F,E)}async function P(_,F){if(_.count)return _.count(F);return B(_,F)}async function O(_,F){if(_.deletePrefix)return _.deletePrefix(F);return R(_,F)}async function E_(_,F){Q("batch operations",F.length),await _.batch(F)}async function b(_,F,E){if(Q("conditionalBatch conditions",F.length),Q("conditionalBatch operations",E.length),L(_,"conditionalBatch","storageConditionalBatch"),!_.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return _.conditionalBatch(F,E)}function Y(_){return encodeURIComponent(_)}function Y_(_){return decodeURIComponent(_)}function X_(_){try{return decodeURIComponent(_)}catch{return null}}var J=(_)=>String(_).padStart(16,"0"),I="0",w="1",A=(_,F,E,X)=>`sig:${Y(_)}:${Y(F)}:${X}:${Y(E)}`,U_={workflow:(_)=>`wf:${Y(_)}`,checkpoint:(_)=>`wf:${Y(_)}:ckpt`,checkpointHistory:(_,F)=>`wf:${Y(_)}:ckpt:${String(F).padStart(10,"0")}`,timelinePrefix:(_)=>`wf:${Y(_)}:timeline:`,timeline:(_,F)=>`wf:${Y(_)}:timeline:${String(F).padStart(10,"0")}`,schedule:(_)=>`schedule:${Y(_)}`,scheduleTick:(_,F)=>`schedule-due:${String(_).padStart(16,"0")}:${Y(F)}`,scheduleRun:(_)=>`schedule-run:${Y(_)}`,scheduleRunLink:(_)=>`schedule-run-link:${Y(_)}`,scheduleRunBySchedulePrefix:(_)=>`schedule-run-by-schedule:${Y(_)}:`,scheduleRunBySchedule:(_,F)=>`schedule-run-by-schedule:${Y(_)}:${Y(F)}`,operation:(_,F,E)=>`op:${_}:${J(F)}:${E}`,operationInflight:(_)=>`op:inflight:${_}`,operationQueued:(_)=>`op:queued:${_}`,operationResolved:(_)=>`op:resolved:${_}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(_,F,E)=>`audit:bulk:${J(_)}:${Y(F)}:${Y(E)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(_,F)=>`op:resolved-by-time:${J(_)}:${Y(F)}`,asyncActivity:(_,F)=>`async-act:v1:${Y(_)}:${Y(F)}`,asyncActivityResolution:(_,F)=>`async-act:v1:${Y(_)}:${Y(F)}:resolution`,activityReconciliationPrefix:(_)=>`actrec:v1:${Y(_)}:`,activityReconciliation:(_,F,E)=>`actrec:v1:${Y(_)}:${Y(F)}:${E}`,eventPrefix:(_)=>`ev:${Y(_)}:`,event:(_,F)=>`ev:${Y(_)}:${String(F).padStart(10,"0")}`,eventHead:(_)=>`ev:${Y(_)}:head`,eventWatermark:(_)=>`ev:${Y(_)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(_)=>`fleet-event:${String(_).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventByWorkflowPrefix:(_)=>`fleet-event-by-workflow:${Y(_)}:`,fleetEventByWorkflow:(_,F)=>`fleet-event-by-workflow:${Y(_)}:${String(F).padStart(10,"0")}`,signal:(_,F,E)=>A(_,F,E,w),startSignal:(_,F,E)=>A(_,F,E,I),signalSequence:(_)=>`sigseq:v1:${Y(_)}`,signalAcceptedResponsePrefix:(_)=>`sigres:v1:${Y(_)}:`,signalAcceptedResponse:(_,F,E)=>`sigres:v1:${Y(_)}:${Y(F)}:${Y(E)}`,deadline:(_,F)=>`wf-deadline:${J(_)}:${Y(F)}`,terminalCleanup:(_,F)=>`wf-cleanup:${J(_)}:${Y(F)}`,teardownTimer:(_,F)=>`wf-teardown:${J(_)}:${Y(F)}`,delayedStart:(_,F)=>`wf-delayed:${J(_)}:${Y(F)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(_,F)=>`wf-terminal:${J(_)}:${Y(F)}`,attribute:(_)=>`attr:${Y(_)}`,attributeIndex:(_,F,E)=>`idx:${_}:${F}:${Y(E)}`,tagIndex:(_,F)=>`tag:${Y(_)}:${Y(F)}`,updatePrefix:(_)=>`upd:${Y(_)}:`,update:(_,F)=>`upd:${Y(_)}:${F}`,updateResponse:(_)=>`upr:${_}`,updateIdempotency:(_,F)=>`upk:${Y(_)}:${F}`,startIdempotency:(_)=>`start-idem:${Y(_)}`,startIdempotencySignalId:(_)=>`start-idem:${_}`,livenessPrefix:()=>"liveness:",liveness:(_)=>`liveness:${Y(_)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",budget:(_,F,E)=>`budget:${_}:${F}:${E}`,review:(_,F)=>`review:${Y(_)}:${F}`,workflowHeaders:(_)=>`wf-headers:${Y(_)}`,childCancellationPrefix:(_)=>`child-cancel:${Y(_)}:`,childCancellation:(_,F)=>`child-cancel:${Y(_)}:${Y(F)}`,childWorkflowByParentPrefix:(_,F)=>`child-by-parent:${Y(_)}:${F===void 0?"":`${Y(F)}:`}`,childWorkflowByParent:(_,F,E)=>`child-by-parent:${Y(_)}:${F===void 0?"":`${Y(F)}:`}${Y(E)}`,terminalCleanupNeeded:(_)=>`wf-cleanup-needed:${Y(_)}`,workflowConcurrency:(_,F)=>`wf-concurrency:${Y(_)}:${Y(F)}`,workflowConcurrencyHolder:(_)=>`wf-concurrency-holder:${Y(_)}`,workflowHasServices:(_)=>`wf-has-services:${Y(_)}`,finalizerState:(_)=>`wf-finalizer-state:${Y(_)}`,teardownOwed:(_)=>`wf-teardown-needed:${Y(_)}`,teardownSucceeded:(_)=>`wf-teardown-succeeded:${Y(_)}`,teardownDeadLetter:(_)=>`wf-teardown-deadletter:${Y(_)}`,offload:(_,F)=>`offload:${Y(_)}:${F}`,archive:(_,F)=>`archive:${Y(_)}:${F}`,stateExecution:(_,F)=>`state:execution:${Y(_)}:${Y(F)}`,stateWorkflow:(_,F)=>`state:workflow-scope:${D}:${Y(_)}:${Y(F)}`,streamChunkPrefix:(_,F)=>`blob:${Y(_)}:${F}:chunk:`,streamChunk:(_,F,E)=>`blob:${Y(_)}:${F}:chunk:${String(E).padStart(10,"0")}`,streamTail:(_,F)=>`blob:${Y(_)}:${F}:tail`,streamMetadata:(_,F)=>`blob:${Y(_)}:${F}:meta`,budgetCharged:(_)=>`budget-charged:${_}`,toolEffect:(_,F,E)=>`tool-effect:${Y(_)}:${F}:${E}`,workflowVisibilityStatus:(_,F)=>`wf-idx-status:${Y(_)}:${Y(F)}`,workflowVisibilityType:(_,F)=>`wf-idx-type:${Y(_)}:${Y(F)}`,workflowVisibilityCreated:(_,F)=>`wf-idx-created:${J(_)}:${Y(F)}`,workflowVisibilityUpdated:(_,F)=>`wf-idx-updated:${J(_)}:${Y(F)}`,workflowVisibilityDeadline:(_,F)=>`wf-idx-deadline:${J(_)}:${Y(F)}`,workflowVisibilityManifest:(_)=>`wf-idx-manifest:${Y(_)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function k(_){if(_===void 0)return;if(typeof _!=="number"||!Number.isInteger(_)||_<0)throw Error("deleteRange limit must be a finite non-negative integer");return _===0?0:_}function H(_){let F={},E=!1;for(let U of["gt","gte","lt","lte"]){let G=_[U];if(G===void 0)continue;if(typeof G!=="string")throw Error("deleteRange bounds must be strings");F[U]=G,E=!0}if(!E)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let X=k(_.limit);if(X!==void 0)F.limit=X;return F}async function m(_,F,E){let X=H(E);if(_.deleteRange)return _.deleteRange(F,X);return C(_,F,X)}function q(_){return _.replaceAll(/:+$/g,"")}function l(_,F){let E=q(_),X=q(F);if(E.length===0)return X;if(X.length===0)return E;return`${E}:${X}`}class T{#_;#Y;constructor(_,F){this.#_=_,this.#Y=q(F)}#F(_){if(this.#Y.length===0)return _;return _.length===0?`${this.#Y}:`:`${this.#Y}:${_}`}#E(_){return _.map((F)=>{if(F.type==="put")return{type:"put",key:this.#F(F.key),value:F.value};return{type:"delete",key:this.#F(F.key)}})}#X(_){if(this.#Y.length===0)return _;return _.slice(this.#Y.length+1)}#U(_){let F={};if(_.limit!==void 0)F.limit=_.limit;if(_.gt!==void 0)F.gt=this.#F(_.gt);if(_.gte!==void 0)F.gte=this.#F(_.gte);if(_.lt!==void 0)F.lt=this.#F(_.lt);if(_.lte!==void 0)F.lte=this.#F(_.lte);return F}#G(_={}){let F=this.#U(_);if(_.reverse!==void 0)F.reverse=_.reverse;return F}#J(_){return this.#U(_)}capabilities(){return this.#_.capabilities()}scoped(_){return new T(this.#_,l(this.#Y,_))}async get(_){return this.#_.get(this.#F(_))}async put(_,F){await this.#_.put(this.#F(_),F)}async delete(_){await this.#_.delete(this.#F(_))}async*scan(_,F){for await(let[E,X]of this.#_.scan(this.#F(_),this.#G(F)))yield[this.#X(E),X]}async batch(_){Q("batch operations",_.length),await this.#_.batch(this.#E(_))}async conditionalBatch(_,F){return b(this.#_,_.map((E)=>({key:this.#F(E.key),expectedValue:E.expectedValue})),this.#E(F))}async has(_){return v(this.#_,this.#F(_))}async deletePrefix(_){return O(this.#_,this.#F(_))}async deleteRange(_,F){let E=this.#J(H(F));return m(this.#_,this.#F(_),E)}async*keys(_,F){for await(let E of h(this.#_,this.#F(_),this.#G(F)))yield this.#X(E)}async count(_){return P(this.#_,this.#F(_))}[Symbol.dispose](){this.#_[Symbol.dispose]()}}function c(_,F){return new T(_,F)}import*as u from"lmdb";class f{#_;#Y=!1;#F=null;constructor(_){this.#_=u.open({path:_,encoding:"binary"})}#E(){if(this.#Y)throw Error("LMDBStorage is closed")}capabilities(){return{persistence:"local",readAfterWrite:"linearizable",scanConsistency:"snapshot",atomicBatch:!0,conditionalBatch:!0,boundedRangeDelete:!1}}async get(_){this.#E();let F=this.#_.get(_);if(F===void 0)return null;return new Uint8Array(F)}async put(_,F){this.#E(),await this.#_.put(_,Buffer.from(F))}async delete(_){this.#E(),await this.#_.remove(_)}async has(_){return this.#E(),this.#_.doesExist(_)}async deletePrefix(_){this.#E();let F=[];for await(let E of this.keys(_))F.push(E);if(F.length===0)return 0;return await this.#_.batch(()=>{for(let E of F)this.#_.remove(E)}),F.length}async deleteRange(_,F){this.#E();let E=H(F),X=[];for await(let U of this.keys(_,E))X.push(U);if(X.length===0)return 0;return await this.#_.batch(()=>{for(let U of X)this.#_.remove(U)}),X.length}async*scan(_,F={}){this.#E();let{limit:E,reverse:X}=F,U=V(_),G=X?this.#_.getRange({start:U,end:_,reverse:!0}):this.#_.getRange({start:_,end:U}),Z=0,M=!1;for(let{key:$,value:y}of G){if(!$.startsWith(_)){if(X&&!M)continue;break}if(M=!0,!S($,F))continue;if(E!==void 0&&Z>=E)break;yield[$,new Uint8Array(y)],Z++}}async*keys(_,F={}){this.#E();let{limit:E,reverse:X}=F,U=V(_),G=X?this.#_.getKeys({start:U,end:_,reverse:!0}):this.#_.getKeys({start:_,end:U}),Z=0,M=!1;for(let $ of G){if(!$.startsWith(_)){if(X&&!M)continue;break}if(M=!0,!S($,F))continue;if(E!==void 0&&Z>=E)break;yield $,Z++}}async count(_){this.#E();let F=V(_);return this.#_.getKeysCount({start:_,end:F})}scoped(_){return this.#E(),c(this,_)}async batch(_){if(this.#E(),Q("batch operations",_.length),_.length===0)return;await this.#_.batch(()=>{for(let F of _)if(F.type==="put")this.#_.put(F.key,Buffer.from(F.value));else this.#_.remove(F.key)})}async conditionalBatch(_,F){return this.#E(),Q("conditionalBatch conditions",_.length),Q("conditionalBatch operations",F.length),this.#_.transactionSync(()=>{for(let X of _){let U=this.#_.get(X.key),G=U===void 0?null:new Uint8Array(U);if(!z(G,X.expectedValue))return!1}for(let X of F)if(X.type==="put")this.#_.putSync(X.key,Buffer.from(X.value));else this.#_.removeSync(X.key);return!0})}close(){return this.#Y=!0,this.#F??=(async()=>{await Promise.resolve(),await this.#_.close()})(),this.#F}[Symbol.dispose](){this.close()}}export{f as LMDBStorage};
2
+ var s=import.meta.require;function L(_,F,Y){if(!_.capabilities()[F])throw Error(`Feature "${Y}" requires storage capability "${F}", but this storage backend does not provide it.`)}function g(_){let F=_.capabilities(),Y=[];if(F.persistence!=="local"&&F.persistence!=="remote")Y.push(`persistence must be "local" or "remote" (got "${F.persistence}")`);if(F.readAfterWrite!=="linearizable")Y.push(`readAfterWrite must be "linearizable" (got "${F.readAfterWrite}")`);if(F.scanConsistency!=="snapshot")Y.push(`scanConsistency must be "snapshot" (got "${F.scanConsistency}")`);if(!F.atomicBatch)Y.push("atomicBatch must be true");if(!F.conditionalBatch)Y.push("conditionalBatch must be true");if(Y.length>0)throw Error(`Storage is not durable enough for recovery: ${Y.join("; ")}.`)}var N="default";async function D(_,F){return await _.get(F)!==null}async function*G(_,F,Y){for await(let[X]of _.scan(F,Y))yield X}async function R(_,F){let Y=0;for await(let X of G(_,F))Y++;return Y}async function A(_,F){let Y=[];for await(let X of G(_,F))Y.push({type:"delete",key:X});if(Y.length===0)return 0;return await _.batch(Y),Y.length}async function S(_,F,Y){let X=[];for await(let U of G(_,F,Y))X.push({type:"delete",key:U});if(X.length===0)return 0;return await _.batch(X),X.length}function E(_){return encodeURIComponent(_)}function I(_){return decodeURIComponent(_)}function w(_){try{return decodeURIComponent(_)}catch{return null}}var C={workflowOwnerEpoch:(_)=>`wf-owner-epoch:${E(_)}`,workflowOwnerHolder:(_)=>`wf-owner-holder:${E(_)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var k=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","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 q=1e4,Q_=1e4;class K extends Error{code="StorageBatchOperationLimitExceededError";cap=q;count;target;constructor(_,F){super(`${_} count ${F} exceeds MAX_BATCH_OPERATIONS (${q}).`);this.name="StorageBatchOperationLimitExceededError",this.target=_,this.count=F}}function Z(_,F){if(F>q)throw new K(_,F)}function V(_){return _.length>0?_.slice(0,-1)+String.fromCharCode(_.charCodeAt(_.length-1)+1):"\xFF"}function W(_,F={}){if(F.gt!==void 0&&_<=F.gt)return!1;if(F.gte!==void 0&&_<F.gte)return!1;if(F.lt!==void 0&&_>=F.lt)return!1;if(F.lte!==void 0&&_>F.lte)return!1;return!0}function P(_,F){if(_===null||F===null)return _===F;if(_.byteLength!==F.byteLength)return!1;for(let Y=0;Y<_.byteLength;Y++)if(_[Y]!==F[Y])return!1;return!0}async function v(_,F){if(_.has)return _.has(F);return D(_,F)}function O(_,F,Y){if(_.keys)return _.keys(F,Y);return G(_,F,Y)}async function h(_,F){if(_.count)return _.count(F);return R(_,F)}async function b(_,F){if(_.deletePrefix)return _.deletePrefix(F);return A(_,F)}async function Z_(_,F){Z("batch operations",F.length),await _.batch(F)}async function m(_,F,Y){if(Z("conditionalBatch conditions",F.length),Z("conditionalBatch operations",Y.length),L(_,"conditionalBatch","storageConditionalBatch"),!_.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return _.conditionalBatch(F,Y)}var M=(_)=>String(_).padStart(16,"0"),f="0",l="1",z=(_,F,Y,X)=>`sig:${E(_)}:${E(F)}:${X}:${E(Y)}`,$_={workflow:(_)=>`wf:${E(_)}`,checkpoint:(_)=>`wf:${E(_)}:ckpt`,checkpointHistory:(_,F)=>`wf:${E(_)}:ckpt:${String(F).padStart(10,"0")}`,timelinePrefix:(_)=>`wf:${E(_)}:timeline:`,timeline:(_,F)=>`wf:${E(_)}:timeline:${String(F).padStart(10,"0")}`,schedule:(_)=>`schedule:${E(_)}`,scheduleTick:(_,F)=>`schedule-due:${String(_).padStart(16,"0")}:${E(F)}`,scheduleRun:(_)=>`schedule-run:${E(_)}`,scheduleRunLink:(_)=>`schedule-run-link:${E(_)}`,scheduleRunBySchedulePrefix:(_)=>`schedule-run-by-schedule:${E(_)}:`,scheduleRunBySchedule:(_,F)=>`schedule-run-by-schedule:${E(_)}:${E(F)}`,operation:(_,F,Y)=>`op:${_}:${M(F)}:${Y}`,operationInflight:(_)=>`op:inflight:${_}`,operationQueued:(_)=>`op:queued:${_}`,operationResolved:(_)=>`op:resolved:${_}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(_,F,Y)=>`audit:bulk:${M(_)}:${E(F)}:${E(Y)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(_,F)=>`op:resolved-by-time:${M(_)}:${E(F)}`,asyncActivity:(_,F)=>`async-act:v1:${E(_)}:${E(F)}`,asyncActivityResolution:(_,F)=>`async-act:v1:${E(_)}:${E(F)}:resolution`,activityReconciliationPrefix:(_)=>`actrec:v1:${E(_)}:`,activityReconciliation:(_,F,Y)=>`actrec:v1:${E(_)}:${E(F)}:${Y}`,eventPrefix:(_)=>`ev:${E(_)}:`,event:(_,F)=>`ev:${E(_)}:${String(F).padStart(10,"0")}`,eventHead:(_)=>`ev:${E(_)}:head`,eventWatermark:(_)=>`ev:${E(_)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(_)=>`fleet-event:${String(_).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventByWorkflowPrefix:(_)=>`fleet-event-by-workflow:${E(_)}:`,fleetEventByWorkflow:(_,F)=>`fleet-event-by-workflow:${E(_)}:${String(F).padStart(10,"0")}`,signal:(_,F,Y)=>z(_,F,Y,l),startSignal:(_,F,Y)=>z(_,F,Y,f),signalSequence:(_)=>`sigseq:v1:${E(_)}`,signalAcceptedResponsePrefix:(_)=>`sigres:v1:${E(_)}:`,signalAcceptedResponse:(_,F,Y)=>`sigres:v1:${E(_)}:${E(F)}:${E(Y)}`,deadline:(_,F)=>`wf-deadline:${M(_)}:${E(F)}`,terminalCleanup:(_,F)=>`wf-cleanup:${M(_)}:${E(F)}`,teardownTimer:(_,F)=>`wf-teardown:${M(_)}:${E(F)}`,delayedStart:(_,F)=>`wf-delayed:${M(_)}:${E(F)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(_,F)=>`wf-terminal:${M(_)}:${E(F)}`,attribute:(_)=>`attr:${E(_)}`,attributeIndex:(_,F,Y)=>`idx:${_}:${F}:${E(Y)}`,tagIndex:(_,F)=>`tag:${E(_)}:${E(F)}`,updatePrefix:(_)=>`upd:${E(_)}:`,update:(_,F)=>`upd:${E(_)}:${F}`,updateResponse:(_)=>`upr:${_}`,updateIdempotency:(_,F)=>`upk:${E(_)}:${F}`,startIdempotency:(_)=>`start-idem:${E(_)}`,startIdempotencySignalId:(_)=>`start-idem:${_}`,livenessPrefix:()=>"liveness:",liveness:(_)=>`liveness:${E(_)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",...C,budget:(_,F,Y)=>`budget:${_}:${F}:${Y}`,review:(_,F)=>`review:${E(_)}:${F}`,workflowHeaders:(_)=>`wf-headers:${E(_)}`,childCancellationPrefix:(_)=>`child-cancel:${E(_)}:`,childCancellation:(_,F)=>`child-cancel:${E(_)}:${E(F)}`,childWorkflowByParentPrefix:(_,F)=>`child-by-parent:${E(_)}:${F===void 0?"":`${E(F)}:`}`,childWorkflowByParent:(_,F,Y)=>`child-by-parent:${E(_)}:${F===void 0?"":`${E(F)}:`}${E(Y)}`,terminalCleanupNeeded:(_)=>`wf-cleanup-needed:${E(_)}`,workflowConcurrency:(_,F)=>`wf-concurrency:${E(_)}:${E(F)}`,workflowConcurrencyHolder:(_)=>`wf-concurrency-holder:${E(_)}`,workflowHasServices:(_)=>`wf-has-services:${E(_)}`,finalizerState:(_)=>`wf-finalizer-state:${E(_)}`,teardownOwed:(_)=>`wf-teardown-needed:${E(_)}`,teardownSucceeded:(_)=>`wf-teardown-succeeded:${E(_)}`,teardownDeadLetter:(_)=>`wf-teardown-deadletter:${E(_)}`,offload:(_,F)=>`offload:${E(_)}:${F}`,archive:(_,F)=>`archive:${E(_)}:${F}`,stateExecution:(_,F)=>`state:execution:${E(_)}:${E(F)}`,stateWorkflow:(_,F)=>`state:workflow-scope:${N}:${E(_)}:${E(F)}`,streamChunkPrefix:(_,F)=>`blob:${E(_)}:${F}:chunk:`,streamChunk:(_,F,Y)=>`blob:${E(_)}:${F}:chunk:${String(Y).padStart(10,"0")}`,streamTail:(_,F)=>`blob:${E(_)}:${F}:tail`,streamMetadata:(_,F)=>`blob:${E(_)}:${F}:meta`,budgetCharged:(_)=>`budget-charged:${_}`,toolEffect:(_,F,Y)=>`tool-effect:${E(_)}:${F}:${Y}`,workflowVisibilityStatus:(_,F)=>`wf-idx-status:${E(_)}:${E(F)}`,workflowVisibilityType:(_,F)=>`wf-idx-type:${E(_)}:${E(F)}`,workflowVisibilityCreated:(_,F)=>`wf-idx-created:${M(_)}:${E(F)}`,workflowVisibilityUpdated:(_,F)=>`wf-idx-updated:${M(_)}:${E(F)}`,workflowVisibilityDeadline:(_,F)=>`wf-idx-deadline:${M(_)}:${E(F)}`,workflowVisibilityManifest:(_)=>`wf-idx-manifest:${E(_)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function d(_){if(_===void 0)return;if(typeof _!=="number"||!Number.isInteger(_)||_<0)throw Error("deleteRange limit must be a finite non-negative integer");return _===0?0:_}function H(_){let F={},Y=!1;for(let U of["gt","gte","lt","lte"]){let Q=_[U];if(Q===void 0)continue;if(typeof Q!=="string")throw Error("deleteRange bounds must be strings");F[U]=Q,Y=!0}if(!Y)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let X=d(_.limit);if(X!==void 0)F.limit=X;return F}async function c(_,F,Y){let X=H(Y);if(_.deleteRange)return _.deleteRange(F,X);return S(_,F,X)}function B(_){return _.replaceAll(/:+$/g,"")}function p(_,F){let Y=B(_),X=B(F);if(Y.length===0)return X;if(X.length===0)return Y;return`${Y}:${X}`}class T{#_;#Y;constructor(_,F){this.#_=_,this.#Y=B(F)}#F(_){if(this.#Y.length===0)return _;return _.length===0?`${this.#Y}:`:`${this.#Y}:${_}`}#E(_){return _.map((F)=>{if(F.type==="put")return{type:"put",key:this.#F(F.key),value:F.value};return{type:"delete",key:this.#F(F.key)}})}#X(_){if(this.#Y.length===0)return _;return _.slice(this.#Y.length+1)}#U(_){let F={};if(_.limit!==void 0)F.limit=_.limit;if(_.gt!==void 0)F.gt=this.#F(_.gt);if(_.gte!==void 0)F.gte=this.#F(_.gte);if(_.lt!==void 0)F.lt=this.#F(_.lt);if(_.lte!==void 0)F.lte=this.#F(_.lte);return F}#M(_={}){let F=this.#U(_);if(_.reverse!==void 0)F.reverse=_.reverse;return F}#Q(_){return this.#U(_)}capabilities(){return this.#_.capabilities()}scoped(_){return new T(this.#_,p(this.#Y,_))}async get(_){return this.#_.get(this.#F(_))}async put(_,F){await this.#_.put(this.#F(_),F)}async delete(_){await this.#_.delete(this.#F(_))}async*scan(_,F){for await(let[Y,X]of this.#_.scan(this.#F(_),this.#M(F)))yield[this.#X(Y),X]}async batch(_){Z("batch operations",_.length),await this.#_.batch(this.#E(_))}async conditionalBatch(_,F){return m(this.#_,_.map((Y)=>({key:this.#F(Y.key),expectedValue:Y.expectedValue})),this.#E(F))}async has(_){return v(this.#_,this.#F(_))}async deletePrefix(_){return b(this.#_,this.#F(_))}async deleteRange(_,F){let Y=this.#Q(H(F));return c(this.#_,this.#F(_),Y)}async*keys(_,F){for await(let Y of O(this.#_,this.#F(_),this.#M(F)))yield this.#X(Y)}async count(_){return h(this.#_,this.#F(_))}[Symbol.dispose](){this.#_[Symbol.dispose]()}}function u(_,F){return new T(_,F)}import*as x from"lmdb";class a{#_;#Y=!1;#F=null;constructor(_){this.#_=x.open({path:_,encoding:"binary"})}#E(){if(this.#Y)throw Error("LMDBStorage is closed")}capabilities(){return{persistence:"local",readAfterWrite:"linearizable",scanConsistency:"snapshot",atomicBatch:!0,conditionalBatch:!0,boundedRangeDelete:!1}}async get(_){this.#E();let F=this.#_.get(_);if(F===void 0)return null;return new Uint8Array(F)}async put(_,F){this.#E(),await this.#_.put(_,Buffer.from(F))}async delete(_){this.#E(),await this.#_.remove(_)}async has(_){return this.#E(),this.#_.doesExist(_)}async deletePrefix(_){this.#E();let F=[];for await(let Y of this.keys(_))F.push(Y);if(F.length===0)return 0;return await this.#_.batch(()=>{for(let Y of F)this.#_.remove(Y)}),F.length}async deleteRange(_,F){this.#E();let Y=H(F),X=[];for await(let U of this.keys(_,Y))X.push(U);if(X.length===0)return 0;return await this.#_.batch(()=>{for(let U of X)this.#_.remove(U)}),X.length}async*scan(_,F={}){this.#E();let{limit:Y,reverse:X}=F,U=V(_),Q=X?this.#_.getRange({start:U,end:_,reverse:!0}):this.#_.getRange({start:_,end:U}),J=0,j=!1;for(let{key:$,value:y}of Q){if(!$.startsWith(_)){if(X&&!j)continue;break}if(j=!0,!W($,F))continue;if(Y!==void 0&&J>=Y)break;yield[$,new Uint8Array(y)],J++}}async*keys(_,F={}){this.#E();let{limit:Y,reverse:X}=F,U=V(_),Q=X?this.#_.getKeys({start:U,end:_,reverse:!0}):this.#_.getKeys({start:_,end:U}),J=0,j=!1;for(let $ of Q){if(!$.startsWith(_)){if(X&&!j)continue;break}if(j=!0,!W($,F))continue;if(Y!==void 0&&J>=Y)break;yield $,J++}}async count(_){this.#E();let F=V(_);return this.#_.getKeysCount({start:_,end:F})}scoped(_){return this.#E(),u(this,_)}async batch(_){if(this.#E(),Z("batch operations",_.length),_.length===0)return;await this.#_.batch(()=>{for(let F of _)if(F.type==="put")this.#_.put(F.key,Buffer.from(F.value));else this.#_.remove(F.key)})}async conditionalBatch(_,F){return this.#E(),Z("conditionalBatch conditions",_.length),Z("conditionalBatch operations",F.length),this.#_.transactionSync(()=>{for(let X of _){let U=this.#_.get(X.key),Q=U===void 0?null:new Uint8Array(U);if(!P(Q,X.expectedValue))return!1}for(let X of F)if(X.type==="put")this.#_.putSync(X.key,Buffer.from(X.value));else this.#_.removeSync(X.key);return!0})}close(){return this.#Y=!0,this.#F??=(async()=>{await Promise.resolve(),await this.#_.close()})(),this.#F}[Symbol.dispose](){this.close()}}export{a as LMDBStorage};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- var k=import.meta.require,l=(_,F,Y)=>{if(F!=null){if(typeof F!=="object"&&typeof F!=="function")throw TypeError('Object expected to be assigned to "using" declaration');let E;if(Y)E=F[Symbol.asyncDispose];if(E===void 0)E=F[Symbol.dispose];if(typeof E!=="function")throw TypeError("Object not disposable");_.push([Y,E,F])}else if(Y)_.push([Y]);return F},d=(_,F,Y)=>{let E=(U)=>F=Y?new SuppressedError(U,F,"An error was suppressed during disposal"):(Y=!0,U),G=(U)=>{while(U=_.pop())try{var M=U[1]&&U[1].call(U[2]);if(U[0])return Promise.resolve(M).then(G,(J)=>(E(J),G()))}catch(J){E(J)}if(Y)throw F};return G()};function L(_,F,Y){if(!_.capabilities()[F])throw Error(`Feature "${Y}" requires storage capability "${F}", but this storage backend does not provide it.`)}function u(_){let F=_.capabilities(),Y=[];if(F.persistence!=="local"&&F.persistence!=="remote")Y.push(`persistence must be "local" or "remote" (got "${F.persistence}")`);if(F.readAfterWrite!=="linearizable")Y.push(`readAfterWrite must be "linearizable" (got "${F.readAfterWrite}")`);if(F.scanConsistency!=="snapshot")Y.push(`scanConsistency must be "snapshot" (got "${F.scanConsistency}")`);if(!F.atomicBatch)Y.push("atomicBatch must be true");if(!F.conditionalBatch)Y.push("conditionalBatch must be true");if(Y.length>0)throw Error(`Storage is not durable enough for recovery: ${Y.join("; ")}.`)}var D="default";async function C(_,F){return await _.get(F)!==null}async function*V(_,F,Y){for await(let[E]of _.scan(F,Y))yield E}async function B(_,F){let Y=0;for await(let E of V(_,F))Y++;return Y}async function R(_,F){let Y=[];for await(let E of V(_,F))Y.push({type:"delete",key:E});if(Y.length===0)return 0;return await _.batch(Y),Y.length}async function A(_,F,Y){let E=[];for await(let G of V(_,F,Y))E.push({type:"delete",key:G});if(E.length===0)return 0;return await _.batch(E),E.length}var x=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","idx:","lease:","liveness:","offload:","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-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var N=1e4,o=1e4;class z extends Error{code="StorageBatchOperationLimitExceededError";cap=N;count;target;constructor(_,F){super(`${_} count ${F} exceeds MAX_BATCH_OPERATIONS (${N}).`);this.name="StorageBatchOperationLimitExceededError",this.target=_,this.count=F}}function Z(_,F){if(F>N)throw new z(_,F)}function $(_){return _.length>0?_.slice(0,-1)+String.fromCharCode(_.charCodeAt(_.length-1)+1):"\xFF"}function H(_,F={}){if(F.gt!==void 0&&_<=F.gt)return!1;if(F.gte!==void 0&&_<F.gte)return!1;if(F.lt!==void 0&&_>=F.lt)return!1;if(F.lte!==void 0&&_>F.lte)return!1;return!0}function K(_,F){if(_===null||F===null)return _===F;if(_.byteLength!==F.byteLength)return!1;for(let Y=0;Y<_.byteLength;Y++)if(_[Y]!==F[Y])return!1;return!0}async function P(_,F){if(_.has)return _.has(F);return C(_,F)}function v(_,F,Y){if(_.keys)return _.keys(F,Y);return V(_,F,Y)}async function O(_,F){if(_.count)return _.count(F);return B(_,F)}async function h(_,F){if(_.deletePrefix)return _.deletePrefix(F);return R(_,F)}async function __(_,F){Z("batch operations",F.length),await _.batch(F)}async function b(_,F,Y){if(Z("conditionalBatch conditions",F.length),Z("conditionalBatch operations",Y.length),L(_,"conditionalBatch","storageConditionalBatch"),!_.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return _.conditionalBatch(F,Y)}function X(_){return encodeURIComponent(_)}function F_(_){return decodeURIComponent(_)}function Y_(_){try{return decodeURIComponent(_)}catch{return null}}var Q=(_)=>String(_).padStart(16,"0"),g="0",y="1",S=(_,F,Y,E)=>`sig:${X(_)}:${X(F)}:${E}:${X(Y)}`,X_={workflow:(_)=>`wf:${X(_)}`,checkpoint:(_)=>`wf:${X(_)}:ckpt`,checkpointHistory:(_,F)=>`wf:${X(_)}:ckpt:${String(F).padStart(10,"0")}`,timelinePrefix:(_)=>`wf:${X(_)}:timeline:`,timeline:(_,F)=>`wf:${X(_)}:timeline:${String(F).padStart(10,"0")}`,schedule:(_)=>`schedule:${X(_)}`,scheduleTick:(_,F)=>`schedule-due:${String(_).padStart(16,"0")}:${X(F)}`,scheduleRun:(_)=>`schedule-run:${X(_)}`,scheduleRunLink:(_)=>`schedule-run-link:${X(_)}`,scheduleRunBySchedulePrefix:(_)=>`schedule-run-by-schedule:${X(_)}:`,scheduleRunBySchedule:(_,F)=>`schedule-run-by-schedule:${X(_)}:${X(F)}`,operation:(_,F,Y)=>`op:${_}:${Q(F)}:${Y}`,operationInflight:(_)=>`op:inflight:${_}`,operationQueued:(_)=>`op:queued:${_}`,operationResolved:(_)=>`op:resolved:${_}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(_,F,Y)=>`audit:bulk:${Q(_)}:${X(F)}:${X(Y)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(_,F)=>`op:resolved-by-time:${Q(_)}:${X(F)}`,asyncActivity:(_,F)=>`async-act:v1:${X(_)}:${X(F)}`,asyncActivityResolution:(_,F)=>`async-act:v1:${X(_)}:${X(F)}:resolution`,activityReconciliationPrefix:(_)=>`actrec:v1:${X(_)}:`,activityReconciliation:(_,F,Y)=>`actrec:v1:${X(_)}:${X(F)}:${Y}`,eventPrefix:(_)=>`ev:${X(_)}:`,event:(_,F)=>`ev:${X(_)}:${String(F).padStart(10,"0")}`,eventHead:(_)=>`ev:${X(_)}:head`,eventWatermark:(_)=>`ev:${X(_)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(_)=>`fleet-event:${String(_).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventByWorkflowPrefix:(_)=>`fleet-event-by-workflow:${X(_)}:`,fleetEventByWorkflow:(_,F)=>`fleet-event-by-workflow:${X(_)}:${String(F).padStart(10,"0")}`,signal:(_,F,Y)=>S(_,F,Y,y),startSignal:(_,F,Y)=>S(_,F,Y,g),signalSequence:(_)=>`sigseq:v1:${X(_)}`,signalAcceptedResponsePrefix:(_)=>`sigres:v1:${X(_)}:`,signalAcceptedResponse:(_,F,Y)=>`sigres:v1:${X(_)}:${X(F)}:${X(Y)}`,deadline:(_,F)=>`wf-deadline:${Q(_)}:${X(F)}`,terminalCleanup:(_,F)=>`wf-cleanup:${Q(_)}:${X(F)}`,teardownTimer:(_,F)=>`wf-teardown:${Q(_)}:${X(F)}`,delayedStart:(_,F)=>`wf-delayed:${Q(_)}:${X(F)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(_,F)=>`wf-terminal:${Q(_)}:${X(F)}`,attribute:(_)=>`attr:${X(_)}`,attributeIndex:(_,F,Y)=>`idx:${_}:${F}:${X(Y)}`,tagIndex:(_,F)=>`tag:${X(_)}:${X(F)}`,updatePrefix:(_)=>`upd:${X(_)}:`,update:(_,F)=>`upd:${X(_)}:${F}`,updateResponse:(_)=>`upr:${_}`,updateIdempotency:(_,F)=>`upk:${X(_)}:${F}`,startIdempotency:(_)=>`start-idem:${X(_)}`,startIdempotencySignalId:(_)=>`start-idem:${_}`,livenessPrefix:()=>"liveness:",liveness:(_)=>`liveness:${X(_)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",budget:(_,F,Y)=>`budget:${_}:${F}:${Y}`,review:(_,F)=>`review:${X(_)}:${F}`,workflowHeaders:(_)=>`wf-headers:${X(_)}`,childCancellationPrefix:(_)=>`child-cancel:${X(_)}:`,childCancellation:(_,F)=>`child-cancel:${X(_)}:${X(F)}`,childWorkflowByParentPrefix:(_,F)=>`child-by-parent:${X(_)}:${F===void 0?"":`${X(F)}:`}`,childWorkflowByParent:(_,F,Y)=>`child-by-parent:${X(_)}:${F===void 0?"":`${X(F)}:`}${X(Y)}`,terminalCleanupNeeded:(_)=>`wf-cleanup-needed:${X(_)}`,workflowConcurrency:(_,F)=>`wf-concurrency:${X(_)}:${X(F)}`,workflowConcurrencyHolder:(_)=>`wf-concurrency-holder:${X(_)}`,workflowHasServices:(_)=>`wf-has-services:${X(_)}`,finalizerState:(_)=>`wf-finalizer-state:${X(_)}`,teardownOwed:(_)=>`wf-teardown-needed:${X(_)}`,teardownSucceeded:(_)=>`wf-teardown-succeeded:${X(_)}`,teardownDeadLetter:(_)=>`wf-teardown-deadletter:${X(_)}`,offload:(_,F)=>`offload:${X(_)}:${F}`,archive:(_,F)=>`archive:${X(_)}:${F}`,stateExecution:(_,F)=>`state:execution:${X(_)}:${X(F)}`,stateWorkflow:(_,F)=>`state:workflow-scope:${D}:${X(_)}:${X(F)}`,streamChunkPrefix:(_,F)=>`blob:${X(_)}:${F}:chunk:`,streamChunk:(_,F,Y)=>`blob:${X(_)}:${F}:chunk:${String(Y).padStart(10,"0")}`,streamTail:(_,F)=>`blob:${X(_)}:${F}:tail`,streamMetadata:(_,F)=>`blob:${X(_)}:${F}:meta`,budgetCharged:(_)=>`budget-charged:${_}`,toolEffect:(_,F,Y)=>`tool-effect:${X(_)}:${F}:${Y}`,workflowVisibilityStatus:(_,F)=>`wf-idx-status:${X(_)}:${X(F)}`,workflowVisibilityType:(_,F)=>`wf-idx-type:${X(_)}:${X(F)}`,workflowVisibilityCreated:(_,F)=>`wf-idx-created:${Q(_)}:${X(F)}`,workflowVisibilityUpdated:(_,F)=>`wf-idx-updated:${Q(_)}:${X(F)}`,workflowVisibilityDeadline:(_,F)=>`wf-idx-deadline:${Q(_)}:${X(F)}`,workflowVisibilityManifest:(_)=>`wf-idx-manifest:${X(_)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function I(_){if(_===void 0)return;if(typeof _!=="number"||!Number.isInteger(_)||_<0)throw Error("deleteRange limit must be a finite non-negative integer");return _===0?0:_}function j(_){let F={},Y=!1;for(let G of["gt","gte","lt","lte"]){let U=_[G];if(U===void 0)continue;if(typeof U!=="string")throw Error("deleteRange bounds must be strings");F[G]=U,Y=!0}if(!Y)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let E=I(_.limit);if(E!==void 0)F.limit=E;return F}async function m(_,F,Y){let E=j(Y);if(_.deleteRange)return _.deleteRange(F,E);return A(_,F,E)}function q(_){return _.replaceAll(/:+$/g,"")}function w(_,F){let Y=q(_),E=q(F);if(Y.length===0)return E;if(E.length===0)return Y;return`${Y}:${E}`}class T{#_;#Y;constructor(_,F){this.#_=_,this.#Y=q(F)}#F(_){if(this.#Y.length===0)return _;return _.length===0?`${this.#Y}:`:`${this.#Y}:${_}`}#X(_){return _.map((F)=>{if(F.type==="put")return{type:"put",key:this.#F(F.key),value:F.value};return{type:"delete",key:this.#F(F.key)}})}#E(_){if(this.#Y.length===0)return _;return _.slice(this.#Y.length+1)}#U(_){let F={};if(_.limit!==void 0)F.limit=_.limit;if(_.gt!==void 0)F.gt=this.#F(_.gt);if(_.gte!==void 0)F.gte=this.#F(_.gte);if(_.lt!==void 0)F.lt=this.#F(_.lt);if(_.lte!==void 0)F.lte=this.#F(_.lte);return F}#G(_={}){let F=this.#U(_);if(_.reverse!==void 0)F.reverse=_.reverse;return F}#J(_){return this.#U(_)}capabilities(){return this.#_.capabilities()}scoped(_){return new T(this.#_,w(this.#Y,_))}async get(_){return this.#_.get(this.#F(_))}async put(_,F){await this.#_.put(this.#F(_),F)}async delete(_){await this.#_.delete(this.#F(_))}async*scan(_,F){for await(let[Y,E]of this.#_.scan(this.#F(_),this.#G(F)))yield[this.#E(Y),E]}async batch(_){Z("batch operations",_.length),await this.#_.batch(this.#X(_))}async conditionalBatch(_,F){return b(this.#_,_.map((Y)=>({key:this.#F(Y.key),expectedValue:Y.expectedValue})),this.#X(F))}async has(_){return P(this.#_,this.#F(_))}async deletePrefix(_){return h(this.#_,this.#F(_))}async deleteRange(_,F){let Y=this.#J(j(F));return m(this.#_,this.#F(_),Y)}async*keys(_,F){for await(let Y of v(this.#_,this.#F(_),this.#G(F)))yield this.#E(Y)}async count(_){return O(this.#_,this.#F(_))}[Symbol.dispose](){this.#_[Symbol.dispose]()}}function c(_,F){return new T(_,F)}class f{#_;constructor(){this.#_=new Map}capabilities(){return{persistence:"ephemeral",readAfterWrite:"linearizable",scanConsistency:"snapshot",atomicBatch:!0,conditionalBatch:!0,boundedRangeDelete:!0}}#Y(_,F,Y){return _>=F&&_<Y}#F(_,F){let Y=[];for(let E of this.#_.keys())if(this.#Y(E,_,F))Y.push(E);return Y.toSorted()}async get(_){return this.#_.get(_)??null}async put(_,F){this.#_.set(_,F)}async delete(_){this.#_.delete(_)}async*scan(_,F={}){let{limit:Y,reverse:E}=F,G=$(_),U=this.#F(_,G);if(U=U.filter((J)=>H(J,F)),E)U.reverse();let M=0;for(let J of U){if(Y!==void 0&&M>=Y)break;let W=this.#_.get(J);if(W!==void 0)yield[J,W],M++}}async batch(_){Z("batch operations",_.length),this.#X(_)}#X(_){for(let F of _)if(F.type==="put")this.#_.set(F.key,F.value);else this.#_.delete(F.key)}async conditionalBatch(_,F){Z("conditionalBatch conditions",_.length),Z("conditionalBatch operations",F.length);for(let Y of _){let E=this.#_.get(Y.key)??null;if(!K(E,Y.expectedValue))return!1}return this.#X(F),!0}async has(_){return this.#_.has(_)}async deletePrefix(_){let F=$(_),Y=this.#F(_,F);for(let E of Y)this.#_.delete(E);return Y.length}async deleteRange(_,F){let Y=j(F),E=$(_),G=this.#F(_,E).filter((M)=>H(M,Y)),U=Y.limit===void 0?G:G.slice(0,Y.limit);for(let M of U)this.#_.delete(M);return U.length}async*keys(_,F={}){let{limit:Y,reverse:E}=F,G=$(_),U=this.#F(_,G);if(U=U.filter((J)=>H(J,F)),E)U.reverse();let M=0;for(let J of U){if(Y!==void 0&&M>=Y)break;yield J,M++}}async count(_){let F=$(_);return this.#F(_,F).length}scoped(_){return c(this,_)}get size(){return this.#_.size}clear(){this.#_.clear()}snapshot(){let _=new Map;for(let[F,Y]of this.#_)_.set(F,new Uint8Array(Y));return _}[Symbol.dispose](){this.#_.clear()}}export{f as MemoryStorage};
2
+ var p=import.meta.require;function L(_,F,Y){if(!_.capabilities()[F])throw Error(`Feature "${Y}" requires storage capability "${F}", but this storage backend does not provide it.`)}function x(_){let F=_.capabilities(),Y=[];if(F.persistence!=="local"&&F.persistence!=="remote")Y.push(`persistence must be "local" or "remote" (got "${F.persistence}")`);if(F.readAfterWrite!=="linearizable")Y.push(`readAfterWrite must be "linearizable" (got "${F.readAfterWrite}")`);if(F.scanConsistency!=="snapshot")Y.push(`scanConsistency must be "snapshot" (got "${F.scanConsistency}")`);if(!F.atomicBatch)Y.push("atomicBatch must be true");if(!F.conditionalBatch)Y.push("conditionalBatch must be true");if(Y.length>0)throw Error(`Storage is not durable enough for recovery: ${Y.join("; ")}.`)}var N="default";async function B(_,F){return await _.get(F)!==null}async function*j(_,F,Y){for await(let[E]of _.scan(F,Y))yield E}async function R(_,F){let Y=0;for await(let E of j(_,F))Y++;return Y}async function A(_,F){let Y=[];for await(let E of j(_,F))Y.push({type:"delete",key:E});if(Y.length===0)return 0;return await _.batch(Y),Y.length}async function C(_,F,Y){let E=[];for await(let M of j(_,F,Y))E.push({type:"delete",key:M});if(E.length===0)return 0;return await _.batch(E),E.length}function X(_){return encodeURIComponent(_)}function g(_){return decodeURIComponent(_)}function y(_){try{return decodeURIComponent(_)}catch{return null}}var z={workflowOwnerEpoch:(_)=>`wf-owner-epoch:${X(_)}`,workflowOwnerHolder:(_)=>`wf-owner-holder:${X(_)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var I=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","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 q=1e4,U_=1e4;class P extends Error{code="StorageBatchOperationLimitExceededError";cap=q;count;target;constructor(_,F){super(`${_} count ${F} exceeds MAX_BATCH_OPERATIONS (${q}).`);this.name="StorageBatchOperationLimitExceededError",this.target=_,this.count=F}}function $(_,F){if(F>q)throw new P(_,F)}function V(_){return _.length>0?_.slice(0,-1)+String.fromCharCode(_.charCodeAt(_.length-1)+1):"\xFF"}function H(_,F={}){if(F.gt!==void 0&&_<=F.gt)return!1;if(F.gte!==void 0&&_<F.gte)return!1;if(F.lt!==void 0&&_>=F.lt)return!1;if(F.lte!==void 0&&_>F.lte)return!1;return!0}function O(_,F){if(_===null||F===null)return _===F;if(_.byteLength!==F.byteLength)return!1;for(let Y=0;Y<_.byteLength;Y++)if(_[Y]!==F[Y])return!1;return!0}async function v(_,F){if(_.has)return _.has(F);return B(_,F)}function K(_,F,Y){if(_.keys)return _.keys(F,Y);return j(_,F,Y)}async function b(_,F){if(_.count)return _.count(F);return R(_,F)}async function h(_,F){if(_.deletePrefix)return _.deletePrefix(F);return A(_,F)}async function M_(_,F){$("batch operations",F.length),await _.batch(F)}async function m(_,F,Y){if($("conditionalBatch conditions",F.length),$("conditionalBatch operations",Y.length),L(_,"conditionalBatch","storageConditionalBatch"),!_.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return _.conditionalBatch(F,Y)}var Q=(_)=>String(_).padStart(16,"0"),w="0",f="1",S=(_,F,Y,E)=>`sig:${X(_)}:${X(F)}:${E}:${X(Y)}`,Q_={workflow:(_)=>`wf:${X(_)}`,checkpoint:(_)=>`wf:${X(_)}:ckpt`,checkpointHistory:(_,F)=>`wf:${X(_)}:ckpt:${String(F).padStart(10,"0")}`,timelinePrefix:(_)=>`wf:${X(_)}:timeline:`,timeline:(_,F)=>`wf:${X(_)}:timeline:${String(F).padStart(10,"0")}`,schedule:(_)=>`schedule:${X(_)}`,scheduleTick:(_,F)=>`schedule-due:${String(_).padStart(16,"0")}:${X(F)}`,scheduleRun:(_)=>`schedule-run:${X(_)}`,scheduleRunLink:(_)=>`schedule-run-link:${X(_)}`,scheduleRunBySchedulePrefix:(_)=>`schedule-run-by-schedule:${X(_)}:`,scheduleRunBySchedule:(_,F)=>`schedule-run-by-schedule:${X(_)}:${X(F)}`,operation:(_,F,Y)=>`op:${_}:${Q(F)}:${Y}`,operationInflight:(_)=>`op:inflight:${_}`,operationQueued:(_)=>`op:queued:${_}`,operationResolved:(_)=>`op:resolved:${_}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(_,F,Y)=>`audit:bulk:${Q(_)}:${X(F)}:${X(Y)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(_,F)=>`op:resolved-by-time:${Q(_)}:${X(F)}`,asyncActivity:(_,F)=>`async-act:v1:${X(_)}:${X(F)}`,asyncActivityResolution:(_,F)=>`async-act:v1:${X(_)}:${X(F)}:resolution`,activityReconciliationPrefix:(_)=>`actrec:v1:${X(_)}:`,activityReconciliation:(_,F,Y)=>`actrec:v1:${X(_)}:${X(F)}:${Y}`,eventPrefix:(_)=>`ev:${X(_)}:`,event:(_,F)=>`ev:${X(_)}:${String(F).padStart(10,"0")}`,eventHead:(_)=>`ev:${X(_)}:head`,eventWatermark:(_)=>`ev:${X(_)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(_)=>`fleet-event:${String(_).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventByWorkflowPrefix:(_)=>`fleet-event-by-workflow:${X(_)}:`,fleetEventByWorkflow:(_,F)=>`fleet-event-by-workflow:${X(_)}:${String(F).padStart(10,"0")}`,signal:(_,F,Y)=>S(_,F,Y,f),startSignal:(_,F,Y)=>S(_,F,Y,w),signalSequence:(_)=>`sigseq:v1:${X(_)}`,signalAcceptedResponsePrefix:(_)=>`sigres:v1:${X(_)}:`,signalAcceptedResponse:(_,F,Y)=>`sigres:v1:${X(_)}:${X(F)}:${X(Y)}`,deadline:(_,F)=>`wf-deadline:${Q(_)}:${X(F)}`,terminalCleanup:(_,F)=>`wf-cleanup:${Q(_)}:${X(F)}`,teardownTimer:(_,F)=>`wf-teardown:${Q(_)}:${X(F)}`,delayedStart:(_,F)=>`wf-delayed:${Q(_)}:${X(F)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(_,F)=>`wf-terminal:${Q(_)}:${X(F)}`,attribute:(_)=>`attr:${X(_)}`,attributeIndex:(_,F,Y)=>`idx:${_}:${F}:${X(Y)}`,tagIndex:(_,F)=>`tag:${X(_)}:${X(F)}`,updatePrefix:(_)=>`upd:${X(_)}:`,update:(_,F)=>`upd:${X(_)}:${F}`,updateResponse:(_)=>`upr:${_}`,updateIdempotency:(_,F)=>`upk:${X(_)}:${F}`,startIdempotency:(_)=>`start-idem:${X(_)}`,startIdempotencySignalId:(_)=>`start-idem:${_}`,livenessPrefix:()=>"liveness:",liveness:(_)=>`liveness:${X(_)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",...z,budget:(_,F,Y)=>`budget:${_}:${F}:${Y}`,review:(_,F)=>`review:${X(_)}:${F}`,workflowHeaders:(_)=>`wf-headers:${X(_)}`,childCancellationPrefix:(_)=>`child-cancel:${X(_)}:`,childCancellation:(_,F)=>`child-cancel:${X(_)}:${X(F)}`,childWorkflowByParentPrefix:(_,F)=>`child-by-parent:${X(_)}:${F===void 0?"":`${X(F)}:`}`,childWorkflowByParent:(_,F,Y)=>`child-by-parent:${X(_)}:${F===void 0?"":`${X(F)}:`}${X(Y)}`,terminalCleanupNeeded:(_)=>`wf-cleanup-needed:${X(_)}`,workflowConcurrency:(_,F)=>`wf-concurrency:${X(_)}:${X(F)}`,workflowConcurrencyHolder:(_)=>`wf-concurrency-holder:${X(_)}`,workflowHasServices:(_)=>`wf-has-services:${X(_)}`,finalizerState:(_)=>`wf-finalizer-state:${X(_)}`,teardownOwed:(_)=>`wf-teardown-needed:${X(_)}`,teardownSucceeded:(_)=>`wf-teardown-succeeded:${X(_)}`,teardownDeadLetter:(_)=>`wf-teardown-deadletter:${X(_)}`,offload:(_,F)=>`offload:${X(_)}:${F}`,archive:(_,F)=>`archive:${X(_)}:${F}`,stateExecution:(_,F)=>`state:execution:${X(_)}:${X(F)}`,stateWorkflow:(_,F)=>`state:workflow-scope:${N}:${X(_)}:${X(F)}`,streamChunkPrefix:(_,F)=>`blob:${X(_)}:${F}:chunk:`,streamChunk:(_,F,Y)=>`blob:${X(_)}:${F}:chunk:${String(Y).padStart(10,"0")}`,streamTail:(_,F)=>`blob:${X(_)}:${F}:tail`,streamMetadata:(_,F)=>`blob:${X(_)}:${F}:meta`,budgetCharged:(_)=>`budget-charged:${_}`,toolEffect:(_,F,Y)=>`tool-effect:${X(_)}:${F}:${Y}`,workflowVisibilityStatus:(_,F)=>`wf-idx-status:${X(_)}:${X(F)}`,workflowVisibilityType:(_,F)=>`wf-idx-type:${X(_)}:${X(F)}`,workflowVisibilityCreated:(_,F)=>`wf-idx-created:${Q(_)}:${X(F)}`,workflowVisibilityUpdated:(_,F)=>`wf-idx-updated:${Q(_)}:${X(F)}`,workflowVisibilityDeadline:(_,F)=>`wf-idx-deadline:${Q(_)}:${X(F)}`,workflowVisibilityManifest:(_)=>`wf-idx-manifest:${X(_)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function k(_){if(_===void 0)return;if(typeof _!=="number"||!Number.isInteger(_)||_<0)throw Error("deleteRange limit must be a finite non-negative integer");return _===0?0:_}function G(_){let F={},Y=!1;for(let M of["gt","gte","lt","lte"]){let U=_[M];if(U===void 0)continue;if(typeof U!=="string")throw Error("deleteRange bounds must be strings");F[M]=U,Y=!0}if(!Y)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let E=k(_.limit);if(E!==void 0)F.limit=E;return F}async function u(_,F,Y){let E=G(Y);if(_.deleteRange)return _.deleteRange(F,E);return C(_,F,E)}function W(_){return _.replaceAll(/:+$/g,"")}function l(_,F){let Y=W(_),E=W(F);if(Y.length===0)return E;if(E.length===0)return Y;return`${Y}:${E}`}class T{#_;#Y;constructor(_,F){this.#_=_,this.#Y=W(F)}#F(_){if(this.#Y.length===0)return _;return _.length===0?`${this.#Y}:`:`${this.#Y}:${_}`}#X(_){return _.map((F)=>{if(F.type==="put")return{type:"put",key:this.#F(F.key),value:F.value};return{type:"delete",key:this.#F(F.key)}})}#E(_){if(this.#Y.length===0)return _;return _.slice(this.#Y.length+1)}#U(_){let F={};if(_.limit!==void 0)F.limit=_.limit;if(_.gt!==void 0)F.gt=this.#F(_.gt);if(_.gte!==void 0)F.gte=this.#F(_.gte);if(_.lt!==void 0)F.lt=this.#F(_.lt);if(_.lte!==void 0)F.lte=this.#F(_.lte);return F}#M(_={}){let F=this.#U(_);if(_.reverse!==void 0)F.reverse=_.reverse;return F}#Q(_){return this.#U(_)}capabilities(){return this.#_.capabilities()}scoped(_){return new T(this.#_,l(this.#Y,_))}async get(_){return this.#_.get(this.#F(_))}async put(_,F){await this.#_.put(this.#F(_),F)}async delete(_){await this.#_.delete(this.#F(_))}async*scan(_,F){for await(let[Y,E]of this.#_.scan(this.#F(_),this.#M(F)))yield[this.#E(Y),E]}async batch(_){$("batch operations",_.length),await this.#_.batch(this.#X(_))}async conditionalBatch(_,F){return m(this.#_,_.map((Y)=>({key:this.#F(Y.key),expectedValue:Y.expectedValue})),this.#X(F))}async has(_){return v(this.#_,this.#F(_))}async deletePrefix(_){return h(this.#_,this.#F(_))}async deleteRange(_,F){let Y=this.#Q(G(F));return u(this.#_,this.#F(_),Y)}async*keys(_,F){for await(let Y of K(this.#_,this.#F(_),this.#M(F)))yield this.#E(Y)}async count(_){return b(this.#_,this.#F(_))}[Symbol.dispose](){this.#_[Symbol.dispose]()}}function c(_,F){return new T(_,F)}class d{#_;constructor(){this.#_=new Map}capabilities(){return{persistence:"ephemeral",readAfterWrite:"linearizable",scanConsistency:"snapshot",atomicBatch:!0,conditionalBatch:!0,boundedRangeDelete:!0}}#Y(_,F,Y){return _>=F&&_<Y}#F(_,F){let Y=[];for(let E of this.#_.keys())if(this.#Y(E,_,F))Y.push(E);return Y.toSorted()}async get(_){return this.#_.get(_)??null}async put(_,F){this.#_.set(_,F)}async delete(_){this.#_.delete(_)}async*scan(_,F={}){let{limit:Y,reverse:E}=F,M=V(_),U=this.#F(_,M);if(U=U.filter((J)=>H(J,F)),E)U.reverse();let Z=0;for(let J of U){if(Y!==void 0&&Z>=Y)break;let D=this.#_.get(J);if(D!==void 0)yield[J,D],Z++}}async batch(_){$("batch operations",_.length),this.#X(_)}#X(_){for(let F of _)if(F.type==="put")this.#_.set(F.key,F.value);else this.#_.delete(F.key)}async conditionalBatch(_,F){$("conditionalBatch conditions",_.length),$("conditionalBatch operations",F.length);for(let Y of _){let E=this.#_.get(Y.key)??null;if(!O(E,Y.expectedValue))return!1}return this.#X(F),!0}async has(_){return this.#_.has(_)}async deletePrefix(_){let F=V(_),Y=this.#F(_,F);for(let E of Y)this.#_.delete(E);return Y.length}async deleteRange(_,F){let Y=G(F),E=V(_),M=this.#F(_,E).filter((Z)=>H(Z,Y)),U=Y.limit===void 0?M:M.slice(0,Y.limit);for(let Z of U)this.#_.delete(Z);return U.length}async*keys(_,F={}){let{limit:Y,reverse:E}=F,M=V(_),U=this.#F(_,M);if(U=U.filter((J)=>H(J,F)),E)U.reverse();let Z=0;for(let J of U){if(Y!==void 0&&Z>=Y)break;yield J,Z++}}async count(_){let F=V(_);return this.#F(_,F).length}scoped(_){return c(this,_)}get size(){return this.#_.size}clear(){this.#_.clear()}snapshot(){let _=new Map;for(let[F,Y]of this.#_)_.set(F,new Uint8Array(Y));return _}[Symbol.dispose](){this.#_.clear()}}export{d as MemoryStorage};