@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
package/src/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RapidPlugin } from "./core/server";
|
|
2
|
+
|
|
1
3
|
export type RapidServerConfig = {
|
|
2
4
|
baseUrl?: string;
|
|
3
5
|
sessionCookieName: string;
|
|
@@ -60,11 +62,11 @@ export interface GetModelOptions {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
export type RpdServerEventTypes = {
|
|
63
|
-
"entity.create": [
|
|
64
|
-
"entity.update": [
|
|
65
|
-
"entity.delete": [
|
|
66
|
-
"entity.addRelations": [
|
|
67
|
-
"entity.removeRelations": [
|
|
65
|
+
"entity.create": [RapidPlugin, RpdEntityCreateEventPayload];
|
|
66
|
+
"entity.update": [RapidPlugin, RpdEntityUpdateEventPayload];
|
|
67
|
+
"entity.delete": [RapidPlugin, RpdEntityDeleteEventPayload];
|
|
68
|
+
"entity.addRelations": [RapidPlugin, RpdEntityAddRelationsEventPayload];
|
|
69
|
+
"entity.removeRelations": [RapidPlugin, RpdEntityRemoveRelationsEventPayload];
|
|
68
70
|
};
|
|
69
71
|
|
|
70
72
|
export interface RpdEntityCreateEventPayload {
|
|
@@ -284,13 +286,8 @@ export interface RpdDataModelExtension {
|
|
|
284
286
|
config: any;
|
|
285
287
|
}
|
|
286
288
|
|
|
287
|
-
|
|
288
|
-
export interface IPluginInstance {
|
|
289
|
-
getName(): string;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
289
|
export type EventHandler<T = any> = (
|
|
293
|
-
sender:
|
|
290
|
+
sender: RapidPlugin,
|
|
294
291
|
payload: T,
|
|
295
292
|
) => void;
|
|
296
293
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
|
|
3
|
+
export async function readFile(path: string): Promise<Buffer> {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
fs.readFile(path, null, (err, data) => {
|
|
6
|
+
if (err) {
|
|
7
|
+
reject(err);
|
|
8
|
+
} else {
|
|
9
|
+
resolve(data);
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function copyFile(fromPath: string, toPath: string): Promise<void> {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
fs.copyFile(fromPath, toPath, (err) => {
|
|
18
|
+
if (err) {
|
|
19
|
+
reject(err);
|
|
20
|
+
} else {
|
|
21
|
+
resolve();
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function removeFile(path: string): Promise<void> {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
fs.rm(path, (err) => {
|
|
30
|
+
if (err) {
|
|
31
|
+
reject(err);
|
|
32
|
+
} else {
|
|
33
|
+
resolve();
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function moveFile(fromPath: string, toPath: string): Promise<void> {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
fs.rename(fromPath, toPath, (err) => {
|
|
42
|
+
if (err) {
|
|
43
|
+
reject(err);
|
|
44
|
+
} else {
|
|
45
|
+
resolve();
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function appendFile(path: string, data: ArrayBuffer): Promise<void> {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
fs.appendFile(path, Buffer.from(data), (err) => {
|
|
54
|
+
if (err) {
|
|
55
|
+
reject(err);
|
|
56
|
+
} else {
|
|
57
|
+
resolve();
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
}
|
package/dist/core/plugin.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meta manager plugin
|
|
3
|
-
*/
|
|
4
|
-
import { IPluginInstance, RpdApplicationConfig } from "~/types";
|
|
5
|
-
import { IRpdServer, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
|
|
6
|
-
export declare const code = "authManager";
|
|
7
|
-
export declare const description = "authManager";
|
|
8
|
-
export declare const extendingAbilities: RpdServerPluginExtendingAbilities[];
|
|
9
|
-
export declare const configurableTargets: RpdServerPluginConfigurableTargetOptions[];
|
|
10
|
-
export declare const configurations: RpdConfigurationItemOptions[];
|
|
11
|
-
export declare function initPlugin(plugin: IPluginInstance, server: IRpdServer): Promise<void>;
|
|
12
|
-
export declare function registerHttpHandlers(server: IRpdServer): Promise<void>;
|
|
13
|
-
export declare function registerEventHandlers(server: IRpdServer): Promise<void>;
|
|
14
|
-
export declare function configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<void>;
|
|
15
|
-
export declare function configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<void>;
|
|
16
|
-
export declare function onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "addEntityRelations";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunEntityHttpHandlerOptions): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "countCollectionEntities";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunEntityHttpHandlerOptions): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "createCollectionEntitiesBatch";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunEntityHttpHandlerOptions): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "createCollectionEntity";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunEntityHttpHandlerOptions): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "deleteCollectionEntityById";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunEntityHttpHandlerOptions): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "findCollectionEntities";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunEntityHttpHandlerOptions): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "findCollectionEntityById";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunEntityHttpHandlerOptions): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunQueryDatabaseHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "queryDatabase";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunQueryDatabaseHandlerOptions): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "removeEntityRelations";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunEntityHttpHandlerOptions): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "updateCollectionEntityById";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunEntityHttpHandlerOptions): Promise<void>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Support manage data in database.
|
|
3
|
-
* This plugin provide:
|
|
4
|
-
* - routes for manage data in database.
|
|
5
|
-
*/
|
|
6
|
-
import { IPluginInstance, RpdApplicationConfig } from "~/types";
|
|
7
|
-
import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer } from "~/core/server";
|
|
8
|
-
export declare const code = "dataManager";
|
|
9
|
-
export declare const description = "\u5BF9\u6570\u636E\u8FDB\u884C\u7BA1\u7406\uFF0C\u63D0\u4F9B\u589E\u5220\u6539\u67E5\u7B49\u63A5\u53E3\u3002";
|
|
10
|
-
export declare const extendingAbilities: RpdServerPluginExtendingAbilities[];
|
|
11
|
-
export declare const configurableTargets: RpdServerPluginConfigurableTargetOptions[];
|
|
12
|
-
export declare const configurations: RpdConfigurationItemOptions[];
|
|
13
|
-
export declare function initPlugin(plugin: IPluginInstance, server: IRpdServer): Promise<void>;
|
|
14
|
-
export declare function registerHttpHandlers(server: IRpdServer): Promise<void>;
|
|
15
|
-
export declare function configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<void>;
|
|
16
|
-
export declare function onApplicationLoaded(server: IRpdServer, application: RpdApplicationConfig): Promise<void>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meta manager plugin
|
|
3
|
-
*/
|
|
4
|
-
import { IPluginInstance, RpdApplicationConfig } from "~/types";
|
|
5
|
-
import { IRpdServer, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
|
|
6
|
-
export declare const code = "metaManager";
|
|
7
|
-
export declare const description = "metaManager";
|
|
8
|
-
export declare const extendingAbilities: RpdServerPluginExtendingAbilities[];
|
|
9
|
-
export declare const configurableTargets: RpdServerPluginConfigurableTargetOptions[];
|
|
10
|
-
export declare const configurations: RpdConfigurationItemOptions[];
|
|
11
|
-
export declare function initPlugin(plugin: IPluginInstance, server: IRpdServer): Promise<void>;
|
|
12
|
-
export declare function registerHttpHandlers(server: IRpdServer): Promise<void>;
|
|
13
|
-
export declare function registerEventHandlers(server: IRpdServer): Promise<void>;
|
|
14
|
-
export declare function configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<void>;
|
|
15
|
-
export declare function onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<void>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IPluginInstance, RunProxyHandlerOptions } from "~/types";
|
|
2
|
-
import { HttpHandlerContext } from "~/core/httpHandler";
|
|
3
|
-
export declare const code = "httpProxy";
|
|
4
|
-
export declare function handler(plugin: IPluginInstance, ctx: HttpHandlerContext, options: RunProxyHandlerOptions): Promise<void>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route manager plugin
|
|
3
|
-
*/
|
|
4
|
-
import { IPluginInstance, RpdApplicationConfig } from "~/types";
|
|
5
|
-
import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer } from "~/core/server";
|
|
6
|
-
export declare const code = "routeManager";
|
|
7
|
-
export declare const description = "routeManager";
|
|
8
|
-
export declare const extendingAbilities: RpdServerPluginExtendingAbilities[];
|
|
9
|
-
export declare const configurableTargets: RpdServerPluginConfigurableTargetOptions[];
|
|
10
|
-
export declare const configurations: RpdConfigurationItemOptions[];
|
|
11
|
-
export declare function initPlugin(plugin: IPluginInstance, server: IRpdServer): Promise<void>;
|
|
12
|
-
export declare function registerMiddlewares(server: IRpdServer): Promise<void>;
|
|
13
|
-
export declare function registerHttpHandlers(server: IRpdServer): Promise<void>;
|
|
14
|
-
export declare function configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<void>;
|
|
15
|
-
export declare function onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<void>;
|
package/src/core/plugin.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meta manager plugin
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as _ from "lodash";
|
|
6
|
-
import {
|
|
7
|
-
IPluginInstance,
|
|
8
|
-
RpdApplicationConfig,
|
|
9
|
-
} from "~/types";
|
|
10
|
-
import { IRpdServer, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
|
|
11
|
-
|
|
12
|
-
import pluginHttpHandlers from "./httpHandlers";
|
|
13
|
-
import pluginModels from "./models";
|
|
14
|
-
import pluginRoutes from "./routes";
|
|
15
|
-
|
|
16
|
-
export const code = "authManager";
|
|
17
|
-
export const description = "authManager";
|
|
18
|
-
export const extendingAbilities: RpdServerPluginExtendingAbilities[] = [];
|
|
19
|
-
export const configurableTargets: RpdServerPluginConfigurableTargetOptions[] = [];
|
|
20
|
-
export const configurations: RpdConfigurationItemOptions[] = [];
|
|
21
|
-
|
|
22
|
-
let _plugin: IPluginInstance;
|
|
23
|
-
|
|
24
|
-
export async function initPlugin(plugin: IPluginInstance, server: IRpdServer) {
|
|
25
|
-
_plugin = plugin;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function registerHttpHandlers(server: IRpdServer) {
|
|
29
|
-
for (const httpHandler of pluginHttpHandlers) {
|
|
30
|
-
server.registerHttpHandler(_plugin, httpHandler);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function registerEventHandlers(server: IRpdServer) {
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function configureModels(
|
|
38
|
-
server: IRpdServer,
|
|
39
|
-
applicationConfig: RpdApplicationConfig,
|
|
40
|
-
) {
|
|
41
|
-
server.appendApplicationConfig({ models: pluginModels });
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function configureRoutes(
|
|
45
|
-
server: IRpdServer,
|
|
46
|
-
applicationConfig: RpdApplicationConfig,
|
|
47
|
-
) {
|
|
48
|
-
server.appendApplicationConfig({ routes: pluginRoutes });
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export async function onApplicationLoaded(
|
|
52
|
-
server: IRpdServer,
|
|
53
|
-
applicationConfig: RpdApplicationConfig,
|
|
54
|
-
) {
|
|
55
|
-
console.log("authManager.onApplicationLoaded");
|
|
56
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Support manage data in database.
|
|
3
|
-
* This plugin provide:
|
|
4
|
-
* - routes for manage data in database.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as _ from "lodash";
|
|
8
|
-
import {
|
|
9
|
-
IPluginInstance,
|
|
10
|
-
RpdApplicationConfig,
|
|
11
|
-
RpdHttpMethod,
|
|
12
|
-
RpdRoute,
|
|
13
|
-
RunEntityHttpHandlerOptions,
|
|
14
|
-
} from "~/types";
|
|
15
|
-
|
|
16
|
-
import * as findCollectionEntitiesHttpHandler from "./httpHandlers/findCollectionEntities";
|
|
17
|
-
import * as findCollectionEntityById from "./httpHandlers/findCollectionEntityById";
|
|
18
|
-
import * as countCollectionEntities from "./httpHandlers/countCollectionEntities";
|
|
19
|
-
import * as createCollectionEntity from "./httpHandlers/createCollectionEntity";
|
|
20
|
-
import * as createCollectionEntitiesBatch from "./httpHandlers/createCollectionEntitiesBatch";
|
|
21
|
-
import * as updateCollectionEntityById from "./httpHandlers/updateCollectionEntityById";
|
|
22
|
-
import * as deleteCollectionEntityById from "./httpHandlers/deleteCollectionEntityById";
|
|
23
|
-
import * as addEntityRelations from "./httpHandlers/addEntityRelations";
|
|
24
|
-
import * as removeEntityRelations from "./httpHandlers/removeEntityRelations";
|
|
25
|
-
import * as queryDatabase from "./httpHandlers/queryDatabase";
|
|
26
|
-
import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer } from "~/core/server";
|
|
27
|
-
|
|
28
|
-
export const code = "dataManager";
|
|
29
|
-
export const description = "对数据进行管理,提供增删改查等接口。";
|
|
30
|
-
export const extendingAbilities: RpdServerPluginExtendingAbilities[] = [];
|
|
31
|
-
export const configurableTargets: RpdServerPluginConfigurableTargetOptions[] = [];
|
|
32
|
-
export const configurations: RpdConfigurationItemOptions[] = [];
|
|
33
|
-
|
|
34
|
-
const routeConfigs: {
|
|
35
|
-
code: string;
|
|
36
|
-
method: RpdHttpMethod;
|
|
37
|
-
endpoint: string;
|
|
38
|
-
handlerCode: string;
|
|
39
|
-
}[] = [
|
|
40
|
-
{
|
|
41
|
-
code: "createBatch",
|
|
42
|
-
method: "POST",
|
|
43
|
-
endpoint: "/operations/create_batch",
|
|
44
|
-
handlerCode: "createCollectionEntitiesBatch",
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
code: "find",
|
|
48
|
-
method: "POST",
|
|
49
|
-
endpoint: "/operations/find",
|
|
50
|
-
handlerCode: "findCollectionEntities",
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
code: "count",
|
|
54
|
-
method: "POST",
|
|
55
|
-
endpoint: "/operations/count",
|
|
56
|
-
handlerCode: "countCollectionEntities",
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
code: "addRelations",
|
|
60
|
-
method: "POST",
|
|
61
|
-
endpoint: "/operations/add_relations",
|
|
62
|
-
handlerCode: "addEntityRelations",
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
code: "removeRelations",
|
|
66
|
-
method: "POST",
|
|
67
|
-
endpoint: "/operations/remove_relations",
|
|
68
|
-
handlerCode: "removeEntityRelations",
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
code: "getById",
|
|
72
|
-
method: "GET",
|
|
73
|
-
endpoint: "/:id",
|
|
74
|
-
handlerCode: "findCollectionEntityById",
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
code: "create",
|
|
78
|
-
method: "POST",
|
|
79
|
-
endpoint: "",
|
|
80
|
-
handlerCode: "createCollectionEntity",
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
code: "updateById",
|
|
84
|
-
method: "PATCH",
|
|
85
|
-
endpoint: "/:id",
|
|
86
|
-
handlerCode: "updateCollectionEntityById",
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
code: "deleteById",
|
|
90
|
-
method: "DELETE",
|
|
91
|
-
endpoint: "/:id",
|
|
92
|
-
handlerCode: "deleteCollectionEntityById",
|
|
93
|
-
},
|
|
94
|
-
];
|
|
95
|
-
|
|
96
|
-
let _plugin: IPluginInstance;
|
|
97
|
-
|
|
98
|
-
export async function initPlugin(plugin: IPluginInstance, server: IRpdServer) {
|
|
99
|
-
_plugin = plugin;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export async function registerHttpHandlers(server: IRpdServer) {
|
|
103
|
-
server.registerHttpHandler(_plugin, findCollectionEntitiesHttpHandler);
|
|
104
|
-
server.registerHttpHandler(_plugin, findCollectionEntityById);
|
|
105
|
-
server.registerHttpHandler(_plugin, countCollectionEntities);
|
|
106
|
-
server.registerHttpHandler(_plugin, createCollectionEntity);
|
|
107
|
-
server.registerHttpHandler(_plugin, createCollectionEntitiesBatch);
|
|
108
|
-
server.registerHttpHandler(_plugin, updateCollectionEntityById);
|
|
109
|
-
server.registerHttpHandler(_plugin, addEntityRelations);
|
|
110
|
-
server.registerHttpHandler(_plugin, removeEntityRelations);
|
|
111
|
-
server.registerHttpHandler(_plugin, deleteCollectionEntityById);
|
|
112
|
-
server.registerHttpHandler(_plugin, queryDatabase);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export async function configureRoutes(
|
|
116
|
-
server: IRpdServer,
|
|
117
|
-
applicationConfig: RpdApplicationConfig,
|
|
118
|
-
) {
|
|
119
|
-
const { models } = applicationConfig;
|
|
120
|
-
const routes: RpdRoute[] = [];
|
|
121
|
-
|
|
122
|
-
models.forEach((model) => {
|
|
123
|
-
const { namespace, singularCode, pluralCode } = model;
|
|
124
|
-
|
|
125
|
-
routeConfigs.forEach((routeConfig) => {
|
|
126
|
-
routes.push({
|
|
127
|
-
namespace,
|
|
128
|
-
name: `${namespace}.${singularCode}.${routeConfig.code}`,
|
|
129
|
-
code: `${namespace}.${singularCode}.${routeConfig.code}`,
|
|
130
|
-
type: "RESTful",
|
|
131
|
-
method: routeConfig.method,
|
|
132
|
-
endpoint: `/${namespace}/${pluralCode}${routeConfig.endpoint}`,
|
|
133
|
-
handlers: [
|
|
134
|
-
{
|
|
135
|
-
code: routeConfig.handlerCode,
|
|
136
|
-
config: {
|
|
137
|
-
namespace,
|
|
138
|
-
singularCode,
|
|
139
|
-
} as RunEntityHttpHandlerOptions,
|
|
140
|
-
},
|
|
141
|
-
],
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
server.appendApplicationConfig({ routes });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export async function onApplicationLoaded(
|
|
150
|
-
server: IRpdServer,
|
|
151
|
-
application: RpdApplicationConfig,
|
|
152
|
-
) {
|
|
153
|
-
console.log("[dataManager.onApplicationLoaded]");
|
|
154
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route manager plugin
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
IPluginInstance,
|
|
7
|
-
RpdApplicationConfig,
|
|
8
|
-
} from "~/types";
|
|
9
|
-
import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer } from "~/core/server";
|
|
10
|
-
import { findEntities } from "../../dataAccess/entityManager";
|
|
11
|
-
import * as httpProxy from "./httpHandlers/httpProxy";
|
|
12
|
-
import * as listMetaRoutes from "./httpHandlers/listMetaRoutes";
|
|
13
|
-
import { buildRoutes } from "~/core/routesBuilder";
|
|
14
|
-
|
|
15
|
-
export const code = "routeManager";
|
|
16
|
-
export const description = "routeManager";
|
|
17
|
-
export const extendingAbilities: RpdServerPluginExtendingAbilities[] = [];
|
|
18
|
-
export const configurableTargets: RpdServerPluginConfigurableTargetOptions[] = [];
|
|
19
|
-
export const configurations: RpdConfigurationItemOptions[] = [];
|
|
20
|
-
|
|
21
|
-
let _plugin: IPluginInstance;
|
|
22
|
-
|
|
23
|
-
export async function initPlugin(plugin: IPluginInstance, server: IRpdServer) {
|
|
24
|
-
_plugin = plugin;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let routes: any;
|
|
28
|
-
|
|
29
|
-
async function routeHandler(ctx: any, next: any) {
|
|
30
|
-
if (routes) {
|
|
31
|
-
await routes(ctx, next);
|
|
32
|
-
} else {
|
|
33
|
-
await next();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function registerMiddlewares(server: IRpdServer) {
|
|
38
|
-
// server.registerMiddleware(routeHandler);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// export async function registerEventHandlers(server: IRpdServer) {
|
|
42
|
-
// server.registerEventHandler("entity.create", handleEntityEvent.bind(null, server))
|
|
43
|
-
// server.registerEventHandler("entity.update", handleEntityEvent.bind(null, server))
|
|
44
|
-
// server.registerEventHandler("entity.delete", handleEntityEvent.bind(null, server))
|
|
45
|
-
// }
|
|
46
|
-
|
|
47
|
-
// async function handleEntityEvent(server: IRpdServer, sender: IPluginInstance, payload: RpdEntityCreateEventPayload | RpdEntityUpdateEventPayload | RpdEntityDeleteEventPayload) {
|
|
48
|
-
// if (sender === _plugin) {
|
|
49
|
-
// return;
|
|
50
|
-
// }
|
|
51
|
-
|
|
52
|
-
// if (payload.namespace === "meta" && payload.modelSingularCode === "route") {
|
|
53
|
-
// console.debug("Rebuilding routes...");
|
|
54
|
-
// routesRef.value = await buildRoutes(server, server.getApplicationConfig());
|
|
55
|
-
// }
|
|
56
|
-
// }
|
|
57
|
-
|
|
58
|
-
export async function registerHttpHandlers(server: IRpdServer) {
|
|
59
|
-
server.registerHttpHandler(_plugin, httpProxy);
|
|
60
|
-
server.registerHttpHandler(_plugin, listMetaRoutes);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export async function configureRoutes(
|
|
64
|
-
server: IRpdServer,
|
|
65
|
-
applicationConfig: RpdApplicationConfig,
|
|
66
|
-
) {
|
|
67
|
-
try {
|
|
68
|
-
const routes = await listRoutes(server, applicationConfig);
|
|
69
|
-
applicationConfig.routes.push(...routes);
|
|
70
|
-
} catch (ex) {
|
|
71
|
-
console.warn("Failed to loading existing meta of routes.", ex.message);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function listRoutes(
|
|
76
|
-
server: IRpdServer,
|
|
77
|
-
applicationConfig: RpdApplicationConfig,
|
|
78
|
-
) {
|
|
79
|
-
const dataAccessor = server.getDataAccessor({
|
|
80
|
-
namespace: "meta",
|
|
81
|
-
singularCode: "route",
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return findEntities(server, dataAccessor, {
|
|
85
|
-
orderBy: [
|
|
86
|
-
{ field: "endpoint" },
|
|
87
|
-
],
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function onApplicationLoaded(
|
|
92
|
-
server: IRpdServer,
|
|
93
|
-
applicationConfig: RpdApplicationConfig,
|
|
94
|
-
) {
|
|
95
|
-
console.log("[routeManager.onApplicationLoaded] build routes");
|
|
96
|
-
routes = await buildRoutes(server, applicationConfig);
|
|
97
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|