@peerbit/shared-log 11.5.8 → 11.6.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.
Files changed (41) hide show
  1. package/dist/benchmark/index.js +118 -63
  2. package/dist/benchmark/index.js.map +1 -1
  3. package/dist/benchmark/memory/child.js +112 -57
  4. package/dist/benchmark/memory/child.js.map +1 -1
  5. package/dist/benchmark/replication-prune.js.map +1 -1
  6. package/dist/benchmark/replication.js +1 -3
  7. package/dist/benchmark/replication.js.map +1 -1
  8. package/dist/src/blocks.js +61 -22
  9. package/dist/src/blocks.js.map +1 -1
  10. package/dist/src/debounce.d.ts +8 -8
  11. package/dist/src/exchange-heads.d.ts.map +1 -1
  12. package/dist/src/exchange-heads.js +164 -81
  13. package/dist/src/exchange-heads.js.map +1 -1
  14. package/dist/src/index.d.ts +1 -2
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +2421 -2380
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/message.js +50 -10
  19. package/dist/src/message.js.map +1 -1
  20. package/dist/src/ranges.d.ts +13 -15
  21. package/dist/src/ranges.d.ts.map +1 -1
  22. package/dist/src/ranges.js +736 -589
  23. package/dist/src/ranges.js.map +1 -1
  24. package/dist/src/replication.js +216 -109
  25. package/dist/src/replication.js.map +1 -1
  26. package/dist/src/role.js +164 -89
  27. package/dist/src/role.js.map +1 -1
  28. package/dist/src/sync/rateless-iblt.d.ts +2 -3
  29. package/dist/src/sync/rateless-iblt.d.ts.map +1 -1
  30. package/dist/src/sync/rateless-iblt.js +224 -129
  31. package/dist/src/sync/rateless-iblt.js.map +1 -1
  32. package/dist/src/sync/simple.d.ts +1 -1
  33. package/dist/src/sync/simple.d.ts.map +1 -1
  34. package/dist/src/sync/simple.js +119 -52
  35. package/dist/src/sync/simple.js.map +1 -1
  36. package/package.json +19 -19
  37. package/src/exchange-heads.ts +3 -2
  38. package/src/index.ts +17 -15
  39. package/src/ranges.ts +10 -10
  40. package/src/sync/rateless-iblt.ts +3 -5
  41. package/src/sync/simple.ts +1 -1
@@ -1,11 +1,36 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
6
27
  };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
9
34
  };
10
35
  import { deserialize, field, serialize, variant, vec } from "@dao-xyz/borsh";
11
36
  import { PublicSignKey, equals, randomBytes, sha256Base64Sync, toBase64, } from "@peerbit/crypto";
