@rxova/journey-core 0.3.0 → 0.5.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/README.md CHANGED
@@ -1,137 +1,60 @@
1
1
  # @rxova/journey-core
2
2
 
3
- The core Journey state machine for non-React environments. Use this package if you want the smallest, framework-agnostic runtime.
3
+ Headless runtime for non-linear journeys.
4
4
 
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- pnpm add @rxova/journey-core
9
- npm install @rxova/journey-core
10
- yarn add @rxova/journey-core
8
+ npm i @rxova/journey-core
11
9
  ```
12
10
 
13
- ## Basic usage
11
+ ## What You Get
12
+
13
+ - Deterministic transition matching (first match wins).
14
+ - Timeline + pointer navigation model.
15
+ - Built-in `goToNextStep()`, `terminateJourney()`, `completeJourney()`, `goToPreviousStep()`, and `goToLastVisitedStep()`.
16
+ - Typed observability stream via `subscribeEvent`.
17
+ - Step metadata updates via `updateStepMetadata`.
18
+ - Optional persistence helpers.
19
+
20
+ ## Quickstart
14
21
 
15
22
  ```ts
16
- import {
17
- createJourneyMachine,
18
- JOURNEY_TERMINAL,
19
- type JourneyDefinition
20
- } from "@rxova/journey-core";
23
+ import { createJourneyMachine } from "@rxova/journey-core";
21
24
 
22
- type StepId = "one" | "two" | "three";
23
- type Event = "next" | "submit";
25
+ type StepId = "start" | "review";
26
+ type Event = "goToNextStep" | "completeJourney" | "back";
24
27
  type Ctx = { name: string };
25
28
 
