@peerbit/pubsub 5.2.11 → 5.3.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/dist/benchmark/fanout-tree-parent-upgrade-default-ready.d.ts +3 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-default-ready.d.ts.map +1 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-default-ready.js +90 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-default-ready.js.map +1 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-eval.d.ts +2 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-eval.d.ts.map +1 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-eval.js +712 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-eval.js.map +1 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-multi-eval.d.ts +2 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-multi-eval.d.ts.map +1 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-multi-eval.js +1591 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-multi-eval.js.map +1 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-prepush.d.ts +2 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-prepush.d.ts.map +1 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-prepush.js +297 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-prepush.js.map +1 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-preset.d.ts +73 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-preset.d.ts.map +1 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-preset.js +183 -0
- package/dist/benchmark/fanout-tree-parent-upgrade-preset.js.map +1 -0
- package/dist/benchmark/fanout-tree-sim-lib.d.ts +101 -0
- package/dist/benchmark/fanout-tree-sim-lib.d.ts.map +1 -1
- package/dist/benchmark/fanout-tree-sim-lib.js +540 -38
- package/dist/benchmark/fanout-tree-sim-lib.js.map +1 -1
- package/dist/benchmark/fanout-tree-sim.d.ts +0 -9
- package/dist/benchmark/fanout-tree-sim.d.ts.map +1 -1
- package/dist/benchmark/fanout-tree-sim.js +369 -28
- package/dist/benchmark/fanout-tree-sim.js.map +1 -1
- package/dist/benchmark/index.js +20 -0
- package/dist/benchmark/index.js.map +1 -1
- package/dist/benchmark/pubsub-topic-sim-lib.d.ts +4 -0
- package/dist/benchmark/pubsub-topic-sim-lib.d.ts.map +1 -1
- package/dist/benchmark/pubsub-topic-sim-lib.js +58 -3
- package/dist/benchmark/pubsub-topic-sim-lib.js.map +1 -1
- package/dist/benchmark/pubsub-topic-sim.js +18 -0
- package/dist/benchmark/pubsub-topic-sim.js.map +1 -1
- package/dist/src/debounced-set.d.ts +1 -1
- package/dist/src/debounced-set.d.ts.map +1 -1
- package/dist/src/debounced-set.js +5 -1
- package/dist/src/debounced-set.js.map +1 -1
- package/dist/src/fanout-tree-codec.d.ts +330 -0
- package/dist/src/fanout-tree-codec.d.ts.map +1 -0
- package/dist/src/fanout-tree-codec.js +1209 -0
- package/dist/src/fanout-tree-codec.js.map +1 -0
- package/dist/src/fanout-tree-parent-upgrade.d.ts +117 -0
- package/dist/src/fanout-tree-parent-upgrade.d.ts.map +1 -0
- package/dist/src/fanout-tree-parent-upgrade.js +135 -0
- package/dist/src/fanout-tree-parent-upgrade.js.map +1 -0
- package/dist/src/fanout-tree.d.ts +241 -73
- package/dist/src/fanout-tree.d.ts.map +1 -1
- package/dist/src/fanout-tree.js +2224 -1050
- package/dist/src/fanout-tree.js.map +1 -1
- package/dist/src/index.d.ts +57 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +293 -41
- package/dist/src/index.js.map +1 -1
- package/dist/src/topic-root-control-plane.d.ts +13 -0
- package/dist/src/topic-root-control-plane.d.ts.map +1 -1
- package/dist/src/topic-root-control-plane.js +45 -0
- package/dist/src/topic-root-control-plane.js.map +1 -1
- package/package.json +7 -7
- package/src/debounced-set.ts +5 -0
- package/src/fanout-tree-codec.ts +1580 -0
- package/src/fanout-tree-parent-upgrade.ts +353 -0
- package/src/fanout-tree.ts +4467 -2204
- package/src/index.ts +392 -56
- package/src/topic-root-control-plane.ts +48 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { RustTopicRootDirectoryState } from "@peerbit/stream";
|
|
2
|
+
|
|
1
3
|
const topicHash32 = (topic: string) => {
|
|
2
4
|
let hash = 0x811c9dc5; // FNV-1a
|
|
3
5
|
for (let index = 0; index < topic.length; index++) {
|
|
@@ -24,6 +26,7 @@ export class TopicRootDirectory {
|
|
|
24
26
|
private readonly explicitRootsByTopic = new Map<string, string>();
|
|
25
27
|
private defaultCandidates: string[] = [];
|
|
26
28
|
private resolver?: TopicRootResolver;
|
|
29
|
+
private native?: RustTopicRootDirectoryState;
|
|
27
30
|
|
|
28
31
|
constructor(options?: TopicRootDirectoryOptions) {
|
|
29
32
|
if (options?.defaultCandidates) {
|
|
@@ -32,19 +35,53 @@ export class TopicRootDirectory {
|
|
|
32
35
|
this.resolver = options?.resolver;
|
|
33
36
|
}
|
|
34
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Move the root-resolution state (explicit roots + deterministic
|
|
40
|
+
* candidates) into the native topic-control core. Current contents are
|
|
41
|
+
* copied over; a directory that already adopted native state keeps it
|
|
42
|
+
* (the first adoption owns the state, so directories shared between
|
|
43
|
+
* co-located planes are only migrated once). The resolver callback and
|
|
44
|
+
* trackers stay host-side.
|
|
45
|
+
*/
|
|
46
|
+
public adoptNativeState(state: RustTopicRootDirectoryState) {
|
|
47
|
+
if (this.native) return;
|
|
48
|
+
for (const [topic, root] of this.explicitRootsByTopic) {
|
|
49
|
+
state.setRoot(topic, root);
|
|
50
|
+
}
|
|
51
|
+
state.setDefaultCandidates(this.defaultCandidates);
|
|
52
|
+
this.explicitRootsByTopic.clear();
|
|
53
|
+
this.defaultCandidates = [];
|
|
54
|
+
this.native = state;
|
|
55
|
+
}
|
|
56
|
+
|
|
35
57
|
public setRoot(topic: string, root: string) {
|
|
58
|
+
if (this.native) {
|
|
59
|
+
this.native.setRoot(topic, root);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
36
62
|
this.explicitRootsByTopic.set(topic, root);
|
|
37
63
|
}
|
|
38
64
|
|
|
39
65
|
public deleteRoot(topic: string) {
|
|
66
|
+
if (this.native) {
|
|
67
|
+
this.native.deleteRoot(topic);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
40
70
|
this.explicitRootsByTopic.delete(topic);
|
|
41
71
|
}
|
|
42
72
|
|
|
43
73
|
public getRoot(topic: string) {
|
|
74
|
+
if (this.native) {
|
|
75
|
+
return this.native.getRoot(topic);
|
|
76
|
+
}
|
|
44
77
|
return this.explicitRootsByTopic.get(topic);
|
|
45
78
|
}
|
|
46
79
|
|
|
47
80
|
public setDefaultCandidates(candidates: string[]) {
|
|
81
|
+
if (this.native) {
|
|
82
|
+
this.native.setDefaultCandidates(candidates);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
48
85
|
const unique = new Set<string>();
|
|
49
86
|
for (const candidate of candidates) {
|
|
50
87
|
if (!candidate) continue;
|
|
@@ -56,6 +93,9 @@ export class TopicRootDirectory {
|
|
|
56
93
|
}
|
|
57
94
|
|
|
58
95
|
public getDefaultCandidates() {
|
|
96
|
+
if (this.native) {
|
|
97
|
+
return this.native.getDefaultCandidates();
|
|
98
|
+
}
|
|
59
99
|
return [...this.defaultCandidates];
|
|
60
100
|
}
|
|
61
101
|
|
|
@@ -78,6 +118,9 @@ export class TopicRootDirectory {
|
|
|
78
118
|
}
|
|
79
119
|
|
|
80
120
|
public resolveDeterministicCandidate(topic: string): string | undefined {
|
|
121
|
+
if (this.native) {
|
|
122
|
+
return this.native.resolveDeterministicCandidate(topic);
|
|
123
|
+
}
|
|
81
124
|
if (this.defaultCandidates.length === 0) return undefined;
|
|
82
125
|
const index = topicHash32(topic) % this.defaultCandidates.length;
|
|
83
126
|
return this.defaultCandidates[index];
|
|
@@ -103,6 +146,11 @@ export class TopicRootControlPlane {
|
|
|
103
146
|
this.trackers = options?.trackers ? [...options.trackers] : [];
|
|
104
147
|
}
|
|
105
148
|
|
|
149
|
+
/** See {@link TopicRootDirectory.adoptNativeState}. */
|
|
150
|
+
public adoptNativeDirectoryState(state: RustTopicRootDirectoryState) {
|
|
151
|
+
this.directory.adoptNativeState(state);
|
|
152
|
+
}
|
|
153
|
+
|
|
106
154
|
public setTopicRoot(topic: string, root: string) {
|
|
107
155
|
this.directory.setRoot(topic, root);
|
|
108
156
|
}
|