@ruiapp/rapid-core 0.7.3 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from "./utilities/accessControlUtility";
11
11
  export * from "./utilities/entityUtility";
12
12
  export * from "./utilities/jwtUtility";
13
13
  export * from "./utilities/timeUtility";
14
+ export * from "./helpers/licenseHelper";
14
15
  export * from "./deno-std/http/cookie";
15
16
  export { mapDbRowToEntity } from "./dataAccess/entityMapper";
16
17
  export * as bootstrapApplicationConfig from "./bootstrapApplicationConfig";
package/dist/index.js CHANGED
@@ -2815,18 +2815,30 @@ async function findEntities(server, dataAccessor, options) {
2815
2815
  continue;
2816
2816
  }
2817
2817
  if (isManyRelation) {
2818
- const relationLinks = await findManyRelationLinksViaLinkTable({
2818
+ const selectRelationOptions = relationOptions[relationProperty.code];
2819
+ const { relationLinks, targetEntities } = await findManyRelationLinksViaLinkTable({
2819
2820
  server,
2820
2821
  routeContext,
2821
2822
  mainModel: relationModel,
2822
2823
  relationProperty,
2823
2824
  mainEntityIds: entityIds,
2824
- selectRelationOptions: relationOptions[relationProperty.code],
2825
+ selectRelationOptions,
2825
2826
  });
2827
+ // 如果查询关联实体时指定了orderBy,则按照targetEntities的顺序,否则按照relationLinks的顺序。
2828
+ const selectRelationOrderByOptionsSpecified = selectRelationOptions && lodash.isObject(selectRelationOptions) && selectRelationOptions.orderBy;
2826
2829
  lodash.forEach(rows, (row) => {
2827
- row[relationProperty.code] = lodash.filter(relationLinks, (link) => {
2828
- return link[relationProperty.selfIdColumnName] == row["id"];
2829
- }).map((link) => mapDbRowToEntity(server, relationModel, link.targetEntity, options.keepNonPropertyFields));
2830
+ if (selectRelationOrderByOptionsSpecified) {
2831
+ row[relationProperty.code] = lodash.filter(targetEntities, (targetEntity) => {
2832
+ return lodash.find(relationLinks, (link) => {
2833
+ return link[relationProperty.selfIdColumnName] == row["id"] && link[relationProperty.targetIdColumnName] == targetEntity["id"];
2834
+ });
2835
+ }).map((targetEntity) => mapDbRowToEntity(server, relationModel, targetEntity, options.keepNonPropertyFields));
2836
+ }
2837
+ else {
2838
+ row[relationProperty.code] = lodash.filter(relationLinks, (link) => {
2839
+ return link[relationProperty.selfIdColumnName] == row["id"];
2840
+ }).map((link) => mapDbRowToEntity(server, relationModel, link.targetEntity, options.keepNonPropertyFields));
2841
+ }
2830
2842
  });
2831
2843
  }
2832
2844
  }
@@ -3139,8 +3151,8 @@ async function findManyRelationLinksViaLinkTable(options) {
3139
3151
  ORDER BY id
3140
3152
  `;
3141
3153
  const params = [mainEntityIds];
3142
- const links = await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
3143
- const targetEntityIds = links.map((link) => link[relationProperty.targetIdColumnName]);
3154
+ const relationLinks = await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
3155
+ const targetEntityIds = relationLinks.map((link) => link[relationProperty.targetIdColumnName]);
3144
3156
  const dataAccessor = server.getDataAccessor({
3145
3157
  namespace: relationModel.namespace,
3146
3158
  singularCode: relationModel.singularCode,
@@ -3178,10 +3190,10 @@ async function findManyRelationLinksViaLinkTable(options) {
3178
3190
  }
3179
3191
  }
3180
3192
  const targetEntities = await findEntities(server, dataAccessor, findEntityOptions);
3181
- lodash.forEach(links, (link) => {
3193
+ lodash.forEach(relationLinks, (link) => {
3182
3194
  link.targetEntity = lodash.find(targetEntities, (e) => e["id"] == link[relationProperty.targetIdColumnName]);
3183
3195
  });
3184
- return links;
3196
+ return { relationLinks, targetEntities };
3185
3197
  }
3186
3198
  async function findManyRelatedEntitiesViaIdPropertyCode(options) {
3187
3199
  const { server, relationProperty, mainEntityIds, selectRelationOptions } = options;
@@ -4843,6 +4855,30 @@ async function generateJwtSecretKey() {
4843
4855
  return encode(exportedKey);
4844
4856
  }
4845
4857
 
4858
+ function validateLicense(server) {
4859
+ const licenseService = server.getService("licenseService");
4860
+ const license = licenseService.getLicense();
4861
+ if (!license) {
4862
+ const errorMessage = `无法获取系统授权信息。`;
4863
+ throw new Error(errorMessage);
4864
+ }
4865
+ if (licenseService.isExpired()) {
4866
+ const expireDate = lodash.get(license.authority, "expireDate");
4867
+ const errorMessage = `您的系统授权已于${expireDate}过期。`;
4868
+ throw new Error(errorMessage);
4869
+ }
4870
+ }
4871
+ function tryValidateLicense(logger, server) {
4872
+ try {
4873
+ validateLicense(server);
4874
+ return true;
4875
+ }
4876
+ catch (err) {
4877
+ logger.error("授权验证失败:%s", err.message || "");
4878
+ }
4879
+ return false;
4880
+ }
4881
+
4846
4882
  const values = new Map();
4847
4883
  async function set(key, value, options) {
4848
4884
  let expireAt = -1;
@@ -6652,20 +6688,6 @@ var changePassword$1 = /*#__PURE__*/Object.freeze({
6652
6688
  handler: handler$e
6653
6689
  });
6654
6690
 
6655
- function validateLicense(server) {
6656
- const licenseService = server.getService("licenseService");
6657
- const license = licenseService.getLicense();
6658
- if (!license) {
6659
- const errorMessage = `无法获取系统授权信息。`;
6660
- throw new Error(errorMessage);
6661
- }
6662
- if (licenseService.isExpired()) {
6663
- const expireDate = lodash.get(license.authority, "expireDate");
6664
- const errorMessage = `您的系统授权已于${expireDate}过期。`;
6665
- throw new Error(errorMessage);
6666
- }
6667
- }
6668
-
6669
6691
  const code$d = "createSession";
6670
6692
  async function handler$d(plugin, ctx, options) {
6671
6693
  const { server, input, routerContext: routeContext, logger } = ctx;
@@ -8955,4 +8977,6 @@ exports.getSetCookies = getSetCookies;
8955
8977
  exports.isAccessAllowed = isAccessAllowed;
8956
8978
  exports.mapDbRowToEntity = mapDbRowToEntity;
8957
8979
  exports.setCookie = setCookie;
8980
+ exports.tryValidateLicense = tryValidateLicense;
8981
+ exports.validateLicense = validateLicense;
8958
8982
  exports.verifyJwt = verifyJwt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -270,19 +270,30 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
270
270
  }
271
271
 
272
272
  if (isManyRelation) {
273
- const relationLinks = await findManyRelationLinksViaLinkTable({
273
+ const selectRelationOptions: FindEntityFindManyRelationEntitiesOptions | undefined = relationOptions[relationProperty.code];
274
+ const { relationLinks, targetEntities } = await findManyRelationLinksViaLinkTable({
274
275
  server,
275
276
  routeContext,
276
277
  mainModel: relationModel,
277
278
  relationProperty,
278
279
  mainEntityIds: entityIds,
279
- selectRelationOptions: relationOptions[relationProperty.code],
280
+ selectRelationOptions,
280
281
  });
281
282
 
283
+ // 如果查询关联实体时指定了orderBy,则按照targetEntities的顺序,否则按照relationLinks的顺序。
284
+ const selectRelationOrderByOptionsSpecified = selectRelationOptions && isObject(selectRelationOptions) && selectRelationOptions.orderBy;
282
285
  forEach(rows, (row: any) => {
283
- row[relationProperty.code] = filter(relationLinks, (link: any) => {
284
- return link[relationProperty.selfIdColumnName!] == row["id"];
285
- }).map((link) => mapDbRowToEntity(server, relationModel, link.targetEntity, options.keepNonPropertyFields));
286
+ if (selectRelationOrderByOptionsSpecified) {
287
+ row[relationProperty.code] = filter(targetEntities, (targetEntity: any) => {
288
+ return find(relationLinks, (link: any) => {
289
+ return link[relationProperty.selfIdColumnName!] == row["id"] && link[relationProperty.targetIdColumnName!] == targetEntity["id"];
290
+ });
291
+ }).map((targetEntity) => mapDbRowToEntity(server, relationModel, targetEntity, options.keepNonPropertyFields));
292
+ } else {
293
+ row[relationProperty.code] = filter(relationLinks, (link: any) => {
294
+ return link[relationProperty.selfIdColumnName!] == row["id"];
295
+ }).map((link) => mapDbRowToEntity(server, relationModel, link.targetEntity, options.keepNonPropertyFields));
296
+ }
286
297
  });
287
298
  }
288
299
  } else {
@@ -628,8 +639,8 @@ async function findManyRelationLinksViaLinkTable(options: FindManyRelationEntiti
628
639
  ORDER BY id
629
640
  `;
630
641
  const params = [mainEntityIds];
631
- const links = await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
632
- const targetEntityIds = links.map((link) => link[relationProperty.targetIdColumnName!]);
642
+ const relationLinks = await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
643
+ const targetEntityIds = relationLinks.map((link) => link[relationProperty.targetIdColumnName!]);
633
644
 
634
645
  const dataAccessor = server.getDataAccessor({
635
646
  namespace: relationModel.namespace,
@@ -672,11 +683,11 @@ async function findManyRelationLinksViaLinkTable(options: FindManyRelationEntiti
672
683
 
673
684
  const targetEntities = await findEntities(server, dataAccessor, findEntityOptions);
674
685
 
675
- forEach(links, (link: any) => {
686
+ forEach(relationLinks, (link: any) => {
676
687
  link.targetEntity = find(targetEntities, (e: any) => e["id"] == link[relationProperty.targetIdColumnName!]);
677
688
  });
678
689
 
679
- return links;
690
+ return { relationLinks, targetEntities };
680
691
  }
681
692
 
682
693
  async function findManyRelatedEntitiesViaIdPropertyCode(options: FindManyRelationEntitiesOptions) {
package/src/index.ts CHANGED
@@ -17,6 +17,8 @@ export * from "./utilities/entityUtility";
17
17
  export * from "./utilities/jwtUtility";
18
18
  export * from "./utilities/timeUtility";
19
19
 
20
+ export * from "./helpers/licenseHelper";
21
+
20
22
  export * from "./deno-std/http/cookie";
21
23
 
22
24
  export { mapDbRowToEntity } from "./dataAccess/entityMapper";