@swirls/looms 0.0.2 → 0.2.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/CHANGELOG.md +24 -2
- package/dist/actor/cell.d.ts +9 -4
- package/dist/actor/cell.js +7 -11
- package/dist/actor/host.d.ts +7 -3
- package/dist/actor/host.js +57 -33
- package/dist/actor/index.d.ts +1 -1
- package/dist/actor/index.js +1 -1
- package/dist/actor/routing.d.ts +12 -1
- package/dist/actor/routing.js +57 -51
- package/dist/agent/agent-session.d.ts +5 -0
- package/dist/agent/agent-session.js +270 -0
- package/dist/agent/debugger/agent-chat.d.ts +2 -0
- package/dist/agent/debugger/agent-chat.js +176 -0
- package/dist/agent/debugger/index.d.ts +5 -0
- package/dist/agent/debugger/index.js +19 -0
- package/dist/agent/debugger/summarize.d.ts +2 -0
- package/dist/agent/debugger/summarize.js +51 -0
- package/dist/agent/debugger/token-usage.d.ts +3 -0
- package/dist/agent/debugger/token-usage.js +11 -0
- package/dist/agent/definitions-store.d.ts +2 -3
- package/dist/agent/definitions-store.js +2 -4
- package/dist/agent/definitions.d.ts +47 -29
- package/dist/agent/definitions.js +39 -12
- package/dist/agent/effects.d.ts +359 -2
- package/dist/agent/effects.js +60 -34
- package/dist/agent/events.d.ts +175 -19
- package/dist/agent/events.js +45 -10
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.js +1 -0
- package/dist/agent/llm.d.ts +11 -2
- package/dist/agent/llm.js +13 -3
- package/dist/agent/module.d.ts +812 -78
- package/dist/agent/module.js +16 -4
- package/dist/agent/scope.d.ts +174 -18
- package/dist/agent/signals.d.ts +26 -1
- package/dist/agent/signals.js +79 -0
- package/dist/agent/threads.d.ts +3 -33
- package/dist/agent/threads.js +20 -25
- package/dist/agent/tool-schema.d.ts +1 -17
- package/dist/agent/tool-schema.js +3 -43
- package/dist/agent/types.d.ts +49 -4
- package/dist/agent/types.js +5 -5
- package/dist/ai-vercel/index.d.ts +1 -0
- package/dist/ai-vercel/index.js +1 -0
- package/dist/ai-vercel/messages.js +22 -7
- package/dist/ai-vercel/vercel-evaluator.d.ts +36 -0
- package/dist/ai-vercel/vercel-evaluator.js +73 -0
- package/dist/ai-vercel/vercel-llm.js +64 -44
- package/dist/approval/debugger/approvals-view.d.ts +3 -0
- package/dist/approval/debugger/approvals-view.js +16 -0
- package/dist/approval/debugger/index.d.ts +4 -0
- package/dist/approval/debugger/index.js +11 -0
- package/dist/approval/debugger/summarize.d.ts +2 -0
- package/dist/approval/debugger/summarize.js +17 -0
- package/dist/approval/effects.d.ts +89 -0
- package/dist/approval/module.d.ts +179 -29
- package/dist/approval/projections.d.ts +0 -14
- package/dist/approval/projections.js +20 -3
- package/dist/approval/signals.d.ts +2 -0
- package/dist/approval/signals.js +18 -2
- package/dist/cli/cli.js +2 -0
- package/dist/cli/commands.js +12 -16
- package/dist/client/client.d.ts +1213 -18
- package/dist/client/client.js +120 -120
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/sse.d.ts +13 -0
- package/dist/client/sse.js +38 -44
- package/dist/cloudflare/alarm-scheduler.d.ts +12 -2
- package/dist/cloudflare/alarm-scheduler.js +34 -7
- package/dist/cloudflare/durable-object.d.ts +10 -2
- package/dist/cloudflare/durable-object.js +59 -28
- package/dist/cloudflare/event-store.d.ts +7 -2
- package/dist/cloudflare/event-store.js +8 -7
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- package/dist/cloudflare/router.d.ts +1 -1
- package/dist/cloudflare/router.js +15 -16
- package/dist/core/catalog.d.ts +3 -3
- package/dist/core/catalog.js +2 -5
- package/dist/core/coalesce.js +5 -3
- package/dist/core/compose.d.ts +2 -1
- package/dist/core/compose.js +19 -2
- package/dist/core/debugger-host.d.ts +16 -0
- package/dist/core/debugger-host.js +1 -0
- package/dist/core/definition-store.d.ts +11 -0
- package/dist/core/definition-store.js +6 -0
- package/dist/core/effects.d.ts +127 -15
- package/dist/core/effects.js +89 -17
- package/dist/core/envelope.d.ts +27 -7
- package/dist/core/envelope.js +20 -6
- package/dist/core/event-codec.d.ts +4 -2
- package/dist/core/event-codec.js +10 -5
- package/dist/core/event-index.js +1 -3
- package/dist/core/fold.d.ts +3 -0
- package/dist/core/fold.js +171 -24
- package/dist/core/ids.d.ts +5 -0
- package/dist/core/ids.js +35 -2
- package/dist/core/index.d.ts +7 -1
- package/dist/core/index.js +6 -1
- package/dist/core/kind.d.ts +22 -0
- package/dist/core/kind.js +17 -0
- package/dist/core/limits.d.ts +34 -0
- package/dist/core/limits.js +46 -0
- package/dist/core/match.d.ts +1 -0
- package/dist/core/match.js +10 -1
- package/dist/core/module-scope.d.ts +22 -20
- package/dist/core/module-scope.js +38 -28
- package/dist/core/module.d.ts +18 -5
- package/dist/core/module.js +4 -0
- package/dist/core/projection.d.ts +13 -13
- package/dist/core/projection.js +9 -5
- package/dist/core/protocol.d.ts +68 -11
- package/dist/core/protocol.js +82 -11
- package/dist/core/published.d.ts +43 -0
- package/dist/core/published.js +44 -0
- package/dist/core/replay.d.ts +312 -3
- package/dist/core/replay.js +11 -1
- package/dist/core/schema.d.ts +11 -20
- package/dist/core/schema.js +63 -80
- package/dist/core/serialize.js +2 -4
- package/dist/core/snapshot-store.d.ts +6 -1
- package/dist/core/snapshot-store.js +15 -2
- package/dist/core/snapshots.d.ts +5 -1
- package/dist/core/snapshots.js +10 -15
- package/dist/core/sqlite-store.js +95 -11
- package/dist/core/state.d.ts +142 -4
- package/dist/core/state.js +78 -0
- package/dist/core/store.d.ts +38 -3
- package/dist/core/store.js +77 -22
- package/dist/core/thread.d.ts +10 -9
- package/dist/core/types.d.ts +5 -8
- package/dist/core/types.js +28 -24
- package/dist/core/validate-event.js +14 -4
- package/dist/core/worker-callback.d.ts +17 -0
- package/dist/core/worker-callback.js +1 -0
- package/dist/debugger/app/assets/index-B3Ah8WAE.css +2 -0
- package/dist/debugger/app/assets/index-Qb371t_O.js +22 -0
- package/dist/debugger/app/assets/rolldown-runtime-CbXtAM7H.js +1 -0
- package/dist/debugger/app/assets/routes-CjtEHgPQ.js +47 -0
- package/dist/debugger/app/index.html +14 -0
- package/dist/debugger/components/composer.d.ts +17 -0
- package/dist/debugger/components/composer.js +25 -0
- package/dist/debugger/components/debugger-split.d.ts +2 -1
- package/dist/debugger/components/debugger-split.js +2 -2
- package/dist/debugger/components/event-inspector.d.ts +2 -1
- package/dist/debugger/components/event-inspector.js +25 -16
- package/dist/debugger/components/event-stream.d.ts +2 -1
- package/dist/debugger/components/event-stream.js +14 -74
- package/dist/debugger/components/follow-list.d.ts +19 -0
- package/dist/debugger/components/follow-list.js +96 -0
- package/dist/debugger/components/json-tree.d.ts +11 -0
- package/dist/debugger/components/json-tree.js +120 -0
- package/dist/debugger/components/json-view.js +2 -2
- package/dist/debugger/components/run-tree.js +53 -20
- package/dist/debugger/components/status-dot.d.ts +4 -0
- package/dist/debugger/components/status-dot.js +6 -2
- package/dist/debugger/context.d.ts +14 -0
- package/dist/debugger/context.js +17 -0
- package/dist/debugger/contracts.d.ts +7 -4
- package/dist/debugger/events/builtin-families.d.ts +3 -0
- package/dist/debugger/events/builtin-families.js +9 -0
- package/dist/debugger/events/catalog.d.ts +3 -4
- package/dist/debugger/events/catalog.js +27 -17
- package/dist/debugger/events/protocol-summarize.d.ts +1 -2
- package/dist/debugger/events/protocol-summarize.js +42 -24
- package/dist/debugger/index.d.ts +20 -6
- package/dist/debugger/index.js +19 -5
- package/dist/debugger/lib/cn.d.ts +1 -0
- package/dist/debugger/lib/cn.js +3 -0
- package/dist/debugger/lib/event-meta.d.ts +2 -3
- package/dist/debugger/lib/event-meta.js +6 -12
- package/dist/debugger/lib/json.d.ts +25 -0
- package/dist/debugger/lib/json.js +87 -0
- package/dist/debugger/lib/payload.d.ts +7 -0
- package/dist/debugger/lib/payload.js +11 -0
- package/dist/debugger/lib/time.d.ts +3 -0
- package/dist/debugger/lib/time.js +24 -0
- package/dist/debugger/plugin.d.ts +36 -0
- package/dist/debugger/plugin.js +14 -0
- package/dist/debugger/server/index.d.ts +14 -0
- package/dist/debugger/server/index.js +114 -0
- package/dist/debugger/shell/debugger-shell.d.ts +15 -0
- package/dist/debugger/shell/debugger-shell.js +43 -0
- package/dist/debugger/shell/definition-key.d.ts +3 -0
- package/dist/debugger/shell/definition-key.js +4 -0
- package/dist/debugger/shell/events-pane.d.ts +12 -0
- package/dist/debugger/shell/events-pane.js +25 -0
- package/dist/debugger/shell/projections-panel.d.ts +4 -0
- package/dist/debugger/shell/projections-panel.js +59 -0
- package/dist/debugger/shell/run-controls.d.ts +4 -0
- package/dist/debugger/shell/run-controls.js +72 -0
- package/dist/debugger/shell/run-search.d.ts +6 -0
- package/dist/debugger/shell/run-search.js +102 -0
- package/dist/debugger/shell/run-type-menu.d.ts +6 -0
- package/dist/debugger/shell/run-type-menu.js +11 -0
- package/dist/debugger/shell/schema-form.d.ts +31 -0
- package/dist/debugger/shell/schema-form.js +117 -0
- package/dist/debugger/shell/start-form.d.ts +3 -0
- package/dist/debugger/shell/start-form.js +75 -0
- package/dist/debugger/shell/use-start-run.d.ts +14 -0
- package/dist/debugger/shell/use-start-run.js +32 -0
- package/dist/debugger/shell/workspace.d.ts +6 -0
- package/dist/debugger/shell/workspace.js +15 -0
- package/dist/debugger/styles.css +111 -27
- package/dist/debugger/ui/button.d.ts +24 -0
- package/dist/debugger/ui/button.js +24 -0
- package/dist/debugger/ui/command.d.ts +9 -0
- package/dist/debugger/ui/command.js +24 -0
- package/dist/debugger/ui/dropdown-menu.d.ts +13 -0
- package/dist/debugger/ui/dropdown-menu.js +37 -0
- package/dist/debugger/ui/panel.d.ts +14 -0
- package/dist/debugger/ui/panel.js +16 -0
- package/dist/debugger/ui/popover.d.ts +7 -0
- package/dist/debugger/ui/popover.js +17 -0
- package/dist/debugger/ui/resizable.d.ts +7 -0
- package/dist/debugger/ui/resizable.js +14 -0
- package/dist/debugger/ui/scroll-area.d.ts +2 -1
- package/dist/debugger/ui/scroll-area.js +5 -3
- package/dist/debugger/ui/select.d.ts +10 -0
- package/dist/debugger/ui/select.js +21 -0
- package/dist/debugger/ui/tabs.js +2 -2
- package/dist/debugger/ui/textarea.d.ts +3 -0
- package/dist/debugger/ui/textarea.js +7 -0
- package/dist/evaluator/definitions-store.d.ts +11 -0
- package/dist/evaluator/definitions-store.js +8 -0
- package/dist/evaluator/definitions.d.ts +18 -0
- package/dist/evaluator/definitions.js +4 -0
- package/dist/evaluator/effects.d.ts +226 -0
- package/dist/evaluator/effects.js +132 -0
- package/dist/evaluator/evaluator.d.ts +24 -0
- package/dist/evaluator/evaluator.js +67 -0
- package/dist/evaluator/events.d.ts +59 -0
- package/dist/evaluator/events.js +21 -0
- package/dist/evaluator/index.d.ts +11 -0
- package/dist/evaluator/index.js +11 -0
- package/dist/evaluator/module.d.ts +606 -0
- package/dist/evaluator/module.js +25 -0
- package/dist/evaluator/projections.d.ts +50 -0
- package/dist/evaluator/projections.js +20 -0
- package/dist/evaluator/scope.d.ts +59 -0
- package/dist/evaluator/scope.js +7 -0
- package/dist/evaluator/signals.d.ts +3 -0
- package/dist/evaluator/signals.js +17 -0
- package/dist/evaluator/threads.d.ts +62 -0
- package/dist/evaluator/threads.js +117 -0
- package/dist/evaluator/types.d.ts +125 -0
- package/dist/evaluator/types.js +51 -0
- package/dist/projectors/delivery.d.ts +83 -0
- package/dist/projectors/delivery.js +182 -0
- package/dist/projectors/index-model.d.ts +1 -1
- package/dist/projectors/index-model.js +4 -6
- package/dist/projectors/index.d.ts +2 -0
- package/dist/projectors/index.js +2 -0
- package/dist/projectors/memory.d.ts +1 -1
- package/dist/projectors/memory.js +10 -8
- package/dist/projectors/postgres.js +44 -58
- package/dist/projectors/projector.d.ts +17 -0
- package/dist/projectors/projector.js +26 -1
- package/dist/projectors/sqlite-delivery.d.ts +4 -0
- package/dist/projectors/sqlite-delivery.js +147 -0
- package/dist/projectors/sqlite.js +23 -23
- package/dist/projectors/with-projectors.d.ts +7 -2
- package/dist/projectors/with-projectors.js +27 -28
- package/dist/react/notify.js +11 -8
- package/dist/react/react.d.ts +2 -3
- package/dist/react/react.js +14 -30
- package/dist/react/sse.d.ts +1 -1
- package/dist/react/sse.js +1 -1
- package/dist/react/store.d.ts +3 -3
- package/dist/react/store.js +109 -119
- package/dist/runtime/cancellation.d.ts +16 -0
- package/dist/runtime/cancellation.js +129 -0
- package/dist/runtime/deadline-transition-planner.d.ts +31 -0
- package/dist/runtime/deadline-transition-planner.js +139 -0
- package/dist/runtime/dispatch-effect.d.ts +3 -2
- package/dist/runtime/dispatch-effect.js +7 -13
- package/dist/runtime/errors.d.ts +51 -0
- package/dist/runtime/errors.js +39 -0
- package/dist/runtime/{runtime-helpers.d.ts → helpers.d.ts} +24 -4
- package/dist/runtime/{runtime-helpers.js → helpers.js} +56 -19
- package/dist/runtime/index.d.ts +3 -3
- package/dist/runtime/index.js +3 -3
- package/dist/runtime/ingress.d.ts +15 -0
- package/dist/runtime/ingress.js +42 -0
- package/dist/runtime/local-effect-executor.d.ts +21 -0
- package/dist/runtime/local-effect-executor.js +137 -0
- package/dist/runtime/looms.d.ts +30 -4
- package/dist/runtime/looms.js +57 -37
- package/dist/runtime/observer.d.ts +45 -0
- package/dist/runtime/observer.js +11 -0
- package/dist/runtime/repository.d.ts +55 -0
- package/dist/runtime/repository.js +293 -0
- package/dist/runtime/retry-policy.d.ts +16 -0
- package/dist/runtime/retry-policy.js +29 -0
- package/dist/runtime/run-execution-context.d.ts +30 -0
- package/dist/runtime/run-execution-context.js +56 -0
- package/dist/runtime/run-start.d.ts +4 -0
- package/dist/runtime/run-start.js +44 -0
- package/dist/runtime/runtime.d.ts +6 -87
- package/dist/runtime/runtime.js +248 -470
- package/dist/runtime/server/auth.d.ts +41 -0
- package/dist/runtime/server/auth.js +45 -0
- package/dist/runtime/server/debugger-host.d.ts +11 -0
- package/dist/runtime/server/debugger-host.js +32 -0
- package/dist/runtime/server/fetch-handler.d.ts +18 -0
- package/dist/runtime/server/fetch-handler.js +62 -0
- package/dist/runtime/server/http.d.ts +38 -0
- package/dist/runtime/server/http.js +66 -0
- package/dist/runtime/server/route-table.d.ts +55 -0
- package/dist/runtime/server/route-table.js +74 -0
- package/dist/runtime/server/routes/definitions.d.ts +3 -0
- package/dist/runtime/server/routes/definitions.js +20 -0
- package/dist/runtime/server/routes/effects.d.ts +3 -0
- package/dist/runtime/server/routes/effects.js +59 -0
- package/dist/runtime/server/routes/operations.d.ts +3 -0
- package/dist/runtime/server/routes/operations.js +14 -0
- package/dist/runtime/server/routes/runs.d.ts +3 -0
- package/dist/runtime/server/routes/runs.js +199 -0
- package/dist/runtime/server.d.ts +4 -8
- package/dist/runtime/server.js +6 -211
- package/dist/runtime/sse.d.ts +2 -1
- package/dist/runtime/sse.js +24 -17
- package/dist/runtime/types.d.ts +117 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/wake-engine.d.ts +20 -0
- package/dist/runtime/wake-engine.js +311 -0
- package/dist/runtime/wake-scheduler.d.ts +3 -4
- package/dist/runtime/wake-scheduler.js +25 -31
- package/dist/runtime/worker-callbacks.d.ts +16 -0
- package/dist/runtime/worker-callbacks.js +167 -0
- package/dist/runtime/worker-effect-dispatch.d.ts +36 -0
- package/dist/runtime/worker-effect-dispatch.js +126 -0
- package/dist/s2/config.d.ts +1 -1
- package/dist/s2/config.js +1 -1
- package/dist/s2/lite.js +70 -82
- package/dist/s2/pagination.d.ts +15 -0
- package/dist/s2/pagination.js +36 -0
- package/dist/s2/projector.js +6 -5
- package/dist/s2/snapshot-store.js +188 -161
- package/dist/s2/store.d.ts +3 -21
- package/dist/s2/store.js +71 -165
- package/dist/testing/index.d.ts +15 -0
- package/dist/testing/index.js +53 -16
- package/dist/workflow/debugger/index.d.ts +4 -0
- package/dist/workflow/debugger/index.js +11 -0
- package/dist/workflow/debugger/nodes-view.d.ts +3 -0
- package/dist/workflow/debugger/nodes-view.js +13 -0
- package/dist/workflow/debugger/summarize.d.ts +2 -0
- package/dist/workflow/debugger/summarize.js +30 -0
- package/dist/workflow/definitions-store.d.ts +2 -3
- package/dist/workflow/definitions-store.js +2 -2
- package/dist/workflow/definitions.d.ts +78 -22
- package/dist/workflow/definitions.js +80 -14
- package/dist/workflow/effects.d.ts +453 -107
- package/dist/workflow/effects.js +214 -115
- package/dist/workflow/events.d.ts +149 -5
- package/dist/workflow/events.js +27 -5
- package/dist/workflow/graph.d.ts +56 -0
- package/dist/workflow/graph.js +207 -0
- package/dist/workflow/index.d.ts +1 -0
- package/dist/workflow/index.js +1 -0
- package/dist/workflow/module.d.ts +1047 -266
- package/dist/workflow/projections.d.ts +14 -12
- package/dist/workflow/projections.js +30 -8
- package/dist/workflow/scope.d.ts +146 -4
- package/dist/workflow/threads.d.ts +383 -155
- package/dist/workflow/threads.js +308 -110
- package/package.json +26 -2
- package/dist/debugger/events/domain-summarize.d.ts +0 -3
- package/dist/debugger/events/domain-summarize.js +0 -107
- package/dist/debugger/events/family.d.ts +0 -8
- package/dist/debugger/events/family.js +0 -44
- package/dist/runtime/events-api.d.ts +0 -4
- package/dist/runtime/events-api.js +0 -84
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import type { Effect } from 'effect';
|
|
1
2
|
import type { EventStore } from '@swirls/looms/core';
|
|
2
|
-
import { type Projector } from '@swirls/looms/projectors';
|
|
3
|
+
import { type Projector, type ProjectorDelivery } from '@swirls/looms/projectors';
|
|
3
4
|
export interface DurableObjectStoreOptions {
|
|
4
5
|
readonly projectors?: readonly Projector[];
|
|
6
|
+
readonly scheduleProjectorRetry?: (at: number) => Effect.Effect<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface DurableObjectEventStore extends EventStore {
|
|
9
|
+
readonly projectorDelivery?: ProjectorDelivery;
|
|
5
10
|
}
|
|
6
11
|
/**
|
|
7
12
|
* Creates an EventStore backed by a Durable Object's embedded SQLite database (`ctx.storage.sql`).
|
|
8
13
|
* Optionally attaches asynchronous projectors (such as S2).
|
|
9
14
|
*/
|
|
10
|
-
export declare function durableObjectEventStore(ctx: DurableObjectState, options?: DurableObjectStoreOptions):
|
|
15
|
+
export declare function durableObjectEventStore(ctx: DurableObjectState, options?: DurableObjectStoreOptions): DurableObjectEventStore;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { sqliteEventStore, sqlStorageExec } from '@swirls/looms/core/sqlite-store';
|
|
2
|
-
import { withProjectors } from '@swirls/looms/projectors';
|
|
2
|
+
import { createProjectorDelivery, sqliteProjectorCursorStore, withProjectors, } from '@swirls/looms/projectors';
|
|
3
3
|
/**
|
|
4
4
|
* Creates an EventStore backed by a Durable Object's embedded SQLite database (`ctx.storage.sql`).
|
|
5
5
|
* Optionally attaches asynchronous projectors (such as S2).
|
|
6
6
|
*/
|
|
7
7
|
export function durableObjectEventStore(ctx, options = {}) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
transaction: (fn) => ctx.storage.transactionSync(fn),
|
|
12
|
-
}),
|
|
8
|
+
const exec = sqlStorageExec(ctx.storage.sql, {
|
|
9
|
+
// DO SQLite rejects BEGIN/COMMIT/ROLLBACK; use the storage transaction API.
|
|
10
|
+
transaction: (fn) => ctx.storage.transactionSync(fn),
|
|
13
11
|
});
|
|
12
|
+
const store = sqliteEventStore({ exec });
|
|
14
13
|
if (options.projectors && options.projectors.length > 0) {
|
|
15
|
-
|
|
14
|
+
const delivery = createProjectorDelivery(store, options.projectors, sqliteProjectorCursorStore(exec), { scheduleRetry: options.scheduleProjectorRetry });
|
|
15
|
+
const wrapped = withProjectors(store, options.projectors, { delivery });
|
|
16
|
+
return Object.assign(wrapped, { projectorDelivery: delivery });
|
|
16
17
|
}
|
|
17
18
|
return store;
|
|
18
19
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { durableObjectEventStore, type DurableObjectStoreOptions } from './event-store';
|
|
1
|
+
export { durableObjectAlarms, type AlarmStorage, type DurableObjectAlarms } from './alarm-scheduler';
|
|
2
|
+
export { durableObjectEventStore, type DurableObjectEventStore, type DurableObjectStoreOptions, } from './event-store';
|
|
3
3
|
export { LoomsDurableObject, type LoomsDurableObjectConfig } from './durable-object';
|
|
4
4
|
export { routeToDurableObject, type DurableObjectNamespaceLike, type DurableObjectStubLike, } from './router';
|
package/dist/cloudflare/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { durableObjectEventStore } from './event-store.js';
|
|
1
|
+
export { durableObjectAlarms } from './alarm-scheduler.js';
|
|
2
|
+
export { durableObjectEventStore, } from './event-store.js';
|
|
3
3
|
export { LoomsDurableObject } from './durable-object.js';
|
|
4
4
|
export { routeToDurableObject, } from './router.js';
|
|
@@ -6,7 +6,7 @@ export interface DurableObjectNamespaceLike<T extends DurableObjectStubLike = Du
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Routes incoming HTTP requests to the appropriate Durable Object actor cell.
|
|
9
|
-
* Handles `/health` locally, returns 501 for global
|
|
9
|
+
* Handles `/health` locally, returns 501 for global run lists, and forwards
|
|
10
10
|
* all other run and event-stream requests to `namespace.getByName(runId)`.
|
|
11
11
|
*/
|
|
12
12
|
export declare function routeToDurableObject(namespace: DurableObjectNamespaceLike, req: Request): Promise<Response | null>;
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import { resolveRunTarget } from '@swirls/looms/actor';
|
|
1
|
+
import { resolveRunTarget, RunTargetError } from '@swirls/looms/actor';
|
|
2
2
|
/**
|
|
3
3
|
* Routes incoming HTTP requests to the appropriate Durable Object actor cell.
|
|
4
|
-
* Handles `/health` locally, returns 501 for global
|
|
4
|
+
* Handles `/health` locally, returns 501 for global run lists, and forwards
|
|
5
5
|
* all other run and event-stream requests to `namespace.getByName(runId)`.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export function routeToDurableObject(namespace, req) {
|
|
8
8
|
const url = new URL(req.url);
|
|
9
9
|
if (url.pathname === '/health') {
|
|
10
|
-
return Response.json({ ok: true });
|
|
10
|
+
return Promise.resolve(Response.json({ ok: true }));
|
|
11
11
|
}
|
|
12
|
-
if (req.method === 'GET' && url.pathname === '/runs') {
|
|
13
|
-
return Response.json({
|
|
12
|
+
if (req.method === 'GET' && (url.pathname === '/runs' || url.pathname === '/runs/summaries')) {
|
|
13
|
+
return Promise.resolve(Response.json({
|
|
14
14
|
error: 'Global run listing is not supported in the Durable Object backend without a global index',
|
|
15
|
-
}, { status: 501 });
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const { runId, request } = await resolveRunTarget(req);
|
|
19
|
-
const stub = namespace.getByName(runId);
|
|
20
|
-
return stub.fetch(request);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
// Paths without a resolvable runId (e.g. GET /) are not handled by this router.
|
|
24
|
-
return null;
|
|
15
|
+
}, { status: 501 }));
|
|
25
16
|
}
|
|
17
|
+
return resolveRunTarget(req)
|
|
18
|
+
.then(({ runId, request }) => namespace.getByName(runId).fetch(request))
|
|
19
|
+
.catch((error) => {
|
|
20
|
+
if (error instanceof RunTargetError) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return Promise.reject(error);
|
|
24
|
+
});
|
|
26
25
|
}
|
package/dist/core/catalog.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import type { Schema } from 'effect';
|
|
3
3
|
import { type EventEnvelope, type EventInput, type TypedEvent } from './envelope';
|
|
4
|
-
import {
|
|
4
|
+
import type { JsonValue } from './types';
|
|
5
5
|
declare const catalogPayloadBrand: unique symbol;
|
|
6
6
|
/** Type-only catalog entry. Carries a payload type without a runtime schema. */
|
|
7
7
|
export type CatalogEventSpec<TPayload = object> = {
|
|
@@ -13,11 +13,11 @@ export type CatalogEventSpec<TPayload = object> = {
|
|
|
13
13
|
* `payload<{ amount: number }>()` is a compile-time marker — not a cast of `{}`.
|
|
14
14
|
*/
|
|
15
15
|
export declare function payload<TPayload>(): CatalogEventSpec<TPayload>;
|
|
16
|
-
export type CatalogEntry = CatalogEventSpec | Schema.
|
|
16
|
+
export type CatalogEntry = CatalogEventSpec | Schema.ConstraintDecoder<unknown> | StandardSchemaV1;
|
|
17
17
|
export type CatalogEntries = {
|
|
18
18
|
readonly [key: string]: CatalogEntry;
|
|
19
19
|
};
|
|
20
|
-
export type InferPayload<T> = T extends CatalogEventSpec<infer P> ? P : T extends Schema.
|
|
20
|
+
export type InferPayload<T> = T extends CatalogEventSpec<infer P> ? P : T extends Schema.ConstraintDecoder<unknown> ? Schema.Schema.Type<T> : T extends StandardSchemaV1<infer _In, infer Out> ? Out : JsonValue;
|
|
21
21
|
export interface EventCatalog<TNamespace extends string = string, TEntries extends CatalogEntries = CatalogEntries> {
|
|
22
22
|
readonly namespace: TNamespace;
|
|
23
23
|
readonly entries: TEntries;
|
package/dist/core/catalog.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createEvent } from './envelope.js';
|
|
2
|
-
import { asJson } from './types.js';
|
|
3
2
|
/**
|
|
4
3
|
* Declare a catalog event's payload type when you do not have a Zod / Standard Schema.
|
|
5
4
|
*
|
|
@@ -17,19 +16,17 @@ export function defineEventCatalog(namespace, entries) {
|
|
|
17
16
|
entries,
|
|
18
17
|
event(key, eventPayload, meta) {
|
|
19
18
|
const { runId, ...rest } = meta;
|
|
20
|
-
// SAFETY: createEvent returns EventEnvelope with inferred payload type.
|
|
21
19
|
return createEvent(runId, {
|
|
22
20
|
...rest,
|
|
23
21
|
type: eventType(namespace, key),
|
|
24
|
-
payload:
|
|
22
|
+
payload: eventPayload,
|
|
25
23
|
});
|
|
26
24
|
},
|
|
27
25
|
input(key, eventPayload, meta) {
|
|
28
26
|
return {
|
|
29
27
|
...meta,
|
|
30
28
|
type: eventType(namespace, key),
|
|
31
|
-
|
|
32
|
-
payload: asJson(eventPayload),
|
|
29
|
+
payload: eventPayload,
|
|
33
30
|
};
|
|
34
31
|
},
|
|
35
32
|
};
|
package/dist/core/coalesce.js
CHANGED
|
@@ -90,7 +90,8 @@ export function createCoalescingAppender(flush, options) {
|
|
|
90
90
|
}
|
|
91
91
|
default: {
|
|
92
92
|
const exhaustiveCheck = taken;
|
|
93
|
-
|
|
93
|
+
void exhaustiveCheck;
|
|
94
|
+
return;
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
}
|
|
@@ -135,11 +136,12 @@ export function createCoalescingAppender(flush, options) {
|
|
|
135
136
|
if (result.pending > maxPending) {
|
|
136
137
|
yield* Deferred.await(result.deferred);
|
|
137
138
|
}
|
|
138
|
-
return;
|
|
139
|
+
return undefined;
|
|
139
140
|
}
|
|
140
141
|
default: {
|
|
141
142
|
const exhaustiveCheck = result;
|
|
142
|
-
|
|
143
|
+
void exhaustiveCheck;
|
|
144
|
+
return undefined;
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
147
|
});
|
package/dist/core/compose.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { CatalogEvent, EventCatalog } from './catalog';
|
|
|
3
3
|
import type { EffectDefinition } from './effects';
|
|
4
4
|
import type { EventEnvelope } from './envelope';
|
|
5
5
|
import type { FoldRegistry } from './fold';
|
|
6
|
-
import type { AnyRuntimeModule, EffectMiddleware, RuntimeModule, RegisteredDefinition } from './module';
|
|
6
|
+
import type { AnyRuntimeModule, EffectMiddleware, RuntimeModule, RegisteredDefinition, SignalInterruptRule } from './module';
|
|
7
7
|
import type { ProjectionDefinition } from './projection';
|
|
8
8
|
import { protocolCatalog } from './protocol';
|
|
9
9
|
import type { ThreadDefinition } from './thread';
|
|
@@ -22,6 +22,7 @@ export interface ComposedRegistry extends FoldRegistry {
|
|
|
22
22
|
readonly projections: ReadonlyMap<string, ProjectionDefinition>;
|
|
23
23
|
readonly catalogs: readonly EventCatalog[];
|
|
24
24
|
readonly middleware: readonly EffectMiddleware[];
|
|
25
|
+
readonly interruptRules: readonly SignalInterruptRule[];
|
|
25
26
|
}
|
|
26
27
|
export declare function composeModules(modules: readonly AnyRuntimeModule[]): ComposedRegistry;
|
|
27
28
|
export declare function composeModulesEffect(modules: readonly AnyRuntimeModule[]): Effect.Effect<ComposedRegistry, ModuleCompositionError>;
|
package/dist/core/compose.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Data, Effect } from 'effect';
|
|
2
|
+
import { DEFAULT_DEFINITION_VERSION, definitionKey } from './module.js';
|
|
2
3
|
import { protocolCatalog } from './protocol.js';
|
|
3
4
|
export class ModuleCompositionError extends Data.TaggedError('ModuleCompositionError') {
|
|
4
5
|
constructor(text) {
|
|
@@ -14,6 +15,7 @@ export function composeModules(modules) {
|
|
|
14
15
|
const effects = new Map();
|
|
15
16
|
const projections = new Map();
|
|
16
17
|
const middleware = [];
|
|
18
|
+
const interruptRules = [];
|
|
17
19
|
const catalogs = [protocolCatalog];
|
|
18
20
|
for (const module of modules) {
|
|
19
21
|
if (namespaces.has(module.namespace)) {
|
|
@@ -41,7 +43,8 @@ export function composeModules(modules) {
|
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
for (const definition of module.definitions ?? []) {
|
|
44
|
-
const
|
|
46
|
+
const version = definition.version ?? DEFAULT_DEFINITION_VERSION;
|
|
47
|
+
const key = definitionKey(definition.kind, definition.name, version);
|
|
45
48
|
if (definitionKeys.has(key)) {
|
|
46
49
|
throw new ModuleCompositionError(`Duplicate definition: ${key}`);
|
|
47
50
|
}
|
|
@@ -52,7 +55,9 @@ export function composeModules(modules) {
|
|
|
52
55
|
definitions.push({
|
|
53
56
|
kind: definition.kind,
|
|
54
57
|
name: definition.name,
|
|
58
|
+
version,
|
|
55
59
|
input: definition.input,
|
|
60
|
+
description: definition.description,
|
|
56
61
|
value: definition,
|
|
57
62
|
});
|
|
58
63
|
}
|
|
@@ -76,6 +81,9 @@ export function composeModules(modules) {
|
|
|
76
81
|
if (module.middleware) {
|
|
77
82
|
middleware.push(...module.middleware);
|
|
78
83
|
}
|
|
84
|
+
if (module.interruptsOnSignal) {
|
|
85
|
+
interruptRules.push(module.interruptsOnSignal);
|
|
86
|
+
}
|
|
79
87
|
if (module.projections) {
|
|
80
88
|
for (const definition of Object.values(module.projections)) {
|
|
81
89
|
if (projections.has(definition.name)) {
|
|
@@ -85,7 +93,16 @@ export function composeModules(modules) {
|
|
|
85
93
|
}
|
|
86
94
|
}
|
|
87
95
|
}
|
|
88
|
-
return {
|
|
96
|
+
return {
|
|
97
|
+
definitions,
|
|
98
|
+
modules,
|
|
99
|
+
threads,
|
|
100
|
+
effects,
|
|
101
|
+
projections,
|
|
102
|
+
catalogs,
|
|
103
|
+
middleware,
|
|
104
|
+
interruptRules,
|
|
105
|
+
};
|
|
89
106
|
}
|
|
90
107
|
export function composeModulesEffect(modules) {
|
|
91
108
|
return Effect.try({
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** A request the runtime has matched and authorized under the debugger mount. */
|
|
2
|
+
export interface DebuggerRequest {
|
|
3
|
+
/** Mount path without a trailing slash, such as `/debugger`. */
|
|
4
|
+
readonly basePath: string;
|
|
5
|
+
/** Path below the mount: empty for the mount itself, otherwise it starts with `/`. */
|
|
6
|
+
readonly path: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Serves a debugger UI under `basePath`. The runtime matches, authorizes, and strips the mount
|
|
10
|
+
* path; the host only serves files.
|
|
11
|
+
*/
|
|
12
|
+
export interface DebuggerHost {
|
|
13
|
+
/** Absolute mount path, such as `/debugger`. Must not overlap the HTTP API. */
|
|
14
|
+
readonly basePath: string;
|
|
15
|
+
fetch(req: Request, mount: DebuggerRequest): Promise<Response | null>;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface VersionedDefinition {
|
|
2
|
+
readonly kind: string;
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly version: string;
|
|
5
|
+
}
|
|
6
|
+
/** Lookup of one definition kind by name and version. */
|
|
7
|
+
export interface DefinitionStore<TDefinition> {
|
|
8
|
+
get(name: string, version: string): TDefinition | undefined;
|
|
9
|
+
}
|
|
10
|
+
/** Indexes definitions of one kind by `definitionKey`. */
|
|
11
|
+
export declare function makeDefinitionStore<TDefinition extends VersionedDefinition>(kind: TDefinition['kind'], definitions: ReadonlyArray<TDefinition>): DefinitionStore<TDefinition>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { definitionKey } from './module.js';
|
|
2
|
+
/** Indexes definitions of one kind by `definitionKey`. */
|
|
3
|
+
export function makeDefinitionStore(kind, definitions) {
|
|
4
|
+
const byKey = new Map(definitions.map((definition) => [definitionKey(definition.kind, definition.name, definition.version), definition]));
|
|
5
|
+
return { get: (name, version) => byKey.get(definitionKey(kind, name, version)) };
|
|
6
|
+
}
|
package/dist/core/effects.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Effect } from 'effect';
|
|
2
|
-
import type
|
|
3
|
-
import { type InferDefinedSchema, type SchemaInput } from './schema';
|
|
1
|
+
import { Effect, Schema, type Context } from 'effect';
|
|
2
|
+
import { type EventInput } from './envelope';
|
|
3
|
+
import { type InferDefinedSchema, type InvalidInputError, type SchemaInput } from './schema';
|
|
4
4
|
import { type JsonValue } from './types';
|
|
5
5
|
export type WaitOnEvent = {
|
|
6
6
|
type: string | readonly string[];
|
|
@@ -15,6 +15,7 @@ export type SpawnEffect = {
|
|
|
15
15
|
childThreadId: string;
|
|
16
16
|
kind: string;
|
|
17
17
|
definitionName: string;
|
|
18
|
+
definitionVersion: string;
|
|
18
19
|
input: JsonValue;
|
|
19
20
|
};
|
|
20
21
|
export type WaitEffect = {
|
|
@@ -26,6 +27,8 @@ export type WaitEffect = {
|
|
|
26
27
|
export type EmitEffect<E extends EventInput = EventInput> = {
|
|
27
28
|
type: 'runtime.emit';
|
|
28
29
|
event: E;
|
|
30
|
+
/** Stable identity, so the emit survives reordering of the thread's effects. */
|
|
31
|
+
tag?: string;
|
|
29
32
|
};
|
|
30
33
|
export type CompleteEffect = {
|
|
31
34
|
type: 'runtime.complete';
|
|
@@ -38,11 +41,17 @@ export type FailEffect = {
|
|
|
38
41
|
export type CancelEffect = {
|
|
39
42
|
type: 'runtime.cancel';
|
|
40
43
|
threadId: string;
|
|
44
|
+
tag?: string;
|
|
41
45
|
};
|
|
42
46
|
export interface RetryPolicy {
|
|
43
47
|
readonly maxAttempts: number;
|
|
44
48
|
readonly backoffMs?: number;
|
|
45
49
|
readonly maxBackoffMs?: number;
|
|
50
|
+
readonly backoffMultiplier?: number;
|
|
51
|
+
readonly scheduleToStartTimeoutMs?: number;
|
|
52
|
+
readonly startToCloseTimeoutMs?: number;
|
|
53
|
+
readonly heartbeatTimeoutMs?: number;
|
|
54
|
+
readonly cancellationTimeoutMs?: number;
|
|
46
55
|
}
|
|
47
56
|
export type InvokeEffect = {
|
|
48
57
|
type: string;
|
|
@@ -51,6 +60,69 @@ export type InvokeEffect = {
|
|
|
51
60
|
};
|
|
52
61
|
export type PrimitiveEffect = SpawnEffect | WaitEffect | EmitEffect | CompleteEffect | FailEffect | CancelEffect;
|
|
53
62
|
export type RuntimeEffect = PrimitiveEffect | InvokeEffect;
|
|
63
|
+
export declare const WaitConditionSchema: Schema.Union<readonly [Schema.Struct<{
|
|
64
|
+
readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
|
|
65
|
+
readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
66
|
+
}>, Schema.Struct<{
|
|
67
|
+
readonly timerAt: Schema.Finite;
|
|
68
|
+
}>]>;
|
|
69
|
+
export declare const RuntimeEffectSchema: Schema.Union<readonly [Schema.Struct<{
|
|
70
|
+
readonly type: Schema.Literal<"runtime.spawn">;
|
|
71
|
+
readonly childThreadId: Schema.String;
|
|
72
|
+
readonly kind: Schema.String;
|
|
73
|
+
readonly definitionName: Schema.String;
|
|
74
|
+
readonly definitionVersion: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
75
|
+
readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
76
|
+
}>, Schema.Struct<{
|
|
77
|
+
readonly type: Schema.Literal<"runtime.wait">;
|
|
78
|
+
readonly waitId: Schema.String;
|
|
79
|
+
readonly on: Schema.Union<readonly [Schema.Struct<{
|
|
80
|
+
readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
|
|
81
|
+
readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
82
|
+
}>, Schema.Struct<{
|
|
83
|
+
readonly timerAt: Schema.Finite;
|
|
84
|
+
}>]>;
|
|
85
|
+
readonly tag: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
86
|
+
}>, Schema.Struct<{
|
|
87
|
+
readonly type: Schema.Literal<"runtime.emit">;
|
|
88
|
+
readonly event: Schema.Struct<{
|
|
89
|
+
readonly type: Schema.String;
|
|
90
|
+
readonly payload: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
91
|
+
readonly threadId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
92
|
+
readonly parentThreadId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
93
|
+
readonly causationId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
94
|
+
readonly correlationId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
95
|
+
readonly effectId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
96
|
+
readonly origin: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
97
|
+
readonly type: Schema.Literal<"thread">;
|
|
98
|
+
readonly threadId: Schema.String;
|
|
99
|
+
}>, Schema.Struct<{
|
|
100
|
+
readonly type: Schema.Literal<"external">;
|
|
101
|
+
readonly actorId: Schema.optional<Schema.String>;
|
|
102
|
+
}>, Schema.Struct<{
|
|
103
|
+
readonly type: Schema.Literal<"system">;
|
|
104
|
+
}>]>>;
|
|
105
|
+
readonly ephemeral: Schema.optional<Schema.Boolean>;
|
|
106
|
+
readonly id: Schema.optional<Schema.String>;
|
|
107
|
+
readonly ts: Schema.optional<Schema.Finite>;
|
|
108
|
+
readonly idempotencyKey: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
109
|
+
}>;
|
|
110
|
+
readonly tag: Schema.optional<Schema.String>;
|
|
111
|
+
}>, Schema.Struct<{
|
|
112
|
+
readonly type: Schema.Literal<"runtime.complete">;
|
|
113
|
+
readonly output: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
114
|
+
}>, Schema.Struct<{
|
|
115
|
+
readonly type: Schema.Literal<"runtime.fail">;
|
|
116
|
+
readonly error: Schema.String;
|
|
117
|
+
}>, Schema.Struct<{
|
|
118
|
+
readonly type: Schema.Literal<"runtime.cancel">;
|
|
119
|
+
readonly threadId: Schema.String;
|
|
120
|
+
readonly tag: Schema.optional<Schema.String>;
|
|
121
|
+
}>, Schema.Struct<{
|
|
122
|
+
readonly type: Schema.String;
|
|
123
|
+
readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
124
|
+
readonly tag: Schema.optional<Schema.String>;
|
|
125
|
+
}>]>;
|
|
54
126
|
export declare function isPrimitiveEffect(effect: RuntimeEffect): effect is PrimitiveEffect;
|
|
55
127
|
export declare function isWaitOnTimer(on: WaitCondition): on is WaitOnTimer;
|
|
56
128
|
export declare function isWaitOnEvent(on: WaitCondition): on is WaitOnEvent;
|
|
@@ -62,6 +134,7 @@ export interface EffectContext {
|
|
|
62
134
|
readonly runId: string;
|
|
63
135
|
readonly threadId: string;
|
|
64
136
|
readonly causingEventId: string;
|
|
137
|
+
readonly signal: AbortSignal;
|
|
65
138
|
emit(event: EventInput): Promise<void>;
|
|
66
139
|
}
|
|
67
140
|
export interface ScopedEffectContext<E extends EventInput = EventInput> {
|
|
@@ -69,32 +142,60 @@ export interface ScopedEffectContext<E extends EventInput = EventInput> {
|
|
|
69
142
|
readonly runId: string;
|
|
70
143
|
readonly threadId: string;
|
|
71
144
|
readonly causingEventId: string;
|
|
145
|
+
readonly signal: AbortSignal;
|
|
72
146
|
emit(event: E): Promise<void>;
|
|
73
147
|
}
|
|
74
148
|
export type EffectInputSchema = SchemaInput;
|
|
75
|
-
|
|
76
|
-
|
|
149
|
+
declare const EffectHandlerError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
150
|
+
readonly _tag: "EffectHandlerError";
|
|
151
|
+
} & Readonly<A>;
|
|
152
|
+
export declare class EffectHandlerError extends EffectHandlerError_base<{
|
|
153
|
+
readonly cause: unknown;
|
|
154
|
+
readonly message: string;
|
|
155
|
+
}> {
|
|
156
|
+
constructor(cause: unknown);
|
|
157
|
+
}
|
|
158
|
+
export type EffectHandlerResult<R = never, E extends EventInput = EventInput, HandlerError = never> = ReadonlyArray<E> | Promise<ReadonlyArray<E>> | Effect.Effect<ReadonlyArray<E>, HandlerError, R>;
|
|
159
|
+
declare const effectInputType: unique symbol;
|
|
160
|
+
export type EffectExecution = 'local' | 'worker';
|
|
161
|
+
export interface EffectDefinition<TInput = JsonValue, R = Context.Service.Any, E extends EventInput = EventInput> {
|
|
77
162
|
readonly type: string;
|
|
78
163
|
readonly input?: SchemaInput;
|
|
79
164
|
readonly retry?: RetryPolicy;
|
|
80
|
-
|
|
165
|
+
/** Forces where the effect runs. When omitted, the runtime decides from `hasHandler` and the configured worker. */
|
|
166
|
+
readonly execution?: EffectExecution;
|
|
167
|
+
/** Whether `execute` runs a user handler. Without one, the effect can only complete through a worker. */
|
|
168
|
+
readonly hasHandler: boolean;
|
|
169
|
+
readonly [effectInputType]?: (input: TInput) => TInput;
|
|
170
|
+
execute(input: JsonValue, ctx: EffectContext): Effect.Effect<ReadonlyArray<E>, InvalidInputError | EffectHandlerError, R>;
|
|
81
171
|
}
|
|
82
172
|
/**
|
|
83
|
-
* Define an effect
|
|
84
|
-
* once while it is alive
|
|
85
|
-
* actor may re-run
|
|
173
|
+
* Define an effect. With `execute`, a run's actor cell runs the handler at
|
|
174
|
+
* most once while it is alive; if the cell dies mid-execution, the replacement
|
|
175
|
+
* actor may re-run it (at-least-once across failover). Keep handlers
|
|
86
176
|
* idempotent when they have external side effects.
|
|
177
|
+
*
|
|
178
|
+
* Omit `execute` to declare an effect that only an `EffectWorker` completes.
|
|
87
179
|
*/
|
|
88
|
-
export declare function defineEffect<TSchema
|
|
180
|
+
export declare function defineEffect<TSchema extends SchemaInput, R = never, E extends EventInput = EventInput, HandlerError = never>(def: {
|
|
181
|
+
type: string;
|
|
182
|
+
input: TSchema;
|
|
183
|
+
retry?: RetryPolicy;
|
|
184
|
+
execution?: EffectExecution;
|
|
185
|
+
execute?: (input: InferDefinedSchema<TSchema>, ctx: EffectContext) => EffectHandlerResult<R, E, HandlerError>;
|
|
186
|
+
}): EffectDefinition<InferDefinedSchema<TSchema>, R, E>;
|
|
187
|
+
export declare function defineEffect<R = never, E extends EventInput = EventInput, HandlerError = never>(def: {
|
|
89
188
|
type: string;
|
|
90
|
-
input?:
|
|
189
|
+
input?: undefined;
|
|
91
190
|
retry?: RetryPolicy;
|
|
92
|
-
|
|
93
|
-
|
|
191
|
+
execution?: EffectExecution;
|
|
192
|
+
execute?: (input: JsonValue, ctx: EffectContext) => EffectHandlerResult<R, E, HandlerError>;
|
|
193
|
+
}): EffectDefinition<JsonValue, R, E>;
|
|
94
194
|
export declare function spawn(args: {
|
|
95
195
|
childThreadId?: string;
|
|
96
196
|
kind: string;
|
|
97
197
|
definitionName: string;
|
|
198
|
+
definitionVersion?: string;
|
|
98
199
|
input: JsonValue;
|
|
99
200
|
}): SpawnEffect;
|
|
100
201
|
export declare function wait(args: {
|
|
@@ -102,9 +203,20 @@ export declare function wait(args: {
|
|
|
102
203
|
on: WaitCondition;
|
|
103
204
|
tag?: JsonValue;
|
|
104
205
|
}): WaitEffect;
|
|
105
|
-
export
|
|
206
|
+
export interface WaitOutcome {
|
|
207
|
+
readonly result: JsonValue | null;
|
|
208
|
+
readonly error: string | null;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Reads the outcome of a satisfied wait. The wait fails when the satisfying event's payload has an
|
|
212
|
+
* `error`, or when the waiter put an `error` on the wait's tag (such as a timeout that loses a
|
|
213
|
+
* race). Otherwise the result is the payload's `output`, else the whole payload.
|
|
214
|
+
*/
|
|
215
|
+
export declare function waitOutcome(satisfied: JsonValue | undefined, tag: JsonValue | undefined, fallback?: JsonValue | null): WaitOutcome;
|
|
216
|
+
export declare function emit<E extends EventInput = EventInput>(event: E, tag?: string): EmitEffect<E>;
|
|
106
217
|
export declare function complete(output: JsonValue): CompleteEffect;
|
|
107
218
|
export declare function fail(error: string): FailEffect;
|
|
108
|
-
export declare function cancel(threadId: string): CancelEffect;
|
|
219
|
+
export declare function cancel(threadId: string, tag?: string): CancelEffect;
|
|
109
220
|
export declare function invoke<TInput>(definition: EffectDefinition<TInput, any, any>, input: TInput, tag?: string): InvokeEffect;
|
|
110
221
|
export declare function invoke(type: string, input: JsonValue, tag?: string): InvokeEffect;
|
|
222
|
+
export {};
|