datagrok-tools 4.14.37 → 4.14.39
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.
|
@@ -20,7 +20,7 @@ let pseudoParams = exports.pseudoParams = /*#__PURE__*/function (pseudoParams) {
|
|
|
20
20
|
pseudoParams["INPUT_TYPE"] = "inputType";
|
|
21
21
|
return pseudoParams;
|
|
22
22
|
}({});
|
|
23
|
-
const nonMetaData = ['sidebar', 'editor', 'friendlyName', 'helpUrl', 'condition', 'top-menu', 'cache', 'cache.invalidateOn'];
|
|
23
|
+
const nonMetaData = ['sidebar', 'editor', 'friendlyName', 'helpUrl', 'help-url', 'condition', 'top-menu', 'cache', 'cache.invalidateOn', 'test'];
|
|
24
24
|
const decoratorOptionToAnnotation = new Map([['initialValue', 'default']]);
|
|
25
25
|
const dgAnnotationTypes = exports.dgAnnotationTypes = {
|
|
26
26
|
INT: 'int',
|
|
@@ -126,7 +126,7 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
|
|
|
126
126
|
const isFileViewer = data.tags?.includes(FUNC_TYPES.FILE_VIEWER) ?? false;
|
|
127
127
|
const isFileImporter = data.tags?.includes(FUNC_TYPES.FILE_HANDLER) ?? false;
|
|
128
128
|
let s = '';
|
|
129
|
-
if (data.name) s += `${comment}name: ${data.name}${sep}`;
|
|
129
|
+
if (data.name && (!data.tags?.includes('init') || data.name !== 'init' && data.name !== '_init')) s += `${comment}name: ${data.name}${sep}`;
|
|
130
130
|
if (pseudoParams.EXTENSION in data && data.tags != null && data.tags.includes(FUNC_TYPES.FILE_EXPORTER)) s += `${comment}description: Save as ${data[pseudoParams.EXTENSION]}${sep}`;else if (data.description) s += `${comment}description: ${data.description}${sep}`;
|
|
131
131
|
if (data.tags && data.tags?.length > 0) {
|
|
132
132
|
s += `${comment}tags: ${isFileViewer && data[pseudoParams.EXTENSIONS] ? data.tags.concat(data[pseudoParams.EXTENSIONS].map(ext => 'fileViewer-' + ext)).join(', ') : data.tags.join(', ')}${sep}`;
|
|
@@ -170,11 +170,13 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
if (data.test) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
if (typeof data.test === 'string') s += `${comment}test: ${data.test}${sep}`;else {
|
|
174
|
+
for (const entry of Object.entries(data.test)) {
|
|
175
|
+
if (entry[0] === 'test' || entry[0] === 'wait') s += `${comment}`;else s += `, `;
|
|
176
|
+
s += `${entry[0]}: ${entry[1]} `;
|
|
177
|
+
}
|
|
178
|
+
s += `${sep}`;
|
|
176
179
|
}
|
|
177
|
-
s += `${sep}`;
|
|
178
180
|
}
|
|
179
181
|
return s;
|
|
180
182
|
}
|
|
@@ -438,7 +440,7 @@ const primitives = new Set(['string', 'string[]', 'number', 'number[]', 'boolean
|
|
|
438
440
|
/** Generates a DG function. */
|
|
439
441
|
function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = [], isAsync = false) {
|
|
440
442
|
// eslint-disable-next-line max-len
|
|
441
|
-
const funcSigNature = inputs.map(e => `${e.name}: ${primitives.has(e.type ?? '') && !typesToAny.includes(e.type ?? '') ? e.type : typesToAnnotation[e.type?.replace('[]', '') ?? ''] && !typesToAny.includes(e.type ?? '') ? e.type : 'any'}`).join(', ');
|
|
443
|
+
const funcSigNature = inputs.map(e => `${e.name}${e.optional ? '?' : ''}: ${primitives.has(e.type ?? '') && !typesToAny.includes(e.type ?? '') ? e.type : typesToAnnotation[e.type?.replace('[]', '') ?? ''] && !typesToAny.includes(e.type ?? '') ? e.type : 'any'}`).join(', ');
|
|
442
444
|
const funcArguments = inputs.map(e => e.name).join(', ');
|
|
443
445
|
|
|
444
446
|
// eslint-disable-next-line max-len
|
package/package.json
CHANGED
|
@@ -237,6 +237,7 @@ class FuncGeneratorPlugin {
|
|
|
237
237
|
// defaultValue = baseParam?.right?.raw;
|
|
238
238
|
baseParam = baseParam?.left;
|
|
239
239
|
}
|
|
240
|
+
const optional = param.optional;
|
|
240
241
|
|
|
241
242
|
if (baseParam.type === 'RestElement' || baseParam.type === 'Identifier') {
|
|
242
243
|
let name =
|
|
@@ -258,8 +259,7 @@ class FuncGeneratorPlugin {
|
|
|
258
259
|
baseParam.typeAnnotation.typeAnnotation.typeArguments?.params;
|
|
259
260
|
if (type !== 'any' && params && params.length > 0)
|
|
260
261
|
type += `<${params.map((e) => e.typeName?.name ?? 'any').join(',')}>`;
|
|
261
|
-
|
|
262
|
-
return {name: name, type: type, options: options};
|
|
262
|
+
return {name: name, type: type, options: options, optional: optional};
|
|
263
263
|
}
|
|
264
264
|
// Commented code belove sets more strong types for ObjectPatterns and ArrayPatterns
|
|
265
265
|
// else if (baseParam.type === 'ObjectPattern' || baseParam.type === 'ArrayPattern') {
|
|
@@ -294,7 +294,7 @@ class FuncGeneratorPlugin {
|
|
|
294
294
|
|
|
295
295
|
// return { name: name, type: type, options: options };
|
|
296
296
|
// }
|
|
297
|
-
return {name: 'value', type: 'any', options: undefined};
|
|
297
|
+
return {name: 'value', type: 'any', options: undefined, optional: optional};
|
|
298
298
|
});
|
|
299
299
|
return params;
|
|
300
300
|
}
|
|
@@ -346,7 +346,7 @@ class FuncGeneratorPlugin {
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
_readReturnType(annotation) {
|
|
349
|
-
let resultType = '
|
|
349
|
+
let resultType = 'void';
|
|
350
350
|
let nodeAnnotation = annotation;
|
|
351
351
|
let isArray = false;
|
|
352
352
|
if (nodeAnnotation?.type === 'TSUnionType' &&
|
|
@@ -376,7 +376,7 @@ class FuncGeneratorPlugin {
|
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
378
|
resultType = typesToAnnotation[resultType];
|
|
379
|
-
if (isArray && resultType) resultType = `list
|
|
379
|
+
if (isArray && resultType) resultType = `list<${resultType}>`;
|
|
380
380
|
return resultType ?? 'dynamic';
|
|
381
381
|
}
|
|
382
382
|
|
|
@@ -398,9 +398,8 @@ class FuncGeneratorPlugin {
|
|
|
398
398
|
results = this._readOutputsFromReturnTypeObject(annotation);
|
|
399
399
|
else {
|
|
400
400
|
const resultType = this._readReturnType(annotation);
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
results = [];
|
|
401
|
+
if (resultType !== 'void')
|
|
402
|
+
results.push({name: 'result', type: resultType});
|
|
404
403
|
}
|
|
405
404
|
return results;
|
|
406
405
|
}
|