effect-machine 0.17.1 → 0.18.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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -54
  3. package/dist/actor.d.ts +8 -45
  4. package/dist/actor.js +157 -231
  5. package/dist/cluster/adapters/in-memory.d.ts +0 -1
  6. package/dist/cluster/adapters/in-memory.js +10 -5
  7. package/dist/cluster/entity-actor-ref.d.ts +2 -3
  8. package/dist/cluster/entity-actor-ref.js +14 -17
  9. package/dist/cluster/entity-machine.d.ts +2 -8
  10. package/dist/cluster/entity-machine.js +57 -34
  11. package/dist/cluster/index.js +1 -1
  12. package/dist/cluster/persistence.d.ts +0 -1
  13. package/dist/cluster/to-entity.d.ts +19 -21
  14. package/dist/cluster/to-entity.js +18 -19
  15. package/dist/errors.d.ts +11 -37
  16. package/dist/errors.js +12 -30
  17. package/dist/index.d.ts +4 -5
  18. package/dist/index.js +4 -5
  19. package/dist/inspection.d.ts +0 -1
  20. package/dist/inspection.js +24 -13
  21. package/dist/internal/brands.d.ts +0 -1
  22. package/dist/internal/event-advancement.d.ts +50 -0
  23. package/dist/internal/event-advancement.js +79 -0
  24. package/dist/internal/inspection.d.ts +5 -9
  25. package/dist/internal/inspection.js +31 -10
  26. package/dist/internal/machine-definition.d.ts +16 -0
  27. package/dist/internal/runtime.d.ts +1 -161
  28. package/dist/internal/runtime.js +191 -150
  29. package/dist/internal/transition.d.ts +4 -135
  30. package/dist/internal/transition.js +82 -157
  31. package/dist/internal/utils.d.ts +3 -40
  32. package/dist/internal/utils.js +2 -2
  33. package/dist/machine.d.ts +47 -137
  34. package/dist/machine.js +147 -215
  35. package/dist/schema.d.ts +42 -21
  36. package/dist/schema.js +28 -18
  37. package/dist/supervision.d.ts +1 -24
  38. package/dist/supervision.js +2 -3
  39. package/dist/testing.d.ts +15 -29
  40. package/dist/testing.js +76 -95
  41. package/package.json +19 -38
  42. package/dist/slot.d.ts +0 -159
  43. package/dist/slot.js +0 -165
  44. package/v3/dist/_virtual/_rolldown/runtime.js +0 -13
  45. package/v3/dist/actor.d.ts +0 -250
  46. package/v3/dist/actor.js +0 -577
  47. package/v3/dist/cluster/adapters/in-memory.d.ts +0 -15
  48. package/v3/dist/cluster/adapters/in-memory.js +0 -62
  49. package/v3/dist/cluster/entity-actor-ref.d.ts +0 -49
  50. package/v3/dist/cluster/entity-actor-ref.js +0 -19
  51. package/v3/dist/cluster/entity-machine.d.ts +0 -74
  52. package/v3/dist/cluster/entity-machine.js +0 -166
  53. package/v3/dist/cluster/index.d.ts +0 -6
  54. package/v3/dist/cluster/index.js +0 -6
  55. package/v3/dist/cluster/persistence.d.ts +0 -48
  56. package/v3/dist/cluster/persistence.js +0 -14
  57. package/v3/dist/cluster/to-entity.d.ts +0 -69
  58. package/v3/dist/cluster/to-entity.js +0 -59
  59. package/v3/dist/errors.d.ts +0 -95
  60. package/v3/dist/errors.js +0 -54
  61. package/v3/dist/index.d.ts +0 -11
  62. package/v3/dist/index.js +0 -9
  63. package/v3/dist/inspection.d.ts +0 -151
  64. package/v3/dist/inspection.js +0 -128
  65. package/v3/dist/internal/brands.d.ts +0 -50
  66. package/v3/dist/internal/inspection.d.ts +0 -11
  67. package/v3/dist/internal/inspection.js +0 -20
  68. package/v3/dist/internal/runtime.d.ts +0 -161
  69. package/v3/dist/internal/runtime.js +0 -360
  70. package/v3/dist/internal/transition.d.ts +0 -190
  71. package/v3/dist/internal/transition.js +0 -278
  72. package/v3/dist/internal/utils.d.ts +0 -101
  73. package/v3/dist/internal/utils.js +0 -75
  74. package/v3/dist/machine.d.ts +0 -398
  75. package/v3/dist/machine.js +0 -487
  76. package/v3/dist/schema.d.ts +0 -174
  77. package/v3/dist/schema.js +0 -206
  78. package/v3/dist/slot.d.ts +0 -158
  79. package/v3/dist/slot.js +0 -165
  80. package/v3/dist/supervision.d.ts +0 -97
  81. package/v3/dist/supervision.js +0 -42
  82. package/v3/dist/testing.d.ts +0 -151
  83. package/v3/dist/testing.js +0 -189
  84. /package/{v3/dist/internal/brands.js → dist/internal/machine-definition.js} +0 -0
