effect-machine 0.8.0 → 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.
- package/dist/_virtual/_rolldown/runtime.js +6 -11
- package/dist/actor.d.ts +23 -3
- package/dist/actor.js +41 -12
- package/dist/cluster/entity-machine.d.ts +0 -1
- package/dist/cluster/entity-machine.js +1 -3
- package/dist/cluster/index.js +1 -2
- package/dist/cluster/to-entity.js +1 -3
- package/dist/errors.js +1 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/dist/inspection.js +1 -3
- package/dist/internal/inspection.js +1 -3
- package/dist/internal/transition.js +1 -3
- package/dist/internal/utils.js +1 -3
- package/dist/machine.d.ts +0 -1
- package/dist/machine.js +2 -31
- package/dist/persistence/adapter.js +1 -3
- package/dist/persistence/adapters/in-memory.js +1 -3
- package/dist/persistence/index.js +1 -2
- package/dist/persistence/persistent-actor.js +5 -6
- package/dist/persistence/persistent-machine.js +1 -3
- package/dist/schema.js +1 -3
- package/dist/slot.js +1 -3
- package/dist/testing.js +1 -3
- package/dist-v3/_virtual/_rolldown/runtime.js +6 -11
- package/dist-v3/actor.js +1 -3
- package/dist-v3/cluster/entity-machine.d.ts +0 -1
- package/dist-v3/cluster/entity-machine.js +1 -3
- package/dist-v3/cluster/index.js +1 -2
- package/dist-v3/cluster/to-entity.js +1 -3
- package/dist-v3/errors.js +1 -3
- package/dist-v3/index.d.ts +0 -1
- package/dist-v3/index.js +1 -2
- package/dist-v3/inspection.js +1 -3
- package/dist-v3/internal/inspection.js +1 -3
- package/dist-v3/internal/transition.js +1 -3
- package/dist-v3/internal/utils.js +1 -3
- package/dist-v3/machine.d.ts +0 -1
- package/dist-v3/machine.js +2 -31
- package/dist-v3/persistence/adapter.js +1 -3
- package/dist-v3/persistence/adapters/in-memory.js +1 -3
- package/dist-v3/persistence/index.js +1 -2
- package/dist-v3/persistence/persistent-actor.js +1 -3
- package/dist-v3/persistence/persistent-machine.js +1 -3
- package/dist-v3/schema.js +1 -3
- package/dist-v3/slot.js +1 -3
- package/dist-v3/testing.js +1 -3
- package/package.json +11 -11
|
@@ -2,17 +2,12 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __exportAll = (all, no_symbols) => {
|
|
4
4
|
let target = {};
|
|
5
|
-
for (var name in all) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
if (!no_symbols) {
|
|
12
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
-
}
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
10
|
return target;
|
|
15
11
|
};
|
|
16
|
-
|
|
17
12
|
//#endregion
|
|
18
|
-
export { __exportAll };
|
|
13
|
+
export { __exportAll };
|
package/dist/actor.d.ts
CHANGED
|
@@ -5,10 +5,17 @@ import { ProcessEventError, ProcessEventHooks, ProcessEventResult, processEventC
|
|
|
5
5
|
import { PersistentActorRef } from "./persistence/persistent-actor.js";
|
|
6
6
|
import { ActorMetadata, PersistenceAdapterTag, PersistenceError, RestoreResult, VersionConflictError } from "./persistence/adapter.js";
|
|
7
7
|
import { BuiltMachine, Machine, MachineRef } from "./machine.js";
|
|
8
|
-
import { Effect, Layer, Option, Queue, Ref, Scope, ServiceMap, Stream, SubscriptionRef } from "effect";
|
|
8
|
+
import { Deferred, Effect, Layer, Option, Queue, Ref, Scope, ServiceMap, Stream, SubscriptionRef } from "effect";
|
|
9
9
|
import * as effect_Tracer0 from "effect/Tracer";
|
|
10
10
|
|
|
11
11
|
//#region src/actor.d.ts
|
|
12
|
+
/** Queued event with optional reply channel */
|
|
13
|
+
interface QueuedEvent<E> {
|
|
14
|
+
readonly event: E;
|
|
15
|
+
readonly reply?: Deferred.Deferred<ProcessEventResult<{
|
|
16
|
+
readonly _tag: string;
|
|
17
|
+
}>>;
|
|
18
|
+
}
|
|
12
19
|
/**
|
|
13
20
|
* Reference to a running actor.
|
|
14
21
|
*/
|
|
@@ -96,6 +103,19 @@ interface ActorRef<State extends {
|
|
|
96
103
|
* (e.g. framework hooks, event handlers).
|
|
97
104
|
*/
|
|
98
105
|
readonly sendSync: (event: Event) => void;
|
|
106
|
+
/**
|
|
107
|
+
* Send event and wait for the transition result (synchronous processing).
|
|
108
|
+
* The event is processed through the queue (preserving serialization)
|
|
109
|
+
* but the caller gets back the ProcessEventResult.
|
|
110
|
+
*
|
|
111
|
+
* OTP gen_server:call equivalent — use when you need to know what happened.
|
|
112
|
+
*/
|
|
113
|
+
readonly dispatch: (event: Event) => Effect.Effect<ProcessEventResult<State>>;
|
|
114
|
+
/**
|
|
115
|
+
* Promise-based dispatch — send event and get back the transition result.
|
|
116
|
+
* Use at non-Effect boundaries (React event handlers, framework hooks, tests).
|
|
117
|
+
*/
|
|
118
|
+
readonly dispatchPromise: (event: Event) => Promise<ProcessEventResult<State>>;
|
|
99
119
|
/**
|
|
100
120
|
* Subscribe to state changes (sync callback)
|
|
101
121
|
* Returns unsubscribe function
|
|
@@ -275,7 +295,7 @@ declare const buildActorRefCore: <S extends {
|
|
|
275
295
|
readonly _tag: string;
|
|
276
296
|
}, E extends {
|
|
277
297
|
readonly _tag: string;
|
|
278
|
-
}, 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<E
|
|
298
|
+
}, 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>>) => ActorRef<S, E>;
|
|
279
299
|
/**
|
|
280
300
|
* Create and start an actor for a machine
|
|
281
301
|
*/
|
|
@@ -289,4 +309,4 @@ declare const createActor: <S extends {
|
|
|
289
309
|
*/
|
|
290
310
|
declare const Default: Layer.Layer<ActorSystem, never, never>;
|
|
291
311
|
//#endregion
|
|
292
|
-
export { ActorRef, ActorSystem, Default, Listeners, type ProcessEventError, type ProcessEventHooks, type ProcessEventResult, SystemEvent, SystemEventListener, buildActorRefCore, createActor, notifyListeners, processEventCore, resolveTransition, runSpawnEffects };
|
|
312
|
+
export { ActorRef, ActorSystem, Default, Listeners, type ProcessEventError, type ProcessEventHooks, type ProcessEventResult, QueuedEvent, SystemEvent, SystemEventListener, buildActorRefCore, createActor, notifyListeners, processEventCore, resolveTransition, runSpawnEffects };
|
package/dist/actor.js
CHANGED
|
@@ -7,7 +7,6 @@ import { processEventCore, resolveTransition, runSpawnEffects } from "./internal
|
|
|
7
7
|
import { PersistenceAdapterTag, PersistenceError } from "./persistence/adapter.js";
|
|
8
8
|
import { createPersistentActor, restorePersistentActor } from "./persistence/persistent-actor.js";
|
|
9
9
|
import { Cause, Deferred, Effect, Exit, Fiber, Layer, MutableHashMap, Option, PubSub, Queue, Ref, Scope, Semaphore, ServiceMap, Stream, SubscriptionRef } from "effect";
|
|
10
|
-
|
|
11
10
|
//#region src/actor.ts
|
|
12
11
|
/**
|
|
13
12
|
* Actor system: spawning, lifecycle, and event processing.
|
|
@@ -35,7 +34,25 @@ const notifyListeners = (listeners, state) => {
|
|
|
35
34
|
const buildActorRefCore = (id, machine, stateRef, eventQueue, stoppedRef, listeners, stop, system, childrenMap) => {
|
|
36
35
|
const send = Effect.fn("effect-machine.actor.send")(function* (event) {
|
|
37
36
|
if (yield* Ref.get(stoppedRef)) return;
|
|
38
|
-
yield* Queue.offer(eventQueue, event);
|
|
37
|
+
yield* Queue.offer(eventQueue, { event });
|
|
38
|
+
});
|
|
39
|
+
const dispatch = Effect.fn("effect-machine.actor.dispatch")(function* (event) {
|
|
40
|
+
if (yield* Ref.get(stoppedRef)) {
|
|
41
|
+
const currentState = yield* SubscriptionRef.get(stateRef);
|
|
42
|
+
return {
|
|
43
|
+
newState: currentState,
|
|
44
|
+
previousState: currentState,
|
|
45
|
+
transitioned: false,
|
|
46
|
+
lifecycleRan: false,
|
|
47
|
+
isFinal: machine.finalStates.has(currentState._tag)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const reply = yield* Deferred.make();
|
|
51
|
+
yield* Queue.offer(eventQueue, {
|
|
52
|
+
event,
|
|
53
|
+
reply
|
|
54
|
+
});
|
|
55
|
+
return yield* Deferred.await(reply);
|
|
39
56
|
});
|
|
40
57
|
const snapshot = SubscriptionRef.get(stateRef).pipe(Effect.withSpan("effect-machine.actor.snapshot"));
|
|
41
58
|
const matches = Effect.fn("effect-machine.actor.matches")(function* (tag) {
|
|
@@ -87,8 +104,10 @@ const buildActorRefCore = (id, machine, stateRef, eventQueue, stoppedRef, listen
|
|
|
87
104
|
awaitFinal,
|
|
88
105
|
sendAndWait,
|
|
89
106
|
sendSync: (event) => {
|
|
90
|
-
if (!Effect.runSync(Ref.get(stoppedRef))) Effect.runSync(Queue.offer(eventQueue, event));
|
|
107
|
+
if (!Effect.runSync(Ref.get(stoppedRef))) Effect.runSync(Queue.offer(eventQueue, { event }));
|
|
91
108
|
},
|
|
109
|
+
dispatch,
|
|
110
|
+
dispatchPromise: (event) => Effect.runPromise(dispatch(event)),
|
|
92
111
|
subscribe: (fn) => {
|
|
93
112
|
listeners.add(fn);
|
|
94
113
|
return () => {
|
|
@@ -120,7 +139,7 @@ const createActor = Effect.fn("effect-machine.actor.spawn")(function* (id, machi
|
|
|
120
139
|
const self = {
|
|
121
140
|
send: Effect.fn("effect-machine.actor.self.send")(function* (event) {
|
|
122
141
|
if (yield* Ref.get(stoppedRef)) return;
|
|
123
|
-
yield* Queue.offer(eventQueue, event);
|
|
142
|
+
yield* Queue.offer(eventQueue, { event });
|
|
124
143
|
}),
|
|
125
144
|
spawn: (childId, childMachine) => Effect.gen(function* () {
|
|
126
145
|
const child = yield* system.spawn(childId, childMachine).pipe(Effect.provideService(ActorSystem, system));
|
|
@@ -198,13 +217,15 @@ const createActor = Effect.fn("effect-machine.actor.spawn")(function* (id, machi
|
|
|
198
217
|
*/
|
|
199
218
|
const eventLoop = Effect.fn("effect-machine.actor.eventLoop")(function* (machine, stateRef, eventQueue, stoppedRef, self, listeners, backgroundFibers, stateScopeRef, actorId, inspector, system) {
|
|
200
219
|
while (true) {
|
|
201
|
-
const event = yield* Queue.take(eventQueue);
|
|
220
|
+
const { event, reply } = yield* Queue.take(eventQueue);
|
|
202
221
|
const currentState = yield* SubscriptionRef.get(stateRef);
|
|
203
|
-
|
|
222
|
+
const { shouldStop, result } = yield* Effect.withSpan("effect-machine.event.process", { attributes: {
|
|
204
223
|
"effect_machine.actor.id": actorId,
|
|
205
224
|
"effect_machine.state.current": currentState._tag,
|
|
206
225
|
"effect_machine.event.type": event._tag
|
|
207
|
-
} })(processEvent(machine, currentState, event, stateRef, self, listeners, stateScopeRef, actorId, inspector, system))
|
|
226
|
+
} })(processEvent(machine, currentState, event, stateRef, self, listeners, stateScopeRef, actorId, inspector, system));
|
|
227
|
+
if (reply !== void 0) yield* Deferred.succeed(reply, result);
|
|
228
|
+
if (shouldStop) {
|
|
208
229
|
yield* Ref.set(stoppedRef, true);
|
|
209
230
|
yield* Scope.close(stateScopeRef.current, Exit.void);
|
|
210
231
|
yield* Effect.all(backgroundFibers.map(Fiber.interrupt), { concurrency: "unbounded" });
|
|
@@ -252,7 +273,10 @@ const processEvent = Effect.fn("effect-machine.actor.processEvent")(function* (m
|
|
|
252
273
|
});
|
|
253
274
|
if (!result.transitioned) {
|
|
254
275
|
yield* Effect.annotateCurrentSpan("effect_machine.transition.matched", false);
|
|
255
|
-
return
|
|
276
|
+
return {
|
|
277
|
+
shouldStop: false,
|
|
278
|
+
result
|
|
279
|
+
};
|
|
256
280
|
}
|
|
257
281
|
yield* Effect.annotateCurrentSpan("effect_machine.transition.matched", true);
|
|
258
282
|
yield* SubscriptionRef.set(stateRef, result.newState);
|
|
@@ -267,10 +291,16 @@ const processEvent = Effect.fn("effect-machine.actor.processEvent")(function* (m
|
|
|
267
291
|
finalState: result.newState,
|
|
268
292
|
timestamp
|
|
269
293
|
}));
|
|
270
|
-
return
|
|
294
|
+
return {
|
|
295
|
+
shouldStop: true,
|
|
296
|
+
result
|
|
297
|
+
};
|
|
271
298
|
}
|
|
272
299
|
}
|
|
273
|
-
return
|
|
300
|
+
return {
|
|
301
|
+
shouldStop: false,
|
|
302
|
+
result
|
|
303
|
+
};
|
|
274
304
|
});
|
|
275
305
|
/**
|
|
276
306
|
* Run spawn effects with actor-specific inspection and tracing.
|
|
@@ -454,6 +484,5 @@ const make = Effect.fn("effect-machine.actorSystem.make")(function* () {
|
|
|
454
484
|
* Default ActorSystem layer
|
|
455
485
|
*/
|
|
456
486
|
const Default = Layer.effect(ActorSystem, make());
|
|
457
|
-
|
|
458
487
|
//#endregion
|
|
459
|
-
export { ActorSystem, Default, buildActorRefCore, createActor, notifyListeners, processEventCore, resolveTransition, runSpawnEffects };
|
|
488
|
+
export { ActorSystem, Default, buildActorRefCore, createActor, notifyListeners, processEventCore, resolveTransition, runSpawnEffects };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EffectsDef, GuardsDef } from "../slot.js";
|
|
2
2
|
import { ProcessEventHooks } from "../internal/transition.js";
|
|
3
3
|
import { Machine } from "../machine.js";
|
|
4
|
-
import "../actor.js";
|
|
5
4
|
import { Layer } from "effect";
|
|
6
5
|
import { Entity } from "effect/unstable/cluster";
|
|
7
6
|
import { Rpc } from "effect/unstable/rpc";
|
|
@@ -2,7 +2,6 @@ import { processEventCore, runSpawnEffects } from "../internal/transition.js";
|
|
|
2
2
|
import { ActorSystem } from "../actor.js";
|
|
3
3
|
import { Effect, Option, Queue, Ref, Scope } from "effect";
|
|
4
4
|
import { Entity } from "effect/unstable/cluster";
|
|
5
|
-
|
|
6
5
|
//#region src/cluster/entity-machine.ts
|
|
7
6
|
/**
|
|
8
7
|
* EntityMachine adapter - wires a machine to a cluster Entity layer.
|
|
@@ -75,6 +74,5 @@ const EntityMachine = { layer: (entity, machine, options) => {
|
|
|
75
74
|
});
|
|
76
75
|
return entity.toLayer(layer());
|
|
77
76
|
} };
|
|
78
|
-
|
|
79
77
|
//#endregion
|
|
80
|
-
export { EntityMachine };
|
|
78
|
+
export { EntityMachine };
|
package/dist/cluster/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { MissingSchemaError } from "../errors.js";
|
|
2
2
|
import { Entity } from "effect/unstable/cluster";
|
|
3
3
|
import { Rpc } from "effect/unstable/rpc";
|
|
4
|
-
|
|
5
4
|
//#region src/cluster/to-entity.ts
|
|
6
5
|
/**
|
|
7
6
|
* Generate Entity definition from a machine.
|
|
@@ -48,6 +47,5 @@ const toEntity = (machine, options) => {
|
|
|
48
47
|
success: stateSchema
|
|
49
48
|
}), Rpc.make("GetState", { success: stateSchema })]);
|
|
50
49
|
};
|
|
51
|
-
|
|
52
50
|
//#endregion
|
|
53
|
-
export { toEntity };
|
|
51
|
+
export { toEntity };
|
package/dist/errors.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
|
|
3
2
|
//#region src/errors.ts
|
|
4
3
|
/**
|
|
5
4
|
* Typed error classes for effect-machine.
|
|
@@ -33,6 +32,5 @@ var ProvisionValidationError = class extends Schema.TaggedErrorClass()("Provisio
|
|
|
33
32
|
}) {};
|
|
34
33
|
/** Assertion failed in testing utilities */
|
|
35
34
|
var AssertionError = class extends Schema.TaggedErrorClass()("AssertionError", { message: Schema.String }) {};
|
|
36
|
-
|
|
37
35
|
//#endregion
|
|
38
|
-
export { AssertionError, DuplicateActorError, InvalidSchemaError, MissingMatchHandlerError, MissingSchemaError, ProvisionValidationError, SlotProvisionError, UnprovidedSlotsError };
|
|
36
|
+
export { AssertionError, DuplicateActorError, InvalidSchemaError, MissingMatchHandlerError, MissingSchemaError, ProvisionValidationError, SlotProvisionError, UnprovidedSlotsError };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { EffectHandlers, EffectSlot, EffectSlots, EffectsDef, EffectsSchema, Gua
|
|
|
2
2
|
import { Event, MachineEventSchema, MachineStateSchema, State } from "./schema.js";
|
|
3
3
|
import { PersistenceConfig, PersistentMachine, isPersistentMachine } from "./persistence/persistent-machine.js";
|
|
4
4
|
import { AssertionError, DuplicateActorError, InvalidSchemaError, MissingMatchHandlerError, MissingSchemaError, ProvisionValidationError, SlotProvisionError, UnprovidedSlotsError } from "./errors.js";
|
|
5
|
+
import { ProcessEventResult } from "./internal/transition.js";
|
|
5
6
|
import { PersistentActorRef, createPersistentActor, restorePersistentActor } from "./persistence/persistent-actor.js";
|
|
6
7
|
import { ActorMetadata, PersistedEvent, PersistenceAdapter, PersistenceAdapterTag, PersistenceError, RestoreFailure, RestoreResult, Snapshot, VersionConflictError } from "./persistence/adapter.js";
|
|
7
8
|
import { InMemoryPersistenceAdapter, makeInMemoryPersistenceAdapter } from "./persistence/adapters/in-memory.js";
|
|
8
|
-
import "./persistence/index.js";
|
|
9
9
|
import { BackgroundEffect, BuiltMachine, HandlerContext, Machine, MachineRef, MakeConfig, PersistOptions, ProvideHandlers, SpawnEffect, StateHandlerContext, TaskOptions, Transition, machine_d_exports } from "./machine.js";
|
|
10
10
|
import { ActorRef, ActorSystem, Default, SystemEvent, SystemEventListener } from "./actor.js";
|
|
11
11
|
import { SimulationResult, TestHarness, TestHarnessOptions, assertNeverReaches, assertPath, assertReaches, createTestHarness, simulate } from "./testing.js";
|
|
12
12
|
import { AnyInspectionEvent, EffectEvent, ErrorEvent, EventReceivedEvent, InspectionEvent, Inspector, InspectorHandler, SpawnEvent, StopEvent, TaskEvent, TracingInspectorOptions, TransitionEvent, collectingInspector, combineInspectors, consoleInspector, makeInspector, makeInspectorEffect, tracingInspector } from "./inspection.js";
|
|
13
|
-
export { type ActorMetadata, type ActorRef, type ActorSystem, Default as ActorSystemDefault, ActorSystem as ActorSystemService, type AnyInspectionEvent, AssertionError, type BackgroundEffect, type BuiltMachine, DuplicateActorError, type EffectEvent, type EffectSlots, type EffectsDef, type EffectsSchema, type ErrorEvent, Event, type EventReceivedEvent, type GuardHandlers, type GuardSlot, type GuardSlots, type GuardsDef, type GuardsSchema, type HandlerContext, InMemoryPersistenceAdapter, type InspectionEvent, type Inspector, type InspectorHandler, Inspector as InspectorService, InvalidSchemaError, machine_d_exports as Machine, type MachineContext, type MachineEventSchema, type MachineRef, type MachineStateSchema, type Machine as MachineType, type MakeConfig, MissingMatchHandlerError, MissingSchemaError, type PersistOptions, type PersistedEvent, type PersistenceAdapter, PersistenceAdapterTag, type PersistenceConfig, PersistenceError, type PersistentActorRef, type PersistentMachine, type ProvideHandlers, ProvisionValidationError, type RestoreFailure, type RestoreResult, type SimulationResult, Slot, type EffectHandlers as SlotEffectHandlers, type EffectSlot as SlotEffectSlot, SlotProvisionError, type Snapshot, type SpawnEffect, type SpawnEvent, State, type StateHandlerContext, type StopEvent, type SystemEvent, type SystemEventListener, type TaskEvent, type TaskOptions, type TestHarness, type TestHarnessOptions, type TracingInspectorOptions, type Transition, type TransitionEvent, UnprovidedSlotsError, VersionConflictError, assertNeverReaches, assertPath, assertReaches, collectingInspector, combineInspectors, consoleInspector, createPersistentActor, createTestHarness, isPersistentMachine, makeInMemoryPersistenceAdapter, makeInspector, makeInspectorEffect, restorePersistentActor, simulate, tracingInspector };
|
|
13
|
+
export { type ActorMetadata, type ActorRef, type ActorSystem, Default as ActorSystemDefault, ActorSystem as ActorSystemService, type AnyInspectionEvent, AssertionError, type BackgroundEffect, type BuiltMachine, DuplicateActorError, type EffectEvent, type EffectSlots, type EffectsDef, type EffectsSchema, type ErrorEvent, Event, type EventReceivedEvent, type GuardHandlers, type GuardSlot, type GuardSlots, type GuardsDef, type GuardsSchema, type HandlerContext, InMemoryPersistenceAdapter, type InspectionEvent, type Inspector, type InspectorHandler, Inspector as InspectorService, InvalidSchemaError, machine_d_exports as Machine, type MachineContext, type MachineEventSchema, type MachineRef, type MachineStateSchema, type Machine as MachineType, type MakeConfig, MissingMatchHandlerError, MissingSchemaError, type PersistOptions, type PersistedEvent, type PersistenceAdapter, PersistenceAdapterTag, type PersistenceConfig, PersistenceError, type PersistentActorRef, type PersistentMachine, type ProcessEventResult, type ProvideHandlers, ProvisionValidationError, type RestoreFailure, type RestoreResult, type SimulationResult, Slot, type EffectHandlers as SlotEffectHandlers, type EffectSlot as SlotEffectSlot, SlotProvisionError, type Snapshot, type SpawnEffect, type SpawnEvent, State, type StateHandlerContext, type StopEvent, type SystemEvent, type SystemEventListener, type TaskEvent, type TaskOptions, type TestHarness, type TestHarnessOptions, type TracingInspectorOptions, type Transition, type TransitionEvent, UnprovidedSlotsError, VersionConflictError, assertNeverReaches, assertPath, assertReaches, collectingInspector, combineInspectors, consoleInspector, createPersistentActor, createTestHarness, isPersistentMachine, makeInMemoryPersistenceAdapter, makeInspector, makeInspectorEffect, restorePersistentActor, simulate, tracingInspector };
|
package/dist/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, combineInspectors, consoleInspector, createPersistentActor, createTestHarness, isPersistentMachine, makeInMemoryPersistenceAdapter, makeInspector, makeInspectorEffect, restorePersistentActor, simulate, tracingInspector };
|
|
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, combineInspectors, consoleInspector, createPersistentActor, createTestHarness, isPersistentMachine, makeInMemoryPersistenceAdapter, makeInspector, makeInspectorEffect, restorePersistentActor, simulate, tracingInspector };
|
package/dist/inspection.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Effect, Option, ServiceMap } from "effect";
|
|
2
|
-
|
|
3
2
|
//#region src/inspection.ts
|
|
4
3
|
/**
|
|
5
4
|
* Inspector service tag - optional service for machine introspection
|
|
@@ -139,6 +138,5 @@ const consoleInspector = () => makeInspector((event) => {
|
|
|
139
138
|
const collectingInspector = (events) => ({ onInspect: (event) => {
|
|
140
139
|
events.push(event);
|
|
141
140
|
} });
|
|
142
|
-
|
|
143
141
|
//#endregion
|
|
144
|
-
export { Inspector, collectingInspector, combineInspectors, consoleInspector, makeInspector, makeInspectorEffect, tracingInspector };
|
|
142
|
+
export { Inspector, collectingInspector, combineInspectors, consoleInspector, makeInspector, makeInspectorEffect, tracingInspector };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Clock, Effect } from "effect";
|
|
2
|
-
|
|
3
2
|
//#region src/internal/inspection.ts
|
|
4
3
|
/**
|
|
5
4
|
* Emit an inspection event with timestamp from Clock.
|
|
@@ -17,6 +16,5 @@ const emitWithTimestamp = Effect.fn("effect-machine.emitWithTimestamp")(function
|
|
|
17
16
|
});
|
|
18
17
|
if (Effect.isEffect(result)) yield* result.pipe(Effect.catchCause(() => Effect.void));
|
|
19
18
|
});
|
|
20
|
-
|
|
21
19
|
//#endregion
|
|
22
|
-
export { emitWithTimestamp };
|
|
20
|
+
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/internal/transition.ts
|
|
6
5
|
/**
|
|
7
6
|
* Transition execution and indexing.
|
|
@@ -236,6 +235,5 @@ const findTransitions = (input, stateTag, eventTag) => {
|
|
|
236
235
|
const findSpawnEffects = (machine, stateTag) => {
|
|
237
236
|
return getIndex(machine).spawn.get(stateTag) ?? [];
|
|
238
237
|
};
|
|
239
|
-
|
|
240
238
|
//#endregion
|
|
241
|
-
export { executeTransition, findSpawnEffects, findTransitions, invalidateIndex, processEventCore, resolveTransition, runSpawnEffects, runTransitionHandler };
|
|
239
|
+
export { executeTransition, findSpawnEffects, findTransitions, invalidateIndex, processEventCore, resolveTransition, runSpawnEffects, runTransitionHandler };
|
package/dist/internal/utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Effect, Stream } from "effect";
|
|
2
|
-
|
|
3
2
|
//#region src/internal/utils.ts
|
|
4
3
|
/**
|
|
5
4
|
* Internal utilities for effect-machine.
|
|
@@ -50,6 +49,5 @@ const stubSystem = {
|
|
|
50
49
|
restoreMany: () => Effect.die("restoreMany not supported in stub system"),
|
|
51
50
|
restoreAll: () => Effect.die("restoreAll not supported in stub system")
|
|
52
51
|
};
|
|
53
|
-
|
|
54
52
|
//#endregion
|
|
55
|
-
export { INTERNAL_ENTER_EVENT, INTERNAL_INIT_EVENT, getTag, isEffect, stubSystem };
|
|
53
|
+
export { INTERNAL_ENTER_EVENT, INTERNAL_INIT_EVENT, getTag, isEffect, stubSystem };
|
package/dist/machine.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { MachineEventSchema, MachineStateSchema, VariantsUnion } from "./schema.
|
|
|
5
5
|
import { PersistenceConfig, PersistentMachine } from "./persistence/persistent-machine.js";
|
|
6
6
|
import { DuplicateActorError } from "./errors.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, Effect, Schedule, Schema, Scope, ServiceMap } from "effect";
|
|
11
10
|
|
package/dist/machine.js
CHANGED
|
@@ -8,7 +8,6 @@ import { MachineContextTag } from "./slot.js";
|
|
|
8
8
|
import { findTransitions, invalidateIndex } from "./internal/transition.js";
|
|
9
9
|
import { createActor } from "./actor.js";
|
|
10
10
|
import { Cause, Effect, Exit, Option, Scope } from "effect";
|
|
11
|
-
|
|
12
11
|
//#region src/machine.ts
|
|
13
12
|
var machine_exports = /* @__PURE__ */ __exportAll({
|
|
14
13
|
BuiltMachine: () => BuiltMachine,
|
|
@@ -344,39 +343,11 @@ var TransitionScope = class {
|
|
|
344
343
|
}
|
|
345
344
|
};
|
|
346
345
|
const make = Machine.make;
|
|
347
|
-
|
|
348
|
-
* Spawn an actor directly without ActorSystem ceremony.
|
|
349
|
-
* Accepts only `BuiltMachine` (call `.build()` first).
|
|
350
|
-
*
|
|
351
|
-
* **Single actor, no registry.** Caller manages lifetime via `actor.stop`.
|
|
352
|
-
* If a `Scope` exists in context, cleanup attaches automatically on scope close.
|
|
353
|
-
*
|
|
354
|
-
* For registry, lookup by ID, persistence, or multi-actor coordination,
|
|
355
|
-
* use `ActorSystemService` / `system.spawn` instead.
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* ```ts
|
|
359
|
-
* // Fire-and-forget — caller manages lifetime
|
|
360
|
-
* const actor = yield* Machine.spawn(machine.build());
|
|
361
|
-
* yield* actor.send(Event.Start);
|
|
362
|
-
* yield* actor.awaitFinal;
|
|
363
|
-
* yield* actor.stop;
|
|
364
|
-
*
|
|
365
|
-
* // Scope-aware — auto-cleans up on scope close
|
|
366
|
-
* yield* Effect.scoped(Effect.gen(function* () {
|
|
367
|
-
* const actor = yield* Machine.spawn(machine.build());
|
|
368
|
-
* yield* actor.send(Event.Start);
|
|
369
|
-
* // actor.stop called automatically when scope closes
|
|
370
|
-
* }));
|
|
371
|
-
* ```
|
|
372
|
-
*/
|
|
373
|
-
const spawnImpl = Effect.fn("effect-machine.spawn")(function* (built, id) {
|
|
346
|
+
const spawn = Effect.fn("effect-machine.spawn")(function* (built, id) {
|
|
374
347
|
const actor = yield* createActor(id ?? `actor-${Math.random().toString(36).slice(2)}`, built._inner);
|
|
375
348
|
const maybeScope = yield* Effect.serviceOption(Scope.Scope);
|
|
376
349
|
if (Option.isSome(maybeScope)) yield* Scope.addFinalizer(maybeScope.value, actor.stop);
|
|
377
350
|
return actor;
|
|
378
351
|
});
|
|
379
|
-
const spawn = spawnImpl;
|
|
380
|
-
|
|
381
352
|
//#endregion
|
|
382
|
-
export { BuiltMachine, Machine, findTransitions, machine_exports, make, spawn };
|
|
353
|
+
export { BuiltMachine, Machine, findTransitions, machine_exports, make, spawn };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema, ServiceMap } from "effect";
|
|
2
|
-
|
|
3
2
|
//#region src/persistence/adapter.ts
|
|
4
3
|
/**
|
|
5
4
|
* Error type for persistence operations
|
|
@@ -22,6 +21,5 @@ var VersionConflictError = class extends Schema.TaggedErrorClass()("VersionConfl
|
|
|
22
21
|
* PersistenceAdapter service tag
|
|
23
22
|
*/
|
|
24
23
|
var PersistenceAdapterTag = class extends ServiceMap.Service()("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/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 };
|
|
@@ -4,8 +4,7 @@ import { emitWithTimestamp } from "../internal/inspection.js";
|
|
|
4
4
|
import { processEventCore, resolveTransition, runSpawnEffects, runTransitionHandler } from "../internal/transition.js";
|
|
5
5
|
import { PersistenceAdapterTag } from "./adapter.js";
|
|
6
6
|
import { ActorSystem, buildActorRefCore, notifyListeners } from "../actor.js";
|
|
7
|
-
import { Cause, Clock, Effect, Exit, Fiber, Option, Queue, Ref, Schedule, Scope, SubscriptionRef } from "effect";
|
|
8
|
-
|
|
7
|
+
import { Cause, Clock, Deferred, Effect, Exit, Fiber, Option, Queue, Ref, Schedule, Scope, SubscriptionRef } from "effect";
|
|
9
8
|
//#region src/persistence/persistent-actor.ts
|
|
10
9
|
/** Get current time in milliseconds using Effect Clock */
|
|
11
10
|
const now = Clock.currentTimeMillis;
|
|
@@ -96,7 +95,7 @@ const createPersistentActor = Effect.fn("effect-machine.persistentActor.spawn")(
|
|
|
96
95
|
const self = {
|
|
97
96
|
send: Effect.fn("effect-machine.persistentActor.self.send")(function* (event) {
|
|
98
97
|
if (yield* Ref.get(stoppedRef)) return;
|
|
99
|
-
yield* Queue.offer(eventQueue, event);
|
|
98
|
+
yield* Queue.offer(eventQueue, { event });
|
|
100
99
|
}),
|
|
101
100
|
spawn: (childId, childMachine) => Effect.gen(function* () {
|
|
102
101
|
const child = yield* system.spawn(childId, childMachine).pipe(Effect.provideService(ActorSystem, system));
|
|
@@ -230,7 +229,7 @@ const persistentEventLoop = Effect.fn("effect-machine.persistentActor.eventLoop"
|
|
|
230
229
|
}))
|
|
231
230
|
};
|
|
232
231
|
while (true) {
|
|
233
|
-
const event = yield* Queue.take(eventQueue);
|
|
232
|
+
const { event, reply } = yield* Queue.take(eventQueue);
|
|
234
233
|
const currentState = yield* SubscriptionRef.get(stateRef);
|
|
235
234
|
const currentVersion = yield* Ref.get(versionRef);
|
|
236
235
|
yield* emitWithTimestamp(inspector, (timestamp) => ({
|
|
@@ -241,6 +240,7 @@ const persistentEventLoop = Effect.fn("effect-machine.persistentActor.eventLoop"
|
|
|
241
240
|
timestamp
|
|
242
241
|
}));
|
|
243
242
|
const result = yield* processEventCore(typedMachine, currentState, event, self, stateScopeRef, system, id, hooks);
|
|
243
|
+
if (reply !== void 0) yield* Deferred.succeed(reply, result);
|
|
244
244
|
if (!result.transitioned) continue;
|
|
245
245
|
const newVersion = currentVersion + 1;
|
|
246
246
|
yield* Ref.set(versionRef, newVersion);
|
|
@@ -364,6 +364,5 @@ const restorePersistentActor = Effect.fn("effect-machine.persistentActor.restore
|
|
|
364
364
|
const actor = yield* createPersistentActor(id, persistentMachine, maybeSnapshot, events);
|
|
365
365
|
return Option.some(actor);
|
|
366
366
|
});
|
|
367
|
-
|
|
368
367
|
//#endregion
|
|
369
|
-
export { createPersistentActor, restorePersistentActor };
|
|
368
|
+
export { createPersistentActor, restorePersistentActor };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { MissingSchemaError } from "../errors.js";
|
|
2
|
-
|
|
3
2
|
//#region src/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/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/schema.ts
|
|
5
4
|
/**
|
|
6
5
|
* Schema-first State/Event definitions for effect-machine.
|
|
@@ -164,6 +163,5 @@ const State = (definition) => createMachineSchema(definition);
|
|
|
164
163
|
* ```
|
|
165
164
|
*/
|
|
166
165
|
const Event = (definition) => createMachineSchema(definition);
|
|
167
|
-
|
|
168
166
|
//#endregion
|
|
169
|
-
export { Event, State };
|
|
167
|
+
export { Event, State };
|
package/dist/slot.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ServiceMap } from "effect";
|
|
2
|
-
|
|
3
2
|
//#region src/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 };
|
package/dist/testing.js
CHANGED
|
@@ -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/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 };
|
|
@@ -2,17 +2,12 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __exportAll = (all, no_symbols) => {
|
|
4
4
|
let target = {};
|
|
5
|
-
for (var name in all) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
if (!no_symbols) {
|
|
12
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
-
}
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
10
|
return target;
|
|
15
11
|
};
|
|
16
|
-
|
|
17
12
|
//#endregion
|
|
18
|
-
export { __exportAll };
|
|
13
|
+
export { __exportAll };
|
package/dist-v3/actor.js
CHANGED
|
@@ -7,7 +7,6 @@ import { emitWithTimestamp } from "./internal/inspection.js";
|
|
|
7
7
|
import { PersistenceAdapterTag, PersistenceError } from "./persistence/adapter.js";
|
|
8
8
|
import { createPersistentActor, restorePersistentActor } from "./persistence/persistent-actor.js";
|
|
9
9
|
import { Cause, Context, Deferred, Effect, Exit, Fiber, Layer, MutableHashMap, Option, PubSub, Queue, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect";
|
|
10
|
-
|
|
11
10
|
//#region src-v3/actor.ts
|
|
12
11
|
/**
|
|
13
12
|
* Actor system: spawning, lifecycle, and event processing.
|
|
@@ -454,6 +453,5 @@ const make = Effect.fn("effect-machine.actorSystem.make")(function* () {
|
|
|
454
453
|
* Default ActorSystem layer
|
|
455
454
|
*/
|
|
456
455
|
const Default = Layer.scoped(ActorSystem, make());
|
|
457
|
-
|
|
458
456
|
//#endregion
|
|
459
|
-
export { ActorSystem, Default, buildActorRefCore, createActor, notifyListeners, processEventCore, resolveTransition, runSpawnEffects };
|
|
457
|
+
export { ActorSystem, Default, buildActorRefCore, createActor, notifyListeners, processEventCore, resolveTransition, runSpawnEffects };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EffectsDef, GuardsDef } from "../slot.js";
|
|
2
2
|
import { ProcessEventHooks } from "../internal/transition.js";
|
|
3
3
|
import { Machine } from "../machine.js";
|
|
4
|
-
import "../actor.js";
|
|
5
4
|
import { Layer } from "effect";
|
|
6
5
|
import { Entity } from "@effect/cluster";
|
|
7
6
|
import { Rpc } from "@effect/rpc";
|
|
@@ -2,7 +2,6 @@ import { processEventCore, runSpawnEffects } from "../internal/transition.js";
|
|
|
2
2
|
import { ActorSystem } from "../actor.js";
|
|
3
3
|
import { Effect, Option, Queue, Ref, Scope } from "effect";
|
|
4
4
|
import { Entity } from "@effect/cluster";
|
|
5
|
-
|
|
6
5
|
//#region src-v3/cluster/entity-machine.ts
|
|
7
6
|
/**
|
|
8
7
|
* EntityMachine adapter - wires a machine to a cluster Entity layer.
|
|
@@ -75,6 +74,5 @@ const EntityMachine = { layer: (entity, machine, options) => {
|
|
|
75
74
|
});
|
|
76
75
|
return entity.toLayer(layer());
|
|
77
76
|
} };
|
|
78
|
-
|
|
79
77
|
//#endregion
|
|
80
|
-
export { EntityMachine };
|
|
78
|
+
export { EntityMachine };
|
package/dist-v3/cluster/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { MissingSchemaError } from "../errors.js";
|
|
2
2
|
import { Entity } from "@effect/cluster";
|
|
3
3
|
import { Rpc } from "@effect/rpc";
|
|
4
|
-
|
|
5
4
|
//#region src-v3/cluster/to-entity.ts
|
|
6
5
|
/**
|
|
7
6
|
* Generate Entity definition from a machine.
|
|
@@ -48,6 +47,5 @@ const toEntity = (machine, options) => {
|
|
|
48
47
|
success: stateSchema
|
|
49
48
|
}), Rpc.make("GetState", { success: stateSchema })]);
|
|
50
49
|
};
|
|
51
|
-
|
|
52
50
|
//#endregion
|
|
53
|
-
export { toEntity };
|
|
51
|
+
export { toEntity };
|
package/dist-v3/errors.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
|
|
3
2
|
//#region src-v3/errors.ts
|
|
4
3
|
/**
|
|
5
4
|
* Typed error classes for effect-machine.
|
|
@@ -33,6 +32,5 @@ var ProvisionValidationError = class extends Schema.TaggedError()("ProvisionVali
|
|
|
33
32
|
}) {};
|
|
34
33
|
/** Assertion failed in testing utilities */
|
|
35
34
|
var AssertionError = class extends Schema.TaggedError()("AssertionError", { message: Schema.String }) {};
|
|
36
|
-
|
|
37
35
|
//#endregion
|
|
38
|
-
export { AssertionError, DuplicateActorError, InvalidSchemaError, MissingMatchHandlerError, MissingSchemaError, ProvisionValidationError, SlotProvisionError, UnprovidedSlotsError };
|
|
36
|
+
export { AssertionError, DuplicateActorError, InvalidSchemaError, MissingMatchHandlerError, MissingSchemaError, ProvisionValidationError, SlotProvisionError, UnprovidedSlotsError };
|
package/dist-v3/index.d.ts
CHANGED
|
@@ -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 };
|
package/dist-v3/inspection.js
CHANGED
|
@@ -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 };
|
package/dist-v3/machine.d.ts
CHANGED
|
@@ -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
|
|
package/dist-v3/machine.js
CHANGED
|
@@ -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 };
|
package/dist-v3/testing.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/cevr/effect-machine.git"
|
|
@@ -58,17 +58,17 @@
|
|
|
58
58
|
"effect": "4.0.0-beta.35"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@changesets/changelog-github": "^0.
|
|
62
|
-
"@changesets/cli": "^2.
|
|
63
|
-
"@effect/language-service": "^0.
|
|
64
|
-
"@types/bun": "1.3.
|
|
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.
|
|
67
|
-
"effect-v3": "npm:effect@^3.
|
|
68
|
-
"lefthook": "^2.1.
|
|
69
|
-
"oxfmt": "^0.
|
|
70
|
-
"oxlint": "^1.
|
|
71
|
-
"tsdown": "^0.
|
|
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": {
|