@dagger.io/dagger 0.1.0 → 0.2.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.
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  step((generator = generator.apply(thisArg, _arguments || [])).next());
12
12
  });
13
13
  };
14
- import { GraphQLClient, gql } from "graphql-request";
15
- import { queryBuilder, queryFlatten } from "./utils.js";
14
+ import { GraphQLClient } from "graphql-request";
15
+ import { queryBuilder } from "./utils.js";
16
16
  class BaseClient {
17
17
  /**
18
18
  * @hidden
@@ -28,25 +28,6 @@ class BaseClient {
28
28
  get queryTree() {
29
29
  return this._queryTree;
30
30
  }
31
- /**
32
- * @hidden
33
- */
34
- _compute() {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- try {
37
- // run the query and return the result.
38
- const query = queryBuilder(this._queryTree);
39
- const computeQuery = yield this.client.request(gql `
40
- ${query}
41
- `);
42
- return queryFlatten(computeQuery);
43
- }
44
- catch (error) {
45
- console.error(JSON.stringify(error, undefined, 2));
46
- return {};
47
- }
48
- });
49
- }
50
31
  }
51
32
  /**
52
33
  * A directory whose contents persist across runs
@@ -60,7 +41,7 @@ export class CacheVolume extends BaseClient {
60
41
  operation: "id",
61
42
  },
62
43
  ];
63
- const response = yield this._compute();
44
+ const response = yield queryBuilder(this._queryTree, this.client);
64
45
  return response;
65
46
  });
66
47
  }
@@ -95,7 +76,7 @@ export class Container extends BaseClient {
95
76
  operation: "defaultArgs",
96
77
  },
97
78
  ];
98
- const response = yield this._compute();
79
+ const response = yield queryBuilder(this._queryTree, this.client);
99
80
  return response;
100
81
  });
101
82
  }
@@ -125,7 +106,7 @@ export class Container extends BaseClient {
125
106
  operation: "entrypoint",
126
107
  },
127
108
  ];
128
- const response = yield this._compute();
109
+ const response = yield queryBuilder(this._queryTree, this.client);
129
110
  return response;
130
111
  });
131
112
  }
@@ -141,7 +122,7 @@ export class Container extends BaseClient {
141
122
  args: { name },
142
123
  },
143
124
  ];
144
- const response = yield this._compute();
125
+ const response = yield queryBuilder(this._queryTree, this.client);
145
126
  return response;
146
127
  });
147
128
  }
@@ -156,12 +137,14 @@ export class Container extends BaseClient {
156
137
  operation: "envVariables",
157
138
  },
158
139
  ];
159
- const response = yield this._compute();
140
+ const response = yield queryBuilder(this._queryTree, this.client);
160
141
  return response;
161
142
  });
162
143
  }
163
144
  /**
164
145
  * This container after executing the specified command inside it
146
+ *
147
+ * @deprecated Replaced by withExec.
165
148
  */
166
149
  exec(args, stdin, redirectStdout, redirectStderr, experimentalPrivilegedNesting) {
167
150
  return new Container({
@@ -193,7 +176,7 @@ export class Container extends BaseClient {
193
176
  operation: "exitCode",
194
177
  },
195
178
  ];
196
- const response = yield this._compute();
179
+ const response = yield queryBuilder(this._queryTree, this.client);
197
180
  return response;
198
181
  });
199
182
  }
@@ -209,7 +192,7 @@ export class Container extends BaseClient {
209
192
  args: { path, platformVariants },
210
193
  },
211
194
  ];
212
- const response = yield this._compute();
195
+ const response = yield queryBuilder(this._queryTree, this.client);
213
196
  return response;
214
197
  });
215
198
  }
@@ -245,6 +228,8 @@ export class Container extends BaseClient {
245
228
  }
246
229
  /**
247
230
  * This container's root filesystem. Mounts are not included.
231
+ *
232
+ * @deprecated Replaced by rootfs.
248
233
  */
249
234
  fs() {
250
235
  return new Directory({
@@ -268,7 +253,7 @@ export class Container extends BaseClient {
268
253
  operation: "id",
269
254
  },
270
255
  ];
271
- const response = yield this._compute();
256
+ const response = yield queryBuilder(this._queryTree, this.client);
272
257
  return response;
273
258
  });
274
259
  }
@@ -283,7 +268,7 @@ export class Container extends BaseClient {
283
268
  operation: "mounts",
284
269
  },
285
270
  ];
