@@ -2,10 +2,10 @@ const chalk = require('chalk');
22const inquirer = require("inquirer");
33const JSONbig = require("json-bigint")({ storeAsString: false });
44const { 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");
66const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
77const { paginate } = require('../paginate');
8- const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionPushChangesConfirmation , questionsPushMessagingTopics, questionsPushResources } = require("../questions");
8+ const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionPushChangesFix , questionsPushMessagingTopics, questionsPushResources } = require("../questions");
99const { cliConfig, actionRunner, success, warn, log, hint, error, commandDescriptions, drawTable } = require("../parser");
1010const { proxyListRules } = require('./proxy');
1111const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
@@ -341,42 +341,50 @@ const awaitPools = {
341341}
342342
343343const 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- }
350-
351- return answers.changes;
352- }
344+ if (cliConfig.force) {
345+ return true;
346+ }
353347
354- let answers = await inquirer.prompt(questionPushChanges);
348+ async function fixConfirmation() {
349+ const answers = await inquirer.prompt(questionPushChangesFix);
355350 if (answers.changes !== 'YES' && answers.changes !== 'NO') {
356- answers.changes = await fixConfirmation();
351+ return await fixConfirmation();
357352 }
358353
359- if (answers.changes === 'YES') {
360- return true;
361- }
354+ return answers.changes;
355+ }
356+
357+ let answers = await inquirer.prompt(questionPushChanges);
358+
359+ if (answers.changes !== 'YES' && answers.changes !== 'NO') {
360+ answers.changes = await fixConfirmation();
361+ }
362362
363- warn('Skipping push action. Changes were not applied.');
364- return false ;
363+ if (answers.changes === 'YES') {
364+ return true ;
365365 }
366366
367- return true;
367+ warn('Skipping push action. Changes were not applied.');
368+ return false;
369+
368370};
369371
370- const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = []) => {
372+ const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = [], secondId = '', secondResourceName = '' ) => {
371373 log('Checking for changes ...');
372374 const changes = [];
373375
374376 await Promise.all(resource.map(async (localResource) => {
375377 try {
376- const remoteResource = await resourceGetFunction( {
378+ const options = {
377379 [resourceName]: localResource['$id'],
378380 parseOutput: false,
379- });
381+ };
382+
383+ if (secondId !== '' && secondResourceName !== '') {
384+ options[secondResourceName] = localResource[secondId]
385+ }
386+
387+ const remoteResource = await resourceGetFunction(options);
380388
381389 for (let [key, value] of Object.entries(whitelistKeys(remoteResource, keys))) {
382390 if (skipKeys.includes(key)) {
@@ -1310,8 +1318,6 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
13101318
13111319 const databases = Array.from(new Set(collections.map(collection => collection['databaseId'])));
13121320
1313- log('Checking for changes ...');
1314-
13151321 // Parallel db actions
13161322 await Promise.all(databases.map(async (databaseId) => {
13171323 const localDatabase = localConfig.getDatabase(databaseId);
@@ -1342,6 +1348,10 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
13421348 }
13431349 }));
13441350
1351+
1352+ if (!(await approveChanges(collections, databasesGetCollection, KeysCollection, 'collectionId', 'collections', ['attributes', 'indexes'], 'databaseId', 'databaseId',))) {
1353+ return;
1354+ }
13451355 // Parallel collection actions
13461356 await Promise.all(collections.map(async (collection) => {
13471357 try {
0 commit comments