tool-db 2.5.0 → 2.5.3
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/README.md +82 -1
- package/bundle.js +1 -0
- package/dist/adapters-base/networkAdapter.d.ts +58 -0
- package/dist/adapters-base/networkAdapter.js +216 -0
- package/dist/adapters-base/networkAdapter.js.map +1 -0
- package/dist/adapters-base/storageAdapter.d.ts +11 -0
- package/dist/adapters-base/storageAdapter.js +36 -0
- package/dist/adapters-base/storageAdapter.js.map +1 -0
- package/dist/adapters-base/userAdapter.d.ts +15 -0
- package/dist/adapters-base/userAdapter.js +42 -0
- package/dist/adapters-base/userAdapter.js.map +1 -0
- package/dist/crdt/baseCrdt.d.ts +9 -0
- package/dist/crdt/baseCrdt.js +27 -0
- package/dist/crdt/baseCrdt.js.map +1 -0
- package/dist/crdt/counterCrdt.d.ts +30 -0
- package/dist/crdt/counterCrdt.js +106 -0
- package/dist/crdt/counterCrdt.js.map +1 -0
- package/dist/crdt/listCrdt.d.ts +42 -0
- package/dist/crdt/listCrdt.js +159 -0
- package/dist/crdt/listCrdt.js.map +1 -0
- package/dist/crdt/mapCrdt.d.ts +32 -0
- package/dist/crdt/mapCrdt.js +118 -0
- package/dist/crdt/mapCrdt.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +83 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +29 -0
- package/dist/logger.js.map +1 -0
- package/dist/messageHandlers/handleCrdtGet.d.ts +2 -0
- package/dist/messageHandlers/handleCrdtGet.js +29 -0
- package/dist/messageHandlers/handleCrdtGet.js.map +1 -0
- package/dist/messageHandlers/handleCrdtPut.d.ts +2 -0
- package/dist/messageHandlers/handleCrdtPut.js +93 -0
- package/dist/messageHandlers/handleCrdtPut.js.map +1 -0
- package/dist/messageHandlers/handleGet.d.ts +2 -0
- package/dist/messageHandlers/handleGet.js +29 -0
- package/dist/messageHandlers/handleGet.js.map +1 -0
- package/dist/messageHandlers/handlePing.d.ts +2 -0
- package/dist/messageHandlers/handlePing.js +36 -0
- package/dist/messageHandlers/handlePing.js.map +1 -0
- package/dist/messageHandlers/handlePong.d.ts +2 -0
- package/dist/messageHandlers/handlePong.js +26 -0
- package/dist/messageHandlers/handlePong.js.map +1 -0
- package/dist/messageHandlers/handlePut.d.ts +2 -0
- package/dist/messageHandlers/handlePut.js +57 -0
- package/dist/messageHandlers/handlePut.js.map +1 -0
- package/dist/messageHandlers/handleQuery.d.ts +2 -0
- package/dist/messageHandlers/handleQuery.js +23 -0
- package/dist/messageHandlers/handleQuery.js.map +1 -0
- package/dist/messageHandlers/handleSubscribe.d.ts +2 -0
- package/dist/messageHandlers/handleSubscribe.js +44 -0
- package/dist/messageHandlers/handleSubscribe.js.map +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +9 -0
- package/dist/server.js.map +1 -0
- package/dist/shared.d.ts +2 -0
- package/dist/shared.js +7 -0
- package/dist/shared.js.map +1 -0
- package/dist/toolDbAnonSignIn.d.ts +2 -0
- package/dist/toolDbAnonSignIn.js +7 -0
- package/dist/toolDbAnonSignIn.js.map +1 -0
- package/dist/toolDbClientOnMessage.d.ts +2 -0
- package/dist/toolDbClientOnMessage.js +59 -0
- package/dist/toolDbClientOnMessage.js.map +1 -0
- package/dist/toolDbCrdtGet.d.ts +9 -0
- package/dist/toolDbCrdtGet.js +77 -0
- package/dist/toolDbCrdtGet.js.map +1 -0
- package/dist/toolDbCrdtPut.d.ts +9 -0
- package/dist/toolDbCrdtPut.js +63 -0
- package/dist/toolDbCrdtPut.js.map +1 -0
- package/dist/toolDbGet.d.ts +9 -0
- package/dist/toolDbGet.js +77 -0
- package/dist/toolDbGet.js.map +1 -0
- package/dist/toolDbKeysSignIn.d.ts +2 -0
- package/dist/toolDbKeysSignIn.js +16 -0
- package/dist/toolDbKeysSignIn.js.map +1 -0
- package/dist/toolDbPut.d.ts +9 -0
- package/dist/toolDbPut.js +69 -0
- package/dist/toolDbPut.js.map +1 -0
- package/dist/toolDbQueryKeys.d.ts +8 -0
- package/dist/toolDbQueryKeys.js +66 -0
- package/dist/toolDbQueryKeys.js.map +1 -0
- package/dist/toolDbSignIn.d.ts +2 -0
- package/dist/toolDbSignIn.js +27 -0
- package/dist/toolDbSignIn.js.map +1 -0
- package/dist/toolDbSignUp.d.ts +2 -0
- package/dist/toolDbSignUp.js +101 -0
- package/dist/toolDbSignUp.js.map +1 -0
- package/dist/toolDbSubscribe.d.ts +9 -0
- package/dist/toolDbSubscribe.js +50 -0
- package/dist/toolDbSubscribe.js.map +1 -0
- package/dist/toolDbVerificationWrapper.d.ts +2 -0
- package/dist/toolDbVerificationWrapper.js +98 -0
- package/dist/toolDbVerificationWrapper.js.map +1 -0
- package/dist/tooldb.d.ts +108 -0
- package/dist/tooldb.js +286 -0
- package/dist/tooldb.js.map +1 -0
- package/dist/types/message.d.ts +100 -0
- package/dist/types/message.js +17 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/tooldb.d.ts +84 -0
- package/dist/types/tooldb.js +3 -0
- package/dist/types/tooldb.js.map +1 -0
- package/dist/utils/catchReturn.d.ts +1 -0
- package/dist/utils/catchReturn.js +8 -0
- package/dist/utils/catchReturn.js.map +1 -0
- package/dist/utils/encoding/arrayBufferToHex.d.ts +1 -0
- package/dist/utils/encoding/arrayBufferToHex.js +19 -0
- package/dist/utils/encoding/arrayBufferToHex.js.map +1 -0
- package/dist/utils/encoding/arrayBufferToString.d.ts +1 -0
- package/dist/utils/encoding/arrayBufferToString.js +12 -0
- package/dist/utils/encoding/arrayBufferToString.js.map +1 -0
- package/dist/utils/encoding/hexToArrayBuffer.d.ts +1 -0
- package/dist/utils/encoding/hexToArrayBuffer.js +15 -0
- package/dist/utils/encoding/hexToArrayBuffer.js.map +1 -0
- package/dist/utils/encoding/hexToString.d.ts +1 -0
- package/dist/utils/encoding/hexToString.js +12 -0
- package/dist/utils/encoding/hexToString.js.map +1 -0
- package/dist/utils/encoding/hexToUint8.d.ts +1 -0
- package/dist/utils/encoding/hexToUint8.js +8 -0
- package/dist/utils/encoding/hexToUint8.js.map +1 -0
- package/dist/utils/encoding/stringToArrayBuffer.d.ts +1 -0
- package/dist/utils/encoding/stringToArrayBuffer.js +12 -0
- package/dist/utils/encoding/stringToArrayBuffer.js.map +1 -0
- package/dist/utils/getPeerSignature.d.ts +2 -0
- package/dist/utils/getPeerSignature.js +9 -0
- package/dist/utils/getPeerSignature.js.map +1 -0
- package/dist/utils/getTimestamp.d.ts +1 -0
- package/dist/utils/getTimestamp.js +7 -0
- package/dist/utils/getTimestamp.js.map +1 -0
- package/dist/utils/proofOfWork.d.ts +4 -0
- package/dist/utils/proofOfWork.js +16 -0
- package/dist/utils/proofOfWork.js.map +1 -0
- package/dist/utils/randomAnimal.d.ts +1 -0
- package/dist/utils/randomAnimal.js +77 -0
- package/dist/utils/randomAnimal.js.map +1 -0
- package/dist/utils/sha1.d.ts +1 -0
- package/dist/utils/sha1.js +13 -0
- package/dist/utils/sha1.js.map +1 -0
- package/dist/utils/sha256.d.ts +3 -0
- package/dist/utils/sha256.js +13 -0
- package/dist/utils/sha256.js.map +1 -0
- package/dist/utils/textRandom.d.ts +1 -0
- package/dist/utils/textRandom.js +15 -0
- package/dist/utils/textRandom.js.map +1 -0
- package/dist/utils/uniq.d.ts +1 -0
- package/dist/utils/uniq.js +7 -0
- package/dist/utils/uniq.js.map +1 -0
- package/dist/utils/verifyMessage.d.ts +8 -0
- package/dist/utils/verifyMessage.js +129 -0
- package/dist/utils/verifyMessage.js.map +1 -0
- package/dist/utils/verifyPeer.d.ts +2 -0
- package/dist/utils/verifyPeer.js +15 -0
- package/dist/utils/verifyPeer.js.map +1 -0
- package/lib/adapters-base/networkAdapter.ts +217 -215
- package/lib/adapters-base/storageAdapter.ts +35 -35
- package/lib/adapters-base/userAdapter.ts +49 -49
- package/lib/crdt/baseCrdt.ts +21 -21
- package/lib/crdt/counterCrdt.ts +111 -111
- package/lib/crdt/listCrdt.ts +190 -190
- package/lib/crdt/mapCrdt.ts +119 -119
- package/lib/index.ts +42 -42
- package/lib/logger.ts +30 -30
- package/lib/messageHandlers/handleCrdtGet.ts +29 -29
- package/lib/messageHandlers/handleCrdtPut.ts +118 -118
- package/lib/messageHandlers/handleGet.ts +29 -29
- package/lib/messageHandlers/handlePing.ts +40 -40
- package/lib/messageHandlers/handlePong.ts +30 -30
- package/lib/messageHandlers/handlePut.ts +54 -54
- package/lib/messageHandlers/handleQuery.ts +25 -25
- package/lib/messageHandlers/handleSubscribe.ts +46 -46
- package/lib/server.ts +7 -7
- package/lib/shared.ts +5 -5
- package/lib/toolDbAnonSignIn.ts +5 -5
- package/lib/toolDbClientOnMessage.ts +75 -75
- package/lib/toolDbCrdtGet.ts +82 -82
- package/lib/toolDbCrdtPut.ts +77 -77
- package/lib/toolDbGet.ts +80 -80
- package/lib/toolDbKeysSignIn.ts +16 -16
- package/lib/toolDbPut.ts +83 -83
- package/lib/toolDbQueryKeys.ts +64 -64
- package/lib/toolDbSignIn.ts +31 -31
- package/lib/toolDbSignUp.ts +71 -71
- package/lib/toolDbSubscribe.ts +53 -53
- package/lib/toolDbVerificationWrapper.ts +55 -55
- package/lib/tooldb.ts +316 -314
- package/lib/types/message.ts +133 -133
- package/lib/types/tooldb.ts +97 -89
- package/lib/utils/catchReturn.ts +4 -4
- package/lib/utils/encoding/arrayBufferToHex.ts +18 -18
- package/lib/utils/encoding/arrayBufferToString.ts +8 -8
- package/lib/utils/encoding/hexToArrayBuffer.ts +13 -13
- package/lib/utils/encoding/hexToString.ts +8 -8
- package/lib/utils/encoding/hexToUint8.ts +5 -5
- package/lib/utils/encoding/stringToArrayBuffer.ts +8 -8
- package/lib/utils/getPeerSignature.ts +12 -12
- package/lib/utils/getTimestamp.ts +3 -3
- package/lib/utils/proofOfWork.ts +16 -16
- package/lib/utils/randomAnimal.ts +77 -77
- package/lib/utils/sha1.ts +7 -7
- package/lib/utils/sha256.ts +7 -7
- package/lib/utils/textRandom.ts +11 -11
- package/lib/utils/uniq.ts +3 -3
- package/lib/utils/verifyMessage.ts +88 -88
- package/lib/utils/verifyPeer.ts +15 -15
- package/package.json +4 -3
- package/tsconfig.json +14 -14
package/lib/crdt/mapCrdt.ts
CHANGED
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
import { BaseCrdt, CRDT_MAP } from "..";
|
|
2
|
-
|
|
3
|
-
export type MapOperations = "SET" | "DEL";
|
|
4
|
-
|
|
5
|
-
export interface ChangeMapBase<T> {
|
|
6
|
-
t: MapOperations;
|
|
7
|
-
a: string;
|
|
8
|
-
k: string;
|
|
9
|
-
i: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface SetMapChange<T> extends ChangeMapBase<T> {
|
|
13
|
-
t: "SET";
|
|
14
|
-
v: T;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface DelMapChange<T> extends ChangeMapBase<T> {
|
|
18
|
-
t: "DEL";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type MapChanges<T> = SetMapChange<T> | DelMapChange<T>;
|
|
22
|
-
|
|
23
|
-
export class MapCrdt<T> extends BaseCrdt<T, MapChanges<T>, Record<string, T>> {
|
|
24
|
-
public type = CRDT_MAP;
|
|
25
|
-
|
|
26
|
-
private _changes: MapChanges<T>[] = [];
|
|
27
|
-
|
|
28
|
-
private _author = "";
|
|
29
|
-
|
|
30
|
-
private _value: Record<string, T> = {};
|
|
31
|
-
|
|
32
|
-
private _keyIndex: Record<string, number> = {};
|
|
33
|
-
|
|
34
|
-
private _lastUpdateSize: number = 0;
|
|
35
|
-
|
|
36
|
-
constructor(author: string, changes?: MapChanges<T>[]) {
|
|
37
|
-
super();
|
|
38
|
-
this._author = author;
|
|
39
|
-
if (changes) {
|
|
40
|
-
this.mergeChanges(changes);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
this.calculate();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
changesSort(a: MapChanges<T>, b: MapChanges<T>) {
|
|
47
|
-
if (a.i < b.i) return -1;
|
|
48
|
-
if (a.i > b.i) return 1;
|
|
49
|
-
if (a.t === "SET" && b.t === "DEL") return -1;
|
|
50
|
-
if (a.t === "DEL" && b.t === "SET") return 1;
|
|
51
|
-
if (a.a < b.a) return -1;
|
|
52
|
-
if (a.a > b.a) return 1;
|
|
53
|
-
return 0; // Should never be equal!
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
calculate() {
|
|
57
|
-
const temp: Record<string, T> = {};
|
|
58
|
-
// Only update if we have new changes
|
|
59
|
-
if (Object.values(this._changes).length !== this._lastUpdateSize) {
|
|
60
|
-
this._changes.sort(this.changesSort).forEach((change) => {
|
|
61
|
-
// Here we apply the model properties
|
|
62
|
-
// Since this is a KV store we dont need much logic,
|
|
63
|
-
// except for the sorting of the changes. Then we just apply them.
|
|
64
|
-
if (change.t === "SET") {
|
|
65
|
-
temp[change.k] = change.v;
|
|
66
|
-
} else if (change.t === "DEL") {
|
|
67
|
-
delete temp[change.k];
|
|
68
|
-
}
|
|
69
|
-
this._keyIndex[change.k] = change.i;
|
|
70
|
-
});
|
|
71
|
-
this._lastUpdateSize = Object.values(temp).length;
|
|
72
|
-
this._value = temp;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
get value(): Record<string, T> {
|
|
77
|
-
this.calculate();
|
|
78
|
-
return this._value;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public mergeChanges(newChanges: MapChanges<T>[]) {
|
|
82
|
-
newChanges.forEach((change) => {
|
|
83
|
-
// Filter by author and index
|
|
84
|
-
const filtered = this._changes.filter(
|
|
85
|
-
(c) => c.i === change.i && c.a === change.a && c.t === change.t
|
|
86
|
-
);
|
|
87
|
-
// Only add if there are not matches
|
|
88
|
-
if (filtered.length === 0) {
|
|
89
|
-
this._changes.push(change);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
this.calculate();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public getChanges(): MapChanges<T>[] {
|
|
96
|
-
return this._changes;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public SET(key: string, value: T) {
|
|
100
|
-
this._keyIndex[key] = (this._keyIndex[key] || 0) + 1;
|
|
101
|
-
this._changes.push({
|
|
102
|
-
t: "SET",
|
|
103
|
-
k: key,
|
|
104
|
-
a: this._author,
|
|
105
|
-
v: value,
|
|
106
|
-
i: this._keyIndex[key],
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
public DEL(key: string) {
|
|
111
|
-
this._keyIndex[key] = (this._keyIndex[key] || 0) + 1;
|
|
112
|
-
this._changes.push({
|
|
113
|
-
t: "DEL",
|
|
114
|
-
k: key,
|
|
115
|
-
a: this._author,
|
|
116
|
-
i: this._keyIndex[key],
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
1
|
+
import { BaseCrdt, CRDT_MAP } from "..";
|
|
2
|
+
|
|
3
|
+
export type MapOperations = "SET" | "DEL";
|
|
4
|
+
|
|
5
|
+
export interface ChangeMapBase<T> {
|
|
6
|
+
t: MapOperations;
|
|
7
|
+
a: string;
|
|
8
|
+
k: string;
|
|
9
|
+
i: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SetMapChange<T> extends ChangeMapBase<T> {
|
|
13
|
+
t: "SET";
|
|
14
|
+
v: T;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface DelMapChange<T> extends ChangeMapBase<T> {
|
|
18
|
+
t: "DEL";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type MapChanges<T> = SetMapChange<T> | DelMapChange<T>;
|
|
22
|
+
|
|
23
|
+
export class MapCrdt<T> extends BaseCrdt<T, MapChanges<T>, Record<string, T>> {
|
|
24
|
+
public type = CRDT_MAP;
|
|
25
|
+
|
|
26
|
+
private _changes: MapChanges<T>[] = [];
|
|
27
|
+
|
|
28
|
+
private _author = "";
|
|
29
|
+
|
|
30
|
+
private _value: Record<string, T> = {};
|
|
31
|
+
|
|
32
|
+
private _keyIndex: Record<string, number> = {};
|
|
33
|
+
|
|
34
|
+
private _lastUpdateSize: number = 0;
|
|
35
|
+
|
|
36
|
+
constructor(author: string, changes?: MapChanges<T>[]) {
|
|
37
|
+
super();
|
|
38
|
+
this._author = author;
|
|
39
|
+
if (changes) {
|
|
40
|
+
this.mergeChanges(changes);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.calculate();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
changesSort(a: MapChanges<T>, b: MapChanges<T>) {
|
|
47
|
+
if (a.i < b.i) return -1;
|
|
48
|
+
if (a.i > b.i) return 1;
|
|
49
|
+
if (a.t === "SET" && b.t === "DEL") return -1;
|
|
50
|
+
if (a.t === "DEL" && b.t === "SET") return 1;
|
|
51
|
+
if (a.a < b.a) return -1;
|
|
52
|
+
if (a.a > b.a) return 1;
|
|
53
|
+
return 0; // Should never be equal!
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
calculate() {
|
|
57
|
+
const temp: Record<string, T> = {};
|
|
58
|
+
// Only update if we have new changes
|
|
59
|
+
if (Object.values(this._changes).length !== this._lastUpdateSize) {
|
|
60
|
+
this._changes.sort(this.changesSort).forEach((change) => {
|
|
61
|
+
// Here we apply the model properties
|
|
62
|
+
// Since this is a KV store we dont need much logic,
|
|
63
|
+
// except for the sorting of the changes. Then we just apply them.
|
|
64
|
+
if (change.t === "SET") {
|
|
65
|
+
temp[change.k] = change.v;
|
|
66
|
+
} else if (change.t === "DEL") {
|
|
67
|
+
delete temp[change.k];
|
|
68
|
+
}
|
|
69
|
+
this._keyIndex[change.k] = change.i;
|
|
70
|
+
});
|
|
71
|
+
this._lastUpdateSize = Object.values(temp).length;
|
|
72
|
+
this._value = temp;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get value(): Record<string, T> {
|
|
77
|
+
this.calculate();
|
|
78
|
+
return this._value;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public mergeChanges(newChanges: MapChanges<T>[]) {
|
|
82
|
+
newChanges.forEach((change) => {
|
|
83
|
+
// Filter by author and index
|
|
84
|
+
const filtered = this._changes.filter(
|
|
85
|
+
(c) => c.i === change.i && c.a === change.a && c.t === change.t
|
|
86
|
+
);
|
|
87
|
+
// Only add if there are not matches
|
|
88
|
+
if (filtered.length === 0) {
|
|
89
|
+
this._changes.push(change);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
this.calculate();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public getChanges(): MapChanges<T>[] {
|
|
96
|
+
return this._changes;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public SET(key: string, value: T) {
|
|
100
|
+
this._keyIndex[key] = (this._keyIndex[key] || 0) + 1;
|
|
101
|
+
this._changes.push({
|
|
102
|
+
t: "SET",
|
|
103
|
+
k: key,
|
|
104
|
+
a: this._author,
|
|
105
|
+
v: value,
|
|
106
|
+
i: this._keyIndex[key],
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public DEL(key: string) {
|
|
111
|
+
this._keyIndex[key] = (this._keyIndex[key] || 0) + 1;
|
|
112
|
+
this._changes.push({
|
|
113
|
+
t: "DEL",
|
|
114
|
+
k: key,
|
|
115
|
+
a: this._author,
|
|
116
|
+
i: this._keyIndex[key],
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
package/lib/index.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
export { default as proofOfWork } from "./utils/proofOfWork";
|
|
2
|
-
export { default as sha1 } from "./utils/sha1";
|
|
3
|
-
export { default as sha256 } from "./utils/sha256";
|
|
4
|
-
export { default as uniq } from "./utils/uniq";
|
|
5
|
-
|
|
6
|
-
export { default as randomAnimal } from "./utils/randomAnimal";
|
|
7
|
-
export { default as verifyMessage } from "./utils/verifyMessage";
|
|
8
|
-
export { default as getPeerSignature } from "./utils/getPeerSignature";
|
|
9
|
-
export { default as verifyPeer } from "./utils/verifyPeer";
|
|
10
|
-
export { default as textRandom } from "./utils/textRandom";
|
|
11
|
-
|
|
12
|
-
export { default as catchReturn } from "./utils/catchReturn";
|
|
13
|
-
|
|
14
|
-
export { default as stringToArrayBuffer } from "./utils/encoding/stringToArrayBuffer";
|
|
15
|
-
export { default as arrayBufferToString } from "./utils/encoding/arrayBufferToString";
|
|
16
|
-
|
|
17
|
-
export { default as arrayBufferToHex } from "./utils/encoding/arrayBufferToHex";
|
|
18
|
-
export { default as hexToArrayBuffer } from "./utils/encoding/hexToArrayBuffer";
|
|
19
|
-
export { default as hexToString } from "./utils/encoding/hexToString";
|
|
20
|
-
export { default as hexToUint8 } from "./utils/encoding/hexToUint8";
|
|
21
|
-
|
|
22
|
-
export { default as ToolDbNetworkAdapter } from "./adapters-base/networkAdapter";
|
|
23
|
-
export { default as ToolDbStorageAdapter } from "./adapters-base/storageAdapter";
|
|
24
|
-
export { default as ToolDbUserAdapter } from "./adapters-base/userAdapter";
|
|
25
|
-
|
|
26
|
-
export * from "./types/tooldb";
|
|
27
|
-
export * from "./types/message";
|
|
28
|
-
export * from "./crdt/baseCrdt";
|
|
29
|
-
export * from "./crdt/counterCrdt";
|
|
30
|
-
export * from "./crdt/listCrdt";
|
|
31
|
-
export * from "./crdt/mapCrdt";
|
|
32
|
-
|
|
33
|
-
export { default as handleSubscribe } from "./messageHandlers/handleSubscribe";
|
|
34
|
-
export { default as handleCrdtGet } from "./messageHandlers/handleCrdtGet";
|
|
35
|
-
export { default as handleCrdtPut } from "./messageHandlers/handleCrdtPut";
|
|
36
|
-
export { default as handleQuery } from "./messageHandlers/handleQuery";
|
|
37
|
-
export { default as handlePing } from "./messageHandlers/handlePing";
|
|
38
|
-
export { default as handlePong } from "./messageHandlers/handlePong";
|
|
39
|
-
export { default as handleGet } from "./messageHandlers/handleGet";
|
|
40
|
-
export { default as handlePut } from "./messageHandlers/handlePut";
|
|
41
|
-
|
|
42
|
-
export { default as ToolDb } from "./tooldb";
|
|
1
|
+
export { default as proofOfWork } from "./utils/proofOfWork";
|
|
2
|
+
export { default as sha1 } from "./utils/sha1";
|
|
3
|
+
export { default as sha256 } from "./utils/sha256";
|
|
4
|
+
export { default as uniq } from "./utils/uniq";
|
|
5
|
+
|
|
6
|
+
export { default as randomAnimal } from "./utils/randomAnimal";
|
|
7
|
+
export { default as verifyMessage } from "./utils/verifyMessage";
|
|
8
|
+
export { default as getPeerSignature } from "./utils/getPeerSignature";
|
|
9
|
+
export { default as verifyPeer } from "./utils/verifyPeer";
|
|
10
|
+
export { default as textRandom } from "./utils/textRandom";
|
|
11
|
+
|
|
12
|
+
export { default as catchReturn } from "./utils/catchReturn";
|
|
13
|
+
|
|
14
|
+
export { default as stringToArrayBuffer } from "./utils/encoding/stringToArrayBuffer";
|
|
15
|
+
export { default as arrayBufferToString } from "./utils/encoding/arrayBufferToString";
|
|
16
|
+
|
|
17
|
+
export { default as arrayBufferToHex } from "./utils/encoding/arrayBufferToHex";
|
|
18
|
+
export { default as hexToArrayBuffer } from "./utils/encoding/hexToArrayBuffer";
|
|
19
|
+
export { default as hexToString } from "./utils/encoding/hexToString";
|
|
20
|
+
export { default as hexToUint8 } from "./utils/encoding/hexToUint8";
|
|
21
|
+
|
|
22
|
+
export { default as ToolDbNetworkAdapter } from "./adapters-base/networkAdapter";
|
|
23
|
+
export { default as ToolDbStorageAdapter } from "./adapters-base/storageAdapter";
|
|
24
|
+
export { default as ToolDbUserAdapter } from "./adapters-base/userAdapter";
|
|
25
|
+
|
|
26
|
+
export * from "./types/tooldb";
|
|
27
|
+
export * from "./types/message";
|
|
28
|
+
export * from "./crdt/baseCrdt";
|
|
29
|
+
export * from "./crdt/counterCrdt";
|
|
30
|
+
export * from "./crdt/listCrdt";
|
|
31
|
+
export * from "./crdt/mapCrdt";
|
|
32
|
+
|
|
33
|
+
export { default as handleSubscribe } from "./messageHandlers/handleSubscribe";
|
|
34
|
+
export { default as handleCrdtGet } from "./messageHandlers/handleCrdtGet";
|
|
35
|
+
export { default as handleCrdtPut } from "./messageHandlers/handleCrdtPut";
|
|
36
|
+
export { default as handleQuery } from "./messageHandlers/handleQuery";
|
|
37
|
+
export { default as handlePing } from "./messageHandlers/handlePing";
|
|
38
|
+
export { default as handlePong } from "./messageHandlers/handlePong";
|
|
39
|
+
export { default as handleGet } from "./messageHandlers/handleGet";
|
|
40
|
+
export { default as handlePut } from "./messageHandlers/handlePut";
|
|
41
|
+
|
|
42
|
+
export { default as ToolDb } from "./tooldb";
|
package/lib/logger.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { ToolDb, sha1 } from ".";
|
|
2
|
-
|
|
3
|
-
export default function logger(
|
|
4
|
-
this: ToolDb,
|
|
5
|
-
arg0: any,
|
|
6
|
-
arg1?: any,
|
|
7
|
-
arg2?: any,
|
|
8
|
-
arg3?: any,
|
|
9
|
-
arg4?: any,
|
|
10
|
-
arg5?: any
|
|
11
|
-
) {
|
|
12
|
-
if (this.options.debug) {
|
|
13
|
-
const isNode = typeof window === "undefined";
|
|
14
|
-
const title = isNode
|
|
15
|
-
? this.options.storageName
|
|
16
|
-
: "%c" + this.options.storageName;
|
|
17
|
-
|
|
18
|
-
const style = isNode
|
|
19
|
-
? ""
|
|
20
|
-
: "background: #" +
|
|
21
|
-
sha1(this.options.storageName).slice(-6) +
|
|
22
|
-
"; padding: 2px; color: black";
|
|
23
|
-
|
|
24
|
-
console.log(
|
|
25
|
-
title,
|
|
26
|
-
style,
|
|
27
|
-
...[arg0, arg1, arg2, arg3, arg4, arg4, arg5].slice(0, arguments.length)
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
import { ToolDb, sha1 } from ".";
|
|
2
|
+
|
|
3
|
+
export default function logger(
|
|
4
|
+
this: ToolDb,
|
|
5
|
+
arg0: any,
|
|
6
|
+
arg1?: any,
|
|
7
|
+
arg2?: any,
|
|
8
|
+
arg3?: any,
|
|
9
|
+
arg4?: any,
|
|
10
|
+
arg5?: any
|
|
11
|
+
) {
|
|
12
|
+
if (this.options.debug) {
|
|
13
|
+
const isNode = typeof window === "undefined";
|
|
14
|
+
const title = isNode
|
|
15
|
+
? this.options.storageName
|
|
16
|
+
: "%c" + this.options.storageName;
|
|
17
|
+
|
|
18
|
+
const style = isNode
|
|
19
|
+
? ""
|
|
20
|
+
: "background: #" +
|
|
21
|
+
sha1(this.options.storageName).slice(-6) +
|
|
22
|
+
"; padding: 2px; color: black";
|
|
23
|
+
|
|
24
|
+
console.log(
|
|
25
|
+
title,
|
|
26
|
+
style,
|
|
27
|
+
...[arg0, arg1, arg2, arg3, arg4, arg4, arg5].slice(0, arguments.length)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { ToolDb, CrdtGetMessage, CrdtPutMessage } from "..";
|
|
2
|
-
|
|
3
|
-
export default function handleCrdtGet(
|
|
4
|
-
this: ToolDb,
|
|
5
|
-
message: CrdtGetMessage,
|
|
6
|
-
remotePeerId: string
|
|
7
|
-
) {
|
|
8
|
-
this.store
|
|
9
|
-
.get(message.key)
|
|
10
|
-
.then((data) => {
|
|
11
|
-
try {
|
|
12
|
-
// Use the id of the get so the other client knows we are replying
|
|
13
|
-
const oldData = {
|
|
14
|
-
type: "crdtPut",
|
|
15
|
-
data: JSON.parse(data),
|
|
16
|
-
to: [],
|
|
17
|
-
id: message.id,
|
|
18
|
-
} as CrdtPutMessage;
|
|
19
|
-
this.network.sendToClientId(remotePeerId, oldData);
|
|
20
|
-
} catch (e) {
|
|
21
|
-
// socket.send(data);
|
|
22
|
-
// do nothing
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
.catch((e) => {
|
|
26
|
-
this.logger("Local key not found, relay", JSON.stringify(message));
|
|
27
|
-
this.network.sendToAll(message, false);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
1
|
+
import { ToolDb, CrdtGetMessage, CrdtPutMessage } from "..";
|
|
2
|
+
|
|
3
|
+
export default function handleCrdtGet(
|
|
4
|
+
this: ToolDb,
|
|
5
|
+
message: CrdtGetMessage,
|
|
6
|
+
remotePeerId: string
|
|
7
|
+
) {
|
|
8
|
+
this.store
|
|
9
|
+
.get(message.key)
|
|
10
|
+
.then((data) => {
|
|
11
|
+
try {
|
|
12
|
+
// Use the id of the get so the other client knows we are replying
|
|
13
|
+
const oldData = {
|
|
14
|
+
type: "crdtPut",
|
|
15
|
+
data: JSON.parse(data),
|
|
16
|
+
to: [],
|
|
17
|
+
id: message.id,
|
|
18
|
+
} as CrdtPutMessage;
|
|
19
|
+
this.network.sendToClientId(remotePeerId, oldData);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
// socket.send(data);
|
|
22
|
+
// do nothing
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
.catch((e) => {
|
|
26
|
+
this.logger("Local key not found, relay", JSON.stringify(message));
|
|
27
|
+
this.network.sendToAll(message, false);
|
|
28
|
+
});
|
|
29
|
+
}
|