@ruiapp/rapid-core 0.9.9 → 0.10.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 (198) hide show
  1. package/CHANGELOG.md +11 -11
  2. package/dist/bootstrapApplicationConfig.d.ts +51 -0
  3. package/dist/index.js +168 -40
  4. package/dist/plugins/auth/services/AuthService.d.ts +7 -1
  5. package/dist/types.d.ts +4 -0
  6. package/package.json +1 -1
  7. package/rollup.config.js +16 -16
  8. package/src/bootstrapApplicationConfig.ts +897 -782
  9. package/src/core/actionHandler.ts +23 -23
  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/http-types.ts +4 -4
  14. package/src/core/pluginManager.ts +193 -193
  15. package/src/core/providers/runtimeProvider.ts +5 -5
  16. package/src/core/request.ts +96 -96
  17. package/src/core/response.ts +79 -79
  18. package/src/core/routeContext.ts +127 -127
  19. package/src/core/routes/healthz.ts +20 -20
  20. package/src/core/routes/index.ts +3 -3
  21. package/src/core/routesBuilder.ts +110 -110
  22. package/src/core/server.ts +156 -156
  23. package/src/dataAccess/columnTypeMapper.ts +22 -22
  24. package/src/dataAccess/dataAccessTypes.ts +165 -165
  25. package/src/dataAccess/dataAccessor.ts +135 -135
  26. package/src/dataAccess/entityManager.ts +1932 -1932
  27. package/src/dataAccess/entityMapper.ts +111 -111
  28. package/src/dataAccess/entityValidator.ts +33 -33
  29. package/src/dataAccess/propertyMapper.ts +28 -28
  30. package/src/deno-std/assert/assert.ts +9 -9
  31. package/src/deno-std/assert/assertion_error.ts +7 -7
  32. package/src/deno-std/datetime/to_imf.ts +32 -32
  33. package/src/deno-std/encoding/base64.ts +141 -141
  34. package/src/deno-std/http/cookie.ts +372 -372
  35. package/src/facilities/cache/CacheFacilityTypes.ts +29 -29
  36. package/src/facilities/cache/CacheFactory.ts +31 -31
  37. package/src/facilities/cache/MemoryCache.ts +58 -58
  38. package/src/facilities/cache/MemoryCacheProvider.ts +15 -15
  39. package/src/facilities/log/LogFacility.ts +35 -35
  40. package/src/helpers/entityHelper.ts +89 -89
  41. package/src/helpers/filterHelper.ts +148 -148
  42. package/src/helpers/inputHelper.ts +11 -11
  43. package/src/helpers/licenseHelper.ts +29 -29
  44. package/src/helpers/metaHelper.ts +111 -111
  45. package/src/helpers/runCollectionEntityActionHandler.ts +58 -58
  46. package/src/index.ts +82 -82
  47. package/src/plugins/auth/AuthPlugin.ts +107 -103
  48. package/src/plugins/auth/AuthPluginTypes.ts +11 -11
  49. package/src/plugins/auth/actionHandlers/changePassword.ts +61 -61
  50. package/src/plugins/auth/actionHandlers/createSession.ts +68 -68
  51. package/src/plugins/auth/actionHandlers/deleteSession.ts +18 -18
  52. package/src/plugins/auth/actionHandlers/getMyProfile.ts +28 -38
  53. package/src/plugins/auth/actionHandlers/index.ts +8 -8
  54. package/src/plugins/auth/actionHandlers/resetPassword.ts +45 -45
  55. package/src/plugins/auth/models/AccessToken.ts +56 -56
  56. package/src/plugins/auth/models/index.ts +3 -3
  57. package/src/plugins/auth/routes/changePassword.ts +15 -15
  58. package/src/plugins/auth/routes/getMyProfile.ts +15 -15
  59. package/src/plugins/auth/routes/index.ts +7 -7
  60. package/src/plugins/auth/routes/resetPassword.ts +15 -15
  61. package/src/plugins/auth/routes/signin.ts +15 -15
  62. package/src/plugins/auth/routes/signout.ts +15 -15
  63. package/src/plugins/auth/services/AuthService.ts +66 -39
  64. package/src/plugins/cronJob/CronJobPlugin.ts +104 -104
  65. package/src/plugins/cronJob/CronJobPluginTypes.ts +44 -44
  66. package/src/plugins/cronJob/actionHandlers/index.ts +4 -4
  67. package/src/plugins/cronJob/actionHandlers/runCronJob.ts +32 -32
  68. package/src/plugins/cronJob/entityWatchers/cronJobEntityWatchers.ts +24 -24
  69. package/src/plugins/cronJob/entityWatchers/index.ts +4 -4
  70. package/src/plugins/cronJob/models/CronJob.ts +129 -129
  71. package/src/plugins/cronJob/models/index.ts +3 -3
  72. package/src/plugins/cronJob/routes/index.ts +3 -3
  73. package/src/plugins/cronJob/routes/runCronJob.ts +15 -15
  74. package/src/plugins/cronJob/services/CronJobService.ts +252 -252
  75. package/src/plugins/dataManage/DataManagePlugin.ts +163 -163
  76. package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +15 -15
  77. package/src/plugins/dataManage/actionHandlers/countCollectionEntities.ts +17 -17
  78. package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +81 -81
  79. package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +20 -20
  80. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntities.ts +45 -45
  81. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +20 -20
  82. package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +27 -27
  83. package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +30 -30
  84. package/src/plugins/dataManage/actionHandlers/queryDatabase.ts +22 -22
  85. package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +15 -15
  86. package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +38 -38
  87. package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +146 -146
  88. package/src/plugins/fileManage/FileManagePlugin.ts +52 -52
  89. package/src/plugins/fileManage/actionHandlers/downloadDocument.ts +65 -65
  90. package/src/plugins/fileManage/actionHandlers/downloadFile.ts +44 -44
  91. package/src/plugins/fileManage/actionHandlers/uploadFile.ts +33 -33
  92. package/src/plugins/fileManage/routes/downloadDocument.ts +15 -15
  93. package/src/plugins/fileManage/routes/downloadFile.ts +15 -15
  94. package/src/plugins/fileManage/routes/index.ts +5 -5
  95. package/src/plugins/fileManage/routes/uploadFile.ts +15 -15
  96. package/src/plugins/license/LicensePlugin.ts +79 -79
  97. package/src/plugins/license/LicensePluginTypes.ts +95 -95
  98. package/src/plugins/license/LicenseService.ts +137 -137
  99. package/src/plugins/license/actionHandlers/getLicense.ts +18 -18
  100. package/src/plugins/license/actionHandlers/index.ts +5 -5
  101. package/src/plugins/license/actionHandlers/updateLicense.ts +24 -24
  102. package/src/plugins/license/helpers/certHelper.ts +21 -21
  103. package/src/plugins/license/helpers/cryptoHelper.ts +47 -47
  104. package/src/plugins/license/models/index.ts +1 -1
  105. package/src/plugins/license/routes/getLicense.ts +15 -15
  106. package/src/plugins/license/routes/index.ts +4 -4
  107. package/src/plugins/license/routes/updateLicense.ts +15 -15
  108. package/src/plugins/mail/MailPlugin.ts +74 -74
  109. package/src/plugins/mail/MailPluginTypes.ts +27 -27
  110. package/src/plugins/mail/MailService.ts +38 -38
  111. package/src/plugins/mail/actionHandlers/index.ts +3 -3
  112. package/src/plugins/mail/models/index.ts +1 -1
  113. package/src/plugins/mail/routes/index.ts +1 -1
  114. package/src/plugins/metaManage/MetaManagePlugin.ts +198 -198
  115. package/src/plugins/metaManage/actionHandlers/getMetaModelDetail.ts +10 -10
  116. package/src/plugins/metaManage/actionHandlers/listMetaModels.ts +9 -9
  117. package/src/plugins/metaManage/actionHandlers/listMetaRoutes.ts +9 -9
  118. package/src/plugins/metaManage/services/MetaService.ts +376 -376
  119. package/src/plugins/notification/NotificationPlugin.ts +68 -68
  120. package/src/plugins/notification/NotificationPluginTypes.ts +13 -13
  121. package/src/plugins/notification/NotificationService.ts +25 -25
  122. package/src/plugins/notification/actionHandlers/index.ts +3 -3
  123. package/src/plugins/notification/models/Notification.ts +60 -60
  124. package/src/plugins/notification/models/index.ts +3 -3
  125. package/src/plugins/notification/routes/index.ts +1 -1
  126. package/src/plugins/routeManage/RouteManagePlugin.ts +64 -64
  127. package/src/plugins/routeManage/actionHandlers/httpProxy.ts +13 -13
  128. package/src/plugins/routeManage/actionHandlers/mock.ts +28 -28
  129. package/src/plugins/sequence/SequencePlugin.ts +146 -146
  130. package/src/plugins/sequence/SequencePluginTypes.ts +69 -69
  131. package/src/plugins/sequence/SequenceService.ts +92 -92
  132. package/src/plugins/sequence/actionHandlers/generateSn.ts +32 -32
  133. package/src/plugins/sequence/actionHandlers/index.ts +4 -4
  134. package/src/plugins/sequence/models/SequenceAutoIncrementRecord.ts +49 -49
  135. package/src/plugins/sequence/models/SequenceRule.ts +42 -42
  136. package/src/plugins/sequence/models/index.ts +4 -4
  137. package/src/plugins/sequence/routes/generateSn.ts +15 -15
  138. package/src/plugins/sequence/routes/index.ts +3 -3
  139. package/src/plugins/sequence/segment-utility.ts +11 -11
  140. package/src/plugins/sequence/segments/autoIncrement.ts +90 -90
  141. package/src/plugins/sequence/segments/dayOfMonth.ts +19 -19
  142. package/src/plugins/sequence/segments/index.ts +9 -9
  143. package/src/plugins/sequence/segments/literal.ts +16 -16
  144. package/src/plugins/sequence/segments/month.ts +19 -19
  145. package/src/plugins/sequence/segments/parameter.ts +20 -20
  146. package/src/plugins/sequence/segments/year.ts +19 -19
  147. package/src/plugins/serverOperation/ServerOperationPlugin.ts +91 -91
  148. package/src/plugins/serverOperation/ServerOperationPluginTypes.ts +15 -15
  149. package/src/plugins/serverOperation/actionHandlers/index.ts +4 -4
  150. package/src/plugins/serverOperation/actionHandlers/runServerOperation.ts +15 -15
  151. package/src/plugins/setting/SettingPlugin.ts +68 -68
  152. package/src/plugins/setting/SettingPluginTypes.ts +37 -37
  153. package/src/plugins/setting/SettingService.ts +213 -213
  154. package/src/plugins/setting/actionHandlers/getSystemSettingValues.ts +30 -30
  155. package/src/plugins/setting/actionHandlers/getUserSettingValues.ts +38 -38
  156. package/src/plugins/setting/actionHandlers/index.ts +6 -6
  157. package/src/plugins/setting/actionHandlers/setSystemSettingValues.ts +30 -30
  158. package/src/plugins/setting/models/SystemSettingGroupSetting.ts +57 -57
  159. package/src/plugins/setting/models/SystemSettingItem.ts +48 -48
  160. package/src/plugins/setting/models/SystemSettingItemSetting.ts +73 -73
  161. package/src/plugins/setting/models/UserSettingGroupSetting.ts +57 -57
  162. package/src/plugins/setting/models/UserSettingItem.ts +55 -55
  163. package/src/plugins/setting/models/UserSettingItemSetting.ts +73 -73
  164. package/src/plugins/setting/models/index.ts +8 -8
  165. package/src/plugins/setting/routes/getSystemSettingValues.ts +15 -15
  166. package/src/plugins/setting/routes/getUserSettingValues.ts +15 -15
  167. package/src/plugins/setting/routes/index.ts +5 -5
  168. package/src/plugins/setting/routes/setSystemSettingValues.ts +15 -15
  169. package/src/plugins/stateMachine/StateMachinePlugin.ts +196 -196
  170. package/src/plugins/stateMachine/StateMachinePluginTypes.ts +48 -48
  171. package/src/plugins/stateMachine/actionHandlers/index.ts +4 -4
  172. package/src/plugins/stateMachine/actionHandlers/sendStateMachineEvent.ts +54 -54
  173. package/src/plugins/stateMachine/models/StateMachine.ts +42 -42
  174. package/src/plugins/stateMachine/models/index.ts +3 -3
  175. package/src/plugins/stateMachine/routes/index.ts +3 -3
  176. package/src/plugins/stateMachine/routes/sendStateMachineEvent.ts +15 -15
  177. package/src/plugins/stateMachine/stateMachineHelper.ts +36 -36
  178. package/src/plugins/webhooks/WebhooksPlugin.ts +148 -148
  179. package/src/plugins/webhooks/pluginConfig.ts +75 -75
  180. package/src/polyfill.ts +5 -5
  181. package/src/proxy/mod.ts +38 -38
  182. package/src/proxy/types.ts +21 -21
  183. package/src/queryBuilder/index.ts +1 -1
  184. package/src/queryBuilder/queryBuilder.ts +755 -755
  185. package/src/server.ts +530 -530
  186. package/src/types/cron-job-types.ts +66 -66
  187. package/src/types.ts +862 -856
  188. package/src/utilities/accessControlUtility.ts +33 -33
  189. package/src/utilities/entityUtility.ts +18 -18
  190. package/src/utilities/errorUtility.ts +15 -15
  191. package/src/utilities/fsUtility.ts +137 -137
  192. package/src/utilities/httpUtility.ts +19 -19
  193. package/src/utilities/jwtUtility.ts +26 -26
  194. package/src/utilities/passwordUtility.ts +26 -26
  195. package/src/utilities/pathUtility.ts +14 -14
  196. package/src/utilities/timeUtility.ts +17 -17
  197. package/src/utilities/typeUtility.ts +15 -15
  198. package/tsconfig.json +19 -19
