@ruiapp/rapid-core 0.9.9 → 0.10.1

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