@doeixd/machine 0.0.4 → 0.0.6

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi.d.ts","sourceRoot":"","sources":["../../src/multi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,OAAO,EACP,OAAO,EACP,cAAc,EACd,eAAe,EAEhB,MAAM,SAAS,CAAC;AAMjB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,IAAI;KACpD,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,CACzB,GAAG,IAAI,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,KAC1B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK;CAC1D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,IAAI;IAC3C;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAElB;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7B;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAEtC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAA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AAU,CAAC,UAAU,EAAE,CAAC,GAAG,IAAI;CAG1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+GG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,gBAAgB,CAAC,CAAC,CAAC,EAE7B,YAAY,EAAE,KAAK,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,EAC7C,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GACnB,CAAC,GAAG,CAAC,CA+DP;AAMD;;;GAGG;AACH,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,WAAW,SAAS,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GACzE,cAAc,CAAC,WAAW,CAAC,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmIC;AACH,wBAAgB,oBAAoB,CAClC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,EAEpD,aAAa,EAAE,CAAC,EAChB,SAAS,EAAE,CAAC,EACZ,eAAe,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,MAAM,CAAC,GACvC,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAmD3C"}
@@ -0,0 +1,202 @@
1
+ /**
2
+ * @file Type-level primitives for formal state machine verification.
3
+ * @description
4
+ * This file provides a Domain Specific Language (DSL) of wrapper functions.
5
+ * These functions serve two purposes:
6
+ * 1. At Runtime: They are identity functions (no-ops). They return your code exactly as is.
7
+ * 2. At Design/Build Time: They "brand" your transition functions with rich type metadata.
8
+ *
9
+ * This allows a static analysis tool (like `ts-morph`) to read your source code
10
+ * and generate a formal Statechart (JSON) that perfectly matches your implementation,
11
+ * including resolving Class Constructors to their names.
12
+ */
13
+ /**
14
+ * A unique symbol used to "brand" a type with metadata.
15
+ * This key allows the static analyzer to find the metadata within a complex type signature.
16
+ */
17
+ export declare const META_KEY: unique symbol;
18
+ /**
19
+ * Runtime metadata symbol.
20
+ * Non-enumerable property key for storing metadata on function objects at runtime.
21
+ * @internal
22
+ */
23
+ export declare const RUNTIME_META: unique symbol;
24
+ /**
25
+ * Helper type representing a Class Constructor.
26
+ * Used to reference target states by their class definition rather than magic strings.
27
+ */
28
+ export type ClassConstructor = new (...args: any[]) => any;
29
+ /**
30
+ * Metadata describing a Guard condition.
31
+ */
32
+ export interface GuardMeta {
33
+ /** The name of the guard (e.g., "isAdmin"). */
34
+ name: string;
35
+ /** Optional documentation explaining the logic. */
36
+ description?: string;
37
+ }
38
+ /**
39
+ * Metadata describing an Invoked Service (async operation).
40
+ */
41
+ export interface InvokeMeta {
42
+ /** The name of the service source (e.g., "fetchUserData"). */
43
+ src: string;
44
+ /** The state class to transition to on success. */
45
+ onDone: ClassConstructor;
46
+ /** The state class to transition to on error. */
47
+ onError: ClassConstructor;
48
+ /** Optional description. */
49
+ description?: string;
50
+ }
51
+ /**
52
+ * Metadata describing a generic Action (side effect).
53
+ */
54
+ export interface ActionMeta {
55
+ /** The name of the action (e.g., "logAnalytics"). */
56
+ name: string;
57
+ /** Optional description. */
58
+ description?: string;
59
+ }
60
+ /**
61
+ * The comprehensive shape of metadata that can be encoded into a transition's type.
62
+ */
63
+ export interface TransitionMeta {
64
+ /** The target state class this transition leads to. */
65
+ target?: ClassConstructor;
66
+ /** A human-readable description of the transition. */
67
+ description?: string;
68
+ /** An array of guards that must be true for this transition to be enabled. */
69
+ guards?: GuardMeta[];
70
+ /** A service to invoke upon taking this transition (or entering the state). */
71
+ invoke?: InvokeMeta;
72
+ /** Fire-and-forget side effects associated with this transition. */
73
+ actions?: ActionMeta[];
74
+ }
75
+ /**
76
+ * The Branded Type.
77
+ * It takes a function type `F` and intersects it with a hidden metadata object `M`.
78
+ * This is the mechanism that carries information from your code to the compiler API.
79
+ */
80
+ export type WithMeta<F extends (...args: any[]) => any, M extends TransitionMeta> = F & {
81
+ [META_KEY]: M;
82
+ };
83
+ /**
84
+ * Runtime metadata interface (resolved class names as strings)
85
+ */
86
+ export interface RuntimeTransitionMeta {
87
+ target?: string;
88
+ description?: string;
89
+ guards?: Array<{
90
+ name: string;
91
+ description?: string;
92
+ }>;
93
+ invoke?: {
94
+ src: string;
95
+ onDone: string;
96
+ onError: string;
97
+ description?: string;
98
+ };
99
+ actions?: Array<{
100
+ name: string;
101
+ description?: string;
102
+ }>;
103
+ }
104
+ /**
105
+ * Defines a transition to a target state class.
106
+ *
107
+ * @param target - The Class Constructor of the state being transitioned to.
108
+ * @param implementation - The implementation function returning the new state instance.
109
+ * @returns The implementation function, branded with target metadata.
110
+ *
111
+ * @example
112
+ * login = transitionTo(LoggedInMachine, (user) => new LoggedInMachine({ user }));
113
+ */
114
+ export declare function transitionTo<T extends ClassConstructor, F extends (...args: any[]) => any>(_target: T, implementation: F): WithMeta<F, {
115
+ target: T;
116
+ }>;
117
+ /**
118
+ * Annotates a transition with a description for documentation generation.
119
+ *
120
+ * @param text - The description text.
121
+ * @param transition - The transition function (or wrapper) to annotate.
122
+ * @example
123
+ * logout = describe("Logs the user out", transitionTo(LoggedOut, ...));
124
+ */
125
+ export declare function describe<F extends (...args: any[]) => any, M extends TransitionMeta>(_text: string, transition: WithMeta<F, M>): WithMeta<F, M & {
126
+ description: string;
127
+ }>;
128
+ /**
129
+ * Annotates a transition with a Guard condition.
130
+ * Note: This only adds metadata. You must still implement the `if` check inside your function.
131
+ *
132
+ * @param guard - Object containing the name and optional description of the guard.
133
+ * @param transition - The transition function to guard.
134
+ * @example
135
+ * delete = guarded({ name: "isAdmin" }, transitionTo(Deleted, ...));
136
+ */
137
+ export declare function guarded<F extends (...args: any[]) => any, M extends TransitionMeta>(guard: GuardMeta, transition: WithMeta<F, M>): WithMeta<F, M & {
138
+ guards: [typeof guard];
139
+ }>;
140
+ /**
141
+ * Annotates a transition with an Invoked Service (asynchronous effect).
142
+ *
143
+ * @param service - configuration for the service (source, onDone target, onError target).
144
+ * @param implementation - The async function implementation.
145
+ * @example
146
+ * load = invoke(
147
+ * { src: "fetchData", onDone: LoadedMachine, onError: ErrorMachine },
148
+ * async () => { ... }
149
+ * );
150
+ */
151
+ export declare function invoke<D extends ClassConstructor, E extends ClassConstructor, F extends (...args: any[]) => any>(service: {
152
+ src: string;
153
+ onDone: D;
154
+ onError: E;
155
+ description?: string;
156
+ }, implementation: F): WithMeta<F, {
157
+ invoke: typeof service;
158
+ }>;
159
+ /**
160
+ * Annotates a transition with a side-effect Action.
161
+ * Useful for logging, analytics, or external event firing that doesn't change state structure.
162
+ *
163
+ * @param action - Object containing the name and optional description.
164
+ * @param transition - The transition function to annotate.
165
+ * @example
166
+ * click = action({ name: "trackClick" }, (ctx) => ...);
167
+ */
168
+ export declare function action<F extends (...args: any[]) => any, M extends TransitionMeta>(action: ActionMeta, transition: WithMeta<F, M>): WithMeta<F, M & {
169
+ actions: [typeof action];
170
+ }>;
171
+ /**
172
+ * Flexible metadata wrapper for functional and type-state patterns.
173
+ *
174
+ * This function allows attaching metadata to values that don't use the class-based
175
+ * MachineBase pattern. It's particularly useful for:
176
+ * - Functional machines created with createMachine()
177
+ * - Type-state discriminated unions
178
+ * - Generic machine configurations
179
+ *
180
+ * @param meta - Partial metadata object describing states, transitions, etc.
181
+ * @param value - The value to annotate (machine, config, factory function, etc.)
182
+ * @returns The value unchanged (identity function at runtime)
183
+ *
184
+ * @example
185
+ * // Annotate a functional machine
186
+ * const machine = metadata(
187
+ * {
188
+ * target: IdleState,
189
+ * description: "Counter machine with increment/decrement"
190
+ * },
191
+ * createMachine({ count: 0 }, { ... })
192
+ * );
193
+ *
194
+ * @example
195
+ * // Annotate a factory function
196
+ * export const createCounter = metadata(
197
+ * { description: "Creates a counter starting at 0" },
198
+ * () => createMachine({ count: 0 }, { ... })
199
+ * );
200
+ */
201
+ export declare function metadata<T>(_meta: Partial<TransitionMeta>, value: T): T;
202
+ //# sourceMappingURL=primitives.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/primitives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH;;;GAGG;AACH,eAAO,MAAM,QAAQ,eAAwB,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,YAAY,eAAqC,CAAC;AAE/D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,8DAA8D;IAC9D,GAAG,EAAE,MAAM,CAAC;IACZ,mDAAmD;IACnD,MAAM,EAAE,gBAAgB,CAAC;IACzB,iDAAiD;IACjD,OAAO,EAAE,gBAAgB,CAAC;IAC1B,4BAA4B;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,uDAAuD;IACvD,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8E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AC,OAAO,MAAM,CAAC,CAAA;CAAE,CAAC,CAQ/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAIvE"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @file Runtime statechart extraction utilities
3
+ * @description Extract statecharts from running machine instances using Symbol-based metadata
4
+ */
5
+ import { type RuntimeTransitionMeta } from './primitives';
6
+ /**
7
+ * Extract metadata from a single function if it has runtime metadata attached
8
+ *
9
+ * @param fn - Function to extract from
10
+ * @returns Metadata object or null if no metadata
11
+ */
12
+ export declare function extractFunctionMetadata(fn: any): RuntimeTransitionMeta | null;
13
+ /**
14
+ * Extract state node from a machine class instance
15
+ *
16
+ * @param stateInstance - Instance of a machine state class
17
+ * @returns State node with transitions
18
+ */
19
+ export declare function extractStateNode(stateInstance: any): any;
20
+ /**
21
+ * Generate a complete statechart from multiple state class instances
22
+ *
23
+ * @param states - Object mapping state names to state instances
24
+ * @param config - Chart configuration
25
+ * @returns XState-compatible statechart JSON
26
+ *
27
+ * @example
28
+ * const chart = generateStatechart({
29
+ * 'LoggedOut': new LoggedOutMachine(),
30
+ * 'LoggedIn': new LoggedInMachine()
31
+ * }, {
32
+ * id: 'auth',
33
+ * initial: 'LoggedOut'
34
+ * });
35
+ */
36
+ export declare function generateStatechart(states: Record<string, any>, config: {
37
+ id: string;
38
+ initial: string;
39
+ description?: string;
40
+ }): any;
41
+ /**
42
+ * Convenience function to extract statechart from a single machine instance
43
+ * Useful for simple machines with a single context but multiple transitions
44
+ *
45
+ * @param machineInstance - Machine instance
46
+ * @param config - Chart configuration
47
+ * @returns XState-compatible statechart JSON
48
+ */
49
+ export declare function extractFromInstance(machineInstance: any, config: {
50
+ id: string;
51
+ stateName?: string;
52
+ }): any;
53
+ //# sourceMappingURL=runtime-extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-extract.d.ts","sourceRoot":"","sources":["../../src/runtime-extract.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAgB,KAAK,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAExE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,GAAG,GAAG,qBAAqB,GAAG,IAAI,CAO7E;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,GAAG,GAAG,GAAG,CAoDxD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5D,GAAG,CAgBL;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,eAAe,EAAE,GAAG,EACpB,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACzC,GAAG,CAUL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doeixd/machine",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
@@ -71,7 +71,11 @@
71
71
  "watch": "pridepack watch",
72
72
  "start": "pridepack start",
73
73
  "dev": "pridepack dev",
74
- "test": "vitest"
74
+ "test": "vitest --test",
75
+ "extract": "tsx scripts/extract-statechart.ts --config .statechart.config.ts",
76
+ "extract:watch": "tsx scripts/extract-statechart.ts --config .statechart.config.ts --watch",
77
+ "extract:validate": "tsx scripts/extract-statechart.ts --config .statechart.config.ts --validate",
78
+ "extract:legacy": "tsx src/extract.ts"
75
79
  },
76
80
  "private": false,
77
81
  "description": "A minimal, type-safe state machine library for TypeScript centered on Type-State Programming. Uses the TypeScript compiler to catch invalid state transitions at compile-time, making illegal states unrepresentable. Features immutable updates, discriminated unions, async support, and integrations for React and Solid.js. Includes static analysis tools for generating formal statecharts compatible with Stately Viz and XState tooling.",