@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,215 @@
|
|
|
1
|
+
import { Cause, Effect, Option, Predicate, Result, Schema, Stream } from "effect";
|
|
2
|
+
import { SqlClient } from "effect/sql";
|
|
3
|
+
import { inTenant, TenantScope } from "../database/tenancy.js";
|
|
4
|
+
import { InvalidContentRef } from "../../errors/content.js";
|
|
5
|
+
import { ContentRef } from "../../identity/content.js";
|
|
6
|
+
import { isContent } from "../../members/blob.js";
|
|
7
|
+
import { routingKey as routingKeyOf } from "../storage/codec.js";
|
|
8
|
+
/** UTF-8 bytes of an entry name; the name shares a btree key with the ownership columns. */
|
|
9
|
+
const MAX_NAME_BYTES = 512;
|
|
10
|
+
/**
|
|
11
|
+
* Bytes one entry may hold. `get` returns an entry as one row, and the Postgres
|
|
12
|
+
* driver closes a connection on any message over 16 MiB, so an entry stays well below it.
|
|
13
|
+
*/
|
|
14
|
+
export const MAX_ENTRY_BYTES = 8 * 1024 * 1024;
|
|
15
|
+
const isContentRef = Schema.is(ContentRef);
|
|
16
|
+
/**
|
|
17
|
+
* Binds blob capabilities to the calling fiber's turn or query. Every row is
|
|
18
|
+
* addressed by the trusted scope, so equal blob and entry names of two actors
|
|
19
|
+
* or tenants never meet; writes run on the turn's connection, inside its
|
|
20
|
+
* savepoint, and roll back with it. Off-turn contexts get read methods only,
|
|
21
|
+
* and turns get no content bytes.
|
|
22
|
+
*
|
|
23
|
+
* Declared blobs, names, and byte arrays are checked on every call, so misuse
|
|
24
|
+
* is a defect of the turn. Entry names reject lone surrogates, which Postgres
|
|
25
|
+
* would turn into U+FFFD and alias another name, and NUL. Byte arrays are
|
|
26
|
+
* copied on the way in and out, since the caller may reuse its buffer and a
|
|
27
|
+
* driver may decode into a pooled one. Content references count against the
|
|
28
|
+
* entry cap with the actor's own entries, and an existing entry stays
|
|
29
|
+
* writable at the cap; the quota is named only after a write changed nothing.
|
|
30
|
+
* A set overwrites chunk 0 and drops the rest in one statement that changes
|
|
31
|
+
* nothing past the quota, so a caught defect leaves the entry whole. Turns of
|
|
32
|
+
* one actor serialize on its generation lock, so an appended chunk index is
|
|
33
|
+
* free at insert. Attaching content verifies its grant by MAC without a read
|
|
34
|
+
* and requires the grant to outlive this shard's clock by the skew margin, so
|
|
35
|
+
* the tenant shard's sweep sees a horizon past this turn's commit. Content
|
|
36
|
+
* keys are required only when a content blob is used.
|
|
37
|
+
*/
|
|
38
|
+
export const bindBlobs = Effect.fnUntraced(function* (scope, write, content) {
|
|
39
|
+
const sql = yield* SqlClient.SqlClient;
|
|
40
|
+
const connection = yield* Effect.serviceOption(sql.transactionService);
|
|
41
|
+
const { role } = yield* TenantScope;
|
|
42
|
+
if (write && Option.isNone(connection))
|
|
43
|
+
return yield* Effect.die(new Error("Blob writes need the turn transaction"));
|
|
44
|
+
const { ref } = scope;
|
|
45
|
+
const routingKey = routingKeyOf({ ref, placement: scope.placement });
|
|
46
|
+
const owner = sql `routing_key = ${routingKey} AND tenant_id = ${ref.tenant}
|
|
47
|
+
AND actor_type = ${ref.actor} AND actor_id = ${ref.id}`;
|
|
48
|
+
const overQuota = Effect.suspend(() => Effect.die(new Error(`One actor's blobs hold at most ${scope.maxBytes} bytes (policy.maxBlobBytes)`)));
|
|
49
|
+
const references = sql `(SELECT count(*) FROM actor_content_refs WHERE ${owner})`;
|
|
50
|
+
const tooManyEntries = Effect.suspend(() => Effect.die(new Error(`One actor's blobs hold at most ${scope.maxEntries} entries (policy.maxBlobEntries)`)));
|
|
51
|
+
const declared = Effect.fnUntraced(function* (blob) {
|
|
52
|
+
yield* scope.guard;
|
|
53
|
+
if (!scope.blobs.includes(blob))
|
|
54
|
+
return yield* Effect.die(new Error(`${String(blob?.name)} is not a declared blob of ${ref.actor}`));
|
|
55
|
+
});
|
|
56
|
+
const entry = Effect.fnUntraced(function* (blob, name) {
|
|
57
|
+
yield* declared(blob);
|
|
58
|
+
if (!Predicate.isString(name) ||
|
|
59
|
+
name.length === 0 ||
|
|
60
|
+
new TextEncoder().encode(name).byteLength > MAX_NAME_BYTES ||
|
|
61
|
+
!name.isWellFormed() ||
|
|
62
|
+
name.includes("\u0000"))
|
|
63
|
+
return yield* Effect.die(new Error(`Blob entry names are well-formed strings of 1-${MAX_NAME_BYTES} UTF-8 bytes without NUL`));
|
|
64
|
+
return sql `${owner} AND blob = ${blob.name} AND name = ${name}`;
|
|
65
|
+
});
|
|
66
|
+
const run = (effect) => effect.pipe((bound) => Option.isSome(connection)
|
|
67
|
+
? Effect.provideService(bound, sql.transactionService, connection.value)
|
|
68
|
+
: inTenant({ sql, role, tenant: ref.tenant })(bound), Effect.orDie);
|
|
69
|
+
/** Runs `use` on the checked address of one entry of `blob`. */
|
|
70
|
+
const atEntry = (blob, name, use) => run(Effect.flatMap(entry(blob, name), use));
|
|
71
|
+
const noted = (blob) => Effect.sync(() => scope.wrote?.(blob.name));
|
|
72
|
+
const contentAccess = (blob) => {
|
|
73
|
+
const bound = Effect.suspend(() => content === undefined
|
|
74
|
+
? Effect.die(new Error("Content blobs need the runtime's content.keys"))
|
|
75
|
+
: Effect.succeed(content));
|
|
76
|
+
const list = run(Effect.gen(function* () {
|
|
77
|
+
yield* declared(blob);
|
|
78
|
+
const rows = yield* sql `
|
|
79
|
+
SELECT name, hash, size::float8 AS size FROM actor_content_refs
|
|
80
|
+
WHERE ${owner} AND blob = ${blob.name} ORDER BY name COLLATE "C"`;
|
|
81
|
+
return rows.map(({ name, hash, size }) => ({ name, hash, size }));
|
|
82
|
+
}));
|
|
83
|
+
const resolve = (name) => atEntry(blob, name, (where) => Effect.map(sql `
|
|
84
|
+
SELECT hash, size::float8 AS size FROM actor_content_refs WHERE ${where}`, ([found]) => Option.fromUndefinedOr(found)));
|
|
85
|
+
if (!write)
|
|
86
|
+
return {
|
|
87
|
+
get: (name) => Effect.gen(function* () {
|
|
88
|
+
const { store } = yield* bound;
|
|
89
|
+
const found = yield* resolve(name);
|
|
90
|
+
if (Option.isNone(found))
|
|
91
|
+
return Option.none();
|
|
92
|
+
return yield* store
|
|
93
|
+
.read(ref.tenant, found.value.hash, found.value.size)
|
|
94
|
+
.pipe(Effect.provideService(SqlClient.SqlClient, sql), Effect.orDie);
|
|
95
|
+
}),
|
|
96
|
+
stream: (name) => Stream.unwrap(Effect.gen(function* () {
|
|
97
|
+
const { store } = yield* bound;
|
|
98
|
+
const found = yield* resolve(name);
|
|
99
|
+
if (Option.isNone(found))
|
|
100
|
+
return Stream.fail(new Cause.NoSuchElementError(`No content entry ${name}`));
|
|
101
|
+
return store
|
|
102
|
+
.stream(ref.tenant, found.value.hash, found.value.size, scope.timeoutMs)
|
|
103
|
+
.pipe(Stream.provideService(SqlClient.SqlClient, sql));
|
|
104
|
+
})),
|
|
105
|
+
list,
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
attach: (name, contentRef) => Effect.gen(function* () {
|
|
109
|
+
const { store, skewMs, offset } = yield* bound;
|
|
110
|
+
const where = yield* run(entry(blob, name));
|
|
111
|
+
if (!isContentRef(contentRef))
|
|
112
|
+
return yield* InvalidContentRef.make({ reason: "malformed" });
|
|
113
|
+
const verified = yield* store.verify(contentRef.grant, {
|
|
114
|
+
tenant: ref.tenant,
|
|
115
|
+
hash: contentRef.hash,
|
|
116
|
+
size: contentRef.size,
|
|
117
|
+
});
|
|
118
|
+
if (Result.isFailure(verified))
|
|
119
|
+
return yield* InvalidContentRef.make({ reason: verified.failure });
|
|
120
|
+
const [checked] = yield* run(sql `WITH used AS (
|
|
121
|
+
SELECT ${verified.success} > floor(extract(epoch FROM clock_timestamp()) * 1000)::bigint
|
|
122
|
+
+ ${offset() + skewMs} AS live,
|
|
123
|
+
EXISTS (SELECT 1 FROM actor_content_refs WHERE ${where}) AS present,
|
|
124
|
+
(SELECT count(*) FROM actor_blobs WHERE ${owner} AND chunk = 0) + ${references} AS entries),
|
|
125
|
+
attached AS (
|
|
126
|
+
INSERT INTO actor_content_refs (routing_key, tenant_id, actor_type, actor_id, blob, name, hash, size)
|
|
127
|
+
SELECT ${routingKey}, ${ref.tenant}, ${ref.actor}, ${ref.id}, ${blob.name}, ${name},
|
|
128
|
+
${contentRef.hash}, ${contentRef.size}
|
|
129
|
+
FROM used WHERE live AND (present OR entries < ${scope.maxEntries})
|
|
130
|
+
ON CONFLICT (routing_key, tenant_id, actor_type, actor_id, blob, name)
|
|
131
|
+
DO UPDATE SET hash = EXCLUDED.hash, size = EXCLUDED.size)
|
|
132
|
+
SELECT live, present OR entries < ${scope.maxEntries} AS fits FROM used`);
|
|
133
|
+
if (!checked.live)
|
|
134
|
+
return yield* InvalidContentRef.make({ reason: "expired" });
|
|
135
|
+
if (!checked.fits)
|
|
136
|
+
return yield* tooManyEntries;
|
|
137
|
+
yield* noted(blob);
|
|
138
|
+
}),
|
|
139
|
+
detach: (name) => atEntry(blob, name, (where) => Effect.andThen(sql `DELETE FROM actor_content_refs WHERE ${where}`, noted(blob))),
|
|
140
|
+
list,
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
const access = (blob) => {
|
|
144
|
+
if (isContent(blob))
|
|
145
|
+
return contentAccess(blob);
|
|
146
|
+
const copy = (bytes) => {
|
|
147
|
+
if (!(bytes instanceof Uint8Array))
|
|
148
|
+
return Effect.die(new Error("Blob bytes are a Uint8Array"));
|
|
149
|
+
return bytes.byteLength > MAX_ENTRY_BYTES ? oversized : Effect.succeed(Uint8Array.from(bytes));
|
|
150
|
+
};
|
|
151
|
+
const oversized = Effect.die(new Error(`A blob entry holds at most ${MAX_ENTRY_BYTES} bytes`));
|
|
152
|
+
const read = {
|
|
153
|
+
get: (name) => atEntry(blob, name, (where) => Effect.map(sql `
|
|
154
|
+
SELECT string_agg(bytes, ''::bytea ORDER BY chunk) AS bytes
|
|
155
|
+
FROM actor_blobs WHERE ${where}`, ([found]) => Option.map(Option.fromNullishOr(found?.bytes), (bytes) => Uint8Array.from(bytes)))),
|
|
156
|
+
};
|
|
157
|
+
if (!write)
|
|
158
|
+
return read;
|
|
159
|
+
const values = (name, chunk, bytes) => sql `${routingKey}::bigint, ${ref.tenant}, ${ref.actor}, ${ref.id}, ${blob.name}, ${name}, ${chunk}, ${bytes}::bytea`;
|
|
160
|
+
const usage = (where) => sql `
|
|
161
|
+
SELECT (count(*) FILTER (WHERE chunk = 0) + ${references})::float8 AS entries,
|
|
162
|
+
COALESCE(bool_or(${where}), false) AS present,
|
|
163
|
+
COALESCE(sum(octet_length(bytes)) FILTER (WHERE ${where}), 0)::float8 AS entry_bytes
|
|
164
|
+
FROM actor_blobs WHERE ${owner}`.pipe(Effect.map(([row]) => row));
|
|
165
|
+
const refused = (used) => !used.present && used.entries >= scope.maxEntries ? tooManyEntries : overQuota;
|
|
166
|
+
return {
|
|
167
|
+
...read,
|
|
168
|
+
set: (name, bytes) => atEntry(blob, name, (where) => Effect.gen(function* () {
|
|
169
|
+
const copied = yield* copy(bytes);
|
|
170
|
+
const written = yield* sql `WITH used AS (
|
|
171
|
+
SELECT COALESCE(sum(octet_length(bytes)) FILTER (WHERE NOT (${where})), 0) AS other,
|
|
172
|
+
count(*) FILTER (WHERE chunk = 0) + ${references} AS entries,
|
|
173
|
+
COALESCE(bool_or(${where}), false) AS present
|
|
174
|
+
FROM actor_blobs WHERE ${owner}),
|
|
175
|
+
fits AS (
|
|
176
|
+
SELECT 1 FROM used WHERE other + ${copied.byteLength} <= ${scope.maxBytes}
|
|
177
|
+
AND (present OR entries < ${scope.maxEntries})),
|
|
178
|
+
dropped AS (
|
|
179
|
+
DELETE FROM actor_blobs WHERE ${where} AND chunk > 0 AND EXISTS (SELECT 1 FROM fits))
|
|
180
|
+
INSERT INTO actor_blobs (routing_key, tenant_id, actor_type, actor_id, blob, name, chunk, bytes)
|
|
181
|
+
SELECT ${values(name, sql.literal("0"), copied)} FROM fits
|
|
182
|
+
ON CONFLICT (routing_key, tenant_id, actor_type, actor_id, blob, name, chunk)
|
|
183
|
+
DO UPDATE SET bytes = EXCLUDED.bytes
|
|
184
|
+
RETURNING chunk`;
|
|
185
|
+
if (written.length === 0)
|
|
186
|
+
return yield* refused(yield* usage(where));
|
|
187
|
+
yield* noted(blob);
|
|
188
|
+
})),
|
|
189
|
+
append: (name, bytes) => atEntry(blob, name, (where) => Effect.gen(function* () {
|
|
190
|
+
const copied = yield* copy(bytes);
|
|
191
|
+
const inserted = yield* sql `INSERT INTO actor_blobs (routing_key, tenant_id, actor_type, actor_id, blob, name, chunk, bytes)
|
|
192
|
+
SELECT ${values(name, sql.literal("COALESCE(max(chunk) FILTER (WHERE entry) + 1, 0)"), copied)}
|
|
193
|
+
FROM (SELECT chunk, bytes, (${where}) AS entry FROM actor_blobs WHERE ${owner}) AS owned
|
|
194
|
+
HAVING COALESCE(sum(octet_length(bytes)) FILTER (WHERE entry), 0) + ${copied.byteLength} <= ${MAX_ENTRY_BYTES}
|
|
195
|
+
AND COALESCE(sum(octet_length(bytes)), 0) + ${copied.byteLength} <= ${scope.maxBytes}
|
|
196
|
+
AND (bool_or(entry) OR count(*) FILTER (WHERE chunk = 0) + ${references} < ${scope.maxEntries})
|
|
197
|
+
RETURNING chunk`;
|
|
198
|
+
if (inserted.length === 0) {
|
|
199
|
+
const used = yield* usage(where);
|
|
200
|
+
return yield* used.entry_bytes + copied.byteLength > MAX_ENTRY_BYTES
|
|
201
|
+
? oversized
|
|
202
|
+
: refused(used);
|
|
203
|
+
}
|
|
204
|
+
yield* noted(blob);
|
|
205
|
+
})),
|
|
206
|
+
compact: (name) => atEntry(blob, name, (where) => Effect.andThen(sql `WITH merged AS (
|
|
207
|
+
DELETE FROM actor_blobs WHERE ${where} AND chunk > 0 RETURNING chunk, bytes)
|
|
208
|
+
UPDATE actor_blobs AS head
|
|
209
|
+
SET bytes = head.bytes || (SELECT string_agg(m.bytes, ''::bytea ORDER BY m.chunk) FROM merged AS m)
|
|
210
|
+
WHERE ${where} AND head.chunk = 0 AND EXISTS (SELECT 1 FROM merged)`, noted(blob))),
|
|
211
|
+
delete: (name) => atEntry(blob, name, (where) => Effect.andThen(sql `DELETE FROM actor_blobs WHERE ${where}`, noted(blob))),
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
return access;
|
|
215
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { Cause, Crypto, Effect, Result } from "effect";
|
|
2
|
+
import { SqlClient, SqlError } from "effect/sql";
|
|
3
|
+
import { ActorError } from "../../errors/actor.ts";
|
|
4
|
+
import { type Broadcast, type ConnectionLister, type EmittedEvent, type RegisteredCommand } from "../members.ts";
|
|
5
|
+
import { Outcome, type Request } from "../request.ts";
|
|
6
|
+
import type { TurnPolicy } from "../../policies/command.ts";
|
|
7
|
+
import { type CronEntry } from "../cron/schedule.ts";
|
|
8
|
+
import type { WriteSet } from "../connections/protocol.ts";
|
|
9
|
+
import type { UsageAccountingService } from "../telemetry/usage.ts";
|
|
10
|
+
import { type ActivationCache } from "../storage/generation.ts";
|
|
11
|
+
/** The events a turn committed: sequences `after + 1` onward, stamped `emittedAtMs`. */
|
|
12
|
+
export interface CommittedEvents {
|
|
13
|
+
readonly after: string;
|
|
14
|
+
readonly events: ReadonlyArray<EmittedEvent>;
|
|
15
|
+
readonly commandId: string;
|
|
16
|
+
readonly emittedAtMs: number;
|
|
17
|
+
}
|
|
18
|
+
/** One command waiting in an activation's mailbox, with the handler it runs. */
|
|
19
|
+
export interface Delivery {
|
|
20
|
+
readonly request: Request;
|
|
21
|
+
readonly command: RegisteredCommand;
|
|
22
|
+
/** Set only after this external id passes the fenced admission check. */
|
|
23
|
+
admitted?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* How one command of a batch ended: an outcome its receipt records or
|
|
27
|
+
* replays, or an admission error answered without a receipt.
|
|
28
|
+
*/
|
|
29
|
+
export type Settled = Result.Result<Outcome, ActorError>;
|
|
30
|
+
/** Rows a committed turn adds; nothing when it replays, acknowledges, or rolls back. */
|
|
31
|
+
export interface Written {
|
|
32
|
+
readonly receipts: number;
|
|
33
|
+
readonly events: number;
|
|
34
|
+
readonly intents: number;
|
|
35
|
+
readonly jobs: number;
|
|
36
|
+
}
|
|
37
|
+
/** What a committed or rolled-back batch answers. */
|
|
38
|
+
export interface Done {
|
|
39
|
+
readonly settled: ReadonlyArray<Settled>;
|
|
40
|
+
/** Broadcasts the batch's committed successes publish to the actor's connections. */
|
|
41
|
+
readonly broadcasts: ReadonlyArray<Broadcast>;
|
|
42
|
+
/** The actor's event sequence once the batch commits. */
|
|
43
|
+
readonly head: string;
|
|
44
|
+
/** Each command's committed events, stamped, in delivery order. */
|
|
45
|
+
readonly committed: ReadonlyArray<CommittedEvents>;
|
|
46
|
+
/** Started jobs the batch's commands cancelled. */
|
|
47
|
+
readonly cancelledJobs: ReadonlyArray<string>;
|
|
48
|
+
readonly generation: string;
|
|
49
|
+
/** The positions in `settled` that answered from a stored receipt. */
|
|
50
|
+
readonly replays: ReadonlySet<number>;
|
|
51
|
+
/** Rows the batch committed; none when it rolled back. */
|
|
52
|
+
readonly written: Written;
|
|
53
|
+
/** The commit version each caller's later queries wait for. */
|
|
54
|
+
readonly version: string;
|
|
55
|
+
/** The database clock read on the turn's session after the transaction ended. */
|
|
56
|
+
readonly endedAtMs: number;
|
|
57
|
+
/** What the batch changed that a watched query may have read; nothing when it rolled back. */
|
|
58
|
+
readonly wrote: WriteSet;
|
|
59
|
+
/** The commit made outbox or subscription work due now, so the relay should claim it at once. */
|
|
60
|
+
readonly wake: boolean;
|
|
61
|
+
/** The commit cancelled a job attempt that is running, so running attempts should look now. */
|
|
62
|
+
readonly cancelled: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Consecutive batches of one activation. `next` takes the batch already
|
|
66
|
+
* waiting, if any, without waiting for one; `prepare` runs before each
|
|
67
|
+
* batch's handlers, and `committed` once the batch commits or rolls back,
|
|
68
|
+
* before the next batch's handlers run. `publishesUnderLock` names a batch
|
|
69
|
+
* whose `committed` may wait for the generation row lock in a transaction of
|
|
70
|
+
* its own; the next batch's admission would hold that lock until `committed`
|
|
71
|
+
* returns, so it is sent only after.
|
|
72
|
+
*/
|
|
73
|
+
interface Run<W extends Delivery, RN, RP, RC> {
|
|
74
|
+
readonly first: ReadonlyArray<W>;
|
|
75
|
+
readonly next: Effect.Effect<ReadonlyArray<W> | undefined, never, RN>;
|
|
76
|
+
readonly prepare: Effect.Effect<void, never, RP>;
|
|
77
|
+
readonly committed: (batch: ReadonlyArray<W>, done: Done) => Effect.Effect<void, never, RC>;
|
|
78
|
+
readonly publishesUnderLock: (batch: ReadonlyArray<W>) => boolean;
|
|
79
|
+
/** Wraps one batch's handlers, commit, and answers in that batch's own span and logs. */
|
|
80
|
+
readonly observe: (batch: ReadonlyArray<W>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Why a run stopped early: the batch that failed, a following batch whose
|
|
84
|
+
* admission was already sent and is rolled back unseen with it, and the cause.
|
|
85
|
+
* Batches before them committed and were answered. `committed` says the batch
|
|
86
|
+
* itself ended, committed or cleanly rolled back, and failed while its callers
|
|
87
|
+
* were being answered, so its commands must resolve through their receipts.
|
|
88
|
+
*/
|
|
89
|
+
export interface Stopped<W extends Delivery> {
|
|
90
|
+
readonly batch: ReadonlyArray<W>;
|
|
91
|
+
readonly orphan: ReadonlyArray<W> | undefined;
|
|
92
|
+
readonly cause: Cause.Cause<unknown>;
|
|
93
|
+
readonly committed: boolean;
|
|
94
|
+
/** The turn never leased a session, so no fence statement or handler was run. */
|
|
95
|
+
readonly poolRefused?: boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Commands already waiting for one actor, run in delivery order in one
|
|
99
|
+
* framework transaction sent as two groups. The admission group opens the
|
|
100
|
+
* transaction, takes the generation fence, resolves every command's receipt
|
|
101
|
+
* under it, and on a cold activation acquires the next generation and reads
|
|
102
|
+
* state. The handlers run in memory once those replies arrive, each on the
|
|
103
|
+
* state the previous one left. The commit group writes the dirty state, each
|
|
104
|
+
* command's events and outbox rows, the creation marker, and every receipt,
|
|
105
|
+
* then commits. A lone command is a batch of one.
|
|
106
|
+
*
|
|
107
|
+
* Each command keeps its own outcome: a declared failure discards only its
|
|
108
|
+
* own staged work, and an admission error (expiry, `NotCreated`, a receipt
|
|
109
|
+
* conflict) answers only that command. A stale fence or any defect fails the
|
|
110
|
+
* whole batch and writes nothing. A batch with nothing to commit rolls back.
|
|
111
|
+
* Every command id in a batch must be distinct.
|
|
112
|
+
*
|
|
113
|
+
* `statements` marks an actor whose handler can issue SQL; only its handlers
|
|
114
|
+
* run under a savepoint, so a declared failure discards the handler's rows.
|
|
115
|
+
* The first handler's savepoint goes out with admission and each later one's
|
|
116
|
+
* with that handler's first statement. A handler that issued no statement has
|
|
117
|
+
* nothing to roll back, so its unsent savepoint is dropped. Rolling back to a
|
|
118
|
+
* savepoint keeps it, so each failed handler leaves one open until commit; a
|
|
119
|
+
* batch never holds more savepoints than its command cap. `parent` is a
|
|
120
|
+
* parent-placed actor's parent type, whose turns alone mint it, and `waited`
|
|
121
|
+
* holds the event tags workflows wait on.
|
|
122
|
+
*
|
|
123
|
+
* Admission statements take no parameter from another's reply, so they share
|
|
124
|
+
* one flight. The generation insert precedes the fenced read, so a brand-new
|
|
125
|
+
* actor's receipts resolve under the generation row lock. The timeout
|
|
126
|
+
* `set_config` runs before that insert, so `lock_timeout` bounds the insert's
|
|
127
|
+
* row waits but not the table lock taken as the statement starts;
|
|
128
|
+
* `statement_timeout` applies from the next statement. With row-level
|
|
129
|
+
* security the same statement takes the tenant role, which binds every later
|
|
130
|
+
* statement of the turn, the handler's included, to the actor's tenant at no
|
|
131
|
+
* extra round trip. A subscription delivery's cursor row is read in the
|
|
132
|
+
* fenced statement, and the delivery's canonical payload, not the event's
|
|
133
|
+
* bytes, binds its identity. When another runner advanced the generation
|
|
134
|
+
* since this activation acquired it, its cached state may be stale, so
|
|
135
|
+
* nothing runs, the activation drops its cache, and the retry reloads under a
|
|
136
|
+
* new generation.
|
|
137
|
+
*
|
|
138
|
+
* Admission checks. The generation row is locked in a materialized input
|
|
139
|
+
* before the read evaluates its clock, so time spent waiting for the fence
|
|
140
|
+
* cannot admit an identity that expired meanwhile. External ids are validated
|
|
141
|
+
* against the fenced read's clock before their receipt is released or a handler
|
|
142
|
+
* runs. An owner reports
|
|
143
|
+
* that admission on a retryable failure, so only a previously admitted
|
|
144
|
+
* redelivery can run past expiry, and not once retention could have pruned
|
|
145
|
+
* its receipt. No pre-delivery receipt read is needed. Only the relay's subscription
|
|
146
|
+
* deliveries reach a handler, and only a handler takes one, so no caller
|
|
147
|
+
* reaches it around the cursor or route. A routed event for a subscriber its
|
|
148
|
+
* creating command has not created is skipped, and its cursor keeps a stale
|
|
149
|
+
* redelivery from running after another command creates the subscriber. A
|
|
150
|
+
* minted actor is created only by the relay delivering the creating intent
|
|
151
|
+
* its parent's turn staged and committed: the mint proof binds the id to the
|
|
152
|
+
* parent's command, and the relay's claimed-row provenance proves that
|
|
153
|
+
* command committed the intent without reading another actor's shard.
|
|
154
|
+
*
|
|
155
|
+
* Handlers and commit. Calls of a commutative reducer already waiting right
|
|
156
|
+
* behind a command merge into its turn: their inputs are combined and reduced
|
|
157
|
+
* once. A complete result lists every key it keeps, and any other key it was
|
|
158
|
+
* given is deleted. A delivery's cursor position is applied with its receipt,
|
|
159
|
+
* declared failures included. Re-arming waiting workflows reads their steps,
|
|
160
|
+
* so it runs before the commit group and only an actor with a workflow
|
|
161
|
+
* waiting on an emitted class pays for it. A cold activation that replays or
|
|
162
|
+
* acknowledges still commits and keeps the generation it acquired, so work
|
|
163
|
+
* the replay wakes runs under it. The first batch a generation commits
|
|
164
|
+
* schedules every cron entry not yet ticking from the database clock after
|
|
165
|
+
* its handlers ran, so a first tick is never due before the batch that
|
|
166
|
+
* writes it. A batch's work is bounded like a lone turn's: interruption and
|
|
167
|
+
* the command timeout roll it back, and SQL failures are defects. A failed or
|
|
168
|
+
* unknown commit leaves nothing the cached state can be trusted for, so it
|
|
169
|
+
* clears the cache.
|
|
170
|
+
*
|
|
171
|
+
* On Postgres a run uses one leased session. Each admission group opens with
|
|
172
|
+
* `BEGIN`, and each commit group ends with `COMMIT`, whose command tag must
|
|
173
|
+
* be `COMMIT`, since Postgres answers `COMMIT` in an aborted transaction with
|
|
174
|
+
* `ROLLBACK`. While batch N commits, the next batch already waiting sends its
|
|
175
|
+
* `BEGIN` and admission group in the same flight, right behind N's `COMMIT`:
|
|
176
|
+
* the server runs them strictly after it, as a new transaction on the same
|
|
177
|
+
* session. That admission is built as if N commits, which its fence proves. A
|
|
178
|
+
* batch that leaves the cache cold is committed alone, so the next one
|
|
179
|
+
* prepares, which may acquire the generation itself, before its admission
|
|
180
|
+
* locks the generation row. So is a batch whose publication may wait for that
|
|
181
|
+
* lock in another transaction: an admission already behind its `COMMIT` would
|
|
182
|
+
* hold the lock until the publication it waits on ends, and neither would
|
|
183
|
+
* ever finish. N's callers are answered once its `COMMIT` reply
|
|
184
|
+
* arrives, and the next batch's handlers run only once its own fence and
|
|
185
|
+
* receipt replies arrive. If N's commit fails, the next batch's transaction
|
|
186
|
+
* is rolled back unseen with it. The commit version is read on the same
|
|
187
|
+
* session after the transaction ends, in the same flight, so it covers the
|
|
188
|
+
* batch's commit record and any receipt it replayed. The same statement reads
|
|
189
|
+
* a fresh clock after the transaction ended for the external expiry recheck,
|
|
190
|
+
* never reusing admission time.
|
|
191
|
+
*
|
|
192
|
+
* The session is unsafe from the moment a `BEGIN` may be queued until a
|
|
193
|
+
* transaction-ending reply with nothing queued behind it. Any other exit
|
|
194
|
+
* rolls back, and a session whose transaction state is unknown never goes
|
|
195
|
+
* back to the pool: an interrupted batch cancels its backend's statement and
|
|
196
|
+
* discards the session, so an unsent `COMMIT` rolls back with it and one
|
|
197
|
+
* already sent resolves through the receipt on retry. Deferred statements go
|
|
198
|
+
* out in the same flight as the next statement a handler sends, or at the
|
|
199
|
+
* head of the commit group.
|
|
200
|
+
*/
|
|
201
|
+
export declare const executeBatches: <W extends Delivery, RN, RP, RC>(run: Run<W, RN, RP, RC>, cache: ActivationCache, routingKey: bigint, policy: TurnPolicy, mintable: boolean, parent: string | undefined, statements: boolean, waited?: ReadonlySet<string> | undefined, connections?: ConnectionLister | undefined, cron?: readonly CronEntry[] | undefined, accounting?: UsageAccountingService | undefined) => Effect.Effect<{
|
|
202
|
+
batch: readonly W[];
|
|
203
|
+
orphan: readonly W[] | undefined;
|
|
204
|
+
cause: Cause.Cause<SqlError.SqlError>;
|
|
205
|
+
committed: false;
|
|
206
|
+
poolRefused: false;
|
|
207
|
+
} | undefined, SqlError.SqlError, RC | RN | RP | Crypto.Crypto | SqlClient.SqlClient>;
|
|
208
|
+
export {};
|