datagrok-tools 4.14.5 → 4.14.6
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/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/plugins/func-gen-plugin.js +43 -18
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -125,12 +125,7 @@ class FuncGeneratorPlugin {
|
|
|
125
125
|
]);
|
|
126
126
|
const functionParams =
|
|
127
127
|
node?.type === "MethodDefinition" ? this._readMethodParamas(node) : [];
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
const annotationByReturnTypeObj = {
|
|
131
|
-
name: "result",
|
|
132
|
-
type: annotationByReturnType,
|
|
133
|
-
};
|
|
128
|
+
const annotationByReturnObj = node?.type === "MethodDefinition" ? this._readOutputsFromReturnType(node) : undefined;
|
|
134
129
|
const isMethodAsync = this._isMethodAsync(node);
|
|
135
130
|
let importString = generateImport(
|
|
136
131
|
node?.type === "MethodDefinition" ? className : identifierName,
|
|
@@ -142,8 +137,8 @@ class FuncGeneratorPlugin {
|
|
|
142
137
|
}${identifierName}`;
|
|
143
138
|
const funcAnnotaionOptions = {
|
|
144
139
|
...reservedDecorators[name]["metadata"],
|
|
145
|
-
...(
|
|
146
|
-
? { outputs:
|
|
140
|
+
...(annotationByReturnObj
|
|
141
|
+
? { outputs: annotationByReturnObj ?? [] }
|
|
147
142
|
: {}),
|
|
148
143
|
...Object.fromEntries(decoratorOptions),
|
|
149
144
|
...{ inputs: functionParams },
|
|
@@ -345,21 +340,14 @@ class FuncGeneratorPlugin {
|
|
|
345
340
|
}
|
|
346
341
|
}
|
|
347
342
|
|
|
348
|
-
_readReturnType(
|
|
343
|
+
_readReturnType(annotation) {
|
|
349
344
|
let resultType = "dynamic";
|
|
350
|
-
let isArray = false;
|
|
351
|
-
let annotation = node.value?.returnType?.typeAnnotation;
|
|
345
|
+
let isArray = false;
|
|
352
346
|
if (
|
|
353
347
|
annotation &&
|
|
354
348
|
annotation.type !== "TSUnionType" &&
|
|
355
349
|
annotation.type !== "TSIntersectionType"
|
|
356
350
|
) {
|
|
357
|
-
// if (annotation?.typeName?.name === "Promise") {
|
|
358
|
-
// const argumnets = annotation.typeArguments?.params;
|
|
359
|
-
// if (argumnets && argumnets.length === 1) {
|
|
360
|
-
// annotation = argumnets[0];
|
|
361
|
-
// } else annotation = {};
|
|
362
|
-
// }
|
|
363
351
|
|
|
364
352
|
if (annotation.typeName || annotation.type === "TSTypeReference")
|
|
365
353
|
resultType =
|
|
@@ -377,12 +365,49 @@ class FuncGeneratorPlugin {
|
|
|
377
365
|
annotation?.elementType?.typeName?.right?.name;
|
|
378
366
|
}
|
|
379
367
|
}
|
|
380
|
-
|
|
381
368
|
resultType = typesToAnnotation[resultType];
|
|
382
369
|
if (isArray && resultType) resultType = `list`;
|
|
383
370
|
return resultType ?? 'dynamic';
|
|
384
371
|
}
|
|
385
372
|
|
|
373
|
+
_readOutputsFromReturnType(node) {
|
|
374
|
+
let results = [];
|
|
375
|
+
let annotation = node.value?.returnType?.typeAnnotation;
|
|
376
|
+
|
|
377
|
+
if (node?.type === 'ClassDeclaration')
|
|
378
|
+
return [];
|
|
379
|
+
|
|
380
|
+
if (annotation?.typeName?.name === "Promise") {
|
|
381
|
+
const argumnets = annotation.typeArguments?.params;
|
|
382
|
+
if (argumnets && argumnets.length === 1) {
|
|
383
|
+
annotation = argumnets[0];
|
|
384
|
+
} else annotation = {};
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (annotation?.type === "TSTypeLiteral"){
|
|
388
|
+
results = this._readOutputsFromReturnTypeObject(annotation);
|
|
389
|
+
}
|
|
390
|
+
else{
|
|
391
|
+
let resultType = this._readReturnType(annotation);
|
|
392
|
+
results.push({name: 'result', type: resultType});
|
|
393
|
+
if (resultType === 'void')
|
|
394
|
+
results = [];
|
|
395
|
+
}
|
|
396
|
+
return results;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
_readOutputsFromReturnTypeObject(node) {
|
|
400
|
+
let i = 0;
|
|
401
|
+
let results = [];
|
|
402
|
+
for (let member of node.members) {
|
|
403
|
+
results.push({
|
|
404
|
+
name: member?.key?.name ?? `result${i}`,
|
|
405
|
+
type: this._readReturnType(member.typeAnnotation.typeAnnotation),
|
|
406
|
+
});
|
|
407
|
+
i++;
|
|
408
|
+
}
|
|
409
|
+
return results;
|
|
410
|
+
}
|
|
386
411
|
|
|
387
412
|
_getTypeNameFromNode(typeNode) {
|
|
388
413
|
if (typeNode.type === "TSTypeReference") {
|