@dagger.io/dagger 0.9.3 → 0.9.5

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 (79) hide show
  1. package/dist/api/client.gen.d.ts +323 -280
  2. package/dist/api/client.gen.d.ts.map +1 -1
  3. package/dist/api/client.gen.js +1725 -1879
  4. package/dist/api/utils.js +73 -90
  5. package/dist/common/errors/DaggerSDKError.js +5 -1
  6. package/dist/common/errors/DockerImageRefValidationError.js +7 -3
  7. package/dist/common/errors/EngineSessionConnectParamsParseError.js +6 -2
  8. package/dist/common/errors/EngineSessionConnectionTimeoutError.js +6 -2
  9. package/dist/common/errors/EngineSessionErrorOptions.js +2 -2
  10. package/dist/common/errors/ExecError.js +18 -2
  11. package/dist/common/errors/GraphQLRequestError.js +10 -2
  12. package/dist/common/errors/InitEngineSessionBinaryError.js +2 -2
  13. package/dist/common/errors/NotAwaitedRequestError.js +2 -2
  14. package/dist/common/errors/TooManyNestedObjectsError.js +6 -2
  15. package/dist/common/errors/UnknownDaggerError.js +2 -2
  16. package/dist/common/errors/errors-codes.js +1 -1
  17. package/dist/common/utils.d.ts +4 -4
  18. package/dist/connect.d.ts +22 -27
  19. package/dist/connect.d.ts.map +1 -1
  20. package/dist/connect.js +43 -49
  21. package/dist/connectOpts.d.ts +25 -0
  22. package/dist/connectOpts.d.ts.map +1 -0
  23. package/dist/connectOpts.js +1 -0
  24. package/dist/context/builder.d.ts +9 -0
  25. package/dist/context/builder.d.ts.map +1 -0
  26. package/dist/context/builder.js +34 -0
  27. package/dist/context/context.d.ts +39 -0
  28. package/dist/context/context.d.ts.map +1 -0
  29. package/dist/context/context.js +51 -0
  30. package/dist/entrypoint/entrypoint.d.ts +2 -0
  31. package/dist/entrypoint/entrypoint.d.ts.map +1 -0
  32. package/dist/entrypoint/entrypoint.js +70 -0
  33. package/dist/entrypoint/invoke.d.ts +11 -0
  34. package/dist/entrypoint/invoke.d.ts.map +1 -0
  35. package/dist/entrypoint/invoke.js +14 -0
  36. package/dist/entrypoint/load.d.ts +16 -0
  37. package/dist/entrypoint/load.d.ts.map +1 -0
  38. package/dist/entrypoint/load.js +44 -0
  39. package/dist/entrypoint/register.d.ts +6 -0
  40. package/dist/entrypoint/register.d.ts.map +1 -0
  41. package/dist/entrypoint/register.js +93 -0
  42. package/dist/graphql/client.d.ts +3 -0
  43. package/dist/graphql/client.d.ts.map +1 -0
  44. package/dist/graphql/client.js +8 -0
  45. package/dist/index.d.ts +3 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +2 -1
  48. package/dist/introspector/decorators/decorators.d.ts +4 -0
  49. package/dist/introspector/decorators/decorators.d.ts.map +1 -0
  50. package/dist/introspector/decorators/decorators.js +7 -0
  51. package/dist/introspector/registry/registry.d.ts +65 -0
  52. package/dist/introspector/registry/registry.d.ts.map +1 -0
  53. package/dist/introspector/registry/registry.js +125 -0
  54. package/dist/introspector/scanner/metadata.d.ts +23 -0
  55. package/dist/introspector/scanner/metadata.d.ts.map +1 -0
  56. package/dist/introspector/scanner/metadata.js +1 -0
  57. package/dist/introspector/scanner/scan.d.ts +17 -0
  58. package/dist/introspector/scanner/scan.d.ts.map +1 -0
  59. package/dist/introspector/scanner/scan.js +158 -0
  60. package/dist/introspector/scanner/serialize.d.ts +34 -0
  61. package/dist/introspector/scanner/serialize.d.ts.map +1 -0
  62. package/dist/introspector/scanner/serialize.js +62 -0
  63. package/dist/introspector/scanner/typeDefs.d.ts +70 -0
  64. package/dist/introspector/scanner/typeDefs.d.ts.map +1 -0
  65. package/dist/introspector/scanner/typeDefs.js +1 -0
  66. package/dist/introspector/scanner/utils.d.ts +62 -0
  67. package/dist/introspector/scanner/utils.d.ts.map +1 -0
  68. package/dist/introspector/scanner/utils.js +124 -0
  69. package/dist/introspector/utils/files.d.ts +5 -0
  70. package/dist/introspector/utils/files.d.ts.map +1 -0
  71. package/dist/introspector/utils/files.js +28 -0
  72. package/dist/provisioning/bin.d.ts +5 -3
  73. package/dist/provisioning/bin.d.ts.map +1 -1
  74. package/dist/provisioning/bin.js +185 -233
  75. package/dist/provisioning/default.d.ts +1 -1
  76. package/dist/provisioning/default.js +1 -1
  77. package/dist/provisioning/engineconn.d.ts +6 -2
  78. package/dist/provisioning/engineconn.d.ts.map +1 -1
  79. package/package.json +3 -3
