@dagger.io/dagger 0.0.1-0

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 (213) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +88 -0
  3. package/dist/src/api/client.gen.d.ts +6123 -0
  4. package/dist/src/api/client.gen.d.ts.map +1 -0
  5. package/dist/src/api/client.gen.js +8494 -0
  6. package/dist/src/common/context.d.ts +12 -0
  7. package/dist/src/common/context.d.ts.map +1 -0
  8. package/dist/src/common/context.js +22 -0
  9. package/dist/src/common/errors/DaggerSDKError.d.ts +32 -0
  10. package/dist/src/common/errors/DaggerSDKError.d.ts.map +1 -0
  11. package/dist/src/common/errors/DaggerSDKError.js +26 -0
  12. package/dist/src/common/errors/DockerImageRefValidationError.d.ts +22 -0
  13. package/dist/src/common/errors/DockerImageRefValidationError.d.ts.map +1 -0
  14. package/dist/src/common/errors/DockerImageRefValidationError.js +21 -0
  15. package/dist/src/common/errors/EngineSessionConnectParamsParseError.d.ts +21 -0
  16. package/dist/src/common/errors/EngineSessionConnectParamsParseError.d.ts.map +1 -0
  17. package/dist/src/common/errors/EngineSessionConnectParamsParseError.js +20 -0
  18. package/dist/src/common/errors/EngineSessionConnectionTimeoutError.d.ts +21 -0
  19. package/dist/src/common/errors/EngineSessionConnectionTimeoutError.d.ts.map +1 -0
  20. package/dist/src/common/errors/EngineSessionConnectionTimeoutError.js +20 -0
  21. package/dist/src/common/errors/EngineSessionErrorOptions.d.ts +16 -0
  22. package/dist/src/common/errors/EngineSessionErrorOptions.d.ts.map +1 -0
  23. package/dist/src/common/errors/EngineSessionErrorOptions.js +16 -0
  24. package/dist/src/common/errors/ExecError.d.ts +42 -0
  25. package/dist/src/common/errors/ExecError.d.ts.map +1 -0
  26. package/dist/src/common/errors/ExecError.js +40 -0
  27. package/dist/src/common/errors/FunctionNotFound.d.ts +7 -0
  28. package/dist/src/common/errors/FunctionNotFound.d.ts.map +1 -0
  29. package/dist/src/common/errors/FunctionNotFound.js +9 -0
  30. package/dist/src/common/errors/GraphQLRequestError.d.ts +31 -0
  31. package/dist/src/common/errors/GraphQLRequestError.d.ts.map +1 -0
  32. package/dist/src/common/errors/GraphQLRequestError.js +30 -0
  33. package/dist/src/common/errors/InitEngineSessionBinaryError.d.ts +13 -0
  34. package/dist/src/common/errors/InitEngineSessionBinaryError.d.ts.map +1 -0
  35. package/dist/src/common/errors/InitEngineSessionBinaryError.js +15 -0
  36. package/dist/src/common/errors/IntrospectionError.d.ts +7 -0
  37. package/dist/src/common/errors/IntrospectionError.d.ts.map +1 -0
  38. package/dist/src/common/errors/IntrospectionError.js +9 -0
  39. package/dist/src/common/errors/NotAwaitedRequestError.d.ts +13 -0
  40. package/dist/src/common/errors/NotAwaitedRequestError.d.ts.map +1 -0
  41. package/dist/src/common/errors/NotAwaitedRequestError.js +15 -0
  42. package/dist/src/common/errors/TooManyNestedObjectsError.d.ts +21 -0
  43. package/dist/src/common/errors/TooManyNestedObjectsError.d.ts.map +1 -0
  44. package/dist/src/common/errors/TooManyNestedObjectsError.js +20 -0
  45. package/dist/src/common/errors/UnknownDaggerError.d.ts +13 -0
  46. package/dist/src/common/errors/UnknownDaggerError.d.ts.map +1 -0
  47. package/dist/src/common/errors/UnknownDaggerError.js +15 -0
  48. package/dist/src/common/errors/errors-codes.d.ts +55 -0
  49. package/dist/src/common/errors/errors-codes.d.ts.map +1 -0
  50. package/dist/src/common/errors/errors-codes.js +47 -0
  51. package/dist/src/common/errors/index.d.ts +15 -0
  52. package/dist/src/common/errors/index.d.ts.map +1 -0
  53. package/dist/src/common/errors/index.js +14 -0
  54. package/dist/src/common/graphql/client.d.ts +3 -0
  55. package/dist/src/common/graphql/client.d.ts.map +1 -0
  56. package/dist/src/common/graphql/client.js +58 -0
  57. package/dist/src/common/graphql/compute_query.d.ts +37 -0
  58. package/dist/src/common/graphql/compute_query.d.ts.map +1 -0
  59. package/dist/src/common/graphql/compute_query.js +171 -0
  60. package/dist/src/common/graphql/connect.d.ts +8 -0
  61. package/dist/src/common/graphql/connect.d.ts.map +1 -0
  62. package/dist/src/common/graphql/connect.js +22 -0
  63. package/dist/src/common/graphql/connection.d.ts +14 -0
  64. package/dist/src/common/graphql/connection.d.ts.map +1 -0
  65. package/dist/src/common/graphql/connection.js +23 -0
  66. package/dist/src/common/utils.d.ts +70 -0
  67. package/dist/src/common/utils.d.ts.map +1 -0
  68. package/dist/src/common/utils.js +6 -0
  69. package/dist/src/connect.d.ts +28 -0
  70. package/dist/src/connect.d.ts.map +1 -0
  71. package/dist/src/connect.js +64 -0
  72. package/dist/src/connectOpts.d.ts +24 -0
  73. package/dist/src/connectOpts.d.ts.map +1 -0
  74. package/dist/src/connectOpts.js +1 -0
  75. package/dist/src/index.d.ts +11 -0
  76. package/dist/src/index.d.ts.map +1 -0
  77. package/dist/src/index.js +13 -0
  78. package/dist/src/module/decorators.d.ts +52 -0
  79. package/dist/src/module/decorators.d.ts.map +1 -0
  80. package/dist/src/module/decorators.js +55 -0
  81. package/dist/src/module/entrypoint/context.d.ts +8 -0
  82. package/dist/src/module/entrypoint/context.d.ts.map +1 -0
  83. package/dist/src/module/entrypoint/context.js +1 -0
  84. package/dist/src/module/entrypoint/entrypoint.d.ts +2 -0
  85. package/dist/src/module/entrypoint/entrypoint.d.ts.map +1 -0
  86. package/dist/src/module/entrypoint/entrypoint.js +92 -0
  87. package/dist/src/module/entrypoint/introspection_entrypoint.d.ts +2 -0
  88. package/dist/src/module/entrypoint/introspection_entrypoint.d.ts.map +1 -0
  89. package/dist/src/module/entrypoint/introspection_entrypoint.js +52 -0
  90. package/dist/src/module/entrypoint/invoke.d.ts +14 -0
  91. package/dist/src/module/entrypoint/invoke.d.ts.map +1 -0
  92. package/dist/src/module/entrypoint/invoke.js +66 -0
  93. package/dist/src/module/entrypoint/load.d.ts +53 -0
  94. package/dist/src/module/entrypoint/load.d.ts.map +1 -0
  95. package/dist/src/module/entrypoint/load.js +237 -0
  96. package/dist/src/module/entrypoint/register.d.ts +33 -0
  97. package/dist/src/module/entrypoint/register.d.ts.map +1 -0
  98. package/dist/src/module/entrypoint/register.js +227 -0
  99. package/dist/src/module/executor.d.ts +28 -0
  100. package/dist/src/module/executor.d.ts.map +1 -0
  101. package/dist/src/module/executor.js +171 -0
  102. package/dist/src/module/introspector/case_convertor.d.ts +2 -0
  103. package/dist/src/module/introspector/case_convertor.d.ts.map +1 -0
  104. package/dist/src/module/introspector/case_convertor.js +15 -0
  105. package/dist/src/module/introspector/dagger_module/argument.d.ts +50 -0
  106. package/dist/src/module/introspector/dagger_module/argument.d.ts.map +1 -0
  107. package/dist/src/module/introspector/dagger_module/argument.js +118 -0
  108. package/dist/src/module/introspector/dagger_module/constructor.d.ts +18 -0
  109. package/dist/src/module/introspector/dagger_module/constructor.d.ts.map +1 -0
  110. package/dist/src/module/introspector/dagger_module/constructor.js +38 -0
  111. package/dist/src/module/introspector/dagger_module/decorator.d.ts +8 -0
  112. package/dist/src/module/introspector/dagger_module/decorator.d.ts.map +1 -0
  113. package/dist/src/module/introspector/dagger_module/decorator.js +7 -0
  114. package/dist/src/module/introspector/dagger_module/enum.d.ts +41 -0
  115. package/dist/src/module/introspector/dagger_module/enum.d.ts.map +1 -0
  116. package/dist/src/module/introspector/dagger_module/enum.js +63 -0
  117. package/dist/src/module/introspector/dagger_module/enumBase.d.ts +19 -0
  118. package/dist/src/module/introspector/dagger_module/enumBase.d.ts.map +1 -0
  119. package/dist/src/module/introspector/dagger_module/enumBase.js +1 -0
  120. package/dist/src/module/introspector/dagger_module/enumClass.d.ts +41 -0
  121. package/dist/src/module/introspector/dagger_module/enumClass.d.ts.map +1 -0
  122. package/dist/src/module/introspector/dagger_module/enumClass.js +69 -0
  123. package/dist/src/module/introspector/dagger_module/function.d.ts +39 -0
  124. package/dist/src/module/introspector/dagger_module/function.d.ts.map +1 -0
  125. package/dist/src/module/introspector/dagger_module/function.js +102 -0
  126. package/dist/src/module/introspector/dagger_module/index.d.ts +15 -0
  127. package/dist/src/module/introspector/dagger_module/index.d.ts.map +1 -0
  128. package/dist/src/module/introspector/dagger_module/index.js +14 -0
  129. package/dist/src/module/introspector/dagger_module/interface.d.ts +25 -0
  130. package/dist/src/module/introspector/dagger_module/interface.d.ts.map +1 -0
  131. package/dist/src/module/introspector/dagger_module/interface.js +56 -0
  132. package/dist/src/module/introspector/dagger_module/interfaceFunction.d.ts +35 -0
  133. package/dist/src/module/introspector/dagger_module/interfaceFunction.d.ts.map +1 -0
  134. package/dist/src/module/introspector/dagger_module/interfaceFunction.js +92 -0
  135. package/dist/src/module/introspector/dagger_module/locatable.d.ts +12 -0
  136. package/dist/src/module/introspector/dagger_module/locatable.d.ts.map +1 -0
  137. package/dist/src/module/introspector/dagger_module/locatable.js +14 -0
  138. package/dist/src/module/introspector/dagger_module/module.d.ts +118 -0
  139. package/dist/src/module/introspector/dagger_module/module.d.ts.map +1 -0
  140. package/dist/src/module/introspector/dagger_module/module.js +316 -0
  141. package/dist/src/module/introspector/dagger_module/object.d.ts +46 -0
  142. package/dist/src/module/introspector/dagger_module/object.d.ts.map +1 -0
  143. package/dist/src/module/introspector/dagger_module/object.js +113 -0
  144. package/dist/src/module/introspector/dagger_module/objectBase.d.ts +32 -0
  145. package/dist/src/module/introspector/dagger_module/objectBase.d.ts.map +1 -0
  146. package/dist/src/module/introspector/dagger_module/objectBase.js +1 -0
  147. package/dist/src/module/introspector/dagger_module/property.d.ts +36 -0
  148. package/dist/src/module/introspector/dagger_module/property.d.ts.map +1 -0
  149. package/dist/src/module/introspector/dagger_module/property.js +82 -0
  150. package/dist/src/module/introspector/dagger_module/reference.d.ts +13 -0
  151. package/dist/src/module/introspector/dagger_module/reference.d.ts.map +1 -0
  152. package/dist/src/module/introspector/dagger_module/reference.js +33 -0
  153. package/dist/src/module/introspector/dagger_module/typeObject.d.ts +49 -0
  154. package/dist/src/module/introspector/dagger_module/typeObject.d.ts.map +1 -0
  155. package/dist/src/module/introspector/dagger_module/typeObject.js +87 -0
  156. package/dist/src/module/introspector/dagger_module/typeObjectProperty.d.ts +34 -0
  157. package/dist/src/module/introspector/dagger_module/typeObjectProperty.d.ts.map +1 -0
  158. package/dist/src/module/introspector/dagger_module/typeObjectProperty.js +60 -0
  159. package/dist/src/module/introspector/index.d.ts +3 -0
  160. package/dist/src/module/introspector/index.d.ts.map +1 -0
  161. package/dist/src/module/introspector/index.js +19 -0
  162. package/dist/src/module/introspector/typedef.d.ts +52 -0
  163. package/dist/src/module/introspector/typedef.d.ts.map +1 -0
  164. package/dist/src/module/introspector/typedef.js +1 -0
  165. package/dist/src/module/introspector/typescript_module/ast.d.ts +64 -0
  166. package/dist/src/module/introspector/typescript_module/ast.d.ts.map +1 -0
  167. package/dist/src/module/introspector/typescript_module/ast.js +476 -0
  168. package/dist/src/module/introspector/typescript_module/declarations.d.ts +15 -0
  169. package/dist/src/module/introspector/typescript_module/declarations.d.ts.map +1 -0
  170. package/dist/src/module/introspector/typescript_module/declarations.js +10 -0
  171. package/dist/src/module/introspector/typescript_module/index.d.ts +4 -0
  172. package/dist/src/module/introspector/typescript_module/index.d.ts.map +1 -0
  173. package/dist/src/module/introspector/typescript_module/index.js +3 -0
  174. package/dist/src/module/introspector/typescript_module/location.d.ts +6 -0
  175. package/dist/src/module/introspector/typescript_module/location.d.ts.map +1 -0
  176. package/dist/src/module/introspector/typescript_module/location.js +1 -0
  177. package/dist/src/module/introspector/typescript_module/typedef_utils.d.ts +5 -0
  178. package/dist/src/module/introspector/typescript_module/typedef_utils.d.ts.map +1 -0
  179. package/dist/src/module/introspector/typescript_module/typedef_utils.js +26 -0
  180. package/dist/src/module/introspector/utils/files.d.ts +5 -0
  181. package/dist/src/module/introspector/utils/files.d.ts.map +1 -0
  182. package/dist/src/module/introspector/utils/files.js +28 -0
  183. package/dist/src/module/registry.d.ts +109 -0
  184. package/dist/src/module/registry.d.ts.map +1 -0
  185. package/dist/src/module/registry.js +123 -0
  186. package/dist/src/provisioning/bin.d.ts +77 -0
  187. package/dist/src/provisioning/bin.d.ts.map +1 -0
  188. package/dist/src/provisioning/bin.js +353 -0
  189. package/dist/src/provisioning/default.d.ts +2 -0
  190. package/dist/src/provisioning/default.d.ts.map +1 -0
  191. package/dist/src/provisioning/default.js +2 -0
  192. package/dist/src/provisioning/engineconn.d.ts +30 -0
  193. package/dist/src/provisioning/engineconn.d.ts.map +1 -0
  194. package/dist/src/provisioning/engineconn.js +1 -0
  195. package/dist/src/provisioning/index.d.ts +4 -0
  196. package/dist/src/provisioning/index.d.ts.map +1 -0
  197. package/dist/src/provisioning/index.js +14 -0
  198. package/dist/src/telemetry/index.d.ts +3 -0
  199. package/dist/src/telemetry/index.d.ts.map +1 -0
  200. package/dist/src/telemetry/index.js +2 -0
  201. package/dist/src/telemetry/init.d.ts +21 -0
  202. package/dist/src/telemetry/init.d.ts.map +1 -0
  203. package/dist/src/telemetry/init.js +86 -0
  204. package/dist/src/telemetry/live_processor.d.ts +12 -0
  205. package/dist/src/telemetry/live_processor.d.ts.map +1 -0
  206. package/dist/src/telemetry/live_processor.js +13 -0
  207. package/dist/src/telemetry/telemetry.d.ts +16 -0
  208. package/dist/src/telemetry/telemetry.d.ts.map +1 -0
  209. package/dist/src/telemetry/telemetry.js +38 -0
  210. package/dist/src/telemetry/tracer.d.ts +32 -0
  211. package/dist/src/telemetry/tracer.d.ts.map +1 -0
  212. package/dist/src/telemetry/tracer.js +54 -0
  213. package/package.json +74 -0
