From a3126c25cc8ba17293a30e41800d47f92e4de2fc Mon Sep 17 00:00:00 2001 From: Rui Barbosa Date: Thu, 5 Oct 2023 13:22:24 -0400 Subject: [PATCH] Advanced collection (#45) * fixed colision in object id + empty remote collection handling --- .DS_Store | Bin 6148 -> 0 bytes src/Collection.js | 19 +++++++++++++------ src/CollectionAdvanced.js | 17 ++++++++++++----- src/DeployIncremental.js | 15 +++++++++++++-- 4 files changed, 38 insertions(+), 13 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 5dd6a0d4c51fd025c9bc0a02bb6771dd2c251f27..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyG{c!5S)b+C()#&^e^xSRusN~A3)@SgcNj0i2f?RE1$;fqaZrcg(jMn)?=@C zY@mKMpSwl&-vQ?i*kQsuK7R9G zrs?3DGASShq<|EV0#e|j3RHO=?k;+&4wC{>;2IS0??aKhr(uNO$8rC>)|36Qdk+;pO-~ ck}|LPocq0SP7FHZK_}{Gz;%&Hf&W(E2iZ0iZU6uP diff --git a/src/Collection.js b/src/Collection.js index a50caed..f3d6e94 100644 --- a/src/Collection.js +++ b/src/Collection.js @@ -110,12 +110,17 @@ class Collection { */ process () { console.log('Processing collection') + const info = this.getInfo() + this.collectionId = info._postman_id + const item = this.getItems() + const variable = this.getVariables() + const auth = this.defaultAuth() const collection = { - info: this.getInfo(), - item: this.getItems(), + info: info, + item: item, event: [], - variable: this.getVariables(), - auth: this.defaultAuth() + variable: variable, + auth: auth } console.log('Done') return collection @@ -206,7 +211,7 @@ class Collection { item: [] } - const folderId = Utils.GenID(JSON.stringify(folder)) + const folderId = Utils.GenID(this.collectionId + JSON.stringify(folder)) folder.id = folderId if (this.verbose) { console.log(` Adding Folder [${folder.name}]`) @@ -234,7 +239,9 @@ class Collection { event: this.getItemEvents(endpoint) } - const itemId = Utils.GenID(JSON.stringify(item)) + // RB: This should pickup a different object id + // unexpected object id collision + const itemId = Utils.GenID(this.collectionId + JSON.stringify(item)) item.id = itemId item.request = this.requestCreate(verb, path, endpoint, item.id) item.response = this.responseCreate(endpoint, item.request.id) diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index 05571e7..4f21f9e 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -52,12 +52,19 @@ class CollectionAdvanced extends Collection { */ // RB: override process () { + console.log('Processing collection') + const info = this.getInfo() + this.collectionId = info._postman_id + const item = this.getItems() + const event = [this.collectionPreRequest()] + const variable = this.getVariables() + const auth = this.defaultAuth() const localCollection = { - info: this.getInfo(), - item: this.getItems(), - event: [this.collectionPreRequest()], - variable: this.getVariables(), - auth: this.defaultAuth() + info, + item, + event, + variable, + auth } // RB: inject utilities diff --git a/src/DeployIncremental.js b/src/DeployIncremental.js index f95753c..521af71 100644 --- a/src/DeployIncremental.js +++ b/src/DeployIncremental.js @@ -156,8 +156,19 @@ const checkObjectChanges = (remoteCollectionObject, localCollectionObject) => { } const checkScriptChanges = (scriptType, remoteCollection, localCollection) => { - const remoteScript = remoteCollection.collection.event.find(event => event.listen === scriptType) - const localScript = localCollection.event.find(event => event.listen === scriptType) + // RB 2020-10-20: The collection may be empty or have no events at all + let remoteScript = null + let localScript = null + if (remoteCollection.collection.event) { + remoteScript = remoteCollection.collection.event.find(event => event.listen === scriptType) + } + + if (localCollection.event) { + localScript = localCollection.event.find(event => event.listen === scriptType) + } + + // const remoteScript = remoteCollection.collection.event.find(event => event.listen === scriptType) + // const localScript = localCollection.event.find(event => event.listen === scriptType) if (!remoteScript && !localScript) { return false