effect-machine 0.10.0 → 0.11.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 (38) hide show
  1. package/README.md +65 -62
  2. package/dist/actor.d.ts +26 -94
  3. package/dist/actor.js +38 -95
  4. package/dist/index.d.ts +3 -7
  5. package/dist/index.js +1 -6
  6. package/dist/internal/transition.d.ts +1 -1
  7. package/dist/internal/transition.js +1 -1
  8. package/dist/internal/utils.js +1 -5
  9. package/dist/machine.d.ts +31 -35
  10. package/dist/machine.js +63 -13
  11. package/package.json +2 -2
  12. package/v3/dist/actor.d.ts +25 -93
  13. package/v3/dist/actor.js +37 -94
  14. package/v3/dist/index.d.ts +3 -7
  15. package/v3/dist/index.js +1 -6
  16. package/v3/dist/internal/utils.js +1 -5
  17. package/v3/dist/machine.d.ts +31 -35
  18. package/v3/dist/machine.js +63 -13
  19. package/dist/persistence/adapter.d.ts +0 -135
  20. package/dist/persistence/adapter.js +0 -25
  21. package/dist/persistence/adapters/in-memory.d.ts +0 -32
  22. package/dist/persistence/adapters/in-memory.js +0 -174
  23. package/dist/persistence/index.d.ts +0 -5
  24. package/dist/persistence/index.js +0 -5
  25. package/dist/persistence/persistent-actor.d.ts +0 -50
  26. package/dist/persistence/persistent-actor.js +0 -404
  27. package/dist/persistence/persistent-machine.d.ts +0 -105
  28. package/dist/persistence/persistent-machine.js +0 -22
  29. package/v3/dist/persistence/adapter.d.ts +0 -138
  30. package/v3/dist/persistence/adapter.js +0 -25
  31. package/v3/dist/persistence/adapters/in-memory.d.ts +0 -32
  32. package/v3/dist/persistence/adapters/in-memory.js +0 -174
  33. package/v3/dist/persistence/index.d.ts +0 -5
  34. package/v3/dist/persistence/index.js +0 -5
  35. package/v3/dist/persistence/persistent-actor.d.ts +0 -50
  36. package/v3/dist/persistence/persistent-actor.js +0 -404
  37. package/v3/dist/persistence/persistent-machine.d.ts +0 -105
  38. package/v3/dist/persistence/persistent-machine.js +0 -22
package/dist/index.js CHANGED
@@ -1,13 +1,8 @@
1
1
  import { Inspector, collectingInspector, combineInspectors, consoleInspector, makeInspector, makeInspectorEffect, tracingInspector } from "./inspection.js";
2
2
  import { ActorStoppedError, AssertionError, DuplicateActorError, InvalidSchemaError, MissingMatchHandlerError, MissingSchemaError, NoReplyError, ProvisionValidationError, SlotProvisionError, UnprovidedSlotsError } from "./errors.js";
3
- import { isPersistentMachine } from "./persistence/persistent-machine.js";
4
3
  import { Slot } from "./slot.js";
5
4
  import { machine_exports } from "./machine.js";
6
- import { PersistenceAdapterTag, PersistenceError, VersionConflictError } from "./persistence/adapter.js";
7
- import { createPersistentActor, restorePersistentActor } from "./persistence/persistent-actor.js";
8
5
  import { ActorSystem, Default } from "./actor.js";
9
6
  import { Event, State } from "./schema.js";
10
7
  import { assertNeverReaches, assertPath, assertReaches, createTestHarness, simulate } from "./testing.js";
