@rljson/rljson 0.0.90 → 0.0.91

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.
@@ -635,11 +635,19 @@ The payload transmitted on the wire between Connector and Server:
635
635
  | `cksum` | `string` | Acknowledgment | Content checksum for ACK verification |
636
636
  | `stamp` | `RefStamp` | Hub order | Where a stamping hub placed the ref |
637
637
  | `src` | `string` | Source node | Node to read the ref's data from first |
638
+ | `holders` | `RouteHolders` | Holders | Which node holds which ref of the route |
638
639
 
639
640
  `src` is set by the relaying hub, never by the sender: the node id of the
640
641
  client it received the ref from, or nothing when it does not know that node.
641
642
  It is a hint for readers; the hub can always serve the data.
642
643
 
644
+ `holders` is set by a hub on what it sends its clients — relayed refs, the
645
+ bootstrap, the state beacon: per node id, the newest ref that node holds
646
+ completely (`RouteHolders`). A node enters it as the sender of a ref, or by
647
+ sending a `HeldPayload` (`{ r }`) on `${route}:held`, and leaves it when its
648
+ last connection to the hub ends. Only nodes the receiver may read from are
649
+ named. A hint like `src`.
650
+
643
651
  ### AckPayload
644
652
 
645
653
  Server → Client acknowledgment that all (or some) receivers successfully
@@ -701,6 +709,7 @@ Helper to generate typed socket event names from a route:
701
709
  | `${route}:gapfill:res` | server → client | Supply missing refs |
702
710
  | `${route}:bootstrap` | server → client | Latest ref on connect / heartbeat |
703
711
  | `${route}:stamp` | server → sender | The stamp its announced ref got |
712
+ | `${route}:held` | client → server | Its node holds a ref completely |
704
713
 
705
714
  ### ClientId
706
715
 
@@ -776,6 +785,7 @@ src/
776
785
  │ ├── client-id.ts # ClientId, clientId(), isClientId()
777
786
  │ ├── connector-payload.ts # ConnectorPayload
778
787
  │ ├── gap-fill.ts # GapFillRequest, GapFillResponse
788
+ │ ├── route-holders.ts # RouteHolders, HeldPayload
779
789
  │ ├── sync-config.ts # SyncConfig
780
790
  │ └── sync-events.ts # SyncEventNames, syncEvents()
781
791
  │
package/README.public.md CHANGED
@@ -286,6 +286,7 @@ const enriched: ConnectorPayload = {
286
286
  cksum: 'sha256:...', // content checksum
287
287
  stamp: { domain: 'office', epoch: 3, hub: 'node-7', n: 12 }, // hub order
288
288
  src: 'node-3', // set by the relaying hub: the node it came from
289
+ holders: { 'node-3': 'ref', 'node-5': 'prev-timeId' }, // set by the hub
289
290
  };
