@dagger.io/dagger 0.10.1 → 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/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 -149
- 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 +2 -1
- 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
|
@@ -2,33 +2,33 @@ import { dag, TypeDefKind, } from "../api/client.gen.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Register the module files and returns its ID
|
|
4
4
|
*/
|
|
5
|
-
export async function register(files,
|
|
5
|
+
export async function register(files, module) {
|
|
6
6
|
// Get a new module that we will fill in with all the types
|
|
7
7
|
let mod = dag.module_();
|
|
8
8
|
// Add module description if any.
|
|
9
|
-
if (
|
|
10
|
-
mod = mod.withDescription(
|
|
9
|
+
if (module.description) {
|
|
10
|
+
mod = mod.withDescription(module.description);
|
|
11
11
|
}
|
|
12
12
|
// For each class scanned, register its type, method and properties in the module.
|
|
13
|
-
Object.values(
|
|
13
|
+
Object.values(module.objects).forEach((object) => {
|
|
14
14
|
// Register the class Typedef object in Dagger
|
|
15
|
-
let typeDef = dag.typeDef().withObject(
|
|
16
|
-
description:
|
|
15
|
+
let typeDef = dag.typeDef().withObject(object.name, {
|
|
16
|
+
description: object.description,
|
|
17
17
|
});
|
|
18
18
|
// Register all functions (methods) to this object
|
|
19
|
-
Object.values(
|
|
20
|
-
typeDef = typeDef.withFunction(addFunction(method));
|
|
19
|
+
Object.values(object.methods).forEach((method) => {
|
|
20
|
+
typeDef = typeDef.withFunction(addFunction(method.typeDef));
|
|
21
21
|
});
|
|
22
22
|
// Register all fields that belong to this object
|
|
23
|
-
Object.values(
|
|
23
|
+
Object.values(object.properties).forEach((field) => {
|
|
24
24
|
if (field.isExposed) {
|
|
25
|
-
typeDef = typeDef.withField(field.alias ?? field.name, addTypeDef(field.typeDef), {
|
|
25
|
+
typeDef = typeDef.withField(field.alias ?? field.name, addTypeDef(field.typeDef.typeDef), {
|
|
26
26
|
description: field.description,
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
if (
|
|
31
|
-
typeDef = typeDef.withConstructor(addConstructor(
|
|
30
|
+
if (object._constructor) {
|
|
31
|
+
typeDef = typeDef.withConstructor(addConstructor(object._constructor.typeDef, typeDef));
|
|
32
32
|
}
|
|
33
33
|
// Add it to the module object
|
|
34
34
|
mod = mod.withObject(typeDef);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
3
|
+
import { FunctionArgTypeDef, TypeDef } from "../typeDefs.js";
|
|
4
|
+
export type Arguments = {
|
|
5
|
+
[name: string]: Argument;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Argument is an abstraction of a function argument.
|
|
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 Argument {
|
|
14
|
+
private symbol;
|
|
15
|
+
private checker;
|
|
16
|
+
private param;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new Argument instance.
|
|
19
|
+
*
|
|
20
|
+
* @param checker Checker to use to introspect the type of the argument.
|
|
21
|
+
* @param param The symbol of the argument to introspect.
|
|
22
|
+
*
|
|
23
|
+
* @throws UnknownDaggerError If the symbol doesn't have any declaration.
|
|
24
|
+
* @throws UnknownDaggerError If the declaration of the symbol isn't a parameter.
|
|
25
|
+
*/
|
|
26
|
+
constructor(checker: ts.TypeChecker, param: ts.Symbol);
|
|
27
|
+
get name(): string;
|
|
28
|
+
get description(): string;
|
|
29
|
+
/**
|
|
30
|
+
* Return the type of the argument in a Dagger TypeDef format.
|
|
31
|
+
*/
|
|
32
|
+
get type(): TypeDef<TypeDefKind>;
|
|
33
|
+
get defaultValue(): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Return true if the parameter is optional.
|
|
36
|
+
*
|
|
37
|
+
* A parameter is considered optional if he fits one of the following:
|
|
38
|
+
* - It has a question token (e.g. `foo?: <type>`).
|
|
39
|
+
* - It's variadic (e.g. `...foo: <type>[]`).
|
|
40
|
+
* - It's nullable (e.g. `foo: <type> | null`).
|
|
41
|
+
*/
|
|
42
|
+
get isOptional(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Return true if the parameter is nullable.
|
|
45
|
+
*
|
|
46
|
+
* A parameter is considered nullable if itstype is a union type with `null`
|
|
47
|
+
* on the list of types.
|
|
48
|
+
* Example: `foo: string | null`.
|
|
49
|
+
*/
|
|
50
|
+
get isNullable(): boolean;
|
|
51
|
+
get isVariadic(): boolean;
|
|
52
|
+
get typeDef(): FunctionArgTypeDef;
|
|
53
|
+
toJSON(): {
|
|
54
|
+
name: string;
|
|
55
|
+
description: string;
|
|
56
|
+
type: TypeDef<TypeDefKind>;
|
|
57
|
+
isVariadic: boolean;
|
|
58
|
+
isNullable: boolean;
|
|
59
|
+
isOptional: boolean;
|
|
60
|
+
defaultValue: string | undefined;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The TypeScript Compiler API returns the raw default value as it is written
|
|
64
|
+
* by the user.
|
|
65
|
+
* However, some notations are not supported by GraphQL so this function
|
|
66
|
+
* formats the default value to be compatible with the GraphQL syntax.
|
|
67
|
+
*
|
|
68
|
+
* Formatting rules:
|
|
69
|
+
* - Single quote strings are converted to double quote strings.
|
|
70
|
+
*
|
|
71
|
+
* @param value The value to format.
|
|
72
|
+
*/
|
|
73
|
+
private formatDefaultValue;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=argument.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"argument.d.ts","sourceRoot":"","sources":["../../../../introspector/scanner/abtractions/argument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAI5D,MAAM,MAAM,SAAS,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AAEpD;;;;;GAKG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAW;IAEzB,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,KAAK,CAAyB;IAEtC;;;;;;;;OAQG;gBACS,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM;IAuBrD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,WAAW,IAAI,MAAM,CAIxB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,CAgB/B;IAED,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAMrC;IAED;;;;;;;OAOG;IACH,IAAI,UAAU,IAAI,OAAO,CAMxB;IAED;;;;;;OAMG;IACH,IAAI,UAAU,IAAI,OAAO,CAcxB;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAID,IAAI,OAAO,IAAI,kBAAkB,CAShC;IAED,MAAM;;;;;;;;;IAYN;;;;;;;;;;OAUG;IACH,OAAO,CAAC,kBAAkB;CAU3B"}
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Argument is an abstraction of a function argument.
|
|
7
|
+
*
|
|
8
|
+
* This aims to simplify and adds clarity to how we analyse the code and using
|
|
9
|
+
* clear accessor.
|
|
10
|
+
*/
|
|
11
|
+
export class Argument {
|
|
12
|
+
symbol;
|
|
13
|
+
checker;
|
|
14
|
+
param;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new Argument instance.
|
|
17
|
+
*
|
|
18
|
+
* @param checker Checker to use to introspect the type of the argument.
|
|
19
|
+
* @param param The symbol of the argument to introspect.
|
|
20
|
+
*
|
|
21
|
+
* @throws UnknownDaggerError If the symbol doesn't have any declaration.
|
|
22
|
+
* @throws UnknownDaggerError If the declaration of the symbol isn't a parameter.
|
|
23
|
+
*/
|
|
24
|
+
constructor(checker, param) {
|
|
25
|
+
this.symbol = param;
|
|
26
|
+
this.checker = checker;
|
|
27
|
+
const declarations = this.symbol.getDeclarations();
|
|
28
|
+
if (!declarations || declarations.length < 0) {
|
|
29
|
+
throw new UnknownDaggerError(`could not find param declarations of symbol ${this.symbol.name}`, {});
|
|
30
|
+
}
|
|
31
|
+
const parameterDeclaration = declarations[0];
|
|
32
|
+
if (!ts.isParameter(parameterDeclaration)) {
|
|
33
|
+
throw new UnknownDaggerError(`the declaration of symbol ${this.symbol.name} isn't a parameter`, {});
|
|
34
|
+
}
|
|
35
|
+
this.param = parameterDeclaration;
|
|
36
|
+
}
|
|
37
|
+
get name() {
|
|
38
|
+
return this.symbol.getName();
|
|
39
|
+
}
|
|
40
|
+
get description() {
|
|
41
|
+
return ts.displayPartsToString(this.symbol.getDocumentationComment(this.checker));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Return the type of the argument in a Dagger TypeDef format.
|
|
45
|
+
*/
|
|
46
|
+
get type() {
|
|
47
|
+
if (!this.symbol.valueDeclaration) {
|
|
48
|
+
throw new UnknownDaggerError("could not find symbol value declaration", {});
|
|
49
|
+
}
|
|
50
|
+
const type = this.checker.getTypeOfSymbolAtLocation(this.symbol, this.symbol.valueDeclaration);
|
|
51
|
+
const typeName = serializeType(this.checker, type);
|
|
52
|
+
return typeNameToTypedef(typeName);
|
|
53
|
+
}
|
|
54
|
+
get defaultValue() {
|
|
55
|
+
if (this.param.initializer === undefined) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
return this.formatDefaultValue(this.param.initializer.getText());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Return true if the parameter is optional.
|
|
62
|
+
*
|
|
63
|
+
* A parameter is considered optional if he fits one of the following:
|
|
64
|
+
* - It has a question token (e.g. `foo?: <type>`).
|
|
65
|
+
* - It's variadic (e.g. `...foo: <type>[]`).
|
|
66
|
+
* - It's nullable (e.g. `foo: <type> | null`).
|
|
67
|
+
*/
|
|
68
|
+
get isOptional() {
|
|
69
|
+
return (this.param.questionToken !== undefined ||
|
|
70
|
+
this.isVariadic ||
|
|
71
|
+
this.isNullable);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Return true if the parameter is nullable.
|
|
75
|
+
*
|
|
76
|
+
* A parameter is considered nullable if itstype is a union type with `null`
|
|
77
|
+
* on the list of types.
|
|
78
|
+
* Example: `foo: string | null`.
|
|
79
|
+
*/
|
|
80
|
+
get isNullable() {
|
|
81
|
+
if (!this.param.type) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
if (ts.isUnionTypeNode(this.param.type)) {
|
|
85
|
+
for (const _type of this.param.type.types) {
|
|
86
|
+
if (_type.getText() === "null") {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
get isVariadic() {
|
|
94
|
+
return this.param.dotDotDotToken !== undefined;
|
|
95
|
+
}
|
|
96
|
+
// TODO(TomChv): replace with `ToJson` method
|
|
97
|
+
// after the refactor is complete.
|
|
98
|
+
get typeDef() {
|
|
99
|
+
return {
|
|
100
|
+
name: this.name,
|
|
101
|
+
description: this.description,
|
|
102
|
+
optional: this.isOptional,
|
|
103
|
+
defaultValue: this.defaultValue,
|
|
104
|
+
isVariadic: this.isVariadic,
|
|
105
|
+
typeDef: this.type,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
toJSON() {
|
|
109
|
+
return {
|
|
110
|
+
name: this.name,
|
|
111
|
+
description: this.description,
|
|
112
|
+
type: this.type,
|
|
113
|
+
isVariadic: this.isVariadic,
|
|
114
|
+
isNullable: this.isNullable,
|
|
115
|
+
isOptional: this.isOptional,
|
|
116
|
+
defaultValue: this.defaultValue,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The TypeScript Compiler API returns the raw default value as it is written
|
|
121
|
+
* by the user.
|
|
122
|
+
* However, some notations are not supported by GraphQL so this function
|
|
123
|
+
* formats the default value to be compatible with the GraphQL syntax.
|
|
124
|
+
*
|
|
125
|
+
* Formatting rules:
|
|
126
|
+
* - Single quote strings are converted to double quote strings.
|
|
127
|
+
*
|
|
128
|
+
* @param value The value to format.
|
|
129
|
+
*/
|
|
130
|
+
formatDefaultValue(value) {
|
|
131
|
+
const isSingleQuoteString = () => value.startsWith("'") && value.endsWith("'");
|
|
132
|
+
if (isSingleQuoteString()) {
|
|
133
|
+
return `"${value.slice(1, value.length - 1)}"`;
|
|
134
|
+
}
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { Arguments } from "./argument.js";
|
|
3
|
+
import { ConstructorTypeDef } from "../typeDefs.js";
|
|
4
|
+
export declare class Constructor {
|
|
5
|
+
private checker;
|
|
6
|
+
private declaration;
|
|
7
|
+
constructor(checker: ts.TypeChecker, declaration: ts.ConstructorDeclaration);
|
|
8
|
+
get name(): string;
|
|
9
|
+
get arguments(): Arguments;
|
|
10
|
+
get typeDef(): ConstructorTypeDef;
|
|
11
|
+
toJSON(): {
|
|
12
|
+
args: Arguments;
|
|
13
|
+
};
|
|
14
|
+
getArgOrder(): string[];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=constructor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constructor.d.ts","sourceRoot":"","sources":["../../../../introspector/scanner/abtractions/constructor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAY,SAAS,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAsB,MAAM,gBAAgB,CAAA;AAEvE,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,WAAW,CAA2B;gBAElC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,EAAE,CAAC,sBAAsB;IAK3E,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,SAAS,IAAI,SAAS,CAgBzB;IAID,IAAI,OAAO,IAAI,kBAAkB,CAWhC;IAED,MAAM;;;IAMN,WAAW,IAAI,MAAM,EAAE;CAGxB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { UnknownDaggerError } from "../../../common/errors/UnknownDaggerError.js";
|
|
2
|
+
import { Argument } from "./argument.js";
|
|
3
|
+
export class Constructor {
|
|
4
|
+
checker;
|
|
5
|
+
declaration;
|
|
6
|
+
constructor(checker, declaration) {
|
|
7
|
+
this.checker = checker;
|
|
8
|
+
this.declaration = declaration;
|
|
9
|
+
}
|
|
10
|
+
get name() {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
get arguments() {
|
|
14
|
+
return this.declaration.parameters.reduce((acc, param) => {
|
|
15
|
+
const symbol = this.checker.getSymbolAtLocation(param.name);
|
|
16
|
+
if (!symbol) {
|
|
17
|
+
throw new UnknownDaggerError(`could not get constructor param: ${param.name.getText()}`, {});
|
|
18
|
+
}
|
|
19
|
+
const argument = new Argument(this.checker, symbol);
|
|
20
|
+
acc[argument.name] = argument;
|
|
21
|
+
return acc;
|
|
22
|
+
}, {});
|
|
23
|
+
}
|
|
24
|
+
// TODO(TomChv): replace with `ToJson` method
|
|
25
|
+
// after the refactor is complete.
|
|
26
|
+
get typeDef() {
|
|
27
|
+
return {
|
|
28
|
+
args: Object.entries(this.arguments).reduce((acc, [name, arg]) => {
|
|
29
|
+
acc[name] = arg.typeDef;
|
|
30
|
+
return acc;
|
|
31
|
+
}, {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
toJSON() {
|
|
35
|
+
return {
|
|
36
|
+
args: this.arguments,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
getArgOrder() {
|
|
40
|
+
return Object.keys(this.arguments);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -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"}
|