From 4e08ab3556c315431cc7d6614dd0f3adfe98b019 Mon Sep 17 00:00:00 2001 From: harryadel Date: Sat, 22 Oct 2022 08:03:33 +0200 Subject: [PATCH 1/5] [ddp-server] Remove underscore --- packages/ddp-server/crossbar.js | 22 ++-- packages/ddp-server/livedata_server.js | 120 ++++++++++------------ packages/ddp-server/package.js | 11 +- packages/ddp-server/server_convenience.js | 6 +- packages/ddp-server/session_view_tests.js | 12 ++- packages/ddp-server/stream_server.js | 18 ++-- packages/ddp-server/writefence.js | 6 +- 7 files changed, 98 insertions(+), 97 deletions(-) diff --git a/packages/ddp-server/crossbar.js b/packages/ddp-server/crossbar.js index 6672059f99..86fd876c41 100644 --- a/packages/ddp-server/crossbar.js +++ b/packages/ddp-server/crossbar.js @@ -1,3 +1,5 @@ +import has from 'lodash.has'; + // A "crossbar" is a class that provides structured notification registration. // See _match for the definition of how a notification matches a trigger. // All notifications and triggers must have a string key named 'collection'. @@ -16,11 +18,11 @@ DDPServer._Crossbar = function (options) { self.factName = options.factName || null; }; -_.extend(DDPServer._Crossbar.prototype, { +Object.assign(DDPServer._Crossbar.prototype, { // msg is a trigger or a notification _collectionForMessage: function (msg) { var self = this; - if (! _.has(msg, 'collection')) { + if (! has(msg, 'collection')) { return ''; } else if (typeof(msg.collection) === 'string') { if (msg.collection === '') @@ -47,7 +49,7 @@ _.extend(DDPServer._Crossbar.prototype, { var collection = self._collectionForMessage(trigger); var record = {trigger: EJSON.clone(trigger), callback: callback}; - if (! _.has(self.listenersByCollection, collection)) { + if (!has(self.listenersByCollection, collection)) { self.listenersByCollection[collection] = {}; self.listenersByCollectionCount[collection] = 0; } @@ -88,13 +90,13 @@ _.extend(DDPServer._Crossbar.prototype, { var collection = self._collectionForMessage(notification); - if (! _.has(self.listenersByCollection, collection)) { + if (!has(self.listenersByCollection, collection)) { return; } var listenersForCollection = self.listenersByCollection[collection]; var callbackIds = []; - _.each(listenersForCollection, function (l, id) { + Object.entries(listenersForCollection).forEach(function ([id, l]) { if (self._matches(notification, l.trigger)) { callbackIds.push(id); } @@ -109,8 +111,8 @@ _.extend(DDPServer._Crossbar.prototype, { // because the only way that stops being true is if listenersForCollection // first gets reduced down to the empty object (and then never gets // increased again). - _.each(callbackIds, function (id) { - if (_.has(listenersForCollection, id)) { + callbackIds.forEach(function (id) { + if (has(listenersForCollection, id)) { listenersForCollection[id].callback(notification); } }); @@ -150,8 +152,8 @@ _.extend(DDPServer._Crossbar.prototype, { return false; } - return _.all(trigger, function (triggerValue, key) { - return !_.has(notification, key) || + return Object.entries(trigger).every(function ([triggerValue, key]) { + return !has(notification, key) || EJSON.equals(triggerValue, notification[key]); }); } @@ -164,4 +166,4 @@ _.extend(DDPServer._Crossbar.prototype, { // message from being sent). DDPServer._InvalidationCrossbar = new DDPServer._Crossbar({ factName: "invalidation-crossbar-listeners" -}); +}); \ No newline at end of file diff --git a/packages/ddp-server/livedata_server.js b/packages/ddp-server/livedata_server.js index 3b4853c39e..98e93b1143 100644 --- a/packages/ddp-server/livedata_server.js +++ b/packages/ddp-server/livedata_server.js @@ -1,6 +1,11 @@ +import Fiber from 'fibers'; +import isEmpty from 'lodash.isempty'; +import has from 'lodash.has'; +import isString from 'lodash.isstring'; +import isObject from 'lodash.isobject'; + DDPServer = {}; -var Fiber = Npm.require('fibers'); // Publication strategies define how we handle data from published cursors at the collection level // This allows someone to: @@ -52,7 +57,7 @@ var SessionDocumentView = function () { DDPServer._SessionDocumentView = SessionDocumentView; -_.extend(SessionDocumentView.prototype, { +Object.assign(SessionDocumentView.prototype, { getFields: function () { var self = this; @@ -160,7 +165,7 @@ Object.assign(SessionCollectionView.prototype, { diff: function (previous) { var self = this; DiffSequence.diffMaps(previous.documents, self.documents, { - both: _.bind(self.diffDocument, self), + both: self.diffDocument.bind(self), rightOnly: function (id, nowDV) { self.callbacks.added(self.collectionName, id, nowDV.getFields()); @@ -201,7 +206,7 @@ Object.assign(SessionCollectionView.prototype, { } docView.existsIn.add(subscriptionHandle); var changeCollector = {}; - _.each(fields, function (value, key) { + Object.entries(fields).forEach(function ([key, value]) { docView.changeField( subscriptionHandle, key, value, changeCollector, true); }); @@ -217,7 +222,7 @@ Object.assign(SessionCollectionView.prototype, { var docView = self.documents.get(id); if (!docView) throw new Error("Could not find element with id " + id + " to change"); - _.each(changed, function (value, key) { + Object.entries(changed).forEach(function ([key, value]) { if (value === undefined) docView.clearField(subscriptionHandle, key, changedResult); else @@ -362,7 +367,7 @@ Object.assign(Session.prototype, { if (self._isSending) self.send({msg: "ready", subs: subscriptionIds}); else { - _.each(subscriptionIds, function (subscriptionId) { + subscriptionIds.forEach(function (subscriptionId) { self._pendingReady.push(subscriptionId); }); } @@ -379,7 +384,7 @@ Object.assign(Session.prototype, { }, sendChanged(collectionName, id, fields) { - if (_.isEmpty(fields)) + if (isEmpty(fields)) return; if (this._canSend(collectionName)) { @@ -400,9 +405,9 @@ Object.assign(Session.prototype, { getSendCallbacks: function () { var self = this; return { - added: _.bind(self.sendAdded, self), - changed: _.bind(self.sendChanged, self), - removed: _.bind(self.sendRemoved, self) + added: self.sendAdded.bind(self), + changed: self.sendChanged.bind(self), + removed: self.sendRemoved.bind(self) }; }, @@ -452,8 +457,8 @@ Object.assign(Session.prototype, { // Make a shallow copy of the set of universal handlers and start them. If // additional universal publishers start while we're running them (due to // yielding), they will run separately as part of Server.publish. - var handlers = _.clone(self.server.universal_publish_handlers); - _.each(handlers, function (handler) { + var handlers = [...self.server.universal_publish_handlers]; + handlers.forEach(function (handler) { self._startSubscription(handler); }); }, @@ -495,7 +500,7 @@ Object.assign(Session.prototype, { // Defer calling the close callbacks, so that the caller closing // the session isn't waiting for all the callbacks to complete. - _.each(self._closeCallbacks, function (callback) { + self._closeCallbacks.forEach(function (callback) { callback(); }); }); @@ -599,7 +604,7 @@ Object.assign(Session.prototype, { return true; }); - if (_.has(self.protocol_handlers, msg.msg)) + if (has(self.protocol_handlers, msg.msg)) self.protocol_handlers[msg.msg].call(self, msg, unblock); else self.sendError('Bad request', msg); @@ -762,33 +767,16 @@ Object.assign(Session.prototype, { } } - const getCurrentMethodInvocationResult = () => { - const currentContext = DDP._CurrentMethodInvocation._setNewContextAndGetCurrent( - invocation - ); - - try { - let result; - const resultOrThenable = maybeAuditArgumentChecks( - handler, - invocation, - msg.params, + resolve(DDPServer._CurrentWriteFence.withValue( + fence, + () => DDP._CurrentMethodInvocation.withValue( + invocation, + () => maybeAuditArgumentChecks( + handler, invocation, msg.params, "call to '" + msg.method + "'" - ); - const isThenable = - resultOrThenable && typeof resultOrThenable.then === 'function'; - if (isThenable) { - result = Promise.await(resultOrThenable); - } else { - result = resultOrThenable; - } - return result; - } finally { - DDP._CurrentMethodInvocation._set(currentContext); - } - }; - - resolve(DDPServer._CurrentWriteFence.withValue(fence, getCurrentMethodInvocationResult)); + ) + ) + )); }); function finish() { @@ -801,7 +789,7 @@ Object.assign(Session.prototype, { id: msg.id }; - promise.then(result => { + promise.then((result) => { finish(); if (result !== undefined) { payload.result = result; @@ -907,7 +895,7 @@ Object.assign(Session.prototype, { Meteor._noYieldsAllowed(function () { self._isSending = true; self._diffCollectionViews(beforeCVs); - if (!_.isEmpty(self._pendingReady)) { + if (!isEmpty(self._pendingReady)) { self.sendReady(self._pendingReady); self._pendingReady = []; } @@ -996,7 +984,7 @@ Object.assign(Session.prototype, { return self.socket.remoteAddress; var forwardedFor = self.socket.headers["x-forwarded-for"]; - if (! _.isString(forwardedFor)) + if (!isString(forwardedFor)) return null; forwardedFor = forwardedFor.trim().split(/\s*,\s*/); @@ -1186,9 +1174,9 @@ Object.assign(Subscription.prototype, { // _publishCursor only returns after the initial added callbacks have run. // mark subscription as ready. self.ready(); - } else if (_.isArray(res)) { + } else if (Array.isArray(res)) { // Check all the elements are cursors - if (! _.all(res, isCursor)) { + if (! res.every(isCursor)) { self.error(new Error("Publish function returned an array of non-Cursors")); return; } @@ -1198,7 +1186,7 @@ Object.assign(Subscription.prototype, { var collectionNames = {}; for (var i = 0; i < res.length; ++i) { var collectionName = res[i]._getCollectionName(); - if (_.has(collectionNames, collectionName)) { + if (has(collectionNames, collectionName)) { self.error(new Error( "Publish function returned multiple cursors for collection " + collectionName)); @@ -1208,7 +1196,7 @@ Object.assign(Subscription.prototype, { }; try { - _.each(res, function (cur) { + res.forEach(function (cur) { cur._publishCursor(self); }); } catch (e) { @@ -1245,7 +1233,7 @@ Object.assign(Subscription.prototype, { // Tell listeners, so they can clean up var callbacks = self._stopCallbacks; self._stopCallbacks = []; - _.each(callbacks, function (callback) { + callbacks.forEach(function (callback) { callback(); }); }, @@ -1534,33 +1522,33 @@ Object.assign(Server.prototype, { }, /** - * @summary Set publication strategy for the given collection. Publications strategies are available from `DDPServer.publicationStrategies`. You call this method from `Meteor.server`, like `Meteor.server.setPublicationStrategy()` + * @summary Set publication strategy for the given publication. Publications strategies are available from `DDPServer.publicationStrategies`. You call this method from `Meteor.server`, like `Meteor.server.setPublicationStrategy()` * @locus Server * @alias setPublicationStrategy - * @param collectionName {String} + * @param publicationName {String} * @param strategy {{useCollectionView: boolean, doAccountingForCollection: boolean}} * @memberOf Meteor.server * @importFromPackage meteor */ - setPublicationStrategy(collectionName, strategy) { + setPublicationStrategy(publicationName, strategy) { if (!Object.values(publicationStrategies).includes(strategy)) { throw new Error(`Invalid merge strategy: ${strategy} - for collection ${collectionName}`); + for collection ${publicationName}`); } - this._publicationStrategies[collectionName] = strategy; + this._publicationStrategies[publicationName] = strategy; }, /** - * @summary Gets the publication strategy for the requested collection. You call this method from `Meteor.server`, like `Meteor.server.getPublicationStrategy()` + * @summary Gets the publication strategy for the requested publication. You call this method from `Meteor.server`, like `Meteor.server.getPublicationStrategy()` * @locus Server * @alias getPublicationStrategy - * @param collectionName {String} + * @param publicationName {String} * @memberOf Meteor.server * @importFromPackage meteor * @return {{useCollectionView: boolean, doAccountingForCollection: boolean}} */ - getPublicationStrategy(collectionName) { - return this._publicationStrategies[collectionName] + getPublicationStrategy(publicationName) { + return this._publicationStrategies[publicationName] || this.options.defaultPublicationStrategy; }, @@ -1582,9 +1570,9 @@ Object.assign(Server.prototype, { // The connect message must specify a version and an array of supported // versions, and it must claim to support what it is proposing. if (!(typeof (msg.version) === 'string' && - _.isArray(msg.support) && - _.all(msg.support, _.isString) && - _.contains(msg.support, msg.version))) { + Array.isArray(msg.support) && + msg.support.every(isString) && + msg.support.includes(msg.version))) { socket.send(DDPCommon.stringifyDDP({msg: 'failed', version: DDPCommon.SUPPORTED_DDP_VERSIONS[0]})); socket.close(); @@ -1649,7 +1637,7 @@ Object.assign(Server.prototype, { publish: function (name, handler, options) { var self = this; - if (! _.isObject(name)) { + if (!isObject(name)) { options = options || {}; if (name && name in self.publish_handlers) { @@ -1699,7 +1687,7 @@ Object.assign(Server.prototype, { } } else{ - _.each(name, function(value, key) { + Object.entries(name).forEach(function([key, value]) { self.publish(key, value, {}); }); } @@ -1719,7 +1707,7 @@ Object.assign(Server.prototype, { */ methods: function (methods) { var self = this; - _.each(methods, function (func, name) { + Object.entries(methods).forEach(function ([name, func]) { if (typeof func !== 'function') throw new Error("Method '" + name + "' must be a function"); if (self.method_handlers[name]) @@ -1837,8 +1825,8 @@ Object.assign(Server.prototype, { var calculateVersion = function (clientSupportedVersions, serverSupportedVersions) { - var correctVersion = _.find(clientSupportedVersions, function (version) { - return _.contains(serverSupportedVersions, version); + var correctVersion = clientSupportedVersions.find(function (version) { + return serverSupportedVersions.includes(version); }); if (!correctVersion) { correctVersion = serverSupportedVersions[0]; @@ -1900,4 +1888,4 @@ var maybeAuditArgumentChecks = function (f, context, args, description) { f, context, args, description); } return f.apply(context, args); -}; +}; \ No newline at end of file diff --git a/packages/ddp-server/package.js b/packages/ddp-server/package.js index da413690b0..a2163fd4c3 100644 --- a/packages/ddp-server/package.js +++ b/packages/ddp-server/package.js @@ -6,11 +6,16 @@ Package.describe({ Npm.depends({ "permessage-deflate": "0.1.7", - sockjs: "0.3.21" + sockjs: "0.3.21", + "lodash.once": "4.1.1", + "lodash.has": "4.5.2", + "lodash.isempty": "4.4.0", + "lodash.isstring": "4.0.1", + "lodash.isobject": "3.0.2" }); Package.onUse(function (api) { - api.use(['check', 'random', 'ejson', 'underscore', + api.use(['check', 'random', 'ejson', 'retry', 'mongo-id', 'diff-sequence', 'ecmascript'], 'server'); @@ -52,7 +57,7 @@ Package.onTest(function (api) { api.use('livedata', ['client', 'server']); api.use('mongo', ['client', 'server']); api.use('test-helpers', ['client', 'server']); - api.use(['underscore', 'tinytest', 'random', 'tracker', 'minimongo', 'reactive-var']); + api.use(['tinytest', 'random', 'tracker', 'minimongo', 'reactive-var']); api.addFiles('livedata_server_tests.js', 'server'); api.addFiles('livedata_server_async_tests.js', 'server'); diff --git a/packages/ddp-server/server_convenience.js b/packages/ddp-server/server_convenience.js index 063bbe6385..fafe2c9a10 100755 --- a/packages/ddp-server/server_convenience.js +++ b/packages/ddp-server/server_convenience.js @@ -11,7 +11,7 @@ Meteor.refresh = function (notification) { // Proxy the public methods of Meteor.server so they can // be called directly on Meteor. -_.each( + [ 'publish', 'methods', @@ -21,8 +21,8 @@ _.each( 'applyAsync', 'onConnection', 'onMessage', - ], + ].forEach( function(name) { - Meteor[name] = _.bind(Meteor.server[name], Meteor.server); + Meteor[name] = Meteor.server[name].bind(Meteor.server); } ); diff --git a/packages/ddp-server/session_view_tests.js b/packages/ddp-server/session_view_tests.js index 0459a45107..ce85208174 100644 --- a/packages/ddp-server/session_view_tests.js +++ b/packages/ddp-server/session_view_tests.js @@ -1,3 +1,5 @@ +import isEmpty from 'lodash.isempty'; + var newView = function(test) { var results = []; var view = new DDPServer._SessionCollectionView('test', { @@ -5,7 +7,7 @@ var newView = function(test) { results.push({fun: 'added', id: id, fields: fields}); }, changed: function (collection, id, changed) { - if (_.isEmpty(changed)) + if (isEmpty(changed)) return; results.push({fun: 'changed', id: id, changed: changed}); }, @@ -17,8 +19,8 @@ var newView = function(test) { view: view, results: results }; - _.each(["added", "changed", "removed"], function (it) { - v[it] = _.bind(view[it], view); + ["added", "changed", "removed"].forEach(function (it) { + v[it] = view[it].bind(view); }); v.expectResult = function (result) { test.equal(results.shift(), result); @@ -182,7 +184,7 @@ Tinytest.add('livedata - sessionview - change to canonical value produces no cha v.added("B", "A1", {foo: "baz"}); var canon = "bar"; var maybeResults = v.drain(); - if (!_.isEmpty(maybeResults)) { + if (!isEmpty(maybeResults)) { // if something happened, it was a change message to baz. // if nothing did, canon is still bar. test.length(maybeResults, 1); @@ -390,4 +392,4 @@ Tinytest.add('livedata - sessionview - clear undefined value', function (test) { v.changed("A", "A1", {field: undefined}); v.expectNoResult(); -}); +}); \ No newline at end of file diff --git a/packages/ddp-server/stream_server.js b/packages/ddp-server/stream_server.js index 49c0f1385d..23457847b8 100644 --- a/packages/ddp-server/stream_server.js +++ b/packages/ddp-server/stream_server.js @@ -1,3 +1,5 @@ +import once from 'lodash.once'; + // By default, we use the permessage-deflate extension with default // configuration. If $SERVER_WEBSOCKET_COMPRESSION is set, then it must be valid // JSON. If it represents a falsey value, then we do not use permessage-deflate @@ -9,7 +11,7 @@ // crash the tool during isopacket load if your JSON doesn't parse. This is only // a problem because the tool has to load the DDP server code just in order to // be a DDP client; see https://github.com/meteor/meteor/issues/3452 .) -var websocketExtensions = _.once(function () { +var websocketExtensions = once(function () { var extensions = []; var websocketCompressionConfig = process.env.SERVER_WEBSOCKET_COMPRESSION @@ -113,7 +115,9 @@ StreamServer = function () { socket.write(data); }; socket.on('close', function () { - self.open_sockets = _.without(self.open_sockets, socket); + self.open_sockets = self.open_sockets.filter(function(value) { + return value !== socket; + }); }); self.open_sockets.push(socket); @@ -125,7 +129,7 @@ StreamServer = function () { // call all our callbacks when we get a new socket. they will do the // work of setting up handlers and such for specific messages. - _.each(self.registration_callbacks, function (callback) { + self.registration_callbacks.forEach(function (callback) { callback(socket); }); }); @@ -138,7 +142,7 @@ Object.assign(StreamServer.prototype, { register: function (callback) { var self = this; self.registration_callbacks.push(callback); - _.each(self.all_sockets(), function (socket) { + self.all_sockets().forEach(function (socket) { callback(socket); }); }, @@ -146,7 +150,7 @@ Object.assign(StreamServer.prototype, { // get a list of all sockets all_sockets: function () { var self = this; - return _.values(self.open_sockets); + return Object.values(self.open_sockets); }, // Redirect /websocket to /sockjs/websocket in order to not expose @@ -180,11 +184,11 @@ Object.assign(StreamServer.prototype, { parsedUrl.pathname = self.prefix + '/websocket'; request.url = url.format(parsedUrl); } - _.each(oldHttpServerListeners, function(oldListener) { + oldHttpServerListeners.forEach(function(oldListener) { oldListener.apply(httpServer, args); }); }; httpServer.addListener(event, newListener); }); } -}); +}); \ No newline at end of file diff --git a/packages/ddp-server/writefence.js b/packages/ddp-server/writefence.js index e9310c9f7f..616da1e3fe 100644 --- a/packages/ddp-server/writefence.js +++ b/packages/ddp-server/writefence.js @@ -21,7 +21,7 @@ DDPServer._WriteFence = function () { // DDPServer._CurrentWriteFence = new Meteor.EnvironmentVariable; -_.extend(DDPServer._WriteFence.prototype, { +Object.assign(DDPServer._WriteFence.prototype, { // Start tracking a write, and return an object to represent it. The // object has a single method, committed(). This method should be // called when the write is fully committed and propagated. You can @@ -107,7 +107,7 @@ _.extend(DDPServer._WriteFence.prototype, { while (self.before_fire_callbacks.length > 0) { var callbacks = self.before_fire_callbacks; self.before_fire_callbacks = []; - _.each(callbacks, invokeCallback); + callbacks.forEach(invokeCallback); } self.outstanding_writes--; @@ -115,7 +115,7 @@ _.extend(DDPServer._WriteFence.prototype, { self.fired = true; var callbacks = self.completion_callbacks; self.completion_callbacks = []; - _.each(callbacks, invokeCallback); + callbacks.forEach(invokeCallback); } } }, From cddee616960fcc426687bffbc2d604994d3faa28 Mon Sep 17 00:00:00 2001 From: harryadel Date: Wed, 22 Nov 2023 17:50:05 +0200 Subject: [PATCH 2/5] [ddp-server] fix test --- packages/ddp-server/crossbar.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/ddp-server/crossbar.js b/packages/ddp-server/crossbar.js index 86fd876c41..2045ba5283 100644 --- a/packages/ddp-server/crossbar.js +++ b/packages/ddp-server/crossbar.js @@ -152,10 +152,9 @@ Object.assign(DDPServer._Crossbar.prototype, { return false; } - return Object.entries(trigger).every(function ([triggerValue, key]) { - return !has(notification, key) || - EJSON.equals(triggerValue, notification[key]); - }); + return Object.keys(trigger).every(function (key) { + return !(key in notification) || EJSON.equals(trigger[key], notification[key]); + }); } }); From d9f9e6df91152090b75b4961d860afed27519276 Mon Sep 17 00:00:00 2001 From: harryadel Date: Sat, 24 Aug 2024 14:03:14 +0300 Subject: [PATCH 3/5] Remove fibers import --- packages/ddp-server/livedata_server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/ddp-server/livedata_server.js b/packages/ddp-server/livedata_server.js index f7515e9451..d09b70db41 100644 --- a/packages/ddp-server/livedata_server.js +++ b/packages/ddp-server/livedata_server.js @@ -1,4 +1,3 @@ -import Fiber from 'fibers'; import isEmpty from 'lodash.isempty'; import has from 'lodash.has'; import isString from 'lodash.isstring'; From 17f0eda386184c1969c31d7a3a45324b64abd513 Mon Sep 17 00:00:00 2001 From: harryadel Date: Tue, 27 Aug 2024 16:58:42 +0300 Subject: [PATCH 4/5] [ddp-server] Re-add missing _getCurrentFence --- packages/ddp-server/livedata_server.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/ddp-server/livedata_server.js b/packages/ddp-server/livedata_server.js index d09b70db41..3f4f1574a2 100644 --- a/packages/ddp-server/livedata_server.js +++ b/packages/ddp-server/livedata_server.js @@ -86,6 +86,14 @@ var SessionDocumentView = function () { DDPServer._SessionDocumentView = SessionDocumentView; +DDPServer._getCurrentFence = function () { + let currentInvocation = this._CurrentWriteFence.get(); + if (currentInvocation) { + return currentInvocation; + } + currentInvocation = DDP._CurrentMethodInvocation.get(); + return currentInvocation ? currentInvocation.fence : undefined; +}; Object.assign(SessionDocumentView.prototype, { From 6ce9526101c641ae84cf84a64b53d8a701b0bb18 Mon Sep 17 00:00:00 2001 From: harryadel Date: Thu, 26 Sep 2024 14:54:36 +0300 Subject: [PATCH 5/5] Replace the usage of lodash.has with native "in" --- packages/ddp-server/crossbar.js | 10 ++++------ packages/ddp-server/livedata_server.js | 12 +++++------- packages/ddp-server/package.js | 1 - 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/ddp-server/crossbar.js b/packages/ddp-server/crossbar.js index 23ead367ea..047825a798 100644 --- a/packages/ddp-server/crossbar.js +++ b/packages/ddp-server/crossbar.js @@ -1,5 +1,3 @@ -import has from 'lodash.has'; - // A "crossbar" is a class that provides structured notification registration. // See _match for the definition of how a notification matches a trigger. // All notifications and triggers must have a string key named 'collection'. @@ -22,7 +20,7 @@ Object.assign(DDPServer._Crossbar.prototype, { // msg is a trigger or a notification _collectionForMessage: function (msg) { var self = this; - if (! has(msg, 'collection')) { + if (!('collection' in msg)) { return ''; } else if (typeof(msg.collection) === 'string') { if (msg.collection === '') @@ -49,7 +47,7 @@ Object.assign(DDPServer._Crossbar.prototype, { var collection = self._collectionForMessage(trigger); var record = {trigger: EJSON.clone(trigger), callback: callback}; - if (!has(self.listenersByCollection, collection)) { + if (! (collection in self.listenersByCollection)) { self.listenersByCollection[collection] = {}; self.listenersByCollectionCount[collection] = 0; } @@ -90,7 +88,7 @@ Object.assign(DDPServer._Crossbar.prototype, { var collection = self._collectionForMessage(notification); - if (!has(self.listenersByCollection, collection)) { + if (!(collection in self.listenersByCollection)) { return; } @@ -112,7 +110,7 @@ Object.assign(DDPServer._Crossbar.prototype, { // first gets reduced down to the empty object (and then never gets // increased again). for (const id of callbackIds) { - if (has(listenersForCollection, id)) { + if (id in listenersForCollection) { await listenersForCollection[id].callback(notification); } } diff --git a/packages/ddp-server/livedata_server.js b/packages/ddp-server/livedata_server.js index 3f4f1574a2..a79d0febf2 100644 --- a/packages/ddp-server/livedata_server.js +++ b/packages/ddp-server/livedata_server.js @@ -1,5 +1,4 @@ import isEmpty from 'lodash.isempty'; -import has from 'lodash.has'; import isString from 'lodash.isstring'; import isObject from 'lodash.isobject'; @@ -645,7 +644,7 @@ Object.assign(Session.prototype, { return true; }); - if (has(self.protocol_handlers, msg.msg)) { + if (msg.msg in self.protocol_handlers) { const result = self.protocol_handlers[msg.msg].call( self, msg, @@ -680,7 +679,7 @@ Object.assign(Session.prototype, { // reject malformed messages if (typeof (msg.id) !== "string" || typeof (msg.name) !== "string" || - (('params' in msg) && !(msg.params instanceof Array))) { + ('params' in msg && !(msg.params instanceof Array))) { self.sendError("Malformed subscription", msg); return; } @@ -749,7 +748,7 @@ Object.assign(Session.prototype, { // for forwards compatibility. if (typeof (msg.id) !== "string" || typeof (msg.method) !== "string" || - (('params' in msg) && !(msg.params instanceof Array)) || + ('params' in msg && !(msg.params instanceof Array)) || (('randomSeed' in msg) && (typeof msg.randomSeed !== "string"))) { self.sendError("Malformed method invocation", msg); return; @@ -1245,7 +1244,7 @@ Object.assign(Subscription.prototype, { for (var i = 0; i < res.length; ++i) { var collectionName = res[i]._getCollectionName(); - if (has(collectionNames, collectionName)) { + if (collectionNames[collectionName]) { self.error(new Error( "Publish function returned multiple cursors for collection " + collectionName)); @@ -1952,8 +1951,7 @@ var wrapInternalException = function (exception, context) { // Did the error contain more details that could have been useful if caught in // server code (or if thrown from non-client-originated code), but also - // provided a "sanitized" version with more context than 500 Internal server - // error? Use that. + // provided a "sanitized" version with more context than 500 Internal server error? Use that. if (exception.sanitizedError) { if (exception.sanitizedError.isClientSafe) return exception.sanitizedError; diff --git a/packages/ddp-server/package.js b/packages/ddp-server/package.js index 7ea2290aa7..8f6526e19e 100644 --- a/packages/ddp-server/package.js +++ b/packages/ddp-server/package.js @@ -8,7 +8,6 @@ Npm.depends({ "permessage-deflate": "0.1.7", sockjs: "0.3.24", "lodash.once": "4.1.1", - "lodash.has": "4.5.2", "lodash.isempty": "4.4.0", "lodash.isstring": "4.0.1", "lodash.isobject": "3.0.2"