@rljson/server 0.0.6 → 0.0.8

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.
@@ -134,6 +134,8 @@ The `Server` class acts as a central coordination point that:
134
134
  - Broadcasts notifications between clients
135
135
  - Provides read access to its own local storage
136
136
 
137
+ **Relay mode (`disableLocalCache: true`):** When the `disableLocalCache` option is set, the server omits the local IoMem/BsMem from its IoMulti/BsMulti stacks. In this mode the server reads all data exclusively from connected client peers, acting as a pure relay without caching any data locally. This is useful for memory-constrained deployments where the server should not retain copies of client data.
138
+
137
139
  **Data Flow Architecture:**
138
140
 
139
141
  ```text
package/README.public.md CHANGED
@@ -176,6 +176,7 @@ This is implemented with `IoMulti` and `BsMulti` internally, but the public API
176
176
  - `bs` – Bs interface used by server
177
177
  - `clients` – `Map` of connected clients (keyed by internal clientId)
178
178
  - `isTornDown` – whether the server has been shut down
179
+ - `isLocalCacheDisabled` – whether local caching is disabled (pure relay mode)
179
180
  - `logger` – the `ServerLogger` instance (defaults to `noopLogger`)
180
181
 
181
182
  ## Example
@@ -306,17 +307,19 @@ const server = new Server(route, io, bs, {
306
307
  logger: new ConsoleLogger(), // Structured logging (default: NoopLogger)
307
308
  refEvictionIntervalMs: 60_000, // Ref dedup sweep interval (default: 60 s, 0 = disable)
308
309
  peerInitTimeoutMs: 30_000, // Peer handshake timeout (default: 30 s, 0 = disable)
310
+ disableLocalCache: true, // Pure relay mode — no local Io/Bs cache (default: false)
309
311
  });
310
312
  ```
311
313
 
312
- | Option | Default | Description |
313
- | ----------------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------- |
314
- | `logger` | NoopLogger | Structured logger for lifecycle, traffic, and error events. |
315
- | `refEvictionIntervalMs` | 60 000 | Two-generation sweep interval for multicast ref dedup. Refs older than two intervals are forgotten, preventing unbounded memory growth. |
316
- | `peerInitTimeoutMs` | 30 000 | Maximum time `addSocket()` waits for a peer to initialize. Prevents hanging on unresponsive clients. |
317
- | `syncConfig` | undefined | Sync protocol configuration (see below). Enables ACK aggregation, gap-fill, and enriched payloads. |
318
- | `refLogSize` | 1 000 | Maximum number of recent payloads retained in the ref log for gap-fill responses. |
319
- | `ackTimeoutMs` | 10 000 | Timeout for collecting individual client ACKs before emitting the aggregated ACK. Falls back to `syncConfig.ackTimeoutMs`. |
314
+ | Option | Default | Description |
315
+ | ----------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
316
+ | `logger` | NoopLogger | Structured logger for lifecycle, traffic, and error events. |
317
+ | `refEvictionIntervalMs` | 60 000 | Two-generation sweep interval for multicast ref dedup. Refs older than two intervals are forgotten, preventing unbounded memory growth. |
318
+ | `peerInitTimeoutMs` | 30 000 | Maximum time `addSocket()` waits for a peer to initialize. Prevents hanging on unresponsive clients. |
319
+ | `syncConfig` | undefined | Sync protocol configuration (see below). Enables ACK aggregation, gap-fill, and enriched payloads. |
320
+ | `refLogSize` | 1 000 | Maximum number of recent payloads retained in the ref log for gap-fill responses. |
321
+ | `ackTimeoutMs` | 10 000 | Timeout for collecting individual client ACKs before emitting the aggregated ACK. Falls back to `syncConfig.ackTimeoutMs`. |
322
+ | `disableLocalCache` | false | When true, the server skips creating local IoMem/BsMem caches. The server acts as a pure relay, reading data only from connected client peers. Useful for memory-constrained deployments. |
320
323
 
321
324
  ## Client options
322
325
 
@@ -134,6 +134,8 @@ The `Server` class acts as a central coordination point that:
134
134
  - Broadcasts notifications between clients
135
135
  - Provides read access to its own local storage
136
136
 
137
+ **Relay mode (`disableLocalCache: true`):** When the `disableLocalCache` option is set, the server omits the local IoMem/BsMem from its IoMulti/BsMulti stacks. In this mode the server reads all data exclusively from connected client peers, acting as a pure relay without caching any data locally. This is useful for memory-constrained deployments where the server should not retain copies of client data.
138
+
137
139
  **Data Flow Architecture:**
