@doeixd/machine 0.0.13 → 0.0.18

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.
Files changed (54) hide show
  1. package/README.md +77 -25
  2. package/dist/cjs/development/core.js +1852 -0
  3. package/dist/cjs/development/core.js.map +7 -0
  4. package/dist/cjs/development/index.js +1377 -1372
  5. package/dist/cjs/development/index.js.map +4 -4
  6. package/dist/cjs/production/core.js +1 -0
  7. package/dist/cjs/production/index.js +5 -5
  8. package/dist/esm/development/core.js +1829 -0
  9. package/dist/esm/development/core.js.map +7 -0
  10. package/dist/esm/development/index.js +1377 -1372
  11. package/dist/esm/development/index.js.map +4 -4
  12. package/dist/esm/production/core.js +1 -0
  13. package/dist/esm/production/index.js +5 -5
  14. package/dist/types/core.d.ts +18 -0
  15. package/dist/types/core.d.ts.map +1 -0
  16. package/dist/types/extract.d.ts +15 -1
  17. package/dist/types/extract.d.ts.map +1 -1
  18. package/dist/types/functional-combinators.d.ts +3 -5
  19. package/dist/types/functional-combinators.d.ts.map +1 -1
  20. package/dist/types/index.d.ts +254 -18
  21. package/dist/types/index.d.ts.map +1 -1
  22. package/dist/types/middleware/composition.d.ts +460 -0
  23. package/dist/types/middleware/composition.d.ts.map +1 -0
  24. package/dist/types/middleware/core.d.ts +196 -0
  25. package/dist/types/middleware/core.d.ts.map +1 -0
  26. package/dist/types/middleware/history.d.ts +54 -0
  27. package/dist/types/middleware/history.d.ts.map +1 -0
  28. package/dist/types/middleware/index.d.ts +10 -0
  29. package/dist/types/middleware/index.d.ts.map +1 -0
  30. package/dist/types/middleware/snapshot.d.ts +63 -0
  31. package/dist/types/middleware/snapshot.d.ts.map +1 -0
  32. package/dist/types/middleware/time-travel.d.ts +81 -0
  33. package/dist/types/middleware/time-travel.d.ts.map +1 -0
  34. package/package.json +19 -6
  35. package/src/core.ts +167 -0
  36. package/src/entry-react.ts +9 -0
  37. package/src/entry-solid.ts +9 -0
  38. package/src/extract.ts +61 -61
  39. package/src/functional-combinators.ts +3 -3
  40. package/src/generators.ts +6 -6
  41. package/src/index.ts +389 -101
  42. package/src/middleware/composition.ts +944 -0
  43. package/src/middleware/core.ts +573 -0
  44. package/src/middleware/history.ts +104 -0
  45. package/src/middleware/index.ts +13 -0
  46. package/src/middleware/snapshot.ts +153 -0
  47. package/src/middleware/time-travel.ts +236 -0
  48. package/src/middleware.ts +735 -1614
  49. package/src/prototype_functional.ts +46 -0
  50. package/src/reproduce_issue.ts +26 -0
  51. package/dist/types/middleware.d.ts +0 -1048
  52. package/dist/types/middleware.d.ts.map +0 -1
  53. package/dist/types/runtime-extract.d.ts +0 -53
  54. package/dist/types/runtime-extract.d.ts.map +0 -1
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @file History tracking middleware
3
+ */
4
+ import type { BaseMachine } from '../index';
5
+ /**
6
+ * A single history entry recording a transition.
7
+ */
8
+ export interface HistoryEntry {
9
+ /** Unique ID for this history entry */
10
+ id: string;
11
+ /** Name of the transition that was called */
12
+ transitionName: string;
13
+ /** Arguments passed to the transition */
14
+ args: any[];
15
+ /** Timestamp when the transition occurred */
16
+ timestamp: number;
17
+ /** Optional serialized version of args for persistence */
18
+ serializedArgs?: string;
19
+ }
20
+ /**
21
+ * Serializer interface for converting context/args to/from strings.
22
+ */
23
+ export interface Serializer<T = any> {
24
+ serialize: (value: T) => string;
25
+ deserialize: (str: string) => T;
26
+ }
27
+ /**
28
+ * Creates a machine with history tracking capabilities.
29
+ * Records all transitions that occur, allowing you to see the sequence of state changes.
30
+ *
31
+ * @template M - The machine type
32
+ * @param machine - The machine to track
33
+ * @param options - Configuration options
34
+ * @returns A new machine with history tracking
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const tracked = withHistory(counter, { maxSize: 50 });
39
+ * tracked.increment();
40
+ * console.log(tracked.history); // [{ id: "entry-1", transitionName: "increment", ... }]
41
+ * ```
42
+ */
43
+ export declare function withHistory<M extends BaseMachine<any>>(machine: M, options?: {
44
+ /** Maximum number of history entries to keep (default: unlimited) */
45
+ maxSize?: number;
46
+ /** Optional serializer for transition arguments */
47
+ serializer?: Serializer<any[]>;
48
+ /** Callback when a transition occurs */
49
+ onEntry?: (entry: HistoryEntry) => void;
50
+ }): M & {
51
+ history: HistoryEntry[];
52
+ clearHistory: () => void;
53
+ };
54
+ //# sourceMappingURL=history.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../../src/middleware/history.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAO5C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,6CAA6C;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,GAAG;IACjC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;IAChC,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,CAAC;CACjC;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,CAAC,EACpD,OAAO,EAAE,CAAC,EACV,OAAO,GAAE;IACP,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,UAAU,CAAC,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/B,wCAAwC;IACxC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;CACpC,GACL,CAAC,GAAG;IAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IAAC,YAAY,EAAE,MAAM,IAAI,CAAA;CAAE,CAsC3D"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file Middleware module exports
3
+ * @description Unified exports for all middleware functionality
4
+ */
5
+ export * from './core';
6
+ export * from './history';
7
+ export * from './snapshot';
8
+ export * from './time-travel';
9
+ export * from './composition';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/middleware/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,QAAQ,CAAC;AAGvB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @file Snapshot tracking middleware for context state
3
+ */
4
+ import type { Context, BaseMachine } from '../index';
5
+ import type { Serializer } from './history';
6
+ /**
7
+ * A snapshot of machine context before and after a transition.
8
+ */
9
+ export interface ContextSnapshot<C extends object> {
10
+ /** Unique ID for this snapshot */
11
+ id: string;
12
+ /** Name of the transition that caused this snapshot */
13
+ transitionName: string;
14
+ /** Context before the transition */
15
+ before: C;
16
+ /** Context after the transition */
17
+ after: C;
18
+ /** Timestamp of the snapshot */
19
+ timestamp: number;
20
+ /** Optional serialized versions of contexts */
21
+ serializedBefore?: string;
22
+ serializedAfter?: string;
23
+ /** Optional diff information */
24
+ diff?: any;
25
+ }
26
+ /**
27
+ * Creates a machine with snapshot tracking capabilities.
28
+ * Records context state before and after each transition for debugging and inspection.
29
+ *
30
+ * @template M - The machine type
31
+ * @param machine - The machine to track
32
+ * @param options - Configuration options
33
+ * @returns A new machine with snapshot tracking
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const tracked = withSnapshot(counter, {
38
+ * maxSize: 50,
39
+ * serializer: {
40
+ * serialize: (ctx) => JSON.stringify(ctx),
41
+ * deserialize: (str) => JSON.parse(str)
42
+ * }
43
+ * });
44
+ *
45
+ * tracked.increment();
46
+ * console.log(tracked.snapshots); // [{ before: { count: 0 }, after: { count: 1 }, ... }]
47
+ * ```
48
+ */
49
+ export declare function withSnapshot<M extends BaseMachine<any>>(machine: M, options?: {
50
+ /** Maximum number of snapshots to keep (default: unlimited) */
51
+ maxSize?: number;
52
+ /** Optional serializer for context */
53
+ serializer?: Serializer<Context<M>>;
54
+ /** Custom function to capture additional snapshot data */
55
+ captureSnapshot?: (before: Context<M>, after: Context<M>) => any;
56
+ /** Only capture snapshots where context actually changed */
57
+ onlyOnChange?: boolean;
58
+ }): M & {
59
+ snapshots: ContextSnapshot<Context<M>>[];
60
+ clearSnapshots: () => void;
61
+ restoreSnapshot: (snapshot: ContextSnapshot<Context<M>>['before']) => M;
62
+ };
63
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/middleware/snapshot.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAM5C;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM;IAC/C,kCAAkC;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,uDAAuD;IACvD,cAAc,EAAE,MAAM,CAAC;IACvB,oCAAoC;IACpC,MAAM,EAAE,CAAC,CAAC;IACV,mCAAmC;IACnC,KAAK,EAAE,CAAC,CAAC;IACT,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gCAAgC;IAChC,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAMD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,CAAC,EACrD,OAAO,EAAE,CAAC,EACV,OAAO,GAAE;IACP,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,UAAU,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,0DAA0D;IAC1D,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;IACjE,4DAA4D;IAC5D,YAAY,CAAC,EAAE,OAAO,CAAC;CACnB,GACL,CAAC,GAAG;IACL,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,eAAe,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;CACzE,CA4EA"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @file Time travel middleware combining history, snapshots, and replay capabilities
3
+ */
4
+ import type { Context, BaseMachine } from '../index';
5
+ import { type HistoryEntry, type Serializer } from './history';
6
+ import { type ContextSnapshot } from './snapshot';
7
+ /**
8
+ * A machine enhanced with history tracking capabilities.
9
+ */
10
+ export type WithHistory<M extends BaseMachine<any>> = M & {
11
+ /** History of all transitions */
12
+ history: HistoryEntry[];
13
+ /** Clear all history */
14
+ clearHistory: () => void;
15
+ };
16
+ /**
17
+ * A machine enhanced with snapshot tracking capabilities.
18
+ */
19
+ export type WithSnapshot<M extends BaseMachine<any>> = M & {
20
+ /** Snapshots of context before/after each transition */
21
+ snapshots: ContextSnapshot<Context<M>>[];
22
+ /** Clear all snapshots */
23
+ clearSnapshots: () => void;
24
+ /** Restore machine to a previous context state */
25
+ restoreSnapshot: (context: Context<M>) => M;
26
+ };
27
+ /**
28
+ * A machine enhanced with time travel capabilities.
29
+ */
30
+ export type WithTimeTravel<M extends BaseMachine<any>> = M & {
31
+ /** History of all transitions */
32
+ history: HistoryEntry[];
33
+ /** Snapshots of context before/after each transition */
34
+ snapshots: ContextSnapshot<Context<M>>[];
35
+ /** Clear all history and snapshots */
36
+ clearTimeTravel: () => void;
37
+ /** Clear just the history */
38
+ clearHistory: () => void;
39
+ /** Clear just the snapshots */
40
+ clearSnapshots: () => void;
41
+ /** Restore machine to a previous context state */
42
+ restoreSnapshot: (context: Context<M>) => M;
43
+ /** Replay transitions from a specific point in history */
44
+ replayFrom: (startIndex: number) => M;
45
+ };
46
+ /**
47
+ * Creates a machine with full time travel debugging capabilities.
48
+ * Combines history tracking, snapshots, and replay functionality.
49
+ *
50
+ * @template M - The machine type
51
+ * @param machine - The machine to enhance
52
+ * @param options - Configuration options
53
+ * @returns A machine with time travel capabilities
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const debugMachine = withTimeTravel(counter);
58
+ *
59
+ * // Make some transitions
60
+ * debugMachine.increment();
61
+ * debugMachine.increment();
62
+ * debugMachine.decrement();
63
+ *
64
+ * // Time travel to previous states
65
+ * const previousState = debugMachine.replayFrom(0); // Replay from start
66
+ * const undoLast = debugMachine.restoreSnapshot(debugMachine.snapshots[1].before);
67
+ *
68
+ * // Inspect history
69
+ * console.log(debugMachine.history);
70
+ * console.log(debugMachine.snapshots);
71
+ * ```
72
+ */
73
+ export declare function withTimeTravel<M extends BaseMachine<any>>(machine: M, options?: {
74
+ /** Maximum number of history entries/snapshots to keep */
75
+ maxSize?: number;
76
+ /** Optional serializer for persistence */
77
+ serializer?: Serializer;
78
+ /** Callback when history/snapshot events occur */
79
+ onRecord?: (type: 'history' | 'snapshot', data: any) => void;
80
+ }): WithTimeTravel<M>;
81
+ //# sourceMappingURL=time-travel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time-travel.d.ts","sourceRoot":"","sources":["../../../src/middleware/time-travel.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAMlD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG;IACxD,iCAAiC;IACjC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,wBAAwB;IACxB,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG;IACzD,wDAAwD;IACxD,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,0BAA0B;IAC1B,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,kDAAkD;IAClD,eAAe,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG;IAC3D,iCAAiC;IACjC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,wDAAwD;IACxD,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,sCAAsC;IACtC,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,6BAA6B;IAC7B,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,+BAA+B;IAC/B,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,kDAAkD;IAClD,eAAe,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC5C,0DAA0D;IAC1D,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,CAAC,CAAC;CACvC,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,CAAC,EACvD,OAAO,EAAE,CAAC,EACV,OAAO,GAAE;IACP,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;CACzD,GACL,cAAc,CAAC,CAAC,CAAC,CA2InB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doeixd/machine",
3
- "version": "0.0.13",
3
+ "version": "0.0.18",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
@@ -46,10 +46,7 @@
46
46
  "optional": true
