add type generation
This commit is contained in:
Vendored
+62
@@ -0,0 +1,62 @@
|
|||||||
|
export type Event_T = [name: string, payload: any];
|
||||||
|
export interface Machine_T {
|
||||||
|
states: Array<State_T>;
|
||||||
|
}
|
||||||
|
export interface State_T {
|
||||||
|
name: string;
|
||||||
|
eventReactionCouplings: Array<EventReactionCouplings_T>;
|
||||||
|
}
|
||||||
|
export interface EventReactionCouplings_T {
|
||||||
|
eventName: string;
|
||||||
|
reactions: Array<Reaction_T>;
|
||||||
|
}
|
||||||
|
export type Reaction_T = SideEffect_T | ContextMutation_T | Goto_T;
|
||||||
|
export interface SideEffect_T {
|
||||||
|
type: 'SideEffect';
|
||||||
|
fn: SideEffectFunction_T;
|
||||||
|
}
|
||||||
|
export type SideEffectFunction_T = (ctx: any, e: Event_T, self: Interpreter_T) => void;
|
||||||
|
export interface ContextMutation_T {
|
||||||
|
type: 'ContextMutation';
|
||||||
|
fn: ContextMutationFunction_T;
|
||||||
|
}
|
||||||
|
export type ContextMutationFunction_T = (ctx: any, e: Event_T, self: Interpreter_T) => any;
|
||||||
|
export interface Goto_T {
|
||||||
|
type: 'Goto';
|
||||||
|
targetStateName: string;
|
||||||
|
}
|
||||||
|
export declare const Machine: (...states: Array<State_T>) => Machine_T;
|
||||||
|
export declare const State: (name: string, ...eventReactionCouplings: Array<EventReactionCouplings_T>) => State_T;
|
||||||
|
export declare const On: (eventName: string, ...reactions: Array<Reaction_T>) => EventReactionCouplings_T;
|
||||||
|
export declare const SideEffect: (fn: SideEffectFunction_T) => SideEffect_T;
|
||||||
|
export declare const Goto: (targetStateName: string) => Goto_T;
|
||||||
|
export declare const Context: (fn: ContextMutationFunction_T) => ContextMutation_T;
|
||||||
|
export interface Interpreter_T {
|
||||||
|
machine: Machine_T;
|
||||||
|
state: string;
|
||||||
|
context: any;
|
||||||
|
eventQueue: Array<Event_T>;
|
||||||
|
isTransitioning: boolean;
|
||||||
|
subscriptions: Record<string, SubscriptionCallbackFunction_T>;
|
||||||
|
}
|
||||||
|
export declare function interpret(machine: Machine_T, options: {
|
||||||
|
state?: string;
|
||||||
|
context: any;
|
||||||
|
}): Interpreter_T;
|
||||||
|
/** Inject an Event into the Interpreter's "tick queue".
|
||||||
|
*
|
||||||
|
* An event can be signify something "new" happening, such that its reactions should run on the next Tick;
|
||||||
|
* or it can signify a milestone "within" the current Tick, such that a Tick can be thought of as having
|
||||||
|
* "sub-Ticks".
|
||||||
|
*
|
||||||
|
* This distinction is significant for proper ordering of reaction execution, and also for determining
|
||||||
|
* whether to run a reaction at all. If an Event is received, and is specified to be applied on a past
|
||||||
|
* Tick, it is discarded.
|
||||||
|
*/
|
||||||
|
export declare function send(interpreter: Interpreter_T, event: Event_T): void;
|
||||||
|
export declare const enqueue: typeof send;
|
||||||
|
export type SubscriptionCallbackFunction_T = (self: Interpreter_T) => void;
|
||||||
|
export declare function subscribe(interpreter: Interpreter_T, callback: SubscriptionCallbackFunction_T): number;
|
||||||
|
export declare function unsubscribe(interpreter: Interpreter_T, subscriptionId: string): void;
|
||||||
|
export declare const Spawn: () => void;
|
||||||
|
export declare const Unspawn: () => void;
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
export {};
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
export {};
|
||||||
+5
-1
@@ -5,14 +5,18 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
"import": "./dist/index.js"
|
"import": "./dist/index.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node build.mjs",
|
"build": "node build.mjs",
|
||||||
|
"build-types": "node tsc",
|
||||||
"build-tests": "esbuild --bundle --outdir=dist/tests src/tests/*.ts"
|
"build-tests": "esbuild --bundle --outdir=dist/tests src/tests/*.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"esbuild": "^0.17.18"
|
"@types/node": "^20.1.4",
|
||||||
|
"esbuild": "^0.17.18",
|
||||||
|
"typescript": "^5.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -2,6 +2,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"emitDeclarationOnly": true,
|
"emitDeclarationOnly": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"lib": ["ES2020"]
|
"lib": ["ES2020"],
|
||||||
|
"outDir": "dist"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,6 +112,11 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.17.18.tgz#3a8e57153905308db357fd02f57c180ee3a0a1fa"
|
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.17.18.tgz#3a8e57153905308db357fd02f57c180ee3a0a1fa"
|
||||||
integrity sha512-qU25Ma1I3NqTSHJUOKi9sAH1/Mzuvlke0ioMJRthLXKm7JiSKVwFghlGbDLOO2sARECGhja4xYfRAZNPAkooYg==
|
integrity sha512-qU25Ma1I3NqTSHJUOKi9sAH1/Mzuvlke0ioMJRthLXKm7JiSKVwFghlGbDLOO2sARECGhja4xYfRAZNPAkooYg==
|
||||||
|
|
||||||
|
"@types/node@^20.1.4":
|
||||||
|
version "20.1.4"
|
||||||
|
resolved "https://verdaccio.torahanytime.com/@types/node/-/node-20.1.4.tgz#83f148d2d1f5fe6add4c53358ba00d97fc4cdb71"
|
||||||
|
integrity sha512-At4pvmIOki8yuwLtd7BNHl3CiWNbtclUbNtScGx4OHfBd4/oWoJC8KRCIxXwkdndzhxOsPXihrsOoydxBjlE9Q==
|
||||||
|
|
||||||
esbuild@^0.17.18:
|
esbuild@^0.17.18:
|
||||||
version "0.17.18"
|
version "0.17.18"
|
||||||
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.18.tgz#f4f8eb6d77384d68cd71c53eb6601c7efe05e746"
|
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.18.tgz#f4f8eb6d77384d68cd71c53eb6601c7efe05e746"
|
||||||
@@ -139,3 +144,8 @@ esbuild@^0.17.18:
|
|||||||
"@esbuild/win32-arm64" "0.17.18"
|
"@esbuild/win32-arm64" "0.17.18"
|
||||||
"@esbuild/win32-ia32" "0.17.18"
|
"@esbuild/win32-ia32" "0.17.18"
|
||||||
"@esbuild/win32-x64" "0.17.18"
|
"@esbuild/win32-x64" "0.17.18"
|
||||||
|
|
||||||
|
typescript@^5.0.4:
|
||||||
|
version "5.0.4"
|
||||||
|
resolved "https://verdaccio.torahanytime.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b"
|
||||||
|
integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==
|
||||||
|
|||||||
Reference in New Issue
Block a user