datagrok-tools 4.14.4 → 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/bin/commands/api.js +6 -5
- package/package.json +1 -1
- package/plugins/func-gen-plugin.js +43 -18
package/CHANGELOG.md
CHANGED
package/bin/commands/api.js
CHANGED
|
@@ -20,9 +20,7 @@ const srcDir = _path.default.join(curDir, 'src');
|
|
|
20
20
|
const funcFilePath = _path.default.join(_fs.default.existsSync(srcDir) ? srcDir : curDir, apiFile);
|
|
21
21
|
const packagePath = _path.default.join(curDir, 'package.json');
|
|
22
22
|
const names = new Set();
|
|
23
|
-
|
|
24
|
-
encoding: 'utf-8'
|
|
25
|
-
}));
|
|
23
|
+
let _package = {};
|
|
26
24
|
function generateQueryWrappers() {
|
|
27
25
|
const queriesDir = _path.default.join(curDir, 'queries');
|
|
28
26
|
if (!_fs.default.existsSync(queriesDir)) {
|
|
@@ -45,7 +43,7 @@ function generateQueryWrappers() {
|
|
|
45
43
|
const name = utils.getScriptName(q, utils.commentMap[utils.queryExtension]);
|
|
46
44
|
if (!name) continue;
|
|
47
45
|
checkNameColision(name);
|
|
48
|
-
const tb = new utils.TemplateBuilder(utils.queryWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package
|
|
46
|
+
const tb = new utils.TemplateBuilder(utils.queryWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package?.name ?? '');
|
|
49
47
|
const description = utils.getScriptDescription(q, utils.commentMap[utils.queryExtension]);
|
|
50
48
|
const inputs = utils.getScriptInputs(q, utils.commentMap[utils.queryExtension]);
|
|
51
49
|
const outputType = utils.getScriptOutputType(q, utils.commentMap[utils.queryExtension]);
|
|
@@ -109,7 +107,7 @@ function generateFunctionWrappers() {
|
|
|
109
107
|
outputType = utils.dgToTsTypeMap[outputAnnotation[1]] ?? 'any';
|
|
110
108
|
}
|
|
111
109
|
checkNameColision(name);
|
|
112
|
-
const tb = new utils.TemplateBuilder(utils.scriptWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package
|
|
110
|
+
const tb = new utils.TemplateBuilder(utils.scriptWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package?.name ?? '').replace('PARAMS_OBJECT', annotationInputs).replace('FUNC_DESCRIPTION', description).replace('TYPED_PARAMS', annotationInputs).replace('OUTPUT_TYPE', outputType);
|
|
113
111
|
wrappers.push(tb.build(1));
|
|
114
112
|
}
|
|
115
113
|
}
|
|
@@ -133,6 +131,9 @@ function checkNameColision(name) {
|
|
|
133
131
|
names.add(name);
|
|
134
132
|
}
|
|
135
133
|
function api(args) {
|
|
134
|
+
_package = JSON.parse(_fs.default.readFileSync(packagePath, {
|
|
135
|
+
encoding: 'utf-8'
|
|
136
|
+
}));
|
|
136
137
|
const nOptions = Object.keys(args).length - 1;
|
|
137
138
|
if (args['_'].length !== 1 || nOptions > 0) return false;
|
|
138
139
|
if (!utils.isPackageDir(process.cwd())) {
|
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") {
|