@adaas/a-concept 0.3.5 → 0.3.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-concept",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "A-Concept is a framework of the new generation that is tailored to use AI, enabling developers to create AI-powered applications with ease. It provides a structured approach to building, managing, and deploying AI-driven solutions.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -177,18 +177,34 @@ export function A_Feature_Extend(
177
177
  ];
178
178
 
179
179
  // ensure that other regexps are preserved
180
+ // Only remove the handler from another regexp if that regexp targets
181
+ // the SAME feature name (i.e., same feature, different scope — inheritance case).
182
+ // If the other regexp targets a DIFFERENT feature, leave it alone so that
183
+ // the same method can serve multiple features.
184
+ const currentFeatureName = (param1 && typeof param1 === 'object' && !A_TypeGuards.isRegExp(param1) && (param1 as Partial<A_TYPES__FeatureExtendDecoratorConfig>).name)
185
+ || propertyKey;
186
+
180
187
  for (const [key, handlers] of existedMeta.entries()) {
181
188
 
182
189
  const indexInAnother = handlers.findIndex(item => item.handler === propertyKey);
183
190
 
184
- // if the same handler exists in another regexp, remove it
191
+ // if the same handler exists in another regexp, check if it's the same feature
185
192
  if (key !== targetRegexp.source && indexInAnother !== -1) {
186
- handlers.splice(indexInAnother, 1);
187
- // if no handlers left for this regexp, remove the regexp entry
188
- if (handlers.length === 0) {
189
- existedMeta.delete(key);
190
- } else {
191
- existedMeta.set(key, handlers);
193
+ // Extract the feature name from the other regexp key
194
+ // Regexp keys are built as: ^...\.featureName$ or .*\.featureName$
195
+ const keyStr = String(key);
196
+ const featureNameMatch = keyStr.match(/\\\.\s*([^\\.$]+)\$$/);
197
+ const otherFeatureName = featureNameMatch ? featureNameMatch[1] : null;
198
+
199
+ // Only clean up if the other regexp targets the same feature name
200
+ if (otherFeatureName === currentFeatureName) {
201
+ handlers.splice(indexInAnother, 1);
202
+ // if no handlers left for this regexp, remove the regexp entry
203
+ if (handlers.length === 0) {
204
+ existedMeta.delete(key);
205
+ } else {
206
+ existedMeta.set(key, handlers);
207
+ }
192
208
  }
193
209
  }
194
210
  }
@@ -1075,13 +1075,16 @@ describe('A-Feature tests', () => {
1075
1075
  ]);
1076
1076
  })
1077
1077
 
1078
- it('Should allow to run feature with the same steps', async () => {
1078
+ it('Should allow to define 2 extension under the same method', async () => {
1079
1079
 
1080
1080
  const resultChain: string[] = [];
1081
1081
 
1082
1082
  class ComponentA extends A_Component {
1083
1083
  @A_Feature.Extend({
1084
- name: 'testFeature',
1084
+ name: 'testFeature1',
1085
+ })
1086
+ @A_Feature.Extend({
1087
+ name: 'testFeature2',
1085
1088
  })
1086
1089
  async feature1() {
1087
1090
  resultChain.push('ComponentA.feature1');
@@ -1090,28 +1093,16 @@ describe('A-Feature tests', () => {
1090
1093
 
1091
1094
  const testScope = new A_Scope({ name: 'TestScope', components: [ComponentA] });
1092
1095
 
1093
- const feature = new A_Feature({
1094
- name: 'testFeature',
1095
- scope: testScope,
1096
- template: [
1097
- {
1098
- name: 'ComponentA.feature1',
1099
- dependency: new A_Dependency('ComponentA'),
1100
- handler: 'feature1',
1101
- },
1102
- {
1103
- name: 'ComponentA.feature1',
1104
- dependency: new A_Dependency('ComponentA'),
1105
- handler: 'feature1',
1106
- },
1107
- ]
1108
- });
1096
+ const component = testScope.resolve(ComponentA)!;
1109
1097
 
1110
- await feature.process();
1098
+ component.call('testFeature1');
1099
+ component.call('testFeature2');
1111
1100
 
1112
1101
  expect(resultChain).toEqual([
1113
1102
  'ComponentA.feature1',
1114
1103
  'ComponentA.feature1'
1115
1104
  ]);
1116
1105
  })
1106
+
1107
+
1117
1108
  });