47
47
  }
48
48
  },
49
- "dependencies": {
50
- "ts-morph": "^27.0.2",
51
- "tsx": "^4.20.6"
52
- },
49
+ "dependencies": {},
53
50
  "devDependencies": {
54
51
  "@types/node": "^22.10.2",
55
52
  "@types/react": "^19.2.4",
@@ -57,6 +54,8 @@
57
54
  "chalk": "^5.6.2",
58
55
  "chokidar": "^4.0.3",
59
56
  "commander": "^14.0.2",
57
+ "ts-morph": "^27.0.2",
58
+ "tsx": "^4.20.6",
60
59
  "pridepack": "2.6.4",
61
60
  "react": "^19.2.0",
62
61
  "solid-js": "^1.8.22",
@@ -97,6 +96,7 @@
97
96
  "types": "./dist/types/index.d.ts",
98
97
  "main": "./dist/cjs/production/index.js",
99
98
  "module": "./dist/esm/production/index.js",
99
+ "sideEffects": false,
100
100
  "exports": {
101
101
  ".": {
102
102
  "types": "./dist/types/index.d.ts",
@@ -106,10 +106,23 @@
106
106
  },
107
107
  "require": "./dist/cjs/production/index.js",
108
108
  "import": "./dist/esm/production/index.js"
109
+ },
110
+ "./core": {
111
+ "types": "./dist/types/core.d.ts",
112
+ "development": {
113
+ "require": "./dist/cjs/development/core.js",
114
+ "import": "./dist/esm/development/core.js"
115
+ },
116
+ "require": "./dist/cjs/production/core.js",
117
+ "import": "./dist/esm/production/core.js"
109
118
  }
110
119
  },
