@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.
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/api/utils.js +6 -2
- package/dist/common/errors/ExecError.d.ts.map +1 -1
- package/dist/entrypoint/context.d.ts +8 -0
- package/dist/entrypoint/context.d.ts.map +1 -0
- package/dist/entrypoint/invoke.d.ts +3 -9
- package/dist/entrypoint/invoke.d.ts.map +1 -1
- package/dist/entrypoint/invoke.js +17 -28
- package/dist/entrypoint/load.d.ts +29 -69
- package/dist/entrypoint/load.d.ts.map +1 -1
- package/dist/entrypoint/load.js +90 -173
- package/dist/entrypoint/register.d.ts +2 -2
- package/dist/entrypoint/register.d.ts.map +1 -1
- package/dist/entrypoint/register.js +12 -12
- package/dist/introspector/scanner/abtractions/argument.d.ts +75 -0
- package/dist/introspector/scanner/abtractions/argument.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/argument.js +137 -0
- package/dist/introspector/scanner/abtractions/constructor.d.ts +16 -0
- package/dist/introspector/scanner/abtractions/constructor.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/constructor.js +42 -0
- package/dist/introspector/scanner/abtractions/method.d.ts +51 -0
- package/dist/introspector/scanner/abtractions/method.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/method.js +105 -0
- package/dist/introspector/scanner/abtractions/module.d.ts +18 -0
- package/dist/introspector/scanner/abtractions/module.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/module.js +59 -0
- package/dist/introspector/scanner/abtractions/object.d.ts +37 -0
- package/dist/introspector/scanner/abtractions/object.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/object.js +94 -0
- package/dist/introspector/scanner/abtractions/property.d.ts +46 -0
- package/dist/introspector/scanner/abtractions/property.d.ts.map +1 -0
- package/dist/introspector/scanner/abtractions/property.js +93 -0
- package/dist/introspector/scanner/scan.d.ts +2 -1
- package/dist/introspector/scanner/scan.d.ts.map +1 -1
- package/dist/introspector/scanner/scan.js +2 -181
- package/dist/introspector/scanner/serialize.d.ts +0 -24
- package/dist/introspector/scanner/serialize.d.ts.map +1 -1
- package/dist/introspector/scanner/serialize.js +0 -53
- package/dist/introspector/scanner/typeDefs.d.ts +3 -3
- package/dist/introspector/scanner/typeDefs.d.ts.map +1 -1
- package/dist/introspector/scanner/utils.d.ts +1 -57
- package/dist/introspector/scanner/utils.d.ts.map +1 -1
- package/dist/introspector/scanner/utils.js +16 -149
- package/dist/provisioning/bin.d.ts.map +1 -1
- package/dist/provisioning/bin.js +9 -3
- package/dist/provisioning/default.d.ts +1 -1
- package/dist/provisioning/default.js +1 -1
- package/package.json +2 -1
- package/dist/introspector/scanner/metadata.d.ts +0 -24
- package/dist/introspector/scanner/metadata.d.ts.map +0 -1
- /package/dist/{introspector/scanner/metadata.js → entrypoint/context.js} +0 -0
package/dist/api/utils.d.ts.map
CHANGED
|
@@ -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,
|
|
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", {
|
|
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", {
|
|
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;
|
|
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 @@
|
|
|
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 {
|
|
2
|
-
import {
|
|
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(
|
|
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":"
|
|
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 {
|
|
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(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
const method = loadInvokedMethod(object, ctx);
|
|
21
|
+
if (!method) {
|
|
22
|
+
throw new Error(`could not find method ${ctx.fnName}`);
|
|
33
23
|
}
|
|
34
|
-
|
|
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 (
|
|
39
|
-
|
|
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,
|
|
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
|
-
*
|
|
17
|
+
* Return the object invoked from the module.
|
|
13
18
|
*
|
|
14
|
-
* @param
|
|
15
|
-
* @param parentName The name of the
|
|
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
|
|
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
|
|
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
|
|
66
|
-
* @param
|
|
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
|
|
30
|
+
export declare function loadArgs(method: Method | Constructor, ctx: InvokeCtx): Promise<Args>;
|
|
70
31
|
/**
|
|
71
|
-
*
|
|
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
|
|
76
|
-
* @param
|
|
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
|
|
37
|
+
export declare function loadParentState(object: DaggerObject, ctx: InvokeCtx): Promise<Args>;
|
|
80
38
|
/**
|
|
81
|
-
* This function load the
|
|
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
|
|
43
|
+
export declare function loadValue(value: any, type: TypeDef<TypeDefKind>): Promise<any>;
|
|
86
44
|
/**
|
|
87
|
-
* Load
|
|
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
|
|
90
|
-
* @param
|
|
91
|
-
* @param
|
|
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
|
|
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,
|
|
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"}
|
package/dist/entrypoint/load.js
CHANGED
|
@@ -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
|
-
*
|
|
13
|
+
* Return the object invoked from the module.
|
|
14
14
|
*
|
|
15
|
-
* @param
|
|
16
|
-
* @param parentName The name of the
|
|
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
|
|
71
|
-
|
|
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
|
-
|
|
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
|
|
25
|
+
return object.methods[ctx.fnName];
|
|
111
26
|
}
|
|
112
27
|
/**
|
|
113
|
-
* Load the
|
|
28
|
+
* Load the values of the arguments from the context.
|
|
114
29
|
*
|
|
115
|
-
* @param
|
|
116
|
-
* @param
|
|
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
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
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
|
-
|
|
49
|
+
continue;
|
|
139
50
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
|
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
|
|
175
|
-
* @param
|
|
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
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
|
77
|
+
return parentState;
|
|
191
78
|
}
|
|
192
79
|
/**
|
|
193
|
-
* This function load the
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
232
|
-
* @param
|
|
233
|
-
* @param
|
|
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
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
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[],
|
|
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,
|
|
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"}
|