@dagger.io/dagger 0.9.2 → 0.9.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 (79) hide show
  1. package/dist/api/client.gen.d.ts +283 -275
  2. package/dist/api/client.gen.d.ts.map +1 -1
  3. package/dist/api/client.gen.js +1656 -1874
  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 +48 -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 +32 -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 +91 -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 +117 -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 +1 -1
package/dist/api/utils.js CHANGED
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
11
2
  import { ClientError, gql } from "graphql-request";
12
3
  import { GraphQLRequestError, TooManyNestedObjectsError, UnknownDaggerError, NotAwaitedRequestError, ExecError, } from "../common/errors/index.js";
@@ -17,9 +8,8 @@ function buildArgs(args) {
17
8
  const metadata = args.__metadata || {};
18
9
  // Remove unwanted quotes
19
10
  const formatValue = (key, value) => {
20
- var _a;
21
11
  // Special treatment for enumeration, they must be inserted without quotes
22
- if ((_a = metadata[key]) === null || _a === void 0 ? void 0 : _a.is_enum) {
12
+ if (metadata[key]?.is_enum) {
23
13
  return JSON.stringify(value).replace(/['"]+/g, "");
24
14
  }
25
15
  return JSON.stringify(value).replace(/\{"[a-zA-Z]+":|,"[a-zA-Z]+":/gi, (str) => {
@@ -48,51 +38,49 @@ function buildArgs(args) {
48
38
  * Find QueryTree, convert them into GraphQl query
49
39
  * then compute and return the result to the appropriate field
50
40
  */
51
- function computeNestedQuery(query, client) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- // Check if there is a nested queryTree to be executed
54
- const isQueryTree = (value) => value["_queryTree"] !== undefined;
55
- // Check if there is a nested array of queryTree to be executed
56
- const isArrayQueryTree = (value) => value.every((v) => v instanceof Object && isQueryTree(v));
57
- // Prepare query tree for final query by computing nested queries
58
- // and building it with their results.
59
- const computeQueryTree = (value) => __awaiter(this, void 0, void 0, function* () {
60
- // Resolve sub queries if operation's args is a subquery
61
- for (const op of value["_queryTree"]) {
62
- yield computeNestedQuery([op], client);
41
+ async function computeNestedQuery(query, client) {
42
+ // Check if there is a nested queryTree to be executed
43
+ const isQueryTree = (value) => value["_queryTree"] !== undefined;
44
+ // Check if there is a nested array of queryTree to be executed
45
+ const isArrayQueryTree = (value) => value.every((v) => v instanceof Object && isQueryTree(v));
46
+ // Prepare query tree for final query by computing nested queries
47
+ // and building it with their results.
48
+ const computeQueryTree = async (value) => {
49
+ // Resolve sub queries if operation's args is a subquery
50
+ for (const op of value["_queryTree"]) {
51
+ await computeNestedQuery([op], client);
52
+ }
53
+ // push an id that will be used by the container
54
+ return buildQuery([
55
+ ...value["_queryTree"],
56
+ {
57
+ operation: "id",
58
+ },
59
+ ]);
60
+ };
61
+ // Remove all undefined args and assert args type
62
+ const queryToExec = query.filter((q) => !!q.args);
63
+ for (const q of queryToExec) {
64
+ await Promise.all(
65
+ // Compute nested query for single object
66
+ Object.entries(q.args).map(async ([key, value]) => {
67
+ if (value instanceof Object && isQueryTree(value)) {
68
+ // push an id that will be used by the container
69
+ const getQueryTree = await computeQueryTree(value);
70
+ q.args[key] = await compute(getQueryTree, client);
63
71
  }
64
- // push an id that will be used by the container
65
- return buildQuery([
66
- ...value["_queryTree"],
67
- {
68
- operation: "id",
69
- },
70
- ]);
71
- });
72
- // Remove all undefined args and assert args type
73
- const queryToExec = query.filter((q) => !!q.args);
74
- for (const q of queryToExec) {
75
- yield Promise.all(
76
- // Compute nested query for single object
77
- Object.entries(q.args).map(([key, value]) => __awaiter(this, void 0, void 0, function* () {
78
- if (value instanceof Object && isQueryTree(value)) {
72
+ // Compute nested query for array of object
73
+ if (Array.isArray(value) && isArrayQueryTree(value)) {
74
+ const tmp = q.args[key];
75
+ for (let i = 0; i < value.length; i++) {
79
76
  // push an id that will be used by the container
80
- const getQueryTree = yield computeQueryTree(value);
81
- q.args[key] = yield compute(getQueryTree, client);
82
- }
83
- // Compute nested query for array of object
84
- if (Array.isArray(value) && isArrayQueryTree(value)) {
85
- const tmp = q.args[key];
86
- for (let i = 0; i < value.length; i++) {
87
- // push an id that will be used by the container
88
- const getQueryTree = yield computeQueryTree(value[i]);
89
- tmp[i] = yield compute(getQueryTree, client);
90
- }
91
- q.args[key] = tmp;
77
+ const getQueryTree = await computeQueryTree(value[i]);
78
+ tmp[i] = await compute(getQueryTree, client);
92
79
  }
93
- })));
94
- }
95
- });
80
+ q.args[key] = tmp;
81
+ }
82
+ }));
83
+ }
96
84
  }
97
85
  /**
98
86
  * Convert the queryTree into a GraphQL query
@@ -113,12 +101,10 @@ export function buildQuery(q) {
113
101
  * @param client | GraphQLClient
114
102
  * @returns
115
103
  */
116
- export function computeQuery(q, client) {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- yield computeNestedQuery(q, client);
119
- const query = buildQuery(q);
120
- return yield compute(query, client);
121
- });
104
+ export async function computeQuery(q, client) {
105
+ await computeNestedQuery(q, client);
106
+ const query = buildQuery(q);
107
+ return await compute(query, client);
122
108
  }
123
109
  /**
124
110
  * Return a Graphql query result flattened
@@ -145,40 +131,37 @@ export function queryFlatten(response) {
145
131
  * return a flatten result
146
132
  * @hidden
147
133
  */
148
- export function compute(query, client) {
149
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
150
- return __awaiter(this, void 0, void 0, function* () {
151
- let computeQuery;
152
- try {
153
- computeQuery = yield client.request(gql `
134
+ export async function compute(query, client) {
135
+ let computeQuery;
136
+ try {
137
+ computeQuery = await client.request(gql `
154
138
  ${query}
155
139
  `);
156
- }
157
- catch (e) {
158
- if (e instanceof ClientError) {
159
- const msg = (_c = (_b = (_a = e.response.errors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : `API Error`;
160
- const ext = (_e = (_d = e.response.errors) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.extensions;
161
- if ((ext === null || ext === void 0 ? void 0 : ext._type) === "EXEC_ERROR") {
162
- throw new ExecError(msg, {
163
- cmd: (_f = ext.cmd) !== null && _f !== void 0 ? _f : [],
164
- exitCode: (_g = ext.exitCode) !== null && _g !== void 0 ? _g : -1,
165
- stdout: (_h = ext.stdout) !== null && _h !== void 0 ? _h : "",
166
- stderr: (_j = ext.stderr) !== null && _j !== void 0 ? _j : "",
167
- });
168
- }
169
- throw new GraphQLRequestError(msg, {
170
- request: e.request,
171
- response: e.response,
172
- cause: e,
140
+ }
141
+ catch (e) {
142
+ if (e instanceof ClientError) {
143
+ const msg = e.response.errors?.[0]?.message ?? `API Error`;
144
+ const ext = e.response.errors?.[0]?.extensions;
145
+ if (ext?._type === "EXEC_ERROR") {
146
+ throw new ExecError(msg, {
147
+ cmd: ext.cmd ?? [],
148
+ exitCode: ext.exitCode ?? -1,
149
+ stdout: ext.stdout ?? "",
150
+ stderr: ext.stderr ?? "",
173
151
  });
174
152
  }
175
- // Looking for connection error in case the function has not been awaited.
176
- if (e.errno === "ECONNREFUSED") {
177
- throw new NotAwaitedRequestError("Encountered an error while requesting data via graphql through a synchronous call. Make sure the function called is awaited.", { cause: e });
178
- }
179
- // Just throw the unknown error
180
- throw new UnknownDaggerError("Encountered an unknown error while requesting data via graphql", { cause: e });
153
+ throw new GraphQLRequestError(msg, {
154
+ request: e.request,
155
+ response: e.response,
156
+ cause: e,
157
+ });
158
+ }
159
+ // Looking for connection error in case the function has not been awaited.
160
+ if (e.errno === "ECONNREFUSED") {
161
+ throw new NotAwaitedRequestError("Encountered an error while requesting data via graphql through a synchronous call. Make sure the function called is awaited.", { cause: e });
181
162
  }
182
- return queryFlatten(computeQuery);
183
- });
163
+ // Just throw the unknown error
164
+ throw new UnknownDaggerError("Encountered an unknown error while requesting data via graphql", { cause: e });
165
+ }
166
+ return queryFlatten(computeQuery);
184
167
  }
@@ -3,9 +3,13 @@ import { log } from "../utils.js";
3
3
  * The base error. Every other error inherits this error.
4
4
  */
5
5
  export class DaggerSDKError extends Error {
6
+ /**
7
+ * The original error, which caused the DaggerSDKError.
8
+ */
9
+ cause;
6
10
  constructor(message, options) {
7
11
  super(message);
8
- this.cause = options === null || options === void 0 ? void 0 : options.cause;
12
+ this.cause = options?.cause;
9
13
  }
10
14
  /**
11
15
  * @hidden
@@ -5,13 +5,17 @@ import { ERROR_CODES, ERROR_NAMES } from "./errors-codes.js";
5
5
  * DockerImage constructor.
6
6
  */
7
7
  export class DockerImageRefValidationError extends DaggerSDKError {
8
+ name = ERROR_NAMES.DockerImageRefValidationError;
9
+ code = ERROR_CODES.DockerImageRefValidationError;
10
+ /**
11
+ * The docker image reference, which caused the error.
12
+ */
13
+ ref;
8
14
  /**
9
15
  * @hidden
10
16
  */
11
17
  constructor(message, options) {
12
18
  super(message, options);
13
- this.name = ERROR_NAMES.DockerImageRefValidationError;
14
- this.code = ERROR_CODES.DockerImageRefValidationError;
15
- this.ref = options === null || options === void 0 ? void 0 : options.ref;
19
+ this.ref = options?.ref;
16
20
  }
17
21
  }
@@ -4,13 +4,17 @@ import { ERROR_CODES, ERROR_NAMES } from "./errors-codes.js";
4
4
  * This error is thrown if the EngineSession does not manage to parse the required connection parameters from the session binary
5
5
  */
6
6
  export class EngineSessionConnectParamsParseError extends DaggerSDKError {
7
+ name = ERROR_NAMES.EngineSessionConnectParamsParseError;
8
+ code = ERROR_CODES.EngineSessionConnectParamsParseError;
9
+ /**
10
+ * the line, which caused the error during parsing, if the error was caused because of parsing.
11
+ */
12
+ parsedLine;
7
13
  /**
8
14
  * @hidden
9
15
  */
10
16
  constructor(message, options) {
11
17
  super(message, options);
12
- this.name = ERROR_NAMES.EngineSessionConnectParamsParseError;
13
- this.code = ERROR_CODES.EngineSessionConnectParamsParseError;
14
18
  this.parsedLine = options.parsedLine;
15
19
  }
16
20
  }
@@ -4,13 +4,17 @@ import { ERROR_CODES, ERROR_NAMES } from "./errors-codes.js";
4
4
  * This error is thrown if the EngineSession does not manage to parse the required port successfully because the sessions connection timed out.
5
5
  */
6
6
  export class EngineSessionConnectionTimeoutError extends DaggerSDKError {
7
+ name = ERROR_NAMES.EngineSessionConnectionTimeoutError;
8
+ code = ERROR_CODES.EngineSessionConnectionTimeoutError;
9
+ /**
10
+ * The duration until the timeout occurred in ms.
11
+ */
12
+ timeOutDuration;
7
13
  /**
8
14
  * @hidden
9
15
  */
10
16
  constructor(message, options) {
11
17
  super(message, options);
12
- this.name = ERROR_NAMES.EngineSessionConnectionTimeoutError;
13
- this.code = ERROR_CODES.EngineSessionConnectionTimeoutError;
14
18
  this.timeOutDuration = options.timeOutDuration;
15
19
  }
16
20
  }
@@ -5,12 +5,12 @@ import { ERROR_CODES, ERROR_NAMES } from "./errors-codes.js";
5
5
  * This usually happens if no connection can be established.
6
6
  */
7
7
  export class EngineSessionError extends DaggerSDKError {
8
+ name = ERROR_NAMES.EngineSessionError;
9
+ code = ERROR_CODES.EngineSessionError;
8
10
  /**
9
11
  * @hidden
10
12
  */
11
13
  constructor(message, options) {
12
14
  super(message, options);
13
- this.name = ERROR_NAMES.EngineSessionError;
14
- this.code = ERROR_CODES.EngineSessionError;
15
15
  }
16
16
  }
@@ -4,13 +4,29 @@ import { ERROR_CODES, ERROR_NAMES } from "./errors-codes.js";
4
4
  * API error from an exec operation in a pipeline.
5
5
  */
6
6
  export class ExecError extends DaggerSDKError {
7
+ name = ERROR_NAMES.ExecError;
8
+ code = ERROR_CODES.ExecError;
9
+ /**
10
+ * The command that caused the error.
11
+ */
12
+ cmd;
13
+ /**
14
+ * The exit code of the command.
15
+ */
16
+ exitCode;
17
+ /**
18
+ * The stdout of the command.
19
+ */
20
+ stdout;
21
+ /**
22
+ * The stderr of the command.
23
+ */
24
+ stderr;
7
25
  /**
8
26
  * @hidden
9
27
  */
10
28
  constructor(message, options) {
11
29
  super(message, options);
12
- this.name = ERROR_NAMES.ExecError;
13
- this.code = ERROR_CODES.ExecError;
14
30
  this.cmd = options.cmd;
15
31
  this.exitCode = options.exitCode;
16
32
  this.stdout = options.stdout;
@@ -4,13 +4,21 @@ import { ERROR_CODES, ERROR_NAMES } from "./errors-codes.js";
4
4
  * This error originates from the dagger engine. It means that some error was thrown and sent back via GraphQL.
5
5
  */
6
6
  export class GraphQLRequestError extends DaggerSDKError {
7
+ name = ERROR_NAMES.GraphQLRequestError;
8
+ code = ERROR_CODES.GraphQLRequestError;
9
+ /**
10
+ * The query and variables, which caused the error.
11
+ */
12
+ requestContext;
13
+ /**
14
+ * the GraphQL response containing the error.
15
+ */
16
+ response;
7
17
  /**
8
18
  * @hidden
9
19
  */
10
20
  constructor(message, options) {
11
21
  super(message, options);
12
- this.name = ERROR_NAMES.GraphQLRequestError;
13
- this.code = ERROR_CODES.GraphQLRequestError;
14
22
  this.requestContext = options.request;
15
23
  this.response = options.response;
16
24
  }
@@ -4,12 +4,12 @@ import { ERROR_CODES, ERROR_NAMES } from "./errors-codes.js";
4
4
  * This error is thrown if the dagger binary cannot be copied from the dagger docker image and copied to the local host.
5
5
  */
6
6
  export class InitEngineSessionBinaryError extends DaggerSDKError {
7
+ name = ERROR_NAMES.InitEngineSessionBinaryError;
8
+ code = ERROR_CODES.InitEngineSessionBinaryError;
7
9
  /**
8
10
  * @hidden
9
11
  */
10
12
  constructor(message, options) {
11
13
  super(message, options);
12
- this.name = ERROR_NAMES.InitEngineSessionBinaryError;
13
- this.code = ERROR_CODES.InitEngineSessionBinaryError;
14
14
  }
15
15
  }
@@ -4,12 +4,12 @@ import { ERROR_CODES, ERROR_NAMES } from "./errors-codes.js";
4
4
  * This error is thrown when the compute function isn't awaited.
5
5
  */
6
6
  export class NotAwaitedRequestError extends DaggerSDKError {
7
+ name = ERROR_NAMES.NotAwaitedRequestError;
8
+ code = ERROR_CODES.NotAwaitedRequestError;
7
9
  /**
8
10
  * @hidden
9
11
  */
10
12
  constructor(message, options) {
11
13
  super(message, options);
12
- this.name = ERROR_NAMES.NotAwaitedRequestError;
13
- this.code = ERROR_CODES.NotAwaitedRequestError;
14
14
  }
15
15
  }
@@ -4,13 +4,17 @@ import { ERROR_CODES, ERROR_NAMES } from "./errors-codes.js";
4
4
  * Dagger only expects one response value from the engine. If the engine returns more than one value this error is thrown.
5
5
  */
6
6
  export class TooManyNestedObjectsError extends DaggerSDKError {
7
+ name = ERROR_NAMES.TooManyNestedObjectsError;
8
+ code = ERROR_CODES.TooManyNestedObjectsError;
9
+ /**
10
+ * the response containing more than one value.
11
+ */
12
+ response;
7
13
  /**
8
14
  * @hidden
9
15
  */
10
16
  constructor(message, options) {
11
17
  super(message, options);
12
- this.name = ERROR_NAMES.TooManyNestedObjectsError;
13
- this.code = ERROR_CODES.TooManyNestedObjectsError;
14
18
  this.response = options.response;
15
19
  }
16
20
  }
@@ -4,12 +4,12 @@ import { ERROR_CODES, ERROR_NAMES } from "./errors-codes.js";
4
4
  * This error is thrown if the dagger SDK does not identify the error and just wraps the cause.
5
5
  */
6
6
  export class UnknownDaggerError extends DaggerSDKError {
7
+ name = ERROR_NAMES.UnknownDaggerError;
8
+ code = ERROR_CODES.UnknownDaggerError;
7
9
  /**
8
10
  * @hidden
9
11
  */
10
12
  constructor(message, options) {
11
13
  super(message, options);
12
- this.name = ERROR_NAMES.UnknownDaggerError;
13
- this.code = ERROR_CODES.UnknownDaggerError;
14
14
  }
15
15
  }
@@ -40,4 +40,4 @@ export const ERROR_CODES = {
40
40
  */
41
41
  ExecError: "D109",
42
42
  };
43
- export const ERROR_NAMES = Object.keys(ERROR_CODES).reduce((obj, item) => (Object.assign(Object.assign({}, obj), { [item]: item })), {});
43
+ export const ERROR_NAMES = Object.keys(ERROR_CODES).reduce((obj, item) => ({ ...obj, [item]: item }), {});
@@ -10,8 +10,8 @@ export declare const log: (stack?: string) => {
10
10
  isLevelValid(level: "error" | "debug" | "info" | "warn" | "disable" | "success"): boolean;
11
11
  isAllowedLevel(level: "error" | "debug" | "info" | "warn" | "disable" | "success"): boolean;
12
12
  checkSetting(setting: {
13
- reverse?: boolean | undefined;
14
13
  bold?: boolean | undefined;
14
+ reverse?: boolean | undefined;
15
15
  italic?: boolean | undefined;
16
16
  dim?: boolean | undefined;
17
17
  underscore?: boolean | undefined;
@@ -29,16 +29,16 @@ export declare const log: (stack?: string) => {
29
29
  reverse(): any;
30
30
  italic(): any;
31
31
  fontColorLog(ticket: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white", text: string, setting?: {
32
- reverse?: boolean | undefined;
33
32
  bold?: boolean | undefined;
33
+ reverse?: boolean | undefined;
34
34
  italic?: boolean | undefined;
35
35
  dim?: boolean | undefined;
36
36
  underscore?: boolean | undefined;
37
37
  strikethrough?: boolean | undefined;
38
38
  } | undefined): void;
39
39
  bgColorLog(ticket: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white", text: string, setting?: {
40
- reverse?: boolean | undefined;
41
40
  bold?: boolean | undefined;
41
+ reverse?: boolean | undefined;
42
42
  italic?: boolean | undefined;
43
43
  dim?: boolean | undefined;
44
44
  underscore?: boolean | undefined;
@@ -48,8 +48,8 @@ export declare const log: (stack?: string) => {
48
48
  font?: ("black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white") | undefined;
49
49
  bg?: ("black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white") | undefined;
50
50
  }, text: string, setting?: {
51
- reverse?: boolean | undefined;
52
51
  bold?: boolean | undefined;
52
+ reverse?: boolean | undefined;
53
53
  italic?: boolean | undefined;
54
54
  dim?: boolean | undefined;
55
55
  underscore?: boolean | undefined;
package/dist/connect.d.ts CHANGED
@@ -1,33 +1,28 @@
1
- /// <reference types="node" />
2
- import { Writable } from "node:stream";
3
1
  import { Client } from "./api/client.gen.js";
2
+ import { ConnectOpts } from "./connectOpts.js";
3
+ export type CallbackFct = (client: Client) => Promise<void>;
4
4
  /**
5
- * ConnectOpts defines option used to connect to an engine.
5
+ * connection executes the given function using the default global Dagger client.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * await connection(
10
+ * async () => {
11
+ * await dag
12
+ * .container()
13
+ * .from("alpine")
14
+ * .withExec(["apk", "add", "curl"])
15
+ * .withExec(["curl", "https://dagger.io/"])
16
+ * .sync()
17
+ * }, { LogOutput: process.stderr }
18
+ * )
19
+ * ```
6
20
  */
7
- export interface ConnectOpts {
8
- /**
9
- * Use to overwrite Dagger workdir
10
- * @defaultValue process.cwd()
11
- */
12
- Workdir?: string;
13
- /**
14
- * Enable logs output
15
- * @example
16
- * LogOutput
17
- * ```ts
18
- * connect(async (client: Client) => {
19
- const source = await client.host().workdir().id()
20
- ...
21
- }, {LogOutput: process.stdout})
22
- ```
23
- */
24
- LogOutput?: Writable;
25
- }
26
- export type CallbackFct = (client: Client) => Promise<void>;
27
- export interface ConnectParams {
28
- port: number;
29
- session_token: string;
30
- }
21
+ export declare function connection(fct: () => Promise<void>, cfg?: ConnectOpts): Promise<void>;
22
+ /**
23
+ * Close global client connection
24
+ */
25
+ export declare function close(): void;
31
26
  /**
32
27
  * connect runs GraphQL server and initializes a
33
28
  * GraphQL client to execute query on it through its callback.
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../connect.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAG5C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,QAAQ,CAAA;CACrB;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAE3D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,EAAE,EAAE,WAAW,EACf,MAAM,GAAE,WAAgB,GACvB,OAAO,CAAC,IAAI,CAAC,CA6Cf"}
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAI9C,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAE3D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACxB,GAAG,GAAE,WAAgB,iBAKtB;AAED;;GAEG;AACH,wBAAgB,KAAK,SAEpB;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,EAAE,EAAE,WAAW,EACf,MAAM,GAAE,WAAgB,GACvB,OAAO,CAAC,IAAI,CAAC,CAiBf"}
package/dist/connect.js CHANGED
@@ -1,57 +1,51 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { Client } from "./api/client.gen.js";
11
- import { Bin, CLI_VERSION } from "./provisioning/index.js";
2
+ import { Context, defaultContext } from "./context/context.js";
3
+ import { CLI_VERSION } from "./provisioning/index.js";
4
+ /**
5
+ * connection executes the given function using the default global Dagger client.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * await connection(
10
+ * async () => {
11
+ * await dag
12
+ * .container()
13
+ * .from("alpine")
14
+ * .withExec(["apk", "add", "curl"])
15
+ * .withExec(["curl", "https://dagger.io/"])
16
+ * .sync()
17
+ * }, { LogOutput: process.stderr }
18
+ * )
19
+ * ```
20
+ */
21
+ export async function connection(fct, cfg = {}) {
22
+ await defaultContext.connection(cfg);
23
+ await fct().finally(() => close());
24
+ }
25
+ /**
26
+ * Close global client connection
27
+ */
28
+ export function close() {
29
+ defaultContext.close();
30
+ }
12
31
  /**
13
32
  * connect runs GraphQL server and initializes a
14
33
  * GraphQL client to execute query on it through its callback.
15
34
  * This implementation is based on the existing Go SDK.
16
35
  */
17
- export function connect(cb, config = {}) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- let client;
20
- let close = null;
21
- // Prefer DAGGER_SESSION_PORT if set
22
- const daggerSessionPort = process.env["DAGGER_SESSION_PORT"];
23
- if (daggerSessionPort) {
24
- const sessionToken = process.env["DAGGER_SESSION_TOKEN"];
25
- if (!sessionToken) {
26
- throw new Error("DAGGER_SESSION_TOKEN must be set when using DAGGER_SESSION_PORT");
27
- }
28
- if (config.Workdir && config.Workdir !== "") {
29
- throw new Error("cannot configure workdir for existing session (please use --workdir or host.directory with absolute paths instead)");
30
- }
31
- client = new Client({
32
- host: `127.0.0.1:${daggerSessionPort}`,
33
- sessionToken: sessionToken,
34
- });
35
- }
36
- else {
37
- // Otherwise, prefer _EXPERIMENTAL_DAGGER_CLI_BIN, with fallback behavior of
38
- // downloading the CLI and using that as the bin.
39
- const cliBin = process.env["_EXPERIMENTAL_DAGGER_CLI_BIN"];
40
- const engineConn = new Bin(cliBin, CLI_VERSION);
41
- client = yield engineConn.Connect(config);
42
- close = () => engineConn.Close();
43
- }
44
- // Warning shall be throw if versions are not compatible
45
- try {
46
- yield client.checkVersionCompatibility(CLI_VERSION);
47
- }
48
- catch (e) {
49
- console.error("failed to check version compatibility:", e);
50
- }
51
- yield cb(client).finally(() => __awaiter(this, void 0, void 0, function* () {
52
- if (close) {
53
- close();
54
- }
55
- }));
36
+ export async function connect(cb, config = {}) {
37
+ const ctx = new Context();
38
+ const client = new Client({ ctx: ctx });
39
+ // Initialize connection
40
+ await ctx.connection(config);
41
+ // Warning shall be throw if versions are not compatible
42
+ try {
43
+ await client.checkVersionCompatibility(CLI_VERSION);
44
+ }
45
+ catch (e) {
46
+ console.error("failed to check version compatibility:", e);
47
+ }
48
+ await cb(client).finally(() => {
49
+ ctx.close();
56
50
  });
57
51
  }