@dagger.io/dagger 0.10.1 → 0.10.2

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 (51) hide show
  1. package/dist/api/utils.d.ts.map +1 -1
  2. package/dist/api/utils.js +6 -2
  3. package/dist/common/errors/ExecError.d.ts.map +1 -1
  4. package/dist/entrypoint/context.d.ts +8 -0
  5. package/dist/entrypoint/context.d.ts.map +1 -0
  6. package/dist/entrypoint/invoke.d.ts +3 -9
  7. package/dist/entrypoint/invoke.d.ts.map +1 -1
  8. package/dist/entrypoint/invoke.js +17 -28
  9. package/dist/entrypoint/load.d.ts +29 -69
  10. package/dist/entrypoint/load.d.ts.map +1 -1
  11. package/dist/entrypoint/load.js +90 -173
  12. package/dist/entrypoint/register.d.ts +2 -2
  13. package/dist/entrypoint/register.d.ts.map +1 -1
  14. package/dist/entrypoint/register.js +12 -12
  15. package/dist/introspector/scanner/abtractions/argument.d.ts +75 -0
  16. package/dist/introspector/scanner/abtractions/argument.d.ts.map +1 -0
  17. package/dist/introspector/scanner/abtractions/argument.js +137 -0
  18. package/dist/introspector/scanner/abtractions/constructor.d.ts +16 -0
  19. package/dist/introspector/scanner/abtractions/constructor.d.ts.map +1 -0
  20. package/dist/introspector/scanner/abtractions/constructor.js +42 -0
  21. package/dist/introspector/scanner/abtractions/method.d.ts +51 -0
  22. package/dist/introspector/scanner/abtractions/method.d.ts.map +1 -0
  23. package/dist/introspector/scanner/abtractions/method.js +105 -0
  24. package/dist/introspector/scanner/abtractions/module.d.ts +18 -0
  25. package/dist/introspector/scanner/abtractions/module.d.ts.map +1 -0
  26. package/dist/introspector/scanner/abtractions/module.js +59 -0
  27. package/dist/introspector/scanner/abtractions/object.d.ts +37 -0
  28. package/dist/introspector/scanner/abtractions/object.d.ts.map +1 -0
  29. package/dist/introspector/scanner/abtractions/object.js +94 -0
  30. package/dist/introspector/scanner/abtractions/property.d.ts +46 -0
  31. package/dist/introspector/scanner/abtractions/property.d.ts.map +1 -0
  32. package/dist/introspector/scanner/abtractions/property.js +93 -0
  33. package/dist/introspector/scanner/scan.d.ts +2 -1
  34. package/dist/introspector/scanner/scan.d.ts.map +1 -1
  35. package/dist/introspector/scanner/scan.js +2 -181
  36. package/dist/introspector/scanner/serialize.d.ts +0 -24
  37. package/dist/introspector/scanner/serialize.d.ts.map +1 -1
  38. package/dist/introspector/scanner/serialize.js +0 -53
  39. package/dist/introspector/scanner/typeDefs.d.ts +3 -3
  40. package/dist/introspector/scanner/typeDefs.d.ts.map +1 -1
  41. package/dist/introspector/scanner/utils.d.ts +1 -57
  42. package/dist/introspector/scanner/utils.d.ts.map +1 -1
  43. package/dist/introspector/scanner/utils.js +16 -149
  44. package/dist/provisioning/bin.d.ts.map +1 -1
  45. package/dist/provisioning/bin.js +9 -3
  46. package/dist/provisioning/default.d.ts +1 -1
  47. package/dist/provisioning/default.js +1 -1
  48. package/package.json +2 -1
  49. package/dist/introspector/scanner/metadata.d.ts +0 -24
  50. package/dist/introspector/scanner/metadata.d.ts.map +0 -1
  51. /package/dist/{introspector/scanner/metadata.js → entrypoint/context.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../api/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,aAAa,EAAE,MAAM,iBAAiB,CAAA;AASjE,OAAO,EAAY,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAkHrD;;;;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,CAMZ;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,CAqBhD;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,CAAC,CAAC,CA2CZ"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../api/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,aAAa,EAAE,MAAM,iBAAiB,CAAA;AASjE,OAAO,EAAY,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAkHrD;;;;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,CAMZ;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,CAuBhD;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,CAAC,CAAC,CA6CZ"}