26
- const journey: JourneyDefinition<Ctx, StepId, Event> = {
27
- initial: "one",
29
+ const journey = {
30
+ initial: "start",
28
31
  context: { name: "" },
29
32
  steps: {
30
- one: {},
31
- two: {},
32
- three: {}
33
+ start: { meta: { label: "Start" } },
34
+ review: { meta: { label: "Review" } }
33
35
  },
34
36
  transitions: [
35
- { from: "one", event: "next", to: "two" },
36
- { from: "two", event: "next", to: "three" },
37
- { from: "three", event: "submit", to: JOURNEY_TERMINAL.COMPLETE }
37
+ { from: "start", event: "goToNextStep", to: "review" },
38
+ { from: "review", event: "completeJourney" }
38
39
  ]
39
40
  };
40
41
 
41
42
  const machine = createJourneyMachine<Ctx, StepId, Event>(journey);
42
- ```
43
-
44
- ## History behavior
45
-
46
- The machine tracks two related collections:
47
-
48
- - `history`: ordered list of prior steps. It grows when you move to a different step.
49
- - `visited`: list of steps you have reached (including current), with duplicates removed. It is not affected by history trimming.
50
-
51
- Why `visited` is a list (not a `Set`) for the following reasons:
52
-
53
- - JSON-friendly for snapshots, logs, and persistence.
54
- - Deterministic order for tests and UI rendering.
55
- - Easier to consume in TypeScript (`readonly TStepId[]`).
56
- - It is derived from `history + current` initially, then maintained independently so trimming history does not remove earlier entries.
57
-
58
- History is used when you target `HISTORY_TARGET` in a transition. It resolves to the most recent valid step in `history`. If history is empty (or contains invalid steps), the machine stays on the current step.
59
-
60
- ### History retention
61
-
62
- You can cap history growth with `maxHistory`. When the history exceeds that limit, the oldest entries are trimmed.
63
-
64
- Defaults:
65
-
66
- - `maxHistory`: `50`
67
- - `maxHistory: null` disables trimming entirely.
68
-
69
- Automatic trimming happens:
70
-
71
- - After transitions (including `goTo`)
72
- - After persistence hydrate
73
-
74
- ### Overflow callback
75
-
76
- `onOverflow` fires only when trimming actually happens. It receives:
43
+ await machine.goToNextStep();
44
+ await machine.goToPreviousStep();
45
+ await machine.completeJourney();
77
46
 
78
- - `previous`: history before trimming
79
- - `next`: history after trimming
80
- - `trimmed`: entries removed
81
- - `maxHistory`: resolved limit (number or `null`)
82
- - `reason`: `"auto" | "hydrate" | "manual"`
83
- - `auto`: trimming happened automatically during a transition (including `goTo`)
84
- - `hydrate`: trimming happened right after loading persisted state
85
- - `manual`: trimming happened because you called `trimHistory()`
86
-
87
- ### Config example
88
-
89
- ```ts
90
- const machine = createJourneyMachine(journey, {
91
- history: {
92
- maxHistory: 20,
93
- onOverflow: ({ trimmed, reason }) => {
94
- console.warn("trimmed history", trimmed, "reason:", reason);
95
- }
96
- }
97
- });
47
+ const snapshot = machine.getSnapshot();
48
+ console.log(snapshot.history.timeline, snapshot.history.index, snapshot.currentStepId);
98
49
  ```
99
50
 
100
- ### History target example
51
+ ## Transition Ergonomics
101
52
 
102
53
  ```ts
103
- import { HISTORY_TARGET } from "@rxova/journey-core";
54
+ import { createTransitions, tx } from "@rxova/journey-core";
104
55
 
105
- const journey: JourneyDefinition<Ctx, StepId, Event> = {
106
- initial: "one",
107
- context: { name: "" },
108
- steps: {
109
- one: {},
110
- two: {},
111
- three: {}
112
- },
113
- transitions: [
114
- { from: "one", event: "next", to: "two" },
115
- { from: "two", event: "next", to: "three" },
116
- { from: "*", event: "back", to: HISTORY_TARGET }
117
- ]
118
- };
56
+ const transitions = createTransitions(
57
+ tx.from("start").on("goToNextStep").to("review"),
58
+ tx.from("review").toComplete()
59
+ );
119
60
  ```
120
-
121
- ### Manual history management
122
-
123
- ```ts
124
- const machine = createJourneyMachine(journey, { history: { maxHistory: 5 } });
125
-
126
- await machine.send({ type: "goTo", to: "two" });
127
- await machine.send({ type: "goTo", to: "three" });
128
-
129
- machine.trimHistory(1); // keep most recent entry only
130
- machine.clearHistory(); // reset history to []
131
- ```
132
-
133
- ## Links
134
-
135
- - Docs: ../../docs/GETTING_STARTED.md
136
- - API: ../../docs/API.md
137
- - React bindings: ../react
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var L=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(e,n)=>{for(var s in n)L(e,s,{get:n[s],enumerable:!0})},oe=(e,n,s,y)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of ee(n))!te.call(e,r)&&r!==s&&L(e,r,{get:()=>n[r],enumerable:!(y=j(n,r))||y.enumerable});return e};var re=e=>oe(L({},"__esModule",{value:!0}),e);var ue={};ne(ue,{HISTORY_TARGET:()=>k,JOURNEY_ASYNC_PHASE:()=>g,JOURNEY_EVENT:()=>w,JOURNEY_STATUS:()=>J,JOURNEY_TERMINAL:()=>O,JOURNEY_WILDCARD:()=>A,createJourneyMachine:()=>K,createPersistenceController:()=>G});module.exports=re(ue);var O={COMPLETE:"COMPLETE",CLOSE:"CLOSE"},J={RUNNING:"running",COMPLETE:"complete",CLOSED:"closed"},k="__HISTORY__",A="*",w={GO_TO:"goTo"},g={IDLE:"idle",EVALUATING_WHEN:"evaluating-when",RUNNING_EFFECT:"running-effect",ERROR:"error"};var U=(e,n,s)=>{if(!(n in e))throw new Error(s)},se=e=>[...new Set(e)],V=(e,n)=>se([...e,n]),D=(e,n)=>e.includes(n)?[...e]:[...e,n],F=e=>typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function",H=()=>({phase:g.IDLE,eventType:null,transitionId:null,error:null}),M=e=>({isLoading:!1,byStep:Object.fromEntries(Object.keys(e).map(s=>[s,H()]))}),$=e=>e.type===w.GO_TO&&"to"in e,z=e=>e===O.COMPLETE||e===O.CLOSE,b=(e,n,s)=>s?{transitioned:n,transitionId:s,snapshot:e}:{transitioned:n,snapshot:e},h=(e,n,s,y,r,p)=>({status:y,current:e,context:n,history:s,visited:p?[...p]:V(s,e),async:r}),W=(e,n)=>{let s=[...e.history];for(;s.length>0;){let y=s.pop();if(!y)break;if(y in n)return{target:y,history:s}}return{target:e.current,history:[...e.history]}},q=async(e,n,s,y)=>{for(let r of e){let p=r.from===A||r.from===n.current,f=r.event===s.type;if(!p||!f)continue;if(!r.when)return r;let u=r.when({context:n.context,from:n.current,history:n.history,event:s}),t=F(u);t&&y?.onAsyncGuardStart?.(r);let v;try{v=await u}catch(i){throw t&&y?.onAsyncGuardError?.(r,i),i}if(t&&y?.onAsyncGuardSuccess?.(r),v)return r}return null},B=(e,n,s)=>{let y=n===e.current?[...e.history]:[...e.history,e.current],r=D(e.visited,n);return h(n,s,y,e.status,e.async,r)};var X=e=>typeof e=="object"&&e!==null,ie=e=>e===J.RUNNING||e===J.COMPLETE||e===J.CLOSED,ae=()=>{let e=globalThis.localStorage;return!e||typeof e.getItem!="function"||typeof e.setItem!="function"||typeof e.removeItem!="function"?null:e},pe=e=>{if(!e)return null;let n=e.storage??ae();return n?{key:e.key,storage:n,version:e.version??1,clearOnReset:e.clearOnReset??!0,serialize:e.serialize??JSON.stringify,deserialize:e.deserialize??JSON.parse,...e.migrate?{migrate:e.migrate}:{},...e.onError?{onError:e.onError}:{}}:null},Q=(e,n,s)=>{if(!X(e))return null;let y=e.current;if(typeof y!="string"||!(y in n))return null;let r=y,p=Array.isArray(e.history)?e.history.filter(i=>typeof i=="string"&&i in n):[],f=ie(e.status)?e.status:J.RUNNING,u=Array.isArray(e.visited)?e.visited.filter(i=>typeof i=="string"&&i in n):null,t=u&&u.length>0?u:V(p,r),v=!u||u.length===0;return{snapshot:{current:r,context:"context"in e?e.context:s,history:p,status:f,visited:t},needsRewrite:v}},G=e=>{let{initial:n,context:s,steps:y,options:r}=e,p=pe(r?.persistence),f=i=>{p?.onError?.(i)},u=i=>{if(p)try{let E={version:p.version,snapshot:{current:i.current,context:i.context,history:[...i.history],status:i.status,visited:[...i.visited]}};p.storage.setItem(p.key,p.serialize(E))}catch(E){f(E)}},t=()=>{if(p)try{p.storage.removeItem(p.key)}catch(i){f(i)}},v=()=>{let i=h(n,s,[],J.RUNNING,M(y));if(!p)return i;try{let E=p.storage.getItem(p.key);if(!E)return i;let c=p.deserialize(E);if(!X(c))return i;let _=c.version;if(typeof _!="number")return i;let x=null,N=!1;if(_===p.version){let m=Q(c.snapshot,y,s);x=m?.snapshot??null,N=!!m?.needsRewrite}else if(p.migrate){let m=p.migrate(c.snapshot,_);x=Q(m,y,s)?.snapshot??null,N=x!==null}if(!x)return i;let R=h(x.current,x.context,x.history,x.status,M(y),x.visited);return N&&u(R),R}catch(E){return f(E),i}};return{clearOnReset:p?.clearOnReset??!0,hydrateSnapshot:v,persistSnapshot:u,removePersistedSnapshot:t}};var ye=50,de=e=>e===null?null:typeof e=="number"&&Number.isFinite(e)?Math.max(0,Math.trunc(e)):ye,Te=(e,n)=>{if(n===null||e.length<=n)return{next:[...e],trimmed:[]};let s=e.length-n;return{next:e.slice(s),trimmed:e.slice(0,s)}},K=(e,n)=>{if(!e.steps||typeof e.steps!="object")throw new Error("Journey steps must be a record object.");if(!Array.isArray(e.transitions))throw new Error("Journey transitions must be an array.");U(e.steps,e.initial,`Journey initial step "${e.initial}" does not exist in steps registry.`);for(let[o,a]of e.transitions.entries()){if(!a||typeof a!="object")throw new Error(`Journey transition at index ${o} must be an object.`);if(typeof a.from!="string"||typeof a.event!="string")throw new Error(`Journey transition at index ${o} must define string "from" and "event".`);if(a.from!==A&&!(a.from in e.steps))throw new Error(`Journey transition at index ${o} references unknown from step "${a.from}".`);if(a.to!==k&&!z(a.to)&&!(a.to in e.steps))throw new Error(`Journey transition at index ${o} points to unknown step "${a.to}".`)}let{clearOnReset:s,hydrateSnapshot:y,persistSnapshot:r,removePersistedSnapshot:p}=G({initial:e.initial,context:e.context,steps:e.steps,...n?{options:n}:{}}),f=n?.history,u=(o,a,S)=>{let d=de(S??f?.maxHistory),{next:T,trimmed:I}=Te(o.history,d);if(I.length===0)return{snapshot:o,trimmed:I,maxHistory:d};let P=h(o.current,o.context,T,o.status,o.async,o.visited);return f?.onOverflow?.({previous:o.history,next:T,trimmed:I,maxHistory:d,reason:a}),{snapshot:P,trimmed:I,maxHistory:d}},t=y(),v=u(t,"hydrate");t=v.snapshot,v.trimmed.length>0&&r(t);let i=new Set,E=Promise.resolve();t={...t,async:M(e.steps)};let c=()=>{for(let o of i)o()},_=o=>o===g.EVALUATING_WHEN||o===g.RUNNING_EFFECT,x=(o,a)=>{let S=t.async.byStep[o]??H(),d=a(S);if(S.phase===d.phase&&S.eventType===d.eventType&&S.transitionId===d.transitionId&&S.error===d.error)return;let T={...t.async.byStep,[o]:d},I=Object.values(T).some(P=>_(P.phase));t={...t,async:{isLoading:I,byStep:T}},c()},N=(o,a,S,d)=>{x(o,()=>({phase:a,eventType:S,transitionId:d??null,error:null}))},R=o=>{x(o,()=>H())},m=(o,a,S,d)=>{x(o,()=>({phase:g.ERROR,eventType:a,transitionId:d??null,error:S}))};return{getSnapshot:()=>t,subscribe:o=>(i.add(o),()=>{i.delete(o)}),reset:()=>(t=h(e.initial,e.context,[],J.RUNNING,M(e.steps)),s?p():r(t),c(),t),updateContext:o=>(t={...t,context:o(t.context)},r(t),c(),t),clearStepError:o=>{let a=o??t.current;return a in e.steps&&R(a),t},trimHistory:o=>{let a=u(t,"manual",o);return a.trimmed.length===0||(t=a.snapshot,r(t),c()),t},clearHistory:()=>(t.history.length===0||(t=h(t.current,t.context,[],t.status,t.async,t.visited),r(t),c()),t),send:o=>{let a=async()=>{if(t.status!==J.RUNNING)return{transitioned:!1,snapshot:t};let d=t.current;if($(o))return U(e.steps,o.to,`Cannot goTo unknown step "${o.to}".`),R(d),t=B(t,o.to,t.context),t=u(t,"auto").snapshot,r(t),c(),b(t,!0,w.GO_TO);let T;try{T=await q(e.transitions,t,o,{onAsyncGuardStart:l=>{N(d,g.EVALUATING_WHEN,o.type,l.id)},onAsyncGuardSuccess:()=>{R(d)},onAsyncGuardError:(l,C)=>{m(d,o.type,C,l.id)}})}catch(l){throw m(d,o.type,l),l}if(!T)return b(t,!1);let I=t.context;if(T.effect){let l=T.effect({context:t.context,from:t.current,history:t.history,event:o});F(l)&&N(d,g.RUNNING_EFFECT,o.type,T.id);let C;try{C=await l}catch(Y){throw m(d,o.type,Y,T.id),Y}C!==void 0&&(I=C)}if(R(d),z(T.to))return t={...t,context:I,status:T.to===O.COMPLETE?J.COMPLETE:J.CLOSED},t=u(t,"auto").snapshot,r(t),c(),b(t,!0,T.id);if(T.to===k){let{target:l,history:C}=W(t,e.steps);U(e.steps,l,`Transition points to unknown step "${l}".`);let Y=D(t.visited,l);return t=h(l,I,C,t.status,t.async,Y),t=u(t,"auto").snapshot,r(t),c(),b(t,!0,T.id)}let P=T.to;U(e.steps,P,`Transition points to unknown step "${P}".`);let Z=B(t,P,I);return t=u(Z,"auto").snapshot,r(t),c(),b(t,!0,T.id)},S=E.then(a,a);return E=S.then(()=>{},()=>{}),S}}};0&&(module.exports={HISTORY_TARGET,JOURNEY_ASYNC_PHASE,JOURNEY_EVENT,JOURNEY_STATUS,JOURNEY_TERMINAL,JOURNEY_WILDCARD,createJourneyMachine,createPersistenceController});
1
+ "use strict";var W=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var Te=(e,n)=>{for(var s in n)W(e,s,{get:n[s],enumerable:!0})},ye=(e,n,s,T)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of pe(n))!ie.call(e,r)&&r!==s&&W(e,r,{get:()=>n[r],enumerable:!(T=ae(n,r))||T.enumerable});return e};var de=e=>ye(W({},"__esModule",{value:!0}),e);var Ee={};Te(Ee,{JOURNEY_ASYNC_PHASE:()=>h,JOURNEY_EVENT:()=>w,JOURNEY_STATUS:()=>m,JOURNEY_WILDCARD:()=>b,createJourneyMachine:()=>ne,createPersistenceController:()=>F,createTransitions:()=>se,tx:()=>re});module.exports=de(Ee);var m={RUNNING:"running",COMPLETE:"complete",TERMINATED:"terminated"},b="*",w={GO_TO_STEP_BY_ID:"goToStepById"},h={IDLE:"idle",EVALUATING_WHEN:"evaluating-when",RUNNING_EFFECT:"running-effect",ERROR:"error"};var L=(e,n,s)=>{if(!(n in e))throw new Error(s)},Q=e=>typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.trunc(e)),c=()=>Date.now(),ue=e=>[...new Set(e)],Se=(e,n)=>Object.fromEntries(n.map(s=>[s,e[s]===!0])),B=(e,n)=>{let s=n??ue(e),T=Object.fromEntries(s.map(r=>[r,!1]));for(let r of e)T[r]=!0;return T},ce=(e,n)=>({...e,[n]:!0}),z=e=>typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function",V=()=>({phase:h.IDLE,eventType:null,transitionId:null,error:null}),U=e=>({isLoading:!1,byStep:Object.fromEntries(Object.keys(e).map(s=>[s,V()]))}),K=e=>e.type===w.GO_TO_STEP_BY_ID&&"stepId"in e,j=e=>e==="COMPLETE"||e==="TERMINATED",X=(e,n)=>{let s=n;for(let[T,r]of e.entries()){if(!r||typeof r!="object")throw new Error(`Journey transition at index ${T} must be an object.`);if(typeof r.from!="string"||typeof r.event!="string")throw new Error(`Journey transition at index ${T} must define string "from" and "event".`);if(r.from!==b&&!(r.from in s))throw new Error(`Journey transition at index ${T} references unknown from step "${r.from}".`);if(r.event==="completeJourney"||r.event==="terminateJourney"){if("to"in r&&r.to!==void 0)throw new Error(`Journey transition at index ${T} with event "${r.event}" cannot define "to".`);continue}if(typeof r.to!="string")throw new Error(`Journey transition at index ${T} with event "${r.event}" must define string "to".`);if(!j(r.to)&&!(r.to in s))throw new Error(`Journey transition at index ${T} points to unknown step "${r.to}".`)}},f=(e,n,s)=>s?{transitioned:n,transitionId:s,snapshot:e}:{transitioned:n,snapshot:e},D=(e,n,s,T,r,u,d)=>{if(e.length===0)throw new Error("Journey timeline cannot be empty.");let t=Math.max(0,Math.min(Math.trunc(n),e.length-1)),E=e[t],I=Object.keys(u);return{status:T,currentStepId:E,history:{timeline:[...e],index:t},context:s,visited:d?Se(d,I):B(e,I),stepMeta:{...u},async:r}},Z=async(e,n,s,T)=>{for(let r of e){let u=r.from===b||r.from===n.currentStepId,d=r.event===s.type;if(!u||!d)continue;if(!r.when)return r;let t=r.when({context:n.context,from:n.currentStepId,timeline:n.history.timeline,index:n.history.index,event:s}),E=z(t);E&&T?.onAsyncGuardStart?.(r);let I;try{I=await t}catch(M){throw E&&T?.onAsyncGuardError?.(r,M),M}if(E&&T?.onAsyncGuardSuccess?.(r),I)return r}return null},q=(e,n,s)=>{let T=e.history.timeline.slice(0,e.history.index+1),r=T;n!==e.currentStepId&&(r=[...T,n]);let u=r.length-1,d=ce(e.visited,n);return D(r,u,s,e.status,e.async,e.stepMeta,d)};var G=e=>typeof e=="object"&&e!==null,ee=e=>e===m.RUNNING||e===m.COMPLETE||e===m.TERMINATED,le=()=>{let e=globalThis.localStorage;return!e||typeof e.getItem!="function"||typeof e.setItem!="function"||typeof e.removeItem!="function"?null:e},xe=e=>{if(!e)return null;let n=e.storage??le();return n?{key:e.key,storage:n,version:e.version??1,clearOnReset:e.clearOnReset??!0,serialize:e.serialize??JSON.stringify,deserialize:e.deserialize??JSON.parse,...e.migrate?{migrate:e.migrate}:{},...e.onError?{onError:e.onError}:{}}:null},te=(e,n,s,T)=>{if(!G(e))return null;let r=!1,u=G(e.history)?e.history:null;u||(r=!0);let d=u?.timeline??e.timeline,t=Array.isArray(d)?d.filter(l=>typeof l=="string"&&l in n):[],E=typeof e.currentStepId=="string"&&e.currentStepId in n?e.currentStepId:typeof e.current=="string"&&e.current in n?e.current:null;if(t.length===0){if(!E)return null;t.push(E),r=!0}let I=t.length-1,M=u?.index??e.index;if(typeof M=="number"&&Number.isFinite(M))I=Math.max(0,Math.min(Math.trunc(M),t.length-1)),I!==M&&(r=!0);else if(E){let l=t.lastIndexOf(E);l>=0&&(I=l,r=!0)}let y=ee(e.status)?e.status:m.RUNNING;ee(e.status)||(r=!0);let p=Object.keys(n),v=e.visited,_=G(v)?Object.fromEntries(p.map(l=>[l,v[l]===!0])):null,J=Array.isArray(v)?B(v.filter(l=>typeof l=="string"&&l in n),p):null,C=B(t,p);if(_){let l=v;C=_,p.some(N=>typeof l[N]!="boolean")&&(r=!0)}else J&&(C=J),r=!0;let P=G(e.stepMeta)?e.stepMeta:null;P||(r=!0);let R=Object.fromEntries(Object.keys(n).map(l=>{let k=l,N=P?P[l]:void 0;return N===void 0?[k,T[k]]:[k,N]}));return{snapshot:{currentStepId:t[I],history:{timeline:t,index:I},context:"context"in e?e.context:s,status:y,visited:C,stepMeta:R},needsRewrite:r}},F=e=>{let{initial:n,context:s,stepMeta:T,steps:r,options:u}=e,d=xe(u?.persistence),t=y=>{d?.onError?.(y)},E=y=>{if(d)try{let p={version:d.version,snapshot:{currentStepId:y.currentStepId,history:{timeline:[...y.history.timeline],index:y.history.index},context:y.context,status:y.status,visited:{...y.visited},stepMeta:{...y.stepMeta}}};d.storage.setItem(d.key,d.serialize(p))}catch(p){t(p)}},I=()=>{if(d)try{d.storage.removeItem(d.key)}catch(y){t(y)}},M=()=>{let y=D([n],0,s,m.RUNNING,U(r),T);if(!d)return y;try{let p=d.storage.getItem(d.key);if(!p)return y;let v=d.deserialize(p);if(!G(v))return y;let _=v.version;if(typeof _!="number")return y;let J=null,C=!1;if(_===d.version){let R=te(v.snapshot,r,s,T);J=R?.snapshot??null,C=!!R?.needsRewrite}else if(d.migrate){let R=d.migrate(v.snapshot,_);J=te(R,r,s,T)?.snapshot??null,C=J!==null}if(!J)return y;let P=D(J.history.timeline,J.history.index,J.context,J.status,U(r),J.stepMeta,J.visited);return C&&E(P),P}catch(p){return t(p),y}};return{clearOnReset:d?.clearOnReset??!0,hydrateSnapshot:M,persistSnapshot:E,removePersistedSnapshot:I}};function ne(e,n){if(!e.steps||typeof e.steps!="object")throw new Error("Journey steps must be a record object.");if(!Array.isArray(e.transitions))throw new Error("Journey transitions must be an array.");L(e.steps,e.initial,`Journey initial step "${e.initial}" does not exist in steps registry.`),X(e.transitions,e.steps);let s=()=>Object.fromEntries(Object.entries(e.steps).map(([o,a])=>[o,a.meta])),{clearOnReset:T,hydrateSnapshot:r,persistSnapshot:u,removePersistedSnapshot:d}=F({initial:e.initial,context:e.context,stepMeta:s(),steps:e.steps,...n?{options:n}:{}}),t=r();t={...t,async:U(e.steps)};let E=new Set,I=new Set,M=Promise.resolve(),y=()=>{for(let o of E)o()},p=o=>{for(let a of I)a(o)},v=o=>{let a=M.then(o,o);return M=a.then(()=>{},()=>{}),a},_=o=>o===h.EVALUATING_WHEN||o===h.RUNNING_EFFECT,J=(o,a)=>{let i=t.async.byStep[o]??V(),x=a(i);if(i.phase===x.phase&&i.eventType===x.eventType&&i.transitionId===x.transitionId&&i.error===x.error)return;let g={...t.async.byStep,[o]:x},O=Object.values(g).some(Y=>_(Y.phase));t={...t,async:{isLoading:O,byStep:g}},y()},C=(o,a,i,x)=>{J(o,()=>({phase:a,eventType:i,transitionId:x??null,error:null}))},P=o=>{J(o,()=>V())},R=(o,a,i,x)=>{J(o,()=>({phase:h.ERROR,eventType:a,transitionId:x??null,error:i}))},l=(o,a)=>{if(t.status!==m.RUNNING)return f(t,!1);let i=Q(o);if(t.history.index===0)return f(t,!1);let x=t.currentStepId,g=Math.max(0,t.history.index-i),O=t.history.index-g;return O<=0?f(t,!1):(p({type:"step.exit",stepId:x,timestamp:c()}),t=D(t.history.timeline,g,t.context,t.status,t.async,t.stepMeta,t.visited),u(t),y(),p({type:"navigation.previous",from:x,to:t.currentStepId,requestedSteps:i,appliedSteps:O,timestamp:c()}),p({type:"step.enter",stepId:t.currentStepId,timestamp:c()}),f(t,!0,a))},k=o=>{if(t.status!==m.RUNNING)return f(t,!1);let a=t.history.timeline.length-1;if(t.history.index>=a)return f(t,!1);let i=t.currentStepId;return p({type:"step.exit",stepId:i,timestamp:c()}),t=D(t.history.timeline,a,t.context,t.status,t.async,t.stepMeta,t.visited),u(t),y(),p({type:"navigation.lastVisited",from:i,to:t.currentStepId,timestamp:c()}),p({type:"step.enter",stepId:t.currentStepId,timestamp:c()}),f(t,!0,o)},N={getSnapshot:()=>t,subscribe:o=>(E.add(o),()=>{E.delete(o)}),subscribeEvent:o=>(I.add(o),()=>{I.delete(o)}),resetMachine:()=>(t=D([e.initial],0,e.context,m.RUNNING,U(e.steps),s()),T?d():u(t),y(),t),updateContext:o=>(t={...t,context:o(t.context)},u(t),y(),t),updateStepMetadata:(o,a)=>{if(!(o in e.steps))return t;let i=t.stepMeta[o],x=a(i);return Object.is(i,x)||(t={...t,stepMeta:{...t.stepMeta,[o]:x}},u(t),y(),p({type:"metadata.updated",stepId:o,previous:i,next:x,timestamp:c()})),t},clearStepError:o=>{let a=o??t.currentStepId;return a in e.steps&&P(a),t},goToPreviousStep:o=>v(async()=>l(o,"goToPreviousStep")),goToLastVisitedStep:()=>v(async()=>k("goToLastVisitedStep")),goToNextStep:()=>N.send({type:"goToNextStep"}),terminateJourney:o=>N.send(o===void 0?{type:"terminateJourney"}:{type:"terminateJourney",payload:o}),completeJourney:o=>N.send(o===void 0?{type:"completeJourney"}:{type:"completeJourney",payload:o}),send:o=>v(async()=>{if(t.status!==m.RUNNING)return f(t,!1);let a=t.currentStepId;if(K(o)){L(e.steps,o.stepId,`Cannot goToStepById unknown step "${o.stepId}".`),p({type:"transition.start",from:a,event:o,timestamp:c()}),P(a);let S=t.currentStepId,A=q(t,o.stepId,t.context);return A.currentStepId!==S&&p({type:"step.exit",stepId:S,timestamp:c()}),t=A,u(t),y(),p({type:"transition.success",from:a,to:t.currentStepId,eventType:w.GO_TO_STEP_BY_ID,transitionId:w.GO_TO_STEP_BY_ID,timestamp:c()}),A.currentStepId!==S&&p({type:"step.enter",stepId:t.currentStepId,timestamp:c()}),f(t,!0,w.GO_TO_STEP_BY_ID)}p({type:"transition.start",from:a,event:o,timestamp:c()});let i;try{i=await Z(e.transitions,t,o,{onAsyncGuardStart:S=>{C(a,h.EVALUATING_WHEN,o.type,S.id)},onAsyncGuardSuccess:()=>{P(a)},onAsyncGuardError:(S,A)=>{R(a,o.type,A,S.id)}})}catch(S){throw R(a,o.type,S),p({type:"transition.error",from:a,eventType:o.type,transitionId:null,error:S,timestamp:c()}),S}if(!i){if(o.type==="goToPreviousStep"||o.type==="back"){let S=l(1,o.type);return S.transitioned&&p({type:"transition.success",from:a,to:S.snapshot.currentStepId,eventType:o.type,transitionId:null,timestamp:c()}),S}return f(t,!1)}let x=t.context;if(i.effect){let S=i.effect({context:t.context,from:t.currentStepId,timeline:t.history.timeline,index:t.history.index,event:o});z(S)&&C(a,h.RUNNING_EFFECT,o.type,i.id);let A;try{A=await S}catch(H){throw R(a,o.type,H,i.id),p({type:"transition.error",from:a,eventType:o.type,transitionId:i.id??null,error:H,timestamp:c()}),H}A!==void 0&&(x=A)}P(a);let g=i.event==="completeJourney"?"COMPLETE":i.event==="terminateJourney"?"TERMINATED":i.to;if(j(g)){let S=t.history.timeline.slice(0,t.history.index+1);return t={...t,history:{timeline:S,index:S.length-1},context:x,status:g==="COMPLETE"?m.COMPLETE:m.TERMINATED},u(t),y(),p({type:"transition.success",from:a,to:g,eventType:o.type,transitionId:i.id??null,timestamp:c()}),p({type:g==="COMPLETE"?"journey.complete":"journey.close",stepId:t.currentStepId,timestamp:c()}),f(t,!0,i.id)}let O=g;L(e.steps,O,`Transition points to unknown step "${O}".`);let Y=t.currentStepId;return Y!==O&&p({type:"step.exit",stepId:Y,timestamp:c()}),t=q(t,O,x),u(t),y(),p({type:"transition.success",from:a,to:t.currentStepId,eventType:o.type,transitionId:i.id??null,timestamp:c()}),Y!==t.currentStepId&&p({type:"step.enter",stepId:t.currentStepId,timestamp:c()}),f(t,!0,i.id)})};return N}var oe=(e,n)=>n==="completeJourney"?{complete:(s={})=>({...s,from:e,event:n})}:n==="terminateJourney"?{terminate:(s={})=>({...s,from:e,event:n})}:{to:(s,T={})=>({...T,from:e,event:n,to:s}),choose:(...s)=>s.map(T=>({...T,from:e,event:n}))},$=(e,n,s={})=>({...s,from:e,event:n}),re={from:e=>({on:n=>oe(e,n),toComplete:(n={})=>$(e,"completeJourney",n),toTerminate:(n={})=>$(e,"terminateJourney",n)}),any:()=>({on:e=>oe(b,e),toComplete:(e={})=>$(b,"completeJourney",e),toTerminate:(e={})=>$(b,"terminateJourney",e)}),when:e=>({to:(n,s={})=>({...s,to:n,when:e})}),otherwise:()=>({to:(e,n={})=>({...n,to:e})})},se=(...e)=>e.flatMap(n=>Array.isArray(n)?[...n]:[n]);0&&(module.exports={JOURNEY_ASYNC_PHASE,JOURNEY_EVENT,JOURNEY_STATUS,JOURNEY_WILDCARD,createJourneyMachine,createPersistenceController,createTransitions,tx});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.ts", "../src/types.ts", "../src/machine-helpers.ts", "../src/persistence.ts", "../src/machine.ts"],
4
- "sourcesContent": ["export { createJourneyMachine } from \"./machine\";\nexport { createPersistenceController } from \"./persistence\";\nexport {\n JOURNEY_EVENT,\n JOURNEY_ASYNC_PHASE,\n JOURNEY_STATUS,\n JOURNEY_WILDCARD,\n HISTORY_TARGET,\n JOURNEY_TERMINAL,\n type JourneyBuiltInEvent,\n type JourneyBuiltInFrom,\n type JourneyAsyncPhase,\n type JourneyStatus,\n type JourneyAsyncState,\n type JourneyStepAsyncState,\n type JourneyEvent,\n type JourneyEventPayloadMap,\n type JourneyDefinition,\n type JourneyHistoryOptions,\n type JourneyHistoryOverflow,\n type JourneyHistoryOverflowReason,\n type JourneyMachineOptions,\n type JourneyGoToEvent,\n type JourneyMachine,\n type JourneyPayloadFor,\n type JourneyPersistedSnapshot,\n type JourneyPersistedState,\n type JourneyPersistenceOptions,\n type JourneyStorage,\n type JourneySendResult,\n type JourneySnapshot,\n type JourneyTerminal,\n type JourneyTransition,\n type JourneyTransitionArgs,\n type JourneyTransitionTarget\n} from \"./types\";\n", "export const JOURNEY_TERMINAL = {\n COMPLETE: \"COMPLETE\",\n CLOSE: \"CLOSE\"\n} as const;\n\nexport type JourneyTerminal = (typeof JOURNEY_TERMINAL)[keyof typeof JOURNEY_TERMINAL];\n\nexport const JOURNEY_STATUS = {\n RUNNING: \"running\",\n COMPLETE: \"complete\",\n CLOSED: \"closed\"\n} as const;\n\nexport type JourneyStatus = (typeof JOURNEY_STATUS)[keyof typeof JOURNEY_STATUS];\n\nexport const HISTORY_TARGET = \"__HISTORY__\" as const;\nexport const JOURNEY_WILDCARD = \"*\" as const;\n\nexport const JOURNEY_EVENT = {\n GO_TO: \"goTo\"\n} as const;\n\nexport type JourneyBuiltInEvent = (typeof JOURNEY_EVENT)[keyof typeof JOURNEY_EVENT];\nexport type JourneyBuiltInFrom = typeof JOURNEY_WILDCARD;\n\nexport const JOURNEY_ASYNC_PHASE = {\n IDLE: \"idle\",\n EVALUATING_WHEN: \"evaluating-when\",\n RUNNING_EFFECT: \"running-effect\",\n ERROR: \"error\"\n} as const;\n\nexport type JourneyAsyncPhase = (typeof JOURNEY_ASYNC_PHASE)[keyof typeof JOURNEY_ASYNC_PHASE];\n\nexport type JourneyStepAsyncState = {\n phase: JourneyAsyncPhase;\n eventType: string | null;\n transitionId: string | null;\n error: unknown | null;\n};\n\nexport type JourneyAsyncState<TStepId extends string> = {\n isLoading: boolean;\n byStep: Record<TStepId, JourneyStepAsyncState>;\n};\n\nexport type JourneyBaseEvent = {\n type: string;\n payload?: unknown;\n};\n\nexport type JourneyEventPayloadMap<TEventType extends string> = Partial<\n Record<TEventType | JourneyBuiltInEvent, unknown>\n>;\n\nexport type JourneyPayloadFor<\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>,\n TEvent extends TEventType | JourneyBuiltInEvent\n> = TEvent extends keyof TPayloadMap ? TPayloadMap[TEvent] : unknown;\n\nexport type JourneyGoToEvent<TStepId extends string, TPayload = unknown> = {\n type: (typeof JOURNEY_EVENT)[\"GO_TO\"];\n to: TStepId;\n payload?: TPayload;\n};\n\nexport type JourneyEvent<\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>\n> =\n | JourneyGoToEvent<\n TStepId,\n JourneyPayloadFor<TEventType, TPayloadMap, (typeof JOURNEY_EVENT)[\"GO_TO\"]>\n >\n | {\n [TType in TEventType]: {\n type: TType;\n payload?: JourneyPayloadFor<TEventType, TPayloadMap, TType>;\n };\n }[TEventType];\n\nexport type JourneyTransitionArgs<\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>\n> = {\n context: TContext;\n from: TStepId;\n history: readonly TStepId[];\n event: JourneyEvent<TStepId, TEventType, TPayloadMap>;\n};\n\nexport type JourneyTransitionTarget<TStepId extends string> =\n | TStepId\n | JourneyTerminal\n | typeof HISTORY_TARGET;\n\nexport type JourneyTransition<\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>\n> = {\n id?: string;\n from: TStepId | JourneyBuiltInFrom;\n event: TEventType | (typeof JOURNEY_EVENT)[\"GO_TO\"];\n to: JourneyTransitionTarget<TStepId>;\n when?: (\n args: JourneyTransitionArgs<TContext, TStepId, TEventType, TPayloadMap>\n ) => boolean | Promise<boolean>;\n effect?: (\n args: JourneyTransitionArgs<TContext, TStepId, TEventType, TPayloadMap>\n ) => TContext | void | Promise<TContext | void>;\n};\n\nexport type JourneySnapshot<TContext, TStepId extends string> = {\n current: TStepId;\n context: TContext;\n history: readonly TStepId[];\n visited: readonly TStepId[];\n status: JourneyStatus;\n async: JourneyAsyncState<TStepId>;\n};\n\nexport type JourneyPersistedSnapshot<TContext, TStepId extends string> = {\n current: TStepId;\n context: TContext;\n history: readonly TStepId[];\n status: JourneyStatus;\n visited: readonly TStepId[];\n};\n\nexport type JourneyPersistedState<TContext, TStepId extends string> = {\n version: number;\n snapshot: JourneyPersistedSnapshot<TContext, TStepId>;\n};\n\nexport type JourneyHistoryOverflowReason = \"auto\" | \"hydrate\" | \"manual\";\n\nexport type JourneyHistoryOverflow<TStepId extends string> = {\n previous: readonly TStepId[];\n next: readonly TStepId[];\n trimmed: readonly TStepId[];\n maxHistory: number | null;\n reason: JourneyHistoryOverflowReason;\n};\n\nexport type JourneyHistoryOptions<TStepId extends string> = {\n maxHistory?: number | null;\n onOverflow?: (info: JourneyHistoryOverflow<TStepId>) => void;\n};\n\nexport type JourneyStorage = {\n getItem: (key: string) => string | null;\n setItem: (key: string, value: string) => void;\n removeItem: (key: string) => void;\n};\n\nexport type JourneyPersistenceOptions<TContext, TStepId extends string> = {\n key: string;\n storage?: JourneyStorage;\n version?: number;\n clearOnReset?: boolean;\n serialize?: (value: JourneyPersistedState<TContext, TStepId>) => string;\n deserialize?: (value: string) => unknown;\n migrate?: (\n value: unknown,\n persistedVersion: number\n ) => JourneyPersistedSnapshot<TContext, TStepId>;\n onError?: (error: unknown) => void;\n};\n\nexport type JourneyDefinition<\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>\n> = {\n initial: TStepId;\n context: TContext;\n steps: Record<TStepId, unknown>;\n transitions: readonly JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[];\n};\n\nexport type JourneyMachineOptions<TContext, TStepId extends string> = {\n persistence?: JourneyPersistenceOptions<TContext, TStepId>;\n history?: JourneyHistoryOptions<TStepId>;\n};\n\nexport type JourneySendResult<TContext, TStepId extends string> = {\n transitioned: boolean;\n transitionId?: string;\n snapshot: JourneySnapshot<TContext, TStepId>;\n};\n\nexport type JourneyMachine<\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>\n> = {\n getSnapshot: () => JourneySnapshot<TContext, TStepId>;\n send: (\n event: JourneyEvent<TStepId, TEventType, TPayloadMap>\n ) => Promise<JourneySendResult<TContext, TStepId>>;\n updateContext: (updater: (context: TContext) => TContext) => JourneySnapshot<TContext, TStepId>;\n clearStepError: (stepId?: TStepId) => JourneySnapshot<TContext, TStepId>;\n reset: () => JourneySnapshot<TContext, TStepId>;\n trimHistory: (maxHistory?: number | null) => JourneySnapshot<TContext, TStepId>;\n clearHistory: () => JourneySnapshot<TContext, TStepId>;\n subscribe: (listener: () => void) => () => void;\n};\n", "import { JOURNEY_ASYNC_PHASE, JOURNEY_EVENT, JOURNEY_TERMINAL, JOURNEY_WILDCARD } from \"./types\";\nimport type {\n JourneyAsyncState,\n JourneyEvent,\n JourneyEventPayloadMap,\n JourneyGoToEvent,\n JourneyPayloadFor,\n JourneySendResult,\n JourneySnapshot,\n JourneyStatus,\n JourneyStepAsyncState,\n JourneyTerminal,\n JourneyTransition\n} from \"./types\";\n\nexport const assertStepExists = <TStepId extends string>(\n steps: Record<TStepId, unknown>,\n stepId: TStepId,\n message: string\n) => {\n if (!(stepId in steps)) {\n throw new Error(message);\n }\n};\n\nconst unique = <T>(items: readonly T[]): T[] => [...new Set(items)];\n\nexport const buildVisited = <TStepId extends string>(\n history: readonly TStepId[],\n current: TStepId\n): TStepId[] => unique([...history, current]);\n\nexport const appendVisited = <TStepId extends string>(\n visited: readonly TStepId[],\n current: TStepId\n): TStepId[] => (visited.includes(current) ? [...visited] : [...visited, current]);\n\nexport const isPromiseLike = <T>(value: T | PromiseLike<T>): value is PromiseLike<T> =>\n typeof value === \"object\" &&\n value !== null &&\n \"then\" in value &&\n typeof (value as { then: unknown }).then === \"function\";\n\nexport const buildIdleStepAsyncState = (): JourneyStepAsyncState => ({\n phase: JOURNEY_ASYNC_PHASE.IDLE,\n eventType: null,\n transitionId: null,\n error: null\n});\n\nexport const buildInitialAsyncState = <TStepId extends string>(\n steps: Record<TStepId, unknown>\n): JourneyAsyncState<TStepId> => {\n const byStep = Object.fromEntries(\n Object.keys(steps).map((stepId) => [stepId, buildIdleStepAsyncState()])\n ) as Record<TStepId, JourneyStepAsyncState>;\n\n return {\n isLoading: false,\n byStep\n };\n};\n\nexport const isGoToEvent = <\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>\n>(\n event: JourneyEvent<TStepId, TEventType, TPayloadMap>\n): event is JourneyGoToEvent<\n TStepId,\n JourneyPayloadFor<TEventType, TPayloadMap, (typeof JOURNEY_EVENT)[\"GO_TO\"]>\n> => event.type === JOURNEY_EVENT.GO_TO && \"to\" in event;\n\nexport const isTerminalTarget = <TStepId extends string>(\n target: TStepId | JourneyTerminal | \"__HISTORY__\"\n): target is JourneyTerminal =>\n target === JOURNEY_TERMINAL.COMPLETE || target === JOURNEY_TERMINAL.CLOSE;\n\nexport const buildSendResult = <TContext, TStepId extends string>(\n snapshot: JourneySnapshot<TContext, TStepId>,\n transitioned: boolean,\n transitionId?: string\n): JourneySendResult<TContext, TStepId> =>\n transitionId ? { transitioned, transitionId, snapshot } : { transitioned, snapshot };\n\nexport const buildSnapshot = <TContext, TStepId extends string>(\n current: TStepId,\n context: TContext,\n history: readonly TStepId[],\n status: JourneyStatus,\n asyncState: JourneyAsyncState<TStepId>,\n visited?: readonly TStepId[]\n): JourneySnapshot<TContext, TStepId> => ({\n status,\n current,\n context,\n history,\n visited: visited ? [...visited] : buildVisited(history, current),\n async: asyncState\n});\n\nexport const resolveHistoryTarget = <TContext, TStepId extends string>(\n snapshot: JourneySnapshot<TContext, TStepId>,\n steps: Record<TStepId, unknown>\n): { target: TStepId; history: TStepId[] } => {\n const cloned = [...snapshot.history];\n\n while (cloned.length > 0) {\n const candidate = cloned.pop();\n if (!candidate) {\n break;\n }\n if (candidate in steps) {\n return {\n target: candidate,\n history: cloned\n };\n }\n }\n\n return {\n target: snapshot.current,\n history: [...snapshot.history]\n };\n};\n\nexport const selectTransition = async <\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>\n>(\n transitions: readonly JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[],\n snapshot: JourneySnapshot<TContext, TStepId>,\n event: JourneyEvent<TStepId, TEventType, TPayloadMap>,\n hooks?: {\n onAsyncGuardStart?: (\n transition: JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>\n ) => void;\n onAsyncGuardSuccess?: (\n transition: JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>\n ) => void;\n onAsyncGuardError?: (\n transition: JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>,\n error: unknown\n ) => void;\n }\n): Promise<JourneyTransition<TContext, TStepId, TEventType, TPayloadMap> | null> => {\n for (const transition of transitions) {\n const fromMatches =\n transition.from === JOURNEY_WILDCARD || transition.from === snapshot.current;\n const eventMatches = transition.event === event.type;\n\n if (!fromMatches || !eventMatches) {\n continue;\n }\n\n if (!transition.when) {\n return transition;\n }\n\n const guardResult = transition.when({\n context: snapshot.context,\n from: snapshot.current,\n history: snapshot.history,\n event\n });\n const asyncGuard = isPromiseLike(guardResult);\n if (asyncGuard) {\n hooks?.onAsyncGuardStart?.(transition);\n }\n\n let allowed: boolean;\n try {\n allowed = await guardResult;\n } catch (error) {\n if (asyncGuard) {\n hooks?.onAsyncGuardError?.(transition, error);\n }\n throw error;\n }\n\n if (asyncGuard) {\n hooks?.onAsyncGuardSuccess?.(transition);\n }\n\n if (allowed) {\n return transition;\n }\n }\n\n return null;\n};\n\nexport const transitionSnapshot = <TContext, TStepId extends string>(\n snapshot: JourneySnapshot<TContext, TStepId>,\n nextCurrent: TStepId,\n nextContext: TContext\n): JourneySnapshot<TContext, TStepId> => {\n const history =\n nextCurrent === snapshot.current\n ? [...snapshot.history]\n : [...snapshot.history, snapshot.current];\n\n const visited = appendVisited(snapshot.visited, nextCurrent);\n\n return buildSnapshot(nextCurrent, nextContext, history, snapshot.status, snapshot.async, visited);\n};\n", "import { JOURNEY_STATUS } from \"./types\";\nimport type {\n JourneyMachineOptions,\n JourneyPersistedSnapshot,\n JourneyPersistedState,\n JourneyStatus,\n JourneySnapshot,\n JourneyStorage\n} from \"./types\";\nimport { buildInitialAsyncState, buildSnapshot, buildVisited } from \"./machine-helpers\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isStatusValue = (value: unknown): value is JourneyStatus =>\n value === JOURNEY_STATUS.RUNNING ||\n value === JOURNEY_STATUS.COMPLETE ||\n value === JOURNEY_STATUS.CLOSED;\n\nconst resolveDefaultStorage = (): JourneyStorage | null => {\n const localStorageCandidate = (globalThis as { localStorage?: Partial<JourneyStorage> })\n .localStorage;\n\n if (\n !localStorageCandidate ||\n typeof localStorageCandidate.getItem !== \"function\" ||\n typeof localStorageCandidate.setItem !== \"function\" ||\n typeof localStorageCandidate.removeItem !== \"function\"\n ) {\n return null;\n }\n\n return localStorageCandidate as JourneyStorage;\n};\n\ntype ResolvedPersistence<TContext, TStepId extends string> = {\n key: string;\n storage: JourneyStorage;\n version: number;\n clearOnReset: boolean;\n serialize: (value: JourneyPersistedState<TContext, TStepId>) => string;\n deserialize: (value: string) => unknown;\n migrate?: (\n value: unknown,\n persistedVersion: number\n ) => JourneyPersistedSnapshot<TContext, TStepId>;\n onError?: (error: unknown) => void;\n};\n\nconst resolvePersistence = <TContext, TStepId extends string>(\n options?: JourneyMachineOptions<TContext, TStepId>[\"persistence\"]\n): ResolvedPersistence<TContext, TStepId> | null => {\n if (!options) {\n return null;\n }\n\n const storage = options.storage ?? resolveDefaultStorage();\n if (!storage) {\n return null;\n }\n\n return {\n key: options.key,\n storage,\n version: options.version ?? 1,\n clearOnReset: options.clearOnReset ?? true,\n serialize: options.serialize ?? JSON.stringify,\n deserialize: options.deserialize ?? JSON.parse,\n ...(options.migrate ? { migrate: options.migrate } : {}),\n ...(options.onError ? { onError: options.onError } : {})\n };\n};\n\nconst coercePersistedSnapshot = <TContext, TStepId extends string>(\n value: unknown,\n steps: Record<TStepId, unknown>,\n fallbackContext: TContext\n): { snapshot: JourneyPersistedSnapshot<TContext, TStepId>; needsRewrite: boolean } | null => {\n if (!isRecord(value)) {\n return null;\n }\n\n const currentValue = value.current;\n if (typeof currentValue !== \"string\" || !(currentValue in steps)) {\n return null;\n }\n const current = currentValue as TStepId;\n\n const history = Array.isArray(value.history)\n ? (value.history.filter(\n (step): step is TStepId => typeof step === \"string\" && step in steps\n ) as TStepId[])\n : [];\n\n const status = isStatusValue(value.status) ? value.status : JOURNEY_STATUS.RUNNING;\n\n const visitedRaw = Array.isArray(value.visited)\n ? (value.visited.filter(\n (step): step is TStepId => typeof step === \"string\" && step in steps\n ) as TStepId[])\n : null;\n const visited = visitedRaw && visitedRaw.length > 0 ? visitedRaw : buildVisited(history, current);\n const needsRewrite = !visitedRaw || visitedRaw.length === 0;\n\n return {\n snapshot: {\n current,\n context: (\"context\" in value ? value.context : fallbackContext) as TContext,\n history,\n status,\n visited\n },\n needsRewrite\n };\n};\n\n/**\n * Creates a persistence controller for snapshots, including hydration,\n * serialization, and storage error handling.\n */\nexport const createPersistenceController = <TContext, TStepId extends string>(args: {\n initial: TStepId;\n context: TContext;\n steps: Record<TStepId, unknown>;\n options?: JourneyMachineOptions<TContext, TStepId>;\n}) => {\n const { initial, context, steps, options } = args;\n const persistence = resolvePersistence(options?.persistence);\n\n const reportPersistenceError = (error: unknown) => {\n persistence?.onError?.(error);\n };\n\n const persistSnapshot = (snapshot: JourneySnapshot<TContext, TStepId>) => {\n if (!persistence) {\n return;\n }\n\n try {\n const persistedState: JourneyPersistedState<TContext, TStepId> = {\n version: persistence.version,\n snapshot: {\n current: snapshot.current,\n context: snapshot.context,\n history: [...snapshot.history],\n status: snapshot.status,\n visited: [...snapshot.visited]\n }\n };\n persistence.storage.setItem(persistence.key, persistence.serialize(persistedState));\n } catch (error) {\n reportPersistenceError(error);\n }\n };\n\n const removePersistedSnapshot = () => {\n if (!persistence) {\n return;\n }\n\n try {\n persistence.storage.removeItem(persistence.key);\n } catch (error) {\n reportPersistenceError(error);\n }\n };\n\n const hydrateSnapshot = (): JourneySnapshot<TContext, TStepId> => {\n const initialSnapshot = buildSnapshot(\n initial,\n context,\n [],\n JOURNEY_STATUS.RUNNING,\n buildInitialAsyncState(steps)\n );\n if (!persistence) {\n return initialSnapshot;\n }\n\n try {\n const rawPersisted = persistence.storage.getItem(persistence.key);\n if (!rawPersisted) {\n return initialSnapshot;\n }\n\n const parsed = persistence.deserialize(rawPersisted);\n if (!isRecord(parsed)) {\n return initialSnapshot;\n }\n\n const persistedVersion = parsed.version;\n if (typeof persistedVersion !== \"number\") {\n return initialSnapshot;\n }\n\n let persistedSnapshot: JourneyPersistedSnapshot<TContext, TStepId> | null = null;\n let shouldRewritePersisted = false;\n\n if (persistedVersion === persistence.version) {\n const coerced = coercePersistedSnapshot(parsed.snapshot, steps, context);\n persistedSnapshot = coerced?.snapshot ?? null;\n shouldRewritePersisted = Boolean(coerced?.needsRewrite);\n } else if (persistence.migrate) {\n const migrated = persistence.migrate(parsed.snapshot, persistedVersion);\n const coerced = coercePersistedSnapshot(migrated, steps, context);\n persistedSnapshot = coerced?.snapshot ?? null;\n shouldRewritePersisted = persistedSnapshot !== null;\n }\n\n if (!persistedSnapshot) {\n return initialSnapshot;\n }\n\n const hydratedSnapshot = buildSnapshot(\n persistedSnapshot.current,\n persistedSnapshot.context,\n persistedSnapshot.history,\n persistedSnapshot.status,\n buildInitialAsyncState(steps),\n persistedSnapshot.visited\n );\n\n if (shouldRewritePersisted) {\n persistSnapshot(hydratedSnapshot);\n }\n\n return hydratedSnapshot;\n } catch (error) {\n reportPersistenceError(error);\n return initialSnapshot;\n }\n };\n\n return {\n clearOnReset: persistence?.clearOnReset ?? true,\n hydrateSnapshot,\n persistSnapshot,\n removePersistedSnapshot\n };\n};\n", "import {\n JOURNEY_ASYNC_PHASE,\n JOURNEY_EVENT,\n JOURNEY_STATUS,\n JOURNEY_TERMINAL,\n JOURNEY_WILDCARD,\n HISTORY_TARGET\n} from \"./types\";\nimport type {\n JourneyAsyncState,\n JourneyAsyncPhase,\n JourneyEventPayloadMap,\n JourneyDefinition,\n JourneyHistoryOverflowReason,\n JourneyHistoryOptions,\n JourneyMachine,\n JourneyMachineOptions,\n JourneySendResult,\n JourneySnapshot\n} from \"./types\";\nimport {\n appendVisited,\n assertStepExists,\n buildIdleStepAsyncState,\n buildInitialAsyncState,\n buildSendResult,\n isGoToEvent,\n isPromiseLike,\n isTerminalTarget,\n resolveHistoryTarget,\n selectTransition,\n transitionSnapshot,\n buildSnapshot\n} from \"./machine-helpers\";\nimport { createPersistenceController } from \"./persistence\";\n\nconst DEFAULT_MAX_HISTORY = 50;\n\nconst resolveMaxHistory = (value: number | null | undefined): number | null => {\n if (value === null) {\n return null;\n }\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return Math.max(0, Math.trunc(value));\n }\n return DEFAULT_MAX_HISTORY;\n};\n\nconst applyHistoryLimit = <TStepId extends string>(\n history: readonly TStepId[],\n maxHistory: number | null\n): { next: TStepId[]; trimmed: TStepId[] } => {\n if (maxHistory === null || history.length <= maxHistory) {\n return { next: [...history], trimmed: [] };\n }\n\n const trimCount = history.length - maxHistory;\n return {\n next: history.slice(trimCount),\n trimmed: history.slice(0, trimCount)\n };\n};\n\n/**\n * Creates a journey machine from a journey definition.\n * Validates steps/transitions, hydrates persisted state (if configured),\n * and returns an API for sending events and reading snapshots.\n */\nexport const createJourneyMachine = <\n TContext,\n TStepId extends string,\n TEventType extends string = \"next\" | \"back\" | \"close\" | \"submit\",\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>\n>(\n journey: JourneyDefinition<TContext, TStepId, TEventType, TPayloadMap>,\n options?: JourneyMachineOptions<TContext, TStepId>\n): JourneyMachine<TContext, TStepId, TEventType, TPayloadMap> => {\n if (!journey.steps || typeof journey.steps !== \"object\") {\n throw new Error(\"Journey steps must be a record object.\");\n }\n\n if (!Array.isArray(journey.transitions)) {\n throw new Error(\"Journey transitions must be an array.\");\n }\n\n assertStepExists(\n journey.steps,\n journey.initial,\n `Journey initial step \"${journey.initial}\" does not exist in steps registry.`\n );\n\n for (const [index, transition] of journey.transitions.entries()) {\n if (!transition || typeof transition !== \"object\") {\n throw new Error(`Journey transition at index ${index} must be an object.`);\n }\n\n if (typeof transition.from !== \"string\" || typeof transition.event !== \"string\") {\n throw new Error(\n `Journey transition at index ${index} must define string \"from\" and \"event\".`\n );\n }\n\n if (\n transition.from !== JOURNEY_WILDCARD &&\n !((transition.from as string) in (journey.steps as Record<string, unknown>))\n ) {\n throw new Error(\n `Journey transition at index ${index} references unknown from step \"${transition.from}\".`\n );\n }\n\n if (\n transition.to !== HISTORY_TARGET &&\n !isTerminalTarget(transition.to) &&\n !((transition.to as string) in (journey.steps as Record<string, unknown>))\n ) {\n throw new Error(\n `Journey transition at index ${index} points to unknown step \"${transition.to}\".`\n );\n }\n }\n\n const { clearOnReset, hydrateSnapshot, persistSnapshot, removePersistedSnapshot } =\n createPersistenceController({\n initial: journey.initial,\n context: journey.context,\n steps: journey.steps,\n ...(options ? { options } : {})\n });\n\n const historyOptions: JourneyHistoryOptions<TStepId> | undefined = options?.history;\n\n const runHistoryTrim = (\n nextSnapshot: JourneySnapshot<TContext, TStepId>,\n reason: JourneyHistoryOverflowReason,\n overrideMaxHistory?: number | null\n ): {\n snapshot: JourneySnapshot<TContext, TStepId>;\n trimmed: TStepId[];\n maxHistory: number | null;\n } => {\n const resolvedMaxHistory = resolveMaxHistory(overrideMaxHistory ?? historyOptions?.maxHistory);\n const { next, trimmed } = applyHistoryLimit(nextSnapshot.history, resolvedMaxHistory);\n if (trimmed.length === 0) {\n return {\n snapshot: nextSnapshot,\n trimmed,\n maxHistory: resolvedMaxHistory\n };\n }\n\n const rebuilt = buildSnapshot(\n nextSnapshot.current,\n nextSnapshot.context,\n next,\n nextSnapshot.status,\n nextSnapshot.async,\n nextSnapshot.visited\n );\n\n historyOptions?.onOverflow?.({\n previous: nextSnapshot.history,\n next,\n trimmed,\n maxHistory: resolvedMaxHistory,\n reason\n });\n\n return {\n snapshot: rebuilt,\n trimmed,\n maxHistory: resolvedMaxHistory\n };\n };\n\n let snapshot = hydrateSnapshot();\n const hydratedTrim = runHistoryTrim(snapshot, \"hydrate\");\n snapshot = hydratedTrim.snapshot;\n if (hydratedTrim.trimmed.length > 0) {\n persistSnapshot(snapshot);\n }\n const listeners = new Set<() => void>();\n let sendQueue: Promise<void> = Promise.resolve();\n snapshot = {\n ...snapshot,\n async: buildInitialAsyncState(journey.steps)\n };\n\n const notify = () => {\n for (const listener of listeners) {\n listener();\n }\n };\n\n const isAsyncLoadingPhase = (phase: JourneyAsyncPhase): boolean =>\n phase === JOURNEY_ASYNC_PHASE.EVALUATING_WHEN || phase === JOURNEY_ASYNC_PHASE.RUNNING_EFFECT;\n\n const updateStepAsync = (\n stepId: TStepId,\n updater: (\n current: JourneyAsyncState<TStepId>[\"byStep\"][TStepId]\n ) => JourneyAsyncState<TStepId>[\"byStep\"][TStepId]\n ) => {\n const current = snapshot.async.byStep[stepId] ?? buildIdleStepAsyncState();\n const next = updater(current);\n if (\n current.phase === next.phase &&\n current.eventType === next.eventType &&\n current.transitionId === next.transitionId &&\n current.error === next.error\n ) {\n return;\n }\n const nextByStep = {\n ...snapshot.async.byStep,\n [stepId]: next\n };\n const isLoading = Object.values(nextByStep).some((state) => isAsyncLoadingPhase(state.phase));\n snapshot = {\n ...snapshot,\n async: {\n isLoading,\n byStep: nextByStep\n }\n };\n notify();\n };\n\n const setStepLoading = (\n stepId: TStepId,\n phase: JourneyAsyncPhase,\n eventType: string,\n transitionId?: string\n ) => {\n updateStepAsync(stepId, () => ({\n phase,\n eventType,\n transitionId: transitionId ?? null,\n error: null\n }));\n };\n\n const setStepIdle = (stepId: TStepId) => {\n updateStepAsync(stepId, () => buildIdleStepAsyncState());\n };\n\n const setStepError = (\n stepId: TStepId,\n eventType: string,\n error: unknown,\n transitionId?: string\n ) => {\n updateStepAsync(stepId, () => ({\n phase: JOURNEY_ASYNC_PHASE.ERROR,\n eventType,\n transitionId: transitionId ?? null,\n error\n }));\n };\n\n return {\n getSnapshot: () => snapshot,\n subscribe: (listener) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n reset: () => {\n snapshot = buildSnapshot(\n journey.initial,\n journey.context,\n [],\n JOURNEY_STATUS.RUNNING,\n buildInitialAsyncState(journey.steps)\n );\n if (clearOnReset) {\n removePersistedSnapshot();\n } else {\n persistSnapshot(snapshot);\n }\n notify();\n return snapshot;\n },\n updateContext: (updater) => {\n snapshot = {\n ...snapshot,\n context: updater(snapshot.context)\n };\n persistSnapshot(snapshot);\n notify();\n return snapshot;\n },\n clearStepError: (stepId) => {\n const resolvedStep = stepId ?? snapshot.current;\n if (!(resolvedStep in journey.steps)) {\n return snapshot;\n }\n\n setStepIdle(resolvedStep);\n return snapshot;\n },\n trimHistory: (maxHistory) => {\n const result = runHistoryTrim(snapshot, \"manual\", maxHistory);\n if (result.trimmed.length === 0) {\n return snapshot;\n }\n snapshot = result.snapshot;\n persistSnapshot(snapshot);\n notify();\n return snapshot;\n },\n clearHistory: () => {\n if (snapshot.history.length === 0) {\n return snapshot;\n }\n snapshot = buildSnapshot(\n snapshot.current,\n snapshot.context,\n [],\n snapshot.status,\n snapshot.async,\n snapshot.visited\n );\n persistSnapshot(snapshot);\n notify();\n return snapshot;\n },\n send: (event) => {\n const run = async (): Promise<JourneySendResult<TContext, TStepId>> => {\n if (snapshot.status !== JOURNEY_STATUS.RUNNING) {\n return { transitioned: false, snapshot };\n }\n\n const fromStep = snapshot.current;\n\n if (isGoToEvent(event)) {\n assertStepExists(journey.steps, event.to, `Cannot goTo unknown step \"${event.to}\".`);\n setStepIdle(fromStep);\n snapshot = transitionSnapshot(snapshot, event.to, snapshot.context);\n snapshot = runHistoryTrim(snapshot, \"auto\").snapshot;\n persistSnapshot(snapshot);\n notify();\n return buildSendResult(snapshot, true, JOURNEY_EVENT.GO_TO);\n }\n\n let transition;\n try {\n transition = await selectTransition(journey.transitions, snapshot, event, {\n onAsyncGuardStart: (currentTransition) => {\n setStepLoading(\n fromStep,\n JOURNEY_ASYNC_PHASE.EVALUATING_WHEN,\n event.type,\n currentTransition.id\n );\n },\n onAsyncGuardSuccess: () => {\n setStepIdle(fromStep);\n },\n onAsyncGuardError: (currentTransition, error) => {\n setStepError(fromStep, event.type, error, currentTransition.id);\n }\n });\n } catch (error) {\n setStepError(fromStep, event.type, error);\n throw error;\n }\n\n if (!transition) {\n return buildSendResult(snapshot, false);\n }\n\n let nextContext = snapshot.context;\n if (transition.effect) {\n const effectResultPromise = transition.effect({\n context: snapshot.context,\n from: snapshot.current,\n history: snapshot.history,\n event\n });\n if (isPromiseLike(effectResultPromise)) {\n setStepLoading(\n fromStep,\n JOURNEY_ASYNC_PHASE.RUNNING_EFFECT,\n event.type as string,\n transition.id\n );\n }\n\n let effectResult: TContext | void;\n try {\n effectResult = await effectResultPromise;\n } catch (error) {\n setStepError(fromStep, event.type, error, transition.id);\n throw error;\n }\n\n if (effectResult !== undefined) {\n nextContext = effectResult;\n }\n }\n\n setStepIdle(fromStep);\n\n if (isTerminalTarget(transition.to)) {\n snapshot = {\n ...snapshot,\n context: nextContext,\n status:\n transition.to === JOURNEY_TERMINAL.COMPLETE\n ? JOURNEY_STATUS.COMPLETE\n : JOURNEY_STATUS.CLOSED\n };\n snapshot = runHistoryTrim(snapshot, \"auto\").snapshot;\n persistSnapshot(snapshot);\n notify();\n return buildSendResult(snapshot, true, transition.id);\n }\n\n if (transition.to === HISTORY_TARGET) {\n const { target, history } = resolveHistoryTarget(snapshot, journey.steps);\n assertStepExists(journey.steps, target, `Transition points to unknown step \"${target}\".`);\n const visited = appendVisited(snapshot.visited, target);\n snapshot = buildSnapshot(\n target,\n nextContext,\n history,\n snapshot.status,\n snapshot.async,\n visited\n );\n snapshot = runHistoryTrim(snapshot, \"auto\").snapshot;\n persistSnapshot(snapshot);\n notify();\n return buildSendResult(snapshot, true, transition.id);\n }\n\n const resolvedTarget = transition.to;\n\n assertStepExists(\n journey.steps,\n resolvedTarget,\n `Transition points to unknown step \"${resolvedTarget}\".`\n );\n\n const nextSnapshot = transitionSnapshot(snapshot, resolvedTarget, nextContext);\n snapshot = runHistoryTrim(nextSnapshot, \"auto\").snapshot;\n persistSnapshot(snapshot);\n notify();\n\n return buildSendResult(snapshot, true, transition.id);\n };\n\n const resultPromise = sendQueue.then(run, run);\n sendQueue = resultPromise.then(\n () => undefined,\n () => undefined\n );\n return resultPromise;\n }\n };\n};\n"],
5
- "mappings": "ibAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,oBAAAE,EAAA,wBAAAC,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,qBAAAC,EAAA,qBAAAC,EAAA,yBAAAC,EAAA,gCAAAC,IAAA,eAAAC,GAAAV,ICAO,IAAMW,EAAmB,CAC9B,SAAU,WACV,MAAO,OACT,EAIaC,EAAiB,CAC5B,QAAS,UACT,SAAU,WACV,OAAQ,QACV,EAIaC,EAAiB,cACjBC,EAAmB,IAEnBC,EAAgB,CAC3B,MAAO,MACT,E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EY_EVENT", "JOURNEY_STATUS", "JOURNEY_TERMINAL", "JOURNEY_WILDCARD", "createJourneyMachine", "createPersistenceController", "__toCommonJS", "JOURNEY_TERMINAL", "JOURNEY_STATUS", "HISTORY_TARGET", "JOURNEY_WILDCARD", "JOURNEY_EVENT", "JOURNEY_ASYNC_PHASE", "assertStepExists", "steps", "stepId", "message", "unique", "items", "buildVisited", "history", "current", "appendVisited", "visited", "isPromiseLike", "value", "buildIdleStepAsyncState", "JOURNEY_ASYNC_PHASE", "buildInitialAsyncState", "isGoToEvent", "event", "JOURNEY_EVENT", "isTerminalTarget", "target", "JOURNEY_TERMINAL", "buildSendResult", "snapshot", "transitioned", "transitionId", "buildSnapshot", "context", "status", "asyncState", "resolveHistoryTarget", "cloned", "candidate", "selectTransition", "transitions", "hooks", "transition", "fromMatches", "JOURNEY_WILDCARD", "eventMatches", "guardResult", "asyncGuard", "allowed", "error", "transitionSnapshot", "nextCurrent", "nextContext", "isRecord", "value", "isStatusValue", "JOURNEY_STATUS", "resolveDefaultStorage", "localStorageCandidate", "resolvePersistence", "options", "storage", "coercePersistedSnapshot", "steps", "fallbackContext", "currentValue", "current", "history", "step", "status", "visitedRaw", "visited", "buildVisited", "needsRewrite", "createPersistenceController", "args", "initial", "context", "persistence", "reportPersistenceError", "error", "persistSnapshot", "snapshot", "persistedState", "removePersistedSnapshot", "hydrateSnapshot", "initialSnapshot", "buildSnapshot", "buildInitialAsyncState", "rawPersisted", "parsed", "persistedVersion", "persistedSnapshot", "shouldRewritePersisted", "coerced", "migrated", "hydratedSnapshot", "DEFAULT_MAX_HISTORY", "resolveMaxHistory", "value", "applyHistoryLimit", "history", "maxHistory", "trimCount", "createJourneyMachine", "journey", "options", "assertStepExists", "index", "transition", "JOURNEY_WILDCARD", "HISTORY_TARGET", "isTerminalTarget", "clearOnReset", "hydrateSnapshot", "persistSnapshot", "removePersistedSnapshot", "createPersistenceController", "historyOptions", "runHistoryTrim", "nextSnapshot", "reason", "overrideMaxHistory", "resolvedMaxHistory", "next", "trimmed", "rebuilt", "buildSnapshot", "snapshot", "hydratedTrim", "listeners", "sendQueue", "buildInitialAsyncState", "notify", "listener", "isAsyncLoadingPhase", "phase", "JOURNEY_ASYNC_PHASE", "updateStepAsync", "stepId", "updater", "current", "buildIdleStepAsyncState", "nextByStep", "isLoading", "state", "setStepLoading", "eventType", "transitionId", "setStepIdle", "setStepError", "error", "JOURNEY_STATUS", "resolvedStep", "result", "event", "run", "fromStep", "isGoToEvent", "transitionSnapshot", "buildSendResult", "JOURNEY_EVENT", "selectTransition", "currentTransition", "nextContext", "effectResultPromise", "isPromiseLike", "effectResult", "JOURNEY_TERMINAL", "target", "resolveHistoryTarget", "visited", "appendVisited", "resolvedTarget", "resultPromise"]
3
+ "sources": ["../src/index.ts", "../src/types/journey.types.ts", "../src/machine-helpers.ts", "../src/persistence.ts", "../src/machine.ts", "../src/transitions.ts"],
4
+ "sourcesContent": ["export { createJourneyMachine } from \"./machine\";\nexport { createPersistenceController } from \"./persistence\";\nexport { createTransitions, tx } from \"./transitions\";\nexport {\n JOURNEY_EVENT,\n JOURNEY_ASYNC_PHASE,\n JOURNEY_STATUS,\n JOURNEY_WILDCARD,\n type JourneyBuiltInEvent,\n type JourneyBuiltInFrom,\n type JourneyDefaultEventType,\n type JourneyAsyncPhase,\n type JourneyStatus,\n type JourneyAsyncState,\n type JourneyStepAsyncState,\n type JourneyEvent,\n type JourneyEventPayloadMap,\n type JourneyDefinition,\n type JourneyMachineOptions,\n type JourneyGoToEvent,\n type JourneyMachine,\n type JourneyObservationEvent,\n type JourneyPayloadFor,\n type JourneyPersistedSnapshot,\n type JourneyPersistedState,\n type JourneyPersistenceOptions,\n type JourneyStepDefinition,\n type JourneyStorage,\n type JourneySendResult,\n type JourneySnapshot,\n type JourneyTerminal,\n type JourneyTransition,\n type JourneyTransitionArgs,\n type JourneyTransitionTarget\n} from \"./types\";\n", "import type { JourneyPersistenceOptions } from \"./persistence.types\";\nimport type { JourneyTransition } from \"./transitions.types\";\n\nexport type JourneyTerminal = \"COMPLETE\" | \"TERMINATED\";\n\nexport const JOURNEY_STATUS = {\n RUNNING: \"running\",\n COMPLETE: \"complete\",\n TERMINATED: \"terminated\"\n} as const;\n\nexport type JourneyStatus = (typeof JOURNEY_STATUS)[keyof typeof JOURNEY_STATUS];\n\nexport const JOURNEY_WILDCARD = \"*\" as const;\n\nexport const JOURNEY_EVENT = {\n GO_TO_STEP_BY_ID: \"goToStepById\"\n} as const;\n\nexport type JourneyBuiltInEvent = (typeof JOURNEY_EVENT)[keyof typeof JOURNEY_EVENT];\nexport type JourneyBuiltInFrom = typeof JOURNEY_WILDCARD;\nexport type JourneyDefaultEventType =\n | \"goToNextStep\"\n | \"goToPreviousStep\"\n | \"terminateJourney\"\n | \"completeJourney\";\n\nexport const JOURNEY_ASYNC_PHASE = {\n IDLE: \"idle\",\n EVALUATING_WHEN: \"evaluating-when\",\n RUNNING_EFFECT: \"running-effect\",\n ERROR: \"error\"\n} as const;\n\nexport type JourneyAsyncPhase = (typeof JOURNEY_ASYNC_PHASE)[keyof typeof JOURNEY_ASYNC_PHASE];\n\nexport type JourneyStepAsyncState = {\n phase: JourneyAsyncPhase;\n eventType: string | null;\n transitionId: string | null;\n error: unknown | null;\n};\n\nexport type JourneyAsyncState<TStepId extends string> = {\n isLoading: boolean;\n byStep: Record<TStepId, JourneyStepAsyncState>;\n};\n\nexport type JourneyBaseEvent = {\n type: string;\n payload?: unknown;\n};\n\nexport type JourneyEventPayloadMap<TEventType extends string> = Partial<\n Record<TEventType | JourneyBuiltInEvent, unknown>\n>;\n\nexport type JourneyPayloadFor<\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>,\n TEvent extends TEventType | JourneyBuiltInEvent\n> = TEvent extends keyof TPayloadMap ? TPayloadMap[TEvent] : unknown;\n\ntype JourneyPayloadForDefaultEvent<\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>,\n TDefaultEvent extends JourneyDefaultEventType\n> = JourneyPayloadFor<\n TEventType | TDefaultEvent,\n TPayloadMap & JourneyEventPayloadMap<TDefaultEvent>,\n TDefaultEvent\n>;\n\nexport type JourneyGoToEvent<TStepId extends string, TPayload = unknown> = {\n type: (typeof JOURNEY_EVENT)[\"GO_TO_STEP_BY_ID\"];\n stepId: TStepId;\n payload?: TPayload;\n};\n\nexport type JourneyEvent<\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>\n> =\n | JourneyGoToEvent<\n TStepId,\n JourneyPayloadFor<TEventType, TPayloadMap, (typeof JOURNEY_EVENT)[\"GO_TO_STEP_BY_ID\"]>\n >\n | {\n [TType in TEventType]: {\n type: TType;\n payload?: JourneyPayloadFor<TEventType, TPayloadMap, TType>;\n };\n }[TEventType];\n\nexport type JourneyStepDefinition<TStepMeta = unknown> = {\n meta?: TStepMeta;\n} & Record<string, unknown>;\n\nexport type JourneySnapshot<TContext, TStepId extends string, TStepMeta = unknown> = {\n currentStepId: TStepId;\n history: {\n timeline: readonly TStepId[];\n index: number;\n };\n context: TContext;\n visited: Record<TStepId, boolean>;\n stepMeta: Record<TStepId, TStepMeta>;\n status: JourneyStatus;\n async: JourneyAsyncState<TStepId>;\n};\n\nexport type JourneyDefinition<\n TContext,\n TStepId extends string = string,\n TEventType extends string = JourneyDefaultEventType,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>,\n TStepMeta = unknown\n> = {\n initial: TStepId;\n context: TContext;\n steps: Record<TStepId, JourneyStepDefinition<TStepMeta>>;\n transitions: readonly JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[];\n};\n\nexport type JourneyMachineOptions<TContext, TStepId extends string, TStepMeta = unknown> = {\n persistence?: JourneyPersistenceOptions<TContext, TStepId, TStepMeta>;\n};\n\nexport type JourneySendResult<TContext, TStepId extends string, TStepMeta = unknown> = {\n transitioned: boolean;\n transitionId?: string;\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>;\n};\n\nexport type JourneyObservationEvent<\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>,\n TStepMeta = unknown\n> =\n | {\n type: \"transition.start\";\n from: TStepId;\n event: JourneyEvent<TStepId, TEventType, TPayloadMap>;\n timestamp: number;\n }\n | {\n type: \"transition.success\";\n from: TStepId;\n to: TStepId | JourneyTerminal;\n eventType: string;\n transitionId: string | null;\n timestamp: number;\n }\n | {\n type: \"transition.error\";\n from: TStepId;\n eventType: string;\n transitionId: string | null;\n error: unknown;\n timestamp: number;\n }\n | {\n type: \"step.exit\";\n stepId: TStepId;\n timestamp: number;\n }\n | {\n type: \"step.enter\";\n stepId: TStepId;\n timestamp: number;\n }\n | {\n type: \"journey.complete\";\n stepId: TStepId;\n timestamp: number;\n }\n | {\n type: \"journey.close\";\n stepId: TStepId;\n timestamp: number;\n }\n | {\n type: \"navigation.previous\";\n from: TStepId;\n to: TStepId;\n requestedSteps: number;\n appliedSteps: number;\n timestamp: number;\n }\n | {\n type: \"navigation.lastVisited\";\n from: TStepId;\n to: TStepId;\n timestamp: number;\n }\n | {\n type: \"metadata.updated\";\n stepId: TStepId;\n previous: TStepMeta;\n next: TStepMeta;\n timestamp: number;\n };\n\nexport type JourneyMachine<\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>,\n TStepMeta = unknown\n> = {\n getSnapshot: () => JourneySnapshot<TContext, TStepId, TStepMeta>;\n send: (\n event: JourneyEvent<TStepId, TEventType, TPayloadMap>\n ) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;\n goToNextStep: () => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;\n terminateJourney: (\n payload?: JourneyPayloadForDefaultEvent<TEventType, TPayloadMap, \"terminateJourney\">\n ) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;\n completeJourney: (\n payload?: JourneyPayloadForDefaultEvent<TEventType, TPayloadMap, \"completeJourney\">\n ) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;\n goToPreviousStep: (steps?: number) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;\n goToLastVisitedStep: () => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;\n updateContext: (\n updater: (context: TContext) => TContext\n ) => JourneySnapshot<TContext, TStepId, TStepMeta>;\n updateStepMetadata: (\n stepId: TStepId,\n updater: (metadata: TStepMeta) => TStepMeta\n ) => JourneySnapshot<TContext, TStepId, TStepMeta>;\n clearStepError: (stepId?: TStepId) => JourneySnapshot<TContext, TStepId, TStepMeta>;\n resetMachine: () => JourneySnapshot<TContext, TStepId, TStepMeta>;\n subscribe: (listener: () => void) => () => void;\n subscribeEvent: (\n listener: (event: JourneyObservationEvent<TStepId, TEventType, TPayloadMap, TStepMeta>) => void\n ) => () => void;\n};\n", "import { JOURNEY_ASYNC_PHASE, JOURNEY_EVENT, JOURNEY_WILDCARD } from \"./types\";\nimport type {\n JourneyAsyncState,\n JourneyEvent,\n JourneyEventPayloadMap,\n JourneyGoToEvent,\n JourneyPayloadFor,\n JourneySendResult,\n JourneySnapshot,\n JourneyStatus,\n JourneyStepAsyncState,\n JourneyTerminal,\n JourneyTransition\n} from \"./types\";\n\nexport const assertStepExists = <TStepId extends string>(\n steps: Record<TStepId, unknown>,\n stepId: TStepId,\n message: string\n) => {\n if (!(stepId in steps)) {\n throw new Error(message);\n }\n};\n\nexport const normalizeStepCount = (steps?: number): number => {\n if (typeof steps !== \"number\" || !Number.isFinite(steps)) {\n return 1;\n }\n return Math.max(1, Math.trunc(steps));\n};\n\nexport const now = (): number => Date.now();\n\nconst unique = <T>(items: readonly T[]): T[] => [...new Set(items)];\n\nconst normalizeVisited = <TStepId extends string>(\n visited: Record<TStepId, boolean>,\n stepIds: readonly TStepId[]\n): Record<TStepId, boolean> =>\n Object.fromEntries(stepIds.map((stepId) => [stepId, visited[stepId] === true])) as Record<\n TStepId,\n boolean\n >;\n\nexport const buildVisitedFromTimeline = <TStepId extends string>(\n timeline: readonly TStepId[],\n stepIds?: readonly TStepId[]\n): Record<TStepId, boolean> => {\n const resolvedStepIds = stepIds ?? unique(timeline);\n const visited = Object.fromEntries(resolvedStepIds.map((stepId) => [stepId, false])) as Record<\n TStepId,\n boolean\n >;\n\n for (const stepId of timeline) {\n visited[stepId] = true;\n }\n\n return visited;\n};\n\nexport const appendVisited = <TStepId extends string>(\n visited: Record<TStepId, boolean>,\n current: TStepId\n): Record<TStepId, boolean> => ({\n ...visited,\n [current]: true\n});\n\nexport const isPromiseLike = <T>(value: T | PromiseLike<T>): value is PromiseLike<T> =>\n typeof value === \"object\" &&\n value !== null &&\n \"then\" in value &&\n typeof (value as { then: unknown }).then === \"function\";\n\nexport const buildIdleStepAsyncState = (): JourneyStepAsyncState => ({\n phase: JOURNEY_ASYNC_PHASE.IDLE,\n eventType: null,\n transitionId: null,\n error: null\n});\n\nexport const buildInitialAsyncState = <TStepId extends string>(\n steps: Record<TStepId, unknown>\n): JourneyAsyncState<TStepId> => {\n const byStep = Object.fromEntries(\n Object.keys(steps).map((stepId) => [stepId, buildIdleStepAsyncState()])\n ) as Record<TStepId, JourneyStepAsyncState>;\n\n return {\n isLoading: false,\n byStep\n };\n};\n\nexport const isGoToStepByIdEvent = <\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>\n>(\n event: JourneyEvent<TStepId, TEventType, TPayloadMap>\n): event is JourneyGoToEvent<\n TStepId,\n JourneyPayloadFor<TEventType, TPayloadMap, (typeof JOURNEY_EVENT)[\"GO_TO_STEP_BY_ID\"]>\n> => event.type === JOURNEY_EVENT.GO_TO_STEP_BY_ID && \"stepId\" in event;\n\nexport const isTerminalTarget = <TStepId extends string>(\n target: TStepId | JourneyTerminal\n): target is JourneyTerminal => target === \"COMPLETE\" || target === \"TERMINATED\";\n\nexport const validateJourneyTransitions = <\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>\n>(\n transitions: readonly JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[],\n steps: Record<TStepId, unknown>\n) => {\n const stepRegistry = steps as Record<string, unknown>;\n\n for (const [index, transition] of transitions.entries()) {\n if (!transition || typeof transition !== \"object\") {\n throw new Error(`Journey transition at index ${index} must be an object.`);\n }\n\n if (typeof transition.from !== \"string\" || typeof transition.event !== \"string\") {\n throw new Error(\n `Journey transition at index ${index} must define string \"from\" and \"event\".`\n );\n }\n\n if (transition.from !== JOURNEY_WILDCARD && !(transition.from in stepRegistry)) {\n throw new Error(\n `Journey transition at index ${index} references unknown from step \"${transition.from}\".`\n );\n }\n\n if (transition.event === \"completeJourney\" || transition.event === \"terminateJourney\") {\n if (\"to\" in transition && transition.to !== undefined) {\n throw new Error(\n `Journey transition at index ${index} with event \"${transition.event}\" cannot define \"to\".`\n );\n }\n continue;\n }\n\n if (typeof transition.to !== \"string\") {\n throw new Error(\n `Journey transition at index ${index} with event \"${transition.event}\" must define string \"to\".`\n );\n }\n\n if (!isTerminalTarget(transition.to) && !(transition.to in stepRegistry)) {\n throw new Error(\n `Journey transition at index ${index} points to unknown step \"${transition.to}\".`\n );\n }\n }\n};\n\nexport const buildSendResult = <TContext, TStepId extends string, TStepMeta>(\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>,\n transitioned: boolean,\n transitionId?: string\n): JourneySendResult<TContext, TStepId, TStepMeta> =>\n transitionId ? { transitioned, transitionId, snapshot } : { transitioned, snapshot };\n\nexport const buildSnapshot = <TContext, TStepId extends string, TStepMeta>(\n timeline: readonly TStepId[],\n index: number,\n context: TContext,\n status: JourneyStatus,\n asyncState: JourneyAsyncState<TStepId>,\n stepMeta: Record<TStepId, TStepMeta>,\n visited?: Record<TStepId, boolean>\n): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n if (timeline.length === 0) {\n throw new Error(\"Journey timeline cannot be empty.\");\n }\n const safeIndex = Math.max(0, Math.min(Math.trunc(index), timeline.length - 1));\n const currentStepId = timeline[safeIndex] as TStepId;\n const stepIds = Object.keys(stepMeta) as TStepId[];\n return {\n status,\n currentStepId,\n history: {\n timeline: [...timeline],\n index: safeIndex\n },\n context,\n visited: visited\n ? normalizeVisited(visited, stepIds)\n : buildVisitedFromTimeline(timeline, stepIds),\n stepMeta: { ...stepMeta },\n async: asyncState\n };\n};\n\nexport const selectTransition = async <\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>,\n TStepMeta\n>(\n transitions: readonly JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[],\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>,\n event: JourneyEvent<TStepId, TEventType, TPayloadMap>,\n hooks?: {\n onAsyncGuardStart?: (\n transition: JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>\n ) => void;\n onAsyncGuardSuccess?: (\n transition: JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>\n ) => void;\n onAsyncGuardError?: (\n transition: JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>,\n error: unknown\n ) => void;\n }\n): Promise<JourneyTransition<TContext, TStepId, TEventType, TPayloadMap> | null> => {\n for (const transition of transitions) {\n const fromMatches =\n transition.from === JOURNEY_WILDCARD || transition.from === snapshot.currentStepId;\n const eventMatches = transition.event === event.type;\n\n if (!fromMatches || !eventMatches) {\n continue;\n }\n\n if (!transition.when) {\n return transition;\n }\n\n const guardResult = transition.when({\n context: snapshot.context,\n from: snapshot.currentStepId,\n timeline: snapshot.history.timeline,\n index: snapshot.history.index,\n event\n });\n const asyncGuard = isPromiseLike(guardResult);\n if (asyncGuard) {\n hooks?.onAsyncGuardStart?.(transition);\n }\n\n let allowed: boolean;\n try {\n allowed = await guardResult;\n } catch (error) {\n if (asyncGuard) {\n hooks?.onAsyncGuardError?.(transition, error);\n }\n throw error;\n }\n\n if (asyncGuard) {\n hooks?.onAsyncGuardSuccess?.(transition);\n }\n\n if (allowed) {\n return transition;\n }\n }\n\n return null;\n};\n\nexport const transitionSnapshot = <TContext, TStepId extends string, TStepMeta>(\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>,\n nextCurrent: TStepId,\n nextContext: TContext\n): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n const baseTimeline = snapshot.history.timeline.slice(0, snapshot.history.index + 1);\n let nextTimeline = baseTimeline;\n if (nextCurrent !== snapshot.currentStepId) {\n nextTimeline = [...baseTimeline, nextCurrent];\n }\n\n const nextIndex = nextTimeline.length - 1;\n const visited = appendVisited(snapshot.visited, nextCurrent);\n\n return buildSnapshot(\n nextTimeline,\n nextIndex,\n nextContext,\n snapshot.status,\n snapshot.async,\n snapshot.stepMeta,\n visited\n );\n};\n", "import { JOURNEY_STATUS } from \"./types/journey.types\";\nimport type {\n JourneyPersistedSnapshot,\n JourneyPersistedState,\n JourneyStorage,\n ResolvedPersistence\n} from \"./types/persistence.types\";\nimport type { JourneyMachineOptions, JourneySnapshot, JourneyStatus } from \"./types/journey.types\";\nimport { buildInitialAsyncState, buildSnapshot, buildVisitedFromTimeline } from \"./machine-helpers\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isStatusValue = (value: unknown): value is JourneyStatus =>\n value === JOURNEY_STATUS.RUNNING ||\n value === JOURNEY_STATUS.COMPLETE ||\n value === JOURNEY_STATUS.TERMINATED;\n\nconst resolveDefaultStorage = (): JourneyStorage | null => {\n const localStorageCandidate = (globalThis as { localStorage?: Partial<JourneyStorage> })\n .localStorage;\n\n if (\n !localStorageCandidate ||\n typeof localStorageCandidate.getItem !== \"function\" ||\n typeof localStorageCandidate.setItem !== \"function\" ||\n typeof localStorageCandidate.removeItem !== \"function\"\n ) {\n return null;\n }\n\n return localStorageCandidate as JourneyStorage;\n};\n\nconst resolvePersistence = <TContext, TStepId extends string, TStepMeta>(\n options?: JourneyMachineOptions<TContext, TStepId, TStepMeta>[\"persistence\"]\n): ResolvedPersistence<TContext, TStepId, TStepMeta> | null => {\n if (!options) {\n return null;\n }\n\n const storage = options.storage ?? resolveDefaultStorage();\n if (!storage) {\n return null;\n }\n\n return {\n key: options.key,\n storage,\n version: options.version ?? 1,\n clearOnReset: options.clearOnReset ?? true,\n serialize: options.serialize ?? JSON.stringify,\n deserialize: options.deserialize ?? JSON.parse,\n ...(options.migrate ? { migrate: options.migrate } : {}),\n ...(options.onError ? { onError: options.onError } : {})\n };\n};\n\nconst coercePersistedSnapshot = <TContext, TStepId extends string, TStepMeta>(\n value: unknown,\n steps: Record<TStepId, unknown>,\n fallbackContext: TContext,\n fallbackStepMeta: Record<TStepId, TStepMeta>\n): {\n snapshot: JourneyPersistedSnapshot<TContext, TStepId, TStepMeta>;\n needsRewrite: boolean;\n} | null => {\n if (!isRecord(value)) {\n return null;\n }\n\n let needsRewrite = false;\n\n const rawHistory = isRecord(value.history) ? value.history : null;\n if (!rawHistory) {\n needsRewrite = true;\n }\n\n const rawTimeline = rawHistory?.timeline ?? value.timeline;\n const timeline = Array.isArray(rawTimeline)\n ? (rawTimeline.filter(\n (step): step is TStepId => typeof step === \"string\" && step in steps\n ) as TStepId[])\n : [];\n\n const currentStepIdValue =\n typeof value.currentStepId === \"string\" && value.currentStepId in steps\n ? (value.currentStepId as TStepId)\n : typeof value.current === \"string\" && value.current in steps\n ? (value.current as TStepId)\n : null;\n\n if (timeline.length === 0) {\n if (!currentStepIdValue) {\n return null;\n }\n timeline.push(currentStepIdValue);\n needsRewrite = true;\n }\n\n let index = timeline.length - 1;\n const rawIndex = rawHistory?.index ?? value.index;\n if (typeof rawIndex === \"number\" && Number.isFinite(rawIndex)) {\n index = Math.max(0, Math.min(Math.trunc(rawIndex), timeline.length - 1));\n if (index !== rawIndex) {\n needsRewrite = true;\n }\n } else if (currentStepIdValue) {\n const inferredIndex = timeline.lastIndexOf(currentStepIdValue);\n if (inferredIndex >= 0) {\n index = inferredIndex;\n needsRewrite = true;\n }\n }\n\n const status = isStatusValue(value.status) ? value.status : JOURNEY_STATUS.RUNNING;\n if (!isStatusValue(value.status)) {\n needsRewrite = true;\n }\n\n const stepIds = Object.keys(steps) as TStepId[];\n const visitedSource = value.visited;\n const visitedFromRecord = isRecord(visitedSource)\n ? (Object.fromEntries(\n stepIds.map((stepId) => [stepId, visitedSource[stepId] === true])\n ) as Record<TStepId, boolean>)\n : null;\n const visitedFromArray = Array.isArray(visitedSource)\n ? buildVisitedFromTimeline(\n visitedSource.filter(\n (step): step is TStepId => typeof step === \"string\" && step in steps\n ) as TStepId[],\n stepIds\n )\n : null;\n\n let visited = buildVisitedFromTimeline(timeline, stepIds);\n if (visitedFromRecord) {\n const visitedRecord = visitedSource as Record<string, unknown>;\n visited = visitedFromRecord;\n const hasMissingOrInvalidStep = stepIds.some(\n (stepId) => typeof visitedRecord[stepId] !== \"boolean\"\n );\n if (hasMissingOrInvalidStep) {\n needsRewrite = true;\n }\n } else if (visitedFromArray) {\n visited = visitedFromArray;\n needsRewrite = true;\n } else {\n needsRewrite = true;\n }\n\n const rawStepMeta = isRecord(value.stepMeta) ? value.stepMeta : null;\n if (!rawStepMeta) {\n needsRewrite = true;\n }\n\n const stepMeta = Object.fromEntries(\n Object.keys(steps).map((stepId) => {\n const typedStepId = stepId as TStepId;\n const rawValue = rawStepMeta ? rawStepMeta[stepId] : undefined;\n if (rawValue === undefined) {\n return [typedStepId, fallbackStepMeta[typedStepId]];\n }\n return [typedStepId, rawValue as TStepMeta];\n })\n ) as Record<TStepId, TStepMeta>;\n\n return {\n snapshot: {\n currentStepId: timeline[index] as TStepId,\n history: {\n timeline,\n index\n },\n context: (\"context\" in value ? value.context : fallbackContext) as TContext,\n status,\n visited,\n stepMeta\n },\n needsRewrite\n };\n};\n\n/**\n * Creates a persistence controller for snapshots, including hydration,\n * serialization, and storage error handling.\n */\nexport const createPersistenceController = <TContext, TStepId extends string, TStepMeta>(args: {\n initial: TStepId;\n context: TContext;\n stepMeta: Record<TStepId, TStepMeta>;\n steps: Record<TStepId, unknown>;\n options?: JourneyMachineOptions<TContext, TStepId, TStepMeta>;\n}) => {\n const { initial, context, stepMeta, steps, options } = args;\n const persistence = resolvePersistence(options?.persistence);\n\n const reportPersistenceError = (error: unknown) => {\n persistence?.onError?.(error);\n };\n\n const persistSnapshot = (snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>) => {\n if (!persistence) {\n return;\n }\n\n try {\n const persistedState: JourneyPersistedState<TContext, TStepId, TStepMeta> = {\n version: persistence.version,\n snapshot: {\n currentStepId: snapshot.currentStepId,\n history: {\n timeline: [...snapshot.history.timeline],\n index: snapshot.history.index\n },\n context: snapshot.context,\n status: snapshot.status,\n visited: { ...snapshot.visited },\n stepMeta: { ...snapshot.stepMeta }\n }\n };\n persistence.storage.setItem(persistence.key, persistence.serialize(persistedState));\n } catch (error) {\n reportPersistenceError(error);\n }\n };\n\n const removePersistedSnapshot = () => {\n if (!persistence) {\n return;\n }\n\n try {\n persistence.storage.removeItem(persistence.key);\n } catch (error) {\n reportPersistenceError(error);\n }\n };\n\n const hydrateSnapshot = (): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n const initialSnapshot = buildSnapshot(\n [initial],\n 0,\n context,\n JOURNEY_STATUS.RUNNING,\n buildInitialAsyncState(steps),\n stepMeta\n );\n if (!persistence) {\n return initialSnapshot;\n }\n\n try {\n const rawPersisted = persistence.storage.getItem(persistence.key);\n if (!rawPersisted) {\n return initialSnapshot;\n }\n\n const parsed = persistence.deserialize(rawPersisted);\n if (!isRecord(parsed)) {\n return initialSnapshot;\n }\n\n const persistedVersion = parsed.version;\n if (typeof persistedVersion !== \"number\") {\n return initialSnapshot;\n }\n\n let persistedSnapshot: JourneyPersistedSnapshot<TContext, TStepId, TStepMeta> | null = null;\n let shouldRewritePersisted = false;\n\n if (persistedVersion === persistence.version) {\n const coerced = coercePersistedSnapshot(parsed.snapshot, steps, context, stepMeta);\n persistedSnapshot = coerced?.snapshot ?? null;\n shouldRewritePersisted = Boolean(coerced?.needsRewrite);\n } else if (persistence.migrate) {\n const migrated = persistence.migrate(parsed.snapshot, persistedVersion);\n const coerced = coercePersistedSnapshot(migrated, steps, context, stepMeta);\n persistedSnapshot = coerced?.snapshot ?? null;\n shouldRewritePersisted = persistedSnapshot !== null;\n }\n\n if (!persistedSnapshot) {\n return initialSnapshot;\n }\n\n const hydratedSnapshot = buildSnapshot(\n persistedSnapshot.history.timeline,\n persistedSnapshot.history.index,\n persistedSnapshot.context,\n persistedSnapshot.status,\n buildInitialAsyncState(steps),\n persistedSnapshot.stepMeta,\n persistedSnapshot.visited\n );\n\n if (shouldRewritePersisted) {\n persistSnapshot(hydratedSnapshot);\n }\n\n return hydratedSnapshot;\n } catch (error) {\n reportPersistenceError(error);\n return initialSnapshot;\n }\n };\n\n return {\n clearOnReset: persistence?.clearOnReset ?? true,\n hydrateSnapshot,\n persistSnapshot,\n removePersistedSnapshot\n };\n};\n", "import { JOURNEY_ASYNC_PHASE, JOURNEY_EVENT, JOURNEY_STATUS } from \"./types\";\nimport type {\n JourneyAsyncState,\n JourneyAsyncPhase,\n JourneyDefaultEventType,\n JourneyDefinition,\n JourneyEventPayloadMap,\n JourneyMachine,\n JourneyMachineOptions,\n JourneyObservationEvent,\n JourneySendResult,\n JourneyStepDefinition,\n JourneyTransition,\n JourneyTerminal\n} from \"./types\";\nimport {\n assertStepExists,\n buildIdleStepAsyncState,\n buildInitialAsyncState,\n buildSendResult,\n buildSnapshot,\n isGoToStepByIdEvent,\n isPromiseLike,\n isTerminalTarget,\n normalizeStepCount,\n now,\n selectTransition,\n transitionSnapshot,\n validateJourneyTransitions\n} from \"./machine-helpers\";\nimport { createPersistenceController } from \"./persistence\";\n\n/**\n * Creates a journey machine from a journey definition.\n * Validates steps/transitions, hydrates persisted state (if configured),\n * and returns an API for sending events and reading snapshots.\n */\nexport function createJourneyMachine<\n TContext,\n TStepMeta = unknown,\n TSteps extends Record<string, JourneyStepDefinition<TStepMeta>> = Record<\n string,\n JourneyStepDefinition<TStepMeta>\n >,\n TPayloadMap extends JourneyEventPayloadMap<JourneyDefaultEventType> = Record<never, never>\n>(\n journey: {\n initial: Extract<keyof TSteps, string>;\n context: TContext;\n steps: TSteps;\n transitions: readonly JourneyTransition<\n TContext,\n Extract<keyof TSteps, string>,\n JourneyDefaultEventType,\n TPayloadMap\n >[];\n },\n options?: JourneyMachineOptions<TContext, Extract<keyof TSteps, string>, TStepMeta>\n): JourneyMachine<\n TContext,\n Extract<keyof TSteps, string>,\n JourneyDefaultEventType,\n TPayloadMap,\n TStepMeta\n>;\n// eslint-disable-next-line no-redeclare\nexport function createJourneyMachine<\n TContext,\n TStepId extends string,\n TEventType extends string = JourneyDefaultEventType,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>,\n TStepMeta = unknown\n>(\n journey: JourneyDefinition<TContext, TStepId, TEventType, TPayloadMap, TStepMeta>,\n options?: JourneyMachineOptions<TContext, TStepId, TStepMeta>\n): JourneyMachine<TContext, TStepId, TEventType, TPayloadMap, TStepMeta>;\n// eslint-disable-next-line no-redeclare\nexport function createJourneyMachine<\n TContext,\n TStepId extends string,\n TEventType extends string = JourneyDefaultEventType,\n TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>,\n TStepMeta = unknown\n>(\n journey: JourneyDefinition<TContext, TStepId, TEventType, TPayloadMap, TStepMeta>,\n options?: JourneyMachineOptions<TContext, TStepId, TStepMeta>\n): JourneyMachine<TContext, TStepId, TEventType, TPayloadMap, TStepMeta> {\n if (!journey.steps || typeof journey.steps !== \"object\") {\n throw new Error(\"Journey steps must be a record object.\");\n }\n\n if (!Array.isArray(journey.transitions)) {\n throw new Error(\"Journey transitions must be an array.\");\n }\n\n assertStepExists(\n journey.steps,\n journey.initial,\n `Journey initial step \"${journey.initial}\" does not exist in steps registry.`\n );\n\n validateJourneyTransitions(journey.transitions, journey.steps);\n\n const buildStepMeta = (): Record<TStepId, TStepMeta> =>\n Object.fromEntries(\n Object.entries(journey.steps).map(([stepId, definition]) => [\n stepId,\n (definition as JourneyStepDefinition<TStepMeta>).meta as TStepMeta\n ])\n ) as Record<TStepId, TStepMeta>;\n\n const { clearOnReset, hydrateSnapshot, persistSnapshot, removePersistedSnapshot } =\n createPersistenceController({\n initial: journey.initial,\n context: journey.context,\n stepMeta: buildStepMeta(),\n steps: journey.steps,\n ...(options ? { options } : {})\n });\n\n let snapshot = hydrateSnapshot();\n snapshot = {\n ...snapshot,\n async: buildInitialAsyncState(journey.steps)\n };\n\n const listeners = new Set<() => void>();\n const eventListeners = new Set<\n (event: JourneyObservationEvent<TStepId, TEventType, TPayloadMap, TStepMeta>) => void\n >();\n let actionQueue: Promise<void> = Promise.resolve();\n\n const notify = () => {\n for (const listener of listeners) {\n listener();\n }\n };\n\n const emit = (event: JourneyObservationEvent<TStepId, TEventType, TPayloadMap, TStepMeta>) => {\n for (const listener of eventListeners) {\n listener(event);\n }\n };\n\n const queue = <T>(runner: () => Promise<T>): Promise<T> => {\n const resultPromise = actionQueue.then(runner, runner);\n actionQueue = resultPromise.then(\n () => undefined,\n () => undefined\n );\n return resultPromise;\n };\n\n const isAsyncLoadingPhase = (phase: JourneyAsyncPhase): boolean =>\n phase === JOURNEY_ASYNC_PHASE.EVALUATING_WHEN || phase === JOURNEY_ASYNC_PHASE.RUNNING_EFFECT;\n\n const updateStepAsync = (\n stepId: TStepId,\n updater: (\n current: JourneyAsyncState<TStepId>[\"byStep\"][TStepId]\n ) => JourneyAsyncState<TStepId>[\"byStep\"][TStepId]\n ) => {\n const current = snapshot.async.byStep[stepId] ?? buildIdleStepAsyncState();\n const next = updater(current);\n if (\n current.phase === next.phase &&\n current.eventType === next.eventType &&\n current.transitionId === next.transitionId &&\n current.error === next.error\n ) {\n return;\n }\n\n const nextByStep = {\n ...snapshot.async.byStep,\n [stepId]: next\n };\n const isLoading = Object.values(nextByStep).some((state) => isAsyncLoadingPhase(state.phase));\n snapshot = {\n ...snapshot,\n async: {\n isLoading,\n byStep: nextByStep\n }\n };\n notify();\n };\n\n const setStepLoading = (\n stepId: TStepId,\n phase: JourneyAsyncPhase,\n eventType: string,\n transitionId?: string\n ) => {\n updateStepAsync(stepId, () => ({\n phase,\n eventType,\n transitionId: transitionId ?? null,\n error: null\n }));\n };\n\n const setStepIdle = (stepId: TStepId) => {\n updateStepAsync(stepId, () => buildIdleStepAsyncState());\n };\n\n const setStepError = (\n stepId: TStepId,\n eventType: string,\n error: unknown,\n transitionId?: string\n ) => {\n updateStepAsync(stepId, () => ({\n phase: JOURNEY_ASYNC_PHASE.ERROR,\n eventType,\n transitionId: transitionId ?? null,\n error\n }));\n };\n\n const applyPreviousNavigation = (\n requestedSteps?: number,\n transitionId?: string\n ): JourneySendResult<TContext, TStepId, TStepMeta> => {\n if (snapshot.status !== JOURNEY_STATUS.RUNNING) {\n return buildSendResult(snapshot, false);\n }\n\n const steps = normalizeStepCount(requestedSteps);\n if (snapshot.history.index === 0) {\n return buildSendResult(snapshot, false);\n }\n\n const from = snapshot.currentStepId;\n const nextIndex = Math.max(0, snapshot.history.index - steps);\n const appliedSteps = snapshot.history.index - nextIndex;\n if (appliedSteps <= 0) {\n return buildSendResult(snapshot, false);\n }\n\n emit({ type: \"step.exit\", stepId: from, timestamp: now() });\n snapshot = buildSnapshot(\n snapshot.history.timeline,\n nextIndex,\n snapshot.context,\n snapshot.status,\n snapshot.async,\n snapshot.stepMeta,\n snapshot.visited\n );\n persistSnapshot(snapshot);\n notify();\n\n emit({\n type: \"navigation.previous\",\n from,\n to: snapshot.currentStepId,\n requestedSteps: steps,\n appliedSteps,\n timestamp: now()\n });\n emit({ type: \"step.enter\", stepId: snapshot.currentStepId, timestamp: now() });\n return buildSendResult(snapshot, true, transitionId);\n };\n\n const applyLastVisitedNavigation = (\n transitionId?: string\n ): JourneySendResult<TContext, TStepId, TStepMeta> => {\n if (snapshot.status !== JOURNEY_STATUS.RUNNING) {\n return buildSendResult(snapshot, false);\n }\n\n const targetIndex = snapshot.history.timeline.length - 1;\n if (snapshot.history.index >= targetIndex) {\n return buildSendResult(snapshot, false);\n }\n\n const from = snapshot.currentStepId;\n emit({ type: \"step.exit\", stepId: from, timestamp: now() });\n snapshot = buildSnapshot(\n snapshot.history.timeline,\n targetIndex,\n snapshot.context,\n snapshot.status,\n snapshot.async,\n snapshot.stepMeta,\n snapshot.visited\n );\n persistSnapshot(snapshot);\n notify();\n\n emit({ type: \"navigation.lastVisited\", from, to: snapshot.currentStepId, timestamp: now() });\n emit({ type: \"step.enter\", stepId: snapshot.currentStepId, timestamp: now() });\n return buildSendResult(snapshot, true, transitionId);\n };\n\n const machine: JourneyMachine<TContext, TStepId, TEventType, TPayloadMap, TStepMeta> = {\n getSnapshot: () => snapshot,\n subscribe: (listener) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n subscribeEvent: (listener) => {\n eventListeners.add(listener);\n return () => {\n eventListeners.delete(listener);\n };\n },\n resetMachine: () => {\n snapshot = buildSnapshot(\n [journey.initial],\n 0,\n journey.context,\n JOURNEY_STATUS.RUNNING,\n buildInitialAsyncState(journey.steps),\n buildStepMeta()\n );\n if (clearOnReset) {\n removePersistedSnapshot();\n } else {\n persistSnapshot(snapshot);\n }\n notify();\n return snapshot;\n },\n updateContext: (updater) => {\n snapshot = {\n ...snapshot,\n context: updater(snapshot.context)\n };\n persistSnapshot(snapshot);\n notify();\n return snapshot;\n },\n updateStepMetadata: (stepId, updater) => {\n if (!(stepId in journey.steps)) {\n return snapshot;\n }\n\n const previousMeta = snapshot.stepMeta[stepId];\n const nextMeta = updater(previousMeta);\n if (Object.is(previousMeta, nextMeta)) {\n return snapshot;\n }\n\n snapshot = {\n ...snapshot,\n stepMeta: {\n ...snapshot.stepMeta,\n [stepId]: nextMeta\n }\n };\n persistSnapshot(snapshot);\n notify();\n emit({\n type: \"metadata.updated\",\n stepId,\n previous: previousMeta,\n next: nextMeta,\n timestamp: now()\n });\n return snapshot;\n },\n clearStepError: (stepId) => {\n const resolvedStep = stepId ?? snapshot.currentStepId;\n if (!(resolvedStep in journey.steps)) {\n return snapshot;\n }\n\n setStepIdle(resolvedStep);\n return snapshot;\n },\n goToPreviousStep: (steps) =>\n queue(async () => {\n const result = applyPreviousNavigation(steps, \"goToPreviousStep\");\n return result;\n }),\n goToLastVisitedStep: () =>\n queue(async () => {\n const result = applyLastVisitedNavigation(\"goToLastVisitedStep\");\n return result;\n }),\n goToNextStep: () =>\n machine.send({ type: \"goToNextStep\" } as Extract<\n Parameters<typeof machine.send>[0],\n { type: \"goToNextStep\" }\n >),\n terminateJourney: (payload) =>\n machine.send(\n (payload === undefined\n ? ({ type: \"terminateJourney\" } as unknown)\n : ({ type: \"terminateJourney\", payload } as unknown)) as Extract<\n Parameters<typeof machine.send>[0],\n { type: \"terminateJourney\" }\n >\n ),\n completeJourney: (payload) =>\n machine.send(\n (payload === undefined\n ? ({ type: \"completeJourney\" } as unknown)\n : ({ type: \"completeJourney\", payload } as unknown)) as Extract<\n Parameters<typeof machine.send>[0],\n { type: \"completeJourney\" }\n >\n ),\n send: (event) =>\n queue(async () => {\n if (snapshot.status !== JOURNEY_STATUS.RUNNING) {\n return buildSendResult(snapshot, false);\n }\n\n const fromStep = snapshot.currentStepId;\n\n if (isGoToStepByIdEvent(event)) {\n assertStepExists(\n journey.steps,\n event.stepId,\n `Cannot goToStepById unknown step \"${event.stepId}\".`\n );\n emit({ type: \"transition.start\", from: fromStep, event, timestamp: now() });\n setStepIdle(fromStep);\n\n const beforeCurrent = snapshot.currentStepId;\n const nextSnapshot = transitionSnapshot(snapshot, event.stepId, snapshot.context);\n if (nextSnapshot.currentStepId !== beforeCurrent) {\n emit({ type: \"step.exit\", stepId: beforeCurrent, timestamp: now() });\n }\n\n snapshot = nextSnapshot;\n persistSnapshot(snapshot);\n notify();\n\n emit({\n type: \"transition.success\",\n from: fromStep,\n to: snapshot.currentStepId,\n eventType: JOURNEY_EVENT.GO_TO_STEP_BY_ID,\n transitionId: JOURNEY_EVENT.GO_TO_STEP_BY_ID,\n timestamp: now()\n });\n\n if (nextSnapshot.currentStepId !== beforeCurrent) {\n emit({ type: \"step.enter\", stepId: snapshot.currentStepId, timestamp: now() });\n }\n\n return buildSendResult(snapshot, true, JOURNEY_EVENT.GO_TO_STEP_BY_ID);\n }\n\n emit({ type: \"transition.start\", from: fromStep, event, timestamp: now() });\n\n let transition;\n try {\n transition = await selectTransition(journey.transitions, snapshot, event, {\n onAsyncGuardStart: (currentTransition) => {\n setStepLoading(\n fromStep,\n JOURNEY_ASYNC_PHASE.EVALUATING_WHEN,\n event.type,\n currentTransition.id\n );\n },\n onAsyncGuardSuccess: () => {\n setStepIdle(fromStep);\n },\n onAsyncGuardError: (currentTransition, error) => {\n setStepError(fromStep, event.type, error, currentTransition.id);\n }\n });\n } catch (error) {\n setStepError(fromStep, event.type, error);\n emit({\n type: \"transition.error\",\n from: fromStep,\n eventType: event.type,\n transitionId: null,\n error,\n timestamp: now()\n });\n throw error;\n }\n\n if (!transition) {\n if (event.type === \"goToPreviousStep\" || event.type === \"back\") {\n const fallbackResult = applyPreviousNavigation(1, event.type);\n if (fallbackResult.transitioned) {\n emit({\n type: \"transition.success\",\n from: fromStep,\n to: fallbackResult.snapshot.currentStepId,\n eventType: event.type,\n transitionId: null,\n timestamp: now()\n });\n }\n return fallbackResult;\n }\n\n return buildSendResult(snapshot, false);\n }\n\n let nextContext = snapshot.context;\n if (transition.effect) {\n const effectResultPromise = transition.effect({\n context: snapshot.context,\n from: snapshot.currentStepId,\n timeline: snapshot.history.timeline,\n index: snapshot.history.index,\n event\n });\n if (isPromiseLike(effectResultPromise)) {\n setStepLoading(\n fromStep,\n JOURNEY_ASYNC_PHASE.RUNNING_EFFECT,\n event.type as string,\n transition.id\n );\n }\n\n let effectResult: TContext | void;\n try {\n effectResult = await effectResultPromise;\n } catch (error) {\n setStepError(fromStep, event.type, error, transition.id);\n emit({\n type: \"transition.error\",\n from: fromStep,\n eventType: event.type,\n transitionId: transition.id ?? null,\n error,\n timestamp: now()\n });\n throw error;\n }\n\n if (effectResult !== undefined) {\n nextContext = effectResult;\n }\n }\n\n setStepIdle(fromStep);\n\n const target: TStepId | JourneyTerminal =\n transition.event === \"completeJourney\"\n ? \"COMPLETE\"\n : transition.event === \"terminateJourney\"\n ? \"TERMINATED\"\n : (transition.to as TStepId | JourneyTerminal);\n\n if (isTerminalTarget(target)) {\n const normalizedTimeline = snapshot.history.timeline.slice(0, snapshot.history.index + 1);\n snapshot = {\n ...snapshot,\n history: {\n timeline: normalizedTimeline,\n index: normalizedTimeline.length - 1\n },\n context: nextContext,\n status: target === \"COMPLETE\" ? JOURNEY_STATUS.COMPLETE : JOURNEY_STATUS.TERMINATED\n };\n persistSnapshot(snapshot);\n notify();\n\n emit({\n type: \"transition.success\",\n from: fromStep,\n to: target,\n eventType: event.type,\n transitionId: transition.id ?? null,\n timestamp: now()\n });\n emit({\n type: target === \"COMPLETE\" ? \"journey.complete\" : \"journey.close\",\n stepId: snapshot.currentStepId,\n timestamp: now()\n });\n\n return buildSendResult(snapshot, true, transition.id);\n }\n\n const resolvedTarget = target;\n\n assertStepExists(\n journey.steps,\n resolvedTarget,\n `Transition points to unknown step \"${resolvedTarget}\".`\n );\n\n const beforeCurrent = snapshot.currentStepId;\n if (beforeCurrent !== resolvedTarget) {\n emit({ type: \"step.exit\", stepId: beforeCurrent, timestamp: now() });\n }\n snapshot = transitionSnapshot(snapshot, resolvedTarget, nextContext);\n persistSnapshot(snapshot);\n notify();\n\n emit({\n type: \"transition.success\",\n from: fromStep,\n to: snapshot.currentStepId,\n eventType: event.type,\n transitionId: transition.id ?? null,\n timestamp: now()\n });\n if (beforeCurrent !== snapshot.currentStepId) {\n emit({ type: \"step.enter\", stepId: snapshot.currentStepId, timestamp: now() });\n }\n\n return buildSendResult(snapshot, true, transition.id);\n })\n };\n\n return machine;\n}\n", "import { JOURNEY_WILDCARD } from \"./types/journey.types\";\nimport type { JourneyEventPayloadMap } from \"./types/journey.types\";\nimport type {\n EventBuilder,\n JourneyEventTransition,\n JourneyTransition,\n JourneyTransitionArgs,\n JourneyTransitionTarget,\n TransitionBranch,\n TransitionConfig\n} from \"./types/transitions.types\";\n\nconst createEventBuilder = <\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>\n>(\n from: TStepId | typeof JOURNEY_WILDCARD,\n event: TEventType\n): EventBuilder<TContext, TStepId, TEventType, TPayloadMap> => {\n if (event === \"completeJourney\") {\n return {\n complete: (\n config: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap> = {}\n ): JourneyTransition<TContext, TStepId, TEventType, TPayloadMap> =>\n ({\n ...config,\n from,\n event: event as Extract<TEventType, \"completeJourney\">\n }) as JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>\n } as EventBuilder<TContext, TStepId, TEventType, TPayloadMap>;\n }\n\n if (event === \"terminateJourney\") {\n return {\n terminate: (\n config: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap> = {}\n ): JourneyTransition<TContext, TStepId, TEventType, TPayloadMap> =>\n ({\n ...config,\n from,\n event: event as Extract<TEventType, \"terminateJourney\">\n }) as JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>\n } as EventBuilder<TContext, TStepId, TEventType, TPayloadMap>;\n }\n\n return {\n to: (\n to: JourneyTransitionTarget<TStepId>,\n config: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap> = {}\n ): JourneyTransition<TContext, TStepId, TEventType, TPayloadMap> =>\n ({\n ...config,\n from,\n event: event as Exclude<TEventType, \"completeJourney\" | \"terminateJourney\">,\n to\n }) as JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>,\n choose: (\n ...branches: Array<TransitionBranch<TContext, TStepId, TEventType, TPayloadMap>>\n ): JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[] =>\n branches.map(\n (branch) =>\n ({\n ...branch,\n from,\n event: event as Exclude<TEventType, \"completeJourney\" | \"terminateJourney\">\n }) as JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>\n )\n } as EventBuilder<TContext, TStepId, TEventType, TPayloadMap>;\n};\n\nconst buildTerminalTransition = <\n TContext,\n TStepId extends string,\n TEventType extends \"completeJourney\" | \"terminateJourney\"\n>(\n from: TStepId | typeof JOURNEY_WILDCARD,\n event: TEventType,\n config: TransitionConfig<TContext, TStepId, TEventType, Record<never, never>> = {}\n): JourneyEventTransition<TContext, TStepId, TEventType, Record<never, never>> =>\n ({\n ...config,\n from,\n event\n }) as JourneyEventTransition<TContext, TStepId, TEventType, Record<never, never>>;\n\nexport const tx = {\n from: <TStepId extends string, TContext = unknown>(from: TStepId) => ({\n on: <TEventType extends string>(event: TEventType) =>\n createEventBuilder<TContext, TStepId, TEventType, Record<never, never>>(from, event),\n toComplete: (\n config: TransitionConfig<TContext, TStepId, \"completeJourney\", Record<never, never>> = {}\n ) => buildTerminalTransition(from, \"completeJourney\", config),\n toTerminate: (\n config: TransitionConfig<TContext, TStepId, \"terminateJourney\", Record<never, never>> = {}\n ) => buildTerminalTransition(from, \"terminateJourney\", config)\n }),\n any: <TContext = unknown, TStepId extends string = string>() => ({\n on: <TEventType extends string>(event: TEventType) =>\n createEventBuilder<TContext, TStepId, TEventType, Record<never, never>>(\n JOURNEY_WILDCARD,\n event\n ),\n toComplete: (\n config: TransitionConfig<TContext, TStepId, \"completeJourney\", Record<never, never>> = {}\n ) => buildTerminalTransition(JOURNEY_WILDCARD, \"completeJourney\", config),\n toTerminate: (\n config: TransitionConfig<TContext, TStepId, \"terminateJourney\", Record<never, never>> = {}\n ) => buildTerminalTransition(JOURNEY_WILDCARD, \"terminateJourney\", config)\n }),\n when: <\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>\n >(\n predicate: (\n args: JourneyTransitionArgs<TContext, TStepId, TEventType, TPayloadMap>\n ) => boolean | Promise<boolean>\n ) => ({\n to: (\n to: JourneyTransitionTarget<TStepId>,\n config: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap> = {}\n ): TransitionBranch<TContext, TStepId, TEventType, TPayloadMap> => ({\n ...config,\n to,\n when: predicate\n })\n }),\n otherwise: <\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>\n >() => ({\n to: (\n to: JourneyTransitionTarget<TStepId>,\n config: TransitionConfig<TContext, TStepId, TEventType, TPayloadMap> = {}\n ): TransitionBranch<TContext, TStepId, TEventType, TPayloadMap> => ({\n ...config,\n to\n })\n })\n};\n\nexport const createTransitions = <\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>\n>(\n ...items: Array<\n | JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>\n | readonly JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[]\n >\n): JourneyTransition<TContext, TStepId, TEventType, TPayloadMap>[] =>\n items.flatMap((item) => (Array.isArray(item) ? [...item] : [item]));\n"],
5
+ "mappings": "mbAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,yBAAAE,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,qBAAAC,EAAA,yBAAAC,GAAA,gCAAAC,EAAA,sBAAAC,GAAA,OAAAC,KAAA,eAAAC,GAAAV,ICKO,IAAMW,EAAiB,CAC5B,QAAS,UACT,SAAU,WACV,WAAY,YACd,EAIaC,EAAmB,IAEnBC,EAAgB,CAC3B,iBAAkB,cACpB,EAUaC,EAAsB,CACjC,KAAM,OACN,gBAAiB,kBACjB,eAAgB,iBAChB,MAAO,OACT,ECjBO,IAAMC,EAAmB,CAC9BC,EACAC,EACAC,IACG,CACH,GAAI,EAAED,KAAUD,GACd,MAAM,IAAI,MAAME,CAAO,CAE3B,EAEaC,EAAsBH,GAC7B,OAAOA,GAAU,UAAY,CAAC,OAAO,SAASA,CAAK,EAC9C,EAEF,KAAK,IAAI,EAAG,KAAK,MAAMA,CAAK,CAAC,EAGzBI,EAAM,IAAc,KAAK,IAAI,EAEpCC,GAAaC,GAA6B,CAAC,GAAG,IAAI,IAAIA,CAAK,CAAC,EAE5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GAAAE,CACF,GACF,OAAQ,IACHC,IAEHA,EAAS,IACNC,IACE,CACC,GAAGA,EACH,KAAAL,EACA,MAAOC,CACT,EACJ,CACJ,EAGIK,EAA0B,CAK9BN,EACAC,EACAC,EAAgF,CAAC,KAEhF,CACC,GAAGA,EACH,KAAAF,EACA,MAAAC,CACF,GAEWM,GAAK,CAChB,KAAmDP,IAAmB,CACpE,GAAgCC,GAC9BF,GAAwEC,EAAMC,CAAK,EACrF,WAAY,CACVC,EAAuF,CAAC,IACrFI,EAAwBN,EAAM,kBAAmBE,CAAM,EAC5D,YAAa,CACXA,EAAwF,CAAC,IACtFI,EAAwBN,EAAM,mBAAoBE,CAAM,CAC/D,GACA,IAAK,KAA4D,CAC/D,GAAgCD,GAC9BF,GACES,EACAP,CACF,EACF,WAAY,CACVC,EAAuF,CAAC,IACrFI,EAAwBE,EAAkB,kBAAmBN,CAAM,EACxE,YAAa,CACXA,EAAwF,CAAC,IACtFI,EAAwBE,EAAkB,mBAAoBN,CAAM,CAC3E,GACA,KAMEO,IAGI,CACJ,GAAI,CACFN,EACAD,EAAuE,CAAC,KACN,CAClE,GAAGA,EACH,GAAAC,EACA,KAAMM,CACR,EACF,GACA,UAAW,KAKH,CACN,GAAI,CACFN,EACAD,EAAuE,CAAC,KACN,CAClE,GAAGA,EACH,GAAAC,CACF,EACF,EACF,EAEaO,GAAoB,IAM5BC,IAKHA,EAAM,QAASC,GAAU,MAAM,QAAQA,CAAI,EAAI,CAAC,GAAGA,CAAI,EAAI,CAACA,CAAI,CAAE",
6
+ "names": ["index_exports", "__export", "JOURNEY_ASYNC_PHASE", "JOURNEY_EVENT", "JOURNEY_STATUS", "JOURNEY_WILDCARD", "createJourneyMachine", "createPersistenceController", "createTransitions", "tx", "__toCommonJS", "JOURNEY_STATUS", "JOURNEY_WILDCARD", "JOURNEY_EVENT", "JOURNEY_ASYNC_PHASE", "assertStepExists", "steps", "stepId", "message", "normalizeStepCount", "now", "unique", "items", "normalizeVisited", "visited", "stepIds", "buildVisitedFromTimeline", "timeline", "resolvedStepIds", "appendVisited", "current", "isPromiseLike", "value", "buildIdleStepAsyncState", "JOURNEY_ASYNC_PHASE", "buildInitialAsyncState", "isGoToStepByIdEvent", "event", "JOURNEY_EVENT", "isTerminalTarget", "target", "validateJourneyTransitions", "transitions", "stepRegistry", "index", "transition", "JOURNEY_WILDCARD", "buildSendResult", "snapshot", "transitioned", "transitionId", "buildSnapshot", "context", "status", "asyncState", "stepMeta", "safeIndex", "currentStepId", "selectTransition", "hooks", "fromMatches", "eventMatches", "guardResult", "asyncGuard", "allowed", "error", "transitionSnapshot", "nextCurrent", "nextContext", "baseTimeline", "nextTimeline", "nextIndex", "isRecord", "value", "isStatusValue", "JOURNEY_STATUS", "resolveDefaultStorage", "localStorageCandidate", "resolvePersistence", "options", "storage", "coercePersistedSnapshot", "steps", "fallbackContext", "fallbackStepMeta", "needsRewrite", "rawHistory", "rawTimeline", "timeline", "step", "currentStepIdValue", "index", "rawIndex", "inferredIndex", "status", "stepIds", "visitedSource", "visitedFromRecord", "stepId", "visitedFromArray", "buildVisitedFromTimeline", "visited", "visitedRecord", "rawStepMeta", "stepMeta", "typedStepId", "rawValue", "createPersistenceController", "args", "initial", "context", "persistence", "reportPersistenceError", "error", "persistSnapshot", "snapshot", "persistedState", "removePersistedSnapshot", "hydrateSnapshot", "initialSnapshot", "buildSnapshot", "buildInitialAsyncState", "rawPersisted", "parsed", "persistedVersion", "persistedSnapshot", "shouldRewritePersisted", "coerced", "migrated", "hydratedSnapshot", "createJourneyMachine", "journey", "options", "assertStepExists", "validateJourneyTransitions", "buildStepMeta", "stepId", "definition", "clearOnReset", "hydrateSnapshot", "persistSnapshot", "removePersistedSnapshot", "createPersistenceController", "snapshot", "buildInitialAsyncState", "listeners", "eventListeners", "actionQueue", "notify", "listener", "emit", "event", "queue", "runner", "resultPromise", "isAsyncLoadingPhase", "phase", "JOURNEY_ASYNC_PHASE", "updateStepAsync", "updater", "current", "buildIdleStepAsyncState", "next", "nextByStep", "isLoading", "state", "setStepLoading", "eventType", "transitionId", "setStepIdle", "setStepError", "error", "applyPreviousNavigation", "requestedSteps", "JOURNEY_STATUS", "buildSendResult", "steps", "normalizeStepCount", "from", "nextIndex", "appliedSteps", "now", "buildSnapshot", "applyLastVisitedNavigation", "targetIndex", "machine", "previousMeta", "nextMeta", "resolvedStep", "payload", "fromStep", "isGoToStepByIdEvent", "beforeCurrent", "nextSnapshot", "transitionSnapshot", "JOURNEY_EVENT", "transition", "selectTransition", "currentTransition", "fallbackResult", "nextContext", "effectResultPromise", "isPromiseLike", "effectResult", "target", "isTerminalTarget", "normalizedTimeline", "resolvedTarget", "createEventBuilder", "from", "event", "config", "to", "branches", "branch", "buildTerminalTransition", "tx", "JOURNEY_WILDCARD", "predicate", "createTransitions", "items", "item"]
7
7
  }
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { createJourneyMachine } from "./machine";
2
2
  export { createPersistenceController } from "./persistence";
