@peerbit/shared-log 4.1.0 → 5.0.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/src/role.ts CHANGED
@@ -31,13 +31,13 @@ class ReplicationSegment {
31
31
  @field({ type: "u32" })
32
32
  private factorNominator: number;
33
33
 
34
- @field({ type: option("u32") })
35
- private offsetNominator?: number;
34
+ @field({ type: "u32" })
35
+ private offsetNominator: number;
36
36
 
37
37
  constructor(properties: {
38
38
  factor: number;
39
+ offset: number;
39
40
  timestamp?: bigint;
40
- offset?: number;
41
41
  }) {
42
42
  const { factor, timestamp, offset } = properties;
43
43
  if (factor > 1 || factor < 0) {
@@ -47,24 +47,18 @@ class ReplicationSegment {
47
47
  this.timestamp = timestamp ?? BigInt(+new Date());
48
48
  this.factorNominator = Math.round(4294967295 * factor);
49
49
 
50
- if (offset != null) {
51
- if (offset > 1 || offset < 0) {
52
- throw new Error(
53
- "Expecting offset to be between 0 and 1, got: " + offset
54
- );
55
- }
56
- this.offsetNominator = Math.round(4294967295 * offset);
50
+ if (offset > 1 || offset < 0) {
51
+ throw new Error("Expecting offset to be between 0 and 1, got: " + offset);
57
52
  }
53
+ this.offsetNominator = Math.round(4294967295 * offset);
58
54
  }
59
55
 
60
56
  get factor(): number {
61
57
  return this.factorNominator / 4294967295;
62
58
  }
63
59
 
64
- get offset(): number | undefined {
65
- return this.offsetNominator != null
66
- ? this.offsetNominator / 4294967295
67
- : undefined;
60
+ get offset(): number {
61
+ return this.offsetNominator / 4294967295;
68
62
  }
69
63
  }
70
64
 
@@ -76,7 +70,7 @@ export class Replicator extends Role {
76
70
  constructor(properties: {
77
71
  factor: number;
78
72
  timestamp?: bigint;
79
- offset?: number;
73
+ offset: number;
80
74
  }) {
81
75
  super();
82
76
  const segment: ReplicationSegment = new ReplicationSegment(properties);
@@ -87,7 +81,7 @@ export class Replicator extends Role {
87
81
  return this.segments[0]!.factor;
88
82
  }
89
83
 
90
- get offset(): number | undefined {
84
+ get offset(): number {
91
85
  return this.segments[0]!.offset;
92
86
  }
93
87