@ultimat3/realtime 31.32.0 → 31.33.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/realtime",
3
- "version": "31.32.0",
3
+ "version": "31.33.0",
4
4
  "description": "Three-tier realtime: channels, live queries, local-first sync — one protocol, one mutator shape",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -52,10 +52,10 @@
52
52
  "test": "bun test"
53
53
  },
54
54
  "dependencies": {
55
- "@ultimat3/core": "31.32.0",
56
- "@ultimat3/entity": "31.32.0",
57
- "@ultimat3/policy": "31.32.0",
58
- "@ultimat3/query": "31.32.0",
55
+ "@ultimat3/core": "31.33.0",
56
+ "@ultimat3/entity": "31.33.0",
57
+ "@ultimat3/policy": "31.33.0",
58
+ "@ultimat3/query": "31.33.0",
59
59
  "nats": "2.29.3"
60
60
  }
61
61
  }
package/src/client.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  // The client half of the sync protocol: one socket's lifecycle — dial, beat, reconnect — and the
2
- // live windows and topics riding it. Framework-agnostic and reactive-runtime-free on purpose: ONE
3
- // client serves the whole page (every island bundle reaches it through the page handle), and a
4
- // signal belongs to one bundle's solid-js, so everything here is a plain read plus a listener.
5
- // Read-only: the socket carries no writes (`useMutation` is HTTP).
2
+ // live windows and topics riding it.
3
+ //
4
+ // Reactive-runtime-free on purpose: ONE client serves the whole page (every island bundle reaches
5
+ // it through the page handle) and a signal belongs to one bundle's solid-js, so everything here is
6
+ // a plain read plus a listener. Read-only: the socket carries no writes (`useMutation` is HTTP).
6
7
 
7
8
  import { type Clock, finiteOption, systemClock, uuidV7 } from '@ultimat3/core/page';
8
9
  import {
@@ -171,9 +172,8 @@ export class LiveClient {
171
172
  this.#heartbeat.start(this.#clock.now().getTime());
172
173
  });
