@ruiapp/rapid-core 0.1.41 → 0.1.43

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 (126) hide show
  1. package/dist/dataAccess/dataAccessTypes.d.ts +63 -0
  2. package/dist/dataAccess/dataAccessor.d.ts +5 -4
  3. package/dist/dataAccess/entityMapper.d.ts +7 -2
  4. package/dist/dataAccess/metaHelper.d.ts +6 -0
  5. package/dist/index.js +576 -324
  6. package/dist/plugins/sequence/SequencePluginTypes.d.ts +1 -0
  7. package/dist/queryBuilder/queryBuilder.d.ts +12 -22
  8. package/dist/types.d.ts +34 -5
  9. package/dist/utilities/errorUtility.d.ts +3 -0
  10. package/package.json +1 -1
  11. package/rollup.config.js +13 -17
  12. package/src/bootstrapApplicationConfig.ts +25 -4
  13. package/src/core/actionHandler.ts +2 -5
  14. package/src/core/eventManager.ts +1 -4
  15. package/src/core/facility.ts +1 -1
  16. package/src/core/http/formDataParser.ts +31 -43
  17. package/src/core/pluginManager.ts +13 -39
  18. package/src/core/providers/runtimeProvider.ts +1 -1
  19. package/src/core/request.ts +3 -3
  20. package/src/core/response.ts +2 -7
  21. package/src/core/routeContext.ts +2 -6
  22. package/src/core/routesBuilder.ts +46 -55
  23. package/src/core/server.ts +8 -34
  24. package/src/dataAccess/dataAccessTypes.ts +86 -0
  25. package/src/dataAccess/dataAccessor.ts +46 -24
  26. package/src/dataAccess/entityManager.ts +294 -245
  27. package/src/dataAccess/entityMapper.ts +32 -15
  28. package/src/dataAccess/filterHelper.ts +1 -3
  29. package/src/dataAccess/metaHelper.ts +45 -0
  30. package/src/dataAccess/propertyMapper.ts +3 -3
  31. package/src/deno-std/datetime/to_imf.ts +2 -17
  32. package/src/deno-std/encoding/base64.ts +1 -5
  33. package/src/deno-std/http/cookie.ts +26 -59
  34. package/src/facilities/log/LogFacility.ts +0 -1
  35. package/src/helpers/entityHelpers.ts +1 -4
  36. package/src/helpers/runCollectionEntityActionHandler.ts +2 -10
  37. package/src/plugins/auth/AuthPlugin.ts +2 -5
  38. package/src/plugins/auth/actionHandlers/changePassword.ts +6 -10
  39. package/src/plugins/auth/actionHandlers/createSession.ts +14 -15
  40. package/src/plugins/auth/actionHandlers/deleteSession.ts +1 -5
  41. package/src/plugins/auth/actionHandlers/getMyProfile.ts +5 -9
  42. package/src/plugins/auth/actionHandlers/index.ts +1 -7
  43. package/src/plugins/auth/actionHandlers/resetPassword.ts +3 -7
  44. package/src/plugins/auth/models/AccessToken.ts +2 -2
  45. package/src/plugins/auth/models/index.ts +1 -3
  46. package/src/plugins/auth/routes/changePassword.ts +1 -1
  47. package/src/plugins/auth/routes/getMyProfile.ts +1 -1
  48. package/src/plugins/auth/routes/index.ts +1 -7
  49. package/src/plugins/auth/routes/resetPassword.ts +1 -1
  50. package/src/plugins/auth/routes/signin.ts +1 -1
  51. package/src/plugins/auth/routes/signout.ts +1 -1
  52. package/src/plugins/cronJob/CronJobPlugin.ts +12 -21
  53. package/src/plugins/cronJob/CronJobPluginTypes.ts +9 -9
  54. package/src/plugins/cronJob/actionHandlers/index.ts +1 -3
  55. package/src/plugins/cronJob/actionHandlers/runCronJob.ts +3 -8
  56. package/src/plugins/cronJob/routes/index.ts +1 -3
  57. package/src/plugins/cronJob/routes/runCronJob.ts +1 -1
  58. package/src/plugins/dataManage/DataManagePlugin.ts +5 -11
  59. package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +1 -5
  60. package/src/plugins/dataManage/actionHandlers/countCollectionEntities.ts +5 -14
  61. package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +8 -9
  62. package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +7 -8
  63. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +1 -5
  64. package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +15 -24
  65. package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +1 -5
  66. package/src/plugins/dataManage/actionHandlers/queryDatabase.ts +1 -5
  67. package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +1 -5
  68. package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +1 -5
  69. package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +5 -6
  70. package/src/plugins/entityWatch/EntityWatchPlugin.ts +18 -17
  71. package/src/plugins/entityWatch/EntityWatchPluginTypes.ts +3 -10
  72. package/src/plugins/fileManage/FileManagePlugin.ts +1 -3
  73. package/src/plugins/fileManage/actionHandlers/downloadDocument.ts +2 -6
  74. package/src/plugins/fileManage/actionHandlers/downloadFile.ts +2 -6
  75. package/src/plugins/fileManage/actionHandlers/uploadFile.ts +3 -7
  76. package/src/plugins/fileManage/routes/downloadDocument.ts +1 -1
  77. package/src/plugins/fileManage/routes/downloadFile.ts +1 -1
  78. package/src/plugins/fileManage/routes/index.ts +1 -5
  79. package/src/plugins/fileManage/routes/uploadFile.ts +1 -1
  80. package/src/plugins/metaManage/MetaManagePlugin.ts +45 -92
  81. package/src/plugins/metaManage/actionHandlers/getMetaModelDetail.ts +1 -5
  82. package/src/plugins/metaManage/actionHandlers/listMetaModels.ts +1 -5
  83. package/src/plugins/metaManage/actionHandlers/listMetaRoutes.ts +1 -5
  84. package/src/plugins/routeManage/RouteManagePlugin.ts +2 -7
  85. package/src/plugins/routeManage/actionHandlers/httpProxy.ts +1 -5
  86. package/src/plugins/sequence/SequencePlugin.ts +14 -16
  87. package/src/plugins/sequence/SequencePluginTypes.ts +20 -29
  88. package/src/plugins/sequence/SequenceService.ts +16 -15
  89. package/src/plugins/sequence/actionHandlers/generateSn.ts +2 -7
  90. package/src/plugins/sequence/actionHandlers/index.ts +1 -3
  91. package/src/plugins/sequence/models/SequenceAutoIncrementRecord.ts +2 -2
  92. package/src/plugins/sequence/models/SequenceRule.ts +2 -2
  93. package/src/plugins/sequence/models/index.ts +1 -4
  94. package/src/plugins/sequence/routes/generateSn.ts +1 -1
  95. package/src/plugins/sequence/routes/index.ts +1 -3
  96. package/src/plugins/sequence/segment-utility.ts +1 -1
  97. package/src/plugins/sequence/segments/autoIncrement.ts +4 -8
  98. package/src/plugins/sequence/segments/dayOfMonth.ts +3 -7
  99. package/src/plugins/sequence/segments/index.ts +1 -8
  100. package/src/plugins/sequence/segments/literal.ts +1 -1
  101. package/src/plugins/sequence/segments/month.ts +3 -7
  102. package/src/plugins/sequence/segments/parameter.ts +3 -7
  103. package/src/plugins/sequence/segments/year.ts +3 -7
  104. package/src/plugins/serverOperation/ServerOperationPlugin.ts +12 -22
  105. package/src/plugins/serverOperation/ServerOperationPluginTypes.ts +1 -1
  106. package/src/plugins/serverOperation/actionHandlers/index.ts +1 -3
  107. package/src/plugins/stateMachine/StateMachinePlugin.ts +19 -22
  108. package/src/plugins/stateMachine/StateMachinePluginTypes.ts +6 -7
  109. package/src/plugins/stateMachine/actionHandlers/index.ts +1 -3
  110. package/src/plugins/stateMachine/actionHandlers/sendStateMachineEvent.ts +3 -7
  111. package/src/plugins/stateMachine/models/StateMachine.ts +2 -2
  112. package/src/plugins/stateMachine/models/index.ts +1 -3
  113. package/src/plugins/stateMachine/routes/index.ts +1 -3
  114. package/src/plugins/stateMachine/routes/sendStateMachineEvent.ts +1 -1
  115. package/src/plugins/webhooks/WebhooksPlugin.ts +9 -41
  116. package/src/polyfill.ts +1 -1
  117. package/src/proxy/mod.ts +4 -13
  118. package/src/queryBuilder/queryBuilder.ts +149 -106
  119. package/src/server.ts +19 -44
  120. package/src/types.ts +54 -79
  121. package/src/utilities/accessControlUtility.ts +4 -4
  122. package/src/utilities/errorUtility.ts +17 -0
  123. package/src/utilities/fsUtility.ts +12 -13
  124. package/src/utilities/httpUtility.ts +1 -5
  125. package/src/utilities/jwtUtility.ts +6 -10
  126. package/tsconfig.json +1 -1
