@automattic/vip 2.12.0 → 2.14.0
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/README.md +27 -3
- package/dist/bin/vip-cache-purge-url.js +93 -0
- package/{package/dist/bin/vip-config.js → dist/bin/vip-cache.js} +6 -3
- package/dist/bin/vip-dev-env-exec.js +9 -2
- package/dist/bin/vip-dev-env-import-sql.js +8 -1
- package/dist/bin/vip-dev-env-start.js +2 -1
- package/dist/bin/vip-dev-env-update.js +1 -0
- package/dist/bin/vip.js +1 -1
- package/dist/lib/api/cache-purge.js +76 -0
- package/dist/lib/dev-environment/dev-environment-cli.js +2 -2
- package/dist/lib/dev-environment/dev-environment-core.js +3 -3
- package/dist/lib/dev-environment/dev-environment-lando.js +38 -7
- package/dist/lib/envvar/read-file.js +2 -18
- package/{package/dist/lib/envvar → dist/lib}/read-file.js +3 -6
- package/dist/lib/validations/sql.js +175 -53
- package/npm-shrinkwrap.json +82 -82
- package/package.json +5 -3
- package/.circleci/config.yml +0 -67
- package/package/dist/bin/vip-app-list.js +0 -73
- package/package/dist/bin/vip-app.js +0 -76
- package/package/dist/bin/vip-config-envvar-delete.js +0 -97
- package/package/dist/bin/vip-config-envvar-get-all.js +0 -94
- package/package/dist/bin/vip-config-envvar-get.js +0 -79
- package/package/dist/bin/vip-config-envvar-list.js +0 -91
- package/package/dist/bin/vip-config-envvar-set.js +0 -123
- package/package/dist/bin/vip-config-envvar.js +0 -23
- package/package/dist/bin/vip-dev-env-create.js +0 -105
- package/package/dist/bin/vip-dev-env-destroy.js +0 -56
- package/package/dist/bin/vip-dev-env-exec.js +0 -67
- package/package/dist/bin/vip-dev-env-import-media.js +0 -51
- package/package/dist/bin/vip-dev-env-import-sql.js +0 -83
- package/package/dist/bin/vip-dev-env-import.js +0 -32
- package/package/dist/bin/vip-dev-env-info.js +0 -61
- package/package/dist/bin/vip-dev-env-list.js +0 -46
- package/package/dist/bin/vip-dev-env-start.js +0 -77
- package/package/dist/bin/vip-dev-env-stop.js +0 -52
- package/package/dist/bin/vip-dev-env-update.js +0 -89
- package/package/dist/bin/vip-dev-env.js +0 -23
- package/package/dist/bin/vip-import-media-abort.js +0 -132
- package/package/dist/bin/vip-import-media-status.js +0 -84
- package/package/dist/bin/vip-import-media.js +0 -168
- package/package/dist/bin/vip-import-sql-status.js +0 -83
- package/package/dist/bin/vip-import-sql.js +0 -580
- package/package/dist/bin/vip-import-validate-files.js +0 -191
- package/package/dist/bin/vip-import-validate-sql.js +0 -34
- package/package/dist/bin/vip-import.js +0 -20
- package/package/dist/bin/vip-logs.js +0 -232
- package/package/dist/bin/vip-search-replace.js +0 -71
- package/package/dist/bin/vip-sync.js +0 -191
- package/package/dist/bin/vip-whoami.js +0 -67
- package/package/dist/bin/vip-wp.js +0 -555
- package/package/dist/bin/vip.js +0 -149
- package/package/dist/lib/analytics/clients/client.js +0 -1
- package/package/dist/lib/analytics/clients/pendo.js +0 -92
- package/package/dist/lib/analytics/clients/stub.js +0 -19
- package/package/dist/lib/analytics/clients/tracks.js +0 -128
- package/package/dist/lib/analytics/index.js +0 -45
- package/package/dist/lib/api/app.js +0 -70
- package/package/dist/lib/api/feature-flags.js +0 -39
- package/package/dist/lib/api/user.js +0 -58
- package/package/dist/lib/api.js +0 -136
- package/package/dist/lib/app-logs/app-logs.js +0 -70
- package/package/dist/lib/cli/apiConfig.js +0 -90
- package/package/dist/lib/cli/command.js +0 -606
- package/package/dist/lib/cli/envAlias.js +0 -60
- package/package/dist/lib/cli/exit.js +0 -33
- package/package/dist/lib/cli/format.js +0 -213
- package/package/dist/lib/cli/pager.js +0 -52
- package/package/dist/lib/cli/progress.js +0 -208
- package/package/dist/lib/cli/prompt.js +0 -37
- package/package/dist/lib/cli/repo.js +0 -77
- package/package/dist/lib/client-file-uploader.js +0 -602
- package/package/dist/lib/constants/dev-environment.js +0 -42
- package/package/dist/lib/constants/file-size.js +0 -14
- package/package/dist/lib/dev-environment/dev-environment-cli.js +0 -508
- package/package/dist/lib/dev-environment/dev-environment-core.js +0 -620
- package/package/dist/lib/dev-environment/dev-environment-lando.js +0 -330
- package/package/dist/lib/dev-environment/types.js +0 -1
- package/package/dist/lib/env.js +0 -36
- package/package/dist/lib/envvar/api-delete.js +0 -56
- package/package/dist/lib/envvar/api-get-all.js +0 -59
- package/package/dist/lib/envvar/api-get.js +0 -24
- package/package/dist/lib/envvar/api-list.js +0 -60
- package/package/dist/lib/envvar/api-set.js +0 -58
- package/package/dist/lib/envvar/api.js +0 -104
- package/package/dist/lib/envvar/input.js +0 -55
- package/package/dist/lib/envvar/logging.js +0 -33
- package/package/dist/lib/http/socks-proxy-agent.js +0 -25
- package/package/dist/lib/keychain/browser.js +0 -35
- package/package/dist/lib/keychain/insecure.js +0 -63
- package/package/dist/lib/keychain/keychain.js +0 -1
- package/package/dist/lib/keychain/secure.js +0 -36
- package/package/dist/lib/keychain.js +0 -36
- package/package/dist/lib/media-import/media-file-import.js +0 -34
- package/package/dist/lib/media-import/progress.js +0 -86
- package/package/dist/lib/media-import/status.js +0 -335
- package/package/dist/lib/rollbar.js +0 -35
- package/package/dist/lib/search-and-replace.js +0 -203
- package/package/dist/lib/site-import/db-file-import.js +0 -46
- package/package/dist/lib/site-import/status.js +0 -444
- package/package/dist/lib/token.js +0 -132
- package/package/dist/lib/tracker.js +0 -96
- package/package/dist/lib/validations/is-multi-site-sql-dump.js +0 -59
- package/package/dist/lib/validations/is-multi-site.js +0 -99
- package/package/dist/lib/validations/line-by-line.js +0 -92
- package/package/dist/lib/validations/site-type.js +0 -66
- package/package/dist/lib/validations/sql.js +0 -371
- package/package/dist/lib/vip-import-validate-files.js +0 -548
- package/package/vip.iml +0 -11
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.validate = exports.staticSqlValidations = exports.getTableNames =
|
|
6
|
+
exports.validate = exports.staticSqlValidations = exports.getTableNames = void 0;
|
|
7
7
|
|
|
8
8
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
9
9
|
|
|
@@ -41,22 +41,62 @@ function formatError(message) {
|
|
|
41
41
|
return `${_chalk.default.red('SQL Error:')} ${message}`;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
function formatWarning(message) {
|
|
45
|
+
return `${_chalk.default.yellow('Warning:')} ${message}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
44
48
|
function formatRecommendation(message) {
|
|
45
49
|
return `${_chalk.default.yellow('Recommendation:')} ${message}`;
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
const
|
|
52
|
+
const generalCheckFormatter = check => {
|
|
53
|
+
const errors = [];
|
|
54
|
+
const infos = [];
|
|
55
|
+
const validProblems = check.results.filter(result => !result.falsePositive);
|
|
56
|
+
|
|
57
|
+
if (validProblems.length > 0) {
|
|
58
|
+
if (validProblems.some(result => !result.warning)) {
|
|
59
|
+
problemsFound += 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
for (const problem of validProblems) {
|
|
63
|
+
const text = `${problem.text || check.message} on line ${problem.lineNumber || ''}.`;
|
|
64
|
+
|
|
65
|
+
if (problem.warning) {
|
|
66
|
+
errors.push({
|
|
67
|
+
warning: formatWarning(text),
|
|
68
|
+
recommendation: formatRecommendation(problem.recomendation || check.recommendation)
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
errors.push({
|
|
72
|
+
error: formatError(text),
|
|
73
|
+
recommendation: formatRecommendation(problem.recomendation || check.recommendation)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
infos.push(`✅ ${check.message} was found 0 times.`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
errors,
|
|
83
|
+
infos
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const lineNumberCheckFormatter = check => {
|
|
49
88
|
const errors = [];
|
|
50
89
|
const infos = [];
|
|
51
90
|
|
|
52
91
|
if (check.results.length > 0) {
|
|
53
92
|
problemsFound += 1;
|
|
93
|
+
const lineNumbers = check.results.map(result => result.lineNumber);
|
|
54
94
|
errors.push({
|
|
55
|
-
error: formatError(`${check.message} on line(s) ${
|
|
95
|
+
error: formatError(`${check.message} on line(s) ${lineNumbers.join(', ')}.`),
|
|
56
96
|
recommendation: formatRecommendation(check.recommendation)
|
|
57
97
|
});
|
|
58
98
|
} else {
|
|
59
|
-
infos.push(`✅ ${check.message} was found
|
|
99
|
+
infos.push(`✅ ${check.message} was found 0 times.`);
|
|
60
100
|
}
|
|
61
101
|
|
|
62
102
|
return {
|
|
@@ -94,7 +134,7 @@ const requiredCheckFormatter = (check, type, isImport) => {
|
|
|
94
134
|
const infoCheckFormatter = check => {
|
|
95
135
|
const infos = [];
|
|
96
136
|
check.results.forEach(item => {
|
|
97
|
-
infos.push(item);
|
|
137
|
+
infos.push(item.text);
|
|
98
138
|
});
|
|
99
139
|
return {
|
|
100
140
|
errors: [],
|
|
@@ -102,11 +142,13 @@ const infoCheckFormatter = check => {
|
|
|
102
142
|
};
|
|
103
143
|
};
|
|
104
144
|
|
|
105
|
-
function checkTablePrefixes(
|
|
145
|
+
function checkTablePrefixes(results, errors, infos) {
|
|
106
146
|
const wpTables = [],
|
|
107
147
|
notWPTables = [],
|
|
108
148
|
wpMultisiteTables = [];
|
|
109
|
-
|
|
149
|
+
results.forEach(result => {
|
|
150
|
+
const tableName = result.text || '';
|
|
151
|
+
|
|
110
152
|
if (tableName.match(/^wp_(\d+_)/)) {
|
|
111
153
|
wpMultisiteTables.push(tableName);
|
|
112
154
|
} else if (tableName.match(/^wp_/)) {
|
|
@@ -136,8 +178,10 @@ function checkTablePrefixes(tables, errors, infos) {
|
|
|
136
178
|
const checks = {
|
|
137
179
|
binaryLogging: {
|
|
138
180
|
matcher: /SET @@SESSION.sql_log_bin/i,
|
|
139
|
-
matchHandler: lineNumber =>
|
|
140
|
-
|
|
181
|
+
matchHandler: lineNumber => ({
|
|
182
|
+
lineNumber
|
|
183
|
+
}),
|
|
184
|
+
outputFormatter: lineNumberCheckFormatter,
|
|
141
185
|
results: [],
|
|
142
186
|
message: 'SET @@SESSION.sql_log_bin statement',
|
|
143
187
|
excerpt: "'SET @@SESSION.sql_log_bin' statement should not be present (case-insensitive)",
|
|
@@ -146,8 +190,10 @@ const checks = {
|
|
|
146
190
|
trigger: {
|
|
147
191
|
// Match `CREATE (DEFINER=`root`@`host`) TRIGGER`
|
|
148
192
|
matcher: /^CREATE (\(?DEFINER=`?(\w*)(`@`)?(\w*\.*%?)*`?\)?)?(| )TRIGGER/i,
|
|
149
|
-
matchHandler: lineNumber =>
|
|
150
|
-
|
|
193
|
+
matchHandler: lineNumber => ({
|
|
194
|
+
lineNumber
|
|
195
|
+
}),
|
|
196
|
+
outputFormatter: lineNumberCheckFormatter,
|
|
151
197
|
results: [],
|
|
152
198
|
message: 'TRIGGER statement',
|
|
153
199
|
excerpt: "'TRIGGER' statement should not be present (case-sensitive)",
|
|
@@ -155,8 +201,10 @@ const checks = {
|
|
|
155
201
|
},
|
|
156
202
|
dropDB: {
|
|
157
203
|
matcher: /^DROP DATABASE/i,
|
|
158
|
-
matchHandler: lineNumber =>
|
|
159
|
-
|
|
204
|
+
matchHandler: lineNumber => ({
|
|
205
|
+
lineNumber
|
|
206
|
+
}),
|
|
207
|
+
outputFormatter: lineNumberCheckFormatter,
|
|
160
208
|
results: [],
|
|
161
209
|
message: 'DROP DATABASE statement',
|
|
162
210
|
excerpt: "'DROP DATABASE' should not be present (case-insensitive)",
|
|
@@ -164,8 +212,10 @@ const checks = {
|
|
|
164
212
|
},
|
|
165
213
|
useStatement: {
|
|
166
214
|
matcher: /^USE /i,
|
|
167
|
-
matchHandler: lineNumber =>
|
|
168
|
-
|
|
215
|
+
matchHandler: lineNumber => ({
|
|
216
|
+
lineNumber
|
|
217
|
+
}),
|
|
218
|
+
outputFormatter: lineNumberCheckFormatter,
|
|
169
219
|
results: [],
|
|
170
220
|
message: 'USE <DATABASE_NAME> statement',
|
|
171
221
|
excerpt: "'USE <DATABASE_NAME>' should not be present (case-insensitive)",
|
|
@@ -173,8 +223,10 @@ const checks = {
|
|
|
173
223
|
},
|
|
174
224
|
alterUser: {
|
|
175
225
|
matcher: /^(ALTER USER|SET PASSWORD)/i,
|
|
176
|
-
matchHandler: lineNumber =>
|
|
177
|
-
|
|
226
|
+
matchHandler: lineNumber => ({
|
|
227
|
+
lineNumber
|
|
228
|
+
}),
|
|
229
|
+
outputFormatter: lineNumberCheckFormatter,
|
|
178
230
|
results: [],
|
|
179
231
|
message: 'ALTER USER statement',
|
|
180
232
|
excerpt: "'ALTER USER' should not be present (case-insensitive)",
|
|
@@ -182,7 +234,9 @@ const checks = {
|
|
|
182
234
|
},
|
|
183
235
|
dropTable: {
|
|
184
236
|
matcher: /^DROP TABLE IF EXISTS `?([a-z0-9_]*)/i,
|
|
185
|
-
matchHandler: (lineNumber, results) =>
|
|
237
|
+
matchHandler: (lineNumber, results) => ({
|
|
238
|
+
text: results[1]
|
|
239
|
+
}),
|
|
186
240
|
outputFormatter: requiredCheckFormatter,
|
|
187
241
|
results: [],
|
|
188
242
|
message: 'DROP TABLE',
|
|
@@ -191,7 +245,9 @@ const checks = {
|
|
|
191
245
|
},
|
|
192
246
|
createTable: {
|
|
193
247
|
matcher: /^CREATE TABLE (?:IF NOT EXISTS )?`?([a-z0-9_]*)/i,
|
|
194
|
-
matchHandler: (lineNumber, results) =>
|
|
248
|
+
matchHandler: (lineNumber, results) => ({
|
|
249
|
+
text: results[1]
|
|
250
|
+
}),
|
|
195
251
|
outputFormatter: requiredCheckFormatter,
|
|
196
252
|
results: [],
|
|
197
253
|
message: 'CREATE TABLE',
|
|
@@ -200,42 +256,85 @@ const checks = {
|
|
|
200
256
|
},
|
|
201
257
|
siteHomeUrl: {
|
|
202
258
|
matcher: "'(siteurl|home)',\\s?'(.*?)'",
|
|
203
|
-
matchHandler: (lineNumber, results) =>
|
|
259
|
+
matchHandler: (lineNumber, results) => ({
|
|
260
|
+
text: results[1]
|
|
261
|
+
}),
|
|
204
262
|
outputFormatter: infoCheckFormatter,
|
|
205
263
|
results: [],
|
|
206
264
|
message: 'Siteurl/home matches',
|
|
207
265
|
excerpt: 'Siteurl/home options',
|
|
208
266
|
recommendation: ''
|
|
209
267
|
},
|
|
268
|
+
siteHomeUrlLando: {
|
|
269
|
+
matcher: "'(siteurl|home)',\\s?'(.*?)'",
|
|
270
|
+
matchHandler: (lineNumber, results, expectedDomain) => {
|
|
271
|
+
const foundDomain = results[2].replace(/https?:\/\//, '');
|
|
272
|
+
|
|
273
|
+
if (!foundDomain.trim()) {
|
|
274
|
+
return {
|
|
275
|
+
falsePositive: true
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (foundDomain.includes(expectedDomain)) {
|
|
280
|
+
return {
|
|
281
|
+
falsePositive: true
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return {
|
|
286
|
+
warning: true,
|
|
287
|
+
lineNumber,
|
|
288
|
+
recomendation: `Use '--search-replace="${foundDomain},${expectedDomain}"' switch to replace the domain`
|
|
289
|
+
};
|
|
290
|
+
},
|
|
291
|
+
outputFormatter: generalCheckFormatter,
|
|
292
|
+
results: [],
|
|
293
|
+
message: 'Siteurl/home options not pointing to lando domain',
|
|
294
|
+
excerpt: 'Siteurl/home options not pointing to lando domain',
|
|
295
|
+
recommendation: 'Use search-replace to change environment\'s domain'
|
|
296
|
+
},
|
|
210
297
|
engineInnoDB: {
|
|
211
298
|
matcher: / ENGINE=(?!(InnoDB))/i,
|
|
212
|
-
matchHandler: lineNumber =>
|
|
213
|
-
|
|
299
|
+
matchHandler: lineNumber => ({
|
|
300
|
+
lineNumber
|
|
301
|
+
}),
|
|
302
|
+
outputFormatter: lineNumberCheckFormatter,
|
|
214
303
|
results: [],
|
|
215
304
|
message: 'ENGINE != InnoDB',
|
|
216
305
|
excerpt: "'ENGINE=InnoDB' should be present (case-insensitive) for all tables",
|
|
217
306
|
recommendation: "Ensure your application works with InnoDB and update your SQL dump to include only 'ENGINE=InnoDB' engine definitions in 'CREATE TABLE' statements. " + "We suggest you search for all 'ENGINE=X' entries and replace them with 'ENGINE=InnoDB'!"
|
|
218
307
|
}
|
|
219
308
|
};
|
|
309
|
+
const DEV_ENV_SPECIFIC_CHECKS = ['useStatement', 'siteHomeUrlLando'];
|
|
220
310
|
|
|
221
|
-
const postValidation = async
|
|
311
|
+
const postValidation = async options => {
|
|
222
312
|
await (0, _tracker.trackEvent)('import_validate_sql_command_execute', {
|
|
223
|
-
is_import: isImport
|
|
313
|
+
is_import: options.isImport
|
|
224
314
|
});
|
|
225
315
|
|
|
226
|
-
if (!isImport) {
|
|
316
|
+
if (!options.isImport) {
|
|
227
317
|
(0, _singleLineLog.stdout)(`Finished processing ${lineNum} lines.`);
|
|
228
318
|
console.log('\n');
|
|
229
319
|
}
|
|
230
320
|
|
|
231
321
|
const errorSummary = {};
|
|
232
|
-
const checkEntries = Object.entries(checks);
|
|
322
|
+
const checkEntries = Object.entries(checks).filter(([type]) => !options.skipChecks.includes(type));
|
|
323
|
+
const formattedWarnings = [];
|
|
233
324
|
let formattedErrors = [];
|
|
234
325
|
let formattedInfos = [];
|
|
235
326
|
|
|
236
327
|
for (const [type, check] of checkEntries) {
|
|
237
|
-
const formattedOutput = check.outputFormatter(check, type, isImport);
|
|
238
|
-
|
|
328
|
+
const formattedOutput = check.outputFormatter(check, type, options.isImport);
|
|
329
|
+
|
|
330
|
+
for (const error of formattedOutput.errors) {
|
|
331
|
+
if (error.warning) {
|
|
332
|
+
formattedWarnings.push(error);
|
|
333
|
+
} else {
|
|
334
|
+
formattedErrors.push(error);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
239
338
|
formattedInfos = formattedInfos.concat(formattedOutput.infos);
|
|
240
339
|
errorSummary[type] = check.results.length;
|
|
241
340
|
} // eslint-disable-next-line camelcase
|
|
@@ -267,9 +366,24 @@ const postValidation = async (filename, isImport = false) => {
|
|
|
267
366
|
formattedErrors = formattedErrors.concat(errorObject);
|
|
268
367
|
}
|
|
269
368
|
|
|
369
|
+
if (formattedWarnings.length) {
|
|
370
|
+
const warningOutput = [];
|
|
371
|
+
formattedWarnings.forEach(warning => {
|
|
372
|
+
warningOutput.push(warning.warning);
|
|
373
|
+
|
|
374
|
+
if (warning.recommendation) {
|
|
375
|
+
warningOutput.push(warning.recommendation);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
warningOutput.push('');
|
|
379
|
+
});
|
|
380
|
+
console.log(warningOutput.join('\n'));
|
|
381
|
+
console.log('');
|
|
382
|
+
}
|
|
383
|
+
|
|
270
384
|
if (problemsFound > 0) {
|
|
271
385
|
await (0, _tracker.trackEvent)('import_validate_sql_command_failure', {
|
|
272
|
-
is_import: isImport,
|
|
386
|
+
is_import: options.isImport,
|
|
273
387
|
error: errorSummary
|
|
274
388
|
});
|
|
275
389
|
const errorOutput = [`SQL validation failed due to ${_chalk.default.red(problemsFound)} error(s)`, ''];
|
|
@@ -283,25 +397,23 @@ const postValidation = async (filename, isImport = false) => {
|
|
|
283
397
|
errorOutput.push('');
|
|
284
398
|
});
|
|
285
399
|
|
|
286
|
-
if (isImport) {
|
|
400
|
+
if (options.isImport) {
|
|
287
401
|
throw new Error(errorOutput.join('\n'));
|
|
288
402
|
}
|
|
289
403
|
|
|
290
404
|
exit.withError(errorOutput.join('\n'));
|
|
291
405
|
}
|
|
292
406
|
|
|
293
|
-
if (!isImport) {
|
|
407
|
+
if (!options.isImport) {
|
|
294
408
|
console.log(formattedInfos.join('\n'));
|
|
295
409
|
console.log('');
|
|
296
410
|
}
|
|
297
411
|
|
|
298
412
|
await (0, _tracker.trackEvent)('import_validate_sql_command_success', {
|
|
299
|
-
is_import: isImport
|
|
413
|
+
is_import: options.isImport
|
|
300
414
|
});
|
|
301
415
|
};
|
|
302
416
|
|
|
303
|
-
exports.postValidation = postValidation;
|
|
304
|
-
|
|
305
417
|
const getTableNames = () => {
|
|
306
418
|
return tableNames;
|
|
307
419
|
};
|
|
@@ -318,53 +430,63 @@ const checkForTableName = line => {
|
|
|
318
430
|
}
|
|
319
431
|
};
|
|
320
432
|
|
|
321
|
-
const
|
|
433
|
+
const DEFAULT_VALIDATION_OPTIONS = {
|
|
434
|
+
isImport: true,
|
|
435
|
+
skipChecks: DEV_ENV_SPECIFIC_CHECKS,
|
|
436
|
+
extraCheckParams: {}
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
const perLineValidations = (line, options = DEFAULT_VALIDATION_OPTIONS) => {
|
|
322
440
|
if (lineNum % 500 === 0) {
|
|
323
|
-
|
|
441
|
+
options.isImport ? '' : (0, _singleLineLog.stdout)(`Reading line ${lineNum} `);
|
|
324
442
|
}
|
|
325
443
|
|
|
326
444
|
checkForTableName(line);
|
|
327
|
-
const checkKeys = Object.keys(checks).filter(checkItem => !skipChecks.includes(checkItem));
|
|
328
|
-
|
|
329
|
-
|
|
445
|
+
const checkKeys = Object.keys(checks).filter(checkItem => !options.skipChecks.includes(checkItem));
|
|
446
|
+
|
|
447
|
+
for (const checkKey of checkKeys) {
|
|
448
|
+
const check = checks[checkKey];
|
|
330
449
|
const results = line.match(check.matcher);
|
|
450
|
+
const extraCheckParams = options.extraCheckParams[checkKey];
|
|
331
451
|
|
|
332
452
|
if (results) {
|
|
333
|
-
check.results.push(check.matchHandler(lineNum, results));
|
|
453
|
+
check.results.push(check.matchHandler(lineNum, results, extraCheckParams));
|
|
334
454
|
}
|
|
335
|
-
}
|
|
336
|
-
lineNum += 1;
|
|
337
|
-
};
|
|
455
|
+
}
|
|
338
456
|
|
|
339
|
-
|
|
340
|
-
perLineValidations(line, isImport, skipChecks);
|
|
457
|
+
lineNum += 1;
|
|
341
458
|
};
|
|
342
459
|
|
|
343
460
|
const postLineExecutionProcessing = async ({
|
|
344
|
-
|
|
345
|
-
|
|
461
|
+
isImport,
|
|
462
|
+
skipChecks
|
|
346
463
|
}) => {
|
|
347
|
-
await postValidation(
|
|
464
|
+
await postValidation({
|
|
465
|
+
isImport: isImport || false,
|
|
466
|
+
skipChecks: skipChecks || DEV_ENV_SPECIFIC_CHECKS,
|
|
467
|
+
extraCheckParams: {}
|
|
468
|
+
});
|
|
348
469
|
};
|
|
349
470
|
|
|
350
471
|
const staticSqlValidations = {
|
|
351
|
-
execute,
|
|
472
|
+
execute: perLineValidations,
|
|
352
473
|
postLineExecutionProcessing
|
|
353
474
|
}; // For standalone SQL validations
|
|
354
475
|
|
|
355
476
|
exports.staticSqlValidations = staticSqlValidations;
|
|
356
477
|
|
|
357
|
-
const validate = async (filename,
|
|
478
|
+
const validate = async (filename, options = DEFAULT_VALIDATION_OPTIONS) => {
|
|
358
479
|
const readInterface = await (0, _lineByLine.getReadInterface)(filename);
|
|
480
|
+
options.isImport = false;
|
|
359
481
|
readInterface.on('line', line => {
|
|
360
|
-
|
|
482
|
+
perLineValidations(line, options);
|
|
361
483
|
}); // Block until the processing completes
|
|
362
484
|
|
|
363
485
|
await new Promise(resolve => readInterface.on('close', resolve));
|
|
364
486
|
readInterface.close();
|
|
365
487
|
await postLineExecutionProcessing({
|
|
366
|
-
|
|
367
|
-
|
|
488
|
+
isImport: options.isImport,
|
|
489
|
+
skipChecks: options.skipChecks
|
|
368
490
|
});
|
|
369
491
|
};
|
|
370
492
|
|