@rikalabs/akter 0.1.0-alpha.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 +15 -0
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +116 -0
- package/dist/actor/codecs.d.ts +77 -0
- package/dist/actor/codecs.js +87 -0
- package/dist/actor/connections.d.ts +34 -0
- package/dist/actor/connections.js +145 -0
- package/dist/actor/definition.d.ts +893 -0
- package/dist/actor/definition.js +147 -0
- package/dist/actor/descriptor.d.ts +172 -0
- package/dist/actor/descriptor.js +367 -0
- package/dist/actor/handles.d.ts +77 -0
- package/dist/actor/handles.js +265 -0
- package/dist/actor/jobs.d.ts +10 -0
- package/dist/actor/jobs.js +137 -0
- package/dist/actor/layers.d.ts +41 -0
- package/dist/actor/layers.js +177 -0
- package/dist/actor/reads.d.ts +47 -0
- package/dist/actor/reads.js +224 -0
- package/dist/actor/served.d.ts +120 -0
- package/dist/actor/served.js +72 -0
- package/dist/actor/turns.d.ts +13 -0
- package/dist/actor/turns.js +332 -0
- package/dist/actor/workflows.d.ts +16 -0
- package/dist/actor/workflows.js +37 -0
- package/dist/client/calls.d.ts +47 -0
- package/dist/client/calls.js +425 -0
- package/dist/client/clock.d.ts +56 -0
- package/dist/client/clock.js +119 -0
- package/dist/client/fleet-page.d.ts +15 -0
- package/dist/client/fleet-page.js +13 -0
- package/dist/client/fleet.d.ts +29 -0
- package/dist/client/fleet.js +51 -0
- package/dist/client/index.d.ts +17 -0
- package/dist/client/index.js +6 -0
- package/dist/client/make.d.ts +157 -0
- package/dist/client/make.js +221 -0
- package/dist/client/offline/queue.d.ts +118 -0
- package/dist/client/offline/queue.js +292 -0
- package/dist/client/offline/store.d.ts +74 -0
- package/dist/client/offline/store.js +78 -0
- package/dist/client/optimistic.d.ts +57 -0
- package/dist/client/optimistic.js +136 -0
- package/dist/client/report.d.ts +2 -0
- package/dist/client/report.js +8 -0
- package/dist/client/sessions/connection.d.ts +118 -0
- package/dist/client/sessions/connection.js +162 -0
- package/dist/client/sessions/feed.d.ts +42 -0
- package/dist/client/sessions/feed.js +43 -0
- package/dist/client/sessions/sse.d.ts +47 -0
- package/dist/client/sessions/sse.js +112 -0
- package/dist/client/sessions/stream.d.ts +28 -0
- package/dist/client/sessions/stream.js +35 -0
- package/dist/client/sessions/watch.d.ts +34 -0
- package/dist/client/sessions/watch.js +40 -0
- package/dist/client/transport.d.ts +37 -0
- package/dist/client/transport.js +66 -0
- package/dist/contexts/command.d.ts +132 -0
- package/dist/contexts/command.js +20 -0
- package/dist/contexts/connection.d.ts +68 -0
- package/dist/contexts/connection.js +0 -0
- package/dist/contexts/job.d.ts +49 -0
- package/dist/contexts/job.js +0 -0
- package/dist/contexts/workflow.d.ts +147 -0
- package/dist/contexts/workflow.js +22 -0
- package/dist/errors/actor.d.ts +200 -0
- package/dist/errors/actor.js +271 -0
- package/dist/errors/content.d.ts +19 -0
- package/dist/errors/content.js +14 -0
- package/dist/errors/database.d.ts +22 -0
- package/dist/errors/database.js +23 -0
- package/dist/errors/events.d.ts +17 -0
- package/dist/errors/events.js +14 -0
- package/dist/errors/subscription.d.ts +12 -0
- package/dist/errors/subscription.js +8 -0
- package/dist/errors/workflow.d.ts +28 -0
- package/dist/errors/workflow.js +17 -0
- package/dist/handles/actors.d.ts +17 -0
- package/dist/handles/actors.js +7 -0
- package/dist/handles/content.d.ts +59 -0
- package/dist/handles/content.js +36 -0
- package/dist/handles/intents.d.ts +164 -0
- package/dist/handles/intents.js +214 -0
- package/dist/handles/run.d.ts +31 -0
- package/dist/handles/run.js +21 -0
- package/dist/handles/workflow.d.ts +27 -0
- package/dist/handles/workflow.js +23 -0
- package/dist/identity/caller.d.ts +105 -0
- package/dist/identity/caller.js +68 -0
- package/dist/identity/child.d.ts +18 -0
- package/dist/identity/child.js +39 -0
- package/dist/identity/command.d.ts +19 -0
- package/dist/identity/command.js +21 -0
- package/dist/identity/connection.d.ts +24 -0
- package/dist/identity/connection.js +29 -0
- package/dist/identity/content.d.ts +18 -0
- package/dist/identity/content.js +12 -0
- package/dist/identity/digest.d.ts +4 -0
- package/dist/identity/digest.js +5 -0
- package/dist/identity/execution.d.ts +32 -0
- package/dist/identity/execution.js +63 -0
- package/dist/identity/mint.d.ts +51 -0
- package/dist/identity/mint.js +76 -0
- package/dist/identity/version.d.ts +2 -0
- package/dist/identity/version.js +3 -0
- package/dist/index.d.ts +159 -0
- package/dist/index.js +97 -0
- package/dist/members/blob.d.ts +43 -0
- package/dist/members/blob.js +29 -0
- package/dist/members/command.d.ts +109 -0
- package/dist/members/command.js +61 -0
- package/dist/members/connection.d.ts +55 -0
- package/dist/members/connection.js +49 -0
- package/dist/members/event.d.ts +36 -0
- package/dist/members/event.js +24 -0
- package/dist/members/job.d.ts +157 -0
- package/dist/members/job.js +67 -0
- package/dist/members/payload.d.ts +93 -0
- package/dist/members/payload.js +145 -0
- package/dist/members/reducer.d.ts +64 -0
- package/dist/members/reducer.js +27 -0
- package/dist/members/stream.d.ts +36 -0
- package/dist/members/stream.js +14 -0
- package/dist/members/subscription.d.ts +182 -0
- package/dist/members/subscription.js +91 -0
- package/dist/members/workflow.d.ts +99 -0
- package/dist/members/workflow.js +2 -0
- package/dist/policies/access.d.ts +35 -0
- package/dist/policies/access.js +6 -0
- package/dist/policies/command.d.ts +127 -0
- package/dist/policies/command.js +45 -0
- package/dist/policies/job.d.ts +28 -0
- package/dist/policies/job.js +60 -0
- package/dist/policies/schedules.d.ts +33 -0
- package/dist/policies/schedules.js +131 -0
- package/dist/protocol/frames.d.ts +66 -0
- package/dist/protocol/frames.js +55 -0
- package/dist/protocol/inspection.d.ts +807 -0
- package/dist/protocol/inspection.js +243 -0
- package/dist/protocol/wire.d.ts +184 -0
- package/dist/protocol/wire.js +150 -0
- package/dist/runtime/actors.d.ts +155 -0
- package/dist/runtime/actors.js +4 -0
- package/dist/runtime/admission.d.ts +34 -0
- package/dist/runtime/admission.js +72 -0
- package/dist/runtime/adoption/backfill.d.ts +27 -0
- package/dist/runtime/adoption/backfill.js +144 -0
- package/dist/runtime/adoption/enforce.d.ts +55 -0
- package/dist/runtime/adoption/enforce.js +241 -0
- package/dist/runtime/adoption/observe.d.ts +43 -0
- package/dist/runtime/adoption/observe.js +139 -0
- package/dist/runtime/adoption/plan.d.ts +45 -0
- package/dist/runtime/adoption/plan.js +192 -0
- package/dist/runtime/adoption/startup.d.ts +32 -0
- package/dist/runtime/adoption/startup.js +76 -0
- package/dist/runtime/adoption/status.d.ts +23 -0
- package/dist/runtime/adoption/status.js +47 -0
- package/dist/runtime/adoption/target.d.ts +33 -0
- package/dist/runtime/adoption/target.js +49 -0
- package/dist/runtime/connections/holder.d.ts +221 -0
- package/dist/runtime/connections/holder.js +816 -0
- package/dist/runtime/connections/owner.d.ts +263 -0
- package/dist/runtime/connections/owner.js +896 -0
- package/dist/runtime/connections/protocol.d.ts +441 -0
- package/dist/runtime/connections/protocol.js +222 -0
- package/dist/runtime/connections/reads.d.ts +24 -0
- package/dist/runtime/connections/reads.js +19 -0
- package/dist/runtime/connections/streams.d.ts +62 -0
- package/dist/runtime/connections/streams.js +128 -0
- package/dist/runtime/connections/transport.d.ts +40 -0
- package/dist/runtime/connections/transport.js +68 -0
- package/dist/runtime/connections/watch.d.ts +52 -0
- package/dist/runtime/connections/watch.js +159 -0
- package/dist/runtime/content/grant.d.ts +34 -0
- package/dist/runtime/content/grant.js +58 -0
- package/dist/runtime/content/store.d.ts +63 -0
- package/dist/runtime/content/store.js +294 -0
- package/dist/runtime/cron/key.d.ts +2 -0
- package/dist/runtime/cron/key.js +2 -0
- package/dist/runtime/cron/schedule.d.ts +69 -0
- package/dist/runtime/cron/schedule.js +144 -0
- package/dist/runtime/database/bounded.d.ts +43 -0
- package/dist/runtime/database/bounded.js +108 -0
- package/dist/runtime/database/connection.d.ts +8 -0
- package/dist/runtime/database/connection.js +18 -0
- package/dist/runtime/database/coordination.d.ts +19 -0
- package/dist/runtime/database/coordination.js +72 -0
- package/dist/runtime/database/flock.d.ts +10 -0
- package/dist/runtime/database/flock.js +60 -0
- package/dist/runtime/database/gate.d.ts +26 -0
- package/dist/runtime/database/gate.js +54 -0
- package/dist/runtime/database/keepalive.d.ts +11 -0
- package/dist/runtime/database/keepalive.js +22 -0
- package/dist/runtime/database/migrations.d.ts +177 -0
- package/dist/runtime/database/migrations.js +1018 -0
- package/dist/runtime/database/neki/migrations.d.ts +31 -0
- package/dist/runtime/database/neki/migrations.js +276 -0
- package/dist/runtime/database/neki/session.d.ts +23 -0
- package/dist/runtime/database/neki/session.js +31 -0
- package/dist/runtime/database/pglite.d.ts +21 -0
- package/dist/runtime/database/pglite.js +74 -0
- package/dist/runtime/database/replica.d.ts +41 -0
- package/dist/runtime/database/replica.js +51 -0
- package/dist/runtime/database/shards.d.ts +21 -0
- package/dist/runtime/database/shards.js +37 -0
- package/dist/runtime/database/snapshot.d.ts +7 -0
- package/dist/runtime/database/snapshot.js +7 -0
- package/dist/runtime/database/tenancy.d.ts +69 -0
- package/dist/runtime/database/tenancy.js +145 -0
- package/dist/runtime/database/transient.d.ts +10 -0
- package/dist/runtime/database/transient.js +25 -0
- package/dist/runtime/drain.d.ts +132 -0
- package/dist/runtime/drain.js +109 -0
- package/dist/runtime/entity/mailbox.d.ts +86 -0
- package/dist/runtime/entity/mailbox.js +121 -0
- package/dist/runtime/entity/register.d.ts +424 -0
- package/dist/runtime/entity/register.js +669 -0
- package/dist/runtime/events/append.d.ts +192 -0
- package/dist/runtime/events/append.js +128 -0
- package/dist/runtime/events/cursor.d.ts +2 -0
- package/dist/runtime/events/cursor.js +5 -0
- package/dist/runtime/events/replay.d.ts +20 -0
- package/dist/runtime/events/replay.js +45 -0
- package/dist/runtime/feeds.d.ts +26 -0
- package/dist/runtime/feeds.js +100 -0
- package/dist/runtime/fleet/checks.d.ts +17 -0
- package/dist/runtime/fleet/checks.js +106 -0
- package/dist/runtime/fleet/maintainer.d.ts +38 -0
- package/dist/runtime/fleet/maintainer.js +383 -0
- package/dist/runtime/fleet/pgoutput.d.ts +41 -0
- package/dist/runtime/fleet/pgoutput.js +102 -0
- package/dist/runtime/fleet/setup.d.ts +36 -0
- package/dist/runtime/fleet/setup.js +58 -0
- package/dist/runtime/fleet/subscribe.d.ts +42 -0
- package/dist/runtime/fleet/subscribe.js +147 -0
- package/dist/runtime/index.d.ts +66 -0
- package/dist/runtime/index.js +37 -0
- package/dist/runtime/inspector/http.d.ts +19 -0
- package/dist/runtime/inspector/http.js +36 -0
- package/dist/runtime/inspector/layer.d.ts +46 -0
- package/dist/runtime/inspector/layer.js +180 -0
- package/dist/runtime/inspector/queries.d.ts +711 -0
- package/dist/runtime/inspector/queries.js +494 -0
- package/dist/runtime/jobs/attempt.d.ts +254 -0
- package/dist/runtime/jobs/attempt.js +413 -0
- package/dist/runtime/jobs/isolation.d.ts +20 -0
- package/dist/runtime/jobs/isolation.js +10 -0
- package/dist/runtime/jobs/progress.d.ts +95 -0
- package/dist/runtime/jobs/progress.js +144 -0
- package/dist/runtime/layer.d.ts +260 -0
- package/dist/runtime/layer.js +876 -0
- package/dist/runtime/members.d.ts +381 -0
- package/dist/runtime/members.js +8 -0
- package/dist/runtime/operators/audit.d.ts +64 -0
- package/dist/runtime/operators/audit.js +56 -0
- package/dist/runtime/operators/auth.d.ts +29 -0
- package/dist/runtime/operators/auth.js +42 -0
- package/dist/runtime/operators/export.d.ts +68 -0
- package/dist/runtime/operators/export.js +137 -0
- package/dist/runtime/operators/grants.d.ts +45 -0
- package/dist/runtime/operators/grants.js +40 -0
- package/dist/runtime/operators/repair.d.ts +206 -0
- package/dist/runtime/operators/repair.js +226 -0
- package/dist/runtime/operators/routes.d.ts +35 -0
- package/dist/runtime/operators/routes.js +190 -0
- package/dist/runtime/operators/seed.d.ts +123 -0
- package/dist/runtime/operators/seed.js +123 -0
- package/dist/runtime/payloads/versions.d.ts +65 -0
- package/dist/runtime/payloads/versions.js +240 -0
- package/dist/runtime/peering/authority.d.ts +42 -0
- package/dist/runtime/peering/authority.js +132 -0
- package/dist/runtime/peering/credentials.d.ts +21 -0
- package/dist/runtime/peering/credentials.js +13 -0
- package/dist/runtime/peering/transport.d.ts +51 -0
- package/dist/runtime/peering/transport.js +175 -0
- package/dist/runtime/queries.d.ts +18 -0
- package/dist/runtime/queries.js +169 -0
- package/dist/runtime/readiness.d.ts +36 -0
- package/dist/runtime/readiness.js +44 -0
- package/dist/runtime/registration.d.ts +58 -0
- package/dist/runtime/registration.js +186 -0
- package/dist/runtime/request.d.ts +158 -0
- package/dist/runtime/request.js +102 -0
- package/dist/runtime/retry.d.ts +8 -0
- package/dist/runtime/retry.js +11 -0
- package/dist/runtime/runner.d.ts +93 -0
- package/dist/runtime/runner.js +122 -0
- package/dist/runtime/storage/codec.d.ts +39 -0
- package/dist/runtime/storage/codec.js +41 -0
- package/dist/runtime/storage/generation.d.ts +69 -0
- package/dist/runtime/storage/generation.js +49 -0
- package/dist/runtime/storage/placements.d.ts +15 -0
- package/dist/runtime/storage/placements.js +38 -0
- package/dist/runtime/storage/platform.d.ts +6 -0
- package/dist/runtime/storage/platform.js +9 -0
- package/dist/runtime/storage/retention.d.ts +73 -0
- package/dist/runtime/storage/retention.js +158 -0
- package/dist/runtime/subscriptions/identity.d.ts +31 -0
- package/dist/runtime/subscriptions/identity.js +45 -0
- package/dist/runtime/subscriptions/relay.d.ts +175 -0
- package/dist/runtime/subscriptions/relay.js +763 -0
- package/dist/runtime/subscriptions/storage.d.ts +40 -0
- package/dist/runtime/subscriptions/storage.js +98 -0
- package/dist/runtime/sweeps.d.ts +39 -0
- package/dist/runtime/sweeps.js +54 -0
- package/dist/runtime/telemetry/defects.d.ts +57 -0
- package/dist/runtime/telemetry/defects.js +43 -0
- package/dist/runtime/telemetry/metrics.d.ts +52 -0
- package/dist/runtime/telemetry/metrics.js +138 -0
- package/dist/runtime/telemetry/routes.d.ts +19 -0
- package/dist/runtime/telemetry/routes.js +18 -0
- package/dist/runtime/telemetry/sampler.d.ts +26 -0
- package/dist/runtime/telemetry/sampler.js +101 -0
- package/dist/runtime/telemetry/spans.d.ts +38 -0
- package/dist/runtime/telemetry/spans.js +44 -0
- package/dist/runtime/telemetry/usage.d.ts +52 -0
- package/dist/runtime/telemetry/usage.js +30 -0
- package/dist/runtime/topology/admission.d.ts +13 -0
- package/dist/runtime/topology/admission.js +36 -0
- package/dist/runtime/topology/locks.d.ts +56 -0
- package/dist/runtime/topology/locks.js +81 -0
- package/dist/runtime/topology/messages.d.ts +15 -0
- package/dist/runtime/topology/messages.js +32 -0
- package/dist/runtime/turn/admission.d.ts +22 -0
- package/dist/runtime/turn/admission.js +41 -0
- package/dist/runtime/turn/blobs.d.ts +38 -0
- package/dist/runtime/turn/blobs.js +215 -0
- package/dist/runtime/turn/execute.d.ts +208 -0
- package/dist/runtime/turn/execute.js +972 -0
- package/dist/runtime/turn/group.d.ts +165 -0
- package/dist/runtime/turn/group.js +326 -0
- package/dist/runtime/turn/hooks.d.ts +44 -0
- package/dist/runtime/turn/hooks.js +28 -0
- package/dist/runtime/turn/outbox.d.ts +159 -0
- package/dist/runtime/turn/outbox.js +269 -0
- package/dist/runtime/turn/pipeline.d.ts +68 -0
- package/dist/runtime/turn/pipeline.js +83 -0
- package/dist/runtime/turn/receipt.d.ts +81 -0
- package/dist/runtime/turn/receipt.js +32 -0
- package/dist/runtime/turn/relay.d.ts +179 -0
- package/dist/runtime/turn/relay.js +685 -0
- package/dist/runtime/turn/rows.d.ts +43 -0
- package/dist/runtime/turn/rows.js +592 -0
- package/dist/runtime/workflows/compatibility.d.ts +125 -0
- package/dist/runtime/workflows/compatibility.js +285 -0
- package/dist/runtime/workflows/engine.d.ts +107 -0
- package/dist/runtime/workflows/engine.js +826 -0
- package/dist/runtime/workflows/manifest.d.ts +34 -0
- package/dist/runtime/workflows/manifest.js +39 -0
- package/dist/runtime/workflows/steps.d.ts +33 -0
- package/dist/runtime/workflows/steps.js +152 -0
- package/dist/serve/api.d.ts +99 -0
- package/dist/serve/api.js +403 -0
- package/dist/serve/assertion/binding.d.ts +41 -0
- package/dist/serve/assertion/binding.js +92 -0
- package/dist/serve/assertion/verify.d.ts +93 -0
- package/dist/serve/assertion/verify.js +189 -0
- package/dist/serve/auth.d.ts +200 -0
- package/dist/serve/auth.js +92 -0
- package/dist/serve/clock.d.ts +10 -0
- package/dist/serve/clock.js +25 -0
- package/dist/serve/jwt.d.ts +65 -0
- package/dist/serve/jwt.js +202 -0
- package/dist/serve/layer.d.ts +98 -0
- package/dist/serve/layer.js +809 -0
- package/dist/serve/mcp/endpoint.d.ts +39 -0
- package/dist/serve/mcp/endpoint.js +187 -0
- package/dist/serve/mcp/tools.d.ts +37 -0
- package/dist/serve/mcp/tools.js +125 -0
- package/dist/serve/origin.d.ts +6 -0
- package/dist/serve/origin.js +21 -0
- package/dist/serve/sessions/feed.d.ts +79 -0
- package/dist/serve/sessions/feed.js +115 -0
- package/dist/serve/sessions/socket.d.ts +56 -0
- package/dist/serve/sessions/socket.js +212 -0
- package/dist/serve/sessions/sse.d.ts +27 -0
- package/dist/serve/sessions/sse.js +26 -0
- package/dist/serve/sessions/stream.d.ts +9 -0
- package/dist/serve/sessions/stream.js +9 -0
- package/dist/serve/sessions/watch.d.ts +12 -0
- package/dist/serve/sessions/watch.js +11 -0
- package/dist/serve/wire.d.ts +16 -0
- package/dist/serve/wire.js +50 -0
- package/dist/state/blob.d.ts +71 -0
- package/dist/state/blob.js +0 -0
- package/dist/state/migration.d.ts +53 -0
- package/dist/state/migration.js +29 -0
- package/dist/tables/fleet.d.ts +170 -0
- package/dist/tables/fleet.js +214 -0
- package/dist/tables/owned.d.ts +250 -0
- package/dist/tables/owned.js +233 -0
- package/dist/testing/actor-test.d.ts +360 -0
- package/dist/testing/actor-test.js +337 -0
- package/dist/testing/cluster.d.ts +93 -0
- package/dist/testing/cluster.js +296 -0
- package/dist/testing/conformance/access.d.ts +5 -0
- package/dist/testing/conformance/access.js +531 -0
- package/dist/testing/conformance/admission.d.ts +11 -0
- package/dist/testing/conformance/admission.js +182 -0
- package/dist/testing/conformance/adoption.d.ts +2 -0
- package/dist/testing/conformance/adoption.js +1019 -0
- package/dist/testing/conformance/assertions.d.ts +202 -0
- package/dist/testing/conformance/assertions.js +849 -0
- package/dist/testing/conformance/batches.d.ts +41 -0
- package/dist/testing/conformance/batches.js +388 -0
- package/dist/testing/conformance/blobs.d.ts +14 -0
- package/dist/testing/conformance/blobs.js +405 -0
- package/dist/testing/conformance/capacity.d.ts +8 -0
- package/dist/testing/conformance/capacity.js +433 -0
- package/dist/testing/conformance/client.d.ts +5 -0
- package/dist/testing/conformance/client.js +719 -0
- package/dist/testing/conformance/cold-serve.d.ts +16 -0
- package/dist/testing/conformance/cold-serve.js +254 -0
- package/dist/testing/conformance/connections/actors.d.ts +1143 -0
- package/dist/testing/conformance/connections/actors.js +180 -0
- package/dist/testing/conformance/connections/harness.d.ts +1754 -0
- package/dist/testing/conformance/connections/harness.js +142 -0
- package/dist/testing/conformance/connections/holders.d.ts +4 -0
- package/dist/testing/conformance/connections/holders.js +165 -0
- package/dist/testing/conformance/connections/lifecycle.d.ts +4 -0
- package/dist/testing/conformance/connections/lifecycle.js +113 -0
- package/dist/testing/conformance/connections/limits.d.ts +4 -0
- package/dist/testing/conformance/connections/limits.js +127 -0
- package/dist/testing/conformance/connections/reauthorization.d.ts +4 -0
- package/dist/testing/conformance/connections/reauthorization.js +170 -0
- package/dist/testing/conformance/connections/resync.d.ts +4 -0
- package/dist/testing/conformance/connections/resync.js +360 -0
- package/dist/testing/conformance/connections/takeover.d.ts +4 -0
- package/dist/testing/conformance/connections/takeover.js +287 -0
- package/dist/testing/conformance/connections.d.ts +4 -0
- package/dist/testing/conformance/connections.js +15 -0
- package/dist/testing/conformance/content-blobs.d.ts +16 -0
- package/dist/testing/conformance/content-blobs.js +534 -0
- package/dist/testing/conformance/counter.d.ts +16 -0
- package/dist/testing/conformance/counter.js +813 -0
- package/dist/testing/conformance/cron.d.ts +5 -0
- package/dist/testing/conformance/cron.js +665 -0
- package/dist/testing/conformance/drain.d.ts +26 -0
- package/dist/testing/conformance/drain.js +540 -0
- package/dist/testing/conformance/effect-control.d.ts +38 -0
- package/dist/testing/conformance/effect-control.js +1059 -0
- package/dist/testing/conformance/effects.d.ts +23 -0
- package/dist/testing/conformance/effects.js +432 -0
- package/dist/testing/conformance/events.d.ts +28 -0
- package/dist/testing/conformance/events.js +335 -0
- package/dist/testing/conformance/export.d.ts +2 -0
- package/dist/testing/conformance/export.js +368 -0
- package/dist/testing/conformance/fleet.d.ts +444 -0
- package/dist/testing/conformance/fleet.js +1009 -0
- package/dist/testing/conformance/groups.d.ts +7 -0
- package/dist/testing/conformance/groups.js +353 -0
- package/dist/testing/conformance/heap.d.ts +3 -0
- package/dist/testing/conformance/heap.js +149 -0
- package/dist/testing/conformance/http.d.ts +2809 -0
- package/dist/testing/conformance/http.js +1234 -0
- package/dist/testing/conformance/inspection-views.d.ts +8 -0
- package/dist/testing/conformance/inspection-views.js +272 -0
- package/dist/testing/conformance/inspector.d.ts +7 -0
- package/dist/testing/conformance/inspector.js +650 -0
- package/dist/testing/conformance/mint.d.ts +58 -0
- package/dist/testing/conformance/mint.js +692 -0
- package/dist/testing/conformance/multi-runner.d.ts +8 -0
- package/dist/testing/conformance/multi-runner.js +403 -0
- package/dist/testing/conformance/neki/plan.d.ts +19 -0
- package/dist/testing/conformance/neki/plan.js +30 -0
- package/dist/testing/conformance/observability.d.ts +3 -0
- package/dist/testing/conformance/observability.js +343 -0
- package/dist/testing/conformance/offline.d.ts +4 -0
- package/dist/testing/conformance/offline.js +474 -0
- package/dist/testing/conformance/operator-harness.d.ts +57 -0
- package/dist/testing/conformance/operator-harness.js +78 -0
- package/dist/testing/conformance/operator.d.ts +3 -0
- package/dist/testing/conformance/operator.js +379 -0
- package/dist/testing/conformance/outbox-cross-shard.d.ts +14 -0
- package/dist/testing/conformance/outbox-cross-shard.js +160 -0
- package/dist/testing/conformance/outbox.d.ts +36 -0
- package/dist/testing/conformance/outbox.js +437 -0
- package/dist/testing/conformance/payload-migrations.d.ts +3 -0
- package/dist/testing/conformance/payload-migrations.js +612 -0
- package/dist/testing/conformance/pipeline.d.ts +3 -0
- package/dist/testing/conformance/pipeline.js +1040 -0
- package/dist/testing/conformance/placement.d.ts +22 -0
- package/dist/testing/conformance/placement.js +539 -0
- package/dist/testing/conformance/platform.d.ts +40 -0
- package/dist/testing/conformance/platform.js +101 -0
- package/dist/testing/conformance/progress.d.ts +39 -0
- package/dist/testing/conformance/progress.js +666 -0
- package/dist/testing/conformance/properties.d.ts +6 -0
- package/dist/testing/conformance/properties.js +295 -0
- package/dist/testing/conformance/protocols.d.ts +4 -0
- package/dist/testing/conformance/protocols.js +618 -0
- package/dist/testing/conformance/provider/advertise.d.ts +21 -0
- package/dist/testing/conformance/provider/advertise.js +44 -0
- package/dist/testing/conformance/read-your-writes.d.ts +20 -0
- package/dist/testing/conformance/read-your-writes.js +192 -0
- package/dist/testing/conformance/reducers.d.ts +8 -0
- package/dist/testing/conformance/reducers.js +258 -0
- package/dist/testing/conformance/relay.d.ts +42 -0
- package/dist/testing/conformance/relay.js +1115 -0
- package/dist/testing/conformance/restore.d.ts +43 -0
- package/dist/testing/conformance/restore.js +341 -0
- package/dist/testing/conformance/retention.d.ts +14 -0
- package/dist/testing/conformance/retention.js +463 -0
- package/dist/testing/conformance/rls.d.ts +24 -0
- package/dist/testing/conformance/rls.js +576 -0
- package/dist/testing/conformance/simulation.d.ts +31 -0
- package/dist/testing/conformance/simulation.js +167 -0
- package/dist/testing/conformance/single-shard.d.ts +2 -0
- package/dist/testing/conformance/single-shard.js +125 -0
- package/dist/testing/conformance/singleton.d.ts +3 -0
- package/dist/testing/conformance/singleton.js +293 -0
- package/dist/testing/conformance/statements.d.ts +60 -0
- package/dist/testing/conformance/statements.js +108 -0
- package/dist/testing/conformance/streams.d.ts +7 -0
- package/dist/testing/conformance/streams.js +280 -0
- package/dist/testing/conformance/subscriptions/access.d.ts +4 -0
- package/dist/testing/conformance/subscriptions/access.js +98 -0
- package/dist/testing/conformance/subscriptions/actors.d.ts +4910 -0
- package/dist/testing/conformance/subscriptions/actors.js +372 -0
- package/dist/testing/conformance/subscriptions/cluster.d.ts +4 -0
- package/dist/testing/conformance/subscriptions/cluster.js +89 -0
- package/dist/testing/conformance/subscriptions/delivery.d.ts +4 -0
- package/dist/testing/conformance/subscriptions/delivery.js +253 -0
- package/dist/testing/conformance/subscriptions/deploys.d.ts +4 -0
- package/dist/testing/conformance/subscriptions/deploys.js +162 -0
- package/dist/testing/conformance/subscriptions/epochs.d.ts +4 -0
- package/dist/testing/conformance/subscriptions/epochs.js +169 -0
- package/dist/testing/conformance/subscriptions/failures.d.ts +4 -0
- package/dist/testing/conformance/subscriptions/failures.js +108 -0
- package/dist/testing/conformance/subscriptions/feeds.d.ts +4 -0
- package/dist/testing/conformance/subscriptions/feeds.js +218 -0
- package/dist/testing/conformance/subscriptions/harness.d.ts +124 -0
- package/dist/testing/conformance/subscriptions/harness.js +143 -0
- package/dist/testing/conformance/subscriptions/operator.d.ts +4 -0
- package/dist/testing/conformance/subscriptions/operator.js +128 -0
- package/dist/testing/conformance/subscriptions/retention.d.ts +4 -0
- package/dist/testing/conformance/subscriptions/retention.js +288 -0
- package/dist/testing/conformance/subscriptions/routing.d.ts +4 -0
- package/dist/testing/conformance/subscriptions/routing.js +179 -0
- package/dist/testing/conformance/subscriptions.d.ts +4 -0
- package/dist/testing/conformance/subscriptions.js +19 -0
- package/dist/testing/conformance/tables.d.ts +125 -0
- package/dist/testing/conformance/tables.js +664 -0
- package/dist/testing/conformance/transports/actors.d.ts +1907 -0
- package/dist/testing/conformance/transports/actors.js +163 -0
- package/dist/testing/conformance/transports/client.d.ts +3 -0
- package/dist/testing/conformance/transports/client.js +237 -0
- package/dist/testing/conformance/transports/feeds.d.ts +3 -0
- package/dist/testing/conformance/transports/feeds.js +232 -0
- package/dist/testing/conformance/transports/harness.d.ts +93 -0
- package/dist/testing/conformance/transports/harness.js +84 -0
- package/dist/testing/conformance/transports/streams.d.ts +3 -0
- package/dist/testing/conformance/transports/streams.js +96 -0
- package/dist/testing/conformance/transports/websocket.d.ts +3 -0
- package/dist/testing/conformance/transports/websocket.js +384 -0
- package/dist/testing/conformance/transports/wire.d.ts +141 -0
- package/dist/testing/conformance/transports/wire.js +204 -0
- package/dist/testing/conformance/transports.d.ts +3 -0
- package/dist/testing/conformance/transports.js +11 -0
- package/dist/testing/conformance/watch.d.ts +59 -0
- package/dist/testing/conformance/watch.js +879 -0
- package/dist/testing/conformance/workflow-engine.d.ts +97 -0
- package/dist/testing/conformance/workflow-engine.js +253 -0
- package/dist/testing/conformance/workflow-versions.d.ts +3 -0
- package/dist/testing/conformance/workflow-versions.js +545 -0
- package/dist/testing/conformance/workflows/access.d.ts +4 -0
- package/dist/testing/conformance/workflows/access.js +147 -0
- package/dist/testing/conformance/workflows/actors.d.ts +2317 -0
- package/dist/testing/conformance/workflows/actors.js +305 -0
- package/dist/testing/conformance/workflows/basics.d.ts +4 -0
- package/dist/testing/conformance/workflows/basics.js +144 -0
- package/dist/testing/conformance/workflows/engine.d.ts +4 -0
- package/dist/testing/conformance/workflows/engine.js +80 -0
- package/dist/testing/conformance/workflows/guards.d.ts +4 -0
- package/dist/testing/conformance/workflows/guards.js +172 -0
- package/dist/testing/conformance/workflows/harness.d.ts +14 -0
- package/dist/testing/conformance/workflows/harness.js +44 -0
- package/dist/testing/conformance/workflows/recovery.d.ts +4 -0
- package/dist/testing/conformance/workflows/recovery.js +181 -0
- package/dist/testing/conformance/workflows/starts.d.ts +4 -0
- package/dist/testing/conformance/workflows/starts.js +57 -0
- package/dist/testing/conformance/workflows/suspension.d.ts +4 -0
- package/dist/testing/conformance/workflows/suspension.js +106 -0
- package/dist/testing/conformance/workflows/waits.d.ts +4 -0
- package/dist/testing/conformance/workflows/waits.js +284 -0
- package/dist/testing/conformance/workflows.d.ts +4 -0
- package/dist/testing/conformance/workflows.js +19 -0
- package/dist/testing/conformance.d.ts +330 -0
- package/dist/testing/conformance.js +364 -0
- package/dist/testing/database.d.ts +31 -0
- package/dist/testing/database.js +70 -0
- package/dist/testing/foundation.d.ts +41 -0
- package/dist/testing/foundation.js +517 -0
- package/dist/testing/index.d.ts +20 -0
- package/dist/testing/index.js +12 -0
- package/dist/testing/property.d.ts +40 -0
- package/dist/testing/property.js +95 -0
- package/dist/testing/simulate-cluster.d.ts +112 -0
- package/dist/testing/simulate-cluster.js +257 -0
- package/dist/testing/simulate.d.ts +90 -0
- package/dist/testing/simulate.js +127 -0
- package/package.json +1 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { Effect, Result, Schema, Semaphore, Stream } from "effect";
|
|
2
|
+
import { outsideTurn } from "../contexts/command.js";
|
|
3
|
+
import { CallPhase, CurrentCallPhase } from "../contexts/workflow.js";
|
|
4
|
+
import { ActorError, InvalidInput } from "../errors/actor.js";
|
|
5
|
+
import { InvalidExecutionId } from "../errors/workflow.js";
|
|
6
|
+
import { Actors } from "../handles/actors.js";
|
|
7
|
+
import { currentStaging, stageIntent } from "../handles/intents.js";
|
|
8
|
+
import { workflowRun } from "../handles/run.js";
|
|
9
|
+
import { ExecutionIdOutput, ExecutionTarget, INTERRUPT, START, StartPayload, } from "../handles/workflow.js";
|
|
10
|
+
import { ActorRef, Caller, CurrentCaller, Tenant } from "../identity/caller.js";
|
|
11
|
+
import { CurrentCommandId } from "../identity/command.js";
|
|
12
|
+
import { CurrentConnectionCommands } from "../identity/connection.js";
|
|
13
|
+
import { checkExecutionKey, decodeExecutionId, encodeExecutionId } from "../identity/execution.js";
|
|
14
|
+
import { isWorkflow } from "../members/workflow.js";
|
|
15
|
+
import { InternalActors } from "../runtime/actors.js";
|
|
16
|
+
import { Outcome, Request } from "../runtime/request.js";
|
|
17
|
+
const decodeCaller = Schema.decodeEffect(Caller);
|
|
18
|
+
const encodeTarget = Schema.encodeEffect(ExecutionTarget);
|
|
19
|
+
const encodeStartPayload = Schema.encodeEffect(StartPayload);
|
|
20
|
+
const decodeExecutionIdOutput = Schema.decodeEffect(ExecutionIdOutput);
|
|
21
|
+
/** Workflow starts staged so far in each turn's staging, numbering keyless starts. */
|
|
22
|
+
const startCounts = new WeakMap();
|
|
23
|
+
const isWatchable = (member) => "watch" in member && member.watch === true;
|
|
24
|
+
const runOf = (descriptor, member, ref, caller, executionId, execute, poll, mint) => workflowRun({
|
|
25
|
+
executionId,
|
|
26
|
+
poll: poll(Request.make({ ref, caller, command: member.tag, commandId: "", payload: executionId })),
|
|
27
|
+
interrupt: Effect.gen(function* () {
|
|
28
|
+
const commandId = (yield* CurrentCommandId) ?? (yield* mint);
|
|
29
|
+
const outcome = yield* execute(Request.make({
|
|
30
|
+
ref,
|
|
31
|
+
caller,
|
|
32
|
+
command: INTERRUPT,
|
|
33
|
+
commandId,
|
|
34
|
+
payload: yield* encodeTarget({ executionId }).pipe(Effect.orDie),
|
|
35
|
+
}));
|
|
36
|
+
if (Outcome.guards.Defect(outcome))
|
|
37
|
+
return yield* Effect.die(outcome.cause);
|
|
38
|
+
}),
|
|
39
|
+
decode: descriptor.workflowExits.get(member.tag).decode,
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* The methods of a request/reply handle to `id`, which reach `internal`
|
|
43
|
+
* commands when `includeInternal` is set. Running a command method's Effect
|
|
44
|
+
* mints its command id once and reuses it on every rerun, so a retry is
|
|
45
|
+
* deduplicated by the receipt; a workflow step's call takes the step's id.
|
|
46
|
+
* Handles never deliver subscriptions, so an acknowledged outcome is a defect.
|
|
47
|
+
*/
|
|
48
|
+
export const handleOf = Effect.fnUntraced(function* (descriptor, id, includeInternal, as, tenant) {
|
|
49
|
+
yield* outsideTurn;
|
|
50
|
+
const actors = yield* Actors;
|
|
51
|
+
const internalActors = yield* InternalActors;
|
|
52
|
+
const caller = yield* decodeCaller(as ?? (yield* CurrentCaller)).pipe(Effect.orDie);
|
|
53
|
+
const ref = ActorRef.make({
|
|
54
|
+
actor: descriptor.name,
|
|
55
|
+
tenant: tenant ?? (yield* Tenant),
|
|
56
|
+
id: descriptor.singleton ? "singleton" : yield* descriptor.decodeId(id).pipe(Effect.orDie),
|
|
57
|
+
});
|
|
58
|
+
const callable = Effect.gen(function* () {
|
|
59
|
+
if (CallPhase.$is("Body")(yield* CurrentCallPhase))
|
|
60
|
+
return yield* Effect.die(new Error("Actor call in a workflow body outside a step"));
|
|
61
|
+
});
|
|
62
|
+
const send = (request) => Effect.gen(function* () {
|
|
63
|
+
if (CallPhase.$is("Activity")(yield* CurrentCallPhase))
|
|
64
|
+
return yield* internalActors.deliver(request);
|
|
65
|
+
return (yield* internalActors.execute(request)).outcome;
|
|
66
|
+
});
|
|
67
|
+
const callId = (command) => Effect.gen(function* () {
|
|
68
|
+
const phase = yield* CurrentCallPhase;
|
|
69
|
+
if (CallPhase.$is("Activity")(phase))
|
|
70
|
+
return yield* phase.nextCommandId;
|
|
71
|
+
const explicit = yield* CurrentCommandId;
|
|
72
|
+
if (explicit !== undefined)
|
|
73
|
+
return explicit;
|
|
74
|
+
const connectionCommands = yield* CurrentConnectionCommands;
|
|
75
|
+
return connectionCommands === undefined
|
|
76
|
+
? yield* actors.mintCommandId
|
|
77
|
+
: yield* connectionCommands(`${ref.tenant}\u0000${ref.actor}\u0000${ref.id}`, command);
|
|
78
|
+
});
|
|
79
|
+
const callIdOnce = (command) => {
|
|
80
|
+
const lock = Semaphore.makeUnsafe(1);
|
|
81
|
+
let identity;
|
|
82
|
+
return lock.withPermit(Effect.gen(function* () {
|
|
83
|
+
if (identity === undefined)
|
|
84
|
+
identity = yield* callId(command);
|
|
85
|
+
return identity;
|
|
86
|
+
}));
|
|
87
|
+
};
|
|
88
|
+
const execute = (request) => Effect.map(internalActors.execute(request), (executed) => executed.outcome);
|
|
89
|
+
const methods = Object.fromEntries((includeInternal ? descriptor.members : Object.values(descriptor.api))
|
|
90
|
+
.filter((member) => member.kind !== "connection")
|
|
91
|
+
.map((member) => {
|
|
92
|
+
const { encodePayload, decodeSuccess, decodeError } = descriptor.codecs.get(member.tag);
|
|
93
|
+
const decoded = (elements, encoded) => elements.pipe(Stream.mapEffect((element) => Effect.map(decodeSuccess(encoded(element)).pipe(Effect.orDie), (out) => out.value)), Stream.catch((error) => Schema.is(ActorError)(error)
|
|
94
|
+
? Stream.fail(error)
|
|
95
|
+
: Stream.fromEffect(Effect.flatMap(decodeError(error.failure).pipe(Effect.orDie), Effect.fail))));
|
|
96
|
+
if (member.kind === "stream")
|
|
97
|
+
return [
|
|
98
|
+
member.tag,
|
|
99
|
+
(input) => Stream.unwrap(Effect.gen(function* () {
|
|
100
|
+
yield* outsideTurn;
|
|
101
|
+
const payload = yield* encodePayload({ value: input }).pipe(Effect.orDie);
|
|
102
|
+
return decoded(internalActors.subscribe(Request.make({ ref, caller, command: member.tag, commandId: "", payload })), (value) => value);
|
|
103
|
+
})),
|
|
104
|
+
];
|
|
105
|
+
if (isWorkflow(member))
|
|
106
|
+
return [
|
|
107
|
+
member.tag,
|
|
108
|
+
(input) => {
|
|
109
|
+
const identify = callIdOnce(member.tag);
|
|
110
|
+
return Effect.gen(function* () {
|
|
111
|
+
yield* outsideTurn;
|
|
112
|
+
yield* callable;
|
|
113
|
+
if (member.key !== undefined)
|
|
114
|
+
yield* checkExecutionKey(member.key(input));
|
|
115
|
+
const payload = yield* encodePayload({ value: input }).pipe(Effect.orDie);
|
|
116
|
+
const outcome = yield* send(Request.make({
|
|
117
|
+
ref,
|
|
118
|
+
caller,
|
|
119
|
+
command: member.tag,
|
|
120
|
+
commandId: yield* identify,
|
|
121
|
+
payload,
|
|
122
|
+
}));
|
|
123
|
+
if (!Outcome.guards.Success(outcome))
|
|
124
|
+
return yield* Effect.die(Outcome.guards.Defect(outcome)
|
|
125
|
+
? outcome.cause
|
|
126
|
+
: new Error("Workflow start failed"));
|
|
127
|
+
const { value: executionId } = yield* decodeExecutionIdOutput(outcome.value).pipe(Effect.orDie);
|
|
128
|
+
return runOf(descriptor, member, ref, caller, executionId, execute, internalActors.pollWorkflow, actors.mintCommandId);
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
];
|
|
132
|
+
const call = (input) => {
|
|
133
|
+
const identify = callIdOnce(member.tag);
|
|
134
|
+
return Effect.gen(function* () {
|
|
135
|
+
yield* outsideTurn;
|
|
136
|
+
if (member.kind !== "query")
|
|
137
|
+
yield* callable;
|
|
138
|
+
const payload = yield* encodePayload({ value: input }).pipe(Effect.orDie);
|
|
139
|
+
const outcome = member.kind === "query"
|
|
140
|
+
? yield* internalActors.query(Request.make({ ref, caller, command: member.tag, commandId: "", payload }), internalActors.observedVersion())
|
|
141
|
+
: yield* send(Request.make({
|
|
142
|
+
ref,
|
|
143
|
+
caller,
|
|
144
|
+
command: member.tag,
|
|
145
|
+
commandId: yield* identify,
|
|
146
|
+
payload,
|
|
147
|
+
}));
|
|
148
|
+
if (Outcome.guards.Defect(outcome))
|
|
149
|
+
return yield* Effect.die(outcome.cause);
|
|
150
|
+
if (Outcome.guards.Failure(outcome))
|
|
151
|
+
return yield* yield* decodeError(outcome.value).pipe(Effect.orDie);
|
|
152
|
+
if (Outcome.guards.Acknowledged(outcome))
|
|
153
|
+
return yield* Effect.die(new Error(`Unexpected ${outcome.reason} acknowledgement`));
|
|
154
|
+
return (yield* decodeSuccess(outcome.value).pipe(Effect.orDie)).value;
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
if (!isWatchable(member))
|
|
158
|
+
return [member.tag, call];
|
|
159
|
+
const watch = (input) => Stream.unwrap(Effect.gen(function* () {
|
|
160
|
+
yield* outsideTurn;
|
|
161
|
+
const payload = yield* encodePayload({ value: input }).pipe(Effect.orDie);
|
|
162
|
+
const results = yield* internalActors.watch(Request.make({ ref, caller, command: member.tag, commandId: "", payload }), { minVersion: internalActors.observedVersion(), expiresAt: undefined });
|
|
163
|
+
return decoded(results, ({ value }) => value).pipe(Stream.catchIf((error) => Schema.is(ActorError)(error) && Schema.is(InvalidInput)(error.reason), Stream.die));
|
|
164
|
+
}));
|
|
165
|
+
return [member.tag, Object.assign(call, { watch })];
|
|
166
|
+
}));
|
|
167
|
+
return { ...methods, ref };
|
|
168
|
+
});
|
|
169
|
+
/**
|
|
170
|
+
* Mints a new UUIDv7 id and returns its handle. Only an unkeyed actor that is
|
|
171
|
+
* not parent-placed may be created by a caller; inside a turn it is a defect.
|
|
172
|
+
*/
|
|
173
|
+
export const createOf = (descriptor) => Effect.gen(function* () {
|
|
174
|
+
yield* outsideTurn;
|
|
175
|
+
if (!descriptor.minted)
|
|
176
|
+
return yield* Effect.die(descriptor.parent === undefined
|
|
177
|
+
? new Error("Only minted actors use create()")
|
|
178
|
+
: new Error(`${descriptor.name} is minted only by its parent ${descriptor.parent.name}`));
|
|
179
|
+
const internalActors = yield* InternalActors;
|
|
180
|
+
return yield* handleOf(descriptor, yield* internalActors.mintActorId, false);
|
|
181
|
+
});
|
|
182
|
+
/**
|
|
183
|
+
* Durable intents to actor `id`, staged in the current command turn. The
|
|
184
|
+
* target shares the sending turn's tenant. A keyless workflow start is keyed
|
|
185
|
+
* by the turn's command id and its order among the turn's starts, so a
|
|
186
|
+
* retried turn restages the same executions. Commands that subscriptions
|
|
187
|
+
* deliver to are left out.
|
|
188
|
+
*/
|
|
189
|
+
export const intentsOf = Effect.fnUntraced(function* (descriptor, id) {
|
|
190
|
+
const { marker, staging } = yield* currentStaging();
|
|
191
|
+
const target = ActorRef.make({
|
|
192
|
+
actor: descriptor.name,
|
|
193
|
+
tenant: staging.sender.tenant,
|
|
194
|
+
id: descriptor.singleton ? "singleton" : yield* descriptor.decodeId(id).pipe(Effect.orDie),
|
|
195
|
+
});
|
|
196
|
+
const methods = Object.fromEntries(descriptor.commands.flatMap((member) => {
|
|
197
|
+
if (descriptor.handlerTags.has(member.tag))
|
|
198
|
+
return [];
|
|
199
|
+
const { encodePayload } = descriptor.codecs.get(member.tag);
|
|
200
|
+
return [
|
|
201
|
+
[
|
|
202
|
+
member.tag,
|
|
203
|
+
(input) => Effect.gen(function* () {
|
|
204
|
+
const payload = yield* encodePayload({ value: input }).pipe(Effect.orDie);
|
|
205
|
+
yield* stageIntent(marker, { target, command: member.tag, payload });
|
|
206
|
+
}),
|
|
207
|
+
],
|
|
208
|
+
];
|
|
209
|
+
}));
|
|
210
|
+
const starts = Object.fromEntries(descriptor.workflows.map((member) => {
|
|
211
|
+
const { encodePayload } = descriptor.codecs.get(member.tag);
|
|
212
|
+
return [
|
|
213
|
+
member.tag,
|
|
214
|
+
(input) => Effect.gen(function* () {
|
|
215
|
+
const { staging: current } = yield* currentStaging(marker);
|
|
216
|
+
const payload = yield* encodePayload({ value: input }).pipe(Effect.orDie);
|
|
217
|
+
const ordinal = (startCounts.get(current) ?? 0) + 1;
|
|
218
|
+
startCounts.set(current, ordinal);
|
|
219
|
+
const key = member.key === undefined ? `${current.commandId}:${ordinal}` : member.key(input);
|
|
220
|
+
const executionId = yield* encodeExecutionId({
|
|
221
|
+
tenant: target.tenant,
|
|
222
|
+
actor: target.actor,
|
|
223
|
+
id: target.id,
|
|
224
|
+
workflow: member.tag,
|
|
225
|
+
key,
|
|
226
|
+
}).pipe(Effect.orDie);
|
|
227
|
+
const own = current.sender.actor === target.actor && current.sender.id === target.id;
|
|
228
|
+
yield* stageIntent(marker, {
|
|
229
|
+
target,
|
|
230
|
+
command: START,
|
|
231
|
+
payload: yield* encodeStartPayload({
|
|
232
|
+
workflow: member.tag,
|
|
233
|
+
input: payload,
|
|
234
|
+
key,
|
|
235
|
+
after: own ? current.head : null,
|
|
236
|
+
}).pipe(Effect.orDie),
|
|
237
|
+
});
|
|
238
|
+
return executionId;
|
|
239
|
+
}),
|
|
240
|
+
];
|
|
241
|
+
}));
|
|
242
|
+
return { ...methods, ...starts, ref: target };
|
|
243
|
+
});
|
|
244
|
+
/**
|
|
245
|
+
* Reattaches to a workflow execution by id without contacting its owner. An
|
|
246
|
+
* id of another tenant, actor type, or workflow fails `InvalidExecutionId`.
|
|
247
|
+
*/
|
|
248
|
+
export const runOfId = Effect.fnUntraced(function* (descriptor, member, executionId) {
|
|
249
|
+
yield* outsideTurn;
|
|
250
|
+
const actors = yield* Actors;
|
|
251
|
+
const internalActors = yield* InternalActors;
|
|
252
|
+
const caller = yield* decodeCaller(yield* CurrentCaller).pipe(Effect.orDie);
|
|
253
|
+
const tenant = yield* Tenant;
|
|
254
|
+
const invalid = InvalidExecutionId.make({ executionId });
|
|
255
|
+
const execution = yield* decodeExecutionId(executionId);
|
|
256
|
+
if (execution.tenant !== tenant ||
|
|
257
|
+
execution.actor !== descriptor.name ||
|
|
258
|
+
execution.workflow !== member.tag ||
|
|
259
|
+
!descriptor.workflows.includes(member))
|
|
260
|
+
return yield* invalid;
|
|
261
|
+
const id = descriptor.singleton ? "singleton" : execution.id;
|
|
262
|
+
if (!descriptor.singleton && Result.isFailure(Schema.decodeResult(descriptor.idSchema)(id)))
|
|
263
|
+
return yield* invalid;
|
|
264
|
+
return runOf(descriptor, member, ActorRef.make({ actor: descriptor.name, tenant, id }), caller, executionId, (request) => Effect.map(internalActors.execute(request), (executed) => executed.outcome), internalActors.pollWorkflow, actors.mintCommandId);
|
|
265
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Context, Effect } from "effect";
|
|
2
|
+
import type { RegisteredJob } from "../runtime/members.ts";
|
|
3
|
+
import type { Handler } from "./codecs.ts";
|
|
4
|
+
import type { Descriptor } from "./descriptor.ts";
|
|
5
|
+
/** Every declared job's registration; a job without an executor is a defect of the layer. */
|
|
6
|
+
export declare const jobsOf: ({ descriptor, Executor, executors, }: {
|
|
7
|
+
readonly descriptor: Descriptor;
|
|
8
|
+
readonly Executor: Context.Key<object, object>;
|
|
9
|
+
readonly executors: Readonly<Record<string, Handler>>;
|
|
10
|
+
}) => Effect.Effect<ReadonlyMap<string, RegisteredJob>, never, never>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Cause, Effect, Exit, Option, Result, Schema } from "effect";
|
|
2
|
+
import { Tenant } from "../identity/caller.js";
|
|
3
|
+
import { CancelledOutcome } from "../members/job.js";
|
|
4
|
+
import { MAX_PROGRESS_BYTES } from "../runtime/jobs/progress.js";
|
|
5
|
+
const utf8 = new TextEncoder();
|
|
6
|
+
/** Encodes a value as a route command's payload. */
|
|
7
|
+
const routeCodec = (command) => {
|
|
8
|
+
const encode = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(Schema.Struct({ value: command.payload }))));
|
|
9
|
+
return (value) => encode({ value }).pipe(Effect.map((payload) => ({ command: command.tag, payload })));
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* One job's registration. Only a typed failure proves the provider did not
|
|
13
|
+
* apply the call; a defect, timeout, or interruption leaves the attempt's
|
|
14
|
+
* outcome unknown. A result `onSuccess` cannot accept is dead-lettered rather
|
|
15
|
+
* than executed again, since the provider already applied it, and a
|
|
16
|
+
* cancelled job's result goes to `onCancelled`, as an unknown outcome when
|
|
17
|
+
* that route cannot accept it. A stored payload that no longer decodes never
|
|
18
|
+
* reaches the executor.
|
|
19
|
+
*/
|
|
20
|
+
const jobOf = (Executor, { job, codec, policy }, execute) => {
|
|
21
|
+
const onSuccess = policy.onSuccess === undefined ? undefined : routeCodec(policy.onSuccess);
|
|
22
|
+
const onDeadLetter = policy.onDeadLetter === undefined ? undefined : routeCodec(policy.onDeadLetter);
|
|
23
|
+
const onCancelled = policy.onCancelled === undefined ? undefined : routeCodec(policy.onCancelled);
|
|
24
|
+
const cancelledRoute = (decoded, letter) => onCancelled === undefined
|
|
25
|
+
? Effect.undefined
|
|
26
|
+
: onCancelled({
|
|
27
|
+
jobId: letter.jobId,
|
|
28
|
+
job: decoded,
|
|
29
|
+
attempts: letter.attempts,
|
|
30
|
+
outcome: letter.outcome,
|
|
31
|
+
ambiguous: letter.ambiguous,
|
|
32
|
+
});
|
|
33
|
+
const encodeProgress = job.progress === undefined
|
|
34
|
+
? undefined
|
|
35
|
+
: Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.toCodecJson(job.progress)));
|
|
36
|
+
return {
|
|
37
|
+
attempts: policy.attempts,
|
|
38
|
+
backoff: policy.backoff,
|
|
39
|
+
progressEveryMs: encodeProgress === undefined ? undefined : policy.progressEveryMs,
|
|
40
|
+
perActor: policy.perActor,
|
|
41
|
+
routesCancelled: onCancelled !== undefined,
|
|
42
|
+
execute: Effect.fnUntraced(function* (payload, version, attempt) {
|
|
43
|
+
const decoded = yield* codec.decode(payload, version).pipe(Effect.mapError((error) => ({
|
|
44
|
+
cause: error.message,
|
|
45
|
+
ambiguous: false,
|
|
46
|
+
notStarted: true,
|
|
47
|
+
})));
|
|
48
|
+
const { report, reporting, ...identity } = attempt;
|
|
49
|
+
const progress = (target, frame) => !reporting()
|
|
50
|
+
? Effect.void
|
|
51
|
+
: target !== job || encodeProgress === undefined
|
|
52
|
+
? Effect.logWarning("Progress frame does not match the running job")
|
|
53
|
+
: encodeProgress(frame).pipe(Effect.map((json) => utf8.encode(json)), Effect.matchEffect({
|
|
54
|
+
onFailure: (error) => Effect.logWarning("Progress frame did not encode", String(error)),
|
|
55
|
+
onSuccess: (bytes) => bytes.length > MAX_PROGRESS_BYTES
|
|
56
|
+
? Effect.logWarning("Progress frame exceeds 4 KiB")
|
|
57
|
+
: report(bytes),
|
|
58
|
+
}), Effect.catchDefect((defect) => Effect.logWarning("Progress frame did not encode", String(defect))));
|
|
59
|
+
const context = {
|
|
60
|
+
jobId: identity.jobId,
|
|
61
|
+
attempt: identity.attempt,
|
|
62
|
+
principal: identity.principal,
|
|
63
|
+
ref: identity.ref,
|
|
64
|
+
progress,
|
|
65
|
+
};
|
|
66
|
+
const exit = yield* execute(decoded).pipe(Effect.timeoutOrElse({
|
|
67
|
+
duration: policy.timeoutMs,
|
|
68
|
+
orElse: () => Effect.die(new Error(`Executor timed out after ${policy.timeoutMs} ms`)),
|
|
69
|
+
}), Effect.provideService(Executor, context), Effect.provideService(Tenant, context.ref.tenant), Effect.exit);
|
|
70
|
+
if (Exit.isFailure(exit))
|
|
71
|
+
return yield* Effect.fail({
|
|
72
|
+
cause: Cause.pretty(exit.cause),
|
|
73
|
+
ambiguous: !Cause.hasFails(exit.cause) ||
|
|
74
|
+
Cause.hasDies(exit.cause) ||
|
|
75
|
+
Cause.hasInterrupts(exit.cause),
|
|
76
|
+
});
|
|
77
|
+
const cancelled = onCancelled === undefined
|
|
78
|
+
? undefined
|
|
79
|
+
: yield* cancelledRoute(decoded, {
|
|
80
|
+
jobId: context.jobId,
|
|
81
|
+
attempts: context.attempt,
|
|
82
|
+
outcome: CancelledOutcome.cases.Succeeded.make({ value: exit.value }),
|
|
83
|
+
ambiguous: false,
|
|
84
|
+
}).pipe(Effect.catch((error) => cancelledRoute(decoded, {
|
|
85
|
+
jobId: context.jobId,
|
|
86
|
+
attempts: context.attempt,
|
|
87
|
+
outcome: CancelledOutcome.cases.Unknown.make({
|
|
88
|
+
cause: `The onCancelled route cannot accept the result: ${String(error)}`,
|
|
89
|
+
}),
|
|
90
|
+
ambiguous: true,
|
|
91
|
+
})), Effect.orDie);
|
|
92
|
+
if (onSuccess === undefined)
|
|
93
|
+
return { success: undefined, cancelled, rejected: undefined };
|
|
94
|
+
const success = yield* onSuccess(exit.value).pipe(Effect.result);
|
|
95
|
+
if (Result.isFailure(success))
|
|
96
|
+
return {
|
|
97
|
+
success: undefined,
|
|
98
|
+
cancelled,
|
|
99
|
+
rejected: {
|
|
100
|
+
cause: `The onSuccess route cannot accept the result: ${String(success.failure)}`,
|
|
101
|
+
ambiguous: true,
|
|
102
|
+
final: true,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
return { success: success.success, cancelled, rejected: undefined };
|
|
106
|
+
}),
|
|
107
|
+
cancelled: Effect.fnUntraced(function* (payload, version, letter) {
|
|
108
|
+
const decoded = yield* codec.decode(payload, version).pipe(Effect.option);
|
|
109
|
+
if (Option.isNone(decoded))
|
|
110
|
+
return undefined;
|
|
111
|
+
return yield* cancelledRoute(decoded.value, letter);
|
|
112
|
+
}, Effect.orDie),
|
|
113
|
+
deadLetter: Effect.fnUntraced(function* (payload, version, letter) {
|
|
114
|
+
const decoded = yield* codec.decode(payload, version).pipe(Effect.option);
|
|
115
|
+
if (onDeadLetter === undefined || Option.isNone(decoded))
|
|
116
|
+
return undefined;
|
|
117
|
+
return yield* onDeadLetter({
|
|
118
|
+
jobId: letter.jobId,
|
|
119
|
+
job: decoded.value,
|
|
120
|
+
attempts: letter.attempts,
|
|
121
|
+
cause: letter.cause,
|
|
122
|
+
ambiguous: letter.ambiguous,
|
|
123
|
+
});
|
|
124
|
+
}, Effect.orDie),
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
/** Every declared job's registration; a job without an executor is a defect of the layer. */
|
|
128
|
+
export const jobsOf = ({ descriptor, Executor, executors, }) => Effect.gen(function* () {
|
|
129
|
+
const registered = new Map();
|
|
130
|
+
for (const compiled of descriptor.jobs.values()) {
|
|
131
|
+
const execute = executors[compiled.job.tag];
|
|
132
|
+
if (execute === undefined)
|
|
133
|
+
return yield* Effect.die(new Error(`Missing executor ${compiled.job.tag}`));
|
|
134
|
+
registered.set(compiled.job.tag, jobOf(Executor, compiled, execute));
|
|
135
|
+
}
|
|
136
|
+
return registered;
|
|
137
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Scope } from "effect";
|
|
2
|
+
import { InternalActors } from "../runtime/actors.ts";
|
|
3
|
+
import type { Descriptor } from "./descriptor.ts";
|
|
4
|
+
/** The per-actor phase services `Actor.make` creates, which the adapters provide. */
|
|
5
|
+
export interface PhaseServices {
|
|
6
|
+
readonly Turn: Context.Key<object, object>;
|
|
7
|
+
readonly Read: Context.Key<object, object>;
|
|
8
|
+
readonly Connection: Context.Key<object, object>;
|
|
9
|
+
readonly Workflow: Context.Key<object, object>;
|
|
10
|
+
readonly Executor: Context.Key<object, object>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What a layer constructor receives: the descriptor, its phase services, the
|
|
14
|
+
* entries or an Effect that builds them, and the Effect that captures the
|
|
15
|
+
* services the entries require when the layer is built.
|
|
16
|
+
*/
|
|
17
|
+
export interface LayerOptions<H extends object, E, RB, RS> {
|
|
18
|
+
readonly descriptor: Descriptor;
|
|
19
|
+
readonly phases: PhaseServices;
|
|
20
|
+
readonly build: H | Effect.Effect<H, E, RB>;
|
|
21
|
+
readonly services: Effect.Effect<Context.Context<RS>, never, RS>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The owner of an ordinary actor's handlers: the builder runs once, when the
|
|
25
|
+
* layer is built, and every activation on this runner shares its handlers. A
|
|
26
|
+
* builder failure fails the layer. Workflow bodies receive the layer's context
|
|
27
|
+
* without its `Scope`: a body's scope is its run's.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ordinaryLayer: <H extends object, E, RB, RS>({ descriptor, phases, build, services: capture, }: LayerOptions<H, E, RB, RS>) => Layer.Layer<never, E, InternalActors | Exclude<RB, Scope.Scope> | Exclude<RS, Scope.Scope>>;
|
|
30
|
+
/**
|
|
31
|
+
* The owner of a singleton's handlers: the builder runs once per activation,
|
|
32
|
+
* in the activation's scope, as the actor with a `System({ source: "actor" })`
|
|
33
|
+
* caller, so a fiber it forks with `Effect.forkScoped` lives exactly as long
|
|
34
|
+
* as the one cluster-wide activation. A builder failure fails that activation,
|
|
35
|
+
* whose commands then fail, rather than the layer.
|
|
36
|
+
*/
|
|
37
|
+
export declare const singletonLayer: <H extends object, E, RB, RS>({ descriptor, phases, build, services: capture, }: LayerOptions<H, E, RB, RS>) => Layer.Layer<never, never, InternalActors | Exclude<RB, Scope.Scope> | Exclude<RS, Scope.Scope>>;
|
|
38
|
+
/** Registers every query's handler; queries run on the caller's node. */
|
|
39
|
+
export declare const queryLayer: <H extends object, E, RB, RS>({ descriptor, phases, build, services: capture, }: LayerOptions<H, E, RB, RS>) => Layer.Layer<never, E, InternalActors | Exclude<RB, Scope.Scope> | Exclude<RS, Scope.Scope>>;
|
|
40
|
+
/** Registers every job's executor; executors run after the enqueueing turn commits. */
|
|
41
|
+
export declare const jobLayer: <H extends object, E, RB, RS>({ descriptor, phases, build, services: capture, }: LayerOptions<H, E, RB, RS>) => Layer.Layer<never, E, InternalActors | Exclude<RB, Scope.Scope> | Exclude<RS, Scope.Scope>>;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Predicate, Scope } from "effect";
|
|
2
|
+
import { CurrentCaller, System, Tenant } from "../identity/caller.js";
|
|
3
|
+
import { payloadChain } from "../members/payload.js";
|
|
4
|
+
import { InternalActors } from "../runtime/actors.js";
|
|
5
|
+
import { connectionOf } from "./connections.js";
|
|
6
|
+
import { jobsOf } from "./jobs.js";
|
|
7
|
+
import { queriesOf, streamOf } from "./reads.js";
|
|
8
|
+
import { turnsOf } from "./turns.js";
|
|
9
|
+
import { workflowsOf } from "./workflows.js";
|
|
10
|
+
/** The entries themselves, or what the builder builds. */
|
|
11
|
+
const built = (build) => (Effect.isEffect(build) ? build : Effect.succeed(build));
|
|
12
|
+
/** The layer's entries as the adapters read them: by tag, with member types erased. */
|
|
13
|
+
const erased = (entries) => entries;
|
|
14
|
+
const registrationOf = (descriptor, tenant) => ({
|
|
15
|
+
name: descriptor.name,
|
|
16
|
+
singleton: descriptor.singleton,
|
|
17
|
+
mintable: descriptor.mintable,
|
|
18
|
+
watches: descriptor.watches,
|
|
19
|
+
tenant,
|
|
20
|
+
access: descriptor.access,
|
|
21
|
+
placement: descriptor.placement,
|
|
22
|
+
policy: descriptor.policy,
|
|
23
|
+
tables: descriptor.tables,
|
|
24
|
+
blobs: descriptor.blobs,
|
|
25
|
+
cron: descriptor.cron,
|
|
26
|
+
subscriptions: descriptor.registeredSubscriptions,
|
|
27
|
+
subscribers: descriptor.policy.subscribers,
|
|
28
|
+
payloads: [
|
|
29
|
+
...descriptor.payloads(true),
|
|
30
|
+
...descriptor.subscriptions.flatMap((declared) => declared.events.map((event) => ({
|
|
31
|
+
actorType: declared.source.name,
|
|
32
|
+
kind: "event",
|
|
33
|
+
tag: event.identifier,
|
|
34
|
+
chain: payloadChain(event),
|
|
35
|
+
writes: false,
|
|
36
|
+
}))),
|
|
37
|
+
],
|
|
38
|
+
upcastEvent: (tag, version, value) => {
|
|
39
|
+
const codec = descriptor.eventCodecs.get(tag);
|
|
40
|
+
return codec === undefined
|
|
41
|
+
? Effect.die(new Error(`Undeclared event: ${tag}`))
|
|
42
|
+
: codec.upcast(value, version).pipe(Effect.orDie);
|
|
43
|
+
},
|
|
44
|
+
feeds: descriptor.feeds,
|
|
45
|
+
});
|
|
46
|
+
const connectionsOf = (descriptor, phases, entries, services) => Effect.gen(function* () {
|
|
47
|
+
const connections = new Map();
|
|
48
|
+
for (const member of descriptor.connections) {
|
|
49
|
+
const entry = entries[member.tag];
|
|
50
|
+
if (entry === undefined ||
|
|
51
|
+
!Predicate.hasProperty(entry, "open") ||
|
|
52
|
+
!Predicate.isFunction(entry.open) ||
|
|
53
|
+
!Predicate.isFunction(entry.frame))
|
|
54
|
+
return yield* Effect.die(new Error(`Missing connection handlers ${member.tag}`));
|
|
55
|
+
connections.set(member.tag, connectionOf({ descriptor, Connection: phases.Connection, member, entry, services }));
|
|
56
|
+
}
|
|
57
|
+
return connections;
|
|
58
|
+
});
|
|
59
|
+
const streamsOf = (descriptor, phases, entries, services, actors) => Effect.gen(function* () {
|
|
60
|
+
const streams = new Map();
|
|
61
|
+
for (const member of descriptor.streams) {
|
|
62
|
+
const handle = entries[member.tag];
|
|
63
|
+
if (!Predicate.isFunction(handle))
|
|
64
|
+
return yield* Effect.die(new Error(`Missing stream handler ${member.tag}`));
|
|
65
|
+
streams.set(member.tag, streamOf({
|
|
66
|
+
descriptor,
|
|
67
|
+
Read: phases.Read,
|
|
68
|
+
member,
|
|
69
|
+
handle: handle,
|
|
70
|
+
services,
|
|
71
|
+
actors,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
return streams;
|
|
75
|
+
});
|
|
76
|
+
const handlersOf = (entries) => Object.fromEntries(Object.entries(entries).flatMap(([tag, entry]) => Predicate.isFunction(entry) ? [[tag, entry]] : []));
|
|
77
|
+
/**
|
|
78
|
+
* The owner of an ordinary actor's handlers: the builder runs once, when the
|
|
79
|
+
* layer is built, and every activation on this runner shares its handlers. A
|
|
80
|
+
* builder failure fails the layer. Workflow bodies receive the layer's context
|
|
81
|
+
* without its `Scope`: a body's scope is its run's.
|
|
82
|
+
*/
|
|
83
|
+
export const ordinaryLayer = ({ descriptor, phases, build, services: capture, }) => Layer.effectDiscard(Effect.gen(function* () {
|
|
84
|
+
const actors = yield* InternalActors;
|
|
85
|
+
const registration = registrationOf(descriptor, yield* Tenant);
|
|
86
|
+
const entries = erased(yield* built(build));
|
|
87
|
+
const services = (yield* capture);
|
|
88
|
+
const connections = yield* connectionsOf(descriptor, phases, entries, services);
|
|
89
|
+
const streams = yield* streamsOf(descriptor, phases, entries, services, actors);
|
|
90
|
+
const handlers = handlersOf(entries);
|
|
91
|
+
const commands = yield* turnsOf({
|
|
92
|
+
descriptor,
|
|
93
|
+
Turn: phases.Turn,
|
|
94
|
+
handlers,
|
|
95
|
+
services,
|
|
96
|
+
actors,
|
|
97
|
+
});
|
|
98
|
+
const workflows = yield* workflowsOf({
|
|
99
|
+
descriptor,
|
|
100
|
+
Workflow: phases.Workflow,
|
|
101
|
+
bodies: handlers,
|
|
102
|
+
services: services.pipe(Context.omit(Scope.Scope)),
|
|
103
|
+
});
|
|
104
|
+
return yield* actors.register({
|
|
105
|
+
...registration,
|
|
106
|
+
workflows,
|
|
107
|
+
activate: () => Effect.succeed(commands),
|
|
108
|
+
connections,
|
|
109
|
+
streams,
|
|
110
|
+
});
|
|
111
|
+
}));
|
|
112
|
+
/**
|
|
113
|
+
* The owner of a singleton's handlers: the builder runs once per activation,
|
|
114
|
+
* in the activation's scope, as the actor with a `System({ source: "actor" })`
|
|
115
|
+
* caller, so a fiber it forks with `Effect.forkScoped` lives exactly as long
|
|
116
|
+
* as the one cluster-wide activation. A builder failure fails that activation,
|
|
117
|
+
* whose commands then fail, rather than the layer.
|
|
118
|
+
*/
|
|
119
|
+
export const singletonLayer = ({ descriptor, phases, build, services: capture, }) => Layer.effectDiscard(Effect.gen(function* () {
|
|
120
|
+
const actors = yield* InternalActors;
|
|
121
|
+
const registration = registrationOf(descriptor, yield* Tenant);
|
|
122
|
+
if (descriptor.connections.length > 0 ||
|
|
123
|
+
descriptor.streams.length > 0 ||
|
|
124
|
+
descriptor.feeds.size > 0 ||
|
|
125
|
+
descriptor.watches.size > 0)
|
|
126
|
+
return yield* Effect.die(new Error("Singleton actors cannot declare connections, streams, feeds, or watches yet"));
|
|
127
|
+
const services = (yield* capture);
|
|
128
|
+
const buildServices = yield* Effect.context();
|
|
129
|
+
if (descriptor.workflows.length > 0)
|
|
130
|
+
return yield* Effect.die(new Error(`Singleton actor ${descriptor.name} cannot declare workflows`));
|
|
131
|
+
yield* actors.register({
|
|
132
|
+
...registration,
|
|
133
|
+
workflows: new Map(),
|
|
134
|
+
activate: Effect.fnUntraced(function* (ref) {
|
|
135
|
+
const scope = yield* Scope.Scope;
|
|
136
|
+
const entries = erased(yield* built(build).pipe(Effect.provideService(Scope.Scope, scope), Effect.provideService(Tenant, ref.tenant), Effect.provideService(CurrentCaller, System.make({ source: "actor", ref })), Effect.provideContext(buildServices), Effect.orDie));
|
|
137
|
+
return yield* turnsOf({
|
|
138
|
+
descriptor,
|
|
139
|
+
Turn: phases.Turn,
|
|
140
|
+
handlers: handlersOf(entries),
|
|
141
|
+
services,
|
|
142
|
+
actors,
|
|
143
|
+
});
|
|
144
|
+
}),
|
|
145
|
+
connections: new Map(),
|
|
146
|
+
streams: new Map(),
|
|
147
|
+
});
|
|
148
|
+
}));
|
|
149
|
+
/** Registers every query's handler; queries run on the caller's node. */
|
|
150
|
+
export const queryLayer = ({ descriptor, phases, build, services: capture, }) => Layer.effectDiscard(Effect.gen(function* () {
|
|
151
|
+
const actors = yield* InternalActors;
|
|
152
|
+
const handlers = handlersOf(erased(yield* built(build)));
|
|
153
|
+
const services = (yield* capture);
|
|
154
|
+
yield* actors.registerQueries({
|
|
155
|
+
name: descriptor.name,
|
|
156
|
+
access: descriptor.access,
|
|
157
|
+
placement: descriptor.placement,
|
|
158
|
+
timeoutMs: descriptor.policy.executionMs,
|
|
159
|
+
tables: descriptor.tables,
|
|
160
|
+
blobs: descriptor.blobs,
|
|
161
|
+
queries: yield* queriesOf({ descriptor, Read: phases.Read, handlers, services, actors }),
|
|
162
|
+
payloads: descriptor.payloads(false).filter((declared) => declared.kind === "event"),
|
|
163
|
+
});
|
|
164
|
+
}));
|
|
165
|
+
/** Registers every job's executor; executors run after the enqueueing turn commits. */
|
|
166
|
+
export const jobLayer = ({ descriptor, phases, build, services: capture, }) => Layer.effectDiscard(Effect.gen(function* () {
|
|
167
|
+
const actors = yield* InternalActors;
|
|
168
|
+
const executors = handlersOf(erased(yield* built(build)));
|
|
169
|
+
const services = (yield* capture);
|
|
170
|
+
yield* actors.registerJobs({
|
|
171
|
+
name: descriptor.name,
|
|
172
|
+
progress: descriptor.progressJobs,
|
|
173
|
+
services,
|
|
174
|
+
jobs: yield* jobsOf({ descriptor, Executor: phases.Executor, executors }),
|
|
175
|
+
payloads: descriptor.payloads(false).filter((declared) => declared.kind === "job"),
|
|
176
|
+
});
|
|
177
|
+
}));
|