@rxova/journey-core 0.7.0 → 1.0.0-rc.2
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/README.md +236 -105
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/journey-builder/index.d.cts +5 -0
- package/dist/journey-builder/index.d.ts +5 -0
- package/dist/journey-builder/types.d.cts +126 -0
- package/dist/journey-builder/types.d.ts +126 -0
- package/dist/journey-machine/async-state.d.cts +12 -0
- package/dist/journey-machine/async-state.d.ts +12 -0
- package/dist/journey-machine/computed.d.cts +2 -0
- package/dist/journey-machine/computed.d.ts +2 -0
- package/dist/journey-machine/controls.d.cts +17 -0
- package/dist/journey-machine/controls.d.ts +17 -0
- package/dist/journey-machine/helpers.d.cts +52 -0
- package/dist/journey-machine/helpers.d.ts +52 -0
- package/dist/journey-machine/index.d.cts +3 -0
- package/dist/journey-machine/index.d.ts +3 -0
- package/dist/journey-machine/navigation.d.cts +32 -0
- package/dist/journey-machine/navigation.d.ts +32 -0
- package/dist/journey-machine/plugin-controller.d.cts +15 -0
- package/dist/journey-machine/plugin-controller.d.ts +15 -0
- package/dist/journey-machine/resolve-journey-definition.d.cts +2 -0
- package/dist/journey-machine/resolve-journey-definition.d.ts +2 -0
- package/dist/journey-machine/runtime.d.cts +33 -0
- package/dist/journey-machine/runtime.d.ts +33 -0
- package/dist/journey-machine/send.d.cts +9 -0
- package/dist/journey-machine/send.d.ts +9 -0
- package/dist/plugins/analytics/index.cjs +2 -0
- package/dist/plugins/analytics/index.cjs.map +7 -0
- package/dist/plugins/analytics/index.d.cts +25 -0
- package/dist/plugins/analytics/index.d.ts +25 -0
- package/dist/plugins/analytics/index.js +2 -0
- package/dist/plugins/analytics/index.js.map +7 -0
- package/dist/plugins/autosave/index.cjs +2 -0
- package/dist/plugins/autosave/index.cjs.map +7 -0
- package/dist/plugins/autosave/index.d.cts +17 -0
- package/dist/plugins/autosave/index.d.ts +17 -0
- package/dist/plugins/autosave/index.js +2 -0
- package/dist/plugins/autosave/index.js.map +7 -0
- package/dist/plugins/diagnostics/diagnostics.d.cts +3 -0
- package/dist/plugins/diagnostics/diagnostics.d.ts +3 -0
- package/dist/plugins/diagnostics/index.cjs +2 -0
- package/dist/plugins/diagnostics/index.cjs.map +7 -0
- package/dist/plugins/diagnostics/index.d.cts +15 -0
- package/dist/plugins/diagnostics/index.d.ts +15 -0
- package/dist/plugins/diagnostics/index.js +2 -0
- package/dist/plugins/diagnostics/index.js.map +7 -0
- package/dist/plugins/execution-paths/execution-paths.d.cts +6 -0
- package/dist/plugins/execution-paths/execution-paths.d.ts +6 -0
- package/dist/plugins/execution-paths/index.cjs +2 -0
- package/dist/plugins/execution-paths/index.cjs.map +7 -0
- package/dist/plugins/execution-paths/index.d.cts +18 -0
- package/dist/plugins/execution-paths/index.d.ts +18 -0
- package/dist/plugins/execution-paths/index.js +2 -0
- package/dist/plugins/execution-paths/index.js.map +7 -0
- package/dist/plugins/persistence/controller.d.cts +17 -0
- package/dist/plugins/persistence/controller.d.ts +17 -0
- package/dist/plugins/persistence/index.cjs +2 -0
- package/dist/plugins/persistence/index.cjs.map +7 -0
- package/dist/plugins/persistence/index.d.cts +12 -0
- package/dist/plugins/persistence/index.d.ts +12 -0
- package/dist/plugins/persistence/index.js +2 -0
- package/dist/plugins/persistence/index.js.map +7 -0
- package/dist/plugins/replay/index.cjs +2 -0
- package/dist/plugins/replay/index.cjs.map +7 -0
- package/dist/plugins/replay/index.d.cts +27 -0
- package/dist/plugins/replay/index.d.ts +27 -0
- package/dist/plugins/replay/index.js +2 -0
- package/dist/plugins/replay/index.js.map +7 -0
- package/dist/types/analytics.types.d.cts +33 -0
- package/dist/types/analytics.types.d.ts +33 -0
- package/dist/types/autosave.types.d.cts +23 -0
- package/dist/types/autosave.types.d.ts +23 -0
- package/dist/types/diagnostics.types.d.cts +38 -0
- package/dist/types/diagnostics.types.d.ts +38 -0
- package/dist/types/index.d.cts +9 -0
- package/dist/types/index.d.ts +9 -4
- package/dist/types/journey.types.d.cts +191 -0
- package/dist/types/journey.types.d.ts +140 -167
- package/dist/types/machine.types.d.cts +104 -0
- package/dist/types/machine.types.d.ts +104 -0
- package/dist/types/observation.types.d.cts +83 -0
- package/dist/types/observation.types.d.ts +83 -0
- package/dist/types/persistence.types.d.cts +34 -0
- package/dist/types/persistence.types.d.ts +13 -20
- package/dist/types/replay.types.d.cts +35 -0
- package/dist/types/replay.types.d.ts +35 -0
- package/dist/types/transitions.types.d.cts +122 -0
- package/dist/types/transitions.types.d.ts +100 -57
- package/package.json +92 -2
- package/dist/machine-helpers.d.ts +0 -23
- package/dist/machine.d.ts +0 -11
- package/dist/persistence.d.ts +0 -17
- package/dist/transitions.d.ts +0 -62
- package/dist/types.d.ts +0 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { JourneyBuiltInFrom, JourneyEvent, JourneyFullEventType, JourneyGoToEvent, JourneyHistory, JourneyJsonObject, JourneyPayloadFor, JourneySendEvent, JourneySendResult, JourneySnapshot, JourneyTerminal } from "./journey.types";
|
|
2
|
+
type JourneyTransitionArgsBase<TContext extends JourneyJsonObject, TStepId extends string, THandlers extends Record<string, unknown>> = {
|
|
3
|
+
snapshot: JourneySnapshot<TContext, TStepId>;
|
|
4
|
+
context: Readonly<TContext>;
|
|
5
|
+
from: TStepId;
|
|
6
|
+
timeline: JourneyHistory<TStepId>["timeline"];
|
|
7
|
+
index: number;
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
handlers: THandlers;
|
|
10
|
+
};
|
|
11
|
+
type JourneyTransitionEventOfType<TStepId extends string, TEventMap extends Record<string, unknown>, TEventType extends JourneyFullEventType<TEventMap>> = TEventType extends "goToStepById" ? JourneyGoToEvent<TStepId, JourneyPayloadFor<TEventMap, "goToStepById">> : {
|
|
12
|
+
type: TEventType;
|
|
13
|
+
payload?: JourneyPayloadFor<TEventMap, TEventType>;
|
|
14
|
+
};
|
|
15
|
+
export type JourneyDispatch<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>> = (event: JourneySendEvent<TStepId, TEventMap>) => Promise<JourneySendResult<TContext, TStepId>>;
|
|
16
|
+
export type JourneyLifecycleArgs<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>> = {
|
|
17
|
+
snapshot: JourneySnapshot<TContext, TStepId>;
|
|
18
|
+
context: Readonly<TContext>;
|
|
19
|
+
from: TStepId;
|
|
20
|
+
to: TStepId | JourneyTerminal;
|
|
21
|
+
event: {
|
|
22
|
+
type: string;
|
|
23
|
+
payload?: unknown;
|
|
24
|
+
};
|
|
25
|
+
transitionId: string | null;
|
|
26
|
+
label?: string;
|
|
27
|
+
handlers: THandlers;
|
|
28
|
+
signal: AbortSignal;
|
|
29
|
+
dispatch: JourneyDispatch<TContext, TStepId, TEventMap>;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Wrap callback signatures to opt into TypeScript's bivariant parameter checking.
|
|
33
|
+
* This keeps narrow event payload handlers assignable to wider transition slots.
|
|
34
|
+
*/
|
|
35
|
+
type JourneyBivariantCallback<TArgs, TResult> = {
|
|
36
|
+
bivarianceHack(args: TArgs): TResult;
|
|
37
|
+
}["bivarianceHack"];
|
|
38
|
+
export type JourneyStepLifecycleCallback<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>> = JourneyBivariantCallback<JourneyLifecycleArgs<TContext, TStepId, TEventMap, THandlers>, void | Promise<void>>;
|
|
39
|
+
export type JourneyTransitionArgs<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransitionArgsBase<TContext, TStepId, THandlers> & {
|
|
40
|
+
event: JourneyEvent<TStepId, TEventMap>;
|
|
41
|
+
};
|
|
42
|
+
export type JourneyTransitionArgsForEvent<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>, TEventType extends JourneyFullEventType<TEventMap>> = JourneyTransitionArgsBase<TContext, TStepId, THandlers> & {
|
|
43
|
+
event: JourneyTransitionEventOfType<TStepId, TEventMap, TEventType>;
|
|
44
|
+
};
|
|
45
|
+
export type JourneyTransitionUpdateContextArgsForEvent<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, TEventType extends JourneyFullEventType<TEventMap>> = {
|
|
46
|
+
snapshot: JourneySnapshot<TContext, TStepId>;
|
|
47
|
+
context: Readonly<TContext>;
|
|
48
|
+
from: TStepId;
|
|
49
|
+
timeline: JourneyHistory<TStepId>["timeline"];
|
|
50
|
+
index: number;
|
|
51
|
+
event: JourneyTransitionEventOfType<TStepId, TEventMap, TEventType>;
|
|
52
|
+
};
|
|
53
|
+
type JourneyStepTransitionEventType<TEventMap extends Record<string, unknown>> = Exclude<JourneyFullEventType<TEventMap>, "completeJourney" | "terminateJourney" | "goToStepById">;
|
|
54
|
+
type JourneyTerminalTransitionEventType<TEventMap extends Record<string, unknown>> = Extract<JourneyFullEventType<TEventMap>, "completeJourney" | "terminateJourney">;
|
|
55
|
+
export type JourneyTransitionTarget<TStepId extends string> = TStepId | JourneyTerminal;
|
|
56
|
+
type JourneyTransitionBehavior<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>, TEventType extends JourneyFullEventType<TEventMap>> = {
|
|
57
|
+
label?: string;
|
|
58
|
+
timeoutMs?: number;
|
|
59
|
+
when?: JourneyBivariantCallback<JourneyTransitionArgsForEvent<TContext, TStepId, TEventMap, THandlers, TEventType>, boolean | Promise<boolean>>;
|
|
60
|
+
updateContext?: JourneyBivariantCallback<JourneyTransitionUpdateContextArgsForEvent<TContext, TStepId, TEventMap, TEventType>, TContext>;
|
|
61
|
+
onEnter?: JourneyStepLifecycleCallback<TContext, TStepId, TEventMap, THandlers>;
|
|
62
|
+
onLeave?: JourneyStepLifecycleCallback<TContext, TStepId, TEventMap, THandlers>;
|
|
63
|
+
};
|
|
64
|
+
type JourneyTransitionConfig<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>, TEventType extends JourneyFullEventType<TEventMap>> = JourneyTransitionBehavior<TContext, TStepId, TEventMap, THandlers, TEventType> & {
|
|
65
|
+
from: TStepId | JourneyBuiltInFrom;
|
|
66
|
+
};
|
|
67
|
+
export type JourneyStepEventTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>, TEventType extends JourneyStepTransitionEventType<TEventMap> = JourneyStepTransitionEventType<TEventMap>> = {
|
|
68
|
+
[TSelectedEvent in TEventType]: JourneyTransitionConfig<TContext, TStepId, TEventMap, THandlers, TSelectedEvent> & {
|
|
69
|
+
event: TSelectedEvent;
|
|
70
|
+
to: JourneyTransitionTarget<TStepId>;
|
|
71
|
+
};
|
|
72
|
+
}[TEventType];
|
|
73
|
+
export type JourneyTerminalTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>, TEventType extends JourneyTerminalTransitionEventType<TEventMap> = JourneyTerminalTransitionEventType<TEventMap>> = {
|
|
74
|
+
[TSelectedEvent in TEventType]: JourneyTransitionConfig<TContext, TStepId, TEventMap, THandlers, TSelectedEvent> & {
|
|
75
|
+
event: TSelectedEvent;
|
|
76
|
+
to?: never;
|
|
77
|
+
};
|
|
78
|
+
}[TEventType];
|
|
79
|
+
export type JourneyGoToStepTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransitionConfig<TContext, TStepId, TEventMap, THandlers, "goToStepById"> & {
|
|
80
|
+
event: "goToStepById";
|
|
81
|
+
to: TStepId;
|
|
82
|
+
};
|
|
83
|
+
export type JourneyTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyStepEventTransition<TContext, TStepId, TEventMap, THandlers> | JourneyTerminalTransition<TContext, TStepId, TEventMap, THandlers> | JourneyGoToStepTransition<TContext, TStepId, TEventMap, THandlers>;
|
|
84
|
+
export type JourneyResolvedTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransition<TContext, TStepId, TEventMap, THandlers> & {
|
|
85
|
+
id: string;
|
|
86
|
+
label?: string;
|
|
87
|
+
};
|
|
88
|
+
export type JourneyGlobalTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransition<TContext, TStepId, TEventMap, THandlers> & {
|
|
89
|
+
from: JourneyBuiltInFrom;
|
|
90
|
+
};
|
|
91
|
+
export type JourneyStepEventGraphEdge<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>, TEventType extends JourneyStepTransitionEventType<TEventMap> = JourneyStepTransitionEventType<TEventMap>> = {
|
|
92
|
+
[TSelectedEvent in TEventType]: JourneyTransitionBehavior<TContext, TStepId, TEventMap, THandlers, TSelectedEvent> & {
|
|
93
|
+
to: JourneyTransitionTarget<TStepId>;
|
|
94
|
+
};
|
|
95
|
+
}[TEventType];
|
|
96
|
+
export type JourneyTerminalGraphEdge<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>, TEventType extends JourneyTerminalTransitionEventType<TEventMap> = JourneyTerminalTransitionEventType<TEventMap>> = {
|
|
97
|
+
[TSelectedEvent in TEventType]: JourneyTransitionBehavior<TContext, TStepId, TEventMap, THandlers, TSelectedEvent> & {
|
|
98
|
+
to?: never;
|
|
99
|
+
};
|
|
100
|
+
}[TEventType];
|
|
101
|
+
export type JourneyGoToStepGraphEdge<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransitionBehavior<TContext, TStepId, TEventMap, THandlers, "goToStepById"> & {
|
|
102
|
+
to: TStepId;
|
|
103
|
+
};
|
|
104
|
+
export type JourneyGraphEdge<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>, TEventType extends JourneyFullEventType<TEventMap> = JourneyFullEventType<TEventMap>> = JourneyStepEventGraphEdge<TContext, TStepId, TEventMap, THandlers, Extract<TEventType, JourneyStepTransitionEventType<TEventMap>>> | JourneyTerminalGraphEdge<TContext, TStepId, TEventMap, THandlers, Extract<TEventType, JourneyTerminalTransitionEventType<TEventMap>>> | (Extract<TEventType, "goToStepById"> extends never ? never : JourneyGoToStepGraphEdge<TContext, TStepId, TEventMap, THandlers>);
|
|
105
|
+
export type JourneyTerminalTransitionShorthand<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>, TEventType extends JourneyTerminalTransitionEventType<TEventMap>> = true | readonly [] | readonly JourneyGraphEdge<TContext, TStepId, TEventMap, THandlers, TEventType>[];
|
|
106
|
+
export type JourneyStepTransitions<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = Partial<{
|
|
107
|
+
[TSelectedEvent in JourneyFullEventType<TEventMap>]: TSelectedEvent extends "completeJourney" | "terminateJourney" ? JourneyTerminalTransitionShorthand<TContext, TStepId, TEventMap, THandlers, Extract<TSelectedEvent, JourneyTerminalTransitionEventType<TEventMap>>> : readonly JourneyGraphEdge<TContext, TStepId, TEventMap, THandlers, TSelectedEvent>[];
|
|
108
|
+
}>;
|
|
109
|
+
export type JourneyGlobalKey = "global";
|
|
110
|
+
export type JourneyTransitionGraph<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = Partial<Record<TStepId, JourneyStepTransitions<TContext, TStepId, TEventMap, THandlers>>> & {
|
|
111
|
+
global?: JourneyStepTransitions<TContext, TStepId, TEventMap, THandlers>;
|
|
112
|
+
};
|
|
113
|
+
export type JourneyLinearStep<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransitionBehavior<TContext, TStepId, TEventMap, THandlers, "goToNextStep"> & {
|
|
114
|
+
step: TStepId;
|
|
115
|
+
when?: never;
|
|
116
|
+
to?: never;
|
|
117
|
+
from?: never;
|
|
118
|
+
event?: never;
|
|
119
|
+
};
|
|
120
|
+
export type JourneyLinearTransitions<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = readonly [TStepId, ...(TStepId | JourneyLinearStep<TContext, TStepId, TEventMap, THandlers>)[]];
|
|
121
|
+
export type JourneyTransitionsDefinition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyLinearTransitions<TContext, TStepId, TEventMap, THandlers> | JourneyTransitionGraph<TContext, TStepId, TEventMap, THandlers>;
|
|
122
|
+
export {};
|
|
@@ -1,79 +1,122 @@
|
|
|
1
|
-
import type { JourneyBuiltInFrom, JourneyEvent,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
context: TContext
|
|
1
|
+
import type { JourneyBuiltInFrom, JourneyEvent, JourneyFullEventType, JourneyGoToEvent, JourneyHistory, JourneyJsonObject, JourneyPayloadFor, JourneySendEvent, JourneySendResult, JourneySnapshot, JourneyTerminal } from "./journey.types";
|
|
2
|
+
type JourneyTransitionArgsBase<TContext extends JourneyJsonObject, TStepId extends string, THandlers extends Record<string, unknown>> = {
|
|
3
|
+
snapshot: JourneySnapshot<TContext, TStepId>;
|
|
4
|
+
context: Readonly<TContext>;
|
|
5
5
|
from: TStepId;
|
|
6
|
-
timeline:
|
|
6
|
+
timeline: JourneyHistory<TStepId>["timeline"];
|
|
7
7
|
index: number;
|
|
8
|
-
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
handlers: THandlers;
|
|
9
10
|
};
|
|
10
|
-
type
|
|
11
|
+
type JourneyTransitionEventOfType<TStepId extends string, TEventMap extends Record<string, unknown>, TEventType extends JourneyFullEventType<TEventMap>> = TEventType extends "goToStepById" ? JourneyGoToEvent<TStepId, JourneyPayloadFor<TEventMap, "goToStepById">> : {
|
|
11
12
|
type: TEventType;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export type
|
|
15
|
-
|
|
13
|
+
payload?: JourneyPayloadFor<TEventMap, TEventType>;
|
|
14
|
+
};
|
|
15
|
+
export type JourneyDispatch<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>> = (event: JourneySendEvent<TStepId, TEventMap>) => Promise<JourneySendResult<TContext, TStepId>>;
|
|
16
|
+
export type JourneyLifecycleArgs<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>> = {
|
|
17
|
+
snapshot: JourneySnapshot<TContext, TStepId>;
|
|
18
|
+
context: Readonly<TContext>;
|
|
19
|
+
from: TStepId;
|
|
20
|
+
to: TStepId | JourneyTerminal;
|
|
21
|
+
event: {
|
|
22
|
+
type: string;
|
|
23
|
+
payload?: unknown;
|
|
24
|
+
};
|
|
25
|
+
transitionId: string | null;
|
|
26
|
+
label?: string;
|
|
27
|
+
handlers: THandlers;
|
|
28
|
+
signal: AbortSignal;
|
|
29
|
+
dispatch: JourneyDispatch<TContext, TStepId, TEventMap>;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Wrap callback signatures to opt into TypeScript's bivariant parameter checking.
|
|
33
|
+
* This keeps narrow event payload handlers assignable to wider transition slots.
|
|
34
|
+
*/
|
|
35
|
+
type JourneyBivariantCallback<TArgs, TResult> = {
|
|
36
|
+
bivarianceHack(args: TArgs): TResult;
|
|
37
|
+
}["bivarianceHack"];
|
|
38
|
+
export type JourneyStepLifecycleCallback<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>> = JourneyBivariantCallback<JourneyLifecycleArgs<TContext, TStepId, TEventMap, THandlers>, void | Promise<void>>;
|
|
39
|
+
export type JourneyTransitionArgs<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransitionArgsBase<TContext, TStepId, THandlers> & {
|
|
40
|
+
event: JourneyEvent<TStepId, TEventMap>;
|
|
41
|
+
};
|
|
42
|
+
export type JourneyTransitionArgsForEvent<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>, TEventType extends JourneyFullEventType<TEventMap>> = JourneyTransitionArgsBase<TContext, TStepId, THandlers> & {
|
|
43
|
+
event: JourneyTransitionEventOfType<TStepId, TEventMap, TEventType>;
|
|
44
|
+
};
|
|
45
|
+
export type JourneyTransitionUpdateContextArgsForEvent<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, TEventType extends JourneyFullEventType<TEventMap>> = {
|
|
46
|
+
snapshot: JourneySnapshot<TContext, TStepId>;
|
|
47
|
+
context: Readonly<TContext>;
|
|
48
|
+
from: TStepId;
|
|
49
|
+
timeline: JourneyHistory<TStepId>["timeline"];
|
|
50
|
+
index: number;
|
|
51
|
+
event: JourneyTransitionEventOfType<TStepId, TEventMap, TEventType>;
|
|
16
52
|
};
|
|
17
|
-
type
|
|
18
|
-
|
|
53
|
+
type JourneyStepTransitionEventType<TEventMap extends Record<string, unknown>> = Exclude<JourneyFullEventType<TEventMap>, "completeJourney" | "terminateJourney" | "goToStepById">;
|
|
54
|
+
type JourneyTerminalTransitionEventType<TEventMap extends Record<string, unknown>> = Extract<JourneyFullEventType<TEventMap>, "completeJourney" | "terminateJourney">;
|
|
19
55
|
export type JourneyTransitionTarget<TStepId extends string> = TStepId | JourneyTerminal;
|
|
20
|
-
type
|
|
21
|
-
|
|
56
|
+
type JourneyTransitionBehavior<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>, TEventType extends JourneyFullEventType<TEventMap>> = {
|
|
57
|
+
label?: string;
|
|
58
|
+
timeoutMs?: number;
|
|
59
|
+
when?: JourneyBivariantCallback<JourneyTransitionArgsForEvent<TContext, TStepId, TEventMap, THandlers, TEventType>, boolean | Promise<boolean>>;
|
|
60
|
+
updateContext?: JourneyBivariantCallback<JourneyTransitionUpdateContextArgsForEvent<TContext, TStepId, TEventMap, TEventType>, TContext>;
|
|
61
|
+
onEnter?: JourneyStepLifecycleCallback<TContext, TStepId, TEventMap, THandlers>;
|
|
62
|
+
onLeave?: JourneyStepLifecycleCallback<TContext, TStepId, TEventMap, THandlers>;
|
|
63
|
+
};
|
|
64
|
+
type JourneyTransitionConfig<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>, TEventType extends JourneyFullEventType<TEventMap>> = JourneyTransitionBehavior<TContext, TStepId, TEventMap, THandlers, TEventType> & {
|
|
22
65
|
from: TStepId | JourneyBuiltInFrom;
|
|
23
|
-
when?: (args: JourneySelectedTransitionArgs<TContext, TStepId, TEventType, JourneyTransitionPayloadMap<TEventType, TPayloadMap>>) => boolean | Promise<boolean>;
|
|
24
|
-
effect?: (args: JourneySelectedTransitionArgs<TContext, TStepId, TEventType, JourneyTransitionPayloadMap<TEventType, TPayloadMap>>) => TContext | void | Promise<TContext | void>;
|
|
25
66
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
[TSelectedEvent in Exclude<TEventType, "completeJourney" | "terminateJourney">]: JourneyTransitionConfig<TContext, TStepId, TSelectedEvent, TPayloadMap> & {
|
|
67
|
+
export type JourneyStepEventTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>, TEventType extends JourneyStepTransitionEventType<TEventMap> = JourneyStepTransitionEventType<TEventMap>> = {
|
|
68
|
+
[TSelectedEvent in TEventType]: JourneyTransitionConfig<TContext, TStepId, TEventMap, THandlers, TSelectedEvent> & {
|
|
29
69
|
event: TSelectedEvent;
|
|
30
70
|
to: JourneyTransitionTarget<TStepId>;
|
|
31
71
|
};
|
|
32
|
-
}[
|
|
33
|
-
|
|
72
|
+
}[TEventType];
|
|
73
|
+
export type JourneyTerminalTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>, TEventType extends JourneyTerminalTransitionEventType<TEventMap> = JourneyTerminalTransitionEventType<TEventMap>> = {
|
|
74
|
+
[TSelectedEvent in TEventType]: JourneyTransitionConfig<TContext, TStepId, TEventMap, THandlers, TSelectedEvent> & {
|
|
34
75
|
event: TSelectedEvent;
|
|
35
76
|
to?: never;
|
|
36
77
|
};
|
|
37
|
-
}[
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
event: JourneyGoToStepByIdEventType;
|
|
78
|
+
}[TEventType];
|
|
79
|
+
export type JourneyGoToStepTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransitionConfig<TContext, TStepId, TEventMap, THandlers, "goToStepById"> & {
|
|
80
|
+
event: "goToStepById";
|
|
41
81
|
to: TStepId;
|
|
42
82
|
};
|
|
43
|
-
|
|
44
|
-
export type
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
id?: string;
|
|
48
|
-
effect?: (args: JourneySelectedTransitionArgs<TContext, TStepId, TEventType, TPayloadMap>) => TContext | void | Promise<TContext | void>;
|
|
49
|
-
};
|
|
50
|
-
/** Branch definition used by `choose(...)`. */
|
|
51
|
-
export type TransitionBranch<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>> = TransitionConfig<TContext, TStepId, TEventType, TPayloadMap> & {
|
|
52
|
-
to: JourneyTransitionTarget<TStepId>;
|
|
53
|
-
when?: (args: JourneySelectedTransitionArgs<TContext, TStepId, TEventType, TPayloadMap>) => boolean | Promise<boolean>;
|
|
83
|
+
export type JourneyTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyStepEventTransition<TContext, TStepId, TEventMap, THandlers> | JourneyTerminalTransition<TContext, TStepId, TEventMap, THandlers> | JourneyGoToStepTransition<TContext, TStepId, TEventMap, THandlers>;
|
|
84
|
+
export type JourneyResolvedTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransition<TContext, TStepId, TEventMap, THandlers> & {
|
|
85
|
+
id: string;
|
|
86
|
+
label?: string;
|
|
54
87
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
to: (to: JourneyTransitionTarget<TStepId>, config?: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap>) => TransitionBranch<TContext, TStepId, TEventType, TPayloadMap>;
|
|
88
|
+
export type JourneyGlobalTransition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransition<TContext, TStepId, TEventMap, THandlers> & {
|
|
89
|
+
from: JourneyBuiltInFrom;
|
|
58
90
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
91
|
+
export type JourneyStepEventGraphEdge<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>, TEventType extends JourneyStepTransitionEventType<TEventMap> = JourneyStepTransitionEventType<TEventMap>> = {
|
|
92
|
+
[TSelectedEvent in TEventType]: JourneyTransitionBehavior<TContext, TStepId, TEventMap, THandlers, TSelectedEvent> & {
|
|
93
|
+
to: JourneyTransitionTarget<TStepId>;
|
|
94
|
+
};
|
|
95
|
+
}[TEventType];
|
|
96
|
+
export type JourneyTerminalGraphEdge<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>, TEventType extends JourneyTerminalTransitionEventType<TEventMap> = JourneyTerminalTransitionEventType<TEventMap>> = {
|
|
97
|
+
[TSelectedEvent in TEventType]: JourneyTransitionBehavior<TContext, TStepId, TEventMap, THandlers, TSelectedEvent> & {
|
|
98
|
+
to?: never;
|
|
99
|
+
};
|
|
100
|
+
}[TEventType];
|
|
101
|
+
export type JourneyGoToStepGraphEdge<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransitionBehavior<TContext, TStepId, TEventMap, THandlers, "goToStepById"> & {
|
|
102
|
+
to: TStepId;
|
|
65
103
|
};
|
|
66
|
-
|
|
67
|
-
export type
|
|
68
|
-
|
|
104
|
+
export type JourneyGraphEdge<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>, TEventType extends JourneyFullEventType<TEventMap> = JourneyFullEventType<TEventMap>> = JourneyStepEventGraphEdge<TContext, TStepId, TEventMap, THandlers, Extract<TEventType, JourneyStepTransitionEventType<TEventMap>>> | JourneyTerminalGraphEdge<TContext, TStepId, TEventMap, THandlers, Extract<TEventType, JourneyTerminalTransitionEventType<TEventMap>>> | (Extract<TEventType, "goToStepById"> extends never ? never : JourneyGoToStepGraphEdge<TContext, TStepId, TEventMap, THandlers>);
|
|
105
|
+
export type JourneyTerminalTransitionShorthand<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown>, THandlers extends Record<string, unknown>, TEventType extends JourneyTerminalTransitionEventType<TEventMap>> = true | readonly [] | readonly JourneyGraphEdge<TContext, TStepId, TEventMap, THandlers, TEventType>[];
|
|
106
|
+
export type JourneyStepTransitions<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = Partial<{
|
|
107
|
+
[TSelectedEvent in JourneyFullEventType<TEventMap>]: TSelectedEvent extends "completeJourney" | "terminateJourney" ? JourneyTerminalTransitionShorthand<TContext, TStepId, TEventMap, THandlers, Extract<TSelectedEvent, JourneyTerminalTransitionEventType<TEventMap>>> : readonly JourneyGraphEdge<TContext, TStepId, TEventMap, THandlers, TSelectedEvent>[];
|
|
108
|
+
}>;
|
|
109
|
+
export type JourneyGlobalKey = "global";
|
|
110
|
+
export type JourneyTransitionGraph<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = Partial<Record<TStepId, JourneyStepTransitions<TContext, TStepId, TEventMap, THandlers>>> & {
|
|
111
|
+
global?: JourneyStepTransitions<TContext, TStepId, TEventMap, THandlers>;
|
|
69
112
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
113
|
+
export type JourneyLinearStep<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyTransitionBehavior<TContext, TStepId, TEventMap, THandlers, "goToNextStep"> & {
|
|
114
|
+
step: TStepId;
|
|
115
|
+
when?: never;
|
|
116
|
+
to?: never;
|
|
117
|
+
from?: never;
|
|
118
|
+
event?: never;
|
|
73
119
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* terminal events expose terminal-only helpers, other events expose `to/choose`.
|
|
77
|
-
*/
|
|
78
|
-
export type EventBuilder<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>> = TEventType extends "completeJourney" ? CompleteJourneyEventBuilder<TContext, TStepId, TEventType, TPayloadMap> : TEventType extends "terminateJourney" ? TerminateJourneyEventBuilder<TContext, TStepId, TEventType, TPayloadMap> : StandardEventBuilder<TContext, TStepId, TEventType, TPayloadMap>;
|
|
120
|
+
export type JourneyLinearTransitions<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = readonly [TStepId, ...(TStepId | JourneyLinearStep<TContext, TStepId, TEventMap, THandlers>)[]];
|
|
121
|
+
export type JourneyTransitionsDefinition<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, THandlers extends Record<string, unknown> = Record<never, never>> = JourneyLinearTransitions<TContext, TStepId, TEventMap, THandlers> | JourneyTransitionGraph<TContext, TStepId, TEventMap, THandlers>;
|
|
79
122
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxova/journey-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
4
|
"description": "Journey core state machine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"journey",
|
|
@@ -39,6 +39,54 @@
|
|
|
39
39
|
},
|
|
40
40
|
"import": "./dist/index.js",
|
|
41
41
|
"require": "./dist/index.cjs"
|
|
42
|
+
},
|
|
43
|
+
"./analytics": {
|
|
44
|
+
"types": {
|
|
45
|
+
"import": "./dist/plugins/analytics/index.d.ts",
|
|
46
|
+
"require": "./dist/plugins/analytics/index.d.cts"
|
|
47
|
+
},
|
|
48
|
+
"import": "./dist/plugins/analytics/index.js",
|
|
49
|
+
"require": "./dist/plugins/analytics/index.cjs"
|
|
50
|
+
},
|
|
51
|
+
"./autosave": {
|
|
52
|
+
"types": {
|
|
53
|
+
"import": "./dist/plugins/autosave/index.d.ts",
|
|
54
|
+
"require": "./dist/plugins/autosave/index.d.cts"
|
|
55
|
+
},
|
|
56
|
+
"import": "./dist/plugins/autosave/index.js",
|
|
57
|
+
"require": "./dist/plugins/autosave/index.cjs"
|
|
58
|
+
},
|
|
59
|
+
"./diagnostics": {
|
|
60
|
+
"types": {
|
|
61
|
+
"import": "./dist/plugins/diagnostics/index.d.ts",
|
|
62
|
+
"require": "./dist/plugins/diagnostics/index.d.cts"
|
|
63
|
+
},
|
|
64
|
+
"import": "./dist/plugins/diagnostics/index.js",
|
|
65
|
+
"require": "./dist/plugins/diagnostics/index.cjs"
|
|
66
|
+
},
|
|
67
|
+
"./persistence": {
|
|
68
|
+
"types": {
|
|
69
|
+
"import": "./dist/plugins/persistence/index.d.ts",
|
|
70
|
+
"require": "./dist/plugins/persistence/index.d.cts"
|
|
71
|
+
},
|
|
72
|
+
"import": "./dist/plugins/persistence/index.js",
|
|
73
|
+
"require": "./dist/plugins/persistence/index.cjs"
|
|
74
|
+
},
|
|
75
|
+
"./replay": {
|
|
76
|
+
"types": {
|
|
77
|
+
"import": "./dist/plugins/replay/index.d.ts",
|
|
78
|
+
"require": "./dist/plugins/replay/index.d.cts"
|
|
79
|
+
},
|
|
80
|
+
"import": "./dist/plugins/replay/index.js",
|
|
81
|
+
"require": "./dist/plugins/replay/index.cjs"
|
|
82
|
+
},
|
|
83
|
+
"./execution-paths": {
|
|
84
|
+
"types": {
|
|
85
|
+
"import": "./dist/plugins/execution-paths/index.d.ts",
|
|
86
|
+
"require": "./dist/plugins/execution-paths/index.d.cts"
|
|
87
|
+
},
|
|
88
|
+
"import": "./dist/plugins/execution-paths/index.js",
|
|
89
|
+
"require": "./dist/plugins/execution-paths/index.cjs"
|
|
42
90
|
}
|
|
43
91
|
},
|
|
44
92
|
"files": [
|
|
@@ -52,7 +100,49 @@
|
|
|
52
100
|
"name": "core/createJourneyMachine",
|
|
53
101
|
"path": "dist/index.js",
|
|
54
102
|
"import": "{ createJourneyMachine }",
|
|
55
|
-
"limit": "
|
|
103
|
+
"limit": "7.9 kB"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"name": "core/createJourneyBuilder",
|
|
107
|
+
"path": "dist/index.js",
|
|
108
|
+
"import": "{ createJourneyBuilder }",
|
|
109
|
+
"limit": "1 kB"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "core/createPersistencePlugin",
|
|
113
|
+
"path": "dist/plugins/persistence/index.js",
|
|
114
|
+
"import": "{ createPersistencePlugin }",
|
|
115
|
+
"limit": "3 kB"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"name": "core/createAnalyticsPlugin",
|
|
119
|
+
"path": "dist/plugins/analytics/index.js",
|
|
120
|
+
"import": "{ createAnalyticsPlugin }",
|
|
121
|
+
"limit": "2 kB"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"name": "core/createAutosavePlugin",
|
|
125
|
+
"path": "dist/plugins/autosave/index.js",
|
|
126
|
+
"import": "{ createAutosavePlugin }",
|
|
127
|
+
"limit": "3.5 kB"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"name": "core/createDiagnosticsPlugin",
|
|
131
|
+
"path": "dist/plugins/diagnostics/index.js",
|
|
132
|
+
"import": "{ createDiagnosticsPlugin }",
|
|
133
|
+
"limit": "2.6 kB"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"name": "core/createExecutionPathsPlugin",
|
|
137
|
+
"path": "dist/plugins/execution-paths/index.js",
|
|
138
|
+
"import": "{ createExecutionPathsPlugin }",
|
|
139
|
+
"limit": "2 kB"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"name": "core/createReplayPlugin",
|
|
143
|
+
"path": "dist/plugins/replay/index.js",
|
|
144
|
+
"import": "{ createReplayPlugin }",
|
|
145
|
+
"limit": "2 kB"
|
|
56
146
|
}
|
|
57
147
|
],
|
|
58
148
|
"scripts": {
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { JourneyAsyncState, JourneyEvent, JourneyEventPayloadMap, JourneyGoToEvent, JourneyGoToStepByIdEventType, JourneyMachineEventType, JourneyMachinePayloadMap, JourneyPayloadFor, JourneySendEvent, JourneySendResult, JourneySnapshot, JourneyStatus, JourneyStepAsyncState, JourneyTerminal, JourneyTransition } from "./types";
|
|
2
|
-
export declare const assertStepExists: <TStepId extends string>(steps: Record<TStepId, unknown>, stepId: TStepId, message: string) => void;
|
|
3
|
-
export declare const normalizeStepCount: (steps?: number) => number;
|
|
4
|
-
export declare const now: () => number;
|
|
5
|
-
export declare const buildVisitedFromTimeline: <TStepId extends string>(timeline: readonly TStepId[], stepIds?: readonly TStepId[]) => Record<TStepId, boolean>;
|
|
6
|
-
export declare const appendVisited: <TStepId extends string>(visited: Record<TStepId, boolean>, current: TStepId) => Record<TStepId, boolean>;
|
|
7
|
-
export declare const isPromiseLike: <T>(value: T | PromiseLike<T>) => value is PromiseLike<T>;
|
|
8
|
-
export declare const buildIdleStepAsyncState: () => JourneyStepAsyncState;
|
|
9
|
-
export declare const buildInitialAsyncState: <TStepId extends string>(steps: Record<TStepId, unknown>) => JourneyAsyncState<TStepId>;
|
|
10
|
-
export declare const isGoToStepByIdEvent: <TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>>(event: JourneySendEvent<TStepId, TEventType, TPayloadMap>) => event is JourneyGoToEvent<TStepId, JourneyPayloadFor<JourneyMachineEventType<TEventType>, JourneyMachinePayloadMap<TEventType, TPayloadMap>, JourneyGoToStepByIdEventType>>;
|
|
11
|
-
export declare const isTerminalTarget: <TStepId extends string>(target: TStepId | JourneyTerminal) => target is JourneyTerminal;
|
|
12
|
-
export declare const validateJourneyTransitions: <TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>>(transitions: readonly JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[], steps: Record<TStepId, unknown>) => void;
|
|
13
|
-
export declare const buildSendResult: <TContext, TStepId extends string, TStepMeta>(snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>, transitioned: boolean, options?: {
|
|
14
|
-
transitionId?: string;
|
|
15
|
-
error?: unknown;
|
|
16
|
-
}) => JourneySendResult<TContext, TStepId, TStepMeta>;
|
|
17
|
-
export declare const buildSnapshot: <TContext, TStepId extends string, TStepMeta>(timeline: readonly TStepId[], index: number, context: TContext, status: JourneyStatus, asyncState: JourneyAsyncState<TStepId>, stepMeta: Record<TStepId, TStepMeta>, visited?: Record<TStepId, boolean>) => JourneySnapshot<TContext, TStepId, TStepMeta>;
|
|
18
|
-
export declare const selectTransition: <TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>, TStepMeta>(transitions: readonly JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[], snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>, event: JourneyEvent<TStepId, TEventType, TPayloadMap>, hooks?: {
|
|
19
|
-
onAsyncGuardStart?: (transition: JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>) => void;
|
|
20
|
-
onAsyncGuardSuccess?: (transition: JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>) => void;
|
|
21
|
-
onAsyncGuardError?: (transition: JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>, error: unknown) => void;
|
|
22
|
-
}) => Promise<JourneyTransition<TContext, TStepId, TEventType, TPayloadMap> | null>;
|
|
23
|
-
export declare const transitionSnapshot: <TContext, TStepId extends string, TStepMeta>(snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>, nextCurrent: TStepId, nextContext: TContext) => JourneySnapshot<TContext, TStepId, TStepMeta>;
|
package/dist/machine.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { JourneyDefaultEventType, JourneyDefinition, JourneyEventPayloadMap, JourneyMachine, JourneyMachineOptions, JourneyStepDefinition, JourneyTransition } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Creates a journey machine from a journey definition.
|
|
4
|
-
* Validates steps/transitions, hydrates persisted state (if configured),
|
|
5
|
-
* and returns an API for sending events and reading snapshots.
|
|
6
|
-
*/
|
|
7
|
-
export declare function createJourneyMachine<TContext, TStepMeta = unknown, TSteps extends Record<string, JourneyStepDefinition<TStepMeta>> = Record<string, JourneyStepDefinition<TStepMeta>>, TPayloadMap extends JourneyEventPayloadMap<JourneyDefaultEventType> = Record<never, never>>(journey: JourneyDefinition<TContext, Extract<keyof TSteps, string>, JourneyDefaultEventType, TPayloadMap, TStepMeta> & {
|
|
8
|
-
steps: TSteps;
|
|
9
|
-
transitions: readonly JourneyTransition<TContext, Extract<keyof TSteps, string>, JourneyDefaultEventType, TPayloadMap>[];
|
|
10
|
-
}, options?: JourneyMachineOptions<TContext, Extract<keyof TSteps, string>, TStepMeta>): JourneyMachine<TContext, Extract<keyof TSteps, string>, JourneyDefaultEventType, TPayloadMap, TStepMeta>;
|
|
11
|
-
export declare function createJourneyMachine<TContext, TStepId extends string, TEventType extends string = JourneyDefaultEventType, TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>, TStepMeta = unknown>(journey: JourneyDefinition<TContext, TStepId, TEventType, TPayloadMap, TStepMeta>, options?: JourneyMachineOptions<TContext, TStepId, TStepMeta>): JourneyMachine<TContext, TStepId, TEventType, TPayloadMap, TStepMeta>;
|
package/dist/persistence.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { JourneyMachineOptions, JourneySnapshot } from "./types/journey.types";
|
|
2
|
-
/**
|
|
3
|
-
* Creates a persistence controller for snapshots, including hydration,
|
|
4
|
-
* serialization, and storage error handling.
|
|
5
|
-
*/
|
|
6
|
-
export declare const createPersistenceController: <TContext, TStepId extends string, TStepMeta>(args: {
|
|
7
|
-
initial: TStepId;
|
|
8
|
-
context: TContext;
|
|
9
|
-
stepMeta: Record<TStepId, TStepMeta>;
|
|
10
|
-
steps: Record<TStepId, unknown>;
|
|
11
|
-
options?: JourneyMachineOptions<TContext, TStepId, TStepMeta>;
|
|
12
|
-
}) => {
|
|
13
|
-
clearOnReset: boolean;
|
|
14
|
-
hydrateSnapshot: () => JourneySnapshot<TContext, TStepId, TStepMeta>;
|
|
15
|
-
persistSnapshot: (snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>) => void;
|
|
16
|
-
removePersistedSnapshot: () => void;
|
|
17
|
-
};
|
package/dist/transitions.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { JourneyEventPayloadMap } from "./types/journey.types";
|
|
2
|
-
import type { EventBuilder, JourneyTransition, JourneySelectedTransitionArgs, JourneyTransitionTarget, TransitionBranch, TransitionConfig } from "./types/transitions.types";
|
|
3
|
-
type TransitionPayloadMap = Partial<Record<string, unknown>>;
|
|
4
|
-
type SelectedPayloadMap<TEventType extends string, TPayloadMap extends TransitionPayloadMap> = TPayloadMap & JourneyEventPayloadMap<TEventType>;
|
|
5
|
-
/**
|
|
6
|
-
* Fluent helpers for building journey transitions with type-safe branches.
|
|
7
|
-
*/
|
|
8
|
-
export declare const tx: {
|
|
9
|
-
from: <TStepId extends string, TContext = unknown, TPayloadMap extends TransitionPayloadMap = Record<never, never>>(from: TStepId) => {
|
|
10
|
-
on: <TEventType extends string>(event: TEventType) => EventBuilder<TContext, TStepId, TEventType, SelectedPayloadMap<TEventType, TPayloadMap>>;
|
|
11
|
-
toComplete: (config?: TransitionConfig<TContext, TStepId, "completeJourney", SelectedPayloadMap<"completeJourney", TPayloadMap>>) => {
|
|
12
|
-
id?: string;
|
|
13
|
-
from: "*" | TStepId;
|
|
14
|
-
when?: (args: JourneySelectedTransitionArgs<TContext, TStepId, "completeJourney", TPayloadMap & Partial<Record<"goToStepById" | "completeJourney", unknown>>>) => boolean | Promise<boolean>;
|
|
15
|
-
effect?: (args: JourneySelectedTransitionArgs<TContext, TStepId, "completeJourney", TPayloadMap & Partial<Record<"goToStepById" | "completeJourney", unknown>>>) => void | TContext | Promise<void | TContext>;
|
|
16
|
-
} & {
|
|
17
|
-
event: "completeJourney";
|
|
18
|
-
to?: never;
|
|
19
|
-
};
|
|
20
|
-
toTerminate: (config?: TransitionConfig<TContext, TStepId, "terminateJourney", SelectedPayloadMap<"terminateJourney", TPayloadMap>>) => {
|
|
21
|
-
id?: string;
|
|
22
|
-
from: "*" | TStepId;
|
|
23
|
-
when?: (args: JourneySelectedTransitionArgs<TContext, TStepId, "terminateJourney", TPayloadMap & Partial<Record<"goToStepById" | "terminateJourney", unknown>>>) => boolean | Promise<boolean>;
|
|
24
|
-
effect?: (args: JourneySelectedTransitionArgs<TContext, TStepId, "terminateJourney", TPayloadMap & Partial<Record<"goToStepById" | "terminateJourney", unknown>>>) => void | TContext | Promise<void | TContext>;
|
|
25
|
-
} & {
|
|
26
|
-
event: "terminateJourney";
|
|
27
|
-
to?: never;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
any: <TContext = unknown, TStepId extends string = string, TPayloadMap extends TransitionPayloadMap = Record<never, never>>() => {
|
|
31
|
-
on: <TEventType extends string>(event: TEventType) => EventBuilder<TContext, TStepId, TEventType, SelectedPayloadMap<TEventType, TPayloadMap>>;
|
|
32
|
-
toComplete: (config?: TransitionConfig<TContext, TStepId, "completeJourney", SelectedPayloadMap<"completeJourney", TPayloadMap>>) => {
|
|
33
|
-
id?: string;
|
|
34
|
-
from: "*" | TStepId;
|
|
35
|
-
when?: (args: JourneySelectedTransitionArgs<TContext, TStepId, "completeJourney", TPayloadMap & Partial<Record<"goToStepById" | "completeJourney", unknown>>>) => boolean | Promise<boolean>;
|
|
36
|
-
effect?: (args: JourneySelectedTransitionArgs<TContext, TStepId, "completeJourney", TPayloadMap & Partial<Record<"goToStepById" | "completeJourney", unknown>>>) => void | TContext | Promise<void | TContext>;
|
|
37
|
-
} & {
|
|
38
|
-
event: "completeJourney";
|
|
39
|
-
to?: never;
|
|
40
|
-
};
|
|
41
|
-
toTerminate: (config?: TransitionConfig<TContext, TStepId, "terminateJourney", SelectedPayloadMap<"terminateJourney", TPayloadMap>>) => {
|
|
42
|
-
id?: string;
|
|
43
|
-
from: "*" | TStepId;
|
|
44
|
-
when?: (args: JourneySelectedTransitionArgs<TContext, TStepId, "terminateJourney", TPayloadMap & Partial<Record<"goToStepById" | "terminateJourney", unknown>>>) => boolean | Promise<boolean>;
|
|
45
|
-
effect?: (args: JourneySelectedTransitionArgs<TContext, TStepId, "terminateJourney", TPayloadMap & Partial<Record<"goToStepById" | "terminateJourney", unknown>>>) => void | TContext | Promise<void | TContext>;
|
|
46
|
-
} & {
|
|
47
|
-
event: "terminateJourney";
|
|
48
|
-
to?: never;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
when: <TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>>(predicate: (args: JourneySelectedTransitionArgs<TContext, TStepId, TEventType, TPayloadMap>) => boolean | Promise<boolean>) => {
|
|
52
|
-
to: (to: JourneyTransitionTarget<TStepId>, config?: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap>) => TransitionBranch<TContext, TStepId, TEventType, TPayloadMap>;
|
|
53
|
-
};
|
|
54
|
-
otherwise: <TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>>() => {
|
|
55
|
-
to: (to: JourneyTransitionTarget<TStepId>, config?: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap>) => TransitionBranch<TContext, TStepId, TEventType, TPayloadMap>;
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Flattens transition items and transition arrays into a single transition list.
|
|
60
|
-
*/
|
|
61
|
-
export declare const createTransitions: <TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>>(...items: Array<JourneyTransition<TContext, TStepId, TEventType, TPayloadMap> | readonly JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[]>) => JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[];
|
|
62
|
-
export {};
|
package/dist/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./types/index";
|