@@ -1,398 +0,0 @@
1
- import { DeferReplyResult, ReplyResult, TransitionResult } from "./internal/utils.js";
2
- import { BrandedEvent, BrandedState, ExtractReply, TaggedOrConstructor } from "./internal/brands.js";
3
- import { MachineEventSchema, MachineStateSchema, VariantsUnion } from "./schema.js";
4
- import { DuplicateActorError } from "./errors.js";
5
- import { MachineContext, ProvideSlots, SlotCalls, SlotsDef, SlotsSchema } from "./slot.js";
6
- import { Supervision } from "./supervision.js";
7
- import { findTransitions } from "./internal/transition.js";
8
- import { ActorRef, ActorSystem } from "./actor.js";
9
- import { Cause, Context, Duration, Effect, Option, Schema, Scope } from "effect";
10
-
11
- //#region src/machine.d.ts
12
- declare namespace machine_d_exports {
13
- export { BackgroundEffect, DeferReplyResult, Durability, DurabilityCommit, HandlerContext, Lifecycle, Machine, MachineRef, MakeConfig, Recovery, RecoveryContext, ReplyResult, SpawnEffect, StateEffectHandler, StateHandlerContext, TaskOptions, TimeoutConfig, Transition, TransitionHandler, deferReply, findTransitions, make, materializeMachine, replay, reply, scoped, spawn };
14
- }
15
- /**
16
- * Self reference for sending events back to the machine
17
- */
18
- interface MachineRef<Event> {
19
- readonly send: (event: Event) => Effect.Effect<void>;
20
- /** Fire-and-forget alias for send (OTP gen_server:cast). */
21
- readonly cast: (event: Event) => Effect.Effect<void>;
22
- readonly spawn: <S2 extends {
23
- readonly _tag: string;
24
- }, E2 extends {
25
- readonly _tag: string;
26
- }, R2>(id: string, machine: Machine<S2, E2, R2, any, any, any>) => Effect.Effect<ActorRef<S2, E2>, DuplicateActorError, R2>;
27
- /**
28
- * Settle a deferred reply from a spawn handler.
29
- * Only usable when the transition handler returned `Machine.deferReply(state)`.
30
- * Returns true if a pending reply was settled, false if none was pending.
31
- */
32
- readonly reply: (value: unknown) => Effect.Effect<boolean>;
33
- }
34
- /**
35
- * Handler context passed to transition handlers
36
- */
37
- interface HandlerContext<State, Event, SD extends SlotsDef = Record<string, never>> {
38
- readonly state: State;
39
- readonly event: Event;
40
- readonly slots: SlotCalls<SD>;
41
- }
42
- /**
43
- * Handler context passed to state effect handlers (onEnter, spawn, background)
44
- */
45
- interface StateHandlerContext<State, Event, SD extends SlotsDef = Record<string, never>> {
46
- readonly actorId: string;
47
- readonly state: State;
48
- readonly event: Event;
49
- readonly self: MachineRef<Event>;
50
- readonly slots: SlotCalls<SD>;
51
- readonly system: ActorSystem;
52
- }
53
- /**
54
- * Transition handler function.
55
- * When Reply is concrete (event has a reply schema), handler must return Machine.reply().
56
- * When Reply is never, handler returns plain state.
57
- */
58
- type TransitionHandler<S, E, NewState, SD extends SlotsDef, R, Reply = never> = (ctx: HandlerContext<S, E, SD>) => TransitionResult<NewState, R, Reply>;
59
- /**
60
- * State effect handler function
61
- */
62
- type StateEffectHandler<S, E, SD extends SlotsDef, R> = (ctx: StateHandlerContext<S, E, SD>) => Effect.Effect<void, never, R>;
63
- /**
64
- * Transition definition
65
- */
66
- interface Transition<State, Event, SD extends SlotsDef, R> {
67
- readonly stateTag: string;
68
- readonly eventTag: string;
69
- readonly handler: TransitionHandler<State, Event, State, SD, R>;
70
- readonly reenter?: boolean;
71
- }
72
- /**
73
- * Spawn effect - state-scoped forked effect
74
- */
75
- interface SpawnEffect<State, Event, SD extends SlotsDef, R> {
76
- readonly stateTag: string;
77
- readonly handler: StateEffectHandler<State, Event, SD, R>;
78
- }
79
- /**
80
- * Background effect - runs for entire machine lifetime
81
- */
82
- interface BackgroundEffect<State, Event, SD extends SlotsDef, R> {
83
- readonly handler: StateEffectHandler<State, Event, SD, R>;
84
- }
85
- interface TaskOptions<State, Event, SD extends SlotsDef, A, E1, ES, EF> {
86
- readonly onSuccess?: (value: A, ctx: StateHandlerContext<State, Event, SD>) => ES;
87
- readonly onFailure?: (cause: Cause.Cause<E1>, ctx: StateHandlerContext<State, Event, SD>) => EF;
88
- readonly name?: string;
89
- }
90
- /**
91
- * Recovery resolves the initial state for a generation. Runs during actor.start.
92
- *
93
- * For initial start (generation 0): loads persisted state.
94
- * For supervision restart (generation 1+): reloads state after crash.
95
- */
96
- interface Recovery<S> {
97
- readonly resolve: (ctx: RecoveryContext<S>) => Effect.Effect<Option.Option<S>>;
98
- }
99
- interface RecoveryContext<S> {
100
- readonly actorId: string;
101
- readonly generation: number;
102
- readonly machineInitial: S;
103
- }
104
- /**
105
- * Durability saves state after committed transitions. Runs during runtime.
106
- */
107
- interface Durability<S, E> {
108
- readonly save: (commit: DurabilityCommit<S, E>) => Effect.Effect<void>;
109
- readonly shouldSave?: (state: S, previousState: S) => boolean;
110
- }
111
- interface DurabilityCommit<S, E> {
112
- readonly actorId: string;
113
- readonly generation: number;
114
- readonly previousState: S;
115
- readonly nextState: S;
116
- readonly event: E;
117
- }
118
- /**
119
- * Actor lifecycle configuration.
120
- */
121
- interface Lifecycle<S, E> {
122
- readonly recovery?: Recovery<S>;
123
- readonly durability?: Durability<S, E>;
124
- }
125
- /**
126
- * Configuration for `.timeout()` — gen_statem-style state timeouts.
127
- *
128
- * Entering the state starts a timer. Leaving cancels it.
129
- * `.reenter()` restarts the timer with fresh state values.
130
- */
131
- interface TimeoutConfig<State, Event> {
132
- /** Duration before firing. Static or derived from current state. */
133
- readonly duration: Duration.DurationInput | ((state: State) => Duration.DurationInput);
134
- /** Event to send when the timer fires. Static or derived from current state. */
135
- readonly event: Event | ((state: State) => Event);
136
- }
137
- interface MakeConfig<SD extends Record<string, Schema.Struct.Fields>, ED extends Record<string, Schema.Struct.Fields>, S extends BrandedState, E extends BrandedEvent, SLD extends SlotsDef = Record<string, never>> {
138
- readonly state: MachineStateSchema<SD> & {
139
- Type: S;
140
- };
141
- readonly event: MachineEventSchema<ED> & {
142
- Type: E;
143
- };
144
- readonly slots?: SlotsSchema<SLD>;
145
- readonly initial: S;
146
- /** Validate slot inputs/outputs at runtime. Default: true. Set to false for hot paths. */
147
- readonly slotValidation?: boolean;
148
- }
149
- /**
150
- * Bind slot handlers to a machine, returning a fresh copy with handlers installed.
151
- * If no handlers provided and machine has no slots, returns the machine as-is.
152
- * Validates that all required slots are provided and no extra slots are given.
153
- *
154
- * @internal — used by spawn, replay, simulate, test harness, entity-machine
155
- */
156
- declare const materializeMachine: <S, E, R, SD extends SlotsDef>(machine: Machine<S, E, R, any, any, SD>, handlers?: Record<string, any>) => Machine<S, E, never, any, any, SD>;
157
- /**
158
- * Machine definition with fluent builder API.
159
- *
160
- * Type parameters:
161
- * - `State`: The state union type
162
- * - `Event`: The event union type
163
- * - `R`: Effect requirements
164
- * - `_SD`: State schema definition (for compile-time validation)
165
- * - `_ED`: Event schema definition (for compile-time validation)
166
- * - `SD`: Slot definitions
167
- */
168
- declare class Machine<State, Event, R = never, _SD extends Record<string, Schema.Struct.Fields> = Record<string, Schema.Struct.Fields>, _ED extends Record<string, Schema.Struct.Fields> = Record<string, Schema.Struct.Fields>, SD extends SlotsDef = Record<string, never>> {
169
- readonly initial: State;
170
- /** @internal */
171
- readonly _transitions: Array<Transition<State, Event, SD, R>>;
172
- /** @internal */
173
- readonly _spawnEffects: Array<SpawnEffect<State, Event, SD, R>>;
174
- /** @internal */
175
- readonly _backgroundEffects: Array<BackgroundEffect<State, Event, SD, R>>;
176
- /** @internal */
177
- readonly _finalStates: Set<string>;
178
- /** @internal */
179
- readonly _postponeRules: Array<{
180
- readonly stateTag: string;
181
- readonly eventTag: string;
182
- }>;
183
- /** @internal */
184
- readonly _slotsSchema?: SlotsSchema<SD>;
185
- /** @internal */
186
- readonly _slotHandlers: Map<string, (params: unknown) => unknown | Effect.Effect<unknown, never, R>>;
187
- /** @internal */
188
- readonly _slots: SlotCalls<SD>;
189
- /** @internal */
190
- readonly _slotValidation: boolean;
191
- readonly stateSchema?: Schema.Schema<State>;
192
- readonly eventSchema?: Schema.Schema<Event>;
193
- /** @internal */
194
- readonly _replySchemas: ReadonlyMap<string, Schema.Schema.Any>;
195
- /**
196
- * Context tag for accessing machine state/event/self in slot handlers.
197
- * Uses shared module-level tag for all machines.
198
- */
199
- readonly Context: Context.Tag<MachineContext<State, Event, MachineRef<Event>>, MachineContext<State, Event, MachineRef<Event>>>;
200
- get transitions(): ReadonlyArray<Transition<State, Event, SD, R>>;
201
- get spawnEffects(): ReadonlyArray<SpawnEffect<State, Event, SD, R>>;
202
- get backgroundEffects(): ReadonlyArray<BackgroundEffect<State, Event, SD, R>>;
203
- get finalStates(): ReadonlySet<string>;
204
- get postponeRules(): ReadonlyArray<{
205
- readonly stateTag: string;
206
- readonly eventTag: string;
207
- }>;
208
- get slotsSchema(): SlotsSchema<SD> | undefined;
209
- get replySchemas(): ReadonlyMap<string, Schema.Schema.Any>;
210
- /** @internal */
211
- constructor(initial: State, stateSchema?: Schema.Schema<State>, eventSchema?: Schema.Schema<Event>, slotsSchema?: SlotsSchema<SD>, slotValidation?: boolean);
212
- from<NS extends VariantsUnion<_SD> & BrandedState, R1>(state: TaggedOrConstructor<NS>, build: (scope: TransitionScope<State, Event, R, _SD, _ED, SD, NS>) => R1): Machine<State, Event, R, _SD, _ED, SD>;
213
- from<NS extends ReadonlyArray<TaggedOrConstructor<VariantsUnion<_SD> & BrandedState>>, R1>(states: NS, build: (scope: TransitionScope<State, Event, R, _SD, _ED, SD, NS[number] extends TaggedOrConstructor<infer S extends VariantsUnion<_SD> & BrandedState> ? S : never>) => R1): Machine<State, Event, R, _SD, _ED, SD>;
214
- /** @internal */
215
- scopeTransition<NS extends VariantsUnion<_SD> & BrandedState, NE extends VariantsUnion<_ED> & BrandedEvent, RS extends VariantsUnion<_SD> & BrandedState>(states: ReadonlyArray<TaggedOrConstructor<NS>>, event: TaggedOrConstructor<NE>, handler: TransitionHandler<NS, NE, RS, SD, never, ExtractReply<NE>>, reenter: boolean): Machine<State, Event, R, _SD, _ED, SD>;
216
- /** Register transition for a single state */
217
- on<NS extends VariantsUnion<_SD> & BrandedState, NE extends VariantsUnion<_ED> & BrandedEvent, RS extends VariantsUnion<_SD> & BrandedState>(state: TaggedOrConstructor<NS>, event: TaggedOrConstructor<NE>, handler: TransitionHandler<NS, NE, RS, SD, never, ExtractReply<NE>>): Machine<State, Event, R, _SD, _ED, SD>;
218
- /** Register transition for multiple states (handler receives union of state types) */
219
- on<NS extends ReadonlyArray<TaggedOrConstructor<VariantsUnion<_SD> & BrandedState>>, NE extends VariantsUnion<_ED> & BrandedEvent, RS extends VariantsUnion<_SD> & BrandedState>(states: NS, event: TaggedOrConstructor<NE>, handler: TransitionHandler<NS[number] extends TaggedOrConstructor<infer S> ? S : never, NE, RS, SD, never, ExtractReply<NE>>): Machine<State, Event, R, _SD, _ED, SD>;
220
- /**
221
- * Like `on()`, but forces onEnter/spawn to run even when transitioning to the same state tag.
222
- * Use this to restart timers, re-run spawned effects, or reset state-scoped effects.
223
- */
224
- /** Single state */
225
- reenter<NS extends VariantsUnion<_SD> & BrandedState, NE extends VariantsUnion<_ED> & BrandedEvent, RS extends VariantsUnion<_SD> & BrandedState>(state: TaggedOrConstructor<NS>, event: TaggedOrConstructor<NE>, handler: TransitionHandler<NS, NE, RS, SD, never, ExtractReply<NE>>): Machine<State, Event, R, _SD, _ED, SD>;
226
- /** Multiple states */
227
- reenter<NS extends ReadonlyArray<TaggedOrConstructor<VariantsUnion<_SD> & BrandedState>>, NE extends VariantsUnion<_ED> & BrandedEvent, RS extends VariantsUnion<_SD> & BrandedState>(states: NS, event: TaggedOrConstructor<NE>, handler: TransitionHandler<NS[number] extends TaggedOrConstructor<infer S> ? S : never, NE, RS, SD, never, ExtractReply<NE>>): Machine<State, Event, R, _SD, _ED, SD>;
228
- /**
229
- * Register a wildcard transition that fires from any state when no specific transition matches.
230
- * Specific `.on()` transitions always take priority over `.onAny()`.
231
- */
232
- onAny<NE extends VariantsUnion<_ED> & BrandedEvent, RS extends VariantsUnion<_SD> & BrandedState>(event: TaggedOrConstructor<NE>, handler: TransitionHandler<VariantsUnion<_SD> & BrandedState, NE, RS, SD, never>): Machine<State, Event, R, _SD, _ED, SD>;
233
- /** @internal */
234
- private addTransition;
235
- /**
236
- * State-scoped effect that is forked on state entry and automatically cancelled on state exit.
237
- *
238
- * @example
239
- * ```ts
240
- * machine.spawn(State.Loading, ({ self, state }) =>
241
- * Effect.gen(function* () {
242
- * yield* Effect.addFinalizer(() => Effect.log("Leaving Loading"));
243
- * const data = yield* Http.get(state.url);
244
- * yield* self.send(Event.Loaded({ data }));
245
- * }),
246
- * );
247
- * ```
248
- */
249
- /** Single state */
250
- spawn<NS extends VariantsUnion<_SD> & BrandedState>(state: TaggedOrConstructor<NS>, handler: StateEffectHandler<NS, VariantsUnion<_ED> & BrandedEvent, SD, Scope.Scope>): Machine<State, Event, R, _SD, _ED, SD>;
251
- /** Multiple states */
252
- spawn<NS extends ReadonlyArray<TaggedOrConstructor<VariantsUnion<_SD> & BrandedState>>>(states: NS, handler: StateEffectHandler<NS[number] extends TaggedOrConstructor<infer S> ? S : never, VariantsUnion<_ED> & BrandedEvent, SD, Scope.Scope>): Machine<State, Event, R, _SD, _ED, SD>;
253
- /**
254
- * State-scoped task that runs on entry and sends success/failure events.
255
- * Interrupts do not emit failure events.
256
- *
257
- * Supports multi-state and shorthand overloads:
258
- * - `.task(State.X, run, { onSuccess, onFailure })` — explicit mapping
259
- * - `.task(State.X, run, { onFailure })` — shorthand when run returns Event directly
260
- * - `.task([State.X, State.Y], run, opts)` — multi-state
261
- */
262
- /** Single state — onSuccess optional (defaults to identity when task returns Event) */
263
- task<NS extends VariantsUnion<_SD> & BrandedState, A, E1, ES extends VariantsUnion<_ED> & BrandedEvent, EF extends VariantsUnion<_ED> & BrandedEvent>(state: TaggedOrConstructor<NS>, run: (ctx: StateHandlerContext<NS, VariantsUnion<_ED> & BrandedEvent, SD>) => Effect.Effect<A, E1, Scope.Scope>, options: TaskOptions<NS, VariantsUnion<_ED> & BrandedEvent, SD, A, E1, ES, EF>): Machine<State, Event, R, _SD, _ED, SD>;
264
- /** Multiple states — onSuccess optional */
265
- task<NS extends ReadonlyArray<TaggedOrConstructor<VariantsUnion<_SD> & BrandedState>>, A, E1, ES extends VariantsUnion<_ED> & BrandedEvent, EF extends VariantsUnion<_ED> & BrandedEvent>(states: NS, run: (ctx: StateHandlerContext<NS[number] extends TaggedOrConstructor<infer S> ? S : never, VariantsUnion<_ED> & BrandedEvent, SD>) => Effect.Effect<A, E1, Scope.Scope>, options: TaskOptions<NS[number] extends TaggedOrConstructor<infer S> ? S : never, VariantsUnion<_ED> & BrandedEvent, SD, A, E1, ES, EF>): Machine<State, Event, R, _SD, _ED, SD>;
266
- /**
267
- * State timeout — gen_statem's `state_timeout`.
268
- *
269
- * Entering the state starts a timer. Leaving cancels it (via state scope).
270
- * `.reenter()` restarts the timer with fresh state values.
271
- * Compiles to `.task()` internally — preserves `@machine.task` inspection events.
272
- *
273
- * @example
274
- * ```ts
275
- * machine
276
- * .timeout(State.Loading, {
277
- * duration: Duration.seconds(30),
278
- * event: Event.Timeout,
279
- * })
280
- * // Dynamic duration from state
281
- * .timeout(State.Retrying, {
282
- * duration: (state) => Duration.seconds(state.backoff),
283
- * event: Event.GiveUp,
284
- * })
285
- * ```
286
- */
287
- timeout<NS extends VariantsUnion<_SD> & BrandedState>(state: TaggedOrConstructor<NS>, config: TimeoutConfig<NS, VariantsUnion<_ED> & BrandedEvent>): Machine<State, Event, R, _SD, _ED, SD>;
288
- /**
289
- * Machine-lifetime effect that is forked on actor spawn and runs until the actor stops.
290
- *
291
- * @example
292
- * ```ts
293
- * machine.background(({ self }) =>
294
- * Effect.forever(
295
- * Effect.sleep("30 seconds").pipe(Effect.andThen(self.send(Event.Ping))),
296
- * ),
297
- * );
298
- * ```
299
- */
300
- background(handler: StateEffectHandler<State, Event, SD, Scope.Scope>): Machine<State, Event, R, _SD, _ED, SD>;
301
- /**
302
- * Postpone events — gen_statem's event postpone.
303
- *
304
- * When a matching event arrives in the given state, it is buffered instead of
305
- * processed. After the next state transition (tag change), all buffered events
306
- * are drained through the loop in FIFO order.
307
- *
308
- * Reply-bearing events (from `call`/`ask`) in the postpone buffer are settled
309
- * with `ActorStoppedError` on stop/interrupt/final-state.
310
- *
311
- * @example
312
- * ```ts
313
- * machine
314
- * .postpone(State.Connecting, Event.Data) // single event
315
- * .postpone(State.Connecting, [Event.Data, Event.Cmd]) // multiple events
316
- * ```
317
- */
318
- postpone<NS extends VariantsUnion<_SD> & BrandedState>(state: TaggedOrConstructor<NS>, events: TaggedOrConstructor<VariantsUnion<_ED> & BrandedEvent> | ReadonlyArray<TaggedOrConstructor<VariantsUnion<_ED> & BrandedEvent>>): Machine<State, Event, R, _SD, _ED, SD>;
319
- final<NS extends VariantsUnion<_SD> & BrandedState>(state: TaggedOrConstructor<NS>): Machine<State, Event, R, _SD, _ED, SD>;
320
- static make<SD extends Record<string, Schema.Struct.Fields>, ED extends Record<string, Schema.Struct.Fields>, S extends BrandedState, E extends BrandedEvent, SLD extends SlotsDef = Record<string, never>>(config: MakeConfig<SD, ED, S, E, SLD>): Machine<S, E, never, SD, ED, SLD>;
321
- }
322
- declare class TransitionScope<State, Event, R, _SD extends Record<string, Schema.Struct.Fields>, _ED extends Record<string, Schema.Struct.Fields>, SD extends SlotsDef, SelectedState extends VariantsUnion<_SD> & BrandedState> {
323
- private readonly machine;
324
- private readonly states;
325
- constructor(machine: Machine<State, Event, R, _SD, _ED, SD>, states: ReadonlyArray<TaggedOrConstructor<SelectedState>>);
326
- on<NE extends VariantsUnion<_ED> & BrandedEvent, RS extends VariantsUnion<_SD> & BrandedState>(event: TaggedOrConstructor<NE>, handler: TransitionHandler<SelectedState, NE, RS, SD, never, ExtractReply<NE>>): TransitionScope<State, Event, R, _SD, _ED, SD, SelectedState>;
327
- reenter<NE extends VariantsUnion<_ED> & BrandedEvent, RS extends VariantsUnion<_SD> & BrandedState>(event: TaggedOrConstructor<NE>, handler: TransitionHandler<SelectedState, NE, RS, SD, never, ExtractReply<NE>>): TransitionScope<State, Event, R, _SD, _ED, SD, SelectedState>;
328
- }
329
- declare const make: typeof Machine.make;
330
- /**
331
- * Spawn an actor from a machine.
332
- *
333
- * For machines with slots, pass implementations via `{ slots: { ... } }`.
334
- *
335
- * @example
336
- * ```ts
337
- * // No slots
338
- * const actor = yield* Machine.spawn(machine);
339
- *
340
- * // With slots
341
- * const actor = yield* Machine.spawn(machine, {
342
- * slots: { canRetry: ({ max }) => attempts < max },
343
- * });
344
- *
345
- * // With lifecycle (recovery + durability)
346
- * const actor = yield* Machine.spawn(machine, {
347
- * lifecycle: {
348
- * recovery: { resolve: ({ machineInitial }) => storage.get("actor-state") },
349
- * durability: { save: ({ nextState }) => storage.set("actor-state", nextState) },
350
- * },
351
- * });
352
- * ```
353
- */
354
- declare const spawn: <S extends {
355
- readonly _tag: string;
356
- }, E extends {
357
- readonly _tag: string;
358
- }, R, SD extends SlotsDef = Record<string, never>>(machine: Machine<S, E, R, any, any, SD>, options?: string | {
359
- id?: string;
360
- hydrate?: S;
361
- slots?: ProvideSlots<SD, any>;
362
- supervision?: Supervision.Policy;
363
- lifecycle?: Lifecycle<S, E>;
364
- }) => Effect.Effect<ActorRef<S, E>, never, R>;
365
- /**
366
- * Wrap an effect to provide an `ActorScope` from the current `Scope`.
367
- *
368
- * Actors spawned inside will attach cleanup finalizers to this scope,
369
- * so they are automatically stopped when the scope closes.
370
- *
371
- * @example
372
- * ```ts
373
- * yield* Effect.scoped(
374
- * Machine.scoped(
375
- * Effect.gen(function* () {
376
- * const actor = yield* Machine.spawn(machine);
377
- * yield* actor.start;
378
- * // actor auto-stopped when scope closes
379
- * }),
380
- * ),
381
- * );
382
- * ```
383
- */
384
- declare const scoped: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R | Scope.Scope>;
385
- declare const replay: {
386
- <S extends {
387
- readonly _tag: string;
388
- }, E extends {
389
- readonly _tag: string;
390
- }, R, SD extends SlotsDef = Record<string, never>>(machine: Machine<S, E, R, any, any, SD>, events: ReadonlyArray<E>, options?: {
391
- from?: S;
392
- slots?: ProvideSlots<SD, any>;
393
- }): Effect.Effect<S, never, R>;
394
- };
395
- declare const reply: <State, Reply>(state: State, reply: Reply) => ReplyResult<State, Reply>;
396
- declare const deferReply: <State>(state: State) => DeferReplyResult<State>;
397
- //#endregion
398
- export { BackgroundEffect, type DeferReplyResult, Durability, DurabilityCommit, HandlerContext, Lifecycle, Machine, MachineRef, MakeConfig, Recovery, RecoveryContext, type ReplyResult, SpawnEffect, StateEffectHandler, StateHandlerContext, TaskOptions, TimeoutConfig, Transition, TransitionHandler, deferReply, findTransitions, machine_d_exports, make, materializeMachine, replay, reply, scoped, spawn };