@@ -2,7 +2,7 @@ const chalk = require('chalk');
2
2
const inquirer = require("inquirer");
3
3
const JSONbig = require("json-bigint")({ storeAsString: false });
4
4
const { Command } = require("commander");
5
- const { localConfig, globalConfig, KeysAttributes, KeysFunction, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, } = require("../config");
5
+ const { localConfig, globalConfig, KeysAttributes, KeysFunction, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, KeysCollection } = require("../config");
6
6
const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
7
7
const { paginate } = require('../paginate');
8
8
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionPushChangesConfirmation, questionsPushMessagingTopics, questionsPushResources } = require("../questions");
@@ -341,42 +341,50 @@ const awaitPools = {
341
341
}
342
342
343
343
const getConfirmation = async () => {
344
- if (!cliConfig.force) {
345
- async function fixConfirmation() {
346
- const answers = await inquirer.prompt(questionPushChangesConfirmation);
347
- if(answers.changes !== 'YES' && answers.changes !== 'NO') {
348
- return await fixConfirmation();
349
- }
344
+ if (cliConfig.force) {
345
+ return true;
346
+ }
350
347
351
- return answers.changes;
348
+ async function fixConfirmation() {
349
+ const answers = await inquirer.prompt(questionPushChangesConfirmation);
350
+ if (answers.changes !== 'YES' && answers.changes !== 'NO') {
351
+ return await fixConfirmation();
352
352
}
353
353
354
- let answers = await inquirer.prompt(questionPushChanges);
355
- if(answers.changes !== 'YES' && answers.changes !== 'NO') {
356
- answers.changes = await fixConfirmation();
357
- }
354
+ return answers.changes;
355
+ }
358
356
359
- if (answers.changes === 'YES') {
360
- return true;
361
- }
357
+ let answers = await inquirer.prompt(questionPushChanges);
362
358
363
- warn('Skipping push action. Changes were not applied.');
364
- return false ;
359
+ if (answers.changes !== 'YES' && answers.changes !== 'NO') {
360
+ answers.changes = await fixConfirmation() ;
365
361
}
366
362
367
- return true;
363
+ if (answers.changes === 'YES') {
364
+ return true;
365
+ }
366
+
367
+ warn('Skipping push action. Changes were not applied.');
368
+ return false;
369
+
368
370
};
369
371
370
- const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = []) => {
372
+ const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = [], secondId = '', secondResourceName = '' ) => {
371
373
log('Checking for changes ...');
372
374
const changes = [];
373
375
374
376
await Promise.all(resource.map(async (localResource) => {
375
377
try {
376
- const remoteResource = await resourceGetFunction( {
378
+ const options = {
377
379
[resourceName]: localResource['$id'],
378
380
parseOutput: false,
379
- });
381
+ };
382
+
383
+ if (secondId !== '' && secondResourceName !== '') {
384
+ options[secondResourceName] = localResource[secondId]
385
+ }
386
+
387
+ const remoteResource = await resourceGetFunction(options);
380
388
381
389
for (let [key, value] of Object.entries(whitelistKeys(remoteResource, keys))) {
382
390
if (skipKeys.includes(key)) {
@@ -412,7 +420,7 @@ const approveChanges = async (resource, resourceGetFunction, keys, resourceName,
412
420
}
413
421
414
422
drawTable(changes);
415
- if((await getConfirmation()) === true) {
423
+ if ((await getConfirmation()) === true) {
416
424
return true;
417
425
}
418
426
@@ -688,6 +696,20 @@ const deleteAttribute = async (collection, attribute, isIndex = false) => {
688
696
});
689
697
}
690
698
699
+ const compareAttribute = (remote, local, reason, key) => {
700
+ if (Array.isArray(remote) && Array.isArray(local)) {
701
+ if (JSON.stringify(remote) !== JSON.stringify(local)) {
702
+ const bol = reason === '' ? '' : '\n';
703
+ reason += `${bol}${key} changed from ${chalk.red(remote)} to ${chalk.green(local)}`;
704
+ }
705
+ } else if (remote !== local) {
706
+ const bol = reason === '' ? '' : '\n';
707
+ reason += `${bol}${key} changed from ${chalk.red(remote)} to ${chalk.green(local)}`;
708
+ }
709
+
710
+ return reason
711
+ }
712
+
691
713
692
714
/**
693
715
* Check if attribute non-changeable fields has been changed
@@ -715,11 +737,7 @@ const checkAttributeChanges = (remote, local, collection, recraeting = true) =>
715
737
716
738
if (changeableKeys.includes(key)) {
717
739
if (!recraeting) {
718
- if (remote[key] !== local[key]) {
719
- const bol = reason === '' ? '' : '\n';
720
- reason += `${bol}${key} changed from ${chalk.red(remote[key])} to ${chalk.green(local[key])}`;
721
- attribute = local;
722
- }
740
+ reason += compareAttribute(remote[key], local[key], reason, key)
723
741
}
724
742
continue;
725
743
}
@@ -728,15 +746,7 @@ const checkAttributeChanges = (remote, local, collection, recraeting = true) =>
728
746
continue;
729
747
}
730
748
731
- if (Array.isArray(remote[key]) && Array.isArray(local[key])) {
732
- if (JSON.stringify(remote[key]) !== JSON.stringify(local[key])) {
733
- const bol = reason === '' ? '' : '\n';
734
- reason += `${bol}${key} changed from ${chalk.red(remote[key])} to ${chalk.green(local[key])}`;
735
- }
736
- } else if (remote[key] !== local[key]) {
737
- const bol = reason === '' ? '' : '\n';
738
- reason += `${bol}${key} changed from ${chalk.red(remote[key])} to ${chalk.green(local[key])}`;
739
- }
749
+ reason += compareAttribute(remote[key], local[key], reason, key)
740
750
}
741
751
742
752
return reason === '' ? undefined : { key: keyName, attribute, reason, action };
@@ -793,7 +803,7 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection,
793
803
log(`Attribute recreation will cause ${chalk.red('loss of data')}`);
794
804
}
795
805
796
- if((await getConfirmation()) !== true) {
806
+ if ((await getConfirmation()) !== true) {
797
807
return changedAttributes;
798
808
}
799
809
}
@@ -915,7 +925,7 @@ const pushSettings = async () => {
915
925
916
926
if (changes.length > 0) {
917
927
drawTable(changes);
918
- if((await getConfirmation()) !== true) {
928
+ if ((await getConfirmation()) !== true) {
919
929
success(`Successfully pushed 0 project settings.`);
920
930
return;
921
931
}
@@ -1308,8 +1318,6 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
1308
1318
1309
1319
const databases = Array.from(new Set(collections.map(collection => collection['databaseId'])));
1310
1320
1311
- log('Checking for changes ...');
1312
-
1313
1321
// Parallel db actions
1314
1322
await Promise.all(databases.map(async (databaseId) => {
1315
1323
const localDatabase = localConfig.getDatabase(databaseId);
@@ -1340,6 +1348,10 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
1340
1348
}
1341
1349
}));
1342
1350
1351
+
1352
+ if (!(await approveChanges(collections, databasesGetCollection, KeysCollection, 'collectionId', 'collections', ['attributes', 'indexes'], 'databaseId', 'databaseId',))) {
1353
+ return;
1354
+ }
1343
1355
// Parallel collection actions
1344
1356
await Promise.all(collections.map(async (collection) => {
1345
1357
try {
0 commit comments