@ruiapp/rapid-core 0.1.42 → 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 +575 -323
- 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 +19 -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 +2 -6
- 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
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as cron from
|
|
1
|
+
import * as cron from "cron";
|
|
2
2
|
import type { RpdApplicationConfig } from "~/types";
|
|
3
3
|
import pluginActionHandlers from "./actionHandlers";
|
|
4
4
|
import pluginRoutes from "./routes";
|
|
5
5
|
import { CronJobConfiguration, CronJobPluginInitOptions } from "./CronJobPluginTypes";
|
|
6
6
|
import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
|
|
7
|
-
import { ActionHandlerContext } from
|
|
8
|
-
import { find } from
|
|
7
|
+
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
8
|
+
import { find } from "lodash";
|
|
9
9
|
|
|
10
10
|
class CronJobPlugin implements RapidPlugin {
|
|
11
11
|
#jobs: CronJobConfiguration[];
|
|
@@ -34,11 +34,9 @@ class CronJobPlugin implements RapidPlugin {
|
|
|
34
34
|
return [];
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
async initPlugin(server: IRpdServer): Promise<any> {
|
|
38
|
-
}
|
|
37
|
+
async initPlugin(server: IRpdServer): Promise<any> {}
|
|
39
38
|
|
|
40
|
-
async registerMiddlewares(server: IRpdServer): Promise<any> {
|
|
41
|
-
}
|
|
39
|
+
async registerMiddlewares(server: IRpdServer): Promise<any> {}
|
|
42
40
|
|
|
43
41
|
async registerActionHandlers(server: IRpdServer): Promise<any> {
|
|
44
42
|
for (const actionHandler of pluginActionHandlers) {
|
|
@@ -46,30 +44,23 @@ class CronJobPlugin implements RapidPlugin {
|
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
50
|
-
}
|
|
47
|
+
async registerEventHandlers(server: IRpdServer): Promise<any> {}
|
|
51
48
|
|
|
52
|
-
async registerMessageHandlers(server: IRpdServer): Promise<any> {
|
|
53
|
-
}
|
|
49
|
+
async registerMessageHandlers(server: IRpdServer): Promise<any> {}
|
|
54
50
|
|
|
55
|
-
async registerTaskProcessors(server: IRpdServer): Promise<any> {
|
|
56
|
-
}
|
|
51
|
+
async registerTaskProcessors(server: IRpdServer): Promise<any> {}
|
|
57
52
|
|
|
58
|
-
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
59
|
-
}
|
|
53
|
+
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
60
54
|
|
|
61
|
-
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
62
|
-
}
|
|
55
|
+
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
63
56
|
|
|
64
|
-
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
65
|
-
}
|
|
57
|
+
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
66
58
|
|
|
67
59
|
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
68
60
|
server.appendApplicationConfig({ routes: pluginRoutes });
|
|
69
61
|
}
|
|
70
62
|
|
|
71
|
-
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
72
|
-
}
|
|
63
|
+
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {}
|
|
73
64
|
|
|
74
65
|
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
75
66
|
for (const job of this.#jobs) {
|
|
@@ -11,25 +11,25 @@ export interface CronJobConfiguration {
|
|
|
11
11
|
* 定时任务描述
|
|
12
12
|
*/
|
|
13
13
|
description?: string;
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
/**
|
|
16
16
|
* crontab 表达式
|
|
17
17
|
*/
|
|
18
18
|
cronTime: string;
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
/**
|
|
21
21
|
* 任务处理程序编号。当指定处理程序编号时,忽略 handler 配置。
|
|
22
22
|
*/
|
|
23
23
|
actionHandlerCode?: string;
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
/**
|
|
26
26
|
* 定时任务处理程序
|
|
27
|
-
* @param ctx
|
|
28
|
-
* @param options
|
|
29
|
-
* @returns
|
|
27
|
+
* @param ctx
|
|
28
|
+
* @param options
|
|
29
|
+
* @returns
|
|
30
30
|
*/
|
|
31
31
|
handler?: (ctx: ActionHandlerContext, options: any) => Promise<void>;
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
/**
|
|
34
34
|
* 处理定时任务时的设置选项
|
|
35
35
|
*/
|
|
@@ -42,8 +42,8 @@ export interface CronJobPluginInitOptions {
|
|
|
42
42
|
|
|
43
43
|
export type RunCronJobActionHandlerOptions = {
|
|
44
44
|
code?: string;
|
|
45
|
-
}
|
|
45
|
+
};
|
|
46
46
|
|
|
47
47
|
export type RunCronJobInput = {
|
|
48
48
|
code?: string;
|
|
49
|
-
}
|
|
49
|
+
};
|
|
@@ -4,14 +4,10 @@ import type CronJobPlugin from "../CronJobPlugin";
|
|
|
4
4
|
|
|
5
5
|
export const code = "runCronJob";
|
|
6
6
|
|
|
7
|
-
export async function handler(
|
|
8
|
-
plugin: CronJobPlugin,
|
|
9
|
-
ctx: ActionHandlerContext,
|
|
10
|
-
options: RunCronJobActionHandlerOptions,
|
|
11
|
-
) {
|
|
7
|
+
export async function handler(plugin: CronJobPlugin, ctx: ActionHandlerContext, options: RunCronJobActionHandlerOptions) {
|
|
12
8
|
const { server, routerContext } = ctx;
|
|
13
9
|
const { response } = routerContext;
|
|
14
|
-
|
|
10
|
+
|
|
15
11
|
const input: RunCronJobInput = ctx.input;
|
|
16
12
|
|
|
17
13
|
if (options.code) {
|
|
@@ -29,6 +25,5 @@ export async function handler(
|
|
|
29
25
|
|
|
30
26
|
await plugin.executeJob(server, job);
|
|
31
27
|
|
|
32
|
-
response.json({
|
|
33
|
-
});
|
|
28
|
+
response.json({});
|
|
34
29
|
}
|
|
@@ -4,12 +4,7 @@
|
|
|
4
4
|
* - routes for manage data in database.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
RpdApplicationConfig,
|
|
9
|
-
RpdHttpMethod,
|
|
10
|
-
RpdRoute,
|
|
11
|
-
RunEntityActionHandlerOptions,
|
|
12
|
-
} from "~/types";
|
|
7
|
+
import { RpdApplicationConfig, RpdHttpMethod, RpdRoute, RunEntityActionHandlerOptions } from "~/types";
|
|
13
8
|
|
|
14
9
|
import * as findCollectionEntities from "./actionHandlers/findCollectionEntities";
|
|
15
10
|
import * as findCollectionEntityById from "./actionHandlers/findCollectionEntityById";
|
|
@@ -23,7 +18,6 @@ import * as removeEntityRelations from "./actionHandlers/removeEntityRelations";
|
|
|
23
18
|
import * as queryDatabase from "./actionHandlers/queryDatabase";
|
|
24
19
|
import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "~/core/server";
|
|
25
20
|
|
|
26
|
-
|
|
27
21
|
const routeConfigs: {
|
|
28
22
|
code: string;
|
|
29
23
|
method: RpdHttpMethod;
|
|
@@ -123,10 +117,10 @@ class DataManager implements RapidPlugin {
|
|
|
123
117
|
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
124
118
|
const { models } = applicationConfig;
|
|
125
119
|
const routes: RpdRoute[] = [];
|
|
126
|
-
|
|
120
|
+
|
|
127
121
|
models.forEach((model) => {
|
|
128
122
|
const { namespace, singularCode, pluralCode } = model;
|
|
129
|
-
|
|
123
|
+
|
|
130
124
|
routeConfigs.forEach((routeConfig) => {
|
|
131
125
|
routes.push({
|
|
132
126
|
namespace,
|
|
@@ -147,9 +141,9 @@ class DataManager implements RapidPlugin {
|
|
|
147
141
|
});
|
|
148
142
|
});
|
|
149
143
|
});
|
|
150
|
-
|
|
144
|
+
|
|
151
145
|
server.appendApplicationConfig({ routes });
|
|
152
146
|
}
|
|
153
147
|
}
|
|
154
148
|
|
|
155
|
-
export default DataManager;
|
|
149
|
+
export default DataManager;
|
|
@@ -5,11 +5,7 @@ import { RapidPlugin } from "~/core/server";
|
|
|
5
5
|
|
|
6
6
|
export const code = "addEntityRelations";
|
|
7
7
|
|
|
8
|
-
export async function handler(
|
|
9
|
-
plugin: RapidPlugin,
|
|
10
|
-
ctx: ActionHandlerContext,
|
|
11
|
-
options: RunEntityActionHandlerOptions,
|
|
12
|
-
) {
|
|
8
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
13
9
|
const { logger, server, input } = ctx;
|
|
14
10
|
|
|
15
11
|
const { defaultInput, fixedInput } = options;
|
|
@@ -6,18 +6,9 @@ import { RapidPlugin } from "~/core/server";
|
|
|
6
6
|
|
|
7
7
|
export const code = "countCollectionEntities";
|
|
8
8
|
|
|
9
|
-
export async function handler(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
)
|
|
14
|
-
await runCollectionEntityActionHandler(
|
|
15
|
-
ctx,
|
|
16
|
-
options,
|
|
17
|
-
code,
|
|
18
|
-
(entityManager, input) => {
|
|
19
|
-
input.filters = removeFiltersWithNullValue(input.filters);
|
|
20
|
-
return entityManager.count(input);
|
|
21
|
-
},
|
|
22
|
-
);
|
|
9
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
10
|
+
await runCollectionEntityActionHandler(ctx, options, code, (entityManager, input) => {
|
|
11
|
+
input.filters = removeFiltersWithNullValue(input.filters);
|
|
12
|
+
return entityManager.count(input);
|
|
13
|
+
});
|
|
23
14
|
}
|
|
@@ -6,11 +6,7 @@ import { RapidPlugin } from "~/core/server";
|
|
|
6
6
|
|
|
7
7
|
export const code = "createCollectionEntitiesBatch";
|
|
8
8
|
|
|
9
|
-
export async function handler(
|
|
10
|
-
plugin: RapidPlugin,
|
|
11
|
-
ctx: ActionHandlerContext,
|
|
12
|
-
options: RunEntityActionHandlerOptions,
|
|
13
|
-
) {
|
|
9
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
14
10
|
const { logger, server, input } = ctx;
|
|
15
11
|
|
|
16
12
|
const { defaultInput, fixedInput } = options;
|
|
@@ -22,7 +18,7 @@ export async function handler(
|
|
|
22
18
|
}
|
|
23
19
|
|
|
24
20
|
const output: any[] = [];
|
|
25
|
-
for(const entity of entities) {
|
|
21
|
+
for (const entity of entities) {
|
|
26
22
|
const mergedEntity = mergeInput(defaultInput?.entity || {}, entity, fixedInput?.entity);
|
|
27
23
|
|
|
28
24
|
const userId = ctx.routerContext.state?.userId;
|
|
@@ -31,9 +27,12 @@ export async function handler(
|
|
|
31
27
|
}
|
|
32
28
|
|
|
33
29
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
34
|
-
const newEntity = await entityManager.createEntity(
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
const newEntity = await entityManager.createEntity(
|
|
31
|
+
{
|
|
32
|
+
entity: mergedEntity,
|
|
33
|
+
},
|
|
34
|
+
plugin,
|
|
35
|
+
);
|
|
37
36
|
|
|
38
37
|
output.push(newEntity);
|
|
39
38
|
}
|
|
@@ -5,11 +5,7 @@ import { RapidPlugin } from "~/core/server";
|
|
|
5
5
|
|
|
6
6
|
export const code = "createCollectionEntity";
|
|
7
7
|
|
|
8
|
-
export async function handler(
|
|
9
|
-
plugin: RapidPlugin,
|
|
10
|
-
ctx: ActionHandlerContext,
|
|
11
|
-
options: RunEntityActionHandlerOptions,
|
|
12
|
-
) {
|
|
8
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
13
9
|
const { logger, server, input } = ctx;
|
|
14
10
|
|
|
15
11
|
const { defaultInput, fixedInput } = options;
|
|
@@ -22,8 +18,11 @@ export async function handler(
|
|
|
22
18
|
}
|
|
23
19
|
|
|
24
20
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
25
|
-
const output = await entityManager.createEntity(
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const output = await entityManager.createEntity(
|
|
22
|
+
{
|
|
23
|
+
entity: input,
|
|
24
|
+
},
|
|
25
|
+
plugin,
|
|
26
|
+
);
|
|
28
27
|
ctx.output = output;
|
|
29
28
|
}
|
|
@@ -4,11 +4,7 @@ import { RapidPlugin } from "~/core/server";
|
|
|
4
4
|
|
|
5
5
|
export const code = "deleteCollectionEntityById";
|
|
6
6
|
|
|
7
|
-
export async function handler(
|
|
8
|
-
plugin: RapidPlugin,
|
|
9
|
-
ctx: ActionHandlerContext,
|
|
10
|
-
options: RunEntityActionHandlerOptions,
|
|
11
|
-
) {
|
|
7
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
12
8
|
const { logger, server, input } = ctx;
|
|
13
9
|
logger.debug(`Running ${code} handler...`);
|
|
14
10
|
|
|
@@ -6,29 +6,20 @@ import { RapidPlugin } from "~/core/server";
|
|
|
6
6
|
|
|
7
7
|
export const code = "findCollectionEntities";
|
|
8
8
|
|
|
9
|
-
export async function handler(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
code,
|
|
18
|
-
async (entityManager, input: FindEntityOptions) => {
|
|
19
|
-
input.filters = removeFiltersWithNullValue(input.filters);
|
|
20
|
-
const entities = await entityManager.findEntities(input);
|
|
21
|
-
const result: {
|
|
22
|
-
list: any;
|
|
23
|
-
total?: any;
|
|
24
|
-
} = { list: entities };
|
|
9
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
10
|
+
await runCollectionEntityActionHandler(ctx, options, code, async (entityManager, input: FindEntityOptions) => {
|
|
11
|
+
input.filters = removeFiltersWithNullValue(input.filters);
|
|
12
|
+
const entities = await entityManager.findEntities(input);
|
|
13
|
+
const result: {
|
|
14
|
+
list: any;
|
|
15
|
+
total?: any;
|
|
16
|
+
} = { list: entities };
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
18
|
+
if (input.pagination && !input.pagination.withoutTotal) {
|
|
19
|
+
// TOOD: count entities when calling findEntities for performance.
|
|
20
|
+
const countResult = await entityManager.count(input);
|
|
21
|
+
result.total = countResult.count;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
});
|
|
34
25
|
}
|
|
@@ -4,11 +4,7 @@ import { RapidPlugin } from "~/core/server";
|
|
|
4
4
|
|
|
5
5
|
export const code = "findCollectionEntityById";
|
|
6
6
|
|
|
7
|
-
export async function handler(
|
|
8
|
-
plugin: RapidPlugin,
|
|
9
|
-
ctx: ActionHandlerContext,
|
|
10
|
-
options: RunEntityActionHandlerOptions,
|
|
11
|
-
) {
|
|
7
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
12
8
|
const { logger, server, input } = ctx;
|
|
13
9
|
logger.debug(`Running ${code} handler...`, { input });
|
|
14
10
|
const { id } = input;
|
|
@@ -6,11 +6,7 @@ import { first } from "lodash";
|
|
|
6
6
|
|
|
7
7
|
export const code = "queryDatabase";
|
|
8
8
|
|
|
9
|
-
export async function handler(
|
|
10
|
-
plugin: RapidPlugin,
|
|
11
|
-
ctx: ActionHandlerContext,
|
|
12
|
-
options: RunQueryDatabaseHandlerOptions,
|
|
13
|
-
) {
|
|
9
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunQueryDatabaseHandlerOptions) {
|
|
14
10
|
const { logger, server, input } = ctx;
|
|
15
11
|
|
|
16
12
|
const { sql, querySingle, defaultInput, fixedInput } = options;
|
|
@@ -5,11 +5,7 @@ import { RapidPlugin } from "~/core/server";
|
|
|
5
5
|
|
|
6
6
|
export const code = "removeEntityRelations";
|
|
7
7
|
|
|
8
|
-
export async function handler(
|
|
9
|
-
plugin: RapidPlugin,
|
|
10
|
-
ctx: ActionHandlerContext,
|
|
11
|
-
options: RunEntityActionHandlerOptions,
|
|
12
|
-
) {
|
|
8
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
13
9
|
const { logger, server, input } = ctx;
|
|
14
10
|
const { defaultInput, fixedInput } = options;
|
|
15
11
|
|
|
@@ -5,11 +5,7 @@ import { RapidPlugin } from "~/core/server";
|
|
|
5
5
|
|
|
6
6
|
export const code = "updateCollectionEntityById";
|
|
7
7
|
|
|
8
|
-
export async function handler(
|
|
9
|
-
plugin: RapidPlugin,
|
|
10
|
-
ctx: ActionHandlerContext,
|
|
11
|
-
options: RunEntityActionHandlerOptions,
|
|
12
|
-
) {
|
|
8
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
13
9
|
const { logger, server, input } = ctx;
|
|
14
10
|
|
|
15
11
|
const { defaultInput, fixedInput } = options;
|
|
@@ -7,8 +7,7 @@ import { isAccessAllowed } from "~/utilities/accessControlUtility";
|
|
|
7
7
|
import { RouteContext } from "~/core/routeContext";
|
|
8
8
|
|
|
9
9
|
class EntityAccessControlPlugin implements RapidPlugin {
|
|
10
|
-
constructor() {
|
|
11
|
-
}
|
|
10
|
+
constructor() {}
|
|
12
11
|
|
|
13
12
|
get code(): string {
|
|
14
13
|
return "entityAccessControl";
|
|
@@ -44,7 +43,7 @@ class EntityAccessControlPlugin implements RapidPlugin {
|
|
|
44
43
|
|
|
45
44
|
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
46
45
|
const logger = server.getLogger();
|
|
47
|
-
logger.info("Configuring entity access checking policies...")
|
|
46
|
+
logger.info("Configuring entity access checking policies...");
|
|
48
47
|
|
|
49
48
|
const model = find(applicationConfig.models, (item) => item.singularCode === "model");
|
|
50
49
|
if (!model) {
|
|
@@ -84,9 +83,9 @@ class EntityAccessControlPlugin implements RapidPlugin {
|
|
|
84
83
|
inner join oc_role_sys_action_links ra on a.id = ra.action_id
|
|
85
84
|
inner join oc_role_user_links ru on ru.role_id = ra.role_id
|
|
86
85
|
where ru.user_id = $1;`,
|
|
87
|
-
[userId]
|
|
88
|
-
|
|
89
|
-
routeContext.state.allowedActions = actions.map(item => item.code);
|
|
86
|
+
[userId],
|
|
87
|
+
);
|
|
88
|
+
routeContext.state.allowedActions = actions.map((item) => item.code);
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
async beforeRunRouteActions(server: IRpdServer, handlerContext: ActionHandlerContext): Promise<any> {
|
|
@@ -4,11 +4,11 @@ import { EntityWatchHandlerContext, EntityWatchPluginInitOptions } from "./Entit
|
|
|
4
4
|
import EventManager from "~/core/eventManager";
|
|
5
5
|
|
|
6
6
|
class EntityWatchPlugin implements RapidPlugin {
|
|
7
|
-
#createEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]
|
|
8
|
-
#updateEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]
|
|
9
|
-
#deleteEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]
|
|
10
|
-
#addRelationsEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]
|
|
11
|
-
#removeRelationsEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]
|
|
7
|
+
#createEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|
|
8
|
+
#updateEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|
|
9
|
+
#deleteEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|
|
10
|
+
#addRelationsEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|
|
11
|
+
#removeRelationsEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|
|
12
12
|
|
|
13
13
|
constructor(options: EntityWatchPluginInitOptions) {
|
|
14
14
|
const { watchers } = options;
|
|
@@ -62,32 +62,33 @@ class EntityWatchPlugin implements RapidPlugin {
|
|
|
62
62
|
server.registerEventHandler("entity.removeRelations", this.handleEntityEvent.bind(this, server, "entity.removeRelations"));
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
handleEntityEvent(
|
|
66
|
-
server: IRpdServer,
|
|
67
|
-
eventName: keyof RpdServerEventTypes,
|
|
68
|
-
sender: RapidPlugin,
|
|
69
|
-
payload: RpdEntityCreateEventPayload
|
|
70
|
-
) {
|
|
65
|
+
handleEntityEvent(server: IRpdServer, eventName: keyof RpdServerEventTypes, sender: RapidPlugin, payload: RpdEntityCreateEventPayload) {
|
|
71
66
|
if (sender === this) {
|
|
72
67
|
return;
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
const { modelSingularCode } = payload;
|
|
70
|
+
const { modelSingularCode, baseModelSingularCode } = payload;
|
|
76
71
|
const entityWatchHandlerContext: EntityWatchHandlerContext<typeof eventName> = {
|
|
77
72
|
server,
|
|
78
73
|
payload,
|
|
79
74
|
};
|
|
80
75
|
|
|
76
|
+
let emitter: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|
|
81
77
|
if (eventName === "entity.create") {
|
|
82
|
-
this.#createEventEmitters
|
|
78
|
+
emitter = this.#createEventEmitters;
|
|
83
79
|
} else if (eventName === "entity.update") {
|
|
84
|
-
this.#updateEventEmitters
|
|
80
|
+
emitter = this.#updateEventEmitters;
|
|
85
81
|
} else if (eventName === "entity.delete") {
|
|
86
|
-
this.#deleteEventEmitters
|
|
82
|
+
emitter = this.#deleteEventEmitters;
|
|
87
83
|
} else if (eventName === "entity.addRelations") {
|
|
88
|
-
this.#addRelationsEventEmitters
|
|
84
|
+
emitter = this.#addRelationsEventEmitters;
|
|
89
85
|
} else if (eventName === "entity.removeRelations") {
|
|
90
|
-
this.#removeRelationsEventEmitters
|
|
86
|
+
emitter = this.#removeRelationsEventEmitters;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
emitter.emit(modelSingularCode, entityWatchHandlerContext);
|
|
90
|
+
if (baseModelSingularCode) {
|
|
91
|
+
emitter.emit(baseModelSingularCode, entityWatchHandlerContext);
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { IRpdServer } from "~/core/server";
|
|
2
2
|
import { RpdServerEventTypes } from "~/types";
|
|
3
3
|
|
|
4
|
-
export type EntityWatcherType =
|
|
5
|
-
| EntityWatcher<"entity.create">
|
|
6
|
-
| EntityWatcher<"entity.update">
|
|
7
|
-
| EntityWatcher<"entity.delete">
|
|
8
|
-
| EntityWatcher<"entity.addRelations">
|
|
9
|
-
| EntityWatcher<"entity.removeRelations">
|
|
10
|
-
| EntityWatcher<any>
|
|
11
|
-
;
|
|
4
|
+
export type EntityWatcherType = EntityWatcher<"entity.create"> | EntityWatcher<"entity.update"> | EntityWatcher<"entity.delete"> | EntityWatcher<"entity.addRelations"> | EntityWatcher<"entity.removeRelations"> | EntityWatcher<any>;
|
|
12
5
|
|
|
13
6
|
export interface EntityWatcher<TEventName extends keyof RpdServerEventTypes = any> {
|
|
14
7
|
eventName: TEventName;
|
|
@@ -21,8 +14,8 @@ export type EntityWatchHandler<TEventName extends keyof RpdServerEventTypes> = (
|
|
|
21
14
|
export type EntityWatchHandlerContext<TEventName extends keyof RpdServerEventTypes> = {
|
|
22
15
|
server: IRpdServer;
|
|
23
16
|
payload: RpdServerEventTypes[TEventName][1];
|
|
24
|
-
}
|
|
17
|
+
};
|
|
25
18
|
|
|
26
19
|
export interface EntityWatchPluginInitOptions {
|
|
27
20
|
watchers: EntityWatcherType[];
|
|
28
|
-
}
|
|
21
|
+
}
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
* File manager plugin
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
RpdApplicationConfig,
|
|
7
|
-
} from "~/types";
|
|
5
|
+
import { RpdApplicationConfig } from "~/types";
|
|
8
6
|
|
|
9
7
|
import * as downloadDocumentActionHandler from "./actionHandlers/downloadDocument";
|
|
10
8
|
import * as downloadFileActionHandler from "./actionHandlers/downloadFile";
|
|
@@ -5,11 +5,7 @@ import { readFile } from "~/utilities/fsUtility";
|
|
|
5
5
|
|
|
6
6
|
export const code = "downloadDocument";
|
|
7
7
|
|
|
8
|
-
export async function handler(
|
|
9
|
-
plugin: RapidPlugin,
|
|
10
|
-
ctx: ActionHandlerContext,
|
|
11
|
-
options: any,
|
|
12
|
-
) {
|
|
8
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
13
9
|
const { server, applicationConfig, routerContext, input } = ctx;
|
|
14
10
|
const { request, response } = routerContext;
|
|
15
11
|
|
|
@@ -36,5 +32,5 @@ export async function handler(
|
|
|
36
32
|
const attachmentFileName = document.name;
|
|
37
33
|
|
|
38
34
|
response.body = await readFile(filePathName);
|
|
39
|
-
response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`)
|
|
35
|
+
response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`);
|
|
40
36
|
}
|
|
@@ -5,11 +5,7 @@ import { RapidPlugin } from "~/core/server";
|
|
|
5
5
|
|
|
6
6
|
export const code = "downloadFile";
|
|
7
7
|
|
|
8
|
-
export async function handler(
|
|
9
|
-
plugin: RapidPlugin,
|
|
10
|
-
ctx: ActionHandlerContext,
|
|
11
|
-
options: any,
|
|
12
|
-
) {
|
|
8
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
13
9
|
const { server, applicationConfig, routerContext, input } = ctx;
|
|
14
10
|
const { request, response } = routerContext;
|
|
15
11
|
|
|
@@ -28,5 +24,5 @@ export async function handler(
|
|
|
28
24
|
const attachmentFileName = input.fileName || path.basename(fileKey);
|
|
29
25
|
|
|
30
26
|
response.body = await readFile(filePathName);
|
|
31
|
-
response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`)
|
|
27
|
+
response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`);
|
|
32
28
|
}
|
|
@@ -7,11 +7,7 @@ import { RapidPlugin } from "~/core/server";
|
|
|
7
7
|
|
|
8
8
|
export const code = "uploadFile";
|
|
9
9
|
|
|
10
|
-
export async function handler(
|
|
11
|
-
plugin: RapidPlugin,
|
|
12
|
-
ctx: ActionHandlerContext,
|
|
13
|
-
options: any,
|
|
14
|
-
) {
|
|
10
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
15
11
|
const { server, applicationConfig, routerContext, input } = ctx;
|
|
16
12
|
const { request, response } = routerContext;
|
|
17
13
|
|
|
@@ -22,12 +18,12 @@ export async function handler(
|
|
|
22
18
|
|
|
23
19
|
if (!file) {
|
|
24
20
|
ctx.status = 400;
|
|
25
|
-
ctx.output = { error: "File not found in request body."};
|
|
21
|
+
ctx.output = { error: "File not found in request body." };
|
|
26
22
|
return;
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
const extName = path.extname(file.name);
|
|
30
|
-
const fileKey = `${uuidv1()}${extName}
|
|
26
|
+
const fileKey = `${uuidv1()}${extName}`;
|
|
31
27
|
const filePathName = path.join(server.config.localFileStoragePath, fileKey);
|
|
32
28
|
|
|
33
29
|
const fileBuffer = await file.arrayBuffer();
|