286
- const response = yield this._compute();
271
+ const response = yield queryBuilder(this._queryTree, this.client);
287
272
  return response;
288
273
  });
289
274
  }
@@ -298,7 +283,7 @@ export class Container extends BaseClient {
298
283
  operation: "platform",
299
284
  },
300
285
  ];
301
- const response = yield this._compute();
286
+ const response = yield queryBuilder(this._queryTree, this.client);
302
287
  return response;
303
288
  });
304
289
  }
@@ -314,23 +299,38 @@ export class Container extends BaseClient {
314
299
  args: { address, platformVariants },
315
300
  },
316
301
  ];
317
- const response = yield this._compute();
302
+ const response = yield queryBuilder(this._queryTree, this.client);
318
303
  return response;
319
304
  });
320
305
  }
306
+ /**
307
+ * This container's root filesystem. Mounts are not included.
308
+ */
309
+ rootfs() {
310
+ return new Directory({
311
+ queryTree: [
312
+ ...this._queryTree,
313
+ {
314
+ operation: "rootfs",
315
+ },
316
+ ],
317
+ host: this.clientHost,
318
+ });
319
+ }
321
320
  /**
322
321
  * The error stream of the last executed command.
323
322
  * Null if no command has been executed.
324
323
  */
325
324
  stderr() {
326
- return new File({
327
- queryTree: [
325
+ return __awaiter(this, void 0, void 0, function* () {
326
+ this._queryTree = [
328
327
  ...this._queryTree,
329
328
  {
330
329
  operation: "stderr",
331
330
  },
332
- ],
333
- host: this.clientHost,
331
+ ];
332
+ const response = yield queryBuilder(this._queryTree, this.client);
333
+ return response;
334
334
  });
335
335
  }
336
336
  /**
@@ -338,14 +338,15 @@ export class Container extends BaseClient {
338
338
  * Null if no command has been executed.
339
339
  */
340
340
  stdout() {
341
- return new File({
342
- queryTree: [
341
+ return __awaiter(this, void 0, void 0, function* () {
342
+ this._queryTree = [
343
343
  ...this._queryTree,
344
344
  {
345
345
  operation: "stdout",
346
346
  },
347
- ],
348
- host: this.clientHost,
347
+ ];
348
+ const response = yield queryBuilder(this._queryTree, this.client);
349
+ return response;
349
350
  });
350
351
  }
351
352
  /**
@@ -359,7 +360,7 @@ export class Container extends BaseClient {
359
360
  operation: "user",
360
361
  },
361
362
  ];
362
- const response = yield this._compute();
363
+ const response = yield queryBuilder(this._queryTree, this.client);
363
364
  return response;
364
365
  });
365
366
  }
@@ -408,8 +409,31 @@ export class Container extends BaseClient {
408
409
  host: this.clientHost,
409
410
  });
410
411
  }
412
+ /**
413
+ * This container after executing the specified command inside it
414
+ */
415
+ withExec(args, stdin, redirectStdout, redirectStderr, experimentalPrivilegedNesting) {
416
+ return new Container({
417
+ queryTree: [
418
+ ...this._queryTree,
419
+ {
420
+ operation: "withExec",
421
+ args: {
422
+ args,
423
+ stdin,
424
+ redirectStdout,
425
+ redirectStderr,
426
+ experimentalPrivilegedNesting,
427
+ },
428
+ },
429
+ ],
430
+ host: this.clientHost,
431
+ });
432
+ }
411
433
  /**
412
434
  * Initialize this container from this DirectoryID
435
+ *
436
+ * @deprecated Replaced by withRootfs.
413
437
  */
414
438
  withFS(id) {
415
439
  return new Container({
@@ -498,6 +522,21 @@ export class Container extends BaseClient {
498
522
  host: this.clientHost,
499
523
  });
500
524
  }
525
+ /**
526
+ * Initialize this container from this DirectoryID
527
+ */
528
+ withRootfs(id) {
529
+ return new Container({
530
+ queryTree: [
531
+ ...this._queryTree,
532
+ {
533
+ operation: "withRootfs",
534
+ args: { id },
535
+ },
536
+ ],
537
+ host: this.clientHost,
538
+ });
539
+ }
501
540
  /**
502
541
  * This container plus an env variable containing the given secret
503
542
  */
@@ -513,6 +552,21 @@ export class Container extends BaseClient {
513
552
  host: this.clientHost,
514
553
  });
515
554
  }
555
+ /**
556
+ * This container plus a socket forwarded to the given Unix socket path
557
+ */
558
+ withUnixSocket(path, source) {
559
+ return new Container({
560
+ queryTree: [
561
+ ...this._queryTree,
562
+ {
563
+ operation: "withUnixSocket",
564
+ args: { path, source },
565
+ },
566
+ ],
567
+ host: this.clientHost,
568
+ });
569
+ }
516
570
  /**
517
571
  * This container but with a different command user
518
572
  */
@@ -573,6 +627,21 @@ export class Container extends BaseClient {
573
627
  host: this.clientHost,
574
628
  });
575
629
  }
630
+ /**
631
+ * This container with a previously added Unix socket removed
632
+ */
633
+ withoutUnixSocket(path) {
634
+ return new Container({
635
+ queryTree: [
636
+ ...this._queryTree,
637
+ {
638
+ operation: "withoutUnixSocket",
639
+ args: { path },
640
+ },
641
+ ],
642
+ host: this.clientHost,
643
+ });
644
+ }
576
645
  /**
577
646
  * The working directory for all commands
578
647
  */
@@ -584,7 +653,7 @@ export class Container extends BaseClient {
584
653
  operation: "workdir",
585
654
  },
586
655
  ];
