@dagger.io/dagger 0.9.8 → 0.9.10
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 +348 -49
- package/dist/api/client.gen.d.ts.map +1 -1
- package/dist/api/client.gen.js +537 -100
- 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 +109 -2
- package/dist/entrypoint/register.d.ts.map +1 -1
- package/dist/entrypoint/register.js +7 -3
- 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 +20 -28
- 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.d.ts.map +1 -1
- package/dist/provisioning/default.js +1 -1
- package/package.json +1 -1
|
@@ -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":"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;;;;;;;;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,CAC3B,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,OAAO,CAAC,GAAG,CAAC,CAsCd;AAED
|
|
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
|
@@ -33,6 +33,31 @@ export function loadArgOrder(scanResult, parentName, fnName) {
|
|
|
33
33
|
}
|
|
34
34
|
return Object.keys(methodTypeDef.args);
|
|
35
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
|
+
}
|
|
36
61
|
/**
|
|
37
62
|
* Load the argument type from the scan result.
|
|
38
63
|
*
|
|
@@ -84,6 +109,86 @@ export function loadPropertyType(scanResult, parentName, propertyName) {
|
|
|
84
109
|
}
|
|
85
110
|
return propertyTypeDef.typeDef;
|
|
86
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
|
+
}
|
|
87
192
|
/**
|
|
88
193
|
* This function load the argument as a Dagger type.
|
|
89
194
|
*
|
|
@@ -124,15 +229,17 @@ export async function loadArg(value, type) {
|
|
|
124
229
|
* Load subfields of the result and IDable object.
|
|
125
230
|
*
|
|
126
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.
|
|
127
234
|
* @returns Loaded result.
|
|
128
235
|
*/
|
|
129
|
-
export async function loadResult(result) {
|
|
236
|
+
export async function loadResult(result, scanResult, parentName) {
|
|
130
237
|
if (result && typeof result?.id === "function") {
|
|
131
238
|
result = await result.id();
|
|
132
239
|
}
|
|
133
240
|
if (typeof result === "object") {
|
|
134
241
|
for (const [key, value] of Object.entries(result)) {
|
|
135
|
-
result[key] = await loadResult(value);
|
|
242
|
+
result[loadResultAlias(scanResult, parentName, key)] = await loadResult(value, scanResult, loadAliasParentName(scanResult, parentName, key));
|
|
136
243
|
}
|
|
137
244
|
}
|
|
138
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"}
|
|
@@ -5,8 +5,12 @@ import { dag, TypeDefKind, } from "../api/client.gen.js";
|
|
|
5
5
|
export async function register(files, scanResult) {
|
|
6
6
|
// Get a new module that we will fill in with all the types
|
|
7
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":"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;
|
|
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"}
|
|
@@ -22,41 +22,33 @@ export class Registry {
|
|
|
22
22
|
* class module that must be exposed to the Dagger API.
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
|
-
object = (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
while (proto && proto !== Object.prototype) {
|
|
31
|
-
const ownMethods = Object.getOwnPropertyNames(proto).filter((name) => {
|
|
32
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
|
33
|
-
// Check if the descriptor exist, then if it's a function and finally
|
|
34
|
-
// if the function is owned by the class.
|
|
35
|
-
return (descriptor &&
|
|
36
|
-
typeof descriptor.value === "function" &&
|
|
37
|
-
Object.prototype.hasOwnProperty.call(proto, name));
|
|
38
|
-
});
|
|
39
|
-
methods.push(...ownMethods);
|
|
40
|
-
proto = Object.getPrototypeOf(proto);
|
|
41
|
-
}
|
|
42
|
-
Reflect.defineMetadata(constructor.name, { class_: constructor, methods }, this);
|
|
43
|
-
return constructor;
|
|
25
|
+
object = () => {
|
|
26
|
+
return (constructor) => {
|
|
27
|
+
Reflect.defineMetadata(constructor.name, { class_: constructor }, this);
|
|
28
|
+
return constructor;
|
|
29
|
+
};
|
|
44
30
|
};
|
|
45
31
|
/**
|
|
46
32
|
* The definition of @field decorator that should be on top of any
|
|
47
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.
|
|
48
36
|
*/
|
|
49
|
-
field = (
|
|
50
|
-
|
|
37
|
+
field = (alias) => {
|
|
38
|
+
return (target, propertyKey) => {
|
|
39
|
+
// A placeholder to declare field in the registry.
|
|
40
|
+
};
|
|
51
41
|
};
|
|
52
42
|
/**
|
|
53
43
|
* The definition of @func decorator that should be on top of any
|
|
54
44
|
* class' method that must be exposed to the Dagger API.
|
|
55
45
|
*/
|
|
56
|
-
func = (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
};
|
|
60
52
|
};
|
|
61
53
|
/**
|
|
62
54
|
* getResult check for the object and method in the registry and call it
|
|
@@ -79,13 +71,13 @@ export class Registry {
|
|
|
79
71
|
if (method === "") {
|
|
80
72
|
return new resolver.class_(...Object.values(inputs));
|
|
81
73
|
}
|
|
74
|
+
// Instantiate the class without calling the constructor
|
|
75
|
+
let r = Object.create(resolver.class_.prototype);
|
|
82
76
|
// Safety check to make sure the method called exist in the class
|
|
83
77
|
// to avoid the app to crash brutally.
|
|
84
|
-
if (!
|
|
78
|
+
if (!r[method]) {
|
|
85
79
|
throw new UnknownDaggerError(`${method} is not registered in the resolver ${object}`, {});
|
|
86
80
|
}
|
|
87
|
-
// Instantiate the class
|
|
88
|
-
let r = new resolver.class_();
|
|
89
81
|
// Apply state to the class
|
|
90
82
|
r = Object.assign(r, state);
|
|
91
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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
|
|
3
3
|
import { serializeSignature, serializeSymbol } from "./serialize.js";
|
|
4
|
-
import { isFunction, isObject, isOptional, isPublicProperty, typeNameToTypedef, } from "./utils.js";
|
|
4
|
+
import { getAlias, isFunction, isMainObject, isObject, isOptional, isPublicProperty, typeNameToTypedef, } from "./utils.js";
|
|
5
5
|
/**
|
|
6
6
|
* Scan the list of TypeScript File using the TypeScript compiler API.
|
|
7
7
|
*
|
|
@@ -11,8 +11,9 @@ import { isFunction, isObject, isOptional, isPublicProperty, typeNameToTypedef,
|
|
|
11
11
|
* WARNING(28/11/23): This does NOT include arrow style function.
|
|
12
12
|
*
|
|
13
13
|
* @param files List of TypeScript files to introspect.
|
|
14
|
+
* @param moduleName The name of the module to introspect.
|
|
14
15
|
*/
|
|
15
|
-
export function scan(files) {
|
|
16
|
+
export function scan(files, moduleName = "") {
|
|
16
17
|
if (files.length === 0) {
|
|
17
18
|
throw new UnknownDaggerError("no files to introspect found", {});
|
|
18
19
|
}
|
|
@@ -20,6 +21,7 @@ export function scan(files) {
|
|
|
20
21
|
const program = ts.createProgram(files, { experimentalDecorators: true });
|
|
21
22
|
const checker = program.getTypeChecker();
|
|
22
23
|
const metadata = {
|
|
24
|
+
module: {},
|
|
23
25
|
classes: {},
|
|
24
26
|
functions: {},
|
|
25
27
|
};
|
|
@@ -32,6 +34,9 @@ export function scan(files) {
|
|
|
32
34
|
// Handle class
|
|
33
35
|
if (ts.isClassDeclaration(node) && isObject(node)) {
|
|
34
36
|
const classTypeDef = introspectClass(checker, node);
|
|
37
|
+
if (isMainObject(classTypeDef.name, moduleName)) {
|
|
38
|
+
metadata.module.description = introspectTopLevelComment(file);
|
|
39
|
+
}
|
|
35
40
|
metadata.classes[classTypeDef.name] = classTypeDef;
|
|
36
41
|
}
|
|
37
42
|
});
|
|
@@ -78,12 +83,12 @@ function introspectClass(checker, node) {
|
|
|
78
83
|
// Handle method from the class.
|
|
79
84
|
if (ts.isMethodDeclaration(member) && isFunction(member)) {
|
|
80
85
|
const fctTypeDef = introspectMethod(checker, member);
|
|
81
|
-
metadata.methods[fctTypeDef.name] = fctTypeDef;
|
|
86
|
+
metadata.methods[fctTypeDef.alias ?? fctTypeDef.name] = fctTypeDef;
|
|
82
87
|
}
|
|
83
88
|
// Handle public properties from the class.
|
|
84
89
|
if (ts.isPropertyDeclaration(member)) {
|
|
85
90
|
const fieldTypeDef = introspectProperty(checker, member);
|
|
86
|
-
metadata.fields[fieldTypeDef.name] = fieldTypeDef;
|
|
91
|
+
metadata.fields[fieldTypeDef.alias ?? fieldTypeDef.name] = fieldTypeDef;
|
|
87
92
|
}
|
|
88
93
|
});
|
|
89
94
|
return metadata;
|
|
@@ -105,6 +110,7 @@ function introspectProperty(checker, property) {
|
|
|
105
110
|
return {
|
|
106
111
|
name,
|
|
107
112
|
description,
|
|
113
|
+
alias: getAlias(property, "field"),
|
|
108
114
|
typeDef: typeNameToTypedef(typeName),
|
|
109
115
|
isExposed: isPublicProperty(property),
|
|
110
116
|
};
|
|
@@ -126,6 +132,7 @@ function introspectConstructor(checker, constructor) {
|
|
|
126
132
|
typeDef: typeNameToTypedef(typeName),
|
|
127
133
|
optional,
|
|
128
134
|
defaultValue,
|
|
135
|
+
isVariadic: false,
|
|
129
136
|
};
|
|
130
137
|
return acc;
|
|
131
138
|
}, {});
|
|
@@ -154,16 +161,42 @@ function introspectMethod(checker, method) {
|
|
|
154
161
|
return {
|
|
155
162
|
name: methodMetadata.name,
|
|
156
163
|
description: methodMetadata.description,
|
|
157
|
-
|
|
164
|
+
alias: getAlias(method, "func"),
|
|
165
|
+
args: methodSignature.params.reduce((acc, { name, typeName, description, optional, defaultValue, isVariadic }) => {
|
|
158
166
|
acc[name] = {
|
|
159
167
|
name,
|
|
160
168
|
typeDef: typeNameToTypedef(typeName),
|
|
161
169
|
description,
|
|
162
170
|
optional,
|
|
163
171
|
defaultValue,
|
|
172
|
+
isVariadic,
|
|
164
173
|
};
|
|
165
174
|
return acc;
|
|
166
175
|
}, {}),
|
|
167
176
|
returnType: typeNameToTypedef(methodSignature.returnType),
|
|
168
177
|
};
|
|
169
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Return the content of the top level comment of the given file.
|
|
181
|
+
*
|
|
182
|
+
* @param file The file to introspect.
|
|
183
|
+
*/
|
|
184
|
+
function introspectTopLevelComment(file) {
|
|
185
|
+
const firstStatement = file.statements[0];
|
|
186
|
+
if (!firstStatement) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
const commentRanges = ts.getLeadingCommentRanges(file.getFullText(), firstStatement.pos);
|
|
190
|
+
if (!commentRanges || commentRanges.length === 0) {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
const commentRange = commentRanges[0];
|
|
194
|
+
const comment = file
|
|
195
|
+
.getFullText()
|
|
196
|
+
.substring(commentRange.pos, commentRange.end)
|
|
197
|
+
.split("\n")
|
|
198
|
+
.slice(1, -1) // Remove start and ending comments characters `/** */`
|
|
199
|
+
.map((line) => line.replace("*", "").trim()) // Remove leading * and spaces
|
|
200
|
+
.join("\n");
|
|
201
|
+
return comment;
|
|
202
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAGjE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,SAAS,EAAE,EAAE,CAAC,SAAS,GACtB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAGjE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,SAAS,EAAE,EAAE,CAAC,SAAS,GACtB,iBAAiB,CAmBnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,MAAM,EAAE,EAAE,CAAC,MAAM,GAChB,cAAc,GAAG;IAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAA;CAAE,CAkBpC;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,CAS5E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
|
|
3
|
-
import { isOptional } from "./utils.js";
|
|
3
|
+
import { isOptional, isVariadic } from "./utils.js";
|
|
4
4
|
/**
|
|
5
5
|
* Convert the function signature from the compiler API into a lighter data type.
|
|
6
6
|
*
|
|
@@ -12,11 +12,17 @@ import { isOptional } from "./utils.js";
|
|
|
12
12
|
export function serializeSignature(checker, signature) {
|
|
13
13
|
return {
|
|
14
14
|
params: signature.parameters.map((param) => {
|
|
15
|
-
|
|
15
|
+
// eslint-disable-next-line prefer-const
|
|
16
|
+
let { optional, defaultValue } = isOptional(param);
|
|
17
|
+
const variadic = isVariadic(param);
|
|
18
|
+
if (variadic) {
|
|
19
|
+
optional = true;
|
|
20
|
+
}
|
|
16
21
|
return {
|
|
17
22
|
...serializeSymbol(checker, param),
|
|
18
23
|
optional,
|
|
19
24
|
defaultValue,
|
|
25
|
+
isVariadic: variadic,
|
|
20
26
|
};
|
|
21
27
|
}),
|
|
22
28
|
returnType: serializeType(checker, signature.getReturnType()),
|
|
@@ -32,6 +32,7 @@ export type TypeDef<T extends BaseTypeDef["kind"]> = T extends TypeDefKind.Objec
|
|
|
32
32
|
*/
|
|
33
33
|
export type FieldTypeDef = {
|
|
34
34
|
name: string;
|
|
35
|
+
alias?: string;
|
|
35
36
|
description: string;
|
|
36
37
|
typeDef: TypeDef<TypeDefKind>;
|
|
37
38
|
isExposed: boolean;
|
|
@@ -44,6 +45,7 @@ export type FunctionArg = {
|
|
|
44
45
|
description: string;
|
|
45
46
|
optional: boolean;
|
|
46
47
|
defaultValue?: string;
|
|
48
|
+
isVariadic: boolean;
|
|
47
49
|
typeDef: TypeDef<TypeDefKind>;
|
|
48
50
|
};
|
|
49
51
|
/**
|
|
@@ -52,6 +54,7 @@ export type FunctionArg = {
|
|
|
52
54
|
export type FunctionTypedef = {
|
|
53
55
|
name: string;
|
|
54
56
|
description: string;
|
|
57
|
+
alias?: string;
|
|
55
58
|
args: {
|
|
56
59
|
[name: string]: FunctionArg;
|
|
57
60
|
};
|