mongodb-livedata-server 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -67,4 +67,9 @@ liveDataServer.publish({
67
67
  const doc = await myCollection.findOne({ _id: id });
68
68
  ```
69
69
  - Neither MongoDB.ObjectId nor it's Meteor.js alternative is supported at the moment. String ids only.
70
+
71
+ ### DDP Extension
72
+
70
73
  - Starting from 0.1.0, this library extends DDP with `init` message, which is used to avoid initial spam of `added` messages.
74
+ - Starting from 0.1.1, `init` message will only be sent if `version` `1a` of DDP protocol is specified. Additionally, when version `1a`
75
+ is specified, server will not send removes for all documents when stopping a subscription, and rely on the client for the cleanup instead.
@@ -107,7 +107,7 @@ class DDPServer {
107
107
  */
108
108
  setPublicationStrategy(publicationName, strategy) {
109
109
  if (!Object.values(DDPServer.publicationStrategies).includes(strategy)) {
110
- throw new Error(`Invalid merge strategy: ${strategy}
110
+ throw new Error(`Invalid merge strategy: ${strategy}
111
111
  for collection ${publicationName}`);
112
112
  }
113
113
  this._publicationStrategies[publicationName] = strategy;
@@ -28,7 +28,7 @@ export declare class DDPSession {
28
28
  connectionHandle: SessionConnectionHandle;
29
29
  _dontStartNewUniversalSubs: boolean;
30
30
  _socketUrl: string;
31
- private version;
31
+ version: string;
32
32
  private socket;
33
33
  private initialized;
34
34
  private workerRunning;
@@ -522,15 +522,16 @@ class DDPSession {
522
522
  }
523
523
  // Tear down specified subscription
524
524
  _stopSubscription(subId, error) {
525
- var self = this;
526
525
  var subName = null;
527
526
  if (subId) {
528
- var maybeSub = self._namedSubs.get(subId);
527
+ var maybeSub = this._namedSubs.get(subId);
529
528
  if (maybeSub) {
530
529
  subName = maybeSub._name;
531
- maybeSub._removeAllDocuments();
530
+ // version 1a doesn't send document deletions and relies on the clients for cleanup
531
+ if (this.version !== "1a")
532
+ maybeSub._removeAllDocuments();
532
533
  maybeSub._deactivate();
533
- self._namedSubs.delete(subId);
534
+ this._namedSubs.delete(subId);
534
535
  }
535
536
  }
536
537
  var response = { msg: 'nosub', id: subId, error: undefined };
@@ -538,7 +539,7 @@ class DDPSession {
538
539
  response.error = (0, livedata_server_1.wrapInternalException)(error, subName ? ("from sub " + subName + " id " + subId)
539
540
  : ("from sub id " + subId));
540
541
  }
541
- self.send(response);
542
+ this.send(response);
542
543
  }
543
544
  // Tear down all subscriptions. Note that this does NOT send removed or nosub
544
545
  // messages, since we assume the client is gone.
@@ -14,7 +14,7 @@ export declare class Subscription {
14
14
  private _handler;
15
15
  private _subscriptionId;
16
16
  private _params;
17
- private _name?;
17
+ _name?: string;
18
18
  connection: SessionConnectionHandle;
19
19
  private _subscriptionHandle;
20
20
  private _deactivated;
@@ -287,7 +287,10 @@ class Subscription {
287
287
  }
288
288
  documents.forEach((_doc, id) => ids.add(id));
289
289
  }
290
- this._session.initialAdds(this._subscriptionHandle, collectionName, documents);
290
+ if (this._session.version === "1a")
291
+ this._session.initialAdds(this._subscriptionHandle, collectionName, documents);
292
+ else
293
+ documents.forEach((doc, id) => this._session.added(this._subscriptionHandle, collectionName, id, doc));
291
294
  }
292
295
  /**
293
296
  * @summary Call inside the publish function. Informs the subscriber that a document has been added to the record set.
@@ -34,7 +34,7 @@ function last(array, n, guard) {
34
34
  return exports.slice.call(array, Math.max(array.length - n, 0));
35
35
  }
36
36
  exports.last = last;
37
- exports.SUPPORTED_DDP_VERSIONS = ['1', 'pre2', 'pre1'];
37
+ exports.SUPPORTED_DDP_VERSIONS = ['1a', '1', 'pre2', 'pre1'];
38
38
  function parseDDP(stringMessage) {
39
39
  try {
40
40
  var msg = JSON.parse(stringMessage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb-livedata-server",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "MongoDB live data server, extracted from Meteor, Fibers removed and converted to TypeScript",
5
5
  "main": "dist/livedata_server.js",
6
6
  "types": "dist/livedata_server.d.ts",
@@ -15,7 +15,7 @@
15
15
  "@types/node": "^18.11.9",
16
16
  "@types/sockjs": "^0.3.33",
17
17
  "double-ended-queue": "^2.1.0-0",
18
- "mongodb": "^5.4.0",
18
+ "mongodb": "^5.9.2",
19
19
  "permessage-deflate": "^0.1.7",
20
20
  "sockjs": "^0.3.24"
21
21
  },