@ruiapp/rapid-core 0.1.3 → 0.1.5
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/core/http/formDataParser.d.ts +22 -0
- package/dist/core/httpHandler.d.ts +3 -3
- package/dist/core/pluginManager.d.ts +31 -26
- package/dist/core/providers/runtimeProvider.d.ts +4 -0
- package/dist/core/routeContext.d.ts +0 -1
- package/dist/core/server.d.ts +21 -21
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3365 -3113
- package/dist/plugins/{authManager → auth}/httpHandlers/createSession.d.ts +2 -2
- package/dist/plugins/auth/httpHandlers/deleteSession.d.ts +4 -0
- package/dist/plugins/auth/httpHandlers/getMyProfile.d.ts +4 -0
- package/dist/plugins/auth/mod.d.ts +25 -0
- package/dist/plugins/dataManage/httpHandlers/addEntityRelations.d.ts +5 -0
- package/dist/plugins/dataManage/httpHandlers/countCollectionEntities.d.ts +5 -0
- package/dist/plugins/dataManage/httpHandlers/createCollectionEntitiesBatch.d.ts +5 -0
- package/dist/plugins/dataManage/httpHandlers/createCollectionEntity.d.ts +5 -0
- package/dist/plugins/dataManage/httpHandlers/deleteCollectionEntityById.d.ts +5 -0
- package/dist/plugins/dataManage/httpHandlers/findCollectionEntities.d.ts +5 -0
- package/dist/plugins/dataManage/httpHandlers/findCollectionEntityById.d.ts +5 -0
- package/dist/plugins/dataManage/httpHandlers/queryDatabase.d.ts +5 -0
- package/dist/plugins/dataManage/httpHandlers/removeEntityRelations.d.ts +5 -0
- package/dist/plugins/dataManage/httpHandlers/updateCollectionEntityById.d.ts +5 -0
- package/dist/plugins/dataManage/mod.d.ts +27 -0
- package/dist/plugins/fileManage/httpHandlers/downloadDocument.d.ts +4 -0
- package/dist/plugins/fileManage/httpHandlers/downloadFile.d.ts +4 -0
- package/dist/plugins/fileManage/httpHandlers/uploadFile.d.ts +4 -0
- package/dist/plugins/fileManage/mod.d.ts +25 -0
- package/dist/plugins/metaManage/httpHandlers/getMetaModelDetail.d.ts +4 -0
- package/dist/plugins/metaManage/httpHandlers/listMetaModels.d.ts +4 -0
- package/dist/plugins/metaManage/httpHandlers/listMetaRoutes.d.ts +4 -0
- package/dist/plugins/metaManage/mod.d.ts +25 -0
- package/dist/plugins/routeManage/httpHandlers/httpProxy.d.ts +5 -0
- package/dist/plugins/routeManage/mod.d.ts +25 -0
- package/dist/plugins/webhooks/mod.d.ts +25 -11
- package/dist/server.d.ts +5 -4
- package/dist/types.d.ts +7 -9
- package/dist/utilities/fsUtility.d.ts +6 -0
- package/package.json +3 -2
- package/src/core/http/formDataParser.ts +101 -0
- package/src/core/httpHandler.ts +3 -3
- package/src/core/pluginManager.ts +107 -106
- package/src/core/providers/runtimeProvider.ts +5 -0
- package/src/core/request.ts +2 -1
- package/src/core/routeContext.ts +0 -1
- package/src/core/routesBuilder.ts +2 -14
- package/src/core/server.ts +21 -39
- package/src/dataAccess/dataAccessor.ts +1 -1
- package/src/index.ts +7 -0
- package/src/plugins/{authManager → auth}/httpHandlers/createSession.ts +2 -2
- package/src/plugins/{authManager → auth}/httpHandlers/deleteSession.ts +2 -2
- package/src/plugins/{authManager → auth}/httpHandlers/getMyProfile.ts +2 -2
- package/src/plugins/auth/mod.ts +80 -0
- package/src/plugins/{dataManager → dataManage}/httpHandlers/addEntityRelations.ts +3 -2
- package/src/plugins/{dataManager → dataManage}/httpHandlers/countCollectionEntities.ts +3 -2
- package/src/plugins/{dataManager → dataManage}/httpHandlers/createCollectionEntitiesBatch.ts +3 -2
- package/src/plugins/{dataManager → dataManage}/httpHandlers/createCollectionEntity.ts +3 -2
- package/src/plugins/{dataManager → dataManage}/httpHandlers/deleteCollectionEntityById.ts +5 -4
- package/src/plugins/{dataManager → dataManage}/httpHandlers/findCollectionEntities.ts +3 -2
- package/src/plugins/{dataManager → dataManage}/httpHandlers/findCollectionEntityById.ts +3 -2
- package/src/plugins/{dataManager → dataManage}/httpHandlers/queryDatabase.ts +3 -2
- package/src/plugins/{dataManager → dataManage}/httpHandlers/removeEntityRelations.ts +3 -2
- package/src/plugins/{dataManager → dataManage}/httpHandlers/updateCollectionEntityById.ts +3 -2
- package/src/plugins/dataManage/mod.ts +187 -0
- package/src/plugins/fileManage/httpHandlers/downloadDocument.ts +40 -0
- package/src/plugins/fileManage/httpHandlers/downloadFile.ts +32 -0
- package/src/plugins/fileManage/httpHandlers/uploadFile.ts +37 -0
- package/src/plugins/fileManage/mod.ts +77 -0
- package/src/plugins/{metaManager → metaManage}/httpHandlers/getMetaModelDetail.ts +2 -2
- package/src/plugins/{metaManager → metaManage}/httpHandlers/listMetaModels.ts +2 -2
- package/src/plugins/{routeManager → metaManage}/httpHandlers/listMetaRoutes.ts +2 -2
- package/src/plugins/{metaManager → metaManage}/mod.ts +86 -53
- package/src/plugins/{routeManager → routeManage}/httpHandlers/httpProxy.ts +3 -2
- package/src/plugins/routeManage/mod.ts +92 -0
- package/src/plugins/webhooks/mod.ts +134 -94
- package/src/server.ts +19 -12
- package/src/types.ts +8 -11
- package/src/utilities/fsUtility.ts +62 -0
- package/dist/core/plugin.d.ts +0 -6
- package/dist/plugins/authManager/httpHandlers/deleteSession.d.ts +0 -4
- package/dist/plugins/authManager/httpHandlers/getMyProfile.d.ts +0 -4
- package/dist/plugins/authManager/mod.d.ts +0 -16
- package/dist/plugins/dataManager/httpHandlers/addEntityRelations.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/countCollectionEntities.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/createCollectionEntitiesBatch.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/createCollectionEntity.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/deleteCollectionEntityById.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/findCollectionEntities.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/findCollectionEntityById.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/queryDatabase.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/removeEntityRelations.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/updateCollectionEntityById.d.ts +0 -4
- package/dist/plugins/dataManager/mod.d.ts +0 -16
- package/dist/plugins/metaManager/httpHandlers/getMetaModelDetail.d.ts +0 -4
- package/dist/plugins/metaManager/httpHandlers/listMetaModels.d.ts +0 -4
- package/dist/plugins/metaManager/mod.d.ts +0 -15
- package/dist/plugins/routeManager/httpHandlers/httpProxy.d.ts +0 -4
- package/dist/plugins/routeManager/httpHandlers/listMetaRoutes.d.ts +0 -4
- package/dist/plugins/routeManager/mod.d.ts +0 -15
- package/src/core/plugin.ts +0 -13
- package/src/plugins/authManager/mod.ts +0 -56
- package/src/plugins/dataManager/mod.ts +0 -154
- package/src/plugins/routeManager/mod.ts +0 -97
- /package/dist/plugins/{authManager → auth}/httpHandlers/index.d.ts +0 -0
- /package/dist/plugins/{authManager → auth}/models/AccessToken.d.ts +0 -0
- /package/dist/plugins/{authManager → auth}/models/index.d.ts +0 -0
- /package/dist/plugins/{authManager → auth}/routes/getMyProfile.d.ts +0 -0
- /package/dist/plugins/{authManager → auth}/routes/index.d.ts +0 -0
- /package/dist/plugins/{authManager → auth}/routes/signin.d.ts +0 -0
- /package/dist/plugins/{authManager → auth}/routes/signout.d.ts +0 -0
- /package/src/plugins/{authManager → auth}/httpHandlers/index.ts +0 -0
- /package/src/plugins/{authManager → auth}/models/AccessToken.ts +0 -0
- /package/src/plugins/{authManager → auth}/models/index.ts +0 -0
- /package/src/plugins/{authManager → auth}/routes/getMyProfile.ts +0 -0
- /package/src/plugins/{authManager → auth}/routes/index.ts +0 -0
- /package/src/plugins/{authManager → auth}/routes/signin.ts +0 -0
- /package/src/plugins/{authManager → auth}/routes/signout.ts +0 -0
|
@@ -1,143 +1,144 @@
|
|
|
1
1
|
import { RpdApplicationConfig } from "~/types";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import * as authManager from "~/plugins/authManager/mod";
|
|
8
|
-
import { IRpdServer, IRpdServerPlugin } from "./server";
|
|
9
|
-
|
|
10
|
-
const plugins: IRpdServerPlugin[] = [];
|
|
11
|
-
|
|
12
|
-
export async function loadPlugins() {
|
|
13
|
-
plugins.push(metaManager);
|
|
14
|
-
plugins.push(dataManager);
|
|
15
|
-
plugins.push(routeManager);
|
|
16
|
-
plugins.push(webhooks);
|
|
17
|
-
plugins.push(authManager);
|
|
18
|
-
}
|
|
2
|
+
import { IRpdServer, RapidPlugin } from "./server";
|
|
3
|
+
|
|
4
|
+
class PluginManager {
|
|
5
|
+
#server: IRpdServer;
|
|
6
|
+
#plugins: RapidPlugin[];
|
|
19
7
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const pluginInstance = new Plugin(plugin.code);
|
|
24
|
-
await plugin.initPlugin(pluginInstance, server);
|
|
8
|
+
constructor(server: IRpdServer) {
|
|
9
|
+
this.#server = server;
|
|
10
|
+
this.#plugins = [];
|
|
25
11
|
}
|
|
26
|
-
}
|
|
27
12
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (plugin.registerMiddlewares) {
|
|
32
|
-
await plugin.registerMiddlewares(server);
|
|
13
|
+
async loadPlugins(plugins: RapidPlugin[]) {
|
|
14
|
+
for(const plugin of plugins) {
|
|
15
|
+
this.#plugins.push(plugin);
|
|
33
16
|
}
|
|
34
17
|
}
|
|
35
|
-
}
|
|
36
18
|
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
await plugin.registerHttpHandlers(server);
|
|
19
|
+
/** 初始化插件时调用。 */
|
|
20
|
+
async initPlugins() {
|
|
21
|
+
for (const plugin of this.#plugins) {
|
|
22
|
+
await plugin.initPlugin(this.#server);
|
|
42
23
|
}
|
|
43
24
|
}
|
|
44
|
-
}
|
|
45
25
|
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
26
|
+
/** 注册中间件 */
|
|
27
|
+
async registerMiddlewares() {
|
|
28
|
+
for (const plugin of this.#plugins) {
|
|
29
|
+
if (plugin.registerMiddlewares) {
|
|
30
|
+
await plugin.registerMiddlewares(this.#server);
|
|
31
|
+
}
|
|
51
32
|
}
|
|
52
33
|
}
|
|
53
|
-
}
|
|
54
34
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
35
|
+
/** 注册接口动作处理程序 */
|
|
36
|
+
async registerHttpHandlers() {
|
|
37
|
+
for (const plugin of this.#plugins) {
|
|
38
|
+
if (plugin.registerHttpHandlers) {
|
|
39
|
+
await plugin.registerHttpHandlers(this.#server);
|
|
40
|
+
}
|
|
60
41
|
}
|
|
61
42
|
}
|
|
62
|
-
}
|
|
63
43
|
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
44
|
+
/** 注册事件处理程序 */
|
|
45
|
+
async registerEventHandlers() {
|
|
46
|
+
for (const plugin of this.#plugins) {
|
|
47
|
+
if (plugin.registerEventHandlers) {
|
|
48
|
+
await plugin.registerEventHandlers(this.#server);
|
|
49
|
+
}
|
|
69
50
|
}
|
|
70
51
|
}
|
|
71
|
-
}
|
|
72
52
|
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
if (plugin.onLoadingApplication) {
|
|
80
|
-
await plugin.onLoadingApplication(server, applicationConfig);
|
|
53
|
+
/** 注册消息处理程序 */
|
|
54
|
+
async registerMessageHandlers() {
|
|
55
|
+
for (const plugin of this.#plugins) {
|
|
56
|
+
if (plugin.registerMessageHandlers) {
|
|
57
|
+
await plugin.registerMessageHandlers(this.#server);
|
|
58
|
+
}
|
|
81
59
|
}
|
|
82
60
|
}
|
|
83
|
-
}
|
|
84
61
|
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
if (plugin.configureModels) {
|
|
92
|
-
await plugin.configureModels(server, applicationConfig);
|
|
62
|
+
/** 注册任务处理程序 */
|
|
63
|
+
async registerTaskProcessors() {
|
|
64
|
+
for (const plugin of this.#plugins) {
|
|
65
|
+
if (plugin.registerTaskProcessors) {
|
|
66
|
+
await plugin.registerTaskProcessors(this.#server);
|
|
67
|
+
}
|
|
93
68
|
}
|
|
94
69
|
}
|
|
95
|
-
}
|
|
96
70
|
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
71
|
+
/** 在加载应用前调用。 */
|
|
72
|
+
async onLoadingApplication(
|
|
73
|
+
server: IRpdServer,
|
|
74
|
+
applicationConfig: RpdApplicationConfig,
|
|
75
|
+
) {
|
|
76
|
+
for (const plugin of this.#plugins) {
|
|
77
|
+
if (plugin.onLoadingApplication) {
|
|
78
|
+
await plugin.onLoadingApplication(server, applicationConfig);
|
|
79
|
+
}
|
|
105
80
|
}
|
|
106
81
|
}
|
|
107
|
-
}
|
|
108
82
|
|
|
109
|
-
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
83
|
+
/** 配置数据模型 */
|
|
84
|
+
async configureModels(
|
|
85
|
+
server: IRpdServer,
|
|
86
|
+
applicationConfig: RpdApplicationConfig,
|
|
87
|
+
) {
|
|
88
|
+
for (const plugin of this.#plugins) {
|
|
89
|
+
if (plugin.configureModels) {
|
|
90
|
+
await plugin.configureModels(server, applicationConfig);
|
|
91
|
+
}
|
|
117
92
|
}
|
|
118
93
|
}
|
|
119
|
-
}
|
|
120
94
|
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
95
|
+
/** 配置模型属性 */
|
|
96
|
+
async configureModelProperties(
|
|
97
|
+
server: IRpdServer,
|
|
98
|
+
applicationConfig: RpdApplicationConfig,
|
|
99
|
+
) {
|
|
100
|
+
for (const plugin of this.#plugins) {
|
|
101
|
+
if (plugin.configureModelProperties) {
|
|
102
|
+
await plugin.configureModelProperties(server, applicationConfig);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** 配置路由 */
|
|
108
|
+
async configureRoutes(
|
|
109
|
+
server: IRpdServer,
|
|
110
|
+
applicationConfig: RpdApplicationConfig,
|
|
111
|
+
) {
|
|
112
|
+
for (const plugin of this.#plugins) {
|
|
113
|
+
if (plugin.configureRoutes) {
|
|
114
|
+
await plugin.configureRoutes(server, applicationConfig);
|
|
115
|
+
}
|
|
129
116
|
}
|
|
130
117
|
}
|
|
131
|
-
}
|
|
132
118
|
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
119
|
+
/** 在应用配置加载完成后调用。此时插件可以进行一些数据的初始化工作。 */
|
|
120
|
+
async onApplicationLoaded(
|
|
121
|
+
server: IRpdServer,
|
|
122
|
+
applicationConfig: RpdApplicationConfig,
|
|
123
|
+
) {
|
|
124
|
+
for (const plugin of this.#plugins) {
|
|
125
|
+
if (plugin.onApplicationLoaded) {
|
|
126
|
+
await plugin.onApplicationLoaded(server, applicationConfig);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** 在应用准备完成后调用。此时服务器已经可以处理网络请求。 */
|
|
132
|
+
async onApplicationReady(
|
|
133
|
+
server: IRpdServer,
|
|
134
|
+
applicationConfig: RpdApplicationConfig,
|
|
135
|
+
) {
|
|
136
|
+
for (const plugin of this.#plugins) {
|
|
137
|
+
if (plugin.onApplicationReady) {
|
|
138
|
+
await plugin.onApplicationReady(server, applicationConfig);
|
|
139
|
+
}
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
142
|
}
|
|
143
|
+
|
|
144
|
+
export default PluginManager;
|
package/src/core/request.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import qs from "qs";
|
|
2
|
+
import { parseFormDataBody } from "./http/formDataParser";
|
|
2
3
|
|
|
3
4
|
export const GlobalRequest = global.Request;
|
|
4
5
|
|
|
@@ -46,7 +47,7 @@ export class RapidRequest {
|
|
|
46
47
|
} else if (contentType.startsWith("multipart/form-data")) {
|
|
47
48
|
this.#body = {
|
|
48
49
|
type: "form-data",
|
|
49
|
-
value: await req
|
|
50
|
+
value: await parseFormDataBody(req),
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
} else {
|
package/src/core/routeContext.ts
CHANGED
|
@@ -47,15 +47,7 @@ export async function buildRoutes(
|
|
|
47
47
|
) {
|
|
48
48
|
const body = request.body;
|
|
49
49
|
if (body) {
|
|
50
|
-
|
|
51
|
-
const formDataReader = body.value;
|
|
52
|
-
const formDataBody = await formDataReader.read({ maxFileSize: 1073741824 /* 1GB */});
|
|
53
|
-
Object.assign(input, {
|
|
54
|
-
formData: formDataBody
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
Object.assign(input, body.value);
|
|
58
|
-
}
|
|
50
|
+
Object.assign(input, body.value);
|
|
59
51
|
}
|
|
60
52
|
}
|
|
61
53
|
|
|
@@ -84,12 +76,8 @@ export async function buildRoutes(
|
|
|
84
76
|
}
|
|
85
77
|
}
|
|
86
78
|
|
|
87
|
-
if (handlerContext.status) {
|
|
88
|
-
routerContext.status = handlerContext.status;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
79
|
if (!isNullOrUndefined(handlerContext.output)) {
|
|
92
|
-
routerContext.json(handlerContext.output);
|
|
80
|
+
routerContext.json(handlerContext.output, handlerContext.status);
|
|
93
81
|
}
|
|
94
82
|
},
|
|
95
83
|
);
|
package/src/core/server.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetDataAccessorOptions, GetModelOptions, IDatabaseConfig,
|
|
1
|
+
import { GetDataAccessorOptions, GetModelOptions, IDatabaseConfig, IQueryBuilder, IRpdDataAccessor, RapidServerConfig, RpdApplicationConfig, RpdDataModel, RpdServerEventTypes } from "~/types";
|
|
2
2
|
import { IPluginHttpHandler, HttpRequestHandler } from "./httpHandler";
|
|
3
3
|
import { Next } from "./routeContext";
|
|
4
4
|
|
|
@@ -16,7 +16,7 @@ export interface IRpdServer {
|
|
|
16
16
|
) => Promise<any[]>;
|
|
17
17
|
registerMiddleware(middleware: any): void;
|
|
18
18
|
registerHttpHandler(
|
|
19
|
-
plugin:
|
|
19
|
+
plugin: RapidPlugin,
|
|
20
20
|
options: IPluginHttpHandler,
|
|
21
21
|
): void;
|
|
22
22
|
getHttpHandlerByCode(code: string): HttpRequestHandler | undefined;
|
|
@@ -32,7 +32,7 @@ export interface IRpdServer {
|
|
|
32
32
|
): this;
|
|
33
33
|
emitEvent<K extends keyof RpdServerEventTypes>(
|
|
34
34
|
eventName: K,
|
|
35
|
-
sender:
|
|
35
|
+
sender: RapidPlugin,
|
|
36
36
|
payload: RpdServerEventTypes[K][1],
|
|
37
37
|
): void;
|
|
38
38
|
handleRequest(request: Request, next: Next): Promise<Response>;
|
|
@@ -88,58 +88,40 @@ export interface RpdServerPluginConfigurableTargetOptions {
|
|
|
88
88
|
configurations: RpdConfigurationItemOptions[];
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
export interface
|
|
91
|
+
export interface RapidPlugin {
|
|
92
92
|
/** 插件代码 */
|
|
93
|
-
code: string;
|
|
93
|
+
get code(): string;
|
|
94
94
|
/** 插件描述 */
|
|
95
|
-
description: string;
|
|
95
|
+
get description(): string;
|
|
96
96
|
/** 插件可以提供哪些扩展能力 */
|
|
97
|
-
extendingAbilities: RpdServerPluginExtendingAbilities[];
|
|
97
|
+
get extendingAbilities(): RpdServerPluginExtendingAbilities[];
|
|
98
98
|
/** 插件可以配置的目标实体,以及和配置目标相关的配置项 */
|
|
99
|
-
configurableTargets
|
|
99
|
+
get configurableTargets(): RpdServerPluginConfigurableTargetOptions[];
|
|
100
100
|
/** 插件的全局配置项 */
|
|
101
|
-
configurations
|
|
101
|
+
get configurations(): RpdConfigurationItemOptions[];
|
|
102
102
|
/** 初始化插件时调用。插件可以在此时进行一些内部对象的初始化工作。 */
|
|
103
|
-
initPlugin
|
|
103
|
+
initPlugin(server: IRpdServer): Promise<any>;
|
|
104
104
|
/** 注册中间件 */
|
|
105
|
-
registerMiddlewares
|
|
105
|
+
registerMiddlewares(server: IRpdServer): Promise<any>;
|
|
106
106
|
/** 注册接口动作处理程序 */
|
|
107
|
-
registerHttpHandlers
|
|
107
|
+
registerHttpHandlers(server: IRpdServer): Promise<any>;
|
|
108
108
|
/** 注册事件处理程序 */
|
|
109
|
-
registerEventHandlers
|
|
109
|
+
registerEventHandlers(server: IRpdServer): Promise<any>;
|
|
110
110
|
/** 注册消息处理程序 */
|
|
111
|
-
registerMessageHandlers
|
|
111
|
+
registerMessageHandlers(server: IRpdServer): Promise<any>;
|
|
112
112
|
/** 注册任务处理程序 */
|
|
113
|
-
registerTaskProcessors
|
|
113
|
+
registerTaskProcessors(server: IRpdServer): Promise<any>;
|
|
114
114
|
/** 在加载应用前调用。 */
|
|
115
|
-
onLoadingApplication
|
|
116
|
-
server: IRpdServer,
|
|
117
|
-
applicationConfig: RpdApplicationConfig,
|
|
118
|
-
) => Promise<any>;
|
|
115
|
+
onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
119
116
|
/** 配置数据集合 */
|
|
120
|
-
configureModels
|
|
121
|
-
server: IRpdServer,
|
|
122
|
-
applicationConfig: RpdApplicationConfig,
|
|
123
|
-
) => Promise<any>;
|
|
117
|
+
configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
124
118
|
/** 配置模型属性 */
|
|
125
|
-
configureModelProperties
|
|
126
|
-
server: IRpdServer,
|
|
127
|
-
applicationConfig: RpdApplicationConfig,
|
|
128
|
-
) => Promise<any>;
|
|
119
|
+
configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
129
120
|
/** 配置路由 */
|
|
130
|
-
configureRoutes
|
|
131
|
-
server: IRpdServer,
|
|
132
|
-
applicationConfig: RpdApplicationConfig,
|
|
133
|
-
) => Promise<any>;
|
|
121
|
+
configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
134
122
|
/** 在应用配置加载完成后调用。此时插件可以进行一些数据的初始化工作。 */
|
|
135
|
-
onApplicationLoaded
|
|
136
|
-
server: IRpdServer,
|
|
137
|
-
applicationConfig: RpdApplicationConfig,
|
|
138
|
-
) => Promise<any>;
|
|
123
|
+
onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
139
124
|
/** 在应用准备完成后调用。此时服务器已经可以处理网络请求,可以对外广播消息。 */
|
|
140
|
-
onApplicationReady
|
|
141
|
-
server: IRpdServer,
|
|
142
|
-
applicationConfig: RpdApplicationConfig,
|
|
143
|
-
) => Promise<any>;
|
|
125
|
+
onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
144
126
|
}
|
|
145
127
|
|
|
@@ -56,7 +56,7 @@ export default class DataAccessor<T = any> implements IRpdDataAccessor<T> {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
async find(options: FindEntityOptions): Promise<T[]> {
|
|
59
|
-
console.debug(
|
|
59
|
+
console.debug(`DataAccessor '${this.#model.singularCode}' find with options:`, options);
|
|
60
60
|
const query = this.#queryBuilder.select(this.#model, options);
|
|
61
61
|
return await this.#databaseAccessor.queryDatabaseObject(query.command, query.params);
|
|
62
62
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,3 +11,10 @@ export * from "./core/server";
|
|
|
11
11
|
export * from "./utilities/jwtUtility";
|
|
12
12
|
|
|
13
13
|
export * as bootstrapApplicationConfig from "./bootstrapApplicationConfig";
|
|
14
|
+
|
|
15
|
+
export { default as MetaManagePlugin } from "./plugins/metaManage/mod";
|
|
16
|
+
export { default as DataManagePlugin } from "./plugins/dataManage/mod";
|
|
17
|
+
export { default as RouteManagePlugin } from "./plugins/routeManage/mod";
|
|
18
|
+
export { default as WebhooksPlugin } from "./plugins/webhooks/mod";
|
|
19
|
+
export { default as AuthPlugin } from "./plugins/auth/mod";
|
|
20
|
+
export { default as FileManagePlugin } from "./plugins/fileManage/mod";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IPluginInstance } from "~/types";
|
|
2
1
|
import { setCookie } from "~/deno-std/http/cookie";
|
|
3
2
|
import { createJwt } from "~/utilities/jwtUtility";
|
|
4
3
|
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
4
|
+
import { RapidPlugin } from "~/core/server";
|
|
5
5
|
|
|
6
6
|
export interface UserAccessToken {
|
|
7
7
|
sub: "userAccessToken",
|
|
@@ -11,7 +11,7 @@ export interface UserAccessToken {
|
|
|
11
11
|
export const code = "createSession";
|
|
12
12
|
|
|
13
13
|
export async function handler(
|
|
14
|
-
plugin:
|
|
14
|
+
plugin: RapidPlugin,
|
|
15
15
|
ctx: HttpHandlerContext,
|
|
16
16
|
options: any,
|
|
17
17
|
) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
2
|
+
import { RapidPlugin } from "~/core/server";
|
|
2
3
|
import { setCookie } from "~/deno-std/http/cookie";
|
|
3
|
-
import { IPluginInstance } from "~/types";
|
|
4
4
|
|
|
5
5
|
export const code = "deleteSession";
|
|
6
6
|
|
|
7
7
|
export async function handler(
|
|
8
|
-
plugin:
|
|
8
|
+
plugin: RapidPlugin,
|
|
9
9
|
ctx: HttpHandlerContext,
|
|
10
10
|
options: any,
|
|
11
11
|
) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { IPluginInstance } from "~/types";
|
|
2
1
|
import { findEntity } from "~/dataAccess/entityManager";
|
|
3
2
|
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
+
import { RapidPlugin } from "~/core/server";
|
|
4
4
|
|
|
5
5
|
export const code = "getMyProfile";
|
|
6
6
|
|
|
7
7
|
export async function handler(
|
|
8
|
-
plugin:
|
|
8
|
+
plugin: RapidPlugin,
|
|
9
9
|
ctx: HttpHandlerContext,
|
|
10
10
|
options: any,
|
|
11
11
|
) {
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth manager plugin
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as _ from "lodash";
|
|
6
|
+
import {
|
|
7
|
+
RpdApplicationConfig,
|
|
8
|
+
} from "~/types";
|
|
9
|
+
import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
|
|
10
|
+
|
|
11
|
+
import pluginHttpHandlers from "./httpHandlers";
|
|
12
|
+
import pluginModels from "./models";
|
|
13
|
+
import pluginRoutes from "./routes";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AuthManager implements RapidPlugin {
|
|
17
|
+
get code(): string {
|
|
18
|
+
return "authManager";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get description(): string {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get extendingAbilities(): RpdServerPluginExtendingAbilities[] {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get configurableTargets(): RpdServerPluginConfigurableTargetOptions[] {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get configurations(): RpdConfigurationItemOptions[] {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async initPlugin(server: IRpdServer): Promise<any> {
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async registerMiddlewares(server: IRpdServer): Promise<any> {
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async registerHttpHandlers(server: IRpdServer): Promise<any> {
|
|
44
|
+
for (const httpHandler of pluginHttpHandlers) {
|
|
45
|
+
server.registerHttpHandler(this, httpHandler);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async registerMessageHandlers(server: IRpdServer): Promise<any> {
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async registerTaskProcessors(server: IRpdServer): Promise<any> {
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
62
|
+
server.appendApplicationConfig({ models: pluginModels });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
69
|
+
server.appendApplicationConfig({ routes: pluginRoutes });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
73
|
+
console.log("authManager.onApplicationLoaded");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default AuthManager;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RunEntityHttpHandlerOptions } from "~/types";
|
|
2
2
|
import { mergeInput } from "~/helpers/inputHelper";
|
|
3
3
|
import { isRelationProperty } from "~/utilities/rapidUtility";
|
|
4
4
|
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
5
|
+
import { RapidPlugin } from "~/core/server";
|
|
5
6
|
|
|
6
7
|
export const code = "addEntityRelations";
|
|
7
8
|
|
|
@@ -12,7 +13,7 @@ interface AddEntityRelationsInput {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export async function handler(
|
|
15
|
-
plugin:
|
|
16
|
+
plugin: RapidPlugin,
|
|
16
17
|
ctx: HttpHandlerContext,
|
|
17
18
|
options: RunEntityHttpHandlerOptions,
|
|
18
19
|
) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RunEntityHttpHandlerOptions } from "~/types";
|
|
2
2
|
import runCollectionEntityHttpHandler from "~/helpers/runCollectionEntityHttpHandler";
|
|
3
3
|
import { removeFiltersWithNullValue } from "~/dataAccess/filterHelper";
|
|
4
4
|
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
5
|
+
import { RapidPlugin } from "~/core/server";
|
|
5
6
|
|
|
6
7
|
export const code = "countCollectionEntities";
|
|
7
8
|
|
|
8
9
|
export async function handler(
|
|
9
|
-
plugin:
|
|
10
|
+
plugin: RapidPlugin,
|
|
10
11
|
ctx: HttpHandlerContext,
|
|
11
12
|
options: RunEntityHttpHandlerOptions,
|
|
12
13
|
) {
|
package/src/plugins/{dataManager → dataManage}/httpHandlers/createCollectionEntitiesBatch.ts
RENAMED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RunEntityHttpHandlerOptions } from "~/types";
|
|
2
2
|
import { mergeInput } from "~/helpers/inputHelper";
|
|
3
3
|
import { createEntity } from "~/dataAccess/entityManager";
|
|
4
4
|
import { isArray } from "lodash";
|
|
5
5
|
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
6
|
+
import { RapidPlugin } from "~/core/server";
|
|
6
7
|
|
|
7
8
|
export const code = "createCollectionEntitiesBatch";
|
|
8
9
|
|
|
9
10
|
export async function handler(
|
|
10
|
-
plugin:
|
|
11
|
+
plugin: RapidPlugin,
|
|
11
12
|
ctx: HttpHandlerContext,
|
|
12
13
|
options: RunEntityHttpHandlerOptions,
|
|
13
14
|
) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RunEntityHttpHandlerOptions } from "~/types";
|
|
2
2
|
import { mergeInput } from "~/helpers/inputHelper";
|
|
3
3
|
import { createEntity } from "~/dataAccess/entityManager";
|
|
4
4
|
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
5
|
+
import { RapidPlugin } from "~/core/server";
|
|
5
6
|
|
|
6
7
|
export const code = "createCollectionEntity";
|
|
7
8
|
|
|
8
9
|
export async function handler(
|
|
9
|
-
plugin:
|
|
10
|
+
plugin: RapidPlugin,
|
|
10
11
|
ctx: HttpHandlerContext,
|
|
11
12
|
options: RunEntityHttpHandlerOptions,
|
|
12
13
|
) {
|