@ruiapp/rapid-core 0.1.72 → 0.1.74

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.
package/src/types.ts CHANGED
@@ -1,593 +1,617 @@
1
- import { RouteContext } from "./core/routeContext";
2
- import { IRpdServer, RapidPlugin } from "./core/server";
3
- import { ColumnSelectOptions, CountRowOptions, FindRowOptions } 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
- }
176
-
177
- export interface RpdApplicationConfig {
178
- code?: string;
179
- name?: string;
180
- models: RpdDataModel[];
181
- routes: RpdRoute[];
182
- }
183
-
184
- export interface RpdDataModel {
185
- maintainedBy?: string;
186
- name: string;
187
- namespace: string;
188
- singularCode: string;
189
- pluralCode: string;
190
- schema?: string;
191
- tableName: string;
192
- /**
193
- * Configure the singular code of base entity.
194
- */
195
- base?: string;
196
- /**
197
- * Configure the type of derived entity.
198
- */
199
- derivedType?: string;
200
- /**
201
- * Configure the property code to save derived type for base entity.
202
- */
203
- derivedTypePropertyCode?: string;
204
- /**
205
- * Configure the property code used to display the entity.
206
- */
207
- displayPropertyCode?: string;
208
- properties: RpdDataModelProperty[];
209
- extensions?: RpdDataModelExtension[];
210
- permissionPolicies?: RpdDataModelPermissionPolicies;
211
- }
212
-
213
- export interface RpdDataModelPermissionPolicies {
214
- find?: PermissionPolicy;
215
- create?: PermissionPolicy;
216
- update?: PermissionPolicy;
217
- delete?: PermissionPolicy;
218
- }
219
-
220
- export interface PermissionPolicy {
221
- any?: string[];
222
- all?: string[];
223
- }
224
-
225
- export interface RpdDataModelProperty {
226
- /**
227
- * 表示此属性由谁来维护
228
- */
229
- maintainedBy?: string;
230
- /**
231
- * 表示是否基础属性
232
- */
233
- isBaseProperty?: boolean;
234
- /**
235
- * 字段名称。可以包含中文。
236
- */
237
- name: string;
238
- /**
239
- * 字段代码。会用于数据表列名和 API 的字段名。
240
- */
241
- code: string;
242
- /**
243
- * 数据表列名。如果没有设置则使用 code。
244
- */
245
- columnName?: string;
246
- /**
247
- * 字段类型。
248
- */
249
- type: RpdDataPropertyTypes;
250
- /**
251
- * 是否必须有值。默认为 false。
252
- */
253
- required?: boolean;
254
- /**
255
- * 默认值。使用默认值的 SQL 表达式表示。
256
- */
257
- defaultValue?: string;
258
- /**
259
- * 属性配置。
260
- */
261
- // deno-lint-ignore no-explicit-any
262
- config?: Record<string, any>;
263
- /**
264
- * 是否自增长。
265
- */
266
- autoIncrement?: boolean;
267
- /**
268
- * 字段值的最小长度。
269
- */
270
- minLength?: number;
271
- /**
272
- * 字段值的最大长度。
273
- */
274
- maxLength?: number;
275
- /**
276
- * 当 type 为 relation 时,设置关联实体为一个还是多个。
277
- */
278
- relation?: "one" | "many";
279
- /**
280
- * 关联实体的singular code,不管 relation one 或者 many 都需要设置。
281
- */
282
- targetSingularCode?: string;
283
- /**
284
- * 当 relation 为 one 时,设置当前模型表中表示关联实体 id 的列名。
285
- * 当 relation 为 many,并且使用关联关系表保存关联信息时,设置关联关系表中表示关联实体 id 的列名。
286
- * 当 relation 为 many,并且不使用关联关系表保存关联信息时,关联实体 id 的列名默认为`id`,此时可以不设置 targetIdColumnName。
287
- */
288
- targetIdColumnName?: string;
289
- /**
290
- * 当 relation 为 many 时,设置目标模型表或关联关系表中表示自身实体 id 的列名。
291
- */
292
- selfIdColumnName?: string;
293
- /**
294
- * 当 relation 为 many 时,可以使用关联关系表保存关联信息,此时需要设置关联关系表的名称。
295
- */
296
- linkTableName?: string;
297
- /**
298
- * 当设置了 linkTableName 时,可以设置关联关系表所在的 Schema。
299
- */
300
- linkSchema?: string;
301
- }
302
-
303
- export type RpdDataPropertyTypes =
304
- | "integer"
305
- | "long"
306
- | "float"
307
- | "double"
308
- | "decimal"
309
- | "text"
310
- | "boolean"
311
- | "date"
312
- | "time"
313
- | "datetime"
314
- | "json"
315
- | "relation"
316
- | "relation[]"
317
- | "option";
318
-
319
- /**
320
- * 数据字典
321
- */
322
- export type RpdDataDictionary = {
323
- /**
324
- * 字典编码
325
- */
326
- code: string;
327
-
328
- /**
329
- * 字典名称
330
- */
331
- description?: string;
332
-
333
- /**
334
- * 字典项值类型
335
- */
336
- type: "string" | "integer";
337
-
338
- /**
339
- * 字典项
340
- */
341
- entries: RpdDataDictionaryEntry[];
342
- };
343
-
344
- /**
345
- * 数据字典项
346
- */
347
- export type RpdDataDictionaryEntry = {
348
- /**
349
- * 名称
350
- */
351
- name: string;
352
-
353
- /**
354
- * 值
355
- */
356
- value: string;
357
-
358
- /**
359
- * 描述
360
- */
361
- description?: string;
362
-
363
- /**
364
- * 排序号
365
- */
366
- orderNum: number;
367
-
368
- /**
369
- * 是否禁用
370
- */
371
- disabled: boolean;
372
- };
373
-
374
- export interface RpdDataModelExtension {
375
- code: string;
376
- config: any;
377
- }
378
-
379
- export type EventHandler<T = any> = (sender: RapidPlugin, payload: T) => void;
380
-
381
- export interface RpdRoute {
382
- name: string;
383
- namespace: string;
384
- code: string;
385
- type: "RESTful";
386
- method: RpdHttpMethod;
387
- endpoint: string;
388
- actions: RpdRouteActionConfig[];
389
- }
390
-
391
- export type RpdHttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
392
-
393
- export interface RpdRouteActionConfig {
394
- code: string;
395
- config?: any;
396
- }
397
-
398
- export interface IRpdDataAccessor<T = any> {
399
- getModel(): RpdDataModel;
400
- create(entity: any): Promise<any>;
401
- updateById(id: any, entity: any): Promise<any>;
402
- find(options: FindRowOptions): Promise<T[]>;
403
- findOne(options: FindRowOptions): Promise<T | null>;
404
- findById(id: any): Promise<T | null>;
405
- count(options: CountRowOptions): Promise<any>;
406
- deleteById(id: any): Promise<void>;
407
- }
408
-
409
- export type EntityFilterRelationalOperators =
410
- | "eq"
411
- | "ne"
412
- | "lt"
413
- | "lte"
414
- | "gt"
415
- | "gte"
416
- | "contains"
417
- | "notContains"
418
- | "containsCS"
419
- | "notContainsCS"
420
- | "startsWith"
421
- | "notStartsWith"
422
- | "endsWith"
423
- | "notEndsWith";
424
-
425
- export type EntityFilterSetOperators = "in" | "notIn";
426
-
427
- export type EntityFilterLogicalOperators = "or" | "and";
428
-
429
- export type EntityFilterUnaryOperators = "null" | "notNull";
430
-
431
- export type EntityFilterExistenceOperators = "exists" | "notExists";
432
-
433
- export type EntityFilterOperators =
434
- | EntityFilterRelationalOperators
435
- | EntityFilterSetOperators
436
- | EntityFilterLogicalOperators
437
- | EntityFilterUnaryOperators
438
- | EntityFilterExistenceOperators;
439
-
440
- export type EntityFilterOptions =
441
- | FindEntityRelationalFilterOptions
442
- | FindEntitySetFilterOptions
443
- | FindEntityLogicalFilterOptions
444
- | FindEntityUnaryFilterOptions
445
- | FindEntityExistenceFilterOptions;
446
-
447
- export type EntityNonRelationPropertyFilterOptions = FindEntityRelationalFilterOptions | FindEntitySetFilterOptions | FindEntityUnaryFilterOptions;
448
-
449
- export interface FindEntityOptions {
450
- routeContext?: RouteContext;
451
- filters?: EntityFilterOptions[];
452
- orderBy?: FindEntityOrderByOptions[];
453
- pagination?: FindEntityPaginationOptions;
454
- properties?: string[];
455
- relations?: Record<string, FindEntitySelectRelationOptions>;
456
- extraColumnsToSelect?: ColumnSelectOptions[];
457
- keepNonPropertyFields?: boolean;
458
- }
459
-
460
- export interface FindEntityByIdOptions {
461
- routeContext?: RouteContext;
462
- id: any;
463
- properties?: string[];
464
- relations?: Record<string, FindEntitySelectRelationOptions>;
465
- keepNonPropertyFields?: boolean;
466
- }
467
-
468
- export interface FindEntityRelationalFilterOptions {
469
- field: string;
470
- operator: EntityFilterRelationalOperators;
471
- value: any;
472
- }
473
-
474
- export interface FindEntitySetFilterOptions {
475
- field: string;
476
- operator: EntityFilterSetOperators;
477
- value: any[];
478
- itemType?: string;
479
- }
480
-
481
- export interface FindEntityLogicalFilterOptions {
482
- operator: EntityFilterLogicalOperators;
483
- filters: EntityFilterOptions[];
484
- }
485
-
486
- export interface FindEntityUnaryFilterOptions {
487
- field: string;
488
- operator: EntityFilterUnaryOperators;
489
- }
490
-
491
- export interface FindEntityExistenceFilterOptions {
492
- field: string;
493
- operator: EntityFilterExistenceOperators;
494
- filters: EntityFilterOptions[];
495
- }
496
-
497
- export interface FindEntityPaginationOptions {
498
- offset: number;
499
- limit: number;
500
- withoutTotal?: boolean;
501
- }
502
-
503
- export type FindEntitySelectRelationOptions =
504
- | true
505
- | {
506
- properties?: string[];
507
- relations?: Record<string, FindEntitySelectRelationOptions>;
508
- };
509
-
510
- export interface FindEntityOrderByOptions {
511
- field: string;
512
- desc?: boolean;
513
- }
514
-
515
- export interface CountEntityOptions {
516
- routeContext?: RouteContext;
517
- filters?: EntityFilterOptions[];
518
- }
519
-
520
- export interface CountEntityResult {
521
- count: number;
522
- }
523
-
524
- export interface DeleteEntityByIdOptions {
525
- routeContext?: RouteContext;
526
- id: any;
527
- }
528
-
529
- export interface CreateEntityOptions {
530
- routeContext?: RouteContext;
531
- entity: any;
532
- }
533
-
534
- export interface UpdateEntityOptions {
535
- routeContext?: RouteContext;
536
- filters?: EntityFilterOptions[];
537
- entity: any;
538
- }
539
-
540
- export interface UpdateEntityByIdOptions {
541
- routeContext?: RouteContext;
542
- id: any;
543
- entityToSave: any;
544
- operation?: {
545
- type: string;
546
- };
547
- stateProperties?: string[];
548
- }
549
-
550
- export interface DeleteEntityOptions {
551
- routeContext?: RouteContext;
552
- filters?: EntityFilterOptions[];
553
- }
554
-
555
- export interface AddEntityRelationsOptions {
556
- routeContext?: RouteContext;
557
- id: number;
558
- property: string;
559
- relations: { id?: number; [k: string]: any }[];
560
- }
561
-
562
- export interface RemoveEntityRelationsOptions {
563
- routeContext?: RouteContext;
564
- id: number;
565
- property: string;
566
- relations: { id?: number; [k: string]: any }[];
567
- }
568
-
569
- export type EntityWatcherType =
570
- | EntityWatcher<"entity.create">
571
- | EntityWatcher<"entity.update">
572
- | EntityWatcher<"entity.delete">
573
- | EntityWatcher<"entity.addRelations">
574
- | EntityWatcher<"entity.removeRelations">
575
- | EntityWatcher<any>;
576
-
577
- export interface EntityWatcher<TEventName extends keyof RpdServerEventTypes = any> {
578
- eventName: TEventName;
579
- modelSingularCode: string;
580
- handler: EntityWatchHandler<TEventName>;
581
- }
582
-
583
- export type EntityWatchHandler<TEventName extends keyof RpdServerEventTypes> = (ctx: EntityWatchHandlerContext<TEventName>) => Promise<void>;
584
-
585
- export type EntityWatchHandlerContext<TEventName extends keyof RpdServerEventTypes> = {
586
- server: IRpdServer;
587
- payload: RpdServerEventTypes[TEventName][1];
588
- routerContext?: RouteContext;
589
- };
590
-
591
- export interface EntityWatchPluginInitOptions {
592
- watchers: EntityWatcherType[];
593
- }
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
+
321
+ /**
322
+ * 数据字典
323
+ */
324
+ export type RpdDataDictionary = {
325
+ /**
326
+ * 字典编码
327
+ */
328
+ code: string;
329
+
330
+ /**
331
+ * 字典名称
332
+ */
333
+ description?: string;
334
+
335
+ /**
336
+ * 字典项值类型
337
+ */
338
+ type: "string" | "integer";
339
+
340
+ /**
341
+ * 字典项
342
+ */
343
+ entries: RpdDataDictionaryEntry[];
344
+ };
345
+
346
+ /**
347
+ * 数据字典项
348
+ */
349
+ export type RpdDataDictionaryEntry = {
350
+ /**
351
+ * 名称
352
+ */
353
+ name: string;
354
+
355
+ /**
356
+ *
357
+ */
358
+ value: string;
359
+
360
+ /**
361
+ * 描述
362
+ */
363
+ description?: string;
364
+
365
+ /**
366
+ * 排序号
367
+ */
368
+ orderNum: number;
369
+
370
+ /**
371
+ * 是否禁用
372
+ */
373
+ disabled: boolean;
374
+ };
375
+
376
+ export interface RpdDataModelExtension {
377
+ code: string;
378
+ config: any;
379
+ }
380
+
381
+ export interface RpdDataModelIndex {
382
+ name?: string;
383
+ unique?: boolean;
384
+ properties: RpdDataModelIndexPropertyConfig[];
385
+ conditions?: RpdDataModelIndexOptions[];
386
+ }
387
+
388
+ export type RpdDataModelIndexPropertyConfig =
389
+ | string
390
+ | {
391
+ code: string;
392
+ order?: "asc" | "desc";
393
+ };
394
+
395
+ export type RpdDataModelIndexOptions =
396
+ | FindEntityRelationalFilterOptions
397
+ | FindEntitySetFilterOptions
398
+ | FindEntityLogicalFilterOptions<RpdDataModelIndexOptions>
399
+ | FindEntityUnaryFilterOptions;
400
+
401
+ export type EventHandler<T = any> = (sender: RapidPlugin, payload: T) => void;
402
+
403
+ export interface RpdRoute {
404
+ name: string;
405
+ namespace: string;
406
+ code: string;
407
+ type: "RESTful";
408
+ method: RpdHttpMethod;
409
+ endpoint: string;
410
+ actions: RpdRouteActionConfig[];
411
+ }
412
+
413
+ export type RpdHttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
414
+
415
+ export interface RpdRouteActionConfig {
416
+ code: string;
417
+ config?: any;
418
+ }
419
+
420
+ export interface IRpdDataAccessor<T = any> {
421
+ getModel(): RpdDataModel;
422
+ create(entity: any): Promise<any>;
423
+ updateById(id: any, entity: any): Promise<any>;
424
+ find(options: FindRowOptions): Promise<T[]>;
425
+ findOne(options: FindRowOptions): Promise<T | null>;
426
+ findById(id: any): Promise<T | null>;
427
+ count(options: CountRowOptions): Promise<any>;
428
+ deleteById(id: any): Promise<void>;
429
+ }
430
+
431
+ export type EntityFilterRelationalOperators =
432
+ | "eq"
433
+ | "ne"
434
+ | "lt"
435
+ | "lte"
436
+ | "gt"
437
+ | "gte"
438
+ | "contains"
439
+ | "notContains"
440
+ | "containsCS"
441
+ | "notContainsCS"
442
+ | "startsWith"
443
+ | "notStartsWith"
444
+ | "endsWith"
445
+ | "notEndsWith";
446
+
447
+ export type EntityFilterSetOperators = "in" | "notIn";
448
+
449
+ export type EntityFilterLogicalOperators = "or" | "and";
450
+
451
+ export type EntityFilterUnaryOperators = "null" | "notNull";
452
+
453
+ export type EntityFilterExistenceOperators = "exists" | "notExists";
454
+
455
+ export type EntityFilterOperators =
456
+ | EntityFilterRelationalOperators
457
+ | EntityFilterSetOperators
458
+ | EntityFilterLogicalOperators
459
+ | EntityFilterUnaryOperators
460
+ | EntityFilterExistenceOperators;
461
+
462
+ export type EntityFilterOptions =
463
+ | FindEntityRelationalFilterOptions
464
+ | FindEntitySetFilterOptions
465
+ | FindEntityLogicalFilterOptions
466
+ | FindEntityUnaryFilterOptions
467
+ | FindEntityExistenceFilterOptions;
468
+
469
+ export type EntityNonRelationPropertyFilterOptions = FindEntityRelationalFilterOptions | FindEntitySetFilterOptions | FindEntityUnaryFilterOptions;
470
+
471
+ export interface FindEntityOptions {
472
+ routeContext?: RouteContext;
473
+ filters?: EntityFilterOptions[];
474
+ orderBy?: FindEntityOrderByOptions[];
475
+ pagination?: FindEntityPaginationOptions;
476
+ properties?: string[];
477
+ relations?: Record<string, FindEntitySelectRelationOptions>;
478
+ extraColumnsToSelect?: ColumnSelectOptions[];
479
+ keepNonPropertyFields?: boolean;
480
+ }
481
+
482
+ export interface FindEntityByIdOptions {
483
+ routeContext?: RouteContext;
484
+ id: any;
485
+ properties?: string[];
486
+ relations?: Record<string, FindEntitySelectRelationOptions>;
487
+ keepNonPropertyFields?: boolean;
488
+ }
489
+
490
+ export interface FindEntityRelationalFilterOptions {
491
+ field: string;
492
+ operator: EntityFilterRelationalOperators;
493
+ value: any;
494
+ }
495
+
496
+ export interface FindEntitySetFilterOptions {
497
+ field: string;
498
+ operator: EntityFilterSetOperators;
499
+ value: any[];
500
+ itemType?: string;
501
+ }
502
+
503
+ export interface FindEntityLogicalFilterOptions<TFilter = EntityFilterOptions> {
504
+ operator: EntityFilterLogicalOperators;
505
+ filters: TFilter[];
506
+ }
507
+
508
+ export interface FindEntityUnaryFilterOptions {
509
+ field: string;
510
+ operator: EntityFilterUnaryOperators;
511
+ }
512
+
513
+ export interface FindEntityExistenceFilterOptions {
514
+ field: string;
515
+ operator: EntityFilterExistenceOperators;
516
+ filters: EntityFilterOptions[];
517
+ }
518
+
519
+ export interface FindEntityPaginationOptions {
520
+ offset: number;
521
+ limit: number;
522
+ withoutTotal?: boolean;
523
+ }
524
+
525
+ export type FindEntitySelectRelationOptions =
526
+ | true
527
+ | {
528
+ properties?: string[];
529
+ relations?: Record<string, FindEntitySelectRelationOptions>;
530
+ };
531
+
532
+ export interface FindEntityOrderByOptions {
533
+ field: string;
534
+ desc?: boolean;
535
+ }
536
+
537
+ export interface CountEntityOptions {
538
+ routeContext?: RouteContext;
539
+ filters?: EntityFilterOptions[];
540
+ }
541
+
542
+ export interface CountEntityResult {
543
+ count: number;
544
+ }
545
+
546
+ export interface DeleteEntityByIdOptions {
547
+ routeContext?: RouteContext;
548
+ id: any;
549
+ }
550
+
551
+ export interface CreateEntityOptions {
552
+ routeContext?: RouteContext;
553
+ entity: any;
554
+ postponeUniquenessCheck?: boolean;
555
+ }
556
+
557
+ export interface UpdateEntityOptions {
558
+ routeContext?: RouteContext;
559
+ filters?: EntityFilterOptions[];
560
+ entity: any;
561
+ }
562
+
563
+ export interface UpdateEntityByIdOptions {
564
+ routeContext?: RouteContext;
565
+ id: any;
566
+ entityToSave: any;
567
+ operation?: {
568
+ type: string;
569
+ };
570
+ stateProperties?: string[];
571
+ postponeUniquenessCheck?: boolean;
572
+ }
573
+
574
+ export interface DeleteEntityOptions {
575
+ routeContext?: RouteContext;
576
+ filters?: EntityFilterOptions[];
577
+ }
578
+
579
+ export interface AddEntityRelationsOptions {
580
+ routeContext?: RouteContext;
581
+ id: number;
582
+ property: string;
583
+ relations: { id?: number; [k: string]: any }[];
584
+ }
585
+
586
+ export interface RemoveEntityRelationsOptions {
587
+ routeContext?: RouteContext;
588
+ id: number;
589
+ property: string;
590
+ relations: { id?: number; [k: string]: any }[];
591
+ }
592
+
593
+ export type EntityWatcherType =
594
+ | EntityWatcher<"entity.create">
595
+ | EntityWatcher<"entity.update">
596
+ | EntityWatcher<"entity.delete">
597
+ | EntityWatcher<"entity.addRelations">
598
+ | EntityWatcher<"entity.removeRelations">
599
+ | EntityWatcher<any>;
600
+
601
+ export interface EntityWatcher<TEventName extends keyof RpdServerEventTypes = any> {
602
+ eventName: TEventName;
603
+ modelSingularCode: string;
604
+ handler: EntityWatchHandler<TEventName>;
605
+ }
606
+
607
+ export type EntityWatchHandler<TEventName extends keyof RpdServerEventTypes> = (ctx: EntityWatchHandlerContext<TEventName>) => Promise<void>;
608
+
609
+ export type EntityWatchHandlerContext<TEventName extends keyof RpdServerEventTypes> = {
610
+ server: IRpdServer;
611
+ payload: RpdServerEventTypes[TEventName][1];
612
+ routerContext?: RouteContext;
613
+ };
614
+
615
+ export interface EntityWatchPluginInitOptions {
616
+ watchers: EntityWatcherType[];
617
+ }