@dagger.io/dagger 0.9.5 → 0.9.7
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/README.md +10 -10
- package/dist/api/client.gen.d.ts +519 -480
- package/dist/api/client.gen.d.ts.map +1 -1
- package/dist/api/client.gen.js +885 -406
- package/dist/entrypoint/entrypoint.d.ts +1 -1
- package/dist/entrypoint/entrypoint.d.ts.map +1 -1
- package/dist/entrypoint/entrypoint.js +13 -25
- package/dist/entrypoint/invoke.d.ts +14 -6
- package/dist/entrypoint/invoke.d.ts.map +1 -1
- package/dist/entrypoint/invoke.js +21 -8
- package/dist/entrypoint/load.d.ts +42 -5
- package/dist/entrypoint/load.d.ts.map +1 -1
- package/dist/entrypoint/load.js +122 -25
- package/dist/entrypoint/register.d.ts +3 -2
- package/dist/entrypoint/register.d.ts.map +1 -1
- package/dist/entrypoint/register.js +15 -16
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/introspector/registry/registry.d.ts +1 -9
- package/dist/introspector/registry/registry.d.ts.map +1 -1
- package/dist/introspector/registry/registry.js +6 -25
- package/dist/introspector/scanner/metadata.d.ts +1 -1
- package/dist/introspector/scanner/scan.d.ts +8 -4
- package/dist/introspector/scanner/scan.d.ts.map +1 -1
- package/dist/introspector/scanner/scan.js +33 -22
- package/dist/introspector/scanner/serialize.d.ts +3 -3
- package/dist/introspector/scanner/serialize.js +3 -3
- package/dist/introspector/scanner/typeDefs.d.ts +16 -7
- package/dist/introspector/scanner/typeDefs.d.ts.map +1 -1
- package/dist/introspector/scanner/utils.js +6 -6
- package/dist/provisioning/default.d.ts +1 -1
- package/dist/provisioning/default.js +1 -1
- package/package.json +5 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function entrypoint(): Promise<void>;
|
|
2
2
|
//# sourceMappingURL=entrypoint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../../entrypoint/entrypoint.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../../entrypoint/entrypoint.ts"],"names":[],"mappings":"AAiBA,wBAAsB,UAAU,kBAyD/B"}
|
|
@@ -2,17 +2,19 @@ import * as path from "path";
|
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import { dag } from "../api/client.gen.js";
|
|
4
4
|
import { connection } from "../connect.js";
|
|
5
|
+
import { scan } from "../introspector/scanner/scan.js";
|
|
5
6
|
import { listFiles } from "../introspector/utils/files.js";
|
|
6
7
|
import { invoke } from "./invoke.js";
|
|
7
|
-
import { load
|
|
8
|
+
import { load } from "./load.js";
|
|
8
9
|
import { register } from "./register.js";
|
|
9
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
11
|
const __dirname = path.dirname(__filename);
|
|
11
12
|
const moduleSrcDirectory = `${__dirname}/../../src/`;
|
|
12
|
-
async function entrypoint() {
|
|
13
|
+
export async function entrypoint() {
|
|
13
14
|
// Pre list all files of the modules since we need it either for a registration
|
|
14
15
|
// or an invocation
|
|
15
16
|
const files = await listFiles(moduleSrcDirectory);
|
|
17
|
+
const scanResult = await scan(files);
|
|
16
18
|
// Start a Dagger session to get the call context
|
|
17
19
|
await connection(async () => {
|
|
18
20
|
const fnCall = dag.currentFunctionCall();
|
|
@@ -23,7 +25,7 @@ async function entrypoint() {
|
|
|
23
25
|
if (parentName === "") {
|
|
24
26
|
// It's a registration, we register the module and assign the module id
|
|
25
27
|
// to the result
|
|
26
|
-
result = await register(files);
|
|
28
|
+
result = await register(files, scanResult);
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
31
|
// Invocation
|
|
@@ -31,30 +33,17 @@ async function entrypoint() {
|
|
|
31
33
|
const parentJson = JSON.parse(await fnCall.parent());
|
|
32
34
|
const fnArgs = await fnCall.inputArgs();
|
|
33
35
|
const args = {};
|
|
34
|
-
const parentArgs = {};
|
|
36
|
+
const parentArgs = parentJson ?? {};
|
|
35
37
|
for (const arg of fnArgs) {
|
|
36
|
-
args[await arg.name()] =
|
|
37
|
-
}
|
|
38
|
-
if (parentJson) {
|
|
39
|
-
for (const [key, value] of Object.entries(parentJson)) {
|
|
40
|
-
parentArgs[key] = await loadArg(value);
|
|
41
|
-
}
|
|
38
|
+
args[await arg.name()] = JSON.parse(await arg.value());
|
|
42
39
|
}
|
|
43
40
|
await load(files);
|
|
44
|
-
result = await invoke(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (typeof result === "object") {
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
-
for (const [key, value] of Object.entries(result)) {
|
|
53
|
-
if (value.id && typeof value.id === "function") {
|
|
54
|
-
result[key] = await value.id();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
41
|
+
result = await invoke(scanResult, {
|
|
42
|
+
parentName,
|
|
43
|
+
fnName,
|
|
44
|
+
parentArgs,
|
|
45
|
+
fnArgs: args,
|
|
46
|
+
});
|
|
58
47
|
}
|
|
59
48
|
// If result is set, we stringify it
|
|
60
49
|
if (result !== undefined && result !== null) {
|
|
@@ -67,4 +56,3 @@ async function entrypoint() {
|
|
|
67
56
|
await fnCall.returnValue(result);
|
|
68
57
|
}, { LogOutput: process.stdout });
|
|
69
58
|
}
|
|
70
|
-
entrypoint();
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { Args
|
|
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
|
+
};
|
|
2
9
|
/**
|
|
3
10
|
* A wrapper around the registry to invoke a function.
|
|
4
11
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
12
|
+
* @param scanResult The result of the scan.
|
|
13
|
+
* @param parentName The name of the parent object.
|
|
14
|
+
* @param fnName The name of the function to call.
|
|
15
|
+
* @param parentArgs The arguments of the parent object.
|
|
16
|
+
* @param fnArgs The arguments of the function to call.
|
|
9
17
|
*/
|
|
10
|
-
export declare function invoke(
|
|
18
|
+
export declare function invoke(scanResult: ScanResult, { parentName, fnName, parentArgs, fnArgs }: InvokeCtx): Promise<any>;
|
|
11
19
|
//# sourceMappingURL=invoke.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../entrypoint/invoke.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,
|
|
1
|
+
{"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../entrypoint/invoke.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,MAAM,sCAAsC,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAS5D,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,CAyBX"}
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { registry } from "../introspector/registry/registry.js";
|
|
2
|
+
import { loadArgOrder, loadArg, loadArgType, loadPropertyType, loadResult, } from "./load.js";
|
|
2
3
|
/**
|
|
3
4
|
* A wrapper around the registry to invoke a function.
|
|
4
5
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
6
|
+
* @param scanResult The result of the scan.
|
|
7
|
+
* @param parentName The name of the parent object.
|
|
8
|
+
* @param fnName The name of the function to call.
|
|
9
|
+
* @param parentArgs The arguments of the parent object.
|
|
10
|
+
* @param fnArgs The arguments of the function to call.
|
|
9
11
|
*/
|
|
10
|
-
export async function invoke(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
export async function invoke(scanResult, { parentName, fnName, parentArgs, fnArgs }) {
|
|
13
|
+
const args = {};
|
|
14
|
+
// Load function arguments in the right order
|
|
15
|
+
for (const argName of loadArgOrder(scanResult, parentName, fnName)) {
|
|
16
|
+
args[argName] = await loadArg(fnArgs[argName], loadArgType(scanResult, parentName, fnName, argName));
|
|
17
|
+
}
|
|
18
|
+
// Load parent state
|
|
19
|
+
for (const [key, value] of Object.entries(parentArgs)) {
|
|
20
|
+
parentArgs[key] = await loadArg(value, loadPropertyType(scanResult, parentName, key));
|
|
21
|
+
}
|
|
22
|
+
let result = await registry.getResult(parentName, fnName, parentArgs, args);
|
|
23
|
+
if (result) {
|
|
24
|
+
result = await loadResult(result);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
14
27
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { TypeDefKind } from "../api/client.gen.js";
|
|
2
|
+
import { ScanResult } from "../introspector/scanner/scan.js";
|
|
3
|
+
import { TypeDef } from "../introspector/scanner/typeDefs.js";
|
|
1
4
|
/**
|
|
2
5
|
* Import all given typescript files so that trigger their decorators
|
|
3
6
|
* and register their class and functions inside the Registry.
|
|
@@ -6,11 +9,45 @@
|
|
|
6
9
|
*/
|
|
7
10
|
export declare function load(files: string[]): Promise<void>;
|
|
8
11
|
/**
|
|
9
|
-
* Load
|
|
12
|
+
* Load the order of arguments for a given function from the scan result.
|
|
10
13
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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 type from the scan result.
|
|
23
|
+
*
|
|
24
|
+
* @param scanResult Result of the scan
|
|
25
|
+
* @param parentName Class called
|
|
26
|
+
* @param fnName Function called
|
|
27
|
+
* @param argName Argument name
|
|
28
|
+
* @returns The type of the argument
|
|
29
|
+
*/
|
|
30
|
+
export declare function loadArgType(scanResult: ScanResult, parentName: string, fnName: string, argName: string): TypeDef<TypeDefKind>;
|
|
31
|
+
/**
|
|
32
|
+
* Load the property type from the scan result.
|
|
33
|
+
*
|
|
34
|
+
* @param scanResult Result of the scan
|
|
35
|
+
* @param parentName Class called
|
|
36
|
+
* @param propertyName property of the class
|
|
37
|
+
* @returns the type of the property
|
|
38
|
+
*/
|
|
39
|
+
export declare function loadPropertyType(scanResult: ScanResult, parentName: string, propertyName: string): TypeDef<TypeDefKind>;
|
|
40
|
+
/**
|
|
41
|
+
* This function load the argument as a Dagger type.
|
|
42
|
+
*
|
|
43
|
+
* Note: The JSON.parse() is required to remove extra quotes
|
|
44
|
+
*/
|
|
45
|
+
export declare function loadArg(value: any, type: TypeDef<TypeDefKind>): Promise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* Load subfields of the result and IDable object.
|
|
48
|
+
*
|
|
49
|
+
* @param result The result of the invocation.
|
|
50
|
+
* @returns Loaded result.
|
|
14
51
|
*/
|
|
15
|
-
export declare function
|
|
52
|
+
export declare function loadResult(result: any): Promise<any>;
|
|
16
53
|
//# sourceMappingURL=load.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../entrypoint/load.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../entrypoint/load.ts"],"names":[],"mappings":"AAAA,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;;;;;;;;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;;;;GAIG;AACH,wBAAsB,OAAO,CAE3B,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GAEzB,OAAO,CAAC,GAAG,CAAC,CAkCd;AAED;;;;;GAKG;AAEH,wBAAsB,UAAU,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAY1D"}
|
package/dist/entrypoint/load.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dag } from "../api/client.gen.js";
|
|
1
|
+
import { dag, TypeDefKind } from "../api/client.gen.js";
|
|
2
2
|
/**
|
|
3
3
|
* Import all given typescript files so that trigger their decorators
|
|
4
4
|
* and register their class and functions inside the Registry.
|
|
@@ -9,36 +9,133 @@ export async function load(files) {
|
|
|
9
9
|
await Promise.all(files.map(async (f) => await import(f)));
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Load
|
|
12
|
+
* Load the order of arguments for a given function from the scan result.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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 function loadArgOrder(scanResult, parentName, fnName) {
|
|
21
|
+
const classTypeDef = scanResult.classes[parentName];
|
|
22
|
+
if (!classTypeDef) {
|
|
23
|
+
throw new Error(`could not find class ${parentName}`);
|
|
24
|
+
}
|
|
25
|
+
// Call for the constructor
|
|
26
|
+
if (fnName === "") {
|
|
27
|
+
return Object.keys(classTypeDef.constructor?.args ?? {});
|
|
28
|
+
}
|
|
29
|
+
const methodTypeDef = classTypeDef.methods[fnName];
|
|
30
|
+
if (!methodTypeDef) {
|
|
31
|
+
throw new Error(`could not find method ${fnName}`);
|
|
32
|
+
}
|
|
33
|
+
return Object.keys(methodTypeDef.args);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Load the argument type from the scan result.
|
|
37
|
+
*
|
|
38
|
+
* @param scanResult Result of the scan
|
|
39
|
+
* @param parentName Class called
|
|
40
|
+
* @param fnName Function called
|
|
41
|
+
* @param argName Argument name
|
|
42
|
+
* @returns The type of the argument
|
|
43
|
+
*/
|
|
44
|
+
export function loadArgType(scanResult, parentName, fnName, argName) {
|
|
45
|
+
const classTypeDef = scanResult.classes[parentName];
|
|
46
|
+
if (!classTypeDef) {
|
|
47
|
+
throw new Error(`could not find class ${parentName}`);
|
|
48
|
+
}
|
|
49
|
+
// Call for the constructor
|
|
50
|
+
if (fnName === "") {
|
|
51
|
+
const argTypeDef = classTypeDef.constructor?.args[argName];
|
|
52
|
+
if (!argTypeDef) {
|
|
53
|
+
throw new Error(`could not find argument ${argName} type in constructor`);
|
|
54
|
+
}
|
|
55
|
+
return argTypeDef.typeDef;
|
|
56
|
+
}
|
|
57
|
+
const methodTypeDef = classTypeDef.methods[fnName];
|
|
58
|
+
if (!methodTypeDef) {
|
|
59
|
+
throw new Error(`could not find method ${fnName}`);
|
|
60
|
+
}
|
|
61
|
+
const argTypeDef = methodTypeDef.args[argName];
|
|
62
|
+
if (!argTypeDef) {
|
|
63
|
+
throw new Error(`could not find argument ${argName} type`);
|
|
64
|
+
}
|
|
65
|
+
return argTypeDef.typeDef;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Load the property type from the scan result.
|
|
69
|
+
*
|
|
70
|
+
* @param scanResult Result of the scan
|
|
71
|
+
* @param parentName Class called
|
|
72
|
+
* @param propertyName property of the class
|
|
73
|
+
* @returns the type of the property
|
|
74
|
+
*/
|
|
75
|
+
export function loadPropertyType(scanResult, parentName, propertyName) {
|
|
76
|
+
const classTypeDef = scanResult.classes[parentName];
|
|
77
|
+
if (!classTypeDef) {
|
|
78
|
+
throw new Error(`could not find class ${parentName}`);
|
|
79
|
+
}
|
|
80
|
+
const propertyTypeDef = classTypeDef.fields[propertyName];
|
|
81
|
+
if (!propertyTypeDef) {
|
|
82
|
+
throw new Error(`could not find property ${propertyName} type`);
|
|
83
|
+
}
|
|
84
|
+
return propertyTypeDef.typeDef;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* This function load the argument as a Dagger type.
|
|
88
|
+
*
|
|
89
|
+
* Note: The JSON.parse() is required to remove extra quotes
|
|
17
90
|
*/
|
|
91
|
+
export async function loadArg(
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
+
value, type
|
|
18
94
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
parsedValue = JSON.parse(value);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
parsedValue = value;
|
|
31
|
-
}
|
|
32
|
-
// If it's a string, it might contain an identifier to load ,or it might be a hidden array
|
|
33
|
-
if (typeof parsedValue === "string") {
|
|
34
|
-
const [source] = parsedValue.split(":");
|
|
35
|
-
const [origin, type] = source.split(".");
|
|
36
|
-
if (origin === "core") {
|
|
95
|
+
) {
|
|
96
|
+
switch (type.kind) {
|
|
97
|
+
case TypeDefKind.ListKind:
|
|
98
|
+
return Promise.all(value.map(
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
+
async (v) => await loadArg(v, type.typeDef)));
|
|
101
|
+
case TypeDefKind.ObjectKind: {
|
|
102
|
+
const objectType = type.name;
|
|
37
103
|
// Workaround to call get any object that has an id
|
|
38
104
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
39
105
|
// @ts-ignore
|
|
40
|
-
|
|
106
|
+
if (dag[`load${objectType}FromID`]) {
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
return dag[`load${objectType}FromID`](value);
|
|
110
|
+
}
|
|
111
|
+
// TODO(supports subfields serialization)
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
// Cannot use , to specify multiple matching case so instead we use fallthrough.
|
|
115
|
+
case TypeDefKind.StringKind:
|
|
116
|
+
case TypeDefKind.IntegerKind:
|
|
117
|
+
case TypeDefKind.BooleanKind:
|
|
118
|
+
case TypeDefKind.VoidKind:
|
|
119
|
+
return value;
|
|
120
|
+
default:
|
|
121
|
+
throw new Error(`unsupported type ${type.kind}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Load subfields of the result and IDable object.
|
|
126
|
+
*
|
|
127
|
+
* @param result The result of the invocation.
|
|
128
|
+
* @returns Loaded result.
|
|
129
|
+
*/
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
131
|
+
export async function loadResult(result) {
|
|
132
|
+
if (result && typeof result?.id === "function") {
|
|
133
|
+
result = await result.id();
|
|
134
|
+
}
|
|
135
|
+
if (typeof result === "object") {
|
|
136
|
+
for (const [key, value] of Object.entries(result)) {
|
|
137
|
+
result[key] = await loadResult(value);
|
|
41
138
|
}
|
|
42
139
|
}
|
|
43
|
-
return
|
|
140
|
+
return result;
|
|
44
141
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ModuleID } from "../api/client.gen";
|
|
1
|
+
import { ModuleID } from "../api/client.gen.js";
|
|
2
|
+
import { ScanResult } from "../introspector/scanner/scan.js";
|
|
2
3
|
/**
|
|
3
4
|
* Register the module files and returns its ID
|
|
4
5
|
*/
|
|
5
|
-
export declare function register(files: string[]): Promise<ModuleID>;
|
|
6
|
+
export declare function register(files: string[], scanResult: ScanResult): Promise<ModuleID>;
|
|
6
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,
|
|
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,CAqCnB"}
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import { dag, TypeDefKind, } from "../api/client.gen";
|
|
2
|
-
import { scan } from "../introspector/scanner/scan.js";
|
|
1
|
+
import { dag, TypeDefKind, } from "../api/client.gen.js";
|
|
3
2
|
/**
|
|
4
3
|
* Register the module files and returns its ID
|
|
5
4
|
*/
|
|
6
|
-
export async function register(files) {
|
|
7
|
-
// Scan all files
|
|
8
|
-
const scanResult = await scan(files);
|
|
5
|
+
export async function register(files, scanResult) {
|
|
9
6
|
// Get the current module
|
|
10
7
|
let mod = dag.currentModule();
|
|
11
8
|
// For each class scanned, register its type, method and properties in the module.
|
|
12
|
-
scanResult.classes.
|
|
9
|
+
Object.values(scanResult.classes).map((modClass) => {
|
|
13
10
|
// Register the class Typedef object in Dagger
|
|
14
11
|
let typeDef = dag.typeDef().withObject(modClass.name, {
|
|
15
12
|
description: modClass.description,
|
|
16
13
|
});
|
|
17
14
|
// Register all functions (methods) to this object
|
|
18
|
-
modClass.methods.forEach((method) => {
|
|
15
|
+
Object.values(modClass.methods).forEach((method) => {
|
|
19
16
|
typeDef = typeDef.withFunction(addFunction(method));
|
|
20
17
|
});
|
|
21
18
|
// Register all fields that belong to this object
|
|
22
|
-
modClass.fields.forEach((field) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
Object.values(modClass.fields).forEach((field) => {
|
|
20
|
+
if (field.isExposed) {
|
|
21
|
+
typeDef = typeDef.withField(field.name, addTypeDef(field.typeDef), {
|
|
22
|
+
description: field.description,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
26
25
|
});
|
|
27
26
|
if (modClass.constructor) {
|
|
28
|
-
typeDef.withConstructor(addConstructor(modClass.constructor, typeDef));
|
|
27
|
+
typeDef = typeDef.withConstructor(addConstructor(modClass.constructor, typeDef));
|
|
29
28
|
}
|
|
30
29
|
// Add it to the module object
|
|
31
30
|
mod = mod.withObject(typeDef);
|
|
@@ -53,7 +52,7 @@ function addFunction(fct) {
|
|
|
53
52
|
*/
|
|
54
53
|
function addArg(args) {
|
|
55
54
|
return function (fct) {
|
|
56
|
-
args.forEach((arg) => {
|
|
55
|
+
Object.values(args).forEach((arg) => {
|
|
57
56
|
const opts = {
|
|
58
57
|
description: arg.description,
|
|
59
58
|
};
|
|
@@ -81,11 +80,11 @@ function addArg(args) {
|
|
|
81
80
|
*/
|
|
82
81
|
function addTypeDef(type) {
|
|
83
82
|
switch (type.kind) {
|
|
84
|
-
case TypeDefKind.
|
|
83
|
+
case TypeDefKind.ObjectKind:
|
|
85
84
|
return dag.typeDef().withObject(type.name);
|
|
86
|
-
case TypeDefKind.
|
|
85
|
+
case TypeDefKind.ListKind:
|
|
87
86
|
return dag.typeDef().withListOf(addTypeDef(type.typeDef));
|
|
88
|
-
case TypeDefKind.
|
|
87
|
+
case TypeDefKind.VoidKind:
|
|
89
88
|
return dag.typeDef().withKind(type.kind).withOptional(true);
|
|
90
89
|
default:
|
|
91
90
|
return dag.typeDef().withKind(type.kind);
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export { GraphQLClient } from "graphql-request";
|
|
|
5
5
|
export { connect, CallbackFct, connection, close } from "./connect.js";
|
|
6
6
|
export { ConnectOpts } from "./connectOpts.js";
|
|
7
7
|
export * from "./introspector/decorators/decorators.js";
|
|
8
|
+
export { entrypoint } from "./entrypoint/entrypoint.js";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,cAAc,yCAAyC,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,cAAc,yCAAyC,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
1
2
|
export type Class = {
|
|
2
3
|
new (...args: any[]): any;
|
|
3
4
|
};
|
|
@@ -20,7 +21,6 @@ export type Args = Record<string, unknown>;
|
|
|
20
21
|
* RegistryClass.
|
|
21
22
|
*/
|
|
22
23
|
export declare class Registry {
|
|
23
|
-
private classes;
|
|
24
24
|
/**
|
|
25
25
|
* The definition of the @object decorator that should be on top of any
|
|
26
26
|
* class module that must be exposed to the Dagger API.
|
|
@@ -49,14 +49,6 @@ export declare class Registry {
|
|
|
49
49
|
* @param inputs The input to send to the method to call
|
|
50
50
|
*/
|
|
51
51
|
getResult(object: string, method: string, state: State, inputs: Args): Promise<any>;
|
|
52
|
-
/**
|
|
53
|
-
* Get the order of argument by reading its content and create an array of its argument
|
|
54
|
-
* We cannot use r[method].prototype because it can be empty depending on the loading.
|
|
55
|
-
* Note(TomChv): This is a workaround until we find something more accurate.
|
|
56
|
-
* @param fct
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
private getArgOrder;
|
|
60
52
|
}
|
|
61
53
|
/**
|
|
62
54
|
* The default registry used in any module.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../introspector/registry/registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../introspector/registry/registry.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAA;AAKzB,MAAM,MAAM,KAAK,GAAG;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,CAAA;AAGjD,MAAM,MAAM,KAAK,GAAG;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAA;AAE/C,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAW1C;;;;;;;;;;;;;GAaG;AACH,qBAAa,QAAQ;IACnB;;;;OAIG;IACH,MAAM,yCA+BL;IAED;;;OAGG;IAEH,KAAK,WAAY,MAAM,eAAe,MAAM,UAE3C;IAED;;;OAGG;IACH,IAAI,WAEM,MAAM,eAED,MAAM,GAAG,MAAM,cAEhB,kBAAkB,UAK/B;IAED;;;;;;;;;;OAUG;IACG,SAAS,CACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,IAAI,GAEX,OAAO,CAAC,GAAG,CAAC;CAkChB;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,UAAiB,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
1
2
|
import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
|
|
2
3
|
/**
|
|
3
4
|
* Registry stores class and method that have the @object decorator.
|
|
@@ -14,7 +15,6 @@ import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
|
|
|
14
15
|
* RegistryClass.
|
|
15
16
|
*/
|
|
16
17
|
export class Registry {
|
|
17
|
-
classes = {};
|
|
18
18
|
/**
|
|
19
19
|
* The definition of the @object decorator that should be on top of any
|
|
20
20
|
* class module that must be exposed to the Dagger API.
|
|
@@ -23,7 +23,7 @@ export class Registry {
|
|
|
23
23
|
object = (constructor) => {
|
|
24
24
|
const methods = [];
|
|
25
25
|
// Create a dummy instance of the constructor to loop through its properties
|
|
26
|
-
// We only register user's method and ignore
|
|
26
|
+
// We only register user's method and ignore TypeScript default method
|
|
27
27
|
let proto = new constructor();
|
|
28
28
|
while (proto && proto !== Object.prototype) {
|
|
29
29
|
const ownMethods = Object.getOwnPropertyNames(proto).filter((name) => {
|
|
@@ -37,8 +37,7 @@ export class Registry {
|
|
|
37
37
|
methods.push(...ownMethods);
|
|
38
38
|
proto = Object.getPrototypeOf(proto);
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
this.classes[constructor.name] = { class_: constructor, methods };
|
|
40
|
+
Reflect.defineMetadata(constructor.name, { class_: constructor, methods }, this);
|
|
42
41
|
return constructor;
|
|
43
42
|
};
|
|
44
43
|
/**
|
|
@@ -79,13 +78,13 @@ export class Registry {
|
|
|
79
78
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
79
|
) {
|
|
81
80
|
// Retrieve the resolver class from its key
|
|
82
|
-
const resolver =
|
|
81
|
+
const resolver = Reflect.getMetadata(object, this);
|
|
83
82
|
if (!resolver) {
|
|
84
83
|
throw new UnknownDaggerError(`${object} is not register as a resolver`, {});
|
|
85
84
|
}
|
|
86
85
|
// If method is nil, apply the constructor.
|
|
87
86
|
if (method === "") {
|
|
88
|
-
return new resolver.class_(...
|
|
87
|
+
return new resolver.class_(...Object.values(inputs));
|
|
89
88
|
}
|
|
90
89
|
// Safety check to make sure the method called exist in the class
|
|
91
90
|
// to avoid the app to crash brutally.
|
|
@@ -97,26 +96,8 @@ export class Registry {
|
|
|
97
96
|
let r = new resolver.class_();
|
|
98
97
|
// Apply state to the class
|
|
99
98
|
r = Object.assign(r, state);
|
|
100
|
-
// Order argument following the arg order and picking argument from the inputs map
|
|
101
|
-
const args = this.getArgOrder(r[method]).map((arg) => inputs[arg]);
|
|
102
99
|
// Execute and return the result
|
|
103
|
-
return await r[method](...
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Get the order of argument by reading its content and create an array of its argument
|
|
107
|
-
* We cannot use r[method].prototype because it can be empty depending on the loading.
|
|
108
|
-
* Note(TomChv): This is a workaround until we find something more accurate.
|
|
109
|
-
* @param fct
|
|
110
|
-
* @private
|
|
111
|
-
*/
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
113
|
-
getArgOrder(fct) {
|
|
114
|
-
const fnStr = fct
|
|
115
|
-
.toString()
|
|
116
|
-
.replace(/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm, "");
|
|
117
|
-
return (fnStr
|
|
118
|
-
.slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")"))
|
|
119
|
-
.match(/\b(\w+)\b(?:(?=\s*[:=?]|,\s*|$))/g) ?? []);
|
|
100
|
+
return await r[method](...Object.values(inputs));
|
|
120
101
|
}
|
|
121
102
|
}
|
|
122
103
|
/**
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { ClassTypeDef, FunctionTypedef } from "./typeDefs.js";
|
|
2
2
|
export type ScanResult = {
|
|
3
|
-
classes:
|
|
4
|
-
|
|
3
|
+
classes: {
|
|
4
|
+
[name: string]: ClassTypeDef;
|
|
5
|
+
};
|
|
6
|
+
functions: {
|
|
7
|
+
[name: string]: FunctionTypedef;
|
|
8
|
+
};
|
|
5
9
|
};
|
|
6
10
|
/**
|
|
7
|
-
* Scan the list of
|
|
11
|
+
* Scan the list of TypeScript File using the TypeScript compiler API.
|
|
8
12
|
*
|
|
9
13
|
* This function introspect files and returns metadata of their class and
|
|
10
14
|
* functions that should be exposed to the Dagger API.
|
|
11
15
|
*
|
|
12
16
|
* WARNING(28/11/23): This does NOT include arrow style function.
|
|
13
17
|
*
|
|
14
|
-
* @param files List of
|
|
18
|
+
* @param files List of TypeScript files to introspect.
|
|
15
19
|
*/
|
|
16
20
|
export declare function scan(files: string[]): ScanResult;
|
|
17
21
|
//# sourceMappingURL=scan.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/scan.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EAIZ,eAAe,EAChB,MAAM,eAAe,CAAA;AAStB,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/scan.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EAIZ,eAAe,EAChB,MAAM,eAAe,CAAA;AAStB,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAA;IACzC,SAAS,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;KAAE,CAAA;CAC/C,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,CA+BhD"}
|