@rljson/rljson 0.0.85 → 0.0.86

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
@@ -1980,7 +1980,13 @@ var connectorPayloadFullExample = () => ({
1980
1980
  t: 1700000000001,
1981
1981
  seq: 42,
1982
1982
  p: ["1700000000000:XyZw"],
1983
- cksum: "sha256:abc123def456"
1983
+ cksum: "sha256:abc123def456",
1984
+ stamp: {
1985
+ domain: "example",
1986
+ epoch: 1,
1987
+ hub: "hub_ExAmPlE",
1988
+ n: 1
1989
+ }
1984
1990
  });
1985
1991
  //#endregion
1986
1992
  //#region src/sync/gap-fill.ts
@@ -2009,6 +2015,56 @@ var gapFillResponseExample = () => ({
2009
2015
  }]
2010
2016
  });
2011
2017
  //#endregion
2018
+ //#region src/sync/ref-stamp.ts
2019
+ // @license
2020
+ /**
2021
+ * Orders two stamps lexicographically on `(domain, epoch, hub, n)`.
2022
+ *
2023
+ * A total order: every pair compares the same way on every machine, and only
2024
+ * equal stamps compare as `0`.
2025
+ * @param a - The first stamp
2026
+ * @param b - The second stamp
2027
+ * @returns A negative number if `a` orders first, a positive number if `b`
2028
+ * does, `0` if they are equal
2029
+ */
2030
+ var compareRefStamp = (a, b) => {
2031
+ if (a.domain !== b.domain) return a.domain < b.domain ? -1 : 1;
2032
+ if (a.epoch !== b.epoch) return a.epoch < b.epoch ? -1 : 1;
2033
+ if (a.hub !== b.hub) return a.hub < b.hub ? -1 : 1;
2034
+ if (a.n !== b.n) return a.n < b.n ? -1 : 1;
2035
+ return 0;
2036
+ };
2037
+ /**
2038
+ * Checks whether a value received from the wire is a well-formed RefStamp.
2039
+ *
2040
+ * A stamp arrives inside a JSON payload from another process, so it is
2041
+ * checked before anything orders by it.
2042
+ * @param value - The value to check
2043
+ * @returns `true` if `value` has a string `domain` and `hub` and a
2044
+ * non-negative integer `epoch` and `n`
2045
+ */
2046
+ var isRefStamp = (value) => {
2047
+ if (typeof value !== "object" || value === null) return false;
2048
+ const stamp = value;
2049
+ return typeof stamp.domain === "string" && typeof stamp.hub === "string" && Number.isSafeInteger(stamp.epoch) && stamp.epoch >= 0 && Number.isSafeInteger(stamp.n) && stamp.n >= 0;
2050
+ };
2051
+ /**
2052
+ * Returns an example RefStamp for documentation and testing.
2053
+ */
2054
+ var refStampExample = () => ({
2055
+ domain: "example",
2056
+ epoch: 1,
2057
+ hub: "hub_ExAmPlE",
2058
+ n: 1
2059
+ });
2060
+ /**
2061
+ * Returns an example StampPayload for documentation and testing.
2062
+ */
2063
+ var stampPayloadExample = () => ({
2064
+ r: "1700000000001:EfGh",
2065
+ stamp: refStampExample()
2066
+ });
2067
+ //#endregion
2012
2068
  //#region src/sync/sync-config.ts
2013
2069
  // @license
2014
2070
  /**
@@ -2043,7 +2099,8 @@ var syncEvents = (route) => ({
2043
2099
  ackClient: `${route}:ack:client`,
2044
2100
  gapFillReq: `${route}:gapfill:req`,
2045
2101
  gapFillRes: `${route}:gapfill:res`,
2046
- bootstrap: `${route}:bootstrap`
2102
+ bootstrap: `${route}:bootstrap`,
2103
+ stamp: `${route}:stamp`
2047
2104
  });
2048
2105
  //#endregion
2049
2106
  //#region src/tables/tables.ts
@@ -3017,4 +3074,4 @@ var Validate = class {
3017
3074
  //#region src/index.ts
3018
3075
  // @license
3019
3076
  //#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 };
3077
+ 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.86";
@@ -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.86",
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",
@@ -26,7 +26,7 @@
26
26
  "@vitest/coverage-v8": "^5.0.3",
27
27
  "cross-env": "^10.1.0",
28
28
  "eslint": "^10.12.0",
29
- "eslint-plugin-jsdoc": "^65.2.0",
29
+ "eslint-plugin-jsdoc": "^65.2.1",
30
30
  "eslint-plugin-tsdoc": "^0.5.4",
31
31
  "globals": "^17.13.0",
32
32
  "jsdoc": "^4.0.5",