nowity 1.10.0 → 1.11.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ws-server.d.ts","sourceRoot":"","sources":["../../src/server/ws-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAI7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAiB,UAAU,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC;CACrC;AAED,yEAAyE;AACzE,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,uBAAuB;IACpC,MAAM,EAAE,UAAU,CAAC;IACnB;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,UAAU,GAAG,IAAI,CAAC;IACpF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,KAAK,CAAC;IAChE;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,GAAG,OAAO,CAAC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UAAU,CAA4B;IAC9C,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,GAAG,CAAgC;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuC;IAChE;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2C;IAClE;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA2C;IAC1E,+DAA+D;IAC/D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA2C;IACzE,mEAAmE;IACnE,OAAO,CAAC,cAAc,CACb;IACT,2DAA2D;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAC3D,OAAO,CAAC,cAAc,CAA+B;IACrD,2EAA2E;IAC3E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAC5D,4EAA4E;IAC5E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4B;IAClD,oDAAoD;IACpD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA8D;gBAExE,IAAI,EAAE,uBAAuB;IAKzC,sDAAsD;IAChD,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAyCzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B5B,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED,4DAA4D;IAC5D,IAAI,mBAAmB,IAAI,MAAM,GAAG,IAAI,CAKvC;IAED,OAAO,CAAC,cAAc;YA4BR,gBAAgB;YAsFhB,aAAa;IA0I3B,OAAO,CAAC,SAAS;YAUH,SAAS;IAWvB,OAAO,CAAC,MAAM;CAkBjB"}
@@ -59,6 +59,14 @@ class NowitySyncServer {
59
59
  * processed before the session exists.
60
60
  */
61
61
  this.chains = new WeakMap();
62
+ /**
63
+ * Where a socket's mutations wait: behind the last `hello` (the session
64
+ * they are written under) and the mutations before them, not behind
65
+ * subscribes. A subscribe can take as long as its query; a move should not.
66
+ */
67
+ this.mutationChains = new WeakMap();
68
+ /** Settles once the socket's last `hello` has been handled. */
69
+ this.helloBarriers = new WeakMap();
62
70
  /** Registered on a borrowed server, and removed again on close. */
63
71
  this.upgradeHandler = null;
64
72
  /** Pings sent since the socket last proved it is alive. */
@@ -205,11 +213,30 @@ class NowitySyncServer {
205
213
  }
206
214
  return;
207
215
  }
208
- const previous = this.chains.get(socket) ?? Promise.resolve();
209
- const next = previous
210
- .then(() => authenticated)
211
- .then((auth) => (auth ? this.handleMessage(socket, auth, message, receivedAt) : undefined));
212
- this.chains.set(socket, next.catch((err) => this.onError(err)));
216
+ const handle = (auth) => auth ? this.handleMessage(socket, auth, message, receivedAt) : undefined;
217
+ const barrier = this.helloBarriers.get(socket);
218
+ if (message.t === "mutate" && barrier) {
219
+ // Mutations keep their order among themselves — they are
220
+ // chained here and again per session in the engine — and keep
221
+ // waiting for the session they belong to; only the queue of
222
+ // subscribes is no longer in front of them. Before any hello
223
+ // they go the ordinary way, to be told to say hello.
224
+ const previous = this.mutationChains.get(socket) ?? Promise.resolve();
225
+ const next = previous.then(() => barrier).then(() => authenticated).then(handle);
226
+ this.mutationChains.set(socket, next.catch((err) => this.onError(err)));
227
+ return;
228
+ }
229
+ // A hello still waits for everything before it, mutations included:
230
+ // it may replace the session they are being written under.
231
+ const control = this.chains.get(socket) ?? Promise.resolve();
232
+ const previous = message.t === "hello"
233
+ ? Promise.all([control, this.mutationChains.get(socket)]).then(() => undefined)
234
+ : control;
235
+ const next = previous.then(() => authenticated).then(handle);
236
+ const settled = next.catch((err) => this.onError(err));
237
+ this.chains.set(socket, settled);
238
+ if (message.t === "hello")
239
+ this.helloBarriers.set(socket, settled);
213
240
  });
214
241
  socket.on("close", () => {
215
242
  settleAuth(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nowity",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Realtime object model over PostgreSQL: logical change stream, query-scoped subscriptions, MobX identity map",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {