@ruiapp/rapid-core 0.11.6 → 0.11.7

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 (204) hide show
  1. package/CHANGELOG.md +11 -11
  2. package/dist/core/pluginManager.d.ts +2 -0
  3. package/dist/core/server.d.ts +3 -0
  4. package/dist/dataAccess/entityManager.d.ts +3 -3
  5. package/dist/index.js +102 -38
  6. package/dist/server.d.ts +1 -0
  7. package/dist/types.d.ts +2 -0
  8. package/package.json +1 -1
  9. package/rollup.config.js +16 -16
  10. package/src/bootstrapApplicationConfig.ts +904 -904
  11. package/src/core/ExpressionInterpreter.ts +45 -45
  12. package/src/core/actionHandler.ts +24 -24
  13. package/src/core/actionHandlers/ifActionHandler.ts +27 -27
  14. package/src/core/eventManager.ts +20 -20
  15. package/src/core/facility.ts +7 -7
  16. package/src/core/http/formDataParser.ts +87 -87
  17. package/src/core/http-types.ts +4 -4
  18. package/src/core/pluginManager.ts +202 -193
  19. package/src/core/providers/runtimeProvider.ts +5 -5
  20. package/src/core/request.ts +96 -96
  21. package/src/core/response.ts +84 -84
  22. package/src/core/routeContext.ts +127 -127
  23. package/src/core/routes/healthz.ts +20 -20
  24. package/src/core/routes/index.ts +3 -3
  25. package/src/core/routesBuilder.ts +129 -122
  26. package/src/core/server.ts +161 -158
  27. package/src/dataAccess/columnTypeMapper.ts +22 -22
  28. package/src/dataAccess/dataAccessTypes.ts +165 -165
  29. package/src/dataAccess/dataAccessor.ts +135 -135
  30. package/src/dataAccess/entityManager.ts +2031 -1996
  31. package/src/dataAccess/entityMapper.ts +111 -111
  32. package/src/dataAccess/entityValidator.ts +33 -33
  33. package/src/dataAccess/propertyMapper.ts +28 -28
  34. package/src/deno-std/assert/assert.ts +9 -9
  35. package/src/deno-std/assert/assertion_error.ts +7 -7
  36. package/src/deno-std/datetime/to_imf.ts +32 -32
  37. package/src/deno-std/encoding/base64.ts +141 -141
  38. package/src/deno-std/http/cookie.ts +372 -372
  39. package/src/facilities/cache/CacheFacilityTypes.ts +29 -29
  40. package/src/facilities/cache/CacheFactory.ts +31 -31
  41. package/src/facilities/cache/MemoryCache.ts +58 -58
  42. package/src/facilities/cache/MemoryCacheProvider.ts +15 -15
  43. package/src/facilities/log/LogFacility.ts +35 -35
  44. package/src/helpers/dbTransactionHelper.ts +42 -42
  45. package/src/helpers/entityHelper.ts +89 -89
  46. package/src/helpers/filterHelper.ts +148 -148
  47. package/src/helpers/inputHelper.ts +11 -11
  48. package/src/helpers/licenseHelper.ts +29 -29
  49. package/src/helpers/metaHelper.ts +111 -111
  50. package/src/helpers/runCollectionEntityActionHandler.ts +58 -58
  51. package/src/index.ts +85 -85
  52. package/src/plugins/auth/AuthPlugin.ts +107 -107
  53. package/src/plugins/auth/AuthPluginTypes.ts +11 -11
  54. package/src/plugins/auth/actionHandlers/changePassword.ts +61 -61
  55. package/src/plugins/auth/actionHandlers/createSession.ts +68 -68
  56. package/src/plugins/auth/actionHandlers/deleteSession.ts +18 -18
  57. package/src/plugins/auth/actionHandlers/getMyProfile.ts +28 -28
  58. package/src/plugins/auth/actionHandlers/index.ts +8 -8
  59. package/src/plugins/auth/actionHandlers/resetPassword.ts +45 -45
  60. package/src/plugins/auth/models/AccessToken.ts +56 -56
  61. package/src/plugins/auth/models/index.ts +3 -3
  62. package/src/plugins/auth/routes/changePassword.ts +15 -15
  63. package/src/plugins/auth/routes/getMyProfile.ts +15 -15
  64. package/src/plugins/auth/routes/index.ts +7 -7
  65. package/src/plugins/auth/routes/resetPassword.ts +15 -15
  66. package/src/plugins/auth/routes/signin.ts +15 -15
  67. package/src/plugins/auth/routes/signout.ts +15 -15
  68. package/src/plugins/auth/services/AuthService.ts +66 -66
  69. package/src/plugins/cronJob/CronJobPlugin.ts +104 -104
  70. package/src/plugins/cronJob/CronJobPluginTypes.ts +44 -44
  71. package/src/plugins/cronJob/actionHandlers/index.ts +4 -4
  72. package/src/plugins/cronJob/actionHandlers/runCronJob.ts +32 -32
  73. package/src/plugins/cronJob/entityWatchers/cronJobEntityWatchers.ts +24 -24
  74. package/src/plugins/cronJob/entityWatchers/index.ts +4 -4
  75. package/src/plugins/cronJob/models/CronJob.ts +129 -129
  76. package/src/plugins/cronJob/models/index.ts +3 -3
  77. package/src/plugins/cronJob/routes/index.ts +3 -3
  78. package/src/plugins/cronJob/routes/runCronJob.ts +15 -15
  79. package/src/plugins/cronJob/services/CronJobService.ts +255 -255
  80. package/src/plugins/dataManage/DataManagePlugin.ts +165 -165
  81. package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +15 -15
  82. package/src/plugins/dataManage/actionHandlers/countCollectionEntities.ts +17 -17
  83. package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +81 -81
  84. package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +20 -20
  85. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntities.ts +47 -45
  86. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +20 -20
  87. package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +27 -27
  88. package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +30 -30
  89. package/src/plugins/dataManage/actionHandlers/queryDatabase.ts +22 -22
  90. package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +15 -15
  91. package/src/plugins/dataManage/actionHandlers/saveEntity.ts +46 -46
  92. package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +38 -38
  93. package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +146 -146
  94. package/src/plugins/fileManage/FileManagePlugin.ts +52 -52
  95. package/src/plugins/fileManage/actionHandlers/downloadDocument.ts +65 -65
  96. package/src/plugins/fileManage/actionHandlers/downloadFile.ts +44 -44
  97. package/src/plugins/fileManage/actionHandlers/uploadFile.ts +33 -33
  98. package/src/plugins/fileManage/routes/downloadDocument.ts +15 -15
  99. package/src/plugins/fileManage/routes/downloadFile.ts +15 -15
  100. package/src/plugins/fileManage/routes/index.ts +5 -5
  101. package/src/plugins/fileManage/routes/uploadFile.ts +15 -15
  102. package/src/plugins/license/LicensePlugin.ts +79 -79
  103. package/src/plugins/license/LicensePluginTypes.ts +95 -95
  104. package/src/plugins/license/LicenseService.ts +141 -141
  105. package/src/plugins/license/actionHandlers/getLicense.ts +18 -18
  106. package/src/plugins/license/actionHandlers/index.ts +5 -5
  107. package/src/plugins/license/actionHandlers/updateLicense.ts +24 -24
  108. package/src/plugins/license/helpers/certHelper.ts +21 -21
  109. package/src/plugins/license/helpers/cryptoHelper.ts +47 -47
  110. package/src/plugins/license/models/index.ts +1 -1
  111. package/src/plugins/license/routes/getLicense.ts +15 -15
  112. package/src/plugins/license/routes/index.ts +4 -4
  113. package/src/plugins/license/routes/updateLicense.ts +15 -15
  114. package/src/plugins/mail/MailPlugin.ts +74 -74
  115. package/src/plugins/mail/MailPluginTypes.ts +27 -27
  116. package/src/plugins/mail/MailService.ts +38 -38
  117. package/src/plugins/mail/actionHandlers/index.ts +3 -3
  118. package/src/plugins/mail/models/index.ts +1 -1
  119. package/src/plugins/mail/routes/index.ts +1 -1
  120. package/src/plugins/metaManage/MetaManagePlugin.ts +198 -198
  121. package/src/plugins/metaManage/actionHandlers/getMetaModelDetail.ts +10 -10
  122. package/src/plugins/metaManage/actionHandlers/listMetaModels.ts +10 -10
  123. package/src/plugins/metaManage/actionHandlers/listMetaRoutes.ts +10 -10
  124. package/src/plugins/metaManage/services/MetaService.ts +376 -376
  125. package/src/plugins/notification/NotificationPlugin.ts +68 -68
  126. package/src/plugins/notification/NotificationPluginTypes.ts +13 -13
  127. package/src/plugins/notification/NotificationService.ts +25 -25
  128. package/src/plugins/notification/actionHandlers/index.ts +3 -3
  129. package/src/plugins/notification/models/Notification.ts +60 -60
  130. package/src/plugins/notification/models/index.ts +3 -3
  131. package/src/plugins/notification/routes/index.ts +1 -1
  132. package/src/plugins/routeManage/RouteManagePlugin.ts +64 -64
  133. package/src/plugins/routeManage/actionHandlers/httpProxy.ts +13 -13
  134. package/src/plugins/routeManage/actionHandlers/mock.ts +28 -28
  135. package/src/plugins/sequence/SequencePlugin.ts +146 -146
  136. package/src/plugins/sequence/SequencePluginTypes.ts +69 -69
  137. package/src/plugins/sequence/SequenceService.ts +92 -92
  138. package/src/plugins/sequence/actionHandlers/generateSn.ts +32 -32
  139. package/src/plugins/sequence/actionHandlers/index.ts +4 -4
  140. package/src/plugins/sequence/models/SequenceAutoIncrementRecord.ts +49 -49
  141. package/src/plugins/sequence/models/SequenceRule.ts +42 -42
  142. package/src/plugins/sequence/models/index.ts +4 -4
  143. package/src/plugins/sequence/routes/generateSn.ts +15 -15
  144. package/src/plugins/sequence/routes/index.ts +3 -3
  145. package/src/plugins/sequence/segment-utility.ts +11 -11
  146. package/src/plugins/sequence/segments/autoIncrement.ts +90 -90
  147. package/src/plugins/sequence/segments/dayOfMonth.ts +19 -19
  148. package/src/plugins/sequence/segments/index.ts +9 -9
  149. package/src/plugins/sequence/segments/literal.ts +16 -16
  150. package/src/plugins/sequence/segments/month.ts +19 -19
  151. package/src/plugins/sequence/segments/parameter.ts +20 -20
  152. package/src/plugins/sequence/segments/year.ts +19 -19
  153. package/src/plugins/serverOperation/ServerOperationPlugin.ts +93 -93
  154. package/src/plugins/serverOperation/ServerOperationPluginTypes.ts +25 -25
  155. package/src/plugins/serverOperation/actionHandlers/index.ts +4 -4
  156. package/src/plugins/serverOperation/actionHandlers/runServerOperation.ts +20 -20
  157. package/src/plugins/setting/SettingPlugin.ts +68 -68
  158. package/src/plugins/setting/SettingPluginTypes.ts +37 -37
  159. package/src/plugins/setting/SettingService.ts +222 -222
  160. package/src/plugins/setting/actionHandlers/getSystemSettingValues.ts +30 -30
  161. package/src/plugins/setting/actionHandlers/getUserSettingValues.ts +38 -38
  162. package/src/plugins/setting/actionHandlers/index.ts +6 -6
  163. package/src/plugins/setting/actionHandlers/setSystemSettingValues.ts +30 -30
  164. package/src/plugins/setting/models/SystemSettingGroupSetting.ts +57 -57
  165. package/src/plugins/setting/models/SystemSettingItem.ts +48 -48
  166. package/src/plugins/setting/models/SystemSettingItemSetting.ts +73 -73
  167. package/src/plugins/setting/models/UserSettingGroupSetting.ts +57 -57
  168. package/src/plugins/setting/models/UserSettingItem.ts +55 -55
  169. package/src/plugins/setting/models/UserSettingItemSetting.ts +73 -73
  170. package/src/plugins/setting/models/index.ts +8 -8
  171. package/src/plugins/setting/routes/getSystemSettingValues.ts +15 -15
  172. package/src/plugins/setting/routes/getUserSettingValues.ts +15 -15
  173. package/src/plugins/setting/routes/index.ts +5 -5
  174. package/src/plugins/setting/routes/setSystemSettingValues.ts +15 -15
  175. package/src/plugins/stateMachine/StateMachinePlugin.ts +196 -196
  176. package/src/plugins/stateMachine/StateMachinePluginTypes.ts +48 -48
  177. package/src/plugins/stateMachine/actionHandlers/index.ts +4 -4
  178. package/src/plugins/stateMachine/actionHandlers/sendStateMachineEvent.ts +54 -54
  179. package/src/plugins/stateMachine/models/StateMachine.ts +42 -42
  180. package/src/plugins/stateMachine/models/index.ts +3 -3
  181. package/src/plugins/stateMachine/routes/index.ts +3 -3
  182. package/src/plugins/stateMachine/routes/sendStateMachineEvent.ts +15 -15
  183. package/src/plugins/stateMachine/stateMachineHelper.ts +36 -36
  184. package/src/plugins/webhooks/WebhooksPlugin.ts +148 -148
  185. package/src/plugins/webhooks/pluginConfig.ts +75 -75
  186. package/src/polyfill.ts +5 -5
  187. package/src/proxy/mod.ts +38 -38
  188. package/src/proxy/types.ts +21 -21
  189. package/src/queryBuilder/index.ts +1 -1
  190. package/src/queryBuilder/queryBuilder.ts +755 -755
  191. package/src/server.ts +567 -556
  192. package/src/types/cron-job-types.ts +71 -71
  193. package/src/types.ts +884 -882
  194. package/src/utilities/accessControlUtility.ts +33 -33
  195. package/src/utilities/entityUtility.ts +18 -18
  196. package/src/utilities/errorUtility.ts +15 -15
  197. package/src/utilities/fsUtility.ts +137 -137
  198. package/src/utilities/httpUtility.ts +19 -19
  199. package/src/utilities/jwtUtility.ts +26 -26
  200. package/src/utilities/passwordUtility.ts +26 -26
  201. package/src/utilities/pathUtility.ts +14 -14
  202. package/src/utilities/timeUtility.ts +17 -17
  203. package/src/utilities/typeUtility.ts +15 -15
  204. package/tsconfig.json +19 -19
package/src/types.ts CHANGED
@@ -1,882 +1,884 @@
1
- import { ActionHandlerContext } from "./core/actionHandler";
2
- import { RouteContext } from "./core/routeContext";
3
- import { IRpdServer, RapidPlugin } from "./core/server";
4
- import { ColumnSelectOptions, CountRowOptions, FindRowOptions, RowFilterOptions } from "./dataAccess/dataAccessTypes";
5
-
6
- export type RapidServerConfig = {
7
- baseUrl?: string;
8
- sessionCookieName: string;
9
- jwtKey: string;
10
- localFileStoragePath: string;
11
- };
12
-
13
- export interface IDatabaseConfig {
14
- dbHost?: string;
15
- dbPort?: number;
16
- dbName?: string;
17
- dbUser?: string;
18
- dbPassword?: string;
19
- dbDefaultSchema?: string;
20
- dbPoolConnections?: number;
21
- }
22
-
23
- export type DatabaseQuery = {
24
- command: string;
25
- params?: unknown[] | Record<string, unknown>;
26
- };
27
-
28
- export interface IDatabaseClient {
29
- release();
30
- query(sql: any, params?: any): Promise<any>;
31
- }
32
-
33
- export interface IDatabaseAccessor {
34
- getClient(): Promise<IDatabaseClient>;
35
- queryDatabaseObject: (sql: string, params?: unknown[] | Record<string, unknown>, client?: IDatabaseClient) => Promise<any[]>;
36
- }
37
-
38
- export type RunActionHandlersOptions = {
39
- actions: RpdRouteActionConfig[];
40
- };
41
-
42
- export interface RunEntityActionHandlerOptions {
43
- /** 模型所在的命名空间 */
44
- namespace: string;
45
- /** 模型Code的单数表示 */
46
- singularCode: string;
47
- /** 默认输入 */
48
- defaultInput: Record<string, any>;
49
- /** 固定输入 */
50
- fixedInput: Record<string, any>;
51
- }
52
-
53
- export interface RunQueryDatabaseHandlerOptions {
54
- sql: string;
55
-
56
- querySingle?: boolean;
57
-
58
- /** 默认输入 */
59
- defaultInput: Record<string, any>;
60
- /** 固定输入 */
61
- fixedInput: Record<string, any>;
62
- }
63
-
64
- export interface RunProxyHandlerOptions {
65
- /** Timeout milli seconds, default as 60000 */
66
- timeout?: number;
67
- /** Target url to proxy */
68
- target: string;
69
- }
70
-
71
- export interface RunMockHandlerOptions {
72
- /**
73
- * 响应时间,毫秒
74
- */
75
- responseTime?: number;
76
-
77
- /**
78
- * 响应状态
79
- */
80
- responseStatus?: number;
81
-
82
- /**
83
- * 响应头
84
- */
85
- responseHeaders?: Record<string, string>;
86
-
87
- /**
88
- * 响应体
89
- */
90
- responseBody?: any;
91
- }
92
-
93
- export interface GetDataAccessorOptions {
94
- namespace?: string;
95
- singularCode: string;
96
- }
97
-
98
- export interface GetModelOptions {
99
- namespace?: string;
100
- singularCode: string;
101
- }
102
-
103
- export type RpdServerEventTypes = {
104
- "entity.beforeCreate": [RapidPlugin, RpdEntityBeforeCreateEventPayload, RouteContext?];
105
- "entity.create": [RapidPlugin, RpdEntityCreateEventPayload, RouteContext?];
106
- "entity.beforeUpdate": [RapidPlugin, RpdEntityBeforeUpdateEventPayload, RouteContext?];
107
- "entity.update": [RapidPlugin, RpdEntityUpdateEventPayload, RouteContext?];
108
- "entity.beforeDelete": [RapidPlugin, RpdEntityBeforeDeleteEventPayload, RouteContext?];
109
- "entity.delete": [RapidPlugin, RpdEntityDeleteEventPayload, RouteContext?];
110
- "entity.addRelations": [RapidPlugin, RpdEntityAddRelationsEventPayload, RouteContext?];
111
- "entity.removeRelations": [RapidPlugin, RpdEntityRemoveRelationsEventPayload, RouteContext?];
112
- "entity.beforeResponse": [RapidPlugin, RpdEntityBeforeResponseEventPayload, RouteContext?];
113
- };
114
-
115
- export interface RpdEntityBeforeCreateEventPayload {
116
- namespace: string;
117
- modelSingularCode: string;
118
- baseModelSingularCode?: string;
119
- before: any;
120
- }
121
-
122
- export interface RpdEntityCreateEventPayload {
123
- namespace: string;
124
- modelSingularCode: string;
125
- baseModelSingularCode?: string;
126
- after: any;
127
- }
128
-
129
- export interface RpdEntityBeforeUpdateEventPayload {
130
- namespace: string;
131
- modelSingularCode: string;
132
- baseModelSingularCode?: string;
133
- before: any;
134
- changes: any;
135
- operation?: {
136
- type: string;
137
- };
138
- stateProperties?: string[];
139
- }
140
-
141
- export interface RpdEntityUpdateEventPayload {
142
- namespace: string;
143
- modelSingularCode: string;
144
- baseModelSingularCode?: string;
145
- before: any;
146
- after: any;
147
- changes: any;
148
- operation?: {
149
- type: string;
150
- };
151
- stateProperties?: string[];
152
- }
153
-
154
- export interface RpdEntityBeforeDeleteEventPayload {
155
- namespace: string;
156
- modelSingularCode: string;
157
- baseModelSingularCode?: string;
158
- before: any;
159
- }
160
-
161
- export interface RpdEntityDeleteEventPayload {
162
- namespace: string;
163
- modelSingularCode: string;
164
- baseModelSingularCode?: string;
165
- before: any;
166
- }
167
-
168
- export interface RpdEntityAddRelationsEventPayload {
169
- namespace: string;
170
- modelSingularCode: string;
171
- baseModelSingularCode?: string;
172
- entity: any;
173
- property: string;
174
- relations: any[];
175
- }
176
-
177
- export interface RpdEntityRemoveRelationsEventPayload {
178
- namespace: string;
179
- modelSingularCode: string;
180
- baseModelSingularCode?: string;
181
- entity: any;
182
- property: string;
183
- relations: any[];
184
- }
185
-
186
- export interface RpdEntityBeforeResponseEventPayload {
187
- namespace: string;
188
- modelSingularCode: string;
189
- baseModelSingularCode?: string;
190
- entities: any[];
191
- }
192
-
193
- export type EmitServerEventOptions<TEventName extends keyof RpdServerEventTypes> = {
194
- eventName: TEventName;
195
- payload: RpdServerEventTypes[TEventName][1];
196
- sender?: RapidPlugin;
197
- routeContext?: RouteContext;
198
- };
199
-
200
- export interface QuoteTableOptions {
201
- schema?: string;
202
- tableName: string;
203
- }
204
-
205
- export interface IQueryBuilder {
206
- quoteTable: (options: QuoteTableOptions) => string;
207
- quoteObject: (name: string) => string;
208
- buildFiltersExpression(model: RpdDataModel, filters: RowFilterOptions[]);
209
- formatValueToSqlLiteral: (value: any) => string;
210
- }
211
-
212
- export interface RpdApplicationConfig {
213
- code?: string;
214
- name?: string;
215
- models: RpdDataModel[];
216
- dataDictionaries: RpdDataDictionary[];
217
- routes: RpdRoute[];
218
- }
219
-
220
- export interface RpdDataModel {
221
- maintainedBy?: string;
222
- name: string;
223
- namespace: string;
224
- code?: string;
225
- singularCode: string;
226
- pluralCode: string;
227
- schema?: string;
228
- tableName: string;
229
- /**
230
- * Configure the singular code of base entity.
231
- */
232
- base?: string;
233
- /**
234
- * Configure the type of derived entity.
235
- */
236
- derivedType?: string;
237
- /**
238
- * Configure the property code to save derived type for base entity.
239
- */
240
- derivedTypePropertyCode?: string;
241
-
242
- /**
243
- * Indicates whether the entity is deprecated.
244
- */
245
- deprecated?: boolean;
246
-
247
- /**
248
- * Configure the property code used to display the entity.
249
- */
250
- displayPropertyCode?: string;
251
-
252
- /**
253
- * 默认排序方式
254
- */
255
- defaultOrderBy?: FindEntityOrderByOptions[];
256
-
257
- properties: RpdDataModelProperty[];
258
- indexes?: RpdDataModelIndex[];
259
- extensions?: RpdDataModelExtension[];
260
- permissionPolicies?: RpdDataModelPermissionPolicies;
261
- /**
262
- * 是否使用软删除
263
- */
264
- softDelete?: boolean;
265
-
266
- /**
267
- * 多语言配置
268
- */
269
- i18n?: Record<string, string>;
270
-
271
- /**
272
- * 本地化资源
273
- */
274
- locales?: Record<string, RpdDataModelLocale>;
275
- }
276
-
277
- /**
278
- * 实体本地化资源配置
279
- */
280
- export type RpdDataModelLocale = {
281
- name: string;
282
- description?: string;
283
- properties?: Record<string, RpdDataModelPropertyLocale>;
284
- };
285
-
286
- export interface RpdDataModelPermissionPolicies {
287
- find?: PermissionPolicy;
288
- create?: PermissionPolicy;
289
- update?: PermissionPolicy;
290
- delete?: PermissionPolicy;
291
- }
292
-
293
- export interface PermissionPolicy {
294
- any?: string[];
295
- all?: string[];
296
- }
297
-
298
- export interface RpdDataModelProperty {
299
- /**
300
- * 表示此属性由谁来维护
301
- */
302
- maintainedBy?: string;
303
- /**
304
- * 表示是否基础属性
305
- */
306
- isBaseProperty?: boolean;
307
- /**
308
- * 字段名称。可以包含中文。
309
- */
310
- name: string;
311
- /**
312
- * 字段代码。会用于数据表列名和 API 的字段名。
313
- */
314
- code: string;
315
- /**
316
- * 字段描述。
317
- */
318
- description?: string;
319
- /**
320
- * 数据表列名。如果没有设置则使用 code。
321
- */
322
- columnName?: string;
323
- /**
324
- * 字段类型。
325
- */
326
- type: RpdDataPropertyTypes;
327
-
328
- /**
329
- * Indicates whether the property is deprecated.
330
- */
331
- deprecated?: boolean;
332
-
333
- /**
334
- * 是否必须有值。默认为 false。
335
- */
336
- required?: boolean;
337
- /**
338
- * 默认值。使用默认值的 SQL 表达式表示。
339
- */
340
- defaultValue?: string;
341
- /**
342
- * 属性配置。
343
- */
344
- // deno-lint-ignore no-explicit-any
345
- config?: Record<string, any>;
346
- /**
347
- * 是否自增长。
348
- */
349
- autoIncrement?: boolean;
350
- /**
351
- * 字段值的最小长度。
352
- */
353
- minLength?: number;
354
- /**
355
- * 字段值的最大长度。
356
- */
357
- maxLength?: number;
358
- /**
359
- * 当 type 为 relation 时,设置关联实体为一个还是多个。
360
- */
361
- relation?: "one" | "many";
362
- /**
363
- * 关联实体的singular code,不管 relation one 或者 many 都需要设置。
364
- */
365
- targetSingularCode?: string;
366
- /**
367
- * 保存关联实体类型的字段名。当设置 targetTypeColumnName 时,表示关联实体类型不固定,可以关联不同类型的实体。
368
- */
369
- targetTypeColumnName?: string;
370
- /**
371
- * 当 relation 为 one 时,设置当前模型表中表示关联实体 id 的列名。
372
- * 当 relation 为 many,并且使用关联关系表保存关联信息时,设置关联关系表中表示关联实体 id 的列名。
373
- * 当 relation 为 many,并且不使用关联关系表保存关联信息时,关联实体 id 的列名默认为`id`,此时可以不设置 targetIdColumnName。
374
- */
375
- targetIdColumnName?: string;
376
- /**
377
- * 当 relation 为 many 时,设置目标模型表或关联关系表中表示自身实体 id 的列名。
378
- */
379
- selfIdColumnName?: string;
380
- /**
381
- * 当 relation 为 many 时,可以使用关联关系表保存关联信息,此时需要设置关联关系表的名称。
382
- */
383
- linkTableName?: string;
384
- /**
385
- * 当设置了 linkTableName 时,可以设置关联关系表所在的 Schema。
386
- */
387
- linkSchema?: string;
388
-
389
- /**
390
- * 数据字典编码。当类型为option时设置
391
- */
392
- dataDictionary?: string;
393
-
394
- /**
395
- * 当删除实体时,针对关系属性的联动处理。
396
- */
397
- entityDeletingReaction?: RpdEntityDeleteRelationPropertyReaction;
398
-
399
- /**
400
- * 当设置为`true`时,仅允许在创建时设置此属性的值,不允许更新。
401
- */
402
- readonly?: boolean;
403
-
404
- /**
405
- * 多语言配置
406
- */
407
- i18n?: Record<string, string>;
408
-
409
- /**
410
- * 本地化资源
411
- */
412
- locales?: Record<string, RpdDataModelPropertyLocale>;
413
- }
414
-
415
- /**
416
- * 实体属性本地化资源配置
417
- */
418
- export type RpdDataModelPropertyLocale = {
419
- name: string;
420
- description?: string;
421
- };
422
-
423
- export type RpdDataPropertyTypes =
424
- | "integer"
425
- | "long"
426
- | "float"
427
- | "double"
428
- | "decimal"
429
- | "text"
430
- | "boolean"
431
- | "date"
432
- | "time"
433
- | "datetime"
434
- | "json"
435
- | "relation"
436
- | "relation[]"
437
- | "option"
438
- | "option[]"
439
- | "file"
440
- | "file[]"
441
- | "image"
442
- | "image[]";
443
-
444
- export type RpdEntityDeleteRelationPropertyReaction = "doNothing" | "unlink" | "cascadingDelete";
445
-
446
- /**
447
- * 数据字典
448
- */
449
- export type RpdDataDictionary = {
450
- /**
451
- * 字典编码
452
- */
453
- code: string;
454
-
455
- /**
456
- * 字典名称
457
- */
458
- name?: string;
459
-
460
- /**
461
- * 描述
462
- */
463
- description?: string;
464
-
465
- /**
466
- * 字典项值类型
467
- */
468
- valueType: "string" | "integer";
469
-
470
- /**
471
- * 字典级别
472
- */
473
- level: "sys" | "app" | "user";
474
-
475
- /**
476
- * 字典项
477
- */
478
- entries: RpdDataDictionaryEntry[];
479
-
480
- /**
481
- * 多语言配置
482
- */
483
- i18n?: Record<string, string>;
484
-
485
- /**
486
- * 本地化资源
487
- */
488
- locales?: Record<string, RpdDataDictionaryLocale>;
489
-
490
- /**
491
- * Indicates whether the data dictionary is deprecated.
492
- */
493
- deprecated?: boolean;
494
- };
495
-
496
- export type RpdDataDictionaryLocale = {
497
- name: string;
498
- description?: string;
499
- };
500
-
501
- /**
502
- * 数据字典项
503
- */
504
- export type RpdDataDictionaryEntry = {
505
- /**
506
- * 名称
507
- */
508
- name: string;
509
-
510
- /**
511
- * 值
512
- */
513
- value: string;
514
-
515
- /**
516
- * 颜色
517
- */
518
- color?: string;
519
-
520
- /**
521
- * 图标
522
- */
523
- icon?: string;
524
-
525
- /**
526
- * 描述
527
- */
528
- description?: string;
529
-
530
- /**
531
- * 排序号
532
- */
533
- orderNum: number;
534
-
535
- /**
536
- * 是否禁用
537
- */
538
- disabled: boolean;
539
-
540
- /**
541
- * 多语言配置
542
- */
543
- i18n?: Record<string, string>;
544
-
545
- /**
546
- * 本地化资源
547
- */
548
- locales?: Record<string, RpdDataDictionaryEntryLocale>;
549
-
550
- /**
551
- * Indicates whether the data dictionary entry is deprecated.
552
- */
553
- deprecated?: boolean;
554
- };
555
-
556
- /**
557
- * 数据字典项本地化资源配置
558
- */
559
- export type RpdDataDictionaryEntryLocale = {
560
- name: string;
561
- description?: string;
562
- };
563
-
564
- export interface RpdDataModelExtension {
565
- code: string;
566
- config: any;
567
- }
568
-
569
- export interface RpdDataModelIndex {
570
- name?: string;
571
- unique?: boolean;
572
- properties: RpdDataModelIndexPropertyConfig[];
573
- conditions?: RpdDataModelIndexOptions[];
574
-
575
- /**
576
- * 重复时的错误信息。
577
- */
578
- duplicateErrorMessage?: string;
579
- }
580
-
581
- export type RpdDataModelIndexPropertyConfig =
582
- | string
583
- | {
584
- code: string;
585
- order?: "asc" | "desc";
586
- };
587
-
588
- export type RpdDataModelIndexOptions =
589
- | FindEntityRelationalFilterOptions
590
- | FindEntitySetFilterOptions
591
- | FindEntityLogicalFilterOptions<RpdDataModelIndexOptions>
592
- | FindEntityUnaryFilterOptions;
593
-
594
- export type EventHandler<T = any> = (sender: RapidPlugin, payload: T) => void;
595
-
596
- export interface RpdRoute {
597
- name: string;
598
- namespace: string;
599
- code: string;
600
- type: "RESTful";
601
- method: RpdHttpMethod;
602
- endpoint: string;
603
- executeInDbTransaction?: boolean;
604
- actions?: RpdRouteActionConfig[];
605
- handler?: string | ((ctx: ActionHandlerContext) => Promise<void>);
606
- }
607
-
608
- export type RpdHttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
609
-
610
- export interface RpdRouteActionConfig {
611
- code: string;
612
- config?: any;
613
- }
614
-
615
- export interface IRpdDataAccessor<T = any> {
616
- getModel(): RpdDataModel;
617
- create(entity: any, databaseClient: IDatabaseClient | null): Promise<any>;
618
- updateById(id: any, entity: any, databaseClient: IDatabaseClient | null): Promise<any>;
619
- find(options: FindRowOptions, databaseClient: IDatabaseClient | null): Promise<T[]>;
620
- findOne(options: FindRowOptions, databaseClient: IDatabaseClient | null): Promise<T | null>;
621
- findById(id: any, databaseClient: IDatabaseClient | null): Promise<T | null>;
622
- count(options: CountRowOptions, databaseClient: IDatabaseClient | null): Promise<number>;
623
- deleteById(id: any, databaseClient: IDatabaseClient | null): Promise<void>;
624
- }
625
-
626
- export type EntityFilterRelationalOperators =
627
- | "eq"
628
- | "ne"
629
- | "lt"
630
- | "lte"
631
- | "gt"
632
- | "gte"
633
- | "matches"
634
- | "matchesCS"
635
- | "contains"
636
- | "notContains"
637
- | "containsCS"
638
- | "notContainsCS"
639
- | "startsWith"
640
- | "notStartsWith"
641
- | "endsWith"
642
- | "notEndsWith";
643
-
644
- export type EntityFilterArrayOperators = "arrayContains" | "arrayOverlap";
645
-
646
- export type EntityFilterSetOperators = "in" | "notIn";
647
-
648
- export type EntityFilterLogicalOperators = "or" | "and";
649
-
650
- export type EntityFilterUnaryOperators = "null" | "notNull";
651
-
652
- export type EntityFilterExistenceOperators = "exists" | "notExists";
653
-
654
- export type EntityFilterOperators =
655
- | EntityFilterRelationalOperators
656
- | EntityFilterArrayOperators
657
- | EntityFilterSetOperators
658
- | EntityFilterLogicalOperators
659
- | EntityFilterUnaryOperators
660
- | EntityFilterExistenceOperators;
661
-
662
- export type EntityFilterOptions =
663
- | FindEntityRelationalFilterOptions
664
- | FindEntityArrayFilterOptions
665
- | FindEntitySetFilterOptions
666
- | FindEntityLogicalFilterOptions
667
- | FindEntityUnaryFilterOptions
668
- | FindEntityExistenceFilterOptions;
669
-
670
- export type EntityNonRelationPropertyFilterOptions =
671
- | FindEntityRelationalFilterOptions
672
- | FindEntityArrayFilterOptions
673
- | FindEntitySetFilterOptions
674
- | FindEntityUnaryFilterOptions;
675
-
676
- export interface FindEntityOptions {
677
- routeContext?: RouteContext;
678
- filters?: EntityFilterOptions[];
679
- orderBy?: FindEntityOrderByOptions[];
680
- pagination?: FindEntityPaginationOptions;
681
- properties?: string[];
682
- relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
683
- extraColumnsToSelect?: ColumnSelectOptions[];
684
- keepNonPropertyFields?: boolean;
685
- /**
686
- * 是否包含已经软删除的实体
687
- */
688
- includingSoftDeleted?: boolean;
689
- }
690
-
691
- export interface FindEntityByIdOptions {
692
- routeContext?: RouteContext;
693
- id: any;
694
- properties?: string[];
695
- relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
696
- keepNonPropertyFields?: boolean;
697
- }
698
-
699
- export interface FindEntityRelationalFilterOptions {
700
- field: string;
701
- operator: EntityFilterRelationalOperators;
702
- value: any;
703
- }
704
-
705
- export interface FindEntityArrayFilterOptions {
706
- field: string;
707
- operator: EntityFilterArrayOperators;
708
- value: any[];
709
- itemType?: string;
710
- }
711
-
712
- export interface FindEntitySetFilterOptions {
713
- field: string;
714
- operator: EntityFilterSetOperators;
715
- value: any[];
716
- itemType?: string;
717
- }
718
-
719
- export interface FindEntityLogicalFilterOptions<TFilter = EntityFilterOptions> {
720
- operator: EntityFilterLogicalOperators;
721
- filters: TFilter[];
722
- }
723
-
724
- export interface FindEntityUnaryFilterOptions {
725
- field: string;
726
- operator: EntityFilterUnaryOperators;
727
- }
728
-
729
- export interface FindEntityExistenceFilterOptions {
730
- field: string;
731
- operator: EntityFilterExistenceOperators;
732
- filters: EntityFilterOptions[];
733
- includingSoftDeleted?: boolean;
734
- }
735
-
736
- export interface FindEntityPaginationOptions {
737
- offset: number;
738
- limit: number;
739
- withoutTotal?: boolean;
740
- }
741
-
742
- export type FindEntityFindRelationEntitiesOptions = FindEntityFindOneRelationEntitiesOptions | FindEntityFindManyRelationEntitiesOptions;
743
-
744
- export type FindEntityFindOneRelationEntitiesOptions =
745
- | true
746
- | {
747
- properties?: string[];
748
- relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
749
- keepNonPropertyFields?: boolean;
750
- includingSoftDeleted?: boolean;
751
- };
752
-
753
- export type FindEntityFindManyRelationEntitiesOptions =
754
- | true
755
- | {
756
- properties?: string[];
757
- relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
758
- filters?: EntityFilterOptions[];
759
- orderBy?: FindEntityOrderByOptions[];
760
- pagination?: FindEntityPaginationOptions;
761
- keepNonPropertyFields?: boolean;
762
- includingSoftDeleted?: boolean;
763
- };
764
-
765
- export interface FindEntityOrderByOptions {
766
- field: string;
767
- desc?: boolean;
768
- }
769
-
770
- export interface CountEntityOptions {
771
- routeContext?: RouteContext;
772
- filters?: EntityFilterOptions[];
773
- }
774
-
775
- export interface CountEntityResult {
776
- count: number;
777
- }
778
-
779
- export interface DeleteEntityByIdOptions {
780
- routeContext?: RouteContext;
781
- id: any;
782
- }
783
-
784
- export interface CreateEntityOptions {
785
- routeContext?: RouteContext;
786
- entity: any;
787
- postponeUniquenessCheck?: boolean;
788
- }
789
-
790
- export interface UpdateEntityOptions {
791
- routeContext?: RouteContext;
792
- filters?: EntityFilterOptions[];
793
- entity: any;
794
- }
795
-
796
- export interface UpdateEntityByIdOptions {
797
- routeContext?: RouteContext;
798
- id: any;
799
- entityToSave: any;
800
- operation?: {
801
- type: string;
802
- };
803
- /**
804
- * 指定需要更新那几个状态属性(配置了`config.stateMachine`的属性)。当不指定时默认更新全部状态属性。
805
- */
806
- stateProperties?: string[];
807
- postponeUniquenessCheck?: boolean;
808
- /**
809
- * 指定需要更新关联对象的哪些属性。更新实体时,会创建关联对象,但是默认不更新关联对象的属性。
810
- */
811
- relationPropertiesToUpdate?: Record<string, UpdateRelationPropertyOptions>;
812
- }
813
-
814
- export type UpdateRelationPropertyOptions =
815
- | true
816
- | {
817
- // TODO: impl savingMode 'patch'
818
- // savingMode?: "overwrite" | "patch";
819
-
820
- /**
821
- * 当需移除关系时是删除关联实体,还是取消关联。默认为`delete`。此配置仅对没有配置`linkTableName`的属性有效。
822
- */
823
- relationRemoveMode?: "unlink" | "delete";
824
- propertiesToUpdate?: string[];
825
- relationPropertiesToUpdate?: Record<string, UpdateRelationPropertyOptions>;
826
- };
827
-
828
- export interface DeleteEntityOptions {
829
- routeContext?: RouteContext;
830
- filters?: EntityFilterOptions[];
831
- }
832
-
833
- export interface AddEntityRelationsOptions {
834
- routeContext?: RouteContext;
835
- id: number;
836
- property: string;
837
- relations: { id?: number; [k: string]: any }[];
838
- }
839
-
840
- export interface RemoveEntityRelationsOptions {
841
- routeContext?: RouteContext;
842
- id: number;
843
- property: string;
844
- relations: { id?: number; [k: string]: any }[];
845
- }
846
-
847
- export type EntityWatcherType =
848
- | EntityWatcher<"entity.beforeCreate">
849
- | EntityWatcher<"entity.create">
850
- | EntityWatcher<"entity.beforeUpdate">
851
- | EntityWatcher<"entity.update">
852
- | EntityWatcher<"entity.beforeDelete">
853
- | EntityWatcher<"entity.delete">
854
- | EntityWatcher<"entity.addRelations">
855
- | EntityWatcher<"entity.removeRelations">
856
- | EntityWatcher<"entity.beforeResponse">
857
- | EntityWatcher<any>;
858
-
859
- export interface EntityWatcher<TEventName extends keyof RpdServerEventTypes> {
860
- eventName: TEventName;
861
- modelSingularCode: string;
862
- handler: EntityWatchHandler<TEventName>;
863
- }
864
-
865
- export type EntityWatchHandler<TEventName extends keyof RpdServerEventTypes> = (ctx: EntityWatchHandlerContext<TEventName>) => Promise<void>;
866
-
867
- export type EntityWatchHandlerContext<TEventName extends keyof RpdServerEventTypes> = {
868
- server: IRpdServer;
869
- payload: RpdServerEventTypes[TEventName][1];
870
- routerContext: RouteContext;
871
- };
872
-
873
- export interface EntityWatchPluginInitOptions {
874
- watchers: EntityWatcherType[];
875
- }
876
-
877
- export interface LocaleString {
878
- namespace: string;
879
- name: string;
880
- lingual: string;
881
- text?: string;
882
- }
1
+ import { ActionHandlerContext } from "./core/actionHandler";
2
+ import { RouteContext } from "./core/routeContext";
3
+ import { IRpdServer, RapidPlugin } from "./core/server";
4
+ import { ColumnSelectOptions, CountRowOptions, FindRowOptions, RowFilterOptions } from "./dataAccess/dataAccessTypes";
5
+
6
+ export type RapidServerConfig = {
7
+ baseUrl?: string;
8
+ sessionCookieName: string;
9
+ jwtKey: string;
10
+ localFileStoragePath: string;
11
+ };
12
+
13
+ export interface IDatabaseConfig {
14
+ dbHost?: string;
15
+ dbPort?: number;
16
+ dbName?: string;
17
+ dbUser?: string;
18
+ dbPassword?: string;
19
+ dbDefaultSchema?: string;
20
+ dbPoolConnections?: number;
21
+ }
22
+
23
+ export type DatabaseQuery = {
24
+ command: string;
25
+ params?: unknown[] | Record<string, unknown>;
26
+ };
27
+
28
+ export interface IDatabaseClient {
29
+ release();
30
+ query(sql: any, params?: any): Promise<any>;
31
+ }
32
+
33
+ export interface IDatabaseAccessor {
34
+ getClient(): Promise<IDatabaseClient>;
35
+ queryDatabaseObject: (sql: string, params?: unknown[] | Record<string, unknown>, client?: IDatabaseClient) => Promise<any[]>;
36
+ }
37
+
38
+ export type RunActionHandlersOptions = {
39
+ actions: RpdRouteActionConfig[];
40
+ };
41
+
42
+ export interface RunEntityActionHandlerOptions {
43
+ /** 模型所在的命名空间 */
44
+ namespace: string;
45
+ /** 模型Code的单数表示 */
46
+ singularCode: string;
47
+ /** 默认输入 */
48
+ defaultInput: Record<string, any>;
49
+ /** 固定输入 */
50
+ fixedInput: Record<string, any>;
51
+ }
52
+
53
+ export interface RunQueryDatabaseHandlerOptions {
54
+ sql: string;
55
+
56
+ querySingle?: boolean;
57
+
58
+ /** 默认输入 */
59
+ defaultInput: Record<string, any>;
60
+ /** 固定输入 */
61
+ fixedInput: Record<string, any>;
62
+ }
63
+
64
+ export interface RunProxyHandlerOptions {
65
+ /** Timeout milli seconds, default as 60000 */
66
+ timeout?: number;
67
+ /** Target url to proxy */
68
+ target: string;
69
+ }
70
+
71
+ export interface RunMockHandlerOptions {
72
+ /**
73
+ * 响应时间,毫秒
74
+ */
75
+ responseTime?: number;
76
+
77
+ /**
78
+ * 响应状态
79
+ */
80
+ responseStatus?: number;
81
+
82
+ /**
83
+ * 响应头
84
+ */
85
+ responseHeaders?: Record<string, string>;
86
+
87
+ /**
88
+ * 响应体
89
+ */
90
+ responseBody?: any;
91
+ }
92
+
93
+ export interface GetDataAccessorOptions {
94
+ namespace?: string;
95
+ singularCode: string;
96
+ }
97
+
98
+ export interface GetModelOptions {
99
+ namespace?: string;
100
+ singularCode: string;
101
+ }
102
+
103
+ export type RpdServerEventTypes = {
104
+ "entity.beforeCreate": [RapidPlugin, RpdEntityBeforeCreateEventPayload, RouteContext?];
105
+ "entity.create": [RapidPlugin, RpdEntityCreateEventPayload, RouteContext?];
106
+ "entity.beforeUpdate": [RapidPlugin, RpdEntityBeforeUpdateEventPayload, RouteContext?];
107
+ "entity.update": [RapidPlugin, RpdEntityUpdateEventPayload, RouteContext?];
108
+ "entity.beforeDelete": [RapidPlugin, RpdEntityBeforeDeleteEventPayload, RouteContext?];
109
+ "entity.delete": [RapidPlugin, RpdEntityDeleteEventPayload, RouteContext?];
110
+ "entity.addRelations": [RapidPlugin, RpdEntityAddRelationsEventPayload, RouteContext?];
111
+ "entity.removeRelations": [RapidPlugin, RpdEntityRemoveRelationsEventPayload, RouteContext?];
112
+ "entity.beforeResponse": [RapidPlugin, RpdEntityBeforeResponseEventPayload, RouteContext?];
113
+ };
114
+
115
+ export interface RpdEntityBeforeCreateEventPayload {
116
+ namespace: string;
117
+ modelSingularCode: string;
118
+ baseModelSingularCode?: string;
119
+ before: any;
120
+ }
121
+
122
+ export interface RpdEntityCreateEventPayload {
123
+ namespace: string;
124
+ modelSingularCode: string;
125
+ baseModelSingularCode?: string;
126
+ after: any;
127
+ }
128
+
129
+ export interface RpdEntityBeforeUpdateEventPayload {
130
+ namespace: string;
131
+ modelSingularCode: string;
132
+ baseModelSingularCode?: string;
133
+ before: any;
134
+ changes: any;
135
+ operation?: {
136
+ type: string;
137
+ };
138
+ stateProperties?: string[];
139
+ }
140
+
141
+ export interface RpdEntityUpdateEventPayload {
142
+ namespace: string;
143
+ modelSingularCode: string;
144
+ baseModelSingularCode?: string;
145
+ before: any;
146
+ after: any;
147
+ changes: any;
148
+ operation?: {
149
+ type: string;
150
+ };
151
+ stateProperties?: string[];
152
+ }
153
+
154
+ export interface RpdEntityBeforeDeleteEventPayload {
155
+ namespace: string;
156
+ modelSingularCode: string;
157
+ baseModelSingularCode?: string;
158
+ before: any;
159
+ }
160
+
161
+ export interface RpdEntityDeleteEventPayload {
162
+ namespace: string;
163
+ modelSingularCode: string;
164
+ baseModelSingularCode?: string;
165
+ before: any;
166
+ }
167
+
168
+ export interface RpdEntityAddRelationsEventPayload {
169
+ namespace: string;
170
+ modelSingularCode: string;
171
+ baseModelSingularCode?: string;
172
+ entity: any;
173
+ property: string;
174
+ relations: any[];
175
+ relationTargetEntities: any[];
176
+ }
177
+
178
+ export interface RpdEntityRemoveRelationsEventPayload {
179
+ namespace: string;
180
+ modelSingularCode: string;
181
+ baseModelSingularCode?: string;
182
+ entity: any;
183
+ property: string;
184
+ relations: any[];
185
+ relationTargetEntities: any[];
186
+ }
187
+
188
+ export interface RpdEntityBeforeResponseEventPayload {
189
+ namespace: string;
190
+ modelSingularCode: string;
191
+ baseModelSingularCode?: string;
192
+ entities: any[];
193
+ }
194
+
195
+ export type EmitServerEventOptions<TEventName extends keyof RpdServerEventTypes> = {
196
+ eventName: TEventName;
197
+ payload: RpdServerEventTypes[TEventName][1];
198
+ sender?: RapidPlugin;
199
+ routeContext?: RouteContext;
200
+ };
201
+
202
+ export interface QuoteTableOptions {
203
+ schema?: string;
204
+ tableName: string;
205
+ }
206
+
207
+ export interface IQueryBuilder {
208
+ quoteTable: (options: QuoteTableOptions) => string;
209
+ quoteObject: (name: string) => string;
210
+ buildFiltersExpression(model: RpdDataModel, filters: RowFilterOptions[]);
211
+ formatValueToSqlLiteral: (value: any) => string;
212
+ }
213
+
214
+ export interface RpdApplicationConfig {
215
+ code?: string;
216
+ name?: string;
217
+ models: RpdDataModel[];
218
+ dataDictionaries: RpdDataDictionary[];
219
+ routes: RpdRoute[];
220
+ }
221
+
222
+ export interface RpdDataModel {
223
+ maintainedBy?: string;
224
+ name: string;
225
+ namespace: string;
226
+ code?: string;
227
+ singularCode: string;
228
+ pluralCode: string;
229
+ schema?: string;
230
+ tableName: string;
231
+ /**
232
+ * Configure the singular code of base entity.
233
+ */
234
+ base?: string;
235
+ /**
236
+ * Configure the type of derived entity.
237
+ */
238
+ derivedType?: string;
239
+ /**
240
+ * Configure the property code to save derived type for base entity.
241
+ */
242
+ derivedTypePropertyCode?: string;
243
+
244
+ /**
245
+ * Indicates whether the entity is deprecated.
246
+ */
247
+ deprecated?: boolean;
248
+
249
+ /**
250
+ * Configure the property code used to display the entity.
251
+ */
252
+ displayPropertyCode?: string;
253
+
254
+ /**
255
+ * 默认排序方式
256
+ */
257
+ defaultOrderBy?: FindEntityOrderByOptions[];
258
+
259
+ properties: RpdDataModelProperty[];
260
+ indexes?: RpdDataModelIndex[];
261
+ extensions?: RpdDataModelExtension[];
262
+ permissionPolicies?: RpdDataModelPermissionPolicies;
263
+ /**
264
+ * 是否使用软删除
265
+ */
266
+ softDelete?: boolean;
267
+
268
+ /**
269
+ * 多语言配置
270
+ */
271
+ i18n?: Record<string, string>;
272
+
273
+ /**
274
+ * 本地化资源
275
+ */
276
+ locales?: Record<string, RpdDataModelLocale>;
277
+ }
278
+
279
+ /**
280
+ * 实体本地化资源配置
281
+ */
282
+ export type RpdDataModelLocale = {
283
+ name: string;
284
+ description?: string;
285
+ properties?: Record<string, RpdDataModelPropertyLocale>;
286
+ };
287
+
288
+ export interface RpdDataModelPermissionPolicies {
289
+ find?: PermissionPolicy;
290
+ create?: PermissionPolicy;
291
+ update?: PermissionPolicy;
292
+ delete?: PermissionPolicy;
293
+ }
294
+
295
+ export interface PermissionPolicy {
296
+ any?: string[];
297
+ all?: string[];
298
+ }
299
+
300
+ export interface RpdDataModelProperty {
301
+ /**
302
+ * 表示此属性由谁来维护
303
+ */
304
+ maintainedBy?: string;
305
+ /**
306
+ * 表示是否基础属性
307
+ */
308
+ isBaseProperty?: boolean;
309
+ /**
310
+ * 字段名称。可以包含中文。
311
+ */
312
+ name: string;
313
+ /**
314
+ * 字段代码。会用于数据表列名和 API 的字段名。
315
+ */
316
+ code: string;
317
+ /**
318
+ * 字段描述。
319
+ */
320
+ description?: string;
321
+ /**
322
+ * 数据表列名。如果没有设置则使用 code。
323
+ */
324
+ columnName?: string;
325
+ /**
326
+ * 字段类型。
327
+ */
328
+ type: RpdDataPropertyTypes;
329
+
330
+ /**
331
+ * Indicates whether the property is deprecated.
332
+ */
333
+ deprecated?: boolean;
334
+
335
+ /**
336
+ * 是否必须有值。默认为 false。
337
+ */
338
+ required?: boolean;
339
+ /**
340
+ * 默认值。使用默认值的 SQL 表达式表示。
341
+ */
342
+ defaultValue?: string;
343
+ /**
344
+ * 属性配置。
345
+ */
346
+ // deno-lint-ignore no-explicit-any
347
+ config?: Record<string, any>;
348
+ /**
349
+ * 是否自增长。
350
+ */
351
+ autoIncrement?: boolean;
352
+ /**
353
+ * 字段值的最小长度。
354
+ */
355
+ minLength?: number;
356
+ /**
357
+ * 字段值的最大长度。
358
+ */
359
+ maxLength?: number;
360
+ /**
361
+ * type 为 relation 时,设置关联实体为一个还是多个。
362
+ */
363
+ relation?: "one" | "many";
364
+ /**
365
+ * 关联实体的singular code,不管 relation 为 one 或者 many 都需要设置。
366
+ */
367
+ targetSingularCode?: string;
368
+ /**
369
+ * 保存关联实体类型的字段名。当设置 targetTypeColumnName 时,表示关联实体类型不固定,可以关联不同类型的实体。
370
+ */
371
+ targetTypeColumnName?: string;
372
+ /**
373
+ * 当 relation 为 one 时,设置当前模型表中表示关联实体 id 的列名。
374
+ * 当 relation 为 many,并且使用关联关系表保存关联信息时,设置关联关系表中表示关联实体 id 的列名。
375
+ * 当 relation 为 many,并且不使用关联关系表保存关联信息时,关联实体 id 的列名默认为`id`,此时可以不设置 targetIdColumnName
376
+ */
377
+ targetIdColumnName?: string;
378
+ /**
379
+ * 当 relation 为 many 时,设置目标模型表或关联关系表中表示自身实体 id 的列名。
380
+ */
381
+ selfIdColumnName?: string;
382
+ /**
383
+ * 当 relation 为 many 时,可以使用关联关系表保存关联信息,此时需要设置关联关系表的名称。
384
+ */
385
+ linkTableName?: string;
386
+ /**
387
+ * 当设置了 linkTableName 时,可以设置关联关系表所在的 Schema。
388
+ */
389
+ linkSchema?: string;
390
+
391
+ /**
392
+ * 数据字典编码。当类型为option时设置
393
+ */
394
+ dataDictionary?: string;
395
+
396
+ /**
397
+ * 当删除实体时,针对关系属性的联动处理。
398
+ */
399
+ entityDeletingReaction?: RpdEntityDeleteRelationPropertyReaction;
400
+
401
+ /**
402
+ * 当设置为`true`时,仅允许在创建时设置此属性的值,不允许更新。
403
+ */
404
+ readonly?: boolean;
405
+
406
+ /**
407
+ * 多语言配置
408
+ */
409
+ i18n?: Record<string, string>;
410
+
411
+ /**
412
+ * 本地化资源
413
+ */
414
+ locales?: Record<string, RpdDataModelPropertyLocale>;
415
+ }
416
+
417
+ /**
418
+ * 实体属性本地化资源配置
419
+ */
420
+ export type RpdDataModelPropertyLocale = {
421
+ name: string;
422
+ description?: string;
423
+ };
424
+
425
+ export type RpdDataPropertyTypes =
426
+ | "integer"
427
+ | "long"
428
+ | "float"
429
+ | "double"
430
+ | "decimal"
431
+ | "text"
432
+ | "boolean"
433
+ | "date"
434
+ | "time"
435
+ | "datetime"
436
+ | "json"
437
+ | "relation"
438
+ | "relation[]"
439
+ | "option"
440
+ | "option[]"
441
+ | "file"
442
+ | "file[]"
443
+ | "image"
444
+ | "image[]";
445
+
446
+ export type RpdEntityDeleteRelationPropertyReaction = "doNothing" | "unlink" | "cascadingDelete";
447
+
448
+ /**
449
+ * 数据字典
450
+ */
451
+ export type RpdDataDictionary = {
452
+ /**
453
+ * 字典编码
454
+ */
455
+ code: string;
456
+
457
+ /**
458
+ * 字典名称
459
+ */
460
+ name?: string;
461
+
462
+ /**
463
+ * 描述
464
+ */
465
+ description?: string;
466
+
467
+ /**
468
+ * 字典项值类型
469
+ */
470
+ valueType: "string" | "integer";
471
+
472
+ /**
473
+ * 字典级别
474
+ */
475
+ level: "sys" | "app" | "user";
476
+
477
+ /**
478
+ * 字典项
479
+ */
480
+ entries: RpdDataDictionaryEntry[];
481
+
482
+ /**
483
+ * 多语言配置
484
+ */
485
+ i18n?: Record<string, string>;
486
+
487
+ /**
488
+ * 本地化资源
489
+ */
490
+ locales?: Record<string, RpdDataDictionaryLocale>;
491
+
492
+ /**
493
+ * Indicates whether the data dictionary is deprecated.
494
+ */
495
+ deprecated?: boolean;
496
+ };
497
+
498
+ export type RpdDataDictionaryLocale = {
499
+ name: string;
500
+ description?: string;
501
+ };
502
+
503
+ /**
504
+ * 数据字典项
505
+ */
506
+ export type RpdDataDictionaryEntry = {
507
+ /**
508
+ * 名称
509
+ */
510
+ name: string;
511
+
512
+ /**
513
+ *
514
+ */
515
+ value: string;
516
+
517
+ /**
518
+ * 颜色
519
+ */
520
+ color?: string;
521
+
522
+ /**
523
+ * 图标
524
+ */
525
+ icon?: string;
526
+
527
+ /**
528
+ * 描述
529
+ */
530
+ description?: string;
531
+
532
+ /**
533
+ * 排序号
534
+ */
535
+ orderNum: number;
536
+
537
+ /**
538
+ * 是否禁用
539
+ */
540
+ disabled: boolean;
541
+
542
+ /**
543
+ * 多语言配置
544
+ */
545
+ i18n?: Record<string, string>;
546
+
547
+ /**
548
+ * 本地化资源
549
+ */
550
+ locales?: Record<string, RpdDataDictionaryEntryLocale>;
551
+
552
+ /**
553
+ * Indicates whether the data dictionary entry is deprecated.
554
+ */
555
+ deprecated?: boolean;
556
+ };
557
+
558
+ /**
559
+ * 数据字典项本地化资源配置
560
+ */
561
+ export type RpdDataDictionaryEntryLocale = {
562
+ name: string;
563
+ description?: string;
564
+ };
565
+
566
+ export interface RpdDataModelExtension {
567
+ code: string;
568
+ config: any;
569
+ }
570
+
571
+ export interface RpdDataModelIndex {
572
+ name?: string;
573
+ unique?: boolean;
574
+ properties: RpdDataModelIndexPropertyConfig[];
575
+ conditions?: RpdDataModelIndexOptions[];
576
+
577
+ /**
578
+ * 重复时的错误信息。
579
+ */
580
+ duplicateErrorMessage?: string;
581
+ }
582
+
583
+ export type RpdDataModelIndexPropertyConfig =
584
+ | string
585
+ | {
586
+ code: string;
587
+ order?: "asc" | "desc";
588
+ };
589
+
590
+ export type RpdDataModelIndexOptions =
591
+ | FindEntityRelationalFilterOptions
592
+ | FindEntitySetFilterOptions
593
+ | FindEntityLogicalFilterOptions<RpdDataModelIndexOptions>
594
+ | FindEntityUnaryFilterOptions;
595
+
596
+ export type EventHandler<T = any> = (sender: RapidPlugin, payload: T) => void;
597
+
598
+ export interface RpdRoute {
599
+ name: string;
600
+ namespace: string;
601
+ code: string;
602
+ type: "RESTful";
603
+ method: RpdHttpMethod;
604
+ endpoint: string;
605
+ executeInDbTransaction?: boolean;
606
+ actions?: RpdRouteActionConfig[];
607
+ handler?: string | ((ctx: ActionHandlerContext) => Promise<void>);
608
+ }
609
+
610
+ export type RpdHttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
611
+
612
+ export interface RpdRouteActionConfig {
613
+ code: string;
614
+ config?: any;
615
+ }
616
+
617
+ export interface IRpdDataAccessor<T = any> {
618
+ getModel(): RpdDataModel;
619
+ create(entity: any, databaseClient: IDatabaseClient | null): Promise<any>;
620
+ updateById(id: any, entity: any, databaseClient: IDatabaseClient | null): Promise<any>;
621
+ find(options: FindRowOptions, databaseClient: IDatabaseClient | null): Promise<T[]>;
622
+ findOne(options: FindRowOptions, databaseClient: IDatabaseClient | null): Promise<T | null>;
623
+ findById(id: any, databaseClient: IDatabaseClient | null): Promise<T | null>;
624
+ count(options: CountRowOptions, databaseClient: IDatabaseClient | null): Promise<number>;
625
+ deleteById(id: any, databaseClient: IDatabaseClient | null): Promise<void>;
626
+ }
627
+
628
+ export type EntityFilterRelationalOperators =
629
+ | "eq"
630
+ | "ne"
631
+ | "lt"
632
+ | "lte"
633
+ | "gt"
634
+ | "gte"
635
+ | "matches"
636
+ | "matchesCS"
637
+ | "contains"
638
+ | "notContains"
639
+ | "containsCS"
640
+ | "notContainsCS"
641
+ | "startsWith"
642
+ | "notStartsWith"
643
+ | "endsWith"
644
+ | "notEndsWith";
645
+
646
+ export type EntityFilterArrayOperators = "arrayContains" | "arrayOverlap";
647
+
648
+ export type EntityFilterSetOperators = "in" | "notIn";
649
+
650
+ export type EntityFilterLogicalOperators = "or" | "and";
651
+
652
+ export type EntityFilterUnaryOperators = "null" | "notNull";
653
+
654
+ export type EntityFilterExistenceOperators = "exists" | "notExists";
655
+
656
+ export type EntityFilterOperators =
657
+ | EntityFilterRelationalOperators
658
+ | EntityFilterArrayOperators
659
+ | EntityFilterSetOperators
660
+ | EntityFilterLogicalOperators
661
+ | EntityFilterUnaryOperators
662
+ | EntityFilterExistenceOperators;
663
+
664
+ export type EntityFilterOptions =
665
+ | FindEntityRelationalFilterOptions
666
+ | FindEntityArrayFilterOptions
667
+ | FindEntitySetFilterOptions
668
+ | FindEntityLogicalFilterOptions
669
+ | FindEntityUnaryFilterOptions
670
+ | FindEntityExistenceFilterOptions;
671
+
672
+ export type EntityNonRelationPropertyFilterOptions =
673
+ | FindEntityRelationalFilterOptions
674
+ | FindEntityArrayFilterOptions
675
+ | FindEntitySetFilterOptions
676
+ | FindEntityUnaryFilterOptions;
677
+
678
+ export interface FindEntityOptions {
679
+ routeContext?: RouteContext;
680
+ filters?: EntityFilterOptions[];
681
+ orderBy?: FindEntityOrderByOptions[];
682
+ pagination?: FindEntityPaginationOptions;
683
+ properties?: string[];
684
+ relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
685
+ extraColumnsToSelect?: ColumnSelectOptions[];
686
+ keepNonPropertyFields?: boolean;
687
+ /**
688
+ * 是否包含已经软删除的实体
689
+ */
690
+ includingSoftDeleted?: boolean;
691
+ }
692
+
693
+ export interface FindEntityByIdOptions {
694
+ routeContext?: RouteContext;
695
+ id: any;
696
+ properties?: string[];
697
+ relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
698
+ keepNonPropertyFields?: boolean;
699
+ }
700
+
701
+ export interface FindEntityRelationalFilterOptions {
702
+ field: string;
703
+ operator: EntityFilterRelationalOperators;
704
+ value: any;
705
+ }
706
+
707
+ export interface FindEntityArrayFilterOptions {
708
+ field: string;
709
+ operator: EntityFilterArrayOperators;
710
+ value: any[];
711
+ itemType?: string;
712
+ }
713
+
714
+ export interface FindEntitySetFilterOptions {
715
+ field: string;
716
+ operator: EntityFilterSetOperators;
717
+ value: any[];
718
+ itemType?: string;
719
+ }
720
+
721
+ export interface FindEntityLogicalFilterOptions<TFilter = EntityFilterOptions> {
722
+ operator: EntityFilterLogicalOperators;
723
+ filters: TFilter[];
724
+ }
725
+
726
+ export interface FindEntityUnaryFilterOptions {
727
+ field: string;
728
+ operator: EntityFilterUnaryOperators;
729
+ }
730
+
731
+ export interface FindEntityExistenceFilterOptions {
732
+ field: string;
733
+ operator: EntityFilterExistenceOperators;
734
+ filters: EntityFilterOptions[];
735
+ includingSoftDeleted?: boolean;
736
+ }
737
+
738
+ export interface FindEntityPaginationOptions {
739
+ offset: number;
740
+ limit: number;
741
+ withoutTotal?: boolean;
742
+ }
743
+
744
+ export type FindEntityFindRelationEntitiesOptions = FindEntityFindOneRelationEntitiesOptions | FindEntityFindManyRelationEntitiesOptions;
745
+
746
+ export type FindEntityFindOneRelationEntitiesOptions =
747
+ | true
748
+ | {
749
+ properties?: string[];
750
+ relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
751
+ keepNonPropertyFields?: boolean;
752
+ includingSoftDeleted?: boolean;
753
+ };
754
+
755
+ export type FindEntityFindManyRelationEntitiesOptions =
756
+ | true
757
+ | {
758
+ properties?: string[];
759
+ relations?: Record<string, FindEntityFindRelationEntitiesOptions>;
760
+ filters?: EntityFilterOptions[];
761
+ orderBy?: FindEntityOrderByOptions[];
762
+ pagination?: FindEntityPaginationOptions;
763
+ keepNonPropertyFields?: boolean;
764
+ includingSoftDeleted?: boolean;
765
+ };
766
+
767
+ export interface FindEntityOrderByOptions {
768
+ field: string;
769
+ desc?: boolean;
770
+ }
771
+
772
+ export interface CountEntityOptions {
773
+ routeContext?: RouteContext;
774
+ filters?: EntityFilterOptions[];
775
+ }
776
+
777
+ export interface CountEntityResult {
778
+ count: number;
779
+ }
780
+
781
+ export interface DeleteEntityByIdOptions {
782
+ routeContext?: RouteContext;
783
+ id: any;
784
+ }
785
+
786
+ export interface CreateEntityOptions {
787
+ routeContext?: RouteContext;
788
+ entity: any;
789
+ postponeUniquenessCheck?: boolean;
790
+ }
791
+
792
+ export interface UpdateEntityOptions {
793
+ routeContext?: RouteContext;
794
+ filters?: EntityFilterOptions[];
795
+ entity: any;
796
+ }
797
+
798
+ export interface UpdateEntityByIdOptions {
799
+ routeContext?: RouteContext;
800
+ id: any;
801
+ entityToSave: any;
802
+ operation?: {
803
+ type: string;
804
+ };
805
+ /**
806
+ * 指定需要更新那几个状态属性(配置了`config.stateMachine`的属性)。当不指定时默认更新全部状态属性。
807
+ */
808
+ stateProperties?: string[];
809
+ postponeUniquenessCheck?: boolean;
810
+ /**
811
+ * 指定需要更新关联对象的哪些属性。更新实体时,会创建关联对象,但是默认不更新关联对象的属性。
812
+ */
813
+ relationPropertiesToUpdate?: Record<string, UpdateRelationPropertyOptions>;
814
+ }
815
+
816
+ export type UpdateRelationPropertyOptions =
817
+ | true
818
+ | {
819
+ // TODO: impl savingMode 'patch'
820
+ // savingMode?: "overwrite" | "patch";
821
+
822
+ /**
823
+ * 当需移除关系时是删除关联实体,还是取消关联。默认为`delete`。此配置仅对没有配置`linkTableName`的属性有效。
824
+ */
825
+ relationRemoveMode?: "unlink" | "delete";
826
+ propertiesToUpdate?: string[];
827
+ relationPropertiesToUpdate?: Record<string, UpdateRelationPropertyOptions>;
828
+ };
829
+
830
+ export interface DeleteEntityOptions {
831
+ routeContext?: RouteContext;
832
+ filters?: EntityFilterOptions[];
833
+ }
834
+
835
+ export interface AddEntityRelationsOptions {
836
+ routeContext?: RouteContext;
837
+ id: number;
838
+ property: string;
839
+ relations: { id?: number; [k: string]: any }[];
840
+ }
841
+
842
+ export interface RemoveEntityRelationsOptions {
843
+ routeContext?: RouteContext;
844
+ id: number;
845
+ property: string;
846
+ relations: { id?: number; [k: string]: any }[];
847
+ }
848
+
849
+ export type EntityWatcherType =
850
+ | EntityWatcher<"entity.beforeCreate">
851
+ | EntityWatcher<"entity.create">
852
+ | EntityWatcher<"entity.beforeUpdate">
853
+ | EntityWatcher<"entity.update">
854
+ | EntityWatcher<"entity.beforeDelete">
855
+ | EntityWatcher<"entity.delete">
856
+ | EntityWatcher<"entity.addRelations">
857
+ | EntityWatcher<"entity.removeRelations">
858
+ | EntityWatcher<"entity.beforeResponse">
859
+ | EntityWatcher<any>;
860
+
861
+ export interface EntityWatcher<TEventName extends keyof RpdServerEventTypes> {
862
+ eventName: TEventName;
863
+ modelSingularCode: string;
864
+ handler: EntityWatchHandler<TEventName>;
865
+ }
866
+
867
+ export type EntityWatchHandler<TEventName extends keyof RpdServerEventTypes> = (ctx: EntityWatchHandlerContext<TEventName>) => Promise<void>;
868
+
869
+ export type EntityWatchHandlerContext<TEventName extends keyof RpdServerEventTypes> = {
870
+ server: IRpdServer;
871
+ payload: RpdServerEventTypes[TEventName][1];
872
+ routerContext: RouteContext;
873
+ };
874
+
875
+ export interface EntityWatchPluginInitOptions {
876
+ watchers: EntityWatcherType[];
877
+ }
878
+
879
+ export interface LocaleString {
880
+ namespace: string;
881
+ name: string;
882
+ lingual: string;
883
+ text?: string;
884
+ }