datagrok-tools 4.14.65 → 4.14.67

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.
File without changes
@@ -35,7 +35,7 @@ let curDir = process.cwd();
35
35
  const packDir = _path.default.join(curDir, 'package.json');
36
36
  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'];
37
37
  let config;
38
- async function processPackage(debug, rebuild, host, devKey, packageName, suffix) {
38
+ async function processPackage(debug, rebuild, host, devKey, packageName, dropDb, suffix) {
39
39
  // Get the server timestamps
40
40
  let timestamps = {};
41
41
  let url = `${host}/packages/dev/${devKey}/${packageName}`;
@@ -166,7 +166,7 @@ async function processPackage(debug, rebuild, host, devKey, packageName, suffix)
166
166
  });
167
167
 
168
168
  // Upload
169
- url += `?debug=${debug.toString()}&rebuild=${rebuild.toString()}`;
169
+ url += `?debug=${debug.toString()}&rebuild=${rebuild.toString()}&dropDb=${(dropDb ?? false).toString()}`;
170
170
  if (suffix) url += `&suffix=${suffix.toString()}`;
171
171
  const uploadPromise = new Promise((resolve, reject) => {
172
172
  (0, _nodeFetch.default)(url, {
@@ -305,7 +305,7 @@ async function publishPackage(args) {
305
305
  if (!args.suffix && stdout) args.suffix = stdout.toString().substring(0, 8);
306
306
  });
307
307
  await utils.delay(100);
308
- code = await processPackage(!args.release, Boolean(args.rebuild), url, key, packageName, args.suffix);
308
+ code = await processPackage(!args.release, Boolean(args.rebuild), url, key, packageName, args.dropDb ?? false, args.suffix);
309
309
  } catch (error) {
310
310
  console.error(error);
311
311
  code = 1;
@@ -136,7 +136,13 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
136
136
  }
137
137
  for (const input of data.inputs ?? []) {
138
138
  if (!input) continue;
139
- let type = input?.type;
139
+ let type = input?.type?.replaceAll(" ", "");
140
+ if (type?.includes(`|undefined`)) {
141
+ type = type.replaceAll(`|undefined`, '');
142
+ // modify original payload
143
+ input.optional = true;
144
+ input.type = type;
145
+ }
140
146
  let isArray = false;
141
147
  if (type?.includes(`[]`)) {
142
148
  type = type.replace(/\[\]$/, '');
@@ -470,8 +476,19 @@ const primitives = exports.primitives = new Set(['string', 'string[]', 'number',
470
476
 
471
477
  /** Generates a DG function. */
472
478
  function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = [], output, isAsync = false) {
473
- // eslint-disable-next-line max-len
474
- 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(', ');
479
+ // FuncCall can have an optional followed by mandatory args for ui reasons, typescript cannot
480
+ let firstTsValidOptionalIdx = inputs.length - 1;
481
+ for (; firstTsValidOptionalIdx >= 0; firstTsValidOptionalIdx--) {
482
+ const e = inputs[firstTsValidOptionalIdx];
483
+ if (!e.optional) break;
484
+ }
485
+ const funcSigNature = inputs.map((e, idx) => {
486
+ const namePart = `${e.name}${e.optional && idx >= firstTsValidOptionalIdx ? '?' : ''}`;
487
+ // eslint-disable-next-line max-len
488
+ let typePart = `${primitives.has(e.type ?? '') && !typesToAny.includes(e.type ?? '') ? e.type : typesToAnnotation[e.type?.replace('[]', '') ?? ''] && !typesToAny.includes(e.type ?? '') ? e.type : 'any'}`;
489
+ if (e.optional && idx < firstTsValidOptionalIdx) typePart += ' | undefined';
490
+ return `${namePart}: ${typePart}`;
491
+ }).join(', ');
475
492
  const funcArguments = inputs.map(e => e.name).join(', ');
476
493
  const returnType = output ? primitives.has(output) ? !isAsync ? `: ${output} ` : `: Promise<${output}> ` : !isAsync ? `: any ` : `: Promise<any> ` : '';
477
494
  // eslint-disable-next-line max-len
@@ -110,7 +110,7 @@ const replacers = exports.replacers = {
110
110
  FUNC_NAME_LOWERCASE: (s, name) => s.replace(/#{FUNC_NAME_LOWERCASE}/g, friendlyNameToName(name, false)),
111
111
  PARAMS_OBJECT: (s, params) => s.replace(/#{PARAMS_OBJECT}/g, params.length ? `{ ${params.map(p => p.name).join(', ')} }` : `{}`),
112
112
  OUTPUT_TYPE: (s, type) => s.replace(/#{OUTPUT_TYPE}/g, type),
113
- TYPED_PARAMS: (s, params) => s.replace(/#{TYPED_PARAMS}/g, params.map(p => `${p.name}${p.isOptional ? '?' : ''}: ${p.type} ${p.nullable ? '| null' : ''}`).join(', '))
113
+ TYPED_PARAMS: (s, params) => s.replace(/#{TYPED_PARAMS}/g, params.map(p => `${p.name}${p.isOptional ? '?' : ''}: ${p.type} ${p.undefinable ? '| undefined' : ''}${p.nullable ? '| null' : ''}`).join(', '))
114
114
  };
115
115
  class TemplateBuilder {
116
116
  static sep = '\n';
@@ -219,9 +219,18 @@ function getScriptOutputType(script, comment = '#') {
219
219
  ;
220
220
  function getScriptInputs(script, comment = '#') {
221
221
  const regex = new RegExp(`${comment}\\s*input:\\s?([a-z_]+)(?:<[^>]*>)?\\s+(\\w+)(?:[^{\\n]*{[^}\\n]*})?`, 'g');
222
+ const testOptional = inputAnnotation => /isOptional\s*:\s*true/.test(inputAnnotation) || /optional\s*:\s*true/.test(inputAnnotation);
223
+ const inputAnnotations = [...script.matchAll(regex)];
224
+ let firstTsValidOptionalIdx = inputAnnotations.length - 1;
225
+ for (; firstTsValidOptionalIdx >= 0; firstTsValidOptionalIdx--) {
226
+ const annotation = inputAnnotations[firstTsValidOptionalIdx][0];
227
+ if (!testOptional(annotation)) break;
228
+ }
222
229
  const inputs = [];
223
- for (const match of script.matchAll(regex)) {
224
- const isOptional = /isOptional\s*:\s*true/.test(match[0]) || /optional\s*:\s*true/.test(match[0]);
230
+ for (const [idx, match] of inputAnnotations.entries()) {
231
+ const hasOptionalAnnotation = testOptional(match[0]);
232
+ const isOptional = hasOptionalAnnotation && idx >= firstTsValidOptionalIdx;
233
+ const undefinable = hasOptionalAnnotation && idx < firstTsValidOptionalIdx;
225
234
  const nullable = /nullable\s*:\s*true/.test(match[0]);
226
235
  const type = dgToTsTypeMap[match[1]] || 'any';
227
236
  const name = match[2];
@@ -229,6 +238,7 @@ function getScriptInputs(script, comment = '#') {
229
238
  type,
230
239
  name,
231
240
  isOptional,
241
+ undefinable,
232
242
  nullable
233
243
  });
234
244
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datagrok-tools",
3
- "version": "4.14.65",
3
+ "version": "4.14.67",
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": {
@@ -31,7 +31,8 @@
31
31
  "link": "npm link",
32
32
  "prepublishOnly": "babel bin --extensions .ts -d bin",
33
33
  "babel": "babel bin --extensions .ts -d bin",
34
- "build": "babel bin --extensions .ts -d bin"
34
+ "build": "babel bin --extensions .ts -d bin",
35
+ "debug-source-map": "babel bin --extensions .ts -d bin --source-maps true"
35
36
  },
36
37
  "bin": {
37
38
  "datagrok-upload": "./bin/_deprecated/upload.js",