@rljson/rljson 0.0.85 → 0.0.87

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.
@@ -633,6 +633,7 @@ The payload transmitted on the wire between Connector and Server:
633
633
  | `seq` | `number` | Predecessor chain | Monotonic counter per (client, route) |
634
634
  | `p` | `InsertHistoryTimeId[]` | Predecessor chain | Causal predecessor timeIds |
635
635
  | `cksum` | `string` | Acknowledgment | Content checksum for ACK verification |
636
+ | `stamp` | `RefStamp` | Hub order | Where a stamping hub placed the ref |
636
637
 
637
638
  ### AckPayload
638
639
 
@@ -646,6 +647,14 @@ received and processed a ref:
646
647
  | `receivedBy` | `number` | Count of confirming clients |
647
648
  | `totalClients` | `number` | Total receiver clients at broadcast |
648
649
 
650
+ ### RefStamp
651
+
652
+ `(domain, epoch, hub, n)`, set by the first hub that relays a ref and forwarded
653
+ unchanged by every hub after it. Ordered lexicographically by
654
+ `compareRefStamp`, a total order computed from no clock. The sender of a ref is
655
+ excluded from the hub's fan-out, so it receives its stamp as a `StampPayload`
656
+ (`{ r, stamp }`) on `${route}:stamp`.
657
+
649
658
  ### GapFill
650
659
 
651
660
  When a Connector detects a gap in sequence numbers from a peer, it requests
@@ -686,6 +695,7 @@ Helper to generate typed socket event names from a route:
686
695
  | `${route}:gapfill:req` | client → server | Request missing refs |
687
696
  | `${route}:gapfill:res` | server → client | Supply missing refs |
688
697
  | `${route}:bootstrap` | server → client | Latest ref on connect / heartbeat |
698
+ | `${route}:stamp` | server → sender | The stamp its announced ref got |
689
699
 
690
700
  ### ClientId
691
701
 
