@rikalabs/akter 0.1.0-alpha.0 → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/CHANGELOG.md +46 -3
  2. package/README.md +2 -2
  3. package/dist/actor/definition.d.ts +13 -9
  4. package/dist/actor/descriptor.d.ts +2 -2
  5. package/dist/actor/descriptor.js +4 -4
  6. package/dist/client/calls.js +1 -1
  7. package/dist/client/index.d.ts +1 -1
  8. package/dist/client/index.js +1 -1
  9. package/dist/errors/actor.d.ts +12 -42
  10. package/dist/errors/actor.js +13 -42
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/members/payload.d.ts +1 -1
  14. package/dist/protocol/inspection.d.ts +221 -1
  15. package/dist/protocol/inspection.js +151 -2
  16. package/dist/protocol/wire.d.ts +6 -49
  17. package/dist/protocol/wire.js +1 -10
  18. package/dist/runtime/actors.d.ts +3 -0
  19. package/dist/runtime/adoption/backfill.js +1 -1
  20. package/dist/runtime/adoption/enforce.js +2 -2
  21. package/dist/runtime/adoption/observe.js +1 -1
  22. package/dist/runtime/adoption/plan.d.ts +1 -1
  23. package/dist/runtime/adoption/startup.js +1 -1
  24. package/dist/runtime/adoption/status.d.ts +1 -1
  25. package/dist/runtime/app.d.ts +65 -0
  26. package/dist/runtime/app.js +38 -0
  27. package/dist/runtime/connections/holder.d.ts +11 -1
  28. package/dist/runtime/connections/holder.js +8 -4
  29. package/dist/runtime/connections/streams.d.ts +4 -4
  30. package/dist/runtime/content/store.js +15 -11
  31. package/dist/runtime/database/bounded.d.ts +4 -18
  32. package/dist/runtime/database/bounded.js +36 -22
  33. package/dist/runtime/database/coordination.d.ts +12 -3
  34. package/dist/runtime/database/coordination.js +29 -36
  35. package/dist/runtime/database/migrations.d.ts +61 -29
  36. package/dist/runtime/database/migrations.js +375 -139
  37. package/dist/runtime/database/replica.d.ts +4 -1
  38. package/dist/runtime/database/replica.js +4 -1
  39. package/dist/runtime/database/schema.d.ts +13 -0
  40. package/dist/runtime/database/schema.js +13 -0
  41. package/dist/runtime/database/shards.d.ts +31 -13
  42. package/dist/runtime/database/shards.js +38 -26
  43. package/dist/runtime/entity/register.d.ts +8 -1
  44. package/dist/runtime/entity/register.js +58 -7
  45. package/dist/runtime/fleet/checks.js +4 -4
  46. package/dist/runtime/fleet/maintainer.d.ts +1 -1
  47. package/dist/runtime/fleet/maintainer.js +1 -1
  48. package/dist/runtime/index.d.ts +2 -0
  49. package/dist/runtime/index.js +1 -0
  50. package/dist/runtime/inspector/layer.d.ts +20 -0
  51. package/dist/runtime/inspector/layer.js +224 -5
  52. package/dist/runtime/inspector/queries.d.ts +54 -8
  53. package/dist/runtime/inspector/queries.js +84 -15
  54. package/dist/runtime/layer.d.ts +48 -39
  55. package/dist/runtime/layer.js +124 -56
  56. package/dist/runtime/operators/audit.d.ts +3 -0
  57. package/dist/runtime/operators/audit.js +6 -2
  58. package/dist/runtime/operators/repair.js +30 -10
  59. package/dist/runtime/operators/seed.js +4 -2
  60. package/dist/runtime/payloads/versions.d.ts +4 -4
  61. package/dist/runtime/payloads/versions.js +24 -15
  62. package/dist/runtime/queries.js +4 -2
  63. package/dist/runtime/registration.d.ts +5 -2
  64. package/dist/runtime/registration.js +3 -3
  65. package/dist/runtime/runner.d.ts +12 -0
  66. package/dist/runtime/runner.js +12 -0
  67. package/dist/runtime/storage/codec.d.ts +19 -7
  68. package/dist/runtime/storage/codec.js +23 -7
  69. package/dist/runtime/storage/placements.d.ts +6 -1
  70. package/dist/runtime/storage/placements.js +98 -6
  71. package/dist/runtime/storage/retention.d.ts +6 -0
  72. package/dist/runtime/storage/retention.js +25 -13
  73. package/dist/runtime/subscriptions/relay.js +47 -44
  74. package/dist/runtime/subscriptions/storage.d.ts +3 -2
  75. package/dist/runtime/subscriptions/storage.js +9 -6
  76. package/dist/runtime/telemetry/live.d.ts +255 -0
  77. package/dist/runtime/telemetry/live.js +540 -0
  78. package/dist/runtime/telemetry/metrics.d.ts +2 -0
  79. package/dist/runtime/telemetry/metrics.js +4 -1
  80. package/dist/runtime/telemetry/sampler.js +33 -13
  81. package/dist/runtime/telemetry/spans.d.ts +1 -1
  82. package/dist/runtime/telemetry/spans.js +1 -1
  83. package/dist/runtime/topology/locks.d.ts +6 -3
  84. package/dist/runtime/topology/locks.js +27 -4
  85. package/dist/runtime/turn/execute.d.ts +2 -0
  86. package/dist/runtime/turn/execute.js +5 -2
  87. package/dist/runtime/turn/pipeline.d.ts +5 -12
  88. package/dist/runtime/turn/pipeline.js +11 -11
  89. package/dist/runtime/turn/relay.d.ts +13 -3
  90. package/dist/runtime/turn/relay.js +27 -14
  91. package/dist/runtime/turn/rows.js +4 -4
  92. package/dist/runtime/workflows/compatibility.d.ts +1 -1
  93. package/dist/runtime/workflows/compatibility.js +85 -31
  94. package/dist/runtime/workflows/engine.js +20 -17
  95. package/dist/serve/layer.js +3 -2
  96. package/dist/tables/owned.d.ts +1 -1
  97. package/dist/tables/owned.js +1 -1
  98. package/dist/testing/actor-test.d.ts +2 -24
  99. package/dist/testing/actor-test.js +1 -27
  100. package/dist/testing/index.d.ts +0 -12
  101. package/dist/testing/index.js +0 -6
  102. package/package.json +1 -1
  103. package/dist/runtime/database/neki/migrations.d.ts +0 -31
  104. package/dist/runtime/database/neki/migrations.js +0 -276
  105. package/dist/runtime/database/neki/session.d.ts +0 -23
  106. package/dist/runtime/database/neki/session.js +0 -31
  107. package/dist/testing/cluster.d.ts +0 -93
  108. package/dist/testing/cluster.js +0 -296
  109. package/dist/testing/conformance/access.d.ts +0 -5
  110. package/dist/testing/conformance/access.js +0 -531
  111. package/dist/testing/conformance/admission.d.ts +0 -11
  112. package/dist/testing/conformance/admission.js +0 -182
  113. package/dist/testing/conformance/adoption.d.ts +0 -2
  114. package/dist/testing/conformance/adoption.js +0 -1019
  115. package/dist/testing/conformance/assertions.d.ts +0 -202
  116. package/dist/testing/conformance/assertions.js +0 -849
  117. package/dist/testing/conformance/batches.d.ts +0 -41
  118. package/dist/testing/conformance/batches.js +0 -388
  119. package/dist/testing/conformance/blobs.d.ts +0 -14
  120. package/dist/testing/conformance/blobs.js +0 -405
  121. package/dist/testing/conformance/capacity.d.ts +0 -8
  122. package/dist/testing/conformance/capacity.js +0 -433
  123. package/dist/testing/conformance/client.d.ts +0 -5
  124. package/dist/testing/conformance/client.js +0 -719
  125. package/dist/testing/conformance/cold-serve.d.ts +0 -16
  126. package/dist/testing/conformance/cold-serve.js +0 -254
  127. package/dist/testing/conformance/connections/actors.d.ts +0 -1143
  128. package/dist/testing/conformance/connections/actors.js +0 -180
  129. package/dist/testing/conformance/connections/harness.d.ts +0 -1754
  130. package/dist/testing/conformance/connections/harness.js +0 -142
  131. package/dist/testing/conformance/connections/holders.d.ts +0 -4
  132. package/dist/testing/conformance/connections/holders.js +0 -165
  133. package/dist/testing/conformance/connections/lifecycle.d.ts +0 -4
  134. package/dist/testing/conformance/connections/lifecycle.js +0 -113
  135. package/dist/testing/conformance/connections/limits.d.ts +0 -4
  136. package/dist/testing/conformance/connections/limits.js +0 -127
  137. package/dist/testing/conformance/connections/reauthorization.d.ts +0 -4
  138. package/dist/testing/conformance/connections/reauthorization.js +0 -170
  139. package/dist/testing/conformance/connections/resync.d.ts +0 -4
  140. package/dist/testing/conformance/connections/resync.js +0 -360
  141. package/dist/testing/conformance/connections/takeover.d.ts +0 -4
  142. package/dist/testing/conformance/connections/takeover.js +0 -287
  143. package/dist/testing/conformance/connections.d.ts +0 -4
  144. package/dist/testing/conformance/connections.js +0 -15
  145. package/dist/testing/conformance/content-blobs.d.ts +0 -16
  146. package/dist/testing/conformance/content-blobs.js +0 -534
  147. package/dist/testing/conformance/counter.d.ts +0 -16
  148. package/dist/testing/conformance/counter.js +0 -813
  149. package/dist/testing/conformance/cron.d.ts +0 -5
  150. package/dist/testing/conformance/cron.js +0 -665
  151. package/dist/testing/conformance/drain.d.ts +0 -26
  152. package/dist/testing/conformance/drain.js +0 -540
  153. package/dist/testing/conformance/effect-control.d.ts +0 -38
  154. package/dist/testing/conformance/effect-control.js +0 -1059
  155. package/dist/testing/conformance/effects.d.ts +0 -23
  156. package/dist/testing/conformance/effects.js +0 -432
  157. package/dist/testing/conformance/events.d.ts +0 -28
  158. package/dist/testing/conformance/events.js +0 -335
  159. package/dist/testing/conformance/export.d.ts +0 -2
  160. package/dist/testing/conformance/export.js +0 -368
  161. package/dist/testing/conformance/fleet.d.ts +0 -444
  162. package/dist/testing/conformance/fleet.js +0 -1009
  163. package/dist/testing/conformance/groups.d.ts +0 -7
  164. package/dist/testing/conformance/groups.js +0 -353
  165. package/dist/testing/conformance/heap.d.ts +0 -3
  166. package/dist/testing/conformance/heap.js +0 -149
  167. package/dist/testing/conformance/http.d.ts +0 -2809
  168. package/dist/testing/conformance/http.js +0 -1234
  169. package/dist/testing/conformance/inspection-views.d.ts +0 -8
  170. package/dist/testing/conformance/inspection-views.js +0 -272
  171. package/dist/testing/conformance/inspector.d.ts +0 -7
  172. package/dist/testing/conformance/inspector.js +0 -650
  173. package/dist/testing/conformance/mint.d.ts +0 -58
  174. package/dist/testing/conformance/mint.js +0 -692
  175. package/dist/testing/conformance/multi-runner.d.ts +0 -8
  176. package/dist/testing/conformance/multi-runner.js +0 -403
  177. package/dist/testing/conformance/neki/plan.d.ts +0 -19
  178. package/dist/testing/conformance/neki/plan.js +0 -30
  179. package/dist/testing/conformance/observability.d.ts +0 -3
  180. package/dist/testing/conformance/observability.js +0 -343
  181. package/dist/testing/conformance/offline.d.ts +0 -4
  182. package/dist/testing/conformance/offline.js +0 -474
  183. package/dist/testing/conformance/operator-harness.d.ts +0 -57
  184. package/dist/testing/conformance/operator-harness.js +0 -78
  185. package/dist/testing/conformance/operator.d.ts +0 -3
  186. package/dist/testing/conformance/operator.js +0 -379
  187. package/dist/testing/conformance/outbox-cross-shard.d.ts +0 -14
  188. package/dist/testing/conformance/outbox-cross-shard.js +0 -160
  189. package/dist/testing/conformance/outbox.d.ts +0 -36
  190. package/dist/testing/conformance/outbox.js +0 -437
  191. package/dist/testing/conformance/payload-migrations.d.ts +0 -3
  192. package/dist/testing/conformance/payload-migrations.js +0 -612
  193. package/dist/testing/conformance/pipeline.d.ts +0 -3
  194. package/dist/testing/conformance/pipeline.js +0 -1040
  195. package/dist/testing/conformance/placement.d.ts +0 -22
  196. package/dist/testing/conformance/placement.js +0 -539
  197. package/dist/testing/conformance/platform.d.ts +0 -40
  198. package/dist/testing/conformance/platform.js +0 -101
  199. package/dist/testing/conformance/progress.d.ts +0 -39
  200. package/dist/testing/conformance/progress.js +0 -666
  201. package/dist/testing/conformance/properties.d.ts +0 -6
  202. package/dist/testing/conformance/properties.js +0 -295
  203. package/dist/testing/conformance/protocols.d.ts +0 -4
  204. package/dist/testing/conformance/protocols.js +0 -618
  205. package/dist/testing/conformance/provider/advertise.d.ts +0 -21
  206. package/dist/testing/conformance/provider/advertise.js +0 -44
  207. package/dist/testing/conformance/read-your-writes.d.ts +0 -20
  208. package/dist/testing/conformance/read-your-writes.js +0 -192
  209. package/dist/testing/conformance/reducers.d.ts +0 -8
  210. package/dist/testing/conformance/reducers.js +0 -258
  211. package/dist/testing/conformance/relay.d.ts +0 -42
  212. package/dist/testing/conformance/relay.js +0 -1115
  213. package/dist/testing/conformance/restore.d.ts +0 -43
  214. package/dist/testing/conformance/restore.js +0 -341
  215. package/dist/testing/conformance/retention.d.ts +0 -14
  216. package/dist/testing/conformance/retention.js +0 -463
  217. package/dist/testing/conformance/rls.d.ts +0 -24
  218. package/dist/testing/conformance/rls.js +0 -576
  219. package/dist/testing/conformance/simulation.d.ts +0 -31
  220. package/dist/testing/conformance/simulation.js +0 -167
  221. package/dist/testing/conformance/single-shard.d.ts +0 -2
  222. package/dist/testing/conformance/single-shard.js +0 -125
  223. package/dist/testing/conformance/singleton.d.ts +0 -3
  224. package/dist/testing/conformance/singleton.js +0 -293
  225. package/dist/testing/conformance/statements.d.ts +0 -60
  226. package/dist/testing/conformance/statements.js +0 -108
  227. package/dist/testing/conformance/streams.d.ts +0 -7
  228. package/dist/testing/conformance/streams.js +0 -280
  229. package/dist/testing/conformance/subscriptions/access.d.ts +0 -4
  230. package/dist/testing/conformance/subscriptions/access.js +0 -98
  231. package/dist/testing/conformance/subscriptions/actors.d.ts +0 -4910
  232. package/dist/testing/conformance/subscriptions/actors.js +0 -372
  233. package/dist/testing/conformance/subscriptions/cluster.d.ts +0 -4
  234. package/dist/testing/conformance/subscriptions/cluster.js +0 -89
  235. package/dist/testing/conformance/subscriptions/delivery.d.ts +0 -4
  236. package/dist/testing/conformance/subscriptions/delivery.js +0 -253
  237. package/dist/testing/conformance/subscriptions/deploys.d.ts +0 -4
  238. package/dist/testing/conformance/subscriptions/deploys.js +0 -162
  239. package/dist/testing/conformance/subscriptions/epochs.d.ts +0 -4
  240. package/dist/testing/conformance/subscriptions/epochs.js +0 -169
  241. package/dist/testing/conformance/subscriptions/failures.d.ts +0 -4
  242. package/dist/testing/conformance/subscriptions/failures.js +0 -108
  243. package/dist/testing/conformance/subscriptions/feeds.d.ts +0 -4
  244. package/dist/testing/conformance/subscriptions/feeds.js +0 -218
  245. package/dist/testing/conformance/subscriptions/harness.d.ts +0 -124
  246. package/dist/testing/conformance/subscriptions/harness.js +0 -143
  247. package/dist/testing/conformance/subscriptions/operator.d.ts +0 -4
  248. package/dist/testing/conformance/subscriptions/operator.js +0 -128
  249. package/dist/testing/conformance/subscriptions/retention.d.ts +0 -4
  250. package/dist/testing/conformance/subscriptions/retention.js +0 -288
  251. package/dist/testing/conformance/subscriptions/routing.d.ts +0 -4
  252. package/dist/testing/conformance/subscriptions/routing.js +0 -179
  253. package/dist/testing/conformance/subscriptions.d.ts +0 -4
  254. package/dist/testing/conformance/subscriptions.js +0 -19
  255. package/dist/testing/conformance/tables.d.ts +0 -125
  256. package/dist/testing/conformance/tables.js +0 -664
  257. package/dist/testing/conformance/transports/actors.d.ts +0 -1907
  258. package/dist/testing/conformance/transports/actors.js +0 -163
  259. package/dist/testing/conformance/transports/client.d.ts +0 -3
  260. package/dist/testing/conformance/transports/client.js +0 -237
  261. package/dist/testing/conformance/transports/feeds.d.ts +0 -3
  262. package/dist/testing/conformance/transports/feeds.js +0 -232
  263. package/dist/testing/conformance/transports/harness.d.ts +0 -93
  264. package/dist/testing/conformance/transports/harness.js +0 -84
  265. package/dist/testing/conformance/transports/streams.d.ts +0 -3
  266. package/dist/testing/conformance/transports/streams.js +0 -96
  267. package/dist/testing/conformance/transports/websocket.d.ts +0 -3
  268. package/dist/testing/conformance/transports/websocket.js +0 -384
  269. package/dist/testing/conformance/transports/wire.d.ts +0 -141
  270. package/dist/testing/conformance/transports/wire.js +0 -204
  271. package/dist/testing/conformance/transports.d.ts +0 -3
  272. package/dist/testing/conformance/transports.js +0 -11
  273. package/dist/testing/conformance/watch.d.ts +0 -59
  274. package/dist/testing/conformance/watch.js +0 -879
  275. package/dist/testing/conformance/workflow-engine.d.ts +0 -97
  276. package/dist/testing/conformance/workflow-engine.js +0 -253
  277. package/dist/testing/conformance/workflow-versions.d.ts +0 -3
  278. package/dist/testing/conformance/workflow-versions.js +0 -545
  279. package/dist/testing/conformance/workflows/access.d.ts +0 -4
  280. package/dist/testing/conformance/workflows/access.js +0 -147
  281. package/dist/testing/conformance/workflows/actors.d.ts +0 -2317
  282. package/dist/testing/conformance/workflows/actors.js +0 -305
  283. package/dist/testing/conformance/workflows/basics.d.ts +0 -4
  284. package/dist/testing/conformance/workflows/basics.js +0 -144
  285. package/dist/testing/conformance/workflows/engine.d.ts +0 -4
  286. package/dist/testing/conformance/workflows/engine.js +0 -80
  287. package/dist/testing/conformance/workflows/guards.d.ts +0 -4
  288. package/dist/testing/conformance/workflows/guards.js +0 -172
  289. package/dist/testing/conformance/workflows/harness.d.ts +0 -14
  290. package/dist/testing/conformance/workflows/harness.js +0 -44
  291. package/dist/testing/conformance/workflows/recovery.d.ts +0 -4
  292. package/dist/testing/conformance/workflows/recovery.js +0 -181
  293. package/dist/testing/conformance/workflows/starts.d.ts +0 -4
  294. package/dist/testing/conformance/workflows/starts.js +0 -57
  295. package/dist/testing/conformance/workflows/suspension.d.ts +0 -4
  296. package/dist/testing/conformance/workflows/suspension.js +0 -106
  297. package/dist/testing/conformance/workflows/waits.d.ts +0 -4
  298. package/dist/testing/conformance/workflows/waits.js +0 -284
  299. package/dist/testing/conformance/workflows.d.ts +0 -4
  300. package/dist/testing/conformance/workflows.js +0 -19
  301. package/dist/testing/conformance.d.ts +0 -330
  302. package/dist/testing/conformance.js +0 -364
  303. package/dist/testing/foundation.d.ts +0 -41
  304. package/dist/testing/foundation.js +0 -517
  305. package/dist/testing/simulate-cluster.d.ts +0 -112
  306. package/dist/testing/simulate-cluster.js +0 -257
  307. package/dist/testing/simulate.d.ts +0 -90
  308. package/dist/testing/simulate.js +0 -127