138
140
 
139
141
  ```text
@@ -176,6 +176,7 @@ This is implemented with `IoMulti` and `BsMulti` internally, but the public API
176
176
  - `bs` – Bs interface used by server
177
177
  - `clients` – `Map` of connected clients (keyed by internal clientId)
178
178
  - `isTornDown` – whether the server has been shut down
179
+ - `isLocalCacheDisabled` – whether local caching is disabled (pure relay mode)
179
180
  - `logger` – the `ServerLogger` instance (defaults to `noopLogger`)
180
181
 
181
182
  ## Example
@@ -306,17 +307,19 @@ const server = new Server(route, io, bs, {
306
307
  logger: new ConsoleLogger(), // Structured logging (default: NoopLogger)
307
308
  refEvictionIntervalMs: 60_000, // Ref dedup sweep interval (default: 60 s, 0 = disable)
308
309
  peerInitTimeoutMs: 30_000, // Peer handshake timeout (default: 30 s, 0 = disable)
310
+ disableLocalCache: true, // Pure relay mode — no local Io/Bs cache (default: false)
309
311
  });
310
312
  ```
311
313
 
312
- | Option | Default | Description |
313
- | ----------------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------- |
314
- | `logger` | NoopLogger | Structured logger for lifecycle, traffic, and error events. |
315
- | `refEvictionIntervalMs` | 60 000 | Two-generation sweep interval for multicast ref dedup. Refs older than two intervals are forgotten, preventing unbounded memory growth. |
316
- | `peerInitTimeoutMs` | 30 000 | Maximum time `addSocket()` waits for a peer to initialize. Prevents hanging on unresponsive clients. |
317
- | `syncConfig` | undefined | Sync protocol configuration (see below). Enables ACK aggregation, gap-fill, and enriched payloads. |
318
- | `refLogSize` | 1 000 | Maximum number of recent payloads retained in the ref log for gap-fill responses. |
319
- | `ackTimeoutMs` | 10 000 | Timeout for collecting individual client ACKs before emitting the aggregated ACK. Falls back to `syncConfig.ackTimeoutMs`. |
314
+ | Option | Default | Description |
315
+ | ----------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
316
+ | `logger` | NoopLogger | Structured logger for lifecycle, traffic, and error events. |
317
+ | `refEvictionIntervalMs` | 60 000 | Two-generation sweep interval for multicast ref dedup. Refs older than two intervals are forgotten, preventing unbounded memory growth. |
318
+ | `peerInitTimeoutMs` | 30 000 | Maximum time `addSocket()` waits for a peer to initialize. Prevents hanging on unresponsive clients. |
319
+ | `syncConfig` | undefined | Sync protocol configuration (see below). Enables ACK aggregation, gap-fill, and enriched payloads. |
320
+ | `refLogSize` | 1 000 | Maximum number of recent payloads retained in the ref log for gap-fill responses. |
321
+ | `ackTimeoutMs` | 10 000 | Timeout for collecting individual client ACKs before emitting the aggregated ACK. Falls back to `syncConfig.ackTimeoutMs`. |
322
+ | `disableLocalCache` | false | When true, the server skips creating local IoMem/BsMem caches. The server acts as a pure relay, reading data only from connected client peers. Useful for memory-constrained deployments. |
320
323
 
321
324
  ## Client options
322
325
 
package/dist/server.d.ts CHANGED
@@ -41,6 +41,14 @@ export interface ServerOptions {
41
41
  * Defaults to the SyncConfig's ackTimeoutMs (or 10 000 ms).
42
42
  */
43
43
  ackTimeoutMs?: number;
44
+ /**
45
+ * When true, the server's IoMulti and BsMulti will NOT include a local
46
+ * in-memory cache (IoMem / BsMem). The server will only read data from
47
+ * connected client peers. Useful when the server should act as a pure
48
+ * relay without caching any data locally.
49
+ * Defaults to false (local cache enabled).
50
+ */
51
+ disableLocalCache?: boolean;
44
52
  }