587
- const response = yield this._compute();
656
+ const response = yield queryBuilder(this._queryTree, this.client);
588
657
  return response;
589
658
  });
590
659
  }
@@ -623,6 +692,21 @@ export class Directory extends BaseClient {
623
692
  host: this.clientHost,
624
693
  });
625
694
  }
695
+ /**
696
+ * Build a new Docker container from this directory
697
+ */
698
+ dockerBuild(dockerfile, platform) {
699
+ return new Container({
700
+ queryTree: [
701
+ ...this._queryTree,
702
+ {
703
+ operation: "dockerBuild",
704
+ args: { dockerfile, platform },
705
+ },
706
+ ],
707
+ host: this.clientHost,
708
+ });
709
+ }
626
710
  /**
627
711
  * Return a list of files and directories at the given path
628
712
  */
@@ -635,7 +719,7 @@ export class Directory extends BaseClient {
635
719
  args: { path },
636
720
  },
637
721
  ];
638
- const response = yield this._compute();
722
+ const response = yield queryBuilder(this._queryTree, this.client);
639
723
  return response;
640
724
  });
641
725
  }
@@ -651,7 +735,7 @@ export class Directory extends BaseClient {
651
735
  args: { path },
652
736
  },
653
737
  ];
654
- const response = yield this._compute();
738
+ const response = yield queryBuilder(this._queryTree, this.client);
655
739
  return response;
656
740
  });
657
741
  }
@@ -681,7 +765,7 @@ export class Directory extends BaseClient {
681
765
  operation: "id",
682
766
  },
683
767
  ];
684
- const response = yield this._compute();
768
+ const response = yield queryBuilder(this._queryTree, this.client);
685
769
  return response;
686
770
  });
687
771
  }
@@ -806,7 +890,7 @@ export class EnvVariable extends BaseClient {
806
890
  operation: "name",
807
891
  },
808
892
  ];
809
- const response = yield this._compute();
893
+ const response = yield queryBuilder(this._queryTree, this.client);
810
894
  return response;
811
895
  });
812
896
  }
@@ -821,7 +905,7 @@ export class EnvVariable extends BaseClient {
821
905
  operation: "value",
822
906
  },
823
907
  ];
824
- const response = yield this._compute();
908
+ const response = yield queryBuilder(this._queryTree, this.client);
825
909
  return response;
826
910
  });
827
911
  }
@@ -841,7 +925,7 @@ export class File extends BaseClient {
841
925
  operation: "contents",
842
926
  },
843
927
  ];
844
- const response = yield this._compute();
928
+ const response = yield queryBuilder(this._queryTree, this.client);
845
929
  return response;
846
930
  });
847
931
  }
@@ -857,7 +941,7 @@ export class File extends BaseClient {
857
941
  args: { path },
858
942
  },
859
943
  ];
860
- const response = yield this._compute();
944
+ const response = yield queryBuilder(this._queryTree, this.client);
861
945
  return response;
862
946
  });
863
947
  }
@@ -872,7 +956,7 @@ export class File extends BaseClient {
872
956
  operation: "id",
873
957
  },
874
958
  ];
875
- const response = yield this._compute();
959
+ const response = yield queryBuilder(this._queryTree, this.client);
876
960
  return response;
877
961
  });
878
962
  }
