@dagger.io/dagger 0.10.1 → 0.10.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.
Files changed (56) hide show
  1. package/dist/api/client.gen.d.ts +80 -5
  2. package/dist/api/client.gen.d.ts.map +1 -1
  3. package/dist/api/client.gen.js +168 -5
  4. package/dist/api/utils.d.ts.map +1 -1
  5. package/dist/api/utils.js +6 -2
  6. package/dist/common/errors/ExecError.d.ts.map +1 -1
  7. package/dist/entrypoint/context.d.ts +8 -0
  8. package/dist/entrypoint/context.d.ts.map +1 -0
  9. package/dist/entrypoint/invoke.d.ts +3 -9
  10. package/dist/entrypoint/invoke.d.ts.map +1 -1
  11. package/dist/entrypoint/invoke.js +17 -28
  12. package/dist/entrypoint/load.d.ts +29 -69
  13. package/dist/entrypoint/load.d.ts.map +1 -1
  14. package/dist/entrypoint/load.js +93 -173
  15. package/dist/entrypoint/register.d.ts +2 -2
  16. package/dist/entrypoint/register.d.ts.map +1 -1
  17. package/dist/entrypoint/register.js +12 -12
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/introspector/scanner/abtractions/argument.d.ts +75 -0
  21. package/dist/introspector/scanner/abtractions/argument.d.ts.map +1 -0
  22. package/dist/introspector/scanner/abtractions/argument.js +137 -0
  23. package/dist/introspector/scanner/abtractions/constructor.d.ts +16 -0
  24. package/dist/introspector/scanner/abtractions/constructor.d.ts.map +1 -0
  25. package/dist/introspector/scanner/abtractions/constructor.js +42 -0
  26. package/dist/introspector/scanner/abtractions/method.d.ts +51 -0
  27. package/dist/introspector/scanner/abtractions/method.d.ts.map +1 -0
  28. package/dist/introspector/scanner/abtractions/method.js +105 -0
  29. package/dist/introspector/scanner/abtractions/module.d.ts +18 -0
  30. package/dist/introspector/scanner/abtractions/module.d.ts.map +1 -0
  31. package/dist/introspector/scanner/abtractions/module.js +59 -0
  32. package/dist/introspector/scanner/abtractions/object.d.ts +37 -0
  33. package/dist/introspector/scanner/abtractions/object.d.ts.map +1 -0
  34. package/dist/introspector/scanner/abtractions/object.js +94 -0
  35. package/dist/introspector/scanner/abtractions/property.d.ts +46 -0
  36. package/dist/introspector/scanner/abtractions/property.d.ts.map +1 -0
  37. package/dist/introspector/scanner/abtractions/property.js +93 -0
  38. package/dist/introspector/scanner/scan.d.ts +2 -1
  39. package/dist/introspector/scanner/scan.d.ts.map +1 -1
  40. package/dist/introspector/scanner/scan.js +2 -181
  41. package/dist/introspector/scanner/serialize.d.ts +0 -24
  42. package/dist/introspector/scanner/serialize.d.ts.map +1 -1
  43. package/dist/introspector/scanner/serialize.js +0 -53
  44. package/dist/introspector/scanner/typeDefs.d.ts +3 -3
  45. package/dist/introspector/scanner/typeDefs.d.ts.map +1 -1
  46. package/dist/introspector/scanner/utils.d.ts +1 -57
  47. package/dist/introspector/scanner/utils.d.ts.map +1 -1
  48. package/dist/introspector/scanner/utils.js +16 -149
  49. package/dist/provisioning/bin.d.ts.map +1 -1
  50. package/dist/provisioning/bin.js +10 -4
  51. package/dist/provisioning/default.d.ts +1 -1
  52. package/dist/provisioning/default.js +1 -1
  53. package/package.json +5 -2
  54. package/dist/introspector/scanner/metadata.d.ts +0 -24
  55. package/dist/introspector/scanner/metadata.d.ts.map +0 -1
  56. /package/dist/{introspector/scanner/metadata.js → entrypoint/context.js} +0 -0
package/dist/index.d.ts CHANGED
@@ -2,8 +2,9 @@ export * from "./api/client.gen.js";
2
2
  export * from "./common/errors/index.js";
3
3
  export { gql } from "graphql-tag";
4
4
  export { GraphQLClient } from "graphql-request";
5
- export { connect, CallbackFct, connection, close } from "./connect.js";
6
- export { ConnectOpts } from "./connectOpts.js";
5
+ export type { CallbackFct } from "./connect.js";
6
+ export { connect, connection, close } from "./connect.js";
7
+ export type { ConnectOpts } from "./connectOpts.js";
7
8
  export * from "./introspector/decorators/decorators.js";
8
9
  export { entrypoint } from "./entrypoint/entrypoint.js";
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,cAAc,yCAAyC,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACzD,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,cAAc,yCAAyC,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA"}
@@ -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"}
@@ -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
+ }