290
291
  ```
291
292
 
@@ -293,6 +294,11 @@ A hub sets `src` when it relays a ref: the node id of the client it received
293
294
  the ref from. A receiver may read the ref's data from that node first; the
294
295
  field is a hint, and the hub can still serve the data.
295
296
 
297
+ A hub also sets `holders` on what it sends: per node, the newest ref that node
298
+ holds completely (`RouteHolders`). A client says its node holds a ref by
299
+ sending a `HeldPayload` (`{ r }`) on `syncEvents(route).held`. A reader may ask
300
+ these nodes for the data before the hub.
301
+
296
302
  ### AckPayload
297
303
 
298
304
  Server → Client acknowledgment that all (or some) receivers got a ref.
@@ -635,11 +635,19 @@ The payload transmitted on the wire between Connector and Server:
635
635
  | `cksum` | `string` | Acknowledgment | Content checksum for ACK verification |
636
636
  | `stamp` | `RefStamp` | Hub order | Where a stamping hub placed the ref |
637
637
  | `src` | `string` | Source node | Node to read the ref's data from first |
638
+ | `holders` | `RouteHolders` | Holders | Which node holds which ref of the route |
638
639
 
639
640
  `src` is set by the relaying hub, never by the sender: the node id of the
640
641
  client it received the ref from, or nothing when it does not know that node.
641
642
  It is a hint for readers; the hub can always serve the data.
642
643
 
644
+ `holders` is set by a hub on what it sends its clients — relayed refs, the
645
+ bootstrap, the state beacon: per node id, the newest ref that node holds
646
+ completely (`RouteHolders`). A node enters it as the sender of a ref, or by
647
+ sending a `HeldPayload` (`{ r }`) on `${route}:held`, and leaves it when its
648
+ last connection to the hub ends. Only nodes the receiver may read from are
649
+ named. A hint like `src`.
650
+
643
651
  ### AckPayload
644
652
 
645
653
  Server → Client acknowledgment that all (or some) receivers successfully
@@ -701,6 +709,7 @@ Helper to generate typed socket event names from a route:
701
709
  | `${route}:gapfill:res` | server → client | Supply missing refs |
702
710
  | `${route}:bootstrap` | server → client | Latest ref on connect / heartbeat |
703
711
  | `${route}:stamp` | server → sender | The stamp its announced ref got |
712
+ | `${route}:held` | client → server | Its node holds a ref completely |
704
713
 
705
714
  ### ClientId
706
715
 
@@ -776,6 +785,7 @@ src/
776
785
  │ ├── client-id.ts # ClientId, clientId(), isClientId()
777
786
  │ ├── connector-payload.ts # ConnectorPayload
778
787
  │ ├── gap-fill.ts # GapFillRequest, GapFillResponse
788
+ │ ├── route-holders.ts # RouteHolders, HeldPayload
779
789
  │ ├── sync-config.ts # SyncConfig
780
790
  │ └── sync-events.ts # SyncEventNames, syncEvents()
781
791
  │
@@ -286,6 +286,7 @@ const enriched: ConnectorPayload = {
286
286
  cksum: 'sha256:...', // content checksum
287
287
  stamp: { domain: 'office', epoch: 3, hub: 'node-7', n: 12 }, // hub order
288
288
  src: 'node-3', // set by the relaying hub: the node it came from
289
+ holders: { 'node-3': 'ref', 'node-5': 'prev-timeId' }, // set by the hub
289
290
  };
290
291
  ```
291
292
 
@@ -293,6 +294,11 @@ A hub sets `src` when it relays a ref: the node id of the client it received
293
294
  the ref from. A receiver may read the ref's data from that node first; the
294
295
  field is a hint, and the hub can still serve the data.
295
296
 
297
+ A hub also sets `holders` on what it sends: per node, the newest ref that node
298
+ holds completely (`RouteHolders`). A client says its node holds a ref by
299
+ sending a `HeldPayload` (`{ r }`) on `syncEvents(route).held`. A reader may ask
300
+ these nodes for the data before the hub.
301
+
296
302
  ### AckPayload
297
303
 
298
304
  Server → Client acknowledgment that all (or some) receivers got a ref.
