@typeonce/effect-machine 0.1.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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +5 -0
  3. package/README.md +117 -0
  4. package/dist/AtomMachine.d.ts +141 -0
  5. package/dist/AtomMachine.d.ts.map +1 -0
  6. package/dist/AtomMachine.js +191 -0
  7. package/dist/AtomMachine.js.map +1 -0
  8. package/dist/ClusterMachine.d.ts +250 -0
  9. package/dist/ClusterMachine.d.ts.map +1 -0
  10. package/dist/ClusterMachine.js +280 -0
  11. package/dist/ClusterMachine.js.map +1 -0
  12. package/dist/Machine.d.ts +2587 -0
  13. package/dist/Machine.d.ts.map +1 -0
  14. package/dist/Machine.js +923 -0
  15. package/dist/Machine.js.map +1 -0
  16. package/dist/cluster.d.ts +2 -0
  17. package/dist/cluster.d.ts.map +1 -0
  18. package/dist/cluster.js +2 -0
  19. package/dist/cluster.js.map +1 -0
  20. package/dist/index.d.ts +2 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +2 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/internal/machineErrors.d.ts +109 -0
  25. package/dist/internal/machineErrors.d.ts.map +1 -0
  26. package/dist/internal/machineErrors.js +65 -0
  27. package/dist/internal/machineErrors.js.map +1 -0
  28. package/dist/internal/machineModel.d.ts +88 -0
  29. package/dist/internal/machineModel.d.ts.map +1 -0
  30. package/dist/internal/machineModel.js +713 -0
  31. package/dist/internal/machineModel.js.map +1 -0
  32. package/dist/internal/machinePlanner.d.ts +64 -0
  33. package/dist/internal/machinePlanner.d.ts.map +1 -0
  34. package/dist/internal/machinePlanner.js +594 -0
  35. package/dist/internal/machinePlanner.js.map +1 -0
  36. package/dist/internal/machineProcess.d.ts +16 -0
  37. package/dist/internal/machineProcess.d.ts.map +1 -0
  38. package/dist/internal/machineProcess.js +170 -0
  39. package/dist/internal/machineProcess.js.map +1 -0
  40. package/dist/internal/machineRuntime.d.ts +119 -0
  41. package/dist/internal/machineRuntime.d.ts.map +1 -0
  42. package/dist/internal/machineRuntime.js +354 -0
  43. package/dist/internal/machineRuntime.js.map +1 -0
  44. package/dist/reactivity.d.ts +2 -0
  45. package/dist/reactivity.d.ts.map +1 -0
  46. package/dist/reactivity.js +2 -0
  47. package/dist/reactivity.js.map +1 -0
  48. package/package.json +76 -0