package/CHANGELOG.md CHANGED
@@ -1,11 +1,11 @@
1
- # @ruiapp/rapid-core
2
-
3
- ## 0.7.0
4
-
5
- - feature: added server.registerCronJob to allow plugins register cron jobs.
6
-
7
- ## 0.2.4
8
-
9
- ### Patch Changes
10
-
11
- - 146a99d: add between filterMode, range is deprecated
1
+ # @ruiapp/rapid-core
2
+
3
+ ## 0.7.0
4
+
5
+ - feature: added server.registerCronJob to allow plugins register cron jobs.
6
+
7
+ ## 0.2.4
8
+
9
+ ### Patch Changes
10
+
11
+ - 146a99d: add between filterMode, range is deprecated
@@ -435,6 +435,57 @@ declare const _default: {
435
435
  description?: undefined;
436
436
  })[];
437
437
  indexes?: undefined;
438
+ } | {
439
+ maintainedBy: string;
440
+ namespace: string;
441
+ name: string;
442
+ code: string;
443
+ singularCode: string;
444
+ pluralCode: string;
445
+ schema: string;
446
+ tableName: string;
447
+ properties: ({
448
+ name: string;
449
+ code: string;
450
+ columnName: string;
451
+ type: "integer";
452
+ required: true;
453
+ autoIncrement: true;
454
+ } | {
455
+ name: string;
456
+ code: string;
457
+ columnName: string;
458
+ type: "text";
459
+ required: true;
460
+ autoIncrement?: undefined;
461
+ } | {
462
+ name: string;
463
+ code: string;
464
+ columnName: string;
465
+ type: "text";
466
+ required: false;
467
+ autoIncrement?: undefined;
468
+ } | {
469
+ name: string;
470
+ code: string;
471
+ columnName: string;
472
+ type: "json";
473
+ required: false;
474
+ autoIncrement?: undefined;
475
+ })[];
476
+ indexes: ({
477
+ name: string;
478
+ properties: {
479
+ code: string;
480
+ }[];
481
+ unique: true;
482
+ } | {
483
+ name: string;
484
+ properties: {
485
+ code: string;
486
+ }[];
487
+ unique?: undefined;
488
+ })[];
438
489
  })[];
