From 0c0f8e2c100f767d33e90d1d574db5cc813f8e88 Mon Sep 17 00:00:00 2001 From: Amadeusz Starzykiewicz Date: Wed, 14 Apr 2021 16:49:22 +0200 Subject: [PATCH 01/42] Fix tests after updating Mocha --- testing/client_side_mutators.js | 84 +- testing/collection-defaults/client.js | 68 +- testing/collection_hooks.server.js | 2 +- testing/include_prev_doc.js | 4 +- testing/lib/sync_utils.js | 2 +- testing/main.client.js | 1886 ++++++++++++----------- testing/object-id/client.js | 20 +- testing/optimistic-ui/client.test.js | 94 +- testing/polling/client.js | 42 +- testing/publishComposite/client.test.js | 46 +- testing/synthetic_mutators.js | 161 +- testing/transformations/client.js | 2 +- testing/vent/client.js | 10 +- 13 files changed, 1217 insertions(+), 1204 deletions(-) diff --git a/testing/client_side_mutators.js b/testing/client_side_mutators.js index 013b32e9..2ea7f2f0 100644 --- a/testing/client_side_mutators.js +++ b/testing/client_side_mutators.js @@ -11,66 +11,66 @@ describe('Client-side Mutators', function () { waitForHandleToBeReady } = helperGenerator(config['Standard'].suffix); - it('Should detect an insert/update and removal from client side', async function (done) { + it('Should detect an insert/update and removal from client side', function (done) { const handle = subscribe({ client_side_mutators: true }); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ client_side_mutators: true }); - cursor = Collection.find({ client_side_mutators: true }); - - let testDocId, inChanged = false, inAdded = false, inRemoved = false; - const observer = cursor.observeChanges({ + let testDocId, inChanged = false, inAdded = false, inRemoved = false; + const observer = cursor.observeChanges({ added(docId, doc) { - if (inAdded) { - return; - } - inAdded = true; + if (inAdded) { + return; + } + inAdded = true; - testDocId = docId; - assert.equal(doc.number, 5); + testDocId = docId; + assert.equal(doc.number, 5); - setTimeout(async () => { - const result = await fetchSync({ _id: docId }); - assert.isArray(result); - assert.lengthOf(result, 1); - assert.equal(result[0].number, 5); + setTimeout(async () => { + const result = await fetchSync({ _id: docId }); + assert.isArray(result); + assert.lengthOf(result, 1); + assert.equal(result[0].number, 5); - Collection.update(docId, { - $set: {number: 10} - }) - }, 100) + Collection.update(docId, { + $set: {number: 10} + }) + }, 100) }, changed(docId, doc) { - if (inChanged) { - return; - } - inChanged = true; - assert.equal(docId, testDocId); - assert.equal(doc.number, 10); + if (inChanged) { + return; + } + inChanged = true; + assert.equal(docId, testDocId); + assert.equal(doc.number, 10); - setTimeout(async () => { - const result = await fetchSync({_id: docId}); - assert.lengthOf(result, 1); - assert.equal(result[0].number, 10); + setTimeout(async () => { + const result = await fetchSync({_id: docId}); + assert.lengthOf(result, 1); + assert.equal(result[0].number, 10); - Collection.remove(docId) - }, 100); + Collection.remove(docId) + }, 100); }, removed(docId) { - if (inRemoved) { - return; - } - inRemoved = true; - assert.equal(docId, testDocId); - done(); + if (inRemoved) { + return; + } + inRemoved = true; + assert.equal(docId, testDocId); + done(); } - }); + }); - Collection.insert({ + Collection.insert({ client_side_mutators: true, number: 5 + }); }); }); -}); \ No newline at end of file +}); diff --git a/testing/collection-defaults/client.js b/testing/collection-defaults/client.js index 15163a1b..f832e17c 100644 --- a/testing/collection-defaults/client.js +++ b/testing/collection-defaults/client.js @@ -5,63 +5,63 @@ import {waitForHandleToBeReady, callWithPromise} from '../lib/sync_utils'; import {Random} from 'meteor/random'; describe('Collection Defaults', () => { - it('Should detect changes based on mutation defaults', async function (done) { + it('Should detect changes based on mutation defaults', function (done) { const context = Random.id(); const handle = Meteor.subscribe('collection_defaults.items', {context}); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + const cursor = Items.find({}); - const cursor = Items.find({}); - - const observer = cursor.observeChanges({ + const observer = cursor.observeChanges({ added(docId, doc) { - assert.isObject(doc); - callWithPromise('collection_defaults.items.update', { - _id: docId - }, { - $set: { - number: 10 - } - }) + assert.isObject(doc); + callWithPromise('collection_defaults.items.update', { + _id: docId + }, { + $set: { + number: 10 + } + }) }, changed(docId, doc) { - assert.equal(doc.number, 10); - handle.stop(); - observer.stop(); - done(); + assert.equal(doc.number, 10); + handle.stop(); + observer.stop(); + done(); } - }); + }); - await callWithPromise('collection_defaults.items.insert', { + callWithPromise('collection_defaults.items.insert', { text: 'hello', context + }); }); }); - it('Should not detect changes based if a namespace is specified', async function (done) { + it('Should not detect changes based if a namespace is specified', function (done) { const context = Random.id(); const handle = Meteor.subscribe('collection_defaults.items', {context}, { namespace: 'someothernamespace' }); - await waitForHandleToBeReady(handle); - - const cursor = Items.find({}); + waitForHandleToBeReady(handle).then(function() { + const cursor = Items.find({}); - const observer = cursor.observeChanges({ + const observer = cursor.observeChanges({ added(docId, doc) { - done('It should not be here') + done('It should not be here') }, - }); + }); - await callWithPromise('collection_defaults.items.insert', { + callWithPromise('collection_defaults.items.insert', { text: 'hello again', context + }).then(function() { + setTimeout(function () { + handle.stop(); + observer.stop(); + done(); + }, 200); + }); }); - - setTimeout(function () { - handle.stop(); - observer.stop(); - done(); - }, 200); }); -}); \ No newline at end of file +}); diff --git a/testing/collection_hooks.server.js b/testing/collection_hooks.server.js index 30aad0a9..c46bf5b3 100644 --- a/testing/collection_hooks.server.js +++ b/testing/collection_hooks.server.js @@ -54,4 +54,4 @@ describe('It should work with collection:hooks', function () { }) }) }) -}); \ No newline at end of file +}); diff --git a/testing/include_prev_doc.js b/testing/include_prev_doc.js index 7eec0d63..29829c88 100644 --- a/testing/include_prev_doc.js +++ b/testing/include_prev_doc.js @@ -13,7 +13,7 @@ PrevDocCollection.configureRedisOplog({ }); describe('PrevDocCollection Serverside', function () { - it('Should receive an insert event with prev doc', async function (done) { + it('Should receive an insert event with prev doc', function (done) { Config.pubSubManager.subscribe('test_redis_prev_doc', function(payload) { // make sure events have prev document values if (payload.e === 'u') { @@ -33,7 +33,7 @@ describe('PrevDocCollection Serverside', function () { PrevDocCollection.remove({ _id: `${random}` }); }); - it('Should receive an insert event without prev doc', async function (done) { + it('Should receive an insert event without prev doc', function (done) { Config.pubSubManager.subscribe('test_redis_no_prev_doc', function(payload) { // make sure events do not have any prev document values // because NoPrevDocCollection does not have shouldIncludePrevDocument set diff --git a/testing/lib/sync_utils.js b/testing/lib/sync_utils.js index c7dee4ca..bde6f559 100644 --- a/testing/lib/sync_utils.js +++ b/testing/lib/sync_utils.js @@ -11,7 +11,7 @@ const callWithPromise = (method, ...args) => { Meteor.callWithPromise = callWithPromise; const waitForHandleToBeReady = handle => { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { Tracker.autorun(c => { if (handle.ready()) { c.stop(); diff --git a/testing/main.client.js b/testing/main.client.js index cbab9d3f..8d66f317 100644 --- a/testing/main.client.js +++ b/testing/main.client.js @@ -33,7 +33,7 @@ _.each(Collections, (Collection, key) => { } = helperGenerator(config[key].suffix); describe('It should work with: ' + key, function() { - it('Should detect a removal', async function(done) { + it('Should detect a removal', function(done) { let handle = subscribe( { game: 'chess', @@ -62,12 +62,14 @@ _.each(Collections, (Collection, key) => { }, }); - await waitForHandleToBeReady(handle); - - _id = await createSync({ game: 'chess', title: randomTitle }); + waitForHandleToBeReady(handle).then(function() { + createSync({ game: 'chess', title: randomTitle }).then(function(id) { + _id = id; + }); + }); }); - it('Should detect an insert', async function(done) { + it('Should detect an insert', function(done) { let handle = subscribe( { game: 'chess', @@ -92,18 +94,19 @@ _.each(Collections, (Collection, key) => { }, }); - await waitForHandleToBeReady(handle); - let data = cursor.fetch(); + waitForHandleToBeReady(handle).then(function() { + let data = cursor.fetch(); - assert.lengthOf(data, 3); + assert.lengthOf(data, 3); - create({ - game: 'chess', - title: 'E', + create({ + game: 'chess', + title: 'E', + }); }); }); - it('Should detect an update simple', async function(done) { + it('Should detect an update simple', function(done) { let handle = subscribe( { game: 'chess', @@ -124,22 +127,22 @@ _.each(Collections, (Collection, key) => { }, }); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + let data = cursor.fetch(); - let data = cursor.fetch(); - - update( - { _id: data[0]._id }, - { - $set: { - score: Math.random(), - }, - } - ); + update( + { _id: data[0]._id }, + { + $set: { + score: Math.random(), + }, + } + ); + }); }); - it('Should detect an update deeply nested', async function(done) { - let docId = await createSync({ + it('Should detect an update deeply nested', function(done) { + createSync({ game: 'chess', nested: { a: 1, @@ -148,143 +151,143 @@ _.each(Collections, (Collection, key) => { a: 1, }, }, - }); + }).then(function(docId) { + let handle = subscribe({ _id: docId }); + const cursor = Collection.find({ _id: docId }); - let handle = subscribe({ _id: docId }); - const cursor = Collection.find({ _id: docId }); + const observeChangesHandle = cursor.observeChanges({ + changed(docId, doc) { + observeChangesHandle.stop(); + handle.stop(); - const observeChangesHandle = cursor.observeChanges({ - changed(docId, doc) { - observeChangesHandle.stop(); - handle.stop(); + assert.equal(doc.nested.b, 2); + assert.equal(doc.nested.a, 1); + assert.equal(doc.nested.c.b, 1); + assert.equal(doc.nested.c.a, 1); + assert.equal(doc.nested.d, 1); + assert.lengthOf(_.keys(doc), 1); + assert.lengthOf(_.keys(doc.nested), 4); - assert.equal(doc.nested.b, 2); - assert.equal(doc.nested.a, 1); - assert.equal(doc.nested.c.b, 1); - assert.equal(doc.nested.c.a, 1); - assert.equal(doc.nested.d, 1); - assert.lengthOf(_.keys(doc), 1); - assert.lengthOf(_.keys(doc.nested), 4); + remove({ _id: docId }, () => { + done(); + }); + }, + }); - remove({ _id: docId }, () => { - done(); - }); - }, + waitForHandleToBeReady(handle).then(function() { + update( + { _id: docId }, + { + $set: { + 'nested.c.b': 1, + 'nested.b': 2, + 'nested.d': 1, + }, + } + ); + }); }); - - await waitForHandleToBeReady(handle); - - update( - { _id: docId }, - { - $set: { - 'nested.c.b': 1, - 'nested.b': 2, - 'nested.d': 1, - }, - } - ); }); - it('Should not update multiple documents if not specified (multi:true)', async function(done) { + it('Should not update multiple documents if not specified (multi:true)', function(done) { const context = Random.id(); - [_id1, _id2] = await createSync([ + createSync([ { context, game: 'monopoly', title: 'test' }, { context, game: 'monopoly', title: 'test2' }, - ]); - - let handle = subscribe({ game: 'monopoly' }); - await waitForHandleToBeReady(handle); - - const cursor = Collection.find({ _id: { $in: [_id1, _id2] } }); + ]).then(function([_id1, _id2]) { + let handle = subscribe({ game: 'monopoly' }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ _id: { $in: [_id1, _id2] } }); + + const observeChangesHandle = cursor.observeChanges({ + changed(docId) { + assert.equal(docId, _id1); + observeChangesHandle.stop(); + handle.stop(); + done(); - const observeChangesHandle = cursor.observeChanges({ - changed(docId) { - assert.equal(docId, _id1); - observeChangesHandle.stop(); - handle.stop(); - done(); + remove({ context, game: 'monopoly' }); + }, + }); - remove({ context, game: 'monopoly' }); - }, + update( + { context, game: 'monopoly' }, + { $set: { score: Math.random() } } + ); + }); }); - - update( - { context, game: 'monopoly' }, - { $set: { score: Math.random() } } - ); }); - it('Should update multiple documents if specified', async function(done) { + it('Should update multiple documents if specified', function(done) { const context = 'multi-update'; - [_id1, id2] = await createSync([ + createSync([ { context, title: 'test' }, { context, title: 'test2' }, - ]); - - let handle = subscribe({ context }); - await waitForHandleToBeReady(handle); - - const cursor = Collection.find({ context }); - - let changes = 0; - const observeChangesHandle = cursor.observeChanges({ - changed(docId) { - changes += 1; + ]).then(function([_id1, _id2]) { + let handle = subscribe({ context }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); + + let changes = 0; + const observeChangesHandle = cursor.observeChanges({ + changed(docId) { + changes += 1; + + if (changes === 2) { + observeChangesHandle.stop(); + handle.stop(); + done(); + } + }, + }); - if (changes === 2) { - observeChangesHandle.stop(); - handle.stop(); - done(); - } - }, + update( + { context }, + { + $set: { score: Math.random() }, + }, + { multi: true } + ); + }); }); - - update( - { context }, - { - $set: { score: Math.random() }, - }, - { multi: true } - ); }); - it('Should detect an update of a non published document', async function(done) { - let _id = await createSync({ + it('Should detect an update of a non published document', function(done) { + let _id = createSync({ game: 'backgammon', title: 'test', - }); + }).then(function(_id){ + let handle = subscribe({ + game: 'chess', + }); - let handle = subscribe({ - game: 'chess', - }); + const score = Math.random(); + const cursor = Collection.find(); - const score = Math.random(); - const cursor = Collection.find(); + const observeChangesHandle = cursor.observeChanges({ + added(docId, doc) { + if (docId !== _id) return; - const observeChangesHandle = cursor.observeChanges({ - added(docId, doc) { - if (docId !== _id) return; + assert.equal(doc.game, 'chess'); + assert.equal(doc.score, score); + assert.equal(doc.title, 'test'); - assert.equal(doc.game, 'chess'); - assert.equal(doc.score, score); - assert.equal(doc.title, 'test'); + observeChangesHandle.stop(); + handle.stop(); + remove({ _id }, () => { + done(); + }); + }, + }); - observeChangesHandle.stop(); - handle.stop(); - remove({ _id }, () => { - done(); - }); - }, + waitForHandleToBeReady(handle).then(function() { + update({ _id }, { $set: { game: 'chess', score } }); + }); }); - - await waitForHandleToBeReady(handle); - - update({ _id }, { $set: { game: 'chess', score } }); }); - it('Should detect an update of a nested field when fields is specified', async function(done) { - let _id = await createSync({ + it('Should detect an update of a nested field when fields is specified', function(done) { + createSync({ roles: { _groups: ['company1', 'company2', 'company3'], _main: 'company1', @@ -292,34 +295,35 @@ _.each(Collections, (Collection, key) => { roles: ['manage-users', 'manage-profiles'], }, }, - }); + }).then(function(_id) { + let handle = subscribe( + {}, + { + fields: { roles: 1 }, + } + ); - let handle = subscribe( - {}, - { - fields: { roles: 1 }, - } - ); + const cursor = Collection.find(); + const observeChangesHandle = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id); + handle.stop(); + observeChangesHandle.stop(); + done(); + remove({ _id }); + }, + }); - const cursor = Collection.find(); - const observeChangesHandle = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id); - handle.stop(); - observeChangesHandle.stop(); - done(); - remove({ _id }); - }, + waitForHandleToBeReady(handle).then(function() { + update({ _id }, { $set: { 'roles._main': 'company2' } }); + }); }); - - await waitForHandleToBeReady(handle); - update({ _id }, { $set: { 'roles._main': 'company2' } }); }); - it('Should update properly a nested field when a positional parameter is used', async function(done) { + it('Should update properly a nested field when a positional parameter is used', function(done) { const context = 'positional-paramter'; - let _id = await createSync({ + createSync({ context, bom: [ { @@ -335,607 +339,610 @@ _.each(Collections, (Collection, key) => { quantity: 3, }, ], - }); + }).then(function(_id) { + let handle = subscribe( + { context }, + { + fields: { + context: 1, + bom: 1, + }, + } + ); - let handle = subscribe( - { context }, - { - fields: { - context: 1, - bom: 1, + const cursor = Collection.find({ context }); + const observeChangesHandle = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id); + doc.bom.forEach(element => { + assert.isTrue(_.keys(element).length === 2); + if (element.stockId === 1) { + assert.equal(element.quantity, 30); + } else { + assert.equal(element.quantity, element.stockId); + } + }); + handle.stop(); + observeChangesHandle.stop(); + remove({ _id }); + done(); }, - } - ); + }); - const cursor = Collection.find({ context }); - const observeChangesHandle = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id); - doc.bom.forEach(element => { - assert.isTrue(_.keys(element).length === 2); - if (element.stockId === 1) { - assert.equal(element.quantity, 30); - } else { - assert.equal(element.quantity, element.stockId); - } - }); - handle.stop(); - observeChangesHandle.stop(); - remove({ _id }); - done(); - }, + waitForHandleToBeReady(handle).then(function() { + update( + { _id, 'bom.stockId': 1 }, + { + $set: { 'bom.$.quantity': 30 }, + } + ); + }); }); - - await waitForHandleToBeReady(handle); - - update( - { _id, 'bom.stockId': 1 }, - { - $set: { 'bom.$.quantity': 30 }, - } - ); }); ['server'].forEach(context => { - it('Should work with $and operators: ' + context, async function( - done - ) { - let _id = await createSync({ + it('Should work with $and operators: ' + context, function(done) { + createSync({ orgid: '1', siteIds: ['1', '2'], Year: 2017, - }); - - let handle = subscribe({ - $and: [ - { - orgid: '1', - }, - { - siteIds: { $in: ['1'] }, - }, - { - Year: { $in: [2017] }, - }, - ], - }); + }).then(function(_id) { + let handle = subscribe({ + $and: [ + { + orgid: '1', + }, + { + siteIds: { $in: ['1'] }, + }, + { + Year: { $in: [2017] }, + }, + ], + }); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find(); + let inChangedEvent = false; + const observeChangesHandle = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id); + inChangedEvent = true; + // assert.equal(doc.something, 30); + update({ _id }, { $set: { Year: 2018 } }); + }, + removed(docId) { + assert.isTrue(inChangedEvent); + assert.equal(docId, _id); - const cursor = Collection.find(); - let inChangedEvent = false; - const observeChangesHandle = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id); - inChangedEvent = true; - // assert.equal(doc.something, 30); - update({ _id }, { $set: { Year: 2018 } }); - }, - removed(docId) { - assert.isTrue(inChangedEvent); - assert.equal(docId, _id); + handle.stop(); + observeChangesHandle.stop(); + done(); + }, + }); - handle.stop(); - observeChangesHandle.stop(); - done(); - }, + update( + { _id }, + { + $set: { + something: 30, + }, + } + ); + }); }); - - update( - { _id }, - { - $set: { - something: 30, - }, - } - ); }); }); - it('Should be able to detect subsequent updates for direct processing with _ids', async function(done) { - let [_id1, _id2] = await createSync([ + it('Should be able to detect subsequent updates for direct processing with _ids', function(done) { + createSync([ { subsequent_test: true, name: 'John Smith' }, { subsequent_test: true, name: 'Michael Willow' }, - ]); - - let handle = subscribe( - { _id: { $in: [_id1, _id2] } }, - { - fields: { subsequent_test: 1, name: 1 }, - } - ); - - const cursor = Collection.find({ subsequent_test: true }); - let inFirst = false; + ]).then(function([_id1, _id2]) { + let handle = subscribe( + { _id: { $in: [_id1, _id2] } }, + { + fields: { subsequent_test: 1, name: 1 }, + } + ); - const observer = cursor.observeChanges({ - changed(docId, doc) { - if (docId == _id1) { - inFirst = true; - assert.equal('John Smithy', doc.name); - } - if (docId == _id2) { - assert.isTrue(inFirst); - assert.equal('Michael Willowy', doc.name); - handle.stop(); - observer.stop(); - done(); - } - }, - }); + const cursor = Collection.find({ subsequent_test: true }); + let inFirst = false; - await waitForHandleToBeReady(handle); + const observer = cursor.observeChanges({ + changed(docId, doc) { + if (docId == _id1) { + inFirst = true; + assert.equal('John Smithy', doc.name); + } + if (docId == _id2) { + assert.isTrue(inFirst); + assert.equal('Michael Willowy', doc.name); + handle.stop(); + observer.stop(); + done(); + } + }, + }); - await updateSync(_id1, { - $set: { name: 'John Smithy' }, - }); - await updateSync(_id2, { - $set: { name: 'Michael Willowy' }, + waitForHandleToBeReady(handle).then(function() { + updateSync(_id1, { + $set: { name: 'John Smithy' }, + }).then(function() { + updateSync(_id2, { + $set: { name: 'Michael Willowy' }, + }); + }); + }); }); }); - it('Should work with the $addToSet', async function(done) { - let _id = await createSync({ + it('Should work with the $addToSet', function(done) { + createSync({ operators: true, connections: [1, 2], number: 10, - }); - - let handle = subscribe({ _id }); - let cursor = Collection.find({ _id }); + }).then(function(_id) { + let handle = subscribe({ _id }); + let cursor = Collection.find({ _id }); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + const observer = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id); + assert.lengthOf(doc.connections, 3); - const observer = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id); - assert.lengthOf(doc.connections, 3); + observer.stop(); + handle.stop(); + done(); + }, + }); - observer.stop(); - handle.stop(); - done(); - }, + updateSync( + { _id }, + { + $addToSet: { + connections: 3, + }, + } + ); + }); }); - - await updateSync( - { _id }, - { - $addToSet: { - connections: 3, - }, - } - ); }); - it('Should work with the $pull', async function(done) { - let _id = await createSync({ + it('Should work with the $pull', function(done) { + createSync({ operators: true, connections: [1, 2], number: 10, - }); - - let handle = subscribe({ _id }); - let cursor = Collection.find({ _id }); + }).then(function(_id) { + let handle = subscribe({ _id }); + let cursor = Collection.find({ _id }); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + const observer = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id); + assert.lengthOf(doc.connections, 1); - const observer = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id); - assert.lengthOf(doc.connections, 1); + observer.stop(); + handle.stop(); + done(); + }, + }); - observer.stop(); - handle.stop(); - done(); - }, + updateSync( + { _id }, + { + $pull: { + connections: 2, + }, + } + ); + }); }); - - await updateSync( - { _id }, - { - $pull: { - connections: 2, - }, - } - ); }); - it('Should work with nested field updates', async function(done) { - let _id = await createSync({ + it('Should work with nested field updates', function(done) { + createSync({ profile: { language: 'EN', email: 'xxx@xxx.com', number: 5, }, - }); - - let handle = subscribe({ _id }); - let cursor = Collection.find({ _id }); + }).then(function(_id) { + let handle = subscribe({ _id }); + let cursor = Collection.find({ _id }); - await waitForHandleToBeReady(handle); - - const observer = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id); - assert.equal(doc.profile.number, 10); - const fullDoc = Collection.findOne(docId); - assert.equal(fullDoc.profile.language, 'EN'); - assert.equal(fullDoc.profile.email, 'xxx@xxx.com'); + waitForHandleToBeReady(handle).then(function() { + const observer = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id); + assert.equal(doc.profile.number, 10); + const fullDoc = Collection.findOne(docId); + assert.equal(fullDoc.profile.language, 'EN'); + assert.equal(fullDoc.profile.email, 'xxx@xxx.com'); - observer.stop(); - handle.stop(); - done(); - }, - }); + observer.stop(); + handle.stop(); + done(); + }, + }); - await updateSync(_id, { - $set: { - 'profile.number': 10, - }, + updateSync(_id, { + $set: { + 'profile.number': 10, + }, + }); + }); }); }); - it('Should work with the $pull and $set in combination', async function(done) { - let _id = await createSync({ + it('Should work with the $pull and $set in combination', function(done) { + createSync({ test_pull_and_set_combo: true, connections: [1], number: 10, - }); - - let handle = subscribe({ test_pull_and_set_combo: true }); - let cursor = Collection.find( - { - _id: { - $in: [_id], - }, - }, - { - fields: { - connections: 1, - number: 1, - }, - } - ); - - await waitForHandleToBeReady(handle); + }).then(function(_id) { + let handle = subscribe({ test_pull_and_set_combo: true }); + let cursor = Collection.find( + { + _id: { + $in: [_id], + }, + }, + { + fields: { + connections: 1, + number: 1, + }, + } + ); - const observer = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id); - assert.equal(doc.number, 20); - assert.lengthOf(doc.connections, 0); + waitForHandleToBeReady(handle).then(function() { + const observer = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id); + assert.equal(doc.number, 20); + assert.lengthOf(doc.connections, 0); - observer.stop(); - handle.stop(); - done(); - }, - }); + observer.stop(); + handle.stop(); + done(); + }, + }); - await updateSync(_id, { - $pull: { - connections: { $in: [1] }, - }, - $set: { - number: 20, - }, + updateSync(_id, { + $pull: { + connections: { $in: [1] }, + }, + $set: { + number: 20, + }, + }); + }); }); }); - it('Should work properly with limit-sort kind of queries', async function(done) { + it('Should work properly with limit-sort kind of queries', function(done) { const context = 'limit-sort-test'; const limit = 5; - await removeSync({ context }); + removeSync({ context }).then(function() { + createSync([ + { context, number: 5, text: 'T - 1' }, + { context, number: 10, text: 'T - 2' }, + { context, number: 15, text: 'T - 3' }, + { context, number: 20, text: 'T - 4' }, + { context, number: 25, text: 'T - 5' }, + { context, number: -1, text: 'T - Last one' }, + ]).then(function(ids) { + const [_id1, _id2, _id3, _id4, _id5, _id6] = ids; + + const handle = subscribe( + { + context, + }, + { + limit, + sort: { number: -1 }, + } + ); - const ids = await createSync([ - { context, number: 5, text: 'T - 1' }, - { context, number: 10, text: 'T - 2' }, - { context, number: 15, text: 'T - 3' }, - { context, number: 20, text: 'T - 4' }, - { context, number: 25, text: 'T - 5' }, - { context, number: -1, text: 'T - Last one' }, - ]); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); + let inChanged = false; + let initialAddBlast = true; + const observer = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id2); + assert.equal(doc.number, 30); + inChanged = true; + }, + removed(docId) { + if (docId === _id3) { + assert.equal(docId, _id3); + + // Now we will add it back! + updateSync( + { _id: _id3 }, + { + $set: { context }, + } + ); + } + }, + added(docId, doc) { + if (initialAddBlast) { + return; + } + + if (docId === _id6) { + // console.log('id6 has been added bc id3 has been removed.'); + } else { + // console.log('id3 should be added back'); + assert.equal(docId, _id3); + assert.isTrue(inChanged); + + observer.stop(); + handle.stop(); + done(); + } + } + }); - const [_id1, _id2, _id3, _id4, _id5, _id6] = ids; + initialAddBlast = false; + const data = cursor.fetch(); - const handle = subscribe( - { - context, - }, - { - limit, - sort: { number: -1 }, - } - ); + assert.lengthOf(data, limit); - await waitForHandleToBeReady(handle); + // We make sure that that the last element does not exist and is properly sorted. + assert.isTrue(data.find(el => el._id === _id6) === undefined); + // ids.forEach((_id, idx) => { + // assert.equal(data[limit - 1 - idx]._id, _id); + // }); - const cursor = Collection.find({ context }); - let inChanged = false; - let initialAddBlast = true; - const observer = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id2); - assert.equal(doc.number, 30); - inChanged = true; - }, - removed(docId) { - if (docId === _id3) { - assert.equal(docId, _id3); - - // Now we will add it back! updateSync( - { _id: _id3 }, - { - $set: { context }, - } + { _id: _id2 }, + { + $set: { number: 30 }, + } ); - } - }, - added(docId, doc) { - if (initialAddBlast) { - return; - } - - if (docId === _id6) { - // console.log('id6 has been added bc id3 has been removed.'); - } else { - // console.log('id3 should be added back'); - assert.equal(docId, _id3); - assert.isTrue(inChanged); - - observer.stop(); - handle.stop(); - done(); - } - } + updateSync( + { _id: _id3 }, + { + $set: { context: 'limit-sort-test-invalidate' }, + } + ); + }); + }); }); - - initialAddBlast = false; - const data = cursor.fetch(); - - assert.lengthOf(data, limit); - - // We make sure that that the last element does not exist and is properly sorted. - assert.isTrue(data.find(el => el._id === _id6) === undefined); - // ids.forEach((_id, idx) => { - // assert.equal(data[limit - 1 - idx]._id, _id); - // }); - - updateSync( - { _id: _id2 }, - { - $set: { number: 30 }, - } - ); - updateSync( - { _id: _id3 }, - { - $set: { context: 'limit-sort-test-invalidate' }, - } - ); }); - it('Should work with _ids direct processing and other filters present', async function(done) { + it('Should work with _ids direct processing and other filters present', function(done) { const context = 'ids-process-test'; - const ids = await createSync([ + createSync([ { context, meta: { student: false } }, { context, meta: { student: true } }, { context, meta: { student: true } }, - ]); - - const handle = subscribe({ - _id: { $in: ids }, - 'meta.student': true, - }); + ]).then(function(ids) { + const handle = subscribe({ + _id: { $in: ids }, + 'meta.student': true, + }); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + let cursor = Collection.find({ context }); + const data = cursor.fetch(); - let cursor = Collection.find({ context }); - const data = cursor.fetch(); + assert.lengthOf(data, 2); - assert.lengthOf(data, 2); + const observer = cursor.observeChanges({ + removed(docId) { + assert.equal(docId, ids[0]); - const observer = cursor.observeChanges({ - removed(docId) { - assert.equal(docId, ids[0]); - - observer.stop(); - handle.stop(); - done(); - }, - added(docId, doc) { - if (docId == ids[0]) { - assert.equal(docId, ids[0]); - update(ids[0], { - $set: { 'meta.changing': true }, - }); - } - }, - changed(docId, doc) { - if (docId == ids[0]) { - update(ids[0], { - $set: { 'meta.student': false }, - }); - } - }, - }); + observer.stop(); + handle.stop(); + done(); + }, + added(docId, doc) { + if (docId == ids[0]) { + assert.equal(docId, ids[0]); + update(ids[0], { + $set: { 'meta.changing': true }, + }); + } + }, + changed(docId, doc) { + if (docId == ids[0]) { + update(ids[0], { + $set: { 'meta.student': false }, + }); + } + }, + }); - updateSync(ids[0], { - $set: { 'meta.student': true }, + updateSync(ids[0], { + $set: { 'meta.student': true }, + }); + }); }); }); - it('Should detect an insert with the default processor', async function(done) { + it('Should detect an insert with the default processor', function(done) { const context = 'insert-default-processing' + Random.id(); const handle = subscribe({ context }); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); - const cursor = Collection.find({ context }); + let observer; + observer = cursor.observeChanges({ + added(docId, doc) { + assert.equal(doc.context, context); + setTimeout(() => { + observer.stop(); + handle.stop(); + done(); + }, 50); + }, + }); - let observer; - observer = cursor.observeChanges({ - added(docId, doc) { - assert.equal(doc.context, context); - setTimeout(() => { - observer.stop(); - handle.stop(); - done(); - }, 50); - }, + create({ context }); }); - - create({ context }); }); - it('Should detect an update with string publication that should be id', async function(done) { + it('Should detect an update with string publication that should be id', function(done) { const context = 'string-filters'; - let _id = await createSync({ context }); - const handle = subscribe(_id); + createSync({ context }).then(function(_id) { + const handle = subscribe(_id); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); - const cursor = Collection.find({ context }); + const observer = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id); + assert.equal(doc.number, 10); + observer.stop(); + handle.stop(); + done(); + }, + }); - const observer = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id); - assert.equal(doc.number, 10); - observer.stop(); - handle.stop(); - done(); - }, + update(_id, { $set: { number: 10 } }); + }); }); - - update(_id, { $set: { number: 10 } }); }); - it('Should work with deep nest specified fields', async function(done) { + it('Should work with deep nest specified fields', function(done) { const context = 'edge-case-001'; - let _id = await createSync({ + createSync({ context, passengers: [], - }); - const handle = subscribe(_id, { - fields: { - context: 1, - 'passengers.name': 1, - }, - }); - - await waitForHandleToBeReady(handle); + }).then(function(_id) { + const handle = subscribe(_id, { + fields: { + context: 1, + 'passengers.name': 1, + }, + }); - const cursor = Collection.find({ context }); - const observer = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id); - assert.lengthOf(doc.passengers, 1); - observer.stop(); - handle.stop(); - done(); - }, - }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); + const observer = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id); + assert.lengthOf(doc.passengers, 1); + observer.stop(); + handle.stop(); + done(); + }, + }); - update(_id, { - $addToSet: { - passengers: { - _id: 'y2MECXDgr9ggiP5D4', - name: 'Marlee Nielsen', - phone: '', - }, - }, + update(_id, { + $addToSet: { + passengers: { + _id: 'y2MECXDgr9ggiP5D4', + name: 'Marlee Nielsen', + phone: '', + }, + }, + }); + }); }); }); - it('Should work with upsert', async function(done) { + it('Should work with upsert', function(done) { const context = 'upsertion' + Random.id(); const handle = subscribe({ context }); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); + const observer = cursor.observeChanges({ + added(docId, doc) { + assert.equal(doc.number, 10); + upsert( + { context }, + { + $set: { + number: 20, + }, + } + ); + }, + changed(docId, doc) { + assert.equal(doc.number, 20); + observer.stop(); + handle.stop(); + done(); + }, + }); - const cursor = Collection.find({ context }); - const observer = cursor.observeChanges({ - added(docId, doc) { - assert.equal(doc.number, 10); - upsert( - { context }, - { - $set: { - number: 20, - }, - } - ); - }, - changed(docId, doc) { - assert.equal(doc.number, 20); - observer.stop(); - handle.stop(); - done(); - }, + upsert( + { context }, + { + context, + number: 10, + } + ); }); - - upsert( - { context }, - { - context, - number: 10, - } - ); }); - it('Should not detect a change if pushToRedis is false', async function(done) { + it('Should not detect a change if pushToRedis is false', function(done) { const context = 'pushToRedis:false'; const handle = subscribe({ context }); - await waitForHandleToBeReady(handle); - - const cursor = Collection.find({ context }); - let _id; - const observer = cursor.observeChanges({ - added(docId, doc) { - if (docId === _id) { - done('Should not be in added'); - } - }, - changed(docId, doc) { - if (docId === _id) { - done('Should not be in changed'); - } - }, - removed(docId) { - if (docId === _id) { - done('Should not be in changed'); - } - }, - }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); + let _id; + const observer = cursor.observeChanges({ + added(docId, doc) { + if (docId === _id) { + done('Should not be in added'); + } + }, + changed(docId, doc) { + if (docId === _id) { + done('Should not be in changed'); + } + }, + removed(docId) { + if (docId === _id) { + done('Should not be in changed'); + } + }, + }); - _id = await createSync( - { - context, - }, - { pushToRedis: false } - ); + createSync( + { + context, + }, + { pushToRedis: false } + ).then(function(id) { + _id = id; - update( - { _id }, - { - $set: { number: 10 }, - }, - { pushToRedis: false }, - (err, res) => { - remove({ _id }, { pushToRedis: false }); - } - ); + update( + { _id }, + { + $set: { number: 10 }, + }, + { pushToRedis: false }, + (err, res) => { + remove({ _id }, { pushToRedis: false }); + } + ); - setTimeout(() => { - observer.stop(); - handle.stop(); - done(); - }, 200); + setTimeout(() => { + observer.stop(); + handle.stop(); + done(); + }, 200); + }); + }); }); - it('Should work correctly when disallowed fields are specified', async function(done) { + it('Should work correctly when disallowed fields are specified', function(done) { const context = 'disallowed-fields-' + Random.id(); const handle = subscribe( { context }, @@ -948,65 +955,67 @@ _.each(Collections, (Collection, key) => { } ); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); - const cursor = Collection.find({ context }); + let _id; + const observer = cursor.observeChanges({ + added(docId, doc) { + if (doc.context !== context) return; - let _id; - const observer = cursor.observeChanges({ - added(docId, doc) { - if (doc.context !== context) return; + assert.equal(doc.other, 'Public'); + assert.isUndefined(doc.profile); + assert.isObject(doc.address); + assert.isString(doc.address.country); + assert.isUndefined(doc.address.city); + assert.isUndefined(doc.fullname); - assert.equal(doc.other, 'Public'); - assert.isUndefined(doc.profile); - assert.isObject(doc.address); - assert.isString(doc.address.country); - assert.isUndefined(doc.address.city); - assert.isUndefined(doc.fullname); + update( + { _id: docId }, + { + $set: { + 'address.country': 'Testing', + fullname: 'Testing', + other: 'Publico', + newField: 'public', + 'profile.firstName': 'John', + }, + } + ); + }, + changed(docId, doc) { + assert.equal(doc.other, 'Publico'); + assert.isUndefined(doc.profile); + assert.isObject(doc.address); + assert.equal(doc.address.country, 'Testing'); + assert.equal(doc.newField, 'public'); + assert.isUndefined(doc.address.city); + assert.isUndefined(doc.fullname); - update( - { _id: docId }, - { - $set: { - 'address.country': 'Testing', - fullname: 'Testing', - other: 'Publico', - newField: 'public', - 'profile.firstName': 'John', - }, - } - ); - }, - changed(docId, doc) { - assert.equal(doc.other, 'Publico'); - assert.isUndefined(doc.profile); - assert.isObject(doc.address); - assert.equal(doc.address.country, 'Testing'); - assert.equal(doc.newField, 'public'); - assert.isUndefined(doc.address.city); - assert.isUndefined(doc.fullname); - - observer.stop(); - handle.stop(); - done(); - }, - }); + observer.stop(); + handle.stop(); + done(); + }, + }); - _id = await createSync({ - context, - profile: { - name: 'Secret', - }, - address: { - country: 'Country', - city: 'Secret', - }, - fullname: 'Secret', - other: 'Public', + createSync({ + context, + profile: { + name: 'Secret', + }, + address: { + country: 'Country', + city: 'Secret', + }, + fullname: 'Secret', + other: 'Public', + }).then(function(id) { + _id = id; + }); }); }); - it('Should work correctly with the allowed fields only specified', async function(done) { + it('Should work correctly with the allowed fields only specified', function(done) { const context = 'allowed-fields'; const handle = subscribe( { context }, @@ -1020,59 +1029,59 @@ _.each(Collections, (Collection, key) => { } ); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); + const observer = cursor.observeChanges({ + added(docId, doc) { + assert.isUndefined(doc.other); + assert.isObject(doc.profile); + assert.isObject(doc.address); + assert.isString(doc.address.city); + assert.isUndefined(doc.address.country); + assert.isString(doc.fullname); - const cursor = Collection.find({ context }); - const observer = cursor.observeChanges({ - added(docId, doc) { - assert.isUndefined(doc.other); - assert.isObject(doc.profile); - assert.isObject(doc.address); - assert.isString(doc.address.city); - assert.isUndefined(doc.address.country); - assert.isString(doc.fullname); + update( + { _id: docId }, + { + $set: { + 'address.country': 'Testing', + fullname: 'Testing', + other: 'secret', + newField: 'secret', + 'profile.firstName': 'John', + }, + } + ); + }, + changed(docId, doc) { + assert.isUndefined(doc.other); + assert.isObject(doc.profile); + assert.equal(doc.profile.firstName, 'John'); + assert.isUndefined(doc.newField); + assert.equal(doc.fullname, 'Testing'); - update( - { _id: docId }, - { - $set: { - 'address.country': 'Testing', - fullname: 'Testing', - other: 'secret', - newField: 'secret', - 'profile.firstName': 'John', - }, - } - ); - }, - changed(docId, doc) { - assert.isUndefined(doc.other); - assert.isObject(doc.profile); - assert.equal(doc.profile.firstName, 'John'); - assert.isUndefined(doc.newField); - assert.equal(doc.fullname, 'Testing'); - - observer.stop(); - handle.stop(); - done(); - }, - }); + observer.stop(); + handle.stop(); + done(); + }, + }); - let _id = await createSync({ - context, - profile: { - name: 'Public', - }, - address: { - country: 'Country', - city: 'Public', - }, - fullname: 'Public', - other: 'Secret', + createSync({ + context, + profile: { + name: 'Public', + }, + address: { + country: 'Country', + city: 'Public', + }, + fullname: 'Public', + other: 'Secret', + }); }); }); - it('Should work with limit-sort when only _id is specified', async function(done) { + it('Should work with limit-sort when only _id is specified', function(done) { const context = Random.id(); const handle = subscribe( { context }, @@ -1086,76 +1095,76 @@ _.each(Collections, (Collection, key) => { } ); - await waitForHandleToBeReady(handle); - - const cursor = Collection.find({ context }); - const observer = cursor.observeChanges({ - added(docId, doc) { - assert.isUndefined(doc.something); - assert.isTrue(_.keys(doc).length == 1); - update( - { _id: docId }, - { - $set: { - something: false, - }, - } - ); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); + const observer = cursor.observeChanges({ + added(docId, doc) { + assert.isUndefined(doc.something); + assert.isTrue(_.keys(doc).length == 1); + update( + { _id: docId }, + { + $set: { + something: false, + }, + } + ); - done(); - }, - changed(docId, doc) { - done( - 'Should not be in changed event because nothing changed' - ); - }, - }); + done(); + }, + changed(docId, doc) { + done( + 'Should not be in changed event because nothing changed' + ); + }, + }); - create({ - context, - something: true, + create({ + context, + something: true, + }); }); }); - it('Should work properly with $unset', async function(done) { + it('Should work properly with $unset', function(done) { const context = 'test-$unset'; const handle = subscribe({ context }); - await waitForHandleToBeReady(handle); - - const cursor = Collection.find({ context }); - const observer = cursor.observeChanges({ - added(docId, doc) { - assert.isTrue(doc.something); - - setTimeout(() => { - update( - { _id: docId }, - { - $unset: { - something: '', - }, - } - ); - }, 50); - }, - changed(docId, doc) { - assert.isTrue('something' in doc); - assert.isUndefined(doc.something); - remove({ _id: docId }); - observer.stop(); - handle.stop(); - done(); - }, - }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); + const observer = cursor.observeChanges({ + added(docId, doc) { + assert.isTrue(doc.something); + + setTimeout(() => { + update( + { _id: docId }, + { + $unset: { + something: '', + }, + } + ); + }, 50); + }, + changed(docId, doc) { + assert.isTrue('something' in doc); + assert.isUndefined(doc.something); + remove({ _id: docId }); + observer.stop(); + handle.stop(); + done(); + }, + }); - create({ - context, - something: true, + create({ + context, + something: true, + }); }); }); - it('Should work when updating deep array when it is specified as a field', async function(done) { + it('Should work when updating deep array when it is specified as a field', function(done) { const context = `deep-array-objects-${Random.id()}`; let handle = subscribe( @@ -1168,51 +1177,51 @@ _.each(Collections, (Collection, key) => { } ); - await waitForHandleToBeReady(handle); - - const cursor = Collection.find({ context }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); - const observer = cursor.observeChanges({ - added(docId, doc) { - assert.isArray(doc.deep.deep.array); - assert.lengthOf(doc.deep.deep.array, 6); - update( - { - _id: docId, - 'deep.deep.array': 6, - }, - { - $set: { - 'deep.deep.array.$': 20, - }, - } - ); - }, - changed(docId, doc) { - assert.isArray(doc.deep.deep.array); - assert.lengthOf(doc.deep.deep.array, 6); - doc.deep.deep.array.forEach(number => { - assert.isNumber(number); - }); - assert.isTrue(_.contains(doc.deep.deep.array, 20)); + const observer = cursor.observeChanges({ + added(docId, doc) { + assert.isArray(doc.deep.deep.array); + assert.lengthOf(doc.deep.deep.array, 6); + update( + { + _id: docId, + 'deep.deep.array': 6, + }, + { + $set: { + 'deep.deep.array.$': 20, + }, + } + ); + }, + changed(docId, doc) { + assert.isArray(doc.deep.deep.array); + assert.lengthOf(doc.deep.deep.array, 6); + doc.deep.deep.array.forEach(number => { + assert.isNumber(number); + }); + assert.isTrue(_.contains(doc.deep.deep.array, 20)); - observer.stop(); - handle.stop(); - done(); - }, - }); + observer.stop(); + handle.stop(); + done(); + }, + }); - create({ - context, - deep: { + create({ + context, deep: { - array: [1, 2, 3, 4, 5, 6], + deep: { + array: [1, 2, 3, 4, 5, 6], + }, }, - }, + }); }); }); - it('Should work when updating a specific element in an array', async function(done) { + it('Should work when updating a specific element in an array', function(done) { const context = 'update-specific-in-arrays'; let handle = subscribe( @@ -1225,48 +1234,49 @@ _.each(Collections, (Collection, key) => { } ); - await waitForHandleToBeReady(handle); - const cursor = Collection.find({ context }); - - const observer = cursor.observeChanges({ - added(docId, doc) { - update( - { _id: docId }, - { - $set: { - 'passengers.1.phone': 'ZZZ', - }, - } - ); - }, - changed(docId, doc) { - doc.passengers.forEach(passenger => { - if (passenger.previous === 'YYY') { - assert.equal(passenger.phone, 'ZZZ'); - observer.stop(); - handle.stop(); - done(); - } - }); - }, - }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ context }); - create({ - context, - passengers: [ - { - previous: 'XXX', - phone: 'XXX', + const observer = cursor.observeChanges({ + added(docId, doc) { + update( + { _id: docId }, + { + $set: { + 'passengers.1.phone': 'ZZZ', + }, + } + ); }, - { - previous: 'YYY', - phone: 'YYY', + changed(docId, doc) { + doc.passengers.forEach(passenger => { + if (passenger.previous === 'YYY') { + assert.equal(passenger.phone, 'ZZZ'); + observer.stop(); + handle.stop(); + done(); + } + }); }, - ], + }); + + create({ + context, + passengers: [ + { + previous: 'XXX', + phone: 'XXX', + }, + { + previous: 'YYY', + phone: 'YYY', + }, + ], + }); }); }); - it('Should work with $elemMatch query selector', async function(done) { + it('Should work with $elemMatch query selector', function(done) { const context = 'work-with-elemMatch-' + Random.id(); let handle = subscribe({ @@ -1278,113 +1288,115 @@ _.each(Collections, (Collection, key) => { }, }); - await waitForHandleToBeReady(handle); - const cursor = Collection.find({ - context, - }); - - const observer = cursor.observeChanges({ - added(docId, doc) { - assert.isArray(doc.emails); - assert.equal('x@x.com', doc.emails[0].address); - handle.stop(); - observer.stop(); - done(); - }, - }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ + context, + }); - create({ - context, - emails: [ - { - address: 'x@x.com', + const observer = cursor.observeChanges({ + added(docId, doc) { + assert.isArray(doc.emails); + assert.equal('x@x.com', doc.emails[0].address); + handle.stop(); + observer.stop(); + done(); }, - ], + }); + + create({ + context, + emails: [ + { + address: 'x@x.com', + }, + ], + }); }); }); - it('Should detect 3rd level nesting changes', async function(done) { + it('Should detect 3rd level nesting changes', function(done) { const context = 'deep-level-nesting-' + Random.id(); let handle = subscribe({ context, }); - await waitForHandleToBeReady(handle); - const cursor = Collection.find({ - context, - }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ + context, + }); - const observer = cursor.observeChanges({ - added(docId, doc) { - update(docId, { - $set: { - 'item.profile.name': 'Elena Smith', - }, - }); - }, - changed(docId, doc) { - assert.isObject(doc.item); - assert.equal('Elena Smith', doc.item.profile.name); - done(); - }, - }); + const observer = cursor.observeChanges({ + added(docId, doc) { + update(docId, { + $set: { + 'item.profile.name': 'Elena Smith', + }, + }); + }, + changed(docId, doc) { + assert.isObject(doc.item); + assert.equal('Elena Smith', doc.item.profile.name); + done(); + }, + }); - create({ - context, - item: { - profile: { - name: 'John Smith', + create({ + context, + item: { + profile: { + name: 'John Smith', + }, }, - }, + }); }); }); - it('Should work with a filter on a subfield and a top field specified', async function(done) { - _id = await createSync({ + it('Should work with a filter on a subfield and a top field specified', function(done) { + createSync({ master: { sub: 'TEST', sub2: 1, sub3: 1, }, - }); - - let handle = subscribe( - { - _id, - 'master.sub': 'TEST', - }, - { - fields: { - master: 1, - }, - } - ); - - await waitForHandleToBeReady(handle); + }).then(function(_id) { + let handle = subscribe( + { + _id, + 'master.sub': 'TEST', + }, + { + fields: { + master: 1, + }, + } + ); - const cursor = Collection.find({ _id }); - const document = Collection.findOne({ _id }); - assert.isObject(document.master); - assert.equal(document.master.sub, 'TEST'); - assert.equal(document.master.sub2, 1); - assert.equal(document.master.sub3, 1); + waitForHandleToBeReady(handle).then(function() { + const cursor = Collection.find({ _id }); + const document = Collection.findOne({ _id }); + assert.isObject(document.master); + assert.equal(document.master.sub, 'TEST'); + assert.equal(document.master.sub2, 1); + assert.equal(document.master.sub3, 1); + + let observeChangesHandle = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(doc.master.sub2, 2); + handle.stop(); + observeChangesHandle.stop(); + done(); + }, + }); - let observeChangesHandle = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(doc.master.sub2, 2); - handle.stop(); - observeChangesHandle.stop(); - done(); - }, + update( + { _id }, + { + $set: { 'master.sub2': 2 }, + } + ); + }); }); - - update( - { _id }, - { - $set: { 'master.sub2': 2 }, - } - ); }); }); }); diff --git a/testing/object-id/client.js b/testing/object-id/client.js index 629cc169..dd987ffc 100644 --- a/testing/object-id/client.js +++ b/testing/object-id/client.js @@ -3,21 +3,21 @@ import { SmartIds } from './collections'; import { Meteor } from 'meteor/meteor'; describe('ObjectId', function() { - it('Should work!', async function(done) { - const [id1, id2] = await Meteor.callWithPromise('smart_ids_reset'); - - const handle = Meteor.subscribe( + it('Should work!', function(done) { + Meteor.callWithPromise('smart_ids_reset').then(function([id1, id2]) { + const handle = Meteor.subscribe( 'smart_ids', { - _id: id1 + _id: id1 }, function() { - const result = SmartIds.findOne(); + const result = SmartIds.findOne(); - assert.isObject(result); - assert.isObject(result._id); - done(); + assert.isObject(result); + assert.isObject(result._id); + done(); } - ); + ); + }); }); }); diff --git a/testing/optimistic-ui/client.test.js b/testing/optimistic-ui/client.test.js index 92e64dad..39943cbd 100644 --- a/testing/optimistic-ui/client.test.js +++ b/testing/optimistic-ui/client.test.js @@ -6,49 +6,49 @@ import { Random } from 'meteor/random'; import './boot'; describe('Optimistic UI', () => { - it('Should not cause a flicker with method calls', async function(done) { + it('Should not cause a flicker with method calls', function(done) { const context = Random.id(); - const itemId = await callWithPromise('optimistic_ui.items.insert', { + callWithPromise('optimistic_ui.items.insert', { context, liked: ['ZZZ'], - }); - - const handle = Meteor.subscribe('optimistic_ui.items', { _id: itemId }); - await waitForHandleToBeReady(handle); - - const cursor = Items.find({ _id: itemId }); - - let alreadyIn = 0; - const observer = cursor.observeChanges({ - changed(docId, doc) { + }).then(function(itemId) { + const handle = Meteor.subscribe('optimistic_ui.items', { _id: itemId }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Items.find({ _id: itemId }); + + let alreadyIn = 0; + const observer = cursor.observeChanges({ + changed(docId, doc) { alreadyIn++; if (alreadyIn > 1) { - done('A flicker was caused.'); + done('A flicker was caused.'); } assert.lengthOf(doc.liked, 2); assert.isTrue(_.contains(doc.liked, 'XXX')); setTimeout(() => { - handle.stop(); - observer.stop(); - done(); + handle.stop(); + observer.stop(); + done(); }, 200); - }, - }); + }, + }); - const item = _.first(cursor.fetch()); - assert.isObject(item); + const item = _.first(cursor.fetch()); + assert.isObject(item); - Meteor.call('optimistic_ui.items.update', item._id, { - $addToSet: { + Meteor.call('optimistic_ui.items.update', item._id, { + $addToSet: { liked: 'XXX', - }, + }, + }); + }); }); }); - it('Should not cause a flicker with isomorphic calls', async function(done) { + it('Should not cause a flicker with isomorphic calls', function(done) { const context = Random.id(); const itemId = Items.insert({ @@ -57,36 +57,36 @@ describe('Optimistic UI', () => { }); const handle = Meteor.subscribe('optimistic_ui.items', { _id: itemId }); - await waitForHandleToBeReady(handle); - - const cursor = Items.find({ _id: itemId }); + waitForHandleToBeReady(handle).then(function() { + const cursor = Items.find({ _id: itemId }); - let alreadyIn = 0; - const observer = cursor.observeChanges({ + let alreadyIn = 0; + const observer = cursor.observeChanges({ changed(docId, doc) { - alreadyIn++; - if (alreadyIn > 1) { - done('A flicker was caused.'); - } - - assert.lengthOf(doc.liked, 2); - assert.isTrue(_.contains(doc.liked, 'XXX')); - - setTimeout(() => { - handle.stop(); - observer.stop(); - done(); - }, 200); + alreadyIn++; + if (alreadyIn > 1) { + done('A flicker was caused.'); + } + + assert.lengthOf(doc.liked, 2); + assert.isTrue(_.contains(doc.liked, 'XXX')); + + setTimeout(() => { + handle.stop(); + observer.stop(); + done(); + }, 200); }, - }); + }); - const item = _.first(cursor.fetch()); - assert.isObject(item); + const item = _.first(cursor.fetch()); + assert.isObject(item); - Items.update(item._id, { + Items.update(item._id, { $addToSet: { - liked: 'XXX', + liked: 'XXX', }, + }); }); }); }); diff --git a/testing/polling/client.js b/testing/polling/client.js index 805919b3..7c1aaff4 100644 --- a/testing/polling/client.js +++ b/testing/polling/client.js @@ -3,35 +3,35 @@ import { Campaigns } from './collections'; import { Meteor } from 'meteor/meteor'; describe('Polling', function() { - it('Should work!', async function(done) { - await Meteor.callWithPromise('campaign_search_reset'); + it('Should work!', function(done) { + Meteor.callWithPromise('campaign_search_reset').then(function() { + const pollingIntervalMs = 100; - const pollingIntervalMs = 100; - - const handle = Meteor.subscribe( + const handle = Meteor.subscribe( 'campaign_search', 'John', pollingIntervalMs, function() { - const results = Campaigns.find().fetch(); + const results = Campaigns.find().fetch(); - assert.lengthOf(results, 2); + assert.lengthOf(results, 2); - Meteor.call( - 'campaign_search_insert', - { - text: 'John Broman' - }, - function() { - setTimeout(() => { - const results = Campaigns.find().fetch(); - assert.lengthOf(results, 3); + Meteor.call( + 'campaign_search_insert', + { + text: 'John Broman' + }, + function() { + setTimeout(() => { + const results = Campaigns.find().fetch(); + assert.lengthOf(results, 3); - done(); - }, pollingIntervalMs + 100); - } - ); + done(); + }, pollingIntervalMs + 100); + } + ); } - ); + ); + }); }); }); diff --git a/testing/publishComposite/client.test.js b/testing/publishComposite/client.test.js index 8edac25d..d2a4f4fd 100644 --- a/testing/publishComposite/client.test.js +++ b/testing/publishComposite/client.test.js @@ -4,41 +4,41 @@ import {_} from 'meteor/underscore'; import {waitForHandleToBeReady, callWithPromise} from '../lib/sync_utils'; describe('Publish Composite', () => { - it('Should be able to detect updates on parent element', async function (done) { - await callWithPromise('publish_composite.load_fixtures'); - - const handle = Meteor.subscribe('items_publish_composite'); - await waitForHandleToBeReady(handle); - - const cursor = Items.find(); - - const observer = cursor.observeChanges({ - changed(docId, doc) { + it('Should be able to detect updates on parent element', function (done) { + callWithPromise('publish_composite.load_fixtures').then(function() { + const handle = Meteor.subscribe('items_publish_composite'); + waitForHandleToBeReady(handle).then(function() { + const cursor = Items.find(); + + const observer = cursor.observeChanges({ + changed(docId, doc) { assert.equal(doc.name, 'Other Name'); const firstChild = Children.find({itemId: docId}).fetch()[0]; Meteor.call('publish_composite.children.update', firstChild._id, { - $set: {name: 'Other Name'} + $set: {name: 'Other Name'} }); - } - }); + } + }); - const item = _.first(cursor.fetch()); - assert.isObject(item); + const item = _.first(cursor.fetch()); + assert.isObject(item); - const childCursor = Children.find({itemId: item._id}); - const childObserver = childCursor.observeChanges({ - changed(docId, doc) { + const childCursor = Children.find({itemId: item._id}); + const childObserver = childCursor.observeChanges({ + changed(docId, doc) { assert.equal(doc.name, 'Other Name'); done(); handle.stop(); observer.stop(); - } - }); + } + }); - await callWithPromise('publish_composite.items.update', item._id, { - $set: {name: 'Other Name'} + callWithPromise('publish_composite.items.update', item._id, { + $set: {name: 'Other Name'} + }); + }); }); }) -}); \ No newline at end of file +}); diff --git a/testing/synthetic_mutators.js b/testing/synthetic_mutators.js index 8dfa1200..002cb342 100644 --- a/testing/synthetic_mutators.js +++ b/testing/synthetic_mutators.js @@ -19,12 +19,12 @@ _.each(Collections, (Collection, key) => { } describe('It should work with synthetic mutators: ' + key, function() { - it('Should work with insert', async function(done) { + it('Should work with insert', function(done) { let handle = subscribe({ game: `synthetic.${config[key].suffix}`, }); - const cursor = Collection.find(); + const cursor = Collection.find({}); let observeChangesHandle = cursor.observeChanges({ added(docId, doc) { @@ -35,14 +35,14 @@ _.each(Collections, (Collection, key) => { }, }); - await waitForHandleToBeReady(handle); - - synthetic('insert', { - game: `synthetic.${config[key].suffix}`, + waitForHandleToBeReady(handle).then(function() { + synthetic('insert', { + game: `synthetic.${config[key].suffix}`, + }); }); }); - it('Should work with update with operators: $set', async function(done) { + it('Should work with update with operators: $set', function(done) { let handle = subscribe({ game: 'chess', }); @@ -58,49 +58,49 @@ _.each(Collections, (Collection, key) => { }, }); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + let _id = cursor.fetch()[0]._id; + assert.isString(_id); - let _id = cursor.fetch()[0]._id; - assert.isString(_id); - - synthetic('update', _id, { - $set: { - isPlaying: true, - }, + synthetic('update', _id, { + $set: { + isPlaying: true, + }, + }); }); }); - it('Should work with update with operators: $push', async function(done) { - let _id = await createSync({ + it('Should work with update with operators: $push', function(done) { + createSync({ synthetic_test: true, connections: [], - }); + }).then(function(_id) { + let handle = subscribe({ synthetic_test: true }); - let handle = subscribe({ synthetic_test: true }); + const cursor = Collection.find({ + synthetic_test: true, + }); - const cursor = Collection.find({ - synthetic_test: true, - }); + let observeChangesHandle = cursor.observeChanges({ + changed(docId, doc) { + assert.lengthOf(doc.connections, 1); + observeChangesHandle.stop(); + handle.stop(); + done(); + }, + }); - let observeChangesHandle = cursor.observeChanges({ - changed(docId, doc) { - assert.lengthOf(doc.connections, 1); - observeChangesHandle.stop(); - handle.stop(); - done(); - }, - }); - - await waitForHandleToBeReady(handle); - - synthetic('update', _id, { - $push: { - connections: 1, - }, + waitForHandleToBeReady(handle).then(function() { + synthetic('update', _id, { + $push: { + connections: 1, + }, + }); + }); }); }); - it('Should work with update', async function(done) { + it('Should work with update', function(done) { let handle = subscribe({ game: 'chess' }); const cursor = Collection.find(); @@ -114,19 +114,19 @@ _.each(Collections, (Collection, key) => { }, }); - await waitForHandleToBeReady(handle); - - let _id = cursor.fetch()[0]._id; - assert.isString(_id); + waitForHandleToBeReady(handle).then(function() { + let _id = cursor.fetch()[0]._id; + assert.isString(_id); - synthetic('update', _id, { - $set: { - isPlaying: true, - }, + synthetic('update', _id, { + $set: { + isPlaying: true, + }, + }); }); }); - it('Should work with remove', async function(done) { + it('Should work with remove', function(done) { let handle = subscribe({ game: 'chess', }); @@ -144,45 +144,46 @@ _.each(Collections, (Collection, key) => { }, }); - await waitForHandleToBeReady(handle); + waitForHandleToBeReady(handle).then(function() { + _id = cursor.fetch()[0]._id; + assert.isString(_id); - _id = cursor.fetch()[0]._id; - assert.isString(_id); - - synthetic('remove', _id); + synthetic('remove', _id); + }); }); - it('Should work with update with _id', async function(done) { + it('Should work with update with _id', function(done) { const context = 'synth-with-id'; - let _id = await createSync({ context }); - let handle = subscribe({ - _id: { $in: [_id] }, + createSync({ context }).then(function(_id) { + let handle = subscribe({ + _id: { $in: [_id] }, + }); + + const cursor = Collection.find(); + waitForHandleToBeReady(handle).then(function() { + let observer = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(docId, _id); + assert.equal(doc.isPlaying, true); + observer.stop(); + handle.stop(); + done(); + }, + }); + + synthetic( + 'update', + _id, + { + $set: { + isPlaying: true, + }, + }, + `${Collection._name}::${_id}` + ); + }); }); - - const cursor = Collection.find(); - await waitForHandleToBeReady(handle); - - let observer = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(docId, _id); - assert.equal(doc.isPlaying, true); - observer.stop(); - handle.stop(); - done(); - }, - }); - - synthetic( - 'update', - _id, - { - $set: { - isPlaying: true, - }, - }, - `${Collection._name}::${_id}` - ); }); }); }); diff --git a/testing/transformations/client.js b/testing/transformations/client.js index 2f741e69..abc87015 100644 --- a/testing/transformations/client.js +++ b/testing/transformations/client.js @@ -29,4 +29,4 @@ describe('Transformations', function () { }) }) }) -}); \ No newline at end of file +}); diff --git a/testing/vent/client.js b/testing/vent/client.js index c2e150f9..a776c6f1 100644 --- a/testing/vent/client.js +++ b/testing/vent/client.js @@ -4,7 +4,7 @@ import {Random} from 'meteor/random'; import {Vent} from 'meteor/cultofcoders:redis-oplog'; describe('Vent', function () { - it('Should receive the event accordingly', async function (done) { + it('Should receive the event accordingly', function (done) { const threadId = Random.id(); const channel = `threads::${threadId}::new_message`; @@ -25,7 +25,7 @@ describe('Vent', function () { }) }); - it('Should be able to work with 2 different listeners to the same endpoint', async function (done) { + it('Should be able to work with 2 different listeners to the same endpoint', function (done) { const threadId = Random.id(); const channel = `threads::${threadId}::new_message`; @@ -63,7 +63,7 @@ describe('Vent', function () { }); - it('Should handle event bombarding and not losing anything along the way', async function (done) { + it('Should handle event bombarding and not losing anything along the way', function (done) { const threadId = Random.id(); const channel = `threads::${threadId}::new_message`; @@ -88,7 +88,7 @@ describe('Vent', function () { }); - it('Should not receive the event if handler is stopped', async function (done) { + it('Should not receive the event if handler is stopped', function (done) { const threadId = Random.id(); const channel = `threads::${threadId}::new_message`; @@ -111,4 +111,4 @@ describe('Vent', function () { done(); }, 200); }); -}); \ No newline at end of file +}); From 31c72354a9be31a1e03021edb9a71d09b6b0f366 Mon Sep 17 00:00:00 2001 From: James Gibson Date: Tue, 27 Apr 2021 15:03:49 -0600 Subject: [PATCH 02/42] fix spacing --- testing/client_side_mutators.js | 98 ++--- testing/collection-defaults/client.js | 92 ++--- testing/collection_hooks.server.js | 10 +- testing/include_prev_doc.js | 74 ++-- testing/lib/sync_utils.js | 2 +- testing/main.client.js | 518 ++++++++++++------------ testing/object-id/client.js | 32 +- testing/optimistic-ui/client.test.js | 110 ++--- testing/polling/client.js | 52 +-- testing/publishComposite/client.test.js | 60 +-- testing/synthetic_mutators.js | 48 +-- testing/transformations/client.js | 4 +- testing/vent/client.js | 20 +- 13 files changed, 560 insertions(+), 560 deletions(-) diff --git a/testing/client_side_mutators.js b/testing/client_side_mutators.js index 2ea7f2f0..37bf10ea 100644 --- a/testing/client_side_mutators.js +++ b/testing/client_side_mutators.js @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import {Collections, config} from './boot'; +import { Collections, config } from './boot'; import helperGenerator from './lib/helpers'; const Collection = Collections['Standard']; @@ -16,61 +16,61 @@ describe('Client-side Mutators', function () { client_side_mutators: true }); - waitForHandleToBeReady(handle).then(function() { - const cursor = Collection.find({ client_side_mutators: true }); + waitForHandleToBeReady(handle).then(function () { + const cursor = Collection.find({ client_side_mutators: true }); - let testDocId, inChanged = false, inAdded = false, inRemoved = false; - const observer = cursor.observeChanges({ - added(docId, doc) { - if (inAdded) { - return; - } - inAdded = true; + let testDocId, inChanged = false, inAdded = false, inRemoved = false; + const observer = cursor.observeChanges({ + added(docId, doc) { + if (inAdded) { + return; + } + inAdded = true; - testDocId = docId; - assert.equal(doc.number, 5); + testDocId = docId; + assert.equal(doc.number, 5); - setTimeout(async () => { - const result = await fetchSync({ _id: docId }); - assert.isArray(result); - assert.lengthOf(result, 1); - assert.equal(result[0].number, 5); + setTimeout(async () => { + const result = await fetchSync({ _id: docId }); + assert.isArray(result); + assert.lengthOf(result, 1); + assert.equal(result[0].number, 5); - Collection.update(docId, { - $set: {number: 10} - }) - }, 100) - }, - changed(docId, doc) { - if (inChanged) { - return; - } - inChanged = true; - assert.equal(docId, testDocId); - assert.equal(doc.number, 10); + Collection.update(docId, { + $set: { number: 10 } + }) + }, 100) + }, + changed(docId, doc) { + if (inChanged) { + return; + } + inChanged = true; + assert.equal(docId, testDocId); + assert.equal(doc.number, 10); - setTimeout(async () => { - const result = await fetchSync({_id: docId}); - assert.lengthOf(result, 1); - assert.equal(result[0].number, 10); + setTimeout(async () => { + const result = await fetchSync({ _id: docId }); + assert.lengthOf(result, 1); + assert.equal(result[0].number, 10); - Collection.remove(docId) - }, 100); - }, - removed(docId) { - if (inRemoved) { - return; - } - inRemoved = true; - assert.equal(docId, testDocId); - done(); - } - }); + Collection.remove(docId) + }, 100); + }, + removed(docId) { + if (inRemoved) { + return; + } + inRemoved = true; + assert.equal(docId, testDocId); + done(); + } + }); - Collection.insert({ - client_side_mutators: true, - number: 5 - }); + Collection.insert({ + client_side_mutators: true, + number: 5 + }); }); }); }); diff --git a/testing/collection-defaults/client.js b/testing/collection-defaults/client.js index f832e17c..2c775500 100644 --- a/testing/collection-defaults/client.js +++ b/testing/collection-defaults/client.js @@ -1,67 +1,67 @@ import { assert } from 'chai'; -import {Items} from './collections'; -import {_} from 'meteor/underscore'; -import {waitForHandleToBeReady, callWithPromise} from '../lib/sync_utils'; -import {Random} from 'meteor/random'; +import { Items } from './collections'; +import { _ } from 'meteor/underscore'; +import { waitForHandleToBeReady, callWithPromise } from '../lib/sync_utils'; +import { Random } from 'meteor/random'; describe('Collection Defaults', () => { it('Should detect changes based on mutation defaults', function (done) { const context = Random.id(); - const handle = Meteor.subscribe('collection_defaults.items', {context}); - waitForHandleToBeReady(handle).then(function() { - const cursor = Items.find({}); + const handle = Meteor.subscribe('collection_defaults.items', { context }); + waitForHandleToBeReady(handle).then(function () { + const cursor = Items.find({}); - const observer = cursor.observeChanges({ - added(docId, doc) { - assert.isObject(doc); - callWithPromise('collection_defaults.items.update', { - _id: docId - }, { - $set: { - number: 10 + const observer = cursor.observeChanges({ + added(docId, doc) { + assert.isObject(doc); + callWithPromise('collection_defaults.items.update', { + _id: docId + }, { + $set: { + number: 10 + } + }) + }, + changed(docId, doc) { + assert.equal(doc.number, 10); + handle.stop(); + observer.stop(); + done(); } - }) - }, - changed(docId, doc) { - assert.equal(doc.number, 10); - handle.stop(); - observer.stop(); - done(); - } - }); + }); - callWithPromise('collection_defaults.items.insert', { - text: 'hello', - context - }); + callWithPromise('collection_defaults.items.insert', { + text: 'hello', + context + }); }); }); it('Should not detect changes based if a namespace is specified', function (done) { const context = Random.id(); - const handle = Meteor.subscribe('collection_defaults.items', {context}, { + const handle = Meteor.subscribe('collection_defaults.items', { context }, { namespace: 'someothernamespace' }); - waitForHandleToBeReady(handle).then(function() { - const cursor = Items.find({}); + waitForHandleToBeReady(handle).then(function () { + const cursor = Items.find({}); - const observer = cursor.observeChanges({ - added(docId, doc) { - done('It should not be here') - }, - }); + const observer = cursor.observeChanges({ + added(docId, doc) { + done('It should not be here') + }, + }); - callWithPromise('collection_defaults.items.insert', { - text: 'hello again', - context - }).then(function() { - setTimeout(function () { - handle.stop(); - observer.stop(); - done(); - }, 200); - }); + callWithPromise('collection_defaults.items.insert', { + text: 'hello again', + context + }).then(function () { + setTimeout(function () { + handle.stop(); + observer.stop(); + done(); + }, 200); + }); }); }); }); diff --git a/testing/collection_hooks.server.js b/testing/collection_hooks.server.js index c46bf5b3..398ffd32 100644 --- a/testing/collection_hooks.server.js +++ b/testing/collection_hooks.server.js @@ -6,8 +6,8 @@ describe('It should work with collection:hooks', function () { const opts = [ {}, - {channel: 'xxx'}, - {namespace: 'xxx'} + { channel: 'xxx' }, + { namespace: 'xxx' } ]; let idx = 1; @@ -45,8 +45,8 @@ describe('It should work with collection:hooks', function () { updates['after.remove'] = true; }); - const id = Collection.insert({someData: true}); - Collection.update(id, {someData: false}); + const id = Collection.insert({ someData: true }); + Collection.update(id, { someData: false }); Collection.remove(id); _.each(updates, (value, key) => { @@ -54,4 +54,4 @@ describe('It should work with collection:hooks', function () { }) }) }) -}); +}); \ No newline at end of file diff --git a/testing/include_prev_doc.js b/testing/include_prev_doc.js index 29829c88..58d2dae8 100644 --- a/testing/include_prev_doc.js +++ b/testing/include_prev_doc.js @@ -9,48 +9,48 @@ const PrevDocCollection = new Mongo.Collection('test_redis_prev_doc'); const NoPrevDocCollection = new Mongo.Collection('test_redis_no_prev_doc'); PrevDocCollection.configureRedisOplog({ - shouldIncludePrevDocument: true, + shouldIncludePrevDocument: true, }); describe('PrevDocCollection Serverside', function () { - it('Should receive an insert event with prev doc', function (done) { - Config.pubSubManager.subscribe('test_redis_prev_doc', function(payload) { - // make sure events have prev document values - if (payload.e === 'u') { - assert.equal(payload.d.value, 'oldValue'); - } - if (payload.e === 'r') { - assert.equal(payload.d.value, 'newValue'); - done(); - } + it('Should receive an insert event with prev doc', function (done) { + Config.pubSubManager.subscribe('test_redis_prev_doc', function (payload) { + // make sure events have prev document values + if (payload.e === 'u') { + assert.equal(payload.d.value, 'oldValue'); + } + if (payload.e === 'r') { + assert.equal(payload.d.value, 'newValue'); + done(); + } + }); + + const random = Random.id() + + // trigger insert update and removed redis events + PrevDocCollection.insert({ _id: `${random}`, value: 'oldValue' }); + PrevDocCollection.update({ _id: `${random}` }, { $set: { value: 'newValue' } }); + PrevDocCollection.remove({ _id: `${random}` }); }); - const random = Random.id() - - // trigger insert update and removed redis events - PrevDocCollection.insert({ _id: `${random}`, value: 'oldValue' }); - PrevDocCollection.update({ _id: `${random}` }, { $set: { value: 'newValue' } }); - PrevDocCollection.remove({ _id: `${random}` }); - }); - - it('Should receive an insert event without prev doc', function (done) { - Config.pubSubManager.subscribe('test_redis_no_prev_doc', function(payload) { - // make sure events do not have any prev document values - // because NoPrevDocCollection does not have shouldIncludePrevDocument set - // to true - if (payload.e === 'u') { - assert.equal(payload.d.value, undefined); - } - if (payload.e === 'r') { - assert.equal(payload.d.value, undefined); - done(); - } + it('Should receive an insert event without prev doc', function (done) { + Config.pubSubManager.subscribe('test_redis_no_prev_doc', function (payload) { + // make sure events do not have any prev document values + // because NoPrevDocCollection does not have shouldIncludePrevDocument set + // to true + if (payload.e === 'u') { + assert.equal(payload.d.value, undefined); + } + if (payload.e === 'r') { + assert.equal(payload.d.value, undefined); + done(); + } + }); + + // trigger insert update and removed redis events + NoPrevDocCollection.insert({ _id: 'no_prev_doc_1', value: 'oldValue' }); + NoPrevDocCollection.update({ _id: 'no_prev_doc_1' }, { $set: { value: 'newValue' } }); + NoPrevDocCollection.remove({ _id: 'no_prev_doc_1' }); }); - - // trigger insert update and removed redis events - NoPrevDocCollection.insert({ _id: 'no_prev_doc_1', value: 'oldValue' }); - NoPrevDocCollection.update({ _id: 'no_prev_doc_1' }, { $set: { value: 'newValue' } }); - NoPrevDocCollection.remove({ _id: 'no_prev_doc_1' }); - }); }); diff --git a/testing/lib/sync_utils.js b/testing/lib/sync_utils.js index bde6f559..9fe776d9 100644 --- a/testing/lib/sync_utils.js +++ b/testing/lib/sync_utils.js @@ -22,4 +22,4 @@ const waitForHandleToBeReady = handle => { }); }; -export { callWithPromise, waitForHandleToBeReady }; +export { callWithPromise, waitForHandleToBeReady }; \ No newline at end of file diff --git a/testing/main.client.js b/testing/main.client.js index 8d66f317..61f5f662 100644 --- a/testing/main.client.js +++ b/testing/main.client.js @@ -32,8 +32,8 @@ _.each(Collections, (Collection, key) => { waitForHandleToBeReady, } = helperGenerator(config[key].suffix); - describe('It should work with: ' + key, function() { - it('Should detect a removal', function(done) { + describe('It should work with: ' + key, function () { + it('Should detect a removal', function (done) { let handle = subscribe( { game: 'chess', @@ -62,14 +62,14 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { - createSync({ game: 'chess', title: randomTitle }).then(function(id) { + waitForHandleToBeReady(handle).then(function () { + createSync({ game: 'chess', title: randomTitle }).then(function (id) { _id = id; }); }); }); - it('Should detect an insert', function(done) { + it('Should detect an insert', function (done) { let handle = subscribe( { game: 'chess', @@ -87,14 +87,14 @@ _.each(Collections, (Collection, key) => { if (doc.title === 'E') { observeChangesHandle.stop(); handle.stop(); - remove({ _id: docId }, function() { + remove({ _id: docId }, function () { done(); }); } }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { let data = cursor.fetch(); assert.lengthOf(data, 3); @@ -106,7 +106,7 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should detect an update simple', function(done) { + it('Should detect an update simple', function (done) { let handle = subscribe( { game: 'chess', @@ -127,21 +127,21 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { let data = cursor.fetch(); update( - { _id: data[0]._id }, - { - $set: { - score: Math.random(), - }, - } + { _id: data[0]._id }, + { + $set: { + score: Math.random(), + }, + } ); }); }); - it('Should detect an update deeply nested', function(done) { + it('Should detect an update deeply nested', function (done) { createSync({ game: 'chess', nested: { @@ -151,7 +151,7 @@ _.each(Collections, (Collection, key) => { a: 1, }, }, - }).then(function(docId) { + }).then(function (docId) { let handle = subscribe({ _id: docId }); const cursor = Collection.find({ _id: docId }); @@ -174,29 +174,29 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { update( - { _id: docId }, - { - $set: { - 'nested.c.b': 1, - 'nested.b': 2, - 'nested.d': 1, - }, - } + { _id: docId }, + { + $set: { + 'nested.c.b': 1, + 'nested.b': 2, + 'nested.d': 1, + }, + } ); }); }); }); - it('Should not update multiple documents if not specified (multi:true)', function(done) { + it('Should not update multiple documents if not specified (multi:true)', function (done) { const context = Random.id(); createSync([ { context, game: 'monopoly', title: 'test' }, { context, game: 'monopoly', title: 'test2' }, - ]).then(function([_id1, _id2]) { + ]).then(function ([_id1, _id2]) { let handle = subscribe({ game: 'monopoly' }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ _id: { $in: [_id1, _id2] } }); const observeChangesHandle = cursor.observeChanges({ @@ -211,21 +211,21 @@ _.each(Collections, (Collection, key) => { }); update( - { context, game: 'monopoly' }, - { $set: { score: Math.random() } } + { context, game: 'monopoly' }, + { $set: { score: Math.random() } } ); }); }); }); - it('Should update multiple documents if specified', function(done) { + it('Should update multiple documents if specified', function (done) { const context = 'multi-update'; createSync([ { context, title: 'test' }, { context, title: 'test2' }, - ]).then(function([_id1, _id2]) { + ]).then(function ([_id1, _id2]) { let handle = subscribe({ context }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); let changes = 0; @@ -242,21 +242,21 @@ _.each(Collections, (Collection, key) => { }); update( - { context }, - { - $set: { score: Math.random() }, - }, - { multi: true } + { context }, + { + $set: { score: Math.random() }, + }, + { multi: true } ); }); }); }); - it('Should detect an update of a non published document', function(done) { + it('Should detect an update of a non published document', function (done) { let _id = createSync({ game: 'backgammon', title: 'test', - }).then(function(_id){ + }).then(function (_id) { let handle = subscribe({ game: 'chess', }); @@ -280,13 +280,13 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { update({ _id }, { $set: { game: 'chess', score } }); }); }); }); - it('Should detect an update of a nested field when fields is specified', function(done) { + it('Should detect an update of a nested field when fields is specified', function (done) { createSync({ roles: { _groups: ['company1', 'company2', 'company3'], @@ -295,12 +295,12 @@ _.each(Collections, (Collection, key) => { roles: ['manage-users', 'manage-profiles'], }, }, - }).then(function(_id) { + }).then(function (_id) { let handle = subscribe( - {}, - { - fields: { roles: 1 }, - } + {}, + { + fields: { roles: 1 }, + } ); const cursor = Collection.find(); @@ -314,13 +314,13 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { update({ _id }, { $set: { 'roles._main': 'company2' } }); }); }); }); - it('Should update properly a nested field when a positional parameter is used', function(done) { + it('Should update properly a nested field when a positional parameter is used', function (done) { const context = 'positional-paramter'; createSync({ @@ -339,15 +339,15 @@ _.each(Collections, (Collection, key) => { quantity: 3, }, ], - }).then(function(_id) { + }).then(function (_id) { let handle = subscribe( - { context }, - { - fields: { - context: 1, - bom: 1, - }, - } + { context }, + { + fields: { + context: 1, + bom: 1, + }, + } ); const cursor = Collection.find({ context }); @@ -369,24 +369,24 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { update( - { _id, 'bom.stockId': 1 }, - { - $set: { 'bom.$.quantity': 30 }, - } + { _id, 'bom.stockId': 1 }, + { + $set: { 'bom.$.quantity': 30 }, + } ); }); }); }); ['server'].forEach(context => { - it('Should work with $and operators: ' + context, function(done) { + it('Should work with $and operators: ' + context, function (done) { createSync({ orgid: '1', siteIds: ['1', '2'], Year: 2017, - }).then(function(_id) { + }).then(function (_id) { let handle = subscribe({ $and: [ { @@ -401,7 +401,7 @@ _.each(Collections, (Collection, key) => { ], }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find(); let inChangedEvent = false; const observeChangesHandle = cursor.observeChanges({ @@ -422,28 +422,28 @@ _.each(Collections, (Collection, key) => { }); update( - { _id }, - { - $set: { - something: 30, - }, - } + { _id }, + { + $set: { + something: 30, + }, + } ); }); }); }); }); - it('Should be able to detect subsequent updates for direct processing with _ids', function(done) { + it('Should be able to detect subsequent updates for direct processing with _ids', function (done) { createSync([ { subsequent_test: true, name: 'John Smith' }, { subsequent_test: true, name: 'Michael Willow' }, - ]).then(function([_id1, _id2]) { + ]).then(function ([_id1, _id2]) { let handle = subscribe( - { _id: { $in: [_id1, _id2] } }, - { - fields: { subsequent_test: 1, name: 1 }, - } + { _id: { $in: [_id1, _id2] } }, + { + fields: { subsequent_test: 1, name: 1 }, + } ); const cursor = Collection.find({ subsequent_test: true }); @@ -465,10 +465,10 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { updateSync(_id1, { $set: { name: 'John Smithy' }, - }).then(function() { + }).then(function () { updateSync(_id2, { $set: { name: 'Michael Willowy' }, }); @@ -477,16 +477,16 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with the $addToSet', function(done) { + it('Should work with the $addToSet', function (done) { createSync({ operators: true, connections: [1, 2], number: 10, - }).then(function(_id) { + }).then(function (_id) { let handle = subscribe({ _id }); let cursor = Collection.find({ _id }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const observer = cursor.observeChanges({ changed(docId, doc) { assert.equal(docId, _id); @@ -499,27 +499,27 @@ _.each(Collections, (Collection, key) => { }); updateSync( - { _id }, - { - $addToSet: { - connections: 3, - }, - } + { _id }, + { + $addToSet: { + connections: 3, + }, + } ); }); }); }); - it('Should work with the $pull', function(done) { + it('Should work with the $pull', function (done) { createSync({ operators: true, connections: [1, 2], number: 10, - }).then(function(_id) { + }).then(function (_id) { let handle = subscribe({ _id }); let cursor = Collection.find({ _id }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const observer = cursor.observeChanges({ changed(docId, doc) { assert.equal(docId, _id); @@ -532,29 +532,29 @@ _.each(Collections, (Collection, key) => { }); updateSync( - { _id }, - { - $pull: { - connections: 2, - }, - } + { _id }, + { + $pull: { + connections: 2, + }, + } ); }); }); }); - it('Should work with nested field updates', function(done) { + it('Should work with nested field updates', function (done) { createSync({ profile: { language: 'EN', email: 'xxx@xxx.com', number: 5, }, - }).then(function(_id) { + }).then(function (_id) { let handle = subscribe({ _id }); let cursor = Collection.find({ _id }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const observer = cursor.observeChanges({ changed(docId, doc) { assert.equal(docId, _id); @@ -578,28 +578,28 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with the $pull and $set in combination', function(done) { + it('Should work with the $pull and $set in combination', function (done) { createSync({ test_pull_and_set_combo: true, connections: [1], number: 10, - }).then(function(_id) { + }).then(function (_id) { let handle = subscribe({ test_pull_and_set_combo: true }); let cursor = Collection.find( - { - _id: { - $in: [_id], - }, - }, - { - fields: { - connections: 1, - number: 1, - }, - } + { + _id: { + $in: [_id], + }, + }, + { + fields: { + connections: 1, + number: 1, + }, + } ); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const observer = cursor.observeChanges({ changed(docId, doc) { assert.equal(docId, _id); @@ -624,10 +624,10 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work properly with limit-sort kind of queries', function(done) { + it('Should work properly with limit-sort kind of queries', function (done) { const context = 'limit-sort-test'; const limit = 5; - removeSync({ context }).then(function() { + removeSync({ context }).then(function () { createSync([ { context, number: 5, text: 'T - 1' }, { context, number: 10, text: 'T - 2' }, @@ -635,20 +635,20 @@ _.each(Collections, (Collection, key) => { { context, number: 20, text: 'T - 4' }, { context, number: 25, text: 'T - 5' }, { context, number: -1, text: 'T - Last one' }, - ]).then(function(ids) { + ]).then(function (ids) { const [_id1, _id2, _id3, _id4, _id5, _id6] = ids; const handle = subscribe( - { - context, - }, - { - limit, - sort: { number: -1 }, - } + { + context, + }, + { + limit, + sort: { number: -1 }, + } ); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); let inChanged = false; let initialAddBlast = true; @@ -664,10 +664,10 @@ _.each(Collections, (Collection, key) => { // Now we will add it back! updateSync( - { _id: _id3 }, - { - $set: { context }, - } + { _id: _id3 }, + { + $set: { context }, + } ); } }, @@ -702,35 +702,35 @@ _.each(Collections, (Collection, key) => { // }); updateSync( - { _id: _id2 }, - { - $set: { number: 30 }, - } + { _id: _id2 }, + { + $set: { number: 30 }, + } ); updateSync( - { _id: _id3 }, - { - $set: { context: 'limit-sort-test-invalidate' }, - } + { _id: _id3 }, + { + $set: { context: 'limit-sort-test-invalidate' }, + } ); }); }); }); }); - it('Should work with _ids direct processing and other filters present', function(done) { + it('Should work with _ids direct processing and other filters present', function (done) { const context = 'ids-process-test'; createSync([ { context, meta: { student: false } }, { context, meta: { student: true } }, { context, meta: { student: true } }, - ]).then(function(ids) { + ]).then(function (ids) { const handle = subscribe({ _id: { $in: ids }, 'meta.student': true, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { let cursor = Collection.find({ context }); const data = cursor.fetch(); @@ -768,11 +768,11 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should detect an insert with the default processor', function(done) { + it('Should detect an insert with the default processor', function (done) { const context = 'insert-default-processing' + Random.id(); const handle = subscribe({ context }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); let observer; @@ -791,12 +791,12 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should detect an update with string publication that should be id', function(done) { + it('Should detect an update with string publication that should be id', function (done) { const context = 'string-filters'; - createSync({ context }).then(function(_id) { + createSync({ context }).then(function (_id) { const handle = subscribe(_id); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); const observer = cursor.observeChanges({ @@ -814,13 +814,13 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with deep nest specified fields', function(done) { + it('Should work with deep nest specified fields', function (done) { const context = 'edge-case-001'; createSync({ context, passengers: [], - }).then(function(_id) { + }).then(function (_id) { const handle = subscribe(_id, { fields: { context: 1, @@ -828,7 +828,7 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); const observer = cursor.observeChanges({ changed(docId, doc) { @@ -853,22 +853,22 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with upsert', function(done) { + it('Should work with upsert', function (done) { const context = 'upsertion' + Random.id(); const handle = subscribe({ context }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); const observer = cursor.observeChanges({ added(docId, doc) { assert.equal(doc.number, 10); upsert( - { context }, - { - $set: { - number: 20, - }, - } + { context }, + { + $set: { + number: 20, + }, + } ); }, changed(docId, doc) { @@ -880,20 +880,20 @@ _.each(Collections, (Collection, key) => { }); upsert( - { context }, - { - context, - number: 10, - } + { context }, + { + context, + number: 10, + } ); }); }); - it('Should not detect a change if pushToRedis is false', function(done) { + it('Should not detect a change if pushToRedis is false', function (done) { const context = 'pushToRedis:false'; const handle = subscribe({ context }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); let _id; const observer = cursor.observeChanges({ @@ -915,22 +915,22 @@ _.each(Collections, (Collection, key) => { }); createSync( - { - context, - }, - { pushToRedis: false } - ).then(function(id) { + { + context, + }, + { pushToRedis: false } + ).then(function (id) { _id = id; update( - { _id }, - { - $set: { number: 10 }, - }, - { pushToRedis: false }, - (err, res) => { - remove({ _id }, { pushToRedis: false }); - } + { _id }, + { + $set: { number: 10 }, + }, + { pushToRedis: false }, + (err, res) => { + remove({ _id }, { pushToRedis: false }); + } ); setTimeout(() => { @@ -942,7 +942,7 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work correctly when disallowed fields are specified', function(done) { + it('Should work correctly when disallowed fields are specified', function (done) { const context = 'disallowed-fields-' + Random.id(); const handle = subscribe( { context }, @@ -955,7 +955,7 @@ _.each(Collections, (Collection, key) => { } ); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); let _id; @@ -971,16 +971,16 @@ _.each(Collections, (Collection, key) => { assert.isUndefined(doc.fullname); update( - { _id: docId }, - { - $set: { - 'address.country': 'Testing', - fullname: 'Testing', - other: 'Publico', - newField: 'public', - 'profile.firstName': 'John', - }, - } + { _id: docId }, + { + $set: { + 'address.country': 'Testing', + fullname: 'Testing', + other: 'Publico', + newField: 'public', + 'profile.firstName': 'John', + }, + } ); }, changed(docId, doc) { @@ -1009,13 +1009,13 @@ _.each(Collections, (Collection, key) => { }, fullname: 'Secret', other: 'Public', - }).then(function(id) { + }).then(function (id) { _id = id; }); }); }); - it('Should work correctly with the allowed fields only specified', function(done) { + it('Should work correctly with the allowed fields only specified', function (done) { const context = 'allowed-fields'; const handle = subscribe( { context }, @@ -1029,7 +1029,7 @@ _.each(Collections, (Collection, key) => { } ); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); const observer = cursor.observeChanges({ added(docId, doc) { @@ -1041,16 +1041,16 @@ _.each(Collections, (Collection, key) => { assert.isString(doc.fullname); update( - { _id: docId }, - { - $set: { - 'address.country': 'Testing', - fullname: 'Testing', - other: 'secret', - newField: 'secret', - 'profile.firstName': 'John', - }, - } + { _id: docId }, + { + $set: { + 'address.country': 'Testing', + fullname: 'Testing', + other: 'secret', + newField: 'secret', + 'profile.firstName': 'John', + }, + } ); }, changed(docId, doc) { @@ -1081,7 +1081,7 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with limit-sort when only _id is specified', function(done) { + it('Should work with limit-sort when only _id is specified', function (done) { const context = Random.id(); const handle = subscribe( { context }, @@ -1095,26 +1095,26 @@ _.each(Collections, (Collection, key) => { } ); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); const observer = cursor.observeChanges({ added(docId, doc) { assert.isUndefined(doc.something); assert.isTrue(_.keys(doc).length == 1); update( - { _id: docId }, - { - $set: { - something: false, - }, - } + { _id: docId }, + { + $set: { + something: false, + }, + } ); done(); }, changed(docId, doc) { done( - 'Should not be in changed event because nothing changed' + 'Should not be in changed event because nothing changed' ); }, }); @@ -1126,11 +1126,11 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work properly with $unset', function(done) { + it('Should work properly with $unset', function (done) { const context = 'test-$unset'; const handle = subscribe({ context }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); const observer = cursor.observeChanges({ added(docId, doc) { @@ -1138,12 +1138,12 @@ _.each(Collections, (Collection, key) => { setTimeout(() => { update( - { _id: docId }, - { - $unset: { - something: '', - }, - } + { _id: docId }, + { + $unset: { + something: '', + }, + } ); }, 50); }, @@ -1164,7 +1164,7 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work when updating deep array when it is specified as a field', function(done) { + it('Should work when updating deep array when it is specified as a field', function (done) { const context = `deep-array-objects-${Random.id()}`; let handle = subscribe( @@ -1177,7 +1177,7 @@ _.each(Collections, (Collection, key) => { } ); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); const observer = cursor.observeChanges({ @@ -1185,15 +1185,15 @@ _.each(Collections, (Collection, key) => { assert.isArray(doc.deep.deep.array); assert.lengthOf(doc.deep.deep.array, 6); update( - { - _id: docId, - 'deep.deep.array': 6, - }, - { - $set: { - 'deep.deep.array.$': 20, - }, - } + { + _id: docId, + 'deep.deep.array': 6, + }, + { + $set: { + 'deep.deep.array.$': 20, + }, + } ); }, changed(docId, doc) { @@ -1221,7 +1221,7 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work when updating a specific element in an array', function(done) { + it('Should work when updating a specific element in an array', function (done) { const context = 'update-specific-in-arrays'; let handle = subscribe( @@ -1234,18 +1234,18 @@ _.each(Collections, (Collection, key) => { } ); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context }); const observer = cursor.observeChanges({ added(docId, doc) { update( - { _id: docId }, - { - $set: { - 'passengers.1.phone': 'ZZZ', - }, - } + { _id: docId }, + { + $set: { + 'passengers.1.phone': 'ZZZ', + }, + } ); }, changed(docId, doc) { @@ -1276,7 +1276,7 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with $elemMatch query selector', function(done) { + it('Should work with $elemMatch query selector', function (done) { const context = 'work-with-elemMatch-' + Random.id(); let handle = subscribe({ @@ -1288,7 +1288,7 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context, }); @@ -1314,14 +1314,14 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should detect 3rd level nesting changes', function(done) { + it('Should detect 3rd level nesting changes', function (done) { const context = 'deep-level-nesting-' + Random.id(); let handle = subscribe({ context, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ context, }); @@ -1352,27 +1352,27 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with a filter on a subfield and a top field specified', function(done) { + it('Should work with a filter on a subfield and a top field specified', function (done) { createSync({ master: { sub: 'TEST', sub2: 1, sub3: 1, }, - }).then(function(_id) { + }).then(function (_id) { let handle = subscribe( - { - _id, - 'master.sub': 'TEST', - }, - { - fields: { - master: 1, - }, - } + { + _id, + 'master.sub': 'TEST', + }, + { + fields: { + master: 1, + }, + } ); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { const cursor = Collection.find({ _id }); const document = Collection.findOne({ _id }); assert.isObject(document.master); @@ -1390,13 +1390,13 @@ _.each(Collections, (Collection, key) => { }); update( - { _id }, - { - $set: { 'master.sub2': 2 }, - } + { _id }, + { + $set: { 'master.sub2': 2 }, + } ); }); }); }); }); -}); +}); \ No newline at end of file diff --git a/testing/object-id/client.js b/testing/object-id/client.js index dd987ffc..205d8d57 100644 --- a/testing/object-id/client.js +++ b/testing/object-id/client.js @@ -2,22 +2,22 @@ import { assert } from 'chai'; import { SmartIds } from './collections'; import { Meteor } from 'meteor/meteor'; -describe('ObjectId', function() { - it('Should work!', function(done) { - Meteor.callWithPromise('smart_ids_reset').then(function([id1, id2]) { - const handle = Meteor.subscribe( - 'smart_ids', - { - _id: id1 - }, - function() { - const result = SmartIds.findOne(); +describe('ObjectId', function () { + it('Should work!', function (done) { + Meteor.callWithPromise('smart_ids_reset').then(function ([id1, id2]) { + const handle = Meteor.subscribe( + 'smart_ids', + { + _id: id1 + }, + function () { + const result = SmartIds.findOne(); - assert.isObject(result); - assert.isObject(result._id); - done(); - } - ); + assert.isObject(result); + assert.isObject(result._id); + done(); + } + ); }); }); -}); +}); \ No newline at end of file diff --git a/testing/optimistic-ui/client.test.js b/testing/optimistic-ui/client.test.js index 39943cbd..2480e25d 100644 --- a/testing/optimistic-ui/client.test.js +++ b/testing/optimistic-ui/client.test.js @@ -6,49 +6,49 @@ import { Random } from 'meteor/random'; import './boot'; describe('Optimistic UI', () => { - it('Should not cause a flicker with method calls', function(done) { + it('Should not cause a flicker with method calls', function (done) { const context = Random.id(); callWithPromise('optimistic_ui.items.insert', { context, liked: ['ZZZ'], - }).then(function(itemId) { - const handle = Meteor.subscribe('optimistic_ui.items', { _id: itemId }); - waitForHandleToBeReady(handle).then(function() { - const cursor = Items.find({ _id: itemId }); + }).then(function (itemId) { + const handle = Meteor.subscribe('optimistic_ui.items', { _id: itemId }); + waitForHandleToBeReady(handle).then(function () { + const cursor = Items.find({ _id: itemId }); - let alreadyIn = 0; - const observer = cursor.observeChanges({ - changed(docId, doc) { - alreadyIn++; - if (alreadyIn > 1) { - done('A flicker was caused.'); - } + let alreadyIn = 0; + const observer = cursor.observeChanges({ + changed(docId, doc) { + alreadyIn++; + if (alreadyIn > 1) { + done('A flicker was caused.'); + } - assert.lengthOf(doc.liked, 2); - assert.isTrue(_.contains(doc.liked, 'XXX')); + assert.lengthOf(doc.liked, 2); + assert.isTrue(_.contains(doc.liked, 'XXX')); - setTimeout(() => { - handle.stop(); - observer.stop(); - done(); - }, 200); - }, - }); + setTimeout(() => { + handle.stop(); + observer.stop(); + done(); + }, 200); + }, + }); - const item = _.first(cursor.fetch()); - assert.isObject(item); + const item = _.first(cursor.fetch()); + assert.isObject(item); - Meteor.call('optimistic_ui.items.update', item._id, { - $addToSet: { - liked: 'XXX', - }, + Meteor.call('optimistic_ui.items.update', item._id, { + $addToSet: { + liked: 'XXX', + }, + }); }); - }); }); }); - it('Should not cause a flicker with isomorphic calls', function(done) { + it('Should not cause a flicker with isomorphic calls', function (done) { const context = Random.id(); const itemId = Items.insert({ @@ -57,36 +57,36 @@ describe('Optimistic UI', () => { }); const handle = Meteor.subscribe('optimistic_ui.items', { _id: itemId }); - waitForHandleToBeReady(handle).then(function() { - const cursor = Items.find({ _id: itemId }); + waitForHandleToBeReady(handle).then(function () { + const cursor = Items.find({ _id: itemId }); - let alreadyIn = 0; - const observer = cursor.observeChanges({ - changed(docId, doc) { - alreadyIn++; - if (alreadyIn > 1) { - done('A flicker was caused.'); - } + let alreadyIn = 0; + const observer = cursor.observeChanges({ + changed(docId, doc) { + alreadyIn++; + if (alreadyIn > 1) { + done('A flicker was caused.'); + } - assert.lengthOf(doc.liked, 2); - assert.isTrue(_.contains(doc.liked, 'XXX')); + assert.lengthOf(doc.liked, 2); + assert.isTrue(_.contains(doc.liked, 'XXX')); - setTimeout(() => { - handle.stop(); - observer.stop(); - done(); - }, 200); - }, - }); + setTimeout(() => { + handle.stop(); + observer.stop(); + done(); + }, 200); + }, + }); - const item = _.first(cursor.fetch()); - assert.isObject(item); + const item = _.first(cursor.fetch()); + assert.isObject(item); - Items.update(item._id, { - $addToSet: { - liked: 'XXX', - }, - }); + Items.update(item._id, { + $addToSet: { + liked: 'XXX', + }, + }); }); }); -}); +}); \ No newline at end of file diff --git a/testing/polling/client.js b/testing/polling/client.js index 7c1aaff4..cf0a3753 100644 --- a/testing/polling/client.js +++ b/testing/polling/client.js @@ -2,36 +2,36 @@ import { assert } from 'chai'; import { Campaigns } from './collections'; import { Meteor } from 'meteor/meteor'; -describe('Polling', function() { - it('Should work!', function(done) { - Meteor.callWithPromise('campaign_search_reset').then(function() { - const pollingIntervalMs = 100; +describe('Polling', function () { + it('Should work!', function (done) { + Meteor.callWithPromise('campaign_search_reset').then(function () { + const pollingIntervalMs = 100; - const handle = Meteor.subscribe( - 'campaign_search', - 'John', - pollingIntervalMs, - function() { - const results = Campaigns.find().fetch(); + const handle = Meteor.subscribe( + 'campaign_search', + 'John', + pollingIntervalMs, + function () { + const results = Campaigns.find().fetch(); - assert.lengthOf(results, 2); + assert.lengthOf(results, 2); - Meteor.call( - 'campaign_search_insert', - { - text: 'John Broman' - }, - function() { - setTimeout(() => { - const results = Campaigns.find().fetch(); - assert.lengthOf(results, 3); + Meteor.call( + 'campaign_search_insert', + { + text: 'John Broman' + }, + function () { + setTimeout(() => { + const results = Campaigns.find().fetch(); + assert.lengthOf(results, 3); - done(); - }, pollingIntervalMs + 100); + done(); + }, pollingIntervalMs + 100); + } + ); } - ); - } - ); + ); }); }); -}); +}); \ No newline at end of file diff --git a/testing/publishComposite/client.test.js b/testing/publishComposite/client.test.js index d2a4f4fd..4342bdbf 100644 --- a/testing/publishComposite/client.test.js +++ b/testing/publishComposite/client.test.js @@ -1,44 +1,44 @@ import { assert } from 'chai'; -import {Items, Children} from './collections'; -import {_} from 'meteor/underscore'; -import {waitForHandleToBeReady, callWithPromise} from '../lib/sync_utils'; +import { Items, Children } from './collections'; +import { _ } from 'meteor/underscore'; +import { waitForHandleToBeReady, callWithPromise } from '../lib/sync_utils'; describe('Publish Composite', () => { it('Should be able to detect updates on parent element', function (done) { - callWithPromise('publish_composite.load_fixtures').then(function() { - const handle = Meteor.subscribe('items_publish_composite'); - waitForHandleToBeReady(handle).then(function() { - const cursor = Items.find(); + callWithPromise('publish_composite.load_fixtures').then(function () { + const handle = Meteor.subscribe('items_publish_composite'); + waitForHandleToBeReady(handle).then(function () { + const cursor = Items.find(); - const observer = cursor.observeChanges({ - changed(docId, doc) { - assert.equal(doc.name, 'Other Name'); - const firstChild = Children.find({itemId: docId}).fetch()[0]; + const observer = cursor.observeChanges({ + changed(docId, doc) { + assert.equal(doc.name, 'Other Name'); + const firstChild = Children.find({ itemId: docId }).fetch()[0]; - Meteor.call('publish_composite.children.update', firstChild._id, { - $set: {name: 'Other Name'} + Meteor.call('publish_composite.children.update', firstChild._id, { + $set: { name: 'Other Name' } + }); + } }); - } - }); - const item = _.first(cursor.fetch()); - assert.isObject(item); + const item = _.first(cursor.fetch()); + assert.isObject(item); - const childCursor = Children.find({itemId: item._id}); - const childObserver = childCursor.observeChanges({ - changed(docId, doc) { - assert.equal(doc.name, 'Other Name'); + const childCursor = Children.find({ itemId: item._id }); + const childObserver = childCursor.observeChanges({ + changed(docId, doc) { + assert.equal(doc.name, 'Other Name'); - done(); - handle.stop(); - observer.stop(); - } - }); + done(); + handle.stop(); + observer.stop(); + } + }); - callWithPromise('publish_composite.items.update', item._id, { - $set: {name: 'Other Name'} + callWithPromise('publish_composite.items.update', item._id, { + $set: { name: 'Other Name' } + }); }); - }); }); }) -}); +}); \ No newline at end of file diff --git a/testing/synthetic_mutators.js b/testing/synthetic_mutators.js index 002cb342..20c2d50a 100644 --- a/testing/synthetic_mutators.js +++ b/testing/synthetic_mutators.js @@ -18,8 +18,8 @@ _.each(Collections, (Collection, key) => { return; } - describe('It should work with synthetic mutators: ' + key, function() { - it('Should work with insert', function(done) { + describe('It should work with synthetic mutators: ' + key, function () { + it('Should work with insert', function (done) { let handle = subscribe({ game: `synthetic.${config[key].suffix}`, }); @@ -35,14 +35,14 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { synthetic('insert', { game: `synthetic.${config[key].suffix}`, }); }); }); - it('Should work with update with operators: $set', function(done) { + it('Should work with update with operators: $set', function (done) { let handle = subscribe({ game: 'chess', }); @@ -58,7 +58,7 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { let _id = cursor.fetch()[0]._id; assert.isString(_id); @@ -70,11 +70,11 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with update with operators: $push', function(done) { + it('Should work with update with operators: $push', function (done) { createSync({ synthetic_test: true, connections: [], - }).then(function(_id) { + }).then(function (_id) { let handle = subscribe({ synthetic_test: true }); const cursor = Collection.find({ @@ -90,7 +90,7 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { synthetic('update', _id, { $push: { connections: 1, @@ -100,7 +100,7 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with update', function(done) { + it('Should work with update', function (done) { let handle = subscribe({ game: 'chess' }); const cursor = Collection.find(); @@ -114,7 +114,7 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { let _id = cursor.fetch()[0]._id; assert.isString(_id); @@ -126,7 +126,7 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with remove', function(done) { + it('Should work with remove', function (done) { let handle = subscribe({ game: 'chess', }); @@ -144,7 +144,7 @@ _.each(Collections, (Collection, key) => { }, }); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { _id = cursor.fetch()[0]._id; assert.isString(_id); @@ -152,16 +152,16 @@ _.each(Collections, (Collection, key) => { }); }); - it('Should work with update with _id', function(done) { + it('Should work with update with _id', function (done) { const context = 'synth-with-id'; - createSync({ context }).then(function(_id) { + createSync({ context }).then(function (_id) { let handle = subscribe({ _id: { $in: [_id] }, }); const cursor = Collection.find(); - waitForHandleToBeReady(handle).then(function() { + waitForHandleToBeReady(handle).then(function () { let observer = cursor.observeChanges({ changed(docId, doc) { assert.equal(docId, _id); @@ -173,17 +173,17 @@ _.each(Collections, (Collection, key) => { }); synthetic( - 'update', - _id, - { - $set: { - isPlaying: true, - }, - }, - `${Collection._name}::${_id}` + 'update', + _id, + { + $set: { + isPlaying: true, + }, + }, + `${Collection._name}::${_id}` ); }); }); }); }); -}); +}); \ No newline at end of file diff --git a/testing/transformations/client.js b/testing/transformations/client.js index abc87015..7359dc58 100644 --- a/testing/transformations/client.js +++ b/testing/transformations/client.js @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import {Items} from './collections'; +import { Items } from './collections'; describe('Transformations', function () { it('Should receive correct data', function (done) { @@ -29,4 +29,4 @@ describe('Transformations', function () { }) }) }) -}); +}); \ No newline at end of file diff --git a/testing/vent/client.js b/testing/vent/client.js index a776c6f1..1c46786d 100644 --- a/testing/vent/client.js +++ b/testing/vent/client.js @@ -1,7 +1,7 @@ import { assert } from 'chai'; -import {waitForHandleToBeReady, callWithPromise} from '../lib/sync_utils'; -import {Random} from 'meteor/random'; -import {Vent} from 'meteor/cultofcoders:redis-oplog'; +import { waitForHandleToBeReady, callWithPromise } from '../lib/sync_utils'; +import { Random } from 'meteor/random'; +import { Vent } from 'meteor/cultofcoders:redis-oplog'; describe('Vent', function () { it('Should receive the event accordingly', function (done) { @@ -21,7 +21,7 @@ describe('Vent', function () { Meteor.call('vent_emit', { channel, - object: {text: 'Hello!'} + object: { text: 'Hello!' } }) }); @@ -32,7 +32,7 @@ describe('Vent', function () { let inHandle1 = false; let inHandle2 = false; - const handle1 = Vent.subscribe('threadMessage', {channel}); + const handle1 = Vent.subscribe('threadMessage', { channel }); handle1.listen(function (message) { inHandle1 = true; @@ -44,7 +44,7 @@ describe('Vent', function () { } }); - const handle2 = Vent.subscribe('threadMessage', {channel}); + const handle2 = Vent.subscribe('threadMessage', { channel }); handle2.listen(function (message) { inHandle2 = true; @@ -58,7 +58,7 @@ describe('Vent', function () { Meteor.call('vent_emit', { channel, - object: {text: 'Hello!'} + object: { text: 'Hello!' } }) }); @@ -82,7 +82,7 @@ describe('Vent', function () { Meteor.call('vent_emit', { channel, - object: {text: 'Hello!'}, + object: { text: 'Hello!' }, times: 100 }) }); @@ -104,11 +104,11 @@ describe('Vent', function () { Meteor.call('vent_emit', { channel, - object: {text: 'Hello!'} + object: { text: 'Hello!' } }); setTimeout(function () { done(); }, 200); }); -}); +}); \ No newline at end of file From b09c714701077c93c16822ae1e95881f47bb5ef4 Mon Sep 17 00:00:00 2001 From: Nick Aquina Date: Mon, 9 Aug 2021 12:15:57 +0200 Subject: [PATCH 03/42] Fix return value of Collection.update when upserting --- lib/mongo/Mutator.js | 8 ++++++-- testing/main.server.js | 1 + testing/return_value.js | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 testing/return_value.js diff --git a/lib/mongo/Mutator.js b/lib/mongo/Mutator.js index 78400e8b..6c8115b0 100644 --- a/lib/mongo/Mutator.js +++ b/lib/mongo/Mutator.js @@ -152,7 +152,7 @@ export default class Mutator { Originals, selector, modifier, - config, + _.extend({}, {_returnObject: false}, config), callback, docIds, docs @@ -294,7 +294,11 @@ export default class Mutator { } } - return data; + if(config._returnObject) { + return data; + } else { + return data.numberAffected; + } } catch (e) { if (callback) { const self = this; diff --git a/testing/main.server.js b/testing/main.server.js index 4e930e69..343f9736 100644 --- a/testing/main.server.js +++ b/testing/main.server.js @@ -19,6 +19,7 @@ import './collection-defaults/server'; import './polling/server'; import './object-id/server'; import './include_prev_doc'; +import './return_value'; import { _ } from 'meteor/underscore'; diff --git a/testing/return_value.js b/testing/return_value.js new file mode 100644 index 00000000..3278da3c --- /dev/null +++ b/testing/return_value.js @@ -0,0 +1,23 @@ +import { assert } from 'chai'; + +describe('Collection', function () { + + let idx = 1; + const Collection = new Mongo.Collection('test_return_value_' + idx++); + + it('should return the amount of updated documents when updating', function () { + const id = Collection.insert({someData: true}) + const r = Collection.update(id, {someData: false}); + assert.strictEqual(r, 1) + }) + it('should return the amount of updated documents when upserting with update', function () { + const id = Collection.insert({someData: true}) + const r = Collection.update(id, {someData: false}, {upsert: true}); + assert.strictEqual(r, 1) + }) + it('should return an object with the amount of updated documents when upserting', function () { + const id = Collection.insert({someData: true}) + const r = Collection.upsert(id, {someData: false}); + assert.deepEqual(r, {numberAffected: 1}) + }) +}); From 122310c8edcab2a03f236d563f38248a590b80ad Mon Sep 17 00:00:00 2001 From: Matthew Fenwick Date: Fri, 1 Oct 2021 13:16:16 -0400 Subject: [PATCH 04/42] Fix collection channel names used by SyntheticMutator --- lib/cache/lib/getChannels.js | 2 +- lib/mongo/SyntheticMutator.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/cache/lib/getChannels.js b/lib/cache/lib/getChannels.js index d229fba1..65915a46 100644 --- a/lib/cache/lib/getChannels.js +++ b/lib/cache/lib/getChannels.js @@ -1,7 +1,7 @@ import { _ } from 'meteor/underscore'; import getChannelName from '../../utils/getChannelName'; -export default (collectionName, {namespace, channel, namespaces, channels}) => { +export default (collectionName, {namespace, channel, namespaces, channels} = {}) => { let channelStrings = []; if (namespaces) { diff --git a/lib/mongo/SyntheticMutator.js b/lib/mongo/SyntheticMutator.js index 5c881fb8..b5bbf233 100644 --- a/lib/mongo/SyntheticMutator.js +++ b/lib/mongo/SyntheticMutator.js @@ -5,6 +5,8 @@ import { EJSON } from 'meteor/ejson'; import getFields from '../utils/getFields'; import { Events, RedisPipe } from '../constants'; import containsOperators from '../mongo/lib/containsOperators'; +import getChannels from '../cache/lib/getChannels'; +import getDedicatedChannel from '../utils/getDedicatedChannel'; /** * call(Mongo.Collection).insert(data) @@ -92,9 +94,9 @@ export default class SyntheticMutator { if (!_.isArray(channels)) { if (channels instanceof Mongo.Collection) { const name = channels._name; - channels = [name]; + channels = getChannels(name); if (_id) { - channels.push(`${name}::${_id}`); + channels.push(getDedicatedChannel(name, _id)); } } From fe3e4b03edfc1c6279b15b92b0c508a483f89245 Mon Sep 17 00:00:00 2001 From: Theodor Diaconu Date: Wed, 15 Dec 2021 08:55:36 +0200 Subject: [PATCH 05/42] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25d8082f..9f34d5ec 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ -# Welcome to Redis Oplog +## Introducing BlueLibs + +- Following the same bold vision of Meteor, but with a modern twist. www.bluelibs.com +- Read more about our approach coming from Meteor: https://www.bluelibs.com/blog/2021/11/26/the-meteor-of-2022 +- We've implemented [RedisOplog](https://www.bluelibs.com/docs/package-x-bundle#live-data) in our framework as well, but it also works with in-memory and with customisable pubsub, not bound to redis. +# Welcome to Redis Oplog ### LICENSE: MIT From 2b4a3cf8cd39f97b3a228d0cddfa53c0b4aa5887 Mon Sep 17 00:00:00 2001 From: Theodor Diaconu Date: Wed, 15 Dec 2021 08:56:28 +0200 Subject: [PATCH 06/42] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9f34d5ec..3e8a670a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ ## Introducing BlueLibs +- [GitHub BlueLibs Monorepo](https://github.com/bluelibs/bluelibs) - Following the same bold vision of Meteor, but with a modern twist. www.bluelibs.com - Read more about our approach coming from Meteor: https://www.bluelibs.com/blog/2021/11/26/the-meteor-of-2022 - We've implemented [RedisOplog](https://www.bluelibs.com/docs/package-x-bundle#live-data) in our framework as well, but it also works with in-memory and with customisable pubsub, not bound to redis. From 9462164bdad150d091be374fb699a2e5024cdf9c Mon Sep 17 00:00:00 2001 From: Maxim Makarov Date: Sat, 16 Apr 2022 20:00:05 +0300 Subject: [PATCH 07/42] update tests packages --- package.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.js b/package.js index d447275b..1c7f8246 100644 --- a/package.js +++ b/package.js @@ -41,17 +41,17 @@ Package.onTest(function(api) { // extensions api.use('aldeed:collection2@3.0.0'); - api.use('reywood:publish-composite@1.5.2'); + api.use('reywood:publish-composite@1.7.3'); api.use('natestrauser:publish-performant-counts@0.1.2'); - api.use('socialize:user-presence@0.4.0'); + api.use('socialize:user-presence@1.0.4'); api.use('ecmascript'); api.use('tracker'); api.use('mongo'); api.use('random'); api.use('accounts-password'); - api.use('matb33:collection-hooks@0.8.4'); - api.use('alanning:roles@1.2.16'); + api.use('matb33:collection-hooks@1.1.2'); + api.use('alanning:roles@3.4.0'); api.use(['meteortesting:mocha']); From 77a39d512fe59a04e7128912e507881f3697de8c Mon Sep 17 00:00:00 2001 From: Maxim Makarov Date: Sat, 16 Apr 2022 20:03:03 +0300 Subject: [PATCH 08/42] import UserPresence explicitly in accounts test --- testing/accounts/server.js | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/accounts/server.js b/testing/accounts/server.js index dfc24925..7eb17028 100644 --- a/testing/accounts/server.js +++ b/testing/accounts/server.js @@ -1,4 +1,5 @@ import { Accounts } from 'meteor/accounts-base'; +import { UserPresence } from 'meteor/socialize:user-presence'; // UserPresence.onCleanup(function(){ // Meteor.users.update({}, {$unset:{status:true}}, {multi:true}); From 03090d9d8cb4e73198d8e5c1a2482c7c5019e983 Mon Sep 17 00:00:00 2001 From: Maxim Makarov Date: Sat, 16 Apr 2022 20:03:39 +0300 Subject: [PATCH 09/42] options.projection support --- docs/finetuning.md | 4 ++-- lib/cache/ObservableCollection.js | 26 +++++++++++++++---------- lib/mongo/Mutator.js | 1 + lib/mongo/RedisOplogObserveDriver.js | 6 ++++-- lib/mongo/allow-deny/validatedRemove.js | 2 ++ lib/mongo/allow-deny/validatedUpdate.js | 2 ++ lib/mongo/observeChanges.js | 9 +++++---- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/docs/finetuning.md b/docs/finetuning.md index 744931a1..babababe 100644 --- a/docs/finetuning.md +++ b/docs/finetuning.md @@ -188,11 +188,11 @@ Messages.configureRedisOplog({ } if (event === Events.REMOVE) { // If it performs a remove by _id (which is the most usual) - threadId = Messages.findOne({_id: selector._id}, {fields: {threadId: 1}}).threadId; + threadId = Messages.findOne({_id: selector._id}, {projection: {threadId: 1}}).threadId; } if (event === Events.UPDATE) { // If it performs an update by _id (which is the most usual) - threadId = Messages.findOne({_id: selector._id}, {fields: {threadId: 1}}).threadId; + threadId = Messages.findOne({_id: selector._id}, {projection: {threadId: 1}}).threadId; } options.namespace = `threads::${threadId}`; diff --git a/lib/cache/ObservableCollection.js b/lib/cache/ObservableCollection.js index 12e29094..3d0eca92 100644 --- a/lib/cache/ObservableCollection.js +++ b/lib/cache/ObservableCollection.js @@ -14,6 +14,7 @@ const allowedOptions = [ 'skip', 'sort', 'fields', + 'projection', 'channels', 'channel', 'namespace', @@ -89,26 +90,29 @@ export default class ObservableCollection { this.options = {}; } + var fields = this.options.projection || this.options.fields; + // check for empty projector object and delete. - if (this.options.fields && _.isEmpty(this.options.fields)) { + if (fields && _.isEmpty(fields)) { + delete this.options.projection; delete this.options.fields; } - if (this.options.fields) { - this.fieldsArray = _.keys(this.options.fields); + if (fields) { + this.fieldsArray = _.keys(fields); if (!_.isArray(this.fieldsArray)) { throw new Meteor.Error( - 'We could not properly extract any fields. "fields" must be an object. This was provided: ' + - JSON.stringify(this.options.fields) + 'We could not properly extract any fields. "projdction" or "fields" must be an object. This was provided: ' + + JSON.stringify(fields) ); } this.projectFieldsOnDoc = LocalCollection._compileProjection( - this.options.fields + fields ); this.isFieldsProjectionByExclusion = fieldProjectionIsExclusion( - this.options.fields + fields ); } @@ -116,7 +120,7 @@ export default class ObservableCollection { this.fieldsOfInterest = this._getFieldsOfInterest(); this.__isInitialized = false; - var projection = this.options.fields || {}; + var projection = fields || {}; this._projectionFn = LocalCollection._compileProjection(projection); // Projection function, result of combining important fields for selector and // existing fields projection @@ -153,7 +157,7 @@ export default class ObservableCollection { if (this.matcher) { return !!this.collection.findOne( _.extend({}, this.selector, { _id }), - { fields: { _id: 1 } } + { projection: { _id: 1 } } ); } @@ -308,7 +312,9 @@ export default class ObservableCollection { * @return {true|object} */ _getFieldsOfInterest() { - if (!this.options.fields) { + const fields = this.options.projection || this.options.fields; + + if (!fields) { return true; } diff --git a/lib/mongo/Mutator.js b/lib/mongo/Mutator.js index 78400e8b..94938ffe 100644 --- a/lib/mongo/Mutator.js +++ b/lib/mongo/Mutator.js @@ -337,6 +337,7 @@ export default class Mutator { if (shouldIncludePrevDocument(this)) { delete removeOptions.fields; + delete removeOptions.projection; } // TODO: optimization check if it has _id or _id with {$in} so we don't have to redo this. diff --git a/lib/mongo/RedisOplogObserveDriver.js b/lib/mongo/RedisOplogObserveDriver.js index a19f3742..97b45cbb 100644 --- a/lib/mongo/RedisOplogObserveDriver.js +++ b/lib/mongo/RedisOplogObserveDriver.js @@ -88,9 +88,11 @@ export default class RedisOplogObserveDriver { // If a fields projection option is given check if it is supported by // minimongo (some operators are not supported). - if (options.fields) { + var fields = options.projection || options.fields; + + if (fields) { try { - LocalCollection._checkSupportedProjection(options.fields); + LocalCollection._checkSupportedProjection(fields); } catch (e) { if (e.name === 'MinimongoError') { return false; diff --git a/lib/mongo/allow-deny/validatedRemove.js b/lib/mongo/allow-deny/validatedRemove.js index b04eeab6..6da505d6 100644 --- a/lib/mongo/allow-deny/validatedRemove.js +++ b/lib/mongo/allow-deny/validatedRemove.js @@ -7,8 +7,10 @@ export default function validatedRemove(userId, selector) { const findOptions = {transform: null} if (!this._validators.fetchAllFields) { findOptions.fields = {} + findOptions.projection = {} _.each(this._validators.fetch, fieldName => { findOptions.fields[fieldName] = 1 + findOptions.projection[fieldName] = 1 }) } diff --git a/lib/mongo/allow-deny/validatedUpdate.js b/lib/mongo/allow-deny/validatedUpdate.js index 1b93c8ab..2fbe9691 100644 --- a/lib/mongo/allow-deny/validatedUpdate.js +++ b/lib/mongo/allow-deny/validatedUpdate.js @@ -83,8 +83,10 @@ export default function validatedUpdate(userId, selector, mutator, options) { const findOptions = { transform: null }; if (!this._validators.fetchAllFields) { findOptions.fields = {}; + findOptions.projection = {}; _.each(this._validators.fetch, fieldName => { findOptions.fields[fieldName] = 1; + findOptions.projection[fieldName] = 1; }); } diff --git a/lib/mongo/observeChanges.js b/lib/mongo/observeChanges.js index 270d532d..159b47de 100644 --- a/lib/mongo/observeChanges.js +++ b/lib/mongo/observeChanges.js @@ -19,12 +19,13 @@ export default function(cursorDescription, ordered, callbacks) { // You may not filter out _id when observing changes, because the id is a core // part of the observeChanges API. + var fields = cursorDescription.options.projection || cursorDescription.options.fields; + if ( - cursorDescription.options.fields && - (cursorDescription.options.fields._id === 0 || - cursorDescription.options.fields._id === false) + fields && + (fields._id === 0 || fields._id === false) ) { - throw Error('You may not observe a cursor with {fields: {_id: 0}}'); + throw Error('You may not observe a cursor with {projection: {_id: 0}}'); } var observeKey = EJSON.stringify( From 070dbbeff9d330ec3a538cc52241a385a1382bc0 Mon Sep 17 00:00:00 2001 From: Maxim Makarov Date: Fri, 22 Apr 2022 11:10:58 +0300 Subject: [PATCH 10/42] fix typo and use fields for backward compatibility --- lib/cache/ObservableCollection.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cache/ObservableCollection.js b/lib/cache/ObservableCollection.js index 3d0eca92..4118d3b1 100644 --- a/lib/cache/ObservableCollection.js +++ b/lib/cache/ObservableCollection.js @@ -103,7 +103,7 @@ export default class ObservableCollection { if (!_.isArray(this.fieldsArray)) { throw new Meteor.Error( - 'We could not properly extract any fields. "projdction" or "fields" must be an object. This was provided: ' + + 'We could not properly extract any fields. "projection" or "fields" must be an object. This was provided: ' + JSON.stringify(fields) ); } @@ -157,7 +157,7 @@ export default class ObservableCollection { if (this.matcher) { return !!this.collection.findOne( _.extend({}, this.selector, { _id }), - { projection: { _id: 1 } } + { fields: { _id: 1 } } ); } From b031f02fd0ea8b53ad38517e50289543845813ed Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 23 Apr 2022 08:54:48 +0200 Subject: [PATCH 11/42] Update meta --- .github/FUNDING.yml | 1 + .gitignore | 3 ++- CHANGELOG.md | 6 +++++- package.js | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..fd630693 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [StorytellerCZ] diff --git a/.gitignore b/.gitignore index 9aaee737..0e70b81c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store dump.rdb -npm-debug.log \ No newline at end of file +npm-debug.log +.idea/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 89d12997..6573773d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGELOG +### 2.1.0 +- Projections option support +- Update Mocha tests + ### 1.2.3 - Redis connection failover handling - Refetching the up to date collection when Redis connection resumes @@ -29,4 +33,4 @@ ### 1.0.3 - Added support for publish composite -- Fixed randomly failing tests \ No newline at end of file +- Fixed randomly failing tests diff --git a/package.js b/package.js index 1c7f8246..1e2cda4f 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'cultofcoders:redis-oplog', - version: '2.0.5', + version: '2.1.0', // Brief, one-line summary of the package. summary: "Replacement for Meteor's MongoDB oplog implementation", // URL to the Git repository containing the source code for this package. From 1884b60c1ea8b70ae07de0c4e1cb9eda9362157d Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 23 Apr 2022 09:08:09 +0200 Subject: [PATCH 12/42] Update tests to Meteor 1.12.2 to fix certificates error --- .gitignore | 2 ++ .travis.yml | 4 ++-- CONTRIBUTING.md | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 0e70b81c..04913f99 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ dump.rdb npm-debug.log .idea/ + +test/ diff --git a/.travis.yml b/.travis.yml index ffee1a5b..119ae9cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ services: language: node_js node_js: - - "8.9.1" + - "12.20.1" before_install: - curl https://install.meteor.com | /bin/sh @@ -19,7 +19,7 @@ notifications: email: false script: - - meteor create --release 1.8.1 --bare test + - meteor create --release 1.12.2 --bare test - cd test - meteor npm i --save puppeteer@1.18.1 simpl-schema chai - METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a18b2a8b..d5584094 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,9 +28,9 @@ It is also always helpful to have some context for your pull request. What was t ### Setup ``` -meteor create --release 1.8.1 --bare test +meteor create --release 1.12.2 --bare test cd test -meteor npm i --save puppeteer@1.18.1 simpl-schema +meteor npm i --save puppeteer@1.18.1 simpl-schema chai ``` ### Start Tests @@ -78,4 +78,4 @@ Thank you to all our sponsors! (please ask your company to also support this ope - \ No newline at end of file + From 5b39487c684363362f2388df389c46682a4c6020 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 23 Apr 2022 09:11:26 +0200 Subject: [PATCH 13/42] changelog update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6573773d..a953e0f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### 2.1.0 - Projections option support - Update Mocha tests +- Update tests to use Meteor 1.12.2 to fix certificates issues ### 1.2.3 - Redis connection failover handling From 4859d7eb5a96d05513e468d97982aa65483b1a11 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 23 Apr 2022 09:24:22 +0200 Subject: [PATCH 14/42] Try GitHub actions for testing --- .github/workflows/test.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..8493b6b0 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: Tests + +on: [push] + +jobs: + test: + runs-on: ubuntu-20.04 + strategy: + matrix: + meteor: [1.12.2, 2.6.1] + redis-version: [4, 5, 6] + + steps: + - uses: actions/checkout@v1 + + - name: Start Redis + uses: supercharge/redis-github-action@1.4.0 + with: + redis-version: ${{ matrix.redis-version }} + + - name: Setup Meteor + uses: meteorengineer/setup-meteor@v1 + with: + meteor-release: ${{ matrix.meteor }} + - run: meteor create --release 1.12.2 --bare test + - run: cd test + - run: meteor npm i --save puppeteer@1.18.1 simpl-schema chai + - run: METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../ From 032d974e9b5bba63da26e60503b3fb11471edf73 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 23 Apr 2022 09:28:40 +0200 Subject: [PATCH 15/42] Update checkouts in GH actions --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8493b6b0..ac261e2f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: redis-version: [4, 5, 6] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - name: Start Redis uses: supercharge/redis-github-action@1.4.0 From 1e8ca60c3a41c1563c0a36981607a2a58111b1e5 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 23 Apr 2022 09:33:26 +0200 Subject: [PATCH 16/42] Try $GITHUB_WORKSPACE --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac261e2f..d57b5d25 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,4 +25,4 @@ jobs: - run: meteor create --release 1.12.2 --bare test - run: cd test - run: meteor npm i --save puppeteer@1.18.1 simpl-schema chai - - run: METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../ + - run: METEOR_PACKAGE_DIRS="$GITHUB_WORKSPACE" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha $GITHUB_WORKSPACE From cadc7432c5b5e935dcf7893f40ac6f41f2096a4a Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 23 Apr 2022 09:37:25 +0200 Subject: [PATCH 17/42] Better instruction for GH action --- .github/workflows/test.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d57b5d25..03cac3c3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,12 @@ jobs: uses: meteorengineer/setup-meteor@v1 with: meteor-release: ${{ matrix.meteor }} - - run: meteor create --release 1.12.2 --bare test - - run: cd test - - run: meteor npm i --save puppeteer@1.18.1 simpl-schema chai - - run: METEOR_PACKAGE_DIRS="$GITHUB_WORKSPACE" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha $GITHUB_WORKSPACE + - name: Setup tests + run: | + meteor create --release 1.12.2 --bare test + cd test + meteor npm i --save puppeteer@1.18.1 simpl-schema chai + - name: Test + run: | + cd test + METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../ From a46486604f31b27ebd8083f71521a4b4389846c4 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 23 Apr 2022 09:41:47 +0200 Subject: [PATCH 18/42] Final version of GH tests, remove Travis --- .github/workflows/test.yml | 5 ++--- .travis.yml | 25 ------------------------- 2 files changed, 2 insertions(+), 28 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 03cac3c3..3d824f66 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,6 +28,5 @@ jobs: cd test meteor npm i --save puppeteer@1.18.1 simpl-schema chai - name: Test - run: | - cd test - METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../ + working-directory: ./test + run: METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 119ae9cf..00000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -services: - - redis-server - -language: node_js - -node_js: - - "12.20.1" - -before_install: - - curl https://install.meteor.com | /bin/sh - - export PATH="$HOME/.meteor:$PATH" - -cache: - directories: - - $HOME/.npm - - $HOME/.meteor - -notifications: - email: false - -script: - - meteor create --release 1.12.2 --bare test - - cd test - - meteor npm i --save puppeteer@1.18.1 simpl-schema chai - - METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../ From 6642a1b3ab3b5cb71b4375f3b80a57587824e83d Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 23 Apr 2022 09:49:42 +0200 Subject: [PATCH 19/42] Test with correct Meteor version --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3d824f66..ab46b898 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: meteor-release: ${{ matrix.meteor }} - name: Setup tests run: | - meteor create --release 1.12.2 --bare test + meteor create --release ${{ matrix.meteor }} --bare test cd test meteor npm i --save puppeteer@1.18.1 simpl-schema chai - name: Test From 0370f57f14744085d67f39b8001192e5ed320c29 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 23 Apr 2022 09:50:51 +0200 Subject: [PATCH 20/42] Run tests on PR as well --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ab46b898..259ffeb0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: Tests -on: [push] +on: [push, pull_request] jobs: test: From 6731d7acde39649febea1dcd004c60d864f694ea Mon Sep 17 00:00:00 2001 From: Don Stephan Date: Sun, 25 Sep 2022 20:01:20 -0500 Subject: [PATCH 21/42] remove socialize:user-presence since it's not used anywhere --- package.js | 2 +- testing/accounts/server.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.js b/package.js index 1e2cda4f..9d9ba978 100644 --- a/package.js +++ b/package.js @@ -43,7 +43,7 @@ Package.onTest(function(api) { api.use('aldeed:collection2@3.0.0'); api.use('reywood:publish-composite@1.7.3'); api.use('natestrauser:publish-performant-counts@0.1.2'); - api.use('socialize:user-presence@1.0.4'); + // api.use('socialize:user-presence@1.0.4'); api.use('ecmascript'); api.use('tracker'); diff --git a/testing/accounts/server.js b/testing/accounts/server.js index 7eb17028..91e90038 100644 --- a/testing/accounts/server.js +++ b/testing/accounts/server.js @@ -1,12 +1,12 @@ import { Accounts } from 'meteor/accounts-base'; -import { UserPresence } from 'meteor/socialize:user-presence'; +// import { UserPresence } from 'meteor/socialize:user-presence'; // UserPresence.onCleanup(function(){ // Meteor.users.update({}, {$unset:{status:true}}, {multi:true}); // }); -UserPresence.onUserOnline(function(userId) { - Meteor.users.update({ _id: userId }, { $set: { status: 'online' } }); -}); +// UserPresence.onUserOnline(function(userId) { +// Meteor.users.update({ _id: userId }, { $set: { status: 'online' } }); +// }); // UserPresence.onUserIdle(function(userId){ // Meteor.users.update({_id:userId}, {$set:{status:"idle"}}) // }); From 04593d2a1404c7d45d8a8221eb7269e23cae4c30 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Thu, 29 Sep 2022 10:42:34 +0200 Subject: [PATCH 22/42] Add Meteor 2.7.3 to tests --- .github/workflows/test.yml | 2 +- CHANGELOG.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 259ffeb0..43988142 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - meteor: [1.12.2, 2.6.1] + meteor: [1.12.2, 2.6.1, 2.7.3] redis-version: [4, 5, 6] steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index a953e0f8..0b825c34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,14 @@ ## CHANGELOG ### 2.1.0 +- Meteor 2.6 support - Projections option support - Update Mocha tests - Update tests to use Meteor 1.12.2 to fix certificates issues ### 1.2.3 - Redis connection failover handling -- Refetching the up to date collection when Redis connection resumes +- Re-fetching the up-to-date collection when Redis connection resumes - Bug fixes and improvements ### 1.2.2 From acaf3f88284701b737da87f2efbf473a435286d0 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Thu, 29 Sep 2022 10:51:05 +0200 Subject: [PATCH 23/42] Published cultofcoders:redis-oplog@2.1.0 --- .meteorignore | 5 ++++ .versions | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 .meteorignore create mode 100644 .versions diff --git a/.meteorignore b/.meteorignore new file mode 100644 index 00000000..51621298 --- /dev/null +++ b/.meteorignore @@ -0,0 +1,5 @@ +.idea/ +.github/ +test/ +docs/ +testing/ diff --git a/.versions b/.versions new file mode 100644 index 00000000..884c3d2a --- /dev/null +++ b/.versions @@ -0,0 +1,68 @@ +accounts-base@2.2.4 +accounts-password@2.3.1 +alanning:roles@3.4.0 +aldeed:collection2@3.0.6 +allow-deny@1.1.1 +babel-compiler@7.9.2 +babel-runtime@1.5.1 +base64@1.0.12 +binary-heap@1.0.11 +boilerplate-generator@1.7.1 +callback-hook@1.4.0 +check@1.3.1 +cultofcoders:redis-oplog@2.1.0 +ddp@1.4.0 +ddp-client@2.5.0 +ddp-common@1.4.0 +ddp-rate-limiter@1.1.0 +ddp-server@2.5.0 +diff-sequence@1.1.1 +dynamic-import@0.7.2 +ecmascript@0.16.2 +ecmascript-runtime@0.8.0 +ecmascript-runtime-client@0.12.1 +ecmascript-runtime-server@0.11.0 +ejson@1.1.2 +email@2.2.1 +fetch@0.1.1 +geojson-utils@1.0.10 +id-map@1.1.1 +inter-process-messaging@0.1.1 +local-test:cultofcoders:redis-oplog@2.1.0 +localstorage@1.2.0 +logging@1.3.1 +matb33:collection-hooks@1.1.4 +meteor@1.10.0 +meteortesting:browser-tests@0.1.2 +meteortesting:mocha@0.4.4 +minimongo@1.8.0 +modern-browsers@0.1.8 +modules@0.18.0 +modules-runtime@0.13.0 +mongo@1.15.0 +mongo-decimal@0.1.3 +mongo-dev-server@1.1.0 +mongo-id@1.0.8 +natestrauser:publish-performant-counts@0.1.2 +npm-mongo@4.3.1 +ordered-dict@1.1.0 +practicalmeteor:mocha-core@1.0.1 +promise@0.12.0 +raix:eventemitter@0.1.3 +random@1.2.0 +rate-limit@1.0.9 +react-fast-refresh@0.2.3 +reactive-var@1.0.11 +reload@1.3.1 +retry@1.1.0 +reywood:publish-composite@1.7.3 +routepolicy@1.1.1 +service-configuration@1.3.0 +sha@1.0.9 +socket-stream-client@0.5.0 +tmeasday:check-npm-versions@0.3.2 +tracker@1.2.0 +underscore@1.0.10 +url@1.3.2 +webapp@1.13.1 +webapp-hashing@1.1.0 From 580412743fcf5980b23060bc41d8c73d33874d95 Mon Sep 17 00:00:00 2001 From: Arpee Ong Date: Thu, 6 Oct 2022 20:14:44 +0800 Subject: [PATCH 24/42] Fix for "callback is not a function error when using SyntheticMutator.update" --- lib/mongo/SyntheticMutator.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/mongo/SyntheticMutator.js b/lib/mongo/SyntheticMutator.js index 5c881fb8..34d50ae8 100644 --- a/lib/mongo/SyntheticMutator.js +++ b/lib/mongo/SyntheticMutator.js @@ -28,7 +28,7 @@ export default class SyntheticMutator { * @param data */ static insert(channels, data) { - channels = SyntheticMutator._extractChannels(channels); + channels = SyntheticMutator._extractChannels(channels, data._id); if (!data._id) { data._id = Random.id(); @@ -47,7 +47,7 @@ export default class SyntheticMutator { * @param modifier */ static update(channels, _id, modifier) { - channels = SyntheticMutator._extractChannels(channels); + channels = SyntheticMutator._extractChannels(channels, _id); if (!containsOperators(modifier)) { throw new Meteor.Error( @@ -73,7 +73,7 @@ export default class SyntheticMutator { * @param _id */ static remove(channels, _id) { - channels = SyntheticMutator._extractChannels(channels); + channels = SyntheticMutator._extractChannels(channels, _id); SyntheticMutator.publish(channels, { [RedisPipe.EVENT]: Events.REMOVE, @@ -94,8 +94,10 @@ export default class SyntheticMutator { const name = channels._name; channels = [name]; if (_id) { - channels.push(`${name}::${_id}`); + channels.push(`${name}::${_id}`); } + } else { + channels = [channels]; } channels = [channels]; From c2ef1ba15a54bfa96fbdcc2208f69646b0d97c74 Mon Sep 17 00:00:00 2001 From: Arpee Ong Date: Thu, 6 Oct 2022 20:24:01 +0800 Subject: [PATCH 25/42] Fix for "callback is not a function error when using SyntheticMutator.update" --- lib/mongo/SyntheticMutator.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/mongo/SyntheticMutator.js b/lib/mongo/SyntheticMutator.js index 34d50ae8..cd32fc7e 100644 --- a/lib/mongo/SyntheticMutator.js +++ b/lib/mongo/SyntheticMutator.js @@ -99,8 +99,6 @@ export default class SyntheticMutator { } else { channels = [channels]; } - - channels = [channels]; } return channels; From eae7809d910ffe7d4c94bd66451c41ec79f62634 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Fri, 7 Oct 2022 11:58:18 +0200 Subject: [PATCH 26/42] Prepare v2.1.1 release --- CHANGELOG.md | 3 +++ package.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b825c34..04d6e179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## CHANGELOG +### 2.1.1 +- Fixes callback is not a function error when using SyntheticMutator.update + ### 2.1.0 - Meteor 2.6 support - Projections option support diff --git a/package.js b/package.js index 9d9ba978..1272c84c 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'cultofcoders:redis-oplog', - version: '2.1.0', + version: '2.1.1', // Brief, one-line summary of the package. summary: "Replacement for Meteor's MongoDB oplog implementation", // URL to the Git repository containing the source code for this package. From 7b44f5c22b83e0eb87c5efa8365dedc7baaed4a0 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Fri, 7 Oct 2022 12:12:16 +0200 Subject: [PATCH 27/42] Published cultofcoders:redis-oplog@2.1.1 --- .versions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.versions b/.versions index 884c3d2a..12ac1f34 100644 --- a/.versions +++ b/.versions @@ -10,7 +10,7 @@ binary-heap@1.0.11 boilerplate-generator@1.7.1 callback-hook@1.4.0 check@1.3.1 -cultofcoders:redis-oplog@2.1.0 +cultofcoders:redis-oplog@2.1.1 ddp@1.4.0 ddp-client@2.5.0 ddp-common@1.4.0 @@ -28,7 +28,7 @@ fetch@0.1.1 geojson-utils@1.0.10 id-map@1.1.1 inter-process-messaging@0.1.1 -local-test:cultofcoders:redis-oplog@2.1.0 +local-test:cultofcoders:redis-oplog@2.1.1 localstorage@1.2.0 logging@1.3.1 matb33:collection-hooks@1.1.4 From fe0f6171ff1061ca21b55d62a68a2bd0e8ec75a6 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Fri, 7 Oct 2022 12:14:10 +0200 Subject: [PATCH 28/42] Start on v2.2.0 --- CHANGELOG.md | 2 ++ package.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04d6e179..2d982983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## CHANGELOG +### 2.2.0 + ### 2.1.1 - Fixes callback is not a function error when using SyntheticMutator.update diff --git a/package.js b/package.js index 1272c84c..97c523f6 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'cultofcoders:redis-oplog', - version: '2.1.1', + version: '2.2.0', // Brief, one-line summary of the package. summary: "Replacement for Meteor's MongoDB oplog implementation", // URL to the Git repository containing the source code for this package. From 700208092cc3b227f029c3f91e4fb338c420fc0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=BCster?= Date: Tue, 6 Dec 2022 12:25:19 +0100 Subject: [PATCH 29/42] feature(ci): add comment issue workflow --- .github/workflows/comment-issue.yml | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/comment-issue.yml diff --git a/.github/workflows/comment-issue.yml b/.github/workflows/comment-issue.yml new file mode 100644 index 00000000..f71d991e --- /dev/null +++ b/.github/workflows/comment-issue.yml @@ -0,0 +1,31 @@ +name: Add immediate comment on new issues + +on: + issues: + types: [opened] + +jobs: + createComment: + runs-on: ubuntu-latest + steps: + - name: Create Comment + uses: peter-evans/create-or-update-comment@v1.4.2 + with: + issue-number: ${{ github.event.issue.number }} + body: | + Thank you for submitting this issue! + + We, the Members of Meteor Community Packages take every issue seriously. + Our goal is to provide long-term lifecycles for packages and keep up + with the newest changes in Meteor and the overall NodeJs/JavaScript ecosystem. + + However, we contribute to these packages mostly in our free time. + Therefore, we can't guarantee you issues to be solved within certain time. + + If you think this issue is trivial to solve, don't hesitate to submit + a pull request, too! We will accompany you in the process with reviews and hints + on how to get development set up. + + Please also consider sponsoring the maintainers of the package. + If you don't know who is currently maintaining this package, just leave a comment + and we'll let you know From 507c53c72d541b6fa7be3b4adf01498b4d0bf931 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 12:37:33 +0200 Subject: [PATCH 30/42] Add some missing imports, remove needless underscore & formatting --- docs/failover.md | 4 ++-- lib/cache/ObservableCollection.js | 6 +++--- lib/cache/lib/extractFieldsFromFilters.js | 2 ++ lib/cache/lib/getChannels.js | 1 - lib/cache/lib/getSnapbackFields.js | 4 ++-- lib/init.js | 2 +- lib/mongo/Mutator.js | 8 +++++--- lib/mongo/ObserveMultiplex.js | 5 +++-- lib/mongo/PollingObserveDriver.js | 7 ++++--- lib/mongo/RedisOplogObserveDriver.js | 2 +- lib/mongo/SyntheticMutator.js | 2 +- lib/mongo/allow-deny/docToValidate.js | 2 +- lib/mongo/allow-deny/validatedInsert.js | 4 ++-- lib/mongo/allow-deny/validatedRemove.js | 4 ++-- lib/mongo/allow-deny/validatedUpdate.js | 6 +++--- lib/mongo/extendMongoCollection.js | 2 +- lib/mongo/extendObserveChanges.js | 7 ++----- lib/mongo/lib/getMutationConfig.js | 2 +- lib/mongo/mongoCollectionNames.js | 4 ++-- lib/mongo/observeChanges.js | 9 ++++----- lib/processors/actions/reload.js | 4 ++-- lib/processors/actions/requery.js | 1 - lib/processors/getStrategy.js | 3 +-- lib/processors/lib/fieldsExist.js | 6 ++---- lib/redis/RedisSubscriber.js | 1 - lib/redis/RedisSubscriptionManager.js | 2 +- lib/redis/getRedisClient.js | 9 ++++----- lib/utils/getFields.js | 10 ++++------ lib/utils/shouldPublicationBeWithPolling.js | 1 + lib/vent/Vent.js | 7 +++---- lib/vent/VentClient.js | 8 ++++---- testing/accounts/client.js | 3 +-- testing/accounts/server.js | 4 ++++ testing/boot.js | 12 ++++++------ testing/collection-defaults/client.js | 1 - testing/collection-defaults/collections.js | 4 +++- testing/collection-defaults/server.js | 1 + testing/custom-publications/client.js | 6 +++--- testing/custom-publications/collections.js | 2 +- testing/custom-publications/server.js | 5 +++-- testing/lib/helpers.js | 5 +++-- testing/lib/sync_utils.js | 5 ++++- testing/main.client.js | 10 +++++----- testing/object-id/server.js | 1 + testing/optimistic-ui/boot.js | 1 + testing/optimistic-ui/client.test.js | 12 ++++++------ testing/optimistic-ui/collections.js | 4 +++- testing/polling/server.js | 1 + testing/publish-counts/client.js | 1 - testing/publish-counts/collections.js | 6 ++---- testing/publish-counts/server.js | 5 +++-- testing/publishComposite/boot.js | 3 ++- testing/publishComposite/client.test.js | 6 +++--- testing/publishComposite/collections.js | 4 +++- testing/publishComposite/loadFixtures.js | 2 +- testing/server-autorun/client.js | 4 ++-- testing/server-autorun/collections.js | 8 +++----- testing/server-autorun/publication.js | 2 +- testing/server-autorun/server.js | 3 ++- testing/transformations/collections.js | 5 +++-- testing/transformations/server.js | 1 + testing/vent/boot.js | 6 +++--- testing/vent/client.js | 3 +-- 63 files changed, 140 insertions(+), 131 deletions(-) diff --git a/docs/failover.md b/docs/failover.md index 2d97dee0..ffa2a7b7 100644 --- a/docs/failover.md +++ b/docs/failover.md @@ -15,7 +15,7 @@ In order to configure these events, you can do it like this: // in a server-side file that is loaded on startup import { Config } from 'meteor/cultofcoders:redis-oplog'; -_.extend(Config.redisExtras.events, { +Object.assign(Config.redisExtras.events, { reconnect({delay, attempt, error}) { // put your logic here. }, @@ -30,4 +30,4 @@ _.extend(Config.redisExtras.events, { Since we have the logic of refreshing an observable collection, we can make it so it falls back to polling. But polling is very dangerous and very expensive, so we should avoid it at all costs, however this could be implemented and customized per collection, but honestly, your redis-server needs to have -high-availability, since it's a core component of your app. \ No newline at end of file +high-availability, since it's a core component of your app. diff --git a/lib/cache/ObservableCollection.js b/lib/cache/ObservableCollection.js index 4118d3b1..127171df 100644 --- a/lib/cache/ObservableCollection.js +++ b/lib/cache/ObservableCollection.js @@ -99,7 +99,7 @@ export default class ObservableCollection { } if (fields) { - this.fieldsArray = _.keys(fields); + this.fieldsArray = Object.keys(fields); if (!_.isArray(this.fieldsArray)) { throw new Meteor.Error( @@ -156,7 +156,7 @@ export default class ObservableCollection { isEligibleByDB(_id) { if (this.matcher) { return !!this.collection.findOne( - _.extend({}, this.selector, { _id }), + Object.assign({}, this.selector, { _id }), { fields: { _id: 1 } } ); } @@ -326,7 +326,7 @@ export default class ObservableCollection { // if we have options, we surely have fields array let fieldsArray = this.fieldsArray.slice(); - if (_.keys(this.selector).length > 0) { + if (Object.keys(this.selector).length > 0) { fieldsArray = _.union( fieldsArray, extractFieldsFromFilters(this.selector) diff --git a/lib/cache/lib/extractFieldsFromFilters.js b/lib/cache/lib/extractFieldsFromFilters.js index ffe8bd2d..11b089f1 100644 --- a/lib/cache/lib/extractFieldsFromFilters.js +++ b/lib/cache/lib/extractFieldsFromFilters.js @@ -1,3 +1,5 @@ +import { _ } from 'meteor/underscore'; + const deepFilterFieldsArray = ['$and', '$or', '$nor']; const deepFilterFieldsObject = ['$not']; diff --git a/lib/cache/lib/getChannels.js b/lib/cache/lib/getChannels.js index d229fba1..6159045a 100644 --- a/lib/cache/lib/getChannels.js +++ b/lib/cache/lib/getChannels.js @@ -1,4 +1,3 @@ -import { _ } from 'meteor/underscore'; import getChannelName from '../../utils/getChannelName'; export default (collectionName, {namespace, channel, namespaces, channels}) => { diff --git a/lib/cache/lib/getSnapbackFields.js b/lib/cache/lib/getSnapbackFields.js index 13182b55..8e113025 100644 --- a/lib/cache/lib/getSnapbackFields.js +++ b/lib/cache/lib/getSnapbackFields.js @@ -19,6 +19,6 @@ const isArray = (doc, parts) => { if (parts.length > 1) { return isArray(doc[parts[0]], parts.slice(1)); } else { - return _.isArray(doc[parts[0]]); + return Array.isArray(doc[parts[0]]); } -}; \ No newline at end of file +}; diff --git a/lib/init.js b/lib/init.js index 43122673..f56cd4e4 100644 --- a/lib/init.js +++ b/lib/init.js @@ -18,7 +18,7 @@ export default (config = {}) => { deepExtend(Config, config); - _.extend(Config, { + Object.assign(Config, { isInitialized: true, oldPublish: Meteor.publish, }); diff --git a/lib/mongo/Mutator.js b/lib/mongo/Mutator.js index 94938ffe..5808e8c4 100644 --- a/lib/mongo/Mutator.js +++ b/lib/mongo/Mutator.js @@ -1,3 +1,5 @@ +import { Meteor } from 'meteor/meteor'; +import { _ } from 'meteor/underscore'; import getMutationConfig from "./lib/getMutationConfig"; import getFields from "../utils/getFields"; import { @@ -163,7 +165,7 @@ export default class Mutator { // we need the exact _ids // and we extend the selector, because if between finding the docIds and updating // another matching insert sneaked in, it's update will not be pushed - const updateSelector = _.extend({}, selector, { + const updateSelector = Object.assign({}, selector, { _id: { $in: docIds } }); @@ -238,7 +240,7 @@ export default class Mutator { this, selector, modifier, - _.extend({}, config, { _returnObject: true }) + Object.assign({}, config, { _returnObject: true }) ); if (callback) { @@ -329,7 +331,7 @@ export default class Mutator { ); } - const removeSelector = _.extend({}, selector); + const removeSelector = Object.assign({}, selector); const removeOptions = { fields: { _id: 1 }, transform: null diff --git a/lib/mongo/ObserveMultiplex.js b/lib/mongo/ObserveMultiplex.js index 7a086974..53e0c103 100644 --- a/lib/mongo/ObserveMultiplex.js +++ b/lib/mongo/ObserveMultiplex.js @@ -2,6 +2,7 @@ // This code is MIT and licensed to Meteor. import { Meteor } from 'meteor/meteor'; +import { _ } from 'meteor/underscore'; import { LocalCollection } from 'meteor/minimongo'; import OptimisticInvocation from './OptimisticInvocation'; @@ -40,7 +41,7 @@ export function ObserveMultiplexer(options) { }); } -_.extend(ObserveMultiplexer.prototype, { +Object.assign(ObserveMultiplexer.prototype, { addHandleAndSendInitialAdds: function(handle) { var self = this; @@ -212,7 +213,7 @@ _.extend(ObserveMultiplexer.prototype, { // can continue until these are done. (But we do have to be careful to not // use a handle that got removed, because removeHandle does not use the // queue; thus, we iterate over an array of keys that we control.) - _.each(_.keys(self._handles), function(handleId) { + Object.keys(self._handles).forEach(function(handleId) { var handle = self._handles && self._handles[handleId]; if (!handle) return; var callback = handle['_' + callbackName]; diff --git a/lib/mongo/PollingObserveDriver.js b/lib/mongo/PollingObserveDriver.js index 1271079f..f2a6f1d0 100644 --- a/lib/mongo/PollingObserveDriver.js +++ b/lib/mongo/PollingObserveDriver.js @@ -1,3 +1,4 @@ +import { _ } from 'meteor/underscore'; import { LocalCollection } from 'meteor/minimongo'; function listenAll(cursorDescription, listenCallback) { @@ -28,7 +29,7 @@ function forEachTrigger(cursorDescription, triggerCallback) { if (specificIds) { _.each(specificIds, function(id) { triggerCallback( - _.extend( + Object.assign( { id: id, }, @@ -38,7 +39,7 @@ function forEachTrigger(cursorDescription, triggerCallback) { }); triggerCallback( - _.extend( + Object.assign( { dropCollection: true, id: null, @@ -141,7 +142,7 @@ export default function PollingObserveDriver(options) { ); } -_.extend(PollingObserveDriver.prototype, { +Object.assign(PollingObserveDriver.prototype, { // This is always called through _.throttle (except once at startup). _unthrottledEnsurePollIsScheduled: function() { var self = this; diff --git a/lib/mongo/RedisOplogObserveDriver.js b/lib/mongo/RedisOplogObserveDriver.js index 97b45cbb..11f45d99 100644 --- a/lib/mongo/RedisOplogObserveDriver.js +++ b/lib/mongo/RedisOplogObserveDriver.js @@ -46,7 +46,7 @@ export default class RedisOplogObserveDriver { let oc = this.observableCollection; if (oc.selector._id) { oc.__containsOtherSelectorsThanId = - _.keys(oc.selector).length > 1; + Object.keys(oc.selector).length > 1; } } diff --git a/lib/mongo/SyntheticMutator.js b/lib/mongo/SyntheticMutator.js index cd32fc7e..50c14e2a 100644 --- a/lib/mongo/SyntheticMutator.js +++ b/lib/mongo/SyntheticMutator.js @@ -89,7 +89,7 @@ export default class SyntheticMutator { * @private */ static _extractChannels(channels, _id) { - if (!_.isArray(channels)) { + if (!Array.isArray(channels)) { if (channels instanceof Mongo.Collection) { const name = channels._name; channels = [name]; diff --git a/lib/mongo/allow-deny/docToValidate.js b/lib/mongo/allow-deny/docToValidate.js index 517d95a3..2636685f 100644 --- a/lib/mongo/allow-deny/docToValidate.js +++ b/lib/mongo/allow-deny/docToValidate.js @@ -1,4 +1,4 @@ -import {EJSON} from 'meteor/ejson' +import { EJSON } from 'meteor/ejson' export default function docToValidate(validator, doc, generatedId) { let ret = doc diff --git a/lib/mongo/allow-deny/validatedInsert.js b/lib/mongo/allow-deny/validatedInsert.js index 5ec2da30..ed7a8df3 100644 --- a/lib/mongo/allow-deny/validatedInsert.js +++ b/lib/mongo/allow-deny/validatedInsert.js @@ -1,5 +1,5 @@ -import {Meteor} from 'meteor/meteor' -import {_} from 'meteor/underscore' +import { Meteor } from 'meteor/meteor' +import { _ } from 'meteor/underscore' import docToValidate from './docToValidate' export default function validatedInsert(userId, doc, generatedId) { diff --git a/lib/mongo/allow-deny/validatedRemove.js b/lib/mongo/allow-deny/validatedRemove.js index 6da505d6..f325b795 100644 --- a/lib/mongo/allow-deny/validatedRemove.js +++ b/lib/mongo/allow-deny/validatedRemove.js @@ -1,6 +1,6 @@ /* eslint no-param-reassign: 0 no-underscore-dangle: 0 */ -import {Meteor} from 'meteor/meteor' -import {_} from 'meteor/underscore' +import { Meteor } from 'meteor/meteor' +import { _ } from 'meteor/underscore' import transformDoc from './transformDoc' export default function validatedRemove(userId, selector) { diff --git a/lib/mongo/allow-deny/validatedUpdate.js b/lib/mongo/allow-deny/validatedUpdate.js index 2fbe9691..35f5f1e2 100644 --- a/lib/mongo/allow-deny/validatedUpdate.js +++ b/lib/mongo/allow-deny/validatedUpdate.js @@ -65,7 +65,7 @@ export default function validatedUpdate(userId, selector, mutator, options) { `Access denied. Operator ${op} not allowed in a restricted collection.` ); } else { - _.each(_.keys(params), field => { + Object.keys(params).forEach(field => { // treat dotted fields as if they are replacing their // top-level part if (field.indexOf('.') !== -1) { @@ -73,7 +73,7 @@ export default function validatedUpdate(userId, selector, mutator, options) { } // record the field we are trying to change - if (!_.contains(fields, field)) { + if (!fields.includes(field)) { fields.push(field); } }); @@ -126,7 +126,7 @@ export default function validatedUpdate(userId, selector, mutator, options) { this.update( selector, mutator, - _.extend(options, { + Object.assign(options, { optimistic: true, }) ); diff --git a/lib/mongo/extendMongoCollection.js b/lib/mongo/extendMongoCollection.js index b9bc6e20..15b84dc1 100644 --- a/lib/mongo/extendMongoCollection.js +++ b/lib/mongo/extendMongoCollection.js @@ -19,7 +19,7 @@ export default () => { extendObserveChanges(); - _.extend(Mongo.Collection.prototype, { + Object.assign(Mongo.Collection.prototype, { /** * @param data * @param config diff --git a/lib/mongo/extendObserveChanges.js b/lib/mongo/extendObserveChanges.js index c9f1d571..c3966ea2 100644 --- a/lib/mongo/extendObserveChanges.js +++ b/lib/mongo/extendObserveChanges.js @@ -1,10 +1,7 @@ -import { DDP } from 'meteor/ddp'; -import { Mongo, MongoInternals } from 'meteor/mongo'; -import { LocalCollection } from 'meteor/minimongo'; -import { Random } from 'meteor/random'; +import { MongoInternals } from 'meteor/mongo'; import observeChanges from './observeChanges'; -const MongoCursor = Object.getPrototypeOf( +export const MongoCursor = Object.getPrototypeOf( MongoInternals.defaultRemoteCollectionDriver().mongo.find() ).constructor; diff --git a/lib/mongo/lib/getMutationConfig.js b/lib/mongo/lib/getMutationConfig.js index 467b5ebe..0a3cb78a 100644 --- a/lib/mongo/lib/getMutationConfig.js +++ b/lib/mongo/lib/getMutationConfig.js @@ -24,7 +24,7 @@ export default function (collection, _config, mutationObject) { defaultOverrides.optimistic = false; } - let config = _.extend({}, Config.mutationDefaults, defaultOverrides, _config); + let config = Object.assign({}, Config.mutationDefaults, defaultOverrides, _config); if (collection._redisOplog) { const {mutation} = collection._redisOplog; diff --git a/lib/mongo/mongoCollectionNames.js b/lib/mongo/mongoCollectionNames.js index 99a4d823..1a6cea6b 100644 --- a/lib/mongo/mongoCollectionNames.js +++ b/lib/mongo/mongoCollectionNames.js @@ -4,7 +4,7 @@ const constructor = Mongo.Collection; const proto = Mongo.Collection.prototype; const hook = function() { - var ret = constructor.apply(this, arguments); + let ret = constructor.apply(this, arguments); map[arguments[0]] = this; return ret; }; @@ -16,7 +16,7 @@ hook.__getCollectionByName = function (name) { hook.prototype = proto; hook.prototype.constructor = hook; -for (var prop in constructor) { +for (let prop in constructor) { if (constructor.hasOwnProperty(prop)) { hook[prop] = constructor[prop]; } diff --git a/lib/mongo/observeChanges.js b/lib/mongo/observeChanges.js index 159b47de..84a15781 100644 --- a/lib/mongo/observeChanges.js +++ b/lib/mongo/observeChanges.js @@ -1,13 +1,12 @@ // This code was started based on meteor/meteor github repository // This code is MIT and licensed to Meteor. - +import { _ } from 'meteor/underscore'; import RedisOplogObserveDriver from './RedisOplogObserveDriver'; -import { MongoInternals } from 'meteor/mongo'; import { ObserveMultiplexer, ObserveHandle } from './ObserveMultiplex'; import PollingObserveDriver from './PollingObserveDriver'; export default function(cursorDescription, ordered, callbacks) { - var self = this; + const self = this; if (cursorDescription.options.tailable) { return self._observeChangesTailable( cursorDescription, @@ -19,7 +18,7 @@ export default function(cursorDescription, ordered, callbacks) { // You may not filter out _id when observing changes, because the id is a core // part of the observeChanges API. - var fields = cursorDescription.options.projection || cursorDescription.options.fields; + const fields = cursorDescription.options.projection || cursorDescription.options.fields; if ( fields && @@ -29,7 +28,7 @@ export default function(cursorDescription, ordered, callbacks) { } var observeKey = EJSON.stringify( - _.extend( + Object.assign( { ordered: ordered, }, diff --git a/lib/processors/actions/reload.js b/lib/processors/actions/reload.js index 2105404a..49f9a305 100644 --- a/lib/processors/actions/reload.js +++ b/lib/processors/actions/reload.js @@ -1,4 +1,4 @@ -import {_} from 'meteor/underscore'; +import { _ } from 'meteor/underscore'; import { MongoIDMap } from '../../cache/mongoIdMap'; /** @@ -17,7 +17,7 @@ export default function (observableCollection) { store.compareWith(newStore, { both(docId, oldDoc, newDoc) { - const modifiedFields = _.union(_.keys(oldDoc), _.keys(newDoc)); + const modifiedFields = _.union(Object.keys(oldDoc), Object.keys(newDoc)); observableCollection.change(newDoc, modifiedFields); }, leftOnly(docId) { diff --git a/lib/processors/actions/requery.js b/lib/processors/actions/requery.js index e23b311e..78b00f25 100644 --- a/lib/processors/actions/requery.js +++ b/lib/processors/actions/requery.js @@ -1,4 +1,3 @@ -import { _ } from 'meteor/underscore'; import { EJSON } from 'meteor/ejson'; import { Events } from '../../constants'; import { MongoIDMap } from '../../cache/mongoIdMap'; diff --git a/lib/processors/getStrategy.js b/lib/processors/getStrategy.js index f99724d3..6170e3b1 100644 --- a/lib/processors/getStrategy.js +++ b/lib/processors/getStrategy.js @@ -1,5 +1,4 @@ import { Strategy } from '../constants'; -import { _ } from 'meteor/underscore'; /** * @param selector @@ -21,4 +20,4 @@ export default function getStrategy(selector = {}, options = {}) { } return Strategy.DEFAULT; -} \ No newline at end of file +} diff --git a/lib/processors/lib/fieldsExist.js b/lib/processors/lib/fieldsExist.js index cbf313ad..f96ee43a 100644 --- a/lib/processors/lib/fieldsExist.js +++ b/lib/processors/lib/fieldsExist.js @@ -1,11 +1,9 @@ -import { _ } from 'meteor/underscore'; - /** * @param fieldsObject {Object} {"profile.firstName": 1, "roles": 1, "something": 1 } * @param fieldsArray {Array} ["profile", "roles.xx", "something" ] */ export function hasSortFields(fieldsObject, fieldsArray) { - const existingFields = _.keys(fieldsObject); + const existingFields = Object.keys(fieldsObject); for (let i = 0 ; i < fieldsArray.length ; i++) { const field = fieldsArray[i]; @@ -21,4 +19,4 @@ export function hasSortFields(fieldsObject, fieldsArray) { } return false; -} \ No newline at end of file +} diff --git a/lib/redis/RedisSubscriber.js b/lib/redis/RedisSubscriber.js index e2791ea7..8e10348f 100644 --- a/lib/redis/RedisSubscriber.js +++ b/lib/redis/RedisSubscriber.js @@ -1,6 +1,5 @@ import { Strategy } from '../constants'; import { getProcessor } from '../processors'; -import { _ } from 'meteor/underscore'; import { Meteor } from 'meteor/meteor'; import extractIdsFromSelector from '../utils/extractIdsFromSelector'; import RedisSubscriptionManager from './RedisSubscriptionManager'; diff --git a/lib/redis/RedisSubscriptionManager.js b/lib/redis/RedisSubscriptionManager.js index 5ced6f27..08aa1131 100644 --- a/lib/redis/RedisSubscriptionManager.js +++ b/lib/redis/RedisSubscriptionManager.js @@ -24,7 +24,7 @@ class RedisSubscriptionManager { */ getAllRedisSubscribers() { let redisSubscribers = []; - for (channel in this.store) { + for (let channel in this.store) { this.store[channel].forEach(_redisSubscriber => redisSubscribers.push(_redisSubscriber) ); diff --git a/lib/redis/getRedisClient.js b/lib/redis/getRedisClient.js index 4bf2ecad..cda5a07c 100644 --- a/lib/redis/getRedisClient.js +++ b/lib/redis/getRedisClient.js @@ -1,7 +1,6 @@ import redis from 'redis'; import Config from '../config'; -import { _ } from 'meteor/underscore'; -import {Meteor} from 'meteor/meteor'; +import { Meteor } from 'meteor/meteor'; // Redis requires two connections for pushing and listening to data let redisPusher; @@ -14,7 +13,7 @@ let redisListener; */ export function getRedisPusher() { if (!redisPusher) { - redisPusher = redis.createClient(_.extend({}, Config.redis, { + redisPusher = redis.createClient(Object.assign({}, Config.redis, { retry_strategy: getRetryStrategy() })); } @@ -30,7 +29,7 @@ export function getRedisPusher() { */ export function getRedisListener({onConnect} = {}) { if (!redisListener) { - redisListener = redis.createClient(_.extend({}, Config.redis, { + redisListener = redis.createClient(Object.assign({}, Config.redis, { retry_strategy: getRetryStrategy() })); @@ -71,4 +70,4 @@ function getRetryStrategy() { return Config.redisExtras.retry_strategy(...args); } } -} \ No newline at end of file +} diff --git a/lib/utils/getFields.js b/lib/utils/getFields.js index ffec25ae..2457c0c7 100644 --- a/lib/utils/getFields.js +++ b/lib/utils/getFields.js @@ -1,7 +1,5 @@ -import { _ } from 'meteor/underscore'; - /** - * Taken from: https://github.com/matb33/meteor-collection-hooks/blob/master/collection-hooks.js#L198 and modified. + * Taken from: https://github.com/Meteor-Community-Packages/meteor-collection-hooks/blob/master/collection-hooks.js#L194 and modified. * @param mutator */ export default function getFields(mutator) { @@ -9,11 +7,11 @@ export default function getFields(mutator) { var fields = []; var topLevelFields = []; - _.each(mutator, function (params, op) { + Object.entries(mutator).forEach(function ([op, params]) { if (op[0] == '$') { - _.each(_.keys(params), function (field) { + Object.keys(params).forEach(function (field) { // record the field we are trying to change - if (!_.contains(fields, field)) { + if (!fields.includes(field)) { // fields.push(field); // topLevelFields.push(field.split('.')[0]); diff --git a/lib/utils/shouldPublicationBeWithPolling.js b/lib/utils/shouldPublicationBeWithPolling.js index 5ffec9e1..b76e507a 100644 --- a/lib/utils/shouldPublicationBeWithPolling.js +++ b/lib/utils/shouldPublicationBeWithPolling.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { _ } from 'meteor/underscore'; export default function(cursors) { let isDisabledOplog = undefined; diff --git a/lib/vent/Vent.js b/lib/vent/Vent.js index 5ed7aaa6..8e5d5c6e 100644 --- a/lib/vent/Vent.js +++ b/lib/vent/Vent.js @@ -1,7 +1,6 @@ -import {getRedisListener, getRedisPusher} from '../redis/getRedisClient'; -import {VentConstants} from '../constants'; -import {Meteor} from 'meteor/meteor'; -import {Random} from 'meteor/random'; +import { VentConstants } from '../constants'; +import { Meteor } from 'meteor/meteor'; +import { _ } from 'meteor/underscore'; import Config from '../config'; // TODO: diff --git a/lib/vent/VentClient.js b/lib/vent/VentClient.js index c2e57437..21304d84 100644 --- a/lib/vent/VentClient.js +++ b/lib/vent/VentClient.js @@ -1,6 +1,6 @@ -import {VentConstants} from '../constants'; -import {Random} from 'meteor/random'; -import {DDPCommon} from 'meteor/ddp-common'; +import { VentConstants } from '../constants'; +import { Random } from 'meteor/random'; +import { DDPCommon } from 'meteor/ddp-common'; /** * Handles vents inside Meteor @@ -104,4 +104,4 @@ class VentClientSubscription { } } -} \ No newline at end of file +} diff --git a/testing/accounts/client.js b/testing/accounts/client.js index 762624f1..311a2aef 100644 --- a/testing/accounts/client.js +++ b/testing/accounts/client.js @@ -1,6 +1,5 @@ import { assert } from 'chai'; -import {Meteor} from 'meteor/meteor'; -import { DDP } from 'meteor/ddp-client'; +import { Meteor } from 'meteor/meteor'; describe('Testing accounts functionality', function () { it('Should properly subscribe and login', function (done) { diff --git a/testing/accounts/server.js b/testing/accounts/server.js index 91e90038..ea3922e1 100644 --- a/testing/accounts/server.js +++ b/testing/accounts/server.js @@ -1,4 +1,8 @@ import { Accounts } from 'meteor/accounts-base'; +import { Random } from 'meteor/random'; +import { Meteor } from 'meteor/meteor' +import { Roles } from 'meteor/alanning:roles' + // import { UserPresence } from 'meteor/socialize:user-presence'; // UserPresence.onCleanup(function(){ diff --git a/testing/boot.js b/testing/boot.js index d6b70de5..b68373c7 100644 --- a/testing/boot.js +++ b/testing/boot.js @@ -64,18 +64,18 @@ if (Meteor.isServer) { filters, options ) { - return Collection.find(filters, _.extend({}, options, opts[key])); + return Collection.find(filters, Object.assign({}, options, opts[key])); }); Meteor.methods({ [`create.${config[key].suffix}`](item, options = {}) { if (_.isArray(item)) { return _.map(item, i => - Collection.insert(i, _.extend(options, opts[key])) + Collection.insert(i, Object.assign(options, opts[key])) ); } - return Collection.insert(item, _.extend(options, opts[key])); + return Collection.insert(item, Object.assign(options, opts[key])); }, [`fetch.${config[key].suffix}`](selector = {}, options = {}) { return Collection.find(selector, options).fetch(); @@ -84,20 +84,20 @@ if (Meteor.isServer) { return Collection.update( selectors, modifier, - _.extend({}, opts[key], options) + Object.assign({}, opts[key], options) ); }, [`upsert.${config[key].suffix}`](selectors, modifier, options) { return Collection.upsert( selectors, modifier, - _.extend({}, opts[key], options) + Object.assign({}, opts[key], options) ); }, [`remove.${config[key].suffix}`](selectors, options = {}) { return Collection.remove( selectors, - _.extend(options, opts[key]) + Object.assign(options, opts[key]) ); }, [`synthetic.${config[key].suffix}`]( diff --git a/testing/collection-defaults/client.js b/testing/collection-defaults/client.js index 2c775500..b6895240 100644 --- a/testing/collection-defaults/client.js +++ b/testing/collection-defaults/client.js @@ -1,6 +1,5 @@ import { assert } from 'chai'; import { Items } from './collections'; -import { _ } from 'meteor/underscore'; import { waitForHandleToBeReady, callWithPromise } from '../lib/sync_utils'; import { Random } from 'meteor/random'; diff --git a/testing/collection-defaults/collections.js b/testing/collection-defaults/collections.js index 918c4d04..c68b6117 100644 --- a/testing/collection-defaults/collections.js +++ b/testing/collection-defaults/collections.js @@ -1,5 +1,7 @@ +import { Mongo } from 'meteor/mongo' + const Items = new Mongo.Collection('collection_defaults_items'); export { Items -} \ No newline at end of file +} diff --git a/testing/collection-defaults/server.js b/testing/collection-defaults/server.js index a7b4b897..39283747 100644 --- a/testing/collection-defaults/server.js +++ b/testing/collection-defaults/server.js @@ -1,3 +1,4 @@ +import { Meteor } from 'meteor/meteor' import { Items } from './collections'; if (Meteor.isServer) { diff --git a/testing/custom-publications/client.js b/testing/custom-publications/client.js index 7a24e8af..230624fc 100644 --- a/testing/custom-publications/client.js +++ b/testing/custom-publications/client.js @@ -1,7 +1,7 @@ import { assert } from 'chai'; -import {Items} from './collections'; -import {Meteor} from 'meteor/meteor'; -import {Counter} from 'meteor/natestrauser:publish-performant-counts' +import { Items } from './collections'; +import { Meteor } from 'meteor/meteor'; +// import {Counter} from 'meteor/natestrauser:publish-performant-counts' describe('Testing custom publications functionality', function () { it('Should be able to retrieve the correct number', function (done) { diff --git a/testing/custom-publications/collections.js b/testing/custom-publications/collections.js index 78979234..f985b16c 100644 --- a/testing/custom-publications/collections.js +++ b/testing/custom-publications/collections.js @@ -1,4 +1,4 @@ -import {Mongo} from 'meteor/mongo'; +import { Mongo } from 'meteor/mongo'; const Items = new Mongo.Collection('custom_publication_items'); diff --git a/testing/custom-publications/server.js b/testing/custom-publications/server.js index 29775f1e..584d474b 100644 --- a/testing/custom-publications/server.js +++ b/testing/custom-publications/server.js @@ -1,4 +1,5 @@ -import {Items} from './collections'; +import { Meteor } from 'meteor/meteor'; +import { Items } from './collections'; Meteor.publish('custom_publications', function () { const cursor = Items.find(); @@ -17,4 +18,4 @@ Meteor.methods({ Items.insert({name: 'Item 2'}); Items.insert({name: 'Item 3'}); } -}); \ No newline at end of file +}); diff --git a/testing/lib/helpers.js b/testing/lib/helpers.js index 847573fc..d52fc836 100644 --- a/testing/lib/helpers.js +++ b/testing/lib/helpers.js @@ -1,4 +1,5 @@ -import {waitForHandleToBeReady, callWithPromise} from './sync_utils'; +import { Meteor } from 'meteor/meteor'; +import { waitForHandleToBeReady, callWithPromise } from './sync_utils'; export default (suffix) => { const create = (...args) => { @@ -69,4 +70,4 @@ export default (suffix) => { syntheticSync, waitForHandleToBeReady } -} \ No newline at end of file +} diff --git a/testing/lib/sync_utils.js b/testing/lib/sync_utils.js index 9fe776d9..bcb98d7f 100644 --- a/testing/lib/sync_utils.js +++ b/testing/lib/sync_utils.js @@ -1,3 +1,6 @@ +import { Meteor } from 'meteor/meteor'; +import { Tracker } from 'meteor/tracker'; + const callWithPromise = (method, ...args) => { return new Promise((resolve, reject) => { Meteor.call(method, ...args, (err, res) => { @@ -22,4 +25,4 @@ const waitForHandleToBeReady = handle => { }); }; -export { callWithPromise, waitForHandleToBeReady }; \ No newline at end of file +export { callWithPromise, waitForHandleToBeReady }; diff --git a/testing/main.client.js b/testing/main.client.js index 61f5f662..7ce6b9d0 100644 --- a/testing/main.client.js +++ b/testing/main.client.js @@ -165,8 +165,8 @@ _.each(Collections, (Collection, key) => { assert.equal(doc.nested.c.b, 1); assert.equal(doc.nested.c.a, 1); assert.equal(doc.nested.d, 1); - assert.lengthOf(_.keys(doc), 1); - assert.lengthOf(_.keys(doc.nested), 4); + assert.lengthOf(Object.keys(doc), 1); + assert.lengthOf(Object.keys(doc.nested), 4); remove({ _id: docId }, () => { done(); @@ -355,7 +355,7 @@ _.each(Collections, (Collection, key) => { changed(docId, doc) { assert.equal(docId, _id); doc.bom.forEach(element => { - assert.isTrue(_.keys(element).length === 2); + assert.isTrue(Object.keys(element).length === 2); if (element.stockId === 1) { assert.equal(element.quantity, 30); } else { @@ -1100,7 +1100,7 @@ _.each(Collections, (Collection, key) => { const observer = cursor.observeChanges({ added(docId, doc) { assert.isUndefined(doc.something); - assert.isTrue(_.keys(doc).length == 1); + assert.isTrue(Object.keys(doc).length == 1); update( { _id: docId }, { @@ -1399,4 +1399,4 @@ _.each(Collections, (Collection, key) => { }); }); }); -}); \ No newline at end of file +}); diff --git a/testing/object-id/server.js b/testing/object-id/server.js index d5dd0ae3..afb62664 100644 --- a/testing/object-id/server.js +++ b/testing/object-id/server.js @@ -1,3 +1,4 @@ +import { Meteor } from 'meteor/meteor'; import { SmartIds } from './collections'; Meteor.publish('smart_ids', function(filters = {}) { diff --git a/testing/optimistic-ui/boot.js b/testing/optimistic-ui/boot.js index d3066847..cfb963da 100644 --- a/testing/optimistic-ui/boot.js +++ b/testing/optimistic-ui/boot.js @@ -1,3 +1,4 @@ +import { Meteor } from 'meteor/meteor'; import { Items } from './collections'; if (Meteor.isServer) { diff --git a/testing/optimistic-ui/client.test.js b/testing/optimistic-ui/client.test.js index 2480e25d..f4f5b15e 100644 --- a/testing/optimistic-ui/client.test.js +++ b/testing/optimistic-ui/client.test.js @@ -1,6 +1,6 @@ +import { Meteor } from 'meteor/meteor'; import { assert } from 'chai'; import { Items } from './collections'; -import { _ } from 'meteor/underscore'; import { waitForHandleToBeReady, callWithPromise } from '../lib/sync_utils'; import { Random } from 'meteor/random'; import './boot'; @@ -26,7 +26,7 @@ describe('Optimistic UI', () => { } assert.lengthOf(doc.liked, 2); - assert.isTrue(_.contains(doc.liked, 'XXX')); + assert.isTrue(doc.liked.includes('XXX')); setTimeout(() => { handle.stop(); @@ -36,7 +36,7 @@ describe('Optimistic UI', () => { }, }); - const item = _.first(cursor.fetch()); + const item = cursor.fetch()[0]; assert.isObject(item); Meteor.call('optimistic_ui.items.update', item._id, { @@ -69,7 +69,7 @@ describe('Optimistic UI', () => { } assert.lengthOf(doc.liked, 2); - assert.isTrue(_.contains(doc.liked, 'XXX')); + assert.isTrue(doc.liked.includes('XXX')); setTimeout(() => { handle.stop(); @@ -79,7 +79,7 @@ describe('Optimistic UI', () => { }, }); - const item = _.first(cursor.fetch()); + const item = cursor.fetch()[0]; assert.isObject(item); Items.update(item._id, { @@ -89,4 +89,4 @@ describe('Optimistic UI', () => { }); }); }); -}); \ No newline at end of file +}); diff --git a/testing/optimistic-ui/collections.js b/testing/optimistic-ui/collections.js index 8da4e384..7649fe26 100644 --- a/testing/optimistic-ui/collections.js +++ b/testing/optimistic-ui/collections.js @@ -1,5 +1,7 @@ +import { Mongo } from 'meteor/mongo'; + const Items = new Mongo.Collection('optimistic_ui_items'); export { Items -} \ No newline at end of file +} diff --git a/testing/polling/server.js b/testing/polling/server.js index bbc6f061..09a23a11 100644 --- a/testing/polling/server.js +++ b/testing/polling/server.js @@ -1,3 +1,4 @@ +import { Meteor } from 'meteor/meteor'; import { Campaigns } from './collections'; Meteor.publish('campaign_search', function(search, pollingIntervalMs = 100) { diff --git a/testing/publish-counts/client.js b/testing/publish-counts/client.js index dcb613a1..b2124100 100644 --- a/testing/publish-counts/client.js +++ b/testing/publish-counts/client.js @@ -1,5 +1,4 @@ import { assert } from 'chai'; -import {Items} from './collections'; import {Meteor} from 'meteor/meteor'; import {Counter} from 'meteor/natestrauser:publish-performant-counts' diff --git a/testing/publish-counts/collections.js b/testing/publish-counts/collections.js index a918f9a9..d6aaa6ce 100644 --- a/testing/publish-counts/collections.js +++ b/testing/publish-counts/collections.js @@ -1,5 +1,3 @@ -import {Mongo} from 'meteor/mongo'; +import { Mongo } from 'meteor/mongo'; -const Items = new Mongo.Collection('performant_counts_items'); - -export {Items} +export const Items = new Mongo.Collection('performant_counts_items'); diff --git a/testing/publish-counts/server.js b/testing/publish-counts/server.js index 1b217eda..2ac113b3 100644 --- a/testing/publish-counts/server.js +++ b/testing/publish-counts/server.js @@ -1,5 +1,6 @@ +import { Meteor } from 'meteor/meteor'; import { Counter } from 'meteor/natestrauser:publish-performant-counts' -import {Items} from './collections'; +import { Items } from './collections'; Meteor.publish('performant_counts', function () { return new Counter( @@ -20,4 +21,4 @@ Meteor.methods({ 'performant_counts_add'() { Items.insert({name: 'Item'}); } -}); \ No newline at end of file +}); diff --git a/testing/publishComposite/boot.js b/testing/publishComposite/boot.js index f43c64fb..3f57b224 100644 --- a/testing/publishComposite/boot.js +++ b/testing/publishComposite/boot.js @@ -1,3 +1,4 @@ +import { Meteor } from 'meteor/meteor'; import { Items, Children } from './collections'; import loadFixtures from './loadFixtures'; @@ -50,4 +51,4 @@ Meteor.methods({ 'publish_composite.children.remove'(...args) { return Children.remove(...args) } -}); \ No newline at end of file +}); diff --git a/testing/publishComposite/client.test.js b/testing/publishComposite/client.test.js index 4342bdbf..c50ff43b 100644 --- a/testing/publishComposite/client.test.js +++ b/testing/publishComposite/client.test.js @@ -1,6 +1,6 @@ +import { Meteor } from 'meteor/meteor'; import { assert } from 'chai'; import { Items, Children } from './collections'; -import { _ } from 'meteor/underscore'; import { waitForHandleToBeReady, callWithPromise } from '../lib/sync_utils'; describe('Publish Composite', () => { @@ -21,7 +21,7 @@ describe('Publish Composite', () => { } }); - const item = _.first(cursor.fetch()); + const item = cursor.fetch()[0]; assert.isObject(item); const childCursor = Children.find({ itemId: item._id }); @@ -41,4 +41,4 @@ describe('Publish Composite', () => { }); }); }) -}); \ No newline at end of file +}); diff --git a/testing/publishComposite/collections.js b/testing/publishComposite/collections.js index 8115835f..6c1619a3 100644 --- a/testing/publishComposite/collections.js +++ b/testing/publishComposite/collections.js @@ -1,7 +1,9 @@ +import { Mongo } from 'meteor/mongo'; + const Items = new Mongo.Collection('publish_composition'); const Children = new Mongo.Collection('publish_composition_children'); export { Items, Children -} \ No newline at end of file +} diff --git a/testing/publishComposite/loadFixtures.js b/testing/publishComposite/loadFixtures.js index ff8eba22..f7428877 100644 --- a/testing/publishComposite/loadFixtures.js +++ b/testing/publishComposite/loadFixtures.js @@ -1,4 +1,4 @@ -import {Items, Children} from './collections'; +import { Items, Children } from './collections'; const ITEMS = 5; const CHILDREN_PER_ITEM = 5; diff --git a/testing/server-autorun/client.js b/testing/server-autorun/client.js index 9c968655..4d5610fd 100644 --- a/testing/server-autorun/client.js +++ b/testing/server-autorun/client.js @@ -1,6 +1,6 @@ import { assert } from 'chai'; -import {Orders, Items} from './collections'; -import {Meteor} from 'meteor/meteor'; +import { Orders, Items } from './collections'; +import { Meteor } from 'meteor/meteor'; describe('Testing autorun functionality', function () { it('Should be able to subscribe', function (done) { diff --git a/testing/server-autorun/collections.js b/testing/server-autorun/collections.js index 9c10c885..91a27020 100644 --- a/testing/server-autorun/collections.js +++ b/testing/server-autorun/collections.js @@ -1,6 +1,4 @@ -import {Mongo} from 'meteor/mongo'; +import { Mongo } from 'meteor/mongo'; -const Items = new Mongo.Collection('autorun_test_items'); -const Orders = new Mongo.Collection('autorun_test_orders'); - -export {Orders, Items} +export const Items = new Mongo.Collection('autorun_test_items'); +export const Orders = new Mongo.Collection('autorun_test_orders'); diff --git a/testing/server-autorun/publication.js b/testing/server-autorun/publication.js index 62f00502..e005457d 100644 --- a/testing/server-autorun/publication.js +++ b/testing/server-autorun/publication.js @@ -1 +1 @@ -import {Orders, Items} from './collections'; +import { Orders, Items } from './collections'; diff --git a/testing/server-autorun/server.js b/testing/server-autorun/server.js index 186f0b6e..96d8d4d5 100644 --- a/testing/server-autorun/server.js +++ b/testing/server-autorun/server.js @@ -1,4 +1,5 @@ -import {Orders, Items} from './collections'; +import { Meteor } from 'meteor/meteor'; +import { Orders, Items } from './collections'; import './publication'; diff --git a/testing/transformations/collections.js b/testing/transformations/collections.js index c227edfb..8be541cf 100644 --- a/testing/transformations/collections.js +++ b/testing/transformations/collections.js @@ -1,4 +1,5 @@ -import {Mongo} from 'meteor/mongo'; +import { Meteor } from 'meteor/meteor'; +import { Mongo } from 'meteor/mongo'; let Items; @@ -18,4 +19,4 @@ if (Meteor.isServer) { }); } -export {Items} +export { Items } diff --git a/testing/transformations/server.js b/testing/transformations/server.js index bf20cbb6..28c1f194 100644 --- a/testing/transformations/server.js +++ b/testing/transformations/server.js @@ -1,3 +1,4 @@ +import { Meteor } from 'meteor/meteor'; import { assert } from 'chai'; import { Items } from './collections'; diff --git a/testing/vent/boot.js b/testing/vent/boot.js index 32910000..60b0c7c6 100644 --- a/testing/vent/boot.js +++ b/testing/vent/boot.js @@ -1,5 +1,5 @@ -import {Vent} from 'meteor/cultofcoders:redis-oplog'; -import {Meteor} from 'meteor/meteor'; +import { Vent } from 'meteor/cultofcoders:redis-oplog'; +import { Meteor } from 'meteor/meteor'; Vent.publish({ 'threadMessage'({channel, shouldReturn = true}) { @@ -21,4 +21,4 @@ Meteor.methods({ Vent.emit(channel, object) } } -}); \ No newline at end of file +}); diff --git a/testing/vent/client.js b/testing/vent/client.js index 1c46786d..9e2575f8 100644 --- a/testing/vent/client.js +++ b/testing/vent/client.js @@ -1,5 +1,4 @@ import { assert } from 'chai'; -import { waitForHandleToBeReady, callWithPromise } from '../lib/sync_utils'; import { Random } from 'meteor/random'; import { Vent } from 'meteor/cultofcoders:redis-oplog'; @@ -111,4 +110,4 @@ describe('Vent', function () { done(); }, 200); }); -}); \ No newline at end of file +}); From 24355583a532be83ee57971ba528bcd547395464 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 12:43:05 +0200 Subject: [PATCH 31/42] Test on Meteor 2.8.1 and Redis 7 --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43988142..77871d6f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,14 +7,14 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - meteor: [1.12.2, 2.6.1, 2.7.3] - redis-version: [4, 5, 6] + meteor: [1.12.2, 2.6.1, 2.7.3, 2.8.1] + redis-version: [4, 5, 6, 7] steps: - uses: actions/checkout@v3 - name: Start Redis - uses: supercharge/redis-github-action@1.4.0 + uses: supercharge/redis-github-action@1.5.0 with: redis-version: ${{ matrix.redis-version }} From 98fe9501a9ce6b2522a2015a15574975a24d5d39 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 12:47:15 +0200 Subject: [PATCH 32/42] Up versionsFrom to 1.12.1 --- package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.js b/package.js index 97c523f6..3485d772 100644 --- a/package.js +++ b/package.js @@ -17,7 +17,7 @@ Npm.depends({ }); Package.onUse(function(api) { - api.versionsFrom('1.5.1'); + api.versionsFrom('1.12.1'); api.use([ 'underscore', 'ecmascript', From 2d0609a0a1cdceecdc25f9d94745b41ba8592195 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 12:49:53 +0200 Subject: [PATCH 33/42] Push the tests to the latest Meteor version --- .github/workflows/test.yml | 2 +- package.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77871d6f..186e541c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - meteor: [1.12.2, 2.6.1, 2.7.3, 2.8.1] + meteor: [1.12.2, 2.6.1, 2.7.3, 2.8.1, 2.12] redis-version: [4, 5, 6, 7] steps: diff --git a/package.js b/package.js index 3485d772..42ea9542 100644 --- a/package.js +++ b/package.js @@ -17,7 +17,7 @@ Npm.depends({ }); Package.onUse(function(api) { - api.versionsFrom('1.12.1'); + api.versionsFrom(['1.12.2', '2.8.1', '2.12']); api.use([ 'underscore', 'ecmascript', From 25883ff42ae8c75652cd6a7eefa6faa8d0f946ad Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 13:02:39 +0200 Subject: [PATCH 34/42] Update NPM dependencies --- package.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.js b/package.js index 42ea9542..4e03a69e 100644 --- a/package.js +++ b/package.js @@ -11,8 +11,8 @@ Package.describe({ }); Npm.depends({ - redis: '2.8.0', - 'deep-extend': '0.5.0', + redis: '3.1.2', + 'deep-extend': '0.6.0', 'lodash.clonedeep': '4.5.0' }); From e01028576f95967c40ea7cdb451a833c6f44168d Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 16:07:22 +0200 Subject: [PATCH 35/42] Add changelog for PR 378 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d982983..0a728065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## CHANGELOG ### 2.2.0 +- Fix update not returning number ### 2.1.1 - Fixes callback is not a function error when using SyntheticMutator.update From 16f8bdd6621cafe68711eadb5847875adaa5046e Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 16:17:51 +0200 Subject: [PATCH 36/42] Remove old Travis badge from readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e8a670a..6589cb8b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ### LICENSE: MIT -[![Build Status](https://api.travis-ci.org/cult-of-coders/redis-oplog.svg?branch=master)](https://travis-ci.org/cult-of-coders/redis-oplog) [![Backers on Open Collective](https://opencollective.com/redis-oplog/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/redis-oplog/sponsors/badge.svg)](#sponsors) +[![Backers on Open Collective](https://opencollective.com/redis-oplog/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/redis-oplog/sponsors/badge.svg)](#sponsors) ## RedisOplog From 8bf2aaf883c6aedc5705b11b56135398a3bf5984 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 16:23:42 +0200 Subject: [PATCH 37/42] Readme addition --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d982983..3d79a071 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## CHANGELOG ### 2.2.0 +- Bumped minimum Meteor version to v1.12.2 +- Updated tests to cover from Meteor v1.12.2 to the latest v2.12 +- Added testing for Redis v7 ### 2.1.1 - Fixes callback is not a function error when using SyntheticMutator.update From c9ba427d7a3e27bf889cceab125e0a0f2a5fc79b Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 16:24:47 +0200 Subject: [PATCH 38/42] Changelog additions --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d79a071..36a25ed6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Bumped minimum Meteor version to v1.12.2 - Updated tests to cover from Meteor v1.12.2 to the latest v2.12 - Added testing for Redis v7 +- Updated `node-redis` to v3.1.2 +- Updated `deep-extend` to v0.6.0 ### 2.1.1 - Fixes callback is not a function error when using SyntheticMutator.update From 49c1d24b32d80205c3b0737bf2cfcfdab8e1ea88 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 16:27:33 +0200 Subject: [PATCH 39/42] Fix needless underscore after merging a fix --- lib/mongo/Mutator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mongo/Mutator.js b/lib/mongo/Mutator.js index 1387e903..956c45f9 100644 --- a/lib/mongo/Mutator.js +++ b/lib/mongo/Mutator.js @@ -154,7 +154,7 @@ export default class Mutator { Originals, selector, modifier, - _.extend({}, {_returnObject: false}, config), + Object.assign({}, {_returnObject: false}, config), callback, docIds, docs From 1daf81232ac1ef2483b3ff1808374937e3c70a3e Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sun, 7 May 2023 16:28:00 +0200 Subject: [PATCH 40/42] Fix missing variable declaration --- lib/mongo/Mutator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mongo/Mutator.js b/lib/mongo/Mutator.js index 956c45f9..dd96345a 100644 --- a/lib/mongo/Mutator.js +++ b/lib/mongo/Mutator.js @@ -252,7 +252,7 @@ export default class Mutator { if (config.pushToRedis) { if (data.insertedId) { - doc = { + let doc = { _id: data.insertedId }; From f5bacb5c158c6f731d02834ee9a4fb78dc8b54e1 Mon Sep 17 00:00:00 2001 From: G <1319474+guncebektas@users.noreply.github.com> Date: Mon, 22 May 2023 15:37:32 +0300 Subject: [PATCH 41/42] fix: missing s in collection name --- docs/outside_mutations.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/outside_mutations.md b/docs/outside_mutations.md index 9177b2c5..49203bc9 100644 --- a/docs/outside_mutations.md +++ b/docs/outside_mutations.md @@ -38,7 +38,7 @@ redis.publish('tasks', JSON.stringify({ You have to be careful, if in your app you subscribe by `_id`: ```js -return Task.find({_id: taskId}) +return Tasks.find({_id: taskId}) ``` In order for the processor to catch the event you have to send it to the `tasks::taskId` channel, where `taskId` represents the actual id inside MongoDB. @@ -47,7 +47,7 @@ So, if you have both types of publications, you have to publish it to both `task If you use namespaces, the channels also change: ```js -return Task.find({groupId}, { +return Tasks.find({groupId}, { namespace: `group::${groupId}` }) ``` @@ -57,7 +57,7 @@ you have to send it to both `group::groupId::tasks` and `tasks::taskId`, where ` Keep in mind, that namespaces don't affect direct query processing: ```js -return Task.find({_id: taskId}, { +return Tasks.find({_id: taskId}, { namespace: `group::${groupId}` }) ``` From f301ad549f045cd0e705b0dc3c9ad6416b44bcd8 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Sat, 10 Jun 2023 10:20:05 +0200 Subject: [PATCH 42/42] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b3537c9..6aee7206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Updated `node-redis` to v3.1.2 - Updated `deep-extend` to v0.6.0 - Fix update not returning number +- Fix SyntheticMutator not applying `globalRedisPrefix` ### 2.1.1 - Fixes callback is not a function error when using SyntheticMutator.update