effect-machine 0.7.2 → 0.9.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 (51) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +6 -11
  2. package/dist/actor.d.ts +23 -3
  3. package/dist/actor.js +46 -15
  4. package/dist/cluster/entity-machine.d.ts +0 -1
  5. package/dist/cluster/entity-machine.js +3 -5
  6. package/dist/cluster/index.js +1 -2
  7. package/dist/cluster/to-entity.js +1 -3
  8. package/dist/errors.js +1 -3
  9. package/dist/index.d.ts +4 -4
  10. package/dist/index.js +2 -3
  11. package/dist/inspection.d.ts +31 -5
  12. package/dist/inspection.js +97 -5
  13. package/dist/internal/inspection.js +8 -7
  14. package/dist/internal/transition.d.ts +4 -4
  15. package/dist/internal/transition.js +11 -10
  16. package/dist/internal/utils.js +1 -3
  17. package/dist/machine.d.ts +20 -7
  18. package/dist/machine.js +64 -32
  19. package/dist/persistence/adapter.js +1 -3
  20. package/dist/persistence/adapters/in-memory.js +1 -3
  21. package/dist/persistence/index.js +1 -2
  22. package/dist/persistence/persistent-actor.js +11 -10
  23. package/dist/persistence/persistent-machine.js +1 -3
  24. package/dist/schema.js +6 -4
  25. package/dist/slot.d.ts +1 -0
  26. package/dist/slot.js +1 -3
  27. package/dist/testing.js +3 -5
  28. package/dist-v3/_virtual/_rolldown/runtime.js +6 -11
  29. package/dist-v3/actor.js +1 -3
  30. package/dist-v3/cluster/entity-machine.d.ts +0 -1
  31. package/dist-v3/cluster/entity-machine.js +1 -3
  32. package/dist-v3/cluster/index.js +1 -2
  33. package/dist-v3/cluster/to-entity.js +1 -3
  34. package/dist-v3/errors.js +1 -3
  35. package/dist-v3/index.d.ts +0 -1
  36. package/dist-v3/index.js +1 -2
  37. package/dist-v3/inspection.js +1 -3
  38. package/dist-v3/internal/inspection.js +1 -3
  39. package/dist-v3/internal/transition.js +1 -3
  40. package/dist-v3/internal/utils.js +1 -3
  41. package/dist-v3/machine.d.ts +0 -1
  42. package/dist-v3/machine.js +2 -31
  43. package/dist-v3/persistence/adapter.js +1 -3
  44. package/dist-v3/persistence/adapters/in-memory.js +1 -3
  45. package/dist-v3/persistence/index.js +1 -2
  46. package/dist-v3/persistence/persistent-actor.js +1 -3
  47. package/dist-v3/persistence/persistent-machine.js +1 -3
  48. package/dist-v3/schema.js +1 -3
  49. package/dist-v3/slot.js +1 -3
  50. package/dist-v3/testing.js +1 -3
  51. package/package.json +13 -13
