@ruiapp/rapid-core 0.1.83 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +64 -25
  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 +1507 -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
@@ -5,6 +5,7 @@ declare const _default: {
5
5
  maintainedBy: string;
6
6
  namespace: string;
7
7
  name: string;
8
+ code: string;
8
9
  singularCode: string;
9
10
  pluralCode: string;
10
11
  schema: string;
@@ -77,6 +78,7 @@ declare const _default: {
77
78
  maintainedBy: string;
78
79
  namespace: string;
79
80
  name: string;
81
+ code: string;
80
82
  singularCode: string;
81
83
  pluralCode: string;
82
84
  schema: string;
@@ -170,6 +172,7 @@ declare const _default: {
170
172
  maintainedBy: string;
171
173
  namespace: string;
172
174
  name: string;
175
+ code: string;
173
176
  singularCode: string;
174
177
  pluralCode: string;
175
178
  schema: string;
@@ -246,6 +249,7 @@ declare const _default: {
246
249
  maintainedBy: string;
247
250
  namespace: string;
248
251
  name: string;
252
+ code: string;
249
253
  singularCode: string;
250
254
  pluralCode: string;
251
255
  schema: string;
@@ -322,6 +326,7 @@ declare const _default: {
322
326
  maintainedBy: string;
323
327
  namespace: string;
324
328
  name: string;
329
+ code: string;
325
330
  singularCode: string;
326
331
  pluralCode: string;
327
332
  schema: string;
@@ -357,6 +362,7 @@ declare const _default: {
357
362
  })[];
358
363
  indexes?: undefined;
359
364
  })[];
365
+ dataDictionaries: any[];
360
366
  routes: {
361
367
  namespace: string;
362
368
  name: string;
@@ -5,6 +5,6 @@ export declare function isOneRelationProperty(property: RpdDataModelProperty): b
5
5
  export declare function isManyRelationProperty(property: RpdDataModelProperty): boolean;
6
6
  export declare function getEntityProperties(server: IRpdServer, model: RpdDataModel): RpdDataModelProperty[];
7
7
  export declare function getEntityPropertiesIncludingBase(server: IRpdServer, model: RpdDataModel): RpdDataModelProperty[];
8
- export declare function getEntityPropertyByCode(server: IRpdServer, model: RpdDataModel, propertyCode: string): RpdDataModelProperty;
9
- export declare function getEntityProperty(server: IRpdServer, model: RpdDataModel, predicate: (item: RpdDataModelProperty) => boolean): RpdDataModelProperty;
10
- export declare function getEntityPropertyByFieldName(server: IRpdServer, model: RpdDataModel, fieldName: string): RpdDataModelProperty;
8
+ export declare function getEntityPropertyByCode(server: IRpdServer, model: RpdDataModel, propertyCode: string): RpdDataModelProperty | undefined;
9
+ export declare function getEntityProperty(server: IRpdServer, model: RpdDataModel, predicate: (item: RpdDataModelProperty) => boolean): RpdDataModelProperty | undefined;
10
+ export declare function getEntityPropertyByFieldName(server: IRpdServer, model: RpdDataModel, fieldName: string): RpdDataModelProperty | undefined;
package/dist/index.js CHANGED
@@ -1407,6 +1407,7 @@ var bootstrapApplicationConfig = {
1407
1407
  maintainedBy: "metaManager",
1408
1408
  namespace: "meta",
1409
1409
  name: "model",
1410
+ code: "Model",
1410
1411
  singularCode: "model",
1411
1412
  pluralCode: "models",
1412
1413
  schema: "public",
@@ -1434,6 +1435,13 @@ var bootstrapApplicationConfig = {
1434
1435
  type: "text",
1435
1436
  required: false,
1436
1437
  },
1438
+ {
1439
+ name: "code",
1440
+ code: "code",
1441
+ columnName: "code",
1442
+ type: "text",
1443
+ required: false,
1444
+ },
1437
1445
  {
1438
1446
  name: "singular code",
1439
1447
  code: "singularCode",
@@ -1547,6 +1555,7 @@ var bootstrapApplicationConfig = {
1547
1555
  maintainedBy: "metaManager",
1548
1556
  namespace: "meta",
1549
1557
  name: "property",
1558
+ code: "Property",
1550
1559
  singularCode: "property",
1551
1560
  pluralCode: "properties",
1552
1561
  schema: "public",
@@ -1717,6 +1726,7 @@ var bootstrapApplicationConfig = {
1717
1726
  maintainedBy: "metaManager",
1718
1727
  namespace: "meta",
1719
1728
  name: "data dictionary",
1729
+ code: "DataDictionary",
1720
1730
  singularCode: "data_dictionary",
1721
1731
  pluralCode: "data_dictionaries",
1722
1732
  schema: "public",
@@ -1808,6 +1818,7 @@ var bootstrapApplicationConfig = {
1808
1818
  maintainedBy: "metaManager",
1809
1819
  namespace: "meta",
1810
1820
  name: "data dictionary entry",
1821
+ code: "DataDictionaryEntry",
1811
1822
  singularCode: "data_dictionary_entry",
1812
1823
  pluralCode: "data_dictionary_entries",
1813
1824
  schema: "public",
@@ -1885,6 +1896,7 @@ var bootstrapApplicationConfig = {
1885
1896
  maintainedBy: "dataManager",
1886
1897
  namespace: "meta",
1887
1898
  name: "routes",
1899
+ code: "Route",
1888
1900
  singularCode: "route",
1889
1901
  pluralCode: "routes",
1890
1902
  schema: "public",
@@ -1957,6 +1969,7 @@ var bootstrapApplicationConfig = {
1957
1969
  ],
1958
1970
  },
1959
1971
  ],
1972
+ dataDictionaries: [],
1960
1973
  routes: [
1961
1974
  {
1962
1975
  namespace: "meta",
@@ -2322,10 +2335,7 @@ async function findEntities(server, dataAccessor, options) {
2322
2335
  let relationPropertyCodes = Object.keys(relationOptions) || [];
2323
2336
  if (!options.properties || !options.properties.length) {
2324
2337
  propertiesToSelect = getEntityPropertiesIncludingBase(server, model).filter((property) => {
2325
- if (!property) {
2326
- throw new Error(`Property '${property}' was not found in ${model.namespace}.${model.singularCode}`);
2327
- }
2328
- return !options.keepNonPropertyFields || isRelationProperty(property) || relationPropertyCodes.includes(property.code);
2338
+ return !isRelationProperty(property) || relationPropertyCodes.includes(property.code);
2329
2339
  });
2330
2340
  }
2331
2341
  else {
@@ -2334,9 +2344,6 @@ async function findEntities(server, dataAccessor, options) {
2334
2344
  const columnsToSelect = [];
2335
2345
  const relationPropertiesToSelect = [];
2336
2346
  lodash.forEach(propertiesToSelect, (property) => {
2337
- if (!property) {
2338
- throw new Error(`Property '${property}' was not found in ${model.namespace}.${model.singularCode}`);
2339
- }
2340
2347
  if (isRelationProperty(property)) {
2341
2348
  relationPropertiesToSelect.push(property);
2342
2349
  if (property.relation === "one" && !property.linkTableName) {
@@ -2684,10 +2691,14 @@ async function convertEntityFiltersToRowFilters(server, model, baseModel, filter
2684
2691
  else {
2685
2692
  const filterField = filter.field;
2686
2693
  let property = getEntityPropertyByCode(server, model, filterField);
2694
+ let filterValue = filter.value;
2687
2695
  let columnName = "";
2688
2696
  if (property) {
2689
2697
  if (isOneRelationProperty(property)) {
2690
2698
  columnName = property.targetIdColumnName;
2699
+ if (lodash.isPlainObject(filterValue)) {
2700
+ filterValue = filterValue.id;
2701
+ }
2691
2702
  }
2692
2703
  else if (isManyRelationProperty(property)) {
2693
2704
  throw new Error(`Operator "${operator}" is not supported on many-relation property "${property.code}"`);
@@ -2709,6 +2720,9 @@ async function convertEntityFiltersToRowFilters(server, model, baseModel, filter
2709
2720
  });
2710
2721
  if (property) {
2711
2722
  columnName = property.targetIdColumnName;
2723
+ if (lodash.isPlainObject(filterValue)) {
2724
+ filterValue = filterValue.id;
2725
+ }
2712
2726
  }
2713
2727
  else {
2714
2728
  columnName = filterField;
@@ -2722,7 +2736,7 @@ async function convertEntityFiltersToRowFilters(server, model, baseModel, filter
2722
2736
  name: columnName,
2723
2737
  tableName: property && property.isBaseProperty ? baseModel.tableName : model.tableName,
2724
2738
  },
2725
- value: filter.value,
2739
+ value: filterValue,
2726
2740
  itemType: filter.itemType,
2727
2741
  });
2728
2742
  }
@@ -2875,7 +2889,8 @@ async function createEntity(server, dataAccessor, options, plugin) {
2875
2889
  lodash.keys(entity).forEach((propertyCode) => {
2876
2890
  const property = getEntityPropertyByCode(server, model, propertyCode);
2877
2891
  if (!property) {
2878
- throw new Error(`Property '${property}' was not found in ${model.namespace}.${model.singularCode}`);
2892
+ // Unknown property
2893
+ return;
2879
2894
  }
2880
2895
  if (isRelationProperty(property)) {
2881
2896
  if (property.relation === "many") {
@@ -3107,7 +3122,8 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
3107
3122
  lodash.keys(changes).forEach((propertyCode) => {
3108
3123
  const property = getEntityPropertyByCode(server, model, propertyCode);
3109
3124
  if (!property) {
3110
- throw new Error(`Property '${property}' was not found in ${model.namespace}.${model.singularCode}`);
3125
+ // Unknown property
3126
+ return;
3111
3127
  }
3112
3128
  if (isRelationProperty(property)) {
3113
3129
  if (property.relation === "many") {
@@ -3213,7 +3229,7 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
3213
3229
  await server.queryDatabaseObject(`DELETE FROM ${server.queryBuilder.quoteTable({
3214
3230
  schema: property.linkSchema,
3215
3231
  tableName: property.linkTableName,
3216
- })} WHERE ${server.queryBuilder.quoteObject(property.selfIdColumnName)} = $1
3232
+ })} WHERE ${server.queryBuilder.quoteObject(property.selfIdColumnName)} = $1
3217
3233
  AND ${server.queryBuilder.quoteObject(property.targetIdColumnName)} <> ALL($2::int[])`, [id, targetIdsToKeep]);
3218
3234
  }
3219
3235
  else {
@@ -3482,11 +3498,11 @@ class EntityManager {
3482
3498
  const command = `INSERT INTO ${queryBuilder.quoteTable({
3483
3499
  schema: relationProperty.linkSchema,
3484
3500
  tableName: relationProperty.linkTableName,
3485
- })} (${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)})
3486
- SELECT $1, $2 WHERE NOT EXISTS (
3487
- SELECT ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}
3488
- FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
3489
- WHERE ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}=$1 AND ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}=$2
3501
+ })} (${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)})
3502
+ SELECT $1, $2 WHERE NOT EXISTS (
3503
+ SELECT ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}
3504
+ FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
3505
+ WHERE ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}=$1 AND ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}=$2
3490
3506
  )`;
3491
3507
  const params = [id, relation.id];
3492
3508
  await server.queryDatabaseObject(command, params);
@@ -3526,7 +3542,7 @@ class EntityManager {
3526
3542
  const { queryBuilder } = server;
3527
3543
  if (relationProperty.linkTableName) {
3528
3544
  for (const relation of relations) {
3529
- const command = `DELETE FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
3545
+ const command = `DELETE FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
3530
3546
  WHERE ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}=$1 AND ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}=$2;`;
3531
3547
  const params = [id, relation.id];
3532
3548
  await server.queryDatabaseObject(command, params);
@@ -3628,7 +3644,7 @@ class RapidServer {
3628
3644
  return this.#applicationConfig;
3629
3645
  }
3630
3646
  appendApplicationConfig(config) {
3631
- const { models, routes } = config;
3647
+ const { models, dataDictionaries, routes } = config;
3632
3648
  if (models) {
3633
3649
  for (const model of models) {
3634
3650
  const originalModel = lodash.find(this.#applicationConfig.models, (item) => item.singularCode == model.singularCode);
@@ -3651,6 +3667,19 @@ class RapidServer {
3651
3667
  }
3652
3668
  }
3653
3669
  }
3670
+ if (dataDictionaries) {
3671
+ for (const dataDictionary of dataDictionaries) {
3672
+ const originalDataDictionary = lodash.find(this.#applicationConfig.dataDictionaries, (item) => item.code == dataDictionary.code);
3673
+ if (originalDataDictionary) {
3674
+ originalDataDictionary.name = dataDictionary.name;
3675
+ originalDataDictionary.description = dataDictionary.description;
3676
+ originalDataDictionary.entries = dataDictionary.entries;
3677
+ }
3678
+ else {
3679
+ this.#applicationConfig.dataDictionaries.push(dataDictionary);
3680
+ }
3681
+ }
3682
+ }
3654
3683
  if (routes) {
3655
3684
  for (const route of routes) {
3656
3685
  const originalRoute = lodash.find(this.#applicationConfig.routes, (item) => item.code == route.code);
@@ -4123,8 +4152,9 @@ class MetaManager {
4123
4152
  const logger = server.getLogger();
4124
4153
  try {
4125
4154
  logger.info("Loading meta of models...");
4126
- const models = await listCollections(server, applicationConfig);
4127
- server.appendApplicationConfig({ models });
4155
+ const models = await listDataModels(server);
4156
+ const dataDictionaries = await listDataDictionaries(server);
4157
+ server.appendApplicationConfig({ models, dataDictionaries });
4128
4158
  }
4129
4159
  catch (error) {
4130
4160
  logger.crit("Failed to load meta of models.", { error });
@@ -4184,7 +4214,7 @@ async function handleEntityDeleteEvent(server, sender, payload) {
4184
4214
  }
4185
4215
  }
4186
4216
  }
4187
- function listCollections(server, applicationConfig) {
4217
+ function listDataModels(server) {
4188
4218
  const entityManager = server.getEntityManager("model");
4189
4219
  const model = entityManager.getModel();
4190
4220
  const properties = getEntityPropertiesIncludingBase(server, model);
@@ -4192,6 +4222,14 @@ function listCollections(server, applicationConfig) {
4192
4222
  properties: properties.map((item) => item.code),
4193
4223
  });
4194
4224
  }
4225
+ function listDataDictionaries(server) {
4226
+ const dataDictionaryManager = server.getEntityManager("data_dictionary");
4227
+ const model = dataDictionaryManager.getModel();
4228
+ const properties = getEntityPropertiesIncludingBase(server, model);
4229
+ return dataDictionaryManager.findEntities({
4230
+ properties: properties.map((item) => item.code),
4231
+ });
4232
+ }
4195
4233
  async function syncDatabaseSchema(server, applicationConfig) {
4196
4234
  const logger = server.getLogger();
4197
4235
  logger.info("Synchronizing database schema...");
@@ -4207,7 +4245,7 @@ async function syncDatabaseSchema(server, applicationConfig) {
4207
4245
  await server.queryDatabaseObject(`CREATE TABLE IF NOT EXISTS ${queryBuilder.quoteTable(model)} ()`, []);
4208
4246
  }
4209
4247
  }
4210
- const sqlQueryColumnInformations = `SELECT table_schema, table_name, column_name, data_type, udt_name, is_nullable, column_default, character_maximum_length, numeric_precision, numeric_scale
4248
+ const sqlQueryColumnInformations = `SELECT table_schema, table_name, column_name, data_type, udt_name, is_nullable, column_default, character_maximum_length, numeric_precision, numeric_scale
4211
4249
  FROM information_schema.columns;`;
4212
4250
  const columnsInDb = await server.queryDatabaseObject(sqlQueryColumnInformations, []);
4213
4251
  for (const model of applicationConfig.models) {
@@ -5482,6 +5520,7 @@ var pluginConfig = {
5482
5520
  ],
5483
5521
  },
5484
5522
  ],
5523
+ dataDictionaries: [],
5485
5524
  routes: [],
5486
5525
  };
5487
5526
 
@@ -7410,9 +7449,9 @@ class EntityAccessControlPlugin {
7410
7449
  if (!userId) {
7411
7450
  return;
7412
7451
  }
7413
- const actions = await server.queryDatabaseObject(`select distinct a.* from sys_actions a
7414
- inner join oc_role_sys_action_links ra on a.id = ra.action_id
7415
- inner join oc_role_user_links ru on ru.role_id = ra.role_id
7452
+ const actions = await server.queryDatabaseObject(`select distinct a.* from sys_actions a
7453
+ inner join oc_role_sys_action_links ra on a.id = ra.action_id
7454
+ inner join oc_role_user_links ru on ru.role_id = ra.role_id
7416
7455
  where ru.user_id = $1;`, [userId]);
7417
7456
  routeContext.state.allowedActions = actions.map((item) => item.code);
7418
7457
  }
@@ -43,6 +43,7 @@ declare const _default: {
43
43
  autoIncrement?: undefined;
44
44
  })[];
45
45
  }[];
46
+ dataDictionaries: any[];
46
47
  routes: any[];
47
48
  };
48
49
  export default _default;
package/dist/types.d.ts CHANGED
@@ -154,12 +154,14 @@ export interface RpdApplicationConfig {
154
154
  code?: string;
155
155
  name?: string;
156
156
  models: RpdDataModel[];
157
+ dataDictionaries: RpdDataDictionary[];
157
158
  routes: RpdRoute[];
158
159
  }
159
160
  export interface RpdDataModel {
160
161
  maintainedBy?: string;
161
162
  name: string;
162
163
  namespace: string;
164
+ code?: string;
163
165
  singularCode: string;
164
166
  pluralCode: string;
165
167
  schema?: string;
@@ -283,11 +285,19 @@ export type RpdDataDictionary = {
283
285
  /**
284
286
  * 字典名称
285
287
  */
288
+ name?: string;
289
+ /**
290
+ * 描述
291
+ */
286
292
  description?: string;
287
293
  /**
288
294
  * 字典项值类型
289
295
  */
290
- type: "string" | "integer";
296
+ valueType: "string" | "integer";
297
+ /**
298
+ * 字典级别
299
+ */
300
+ level: "sys" | "app" | "user";
291
301
  /**
292
302
  * 字典项
293
303
  */
@@ -305,6 +315,14 @@ export type RpdDataDictionaryEntry = {
305
315
  * 值
306
316
  */
307
317
  value: string;
318
+ /**
319
+ * 颜色
320
+ */
321
+ color?: string;
322
+ /**
323
+ * 图标
324
+ */
325
+ icon?: string;
308
326
  /**
309
327
  * 描述
310
328
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.1.83",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/rollup.config.js CHANGED
@@ -1,16 +1,16 @@
1
- import typescript from "rollup-plugin-typescript2";
2
- import tscAlias from "rollup-plugin-tsc-alias";
3
-
4
- export default {
5
- input: ["src/index.ts"],
6
- output: [
7
- {
8
- dir: "dist",
9
- entryFileNames: "[name].js",
10
- format: "cjs",
11
- exports: "named",
12
- },
13
- ],
14
- plugins: [typescript(), tscAlias()],
15
- external: [],
16
- };
1
+ import typescript from "rollup-plugin-typescript2";
2
+ import tscAlias from "rollup-plugin-tsc-alias";
3
+
4
+ export default {
5
+ input: ["src/index.ts"],
6
+ output: [
7
+ {
8
+ dir: "dist",
9
+ entryFileNames: "[name].js",
10
+ format: "cjs",
11
+ exports: "named",
12
+ },
13
+ ],
14
+ plugins: [typescript(), tscAlias()],
15
+ external: [],
16
+ };