datagrok-tools 4.14.42 → 4.14.43

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.
@@ -3,13 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.dgAnnotationTypes = exports.FUNC_TYPES = void 0;
6
+ exports.dgAnnotationTypes = exports.decoratorOptionToAnnotation = exports.FUNC_TYPES = void 0;
7
7
  exports.generateClassFunc = generateClassFunc;
8
8
  exports.generateExport = generateExport;
9
9
  exports.generateFunc = generateFunc;
10
10
  exports.generateImport = generateImport;
11
11
  exports.getFuncAnnotation = getFuncAnnotation;
12
- exports.typesToAny = exports.typesToAnnotation = exports.reservedDecorators = exports.pseudoParams = exports.headerParams = void 0;
12
+ exports.typesToAny = exports.typesToAnnotation = exports.reservedDecorators = exports.pseudoParams = exports.primitives = exports.inputOptionsNames = exports.headerParams = void 0;
13
13
  /* eslint-disable no-unused-vars */
14
14
  /* eslint-disable valid-jsdoc */
15
15
 
@@ -20,8 +20,8 @@ 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', 'help-url', 'condition', 'top-menu', 'cache', 'cache.invalidateOn', 'test'];
24
- const decoratorOptionToAnnotation = new Map([['initialValue', 'default']]);
23
+ const nonMetaData = ['sidebar', 'editor', 'friendlyName', 'helpUrl', 'help-url', 'condition', 'connection', 'top-menu', 'cache', 'cache.invalidateOn', 'test'];
24
+ const decoratorOptionToAnnotation = exports.decoratorOptionToAnnotation = new Map([['initialValue', 'default'], ['helpUrl', 'help-url'], ['topMenu', 'top-menu'], ['metaUrl', 'meta.url'], ['optionsType', 'type'], ['cacheInvalidateOn', 'cache.invalidateOn'], ['scriptHandlerLanguage', 'scriptHandler.language'], ['scriptHandlerExtensions', 'scriptHandler.extensions'], ['scriptHandlerCommentStart', 'scriptHandler.commentStart'], ['scriptHandlerTemplateScript', 'scriptHandler.templateScript'], ['scriptHandlerCodeEditorMode', 'scriptHandler.codeEditorMode'], ['scriptHandlerVectorizationFunction', 'scriptHandler.vectorizationFunction']]);
25
25
  const dgAnnotationTypes = exports.dgAnnotationTypes = {
26
26
  INT: 'int',
27
27
  BIG_INT: 'bigint',
@@ -88,6 +88,7 @@ let FUNC_TYPES = exports.FUNC_TYPES = /*#__PURE__*/function (FUNC_TYPES) {
88
88
  FUNC_TYPES["FUNCTION_ANALYSIS"] = "functionAnalysis";
89
89
  FUNC_TYPES["CONVERTER"] = "converter";
90
90
  FUNC_TYPES["MODEL"] = "model";
91
+ FUNC_TYPES["APP_TREE_BROWSER"] = "appTreeBrowser";
91
92
  return FUNC_TYPES;
92
93
  }({});
93
94
  const typesToAnnotation = exports.typesToAnnotation = {
@@ -95,6 +96,8 @@ const typesToAnnotation = exports.typesToAnnotation = {
95
96
  'DG.DataFrame': 'dataframe',
96
97
  'Column': 'column',
97
98
  'DG.Column': 'column',
99
+ 'Column<any>': 'column',
100
+ 'DG.Column<any>': 'column',
98
101
  'ColumnList': 'column_list',
99
102
  'DG.ColumnList': 'column_list',
100
103
  'FileInfo': 'file',
@@ -143,7 +146,7 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
143
146
  if (input?.options?.type) type = input?.options?.type;else if (annotationType) {
144
147
  if (isArray) type = `list<${annotationType}>`;else type = annotationType;
145
148
  } else type = 'dynamic';
146
- const options = input?.options?.options ? buildStringOfOptions(input.options.options ?? {}) : '';
149
+ const options = input?.options?.options ? buildStringOfOptions(input.options ?? {}) : '';
147
150
  const functionName = (input.options?.name ? input?.options?.name : ` ${input.name?.replaceAll('.', '')}`)?.trim();
148
151
 
149
152
  // eslint-disable-next-line max-len
@@ -158,11 +161,11 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
158
161
  }
159
162
  }
160
163
  if (data.meta) {
161
- for (const entry of Object.entries(data.meta)) s += `${comment}meta.${entry[0]}: ${entry[1]}${sep}`;
164
+ for (const entry of Object.entries(data.meta)) s += `${comment}meta.${decoratorOptionToAnnotation.get(entry[0]) ?? entry[0]}: ${entry[1]}${sep}`;
162
165
  }
163
166
  for (const parameter in data) {
164
167
  // eslint-disable-next-line max-len
165
- if (parameter === pseudoParams.EXTENSION || parameter === pseudoParams.INPUT_TYPE || parameter === 'meta' || parameter === 'isAsync' || parameter === 'test') continue;else if (parameter === pseudoParams.EXTENSIONS) {
168
+ if (parameter === pseudoParams.EXTENSION || parameter === pseudoParams.INPUT_TYPE || parameter === 'meta' || parameter === 'isAsync' || parameter === 'test' || parameter === 'actualTypeObj') continue;else if (parameter === pseudoParams.EXTENSIONS) {
166
169
  if (isFileViewer) continue;
167
170
  s += `${comment}meta.ext: ${data[parameter]}${sep}`;
168
171
  } else if (!headerParams.includes(parameter)) {
@@ -180,9 +183,10 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
180
183
  }
181
184
  return s;
182
185
  }
183
- function buildStringOfOptions(options) {
186
+ const inputOptionsNames = exports.inputOptionsNames = ['semType', 'category', 'optional', 'editor', 'nullable', 'separators', 'choices', 'format', 'min', 'max', 'caption', 'description', 'initialValue', 'viewer', 'units', 'type', 'optionsType', 'step', 'meta.url', 'metaUrl'];
187
+ function buildStringOfOptions(input) {
184
188
  const optionsInString = [];
185
- for (const [key, value] of Object.entries(options ?? {})) {
189
+ for (const [key, value] of Object.entries(input.options ?? {})) {
186
190
  let val = value;
187
191
  let option = key;
188
192
  option = decoratorOptionToAnnotation.get(option) ?? option;
@@ -225,6 +229,21 @@ const reservedDecorators = exports.reservedDecorators = {
225
229
  },
226
230
  genFunc: generateClassFunc
227
231
  },
232
+ appTreeBrowser: {
233
+ metadata: {
234
+ tags: [],
235
+ role: FUNC_TYPES.APP_TREE_BROWSER,
236
+ inputs: [{
237
+ type: 'dynamic',
238
+ name: 'treeNode'
239
+ }, {
240
+ type: 'view',
241
+ name: 'browseView'
242
+ }],
243
+ outputs: []
244
+ },
245
+ genFunc: generateFunc
246
+ },
228
247
  fileExporter: {
229
248
  metadata: {
230
249
  tags: [FUNC_TYPES.FILE_EXPORTER],
@@ -435,16 +454,16 @@ const reservedDecorators = exports.reservedDecorators = {
435
454
  function generateClassFunc(annotation, className, sep = '\n') {
436
455
  return annotation + `export function _${className}() {${sep} return new ${className}();${sep}}${sep.repeat(2)}`;
437
456
  }
438
- const primitives = new Set(['string', 'string[]', 'number', 'number[]', 'boolean', 'boolean[]']);
457
+ const primitives = exports.primitives = new Set(['string', 'string[]', 'number', 'number[]', 'boolean', 'boolean[]', 'any', 'Uint8Array', 'Uint8Array[]', 'void']);
439
458
 
440
459
  /** Generates a DG function. */
441
- function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = [], isAsync = false) {
460
+ function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = [], output, isAsync = false) {
442
461
  // eslint-disable-next-line max-len
443
462
  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(', ');
444
463
  const funcArguments = inputs.map(e => e.name).join(', ');
445
-
464
+ const returnType = output ? primitives.has(output) ? !isAsync ? `: ${output} ` : `: Promise<${output}> ` : !isAsync ? `: any ` : `: Promise<any> ` : '';
446
465
  // eslint-disable-next-line max-len
447
- return sep + annotation + `export ${isAsync ? 'async ' : ''}function ${funcName}(${funcSigNature}) {${sep} return ${className.length > 0 ? `${className}.` : ''}${funcName}(${funcArguments});${sep}}${sep}`;
466
+ return sep + annotation + `export ${isAsync ? 'async ' : ''}function ${funcName}(${funcSigNature}) ${returnType}{${sep} ${output !== 'void' ? 'return ' : ''}${className.length > 0 ? `${className}.` : ''}${funcName}(${funcArguments});${sep}}${sep}`;
448
467
  }
449
468
  function generateImport(className, path, sep = '\n') {
450
469
  return `import {${className}} from '${path}';${sep}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datagrok-tools",
3
- "version": "4.14.42",
3
+ "version": "4.14.43",
4
4
  "description": "Utility to upload and publish packages to Datagrok",
5
5
  "homepage": "https://github.com/datagrok-ai/public/tree/master/tools#readme",
6
6
  "dependencies": {
@@ -11,6 +11,7 @@ const {
11
11
  generateExport,
12
12
  typesToAnnotation,
13
13
  dgAnnotationTypes,
14
+ decoratorOptionToAnnotation,
14
15
  } = require('../bin/utils/func-generation');
15
16
 
16
17
  const {api} = require('../bin/commands/api');
@@ -19,6 +20,30 @@ const baseImport = 'import * as DG from \'datagrok-api/dg\';\n';
19
20
  // eslint-disable-next-line max-len
20
21
  const annotationForGeneratedFile = `/**\nThis file is auto-generated by the webpack command.\nIf you notice any changes, please push them to the repository.\nDo not edit this file manually.\n*/\n`;
21
22
 
23
+
24
+ const inputOptionsNames = [
25
+ 'semType',
26
+ 'category',
27
+ 'optional',
28
+ 'editor',
29
+ 'nullable',
30
+ 'separators',
31
+ 'choices',
32
+ 'format',
33
+ 'min',
34
+ 'max',
35
+ 'caption',
36
+ 'description',
37
+ 'initialValue',
38
+ 'viewer',
39
+ 'units',
40
+ 'optionsType',
41
+ 'step',
42
+ 'meta.url',
43
+ 'metaUrl',
44
+ ];
45
+
46
+
22
47
  class FuncGeneratorPlugin {
23
48
  constructor(options = {outputPath: './src/package.g.ts'}) {
24
49
  this.options = options;
@@ -130,9 +155,19 @@ class FuncGeneratorPlugin {
130
155
  ...(reservedDecorators[name]['metadata']['tags'] ?? []),
131
156
  ...(decoratorOptions.get('tags') ?? []),
132
157
  ]);
158
+
159
+ if ((reservedDecorators[name]['metadata']['role']?.length > 0) ) {
160
+ if (!decoratorOptions.get('meta'))
161
+ decoratorOptions.set('meta', {roles: reservedDecorators[name]['metadata']['role']});
162
+ else if (!decoratorOptions.get('meta')['role'])
163
+ decoratorOptions.get('meta')['role'] = reservedDecorators[name]['metadata']['role'];
164
+ delete reservedDecorators[name]['metadata']['role'];
165
+ }
166
+
133
167
  const functionParams =
134
168
  node?.type === 'MethodDefinition' ? this._readMethodParamas(node) : [];
135
169
  const annotationByReturnObj = node?.type === 'MethodDefinition' ? this._readOutputsFromReturnType(node) : undefined;
170
+
136
171
  const isMethodAsync = this._isMethodAsync(node);
137
172
  const importString = generateImport(
138
173
  node?.type === 'MethodDefinition' ? className : identifierName,
@@ -151,6 +186,15 @@ class FuncGeneratorPlugin {
151
186
  ...{inputs: functionParams},
152
187
  ...{isAsync: isMethodAsync},
153
188
  };
189
+
190
+ let actualType = undefined;
191
+ if (annotationByReturnObj?.length > 1)
192
+ actualType = 'any';
193
+ else if (annotationByReturnObj?.length === 1 && annotationByReturnObj[0]?.actualType)
194
+ actualType = annotationByReturnObj[0].actualType;
195
+ else if (funcAnnotaionOptions.outputs?.length === 0)
196
+ actualType = 'void';
197
+
154
198
  if (!funcAnnotaionOptions.name) funcAnnotaionOptions.name = identifierName;
155
199
  functions.push(
156
200
  reservedDecorators[name]['genFunc'](
@@ -159,6 +203,7 @@ class FuncGeneratorPlugin {
159
203
  '\n',
160
204
  className ?? '',
161
205
  functionParams,
206
+ actualType,
162
207
  funcAnnotaionOptions.isAsync ?? false,
163
208
  ),
164
209
  );
@@ -188,11 +233,28 @@ class FuncGeneratorPlugin {
188
233
  return results;
189
234
  }
190
235
 
191
- _readDecoratorOptions(properties) {
236
+ _readDecoratorOptions(properties, readForParams= false) {
192
237
  const resultMap = new Map();
193
-
194
- for (const prop of properties)
195
- resultMap.set(prop.key.name ?? prop.key.value, this._evalLiteral(prop.value));
238
+ let resultObj = undefined;
239
+ // for (const prop of properties)
240
+ // resultMap.set(prop.key.name ?? prop.key.value, this._evalLiteral(prop.value));
241
+ const optionsToAdd = new Map();
242
+ for (const prop of properties) {
243
+ const key = decoratorOptionToAnnotation.get(prop.key.name ?? prop.key.value ?? '') ?? prop.key.name ?? prop.key.value;
244
+ if (!readForParams && key === 'result')
245
+ resultObj = this._evalLiteral(prop.value);
246
+ else if (readForParams && inputOptionsNames.includes( prop.key.name ?? prop.key.value))
247
+ optionsToAdd.set(key, this._evalLiteral(prop.value));
248
+ else
249
+ resultMap.set(key, this._evalLiteral(prop.value));
250
+
251
+ }
252
+
253
+ if (optionsToAdd.size > 0)
254
+ resultMap.set('options', {...(resultMap.get('options') ?? {}), ...Object.fromEntries(optionsToAdd)});
255
+ if (resultObj)
256
+ resultMap.set('outputs', [resultObj]);
257
+
196
258
  return resultMap;
197
259
  }
198
260
 
@@ -228,11 +290,10 @@ class FuncGeneratorPlugin {
228
290
  param.decorators?.length > 0 ?
229
291
  Object.fromEntries(
230
292
  this._readDecoratorOptions(
231
- param.decorators[0]?.expression?.arguments[0].properties,
232
- ),
293
+ param.decorators[0]?.expression?.arguments[0].properties, true),
233
294
  ) :
234
295
  undefined;
235
-
296
+
236
297
  // Commented code finds value by default of function's variable
237
298
  // let defaultValue = undefined;
238
299
  if (baseParam.type === 'AssignmentPattern') {
@@ -241,7 +302,6 @@ class FuncGeneratorPlugin {
241
302
  baseParam = baseParam?.left;
242
303
  }
243
304
  const optional = param.optional;
244
-
245
305
  if (baseParam.type === 'RestElement' || baseParam.type === 'Identifier') {
246
306
  let name =
247
307
  baseParam.type === 'RestElement' ?
@@ -297,6 +357,7 @@ class FuncGeneratorPlugin {
297
357
 
298
358
  // return { name: name, type: type, options: options };
299
359
  // }
360
+
300
361
  return {name: 'value', type: 'any', options: undefined, optional: optional};
301
362
  });
302
363
  return params;
@@ -380,9 +441,9 @@ class FuncGeneratorPlugin {
380
441
  nodeAnnotation?.elementType?.typeName?.right?.name;
381
442
  }
382
443
  }
383
- resultType = typesToAnnotation[resultType];
384
- if (isArray && resultType) resultType = `list<${resultType}>`;
385
- return resultType ?? 'dynamic';
444
+ let anotationType = typesToAnnotation[resultType];
445
+ if (isArray && anotationType) anotationType = `list<${anotationType}>`;
446
+ return [anotationType ?? 'dynamic', `${resultType}${isArray? '[]': ''}` ?? 'any'];
386
447
  }
387
448
 
388
449
  _readOutputsFromReturnType(node) {
@@ -402,9 +463,14 @@ class FuncGeneratorPlugin {
402
463
  if (annotation?.type === 'TSTypeLiteral')
403
464
  results = this._readOutputsFromReturnTypeObject(annotation);
404
465
  else {
405
- const resultType = this._readReturnType(annotation);
406
- if (resultType !== 'void')
407
- results.push({name: 'result', type: resultType});
466
+ const [annotationType, resultType] = this._readReturnType(annotation);
467
+ if (annotationType !== 'void') {
468
+ results.push({
469
+ name: 'result',
470
+ type: annotationType,
471
+ actualType: resultType,
472
+ });
473
+ }
408
474
  }
409
475
  return results;
410
476
  }
@@ -413,9 +479,11 @@ class FuncGeneratorPlugin {
413
479
  let i = 0;
414
480
  const results = [];
415
481
  for (const member of node.members) {
482
+ const [annotationType, resultType] = this._readReturnType(annotation);
416
483
  results.push({
417
484
  name: member?.key?.name ?? `result${i}`,
418
- type: this._readReturnType(member.typeAnnotation.typeAnnotation),
485
+ type: annotationType,
486
+ actualType: resultType,
419
487
  });
420
488
  i++;
421
489
  }