@quazardous/quarkernel 1.0.11 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,74 +1,80 @@
1
- # QuarKernel
1
+ # @quazardous/quarkernel
2
2
 
3
- Micro Custom Event Kernel.
3
+ Event orchestration with dependency ordering and shared context.
4
4
 
5
- ## Features
5
+ [![npm version](https://img.shields.io/npm/v/@quazardous/quarkernel.svg?style=flat-square)](https://www.npmjs.com/package/@quazardous/quarkernel)
6
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@quazardous/quarkernel?style=flat-square)](https://bundlephobia.com/package/@quazardous/quarkernel)
6
7
 
7
- Helps structuring your app with events.
8
+ ## Features
8
9
 
9
- - Modern: ES6, Async() support with Promise
10
- - Dependency support: easily handle async resource dependencies
11
- - Composite event: handle complex logic with a common event pipe
12
- - Shared context: use event data to share variable
10
+ - **Dependency ordering** - Guarantee listener execution order
11
+ - **Shared context** - Pass state between listeners
12
+ - **Composite events** - React to event combinations
13
+ - **Wildcards** - Pattern matching (`user:*`)
14
+ - **TypeScript-first** - Full type safety
15
+ - **Zero dependencies** - No runtime deps
16
+ - **< 2KB gzipped**
13
17
 
14
- ## Install
18
+ ## Installation
15
19
 
16
20
  ```bash
17
- npm i "@quazardous/quarkernel"
21
+ npm install @quazardous/quarkernel
22
+ ```
23
+
24
+ ```html
25
+ <!-- CDN -->
26
+ <script src="https://unpkg.com/@quazardous/quarkernel@2/dist/index.umd.js"></script>
18
27
  ```
19
28
 
20
- ## Basic usage
29
+ ## Quick Start
21
30
 
22
- Define event listeners across your app modules with dependency support.
23
- Share context between components.
31
+ ```typescript
32
+ import { createKernel } from '@quazardous/quarkernel';
24
33
 
25
- ```js
26
- import { QuarKernel, QuarKernelEvent as QKE } from '@quazardous/quarkernel';
34
+ const qk = createKernel();
27
35
 
28
- // singleton
29
- const qk = new QuarKernel();
36
+ // Dependency ordering
37
+ qk.on('checkout', async (e) => {
38
+ e.context.stock = await checkStock(e.data.items);
39
+ }, { id: 'stock' });
30
40
 
31
- qk.addEventListener('my_event', (e) => {
32
- // something
33
- notNeeded();
34
- });
41
+ qk.on('checkout', async (e) => {
42
+ // Runs AFTER stock check
43
+ await processPayment(e.data.card, e.context.stock);
44
+ }, { after: ['stock'] });
35
45
 
36
- // your module foo does some init stuff
37
- qk.addEventListener('my_event', async (e) => {
38
- // something async
39
- e.context.needed = await needed();
40
- }, 'foo');
41
-
42
- // somewhere else in your app your module bar is waiting after foo to set a specific context
43
- qk.addEventListener('my_event', (e) => {
44
- // something after the async callback
45
- needing(e.context.needed);
46
- }, 'bar', 'foo');
47
-
48
- // call everything
49
- qk.dispatchEvent(new QKE('my_event')).then((e) => {
50
- // event my_event fully dispatched
51
- happyEnd();
52
- });
53
- // or await qk.dispatchEvent(new QKE('my_event'));
46
+ await qk.emit('checkout', { items: ['sku-123'], card: 'tok_visa' });
54
47
  ```
55
48
 
56
- ## Composite event
49
+ ## Composition
57
50
 
58
- Composite event are auto dispatched when a specific list of events are dispatched.
51
+ React to multiple events:
59
52
 
60
- ie. You set a composite event C on A+B. Your code dispatches A, then B. C is auto dispatched after B.
53
+ ```typescript
54
+ import { Composition } from '@quazardous/quarkernel';
61
55
 
62
- ```js
63
- ...
64
- // init
65
- qk.addCompositeEvent(['A','B'], (stack) => new QKE('C'));
66
- ...
67
- qk.dispatchEvent(new QKE('A'));
68
- ...
69
- // this will auto dispatch C
70
- qk.dispatchEvent(new QKE('B'));
56
+ const checkout = new Composition([
57
+ [qk, 'cart:ready'],
58
+ [qk, 'payment:confirmed']
59
+ ]);
71
60
 
61
+ checkout.onComposed(() => {
62
+ console.log('Both events fired!');
63
+ });
72
64
  ```
73
65
 
66
+ ## Framework Adapters
67
+
68
+ - `@quazardous/quarkernel-vue` - Vue 3 plugin
69
+ - `@quazardous/quarkernel-react` - React hooks
70
+ - `@quazardous/quarkernel-svelte` - Svelte 5 context
71
+
72
+ ## Documentation
73
+
74
+ - [Getting Started](../../docs/getting-started.md)
75
+ - [API Reference](../../docs/api-reference.md)
76
+ - [Migration v1 to v2](../../docs/migration-v1-to-v2.md)
77
+
78
+ ## License
74
79
 
80
+ MIT
@@ -0,0 +1,275 @@
1
+ /**
2
+ * FSM Types for QuarKernel
3
+ *
4
+ * Flexible state machine layer built on quarkernel events.
5
+ * Prefixed events allow loose coupling and multi-machine orchestration.
6
+ */
7
+ /**
8
+ * State name type
9
+ */
10
+ type StateName = string;
11
+ /**
12
+ * Transition event name type
13
+ */
14
+ type TransitionEvent = string;
15
+ /**
16
+ * Guard function - returns true to allow transition
17
+ */
18
+ type GuardFunction<TContext = any> = (context: TContext, event: TransitionEvent, payload?: any) => boolean;
19
+ /**
20
+ * Action function - side effect on transition
21
+ */
22
+ type ActionFunction<TContext = any> = (context: TContext, event: TransitionEvent, payload?: any) => void | Promise<void>;
23
+ /**
24
+ * Transition definition
25
+ */
26
+ interface TransitionDef<TContext = any> {
27
+ /** Target state */
28
+ target: StateName;
29
+ /** Guard condition (optional) */
30
+ guard?: GuardFunction<TContext>;
31
+ /** Actions to run on transition (optional) */
32
+ actions?: ActionFunction<TContext> | ActionFunction<TContext>[];
33
+ }
34
+ /**
35
+ * Timer/after definition for auto-transitions
36
+ */
37
+ interface AfterDef$1 {
38
+ /** Delay in milliseconds */
39
+ delay: number;
40
+ /** Event to send after delay */
41
+ send: string;
42
+ }
43
+ /**
44
+ * State node definition (state-centric format)
45
+ */
46
+ interface StateNode<TContext = any> {
47
+ /** Transitions from this state: event -> target or TransitionDef */
48
+ on?: Record<TransitionEvent, StateName | TransitionDef<TContext>>;
49
+ /** Action on entering this state */
50
+ entry?: ActionFunction<TContext>;
51
+ /** Action on exiting this state */
52
+ exit?: ActionFunction<TContext>;
53
+ /** Auto-transition after delay: { delay: 3000, send: 'TIMER' } */
54
+ after?: AfterDef$1;
55
+ }
56
+ /**
57
+ * Machine configuration
58
+ */
59
+ interface MachineConfig<TContext = any> {
60
+ /** Event prefix for this machine (e.g., 'order', 'player') */
61
+ prefix: string;
62
+ /** Initial state */
63
+ initial: StateName;
64
+ /** State definitions */
65
+ states: Record<StateName, StateNode<TContext>>;
66
+ /** Initial context (optional) */
67
+ context?: TContext;
68
+ /** Allow force transitions that bypass guards */
69
+ allowForce?: boolean;
70
+ /** Restore from snapshot (overrides initial/context) */
71
+ snapshot?: MachineSnapshot<TContext>;
72
+ /** Track transition history */
73
+ trackHistory?: boolean;
74
+ /** Max history entries (default: 100) */
75
+ maxHistory?: number;
76
+ }
77
+ /**
78
+ * Send options
79
+ */
80
+ interface SendOptions<TContext = any> {
81
+ /** Force transition (bypass guards and undefined transitions) */
82
+ force?: boolean;
83
+ /** Target state for force transitions */
84
+ target?: StateName;
85
+ /** Inline guard (overrides state guard) */
86
+ guard?: GuardFunction<TContext>;
87
+ /** Fallback state if guard fails */
88
+ fallback?: StateName;
89
+ }
90
+ /**
91
+ * Serialized machine state (for persistence)
92
+ */
93
+ interface MachineSnapshot<TContext = any> {
94
+ /** Current state */
95
+ state: StateName;
96
+ /** Machine context */
97
+ context: TContext;
98
+ /** Transition history (optional) */
99
+ history?: Array<{
100
+ from: StateName;
101
+ to: StateName;
102
+ event: TransitionEvent;
103
+ timestamp: number;
104
+ }>;
105
+ }
106
+ /**
107
+ * Machine instance returned by useMachine()
108
+ */
109
+ interface Machine<TContext = any> {
110
+ /** Current state */
111
+ getState(): StateName;
112
+ /** Machine context */
113
+ getContext(): TContext;
114
+ /** Update context */
115
+ setContext(updater: Partial<TContext> | ((ctx: TContext) => TContext)): void;
116
+ /** Send transition event */
117
+ send(event: TransitionEvent, payload?: any, options?: SendOptions<TContext>): Promise<boolean>;
118
+ /** Check if transition is valid from current state */
119
+ can(event: TransitionEvent): boolean;
120
+ /** Get available transitions from current state */
121
+ transitions(): TransitionEvent[];
122
+ /** Machine prefix */
123
+ readonly prefix: string;
124
+ /** Serialize machine state to JSON */
125
+ toJSON(): MachineSnapshot<TContext>;
126
+ /** Restore machine state from snapshot */
127
+ restore(snapshot: MachineSnapshot<TContext>): void;
128
+ /** Cleanup listeners */
129
+ destroy(): void;
130
+ }
131
+ /**
132
+ * FSM event data emitted on kernel
133
+ */
134
+ interface FSMEventData {
135
+ /** Machine prefix */
136
+ machine: string;
137
+ /** Current/new state */
138
+ state: StateName;
139
+ /** Previous state (for transition events) */
140
+ from?: StateName;
141
+ /** Target state (for transition events) */
142
+ to?: StateName;
143
+ /** Transition event name */
144
+ event?: TransitionEvent;
145
+ /** Event payload */
146
+ payload?: any;
147
+ /** Whether this was a forced transition */
148
+ forced?: boolean;
149
+ }
150
+
151
+ /**
152
+ * createMachine - High-level FSM factory
153
+ *
154
+ * Standalone state machine with declarative behaviors.
155
+ * Can work independently or connect to a kernel.
156
+ */
157
+
158
+ /**
159
+ * Built-in helpers (always available)
160
+ */
161
+ interface BuiltInHelpers<TContext = Record<string, unknown>> {
162
+ /** Merge into context */
163
+ set: (partial: Partial<TContext>) => void;
164
+ /** Trigger transition */
165
+ send: (event: string, payload?: unknown) => void;
166
+ /** Log message (default: console.log) */
167
+ log: (message: string) => void;
168
+ }
169
+ /**
170
+ * Behavior helpers passed to callbacks (built-ins + custom)
171
+ */
172
+ type BehaviorHelpers<TContext = Record<string, unknown>, TCustom = Record<string, unknown>> = BuiltInHelpers<TContext> & TCustom;
173
+ /**
174
+ * Behavior callback
175
+ */
176
+ type BehaviorFn<TContext = Record<string, unknown>> = (ctx: TContext, helpers: BehaviorHelpers<TContext>) => void | Promise<void>;
177
+ /**
178
+ * Timer/after definition
179
+ */
180
+ interface AfterDef {
181
+ /** Event to send */
182
+ send: string;
183
+ /** Delay in ms */
184
+ delay: number;
185
+ }
186
+ /**
187
+ * State-centric state definition
188
+ */
189
+ interface StateConfig<TContext = Record<string, unknown>> {
190
+ /** Transitions: { EVENT: 'target' } or { EVENT: { target: 'x', cond: 'guard' } } */
191
+ on?: Record<string, string | {
192
+ target: string;
193
+ cond?: string;
194
+ }>;
195
+ /** Action on entering this state */
196
+ entry?: BehaviorFn<TContext>;
197
+ /** Action on exiting this state */
198
+ exit?: BehaviorFn<TContext>;
199
+ /** Auto-transition after delay: { delay: 3000, send: 'TIMER' } */
200
+ after?: AfterDef;
201
+ }
202
+ /**
203
+ * High-level machine config (state-centric)
204
+ */
205
+ interface CreateMachineConfig<TContext = Record<string, unknown>, THelpers = Record<string, unknown>> {
206
+ /** Machine identifier */
207
+ id: string;
208
+ /** Initial state */
209
+ initial: string;
210
+ /** Initial context */
211
+ context?: TContext;
212
+ /** State definitions with entry/exit/after inline */
213
+ states: Record<string, StateConfig<TContext>>;
214
+ /** Global event handlers: { EVENT_NAME: (ctx, helpers) => ... } */
215
+ on?: Record<string, BehaviorFn<TContext>>;
216
+ /** Custom helpers merged with built-ins (set, send) */
217
+ helpers?: THelpers;
218
+ }
219
+ /**
220
+ * Extended machine interface with behaviors
221
+ */
222
+ interface BehaviorMachine<TContext = Record<string, unknown>> extends Machine<TContext> {
223
+ /** Machine ID */
224
+ readonly id: string;
225
+ /** Current state (getter) */
226
+ readonly state: string;
227
+ /** Current context (getter) */
228
+ readonly context: TContext;
229
+ }
230
+ /**
231
+ * Create a standalone state machine with behaviors (state-centric)
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * const order = createMachine({
236
+ * id: 'order',
237
+ * initial: 'draft',
238
+ * context: { items: 0, total: 0 },
239
+ *
240
+ * states: {
241
+ * draft: {
242
+ * on: { ADD_ITEM: 'draft', SUBMIT: 'pending' }
243
+ * },
244
+ * pending: {
245
+ * entry: (ctx, { log }) => log('Order pending...'),
246
+ * on: { APPROVE: 'confirmed', REJECT: 'draft' }
247
+ * },
248
+ * confirmed: {
249
+ * entry: (ctx, { log }) => log(`Order confirmed: ${ctx.items} items`),
250
+ * on: { SHIP: 'shipped' }
251
+ * },
252
+ * processing: {
253
+ * after: { delay: 2000, send: 'COMPLETE' },
254
+ * on: { COMPLETE: 'done' }
255
+ * },
256
+ * shipped: {},
257
+ * },
258
+ *
259
+ * // Global event handlers (optional)
260
+ * on: {
261
+ * ADD_ITEM: (ctx, { set }) => {
262
+ * set({ items: ctx.items + 1, total: ctx.total + 29.99 });
263
+ * },
264
+ * },
265
+ * });
266
+ *
267
+ * order.send('ADD_ITEM');
268
+ * order.send('SUBMIT');
269
+ * console.log(order.state); // 'pending'
270
+ * console.log(order.context); // { items: 1, total: 29.99 }
271
+ * ```
272
+ */
273
+ declare function createMachine<TContext = Record<string, unknown>>(config: CreateMachineConfig<TContext>): BehaviorMachine<TContext>;
274
+
275
+ export { type ActionFunction as A, type BehaviorMachine as B, type CreateMachineConfig as C, type FSMEventData as F, type GuardFunction as G, type MachineConfig as M, type StateNode as S, type TransitionDef as T, type Machine as a, type MachineSnapshot as b, createMachine as c, type SendOptions as d, type StateName as e, type TransitionEvent as f, type StateConfig as g, type BehaviorFn as h, type BehaviorHelpers as i, type BuiltInHelpers as j, type AfterDef as k, type AfterDef$1 as l };
@@ -0,0 +1,275 @@
1
+ /**
2
+ * FSM Types for QuarKernel
3
+ *
4
+ * Flexible state machine layer built on quarkernel events.
5
+ * Prefixed events allow loose coupling and multi-machine orchestration.
6
+ */
7
+ /**
8
+ * State name type
9
+ */
10
+ type StateName = string;
11
+ /**
12
+ * Transition event name type
13
+ */
14
+ type TransitionEvent = string;
15
+ /**
16
+ * Guard function - returns true to allow transition
17
+ */
18
+ type GuardFunction<TContext = any> = (context: TContext, event: TransitionEvent, payload?: any) => boolean;
19
+ /**
20
+ * Action function - side effect on transition
21
+ */
22
+ type ActionFunction<TContext = any> = (context: TContext, event: TransitionEvent, payload?: any) => void | Promise<void>;
23
+ /**
24
+ * Transition definition
25
+ */
26
+ interface TransitionDef<TContext = any> {
27
+ /** Target state */
28
+ target: StateName;
29
+ /** Guard condition (optional) */
30
+ guard?: GuardFunction<TContext>;
31
+ /** Actions to run on transition (optional) */
32
+ actions?: ActionFunction<TContext> | ActionFunction<TContext>[];
33
+ }
34
+ /**
35
+ * Timer/after definition for auto-transitions
36
+ */
37
+ interface AfterDef$1 {
38
+ /** Delay in milliseconds */
39
+ delay: number;
40
+ /** Event to send after delay */
41
+ send: string;
42
+ }
43
+ /**
44
+ * State node definition (state-centric format)
45
+ */
46
+ interface StateNode<TContext = any> {
47
+ /** Transitions from this state: event -> target or TransitionDef */
48
+ on?: Record<TransitionEvent, StateName | TransitionDef<TContext>>;
49
+ /** Action on entering this state */
50
+ entry?: ActionFunction<TContext>;
51
+ /** Action on exiting this state */
52
+ exit?: ActionFunction<TContext>;
53
+ /** Auto-transition after delay: { delay: 3000, send: 'TIMER' } */
54
+ after?: AfterDef$1;
55
+ }
56
+ /**
57
+ * Machine configuration
58
+ */
59
+ interface MachineConfig<TContext = any> {
60
+ /** Event prefix for this machine (e.g., 'order', 'player') */
61
+ prefix: string;
62
+ /** Initial state */
63
+ initial: StateName;
64
+ /** State definitions */
65
+ states: Record<StateName, StateNode<TContext>>;
66
+ /** Initial context (optional) */
67
+ context?: TContext;
68
+ /** Allow force transitions that bypass guards */
69
+ allowForce?: boolean;
70
+ /** Restore from snapshot (overrides initial/context) */
71
+ snapshot?: MachineSnapshot<TContext>;
72
+ /** Track transition history */
73
+ trackHistory?: boolean;
74
+ /** Max history entries (default: 100) */
75
+ maxHistory?: number;
76
+ }
77
+ /**
78
+ * Send options
79
+ */
80
+ interface SendOptions<TContext = any> {
81
+ /** Force transition (bypass guards and undefined transitions) */
82
+ force?: boolean;
83
+ /** Target state for force transitions */
84
+ target?: StateName;
85
+ /** Inline guard (overrides state guard) */
86
+ guard?: GuardFunction<TContext>;
87
+ /** Fallback state if guard fails */
88
+ fallback?: StateName;
89
+ }
90
+ /**
91
+ * Serialized machine state (for persistence)
92
+ */
93
+ interface MachineSnapshot<TContext = any> {
94
+ /** Current state */
95
+ state: StateName;
96
+ /** Machine context */
97
+ context: TContext;
98
+ /** Transition history (optional) */
99
+ history?: Array<{
100
+ from: StateName;
101
+ to: StateName;
102
+ event: TransitionEvent;
103
+ timestamp: number;
104
+ }>;
105
+ }
106
+ /**
107
+ * Machine instance returned by useMachine()
108
+ */
109
+ interface Machine<TContext = any> {
110
+ /** Current state */
111
+ getState(): StateName;
112
+ /** Machine context */
113
+ getContext(): TContext;
114
+ /** Update context */
115
+ setContext(updater: Partial<TContext> | ((ctx: TContext) => TContext)): void;
116
+ /** Send transition event */
117
+ send(event: TransitionEvent, payload?: any, options?: SendOptions<TContext>): Promise<boolean>;
118
+ /** Check if transition is valid from current state */
119
+ can(event: TransitionEvent): boolean;
120
+ /** Get available transitions from current state */
121
+ transitions(): TransitionEvent[];
122
+ /** Machine prefix */
123
+ readonly prefix: string;
124
+ /** Serialize machine state to JSON */
125
+ toJSON(): MachineSnapshot<TContext>;
126
+ /** Restore machine state from snapshot */
127
+ restore(snapshot: MachineSnapshot<TContext>): void;
128
+ /** Cleanup listeners */
129
+ destroy(): void;
130
+ }
131
+ /**
132
+ * FSM event data emitted on kernel
133
+ */
134
+ interface FSMEventData {
135
+ /** Machine prefix */
136
+ machine: string;
137
+ /** Current/new state */
138
+ state: StateName;
139
+ /** Previous state (for transition events) */
140
+ from?: StateName;
141
+ /** Target state (for transition events) */
142
+ to?: StateName;
143
+ /** Transition event name */
144
+ event?: TransitionEvent;
145
+ /** Event payload */
146
+ payload?: any;
147
+ /** Whether this was a forced transition */
148
+ forced?: boolean;
149
+ }
150
+
151
+ /**
152
+ * createMachine - High-level FSM factory
153
+ *
154
+ * Standalone state machine with declarative behaviors.
155
+ * Can work independently or connect to a kernel.
156
+ */
157
+
158
+ /**
159
+ * Built-in helpers (always available)
160
+ */
161
+ interface BuiltInHelpers<TContext = Record<string, unknown>> {
162
+ /** Merge into context */
163
+ set: (partial: Partial<TContext>) => void;
164
+ /** Trigger transition */
165
+ send: (event: string, payload?: unknown) => void;
166
+ /** Log message (default: console.log) */
167
+ log: (message: string) => void;
168
+ }
169
+ /**
170
+ * Behavior helpers passed to callbacks (built-ins + custom)
171
+ */
172
+ type BehaviorHelpers<TContext = Record<string, unknown>, TCustom = Record<string, unknown>> = BuiltInHelpers<TContext> & TCustom;
173
+ /**
174
+ * Behavior callback
175
+ */
176
+ type BehaviorFn<TContext = Record<string, unknown>> = (ctx: TContext, helpers: BehaviorHelpers<TContext>) => void | Promise<void>;
177
+ /**
178
+ * Timer/after definition
179
+ */
180
+ interface AfterDef {
181
+ /** Event to send */
182
+ send: string;
183
+ /** Delay in ms */
184
+ delay: number;
185
+ }
186
+ /**
187
+ * State-centric state definition
188
+ */
189
+ interface StateConfig<TContext = Record<string, unknown>> {
190
+ /** Transitions: { EVENT: 'target' } or { EVENT: { target: 'x', cond: 'guard' } } */
191
+ on?: Record<string, string | {
192
+ target: string;
193
+ cond?: string;
194
+ }>;
195
+ /** Action on entering this state */
196
+ entry?: BehaviorFn<TContext>;
197
+ /** Action on exiting this state */
198
+ exit?: BehaviorFn<TContext>;
199
+ /** Auto-transition after delay: { delay: 3000, send: 'TIMER' } */
200
+ after?: AfterDef;
201
+ }
202
+ /**
203
+ * High-level machine config (state-centric)
204
+ */
205
+ interface CreateMachineConfig<TContext = Record<string, unknown>, THelpers = Record<string, unknown>> {
206
+ /** Machine identifier */
207
+ id: string;
208
+ /** Initial state */
209
+ initial: string;
210
+ /** Initial context */
211
+ context?: TContext;
212
+ /** State definitions with entry/exit/after inline */
213
+ states: Record<string, StateConfig<TContext>>;
214
+ /** Global event handlers: { EVENT_NAME: (ctx, helpers) => ... } */
215
+ on?: Record<string, BehaviorFn<TContext>>;
216
+ /** Custom helpers merged with built-ins (set, send) */
217
+ helpers?: THelpers;
218
+ }
219
+ /**
220
+ * Extended machine interface with behaviors
221
+ */
222
+ interface BehaviorMachine<TContext = Record<string, unknown>> extends Machine<TContext> {
223
+ /** Machine ID */
224
+ readonly id: string;
225
+ /** Current state (getter) */
226
+ readonly state: string;
227
+ /** Current context (getter) */
228
+ readonly context: TContext;
229
+ }
230
+ /**
231
+ * Create a standalone state machine with behaviors (state-centric)
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * const order = createMachine({
236
+ * id: 'order',
237
+ * initial: 'draft',
238
+ * context: { items: 0, total: 0 },
239
+ *
240
+ * states: {
241
+ * draft: {
242
+ * on: { ADD_ITEM: 'draft', SUBMIT: 'pending' }
243
+ * },
244
+ * pending: {
245
+ * entry: (ctx, { log }) => log('Order pending...'),
246
+ * on: { APPROVE: 'confirmed', REJECT: 'draft' }
247
+ * },
248
+ * confirmed: {
249
+ * entry: (ctx, { log }) => log(`Order confirmed: ${ctx.items} items`),
250
+ * on: { SHIP: 'shipped' }
251
+ * },
252
+ * processing: {
253
+ * after: { delay: 2000, send: 'COMPLETE' },
254
+ * on: { COMPLETE: 'done' }
255
+ * },
256
+ * shipped: {},
257
+ * },
258
+ *
259
+ * // Global event handlers (optional)
260
+ * on: {
261
+ * ADD_ITEM: (ctx, { set }) => {
262
+ * set({ items: ctx.items + 1, total: ctx.total + 29.99 });
263
+ * },
264
+ * },
265
+ * });
266
+ *
267
+ * order.send('ADD_ITEM');
268
+ * order.send('SUBMIT');
269
+ * console.log(order.state); // 'pending'
270
+ * console.log(order.context); // { items: 1, total: 29.99 }
271
+ * ```
272
+ */
273
+ declare function createMachine<TContext = Record<string, unknown>>(config: CreateMachineConfig<TContext>): BehaviorMachine<TContext>;
274
+
275
+ export { type ActionFunction as A, type BehaviorMachine as B, type CreateMachineConfig as C, type FSMEventData as F, type GuardFunction as G, type MachineConfig as M, type StateNode as S, type TransitionDef as T, type Machine as a, type MachineSnapshot as b, createMachine as c, type SendOptions as d, type StateName as e, type TransitionEvent as f, type StateConfig as g, type BehaviorFn as h, type BehaviorHelpers as i, type BuiltInHelpers as j, type AfterDef as k, type AfterDef$1 as l };