@ruiapp/rapid-core 0.1.34 → 0.1.36
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.
- package/dist/index.js +6 -3
- package/dist/plugins/stateMachine/StateMachinePluginTypes.d.ts +11 -4
- package/dist/plugins/stateMachine/StateMachineService.d.ts +2 -1
- package/package.json +1 -1
- package/src/dataAccess/entityManager.ts +1 -1
- package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +6 -2
- package/src/plugins/stateMachine/StateMachinePluginTypes.ts +16 -5
- package/src/plugins/stateMachine/StateMachineService.ts +20 -2
package/dist/index.js
CHANGED
|
@@ -2107,7 +2107,7 @@ async function createEntity(server, dataAccessor, options, plugin) {
|
|
|
2107
2107
|
}
|
|
2108
2108
|
}
|
|
2109
2109
|
const newRow = await dataAccessor.create(row);
|
|
2110
|
-
const newEntity = mapDbRowToEntity(model, newRow,
|
|
2110
|
+
const newEntity = mapDbRowToEntity(model, newRow, true);
|
|
2111
2111
|
// save many-relation properties
|
|
2112
2112
|
for (const property of manyRelationPropertiesToCreate) {
|
|
2113
2113
|
newEntity[property.code] = [];
|
|
@@ -3339,8 +3339,12 @@ async function handler$h(plugin, ctx, options) {
|
|
|
3339
3339
|
if (operation) {
|
|
3340
3340
|
delete mergedInput.$operation;
|
|
3341
3341
|
}
|
|
3342
|
+
const stateProperty = mergedInput.$stateProperty;
|
|
3343
|
+
if (stateProperty) {
|
|
3344
|
+
delete mergedInput.$stateProperty;
|
|
3345
|
+
}
|
|
3342
3346
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
3343
|
-
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput, operation }, plugin);
|
|
3347
|
+
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput, operation, stateProperty }, plugin);
|
|
3344
3348
|
ctx.output = output;
|
|
3345
3349
|
}
|
|
3346
3350
|
|
|
@@ -5036,7 +5040,6 @@ class CronJobPlugin {
|
|
|
5036
5040
|
}
|
|
5037
5041
|
|
|
5038
5042
|
async function getStateMachineNextSnapshot(server, options) {
|
|
5039
|
-
debugger;
|
|
5040
5043
|
const { machineConfig, currentState, event } = options;
|
|
5041
5044
|
machineConfig.initial = currentState;
|
|
5042
5045
|
const machine = xstate.createMachine(machineConfig);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MachineConfig } from "xstate";
|
|
1
|
+
import { AnyActorRef, AnyEventObject, EventObject, MachineConfig, MachineContext, MachineSnapshot, MetaObject, StateValue } from "xstate";
|
|
2
2
|
export type PropertyStateMachineConfig = {
|
|
3
3
|
enabled: boolean;
|
|
4
4
|
config: MachineConfig<any, any>;
|
|
@@ -7,18 +7,25 @@ export type PropertyStateMachineConfig = {
|
|
|
7
7
|
export type SendStateMachineEventOptions = {
|
|
8
8
|
code: string;
|
|
9
9
|
};
|
|
10
|
+
export type StateMachineEvent = AnyEventObject;
|
|
10
11
|
export type SendStateMachineEventInput = {
|
|
11
12
|
code?: string;
|
|
12
13
|
context: any;
|
|
13
14
|
currentState: string;
|
|
14
15
|
event: StateMachineEvent;
|
|
15
16
|
};
|
|
16
|
-
export type StateMachineEvent = {
|
|
17
|
-
type: string;
|
|
18
|
-
};
|
|
19
17
|
export type GetStateMachineNextSnapshotOptions = {
|
|
20
18
|
machineConfig: MachineConfig<any, any>;
|
|
21
19
|
context: any;
|
|
22
20
|
currentState: string;
|
|
23
21
|
event: StateMachineEvent;
|
|
24
22
|
};
|
|
23
|
+
export type DefaultStateMachineSnapshot = MachineSnapshot<MachineContext, EventObject, Record<string, AnyActorRef | undefined>, StateValue, string, unknown, MetaObject>;
|
|
24
|
+
export type TryGetStateMachineNextSnapshotResult = TryGetStateMachineNextSnapshotPositiveResult | TryGetStateMachineNextSnapshotNegativeResult;
|
|
25
|
+
export type TryGetStateMachineNextSnapshotPositiveResult = {
|
|
26
|
+
canTransfer: true;
|
|
27
|
+
nextSnapshot: DefaultStateMachineSnapshot;
|
|
28
|
+
};
|
|
29
|
+
export type TryGetStateMachineNextSnapshotNegativeResult = {
|
|
30
|
+
canTransfer: false;
|
|
31
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { IRpdServer } from "../../core/server";
|
|
2
|
-
import { GetStateMachineNextSnapshotOptions } from "./StateMachinePluginTypes";
|
|
2
|
+
import { GetStateMachineNextSnapshotOptions, TryGetStateMachineNextSnapshotResult } from "./StateMachinePluginTypes";
|
|
3
3
|
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>>;
|
|
4
|
+
export declare function tryGetStateMachineNextSnapshot(server: IRpdServer, options: GetStateMachineNextSnapshotOptions): Promise<TryGetStateMachineNextSnapshotResult>;
|
package/package.json
CHANGED
|
@@ -491,7 +491,7 @@ async function createEntity(
|
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
const newRow = await dataAccessor.create(row);
|
|
494
|
-
const newEntity = mapDbRowToEntity(model, newRow,
|
|
494
|
+
const newEntity = mapDbRowToEntity(model, newRow, true);
|
|
495
495
|
|
|
496
496
|
// save many-relation properties
|
|
497
497
|
for (const property of manyRelationPropertiesToCreate) {
|
|
@@ -16,13 +16,17 @@ export async function handler(
|
|
|
16
16
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
17
17
|
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
const operation = mergedInput.$operation;
|
|
21
20
|
if (operation) {
|
|
22
21
|
delete mergedInput.$operation;
|
|
23
22
|
}
|
|
24
23
|
|
|
24
|
+
const stateProperty = mergedInput.$stateProperty;
|
|
25
|
+
if (stateProperty) {
|
|
26
|
+
delete mergedInput.$stateProperty;
|
|
27
|
+
}
|
|
28
|
+
|
|
25
29
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
26
|
-
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput, operation }, plugin);
|
|
30
|
+
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput, operation, stateProperty }, plugin);
|
|
27
31
|
ctx.output = output;
|
|
28
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MachineConfig } from "xstate";
|
|
1
|
+
import { AnyActorRef, AnyEventObject, EventObject, MachineConfig, MachineContext, MachineSnapshot, MetaObject, StateValue } from "xstate";
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
export type PropertyStateMachineConfig = {
|
|
@@ -11,6 +11,8 @@ export type SendStateMachineEventOptions = {
|
|
|
11
11
|
code: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export type StateMachineEvent = AnyEventObject;
|
|
15
|
+
|
|
14
16
|
export type SendStateMachineEventInput = {
|
|
15
17
|
code?: string;
|
|
16
18
|
context: any;
|
|
@@ -18,13 +20,22 @@ export type SendStateMachineEventInput = {
|
|
|
18
20
|
event: StateMachineEvent;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
export type StateMachineEvent = {
|
|
22
|
-
type: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
23
|
export type GetStateMachineNextSnapshotOptions = {
|
|
26
24
|
machineConfig: MachineConfig<any, any>;
|
|
27
25
|
context: any;
|
|
28
26
|
currentState: string;
|
|
29
27
|
event: StateMachineEvent;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type DefaultStateMachineSnapshot = MachineSnapshot<MachineContext, EventObject, Record<string, AnyActorRef | undefined>, StateValue, string, unknown, MetaObject>;
|
|
31
|
+
|
|
32
|
+
export type TryGetStateMachineNextSnapshotResult = TryGetStateMachineNextSnapshotPositiveResult | TryGetStateMachineNextSnapshotNegativeResult;
|
|
33
|
+
|
|
34
|
+
export type TryGetStateMachineNextSnapshotPositiveResult = {
|
|
35
|
+
canTransfer: true;
|
|
36
|
+
nextSnapshot: DefaultStateMachineSnapshot;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type TryGetStateMachineNextSnapshotNegativeResult = {
|
|
40
|
+
canTransfer: false;
|
|
30
41
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { IRpdServer } from "~/core/server";
|
|
2
|
-
import { GetStateMachineNextSnapshotOptions } from "./StateMachinePluginTypes";
|
|
2
|
+
import { DefaultStateMachineSnapshot, GetStateMachineNextSnapshotOptions, TryGetStateMachineNextSnapshotResult } from "./StateMachinePluginTypes";
|
|
3
3
|
import { createMachine, getInitialSnapshot, getNextSnapshot } from "xstate";
|
|
4
4
|
|
|
5
5
|
export async function getStateMachineNextSnapshot(server: IRpdServer, options: GetStateMachineNextSnapshotOptions) {
|
|
6
|
-
debugger
|
|
7
6
|
const { machineConfig, currentState, event } = options;
|
|
8
7
|
machineConfig.initial = currentState;
|
|
9
8
|
|
|
@@ -17,3 +16,22 @@ export async function getStateMachineNextSnapshot(server: IRpdServer, options: G
|
|
|
17
16
|
const nextSnapshot = getNextSnapshot(machine, snapshot, event);
|
|
18
17
|
return nextSnapshot;
|
|
19
18
|
}
|
|
19
|
+
|
|
20
|
+
export async function tryGetStateMachineNextSnapshot(server: IRpdServer, options: GetStateMachineNextSnapshotOptions): Promise<TryGetStateMachineNextSnapshotResult> {
|
|
21
|
+
const { machineConfig, currentState, event } = options;
|
|
22
|
+
machineConfig.initial = currentState;
|
|
23
|
+
|
|
24
|
+
const machine = createMachine(machineConfig);
|
|
25
|
+
const snapshot = getInitialSnapshot(machine);
|
|
26
|
+
|
|
27
|
+
const canTransfer = snapshot.can(event);
|
|
28
|
+
let nextSnapshot: DefaultStateMachineSnapshot;
|
|
29
|
+
if (canTransfer) {
|
|
30
|
+
nextSnapshot = getNextSnapshot(machine, snapshot, event);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
canTransfer,
|
|
35
|
+
nextSnapshot,
|
|
36
|
+
};
|
|
37
|
+
}
|