@dagger.io/dagger 0.13.2 → 0.13.4

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 (154) hide show
  1. package/dist/api/client.gen.d.ts +3846 -0
  2. package/dist/api/client.gen.d.ts.map +1 -0
  3. package/dist/api/client.gen.js +7207 -0
  4. package/dist/api/utils.d.ts +28 -0
  5. package/dist/api/utils.d.ts.map +1 -0
  6. package/dist/api/utils.js +170 -0
  7. package/dist/common/errors/DaggerSDKError.d.ts +32 -0
  8. package/dist/common/errors/DaggerSDKError.d.ts.map +1 -0
  9. package/dist/common/errors/DaggerSDKError.js +26 -0
  10. package/dist/common/errors/DockerImageRefValidationError.d.ts +22 -0
  11. package/dist/common/errors/DockerImageRefValidationError.d.ts.map +1 -0
  12. package/dist/common/errors/DockerImageRefValidationError.js +21 -0
  13. package/dist/common/errors/EngineSessionConnectParamsParseError.d.ts +21 -0
  14. package/dist/common/errors/EngineSessionConnectParamsParseError.d.ts.map +1 -0
  15. package/dist/common/errors/EngineSessionConnectParamsParseError.js +20 -0
  16. package/dist/common/errors/EngineSessionConnectionTimeoutError.d.ts +21 -0
  17. package/dist/common/errors/EngineSessionConnectionTimeoutError.d.ts.map +1 -0
  18. package/dist/common/errors/EngineSessionConnectionTimeoutError.js +20 -0
  19. package/dist/common/errors/EngineSessionErrorOptions.d.ts +16 -0
  20. package/dist/common/errors/EngineSessionErrorOptions.d.ts.map +1 -0
  21. package/dist/common/errors/EngineSessionErrorOptions.js +16 -0
  22. package/dist/common/errors/ExecError.d.ts +37 -0
  23. package/dist/common/errors/ExecError.d.ts.map +1 -0
  24. package/dist/common/errors/ExecError.js +38 -0
  25. package/dist/common/errors/GraphQLRequestError.d.ts +26 -0
  26. package/dist/common/errors/GraphQLRequestError.d.ts.map +1 -0
  27. package/dist/common/errors/GraphQLRequestError.js +25 -0
  28. package/dist/common/errors/InitEngineSessionBinaryError.d.ts +13 -0
  29. package/dist/common/errors/InitEngineSessionBinaryError.d.ts.map +1 -0
  30. package/dist/common/errors/InitEngineSessionBinaryError.js +15 -0
  31. package/dist/common/errors/NotAwaitedRequestError.d.ts +13 -0
  32. package/dist/common/errors/NotAwaitedRequestError.d.ts.map +1 -0
  33. package/dist/common/errors/NotAwaitedRequestError.js +15 -0
  34. package/dist/common/errors/TooManyNestedObjectsError.d.ts +21 -0
  35. package/dist/common/errors/TooManyNestedObjectsError.d.ts.map +1 -0
  36. package/dist/common/errors/TooManyNestedObjectsError.js +20 -0
  37. package/dist/common/errors/UnknownDaggerError.d.ts +13 -0
  38. package/dist/common/errors/UnknownDaggerError.d.ts.map +1 -0
  39. package/dist/common/errors/UnknownDaggerError.js +15 -0
  40. package/dist/common/errors/errors-codes.d.ts +51 -0
  41. package/dist/common/errors/errors-codes.d.ts.map +1 -0
  42. package/dist/common/errors/errors-codes.js +43 -0
  43. package/dist/common/errors/index.d.ts +13 -0
  44. package/dist/common/errors/index.d.ts.map +1 -0
  45. package/dist/common/errors/index.js +12 -0
  46. package/dist/common/utils.d.ts +68 -0
  47. package/dist/common/utils.d.ts.map +1 -0
  48. package/dist/common/utils.js +2 -0
  49. package/dist/connect.d.ts +32 -0
  50. package/dist/connect.d.ts.map +1 -0
  51. package/dist/connect.js +66 -0
  52. package/dist/connectOpts.d.ts +24 -0
  53. package/dist/connectOpts.d.ts.map +1 -0
  54. package/dist/connectOpts.js +1 -0
  55. package/dist/context/builder.d.ts +9 -0
  56. package/dist/context/builder.d.ts.map +1 -0
  57. package/dist/context/builder.js +34 -0
  58. package/dist/context/context.d.ts +40 -0
  59. package/dist/context/context.d.ts.map +1 -0
  60. package/dist/context/context.js +53 -0
  61. package/dist/entrypoint/context.d.ts +8 -0
  62. package/dist/entrypoint/context.d.ts.map +1 -0
  63. package/dist/entrypoint/context.js +1 -0
  64. package/dist/entrypoint/entrypoint.d.ts +2 -0
  65. package/dist/entrypoint/entrypoint.d.ts.map +1 -0
  66. package/dist/entrypoint/entrypoint.js +71 -0
  67. package/dist/entrypoint/invoke.d.ts +13 -0
  68. package/dist/entrypoint/invoke.d.ts.map +1 -0
  69. package/dist/entrypoint/invoke.js +40 -0
  70. package/dist/entrypoint/load.d.ts +56 -0
  71. package/dist/entrypoint/load.d.ts.map +1 -0
  72. package/dist/entrypoint/load.js +198 -0
  73. package/dist/entrypoint/register.d.ts +7 -0
  74. package/dist/entrypoint/register.d.ts.map +1 -0
  75. package/dist/entrypoint/register.js +139 -0
  76. package/dist/graphql/client.d.ts +3 -0
  77. package/dist/graphql/client.d.ts.map +1 -0
  78. package/dist/graphql/client.js +48 -0
  79. package/dist/index.d.ts +10 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +7 -0
  82. package/dist/introspector/decorators/decorators.d.ts +44 -0
  83. package/dist/introspector/decorators/decorators.d.ts.map +1 -0
  84. package/dist/introspector/decorators/decorators.js +47 -0
  85. package/dist/introspector/registry/registry.d.ts +89 -0
  86. package/dist/introspector/registry/registry.d.ts.map +1 -0
  87. package/dist/introspector/registry/registry.js +115 -0
  88. package/dist/introspector/scanner/abtractions/argument.d.ts +104 -0
  89. package/dist/introspector/scanner/abtractions/argument.d.ts.map +1 -0
  90. package/dist/introspector/scanner/abtractions/argument.js +207 -0
  91. package/dist/introspector/scanner/abtractions/constructor.d.ts +17 -0
  92. package/dist/introspector/scanner/abtractions/constructor.d.ts.map +1 -0
  93. package/dist/introspector/scanner/abtractions/constructor.js +40 -0
  94. package/dist/introspector/scanner/abtractions/enum.d.ts +33 -0
  95. package/dist/introspector/scanner/abtractions/enum.d.ts.map +1 -0
  96. package/dist/introspector/scanner/abtractions/enum.js +73 -0
  97. package/dist/introspector/scanner/abtractions/enumValue.d.ts +24 -0
  98. package/dist/introspector/scanner/abtractions/enumValue.d.ts.map +1 -0
  99. package/dist/introspector/scanner/abtractions/enumValue.js +51 -0
  100. package/dist/introspector/scanner/abtractions/method.d.ts +67 -0
  101. package/dist/introspector/scanner/abtractions/method.d.ts.map +1 -0
  102. package/dist/introspector/scanner/abtractions/method.js +132 -0
  103. package/dist/introspector/scanner/abtractions/module.d.ts +26 -0
  104. package/dist/introspector/scanner/abtractions/module.d.ts.map +1 -0
  105. package/dist/introspector/scanner/abtractions/module.js +103 -0
  106. package/dist/introspector/scanner/abtractions/object.d.ts +52 -0
  107. package/dist/introspector/scanner/abtractions/object.d.ts.map +1 -0
  108. package/dist/introspector/scanner/abtractions/object.js +118 -0
  109. package/dist/introspector/scanner/abtractions/property.d.ts +55 -0
  110. package/dist/introspector/scanner/abtractions/property.d.ts.map +1 -0
  111. package/dist/introspector/scanner/abtractions/property.js +110 -0
  112. package/dist/introspector/scanner/abtractions/typeToTypedef.d.ts +8 -0
  113. package/dist/introspector/scanner/abtractions/typeToTypedef.d.ts.map +1 -0
  114. package/dist/introspector/scanner/abtractions/typeToTypedef.js +85 -0
  115. package/dist/introspector/scanner/scan.d.ts +14 -0
  116. package/dist/introspector/scanner/scan.d.ts.map +1 -0
  117. package/dist/introspector/scanner/scan.js +26 -0
  118. package/dist/introspector/scanner/typeDefs.d.ts +45 -0
  119. package/dist/introspector/scanner/typeDefs.d.ts.map +1 -0
  120. package/dist/introspector/scanner/typeDefs.js +1 -0
  121. package/dist/introspector/scanner/utils.d.ts +22 -0
  122. package/dist/introspector/scanner/utils.d.ts.map +1 -0
  123. package/dist/introspector/scanner/utils.js +101 -0
  124. package/dist/introspector/utils/files.d.ts +5 -0
  125. package/dist/introspector/utils/files.d.ts.map +1 -0
  126. package/dist/introspector/utils/files.js +28 -0
  127. package/dist/provisioning/bin.d.ts +77 -0
  128. package/dist/provisioning/bin.d.ts.map +1 -0
  129. package/dist/provisioning/bin.js +353 -0
  130. package/dist/provisioning/default.d.ts +2 -0
  131. package/dist/provisioning/default.d.ts.map +1 -0
  132. package/dist/provisioning/default.js +2 -0
  133. package/dist/provisioning/engineconn.d.ts +28 -0
  134. package/dist/provisioning/engineconn.d.ts.map +1 -0
  135. package/dist/provisioning/engineconn.js +1 -0
  136. package/dist/provisioning/index.d.ts +4 -0
  137. package/dist/provisioning/index.d.ts.map +1 -0
  138. package/dist/provisioning/index.js +3 -0
  139. package/dist/telemetry/attributes.d.ts +2 -0
  140. package/dist/telemetry/attributes.d.ts.map +1 -0
  141. package/dist/telemetry/attributes.js +1 -0
  142. package/dist/telemetry/index.d.ts +3 -0
  143. package/dist/telemetry/index.d.ts.map +1 -0
  144. package/dist/telemetry/index.js +2 -0
  145. package/dist/telemetry/init.d.ts +21 -0
  146. package/dist/telemetry/init.d.ts.map +1 -0
  147. package/dist/telemetry/init.js +66 -0
  148. package/dist/telemetry/telemetry.d.ts +16 -0
  149. package/dist/telemetry/telemetry.d.ts.map +1 -0
  150. package/dist/telemetry/telemetry.js +38 -0
  151. package/dist/telemetry/tracer.d.ts +32 -0
  152. package/dist/telemetry/tracer.d.ts.map +1 -0
  153. package/dist/telemetry/tracer.js +54 -0
  154. package/package.json +2 -2
