datagrok-tools 4.14.24 → 4.14.26

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # Datagrok-tools changelog
2
2
 
3
+ ## 4.14.26 (2025-07-10)
4
+
5
+ ### Features
6
+
7
+ * Grok Decorators added support for ViewBase type
8
+ * Grok Decorators updated comments and line feeds
9
+ * Grok Api updated comments and line feeds
10
+ * Grok Api minor type update
11
+
3
12
  ## 4.14.19 (2025-06-23)
4
13
 
5
14
  ### Features
@@ -12,6 +12,7 @@ var utils = _interopRequireWildcard(require("../utils/utils"));
12
12
  var color = _interopRequireWildcard(require("../utils/color-utils"));
13
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ const annotationForApiFile = `/**\nThis file is auto-generated by the grok api command.\nIf you notice any changes, please push them to the repository.\nDo not edit this file manually.\n*/\n`;
15
16
  const sep = '\n';
16
17
  const packageFuncDirs = ['package.ts', 'package.g.ts'];
17
18
  const apiFile = 'package-api.ts';
@@ -112,6 +113,7 @@ function generateFunctionWrappers() {
112
113
  saveWrappersToFile('funcs', wrappers);
113
114
  }
114
115
  function saveWrappersToFile(namespaceName, wrappers) {
116
+ if (wrappers.length === 0) return;
115
117
  if (!_fs.default.existsSync(funcFilePath)) createApiFile();
116
118
  const scriptApi = new utils.TemplateBuilder(utils.namespaceTemplate).replace('PACKAGE_NAMESPACE', namespaceName).replace('NAME', wrappers.join(sep.repeat(2)));
117
119
  _fs.default.appendFileSync(funcFilePath, sep + scriptApi.build() + sep);
@@ -122,7 +124,7 @@ function createApiFile() {
122
124
  color.warn(`The file ${funcFilePath} already exists`);
123
125
  console.log('Rewriting its contents...');
124
126
  }
125
- _fs.default.writeFileSync(funcFilePath, utils.dgImports + sep, 'utf8');
127
+ _fs.default.writeFileSync(funcFilePath, annotationForApiFile + utils.dgImports + sep, 'utf8');
126
128
  }
127
129
  function checkNameColision(name) {
128
130
  if (names.has(name)) console.log('There is collision in name ' + name);
@@ -40,7 +40,7 @@ function runChecks(packagePath, soft = false) {
40
40
  path: packagePath,
41
41
  ignoreFiles: ['.npmignore', '.gitignore']
42
42
  }).filter(e => !e.includes('node_modules'));
43
- const jsTsFiles = files.filter(f => !f.startsWith('dist/') && (f.endsWith('.js') || f.endsWith('.ts') || f.endsWith('.sql') || f.endsWith('.py')));
43
+ const jsTsFiles = files.filter(f => (f.startsWith('src' + _path.default.sep) || f.startsWith('queries' + _path.default.sep) || f.startsWith('scripts' + _path.default.sep)) && (f.endsWith('.js') || f.endsWith('.ts') || f.endsWith('.sql') || f.endsWith('.py')));
44
44
  const packageFiles = ['src/package.ts', 'src/detectors.ts', 'src/package.js', 'src/detectors.js', 'src/package-test.ts', 'src/package-test.js', 'package.js', 'detectors.js'];
45
45
  // const funcFiles = jsTsFiles.filter((f) => packageFiles.includes(f));
46
46
  const errors = [];
@@ -305,6 +305,7 @@ function checkFuncSignatures(packagePath, files) {
305
305
  };
306
306
  const functionRoles = Object.keys(checkFunctions);
