tool-db 2.5.3 → 2.5.4
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 -82
- package/bundle.js +1 -1
- package/dist/adapters-base/networkAdapter.d.ts +58 -58
- package/dist/adapters-base/networkAdapter.js +215 -215
- package/dist/adapters-base/storageAdapter.d.ts +11 -11
- package/dist/adapters-base/storageAdapter.js +35 -35
- package/dist/adapters-base/userAdapter.d.ts +15 -15
- package/dist/adapters-base/userAdapter.js +41 -41
- package/dist/crdt/baseCrdt.d.ts +9 -9
- package/dist/crdt/baseCrdt.js +26 -26
- package/dist/crdt/counterCrdt.d.ts +30 -30
- package/dist/crdt/counterCrdt.js +105 -105
- package/dist/crdt/listCrdt.d.ts +42 -42
- package/dist/crdt/listCrdt.js +158 -158
- package/dist/crdt/mapCrdt.d.ts +32 -32
- package/dist/crdt/mapCrdt.js +117 -117
- package/dist/index.d.ts +34 -34
- package/dist/index.js +82 -82
- package/dist/logger.d.ts +2 -2
- package/dist/logger.js +28 -28
- package/dist/messageHandlers/handleCrdtGet.d.ts +2 -2
- package/dist/messageHandlers/handleCrdtGet.js +49 -28
- package/dist/messageHandlers/handleCrdtGet.js.map +1 -1
- package/dist/messageHandlers/handleCrdtPut.d.ts +2 -2
- package/dist/messageHandlers/handleCrdtPut.js +102 -92
- package/dist/messageHandlers/handleCrdtPut.js.map +1 -1
- package/dist/messageHandlers/handleGet.d.ts +2 -2
- package/dist/messageHandlers/handleGet.js +49 -28
- package/dist/messageHandlers/handleGet.js.map +1 -1
- package/dist/messageHandlers/handlePing.d.ts +2 -2
- package/dist/messageHandlers/handlePing.js +35 -35
- package/dist/messageHandlers/handlePing.js.map +1 -1
- package/dist/messageHandlers/handlePong.d.ts +2 -2
- package/dist/messageHandlers/handlePong.js +25 -25
- package/dist/messageHandlers/handlePut.d.ts +2 -2
- package/dist/messageHandlers/handlePut.js +77 -56
- package/dist/messageHandlers/handlePut.js.map +1 -1
- package/dist/messageHandlers/handleQuery.d.ts +2 -2
- package/dist/messageHandlers/handleQuery.js +43 -22
- package/dist/messageHandlers/handleQuery.js.map +1 -1
- package/dist/messageHandlers/handleSubscribe.d.ts +2 -2
- package/dist/messageHandlers/handleSubscribe.js +43 -43
- package/dist/server.d.ts +1 -1
- package/dist/server.js +8 -8
- package/dist/shared.d.ts +2 -2
- package/dist/shared.js +6 -6
- package/dist/toolDbAnonSignIn.d.ts +2 -2
- package/dist/toolDbAnonSignIn.js +6 -6
- package/dist/toolDbClientOnMessage.d.ts +2 -2
- package/dist/toolDbClientOnMessage.js +58 -58
- package/dist/toolDbCrdtGet.d.ts +9 -9
- package/dist/toolDbCrdtGet.js +76 -76
- package/dist/toolDbCrdtGet.js.map +1 -1
- package/dist/toolDbCrdtPut.d.ts +9 -9
- package/dist/toolDbCrdtPut.js +62 -62
- package/dist/toolDbCrdtPut.js.map +1 -1
- package/dist/toolDbGet.d.ts +9 -9
- package/dist/toolDbGet.js +76 -76
- package/dist/toolDbGet.js.map +1 -1
- package/dist/toolDbKeysSignIn.d.ts +2 -2
- package/dist/toolDbKeysSignIn.js +15 -15
- package/dist/toolDbPut.d.ts +9 -9
- package/dist/toolDbPut.js +68 -68
- package/dist/toolDbPut.js.map +1 -1
- package/dist/toolDbQueryKeys.d.ts +8 -8
- package/dist/toolDbQueryKeys.js +65 -65
- package/dist/toolDbQueryKeys.js.map +1 -1
- package/dist/toolDbSignIn.d.ts +2 -2
- package/dist/toolDbSignIn.js +26 -26
- package/dist/toolDbSignIn.js.map +1 -1
- package/dist/toolDbSignUp.d.ts +2 -2
- package/dist/toolDbSignUp.js +100 -100
- package/dist/toolDbSignUp.js.map +1 -1
- package/dist/toolDbSubscribe.d.ts +9 -9
- package/dist/toolDbSubscribe.js +49 -49
- package/dist/toolDbSubscribe.js.map +1 -1
- package/dist/toolDbVerificationWrapper.d.ts +2 -2
- package/dist/toolDbVerificationWrapper.js +97 -97
- package/dist/tooldb.d.ts +108 -108
- package/dist/tooldb.js +285 -285
- package/dist/types/message.d.ts +100 -100
- package/dist/types/message.js +16 -16
- package/dist/types/tooldb.d.ts +84 -84
- package/dist/types/tooldb.js +2 -2
- package/dist/utils/catchReturn.d.ts +1 -1
- package/dist/utils/catchReturn.js +7 -7
- package/dist/utils/encoding/arrayBufferToHex.d.ts +1 -1
- package/dist/utils/encoding/arrayBufferToHex.js +18 -18
- package/dist/utils/encoding/arrayBufferToString.d.ts +1 -1
- package/dist/utils/encoding/arrayBufferToString.js +11 -11
- package/dist/utils/encoding/hexToArrayBuffer.d.ts +1 -1
- package/dist/utils/encoding/hexToArrayBuffer.js +14 -14
- package/dist/utils/encoding/hexToString.d.ts +1 -1
- package/dist/utils/encoding/hexToString.js +11 -11
- package/dist/utils/encoding/hexToUint8.d.ts +1 -1
- package/dist/utils/encoding/hexToUint8.js +7 -7
- package/dist/utils/encoding/stringToArrayBuffer.d.ts +1 -1
- package/dist/utils/encoding/stringToArrayBuffer.js +11 -11
- package/dist/utils/getPeerSignature.d.ts +2 -2
- package/dist/utils/getPeerSignature.js +8 -8
- package/dist/utils/getTimestamp.d.ts +1 -1
- package/dist/utils/getTimestamp.js +6 -6
- package/dist/utils/proofOfWork.d.ts +4 -4
- package/dist/utils/proofOfWork.js +15 -15
- package/dist/utils/randomAnimal.d.ts +1 -1
- package/dist/utils/randomAnimal.js +76 -76
- package/dist/utils/sha1.d.ts +1 -1
- package/dist/utils/sha1.js +12 -12
- package/dist/utils/sha256.d.ts +3 -3
- package/dist/utils/sha256.js +12 -12
- package/dist/utils/textRandom.d.ts +1 -1
- package/dist/utils/textRandom.js +14 -14
- package/dist/utils/uniq.d.ts +1 -1
- package/dist/utils/uniq.js +6 -6
- package/dist/utils/verifyMessage.d.ts +8 -8
- package/dist/utils/verifyMessage.js +128 -128
- package/dist/utils/verifyPeer.d.ts +2 -2
- package/dist/utils/verifyPeer.js +14 -14
- package/lib/adapters-base/networkAdapter.ts +217 -217
- 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 +34 -29
- package/lib/messageHandlers/handleCrdtPut.ts +123 -118
- package/lib/messageHandlers/handleGet.ts +34 -29
- package/lib/messageHandlers/handlePing.ts +40 -40
- package/lib/messageHandlers/handlePong.ts +30 -30
- package/lib/messageHandlers/handlePut.ts +59 -54
- package/lib/messageHandlers/handleQuery.ts +30 -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 +83 -82
- package/lib/toolDbCrdtPut.ts +78 -77
- package/lib/toolDbGet.ts +81 -80
- package/lib/toolDbKeysSignIn.ts +16 -16
- package/lib/toolDbPut.ts +84 -83
- package/lib/toolDbQueryKeys.ts +65 -64
- package/lib/toolDbSignIn.ts +32 -31
- package/lib/toolDbSignUp.ts +72 -71
- package/lib/toolDbSubscribe.ts +54 -53
- package/lib/toolDbVerificationWrapper.ts +55 -55
- package/lib/tooldb.ts +316 -316
- package/lib/types/message.ts +133 -133
- package/lib/types/tooldb.ts +97 -97
- 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 +2 -2
- package/tsconfig.json +14 -14
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ToolDb } from ".";
|
|
2
|
-
export default function toolDbAnonSignIn(this: ToolDb): void;
|
|
1
|
+
import { ToolDb } from ".";
|
|
2
|
+
export default function toolDbAnonSignIn(this: ToolDb): void;
|
package/dist/toolDbAnonSignIn.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function toolDbAnonSignIn() {
|
|
4
|
-
this.userAccount.anonUser();
|
|
5
|
-
}
|
|
6
|
-
exports.default = toolDbAnonSignIn;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function toolDbAnonSignIn() {
|
|
4
|
+
this.userAccount.anonUser();
|
|
5
|
+
}
|
|
6
|
+
exports.default = toolDbAnonSignIn;
|
|
7
7
|
//# sourceMappingURL=toolDbAnonSignIn.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ToolDb, ToolDbMessage } from ".";
|
|
2
|
-
export default function toolDbClientOnMessage(this: ToolDb, message: ToolDbMessage, remotePeerId: string): void;
|
|
1
|
+
import { ToolDb, ToolDbMessage } from ".";
|
|
2
|
+
export default function toolDbClientOnMessage(this: ToolDb, message: ToolDbMessage, remotePeerId: string): void;
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function toolDbClientOnMessage(message, remotePeerId) {
|
|
4
|
-
if (!this.processedIds[message.type]) {
|
|
5
|
-
this.processedIds[message.type] = [];
|
|
6
|
-
}
|
|
7
|
-
if (this.processedIds[message.type].includes(message.id)) {
|
|
8
|
-
// this.logger(
|
|
9
|
-
// `Already processed this message > ${message.type} from ${remotePeerId}`
|
|
10
|
-
// );
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
this.emit("message", message, remotePeerId);
|
|
14
|
-
this.processedIds[message.type].push(message.id);
|
|
15
|
-
this.logger("Got message ".concat(message.type, " from ").concat(remotePeerId));
|
|
16
|
-
this.logger(message);
|
|
17
|
-
// Check if we are listening for this ID
|
|
18
|
-
if (message.id) {
|
|
19
|
-
var msgId = message.id;
|
|
20
|
-
if (this._idListeners[msgId]) {
|
|
21
|
-
this._idListeners[msgId](message);
|
|
22
|
-
this.removeIdListener(msgId);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (message === undefined || message.type === undefined) {
|
|
26
|
-
this.logger("Message is invalid!", message, typeof message);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
switch (message.type) {
|
|
30
|
-
case "ping":
|
|
31
|
-
this.handlePing(message, remotePeerId);
|
|
32
|
-
break;
|
|
33
|
-
case "pong":
|
|
34
|
-
this.handlePong(message, remotePeerId);
|
|
35
|
-
break;
|
|
36
|
-
case "subscribe":
|
|
37
|
-
this.handleSubscribe(message, remotePeerId);
|
|
38
|
-
break;
|
|
39
|
-
case "get":
|
|
40
|
-
this.handleGet(message, remotePeerId);
|
|
41
|
-
break;
|
|
42
|
-
case "put":
|
|
43
|
-
this.handlePut(message, remotePeerId);
|
|
44
|
-
break;
|
|
45
|
-
case "crdtPut":
|
|
46
|
-
this.handleCrdtPut(message, remotePeerId);
|
|
47
|
-
break;
|
|
48
|
-
case "crdtGet":
|
|
49
|
-
this.handleCrdtGet(message, remotePeerId);
|
|
50
|
-
break;
|
|
51
|
-
case "query":
|
|
52
|
-
this.handleQuery(message, remotePeerId);
|
|
53
|
-
break;
|
|
54
|
-
default:
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.default = toolDbClientOnMessage;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function toolDbClientOnMessage(message, remotePeerId) {
|
|
4
|
+
if (!this.processedIds[message.type]) {
|
|
5
|
+
this.processedIds[message.type] = [];
|
|
6
|
+
}
|
|
7
|
+
if (this.processedIds[message.type].includes(message.id)) {
|
|
8
|
+
// this.logger(
|
|
9
|
+
// `Already processed this message > ${message.type} from ${remotePeerId}`
|
|
10
|
+
// );
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
this.emit("message", message, remotePeerId);
|
|
14
|
+
this.processedIds[message.type].push(message.id);
|
|
15
|
+
this.logger("Got message ".concat(message.type, " from ").concat(remotePeerId));
|
|
16
|
+
this.logger(message);
|
|
17
|
+
// Check if we are listening for this ID
|
|
18
|
+
if (message.id) {
|
|
19
|
+
var msgId = message.id;
|
|
20
|
+
if (this._idListeners[msgId]) {
|
|
21
|
+
this._idListeners[msgId](message);
|
|
22
|
+
this.removeIdListener(msgId);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (message === undefined || message.type === undefined) {
|
|
26
|
+
this.logger("Message is invalid!", message, typeof message);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
switch (message.type) {
|
|
30
|
+
case "ping":
|
|
31
|
+
this.handlePing(message, remotePeerId);
|
|
32
|
+
break;
|
|
33
|
+
case "pong":
|
|
34
|
+
this.handlePong(message, remotePeerId);
|
|
35
|
+
break;
|
|
36
|
+
case "subscribe":
|
|
37
|
+
this.handleSubscribe(message, remotePeerId);
|
|
38
|
+
break;
|
|
39
|
+
case "get":
|
|
40
|
+
this.handleGet(message, remotePeerId);
|
|
41
|
+
break;
|
|
42
|
+
case "put":
|
|
43
|
+
this.handlePut(message, remotePeerId);
|
|
44
|
+
break;
|
|
45
|
+
case "crdtPut":
|
|
46
|
+
this.handleCrdtPut(message, remotePeerId);
|
|
47
|
+
break;
|
|
48
|
+
case "crdtGet":
|
|
49
|
+
this.handleCrdtGet(message, remotePeerId);
|
|
50
|
+
break;
|
|
51
|
+
case "query":
|
|
52
|
+
this.handleQuery(message, remotePeerId);
|
|
53
|
+
break;
|
|
54
|
+
default:
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.default = toolDbClientOnMessage;
|
|
59
59
|
//# sourceMappingURL=toolDbClientOnMessage.js.map
|
package/dist/toolDbCrdtGet.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { BaseCrdt, ToolDb, CrdtPutMessage } from ".";
|
|
2
|
-
/**
|
|
3
|
-
* Triggers a GET request to other peers. If the data is available locally it will return that instead.
|
|
4
|
-
* @param key key of the data
|
|
5
|
-
* @param userNamespaced If this key bolongs to a user or its public. Making it private will enforce validation for our address and signatures.
|
|
6
|
-
* @param timeout Max time to wait for remote.
|
|
7
|
-
* @returns Promise<Data>
|
|
8
|
-
*/
|
|
9
|
-
export default function toolDbCrdtGet<T = any>(this: ToolDb, key: string, crdt: BaseCrdt<T, any, any>, userNamespaced?: boolean, timeoutMs?: number): Promise<CrdtPutMessage<T> | null>;
|
|
1
|
+
import { BaseCrdt, ToolDb, CrdtPutMessage } from ".";
|
|
2
|
+
/**
|
|
3
|
+
* Triggers a GET request to other peers. If the data is available locally it will return that instead.
|
|
4
|
+
* @param key key of the data
|
|
5
|
+
* @param userNamespaced If this key bolongs to a user or its public. Making it private will enforce validation for our address and signatures.
|
|
6
|
+
* @param timeout Max time to wait for remote.
|
|
7
|
+
* @returns Promise<Data>
|
|
8
|
+
*/
|
|
9
|
+
export default function toolDbCrdtGet<T = any>(this: ToolDb, key: string, crdt: BaseCrdt<T, any, any>, userNamespaced?: boolean, timeoutMs?: number, to?: string[]): Promise<CrdtPutMessage<T> | null>;
|
package/dist/toolDbCrdtGet.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var _1 = require(".");
|
|
4
|
-
/**
|
|
5
|
-
* Triggers a GET request to other peers. If the data is available locally it will return that instead.
|
|
6
|
-
* @param key key of the data
|
|
7
|
-
* @param userNamespaced If this key bolongs to a user or its public. Making it private will enforce validation for our address and signatures.
|
|
8
|
-
* @param timeout Max time to wait for remote.
|
|
9
|
-
* @returns Promise<Data>
|
|
10
|
-
*/
|
|
11
|
-
function toolDbCrdtGet(key, crdt, userNamespaced, timeoutMs) {
|
|
12
|
-
var _this = this;
|
|
13
|
-
if (userNamespaced === void 0) { userNamespaced = false; }
|
|
14
|
-
if (timeoutMs === void 0) { timeoutMs = 1000; }
|
|
15
|
-
return new Promise(function (resolve, reject) {
|
|
16
|
-
if (userNamespaced && _this.userAccount.getAddress() === undefined) {
|
|
17
|
-
reject(new Error("You are not authorized yet!"));
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
var finalKey = userNamespaced
|
|
21
|
-
? ":".concat(_this.userAccount.getAddress(), ".").concat(key)
|
|
22
|
-
: key;
|
|
23
|
-
_this.logger("CRDT GET", finalKey);
|
|
24
|
-
var msgId = (0, _1.textRandom)(10);
|
|
25
|
-
var cancelTimeout = setTimeout(function () {
|
|
26
|
-
_this.store
|
|
27
|
-
.get(finalKey)
|
|
28
|
-
.then(function (data) {
|
|
29
|
-
try {
|
|
30
|
-
var message = JSON.parse(data);
|
|
31
|
-
crdt.mergeChanges(message.v);
|
|
32
|
-
_this.emit("data", message);
|
|
33
|
-
resolve(message);
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
resolve(null);
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
.catch(function (e) { return reject(null); });
|
|
40
|
-
}, timeoutMs);
|
|
41
|
-
_this.addIdListener(msgId, function (msg) {
|
|
42
|
-
_this.logger("GET RECV", finalKey);
|
|
43
|
-
clearTimeout(cancelTimeout);
|
|
44
|
-
if (msg.type === "crdtPut") {
|
|
45
|
-
crdt.mergeChanges(msg.data.v);
|
|
46
|
-
resolve(msg);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
_this.store
|
|
50
|
-
.get(finalKey)
|
|
51
|
-
.then(function (data) {
|
|
52
|
-
try {
|
|
53
|
-
var msg = JSON.parse(data);
|
|
54
|
-
clearTimeout(cancelTimeout);
|
|
55
|
-
_this.removeIdListener(msgId);
|
|
56
|
-
crdt.mergeChanges(msg.v);
|
|
57
|
-
_this.emit("data", msg);
|
|
58
|
-
resolve(msg);
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
// do nothing
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
.catch(function () {
|
|
65
|
-
// do nothing
|
|
66
|
-
});
|
|
67
|
-
// Do get
|
|
68
|
-
_this.network.sendToAll({
|
|
69
|
-
type: "crdtGet",
|
|
70
|
-
to: [],
|
|
71
|
-
key: finalKey,
|
|
72
|
-
id: msgId,
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
exports.default = toolDbCrdtGet;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var _1 = require(".");
|
|
4
|
+
/**
|
|
5
|
+
* Triggers a GET request to other peers. If the data is available locally it will return that instead.
|
|
6
|
+
* @param key key of the data
|
|
7
|
+
* @param userNamespaced If this key bolongs to a user or its public. Making it private will enforce validation for our address and signatures.
|
|
8
|
+
* @param timeout Max time to wait for remote.
|
|
9
|
+
* @returns Promise<Data>
|
|
10
|
+
*/
|
|
11
|
+
function toolDbCrdtGet(key, crdt, userNamespaced, timeoutMs, to) {
|
|
12
|
+
var _this = this;
|
|
13
|
+
if (userNamespaced === void 0) { userNamespaced = false; }
|
|
14
|
+
if (timeoutMs === void 0) { timeoutMs = 1000; }
|
|
15
|
+
return new Promise(function (resolve, reject) {
|
|
16
|
+
if (userNamespaced && _this.userAccount.getAddress() === undefined) {
|
|
17
|
+
reject(new Error("You are not authorized yet!"));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
var finalKey = userNamespaced
|
|
21
|
+
? ":".concat(_this.userAccount.getAddress(), ".").concat(key)
|
|
22
|
+
: key;
|
|
23
|
+
_this.logger("CRDT GET", finalKey);
|
|
24
|
+
var msgId = (0, _1.textRandom)(10);
|
|
25
|
+
var cancelTimeout = setTimeout(function () {
|
|
26
|
+
_this.store
|
|
27
|
+
.get(finalKey)
|
|
28
|
+
.then(function (data) {
|
|
29
|
+
try {
|
|
30
|
+
var message = JSON.parse(data);
|
|
31
|
+
crdt.mergeChanges(message.v);
|
|
32
|
+
_this.emit("data", message);
|
|
33
|
+
resolve(message);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
resolve(null);
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
.catch(function (e) { return reject(null); });
|
|
40
|
+
}, timeoutMs);
|
|
41
|
+
_this.addIdListener(msgId, function (msg) {
|
|
42
|
+
_this.logger("GET RECV", finalKey);
|
|
43
|
+
clearTimeout(cancelTimeout);
|
|
44
|
+
if (msg.type === "crdtPut") {
|
|
45
|
+
crdt.mergeChanges(msg.data.v);
|
|
46
|
+
resolve(msg);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
_this.store
|
|
50
|
+
.get(finalKey)
|
|
51
|
+
.then(function (data) {
|
|
52
|
+
try {
|
|
53
|
+
var msg = JSON.parse(data);
|
|
54
|
+
clearTimeout(cancelTimeout);
|
|
55
|
+
_this.removeIdListener(msgId);
|
|
56
|
+
crdt.mergeChanges(msg.v);
|
|
57
|
+
_this.emit("data", msg);
|
|
58
|
+
resolve(msg);
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
// do nothing
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
.catch(function () {
|
|
65
|
+
// do nothing
|
|
66
|
+
});
|
|
67
|
+
// Do get
|
|
68
|
+
_this.network.sendToAll({
|
|
69
|
+
type: "crdtGet",
|
|
70
|
+
to: to || [],
|
|
71
|
+
key: finalKey,
|
|
72
|
+
id: msgId,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.default = toolDbCrdtGet;
|
|
77
77
|
//# sourceMappingURL=toolDbCrdtGet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolDbCrdtGet.js","sourceRoot":"","sources":["../lib/toolDbCrdtGet.ts"],"names":[],"mappings":";;AAAA,sBAAiE;AAEjE;;;;;;GAMG;AACH,SAAwB,aAAa,CAEnC,GAAW,EACX,IAA2B,EAC3B,cAAsB,EACtB,SAAgB;
|
|
1
|
+
{"version":3,"file":"toolDbCrdtGet.js","sourceRoot":"","sources":["../lib/toolDbCrdtGet.ts"],"names":[],"mappings":";;AAAA,sBAAiE;AAEjE;;;;;;GAMG;AACH,SAAwB,aAAa,CAEnC,GAAW,EACX,IAA2B,EAC3B,cAAsB,EACtB,SAAgB,EAChB,EAAa;IANf,iBAyEC;IArEC,+BAAA,EAAA,sBAAsB;IACtB,0BAAA,EAAA,gBAAgB;IAGhB,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACjC,IAAI,cAAc,IAAI,KAAI,CAAC,WAAW,CAAC,UAAU,EAAE,KAAK,SAAS,EAAE;YACjE,MAAM,CAAC,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAAC;YACjD,OAAO;SACR;QACD,IAAM,QAAQ,GAAG,cAAc;YAC7B,CAAC,CAAC,WAAI,KAAI,CAAC,WAAW,CAAC,UAAU,EAAE,cAAI,GAAG,CAAE;YAC5C,CAAC,CAAC,GAAG,CAAC;QACR,KAAI,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAElC,IAAM,KAAK,GAAG,IAAA,aAAU,EAAC,EAAE,CAAC,CAAC;QAE7B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C;gBACzB,KAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBACvB,OAAO,CAAC,GAAG,CAAC,CAAC;aACd;YAAC,OAAO,CAAC,EAAE;gBACV,aAAa;aACd;QACH,CAAC,CAAC;aACD,KAAK,CAAC;YACL,aAAa;QACf,CAAC,CAAC,CAAC;QAEL,SAAS;QACT,KAAI,CAAC,OAAO,CAAC,SAAS,CAAC;YACrB,IAAI,EAAE,SAAS;YACf,EAAE,EAAE,EAAE,IAAI,EAAE;YACZ,GAAG,EAAE,QAAQ;YACb,EAAE,EAAE,KAAK;SACV,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAzED,gCAyEC"}
|
package/dist/toolDbCrdtPut.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ToolDb, CrdtPutMessage, BaseCrdt } from ".";
|
|
2
|
-
/**
|
|
3
|
-
* Triggers a PUT request to other peers.
|
|
4
|
-
* @param key key where we want to put the data at.
|
|
5
|
-
* @param value Data we want to any (any type)
|
|
6
|
-
* @param userNamespaced If this key bolongs to a user or its public. Making it private will enforce validation for our address and signatures.
|
|
7
|
-
* @returns Promise<Data | null>
|
|
8
|
-
*/
|
|
9
|
-
export default function toolDbCrdtPut<T = any>(this: ToolDb, key: string, crdt: BaseCrdt<T, any, any>, userNamespaced?: boolean): Promise<CrdtPutMessage | null>;
|
|
1
|
+
import { ToolDb, CrdtPutMessage, BaseCrdt } from ".";
|
|
2
|
+
/**
|
|
3
|
+
* Triggers a PUT request to other peers.
|
|
4
|
+
* @param key key where we want to put the data at.
|
|
5
|
+
* @param value Data we want to any (any type)
|
|
6
|
+
* @param userNamespaced If this key bolongs to a user or its public. Making it private will enforce validation for our address and signatures.
|
|
7
|
+
* @returns Promise<Data | null>
|
|
8
|
+
*/
|
|
9
|
+
export default function toolDbCrdtPut<T = any>(this: ToolDb, key: string, crdt: BaseCrdt<T, any, any>, userNamespaced?: boolean, to?: string[]): Promise<CrdtPutMessage | null>;
|
package/dist/toolDbCrdtPut.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var _1 = require(".");
|
|
4
|
-
/**
|
|
5
|
-
* Triggers a PUT request to other peers.
|
|
6
|
-
* @param key key where we want to put the data at.
|
|
7
|
-
* @param value Data we want to any (any type)
|
|
8
|
-
* @param userNamespaced If this key bolongs to a user or its public. Making it private will enforce validation for our address and signatures.
|
|
9
|
-
* @returns Promise<Data | null>
|
|
10
|
-
*/
|
|
11
|
-
function toolDbCrdtPut(key, crdt, userNamespaced) {
|
|
12
|
-
var _this = this;
|
|
13
|
-
if (userNamespaced === void 0) { userNamespaced = false; }
|
|
14
|
-
return new Promise(function (resolve, reject) {
|
|
15
|
-
if (key.includes(".")) {
|
|
16
|
-
// Dots are used as a delimitator character between bublic keys and the key of the user's data
|
|
17
|
-
reject(new Error("Key cannot include dots!; ".concat(key)));
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (!_this.userAccount.getAddress()) {
|
|
21
|
-
reject(new Error("You need to log in before you can PUT."));
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
var timestamp = new Date().getTime();
|
|
25
|
-
var crdtChanges = crdt.getChanges();
|
|
26
|
-
var encodedData = JSON.stringify(crdtChanges);
|
|
27
|
-
var dataString = "".concat(encodedData).concat(_this.userAccount.getAddress()).concat(timestamp);
|
|
28
|
-
// WORK
|
|
29
|
-
(0, _1.proofOfWork)(dataString, _this.options.pow)
|
|
30
|
-
.then(function (_a) {
|
|
31
|
-
var hash = _a.hash, nonce = _a.nonce;
|
|
32
|
-
_this.userAccount.signData(hash).then(function (signature) {
|
|
33
|
-
if (signature && _this.userAccount.getAddress()) {
|
|
34
|
-
// Compose the message
|
|
35
|
-
var data = {
|
|
36
|
-
k: userNamespaced
|
|
37
|
-
? ":".concat(_this.userAccount.getAddress(), ".").concat(key)
|
|
38
|
-
: key,
|
|
39
|
-
a: _this.userAccount.getAddress() || "",
|
|
40
|
-
n: nonce,
|
|
41
|
-
t: timestamp,
|
|
42
|
-
h: hash,
|
|
43
|
-
s: signature,
|
|
44
|
-
v: crdtChanges,
|
|
45
|
-
c: crdt.type,
|
|
46
|
-
};
|
|
47
|
-
_this.logger("PUT CRDT", key, data);
|
|
48
|
-
var finalMessage = {
|
|
49
|
-
type: "crdtPut",
|
|
50
|
-
id: (0, _1.textRandom)(10),
|
|
51
|
-
to: [],
|
|
52
|
-
data: data,
|
|
53
|
-
};
|
|
54
|
-
_this.network.sendToAll(finalMessage);
|
|
55
|
-
resolve(finalMessage);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
})
|
|
59
|
-
.catch(reject);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
exports.default = toolDbCrdtPut;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var _1 = require(".");
|
|
4
|
+
/**
|
|
5
|
+
* Triggers a PUT request to other peers.
|
|
6
|
+
* @param key key where we want to put the data at.
|
|
7
|
+
* @param value Data we want to any (any type)
|
|
8
|
+
* @param userNamespaced If this key bolongs to a user or its public. Making it private will enforce validation for our address and signatures.
|
|
9
|
+
* @returns Promise<Data | null>
|
|
10
|
+
*/
|
|
11
|
+
function toolDbCrdtPut(key, crdt, userNamespaced, to) {
|
|
12
|
+
var _this = this;
|
|
13
|
+
if (userNamespaced === void 0) { userNamespaced = false; }
|
|
14
|
+
return new Promise(function (resolve, reject) {
|
|
15
|
+
if (key.includes(".")) {
|
|
16
|
+
// Dots are used as a delimitator character between bublic keys and the key of the user's data
|
|
17
|
+
reject(new Error("Key cannot include dots!; ".concat(key)));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!_this.userAccount.getAddress()) {
|
|
21
|
+
reject(new Error("You need to log in before you can PUT."));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
var timestamp = new Date().getTime();
|
|
25
|
+
var crdtChanges = crdt.getChanges();
|
|
26
|
+
var encodedData = JSON.stringify(crdtChanges);
|
|
27
|
+
var dataString = "".concat(encodedData).concat(_this.userAccount.getAddress()).concat(timestamp);
|
|
28
|
+
// WORK
|
|
29
|
+
(0, _1.proofOfWork)(dataString, _this.options.pow)
|
|
30
|
+
.then(function (_a) {
|
|
31
|
+
var hash = _a.hash, nonce = _a.nonce;
|
|
32
|
+
_this.userAccount.signData(hash).then(function (signature) {
|
|
33
|
+
if (signature && _this.userAccount.getAddress()) {
|
|
34
|
+
// Compose the message
|
|
35
|
+
var data = {
|
|
36
|
+
k: userNamespaced
|
|
37
|
+
? ":".concat(_this.userAccount.getAddress(), ".").concat(key)
|
|
38
|
+
: key,
|
|
39
|
+
a: _this.userAccount.getAddress() || "",
|
|
40
|
+
n: nonce,
|
|
41
|
+
t: timestamp,
|
|
42
|
+
h: hash,
|
|
43
|
+
s: signature,
|
|
44
|
+
v: crdtChanges,
|
|
45
|
+
c: crdt.type,
|
|
46
|
+
};
|
|
47
|
+
_this.logger("PUT CRDT", key, data);
|
|
48
|
+
var finalMessage = {
|
|
49
|
+
type: "crdtPut",
|
|
50
|
+
id: (0, _1.textRandom)(10),
|
|
51
|
+
to: to || [],
|
|
52
|
+
data: data,
|
|
53
|
+
};
|
|
54
|
+
_this.network.sendToAll(finalMessage);
|
|
55
|
+
resolve(finalMessage);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
})
|
|
59
|
+
.catch(reject);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.default = toolDbCrdtPut;
|
|
63
63
|
//# sourceMappingURL=toolDbCrdtPut.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolDbCrdtPut.js","sourceRoot":"","sources":["../lib/toolDbCrdtPut.ts"],"names":[],"mappings":";;AAAA,sBAOW;AAEX;;;;;;GAMG;AACH,SAAwB,aAAa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oBAC9C,sBAAsB;oBACtB,IAAM,IAAI,GAA0B;wBAClC,CAAC,EAAE,cAAc;4BACf,CAAC,CAAC,WAAI,KAAI,CAAC,WAAW,CAAC,UAAU,EAAE,cAAI,GAAG,CAAE;4BAC5C,CAAC,CAAC,GAAG;wBACP,CAAC,EAAE,KAAI,CAAC,WAAW,CAAC,UAAU,EAAE,IAAI,EAAE;wBACtC,CAAC,EAAE,KAAK;wBACR,CAAC,EAAE,SAAS;wBACZ,CAAC,EAAE,IAAI;wBACP,CAAC,EAAE,SAAS;wBACZ,CAAC,EAAE,WAAW;wBACd,CAAC,EAAE,IAAI,CAAC,IAAI;qBACb,CAAC;oBAEF,KAAI,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;oBAEnC,IAAM,YAAY,GAAwB;wBACxC,IAAI,EAAE,SAAS;wBACf,EAAE,EAAE,IAAA,aAAU,EAAC,EAAE,CAAC;wBAClB,EAAE,EAAE,EAAE,IAAI,EAAE;wBACZ,IAAI,MAAA;qBACL,CAAC;oBACF,KAAI,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;oBACrC,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvB;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;aACD,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AA7DD,gCA6DC"}
|
package/dist/toolDbGet.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ToolDb } from ".";
|
|
2
|
-
/**
|
|
3
|
-
* Triggers a GET request to other peers. If the data is available locally it will return that instead.
|
|
4
|
-
* @param key key of the data
|
|
5
|
-
* @param userNamespaced If this key bolongs to a user or its public. Making it private will enforce validation for our address and signatures.
|
|
6
|
-
* @param timeout Max time to wait for remote.
|
|
7
|
-
* @returns Promise<Data>
|
|
8
|
-
*/
|
|
9
|
-
export default function toolDbGet<T = any>(this: ToolDb, key: string, userNamespaced?: boolean, timeoutMs?: number): Promise<T | null>;
|
|
1
|
+
import { ToolDb } from ".";
|
|
2
|
+
/**
|
|
3
|
+
* Triggers a GET request to other peers. If the data is available locally it will return that instead.
|
|
4
|
+
* @param key key of the data
|
|
5
|
+
* @param userNamespaced If this key bolongs to a user or its public. Making it private will enforce validation for our address and signatures.
|
|
6
|
+
* @param timeout Max time to wait for remote.
|
|
7
|
+
* @returns Promise<Data>
|
|
8
|
+
*/
|
|
9
|
+
export default function toolDbGet<T = any>(this: ToolDb, key: string, userNamespaced?: boolean, timeoutMs?: number, to?: string[]): Promise<T | null>;
|