@ibiz-template/model-helper 0.7.41-alpha.124 → 0.7.41-alpha.126

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 (43) hide show
  1. package/dist/index.esm.js +152 -13
  2. package/dist/index.system.min.js +1 -1
  3. package/out/index.d.ts +2 -1
  4. package/out/index.d.ts.map +1 -1
  5. package/out/index.js +1 -1
  6. package/out/interface/i-model-handler.d.ts +20 -0
  7. package/out/interface/i-model-handler.d.ts.map +1 -0
  8. package/out/interface/i-model-handler.js +1 -0
  9. package/out/interface/index.d.ts +2 -0
  10. package/out/interface/index.d.ts.map +1 -0
  11. package/out/interface/index.js +1 -0
  12. package/out/locale/en/index.d.ts +3 -0
  13. package/out/locale/en/index.d.ts.map +1 -1
  14. package/out/locale/en/index.js +3 -0
  15. package/out/locale/zh-CN/index.d.ts +3 -0
  16. package/out/locale/zh-CN/index.d.ts.map +1 -1
  17. package/out/locale/zh-CN/index.js +3 -0
  18. package/out/model-util.d.ts +3 -2
  19. package/out/model-util.d.ts.map +1 -1
  20. package/out/model-util.js +20 -12
  21. package/out/utils/index.d.ts +3 -0
  22. package/out/utils/index.d.ts.map +1 -1
  23. package/out/utils/index.js +3 -0
  24. package/out/utils/model-transformer/model-handler.d.ts +32 -0
  25. package/out/utils/model-transformer/model-handler.d.ts.map +1 -0
  26. package/out/utils/model-transformer/model-handler.js +24 -0
  27. package/out/utils/model-transformer/model-register.d.ts +9 -0
  28. package/out/utils/model-transformer/model-register.d.ts.map +1 -0
  29. package/out/utils/model-transformer/model-register.js +10 -0
  30. package/out/utils/model-transformer/model-transformer.d.ts +55 -0
  31. package/out/utils/model-transformer/model-transformer.d.ts.map +1 -0
  32. package/out/utils/model-transformer/model-transformer.js +102 -0
  33. package/package.json +3 -3
  34. package/src/index.ts +6 -1
  35. package/src/interface/i-model-handler.ts +19 -0
  36. package/src/interface/index.ts +1 -0
  37. package/src/locale/en/index.ts +6 -0
  38. package/src/locale/zh-CN/index.ts +4 -0
  39. package/src/model-util.ts +28 -12
  40. package/src/utils/index.ts +3 -0
  41. package/src/utils/model-transformer/model-handler.ts +36 -0
  42. package/src/utils/model-transformer/model-register.ts +15 -0
  43. package/src/utils/model-transformer/model-transformer.ts +124 -0
package/dist/index.esm.js CHANGED
@@ -19401,6 +19401,128 @@ var MergeSubModelHelper = class {
19401
19401
  }
19402
19402
  };
19403
19403
 
