@evolu/common 8.0.0-next.4 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/Array.d.ts +279 -173
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +105 -101
- package/dist/src/Assert.d.ts +44 -44
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +44 -32
- package/dist/src/BigInt.d.ts +6 -3
- package/dist/src/BigInt.d.ts.map +1 -1
- package/dist/src/BigInt.js +5 -2
- package/dist/src/Brand.d.ts +27 -40
- package/dist/src/Brand.d.ts.map +1 -1
- package/dist/src/Buffer.d.ts +27 -11
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Cache.d.ts +9 -4
- package/dist/src/Cache.d.ts.map +1 -1
- package/dist/src/Cache.js +8 -3
- package/dist/src/Callbacks.d.ts +30 -19
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Console.d.ts +145 -66
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +91 -43
- package/dist/src/Crypto.d.ts +85 -42
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +44 -20
- package/dist/src/Eq.d.ts +87 -21
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +67 -19
- package/dist/src/Error.d.ts +5 -3
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +16 -0
- package/dist/src/Function.d.ts +119 -58
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +86 -43
- package/dist/src/Http.d.ts +394 -0
- package/dist/src/Http.d.ts.map +1 -0
- package/dist/src/Http.js +102 -0
- package/dist/src/Identicon.d.ts +16 -7
- package/dist/src/Identicon.d.ts.map +1 -1
- package/dist/src/Identicon.js +14 -5
- package/dist/src/LeakDetector.d.ts +88 -0
- package/dist/src/LeakDetector.d.ts.map +1 -0
- package/dist/src/LeakDetector.js +86 -0
- package/dist/src/LockManager.d.ts +18 -9
- package/dist/src/LockManager.d.ts.map +1 -1
- package/dist/src/LockManager.js +7 -8
- package/dist/src/Lookup.d.ts +43 -13
- package/dist/src/Lookup.d.ts.map +1 -1
- package/dist/src/Lookup.js +28 -8
- package/dist/src/Microtask.d.ts +1 -1
- package/dist/src/Microtask.d.ts.map +1 -1
- package/dist/src/Microtask.js +3 -7
- package/dist/src/Number.d.ts +49 -13
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +34 -5
- package/dist/src/Object.d.ts +160 -40
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +92 -46
- package/dist/src/Option.d.ts +10 -7
- package/dist/src/Option.d.ts.map +1 -1
- package/dist/src/Option.js +9 -6
- package/dist/src/Order.d.ts +21 -21
- package/dist/src/Order.d.ts.map +1 -1
- package/dist/src/Order.js +18 -21
- package/dist/src/Platform.d.ts +31 -0
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +98 -0
- package/dist/src/Random.d.ts +32 -17
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +12 -8
- package/dist/src/Redacted.d.ts +43 -29
- package/dist/src/Redacted.d.ts.map +1 -1
- package/dist/src/Redacted.js +14 -3
- package/dist/src/Ref.d.ts +11 -3
- package/dist/src/Ref.d.ts.map +1 -1
- package/dist/src/Ref.js +2 -2
- package/dist/src/RefCount.d.ts +2 -6
- package/dist/src/RefCount.d.ts.map +1 -1
- package/dist/src/RefCount.js +33 -90
- package/dist/src/Relation.d.ts +70 -5
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Relation.js +77 -2
- package/dist/src/Resource.d.ts +590 -155
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Resource.js +592 -343
- package/dist/src/Result.d.ts +838 -191
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +163 -102
- package/dist/src/Schedule.d.ts +684 -231
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/Schedule.js +766 -295
- package/dist/src/Set.d.ts +89 -40
- package/dist/src/Set.d.ts.map +1 -1
- package/dist/src/Set.js +50 -29
- package/dist/src/Sqlite.d.ts +29 -72
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +41 -46
- package/dist/src/StackTrace.d.ts +40 -0
- package/dist/src/StackTrace.d.ts.map +1 -0
- package/dist/src/StackTrace.js +140 -0
- package/dist/src/Store.d.ts +5 -4
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/Store.js +5 -4
- package/dist/src/String.d.ts +7 -1
- package/dist/src/String.d.ts.map +1 -1
- package/dist/src/String.js +20 -7
- package/dist/src/Task.d.ts +3572 -1770
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1879 -1274
- package/dist/src/Test.d.ts +17 -125
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +17 -68
- package/dist/src/Time.d.ts +108 -49
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +172 -73
- package/dist/src/Type.d.ts +3542 -1926
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +3070 -1784
- package/dist/src/Types.d.ts +200 -108
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/Types.js +39 -8
- package/dist/src/WebSocket.d.ts +48 -23
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +15 -6
- package/dist/src/Worker.d.ts +94 -36
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +58 -24
- package/dist/src/index.d.ts +55 -52
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/intl/cs.d.ts +94 -0
- package/dist/src/intl/cs.d.ts.map +1 -0
- package/dist/src/intl/cs.js +220 -0
- package/dist/src/intl/index.d.ts +7 -0
- package/dist/src/intl/index.d.ts.map +1 -0
- package/dist/src/intl/index.js +6 -0
- package/dist/src/local-first/Db.d.ts +12 -8
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +109 -132
- package/dist/src/local-first/Error.d.ts +4 -4
- package/dist/src/local-first/Evolu.d.ts +338 -92
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +47 -55
- package/dist/src/local-first/LocalAuth.d.ts +4 -4
- package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
- package/dist/src/local-first/Owner.d.ts +61 -24
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +45 -8
- package/dist/src/local-first/Protocol.d.ts +44 -31
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +36 -13
- package/dist/src/local-first/Query.d.ts +147 -62
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Query.js +112 -58
- package/dist/src/local-first/Relay.d.ts +44 -14
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Schema.d.ts +92 -41
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +25 -8
- package/dist/src/local-first/Shared.d.ts +23 -21
- package/dist/src/local-first/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +100 -57
- package/dist/src/local-first/Storage.d.ts +53 -32
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +194 -234
- package/dist/src/local-first/Timestamp.d.ts +21 -21
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +2 -2
- package/dist/src/local-first/index.d.ts +11 -11
- package/package.json +14 -13
- package/src/Array.ts +306 -205
- package/src/Assert.ts +54 -69
- package/src/BigInt.ts +6 -3
- package/src/Brand.ts +27 -40
- package/src/Buffer.ts +28 -12
- package/src/Cache.ts +9 -4
- package/src/Callbacks.ts +30 -19
- package/src/Console.ts +156 -84
- package/src/Crypto.ts +83 -41
- package/src/Eq.ts +95 -22
- package/src/Error.ts +8 -4
- package/src/Function.ts +167 -59
- package/src/Http.ts +549 -0
- package/src/Identicon.ts +16 -7
- package/src/LeakDetector.ts +182 -0
- package/src/LockManager.ts +43 -39
- package/src/Lookup.ts +62 -28
- package/src/Microtask.ts +19 -23
- package/src/Number.ts +64 -12
- package/src/Object.ts +173 -49
- package/src/Option.ts +10 -7
- package/src/Order.ts +23 -21
- package/src/Platform.ts +136 -0
- package/src/Polyfills.ts +6 -12
- package/src/Random.ts +32 -19
- package/src/Redacted.ts +44 -30
- package/src/Ref.ts +14 -6
- package/src/RefCount.ts +38 -80
- package/src/Relation.ts +202 -10
- package/src/Resource.ts +1199 -591
- package/src/Result.ts +930 -271
- package/src/Schedule.ts +859 -343
- package/src/Set.ts +89 -40
- package/src/Sqlite.ts +144 -138
- package/src/StackTrace.ts +230 -0
- package/src/Store.ts +8 -7
- package/src/String.ts +22 -5
- package/src/Task.ts +5101 -2832
- package/src/Test.ts +20 -168
- package/src/Time.ts +293 -90
- package/src/Type.ts +10034 -4117
- package/src/Types.ts +227 -110
- package/src/WebSocket.ts +64 -36
- package/src/Worker.ts +180 -72
- package/src/index.ts +55 -52
- package/src/intl/cs.ts +388 -0
- package/src/intl/index.ts +7 -0
- package/src/local-first/Db.ts +152 -179
- package/src/local-first/Error.ts +4 -4
- package/src/local-first/Evolu.ts +495 -250
- package/src/local-first/LocalAuth.ts +6 -12
- package/src/local-first/Owner.ts +58 -21
- package/src/local-first/Protocol.ts +49 -31
- package/src/local-first/Query.ts +146 -61
- package/src/local-first/Relay.ts +51 -21
- package/src/local-first/Schema.ts +109 -51
- package/src/local-first/Shared.ts +266 -226
- package/src/local-first/Storage.ts +266 -264
- package/src/local-first/Timestamp.ts +25 -18
- package/src/local-first/index.ts +11 -11
- package/dist/src/Skiplist.d.ts +0 -28
- package/dist/src/Skiplist.d.ts.map +0 -1
- package/dist/src/Skiplist.js +0 -64
- package/dist/src/Tracer.d.ts +0 -48
- package/dist/src/Tracer.d.ts.map +0 -1
- package/dist/src/Tracer.js +0 -6
- package/src/Skiplist.ts +0 -108
- package/src/Tracer.ts +0 -54
|
@@ -56,39 +56,35 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
56
56
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
57
57
|
});
|
|
58
58
|
import { appendToArray, firstInArray, } from "../Array.js";
|
|
59
|
-
import { assert, assertNonEmptyReadonlyArray,
|
|
59
|
+
import { assert, assertNonEmptyReadonlyArray, assertNonNullable, } from "../Assert.js";
|
|
60
60
|
import { EncryptionKey, } from "../Crypto.js";
|
|
61
|
-
import {
|
|
61
|
+
import { constFalse, constVoid } from "../Function.js";
|
|
62
62
|
import { acquireLeaderLock } from "../LockManager.js";
|
|
63
|
-
import {
|
|
63
|
+
import { createMutableRecord, getOwnProp, objectToEntries } from "../Object.js";
|
|
64
64
|
import { ok } from "../Result.js";
|
|
65
65
|
import { booleanToSqliteBoolean, createSqlite, sql, SqliteBoolean, sqliteBooleanToBoolean, sqliteQueryStringToSqliteQuery, SqliteValue, } from "../Sqlite.js";
|
|
66
66
|
import { callback } from "../Task.js";
|
|
67
67
|
import { Millis, millisToDateIso } from "../Time.js";
|
|
68
|
-
import { Id, IdBytes, idBytesToId, idToIdBytes, onePositiveInt, } from "../Type.js";
|
|
68
|
+
import { assertType, Id, IdBytes, idBytesToId, idToIdBytes, onePositiveInt, } from "../Type.js";
|
|
69
69
|
import { ownerIdBytesToOwnerId, ownerIdToOwnerIdBytes } from "./Owner.js";
|
|
70
70
|
import { applyProtocolMessageAsClient, createProtocolMessageForSync, decryptAndDecodeDbChange, encodeAndEncryptDbChange, protocolVersion, SubscriptionFlags, } from "./Protocol.js";
|
|
71
71
|
import { ensureSqliteSchema, getEvoluSqliteSchema, systemColumns, } from "./Schema.js";
|
|
72
72
|
import { consoleEntryOrErrorBroadcastChannelName } from "./Shared.js";
|
|
73
73
|
import { createBaseSqliteStorage, createBaseSqliteStorageTables, DbChange, getTimestampInsertStrategy, readOwnerUsageOrDefault, updateOwnerUsage, } from "./Storage.js";
|
|
74
74
|
import { createInitialTimestamp, defaultTimestampMaxDrift, receiveTimestamp, sendTimestamp, TimestampBytes, timestampBytesToTimestamp, timestampToTimestampBytes, } from "./Timestamp.js";
|
|
75
|
+
/**
|
|
76
|
+
* Starts the platform-agnostic Evolu DbWorker and owns its resources until the
|
|
77
|
+
* worker receives a dispose message or its {@link Run} is aborted.
|
|
78
|
+
*/
|
|
75
79
|
export const startDbWorker = (self) => async (run) => {
|
|
76
80
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
77
81
|
try {
|
|
78
82
|
const disposer = __addDisposableResource(env_1, new AsyncDisposableStack(), true);
|
|
79
83
|
disposer.use(self);
|
|
80
|
-
const
|
|
81
|
-
const {
|
|
82
|
-
|
|
83
|
-
const initMessage = await dbWorkerRun.orThrow(callback(({ ok }) => {
|
|
84
|
-
self.onMessage = (message) => {
|
|
85
|
-
assert(!initialized, "DbWorker must be initialized only once");
|
|
86
|
-
initialized = true;
|
|
87
|
-
ok(message);
|
|
88
|
-
};
|
|
84
|
+
const { deps } = run;
|
|
85
|
+
const initMessage = await run.ok(callback(({ resolve }) => {
|
|
86
|
+
self.onMessage = (message) => resolve(ok(message));
|
|
89
87
|
}));
|
|
90
|
-
const console = deps.console.child(initMessage.name).child("DbWorker");
|
|
91
|
-
console.setLevel(initMessage.consoleLevel);
|
|
92
88
|
const port = disposer.use(deps.createMessagePort(initMessage.port));
|
|
93
89
|
const consoleEntryOrErrorBroadcastChannel = disposer.use(deps.createBroadcastChannel(consoleEntryOrErrorBroadcastChannelName));
|
|
94
90
|
disposer.defer(deps.consoleStoreOutputEntry.subscribe(() => {
|
|
@@ -99,19 +95,13 @@ export const startDbWorker = (self) => async (run) => {
|
|
|
99
95
|
entry,
|
|
100
96
|
});
|
|
101
97
|
}));
|
|
102
|
-
|
|
103
|
-
disposer.use(await
|
|
104
|
-
port.postMessage({ type: "LeaderAcquired", name: initMessage.name });
|
|
105
|
-
const sqlite = disposer.use(await dbWorkerRun.orThrow(createSqlite(initMessage.name, initMessage.memoryOnly
|
|
98
|
+
disposer.use(await run.ok(acquireLeaderLock(initMessage.name)));
|
|
99
|
+
const sqlite = disposer.use(await run.ok(createSqlite(initMessage.name, initMessage.memoryOnly
|
|
106
100
|
? { mode: "memory" }
|
|
107
101
|
: { mode: "encrypted", encryptionKey: initMessage.encryptionKey })));
|
|
108
|
-
|
|
109
|
-
const baseSqliteStorage = createBaseSqliteStorage({
|
|
110
|
-
sqlite,
|
|
111
|
-
...dbWorkerRun.deps,
|
|
112
|
-
});
|
|
102
|
+
const baseSqliteStorage = createBaseSqliteStorage({ sqlite, ...deps });
|
|
113
103
|
const dbDeps = {
|
|
114
|
-
...
|
|
104
|
+
...deps,
|
|
115
105
|
sqlite,
|
|
116
106
|
sqliteSchema: initMessage.sqliteSchema,
|
|
117
107
|
baseSqliteStorage,
|
|
@@ -134,117 +124,102 @@ export const startDbWorker = (self) => async (run) => {
|
|
|
134
124
|
});
|
|
135
125
|
},
|
|
136
126
|
});
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const { callbackId, request } = input;
|
|
147
|
-
const postQueuedResponse = (response) => {
|
|
148
|
-
port.postMessage({ type: "OnQueuedResponse", callbackId, response }, response.type === "ForEvolu" && response.message.type === "Export"
|
|
149
|
-
? [response.message.file.buffer]
|
|
150
|
-
: undefined);
|
|
151
|
-
};
|
|
152
|
-
switch (request.type) {
|
|
153
|
-
case "ForEvolu": {
|
|
154
|
-
switch (request.message.type) {
|
|
155
|
-
case "Mutate": {
|
|
156
|
-
const result = handleMutation({ ...dbDeps, clock })(request.message);
|
|
157
|
-
if (!result.ok) {
|
|
158
|
-
consoleEntryOrErrorBroadcastChannel.postMessage({
|
|
159
|
-
type: "Error",
|
|
160
|
-
error: result.error,
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
postQueuedResponse({
|
|
165
|
-
type: "ForEvolu",
|
|
166
|
-
id: request.id,
|
|
167
|
-
message: result.value,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
case "Query":
|
|
173
|
-
postQueuedResponse({
|
|
174
|
-
type: "ForEvolu",
|
|
175
|
-
id: request.id,
|
|
176
|
-
message: {
|
|
177
|
-
type: "Query",
|
|
178
|
-
rowsByQuery: loadQueries(dbDeps)(request.message.queries),
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
break;
|
|
182
|
-
case "Export":
|
|
183
|
-
postQueuedResponse({
|
|
184
|
-
type: "ForEvolu",
|
|
185
|
-
id: request.id,
|
|
186
|
-
message: {
|
|
187
|
-
type: "Export",
|
|
188
|
-
file: dbDeps.sqlite.export(),
|
|
189
|
-
},
|
|
190
|
-
});
|
|
191
|
-
break;
|
|
192
|
-
default:
|
|
193
|
-
exhaustiveCheck(request.message);
|
|
194
|
-
}
|
|
195
|
-
break;
|
|
127
|
+
const dbWorkerRun = disposer.use(run.create({ storage }));
|
|
128
|
+
port.postMessage({ type: "LeaderAcquired", name: initMessage.name });
|
|
129
|
+
await run.ok(callback(({ resolve }) => {
|
|
130
|
+
port.onMessage = (input) => {
|
|
131
|
+
if (input.type === "Dispose") {
|
|
132
|
+
resolve(ok());
|
|
133
|
+
return;
|
|
196
134
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
135
|
+
const { callbackId, request } = input;
|
|
136
|
+
const postQueuedResponse = (response) => {
|
|
137
|
+
port.postMessage({
|
|
138
|
+
type: "OnQueuedResponse",
|
|
139
|
+
callbackId,
|
|
140
|
+
response,
|
|
141
|
+
}, response.type === "ForEvolu" && response.message.type === "Export"
|
|
142
|
+
? [response.message.file.buffer]
|
|
143
|
+
: undefined);
|
|
144
|
+
};
|
|
145
|
+
if (request.type === "ForSharedWorker") {
|
|
146
|
+
if (request.message.type === "ApplySyncMessage") {
|
|
147
|
+
const { owner, inputMessage } = request.message;
|
|
148
|
+
void dbWorkerRun(async (run) => {
|
|
149
|
+
storage.setRequestContext(owner.encryptionKey);
|
|
150
|
+
const result = await run.abortable(applyProtocolMessageAsClient(inputMessage, {
|
|
151
|
+
writeKey: owner.writeKey,
|
|
152
|
+
}));
|
|
209
153
|
postQueuedResponse({
|
|
210
154
|
type: "ForSharedWorker",
|
|
211
155
|
message: {
|
|
212
|
-
type: "
|
|
213
|
-
|
|
156
|
+
type: "ApplySyncMessage",
|
|
157
|
+
ownerId: owner.id,
|
|
158
|
+
didWriteMessages: storage.didWriteMessages(),
|
|
159
|
+
result,
|
|
214
160
|
},
|
|
215
161
|
});
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const { owner, inputMessage } = request.message;
|
|
220
|
-
dbWorkerRunWithStorage(async (run) => {
|
|
221
|
-
storage.setRequestContext(owner.encryptionKey);
|
|
222
|
-
const result = await run(applyProtocolMessageAsClient(inputMessage, {
|
|
223
|
-
writeKey: owner.writeKey,
|
|
224
|
-
}));
|
|
225
|
-
const didWriteMessages = storage.didWriteMessages();
|
|
226
|
-
postQueuedResponse({
|
|
227
|
-
type: "ForSharedWorker",
|
|
228
|
-
message: {
|
|
229
|
-
type: "ApplySyncMessage",
|
|
230
|
-
ownerId: owner.id,
|
|
231
|
-
didWriteMessages,
|
|
232
|
-
result,
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
return ok();
|
|
236
|
-
});
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
default:
|
|
240
|
-
exhaustiveCheck(request.message);
|
|
162
|
+
return ok();
|
|
163
|
+
});
|
|
164
|
+
return;
|
|
241
165
|
}
|
|
242
|
-
|
|
166
|
+
const protocolMessagesByOwnerId = new Map();
|
|
167
|
+
for (const owner of request.message.owners) {
|
|
168
|
+
storage.setRequestContext(owner.encryptionKey);
|
|
169
|
+
protocolMessagesByOwnerId.set(owner.id, createProtocolMessageForSync({
|
|
170
|
+
storage,
|
|
171
|
+
console: deps.console,
|
|
172
|
+
})(owner.id, SubscriptionFlags.Subscribe));
|
|
173
|
+
}
|
|
174
|
+
postQueuedResponse({
|
|
175
|
+
type: "ForSharedWorker",
|
|
176
|
+
message: {
|
|
177
|
+
type: "CreateSyncMessages",
|
|
178
|
+
protocolMessagesByOwnerId,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
243
182
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
183
|
+
if (request.message.type === "Query") {
|
|
184
|
+
postQueuedResponse({
|
|
185
|
+
type: "ForEvolu",
|
|
186
|
+
id: request.id,
|
|
187
|
+
message: {
|
|
188
|
+
type: "Query",
|
|
189
|
+
rowsByQuery: loadQueries(dbDeps)(request.message.queries),
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (request.message.type === "Export") {
|
|
195
|
+
postQueuedResponse({
|
|
196
|
+
type: "ForEvolu",
|
|
197
|
+
id: request.id,
|
|
198
|
+
message: {
|
|
199
|
+
type: "Export",
|
|
200
|
+
file: sqlite.export(),
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const result = handleMutation({ ...dbDeps, clock })(request.message);
|
|
206
|
+
if (!result.ok) {
|
|
207
|
+
consoleEntryOrErrorBroadcastChannel.postMessage({
|
|
208
|
+
type: "Error",
|
|
209
|
+
error: result.error,
|
|
210
|
+
});
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
postQueuedResponse({
|
|
214
|
+
type: "ForEvolu",
|
|
215
|
+
id: request.id,
|
|
216
|
+
message: result.value,
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
return () => {
|
|
220
|
+
port.onMessage = null;
|
|
221
|
+
};
|
|
222
|
+
}));
|
|
248
223
|
return ok();
|
|
249
224
|
}
|
|
250
225
|
catch (e_1) {
|
|
@@ -393,7 +368,7 @@ const tryApplyQuarantinedMessages = (deps) => {
|
|
|
393
368
|
}
|
|
394
369
|
};
|
|
395
370
|
const validateColumnValue = (deps) => (table, column, _value) => {
|
|
396
|
-
const schemaColumns =
|
|
371
|
+
const schemaColumns = getOwnProp(deps.sqliteSchema.tables, table);
|
|
397
372
|
return (schemaColumns != null &&
|
|
398
373
|
(systemColumnsWithoutOwnerId.has(column) || schemaColumns.has(column)));
|
|
399
374
|
};
|
|
@@ -454,8 +429,8 @@ const createClientStorage = (deps) => ({ onError, }) => {
|
|
|
454
429
|
},
|
|
455
430
|
didWriteMessages: () => didWriteMessages,
|
|
456
431
|
// Not implemented yet.
|
|
457
|
-
validateWriteKey:
|
|
458
|
-
setWriteKey:
|
|
432
|
+
validateWriteKey: constFalse,
|
|
433
|
+
setWriteKey: constVoid,
|
|
459
434
|
writeMessages: (ownerIdBytes, encryptedMessages) => () => {
|
|
460
435
|
// TODO: Add quota checking for collaborative scenarios.
|
|
461
436
|
// When receiving messages from other owners via relay broadcast,
|
|
@@ -502,7 +477,7 @@ const createClientStorage = (deps) => ({ onError, }) => {
|
|
|
502
477
|
const { rows } = result;
|
|
503
478
|
assertNonEmptyReadonlyArray(rows, "Every timestamp must have rows");
|
|
504
479
|
const firstRow = firstInArray(rows);
|
|
505
|
-
const values =
|
|
480
|
+
const values = createMutableRecord();
|
|
506
481
|
let isInsert = false;
|
|
507
482
|
let isDelete = null;
|
|
508
483
|
for (const r of rows) {
|
|
@@ -582,6 +557,7 @@ const applyLocalOnlyChange = (deps) => (change) => {
|
|
|
582
557
|
const ownerId = change.ownerId;
|
|
583
558
|
const columns = dbChangeToColumns(change, deps.time.now());
|
|
584
559
|
for (const [column, value] of columns) {
|
|
560
|
+
assertNonNullable(value);
|
|
585
561
|
deps.sqlite.exec(sql.prepared `
|
|
586
562
|
insert into ${sql.identifier(change.table)}
|
|
587
563
|
("ownerId", "id", ${sql.identifier(column)})
|
|
@@ -601,6 +577,7 @@ const applyMessages = (deps) => (ownerId, messages) => {
|
|
|
601
577
|
const idBytes = idToIdBytes(change.id);
|
|
602
578
|
const timestampBytes = timestampToTimestampBytes(timestamp);
|
|
603
579
|
for (const [column, value] of columns) {
|
|
580
|
+
assertNonNullable(value);
|
|
604
581
|
if (validateColumnValue(deps)(change.table, column, value)) {
|
|
605
582
|
applyColumnChange(deps)(ownerIdBytes, ownerId, change.table, idBytes, change.id, column, value, timestampBytes);
|
|
606
583
|
}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { DecryptWithXChaCha20Poly1305Error } from "../Crypto.
|
|
7
|
-
import type { UnknownError } from "../Error.
|
|
8
|
-
import type { ProtocolError } from "./Protocol.
|
|
9
|
-
import type { TimestampError } from "./Timestamp.
|
|
6
|
+
import type { DecryptWithXChaCha20Poly1305Error } from "../Crypto.ts";
|
|
7
|
+
import type { UnknownError } from "../Error.ts";
|
|
8
|
+
import type { ProtocolError } from "./Protocol.ts";
|
|
9
|
+
import type { TimestampError } from "./Timestamp.ts";
|
|
10
10
|
/** Represents errors that can occur in Evolu. */
|
|
11
11
|
export type EvoluError = DecryptWithXChaCha20Poly1305Error | ProtocolError | TimestampError | UnknownError;
|
|
12
12
|
//# sourceMappingURL=Error.d.ts.map
|