@living-architecture/riviere-extract-ts 0.2.2 → 0.2.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"enrich-components.d.ts","sourceRoot":"","sources":["../../../src/domain/value-extraction/enrich-components.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACQ,OAAO,EAC1B,MAAM,UAAU,CAAA;AAEjB,OAAO,KAAK,EACV,wBAAwB,EAQzB,MAAM,6CAA6C,CAAA;AACpD,OAAO,KAAK,EACV,cAAc,EAAE,WAAW,EAC5B,MAAM,mCAAmC,CAAA;AAU1C,KAAK,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAA;AAEzD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IACD,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IACvC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,cAAc,CAAA;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,iBAAiB,EAAE,CAAA;IAC/B,QAAQ,EAAE,iBAAiB,EAAE,CAAA;CAC9B;AAuND,wBAAgB,gBAAgB,CAC9B,eAAe,EAAE,cAAc,EAAE,EACjC,MAAM,EAAE,wBAAwB,EAChC,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,GAChB,gBAAgB,CAclB"}
1
+ {"version":3,"file":"enrich-components.d.ts","sourceRoot":"","sources":["../../../src/domain/value-extraction/enrich-components.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAC2B,OAAO,EAC7C,MAAM,UAAU,CAAA;AAEjB,OAAO,KAAK,EACV,wBAAwB,EAUzB,MAAM,6CAA6C,CAAA;AACpD,OAAO,KAAK,EACV,cAAc,EAAE,WAAW,EAC5B,MAAM,mCAAmC,CAAA;AAY1C,KAAK,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAA;AAEzD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IACD,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IACvC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,cAAc,CAAA;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,iBAAiB,EAAE,CAAA;IAC/B,QAAQ,EAAE,iBAAiB,EAAE,CAAA;CAC9B;AA6RD,wBAAgB,gBAAgB,CAC9B,eAAe,EAAE,cAAc,EAAE,EACjC,MAAM,EAAE,wBAAwB,EAChC,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,GAChB,gBAAgB,CAclB"}
@@ -1,5 +1,6 @@
1
1
  import { posix } from 'node:path';
2
- import { evaluateLiteralRule, evaluateFromClassNameRule, evaluateFromFilePathRule, evaluateFromPropertyRule, } from './evaluate-extraction-rule';
2
+ import { evaluateLiteralRule, evaluateFromClassNameRule, evaluateFromFilePathRule, evaluateFromPropertyRule, evaluateFromMethodNameRule, } from './evaluate-extraction-rule';
3
+ import { evaluateFromGenericArgRule } from './evaluate-extraction-rule-generic';
3
4
  import { ExtractionError } from '../../platform/domain/ast-literals/literal-detection';
4
5
  function findMatchingModule(filePath, modules, globMatcher, configDir) {
5
6
  const normalized = filePath.replaceAll(/\\+/g, '/');
@@ -54,6 +55,12 @@ function isFromFilePathRule(rule) {
54
55
  function isFromPropertyRule(rule) {
55
56
  return 'fromProperty' in rule;
56
57
  }
58
+ function isFromMethodNameRule(rule) {
59
+ return 'fromMethodName' in rule;
60
+ }
61
+ function isFromGenericArgRule(rule) {
62
+ return 'fromGenericArg' in rule;
63
+ }
57
64
  function findClassAtLine(project, draft) {
58
65
  const sourceFile = project.getSourceFile(draft.location.file);
59
66
  if (sourceFile === undefined) {
@@ -67,6 +74,36 @@ function findClassAtLine(project, draft) {
67
74
  }
68
75
  return classDecl;
69
76
  }
77
+ function findMethodAtLine(project, draft) {
78
+ const sourceFile = project.getSourceFile(draft.location.file);
79
+ if (sourceFile === undefined) {
80
+ throw new ExtractionError(`Source file '${draft.location.file}' not found in project`, draft.location.file, draft.location.line);
81
+ }
82
+ for (const classDecl of sourceFile.getClasses()) {
83
+ const method = classDecl
84
+ .getMethods()
85
+ .find((m) => m.getStartLineNumber() === draft.location.line);
86
+ if (method !== undefined) {
87
+ return method;
88
+ }
89
+ }
90
+ throw new ExtractionError(`No method declaration found at line ${draft.location.line}`, draft.location.file, draft.location.line);
91
+ }
92
+ function findContainingClass(project, draft) {
93
+ const sourceFile = project.getSourceFile(draft.location.file);
94
+ if (sourceFile === undefined) {
95
+ throw new ExtractionError(`Source file '${draft.location.file}' not found in project`, draft.location.file, draft.location.line);
96
+ }
97
+ const methodLine = draft.location.line;
98
+ for (const classDecl of sourceFile.getClasses()) {
99
+ const classStart = classDecl.getStartLineNumber();
100
+ const classEnd = classDecl.getEndLineNumber();
101
+ if (methodLine >= classStart && methodLine <= classEnd) {
102
+ return classDecl;
103
+ }
104
+ }
105
+ throw new ExtractionError(`No containing class found for method at line ${methodLine}`, draft.location.file, draft.location.line);
106
+ }
70
107
  function evaluateClassRule(rule, classDecl) {
71
108
  if (isFromClassNameRule(rule)) {
72
109
  return evaluateFromClassNameRule(rule, classDecl);
@@ -84,6 +121,14 @@ function evaluateRule(rule, draft, project) {
84
121
  if (isFromFilePathRule(rule)) {
85
122
  return evaluateFromFilePathRule(rule, draft.location.file);
86
123
  }
124
+ if (isFromMethodNameRule(rule)) {
125
+ const methodDecl = findMethodAtLine(project, draft);
126
+ return evaluateFromMethodNameRule(rule, methodDecl);
127
+ }
128
+ if (isFromGenericArgRule(rule)) {
129
+ const classDecl = findContainingClass(project, draft);
130
+ return evaluateFromGenericArgRule(rule, classDecl);
131
+ }
87
132
  const classDecl = findClassAtLine(project, draft);
88
133
  return evaluateClassRule(rule, classDecl);
89
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@living-architecture/riviere-extract-ts",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"