19404
+ // src/utils/model-transformer/model-handler.ts
19405
+ var ModelHandler = class {
19406
+ /**
19407
+ * Creates an instance of ModelHandler.
19408
+ * @param {number} [priority=1] 优先级,数值越小越先执行
19409
+ * @memberof ModelHandler
19410
+ */
19411
+ constructor(priority = 1) {
19412
+ /**
19413
+ * @description 优先级,默认值为1
19414
+ * @public
19415
+ * @type {number}
19416
+ * @memberof ModelHandler
19417
+ */
19418
+ this.priority = 1;
19419
+ this.priority = priority;
19420
+ }
19421
+ };
19422
+
19423
+ // src/utils/model-transformer/model-transformer.ts
19424
+ var ModelTransformer = class _ModelTransformer {
19425
+ constructor() {
19426
+ /**
19427
+ * @description 模型处理器Map
19428
+ * @private
19429
+ * @type {Map<string, ModelHandler[]>}
19430
+ * @memberof ModelTransformer
19431
+ */
19432
+ this.handlerMap = /* @__PURE__ */ new Map();
19433
+ /**
19434
+ * @description 模型缓存Map
19435
+ * @private
19436
+ * @type {Map<string, IModel>}
19437
+ * @memberof ModelTransformer
19438
+ */
19439
+ this.modelCacheMap = /* @__PURE__ */ new Map();
19440
+ }
19441
+ /**
19442
+ * @description 获取 ModelTransformer 单例对象
19443
+ * @static
19444
+ * @returns {*} {ModelTransformer}
19445
+ * @memberof ModelTransformer
19446
+ */
19447
+ static getInstance() {
19448
+ if (!this.modelTransformer) {
19449
+ this.modelTransformer = new _ModelTransformer();
19450
+ }
19451
+ return this.modelTransformer;
19452
+ }
19453
+ /**
19454
+ * @description 注册模型处理器
19455
+ * @param {string} dynaModelFilePath 模型路径
19456
+ * @param {IModelHandler} handler 执行器
19457
+ * @memberof ModelTransformer
19458
+ */
19459
+ registerHandler(dynaModelFilePath, handler) {
19460
+ const handlers = this.handlerMap.get(dynaModelFilePath);
19461
+ if (handlers) {
19462
+ handlers.push(handler);
19463
+ } else {
19464
+ this.handlerMap.set(dynaModelFilePath, [handler]);
19465
+ }
19466
+ this.modelCacheMap.delete(dynaModelFilePath);
19467
+ }
19468
+ /**
19469
+ * @description 变换模型
19470
+ * @param {string} dynaModelFilePath 模型路径
19471
+ * @param {IModel} model 原始模型
19472
+ * @returns {*} {IModel}
19473
+ * @memberof ModelTransformer
19474
+ */
19475
+ transform(dynaModelFilePath, model) {
19476
+ ibiz.log.debug(
19477
+ ibiz.i18n.t("modelHelper.utils.tryGetModel", {
19478
+ dynaModelFilePath
19479
+ })
19480
+ );
19481
+ if (this.modelCacheMap.has(dynaModelFilePath)) {
19482
+ return this.modelCacheMap.get(dynaModelFilePath);
19483
+ }
19484
+ const handlers = this.handlerMap.get(dynaModelFilePath);
19485
+ if (!handlers || handlers.length === 0) {
19486
+ this.modelCacheMap.set(dynaModelFilePath, model);
19487
+ return model;
19488
+ }
19489
+ const sortedHandlers = [...handlers].sort(
19490
+ (a, b) => a.priority - b.priority
19491
+ );
19492
+ let result = model;
19493
+ for (const handler of sortedHandlers) {
19494
+ try {
19495
+ const next = handler.execute(result);
19496
+ if (next) {
19497
+ result = next;
19498
+ } else {
19499
+ ibiz.log.error(
19500
+ ibiz.i18n.t("modelHelper.utils.transformNoModelData", {
19501
+ dynaModelFilePath
19502
+ })
19503
+ );
19504
+ return model;
19505
+ }
19506
+ } catch (error) {
19507
+ ibiz.log.error(
19508
+ ibiz.i18n.t("modelHelper.utils.transformException", {
19509
+ dynaModelFilePath
19510
+ }),
19511
+ error
19512
+ );
19513
+ return model;
19514
+ }
19515
+ }
19516
+ this.modelCacheMap.set(dynaModelFilePath, result);
19517
+ return result;
19518
+ }
19519
+ };
19520
+
19521
+ // src/utils/model-transformer/model-register.ts
19522
+ function registerModelHandler(dynaModelFilePath, handler) {
19523
+ ModelTransformer.getInstance().registerHandler(dynaModelFilePath, handler);
19524
+ }
19525
+
19404
19526
  // src/model/PSSYSAPP.ts