@@ -0,0 +1,250 @@
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as Option from "effect/Option";
5
+ import * as Schema from "effect/Schema";
6
+ import * as Machine from "./Machine.js";
7
+ import { Rpc } from "effect/unstable/rpc";
8
+ import { ClusterError, Entity, EntityAddress, MessageStorage, type Sharding, Snowflake } from "effect/unstable/cluster";
9
+ type EntityAddress = EntityAddress.EntityAddress;
10
+ type PersistenceError = ClusterError.PersistenceError;
11
+ type Snowflake = Snowflake.Snowflake;
12
+ /**
13
+ * Persisted machine checkpoint owned by the Cluster bridge.
14
+ *
15
+ * **Details**
16
+ *
17
+ * Machine identity and deployment version are stored around the generic
18
+ * encoded snapshot. The request id records the request that produced the
19
+ * checkpoint.
20
+ *
21
+ * @category models
22
+ * @since 4.0.0
23
+ */
24
+ export interface Checkpoint {
25
+ readonly machineId: string;
26
+ readonly version: string;
27
+ readonly requestId: Snowflake;
28
+ readonly snapshot: Machine.Machine.EncodedSnapshot;
29
+ }
30
+ /**
31
+ * Result of loading a checkpoint for a Cluster machine request.
32
+ *
33
+ * **Details**
34
+ *
35
+ * `processed` reports whether the exact Cluster request id was already
36
+ * committed. Storage implementations must retain enough request ids to detect
37
+ * redelivery even after later requests have advanced the checkpoint.
38
+ *
39
+ * @category models
40
+ * @since 4.0.0
41
+ */
42
+ export interface LoadResult {
43
+ readonly checkpoint: Option.Option<Checkpoint>;
44
+ readonly processed: boolean;
45
+ }
46
+ /**
47
+ * Result of atomically committing a Cluster machine request.
48
+ *
49
+ * @category models
50
+ * @since 4.0.0
51
+ */
52
+ export type CommitResult = CommitResult.Committed | CommitResult.Duplicate;
53
+ /**
54
+ * Constructors and types for Cluster machine commit results.
55
+ *
56
+ * @category models
57
+ * @since 4.0.0
58
+ */
59
+ export declare const CommitResult: {
60
+ Committed: () => CommitResult.Committed;
61
+ Duplicate: () => CommitResult.Duplicate;
62
+ };
63
+ /**
64
+ * Types for Cluster machine commit results.
65
+ *
66
+ * @since 4.0.0
67
+ */
68
+ export declare namespace CommitResult {
69
+ /**
70
+ * Indicates that the request id and checkpoint were committed atomically.
71
+ *
72
+ * @category models
73
+ * @since 4.0.0
74
+ */
75
+ interface Committed {
76
+ readonly _tag: "Committed";
77
+ }
78
+ /**
79
+ * Indicates that the request id was already committed.
80
+ *
81
+ * @category models
82
+ * @since 4.0.0
83
+ */
84
+ interface Duplicate {
85
+ readonly _tag: "Duplicate";
86
+ }
87
+ }
88
+ declare const Storage_base: Context.ServiceClass<Storage, "effect/cluster/ClusterMachine/Storage", {
89
+ readonly load: (address: EntityAddress, requestId: Snowflake) => Effect.Effect<LoadResult, PersistenceError>;
90
+ readonly commit: (address: EntityAddress, checkpoint: Checkpoint) => Effect.Effect<CommitResult, PersistenceError>;
91
+ }>;
92
+ /**
93
+ * Checkpoint persistence service used by Cluster machines.
94
+ *
95
+ * **When to use**
96
+ *
97
+ * Use to connect `ClusterMachine` to a durable checkpoint store that can
98
+ * atomically deduplicate request ids and replace the current checkpoint.
99
+ *
100
+ * **Gotchas**
101
+ *
102
+ * For checkpoint and emitted-message persistence to commit atomically, this
103
+ * service must join the transaction opened through the configured
104
+ * `MessageStorage`. The reply is persisted after that transaction; storing the
105
+ * request id with the checkpoint makes a redelivery recover that reply without
106
+ * applying the transition again. A separate transaction or database cannot
107
+ * provide checkpoint-and-emission atomicity.
108
+ *
109
+ * @category services
110
+ * @since 4.0.0
111
+ */
112
+ export declare class Storage extends Storage_base {
113
+ }
114
+ declare const Accepted_base: Schema.Class<Accepted, Schema.TaggedStruct<"Accepted", {}>, {}>;
115
+ /**
116
+ * Successful result returned after a Cluster machine request is committed or
117
+ * recognized as a redelivery.
118
+ *
119
+ * @category models
120
+ * @since 4.0.0
121
+ */
122
+ export declare class Accepted extends Accepted_base {
123
+ }
124
+ /**
125
+ * Schema for reasons a Cluster machine request can be rejected without
126
+ * advancing its checkpoint.
127
+ *
128
+ * @category models
129
+ * @since 4.0.0
130
+ */
131
+ export declare const RejectionReason: Schema.Literals<readonly ["MachineIdMismatch", "VersionMismatch", "InvalidCheckpoint", "UnsupportedProcessLocal", "TransitionFailure", "PersistenceFailure", "EmissionFailure"]>;
132
+ /**
133
+ * Type of {@link RejectionReason}.
134
+ *
135
+ * @category models
136
+ * @since 4.0.0
137
+ */
138
+ export type RejectionReason = typeof RejectionReason.Type;
139
+ declare const Rejected_base: Schema.Class<Rejected, Schema.TaggedStruct<"Rejected", {
140
+ readonly reason: Schema.Literals<readonly ["MachineIdMismatch", "VersionMismatch", "InvalidCheckpoint", "UnsupportedProcessLocal", "TransitionFailure", "PersistenceFailure", "EmissionFailure"]>;
141
+ readonly message: Schema.String;
142
+ }>, {}>;
143
+ /**
144
+ * Rejected Cluster machine request. Transaction-participating durable storage
145
+ * leaves the previous checkpoint in place and suppresses emitted events.
146
+ *
147
+ * @category models
148
+ * @since 4.0.0
149
+ */
150
+ export declare class Rejected extends Rejected_base {
151
+ }
152
+ /**
153
+ * Schema for Cluster machine request outcomes.
154
+ *
155
+ * @category schemas
156
+ * @since 4.0.0
157
+ */
158
+ export declare const SendResult: Schema.Union<readonly [typeof Accepted, typeof Rejected]>;
159
+ type SendRpc<Events extends ReadonlyArray<Machine.Machine.TaggedSchema>> = Rpc.Rpc<"send", Schema.Union<Events>, typeof SendResult>;
160
+ type MachineEvents<M extends Machine.Machine.Any> = M extends Machine.Machine<any, infer Events, any, any, any, any, any, any, any, any, any, any> ? Events & ReadonlyArray<Machine.Machine.TaggedSchema> : never;
161
+ type MachineEmits<M extends Machine.Machine.Any> = M extends Machine.Machine<any, any, any, any, any, any, any, any, any, any, infer Emits, any> ? Emits & ReadonlyArray<Machine.Machine.TaggedSchema> : never;
162
+ /**
163
+ * Cluster adapter for one machine definition and entity type.
164
+ *
165
+ * **Details**
166
+ *
167
+ * The adapter exposes one persisted `send` RPC. Entity requests are serialized
168
+ * by the normal Cluster entity concurrency and every accepted request advances
169
+ * the checkpoint at most once.
170
+ *
171
+ * @category models
172
+ * @since 4.0.0
173
+ */
174
+ export interface ClusterMachine<in out Type extends string, in out M extends Machine.Machine.Any, out Services = MachineServices<M>> {
175
+ readonly machine: M;
176
+ readonly entity: Entity.Entity<Type, SendRpc<MachineEvents<M>>>;
177
+ /**
178
+ * Creates the Cluster entity layer for this machine.
179
+ *
180
+ * **Gotchas**
181
+ *
182
+ * `enqueue` runs after the checkpoint write in the same `MessageStorage`
183
+ * transaction. It must durably enqueue emitted events in that transaction;
184
+ * arbitrary external effects are not atomic with the checkpoint. The reply
185
+ * is persisted after commit and recovered through request-id deduplication if
186
+ * delivery is interrupted. Machines that never emit may omit `enqueue`.
187
+ */
188
+ readonly toLayer: <R = never>(options?: {
189
+ readonly enqueue?: (event: Machine.Machine.EmitOf<MachineEmits<M>>) => Effect.Effect<void, unknown, R>;
190
+ }) => Layer.Layer<never, never, Storage | MessageStorage.MessageStorage | Sharding.Sharding | R | Services>;
191
+ }
192
+ type MachineServices<M extends Machine.Machine.Any> = M extends Machine.Machine<infer States, infer Events, any, any, any, infer R, any, infer InitialR, any, any, infer Emits, any> ? ExcludeCompatibleRuntime<Machine.ExecutionServices<R | InitialR>, Machine.Machine.EventOf<Events & ReadonlyArray<Machine.Machine.TaggedSchema>>, Machine.Machine.EmitOf<Emits & ReadonlyArray<Machine.Machine.TaggedSchema>>> | Machine.Machine.SnapshotDecodingServices<States & Machine.Machine.StateSchemas> | Machine.Machine.SnapshotEncodingServices<States & Machine.Machine.StateSchemas> : never;
193
+ type IsAny<A> = 0 extends (1 & A) ? true : false;
194
+ type ExcludeCompatibleRuntime<Requirements, Events, Emits> = Requirements extends Machine.Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? Requirements : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : Requirements;
195
+ /**
196
+ * Creates an in-memory Cluster machine checkpoint store.
197
+ *
198
+ * **When to use**
199
+ *
200
+ * Use when you test or run a local process that does not require checkpoints
201
+ * to survive a restart.
202
+ *
203
+ * **Gotchas**
204
+ *
205
+ * This store is not durable and does not provide rollback with the in-memory
206
+ * `MessageStorage` transaction marker.
207
+ *
208
+ * @category constructors
209
+ * @since 4.0.0
210
+ */
211
+ export declare const makeMemory: Effect.Effect<Storage["Service"]>;
212
+ /**
213
+ * Layer providing the in-memory Cluster machine checkpoint store.
214
+ *
215
+ * @category layers
216
+ * @since 4.0.0
217
+ */
218
+ export declare const layerMemory: Layer.Layer<Storage>;
219
+ /**
220
+ * Creates a persisted Cluster entity adapter for a machine.
221
+ *
222
+ * **When to use**
223
+ *
224
+ * Use when each Cluster entity id should own one durable machine snapshot and
225
+ * accept schema-validated machine events through a persisted `send` RPC.
226
+ *
227
+ * **Details**
228
+ *
229
+ * A missing checkpoint runs initial planning before the first event. Existing
230
+ * checkpoints are identity-checked, version-checked, decoded, and resumed
231
+ * without rerunning initial entry behavior. Final checkpoints accept later
232
+ * requests as no-ops. The stable bridge identity is `machine.id` when present,
233
+ * otherwise the Cluster entity type.
234
+ *
235
+ * **Gotchas**
236
+ *
237
+ * Invoked processes, spawned children, action-time `runtime.raise`, timers,
238
+ * subscriptions, and other process-local state are not durable and are
239
+ * rejected. Planning-time raised events remain part of the current macrostep.
240
+ * Arbitrary action effects may run again after a crash before checkpoint
241
+ * commit, so the bridge does not provide exactly-once external effects.
242
+ *
243
+ * @category constructors
244
+ * @since 4.0.0
245
+ */
246
+ export declare const make: <const Type extends string, States extends Machine.Machine.StateSchemas, Events extends ReadonlyArray<Machine.Machine.TaggedSchema>, Input extends Schema.Top, UnhandledStates extends Machine.Machine.StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends Machine.Machine.StateIdentifier<States>, Output, Emits extends ReadonlyArray<Machine.Machine.TaggedSchema>, OutputStates extends Machine.Machine.StateIdentifier<States>>(type: Type, machine: Machine.Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates>, options: {
247
+ readonly version: string;
248
+ }, ...input: [...Machine.Machine.InputArgs<Input>]) => ClusterMachine<Type, Machine.Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates>, ExcludeCompatibleRuntime<Machine.ExecutionServices<R | InitialR>, Machine.Machine.EventOf<Events>, Machine.Machine.EmitOf<Emits>> | Machine.Machine.SnapshotDecodingServices<States> | Machine.Machine.SnapshotEncodingServices<States>>;
249
+ export {};
250
+ //# sourceMappingURL=ClusterMachine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClusterMachine.d.ts","sourceRoot":"","sources":["../src/ClusterMachine.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EACL,YAAY,EAEZ,MAAM,EACN,aAAa,EACb,cAAc,EACd,KAAK,QAAQ,EACb,SAAS,EACV,MAAM,yBAAyB,CAAA;AAEhC,KAAK,aAAa,GAAG,aAAa,CAAC,aAAa,CAAA;AAChD,KAAK,gBAAgB,GAAG,YAAY,CAAC,gBAAgB,CAAA;AACrD,KAAK,SAAS,GAAG,SAAS,CAAC,SAAS,CAAA;AAEpC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,EAC/D,CAAC,EACD,CAAC,EACD,QAAQ,EACR,QAAQ,EACR,WAAW,SAAS,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,EAC3D,MAAM,EACN,KAAK,SAAS,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EACzD,YAAY,SAAS,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,EAE5D,MAAM,IAAI,EACV,SAAS,OAAO,CAAC,OAAO,CACtB,MAAM,EACN,MAAM,EACN,KAAK,EACL,eAAe,EACf,CAAC,EACD,CAAC,EACD,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,MAAM,EACN,KAAK,EACL,YAAY,CACb,EACD,SAAS;IACP,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB,EACD,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,KAC9C,cAAc,CACf,IAAI,EACJ,OAAO,CAAC,OAAO,CACb,MAAM,EACN,MAAM,EACN,KAAK,EACL,eAAe,EACf,CAAC,EACD,CAAC,EACD,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,MAAM,EACN,KAAK,EACL,YAAY,CACb,EACC,wBAAwB,CACxB,OAAO,CAAC,iBAAiB,CAAC,CAAC,GAAG,QAAQ,CAAC,EACvC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAC/B,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAC9B,GACC,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC,MAAM,CAAC,GAChD,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC,MAAM,CAAC,CA6JnD,CAAA"}
@@ -0,0 +1,280 @@
1
+ /**
2
+ * Runs Effect machines as persisted Cluster entities.
3
+ *
4
+ * @since 4.0.0
5
+ */
6
+ import * as Cause from "effect/Cause";
7
+ import * as Context from "effect/Context";
8
+ import * as Effect from "effect/Effect";
9
+ import * as Layer from "effect/Layer";
10
+ import * as Option from "effect/Option";
11
+ import * as Schema from "effect/Schema";
12
+ import * as Machine from "./Machine.js";
13
+ import { Rpc } from "effect/unstable/rpc";
14
+ import { ClusterError, ClusterSchema, Entity, EntityAddress, MessageStorage, Snowflake } from "effect/unstable/cluster";
15
+ /**
16
+ * Constructors and types for Cluster machine commit results.
17
+ *
18
+ * @category models
19
+ * @since 4.0.0
20
+ */
21
+ export const CommitResult = {
22
+ Committed: () => ({ _tag: "Committed" }),
23
+ Duplicate: () => ({ _tag: "Duplicate" })
24
+ };
25
+ /**
26
+ * Checkpoint persistence service used by Cluster machines.
27
+ *
28
+ * **When to use**
29
+ *
30
+ * Use to connect `ClusterMachine` to a durable checkpoint store that can
31
+ * atomically deduplicate request ids and replace the current checkpoint.
32
+ *
33
+ * **Gotchas**
34
+ *
35
+ * For checkpoint and emitted-message persistence to commit atomically, this
36
+ * service must join the transaction opened through the configured
37
+ * `MessageStorage`. The reply is persisted after that transaction; storing the
38
+ * request id with the checkpoint makes a redelivery recover that reply without
39
+ * applying the transition again. A separate transaction or database cannot
40
+ * provide checkpoint-and-emission atomicity.
41
+ *
42
+ * @category services
43
+ * @since 4.0.0
44
+ */
45
+ export class Storage extends Context.Service()("effect/cluster/ClusterMachine/Storage") {
46
+ }
47
+ /**
48
+ * Successful result returned after a Cluster machine request is committed or
49
+ * recognized as a redelivery.
50
+ *
51
+ * @category models
52
+ * @since 4.0.0
53
+ */
54
+ export class Accepted extends Schema.TaggedClass("effect/cluster/ClusterMachine/Accepted")("Accepted", {}) {
55
+ }
56
+ /**
57
+ * Schema for reasons a Cluster machine request can be rejected without
58
+ * advancing its checkpoint.
59
+ *
60
+ * @category models
61
+ * @since 4.0.0
62
+ */
63
+ export const RejectionReason = Schema.Literals([
64
+ "MachineIdMismatch",
65
+ "VersionMismatch",
66
+ "InvalidCheckpoint",
67
+ "UnsupportedProcessLocal",
68
+ "TransitionFailure",
69
+ "PersistenceFailure",
70
+ "EmissionFailure"
71
+ ]);
72
+ /**
73
+ * Rejected Cluster machine request. Transaction-participating durable storage
74
+ * leaves the previous checkpoint in place and suppresses emitted events.
75
+ *
76
+ * @category models
77
+ * @since 4.0.0
78
+ */
79
+ export class Rejected extends Schema.TaggedClass("effect/cluster/ClusterMachine/Rejected")("Rejected", {
80
+ reason: RejectionReason,
81
+ message: Schema.String
82
+ }) {
83
+ }
84
+ /**
85
+ * Schema for Cluster machine request outcomes.
86
+ *
87
+ * @category schemas
88
+ * @since 4.0.0
89
+ */
90
+ export const SendResult = Schema.Union([Accepted, Rejected]);
91
+ const hasInvokes = (machine) => Reflect.ownKeys(machine.handlers).some((key) => machine.handlers[key]?.invoke !== undefined);
92
+ const reject = (reason, message) => new Rejected({ reason, message });
93
+ const fail = (reason, message) => Effect.fail(reject(reason, message));
94
+ const messageFromCause = (cause) => {
95
+ const squashed = Cause.squash(cause);
96
+ return squashed instanceof globalThis.Error ? squashed.message : String(squashed);
97
+ };
98
+ const rejectionFromCause = (cause) => {
99
+ const error = Cause.findErrorOption(cause);
100
+ if (Option.isSome(error) && error.value instanceof Rejected) {
101
+ return error.value;
102
+ }
103
+ if (Option.isSome(error) && error.value instanceof Machine.ProcessLocalError) {
104
+ return reject("UnsupportedProcessLocal", `${error.value.operation} is process-local and is not supported`);
105
+ }
106
+ return reject("TransitionFailure", messageFromCause(cause));
107
+ };
108
+ const addressKey = (address) => `${address.entityType}\u0000${address.entityId}`;
109
+ /**
110
+ * Creates an in-memory Cluster machine checkpoint store.
111
+ *
112
+ * **When to use**
113
+ *
114
+ * Use when you test or run a local process that does not require checkpoints
115
+ * to survive a restart.
116
+ *
117
+ * **Gotchas**
118
+ *
119
+ * This store is not durable and does not provide rollback with the in-memory
120
+ * `MessageStorage` transaction marker.
121
+ *
122
+ * @category constructors
123
+ * @since 4.0.0
124
+ */
125
+ export const makeMemory = Effect.sync(() => {
126
+ const entries = new Map();
127
+ return Storage.of({
128
+ load: (address, requestId) => Effect.sync(() => {
129
+ const entry = entries.get(addressKey(address));
130
+ return {
131
+ checkpoint: Option.fromNullishOr(entry?.checkpoint),
132
+ processed: entry?.requests.has(requestId) ?? false
133
+ };
134
+ }),
135
+ commit: (address, checkpoint) => Effect.sync(() => {
136
+ const key = addressKey(address);
137
+ const entry = entries.get(key);
138
+ if (entry?.requests.has(checkpoint.requestId)) {
139
+ return CommitResult.Duplicate();
140
+ }
141
+ if (entry === undefined) {
142
+ entries.set(key, {
143
+ checkpoint,
144
+ requests: new Set([checkpoint.requestId])
145
+ });
146
+ }
147
+ else {
148
+ entry.checkpoint = checkpoint;
149
+ entry.requests.add(checkpoint.requestId);
150
+ }
151
+ return CommitResult.Committed();
152
+ })
153
+ });
154
+ });
155
+ /**
156
+ * Layer providing the in-memory Cluster machine checkpoint store.
157
+ *
158
+ * @category layers
159
+ * @since 4.0.0
160
+ */
161
+ export const layerMemory = Layer.effect(Storage, makeMemory);
162
+ /**
163
+ * Creates a persisted Cluster entity adapter for a machine.
164
+ *
165
+ * **When to use**
166
+ *
167
+ * Use when each Cluster entity id should own one durable machine snapshot and
168
+ * accept schema-validated machine events through a persisted `send` RPC.
169
+ *
170
+ * **Details**
171
+ *
172
+ * A missing checkpoint runs initial planning before the first event. Existing
173
+ * checkpoints are identity-checked, version-checked, decoded, and resumed
174
+ * without rerunning initial entry behavior. Final checkpoints accept later
175
+ * requests as no-ops. The stable bridge identity is `machine.id` when present,
176
+ * otherwise the Cluster entity type.
177
+ *
178
+ * **Gotchas**
179
+ *
180
+ * Invoked processes, spawned children, action-time `runtime.raise`, timers,
181
+ * subscriptions, and other process-local state are not durable and are
182
+ * rejected. Planning-time raised events remain part of the current macrostep.
183
+ * Arbitrary action effects may run again after a crash before checkpoint
184
+ * commit, so the bridge does not provide exactly-once external effects.
185
+ *
186
+ * @category constructors
187
+ * @since 4.0.0
188
+ */
189
+ export const make = (type, machine, options, ...input) => {
190
+ const eventSchema = Schema.Union(machine.events);
191
+ const rpc = Rpc.make("send", {
192
+ payload: eventSchema,
193
+ success: SendResult
194
+ })
195
+ .annotate(ClusterSchema.Persisted, true);
196
+ const entity = Entity.make(type, [rpc]);
197
+ const machineId = machine.id ?? type;
198
+ const toLayer = (layerOptions) => entity.toLayer(Effect.gen(function* () {
199
+ const storage = yield* Storage;
200
+ const messageStorage = yield* MessageStorage.MessageStorage;
201
+ const handle = Effect.fnUntraced(function* (request) {
202
+ if (hasInvokes(machine)) {
203
+ return yield* fail("UnsupportedProcessLocal", "Machine invoke configurations are process-local and cannot be restored");
204
+ }
205
+ const loaded = yield* storage.load(request.address, request.requestId).pipe(Effect.mapError((error) => reject("PersistenceFailure", String(error.cause))));
206
+ let current;
207
+ const emitted = [];
208
+ if (Option.isSome(loaded.checkpoint)) {
209
+ const checkpoint = loaded.checkpoint.value;
210
+ if (loaded.processed) {
211
+ return new Accepted({});
212
+ }
213
+ if (checkpoint.machineId !== machineId) {
214
+ return yield* fail("MachineIdMismatch", `Expected machine id ${machineId}, received ${checkpoint.machineId}`);
215
+ }
216
+ if (checkpoint.version !== options.version) {
217
+ return yield* fail("VersionMismatch", `Expected version ${options.version}, received ${checkpoint.version}`);
218
+ }
219
+ current = yield* Machine.decodeSnapshot(machine, checkpoint.snapshot).pipe(Effect.mapError((error) => reject("InvalidCheckpoint", String(error.cause))));
220
+ }
221
+ else if (loaded.processed) {
222
+ return yield* fail("InvalidCheckpoint", "The request was recorded without a checkpoint");
223
+ }
224
+ const runtime = {
225
+ raise: () => Effect.die(new Machine.ProcessLocalError({ operation: "runtime.raise" })),
226
+ sendParent: (event) => Effect.sync(() => {
227
+ emitted.push(event);
228
+ })
229
+ };
230
+ if (current === undefined) {
231
+ const initial = yield* Machine.planInitial(machine, ...input);
232
+ yield* Machine.runActions(initial.actions, runtime);
233
+ current = initial.state;
234
+ emitted.push(...initial.emittedEvents);
235
+ }
236
+ if (!Machine.isFinal(machine, current)) {
237
+ const planned = yield* Machine.plan(machine, current, request.payload);
238
+ yield* Machine.runActions(planned.actions, runtime);
239
+ current = planned.next;
240
+ emitted.push(...planned.emittedEvents);
241
+ }
242
+ const encoded = yield* Machine.encodeSnapshot(machine, current);
243
+ if (emitted.length > 0 && layerOptions?.enqueue === undefined) {
244
+ return yield* fail("EmissionFailure", "No durable enqueue handler was configured");
245
+ }
246
+ const committed = yield* storage.commit(request.address, {
247
+ machineId,
248
+ version: options.version,
249
+ requestId: request.requestId,
250
+ snapshot: encoded
251
+ }).pipe(Effect.mapError((error) => reject("PersistenceFailure", String(error.cause))));
252
+ if (committed._tag === "Duplicate") {
253
+ return new Accepted({});
254
+ }
255
+ if (layerOptions?.enqueue !== undefined) {
256
+ yield* Effect.forEach(emitted, layerOptions.enqueue, { discard: true }).pipe(Effect.mapError((error) => reject("EmissionFailure", String(error))));
257
+ }
258
+ return new Accepted({});
259
+ });
260
+ return entity.of({
261
+ send: (request) => messageStorage.withTransaction(handle(request).pipe(Effect.catchCause((cause) => Cause.hasInterrupts(cause)
262
+ ? Effect.failCause(cause)
263
+ : Effect.fail(rejectionFromCause(cause))))).pipe(Effect.catchCause((cause) => {
264
+ if (Cause.hasInterrupts(cause)) {
265
+ return Effect.failCause(cause);
266
+ }
267
+ const error = Cause.findErrorOption(cause);
268
+ return Effect.succeed(Option.isSome(error) && error.value instanceof Rejected
269
+ ? error.value
270
+ : reject("PersistenceFailure", messageFromCause(cause)));
271
+ }))
272
+ });
273
+ }));
274
+ return {
275
+ machine,
276
+ entity,
277
+ toLayer
278
+ };
279
+ };
280
+ //# sourceMappingURL=ClusterMachine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClusterMachine.js","sourceRoot":"","sources":["../src/ClusterMachine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,C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