datagrok-tools 4.14.27 → 4.14.29

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/bin/grok.js CHANGED
@@ -15,31 +15,32 @@ const commands = {
15
15
  link: require('./commands/link').link,
16
16
  publish: require('./commands/publish').publish,
17
17
  test: require('./commands/test').test,
18
- testall: require('./commands/test-all').testAll,
18
+ testall: require('./commands/test-all').testAll,
19
19
  };
20
20
 
21
- const onPackageCommandNames = ['api', 'check', 'link', 'publish', 'test'];
21
+ const onPackageCommandNames = ['api', 'check', 'link', 'publish', 'test'];
22
22
 
23
- const command = argv['_'][0];
23
+ const command = argv['_'][0];
24
24
  if (command in commands) {
25
- try {
26
- if(argv["help"]){
25
+ try {
26
+ if (argv['help']) {
27
27
  console.log(help[command]);
28
28
  exitWithCode(1);
29
29
  }
30
- else if (argv.all && onPackageCommandNames.includes(command)){
31
- runAllCommand(process.cwd(), `grok ${process.argv.slice(2).join(' ')}`.replace('--all', ''), {});
30
+ else if (argv.all && onPackageCommandNames.includes(command)) {
31
+ runAllCommand(process.cwd(),
32
+ `grok ${process.argv.slice(2).join(' ')}`.replace('--all', ''), {});
32
33
  }
33
- else if (!commands[command](argv)) {
34
+ else if (!commands[command](argv)) {
34
35
  console.log(help[command]);
35
36
  exitWithCode(1);
36
37
  }
37
- } catch (err) {
38
+ } catch (err) {
38
39
  console.error(err);
39
40
  console.log(help[command]);
40
41
  exitWithCode(255);
41
42
  }
42
- } else
43
+ } else
43
44
  console.log(help.help);
44
45
 
45
46
 
@@ -9,7 +9,7 @@ exports.generateExport = generateExport;
9
9
  exports.generateFunc = generateFunc;
10
10
  exports.generateImport = generateImport;
11
11
  exports.getFuncAnnotation = getFuncAnnotation;
12
- exports.typesToAnnotation = exports.reservedDecorators = exports.pseudoParams = exports.headerParams = void 0;
12
+ exports.typesToAny = exports.typesToAnnotation = exports.reservedDecorators = exports.pseudoParams = exports.headerParams = void 0;
13
13
  /* eslint-disable no-unused-vars */
14
14
  /* eslint-disable valid-jsdoc */
15
15
 
@@ -23,51 +23,51 @@ let pseudoParams = exports.pseudoParams = /*#__PURE__*/function (pseudoParams) {
23
23
  const nonMetaData = ['sidebar', 'editor'];
24
24
  const decoratorOptionToAnnotation = new Map([['initialValue', 'default']]);
25
25
  const dgAnnotationTypes = exports.dgAnnotationTypes = {
26
- INT: "int",
27
- BIG_INT: "bigint",
28
- FLOAT: "double",
29
- NUM: "num",
30
- QNUM: "qnum",
31
- BOOL: "bool",
32
- STRING: "string",
33
- STRING_LIST: "string_list",
34
- DATE_TIME: "datetime",
35
- OBJECT: "object",
36
- BYTE_ARRAY: "byte_array",
37
- DATA_FRAME: "dataframe",
38
- DATA_FRAME_LIST: "dataframe_list",
39
- CELL: "cell",
40
- COLUMN: "column",
41
- COLUMN_LIST: "column_list",
42
- GRAPHICS: "graphics",
43
- FILE: "file",
44
- BLOB: "blob",
45
- ROW_FILTER: "tablerowfiltercall",
46
- COLUMN_FILTER: "colfiltercall",
47
- BIT_SET: "bitset",
48
- MAP: "map",
49
- DYNAMIC: "dynamic",
50
- VIEWER: "viewer",
51
- LIST: "list",
52
- SEM_VALUE: "semantic_value",
53
- FUNC: "func",
54
- FUNC_CALL: "funccall",
55
- PROPERTY: "property",
56
- CATEGORICAL: "categorical",
57
- NUMERICAL: "numerical",
58
- GRID_CELL_RENDER_ARGS: "GridCellRenderArgs",
59
- ELEMENT: "element",
60
- VIEW: "view",
61
- TABLE_VIEW: "TableView",
62
- USER: "User",
63
- MENU: "Menu",
64
- PROJECT: "Project",
65
- SEMANTIC_VALUE: "semantic_value",
66
- EVENT_DATA: "event_data",
67
- PROGRESS_INDICATOR: "progressindicator",
68
- CREDENTIALS: "Credentials",
69
- SCRIPT_ENVIRONMENT: "ScriptEnvironment",
70
- NOTEBOOK: "Notebook"
26
+ INT: 'int',
27
+ BIG_INT: 'bigint',
28
+ FLOAT: 'double',
29
+ NUM: 'num',
30
+ QNUM: 'qnum',
31
+ BOOL: 'bool',
32
+ STRING: 'string',
33
+ STRING_LIST: 'string_list',
34
+ DATE_TIME: 'datetime',
35
+ OBJECT: 'object',
36
+ BYTE_ARRAY: 'byte_array',
37
+ DATA_FRAME: 'dataframe',
38
+ DATA_FRAME_LIST: 'dataframe_list',
39
+ CELL: 'cell',
40
+ COLUMN: 'column',
41
+ COLUMN_LIST: 'column_list',
42
+ GRAPHICS: 'graphics',
43
+ FILE: 'file',
44
+ BLOB: 'blob',
45
+ ROW_FILTER: 'tablerowfiltercall',
46
+ COLUMN_FILTER: 'colfiltercall',
47
+ BIT_SET: 'bitset',
48
+ MAP: 'map',
49
+ DYNAMIC: 'dynamic',
50
+ VIEWER: 'viewer',
51
+ LIST: 'list',
52
+ SEM_VALUE: 'semantic_value',
53
+ FUNC: 'func',
54
+ FUNC_CALL: 'funccall',
55
+ PROPERTY: 'property',
56
+ CATEGORICAL: 'categorical',
57
+ NUMERICAL: 'numerical',
58
+ GRID_CELL_RENDER_ARGS: 'GridCellRenderArgs',
59
+ ELEMENT: 'element',
60
+ VIEW: 'view',
61
+ TABLE_VIEW: 'TableView',
62
+ USER: 'User',
63
+ MENU: 'Menu',
64
+ PROJECT: 'Project',
65
+ SEMANTIC_VALUE: 'semantic_value',
66
+ EVENT_DATA: 'event_data',
67
+ PROGRESS_INDICATOR: 'progressindicator',
68
+ CREDENTIALS: 'Credentials',
69
+ SCRIPT_ENVIRONMENT: 'ScriptEnvironment',
70
+ NOTEBOOK: 'Notebook'
71
71
  };
72
72
  let FUNC_TYPES = exports.FUNC_TYPES = /*#__PURE__*/function (FUNC_TYPES) {
73
73
  FUNC_TYPES["APP"] = "app";
@@ -119,6 +119,7 @@ const typesToAnnotation = exports.typesToAnnotation = {
119
119
  'void': 'void',
120
120
  'string': 'string'
121
121
  };
122
+ const typesToAny = exports.typesToAny = ['dayjs.Dayjs', 'Dayjs'];
122
123
 
123
124
  /** Generates an annotation header for a function based on provided metadata. */
124
125
  function getFuncAnnotation(data, comment = '//', sep = '\n') {
@@ -130,7 +131,7 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
130
131
  if (data.tags && data.tags?.length > 0) {
131
132
  s += `${comment}tags: ${isFileViewer && data[pseudoParams.EXTENSIONS] ? data.tags.concat(data[pseudoParams.EXTENSIONS].map(ext => 'fileViewer-' + ext)).join(', ') : data.tags.join(', ')}${sep}`;
132
133
  }
133
- for (let input of data.inputs ?? []) {
134
+ for (const input of data.inputs ?? []) {
134
135
  if (!input) continue;
135
136
  let type = input?.type;
136
137
  let isArray = false;
@@ -147,10 +148,12 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
147
148
  s += comment + 'input: ' + type + ' ' + functionName + (input.defaultValue !== undefined ? `= ${input.defaultValue}` : '') + ' ' + options.replaceAll('"', '\'') + sep;
148
149
  }
149
150
  if (data.outputs) {
150
- for (const output of data.outputs) if (output.type !== 'void') s += comment + 'output: ' + output.type + (output.name ? ` ${output.name}${output.options ? ` ${buildStringOfOptions(output.options)}` : ''}` : '') + sep;
151
+ for (const output of data.outputs) {
152
+ if (output.type !== 'void') s += comment + 'output: ' + output.type + (output.name ? ` ${output.name}${output.options ? ` ${buildStringOfOptions(output.options)}` : ''}` : '') + sep;
153
+ }
151
154
  }
152
155
  if (data.meta) {
153
- for (let entry of Object.entries(data.meta)) s += `${comment}meta.${entry[0]}: ${entry[1]}${sep}`;
156
+ for (const entry of Object.entries(data.meta)) s += `${comment}meta.${entry[0]}: ${entry[1]}${sep}`;
154
157
  }
155
158
  for (const parameter in data) {
156
159
  if (parameter === pseudoParams.EXTENSION || parameter === pseudoParams.INPUT_TYPE || parameter === 'meta' || parameter === 'isAsync' || parameter === 'test') continue;else if (parameter === pseudoParams.EXTENSIONS) {
@@ -161,7 +164,7 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
161
164
  }
162
165
  }
163
166
  if (data.test) {
164
- for (let entry of Object.entries(data.test)) {
167
+ for (const entry of Object.entries(data.test)) {
165
168
  if (entry[0] === 'test' || entry[0] === 'wait') s += `${comment}`;else s += `, `;
166
169
  s += `${entry[0]}: ${entry[1]} `;
167
170
  }
@@ -170,7 +173,7 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
170
173
  return s;
171
174
  }
172
175
  function buildStringOfOptions(options) {
173
- let optionsInString = [];
176
+ const optionsInString = [];
174
177
  for (const [key, value] of Object.entries(options ?? {})) {
175
178
  let val = value;
176
179
  let option = key;
@@ -428,8 +431,8 @@ const primitives = new Set(['string', 'string[]', 'number', 'number[]', 'boolean
428
431
 
429
432
  /** Generates a DG function. */
430
433
  function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = [], isAsync = false) {
431
- let funcSigNature = inputs.map(e => `${e.name}: ${primitives.has(e.type ?? '') ? e.type : typesToAnnotation[e.type?.replace('[]', '') ?? ''] ? e.type : 'any'}`).join(', ');
432
- let funcArguments = inputs.map(e => e.name).join(', ');
434
+ 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(', ');
435
+ const funcArguments = inputs.map(e => e.name).join(', ');
433
436
  return sep + annotation + `export ${isAsync ? 'async ' : ''}function ${funcName}(${funcSigNature}) {${sep} return ${className.length > 0 ? `${className}.` : ''}${funcName}(${funcArguments});${sep}}${sep}`;
434
437
  }
435
438
  function generateImport(className, path, sep = '\n') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datagrok-tools",
3
- "version": "4.14.27",
3
+ "version": "4.14.29",
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": {
@@ -460,7 +460,7 @@ class FuncGeneratorPlugin {
460
460
  } else
461
461
  fs.writeFileSync(
462
462
  this.options.outputPath,
463
- `${baseImport}\n${importArray.join("")}`,
463
+ `${annotationForGeneratedFile}${baseImport}\n${importArray.join("")}`,
464
464
  "utf-8"
465
465
  );
466
466
  }