@evolu/common 6.0.1-preview.2 → 6.0.1-preview.21
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/src/Assert.d.ts +6 -3
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +7 -4
- package/dist/src/Brand.d.ts +75 -0
- package/dist/src/Brand.d.ts.map +1 -0
- package/dist/src/Brand.js +1 -0
- package/dist/src/Buffer.d.ts +1 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +1 -1
- package/dist/src/CallbackRegistry.d.ts +53 -0
- package/dist/src/CallbackRegistry.d.ts.map +1 -0
- package/dist/src/CallbackRegistry.js +25 -0
- package/dist/src/Console.d.ts +31 -6
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +72 -9
- package/dist/src/Crypto.d.ts +61 -34
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +29 -42
- package/dist/src/Evolu/Db.d.ts +159 -66
- package/dist/src/Evolu/Db.d.ts.map +1 -1
- package/dist/src/Evolu/Db.js +300 -705
- package/dist/src/Evolu/Diff.d.ts +3 -3
- package/dist/src/Evolu/Diff.d.ts.map +1 -1
- package/dist/src/Evolu/Diff.js +7 -5
- package/dist/src/Evolu/Evolu.d.ts +200 -115
- package/dist/src/Evolu/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu/Evolu.js +287 -157
- package/dist/src/Evolu/Internal.d.ts +0 -2
- package/dist/src/Evolu/Internal.d.ts.map +1 -1
- package/dist/src/Evolu/Internal.js +0 -2
- package/dist/src/Evolu/LocalAuth.d.ts +144 -0
- package/dist/src/Evolu/LocalAuth.d.ts.map +1 -0
- package/dist/src/Evolu/LocalAuth.js +171 -0
- package/dist/src/Evolu/Owner.d.ts +209 -124
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +118 -104
- package/dist/src/Evolu/Platform.d.ts +9 -7
- package/dist/src/Evolu/Platform.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.d.ts +256 -211
- package/dist/src/Evolu/Protocol.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.js +558 -359
- package/dist/src/Evolu/Public.d.ts +6 -8
- package/dist/src/Evolu/Public.d.ts.map +1 -1
- package/dist/src/Evolu/Public.js +2 -3
- package/dist/src/Evolu/PublicKysely.js +3 -3
- package/dist/src/Evolu/Query.d.ts +2 -1
- package/dist/src/Evolu/Query.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.d.ts +72 -4
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +124 -13
- package/dist/src/Evolu/Schema.d.ts +129 -73
- package/dist/src/Evolu/Schema.d.ts.map +1 -1
- package/dist/src/Evolu/Schema.js +169 -89
- package/dist/src/Evolu/Storage.d.ts +159 -14
- package/dist/src/Evolu/Storage.d.ts.map +1 -1
- package/dist/src/Evolu/Storage.js +42 -32
- package/dist/src/Evolu/Sync.d.ts +68 -13
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +414 -20
- package/dist/src/Evolu/Timestamp.d.ts +35 -27
- package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
- package/dist/src/Evolu/Timestamp.js +27 -18
- package/dist/src/ManyToManyMap.d.ts +74 -10
- package/dist/src/ManyToManyMap.d.ts.map +1 -1
- package/dist/src/ManyToManyMap.js +41 -6
- package/dist/src/Number.d.ts +2 -1
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Random.d.ts +3 -2
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/RefCountedResourceManager.d.ts +119 -0
- package/dist/src/RefCountedResourceManager.d.ts.map +1 -0
- package/dist/src/RefCountedResourceManager.js +197 -0
- package/dist/src/Result.d.ts +176 -51
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +30 -241
- package/dist/src/Sqlite.d.ts +21 -4
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +50 -8
- package/dist/src/Task.d.ts +511 -0
- package/dist/src/Task.d.ts.map +1 -0
- package/dist/src/Task.js +410 -0
- package/dist/src/Time.d.ts +59 -0
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +87 -4
- package/dist/src/Type.d.ts +474 -327
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +502 -436
- package/dist/src/Types.d.ts +0 -74
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/WebSocket.d.ts +5 -2
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +12 -13
- package/dist/src/Worker.d.ts +39 -11
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +22 -4
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/package.json +14 -13
- package/src/Assert.ts +8 -7
- package/src/Brand.ts +75 -0
- package/src/Buffer.ts +1 -1
- package/src/CallbackRegistry.ts +84 -0
- package/src/Console.ts +91 -11
- package/src/Crypto.ts +94 -79
- package/src/Evolu/Db.ts +528 -1027
- package/src/Evolu/Diff.ts +7 -5
- package/src/Evolu/Evolu.ts +682 -329
- package/src/Evolu/Internal.ts +0 -2
- package/src/Evolu/LocalAuth.ts +422 -0
- package/src/Evolu/Owner.ts +282 -227
- package/src/Evolu/Platform.ts +9 -9
- package/src/Evolu/Protocol.ts +788 -640
- package/src/Evolu/Public.ts +7 -14
- package/src/Evolu/PublicKysely.ts +3 -3
- package/src/Evolu/Query.ts +2 -1
- package/src/Evolu/Relay.ts +238 -18
- package/src/Evolu/Schema.ts +391 -191
- package/src/Evolu/Storage.ts +275 -55
- package/src/Evolu/Sync.ts +708 -37
- package/src/Evolu/Timestamp.ts +38 -35
- package/src/ManyToManyMap.ts +127 -24
- package/src/Number.ts +2 -6
- package/src/Random.ts +3 -2
- package/src/RefCountedResourceManager.ts +368 -0
- package/src/Result.ts +183 -53
- package/src/Sqlite.ts +59 -23
- package/src/Task.ts +779 -0
- package/src/Time.ts +168 -4
- package/src/Type.ts +708 -660
- package/src/Types.ts +0 -76
- package/src/WebSocket.ts +23 -17
- package/src/Worker.ts +72 -23
- package/src/index.ts +3 -3
- package/dist/src/Callbacks.d.ts +0 -20
- package/dist/src/Callbacks.d.ts.map +0 -1
- package/dist/src/Callbacks.js +0 -18
- package/dist/src/Evolu/Config.d.ts +0 -69
- package/dist/src/Evolu/Config.d.ts.map +0 -1
- package/dist/src/Evolu/Config.js +0 -9
- package/dist/src/Evolu/Kysely.d.ts +0 -6
- package/dist/src/Evolu/Kysely.d.ts.map +0 -1
- package/dist/src/Evolu/Kysely.js +0 -21
- package/dist/src/NanoId.d.ts +0 -27
- package/dist/src/NanoId.d.ts.map +0 -1
- package/dist/src/NanoId.js +0 -6
- package/dist/src/Promise.d.ts +0 -180
- package/dist/src/Promise.d.ts.map +0 -1
- package/dist/src/Promise.js +0 -176
- package/src/Callbacks.ts +0 -43
- package/src/Evolu/Config.ts +0 -83
- package/src/Evolu/Kysely.ts +0 -38
- package/src/NanoId.ts +0 -39
- package/src/Promise.ts +0 -295
package/dist/src/Evolu/Sync.js
CHANGED
|
@@ -1,29 +1,423 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { assert } from "../Assert.js";
|
|
2
|
+
import { eqArrayNumber } from "../Eq.js";
|
|
3
|
+
import { createTransferableError } from "../Error.js";
|
|
4
|
+
import { constFalse } from "../Function.js";
|
|
5
|
+
import { objectToEntries } from "../Object.js";
|
|
6
|
+
import { createRefCountedResourceManager } from "../RefCountedResourceManager.js";
|
|
7
|
+
import { ok } from "../Result.js";
|
|
8
|
+
import { sql } from "../Sqlite.js";
|
|
9
|
+
import { createMutex } from "../Task.js";
|
|
10
|
+
import { idBytesToId, idToIdBytes } from "../Type.js";
|
|
11
|
+
import { ownerIdBytesToOwnerId, ownerIdToOwnerIdBytes, } from "./Owner.js";
|
|
12
|
+
import { applyProtocolMessageAsClient, createProtocolMessageForSync, createProtocolMessageForUnsubscribe, createProtocolMessageFromCrdtMessages, decryptAndDecodeDbChange, encodeAndEncryptDbChange, SubscriptionFlags, } from "./Protocol.js";
|
|
13
|
+
import { createSqliteStorageBase, } from "./Storage.js";
|
|
14
|
+
import { createInitialTimestamp, receiveTimestamp, sendTimestamp, timestampBytesToTimestamp, timestampToTimestampBytes, timestampToTimestampString, } from "./Timestamp.js";
|
|
15
|
+
export const createSync = (deps) => (config) => {
|
|
16
|
+
let isDisposed = false;
|
|
17
|
+
/** Returns owner data only if actively assigned to at least one transport. */
|
|
18
|
+
const getSyncOwner = (ownerId) => {
|
|
19
|
+
if (isDisposed)
|
|
20
|
+
return null;
|
|
21
|
+
return transports.getConsumer(ownerId);
|
|
22
|
+
};
|
|
23
|
+
const storageResult = createClientStorage({
|
|
24
|
+
...deps,
|
|
25
|
+
getSyncOwner,
|
|
26
|
+
})(config);
|
|
27
|
+
if (!storageResult.ok)
|
|
28
|
+
return storageResult;
|
|
29
|
+
const storage = storageResult.value;
|
|
30
|
+
const createResource = (transportConfig) => {
|
|
31
|
+
const transportKey = createTransportKey(transportConfig);
|
|
32
|
+
deps.console.log("[sync]", "createWebSocket", {
|
|
33
|
+
transportKey,
|
|
34
|
+
url: transportConfig.url,
|
|
35
|
+
});
|
|
36
|
+
return deps.createWebSocket(transportConfig.url, {
|
|
37
|
+
binaryType: "arraybuffer",
|
|
38
|
+
onOpen: () => {
|
|
39
|
+
if (isDisposed)
|
|
40
|
+
return;
|
|
41
|
+
const webSocket = transports.getResource(transportKey);
|
|
42
|
+
if (!webSocket)
|
|
43
|
+
return;
|
|
44
|
+
const ownerIds = transports.getConsumersForResource(transportKey);
|
|
45
|
+
deps.console.log("[sync]", "onOpen", { transportKey, ownerIds });
|
|
46
|
+
for (const ownerId of ownerIds) {
|
|
47
|
+
const message = createProtocolMessageForSync({ storage })(ownerId, SubscriptionFlags.Subscribe);
|
|
48
|
+
if (!message)
|
|
49
|
+
continue;
|
|
50
|
+
deps.console.log("[sync]", "send", { message });
|
|
51
|
+
webSocket.send(message);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
onClose: (event) => {
|
|
55
|
+
deps.console.log("[sync]", "onClose", {
|
|
56
|
+
transportKey,
|
|
57
|
+
code: event.code,
|
|
58
|
+
reason: event.reason,
|
|
59
|
+
wasClean: event.wasClean,
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
onError: (error) => {
|
|
63
|
+
deps.console.warn("[sync]", "onError", { transportKey, error });
|
|
64
|
+
},
|
|
65
|
+
onMessage: (data) => {
|
|
66
|
+
// Only handle ArrayBuffer data for sync messages
|
|
67
|
+
if (isDisposed || !(data instanceof ArrayBuffer))
|
|
68
|
+
return;
|
|
69
|
+
const webSocket = transports.getResource(transportKey);
|
|
70
|
+
if (!webSocket)
|
|
71
|
+
return;
|
|
72
|
+
const input = new Uint8Array(data);
|
|
73
|
+
deps.console.log("[sync]", "onMessage", {
|
|
74
|
+
transportKey,
|
|
75
|
+
message: input,
|
|
76
|
+
});
|
|
77
|
+
applyProtocolMessageAsClient({ storage })(input, {
|
|
78
|
+
// No write key, no sync (for a case when an owner was unused).
|
|
79
|
+
getWriteKey: (ownerId) => getSyncOwner(ownerId)?.writeKey ?? null,
|
|
80
|
+
})
|
|
81
|
+
.then((message) => {
|
|
82
|
+
if (!message.ok) {
|
|
83
|
+
config.onError(message.error);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
switch (message.value.type) {
|
|
87
|
+
case "response":
|
|
88
|
+
webSocket.send(message.value.message);
|
|
89
|
+
break;
|
|
90
|
+
case "no-response":
|
|
91
|
+
// Sync complete, no response needed
|
|
92
|
+
break;
|
|
93
|
+
case "broadcast":
|
|
94
|
+
// This was a broadcast message, don't affect sync counter
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
.catch((error) => {
|
|
99
|
+
config.onError(createTransferableError(error));
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
const transports = createRefCountedResourceManager({
|
|
105
|
+
createResource,
|
|
106
|
+
getResourceKey: createTransportKey,
|
|
107
|
+
getConsumerId: (owner) => owner.id,
|
|
108
|
+
disposalDelay: config.disposalDelayMs ?? 100,
|
|
109
|
+
onConsumerAdded: (owner, webSocket) => {
|
|
110
|
+
deps.console.log("[sync]", "onConsumerAdded", {
|
|
111
|
+
ownerId: owner.id,
|
|
112
|
+
isOpen: webSocket.isOpen(),
|
|
113
|
+
});
|
|
114
|
+
// The onOpen handler will sync it.
|
|
115
|
+
if (!webSocket.isOpen())
|
|
116
|
+
return;
|
|
117
|
+
const message = createProtocolMessageForSync({ storage })(owner.id, SubscriptionFlags.Subscribe);
|
|
118
|
+
if (message)
|
|
119
|
+
webSocket.send(message);
|
|
120
|
+
},
|
|
121
|
+
onConsumerRemoved: (owner, webSocket) => {
|
|
122
|
+
deps.console.log("[sync]", "onConsumerRemoved", {
|
|
123
|
+
ownerId: owner.id,
|
|
124
|
+
isOpen: webSocket.isOpen(),
|
|
125
|
+
});
|
|
126
|
+
const message = createProtocolMessageForUnsubscribe(owner.id);
|
|
127
|
+
webSocket.send(message);
|
|
128
|
+
},
|
|
129
|
+
});
|
|
3
130
|
const sync = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* and mutations are stored in SQLite. Dropped CRDT messages are synced
|
|
8
|
-
* when the web socket connection is open.
|
|
9
|
-
*/
|
|
10
|
-
if (socket.getReadyState() !== "open")
|
|
131
|
+
useOwner: (use, owner) => {
|
|
132
|
+
if (isDisposed) {
|
|
133
|
+
deps.console.warn("[sync]", "useOwner called on disposed Sync instance", { owner });
|
|
11
134
|
return;
|
|
12
|
-
|
|
135
|
+
}
|
|
136
|
+
deps.console.log("[sync]", "useOwner", { use, owner });
|
|
137
|
+
const transportsToUse = owner.transports ?? config.transports;
|
|
138
|
+
if (use) {
|
|
139
|
+
transports.addConsumer(owner, transportsToUse);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
const result = transports.removeConsumer(owner, transportsToUse);
|
|
143
|
+
if (!result.ok) {
|
|
144
|
+
deps.console.warn("[sync]", "Failed to remove consumer", {
|
|
145
|
+
transportsToUse,
|
|
146
|
+
ownerId: owner.id,
|
|
147
|
+
error: result.error,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
applyChanges: (changes) => {
|
|
153
|
+
deps.console.log("[sync]", "applyChanges", { changes });
|
|
154
|
+
let clockTimestamp = deps.clock.get();
|
|
155
|
+
const ownerMessages = new Map();
|
|
156
|
+
for (const change of changes) {
|
|
157
|
+
const nextTimestamp = sendTimestamp(deps)(clockTimestamp);
|
|
158
|
+
if (!nextTimestamp.ok)
|
|
159
|
+
return nextTimestamp;
|
|
160
|
+
clockTimestamp = nextTimestamp.value;
|
|
161
|
+
const { ownerId = config.appOwner.id, ...dbChange } = change;
|
|
162
|
+
const message = { timestamp: clockTimestamp, change: dbChange };
|
|
163
|
+
const messages = ownerMessages.get(ownerId);
|
|
164
|
+
if (messages)
|
|
165
|
+
messages.push(message);
|
|
166
|
+
else
|
|
167
|
+
ownerMessages.set(ownerId, [message]);
|
|
168
|
+
}
|
|
169
|
+
for (const [ownerId, messages] of ownerMessages) {
|
|
170
|
+
const result = applyMessages({ ...deps, storage })(ownerId, messages);
|
|
171
|
+
if (!result.ok)
|
|
172
|
+
return result;
|
|
173
|
+
const owner = getSyncOwner(ownerId);
|
|
174
|
+
if (!owner?.writeKey)
|
|
175
|
+
continue;
|
|
176
|
+
const message = createProtocolMessageFromCrdtMessages(deps)({
|
|
177
|
+
id: owner.id,
|
|
178
|
+
encryptionKey: owner.encryptionKey,
|
|
179
|
+
writeKey: owner.writeKey,
|
|
180
|
+
}, messages);
|
|
181
|
+
const transportsToUse = owner.transports ?? config.transports;
|
|
182
|
+
// Send message to all transports for this owner
|
|
183
|
+
for (const transportConfig of transportsToUse) {
|
|
184
|
+
const transportKey = createTransportKey(transportConfig);
|
|
185
|
+
const webSocket = transports.getResource(transportKey);
|
|
186
|
+
if (!webSocket)
|
|
187
|
+
continue;
|
|
188
|
+
if (webSocket.isOpen()) {
|
|
189
|
+
deps.console.log("[sync]", "send", { transportKey, message });
|
|
190
|
+
webSocket.send(message);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return deps.clock.save(clockTimestamp);
|
|
195
|
+
},
|
|
196
|
+
[Symbol.dispose]: () => {
|
|
197
|
+
if (isDisposed)
|
|
198
|
+
return;
|
|
199
|
+
isDisposed = true;
|
|
200
|
+
transports[Symbol.dispose]();
|
|
13
201
|
},
|
|
14
202
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
203
|
+
return ok(sync);
|
|
204
|
+
};
|
|
205
|
+
export const createClock = (deps) => (initialTimestamp = createInitialTimestamp(deps)) => {
|
|
206
|
+
let currentTimestamp = initialTimestamp;
|
|
207
|
+
return {
|
|
208
|
+
get: () => currentTimestamp,
|
|
209
|
+
save: (timestamp) => {
|
|
210
|
+
currentTimestamp = timestamp;
|
|
211
|
+
const timestampString = timestampToTimestampString(timestamp);
|
|
212
|
+
const result = deps.sqlite.exec(sql.prepared `
|
|
213
|
+
update evolu_config set "clock" = ${timestampString};
|
|
214
|
+
`);
|
|
215
|
+
if (!result.ok)
|
|
216
|
+
return result;
|
|
217
|
+
return ok();
|
|
19
218
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
const createClientStorage = (deps) => (config) => {
|
|
222
|
+
const sqliteStorageBase = createSqliteStorageBase(deps)({
|
|
223
|
+
onStorageError: config.onError,
|
|
224
|
+
});
|
|
225
|
+
if (!sqliteStorageBase.ok)
|
|
226
|
+
return sqliteStorageBase;
|
|
227
|
+
const mutex = createMutex();
|
|
228
|
+
const storage = {
|
|
229
|
+
...sqliteStorageBase.value,
|
|
230
|
+
validateWriteKey: constFalse,
|
|
231
|
+
setWriteKey: constFalse,
|
|
232
|
+
writeMessages: async (ownerIdBytes, encryptedMessages) => {
|
|
233
|
+
const writeResult = await mutex.withLock(async () => {
|
|
234
|
+
const ownerId = ownerIdBytesToOwnerId(ownerIdBytes);
|
|
235
|
+
const owner = deps.getSyncOwner(ownerId);
|
|
236
|
+
// Owner can be removed during syncing.
|
|
237
|
+
if (!owner)
|
|
238
|
+
return ok(false);
|
|
239
|
+
const messages = [];
|
|
240
|
+
for (const message of encryptedMessages) {
|
|
241
|
+
const change = decryptAndDecodeDbChange(deps)(message, owner.encryptionKey);
|
|
242
|
+
if (!change.ok)
|
|
243
|
+
return change;
|
|
244
|
+
messages.push({
|
|
245
|
+
timestamp: message.timestamp,
|
|
246
|
+
change: change.value,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
const transaction = deps.sqlite.transaction(() => {
|
|
250
|
+
let clockTimestamp = deps.clock.get();
|
|
251
|
+
for (const message of messages) {
|
|
252
|
+
const nextTimestamp = receiveTimestamp(deps)(clockTimestamp, message.timestamp);
|
|
253
|
+
if (!nextTimestamp.ok)
|
|
254
|
+
return nextTimestamp;
|
|
255
|
+
clockTimestamp = nextTimestamp.value;
|
|
256
|
+
}
|
|
257
|
+
const applyMessagesResult = applyMessages({ ...deps, storage })(owner.id, messages);
|
|
258
|
+
if (!applyMessagesResult.ok)
|
|
259
|
+
return applyMessagesResult;
|
|
260
|
+
// // Apply local mutations atomically with approved messages
|
|
261
|
+
// for (const change of localMutations) {
|
|
262
|
+
// const result = applyLocalOnlyChange(deps)(change);
|
|
263
|
+
// if (!result.ok) return result;
|
|
264
|
+
// }
|
|
265
|
+
return deps.clock.save(clockTimestamp);
|
|
266
|
+
});
|
|
267
|
+
if (!transaction.ok)
|
|
268
|
+
return transaction;
|
|
269
|
+
return ok(true);
|
|
270
|
+
})();
|
|
271
|
+
if (!writeResult.ok) {
|
|
272
|
+
if (writeResult.error.type !== "AbortError") {
|
|
273
|
+
config.onError(writeResult.error);
|
|
274
|
+
}
|
|
275
|
+
return false;
|
|
24
276
|
}
|
|
277
|
+
config.onReceive();
|
|
278
|
+
return true;
|
|
25
279
|
},
|
|
26
|
-
|
|
27
|
-
|
|
280
|
+
readDbChange: (ownerId, timestamp) => {
|
|
281
|
+
const owner = deps.getSyncOwner(ownerIdBytesToOwnerId(ownerId));
|
|
282
|
+
// Owner can be removed to stop syncing.
|
|
283
|
+
if (!owner)
|
|
284
|
+
return null;
|
|
285
|
+
const result = deps.sqlite.exec(sql `
|
|
286
|
+
select "table", "id", "column", "value"
|
|
287
|
+
from evolu_history
|
|
288
|
+
where "ownerId" = ${ownerId} and "timestamp" = ${timestamp};
|
|
289
|
+
`);
|
|
290
|
+
if (!result.ok) {
|
|
291
|
+
config.onError(result.error);
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
const { rows } = result.value;
|
|
295
|
+
assert(rows.length > 0, "Rows must not be empty");
|
|
296
|
+
const { table, id } = rows[0];
|
|
297
|
+
const values = {};
|
|
298
|
+
for (const r of rows) {
|
|
299
|
+
assert(r.table === table, "All rows must have the same table");
|
|
300
|
+
assert(eqArrayNumber(r.id, id), "All rows must have the same Id");
|
|
301
|
+
values[r.column] = r.value;
|
|
302
|
+
}
|
|
303
|
+
const message = {
|
|
304
|
+
timestamp: timestampBytesToTimestamp(timestamp),
|
|
305
|
+
change: {
|
|
306
|
+
table: rows[0].table,
|
|
307
|
+
id: idBytesToId(rows[0].id),
|
|
308
|
+
values,
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
return encodeAndEncryptDbChange(deps)(message, owner.encryptionKey);
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
return ok(storage);
|
|
315
|
+
};
|
|
316
|
+
/** Creates a unique identifier for a transport configuration. */
|
|
317
|
+
const createTransportKey = (transportConfig) => {
|
|
318
|
+
return `${transportConfig.type}:${transportConfig.url}`;
|
|
319
|
+
};
|
|
320
|
+
export const applyLocalOnlyChange = (deps) => (change) => {
|
|
321
|
+
const dbChange = {
|
|
322
|
+
table: change.table,
|
|
323
|
+
id: change.id,
|
|
324
|
+
values: change.values,
|
|
325
|
+
};
|
|
326
|
+
const isDeletion = "isDeleted" in dbChange.values && dbChange.values.isDeleted === 1;
|
|
327
|
+
if (isDeletion) {
|
|
328
|
+
const result = deps.sqlite.exec(sql `
|
|
329
|
+
delete from ${sql.identifier(dbChange.table)}
|
|
330
|
+
where id = ${dbChange.id};
|
|
331
|
+
`);
|
|
332
|
+
if (!result.ok)
|
|
333
|
+
return result;
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
const date = new Date(deps.time.now()).toISOString();
|
|
337
|
+
for (const [column, value] of objectToEntries(dbChange.values)) {
|
|
338
|
+
const result = deps.sqlite.exec(sql.prepared `
|
|
339
|
+
insert into ${sql.identifier(dbChange.table)}
|
|
340
|
+
("id", ${sql.identifier(column)}, createdAt, updatedAt)
|
|
341
|
+
values (${dbChange.id}, ${value}, ${date}, ${date})
|
|
342
|
+
on conflict ("id") do update
|
|
343
|
+
set
|
|
344
|
+
${sql.identifier(column)} = ${value},
|
|
345
|
+
updatedAt = ${date};
|
|
346
|
+
`);
|
|
347
|
+
if (!result.ok)
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return ok();
|
|
352
|
+
};
|
|
353
|
+
export const applyMessages = (deps) => (ownerId, messages) => {
|
|
354
|
+
const ownerIdBytes = ownerIdToOwnerIdBytes(ownerId);
|
|
355
|
+
for (const message of messages) {
|
|
356
|
+
const result1 = applyMessageToAppTable(deps)(ownerIdBytes, message);
|
|
357
|
+
if (!result1.ok)
|
|
358
|
+
return result1;
|
|
359
|
+
const result2 = applyMessageToTimestampAndHistoryTables(deps)(ownerIdBytes, message);
|
|
360
|
+
if (!result2.ok)
|
|
361
|
+
return result2;
|
|
362
|
+
}
|
|
363
|
+
return ok();
|
|
364
|
+
};
|
|
365
|
+
const applyMessageToAppTable = (deps) => (ownerId, message) => {
|
|
366
|
+
const timestamp = timestampToTimestampBytes(message.timestamp);
|
|
367
|
+
const updatedAt = new Date(message.timestamp.millis).toISOString();
|
|
368
|
+
for (const [column, value] of objectToEntries(message.change.values)) {
|
|
369
|
+
const result = deps.sqlite.exec(sql.prepared `
|
|
370
|
+
with
|
|
371
|
+
existingTimestamp as (
|
|
372
|
+
select 1
|
|
373
|
+
from evolu_history
|
|
374
|
+
where
|
|
375
|
+
"ownerId" = ${ownerId}
|
|
376
|
+
and "table" = ${message.change.table}
|
|
377
|
+
and "id" = ${idToIdBytes(message.change.id)}
|
|
378
|
+
and "column" = ${column}
|
|
379
|
+
and "timestamp" >= ${timestamp}
|
|
380
|
+
limit 1
|
|
381
|
+
)
|
|
382
|
+
insert into ${sql.identifier(message.change.table)}
|
|
383
|
+
("id", ${sql.identifier(column)}, updatedAt)
|
|
384
|
+
select ${message.change.id}, ${value}, ${updatedAt}
|
|
385
|
+
where not exists (select 1 from existingTimestamp)
|
|
386
|
+
on conflict ("id") do update
|
|
387
|
+
set
|
|
388
|
+
${sql.identifier(column)} = ${value},
|
|
389
|
+
updatedAt = ${updatedAt}
|
|
390
|
+
where not exists (select 1 from existingTimestamp);
|
|
391
|
+
`);
|
|
392
|
+
if (!result.ok)
|
|
393
|
+
return result;
|
|
394
|
+
}
|
|
395
|
+
return ok();
|
|
396
|
+
};
|
|
397
|
+
export const applyMessageToTimestampAndHistoryTables = (deps) => (ownerId, message) => {
|
|
398
|
+
const timestamp = timestampToTimestampBytes(message.timestamp);
|
|
399
|
+
const id = idToIdBytes(message.change.id);
|
|
400
|
+
const result = deps.storage.insertTimestamp(ownerId, timestamp);
|
|
401
|
+
if (!result.ok)
|
|
402
|
+
return result;
|
|
403
|
+
for (const [column, value] of Object.entries(message.change.values)) {
|
|
404
|
+
const result = deps.sqlite.exec(sql.prepared `
|
|
405
|
+
insert into evolu_history
|
|
406
|
+
("ownerId", "table", "id", "column", "value", "timestamp")
|
|
407
|
+
values
|
|
408
|
+
(
|
|
409
|
+
${ownerId},
|
|
410
|
+
${message.change.table},
|
|
411
|
+
${id},
|
|
412
|
+
${column},
|
|
413
|
+
${value},
|
|
414
|
+
${timestamp}
|
|
415
|
+
)
|
|
416
|
+
on conflict do nothing;
|
|
417
|
+
`);
|
|
418
|
+
if (!result.ok)
|
|
419
|
+
return result;
|
|
420
|
+
}
|
|
421
|
+
return ok();
|
|
28
422
|
};
|
|
29
423
|
export const initialSyncState = { type: "SyncStateInitial" };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Brand } from "../Brand.js";
|
|
2
|
+
import { RandomBytesDep } from "../Crypto.js";
|
|
2
3
|
import { Order } from "../Order.js";
|
|
3
4
|
import { Result } from "../Result.js";
|
|
4
5
|
import { TimeDep } from "../Time.js";
|
|
5
|
-
import {
|
|
6
|
+
import { InferType } from "../Type.js";
|
|
6
7
|
export interface TimestampConfig {
|
|
7
8
|
/**
|
|
8
9
|
* Maximum physical clock drift allowed in ms.
|
|
@@ -14,7 +15,7 @@ export interface TimestampConfig {
|
|
|
14
15
|
export interface TimestampConfigDep {
|
|
15
16
|
readonly timestampConfig: TimestampConfig;
|
|
16
17
|
}
|
|
17
|
-
export type TimestampError = TimestampDriftError | TimestampCounterOverflowError |
|
|
18
|
+
export type TimestampError = TimestampDriftError | TimestampCounterOverflowError | TimestampTimeOutOfRangeError;
|
|
18
19
|
export interface TimestampDriftError {
|
|
19
20
|
readonly type: "TimestampDriftError";
|
|
20
21
|
readonly next: Millis;
|
|
@@ -23,10 +24,6 @@ export interface TimestampDriftError {
|
|
|
23
24
|
export interface TimestampCounterOverflowError {
|
|
24
25
|
readonly type: "TimestampCounterOverflowError";
|
|
25
26
|
}
|
|
26
|
-
export interface TimestampDuplicateNodeError {
|
|
27
|
-
readonly type: "TimestampDuplicateNodeError";
|
|
28
|
-
readonly nodeId: NodeId;
|
|
29
|
-
}
|
|
30
27
|
export interface TimestampTimeOutOfRangeError {
|
|
31
28
|
readonly type: "TimestampTimeOutOfRangeError";
|
|
32
29
|
}
|
|
@@ -42,11 +39,11 @@ export interface TimestampTimeOutOfRangeError {
|
|
|
42
39
|
*
|
|
43
40
|
* `new Date(281474976710654).toString()` = Tue Aug 02 10889 07:31:49
|
|
44
41
|
*/
|
|
45
|
-
export declare const Millis: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int"> & Brand<"NonNegative">, number, import("../Type.js").NonNegativeError, number & Brand<"Int">, import("../Type.js").
|
|
42
|
+
export declare const Millis: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int"> & Brand<"NonNegative">, number, import("../Type.js").NonNegativeError, number & Brand<"Int">, import("../Type.js").IntError | import("../Type.js").NumberError>, `LessThanOrEqualTo${number}`, import("../Type.js").LessThanOrEqualToError<number>, import("../Type.js").NonNegativeError | import("../Type.js").IntError | import("../Type.js").NumberError>, "Millis", import("../Type.js").BrandWithoutRefineError<"Millis", import("../Type.js").NonNegativeError | import("../Type.js").IntError | import("../Type.js").NumberError | import("../Type.js").LessThanOrEqualToError<number>>, never>;
|
|
46
43
|
export type Millis = typeof Millis.Type;
|
|
47
44
|
export declare const minMillis: Millis;
|
|
48
45
|
export declare const maxMillis: Millis;
|
|
49
|
-
export declare const Counter: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int"> & Brand<"NonNegative">, number, import("../Type.js").NonNegativeError, number & Brand<"Int">, import("../Type.js").
|
|
46
|
+
export declare const Counter: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int"> & Brand<"NonNegative">, number, import("../Type.js").NonNegativeError, number & Brand<"Int">, import("../Type.js").IntError | import("../Type.js").NumberError>, "LessThanOrEqualTo65535", import("../Type.js").LessThanOrEqualToError<65535>, import("../Type.js").NonNegativeError | import("../Type.js").IntError | import("../Type.js").NumberError>, "Counter", import("../Type.js").BrandWithoutRefineError<"Counter", import("../Type.js").NonNegativeError | import("../Type.js").IntError | import("../Type.js").NumberError | import("../Type.js").LessThanOrEqualToError<65535>>, never>;
|
|
50
47
|
export type Counter = typeof Counter.Type;
|
|
51
48
|
export declare const minCounter: Counter;
|
|
52
49
|
export declare const maxCounter: Counter;
|
|
@@ -63,14 +60,17 @@ export declare const maxCounter: Counter;
|
|
|
63
60
|
*
|
|
64
61
|
* https://lemire.me/blog/2019/12/12/are-64-bit-random-identifiers-free-from-collision
|
|
65
62
|
*
|
|
66
|
-
* What
|
|
63
|
+
* What happens if different devices generate the same NodeId?
|
|
67
64
|
*
|
|
68
|
-
* If the
|
|
69
|
-
* different owner have different owner IDs. Timestamps are partitioned by
|
|
70
|
-
* OwnerId.
|
|
65
|
+
* If devices with the same NodeId use different owners, no issues occur.
|
|
71
66
|
*
|
|
72
|
-
* If the
|
|
73
|
-
*
|
|
67
|
+
* If devices with the same NodeId use the same owner, problems only arise when
|
|
68
|
+
* they generate CRDT messages with identical timestamps (same millis, counter,
|
|
69
|
+
* and NodeId). In this case, the protocol sync algorithm treats them as the
|
|
70
|
+
* same message: the first will be synced with the relay, while the affected
|
|
71
|
+
* message will not be delivered. The affected devices will see different data
|
|
72
|
+
* yet they will think they are synced. This is extremely rare and can be
|
|
73
|
+
* resolved by resetting one device to generate a new NodeId.
|
|
74
74
|
*/
|
|
75
75
|
export declare const NodeId: import("../Type.js").BrandType<import("../Type.js").Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>, "NodeId", import("../Type.js").RegexError<"NodeId">, import("../Type.js").StringError>;
|
|
76
76
|
export type NodeId = typeof NodeId.Type;
|
|
@@ -84,23 +84,31 @@ export declare const maxNodeId: NodeId;
|
|
|
84
84
|
* - https://jaredforsyth.com/posts/hybrid-logical-clocks/
|
|
85
85
|
*/
|
|
86
86
|
export declare const Timestamp: import("../Type.js").ObjectType<{
|
|
87
|
-
millis: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int"> & Brand<"NonNegative">, number, import("../Type.js").NonNegativeError, number & Brand<"Int">, import("../Type.js").
|
|
88
|
-
counter: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int"> & Brand<"NonNegative">, number, import("../Type.js").NonNegativeError, number & Brand<"Int">, import("../Type.js").
|
|
87
|
+
millis: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int"> & Brand<"NonNegative">, number, import("../Type.js").NonNegativeError, number & Brand<"Int">, import("../Type.js").IntError | import("../Type.js").NumberError>, `LessThanOrEqualTo${number}`, import("../Type.js").LessThanOrEqualToError<number>, import("../Type.js").NonNegativeError | import("../Type.js").IntError | import("../Type.js").NumberError>, "Millis", import("../Type.js").BrandWithoutRefineError<"Millis", import("../Type.js").NonNegativeError | import("../Type.js").IntError | import("../Type.js").NumberError | import("../Type.js").LessThanOrEqualToError<number>>, never>;
|
|
88
|
+
counter: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", number & Brand<"Int"> & Brand<"NonNegative">, number, import("../Type.js").NonNegativeError, number & Brand<"Int">, import("../Type.js").IntError | import("../Type.js").NumberError>, "LessThanOrEqualTo65535", import("../Type.js").LessThanOrEqualToError<65535>, import("../Type.js").NonNegativeError | import("../Type.js").IntError | import("../Type.js").NumberError>, "Counter", import("../Type.js").BrandWithoutRefineError<"Counter", import("../Type.js").NonNegativeError | import("../Type.js").IntError | import("../Type.js").NumberError | import("../Type.js").LessThanOrEqualToError<65535>>, never>;
|
|
89
89
|
nodeId: import("../Type.js").BrandType<import("../Type.js").Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>, "NodeId", import("../Type.js").RegexError<"NodeId">, import("../Type.js").StringError>;
|
|
90
90
|
}>;
|
|
91
|
-
export
|
|
91
|
+
export interface Timestamp extends InferType<typeof Timestamp> {
|
|
92
|
+
}
|
|
93
|
+
/** Equality function for comparing {@link Timestamp}. */
|
|
94
|
+
export declare const eqTimestamp: import("../Eq.js").Eq<{
|
|
95
|
+
readonly millis: number & Brand<"Int"> & Brand<"NonNegative"> & Brand<`LessThanOrEqualTo${number}`> & Brand<"Millis">;
|
|
96
|
+
readonly counter: number & Brand<"Int"> & Brand<"NonNegative"> & Brand<"LessThanOrEqualTo65535"> & Brand<"Counter">;
|
|
97
|
+
readonly nodeId: string & Brand<"NodeId">;
|
|
98
|
+
}>;
|
|
92
99
|
export declare const createTimestamp: ({ millis, counter, nodeId, }?: Partial<Timestamp>) => Timestamp;
|
|
93
|
-
export declare const createInitialTimestamp: (deps:
|
|
94
|
-
/**
|
|
100
|
+
export declare const createInitialTimestamp: (deps: RandomBytesDep) => Timestamp;
|
|
101
|
+
/** Sortable string representation of {@link Timestamp}. */
|
|
95
102
|
export type TimestampString = string & Brand<"TimestampString">;
|
|
96
103
|
export declare const timestampToTimestampString: (t: Timestamp) => TimestampString;
|
|
97
104
|
export declare const timestampStringToTimestamp: (timestampString: TimestampString) => Timestamp;
|
|
98
105
|
export declare const sendTimestamp: (deps: TimeDep & TimestampConfigDep) => (timestamp: Timestamp) => Result<Timestamp, TimestampDriftError | TimestampCounterOverflowError | TimestampTimeOutOfRangeError>;
|
|
99
|
-
export declare const receiveTimestamp: (deps: TimeDep & TimestampConfigDep) => (local: Timestamp, remote: Timestamp) => Result<Timestamp, TimestampDriftError | TimestampCounterOverflowError |
|
|
100
|
-
/**
|
|
101
|
-
export
|
|
102
|
-
export
|
|
103
|
-
export declare const
|
|
104
|
-
export declare const
|
|
105
|
-
export declare const
|
|
106
|
+
export declare const receiveTimestamp: (deps: TimeDep & TimestampConfigDep) => (local: Timestamp, remote: Timestamp) => Result<Timestamp, TimestampDriftError | TimestampCounterOverflowError | TimestampTimeOutOfRangeError>;
|
|
107
|
+
/** Sortable bytes representation of {@link Timestamp}. */
|
|
108
|
+
export declare const TimestampBytes: import("../Type.js").BrandType<import("../Type.js").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("../Type.js").Uint8ArrayError, Uint8Array<ArrayBufferLike>, import("../Type.js").Uint8ArrayError>, "TimestampBytes", import("../Type.js").BrandWithoutRefineError<"TimestampBytes", import("../Type.js").Uint8ArrayError>, never>;
|
|
109
|
+
export type TimestampBytes = typeof TimestampBytes.Type;
|
|
110
|
+
export declare const timestampBytesLength: number & Brand<"Int"> & Brand<"NonNegative">;
|
|
111
|
+
export declare const timestampToTimestampBytes: (timestamp: Timestamp) => TimestampBytes;
|
|
112
|
+
export declare const timestampBytesToTimestamp: (timestamp: TimestampBytes) => Timestamp;
|
|
113
|
+
export declare const orderTimestampBytes: Order<TimestampBytes>;
|
|
106
114
|
//# sourceMappingURL=Timestamp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Timestamp.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Timestamp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Timestamp.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Timestamp.ts"],"names":[],"mappings":"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"}
|