@ruiapp/rapid-core
Advanced tools
Comparing version 0.1.35 to 0.1.36
@@ -1,2 +0,2 @@ | ||
import { MachineConfig } from "xstate"; | ||
import { AnyActorRef, AnyEventObject, EventObject, MachineConfig, MachineContext, MachineSnapshot, MetaObject, StateValue } from "xstate"; | ||
export type PropertyStateMachineConfig = { | ||
@@ -10,2 +10,3 @@ enabled: boolean; | ||
}; | ||
export type StateMachineEvent = AnyEventObject; | ||
export type SendStateMachineEventInput = { | ||
@@ -17,5 +18,2 @@ code?: string; | ||
}; | ||
export type StateMachineEvent = { | ||
type: string; | ||
}; | ||
export type GetStateMachineNextSnapshotOptions = { | ||
@@ -27,1 +25,10 @@ machineConfig: MachineConfig<any, any>; | ||
}; | ||
export type DefaultStateMachineSnapshot = MachineSnapshot<MachineContext, EventObject, Record<string, AnyActorRef | undefined>, StateValue, string, unknown, MetaObject>; | ||
export type TryGetStateMachineNextSnapshotResult = TryGetStateMachineNextSnapshotPositiveResult | TryGetStateMachineNextSnapshotNegativeResult; | ||
export type TryGetStateMachineNextSnapshotPositiveResult = { | ||
canTransfer: true; | ||
nextSnapshot: DefaultStateMachineSnapshot; | ||
}; | ||
export type TryGetStateMachineNextSnapshotNegativeResult = { | ||
canTransfer: false; | ||
}; |
import { IRpdServer } from "../../core/server"; | ||
import { GetStateMachineNextSnapshotOptions } from "./StateMachinePluginTypes"; | ||
import { GetStateMachineNextSnapshotOptions, TryGetStateMachineNextSnapshotResult } from "./StateMachinePluginTypes"; | ||
export declare function getStateMachineNextSnapshot(server: IRpdServer, options: GetStateMachineNextSnapshotOptions): Promise<import("xstate").MachineSnapshot<any, import("xstate").AnyEventObject, Record<string, import("xstate").AnyActorRef>, import("xstate").StateValue, string, unknown, import("xstate").MetaObject, never>>; | ||
export declare function tryGetStateMachineNextSnapshot(server: IRpdServer, options: GetStateMachineNextSnapshotOptions): Promise<TryGetStateMachineNextSnapshotResult>; |
{ | ||
"name": "@ruiapp/rapid-core", | ||
"version": "0.1.35", | ||
"version": "0.1.36", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -19,3 +19,2 @@ import { RunEntityActionHandlerOptions } from "~/types"; | ||
const operation = mergedInput.$operation; | ||
@@ -26,5 +25,10 @@ if (operation) { | ||
const stateProperty = mergedInput.$stateProperty; | ||
if (stateProperty) { | ||
delete mergedInput.$stateProperty; | ||
} | ||
const entityManager = server.getEntityManager(options.singularCode); | ||
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput, operation }, plugin); | ||
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput, operation, stateProperty }, plugin); | ||
ctx.output = output; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { MachineConfig } from "xstate"; | ||
import { AnyActorRef, AnyEventObject, EventObject, MachineConfig, MachineContext, MachineSnapshot, MetaObject, StateValue } from "xstate"; | ||
@@ -14,2 +14,4 @@ | ||
export type StateMachineEvent = AnyEventObject; | ||
export type SendStateMachineEventInput = { | ||
@@ -22,6 +24,2 @@ code?: string; | ||
export type StateMachineEvent = { | ||
type: string; | ||
} | ||
export type GetStateMachineNextSnapshotOptions = { | ||
@@ -32,2 +30,15 @@ machineConfig: MachineConfig<any, any>; | ||
event: StateMachineEvent; | ||
} | ||
export type DefaultStateMachineSnapshot = MachineSnapshot<MachineContext, EventObject, Record<string, AnyActorRef | undefined>, StateValue, string, unknown, MetaObject>; | ||
export type TryGetStateMachineNextSnapshotResult = TryGetStateMachineNextSnapshotPositiveResult | TryGetStateMachineNextSnapshotNegativeResult; | ||
export type TryGetStateMachineNextSnapshotPositiveResult = { | ||
canTransfer: true; | ||
nextSnapshot: DefaultStateMachineSnapshot; | ||
} | ||
export type TryGetStateMachineNextSnapshotNegativeResult = { | ||
canTransfer: false; | ||
} |
import { IRpdServer } from "~/core/server"; | ||
import { GetStateMachineNextSnapshotOptions } from "./StateMachinePluginTypes"; | ||
import { DefaultStateMachineSnapshot, GetStateMachineNextSnapshotOptions, TryGetStateMachineNextSnapshotResult } from "./StateMachinePluginTypes"; | ||
import { createMachine, getInitialSnapshot, getNextSnapshot } from "xstate"; | ||
export async function getStateMachineNextSnapshot(server: IRpdServer, options: GetStateMachineNextSnapshotOptions) { | ||
debugger | ||
const { machineConfig, currentState, event } = options; | ||
@@ -20,1 +19,20 @@ machineConfig.initial = currentState; | ||
} | ||
export async function tryGetStateMachineNextSnapshot(server: IRpdServer, options: GetStateMachineNextSnapshotOptions): Promise<TryGetStateMachineNextSnapshotResult> { | ||
const { machineConfig, currentState, event } = options; | ||
machineConfig.initial = currentState; | ||
const machine = createMachine(machineConfig); | ||
const snapshot = getInitialSnapshot(machine); | ||
const canTransfer = snapshot.can(event); | ||
let nextSnapshot: DefaultStateMachineSnapshot; | ||
if (canTransfer) { | ||
nextSnapshot = getNextSnapshot(machine, snapshot, event); | ||
} | ||
return { | ||
canTransfer, | ||
nextSnapshot, | ||
}; | ||
} |
Sorry, the diff of this file is too big to display
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
530370
14787