11
- import { InMemoryPersistenceAdapter, makeInMemoryPersistenceAdapter } from "./persistence/adapters/in-memory.js";
12
- import "./persistence/index.js";
13
- export { ActorStoppedError, Default as ActorSystemDefault, ActorSystem as ActorSystemService, AssertionError, DuplicateActorError, Event, InMemoryPersistenceAdapter, Inspector as InspectorService, InvalidSchemaError, machine_exports as Machine, MissingMatchHandlerError, MissingSchemaError, NoReplyError, PersistenceAdapterTag, PersistenceError, ProvisionValidationError, Slot, SlotProvisionError, State, UnprovidedSlotsError, VersionConflictError, assertNeverReaches, assertPath, assertReaches, collectingInspector, combineInspectors, consoleInspector, createPersistentActor, createTestHarness, isPersistentMachine, makeInMemoryPersistenceAdapter, makeInspector, makeInspectorEffect, restorePersistentActor, simulate, tracingInspector };
8
+ export { ActorStoppedError, Default as ActorSystemDefault, ActorSystem as ActorSystemService, AssertionError, DuplicateActorError, Event, Inspector as InspectorService, InvalidSchemaError, machine_exports as Machine, MissingMatchHandlerError, MissingSchemaError, NoReplyError, ProvisionValidationError, Slot, SlotProvisionError, State, UnprovidedSlotsError, assertNeverReaches, assertPath, assertReaches, collectingInspector, combineInspectors, consoleInspector, createTestHarness, makeInspector, makeInspectorEffect, simulate, tracingInspector };
@@ -21,7 +21,7 @@ interface TransitionExecutionResult<S> {
21
21
  *
22
22
  * Used by:
23
23
  * - executeTransition (actor event loop, testing)
24
- * - persistent-actor replay (restore, replayTo)
24
+ * - Machine.replay (event sourcing restore)
25
25
  *
26
26
  * @internal
27
27
  */
@@ -18,7 +18,7 @@ import { Cause, Effect, Exit, Scope } from "effect";
18
18
  *
19
19
  * Used by:
20
20
  * - executeTransition (actor event loop, testing)
21
- * - persistent-actor replay (restore, replayTo)
21
+ * - Machine.replay (event sourcing restore)
22
22
  *
23
23
  * @internal
24
24
  */
@@ -37,17 +37,13 @@ const isEffect = Effect.isEffect;
37
37
  */
38
38
  const stubSystem = {
39
39
  spawn: () => Effect.die("spawn not supported in stub system"),
40
- restore: () => Effect.die("restore not supported in stub system"),
41
40
  get: () => Effect.die("get not supported in stub system"),
42
41
  stop: () => Effect.die("stop not supported in stub system"),
43
42
  events: Stream.empty,
44
43
  get actors() {
45
44
  return /* @__PURE__ */ new Map();
46
45
  },
47
- subscribe: () => () => {},
48
- listPersisted: () => Effect.die("listPersisted not supported in stub system"),
49
- restoreMany: () => Effect.die("restoreMany not supported in stub system"),
50
- restoreAll: () => Effect.die("restoreAll not supported in stub system")
46
+ subscribe: () => () => {}
51
47
  };
52
48
  //#endregion
53
49
  export { INTERNAL_ENTER_EVENT, INTERNAL_INIT_EVENT, getTag, isEffect, stubSystem };
package/dist/machine.d.ts CHANGED
@@ -2,15 +2,14 @@ import { EffectHandlers, EffectSlots, EffectsDef, EffectsSchema, GuardHandlers,
2
2
  import { TransitionResult } from "./internal/utils.js";
3
3
  import { BrandedEvent, BrandedState, TaggedOrConstructor } from "./internal/brands.js";
4
4
  import { MachineEventSchema, MachineStateSchema, VariantsUnion } from "./schema.js";
5
- import { PersistenceConfig, PersistentMachine } from "./persistence/persistent-machine.js";
6
5
  import { DuplicateActorError } from "./errors.js";
7
6
  import { findTransitions } from "./internal/transition.js";
8
7
  import { ActorRef, ActorSystem } from "./actor.js";
9
- import { Cause, Duration, Effect, Schedule, Schema, Scope, ServiceMap } from "effect";
8
+ import { Cause, Duration, Effect, Schema, Scope, ServiceMap } from "effect";
10
9
 
11
10
  //#region src/machine.d.ts
12
11
  declare namespace machine_d_exports {
13
- export { BackgroundEffect, BuiltMachine, HandlerContext, Machine, MachineRef, MakeConfig, PersistOptions, PersistenceConfig, PersistentMachine, ProvideHandlers, SlotContext, SpawnEffect, StateEffectHandler, StateHandlerContext, TaskOptions, TimeoutConfig, Transition, TransitionHandler, findTransitions, make, spawn };
12
+ export { BackgroundEffect, BuiltMachine, HandlerContext, Machine, MachineRef, MakeConfig, ProvideHandlers, SlotContext, SpawnEffect, StateEffectHandler, StateHandlerContext, TaskOptions, TimeoutConfig, Transition, TransitionHandler, findTransitions, make, replay, spawn };
14
13
  }
15
14
  /**
16
15
  * Self reference for sending events back to the machine
@@ -75,14 +74,6 @@ interface SpawnEffect<State, Event, ED extends EffectsDef, R> {
75
74
  interface BackgroundEffect<State, Event, ED extends EffectsDef, R> {
76
75
  readonly handler: StateEffectHandler<State, Event, ED, R>;
77
76
  }
78
- /** Options for `persist` */
79
- interface PersistOptions {
80
- readonly snapshotSchedule: Schedule.Schedule<unknown, {
81
- readonly _tag: string;
82
- }>;
83
- readonly journalEvents: boolean;
84
- readonly machineType?: string;
85
- }
86
77
  interface TaskOptions<State, Event, ED extends EffectsDef, A, E1, ES, EF> {
87
78
  readonly onSuccess: (value: A, ctx: StateHandlerContext<State, Event, ED>) => ES;
88
79
  readonly onFailure?: (cause: Cause.Cause<E1>, ctx: StateHandlerContext<State, Event, ED>) => EF;
@@ -137,11 +128,6 @@ declare class BuiltMachine<State, Event, R = never> {
137
128
  /** @internal */
138
129
  constructor(machine: Machine<State, Event, R, any, any, any, any>);
139
130
  get initial(): State;
140
- persist(config: PersistOptions): PersistentMachine<State & {
141
- readonly _tag: string;
142
- }, Event & {
143
- readonly _tag: string;
144
- }, R>;
145
131
  }
146
132
  /**
147
133
  * Machine definition with fluent builder API.
@@ -322,12 +308,6 @@ declare class Machine<State, Event, R = never, _SD extends Record<string, Schema
322
308
  * - Machines without slots: call with no arguments.
323
309
  */
324
310
  build<R2 = never>(...args: HasSlots<GD, EFD> extends true ? [handlers: ProvideHandlers<State, Event, GD, EFD, R2>] : [handlers?: ProvideHandlers<State, Event, GD, EFD, R2>]): BuiltMachine<State, Event, R | NormalizeR<R2>>;
325
- /** @internal Persist from raw Machine — prefer BuiltMachine.persist() */
326
- persist(config: PersistOptions): PersistentMachine<State & {
327
- readonly _tag: string;
328
- }, Event & {
329
- readonly _tag: string;
330
- }, R>;
331
311
  static make<SD extends Record<string, Schema.Struct.Fields>, ED extends Record<string, Schema.Struct.Fields>, S extends BrandedState, E extends BrandedEvent, GD extends GuardsDef = Record<string, never>, EFD extends EffectsDef = Record<string, never>>(config: MakeConfig<SD, ED, S, E, GD, EFD>): Machine<S, E, never, SD, ED, GD, EFD>;
332
312
  }
333
313
  declare class TransitionScope<State, Event, R, _SD extends Record<string, Schema.Struct.Fields>, _ED extends Record<string, Schema.Struct.Fields>, GD extends GuardsDef, EFD extends EffectsDef, SelectedState extends VariantsUnion<_SD> & BrandedState> {
@@ -338,17 +318,33 @@ declare class TransitionScope<State, Event, R, _SD extends Record<string, Schema
338
318
  reenter<NE extends VariantsUnion<_ED> & BrandedEvent, RS extends VariantsUnion<_SD> & BrandedState>(event: TaggedOrConstructor<NE>, handler: TransitionHandler<SelectedState, NE, RS, GD, EFD, never>): TransitionScope<State, Event, R, _SD, _ED, GD, EFD, SelectedState>;
339
319
  }
340
320
  declare const make: typeof Machine.make;
341
- declare const spawn: {
342
- <S extends {
343
- readonly _tag: string;
344
- }, E extends {
345
- readonly _tag: string;
346
- }, R>(machine: BuiltMachine<S, E, R>): Effect.Effect<ActorRef<S, E>, never, R>;
347
- <S extends {
348
- readonly _tag: string;
349
- }, E extends {
350
- readonly _tag: string;
351
- }, R>(machine: BuiltMachine<S, E, R>, id: string): Effect.Effect<ActorRef<S, E>, never, R>;
352
- };
321
+ /**
322
+ * Spawn an actor from a built machine.
323
+ *
324
+ * Options:
325
+ * - `id` — custom actor ID (default: random)
326
+ * - `hydrate` restore from a previously-saved state snapshot.
327
+ * The actor starts in the hydrated state and re-runs spawn effects
328
+ * for that state (timers, scoped resources, etc.). Transition history
329
+ * is not replayed — only the current state's entry effects run.
330
+ *
331
+ * Persistence is composed in userland by observing `actor.changes`
332
+ * and saving snapshots to your own storage.
333
+ */
334
+ declare const spawn: <S extends {
335
+ readonly _tag: string;
336
+ }, E extends {
337
+ readonly _tag: string;
338
+ }, R>(machine: BuiltMachine<S, E, R>, idOrOptions?: string | {
339
+ id?: string;
340
+ hydrate?: S;
341
+ }) => Effect.Effect<ActorRef<S, E>, never, R>;
342
+ declare const replay: <S extends {
343
+ readonly _tag: string;
344
+ }, E extends {
345
+ readonly _tag: string;
346
+ }, R>(machine: BuiltMachine<S, E, R>, events: ReadonlyArray<E>, options?: {
347
+ from?: S;
348
+ }) => Effect.Effect<S, never, R>;
353
349
  //#endregion
354
- export { BackgroundEffect, BuiltMachine, HandlerContext, Machine, MachineRef, MakeConfig, PersistOptions, type PersistenceConfig, type PersistentMachine, ProvideHandlers, SlotContext, SpawnEffect, StateEffectHandler, StateHandlerContext, TaskOptions, TimeoutConfig, Transition, TransitionHandler, findTransitions, machine_d_exports, make, spawn };
350
+ export { BackgroundEffect, BuiltMachine, HandlerContext, Machine, MachineRef, MakeConfig, ProvideHandlers, SlotContext, SpawnEffect, StateEffectHandler, StateHandlerContext, TaskOptions, TimeoutConfig, Transition, TransitionHandler, findTransitions, machine_d_exports, make, replay, spawn };
package/dist/machine.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { Inspector } from "./inspection.js";
3
- import { getTag } from "./internal/utils.js";
3
+ import { getTag, stubSystem } from "./internal/utils.js";
4
4
  import { ProvisionValidationError, SlotProvisionError } from "./errors.js";
5
- import { persist } from "./persistence/persistent-machine.js";
6
5
  import { emitWithTimestamp } from "./internal/inspection.js";
7
6
  import { MachineContextTag } from "./slot.js";
8
- import { findTransitions, invalidateIndex } from "./internal/transition.js";
7
+ import { findTransitions, invalidateIndex, resolveTransition, runTransitionHandler, shouldPostpone } from "./internal/transition.js";
9
8
  import { createActor } from "./actor.js";
10
9
  import { Cause, Effect, Exit, Option, Scope } from "effect";
11
10
  //#region src/machine.ts
@@ -14,6 +13,7 @@ var machine_exports = /* @__PURE__ */ __exportAll({
14
13
  Machine: () => Machine,
15
14
  findTransitions: () => findTransitions,
16
15
  make: () => make,
16
+ replay: () => replay,
17
17
  spawn: () => spawn
18
18
  });
19
19
  const emitTaskInspection = (input) => Effect.flatMap(Effect.serviceOption(Inspector), (inspector) => Option.isNone(inspector) ? Effect.void : emitWithTimestamp(inspector.value, (timestamp) => ({
@@ -42,9 +42,6 @@ var BuiltMachine = class {
42
42
  get initial() {
43
43
  return this._inner.initial;
44
44
  }
45
- persist(config) {
46
- return this._inner.persist(config);
47
- }
48
45
  };
49
46
  /**
50
47
  * Machine definition with fluent builder API.
@@ -385,10 +382,6 @@ var Machine = class Machine {
385
382
  }
386
383
  return new BuiltMachine(this);
387
384
  }
388
- /** @internal Persist from raw Machine — prefer BuiltMachine.persist() */
389
- persist(config) {
390
- return persist(config)(this);
391
- }
392
385
  static make(config) {
393
386
  return new Machine(config.initial, config.state, config.event, config.guards, config.effects);
394
387
  }
@@ -408,11 +401,68 @@ var TransitionScope = class {
408
401
  }
409
402
  };
410
403
  const make = Machine.make;
411
- const spawn = Effect.fn("effect-machine.spawn")(function* (built, id) {
412
- const actor = yield* createActor(id ?? `actor-${Math.random().toString(36).slice(2)}`, built._inner);
404
+ /**
405
+ * Spawn an actor from a built machine.
406
+ *
407
+ * Options:
408
+ * - `id` — custom actor ID (default: random)
409
+ * - `hydrate` — restore from a previously-saved state snapshot.
410
+ * The actor starts in the hydrated state and re-runs spawn effects
411
+ * for that state (timers, scoped resources, etc.). Transition history
412
+ * is not replayed — only the current state's entry effects run.
413
+ *
414
+ * Persistence is composed in userland by observing `actor.changes`
415
+ * and saving snapshots to your own storage.
416
+ */
417
+ const spawn = Effect.fn("effect-machine.spawn")(function* (built, idOrOptions) {
418
+ const opts = typeof idOrOptions === "string" ? { id: idOrOptions } : idOrOptions;
419
+ const actor = yield* createActor(opts?.id ?? `actor-${Math.random().toString(36).slice(2)}`, built._inner, { initialState: opts?.hydrate });
413
420
  const maybeScope = yield* Effect.serviceOption(Scope.Scope);
414
421
  if (Option.isSome(maybeScope)) yield* Scope.addFinalizer(maybeScope.value, actor.stop);
415
422
  return actor;
416
423
  });
424
+ const replay = Effect.fn("effect-machine.replay")(function* (built, events, options) {
425
+ const machine = built._inner;
426
+ let state = options?.from ?? machine.initial;
427
+ const hasPostponeRules = machine.postponeRules.length > 0;
428
+ const postponed = [];
429
+ const dummySend = Effect.fn("effect-machine.replay.send")((_event) => Effect.void);
430
+ const self = {
431
+ send: dummySend,
432
+ cast: dummySend,
433
+ spawn: () => Effect.die("spawn not supported in replay")
434
+ };
435
+ for (const event of events) {
436
+ if (machine.finalStates.has(state._tag)) break;
437
+ if (hasPostponeRules && shouldPostpone(machine, state._tag, event._tag)) {
438
+ postponed.push(event);
439
+ continue;
440
+ }
441
+ const transition = resolveTransition(machine, state, event);
442
+ if (transition !== void 0) {
443
+ const result = yield* runTransitionHandler(machine, transition, state, event, self, stubSystem, "replay");
444
+ const previousTag = state._tag;
445
+ state = result.newState;
446
+ if ((state._tag !== previousTag || transition.reenter === true) && postponed.length > 0) {
447
+ let drainTag = previousTag;
448
+ while (state._tag !== drainTag && postponed.length > 0) {
449
+ if (machine.finalStates.has(state._tag)) break;
450
+ drainTag = state._tag;
451
+ const drained = postponed.splice(0);
452
+ for (const postponedEvent of drained) {
453
+ if (machine.finalStates.has(state._tag)) break;
454
+ if (shouldPostpone(machine, state._tag, postponedEvent._tag)) {
455
+ postponed.push(postponedEvent);
456
+ continue;
457
+ }
458
+ const pTransition = resolveTransition(machine, state, postponedEvent);
459
+ if (pTransition !== void 0) state = (yield* runTransitionHandler(machine, pTransition, state, postponedEvent, self, stubSystem, "replay")).newState;
460
+ }
461
+ }
462
+ }
463
+ }
464
+ }
465
+ return state;
466
+ });
417
467
  //#endregion
418
- export { BuiltMachine, Machine, findTransitions, machine_exports, make, spawn };
468
+ export { BuiltMachine, Machine, findTransitions, machine_exports, make, replay, spawn };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-machine",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cevr/effect-machine.git"
@@ -64,7 +64,7 @@
64
64
  "@effect/language-service": "^0.82.0",
65
65
  "@types/bun": "1.3.11",
66
66
  "concurrently": "^9.2.1",
67
- "effect-bun-test": "0.2.1",
67
+ "effect-bun-test": "0.3.0",
68
68
  "effect-v3": "npm:effect@^3.21.0",
69
69
  "lefthook": "^2.1.4",
70
70
  "oxfmt": "^0.41.0",
@@ -1,11 +1,8 @@
1
1
  import { EffectsDef, GuardsDef, MachineContext } from "./slot.js";
2
- import { PersistentMachine } from "./persistence/persistent-machine.js";
3
2
  import { ActorStoppedError, DuplicateActorError, NoReplyError } from "./errors.js";
4
3
  import { ProcessEventError, ProcessEventHooks, ProcessEventResult, processEventCore, resolveTransition, runSpawnEffects } from "./internal/transition.js";
5
- import { PersistentActorRef } from "./persistence/persistent-actor.js";
6
- import { ActorMetadata, PersistenceAdapterTag, PersistenceError, RestoreResult, VersionConflictError } from "./persistence/adapter.js";
7
4
  import { BuiltMachine, Machine, MachineRef } from "./machine.js";
8
- import { Context, Deferred, Effect, Layer, Option, Queue, Ref, Scope, Stream, SubscriptionRef } from "effect";
5
+ import { Context, Deferred, Effect, Layer, Option, PubSub, Queue, Ref, Scope, Stream, SubscriptionRef } from "effect";
9
6
  import * as effect_dist_dts_Tracer_js0 from "effect/dist/dts/Tracer.js";
10
7
 
11
8
  //#region src/actor.d.ts
@@ -39,6 +36,15 @@ interface ActorRefSync<State extends {
39
36
  readonly matches: (tag: State["_tag"]) => boolean;
40
37
  readonly can: (event: Event) => boolean;
41
38
  }
39
+ /**
40
+ * Information about a successful transition.
41
+ * Emitted on the `transitions` stream after each accepted event.
42
+ */
43
+ interface TransitionInfo<State, Event> {
44
+ readonly fromState: State;
45
+ readonly toState: State;
46
+ readonly event: Event;
47
+ }
42
48
  interface ActorRef<State extends {
43
49
  readonly _tag: string;
44
50
  }, Event> {
@@ -70,6 +76,14 @@ interface ActorRef<State extends {
70
76
  readonly can: (event: Event) => Effect.Effect<boolean>;
71
77
  /** Stream of state changes. */
72
78
  readonly changes: Stream.Stream<State>;
79
+ /**
80
+ * Stream of accepted transitions (edge stream).
81
+ *
82
+ * Emits `{ fromState, toState, event }` on every successful transition,
83
+ * including same-state reenters. PubSub-backed — late subscribers miss
84
+ * past edges. This is observational, not a durability guarantee.
85
+ */
86
+ readonly transitions: Stream.Stream<TransitionInfo<State, Event>>;
73
87
  /** Wait for a state matching predicate or variant (includes current snapshot). */
74
88
  readonly waitFor: {
75
89
  (predicate: (state: State) => boolean): Effect.Effect<State>;
@@ -123,54 +137,17 @@ interface ActorSystem {
123
137
  /**
124
138
  * Spawn a new actor with the given machine.
125
139
  *
126
- * For regular machines, returns ActorRef.
127
- * For persistent machines (created with Machine.persist), returns PersistentActorRef.
128
- *
129
- * All effect slots must be provided via `.build()` before spawning.
130
- *
131
140
  * @example
132
141
  * ```ts
133
- * // Regular machine (built)
134
142
  * const built = machine.build({ fetchData: ... })
135
143
  * const actor = yield* system.spawn("my-actor", built);
136
- *
137
- * // Persistent machine (auto-detected)
138
- * const persistentActor = yield* system.spawn("my-actor", persistentMachine);
139
- * persistentActor.persist; // available
140
- * persistentActor.version; // available
141
- * ```
142
- */
143
- readonly spawn: {
144
- <S extends {
145
- readonly _tag: string;
146
- }, E extends {
147
- readonly _tag: string;
148
- }, R>(id: string, machine: BuiltMachine<S, E, R>): Effect.Effect<ActorRef<S, E>, DuplicateActorError, R>;
149
- <S extends {
150
- readonly _tag: string;
151
- }, E extends {
152
- readonly _tag: string;
153
- }, R>(id: string, machine: PersistentMachine<S, E, R>): Effect.Effect<PersistentActorRef<S, E, R>, PersistenceError | VersionConflictError | DuplicateActorError, R | PersistenceAdapterTag>;
154
- };
155
- /**
156
- * Restore an actor from persistence.
157
- * Returns None if no persisted state exists for the given ID.
158
- *
159
- * @example
160
- * ```ts
161
- * const maybeActor = yield* system.restore("order-1", persistentMachine);
162
- * if (Option.isSome(maybeActor)) {
163
- * const actor = maybeActor.value;
164
- * const state = yield* actor.snapshot;
165
- * console.log(`Restored to state: ${state._tag}`);
166
- * }
167
144
  * ```
168
145
  */
169
- readonly restore: <S extends {
146
+ readonly spawn: <S extends {
170
147
  readonly _tag: string;
171
148
  }, E extends {
172
149
  readonly _tag: string;
173
- }, R>(id: string, machine: PersistentMachine<S, E, R>) => Effect.Effect<Option.Option<PersistentActorRef<S, E, R>>, PersistenceError | DuplicateActorError, R | PersistenceAdapterTag>;
150
+ }, R>(id: string, machine: BuiltMachine<S, E, R>) => Effect.Effect<ActorRef<S, E>, DuplicateActorError, R>;
174
151
  /**
175
152
  * Get an existing actor by ID
176
153
  */
@@ -194,53 +171,6 @@ interface ActorSystem {
194
171
  * Returns an unsubscribe function.
195
172
  */
196
173
  readonly subscribe: (fn: SystemEventListener) => () => void;
197
- /**
198
- * List all persisted actor metadata.
199
- * Returns empty array if adapter doesn't support registry.
200
- *
201
- * @example
202
- * ```ts
203
- * const actors = yield* system.listPersisted();
204
- * for (const meta of actors) {
205
- * console.log(`${meta.id}: ${meta.stateTag} (v${meta.version})`);
206
- * }
207
- * ```
208
- */
209
- readonly listPersisted: () => Effect.Effect<ReadonlyArray<ActorMetadata>, PersistenceError, PersistenceAdapterTag>;
210
- /**
211
- * Restore multiple actors by ID.
212
- * Returns both successfully restored actors and failures.
213
- *
214
- * @example
215
- * ```ts
216
- * const result = yield* system.restoreMany(["order-1", "order-2"], orderMachine);
217
- * console.log(`Restored: ${result.restored.length}, Failed: ${result.failed.length}`);
218
- * ```
219
- */
220
- readonly restoreMany: <S extends {
221
- readonly _tag: string;
222
- }, E extends {
223
- readonly _tag: string;
224
- }, R>(ids: ReadonlyArray<string>, machine: PersistentMachine<S, E, R>) => Effect.Effect<RestoreResult<S, E, R>, never, R | PersistenceAdapterTag>;
225
- /**
226
- * Restore all persisted actors for a machine type.
227
- * Uses adapter registry if available, otherwise returns empty result.
228
- *
229
- * @example
230
- * ```ts
231
- * const result = yield* system.restoreAll(orderMachine, {
232
- * filter: (meta) => meta.stateTag !== "Done"
233
- * });
234
- * console.log(`Restored ${result.restored.length} active orders`);
235
- * ```
236
- */
237
- readonly restoreAll: <S extends {
238
- readonly _tag: string;
239
- }, E extends {
240
- readonly _tag: string;
241
- }, R>(machine: PersistentMachine<S, E, R>, options?: {
242
- filter?: (meta: ActorMetadata) => boolean;
243
- }) => Effect.Effect<RestoreResult<S, E, R>, PersistenceError, R | PersistenceAdapterTag>;
244
174
  }
245
175
  /**
246
176
  * ActorSystem service tag
@@ -259,7 +189,7 @@ declare const buildActorRefCore: <S extends {
259
189
  readonly _tag: string;
260
190
  }, E extends {
261
191
  readonly _tag: string;
262
- }, R, GD extends GuardsDef, EFD extends EffectsDef>(id: string, machine: Machine<S, E, R, any, any, GD, EFD>, stateRef: SubscriptionRef.SubscriptionRef<S>, eventQueue: Queue.Queue<QueuedEvent<E>>, stoppedRef: Ref.Ref<boolean>, listeners: Listeners<S>, stop: Effect.Effect<void>, system: ActorSystem, childrenMap: ReadonlyMap<string, ActorRef<AnyState, unknown>>, pendingReplies: Set<Deferred.Deferred<unknown, unknown>>) => ActorRef<S, E>;
192
+ }, R, GD extends GuardsDef, EFD extends EffectsDef>(id: string, machine: Machine<S, E, R, any, any, GD, EFD>, stateRef: SubscriptionRef.SubscriptionRef<S>, eventQueue: Queue.Queue<QueuedEvent<E>>, stoppedRef: Ref.Ref<boolean>, listeners: Listeners<S>, stop: Effect.Effect<void>, system: ActorSystem, childrenMap: ReadonlyMap<string, ActorRef<AnyState, unknown>>, pendingReplies: Set<Deferred.Deferred<unknown, unknown>>, transitionsPubSub?: PubSub.PubSub<TransitionInfo<S, E>>) => ActorRef<S, E>;
263
193
  /**
264
194
  * Create and start an actor for a machine
265
195
  */
@@ -267,7 +197,9 @@ declare const createActor: <S extends {
267
197
  readonly _tag: string;
268
198
  }, E extends {
269
199
  readonly _tag: string;
270
- }, R, GD extends GuardsDef, EFD extends EffectsDef>(id: string, machine: Machine<S, E, R, Record<string, never>, Record<string, never>, GD, EFD>) => Effect.Effect<ActorRef<S, E>, never, Exclude<R, MachineContext<S, E, MachineRef<E>>> | Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, effect_dist_dts_Tracer_js0.ParentSpan> | Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, Scope.Scope> | Exclude<Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, Scope.Scope>, effect_dist_dts_Tracer_js0.ParentSpan>>;
200
+ }, R, GD extends GuardsDef, EFD extends EffectsDef>(id: string, machine: Machine<S, E, R, Record<string, never>, Record<string, never>, GD, EFD>, options?: {
201
+ initialState?: S;
202
+ } | undefined) => Effect.Effect<ActorRef<S, E>, never, Exclude<R, MachineContext<S, E, MachineRef<E>>> | Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, effect_dist_dts_Tracer_js0.ParentSpan> | Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, Scope.Scope> | Exclude<Exclude<Exclude<R, MachineContext<S, E, MachineRef<E>>>, Scope.Scope>, effect_dist_dts_Tracer_js0.ParentSpan>>;
271
203
  /** Fail all pending call/ask Deferreds with ActorStoppedError. Safe to call multiple times. */
272
204
  declare const settlePendingReplies: (pendingReplies: Set<Deferred.Deferred<unknown, unknown>>, actorId: string) => Effect.Effect<void, never, never>;
273
205
  /**
@@ -275,4 +207,4 @@ declare const settlePendingReplies: (pendingReplies: Set<Deferred.Deferred<unkno
275
207
  */
276
208
  declare const Default: Layer.Layer<ActorSystem, never, never>;
277
209
  //#endregion
278
- export { ActorRef, ActorRefSync, ActorSystem, Default, Listeners, type ProcessEventError, type ProcessEventHooks, type ProcessEventResult, QueuedEvent, SystemEvent, SystemEventListener, buildActorRefCore, createActor, notifyListeners, processEventCore, resolveTransition, runSpawnEffects, settlePendingReplies };
210
+ export { ActorRef, ActorRefSync, ActorSystem, Default, Listeners, type ProcessEventError, type ProcessEventHooks, type ProcessEventResult, QueuedEvent, SystemEvent, SystemEventListener, TransitionInfo, buildActorRefCore, createActor, notifyListeners, processEventCore, resolveTransition, runSpawnEffects, settlePendingReplies };