19405
19527
  var PSSysApp = {
19406
19528
  getAllPSAppDEUIActions: {
@@ -19743,37 +19865,46 @@ var ModelUtil = class {
19743
19865
  return this.modelCache.get(url);
19744
19866
  }
19745
19867
  const model = await this.get(url, params);
19868
+ const filledModel = this.deepFillModel(model);
19746
19869
  if (!isParams) {
19747
- this.modelCache.set(url, model);
19870
+ this.modelCache.set(url, filledModel);
19748
19871
  }
19749
- this.deepFillAppId(model);
19750
- return model;
19872
+ return filledModel;
19751
19873
  }
19752
19874
  /**
19753
- * 递归填充应用标识
19875
+ * 递归填充模型,包括填充模型appId、变换模型
19754
19876
  *
19755
19877
  * @author chitanda
19756
19878
  * @date 2023-08-21 10:08:41
19757
19879
  * @protected
19758
19880
  * @param {IModel} model
19881
+ * @return {*} {IModel} 返回处理后的模型,若处理器返回新对象则替换原引用
19759
19882
  */
19760
- deepFillAppId(model) {
19761
- model.appId = this.appId;
19762
- const keys4 = Object.keys(model);
19883
+ deepFillModel(model) {
19884
+ let result = model;
19885
+ if (model.dynaModelFilePath) {
19886
+ result = ModelTransformer.getInstance().transform(
19887
+ model.dynaModelFilePath,
19888
+ model
19889
+ );
19890
+ }
19891
+ result.appId = this.appId;
19892
+ const keys4 = Object.keys(result);
19763
19893
  keys4.forEach((key) => {
19764
- const value = model[key];
19894
+ const value = result[key];
19765
19895
  if (value && typeof value === "object") {
19766
19896
  if (Array.isArray(value)) {
19767
- value.forEach((item) => {
19897
+ value.forEach((item, index) => {
19768
19898
  if (item && typeof item === "object") {
19769
- this.deepFillAppId(item);
19899
+ value[index] = this.deepFillModel(item);
19770
19900
  }
19771
19901
  });
19772
19902
  } else {
19773
- this.deepFillAppId(value);
19903
+ result[key] = this.deepFillModel(value);
19774
19904
  }
19775
19905
  }
19776
19906
  });
19907
+ return result;
19777
19908
  }
19778
19909
  /**
19779
19910
  * 计算应用模型请求路径
@@ -20548,7 +20679,10 @@ var en2 = {
20548
20679
  noFoundEntity: "Entity not found {id}",
20549
20680
  maximumTier: "Service path calculation exceeds maximum tier 10",
20550
20681
  circularRecursive: "A circular recursive reference appears in the computational resource relationship path, triggering the entity:",
20551
- calculatedEntities: "Current list of calculated entities. "
20682
+ calculatedEntities: "Current list of calculated entities. ",
20683
+ transformNoModelData: "[{dynaModelFilePath}] model transformation exception, no model data returned",
20684
+ transformException: "[{dynaModelFilePath}] model transformation exception",
20685
+ tryGetModel: "[Custom extension model data] Try to get the extension model of path [{dynaModelFilePath}]"
20552
20686
  },
20553
20687
  noInitialized: "[{appId}] is not initialized, please call initModelUtil method to initialize it first",
20554
20688
  noFoundEntity: "Application [{appId}] data entity not found [{tag}]",
@@ -20564,7 +20698,10 @@ var zhCn2 = {
20564
20698
  noFoundEntity: "\u672A\u627E\u5230\u5B9E\u4F53 {id}",
20565
20699
  maximumTier: "\u670D\u52A1\u8DEF\u5F84\u8BA1\u7B97\u8D85\u8FC7\u6700\u5927\u5C42\u7EA7 10",
20566
20700
  circularRecursive: "\u8BA1\u7B97\u8D44\u6E90\u5173\u7CFB\u8DEF\u5F84\u51FA\u73B0\u5FAA\u73AF\u9012\u5F52\u5F15\u7528\uFF0C\u89E6\u53D1\u5B9E\u4F53\uFF1A",
20567
- calculatedEntities: "\u5F53\u524D\u5DF2\u8BA1\u7B97\u8FC7\u5B9E\u4F53\u6E05\u5355: "
20701
+ calculatedEntities: "\u5F53\u524D\u5DF2\u8BA1\u7B97\u8FC7\u5B9E\u4F53\u6E05\u5355: ",
20702
+ transformNoModelData: "[{dynaModelFilePath}]\u6A21\u578B\u8F6C\u5316\u5F02\u5E38\uFF0C\u672A\u8FD4\u56DE\u6A21\u578B\u6570\u636E",
20703
+ transformException: "[{dynaModelFilePath}]\u6A21\u578B\u8F6C\u5316\u5F02\u5E38",
20704
+ tryGetModel: "[\u81EA\u5B9A\u4E49\u6269\u5C55\u6A21\u578B\u6570\u636E] \u5C1D\u8BD5\u83B7\u53D6\u8DEF\u5F84[{dynaModelFilePath}]\u7684\u6269\u5C55\u6A21\u578B"
20568
20705
  },
20569
20706
  noInitialized: "[{appId}]\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 initModelUtil \u65B9\u6CD5\u521D\u59CB\u5316",
20570
20707
  noFoundEntity: "\u5E94\u7528[{appId}]\u672A\u627E\u5230\u6570\u636E\u5B9E\u4F53[{tag}]",
@@ -20574,7 +20711,9 @@ var zhCn2 = {
20574
20711
  };
20575
20712
  export {
20576
20713
  MergeSubModelHelper,
20714
+ ModelHandler,
20577
20715
  ModelHelper,
20578
20716
  en2 as en,
20717
+ registerModelHandler,
20579
20718
  zhCn2 as zhCn
20580
20719
  };