@@ -0,0 +1,25 @@
1
+ /// <reference types="node" />
2
+ import { Writable } from "node:stream";
3
+ /**
4
+ * ConnectOpts defines option used to connect to an engine.
5
+ */
6
+ export interface ConnectOpts {
7
+ /**
8
+ * Use to overwrite Dagger workdir
9
+ * @defaultValue process.cwd()
10
+ */
11
+ Workdir?: string;
12
+ /**
13
+ * Enable logs output
14
+ * @example
15
+ * LogOutput
16
+ * ```ts
17
+ * connect(async (client: Client) => {
18
+ const source = await client.host().workdir().id()
19
+ ...
20
+ }, {LogOutput: process.stdout})
21
+ ```
22
+ */
23
+ LogOutput?: Writable;
24
+ }
25
+ //# sourceMappingURL=connectOpts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectOpts.d.ts","sourceRoot":"","sources":["../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,9 @@
1
+ import { ConnectOpts } from "../connectOpts.js";
2
+ import { Context } from "./context.js";
3
+ /**
4
+ * @hidden
5
+ *
6
+ * Initialize a default client context from environment.
7
+ */
8
+ export declare function initDefaultContext(cfg?: ConnectOpts): Promise<Context>;
9
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../context/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,GAAE,WAAgB,GACpB,OAAO,CAAC,OAAO,CAAC,CAiClB"}
@@ -0,0 +1,34 @@
1
+ import { createGQLClient } from "../graphql/client.js";
2
+ import { Bin, CLI_VERSION } from "../provisioning/index.js";
3
+ import { Context } from "./context.js";
4
+ /**
5
+ * @hidden
6
+ *
7
+ * Initialize a default client context from environment.
8
+ */
9
+ export async function initDefaultContext(cfg = {}) {
10
+ let ctx = new Context();
11
+ // Prefer DAGGER_SESSION_PORT if set
12
+ const daggerSessionPort = process.env["DAGGER_SESSION_PORT"];
13
+ if (daggerSessionPort) {
14
+ const sessionToken = process.env["DAGGER_SESSION_TOKEN"];
15
+ if (!sessionToken) {
16
+ throw new Error("DAGGER_SESSION_TOKEN must be set when using DAGGER_SESSION_PORT");
17
+ }
18
+ if (cfg.Workdir && cfg.Workdir !== "") {
19
+ throw new Error("cannot configure workdir for existing session (please use --workdir or host.directory with absolute paths instead)");
20
+ }
21
+ ctx = new Context({
22
+ client: createGQLClient(Number(daggerSessionPort), sessionToken),
23
+ });
24
+ }
25
+ else {
26
+ // Otherwise, prefer _EXPERIMENTAL_DAGGER_CLI_BIN, with fallback behavior of
27
+ // downloading the CLI and using that as the bin.
28
+ const cliBin = process.env["_EXPERIMENTAL_DAGGER_CLI_BIN"];
29
+ const engineConn = new Bin(cliBin, CLI_VERSION);
30
+ const client = await engineConn.Connect(cfg);
31
+ ctx = new Context({ client, subProcess: engineConn.subProcess });
32
+ }
33
+ return ctx;
34
+ }
@@ -0,0 +1,39 @@
1
+ import { ExecaChildProcess } from "execa";
2
+ import { GraphQLClient } from "graphql-request";
3
+ import { ConnectOpts } from "../connectOpts.js";
4
+ interface ContextConfig {
5
+ client?: GraphQLClient;
6
+ subProcess?: ExecaChildProcess;
7
+ }
8
+ /**
9
+ * Context abstracts the connection to the engine.
10
+ *
11
+ * It's required to implement the default global SDK.
12
+ * Its purpose is to store and returns the connection to the graphQL API, if
13
+ * no connection is set, it can create its own.
14
+ *
15
+ * This is also useful for lazy evaluation with the default global client,
16
+ * this one should only run the engine if it actually executes something.
17
+ */
18
+ export declare class Context {
19
+ private _client?;
20
+ private _subProcess?;
21
+ constructor(config?: ContextConfig);
22
+ /**
23
+ * Returns a GraphQL client connected to the engine.
24
+ *
25
+ * If no client is set, it will create one.
26
+ */
27
+ connection(cfg?: ConnectOpts): Promise<GraphQLClient>;
28
+ /**
29
+ * Close the connection and the engine if this one was started by the node
30
+ * SDK.
31
+ */
32
+ close(): void;
33
+ }
34
+ /**
35
+ * Expose a default context for the global client
36
+ */
37
+ export declare const defaultContext: Context;
38
+ export {};
39
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../context/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,UAAU,aAAa;IACrB,MAAM,CAAC,EAAE,aAAa,CAAA;IACtB,UAAU,CAAC,EAAE,iBAAiB,CAAA;CAC/B;AAED;;;;;;;;;GASG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,OAAO,CAAC,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAC,CAAmB;gBAE3B,MAAM,CAAC,EAAE,aAAa;IAKlC;;;;OAIG;IACU,UAAU,CAAC,GAAG,GAAE,WAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAUtE;;;OAGG;IACI,KAAK,IAAI,IAAI;CAYrB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,SAAgB,CAAA"}
@@ -0,0 +1,51 @@
1
+ import { initDefaultContext } from "./builder.js";
2
+ /**
3
+ * Context abstracts the connection to the engine.
4
+ *
5
+ * It's required to implement the default global SDK.
6
+ * Its purpose is to store and returns the connection to the graphQL API, if
7
+ * no connection is set, it can create its own.
8
+ *
9
+ * This is also useful for lazy evaluation with the default global client,
10
+ * this one should only run the engine if it actually executes something.
11
+ */
12
+ export class Context {
13
+ _client;
14
+ _subProcess;
15
+ constructor(config) {
16
+ this._client = config?.client;
17
+ this._subProcess = config?.subProcess;
18
+ }
19
+ /**
20
+ * Returns a GraphQL client connected to the engine.
21
+ *
22
+ * If no client is set, it will create one.
23
+ */
24
+ async connection(cfg = {}) {
25
+ if (!this._client) {
26
+ const defaultCtx = await initDefaultContext(cfg);
27
+ this._client = defaultCtx._client;
28
+ this._subProcess = defaultCtx._subProcess;
29
+ }
30
+ return this._client;
31
+ }
32
+ /**
33
+ * Close the connection and the engine if this one was started by the node
34
+ * SDK.
35
+ */
36
+ close() {
37
+ if (this._subProcess) {
38
+ this._subProcess.kill("SIGTERM", {
39
+ // Set a long timeout to give time for any cache exports to pack layers up
40
+ // which currently has to happen synchronously with the session.
41
+ forceKillAfterTimeout: 300000, // 5 mins
42
+ });
43
+ }
44
+ // Reset client, so it can restart a new connection if necessary
45
+ this._client = undefined;
46
+ }
47
+ }
48
+ /**
49
+ * Expose a default context for the global client
50
+ */
51
+ export const defaultContext = new Context();
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../../entrypoint/entrypoint.ts"],"names":[],"mappings":""}
@@ -0,0 +1,70 @@
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 { listFiles } from "../introspector/utils/files.js";
6
+ import { invoke } from "./invoke.js";
7
+ import { load, loadArg } from "./load.js";
8
+ import { register } from "./register.js";
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+ const moduleSrcDirectory = `${__dirname}/../../src/`;
12
+ async function entrypoint() {
13
+ // Pre list all files of the modules since we need it either for a registration
14
+ // or an invocation
15
+ const files = await listFiles(moduleSrcDirectory);
16
+ // Start a Dagger session to get the call context
17
+ await connection(async () => {
18
+ const fnCall = dag.currentFunctionCall();
19
+ const parentName = await fnCall.parentName();
20
+ // Pre allocate the result, we got one in both case.
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ let result;
23
+ if (parentName === "") {
24
+ // It's a registration, we register the module and assign the module id
25
+ // to the result
26
+ result = await register(files);
27
+ }
28
+ else {
29
+ // Invocation
30
+ const fnName = await fnCall.name();
31
+ const parentJson = JSON.parse(await fnCall.parent());
32
+ const fnArgs = await fnCall.inputArgs();
33
+ const args = {};
34
+ const parentArgs = {};
35
+ for (const arg of fnArgs) {
36
+ args[await arg.name()] = await loadArg(await arg.value());
37
+ }
38
+ if (parentJson) {
39
+ for (const [key, value] of Object.entries(parentJson)) {
40
+ parentArgs[key] = await loadArg(value);
41
+ }
42
+ }
43
+ await load(files);
44
+ result = await invoke(parentName, fnName, parentArgs, args);
45
+ // Load ID if it's a Dagger type with an id
46
+ if (typeof result?.id === "function") {
47
+ result = await result.id();
48
+ }
49
+ // Load its field ID if there are
50
+ if (typeof result === "object") {
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ for (const [key, value] of Object.entries(result)) {
53
+ if (value.id && typeof value.id === "function") {
54
+ result[key] = await value.id();
55
+ }
56
+ }
57
+ }
58
+ }
59
+ // If result is set, we stringify it
60
+ if (result !== undefined && result !== null) {
61
+ result = JSON.stringify(result);
62
+ }
63
+ else {
64
+ result = "null";
65
+ }
66
+ // Send the result to Dagger
67
+ await fnCall.returnValue(result);
68
+ }, { LogOutput: process.stdout });
69
+ }
70
+ entrypoint();
@@ -0,0 +1,11 @@
1
+ import { Args, State } from "../introspector/registry/registry.js";
2
+ /**
3
+ * A wrapper around the registry to invoke a function.
4
+ *
5
+ * @param objectName – The class to look for
6
+ * @param methodName – The method to call in the class
7
+ * @param state – The current state of the class
8
+ * @param inputs – The input to send to the method to call
9
+ */
10
+ export declare function invoke(objectName: string, methodName: string, state: State, inputs: Args): Promise<any>;
11
+ //# sourceMappingURL=invoke.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../entrypoint/invoke.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,KAAK,EAAE,MAAM,sCAAsC,CAAA;AAE5E;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAC1B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,IAAI,GAEX,OAAO,CAAC,GAAG,CAAC,CAEd"}
@@ -0,0 +1,14 @@
1
+ import { registry } from "../introspector/registry/registry.js";
2
+ /**
3
+ * A wrapper around the registry to invoke a function.
4
+ *
5
+ * @param objectName – The class to look for
6
+ * @param methodName – The method to call in the class
7
+ * @param state – The current state of the class
8
+ * @param inputs – The input to send to the method to call
9
+ */
10
+ export async function invoke(objectName, methodName, state, inputs
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ ) {
13
+ return await registry.getResult(objectName, methodName, state, inputs);
14
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Import all given typescript files so that trigger their decorators
3
+ * and register their class and functions inside the Registry.
4
+ *
5
+ * @param files List of files to load.
6
+ */
7
+ export declare function load(files: string[]): Promise<void>;
8
+ /**
9
+ * Load argument as Dagger type.
10
+ *
11
+ * This function remove the quote from the identifier and checks
12
+ * if it's a Dagger type, if it is, it loads it according to
13
+ * its type.
14
+ */
15
+ export declare function loadArg(value: string): Promise<any>;
16
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../entrypoint/load.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED;;;;;;GAMG;AAEH,wBAAsB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CA8BzD"}
@@ -0,0 +1,44 @@
1
+ import { dag } from "../api/client.gen.js";
2
+ /**
3
+ * Import all given typescript files so that trigger their decorators
4
+ * and register their class and functions inside the Registry.
5
+ *
6
+ * @param files List of files to load.
7
+ */
8
+ export async function load(files) {
9
+ await Promise.all(files.map(async (f) => await import(f)));
10
+ }
11
+ /**
12
+ * Load argument as Dagger type.
13
+ *
14
+ * This function remove the quote from the identifier and checks
15
+ * if it's a Dagger type, if it is, it loads it according to
16
+ * its type.
17
+ */
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ export async function loadArg(value) {
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ let parsedValue;
22
+ const isString = () => (value.startsWith('"') && value.endsWith('"')) ||
23
+ (value.startsWith(`'`) && value.endsWith(`'`));
24
+ const isArray = () => value.startsWith("[") && value.endsWith("]");
25
+ // Apply JSON parse to parse array or string if the value is wrapped into a string or array
26
+ if (isString() || isArray()) {
27
+ parsedValue = JSON.parse(value);
28
+ }
29
+ else {
30
+ parsedValue = value;
31
+ }
32
+ // If it's a string, it might contain an identifier to load ,or it might be a hidden array
33
+ if (typeof parsedValue === "string") {
34
+ const [source] = parsedValue.split(":");
35
+ const [origin, type] = source.split(".");
36
+ if (origin === "core") {
37
+ // Workaround to call get any object that has an id
38
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
39
+ // @ts-ignore
40
+ return dag[`load${type}FromID`](parsedValue);
41
+ }
42
+ }
43
+ return parsedValue;
44
+ }
@@ -0,0 +1,6 @@
1
+ import { ModuleID } from "../api/client.gen";
2
+ /**
3
+ * Register the module files and returns its ID
4
+ */
5
+ export declare function register(files: string[]): Promise<ModuleID>;
6
+ //# 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,mBAAmB,CAAA;AAW1B;;GAEG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoCjE"}
@@ -0,0 +1,93 @@
1
+ import { dag, TypeDefKind, } from "../api/client.gen";
2
+ import { scan } from "../introspector/scanner/scan.js";
3
+ /**
4
+ * Register the module files and returns its ID
5
+ */
6
+ export async function register(files) {
7
+ // Scan all files
8
+ const scanResult = await scan(files);
9
+ // Get the current module
10
+ let mod = dag.currentModule();
11
+ // For each class scanned, register its type, method and properties in the module.
12
+ scanResult.classes.forEach((modClass) => {
13
+ // Register the class Typedef object in Dagger
14
+ let typeDef = dag.typeDef().withObject(modClass.name, {
15
+ description: modClass.description,
16
+ });
17
+ // Register all functions (methods) to this object
18
+ modClass.methods.forEach((method) => {
19
+ typeDef = typeDef.withFunction(addFunction(method));
20
+ });
21
+ // Register all fields that belong to this object
22
+ modClass.fields.forEach((field) => {
23
+ typeDef = typeDef.withField(field.name, addTypeDef(field.typeDef), {
24
+ description: field.description,
25
+ });
26
+ });
27
+ if (modClass.constructor) {
28
+ typeDef.withConstructor(addConstructor(modClass.constructor, typeDef));
29
+ }
30
+ // Add it to the module object
31
+ mod = mod.withObject(typeDef);
32
+ });
33
+ // Call ID to actually execute the registration
34
+ return await mod.id();
35
+ }
36
+ /**
37
+ * Bind a constructor to the given object.
38
+ */
39
+ function addConstructor(constructor, owner) {
40
+ return dag.function_("", owner).with(addArg(constructor.args));
41
+ }
42
+ /**
43
+ * Create a function in the Dagger API.
44
+ */
45
+ function addFunction(fct) {
46
+ return dag
47
+ .function_(fct.name, addTypeDef(fct.returnType))
48
+ .withDescription(fct.description)
49
+ .with(addArg(fct.args));
50
+ }
51
+ /**
52
+ * Register all arguments in the function.
53
+ */
54
+ function addArg(args) {
55
+ return function (fct) {
56
+ args.forEach((arg) => {
57
+ const opts = {
58
+ description: arg.description,
59
+ };
60
+ if (arg.defaultValue) {
61
+ opts.defaultValue = arg.defaultValue;
62
+ }
63
+ let typeDef = addTypeDef(arg.typeDef);
64
+ if (arg.optional) {
65
+ typeDef = typeDef.withOptional(true);
66
+ }
67
+ fct = fct.withArg(arg.name, typeDef, opts);
68
+ });
69
+ return fct;
70
+ };
71
+ }
72
+ /**
73
+ * Wrapper around TypeDef to return the right Dagger TypesDef with its options.
74
+ *
75
+ * This function only convert the Typedef into correct dagger call
76
+ * but, it's up to function above with more context to add documentation,
77
+ * define if it's an optional value or its default's.
78
+ *
79
+ * We cannot do it there because the Typedef can come from any source:
80
+ * a field, a param, a return value etc...
81
+ */
82
+ function addTypeDef(type) {
83
+ switch (type.kind) {
84
+ case TypeDefKind.Objectkind:
85
+ return dag.typeDef().withObject(type.name);
86
+ case TypeDefKind.Listkind:
87
+ return dag.typeDef().withListOf(addTypeDef(type.typeDef));
88
+ case TypeDefKind.Voidkind:
89
+ return dag.typeDef().withKind(type.kind).withOptional(true);
90
+ default:
91
+ return dag.typeDef().withKind(type.kind);
92
+ }
93
+ }
@@ -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":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAM1E"}
@@ -0,0 +1,8 @@
1
+ import { GraphQLClient } from "graphql-request";
2
+ export function createGQLClient(port, token) {
3
+ return new GraphQLClient(`http://127.0.0.1:${port}/query`, {
4
+ headers: {
5
+ Authorization: "Basic " + Buffer.from(token + ":").toString("base64"),
6
+ },
7
+ });
8
+ }
package/dist/index.d.ts CHANGED
@@ -2,5 +2,7 @@ export * from "./api/client.gen.js";
2
2
  export * from "./common/errors/index.js";