@@ -12,4 +12,4 @@ export default {
12
12
  code: "downloadFile",
13
13
  },
14
14
  ],
15
- } satisfies RpdRoute;
15
+ } satisfies RpdRoute;
@@ -2,8 +2,4 @@ import getMyProfile from "./uploadFile";
2
2
  import signin from "./downloadFile";
3
3
  import signout from "./downloadDocument";
4
4
 
5
- export default [
6
- getMyProfile,
7
- signin,
8
- signout,
9
- ]
5
+ export default [getMyProfile, signin, signout];
@@ -12,4 +12,4 @@ export default {
12
12
  code: "uploadFile",
13
13
  },
14
14
  ],
15
- } satisfies RpdRoute;
15
+ } satisfies RpdRoute;
@@ -2,17 +2,7 @@
2
2
  * Meta manager plugin
3
3
  */
4
4
 
5
- import {
6
- IQueryBuilder,
7
- QuoteTableOptions,
8
- RpdApplicationConfig,
9
- RpdDataModel,
10
- RpdDataModelProperty,
11
- RpdDataPropertyTypes,
12
- RpdEntityCreateEventPayload,
13
- RpdEntityDeleteEventPayload,
14
- RpdEntityUpdateEventPayload,
15
- } from "~/types";
5
+ import { IQueryBuilder, QuoteTableOptions, RpdApplicationConfig, RpdDataModel, RpdDataModelProperty, RpdDataPropertyTypes, RpdEntityCreateEventPayload, RpdEntityDeleteEventPayload, RpdEntityUpdateEventPayload } from "~/types";
16
6
  import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
