@dagger.io/dagger 0.10.0 → 0.10.2
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/api/client.gen.d.ts +35 -5
- package/dist/api/client.gen.d.ts.map +1 -1
- package/dist/api/client.gen.js +12 -4
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/api/utils.js +6 -2
- package/dist/common/errors/ExecError.d.ts.map +1 -1
- package/dist/entrypoint/context.d.ts +8 -0
- package/dist/entrypoint/context.d.ts.map +1 -0
- package/dist/entrypoint/invoke.d.ts +3 -9
- package/dist/entrypoint/invoke.d.ts.map +1 -1
- package/dist/entrypoint/invoke.js +17 -28
- package/dist/entrypoint/load.d.ts +29 -69
- package/dist/entrypoint/load.d.ts.map +1 -1
- package/dist/entrypoint/load.js +90 -173
- package/dist/entrypoint/register.d.ts +2 -2
- package/dist/entrypoint/register.d.ts.map +1 -1
- package/dist/entrypoint/register.js +12 -12
- package/dist/introspector/scanner/abtractions/argument.d.ts +75 -0
- package/dist/introspector/scanner/abtractions/argument.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/argument.js +137 -0
- package/dist/introspector/scanner/abtractions/constructor.d.ts +16 -0
- package/dist/introspector/scanner/abtractions/constructor.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/constructor.js +42 -0
- package/dist/introspector/scanner/abtractions/method.d.ts +51 -0
- package/dist/introspector/scanner/abtractions/method.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/method.js +105 -0
- package/dist/introspector/scanner/abtractions/module.d.ts +18 -0
- package/dist/introspector/scanner/abtractions/module.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/module.js +59 -0
- package/dist/introspector/scanner/abtractions/object.d.ts +37 -0
- package/dist/introspector/scanner/abtractions/object.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/object.js +94 -0
- package/dist/introspector/scanner/abtractions/property.d.ts +46 -0
- package/dist/introspector/scanner/abtractions/property.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/property.js +93 -0
- package/dist/introspector/scanner/scan.d.ts +2 -1
- package/dist/introspector/scanner/scan.d.ts.map +1 -1
- package/dist/introspector/scanner/scan.js +2 -181
- package/dist/introspector/scanner/serialize.d.ts +0 -24
- package/dist/introspector/scanner/serialize.d.ts.map +1 -1
- package/dist/introspector/scanner/serialize.js +0 -53
- package/dist/introspector/scanner/typeDefs.d.ts +3 -3
- package/dist/introspector/scanner/typeDefs.d.ts.map +1 -1
- package/dist/introspector/scanner/utils.d.ts +1 -57
- package/dist/introspector/scanner/utils.d.ts.map +1 -1
- package/dist/introspector/scanner/utils.js +16 -139
- package/dist/provisioning/bin.d.ts.map +1 -1
- package/dist/provisioning/bin.js +9 -3
- package/dist/provisioning/default.d.ts +1 -1
- package/dist/provisioning/default.js +1 -1
- package/package.json +6 -5
- package/dist/introspector/scanner/metadata.d.ts +0 -24
- package/dist/introspector/scanner/metadata.d.ts.map +0 -1
- /package/dist/{introspector/scanner/metadata.js → entrypoint/context.js} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { Arguments } from "./argument.js";
|
|
3
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
4
|
+
import { FunctionTypedef, TypeDef } from "../typeDefs.js";
|
|
5
|
+
export type Methods = {
|
|
6
|
+
[name: string]: Method;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Method is an abstraction of a function or method.
|
|
10
|
+
*
|
|
11
|
+
* This aims to simplify and adds clarity to how we analyse the code and using
|
|
12
|
+
* clear accessor.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Method {
|
|
15
|
+
private checker;
|
|
16
|
+
private method;
|
|
17
|
+
private symbol;
|
|
18
|
+
private signature;
|
|
19
|
+
private decorator;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new Method instance.
|
|
22
|
+
*
|
|
23
|
+
* @param checker Checker to use to introspect the method.
|
|
24
|
+
* @param method The method to introspect.
|
|
25
|
+
*
|
|
26
|
+
* @throws UnknownDaggerError If the method doesn't have any symbol.
|
|
27
|
+
* @throws UnknownDaggerError If the method doesn't have any signature.
|
|
28
|
+
*/
|
|
29
|
+
constructor(checker: ts.TypeChecker, method: ts.MethodDeclaration);
|
|
30
|
+
get name(): string;
|
|
31
|
+
get description(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Return the alias of the method if it has one.
|
|
34
|
+
*/
|
|
35
|
+
get alias(): string | undefined;
|
|
36
|
+
get arguments(): Arguments;
|
|
37
|
+
/**
|
|
38
|
+
* Return the type of the return value in a Dagger TypeDef format.
|
|
39
|
+
*/
|
|
40
|
+
get returnType(): TypeDef<TypeDefKind>;
|
|
41
|
+
get typeDef(): FunctionTypedef;
|
|
42
|
+
toJSON(): {
|
|
43
|
+
name: string;
|
|
44
|
+
description: string;
|
|
45
|
+
alias: string | undefined;
|
|
46
|
+
arguments: Arguments;
|
|
47
|
+
returnType: TypeDef<TypeDefKind>;
|
|
48
|
+
};
|
|
49
|
+
getArgOrder(): string[];
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=method.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../../introspector/scanner/abtractions/method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,EAAY,SAAS,EAAE,MAAM,eAAe,CAAA;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAsB,eAAe,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAI7E,MAAM,MAAM,OAAO,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAA;AAEhD;;;;;GAKG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,MAAM,CAAsB;IAEpC,OAAO,CAAC,MAAM,CAAW;IAEzB,OAAO,CAAC,SAAS,CAAc;IAE/B,OAAO,CAAC,SAAS,CAA0B;IAE3C;;;;;;;;OAQG;gBACS,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC,iBAAiB;IAiCjE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,WAAW,IAAI,MAAM,CAIxB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAa9B;IAED,IAAI,SAAS,IAAI,SAAS,CAQzB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC,CAIrC;IAED,IAAI,OAAO,IAAI,eAAe,CAe7B;IAED,MAAM;;;;;;;IAUN,WAAW,IAAI,MAAM,EAAE;CAGxB"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { UnknownDaggerError } from "../../../common/errors/UnknownDaggerError.js";
|
|
3
|
+
import { Argument } from "./argument.js";
|
|
4
|
+
import { serializeType } from "../serialize.js";
|
|
5
|
+
import { typeNameToTypedef } from "../utils.js";
|
|
6
|
+
const METHOD_DECORATOR = "func";
|
|
7
|
+
/**
|
|
8
|
+
* Method is an abstraction of a function or method.
|
|
9
|
+
*
|
|
10
|
+
* This aims to simplify and adds clarity to how we analyse the code and using
|
|
11
|
+
* clear accessor.
|
|
12
|
+
*/
|
|
13
|
+
export class Method {
|
|
14
|
+
checker;
|
|
15
|
+
method;
|
|
16
|
+
symbol;
|
|
17
|
+
signature;
|
|
18
|
+
decorator;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new Method instance.
|
|
21
|
+
*
|
|
22
|
+
* @param checker Checker to use to introspect the method.
|
|
23
|
+
* @param method The method to introspect.
|
|
24
|
+
*
|
|
25
|
+
* @throws UnknownDaggerError If the method doesn't have any symbol.
|
|
26
|
+
* @throws UnknownDaggerError If the method doesn't have any signature.
|
|
27
|
+
*/
|
|
28
|
+
constructor(checker, method) {
|
|
29
|
+
this.checker = checker;
|
|
30
|
+
this.method = method;
|
|
31
|
+
const methodSymbol = checker.getSymbolAtLocation(method.name);
|
|
32
|
+
if (!methodSymbol) {
|
|
33
|
+
throw new UnknownDaggerError(`could not get method symbol: ${method.name.getText()}`, {});
|
|
34
|
+
}
|
|
35
|
+
this.symbol = methodSymbol;
|
|
36
|
+
const signature = checker.getSignatureFromDeclaration(method);
|
|
37
|
+
if (!signature) {
|
|
38
|
+
throw new UnknownDaggerError(`could not get method signature: ${method.name.getText()}`, {});
|
|
39
|
+
}
|
|
40
|
+
this.signature = signature;
|
|
41
|
+
this.decorator = ts.getDecorators(method)?.find((d) => {
|
|
42
|
+
if (ts.isCallExpression(d.expression)) {
|
|
43
|
+
return d.expression.expression.getText() === METHOD_DECORATOR;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
get name() {
|
|
49
|
+
return this.symbol.getName();
|
|
50
|
+
}
|
|
51
|
+
get description() {
|
|
52
|
+
return ts.displayPartsToString(this.symbol.getDocumentationComment(this.checker));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Return the alias of the method if it has one.
|
|
56
|
+
*/
|
|
57
|
+
get alias() {
|
|
58
|
+
if (!this.decorator) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const expression = this.decorator.expression;
|
|
62
|
+
const aliasArg = expression.arguments[0];
|
|
63
|
+
if (!aliasArg) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return JSON.parse(aliasArg.getText().replace(/'/g, '"'));
|
|
67
|
+
}
|
|
68
|
+
get arguments() {
|
|
69
|
+
return this.signature.parameters.reduce((acc, param) => {
|
|
70
|
+
const argument = new Argument(this.checker, param);
|
|
71
|
+
acc[argument.name] = argument;
|
|
72
|
+
return acc;
|
|
73
|
+
}, {});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Return the type of the return value in a Dagger TypeDef format.
|
|
77
|
+
*/
|
|
78
|
+
get returnType() {
|
|
79
|
+
return typeNameToTypedef(serializeType(this.checker, this.signature.getReturnType()));
|
|
80
|
+
}
|
|
81
|
+
get typeDef() {
|
|
82
|
+
return {
|
|
83
|
+
name: this.name,
|
|
84
|
+
description: this.description,
|
|
85
|
+
alias: this.alias,
|
|
86
|
+
args: Object.entries(this.arguments).reduce((acc, [name, arg]) => {
|
|
87
|
+
acc[name] = arg.typeDef;
|
|
88
|
+
return acc;
|
|
89
|
+
}, {}),
|
|
90
|
+
returnType: this.returnType,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
toJSON() {
|
|
94
|
+
return {
|
|
95
|
+
name: this.name,
|
|
96
|
+
description: this.description,
|
|
97
|
+
alias: this.alias,
|
|
98
|
+
arguments: this.arguments,
|
|
99
|
+
returnType: this.returnType,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
getArgOrder() {
|
|
103
|
+
return Object.keys(this.arguments);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { DaggerObject, DaggerObjects } from "./object.js";
|
|
3
|
+
export declare class DaggerModule {
|
|
4
|
+
private checker;
|
|
5
|
+
private readonly files;
|
|
6
|
+
name: string;
|
|
7
|
+
constructor(checker: ts.TypeChecker, name: string | undefined, files: readonly ts.SourceFile[]);
|
|
8
|
+
get objects(): DaggerObjects;
|
|
9
|
+
get description(): string | undefined;
|
|
10
|
+
toJSON(): {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string | undefined;
|
|
13
|
+
objects: {
|
|
14
|
+
[name: string]: DaggerObject;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../introspector/scanner/abtractions/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAGzD,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiB;IAEhC,IAAI,EAAE,MAAM,CAAA;gBAGjB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,oBAAK,EACT,KAAK,EAAE,SAAS,EAAE,CAAC,UAAU,EAAE;IAOjC,IAAI,OAAO,IAAI,aAAa,CAc3B;IAED,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAgCpC;IAED,MAAM;;;;;;;CAcP"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { DaggerObject } from "./object.js";
|
|
3
|
+
import { isObject, toPascalCase } from "../utils.js";
|
|
4
|
+
export class DaggerModule {
|
|
5
|
+
checker;
|
|
6
|
+
files;
|
|
7
|
+
name;
|
|
8
|
+
constructor(checker, name = "", files) {
|
|
9
|
+
this.checker = checker;
|
|
10
|
+
this.files = files.filter((file) => !file.isDeclarationFile);
|
|
11
|
+
this.name = toPascalCase(name);
|
|
12
|
+
}
|
|
13
|
+
get objects() {
|
|
14
|
+
const objects = {};
|
|
15
|
+
for (const file of this.files) {
|
|
16
|
+
ts.forEachChild(file, (node) => {
|
|
17
|
+
if (ts.isClassDeclaration(node) && isObject(node)) {
|
|
18
|
+
const object = new DaggerObject(this.checker, file, node);
|
|
19
|
+
objects[object.name] = object;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return objects;
|
|
24
|
+
}
|
|
25
|
+
get description() {
|
|
26
|
+
const mainObject = Object.values(this.objects).find((object) => object.name === this.name);
|
|
27
|
+
if (!mainObject) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const file = mainObject.file;
|
|
31
|
+
const topLevelStatement = file.statements[0];
|
|
32
|
+
if (!topLevelStatement) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
// Get the range of the top level comment
|
|
36
|
+
const topLevelCommentRanges = ts.getLeadingCommentRanges(file.getFullText(), topLevelStatement.pos);
|
|
37
|
+
if (!topLevelCommentRanges || topLevelCommentRanges.length === 0) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const topLevelCommentRange = topLevelCommentRanges[0];
|
|
41
|
+
return file
|
|
42
|
+
.getFullText()
|
|
43
|
+
.substring(topLevelCommentRange.pos, topLevelCommentRange.end)
|
|
44
|
+
.split("\n")
|
|
45
|
+
.slice(1, -1) // Remove start and ending comments characters `/** */`
|
|
46
|
+
.map((line) => line.replace("*", "").trim()) // Remove leading * and spaces
|
|
47
|
+
.join("\n");
|
|
48
|
+
}
|
|
49
|
+
toJSON() {
|
|
50
|
+
return {
|
|
51
|
+
name: this.name,
|
|
52
|
+
description: this.description,
|
|
53
|
+
objects: Object.entries(this.objects).reduce((acc, [name, object]) => {
|
|
54
|
+
acc[name] = object;
|
|
55
|
+
return acc;
|
|
56
|
+
}, {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { Constructor } from "./constructor.js";
|
|
3
|
+
import { Methods } from "./method.js";
|
|
4
|
+
import { Properties } from "./property.js";
|
|
5
|
+
import { ClassTypeDef } from "../typeDefs.js";
|
|
6
|
+
export type DaggerObjects = {
|
|
7
|
+
[name: string]: DaggerObject;
|
|
8
|
+
};
|
|
9
|
+
export declare class DaggerObject {
|
|
10
|
+
private checker;
|
|
11
|
+
private class;
|
|
12
|
+
private symbol;
|
|
13
|
+
file: ts.SourceFile;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param checker The checker to use to introspect the class.
|
|
17
|
+
* @param classDeclaration The class to introspect.
|
|
18
|
+
*
|
|
19
|
+
* @throws UnknownDaggerError If the class doesn't have a name.
|
|
20
|
+
* @throws UnknownDaggerError If the class doesn't have a symbol.
|
|
21
|
+
*/
|
|
22
|
+
constructor(checker: ts.TypeChecker, file: ts.SourceFile, classDeclaration: ts.ClassDeclaration);
|
|
23
|
+
get name(): string;
|
|
24
|
+
get description(): string;
|
|
25
|
+
get _constructor(): Constructor | undefined;
|
|
26
|
+
get methods(): Methods;
|
|
27
|
+
get properties(): Properties;
|
|
28
|
+
get typeDef(): ClassTypeDef;
|
|
29
|
+
toJSON(): {
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
constructor: Constructor | undefined;
|
|
33
|
+
methods: Methods;
|
|
34
|
+
properties: Properties;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../../introspector/scanner/abtractions/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EAAU,OAAO,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAY,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,YAAY,EAAiC,MAAM,gBAAgB,CAAA;AAG5E,MAAM,MAAM,aAAa,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,CAAA;AAE5D,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,KAAK,CAAqB;IAElC,OAAO,CAAC,MAAM,CAAW;IAElB,IAAI,EAAE,EAAE,CAAC,UAAU,CAAA;IAE1B;;;;;;;OAOG;gBAED,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,EAAE,EAAE,CAAC,UAAU,EACnB,gBAAgB,EAAE,EAAE,CAAC,gBAAgB;IAwBvC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,WAAW,IAAI,MAAM,CAIxB;IAED,IAAI,YAAY,IAAI,WAAW,GAAG,SAAS,CAe1C;IAED,IAAI,OAAO,IAAI,OAAO,CAUrB;IAED,IAAI,UAAU,IAAI,UAAU,CAY3B;IAID,IAAI,OAAO,IAAI,YAAY,CAoB1B;IAED,MAAM;;;;;;;CASP"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { Constructor } from "./constructor.js";
|
|
3
|
+
import { UnknownDaggerError } from "../../../common/errors/UnknownDaggerError.js";
|
|
4
|
+
import { Method } from "./method.js";
|
|
5
|
+
import { Property } from "./property.js";
|
|
6
|
+
import { isFunction } from "../utils.js";
|
|
7
|
+
export class DaggerObject {
|
|
8
|
+
checker;
|
|
9
|
+
class;
|
|
10
|
+
symbol;
|
|
11
|
+
file;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param checker The checker to use to introspect the class.
|
|
15
|
+
* @param classDeclaration The class to introspect.
|
|
16
|
+
*
|
|
17
|
+
* @throws UnknownDaggerError If the class doesn't have a name.
|
|
18
|
+
* @throws UnknownDaggerError If the class doesn't have a symbol.
|
|
19
|
+
*/
|
|
20
|
+
constructor(checker, file, classDeclaration) {
|
|
21
|
+
this.checker = checker;
|
|
22
|
+
this.class = classDeclaration;
|
|
23
|
+
this.file = file;
|
|
24
|
+
if (!classDeclaration.name) {
|
|
25
|
+
throw new UnknownDaggerError(`could not introspect class: ${classDeclaration}`, {});
|
|
26
|
+
}
|
|
27
|
+
const classSymbol = checker.getSymbolAtLocation(classDeclaration.name);
|
|
28
|
+
if (!classSymbol) {
|
|
29
|
+
throw new UnknownDaggerError(`could not get class symbol: ${classDeclaration.name.getText()}`, {});
|
|
30
|
+
}
|
|
31
|
+
this.symbol = classSymbol;
|
|
32
|
+
}
|
|
33
|
+
get name() {
|
|
34
|
+
return this.symbol.getName();
|
|
35
|
+
}
|
|
36
|
+
get description() {
|
|
37
|
+
return ts.displayPartsToString(this.symbol.getDocumentationComment(this.checker));
|
|
38
|
+
}
|
|
39
|
+
get _constructor() {
|
|
40
|
+
const constructor = this.class.members.find((member) => {
|
|
41
|
+
if (ts.isConstructorDeclaration(member)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (!constructor) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return new Constructor(this.checker, constructor);
|
|
49
|
+
}
|
|
50
|
+
get methods() {
|
|
51
|
+
return this.class.members
|
|
52
|
+
.filter((member) => ts.isMethodDeclaration(member) && isFunction(member))
|
|
53
|
+
.reduce((acc, member) => {
|
|
54
|
+
const method = new Method(this.checker, member);
|
|
55
|
+
acc[method.alias ?? method.name] = method;
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
}
|
|
59
|
+
get properties() {
|
|
60
|
+
return this.class.members
|
|
61
|
+
.filter((member) => ts.isPropertyDeclaration(member))
|
|
62
|
+
.reduce((acc, member) => {
|
|
63
|
+
const property = new Property(this.checker, member);
|
|
64
|
+
acc[property.alias ?? property.name] = property;
|
|
65
|
+
return acc;
|
|
66
|
+
}, {});
|
|
67
|
+
}
|
|
68
|
+
// TODO(TomChv): replace with `ToJson` method
|
|
69
|
+
// after the refactor is complete.
|
|
70
|
+
get typeDef() {
|
|
71
|
+
return {
|
|
72
|
+
name: this.name,
|
|
73
|
+
description: this.description,
|
|
74
|
+
constructor: this._constructor?.typeDef,
|
|
75
|
+
methods: Object.entries(this.methods).reduce((acc, [name, method]) => {
|
|
76
|
+
acc[name] = method.typeDef;
|
|
77
|
+
return acc;
|
|
78
|
+
}, {}),
|
|
79
|
+
fields: Object.entries(this.properties).reduce((acc, [name, property]) => {
|
|
80
|
+
acc[name] = property.typeDef;
|
|
81
|
+
return acc;
|
|
82
|
+
}, {}),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
toJSON() {
|
|
86
|
+
return {
|
|
87
|
+
name: this.name,
|
|
88
|
+
description: this.description,
|
|
89
|
+
constructor: this._constructor,
|
|
90
|
+
methods: this.methods,
|
|
91
|
+
properties: this.properties,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { FieldTypeDef, TypeDef } from "../typeDefs.js";
|
|
3
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
4
|
+
export type Properties = {
|
|
5
|
+
[name: string]: Property;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Property is an abstraction of a class property.
|
|
9
|
+
*
|
|
10
|
+
* This aims to simplify and adds clarity to how we analyse the code and using
|
|
11
|
+
* clear accessor.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Property {
|
|
14
|
+
private symbol;
|
|
15
|
+
private checker;
|
|
16
|
+
private property;
|
|
17
|
+
private decorator;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param checker Checker to use to introspect the property.
|
|
21
|
+
* @param property The property to introspect.
|
|
22
|
+
*
|
|
23
|
+
* @throws UnknownDaggerError If the property doesn't have any symbol.
|
|
24
|
+
*/
|
|
25
|
+
constructor(checker: ts.TypeChecker, property: ts.PropertyDeclaration);
|
|
26
|
+
get name(): string;
|
|
27
|
+
get description(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Return the alias of the property if it has one.
|
|
30
|
+
*/
|
|
31
|
+
get alias(): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Return the type of the property in a Dagger TypeDef format.
|
|
34
|
+
*/
|
|
35
|
+
get type(): TypeDef<TypeDefKind>;
|
|
36
|
+
get isExposed(): boolean;
|
|
37
|
+
get typeDef(): FieldTypeDef;
|
|
38
|
+
toJSON(): {
|
|
39
|
+
name: string;
|
|
40
|
+
description: string;
|
|
41
|
+
alias: string | undefined;
|
|
42
|
+
type: TypeDef<TypeDefKind>;
|
|
43
|
+
isExposed: boolean;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=property.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../introspector/scanner/abtractions/property.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAK3B,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAIxD,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AAErD;;;;;GAKG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAW;IAEzB,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,QAAQ,CAAwB;IAExC,OAAO,CAAC,SAAS,CAA0B;IAE3C;;;;;;OAMG;gBACS,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,CAAC,mBAAmB;IAuBrE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,WAAW,IAAI,MAAM,CAIxB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAa9B;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,CAgB/B;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAID,IAAI,OAAO,IAAI,YAAY,CAQ1B;IAED,MAAM;;;;;;;CASP"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { UnknownDaggerError } from "../../../common/errors/UnknownDaggerError.js";
|
|
3
|
+
import { serializeType } from "../serialize.js";
|
|
4
|
+
import { typeNameToTypedef } from "../utils.js";
|
|
5
|
+
const PROPERTY_DECORATOR = "field";
|
|
6
|
+
/**
|
|
7
|
+
* Property is an abstraction of a class property.
|
|
8
|
+
*
|
|
9
|
+
* This aims to simplify and adds clarity to how we analyse the code and using
|
|
10
|
+
* clear accessor.
|
|
11
|
+
*/
|
|
12
|
+
export class Property {
|
|
13
|
+
symbol;
|
|
14
|
+
checker;
|
|
15
|
+
property;
|
|
16
|
+
decorator;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param checker Checker to use to introspect the property.
|
|
20
|
+
* @param property The property to introspect.
|
|
21
|
+
*
|
|
22
|
+
* @throws UnknownDaggerError If the property doesn't have any symbol.
|
|
23
|
+
*/
|
|
24
|
+
constructor(checker, property) {
|
|
25
|
+
this.checker = checker;
|
|
26
|
+
this.property = property;
|
|
27
|
+
const propertySymbol = checker.getSymbolAtLocation(property.name);
|
|
28
|
+
if (!propertySymbol) {
|
|
29
|
+
throw new UnknownDaggerError(`could not get property symbol: ${property.name.getText()}`, {});
|
|
30
|
+
}
|
|
31
|
+
this.symbol = propertySymbol;
|
|
32
|
+
this.decorator = ts.getDecorators(property)?.find((d) => {
|
|
33
|
+
if (ts.isCallExpression(d.expression)) {
|
|
34
|
+
return d.expression.expression.getText() === PROPERTY_DECORATOR;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
get name() {
|
|
40
|
+
return this.property.name.getText();
|
|
41
|
+
}
|
|
42
|
+
get description() {
|
|
43
|
+
return ts.displayPartsToString(this.symbol.getDocumentationComment(this.checker));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Return the alias of the property if it has one.
|
|
47
|
+
*/
|
|
48
|
+
get alias() {
|
|
49
|
+
if (!this.decorator) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const expression = this.decorator.expression;
|
|
53
|
+
const aliasArg = expression.arguments[0];
|
|
54
|
+
if (!aliasArg) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
return JSON.parse(aliasArg.getText().replace(/'/g, '"'));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Return the type of the property in a Dagger TypeDef format.
|
|
61
|
+
*/
|
|
62
|
+
get type() {
|
|
63
|
+
if (!this.symbol.valueDeclaration) {
|
|
64
|
+
throw new UnknownDaggerError("could not find symbol value declaration", {});
|
|
65
|
+
}
|
|
66
|
+
const type = this.checker.getTypeOfSymbolAtLocation(this.symbol, this.symbol.valueDeclaration);
|
|
67
|
+
const typeName = serializeType(this.checker, type);
|
|
68
|
+
return typeNameToTypedef(typeName);
|
|
69
|
+
}
|
|
70
|
+
get isExposed() {
|
|
71
|
+
return this.decorator !== undefined;
|
|
72
|
+
}
|
|
73
|
+
// TODO(TomChv): replace with `ToJson` method
|
|
74
|
+
// after the refactor is complete.
|
|
75
|
+
get typeDef() {
|
|
76
|
+
return {
|
|
77
|
+
name: this.name,
|
|
78
|
+
description: this.description,
|
|
79
|
+
alias: this.alias,
|
|
80
|
+
typeDef: this.type,
|
|
81
|
+
isExposed: this.isExposed,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
toJSON() {
|
|
85
|
+
return {
|
|
86
|
+
name: this.name,
|
|
87
|
+
description: this.description,
|
|
88
|
+
alias: this.alias,
|
|
89
|
+
type: this.type,
|
|
90
|
+
isExposed: this.isExposed,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ClassTypeDef, FunctionTypedef } from "./typeDefs.js";
|
|
2
|
+
import { DaggerModule } from "./abtractions/module.js";
|
|
2
3
|
export type ScanResult = {
|
|
3
4
|
module: {
|
|
4
5
|
description?: string;
|
|
@@ -21,5 +22,5 @@ export type ScanResult = {
|
|
|
21
22
|
* @param files List of TypeScript files to introspect.
|
|
22
23
|
* @param moduleName The name of the module to introspect.
|
|
23
24
|
*/
|
|
24
|
-
export declare function scan(files: string[], moduleName?: string):
|
|
25
|
+
export declare function scan(files: string[], moduleName?: string): DaggerModule;
|
|
25
26
|
//# sourceMappingURL=scan.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/scan.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/scan.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEtD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE;QACN,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,OAAO,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAA;IACzC,SAAS,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;KAAE,CAAA;CAC/C,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,SAAK,GAAG,YAAY,CAUnE"}
|