3
3
  export { gql } from "graphql-tag";
4
4
  export { GraphQLClient } from "graphql-request";
5
- export { connect, ConnectOpts, CallbackFct } from "./connect.js";
5
+ export { connect, CallbackFct, connection, close } from "./connect.js";
6
+ export { ConnectOpts } from "./connectOpts.js";
7
+ export * from "./introspector/decorators/decorators.js";
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,cAAc,yCAAyC,CAAA"}
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@ export * from "./api/client.gen.js";
2
2
  export * from "./common/errors/index.js";
3
3
  export { gql } from "graphql-tag";
4
4
  export { GraphQLClient } from "graphql-request";
5
- export { connect } from "./connect.js";
5
+ export { connect, connection, close } from "./connect.js";
6
+ export * from "./introspector/decorators/decorators.js";
@@ -0,0 +1,4 @@
1
+ export declare const object: <T extends import("../registry/registry.js").Class>(constructor: T) => T;
2
+ export declare const func: (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
3
+ export declare const field: (target: object, propertyKey: string) => void;
4
+ //# sourceMappingURL=decorators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../introspector/decorators/decorators.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,0EAAkB,CAAA;AACrC,eAAO,MAAM,IAAI,wFAAgB,CAAA;AACjC,eAAO,MAAM,KAAK,+CAAiB,CAAA"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Expose the decorator publicly, so they insert data into the global registry.
3
+ */
4
+ import { registry } from "../registry/registry.js";
5
+ export const object = registry.object;
6
+ export const func = registry.func;
7
+ export const field = registry.field;
@@ -0,0 +1,65 @@
1
+ export type Class = {
2
+ new (...args: any[]): any;
3
+ };
4
+ export type State = {
5
+ [property: string]: any;
6
+ };
7
+ export type Args = Record<string, unknown>;
8
+ /**
9
+ * Registry stores class and method that have the @object decorator.
10
+ *
11
+ * This is a convenient way to make possible the invocation of class' function.
12
+ *
13
+ * The decorator @object store the class into the Registry, but also all the
14
+ * users method's name.
15
+ * It doesn't consider the `@func` or `field` decorators because this is
16
+ * used by the Dagger API to know what to expose or not.
17
+ * This might lead to unnecessary data register into the registry, but
18
+ * we use map as datastructure to optimize the searching process
19
+ * since we directly look through a key into the `class_` member of
20
+ * RegistryClass.
21
+ */
22
+ export declare class Registry {
23
+ private classes;
24
+ /**
25
+ * The definition of the @object decorator that should be on top of any
26
+ * class module that must be exposed to the Dagger API.
27
+ *
28
+ */
29
+ object: <T extends Class>(constructor: T) => T;
30
+ /**
31
+ * The definition of @field decorator that should be on top of any
32
+ * class' property that must be exposed to the Dagger API.
33
+ */
34
+ field: (target: object, propertyKey: string) => void;
35
+ /**
36
+ * The definition of @func decorator that should be on top of any
37
+ * class' method that must be exposed to the Dagger API.
38
+ */
39
+ func: (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
40
+ /**
41
+ * getResult check for the object and method in the registry and call it
42
+ * with the given input and state.
43
+ *
44
+ * This is the function responsible for any module methods execution.
45
+ *
46
+ * @param object The class to look for
47
+ * @param method The method to call in the class
48
+ * @param state The current state of the class
49
+ * @param inputs The input to send to the method to call
50
+ */
51
+ getResult(object: string, method: string, state: State, inputs: Args): Promise<any>;
52
+ /**
53
+ * Get the order of argument by reading its content and create an array of its argument
54
+ * We cannot use r[method].prototype because it can be empty depending on the loading.
55
+ * Note(TomChv): This is a workaround until we find something more accurate.
56
+ * @param fct
57
+ * @private
58
+ */
59
+ private getArgOrder;
60
+ }
61
+ /**
62
+ * The default registry used in any module.
63
+ */
64
+ export declare const registry: Registry;
65
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../introspector/registry/registry.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,KAAK,GAAG;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,CAAA;AAGjD,MAAM,MAAM,KAAK,GAAG;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAA;AAE/C,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAa1C;;;;;;;;;;;;;GAaG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAoB;IAEnC;;;;OAIG;IACH,MAAM,yCA4BL;IAED;;;OAGG;IAEH,KAAK,WAAY,MAAM,eAAe,MAAM,UAE3C;IAED;;;OAGG;IACH,IAAI,WAEM,MAAM,eAED,MAAM,GAAG,MAAM,cAEhB,kBAAkB,UAK/B;IAED;;;;;;;;;;OAUG;IACG,SAAS,CACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,IAAI,GAEX,OAAO,CAAC,GAAG,CAAC;IAwCf;;;;;;OAMG;IAEH,OAAO,CAAC,WAAW;CAWpB;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,UAAiB,CAAA"}