@@ -0,0 +1,64 @@
1
+ import * as opentelemetry from "@opentelemetry/api";
2
+ import { Client } from "./api/client.gen.js";
3
+ import { Context } from "./common/context.js";
4
+ import { withGQLClient } from "./common/graphql/connect.js";
5
+ import { Connection, globalConnection } from "./common/graphql/connection.js";
6
+ import * as telemetry from "./telemetry/telemetry.js";
7
+ /**
8
+ * connection executes the given function using the default global Dagger client.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * await connection(
13
+ * async () => {
14
+ * await dag
15
+ * .container()
16
+ * .from("alpine")
17
+ * .withExec(["apk", "add", "curl"])
18
+ * .withExec(["curl", "https://dagger.io/"])
19
+ * .sync()
20
+ * }, { LogOutput: process.stderr }
21
+ * )
22
+ * ```
23
+ */
24
+ export async function connection(fct, cfg = {}) {
25
+ try {
26
+ telemetry.initialize();
27
+ // Wrap connection into the opentelemetry context for propagation
28
+ await opentelemetry.context.with(telemetry.getContext(), async () => {
29
+ try {
30
+ await withGQLClient(cfg, async (gqlClient) => {
31
+ // Set the GQL client inside the global dagger client
32
+ globalConnection.setGQLClient(gqlClient);
33
+ await fct();
34
+ });
35
+ }
36
+ finally {
37
+ globalConnection.resetClient();
38
+ }
39
+ });
40
+ }
41
+ finally {
42
+ await telemetry.close();
43
+ }
44
+ }
45
+ /**
46
+ * connect runs GraphQL server and initializes a
47
+ * GraphQL client to execute query on it through its callback.
48
+ * This implementation is based on the existing Go SDK.
49
+ */
50
+ export async function connect(cb, config = {}) {
51
+ await withGQLClient(config, async (gqlClient) => {
52
+ const connection = new Connection(gqlClient);
53
+ const ctx = new Context([], connection);
54
+ const client = new Client(ctx);
55
+ // Warning shall be throw if versions are not compatible
56
+ try {
57
+ await client.version();
58
+ }
59
+ catch (e) {
60
+ console.error("failed to check version compatibility:", e);
61
+ }
62
+ return await cb(client);
63
+ });
64
+ }
@@ -0,0 +1,24 @@
1
+ import { Writable } from "node:stream";
2
+ /**
3
+ * ConnectOpts defines option used to connect to an engine.
4
+ */
5
+ export interface ConnectOpts {
6
+ /**
7
+ * Use to overwrite Dagger workdir
8
+ * @defaultValue process.cwd()
9
+ */
10
+ Workdir?: string;
11
+ /**
12
+ * Enable logs output
13
+ * @example
14
+ * LogOutput
15
+ * ```ts
16
+ * connect(async (client: Client) => {
17
+ const source = await client.host().workdir().id()
18
+ ...
19
+ }, {LogOutput: process.stdout})
20
+ ```
21
+ */
22
+ LogOutput?: Writable;
23
+ }
24
+ //# sourceMappingURL=connectOpts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectOpts.d.ts","sourceRoot":"","sources":["../../src/connectOpts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;;;;;;;SAUK;IACL,SAAS,CAAC,EAAE,QAAQ,CAAA;CACrB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ export { GraphQLClient } from "graphql-request";
2
+ export * from "./telemetry/index.js";
3
+ export * from "./api/client.gen.js";
4
+ export * from "./common/errors/index.js";
5
+ export type { CallbackFct } from "./connect.js";
6
+ export { connect, connection } from "./connect.js";
7
+ export type { ConnectOpts } from "./connectOpts.js";
8
+ export { Context } from "./common/context.js";
9
+ export * from "./module/decorators.js";
10
+ export { entrypoint } from "./module/entrypoint/entrypoint.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAG/C,cAAc,sBAAsB,CAAA;AAGpC,cAAc,qBAAqB,CAAA;AAGnC,cAAc,0BAA0B,CAAA;AAGxC,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAClD,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAG7C,cAAc,wBAAwB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA"}
@@ -0,0 +1,13 @@
1
+ export { GraphQLClient } from "graphql-request";
2
+ // Telemetry
3
+ export * from "./telemetry/index.js";
4
+ // Default client bindings
5
+ export * from "./api/client.gen.js";
6
+ // Common errors
7
+ export * from "./common/errors/index.js";
8
+ export { connect, connection } from "./connect.js";
9
+ // Export dagger connection context
10
+ export { Context } from "./common/context.js";
11
+ // Module library
12
+ export * from "./module/decorators.js";
13
+ export { entrypoint } from "./module/entrypoint/entrypoint.js";
@@ -0,0 +1,52 @@
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.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
+ * @param cache The cache setting to use for that function.
13
+ */
14
+ export declare const func: (opts?: import("./registry.js").FunctionOptions | string) => ((target: object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => void);
15
+ /**
16
+ * The definition of @check decorator that marks a function as a check.
17
+ * Checks are functions that return void/error to indicate pass/fail.
18
+ */
19
+ export declare const check: () => ((target: object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => void);
20
+ /**
21
+ * The definition of @field decorator that should be on top of any
22
+ * class' property that must be exposed to the Dagger API.
23
+ *
24
+ * @deprecated In favor of `@func`
25
+ * @param alias The alias to use for the field when exposed on the API.
26
+ */
27
+ export declare const field: (alias?: string) => ((target: object, propertyKey: string) => void);
28
+ /**
29
+ * The definition of the `@enumType` decorator that should be on top of any
30
+ * class module that must be exposed to the Dagger API as enumeration.
31
+ *
32
+ * @deprecated In favor of using TypeScript `enum` types.
33
+ */
34
+ export declare const enumType: () => (<T extends import("./registry.js").Class>(constructor: T) => T);
35
+ /**
36
+ * Add a `@argument` decorator to an argument of type `Directory` or `File` to load
37
+ * its contents from the module context directory.
38
+ *
39
+ * The context directory is the git repository containing the module.
40
+ * If there's no git repository, the context directory is the directory containing
41
+ * the module source code.
42
+ *
43
+ * @param opts.defaultPath Only applies to arguments of type File or Directory. If the argument is not set,
44
+ * load it from the given path in the context directory.
45
+ * @param opts.ignore Only applies to arguments of type Directory. The ignore patterns are applied to the input directory,
46
+ * and matching entries are filtered out, in a cache-efficient manner..
47
+ *
48
+ * Relative paths are relative to the current source files.
49
+ * Absolute paths are rooted to the module context directory.
50
+ */
51
+ export declare const argument: (opts?: import("./registry.js").ArgumentOptions) => ((target: object, propertyKey: string | undefined, parameterIndex: number) => void);
52
+ //# sourceMappingURL=decorators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/module/decorators.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,MAAM,wEAAkB,CAAA;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,yHA0C2+C,CAAC,8BA1C59C,CAAA;AAEjC;;;GAGG;AACH,eAAO,MAAM,KAAK,kEAoC6zD,CAAC,8BApC7yD,CAAA;AAEnC;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,qEAAiB,CAAA;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,wEAAoB,CAAA;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,yIAAoB,CAAA"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Expose the decorator publicly, so they insert data into the global registry.
3
+ */
4
+ import { registry } from "./registry.js";
5
+ /**
6
+ * The definition of the `@object` decorator that should be on top of any
7
+ * class module that must be exposed to the Dagger API.
8
+ *
9
+ */
10
+ export const object = registry.object;
11
+ /**
12
+ * The definition of @func decorator that should be on top of any
13
+ * class' method that must be exposed to the Dagger API.
14
+ *
15
+ * @param alias The alias to use for the field when exposed on the API.
16
+ * @param cache The cache setting to use for that function.
17
+ */
18
+ export const func = registry.func;
19
+ /**
20
+ * The definition of @check decorator that marks a function as a check.
21
+ * Checks are functions that return void/error to indicate pass/fail.
22
+ */
23
+ export const check = registry.check;
24
+ /**
25
+ * The definition of @field decorator that should be on top of any
26
+ * class' property that must be exposed to the Dagger API.
27
+ *
28
+ * @deprecated In favor of `@func`
29
+ * @param alias The alias to use for the field when exposed on the API.
30
+ */
31
+ export const field = registry.field;
32
+ /**
33
+ * The definition of the `@enumType` decorator that should be on top of any
34
+ * class module that must be exposed to the Dagger API as enumeration.
35
+ *
36
+ * @deprecated In favor of using TypeScript `enum` types.
37
+ */
38
+ export const enumType = registry.enumType;
39
+ /**
40
+ * Add a `@argument` decorator to an argument of type `Directory` or `File` to load
41
+ * its contents from the module context directory.
42
+ *
43
+ * The context directory is the git repository containing the module.
44
+ * If there's no git repository, the context directory is the directory containing
45
+ * the module source code.
46
+ *
47
+ * @param opts.defaultPath Only applies to arguments of type File or Directory. If the argument is not set,
48
+ * load it from the given path in the context directory.
49
+ * @param opts.ignore Only applies to arguments of type Directory. The ignore patterns are applied to the input directory,
50
+ * and matching entries are filtered out, in a cache-efficient manner..
51
+ *
52
+ * Relative paths are relative to the current source files.
53
+ * Absolute paths are rooted to the module context directory.
54
+ */
55
+ export const argument = registry.argument;
@@ -0,0 +1,8 @@
1
+ import { Args } from "../executor.js";
2
+ export type InvokeCtx = {
3
+ parentName: string;
4
+ fnName: string;
5
+ parentArgs: Args;
6
+ fnArgs: Args;
7
+ };
8
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/module/entrypoint/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAErC,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,IAAI,CAAA;IAChB,MAAM,EAAE,IAAI,CAAA;CACb,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function entrypoint(files: string[]): Promise<void>;
2
+ //# sourceMappingURL=entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../../../../src/module/entrypoint/entrypoint.ts"],"names":[],"mappings":"AAYA,wBAAsB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,iBA8D/C"}
@@ -0,0 +1,92 @@
1
+ import { dag } from "../../api/client.gen.js";
2
+ import { ExecError } from "../../common/errors/ExecError.js";
3
+ import { GraphQLRequestError } from "../../common/errors/GraphQLRequestError.js";
4
+ import { connection } from "../../connect.js";
5
+ import * as telemetry from "../../telemetry/telemetry.js";
6
+ import { Executor } from "../executor.js";
7
+ import { scan } from "../introspector/index.js";
8
+ import { invoke } from "./invoke.js";
9
+ import { load } from "./load.js";
10
+ import { Register } from "./register.js";
11
+ export async function entrypoint(files) {
12
+ // Start a Dagger session to get the call context
13
+ await connection(async () => {
14
+ const fnCall = dag.currentFunctionCall();
15
+ const moduleName = await dag.currentModule().name();
16
+ const scanResult = await scan(files, moduleName);
17
+ const parentName = await fnCall.parentName();
18
+ // Pre allocate the result, we got one in both case.
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ let result;
21
+ if (parentName === "") {
22
+ result = await new Register(scanResult).run();
23
+ }
24
+ else {
25
+ // Invocation
26
+ const fnName = await fnCall.name();
27
+ const parentJson = JSON.parse(await fnCall.parent());
28
+ const fnArgs = await fnCall.inputArgs();
29
+ const args = {};
30
+ const parentArgs = parentJson ?? {};
31
+ for (const arg of fnArgs) {
32
+ args[await arg.name()] = JSON.parse(await arg.value());
33
+ }
34
+ const modules = await load(files);
35
+ const executor = new Executor(modules, scanResult);
36
+ try {
37
+ result = await invoke(executor, scanResult, {
38
+ parentName,
39
+ fnName,
40
+ parentArgs,
41
+ fnArgs: args,
42
+ });
43
+ }
44
+ catch (e) {
45
+ await fnCall.returnError(formatError(e));
46
+ // Closing telemetry here since the process is shutdown after
47
+ // so any parent's finally will not be executed.
48
+ // That way, we guarantee that the spans are flushed.
49
+ await telemetry.close();
50
+ process.exit(1);
51
+ }
52
+ }
53
+ // If result is set, we stringify it
54
+ if (result !== undefined && result !== null) {
55
+ result = JSON.stringify(result);
56
+ }
57
+ else {
58
+ result = "null";
59
+ }
60
+ // Send the result to Dagger
61
+ await fnCall.returnValue(result);
62
+ }, { LogOutput: process.stdout });
63
+ }
64
+ /**
65
+ * Take the error thrown by the user module and stringify it so it can
66
+ * be returned to Dagger.
67
+ *
68
+ * If the error is an instance of Error, we stringify the message.
69
+ * If the error is an instance of ExecError, we stringify the message and add the
70
+ * extensions fields in the error object.
71
+ */
72
+ function formatError(e) {
73
+ if (e instanceof Error) {
74
+ let error = dag.error(e.message);
75
+ // If the error is an instance of GraphQLError or a inherit type of it,
76
+ // we can add the extensions fields in the error object.
77
+ if (e instanceof ExecError || e instanceof GraphQLRequestError) {
78
+ Object.entries(e.extensions ?? []).forEach(([key, value]) => {
79
+ if (value !== "" && value !== undefined && value !== null) {
80
+ error = error.withValue(key, JSON.stringify(value));
81
+ }
82
+ });
83
+ }
84
+ return error;
85
+ }
86
+ try {
87
+ return dag.error(JSON.stringify(e));
88
+ }
89
+ catch {
90
+ return dag.error(String(e));
91
+ }
92
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=introspection_entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspection_entrypoint.d.ts","sourceRoot":"","sources":["../../../../src/module/entrypoint/introspection_entrypoint.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { connection } from "../../connect.js";
4
+ import { scan } from "../introspector/index.js";
5
+ import { Register } from "./register.js";
6
+ async function introspection(files, moduleName) {
7
+ return await scan(files, moduleName, false);
8
+ }
9
+ const allowedExtensions = [".ts", ".mts"];
10
+ function getTsSourceCodeFiles(dir) {
11
+ return fs
12
+ .readdirSync(dir)
13
+ .map((file) => {
14
+ const filepath = path.join(dir, file);
15
+ const stat = fs.statSync(filepath);
16
+ if (stat.isDirectory()) {
17
+ return getTsSourceCodeFiles(filepath);
18
+ }
19
+ const ext = path.extname(filepath);
20
+ if (allowedExtensions.find((allowedExt) => allowedExt === ext)) {
21
+ return [path.join(dir, file)];
22
+ }
23
+ return [];
24
+ })
25
+ .reduce((p, c) => [...c, ...p]);
26
+ }
27
+ async function main() {
28
+ const args = process.argv.slice(2);
29
+ if (args.length < 3) {
30
+ console.log("usage: introspection <moduleName> <userSourceCodeDir> <typescriptClientFile>");
31
+ process.exit(1);
32
+ }
33
+ const moduleName = args[0];
34
+ const userSourceCodeDir = args[1];
35
+ const typescriptClientFile = args[2];
36
+ const userSourceCodeFiles = getTsSourceCodeFiles(userSourceCodeDir);
37
+ const result = await introspection([...userSourceCodeFiles, typescriptClientFile], moduleName);
38
+ if (process.env.DRY_RUN) {
39
+ console.log(JSON.stringify(result, null, 2));
40
+ process.exit(0);
41
+ }
42
+ // TODO(TomChv): move that logic inside the engine at some point
43
+ // so we don't even need a connection.
44
+ // Idea: We should output a JSON schema of the module that can be transformed
45
+ // into a Dagger module by the engine.
46
+ await connection(async () => {
47
+ const outputFilePath = process.env.TYPEDEF_OUTPUT_FILE ?? "/module-id.json";
48
+ const moduleID = await new Register(result).run();
49
+ await fs.promises.writeFile(outputFilePath, JSON.stringify(moduleID));
50
+ });
51
+ }
52
+ main();
@@ -0,0 +1,14 @@
1
+ import { Executor } from "../executor.js";
2
+ import { DaggerModule } from "../introspector/dagger_module/index.js";
3
+ import { InvokeCtx } from "./context.js";
4
+ /**
5
+ * A wrapper around the registry to invoke a function.
6
+ *
7
+ * @param scanResult The result of the scan.
8
+ * @param parentName The name of the parent object.
9
+ * @param fnName The name of the function to call.
10
+ * @param parentArgs The arguments of the parent object.
11
+ * @param fnArgs The arguments of the function to call.
12
+ */
13
+ export declare function invoke(executor: Executor, module: DaggerModule, ctx: InvokeCtx): Promise<any>;
14
+ //# sourceMappingURL=invoke.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../../../src/module/entrypoint/invoke.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAIL,YAAY,EAEb,MAAM,wCAAwC,CAAA;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAkBxC;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,gBAmEf"}
@@ -0,0 +1,66 @@
1
+ import { TypeDefKind } from "../../api/client.gen.js";
2
+ import { FunctionNotFound } from "../../common/errors/index.js";
3
+ import { registry } from "../registry.js";
4
+ import { loadResult, loadInvokedMethod, loadInvokedObject, loadArgs, loadParentState, loadObjectReturnType, } from "./load.js";
5
+ function isConstructor(method) {
6
+ return method.name === "";
7
+ }
8
+ function isFloat(num) {
9
+ return num % 1 !== 0;
10
+ }
11
+ /**
12
+ * A wrapper around the registry to invoke a function.
13
+ *
14
+ * @param scanResult The result of the scan.
15
+ * @param parentName The name of the parent object.
16
+ * @param fnName The name of the function to call.
17
+ * @param parentArgs The arguments of the parent object.
18
+ * @param fnArgs The arguments of the function to call.
19
+ */
20
+ export async function invoke(executor, module, ctx) {
21
+ const object = loadInvokedObject(module, ctx.parentName);
22
+ if (!object) {
23
+ throw new Error(`could not find object ${ctx.parentName}`);
24
+ }
25
+ const method = loadInvokedMethod(object, ctx);
26
+ if (!method) {
27
+ throw new Error(`could not find method ${ctx.fnName}`);
28
+ }
29
+ const args = await loadArgs(executor, method, ctx);
30
+ const parentState = await loadParentState(executor, object, ctx);
31
+ // Disabling linter because the result could be anything.
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ let result = {};
34
+ try {
35
+ result = await executor.getResult(object.name, method.name, parentState, args);
36
+ }
37
+ catch (e) {
38
+ // If the function isn't found because it's
39
+ // not exported, we try to get the result from the registry.
40
+ if (e instanceof FunctionNotFound) {
41
+ result = await registry.getResult(object.name, method.name, parentState, args);
42
+ }
43
+ else {
44
+ throw e;
45
+ }
46
+ }
47
+ if (result) {
48
+ let returnType;
49
+ // Handle alias serialization by getting the return type to load
50
+ // if the function called isn't a constructor.
51
+ if (!isConstructor(method)) {
52
+ // Guard to catch if a user returned a float number but the function's return
53
+ // type is set to `number` (integer).
54
+ if (method.returnType.kind === TypeDefKind.IntegerKind &&
55
+ isFloat(result)) {
56
+ throw new Error(`cannot return float '${result}' if return type is 'number' (integer), please use 'float' as return type instead`);
57
+ }
58
+ returnType = loadObjectReturnType(module, object, method);
59
+ }
60
+ else {
61
+ returnType = object;
62
+ }
63
+ result = await loadResult(result, module, returnType);
64
+ }
65
+ return result;
66
+ }
@@ -0,0 +1,53 @@
1
+ import Module from "node:module";
2
+ import { TypeDefKind } from "../../api/client.gen.js";
3
+ import { Executor, Args } from "../executor.js";
4
+ import { DaggerConstructor as Constructor, DaggerFunction as Method, DaggerEnumBase, DaggerModule, DaggerObject, DaggerObjectBase } from "../introspector/dagger_module/index.js";
5
+ import { TypeDef } from "../introspector/typedef.js";
6
+ import { InvokeCtx } from "./context.js";
7
+ /**
8
+ * Import all given typescript files so that trigger their decorators
9
+ * and register their class and functions inside the Registry.
10
+ *
11
+ * @param files List of files to load.
12
+ */
13
+ export declare function load(files: string[]): Promise<Module[]>;
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 declare function loadInvokedObject(module: DaggerModule, parentName: string): DaggerObject;
21
+ export declare function loadInvokedMethod(object: DaggerObject, ctx: InvokeCtx): (Method | Constructor) | undefined;
22
+ /**
23
+ * Load the values of the arguments from the context.
24
+ *
25
+ * @param method Method to load the arguments from.
26
+ * @param ctx The context of the invocation.
27
+ */
28
+ export declare function loadArgs(executor: Executor, method: Method | Constructor, ctx: InvokeCtx): Promise<Args>;
29
+ /**
30
+ * Load the state of the parent object from the context.
31
+ *
32
+ * @param object The object to load the parent state from.
33
+ * @param ctx The context of the invocation.
34
+ */
35
+ export declare function loadParentState(executor: Executor, object: DaggerObject, ctx: InvokeCtx): Promise<Args>;
36
+ /**
37
+ * This function load the value as a Dagger type.
38
+ *
39
+ * Note: The JSON.parse() is required to remove extra quotes
40
+ */
41
+ export declare function loadValue(executor: Executor, value: any, type: TypeDef<TypeDefKind>): Promise<any>;
42
+ /**
43
+ * Load the object type from the return type of the method.
44
+ * This covers the case where the return type is an other object of the module.
45
+ * For example: `msg(): Message` where message is an object of the module.
46
+ *
47
+ * @param module The module to load the object from.
48
+ * @param object The current object to load the return type from.
49
+ * @param method The method to load the return type from.
50
+ */
51
+ export declare function loadObjectReturnType(module: DaggerModule, object: DaggerObject, method: Method): DaggerObjectBase | DaggerEnumBase;
52
+ export declare function loadResult(result: any, module: DaggerModule, object: DaggerObjectBase | DaggerEnumBase): Promise<any>;
53
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../../../src/module/entrypoint/load.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,aAAa,CAAA;AAEhC,OAAO,EAAO,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EACL,iBAAiB,IAAI,WAAW,EAChC,cAAc,IAAI,MAAM,EAExB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAGjB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAE7D;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,CA6Cf;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,IAAI,CAAC,CAiBf;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,CAqDd;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,GACb,gBAAgB,GAAG,cAAc,CA4BnC;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,GAAG,EACX,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,gBAAgB,GAAG,cAAc,GACxC,OAAO,CAAC,GAAG,CAAC,CA0Gd"}