@ultimat3/realtime 31.32.0 → 31.34.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 +5 -5
- package/src/client.ts +7 -7
- package/src/close-codes.ts +6 -5
- package/src/error-titles.ts +8 -6
- package/src/nats-transport.ts +6 -4
- package/src/page-errors.ts +6 -4
- package/src/server.ts +6 -4
- package/src/socket-engine.ts +6 -4
- package/src/socket.ts +8 -6
- package/src/transport-env.ts +7 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/realtime",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.34.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.
|
|
56
|
-
"@ultimat3/entity": "31.
|
|
57
|
-
"@ultimat3/policy": "31.
|
|
58
|
-
"@ultimat3/query": "31.
|
|
55
|
+
"@ultimat3/core": "31.34.0",
|
|
56
|
+
"@ultimat3/entity": "31.34.0",
|
|
57
|
+
"@ultimat3/policy": "31.34.0",
|
|
58
|
+
"@ultimat3/query": "31.34.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.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
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,
|
|
175
|
-
//
|
|
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
|
package/src/close-codes.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// The close codes this protocol speaks, defined once below both halves.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
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
|
package/src/error-titles.ts
CHANGED
|
@@ -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`.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
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
|
package/src/nats-transport.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: the production `Transport` — core NATS for fanout, JetStream KV for the
|
|
2
|
-
// shared presence sets.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
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
|
package/src/page-errors.ts
CHANGED
|
@@ -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.
|
|
3
|
-
//
|
|
4
|
-
// `
|
|
5
|
-
//
|
|
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.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
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.
|
package/src/socket-engine.ts
CHANGED
|
@@ -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`.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
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
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
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,
|
package/src/transport-env.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
// Single responsibility: environment → fanout transport. The one place a boot
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
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';
|