@lostgradient/weft 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/alerting/alert-manager.d.ts +5 -3
- package/dist/alerting/alert-manager.js +26 -5
- package/dist/alerting/index.d.ts +1 -1
- package/dist/alerting/types.d.ts +17 -13
- package/dist/alerting/types.js +5 -0
- package/dist/cli/api.js +5 -19
- package/dist/cli/console.d.ts +12 -0
- package/dist/cli/console.js +62 -0
- package/dist/cli/generated/operation-catalog.snapshot.json +71 -0
- package/dist/cli/generated/operation-client.generated.d.ts +15 -2
- package/dist/cli/generated/operation-client.generated.js +2 -0
- package/dist/cli/help-text.d.ts +1 -1
- package/dist/cli/help-text.js +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/json-input.d.ts +20 -0
- package/dist/cli/json-input.js +33 -0
- package/dist/cli/parse-arguments.js +2 -0
- package/dist/cli/schedule.js +7 -9
- package/dist/cli/types.d.ts +1 -0
- package/dist/cli/workflow-commands.js +5 -25
- package/dist/cli-main.js +4 -2
- package/dist/core/engine/disposal.js +7 -0
- package/dist/core/engine/engine-runtime-helpers.d.ts +3 -1
- package/dist/core/engine/engine-runtime-helpers.js +2 -2
- package/dist/core/engine/errors.d.ts +20 -0
- package/dist/core/engine/errors.js +8 -0
- package/dist/core/engine/index.d.ts +39 -14
- package/dist/core/engine/index.js +84 -9
- package/dist/core/engine/inline-launch-queue.d.ts +6 -2
- package/dist/core/engine/inline-launch-queue.js +41 -6
- package/dist/core/engine/internals.d.ts +2 -0
- package/dist/core/engine/lease-manager.d.ts +3 -2
- package/dist/core/engine/lease-manager.js +7 -3
- package/dist/core/engine/operations-time.js +6 -0
- package/dist/core/execution-strategy.d.ts +8 -0
- package/dist/core/inline-execution-strategy.d.ts +1 -0
- package/dist/core/inline-execution-strategy.js +33 -20
- package/dist/core/weft-error.d.ts +1 -1
- package/dist/core/weft-error.js +1 -0
- package/dist/core/worker-execution-strategy.d.ts +2 -0
- package/dist/core/worker-execution-strategy.js +7 -2
- package/dist/core/worker-turn-watchdog.d.ts +4 -1
- package/dist/core/worker-turn-watchdog.js +9 -4
- package/dist/diagnostics/recommendations.js +1 -9
- package/dist/http.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -0
- package/dist/indexeddb.js +1 -1
- package/dist/json-schema.js +1 -1
- package/dist/mcp/tools.js +1 -3
- package/dist/server/authorization-scope.d.ts +1 -1
- package/dist/server/authorization-scope.js +0 -2
- package/dist/server/dashboard-assets.d.ts +37 -0
- package/dist/server/dashboard-assets.js +209 -0
- package/dist/server/index.d.ts +10 -1
- package/dist/server/index.js +11 -2
- package/dist/server/interactive-operations.js +1 -0
- package/dist/server/operations/aggregate-workflows.js +0 -7
- package/dist/server/operations/async-activity.js +5 -24
- package/dist/server/operations/bulk-cancel-workflows.js +3 -8
- package/dist/server/operations/bulk-delete-workflows.js +3 -8
- package/dist/server/operations/bulk-mutate-workflow-tags.js +3 -8
- package/dist/server/operations/bulk-operation-helpers.d.ts +2 -10
- package/dist/server/operations/bulk-operation-helpers.js +0 -6
- package/dist/server/operations/bulk-retry-failed-workflows.js +3 -8
- package/dist/server/operations/bulk-signal-workflows.js +3 -8
- package/dist/server/operations/cancel-schedule.js +1 -3
- package/dist/server/operations/cancel-workflow.js +1 -3
- package/dist/server/operations/create-schedule.js +21 -49
- package/dist/server/operations/fork-workflow.js +2 -3
- package/dist/server/operations/get-checkpoint-at.js +1 -6
- package/dist/server/operations/get-registry.js +1 -7
- package/dist/server/operations/get-retention-overview.js +2 -15
- package/dist/server/operations/get-review.js +2 -15
- package/dist/server/operations/get-schedule.js +2 -8
- package/dist/server/operations/get-stream-chunks.js +2 -6
- package/dist/server/operations/get-system-lease.js +1 -7
- package/dist/server/operations/get-system-metrics.js +0 -4
- package/dist/server/operations/get-task-diagnostics.js +2 -13
- package/dist/server/operations/get-update-result.js +1 -6
- package/dist/server/operations/get-workflow-attributes.js +2 -15
- package/dist/server/operations/get-workflow-events.js +2 -15
- package/dist/server/operations/get-workflow-observability.js +2 -5
- package/dist/server/operations/get-workflow-result.js +0 -7
- package/dist/server/operations/get-workflow-timeline.js +1 -6
- package/dist/server/operations/get-workflow.d.ts +3 -6
- package/dist/server/operations/get-workflow.js +2 -12
- package/dist/server/operations/list-alerts.d.ts +29 -0
- package/dist/server/operations/list-alerts.js +47 -0
- package/dist/server/operations/list-checkpoints.js +1 -6
- package/dist/server/operations/list-reviews.js +0 -7
- package/dist/server/operations/list-schedules.js +3 -8
- package/dist/server/operations/list-task-queues.js +0 -4
- package/dist/server/operations/list-workers.js +0 -4
- package/dist/server/operations/list-workflows.js +0 -7
- package/dist/server/operations/pause-schedule.js +1 -3
- package/dist/server/operations/purge-workflows.js +2 -5
- package/dist/server/operations/query-workflow.js +4 -15
- package/dist/server/operations/replay-workflow.js +2 -6
- package/dist/server/operations/resume-schedule.js +1 -3
- package/dist/server/operations/resume-workflow.js +1 -3
- package/dist/server/operations/schedule-faults.d.ts +9 -1
- package/dist/server/operations/schedule-faults.js +51 -0
- package/dist/server/operations/set-workflow-attributes.js +3 -15
- package/dist/server/operations/signal-workflow.js +3 -12
- package/dist/server/operations/single-workflow-tag-mutation.js +0 -7
- package/dist/server/operations/start-or-signal-workflow.js +2 -3
- package/dist/server/operations/start-workflow.js +2 -3
- package/dist/server/operations/storage-capabilities.js +1 -3
- package/dist/server/operations/storage.js +7 -13
- package/dist/server/operations/submit-review-decision.js +3 -12
- package/dist/server/operations/suspend-workflow.js +1 -3
- package/dist/server/operations/timeout-workflow.js +1 -3
- package/dist/server/operations/update-schedule.js +7 -56
- package/dist/server/operations/update-workflow.js +2 -3
- package/dist/server/operations/worker-drain.js +0 -8
- package/dist/server/rest-binding.d.ts +3 -2
- package/dist/server/rest-bindings.js +3 -0
- package/dist/server/route-model.d.ts +2 -0
- package/dist/server/route-model.js +1 -1
- package/dist/server/runtime/task-reconciliation.d.ts +10 -1
- package/dist/server/runtime/task-reconciliation.js +26 -2
- package/dist/server/serve-internals.js +12 -6
- package/dist/service-worker/index.d.ts +4 -1
- package/dist/service-worker/index.js +2 -2
- package/dist/service-worker/setup.d.ts +20 -0
- package/dist/service-worker/setup.js +5 -5
- package/dist/storage/bun-sql.js +13 -31
- package/dist/storage/indexeddb.js +28 -48
- package/dist/storage/lmdb.js +1 -1
- package/dist/storage/memory.js +1 -1
- package/dist/storage/neon.js +2 -2
- package/dist/storage/postgres.js +2 -2
- package/dist/storage/resolve.js +1 -1
- package/dist/storage/scoped-storage.js +1 -1
- package/dist/storage/testing.d.ts +6 -3
- package/dist/storage/testing.js +1 -1
- package/dist/storage/turso.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/web-extension.js +1 -1
- package/dist/worker/protocol-schemas.d.ts +2 -2
- package/dist/worker/protocol-schemas.js +2 -2
- package/dist/worker/protocol.js +1 -1
- package/package.json +5 -1
|
@@ -98,6 +98,7 @@ import {
|
|
|
98
98
|
getWorkflowTimelineRestBinding
|
|
99
99
|
} from "./operations/get-workflow-timeline.js";
|
|
100
100
|
import { getWorkflowOperation, getWorkflowRestBinding } from "./operations/get-workflow.js";
|
|
101
|
+
import { listAlertsOperation, listAlertsRestBinding } from "./operations/list-alerts.js";
|
|
101
102
|
import {
|
|
102
103
|
listCheckpointsOperation,
|
|
103
104
|
listCheckpointsRestBinding
|
|
@@ -214,6 +215,7 @@ import {
|
|
|
214
215
|
} from "./operations/workflow-events-sse.js";
|
|
215
216
|
import { workflowEventsSubscriptionOperation } from "./operations/workflow-events-subscription.js";
|
|
216
217
|
export const REST_BINDINGS = [
|
|
218
|
+
listAlertsRestBinding,
|
|
217
219
|
startWorkflowRestBinding,
|
|
218
220
|
startOrSignalWorkflowRestBinding,
|
|
219
221
|
recoverAllRestBinding,
|
|
@@ -401,6 +403,7 @@ export function createLiveOperationRegistry(options) {
|
|
|
401
403
|
buildTaskDiagnosticsOperationForRegistry(resolved),
|
|
402
404
|
clearTaskDeadLetterOperation,
|
|
403
405
|
listSchedulesOperation,
|
|
406
|
+
listAlertsOperation,
|
|
404
407
|
getScheduleOperation,
|
|
405
408
|
replayWorkflowOperation,
|
|
406
409
|
storageCapabilities.storageCapabilitiesOperation,
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
* RFC 9264 / discovery convention.
|
|
35
35
|
*/
|
|
36
36
|
export declare const API_PREFIX = "/api";
|
|
37
|
+
/** Root-relative namespace for the functional REST and WebSocket API. */
|
|
38
|
+
export declare const ROOT_API_PREFIX = "/v1";
|
|
37
39
|
/**
|
|
38
40
|
* Map a canonical, root-relative server path to its external (`/api`-prefixed)
|
|
39
41
|
* form for emission in specs and discovery documents.
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { ServeOptions } from '../index.ts';
|
|
2
2
|
import type { InflightRecord, TaskRequeueReason } from '../task-state.ts';
|
|
3
3
|
import type { ServerContext } from './context.ts';
|
|
4
|
+
interface ManualTaskReconciliationForTesting {
|
|
5
|
+
readonly options: ServeOptions;
|
|
6
|
+
scanAt(operationId: string, trackedDeadline: number, now: number): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/** @internal Restricts manual reconciliation to explicitly marked test options. */
|
|
9
|
+
export declare function useManualTaskReconciliationForTesting(options: ServeOptions): ManualTaskReconciliationForTesting;
|
|
10
|
+
/** @internal Installs the narrow one-shot test controller before a server starts. */
|
|
11
|
+
export declare function consumeManualTaskReconciliationForTesting(options: ServeOptions, context: ServerContext, cleanupWorkflowIndex: (operationId: string) => void): boolean;
|
|
4
12
|
/**
|
|
5
13
|
* Given a persisted inflight record, either permanently fail the task (if
|
|
6
14
|
* retry attempts are exhausted) or transition it back to queued and
|
|
@@ -13,5 +21,6 @@ export declare function reassignOrExpireTask(context: ServerContext, options: Se
|
|
|
13
21
|
* their tasks. Only touches storage for the specific operations whose
|
|
14
22
|
* deadlines have actually passed — no full `op:inflight:*` scan.
|
|
15
23
|
*/
|
|
16
|
-
export declare function scanExpiredTasks(context: ServerContext, options: ServeOptions, cleanupWorkflowIndex: (operationId: string) => void): Promise<void>;
|
|
24
|
+
export declare function scanExpiredTasks(context: ServerContext, options: ServeOptions, cleanupWorkflowIndex: (operationId: string) => void, now?: number): Promise<void>;
|
|
17
25
|
export declare function reconcileOrphanedRecords(context: ServerContext, options: ServeOptions, cleanupWorkflowIndex: (operationId: string) => void): Promise<void>;
|
|
26
|
+
export {};
|
|
@@ -17,6 +17,30 @@ import {
|
|
|
17
17
|
recordWorkerCapacitySaturationMetric
|
|
18
18
|
} from "./task-metrics.js";
|
|
19
19
|
import { isInflightRecord } from "./websocket-worker.js";
|
|
20
|
+
const manualTaskReconciliationRegistrations = new WeakMap;
|
|
21
|
+
export function useManualTaskReconciliationForTesting(options) {
|
|
22
|
+
const registration = {};
|
|
23
|
+
manualTaskReconciliationRegistrations.set(options, registration);
|
|
24
|
+
return {
|
|
25
|
+
options,
|
|
26
|
+
scanAt(operationId, trackedDeadline, now) {
|
|
27
|
+
if (registration.scanAt === void 0)
|
|
28
|
+
throw Error("Manual task reconciliation requires a running test server");
|
|
29
|
+
return registration.scanAt(operationId, trackedDeadline, now);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function consumeManualTaskReconciliationForTesting(options, context, cleanupWorkflowIndex) {
|
|
34
|
+
const registration = manualTaskReconciliationRegistrations.get(options);
|
|
35
|
+
manualTaskReconciliationRegistrations.delete(options);
|
|
36
|
+
if (registration === void 0)
|
|
37
|
+
return !1;
|
|
38
|
+
registration.scanAt = async (operationId, trackedDeadline, now) => {
|
|
39
|
+
context.deadlineTracker.add({ operationId, deadline: trackedDeadline });
|
|
40
|
+
await scanExpiredTasks(context, options, cleanupWorkflowIndex, now);
|
|
41
|
+
};
|
|
42
|
+
return !0;
|
|
43
|
+
}
|
|
20
44
|
export async function reassignOrExpireTask(context, options, operationId, record, reason = "visibility-timeout") {
|
|
21
45
|
const nextAttempt = (record.attempt ?? 1) + 1, policy = record.retryPolicy, nextRetryCount = Math.max(record.retryCount ?? 0, nextAttempt - 1);
|
|
22
46
|
if (hasExceededMaxAttempts(policy, nextAttempt)) {
|
|
@@ -82,12 +106,12 @@ function scheduleTaskRedispatch(context, options, taskDispatch, policy) {
|
|
|
82
106
|
} else
|
|
83
107
|
dispatchTaskImpl(context, options, taskDispatch).catch((err) => console.error(`[weft] Redispatch failed for "${taskDispatch.operationId}":`, err));
|
|
84
108
|
}
|
|
85
|
-
export async function scanExpiredTasks(context, options, cleanupWorkflowIndex) {
|
|
109
|
+
export async function scanExpiredTasks(context, options, cleanupWorkflowIndex, now = Date.now()) {
|
|
86
110
|
if (context.scanRunning)
|
|
87
111
|
return;
|
|
88
112
|
context.scanRunning = !0;
|
|
89
113
|
try {
|
|
90
|
-
const
|
|
114
|
+
const expired = context.deadlineTracker.drainExpired(now);
|
|
91
115
|
for (const { operationId, deadline } of expired) {
|
|
92
116
|
if (context.processingOperations.has(operationId)) {
|
|
93
117
|
context.deadlineTracker.add({ operationId, deadline });
|
|
@@ -25,7 +25,11 @@ import {
|
|
|
25
25
|
registerWorkflowEventLifecycle
|
|
26
26
|
} from "./runtime/event-broadcasting.js";
|
|
27
27
|
import { shutdownAllWorkers } from "./runtime/shutdown.js";
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
consumeManualTaskReconciliationForTesting as consumeManual,
|
|
30
|
+
reconcileOrphanedRecords,
|
|
31
|
+
scanExpiredTasks
|
|
32
|
+
} from "./runtime/task-reconciliation.js";
|
|
29
33
|
import { DEFAULT_MAX_STREAM_CONNECTIONS_PER_WORKFLOW } from "./runtime/websocket-stream.js";
|
|
30
34
|
import { isInflightRecord, withRetry } from "./runtime/websocket-worker.js";
|
|
31
35
|
import { TaskQueue } from "./task-queue.js";
|
|
@@ -166,14 +170,16 @@ export function registerStackDisposers(stack, context, options, broadcastingHand
|
|
|
166
170
|
stack.defer(() => context.mcpSessionManager[Symbol.asyncDispose]());
|
|
167
171
|
stack.defer(registerWorkflowEventLifecycle(options.engine, context, broadcastingHandle));
|
|
168
172
|
stack.defer(() => shutdownAllWorkers(context, options.workerShutdownTimeoutMs === void 0 ? void 0 : { timeoutMs: options.workerShutdownTimeoutMs, stopWaitingWhenIdle: !0 }));
|
|
169
|
-
const visibilityPollHandle = setInterval(() => {
|
|
173
|
+
const schedulesTaskReconciliation = !consumeManual(options, context, onOperationCleanup), visibilityPollHandle = schedulesTaskReconciliation ? setInterval(() => {
|
|
170
174
|
scanExpiredTasks(context, options, onOperationCleanup);
|
|
171
|
-
}, context.visibilityPollMs), reconciliationIntervalMs = context.visibilityPollMs * RECONCILIATION_MULTIPLIER, reconciliationHandle = setInterval(() => {
|
|
175
|
+
}, context.visibilityPollMs) : void 0, reconciliationIntervalMs = context.visibilityPollMs * RECONCILIATION_MULTIPLIER, reconciliationHandle = schedulesTaskReconciliation ? setInterval(() => {
|
|
172
176
|
reconcileOrphanedRecords(context, options, onOperationCleanup);
|
|
173
|
-
}, reconciliationIntervalMs);
|
|
177
|
+
}, reconciliationIntervalMs) : void 0;
|
|
174
178
|
stack.defer(() => {
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
if (visibilityPollHandle !== void 0)
|
|
180
|
+
clearInterval(visibilityPollHandle);
|
|
181
|
+
if (reconciliationHandle !== void 0)
|
|
182
|
+
clearInterval(reconciliationHandle);
|
|
177
183
|
context.deadlineTracker.clear();
|
|
178
184
|
for (const timer of context.pendingTimers)
|
|
179
185
|
clearTimeout(timer);
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { RegistryAgnosticEngine } from '../core/engine';
|
|
10
10
|
import type { ServiceWorkerScheduler } from './scheduler.ts';
|
|
11
|
+
import type { ServiceWorkerHandlerOptions } from './setup.ts';
|
|
11
12
|
import type { MinimalExtendableEvent, MinimalFetchEvent, MinimalPeriodicSyncEvent } from './shared.ts';
|
|
12
13
|
export { ServiceWorkerScheduler } from './scheduler.ts';
|
|
13
14
|
export type { ServiceWorkerSchedulerOptions } from './scheduler.ts';
|
|
@@ -44,6 +45,8 @@ export interface ServiceWorkerOptions {
|
|
|
44
45
|
*/
|
|
45
46
|
engine: RegistryAgnosticEngine;
|
|
46
47
|
pathPrefix?: string;
|
|
48
|
+
/** Handler options supported by the Service Worker runtime. */
|
|
49
|
+
handlerOptions?: ServiceWorkerHandlerOptions;
|
|
47
50
|
}
|
|
48
51
|
/**
|
|
49
52
|
* Create a fetch event handler that intercepts requests matching the given
|
|
@@ -127,4 +130,4 @@ export declare function createLifecycleHandlers(): {
|
|
|
127
130
|
install: (event: MinimalExtendableEvent) => void;
|
|
128
131
|
activate: (event: MinimalExtendableEvent) => void;
|
|
129
132
|
};
|
|
130
|
-
export { setupServiceWorker, type SetupServiceWorkerOptions, type SetupServiceWorkerResult, } from './setup.ts';
|
|
133
|
+
export { setupServiceWorker, type ServiceWorkerHandlerOptions, type SetupServiceWorkerOptions, type SetupServiceWorkerResult, } from './setup.ts';
|
|
@@ -3,12 +3,12 @@ import { buildDelegatedRequest, DEFAULT_PERIODIC_SYNC_TAG, normalizePathPrefix }
|
|
|
3
3
|
export { ServiceWorkerScheduler } from "./scheduler.js";
|
|
4
4
|
export { buildDelegatedRequest, DEFAULT_PERIODIC_SYNC_TAG, normalizePathPrefix } from "./shared.js";
|
|
5
5
|
export function createFetchHandler(options) {
|
|
6
|
-
const { engine } = options, pathPrefix = normalizePathPrefix(options.pathPrefix);
|
|
6
|
+
const { engine, handlerOptions } = options, pathPrefix = normalizePathPrefix(options.pathPrefix);
|
|
7
7
|
return (event) => {
|
|
8
8
|
const delegatedRequest = buildDelegatedRequest(event, pathPrefix);
|
|
9
9
|
if (delegatedRequest === null)
|
|
10
10
|
return;
|
|
11
|
-
event.respondWith(handleRequest(delegatedRequest, engine));
|
|
11
|
+
event.respondWith(handleRequest(delegatedRequest, engine, handlerOptions));
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
export function createPeriodicSyncHandler(scheduler, tag) {
|
|
@@ -11,8 +11,26 @@
|
|
|
11
11
|
* @module service-worker/setup
|
|
12
12
|
*/
|
|
13
13
|
import { Engine, type RegistryAgnosticEngine } from '../core/engine';
|
|
14
|
+
import type { HandlerOptions } from '../server/handler';
|
|
14
15
|
import type { Storage as WeftStorage } from '../storage/interface';
|
|
15
16
|
import { ServiceWorkerScheduler } from './scheduler';
|
|
17
|
+
/**
|
|
18
|
+
* The subset of {@link HandlerOptions} that can be supplied by a Service
|
|
19
|
+
* Worker. Service Workers can inject request authorization and event-stream
|
|
20
|
+
* plumbing, but cannot provide server-owned registries or Bun runtime
|
|
21
|
+
* integrations.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import type { ServiceWorkerHandlerOptions } from '@lostgradient/weft/service-worker';
|
|
26
|
+
*
|
|
27
|
+
* const handlerOptions: ServiceWorkerHandlerOptions = {
|
|
28
|
+
* authContext: { method: 'public' },
|
|
29
|
+
* };
|
|
30
|
+
* void handlerOptions;
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type ServiceWorkerHandlerOptions = Pick<HandlerOptions, 'authContext' | 'workflowEventFeed' | 'fleetEventFeed' | 'acquireWorkflowStreamConnection'>;
|
|
16
34
|
/**
|
|
17
35
|
* Options for {@link setupServiceWorker}. All fields are optional; the
|
|
18
36
|
* helper supplies sensible defaults (`/weft/` path prefix, `'weft'`
|
|
@@ -58,6 +76,8 @@ export interface SetupServiceWorkerOptions {
|
|
|
58
76
|
* engine's storage when both are provided.
|
|
59
77
|
*/
|
|
60
78
|
storage?: WeftStorage;
|
|
79
|
+
/** Handler options supported by the Service Worker runtime. */
|
|
80
|
+
handlerOptions?: ServiceWorkerHandlerOptions;
|
|
61
81
|
/**
|
|
62
82
|
* Register workflows on the engine before listeners do real work.
|
|
63
83
|
* Resolves before the helper returns. Rejection causes subsequent
|
|
@@ -49,16 +49,16 @@ function resolveStorageAndEngine(options) {
|
|
|
49
49
|
const storage = options.storage ?? new IndexedDBStorage(options.databaseName ?? DEFAULT_DATABASE_NAME);
|
|
50
50
|
return { storage, engine: new Engine({ storage }) };
|
|
51
51
|
}
|
|
52
|
-
function buildFetchListener(pathPrefix, engine, registrationReady) {
|
|
52
|
+
function buildFetchListener(pathPrefix, engine, registrationReady, handlerOptions) {
|
|
53
53
|
return (event) => {
|
|
54
54
|
const delegatedRequest = buildDelegatedRequest(event, pathPrefix);
|
|
55
55
|
if (delegatedRequest === null)
|
|
56
56
|
return;
|
|
57
|
-
event.respondWith(registrationReady.then(() => handleRequest(delegatedRequest, engine)).catch((error) => buildErrorResponse(error instanceof Error ? error : Error(String(error)))));
|
|
57
|
+
event.respondWith(registrationReady.then(() => handleRequest(delegatedRequest, engine, handlerOptions)).catch((error) => buildErrorResponse(error instanceof Error ? error : Error(String(error)))));
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
function attachListeners(scope, pathPrefix, periodicSyncTag, engine, scheduler, registrationReady) {
|
|
61
|
-
const fetchListener = buildFetchListener(pathPrefix, engine, registrationReady), periodicSyncListener = (event) => {
|
|
60
|
+
function attachListeners(scope, pathPrefix, periodicSyncTag, engine, scheduler, registrationReady, handlerOptions) {
|
|
61
|
+
const fetchListener = buildFetchListener(pathPrefix, engine, registrationReady, handlerOptions), periodicSyncListener = (event) => {
|
|
62
62
|
if (event.tag !== periodicSyncTag)
|
|
63
63
|
return;
|
|
64
64
|
event.waitUntil(registrationReady.then(() => scheduler.tick()));
|
|
@@ -104,7 +104,7 @@ export function setupServiceWorker(options = {}) {
|
|
|
104
104
|
await engine.recoverAll();
|
|
105
105
|
}
|
|
106
106
|
const registrationReady = Promise.resolve().then(runRegistrationAndRecovery);
|
|
107
|
-
attachListeners(scope, pathPrefix, periodicSyncTag, engine, scheduler, registrationReady);
|
|
107
|
+
attachListeners(scope, pathPrefix, periodicSyncTag, engine, scheduler, registrationReady, options.handlerOptions);
|
|
108
108
|
const result = {
|
|
109
109
|
engine,
|
|
110
110
|
storage,
|
package/dist/storage/bun-sql.js
CHANGED
|
@@ -253,47 +253,29 @@ class ScopedStorage {
|
|
|
253
253
|
}
|
|
254
254
|
return key.slice(this.#scopePrefix.length + 1);
|
|
255
255
|
}
|
|
256
|
-
#
|
|
256
|
+
#toInnerRangeOptions(options) {
|
|
257
257
|
const innerOptions = {};
|
|
258
|
-
if (options.limit !== undefined)
|
|
258
|
+
if (options.limit !== undefined)
|
|
259
259
|
innerOptions.limit = options.limit;
|
|
260
|
-
|
|
261
|
-
if (options.reverse !== undefined) {
|
|
262
|
-
innerOptions.reverse = options.reverse;
|
|
263
|
-
}
|
|
264
|
-
if (options.gt !== undefined) {
|
|
260
|
+
if (options.gt !== undefined)
|
|
265
261
|
innerOptions.gt = this.#toInnerKey(options.gt);
|
|
266
|
-
|
|
267
|
-
if (options.gte !== undefined) {
|
|
262
|
+
if (options.gte !== undefined)
|
|
268
263
|
innerOptions.gte = this.#toInnerKey(options.gte);
|
|
269
|
-
|
|
270
|
-
if (options.lt !== undefined) {
|
|
264
|
+
if (options.lt !== undefined)
|
|
271
265
|
innerOptions.lt = this.#toInnerKey(options.lt);
|
|
272
|
-
|
|
273
|
-
if (options.lte !== undefined) {
|
|
266
|
+
if (options.lte !== undefined)
|
|
274
267
|
innerOptions.lte = this.#toInnerKey(options.lte);
|
|
275
|
-
}
|
|
276
268
|
return innerOptions;
|
|
277
269
|
}
|
|
278
|
-
#
|
|
279
|
-
const innerOptions =
|
|
280
|
-
if (options.
|
|
281
|
-
innerOptions.
|
|
282
|
-
}
|
|
283
|
-
if (options.gt !== undefined) {
|
|
284
|
-
innerOptions.gt = this.#toInnerKey(options.gt);
|
|
285
|
-
}
|
|
286
|
-
if (options.gte !== undefined) {
|
|
287
|
-
innerOptions.gte = this.#toInnerKey(options.gte);
|
|
288
|
-
}
|
|
289
|
-
if (options.lt !== undefined) {
|
|
290
|
-
innerOptions.lt = this.#toInnerKey(options.lt);
|
|
291
|
-
}
|
|
292
|
-
if (options.lte !== undefined) {
|
|
293
|
-
innerOptions.lte = this.#toInnerKey(options.lte);
|
|
294
|
-
}
|
|
270
|
+
#toInnerOptions(options = {}) {
|
|
271
|
+
const innerOptions = this.#toInnerRangeOptions(options);
|
|
272
|
+
if (options.reverse !== undefined)
|
|
273
|
+
innerOptions.reverse = options.reverse;
|
|
295
274
|
return innerOptions;
|
|
296
275
|
}
|
|
276
|
+
#toInnerDeleteRangeOptions(options) {
|
|
277
|
+
return this.#toInnerRangeOptions(options);
|
|
278
|
+
}
|
|
297
279
|
capabilities() {
|
|
298
280
|
return this.#storage.capabilities();
|
|
299
281
|
}
|
|
@@ -74,6 +74,30 @@ function createCursorRequestAwaiter(request, transaction) {
|
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
+
async function* iterateCursor(database, keyRangeFactory, prefix, options, openCursor, project) {
|
|
78
|
+
const { limit, reverse } = options, prefixEnd = resolvePrefixRangeEnd(prefix), range = keyRangeFactory.bound(prefix, prefixEnd, !1, !0), direction = reverse ? "prev" : "next", transaction = database.transaction(STORE_NAME, "readonly"), store = transaction.objectStore(STORE_NAME), request = openCursor(store, range, direction), nextCursor = createCursorRequestAwaiter(request, transaction);
|
|
79
|
+
let count = 0, completed = !1;
|
|
80
|
+
try {
|
|
81
|
+
let cursor = await nextCursor();
|
|
82
|
+
while (cursor) {
|
|
83
|
+
if (limit !== void 0 && count >= limit)
|
|
84
|
+
break;
|
|
85
|
+
const key = cursor.key;
|
|
86
|
+
if (matchesScanOptions(key, options)) {
|
|
87
|
+
yield project(cursor);
|
|
88
|
+
count++;
|
|
89
|
+
}
|
|
90
|
+
cursor.continue();
|
|
91
|
+
cursor = await nextCursor();
|
|
92
|
+
}
|
|
93
|
+
completed = !0;
|
|
94
|
+
} finally {
|
|
95
|
+
if (!completed)
|
|
96
|
+
try {
|
|
97
|
+
transaction.abort();
|
|
98
|
+
} catch {}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
77
101
|
|
|
78
102
|
export class IndexedDBStorage {
|
|
79
103
|
#databaseName;
|
|
@@ -168,30 +192,8 @@ export class IndexedDBStorage {
|
|
|
168
192
|
});
|
|
169
193
|
}
|
|
170
194
|
async* scan(prefix, options = {}) {
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
const nextCursor = createCursorRequestAwaiter(request, transaction);
|
|
174
|
-
let completed = !1;
|
|
175
|
-
try {
|
|
176
|
-
let cursor = await nextCursor();
|
|
177
|
-
while (cursor) {
|
|
178
|
-
if (limit !== void 0 && count >= limit)
|
|
179
|
-
break;
|
|
180
|
-
const key = cursor.key;
|
|
181
|
-
if (matchesScanOptions(key, options)) {
|
|
182
|
-
yield [key, new Uint8Array(cursor.value)];
|
|
183
|
-
count++;
|
|
184
|
-
}
|
|
185
|
-
cursor.continue();
|
|
186
|
-
cursor = await nextCursor();
|
|
187
|
-
}
|
|
188
|
-
completed = !0;
|
|
189
|
-
} finally {
|
|
190
|
-
if (!completed)
|
|
191
|
-
try {
|
|
192
|
-
transaction.abort();
|
|
193
|
-
} catch {}
|
|
194
|
-
}
|
|
195
|
+
const database = await this.#databasePromise;
|
|
196
|
+
yield* iterateCursor(database, this.#runtime.IDBKeyRange, prefix, options, (store, range, direction) => store.openCursor(range, direction), (cursor) => [cursor.key, new Uint8Array(cursor.value)]);
|
|
195
197
|
}
|
|
196
198
|
async batch(operations) {
|
|
197
199
|
assertStorageBatchOperationCount("batch operations", operations.length);
|
|
@@ -270,30 +272,8 @@ export class IndexedDBStorage {
|
|
|
270
272
|
});
|
|
271
273
|
}
|
|
272
274
|
async* keys(prefix, options = {}) {
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
const nextCursor = createCursorRequestAwaiter(request, transaction);
|
|
276
|
-
let completed = !1;
|
|
277
|
-
try {
|
|
278
|
-
let cursor = await nextCursor();
|
|
279
|
-
while (cursor) {
|
|
280
|
-
if (limit !== void 0 && count >= limit)
|
|
281
|
-
break;
|
|
282
|
-
const key = cursor.key;
|
|
283
|
-
if (matchesScanOptions(key, options)) {
|
|
284
|
-
yield key;
|
|
285
|
-
count++;
|
|
286
|
-
}
|
|
287
|
-
cursor.continue();
|
|
288
|
-
cursor = await nextCursor();
|
|
289
|
-
}
|
|
290
|
-
completed = !0;
|
|
291
|
-
} finally {
|
|
292
|
-
if (!completed)
|
|
293
|
-
try {
|
|
294
|
-
transaction.abort();
|
|
295
|
-
} catch {}
|
|
296
|
-
}
|
|
275
|
+
const database = await this.#databasePromise;
|
|
276
|
+
yield* iterateCursor(database, this.#runtime.IDBKeyRange, prefix, options, (store, range, direction) => store.openKeyCursor(range, direction), (cursor) => cursor.key);
|
|
297
277
|
}
|
|
298
278
|
async count(prefix) {
|
|
299
279
|
const database = await this.#databasePromise, prefixEnd = resolvePrefixRangeEnd(prefix), store = database.transaction(STORE_NAME, "readonly").objectStore(STORE_NAME);
|
package/dist/storage/lmdb.js
CHANGED
|
@@ -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 T(_,F){return await _.get(F)!==null}async function*j(_,F,E){for await(let[X]of _.scan(F,E))yield X}async function W(_,F){let E=0;for await(let X of j(_,F))E++;return E}async function B(_,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 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 Q(_,F){if(F>N)throw new z(_,F)}function V(_){return _.length>0?_.slice(0,-1)+String.fromCharCode(_.charCodeAt(_.length-1)+1):"\xFF"}function R(_,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 E=0;E<_.byteLength;E++)if(_[E]!==F[E])return!1;return!0}async function v(_,F){if(_.has)return _.has(F);return T(_,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 W(_,F)}async function O(_,F){if(_.deletePrefix)return _.deletePrefix(F);return B(_,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:${_}`,operationDeadLetterPrefix:()=>"op:dead-letter:",operationDeadLetter:(_)=>`op:dead-letter:${_}`,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 S(_){return _.replaceAll(/:+$/g,"")}function l(_,F){let E=S(_),X=S(F);if(E.length===0)return X;if(X.length===0)return E;return`${E}:${X}`}class q{#_;#Y;constructor(_,F){this.#_=_,this.#Y=S(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(_.reverse!==void 0)F.reverse=_.reverse;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={};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}capabilities(){return this.#_.capabilities()}scoped(_){return new q(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.#U(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.#G(H(F));return m(this.#_,this.#F(_),E)}async*keys(_,F){for await(let E of h(this.#_,this.#F(_),this.#U(F)))yield this.#X(E)}async count(_){return P(this.#_,this.#F(_))}[Symbol.dispose](){this.#_[Symbol.dispose]()}}function c(_,F){return new q(_,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,!R($,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,!R($,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(!K(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 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:${_}`,operationDeadLetterPrefix:()=>"op:dead-letter:",operationDeadLetter:(_)=>`op:dead-letter:${_}`,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};
|
package/dist/storage/memory.js
CHANGED
|
@@ -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 R(_,F){let Y=0;for await(let E of V(_,F))Y++;return Y}async function B(_,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 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,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 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 C(_,F)}function K(_,F,Y){if(_.keys)return _.keys(F,Y);return V(_,F,Y)}async function h(_,F){if(_.count)return _.count(F);return R(_,F)}async function O(_,F){if(_.deletePrefix)return _.deletePrefix(F);return B(_,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"),x="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:${_}`,operationDeadLetterPrefix:()=>"op:dead-letter:",operationDeadLetter:(_)=>`op:dead-letter:${_}`,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,x),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(_.reverse!==void 0)F.reverse=_.reverse;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={};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}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.#U(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 v(this.#_,this.#F(_))}async deletePrefix(_){return O(this.#_,this.#F(_))}async deleteRange(_,F){let Y=this.#G(j(F));return m(this.#_,this.#F(_),Y)}async*keys(_,F){for await(let Y of K(this.#_,this.#F(_),this.#U(F)))yield this.#E(Y)}async count(_){return h(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(!P(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 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:${_}`,operationDeadLetterPrefix:()=>"op:dead-letter:",operationDeadLetter:(_)=>`op:dead-letter:${_}`,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};
|