@xstate/graph
Advanced tools
Comparing version 2.0.0-beta.4 to 2.0.0-beta.5
@@ -1,4 +0,4 @@ | ||
import { ActorLogic, ActorSystem, EventObject } from 'xstate'; | ||
import { ActorLogic, ActorSystem, EventObject, Snapshot } from 'xstate'; | ||
import { TraversalOptions } from "./types.js"; | ||
import { AdjacencyMap } from "./graph.js"; | ||
export declare function getAdjacencyMap<TEvent extends EventObject, TSnapshot, TInternalState = TSnapshot, TPersisted = TInternalState, TSystem extends ActorSystem<any> = ActorSystem<any>>(logic: ActorLogic<TEvent, TSnapshot, TInternalState, TPersisted, TSystem>, options: TraversalOptions<TInternalState, TEvent>): AdjacencyMap<TInternalState, TEvent>; | ||
export declare function getAdjacencyMap<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput, TPersisted = TSnapshot, TSystem extends ActorSystem<any> = ActorSystem<any>>(logic: ActorLogic<TSnapshot, TEvent, TInput, TPersisted, TSystem>, options: TraversalOptions<TSnapshot, TEvent>): AdjacencyMap<TSnapshot, TEvent>; |
@@ -1,2 +0,2 @@ | ||
import { EventObject, AnyStateMachine, AnyState, StateFrom, EventFrom, AnyActorLogic, SnapshotFrom, EventFromLogic } from 'xstate'; | ||
import { EventObject, AnyStateMachine, EventFrom, AnyActorLogic, EventFromLogic, Snapshot } from 'xstate'; | ||
import type { SerializedEvent, SerializedState, StatePath, DirectedGraphNode, TraversalOptions, AnyStateNode, TraversalConfig } from "./types.js"; | ||
@@ -9,5 +9,5 @@ /** | ||
export declare function getChildren(stateNode: AnyStateNode): AnyStateNode[]; | ||
export declare function serializeMachineState(state: AnyState): SerializedState; | ||
export declare function serializeMachineState(state: ReturnType<AnyStateMachine['transition']>): SerializedState; | ||
export declare function serializeEvent<TEvent extends EventObject>(event: TEvent): SerializedEvent; | ||
export declare function createDefaultMachineOptions<TMachine extends AnyStateMachine>(machine: TMachine, options?: TraversalOptions<StateFrom<TMachine>, EventFrom<TMachine>>): TraversalOptions<StateFrom<TMachine>, EventFrom<TMachine>>; | ||
export declare function createDefaultMachineOptions<TMachine extends AnyStateMachine>(machine: TMachine, options?: TraversalOptions<ReturnType<TMachine['transition']>, EventFrom<TMachine>>): TraversalOptions<ReturnType<TMachine['transition']>, EventFrom<TMachine>>; | ||
export declare function createDefaultLogicOptions(): TraversalOptions<any, any>; | ||
@@ -27,3 +27,3 @@ export declare function toDirectedGraph(stateMachine: AnyStateNode | AnyStateMachine): DirectedGraphNode; | ||
} | ||
export declare function resolveTraversalOptions<TLogic extends AnyActorLogic, TState extends SnapshotFrom<TLogic>, TEvent extends EventFromLogic<TLogic>>(logic: AnyActorLogic, traversalOptions?: TraversalOptions<TState, TEvent>, defaultOptions?: TraversalOptions<TState, TEvent>): TraversalConfig<TState, TEvent>; | ||
export declare function joinPaths<TState, TEvent extends EventObject>(headPath: StatePath<TState, TEvent>, tailPath: StatePath<TState, TEvent>): StatePath<TState, TEvent>; | ||
export declare function resolveTraversalOptions<TLogic extends AnyActorLogic>(logic: TLogic, traversalOptions?: TraversalOptions<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>>, defaultOptions?: TraversalOptions<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>>): TraversalConfig<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>>; | ||
export declare function joinPaths<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject>(headPath: StatePath<TSnapshot, TEvent>, tailPath: StatePath<TSnapshot, TEvent>): StatePath<TSnapshot, TEvent>; |
@@ -1,3 +0,3 @@ | ||
import { ActorLogic, ActorSystem, EventObject } from 'xstate'; | ||
import { ActorLogic, ActorSystem, EventObject, Snapshot } from 'xstate'; | ||
import { StatePath, TraversalOptions } from "./types.js"; | ||
export declare function getPathsFromEvents<TEvent extends EventObject, TSnapshot, TInternalState = TSnapshot, TPersisted = TInternalState, TSystem extends ActorSystem<any> = ActorSystem<any>>(logic: ActorLogic<TEvent, TSnapshot, TInternalState, TPersisted, TSystem>, events: TEvent[], options?: TraversalOptions<TInternalState, TEvent>): Array<StatePath<TInternalState, TEvent>>; | ||
export declare function getPathsFromEvents<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput, TPersisted = TSnapshot, TSystem extends ActorSystem<any> = ActorSystem<any>>(logic: ActorLogic<TSnapshot, TEvent, TInput, TPersisted, TSystem>, events: TEvent[], options?: TraversalOptions<TSnapshot, TEvent>): Array<StatePath<TSnapshot, TEvent>>; |
@@ -1,3 +0,3 @@ | ||
import { AnyActorLogic, SnapshotFrom, EventFromLogic } from 'xstate'; | ||
import { AnyActorLogic, EventFromLogic } from 'xstate'; | ||
import { StatePath, TraversalOptions } from "./types.js"; | ||
export declare function getShortestPaths<TLogic extends AnyActorLogic, TState extends SnapshotFrom<TLogic>, TEvent extends EventFromLogic<TLogic>>(logic: TLogic, options?: TraversalOptions<TState, TEvent>): Array<StatePath<TState, TEvent>>; | ||
export declare function getShortestPaths<TLogic extends AnyActorLogic>(logic: TLogic, options?: TraversalOptions<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>>): Array<StatePath<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>>>; |
@@ -1,3 +0,3 @@ | ||
import { AnyActorLogic, EventFromLogic, SnapshotFrom } from 'xstate'; | ||
import { AnyActorLogic, EventFromLogic } from 'xstate'; | ||
import { StatePath, TraversalOptions } from "./types.js"; | ||
export declare function getSimplePaths<TLogic extends AnyActorLogic, TState extends SnapshotFrom<TLogic>, TEvent extends EventFromLogic<TLogic>>(logic: TLogic, options?: TraversalOptions<TState, TEvent>): Array<StatePath<TState, TEvent>>; | ||
export declare function getSimplePaths<TLogic extends AnyActorLogic>(logic: TLogic, options?: TraversalOptions<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>>): Array<StatePath<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>>>; |
@@ -1,2 +0,2 @@ | ||
import { EventObject, StateValue, StateNode, TransitionDefinition } from 'xstate'; | ||
import { EventObject, StateValue, StateNode, TransitionDefinition, Snapshot } from 'xstate'; | ||
export type AnyStateNode = StateNode<any, any>; | ||
@@ -43,21 +43,21 @@ export interface TransitionMap { | ||
} | ||
export interface StatePlan<TState, TEvent extends EventObject> { | ||
export interface StatePlan<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> { | ||
/** | ||
* The target state. | ||
*/ | ||
state: TState; | ||
state: TSnapshot; | ||
/** | ||
* The paths that reach the target state. | ||
*/ | ||
paths: Array<StatePath<TState, TEvent>>; | ||
paths: Array<StatePath<TSnapshot, TEvent>>; | ||
} | ||
export interface StatePath<TState, TEvent extends EventObject> { | ||
export interface StatePath<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> { | ||
/** | ||
* The ending state of the path. | ||
*/ | ||
state: TState; | ||
state: TSnapshot; | ||
/** | ||
* The ordered array of state-event pairs (steps) which reach the ending `state`. | ||
*/ | ||
steps: Steps<TState, TEvent>; | ||
steps: Steps<TSnapshot, TEvent>; | ||
/** | ||
@@ -68,6 +68,6 @@ * The combined weight of all steps in the path. | ||
} | ||
export interface StatePlanMap<TState, TEvent extends EventObject> { | ||
[key: string]: StatePlan<TState, TEvent>; | ||
export interface StatePlanMap<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> { | ||
[key: string]: StatePlan<TSnapshot, TEvent>; | ||
} | ||
export interface Step<TState, TEvent extends EventObject> { | ||
export interface Step<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> { | ||
/** | ||
@@ -80,5 +80,5 @@ * The event that resulted in the current state | ||
*/ | ||
state: TState; | ||
state: TSnapshot; | ||
} | ||
export type Steps<TState, TEvent extends EventObject> = Array<Step<TState, TEvent>>; | ||
export type Steps<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> = Array<Step<TSnapshot, TEvent>>; | ||
export type ExtractEvent<TEvent extends EventObject, TType extends TEvent['type']> = TEvent extends { | ||
@@ -100,9 +100,9 @@ type: TType; | ||
} | ||
export interface SerializationConfig<TState, TEvent extends EventObject> { | ||
serializeState: (state: TState, event: TEvent | undefined, prevState?: TState) => string; | ||
export interface SerializationConfig<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> { | ||
serializeState: (state: TSnapshot, event: TEvent | undefined, prevState?: TSnapshot) => string; | ||
serializeEvent: (event: TEvent) => string; | ||
} | ||
export type SerializationOptions<TState, TEvent extends EventObject> = Partial<Pick<SerializationConfig<TState, TEvent>, 'serializeState' | 'serializeEvent'>>; | ||
export type TraversalOptions<TState, TEvent extends EventObject> = SerializationOptions<TState, TEvent> & Partial<Pick<TraversalConfig<TState, TEvent>, 'filter' | 'events' | 'traversalLimit' | 'fromState' | 'stopCondition' | 'toState'>>; | ||
export interface TraversalConfig<TState, TEvent extends EventObject> extends SerializationConfig<TState, TEvent> { | ||
export type SerializationOptions<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> = Partial<Pick<SerializationConfig<TSnapshot, TEvent>, 'serializeState' | 'serializeEvent'>>; | ||
export type TraversalOptions<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> = SerializationOptions<TSnapshot, TEvent> & Partial<Pick<TraversalConfig<TSnapshot, TEvent>, 'filter' | 'events' | 'traversalLimit' | 'fromState' | 'stopCondition' | 'toState'>>; | ||
export interface TraversalConfig<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> extends SerializationConfig<TSnapshot, TEvent> { | ||
/** | ||
@@ -112,4 +112,4 @@ * Determines whether to traverse a transition from `state` on | ||
*/ | ||
filter: (state: TState, event: TEvent) => boolean; | ||
events: readonly TEvent[] | ((state: TState) => readonly TEvent[]); | ||
filter: (state: TSnapshot, event: TEvent) => boolean; | ||
events: readonly TEvent[] | ((state: TSnapshot) => readonly TEvent[]); | ||
/** | ||
@@ -122,3 +122,3 @@ * The maximum number of traversals to perform when calculating | ||
traversalLimit: number; | ||
fromState: TState | undefined; | ||
fromState: TSnapshot | undefined; | ||
/** | ||
@@ -128,4 +128,4 @@ * When true, traversal of the adjacency map will stop | ||
*/ | ||
stopCondition: ((state: TState) => boolean) | undefined; | ||
toState: ((state: TState) => boolean) | undefined; | ||
stopCondition: ((state: TSnapshot) => boolean) | undefined; | ||
toState: ((state: TSnapshot) => boolean) | undefined; | ||
} | ||
@@ -132,0 +132,0 @@ type Brand<T, Tag extends string> = T & { |
@@ -7,2 +7,15 @@ 'use strict'; | ||
function createMockActorContext() { | ||
const emptyActor = xstate.createEmptyActor(); | ||
return { | ||
self: emptyActor, | ||
logger: console.log, | ||
id: '', | ||
sessionId: Math.random().toString(32).slice(2), | ||
defer: () => {}, | ||
system: emptyActor, | ||
stopChild: () => {} | ||
}; | ||
} | ||
function flatten(array) { | ||
@@ -70,5 +83,3 @@ return [].concat(...array); | ||
}, | ||
fromState: machine.getInitialState({} // TODO: figure out the simulation API | ||
), | ||
fromState: machine.getInitialState(createMockActorContext()), | ||
...otherOptions | ||
@@ -182,6 +193,6 @@ }; | ||
} = resolveTraversalOptions(logic, options); | ||
const actorContext = { | ||
self: {} | ||
}; // TODO: figure out the simulation API | ||
const fromState = customFromState ?? logic.getInitialState(actorContext, undefined); | ||
const actorContext = createMockActorContext(); | ||
const fromState = customFromState ?? logic.getInitialState(actorContext, | ||
// TODO: fix this | ||
undefined); | ||
const adj = {}; | ||
@@ -268,5 +279,3 @@ let iterations = 0; | ||
const resolvedOptions = resolveTraversalOptions(logic, options); | ||
const actorContext = { | ||
self: {} | ||
}; // TODO: figure out the simulation API | ||
const actorContext = createMockActorContext(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(actorContext, undefined); | ||
@@ -339,5 +348,3 @@ const serializeState = resolvedOptions.serializeState; | ||
const serializeState = resolvedOptions.serializeState; | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState({}, | ||
// TODO: figure out the simulation API | ||
undefined); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(createMockActorContext(), undefined); | ||
const adjacency = getAdjacencyMap(logic, resolvedOptions); | ||
@@ -435,6 +442,6 @@ | ||
}, isMachine(logic) ? createDefaultMachineOptions(logic) : createDefaultLogicOptions()); | ||
const actorContext = { | ||
self: {} | ||
}; // TODO: figure out the simulation API | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(actorContext, undefined); | ||
const actorContext = createMockActorContext(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(actorContext, | ||
// TODO: fix this | ||
undefined); | ||
const { | ||
@@ -441,0 +448,0 @@ serializeState, |
@@ -1,3 +0,16 @@ | ||
import { StateMachine } from 'xstate'; | ||
import { createEmptyActor, StateMachine } from 'xstate'; | ||
function createMockActorContext() { | ||
const emptyActor = createEmptyActor(); | ||
return { | ||
self: emptyActor, | ||
logger: console.log, | ||
id: '', | ||
sessionId: Math.random().toString(32).slice(2), | ||
defer: () => {}, | ||
system: emptyActor, | ||
stopChild: () => {} | ||
}; | ||
} | ||
function flatten(array) { | ||
@@ -65,5 +78,3 @@ return [].concat(...array); | ||
}, | ||
fromState: machine.getInitialState({} // TODO: figure out the simulation API | ||
), | ||
fromState: machine.getInitialState(createMockActorContext()), | ||
...otherOptions | ||
@@ -177,6 +188,6 @@ }; | ||
} = resolveTraversalOptions(logic, options); | ||
const actorContext = { | ||
self: {} | ||
}; // TODO: figure out the simulation API | ||
const fromState = customFromState ?? logic.getInitialState(actorContext, undefined); | ||
const actorContext = createMockActorContext(); | ||
const fromState = customFromState ?? logic.getInitialState(actorContext, | ||
// TODO: fix this | ||
undefined); | ||
const adj = {}; | ||
@@ -263,5 +274,3 @@ let iterations = 0; | ||
const resolvedOptions = resolveTraversalOptions(logic, options); | ||
const actorContext = { | ||
self: {} | ||
}; // TODO: figure out the simulation API | ||
const actorContext = createMockActorContext(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(actorContext, undefined); | ||
@@ -334,5 +343,3 @@ const serializeState = resolvedOptions.serializeState; | ||
const serializeState = resolvedOptions.serializeState; | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState({}, | ||
// TODO: figure out the simulation API | ||
undefined); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(createMockActorContext(), undefined); | ||
const adjacency = getAdjacencyMap(logic, resolvedOptions); | ||
@@ -430,6 +437,6 @@ | ||
}, isMachine(logic) ? createDefaultMachineOptions(logic) : createDefaultLogicOptions()); | ||
const actorContext = { | ||
self: {} | ||
}; // TODO: figure out the simulation API | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(actorContext, undefined); | ||
const actorContext = createMockActorContext(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(actorContext, | ||
// TODO: fix this | ||
undefined); | ||
const { | ||
@@ -436,0 +443,0 @@ serializeState, |
{ | ||
"name": "@xstate/graph", | ||
"version": "2.0.0-beta.4", | ||
"version": "2.0.0-beta.5", | ||
"description": "XState graph utilities", | ||
@@ -43,8 +43,8 @@ "keywords": [ | ||
"peerDependencies": { | ||
"xstate": "^5.0.0-beta.26" | ||
"xstate": "^5.0.0-beta.30" | ||
}, | ||
"devDependencies": { | ||
"xstate": "5.0.0-beta.26" | ||
"xstate": "5.0.0-beta.30" | ||
}, | ||
"dependencies": {} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40898
1139