439
490
  dataDictionaries: any[];
440
491
  routes: {
package/dist/index.js CHANGED
@@ -1385,6 +1385,13 @@ var bootstrapApplicationConfig = {
1385
1385
  required: true,
1386
1386
  defaultValue: "false",
1387
1387
  },
1388
+ {
1389
+ name: "defaultOrderBy",
1390
+ code: "defaultOrderBy",
1391
+ columnName: "default_order_by",
1392
+ type: "json",
1393
+ required: false,
1394
+ },
1388
1395
  ],
1389
1396
  indexes: [
1390
1397
  {
@@ -1968,6 +1975,114 @@ var bootstrapApplicationConfig = {
1968
1975
  },
1969
1976
  ],
1970
1977
  },
1978
+ {
1979
+ maintainedBy: "metaManager",
1980
+ namespace: "meta",
1981
+ name: "page",
1982
+ code: "Page",
1983
+ singularCode: "page",
1984
+ pluralCode: "pages",
1985
+ schema: "public",
1986
+ tableName: "meta_pages",
1987
+ properties: [
1988
+ {
1989
+ name: "id",
1990
+ code: "id",
1991
+ columnName: "id",
1992
+ type: "integer",
1993
+ required: true,
1994
+ autoIncrement: true,
1995
+ },
1996
+ {
1997
+ name: "code",
1998
+ code: "code",
1999
+ columnName: "code",
2000
+ type: "text",
2001
+ required: true,
2002
+ },
2003
+ {
2004
+ name: "parentCode",
2005
+ code: "parentCode",
2006
+ columnName: "parent_code",
2007
+ type: "text",
2008
+ required: false,
2009
+ },
2010
+ {
2011
+ name: "subSystem",
2012
+ code: "subSystem",
2013
+ columnName: "sub_system",
2014
+ type: "text",
2015
+ required: false,
2016
+ },
2017
+ {
2018
+ name: "appCode",
2019
+ code: "appCode",
2020
+ columnName: "app_code",
2021
+ type: "text",
2022
+ required: false,
2023
+ },
2024
+ {
2025
+ name: "routePath",
2026
+ code: "routePath",
2027
+ columnName: "route_path",
2028
+ type: "text",
2029
+ required: false,
2030
+ },
2031
+ {
2032
+ name: "name",
2033
+ code: "name",
2034
+ columnName: "name",
2035
+ type: "text",
2036
+ required: false,
2037
+ },
2038
+ {
2039
+ name: "title",
2040
+ code: "title",
2041
+ columnName: "title",
2042
+ type: "text",
2043
+ required: false,
2044
+ },
2045
+ {
2046
+ name: "config",
2047
+ code: "config",
2048
+ columnName: "config",
2049
+ type: "json",
2050
+ required: false,
2051
+ },
2052
+ {
2053
+ name: "permissionCheck",
2054
+ code: "permissionCheck",
2055
+ columnName: "permission_check",
2056
+ type: "json",
2057
+ required: false,
2058
+ },
2059
+ ],
2060
+ indexes: [
2061
+ {
2062
+ name: "meta_pages_code_uindex",
2063
+ properties: [
2064
+ {
2065
+ code: "code",
2066
+ },
2067
+ ],
2068
+ unique: true,
2069
+ },
2070
+ {
2071
+ name: "meta_pages_subsystem_appcode_code_idx",
2072
+ properties: [
2073
+ {
2074
+ code: "subSystem",
2075
+ },
2076
+ {
2077
+ code: "appCode",
2078
+ },
2079
+ {
2080
+ code: "code",
2081
+ },
2082
+ ],
2083
+ },
2084
+ ],
2085
+ },
1971
2086
  ],