package/dist/api/utils.js CHANGED
@@ -121,7 +121,9 @@ export function queryFlatten(response) {
121
121
  if (keys.length != 1) {
122
122
  // Dagger is currently expecting to only return one value
123
123
  // If the response is nested in a way were more than one object is nested inside throw an error
124
- throw new TooManyNestedObjectsError("Too many nested objects inside graphql response", { response: response });
124
+ throw new TooManyNestedObjectsError("Too many nested objects inside graphql response", {
125
+ response: response,
126
+ });
125
127
  }
126
128
  const nestedKey = keys[0];
127
129
  return queryFlatten(response[nestedKey]);
@@ -161,7 +163,9 @@ export async function compute(query, client) {
161
163
  throw new NotAwaitedRequestError("Encountered an error while requesting data via graphql through a synchronous call. Make sure the function called is awaited.", { cause: e });
162
164
  }
163
165
  // Just throw the unknown error
164
- throw new UnknownDaggerError("Encountered an unknown error while requesting data via graphql", { cause: e });
166
+ throw new UnknownDaggerError("Encountered an unknown error while requesting data via graphql", {
167
+ cause: e,
168
+ });
165
169
  }
166
170
  return queryFlatten(computeQuery);
167
171
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ExecError.d.ts","sourceRoot":"","sources":["../../../common/errors/ExecError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAG3E,UAAU,gBAAiB,SAAQ,qBAAqB;IACtD,GAAG,EAAE,MAAM,EAAE,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,cAAc;IAC3C,IAAI,cAAwB;IAC5B,IAAI,SAAwB;IAE5B;;OAEG;IACH,GAAG,EAAE,MAAM,EAAE,CAAA;IAEb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB;IAQtD,QAAQ,IAAI,MAAM;CAKnB"}
1
+ {"version":3,"file":"ExecError.d.ts","sourceRoot":"","sources":["../../../common/errors/ExecError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAG3E,UAAU,gBAAiB,SAAQ,qBAAqB;IACtD,GAAG,EAAE,MAAM,EAAE,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,cAAc;IAC3C,IAAI,cAAwB;IAC5B,IAAI,SAAwB;IAE5B;;OAEG;IACH,GAAG,EAAE,MAAM,EAAE,CAAA;IAEb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB;IAQtD,QAAQ,IAAI,MAAM;CAGnB"}
@@ -0,0 +1,8 @@
1
+ import { Args } from "../introspector/registry/registry.js";
2
+ export type InvokeCtx = {
3
+ parentName: string;
4
+ fnName: string;
5
+ parentArgs: Args;
6
+ fnArgs: Args;
7
+ };
8
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../entrypoint/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,sCAAsC,CAAA;AAE3D,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,IAAI,CAAA;IAChB,MAAM,EAAE,IAAI,CAAA;CACb,CAAA"}
@@ -1,11 +1,5 @@
1
- import { Args } from "../introspector/registry/registry.js";
2
- import { ScanResult } from "../introspector/scanner/scan.js";
3
- export type InvokeCtx = {
4
- parentName: string;
5
- fnName: string;
6
- parentArgs: Args;
7
- fnArgs: Args;
8
- };
1
+ import { DaggerModule } from "../introspector/scanner/abtractions/module.js";
2
+ import { InvokeCtx } from "./context.js";
9
3
  /**
10
4
  * A wrapper around the registry to invoke a function.
11
5
  *
@@ -15,5 +9,5 @@ export type InvokeCtx = {
15
9
  * @param parentArgs The arguments of the parent object.
16
10
  * @param fnArgs The arguments of the function to call.
17
11
  */
18
- export declare function invoke(scanResult: ScanResult, { parentName, fnName, parentArgs, fnArgs }: InvokeCtx): Promise<any>;
12
+ export declare function invoke(module: DaggerModule, ctx: InvokeCtx): Promise<any>;
19
13
  //# sourceMappingURL=invoke.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../entrypoint/invoke.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAY,MAAM,sCAAsC,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAY5D,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,IAAI,CAAA;IAChB,MAAM,EAAE,IAAI,CAAA;CACb,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,UAAU,EAAE,UAAU,EACtB,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,SAAS,GAEvD,OAAO,CAAC,GAAG,CAAC,CAmDX"}
1
+ {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../entrypoint/invoke.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAcxC;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,SAAS,gBAgChE"}
@@ -1,6 +1,8 @@
1
- import { TypeDefKind } from "../api/client.gen.js";
2
1
  import { registry } from "../introspector/registry/registry.js";
3
- import { loadArgOrder, loadArg, loadArgType, loadPropertyType, loadResult, isArgVariadic, loadName, } from "./load.js";
2
+ import { loadResult, loadInvokedMethod, loadInvokedObject, loadArgs, loadParentState, loadObjectReturnType, } from "./load.js";
3
+ function isConstructor(method) {
4
+ return method.name === "";
5
+ }
4
6
  /**
5
7
  * A wrapper around the registry to invoke a function.
6
8
  *
@@ -10,38 +12,25 @@ import { loadArgOrder, loadArg, loadArgType, loadPropertyType, loadResult, isArg
10
12
  * @param parentArgs The arguments of the parent object.
11
13
  * @param fnArgs The arguments of the function to call.
12
14
  */
13
- export async function invoke(scanResult, { parentName, fnName, parentArgs, fnArgs }) {
14
- const args = {};
15
- // Load function arguments in the right order
16
- for (const argName of loadArgOrder(scanResult, parentName, fnName)) {
17
- const loadedArg = await loadArg(fnArgs[argName], loadArgType(scanResult, parentName, fnName, argName));
18
- if (isArgVariadic(scanResult, parentName, fnName, argName)) {
19
- // If the argument is variadic, we need to load each args independently
20
- // so it's correctly propagated when it's sent to the function.
21
- // Note: variadic args are always last in the list of args.
22
- for (const [i, arg] of (loadedArg ?? []).entries()) {
23
- args[`${argName}${i}`] = arg;
24
- }
25
- }
26
- else {
27
- args[argName] = loadedArg;
28
- }
15
+ export async function invoke(module, ctx) {
16
+ let object = loadInvokedObject(module, ctx.parentName);
17
+ if (!object) {
18
+ throw new Error(`could not find object ${ctx.parentName}`);
29
19
  }
30
- // Load parent state
31
- for (const [key, value] of Object.entries(parentArgs)) {
32
- parentArgs[loadName(scanResult, parentName, key, "field")] = await loadArg(value, loadPropertyType(scanResult, parentName, key));
20
+ const method = loadInvokedMethod(object, ctx);
21
+ if (!method) {
22
+ throw new Error(`could not find method ${ctx.fnName}`);
33
23
  }
34
- let result = await registry.getResult(loadName(scanResult, parentName, parentName, "object"), loadName(scanResult, parentName, fnName, "function"), parentArgs, args);
24
+ const args = await loadArgs(method, ctx);
25
+ const parentState = await loadParentState(object, ctx);
26
+ let result = await registry.getResult(object.name, method.name, parentState, args);
35
27
  if (result) {
36
28
  // Handle alias serialization by getting the return type to load
37
29
  // if the function called isn't a constructor.
38
- if (fnName !== "") {
39
- const retType = scanResult.classes[parentName].methods[fnName].returnType;
40
- if (retType.kind === TypeDefKind.ObjectKind) {
41
- parentName = retType.name;
42
- }
30
+ if (!isConstructor(method)) {
31
+ object = loadObjectReturnType(module, object, method);
43
32
  }
44
- result = await loadResult(result, scanResult, parentName);
33
+ result = await loadResult(result, module, object);
45
34
  }
46
35
  return result;
47
36
  }
@@ -1,6 +1,11 @@
1
1
  import { TypeDefKind } from "../api/client.gen.js";
2
- import { ScanResult } from "../introspector/scanner/scan.js";
3
2
  import { TypeDef } from "../introspector/scanner/typeDefs.js";
3
+ import { InvokeCtx } from "./context.js";
4
+ import { DaggerModule } from "../introspector/scanner/abtractions/module.js";
5
+ import { Method } from "../introspector/scanner/abtractions/method.js";
6
+ import { Constructor } from "../introspector/scanner/abtractions/constructor.js";
7
+ import { DaggerObject } from "../introspector/scanner/abtractions/object.js";
8
+ import { Args } from "../introspector/registry/registry.js";
4
9
  /**
5
10
  * Import all given typescript files so that trigger their decorators
6
11
  * and register their class and functions inside the Registry.
@@ -9,87 +14,42 @@ import { TypeDef } from "../introspector/scanner/typeDefs.js";
9
14
  */
10
15
  export declare function load(files: string[]): Promise<void>;
11
16
  /**
12
- * Load the order of arguments for a given function from the scan result.
17
+ * Return the object invoked from the module.
13
18
  *
14
- * @param scanResult The result of the scan.
15
- * @param parentName The name of the class.
16
- * @param fnName The name of the function.
17
- *
18
- * @returns An array of strings representing the order of arguments.
19
- */
20
- export declare function loadArgOrder(scanResult: ScanResult, parentName: string, fnName: string): string[];
21
- /**
22
- * Load the argument for the given function and check if it's variadic.
23
- *
24
- * @param scanResult The result of the scan.
25
- * @param parentName The name of the class.
26
- * @param fnName The name of the function.
27
- * @param argName The name of the argument.
28
- *
29
- * @returns True if the argument is variadic, false otherwise.
30
- */
31
- export declare function isArgVariadic(scanResult: ScanResult, parentName: string, fnName: string, argName: string): boolean;
32
- /**
33
- * Load the argument type from the scan result.
34
- *
35
- * @param scanResult Result of the scan
36
- * @param parentName Class called
37
- * @param fnName Function called
38
- * @param argName Argument name
39
- * @returns The type of the argument
40
- */
41
- export declare function loadArgType(scanResult: ScanResult, parentName: string, fnName: string, argName: string): TypeDef<TypeDefKind>;
42
- /**
43
- * Load the property type from the scan result.
44
- *
45
- * @param scanResult Result of the scan
46
- * @param parentName Class called
47
- * @param propertyName property of the class
48
- * @returns the type of the property
49
- */
50
- export declare function loadPropertyType(scanResult: ScanResult, parentName: string, propertyName: string): TypeDef<TypeDefKind>;
51
- /**
52
- * Load the true name from the scan result
53
- *
54
- * @param scanResult Result of the scan
55
- * @param parentName Class called
56
- * @param alias exposed name
57
- * @param kind location of the alias
19
+ * @param module The module to load the object from.
20
+ * @param parentName The name of the parent object.
58
21
  */
59
- export declare function loadName(scanResult: ScanResult, parentName: string, alias: string, kind: "field" | "function" | "object"): string;
22
+ export declare function loadInvokedObject(module: DaggerModule, parentName: string): DaggerObject;
23
+ export declare function loadInvokedMethod(object: DaggerObject, ctx: InvokeCtx): (Method | Constructor) | undefined;
60
24
  /**
61
- * Load the alias from the true property name.
62
- * If not found, return the original alias because it's not
63
- * a registered field.
25
+ * Load the values of the arguments from the context.
64
26
  *
65
- * @param scanResult Result of the scan
66
- * @param parentName Class called
67
- * @param alias exposed name
27
+ * @param method Method to load the arguments from.
28
+ * @param ctx The context of the invocation.
68
29
  */
69
- export declare function loadResultAlias(scanResult: ScanResult, parentName: string, alias: string): string;
30
+ export declare function loadArgs(method: Method | Constructor, ctx: InvokeCtx): Promise<Args>;
70
31
  /**
71
- * Return the eventual parent name of a field if its return type is a
72
- * registered object.
73
- * If not found, return the original parent name.
32
+ * Load the state of the parent object from the context.
74
33
  *
75
- * @param scanResult The result of the scan.
76
- * @param parentName Original parent name
77
- * @param alias The field alias
34
+ * @param object The object to load the parent state from.
35
+ * @param ctx The context of the invocation.
78
36
  */
79
- export declare function loadAliasParentName(scanResult: ScanResult, parentName: string, alias: string): string;
37
+ export declare function loadParentState(object: DaggerObject, ctx: InvokeCtx): Promise<Args>;
80
38
  /**
81
- * This function load the argument as a Dagger type.
39
+ * This function load the value as a Dagger type.
82
40
  *
83
41
  * Note: The JSON.parse() is required to remove extra quotes
84
42
  */
85
- export declare function loadArg(value: any, type: TypeDef<TypeDefKind>): Promise<any>;
43
+ export declare function loadValue(value: any, type: TypeDef<TypeDefKind>): Promise<any>;
86
44
  /**
87
- * Load subfields of the result and IDable object.
45
+ * Load the object type from the return type of the method.
46
+ * This covers the case where the return type is an other object of the module.
47
+ * For example: `msg(): Message` where message is an object of the module.
88
48
  *
89
- * @param result The result of the invocation.
90
- * @param scanResult The result of the scan.
91
- * @param parentName The name of the parent object.
92
- * @returns Loaded result.
49
+ * @param module The module to load the object from.
50
+ * @param object The current object to load the return type from.
51
+ * @param method The method to load the return type from.
93
52
  */
94
- export declare function loadResult(result: any, scanResult: ScanResult, parentName: string): Promise<any>;
53
+ export declare function loadObjectReturnType(module: DaggerModule, object: DaggerObject, method: Method): DaggerObject;
54
+ export declare function loadResult(result: any, module: DaggerModule, object: DaggerObject): Promise<any>;
95
55
  //# sourceMappingURL=load.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../entrypoint/load.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAA;AAE7D;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,EAAE,CAiBV;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAiBT;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,WAAW,CAAC,CA2BtB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,WAAW,CAAC,CAYtB;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CACtB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,QAAQ,GACpC,MAAM,CAgCR;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,GACZ,MAAM,CAcR;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,GACZ,MAAM,CAkBR;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,OAAO,CAAC,GAAG,CAAC,CAsCd;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,GAAG,EACX,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,GAAG,CAAC,CA+Bd"}
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../entrypoint/load.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,oDAAoD,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,sCAAsC,CAAA;AAE3D;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,GACjB,YAAY,CAEd;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,GACb,CAAC,MAAM,GAAG,WAAW,CAAC,GAAG,SAAS,CAMpC;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,MAAM,GAAG,WAAW,EAC5B,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,IAAI,CAAC,CAqCf;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAC7B,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,OAAO,CAAC,GAAG,CAAC,CAsCd;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,GACb,YAAY,CAmBd;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,GAAG,EACX,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,GAAG,CAAC,CAiDd"}
@@ -10,198 +10,85 @@ export async function load(files) {
10
10
  await Promise.all(files.map(async (f) => await import(f)));
11
11
  }
12
12
  /**
13
- * Load the order of arguments for a given function from the scan result.
13
+ * Return the object invoked from the module.
14
14
  *
15
- * @param scanResult The result of the scan.
16
- * @param parentName The name of the class.
17
- * @param fnName The name of the function.
18
- *
19
- * @returns An array of strings representing the order of arguments.
20
- */
21
- export function loadArgOrder(scanResult, parentName, fnName) {
22
- const classTypeDef = scanResult.classes[parentName];
23
- if (!classTypeDef) {
24
- throw new Error(`could not find class ${parentName}`);
25
- }
26
- // Call for the constructor
27
- if (fnName === "") {
28
- return Object.keys(classTypeDef.constructor?.args ?? {});
29
- }
30
- const methodTypeDef = classTypeDef.methods[fnName];
31
- if (!methodTypeDef) {
32
- throw new Error(`could not find method ${fnName}`);
33
- }
34
- return Object.keys(methodTypeDef.args);
35
- }
36
- /**
37
- * Load the argument for the given function and check if it's variadic.
38
- *
39
- * @param scanResult The result of the scan.
40
- * @param parentName The name of the class.
41
- * @param fnName The name of the function.
42
- * @param argName The name of the argument.
43
- *
44
- * @returns True if the argument is variadic, false otherwise.
45
- */
46
- export function isArgVariadic(scanResult, parentName, fnName, argName) {
47
- const classTypeDef = scanResult.classes[parentName];
48
- if (!classTypeDef) {
49
- throw new Error(`could not find class ${parentName}`);
50
- }
51
- // It's not possible to have variadic arguments in the constructor.
52
- if (fnName === "") {
53
- return false;
54
- }
55
- const methodTypeDef = classTypeDef.methods[fnName];
56
- if (!methodTypeDef) {
57
- throw new Error(`could not find method ${fnName}`);
58
- }
59
- return methodTypeDef.args[argName].isVariadic;
60
- }
61
- /**
62
- * Load the argument type from the scan result.
63
- *
64
- * @param scanResult Result of the scan
65
- * @param parentName Class called
66
- * @param fnName Function called
67
- * @param argName Argument name
68
- * @returns The type of the argument
15
+ * @param module The module to load the object from.
16
+ * @param parentName The name of the parent object.
69
17
  */
70
- export function loadArgType(scanResult, parentName, fnName, argName) {
71
- const classTypeDef = scanResult.classes[parentName];
72
- if (!classTypeDef) {
73
- throw new Error(`could not find class ${parentName}`);
74
- }
75
- // Call for the constructor
76
- if (fnName === "") {
77
- const argTypeDef = classTypeDef.constructor?.args[argName];
78
- if (!argTypeDef) {
79
- throw new Error(`could not find argument ${argName} type in constructor`);
80
- }
81
- return argTypeDef.typeDef;
82
- }
83
- const methodTypeDef = classTypeDef.methods[fnName];
84
- if (!methodTypeDef) {
85
- throw new Error(`could not find method ${fnName}`);
86
- }
87
- const argTypeDef = methodTypeDef.args[argName];
88
- if (!argTypeDef) {
89
- throw new Error(`could not find argument ${argName} type`);
90
- }
91
- return argTypeDef.typeDef;
18
+ export function loadInvokedObject(module, parentName) {
19
+ return module.objects[parentName];
92
20
  }
93
- /**
94
- * Load the property type from the scan result.
95
- *
96
- * @param scanResult Result of the scan
97
- * @param parentName Class called
98
- * @param propertyName property of the class
99
- * @returns the type of the property
100
- */
101
- export function loadPropertyType(scanResult, parentName, propertyName) {
102
- const classTypeDef = scanResult.classes[parentName];
103
- if (!classTypeDef) {
104
- throw new Error(`could not find class ${parentName}`);
105
- }
106
- const propertyTypeDef = classTypeDef.fields[propertyName];
107
- if (!propertyTypeDef) {
108
- throw new Error(`could not find property ${propertyName} type`);
21
+ export function loadInvokedMethod(object, ctx) {
22
+ if (ctx.fnName === "") {
23
+ return object._constructor;
109
24
  }
110
- return propertyTypeDef.typeDef;
25
+ return object.methods[ctx.fnName];
111
26
  }
112
27
  /**
113
- * Load the true name from the scan result
28
+ * Load the values of the arguments from the context.
114
29
  *
115
- * @param scanResult Result of the scan
116
- * @param parentName Class called
117
- * @param alias exposed name
118
- * @param kind location of the alias
30
+ * @param method Method to load the arguments from.
31
+ * @param ctx The context of the invocation.
119
32
  */
120
- export function loadName(scanResult, parentName, alias, kind) {
121
- const classTypeDef = scanResult.classes[parentName];
122
- if (!classTypeDef) {
123
- throw new Error(`could not find class ${parentName}`);
124
- }
125
- switch (kind) {
126
- case "object": {
127
- return classTypeDef.name;
33
+ export async function loadArgs(method, ctx) {
34
+ const args = {};
35
+ // Load arguments
36
+ for (const argName of method.getArgOrder()) {
37
+ const argument = method.arguments[argName];
38
+ if (!argument) {
39
+ throw new Error(`could not find argument ${argName}`);
128
40
  }
129
- case "function": {
130
- // Handle constructor
131
- if (alias === "") {
132
- return "";
133
- }
134
- const methodTypeDef = classTypeDef.methods[alias];
135
- if (!methodTypeDef) {
136
- throw new Error(`could not find method ${alias} type`);
41
+ const loadedArg = await loadValue(ctx.fnArgs[argName], argument.type);
42
+ // If the argument is variadic, we need to load each args independently
43
+ // so it's correctly propagated when it's sent to the function.
44
+ // Note: variadic args are always last in the list of args.
45
+ if (argument.isVariadic) {
46
+ for (const [i, arg] of (loadedArg ?? []).entries()) {
47
+ args[`${argName}${i}`] = arg;
137
48
  }
138
- return methodTypeDef.name;
49
+ continue;
139
50
  }
140
- case "field": {
141
- const propertyTypeDef = classTypeDef.fields[alias];
142
- if (!propertyTypeDef) {
143
- throw new Error(`could not find property ${alias}`);
144
- }
145
- return propertyTypeDef.name;
51
+ // If the argument is nullable and the loaded arg is undefined with no default value, we set it to null.
52
+ if (argument.isNullable &&
53
+ loadedArg === undefined &&
54
+ !argument.defaultValue) {
55
+ args[argName] = null;
56
+ continue;
146
57
  }
58
+ args[argName] = loadedArg;
147
59
  }
60
+ return args;
148
61
  }
149
62
  /**
150
- * Load the alias from the true property name.
151
- * If not found, return the original alias because it's not
152
- * a registered field.
153
- *
154
- * @param scanResult Result of the scan
155
- * @param parentName Class called
156
- * @param alias exposed name
157
- */
158
- export function loadResultAlias(scanResult, parentName, alias) {
159
- const classTypeDef = scanResult.classes[parentName];
160
- if (!classTypeDef) {
161
- return alias;
162
- }
163
- const fieldTypeDef = Object.values(classTypeDef.fields).find((field) => field.name === alias);
164
- if (!fieldTypeDef) {
165
- return alias;
166
- }
167
- return fieldTypeDef.alias ?? fieldTypeDef.name;
168
- }
169
- /**
170
- * Return the eventual parent name of a field if its return type is a
171
- * registered object.
172
- * If not found, return the original parent name.
63
+ * Load the state of the parent object from the context.
173
64
  *
174
- * @param scanResult The result of the scan.
175
- * @param parentName Original parent name
176
- * @param alias The field alias
65
+ * @param object The object to load the parent state from.
66
+ * @param ctx The context of the invocation.
177
67
  */
178
- export function loadAliasParentName(scanResult, parentName, alias) {
179
- const classTypeDef = scanResult.classes[parentName];
180
- if (!classTypeDef) {
181
- return parentName;
182
- }
183
- const fieldTypeDef = Object.values(classTypeDef.fields).find((field) => field.name === alias);
184
- if (!fieldTypeDef) {
185
- return parentName;
186
- }
187
- if (fieldTypeDef.typeDef.kind === TypeDefKind.ObjectKind) {
188
- return fieldTypeDef.typeDef.name;
68
+ export async function loadParentState(object, ctx) {
69
+ const parentState = {};
70
+ for (const [key, value] of Object.entries(ctx.parentArgs)) {
71
+ const property = object.properties[key];
72
+ if (!property) {
73
+ throw new Error(`could not find parent property ${key}`);
74
+ }
75
+ parentState[property.name] = await loadValue(value, property.type);
189
76
  }
190
- return parentName;
77
+ return parentState;
191
78
  }
192
79
  /**
193
- * This function load the argument as a Dagger type.
80
+ * This function load the value as a Dagger type.
194
81
  *
195
82
  * Note: The JSON.parse() is required to remove extra quotes
196
83
  */
197
- export async function loadArg(value, type) {
84
+ export async function loadValue(value, type) {
198
85
  // If value is undefinied, return it directly.
199
86
  if (value === undefined) {
200
87
  return value;
201
88
  }
202
89
  switch (type.kind) {
203
90
  case TypeDefKind.ListKind:
204
- return Promise.all(value.map(async (v) => await loadArg(v, type.typeDef)));
91
+ return Promise.all(value.map(async (v) => await loadValue(v, type.typeDef)));
205
92
  case TypeDefKind.ObjectKind: {
206
93
  const objectType = type.name;
207
94
  // Workaround to call get any object that has an id
@@ -215,7 +102,7 @@ export async function loadArg(value, type) {
215
102
  // TODO(supports subfields serialization)
216
103
  return value;
217
104
  }
218
- // Cannot use , to specify multiple matching case so instead we use fallthrough.
105
+ // Cannot use `,` to specify multiple matching case so instead we use fallthrough.
219
106
  case TypeDefKind.StringKind:
220
107
  case TypeDefKind.IntegerKind:
221
108
  case TypeDefKind.BooleanKind:
@@ -226,30 +113,60 @@ export async function loadArg(value, type) {
226
113
  }
227
114
  }
228
115
  /**
229
- * Load subfields of the result and IDable object.
116
+ * Load the object type from the return type of the method.
117
+ * This covers the case where the return type is an other object of the module.
118
+ * For example: `msg(): Message` where message is an object of the module.
230
119
  *
231
- * @param result The result of the invocation.
232
- * @param scanResult The result of the scan.
233
- * @param parentName The name of the parent object.
234
- * @returns Loaded result.
120
+ * @param module The module to load the object from.
121
+ * @param object The current object to load the return type from.
122
+ * @param method The method to load the return type from.
235
123
  */
236
- export async function loadResult(result, scanResult, parentName) {
124
+ export function loadObjectReturnType(module, object, method) {
125
+ const retType = method.returnType;
126
+ switch (retType.kind) {
127
+ case TypeDefKind.ListKind: {
128
+ // Loop until we find the original object type.
129
+ // This way we handle the list of list (e.g Object[][][]...[])
130
+ let listType = retType;
131
+ while (listType.kind === TypeDefKind.ListKind) {
132
+ listType = listType.typeDef;
133
+ }
134
+ return module.objects[listType.name];
135
+ }
136
+ case TypeDefKind.ObjectKind:
137
+ return module.objects[retType.name];
138
+ default:
139
+ return object;
140
+ }
141
+ }
142
+ export async function loadResult(result, module, object) {
237
143
  // Handle IDable objects
238
144
  if (result && typeof result?.id === "function") {
239
145
  result = await result.id();
240
146
  }
241
147
  // Handle arrays
242
148
  if (Array.isArray(result)) {
243
- result = await Promise.all(result.map(async (r) => await loadResult(r, scanResult, parentName)));
149
+ result = await Promise.all(result.map(async (r) => await loadResult(r, module, object)));
244
150
  return result;
245
151
  }
246
152
  // Handle objects
247
153
  if (typeof result === "object") {
248
154
  const state = {};
249
155
  for (const [key, value] of Object.entries(result)) {
250
- state[loadResultAlias(scanResult, parentName, key)] = await loadResult(value, scanResult, loadAliasParentName(scanResult, parentName, key));
156
+ const property = Object.values(object.properties).find((p) => p.name === key);
157
+ if (!property) {
158
+ throw new Error(`could not find result property ${key}`);
159
+ }
160
+ if (property.type.kind === TypeDefKind.ObjectKind) {
161
+ const referencedObject = module.objects[property.type.name];
162
+ if (referencedObject) {
163
+ object = referencedObject;
164
+ }
165
+ }
166
+ state[property.alias ?? property.name] = await loadResult(value, module, object);
251
167
  }
252
- result = state;
168
+ return state;
253
169
  }
170
+ // Handle primitive types
254
171
  return result;
255
172
  }
@@ -1,7 +1,7 @@
1
1
  import { ModuleID } from "../api/client.gen.js";
2
- import { ScanResult } from "../introspector/scanner/scan.js";
2
+ import { DaggerModule } from "../introspector/scanner/abtractions/module.js";
3
3
  /**
4
4
  * Register the module files and returns its ID
5
5
  */
6
- export declare function register(files: string[], scanResult: ScanResult): Promise<ModuleID>;
6
+ export declare function register(files: string[], module: DaggerModule): Promise<ModuleID>;
7
7
  //# sourceMappingURL=register.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../entrypoint/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,QAAQ,EAGT,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAU5D;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,QAAQ,CAAC,CA8CnB"}
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../entrypoint/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,QAAQ,EAGT,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAU5E;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,QAAQ,CAAC,CA8CnB"}