@rxova/journey-core 0.6.1 → 0.6.3

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.
@@ -1,4 +1,5 @@
1
- import type { JOURNEY_EVENT, JourneyBuiltInFrom, JourneyEvent, JourneyEventPayloadMap, JourneyTerminal } from "./journey.types";
1
+ import type { JourneyBuiltInFrom, JourneyEvent, JourneyEventPayloadMap, JourneyGoToStepByIdEventType, JourneyTerminal } from "./journey.types";
2
+ /** Arguments passed to transition guards and effects. */
2
3
  export type JourneyTransitionArgs<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>> = {
3
4
  context: TContext;
4
5
  from: TStepId;
@@ -6,6 +7,7 @@ export type JourneyTransitionArgs<TContext, TStepId extends string, TEventType e
6
7
  index: number;
7
8
  event: JourneyEvent<TStepId, TEventType, TPayloadMap>;
8
9
  };
10
+ /** Transition destination, either another step or a terminal machine state. */
9
11
  export type JourneyTransitionTarget<TStepId extends string> = TStepId | JourneyTerminal;
10
12
  type JourneyTransitionConfig<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>> = {
11
13
  id?: string;
@@ -13,6 +15,7 @@ type JourneyTransitionConfig<TContext, TStepId extends string, TEventType extend
13
15
  when?: (args: JourneyTransitionArgs<TContext, TStepId, TEventType, TPayloadMap>) => boolean | Promise<boolean>;
14
16
  effect?: (args: JourneyTransitionArgs<TContext, TStepId, TEventType, TPayloadMap>) => TContext | void | Promise<TContext | void>;
15
17
  };
18
+ /** Transition declared for a standard event or terminal event. */
16
19
  export type JourneyEventTransition<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>> = (JourneyTransitionConfig<TContext, TStepId, TEventType, TPayloadMap> & {
17
20
  event: Exclude<TEventType, "completeJourney" | "terminateJourney">;
18
21
  to: JourneyTransitionTarget<TStepId>;
@@ -20,28 +23,39 @@ export type JourneyEventTransition<TContext, TStepId extends string, TEventType
20
23
  event: Extract<TEventType, "completeJourney" | "terminateJourney">;
21
24
  to?: never;
22
25
  });
26
+ /** Direct jump transition triggered by the built-in `goToStepById` event. */
23
27
  export type JourneyGoToStepTransition<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>> = JourneyTransitionConfig<TContext, TStepId, TEventType, TPayloadMap> & {
24
- event: (typeof JOURNEY_EVENT)["GO_TO_STEP_BY_ID"];
28
+ event: JourneyGoToStepByIdEventType;
25
29
  to: TStepId;
26
30
  };
31
+ /** Any transition shape accepted by `createJourneyMachine`. */
27
32
  export type JourneyTransition<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>> = JourneyEventTransition<TContext, TStepId, TEventType, TPayloadMap> | JourneyGoToStepTransition<TContext, TStepId, TEventType, TPayloadMap>;
33
+ /** Optional transition behavior shared by direct and branch transitions. */
28
34
  export type TransitionConfig<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>> = {
29
35
  id?: string;
30
36
  effect?: (args: JourneyTransitionArgs<TContext, TStepId, TEventType, TPayloadMap>) => TContext | void | Promise<TContext | void>;
31
37
  };
38
+ /** Branch definition used by `choose(...)`. */
32
39
  export type TransitionBranch<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>> = TransitionConfig<TContext, TStepId, TEventType, TPayloadMap> & {
33
40
  to: JourneyTransitionTarget<TStepId>;
34
41
  when?: (args: JourneyTransitionArgs<TContext, TStepId, TEventType, TPayloadMap>) => boolean | Promise<boolean>;
35
42
  };
43
+ /** Builder returned by `tx.from(...).on(nonTerminalEvent)` and `tx.any().on(...)`. */
36
44
  export type StandardEventBuilder<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>> = {
37
45
  to: (to: JourneyTransitionTarget<TStepId>, config?: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap>) => JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>;
38
46
  choose: (...branches: Array<TransitionBranch<TContext, TStepId, TEventType, TPayloadMap>>) => JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[];
39
47
  };
48
+ /** Builder returned by `tx.from(...).on("completeJourney")`. */
40
49
  export type CompleteJourneyEventBuilder<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>> = {
41
50
  complete: (config?: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap>) => JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>;
42
51
  };
52
+ /** Builder returned by `tx.from(...).on("terminateJourney")`. */
43
53
  export type TerminateJourneyEventBuilder<TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>> = {
44
54
  terminate: (config?: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap>) => JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>;
45
55
  };
56
+ /**
57
+ * Conditional transition builder returned by `tx.from(...).on(event)`:
58
+ * terminal events expose terminal-only helpers, other events expose `to/choose`.
59
+ */
46
60
  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>;
47
61
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxova/journey-core",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Journey core state machine.",
5
5
  "keywords": [
6
6
  "journey",
@@ -57,7 +57,7 @@
57
57
  ],
58
58
  "scripts": {
59
59
  "build": "pnpm run clean && node ./scripts/build.mjs && tsc -p tsconfig.build.json && node ../../scripts/copy-types.mjs dist",
60
- "clean": "rm -rf dist tsconfig.build.tsbuildinfo",
60
+ "clean": "node ../../scripts/clean-paths.mjs dist tsconfig.build.tsbuildinfo",
61
61
  "coverage": "pnpm --workspace-root vitest run --coverage --coverage.include=packages/core/src/** --coverage.reporter=text-summary",
62
62
  "typecheck": "tsc --noEmit -p tsconfig.json",
63
63
  "publint": "publint",