@ruiapp/rapid-core 0.1.83 → 0.2.0

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