@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,71 @@
1
+ import * as path from "path";
2
+ import { fileURLToPath } from "url";
3
+ import { dag } from "../api/client.gen.js";
4
+ import { connection } from "../connect.js";
5
+ import { scan } from "../introspector/scanner/scan.js";
6
+ import { listFiles } from "../introspector/utils/files.js";
7
+ import { invoke } from "./invoke.js";
8
+ import { load } from "./load.js";
9
+ import { register } from "./register.js";
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+ const moduleSrcDirectory = `${__dirname}/../../src/`;
13
+ export async function entrypoint() {
14
+ // Pre list all files of the modules since we need it either for a registration
15
+ // or an invocation
16
+ const files = await listFiles(moduleSrcDirectory);
17
+ // Start a Dagger session to get the call context
18
+ await connection(async () => {
19
+ const fnCall = dag.currentFunctionCall();
20
+ const moduleName = await dag.currentModule().name();
21
+ const parentName = await fnCall.parentName();
22
+ const scanResult = scan(files, moduleName);
23
+ // Pre allocate the result, we got one in both case.
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ let result;
26
+ if (parentName === "") {
27
+ result = await register(files, scanResult);
28
+ }
29
+ else {
30
+ // Invocation
31
+ const fnName = await fnCall.name();
32
+ const parentJson = JSON.parse(await fnCall.parent());
33
+ const fnArgs = await fnCall.inputArgs();
34
+ const args = {};
35
+ const parentArgs = parentJson ?? {};
36
+ for (const arg of fnArgs) {
37
+ args[await arg.name()] = JSON.parse(await arg.value());
38
+ }
39
+ await load(files);
40
+ try {
41
+ result = await invoke(scanResult, {
42
+ parentName,
43
+ fnName,
44
+ parentArgs,
45
+ fnArgs: args,
46
+ });
47
+ }
48
+ catch (e) {
49
+ if (e instanceof Error) {
50
+ if (e.cause) {
51
+ console.error(`${e.cause}`);
52
+ }
53
+ console.error(`Error: ${e.message}`);
54
+ }
55
+ else {
56
+ console.error(e);
57
+ }
58
+ process.exit(1);
59
+ }
60
+ }
61
+ // If result is set, we stringify it
62
+ if (result !== undefined && result !== null) {
63
+ result = JSON.stringify(result);
64
+ }
65
+ else {
66
+ result = "null";
67
+ }
68
+ // Send the result to Dagger
69
+ await fnCall.returnValue(result);
70
+ }, { LogOutput: process.stdout });
71
+ }
@@ -0,0 +1,13 @@
1
+ import { DaggerModule } from "../introspector/scanner/abtractions/module.js";
2
+ import { InvokeCtx } from "./context.js";
3
+ /**
4
+ * A wrapper around the registry to invoke a function.
5
+ *
6
+ * @param scanResult The result of the scan.
7
+ * @param parentName The name of the parent object.
8
+ * @param fnName The name of the function to call.
9
+ * @param parentArgs The arguments of the parent object.
10
+ * @param fnArgs The arguments of the function to call.
11
+ */
12
+ export declare function invoke(module: DaggerModule, ctx: InvokeCtx): Promise<any>;
13
+ //# sourceMappingURL=invoke.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../entrypoint/invoke.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAE5E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAcxC;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,SAAS,gBAoChE"}
@@ -0,0 +1,40 @@
1
+ import { registry } from "../introspector/registry/registry.js";
2
+ import { loadResult, loadInvokedMethod, loadInvokedObject, loadArgs, loadParentState, loadObjectReturnType, } from "./load.js";
3
+ function isConstructor(method) {
4
+ return method.name === "";
5
+ }
6
+ /**
7
+ * A wrapper around the registry to invoke a function.
8
+ *
9
+ * @param scanResult The result of the scan.
10
+ * @param parentName The name of the parent object.
11
+ * @param fnName The name of the function to call.
12
+ * @param parentArgs The arguments of the parent object.
13
+ * @param fnArgs The arguments of the function to call.
14
+ */
15
+ export async function invoke(module, ctx) {
16
+ const object = loadInvokedObject(module, ctx.parentName);
17
+ if (!object) {
18
+ throw new Error(`could not find object ${ctx.parentName}`);
19
+ }
20
+ const method = loadInvokedMethod(object, ctx);
21
+ if (!method) {
22
+ throw new Error(`could not find method ${ctx.fnName}`);
23
+ }
24
+ const args = await loadArgs(registry, method, ctx);
25
+ const parentState = await loadParentState(registry, object, ctx);
26
+ let result = await registry.getResult(object.name, method.name, parentState, args);
27
+ if (result) {
28
+ let returnType;
29
+ // Handle alias serialization by getting the return type to load
30
+ // if the function called isn't a constructor.
31
+ if (!isConstructor(method)) {
32
+ returnType = loadObjectReturnType(module, object, method);
33
+ }
34
+ else {
35
+ returnType = object;
36
+ }
37
+ result = await loadResult(result, module, returnType);
38
+ }
39
+ return result;
40
+ }
@@ -0,0 +1,56 @@
1
+ import { TypeDefKind } from "../api/client.gen.js";
2
+ import { Args, Registry } from "../introspector/registry/registry.js";
3
+ import { Constructor } from "../introspector/scanner/abtractions/constructor.js";
4
+ import { DaggerEnum } from "../introspector/scanner/abtractions/enum.js";
5
+ import { Method } from "../introspector/scanner/abtractions/method.js";
6
+ import { DaggerModule } from "../introspector/scanner/abtractions/module.js";
7
+ import { DaggerObject } from "../introspector/scanner/abtractions/object.js";
8
+ import { TypeDef } from "../introspector/scanner/typeDefs.js";
9
+ import { InvokeCtx } from "./context.js";
10
+ /**
11
+ * Import all given typescript files so that trigger their decorators
12
+ * and register their class and functions inside the Registry.
13
+ *
14
+ * @param files List of files to load.
15
+ */
16
+ export declare function load(files: string[]): Promise<void>;
17
+ /**
18
+ * Return the object invoked from the module.
19
+ *
20
+ * @param module The module to load the object from.
21
+ * @param parentName The name of the parent object.
22
+ */
23
+ export declare function loadInvokedObject(module: DaggerModule, parentName: string): DaggerObject;
24
+ export declare function loadInvokedMethod(object: DaggerObject, ctx: InvokeCtx): (Method | Constructor) | undefined;
25
+ /**
26
+ * Load the values of the arguments from the context.
27
+ *
28
+ * @param method Method to load the arguments from.
29
+ * @param ctx The context of the invocation.
30
+ */
31
+ export declare function loadArgs(registry: Registry, method: Method | Constructor, ctx: InvokeCtx): Promise<Args>;
32
+ /**
33
+ * Load the state of the parent object from the context.
34
+ *
35
+ * @param object The object to load the parent state from.
36
+ * @param ctx The context of the invocation.
37
+ */
38
+ export declare function loadParentState(registry: Registry, object: DaggerObject, ctx: InvokeCtx): Promise<Args>;
39
+ /**
40
+ * This function load the value as a Dagger type.
41
+ *
42
+ * Note: The JSON.parse() is required to remove extra quotes
43
+ */
44
+ export declare function loadValue(registry: Registry, value: any, type: TypeDef<TypeDefKind>): Promise<any>;
45
+ /**
46
+ * Load the object type from the return type of the method.
47
+ * This covers the case where the return type is an other object of the module.
48
+ * For example: `msg(): Message` where message is an object of the module.
49
+ *
50
+ * @param module The module to load the object from.
51
+ * @param object The current object to load the return type from.
52
+ * @param method The method to load the return type from.
53
+ */
54
+ export declare function loadObjectReturnType(module: DaggerModule, object: DaggerObject, method: Method): DaggerObject | DaggerEnum;
55
+ export declare function loadResult(result: any, module: DaggerModule, object: DaggerObject | DaggerEnum): Promise<any>;
56
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../entrypoint/load.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,oDAAoD,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,GACjB,YAAY,CAEd;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,GACb,CAAC,MAAM,GAAG,WAAW,CAAC,GAAG,SAAS,CAMpC;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GAAG,WAAW,EAC5B,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,IAAI,CAAC,CAyCf;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,OAAO,CAAC,GAAG,CAAC,CA4Cd;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,GACb,YAAY,GAAG,UAAU,CAqB3B;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,GAAG,EACX,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,GAAG,UAAU,GAChC,OAAO,CAAC,GAAG,CAAC,CA0Ed"}
@@ -0,0 +1,198 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { dag, TypeDefKind } from "../api/client.gen.js";
3
+ import { DaggerEnum } from "../introspector/scanner/abtractions/enum.js";
4
+ import { DaggerObject } from "../introspector/scanner/abtractions/object.js";
5
+ /**
6
+ * Import all given typescript files so that trigger their decorators
7
+ * and register their class and functions inside the Registry.
8
+ *
9
+ * @param files List of files to load.
10
+ */
11
+ export async function load(files) {
12
+ await Promise.all(files.map(async (f) => await import(f)));
13
+ }
14
+ /**
15
+ * Return the object invoked from the module.
16
+ *
17
+ * @param module The module to load the object from.
18
+ * @param parentName The name of the parent object.
19
+ */
20
+ export function loadInvokedObject(module, parentName) {
21
+ return module.objects[parentName];
22
+ }
23
+ export function loadInvokedMethod(object, ctx) {
24
+ if (ctx.fnName === "") {
25
+ return object._constructor;
26
+ }
27
+ return object.methods[ctx.fnName];
28
+ }
29
+ /**
30
+ * Load the values of the arguments from the context.
31
+ *
32
+ * @param method Method to load the arguments from.
33
+ * @param ctx The context of the invocation.
34
+ */
35
+ export async function loadArgs(registry, method, ctx) {
36
+ const args = {};
37
+ // Load arguments
38
+ for (const argName of method.getArgOrder()) {
39
+ const argument = method.arguments[argName];
40
+ if (!argument) {
41
+ throw new Error(`could not find argument ${argName}`);
42
+ }
43
+ const loadedArg = await loadValue(registry, ctx.fnArgs[argName], argument.type);
44
+ // If the argument is variadic, we need to load each args independently
45
+ // so it's correctly propagated when it's sent to the function.
46
+ // Note: variadic args are always last in the list of args.
47
+ if (argument.isVariadic) {
48
+ for (const [i, arg] of (loadedArg ?? []).entries()) {
49
+ args[`${argName}${i}`] = arg;
50
+ }
51
+ continue;
52
+ }
53
+ // If the argument is nullable and the loaded arg is undefined with no default value, we set it to null.
54
+ if (argument.isNullable &&
55
+ loadedArg === undefined &&
56
+ !argument.defaultValue) {
57
+ args[argName] = null;
58
+ continue;
59
+ }
60
+ args[argName] = loadedArg;
61
+ }
62
+ return args;
63
+ }
64
+ /**
65
+ * Load the state of the parent object from the context.
66
+ *
67
+ * @param object The object to load the parent state from.
68
+ * @param ctx The context of the invocation.
69
+ */
70
+ export async function loadParentState(registry, object, ctx) {
71
+ const parentState = {};
72
+ for (const [key, value] of Object.entries(ctx.parentArgs)) {
73
+ const property = object.properties[key];
74
+ if (!property) {
75
+ throw new Error(`could not find parent property ${key}`);
76
+ }
77
+ parentState[property.name] = await loadValue(registry, value, property.type);
78
+ }
79
+ return parentState;
80
+ }
81
+ /**
82
+ * This function load the value as a Dagger type.
83
+ *
84
+ * Note: The JSON.parse() is required to remove extra quotes
85
+ */
86
+ export async function loadValue(registry, value, type) {
87
+ // If value is undefinied, return it directly.
88
+ if (value === undefined) {
89
+ return value;
90
+ }
91
+ switch (type.kind) {
92
+ case TypeDefKind.ListKind:
93
+ return Promise.all(value.map(async (v) => await loadValue(registry, v, type.typeDef)));
94
+ case TypeDefKind.ObjectKind: {
95
+ const objectType = type.name;
96
+ // Workaround to call get any object that has an id
97
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
98
+ // @ts-ignore
99
+ if (dag[`load${objectType}FromID`]) {
100
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
101
+ // @ts-ignore
102
+ return dag[`load${objectType}FromID`](value);
103
+ }
104
+ // TODO(supports subfields serialization)
105
+ return registry.buildClass(objectType, value);
106
+ }
107
+ // Cannot use `,` to specify multiple matching case so instead we use fallthrough.
108
+ case TypeDefKind.StringKind:
109
+ case TypeDefKind.IntegerKind:
110
+ case TypeDefKind.BooleanKind:
111
+ case TypeDefKind.VoidKind:
112
+ case TypeDefKind.ScalarKind:
113
+ case TypeDefKind.EnumKind:
114
+ return value;
115
+ default:
116
+ throw new Error(`unsupported type ${type.kind}`);
117
+ }
118
+ }
119
+ /**
120
+ * Load the object type from the return type of the method.
121
+ * This covers the case where the return type is an other object of the module.
122
+ * For example: `msg(): Message` where message is an object of the module.
123
+ *
124
+ * @param module The module to load the object from.
125
+ * @param object The current object to load the return type from.
126
+ * @param method The method to load the return type from.
127
+ */
128
+ export function loadObjectReturnType(module, object, method) {
129
+ const retType = method.returnType;
130
+ switch (retType.kind) {
131
+ case TypeDefKind.ListKind: {
132
+ // Loop until we find the original object type.
133
+ // This way we handle the list of list (e.g Object[][][]...[])
134
+ let listType = retType;
135
+ while (listType.kind === TypeDefKind.ListKind) {
136
+ listType = listType.typeDef;
137
+ }
138
+ return module.objects[listType.name];
139
+ }
140
+ case TypeDefKind.ObjectKind:
141
+ return module.objects[retType.name];
142
+ case TypeDefKind.EnumKind:
143
+ return module.enums[retType.name];
144
+ default:
145
+ return object;
146
+ }
147
+ }
148
+ export async function loadResult(result, module, object) {
149
+ // Handle IDable objects
150
+ if (result && typeof result?.id === "function") {
151
+ result = await result.id();
152
+ }
153
+ // Handle arrays
154
+ if (Array.isArray(result)) {
155
+ result = await Promise.all(result.map(async (r) => await loadResult(r, module, object)));
156
+ return result;
157
+ }
158
+ // Handle objects
159
+ if (typeof result === "object" && object instanceof DaggerObject) {
160
+ const state = {};
161
+ for (const [key, value] of Object.entries(result)) {
162
+ const property = Object.values(object.properties).find((p) => p.name === key);
163
+ if (!property) {
164
+ throw new Error(`could not find result property ${key}`);
165
+ }
166
+ let referencedObject = undefined;
167
+ // Handle nested objects
168
+ if (property.type.kind === TypeDefKind.ObjectKind) {
169
+ referencedObject =
170
+ module.objects[property.type.name];
171
+ }
172
+ // Handle list of nested objects
173
+ if (property.type.kind === TypeDefKind.ListKind) {
174
+ let _property = property.type;
175
+ // Loop until we find the original type.
176
+ while (_property.kind === TypeDefKind.ListKind) {
177
+ _property = _property.typeDef;
178
+ }
179
+ // If the original type is an object, we use it as the referenced object.
180
+ if (_property.kind === TypeDefKind.ObjectKind) {
181
+ referencedObject =
182
+ module.objects[_property.name];
183
+ }
184
+ }
185
+ // If there's no referenced object, we use the current object.
186
+ if (!referencedObject) {
187
+ referencedObject = object;
188
+ }
189
+ state[property.alias ?? property.name] = await loadResult(value, module, referencedObject);
190
+ }
191
+ return state;
192
+ }
193
+ if (typeof result === "object" && object instanceof DaggerEnum) {
194
+ return result;
195
+ }
196
+ // Handle primitive types
197
+ return result;
198
+ }
@@ -0,0 +1,7 @@
1
+ import { ModuleID } from "../api/client.gen.js";
2
+ import { DaggerModule } from "../introspector/scanner/abtractions/module.js";
3
+ /**
4
+ * Register the module files and returns its ID
5
+ */
6
+ export declare function register(files: string[], module: DaggerModule): Promise<ModuleID>;
7
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../entrypoint/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,QAAQ,EAGT,MAAM,sBAAsB,CAAA;AAI7B,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAS5E;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,QAAQ,CAAC,CA6DnB"}
@@ -0,0 +1,139 @@
1
+ import { dag, TypeDefKind, } from "../api/client.gen.js";
2
+ /**
3
+ * Register the module files and returns its ID
4
+ */
5
+ export async function register(files, module) {
6
+ // Get a new module that we will fill in with all the types
7
+ let mod = dag.module_();
8
+ // Add module description if any.
9
+ if (module.description) {
10
+ mod = mod.withDescription(module.description);
11
+ }
12
+ // For each class scanned, register its type, method and properties in the module.
13
+ Object.values(module.objects).forEach((object) => {
14
+ // Register the class Typedef object in Dagger
15
+ let typeDef = dag.typeDef().withObject(object.name, {
16
+ description: object.description,
17
+ });
18
+ // Register all functions (methods) to this object
19
+ Object.values(object.methods).forEach((method) => {
20
+ typeDef = typeDef.withFunction(addFunction(method));
21
+ });
22
+ // Register all fields that belong to this object
23
+ Object.values(object.properties).forEach((field) => {
24
+ if (field.isExposed) {
25
+ typeDef = typeDef.withField(field.alias ?? field.name, addTypeDef(field.type), {
26
+ description: field.description,
27
+ });
28
+ }
29
+ });
30
+ if (object._constructor) {
31
+ typeDef = typeDef.withConstructor(addConstructor(object._constructor, typeDef));
32
+ }
33
+ // Add it to the module object
34
+ mod = mod.withObject(typeDef);
35
+ });
36
+ // Register all enums defined by this modules
37
+ Object.values(module.enums).forEach((enum_) => {
38
+ let typeDef = dag.typeDef().withEnum(enum_.name, {
39
+ description: enum_.description,
40
+ });
41
+ Object.values(enum_.values).forEach((value) => {
42
+ typeDef = typeDef.withEnumValue(value.value, {
43
+ description: value.description,
44
+ });
45
+ });
46
+ mod = mod.withEnum(typeDef);
47
+ });
48
+ // Call ID to actually execute the registration
49
+ return await mod.id();
50
+ }
51
+ /**
52
+ * Bind a constructor to the given object.
53
+ */
54
+ function addConstructor(constructor, owner) {
55
+ return dag.function_("", owner).with(addArg(constructor.arguments));
56
+ }
57
+ /**
58
+ * Create a function in the Dagger API.
59
+ */
60
+ function addFunction(fct) {
61
+ return dag
62
+ .function_(fct.alias ?? fct.name, addTypeDef(fct.returnType))
63
+ .withDescription(fct.description)
64
+ .with(addArg(fct.arguments));
65
+ }
66
+ /**
67
+ * Register all arguments in the function.
68
+ */
69
+ function addArg(args) {
70
+ return function (fct) {
71
+ Object.values(args).forEach((arg) => {
72
+ const opts = {
73
+ description: arg.description,
74
+ };
75
+ let typeDef = addTypeDef(arg.type);
76
+ if (arg.isOptional) {
77
+ typeDef = typeDef.withOptional(true);
78
+ }
79
+ // Check if both values are used, return an error if so.
80
+ if (arg.defaultValue && arg.defaultPath) {
81
+ throw new Error("cannot set both default value and default path from context");
82
+ }
83
+ // We do not set the default value if it's not a primitive type, we let TypeScript
84
+ // resolve the default value during the runtime instead.
85
+ // If it has a default value but is not primitive, we set the value as optional
86
+ // to workaround the fact that the API isn't aware of the default value and will
87
+ // expect it to be set as required input.
88
+ if (arg.defaultValue) {
89
+ if (isPrimitiveType(arg.type)) {
90
+ opts.defaultValue = arg.defaultValue;
91
+ }
92
+ else {
93
+ typeDef = typeDef.withOptional(true);
94
+ }
95
+ }
96
+ // If the argument is a contextual argument, it becomes optional.
97
+ if (arg.defaultPath) {
98
+ opts.defaultPath = arg.defaultPath;
99
+ }
100
+ if (arg.ignore) {
101
+ opts.ignore = arg.ignore;
102
+ }
103
+ fct = fct.withArg(arg.name, typeDef, opts);
104
+ });
105
+ return fct;
106
+ };
107
+ }
108
+ /**
109
+ * Wrapper around TypeDef to return the right Dagger TypesDef with its options.
110
+ *
111
+ * This function only convert the Typedef into correct dagger call
112
+ * but, it's up to function above with more context to add documentation,
113
+ * define if it's an optional value or its default's.
114
+ *
115
+ * We cannot do it there because the Typedef can come from any source:
116
+ * a field, a param, a return value etc...
117
+ */
118
+ function addTypeDef(type) {
119
+ switch (type.kind) {
120
+ case TypeDefKind.ScalarKind:
121
+ return dag.typeDef().withScalar(type.name);
122
+ case TypeDefKind.ObjectKind:
123
+ return dag.typeDef().withObject(type.name);
124
+ case TypeDefKind.ListKind:
125
+ return dag.typeDef().withListOf(addTypeDef(type.typeDef));
126
+ case TypeDefKind.VoidKind:
127
+ return dag.typeDef().withKind(type.kind).withOptional(true);
128
+ case TypeDefKind.EnumKind:
129
+ return dag.typeDef().withEnum(type.name);
130
+ default:
131
+ return dag.typeDef().withKind(type.kind);
132
+ }
133
+ }
134
+ function isPrimitiveType(type) {
135
+ return (type.kind === TypeDefKind.BooleanKind ||
136
+ type.kind === TypeDefKind.IntegerKind ||
137
+ type.kind === TypeDefKind.StringKind ||
138
+ type.kind === TypeDefKind.EnumKind);
139
+ }
@@ -0,0 +1,3 @@
1
+ import { GraphQLClient } from "graphql-request";
2
+ export declare function createGQLClient(port: number, token: string): GraphQLClient;
3
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../graphql/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AA2C/C,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAsB1E"}
@@ -0,0 +1,48 @@
1
+ import * as opentelemetry from "@opentelemetry/api";
2
+ import { GraphQLClient } from "graphql-request";
3
+ import fetch from "node-fetch";
4
+ const createFetchWithTimeout = (timeout) => async (input, init) => {
5
+ if (init?.signal) {
6
+ throw new Error("Internal error: could not create fetch client with timeout");
7
+ }
8
+ const controller = new AbortController();
9
+ const timerId = setTimeout(() => {
10
+ controller.abort();
11
+ }, timeout);
12
+ try {
13
+ return (await fetch(input, {
14
+ ...init,
15
+ signal: controller.signal,
16
+ }));
17
+ }
18
+ finally {
19
+ clearTimeout(timerId);
20
+ }
21
+ };
22
+ /**
23
+ * Customer setter to inject trace parent into the request headers
24
+ * This is required because `graphql-request` 7.0.1 changes its header
25
+ * type to `Headers` which break the default open telemetry propagator.
26
+ */
27
+ class CustomSetter {
28
+ set(carrier, key, value) {
29
+ carrier.set(key, value);
30
+ }
31
+ }
32
+ export function createGQLClient(port, token) {
33
+ const client = new GraphQLClient(`http://127.0.0.1:${port}/query`, {
34
+ // 1 week timeout so we should never hit that one.
35
+ // This is to bypass the current graphql-request timeout, which depends on
36
+ // node-fetch and is 5minutes by default.
37
+ fetch: createFetchWithTimeout(1000 * 60 * 60 * 24 * 7),
38
+ headers: {
39
+ Authorization: "Basic " + Buffer.from(token + ":").toString("base64"),
40
+ },
41
+ // Inject trace parent into the request headers so it can be correctly linked
42
+ requestMiddleware: async (req) => {
43
+ opentelemetry.propagation.inject(opentelemetry.context.active(), req.headers, new CustomSetter());
44
+ return req;
45
+ },
46
+ });
47
+ return client;
48
+ }
@@ -0,0 +1,10 @@
1
+ export * from "./api/client.gen.js";
2
+ export * from "./common/errors/index.js";
3
+ export { gql } from "graphql-tag";
4
+ export { GraphQLClient } from "graphql-request";
5
+ export type { CallbackFct } from "./connect.js";
6
+ export { connect, connection, close } from "./connect.js";
7
+ export type { ConnectOpts } from "./connectOpts.js";
8
+ export * from "./introspector/decorators/decorators.js";
9
+ export { entrypoint } from "./entrypoint/entrypoint.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,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"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./api/client.gen.js";
2
+ export * from "./common/errors/index.js";
3
+ export { gql } from "graphql-tag";
4
+ export { GraphQLClient } from "graphql-request";
5
+ export { connect, connection, close } from "./connect.js";
6
+ export * from "./introspector/decorators/decorators.js";
7
+ export { entrypoint } from "./entrypoint/entrypoint.js";
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The definition of the `@object` decorator that should be on top of any
3
+ * class module that must be exposed to the Dagger API.
4
+ *
5
+ */
6
+ export declare const object: () => (<T extends import("../registry/registry.js").Class>(constructor: T) => T);
7
+ /**
8
+ * The definition of @func decorator that should be on top of any
9
+ * class' method that must be exposed to the Dagger API.
10
+ *
11
+ * @param alias The alias to use for the field when exposed on the API.
12
+ */
13
+ export declare const func: (alias?: string) => ((target: object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => void);
14
+ /**
15
+ * The definition of @field decorator that should be on top of any
16
+ * class' property that must be exposed to the Dagger API.
17
+ *
18
+ * @deprecated In favor of `@func`
19
+ * @param alias The alias to use for the field when exposed on the API.
20
+ */
21
+ export declare const field: (alias?: string) => ((target: object, propertyKey: string) => void);
22
+ /**
23
+ * The definition of the `@enumType` decorator that should be on top of any
24
+ * class module that must be exposed to the Dagger API as enumeration.
25
+ */
26
+ export declare const enumType: () => (<T extends import("../registry/registry.js").Class>(constructor: T) => T);
27
+ /**
28
+ * Add a `@argument` decorator to an argument of type `Directory` or `File` to load
29
+ * its contents from the module context directory.
30
+ *
31
+ * The context directory is the git repository containing the module.
32
+ * If there's no git repository, the context directory is the directory containing
33
+ * the module source code.
34
+ *
35
+ * @param opts.defaultPath Only applies to arguments of type File or Directory. If the argument is not set,
36
+ * load it from the given path in the context directory.
37
+ * @param opts.ignore Only applies to arguments of type Directory. The ignore patterns are applied to the input directory,
38
+ * and matching entries are filtered out, in a cache-efficient manner..
39
+ *
40
+ * Relative paths are relative to the current source files.
41
+ * Absolute paths are rooted to the module context directory.
42
+ */
43
+ export declare const argument: (opts?: import("../registry/registry.js").ArgumentOptions) => ((target: object, propertyKey: string, parameterIndex: number) => void);
44
+ //# sourceMappingURL=decorators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../introspector/decorators/decorators.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,MAAM,kFAAkB,CAAA;AAErC;;;;;GAKG;AACH,eAAO,MAAM,IAAI,gFAkCksC,CAAC,8BAlCnrC,CAAA;AAEjC;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,qEAAiB,CAAA;AAEnC;;;GAGG;AACH,eAAO,MAAM,QAAQ,kFAAoB,CAAA;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,uIAAoB,CAAA"}