1972
2087
  dataDictionaries: [],
1973
2088
  routes: [
@@ -2868,8 +2983,8 @@ async function findManyRelationLinksViaLinkTable(options) {
2868
2983
  const command = `SELECT * FROM ${server.queryBuilder.quoteTable({
2869
2984
  schema: relationProperty.linkSchema,
2870
2985
  tableName: relationProperty.linkTableName,
2871
- })} WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName)} = ANY($1::int[])
2872
- ORDER BY id
2986
+ })} WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName)} = ANY($1::int[])
2987
+ ORDER BY id
2873
2988
  `;
2874
2989
  const params = [mainEntityIds];
2875
2990
  const relationLinks = await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
@@ -3500,7 +3615,7 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
3500
3615
  await server.queryDatabaseObject(`DELETE FROM ${server.queryBuilder.quoteTable({
3501
3616
  schema: property.linkSchema,
3502
3617
  tableName: property.linkTableName,
3503
- })} WHERE ${server.queryBuilder.quoteObject(property.selfIdColumnName)} = $1
3618
+ })} WHERE ${server.queryBuilder.quoteObject(property.selfIdColumnName)} = $1
3504
3619
  AND ${server.queryBuilder.quoteObject(property.targetIdColumnName)} <> ALL($2::int[])`, [id, targetIdsToKeep], routeContext?.getDbTransactionClient());
3505
3620
  }
3506
3621
  else {
@@ -3529,8 +3644,8 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
3529
3644
  await server.queryDatabaseObject(`UPDATE ${server.queryBuilder.quoteTable({
3530
3645
  schema: relationModel.schema,
3531
3646
  tableName: relationModel.tableName,
3532
- })}
3533
- SET ${server.queryBuilder.quoteObject(property.selfIdColumnName)} = null
3647
+ })}
3648
+ SET ${server.queryBuilder.quoteObject(property.selfIdColumnName)} = null
3534
3649
  WHERE id = ANY($1::int[])`, [targetIdsToRemove], routeContext?.getDbTransactionClient());
3535
3650
  }
3536
3651
  else {
@@ -3815,7 +3930,7 @@ async function deleteEntityById(server, dataAccessor, options, plugin) {
3815
3930
  await server.queryDatabaseObject(`DELETE FROM ${server.queryBuilder.quoteTable({
3816
3931
  schema: relationProperty.linkSchema,
3817
3932
  tableName: relationProperty.linkTableName,
3818
- })}
3933
+ })}
3819
3934
  WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName)} = $1`, [id], routeContext?.getDbTransactionClient());
3820
3935
  }
3821
3936
  else {
@@ -3825,8 +3940,8 @@ async function deleteEntityById(server, dataAccessor, options, plugin) {
3825
3940
  await server.queryDatabaseObject(`UPDATE ${server.queryBuilder.quoteTable({
3826
3941
  schema: relationModel.schema,
3827
3942
  tableName: relationModel.tableName,
3828
- })}
3829
- SET ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName)} = null
3943
+ })}
3944
+ SET ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName)} = null
3830
3945
  WHERE ${server.queryBuilder.quoteObject(relationProperty.selfIdColumnName)} = $1`, [id], routeContext?.getDbTransactionClient());
3831
3946
  }
3832
3947
  }
@@ -3923,11 +4038,11 @@ class EntityManager {
3923
4038
  const command = `INSERT INTO ${queryBuilder.quoteTable({
3924
4039
  schema: relationProperty.linkSchema,
3925
4040
  tableName: relationProperty.linkTableName,
3926
- })} (${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)})
3927
- SELECT $1, $2 WHERE NOT EXISTS (
3928
- SELECT ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}
3929
- FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
3930
- WHERE ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}=$1 AND ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}=$2
4041
+ })} (${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)})
4042
+ SELECT $1, $2 WHERE NOT EXISTS (
4043
+ SELECT ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}
4044
+ FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
4045
+ WHERE ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}=$1 AND ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}=$2
3931
4046
  )`;
3932
4047
  const params = [id, relation.id];
3933
4048
  await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
@@ -3967,7 +4082,7 @@ class EntityManager {
3967
4082
  const { queryBuilder } = server;
3968
4083
  if (relationProperty.linkTableName) {
3969
4084
  for (const relation of relations) {
3970
- const command = `DELETE FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
4085
+ const command = `DELETE FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
3971
4086
  WHERE ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}=$1 AND ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}=$2;`;
3972
4087
  const params = [id, relation.id];
3973
4088
  await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
@@ -5587,7 +5702,7 @@ class MetaService {
5587
5702
  const tablesInDb = await server.queryDatabaseObject(sqlQueryTableInformations);
5588
5703
  const { queryBuilder } = server;
5589
5704
  for (const model of applicationConfig.models) {
5590
- logger.debug(`Checking data table for '${model.namespace}.${model.singularCode}'...`);
5705
+ logger.info(`Checking data table for '${model.namespace}.${model.singularCode}'...`);
5591
5706
  const expectedTableSchema = model.schema || server.databaseConfig.dbDefaultSchema;
5592
5707
  const expectedTableName = model.tableName;
5593
5708
  const tableInDb = lodash.find(tablesInDb, { table_schema: expectedTableSchema, table_name: expectedTableName });
@@ -5598,13 +5713,13 @@ class MetaService {
5598
5713
  await server.tryQueryDatabaseObject(`COMMENT ON TABLE ${queryBuilder.quoteTable(model)} IS ${queryBuilder.formatValueToSqlLiteral(model.name)};`, []);
5599
5714
  }
5600
5715
  }
5601
- const sqlQueryColumnInformations = `SELECT c.table_schema, c.table_name, c.column_name, c.ordinal_position, d.description, c.data_type, c.udt_name, c.is_nullable, c.column_default, c.character_maximum_length, c.numeric_precision, c.numeric_scale
5602
- FROM information_schema.columns c
5603
- INNER JOIN pg_catalog.pg_statio_all_tables st ON (st.schemaname = c.table_schema and st.relname = c.table_name)
5716
+ const sqlQueryColumnInformations = `SELECT c.table_schema, c.table_name, c.column_name, c.ordinal_position, d.description, c.data_type, c.udt_name, c.is_nullable, c.column_default, c.character_maximum_length, c.numeric_precision, c.numeric_scale
5717
+ FROM information_schema.columns c
5718
+ INNER JOIN pg_catalog.pg_statio_all_tables st ON (st.schemaname = c.table_schema and st.relname = c.table_name)
5604
5719
  LEFT JOIN pg_catalog.pg_description d ON (d.objoid = st.relid and d.objsubid = c.ordinal_position);`;
5605
5720
  const columnsInDb = await server.queryDatabaseObject(sqlQueryColumnInformations, []);
5606
5721
  for (const model of applicationConfig.models) {
5607
- logger.debug(`Checking data columns for '${model.namespace}.${model.singularCode}'...`);
5722
+ logger.info(`Checking data columns for '${model.namespace}.${model.singularCode}'...`);
5608
5723
  for (const property of model.properties) {
5609
5724
  let columnDDL = "";
5610
5725
  if (isRelationProperty(property)) {
@@ -5745,7 +5860,7 @@ class MetaService {
5745
5860
  const expectedTableSchema = model.schema || server.databaseConfig.dbDefaultSchema;
5746
5861
  const expectedTableName = model.tableName;
5747
5862
  const expectedContraintName = `${expectedTableName}_pk`;
5748
- logger.debug(`Checking pk for '${expectedTableSchema}.${expectedTableName}'...`);
5863
+ logger.info(`Checking pk for '${expectedTableSchema}.${expectedTableName}'...`);
5749
5864
  const constraintInDb = lodash.find(constraintsInDb, {
5750
5865
  table_schema: expectedTableSchema,
5751
5866
  table_name: expectedTableName,
@@ -5761,7 +5876,7 @@ class MetaService {
5761
5876
  if (!model.indexes || !model.indexes.length) {
5762
5877
  continue;
5763
5878
  }
5764
- logger.debug(`Creating indexes of table ${queryBuilder.quoteTable(model)}`);
5879
+ logger.info(`Creating indexes of table ${queryBuilder.quoteTable(model)}`);
5765
5880
  for (const index of model.indexes) {
5766
5881
  const sqlCreateIndex = generateTableIndexDDL(queryBuilder, server, model, index);
5767
5882
  try {
@@ -7221,19 +7336,8 @@ async function handler$c(plugin, ctx, options) {
7221
7336
  };
7222
7337
  return;
7223
7338
  }
7224
- const userEntitySingularCode = plugin.options?.userEntitySingularCode || "oc_user";
7225
- const profilePropertyCodes = plugin.options?.profilePropertyCodes || ["id", "name", "login", "email", "department", "roles", "state", "createdAt"];
7226
- const entityManager = server.getEntityManager(userEntitySingularCode);
7227
- const user = await entityManager.findEntity({
7228
- filters: [
7229
- {
7230
- operator: "eq",
7231
- field: "id",
7232
- value: userId,
7233
- },
7234
- ],
7235
- properties: profilePropertyCodes,
7236
- });
7339
+ const authService = server.getService("authService");
7340
+ const user = await authService.getProfileOfUser(userId);
7237
7341
  ctx.output = {
7238
7342
  user,
7239
7343
  };
@@ -7412,9 +7516,13 @@ var pluginRoutes$7 = [changePassword, getMyProfile$1, resetPassword, signin$1, s
7412
7516
  class AuthService {
7413
7517
  #server;
7414
7518
  #jwtKey;
7415
- constructor(server, jwtKey) {
7519
+ #userEntitySingularCode;
7520
+ #profilePropertyCodes;
7521
+ constructor(server, options) {
7416
7522
  this.#server = server;
7417
- this.#jwtKey = jwtKey;
7523
+ this.#jwtKey = options.jwtKey;
7524
+ this.#userEntitySingularCode = options.userEntitySingularCode;
7525
+ this.#profilePropertyCodes = options.profilePropertyCodes;
7418
7526
  }
7419
7527
  createUserAccessToken(options) {
7420
7528
  const secretKey = Buffer.from(this.#jwtKey, "base64");
@@ -7427,6 +7535,22 @@ class AuthService {
7427
7535
  }, secretKey);
7428
7536
  return token;
7429
7537
  }
7538
+ async getProfileOfUser(userId) {
7539
+ const userEntitySingularCode = this.#userEntitySingularCode || "oc_user";
7540
+ const profilePropertyCodes = this.#profilePropertyCodes || ["id", "name", "login", "email", "department", "roles", "state", "createdAt"];
7541
+ const entityManager = this.#server.getEntityManager(userEntitySingularCode);
7542
+ const user = await entityManager.findEntity({
7543
+ filters: [
7544
+ {
7545
+ operator: "eq",
7546
+ field: "id",
7547
+ value: userId,
7548
+ },
7549
+ ],
7550
+ properties: profilePropertyCodes,
7551
+ });
7552
+ return user;
7553
+ }
7430
7554
  }
7431
7555
 
7432
7556
  /**
@@ -7465,7 +7589,11 @@ class AuthPlugin {
7465
7589
  server.appendApplicationConfig({ models: pluginModels$6 });
7466
7590
  }
7467
7591
  async configureServices(server, applicationConfig) {
7468
- this.#authService = new AuthService(server, server.config.jwtKey);
7592
+ this.#authService = new AuthService(server, {
7593
+ jwtKey: server.config.jwtKey,
7594
+ userEntitySingularCode: this.#options.userEntitySingularCode,
7595
+ profilePropertyCodes: this.#options.profilePropertyCodes,
7596
+ });
7469
7597
  server.registerService("authService", this.#authService);
7470
7598
  }
7471
7599
  async configureRoutes(server, applicationConfig) {
@@ -9763,9 +9891,9 @@ class EntityAccessControlPlugin {
9763
9891
  if (!userId) {
9764
9892
  return;
9765
9893
  }
9766
- const actions = await server.queryDatabaseObject(`select distinct a.* from sys_actions a
9767
- inner join oc_role_sys_action_links ra on a.id = ra.action_id
9768
- inner join oc_role_user_links ru on ru.role_id = ra.role_id
9894
+ const actions = await server.queryDatabaseObject(`select distinct a.* from sys_actions a
9895
+ inner join oc_role_sys_action_links ra on a.id = ra.action_id
9896
+ inner join oc_role_user_links ru on ru.role_id = ra.role_id
9769
9897
  where ru.user_id = $1;`, [userId]);
9770
9898
  routeContext.state.allowedActions = actions.map((item) => item.code);
9771
9899
  }
@@ -1,4 +1,9 @@
1
1
  import { IRpdServer } from "../../../core/server";
2
+ export type AuthServiceOptions = {
3
+ jwtKey: string;
4
+ userEntitySingularCode?: string;
5
+ profilePropertyCodes?: string[];
6
+ };
2
7
  export interface UserAccessToken {
3
8
  sub: "userAccessToken";
4
9
  aud: string;
@@ -10,6 +15,7 @@ export interface CreateUserAccessTokenOptions {
10
15
  }
11
16
  export default class AuthService {
12
17
  #private;
13
- constructor(server: IRpdServer, jwtKey: string);
18
+ constructor(server: IRpdServer, options: AuthServiceOptions);
14
19
  createUserAccessToken(options: CreateUserAccessTokenOptions): string;
20
+ getProfileOfUser(userId: number): Promise<any>;
15
21
  }
package/dist/types.d.ts CHANGED
@@ -211,6 +211,10 @@ export interface RpdDataModel {
211
211
  * Configure the property code used to display the entity.
212
212
  */
213
213
  displayPropertyCode?: string;
214
+ /**
215
+ * 默认排序方式
216
+ */
217
+ defaultOrderBy?: FindEntityOrderByOptions[];
214
218
  properties: RpdDataModelProperty[];
215
219
  indexes?: RpdDataModelIndex[];
216
220
  extensions?: RpdDataModelExtension[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.9.9",
3
+ "version": "0.10.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
+ };