package/README.public.md CHANGED
@@ -32,6 +32,7 @@ Core types, validation, and sync protocol for the RLJSON data format.
32
32
  - [Sync Protocol](#sync-protocol)
33
33
  - [ConnectorPayload](#connectorpayload)
34
34
  - [AckPayload](#ackpayload)
35
+ - [RefStamp](#refstamp)
35
36
  - [GapFill](#gapfill)
36
37
  - [SyncConfig](#syncconfig)
37
38
  - [SyncEventNames](#synceventnames)
@@ -283,6 +284,7 @@ const enriched: ConnectorPayload = {
283
284
  seq: 42, // monotonic sequence number
284
285
  p: ['prev-timeId'], // causal predecessors
285
286
  cksum: 'sha256:...', // content checksum
287
+ stamp: { domain: 'office', epoch: 3, hub: 'node-7', n: 12 }, // hub order
286
288
  };
287
289
  ```
288
290
 
@@ -301,6 +303,39 @@ const ack: AckPayload = {
301
303
  };
302
304
  ```
303
305
 
306
+ ### RefStamp
307
+
308
+ Where a stamping hub placed a ref in the order it relays them — a fact about
309
+ what the fleet saw, read from no clock. The first hub that relays a ref stamps
310
+ it; a hub that receives a payload already carrying a `stamp` forwards it
311
+ unchanged.
312
+
313
+ | Field | Meaning |
314
+ | -------- | ---------------------------------------------------- |
315
+ | `domain` | The network domain whose hub stamped the ref |
316
+ | `epoch` | Advanced each time a hub takes office in that domain |
317
+ | `hub` | The node id of the stamping hub |
318
+ | `n` | Monotonic within `(domain, epoch, hub)` |
319
+
320
+ `compareRefStamp` orders stamps lexicographically on `(domain, epoch, hub, n)`.
321
+ It is a total order, so every machine sorts the same stamps the same way, and
322
+ `hub` keeps two hubs that both believe they hold one epoch distinct.
323
+
324
+ A hub forwards an announcement to everyone except its sender, so the sender
325
+ learns its own stamp from a `StampPayload` on the `${route}:stamp` event.
326
+ `isRefStamp` checks a value received from the wire before anything orders by
327
+ it.
328
+
329
+ ```typescript
330
+ import { compareRefStamp, isRefStamp, RefStamp } from '@rljson/rljson';
331
+
332
+ const a: RefStamp = { domain: 'office', epoch: 3, hub: 'node-7', n: 12 };
333
+ const b: RefStamp = { domain: 'office', epoch: 4, hub: 'node-2', n: 1 };
334
+
335
+ compareRefStamp(a, b); // < 0 — a later epoch orders after, whatever its n
336
+ isRefStamp({ domain: 'office' }); // false
337
+ ```
338
+
304
339
  ### GapFill
305
340
 
306
341
  Types for requesting and receiving missing refs when a sequence gap is
@@ -347,6 +382,7 @@ const events = syncEvents('/sharedTree');
347
382
  // events.gapFillReq → '/sharedTree:gapfill:req'
348
383
  // events.gapFillRes → '/sharedTree:gapfill:res'
349
384
  // events.bootstrap → '/sharedTree:bootstrap'
385
+ // events.stamp → '/sharedTree:stamp'
350
386
  ```
351
387
 
352
388
  ### ClientId
@@ -633,6 +633,7 @@ The payload transmitted on the wire between Connector and Server:
633
633
  | `seq` | `number` | Predecessor chain | Monotonic counter per (client, route) |
634
634
  | `p` | `InsertHistoryTimeId[]` | Predecessor chain | Causal predecessor timeIds |
635
635
  | `cksum` | `string` | Acknowledgment | Content checksum for ACK verification |
636
+ | `stamp` | `RefStamp` | Hub order | Where a stamping hub placed the ref |
636
637
 
637
638
  ### AckPayload
638
639
 
@@ -646,6 +647,14 @@ received and processed a ref:
646
647
  | `receivedBy` | `number` | Count of confirming clients |
647
648
  | `totalClients` | `number` | Total receiver clients at broadcast |
648
649
 
650
+ ### RefStamp
651
+
652
+ `(domain, epoch, hub, n)`, set by the first hub that relays a ref and forwarded
653
+ unchanged by every hub after it. Ordered lexicographically by
654
+ `compareRefStamp`, a total order computed from no clock. The sender of a ref is
655
+ excluded from the hub's fan-out, so it receives its stamp as a `StampPayload`
656
+ (`{ r, stamp }`) on `${route}:stamp`.
657
+
649
658
  ### GapFill
650
659
 
651
660
  When a Connector detects a gap in sequence numbers from a peer, it requests
@@ -686,6 +695,7 @@ Helper to generate typed socket event names from a route:
686
695
  | `${route}:gapfill:req` | client → server | Request missing refs |
687
696
  | `${route}:gapfill:res` | server → client | Supply missing refs |
688
697
  | `${route}:bootstrap` | server → client | Latest ref on connect / heartbeat |
698
+ | `${route}:stamp` | server → sender | The stamp its announced ref got |
689
699
 
690
700
  ### ClientId
691
701
 
@@ -32,6 +32,7 @@ Core types, validation, and sync protocol for the RLJSON data format.
32
32
  - [Sync Protocol](#sync-protocol)
33
33
  - [ConnectorPayload](#connectorpayload)
34
34
  - [AckPayload](#ackpayload)
35
+ - [RefStamp](#refstamp)
35
36
  - [GapFill](#gapfill)
36
37
  - [SyncConfig](#syncconfig)
37
38
  - [SyncEventNames](#synceventnames)
@@ -283,6 +284,7 @@ const enriched: ConnectorPayload = {
283
284
  seq: 42, // monotonic sequence number
284
285
  p: ['prev-timeId'], // causal predecessors
285
286
  cksum: 'sha256:...', // content checksum
287
+ stamp: { domain: 'office', epoch: 3, hub: 'node-7', n: 12 }, // hub order
286
288
  };
287
289
  ```
288
290
 
@@ -301,6 +303,39 @@ const ack: AckPayload = {
301
303
  };
302
304
  ```
303
305
 
306
+ ### RefStamp
307
+
308
+ Where a stamping hub placed a ref in the order it relays them — a fact about
309
+ what the fleet saw, read from no clock. The first hub that relays a ref stamps
310
+ it; a hub that receives a payload already carrying a `stamp` forwards it
311
+ unchanged.
312
+
313
+ | Field | Meaning |
314
+ | -------- | ---------------------------------------------------- |
315
+ | `domain` | The network domain whose hub stamped the ref |
316
+ | `epoch` | Advanced each time a hub takes office in that domain |
317
+ | `hub` | The node id of the stamping hub |
318
+ | `n` | Monotonic within `(domain, epoch, hub)` |
319
+
320
+ `compareRefStamp` orders stamps lexicographically on `(domain, epoch, hub, n)`.
321
+ It is a total order, so every machine sorts the same stamps the same way, and
322
+ `hub` keeps two hubs that both believe they hold one epoch distinct.
323
+
324
+ A hub forwards an announcement to everyone except its sender, so the sender
325
+ learns its own stamp from a `StampPayload` on the `${route}:stamp` event.
326
+ `isRefStamp` checks a value received from the wire before anything orders by
327
+ it.
328
+
329
+ ```typescript
330
+ import { compareRefStamp, isRefStamp, RefStamp } from '@rljson/rljson';
331
+
332
+ const a: RefStamp = { domain: 'office', epoch: 3, hub: 'node-7', n: 12 };
333
+ const b: RefStamp = { domain: 'office', epoch: 4, hub: 'node-2', n: 1 };
334
+
335
+ compareRefStamp(a, b); // < 0 — a later epoch orders after, whatever its n
336
+ isRefStamp({ domain: 'office' }); // false
337
+ ```
338
+
304
339
  ### GapFill
305
340
 
306
341
  Types for requesting and receiving missing refs when a sequence gap is
@@ -347,6 +382,7 @@ const events = syncEvents('/sharedTree');
347
382
  // events.gapFillReq → '/sharedTree:gapfill:req'
348
383
  // events.gapFillRes → '/sharedTree:gapfill:res'
349
384
  // events.bootstrap → '/sharedTree:bootstrap'
385
+ // events.stamp → '/sharedTree:stamp'
350
386
  ```
351
387
 
352
388
  ### ClientId
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export * from './sync/client-id.ts';
21
21
  export * from './sync/conflict.ts';
22
22
  export * from './sync/connector-payload.ts';
23
23
  export * from './sync/gap-fill.ts';
24
+ export * from './sync/ref-stamp.ts';
24
25
  export * from './sync/sync-config.ts';
25
26
  export * from './sync/sync-events.ts';
26
27
  export * from './tables/tables.ts';
package/dist/rljson.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { hip, hsh } from "@rljson/hash";
2
2
  import { exampleJsonObject, jsonValueMatchesType, jsonValueType, jsonValueTypes } from "@rljson/json";
3
3
  import { nanoid } from "nanoid";
4
- //#region src/route/route.ts
4
+ // src/route/route.ts
5
5
  // @license
6
6
  var routeRefSeperator = "@";
7
7
  var routeSliceIdIndicators = ["(", ")"];
@@ -278,8 +278,7 @@ var Route = class Route {
278
278
  return this.segmentHasRef(segment) && Object.keys(segment).some((k) => k.endsWith("InsertHistoryRef"));
279
279
  }
280
280
  };
281
- //#endregion
282
- //#region src/example/bakery-example.ts
281
+ // src/example/bakery-example.ts
283
282
  // @license
284
283
  var bakeryExample = () => {
285
284
  const nutritionalValues = hip({
@@ -429,12 +428,10 @@ var bakeryExample = () => {
429
428
  })
430
429
  };
431
430
  };
432
- //#endregion
433
- //#region src/content/buffet.ts
431
+ // src/content/buffet.ts
434
432
  // @license
435
433
  var exampleBuffetsTable = () => bakeryExample().buffets;
436
- //#endregion
437
- //#region src/content/cake.ts
434
+ // src/content/cake.ts
438
435
  // @license
439
436
  /**
440
437
  * Sample Table as BoilerPlate for Tests and Examples
@@ -486,15 +483,13 @@ var createCakeTableCfg = (cakeKey) => ({
486
483
  * Provides an example cakes table for test purposes
487
484
  */
488
485
  var exampleCakesTable = () => bakeryExample().cakes;
489
- //#endregion
490
- //#region src/content/components.ts
486
+ // src/content/components.ts
491
487
  // @license
492
488
  /**
493
489
  * Provides an example components table for test purposes
494
490
  */
495
491
  var exampleComponentsTable = () => bakeryExample().nutritionalValues;
496
- //#endregion
497
- //#region src/content/layer.ts
492
+ // src/content/layer.ts
498
493
  // @license
499
494
  /**
500
495
  * Sample Table as BoilerPlate for Tests and Examples
@@ -555,8 +550,7 @@ var createLayerTableCfg = (layerKey) => ({
555
550
  * Provides an example layersTable for test purposes
556
551
  */
557
552
  var exampleLayersTable = () => bakeryExample().recipeLayers;
558
- //#endregion
559
- //#region src/content/revision.ts
553
+ // src/content/revision.ts
560
554
  // @license
561
555
  /**
562
556
  * Example revision object for test purposes
@@ -568,8 +562,7 @@ var exampleRevision = () => ({
568
562
  successor: "IqeoWJjZQNlr-NVk2QT15B",
569
563
  timestamp: 1743558427
570
564
  });
571
- //#endregion
572
- //#region src/content/slice-ids.ts
565
+ // src/content/slice-ids.ts
573
566
  // @license
574
567
  /**
575
568
  * Returns the slice ids table of the bakery example
@@ -613,8 +606,7 @@ var createSliceIdsTableCfg = (tableKey) => ({
613
606
  isRoot: false,
614
607
  isShared: true
615
608
  });
616
- //#endregion
617
- //#region src/content/tree.ts
609
+ // src/content/tree.ts
618
610
  // @license
619
611
  /**
620
612
  * Creates a TableCfg for Trees tables
@@ -770,8 +762,7 @@ var treeFromObject = (obj, skipRootCreation = false) => {
770
762
  }
771
763
  return result;
772
764
  };
773
- //#endregion
774
- //#region src/example.ts
765
+ // src/example.ts
775
766
  // @license
776
767
  var Example = class Example {
777
768
  static ok = {
@@ -1487,8 +1478,7 @@ var Example = class Example {
1487
1478
  }
1488
1479
  };
1489
1480
  };
1490
- //#endregion
1491
- //#region src/content/table-cfg.ts
1481
+ // src/content/table-cfg.ts
1492
1482
  // @license
1493
1483
  /**
1494
1484
  * Throws an error if the table configuration is not valid.
@@ -1581,8 +1571,7 @@ var exampleTableCfg = (tableCfg = void 0) => {
1581
1571
  isShared: false
1582
1572
  };
1583
1573
  };
1584
- //#endregion
1585
- //#region src/edit/edit-history.ts
1574
+ // src/edit/edit-history.ts
1586
1575
  // @license
1587
1576
  var createEditHistoryTableCfg = (cakeKey) => ({
1588
1577
  key: `${cakeKey}EditHistory`,
@@ -1625,8 +1614,7 @@ var createEditHistoryTableCfg = (cakeKey) => ({
1625
1614
  isRoot: false,
1626
1615
  isShared: true
1627
1616
  });
1628
- //#endregion
1629
- //#region src/edit/edit.ts
1617
+ // src/edit/edit.ts
1630
1618
  // @license
1631
1619
  var createEditTableCfg = (cakeKey) => ({
1632
1620
  key: `${cakeKey}Edits`,
@@ -1655,8 +1643,7 @@ var createEditTableCfg = (cakeKey) => ({
1655
1643
  isRoot: false,
1656
1644
  isShared: true
1657
1645
  });
1658
- //#endregion
1659
- //#region src/edit/multi-edit.ts
1646
+ // src/edit/multi-edit.ts
1660
1647
  // @license
1661
1648
  var createMultiEditTableCfg = (cakeKey) => ({
1662
1649
  key: `${cakeKey}MultiEdits`,
@@ -1686,12 +1673,10 @@ var createMultiEditTableCfg = (cakeKey) => ({
1686
1673
  isRoot: false,
1687
1674
  isShared: true
1688
1675
  });
1689
- //#endregion
1690
- //#region src/tools/object-depth.ts
1676
+ // src/tools/object-depth.ts
1691
1677
  // @license
1692
1678
  var objectDepth = (o) => Object(o) === o ? 1 + Math.max(-1, ...Object.values(o).map(objectDepth)) : 0;
1693
- //#endregion
1694
- //#region src/insert/insert-validator.ts
1679
+ // src/insert/insert-validator.ts
1695
1680
  // @license
1696
1681
  var InsertValidator = class InsertValidator {
1697
1682
  _insert;
@@ -1783,16 +1768,14 @@ var InsertValidator = class InsertValidator {
1783
1768
  var validateInsert = (insert) => {
1784
1769
  return InsertValidator.create(insert).validate();
1785
1770
  };
1786
- //#endregion
1787
- //#region src/insert/insert.ts
1771
+ // src/insert/insert.ts
1788
1772
  // @license
1789
1773
  var exampleInsert = () => ({
1790
1774
  route: "a/b/c",
1791
1775
  command: "add",
1792
1776
  value: { x: { y: { z: true } } }
1793
1777
  });
1794
- //#endregion
1795
- //#region src/insertHistory/insertHistory.ts
1778
+ // src/insertHistory/insertHistory.ts
1796
1779
  // @license
1797
1780
  /**
1798
1781
  * Creates a TableCfg for a InsertHistory table for the given table configuration
@@ -1858,8 +1841,7 @@ var createInsertHistoryTableCfg = (tableCfg) => ({
1858
1841
  * Provides an example insertHistory table for test purposes
1859
1842
  */
1860
1843
  var exampleInsertHistoryTable = () => bakeryExample().ingredientsInsertHistory;
1861
- //#endregion
1862
- //#region src/rljson.ts
1844
+ // src/rljson.ts
1863
1845
  // @license
1864
1846
  var reservedFieldNames = ["_data"];
1865
1847
  var reservedTableKeys = [
@@ -1912,8 +1894,7 @@ var iterateTables = async (rljson, callback) => {
1912
1894
  await Promise.all(array);
1913
1895
  if (errors.length) throw errors;
1914
1896
  };
1915
- //#endregion
1916
- //#region src/sync/ack-payload.ts
1897
+ // src/sync/ack-payload.ts
1917
1898
  // @license
1918
1899
  /**
1919
1900
  * Returns an example AckPayload where all clients confirmed receipt.
@@ -1933,8 +1914,7 @@ var ackPayloadPartialExample = () => ({
1933
1914
  receivedBy: 1,
1934
1915
  totalClients: 3
1935
1916
  });
1936
- //#endregion
1937
- //#region src/sync/client-id.ts
1917
+ // src/sync/client-id.ts
1938
1918
  // @license
1939
1919
  /**
1940
1920
  * Generates a new ClientId.
@@ -1960,8 +1940,7 @@ var isClientId = (id) => {
1960
1940
  * Returns an example ClientId for documentation and testing.
1961
1941
  */
1962
1942
  var clientIdExample = () => "client_ExAmPlE12345";
1963
- //#endregion
1964
- //#region src/sync/connector-payload.ts
1943
+ // src/sync/connector-payload.ts
1965
1944
  // @license
1966
1945
  /**
1967
1946
  * Returns a minimal example ConnectorPayload (backward-compatible format).
@@ -1980,10 +1959,15 @@ var connectorPayloadFullExample = () => ({
1980
1959
  t: 1700000000001,
1981
1960
  seq: 42,
1982
1961
  p: ["1700000000000:XyZw"],
1983
- cksum: "sha256:abc123def456"
1962
+ cksum: "sha256:abc123def456",
1963
+ stamp: {
1964
+ domain: "example",
1965
+ epoch: 1,
1966
+ hub: "hub_ExAmPlE",
1967
+ n: 1
1968
+ }
1984
1969
  });
1985
- //#endregion
1986
- //#region src/sync/gap-fill.ts
1970
+ // src/sync/gap-fill.ts
1987
1971
  // @license
1988
1972
  /**
1989
1973
  * Returns an example GapFillRequest.
@@ -2008,8 +1992,56 @@ var gapFillResponseExample = () => ({
2008
1992
  seq: 7
2009
1993
  }]
2010
1994
  });
2011
- //#endregion
2012
- //#region src/sync/sync-config.ts
1995
+ // src/sync/ref-stamp.ts
1996
+ // @license
1997
+ /**
1998
+ * Orders two stamps lexicographically on `(domain, epoch, hub, n)`.
1999
+ *
2000
+ * A total order: every pair compares the same way on every machine, and only
2001
+ * equal stamps compare as `0`.
2002
+ * @param a - The first stamp
2003
+ * @param b - The second stamp
2004
+ * @returns A negative number if `a` orders first, a positive number if `b`
2005
+ * does, `0` if they are equal
2006
+ */
2007
+ var compareRefStamp = (a, b) => {
2008
+ if (a.domain !== b.domain) return a.domain < b.domain ? -1 : 1;
2009
+ if (a.epoch !== b.epoch) return a.epoch < b.epoch ? -1 : 1;
2010
+ if (a.hub !== b.hub) return a.hub < b.hub ? -1 : 1;
2011
+ if (a.n !== b.n) return a.n < b.n ? -1 : 1;
2012
+ return 0;
2013
+ };
2014
+ /**
2015
+ * Checks whether a value received from the wire is a well-formed RefStamp.
2016
+ *
2017
+ * A stamp arrives inside a JSON payload from another process, so it is
2018
+ * checked before anything orders by it.
2019
+ * @param value - The value to check
2020
+ * @returns `true` if `value` has a string `domain` and `hub` and a
2021
+ * non-negative integer `epoch` and `n`
2022
+ */
2023
+ var isRefStamp = (value) => {
2024
+ if (typeof value !== "object" || value === null) return false;
2025
+ const stamp = value;
2026
+ return typeof stamp.domain === "string" && typeof stamp.hub === "string" && Number.isSafeInteger(stamp.epoch) && stamp.epoch >= 0 && Number.isSafeInteger(stamp.n) && stamp.n >= 0;
2027
+ };
2028
+ /**
2029
+ * Returns an example RefStamp for documentation and testing.
2030
+ */
2031
+ var refStampExample = () => ({
2032
+ domain: "example",
2033
+ epoch: 1,
2034
+ hub: "hub_ExAmPlE",
2035
+ n: 1
2036
+ });
2037
+ /**
2038
+ * Returns an example StampPayload for documentation and testing.
2039
+ */
2040
+ var stampPayloadExample = () => ({
2041
+ r: "1700000000001:EfGh",
2042
+ stamp: refStampExample()
2043
+ });
2044
+ // src/sync/sync-config.ts
2013
2045
  // @license
2014
2046
  /**
2015
2047
  * Default SyncConfig — all features disabled (backward-compatible mode).
@@ -2029,8 +2061,7 @@ var syncConfigFullExample = () => ({
2029
2061
  * Returns an example SyncConfig with only causal ordering enabled.
2030
2062
  */
2031
2063
  var syncConfigCausalOnlyExample = () => ({ causalOrdering: true });
2032
- //#endregion
2033
- //#region src/sync/sync-events.ts
2064
+ // src/sync/sync-events.ts
2034
2065
  // @license
2035
2066
  /**
2036
2067
  * Creates typed, route-specific socket event names for the sync protocol.
@@ -2043,10 +2074,10 @@ var syncEvents = (route) => ({
2043
2074
  ackClient: `${route}:ack:client`,
2044
2075
  gapFillReq: `${route}:gapfill:req`,
2045
2076
  gapFillRes: `${route}:gapfill:res`,
2046
- bootstrap: `${route}:bootstrap`
2077
+ bootstrap: `${route}:bootstrap`,
2078
+ stamp: `${route}:stamp`
2047
2079
  });
2048
- //#endregion
2049
- //#region src/tables/tables.ts
2080
+ // src/tables/tables.ts
2050
2081
  // @license
2051
2082
  /**
2052
2083
  * Read only view on the tables of an Rljson dump.
@@ -2130,8 +2161,7 @@ var Tables = class Tables {
2130
2161
  return typeof value === "object" && value !== null && typeof value._type === "string" && Array.isArray(value._data);
2131
2162
  }
2132
2163
  };
2133
- //#endregion
2134
- //#region src/tools/ref.ts
2164
+ // src/tools/ref.ts
2135
2165
  // @license
2136
2166
  /**
2137
2167
  * Returns the reference to a row: the hash that `hip` has written into it.
@@ -2160,8 +2190,7 @@ var rowOf = (table, hash) => {
2160
2190
  if (!row) throw new Error(`rowOf: The table has no row with hash "${hash}".`);
2161
2191
  return row;
2162
2192
  };
2163
- //#endregion
2164
- //#region src/tools/resolve-slice-ids.ts
2193
+ // src/tools/resolve-slice-ids.ts
2165
2194
  // @license
2166
2195
  /**
2167
2196
  * Merges a row of slice ids with the resolved slice ids of its base.
@@ -2198,8 +2227,7 @@ var resolveSliceIds = (table, row) => {
2198
2227
  }
2199
2228
  return chain.reduceRight(mergeSliceIds, []);
2200
2229
  };
2201
- //#endregion
2202
- //#region src/tools/remove-duplicates.ts
2230
+ // src/tools/remove-duplicates.ts
2203
2231
  // @license
2204
2232
  var removeDuplicates = (rljson) => {
2205
2233
  const result = {};
@@ -2218,8 +2246,7 @@ var removeDuplicates = (rljson) => {
2218
2246
  updateExistingHashes: true
2219
2247
  });
2220
2248
  };
2221
- //#endregion
2222
- //#region src/tools/time-id.ts
2249
+ // src/tools/time-id.ts
2223
2250
  // @license
2224
2251
  /**
2225
2252
  * Generates a new TimeId.
@@ -2264,8 +2291,7 @@ var getTimeIdUniquePart = (id) => {
2264
2291
  if (!isTimeId(id)) return null;
2265
2292
  return id.split(":")[1];
2266
2293
  };
2267
- //#endregion
2268
- //#region src/typedefs.ts
2294
+ // src/typedefs.ts
2269
2295
  // @license
2270
2296
  /**
2271
2297
  * Types of tables that can be stored in an Rljson object
@@ -2301,8 +2327,7 @@ var exampleTypedefs = () => {
2301
2327
  contentType: "layers"
2302
2328
  };
2303
2329
  };
2304
- //#endregion
2305
- //#region src/rljson-indexed.ts
2330
+ // src/rljson-indexed.ts
2306
2331
  // @license
2307
2332
  /**
2308
2333
  * Returns an rljson where all tables' rows are indexed by their hash.
@@ -2329,8 +2354,7 @@ var rljsonIndexed = (rljson) => {
2329
2354
  }
2330
2355
  return result;
2331
2356
  };
2332
- //#endregion
2333
- //#region src/validate/base-validator.ts
2357
+ // src/validate/base-validator.ts
2334
2358
  // @license
2335
2359
  var BaseValidator = class {
2336
2360
  name = "base";
@@ -2987,8 +3011,7 @@ var _BaseValidator = class {
2987
3011
  * @returns true if the field name is valid, false otherwise
2988
3012
  */
2989
3013
  var isValidFieldName = (fieldName) => BaseValidator.isValidFieldName(fieldName);
2990
- //#endregion
2991
- //#region src/validate/validate.ts
3014
+ // src/validate/validate.ts
2992
3015
  // @license
2993
3016
  var Validate = class {
2994
3017
  addValidator(validator) {
@@ -3013,8 +3036,6 @@ var Validate = class {
3013
3036
  }
3014
3037
  _validators = [];
3015
3038
  };
3016
- //#endregion
3017
- //#region src/index.ts
3039
+ // src/index.ts
3018
3040
  // @license
3019
- //#endregion
3020
- export { BaseValidator, Example, InsertValidator, Route, Tables, Validate, ackPayloadExample, ackPayloadPartialExample, addColumnsToTableCfg, bakeryExample, clientId, clientIdExample, 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, isTimeId, isValidFieldName, iterateTables, iterateTablesSync, mergeSliceIds, ref, removeDuplicates, reservedFieldNames, reservedTableKeys, resolveSliceIds, routeRefSeperator, routeSliceIdIndicators, routeSliceIdSeperator, rowOf, syncConfigCausalOnlyExample, syncConfigDefault, syncConfigFullExample, syncEvents, throwOnInvalidTableCfg, timeId, treeFromObject, validateInsert, validateRljsonAgainstTableCfg };
3041
+ 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 };
@@ -1,2 +1,2 @@
1
1
  /** The version of the `@rljson/rljson` package. */
2
- export declare const rljsonVersion = "0.0.85";
2
+ export declare const rljsonVersion = "0.0.87";
@@ -1,5 +1,6 @@
1
1
  import { InsertHistoryTimeId } from '../insertHistory/insertHistory.ts';
2
2
  import { ClientId } from './client-id.ts';
3
+ import { RefStamp } from './ref-stamp.ts';
3
4
  /**
4
5
  * Wire-protocol payload transmitted between Connector and Server.
5
6
  *
@@ -17,6 +18,7 @@ import { ClientId } from './client-id.ts';
17
18
  * | `seq` | Predecessor chain | Monotonic counter per (client, route) |
18
19
  * | `p` | Predecessor chain | Causal predecessor timeIds |
19
20
  * | `cksum` | Acknowledgment | Content checksum for ACK verification |
21
+ * | `stamp` | Hub order | Where a stamping hub placed the ref |
20
22
  */
21
23
  export type ConnectorPayload = {
22
24
  /** The ref (InsertHistoryTimeId) being announced. */
@@ -33,6 +35,13 @@ export type ConnectorPayload = {
33
35
  p?: InsertHistoryTimeId[];
34
36
  /** Content checksum of the referenced data, for ACK verification. */
35
37
  cksum?: string;
38
+ /**
39
+ * Where a stamping hub placed the ref in the order it relays them.
40
+ *
41
+ * Set by the first hub that relays the ref; a hub that receives a payload
42
+ * already carrying a stamp forwards it unchanged.
43
+ */
44
+ stamp?: RefStamp;
36
45
  };
37
46
  /**
38
47
  * Returns a minimal example ConnectorPayload (backward-compatible format).
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Where a ref stands in the order a hub relayed it — a fact about what the
3
+ * fleet saw, not a timestamp.
4
+ *
5
+ * A hub that stamps assigns one to every ref it relays on a route. The tuple
6
+ * orders lexicographically on `(domain, epoch, hub, n)`, see
7
+ * {@link compareRefStamp}. No field is read from a clock, so two machines with
8
+ * different wall clocks order the same two refs the same way.
9
+ *
10
+ * | Field | Meaning |
11
+ * |----------|----------------------------------------------------------|
12
+ * | `domain` | The network domain whose hub stamped the ref |
13
+ * | `epoch` | Advanced each time a hub takes office in that domain |
14
+ * | `hub` | The node id of the stamping hub |
15
+ * | `n` | Monotonic within `(domain, epoch, hub)` |
16
+ *
17
+ * `hub` keeps two hubs that believe they hold the same epoch — a split brain —
18
+ * distinct and still totally ordered.
19
+ */
20
+ export type RefStamp = {
21
+ /** The network domain whose hub stamped the ref. */
22
+ domain: string;
23
+ /** Advanced each time a hub takes office in the domain. */
24
+ epoch: number;
25
+ /** The node id of the stamping hub. */
26
+ hub: string;
27
+ /** Monotonic within `(domain, epoch, hub)`. */
28
+ n: number;
29
+ };
30
+ /**
31
+ * Server → Client: the stamp a hub gave a ref the client announced.
32
+ *
33
+ * A hub forwards an announcement to every client except its sender, so the
34
+ * sender never sees its own stamp on the ref event. This payload, sent on the
35
+ * `${route}:stamp` event to the sender only, is how it learns it.
36
+ */
37
+ export type StampPayload = {
38
+ /** The ref that was stamped. */
39
+ r: string;
40
+ /** The stamp the hub gave it. */
41
+ stamp: RefStamp;
42
+ };
43
+ /**
44
+ * Orders two stamps lexicographically on `(domain, epoch, hub, n)`.
45
+ *
46
+ * A total order: every pair compares the same way on every machine, and only
47
+ * equal stamps compare as `0`.
48
+ * @param a - The first stamp
49
+ * @param b - The second stamp
50
+ * @returns A negative number if `a` orders first, a positive number if `b`
51
+ * does, `0` if they are equal
52
+ */
53
+ export declare const compareRefStamp: (a: RefStamp, b: RefStamp) => number;
54
+ /**
55
+ * Checks whether a value received from the wire is a well-formed RefStamp.
56
+ *
57
+ * A stamp arrives inside a JSON payload from another process, so it is
58
+ * checked before anything orders by it.
59
+ * @param value - The value to check
60
+ * @returns `true` if `value` has a string `domain` and `hub` and a
61
+ * non-negative integer `epoch` and `n`
62
+ */
63
+ export declare const isRefStamp: (value: unknown) => value is RefStamp;
64
+ /**
65
+ * Returns an example RefStamp for documentation and testing.
66
+ */
67
+ export declare const refStampExample: () => RefStamp;
68
+ /**
69
+ * Returns an example StampPayload for documentation and testing.
70
+ */
71
+ export declare const stampPayloadExample: () => StampPayload;
@@ -23,6 +23,8 @@ export type SyncEventNames = {
23
23
  gapFillRes: string;
24
24
  /** Server → Client: bootstrap latest ref on connect / heartbeat. */
25
25
  bootstrap: string;
26
+ /** Server → Client (sender only): the stamp its announced ref received. */
27
+ stamp: string;
26
28
  };
27
29
  /**
28
30
  * 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.85",
3
+ "version": "0.0.87",
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",
@@ -20,28 +20,30 @@
20
20
  ],
21
21
  "type": "module",
22
22
  "devDependencies": {
23
- "@types/node": "^26.6.4",
24
- "@typescript-eslint/eslint-plugin": "^8.71.1",
25
- "@typescript-eslint/parser": "^8.71.1",
26
- "@vitest/coverage-v8": "^5.0.3",
23
+ "@rljson/dna-rljson": "^0.3.1",
24
+ "@tssuite/helix-js": "^0.5.1",
25
+ "@types/node": "^26.6.6",
26
+ "@typescript-eslint/eslint-plugin": "^8.72.1",
27
+ "@typescript-eslint/parser": "^8.72.1",
28
+ "@vitest/coverage-v8": "^5.0.5",
27
29
  "cross-env": "^10.1.0",
28
- "eslint": "^10.12.0",
29
- "eslint-plugin-jsdoc": "^65.2.0",
30
+ "eslint": "^10.13.0",
31
+ "eslint-plugin-jsdoc": "^65.4.2",
30
32
  "eslint-plugin-tsdoc": "^0.5.4",
31
33
  "globals": "^17.13.0",
32
34
  "jsdoc": "^4.0.5",
33
35
  "read-pkg": "^10.1.0",
34
36
  "typescript": "~6.0.3",
35
- "typescript-eslint": "^8.71.1",
36
- "vite": "^8.3.4",
37
+ "typescript-eslint": "^8.72.1",
38
+ "vite": "^8.3.5",
37
39
  "vite-node": "^6.0.0",
38
40
  "vite-plugin-dts": "^5.1.2",
39
41
  "vite-tsconfig-paths": "^6.1.1",
40
- "vitest": "^5.0.3",
42
+ "vitest": "^5.0.5",
41
43
  "vitest-dom": "^0.1.1"
42
44
  },
43
45
  "dependencies": {
44
- "@rljson/hash": "0.0.19",
46
+ "@rljson/hash": "0.0.20",
45
47
  "@rljson/json": "0.0.23",
46
48
  "nanoid": "^6.0.2"
47
49
  },