@@ -5,7 +5,6 @@ import { EffectHandlers, EffectSlot, EffectSlots, EffectsDef, EffectsSchema, Gua
5
5
  import { PersistentActorRef, createPersistentActor, restorePersistentActor } from "./persistence/persistent-actor.js";
6
6
  import { ActorMetadata, PersistedEvent, PersistenceAdapter, PersistenceAdapterTag, PersistenceError, RestoreFailure, RestoreResult, Snapshot, VersionConflictError } from "./persistence/adapter.js";
7
7
  import { InMemoryPersistenceAdapter, makeInMemoryPersistenceAdapter } from "./persistence/adapters/in-memory.js";
8
- import "./persistence/index.js";
9
8
  import { BackgroundEffect, BuiltMachine, HandlerContext, Machine, MachineRef, MakeConfig, PersistOptions, ProvideHandlers, SpawnEffect, StateHandlerContext, Transition, machine_d_exports } from "./machine.js";
10
9
  import { ActorRef, ActorSystem, Default, SystemEvent, SystemEventListener } from "./actor.js";
11
10
  import { SimulationResult, TestHarness, TestHarnessOptions, assertNeverReaches, assertPath, assertReaches, createTestHarness, simulate } from "./testing.js";
package/dist-v3/index.js CHANGED
@@ -10,5 +10,4 @@ import { Event, State } from "./schema.js";
10
10
  import { assertNeverReaches, assertPath, assertReaches, createTestHarness, simulate } from "./testing.js";
11
11
  import { InMemoryPersistenceAdapter, makeInMemoryPersistenceAdapter } from "./persistence/adapters/in-memory.js";
12
12
  import "./persistence/index.js";
13
-
14
- export { Default as ActorSystemDefault, ActorSystem as ActorSystemService, AssertionError, DuplicateActorError, Event, InMemoryPersistenceAdapter, Inspector as InspectorService, InvalidSchemaError, machine_exports as Machine, MissingMatchHandlerError, MissingSchemaError, PersistenceAdapterTag, PersistenceError, ProvisionValidationError, Slot, SlotProvisionError, State, UnprovidedSlotsError, VersionConflictError, assertNeverReaches, assertPath, assertReaches, collectingInspector, consoleInspector, createPersistentActor, createTestHarness, isPersistentMachine, makeInMemoryPersistenceAdapter, makeInspector, restorePersistentActor, simulate };
13
+ export { Default as ActorSystemDefault, ActorSystem as ActorSystemService, AssertionError, DuplicateActorError, Event, InMemoryPersistenceAdapter, Inspector as InspectorService, InvalidSchemaError, machine_exports as Machine, MissingMatchHandlerError, MissingSchemaError, PersistenceAdapterTag, PersistenceError, ProvisionValidationError, Slot, SlotProvisionError, State, UnprovidedSlotsError, VersionConflictError, assertNeverReaches, assertPath, assertReaches, collectingInspector, consoleInspector, createPersistentActor, createTestHarness, isPersistentMachine, makeInMemoryPersistenceAdapter, makeInspector, restorePersistentActor, simulate };
@@ -1,5 +1,4 @@
1
1
  import { Context } from "effect";
2
-
3
2
  //#region src-v3/inspection.ts
4
3
  /**
5
4
  * Inspector service tag - optional service for machine introspection
@@ -45,6 +44,5 @@ const consoleInspector = () => makeInspector((event) => {
45
44
  * Collecting inspector that stores events in an array for testing
46
45
  */
47
46
  const collectingInspector = (events) => ({ onInspect: (event) => events.push(event) });
48
-
49
47
  //#endregion
50
- export { Inspector, collectingInspector, consoleInspector, makeInspector };
48
+ export { Inspector, collectingInspector, consoleInspector, makeInspector };
@@ -1,5 +1,4 @@
1
1
  import { Clock, Effect } from "effect";
2
-
3
2
  //#region src-v3/internal/inspection.ts
4
3
  /**
5
4
  * Emit an inspection event with timestamp from Clock.
@@ -10,6 +9,5 @@ const emitWithTimestamp = Effect.fn("effect-machine.emitWithTimestamp")(function
10
9
  const timestamp = yield* Clock.currentTimeMillis;
11
10
  yield* Effect.try(() => inspector.onInspect(makeEvent(timestamp))).pipe(Effect.ignore);
12
11
  });
13
-
14
12
  //#endregion
15
- export { emitWithTimestamp };
13
+ export { emitWithTimestamp };
@@ -1,7 +1,6 @@
1
1
  import { INTERNAL_ENTER_EVENT, isEffect } from "./utils.js";
2
2
  import { BuiltMachine } from "../machine.js";
3
3
  import { Cause, Effect, Exit, Scope } from "effect";
4
-
5
4
  //#region src-v3/internal/transition.ts
6
5
  /**
7
6
  * Transition execution and indexing.
@@ -233,6 +232,5 @@ const findTransitions = (input, stateTag, eventTag) => {
233
232
  const findSpawnEffects = (machine, stateTag) => {
234
233
  return getIndex(machine).spawn.get(stateTag) ?? [];
235
234
  };
236
-
237
235
  //#endregion
238
- export { executeTransition, findSpawnEffects, findTransitions, invalidateIndex, processEventCore, resolveTransition, runSpawnEffects, runTransitionHandler };
236
+ export { executeTransition, findSpawnEffects, findTransitions, invalidateIndex, processEventCore, resolveTransition, runSpawnEffects, runTransitionHandler };
@@ -1,5 +1,4 @@
1
1
  import { Effect, Stream } from "effect";
2
-
3
2
  //#region src-v3/internal/utils.ts
4
3
  /**
5
4
  * Internal event tags used for lifecycle effect contexts.
@@ -46,6 +45,5 @@ const stubSystem = {
46
45
  restoreMany: () => Effect.die("restoreMany not supported in stub system"),
47
46
  restoreAll: () => Effect.die("restoreAll not supported in stub system")
48
47
  };
49
-
50
48
  //#endregion
51
- export { INTERNAL_ENTER_EVENT, INTERNAL_INIT_EVENT, getTag, isEffect, stubSystem };
49
+ export { INTERNAL_ENTER_EVENT, INTERNAL_INIT_EVENT, getTag, isEffect, stubSystem };
@@ -5,7 +5,6 @@ import { PersistenceConfig, PersistentMachine } from "./persistence/persistent-m
5
5
  import { DuplicateActorError } from "./errors.js";
6
6
  import { EffectHandlers, EffectSlots, EffectsDef, EffectsSchema, GuardHandlers, GuardSlots, GuardsDef, GuardsSchema, MachineContext } from "./slot.js";
7
7
  import { findTransitions } from "./internal/transition.js";
8
- import "./persistence/index.js";
9
8
  import { ActorRef, ActorSystem } from "./actor.js";
10
9
  import { Cause, Context, Effect, Schedule, Schema, Scope } from "effect";
11
10
 
@@ -6,7 +6,6 @@ import { MachineContextTag } from "./slot.js";
6
6
  import { findTransitions, invalidateIndex } from "./internal/transition.js";
7
7
  import { createActor } from "./actor.js";
8
8
  import { Cause, Effect, Exit, Option, Scope } from "effect";
9
-
10
9
  //#region src-v3/machine.ts
11
10
  var machine_exports = /* @__PURE__ */ __exportAll({
12
11
  BuiltMachine: () => BuiltMachine,
@@ -279,39 +278,11 @@ var Machine = class Machine {
279
278
  }
280
279
  };
281
280
  const make = Machine.make;
282
- /**
283
- * Spawn an actor directly without ActorSystem ceremony.
284
- * Accepts only `BuiltMachine` (call `.build()` first).
285
- *
286
- * **Single actor, no registry.** Caller manages lifetime via `actor.stop`.
287
- * If a `Scope` exists in context, cleanup attaches automatically on scope close.
288
- *
289
- * For registry, lookup by ID, persistence, or multi-actor coordination,
290
- * use `ActorSystemService` / `system.spawn` instead.
291
- *
292
- * @example
293
- * ```ts
294
- * // Fire-and-forget — caller manages lifetime
295
- * const actor = yield* Machine.spawn(machine.build());
296
- * yield* actor.send(Event.Start);
297
- * yield* actor.awaitFinal;
298
- * yield* actor.stop;
299
- *
300
- * // Scope-aware — auto-cleans up on scope close
301
- * yield* Effect.scoped(Effect.gen(function* () {
302
- * const actor = yield* Machine.spawn(machine.build());
303
- * yield* actor.send(Event.Start);
304
- * // actor.stop called automatically when scope closes
305
- * }));
306
- * ```
307
- */
308
- const spawnImpl = Effect.fn("effect-machine.spawn")(function* (built, id) {
281
+ const spawn = Effect.fn("effect-machine.spawn")(function* (built, id) {
309
282
  const actor = yield* createActor(id ?? `actor-${Math.random().toString(36).slice(2)}`, built._inner);
310
283
  const maybeScope = yield* Effect.serviceOption(Scope.Scope);
311
284
  if (Option.isSome(maybeScope)) yield* Scope.addFinalizer(maybeScope.value, actor.stop);
312
285
  return actor;
313
286
  });
314
- const spawn = spawnImpl;
315
-
316
287
  //#endregion
317
- export { BuiltMachine, Machine, findTransitions, machine_exports, make, spawn };
288
+ export { BuiltMachine, Machine, findTransitions, machine_exports, make, spawn };
@@ -1,5 +1,4 @@
1
1
  import { Context, Schema } from "effect";
2
-
3
2
  //#region src-v3/persistence/adapter.ts
4
3
  /**
5
4
  * Error type for persistence operations
@@ -22,6 +21,5 @@ var VersionConflictError = class extends Schema.TaggedError()("VersionConflictEr
22
21
  * PersistenceAdapter service tag
23
22
  */
24
23
  var PersistenceAdapterTag = class extends Context.Tag("effect-machine/src/persistence/adapter/PersistenceAdapterTag")() {};
25
-
26
24
  //#endregion
27
- export { PersistenceAdapterTag, PersistenceError, VersionConflictError };
25
+ export { PersistenceAdapterTag, PersistenceError, VersionConflictError };
@@ -1,6 +1,5 @@
1
1
  import { PersistenceAdapterTag, PersistenceError, VersionConflictError } from "../adapter.js";
2
2
  import { Effect, Layer, Option, Ref, Schema } from "effect";
3
-
4
3
  //#region src-v3/persistence/adapters/in-memory.ts
5
4
  /**
6
5
  * Create an in-memory persistence adapter.
@@ -171,6 +170,5 @@ const makeInMemoryPersistenceAdapter = make;
171
170
  * ```
172
171
  */
173
172
  const InMemoryPersistenceAdapter = Layer.effect(PersistenceAdapterTag, make);
174
-
175
173
  //#endregion
176
- export { InMemoryPersistenceAdapter, makeInMemoryPersistenceAdapter };
174
+ export { InMemoryPersistenceAdapter, makeInMemoryPersistenceAdapter };
@@ -2,5 +2,4 @@ import { isPersistentMachine, persist } from "./persistent-machine.js";
2
2
  import { PersistenceAdapterTag, PersistenceError, VersionConflictError } from "./adapter.js";
3
3
  import { createPersistentActor, restorePersistentActor } from "./persistent-actor.js";
4
4
  import { InMemoryPersistenceAdapter, makeInMemoryPersistenceAdapter } from "./adapters/in-memory.js";
5
-
6
- export { InMemoryPersistenceAdapter, PersistenceAdapterTag, PersistenceError, VersionConflictError, createPersistentActor, isPersistentMachine, makeInMemoryPersistenceAdapter, persist, restorePersistentActor };
5
+ export { InMemoryPersistenceAdapter, PersistenceAdapterTag, PersistenceError, VersionConflictError, createPersistentActor, isPersistentMachine, makeInMemoryPersistenceAdapter, persist, restorePersistentActor };
@@ -5,7 +5,6 @@ import { emitWithTimestamp } from "../internal/inspection.js";
5
5
  import { PersistenceAdapterTag } from "./adapter.js";
6
6
  import { ActorSystem, buildActorRefCore, notifyListeners } from "../actor.js";
7
7
  import { Cause, Clock, Effect, Exit, Fiber, Option, Queue, Ref, Schedule, Scope, SubscriptionRef } from "effect";
8
-
9
8
  //#region src-v3/persistence/persistent-actor.ts
10
9
  /** Get current time in milliseconds using Effect Clock */
11
10
  const now = Clock.currentTimeMillis;
@@ -362,6 +361,5 @@ const restorePersistentActor = Effect.fn("effect-machine.persistentActor.restore
362
361
  const actor = yield* createPersistentActor(id, persistentMachine, maybeSnapshot, events);
363
362
  return Option.some(actor);
364
363
  });
365
-
366
364
  //#endregion
367
- export { createPersistentActor, restorePersistentActor };
365
+ export { createPersistentActor, restorePersistentActor };
@@ -1,5 +1,4 @@
1
1
  import { MissingSchemaError } from "../errors.js";
2
-
3
2
  //#region src-v3/persistence/persistent-machine.ts
4
3
  /**
5
4
  * Type guard to check if a value is a PersistentMachine
@@ -19,6 +18,5 @@ const persist = (config) => (machine) => {
19
18
  }
20
19
  };
21
20
  };
22
-
23
21
  //#endregion
24
- export { isPersistentMachine, persist };
22
+ export { isPersistentMachine, persist };
package/dist-v3/schema.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { InvalidSchemaError, MissingMatchHandlerError } from "./errors.js";
2
2
  import { Schema } from "effect";
3
-
4
3
  //#region src-v3/schema.ts
5
4
  /**
6
5
  * Schema-first State/Event definitions for effect-machine.
@@ -160,6 +159,5 @@ const State = (definition) => createMachineSchema(definition);
160
159
  * ```
161
160
  */
162
161
  const Event = (definition) => createMachineSchema(definition);
163
-
164
162
  //#endregion
165
- export { Event, State };
163
+ export { Event, State };
package/dist-v3/slot.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Context } from "effect";
2
-
3
2
  //#region src-v3/slot.ts
4
3
  /**
5
4
  * Slot module - schema-based, parameterized guards and effects.
@@ -94,6 +93,5 @@ const Slot = {
94
93
  Guards,
95
94
  Effects
96
95
  };
97
-
98
96
  //#endregion
99
- export { Effects, Guards, MachineContextTag, Slot };
97
+ export { Effects, Guards, MachineContextTag, Slot };
@@ -3,7 +3,6 @@ import { AssertionError } from "./errors.js";
3
3
  import { BuiltMachine } from "./machine.js";
4
4
  import { executeTransition } from "./internal/transition.js";
5
5
  import { Effect, SubscriptionRef } from "effect";
6
-
7
6
  //#region src-v3/testing.ts
8
7
  /**
9
8
  * Simulate a sequence of events through a machine without running an actor.
@@ -133,6 +132,5 @@ const createTestHarness = Effect.fn("effect-machine.createTestHarness")(function
133
132
  getState: SubscriptionRef.get(stateRef)
134
133
  };
135
134
  });
136
-
137
135
  //#endregion
138
- export { AssertionError, assertNeverReaches, assertPath, assertReaches, createTestHarness, simulate };
136
+ export { AssertionError, assertNeverReaches, assertPath, assertReaches, createTestHarness, simulate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-machine",
3
- "version": "0.7.2",
3
+ "version": "0.9.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cevr/effect-machine.git"
@@ -55,20 +55,20 @@
55
55
  "release": "bun run build && changeset publish"
56
56
  },
57
57
  "dependencies": {
58
- "effect": "4.0.0-beta.26"
58
+ "effect": "4.0.0-beta.35"
59
59
  },
60
60
  "devDependencies": {
61
- "@changesets/changelog-github": "^0.5.2",
62
- "@changesets/cli": "^2.29.8",
63
- "@effect/language-service": "^0.75.1",
64
- "@types/bun": "1.3.9",
61
+ "@changesets/changelog-github": "^0.6.0",
62
+ "@changesets/cli": "^2.30.0",
63
+ "@effect/language-service": "^0.82.0",
64
+ "@types/bun": "1.3.11",
65
65
  "concurrently": "^9.2.1",
66
- "effect-bun-test": "0.2.0",
67
- "effect-v3": "npm:effect@^3.19.18",
68
- "lefthook": "^2.1.1",
69
- "oxfmt": "^0.33.0",
70
- "oxlint": "^1.48.0",
71
- "tsdown": "^0.20.3",
66
+ "effect-bun-test": "0.2.1",
67
+ "effect-v3": "npm:effect@^3.21.0",
68
+ "lefthook": "^2.1.4",
69
+ "oxfmt": "^0.41.0",
70
+ "oxlint": "^1.56.0",
71
+ "tsdown": "^0.21.4",
72
72
  "typescript": "^5.9.3"
73
73
  },
74
74
  "peerDependencies": {
@@ -80,6 +80,6 @@
80
80
  }
81
81
  },
82
82
  "overrides": {
83
- "effect": "4.0.0-beta.26"
83
+ "effect": "4.0.0-beta.35"
84
84
  }
85
85
  }