Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions packages/core/src/Machine.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
import { StateMachine } from './StateMachine.ts';
import { ResolveTypegenMeta, TypegenConstraint } from './typegenTypes.ts';
import {
AnyEventObject,
EventObject,
InternalMachineImplementations,
MachineConfig,
MachineContext,
InternalMachineImplementations,
ParameterizedObject,
ProvidedActor,
MachineTypes,
NonReducibleUnknown,
ParameterizedObject,
Prop,
AnyEventObject
ProvidedActor
} from './types.ts';
import { TypegenConstraint, ResolveTypegenMeta } from './typegenTypes.ts';
import { StateMachine } from './StateMachine.ts';

interface InferenceSource<
TContext extends MachineContext,
TEvent extends EventObject,
TActor extends ProvidedActor,
TAction extends ParameterizedObject,
TGuard extends ParameterizedObject,
TDelay extends string,
TTag extends string,
TInput,
TOutput extends NonReducibleUnknown,
TTypesMeta extends TypegenConstraint
> {
types?: MachineTypes<
TContext,
TEvent,
TActor,
TAction,
TGuard,
TDelay,
TTag,
TInput,
TOutput,
TTypesMeta
>;
}

export function createMachine<
TContext extends MachineContext,
Expand All @@ -21,9 +49,22 @@ export function createMachine<
TTag extends string,
TInput,
TOutput extends NonReducibleUnknown,
TTypesMeta extends TypegenConstraint
TTypesMeta extends TypegenConstraint,
TConfig extends MachineConfig<
TContext,
TEvent,
TActor,
TAction,
TGuard,
TDelay,
TTag,
TInput,
TOutput,
TStringLiteral
>,
TStringLiteral extends string
>(
config: MachineConfig<
config: InferenceSource<
TContext,
TEvent,
TActor,
Expand All @@ -34,7 +75,8 @@ export function createMachine<
TInput,
TOutput,
TTypesMeta
>,
> &
TConfig,
implementations?: InternalMachineImplementations<
TContext,
TEvent,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/StateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class StateMachine<
any,
any,
TOutput,
any
string
>,
implementations?: MachineImplementationsSimplified<TContext, TEvent>
) {
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/StateNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ export class StateNode<
TODO, // output
TODO, // guards
TODO, // delays
TODO // tags
TODO, // tags
string // TStringLiteral
>,
options: StateNodeOptions<TContext, TEvent>
) {
Expand Down Expand Up @@ -293,6 +294,7 @@ export class StateNode<
ProvidedActor,
ParameterizedObject,
ParameterizedObject,
string,
string
>
> {
Expand Down Expand Up @@ -337,6 +339,7 @@ export class StateNode<
ProvidedActor,
ParameterizedObject,
ParameterizedObject,
string,
string
>;
})
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/actions/pure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export function pure<
TActor extends ProvidedActor = ProvidedActor,
TAction extends ParameterizedObject = ParameterizedObject,
TGuard extends ParameterizedObject = ParameterizedObject,
TDelay extends string = string
TDelay extends string = string,
TStringLiteral extends string = string
>(
getActions: ({
context,
Expand All @@ -82,7 +83,8 @@ export function pure<
TActor,
NoInfer<TAction>,
NoInfer<TGuard>,
TDelay
TDelay,
TStringLiteral
>
| undefined
): PureAction<
Expand Down
25 changes: 18 additions & 7 deletions packages/core/src/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ export type Guard<
TContext extends MachineContext,
TExpressionEvent extends EventObject,
TExpressionGuard extends ParameterizedObject | undefined,
TGuard extends ParameterizedObject
TGuard extends ParameterizedObject,
TStringLiteral extends string
> =
| NoRequiredParams<TGuard>
| WithDynamicParams<TContext, TExpressionEvent, TGuard>
| WithDynamicParams<TContext, TExpressionEvent, TGuard, TStringLiteral>
| GuardPredicate<TContext, TExpressionEvent, TExpressionGuard, TGuard>;

export type UnknownGuard = UnknownReferencedGuard | UnknownInlineGuard;
Expand All @@ -47,14 +48,16 @@ type UnknownReferencedGuard = Guard<
MachineContext,
EventObject,
ParameterizedObject,
ParameterizedObject
ParameterizedObject,
string
>;

type UnknownInlineGuard = Guard<
MachineContext,
EventObject,
undefined,
ParameterizedObject
ParameterizedObject,
string
>;

interface BuiltinGuard {
Expand Down Expand Up @@ -114,7 +117,15 @@ export function not<
TExpressionEvent extends EventObject,
TExpressionGuard extends ParameterizedObject | undefined,
TGuard extends ParameterizedObject
>(guard: Guard<TContext, TExpressionEvent, TExpressionGuard, NoInfer<TGuard>>) {
>(
guard: Guard<
TContext,
TExpressionEvent,
TExpressionGuard,
NoInfer<TGuard>,
string
>
) {
function not(_: GuardArgs<TContext, TExpressionEvent, TExpressionGuard>) {
if (isDevelopment) {
throw new Error(`This isn't supposed to be called`);
Expand Down Expand Up @@ -148,7 +159,7 @@ export function and<
TGuard extends ParameterizedObject
>(
guards: ReadonlyArray<
Guard<TContext, TExpressionEvent, TExpressionGuard, NoInfer<TGuard>>
Guard<TContext, TExpressionEvent, TExpressionGuard, NoInfer<TGuard>, string>
>
) {
function and(_: GuardArgs<TContext, TExpressionEvent, TExpressionGuard>) {
Expand Down Expand Up @@ -184,7 +195,7 @@ export function or<
TGuard extends ParameterizedObject
>(
guards: ReadonlyArray<
Guard<TContext, TExpressionEvent, TExpressionGuard, NoInfer<TGuard>>
Guard<TContext, TExpressionEvent, TExpressionGuard, NoInfer<TGuard>, string>
>
) {
function or(_: GuardArgs<TContext, TExpressionEvent, TExpressionGuard>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/stateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export function formatInitialTransition<
stateNode: AnyStateNode,
_target:
| SingleOrArray<string>
| InitialTransitionConfig<TContext, TEvent, TODO, TODO, TODO, TODO>
| InitialTransitionConfig<TContext, TEvent, TODO, TODO, TODO, TODO, string>
): InitialTransitionDefinition<TContext, TEvent> {
if (typeof _target === 'string' || isArray(_target)) {
const targets = toArray(_target).map((t) => {
Expand Down
Loading