@ibiz-template/model-helper 0.7.41-alpha.129 → 0.7.41-alpha.130

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.
@@ -8,6 +8,7 @@ export declare const en: {
8
8
  transformNoModelData: string;
9
9
  transformException: string;
10
10
  tryGetModel: string;
11
+ invalidPathPattern: string;
11
12
  };
12
13
  noInitialized: string;
13
14
  noFoundEntity: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/locale/en/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;CAqBd,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/locale/en/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;CAuBd,CAAC"}
@@ -8,6 +8,7 @@ export const en = {
8
8
  transformNoModelData: '[{dynaModelFilePath}] model transformation exception, no model data returned',
9
9
  transformException: '[{dynaModelFilePath}] model transformation exception',
10
10
  tryGetModel: '[Custom extension model data] Try to get the extension model of path [{dynaModelFilePath}]',
11
+ invalidPathPattern: '[Model handler path validation failed]: wildcards are not allowed in even-position path segments, [{pathPattern}] registration skipped',
11
12
  },
12
13
  noInitialized: '[{appId}] is not initialized, please call initModelUtil method to initialize it first',
13
14
  noFoundEntity: 'Application [{appId}] data entity not found [{tag}]',
@@ -8,6 +8,7 @@ export declare const zhCn: {
8
8
  transformNoModelData: string;
9
9
  transformException: string;
10
10
  tryGetModel: string;
11
+ invalidPathPattern: string;
11
12
  };
12
13
  noInitialized: string;
13
14
  noFoundEntity: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/locale/zh-CN/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;CAiBhB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/locale/zh-CN/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;CAmBhB,CAAC"}
@@ -8,6 +8,7 @@ export const zhCn = {
8
8
  transformNoModelData: '[{dynaModelFilePath}]模型转化异常,未返回模型数据',
9
9
  transformException: '[{dynaModelFilePath}]模型转化异常',
10
10
  tryGetModel: '[自定义扩展模型数据] 尝试获取路径[{dynaModelFilePath}]的扩展模型',
11
+ invalidPathPattern: '[模型处理器校验路径失败],偶数位路径段不允许使用通配符,[{pathPattern}]已跳过注册',
11
12
  },
12
13
  noInitialized: '[{appId}]未初始化,请先调用 initModelUtil 方法初始化',
13
14
  noFoundEntity: '应用[{appId}]未找到数据实体[{tag}]',
@@ -2,8 +2,8 @@ import { ModelHandler } from './model-handler';
2
2
  /**
3
3
  * @description 注册模型处理器
4
4
  * @export
5
- * @param {string} dynaModelFilePath 模型路径
5
+ * @param {string} pathPattern 路径表达式
6
6
  * @param {ModelHandler} handler 模型处理器
7
7
  */
8
- export declare function registerModelHandler(dynaModelFilePath: string, handler: ModelHandler): void;
8
+ export declare function registerModelHandler(pathPattern: string, handler: ModelHandler): void;
9
9
  //# sourceMappingURL=model-register.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-register.d.ts","sourceRoot":"","sources":["../../../src/utils/model-transformer/model-register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,iBAAiB,EAAE,MAAM,EACzB,OAAO,EAAE,YAAY,GACpB,IAAI,CAEN"}
