datagrok-tools 4.14.18 → 4.14.19
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/check.js +13 -2
- package/bin/utils/utils.js +9 -7
- package/package-template/package.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/bin/commands/check.js
CHANGED
|
@@ -308,7 +308,7 @@ function checkFuncSignatures(packagePath, files) {
|
|
|
308
308
|
encoding: 'utf-8'
|
|
309
309
|
});
|
|
310
310
|
const functions = getFuncMetadata(content, file.split('.').pop() ?? 'ts');
|
|
311
|
-
for (const f of functions) {
|
|
311
|
+
for (const f of functions.meta) {
|
|
312
312
|
const paramsCheck = checkFunctions.params(f);
|
|
313
313
|
if (!paramsCheck.value) warnings.push(`File ${file}, function ${f.name}:\n${paramsCheck.message}`);
|
|
314
314
|
const roles = functionRoles.filter(role => f.tags?.includes(role));
|
|
@@ -327,6 +327,9 @@ function checkFuncSignatures(packagePath, files) {
|
|
|
327
327
|
if (f.cache) if (!utils.cacheValues.includes(f.cache)) errors.push(`File ${file}, function ${f.name}: unsupposed variable for cache : ${f.cache}`);
|
|
328
328
|
if (f.invalidateOn) if (!utils.isValidCron(f.invalidateOn)) errors.push(`File ${file}, function ${f.name}: unsupposed variable for invalidateOn : ${f.invalidateOn}`);
|
|
329
329
|
}
|
|
330
|
+
functions.warnings.forEach(e => {
|
|
331
|
+
warnings.push(`${e} In the file: ${file}.`);
|
|
332
|
+
});
|
|
330
333
|
}
|
|
331
334
|
for (const [name, files] of namesInFiles) {
|
|
332
335
|
if (files.length > 1) errors.push(`Duplicate names ('${name}'): \n ${files.join('\n ')}`);
|
|
@@ -515,6 +518,7 @@ function warn(warnings) {
|
|
|
515
518
|
}
|
|
516
519
|
function getFuncMetadata(script, fileExtention) {
|
|
517
520
|
const funcData = [];
|
|
521
|
+
const warnings = [];
|
|
518
522
|
let isHeader = false;
|
|
519
523
|
let data = {
|
|
520
524
|
name: '',
|
|
@@ -528,6 +532,10 @@ function getFuncMetadata(script, fileExtention) {
|
|
|
528
532
|
if (match) {
|
|
529
533
|
if (!isHeader) isHeader = true;
|
|
530
534
|
const param = match[1];
|
|
535
|
+
if (!utils.headerTags.includes(param) && !param.includes('meta.')) {
|
|
536
|
+
warnings.push(`Unknown header tag: ${param},`);
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
531
539
|
if (param === 'name') data.name = line.match(utils.nameAnnRegex)?.[2]?.toLocaleLowerCase();else if (param === 'description') data.description = match[2];else if (param === 'input') {
|
|
532
540
|
data.inputs.push({
|
|
533
541
|
type: match[2],
|
|
@@ -560,5 +568,8 @@ function getFuncMetadata(script, fileExtention) {
|
|
|
560
568
|
}
|
|
561
569
|
}
|
|
562
570
|
}
|
|
563
|
-
return
|
|
571
|
+
return {
|
|
572
|
+
meta: funcData,
|
|
573
|
+
warnings
|
|
574
|
+
};
|
|
564
575
|
}
|
package/bin/utils/utils.js
CHANGED
|
@@ -109,7 +109,7 @@ const replacers = exports.replacers = {
|
|
|
109
109
|
FUNC_NAME_LOWERCASE: (s, name) => s.replace(/#{FUNC_NAME_LOWERCASE}/g, friendlyNameToName(name, false)),
|
|
110
110
|
PARAMS_OBJECT: (s, params) => s.replace(/#{PARAMS_OBJECT}/g, params.length ? `{ ${params.map(p => p.name).join(', ')} }` : `{}`),
|
|
111
111
|
OUTPUT_TYPE: (s, type) => s.replace(/#{OUTPUT_TYPE}/g, type),
|
|
112
|
-
TYPED_PARAMS: (s, params) => s.replace(/#{TYPED_PARAMS}/g, params.map(p => `${p.name}: ${p.type}`).join(', '))
|
|
112
|
+
TYPED_PARAMS: (s, params) => s.replace(/#{TYPED_PARAMS}/g, params.map(p => `${p.name}${p.isOptional ? '?' : ''}: ${p.type}`).join(', '))
|
|
113
113
|
};
|
|
114
114
|
class TemplateBuilder {
|
|
115
115
|
static sep = '\n';
|
|
@@ -185,10 +185,10 @@ const dgToTsTypeMap = exports.dgToTsTypeMap = {
|
|
|
185
185
|
const propertyTypes = exports.propertyTypes = ['bool', 'int', 'double', 'string', 'datetime', 'object', 'column', 'dataframe', 'bitset', 'cell', 'string_list', 'map'];
|
|
186
186
|
const headerTags = exports.headerTags = ['name', 'description', 'help-url', 'input', 'output', 'tags', 'sample', 'language', 'returns', 'test', 'sidebar', 'condition', 'top-menu', 'environment', 'require', 'editor-for', 'schedule', 'reference', 'editor', 'meta', 'connection', 'friendlyName'];
|
|
187
187
|
const fileParamRegex = exports.fileParamRegex = {
|
|
188
|
-
py: new RegExp(`^\#\\s*(
|
|
189
|
-
ts: new RegExp(`^\/\/\\s*(
|
|
190
|
-
js: new RegExp(`^\/\/\\s*(
|
|
191
|
-
sql: new RegExp(`^--\\s*(
|
|
188
|
+
py: new RegExp(`^\#\\s*([^:]*): *([^\\s\\[\\{]+) ?([^\\s\\[\\{]+)?[^\\n]*$`),
|
|
189
|
+
ts: new RegExp(`^\/\/\\s*([^:]*): *([^\\s\\[\\{]+) ?([^\\s\\[\\{]+)?[^\\n]*$`),
|
|
190
|
+
js: new RegExp(`^\/\/\\s*([^:]*): *([^\\s\\[\\{]+) ?([^\\s\\[\\{]+)?[^\\n]*$`),
|
|
191
|
+
sql: new RegExp(`^--\\s*([^:]*): *([^\\s\\[\\{]+) ?([^\\s\\[\\{]+)?[^\\n]*$`)
|
|
192
192
|
};
|
|
193
193
|
const nameAnnRegex = exports.nameAnnRegex = /\s*(name[^:]*): ([^\n\r\[\{]+)/;
|
|
194
194
|
const nameRegex = exports.nameRegex = /(?:|(?:static)(?:export )(?:async ))\s+function\s+([a-zA-Z_][a-zA-Z0-9_$]*)\s*\((.*?).*/;
|
|
@@ -201,14 +201,16 @@ function getScriptOutputType(script, comment = '#') {
|
|
|
201
201
|
}
|
|
202
202
|
;
|
|
203
203
|
function getScriptInputs(script, comment = '#') {
|
|
204
|
-
const regex = new RegExp(`${comment}\\s*input:\\s?([a-z_]+)\\s+(\\w+)
|
|
204
|
+
const regex = new RegExp(`${comment}\\s*input:\\s?([a-z_]+)\\s+(\\w+)(?:[^{\\n]*{[^}\\n]*})?`, 'g');
|
|
205
205
|
const inputs = [];
|
|
206
206
|
for (const match of script.matchAll(regex)) {
|
|
207
|
+
const isOptional = /isOptional\s*:\s*true/.test(match[0]);
|
|
207
208
|
const type = dgToTsTypeMap[match[1]] || 'any';
|
|
208
209
|
const name = match[2];
|
|
209
210
|
inputs.push({
|
|
210
211
|
type,
|
|
211
|
-
name
|
|
212
|
+
name,
|
|
213
|
+
isOptional
|
|
212
214
|
});
|
|
213
215
|
}
|
|
214
216
|
return inputs;
|
package/package.json
CHANGED