@dagger.io/dagger 0.9.7 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/client.gen.d.ts +648 -59
- package/dist/api/client.gen.d.ts.map +1 -1
- package/dist/api/client.gen.js +1231 -99
- package/dist/common/utils.d.ts +3 -0
- package/dist/common/utils.d.ts.map +1 -1
- package/dist/entrypoint/entrypoint.js +2 -1
- package/dist/entrypoint/invoke.d.ts.map +1 -1
- package/dist/entrypoint/invoke.js +25 -5
- package/dist/entrypoint/load.d.ts +43 -1
- package/dist/entrypoint/load.d.ts.map +1 -1
- package/dist/entrypoint/load.js +116 -11
- package/dist/entrypoint/register.d.ts.map +1 -1
- package/dist/entrypoint/register.js +9 -5
- package/dist/introspector/decorators/decorators.d.ts +3 -3
- package/dist/introspector/decorators/decorators.d.ts.map +1 -1
- package/dist/introspector/registry/registry.d.ts +5 -3
- package/dist/introspector/registry/registry.d.ts.map +1 -1
- package/dist/introspector/registry/registry.js +23 -39
- package/dist/introspector/scanner/metadata.d.ts +1 -0
- package/dist/introspector/scanner/metadata.d.ts.map +1 -1
- package/dist/introspector/scanner/scan.d.ts +5 -1
- package/dist/introspector/scanner/scan.d.ts.map +1 -1
- package/dist/introspector/scanner/scan.js +38 -5
- package/dist/introspector/scanner/serialize.d.ts.map +1 -1
- package/dist/introspector/scanner/serialize.js +8 -2
- package/dist/introspector/scanner/typeDefs.d.ts +3 -0
- package/dist/introspector/scanner/typeDefs.d.ts.map +1 -1
- package/dist/introspector/scanner/utils.d.ts +18 -2
- package/dist/introspector/scanner/utils.d.ts.map +1 -1
- package/dist/introspector/scanner/utils.js +85 -12
- package/dist/provisioning/default.d.ts +1 -1
- package/dist/provisioning/default.js +1 -1
- package/package.json +6 -6
package/dist/common/utils.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const log: (stack?: string) => {
|
|
|
5
5
|
noColor: boolean;
|
|
6
6
|
setLevel(level: "error" | "debug" | "info" | "warn" | "disable" | "success"): void;
|
|
7
7
|
createNamedLogger(name: string): any;
|
|
8
|
+
setLogStream(stream: Stream): any;
|
|
8
9
|
setLevelNoColor(): void;
|
|
9
10
|
setLevelColor(): void;
|
|
10
11
|
isLevelValid(level: "error" | "debug" | "info" | "warn" | "disable" | "success"): boolean;
|
|
@@ -18,6 +19,8 @@ export declare const log: (stack?: string) => {
|
|
|
18
19
|
strikethrough?: boolean | undefined;
|
|
19
20
|
}): string;
|
|
20
21
|
joint(): any;
|
|
22
|
+
append(...args: any[]): any;
|
|
23
|
+
reset(): any;
|
|
21
24
|
setDate(callback: Function): void;
|
|
22
25
|
getDate(): string;
|
|
23
26
|
color(ticket: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white"): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../common/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG,WAAY,MAAM
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../common/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG,WAAY,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACe,CAAA"}
|
|
@@ -14,11 +14,12 @@ export async function entrypoint() {
|
|
|
14
14
|
// Pre list all files of the modules since we need it either for a registration
|
|
15
15
|
// or an invocation
|
|
16
16
|
const files = await listFiles(moduleSrcDirectory);
|
|
17
|
-
const scanResult = await scan(files);
|
|
18
17
|
// Start a Dagger session to get the call context
|
|
19
18
|
await connection(async () => {
|
|
20
19
|
const fnCall = dag.currentFunctionCall();
|
|
20
|
+
const moduleName = await dag.currentModule().name();
|
|
21
21
|
const parentName = await fnCall.parentName();
|
|
22
|
+
const scanResult = await scan(files, moduleName);
|
|
22
23
|
// Pre allocate the result, we got one in both case.
|
|
23
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
25
|
let result;
|
|
@@ -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":"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,5 +1,6 @@
|
|
|
1
|
+
import { TypeDefKind } from "../api/client.gen.js";
|
|
1
2
|
import { registry } from "../introspector/registry/registry.js";
|
|
2
|
-
import { loadArgOrder, loadArg, loadArgType, loadPropertyType, loadResult, } from "./load.js";
|
|
3
|
+
import { loadArgOrder, loadArg, loadArgType, loadPropertyType, loadResult, isArgVariadic, loadName, } from "./load.js";
|
|
3
4
|
/**
|
|
4
5
|
* A wrapper around the registry to invoke a function.
|
|
5
6
|
*
|
|
@@ -13,15 +14,34 @@ export async function invoke(scanResult, { parentName, fnName, parentArgs, fnArg
|
|
|
13
14
|
const args = {};
|
|
14
15
|
// Load function arguments in the right order
|
|
15
16
|
for (const argName of loadArgOrder(scanResult, parentName, fnName)) {
|
|
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
|
+
}
|
|
17
29
|
}
|
|
18
30
|
// Load parent state
|
|
19
31
|
for (const [key, value] of Object.entries(parentArgs)) {
|
|
20
|
-
parentArgs[key] = await loadArg(value, loadPropertyType(scanResult, parentName, key));
|
|
32
|
+
parentArgs[loadName(scanResult, parentName, key, "field")] = await loadArg(value, loadPropertyType(scanResult, parentName, key));
|
|
21
33
|
}
|
|
22
|
-
let result = await registry.getResult(parentName, fnName, parentArgs, args);
|
|
34
|
+
let result = await registry.getResult(loadName(scanResult, parentName, parentName, "object"), loadName(scanResult, parentName, fnName, "function"), parentArgs, args);
|
|
23
35
|
if (result) {
|
|
24
|
-
|
|
36
|
+
// Handle alias serialization by getting the return type to load
|
|
37
|
+
// 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
|
+
}
|
|
43
|
+
}
|
|
44
|
+
result = await loadResult(result, scanResult, parentName);
|
|
25
45
|
}
|
|
26
46
|
return result;
|
|
27
47
|
}
|
|
@@ -18,6 +18,17 @@ export declare function load(files: string[]): Promise<void>;
|
|
|
18
18
|
* @returns An array of strings representing the order of arguments.
|
|
19
19
|
*/
|
|
20
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;
|
|
21
32
|
/**
|
|
22
33
|
* Load the argument type from the scan result.
|
|
23
34
|
*
|
|
@@ -37,6 +48,35 @@ export declare function loadArgType(scanResult: ScanResult, parentName: string,
|
|
|
37
48
|
* @returns the type of the property
|
|
38
49
|
*/
|
|
39
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
|
|
58
|
+
*/
|
|
59
|
+
export declare function loadName(scanResult: ScanResult, parentName: string, alias: string, kind: "field" | "function" | "object"): string;
|
|
60
|
+
/**
|
|
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.
|
|
64
|
+
*
|
|
65
|
+
* @param scanResult Result of the scan
|
|
66
|
+
* @param parentName Class called
|
|
67
|
+
* @param alias exposed name
|
|
68
|
+
*/
|
|
69
|
+
export declare function loadResultAlias(scanResult: ScanResult, parentName: string, alias: string): string;
|
|
70
|
+
/**
|
|
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.
|
|
74
|
+
*
|
|
75
|
+
* @param scanResult The result of the scan.
|
|
76
|
+
* @param parentName Original parent name
|
|
77
|
+
* @param alias The field alias
|
|
78
|
+
*/
|
|
79
|
+
export declare function loadAliasParentName(scanResult: ScanResult, parentName: string, alias: string): string;
|
|
40
80
|
/**
|
|
41
81
|
* This function load the argument as a Dagger type.
|
|
42
82
|
*
|
|
@@ -47,7 +87,9 @@ export declare function loadArg(value: any, type: TypeDef<TypeDefKind>): Promise
|
|
|
47
87
|
* Load subfields of the result and IDable object.
|
|
48
88
|
*
|
|
49
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.
|
|
50
92
|
* @returns Loaded result.
|
|
51
93
|
*/
|
|
52
|
-
export declare function loadResult(result: any): Promise<any>;
|
|
94
|
+
export declare function loadResult(result: any, scanResult: ScanResult, parentName: string): Promise<any>;
|
|
53
95
|
//# 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":"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,CAgBd"}
|
package/dist/entrypoint/load.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { dag, TypeDefKind } from "../api/client.gen.js";
|
|
2
3
|
/**
|
|
3
4
|
* Import all given typescript files so that trigger their decorators
|
|
@@ -32,6 +33,31 @@ export function loadArgOrder(scanResult, parentName, fnName) {
|
|
|
32
33
|
}
|
|
33
34
|
return Object.keys(methodTypeDef.args);
|
|
34
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
|
+
}
|
|
35
61
|
/**
|
|
36
62
|
* Load the argument type from the scan result.
|
|
37
63
|
*
|
|
@@ -83,21 +109,99 @@ export function loadPropertyType(scanResult, parentName, propertyName) {
|
|
|
83
109
|
}
|
|
84
110
|
return propertyTypeDef.typeDef;
|
|
85
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Load the true name from the scan result
|
|
114
|
+
*
|
|
115
|
+
* @param scanResult Result of the scan
|
|
116
|
+
* @param parentName Class called
|
|
117
|
+
* @param alias exposed name
|
|
118
|
+
* @param kind location of the alias
|
|
119
|
+
*/
|
|
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;
|
|
128
|
+
}
|
|
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`);
|
|
137
|
+
}
|
|
138
|
+
return methodTypeDef.name;
|
|
139
|
+
}
|
|
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;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
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.
|
|
173
|
+
*
|
|
174
|
+
* @param scanResult The result of the scan.
|
|
175
|
+
* @param parentName Original parent name
|
|
176
|
+
* @param alias The field alias
|
|
177
|
+
*/
|
|
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;
|
|
189
|
+
}
|
|
190
|
+
return parentName;
|
|
191
|
+
}
|
|
86
192
|
/**
|
|
87
193
|
* This function load the argument as a Dagger type.
|
|
88
194
|
*
|
|
89
195
|
* Note: The JSON.parse() is required to remove extra quotes
|
|
90
196
|
*/
|
|
91
|
-
export async function loadArg(
|
|
92
|
-
//
|
|
93
|
-
value
|
|
94
|
-
|
|
95
|
-
|
|
197
|
+
export async function loadArg(value, type) {
|
|
198
|
+
// If value is undefinied, return it directly.
|
|
199
|
+
if (value === undefined) {
|
|
200
|
+
return value;
|
|
201
|
+
}
|
|
96
202
|
switch (type.kind) {
|
|
97
203
|
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)));
|
|
204
|
+
return Promise.all(value.map(async (v) => await loadArg(v, type.typeDef)));
|
|
101
205
|
case TypeDefKind.ObjectKind: {
|
|
102
206
|
const objectType = type.name;
|
|
103
207
|
// Workaround to call get any object that has an id
|
|
@@ -125,16 +229,17 @@ value, type
|
|
|
125
229
|
* Load subfields of the result and IDable object.
|
|
126
230
|
*
|
|
127
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.
|
|
128
234
|
* @returns Loaded result.
|
|
129
235
|
*/
|
|
130
|
-
|
|
131
|
-
export async function loadResult(result) {
|
|
236
|
+
export async function loadResult(result, scanResult, parentName) {
|
|
132
237
|
if (result && typeof result?.id === "function") {
|
|
133
238
|
result = await result.id();
|
|
134
239
|
}
|
|
135
240
|
if (typeof result === "object") {
|
|
136
241
|
for (const [key, value] of Object.entries(result)) {
|
|
137
|
-
result[key] = await loadResult(value);
|
|
242
|
+
result[loadResultAlias(scanResult, parentName, key)] = await loadResult(value, scanResult, loadAliasParentName(scanResult, parentName, key));
|
|
138
243
|
}
|
|
139
244
|
}
|
|
140
245
|
return result;
|
|
@@ -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,
|
|
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"}
|
|
@@ -3,10 +3,14 @@ import { dag, TypeDefKind, } from "../api/client.gen.js";
|
|
|
3
3
|
* Register the module files and returns its ID
|
|
4
4
|
*/
|
|
5
5
|
export async function register(files, scanResult) {
|
|
6
|
-
// Get
|
|
7
|
-
let mod = dag.
|
|
6
|
+
// Get a new module that we will fill in with all the types
|
|
7
|
+
let mod = dag.module_();
|
|
8
|
+
// Add module description if any.
|
|
9
|
+
if (scanResult.module.description) {
|
|
10
|
+
mod = mod.withDescription(scanResult.module.description);
|
|
11
|
+
}
|
|
8
12
|
// For each class scanned, register its type, method and properties in the module.
|
|
9
|
-
Object.values(scanResult.classes).
|
|
13
|
+
Object.values(scanResult.classes).forEach((modClass) => {
|
|
10
14
|
// Register the class Typedef object in Dagger
|
|
11
15
|
let typeDef = dag.typeDef().withObject(modClass.name, {
|
|
12
16
|
description: modClass.description,
|
|
@@ -18,7 +22,7 @@ export async function register(files, scanResult) {
|
|
|
18
22
|
// Register all fields that belong to this object
|
|
19
23
|
Object.values(modClass.fields).forEach((field) => {
|
|
20
24
|
if (field.isExposed) {
|
|
21
|
-
typeDef = typeDef.withField(field.name, addTypeDef(field.typeDef), {
|
|
25
|
+
typeDef = typeDef.withField(field.alias ?? field.name, addTypeDef(field.typeDef), {
|
|
22
26
|
description: field.description,
|
|
23
27
|
});
|
|
24
28
|
}
|
|
@@ -43,7 +47,7 @@ function addConstructor(constructor, owner) {
|
|
|
43
47
|
*/
|
|
44
48
|
function addFunction(fct) {
|
|
45
49
|
return dag
|
|
46
|
-
.function_(fct.name, addTypeDef(fct.returnType))
|
|
50
|
+
.function_(fct.alias ?? fct.name, addTypeDef(fct.returnType))
|
|
47
51
|
.withDescription(fct.description)
|
|
48
52
|
.with(addArg(fct.args));
|
|
49
53
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const object: <T extends import("../registry/registry.js").Class>(constructor: T) => T;
|
|
2
|
-
export declare const func: (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
3
|
-
export declare const field: (target: object, propertyKey: string) => void;
|
|
1
|
+
export declare const object: () => <T extends import("../registry/registry.js").Class>(constructor: T) => T;
|
|
2
|
+
export declare const func: (alias?: string | undefined) => (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
3
|
+
export declare const field: (alias?: string | undefined) => (target: object, propertyKey: string) => void;
|
|
4
4
|
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../introspector/decorators/decorators.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../introspector/decorators/decorators.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,gFAAkB,CAAA;AACrC,eAAO,MAAM,IAAI,wHAAgB,CAAA;AACjC,eAAO,MAAM,KAAK,+EAAiB,CAAA"}
|
|
@@ -26,17 +26,19 @@ export declare class Registry {
|
|
|
26
26
|
* class module that must be exposed to the Dagger API.
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
|
-
object: <T extends Class>(constructor: T) => T;
|
|
29
|
+
object: () => <T extends Class>(constructor: T) => T;
|
|
30
30
|
/**
|
|
31
31
|
* The definition of @field decorator that should be on top of any
|
|
32
32
|
* class' property that must be exposed to the Dagger API.
|
|
33
|
+
*
|
|
34
|
+
* @param alias The alias to use for the field when exposed on the API.
|
|
33
35
|
*/
|
|
34
|
-
field: (target: object, propertyKey: string) => void;
|
|
36
|
+
field: (alias?: string) => (target: object, propertyKey: string) => void;
|
|
35
37
|
/**
|
|
36
38
|
* The definition of @func decorator that should be on top of any
|
|
37
39
|
* class' method that must be exposed to the Dagger API.
|
|
38
40
|
*/
|
|
39
|
-
func: (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
41
|
+
func: (alias?: string) => (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
40
42
|
/**
|
|
41
43
|
* getResult check for the object and method in the registry and call it
|
|
42
44
|
* with the given input and state.
|
|
@@ -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":"AAGA,OAAO,kBAAkB,CAAA;AAIzB,MAAM,MAAM,KAAK,GAAG;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,CAAA;AAEjD,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;AAU1C;;;;;;;;;;;;;GAaG;AACH,qBAAa,QAAQ;IACnB;;;;OAIG;IACH,MAAM,+CAML;IAED;;;;;OAKG;IACH,KAAK,WAAY,MAAM,cAAa,MAAM,eAAe,MAAM,KAAK,IAAI,CAIvE;IAED;;;OAGG;IACH,IAAI,WACM,MAAM,cAEN,MAAM,eACD,MAAM,GAAG,MAAM,cAChB,kBAAkB,KAC3B,IAAI,CAUR;IAED;;;;;;;;;;OAUG;IACG,SAAS,CACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,IAAI,GACX,OAAO,CAAC,GAAG,CAAC;CAiChB;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,UAAiB,CAAA"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
3
|
import "reflect-metadata";
|
|
2
4
|
import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
|
|
3
5
|
/**
|
|
@@ -20,48 +22,33 @@ export class Registry {
|
|
|
20
22
|
* class module that must be exposed to the Dagger API.
|
|
21
23
|
*
|
|
22
24
|
*/
|
|
23
|
-
object = (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
while (proto && proto !== Object.prototype) {
|
|
29
|
-
const ownMethods = Object.getOwnPropertyNames(proto).filter((name) => {
|
|
30
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
|
31
|
-
// Check if the descriptor exist, then if it's a function and finally
|
|
32
|
-
// if the function is owned by the class.
|
|
33
|
-
return (descriptor &&
|
|
34
|
-
typeof descriptor.value === "function" &&
|
|
35
|
-
Object.prototype.hasOwnProperty.call(proto, name));
|
|
36
|
-
});
|
|
37
|
-
methods.push(...ownMethods);
|
|
38
|
-
proto = Object.getPrototypeOf(proto);
|
|
39
|
-
}
|
|
40
|
-
Reflect.defineMetadata(constructor.name, { class_: constructor, methods }, this);
|
|
41
|
-
return constructor;
|
|
25
|
+
object = () => {
|
|
26
|
+
return (constructor) => {
|
|
27
|
+
Reflect.defineMetadata(constructor.name, { class_: constructor }, this);
|
|
28
|
+
return constructor;
|
|
29
|
+
};
|
|
42
30
|
};
|
|
43
31
|
/**
|
|
44
32
|
* The definition of @field decorator that should be on top of any
|
|
45
33
|
* class' property that must be exposed to the Dagger API.
|
|
34
|
+
*
|
|
35
|
+
* @param alias The alias to use for the field when exposed on the API.
|
|
46
36
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
field = (alias) => {
|
|
38
|
+
return (target, propertyKey) => {
|
|
39
|
+
// A placeholder to declare field in the registry.
|
|
40
|
+
};
|
|
50
41
|
};
|
|
51
42
|
/**
|
|
52
43
|
* The definition of @func decorator that should be on top of any
|
|
53
44
|
* class' method that must be exposed to the Dagger API.
|
|
54
45
|
*/
|
|
55
|
-
func = (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
descriptor) => {
|
|
62
|
-
// The logic is done in the object constructor since it's not possible to
|
|
63
|
-
// access the class parent's name from a method constructor without calling
|
|
64
|
-
// the method itself
|
|
46
|
+
func = (alias) => {
|
|
47
|
+
return (target, propertyKey, descriptor) => {
|
|
48
|
+
// The logic is done in the object constructor since it's not possible to
|
|
49
|
+
// access the class parent's name from a method constructor without calling
|
|
50
|
+
// the method itself
|
|
51
|
+
};
|
|
65
52
|
};
|
|
66
53
|
/**
|
|
67
54
|
* getResult check for the object and method in the registry and call it
|
|
@@ -74,9 +61,7 @@ export class Registry {
|
|
|
74
61
|
* @param state The current state of the class
|
|
75
62
|
* @param inputs The input to send to the method to call
|
|
76
63
|
*/
|
|
77
|
-
async getResult(object, method, state, inputs
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
-
) {
|
|
64
|
+
async getResult(object, method, state, inputs) {
|
|
80
65
|
// Retrieve the resolver class from its key
|
|
81
66
|
const resolver = Reflect.getMetadata(object, this);
|
|
82
67
|
if (!resolver) {
|
|
@@ -86,14 +71,13 @@ export class Registry {
|
|
|
86
71
|
if (method === "") {
|
|
87
72
|
return new resolver.class_(...Object.values(inputs));
|
|
88
73
|
}
|
|
74
|
+
// Instantiate the class without calling the constructor
|
|
75
|
+
let r = Object.create(resolver.class_.prototype);
|
|
89
76
|
// Safety check to make sure the method called exist in the class
|
|
90
77
|
// to avoid the app to crash brutally.
|
|
91
|
-
if (!
|
|
78
|
+
if (!r[method]) {
|
|
92
79
|
throw new UnknownDaggerError(`${method} is not registered in the resolver ${object}`, {});
|
|
93
80
|
}
|
|
94
|
-
// Instantiate the class
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
-
let r = new resolver.class_();
|
|
97
81
|
// Apply state to the class
|
|
98
82
|
r = Object.assign(r, state);
|
|
99
83
|
// Execute and return the result
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/metadata.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG;IAC3C,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/metadata.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG;IAC3C,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ClassTypeDef, FunctionTypedef } from "./typeDefs.js";
|
|
2
2
|
export type ScanResult = {
|
|
3
|
+
module: {
|
|
4
|
+
description?: string;
|
|
5
|
+
};
|
|
3
6
|
classes: {
|
|
4
7
|
[name: string]: ClassTypeDef;
|
|
5
8
|
};
|
|
@@ -16,6 +19,7 @@ export type ScanResult = {
|
|
|
16
19
|
* WARNING(28/11/23): This does NOT include arrow style function.
|
|
17
20
|
*
|
|
18
21
|
* @param files List of TypeScript files to introspect.
|
|
22
|
+
* @param moduleName The name of the module to introspect.
|
|
19
23
|
*/
|
|
20
|
-
export declare function scan(files: string[]): ScanResult;
|
|
24
|
+
export declare function scan(files: string[], moduleName?: string): ScanResult;
|
|
21
25
|
//# 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;
|
|
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;AAWtB,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE;QACN,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,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;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,SAAK,GAAG,UAAU,CAoCjE"}
|