@rxova/journey-core 0.1.0 → 0.2.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/LICENSE +21 -0
- package/README.md +137 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/machine.d.ts +5 -0
- package/dist/machine.d.ts.map +1 -1
- package/dist/persistence.d.ts +4 -0
- package/dist/persistence.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +43 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# @rxova/journey-core
|
|
2
|
+
|
|
3
|
+
The core Journey state machine for non-React environments. Use this package if you want the smallest, framework-agnostic runtime.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @rxova/journey-core
|
|
9
|
+
npm install @rxova/journey-core
|
|
10
|
+
yarn add @rxova/journey-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Basic usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
createJourneyMachine,
|
|
18
|
+
JOURNEY_TERMINAL,
|
|
19
|
+
type JourneyDefinition
|
|
20
|
+
} from "@rxova/journey-core";
|
|
21
|
+
|
|
22
|
+
type StepId = "one" | "two" | "three";
|
|
23
|
+
type Event = "next" | "submit";
|
|
24
|
+
type Ctx = { name: string };
|
|
25
|
+
|
|
26
|
+
const journey: JourneyDefinition<Ctx, StepId, Event> = {
|
|
27
|
+
initial: "one",
|
|
28
|
+
context: { name: "" },
|
|
29
|
+
steps: {
|
|
30
|
+
one: {},
|
|
31
|
+
two: {},
|
|
32
|
+
three: {}
|
|
33
|
+
},
|
|
34
|
+
transitions: [
|
|
35
|
+
{ from: "one", event: "next", to: "two" },
|
|
36
|
+
{ from: "two", event: "next", to: "three" },
|
|
37
|
+
{ from: "three", event: "submit", to: JOURNEY_TERMINAL.COMPLETE }
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
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`: derived list of steps you have ever reached (including current), with duplicates removed.
|
|
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`, so a list is the simplest representation.
|
|
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:
|
|
77
|
+
|
|
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
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### History target example
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { HISTORY_TARGET } from "@rxova/journey-core";
|
|
104
|
+
|
|
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
|
+
};
|
|
119
|
+
```
|
|
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
|
|
1
|
+
"use strict";var G=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var ee=(e,r)=>{for(var o in r)G(e,o,{get:r[o],enumerable:!0})},te=(e,r,o,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of Z(r))!j.call(e,s)&&s!==o&&G(e,s,{get:()=>r[s],enumerable:!(a=K(r,s))||a.enumerable});return e};var ne=e=>te(G({},"__esModule",{value:!0}),e);var Te={};ee(Te,{HISTORY_TARGET:()=>k,JOURNEY_ASYNC_PHASE:()=>g,JOURNEY_EVENT:()=>N,JOURNEY_STATUS:()=>x,JOURNEY_TERMINAL:()=>C,JOURNEY_WILDCARD:()=>O,createJourneyMachine:()=>Q,createPersistenceController:()=>H});module.exports=ne(Te);var C={COMPLETE:"COMPLETE",CLOSE:"CLOSE"},x={RUNNING:"running",COMPLETE:"complete",CLOSED:"closed"},k="__HISTORY__",O="*",N={GO_TO:"goTo"},g={IDLE:"idle",EVALUATING_WHEN:"evaluating-when",RUNNING_EFFECT:"running-effect",ERROR:"error"};var U=(e,r,o)=>{if(!(r in e))throw new Error(o)},re=e=>[...new Set(e)],L=e=>typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function",Y=()=>({phase:g.IDLE,eventType:null,transitionId:null,error:null}),A=e=>({isLoading:!1,byStep:Object.fromEntries(Object.keys(e).map(o=>[o,Y()]))}),z=e=>e.type===N.GO_TO&&"to"in e,D=e=>e===C.COMPLETE||e===C.CLOSE,M=(e,r,o)=>o?{transitioned:r,transitionId:o,snapshot:e}:{transitioned:r,snapshot:e},v=(e,r,o,a,s)=>({status:a,current:e,context:r,history:o,visited:re([...o,e]),async:s}),$=(e,r)=>{let o=[...e.history];for(;o.length>0;){let a=o.pop();if(!a)break;if(a in r)return{target:a,history:o}}return{target:e.current,history:[...e.history]}},B=async(e,r,o,a)=>{for(let s of e){let y=s.from===O||s.from===r.current,f=s.event===o.type;if(!y||!f)continue;if(!s.when)return s;let u=s.when({context:r.context,from:r.current,history:r.history,event:o}),t=L(u);t&&a?.onAsyncGuardStart?.(s);let m;try{m=await u}catch(T){throw t&&a?.onAsyncGuardError?.(s,T),T}if(t&&a?.onAsyncGuardSuccess?.(s),m)return s}return null},V=(e,r,o)=>{let a=r===e.current?[...e.history]:[...e.history,e.current];return v(r,o,a,e.status,e.async)};var q=e=>typeof e=="object"&&e!==null,oe=e=>e===x.RUNNING||e===x.COMPLETE||e===x.CLOSED,se=()=>{let e=globalThis.localStorage;return!e||typeof e.getItem!="function"||typeof e.setItem!="function"||typeof e.removeItem!="function"?null:e},ie=e=>{if(!e)return null;let r=e.storage??se();return r?{key:e.key,storage:r,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},W=(e,r,o)=>{if(!q(e))return null;let a=e.current;if(typeof a!="string"||!(a in r))return null;let s=a,y=Array.isArray(e.history)?e.history.filter(u=>typeof u=="string"&&u in r):[],f=oe(e.status)?e.status:x.RUNNING;return{current:s,context:"context"in e?e.context:o,history:y,status:f}},H=e=>{let{initial:r,context:o,steps:a,options:s}=e,y=ie(s?.persistence),f=T=>{y?.onError?.(T)},u=T=>{if(y)try{let E={version:y.version,snapshot:{current:T.current,context:T.context,history:[...T.history],status:T.status}};y.storage.setItem(y.key,y.serialize(E))}catch(E){f(E)}},t=()=>{if(y)try{y.storage.removeItem(y.key)}catch(T){f(T)}},m=()=>{let T=v(r,o,[],x.RUNNING,A(a));if(!y)return T;try{let E=y.storage.getItem(y.key);if(!E)return T;let c=y.deserialize(E);if(!q(c))return T;let w=c.version;if(typeof w!="number")return T;let J=null,_=!1;if(w===y.version)J=W(c.snapshot,a,o);else if(y.migrate){let b=y.migrate(c.snapshot,w);J=W(b,a,o),_=J!==null}if(!J)return T;let h=v(J.current,J.context,J.history,J.status,A(a));return _&&u(h),h}catch(E){return f(E),T}};return{clearOnReset:y?.clearOnReset??!0,hydrateSnapshot:m,persistSnapshot:u,removePersistedSnapshot:t}};var ae=50,ye=e=>e===null?null:typeof e=="number"&&Number.isFinite(e)?Math.max(0,Math.trunc(e)):ae,pe=(e,r)=>{if(r===null||e.length<=r)return{next:[...e],trimmed:[]};let o=e.length-r;return{next:e.slice(o),trimmed:e.slice(0,o)}},Q=(e,r)=>{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[n,i]of e.transitions.entries()){if(!i||typeof i!="object")throw new Error(`Journey transition at index ${n} must be an object.`);if(typeof i.from!="string"||typeof i.event!="string")throw new Error(`Journey transition at index ${n} must define string "from" and "event".`);if(i.from!==O&&!(i.from in e.steps))throw new Error(`Journey transition at index ${n} references unknown from step "${i.from}".`);if(i.to!==k&&!D(i.to)&&!(i.to in e.steps))throw new Error(`Journey transition at index ${n} points to unknown step "${i.to}".`)}let{clearOnReset:o,hydrateSnapshot:a,persistSnapshot:s,removePersistedSnapshot:y}=H({initial:e.initial,context:e.context,steps:e.steps,...r?{options:r}:{}}),f=r?.history,u=(n,i,S)=>{let p=ye(S??f?.maxHistory),{next:d,trimmed:I}=pe(n.history,p);if(I.length===0)return{snapshot:n,trimmed:I,maxHistory:p};let R=v(n.current,n.context,d,n.status,n.async);return f?.onOverflow?.({previous:n.history,next:d,trimmed:I,maxHistory:p,reason:i}),{snapshot:R,trimmed:I,maxHistory:p}},t=a(),m=u(t,"hydrate");t=m.snapshot,m.trimmed.length>0&&s(t);let T=new Set,E=Promise.resolve();t={...t,async:A(e.steps)};let c=()=>{for(let n of T)n()},w=n=>n===g.EVALUATING_WHEN||n===g.RUNNING_EFFECT,J=(n,i)=>{let S=t.async.byStep[n]??Y(),p=i(S);if(S.phase===p.phase&&S.eventType===p.eventType&&S.transitionId===p.transitionId&&S.error===p.error)return;let d={...t.async.byStep,[n]:p},I=Object.values(d).some(R=>w(R.phase));t={...t,async:{isLoading:I,byStep:d}},c()},_=(n,i,S,p)=>{J(n,()=>({phase:i,eventType:S,transitionId:p??null,error:null}))},h=n=>{J(n,()=>Y())},b=(n,i,S,p)=>{J(n,()=>({phase:g.ERROR,eventType:i,transitionId:p??null,error:S}))};return{getSnapshot:()=>t,subscribe:n=>(T.add(n),()=>{T.delete(n)}),reset:()=>(t=v(e.initial,e.context,[],x.RUNNING,A(e.steps)),o?y():s(t),c(),t),updateContext:n=>(t={...t,context:n(t.context)},s(t),c(),t),clearStepError:n=>{let i=n??t.current;return i in e.steps&&h(i),t},trimHistory:n=>{let i=u(t,"manual",n);return i.trimmed.length===0||(t=i.snapshot,s(t),c()),t},clearHistory:()=>(t.history.length===0||(t=v(t.current,t.context,[],t.status,t.async),s(t),c()),t),send:n=>{let i=async()=>{if(t.status!==x.RUNNING)return{transitioned:!1,snapshot:t};let p=t.current;if(z(n))return U(e.steps,n.to,`Cannot goTo unknown step "${n.to}".`),h(p),t=V(t,n.to,t.context),t=u(t,"auto").snapshot,s(t),c(),M(t,!0,N.GO_TO);let d;try{d=await B(e.transitions,t,n,{onAsyncGuardStart:l=>{_(p,g.EVALUATING_WHEN,n.type,l.id)},onAsyncGuardSuccess:()=>{h(p)},onAsyncGuardError:(l,P)=>{b(p,n.type,P,l.id)}})}catch(l){throw b(p,n.type,l),l}if(!d)return M(t,!1);let I=t.context;if(d.effect){let l=d.effect({context:t.context,from:t.current,history:t.history,event:n});L(l)&&_(p,g.RUNNING_EFFECT,n.type,d.id);let P;try{P=await l}catch(F){throw b(p,n.type,F,d.id),F}P!==void 0&&(I=P)}if(h(p),D(d.to))return t={...t,context:I,status:d.to===C.COMPLETE?x.COMPLETE:x.CLOSED},t=u(t,"auto").snapshot,s(t),c(),M(t,!0,d.id);if(d.to===k){let{target:l,history:P}=$(t,e.steps);return U(e.steps,l,`Transition points to unknown step "${l}".`),t=v(l,I,P,t.status,t.async),t=u(t,"auto").snapshot,s(t),c(),M(t,!0,d.id)}let R=d.to;U(e.steps,R,`Transition points to unknown step "${R}".`);let X=V(t,R,I);return t=u(X,"auto").snapshot,s(t),c(),M(t,!0,d.id)},S=E.then(i,i);return E=S.then(()=>{},()=>{}),S}}};0&&(module.exports={HISTORY_TARGET,JOURNEY_ASYNC_PHASE,JOURNEY_EVENT,JOURNEY_STATUS,JOURNEY_TERMINAL,JOURNEY_WILDCARD,createJourneyMachine,createPersistenceController});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 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};\n\nexport type JourneyPersistedState<TContext, TStepId extends string> = {\n version: number;\n snapshot: JourneyPersistedSnapshot<TContext, TStepId>;\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};\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 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 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): JourneySnapshot<TContext, TStepId> => ({\n status,\n current,\n context,\n history,\n visited: unique([...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 return buildSnapshot(nextCurrent, nextContext, history, snapshot.status, snapshot.async);\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 } 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): JourneyPersistedSnapshot<TContext, TStepId> | 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 return {\n current,\n context: (\"context\" in value ? value.context : fallbackContext) as TContext,\n history,\n status\n };\n};\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 }\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 persistedSnapshot = coercePersistedSnapshot(parsed.snapshot, steps, context);\n } else if (persistence.migrate) {\n const migrated = persistence.migrate(parsed.snapshot, persistedVersion);\n persistedSnapshot = coercePersistedSnapshot(migrated, steps, context);\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 );\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 JourneyMachine,\n JourneyMachineOptions,\n JourneySendResult\n} from \"./types\";\nimport {\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\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 let snapshot = hydrateSnapshot();\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 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 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 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 snapshot = buildSnapshot(target, nextContext, history, snapshot.status, snapshot.async);\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\n snapshot = nextSnapshot;\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": "yaAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,oBAAAE,EAAA,wBAAAC,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,qBAAAC,EAAA,qBAAAC,EAAA,yBAAAC,EAAA,gCAAAC,IAAA,eAAAC,EAAAV,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,EAKaC,EAAsB,CACjC,KAAM,OACN,g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ACxB,IAAG,GACH,IAAG,EACL,EACOA,CACT,CACF,CACF",
|
|
6
|
-
"names": ["index_exports", "__export", "HISTORY_TARGET", "JOURNEY_ASYNC_PHASE", "JOURNEY_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", "isPromiseLike", "value", "buildIdleStepAsyncState", "JOURNEY_ASYNC_PHASE", "buildInitialAsyncState", "isGoToEvent", "event", "JOURNEY_EVENT", "isTerminalTarget", "target", "JOURNEY_TERMINAL", "buildSendResult", "snapshot", "transitioned", "transitionId", "buildSnapshot", "current", "context", "history", "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", "createPersistenceController", "args", "initial", "context", "persistence", "reportPersistenceError", "error", "persistSnapshot", "snapshot", "persistedState", "removePersistedSnapshot", "hydrateSnapshot", "initialSnapshot", "buildSnapshot", "buildInitialAsyncState", "rawPersisted", "parsed", "persistedVersion", "persistedSnapshot", "shouldRewritePersisted", "migrated", "hydratedSnapshot", "createJourneyMachine", "journey", "options", "assertStepExists", "index", "transition", "JOURNEY_WILDCARD", "HISTORY_TARGET", "isTerminalTarget", "clearOnReset", "hydrateSnapshot", "persistSnapshot", "removePersistedSnapshot", "createPersistenceController", "snapshot", "listeners", "sendQueue", "buildInitialAsyncState", "notify", "listener", "isAsyncLoadingPhase", "phase", "JOURNEY_ASYNC_PHASE", "updateStepAsync", "stepId", "updater", "current", "buildIdleStepAsyncState", "
|
|
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};\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 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): JourneySnapshot<TContext, TStepId> => ({\n status,\n current,\n context,\n history,\n visited: unique([...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 return buildSnapshot(nextCurrent, nextContext, history, snapshot.status, snapshot.async);\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 } 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): JourneyPersistedSnapshot<TContext, TStepId> | 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 return {\n current,\n context: (\"context\" in value ? value.context : fallbackContext) as TContext,\n history,\n status\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 }\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 persistedSnapshot = coercePersistedSnapshot(parsed.snapshot, steps, context);\n } else if (persistence.migrate) {\n const migrated = persistence.migrate(parsed.snapshot, persistedVersion);\n persistedSnapshot = coercePersistedSnapshot(migrated, steps, context);\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 );\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 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 );\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 );\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 snapshot = buildSnapshot(target, nextContext, history, snapshot.status, snapshot.async);\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": "6aAAA,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,EAKaC,EAAsB,CACjC,KAAM,OACN,gBAAiB,kBACjB,eAAgB,iBAChB,MAAO,OACT,ECfO,IAAMC,EAAmB,CAC9BC,EACAC,EACAC,IACG,CACH,GAAI,EAAED,KAAUD,GACd,MAAM,IAAI,MAAME,CAAO,CAE3B,EAEMC,GAAaC,GAA6B,CAAC,GAAG,IAAI,IAAIA,CAAK,CAAC,EAErDC,EAAoBC,GAC/B,OAAOA,GAAU,UACjBA,IAAU,MACV,SAAUA,GACV,OAAQA,EAA4B,MAAS,WAElCC,EAA0B,KAA8B,CACnE,MAAOC,EAAoB,KAC3B,UAAW,KACX,aAAc,KACd,MAAO,IACT,GAEaC,EACXT,IAMO,CACL,UAAW,GACX,OANa,OAAO,YACpB,OAAO,KAAKA,CAAK,EAAE,IAAKC,GAAW,CAACA,EAAQM,EAAwB,CAAC,CAAC,CACxE,CAKA,GAGWG,EAKXC,GAIGA,EAAM,OAASC,EAAc,OAAS,OAAQD,EAEtCE,EACXC,GAEAA,IAAWC,EAAiB,UAAYD,IA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OAAAmB,EAAW,CACT,GAAGA,EACH,QAASoC,EACT,OACEvD,EAAW,KAAO2D,EAAiB,SAC/BhB,EAAe,SACfA,EAAe,MACvB,EACAxB,EAAWT,EAAeS,EAAU,MAAM,EAAE,SAC5Cb,EAAgBa,CAAQ,EACxBK,EAAO,EACA2B,EAAgBhC,EAAU,GAAMnB,EAAW,EAAE,EAGtD,GAAIA,EAAW,KAAOE,EAAgB,CACpC,GAAM,CAAE,OAAA0D,EAAQ,QAAApE,CAAQ,EAAIqE,EAAqB1C,EAAUvB,EAAQ,KAAK,EACxE,OAAAE,EAAiBF,EAAQ,MAAOgE,EAAQ,sCAAsCA,CAAM,IAAI,EACxFzC,EAAWD,EAAc0C,EAAQL,EAAa/D,EAAS2B,EAAS,OAAQA,EAAS,KAAK,EACtFA,EAAWT,EAAeS,EAAU,MAAM,EAAE,SAC5Cb,EAAgBa,CAAQ,EACxBK,EAAO,EACA2B,EAAgBhC,EAAU,GAAMnB,EAAW,EAAE,CACtD,CAEA,IAAM8D,EAAiB9D,EAAW,GAElCF,EACEF,EAAQ,MACRkE,EACA,sCAAsCA,CAAc,IACtD,EAEA,IAAMnD,EAAeuC,EAAmB/B,EAAU2C,EAAgBP,CAAW,EAC7E,OAAApC,EAAWT,EAAeC,EAAc,MAAM,EAAE,SAChDL,EAAgBa,CAAQ,EACxBK,EAAO,EAEA2B,EAAgBhC,EAAU,GAAMnB,EAAW,EAAE,CACtD,EAEM+D,EAAgBzC,EAAU,KAAKyB,EAAKA,CAAG,EAC7C,OAAAzB,EAAYyC,EAAc,KACxB,IAAG,GACH,IAAG,EACL,EACOA,CACT,CACF,CACF",
|
|
6
|
+
"names": ["index_exports", "__export", "HISTORY_TARGET", "JOURNEY_ASYNC_PHASE", "JOURNEY_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", "isPromiseLike", "value", "buildIdleStepAsyncState", "JOURNEY_ASYNC_PHASE", "buildInitialAsyncState", "isGoToEvent", "event", "JOURNEY_EVENT", "isTerminalTarget", "target", "JOURNEY_TERMINAL", "buildSendResult", "snapshot", "transitioned", "transitionId", "buildSnapshot", "current", "context", "history", "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", "createPersistenceController", "args", "initial", "context", "persistence", "reportPersistenceError", "error", "persistSnapshot", "snapshot", "persistedState", "removePersistedSnapshot", "hydrateSnapshot", "initialSnapshot", "buildSnapshot", "buildInitialAsyncState", "rawPersisted", "parsed", "persistedVersion", "persistedSnapshot", "shouldRewritePersisted", "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", "resolvedTarget", "resultPromise"]
|
|
7
7
|
}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createJourneyMachine } from "./machine";
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAC"}
|
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 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";
|
|
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
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var C={COMPLETE:"COMPLETE",CLOSE:"CLOSE"},J={RUNNING:"running",COMPLETE:"complete",CLOSED:"closed"},
|
|
1
|
+
var C={COMPLETE:"COMPLETE",CLOSE:"CLOSE"},J={RUNNING:"running",COMPLETE:"complete",CLOSED:"closed"},U="__HISTORY__",_="*",b={GO_TO:"goTo"},g={IDLE:"idle",EVALUATING_WHEN:"evaluating-when",RUNNING_EFFECT:"running-effect",ERROR:"error"};var k=(e,r,o)=>{if(!(r in e))throw new Error(o)},Q=e=>[...new Set(e)],H=e=>typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function",Y=()=>({phase:g.IDLE,eventType:null,transitionId:null,error:null}),O=e=>({isLoading:!1,byStep:Object.fromEntries(Object.keys(e).map(o=>[o,Y()]))}),F=e=>e.type===b.GO_TO&&"to"in e,G=e=>e===C.COMPLETE||e===C.CLOSE,N=(e,r,o)=>o?{transitioned:r,transitionId:o,snapshot:e}:{transitioned:r,snapshot:e},v=(e,r,o,p,i)=>({status:p,current:e,context:r,history:o,visited:Q([...o,e]),async:i}),z=(e,r)=>{let o=[...e.history];for(;o.length>0;){let p=o.pop();if(!p)break;if(p in r)return{target:p,history:o}}return{target:e.current,history:[...e.history]}},$=async(e,r,o,p)=>{for(let i of e){let a=i.from===_||i.from===r.current,f=i.event===o.type;if(!a||!f)continue;if(!i.when)return i;let u=i.when({context:r.context,from:r.current,history:r.history,event:o}),t=H(u);t&&p?.onAsyncGuardStart?.(i);let m;try{m=await u}catch(T){throw t&&p?.onAsyncGuardError?.(i,T),T}if(t&&p?.onAsyncGuardSuccess?.(i),m)return i}return null},L=(e,r,o)=>{let p=r===e.current?[...e.history]:[...e.history,e.current];return v(r,o,p,e.status,e.async)};var W=e=>typeof e=="object"&&e!==null,X=e=>e===J.RUNNING||e===J.COMPLETE||e===J.CLOSED,K=()=>{let e=globalThis.localStorage;return!e||typeof e.getItem!="function"||typeof e.setItem!="function"||typeof e.removeItem!="function"?null:e},Z=e=>{if(!e)return null;let r=e.storage??K();return r?{key:e.key,storage:r,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},B=(e,r,o)=>{if(!W(e))return null;let p=e.current;if(typeof p!="string"||!(p in r))return null;let i=p,a=Array.isArray(e.history)?e.history.filter(u=>typeof u=="string"&&u in r):[],f=X(e.status)?e.status:J.RUNNING;return{current:i,context:"context"in e?e.context:o,history:a,status:f}},D=e=>{let{initial:r,context:o,steps:p,options:i}=e,a=Z(i?.persistence),f=T=>{a?.onError?.(T)},u=T=>{if(a)try{let E={version:a.version,snapshot:{current:T.current,context:T.context,history:[...T.history],status:T.status}};a.storage.setItem(a.key,a.serialize(E))}catch(E){f(E)}},t=()=>{if(a)try{a.storage.removeItem(a.key)}catch(T){f(T)}},m=()=>{let T=v(r,o,[],J.RUNNING,O(p));if(!a)return T;try{let E=a.storage.getItem(a.key);if(!E)return T;let c=a.deserialize(E);if(!W(c))return T;let A=c.version;if(typeof A!="number")return T;let x=null,M=!1;if(A===a.version)x=B(c.snapshot,p,o);else if(a.migrate){let w=a.migrate(c.snapshot,A);x=B(w,p,o),M=x!==null}if(!x)return T;let h=v(x.current,x.context,x.history,x.status,O(p));return M&&u(h),h}catch(E){return f(E),T}};return{clearOnReset:a?.clearOnReset??!0,hydrateSnapshot:m,persistSnapshot:u,removePersistedSnapshot:t}};var j=50,ee=e=>e===null?null:typeof e=="number"&&Number.isFinite(e)?Math.max(0,Math.trunc(e)):j,te=(e,r)=>{if(r===null||e.length<=r)return{next:[...e],trimmed:[]};let o=e.length-r;return{next:e.slice(o),trimmed:e.slice(0,o)}},ne=(e,r)=>{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.");k(e.steps,e.initial,`Journey initial step "${e.initial}" does not exist in steps registry.`);for(let[n,s]of e.transitions.entries()){if(!s||typeof s!="object")throw new Error(`Journey transition at index ${n} must be an object.`);if(typeof s.from!="string"||typeof s.event!="string")throw new Error(`Journey transition at index ${n} must define string "from" and "event".`);if(s.from!==_&&!(s.from in e.steps))throw new Error(`Journey transition at index ${n} references unknown from step "${s.from}".`);if(s.to!==U&&!G(s.to)&&!(s.to in e.steps))throw new Error(`Journey transition at index ${n} points to unknown step "${s.to}".`)}let{clearOnReset:o,hydrateSnapshot:p,persistSnapshot:i,removePersistedSnapshot:a}=D({initial:e.initial,context:e.context,steps:e.steps,...r?{options:r}:{}}),f=r?.history,u=(n,s,S)=>{let y=ee(S??f?.maxHistory),{next:d,trimmed:I}=te(n.history,y);if(I.length===0)return{snapshot:n,trimmed:I,maxHistory:y};let R=v(n.current,n.context,d,n.status,n.async);return f?.onOverflow?.({previous:n.history,next:d,trimmed:I,maxHistory:y,reason:s}),{snapshot:R,trimmed:I,maxHistory:y}},t=p(),m=u(t,"hydrate");t=m.snapshot,m.trimmed.length>0&&i(t);let T=new Set,E=Promise.resolve();t={...t,async:O(e.steps)};let c=()=>{for(let n of T)n()},A=n=>n===g.EVALUATING_WHEN||n===g.RUNNING_EFFECT,x=(n,s)=>{let S=t.async.byStep[n]??Y(),y=s(S);if(S.phase===y.phase&&S.eventType===y.eventType&&S.transitionId===y.transitionId&&S.error===y.error)return;let d={...t.async.byStep,[n]:y},I=Object.values(d).some(R=>A(R.phase));t={...t,async:{isLoading:I,byStep:d}},c()},M=(n,s,S,y)=>{x(n,()=>({phase:s,eventType:S,transitionId:y??null,error:null}))},h=n=>{x(n,()=>Y())},w=(n,s,S,y)=>{x(n,()=>({phase:g.ERROR,eventType:s,transitionId:y??null,error:S}))};return{getSnapshot:()=>t,subscribe:n=>(T.add(n),()=>{T.delete(n)}),reset:()=>(t=v(e.initial,e.context,[],J.RUNNING,O(e.steps)),o?a():i(t),c(),t),updateContext:n=>(t={...t,context:n(t.context)},i(t),c(),t),clearStepError:n=>{let s=n??t.current;return s in e.steps&&h(s),t},trimHistory:n=>{let s=u(t,"manual",n);return s.trimmed.length===0||(t=s.snapshot,i(t),c()),t},clearHistory:()=>(t.history.length===0||(t=v(t.current,t.context,[],t.status,t.async),i(t),c()),t),send:n=>{let s=async()=>{if(t.status!==J.RUNNING)return{transitioned:!1,snapshot:t};let y=t.current;if(F(n))return k(e.steps,n.to,`Cannot goTo unknown step "${n.to}".`),h(y),t=L(t,n.to,t.context),t=u(t,"auto").snapshot,i(t),c(),N(t,!0,b.GO_TO);let d;try{d=await $(e.transitions,t,n,{onAsyncGuardStart:l=>{M(y,g.EVALUATING_WHEN,n.type,l.id)},onAsyncGuardSuccess:()=>{h(y)},onAsyncGuardError:(l,P)=>{w(y,n.type,P,l.id)}})}catch(l){throw w(y,n.type,l),l}if(!d)return N(t,!1);let I=t.context;if(d.effect){let l=d.effect({context:t.context,from:t.current,history:t.history,event:n});H(l)&&M(y,g.RUNNING_EFFECT,n.type,d.id);let P;try{P=await l}catch(V){throw w(y,n.type,V,d.id),V}P!==void 0&&(I=P)}if(h(y),G(d.to))return t={...t,context:I,status:d.to===C.COMPLETE?J.COMPLETE:J.CLOSED},t=u(t,"auto").snapshot,i(t),c(),N(t,!0,d.id);if(d.to===U){let{target:l,history:P}=z(t,e.steps);return k(e.steps,l,`Transition points to unknown step "${l}".`),t=v(l,I,P,t.status,t.async),t=u(t,"auto").snapshot,i(t),c(),N(t,!0,d.id)}let R=d.to;k(e.steps,R,`Transition points to unknown step "${R}".`);let q=L(t,R,I);return t=u(q,"auto").snapshot,i(t),c(),N(t,!0,d.id)},S=E.then(s,s);return E=S.then(()=>{},()=>{}),S}}};export{U as HISTORY_TARGET,g as JOURNEY_ASYNC_PHASE,b as JOURNEY_EVENT,J as JOURNEY_STATUS,C as JOURNEY_TERMINAL,_ as JOURNEY_WILDCARD,ne as createJourneyMachine,D as createPersistenceController};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/types.ts", "../src/machine-helpers.ts", "../src/persistence.ts", "../src/machine.ts"],
|
|
4
|
-
"sourcesContent": ["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};\n\nexport type JourneyPersistedState<TContext, TStepId extends string> = {\n version: number;\n snapshot: JourneyPersistedSnapshot<TContext, TStepId>;\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};\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 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 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): JourneySnapshot<TContext, TStepId> => ({\n status,\n current,\n context,\n history,\n visited: unique([...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 return buildSnapshot(nextCurrent, nextContext, history, snapshot.status, snapshot.async);\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 } 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): JourneyPersistedSnapshot<TContext, TStepId> | 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 return {\n current,\n context: (\"context\" in value ? value.context : fallbackContext) as TContext,\n history,\n status\n };\n};\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 }\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 persistedSnapshot = coercePersistedSnapshot(parsed.snapshot, steps, context);\n } else if (persistence.migrate) {\n const migrated = persistence.migrate(parsed.snapshot, persistedVersion);\n persistedSnapshot = coercePersistedSnapshot(migrated, steps, context);\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 );\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 JourneyMachine,\n JourneyMachineOptions,\n JourneySendResult\n} from \"./types\";\nimport {\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\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 let snapshot = hydrateSnapshot();\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 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 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 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 snapshot = buildSnapshot(target, nextContext, history, snapshot.status, snapshot.async);\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\n snapshot = nextSnapshot;\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": "AAAO,IAAMA,EAAmB,CAC9B,SAAU,WACV,MAAO,OACT,EAIaC,EAAiB,CAC5B,QAAS,UACT,SAAU,WACV,OAAQ,QACV,EAIaC,EAAiB,cACjBC,EAAmB,IAEnBC,EAAgB,CAC3B,MAAO,MACT,EAKaC,EAAsB,CACjC,KAAM,OACN,gBAAiB,kBACjB,eAAgB,iBAChB,MAAO,OACT,ECfO,IAAMC,EAAmB,CAC9BC,EACAC,EACAC,IACG,CACH,GAAI,EAAED,KAAUD,GACd,MAAM,IAAI,MAAME,CAAO,CAE3B,EAEMC,EAAaC,GAA6B,CAAC,GAAG,IAAI,IAAIA,CAAK,CAAC,EAErDC,EAAoBC,GAC/B,OAAOA,GAAU,UACjBA,IAAU,MACV,SAAUA,G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AOhC,EAAW,EAAE,EACjDgC,CACR,CAEIgB,IAAiB,SACnBH,EAAcG,EAElB,CAIA,GAFAlB,EAAYQ,CAAQ,EAEhBnC,EAAiBH,EAAW,EAAE,EAChC,OAAAS,EAAW,CACT,GAAGA,EACH,QAASoC,EACT,OACE7C,EAAW,KAAOiD,EAAiB,SAC/Bf,EAAe,SACfA,EAAe,MACvB,EACA5B,EAAgBG,CAAQ,EACxBI,EAAO,EACA4B,EAAgBhC,EAAU,GAAMT,EAAW,EAAE,EAGtD,GAAIA,EAAW,KAAOE,EAAgB,CACpC,GAAM,CAAE,OAAAgD,EAAQ,QAAAC,CAAQ,EAAIC,EAAqB3C,EAAUb,EAAQ,KAAK,EACxE,OAAAE,EAAiBF,EAAQ,MAAOsD,EAAQ,sCAAsCA,CAAM,IAAI,EACxFzC,EAAWwB,EAAciB,EAAQL,EAAaM,EAAS1C,EAAS,OAAQA,EAAS,KAAK,EACtFH,EAAgBG,CAAQ,EACxBI,EAAO,EACA4B,EAAgBhC,EAAU,GAAMT,EAAW,EAAE,CACtD,CAEA,IAAMqD,EAAiBrD,EAAW,GAElC,OAAAF,EACEF,EAAQ,MACRyD,EACA,sCAAsCA,CAAc,IACtD,EAIA5C,EAFqB+B,EAAmB/B,EAAU4C,EAAgBR,CAAW,EAG7EvC,EAAgBG,CAAQ,EACxBI,EAAO,EAEA4B,EAAgBhC,EAAU,GAAMT,EAAW,EAAE,CACtD,EAEMsD,EAAgB3C,EAAU,KAAK0B,EAAKA,CAAG,EAC7C,OAAA1B,EAAY2C,EAAc,KACxB,IAAG,GACH,IAAG,EACL,EACOA,CACT,CACF,CACF",
|
|
6
|
-
"names": ["JOURNEY_TERMINAL", "JOURNEY_STATUS", "HISTORY_TARGET", "JOURNEY_WILDCARD", "JOURNEY_EVENT", "JOURNEY_ASYNC_PHASE", "assertStepExists", "steps", "stepId", "message", "unique", "items", "isPromiseLike", "value", "buildIdleStepAsyncState", "JOURNEY_ASYNC_PHASE", "buildInitialAsyncState", "isGoToEvent", "event", "JOURNEY_EVENT", "isTerminalTarget", "target", "JOURNEY_TERMINAL", "buildSendResult", "snapshot", "transitioned", "transitionId", "buildSnapshot", "current", "context", "history", "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", "createPersistenceController", "args", "initial", "context", "persistence", "reportPersistenceError", "error", "persistSnapshot", "snapshot", "persistedState", "removePersistedSnapshot", "hydrateSnapshot", "initialSnapshot", "buildSnapshot", "buildInitialAsyncState", "rawPersisted", "parsed", "persistedVersion", "persistedSnapshot", "shouldRewritePersisted", "migrated", "hydratedSnapshot", "createJourneyMachine", "journey", "options", "assertStepExists", "index", "transition", "JOURNEY_WILDCARD", "HISTORY_TARGET", "isTerminalTarget", "clearOnReset", "hydrateSnapshot", "persistSnapshot", "removePersistedSnapshot", "createPersistenceController", "snapshot", "listeners", "sendQueue", "buildInitialAsyncState", "notify", "listener", "isAsyncLoadingPhase", "phase", "JOURNEY_ASYNC_PHASE", "updateStepAsync", "stepId", "updater", "current", "buildIdleStepAsyncState", "
|
|
4
|
+
"sourcesContent": ["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};\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 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): JourneySnapshot<TContext, TStepId> => ({\n status,\n current,\n context,\n history,\n visited: unique([...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 return buildSnapshot(nextCurrent, nextContext, history, snapshot.status, snapshot.async);\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 } 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): JourneyPersistedSnapshot<TContext, TStepId> | 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 return {\n current,\n context: (\"context\" in value ? value.context : fallbackContext) as TContext,\n history,\n status\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 }\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 persistedSnapshot = coercePersistedSnapshot(parsed.snapshot, steps, context);\n } else if (persistence.migrate) {\n const migrated = persistence.migrate(parsed.snapshot, persistedVersion);\n persistedSnapshot = coercePersistedSnapshot(migrated, steps, context);\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 );\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 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 );\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 );\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 snapshot = buildSnapshot(target, nextContext, history, snapshot.status, snapshot.async);\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": "AAAO,IAAMA,EAAmB,CAC9B,SAAU,WACV,MAAO,OACT,EAIaC,EAAiB,CAC5B,QAAS,UACT,SAAU,WACV,OAAQ,QACV,EAIaC,EAAiB,cACjBC,EAAmB,IAEnBC,EAAgB,CAC3B,MAAO,MACT,EAKaC,EAAsB,CACjC,KAAM,OACN,gBAAiB,kBACjB,eAAgB,iBAChB,MAAO,OACT,ECfO,IAAMC,EAAmB,CAC9BC,EACAC,EACAC,IACG,CACH,GAAI,EAAED,KAAUD,GACd,MAAM,IAAI,MAAME,CAAO,CAE3B,EAEMC,EAAaC,GAA6B,CAAC,GAAG,IAAI,IAAIA,CAAK,CAAC,EAErDC,EAAoBC,GAC/B,OAAOA,GAAU,UACjBA,IAAU,MACV,SAAUA,GACV,OAAQA,EAA4B,MAAS,WAElCC,EAA0B,KAA8B,CACnE,MAAOC,EAAoB,KAC3B,UAAW,KACX,aAAc,KACd,MAAO,IACT,GAEaC,EACXT,IAMO,CACL,UAAW,GACX,OANa,OAAO,YACpB,OAAO,KAAKA,CAAK,EAAE,IAAKC,GAAW,CAACA,EAAQM,EAAwB,CAAC,CAAC,CACxE,CAKA,GAGWG,EAKXC,GAIGA,EAAM,OAASC,EAAc,OAAS,OAAQD,EAEtCE,EACXC,GAE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,EAAiBH,EAAW,EAAE,EAChC,OAAAmB,EAAW,CACT,GAAGA,EACH,QAASoC,EACT,OACEvD,EAAW,KAAO2D,EAAiB,SAC/BhB,EAAe,SACfA,EAAe,MACvB,EACAxB,EAAWT,EAAeS,EAAU,MAAM,EAAE,SAC5Cb,EAAgBa,CAAQ,EACxBK,EAAO,EACA2B,EAAgBhC,EAAU,GAAMnB,EAAW,EAAE,EAGtD,GAAIA,EAAW,KAAOE,EAAgB,CACpC,GAAM,CAAE,OAAA0D,EAAQ,QAAApE,CAAQ,EAAIqE,EAAqB1C,EAAUvB,EAAQ,KAAK,EACxE,OAAAE,EAAiBF,EAAQ,MAAOgE,EAAQ,sCAAsCA,CAAM,IAAI,EACxFzC,EAAWD,EAAc0C,EAAQL,EAAa/D,EAAS2B,EAAS,OAAQA,EAAS,KAAK,EACtFA,EAAWT,EAAeS,EAAU,MAAM,EAAE,SAC5Cb,EAAgBa,CAAQ,EACxBK,EAAO,EACA2B,EAAgBhC,EAAU,GAAMnB,EAAW,EAAE,CACtD,CAEA,IAAM8D,EAAiB9D,EAAW,GAElCF,EACEF,EAAQ,MACRkE,EACA,sCAAsCA,CAAc,IACtD,EAEA,IAAMnD,EAAeuC,EAAmB/B,EAAU2C,EAAgBP,CAAW,EAC7E,OAAApC,EAAWT,EAAeC,EAAc,MAAM,EAAE,SAChDL,EAAgBa,CAAQ,EACxBK,EAAO,EAEA2B,EAAgBhC,EAAU,GAAMnB,EAAW,EAAE,CACtD,EAEM+D,EAAgBzC,EAAU,KAAKyB,EAAKA,CAAG,EAC7C,OAAAzB,EAAYyC,EAAc,KACxB,IAAG,GACH,IAAG,EACL,EACOA,CACT,CACF,CACF",
|
|
6
|
+
"names": ["JOURNEY_TERMINAL", "JOURNEY_STATUS", "HISTORY_TARGET", "JOURNEY_WILDCARD", "JOURNEY_EVENT", "JOURNEY_ASYNC_PHASE", "assertStepExists", "steps", "stepId", "message", "unique", "items", "isPromiseLike", "value", "buildIdleStepAsyncState", "JOURNEY_ASYNC_PHASE", "buildInitialAsyncState", "isGoToEvent", "event", "JOURNEY_EVENT", "isTerminalTarget", "target", "JOURNEY_TERMINAL", "buildSendResult", "snapshot", "transitioned", "transitionId", "buildSnapshot", "current", "context", "history", "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", "createPersistenceController", "args", "initial", "context", "persistence", "reportPersistenceError", "error", "persistSnapshot", "snapshot", "persistedState", "removePersistedSnapshot", "hydrateSnapshot", "initialSnapshot", "buildSnapshot", "buildInitialAsyncState", "rawPersisted", "parsed", "persistedVersion", "persistedSnapshot", "shouldRewritePersisted", "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", "resolvedTarget", "resultPromise"]
|
|
7
7
|
}
|
package/dist/machine.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { JourneyEventPayloadMap, JourneyDefinition, JourneyMachine, JourneyMachineOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a journey machine from a journey definition.
|
|
4
|
+
* Validates steps/transitions, hydrates persisted state (if configured),
|
|
5
|
+
* and returns an API for sending events and reading snapshots.
|
|
6
|
+
*/
|
|
2
7
|
export declare const createJourneyMachine: <TContext, TStepId extends string, TEventType extends string = "next" | "back" | "close" | "submit", TPayloadMap extends JourneyEventPayloadMap<TEventType> = Record<never, never>>(journey: JourneyDefinition<TContext, TStepId, TEventType, TPayloadMap>, options?: JourneyMachineOptions<TContext, TStepId>) => JourneyMachine<TContext, TStepId, TEventType, TPayloadMap>;
|
|
3
8
|
//# sourceMappingURL=machine.d.ts.map
|
package/dist/machine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../src/machine.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAGV,sBAAsB,EACtB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../src/machine.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAGV,sBAAsB,EACtB,iBAAiB,EAGjB,cAAc,EACd,qBAAqB,EAGtB,MAAM,SAAS,CAAC;AA2CjB;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,EACR,OAAO,SAAS,MAAM,EACtB,UAAU,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,EAChE,WAAW,SAAS,sBAAsB,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAE7E,SAAS,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,EACtE,UAAU,qBAAqB,CAAC,QAAQ,EAAE,OAAO,CAAC,KACjD,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAwX3D,CAAC"}
|
package/dist/persistence.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { JourneyMachineOptions, JourneySnapshot } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a persistence controller for snapshots, including hydration,
|
|
4
|
+
* serialization, and storage error handling.
|
|
5
|
+
*/
|
|
2
6
|
export declare const createPersistenceController: <TContext, TStepId extends string>(args: {
|
|
3
7
|
initial: TStepId;
|
|
4
8
|
context: TContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../src/persistence.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EAIrB,eAAe,EAEhB,MAAM,SAAS,CAAC;AAgGjB,eAAO,MAAM,2BAA2B,GAAI,QAAQ,EAAE,OAAO,SAAS,MAAM,EAAE,MAAM;IAClF,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,QAAQ,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,qBAAqB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;CACpD;;2BAyC6B,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC;gCAjC3B,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC;;CAqGtE,CAAC"}
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../src/persistence.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EAIrB,eAAe,EAEhB,MAAM,SAAS,CAAC;AAgGjB;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,QAAQ,EAAE,OAAO,SAAS,MAAM,EAAE,MAAM;IAClF,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,QAAQ,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,qBAAqB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;CACpD;;2BAyC6B,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC;gCAjC3B,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC;;CAqGtE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"fileNames":["../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.asynciterable.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.scripthost.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.full.d.ts","../src/types.ts","../src/machine-helpers.ts","../src/persistence.ts","../src/machine.ts","../src/index.ts"],"fileIdsList":[[52,54,55],[52],[52,53,54],[52,53]],"fileInfos":[{"version":"c430d44666289dae81f30fa7b2edebf186ecc91a2d4c71266ea6ae76388792e1","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","impliedFormat":1},{"version":"080941d9f9ff9307f7e27a83bcd888b7c8270716c39af943532438932ec1d0b9","affectsGlobalScope":true,"impliedFormat":1},{"version":"2e80ee7a49e8ac312cc11b77f1475804bee36b3b2bc896bead8b6e1266befb43","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7a3c8b952931daebdfc7a2897c53c0a1c73624593fa070e46bd537e64dcd20a","affectsGlobalScope":true,"impliedFormat":1},{"version":"80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89","affectsGlobalScope":true,"impliedFormat":1},{"version":"cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"fb0f136d372979348d59b3f5020b4cdb81b5504192b1cacff5d1fbba29378aa1","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"a680117f487a4d2f30ea46f1b4b7f58bef1480456e18ba53ee85c2746eeca012","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"d6d7ae4d1f1f3772e2a3cde568ed08991a8ae34a080ff1151af28b7f798e22ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true,"impliedFormat":1},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true,"impliedFormat":1},{"version":"52ada8e0b6e0482b728070b7639ee42e83a9b1c22d205992756fe020fd9f4a47","affectsGlobalScope":true,"impliedFormat":1},{"version":"3bdefe1bfd4d6dee0e26f928f93ccc128f1b64d5d501ff4a8cf3c6371200e5e6","affectsGlobalScope":true,"impliedFormat":1},{"version":"59fb2c069260b4ba00b5643b907ef5d5341b167e7d1dbf58dfd895658bda2867","affectsGlobalScope":true,"impliedFormat":1},{"version":"639e512c0dfc3fad96a84caad71b8834d66329a1f28dc95e3946c9b58176c73a","affectsGlobalScope":true,"impliedFormat":1},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"1305d1e76ca44e30fb8b2b8075fa522b83f60c0bcf5d4326a9d2cf79b53724f8","impliedFormat":1},{"version":"3fd372717c7c15022bc1c6ad1f431f86b3350bcfa77c5927f1b737cd7b941add","signature":"3518fd87b0f1b2225d6e121f84794d75c0f9f2fc6ae4683ea0b2e96e0a6ef0f6"},{"version":"05801c11e1e9f163401117a753fdddeb49857a1c382f6ed3fe70b7e54e1883d5","signature":"7c12eeb8675fb066a04c79038ec56775e7a806e55d71d42abb3419cf3a8b30ff"},{"version":"bc265e74cf92d75de52cb617e2295c65ddf53eaa07ae31033c5a82b9f386e1e9","signature":"64a4320c603b4e6640d2813fd4817ab65f14fe57327373634a10ddc0016b6435"},{"version":"02aa1a03cdbd41bef5cc4ba9d0032a6e423fc6a86f687fe0c7790e32134c67f5","signature":"3d3e7b4efbe8891f0b0f37b832ce6adf587b32c4de869b557c2e2613d5363a65"},{"version":"6a2076fef6db705767a4ecbc9128e84718f9d0977ac8062b58f69751b7ed39e3","signature":"bdd8041fa7979a7f7a52eea92f4ecafc4155db4f964e0339b57ea05ca57afb8d"}],"root":[[52,56]],"options":{"composite":true,"declaration":true,"declarationDir":"./","declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":false,"exactOptionalPropertyTypes":true,"jsx":4,"module":99,"noFallthroughCasesInSwitch":true,"noUncheckedIndexedAccess":true,"outDir":"./","rootDir":"../src","skipLibCheck":true,"sourceMap":true,"strict":true,"target":7,"tsBuildInfoFile":"./tsconfig.build.tsbuildinfo"},"referencedMap":[[56,1],[53,2],[55,3],[54,4]],"latestChangedDtsFile":"./index.d.ts","version":"5.9.3"}
|
package/dist/types.d.ts
CHANGED
|
@@ -83,6 +83,18 @@ export type JourneyPersistedState<TContext, TStepId extends string> = {
|
|
|
83
83
|
version: number;
|
|
84
84
|
snapshot: JourneyPersistedSnapshot<TContext, TStepId>;
|
|
85
85
|
};
|
|
86
|
+
export type JourneyHistoryOverflowReason = "auto" | "hydrate" | "manual";
|
|
87
|
+
export type JourneyHistoryOverflow<TStepId extends string> = {
|
|
88
|
+
previous: readonly TStepId[];
|
|
89
|
+
next: readonly TStepId[];
|
|
90
|
+
trimmed: readonly TStepId[];
|
|
91
|
+
maxHistory: number | null;
|
|
92
|
+
reason: JourneyHistoryOverflowReason;
|
|
93
|
+
};
|
|
94
|
+
export type JourneyHistoryOptions<TStepId extends string> = {
|
|
95
|
+
maxHistory?: number | null;
|
|
96
|
+
onOverflow?: (info: JourneyHistoryOverflow<TStepId>) => void;
|
|
97
|
+
};
|
|
86
98
|
export type JourneyStorage = {
|
|
87
99
|
getItem: (key: string) => string | null;
|
|
88
100
|
setItem: (key: string, value: string) => void;
|
|
@@ -106,6 +118,7 @@ export type JourneyDefinition<TContext, TStepId extends string, TEventType exten
|
|
|
106
118
|
};
|
|
107
119
|
export type JourneyMachineOptions<TContext, TStepId extends string> = {
|
|
108
120
|
persistence?: JourneyPersistenceOptions<TContext, TStepId>;
|
|
121
|
+
history?: JourneyHistoryOptions<TStepId>;
|
|
109
122
|
};
|
|
110
123
|
export type JourneySendResult<TContext, TStepId extends string> = {
|
|
111
124
|
transitioned: boolean;
|
|
@@ -118,6 +131,8 @@ export type JourneyMachine<TContext, TStepId extends string, TEventType extends
|
|
|
118
131
|
updateContext: (updater: (context: TContext) => TContext) => JourneySnapshot<TContext, TStepId>;
|
|
119
132
|
clearStepError: (stepId?: TStepId) => JourneySnapshot<TContext, TStepId>;
|
|
120
133
|
reset: () => JourneySnapshot<TContext, TStepId>;
|
|
134
|
+
trimHistory: (maxHistory?: number | null) => JourneySnapshot<TContext, TStepId>;
|
|
135
|
+
clearHistory: () => JourneySnapshot<TContext, TStepId>;
|
|
121
136
|
subscribe: (listener: () => void) => () => void;
|
|
122
137
|
};
|
|
123
138
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAEvF,eAAO,MAAM,cAAc;;;;CAIjB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAEjF,eAAO,MAAM,cAAc,EAAG,aAAsB,CAAC;AACrD,eAAO,MAAM,gBAAgB,EAAG,GAAY,CAAC;AAE7C,eAAO,MAAM,aAAa;;CAEhB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AACrF,MAAM,MAAM,kBAAkB,GAAG,OAAO,gBAAgB,CAAC;AAEzD,eAAO,MAAM,mBAAmB;;;;;CAKtB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAC;AAE/F,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,iBAAiB,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B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AQ,EACR,OAAO,SAAS,MAAM,EACtB,UAAU,SAAS,MAAM,EACzB,WAAW,SAAS,sBAAsB,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAC3E;IACF,WAAW,EAAE,MAAM,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtD,IAAI,EAAE,CACJ,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,KAClD,OAAO,CAAC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,aAAa,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,QAAQ,KAAK,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChG,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzE,KAAK,EAAE,MAAM,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChD,WAAW,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChF,YAAY,EAAE,MAAM,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvD,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,36 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxova/journey-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Journey core state machine.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"journey",
|
|
7
|
+
"state-machine",
|
|
8
|
+
"flow",
|
|
9
|
+
"wizard",
|
|
10
|
+
"stepper",
|
|
11
|
+
"typescript",
|
|
12
|
+
"graph",
|
|
13
|
+
"finite-state",
|
|
14
|
+
"workflow"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/rxova/journey",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/rxova/journey/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/rxova/journey.git"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
5
27
|
"license": "MIT",
|
|
28
|
+
"author": "Jonatan Kruszewski",
|
|
6
29
|
"type": "module",
|
|
7
30
|
"main": "./dist/index.cjs",
|
|
8
31
|
"module": "./dist/index.js",
|
|
9
32
|
"types": "./dist/index.d.ts",
|
|
10
33
|
"exports": {
|
|
11
34
|
".": {
|
|
12
|
-
"types":
|
|
35
|
+
"types": {
|
|
36
|
+
"import": "./dist/index.d.ts",
|
|
37
|
+
"require": "./dist/index.d.cts"
|
|
38
|
+
},
|
|
13
39
|
"import": "./dist/index.js",
|
|
14
40
|
"require": "./dist/index.cjs"
|
|
15
41
|
}
|
|
16
42
|
},
|
|
17
43
|
"files": [
|
|
18
|
-
"dist"
|
|
44
|
+
"dist",
|
|
45
|
+
"README.md",
|
|
46
|
+
"LICENSE"
|
|
19
47
|
],
|
|
20
48
|
"sideEffects": false,
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "pnpm run clean && node ./scripts/build.mjs && tsc -p tsconfig.build.json",
|
|
23
|
-
"clean": "rm -rf dist",
|
|
24
|
-
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
25
|
-
"size": "pnpm run size:check",
|
|
26
|
-
"size:check": "pnpm run build && size-limit"
|
|
27
|
-
},
|
|
28
49
|
"size-limit": [
|
|
29
50
|
{
|
|
30
51
|
"name": "core/createJourneyMachine",
|
|
31
52
|
"path": "dist/index.js",
|
|
32
53
|
"import": "{ createJourneyMachine }",
|
|
33
|
-
"limit": "
|
|
54
|
+
"limit": "3 kB"
|
|
34
55
|
}
|
|
35
|
-
]
|
|
36
|
-
|
|
56
|
+
],
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "pnpm run clean && node ./scripts/build.mjs && tsc -p tsconfig.build.json && node ../../scripts/copy-types.mjs dist",
|
|
59
|
+
"clean": "rm -rf dist",
|
|
60
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
61
|
+
"publint": "publint",
|
|
62
|
+
"attw": "attw --pack .",
|
|
63
|
+
"size": "pnpm run size:check",
|
|
64
|
+
"size:check": "pnpm run build && size-limit"
|
|
65
|
+
}
|
|
66
|
+
}
|