307
307
  for (const file of files) {
308
+ if (file.includes('.min.')) continue;
308
309
  const content = _fs.default.readFileSync(_path.default.join(packagePath, file), {
309
310
  encoding: 'utf-8'
310
311
  });
@@ -557,6 +558,15 @@ function getFuncMetadata(script, fileExtention) {
557
558
  }
558
559
  if (isHeader) {
559
560
  const nm = line.match(utils.nameRegex);
561
+ if (data.name === '') {
562
+ data = {
563
+ name: '',
564
+ inputs: [],
565
+ outputs: []
566
+ };
567
+ isHeader = false;
568
+ continue;
569
+ }
560
570
  if (nm) data.name = nm[1]?.toLocaleLowerCase();
561
571
  if (data.name && !match) {
562
572
  funcData.push(data);
@@ -207,13 +207,14 @@ async function processPackage(debug, rebuild, host, devKey, packageName, suffix)
207
207
  return 0;
208
208
  }
209
209
  async function publish(args) {
210
- if (!args['skip-check']) (0, _check.check)({
210
+ console.log('publish');
211
+ if (!args['skip-check'] && !args['all']) (0, _check.check)({
211
212
  _: ['check']
212
213
  });
213
214
  config = _jsYaml.default.load(_fs.default.readFileSync(confPath, {
214
215
  encoding: 'utf-8'
215
216
  }));
216
- if (args.refresh || args.all) {
217
+ if (args.refresh) {
217
218
  if (_path.default.basename(curDir) !== 'packages') curDir = _path.default.dirname(curDir);
218
219
  let host = config.default;
219
220
  if (args['_'].length === 2) host = args['_'][1];
@@ -249,6 +250,8 @@ async function publishPackage(args) {
249
250
  if (nArgs > 2 || nOptions > 5) return false;
250
251
  if (!Object.keys(args).slice(1).every(option => ['build', 'rebuild', 'debug', 'release', 'k', 'key', 'suffix'].includes(option))) return false;
251
252
  if (args.build && args.rebuild) {
253
+ utils.runScript('npm install', curDir, false);
254
+ utils.runScript('npm run build', curDir, false);
252
255
  color.error('Incompatible options: --build and --rebuild');
253
256
  return false;
254
257
  }
package/bin/grok.js CHANGED
@@ -3,6 +3,7 @@ const argv = require('minimist')(process.argv.slice(2), {
3
3
  alias: {k: 'key', h: 'help', r: 'recursive'},
4
4
  });
5
5
  const help = require('./commands/help').help;
6
+ const runAllCommand = require('./utils/utils').runAll;
6
7
 
7
8
  const commands = {
8
9
  add: require('./commands/add').add,
@@ -17,13 +18,18 @@ const commands = {
17
18
  testall: require('./commands/test-all').testAll,
18
19
  };
19
20
 
20
- const command = argv['_'][0];
21
+ const onPackageCommandNames = ['api', 'check', 'link', 'publish', 'test'];
22
+
23
+ const command = argv['_'][0];
21
24
  if (command in commands) {
22
25
  try {
23
26
  if(argv["help"]){
24
27
  console.log(help[command]);
25
28
  exitWithCode(1);
26
29
  }
30
+ else if (argv.all && onPackageCommandNames.includes(command)){
31
+ runAllCommand(process.cwd(), `grok ${process.argv.slice(2).join(' ')}`.replace('--all', ''), {});
32
+ }
27
33
  else if (!commands[command](argv)) {
28
34
  console.log(help[command]);
29
35
  exitWithCode(1);
@@ -106,7 +106,9 @@ const typesToAnnotation = exports.typesToAnnotation = {
106
106
  'Dayjs': 'datetime',
107
107
  'graphics': 'graphics',
108
108
  'DG.View': 'view',
109
+ 'DG.ViewBase': 'view',
109
110
  'View': 'view',
111
+ 'ViewBase': 'view',
110
112
  'DG.Widget': 'widget',
111
113
  'Widget': 'widget',
112
114
  'DG.FuncCall': 'funccall',
@@ -428,7 +430,7 @@ const primitives = new Set(['string', 'string[]', 'number', 'number[]', 'boolean
428
430
  function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = [], isAsync = false) {
429
431
  let funcSigNature = inputs.map(e => `${e.name}: ${primitives.has(e.type ?? '') ? e.type : typesToAnnotation[e.type?.replace('[]', '') ?? ''] ? e.type : 'any'}`).join(', ');
430
432
  let funcArguments = inputs.map(e => e.name).join(', ');
431
- return annotation + `export ${isAsync ? 'async ' : ''}function ${funcName}(${funcSigNature}) {${sep} return ${className.length > 0 ? `${className}.` : ''}${funcName}(${funcArguments});${sep}}${sep.repeat(2)}`;
433
+ return sep + annotation + `export ${isAsync ? 'async ' : ''}function ${funcName}(${funcSigNature}) {${sep} return ${className.length > 0 ? `${className}.` : ''}${funcName}(${funcArguments});${sep}}${sep}`;
432
434
  }
433
435
  function generateImport(className, path, sep = '\n') {
434
436
  return `import {${className}} from '${path}';${sep}`;
@@ -27,6 +27,7 @@ exports.mapURL = mapURL;
27
27
  exports.queryWrapperTemplate = exports.queryExtension = exports.propertyTypes = exports.namespaceTemplate = exports.nameRegex = exports.nameAnnRegex = void 0;
28
28
  exports.removeScope = removeScope;
29
29
  exports.replacers = void 0;
30
+ exports.runAll = runAll;
30
31
  exports.runScript = runScript;
31
32
  exports.scriptWrapperTemplate = exports.scriptLangExtMap = exports.scriptExtensions = void 0;
32
33
  exports.setHost = setHost;
@@ -54,7 +55,7 @@ function kebabToCamelCase(s, firstUpper = true) {
54
55
  }
55
56
  function descriptionToComment(s) {
56
57
  if (s.length === 0) return '';
57
- return '//' + s + '\n';
58
+ return '/**\n' + s + '\n*/\n';
58
59
  }
59
60
  function spaceToCamelCase(s, firstUpper = true) {
60
61
  s = s.replace(/\s+./g, x => x[x.length - 1].toUpperCase());
@@ -180,7 +181,8 @@ const dgToTsTypeMap = exports.dgToTsTypeMap = {
180
181
  column: 'DG.Column',
181
182
  column_list: 'string[]',
182
183
  file: 'DG.FileInfo',
183
- view: 'DG.View'
184
+ view: 'DG.View',
185
+ void: 'void'
184
186
  };
185
187
  const propertyTypes = exports.propertyTypes = ['bool', 'int', 'double', 'string', 'datetime', 'object', 'column', 'dataframe', 'bitset', 'cell', 'string_list', 'map'];
186
188
  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'];
@@ -240,7 +242,7 @@ function getScriptDescription(script, comment = '#') {
240
242
  return desc;
241
243
  }
242
244
  ;
243
- const dgImports = exports.dgImports = `import * as grok from 'datagrok-api/grok';\nimport * as DG from 'datagrok-api/dg';\n\n`;
245
+ const dgImports = exports.dgImports = `import * as grok from 'datagrok-api/grok';\nimport * as DG from 'datagrok-api/dg';\n`;
244
246
  const scriptWrapperTemplate = exports.scriptWrapperTemplate = `#{FUNC_DESCRIPTION}export async function #{FUNC_NAME_LOWERCASE}(#{TYPED_PARAMS}): Promise<#{OUTPUT_TYPE}> {
245
247
  return await grok.functions.call('#{PACKAGE_NAMESPACE}:#{FUNC_NAME}', #{PARAMS_OBJECT});
246
248
  }`;
@@ -280,4 +282,37 @@ function setHost(host, configFile) {
280
282
  process.env.HOST = configFile.default;
281
283
  console.log('Environment variable `HOST` is set to', configFile.default);
282
284
  }
285
+ }
286
+ async function runAll(packagesDir, command, options, packagesToLoad = ['all']) {
287
+ const packages = _fs.default.readdirSync(packagesDir);
288
+ const commandToRun = `${command} ${optionsToString(options)}`;
289
+ for (const packageName of packages) {
290
+ const packagePath = _path.default.join(...[packagesDir, packageName]);
291
+ const packageJsonPath = _path.default.join(...[packagesDir, packageName, 'package.json']);
292
+ if (_fs.default.statSync(packagePath).isDirectory() && _fs.default.existsSync(packageJsonPath)) {
293
+ try {
294
+ console.log(`${packagePath}: ${commandToRun} - Started`);
295
+ await runScript(commandToRun, packagePath, options.verbose);
296
+ console.log(`${packagePath}: ${commandToRun} - Finished`);
297
+ } catch (e) {
298
+ console.log(`${packagePath}: ${commandToRun} - Error`);
299
+ break;
300
+ }
301
+ }
302
+ }
303
+ return;
304
+ }
305
+ function optionsToString(options) {
306
+ const parts = [];
307
+ for (const [key, value] of Object.entries(options)) {
308
+ if (key === '_' || key === 'all') continue;
309
+ if (typeof value === 'boolean') {
310
+ if (value) {
311
+ parts.push(`--${key}`);
312
+ }
313
+ } else if (value !== undefined && value !== null) {
314
+ parts.push(`--${key}="${value}"`);
315
+ }
316
+ }
317
+ return parts.join(' ');
283
318
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datagrok-tools",
3
- "version": "4.14.24",
3
+ "version": "4.14.26",
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": {
@@ -14,6 +14,7 @@ const {
14
14
  } = require("../bin/utils/func-generation");
15
15
 
16
16
  const baseImport = "import * as DG from 'datagrok-api/dg';\n";
17
+ 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`;
17
18
 
18
19
  class FuncGeneratorPlugin {
19
20
  constructor(options = { outputPath: "./src/package.g.ts" }) {
@@ -445,7 +446,7 @@ class FuncGeneratorPlugin {
445
446
  const importStatement = imports[i];
446
447
  const exportStatement = exp[i];
447
448
  if (!content.includes(importStatement.trim()))
448
- content = importStatement + content + exportStatement;
449
+ content = annotationForGeneratedFile + importStatement + content + exportStatement;
449
450
  }
450
451
  fs.writeFileSync(filePath, content, "utf-8");
451
452
  }