@dagger.io/dagger 0.9.7 → 0.9.9

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 (33) hide show
  1. package/dist/api/client.gen.d.ts +648 -59
  2. package/dist/api/client.gen.d.ts.map +1 -1
  3. package/dist/api/client.gen.js +1231 -99
  4. package/dist/common/utils.d.ts +3 -0
  5. package/dist/common/utils.d.ts.map +1 -1
  6. package/dist/entrypoint/entrypoint.js +2 -1
  7. package/dist/entrypoint/invoke.d.ts.map +1 -1
  8. package/dist/entrypoint/invoke.js +25 -5
  9. package/dist/entrypoint/load.d.ts +43 -1
  10. package/dist/entrypoint/load.d.ts.map +1 -1
  11. package/dist/entrypoint/load.js +116 -11
  12. package/dist/entrypoint/register.d.ts.map +1 -1
  13. package/dist/entrypoint/register.js +9 -5
  14. package/dist/introspector/decorators/decorators.d.ts +3 -3
  15. package/dist/introspector/decorators/decorators.d.ts.map +1 -1
  16. package/dist/introspector/registry/registry.d.ts +5 -3
  17. package/dist/introspector/registry/registry.d.ts.map +1 -1
  18. package/dist/introspector/registry/registry.js +23 -39
  19. package/dist/introspector/scanner/metadata.d.ts +1 -0
  20. package/dist/introspector/scanner/metadata.d.ts.map +1 -1
  21. package/dist/introspector/scanner/scan.d.ts +5 -1
  22. package/dist/introspector/scanner/scan.d.ts.map +1 -1
  23. package/dist/introspector/scanner/scan.js +38 -5
  24. package/dist/introspector/scanner/serialize.d.ts.map +1 -1
  25. package/dist/introspector/scanner/serialize.js +8 -2
  26. package/dist/introspector/scanner/typeDefs.d.ts +3 -0
  27. package/dist/introspector/scanner/typeDefs.d.ts.map +1 -1
  28. package/dist/introspector/scanner/utils.d.ts +18 -2
  29. package/dist/introspector/scanner/utils.d.ts.map +1 -1
  30. package/dist/introspector/scanner/utils.js +85 -12
  31. package/dist/provisioning/default.d.ts +1 -1
  32. package/dist/provisioning/default.js +1 -1
  33. package/package.json +6 -6
@@ -1,7 +1,7 @@
1
1
  import ts from "typescript";
2
2
  import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
3
3
  import { serializeSignature, serializeSymbol } from "./serialize.js";
4
- import { isFunction, isObject, isOptional, isPublicProperty, typeNameToTypedef, } from "./utils.js";
4
+ import { getAlias, isFunction, isMainObject, isObject, isOptional, isPublicProperty, typeNameToTypedef, } from "./utils.js";
5
5
  /**
6
6
  * Scan the list of TypeScript File using the TypeScript compiler API.
7
7
  *
@@ -11,8 +11,9 @@ import { isFunction, isObject, isOptional, isPublicProperty, typeNameToTypedef,
11
11
  * WARNING(28/11/23): This does NOT include arrow style function.
12
12
  *
13
13
  * @param files List of TypeScript files to introspect.
14
+ * @param moduleName The name of the module to introspect.
14
15
  */