45
53
  export declare class Server extends BaseNode {
46
54
  private _route;
@@ -66,6 +74,7 @@ export declare class Server extends BaseNode {
66
74
  private _refLog;
67
75
  private _refLogSize;
68
76
  private _ackTimeoutMs;
77
+ private _disableLocalCache;
69
78
  private _latestRef;
70
79
  private _bootstrapHeartbeatTimer?;
71
80
  private _tornDown;
@@ -126,10 +135,18 @@ export declare class Server extends BaseNode {
126
135
  * Returns the typed sync event names.
127
136
  */
128
137
  get events(): SyncEventNames;
138
+ /**
139
+ * Returns the configured maximum ref log size.
140
+ */
141
+ get refLogSize(): number;
129
142
  /**
130
143
  * Returns the current ref log contents (for diagnostics / testing).
131
144
  */
132
145
  get refLog(): readonly ConnectorPayload[];
146
+ /**
147
+ * Returns whether the local cache is disabled.
148
+ */
149
+ get isLocalCacheDisabled(): boolean;
133
150
  /**
134
151
  * Returns the latest ref tracked by the server (for bootstrap / diagnostics).
135
152
  */
package/dist/server.js CHANGED
@@ -1407,6 +1407,7 @@ class Server extends BaseNode {
1407
1407
  this._localBs = _localBs;
1408
1408
  this._logger = options?.logger ?? noopLogger;
1409
1409
  this._peerInitTimeoutMs = options?.peerInitTimeoutMs ?? 3e4;
1410
+ this._disableLocalCache = options?.disableLocalCache ?? false;
1410
1411
  this._syncConfig = options?.syncConfig;
1411
1412
  this._refLogSize = options?.refLogSize ?? 1e3;
1412
1413
  this._ackTimeoutMs = options?.ackTimeoutMs ?? options?.syncConfig?.ackTimeoutMs ?? 1e4;
@@ -1422,23 +1423,27 @@ class Server extends BaseNode {
1422
1423
  }, evictionMs);
1423
1424
  this._refEvictionTimer.unref();
1424
1425
  }
1425
- const ioMultiIoLocal = {
1426
- io: this._localIo,
1427
- dump: true,
1428
- read: true,
1429
- write: true,
1430
- priority: 1
1431
- };
1432
- this._ios.push(ioMultiIoLocal);
1426
+ if (!this._disableLocalCache) {
1427
+ const ioMultiIoLocal = {
1428
+ io: this._localIo,
1429
+ dump: true,
1430
+ read: true,
1431
+ write: true,
1432
+ priority: 1
1433
+ };
1434
+ this._ios.push(ioMultiIoLocal);
1435
+ }
1433
1436
  this._ioMulti = new IoMulti(this._ios);
1434
1437
  this._ioServer = new IoServer(this._ioMulti);
1435
- const bsMultiBsLocal = {
1436
- bs: this._localBs,
1437
- read: true,
1438
- write: true,
1439
- priority: 1
1440
- };
1441
- this._bss.push(bsMultiBsLocal);
1438
+ if (!this._disableLocalCache) {
1439
+ const bsMultiBsLocal = {
1440
+ bs: this._localBs,
1441
+ read: true,
1442
+ write: true,
1443
+ priority: 1
1444
+ };
1445
+ this._bss.push(bsMultiBsLocal);
1446
+ }
1442
1447
  this._bsMulti = new BsMulti(this._bss);
1443
1448
  this._bsServer = new BsServer(this._bsMulti);
1444
1449
  }
@@ -1471,6 +1476,8 @@ class Server extends BaseNode {
1471
1476
  _refLog = [];
1472
1477
  _refLogSize;
1473
1478
  _ackTimeoutMs;
1479
+ // Local cache toggle
1480
+ _disableLocalCache;
1474
1481
  // Bootstrap state
1475
1482
  _latestRef;
1476
1483
  _bootstrapHeartbeatTimer;
@@ -1660,12 +1667,24 @@ class Server extends BaseNode {
1660
1667
  get events() {
1661
1668
  return this._events;
1662
1669
  }
1670
+ /**
1671
+ * Returns the configured maximum ref log size.
1672
+ */
1673
+ get refLogSize() {
1674
+ return this._refLogSize;
1675
+ }
1663
1676
  /**
1664
1677
  * Returns the current ref log contents (for diagnostics / testing).
1665
1678
  */
1666
1679
  get refLog() {
1667
1680
  return this._refLog;
1668
1681
  }
1682
+ /**
1683
+ * Returns whether the local cache is disabled.
1684
+ */
1685
+ get isLocalCacheDisabled() {
1686
+ return this._disableLocalCache;
1687
+ }
1669
1688
  /**
1670
1689
  * Returns the latest ref tracked by the server (for bootstrap / diagnostics).
1671
1690
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/server",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Rljson server description",
5
5
  "homepage": "https://github.com/rljson/server",
6
6
  "bugs": "https://github.com/rljson/server/issues",