111
120
  "typesVersions": {
112
- "*": {}
121
+ "*": {
122
+ "core": [
123
+ "./dist/types/core.d.ts"
124
+ ]
125
+ }
113
126
  },
114
127
  "bin": {
115
128
  "extract": "./scripts/extract-statechart.ts"
package/src/core.ts ADDED
@@ -0,0 +1,167 @@
1
+ /**
2
+ * @file Core library exports without framework integrations
3
+ * @description Minimal bundle for users who don't need React/Solid.js
4
+ */
5
+
6
+ // =============================================================================
7
+ // SECTION: CORE TYPES & INTERFACES
8
+ // =============================================================================
9
+
10
+ export type {
11
+ MaybePromise,
12
+ Machine,
13
+ AsyncMachine,
14
+ AsyncTransitionArgs,
15
+ TransitionOptions,
16
+ BaseMachine,
17
+ DeepReadonly,
18
+ InferMachine,
19
+ Event,
20
+ MachineLike,
21
+ MachineResult
22
+ } from './index';
23
+
24
+ // =============================================================================
25
+ // SECTION: TYPE UTILITIES & INTROSPECTION
26
+ // =============================================================================
27
+
28
+ export type {
29
+ Context,
30
+ Transitions,
31
+ TransitionArgs,
32
+ TransitionNames
33
+ } from './index';
34
+
35
+ // =============================================================================
36
+ // SECTION: MACHINE CREATION (FUNCTIONAL & OOP)
37
+ // =============================================================================
38
+
39
+ export {
40
+ createMachine,
41
+ createAsyncMachine,
42
+ createMachineFactory,
43
+ createMachineBuilder,
44
+ MachineBase,
45
+ next,
46
+ matchMachine,
47
+ hasState
48
+ } from './index';
49
+
50
+ // =============================================================================
51
+ // SECTION: ADVANCED CREATION & IMMUTABLE HELPERS
52
+ // =============================================================================
53
+
54
+ export {
55
+ setContext,
56
+ overrideTransitions,
57
+ extendTransitions,
58
+ combineFactories
59
+ } from './index';
60
+
61
+ // =============================================================================
62
+ // SECTION: RUNTIME & EVENT DISPATCHER
63
+ // =============================================================================
64
+
65
+ export {
66
+ runMachine
67
+ } from './index';
68
+
69
+ // =============================================================================
70
+ // SECTION: GENERATOR-BASED COMPOSITION
71
+ // =============================================================================
72
+
73
+ export {
74
+ run,
75
+ step,
76
+ yieldMachine,
77
+ runSequence,
78
+ createFlow,
79
+ runWithDebug,
80
+ runAsync,
81
+ stepAsync
82
+ } from './generators';
83
+
84
+ // =============================================================================
85
+ // SECTION: TYPE-LEVEL METADATA PRIMITIVES
86
+ // =============================================================================
87
+
88
+ export {
89
+ transitionTo,
90
+ describe,
91
+ guarded,
92
+ guard,
93
+ guardAsync,
94
+ whenGuard,
95
+ whenGuardAsync,
96
+ invoke,
97
+ action,
98
+ metadata,
99
+ META_KEY,
100
+ type TransitionMeta,
101
+ type GuardMeta,
102
+ type InvokeMeta,
103
+ type ActionMeta,
104
+ type ClassConstructor,
105
+ type WithMeta,
106
+ type GuardOptions,
107
+ type GuardFallback,
108
+ type GuardedTransition
109
+ } from './primitives';
110
+
111
+ // =============================================================================
112
+ // SECTION: STATECHART EXTRACTION (Build-time only)
113
+ // =============================================================================
114
+
115
+ // Note: Extraction tools are available as dev dependencies for build-time use
116
+ // They are not included in the runtime bundle for size optimization
117
+ // Use: npx tsx scripts/extract-statechart.ts
118
+
119
+ export type {
120
+ MachineConfig,
121
+ ExtractionConfig
122
+ } from './extract';
123
+
124
+ // =============================================================================
125
+ // SECTION: MIDDLEWARE & INTERCEPTION
126
+ // =============================================================================
127
+
128
+ export * from './middleware/index';
129
+
130
+ // =============================================================================
131
+ // SECTION: UTILITIES & HELPERS
132
+ // =============================================================================
133
+
134
+ export {
135
+ isState,
136
+ createEvent,
137
+ createTransition,
138
+ mergeContext,
139
+ pipeTransitions,
140
+ logState,
141
+ call,
142
+ bindTransitions,
143
+ BoundMachine
144
+ } from './utils';
145
+
146
+ // =============================================================================
147
+ // SECTION: FUNCTIONAL COMBINATORS
148
+ // =============================================================================
149
+
150
+ export {
151
+ createTransitionFactory,
152
+ createTransitionExtender,
153
+ createFunctionalMachine,
154
+ state
155
+ } from './functional-combinators';
156
+
157
+ // =============================================================================
158
+ // SECTION: MULTI-MACHINE COORDINATION
159
+ // =============================================================================
160
+
161
+ export * from './multi';
162
+
163
+ // =============================================================================
164
+ // SECTION: HIGHER-ORDER MACHINES
165
+ // =============================================================================
166
+
167
+ export * from './higher-order';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @file React integration entry point
3
+ */
4
+
5
+ // Re-export core functionality
6
+ export * from './core';
7
+
8
+ // Re-export React-specific functionality
9
+ export * from './react';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @file Solid.js integration entry point
3
+ */
4
+
5
+ // Re-export core functionality
6
+ export * from './core';
7
+
8
+ // Re-export Solid-specific functionality
9
+ export * from './solid';
package/src/extract.ts CHANGED
@@ -106,8 +106,8 @@ export interface ExtractionConfig {
106
106
  * @returns A JSON-compatible value (string, number, object, array).
107
107
  * @internal
108
108
  */
109
- // @ts-expect-error - verbose parameter is used but TypeScript doesn't detect it
110
- function _typeToJson(type: Type, verbose = false): any {
109
+
110
+ export function _typeToJson(type: Type, verbose = false): any {
111
111
  // --- Terminal Types ---
112
112
  const symbol = type.getSymbol();
113
113
  if (symbol && symbol.getDeclarations().some(Node.isClassDeclaration)) {
@@ -324,65 +324,65 @@ function extractFromCallExpression(call: Node, verbose = false): any | null {
324
324
  break;
325
325
 
326
326
  case 'action':
327
- // Args: (action, transition)
328
- if (args[0]) {
329
- const actionMeta = parseObjectLiteral(args[0]);
330
- if (Object.keys(actionMeta).length > 0) {
331
- metadata.actions = [actionMeta];
332
- }
333
- }
334
- // Recurse into wrapped transition
335
- if (args[1] && Node.isCallExpression(args[1])) {
336
- const nested = extractFromCallExpression(args[1], verbose);
337
- if (nested) {
338
- Object.assign(metadata, nested);
339
- }
340
- }
341
- break;
342
-
343
- case 'guard':
344
- // Args: (condition, transition, options?)
345
- // Extract description from options object (third argument)
346
- if (args[2]) {
347
- const options = parseObjectLiteral(args[2]);
348
- if (options.description) {
349
- metadata.description = options.description;
350
- }
351
- }
352
- // Add a generic guard condition for static analysis
353
- metadata.guards = [{ name: 'runtime_guard', description: metadata.description || 'Synchronous condition check' }];
354
- // Recurse into the transition (second argument)
355
- if (args[1] && Node.isCallExpression(args[1])) {
356
- const nested = extractFromCallExpression(args[1], verbose);
357
- if (nested) {
358
- Object.assign(metadata, nested);
359
- }
360
- }
361
- break;
362
-
363
- case 'guardAsync':
364
- // Args: (condition, transition, options?)
365
- // Extract description from options object (third argument)
366
- if (args[2]) {
367
- const options = parseObjectLiteral(args[2]);
368
- if (options.description) {
369
- metadata.description = options.description;
370
- }
371
- }
372
- // Add a generic guard condition for static analysis
373
- metadata.guards = [{ name: 'runtime_guard_async', description: metadata.description || 'Asynchronous condition check' }];
374
- // Recurse into the transition (second argument)
375
- if (args[1] && Node.isCallExpression(args[1])) {
376
- const nested = extractFromCallExpression(args[1], verbose);
377
- if (nested) {
378
- Object.assign(metadata, nested);
379
- }
380
- }
381
- break;
382
-
383
- default:
384
- // Not a DSL primitive we recognize
385
- return null;
327
+ // Args: (action, transition)
328
+ if (args[0]) {
329
+ const actionMeta = parseObjectLiteral(args[0]);
330
+ if (Object.keys(actionMeta).length > 0) {
331
+ metadata.actions = [actionMeta];
332
+ }
333
+ }
334
+ // Recurse into wrapped transition
335
+ if (args[1] && Node.isCallExpression(args[1])) {
336
+ const nested = extractFromCallExpression(args[1], verbose);
337
+ if (nested) {
338
+ Object.assign(metadata, nested);
339
+ }
340
+ }
341
+ break;
342
+
343
+ case 'guard':
344
+ // Args: (condition, transition, options?)
345
+ // Extract description from options object (third argument)
346
+ if (args[2]) {
347
+ const options = parseObjectLiteral(args[2]);
348
+ if (options.description) {
349
+ metadata.description = options.description;
350
+ }
351
+ }
352
+ // Add a generic guard condition for static analysis
353
+ metadata.guards = [{ name: 'runtime_guard', description: metadata.description || 'Synchronous condition check' }];
354
+ // Recurse into the transition (second argument)
355
+ if (args[1] && Node.isCallExpression(args[1])) {
356
+ const nested = extractFromCallExpression(args[1], verbose);
357
+ if (nested) {
358
+ Object.assign(metadata, nested);
359
+ }
360
+ }
361
+ break;
362
+
363
+ case 'guardAsync':
364
+ // Args: (condition, transition, options?)
365
+ // Extract description from options object (third argument)
366
+ if (args[2]) {
367
+ const options = parseObjectLiteral(args[2]);
368
+ if (options.description) {
369
+ metadata.description = options.description;
370
+ }
371
+ }
372
+ // Add a generic guard condition for static analysis
373
+ metadata.guards = [{ name: 'runtime_guard_async', description: metadata.description || 'Asynchronous condition check' }];
374
+ // Recurse into the transition (second argument)
375
+ if (args[1] && Node.isCallExpression(args[1])) {
376
+ const nested = extractFromCallExpression(args[1], verbose);
377
+ if (nested) {
378
+ Object.assign(metadata, nested);
379
+ }
380
+ }
381
+ break;
382
+
383
+ default:
384
+ // Not a DSL primitive we recognize
385
+ return null;
386
386
  }
387
387
 
388
388
  return Object.keys(metadata).length > 0 ? metadata : null;
@@ -1,4 +1,4 @@
1
- import { createMachine, Machine, extendTransitions } from './index';
1
+ import { createMachine, Machine, BaseMachine, extendTransitions } from './index';
2
2
 
3
3
  /**
4
4
  * Creates a factory for building type-safe transitions for a specific machine.
@@ -75,7 +75,7 @@ export function createTransitionFactory<C extends object>() {
75
75
  return function createTransition<TArgs extends any[]>(
76
76
  transformer: (ctx: C, ...args: TArgs) => C
77
77
  ) {
78
- return function (this: Machine<C>, ...args: TArgs): Machine<C> {
78
+ return function (this: BaseMachine<C>, ...args: TArgs): Machine<C> {
79
79
  const nextContext = transformer(this.context, ...args);
80
80
  // Use `this` as the transitions object, which includes all current transitions
81
81
  return createMachine(nextContext, this);
@@ -196,7 +196,7 @@ type MachineTransitions<
196
196
  C extends object
197
197
  > = {
198
198
  [K in keyof T]: T[K] extends (ctx: C, ...args: infer A) => C
199
- ? (this: { context: C } & T, ...args: A) => Machine<C>
199
+ ? (this: Machine<C>, ...args: A) => Machine<C>
200
200
  : never;
201
201
  };
202
202