15
- export function scan(files) {
16
+ export function scan(files, moduleName = "") {
16
17
  if (files.length === 0) {
17
18
  throw new UnknownDaggerError("no files to introspect found", {});
18
19
  }
@@ -20,6 +21,7 @@ export function scan(files) {
20
21
  const program = ts.createProgram(files, { experimentalDecorators: true });
21
22
  const checker = program.getTypeChecker();
22
23
  const metadata = {
24
+ module: {},
23
25
  classes: {},
24
26
  functions: {},
25
27
  };
@@ -32,6 +34,9 @@ export function scan(files) {
32
34
  // Handle class
33
35
  if (ts.isClassDeclaration(node) && isObject(node)) {
34
36
  const classTypeDef = introspectClass(checker, node);
37
+ if (isMainObject(classTypeDef.name, moduleName)) {
38
+ metadata.module.description = introspectTopLevelComment(file);
39
+ }
35
40
  metadata.classes[classTypeDef.name] = classTypeDef;
36
41
  }
37
42
  });
@@ -78,12 +83,12 @@ function introspectClass(checker, node) {
78
83
  // Handle method from the class.
79
84
  if (ts.isMethodDeclaration(member) && isFunction(member)) {
80
85
  const fctTypeDef = introspectMethod(checker, member);
81
- metadata.methods[fctTypeDef.name] = fctTypeDef;
86
+ metadata.methods[fctTypeDef.alias ?? fctTypeDef.name] = fctTypeDef;
82
87
  }
83
88
  // Handle public properties from the class.
84
89
  if (ts.isPropertyDeclaration(member)) {
85
90
  const fieldTypeDef = introspectProperty(checker, member);
86
- metadata.fields[fieldTypeDef.name] = fieldTypeDef;
91
+ metadata.fields[fieldTypeDef.alias ?? fieldTypeDef.name] = fieldTypeDef;
87
92
  }
88
93
  });
89
94
  return metadata;
@@ -105,6 +110,7 @@ function introspectProperty(checker, property) {
105
110
  return {
106
111
  name,
107
112
  description,
113
+ alias: getAlias(property, "field"),
108
114
  typeDef: typeNameToTypedef(typeName),
109
115
  isExposed: isPublicProperty(property),
110
116
  };
@@ -126,6 +132,7 @@ function introspectConstructor(checker, constructor) {
126
132
  typeDef: typeNameToTypedef(typeName),
127
133
  optional,
128
134
  defaultValue,
135
+ isVariadic: false,
129
136
  };
130
137
  return acc;
131
138
  }, {});
