statewire 0.9.1 → 0.10.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.
Files changed (53) hide show
  1. package/dist/client/connection.d.ts +5 -2
  2. package/dist/client/connection.d.ts.map +1 -1
  3. package/dist/client/connection.js +123 -23
  4. package/dist/client/connection.js.map +1 -1
  5. package/dist/client/session.d.ts +7 -4
  6. package/dist/client/session.d.ts.map +1 -1
  7. package/dist/client/session.js +62 -15
  8. package/dist/client/session.js.map +1 -1
  9. package/dist/client/sessionStore.d.ts +5 -14
  10. package/dist/client/sessionStore.d.ts.map +1 -1
  11. package/dist/client/sessionStore.js +4 -1
  12. package/dist/client/sessionStore.js.map +1 -1
  13. package/dist/client/timing.d.ts +2 -0
  14. package/dist/client/timing.d.ts.map +1 -1
  15. package/dist/client/timing.js +8 -2
  16. package/dist/client/timing.js.map +1 -1
  17. package/dist/host/http.d.ts +7 -0
  18. package/dist/host/http.d.ts.map +1 -0
  19. package/dist/host/http.js +175 -0
  20. package/dist/host/http.js.map +1 -0
  21. package/dist/host/socket.d.ts +102 -1
  22. package/dist/host/socket.d.ts.map +1 -1
  23. package/dist/host/socket.js +48 -27
  24. package/dist/host/socket.js.map +1 -1
  25. package/dist/host-internal.d.ts +5 -0
  26. package/dist/host-internal.d.ts.map +1 -1
  27. package/dist/host.d.ts +1 -1
  28. package/dist/host.d.ts.map +1 -1
  29. package/dist/statewire.d.ts +34 -8
  30. package/dist/statewire.d.ts.map +1 -1
  31. package/dist/statewire.js +9 -2
  32. package/dist/statewire.js.map +1 -1
  33. package/dist/transports/sse.d.ts.map +1 -1
  34. package/dist/transports/sse.js +6 -4
  35. package/dist/transports/sse.js.map +1 -1
  36. package/dist/transports/ws.d.ts.map +1 -1
  37. package/dist/transports/ws.js +5 -9
  38. package/dist/transports/ws.js.map +1 -1
  39. package/dist/types.d.ts +1 -1
  40. package/dist/types.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/client/connection.ts +212 -40
  43. package/src/client/session.ts +90 -24
  44. package/src/client/sessionStore.ts +8 -15
  45. package/src/client/timing.ts +10 -2
  46. package/src/host/http.ts +280 -0
  47. package/src/host/socket.ts +120 -57
  48. package/src/host-internal.ts +5 -0
  49. package/src/host.ts +1 -0
  50. package/src/statewire.ts +65 -9
  51. package/src/transports/sse.ts +6 -5
  52. package/src/transports/ws.ts +4 -9
  53. package/src/types.ts +1 -1
@@ -27,7 +27,6 @@ type WsChannel = {
27
27
  const OPEN = 1;
28
28
 
29
29
  export const WS_SUBPROTOCOL = "statewire.v1";
30
- const UNAUTHORIZED_CLOSE = 4401;
31
30
 
32
31
  const socketUrl = async (
33
32
  options: StatewireClient.WSOptions,
@@ -64,7 +63,6 @@ const runSocket = (
64
63
  w: WsChannel,
65
64
  ws: WebSocket,
66
65
  frame: string,
67
- staleAuth: boolean,
68
66
  abort: AbortController,
69
67
  ): Promise<AttemptOutcome> =>
70
68
  new Promise((resolve, reject) => {
@@ -110,6 +108,7 @@ const runSocket = (
110
108
  try {
111
109
  const done = flushTapSync(() => handleEnvelope(c, env));
112
110
  if (done) {
111
+ if (env.fin?.reason === "unauthorized") w.authStale = true;
113
112
  outcome = done;
114
113
  ws.close();
115
114
  }
@@ -117,15 +116,11 @@ const runSocket = (
117
116
  fail(error);
118
117
  }
119
118
  };
120
- ws.onclose = (event?: { code?: number }) => {
119
+ ws.onclose = () => {
121
120
  closed = true;
122
121
  clearTimeout(timer);
123
122
  if (outcome) resolve(outcome);
124
- else if (event?.code === UNAUTHORIZED_CLOSE) {
125
- if (staleAuth) c.episode = { cause: "unauthorized" };
126
- w.authStale = true;
127
- reject(new Error("unauthorized"));
128
- } else reject(new Error(timedOut ? "timeout" : "network"));
123
+ else reject(new Error(timedOut ? "timeout" : "network"));
129
124
  };
130
125
  });
131
126
 
@@ -154,7 +149,7 @@ const attemptSocket = async (
154
149
  : protocols;
155
150
  ws = new WS(url, [WS_SUBPROTOCOL, ...extra]);
156
151
  w.socket = ws;
157
- return await runSocket(c, w, ws, frame, stale, abort);
152
+ return await runSocket(c, w, ws, frame, abort);
158
153
  } finally {
159
154
  if (w.socket === ws) w.socket = null;
160
155
  }
package/src/types.ts CHANGED
@@ -53,7 +53,7 @@ export interface Statewire<
53
53
  commands: Statewire.CommandsProxy<TCommands>;
54
54
  connection?: StatewireClient.Connection;
55
55
  source?: Statewire.StateSource;
56
- /** Highest command seq released from the resend queue by the server's dur flag. */
56
+ /** Highest command seq the server's dur flag states durably admitted — never lost, never run again — and released from the resend queue. */
57
57
  durableSeq?: number;
58
58
  /** Negation of the server's broadcast idle level; absent means always busy. */
59
59
  isBusy?: boolean;