@ruiapp/rapid-core 0.5.11 → 0.5.13

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