17
7
 
18
8
  import * as listMetaModels from "./actionHandlers/listMetaModels";
@@ -20,6 +10,7 @@ import * as listMetaRoutes from "./actionHandlers/listMetaRoutes";
20
10
  import * as getMetaModelDetail from "./actionHandlers/getMetaModelDetail";
21
11
  import { isRelationProperty } from "~/utilities/rapidUtility";
22
12
  import { find } from "lodash";
13
+ import { getEntityPropertiesIncludingBase } from "~/dataAccess/metaHelper";
23
14
 
24
15
  class MetaManager implements RapidPlugin {
25
16
  get code(): string {
@@ -49,18 +40,9 @@ class MetaManager implements RapidPlugin {
49
40
  }
50
41
 
51
42
  async registerEventHandlers(server: IRpdServer): Promise<any> {
52
- server.registerEventHandler(
53
- "entity.create",
54
- handleEntityCreateEvent.bind(this, server),
55
- );
56
- server.registerEventHandler(
57
- "entity.update",
58
- handleEntityUpdateEvent.bind(this, server),
59
- );
60
- server.registerEventHandler(
61
- "entity.delete",
62
- handleEntityDeleteEvent.bind(this, server),
63
- );
43
+ server.registerEventHandler("entity.create", handleEntityCreateEvent.bind(this, server));
44
+ server.registerEventHandler("entity.update", handleEntityUpdateEvent.bind(this, server));
45
+ server.registerEventHandler("entity.delete", handleEntityDeleteEvent.bind(this, server));
64
46
  }
65
47
 
66
48
  async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
@@ -81,12 +63,7 @@ class MetaManager implements RapidPlugin {
81
63
 
82
64
  export default MetaManager;
83
65
 
84
-
85
- async function handleEntityCreateEvent(
86
- server: IRpdServer,
87
- sender: RapidPlugin,
88
- payload: RpdEntityCreateEventPayload,
89
- ) {
66
+ async function handleEntityCreateEvent(server: IRpdServer, sender: RapidPlugin, payload: RpdEntityCreateEventPayload) {
90
67
  if (sender === this) {
91
68
  return;
92
69
  }
@@ -97,19 +74,12 @@ async function handleEntityCreateEvent(
97
74
  const model: Partial<RpdDataModel> = payload.after;
98
75
  if (model.tableName) {
99
76
  const model: RpdDataModel = payload.after;
100
- await server.queryDatabaseObject(
101
- `CREATE TABLE ${queryBuilder.quoteTable(model)} ();`,
102
- [],
103
- );
77
+ await server.queryDatabaseObject(`CREATE TABLE ${queryBuilder.quoteTable(model)} ();`, []);
104
78
  }
105
79
  }
106
80
  }
107
81
 
108
- async function handleEntityUpdateEvent(
109
- server: IRpdServer,
110
- sender: RapidPlugin,
111
- payload: RpdEntityUpdateEventPayload,
112
- ) {
82
+ async function handleEntityUpdateEvent(server: IRpdServer, sender: RapidPlugin, payload: RpdEntityUpdateEventPayload) {
113
83
  if (sender === this) {
114
84
  return;
115
85
  }
@@ -120,19 +90,12 @@ async function handleEntityUpdateEvent(
120
90
  const modelChanges: Partial<RpdDataModel> = payload.changes;
121
91
  if (modelChanges.tableName) {
122
92
  const modelBefore: RpdDataModel = payload.before;
123
- await server.queryDatabaseObject(
124
- `ALTER TABLE ${queryBuilder.quoteTable(modelBefore)} RENAME TO ${queryBuilder.quoteTable(modelChanges as QuoteTableOptions)}`,
125
- [],
126
- );
93
+ await server.queryDatabaseObject(`ALTER TABLE ${queryBuilder.quoteTable(modelBefore)} RENAME TO ${queryBuilder.quoteTable(modelChanges as QuoteTableOptions)}`, []);
127
94
  }
128
95
  }
129
96
  }
130
97
 
131
- async function handleEntityDeleteEvent(
132
- server: IRpdServer,
133
- sender: RapidPlugin,
134
- payload: RpdEntityDeleteEventPayload,
135
- ) {
98
+ async function handleEntityDeleteEvent(server: IRpdServer, sender: RapidPlugin, payload: RpdEntityDeleteEventPayload) {
136
99
  if (sender === this) {
137
100
  return;
138
101
  }
@@ -145,10 +108,7 @@ async function handleEntityDeleteEvent(
145
108
 
146
109
  if (payload.modelSingularCode === "model") {
147
110
  const deletedModel: RpdDataModel = payload.before;
148
- await server.queryDatabaseObject(
149
- `DROP TABLE ${queryBuilder.quoteTable(deletedModel)}`,
150
- [],
151
- );
111
+ await server.queryDatabaseObject(`DROP TABLE ${queryBuilder.quoteTable(deletedModel)}`, []);
152
112
  } else if (payload.modelSingularCode === "property") {
153
113
  const deletedProperty: RpdDataModelProperty = payload.before;
154
114
 
@@ -168,33 +128,25 @@ async function handleEntityDeleteEvent(
168
128
  });
169
129
  const model = await dataAccessor.findById((deletedProperty as any).modelId);
170
130
  if (model) {
171
- await server.queryDatabaseObject(
172
- `ALTER TABLE ${queryBuilder.quoteTable(model)} DROP COLUMN ${
173
- queryBuilder.quoteObject(columnNameToDrop)
174
- }`,
175
- [],
176
- );
131
+ await server.queryDatabaseObject(`ALTER TABLE ${queryBuilder.quoteTable(model)} DROP COLUMN ${queryBuilder.quoteObject(columnNameToDrop)}`, []);
177
132
  }
178
133
  }
179
134
  }
180
135
 
181
- function listCollections(
182
- server: IRpdServer,
183
- applicationConfig: RpdApplicationConfig,
184
- ) {
136
+ function listCollections(server: IRpdServer, applicationConfig: RpdApplicationConfig) {
185
137
  const entityManager = server.getEntityManager("model");
186
138
  const model = entityManager.getModel();
187
139
 
140
+ const properties = getEntityPropertiesIncludingBase(server, model);
188
141
  return entityManager.findEntities({
189
- properties: model.properties.map((item) => item.code),
142
+ properties: properties.map((item) => item.code),
190
143
  });
191
144
  }
192
145
 
193
-
194
146
  type TableInformation = {
195
147
  table_schema: string;
196
148
  table_name: string;
197
- }
149
+ };
198
150
 
199
151
  type ColumnInformation = {
200
152
  table_schema: string;
@@ -207,12 +159,9 @@ type ColumnInformation = {
207
159
  character_maximum_length: number;
208
160
  numeric_precision: number;
209
161
  numeric_scale: number;
210
- }
162
+ };
211
163
 
212
- async function syncDatabaseSchema(
213
- server: IRpdServer,
214
- applicationConfig: RpdApplicationConfig,
215
- ) {
164
+ async function syncDatabaseSchema(server: IRpdServer, applicationConfig: RpdApplicationConfig) {
216
165
  const logger = server.getLogger();
217
166
  logger.info("Synchronizing database schema...");
218
167
  const sqlQueryTableInformations = `SELECT table_schema, table_name FROM information_schema.tables`;
@@ -224,7 +173,7 @@ async function syncDatabaseSchema(
224
173
 
225
174
  const expectedTableSchema = model.schema || server.databaseConfig.dbDefaultSchema;
226
175
  const expectedTableName = model.tableName;
227
- const tableInDb = find(tablesInDb, { table_schema: expectedTableSchema, table_name: expectedTableName});
176
+ const tableInDb = find(tablesInDb, { table_schema: expectedTableSchema, table_name: expectedTableName });
228
177
  if (!tableInDb) {
229
178
  await server.queryDatabaseObject(`CREATE TABLE IF NOT EXISTS ${queryBuilder.quoteTable(model)} ()`, []);
230
179
  }
@@ -241,9 +190,9 @@ async function syncDatabaseSchema(
241
190
  let columnDDL;
242
191
  if (isRelationProperty(property)) {
243
192
  if (property.relation === "one") {
244
- const targetModel = applicationConfig.models.find(item => item.singularCode === property.targetSingularCode);
193
+ const targetModel = applicationConfig.models.find((item) => item.singularCode === property.targetSingularCode);
245
194
  if (!targetModel) {
246
- logger.warn(`Cannot find target model with singular code "${property.targetSingularCode}".`)
195
+ logger.warn(`Cannot find target model with singular code "${property.targetSingularCode}".`);
247
196
  }
248
197
 
249
198
  const columnInDb: ColumnInformation | undefined = find(columnsInDb, {
@@ -264,7 +213,7 @@ async function syncDatabaseSchema(
264
213
  }
265
214
  } else if (property.relation === "many") {
266
215
  if (property.linkTableName) {
267
- const tableInDb = find(tablesInDb, { table_schema: property.linkSchema || server.databaseConfig.dbDefaultSchema, table_name: property.linkTableName});
216
+ const tableInDb = find(tablesInDb, { table_schema: property.linkSchema || server.databaseConfig.dbDefaultSchema, table_name: property.linkTableName });
268
217
  if (!tableInDb) {
269
218
  columnDDL = generateLinkTableDDL(queryBuilder, {
270
219
  linkSchema: property.linkSchema,
@@ -274,9 +223,9 @@ async function syncDatabaseSchema(
274
223
  });
275
224
  }
276
225
  } else {
277
- const targetModel = applicationConfig.models.find(item => item.singularCode === property.targetSingularCode);
226
+ const targetModel = applicationConfig.models.find((item) => item.singularCode === property.targetSingularCode);
278
227
  if (!targetModel) {
279
- logger.warn(`Cannot find target model with singular code "${property.targetSingularCode}".`)
228
+ logger.warn(`Cannot find target model with singular code "${property.targetSingularCode}".`);
280
229
  continue;
281
230
  }
282
231
 
@@ -360,15 +309,18 @@ async function syncDatabaseSchema(
360
309
  }
361
310
  }
362
311
 
363
- function generateCreateColumnDDL(queryBuilder: IQueryBuilder, options: {
364
- schema?: string;
365
- tableName: string;
366
- name: string;
367
- type: RpdDataPropertyTypes;
368
- autoIncrement?: boolean;
369
- notNull?: boolean;
370
- defaultValue?: string;
371
- }) {
312
+ function generateCreateColumnDDL(
313
+ queryBuilder: IQueryBuilder,
314
+ options: {
315
+ schema?: string;
316
+ tableName: string;
317
+ name: string;
318
+ type: RpdDataPropertyTypes;
319
+ autoIncrement?: boolean;
320
+ notNull?: boolean;
321
+ defaultValue?: string;
322
+ },
323
+ ) {
372
324
  let columnDDL = `ALTER TABLE ${queryBuilder.quoteTable(options)} ADD`;
373
325
  columnDDL += ` ${queryBuilder.quoteObject(options.name)}`;
374
326
  if (options.type === "integer" && options.autoIncrement) {
@@ -391,13 +343,15 @@ function generateCreateColumnDDL(queryBuilder: IQueryBuilder, options: {
391
343
  return columnDDL;
392
344
  }
393
345
 
394
-
395
- function generateLinkTableDDL(queryBuilder: IQueryBuilder, options: {
396
- linkSchema?: string;
397
- linkTableName: string;
398
- targetIdColumnName: string;
399
- selfIdColumnName: string;
400
- }) {
346
+ function generateLinkTableDDL(
347
+ queryBuilder: IQueryBuilder,
348
+ options: {
349
+ linkSchema?: string;
350
+ linkTableName: string;
351
+ targetIdColumnName: string;
352
+ selfIdColumnName: string;
353
+ },
354
+ ) {
401
355
  let columnDDL = `CREATE TABLE ${queryBuilder.quoteTable({
402
356
  schema: options.linkSchema,
403
357
  tableName: options.linkTableName,
@@ -409,7 +363,6 @@ function generateLinkTableDDL(queryBuilder: IQueryBuilder, options: {
409
363
  return columnDDL;
410
364
  }
411
365
 
412
-
413
366
  const pgPropertyTypeColumnMap: Partial<Record<RpdDataPropertyTypes, string>> = {
414
367
  integer: "int4",
415
368
  long: "int8",
@@ -3,11 +3,7 @@ import { RapidPlugin } from "~/core/server";
3
3
 
4
4
  export const code = "getMetaModelDetail";
5
5
 
6
- export async function handler(
7
- plugin: RapidPlugin,
8
- ctx: ActionHandlerContext,
9
- options: any,
10
- ) {
6
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
11
7
  const { server, input } = ctx;
12
8
  const model = server.getModel(input);
13
9
  ctx.output = model;
@@ -3,11 +3,7 @@ import { RapidPlugin } from "~/core/server";
3
3
 
4
4
  export const code = "listMetaModels";
5
5
 
6
- export async function handler(
7
- plugin: RapidPlugin,
8
- ctx: ActionHandlerContext,
9
- options: any,
10
- ) {
6
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
11
7
  const { applicationConfig } = ctx;
12
8
  ctx.output = { list: applicationConfig.models };
13
9
  }
@@ -3,11 +3,7 @@ import { RapidPlugin } from "~/core/server";
3
3
 
4
4
  export const code = "listMetaRoutes";
5
5
 
6
- export async function handler(
7
- plugin: RapidPlugin,
8
- ctx: ActionHandlerContext,
9
- options: any,
10
- ) {
6
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
11
7
  const { applicationConfig } = ctx;
12
8
  ctx.output = { list: applicationConfig.routes };
13
9
  }
@@ -2,13 +2,10 @@
2
2
  * Route manager plugin
3
3
  */
4
4
 
5
- import {
6
- RpdApplicationConfig,
7
- } from "~/types";
5
+ import { RpdApplicationConfig } from "~/types";
8
6
  import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "~/core/server";
9
7
  import * as httpProxy from "./actionHandlers/httpProxy";
10
8
 
11
-
12
9
  class RouteManager implements RapidPlugin {
13
10
  get code(): string {
14
11
  return "routeManager";
@@ -47,9 +44,7 @@ class RouteManager implements RapidPlugin {
47
44
  logger.info("Loading meta of routes...");
48
45
  const entityManager = server.getEntityManager("route");
49
46
  const routes = await entityManager.findEntities({
50
- orderBy: [
51
- { field: "endpoint" },
52
- ],
47
+ orderBy: [{ field: "endpoint" }],
53
48
  });
54
49
  applicationConfig.routes.push(...routes);
55
50
  } catch (error) {
@@ -5,11 +5,7 @@ import { RapidPlugin } from "~/core/server";
5
5
 
6
6
  export const code = "httpProxy";
7
7
 
8
- export async function handler(
9
- plugin: RapidPlugin,
10
- ctx: ActionHandlerContext,
11
- options: RunProxyHandlerOptions,
12
- ) {
8
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunProxyHandlerOptions) {
13
9
  const { logger } = ctx;
14
10
  logger.debug(`Running ${code} handler...`);
15
11
 
@@ -2,12 +2,7 @@
2
2
  * Sequence plugin
3
3
  */
4
4
 
5
- import {
6
- CreateEntityOptions,
7
- RpdApplicationConfig,
8
- RpdDataModel,
9
- RpdDataModelProperty,
10
- } from "~/types";
5
+ import { CreateEntityOptions, RpdApplicationConfig, RpdDataModel, RpdDataModelProperty } from "~/types";
11
6
  import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
12
7
 
13
8
  import pluginActionHandlers from "./actionHandlers";
@@ -17,7 +12,7 @@ import { PropertySequenceConfig } from "./SequencePluginTypes";
17
12
  import { isEqual } from "lodash";
18
13
  import SequenceService from "./SequenceService";
19
14
  import { isNullOrUndefined } from "~/utilities/typeUtility";
20
-
15
+ import { getEntityPropertiesIncludingBase } from "~/dataAccess/metaHelper";
21
16
 
22
17
  class SequencePlugin implements RapidPlugin {
23
18
  #sequenceService!: SequenceService;
@@ -55,7 +50,7 @@ class SequencePlugin implements RapidPlugin {
55
50
  async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
56
51
  server.appendApplicationConfig({ models: pluginModels });
57
52
  }
58
-
53
+
59
54
  async configureServices(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
60
55
  this.#sequenceService = new SequenceService(server);
61
56
  server.registerService("sequenceService", this.#sequenceService);
@@ -68,7 +63,7 @@ class SequencePlugin implements RapidPlugin {
68
63
  async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig) {
69
64
  const models = server.getApplicationConfig().models;
70
65
  for (const model of models) {
71
- for (const property of model.properties) {
66
+ for (const property of getEntityPropertiesIncludingBase(server, model)) {
72
67
  const propertySequenceConfig: PropertySequenceConfig = property.config?.sequence;
73
68
  if (propertySequenceConfig) {
74
69
  const ruleCode = getSequenceRuleCode(model, property);
@@ -81,7 +76,9 @@ class SequencePlugin implements RapidPlugin {
81
76
  filters: [
82
77
  {
83
78
  operator: "eq",
84
- field: "code",
79
+ field: {
80
+ name: "code",
81
+ },
85
82
  value: ruleCode,
86
83
  },
87
84
  ],
@@ -106,13 +103,10 @@ class SequencePlugin implements RapidPlugin {
106
103
 
107
104
  async beforeCreateEntity(server: IRpdServer, model: RpdDataModel, options: CreateEntityOptions) {
108
105
  const entity = options.entity;
109
- for (const property of model.properties) {
106
+ for (const property of getEntityPropertiesIncludingBase(server, model)) {
110
107
  const sequenceConfig: PropertySequenceConfig = property.config?.sequence;
111
108
  const propertyValue = entity[property.code];
112
- if (sequenceConfig &&
113
- sequenceConfig.enabled &&
114
- isNullOrUndefined(propertyValue)
115
- ) {
109
+ if (sequenceConfig && sequenceConfig.enabled && isNullOrUndefined(propertyValue)) {
116
110
  const ruleCode = getSequenceRuleCode(model, property);
117
111
  const numbers = await this.#sequenceService.generateSn(server, {
118
112
  ruleCode,
@@ -126,7 +120,11 @@ class SequencePlugin implements RapidPlugin {
126
120
  }
127
121
 
128
122
  function getSequenceRuleCode(model: RpdDataModel, property: RpdDataModelProperty) {
129
- return `propertyAutoGenerate.${model.namespace}.${model.singularCode}.${property.code}`;
123
+ if (property.isBaseProperty) {
124
+ return `propertyAutoGenerate.${model.namespace}.${model.base}.${property.code}`;
125
+ } else {
126
+ return `propertyAutoGenerate.${model.namespace}.${model.singularCode}.${property.code}`;
127
+ }
130
128
  }
131
129
 
132
130
  export default SequencePlugin;
@@ -1,70 +1,61 @@
1
1
  export type PropertySequenceConfig = {
2
2
  enabled: boolean;
3
3
  config: SequenceRuleConfig;
4
- }
4
+ };
5
5
 
6
6
  export type SequenceRuleConfig = {
7
7
  segments: SequenceSegmentConfig[];
8
- }
8
+ };
9
9
 
10
-
11
- export type SequenceSegmentConfig =
12
- | SequenceLiteralSegmentConfig
13
- | SequenceYearSegmentConfig
14
- | SequenceMonthSegmentConfig
15
- | SequenceDayOfMonthSegmentConfig
16
- | SequenceDayOfWeekSegmentConfig
17
- | SequenceDayOfYearSegmentConfig
18
- | SequenceParameterSegmentConfig
19
- | SequenceAutoIncrementSegmentConfig
20
- ;
10
+ export type SequenceSegmentConfig = SequenceLiteralSegmentConfig | SequenceYearSegmentConfig | SequenceMonthSegmentConfig | SequenceDayOfMonthSegmentConfig | SequenceDayOfWeekSegmentConfig | SequenceDayOfYearSegmentConfig | SequenceParameterSegmentConfig | SequenceAutoIncrementSegmentConfig;
21
11
 
22
12
  export type SequenceLiteralSegmentConfig = {
23
- type: "literal",
13
+ type: "literal";
24
14
  content: string;
25
- }
15
+ };
26
16
 
27
17
  export type SequenceYearSegmentConfig = {
28
- type: "year",
18
+ type: "year";
29
19
  padding?: string;
30
20
  length?: number;
31
- }
21
+ };
32
22
 
33
23
  export type SequenceMonthSegmentConfig = {
34
- type: "month",
24
+ type: "month";
35
25
  padding?: string;
36
26
  length?: number;
37
- }
27
+ };
38
28
 
39
29
  export type SequenceDayOfMonthSegmentConfig = {
40
- type: "dayOfMonth",
30
+ type: "dayOfMonth";
41
31
  padding?: string;
42
32
  length?: number;
43
- }
33
+ };
44
34
 
45
35
  export type SequenceDayOfWeekSegmentConfig = {
46
- type: "dayOfWeek",
36
+ type: "dayOfWeek";
47
37
  padding?: string;
48
38
  length?: number;
49
- }
39
+ };
50
40
 
51
41
  export type SequenceDayOfYearSegmentConfig = {
52
- type: "dayOfYear",
42
+ type: "dayOfYear";
53
43
  padding?: string;
54
44
  length?: number;
55
- }
45
+ };
56
46
 
57
47
  export type SequenceParameterSegmentConfig = {
58
- type: "parameter",
48
+ type: "parameter";
59
49
  parameterName: string;
50
+ defaultContent?: string;
60
51
  padding?: string;
61
52
  length?: number;
62
- }
53
+ };
63
54
 
64
55
  export type SequenceAutoIncrementSegmentConfig = {
65
- type: "autoIncrement",
56
+ type: "autoIncrement";
66
57
  scope?: string;
67
58
  period?: "forever" | "day" | "month" | "year";
68
59
  padding?: string;
69
60
  length?: number;
70
- }
61
+ };
@@ -29,52 +29,53 @@ export default class SequenceService {
29
29
  const sequenceNumbers = [];
30
30
  const { ruleCode, parameters } = input;
31
31
  let { amount } = input;
32
-
32
+
33
33
  if (!amount) {
34
34
  amount = 1;
35
35
  }
36
-
36
+
37
37
  const sequenceRuleDataAccessor = server.getDataAccessor({
38
38
  singularCode: "sequence_rule",
39
39
  });
40
-
40
+
41
41
  const sequenceRule = await sequenceRuleDataAccessor.findOne({
42
42
  filters: [
43
43
  {
44
44
  operator: "eq",
45
- field: "code",
45
+ field: {
46
+ name: "code",
47
+ },
46
48
  value: ruleCode,
47
- }
48
- ]
49
+ },
50
+ ],
49
51
  });
50
-
52
+
51
53
  if (!sequenceRule) {
52
54
  throw new Error(`Failed to generate sequence number. Sequence with code '${sequenceRule.code}' not found.`);
53
55
  }
54
-
56
+
55
57
  const sequenceConfig: SequenceRuleConfig = sequenceRule.config;
56
58
  if (!sequenceConfig || !sequenceConfig.segments) {
57
59
  throw new Error("Failed to generate sequence number. Sequence not configured.");
58
60
  }
59
-
61
+
60
62
  for (let i = 0; i < amount; i++) {
61
63
  let sequenceNumber: string = "";
62
-
64
+
63
65
  for (const segmentConfig of sequenceConfig.segments) {
64
66
  const segmentResolver: SegmentResolver = find(segmentResolvers, (item) => item.segmentType === segmentConfig.type);
65
67
  if (!segmentResolver) {
66
68
  // TODO: deal with unkown segment type
67
69
  continue;
68
70
  }
69
-
71
+
70
72
  const segment = await segmentResolver.resolveSegmentValue(server, ruleCode, segmentConfig, input);
71
73
  sequenceNumber += segment;
72
74
  }
73
-
75
+
74
76
  sequenceNumbers.push(sequenceNumber);
75
77
  }
76
-
78
+
77
79
  return sequenceNumbers;
78
80
  }
79
-
80
- }
81
+ }
@@ -6,17 +6,12 @@ export interface GenerateSequenceNumbersOptions {
6
6
  ruleCode: string;
7
7
  }
8
8
 
9
-
10
9
  export const code = "generateSn";
11
10
 
12
- export async function handler(
13
- plugin: RapidPlugin,
14
- ctx: ActionHandlerContext,
15
- options: GenerateSequenceNumbersOptions,
16
- ) {
11
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: GenerateSequenceNumbersOptions) {
17
12
  const { server, routerContext } = ctx;
18
13
  const { response } = routerContext;
19
-
14
+
20
15
  const input: GenerateSequenceNumbersInput = ctx.input;
21
16
 
22
17
  if (options?.ruleCode) {
@@ -1,6 +1,4 @@
1
1
  import { IPluginActionHandler } from "~/core/actionHandler";
2
2
  import * as generateSn from "./generateSn";
3
3
 
4
- export default [
5
- generateSn,
6
- ] satisfies IPluginActionHandler[];
4
+ export default [generateSn] satisfies IPluginActionHandler[];
@@ -1,6 +1,6 @@
1
1
  import { RpdDataModel } from "~/types";
2
2
 
3
- export default {
3
+ export default {
4
4
  maintainedBy: "sequencePlugin",
5
5
  namespace: "svc",
6
6
  name: "sequence_auto_increment_record",
@@ -46,4 +46,4 @@ export default {
46
46
  required: true,
47
47
  },
48
48
  ],
49
- } as RpdDataModel;
49
+ } as RpdDataModel;
@@ -1,6 +1,6 @@
1
1
  import { RpdDataModel } from "~/types";
2
2
 
3
- export default {
3
+ export default {
4
4
  maintainedBy: "sequencePlugin",
5
5
  namespace: "svc",
6
6
  name: "sequence_rule",
@@ -39,4 +39,4 @@ export default {
39
39
  required: false,
40
40
  },
41
41
  ],
42
- } as RpdDataModel;
42
+ } as RpdDataModel;