@@ -51,309 +76,397 @@ export const shouldAssigneToRangeBoundary = (leaders, minReplicas) => {
51
76
  export const isEntryReplicated = (x) => {
52
77
  return x instanceof EntryReplicatedU32 || x instanceof EntryReplicatedU64;
53
78
  };
54
- export class EntryReplicatedU32 {
55
- hash;
56
- hashNumber;
57
- gid;
58
- coordinates;
59
- wallTime;
60
- assignedToRangeBoundary;
61
- _meta;
62
- _metaResolved;
63
- constructor(properties) {
64
- this.coordinates = properties.coordinates;
65
- this.hash = properties.hash;
66
- this.gid = properties.meta.gid;
67
- this.wallTime = properties.meta.clock.timestamp.wallTime;
68
- this.hashNumber = properties.hashNumber;
69
- const shallow = properties.meta instanceof Meta
70
- ? new ShallowMeta(properties.meta)
71
- : properties.meta;
72
- this._meta = serialize(shallow);
73
- this._metaResolved = deserialize(this._meta, ShallowMeta);
74
- this._metaResolved = properties.meta;
75
- this.assignedToRangeBoundary = properties.assignedToRangeBoundary;
76
- }
77
- get meta() {
78
- if (!this._metaResolved) {
79
+ let EntryReplicatedU32 = (() => {
80
+ let _hash_decorators;
81
+ let _hash_initializers = [];
82
+ let _hash_extraInitializers = [];
83
+ let _hashNumber_decorators;
84
+ let _hashNumber_initializers = [];
85
+ let _hashNumber_extraInitializers = [];
86
+ let _gid_decorators;
87
+ let _gid_initializers = [];
88
+ let _gid_extraInitializers = [];
89
+ let _coordinates_decorators;
90
+ let _coordinates_initializers = [];
91
+ let _coordinates_extraInitializers = [];
92
+ let _wallTime_decorators;
93
+ let _wallTime_initializers = [];
94
+ let _wallTime_extraInitializers = [];
95
+ let _assignedToRangeBoundary_decorators;
96
+ let _assignedToRangeBoundary_initializers = [];
97
+ let _assignedToRangeBoundary_extraInitializers = [];
98
+ let __meta_decorators;
99
+ let __meta_initializers = [];
100
+ let __meta_extraInitializers = [];
101
+ return class EntryReplicatedU32 {
102
+ static {
103
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
104
+ _hash_decorators = [id({ type: "string" })];
105
+ _hashNumber_decorators = [field({ type: "u32" })];
106
+ _gid_decorators = [field({ type: "string" })];
107
+ _coordinates_decorators = [field({ type: vec("u32") })];
108
+ _wallTime_decorators = [field({ type: "u64" })];
109
+ _assignedToRangeBoundary_decorators = [field({ type: "bool" })];
110
+ __meta_decorators = [field({ type: Uint8Array })];
111
+ __esDecorate(null, null, _hash_decorators, { kind: "field", name: "hash", static: false, private: false, access: { has: obj => "hash" in obj, get: obj => obj.hash, set: (obj, value) => { obj.hash = value; } }, metadata: _metadata }, _hash_initializers, _hash_extraInitializers);
112
+ __esDecorate(null, null, _hashNumber_decorators, { kind: "field", name: "hashNumber", static: false, private: false, access: { has: obj => "hashNumber" in obj, get: obj => obj.hashNumber, set: (obj, value) => { obj.hashNumber = value; } }, metadata: _metadata }, _hashNumber_initializers, _hashNumber_extraInitializers);
113
+ __esDecorate(null, null, _gid_decorators, { kind: "field", name: "gid", static: false, private: false, access: { has: obj => "gid" in obj, get: obj => obj.gid, set: (obj, value) => { obj.gid = value; } }, metadata: _metadata }, _gid_initializers, _gid_extraInitializers);
114
+ __esDecorate(null, null, _coordinates_decorators, { kind: "field", name: "coordinates", static: false, private: false, access: { has: obj => "coordinates" in obj, get: obj => obj.coordinates, set: (obj, value) => { obj.coordinates = value; } }, metadata: _metadata }, _coordinates_initializers, _coordinates_extraInitializers);
115
+ __esDecorate(null, null, _wallTime_decorators, { kind: "field", name: "wallTime", static: false, private: false, access: { has: obj => "wallTime" in obj, get: obj => obj.wallTime, set: (obj, value) => { obj.wallTime = value; } }, metadata: _metadata }, _wallTime_initializers, _wallTime_extraInitializers);
116
+ __esDecorate(null, null, _assignedToRangeBoundary_decorators, { kind: "field", name: "assignedToRangeBoundary", static: false, private: false, access: { has: obj => "assignedToRangeBoundary" in obj, get: obj => obj.assignedToRangeBoundary, set: (obj, value) => { obj.assignedToRangeBoundary = value; } }, metadata: _metadata }, _assignedToRangeBoundary_initializers, _assignedToRangeBoundary_extraInitializers);
117
+ __esDecorate(null, null, __meta_decorators, { kind: "field", name: "_meta", static: false, private: false, access: { has: obj => "_meta" in obj, get: obj => obj._meta, set: (obj, value) => { obj._meta = value; } }, metadata: _metadata }, __meta_initializers, __meta_extraInitializers);
118
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
119
+ }
120
+ hash = __runInitializers(this, _hash_initializers, void 0);
121
+ hashNumber = (__runInitializers(this, _hash_extraInitializers), __runInitializers(this, _hashNumber_initializers, void 0));
122
+ gid = (__runInitializers(this, _hashNumber_extraInitializers), __runInitializers(this, _gid_initializers, void 0));
123
+ coordinates = (__runInitializers(this, _gid_extraInitializers), __runInitializers(this, _coordinates_initializers, void 0));
124
+ wallTime = (__runInitializers(this, _coordinates_extraInitializers), __runInitializers(this, _wallTime_initializers, void 0));
125
+ assignedToRangeBoundary = (__runInitializers(this, _wallTime_extraInitializers), __runInitializers(this, _assignedToRangeBoundary_initializers, void 0));
126
+ _meta = (__runInitializers(this, _assignedToRangeBoundary_extraInitializers), __runInitializers(this, __meta_initializers, void 0));
127
+ _metaResolved = __runInitializers(this, __meta_extraInitializers);
128
+ constructor(properties) {
129
+ this.coordinates = properties.coordinates;
130
+ this.hash = properties.hash;
131
+ this.gid = properties.meta.gid;
132
+ this.wallTime = properties.meta.clock.timestamp.wallTime;
133
+ this.hashNumber = properties.hashNumber;
134
+ const shallow = properties.meta instanceof Meta
135
+ ? new ShallowMeta(properties.meta)
136
+ : properties.meta;
137
+ this._meta = serialize(shallow);
79
138
  this._metaResolved = deserialize(this._meta, ShallowMeta);
139
+ this._metaResolved = properties.meta;
140
+ this.assignedToRangeBoundary = properties.assignedToRangeBoundary;
80
141
  }
81
- return this._metaResolved;
82
- }
83
- }
84
- __decorate([
85
- id({ type: "string" }),
86
- __metadata("design:type", String)
87
- ], EntryReplicatedU32.prototype, "hash", void 0);
88
- __decorate([
89
- field({ type: "u32" }),
90
- __metadata("design:type", Number)
91
- ], EntryReplicatedU32.prototype, "hashNumber", void 0);
92
- __decorate([
93
- field({ type: "string" }),
94
- __metadata("design:type", String)
95
- ], EntryReplicatedU32.prototype, "gid", void 0);
96
- __decorate([
97
- field({ type: vec("u32") }),
98
- __metadata("design:type", Array)
99
- ], EntryReplicatedU32.prototype, "coordinates", void 0);
100
- __decorate([
101
- field({ type: "u64" }),
102
- __metadata("design:type", BigInt)
103
- ], EntryReplicatedU32.prototype, "wallTime", void 0);
104
- __decorate([
105
- field({ type: "bool" }),
106
- __metadata("design:type", Boolean)
107
- ], EntryReplicatedU32.prototype, "assignedToRangeBoundary", void 0);
108
- __decorate([
109
- field({ type: Uint8Array }),
110
- __metadata("design:type", Uint8Array)
111
- ], EntryReplicatedU32.prototype, "_meta", void 0);
112
- export class EntryReplicatedU64 {
113
- hash;
114
- hashNumber;
115
- gid;
116
- coordinates;
117
- wallTime;
118
- assignedToRangeBoundary;
119
- _meta;
120
- _metaResolved;
121
- constructor(properties) {
122
- this.coordinates = properties.coordinates;
123
- this.hash = properties.hash;
124
- this.hashNumber = properties.hashNumber;
125
- this.gid = properties.meta.gid;
126
- this.wallTime = properties.meta.clock.timestamp.wallTime;
127
- const shallow = properties.meta instanceof Meta
128
- ? new ShallowMeta(properties.meta)
129
- : properties.meta;
130
- this._meta = serialize(shallow);
131
- this._metaResolved = deserialize(this._meta, ShallowMeta);
132
- this._metaResolved = properties.meta;
133
- this.assignedToRangeBoundary = properties.assignedToRangeBoundary;
134
- }
135
- get meta() {
136
- if (!this._metaResolved) {
142
+ get meta() {
143
+ if (!this._metaResolved) {
144
+ this._metaResolved = deserialize(this._meta, ShallowMeta);
145
+ }
146
+ return this._metaResolved;
147
+ }
148
+ };
149
+ })();
150
+ export { EntryReplicatedU32 };
151
+ let EntryReplicatedU64 = (() => {
152
+ let _hash_decorators;
153
+ let _hash_initializers = [];
154
+ let _hash_extraInitializers = [];
155
+ let _hashNumber_decorators;
156
+ let _hashNumber_initializers = [];
157
+ let _hashNumber_extraInitializers = [];
158
+ let _gid_decorators;
159
+ let _gid_initializers = [];
160
+ let _gid_extraInitializers = [];
161
+ let _coordinates_decorators;
162
+ let _coordinates_initializers = [];
163
+ let _coordinates_extraInitializers = [];
164
+ let _wallTime_decorators;
165
+ let _wallTime_initializers = [];
166
+ let _wallTime_extraInitializers = [];
167
+ let _assignedToRangeBoundary_decorators;
168
+ let _assignedToRangeBoundary_initializers = [];
169
+ let _assignedToRangeBoundary_extraInitializers = [];
170
+ let __meta_decorators;
171
+ let __meta_initializers = [];
172
+ let __meta_extraInitializers = [];
173
+ return class EntryReplicatedU64 {
174
+ static {
175
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
176
+ _hash_decorators = [id({ type: "string" })];
177
+ _hashNumber_decorators = [field({ type: "u64" })];
178
+ _gid_decorators = [field({ type: "string" })];
179
+ _coordinates_decorators = [field({ type: vec("u64") })];
180
+ _wallTime_decorators = [field({ type: "u64" })];
181
+ _assignedToRangeBoundary_decorators = [field({ type: "bool" })];
182
+ __meta_decorators = [field({ type: Uint8Array })];
183
+ __esDecorate(null, null, _hash_decorators, { kind: "field", name: "hash", static: false, private: false, access: { has: obj => "hash" in obj, get: obj => obj.hash, set: (obj, value) => { obj.hash = value; } }, metadata: _metadata }, _hash_initializers, _hash_extraInitializers);
184
+ __esDecorate(null, null, _hashNumber_decorators, { kind: "field", name: "hashNumber", static: false, private: false, access: { has: obj => "hashNumber" in obj, get: obj => obj.hashNumber, set: (obj, value) => { obj.hashNumber = value; } }, metadata: _metadata }, _hashNumber_initializers, _hashNumber_extraInitializers);
185
+ __esDecorate(null, null, _gid_decorators, { kind: "field", name: "gid", static: false, private: false, access: { has: obj => "gid" in obj, get: obj => obj.gid, set: (obj, value) => { obj.gid = value; } }, metadata: _metadata }, _gid_initializers, _gid_extraInitializers);
186
+ __esDecorate(null, null, _coordinates_decorators, { kind: "field", name: "coordinates", static: false, private: false, access: { has: obj => "coordinates" in obj, get: obj => obj.coordinates, set: (obj, value) => { obj.coordinates = value; } }, metadata: _metadata }, _coordinates_initializers, _coordinates_extraInitializers);
187
+ __esDecorate(null, null, _wallTime_decorators, { kind: "field", name: "wallTime", static: false, private: false, access: { has: obj => "wallTime" in obj, get: obj => obj.wallTime, set: (obj, value) => { obj.wallTime = value; } }, metadata: _metadata }, _wallTime_initializers, _wallTime_extraInitializers);
188
+ __esDecorate(null, null, _assignedToRangeBoundary_decorators, { kind: "field", name: "assignedToRangeBoundary", static: false, private: false, access: { has: obj => "assignedToRangeBoundary" in obj, get: obj => obj.assignedToRangeBoundary, set: (obj, value) => { obj.assignedToRangeBoundary = value; } }, metadata: _metadata }, _assignedToRangeBoundary_initializers, _assignedToRangeBoundary_extraInitializers);
189
+ __esDecorate(null, null, __meta_decorators, { kind: "field", name: "_meta", static: false, private: false, access: { has: obj => "_meta" in obj, get: obj => obj._meta, set: (obj, value) => { obj._meta = value; } }, metadata: _metadata }, __meta_initializers, __meta_extraInitializers);
190
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
191
+ }
192
+ hash = __runInitializers(this, _hash_initializers, void 0);
193
+ hashNumber = (__runInitializers(this, _hash_extraInitializers), __runInitializers(this, _hashNumber_initializers, void 0));
194
+ gid = (__runInitializers(this, _hashNumber_extraInitializers), __runInitializers(this, _gid_initializers, void 0));
195
+ coordinates = (__runInitializers(this, _gid_extraInitializers), __runInitializers(this, _coordinates_initializers, void 0));
196
+ wallTime = (__runInitializers(this, _coordinates_extraInitializers), __runInitializers(this, _wallTime_initializers, void 0));
197
+ assignedToRangeBoundary = (__runInitializers(this, _wallTime_extraInitializers), __runInitializers(this, _assignedToRangeBoundary_initializers, void 0));
198
+ _meta = (__runInitializers(this, _assignedToRangeBoundary_extraInitializers), __runInitializers(this, __meta_initializers, void 0));
199
+ _metaResolved = __runInitializers(this, __meta_extraInitializers);
200
+ constructor(properties) {
201
+ this.coordinates = properties.coordinates;
202
+ this.hash = properties.hash;
203
+ this.hashNumber = properties.hashNumber;
204
+ this.gid = properties.meta.gid;
205
+ this.wallTime = properties.meta.clock.timestamp.wallTime;
206
+ const shallow = properties.meta instanceof Meta
207
+ ? new ShallowMeta(properties.meta)
208
+ : properties.meta;
209
+ this._meta = serialize(shallow);
137
210
  this._metaResolved = deserialize(this._meta, ShallowMeta);
211
+ this._metaResolved = properties.meta;
212
+ this.assignedToRangeBoundary = properties.assignedToRangeBoundary;
138
213
  }
139
- return this._metaResolved;
140
- }
141
- }
142
- __decorate([
143
- id({ type: "string" }),
144
- __metadata("design:type", String)
145
- ], EntryReplicatedU64.prototype, "hash", void 0);
146
- __decorate([
147
- field({ type: "u64" }),
148
- __metadata("design:type", BigInt)
149
- ], EntryReplicatedU64.prototype, "hashNumber", void 0);
150
- __decorate([
151
- field({ type: "string" }),
152
- __metadata("design:type", String)
153
- ], EntryReplicatedU64.prototype, "gid", void 0);
154
- __decorate([
155
- field({ type: vec("u64") }),
156
- __metadata("design:type", Array)
157
- ], EntryReplicatedU64.prototype, "coordinates", void 0);
158
- __decorate([
159
- field({ type: "u64" }),
160
- __metadata("design:type", BigInt)
161
- ], EntryReplicatedU64.prototype, "wallTime", void 0);
162
- __decorate([
163
- field({ type: "bool" }),
164
- __metadata("design:type", Boolean)
165
- ], EntryReplicatedU64.prototype, "assignedToRangeBoundary", void 0);
166
- __decorate([
167
- field({ type: Uint8Array }),
168
- __metadata("design:type", Uint8Array)
169
- ], EntryReplicatedU64.prototype, "_meta", void 0);
214
+ get meta() {
215
+ if (!this._metaResolved) {
216
+ this._metaResolved = deserialize(this._meta, ShallowMeta);
217
+ }
218
+ return this._metaResolved;
219
+ }
220
+ };
221
+ })();
222
+ export { EntryReplicatedU64 };
170
223
  export const isReplicationRangeMessage = (x) => {
171
224
  return x instanceof ReplicationRangeMessage;
172
225
  };
173
226
  export class ReplicationRangeMessage {
174
227
  }
175
- let ReplicationRangeMessageU32 = class ReplicationRangeMessageU32 extends ReplicationRangeMessage {
176
- id;
177
- timestamp;
178
- _offset;
179
- _factor;
180
- mode;
181
- constructor(properties) {
182
- super();
183
- const { id, offset, factor, timestamp, mode } = properties;
184
- this.id = id;
185
- this._offset = offset;
186
- this._factor = factor;
187
- this.timestamp = timestamp;
188
- this.mode = mode;
189
- }
190
- get factor() {
191
- return this._factor;
192
- }
193
- get offset() {
194
- return this._offset;
195
- }
196
- toReplicationRangeIndexable(key) {
197
- return new ReplicationRangeIndexableU32({
198
- id: this.id,
199
- publicKeyHash: key.hashcode(),
200
- offset: this.offset,
201
- width: this.factor,
202
- timestamp: this.timestamp,
203
- mode: this.mode,
204
- });
205
- }
206
- };
207
- __decorate([
208
- field({ type: Uint8Array }),
209
- __metadata("design:type", Uint8Array)
210
- ], ReplicationRangeMessageU32.prototype, "id", void 0);
211
- __decorate([
212
- field({ type: "u64" }),
213
- __metadata("design:type", BigInt)
214
- ], ReplicationRangeMessageU32.prototype, "timestamp", void 0);
215
- __decorate([
216
- field({ type: "u32" }),
217
- __metadata("design:type", Number)
218
- ], ReplicationRangeMessageU32.prototype, "_offset", void 0);
219
- __decorate([
220
- field({ type: "u32" }),
221
- __metadata("design:type", Number)
222
- ], ReplicationRangeMessageU32.prototype, "_factor", void 0);
223
- __decorate([
224
- field({ type: "u8" }),
225
- __metadata("design:type", Number)
226
- ], ReplicationRangeMessageU32.prototype, "mode", void 0);
227
- ReplicationRangeMessageU32 = __decorate([
228
- variant(0),
229
- __metadata("design:paramtypes", [Object])
230
- ], ReplicationRangeMessageU32);
228
+ let ReplicationRangeMessageU32 = (() => {
229
+ let _classDecorators = [variant(0)];
230
+ let _classDescriptor;
231
+ let _classExtraInitializers = [];
232
+ let _classThis;
233
+ let _classSuper = ReplicationRangeMessage;
234
+ let _id_decorators;
235
+ let _id_initializers = [];
236
+ let _id_extraInitializers = [];
237
+ let _timestamp_decorators;
238
+ let _timestamp_initializers = [];
239
+ let _timestamp_extraInitializers = [];
240
+ let __offset_decorators;
241
+ let __offset_initializers = [];
242
+ let __offset_extraInitializers = [];
243
+ let __factor_decorators;
244
+ let __factor_initializers = [];
245
+ let __factor_extraInitializers = [];
246
+ let _mode_decorators;
247
+ let _mode_initializers = [];
248
+ let _mode_extraInitializers = [];
249
+ var ReplicationRangeMessageU32 = class extends _classSuper {
250
+ static { _classThis = this; }
251
+ static {
252
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
253
+ _id_decorators = [field({ type: Uint8Array })];
254
+ _timestamp_decorators = [field({ type: "u64" })];
255
+ __offset_decorators = [field({ type: "u32" })];
256
+ __factor_decorators = [field({ type: "u32" })];
257
+ _mode_decorators = [field({ type: "u8" })];
258
+ __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
259
+ __esDecorate(null, null, _timestamp_decorators, { kind: "field", name: "timestamp", static: false, private: false, access: { has: obj => "timestamp" in obj, get: obj => obj.timestamp, set: (obj, value) => { obj.timestamp = value; } }, metadata: _metadata }, _timestamp_initializers, _timestamp_extraInitializers);
260
+ __esDecorate(null, null, __offset_decorators, { kind: "field", name: "_offset", static: false, private: false, access: { has: obj => "_offset" in obj, get: obj => obj._offset, set: (obj, value) => { obj._offset = value; } }, metadata: _metadata }, __offset_initializers, __offset_extraInitializers);
261
+ __esDecorate(null, null, __factor_decorators, { kind: "field", name: "_factor", static: false, private: false, access: { has: obj => "_factor" in obj, get: obj => obj._factor, set: (obj, value) => { obj._factor = value; } }, metadata: _metadata }, __factor_initializers, __factor_extraInitializers);
262
+ __esDecorate(null, null, _mode_decorators, { kind: "field", name: "mode", static: false, private: false, access: { has: obj => "mode" in obj, get: obj => obj.mode, set: (obj, value) => { obj.mode = value; } }, metadata: _metadata }, _mode_initializers, _mode_extraInitializers);
263
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
264
+ ReplicationRangeMessageU32 = _classThis = _classDescriptor.value;
265
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
266
+ __runInitializers(_classThis, _classExtraInitializers);
267
+ }
268
+ id = __runInitializers(this, _id_initializers, void 0);
269
+ timestamp = (__runInitializers(this, _id_extraInitializers), __runInitializers(this, _timestamp_initializers, void 0));
270
+ _offset = (__runInitializers(this, _timestamp_extraInitializers), __runInitializers(this, __offset_initializers, void 0));
271
+ _factor = (__runInitializers(this, __offset_extraInitializers), __runInitializers(this, __factor_initializers, void 0));
272
+ mode = (__runInitializers(this, __factor_extraInitializers), __runInitializers(this, _mode_initializers, void 0));
273
+ constructor(properties) {
274
+ super();
275
+ __runInitializers(this, _mode_extraInitializers);
276
+ const { id, offset, factor, timestamp, mode } = properties;
277
+ this.id = id;
278
+ this._offset = offset;
279
+ this._factor = factor;
280
+ this.timestamp = timestamp;
281
+ this.mode = mode;
282
+ }
283
+ get factor() {
284
+ return this._factor;
285
+ }
286
+ get offset() {
287
+ return this._offset;
288
+ }
289
+ toReplicationRangeIndexable(key) {
290
+ return new ReplicationRangeIndexableU32({
291
+ id: this.id,
292
+ publicKeyHash: key.hashcode(),
293
+ offset: this.offset,
294
+ width: this.factor,
295
+ timestamp: this.timestamp,
296
+ mode: this.mode,
297
+ });
298
+ }
299
+ };
300
+ return ReplicationRangeMessageU32 = _classThis;
301
+ })();
231
302
  export { ReplicationRangeMessageU32 };
232
- let ReplicationRangeMessageU64 = class ReplicationRangeMessageU64 extends ReplicationRangeMessage {
233
- id;
234
- timestamp;
235
- _offset;
236
- _factor;
237
- mode;
238
- constructor(properties) {
239
- super();
240
- const { id, offset, factor, timestamp, mode } = properties;
241
- this.id = id;
242
- this._offset = offset;
243
- this._factor = factor;
244
- this.timestamp = timestamp;
245
- this.mode = mode;
246
- }
247
- get factor() {
248
- return this._factor;
249
- }
250
- get offset() {
251
- return this._offset;
252
- }
253
- toReplicationRangeIndexable(key) {
254
- return new ReplicationRangeIndexableU64({
255
- id: this.id,
256
- publicKeyHash: key.hashcode(),
257
- offset: this.offset,
258
- width: this.factor,
259
- timestamp: this.timestamp,
260
- mode: this.mode,
261
- });
262
- }
263
- };
264
- __decorate([
265
- field({ type: Uint8Array }),
266
- __metadata("design:type", Uint8Array)
267
- ], ReplicationRangeMessageU64.prototype, "id", void 0);
268
- __decorate([
269
- field({ type: "u64" }),
270
- __metadata("design:type", BigInt)
271
- ], ReplicationRangeMessageU64.prototype, "timestamp", void 0);
272
- __decorate([
273
- field({ type: "u64" }),
274
- __metadata("design:type", BigInt)
275
- ], ReplicationRangeMessageU64.prototype, "_offset", void 0);
276
- __decorate([
277
- field({ type: "u64" }),
278
- __metadata("design:type", BigInt)
279
- ], ReplicationRangeMessageU64.prototype, "_factor", void 0);
280
- __decorate([
281
- field({ type: "u8" }),
282
- __metadata("design:type", Number)
283
- ], ReplicationRangeMessageU64.prototype, "mode", void 0);
284
- ReplicationRangeMessageU64 = __decorate([
285
- variant(1),
286
- __metadata("design:paramtypes", [Object])
287
- ], ReplicationRangeMessageU64);
303
+ let ReplicationRangeMessageU64 = (() => {
304
+ let _classDecorators = [variant(1)];
305
+ let _classDescriptor;
306
+ let _classExtraInitializers = [];
307
+ let _classThis;
308
+ let _classSuper = ReplicationRangeMessage;
309
+ let _id_decorators;
310
+ let _id_initializers = [];
311
+ let _id_extraInitializers = [];
312
+ let _timestamp_decorators;
313
+ let _timestamp_initializers = [];
314
+ let _timestamp_extraInitializers = [];
315
+ let __offset_decorators;
316
+ let __offset_initializers = [];
317
+ let __offset_extraInitializers = [];
318
+ let __factor_decorators;
319
+ let __factor_initializers = [];
320
+ let __factor_extraInitializers = [];
321
+ let _mode_decorators;
322
+ let _mode_initializers = [];
323
+ let _mode_extraInitializers = [];
324
+ var ReplicationRangeMessageU64 = class extends _classSuper {
325
+ static { _classThis = this; }
326
+ static {
327
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
328
+ _id_decorators = [field({ type: Uint8Array })];
329
+ _timestamp_decorators = [field({ type: "u64" })];
330
+ __offset_decorators = [field({ type: "u64" })];
331
+ __factor_decorators = [field({ type: "u64" })];
332
+ _mode_decorators = [field({ type: "u8" })];
333
+ __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
334
+ __esDecorate(null, null, _timestamp_decorators, { kind: "field", name: "timestamp", static: false, private: false, access: { has: obj => "timestamp" in obj, get: obj => obj.timestamp, set: (obj, value) => { obj.timestamp = value; } }, metadata: _metadata }, _timestamp_initializers, _timestamp_extraInitializers);
335
+ __esDecorate(null, null, __offset_decorators, { kind: "field", name: "_offset", static: false, private: false, access: { has: obj => "_offset" in obj, get: obj => obj._offset, set: (obj, value) => { obj._offset = value; } }, metadata: _metadata }, __offset_initializers, __offset_extraInitializers);
336
+ __esDecorate(null, null, __factor_decorators, { kind: "field", name: "_factor", static: false, private: false, access: { has: obj => "_factor" in obj, get: obj => obj._factor, set: (obj, value) => { obj._factor = value; } }, metadata: _metadata }, __factor_initializers, __factor_extraInitializers);
337
+ __esDecorate(null, null, _mode_decorators, { kind: "field", name: "mode", static: false, private: false, access: { has: obj => "mode" in obj, get: obj => obj.mode, set: (obj, value) => { obj.mode = value; } }, metadata: _metadata }, _mode_initializers, _mode_extraInitializers);
338
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
339
+ ReplicationRangeMessageU64 = _classThis = _classDescriptor.value;
340
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
341
+ __runInitializers(_classThis, _classExtraInitializers);
342
+ }
343
+ id = __runInitializers(this, _id_initializers, void 0);
344
+ timestamp = (__runInitializers(this, _id_extraInitializers), __runInitializers(this, _timestamp_initializers, void 0));
345
+ _offset = (__runInitializers(this, _timestamp_extraInitializers), __runInitializers(this, __offset_initializers, void 0));
346
+ _factor = (__runInitializers(this, __offset_extraInitializers), __runInitializers(this, __factor_initializers, void 0));
347
+ mode = (__runInitializers(this, __factor_extraInitializers), __runInitializers(this, _mode_initializers, void 0));
348
+ constructor(properties) {
349
+ super();
350
+ __runInitializers(this, _mode_extraInitializers);
351
+ const { id, offset, factor, timestamp, mode } = properties;
352
+ this.id = id;
353
+ this._offset = offset;
354
+ this._factor = factor;
355
+ this.timestamp = timestamp;
356
+ this.mode = mode;
357
+ }
358
+ get factor() {
359
+ return this._factor;
360
+ }
361
+ get offset() {
362
+ return this._offset;
363
+ }
364
+ toReplicationRangeIndexable(key) {
365
+ return new ReplicationRangeIndexableU64({
366
+ id: this.id,
367
+ publicKeyHash: key.hashcode(),
368
+ offset: this.offset,
369
+ width: this.factor,
370
+ timestamp: this.timestamp,
371
+ mode: this.mode,
372
+ });
373
+ }
374
+ };
375
+ return ReplicationRangeMessageU64 = _classThis;
376
+ })();
288
377
  export { ReplicationRangeMessageU64 };
289
- class HashableSegmentU32 {
290
- start1;
291
- end1;
292
- start2;
293
- end2;
294
- mode;
295
- constructor(properties) {
296
- this.start1 = properties.start1;
297
- this.end1 = properties.end1;
298
- this.start2 = properties.start2;
299
- this.end2 = properties.end2;
300
- this.mode = properties.mode;
301
- }
302
- }
303
- __decorate([
304
- field({ type: "u32" }),
305
- __metadata("design:type", Number)
306
- ], HashableSegmentU32.prototype, "start1", void 0);
307
- __decorate([
308
- field({ type: "u32" }),
309
- __metadata("design:type", Number)
310
- ], HashableSegmentU32.prototype, "end1", void 0);
311
- __decorate([
312
- field({ type: "u32" }),
313
- __metadata("design:type", Number)
314
- ], HashableSegmentU32.prototype, "start2", void 0);
315
- __decorate([
316
- field({ type: "u32" }),
317
- __metadata("design:type", Number)
318
- ], HashableSegmentU32.prototype, "end2", void 0);
319
- __decorate([
320
- field({ type: "u8" }),
321
- __metadata("design:type", Number)
322
- ], HashableSegmentU32.prototype, "mode", void 0);
323
- class HashableSegmentU64 {
324
- start1;
325
- end1;
326
- start2;
327
- end2;
328
- mode;
329
- constructor(properties) {
330
- this.start1 = properties.start1;
331
- this.end1 = properties.end1;
332
- this.start2 = properties.start2;
333
- this.end2 = properties.end2;
334
- this.mode = properties.mode;
335
- }
336
- }
337
- __decorate([
338
- field({ type: "u64" }),
339
- __metadata("design:type", BigInt)
340
- ], HashableSegmentU64.prototype, "start1", void 0);
341
- __decorate([
342
- field({ type: "u64" }),
343
- __metadata("design:type", BigInt)
344
- ], HashableSegmentU64.prototype, "end1", void 0);
345
- __decorate([
346
- field({ type: "u64" }),
347
- __metadata("design:type", BigInt)
348
- ], HashableSegmentU64.prototype, "start2", void 0);
349
- __decorate([
350
- field({ type: "u64" }),
351
- __metadata("design:type", BigInt)
352
- ], HashableSegmentU64.prototype, "end2", void 0);
353
- __decorate([
354
- field({ type: "u8" }),
355
- __metadata("design:type", Number)
356
- ], HashableSegmentU64.prototype, "mode", void 0);
378
+ let HashableSegmentU32 = (() => {
379
+ let _start1_decorators;
380
+ let _start1_initializers = [];
381
+ let _start1_extraInitializers = [];
382
+ let _end1_decorators;
383
+ let _end1_initializers = [];
384
+ let _end1_extraInitializers = [];
385
+ let _start2_decorators;
386
+ let _start2_initializers = [];
387
+ let _start2_extraInitializers = [];
388
+ let _end2_decorators;
389
+ let _end2_initializers = [];
390
+ let _end2_extraInitializers = [];
391
+ let _mode_decorators;
392
+ let _mode_initializers = [];
393
+ let _mode_extraInitializers = [];
394
+ return class HashableSegmentU32 {
395
+ static {
396
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
397
+ _start1_decorators = [field({ type: "u32" })];
398
+ _end1_decorators = [field({ type: "u32" })];
399
+ _start2_decorators = [field({ type: "u32" })];
400
+ _end2_decorators = [field({ type: "u32" })];
401
+ _mode_decorators = [field({ type: "u8" })];
402
+ __esDecorate(null, null, _start1_decorators, { kind: "field", name: "start1", static: false, private: false, access: { has: obj => "start1" in obj, get: obj => obj.start1, set: (obj, value) => { obj.start1 = value; } }, metadata: _metadata }, _start1_initializers, _start1_extraInitializers);
403
+ __esDecorate(null, null, _end1_decorators, { kind: "field", name: "end1", static: false, private: false, access: { has: obj => "end1" in obj, get: obj => obj.end1, set: (obj, value) => { obj.end1 = value; } }, metadata: _metadata }, _end1_initializers, _end1_extraInitializers);
404
+ __esDecorate(null, null, _start2_decorators, { kind: "field", name: "start2", static: false, private: false, access: { has: obj => "start2" in obj, get: obj => obj.start2, set: (obj, value) => { obj.start2 = value; } }, metadata: _metadata }, _start2_initializers, _start2_extraInitializers);
405
+ __esDecorate(null, null, _end2_decorators, { kind: "field", name: "end2", static: false, private: false, access: { has: obj => "end2" in obj, get: obj => obj.end2, set: (obj, value) => { obj.end2 = value; } }, metadata: _metadata }, _end2_initializers, _end2_extraInitializers);
406
+ __esDecorate(null, null, _mode_decorators, { kind: "field", name: "mode", static: false, private: false, access: { has: obj => "mode" in obj, get: obj => obj.mode, set: (obj, value) => { obj.mode = value; } }, metadata: _metadata }, _mode_initializers, _mode_extraInitializers);
407
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
408
+ }
409
+ start1 = __runInitializers(this, _start1_initializers, void 0);
410
+ end1 = (__runInitializers(this, _start1_extraInitializers), __runInitializers(this, _end1_initializers, void 0));
411
+ start2 = (__runInitializers(this, _end1_extraInitializers), __runInitializers(this, _start2_initializers, void 0));
412
+ end2 = (__runInitializers(this, _start2_extraInitializers), __runInitializers(this, _end2_initializers, void 0));
413
+ mode = (__runInitializers(this, _end2_extraInitializers), __runInitializers(this, _mode_initializers, void 0));
414
+ constructor(properties) {
415
+ __runInitializers(this, _mode_extraInitializers);
416
+ this.start1 = properties.start1;
417
+ this.end1 = properties.end1;
418
+ this.start2 = properties.start2;
419
+ this.end2 = properties.end2;
420
+ this.mode = properties.mode;
421
+ }
422
+ };
423
+ })();
424
+ let HashableSegmentU64 = (() => {
425
+ let _start1_decorators;
426
+ let _start1_initializers = [];
427
+ let _start1_extraInitializers = [];
428
+ let _end1_decorators;
429
+ let _end1_initializers = [];
430
+ let _end1_extraInitializers = [];
431
+ let _start2_decorators;
432
+ let _start2_initializers = [];
433
+ let _start2_extraInitializers = [];
434
+ let _end2_decorators;
435
+ let _end2_initializers = [];
436
+ let _end2_extraInitializers = [];
437
+ let _mode_decorators;
438
+ let _mode_initializers = [];
439
+ let _mode_extraInitializers = [];
440
+ return class HashableSegmentU64 {
441
+ static {
442
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
443
+ _start1_decorators = [field({ type: "u64" })];
444
+ _end1_decorators = [field({ type: "u64" })];
445
+ _start2_decorators = [field({ type: "u64" })];
446
+ _end2_decorators = [field({ type: "u64" })];
447
+ _mode_decorators = [field({ type: "u8" })];
448
+ __esDecorate(null, null, _start1_decorators, { kind: "field", name: "start1", static: false, private: false, access: { has: obj => "start1" in obj, get: obj => obj.start1, set: (obj, value) => { obj.start1 = value; } }, metadata: _metadata }, _start1_initializers, _start1_extraInitializers);
449
+ __esDecorate(null, null, _end1_decorators, { kind: "field", name: "end1", static: false, private: false, access: { has: obj => "end1" in obj, get: obj => obj.end1, set: (obj, value) => { obj.end1 = value; } }, metadata: _metadata }, _end1_initializers, _end1_extraInitializers);
450
+ __esDecorate(null, null, _start2_decorators, { kind: "field", name: "start2", static: false, private: false, access: { has: obj => "start2" in obj, get: obj => obj.start2, set: (obj, value) => { obj.start2 = value; } }, metadata: _metadata }, _start2_initializers, _start2_extraInitializers);
451
+ __esDecorate(null, null, _end2_decorators, { kind: "field", name: "end2", static: false, private: false, access: { has: obj => "end2" in obj, get: obj => obj.end2, set: (obj, value) => { obj.end2 = value; } }, metadata: _metadata }, _end2_initializers, _end2_extraInitializers);
452
+ __esDecorate(null, null, _mode_decorators, { kind: "field", name: "mode", static: false, private: false, access: { has: obj => "mode" in obj, get: obj => obj.mode, set: (obj, value) => { obj.mode = value; } }, metadata: _metadata }, _mode_initializers, _mode_extraInitializers);
453
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
454
+ }
455
+ start1 = __runInitializers(this, _start1_initializers, void 0);
456
+ end1 = (__runInitializers(this, _start1_extraInitializers), __runInitializers(this, _end1_initializers, void 0));
457
+ start2 = (__runInitializers(this, _end1_extraInitializers), __runInitializers(this, _start2_initializers, void 0));
458
+ end2 = (__runInitializers(this, _start2_extraInitializers), __runInitializers(this, _end2_initializers, void 0));
459
+ mode = (__runInitializers(this, _end2_extraInitializers), __runInitializers(this, _mode_initializers, void 0));
460
+ constructor(properties) {
461
+ __runInitializers(this, _mode_extraInitializers);
462
+ this.start1 = properties.start1;
463
+ this.end1 = properties.end1;
464
+ this.start2 = properties.start2;
465
+ this.end2 = properties.end2;
466
+ this.mode = properties.mode;
467
+ }
468
+ };
469
+ })();
357
470
  /**
358
471
  * Convert a GeneralRange<N> into one or two `[bigint, bigint]` segments.
359
472
  * - If it’s not wrapped, there’s one segment: [start1, end1).
@@ -533,304 +646,338 @@ export function symmetricDifferenceRanges(rangeA, rangeB) {
533
646
  rangesFromB,
534
647
  };
535
648
  }
536
- export class ReplicationRangeIndexableU32 {
537
- id;
538
- hash;
539
- timestamp;
540
- start1;
541
- end1;
542
- start2;
543
- end2;
544
- width;
545
- mode;
546
- constructor(properties) {
547
- this.id = properties.id ?? randomBytes(32);
548
- this.hash =
549
- properties.publicKeyHash ||
550
- properties.publicKey.hashcode();
551
- this.transform({ width: properties.width, offset: properties.offset });
552
- this.mode = properties.mode ?? ReplicationIntent.NonStrict;
553
- this.timestamp = properties.timestamp || BigInt(0);
554
- }
555
- transform(properties) {
556
- const ranges = getSegmentsFromOffsetAndRange(properties.offset, properties.width, 0, MAX_U32);
557
- this.start1 = Math.round(ranges[0][0]);
558
- this.end1 = Math.round(ranges[0][1]);
559
- this.start2 = Math.round(ranges[1][0]);
560
- this.end2 = Math.round(ranges[1][1]);
561
- this.width =
562
- this.end1 -
563
- this.start1 +
564
- (this.end2 < this.end1 ? this.end2 - this.start2 : 0);
565
- if (this.start1 > MAX_U32 ||
566
- this.end1 > MAX_U32 ||
567
- this.start2 > MAX_U32 ||
568
- this.end2 > MAX_U32 ||
569
- this.width > MAX_U32 ||
570
- this.width < 0) {
571
- throw new Error("Segment coordinate out of bounds");
649
+ let ReplicationRangeIndexableU32 = (() => {
650
+ let _id_decorators;
651
+ let _id_initializers = [];
652
+ let _id_extraInitializers = [];
653
+ let _hash_decorators;
654
+ let _hash_initializers = [];
655
+ let _hash_extraInitializers = [];
656
+ let _timestamp_decorators;
657
+ let _timestamp_initializers = [];
658
+ let _timestamp_extraInitializers = [];
659
+ let _start1_decorators;
660
+ let _start1_initializers = [];
661
+ let _start1_extraInitializers = [];
662
+ let _end1_decorators;
663
+ let _end1_initializers = [];
664
+ let _end1_extraInitializers = [];
665
+ let _start2_decorators;
666
+ let _start2_initializers = [];
667
+ let _start2_extraInitializers = [];
668
+ let _end2_decorators;
669
+ let _end2_initializers = [];
670
+ let _end2_extraInitializers = [];
671
+ let _width_decorators;
672
+ let _width_initializers = [];
673
+ let _width_extraInitializers = [];
674
+ let _mode_decorators;
675
+ let _mode_initializers = [];
676
+ let _mode_extraInitializers = [];
677
+ return class ReplicationRangeIndexableU32 {
678
+ static {
679
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
680
+ _id_decorators = [id({ type: Uint8Array })];
681
+ _hash_decorators = [field({ type: "string" })];
682
+ _timestamp_decorators = [field({ type: "u64" })];
683
+ _start1_decorators = [field({ type: "u32" })];
684
+ _end1_decorators = [field({ type: "u32" })];
685
+ _start2_decorators = [field({ type: "u32" })];
686
+ _end2_decorators = [field({ type: "u32" })];
687
+ _width_decorators = [field({ type: "u32" })];
688
+ _mode_decorators = [field({ type: "u8" })];
689
+ __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
690
+ __esDecorate(null, null, _hash_decorators, { kind: "field", name: "hash", static: false, private: false, access: { has: obj => "hash" in obj, get: obj => obj.hash, set: (obj, value) => { obj.hash = value; } }, metadata: _metadata }, _hash_initializers, _hash_extraInitializers);
691
+ __esDecorate(null, null, _timestamp_decorators, { kind: "field", name: "timestamp", static: false, private: false, access: { has: obj => "timestamp" in obj, get: obj => obj.timestamp, set: (obj, value) => { obj.timestamp = value; } }, metadata: _metadata }, _timestamp_initializers, _timestamp_extraInitializers);
692
+ __esDecorate(null, null, _start1_decorators, { kind: "field", name: "start1", static: false, private: false, access: { has: obj => "start1" in obj, get: obj => obj.start1, set: (obj, value) => { obj.start1 = value; } }, metadata: _metadata }, _start1_initializers, _start1_extraInitializers);
693
+ __esDecorate(null, null, _end1_decorators, { kind: "field", name: "end1", static: false, private: false, access: { has: obj => "end1" in obj, get: obj => obj.end1, set: (obj, value) => { obj.end1 = value; } }, metadata: _metadata }, _end1_initializers, _end1_extraInitializers);
694
+ __esDecorate(null, null, _start2_decorators, { kind: "field", name: "start2", static: false, private: false, access: { has: obj => "start2" in obj, get: obj => obj.start2, set: (obj, value) => { obj.start2 = value; } }, metadata: _metadata }, _start2_initializers, _start2_extraInitializers);
695
+ __esDecorate(null, null, _end2_decorators, { kind: "field", name: "end2", static: false, private: false, access: { has: obj => "end2" in obj, get: obj => obj.end2, set: (obj, value) => { obj.end2 = value; } }, metadata: _metadata }, _end2_initializers, _end2_extraInitializers);
696
+ __esDecorate(null, null, _width_decorators, { kind: "field", name: "width", static: false, private: false, access: { has: obj => "width" in obj, get: obj => obj.width, set: (obj, value) => { obj.width = value; } }, metadata: _metadata }, _width_initializers, _width_extraInitializers);
697
+ __esDecorate(null, null, _mode_decorators, { kind: "field", name: "mode", static: false, private: false, access: { has: obj => "mode" in obj, get: obj => obj.mode, set: (obj, value) => { obj.mode = value; } }, metadata: _metadata }, _mode_initializers, _mode_extraInitializers);
698
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
572
699
  }
573
- }
574
- get idString() {
575
- return toBase64(this.id);
576
- }
577
- get rangeHash() {
578
- const ser = serialize(this);
579
- return sha256Base64Sync(ser);
580
- }
581
- contains(point) {
582
- return ((point >= this.start1 && point < this.end1) ||
583
- (point >= this.start2 && point < this.end2));
584
- }
585
- overlaps(other, checkOther = true) {
586
- if (this.contains(other.start1) ||
587
- this.contains(other.start2) ||
588
- this.contains(other.end1 - 1) ||
589
- this.contains(other.end2 - 1)) {
590
- return true;
700
+ id = __runInitializers(this, _id_initializers, void 0);
701
+ hash = (__runInitializers(this, _id_extraInitializers), __runInitializers(this, _hash_initializers, void 0));
702
+ timestamp = (__runInitializers(this, _hash_extraInitializers), __runInitializers(this, _timestamp_initializers, void 0));
703
+ start1 = (__runInitializers(this, _timestamp_extraInitializers), __runInitializers(this, _start1_initializers, void 0));
704
+ end1 = (__runInitializers(this, _start1_extraInitializers), __runInitializers(this, _end1_initializers, void 0));
705
+ start2 = (__runInitializers(this, _end1_extraInitializers), __runInitializers(this, _start2_initializers, void 0));
706
+ end2 = (__runInitializers(this, _start2_extraInitializers), __runInitializers(this, _end2_initializers, void 0));
707
+ width = (__runInitializers(this, _end2_extraInitializers), __runInitializers(this, _width_initializers, void 0));
708
+ mode = (__runInitializers(this, _width_extraInitializers), __runInitializers(this, _mode_initializers, void 0));
709
+ constructor(properties) {
710
+ __runInitializers(this, _mode_extraInitializers);
711
+ this.id = properties.id ?? randomBytes(32);
712
+ this.hash =
713
+ properties.publicKeyHash ||
714
+ properties.publicKey.hashcode();
715
+ this.transform({ width: properties.width, offset: properties.offset });
716
+ this.mode = properties.mode ?? ReplicationIntent.NonStrict;
717
+ this.timestamp = properties.timestamp || BigInt(0);
591
718
  }
592
- if (checkOther) {
593
- return other.overlaps(this, false);
719
+ transform(properties) {
720
+ const ranges = getSegmentsFromOffsetAndRange(properties.offset, properties.width, 0, MAX_U32);
721
+ this.start1 = Math.round(ranges[0][0]);
722
+ this.end1 = Math.round(ranges[0][1]);
723
+ this.start2 = Math.round(ranges[1][0]);
724
+ this.end2 = Math.round(ranges[1][1]);
725
+ this.width =
726
+ this.end1 -
727
+ this.start1 +
728
+ (this.end2 < this.end1 ? this.end2 - this.start2 : 0);
729
+ if (this.start1 > MAX_U32 ||
730
+ this.end1 > MAX_U32 ||
731
+ this.start2 > MAX_U32 ||
732
+ this.end2 > MAX_U32 ||
733
+ this.width > MAX_U32 ||
734
+ this.width < 0) {
735
+ throw new Error("Segment coordinate out of bounds");
736
+ }
594
737
  }
595
- return false;
596
- }
597
- toReplicationRange() {
598
- return new ReplicationRangeMessageU32({
599
- id: this.id,
600
- offset: this.start1,
601
- factor: this.width,
602
- timestamp: this.timestamp,
603
- mode: this.mode,
604
- });
605
- }
606
- get wrapped() {
607
- return this.end2 < this.end1;
608
- }
609
- get widthNormalized() {
610
- return this.width / MAX_U32;
611
- }
612
- equals(other) {
613
- if (equals(this.id, other.id) &&
614
- this.hash === other.hash &&
615
- this.timestamp === other.timestamp &&
616
- this.mode === other.mode &&
617
- this.start1 === other.start1 &&
618
- this.end1 === other.end1 &&
619
- this.start2 === other.start2 &&
620
- this.end2 === other.end2 &&
621
- this.width === other.width) {
622
- return true;
623
- }
624
- return false;
625
- }
626
- equalRange(other) {
627
- return (this.hash === other.hash &&
628
- this.start1 === other.start1 &&
629
- this.end1 === other.end1 &&
630
- this.start2 === other.start2 &&
631
- this.end2 === other.end2);
632
- }
633
- toString() {
634
- let roundToTwoDecimals = (num) => Math.round(num * 100) / 100;
635
- if (Math.abs(this.start1 - this.start2) < 0.0001) {
636
- return `([${roundToTwoDecimals(this.start1 / MAX_U32)}, ${roundToTwoDecimals(this.end1 / MAX_U32)}])`;
738
+ get idString() {
739
+ return toBase64(this.id);
637
740
  }
638
- return `([${roundToTwoDecimals(this.start1 / MAX_U32)}, ${roundToTwoDecimals(this.end1 / MAX_U32)}] [${roundToTwoDecimals(this.start2 / MAX_U32)}, ${roundToTwoDecimals(this.end2 / MAX_U32)}])`;
639
- }
640
- toStringDetailed() {
641
- return `(hash ${this.hash} range: ${this.toString()})`;
642
- }
643
- toUniqueSegmentId() {
644
- // return a unique id as a function of the segments location and the replication intent
645
- const hashable = new HashableSegmentU32(this);
646
- return sha256Base64Sync(serialize(hashable));
647
- }
648
- }
649
- __decorate([
650
- id({ type: Uint8Array }),
651
- __metadata("design:type", Uint8Array)
652
- ], ReplicationRangeIndexableU32.prototype, "id", void 0);
653
- __decorate([
654
- field({ type: "string" }),
655
- __metadata("design:type", String)
656
- ], ReplicationRangeIndexableU32.prototype, "hash", void 0);
657
- __decorate([
658
- field({ type: "u64" }),
659
- __metadata("design:type", BigInt)
660
- ], ReplicationRangeIndexableU32.prototype, "timestamp", void 0);
661
- __decorate([
662
- field({ type: "u32" }),
663
- __metadata("design:type", Number)
664
- ], ReplicationRangeIndexableU32.prototype, "start1", void 0);
665
- __decorate([
666
- field({ type: "u32" }),
667
- __metadata("design:type", Number)
668
- ], ReplicationRangeIndexableU32.prototype, "end1", void 0);
669
- __decorate([
670
- field({ type: "u32" }),
671
- __metadata("design:type", Number)
672
- ], ReplicationRangeIndexableU32.prototype, "start2", void 0);
673
- __decorate([
674
- field({ type: "u32" }),
675
- __metadata("design:type", Number)
676
- ], ReplicationRangeIndexableU32.prototype, "end2", void 0);
677
- __decorate([
678
- field({ type: "u32" }),
679
- __metadata("design:type", Number)
680
- ], ReplicationRangeIndexableU32.prototype, "width", void 0);
681
- __decorate([
682
- field({ type: "u8" }),
683
- __metadata("design:type", Number)
684
- ], ReplicationRangeIndexableU32.prototype, "mode", void 0);
685
- export class ReplicationRangeIndexableU64 {
686
- id;
687
- hash; // publickey hash
688
- timestamp;
689
- start1;
690
- end1;
691
- start2;
692
- end2;
693
- width;
694
- mode;
695
- constructor(properties) {
696
- this.id = properties.id ?? randomBytes(32);
697
- this.hash =
698
- properties.publicKeyHash ||
699
- properties.publicKey.hashcode();
700
- this.transform({ width: properties.width, offset: properties.offset });
701
- this.mode = properties.mode ?? ReplicationIntent.NonStrict;
702
- this.timestamp = properties.timestamp || BigInt(0);
703
- }
704
- transform(properties) {
705
- const ranges = getSegmentsFromOffsetAndRange(BigInt(properties.offset), BigInt(properties.width), 0n, MAX_U64);
706
- this.start1 = ranges[0][0];
707
- this.end1 = ranges[0][1];
708
- this.start2 = ranges[1][0];
709
- this.end2 = ranges[1][1];
710
- this.width =
711
- this.end1 -
712
- this.start1 +
713
- (this.end2 < this.end1 ? this.end2 - this.start2 : 0n);
714
- if (this.start1 > MAX_U64 ||
715
- this.end1 > MAX_U64 ||
716
- this.start2 > MAX_U64 ||
717
- this.end2 > MAX_U64 ||
718
- this.width > MAX_U64 ||
719
- this.width < 0n) {
720
- throw new Error("Segment coordinate out of bounds");
741
+ get rangeHash() {
742
+ const ser = serialize(this);
743
+ return sha256Base64Sync(ser);
721
744
  }
722
- }
723
- get idString() {
724
- return toBase64(this.id);
725
- }
726
- contains(point) {
727
- return ((point >= this.start1 && point < this.end1) ||
728
- (point >= this.start2 && point < this.end2));
729
- }
730
- get rangeHash() {
731
- const ser = serialize(this);
732
- return sha256Base64Sync(ser);
733
- }
734
- overlaps(other, checkOther = true) {
735
- if (this.contains(other.start1) ||
736
- this.contains(other.start2) ||
737
- this.contains(other.end1 - 1n) ||
738
- this.contains(other.end2 - 1n)) {
739
- return true;
745
+ contains(point) {
746
+ return ((point >= this.start1 && point < this.end1) ||
747
+ (point >= this.start2 && point < this.end2));
740
748
  }
741
- if (checkOther) {
742
- return other.overlaps(this, false);
749
+ overlaps(other, checkOther = true) {
750
+ if (this.contains(other.start1) ||
751
+ this.contains(other.start2) ||
752
+ this.contains(other.end1 - 1) ||
753
+ this.contains(other.end2 - 1)) {
754
+ return true;
755
+ }
756
+ if (checkOther) {
757
+ return other.overlaps(this, false);
758
+ }
759
+ return false;
743
760
  }
744
- return false;
745
- }
746
- toReplicationRange() {
747
- return new ReplicationRangeMessageU64({
748
- id: this.id,
749
- offset: this.start1,
750
- factor: this.width,
751
- timestamp: this.timestamp,
752
- mode: this.mode,
753
- });
754
- }
755
- get wrapped() {
756
- return this.end2 < this.end1;
757
- }
758
- get widthNormalized() {
759
- return Number(this.width) / Number(MAX_U64);
760
- }
761
- equals(other) {
762
- if (equals(this.id, other.id) &&
763
- this.hash === other.hash &&
764
- this.timestamp === other.timestamp &&
765
- this.mode === other.mode &&
766
- this.start1 === other.start1 &&
767
- this.end1 === other.end1 &&
768
- this.start2 === other.start2 &&
769
- this.end2 === other.end2 &&
770
- this.width === other.width) {
771
- return true;
772
- }
773
- return false;
774
- }
775
- equalRange(other) {
776
- return (this.hash === other.hash &&
777
- this.start1 === other.start1 &&
778
- this.end1 === other.end1 &&
779
- this.start2 === other.start2 &&
780
- this.end2 === other.end2);
781
- }
782
- toString() {
783
- let roundToTwoDecimals = (num) => Math.round(num * 100) / 100;
784
- if (Math.abs(Number(this.start1 - this.start2)) < 0.0001) {
785
- return `([${roundToTwoDecimals(Number(this.start1) / Number(MAX_U64))}, ${roundToTwoDecimals(Number(this.start1) / Number(MAX_U64))}])`;
761
+ toReplicationRange() {
762
+ return new ReplicationRangeMessageU32({
763
+ id: this.id,
764
+ offset: this.start1,
765
+ factor: this.width,
766
+ timestamp: this.timestamp,
767
+ mode: this.mode,
768
+ });
786
769
  }
787
- return `([${roundToTwoDecimals(Number(this.start1) / Number(MAX_U64))}, ${roundToTwoDecimals(Number(this.start1) / Number(MAX_U64))}] [${roundToTwoDecimals(Number(this.start2) / Number(MAX_U64))}, ${roundToTwoDecimals(Number(this.end2) / Number(MAX_U64))}])`;
788
- }
789
- toStringDetailed() {
790
- return `(hash ${this.hash} range: ${this.toString()})`;
791
- }
792
- toUniqueSegmentId() {
793
- // return a unique id as a function of the segments location and the replication intent
794
- const hashable = new HashableSegmentU64(this);
795
- return sha256Base64Sync(serialize(hashable));
796
- }
797
- }
798
- __decorate([
799
- id({ type: Uint8Array }),
800
- __metadata("design:type", Uint8Array)
801
- ], ReplicationRangeIndexableU64.prototype, "id", void 0);
802
- __decorate([
803
- field({ type: "string" }),
804
- __metadata("design:type", String)
805
- ], ReplicationRangeIndexableU64.prototype, "hash", void 0);
806
- __decorate([
807
- field({ type: "u64" }),
808
- __metadata("design:type", BigInt)
809
- ], ReplicationRangeIndexableU64.prototype, "timestamp", void 0);
810
- __decorate([
811
- field({ type: "u64" }),
812
- __metadata("design:type", BigInt)
813
- ], ReplicationRangeIndexableU64.prototype, "start1", void 0);
814
- __decorate([
815
- field({ type: "u64" }),
816
- __metadata("design:type", BigInt)
817
- ], ReplicationRangeIndexableU64.prototype, "end1", void 0);
818
- __decorate([
819
- field({ type: "u64" }),
820
- __metadata("design:type", BigInt)
821
- ], ReplicationRangeIndexableU64.prototype, "start2", void 0);
822
- __decorate([
823
- field({ type: "u64" }),
824
- __metadata("design:type", BigInt)
825
- ], ReplicationRangeIndexableU64.prototype, "end2", void 0);
826
- __decorate([
827
- field({ type: "u64" }),
828
- __metadata("design:type", BigInt)
829
- ], ReplicationRangeIndexableU64.prototype, "width", void 0);
830
- __decorate([
831
- field({ type: "u8" }),
832
- __metadata("design:type", Number)
833
- ], ReplicationRangeIndexableU64.prototype, "mode", void 0);
770
+ get wrapped() {
771
+ return this.end2 < this.end1;
772
+ }
773
+ get widthNormalized() {
774
+ return this.width / MAX_U32;
775
+ }
776
+ equals(other) {
777
+ if (equals(this.id, other.id) &&
778
+ this.hash === other.hash &&
779
+ this.timestamp === other.timestamp &&
780
+ this.mode === other.mode &&
781
+ this.start1 === other.start1 &&
782
+ this.end1 === other.end1 &&
783
+ this.start2 === other.start2 &&
784
+ this.end2 === other.end2 &&
785
+ this.width === other.width) {
786
+ return true;
787
+ }
788
+ return false;
789
+ }
790
+ equalRange(other) {
791
+ return (this.hash === other.hash &&
792
+ this.start1 === other.start1 &&
793
+ this.end1 === other.end1 &&
794
+ this.start2 === other.start2 &&
795
+ this.end2 === other.end2);
796
+ }
797
+ toString() {
798
+ let roundToTwoDecimals = (num) => Math.round(num * 100) / 100;
799
+ if (Math.abs(this.start1 - this.start2) < 0.0001) {
800
+ return `([${roundToTwoDecimals(this.start1 / MAX_U32)}, ${roundToTwoDecimals(this.end1 / MAX_U32)}])`;
801
+ }
802
+ return `([${roundToTwoDecimals(this.start1 / MAX_U32)}, ${roundToTwoDecimals(this.end1 / MAX_U32)}] [${roundToTwoDecimals(this.start2 / MAX_U32)}, ${roundToTwoDecimals(this.end2 / MAX_U32)}])`;
803
+ }
804
+ toStringDetailed() {
805
+ return `(hash ${this.hash} range: ${this.toString()})`;
806
+ }
807
+ toUniqueSegmentId() {
808
+ // return a unique id as a function of the segments location and the replication intent
809
+ const hashable = new HashableSegmentU32(this);
810
+ return sha256Base64Sync(serialize(hashable));
811
+ }
812
+ };
813
+ })();
814
+ export { ReplicationRangeIndexableU32 };
815
+ let ReplicationRangeIndexableU64 = (() => {
816
+ let _id_decorators;
817
+ let _id_initializers = [];
818
+ let _id_extraInitializers = [];
819
+ let _hash_decorators;
820
+ let _hash_initializers = [];
821
+ let _hash_extraInitializers = [];
822
+ let _timestamp_decorators;
823
+ let _timestamp_initializers = [];
824
+ let _timestamp_extraInitializers = [];
825
+ let _start1_decorators;
826
+ let _start1_initializers = [];
827
+ let _start1_extraInitializers = [];
828
+ let _end1_decorators;
829
+ let _end1_initializers = [];
830
+ let _end1_extraInitializers = [];
831
+ let _start2_decorators;
832
+ let _start2_initializers = [];
833
+ let _start2_extraInitializers = [];
834
+ let _end2_decorators;
835
+ let _end2_initializers = [];
836
+ let _end2_extraInitializers = [];
837
+ let _width_decorators;
838
+ let _width_initializers = [];
839
+ let _width_extraInitializers = [];
840
+ let _mode_decorators;
841
+ let _mode_initializers = [];
842
+ let _mode_extraInitializers = [];
843
+ return class ReplicationRangeIndexableU64 {
844
+ static {
845
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
846
+ _id_decorators = [id({ type: Uint8Array })];
847
+ _hash_decorators = [field({ type: "string" })];
848
+ _timestamp_decorators = [field({ type: "u64" })];
849
+ _start1_decorators = [field({ type: "u64" })];
850
+ _end1_decorators = [field({ type: "u64" })];
851
+ _start2_decorators = [field({ type: "u64" })];
852
+ _end2_decorators = [field({ type: "u64" })];
853
+ _width_decorators = [field({ type: "u64" })];
854
+ _mode_decorators = [field({ type: "u8" })];
855
+ __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
856
+ __esDecorate(null, null, _hash_decorators, { kind: "field", name: "hash", static: false, private: false, access: { has: obj => "hash" in obj, get: obj => obj.hash, set: (obj, value) => { obj.hash = value; } }, metadata: _metadata }, _hash_initializers, _hash_extraInitializers);
857
+ __esDecorate(null, null, _timestamp_decorators, { kind: "field", name: "timestamp", static: false, private: false, access: { has: obj => "timestamp" in obj, get: obj => obj.timestamp, set: (obj, value) => { obj.timestamp = value; } }, metadata: _metadata }, _timestamp_initializers, _timestamp_extraInitializers);
858
+ __esDecorate(null, null, _start1_decorators, { kind: "field", name: "start1", static: false, private: false, access: { has: obj => "start1" in obj, get: obj => obj.start1, set: (obj, value) => { obj.start1 = value; } }, metadata: _metadata }, _start1_initializers, _start1_extraInitializers);
859
+ __esDecorate(null, null, _end1_decorators, { kind: "field", name: "end1", static: false, private: false, access: { has: obj => "end1" in obj, get: obj => obj.end1, set: (obj, value) => { obj.end1 = value; } }, metadata: _metadata }, _end1_initializers, _end1_extraInitializers);
860
+ __esDecorate(null, null, _start2_decorators, { kind: "field", name: "start2", static: false, private: false, access: { has: obj => "start2" in obj, get: obj => obj.start2, set: (obj, value) => { obj.start2 = value; } }, metadata: _metadata }, _start2_initializers, _start2_extraInitializers);
861
+ __esDecorate(null, null, _end2_decorators, { kind: "field", name: "end2", static: false, private: false, access: { has: obj => "end2" in obj, get: obj => obj.end2, set: (obj, value) => { obj.end2 = value; } }, metadata: _metadata }, _end2_initializers, _end2_extraInitializers);
862
+ __esDecorate(null, null, _width_decorators, { kind: "field", name: "width", static: false, private: false, access: { has: obj => "width" in obj, get: obj => obj.width, set: (obj, value) => { obj.width = value; } }, metadata: _metadata }, _width_initializers, _width_extraInitializers);
863
+ __esDecorate(null, null, _mode_decorators, { kind: "field", name: "mode", static: false, private: false, access: { has: obj => "mode" in obj, get: obj => obj.mode, set: (obj, value) => { obj.mode = value; } }, metadata: _metadata }, _mode_initializers, _mode_extraInitializers);
864
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
865
+ }
866
+ id = __runInitializers(this, _id_initializers, void 0);
867
+ hash = (__runInitializers(this, _id_extraInitializers), __runInitializers(this, _hash_initializers, void 0)); // publickey hash
868
+ timestamp = (__runInitializers(this, _hash_extraInitializers), __runInitializers(this, _timestamp_initializers, void 0));
869
+ start1 = (__runInitializers(this, _timestamp_extraInitializers), __runInitializers(this, _start1_initializers, void 0));
870
+ end1 = (__runInitializers(this, _start1_extraInitializers), __runInitializers(this, _end1_initializers, void 0));
871
+ start2 = (__runInitializers(this, _end1_extraInitializers), __runInitializers(this, _start2_initializers, void 0));
872
+ end2 = (__runInitializers(this, _start2_extraInitializers), __runInitializers(this, _end2_initializers, void 0));
873
+ width = (__runInitializers(this, _end2_extraInitializers), __runInitializers(this, _width_initializers, void 0));
874
+ mode = (__runInitializers(this, _width_extraInitializers), __runInitializers(this, _mode_initializers, void 0));
875
+ constructor(properties) {
876
+ __runInitializers(this, _mode_extraInitializers);
877
+ this.id = properties.id ?? randomBytes(32);
878
+ this.hash =
879
+ properties.publicKeyHash ||
880
+ properties.publicKey.hashcode();
881
+ this.transform({ width: properties.width, offset: properties.offset });
882
+ this.mode = properties.mode ?? ReplicationIntent.NonStrict;
883
+ this.timestamp = properties.timestamp || BigInt(0);
884
+ }
885
+ transform(properties) {
886
+ const ranges = getSegmentsFromOffsetAndRange(BigInt(properties.offset), BigInt(properties.width), 0n, MAX_U64);
887
+ this.start1 = ranges[0][0];
888
+ this.end1 = ranges[0][1];
889
+ this.start2 = ranges[1][0];
890
+ this.end2 = ranges[1][1];
891
+ this.width =
892
+ this.end1 -
893
+ this.start1 +
894
+ (this.end2 < this.end1 ? this.end2 - this.start2 : 0n);
895
+ if (this.start1 > MAX_U64 ||
896
+ this.end1 > MAX_U64 ||
897
+ this.start2 > MAX_U64 ||
898
+ this.end2 > MAX_U64 ||
899
+ this.width > MAX_U64 ||
900
+ this.width < 0n) {
901
+ throw new Error("Segment coordinate out of bounds");
902
+ }
903
+ }
904
+ get idString() {
905
+ return toBase64(this.id);
906
+ }
907
+ contains(point) {
908
+ return ((point >= this.start1 && point < this.end1) ||
909
+ (point >= this.start2 && point < this.end2));
910
+ }
911
+ get rangeHash() {
912
+ const ser = serialize(this);
913
+ return sha256Base64Sync(ser);
914
+ }
915
+ overlaps(other, checkOther = true) {
916
+ if (this.contains(other.start1) ||
917
+ this.contains(other.start2) ||
918
+ this.contains(other.end1 - 1n) ||
919
+ this.contains(other.end2 - 1n)) {
920
+ return true;
921
+ }
922
+ if (checkOther) {
923
+ return other.overlaps(this, false);
924
+ }
925
+ return false;
926
+ }
927
+ toReplicationRange() {
928
+ return new ReplicationRangeMessageU64({
929
+ id: this.id,
930
+ offset: this.start1,
931
+ factor: this.width,
932
+ timestamp: this.timestamp,
933
+ mode: this.mode,
934
+ });
935
+ }
936
+ get wrapped() {
937
+ return this.end2 < this.end1;
938
+ }
939
+ get widthNormalized() {
940
+ return Number(this.width) / Number(MAX_U64);
941
+ }
942
+ equals(other) {
943
+ if (equals(this.id, other.id) &&
944
+ this.hash === other.hash &&
945
+ this.timestamp === other.timestamp &&
946
+ this.mode === other.mode &&
947
+ this.start1 === other.start1 &&
948
+ this.end1 === other.end1 &&
949
+ this.start2 === other.start2 &&
950
+ this.end2 === other.end2 &&
951
+ this.width === other.width) {
952
+ return true;
953
+ }
954
+ return false;
955
+ }
956
+ equalRange(other) {
957
+ return (this.hash === other.hash &&
958
+ this.start1 === other.start1 &&
959
+ this.end1 === other.end1 &&
960
+ this.start2 === other.start2 &&
961
+ this.end2 === other.end2);
962
+ }
963
+ toString() {
964
+ let roundToTwoDecimals = (num) => Math.round(num * 100) / 100;
965
+ if (Math.abs(Number(this.start1 - this.start2)) < 0.0001) {
966
+ return `([${roundToTwoDecimals(Number(this.start1) / Number(MAX_U64))}, ${roundToTwoDecimals(Number(this.start1) / Number(MAX_U64))}])`;
967
+ }
968
+ return `([${roundToTwoDecimals(Number(this.start1) / Number(MAX_U64))}, ${roundToTwoDecimals(Number(this.start1) / Number(MAX_U64))}] [${roundToTwoDecimals(Number(this.start2) / Number(MAX_U64))}, ${roundToTwoDecimals(Number(this.end2) / Number(MAX_U64))}])`;
969
+ }
970
+ toStringDetailed() {
971
+ return `(hash ${this.hash} range: ${this.toString()})`;
972
+ }
973
+ toUniqueSegmentId() {
974
+ // return a unique id as a function of the segments location and the replication intent
975
+ const hashable = new HashableSegmentU64(this);
976
+ return sha256Base64Sync(serialize(hashable));
977
+ }
978
+ };
979
+ })();
980
+ export { ReplicationRangeIndexableU64 };
834
981
  export const mergeRanges = (segments, numbers) => {
835
982
  if (segments.length === 0) {
836
983
  throw new Error("No segments to merge");