added sync id feature

This commit is contained in:
Philip Ellis
2024-01-22 15:21:00 -06:00
parent 2ac944a223
commit 66a205c3cc
2 changed files with 44 additions and 12 deletions

View File

@@ -22,11 +22,11 @@ const release = async () => {
} }
// check if the top level collection has changed, If so, update it... This will delete all folders unfortunately. // check if the top level collection has changed, If so, update it... This will delete all folders unfortunately.
if (checkIfDifferent(remoteCollection.collection.event, localCollection.event) if (checkIfDifferent(localCollection.event, remoteCollection.collection.event)
|| checkIfDifferent(remoteCollection.collection.info.description, localCollection.info.description.content) || checkIfDifferent( localCollection.info.description.content, remoteCollection.collection.info.description)
|| checkIfDifferent(remoteCollection.collection.info.name, localCollection.info.name) || checkIfDifferent( localCollection.info.name, remoteCollection.collection.info.name)
|| checkIfDifferent(remoteCollection.collection.variable, localCollection.variable) || checkIfDifferent(localCollection.variable, remoteCollection.collection.variable)
|| checkIfDifferent(remoteCollection.collection.auth, localCollection.auth)) { || checkIfDifferent( localCollection.auth, remoteCollection.collection.auth)) {
const localEmptyCollection = { ...localCollection } const localEmptyCollection = { ...localCollection }
localEmptyCollection.item = [] localEmptyCollection.item = []
//delete all folders. Do this one at a time so it doesn't timeout //delete all folders. Do this one at a time so it doesn't timeout
@@ -113,8 +113,7 @@ function buildRequestBody(items) {
} }
function checkIfDifferent(source, dest) { function checkIfDifferent(source, dest) {
removeIdFields(source) syncKeys(source, dest)
removeIdFields(dest)
if (isDeepEqual(source, dest)) { if (isDeepEqual(source, dest)) {
return false return false
} }
@@ -149,6 +148,34 @@ function isNullorEmpty(obj) {
} }
function syncKeys(obj1, obj2) {
if (typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 == null || obj2 == null) {
return;
}
const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);
for (let key of keys1) {
const val1 = obj1[key];
const val2 = obj2[key];
if (val2 === undefined) {
continue;
} else if (key === 'id') {
obj1[key] = val2;
}
const areObjects = isObject(val1) && isObject(val2);
if (areObjects) {
syncKeys(val1, val2)
}
}
return true;
}
function isDeepEqual(obj1, obj2) { function isDeepEqual(obj1, obj2) {
if (areValuesEqual(obj1, obj2)) { if (areValuesEqual(obj1, obj2)) {
return true return true

View File

@@ -33,7 +33,7 @@ class Collection {
retries: 10, retries: 10,
retryCondition: (error) => { retryCondition: (error) => {
console.log('error, retrying') console.log('error, retrying')
return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error) || error.response.status === 429 return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error)
} }
}) })
@@ -96,7 +96,7 @@ class Folder {
//retryDelay: axiosRetry.exponentialDelay, //retryDelay: axiosRetry.exponentialDelay,
retryCondition: (error) => { retryCondition: (error) => {
console.log('error, retrying') console.log('error, retrying')
return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error) || error.response.status === 429 return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error)
} }
}) })
//this.axios.interceptors.response.use(response => response, handleError); //this.axios.interceptors.response.use(response => response, handleError);
@@ -164,11 +164,16 @@ class Request {
}) })
axiosRetry(this.axios, { axiosRetry(this.axios, {
retries: 10, retries: 10,
//retryDelay: axiosRetry.exponentialDelay, retryDelay: axiosRetry.exponentialDelay,
retryCondition: (error) => { retryCondition: (error) => {
console.log('error, retrying') console.log('error, retrying')
return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error) || error.response.status === 429 return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error)
},
onRetryAttempt: (err) => {
const cfg = axiosRetry.getConfig(err);
console.log(`Retry attempt #${cfg.currentRetryAttempt}`);
} }
}) })
//this.axios.interceptors.response.use(response => response, handleError); //this.axios.interceptors.response.use(response => response, handleError);
} }
@@ -239,7 +244,7 @@ class Response {
//retryDelay: axiosRetry.exponentialDelay, //retryDelay: axiosRetry.exponentialDelay,
retryCondition: (error) => { retryCondition: (error) => {
console.log('error, retrying') console.log('error, retrying')
return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error) || error.response.status === 429 return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error)
} }
}) })
//this.axios.interceptors.response.use(response => response, handleError); //this.axios.interceptors.response.use(response => response, handleError);