@@ -154,16 +161,42 @@ function introspectMethod(checker, method) {
154
161
  return {
155
162
  name: methodMetadata.name,
156
163
  description: methodMetadata.description,
157
- args: methodSignature.params.reduce((acc, { name, typeName, description, optional, defaultValue }) => {
164
+ alias: getAlias(method, "func"),
165
+ args: methodSignature.params.reduce((acc, { name, typeName, description, optional, defaultValue, isVariadic }) => {
158
166
  acc[name] = {
159
167
  name,
160
168
  typeDef: typeNameToTypedef(typeName),
161
169
  description,
162
170
  optional,
163
171
  defaultValue,
172
+ isVariadic,
164
173
  };
165
174
  return acc;
166
175
  }, {}),
167
176
  returnType: typeNameToTypedef(methodSignature.returnType),
168
177
  };
169
178
  }
179
+ /**
180
+ * Return the content of the top level comment of the given file.
181
+ *
182
+ * @param file The file to introspect.
183
+ */
184
+ function introspectTopLevelComment(file) {
185
+ const firstStatement = file.statements[0];
186
+ if (!firstStatement) {
187
+ return undefined;
188
+ }
189
+ const commentRanges = ts.getLeadingCommentRanges(file.getFullText(), firstStatement.pos);
190
+ if (!commentRanges || commentRanges.length === 0) {
191
+ return undefined;
192
+ }
193
+ const commentRange = commentRanges[0];
194
+ const comment = file
195
+ .getFullText()
196
+ .substring(commentRange.pos, commentRange.end)
197
+ .split("\n")
198
+ .slice(1, -1) // Remove start and ending comments characters `/** */`
199
+ .map((line) => line.replace("*", "").trim()) // Remove leading * and spaces
200
+ .join("\n");
201
+ return comment;
202
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAGjE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,SAAS,EAAE,EAAE,CAAC,SAAS,GACtB,iBAAiB,CAanB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,MAAM,EAAE,EAAE,CAAC,MAAM,GAChB,cAAc,GAAG;IAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAA;CAAE,CAkBpC;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,CAS5E"}
1
+ {"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAGjE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,SAAS,EAAE,EAAE,CAAC,SAAS,GACtB,iBAAiB,CAmBnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,MAAM,EAAE,EAAE,CAAC,MAAM,GAChB,cAAc,GAAG;IAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAA;CAAE,CAkBpC;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,CAS5E"}
@@ -1,6 +1,6 @@
1
1
  import ts from "typescript";
2
2
  import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
3
- import { isOptional } from "./utils.js";
3
+ import { isOptional, isVariadic } from "./utils.js";
4
4
  /**
5
5
  * Convert the function signature from the compiler API into a lighter data type.
6
6
  *
@@ -12,11 +12,17 @@ import { isOptional } from "./utils.js";
12
12
  export function serializeSignature(checker, signature) {
13
13
  return {
14
14
  params: signature.parameters.map((param) => {
15
- const { optional, defaultValue } = isOptional(param);
15
+ // eslint-disable-next-line prefer-const
16
+ let { optional, defaultValue } = isOptional(param);
17
+ const variadic = isVariadic(param);
18
+ if (variadic) {
19
+ optional = true;
20
+ }
16
21
  return {
17
22
  ...serializeSymbol(checker, param),
18
23
  optional,
19
24
  defaultValue,
25
+ isVariadic: variadic,
20
26
  };
21
27
  }),
22
28
  returnType: serializeType(checker, signature.getReturnType()),
@@ -32,6 +32,7 @@ export type TypeDef<T extends BaseTypeDef["kind"]> = T extends TypeDefKind.Objec
32
32
  */
33
33
  export type FieldTypeDef = {
34
34
  name: string;
35
+ alias?: string;
35
36
  description: string;
36
37
  typeDef: TypeDef<TypeDefKind>;
37
38
  isExposed: boolean;
@@ -44,6 +45,7 @@ export type FunctionArg = {
44
45
  description: string;
45
46
  optional: boolean;
46
47
  defaultValue?: string;
48
+ isVariadic: boolean;
47
49
  typeDef: TypeDef<TypeDefKind>;
48
50
  };
49
51
  /**
@@ -52,6 +54,7 @@ export type FunctionArg = {
52
54
  export type FunctionTypedef = {
53
55
  name: string;
54
56
  description: string;
57
+ alias?: string;
55
58
  args: {
56
59
  [name: string]: FunctionArg;
57
60
  };
@@ -1 +1 @@
1
- {"version":3,"file":"typeDefs.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/typeDefs.ts"],"names":[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Kind } from "../../api/client.gen.js";
3
3
  import { TypeDef } from "./typeDefs.js";
4
4
  /**
5
- * Return true if the given class declaration has the decorator @obj on
5
+ * Return true if the given class declaration has the decorator @obj() on
6
6
  * top of its declaration.
7
7
  * @param object
8
8
  */
9
9
  export declare function isObject(object: ts.ClassDeclaration): boolean;
10
10
  /**
11
- * Return true if the given method has the decorator @fct on top
11
+ * Check if the class is the main object of the module.
12
+ *
13
+ * @param classtName The name of the class to check.
14
+ * @param moduleName The name of the module.
15
+ */
16
+ export declare function isMainObject(className: string, moduleName: string): boolean;
17
+ /**
18
+ * Return true if the given method has the decorator @fct() on top
12
19
  * of its declaration.
13
20
  *
14
21
  * @param method The method to check
15
22
  */
16
23
  export declare function isFunction(method: ts.MethodDeclaration): boolean;
24
+ /**
25
+ * Return true if the given property has the decorator @field() on top
26
+ * of its declaration.
27
+ *
28
+ * @param property The property to check
29
+ */
30
+ export declare function isField(property: ts.PropertyDeclaration): boolean;
31
+ export declare function getAlias(elem: ts.HasDecorators, kind: "field" | "func"): string | undefined;
17
32
  /**
18
33
  * Return true if the given property is public.
19
34
  *
@@ -54,6 +69,7 @@ type OptionalValue = {
54
69
  * @param param The param to check.
55
70
  */
56
71
  export declare function isOptional(param: ts.Symbol): OptionalValue;
72
+ export declare function isVariadic(param: ts.Symbol): boolean;
57
73
  /**
58
74
  * Convert a typename into a Dagger Typedef using dynamic typing.
59
75
  */
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,GAAG,OAAO,CAM7D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAA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G;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,EAAE,CAAC,mBAAmB,GAAG,OAAO,CAe1E;AAED,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,GAAG,aAAa,CAwB1D;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,GAAG,OAAO,CAcpD;AAaD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAyBxE"}
@@ -1,24 +1,89 @@
1
1
  import ts from "typescript";
2
2
  import { TypeDefKind } from "../../api/client.gen.js";
3
3
  /**
4
- * Return true if the given class declaration has the decorator @obj on
4
+ * Return true if the given class declaration has the decorator @obj() on
5
5
  * top of its declaration.
6
6
  * @param object
7
7
  */
8
8
  export function isObject(object) {
9
- return (ts
10
- .getDecorators(object)
11
- ?.find((d) => d.expression.getText() === "object") !== undefined);
9
+ return (ts.getDecorators(object)?.find((d) => {
10
+ if (ts.isCallExpression(d.expression)) {
11
+ return d.expression.expression.getText() === "object";
12
+ }
13
+ return false;
14
+ }) !== undefined);
12
15
  }
13
16
  /**
14
- * Return true if the given method has the decorator @fct on top
17
+ * Check if the class is the main object of the module.
18
+ *
19
+ * @param classtName The name of the class to check.
20
+ * @param moduleName The name of the module.
21
+ */
22
+ export function isMainObject(className, moduleName) {
23
+ const toPascalCase = (input) => {
24
+ const words = input
25
+ .replace(/[^a-zA-Z0-9]/g, " ") // Replace non-alphanumeric characters with spaces
26
+ .split(/\s+/)
27
+ .filter((word) => word.length > 0);
28
+ if (words.length === 0) {
29
+ return ""; // No valid words found
30
+ }
31
+ // It's an edge case when moduleName is already in PascalCase or camelCase
32
+ if (words.length === 1) {
33
+ return words[0].charAt(0).toUpperCase() + words[0].slice(1);
34
+ }
35
+ const pascalCase = words
36
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
37
+ .join("");
38
+ return pascalCase;
39
+ };
40
+ return toPascalCase(moduleName) === className;
41
+ }
42
+ /**
43
+ * Return true if the given method has the decorator @fct() on top
15
44
  * of its declaration.
16
45
  *
17
46
  * @param method The method to check
18
47
  */
19
48
  export function isFunction(method) {
20
- return (ts.getDecorators(method)?.find((d) => d.expression.getText() === "func") !==
21
- undefined);
49
+ return (ts.getDecorators(method)?.find((d) => {
50
+ if (ts.isCallExpression(d.expression)) {
51
+ return d.expression.expression.getText() === "func";
52
+ }
53
+ return false;
54
+ }) !== undefined);
55
+ }
56
+ /**
57
+ * Return true if the given property has the decorator @field() on top
58
+ * of its declaration.
59
+ *
60
+ * @param property The property to check
61
+ */
62
+ export function isField(property) {
63
+ return (ts.getDecorators(property)?.find((d) => {
64
+ if (ts.isCallExpression(d.expression)) {
65
+ return d.expression.expression.getText() === "field";
66
+ }
67
+ return false;
68
+ }) !== undefined);
69
+ }
70
+ export function getAlias(elem, kind) {
71
+ const decorator = ts.getDecorators(elem)?.find((d) => {
72
+ if (ts.isCallExpression(d.expression)) {
73
+ return d.expression.expression.getText() === kind;
74
+ }
75
+ return false;
76
+ });
77
+ if (!decorator) {
78
+ return undefined;
79
+ }
80
+ const expression = decorator.expression;
81
+ const args = expression.arguments;
82
+ const alias = args[0]?.getText();
83
+ if (alias) {
84
+ return JSON.parse(alias.replace(/'/g, '"'));
85
+ }
86
+ return undefined;
22
87
  }
23
88
  /**
24
89
  * Return true if the given property is public.
@@ -45,11 +110,7 @@ export function isFunction(method) {
45
110
  * @param property The property to check on.
46
111
  */
47
112
  export function isPublicProperty(property) {
48
- const decorators = ts.getDecorators(property);
49
- if (!decorators) {
50
- return false;
51
- }
52
- if (decorators.find((d) => d.expression.getText() === "field") === undefined) {
113
+ if (!isField(property)) {
53
114
  return false;
54
115
  }
55
116
  const modifiers = ts.getModifiers(property);
@@ -87,6 +148,18 @@ export function isOptional(param) {
87
148
  }
88
149
  return result;
89
150
  }
151
+ export function isVariadic(param) {
152
+ const declarations = param.getDeclarations();
153
+ // Only check if the parameters actually have declarations
154
+ if (declarations && declarations.length > 0) {
155
+ const parameterDeclaration = declarations[0];
156
+ // Convert the symbol declaration into Parameter
157
+ if (ts.isParameter(parameterDeclaration)) {
158
+ return parameterDeclaration.dotDotDotToken !== undefined;
159
+ }
160
+ }
161
+ return false;
162
+ }
90
163
  function formatDefaultValue(value) {
91
164
  const isSingleQuoteString = () => value.startsWith("'") && value.endsWith("'");
92
165
  if (isSingleQuoteString()) {
@@ -1,2 +1,2 @@
1
- export declare const CLI_VERSION = "0.9.7";
1
+ export declare const CLI_VERSION = "0.9.9";
2
2
  //# sourceMappingURL=default.d.ts.map
@@ -1,2 +1,2 @@
1
1
  // Code generated by dagger. DO NOT EDIT.
2
- export const CLI_VERSION = "0.9.7";
2
+ export const CLI_VERSION = "0.9.9";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dagger.io/dagger",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
4
4
  "author": "hello@dagger.io",
5
5
  "license": "Apache-2.0",
6
6
  "types": "./dist/index.d.ts",
@@ -23,10 +23,11 @@
23
23
  "graphql": "^16.8.0",
24
24
  "graphql-request": "^6.1.0",
25
25
  "graphql-tag": "^2.12.6",
26
- "node-color-log": "^10.0.2",
26
+ "node-color-log": "^11.0.0",
27
27
  "node-fetch": "^3.3.1",
28
28
  "reflect-metadata": "^0.2.1",
29
- "tar": "^6.1.13"
29
+ "tar": "^6.1.13",
30
+ "typescript": "^5.3.3"
30
31
  },
31
32
  "scripts": {
32
33
  "build": "tsc",
@@ -41,7 +42,7 @@
41
42
  "@trivago/prettier-plugin-sort-imports": "^4.2.0",
42
43
  "@types/adm-zip": "^0.5.0",
43
44
  "@types/mocha": "latest",
44
- "@types/node": "~16",
45
+ "@types/node": "~20",
45
46
  "@types/tar": "^6.1.4",
46
47
  "@typescript-eslint/eslint-plugin": "^5.62.0",
47
48
  "@typescript-eslint/parser": "^5.62.0",
@@ -50,7 +51,6 @@
50
51
  "eslint-plugin-prettier": "^4.2.1",
51
52
  "mocha": "^10.2.0",
52
53
  "prettier": "^2.8.7",
53
- "ts-node": "^10.9.1",
54
- "typescript": "^5.3.3"
54
+ "ts-node": "^10.9.1"
55
55
  }
56
56
  }