From 824b56483ce807a0637a04ed4d24a58c5e9c6172 Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Thu, 18 Mar 2021 15:59:56 +0000 Subject: [PATCH 1/4] fix: Remove the global reference to target --- src/rules/deleteReferences.ts | 14 ++++++-------- src/rules/maintainCount.ts | 5 +++-- src/rules/replicateAttributes.ts | 1 - 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/rules/deleteReferences.ts b/src/rules/deleteReferences.ts index 522f503..e4cea03 100644 --- a/src/rules/deleteReferences.ts +++ b/src/rules/deleteReferences.ts @@ -67,7 +67,6 @@ export function integrifyDeleteReferences( // Call "pre" hook if defined if (rule.hooks && rule.hooks.pre) { await rule.hooks.pre(snap, context); - // logger.debug(`integrify: Running pre-hook: ${rule.hooks.pre}`); } // Loop over each target @@ -93,25 +92,25 @@ export function integrifyDeleteReferences( { source: snap.data() || {}, ...context.params }, target.collection ); - target.collection = fieldSwap.targetCollection; + const targetCollection = fieldSwap.targetCollection; // Delete all docs in this target corresponding to deleted master doc let whereable: FirebaseFirestore.Query = null; if (target.isCollectionGroup) { - whereable = db.collectionGroup(target.collection); + whereable = db.collectionGroup(targetCollection); } else { - whereable = db.collection(target.collection); + whereable = db.collection(targetCollection); } if (target.deleteAll) { logger.debug( - `integrify: Deleting all docs in sub-collection [${target.collection}]` + `integrify: Deleting all docs in sub-collection [${targetCollection}]` ); } else { logger.debug( `integrify: Deleting all docs in collection ${ target.isCollectionGroup ? 'group ' : '' - }[${target.collection}] where foreign key [${ + }[${targetCollection}] where foreign key [${ target.foreignKey }] matches [${primaryKeyValue}]` ); @@ -123,7 +122,7 @@ export function integrifyDeleteReferences( const querySnap = await whereable.get(); for (const doc of querySnap.docs) { logger.debug( - `integrify: Deleting [${target.collection}]${ + `integrify: Deleting [${targetCollection}]${ target.isCollectionGroup ? ' (group)' : '' }, id [${doc.id}]` ); @@ -135,7 +134,6 @@ export function integrifyDeleteReferences( // Call "post" hook if defined if (rule.hooks && rule.hooks.post) { await rule.hooks.post(snap, context); - // logger.debug(`integrify: Running post-hook: ${rule.hooks.post}`); } }); } diff --git a/src/rules/maintainCount.ts b/src/rules/maintainCount.ts index 8e14c6b..b57b6c4 100644 --- a/src/rules/maintainCount.ts +++ b/src/rules/maintainCount.ts @@ -69,15 +69,16 @@ export function integrifyMaintainCount( rule.target.collection, rule?.hooks?.pre ); + const targetCollection = fieldSwap.targetCollection; // For maintain it must reference a doc - const targetRef = db.doc(fieldSwap.targetCollection); + const targetRef = db.doc(targetCollection); const targetSnap = await targetRef.get(); // No-op if target does not exist if (!targetSnap.exists) { logger.debug( - `integrify: WARNING: Target document does not exist in [${fieldSwap.targetCollection}]` + `integrify: WARNING: Target document does not exist in [${targetCollection}]` ); return; } diff --git a/src/rules/replicateAttributes.ts b/src/rules/replicateAttributes.ts index 524a71a..2057d2c 100644 --- a/src/rules/replicateAttributes.ts +++ b/src/rules/replicateAttributes.ts @@ -81,7 +81,6 @@ export function integrifyReplicateAttributes( // Call "pre" hook if defined if (rule.hooks && rule.hooks.pre) { await rule.hooks.pre(change, context); - // logger.debug(`integrify: Running pre-hook: ${rule.hooks.pre}`); } // Check if at least one of the attributes to be replicated was changed From d90858c20905b601379577c1b39454a2dbc34c38 Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Thu, 18 Mar 2021 16:00:24 +0000 Subject: [PATCH 2/4] 5.0.0-beta.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 099fe11..3420a32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "integrify", - "version": "4.0.3", + "version": "5.0.0-beta.1", "description": "Enforce referential integrity in Firestore using Cloud Functions", "keywords": [ "firebase", From 42aa4f6a86034203041220901823c755573abd1f Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Thu, 18 Mar 2021 16:01:48 +0000 Subject: [PATCH 3/4] 5.0.0-alpha.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3420a32..14cb8dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "integrify", - "version": "5.0.0-beta.1", + "version": "5.0.0-alpha.1", "description": "Enforce referential integrity in Firestore using Cloud Functions", "keywords": [ "firebase", From ceba6dac61644c4ac555ce5e9736fc3b6849fac9 Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Thu, 18 Mar 2021 16:55:25 +0000 Subject: [PATCH 4/4] chore: Update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 14cb8dd..ad85d37 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "integrify", - "version": "5.0.0-alpha.1", + "version": "5.0.0", "description": "Enforce referential integrity in Firestore using Cloud Functions", "keywords": [ "firebase",