1
+ {"version":3,"file":"model-register.d.ts","sourceRoot":"","sources":["../../../src/utils/model-transformer/model-register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,YAAY,GACpB,IAAI,CAEN"}
@@ -2,9 +2,9 @@ import { ModelTransformer } from './model-transformer';
2
2
  /**
3
3
  * @description 注册模型处理器
4
4
  * @export
5
- * @param {string} dynaModelFilePath 模型路径
5
+ * @param {string} pathPattern 路径表达式
6
6
  * @param {ModelHandler} handler 模型处理器
7
7
  */
8
- export function registerModelHandler(dynaModelFilePath, handler) {
9
- ModelTransformer.getInstance().registerHandler(dynaModelFilePath, handler);
8
+ export function registerModelHandler(pathPattern, handler) {
9
+ ModelTransformer.getInstance().registerHandler(pathPattern, handler);
10
10
  }
@@ -30,19 +30,27 @@ export declare class ModelTransformer {
30
30
  */
31
31
  private handlerMap;
32
32
  /**
33
- * @description 模型缓存Map
33
+ * @description 路径匹配器(支持通配符路径匹配)
34
34
  * @private
35
- * @type {Map<string, IModel>}
35
+ * @type {ReturnType<typeof AntPathMatcher>}
36
36
  * @memberof ModelTransformer
37
37
  */
38
- private modelCacheMap;
38
+ private pathMatcher;
39
39
  /**
40
40
  * @description 注册模型处理器
41
- * @param {string} dynaModelFilePath 模型路径
41
+ * @param {string} pathPattern 路径表达式(奇数位路径段支持通配符)
42
42
  * @param {IModelHandler} handler 执行器
43
43
  * @memberof ModelTransformer
44
44
  */
45
- registerHandler(dynaModelFilePath: string, handler: ModelHandler): void;
45
+ registerHandler(pathPattern: string, handler: ModelHandler): void;
46
+ /**
47
+ * @description 校验模型路径,从0开始数,偶数位路径段(如PSSYSAPPS、PSAPPDATAENTITIES等类型段)不允许使用通配符,奇数位路径段可使用
48
+ * @private
49
+ * @param {string} pathPattern 路径表达式
50
+ * @returns {*} {boolean}
51
+ * @memberof ModelTransformer
52
+ */
53
+ private validatePattern;
46
54
  /**
47
55
  * @description 变换模型
48
56
  * @param {string} dynaModelFilePath 模型路径
@@ -1 +1 @@
1
- {"version":3,"file":"model-transformer.d.ts","sourceRoot":"","sources":["../../../src/utils/model-transformer/model-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAmB;IAElD;;;;;OAKG;WACW,WAAW,IAAI,gBAAgB;IAO7C;;;;;OAKG;IACH,OAAO,CAAC,UAAU,CAA0C;IAE5D;;;;;OAKG;IACH,OAAO,CAAC,aAAa,CAAkC;IAEvD;;;;;OAKG;IACI,eAAe,CACpB,iBAAiB,EAAE,MAAM,EACzB,OAAO,EAAE,YAAY,GACpB,IAAI;IAWP;;;;;;OAMG;IACI,SAAS,CAAC,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAgDnE"}
1
+ {"version":3,"file":"model-transformer.d.ts","sourceRoot":"","sources":["../../../src/utils/model-transformer/model-transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAmB;IAElD;;;;;OAKG;WACW,WAAW,IAAI,gBAAgB;IAO7C;;;;;OAKG;IACH,OAAO,CAAC,UAAU,CAA0C;IAE5D;;;;;OAKG;IACH,OAAO,CAAC,WAAW,CAAoB;IAEvC;;;;;OAKG;IACI,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAYxE;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAgBvB;;;;;;OAMG;IACI,SAAS,CAAC,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAiDnE"}
@@ -1,3 +1,4 @@
1
+ import AntPathMatcher from '@maxbilbow/ant-path-matcher';
1
2
  /**
2
3
  * @description 模型变换器
3
4
  * @author tony001
@@ -15,12 +16,12 @@ export class ModelTransformer {
15
16
  */
16
17
  this.handlerMap = new Map();
17
18
  /**
18
- * @description 模型缓存Map
19
+ * @description 路径匹配器(支持通配符路径匹配)
19
20
  * @private
20
- * @type {Map<string, IModel>}
21
+ * @type {ReturnType<typeof AntPathMatcher>}
21
22
  * @memberof ModelTransformer
22
23
  */
23
- this.modelCacheMap = new Map();
24
+ this.pathMatcher = AntPathMatcher();
24
25
  }
25
26
  /**
26
27
  * @description 获取 ModelTransformer 单例对象
@@ -36,20 +37,41 @@ export class ModelTransformer {
36
37
  }
37
38
  /**
38
39
  * @description 注册模型处理器
39
- * @param {string} dynaModelFilePath 模型路径
40
+ * @param {string} pathPattern 路径表达式(奇数位路径段支持通配符)
40
41
  * @param {IModelHandler} handler 执行器
41
42
  * @memberof ModelTransformer
42
43
  */
43
- registerHandler(dynaModelFilePath, handler) {
44
- const handlers = this.handlerMap.get(dynaModelFilePath);
44
+ registerHandler(pathPattern, handler) {
45
+ if (!this.validatePattern(pathPattern)) {
46
+ return;
47
+ }
48
+ const handlers = this.handlerMap.get(pathPattern);
45
49
  if (handlers) {
46
50
  handlers.push(handler);
47
51
  }
48
52
  else {
49
- this.handlerMap.set(dynaModelFilePath, [handler]);
53
+ this.handlerMap.set(pathPattern, [handler]);
50
54
  }
51
- // 注册新处理器后清除该路径的模型缓存,确保新处理器能生效
52
- this.modelCacheMap.delete(dynaModelFilePath);
55
+ }
56
+ /**
57
+ * @description 校验模型路径,从0开始数,偶数位路径段(如PSSYSAPPS、PSAPPDATAENTITIES等类型段)不允许使用通配符,奇数位路径段可使用
58
+ * @private
59
+ * @param {string} pathPattern 路径表达式
60
+ * @returns {*} {boolean}
61
+ * @memberof ModelTransformer
62
+ */
63
+ validatePattern(pathPattern) {
64
+ const segments = pathPattern.split('/');
65
+ const isValid = segments.every((segment, index) => {
66
+ // 偶数位不允许出现通配符,奇数位有无通配符均可
67
+ return index % 2 === 1 || !/[*?]/.test(segment);
68
+ });
69
+ if (!isValid) {
70
+ ibiz.log.error(ibiz.i18n.t('modelHelper.utils.invalidPathPattern', {
71
+ pathPattern,
72
+ }));
73
+ }
74
+ return isValid;
53
75
  }
54
76
  /**
55
77
  * @description 变换模型
@@ -62,16 +84,18 @@ export class ModelTransformer {
62
84
  ibiz.log.debug(ibiz.i18n.t('modelHelper.utils.tryGetModel', {
63
85
  dynaModelFilePath,
64
86
  }));
65
- if (this.modelCacheMap.has(dynaModelFilePath)) {
66
- return this.modelCacheMap.get(dynaModelFilePath);
67
- }
68
- const handlers = this.handlerMap.get(dynaModelFilePath);
69
- if (!handlers || handlers.length === 0) {
70
- this.modelCacheMap.set(dynaModelFilePath, model);
87
+ // 收集所有匹配当前路径的处理器(支持通配符路径)
88
+ const matchedHandlers = [];
89
+ this.handlerMap.forEach((handlers, pattern) => {
90
+ if (this.pathMatcher.match(pattern, dynaModelFilePath)) {
91
+ matchedHandlers.push(...handlers);
92
+ }
93
+ });
94
+ if (matchedHandlers.length === 0) {
71
95
  return model;
72
96
  }
73
97
  // 按照优先级升序排序,优先级高的后执行
74
- const sortedHandlers = [...handlers].sort((a, b) => a.priority - b.priority);
98
+ const sortedHandlers = [...matchedHandlers].sort((a, b) => a.priority - b.priority);
75
99
  // 模型处理
76
100
  let result = model;
77
101
  for (const handler of sortedHandlers) {
@@ -96,7 +120,6 @@ export class ModelTransformer {
96
120
  return model;
97
121
  }
98
122
  }
99
- this.modelCacheMap.set(dynaModelFilePath, result);
100
123
  return result;
101
124
  }
102
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiz-template/model-helper",
3
- "version": "0.7.41-alpha.129",
3
+ "version": "0.7.41-alpha.130",
4
4
  "description": "模型辅助库",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",
@@ -33,12 +33,13 @@
33
33
  "dependencies": {
34
34
  "@ibiz-template/core": "^0.7.41-alpha.119",
35
35
  "@ibiz/model-core": "^0.1.89",
36
- "@ibiz/rt-model-api": "0.2.89",
36
+ "@ibiz/rt-model-api": "0.2.90",
37
+ "@maxbilbow/ant-path-matcher": "0.0.2",
37
38
  "pluralize": "^8.0.0",
38
39
  "ramda": "^0.29.1"
39
40
  },
40
41
  "devDependencies": {
41
- "@ibiz-template/runtime": "^0.7.41-alpha.128",
42
+ "@ibiz-template/runtime": "^0.7.41-alpha.130",
42
43
  "@types/pluralize": "^0.0.33",
43
44
  "@types/ramda": "^0.29.10"
44
45
  },
@@ -46,5 +47,5 @@
46
47
  "@ibiz-template/runtime": "^0.6.0",
47
48
  "ramda": "^0.29.0"
48
49
  },
49
- "gitHead": "9b81ee754ee4d247e69c2d5eca54b0b95586b67c"
50
+ "gitHead": "884c135f203cf1a0ae3977442b559b757acd6b47"
50
51
  }
@@ -12,6 +12,8 @@ export const en = {
12
12
  '[{dynaModelFilePath}] model transformation exception',
13
13
  tryGetModel:
14
14
  '[Custom extension model data] Try to get the extension model of path [{dynaModelFilePath}]',
15
+ invalidPathPattern:
16
+ '[Model handler path validation failed]: wildcards are not allowed in even-position path segments, [{pathPattern}] registration skipped',
15
17
  },
16
18
  noInitialized:
17
19
  '[{appId}] is not initialized, please call initModelUtil method to initialize it first',
@@ -9,6 +9,8 @@ export const zhCn = {
9
9
  transformException: '[{dynaModelFilePath}]模型转化异常',
10
10
  tryGetModel:
11
11
  '[自定义扩展模型数据] 尝试获取路径[{dynaModelFilePath}]的扩展模型',
12
+ invalidPathPattern:
13
+ '[模型处理器校验路径失败],偶数位路径段不允许使用通配符,[{pathPattern}]已跳过注册',
12
14
  },
13
15
  noInitialized: '[{appId}]未初始化,请先调用 initModelUtil 方法初始化',
14
16
  noFoundEntity: '应用[{appId}]未找到数据实体[{tag}]',
@@ -4,12 +4,12 @@ import { ModelTransformer } from './model-transformer';
4
4
  /**
5
5
  * @description 注册模型处理器
6
6
  * @export
7
- * @param {string} dynaModelFilePath 模型路径
7
+ * @param {string} pathPattern 路径表达式
8
8
  * @param {ModelHandler} handler 模型处理器
9
9
  */
10
10
  export function registerModelHandler(
11
- dynaModelFilePath: string,
11
+ pathPattern: string,
12
12
  handler: ModelHandler,
13
13
  ): void {
14
- ModelTransformer.getInstance().registerHandler(dynaModelFilePath, handler);
14
+ ModelTransformer.getInstance().registerHandler(pathPattern, handler);
15
15
  }
@@ -1,3 +1,4 @@
1
+ import AntPathMatcher from '@maxbilbow/ant-path-matcher';
1
2
  import { ModelHandler } from './model-handler';
2
3
 
3
4
  /**
@@ -39,31 +40,52 @@ export class ModelTransformer {
39
40
  private handlerMap: Map<string, ModelHandler[]> = new Map();
40
41
 
41
42
  /**
42
- * @description 模型缓存Map
43
+ * @description 路径匹配器(支持通配符路径匹配)
43
44
  * @private
44
- * @type {Map<string, IModel>}
45
+ * @type {ReturnType<typeof AntPathMatcher>}
45
46
  * @memberof ModelTransformer
46
47
  */
47
- private modelCacheMap: Map<string, IModel> = new Map();
48
+ private pathMatcher = AntPathMatcher();
48
49
 
49
50
  /**
50
51
  * @description 注册模型处理器
51
- * @param {string} dynaModelFilePath 模型路径
52
+ * @param {string} pathPattern 路径表达式(奇数位路径段支持通配符)
52
53
  * @param {IModelHandler} handler 执行器
53
54
  * @memberof ModelTransformer
54
55
  */
55
- public registerHandler(
56
- dynaModelFilePath: string,
57
- handler: ModelHandler,
58
- ): void {
59
- const handlers = this.handlerMap.get(dynaModelFilePath);
56
+ public registerHandler(pathPattern: string, handler: ModelHandler): void {
57
+ if (!this.validatePattern(pathPattern)) {
58
+ return;
59
+ }
60
+ const handlers = this.handlerMap.get(pathPattern);
60
61
  if (handlers) {
61
62
  handlers.push(handler);
62
63
  } else {
63
- this.handlerMap.set(dynaModelFilePath, [handler]);
64
+ this.handlerMap.set(pathPattern, [handler]);
64
65
  }
65
- // 注册新处理器后清除该路径的模型缓存,确保新处理器能生效
66
- this.modelCacheMap.delete(dynaModelFilePath);
66
+ }
67
+
68
+ /**
69
+ * @description 校验模型路径,从0开始数,偶数位路径段(如PSSYSAPPS、PSAPPDATAENTITIES等类型段)不允许使用通配符,奇数位路径段可使用
70
+ * @private
71
+ * @param {string} pathPattern 路径表达式
72
+ * @returns {*} {boolean}
73
+ * @memberof ModelTransformer
74
+ */
75
+ private validatePattern(pathPattern: string): boolean {
76
+ const segments = pathPattern.split('/');
77
+ const isValid = segments.every((segment: string, index: number) => {
78
+ // 偶数位不允许出现通配符,奇数位有无通配符均可
79
+ return index % 2 === 1 || !/[*?]/.test(segment);
80
+ });
81
+ if (!isValid) {
82
+ ibiz.log.error(
83
+ ibiz.i18n.t('modelHelper.utils.invalidPathPattern', {
84
+ pathPattern,
85
+ }),
86
+ );
87
+ }
88
+ return isValid;
67
89
  }
68
90
 
69
91
  /**
@@ -79,16 +101,18 @@ export class ModelTransformer {
79
101
  dynaModelFilePath,
80
102
  }),
81
103
  );
82
- if (this.modelCacheMap.has(dynaModelFilePath)) {
83
- return this.modelCacheMap.get(dynaModelFilePath)!;
84
- }
85
- const handlers = this.handlerMap.get(dynaModelFilePath);
86
- if (!handlers || handlers.length === 0) {
87
- this.modelCacheMap.set(dynaModelFilePath, model);
104
+ // 收集所有匹配当前路径的处理器(支持通配符路径)
105
+ const matchedHandlers: ModelHandler[] = [];
106
+ this.handlerMap.forEach((handlers: ModelHandler[], pattern: string) => {
107
+ if (this.pathMatcher.match(pattern, dynaModelFilePath)) {
108
+ matchedHandlers.push(...handlers);
109
+ }
110
+ });
111
+ if (matchedHandlers.length === 0) {
88
112
  return model;
89
113
  }
90
114
  // 按照优先级升序排序,优先级高的后执行
91
- const sortedHandlers = [...handlers].sort(
115
+ const sortedHandlers = [...matchedHandlers].sort(
92
116
  (a: ModelHandler, b: ModelHandler) => a.priority - b.priority,
93
117
  );
94
118
  // 模型处理
@@ -118,7 +142,6 @@ export class ModelTransformer {
118
142
  return model;
119
143
  }
120
144
  }
121
- this.modelCacheMap.set(dynaModelFilePath, result);
122
145
  return result;
123
146
  }
124
147
  }