datagrok-tools 4.14.28 → 4.14.30
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 +11 -10
- package/bin/utils/func-generation.js +57 -54
- package/package.json +1 -1
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[
|
|
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(),
|
|
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
|
|
|
@@ -20,54 +20,54 @@ let pseudoParams = exports.pseudoParams = /*#__PURE__*/function (pseudoParams) {
|
|
|
20
20
|
pseudoParams["INPUT_TYPE"] = "inputType";
|
|
21
21
|
return pseudoParams;
|
|
22
22
|
}({});
|
|
23
|
-
const nonMetaData = ['sidebar', 'editor'];
|
|
23
|
+
const nonMetaData = ['sidebar', 'editor', 'friendlyName', 'helpUrl'];
|
|
24
24
|
const decoratorOptionToAnnotation = new Map([['initialValue', 'default']]);
|
|
25
25
|
const dgAnnotationTypes = exports.dgAnnotationTypes = {
|
|
26
|
-
INT:
|
|
27
|
-
BIG_INT:
|
|
28
|
-
FLOAT:
|
|
29
|
-
NUM:
|
|
30
|
-
QNUM:
|
|
31
|
-
BOOL:
|
|
32
|
-
STRING:
|
|
33
|
-
STRING_LIST:
|
|
34
|
-
DATE_TIME:
|
|
35
|
-
OBJECT:
|
|
36
|
-
BYTE_ARRAY:
|
|
37
|
-
DATA_FRAME:
|
|
38
|
-
DATA_FRAME_LIST:
|
|
39
|
-
CELL:
|
|
40
|
-
COLUMN:
|
|
41
|
-
COLUMN_LIST:
|
|
42
|
-
GRAPHICS:
|
|
43
|
-
FILE:
|
|
44
|
-
BLOB:
|
|
45
|
-
ROW_FILTER:
|
|
46
|
-
COLUMN_FILTER:
|
|
47
|
-
BIT_SET:
|
|
48
|
-
MAP:
|
|
49
|
-
DYNAMIC:
|
|
50
|
-
VIEWER:
|
|
51
|
-
LIST:
|
|
52
|
-
SEM_VALUE:
|
|
53
|
-
FUNC:
|
|
54
|
-
FUNC_CALL:
|
|
55
|
-
PROPERTY:
|
|
56
|
-
CATEGORICAL:
|
|
57
|
-
NUMERICAL:
|
|
58
|
-
GRID_CELL_RENDER_ARGS:
|
|
59
|
-
ELEMENT:
|
|
60
|
-
VIEW:
|
|
61
|
-
TABLE_VIEW:
|
|
62
|
-
USER:
|
|
63
|
-
MENU:
|
|
64
|
-
PROJECT:
|
|
65
|
-
SEMANTIC_VALUE:
|
|
66
|
-
EVENT_DATA:
|
|
67
|
-
PROGRESS_INDICATOR:
|
|
68
|
-
CREDENTIALS:
|
|
69
|
-
SCRIPT_ENVIRONMENT:
|
|
70
|
-
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 (
|
|
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)
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
432
|
-
|
|
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