173
174
  socket.onMessage((data) => {
174
- // A frame speaks only for its own socket, the same rule `onClose` follows. A replaced socket
175
- // that is still draining bytes would otherwise fold its patches into the live registrations
176
- // a second time, over newer state.
175
+ // A frame speaks only for its own socket, as `onClose` does: a replaced socket still draining
176
+ // would otherwise fold its patches into the live registrations again, over newer state.
177
177
  if (this.#socket !== socket) return;
178
178
  // The curve resets on the node's first word, not on the open: a proxy or an overloaded node
179
179
  // that accepts the upgrade and drops it at once would otherwise reset it every time, and the
@@ -1,8 +1,9 @@
1
- // The close codes this protocol speaks, defined once below both halves. `socket.ts` (the node's
2
- // registry) and `client-frames.ts` (browser code) each need one of these and neither may import
3
- // the other — the client must not pull the node's registry into the tab — so the table lives here,
4
- // a leaf with no import at all, and `socket.ts` re-exports it for the node-side files that already
5
- // read `CLOSE` from there.
1
+ // The close codes this protocol speaks, defined once below both halves.
2
+ //
3
+ // `socket.ts` (the node's registry) and `client-frames.ts` (browser code) each need one of these
4
+ // and neither may import the other — the client must not pull the node's registry into the tab — so
5
+ // the table lives here, a leaf with no import at all, and `socket.ts` re-exports it for the
6
+ // node-side files that already read `CLOSE` from there.
6
7
  //
7
8
  // 1000–1015 are the RFC 6455 codes; 4000–4999 are private use. A browser accepts only 1000 and
8
9
  // 3000–4999 from script (`WebSocket.close()` throws `InvalidAccessError` on anything else), which
@@ -1,10 +1,12 @@
1
1
  // @ultimat3/realtime's PAGE codes and their TITLES — every code a browser can raise or receive on
2
- // the wire — registered at import. Server-only codes are `error-titles-server.ts`. Listed in
3
- // `sideEffects`, so `errors.ts` (the sync node's refusal classes) is unlisted and no hook's
4
- // chunk carries it (`page-errors-bundle.test.ts`): measured on Bun 1.4.2, −1,081 B on `feed`, −1,051 B on `likes-badge`, −1,047 B on
5
- // `run-console`, every title still registered. Imported bare by `index.ts` (a page
6
- // rebuilds a node's refusal by code in `refusalError`, and `page-errors.ts` constructs codes from
7
- // here without importing it) and by `errors.ts`, so constructing a server refusal registers too.
2
+ // the wire — registered at import. Server-only codes are `error-titles-server.ts`.
3
+ //
4
+ // Listed in `sideEffects`, so `errors.ts` (the sync node's refusal classes) is unlisted and no
5
+ // hook's chunk carries it (`page-errors-bundle.test.ts`): measured on Bun 1.4.2, −1,081 B on
6
+ // `feed`, −1,051 B on `likes-badge`, −1,047 B on `run-console`, every title still registered.
7
+ // Imported bare by `index.ts` (a page rebuilds a node's refusal by code in `refusalError`, and
8
+ // `page-errors.ts` constructs codes from here without importing it) and by `errors.ts`, so
9
+ // constructing a server refusal registers too.
8
10
 
9
11
  // From `/page`, never core's barrel: this module is in every island chunk that reaches realtime,
10
12
  // and the barrel's own anchors are core's and schema's titles tables — 4,571 B minified of titles
@@ -1,8 +1,10 @@
1
1
  // Single responsibility: the production `Transport` — core NATS for fanout, JetStream KV for the
2
- // shared presence sets. The client underneath owns the wire and the reconnect, including
3
- // re-establishing subscriptions, which is what makes a `sync` node stateless. The one loss it does
4
- // not own is its own end: a client closed for good once its reconnect budget is spent is replaced
5
- // here, on our backoff, and every kept subscription is bound again on the new one.
2
+ // shared presence sets.
3
+ //
4
+ // The client underneath owns the wire and the reconnect, including re-establishing subscriptions,
5
+ // which is what makes a `sync` node stateless. The one loss it does not own is its own end: a
6
+ // client closed for good once its reconnect budget is spent is replaced here, on our backoff, and
7
+ // every kept subscription is bound again on the new one.
6
8
  //
7
9
  // Two ways to open it, because two kinds of process hold one. A node that SERVES from the bus
8
10
  // awaits `connect()` and refuses to boot without it; a process that only PUBLISHES calls
@@ -1,8 +1,10 @@
1
1
  // The refusals a BROWSER can reach — the page store, the hooks, the socket's wire check, the local
2
- // store. Apart from `errors.ts` for bytes: that module holds the sync node's refusal classes, which
3
- // no island constructs. The codes and their titles are `error-titles.ts` (the module
4
- // `package.json`'s `sideEffects` names, imported bare by the barrel), so a code constructed here is
5
- // titled wherever the barrel was reached. This module runs nothing at import.
2
+ // store.
3
+ //
4
+ // Apart from `errors.ts` for bytes: that module holds the sync node's refusal classes, which no
5
+ // island constructs. The codes and their titles are `error-titles.ts` (the module `package.json`'s
6
+ // `sideEffects` names, imported bare by the barrel), so a code constructed here is titled wherever
7
+ // the barrel was reached. This module runs nothing at import.
6
8
 
7
9
  import { renderFixShellArg } from '@ultimat3/core/page';
8
10
  import { RealtimeError } from './realtime-error';
package/src/server.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  // The SERVER half of the public API: the bus, the Postgres replication path, the sync node and the
2
- // live-query registry it fans out through. Split from `index.ts` because `nats` require()s
3
- // `stream/web` and the WAL decoder is a Postgres client — one barrel carrying both made the browser
4
- // island realtime promises unbuildable. Every name here has exactly one home; the shared
5
- // vocabulary (the wire, the errors, `LiveRow`, the backoff) stays on `@ultimat3/realtime`.
2
+ // live-query registry it fans out through.
3
+ //
4
+ // Split from `index.ts` because `nats` require()s `stream/web` and the WAL decoder is a Postgres
5
+ // client — one barrel carrying both made the browser island realtime promises unbuildable. Every
6
+ // name here has exactly one home; the shared vocabulary (the wire, the errors, `LiveRow`, the
7
+ // backoff) stays on `@ultimat3/realtime`.
6
8
 
7
9
  // The server-only codes' titles (`sideEffects`): a process that loads this barrel titles them,
8
10
  // whichever class it constructs first.
@@ -1,8 +1,10 @@
1
1
  // The socket engine (plan 101, slice 11): ONE sync socket shared by every tab of an origin and
2
- // principal, talking to each tab only over a `MessagePort`. Host-agnostic — the SharedWorker entry
3
- // and the in-page fallback run this same code. Each tab keeps its own `LiveClient` and store; to
4
- // it, its port IS a socket. This file is the socket's lifecycle — dial, beat, redial, reap; the
5
- // multiplexing (one membership per topic, frames routed per port) is `socket-routes.ts`.
2
+ // principal, talking to each tab only over a `MessagePort`.
3
+ //
4
+ // Host-agnostic — the SharedWorker entry and the in-page fallback run this same code. Each tab
5
+ // keeps its own `LiveClient` and store; to it, its port IS a socket. This file is the socket's
6
+ // lifecycle — dial, beat, redial, reap; the multiplexing (one membership per topic, frames routed
7
+ // per port) is `socket-routes.ts`.
6
8
 
7
9
  import { type Clock, finiteOption, systemClock } from '@ultimat3/core/page';
8
10
  import type { ClientSocket } from './client-contract';
package/src/socket.ts CHANGED
@@ -1,9 +1,11 @@
1
- // One WS connection. Bun's WS profile is what makes a million sockets affordable, so this object
2
- // is deliberately lean: ~8 fields, two small sets and one token bucket (the frame budget, which is
3
- // five numbers and the only thing standing between one authenticated socket and this node's whole
4
- // subscribe path). Budget is ~1KB of JS heap per connection on top of Bun's own per-socket cost —
5
- // anything richer (row caches, per-socket buffers) belongs in the transport or the change buffer,
6
- // never here. `sync` is stateless: nothing on this object survives a restart, and nothing needs to.
1
+ // One WS connection, deliberately lean: ~8 fields, two small sets and one token bucket.
2
+ //
3
+ // Bun's WS profile is what makes a million sockets affordable, and this object must not spend it.
4
+ // The token bucket is the frame budget: five numbers, and the only thing standing between one
5
+ // authenticated socket and this node's whole subscribe path.
6
+ // Budget is ~1KB of JS heap per connection on top of Bun's own per-socket cost — anything richer
7
+ // (row caches, per-socket buffers) belongs in the transport or the change buffer, never here.
8
+ // `sync` is stateless: nothing on this object survives a restart, and nothing needs to.
7
9
 
8
10
  import {
9
11
  type Actor,
@@ -1,8 +1,10 @@
1
- // Single responsibility: environment → fanout transport. The one place a boot
2
- // decides whether this process fans changes out inside its own heap or over NATS, so `x dev`, a
3
- // `sync` container and any custom host resolve it identically. The KV bucket and the presence TTL are decided here too:
4
- // the bucket's whole-stream age limit and `PresenceRegistry`'s TTL are the same number seen from
5
- // two sides, and a caller that had to pass each one separately could quietly set them apart.
1
+ // Single responsibility: environment → fanout transport. The one place a boot decides whether this
2
+ // process fans changes out inside its own heap or over NATS, so `x dev`, a `sync` container and any
3
+ // custom host resolve it identically.
4
+ //
5
+ // The KV bucket and the presence TTL are decided here too: the bucket's whole-stream age limit and
6
+ // `PresenceRegistry`'s TTL are the same number seen from two sides, and a caller that had to pass
7
+ // each one separately could quietly set them apart.
6
8
 
7
9
  import type { Clock } from '@ultimat3/core';
8
10
  import { finiteOption } from '@ultimat3/core';