@living-architecture/riviere-cli 0.8.2 → 0.8.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.
- package/dist/bin.js +111 -1
- package/dist/index.js +110 -0
- package/package.json +2 -2
package/dist/bin.js
CHANGED
|
@@ -26270,6 +26270,63 @@ function extractLiteralValue(expression, file2, line) {
|
|
|
26270
26270
|
|
|
26271
26271
|
// ../riviere-extract-ts/dist/domain/value-extraction/evaluate-extraction-rule-generic.js
|
|
26272
26272
|
import { SyntaxKind as SyntaxKind2 } from "ts-morph";
|
|
26273
|
+
function getInterfaceTypeArgs(classDecl, interfaceName) {
|
|
26274
|
+
const implementsClause = classDecl.getImplements();
|
|
26275
|
+
for (const impl of implementsClause) {
|
|
26276
|
+
const expression = impl.getExpression();
|
|
26277
|
+
if (expression.getText() === interfaceName) {
|
|
26278
|
+
return impl.getTypeArguments();
|
|
26279
|
+
}
|
|
26280
|
+
}
|
|
26281
|
+
const extendsClause = classDecl.getExtends();
|
|
26282
|
+
if (extendsClause === void 0) {
|
|
26283
|
+
return void 0;
|
|
26284
|
+
}
|
|
26285
|
+
const baseClass = classDecl.getBaseClass();
|
|
26286
|
+
if (baseClass === void 0)
|
|
26287
|
+
return void 0;
|
|
26288
|
+
return getInterfaceTypeArgs(baseClass, interfaceName);
|
|
26289
|
+
}
|
|
26290
|
+
function extractTypeNames(typeNode) {
|
|
26291
|
+
if (typeNode.getKind() === SyntaxKind2.UnionType) {
|
|
26292
|
+
const unionType = typeNode.asKindOrThrow(SyntaxKind2.UnionType);
|
|
26293
|
+
return unionType.getTypeNodes().map((t) => t.getText());
|
|
26294
|
+
}
|
|
26295
|
+
return [typeNode.getText()];
|
|
26296
|
+
}
|
|
26297
|
+
function evaluateFromGenericArgRule(rule, classDecl) {
|
|
26298
|
+
const { interface: interfaceName, position, transform: transform2 } = rule.fromGenericArg;
|
|
26299
|
+
const sourceFile = classDecl.getSourceFile();
|
|
26300
|
+
const location = {
|
|
26301
|
+
filePath: sourceFile.getFilePath(),
|
|
26302
|
+
line: classDecl.getStartLineNumber()
|
|
26303
|
+
};
|
|
26304
|
+
const typeArgs = getInterfaceTypeArgs(classDecl, interfaceName);
|
|
26305
|
+
if (typeArgs === void 0) {
|
|
26306
|
+
throw new ExtractionError(`Class '${classDecl.getName() ?? "anonymous"}' does not implement interface '${interfaceName}'`, location.filePath, location.line);
|
|
26307
|
+
}
|
|
26308
|
+
const typeArg = typeArgs[position];
|
|
26309
|
+
if (typeArg === void 0) {
|
|
26310
|
+
throw new ExtractionError(`Position ${position} out of bounds. Interface has ${typeArgs.length} type argument(s)`, location.filePath, location.line);
|
|
26311
|
+
}
|
|
26312
|
+
if (typeArg.getKind() === SyntaxKind2.TypeReference) {
|
|
26313
|
+
const typeRef = typeArg.asKindOrThrow(SyntaxKind2.TypeReference);
|
|
26314
|
+
const typeName = typeRef.getTypeName();
|
|
26315
|
+
if (typeName.getKind() === SyntaxKind2.Identifier) {
|
|
26316
|
+
const classTypeParams = classDecl.getTypeParameters();
|
|
26317
|
+
const paramName = typeName.getText();
|
|
26318
|
+
const isTypeParam = classTypeParams.some((p) => p.getName() === paramName);
|
|
26319
|
+
if (isTypeParam) {
|
|
26320
|
+
throw new ExtractionError(`Generic argument at position ${position} is type parameter '${paramName}', expected concrete type`, location.filePath, location.line);
|
|
26321
|
+
}
|
|
26322
|
+
}
|
|
26323
|
+
}
|
|
26324
|
+
const typeNames = extractTypeNames(typeArg);
|
|
26325
|
+
if (transform2 === void 0) {
|
|
26326
|
+
return { value: typeNames };
|
|
26327
|
+
}
|
|
26328
|
+
return { value: typeNames.map((name) => applyTransforms(name, transform2)) };
|
|
26329
|
+
}
|
|
26273
26330
|
|
|
26274
26331
|
// ../riviere-extract-ts/dist/domain/value-extraction/evaluate-extraction-rule.js
|
|
26275
26332
|
import { SyntaxKind as SyntaxKind3 } from "ts-morph";
|
|
@@ -26290,6 +26347,17 @@ function evaluateFromClassNameRule(rule, classDecl) {
|
|
|
26290
26347
|
}
|
|
26291
26348
|
return { value: applyTransforms(className, transform2) };
|
|
26292
26349
|
}
|
|
26350
|
+
function evaluateFromMethodNameRule(rule, methodDecl) {
|
|
26351
|
+
const methodName = methodDecl.getName();
|
|
26352
|
+
if (rule.fromMethodName === true) {
|
|
26353
|
+
return { value: methodName };
|
|
26354
|
+
}
|
|
26355
|
+
const transform2 = rule.fromMethodName.transform;
|
|
26356
|
+
if (transform2 === void 0) {
|
|
26357
|
+
return { value: methodName };
|
|
26358
|
+
}
|
|
26359
|
+
return { value: applyTransforms(methodName, transform2) };
|
|
26360
|
+
}
|
|
26293
26361
|
function evaluateFromFilePathRule(rule, filePath) {
|
|
26294
26362
|
const { pattern, capture, transform: transform2 } = rule.fromFilePath;
|
|
26295
26363
|
const regex = new RegExp(pattern);
|
|
@@ -27954,6 +28022,12 @@ function isFromFilePathRule(rule) {
|
|
|
27954
28022
|
function isFromPropertyRule(rule) {
|
|
27955
28023
|
return "fromProperty" in rule;
|
|
27956
28024
|
}
|
|
28025
|
+
function isFromMethodNameRule(rule) {
|
|
28026
|
+
return "fromMethodName" in rule;
|
|
28027
|
+
}
|
|
28028
|
+
function isFromGenericArgRule(rule) {
|
|
28029
|
+
return "fromGenericArg" in rule;
|
|
28030
|
+
}
|
|
27957
28031
|
function findClassAtLine(project, draft) {
|
|
27958
28032
|
const sourceFile = project.getSourceFile(draft.location.file);
|
|
27959
28033
|
if (sourceFile === void 0) {
|
|
@@ -27965,6 +28039,34 @@ function findClassAtLine(project, draft) {
|
|
|
27965
28039
|
}
|
|
27966
28040
|
return classDecl;
|
|
27967
28041
|
}
|
|
28042
|
+
function findMethodAtLine(project, draft) {
|
|
28043
|
+
const sourceFile = project.getSourceFile(draft.location.file);
|
|
28044
|
+
if (sourceFile === void 0) {
|
|
28045
|
+
throw new ExtractionError(`Source file '${draft.location.file}' not found in project`, draft.location.file, draft.location.line);
|
|
28046
|
+
}
|
|
28047
|
+
for (const classDecl of sourceFile.getClasses()) {
|
|
28048
|
+
const method = classDecl.getMethods().find((m) => m.getStartLineNumber() === draft.location.line);
|
|
28049
|
+
if (method !== void 0) {
|
|
28050
|
+
return method;
|
|
28051
|
+
}
|
|
28052
|
+
}
|
|
28053
|
+
throw new ExtractionError(`No method declaration found at line ${draft.location.line}`, draft.location.file, draft.location.line);
|
|
28054
|
+
}
|
|
28055
|
+
function findContainingClass(project, draft) {
|
|
28056
|
+
const sourceFile = project.getSourceFile(draft.location.file);
|
|
28057
|
+
if (sourceFile === void 0) {
|
|
28058
|
+
throw new ExtractionError(`Source file '${draft.location.file}' not found in project`, draft.location.file, draft.location.line);
|
|
28059
|
+
}
|
|
28060
|
+
const methodLine = draft.location.line;
|
|
28061
|
+
for (const classDecl of sourceFile.getClasses()) {
|
|
28062
|
+
const classStart = classDecl.getStartLineNumber();
|
|
28063
|
+
const classEnd = classDecl.getEndLineNumber();
|
|
28064
|
+
if (methodLine >= classStart && methodLine <= classEnd) {
|
|
28065
|
+
return classDecl;
|
|
28066
|
+
}
|
|
28067
|
+
}
|
|
28068
|
+
throw new ExtractionError(`No containing class found for method at line ${methodLine}`, draft.location.file, draft.location.line);
|
|
28069
|
+
}
|
|
27968
28070
|
function evaluateClassRule(rule, classDecl) {
|
|
27969
28071
|
if (isFromClassNameRule(rule)) {
|
|
27970
28072
|
return evaluateFromClassNameRule(rule, classDecl);
|
|
@@ -27981,6 +28083,14 @@ function evaluateRule(rule, draft, project) {
|
|
|
27981
28083
|
if (isFromFilePathRule(rule)) {
|
|
27982
28084
|
return evaluateFromFilePathRule(rule, draft.location.file);
|
|
27983
28085
|
}
|
|
28086
|
+
if (isFromMethodNameRule(rule)) {
|
|
28087
|
+
const methodDecl = findMethodAtLine(project, draft);
|
|
28088
|
+
return evaluateFromMethodNameRule(rule, methodDecl);
|
|
28089
|
+
}
|
|
28090
|
+
if (isFromGenericArgRule(rule)) {
|
|
28091
|
+
const classDecl2 = findContainingClass(project, draft);
|
|
28092
|
+
return evaluateFromGenericArgRule(rule, classDecl2);
|
|
28093
|
+
}
|
|
27984
28094
|
const classDecl = findClassAtLine(project, draft);
|
|
27985
28095
|
return evaluateClassRule(rule, classDecl);
|
|
27986
28096
|
}
|
|
@@ -28660,7 +28770,7 @@ function parsePackageJson(pkg) {
|
|
|
28660
28770
|
}
|
|
28661
28771
|
function loadPackageJson() {
|
|
28662
28772
|
if (true) {
|
|
28663
|
-
return { version: "0.8.
|
|
28773
|
+
return { version: "0.8.2" };
|
|
28664
28774
|
}
|
|
28665
28775
|
const require2 = createRequire2(import.meta.url);
|
|
28666
28776
|
return parsePackageJson(require2("../../package.json"));
|
package/dist/index.js
CHANGED
|
@@ -26295,6 +26295,63 @@ function extractLiteralValue(expression, file2, line) {
|
|
|
26295
26295
|
|
|
26296
26296
|
// ../riviere-extract-ts/dist/domain/value-extraction/evaluate-extraction-rule-generic.js
|
|
26297
26297
|
import { SyntaxKind as SyntaxKind2 } from "ts-morph";
|
|
26298
|
+
function getInterfaceTypeArgs(classDecl, interfaceName) {
|
|
26299
|
+
const implementsClause = classDecl.getImplements();
|
|
26300
|
+
for (const impl of implementsClause) {
|
|
26301
|
+
const expression = impl.getExpression();
|
|
26302
|
+
if (expression.getText() === interfaceName) {
|
|
26303
|
+
return impl.getTypeArguments();
|
|
26304
|
+
}
|
|
26305
|
+
}
|
|
26306
|
+
const extendsClause = classDecl.getExtends();
|
|
26307
|
+
if (extendsClause === void 0) {
|
|
26308
|
+
return void 0;
|
|
26309
|
+
}
|
|
26310
|
+
const baseClass = classDecl.getBaseClass();
|
|
26311
|
+
if (baseClass === void 0)
|
|
26312
|
+
return void 0;
|
|
26313
|
+
return getInterfaceTypeArgs(baseClass, interfaceName);
|
|
26314
|
+
}
|
|
26315
|
+
function extractTypeNames(typeNode) {
|
|
26316
|
+
if (typeNode.getKind() === SyntaxKind2.UnionType) {
|
|
26317
|
+
const unionType = typeNode.asKindOrThrow(SyntaxKind2.UnionType);
|
|
26318
|
+
return unionType.getTypeNodes().map((t) => t.getText());
|
|
26319
|
+
}
|
|
26320
|
+
return [typeNode.getText()];
|
|
26321
|
+
}
|
|
26322
|
+
function evaluateFromGenericArgRule(rule, classDecl) {
|
|
26323
|
+
const { interface: interfaceName, position, transform: transform2 } = rule.fromGenericArg;
|
|
26324
|
+
const sourceFile = classDecl.getSourceFile();
|
|
26325
|
+
const location = {
|
|
26326
|
+
filePath: sourceFile.getFilePath(),
|
|
26327
|
+
line: classDecl.getStartLineNumber()
|
|
26328
|
+
};
|
|
26329
|
+
const typeArgs = getInterfaceTypeArgs(classDecl, interfaceName);
|
|
26330
|
+
if (typeArgs === void 0) {
|
|
26331
|
+
throw new ExtractionError(`Class '${classDecl.getName() ?? "anonymous"}' does not implement interface '${interfaceName}'`, location.filePath, location.line);
|
|
26332
|
+
}
|
|
26333
|
+
const typeArg = typeArgs[position];
|
|
26334
|
+
if (typeArg === void 0) {
|
|
26335
|
+
throw new ExtractionError(`Position ${position} out of bounds. Interface has ${typeArgs.length} type argument(s)`, location.filePath, location.line);
|
|
26336
|
+
}
|
|
26337
|
+
if (typeArg.getKind() === SyntaxKind2.TypeReference) {
|
|
26338
|
+
const typeRef = typeArg.asKindOrThrow(SyntaxKind2.TypeReference);
|
|
26339
|
+
const typeName = typeRef.getTypeName();
|
|
26340
|
+
if (typeName.getKind() === SyntaxKind2.Identifier) {
|
|
26341
|
+
const classTypeParams = classDecl.getTypeParameters();
|
|
26342
|
+
const paramName = typeName.getText();
|
|
26343
|
+
const isTypeParam = classTypeParams.some((p) => p.getName() === paramName);
|
|
26344
|
+
if (isTypeParam) {
|
|
26345
|
+
throw new ExtractionError(`Generic argument at position ${position} is type parameter '${paramName}', expected concrete type`, location.filePath, location.line);
|
|
26346
|
+
}
|
|
26347
|
+
}
|
|
26348
|
+
}
|
|
26349
|
+
const typeNames = extractTypeNames(typeArg);
|
|
26350
|
+
if (transform2 === void 0) {
|
|
26351
|
+
return { value: typeNames };
|
|
26352
|
+
}
|
|
26353
|
+
return { value: typeNames.map((name) => applyTransforms(name, transform2)) };
|
|
26354
|
+
}
|
|
26298
26355
|
|
|
26299
26356
|
// ../riviere-extract-ts/dist/domain/value-extraction/evaluate-extraction-rule.js
|
|
26300
26357
|
import { SyntaxKind as SyntaxKind3 } from "ts-morph";
|
|
@@ -26315,6 +26372,17 @@ function evaluateFromClassNameRule(rule, classDecl) {
|
|
|
26315
26372
|
}
|
|
26316
26373
|
return { value: applyTransforms(className, transform2) };
|
|
26317
26374
|
}
|
|
26375
|
+
function evaluateFromMethodNameRule(rule, methodDecl) {
|
|
26376
|
+
const methodName = methodDecl.getName();
|
|
26377
|
+
if (rule.fromMethodName === true) {
|
|
26378
|
+
return { value: methodName };
|
|
26379
|
+
}
|
|
26380
|
+
const transform2 = rule.fromMethodName.transform;
|
|
26381
|
+
if (transform2 === void 0) {
|
|
26382
|
+
return { value: methodName };
|
|
26383
|
+
}
|
|
26384
|
+
return { value: applyTransforms(methodName, transform2) };
|
|
26385
|
+
}
|
|
26318
26386
|
function evaluateFromFilePathRule(rule, filePath) {
|
|
26319
26387
|
const { pattern, capture, transform: transform2 } = rule.fromFilePath;
|
|
26320
26388
|
const regex = new RegExp(pattern);
|
|
@@ -27979,6 +28047,12 @@ function isFromFilePathRule(rule) {
|
|
|
27979
28047
|
function isFromPropertyRule(rule) {
|
|
27980
28048
|
return "fromProperty" in rule;
|
|
27981
28049
|
}
|
|
28050
|
+
function isFromMethodNameRule(rule) {
|
|
28051
|
+
return "fromMethodName" in rule;
|
|
28052
|
+
}
|
|
28053
|
+
function isFromGenericArgRule(rule) {
|
|
28054
|
+
return "fromGenericArg" in rule;
|
|
28055
|
+
}
|
|
27982
28056
|
function findClassAtLine(project, draft) {
|
|
27983
28057
|
const sourceFile = project.getSourceFile(draft.location.file);
|
|
27984
28058
|
if (sourceFile === void 0) {
|
|
@@ -27990,6 +28064,34 @@ function findClassAtLine(project, draft) {
|
|
|
27990
28064
|
}
|
|
27991
28065
|
return classDecl;
|
|
27992
28066
|
}
|
|
28067
|
+
function findMethodAtLine(project, draft) {
|
|
28068
|
+
const sourceFile = project.getSourceFile(draft.location.file);
|
|
28069
|
+
if (sourceFile === void 0) {
|
|
28070
|
+
throw new ExtractionError(`Source file '${draft.location.file}' not found in project`, draft.location.file, draft.location.line);
|
|
28071
|
+
}
|
|
28072
|
+
for (const classDecl of sourceFile.getClasses()) {
|
|
28073
|
+
const method = classDecl.getMethods().find((m) => m.getStartLineNumber() === draft.location.line);
|
|
28074
|
+
if (method !== void 0) {
|
|
28075
|
+
return method;
|
|
28076
|
+
}
|
|
28077
|
+
}
|
|
28078
|
+
throw new ExtractionError(`No method declaration found at line ${draft.location.line}`, draft.location.file, draft.location.line);
|
|
28079
|
+
}
|
|
28080
|
+
function findContainingClass(project, draft) {
|
|
28081
|
+
const sourceFile = project.getSourceFile(draft.location.file);
|
|
28082
|
+
if (sourceFile === void 0) {
|
|
28083
|
+
throw new ExtractionError(`Source file '${draft.location.file}' not found in project`, draft.location.file, draft.location.line);
|
|
28084
|
+
}
|
|
28085
|
+
const methodLine = draft.location.line;
|
|
28086
|
+
for (const classDecl of sourceFile.getClasses()) {
|
|
28087
|
+
const classStart = classDecl.getStartLineNumber();
|
|
28088
|
+
const classEnd = classDecl.getEndLineNumber();
|
|
28089
|
+
if (methodLine >= classStart && methodLine <= classEnd) {
|
|
28090
|
+
return classDecl;
|
|
28091
|
+
}
|
|
28092
|
+
}
|
|
28093
|
+
throw new ExtractionError(`No containing class found for method at line ${methodLine}`, draft.location.file, draft.location.line);
|
|
28094
|
+
}
|
|
27993
28095
|
function evaluateClassRule(rule, classDecl) {
|
|
27994
28096
|
if (isFromClassNameRule(rule)) {
|
|
27995
28097
|
return evaluateFromClassNameRule(rule, classDecl);
|
|
@@ -28006,6 +28108,14 @@ function evaluateRule(rule, draft, project) {
|
|
|
28006
28108
|
if (isFromFilePathRule(rule)) {
|
|
28007
28109
|
return evaluateFromFilePathRule(rule, draft.location.file);
|
|
28008
28110
|
}
|
|
28111
|
+
if (isFromMethodNameRule(rule)) {
|
|
28112
|
+
const methodDecl = findMethodAtLine(project, draft);
|
|
28113
|
+
return evaluateFromMethodNameRule(rule, methodDecl);
|
|
28114
|
+
}
|
|
28115
|
+
if (isFromGenericArgRule(rule)) {
|
|
28116
|
+
const classDecl2 = findContainingClass(project, draft);
|
|
28117
|
+
return evaluateFromGenericArgRule(rule, classDecl2);
|
|
28118
|
+
}
|
|
28009
28119
|
const classDecl = findClassAtLine(project, draft);
|
|
28010
28120
|
return evaluateClassRule(rule, classDecl);
|
|
28011
28121
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@living-architecture/riviere-cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"ts-morph": "^24.0.0",
|
|
34
34
|
"yaml": "^2.7.0",
|
|
35
35
|
"@living-architecture/riviere-builder": "0.6.1",
|
|
36
|
-
"@living-architecture/riviere-extract-ts": "0.2.2",
|
|
37
36
|
"@living-architecture/riviere-extract-config": "0.4.1",
|
|
37
|
+
"@living-architecture/riviere-extract-ts": "0.2.3",
|
|
38
38
|
"@living-architecture/riviere-query": "0.5.1",
|
|
39
39
|
"@living-architecture/riviere-schema": "0.5.1"
|
|
40
40
|
}
|