datagrok-tools 4.13.74 → 4.13.76
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/commands/add.js +96 -106
- package/bin/commands/api.js +65 -107
- package/bin/commands/check.js +264 -396
- package/bin/commands/config.js +82 -158
- package/bin/commands/create.js +65 -80
- package/bin/commands/help.js +194 -12
- package/bin/commands/init.js +73 -95
- package/bin/commands/link.js +70 -176
- package/bin/commands/publish.js +283 -484
- package/bin/commands/test-all.js +77 -291
- package/bin/commands/test.js +169 -391
- package/bin/utils/color-utils.js +8 -11
- package/bin/utils/ent-helpers.js +52 -42
- package/bin/utils/func-generation.js +25 -57
- package/bin/utils/interfaces.js +5 -1
- package/bin/utils/order-functions.js +47 -118
- package/bin/utils/test-utils.js +322 -750
- package/bin/utils/utils.js +123 -235
- package/bin/validators/config-validator.js +12 -14
- package/package.json +13 -4
package/bin/utils/utils.js
CHANGED
|
@@ -29,95 +29,57 @@ exports.scriptWrapperTemplate = exports.scriptLangExtMap = exports.scriptExtensi
|
|
|
29
29
|
exports.setHost = setHost;
|
|
30
30
|
exports.spaceToCamelCase = spaceToCamelCase;
|
|
31
31
|
exports.wordsToCamelCase = wordsToCamelCase;
|
|
32
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
33
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
34
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
35
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
36
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
37
32
|
var _fs = _interopRequireDefault(require("fs"));
|
|
38
33
|
var _path = _interopRequireDefault(require("path"));
|
|
39
34
|
var _child_process = require("child_process");
|
|
40
35
|
var _util = require("util");
|
|
41
|
-
|
|
42
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
43
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
44
|
-
var execAsync = (0, _util.promisify)(_child_process.exec);
|
|
36
|
+
const execAsync = (0, _util.promisify)(_child_process.exec);
|
|
45
37
|
|
|
46
38
|
/* Waits [ms] milliseconds */
|
|
47
|
-
function delay(
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
function _delay() {
|
|
51
|
-
_delay = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(ms) {
|
|
52
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
53
|
-
while (1) switch (_context.prev = _context.next) {
|
|
54
|
-
case 0:
|
|
55
|
-
_context.next = 2;
|
|
56
|
-
return new Promise(function (r) {
|
|
57
|
-
return setTimeout(r, ms);
|
|
58
|
-
});
|
|
59
|
-
case 2:
|
|
60
|
-
case "end":
|
|
61
|
-
return _context.stop();
|
|
62
|
-
}
|
|
63
|
-
}, _callee);
|
|
64
|
-
}));
|
|
65
|
-
return _delay.apply(this, arguments);
|
|
39
|
+
async function delay(ms) {
|
|
40
|
+
await new Promise(r => setTimeout(r, ms));
|
|
66
41
|
}
|
|
67
42
|
function isEmpty(dir) {
|
|
68
|
-
return _fs
|
|
43
|
+
return _fs.default.readdirSync(dir).length === 0;
|
|
69
44
|
}
|
|
70
45
|
function isPackageDir(dir) {
|
|
71
|
-
return _fs
|
|
46
|
+
return _fs.default.existsSync(_path.default.join(dir, 'package.json'));
|
|
72
47
|
}
|
|
73
|
-
function kebabToCamelCase(s) {
|
|
74
|
-
|
|
75
|
-
s = s.replace(/-./g, function (x) {
|
|
76
|
-
return x.toUpperCase()[1];
|
|
77
|
-
});
|
|
48
|
+
function kebabToCamelCase(s, firstUpper = true) {
|
|
49
|
+
s = s.replace(/-./g, x => x.toUpperCase()[1]);
|
|
78
50
|
return (firstUpper ? s[0].toUpperCase() : s[0].toLowerCase()) + s.slice(1);
|
|
79
51
|
}
|
|
80
|
-
function spaceToCamelCase(s) {
|
|
81
|
-
|
|
82
|
-
s = s.replace(/\s+./g, function (x) {
|
|
83
|
-
return x[x.length - 1].toUpperCase();
|
|
84
|
-
});
|
|
52
|
+
function spaceToCamelCase(s, firstUpper = true) {
|
|
53
|
+
s = s.replace(/\s+./g, x => x[x.length - 1].toUpperCase());
|
|
85
54
|
return (firstUpper ? s[0].toUpperCase() : s[0].toLowerCase()) + s.slice(1);
|
|
86
55
|
}
|
|
87
|
-
function wordsToCamelCase(s) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
var lastIndex = m ? m[0].length : 1;
|
|
56
|
+
function wordsToCamelCase(s, firstUpper = true) {
|
|
57
|
+
const m = s.match(/^[A-Z]+/); // only abbreviation handling
|
|
58
|
+
const lastIndex = m ? m[0].length : 1;
|
|
91
59
|
return s.slice(0, lastIndex).toLowerCase() + s.slice(lastIndex);
|
|
92
60
|
}
|
|
93
61
|
function camelCaseToKebab(s) {
|
|
94
|
-
return s.replace(/[A-Z]/g,
|
|
95
|
-
return index == 0 ? _char.toLowerCase() : '-' + _char.toLowerCase();
|
|
96
|
-
});
|
|
62
|
+
return s.replace(/[A-Z]/g, (char, index) => index == 0 ? char.toLowerCase() : '-' + char.toLowerCase());
|
|
97
63
|
}
|
|
98
64
|
function removeScope(name) {
|
|
99
|
-
|
|
65
|
+
const split = name.split('/');
|
|
100
66
|
return split[split.length - 1];
|
|
101
67
|
}
|
|
102
68
|
function mapURL(conf) {
|
|
103
|
-
|
|
104
|
-
for (
|
|
69
|
+
const urls = {};
|
|
70
|
+
for (const server in conf['servers']) urls[conf['servers'][server]['url']] = server;
|
|
105
71
|
return urls;
|
|
106
72
|
}
|
|
107
|
-
function friendlyNameToName(s) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
var isUpper = function isUpper(s) {
|
|
118
|
-
return /[A-Z]/.test(s);
|
|
119
|
-
};
|
|
120
|
-
for (var i = 0; i < s.length; i++) {
|
|
73
|
+
function friendlyNameToName(s, firstUpper = true) {
|
|
74
|
+
let out = '';
|
|
75
|
+
let cap = true;
|
|
76
|
+
let firstWordUpperCase = false;
|
|
77
|
+
let start = true;
|
|
78
|
+
s = (s ?? '').trim();
|
|
79
|
+
const letterRegex = /[A-Za-z]/;
|
|
80
|
+
const digitRegex = /\d/;
|
|
81
|
+
const isUpper = s => /[A-Z]/.test(s);
|
|
82
|
+
for (let i = 0; i < s.length; i++) {
|
|
121
83
|
if (!letterRegex.test(s[i]) && !digitRegex.test(s[i])) cap = true;else {
|
|
122
84
|
if (start && digitRegex.test(s[i])) continue;
|
|
123
85
|
firstWordUpperCase = start ? isUpper(s[i]) : firstWordUpperCase && isUpper(s[i]);
|
|
@@ -128,74 +90,38 @@ function friendlyNameToName(s) {
|
|
|
128
90
|
}
|
|
129
91
|
return out;
|
|
130
92
|
}
|
|
131
|
-
|
|
132
|
-
NAME:
|
|
133
|
-
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
},
|
|
144
|
-
PACKAGE_DETECTORS_NAME: function PACKAGE_DETECTORS_NAME(s, name) {
|
|
145
|
-
return s.replace(/#{PACKAGE_DETECTORS_NAME}/g, kebabToCamelCase(name));
|
|
146
|
-
},
|
|
147
|
-
PACKAGE_NAMESPACE: function PACKAGE_NAMESPACE(s, name) {
|
|
148
|
-
return s.replace(/#{PACKAGE_NAMESPACE}/g, kebabToCamelCase(removeScope(name)));
|
|
149
|
-
},
|
|
150
|
-
FUNC_NAME: function FUNC_NAME(s, name) {
|
|
151
|
-
return s.replace(/#{FUNC_NAME}/g, friendlyNameToName(name));
|
|
152
|
-
},
|
|
153
|
-
FUNC_NAME_LOWERCASE: function FUNC_NAME_LOWERCASE(s, name) {
|
|
154
|
-
return s.replace(/#{FUNC_NAME_LOWERCASE}/g, friendlyNameToName(name, false));
|
|
155
|
-
},
|
|
156
|
-
PARAMS_OBJECT: function PARAMS_OBJECT(s, params) {
|
|
157
|
-
return s.replace(/#{PARAMS_OBJECT}/g, params.length ? "{ ".concat(params.map(function (p) {
|
|
158
|
-
return p.name;
|
|
159
|
-
}).join(', '), " }") : "{}");
|
|
160
|
-
},
|
|
161
|
-
OUTPUT_TYPE: function OUTPUT_TYPE(s, type) {
|
|
162
|
-
return s.replace(/#{OUTPUT_TYPE}/g, type);
|
|
163
|
-
},
|
|
164
|
-
TYPED_PARAMS: function TYPED_PARAMS(s, params) {
|
|
165
|
-
return s.replace(/#{TYPED_PARAMS}/g, params.map(function (p) {
|
|
166
|
-
return "".concat(p.name, ": ").concat(p.type);
|
|
167
|
-
}).join(', '));
|
|
168
|
-
}
|
|
93
|
+
const replacers = exports.replacers = {
|
|
94
|
+
NAME: (s, name) => s.replace(/#{NAME}/g, name),
|
|
95
|
+
NAME_TITLECASE: (s, name) => s.replace(/#{NAME_TITLECASE}/g, name[0].toUpperCase() + name.slice(1).toLowerCase()),
|
|
96
|
+
NAME_LOWERCASE: (s, name) => s.replace(/#{NAME_LOWERCASE}/g, name.toLowerCase()),
|
|
97
|
+
NAME_PREFIX: (s, name) => s.replace(/#{NAME_PREFIX}/g, name.slice(0, 3)),
|
|
98
|
+
PACKAGE_DETECTORS_NAME: (s, name) => s.replace(/#{PACKAGE_DETECTORS_NAME}/g, kebabToCamelCase(name)),
|
|
99
|
+
PACKAGE_NAMESPACE: (s, name) => s.replace(/#{PACKAGE_NAMESPACE}/g, kebabToCamelCase(removeScope(name))),
|
|
100
|
+
FUNC_NAME: (s, name) => s.replace(/#{FUNC_NAME}/g, friendlyNameToName(name)),
|
|
101
|
+
FUNC_NAME_LOWERCASE: (s, name) => s.replace(/#{FUNC_NAME_LOWERCASE}/g, friendlyNameToName(name, false)),
|
|
102
|
+
PARAMS_OBJECT: (s, params) => s.replace(/#{PARAMS_OBJECT}/g, params.length ? `{ ${params.map(p => p.name).join(', ')} }` : `{}`),
|
|
103
|
+
OUTPUT_TYPE: (s, type) => s.replace(/#{OUTPUT_TYPE}/g, type),
|
|
104
|
+
TYPED_PARAMS: (s, params) => s.replace(/#{TYPED_PARAMS}/g, params.map(p => `${p.name}: ${p.type}`).join(', '))
|
|
169
105
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
106
|
+
class TemplateBuilder {
|
|
107
|
+
static sep = '\n';
|
|
108
|
+
static indentSize = 2;
|
|
109
|
+
constructor(template) {
|
|
174
110
|
this.template = template;
|
|
175
111
|
}
|
|
176
|
-
(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
key: "build",
|
|
184
|
-
value: function build() {
|
|
185
|
-
var indent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
186
|
-
if (indent) {
|
|
187
|
-
this.template = this.template.split(TemplateBuilder.sep).map(function (line) {
|
|
188
|
-
return ' '.repeat(indent * TemplateBuilder.indentSize) + line;
|
|
189
|
-
}).join(TemplateBuilder.sep);
|
|
190
|
-
}
|
|
191
|
-
return this.template;
|
|
112
|
+
replace(pattern, value) {
|
|
113
|
+
this.template = replacers[pattern](this.template, value);
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
build(indent = 0) {
|
|
117
|
+
if (indent) {
|
|
118
|
+
this.template = this.template.split(TemplateBuilder.sep).map(line => ' '.repeat(indent * TemplateBuilder.indentSize) + line).join(TemplateBuilder.sep);
|
|
192
119
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
var scriptLangExtMap = exports.scriptLangExtMap = {
|
|
120
|
+
return this.template;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.TemplateBuilder = TemplateBuilder;
|
|
124
|
+
const scriptLangExtMap = exports.scriptLangExtMap = {
|
|
199
125
|
javascript: 'js',
|
|
200
126
|
julia: 'jl',
|
|
201
127
|
node: 'js',
|
|
@@ -203,7 +129,7 @@ var scriptLangExtMap = exports.scriptLangExtMap = {
|
|
|
203
129
|
python: 'py',
|
|
204
130
|
r: 'R'
|
|
205
131
|
};
|
|
206
|
-
|
|
132
|
+
const commentMap = exports.commentMap = {
|
|
207
133
|
'.js': '//',
|
|
208
134
|
'.jl': '#',
|
|
209
135
|
'.m': '#',
|
|
@@ -211,39 +137,33 @@ var commentMap = exports.commentMap = {
|
|
|
211
137
|
'.R': '#',
|
|
212
138
|
'.sql': '--'
|
|
213
139
|
};
|
|
214
|
-
|
|
215
|
-
|
|
140
|
+
const queryExtension = exports.queryExtension = '.sql';
|
|
141
|
+
const scriptExtensions = exports.scriptExtensions = ['.jl', '.m', '.py', '.R'];
|
|
216
142
|
function checkScriptLocation(filepath) {
|
|
217
|
-
if (!(filepath.startsWith('scripts/') || filepath.startsWith('projects/') || filepath.startsWith('dockerfiles/')) && scriptExtensions.some(
|
|
218
|
-
return filepath.endsWith(ext);
|
|
219
|
-
})) return false;
|
|
143
|
+
if (!(filepath.startsWith('scripts/') || filepath.startsWith('projects/') || filepath.startsWith('dockerfiles/')) && scriptExtensions.some(ext => filepath.endsWith(ext))) return false;
|
|
220
144
|
return true;
|
|
221
145
|
}
|
|
222
146
|
;
|
|
223
|
-
function getScriptName(script) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
var match = script.match(regex);
|
|
228
|
-
return match ? (_match$ = match[1]) === null || _match$ === void 0 ? void 0 : _match$.trim() : null;
|
|
147
|
+
function getScriptName(script, comment = '#') {
|
|
148
|
+
const regex = new RegExp(`${comment}\\s*name:\\s*(.*)`);
|
|
149
|
+
const match = script.match(regex);
|
|
150
|
+
return match ? match[1]?.trim() : null;
|
|
229
151
|
}
|
|
230
152
|
;
|
|
231
|
-
function getParam(name, script) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
var match = script.match(regex);
|
|
236
|
-
return match ? (_match$2 = match[1]) === null || _match$2 === void 0 ? void 0 : _match$2.trim() : null;
|
|
153
|
+
function getParam(name, script, comment = '#') {
|
|
154
|
+
const regex = new RegExp(`${comment}\\s*${name}:\\s*(.*)`);
|
|
155
|
+
const match = script.match(regex);
|
|
156
|
+
return match ? match[1]?.trim() : null;
|
|
237
157
|
}
|
|
238
158
|
;
|
|
239
|
-
|
|
159
|
+
const cahceValues = exports.cahceValues = ['all', 'server', 'client', 'true'];
|
|
240
160
|
function isValidCron(cronExpression) {
|
|
241
|
-
|
|
161
|
+
const cronRegex = /^(\*|([0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])|\*\/([0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])) (\*|([0-9]|1[0-9]|2[0-3])|\*\/([0-9]|1[0-9]|2[0-3])) (\*|([1-9]|1[0-9]|2[0-9]|3[0-1])|\*\/([1-9]|1[0-9]|2[0-9]|3[0-1])) (\*|([1-9]|1[0-2])|\*\/([1-9]|1[0-2])) (\*|([0-6])|\*\/([0-6]))$/;
|
|
242
162
|
return cronRegex.test(cronExpression);
|
|
243
163
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
164
|
+
const dgToTsTypeMap = exports.dgToTsTypeMap = {
|
|
165
|
+
int: 'number',
|
|
166
|
+
double: 'number',
|
|
247
167
|
bigint: 'bigint',
|
|
248
168
|
bool: 'boolean',
|
|
249
169
|
string: 'string',
|
|
@@ -252,96 +172,64 @@ var dgToTsTypeMap = exports.dgToTsTypeMap = {
|
|
|
252
172
|
column_list: 'string[]',
|
|
253
173
|
file: 'DG.FileInfo'
|
|
254
174
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
py: new RegExp(
|
|
259
|
-
ts: new RegExp(
|
|
260
|
-
js: new RegExp(
|
|
261
|
-
sql: new RegExp(
|
|
175
|
+
const propertyTypes = exports.propertyTypes = ['bool', 'int', 'double', 'string', 'datetime', 'object', 'column', 'dataframe', 'bitset', 'cell', 'string_list', 'map'];
|
|
176
|
+
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'];
|
|
177
|
+
const fileParamRegex = exports.fileParamRegex = {
|
|
178
|
+
py: new RegExp(`^\#\\s*((?:${headerTags.join('|')})[^:]*): *([^\\s\\[\\{]+) ?([^\\s\\[\\{]+)?[^\\n]*$`),
|
|
179
|
+
ts: new RegExp(`^\/\/\\s*((?:${headerTags.join('|')})[^:]*): *([^\\s\\[\\{]+) ?([^\\s\\[\\{]+)?[^\\n]*$`),
|
|
180
|
+
js: new RegExp(`^\/\/\\s*((?:${headerTags.join('|')})[^:]*): *([^\\s\\[\\{]+) ?([^\\s\\[\\{]+)?[^\\n]*$`),
|
|
181
|
+
sql: new RegExp(`^--\\s*((?:${headerTags.join('|')})[^:]*): *([^\\s\\[\\{]+) ?([^\\s\\[\\{]+)?[^\\n]*$`)
|
|
262
182
|
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
function getScriptOutputType(script) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
var match = script.match(regex);
|
|
183
|
+
const nameAnnRegex = exports.nameAnnRegex = /\/\/\s*(name[^:]*): ([^\n\r\[\{]+)/;
|
|
184
|
+
const nameRegex = exports.nameRegex = /(?:|(?:static)(?:export )(?:async )function )\s+([a-zA-Z_][a-zA-Z0-9_$]*)\s*\((.*?).*/;
|
|
185
|
+
const absUrlRegex = exports.absUrlRegex = new RegExp('^(?:[a-z+]+:)?//', 'i');
|
|
186
|
+
function getScriptOutputType(script, comment = '#') {
|
|
187
|
+
const regex = new RegExp(`${comment}\\s*output:\\s?([a-z_]+)\\s*`);
|
|
188
|
+
const match = script.match(regex);
|
|
270
189
|
if (!match) return 'void';
|
|
271
190
|
return dgToTsTypeMap[match[1]] || 'any';
|
|
272
191
|
}
|
|
273
192
|
;
|
|
274
|
-
function getScriptInputs(script) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
var name = match[2];
|
|
285
|
-
inputs.push({
|
|
286
|
-
type: type,
|
|
287
|
-
name: name
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
} catch (err) {
|
|
291
|
-
_iterator.e(err);
|
|
292
|
-
} finally {
|
|
293
|
-
_iterator.f();
|
|
193
|
+
function getScriptInputs(script, comment = '#') {
|
|
194
|
+
const regex = new RegExp(`${comment}\\s*input:\\s?([a-z_]+)\\s+(\\w+)`, 'g');
|
|
195
|
+
const inputs = [];
|
|
196
|
+
for (const match of script.matchAll(regex)) {
|
|
197
|
+
const type = dgToTsTypeMap[match[1]] || 'any';
|
|
198
|
+
const name = match[2];
|
|
199
|
+
inputs.push({
|
|
200
|
+
type,
|
|
201
|
+
name
|
|
202
|
+
});
|
|
294
203
|
}
|
|
295
204
|
return inputs;
|
|
296
205
|
}
|
|
297
206
|
;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
function
|
|
303
|
-
return
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
207
|
+
const dgImports = exports.dgImports = `import * as grok from 'datagrok-api/grok';\nimport * as DG from 'datagrok-api/dg';\n\n`;
|
|
208
|
+
const scriptWrapperTemplate = exports.scriptWrapperTemplate = `export async function #{FUNC_NAME_LOWERCASE}(#{TYPED_PARAMS}): Promise<#{OUTPUT_TYPE}> {
|
|
209
|
+
return await grok.functions.call('#{PACKAGE_NAMESPACE}:#{FUNC_NAME}', #{PARAMS_OBJECT});
|
|
210
|
+
}`;
|
|
211
|
+
const queryWrapperTemplate = exports.queryWrapperTemplate = `export async function #{FUNC_NAME_LOWERCASE}(#{TYPED_PARAMS}): Promise<#{OUTPUT_TYPE}> {
|
|
212
|
+
return await grok.data.query('#{PACKAGE_NAMESPACE}:#{FUNC_NAME}', #{PARAMS_OBJECT});
|
|
213
|
+
}`;
|
|
214
|
+
const namespaceTemplate = exports.namespaceTemplate = `export namespace #{PACKAGE_NAMESPACE} {\n#{NAME}\n}`;
|
|
215
|
+
async function runScript(script, path, verbose = false) {
|
|
216
|
+
try {
|
|
217
|
+
const {
|
|
309
218
|
stdout,
|
|
310
|
-
stderr
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
stderr = _yield$execAsync.stderr;
|
|
325
|
-
if (stderr && verbose) {
|
|
326
|
-
console.error("Warning/Error: ".concat(stderr));
|
|
327
|
-
}
|
|
328
|
-
if (stdout && verbose) {
|
|
329
|
-
console.log("Output: ".concat(stdout));
|
|
330
|
-
}
|
|
331
|
-
_context2.next = 15;
|
|
332
|
-
break;
|
|
333
|
-
case 11:
|
|
334
|
-
_context2.prev = 11;
|
|
335
|
-
_context2.t0 = _context2["catch"](1);
|
|
336
|
-
console.error("Execution failed: ".concat(_context2.t0.message));
|
|
337
|
-
throw new Error("Cant run script ".concat(script));
|
|
338
|
-
case 15:
|
|
339
|
-
case "end":
|
|
340
|
-
return _context2.stop();
|
|
341
|
-
}
|
|
342
|
-
}, _callee2, null, [[1, 11]]);
|
|
343
|
-
}));
|
|
344
|
-
return _runScript.apply(this, arguments);
|
|
219
|
+
stderr
|
|
220
|
+
} = await execAsync(script, {
|
|
221
|
+
cwd: path
|
|
222
|
+
});
|
|
223
|
+
if (stderr && verbose) {
|
|
224
|
+
console.error(`Warning/Error: ${stderr}`);
|
|
225
|
+
}
|
|
226
|
+
if (stdout && verbose) {
|
|
227
|
+
console.log(`Output: ${stdout}`);
|
|
228
|
+
}
|
|
229
|
+
} catch (error) {
|
|
230
|
+
console.error(`Execution failed: ${error.message}`);
|
|
231
|
+
throw new Error(`Cant run script ${script}`);
|
|
232
|
+
}
|
|
345
233
|
}
|
|
346
234
|
function setHost(host, configFile) {
|
|
347
235
|
if (host) {
|
|
@@ -349,11 +237,11 @@ function setHost(host, configFile) {
|
|
|
349
237
|
process.env.HOST = host;
|
|
350
238
|
console.log('Environment variable `HOST` is set to', host);
|
|
351
239
|
} else {
|
|
352
|
-
console.error(
|
|
240
|
+
console.error(`Unknown server alias. Please add it to Config File`);
|
|
353
241
|
return false;
|
|
354
242
|
}
|
|
355
|
-
} else if (configFile
|
|
356
|
-
process.env.HOST = configFile
|
|
357
|
-
console.log('Environment variable `HOST` is set to', configFile
|
|
243
|
+
} else if (configFile.default) {
|
|
244
|
+
process.env.HOST = configFile.default;
|
|
245
|
+
console.log('Environment variable `HOST` is set to', configFile.default);
|
|
358
246
|
}
|
|
359
247
|
}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.validateConf = validateConf;
|
|
8
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
7
|
function validateConf(config) {
|
|
10
|
-
|
|
8
|
+
const vr = {
|
|
11
9
|
message: 'Validation Error\n\nRun `grok config` to see the config file or ' + '`grok config --reset` to restore the default template.\n\nDetails:\n',
|
|
12
10
|
value: false,
|
|
13
11
|
warnings: []
|
|
14
12
|
};
|
|
15
|
-
if (
|
|
13
|
+
if (typeof config !== 'object' || config === null) {
|
|
16
14
|
vr.message += 'Couldn\'t find server configuration in the file.';
|
|
17
15
|
return vr;
|
|
18
16
|
}
|
|
19
|
-
if (!config.hasOwnProperty('default') || !config
|
|
17
|
+
if (!config.hasOwnProperty('default') || !config.default) {
|
|
20
18
|
vr.message += 'The default server is not specified.';
|
|
21
19
|
return vr;
|
|
22
20
|
}
|
|
@@ -24,26 +22,26 @@ function validateConf(config) {
|
|
|
24
22
|
vr.message += 'The servers information is missing.';
|
|
25
23
|
return vr;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const defaultServer = config.default;
|
|
26
|
+
let hasDefault = false;
|
|
29
27
|
if (typeof defaultServer !== 'string') {
|
|
30
28
|
vr.message += 'The "default" field should contain a server alias.';
|
|
31
29
|
return vr;
|
|
32
30
|
}
|
|
33
|
-
for (
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
vr.message +=
|
|
31
|
+
for (const server in config.servers) {
|
|
32
|
+
const info = config.servers[server];
|
|
33
|
+
if (typeof info !== 'object' || info === null || !('url' in info) || !('key' in info)) {
|
|
34
|
+
vr.message += `Configuration for server "${server}" has the wrong format. Add properties "url" and "key".`;
|
|
37
35
|
return vr;
|
|
38
36
|
}
|
|
39
37
|
// For cases where the values were skipped during `grok config` setup
|
|
40
|
-
if ('url' in info && !info.url) vr.warnings.push(
|
|
41
|
-
if ('key' in info && !info.key) vr.warnings.push(
|
|
38
|
+
if ('url' in info && !info.url) vr.warnings.push(`Missing URL for server "${server}".`);
|
|
39
|
+
if ('key' in info && !info.key) vr.warnings.push(`Missing key for server "${server}".`);
|
|
42
40
|
if (server == defaultServer) hasDefault = true;
|
|
43
41
|
}
|
|
44
42
|
if (hasDefault) {
|
|
45
43
|
vr.value = true;
|
|
46
44
|
vr.message = '';
|
|
47
|
-
} else vr.message +=
|
|
45
|
+
} else vr.message += `The default server "${defaultServer}" is not in the server list.`;
|
|
48
46
|
return vr;
|
|
49
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datagrok-tools",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.76",
|
|
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": {
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"@babel/traverse": "^7.23.7",
|
|
10
10
|
"archiver": "^4.0.2",
|
|
11
11
|
"archiver-promise": "^1.0.0",
|
|
12
|
-
"ffmpeg-installer": "^1.0.2",
|
|
13
12
|
"fs": "^0.0.1-security",
|
|
14
13
|
"ignore-walk": "^3.0.4",
|
|
15
14
|
"inquirer": "^7.3.3",
|
|
@@ -36,8 +35,18 @@
|
|
|
36
35
|
},
|
|
37
36
|
"babel": {
|
|
38
37
|
"presets": [
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
[
|
|
39
|
+
"@babel/preset-env",
|
|
40
|
+
{
|
|
41
|
+
"targets": {
|
|
42
|
+
"chrome": "100"
|
|
43
|
+
},
|
|
44
|
+
"exclude": [
|
|
45
|
+
"@babel/plugin-transform-async-to-generator"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"@babel/preset-typescript"
|
|
41
50
|
],
|
|
42
51
|
"plugins": [
|
|
43
52
|
"@babel/plugin-transform-runtime"
|