@evolu/common 7.4.1 → 8.0.0-next.1
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 +4 -61
- package/dist/src/Array.d.ts +343 -102
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +181 -85
- package/dist/src/Assert.d.ts +57 -11
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +47 -11
- package/dist/src/BigInt.d.ts +6 -1
- package/dist/src/BigInt.d.ts.map +1 -1
- package/dist/src/BigInt.js +5 -0
- package/dist/src/Brand.d.ts +40 -12
- package/dist/src/Brand.d.ts.map +1 -1
- package/dist/src/Brand.js +5 -0
- package/dist/src/Buffer.d.ts +6 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +7 -2
- package/dist/src/Cache.d.ts +10 -2
- package/dist/src/Cache.d.ts.map +1 -1
- package/dist/src/Cache.js +6 -0
- package/dist/src/Callbacks.d.ts +10 -7
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Callbacks.js +23 -13
- package/dist/src/Console.d.ts +361 -69
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +217 -117
- package/dist/src/Crypto.d.ts +70 -21
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +72 -27
- package/dist/src/Eq.d.ts +22 -2
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +21 -1
- package/dist/src/Error.d.ts +23 -12
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +27 -11
- package/dist/src/Function.d.ts +128 -56
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +118 -14
- package/dist/src/Identicon.d.ts +5 -0
- package/dist/src/Identicon.d.ts.map +1 -1
- package/dist/src/Identicon.js +6 -1
- package/dist/src/Lookup.d.ts +162 -0
- package/dist/src/Lookup.d.ts.map +1 -0
- package/dist/src/Lookup.js +200 -0
- package/dist/src/Microtask.d.ts +21 -0
- package/dist/src/Microtask.d.ts.map +1 -0
- package/dist/src/Microtask.js +37 -0
- package/dist/src/Number.d.ts +18 -4
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +23 -1
- package/dist/src/Object.d.ts +110 -5
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +108 -5
- package/dist/src/Option.d.ts +58 -0
- package/dist/src/Option.d.ts.map +1 -0
- package/dist/src/Option.js +43 -0
- package/dist/src/Order.d.ts +5 -0
- package/dist/src/Order.d.ts.map +1 -1
- package/dist/src/Order.js +8 -3
- package/dist/src/Platform.d.ts +36 -2
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +10 -6
- package/dist/src/Polyfills.d.ts +29 -0
- package/dist/src/Polyfills.d.ts.map +1 -0
- package/dist/src/Polyfills.js +329 -0
- package/dist/src/Random.d.ts +18 -7
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +9 -7
- package/dist/src/Redacted.d.ts +7 -4
- package/dist/src/Redacted.d.ts.map +1 -1
- package/dist/src/Redacted.js +5 -0
- package/dist/src/Ref.d.ts +31 -16
- package/dist/src/Ref.d.ts.map +1 -1
- package/dist/src/Ref.js +35 -7
- package/dist/src/RefCount.d.ts +62 -0
- package/dist/src/RefCount.d.ts.map +1 -0
- package/dist/src/RefCount.js +83 -0
- package/dist/src/Relation.d.ts +84 -29
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Relation.js +83 -105
- package/dist/src/Resource.d.ts +263 -0
- package/dist/src/Resource.d.ts.map +1 -0
- package/dist/src/Resource.js +389 -0
- package/dist/src/Result.d.ts +390 -374
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +142 -70
- package/dist/src/Schedule.d.ts +953 -0
- package/dist/src/Schedule.d.ts.map +1 -0
- package/dist/src/Schedule.js +1199 -0
- package/dist/src/Set.d.ts +181 -0
- package/dist/src/Set.d.ts.map +1 -0
- package/dist/src/Set.js +137 -0
- package/dist/src/Skiplist.d.ts +6 -1
- package/dist/src/Skiplist.d.ts.map +1 -1
- package/dist/src/Skiplist.js +5 -0
- package/dist/src/Sqlite.d.ts +160 -60
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +290 -190
- package/dist/src/Store.d.ts +36 -28
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/Store.js +55 -15
- package/dist/src/String.d.ts +5 -0
- package/dist/src/String.d.ts.map +1 -1
- package/dist/src/String.js +5 -0
- package/dist/src/Task.d.ts +2274 -423
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1499 -348
- package/dist/src/Test.d.ts +150 -0
- package/dist/src/Test.d.ts.map +1 -0
- package/dist/src/Test.js +97 -0
- package/dist/src/Time.d.ts +202 -48
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +199 -88
- package/dist/src/Tracer.d.ts +48 -0
- package/dist/src/Tracer.d.ts.map +1 -0
- package/dist/src/Tracer.js +6 -0
- package/dist/src/Type.d.ts +587 -209
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +370 -240
- package/dist/src/Types.d.ts +160 -6
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/Types.js +22 -2
- package/dist/src/WebSocket.d.ts +130 -58
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +274 -113
- package/dist/src/Worker.d.ts +245 -60
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +220 -64
- package/dist/src/index.d.ts +25 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +19 -3
- package/dist/src/local-first/Db.d.ts +24 -213
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +621 -293
- package/dist/src/local-first/Error.d.ts +12 -0
- package/dist/src/local-first/Error.d.ts.map +1 -0
- package/dist/src/local-first/Error.js +6 -0
- package/dist/src/local-first/Evolu.d.ts +330 -285
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +472 -402
- package/dist/src/local-first/LocalAuth.d.ts +10 -10
- package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
- package/dist/src/local-first/LocalAuth.js +6 -1
- package/dist/src/local-first/Owner.d.ts +70 -27
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +27 -14
- package/dist/src/local-first/Protocol.d.ts +58 -50
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +253 -155
- package/dist/src/local-first/Query.d.ts +133 -43
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Query.js +139 -90
- package/dist/src/local-first/Relay.d.ts +34 -49
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Relay.js +59 -177
- package/dist/src/local-first/Schema.d.ts +139 -144
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +78 -163
- package/dist/src/local-first/Shared.d.ts +125 -0
- package/dist/src/local-first/Shared.d.ts.map +1 -0
- package/dist/src/local-first/Shared.js +569 -0
- package/dist/src/local-first/Storage.d.ts +54 -58
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +127 -179
- package/dist/src/local-first/Timestamp.d.ts +28 -35
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +24 -25
- package/dist/src/local-first/index.d.ts +2 -15
- package/dist/src/local-first/index.d.ts.map +1 -1
- package/dist/src/local-first/index.js +2 -15
- package/package.json +37 -24
- package/src/Array.ts +467 -106
- package/src/Assert.ts +87 -12
- package/src/BigInt.ts +7 -1
- package/src/Brand.ts +41 -12
- package/src/Buffer.ts +10 -4
- package/src/Cache.ts +11 -2
- package/src/Callbacks.ts +33 -23
- package/src/Console.ts +567 -178
- package/src/Crypto.ts +111 -62
- package/src/Eq.ts +30 -3
- package/src/Error.ts +50 -34
- package/src/Function.ts +140 -68
- package/src/Identicon.ts +7 -1
- package/src/Lookup.ts +429 -0
- package/src/Microtask.ts +58 -0
- package/src/Number.ts +40 -7
- package/src/Object.ts +155 -16
- package/src/Option.ts +74 -0
- package/src/Order.ts +11 -3
- package/src/Platform.ts +43 -7
- package/src/Polyfills.ts +520 -0
- package/src/Random.ts +25 -11
- package/src/Redacted.ts +8 -4
- package/src/Ref.ts +72 -21
- package/src/RefCount.ts +170 -0
- package/src/Relation.ts +188 -136
- package/src/Resource.ts +864 -0
- package/src/Result.ts +548 -381
- package/src/Schedule.ts +1471 -0
- package/src/Set.ts +247 -0
- package/src/Skiplist.ts +7 -1
- package/src/Sqlite.ts +409 -304
- package/src/Store.ts +94 -48
- package/src/String.ts +6 -0
- package/src/Task.ts +3696 -740
- package/src/Test.ts +202 -0
- package/src/Time.ts +357 -147
- package/src/Tracer.ts +54 -0
- package/src/Type.ts +866 -430
- package/src/Types.ts +202 -7
- package/src/WebSocket.ts +404 -167
- package/src/Worker.ts +527 -147
- package/src/index.ts +74 -3
- package/src/local-first/Db.ts +867 -597
- package/src/local-first/Error.ts +17 -0
- package/src/local-first/Evolu.ts +884 -824
- package/src/local-first/LocalAuth.ts +10 -10
- package/src/local-first/Owner.ts +94 -42
- package/src/local-first/Protocol.ts +441 -307
- package/src/local-first/Query.ts +243 -194
- package/src/local-first/Relay.ts +119 -273
- package/src/local-first/Schema.ts +284 -394
- package/src/local-first/Shared.ts +932 -0
- package/src/local-first/Storage.ts +211 -283
- package/src/local-first/Timestamp.ts +38 -45
- package/src/local-first/index.ts +2 -16
- package/dist/src/Instances.d.ts +0 -34
- package/dist/src/Instances.d.ts.map +0 -1
- package/dist/src/Instances.js +0 -44
- package/dist/src/Resources.d.ts +0 -118
- package/dist/src/Resources.d.ts.map +0 -1
- package/dist/src/Resources.js +0 -197
- package/dist/src/local-first/Platform.d.ts +0 -25
- package/dist/src/local-first/Platform.d.ts.map +0 -1
- package/dist/src/local-first/Platform.js +0 -1
- package/dist/src/local-first/Public.d.ts +0 -22
- package/dist/src/local-first/Public.d.ts.map +0 -1
- package/dist/src/local-first/Public.js +0 -15
- package/dist/src/local-first/PublicKysely.d.ts +0 -148
- package/dist/src/local-first/PublicKysely.d.ts.map +0 -1
- package/dist/src/local-first/PublicKysely.js +0 -184
- package/dist/src/local-first/Sync.d.ts +0 -112
- package/dist/src/local-first/Sync.d.ts.map +0 -1
- package/dist/src/local-first/Sync.js +0 -526
- package/src/Instances.ts +0 -92
- package/src/Resources.ts +0 -367
- package/src/local-first/Platform.ts +0 -27
- package/src/local-first/Public.ts +0 -42
- package/src/local-first/PublicKysely.ts +0 -239
- package/src/local-first/Sync.ts +0 -949
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Relay server for data synchronization.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { dedupeArray, filterArray, firstInArray, isNonEmptyArray, mapArray, } from "../Array.js";
|
|
7
|
+
import { assert } from "../Assert.js";
|
|
3
8
|
import { err, ok } from "../Result.js";
|
|
4
9
|
import { sql } from "../Sqlite.js";
|
|
5
|
-
import {
|
|
6
|
-
import { PositiveInt } from "../Type.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
10
|
+
import { createMutexByKey } from "../Task.js";
|
|
11
|
+
import { Name, PositiveInt, uint8ArrayToBase64Url } from "../Type.js";
|
|
12
|
+
import { isPromiseLike } from "../Types.js";
|
|
13
|
+
import { OwnerId, ownerIdBytesToOwnerId,
|
|
14
|
+
// OwnerTransport,
|
|
15
|
+
OwnerWriteKey, } from "./Owner.js";
|
|
16
|
+
import { createBaseSqliteStorage, getTimestampInsertStrategy, readOwnerUsageOrDefault, updateOwnerUsage, } from "./Storage.js";
|
|
9
17
|
import { timestampToTimestampBytes } from "./Timestamp.js";
|
|
10
18
|
export const createRelaySqliteStorage = (deps) => (config) => {
|
|
11
|
-
const sqliteStorageBase = createBaseSqliteStorage(deps)
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
* the same owner. Instances are never evicted, causing a memory leak
|
|
15
|
-
* proportional to unique owner count. However, per-instance overhead should
|
|
16
|
-
* be small. Monitor production memory usage to determine if
|
|
17
|
-
* eviction/cleanup is needed.
|
|
18
|
-
*/
|
|
19
|
-
const ownerMutexes = createInstances();
|
|
19
|
+
const sqliteStorageBase = createBaseSqliteStorage(deps);
|
|
20
|
+
/** Mutex keyed by OwnerId to prevent concurrent writes. */
|
|
21
|
+
const mutexByOwnerId = createMutexByKey();
|
|
20
22
|
return {
|
|
21
23
|
...sqliteStorageBase,
|
|
22
24
|
/**
|
|
@@ -34,100 +36,69 @@ export const createRelaySqliteStorage = (deps) => (config) => {
|
|
|
34
36
|
from evolu_writeKey
|
|
35
37
|
where ownerId = ${ownerId};
|
|
36
38
|
`);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
const { rows } = selectWriteKey.value;
|
|
42
|
-
if (isNonEmptyReadonlyArray(rows)) {
|
|
39
|
+
const { rows } = selectWriteKey;
|
|
40
|
+
if (isNonEmptyArray(rows)) {
|
|
43
41
|
return deps.timingSafeEqual(rows[0].writeKey, writeKey);
|
|
44
42
|
}
|
|
45
|
-
|
|
43
|
+
deps.sqlite.exec(sql `
|
|
46
44
|
insert into evolu_writeKey (ownerId, writeKey)
|
|
47
45
|
values (${ownerId}, ${writeKey});
|
|
48
46
|
`);
|
|
49
|
-
if (!insertWriteKey.ok) {
|
|
50
|
-
config.onStorageError(insertWriteKey.error);
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
47
|
return true;
|
|
54
48
|
},
|
|
55
49
|
setWriteKey: (ownerId, writeKey) => {
|
|
56
|
-
|
|
50
|
+
deps.sqlite.exec(sql `
|
|
57
51
|
insert into evolu_writeKey (ownerId, writeKey)
|
|
58
52
|
values (${ownerId}, ${writeKey})
|
|
59
53
|
on conflict (ownerId) do update
|
|
60
54
|
set writeKey = excluded.writeKey;
|
|
61
55
|
`);
|
|
62
|
-
if (!upsertWriteKey.ok) {
|
|
63
|
-
config.onStorageError(upsertWriteKey.error);
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
56
|
},
|
|
68
|
-
writeMessages:
|
|
57
|
+
writeMessages: (ownerIdBytes, messages) => async (run) => {
|
|
69
58
|
const ownerId = ownerIdBytesToOwnerId(ownerIdBytes);
|
|
70
|
-
const
|
|
59
|
+
const uniqueMessagesWithTimestampBytes = dedupeArray(mapArray(messages, (m) => ({
|
|
71
60
|
timestamp: timestampToTimestampBytes(m.timestamp),
|
|
72
61
|
change: m.change,
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
.
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
if (!existingTimestampsResult.ok)
|
|
79
|
-
return existingTimestampsResult;
|
|
80
|
-
const existingTimestampsSet = new Set(existingTimestampsResult.value.map((t) => t.toString()));
|
|
81
|
-
const newMessages = filterArray(messagesWithTimestampBytes, (m) => !existingTimestampsSet.has(m.timestamp.toString()));
|
|
62
|
+
})), (message) => uint8ArrayToBase64Url(message.timestamp));
|
|
63
|
+
return run(mutexByOwnerId.withLock(ownerId, async () => {
|
|
64
|
+
const existingTimestampsResult = sqliteStorageBase.getExistingTimestamps(ownerIdBytes, mapArray(uniqueMessagesWithTimestampBytes, (m) => m.timestamp));
|
|
65
|
+
const existingTimestampKeys = new Set(mapArray(existingTimestampsResult, uint8ArrayToBase64Url));
|
|
66
|
+
const newMessages = filterArray(uniqueMessagesWithTimestampBytes, (message) => !existingTimestampKeys.has(uint8ArrayToBase64Url(message.timestamp)));
|
|
82
67
|
// Nothing to write
|
|
83
|
-
if (!
|
|
68
|
+
if (!isNonEmptyArray(newMessages)) {
|
|
84
69
|
return ok();
|
|
85
70
|
}
|
|
86
|
-
const usage =
|
|
87
|
-
if (!usage.ok)
|
|
88
|
-
return usage;
|
|
89
|
-
const { storedBytes } = usage.value;
|
|
71
|
+
const usage = readOwnerUsageOrDefault(deps)(ownerIdBytes, firstInArray(newMessages).timestamp);
|
|
90
72
|
const incomingBytes = newMessages.reduce((sum, m) => sum + m.change.length, 0);
|
|
91
|
-
const newStoredBytes = PositiveInt.orThrow((storedBytes ?? 0) + incomingBytes);
|
|
92
|
-
const
|
|
93
|
-
const isWithinQuota =
|
|
73
|
+
const newStoredBytes = PositiveInt.orThrow((usage.storedBytes ?? 0) + incomingBytes);
|
|
74
|
+
const quotaResult = config.isOwnerWithinQuota(ownerId, newStoredBytes);
|
|
75
|
+
const isWithinQuota = isPromiseLike(quotaResult)
|
|
76
|
+
? await quotaResult
|
|
77
|
+
: quotaResult;
|
|
94
78
|
if (!isWithinQuota) {
|
|
95
|
-
return err({
|
|
79
|
+
return err({
|
|
80
|
+
type: "StorageQuotaError",
|
|
81
|
+
ownerId,
|
|
82
|
+
});
|
|
96
83
|
}
|
|
97
|
-
let { firstTimestamp, lastTimestamp } = usage
|
|
84
|
+
let { firstTimestamp, lastTimestamp } = usage;
|
|
98
85
|
return deps.sqlite.transaction(() => {
|
|
99
86
|
for (const { timestamp, change } of newMessages) {
|
|
100
87
|
let strategy;
|
|
101
88
|
[strategy, firstTimestamp, lastTimestamp] =
|
|
102
89
|
getTimestampInsertStrategy(timestamp, firstTimestamp, lastTimestamp);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
insert into evolu_message ("ownerId", "timestamp", "change")
|
|
111
|
-
values (${ownerIdBytes}, ${timestamp}, ${change})
|
|
112
|
-
on conflict do nothing;
|
|
113
|
-
`);
|
|
114
|
-
if (!result.ok)
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
90
|
+
sqliteStorageBase.insertTimestamp(ownerIdBytes, timestamp, strategy);
|
|
91
|
+
deps.sqlite.exec(sql `
|
|
92
|
+
insert into evolu_message
|
|
93
|
+
("ownerId", "timestamp", "change")
|
|
94
|
+
values (${ownerIdBytes}, ${timestamp}, ${change})
|
|
95
|
+
on conflict do nothing;
|
|
96
|
+
`);
|
|
117
97
|
}
|
|
118
|
-
|
|
98
|
+
updateOwnerUsage(deps)(ownerIdBytes, newStoredBytes, firstTimestamp, lastTimestamp);
|
|
99
|
+
return ok();
|
|
119
100
|
});
|
|
120
|
-
})
|
|
121
|
-
if (!result.ok && result.error.type !== "AbortError") {
|
|
122
|
-
switch (result.error.type) {
|
|
123
|
-
case "SqliteError":
|
|
124
|
-
config.onStorageError(result.error);
|
|
125
|
-
return err({ type: "StorageWriteError", ownerId });
|
|
126
|
-
case "StorageQuotaError":
|
|
127
|
-
return err({ type: "StorageQuotaError", ownerId });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return ok();
|
|
101
|
+
}));
|
|
131
102
|
},
|
|
132
103
|
readDbChange: (ownerId, timestamp) => {
|
|
133
104
|
const result = deps.sqlite.exec(sql `
|
|
@@ -135,40 +106,24 @@ export const createRelaySqliteStorage = (deps) => (config) => {
|
|
|
135
106
|
from evolu_message
|
|
136
107
|
where "ownerId" = ${ownerId} and "timestamp" = ${timestamp};
|
|
137
108
|
`);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
return result.value.rows[0]?.change;
|
|
109
|
+
const row = result.rows[0];
|
|
110
|
+
assert(row, "Every timestamp must have a change");
|
|
111
|
+
return row.change;
|
|
143
112
|
},
|
|
144
113
|
deleteOwner: (ownerId) => {
|
|
145
|
-
|
|
146
|
-
|
|
114
|
+
deps.sqlite.transaction(() => {
|
|
115
|
+
deps.sqlite.exec(sql `
|
|
147
116
|
delete from evolu_writeKey where ownerId = ${ownerId};
|
|
148
117
|
`);
|
|
149
|
-
|
|
150
|
-
return deleteWriteKey;
|
|
151
|
-
const deleteMessages = deps.sqlite.exec(sql `
|
|
118
|
+
deps.sqlite.exec(sql `
|
|
152
119
|
delete from evolu_message where ownerId = ${ownerId};
|
|
153
120
|
`);
|
|
154
|
-
|
|
155
|
-
return deleteMessages;
|
|
156
|
-
const deleteUsage = deps.sqlite.exec(sql `
|
|
121
|
+
deps.sqlite.exec(sql `
|
|
157
122
|
delete from evolu_usage where ownerId = ${ownerId};
|
|
158
123
|
`);
|
|
159
|
-
|
|
160
|
-
return deleteUsage;
|
|
161
|
-
const deleteBaseOwner = sqliteStorageBase.deleteOwner(ownerId);
|
|
162
|
-
if (!deleteBaseOwner)
|
|
163
|
-
return err(null);
|
|
124
|
+
sqliteStorageBase.deleteOwner(ownerId);
|
|
164
125
|
return ok();
|
|
165
126
|
});
|
|
166
|
-
if (!transactionResult.ok) {
|
|
167
|
-
if (transactionResult.error)
|
|
168
|
-
config.onStorageError(transactionResult.error);
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
return true;
|
|
172
127
|
},
|
|
173
128
|
};
|
|
174
129
|
};
|
|
@@ -192,79 +147,6 @@ export const createRelayStorageTables = (deps) => {
|
|
|
192
147
|
strict;
|
|
193
148
|
`,
|
|
194
149
|
]) {
|
|
195
|
-
|
|
196
|
-
if (!result.ok)
|
|
197
|
-
return result;
|
|
150
|
+
deps.sqlite.exec(query);
|
|
198
151
|
}
|
|
199
|
-
return ok();
|
|
200
152
|
};
|
|
201
|
-
export const createRelayLogger = (deps) => ({
|
|
202
|
-
started: (enableLogging, port) => {
|
|
203
|
-
deps.console.enabled = true;
|
|
204
|
-
deps.console.log(`Evolu Relay started on port ${port}`);
|
|
205
|
-
deps.console.enabled = enableLogging;
|
|
206
|
-
},
|
|
207
|
-
storageError: (error) => {
|
|
208
|
-
deps.console.error("[relay]", "storage", error);
|
|
209
|
-
},
|
|
210
|
-
upgradeSocketError: (error) => {
|
|
211
|
-
deps.console.warn("[relay]", "socket error", { error });
|
|
212
|
-
},
|
|
213
|
-
invalidOrMissingOwnerIdInUrl: (url) => {
|
|
214
|
-
deps.console.warn("[relay]", "invalid or missing ownerId in URL", { url });
|
|
215
|
-
},
|
|
216
|
-
unauthorizedOwner: (ownerId) => {
|
|
217
|
-
deps.console.warn("[relay]", "unauthorized owner", { ownerId });
|
|
218
|
-
},
|
|
219
|
-
connectionEstablished: (totalConnectionCount) => {
|
|
220
|
-
deps.console.log("[relay]", "connection", { totalConnectionCount });
|
|
221
|
-
},
|
|
222
|
-
connectionWebSocketError: (error) => {
|
|
223
|
-
deps.console.error("[relay]", "error", { error });
|
|
224
|
-
},
|
|
225
|
-
relayOptionSubscribe: (ownerId, getSubscriberCount) => {
|
|
226
|
-
if (deps.console.enabled)
|
|
227
|
-
deps.console.log("[relay]", "subscribe", {
|
|
228
|
-
ownerId,
|
|
229
|
-
subscriberCount: getSubscriberCount(),
|
|
230
|
-
});
|
|
231
|
-
},
|
|
232
|
-
relayOptionUnsubscribe: (ownerId, getSubscriberCount) => {
|
|
233
|
-
if (deps.console.enabled)
|
|
234
|
-
deps.console.log("[relay]", "unsubscribe", {
|
|
235
|
-
ownerId,
|
|
236
|
-
subscriberCount: getSubscriberCount(),
|
|
237
|
-
});
|
|
238
|
-
},
|
|
239
|
-
relayOptionBroadcast: (ownerId, broadcastCount, totalSubscribers) => {
|
|
240
|
-
deps.console.log("[relay]", "broadcast", {
|
|
241
|
-
ownerId,
|
|
242
|
-
broadcastCount,
|
|
243
|
-
totalSubscribers,
|
|
244
|
-
});
|
|
245
|
-
},
|
|
246
|
-
messageLength: (messageLength) => {
|
|
247
|
-
deps.console.log("[relay]", "on message", { messageLength });
|
|
248
|
-
},
|
|
249
|
-
applyProtocolMessageAsRelayError: (error) => {
|
|
250
|
-
deps.console.error("[relay]", "applyProtocolMessageAsRelay", error);
|
|
251
|
-
},
|
|
252
|
-
responseLength: (responseLength) => {
|
|
253
|
-
deps.console.log("[relay]", "responseLength", { responseLength });
|
|
254
|
-
},
|
|
255
|
-
applyProtocolMessageAsRelayUnknownError: (error) => {
|
|
256
|
-
deps.console.error("[relay]", "applyProtocolMessageAsRelayUnknownError", error);
|
|
257
|
-
},
|
|
258
|
-
connectionClosed: (totalConnectionCount) => {
|
|
259
|
-
deps.console.log("[relay]", "close", { totalConnectionCount });
|
|
260
|
-
},
|
|
261
|
-
shuttingDown: () => {
|
|
262
|
-
deps.console.log("Shutting down Evolu Relay...");
|
|
263
|
-
},
|
|
264
|
-
webSocketServerDisposed: () => {
|
|
265
|
-
deps.console.log("Evolu Relay WebSocketServer disposed");
|
|
266
|
-
},
|
|
267
|
-
httpServerDisposed: () => {
|
|
268
|
-
deps.console.log("Evolu Relay HTTP server disposed");
|
|
269
|
-
},
|
|
270
|
-
});
|