@@ -50,9 +50,6 @@ export interface Cake extends Json {
50
50
  */
51
51
  export type CakesTable = RljsonTable<Cake, 'cakes'>;
52
52
  /**
53
- * Sample Table as BoilerPlate for Tests and Examples
54
- */
55
- /**pnpm build
56
53
  * Sample Table as BoilerPlate for Tests and Examples
57
54
  * @param cakeKey - the key of the cake table cfg
58
55
  */
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export * from './sync/conflict.ts';
22
22
  export * from './sync/connector-payload.ts';
23
23
  export * from './sync/gap-fill.ts';
24
24
  export * from './sync/ref-stamp.ts';
25
+ export * from './sync/route-holders.ts';
25
26
  export * from './sync/sync-config.ts';
26
27
  export * from './sync/sync-events.ts';
27
28
  export * from './tables/tables.ts';
package/dist/rljson.js CHANGED
@@ -435,9 +435,6 @@ var exampleBuffetsTable = () => bakeryExample().buffets;
435
435
  // @license
436
436
  /**
437
437
  * Sample Table as BoilerPlate for Tests and Examples
438
- */
439
- /**pnpm build
440
- * Sample Table as BoilerPlate for Tests and Examples
441
438
  * @param cakeKey - the key of the cake table cfg
442
439
  */
443
440
  var createCakeTableCfg = (cakeKey) => ({
@@ -1938,6 +1935,22 @@ var isClientId = (id) => {
1938
1935
  * Returns an example ClientId for documentation and testing.
1939
1936
  */
1940
1937
  var clientIdExample = () => "client_ExAmPlE12345";
1938
+ // src/sync/route-holders.ts
1939
+ // @license
1940
+ /**
1941
+ * Returns an example of the holders of a route.
1942
+ * @returns Two nodes on the newer ref, one on an older one.
1943
+ */
1944
+ var routeHoldersExample = () => ({
1945
+ node_ExAmPlE: "1700000000001:EfGh",
1946
+ node_OtHeR: "1700000000001:EfGh",
1947
+ node_BeHiNd: "1700000000000:XyZw"
1948
+ });
1949
+ /**
1950
+ * Returns an example held payload.
1951
+ * @returns The payload.
1952
+ */
1953
+ var heldPayloadExample = () => ({ r: "1700000000001:EfGh" });
1941
1954
  // src/sync/connector-payload.ts
1942
1955
  // @license
1943
1956
  /**
@@ -1964,7 +1977,8 @@ var connectorPayloadFullExample = () => ({
1964
1977
  hub: "hub_ExAmPlE",
1965
1978
  n: 1
1966
1979
  },
1967
- src: "node_ExAmPlE"
1980
+ src: "node_ExAmPlE",
1981
+ holders: routeHoldersExample()
1968
1982
  });
1969
1983
  // src/sync/gap-fill.ts
1970
1984
  // @license
@@ -2074,7 +2088,8 @@ var syncEvents = (route) => ({
2074
2088
  gapFillReq: `${route}:gapfill:req`,
2075
2089
  gapFillRes: `${route}:gapfill:res`,
2076
2090
  bootstrap: `${route}:bootstrap`,
2077
- stamp: `${route}:stamp`
2091
+ stamp: `${route}:stamp`,
2092
+ held: `${route}:held`
2078
2093
  });
2079
2094
  // src/tables/tables.ts
2080
2095
  // @license
@@ -3037,4 +3052,4 @@ var Validate = class {
3037
3052
  };
3038
3053
  // src/index.ts
3039
3054
  // @license
3040
- export { BaseValidator, Example, InsertValidator, Route, Tables, Validate, ackPayloadExample, ackPayloadPartialExample, addColumnsToTableCfg, bakeryExample, clientId, clientIdExample, compareRefStamp, connectorPayloadExample, connectorPayloadFullExample, contentTypes, createCakeTableCfg, createEditHistoryTableCfg, createEditTableCfg, createInsertHistoryTableCfg, createLayerTableCfg, createMultiEditTableCfg, createSliceIdsTableCfg, createTreesTableCfg, exampleBuffetsTable, exampleCakesTable, exampleComponentsTable, exampleInsert, exampleInsertHistoryTable, exampleLayersTable, exampleRevision, exampleRljson, exampleSliceIdsTable, exampleTableCfg, exampleTableCfgTable, exampleTreesTable, exampleTypedefs, gapFillRequestExample, gapFillResponseExample, getTimeIdTimestamp, getTimeIdUniquePart, isClientId, isRefStamp, isTimeId, isValidFieldName, iterateTables, iterateTablesSync, mergeSliceIds, ref, refStampExample, removeDuplicates, reservedFieldNames, reservedTableKeys, resolveSliceIds, routeRefSeperator, routeSliceIdIndicators, routeSliceIdSeperator, rowOf, stampPayloadExample, syncConfigCausalOnlyExample, syncConfigDefault, syncConfigFullExample, syncEvents, throwOnInvalidTableCfg, timeId, treeFromObject, validateInsert, validateRljsonAgainstTableCfg };
3055
+ export { BaseValidator, Example, InsertValidator, Route, Tables, Validate, ackPayloadExample, ackPayloadPartialExample, addColumnsToTableCfg, bakeryExample, clientId, clientIdExample, compareRefStamp, connectorPayloadExample, connectorPayloadFullExample, contentTypes, createCakeTableCfg, createEditHistoryTableCfg, createEditTableCfg, createInsertHistoryTableCfg, createLayerTableCfg, createMultiEditTableCfg, createSliceIdsTableCfg, createTreesTableCfg, exampleBuffetsTable, exampleCakesTable, exampleComponentsTable, exampleInsert, exampleInsertHistoryTable, exampleLayersTable, exampleRevision, exampleRljson, exampleSliceIdsTable, exampleTableCfg, exampleTableCfgTable, exampleTreesTable, exampleTypedefs, gapFillRequestExample, gapFillResponseExample, getTimeIdTimestamp, getTimeIdUniquePart, heldPayloadExample, isClientId, isRefStamp, isTimeId, isValidFieldName, iterateTables, iterateTablesSync, mergeSliceIds, ref, refStampExample, removeDuplicates, reservedFieldNames, reservedTableKeys, resolveSliceIds, routeHoldersExample, routeRefSeperator, routeSliceIdIndicators, routeSliceIdSeperator, rowOf, stampPayloadExample, syncConfigCausalOnlyExample, syncConfigDefault, syncConfigFullExample, syncEvents, throwOnInvalidTableCfg, timeId, treeFromObject, validateInsert, validateRljsonAgainstTableCfg };
@@ -1,2 +1,2 @@
1
1
  /** The version of the `@rljson/rljson` package. */
2
- export declare const rljsonVersion = "0.0.90";
2
+ export declare const rljsonVersion = "0.0.91";
@@ -1,6 +1,7 @@
1
1
  import { InsertHistoryTimeId } from '../insertHistory/insertHistory.ts';
2
2
  import { ClientId } from './client-id.ts';
3
3
  import { RefStamp } from './ref-stamp.ts';
4
+ import { RouteHolders } from './route-holders.ts';
4
5
  /**
5
6
  * Wire-protocol payload transmitted between Connector and Server.
6
7
  *
@@ -9,17 +10,18 @@ import { RefStamp } from './ref-stamp.ts';
9
10
  * optional and activate only when the corresponding `SyncConfig`
10
11
  * flags are set.
11
12
  *
12
- * | Field | Concept | Purpose |
13
- * |---------|------------------------|----------------------------------------|
14
- * | `r` | existing | The ref being announced |
15
- * | `o` | existing | Ephemeral origin for self-echo filter |
16
- * | `c` | Client identity | Stable client id across reconnections |
17
- * | `t` | Client identity | Client-side wall-clock timestamp (ms) |
18
- * | `seq` | Predecessor chain | Monotonic counter per (client, route) |
19
- * | `p` | Predecessor chain | Causal predecessor timeIds |
20
- * | `cksum` | Acknowledgment | Content checksum for ACK verification |
21
- * | `stamp` | Hub order | Where a stamping hub placed the ref |
22
- * | `src` | Source node | Node to read the ref's data from first |
13
+ * | Field | Concept | Purpose |
14
+ * |-----------|-------------------|-----------------------------------------|
15
+ * | `r` | existing | The ref being announced |
16
+ * | `o` | existing | Ephemeral origin for self-echo filter |
17
+ * | `c` | Client identity | Stable client id across reconnections |
18
+ * | `t` | Client identity | Client-side wall-clock timestamp (ms) |
19
+ * | `seq` | Predecessor chain | Monotonic counter per (client, route) |
20
+ * | `p` | Predecessor chain | Causal predecessor timeIds |
21
+ * | `cksum` | Acknowledgment | Content checksum for ACK verification |
22
+ * | `stamp` | Hub order | Where a stamping hub placed the ref |
23
+ * | `src` | Source node | Node to read the ref's data from first |
24
+ * | `holders` | Holders | Which node holds which ref of the route |
23
25
  */
24
26
  export type ConnectorPayload = {
25
27
  /** The ref (InsertHistoryTimeId) being announced. */
@@ -53,6 +55,16 @@ export type ConnectorPayload = {
53
55
  * may be gone or unreachable, and the hub can still serve the data.
54
56
  */
55
57
  src?: string;
58
+ /**
59
+ * Which node holds which ref of the route, as the hub knows it: per node,
60
+ * the newest ref it holds completely.
61
+ *
62
+ * Set by a hub on what it sends its clients — relayed refs, the bootstrap,
63
+ * the state beacon — never by a sender: a hub overwrites what arrives. Only
64
+ * nodes the receiver may read from are named. A hint, like `src`: a reader
65
+ * may ask these nodes for the data before the hub.
66
+ */
67
+ holders?: RouteHolders;
56
68
  };
57
69
  /**
58
70
  * Returns a minimal example ConnectorPayload (backward-compatible format).
@@ -0,0 +1,35 @@
1
+ import { InsertHistoryTimeId } from '../insertHistory/insertHistory.ts';
2
+ /**
3
+ * Which node holds which state of a route: per node id, the newest ref the
4
+ * node holds completely — every row under it in its own store.
5
+ *
6
+ * A hub keeps one per route and sends it with what it sends its clients, so a
7
+ * reader knows which nodes it can read a ref's data from besides the hub. A
8
+ * node enters it as the sender of a ref, or by saying it holds one
9
+ * ({@link HeldPayload}), and leaves it when its last connection to the hub
10
+ * ends.
11
+ *
12
+ * A hint, not a promise: a node may have moved on, may be gone, or may lack a
13
+ * blob the rows name. The hub can still serve the data.
14
+ */
15
+ export type RouteHolders = Record<string, InsertHistoryTimeId>;
16
+ /**
17
+ * Client → Server: the client's node holds a ref of the route completely.
18
+ *
19
+ * Sent on `${route}:held` ({@link SyncEventNames.held}). It carries no node
20
+ * id: the hub knows which node a connection belongs to.
21
+ */
22
+ export type HeldPayload = {
23
+ /** The ref the node holds every row under. */
24
+ r: InsertHistoryTimeId;
25
+ };
26
+ /**
27
+ * Returns an example of the holders of a route.
28
+ * @returns Two nodes on the newer ref, one on an older one.
29
+ */
30
+ export declare const routeHoldersExample: () => RouteHolders;
31
+ /**
32
+ * Returns an example held payload.
33
+ * @returns The payload.
34
+ */
35
+ export declare const heldPayloadExample: () => HeldPayload;
@@ -25,6 +25,8 @@ export type SyncEventNames = {
25
25
  bootstrap: string;
26
26
  /** Server → Client (sender only): the stamp its announced ref received. */
27
27
  stamp: string;
28
+ /** Client → Server: the client's node holds a ref completely. */
29
+ held: string;
28
30
  };
29
31
  /**
30
32
  * Creates typed, route-specific socket event names for the sync protocol.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.90",
3
+ "version": "0.0.91",
4
4
  "description": "The RLJSON data format specification",
5
5
  "homepage": "https://github.com/rljson/rljson",
6
6
  "bugs": "https://github.com/rljson/rljson/issues",
@@ -27,8 +27,8 @@
27
27
  "@typescript-eslint/parser": "^8.74.0",
28
28
  "@vitest/coverage-v8": "^5.1.2",
29
29
  "cross-env": "^10.1.0",
30
- "eslint": "^10.15.0",
31
- "eslint-plugin-jsdoc": "^65.5.6",
30
+ "eslint": "^10.16.0",
31
+ "eslint-plugin-jsdoc": "^65.5.7",
32
32
  "eslint-plugin-tsdoc": "^0.5.4",
33
33
  "globals": "^17.14.0",
34
34
  "jsdoc": "^4.0.5",
@@ -48,7 +48,7 @@
48
48
  "nanoid": "^6.0.2"
49
49
  },
50
50
  "scripts": {
51
- "build": "pnpm test && vite build && tsc && cp README* dist && mkdir dist/src && cp src/example.ts dist/src",
51
+ "build": "pnpm test && vite build && tsc && node scripts/copy-readme-to-dist.js",
52
52
  "test": "vitest run --coverage && npm run lint",
53
53
  "lint": "eslint",
54
54
  "updateGoldens": "cross-env UPDATE_GOLDENS=true npm test"