@@ -898,7 +982,7 @@ export class File extends BaseClient {
898
982
  operation: "size",
899
983
  },
900
984
  ];
901
- const response = yield this._compute();
985
+ const response = yield queryBuilder(this._queryTree, this.client);
902
986
  return response;
903
987
  });
904
988
  }
@@ -918,19 +1002,20 @@ export class GitRef extends BaseClient {
918
1002
  operation: "digest",
919
1003
  },
920
1004
  ];
921
- const response = yield this._compute();
1005
+ const response = yield queryBuilder(this._queryTree, this.client);
922
1006
  return response;
923
1007
  });
924
1008
  }
925
1009
  /**
926
1010
  * The filesystem tree at this ref
927
1011
  */
928
- tree() {
1012
+ tree(sshKnownHosts, sshAuthSocket) {
929
1013
  return new Directory({
930
1014
  queryTree: [
931
1015
  ...this._queryTree,
932
1016
  {
933
1017
  operation: "tree",
1018
+ args: { sshKnownHosts, sshAuthSocket },
934
1019
  },
935
1020
  ],
936
1021
  host: this.clientHost,
@@ -967,7 +1052,7 @@ export class GitRepository extends BaseClient {
967
1052
  operation: "branches",
968
1053
  },
969
1054
  ];
970
- const response = yield this._compute();
1055
+ const response = yield queryBuilder(this._queryTree, this.client);
971
1056
  return response;
972
1057
  });
973
1058
  }
@@ -1012,7 +1097,7 @@ export class GitRepository extends BaseClient {
1012
1097
  operation: "tags",
1013
1098
  },
1014
1099
  ];
1015
- const response = yield this._compute();
1100
+ const response = yield queryBuilder(this._queryTree, this.client);
1016
1101
  return response;
1017
1102
  });
1018
1103
  }
@@ -1037,7 +1122,7 @@ export class Host extends BaseClient {
1037
1122
  });
1038
1123
  }
1039
1124
  /**
1040
- * Lookup the value of an environment variable. Null if the variable is not available.
1125
+ * Access an environment variable on the host
1041
1126
  */
1042
1127
  envVariable(name) {
1043
1128
  return new HostVariable({
@@ -1051,8 +1136,25 @@ export class Host extends BaseClient {
1051
1136
  host: this.clientHost,
1052
1137
  });
1053
1138
  }
1139
+ /**
1140
+ * Access a Unix socket on the host
1141
+ */
1142
+ unixSocket(path) {
1143
+ return new Socket({
1144
+ queryTree: [
1145
+ ...this._queryTree,
1146
+ {
1147
+ operation: "unixSocket",
1148
+ args: { path },
1149
+ },
1150
+ ],
1151
+ host: this.clientHost,
1152
+ });
1153
+ }
1054
1154
  /**
1055
1155
  * The current working directory on the host
1156
+ *
1157
+ * @deprecated Use directory with path set to '.' instead.
1056
1158
  */
1057
1159
  workdir(exclude, include) {
1058
1160
  return new Directory({
@@ -1096,7 +1198,7 @@ export class HostVariable extends BaseClient {
1096
1198
  operation: "value",
1097
1199
  },
1098
1200
  ];
1099
- const response = yield this._compute();
1201
+ const response = yield queryBuilder(this._queryTree, this.client);
1100
1202
  return response;
1101
1203
  });
1102
1204
  }
@@ -1116,7 +1218,7 @@ export class Project extends BaseClient {
1116
1218
  operation: "extensions",
1117
1219
  },
1118
1220
  ];
1119
- const response = yield this._compute();
1221
+ const response = yield queryBuilder(this._queryTree, this.client);
1120
1222
  return response;
1121
1223
  });
1122
1224
  }
@@ -1145,7 +1247,7 @@ export class Project extends BaseClient {
1145
1247
  operation: "install",
1146
1248
  },
1147
1249
  ];
1148
- const response = yield this._compute();
1250
+ const response = yield queryBuilder(this._queryTree, this.client);
1149
1251
  return response;
1150
1252
  });
1151
1253
  }
@@ -1160,7 +1262,7 @@ export class Project extends BaseClient {
1160
1262
  operation: "name",
1161
1263
  },
1162
1264
  ];
1163
- const response = yield this._compute();
1265
+ const response = yield queryBuilder(this._queryTree, this.client);
1164
1266
  return response;
1165
1267
  });
1166
1268
  }
@@ -1175,7 +1277,7 @@ export class Project extends BaseClient {
1175
1277
  operation: "schema",
1176
1278
  },
