@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.
Files changed (116) hide show
  1. package/dist/core/http/formDataParser.d.ts +22 -0
  2. package/dist/core/httpHandler.d.ts +3 -3
  3. package/dist/core/pluginManager.d.ts +31 -26
  4. package/dist/core/providers/runtimeProvider.d.ts +4 -0
  5. package/dist/core/routeContext.d.ts +0 -1
  6. package/dist/core/server.d.ts +21 -21
  7. package/dist/index.d.ts +6 -0
  8. package/dist/index.js +3365 -3113
  9. package/dist/plugins/{authManager → auth}/httpHandlers/createSession.d.ts +2 -2
  10. package/dist/plugins/auth/httpHandlers/deleteSession.d.ts +4 -0
  11. package/dist/plugins/auth/httpHandlers/getMyProfile.d.ts +4 -0
  12. package/dist/plugins/auth/mod.d.ts +25 -0
  13. package/dist/plugins/dataManage/httpHandlers/addEntityRelations.d.ts +5 -0
  14. package/dist/plugins/dataManage/httpHandlers/countCollectionEntities.d.ts +5 -0
  15. package/dist/plugins/dataManage/httpHandlers/createCollectionEntitiesBatch.d.ts +5 -0
  16. package/dist/plugins/dataManage/httpHandlers/createCollectionEntity.d.ts +5 -0
  17. package/dist/plugins/dataManage/httpHandlers/deleteCollectionEntityById.d.ts +5 -0
  18. package/dist/plugins/dataManage/httpHandlers/findCollectionEntities.d.ts +5 -0
  19. package/dist/plugins/dataManage/httpHandlers/findCollectionEntityById.d.ts +5 -0
  20. package/dist/plugins/dataManage/httpHandlers/queryDatabase.d.ts +5 -0
  21. package/dist/plugins/dataManage/httpHandlers/removeEntityRelations.d.ts +5 -0
  22. package/dist/plugins/dataManage/httpHandlers/updateCollectionEntityById.d.ts +5 -0
  23. package/dist/plugins/dataManage/mod.d.ts +27 -0
  24. package/dist/plugins/fileManage/httpHandlers/downloadDocument.d.ts +4 -0
  25. package/dist/plugins/fileManage/httpHandlers/downloadFile.d.ts +4 -0
  26. package/dist/plugins/fileManage/httpHandlers/uploadFile.d.ts +4 -0
  27. package/dist/plugins/fileManage/mod.d.ts +25 -0
  28. package/dist/plugins/metaManage/httpHandlers/getMetaModelDetail.d.ts +4 -0
  29. package/dist/plugins/metaManage/httpHandlers/listMetaModels.d.ts +4 -0
  30. package/dist/plugins/metaManage/httpHandlers/listMetaRoutes.d.ts +4 -0
  31. package/dist/plugins/metaManage/mod.d.ts +25 -0
  32. package/dist/plugins/routeManage/httpHandlers/httpProxy.d.ts +5 -0
  33. package/dist/plugins/routeManage/mod.d.ts +25 -0
  34. package/dist/plugins/webhooks/mod.d.ts +25 -11
  35. package/dist/server.d.ts +5 -4
  36. package/dist/types.d.ts +7 -9
  37. package/dist/utilities/fsUtility.d.ts +6 -0
  38. package/package.json +3 -2
  39. package/src/core/http/formDataParser.ts +101 -0
  40. package/src/core/httpHandler.ts +3 -3
  41. package/src/core/pluginManager.ts +107 -106
  42. package/src/core/providers/runtimeProvider.ts +5 -0
  43. package/src/core/request.ts +2 -1
  44. package/src/core/routeContext.ts +0 -1
  45. package/src/core/routesBuilder.ts +2 -14
  46. package/src/core/server.ts +21 -39
  47. package/src/dataAccess/dataAccessor.ts +1 -1
  48. package/src/index.ts +7 -0
  49. package/src/plugins/{authManager → auth}/httpHandlers/createSession.ts +2 -2
  50. package/src/plugins/{authManager → auth}/httpHandlers/deleteSession.ts +2 -2
  51. package/src/plugins/{authManager → auth}/httpHandlers/getMyProfile.ts +2 -2
  52. package/src/plugins/auth/mod.ts +80 -0
  53. package/src/plugins/{dataManager → dataManage}/httpHandlers/addEntityRelations.ts +3 -2
  54. package/src/plugins/{dataManager → dataManage}/httpHandlers/countCollectionEntities.ts +3 -2
  55. package/src/plugins/{dataManager → dataManage}/httpHandlers/createCollectionEntitiesBatch.ts +3 -2
  56. package/src/plugins/{dataManager → dataManage}/httpHandlers/createCollectionEntity.ts +3 -2
  57. package/src/plugins/{dataManager → dataManage}/httpHandlers/deleteCollectionEntityById.ts +5 -4
  58. package/src/plugins/{dataManager → dataManage}/httpHandlers/findCollectionEntities.ts +3 -2
  59. package/src/plugins/{dataManager → dataManage}/httpHandlers/findCollectionEntityById.ts +3 -2
  60. package/src/plugins/{dataManager → dataManage}/httpHandlers/queryDatabase.ts +3 -2
  61. package/src/plugins/{dataManager → dataManage}/httpHandlers/removeEntityRelations.ts +3 -2
  62. package/src/plugins/{dataManager → dataManage}/httpHandlers/updateCollectionEntityById.ts +3 -2
  63. package/src/plugins/dataManage/mod.ts +187 -0
  64. package/src/plugins/fileManage/httpHandlers/downloadDocument.ts +40 -0
  65. package/src/plugins/fileManage/httpHandlers/downloadFile.ts +32 -0
  66. package/src/plugins/fileManage/httpHandlers/uploadFile.ts +37 -0
  67. package/src/plugins/fileManage/mod.ts +77 -0
  68. package/src/plugins/{metaManager → metaManage}/httpHandlers/getMetaModelDetail.ts +2 -2
  69. package/src/plugins/{metaManager → metaManage}/httpHandlers/listMetaModels.ts +2 -2
  70. package/src/plugins/{routeManager → metaManage}/httpHandlers/listMetaRoutes.ts +2 -2
  71. package/src/plugins/{metaManager → metaManage}/mod.ts +86 -53
  72. package/src/plugins/{routeManager → routeManage}/httpHandlers/httpProxy.ts +3 -2
  73. package/src/plugins/routeManage/mod.ts +92 -0
  74. package/src/plugins/webhooks/mod.ts +134 -94
  75. package/src/server.ts +19 -12
  76. package/src/types.ts +8 -11
  77. package/src/utilities/fsUtility.ts +62 -0
  78. package/dist/core/plugin.d.ts +0 -6
  79. package/dist/plugins/authManager/httpHandlers/deleteSession.d.ts +0 -4
  80. package/dist/plugins/authManager/httpHandlers/getMyProfile.d.ts +0 -4
  81. package/dist/plugins/authManager/mod.d.ts +0 -16
  82. package/dist/plugins/dataManager/httpHandlers/addEntityRelations.d.ts +0 -4
  83. package/dist/plugins/dataManager/httpHandlers/countCollectionEntities.d.ts +0 -4
  84. package/dist/plugins/dataManager/httpHandlers/createCollectionEntitiesBatch.d.ts +0 -4
  85. package/dist/plugins/dataManager/httpHandlers/createCollectionEntity.d.ts +0 -4
  86. package/dist/plugins/dataManager/httpHandlers/deleteCollectionEntityById.d.ts +0 -4
  87. package/dist/plugins/dataManager/httpHandlers/findCollectionEntities.d.ts +0 -4
  88. package/dist/plugins/dataManager/httpHandlers/findCollectionEntityById.d.ts +0 -4
  89. package/dist/plugins/dataManager/httpHandlers/queryDatabase.d.ts +0 -4
  90. package/dist/plugins/dataManager/httpHandlers/removeEntityRelations.d.ts +0 -4
  91. package/dist/plugins/dataManager/httpHandlers/updateCollectionEntityById.d.ts +0 -4
  92. package/dist/plugins/dataManager/mod.d.ts +0 -16
  93. package/dist/plugins/metaManager/httpHandlers/getMetaModelDetail.d.ts +0 -4
  94. package/dist/plugins/metaManager/httpHandlers/listMetaModels.d.ts +0 -4
  95. package/dist/plugins/metaManager/mod.d.ts +0 -15
  96. package/dist/plugins/routeManager/httpHandlers/httpProxy.d.ts +0 -4
  97. package/dist/plugins/routeManager/httpHandlers/listMetaRoutes.d.ts +0 -4
  98. package/dist/plugins/routeManager/mod.d.ts +0 -15
  99. package/src/core/plugin.ts +0 -13
  100. package/src/plugins/authManager/mod.ts +0 -56
  101. package/src/plugins/dataManager/mod.ts +0 -154
  102. package/src/plugins/routeManager/mod.ts +0 -97
  103. /package/dist/plugins/{authManager → auth}/httpHandlers/index.d.ts +0 -0
  104. /package/dist/plugins/{authManager → auth}/models/AccessToken.d.ts +0 -0
  105. /package/dist/plugins/{authManager → auth}/models/index.d.ts +0 -0
  106. /package/dist/plugins/{authManager → auth}/routes/getMyProfile.d.ts +0 -0
  107. /package/dist/plugins/{authManager → auth}/routes/index.d.ts +0 -0
  108. /package/dist/plugins/{authManager → auth}/routes/signin.d.ts +0 -0
  109. /package/dist/plugins/{authManager → auth}/routes/signout.d.ts +0 -0
  110. /package/src/plugins/{authManager → auth}/httpHandlers/index.ts +0 -0
  111. /package/src/plugins/{authManager → auth}/models/AccessToken.ts +0 -0
  112. /package/src/plugins/{authManager → auth}/models/index.ts +0 -0
  113. /package/src/plugins/{authManager → auth}/routes/getMyProfile.ts +0 -0
  114. /package/src/plugins/{authManager → auth}/routes/index.ts +0 -0
  115. /package/src/plugins/{authManager → auth}/routes/signin.ts +0 -0
  116. /package/src/plugins/{authManager → auth}/routes/signout.ts +0 -0
