@dagger.io/dagger 0.13.3 → 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,55 @@
1
+ import ts from "typescript";
2
+ import { TypeDefKind } from "../../../api/client.gen.js";
3
+ import { TypeDef } from "../typeDefs.js";
4
+ export type Properties = {
5
+ [name: string]: Property;
6
+ };
7
+ /**
8
+ * Property is an abstraction of a class property.
9
+ *
10
+ * This aims to simplify and adds clarity to how we analyse the code and using
11
+ * clear accessor.
12
+ */
13
+ export declare class Property {
14
+ private symbol;
15
+ private checker;
16
+ private property;
17
+ private decorator;
18
+ private _name;
19
+ private _description;
20
+ private _alias;
21
+ private _type;
22
+ private _isExposed;
23
+ /**
24
+ *
25
+ * @param checker Checker to use to introspect the property.
26
+ * @param property The property to introspect.
27
+ *
28
+ * @throws UnknownDaggerError If the property doesn't have any symbol.
29
+ */
30
+ constructor(checker: ts.TypeChecker, property: ts.PropertyDeclaration);
31
+ get name(): string;
32
+ get description(): string;
33
+ /**
34
+ * Return the alias of the property if it has one.
35
+ */
36
+ get alias(): string | undefined;
37
+ /**
38
+ * Return the type of the property in a Dagger TypeDef format.
39
+ */
40
+ get type(): TypeDef<TypeDefKind>;
41
+ get isExposed(): boolean;
42
+ toJSON(): {
43
+ name: string;
44
+ description: string;
45
+ alias: string | undefined;
46
+ type: TypeDef<TypeDefKind>;
47
+ isExposed: boolean;
48
+ };
49
+ private loadName;
50
+ private loadDescription;
51
+ private loadAlias;
52
+ private loadType;
53
+ private loadIsExposed;
54
+ }
55
+ //# sourceMappingURL=property.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../introspector/scanner/abtractions/property.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAGxD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAMxC,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AAErD;;;;;GAKG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAW;IAEzB,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,QAAQ,CAAwB;IAExC,OAAO,CAAC,SAAS,CAA0B;IAG3C,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;;;OAMG;gBACS,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,CAAC,mBAAmB;IAiCrE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,CAE/B;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,MAAM;;;;;;;IAUN,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,QAAQ;IAgBhB,OAAO,CAAC,aAAa;CAGtB"}
@@ -0,0 +1,110 @@
1
+ import ts from "typescript";
2
+ import { UnknownDaggerError } from "../../../common/errors/UnknownDaggerError.js";
3
+ import { field, func } from "../../decorators/decorators.js";
4
+ import { typeToTypedef } from "./typeToTypedef.js";
5
+ const DEPRECATED_PROPERTY_DECORATOR = field.name;
6
+ const PROPERTY_DECORATOR = func.name;
7
+ /**
8
+ * Property is an abstraction of a class property.
9
+ *
10
+ * This aims to simplify and adds clarity to how we analyse the code and using
11
+ * clear accessor.
12
+ */
13
+ export class Property {
14
+ symbol;
15
+ checker;
16
+ property;
17
+ decorator;
18
+ // Preloaded values.
19
+ _name;
20
+ _description;
21
+ _alias;
22
+ _type;
23
+ _isExposed;
24
+ /**
25
+ *
26
+ * @param checker Checker to use to introspect the property.
27
+ * @param property The property to introspect.
28
+ *
29
+ * @throws UnknownDaggerError If the property doesn't have any symbol.
30
+ */
31
+ constructor(checker, property) {
32
+ this.checker = checker;
33
+ this.property = property;
34
+ const propertySymbol = checker.getSymbolAtLocation(property.name);
35
+ if (!propertySymbol) {
36
+ throw new UnknownDaggerError(`could not get property symbol: ${property.name.getText()}`, {});
37
+ }
38
+ this.symbol = propertySymbol;
39
+ this.decorator = ts.getDecorators(property)?.find((d) => {
40
+ if (ts.isCallExpression(d.expression)) {
41
+ return (d.expression.expression.getText() === PROPERTY_DECORATOR ||
42
+ d.expression.expression.getText() === DEPRECATED_PROPERTY_DECORATOR);
43
+ }
44
+ return false;
45
+ });
46
+ // Preload values to optimize introspection
47
+ this._name = this.loadName();
48
+ this._description = this.loadDescription();
49
+ this._alias = this.loadAlias();
50
+ this._type = this.loadType();
51
+ this._isExposed = this.loadIsExposed();
52
+ }
53
+ get name() {
54
+ return this._name;
55
+ }
56
+ get description() {
57
+ return this._description;
58
+ }
59
+ /**
60
+ * Return the alias of the property if it has one.
61
+ */
62
+ get alias() {
63
+ return this._alias;
64
+ }
65
+ /**
66
+ * Return the type of the property in a Dagger TypeDef format.
67
+ */
68
+ get type() {
69
+ return this._type;
70
+ }
71
+ get isExposed() {
72
+ return this._isExposed;
73
+ }
74
+ toJSON() {
75
+ return {
76
+ name: this.name,
77
+ description: this.description,
78
+ alias: this.alias,
79
+ type: this.type,
80
+ isExposed: this.isExposed,
81
+ };
82
+ }
83
+ loadName() {
84
+ return this.symbol.getName();
85
+ }
86
+ loadDescription() {
87
+ return ts.displayPartsToString(this.symbol.getDocumentationComment(this.checker));
88
+ }
89
+ loadAlias() {
90
+ if (!this.decorator) {
91
+ return undefined;
92
+ }
93
+ const expression = this.decorator.expression;
94
+ const aliasArg = expression.arguments[0];
95
+ if (!aliasArg) {
96
+ return undefined;
97
+ }
98
+ return JSON.parse(aliasArg.getText().replace(/'/g, '"'));
99
+ }
100
+ loadType() {
101
+ if (!this.symbol.valueDeclaration) {
102
+ throw new UnknownDaggerError("could not find symbol value declaration", {});
103
+ }
104
+ const type = this.checker.getTypeOfSymbolAtLocation(this.symbol, this.symbol.valueDeclaration);
105
+ return typeToTypedef(this.checker, type);
106
+ }
107
+ loadIsExposed() {
108
+ return this.decorator !== undefined;
109
+ }
110
+ }
@@ -0,0 +1,8 @@
1
+ import ts from "typescript";
2
+ import { TypeDefKind } from "../../../api/client.gen.js";
3
+ import { TypeDef } from "../typeDefs.js";
4
+ /**
5
+ * Convert a type into a Dagger Typedef using dynamic typing.
6
+ */
7
+ export declare function typeToTypedef(checker: ts.TypeChecker, type: ts.Type): TypeDef<TypeDefKind>;
8
+ //# sourceMappingURL=typeToTypedef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeToTypedef.d.ts","sourceRoot":"","sources":["../../../../introspector/scanner/abtractions/typeToTypedef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAGxC;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,EAAE,EAAE,CAAC,IAAI,GACZ,OAAO,CAAC,WAAW,CAAC,CAiGtB"}
@@ -0,0 +1,85 @@
1
+ import ts from "typescript";
2
+ import { TypeDefKind } from "../../../api/client.gen.js";
3
+ import { isEnumDecorated } from "./enum.js";
4
+ /**
5
+ * Convert a type into a Dagger Typedef using dynamic typing.
6
+ */
7
+ export function typeToTypedef(checker, type) {
8
+ const symbol = type.getSymbol();
9
+ const symbolName = symbol?.name;
10
+ const symbolDeclaration = symbol?.valueDeclaration;
11
+ if (symbolName === "Promise") {
12
+ const typeArgs = checker.getTypeArguments(type);
13
+ if (typeArgs.length > 0) {
14
+ return typeToTypedef(checker, typeArgs[0]);
15
+ }
16
+ }
17
+ if (symbolName === "Array") {
18
+ const typeArgs = checker.getTypeArguments(type);
19
+ if (typeArgs.length === 0) {
20
+ throw new Error("Generic array not supported");
21
+ }
22
+ return {
23
+ kind: TypeDefKind.ListKind,
24
+ typeDef: typeToTypedef(checker, typeArgs[0]),
25
+ };
26
+ }
27
+ const strType = checker.typeToString(type);
28
+ switch (strType) {
29
+ case "string":
30
+ return { kind: TypeDefKind.StringKind };
31
+ case "number":
32
+ return { kind: TypeDefKind.IntegerKind };
33
+ case "boolean":
34
+ return { kind: TypeDefKind.BooleanKind };
35
+ case "void":
36
+ return { kind: TypeDefKind.VoidKind };
37
+ // Intercept primitive types and throw error in this case
38
+ case "String":
39
+ throw new Error("Use of primitive String type detected, did you mean string?");
40
+ case "Number":
41
+ throw new Error("Use of primitive Number type detected, did you mean number?");
42
+ case "Boolean":
43
+ throw new Error("Use of primitive Boolean type detected, did you mean boolean?");
44
+ default:
45
+ if (symbolName &&
46
+ type.isClassOrInterface() &&
47
+ symbolDeclaration &&
48
+ ts.isClassDeclaration(symbolDeclaration)) {
49
+ if (isEnumDecorated(symbolDeclaration)) {
50
+ return {
51
+ kind: TypeDefKind.EnumKind,
52
+ name: symbolName,
53
+ };
54
+ }
55
+ return {
56
+ kind: TypeDefKind.ObjectKind,
57
+ name: symbolName,
58
+ };
59
+ }
60
+ if (symbol?.getFlags() !== undefined &&
61
+ (symbol.getFlags() & ts.SymbolFlags.Enum) !== 0) {
62
+ return {
63
+ kind: TypeDefKind.EnumKind,
64
+ name: strType,
65
+ };
66
+ }
67
+ // If it's a union, then it's a scalar type
68
+ if (type.isUnionOrIntersection()) {
69
+ return {
70
+ kind: TypeDefKind.ScalarKind,
71
+ name: strType,
72
+ };
73
+ }
74
+ // If we cannot resolve the symbol, we check for the alias symbol.
75
+ // This should mostly lead to a failure since external types are not supported by
76
+ // dagger yet.
77
+ if (type.aliasSymbol && type.aliasSymbol.flags & ts.TypeFlags.Object) {
78
+ return {
79
+ kind: TypeDefKind.ObjectKind,
80
+ name: type.aliasSymbol.escapedName.toString(),
81
+ };
82
+ }
83
+ throw new Error(`Unsupported type ${strType}`);
84
+ }
85
+ }
@@ -0,0 +1,14 @@
1
+ import { DaggerModule } from "./abtractions/module.js";
2
+ /**
3
+ * Scan the list of TypeScript File using the TypeScript compiler API.
4
+ *
5
+ * This function introspect files and returns metadata of their class and
6
+ * functions that should be exposed to the Dagger API.
7
+ *
8
+ * WARNING(28/11/23): This does NOT include arrow style function.
9
+ *
10
+ * @param files List of TypeScript files to introspect.
11
+ * @param moduleName The name of the module to introspect.
12
+ */
13
+ export declare function scan(files: string[], moduleName?: string): DaggerModule;
14
+ //# sourceMappingURL=scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/scan.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEtD;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,SAAK,GAAG,YAAY,CAenE"}
@@ -0,0 +1,26 @@
1
+ import ts from "typescript";
2
+ import { DaggerModule } from "./abtractions/module.js";
3
+ /**
4
+ * Scan the list of TypeScript File using the TypeScript compiler API.
5
+ *
6
+ * This function introspect files and returns metadata of their class and
7
+ * functions that should be exposed to the Dagger API.
8
+ *
9
+ * WARNING(28/11/23): This does NOT include arrow style function.
10
+ *
11
+ * @param files List of TypeScript files to introspect.
12
+ * @param moduleName The name of the module to introspect.
13
+ */
14
+ export function scan(files, moduleName = "") {
15
+ if (files.length === 0) {
16
+ throw new Error("no files to introspect found");
17
+ }
18
+ // Interpret the given typescript source files.
19
+ const program = ts.createProgram(files, { experimentalDecorators: true });
20
+ const checker = program.getTypeChecker();
21
+ const module = new DaggerModule(checker, moduleName, program.getSourceFiles());
22
+ if (Object.keys(module.objects).length === 0) {
23
+ throw new Error("no objects found in the module");
24
+ }
25
+ return module;
26
+ }
@@ -0,0 +1,45 @@
1
+ import { TypeDefKind } from "../../api/client.gen.js";
2
+ /**
3
+ * Base type of argument, field or return type.
4
+ */
5
+ export type BaseTypeDef = {
6
+ kind: TypeDefKind;
7
+ };
8
+ /**
9
+ * Extends the base type def if it's an object to add its name.
10
+ */
11
+ export type ObjectTypeDef = BaseTypeDef & {
12
+ kind: TypeDefKind.ObjectKind;
13
+ name: string;
14
+ };
15
+ /**
16
+ * Extends the base type def if it's an enum to add its name.
17
+ */
18
+ export type EnumTypeDef = BaseTypeDef & {
19
+ kind: TypeDefKind.EnumKind;
20
+ name: string;
21
+ };
22
+ /**
23
+ * Extends the base typedef if it's a scalar to add its name and real type.
24
+ */
25
+ export type ScalarTypeDef = BaseTypeDef & {
26
+ kind: TypeDefKind.ScalarKind;
27
+ name: string;
28
+ };
29
+ /**
30
+ * Extends the base if it's a list to add its subtype.
31
+ */
32
+ export type ListTypeDef = BaseTypeDef & {
33
+ kind: TypeDefKind.ListKind;
34
+ typeDef: TypeDef<TypeDefKind>;
35
+ };
36
+ /**
37
+ * A generic TypeDef that will dynamically add necessary properties
38
+ * depending on its type.
39
+ *
40
+ * If it's a type of kind scalar, it transforms the BaseTypeDef into a ScalarTypeDef.
41
+ * If it's type of kind object, it transforms the BaseTypeDef into an ObjectTypeDef.
42
+ * If it's a type of kind list, it transforms the BaseTypeDef into a ListTypeDef.
43
+ */
44
+ export type TypeDef<T extends BaseTypeDef["kind"]> = T extends TypeDefKind.ScalarKind ? ScalarTypeDef : T extends TypeDefKind.ObjectKind ? ObjectTypeDef : T extends TypeDefKind.ListKind ? ListTypeDef : T extends TypeDefKind.EnumKind ? EnumTypeDef : BaseTypeDef;
45
+ //# sourceMappingURL=typeDefs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeDefs.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/typeDefs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,WAAW,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACxC,IAAI,EAAE,WAAW,CAAC,UAAU,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACxC,IAAI,EAAE,WAAW,CAAC,UAAU,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;CAC9B,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,IAC/C,CAAC,SAAS,WAAW,CAAC,UAAU,GAC5B,aAAa,GACb,CAAC,SAAS,WAAW,CAAC,UAAU,GAC9B,aAAa,GACb,CAAC,SAAS,WAAW,CAAC,QAAQ,GAC5B,WAAW,GACX,CAAC,SAAS,WAAW,CAAC,QAAQ,GAC5B,WAAW,GACX,WAAW,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import ts from "typescript";
2
+ import { TypeDefKind } from "../../api/client.gen.js";
3
+ import { TypeDef } from "./typeDefs.js";
4
+ /**
5
+ * Return true if the given class declaration has the decorator @obj() on
6
+ * top of its declaration.
7
+ * @param object
8
+ */
9
+ export declare function isObject(object: ts.ClassDeclaration): boolean;
10
+ export declare function toPascalCase(input: string): string;
11
+ /**
12
+ * Return true if the given method has the decorator @func() on top
13
+ * of its declaration.
14
+ *
15
+ * @param method The method to check
16
+ */
17
+ export declare function isFunction(method: ts.MethodDeclaration): boolean;
18
+ /**
19
+ * Convert a type into a Dagger Typedef using dynamic typing.
20
+ */
21
+ export declare function typeToTypedef(checker: ts.TypeChecker, type: ts.Type): TypeDef<TypeDefKind>;
22
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,GAAG,OAAO,CAU7D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAoBlD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,GAAG,OAAO,CAUhE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,EAAE,EAAE,CAAC,IAAI,GACZ,OAAO,CAAC,WAAW,CAAC,CA8DtB"}
@@ -0,0 +1,101 @@
1
+ import ts from "typescript";
2
+ import { TypeDefKind } from "../../api/client.gen.js";
3
+ /**
4
+ * Return true if the given class declaration has the decorator @obj() on
5
+ * top of its declaration.
6
+ * @param object
7
+ */
8
+ export function isObject(object) {
9
+ return (ts.getDecorators(object)?.find((d) => {
10
+ if (ts.isCallExpression(d.expression)) {
11
+ return d.expression.expression.getText() === "object";
12
+ }
13
+ return false;
14
+ }) !== undefined);
15
+ }
16
+ export function toPascalCase(input) {
17
+ const words = input
18
+ .replace(/[^a-zA-Z0-9]/g, " ") // Replace non-alphanumeric characters with spaces
19
+ .split(/\s+/)
20
+ .filter((word) => word.length > 0);
21
+ if (words.length === 0) {
22
+ return ""; // No valid words found
23
+ }
24
+ // It's an edge case when moduleName is already in PascalCase or camelCase
25
+ if (words.length === 1) {
26
+ return words[0].charAt(0).toUpperCase() + words[0].slice(1);
27
+ }
28
+ const pascalCase = words
29
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
30
+ .join("");
31
+ return pascalCase;
32
+ }
33
+ /**
34
+ * Return true if the given method has the decorator @func() on top
35
+ * of its declaration.
36
+ *
37
+ * @param method The method to check
38
+ */
39
+ export function isFunction(method) {
40
+ return (ts.getDecorators(method)?.find((d) => {
41
+ if (ts.isCallExpression(d.expression)) {
42
+ return d.expression.expression.getText() === "func";
43
+ }
44
+ return false;
45
+ }) !== undefined);
46
+ }
47
+ /**
48
+ * Convert a type into a Dagger Typedef using dynamic typing.
49
+ */
50
+ export function typeToTypedef(checker, type) {
51
+ if (type.symbol?.name === "Promise") {
52
+ const typeArgs = checker.getTypeArguments(type);
53
+ if (typeArgs.length > 0) {
54
+ return typeToTypedef(checker, typeArgs[0]);
55
+ }
56
+ }
57
+ if (type.symbol?.name === "Array") {
58
+ const typeArgs = checker.getTypeArguments(type);
59
+ if (typeArgs.length === 0) {
60
+ throw new Error("Generic array not supported");
61
+ }
62
+ return {
63
+ kind: TypeDefKind.ListKind,
64
+ typeDef: typeToTypedef(checker, typeArgs[0]),
65
+ };
66
+ }
67
+ const strType = checker.typeToString(type);
68
+ switch (strType) {
69
+ case "string":
70
+ return { kind: TypeDefKind.StringKind };
71
+ case "number":
72
+ return { kind: TypeDefKind.IntegerKind };
73
+ case "boolean":
74
+ return { kind: TypeDefKind.BooleanKind };
75
+ case "void":
76
+ return { kind: TypeDefKind.VoidKind };
77
+ // Intercept primitive types and throw error in this case
78
+ case "String":
79
+ throw new Error("Use of primitive String type detected, did you mean string?");
80
+ case "Number":
81
+ throw new Error("Use of primitive Number type detected, did you mean number?");
82
+ case "Boolean":
83
+ throw new Error("Use of primitive Boolean type detected, did you mean boolean?");
84
+ default:
85
+ // If it's a class or interface, it's an object
86
+ if (type.symbol?.name && type.isClassOrInterface()) {
87
+ return {
88
+ kind: TypeDefKind.ObjectKind,
89
+ name: strType,
90
+ };
91
+ }
92
+ // If it's a union, then it's a scalar type
93
+ if (type.isUnionOrIntersection()) {
94
+ return {
95
+ kind: TypeDefKind.ScalarKind,
96
+ name: strType,
97
+ };
98
+ }
99
+ throw new Error(`Unsupported type ${strType}`);
100
+ }
101
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns a list of path of all files in the given directory
3
+ */
4
+ export declare function listFiles(dir?: string): Promise<string[]>;
5
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../introspector/utils/files.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,wBAAsB,SAAS,CAAC,GAAG,SAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA0B5D"}
@@ -0,0 +1,28 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ /**
4
+ * Extensions supported by the loader.
5
+ */
6
+ const allowedExtensions = [".ts", ".mts"];
7
+ /**
8
+ * Returns a list of path of all files in the given directory
9
+ */
10
+ export async function listFiles(dir = ".") {
11
+ const res = await Promise.all(fs.readdirSync(dir).map(async (file) => {
12
+ const filepath = path.join(dir, file);
13
+ // Ignore node_modules and transpiled typescript
14
+ if (filepath.includes("node_modules") || filepath.includes("dist")) {
15
+ return [];
16
+ }
17
+ const stat = fs.statSync(filepath);
18
+ if (stat.isDirectory()) {
19
+ return await listFiles(filepath);
20
+ }
21
+ const ext = path.extname(filepath);
22
+ if (allowedExtensions.find((allowedExt) => allowedExt === ext)) {
23
+ return [`${dir}/${file}`];
24
+ }
25
+ return [];
26
+ }));
27
+ return res.reduce((p, c) => [...c, ...p], []);
28
+ }
@@ -0,0 +1,77 @@
1
+ import { ResultPromise } from "execa";
2
+ import { GraphQLClient } from "graphql-request";
3
+ import { ConnectOpts, EngineConn } from "./engineconn.js";
4
+ export type ExecaChildProcess = ResultPromise<{
5
+ stdio: "pipe";
6
+ reject: true;
7
+ cleanup: true;
8
+ }>;
9
+ /**
10
+ * Bin runs an engine session from a specified binary
11
+ */
12
+ export declare class Bin implements EngineConn {
13
+ private _subProcess?;
14
+ private binPath?;
15
+ private cliVersion?;
16
+ private readonly cacheDir;
17
+ private readonly DAGGER_CLI_BIN_PREFIX;
18
+ constructor(binPath?: string, cliVersion?: string);
19
+ Addr(): string;
20
+ get subProcess(): ExecaChildProcess | undefined;
21
+ Connect(opts: ConnectOpts): Promise<GraphQLClient>;
22
+ private downloadCLI;
23
+ /**
24
+ * Traverse up the directory tree to find the package.json file and return the
25
+ * SDK version.
26
+ * @returns the SDK version or "n/a" if the version cannot be found.
27
+ */
28
+ private getSDKVersion;
29
+ /**
30
+ * runEngineSession execute the engine binary and set up a GraphQL client that
31
+ * target this engine.
32
+ */
33
+ private runEngineSession;
34
+ private readConnectParams;
35
+ Close(): Promise<void>;
36
+ /**
37
+ * createCacheDir will create a cache directory on user
38
+ * host to store dagger binary.
39
+ *
40
+ * If set, it will use envPaths to determine system's cache directory,
41
+ * if not, it will use `$HOME/.cache` as base path.
42
+ * Nothing happens if the directory already exists.
43
+ */
44
+ private createCacheDir;
45
+ /**
46
+ * buildBinPath create a path to output dagger cli binary.
47
+ *
48
+ * It will store it in the cache directory with a name composed
49
+ * of the base engine session as constant and the engine identifier.
50
+ */
51
+ private buildBinPath;
52
+ /**
53
+ * buildExePath create a path to output dagger cli binary.
54
+ */
55
+ private buildOsExePath;
56
+ /**
57
+ * normalizedArch returns the architecture name used by the rest of our SDKs.
58
+ */
59
+ private normalizedArch;
60
+ /**
61
+ * normalizedOS returns the os name used by the rest of our SDKs.
62
+ */
63
+ private normalizedOS;
64
+ private cliArchiveName;
65
+ private cliArchiveURL;
66
+ private cliChecksumURL;
67
+ private checksumMap;
68
+ private expectedChecksum;
69
+ private extractArchive;
70
+ /**
71
+ * Generate a unix timestamp in nanosecond
72
+ */
73
+ private getRandomId;
74
+ }
75
+ export declare function _overrideCLIURL(url: string): void;
76
+ export declare function _overrideCLIChecksumsURL(url: string): void;
77
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../provisioning/bin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAS,aAAa,EAAE,MAAM,OAAO,CAAA;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAgB/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAA;AAMxE,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC;IAC5C,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,IAAI,CAAA;IACZ,OAAO,EAAE,IAAI,CAAA;CACd,CAAC,CAAA;AAEF;;GAEG;AACH,qBAAa,GAAI,YAAW,UAAU;IACpC,OAAO,CAAC,WAAW,CAAC,CAAmB;IAEvC,OAAO,CAAC,OAAO,CAAC,CAAQ;IACxB,OAAO,CAAC,UAAU,CAAC,CAAQ;IAE3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAGxB;IAED,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAW;gBAErC,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;IAKjD,IAAI,IAAI,MAAM;IAId,IAAI,UAAU,IAAI,iBAAiB,GAAG,SAAS,CAE9C;IAEK,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;YAgB1C,WAAW;IAkEzB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAqBrB;;;OAGG;YACW,gBAAgB;YA2EhB,iBAAiB;IA6BzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAM5B;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IAItB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,cAAc;YAOR,WAAW;YAkBX,gBAAgB;YAWhB,cAAc;IA4C5B;;OAEG;IACH,OAAO,CAAC,WAAW;CAGpB;AAGD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEjD;AAGD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE1D"}