3
- export { JOURNEY_EVENT, JOURNEY_ASYNC_PHASE, JOURNEY_STATUS, JOURNEY_WILDCARD, HISTORY_TARGET, JOURNEY_TERMINAL, type JourneyBuiltInEvent, type JourneyBuiltInFrom, type JourneyAsyncPhase, type JourneyStatus, type JourneyAsyncState, type JourneyStepAsyncState, type JourneyEvent, type JourneyEventPayloadMap, type JourneyDefinition, type JourneyHistoryOptions, type JourneyHistoryOverflow, type JourneyHistoryOverflowReason, type JourneyMachineOptions, type JourneyGoToEvent, type JourneyMachine, type JourneyPayloadFor, type JourneyPersistedSnapshot, type JourneyPersistedState, type JourneyPersistenceOptions, type JourneyStorage, type JourneySendResult, type JourneySnapshot, type JourneyTerminal, type JourneyTransition, type JourneyTransitionArgs, type JourneyTransitionTarget } from "./types";
4
- //# sourceMappingURL=index.d.cts.map
3
+ export { createTransitions, tx } from "./transitions";
4
+ export { JOURNEY_EVENT, JOURNEY_ASYNC_PHASE, JOURNEY_STATUS, JOURNEY_WILDCARD, type JourneyBuiltInEvent, type JourneyBuiltInFrom, type JourneyDefaultEventType, type JourneyAsyncPhase, type JourneyStatus, type JourneyAsyncState, type JourneyStepAsyncState, type JourneyEvent, type JourneyEventPayloadMap, type JourneyDefinition, type JourneyMachineOptions, type JourneyGoToEvent, type JourneyMachine, type JourneyObservationEvent, type JourneyPayloadFor, type JourneyPersistedSnapshot, type JourneyPersistedState, type JourneyPersistenceOptions, type JourneyStepDefinition, type JourneyStorage, type JourneySendResult, type JourneySnapshot, type JourneyTerminal, type JourneyTransition, type JourneyTransitionArgs, type JourneyTransitionTarget } from "./types";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { createJourneyMachine } from "./machine";
2
2
  export { createPersistenceController } from "./persistence";