@@ -1,41 +0,0 @@
1
- import { Effect, Fiber, Layer, Schema } from "effect";
2
- import { SqlClient } from "effect/sql";
3
- import { ActorTest } from "../actor-test.ts";
4
- import type { ConformanceCase, ConformanceSuite } from "../conformance.ts";
5
- export declare const reductions: {
6
- count: number;
7
- };
8
- /** Adds to the count; merged calls combine by summing. */
9
- export declare const Bump: import("../../index.ts").Reducer<"Bump", {
10
- readonly log: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
11
- readonly count: Schema.withDecodingDefault<Schema.Int, never>;
12
- }, Schema.Int, Schema.Void, Schema.Never>;
13
- /** Like `Bump`, but models a reducer bug: an input above 10 throws. */
14
- export declare const Fragile: import("../../index.ts").Reducer<"Fragile", {
15
- readonly log: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
16
- readonly count: Schema.withDecodingDefault<Schema.Int, never>;
17
- }, Schema.Int, Schema.Void, Schema.Never>;
18
- export declare const batchesLayer: Layer.Layer<never, never, import("../index.ts").InternalActors | SqlClient.SqlClient>;
19
- /**
20
- * Sends each call only once the previous one is in the actor's mailbox, so
21
- * the calls are delivered in the order given.
22
- */
23
- export declare const enqueue: <A, R>(calls: readonly Effect.Effect<A, never, R>[]) => Effect.Effect<Fiber.Fiber<A, never>[], never, R | ActorTest>;
24
- /**
25
- * Holds the actor's next turn before its commit, so every call enqueued
26
- * meanwhile is already waiting when the actor takes its next batch.
27
- */
28
- export declare const holding: <A, E, R>(first: Effect.Effect<A, E, R>) => Effect.Effect<{
29
- fiber: Fiber.Fiber<A, E>;
30
- release: Effect.Effect<void, never, never>;
31
- }, never, R | ActorTest>;
32
- /** The transaction that committed each receipt of `ref`, by command id. */
33
- export declare const transactions: (ref: {
34
- readonly tenant: string;
35
- readonly actor: string;
36
- readonly id: string;
37
- }) => Effect.Effect<Map<string, string>, never, SqlClient.SqlClient>;
38
- /** Turn-batch cases: waiting commands share one transaction in delivery order with one receipt each, respect the batch cap, and isolate declared failures and defects. */
39
- export declare const batchesConformance: ReadonlyArray<ConformanceCase>;
40
- /** The batch ledger actor. */
41
- export declare const batchesSuite: ConformanceSuite;
@@ -1,388 +0,0 @@
1
- import { pgTable, text } from "drizzle-orm/pg-core";
2
- import { Cause, Effect, Exit, Fiber, Layer, Result, Schema } from "effect";
3
- import { SqlClient } from "effect/sql";
4
- import { retryPoolRefusal } from "../../runtime/database/bounded.js";
5
- import { Actor, Actors, Intent } from "../../index.js";
6
- import { BATCH_CAP, MERGE_CAP } from "../../runtime/entity/mailbox.js";
7
- import { ActorTest } from "../actor-test.js";
8
- const marks = Actor.table(pgTable("batch_marks", { id: text("id").primaryKey() }));
9
- class Refused extends Schema.TaggedError()("Refused", { label: Schema.String }) {
10
- }
11
- const Entry = Schema.Struct({ log: Schema.Array(Schema.String), marks: Schema.Finite });
12
- const Append = Actor.command("Append", { payload: Schema.String, success: Entry });
13
- const Refuse = Actor.command("Refuse", { payload: Schema.String, error: Refused });
14
- const Explode = Actor.command("Explode", { payload: Schema.String });
15
- const Noted = Actor.command("Noted", {});
16
- /**
17
- * Each handler writes state and an owned row, so a batch of its commands
18
- * takes a savepoint per handler and threads state from one to the next.
19
- */
20
- const LedgerState = Actor.state({
21
- log: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
22
- count: Schema.Int.pipe(Schema.withDecodingDefault(Effect.succeed(0))),
23
- });
24
- export const reductions = { count: 0 };
25
- /** Adds to the count; merged calls combine by summing. */
26
- export const Bump = Actor.reducer("Bump", {
27
- state: LedgerState,
28
- payload: Schema.Int,
29
- reduce: (state, amount) => {
30
- reductions.count += 1;
31
- return Result.succeed({ ...state, count: state.count + amount });
32
- },
33
- batch: { combine: (first, second) => first + second },
34
- });
35
- /** Like `Bump`, but models a reducer bug: an input above 10 throws. */
36
- export const Fragile = Actor.reducer("Fragile", {
37
- state: LedgerState,
38
- payload: Schema.Int,
39
- reduce: (state, amount) => {
40
- if (amount > 10)
41
- throw new Error("Fragile reducer bug");
42
- return Result.succeed({ ...state, count: state.count + amount });
43
- },
44
- batch: { combine: (first, second) => first + second },
45
- });
46
- const Ledger = Actor.make("BatchLedger", {
47
- key: Schema.String,
48
- state: LedgerState,
49
- tables: [marks],
50
- api: { Append, Refuse, Explode, Bump, Fragile },
51
- internal: { Noted },
52
- policy: { mailboxCapacity: 2048 },
53
- });
54
- const runs = new Map();
55
- const ran = (label) => runs.set(label, (runs.get(label) ?? 0) + 1);
56
- export const batchesLayer = Layer.unwrap(Effect.gen(function* () {
57
- const sql = yield* SqlClient.SqlClient;
58
- yield* retryPoolRefusal(sql.unsafe(`CREATE TABLE IF NOT EXISTS batch_marks (
59
- routing_key bigint, tenant_id text, actor_id text, id text,
60
- PRIMARY KEY (routing_key, tenant_id, actor_id, id))`));
61
- return Ledger.toLayer(Effect.succeed({
62
- Append: Effect.fnUntraced(function* (label) {
63
- ran(label);
64
- const turn = yield* Ledger.Turn;
65
- const log = [...turn.state.log, label];
66
- yield* turn.state.set({ log });
67
- yield* turn.rows(marks).insert({ id: label });
68
- return { log, marks: yield* turn.rows(marks).count() };
69
- }),
70
- Refuse: Effect.fnUntraced(function* (label) {
71
- ran(label);
72
- const turn = yield* Ledger.Turn;
73
- yield* turn.state.set({ log: [...turn.state.log, label] });
74
- yield* turn.rows(marks).insert({ id: label });
75
- const self = yield* Ledger.intents(turn.id);
76
- yield* self.Noted().pipe(Intent.after("1 hour"));
77
- return yield* Refused.make({ label });
78
- }),
79
- Explode: Effect.fnUntraced(function* (label) {
80
- ran(label);
81
- const turn = yield* Ledger.Turn;
82
- yield* turn.state.set({ log: [...turn.state.log, label] });
83
- return yield* Effect.die(new Error("Batch member defect"));
84
- }),
85
- Noted: () => Effect.void,
86
- }));
87
- }).pipe(Effect.orDie));
88
- /**
89
- * Sends each call only once the previous one is in the actor's mailbox, so
90
- * the calls are delivered in the order given.
91
- */
92
- export const enqueue = Effect.fnUntraced(function* (calls) {
93
- const test = yield* ActorTest;
94
- const fibers = [];
95
- for (const call of calls) {
96
- const queued = yield* test.pauseNext("queued");
97
- fibers.push(yield* Effect.forkChild(call));
98
- yield* queued.reached;
99
- yield* queued.release;
100
- yield* Effect.yieldNow;
101
- }
102
- return fibers;
103
- });
104
- /**
105
- * Holds the actor's next turn before its commit, so every call enqueued
106
- * meanwhile is already waiting when the actor takes its next batch.
107
- */
108
- export const holding = Effect.fnUntraced(function* (first) {
109
- const test = yield* ActorTest;
110
- const held = yield* test.pauseNext("beforeCommit");
111
- const fiber = yield* Effect.forkChild(first);
112
- yield* held.reached;
113
- return { fiber, release: held.release };
114
- });
115
- /** The transaction that committed each receipt of `ref`, by command id. */
116
- export const transactions = Effect.fnUntraced(function* (ref) {
117
- const sql = yield* SqlClient.SqlClient;
118
- const rows = yield* sql `
119
- SELECT command_id, xmin::text AS tx FROM actor_receipts
120
- WHERE tenant_id = ${ref.tenant} AND actor_type = ${ref.actor} AND actor_id = ${ref.id}`;
121
- return new Map(rows.map((row) => [row.command_id, row.tx]));
122
- }, Effect.orDie);
123
- const mint = Effect.fnUntraced(function* (count) {
124
- const actors = yield* Actors;
125
- return yield* Effect.forEach(Array.from({ length: count }), () => actors.mintCommandId);
126
- });
127
- /** Turn-batch cases: waiting commands share one transaction in delivery order with one receipt each, respect the batch cap, and isolate declared failures and defects. */
128
- export const batchesConformance = [
129
- {
130
- name: "turn batch: waiting commands share one transaction in delivery order, each with its own receipt, and none replies before the commit",
131
- requiresIndependentConnections: true,
132
- timeoutMs: 60_000,
133
- run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
134
- const test = yield* ActorTest;
135
- const ledger = yield* Ledger.get("order");
136
- const [lone, ...ids] = yield* mint(5);
137
- const labels = ["order-a", "order-b", "order-c", "order-d"];
138
- const first = yield* holding(ledger.Append("order-first").pipe(Actor.commandId(lone)));
139
- const waiting = yield* enqueue(labels.map((label, index) => ledger.Append(label).pipe(Actor.commandId(ids[index]), Effect.orDie)));
140
- const commit = yield* test.pauseNext("beforeCommit");
141
- yield* first.release;
142
- expect(yield* Fiber.join(first.fiber)).toEqual({ log: ["order-first"], marks: 1 });
143
- yield* commit.reached;
144
- expect(waiting.map((fiber) => fiber.pollUnsafe())).toEqual(labels.map(() => undefined));
145
- yield* commit.release;
146
- const replies = yield* Effect.forEach(waiting, Fiber.join);
147
- expect(replies).toEqual(labels.map((_, index) => ({
148
- log: ["order-first", ...labels.slice(0, index + 1)],
149
- marks: index + 2,
150
- })));
151
- const committed = yield* transactions(ledger.ref);
152
- expect(new Set(ids.map((id) => committed.get(id))).size).toBe(1);
153
- expect(committed.get(ids[0])).not.toBe(committed.get(lone));
154
- expect(yield* test.inspect(ledger.ref)).toMatchObject({
155
- state: { log: ["order-first", ...labels] },
156
- receipts: 5,
157
- });
158
- })),
159
- },
160
- {
161
- name: "turn batch: no batch exceeds the cap of waiting commands",
162
- requiresIndependentConnections: true,
163
- timeoutMs: 60_000,
164
- run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
165
- const ledger = yield* Ledger.get("cap");
166
- const total = BATCH_CAP + 8;
167
- const [lone, ...ids] = yield* mint(total + 1);
168
- const first = yield* holding(ledger.Append("cap-first").pipe(Actor.commandId(lone)));
169
- const waiting = yield* enqueue(ids.map((id, index) => ledger.Append(`cap-${index}`).pipe(Actor.commandId(id), Effect.orDie)));
170
- yield* first.release;
171
- yield* Fiber.join(first.fiber);
172
- const replies = yield* Effect.forEach(waiting, Fiber.join);
173
- expect(replies.at(-1)).toMatchObject({ marks: total + 1 });
174
- const committed = yield* transactions(ledger.ref);
175
- const sizes = new Map();
176
- for (const id of ids) {
177
- const tx = committed.get(id);
178
- sizes.set(tx, (sizes.get(tx) ?? 0) + 1);
179
- }
180
- expect([...sizes.values()].sort((a, b) => b - a)).toEqual([BATCH_CAP, 8]);
181
- })),
182
- },
183
- {
184
- name: "turn batch: a declared failure discards only its own state, rows, and intents, and commits its failure receipt",
185
- requiresIndependentConnections: true,
186
- timeoutMs: 60_000,
187
- run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
188
- const test = yield* ActorTest;
189
- const ledger = yield* Ledger.get("declared");
190
- const [lone, before, refused, after] = yield* mint(4);
191
- const first = yield* holding(ledger.Append("declared-first").pipe(Actor.commandId(lone)));
192
- const [a, r, b] = yield* enqueue([
193
- ledger.Append("declared-a").pipe(Actor.commandId(before), Effect.exit),
194
- ledger.Refuse("declared-r").pipe(Actor.commandId(refused), Effect.exit),
195
- ledger.Append("declared-b").pipe(Actor.commandId(after), Effect.exit),
196
- ]);
197
- yield* first.release;
198
- yield* Fiber.join(first.fiber);
199
- expect(yield* Fiber.join(a)).toEqual(Exit.succeed({ log: ["declared-first", "declared-a"], marks: 2 }));
200
- expect(yield* Fiber.join(r)).toEqual(Exit.fail(Refused.make({ label: "declared-r" })));
201
- expect(yield* Fiber.join(b)).toEqual(Exit.succeed({ log: ["declared-first", "declared-a", "declared-b"], marks: 3 }));
202
- const committed = yield* transactions(ledger.ref);
203
- expect(new Set([before, refused, after].map((id) => committed.get(id))).size).toBe(1);
204
- expect(yield* test.inspect(ledger.ref)).toMatchObject({
205
- state: { log: ["declared-first", "declared-a", "declared-b"] },
206
- receipts: 4,
207
- outbox: 0,
208
- });
209
- expect(yield* ledger.Refuse("declared-r").pipe(Actor.commandId(refused), Effect.flip)).toEqual(Refused.make({ label: "declared-r" }));
210
- expect(runs.get("declared-r")).toBe(1);
211
- })),
212
- },
213
- {
214
- name: "turn batch: a defect rolls the batch back, then its commands run one per transaction",
215
- requiresIndependentConnections: true,
216
- timeoutMs: 60_000,
217
- run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
218
- const test = yield* ActorTest;
219
- const ledger = yield* Ledger.get("defect");
220
- const [lone, before, exploded, after] = yield* mint(4);
221
- const first = yield* holding(ledger.Append("defect-first").pipe(Actor.commandId(lone)));
222
- const [a, x, b] = yield* enqueue([
223
- ledger.Append("defect-a").pipe(Actor.commandId(before), Effect.exit),
224
- ledger.Explode("defect-x").pipe(Actor.commandId(exploded), Effect.exit),
225
- ledger.Append("defect-b").pipe(Actor.commandId(after), Effect.exit),
226
- ]);
227
- yield* first.release;
228
- yield* Fiber.join(first.fiber);
229
- expect(yield* Fiber.join(a)).toEqual(Exit.succeed({ log: ["defect-first", "defect-a"], marks: 2 }));
230
- const failed = yield* Fiber.join(x);
231
- expect(Exit.isFailure(failed) && Cause.hasDies(failed.cause)).toBe(true);
232
- expect(yield* Fiber.join(b)).toEqual(Exit.succeed({ log: ["defect-first", "defect-a", "defect-b"], marks: 3 }));
233
- expect(["defect-a", "defect-x", "defect-b"].map((label) => runs.get(label))).toEqual([
234
- 2, 2, 1,
235
- ]);
236
- const committed = yield* transactions(ledger.ref);
237
- expect(committed.has(exploded)).toBe(false);
238
- expect(committed.get(before)).not.toBe(committed.get(after));
239
- expect(yield* test.inspect(ledger.ref)).toMatchObject({
240
- state: { log: ["defect-first", "defect-a", "defect-b"] },
241
- receipts: 3,
242
- });
243
- })),
244
- },
245
- {
246
- name: "turn batch: a crash before the shared commit reruns each command alone, and a crash after it replays each receipt",
247
- requiresIndependentConnections: true,
248
- timeoutMs: 60_000,
249
- run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
250
- const test = yield* ActorTest;
251
- const ledger = yield* Ledger.get("crash");
252
- const [lone, ...ids] = yield* mint(7);
253
- const before = ["crash-a", "crash-b", "crash-c"];
254
- const after = ["crash-d", "crash-e", "crash-f"];
255
- const first = yield* holding(ledger.Append("crash-first").pipe(Actor.commandId(lone)));
256
- const early = yield* enqueue(before.map((label, index) => ledger.Append(label).pipe(Actor.commandId(ids[index]), Effect.orDie)));
257
- yield* test.crashNext("beforeCommit");
258
- yield* first.release;
259
- yield* Fiber.join(first.fiber);
260
- yield* Effect.forEach(early, Fiber.join);
261
- expect(before.map((label) => runs.get(label))).toEqual([2, 1, 1]);
262
- let committed = yield* transactions(ledger.ref);
263
- expect(new Set(ids.slice(0, 3).map((id) => committed.get(id))).size).toBe(3);
264
- const second = yield* holding(ledger.Append("crash-second"));
265
- const late = yield* enqueue(after.map((label, index) => ledger.Append(label).pipe(Actor.commandId(ids[index + 3]), Effect.orDie)));
266
- const shared = yield* test.pauseNext("beforeCommit");
267
- yield* second.release;
268
- yield* Fiber.join(second.fiber);
269
- yield* shared.reached;
270
- yield* test.crashNext("afterCommit");
271
- yield* shared.release;
272
- const replies = yield* Effect.forEach(late, Fiber.join);
273
- expect(replies.at(-1)).toMatchObject({ marks: 8 });
274
- expect(after.map((label) => runs.get(label))).toEqual([1, 1, 1]);
275
- committed = yield* transactions(ledger.ref);
276
- expect(new Set(ids.slice(3).map((id) => committed.get(id))).size).toBe(1);
277
- expect(yield* test.inspect(ledger.ref)).toMatchObject({ receipts: 8 });
278
- })),
279
- },
280
- {
281
- name: "turn batch: a retry waiting behind its original resolves through the original's receipt",
282
- requiresIndependentConnections: true,
283
- timeoutMs: 60_000,
284
- run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
285
- const test = yield* ActorTest;
286
- const ledger = yield* Ledger.get("duplicate");
287
- const [id] = yield* mint(1);
288
- const first = yield* holding(ledger.Append("duplicate-first"));
289
- const call = ledger.Append("duplicate-x").pipe(Actor.commandId(id), Effect.orDie);
290
- const [original, retry] = yield* enqueue([call, call]);
291
- yield* first.release;
292
- yield* Fiber.join(first.fiber);
293
- const reply = { log: ["duplicate-first", "duplicate-x"], marks: 2 };
294
- expect(yield* Fiber.join(original)).toEqual(reply);
295
- expect(yield* Fiber.join(retry)).toEqual(reply);
296
- expect(runs.get("duplicate-x")).toBe(1);
297
- expect(yield* test.inspect(ledger.ref)).toMatchObject({ receipts: 2 });
298
- })),
299
- },
300
- {
301
- name: "merged turn: commutative calls already waiting commit in one turn with one receipt per command id",
302
- requiresIndependentConnections: true,
303
- timeoutMs: 60_000,
304
- run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
305
- const test = yield* ActorTest;
306
- const ledger = yield* Ledger.get("merged");
307
- const ids = yield* mint(5);
308
- const first = yield* holding(ledger.Append("merged-first"));
309
- const waiting = yield* enqueue(ids.map((id, index) => ledger.Bump(index + 1).pipe(Actor.commandId(id), Effect.orDie)));
310
- const before = reductions.count;
311
- yield* first.release;
312
- yield* Fiber.join(first.fiber);
313
- expect(yield* Effect.forEach(waiting, Fiber.join)).toEqual(ids.map(() => undefined));
314
- expect(reductions.count - before).toBe(1);
315
- const committed = yield* transactions(ledger.ref);
316
- expect(ids.every((id) => committed.has(id))).toBe(true);
317
- expect(new Set(ids.map((id) => committed.get(id))).size).toBe(1);
318
- expect(yield* test.inspect(ledger.ref)).toMatchObject({
319
- state: { log: ["merged-first"], count: 15 },
320
- receipts: 6,
321
- });
322
- expect(yield* ledger.Bump(3).pipe(Actor.commandId(ids[2]))).toBe(undefined);
323
- expect(reductions.count - before).toBe(1);
324
- expect((yield* test.inspect(ledger.ref)).receipts).toBe(6);
325
- })),
326
- },
327
- {
328
- name: "merged turn: never combines more than 1,024 calls",
329
- requiresIndependentConnections: true,
330
- timeoutMs: 120_000,
331
- run: ({ expect, environment }) => Effect.runPromise(Effect.gen(function* () {
332
- yield* environment.stop;
333
- const runtime = environment.build({ admission: { concurrency: 2048 } });
334
- yield* Effect.promise(() => runtime
335
- .runPromise(Effect.scoped(Effect.gen(function* () {
336
- const ledger = yield* Ledger.get("merge-cap");
337
- const ids = yield* mint(MERGE_CAP + 6);
338
- const first = yield* holding(ledger.Append("merge-cap-first"));
339
- const waiting = yield* enqueue(ids.map((id) => ledger.Bump(1).pipe(Actor.commandId(id), Effect.orDie)));
340
- const before = reductions.count;
341
- yield* first.release;
342
- yield* Fiber.join(first.fiber);
343
- yield* Effect.forEach(waiting, Fiber.join);
344
- expect(reductions.count - before).toBe(2);
345
- const committed = yield* transactions(ledger.ref);
346
- expect(new Set(ids.map((id) => committed.get(id))).size).toBe(1);
347
- const [state] = yield* SqlClient.SqlClient.pipe(Effect.flatMap((sql) => sql `SELECT count(*)::integer AS receipts
348
- FROM actor_receipts WHERE actor_type = 'BatchLedger' AND actor_id = ${ledger.ref.id}
349
- AND command = 'Bump'`), Effect.orDie);
350
- expect(state.receipts).toBe(MERGE_CAP + 6);
351
- })))
352
- .finally(() => runtime.dispose()));
353
- }).pipe(Effect.ensuring(environment.restart))),
354
- },
355
- {
356
- name: "merged turn: a failing merged turn commits none of its calls, and each then runs alone",
357
- requiresIndependentConnections: true,
358
- timeoutMs: 60_000,
359
- run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
360
- const test = yield* ActorTest;
361
- const ledger = yield* Ledger.get("merge-fails");
362
- const [one, bad, two] = yield* mint(3);
363
- const first = yield* holding(ledger.Append("merge-fails-first"));
364
- const [a, x, b] = yield* enqueue([
365
- ledger.Fragile(1).pipe(Actor.commandId(one), Effect.exit),
366
- ledger.Fragile(13).pipe(Actor.commandId(bad), Effect.exit),
367
- ledger.Fragile(2).pipe(Actor.commandId(two), Effect.exit),
368
- ]);
369
- yield* first.release;
370
- yield* Fiber.join(first.fiber);
371
- expect(yield* Fiber.join(a)).toEqual(Exit.succeed(undefined));
372
- const failed = yield* Fiber.join(x);
373
- expect(Exit.isFailure(failed) && Cause.hasDies(failed.cause)).toBe(true);
374
- expect(yield* Fiber.join(b)).toEqual(Exit.succeed(undefined));
375
- const committed = yield* transactions(ledger.ref);
376
- expect(committed.has(bad)).toBe(false);
377
- expect(committed.get(one)).not.toBe(committed.get(two));
378
- expect(yield* test.inspect(ledger.ref)).toMatchObject({
379
- state: { count: 3 },
380
- receipts: 3,
381
- });
382
- })),
383
- },
384
- ];
385
- /** The batch ledger actor. */
386
- export const batchesSuite = {
387
- layer: () => batchesLayer,
388
- };
@@ -1,14 +0,0 @@
1
- import { Effect, Layer } from "effect";
2
- import type { ConformanceCase, ConformanceSuite } from "../conformance.ts";
3
- /** Blob names shared by two actor types, so only the scope keeps their entries apart. */
4
- export declare const files: import("../../index.ts").Blob<"files">;
5
- export interface BlobsFixture {
6
- escaped: Effect.Effect<unknown>;
7
- }
8
- export declare const blobsFixture: () => BlobsFixture;
9
- /** Handlers for the blob actors; `fixture` records handler runs so cases can tell a rerun from a replay. */
10
- export declare const blobsLayer: (fixture: BlobsFixture) => Layer.Layer<never, never, import("../index.ts").InternalActors>;
11
- /** Actor blob cases: tenant and actor scoping, append/compact/set round trips, and rollback with a declared failure. */
12
- export declare const blobsConformance: ReadonlyArray<ConformanceCase<BlobsFixture>>;
13
- /** The actor blob actors. */
14
- export declare const blobsSuite: ConformanceSuite<BlobsFixture>;