@kubun/hlc 0.12.0 → 0.14.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/lib/index.d.ts CHANGED
@@ -15,6 +15,17 @@ export declare class HLC {
15
15
  receive(remote: HLCTimestamp): HLCTimestamp;
16
16
  static serialize(ts: HLCTimestamp): string;
17
17
  static parse(s: string): HLCTimestamp;
18
+ /**
19
+ * Parse a stamp that arrived from somewhere else, or answer `null`.
20
+ *
21
+ * `parse` never throws and never returns a uniformly-NaN record: a string with
22
+ * no `Z` yields a NaN wall time beside a counter that may still parse, so a
23
+ * caller checking one field admits the other. Every field is checked here, and
24
+ * anything a peer sends has to come through this rather than `parse` —
25
+ * `receive` assigns NaN straight into the clock, and the drift bound is blind
26
+ * to it because every comparison against NaN is false.
27
+ */
28
+ static tryParse(s: string): HLCTimestamp | null;
18
29
  static compare(a: HLCTimestamp, b: HLCTimestamp): number;
19
30
  }
20
31
  export {};
package/lib/index.js CHANGED
@@ -79,6 +79,19 @@ export class HLC {
79
79
  nodeID
80
80
  };
81
81
  }
82
+ /**
83
+ * Parse a stamp that arrived from somewhere else, or answer `null`.
84
+ *
85
+ * `parse` never throws and never returns a uniformly-NaN record: a string with
86
+ * no `Z` yields a NaN wall time beside a counter that may still parse, so a
87
+ * caller checking one field admits the other. Every field is checked here, and
88
+ * anything a peer sends has to come through this rather than `parse` —
89
+ * `receive` assigns NaN straight into the clock, and the drift bound is blind
90
+ * to it because every comparison against NaN is false.
91
+ */ static tryParse(s) {
92
+ const ts = HLC.parse(s);
93
+ return Number.isFinite(ts.wallTime) && Number.isFinite(ts.counter) && ts.nodeID !== '' ? ts : null;
94
+ }
82
95
  static compare(a, b) {
83
96
  if (a.wallTime !== b.wallTime) return a.wallTime - b.wallTime;
84
97
  if (a.counter !== b.counter) return a.counter - b.counter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/hlc",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,
@@ -14,6 +14,9 @@
14
14
  "lib/*",
15
15
  "LICENSE.md"
16
16
  ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
17
20
  "scripts": {
18
21
  "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
19
22
  "build:clean": "del lib",