3
- export { JOURNEY_EVENT, JOURNEY_ASYNC_PHASE, JOURNEY_STATUS, JOURNEY_WILDCARD, HISTORY_TARGET, JOURNEY_TERMINAL, type JourneyBuiltInEvent, type JourneyBuiltInFrom, type JourneyAsyncPhase, type JourneyStatus, type JourneyAsyncState, type JourneyStepAsyncState, type JourneyEvent, type JourneyEventPayloadMap, type JourneyDefinition, type JourneyHistoryOptions, type JourneyHistoryOverflow, type JourneyHistoryOverflowReason, type JourneyMachineOptions, type JourneyGoToEvent, type JourneyMachine, type JourneyPayloadFor, type JourneyPersistedSnapshot, type JourneyPersistedState, type JourneyPersistenceOptions, type JourneyStorage, type JourneySendResult, type JourneySnapshot, type JourneyTerminal, type JourneyTransition, type JourneyTransitionArgs, type JourneyTransitionTarget } from "./types";
4
- //# sourceMappingURL=index.d.ts.map
3
+ export { createTransitions, tx } from "./transitions";
4
+ export { JOURNEY_EVENT, JOURNEY_ASYNC_PHASE, JOURNEY_STATUS, JOURNEY_WILDCARD, type JourneyBuiltInEvent, type JourneyBuiltInFrom, type JourneyDefaultEventType, type JourneyAsyncPhase, type JourneyStatus, type JourneyAsyncState, type JourneyStepAsyncState, type JourneyEvent, type JourneyEventPayloadMap, type JourneyDefinition, type JourneyMachineOptions, type JourneyGoToEvent, type JourneyMachine, type JourneyObservationEvent, type JourneyPayloadFor, type JourneyPersistedSnapshot, type JourneyPersistedState, type JourneyPersistenceOptions, type JourneyStepDefinition, type JourneyStorage, type JourneySendResult, type JourneySnapshot, type JourneyTerminal, type JourneyTransition, type JourneyTransitionArgs, type JourneyTransitionTarget } from "./types";