@@ -1,143 +1,144 @@
1
1
  import { RpdApplicationConfig } from "~/types";
2
- import Plugin from "./plugin";
3
- import * as metaManager from "~/plugins/metaManager/mod";
4
- import * as dataManager from "~/plugins/dataManager/mod";
5
- import * as routeManager from "~/plugins/routeManager/mod";
6
- import * as webhooks from "~/plugins/webhooks/mod";
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
- export async function initPlugins(server: IRpdServer) {
22
- for (const plugin of plugins) {
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
- export async function registerMiddlewares(server: IRpdServer) {
30
- for (const plugin of plugins) {
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
- export async function registerHttpHandlers(server: IRpdServer) {
39
- for (const plugin of plugins) {
40
- if (plugin.registerHttpHandlers) {
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
- export async function registerEventHandlers(server: IRpdServer) {
48
- for (const plugin of plugins) {
49
- if (plugin.registerEventHandlers) {
50
- await plugin.registerEventHandlers(server);
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
- export async function registerMessageHandlers(server: IRpdServer) {
57
- for (const plugin of plugins) {
58
- if (plugin.registerMessageHandlers) {
59
- await plugin.registerMessageHandlers(server);
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
- export async function registerTaskProcessors(server: IRpdServer) {
66
- for (const plugin of plugins) {
67
- if (plugin.registerTaskProcessors) {
68
- await plugin.registerTaskProcessors(server);
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
- export async function onLoadingApplication(
75
- server: IRpdServer,
76
- applicationConfig: RpdApplicationConfig,
77
- ) {
78
- for (const plugin of plugins) {
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
- export async function configureModels(
87
- server: IRpdServer,
88
- applicationConfig: RpdApplicationConfig,
89
- ) {
90
- for (const plugin of plugins) {
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
- export async function configureModelProperties(
99
- server: IRpdServer,
100
- applicationConfig: RpdApplicationConfig,
101
- ) {
102
- for (const plugin of plugins) {
103
- if (plugin.configureModelProperties) {
104
- await plugin.configureModelProperties(server, applicationConfig);
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
- export async function configureRoutes(
111
- server: IRpdServer,
112
- applicationConfig: RpdApplicationConfig,
113
- ) {
114
- for (const plugin of plugins) {
115
- if (plugin.configureRoutes) {
116
- await plugin.configureRoutes(server, applicationConfig);
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
- export async function onApplicationLoaded(
123
- server: IRpdServer,
124
- applicationConfig: RpdApplicationConfig,
125
- ) {
126
- for (const plugin of plugins) {
127
- if (plugin.onApplicationLoaded) {
128
- await plugin.onApplicationLoaded(server, applicationConfig);
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
- export async function onApplicationReady(
135
- server: IRpdServer,
136
- applicationConfig: RpdApplicationConfig,
137
- ) {
138
- for (const plugin of plugins) {
139
- if (plugin.onApplicationReady) {
140
- await plugin.onApplicationReady(server, applicationConfig);
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;
@@ -0,0 +1,5 @@
1
+ export interface IRuntimeProvider {
2
+ copyFile(fromPath: string, toPath: string): Promise<void>;
3
+
4
+ removeFile(path: string): Promise<void>;
5
+ }
@@ -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.formData(),
50
+ value: await parseFormDataBody(req),
50
51
  }
51
52
  }
52
53
  } else {
@@ -11,7 +11,6 @@ export class RouteContext {
11
11
  readonly state: Record<string, any>;
12
12
  method: string;
13
13
  path: string;
14
- status: HttpStatus;
15
14
  params: Record<string, string>;
16
15
 
17
16
  constructor(request: RapidRequest) {
@@ -47,15 +47,7 @@ export async function buildRoutes(
47
47
  ) {
48
48
  const body = request.body;
49
49
  if (body) {
50
- if (body.type === "form-data") {
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
  );
@@ -1,4 +1,4 @@
1
- import { GetDataAccessorOptions, GetModelOptions, IDatabaseConfig, IPluginInstance, IQueryBuilder, IRpdDataAccessor, RapidServerConfig, RpdApplicationConfig, RpdDataModel, RpdServerEventTypes } from "~/types";
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: IPluginInstance,
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: IPluginInstance,
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 IRpdServerPlugin {
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?: RpdServerPluginConfigurableTargetOptions[];
99
+ get configurableTargets(): RpdServerPluginConfigurableTargetOptions[];
100
100
  /** 插件的全局配置项 */
101
- configurations?: RpdConfigurationItemOptions[];
101
+ get configurations(): RpdConfigurationItemOptions[];
102
102
  /** 初始化插件时调用。插件可以在此时进行一些内部对象的初始化工作。 */
103
- initPlugin: (plugin: IPluginInstance, server: IRpdServer) => Promise<any>;
103
+ initPlugin(server: IRpdServer): Promise<any>;
104
104
  /** 注册中间件 */
105
- registerMiddlewares?: (server: IRpdServer) => Promise<any>;
105
+ registerMiddlewares(server: IRpdServer): Promise<any>;
106
106
  /** 注册接口动作处理程序 */
107
- registerHttpHandlers?: (server: IRpdServer) => Promise<any>;
107
+ registerHttpHandlers(server: IRpdServer): Promise<any>;
108
108
  /** 注册事件处理程序 */
109
- registerEventHandlers?: (server: IRpdServer) => Promise<any>;
109
+ registerEventHandlers(server: IRpdServer): Promise<any>;
110
110
  /** 注册消息处理程序 */
111
- registerMessageHandlers?: (server: IRpdServer) => Promise<any>;
111
+ registerMessageHandlers(server: IRpdServer): Promise<any>;
112
112
  /** 注册任务处理程序 */
113
- registerTaskProcessors?: (server: IRpdServer) => Promise<any>;
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("DataAccessor.find() with options:", options);
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: IPluginInstance,
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: IPluginInstance,
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: IPluginInstance,
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 { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
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: IPluginInstance,
16
+ plugin: RapidPlugin,
16
17
  ctx: HttpHandlerContext,
17
18
  options: RunEntityHttpHandlerOptions,
18
19
  ) {
@@ -1,12 +1,13 @@
1
- import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
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: IPluginInstance,
10
+ plugin: RapidPlugin,
10
11
  ctx: HttpHandlerContext,
11
12
  options: RunEntityHttpHandlerOptions,
12
13
  ) {
@@ -1,13 +1,14 @@
1
- import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
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: IPluginInstance,
11
+ plugin: RapidPlugin,
11
12
  ctx: HttpHandlerContext,
12
13
  options: RunEntityHttpHandlerOptions,
13
14
  ) {
@@ -1,12 +1,13 @@
1
- import { IPluginInstance, RunEntityHttpHandlerOptions } from "~/types";
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: IPluginInstance,
10
+ plugin: RapidPlugin,
10
11
  ctx: HttpHandlerContext,
11
12
  options: RunEntityHttpHandlerOptions,
12
13
  ) {