1177
1279
  ];
1178
- const response = yield this._compute();
1280
+ const response = yield queryBuilder(this._queryTree, this.client);
1179
1281
  return response;
1180
1282
  });
1181
1283
  }
@@ -1190,7 +1292,7 @@ export class Project extends BaseClient {
1190
1292
  operation: "sdk",
1191
1293
  },
1192
1294
  ];
1193
- const response = yield this._compute();
1295
+ const response = yield queryBuilder(this._queryTree, this.client);
1194
1296
  return response;
1195
1297
  });
1196
1298
  }
@@ -1239,7 +1341,7 @@ export default class Client extends BaseClient {
1239
1341
  operation: "defaultPlatform",
1240
1342
  },
1241
1343
  ];
1242
- const response = yield this._compute();
1344
+ const response = yield queryBuilder(this._queryTree, this.client);
1243
1345
  return response;
1244
1346
  });
1245
1347
  }
@@ -1347,6 +1449,21 @@ export default class Client extends BaseClient {
1347
1449
  host: this.clientHost,
1348
1450
  });
1349
1451
  }
1452
+ /**
1453
+ * Load a socket by ID
1454
+ */
1455
+ socket(id) {
1456
+ return new Socket({
1457
+ queryTree: [
1458
+ ...this._queryTree,
1459
+ {
1460
+ operation: "socket",
1461
+ args: { id },
1462
+ },
1463
+ ],
1464
+ host: this.clientHost,
1465
+ });
1466
+ }
1350
1467
  }
1351
1468
  /**
1352
1469
  * A reference to a secret value, which can be handled more safely than the value itself
@@ -1363,7 +1480,7 @@ export class Secret extends BaseClient {
1363
1480
  operation: "id",
1364
1481
  },
1365
1482
  ];
1366
- const response = yield this._compute();
1483
+ const response = yield queryBuilder(this._queryTree, this.client);
1367
1484
  return response;
1368
1485
  });
1369
1486
  }
@@ -1378,7 +1495,24 @@ export class Secret extends BaseClient {
1378
1495
  operation: "plaintext",
1379
1496
  },
1380
1497
  ];
1381
- const response = yield this._compute();
1498
+ const response = yield queryBuilder(this._queryTree, this.client);
1499
+ return response;
1500
+ });
1501
+ }
1502
+ }
1503
+ export class Socket extends BaseClient {
1504
+ /**
1505
+ * The content-addressed identifier of the socket
1506
+ */
1507
+ id() {
1508
+ return __awaiter(this, void 0, void 0, function* () {
1509
+ this._queryTree = [
1510
+ ...this._queryTree,
1511
+ {
1512
+ operation: "id",
1513
+ },
1514
+ ];
1515
+ const response = yield queryBuilder(this._queryTree, this.client);
1382
1516
  return response;
1383
1517
  });
1384
1518
  }
@@ -1,4 +1,28 @@
1
+ import { GraphQLClient } from "graphql-request";
1
2
  import { QueryTree } from "./client.gen.js";
2
- export declare function queryBuilder(q: QueryTree[]): string;
3
- export declare function queryFlatten(res: Record<string, any>): Record<string, any>;
3
+ /**
4
+ * Convert the queryTree into a GraphQL query
5
+ * @param q
6
+ * @returns
7
+ */
8
+ export declare function buildQuery(q: QueryTree[]): string;
9
+ /**
10
+ * Convert querytree into a Graphql query then compute it
11
+ * @param q | QueryTree[]
12
+ * @param client | GraphQLClient
13
+ * @returns
14
+ */
15
+ export declare function queryBuilder<T>(q: QueryTree[], client: GraphQLClient): Promise<T>;
16
+ /**
17
+ * Return a Graphql query result flattened
18
+ * @param response any
19
+ * @returns
20
+ */
21
+ export declare function queryFlatten<T>(response: any): T;
22
+ /**
23
+ * Send a GraphQL document to the server
24
+ * return a flatten result
25
+ * @hidden
26
+ */
27
+ export declare function compute<T>(query: string, client: GraphQLClient): Promise<T>;
4
28
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../api/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,wBAAgB,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,UAmC1C;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAc1E"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../api/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAkD3C;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,MAAM,CAYjD;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAClC,CAAC,EAAE,SAAS,EAAE,EACd,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,CAAC,CAAC,CAQZ;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,CAmBhD;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,CAAC,CAAC,CAQZ"}