@ruiapp/rapid-core 0.1.41 → 0.1.43
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/dataAccess/dataAccessTypes.d.ts +63 -0
- package/dist/dataAccess/dataAccessor.d.ts +5 -4
- package/dist/dataAccess/entityMapper.d.ts +7 -2
- package/dist/dataAccess/metaHelper.d.ts +6 -0
- package/dist/index.js +576 -324
- package/dist/plugins/sequence/SequencePluginTypes.d.ts +1 -0
- package/dist/queryBuilder/queryBuilder.d.ts +12 -22
- package/dist/types.d.ts +34 -5
- package/dist/utilities/errorUtility.d.ts +3 -0
- package/package.json +1 -1
- package/rollup.config.js +13 -17
- package/src/bootstrapApplicationConfig.ts +25 -4
- package/src/core/actionHandler.ts +2 -5
- package/src/core/eventManager.ts +1 -4
- package/src/core/facility.ts +1 -1
- package/src/core/http/formDataParser.ts +31 -43
- package/src/core/pluginManager.ts +13 -39
- package/src/core/providers/runtimeProvider.ts +1 -1
- package/src/core/request.ts +3 -3
- package/src/core/response.ts +2 -7
- package/src/core/routeContext.ts +2 -6
- package/src/core/routesBuilder.ts +46 -55
- package/src/core/server.ts +8 -34
- package/src/dataAccess/dataAccessTypes.ts +86 -0
- package/src/dataAccess/dataAccessor.ts +46 -24
- package/src/dataAccess/entityManager.ts +294 -245
- package/src/dataAccess/entityMapper.ts +32 -15
- package/src/dataAccess/filterHelper.ts +1 -3
- package/src/dataAccess/metaHelper.ts +45 -0
- package/src/dataAccess/propertyMapper.ts +3 -3
- package/src/deno-std/datetime/to_imf.ts +2 -17
- package/src/deno-std/encoding/base64.ts +1 -5
- package/src/deno-std/http/cookie.ts +26 -59
- package/src/facilities/log/LogFacility.ts +0 -1
- package/src/helpers/entityHelpers.ts +1 -4
- package/src/helpers/runCollectionEntityActionHandler.ts +2 -10
- package/src/plugins/auth/AuthPlugin.ts +2 -5
- package/src/plugins/auth/actionHandlers/changePassword.ts +6 -10
- package/src/plugins/auth/actionHandlers/createSession.ts +14 -15
- package/src/plugins/auth/actionHandlers/deleteSession.ts +1 -5
- package/src/plugins/auth/actionHandlers/getMyProfile.ts +5 -9
- package/src/plugins/auth/actionHandlers/index.ts +1 -7
- package/src/plugins/auth/actionHandlers/resetPassword.ts +3 -7
- package/src/plugins/auth/models/AccessToken.ts +2 -2
- package/src/plugins/auth/models/index.ts +1 -3
- package/src/plugins/auth/routes/changePassword.ts +1 -1
- package/src/plugins/auth/routes/getMyProfile.ts +1 -1
- package/src/plugins/auth/routes/index.ts +1 -7
- package/src/plugins/auth/routes/resetPassword.ts +1 -1
- package/src/plugins/auth/routes/signin.ts +1 -1
- package/src/plugins/auth/routes/signout.ts +1 -1
- package/src/plugins/cronJob/CronJobPlugin.ts +12 -21
- package/src/plugins/cronJob/CronJobPluginTypes.ts +9 -9
- package/src/plugins/cronJob/actionHandlers/index.ts +1 -3
- package/src/plugins/cronJob/actionHandlers/runCronJob.ts +3 -8
- package/src/plugins/cronJob/routes/index.ts +1 -3
- package/src/plugins/cronJob/routes/runCronJob.ts +1 -1
- package/src/plugins/dataManage/DataManagePlugin.ts +5 -11
- package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +1 -5
- package/src/plugins/dataManage/actionHandlers/countCollectionEntities.ts +5 -14
- package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +8 -9
- package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +7 -8
- package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +1 -5
- package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +15 -24
- package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +1 -5
- package/src/plugins/dataManage/actionHandlers/queryDatabase.ts +1 -5
- package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +1 -5
- package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +1 -5
- package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +5 -6
- package/src/plugins/entityWatch/EntityWatchPlugin.ts +18 -17
- package/src/plugins/entityWatch/EntityWatchPluginTypes.ts +3 -10
- package/src/plugins/fileManage/FileManagePlugin.ts +1 -3
- package/src/plugins/fileManage/actionHandlers/downloadDocument.ts +2 -6
- package/src/plugins/fileManage/actionHandlers/downloadFile.ts +2 -6
- package/src/plugins/fileManage/actionHandlers/uploadFile.ts +3 -7
- package/src/plugins/fileManage/routes/downloadDocument.ts +1 -1
- package/src/plugins/fileManage/routes/downloadFile.ts +1 -1
- package/src/plugins/fileManage/routes/index.ts +1 -5
- package/src/plugins/fileManage/routes/uploadFile.ts +1 -1
- package/src/plugins/metaManage/MetaManagePlugin.ts +45 -92
- package/src/plugins/metaManage/actionHandlers/getMetaModelDetail.ts +1 -5
- package/src/plugins/metaManage/actionHandlers/listMetaModels.ts +1 -5
- package/src/plugins/metaManage/actionHandlers/listMetaRoutes.ts +1 -5
- package/src/plugins/routeManage/RouteManagePlugin.ts +2 -7
- package/src/plugins/routeManage/actionHandlers/httpProxy.ts +1 -5
- package/src/plugins/sequence/SequencePlugin.ts +14 -16
- package/src/plugins/sequence/SequencePluginTypes.ts +20 -29
- package/src/plugins/sequence/SequenceService.ts +16 -15
- package/src/plugins/sequence/actionHandlers/generateSn.ts +2 -7
- package/src/plugins/sequence/actionHandlers/index.ts +1 -3
- package/src/plugins/sequence/models/SequenceAutoIncrementRecord.ts +2 -2
- package/src/plugins/sequence/models/SequenceRule.ts +2 -2
- package/src/plugins/sequence/models/index.ts +1 -4
- package/src/plugins/sequence/routes/generateSn.ts +1 -1
- package/src/plugins/sequence/routes/index.ts +1 -3
- package/src/plugins/sequence/segment-utility.ts +1 -1
- package/src/plugins/sequence/segments/autoIncrement.ts +4 -8
- package/src/plugins/sequence/segments/dayOfMonth.ts +3 -7
- package/src/plugins/sequence/segments/index.ts +1 -8
- package/src/plugins/sequence/segments/literal.ts +1 -1
- package/src/plugins/sequence/segments/month.ts +3 -7
- package/src/plugins/sequence/segments/parameter.ts +3 -7
- package/src/plugins/sequence/segments/year.ts +3 -7
- package/src/plugins/serverOperation/ServerOperationPlugin.ts +12 -22
- package/src/plugins/serverOperation/ServerOperationPluginTypes.ts +1 -1
- package/src/plugins/serverOperation/actionHandlers/index.ts +1 -3
- package/src/plugins/stateMachine/StateMachinePlugin.ts +19 -22
- package/src/plugins/stateMachine/StateMachinePluginTypes.ts +6 -7
- package/src/plugins/stateMachine/actionHandlers/index.ts +1 -3
- package/src/plugins/stateMachine/actionHandlers/sendStateMachineEvent.ts +3 -7
- package/src/plugins/stateMachine/models/StateMachine.ts +2 -2
- package/src/plugins/stateMachine/models/index.ts +1 -3
- package/src/plugins/stateMachine/routes/index.ts +1 -3
- package/src/plugins/stateMachine/routes/sendStateMachineEvent.ts +1 -1
- package/src/plugins/webhooks/WebhooksPlugin.ts +9 -41
- package/src/polyfill.ts +1 -1
- package/src/proxy/mod.ts +4 -13
- package/src/queryBuilder/queryBuilder.ts +149 -106
- package/src/server.ts +19 -44
- package/src/types.ts +54 -79
- package/src/utilities/accessControlUtility.ts +4 -4
- package/src/utilities/errorUtility.ts +17 -0
- package/src/utilities/fsUtility.ts +12 -13
- package/src/utilities/httpUtility.ts +1 -5
- package/src/utilities/jwtUtility.ts +6 -10
- package/tsconfig.json +1 -1
|
@@ -45,7 +45,7 @@ export async function resolveSegmentValue(server: IRpdServer, ruleCode: string,
|
|
|
45
45
|
if (now.year() !== lastUpdate.year() || now.month() !== lastUpdate.month()) {
|
|
46
46
|
shouldReset = true;
|
|
47
47
|
}
|
|
48
|
-
} else
|
|
48
|
+
} else if (period === "day") {
|
|
49
49
|
if (now.year() !== lastUpdate.year() || now.month() !== lastUpdate.month() || now.date() !== lastUpdate.date()) {
|
|
50
50
|
shouldReset = true;
|
|
51
51
|
}
|
|
@@ -64,14 +64,10 @@ export async function resolveSegmentValue(server: IRpdServer, ruleCode: string,
|
|
|
64
64
|
scope: scope,
|
|
65
65
|
current_value: nextValue,
|
|
66
66
|
updated_at: nowString,
|
|
67
|
-
})
|
|
67
|
+
});
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
const segmentValue = nextValue.toString();
|
|
71
71
|
|
|
72
|
-
return padSegment(
|
|
73
|
-
|
|
74
|
-
config.length,
|
|
75
|
-
config.padding || "0",
|
|
76
|
-
);
|
|
77
|
-
}
|
|
72
|
+
return padSegment(segmentValue, config.length, config.padding || "0");
|
|
73
|
+
}
|
|
@@ -6,11 +6,7 @@ import { IRpdServer } from "~/core/server";
|
|
|
6
6
|
export const segmentType = "dayOfMonth";
|
|
7
7
|
|
|
8
8
|
export async function resolveSegmentValue(server: IRpdServer, ruleCode: string, config: SequenceDayOfMonthSegmentConfig, input: GenerateSequenceNumbersInput): Promise<string> {
|
|
9
|
-
const segmentValue =
|
|
9
|
+
const segmentValue = new Date().getDate().toString();
|
|
10
10
|
|
|
11
|
-
return padSegment(
|
|
12
|
-
|
|
13
|
-
config.length || 2,
|
|
14
|
-
config.padding || "0",
|
|
15
|
-
);
|
|
16
|
-
}
|
|
11
|
+
return padSegment(segmentValue, config.length || 2, config.padding || "0");
|
|
12
|
+
}
|
|
@@ -6,11 +6,4 @@ import * as dayOfMonth from "./dayOfMonth";
|
|
|
6
6
|
import * as parameter from "./parameter";
|
|
7
7
|
import * as autoIncrement from "./autoIncrement";
|
|
8
8
|
|
|
9
|
-
export default [
|
|
10
|
-
literal,
|
|
11
|
-
year,
|
|
12
|
-
month,
|
|
13
|
-
dayOfMonth,
|
|
14
|
-
parameter,
|
|
15
|
-
autoIncrement,
|
|
16
|
-
] satisfies SegmentResolver[];
|
|
9
|
+
export default [literal, year, month, dayOfMonth, parameter, autoIncrement] satisfies SegmentResolver[];
|
|
@@ -6,11 +6,7 @@ import { IRpdServer } from "~/core/server";
|
|
|
6
6
|
export const segmentType = "month";
|
|
7
7
|
|
|
8
8
|
export async function resolveSegmentValue(server: IRpdServer, ruleCode: string, config: SequenceMonthSegmentConfig, input: GenerateSequenceNumbersInput): Promise<string> {
|
|
9
|
-
const segmentValue = (
|
|
9
|
+
const segmentValue = (new Date().getMonth() + 1).toString();
|
|
10
10
|
|
|
11
|
-
return padSegment(
|
|
12
|
-
|
|
13
|
-
config.length || 2,
|
|
14
|
-
config.padding || "0",
|
|
15
|
-
);
|
|
16
|
-
}
|
|
11
|
+
return padSegment(segmentValue, config.length || 2, config.padding || "0");
|
|
12
|
+
}
|
|
@@ -7,11 +7,7 @@ import { IRpdServer } from "~/core/server";
|
|
|
7
7
|
export const segmentType = "parameter";
|
|
8
8
|
|
|
9
9
|
export async function resolveSegmentValue(server: IRpdServer, ruleCode: string, config: SequenceParameterSegmentConfig, input: GenerateSequenceNumbersInput): Promise<string> {
|
|
10
|
-
const segmentValue = get(input.parameters, config.parameterName, "");
|
|
10
|
+
const segmentValue = get(input.parameters, config.parameterName, config.defaultContent || "");
|
|
11
11
|
|
|
12
|
-
return padSegment(
|
|
13
|
-
|
|
14
|
-
config.length,
|
|
15
|
-
config.padding,
|
|
16
|
-
);
|
|
17
|
-
}
|
|
12
|
+
return padSegment(segmentValue, config.length, config.padding);
|
|
13
|
+
}
|
|
@@ -6,11 +6,7 @@ import { IRpdServer } from "~/core/server";
|
|
|
6
6
|
export const segmentType = "year";
|
|
7
7
|
|
|
8
8
|
export async function resolveSegmentValue(server: IRpdServer, ruleCode: string, config: SequenceYearSegmentConfig, input: GenerateSequenceNumbersInput): Promise<string> {
|
|
9
|
-
const segmentValue =
|
|
9
|
+
const segmentValue = new Date().getFullYear().toString();
|
|
10
10
|
|
|
11
|
-
return padSegment(
|
|
12
|
-
|
|
13
|
-
config.length || 4,
|
|
14
|
-
config.padding || "0",
|
|
15
|
-
);
|
|
16
|
-
}
|
|
11
|
+
return padSegment(segmentValue, config.length || 4, config.padding || "0");
|
|
12
|
+
}
|
|
@@ -31,11 +31,9 @@ class ServerOperationPlugin implements RapidPlugin {
|
|
|
31
31
|
return [];
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
async initPlugin(server: IRpdServer): Promise<any> {
|
|
35
|
-
}
|
|
34
|
+
async initPlugin(server: IRpdServer): Promise<any> {}
|
|
36
35
|
|
|
37
|
-
async registerMiddlewares(server: IRpdServer): Promise<any> {
|
|
38
|
-
}
|
|
36
|
+
async registerMiddlewares(server: IRpdServer): Promise<any> {}
|
|
39
37
|
|
|
40
38
|
async registerActionHandlers(server: IRpdServer): Promise<any> {
|
|
41
39
|
for (const actionHandler of pluginActionHandlers) {
|
|
@@ -43,23 +41,17 @@ class ServerOperationPlugin implements RapidPlugin {
|
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
47
|
-
}
|
|
44
|
+
async registerEventHandlers(server: IRpdServer): Promise<any> {}
|
|
48
45
|
|
|
49
|
-
async registerMessageHandlers(server: IRpdServer): Promise<any> {
|
|
50
|
-
}
|
|
46
|
+
async registerMessageHandlers(server: IRpdServer): Promise<any> {}
|
|
51
47
|
|
|
52
|
-
async registerTaskProcessors(server: IRpdServer): Promise<any> {
|
|
53
|
-
}
|
|
48
|
+
async registerTaskProcessors(server: IRpdServer): Promise<any> {}
|
|
54
49
|
|
|
55
|
-
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
56
|
-
}
|
|
50
|
+
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
57
51
|
|
|
58
|
-
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
59
|
-
}
|
|
52
|
+
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
60
53
|
|
|
61
|
-
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
62
|
-
}
|
|
54
|
+
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
63
55
|
|
|
64
56
|
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
65
57
|
const routes: RpdRoute[] = [];
|
|
@@ -76,19 +68,17 @@ class ServerOperationPlugin implements RapidPlugin {
|
|
|
76
68
|
code: "runServerOperation",
|
|
77
69
|
config: {
|
|
78
70
|
operation: operation.handler,
|
|
79
|
-
}
|
|
71
|
+
},
|
|
80
72
|
},
|
|
81
73
|
],
|
|
82
|
-
})
|
|
74
|
+
});
|
|
83
75
|
}
|
|
84
76
|
server.appendApplicationConfig({ routes });
|
|
85
77
|
}
|
|
86
78
|
|
|
87
|
-
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
88
|
-
}
|
|
79
|
+
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
89
80
|
|
|
90
|
-
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
91
|
-
}
|
|
81
|
+
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
92
82
|
}
|
|
93
83
|
|
|
94
84
|
export default ServerOperationPlugin;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { IPluginActionHandler } from "~/core/actionHandler";
|
|
2
2
|
import * as runServerOperation from "./runServerOperation";
|
|
3
3
|
|
|
4
|
-
export default [
|
|
5
|
-
runServerOperation,
|
|
6
|
-
] satisfies IPluginActionHandler[];
|
|
4
|
+
export default [runServerOperation] satisfies IPluginActionHandler[];
|
|
@@ -2,13 +2,7 @@
|
|
|
2
2
|
* State machine plugin
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
CreateEntityOptions,
|
|
7
|
-
RpdApplicationConfig,
|
|
8
|
-
RpdDataModel,
|
|
9
|
-
RpdDataModelProperty,
|
|
10
|
-
UpdateEntityByIdOptions,
|
|
11
|
-
} from "~/types";
|
|
5
|
+
import { CreateEntityOptions, RpdApplicationConfig, RpdDataModel, RpdDataModelProperty, UpdateEntityByIdOptions } from "~/types";
|
|
12
6
|
import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
|
|
13
7
|
|
|
14
8
|
import pluginActionHandlers from "./actionHandlers";
|
|
@@ -18,7 +12,7 @@ import { filter, find, first, get, isEqual } from "lodash";
|
|
|
18
12
|
import { PropertyStateMachineConfig } from "./StateMachinePluginTypes";
|
|
19
13
|
import { isNullOrUndefined } from "~/utilities/typeUtility";
|
|
20
14
|
import { getStateMachineNextSnapshot } from "./stateMachineHelper";
|
|
21
|
-
|
|
15
|
+
import { getEntityPropertiesIncludingBase } from "~/dataAccess/metaHelper";
|
|
22
16
|
|
|
23
17
|
class StateMachinePlugin implements RapidPlugin {
|
|
24
18
|
get code(): string {
|
|
@@ -58,7 +52,7 @@ class StateMachinePlugin implements RapidPlugin {
|
|
|
58
52
|
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig) {
|
|
59
53
|
const models = server.getApplicationConfig().models;
|
|
60
54
|
for (const model of models) {
|
|
61
|
-
for (const property of model
|
|
55
|
+
for (const property of getEntityPropertiesIncludingBase(server, model)) {
|
|
62
56
|
const propertyStateMachineConfig: PropertyStateMachineConfig = property.config?.stateMachine;
|
|
63
57
|
if (propertyStateMachineConfig) {
|
|
64
58
|
const stateMachineCode = getStateMachineCode(model, property);
|
|
@@ -97,15 +91,14 @@ class StateMachinePlugin implements RapidPlugin {
|
|
|
97
91
|
/**
|
|
98
92
|
* 创建实体前的处理。
|
|
99
93
|
* 当属性启用了状态机管理,如创建实体时没有指定该属性的状态值,则应将该属性设置为 stateMachine.config.initial 。
|
|
100
|
-
* @param server
|
|
101
|
-
* @param model
|
|
102
|
-
* @param options
|
|
94
|
+
* @param server
|
|
95
|
+
* @param model
|
|
96
|
+
* @param options
|
|
103
97
|
*/
|
|
104
98
|
async beforeCreateEntity(server: IRpdServer, model: RpdDataModel, options: CreateEntityOptions) {
|
|
105
|
-
for (const property of model
|
|
99
|
+
for (const property of getEntityPropertiesIncludingBase(server, model)) {
|
|
106
100
|
const isStateMachineEnabled = get(property.config, "stateMachine.enabled", false);
|
|
107
|
-
if (isStateMachineEnabled && isNullOrUndefined(options.entity[property.code])
|
|
108
|
-
) {
|
|
101
|
+
if (isStateMachineEnabled && isNullOrUndefined(options.entity[property.code])) {
|
|
109
102
|
const initialState = get(property.config, "stateMachine.config.initial", null);
|
|
110
103
|
if (initialState) {
|
|
111
104
|
options.entity[property.code] = initialState;
|
|
@@ -120,15 +113,15 @@ class StateMachinePlugin implements RapidPlugin {
|
|
|
120
113
|
* 2. 当更新实体时指定了operation,则查找启用了状态机管理的属性。
|
|
121
114
|
* 如果一个模型中存在多个属性启用了状态机管理,则以 options.stateProperty 中指定的为准。
|
|
122
115
|
* 对于该状态属性应用 options.operation,使其转换到下一状态。
|
|
123
|
-
* @param server
|
|
124
|
-
* @param model
|
|
125
|
-
* @param options
|
|
116
|
+
* @param server
|
|
117
|
+
* @param model
|
|
118
|
+
* @param options
|
|
126
119
|
*/
|
|
127
120
|
async beforeUpdateEntity(server: IRpdServer, model: RpdDataModel, options: UpdateEntityByIdOptions, currentEntity: any) {
|
|
128
121
|
const entity = options.entityToSave;
|
|
129
122
|
|
|
130
123
|
const stateMachineEnabledProperties: RpdDataModelProperty[] = [];
|
|
131
|
-
for (const property of model
|
|
124
|
+
for (const property of getEntityPropertiesIncludingBase(server, model)) {
|
|
132
125
|
const isStateMachineEnabled = get(property.config, "stateMachine.enabled", false);
|
|
133
126
|
|
|
134
127
|
if (isStateMachineEnabled) {
|
|
@@ -163,21 +156,25 @@ class StateMachinePlugin implements RapidPlugin {
|
|
|
163
156
|
throw new Error(`State machine of property '${statePropertyToUpdate.code}' not configured.`);
|
|
164
157
|
}
|
|
165
158
|
machineConfig.id = getStateMachineCode(model, statePropertyToUpdate);
|
|
166
|
-
|
|
159
|
+
|
|
167
160
|
const nextSnapshot = await getStateMachineNextSnapshot({
|
|
168
161
|
machineConfig,
|
|
169
162
|
context: {},
|
|
170
163
|
currentState: currentEntity[statePropertyToUpdate.code],
|
|
171
164
|
event: options.operation,
|
|
172
165
|
});
|
|
173
|
-
|
|
166
|
+
|
|
174
167
|
entity[statePropertyToUpdate.code] = nextSnapshot.value;
|
|
175
168
|
}
|
|
176
169
|
}
|
|
177
170
|
}
|
|
178
171
|
|
|
179
172
|
function getStateMachineCode(model: RpdDataModel, property: RpdDataModelProperty) {
|
|
180
|
-
|
|
173
|
+
if (property.isBaseProperty) {
|
|
174
|
+
return `propertyStateMachine.${model.namespace}.${model.base}.${property.code}`;
|
|
175
|
+
} else {
|
|
176
|
+
return `propertyStateMachine.${model.namespace}.${model.singularCode}.${property.code}`;
|
|
177
|
+
}
|
|
181
178
|
}
|
|
182
179
|
|
|
183
180
|
export default StateMachinePlugin;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { AnyActorRef, AnyEventObject, EventObject, MachineConfig, MachineContext, MachineSnapshot, MetaObject, StateValue } from "xstate";
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
export type PropertyStateMachineConfig = {
|
|
5
4
|
enabled: boolean;
|
|
6
5
|
config: MachineConfig<any, any>;
|
|
7
6
|
transferControl?: boolean;
|
|
8
|
-
}
|
|
7
|
+
};
|
|
9
8
|
|
|
10
9
|
export type SendStateMachineEventOptions = {
|
|
11
10
|
code: string;
|
|
12
|
-
}
|
|
11
|
+
};
|
|
13
12
|
|
|
14
13
|
export type StateMachineEvent = AnyEventObject;
|
|
15
14
|
|
|
@@ -18,14 +17,14 @@ export type SendStateMachineEventInput = {
|
|
|
18
17
|
context: any;
|
|
19
18
|
currentState: string;
|
|
20
19
|
event: StateMachineEvent;
|
|
21
|
-
}
|
|
20
|
+
};
|
|
22
21
|
|
|
23
22
|
export type GetStateMachineNextSnapshotOptions = {
|
|
24
23
|
machineConfig: MachineConfig<any, any>;
|
|
25
24
|
context: any;
|
|
26
25
|
currentState: string;
|
|
27
26
|
event: StateMachineEvent;
|
|
28
|
-
}
|
|
27
|
+
};
|
|
29
28
|
|
|
30
29
|
export type DefaultStateMachineSnapshot = MachineSnapshot<MachineContext, EventObject, Record<string, AnyActorRef | undefined>, StateValue, string, unknown, MetaObject>;
|
|
31
30
|
|
|
@@ -34,8 +33,8 @@ export type TryGetStateMachineNextSnapshotResult = TryGetStateMachineNextSnapsho
|
|
|
34
33
|
export type TryGetStateMachineNextSnapshotPositiveResult = {
|
|
35
34
|
canTransfer: true;
|
|
36
35
|
nextSnapshot: DefaultStateMachineSnapshot;
|
|
37
|
-
}
|
|
36
|
+
};
|
|
38
37
|
|
|
39
38
|
export type TryGetStateMachineNextSnapshotNegativeResult = {
|
|
40
39
|
canTransfer: false;
|
|
41
|
-
}
|
|
40
|
+
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { IPluginActionHandler } from "~/core/actionHandler";
|
|
2
2
|
import * as sendStateMachineEvent from "./sendStateMachineEvent";
|
|
3
3
|
|
|
4
|
-
export default [
|
|
5
|
-
sendStateMachineEvent,
|
|
6
|
-
] satisfies IPluginActionHandler[];
|
|
4
|
+
export default [sendStateMachineEvent] satisfies IPluginActionHandler[];
|
|
@@ -5,11 +5,7 @@ import { getStateMachineNextSnapshot } from "../stateMachineHelper";
|
|
|
5
5
|
|
|
6
6
|
export const code = "sendStateMachineEvent";
|
|
7
7
|
|
|
8
|
-
export async function handler(
|
|
9
|
-
plugin: RapidPlugin,
|
|
10
|
-
ctx: ActionHandlerContext,
|
|
11
|
-
options: SendStateMachineEventOptions,
|
|
12
|
-
) {
|
|
8
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: SendStateMachineEventOptions) {
|
|
13
9
|
const { server, routerContext } = ctx;
|
|
14
10
|
const { response } = routerContext;
|
|
15
11
|
|
|
@@ -32,8 +28,8 @@ export async function handler(
|
|
|
32
28
|
operator: "eq",
|
|
33
29
|
field: "code",
|
|
34
30
|
value: input.code,
|
|
35
|
-
}
|
|
36
|
-
]
|
|
31
|
+
},
|
|
32
|
+
],
|
|
37
33
|
});
|
|
38
34
|
|
|
39
35
|
if (!stateMachine) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RpdDataModel } from "~/types";
|
|
2
2
|
|
|
3
|
-
export default
|
|
3
|
+
export default {
|
|
4
4
|
maintainedBy: "stateMachinePlugin",
|
|
5
5
|
namespace: "svc",
|
|
6
6
|
name: "state_machine",
|
|
@@ -39,4 +39,4 @@ export default {
|
|
|
39
39
|
required: false,
|
|
40
40
|
},
|
|
41
41
|
],
|
|
42
|
-
} as RpdDataModel;
|
|
42
|
+
} as RpdDataModel;
|
|
@@ -2,19 +2,12 @@
|
|
|
2
2
|
* Webhooks plugin
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
RpdApplicationConfig,
|
|
7
|
-
RpdEntityCreateEventPayload,
|
|
8
|
-
RpdEntityDeleteEventPayload,
|
|
9
|
-
RpdEntityUpdateEventPayload,
|
|
10
|
-
RpdServerEventTypes,
|
|
11
|
-
} from "~/types";
|
|
5
|
+
import { RpdApplicationConfig, RpdEntityCreateEventPayload, RpdEntityDeleteEventPayload, RpdEntityUpdateEventPayload, RpdServerEventTypes } from "~/types";
|
|
12
6
|
import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "~/core/server";
|
|
13
7
|
import { fetchWithTimeout } from "~/utilities/httpUtility";
|
|
14
8
|
import pluginConfig from "./pluginConfig";
|
|
15
9
|
import { indexOf } from "lodash";
|
|
16
10
|
|
|
17
|
-
|
|
18
11
|
export interface Webhook {
|
|
19
12
|
name: string;
|
|
20
13
|
url: string;
|
|
@@ -26,10 +19,7 @@ export interface Webhook {
|
|
|
26
19
|
enabled: boolean;
|
|
27
20
|
}
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
function listWebhooks(
|
|
31
|
-
server: IRpdServer,
|
|
32
|
-
) {
|
|
22
|
+
function listWebhooks(server: IRpdServer) {
|
|
33
23
|
const logger = server.getLogger();
|
|
34
24
|
logger.info("Loading meta of webhooks...");
|
|
35
25
|
|
|
@@ -49,7 +39,6 @@ function listWebhooks(
|
|
|
49
39
|
}
|
|
50
40
|
}
|
|
51
41
|
|
|
52
|
-
|
|
53
42
|
class WebhooksPlugin implements RapidPlugin {
|
|
54
43
|
#webhooks: Webhook[];
|
|
55
44
|
|
|
@@ -78,16 +67,9 @@ class WebhooksPlugin implements RapidPlugin {
|
|
|
78
67
|
}
|
|
79
68
|
|
|
80
69
|
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
81
|
-
const events: (keyof RpdServerEventTypes)[] = [
|
|
82
|
-
"entity.create",
|
|
83
|
-
"entity.update",
|
|
84
|
-
"entity.delete",
|
|
85
|
-
];
|
|
70
|
+
const events: (keyof RpdServerEventTypes)[] = ["entity.create", "entity.update", "entity.delete"];
|
|
86
71
|
for (const event of events) {
|
|
87
|
-
server.registerEventHandler(
|
|
88
|
-
event,
|
|
89
|
-
this.handleEntityEvent.bind(this, server, event),
|
|
90
|
-
);
|
|
72
|
+
server.registerEventHandler(event, this.handleEntityEvent.bind(this, server, event));
|
|
91
73
|
}
|
|
92
74
|
}
|
|
93
75
|
|
|
@@ -97,28 +79,17 @@ class WebhooksPlugin implements RapidPlugin {
|
|
|
97
79
|
});
|
|
98
80
|
}
|
|
99
81
|
|
|
100
|
-
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
101
|
-
}
|
|
82
|
+
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
102
83
|
|
|
103
|
-
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
104
|
-
}
|
|
84
|
+
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
105
85
|
|
|
106
86
|
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
107
87
|
this.#webhooks = await listWebhooks(server);
|
|
108
88
|
}
|
|
109
89
|
|
|
110
|
-
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
111
|
-
}
|
|
90
|
+
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
112
91
|
|
|
113
|
-
async handleEntityEvent(
|
|
114
|
-
server: IRpdServer,
|
|
115
|
-
event: keyof RpdServerEventTypes,
|
|
116
|
-
sender: RapidPlugin,
|
|
117
|
-
payload:
|
|
118
|
-
| RpdEntityCreateEventPayload
|
|
119
|
-
| RpdEntityUpdateEventPayload
|
|
120
|
-
| RpdEntityDeleteEventPayload,
|
|
121
|
-
) {
|
|
92
|
+
async handleEntityEvent(server: IRpdServer, event: keyof RpdServerEventTypes, sender: RapidPlugin, payload: RpdEntityCreateEventPayload | RpdEntityUpdateEventPayload | RpdEntityDeleteEventPayload) {
|
|
122
93
|
if (sender === this) {
|
|
123
94
|
return;
|
|
124
95
|
}
|
|
@@ -140,10 +111,7 @@ class WebhooksPlugin implements RapidPlugin {
|
|
|
140
111
|
continue;
|
|
141
112
|
}
|
|
142
113
|
|
|
143
|
-
if (
|
|
144
|
-
webhook.namespace != payload.namespace ||
|
|
145
|
-
webhook.modelSingularCode !== payload.modelSingularCode
|
|
146
|
-
) {
|
|
114
|
+
if (webhook.namespace != payload.namespace || webhook.modelSingularCode !== payload.modelSingularCode) {
|
|
147
115
|
continue;
|
|
148
116
|
}
|
|
149
117
|
|
package/src/polyfill.ts
CHANGED
package/src/proxy/mod.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { fetchWithTimeout } from "../utilities/httpUtility";
|
|
2
2
|
import { ProxyContext, ProxyOptions } from "./types";
|
|
3
|
-
import { RouteContext} from "~/core/routeContext";
|
|
3
|
+
import { RouteContext } from "~/core/routeContext";
|
|
4
4
|
|
|
5
|
-
export async function doProxy(
|
|
6
|
-
sourceRouterCtx: RouteContext,
|
|
7
|
-
options: ProxyOptions,
|
|
8
|
-
) {
|
|
5
|
+
export async function doProxy(sourceRouterCtx: RouteContext, options: ProxyOptions) {
|
|
9
6
|
const proxyCtx = createProxyContext(sourceRouterCtx, options);
|
|
10
7
|
const targetRes = await sendTargetRequest(proxyCtx);
|
|
11
8
|
sendSourceResponse(proxyCtx, targetRes);
|
|
12
9
|
}
|
|
13
10
|
|
|
14
|
-
export function createProxyContext(
|
|
15
|
-
sourceRouterCtx: RouteContext,
|
|
16
|
-
options: ProxyOptions,
|
|
17
|
-
) {
|
|
11
|
+
export function createProxyContext(sourceRouterCtx: RouteContext, options: ProxyOptions) {
|
|
18
12
|
return {
|
|
19
13
|
sourceContext: {
|
|
20
14
|
request: sourceRouterCtx.request,
|
|
@@ -37,10 +31,7 @@ export async function sendTargetRequest(proxyCtx: ProxyContext) {
|
|
|
37
31
|
return await fetchWithTimeout(target, reqInit, timeout);
|
|
38
32
|
}
|
|
39
33
|
|
|
40
|
-
export async function sendSourceResponse(
|
|
41
|
-
proxyCtx: ProxyContext,
|
|
42
|
-
targetRes: Response,
|
|
43
|
-
) {
|
|
34
|
+
export async function sendSourceResponse(proxyCtx: ProxyContext, targetRes: Response) {
|
|
44
35
|
const { response: srcRes } = proxyCtx.sourceContext;
|
|
45
36
|
srcRes.status = targetRes.status;
|
|
46
37
|
srcRes.body = targetRes.body;
|