@@ -0,0 +1,73 @@
1
+ import ts from "typescript";
2
+ import { UnknownDaggerError } from "../../../common/errors/UnknownDaggerError.js";
3
+ import { enumType } from "../../decorators/decorators.js";
4
+ import { DaggerEnumValue } from "./enumValue.js";
5
+ export const ENUM_DECORATOR = enumType.name;
6
+ /**
7
+ * Return true if the given class declaration has the decorator @enum() on
8
+ * top of its declaration.
9
+ */
10
+ export function isEnumDecorated(object) {
11
+ return (ts.getDecorators(object)?.find((d) => {
12
+ if (ts.isCallExpression(d.expression)) {
13
+ return d.expression.expression.getText() === ENUM_DECORATOR;
14
+ }
15
+ return false;
16
+ }) !== undefined);
17
+ }
18
+ export class DaggerEnum {
19
+ checker;
20
+ enumClass;
21
+ symbol;
22
+ file;
23
+ _name;
24
+ _description;
25
+ _values;
26
+ constructor(checker, file, enumClassDeclaration) {
27
+ this.checker = checker;
28
+ this.enumClass = enumClassDeclaration;
29
+ this.file = file;
30
+ if (!enumClassDeclaration.name) {
31
+ throw new UnknownDaggerError(`could not introspect enum class: ${enumClassDeclaration}`, {});
32
+ }
33
+ const enumClassSymbol = checker.getSymbolAtLocation(enumClassDeclaration.name);
34
+ if (!enumClassSymbol) {
35
+ throw new UnknownDaggerError(`could not get enum class symbol: ${enumClassDeclaration.name.getText()}`, {});
36
+ }
37
+ this.symbol = enumClassSymbol;
38
+ // Preload definition to optimize the introspection.
39
+ this._name = this.loadName();
40
+ this._description = this.loadDescription();
41
+ this._values = this.loadEnumValues();
42
+ }
43
+ get name() {
44
+ return this._name;
45
+ }
46
+ get description() {
47
+ return this._description;
48
+ }
49
+ get values() {
50
+ return this._values;
51
+ }
52
+ toJSON() {
53
+ return {
54
+ name: this.name,
55
+ description: this.description,
56
+ values: this._values,
57
+ };
58
+ }
59
+ loadName() {
60
+ return this.symbol.getName();
61
+ }
62
+ loadDescription() {
63
+ return ts.displayPartsToString(this.symbol.getDocumentationComment(this.checker));
64
+ }
65
+ loadEnumValues() {
66
+ return this.enumClass.members
67
+ .filter((member) => ts.isPropertyDeclaration(member))
68
+ .reduce((acc, member) => {
69
+ const value = new DaggerEnumValue(this.checker, member);
70
+ return { ...acc, [value.name]: value };
71
+ }, {});
72
+ }
73
+ }
@@ -0,0 +1,24 @@
1
+ import ts from "typescript";
2
+ export type DaggerEnumValues = {
3
+ [name: string]: DaggerEnumValue;
4
+ };
5
+ export declare class DaggerEnumValue {
6
+ private checker;
7
+ private property;
8
+ private symbol;
9
+ private _name;
10
+ private _value;
11
+ private _description;
12
+ constructor(checker: ts.TypeChecker, property: ts.PropertyDeclaration);
13
+ get name(): string;
14
+ get value(): string;
15
+ get description(): string;
16
+ toJSON(): {
17
+ name: string;
18
+ description: string;
19
+ };
20
+ private loadName;
21
+ private loadValue;
22
+ private loadDescription;
23
+ }
24
+ //# sourceMappingURL=enumValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enumValue.d.ts","sourceRoot":"","sources":["../../../../introspector/scanner/abtractions/enumValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAI3B,MAAM,MAAM,gBAAgB,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;CAAE,CAAA;AAElE,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,QAAQ,CAAwB;IAExC,OAAO,CAAC,MAAM,CAAW;IAEzB,OAAO,CAAC,KAAK,CAAQ;IAErB,OAAO,CAAC,MAAM,CAAQ;IAEtB,OAAO,CAAC,YAAY,CAAQ;gBAEhB,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,CAAC,mBAAmB;IAkBrE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,MAAM;;;;IAON,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,eAAe;CAKxB"}
@@ -0,0 +1,51 @@
1
+ import ts from "typescript";
2
+ import { UnknownDaggerError } from "../../../common/errors/UnknownDaggerError.js";
3
+ export class DaggerEnumValue {
4
+ checker;
5
+ property;
6
+ symbol;
7
+ _name;
8
+ _value;
9
+ _description;
10
+ constructor(checker, property) {
11
+ this.checker = checker;
12
+ this.property = property;
13
+ const propertySymbol = checker.getSymbolAtLocation(property.name);
14
+ if (!propertySymbol) {
15
+ throw new UnknownDaggerError(`could not get property symbol: ${property.name.getText()}`, {});
16
+ }
17
+ this.symbol = propertySymbol;
18
+ this._name = this.loadName();
19
+ this._value = this.loadValue();
20
+ this._description = this.loadDescription();
21
+ }
22
+ get name() {
23
+ return this._name;
24
+ }
25
+ get value() {
26
+ return this._value;
27
+ }
28
+ get description() {
29
+ return this._description;
30
+ }
31
+ toJSON() {
32
+ return {
33
+ name: this.value,
34
+ description: this.description,
35
+ };
36
+ }
37
+ loadName() {
38
+ return this.symbol.getName();
39
+ }
40
+ // Load the value of the enum value from the property initializer.
41
+ // If the initializer is not set, it will throw an error.
42
+ loadValue() {
43
+ if (!this.property.initializer) {
44
+ throw new Error("Dagger enum value has no value set");
45
+ }
46
+ return JSON.parse(this.property.initializer.getText());
47
+ }
48
+ loadDescription() {
49
+ return ts.displayPartsToString(this.symbol.getDocumentationComment(this.checker));
50
+ }
51
+ }
@@ -0,0 +1,67 @@
1
+ import ts from "typescript";
2
+ import { TypeDefKind } from "../../../api/client.gen.js";
3
+ import { TypeDef } from "../typeDefs.js";
4
+ import { Arguments } from "./argument.js";
5
+ export declare const METHOD_DECORATOR: string;
6
+ /**
7
+ * Return true if the given method has the decorator @fct() on top
8
+ * of its declaration.
9
+ *
10
+ * @param method The method to check
11
+ */
12
+ export declare function isMethodDecorated(method: ts.MethodDeclaration): boolean;
13
+ export type Methods = {
14
+ [name: string]: Method;
15
+ };
16
+ /**
17
+ * Method is an abstraction of a function or method.
18
+ *
19
+ * This aims to simplify and adds clarity to how we analyse the code and using
20
+ * clear accessor.
21
+ */
22
+ export declare class Method {
23
+ private checker;
24
+ private symbol;
25
+ private signature;
26
+ private decorator;
27
+ private _name;
28
+ private _description;
29
+ private _alias;
30
+ private _arguments;
31
+ private _returnType;
32
+ /**
33
+ * Create a new Method instance.
34
+ *
35
+ * @param checker Checker to use to introspect the method.
36
+ * @param method The method to introspect.
37
+ *
38
+ * @throws UnknownDaggerError If the method doesn't have any symbol.
39
+ * @throws UnknownDaggerError If the method doesn't have any signature.
40
+ */
41
+ constructor(checker: ts.TypeChecker, method: ts.MethodDeclaration);
42
+ get name(): string;
43
+ get description(): string;
44
+ /**
45
+ * Return the alias of the method if it has one.
46
+ */
47
+ get alias(): string | undefined;
48
+ get arguments(): Arguments;
49
+ /**
50
+ * Return the type of the return value in a Dagger TypeDef format.
51
+ */
52
+ get returnType(): TypeDef<TypeDefKind>;
53
+ toJSON(): {
54
+ name: string;
55
+ description: string;
56
+ alias: string | undefined;
57
+ arguments: Arguments;
58
+ returnType: TypeDef<TypeDefKind>;
59
+ };
60
+ getArgOrder(): string[];
61
+ private loadName;
62
+ private loadDescription;
63
+ private loadAlias;
64
+ private loadArguments;
65
+ private loadReturnType;
66
+ }
67
+ //# 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;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAGxD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAY,SAAS,EAAE,MAAM,eAAe,CAAA;AAGnD,eAAO,MAAM,gBAAgB,QAAY,CAAA;AAEzC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,GAAG,OAAO,CAUvE;AAED,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,CAAW;IAEzB,OAAO,CAAC,SAAS,CAAc;IAE/B,OAAO,CAAC,SAAS,CAA0B;IAG3C,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,UAAU,CAAW;IAC7B,OAAO,CAAC,WAAW,CAAsB;IAEzC;;;;;;;;OAQG;gBACS,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC,iBAAiB;IAuCjE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAED,IAAI,SAAS,IAAI,SAAS,CAEzB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC,CAErC;IAED,MAAM;;;;;;;IAUN,WAAW,IAAI,MAAM,EAAE;IAIvB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,cAAc;CAGvB"}
@@ -0,0 +1,132 @@
1
+ import ts from "typescript";
2
+ import { UnknownDaggerError } from "../../../common/errors/UnknownDaggerError.js";
3
+ import { func } from "../../decorators/decorators.js";
4
+ import { Argument } from "./argument.js";
5
+ import { typeToTypedef } from "./typeToTypedef.js";
6
+ export const METHOD_DECORATOR = func.name;
7
+ /**
8
+ * Return true if the given method has the decorator @fct() on top
9
+ * of its declaration.
10
+ *
11
+ * @param method The method to check
12
+ */
13
+ export function isMethodDecorated(method) {
14
+ return (ts.getDecorators(method)?.find((d) => {
15
+ if (ts.isCallExpression(d.expression)) {
16
+ return d.expression.expression.getText() === METHOD_DECORATOR;
17
+ }
18
+ return false;
19
+ }) !== undefined);
20
+ }
21
+ /**
22
+ * Method is an abstraction of a function or method.
23
+ *
24
+ * This aims to simplify and adds clarity to how we analyse the code and using
25
+ * clear accessor.
26
+ */
27
+ export class Method {
28
+ checker;
29
+ symbol;
30
+ signature;
31
+ decorator;
32
+ // Preloaded values.
33
+ _name;
34
+ _description;
35
+ _alias;
36
+ _arguments;
37
+ _returnType;
38
+ /**
39
+ * Create a new Method instance.
40
+ *
41
+ * @param checker Checker to use to introspect the method.
42
+ * @param method The method to introspect.
43
+ *
44
+ * @throws UnknownDaggerError If the method doesn't have any symbol.
45
+ * @throws UnknownDaggerError If the method doesn't have any signature.
46
+ */
47
+ constructor(checker, method) {
48
+ this.checker = checker;
49
+ const methodSymbol = checker.getSymbolAtLocation(method.name);
50
+ if (!methodSymbol) {
51
+ throw new UnknownDaggerError(`could not get method symbol: ${method.name.getText()}`, {});
52
+ }
53
+ this.symbol = methodSymbol;
54
+ const signature = checker.getSignatureFromDeclaration(method);
55
+ if (!signature) {
56
+ throw new UnknownDaggerError(`could not get method signature: ${method.name.getText()}`, {});
57
+ }
58
+ this.signature = signature;
59
+ this.decorator = ts.getDecorators(method)?.find((d) => {
60
+ if (ts.isCallExpression(d.expression)) {
61
+ return d.expression.expression.getText() === METHOD_DECORATOR;
62
+ }
63
+ return false;
64
+ });
65
+ // Preload to optimize the introspection.
66
+ this._name = this.loadName();
67
+ this._description = this.loadDescription();
68
+ this._alias = this.loadAlias();
69
+ this._arguments = this.loadArguments();
70
+ this._returnType = this.loadReturnType();
71
+ }
72
+ get name() {
73
+ return this._name;
74
+ }
75
+ get description() {
76
+ return this._description;
77
+ }
78
+ /**
79
+ * Return the alias of the method if it has one.
80
+ */
81
+ get alias() {
82
+ return this._alias;
83
+ }
84
+ get arguments() {
85
+ return this._arguments;
86
+ }
87
+ /**
88
+ * Return the type of the return value in a Dagger TypeDef format.
89
+ */
90
+ get returnType() {
91
+ return this._returnType;
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
+ loadName() {
106
+ return this.symbol.getName();
107
+ }
108
+ loadDescription() {
109
+ return ts.displayPartsToString(this.symbol.getDocumentationComment(this.checker));
110
+ }
111
+ loadAlias() {
112
+ if (!this.decorator) {
113
+ return undefined;
114
+ }
115
+ const expression = this.decorator.expression;
116
+ const aliasArg = expression.arguments[0];
117
+ if (!aliasArg) {
118
+ return undefined;
119
+ }
120
+ return JSON.parse(aliasArg.getText().replace(/'/g, '"'));
121
+ }
122
+ loadArguments() {
123
+ return this.signature.parameters.reduce((acc, param) => {
124
+ const argument = new Argument(this.checker, param);
125
+ acc[argument.name] = argument;
126
+ return acc;
127
+ }, {});
128
+ }
129
+ loadReturnType() {
130
+ return typeToTypedef(this.checker, this.signature.getReturnType());
131
+ }
132
+ }
@@ -0,0 +1,26 @@
1
+ import ts from "typescript";
2
+ import { DaggerEnums } from "./enum.js";
3
+ import { DaggerObjects } from "./object.js";
4
+ export declare class DaggerModule {
5
+ private checker;
6
+ private readonly files;
7
+ name: string;
8
+ private _description;
9
+ private _objects;
10
+ private _enums;
11
+ constructor(checker: ts.TypeChecker, name: string | undefined, files: readonly ts.SourceFile[]);
12
+ get objects(): DaggerObjects;
13
+ get enums(): DaggerEnums;
14
+ get description(): string | undefined;
15
+ toJSON(): {
16
+ name: string;
17
+ description: string | undefined;
18
+ objects: DaggerObjects;
19
+ enums: DaggerEnums;
20
+ };
21
+ private loadObjects;
22
+ private loadEnums;
23
+ private loadDescription;
24
+ private toPascalCase;
25
+ }
26
+ //# 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,EAAc,WAAW,EAAmB,MAAM,WAAW,CAAA;AACpE,OAAO,EAAgB,aAAa,EAAqB,MAAM,aAAa,CAAA;AAE5E,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiB;IAEhC,IAAI,EAAE,MAAM,CAAA;IAGnB,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,MAAM,CAAa;gBAGzB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,oBAAK,EACT,KAAK,EAAE,SAAS,EAAE,CAAC,UAAU,EAAE;IAYjC,IAAI,OAAO,IAAI,aAAa,CAE3B;IAED,IAAI,KAAK,IAAI,WAAW,CAEvB;IAED,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED,MAAM;;;;;;IASN,OAAO,CAAC,WAAW;IAgBnB,OAAO,CAAC,SAAS;IAgBjB,OAAO,CAAC,eAAe;IAkCvB,OAAO,CAAC,YAAY;CAqBrB"}
@@ -0,0 +1,103 @@
1
+ import ts from "typescript";
2
+ import { DaggerEnum, isEnumDecorated } from "./enum.js";
3
+ import { DaggerObject, isObjectDecorated } from "./object.js";
4
+ export class DaggerModule {
5
+ checker;
6
+ files;
7
+ name;
8
+ // Preloaded values.
9
+ _description;
10
+ _objects;
11
+ _enums;
12
+ constructor(checker, name = "", files) {
13
+ this.checker = checker;
14
+ this.files = files.filter((file) => !file.isDeclarationFile);
15
+ this.name = this.toPascalCase(name);
16
+ // Preload values to optimize introspection.
17
+ this._objects = this.loadObjects();
18
+ this._enums = this.loadEnums();
19
+ this._description = this.loadDescription();
20
+ }
21
+ get objects() {
22
+ return this._objects;
23
+ }
24
+ get enums() {
25
+ return this._enums;
26
+ }
27
+ get description() {
28
+ return this._description;
29
+ }
30
+ toJSON() {
31
+ return {
32
+ name: this.name,
33
+ description: this.description,
34
+ objects: this._objects,
35
+ enums: this._enums,
36
+ };
37
+ }
38
+ loadObjects() {
39
+ const objects = {};
40
+ for (const file of this.files) {
41
+ ts.forEachChild(file, (node) => {
42
+ if (ts.isClassDeclaration(node) && isObjectDecorated(node)) {
43
+ const object = new DaggerObject(this.checker, file, node);
44
+ objects[object.name] = object;
45
+ }
46
+ });
47
+ }
48
+ return objects;
49
+ }
50
+ loadEnums() {
51
+ const daggerEnums = {};
52
+ for (const file of this.files) {
53
+ ts.forEachChild(file, (node) => {
54
+ if (ts.isClassDeclaration(node) && isEnumDecorated(node)) {
55
+ const daggerEnum = new DaggerEnum(this.checker, file, node);
56
+ daggerEnums[daggerEnum.name] = daggerEnum;
57
+ }
58
+ });
59
+ }
60
+ return daggerEnums;
61
+ }
62
+ loadDescription() {
63
+ const mainObject = Object.values(this.objects).find((object) => object.name === this.name);
64
+ if (!mainObject) {
65
+ return undefined;
66
+ }
67
+ const file = mainObject.file;
68
+ const topLevelStatement = file.statements[0];
69
+ if (!topLevelStatement) {
70
+ return undefined;
71
+ }
72
+ // Get the range of the top level comment
73
+ const topLevelCommentRanges = ts.getLeadingCommentRanges(file.getFullText(), topLevelStatement.pos);
74
+ if (!topLevelCommentRanges || topLevelCommentRanges.length === 0) {
75
+ return undefined;
76
+ }
77
+ const topLevelCommentRange = topLevelCommentRanges[0];
78
+ return file
79
+ .getFullText()
80
+ .substring(topLevelCommentRange.pos, topLevelCommentRange.end)
81
+ .split("\n")
82
+ .slice(1, -1) // Remove start and ending comments characters `/** */`
83
+ .map((line) => line.replace("*", "").trim()) // Remove leading * and spaces
84
+ .join("\n");
85
+ }
86
+ toPascalCase(input) {
87
+ const words = input
88
+ .replace(/[^a-zA-Z0-9]/g, " ") // Replace non-alphanumeric characters with spaces
89
+ .split(/\s+/)
90
+ .filter((word) => word.length > 0);
91
+ if (words.length === 0) {
92
+ return ""; // No valid words found
93
+ }
94
+ // It's an edge case when moduleName is already in PascalCase or camelCase
95
+ if (words.length === 1) {
96
+ return words[0].charAt(0).toUpperCase() + words[0].slice(1);
97
+ }
98
+ const pascalCase = words
99
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
100
+ .join("");
101
+ return pascalCase;
102
+ }
103
+ }
@@ -0,0 +1,52 @@
1
+ import ts from "typescript";
2
+ import { Constructor } from "./constructor.js";
3
+ import { Methods } from "./method.js";
4
+ import { Properties } from "./property.js";
5
+ export declare const OBJECT_DECORATOR: string;
6
+ /**
7
+ * Return true if the given class declaration has the decorator @obj() on
8
+ * top of its declaration.
9
+ * @param object
10
+ */
11
+ export declare function isObjectDecorated(object: ts.ClassDeclaration): boolean;
12
+ export type DaggerObjects = {
13
+ [name: string]: DaggerObject;
14
+ };
15
+ export declare class DaggerObject {
16
+ private checker;
17
+ private class;
18
+ private symbol;
19
+ file: ts.SourceFile;
20
+ private _name;
21
+ private _description;
22
+ private _classConstructor;
23
+ private _methods;
24
+ private _properties;
25
+ /**
26
+ *
27
+ * @param checker The checker to use to introspect the class.
28
+ * @param classDeclaration The class to introspect.
29
+ *
30
+ * @throws UnknownDaggerError If the class doesn't have a name.
31
+ * @throws UnknownDaggerError If the class doesn't have a symbol.
32
+ */
33
+ constructor(checker: ts.TypeChecker, file: ts.SourceFile, classDeclaration: ts.ClassDeclaration);
34
+ get name(): string;
35
+ get description(): string;
36
+ get _constructor(): Constructor | undefined;
37
+ get methods(): Methods;
38
+ get properties(): Properties;
39
+ toJSON(): {
40
+ name: string;
41
+ description: string;
42
+ constructor: Constructor | undefined;
43
+ methods: Methods;
44
+ properties: Properties;
45
+ };
46
+ private loadName;
47
+ private loadDescription;
48
+ private loadConstructor;
49
+ private loadMethods;
50
+ private loadProperties;
51
+ }
52
+ //# 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;AAI3B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAU,OAAO,EAAqB,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,UAAU,EAAY,MAAM,eAAe,CAAA;AAEpD,eAAO,MAAM,gBAAgB,QAAc,CAAA;AAE3C;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,GAAG,OAAO,CAUtE;AAED,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;IAG1B,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,iBAAiB,CAAyB;IAClD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,WAAW,CAAY;IAE/B;;;;;;;OAOG;gBAED,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,EAAE,EAAE,CAAC,UAAU,EACnB,gBAAgB,EAAE,EAAE,CAAC,gBAAgB;IA+BvC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,YAAY,IAAI,WAAW,GAAG,SAAS,CAE1C;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,UAAU,IAAI,UAAU,CAE3B;IAED,MAAM;;;;;;;IAUN,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,WAAW;IAcnB,OAAO,CAAC,cAAc;CAavB"}
@@ -0,0 +1,118 @@
1
+ import ts from "typescript";
2
+ import { UnknownDaggerError } from "../../../common/errors/UnknownDaggerError.js";
3
+ import { object } from "../../decorators/decorators.js";
4
+ import { Constructor } from "./constructor.js";
5
+ import { Method, isMethodDecorated } from "./method.js";
6
+ import { Property } from "./property.js";
7
+ export const OBJECT_DECORATOR = object.name;
8
+ /**
9
+ * Return true if the given class declaration has the decorator @obj() on
10
+ * top of its declaration.
11
+ * @param object
12
+ */
13
+ export function isObjectDecorated(object) {
14
+ return (ts.getDecorators(object)?.find((d) => {
15
+ if (ts.isCallExpression(d.expression)) {
16
+ return d.expression.expression.getText() === OBJECT_DECORATOR;
17
+ }
18
+ return false;
19
+ }) !== undefined);
20
+ }
21
+ export class DaggerObject {
22
+ checker;
23
+ class;
24
+ symbol;
25
+ file;
26
+ // Preloaded values.
27
+ _name;
28
+ _description;
29
+ _classConstructor;
30
+ _methods;
31
+ _properties;
32
+ /**
33
+ *
34
+ * @param checker The checker to use to introspect the class.
35
+ * @param classDeclaration The class to introspect.
36
+ *
37
+ * @throws UnknownDaggerError If the class doesn't have a name.
38
+ * @throws UnknownDaggerError If the class doesn't have a symbol.
39
+ */
40
+ constructor(checker, file, classDeclaration) {
41
+ this.checker = checker;
42
+ this.class = classDeclaration;
43
+ this.file = file;
44
+ if (!classDeclaration.name) {
45
+ throw new UnknownDaggerError(`could not introspect class: ${classDeclaration}`, {});
46
+ }
47
+ const classSymbol = checker.getSymbolAtLocation(classDeclaration.name);
48
+ if (!classSymbol) {
49
+ throw new UnknownDaggerError(`could not get class symbol: ${classDeclaration.name.getText()}`, {});
50
+ }
51
+ this.symbol = classSymbol;
52
+ // Preload values to optimize introspection.
53
+ this._name = this.loadName();
54
+ this._description = this.loadDescription();
55
+ this._classConstructor = this.loadConstructor();
56
+ this._methods = this.loadMethods();
57
+ this._properties = this.loadProperties();
58
+ }
59
+ get name() {
60
+ return this._name;
61
+ }
62
+ get description() {
63
+ return this._description;
64
+ }
65
+ get _constructor() {
66
+ return this._classConstructor;
67
+ }
68
+ get methods() {
69
+ return this._methods;
70
+ }
71
+ get properties() {
72
+ return this._properties;
73
+ }
74
+ toJSON() {
75
+ return {
76
+ name: this.name,
77
+ description: this.description,
78
+ constructor: this._constructor,
79
+ methods: this.methods,
80
+ properties: this.properties,
81
+ };
82
+ }
83
+ loadName() {
84
+ return this.symbol.getName();
85
+ }
86
+ loadDescription() {
87
+ return ts.displayPartsToString(this.symbol.getDocumentationComment(this.checker));
88
+ }
89
+ loadConstructor() {
90
+ const constructor = this.class.members.find((member) => {
91
+ if (ts.isConstructorDeclaration(member)) {
92
+ return true;
93
+ }
94
+ });
95
+ if (!constructor) {
96
+ return undefined;
97
+ }
98
+ return new Constructor(this.checker, constructor);
99
+ }
100
+ loadMethods() {
101
+ return this.class.members
102
+ .filter((member) => ts.isMethodDeclaration(member) && isMethodDecorated(member))
103
+ .reduce((acc, member) => {
104
+ const method = new Method(this.checker, member);
105
+ acc[method.alias ?? method.name] = method;
106
+ return acc;
107
+ }, {});
108
+ }
109
+ loadProperties() {
110
+ return this.class.members
111
+ .filter((member) => ts.isPropertyDeclaration(member))
112
+ .reduce((acc, member) => {
113
+ const property = new Property(this.checker, member);
114
+ acc[property.alias ?? property.name] = property;
115
+ return acc;
116
+ }, {});
117
+ }
118
+ }