@evolu/common 8.0.0-next.5 → 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 +39 -44
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +38 -31
- 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 +3 -3
- package/dist/src/Error.d.ts.map +1 -1
- 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 +39 -45
- 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 +3428 -1629
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1876 -1279
- package/dist/src/Test.d.ts +17 -124
- 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 -100
- 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 +107 -130
- 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 +85 -42
- 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 +48 -68
- 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 +5 -2
- 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 +142 -137
- package/src/StackTrace.ts +230 -0
- package/src/Store.ts +8 -7
- package/src/String.ts +22 -5
- package/src/Task.ts +5109 -2845
- package/src/Test.ts +20 -167
- package/src/Time.ts +293 -90
- package/src/Type.ts +10034 -4117
- package/src/Types.ts +227 -101
- 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 +161 -190
- 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 +253 -214
- 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
|
@@ -3,26 +3,25 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import { type NonEmptyReadonlyArray } from "../Array.
|
|
7
|
-
import type { Brand } from "../Brand.
|
|
8
|
-
import type { ConsoleEntry, ConsoleLevel } from "../Console.
|
|
9
|
-
import type { EncryptionKey } from "../Crypto.
|
|
10
|
-
import { type LockManagerDep } from "../LockManager.
|
|
11
|
-
import { type Result } from "../Result.
|
|
12
|
-
import type { NonEmptyReadonlySet } from "../Set.
|
|
13
|
-
import type { SqliteSchema } from "../Sqlite.
|
|
14
|
-
import { AbortError, type Task } from "../Task.
|
|
15
|
-
import {
|
|
16
|
-
import type {
|
|
17
|
-
import type {
|
|
18
|
-
import type {
|
|
19
|
-
import type {
|
|
20
|
-
import type {
|
|
21
|
-
import type
|
|
22
|
-
import { type
|
|
23
|
-
import
|
|
24
|
-
import type {
|
|
25
|
-
import type { CrdtMessage } from "./Storage.js";
|
|
6
|
+
import { type NonEmptyReadonlyArray } from "../Array.ts";
|
|
7
|
+
import type { Brand } from "../Brand.ts";
|
|
8
|
+
import type { ConsoleEntry, ConsoleLevel } from "../Console.ts";
|
|
9
|
+
import type { EncryptionKey } from "../Crypto.ts";
|
|
10
|
+
import { type LockManagerDep } from "../LockManager.ts";
|
|
11
|
+
import { type Result } from "../Result.ts";
|
|
12
|
+
import type { NonEmptyReadonlySet } from "../Set.ts";
|
|
13
|
+
import type { SqliteSchema } from "../Sqlite.ts";
|
|
14
|
+
import { AbortError, type Task } from "../Task.ts";
|
|
15
|
+
import type { Id, Name, Typed } from "../Type.ts";
|
|
16
|
+
import type { CreateWebSocketDep } from "../WebSocket.ts";
|
|
17
|
+
import type { SharedWorker as CommonSharedWorker, CreateBroadcastChannelDep, CreateMessageChannelDep, NativeMessagePort, SharedWorkerSelf, WorkerDeps } from "../Worker.ts";
|
|
18
|
+
import type { DbWorkerInit } from "./Db.ts";
|
|
19
|
+
import type { EvoluError } from "./Error.ts";
|
|
20
|
+
import type { Owner, OwnerId, SyncOwner } from "./Owner.ts";
|
|
21
|
+
import { type ApplyProtocolMessageAsClientResult, type ProtocolError, type ProtocolMessage } from "./Protocol.ts";
|
|
22
|
+
import { type Patch, type Query, type RowsByQueryMap } from "./Query.ts";
|
|
23
|
+
import type { MutationChange } from "./Schema.ts";
|
|
24
|
+
import type { CrdtMessage } from "./Storage.ts";
|
|
26
25
|
export type SharedWorker = CommonSharedWorker<SharedWorkerInput, SharedWorkerOutput>;
|
|
27
26
|
export interface SharedWorkerDep {
|
|
28
27
|
readonly sharedWorker: SharedWorker;
|
|
@@ -83,7 +82,9 @@ export type DbWorkerInput = (Typed<"Request"> & {
|
|
|
83
82
|
export type DbWorkerRequest = {
|
|
84
83
|
readonly type: "ForEvolu";
|
|
85
84
|
readonly id: EvoluInstanceId;
|
|
86
|
-
readonly message:
|
|
85
|
+
readonly message: {
|
|
86
|
+
readonly [Message in EvoluInput as Message["type"]]: Message;
|
|
87
|
+
}["Mutate" | "Query" | "Export"];
|
|
87
88
|
} | {
|
|
88
89
|
readonly type: "ForSharedWorker";
|
|
89
90
|
readonly message: {
|
|
@@ -132,5 +133,6 @@ export type DbWorkerQueuedResponse = {
|
|
|
132
133
|
export type SharedWorkerDeps = WorkerDeps & CreateBroadcastChannelDep & CreateMessageChannelDep & CreateWebSocketDep & LockManagerDep;
|
|
133
134
|
export type EvoluInstanceId = Id & Brand<"EvoluInstance">;
|
|
134
135
|
export type SyncState = 123;
|
|
136
|
+
/** Initializes the platform-agnostic Evolu SharedWorker. */
|
|
135
137
|
export declare const initSharedWorker: (self: SharedWorkerSelf<SharedWorkerInput, SharedWorkerOutput>) => Task<AsyncDisposableStack, never, SharedWorkerDeps>;
|
|
136
138
|
//# sourceMappingURL=Shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Shared.d.ts","sourceRoot":"","sources":["../../../src/local-first/Shared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,CAAC,WAAW,EAAE,cAAc,CAAC;KACtC,GACD;QACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;QACvB,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;KACtC,GACD;QACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;QACxB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;KACxC,CAAC;CACP,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,OAAO,EACZ;QACE,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;QACpC,QAAQ,CAAC,yBAAyB,EAAE,WAAW,CAC7C,OAAO,EACP,eAAe,CAChB,CAAC;KACH,GACD;QACE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;QAClC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAC1B,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;QACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CACrB,kCAAkC,EAClC,aAAa,GAAG,UAAU,CAC3B,CAAC;KACH,CAAC;CACP,CAAC;AAEN,MAAM,MAAM,gBAAgB,GAAG,UAAU,GACvC,yBAAyB,GACzB,uBAAuB,GACvB,kBAAkB,GAClB,cAAc,CAAC;AAuCjB,MAAM,MAAM,eAAe,GAAG,EAAE,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC;AAE1D,MAAM,MAAM,SAAS,GAAG,GAAG,CAAC;AAE5B,4DAA4D;AAC5D,eAAO,MAAM,gBAAgB,SAEnB,gBAAgB,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,KAC5D,IAAI,CAAC,oBAAoB,EAAE,KAAK,EAAE,gBAAgB,CAgKpD,CAAC"}
|
|
@@ -55,20 +55,21 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
55
55
|
var e = new Error(message);
|
|
56
56
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
57
57
|
});
|
|
58
|
-
import { emptyArray, firstInArray, isNonEmptyArray,
|
|
59
|
-
import { assert
|
|
58
|
+
import { emptyArray, firstInArray, isNonEmptyArray, } from "../Array.js";
|
|
59
|
+
import { assert } from "../Assert.js";
|
|
60
60
|
import { createCallbacks } from "../Callbacks.js";
|
|
61
|
+
import { disposable } from "../Function.js";
|
|
61
62
|
import { acquireLeaderLock } from "../LockManager.js";
|
|
62
|
-
import { structuralLookup } from "../Lookup.js";
|
|
63
|
+
import { createLookupMap, structuralLookup, } from "../Lookup.js";
|
|
63
64
|
import { createRefCountByKey } from "../RefCount.js";
|
|
64
65
|
import { createSharedResourceByKey, createSharedResourceByKeyWithClaims, } from "../Resource.js";
|
|
65
66
|
import { ok } from "../Result.js";
|
|
66
67
|
import { createStore } from "../Store.js";
|
|
67
68
|
import { AbortError, createMutex, unabortable, } from "../Task.js";
|
|
68
|
-
import {} from "../Type.js";
|
|
69
69
|
import { createProtocolMessageForUnsubscribe, createProtocolMessageFromCrdtMessages, parseProtocolHeader, } from "./Protocol.js";
|
|
70
70
|
import { makePatches, } from "./Query.js";
|
|
71
71
|
export const consoleEntryOrErrorBroadcastChannelName = "evolu:console-entry-or-error";
|
|
72
|
+
/** Initializes the platform-agnostic Evolu SharedWorker. */
|
|
72
73
|
export const initSharedWorker = (self) => async (run) => {
|
|
73
74
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
74
75
|
try {
|
|
@@ -95,10 +96,8 @@ export const initSharedWorker = (self) => async (run) => {
|
|
|
95
96
|
}
|
|
96
97
|
case "CreateEvolu": {
|
|
97
98
|
void sharedWorkerRun(async (run) => {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
return tenant;
|
|
101
|
-
tenant.value.addInstance(message, () => void sharedWorkerRun(tenantsByName.release(message)));
|
|
99
|
+
const tenantLease = await run.ok(unabortable(tenantsByName.acquire(message)));
|
|
100
|
+
tenantLease.resource.addInstance(message, tenantLease.release);
|
|
102
101
|
return ok();
|
|
103
102
|
});
|
|
104
103
|
break;
|
|
@@ -114,7 +113,8 @@ export const initSharedWorker = (self) => async (run) => {
|
|
|
114
113
|
if (entry)
|
|
115
114
|
postConsoleEntryOrError({ type: "ConsoleEntry", entry });
|
|
116
115
|
}));
|
|
117
|
-
const
|
|
116
|
+
const currentTenantsByName = new Map();
|
|
117
|
+
const transports = disposer.use(await run.ok(createSharedResourceByKeyWithClaims((transport) => deps.createWebSocket(transport.url, {
|
|
118
118
|
binaryType: "arraybuffer",
|
|
119
119
|
onOpen: () => {
|
|
120
120
|
const ownerIds = transports.getClaimsForResource(transport);
|
|
@@ -168,15 +168,14 @@ export const initSharedWorker = (self) => async (run) => {
|
|
|
168
168
|
tabLeaderPortStore,
|
|
169
169
|
transports,
|
|
170
170
|
});
|
|
171
|
-
const tenantsByName = disposer.use(await sharedWorkerRun.
|
|
171
|
+
const tenantsByName = disposer.use(await sharedWorkerRun.ok(createSharedResourceByKey((message) => createEvoluTenant(message, currentTenantsByName), {
|
|
172
172
|
idleDisposeAfter: "3s",
|
|
173
173
|
lookup: (message) => message.name,
|
|
174
174
|
})));
|
|
175
175
|
sharedWorkerReady.resolve();
|
|
176
176
|
const forEachTenant = (callback) => {
|
|
177
|
-
for (const tenant of
|
|
177
|
+
for (const tenant of currentTenantsByName.values())
|
|
178
178
|
callback(tenant);
|
|
179
|
-
}
|
|
180
179
|
};
|
|
181
180
|
return ok(disposer.move());
|
|
182
181
|
}
|
|
@@ -190,7 +189,7 @@ export const initSharedWorker = (self) => async (run) => {
|
|
|
190
189
|
await result_1;
|
|
191
190
|
}
|
|
192
191
|
};
|
|
193
|
-
const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, memoryOnly, }) => async (run) => {
|
|
192
|
+
const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, memoryOnly, }, currentTenantsByName) => async (run) => {
|
|
194
193
|
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
195
194
|
try {
|
|
196
195
|
const disposer = __addDisposableResource(env_2, new AsyncDisposableStack(), true);
|
|
@@ -269,7 +268,7 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
269
268
|
break;
|
|
270
269
|
}
|
|
271
270
|
// Complete the current queue item and continue with the next one.
|
|
272
|
-
|
|
271
|
+
queue.shift();
|
|
273
272
|
queueRequestInFlight = false;
|
|
274
273
|
runQueue();
|
|
275
274
|
});
|
|
@@ -287,11 +286,7 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
287
286
|
// DbWorker releases it: either because Dispose was delivered or because
|
|
288
287
|
// the hosting tab closed. The wait is unabortable because tenant disposal
|
|
289
288
|
// must finish even after tenantRun receives an abort request.
|
|
290
|
-
const
|
|
291
|
-
// AbortError here means tenantRun was already disposed before this
|
|
292
|
-
// cleanup could start, violating the disposal ordering above.
|
|
293
|
-
assertNotAborted(lock);
|
|
294
|
-
const _ = __addDisposableResource(env_4, lock.value, true);
|
|
289
|
+
const _ = __addDisposableResource(env_4, await tenantRun.ok(acquireLeaderLock(name)), true);
|
|
295
290
|
}
|
|
296
291
|
catch (e_4) {
|
|
297
292
|
env_4.error = e_4;
|
|
@@ -306,7 +301,6 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
306
301
|
disposer.defer(deps.tabLeaderPortStore.subscribe(initDbWorker));
|
|
307
302
|
initDbWorker();
|
|
308
303
|
await dbWorkerInited.promise;
|
|
309
|
-
const disposables = disposer.move();
|
|
310
304
|
const handleResponseForEvolu = (response, first) => {
|
|
311
305
|
const instance = instancesById.get(response.id);
|
|
312
306
|
if (!instance)
|
|
@@ -395,17 +389,16 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
395
389
|
};
|
|
396
390
|
const sendProtocolMessagesByOwnerId = (protocolMessagesByOwnerId) => {
|
|
397
391
|
for (const [ownerId, protocolMessage] of protocolMessagesByOwnerId) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
continue;
|
|
392
|
+
deps.transports.forEachResourceForClaim(ownerId, (webSocket, transport) => {
|
|
393
|
+
if (!webSocket.isOpen())
|
|
394
|
+
return;
|
|
402
395
|
console.debug("sendProtocolMessage", {
|
|
403
396
|
ownerId,
|
|
404
397
|
url: transport.url,
|
|
405
398
|
byteLength: protocolMessage.byteLength,
|
|
406
399
|
});
|
|
407
400
|
webSocket.send(protocolMessage);
|
|
408
|
-
}
|
|
401
|
+
});
|
|
409
402
|
}
|
|
410
403
|
};
|
|
411
404
|
const getUsedOwnersById = (ownerIds) => {
|
|
@@ -421,19 +414,58 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
421
414
|
};
|
|
422
415
|
const toggleSyncOwner = (instance, syncOwner, action) => async (run) => {
|
|
423
416
|
if (action === "add") {
|
|
424
|
-
|
|
425
|
-
|
|
417
|
+
const env_5 = { stack: [], error: void 0, hasError: false };
|
|
418
|
+
try {
|
|
419
|
+
instance.usedSyncOwners.increment(syncOwner);
|
|
420
|
+
let succeeded = false;
|
|
421
|
+
const compensation = __addDisposableResource(env_5, new DisposableStack(), false);
|
|
422
|
+
compensation.defer(() => {
|
|
423
|
+
if (!succeeded)
|
|
424
|
+
instance.usedSyncOwners.decrement(syncOwner);
|
|
425
|
+
});
|
|
426
|
+
const claimLease = await run.ok(deps.transports.claim(syncOwner.owner.id, syncOwner.transports));
|
|
427
|
+
instance.claimLeasesBySyncOwner
|
|
428
|
+
.getOrInsertComputed(syncOwner, () => [])
|
|
429
|
+
.push(claimLease);
|
|
430
|
+
succeeded = true;
|
|
431
|
+
}
|
|
432
|
+
catch (e_5) {
|
|
433
|
+
env_5.error = e_5;
|
|
434
|
+
env_5.hasError = true;
|
|
435
|
+
}
|
|
436
|
+
finally {
|
|
437
|
+
__disposeResources(env_5);
|
|
438
|
+
}
|
|
426
439
|
}
|
|
427
440
|
else {
|
|
428
441
|
instance.usedSyncOwners.decrement(syncOwner);
|
|
429
|
-
|
|
442
|
+
const claimLeases = instance.claimLeasesBySyncOwner.get(syncOwner);
|
|
443
|
+
assert(claimLeases, "Expected a ClaimLease for the used owner.");
|
|
444
|
+
const claimLease = claimLeases.pop();
|
|
445
|
+
assert(claimLease, "Expected a ClaimLease for the used owner.");
|
|
446
|
+
claimLease.release();
|
|
447
|
+
if (claimLeases.length === 0) {
|
|
448
|
+
instance.claimLeasesBySyncOwner.delete(syncOwner);
|
|
449
|
+
}
|
|
430
450
|
}
|
|
451
|
+
return ok();
|
|
431
452
|
};
|
|
432
|
-
|
|
453
|
+
disposer.defer(() => {
|
|
454
|
+
currentTenantsByName.delete(name);
|
|
455
|
+
});
|
|
456
|
+
const tenant = disposable({
|
|
433
457
|
addInstance: (message, onDisposed) => {
|
|
434
|
-
|
|
458
|
+
const disposer = new AsyncDisposableStack();
|
|
435
459
|
const instance = {
|
|
436
460
|
id: message.id,
|
|
461
|
+
claimLeasesBySyncOwner: createLookupMap({
|
|
462
|
+
lookup: (syncOwner) => structuralLookup({
|
|
463
|
+
ownerId: syncOwner.owner.id,
|
|
464
|
+
transports: syncOwner.transports
|
|
465
|
+
.map(structuralLookup)
|
|
466
|
+
.toSorted(),
|
|
467
|
+
}),
|
|
468
|
+
}),
|
|
437
469
|
port: deps.createMessagePort(message.evoluPort),
|
|
438
470
|
onDisposed,
|
|
439
471
|
rowsByQuery: new Map(),
|
|
@@ -444,10 +476,8 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
444
476
|
[Symbol.asyncDispose]: () => disposer.disposeAsync(),
|
|
445
477
|
};
|
|
446
478
|
instancesById.set(instance.id, instance);
|
|
447
|
-
const disposer = new AsyncDisposableStack();
|
|
448
479
|
disposer.defer(instance.onDisposed);
|
|
449
480
|
disposer.use(instance.usedSyncOwners);
|
|
450
|
-
disposer.use(instance.useOwnerMutex);
|
|
451
481
|
disposer.defer(async () => {
|
|
452
482
|
await tenantRun(instance.useOwnerMutex.withLock(async (run) => {
|
|
453
483
|
for (const syncOwner of instance.usedSyncOwners.keys()) {
|
|
@@ -463,15 +493,20 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
463
493
|
console.info("evoluDispose", { name, id: instance.id });
|
|
464
494
|
});
|
|
465
495
|
disposer.use(instance.port);
|
|
496
|
+
disposer.defer(() => {
|
|
497
|
+
instance.port.onMessage = null;
|
|
498
|
+
});
|
|
466
499
|
// The main-thread Evolu instance holds this per-instance leader lock
|
|
467
500
|
// while it is alive. Acquiring the same lock here means the main
|
|
468
501
|
// thread instance was disposed or its tab closed, so the tenant-side
|
|
469
502
|
// instance must dispose itself.
|
|
470
|
-
void tenantRun
|
|
503
|
+
void tenantRun
|
|
504
|
+
.abortable(acquireLeaderLock(message.id))
|
|
505
|
+
.then((lock) => {
|
|
471
506
|
if (!lock.ok)
|
|
472
507
|
return;
|
|
473
508
|
disposer.use(lock.value);
|
|
474
|
-
return
|
|
509
|
+
return instance[Symbol.asyncDispose]();
|
|
475
510
|
});
|
|
476
511
|
instance.port.onMessage = (message) => {
|
|
477
512
|
switch (message.type) {
|
|
@@ -539,8 +574,9 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
539
574
|
});
|
|
540
575
|
runQueue();
|
|
541
576
|
},
|
|
542
|
-
|
|
543
|
-
|
|
577
|
+
}, disposer);
|
|
578
|
+
currentTenantsByName.set(name, tenant);
|
|
579
|
+
return ok(tenant);
|
|
544
580
|
}
|
|
545
581
|
catch (e_2) {
|
|
546
582
|
env_2.error = e_2;
|
|
@@ -574,10 +610,17 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
574
610
|
// readonly onCompleteId: CallbackId;
|
|
575
611
|
// readonly reload: boolean;
|
|
576
612
|
// })
|
|
577
|
-
// TODO:
|
|
578
|
-
// -
|
|
579
|
-
// -
|
|
613
|
+
// TODO: SharedWorker follow-ups.
|
|
614
|
+
// - Complete the queue head when a DbWorker mutation returns an error.
|
|
615
|
+
// - Make retried DbWorker requests deterministic by materializing clocks and
|
|
616
|
+
// timestamps in the SharedWorker before enqueueing them.
|
|
617
|
+
// - Replace the callback registry and queueRequestInFlight flag with one
|
|
618
|
+
// explicit in-flight request state.
|
|
619
|
+
// - Detect DbWorker and port liveness so a worker-only crash resumes the queue.
|
|
620
|
+
// - Consolidate usedSyncOwners and claimLeasesBySyncOwner into one owner-use
|
|
621
|
+
// state abstraction without changing repeated-use semantics.
|
|
622
|
+
// - Split worker protocol types and the EvoluTenant implementation into focused
|
|
623
|
+
// modules.
|
|
624
|
+
// - Remove the obsolete commented protocol block above.
|
|
625
|
+
// - Replace the SyncState placeholder with actual sync monitoring state.
|
|
580
626
|
// - Propagate invalid protocol messages to sync state.
|
|
581
|
-
// - Make DbWorker logically stateless by making all requests idempotent.
|
|
582
|
-
// - Investigate WebKit bug 301520 relevance to DbWorker disposal. (again)
|
|
583
|
-
// https://bugs.webkit.org/show_bug.cgi?id=301520
|
|
@@ -3,17 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { NonEmptyReadonlyArray } from "../Array.
|
|
7
|
-
import type { Brand } from "../Brand.
|
|
8
|
-
import type { RandomDep } from "../Random.
|
|
9
|
-
import type { SqliteDep } from "../Sqlite.
|
|
10
|
-
import type { Task } from "../Task.
|
|
11
|
-
import type
|
|
12
|
-
import {
|
|
13
|
-
import type {
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
import { Timestamp, TimestampBytes } from "./Timestamp.js";
|
|
6
|
+
import type { NonEmptyReadonlyArray } from "../Array.ts";
|
|
7
|
+
import type { Brand } from "../Brand.ts";
|
|
8
|
+
import type { RandomDep } from "../Random.ts";
|
|
9
|
+
import type { SqliteDep } from "../Sqlite.ts";
|
|
10
|
+
import type { Task } from "../Task.ts";
|
|
11
|
+
import { Boolean, Id, type InferType, NonNegativeInt, Null, type ObjectType, PositiveInt, String, type Typed, type TypeError, type UnionType } from "../Type.ts";
|
|
12
|
+
import type { Awaitable } from "../Types.ts";
|
|
13
|
+
import type { OwnerError, OwnerIdBytes } from "./Owner.ts";
|
|
14
|
+
import { OwnerId, OwnerWriteKey } from "./Owner.ts";
|
|
15
|
+
import { Timestamp, TimestampBytes } from "./Timestamp.ts";
|
|
17
16
|
export interface StorageConfig {
|
|
18
17
|
/**
|
|
19
18
|
* Callback called before an attempt to write, to check if an {@link OwnerId}
|
|
@@ -30,18 +29,37 @@ export interface StorageConfig {
|
|
|
30
29
|
* The callback returns a boolean rather than an error because error handling
|
|
31
30
|
* and logging are the responsibility of the callback implementation.
|
|
32
31
|
*
|
|
32
|
+
* Relay deployments configure this callback. Client applications can observe
|
|
33
|
+
* a denied relay write as a `ProtocolQuotaError` by subscribing once to the
|
|
34
|
+
* shared `EvoluErrorDep.evoluError` store returned by `createEvoluDeps`.
|
|
35
|
+
*
|
|
33
36
|
* ### Example
|
|
34
37
|
*
|
|
35
38
|
* ```ts
|
|
36
|
-
*
|
|
37
|
-
*
|
|
39
|
+
* import {
|
|
40
|
+
* createAppOwner,
|
|
41
|
+
* createOwnerSecret,
|
|
42
|
+
* createRandomBytes,
|
|
43
|
+
* PositiveInt,
|
|
44
|
+
* } from "@evolu/common";
|
|
45
|
+
* import type { StorageConfig } from "@evolu/common/local-first";
|
|
38
46
|
*
|
|
39
|
-
* //
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
47
|
+
* // Create once, persist the mnemonic securely, and restore it on later runs.
|
|
48
|
+
* const appOwner = createAppOwner(
|
|
49
|
+
* createOwnerSecret({ randomBytes: createRandomBytes() }),
|
|
50
|
+
* );
|
|
51
|
+
* const maxBytes = PositiveInt.orThrow(1024);
|
|
52
|
+
* const relayStorageConfig: StorageConfig = {
|
|
53
|
+
* isOwnerWithinQuota: (ownerId, requiredBytes) =>
|
|
54
|
+
* ownerId === appOwner.id && requiredBytes <= maxBytes,
|
|
44
55
|
* };
|
|
56
|
+
*
|
|
57
|
+
* expect(
|
|
58
|
+
* await relayStorageConfig.isOwnerWithinQuota(
|
|
59
|
+
* appOwner.id,
|
|
60
|
+
* PositiveInt.orThrow(2048),
|
|
61
|
+
* ),
|
|
62
|
+
* ).toBe(false);
|
|
45
63
|
* ```
|
|
46
64
|
*/
|
|
47
65
|
readonly isOwnerWithinQuota: (ownerId: OwnerId, requiredBytes: PositiveInt) => Awaitable<boolean>;
|
|
@@ -110,7 +128,7 @@ export interface StorageQuotaError extends OwnerError, Typed<"StorageQuotaError"
|
|
|
110
128
|
* one or more timestamps.
|
|
111
129
|
*/
|
|
112
130
|
export type Fingerprint = Uint8Array & Brand<"Fingerprint">;
|
|
113
|
-
export declare const fingerprintSize: number & Brand<"Int"> & Brand<"NonNegative">;
|
|
131
|
+
export declare const fingerprintSize: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;
|
|
114
132
|
/** A fingerprint of an empty range. */
|
|
115
133
|
export declare const zeroFingerprint: Fingerprint;
|
|
116
134
|
export interface BaseRange {
|
|
@@ -161,23 +179,24 @@ export interface CrdtMessage {
|
|
|
161
179
|
}
|
|
162
180
|
/** Test helper for creating a simple {@link CrdtMessage}. */
|
|
163
181
|
export declare const testCreateCrdtMessage: (id: Id, millis: number, name: string) => CrdtMessage;
|
|
164
|
-
export declare const DbChangeValues: import("../Type.
|
|
165
|
-
export type DbChangeValues = typeof DbChangeValues.
|
|
166
|
-
export declare const ValidDbChangeValues: import("../Type.
|
|
167
|
-
export type ValidDbChangeValues = typeof ValidDbChangeValues.
|
|
182
|
+
export declare const DbChangeValues: import("../Type.ts").RecordType<import("../Type.ts").Type<"String", string, string, import("../Type.ts").TypeOfError<"String">, null, import("../Type.ts").TypeOfError<"String">, never, string, true>, UnionType<readonly [import("../Type.ts").LiteralType<null>, import("../Type.ts").Type<"String", string, string, import("../Type.ts").TypeOfError<"String">, null, import("../Type.ts").TypeOfError<"String">, never, string, true>, import("../Type.ts").Type<"Number", number, number, import("../Type.ts").TypeOfError<"Number">, null, import("../Type.ts").TypeOfError<"Number">, never, number, true>, import("../Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("../Type.ts").ObjectTagError<"Uint8Array">, null, import("../Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>]>>;
|
|
183
|
+
export type DbChangeValues = typeof DbChangeValues.Output;
|
|
184
|
+
export declare const ValidDbChangeValues: import("../Type.ts").BrandType<import("../Type.ts").RecordType<import("../Type.ts").Type<"String", string, string, import("../Type.ts").TypeOfError<"String">, null, import("../Type.ts").TypeOfError<"String">, never, string, true>, UnionType<readonly [import("../Type.ts").LiteralType<null>, import("../Type.ts").Type<"String", string, string, import("../Type.ts").TypeOfError<"String">, null, import("../Type.ts").TypeOfError<"String">, never, string, true>, import("../Type.ts").Type<"Number", number, number, import("../Type.ts").TypeOfError<"Number">, null, import("../Type.ts").TypeOfError<"Number">, never, number, true>, import("../Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("../Type.ts").ObjectTagError<"Uint8Array">, null, import("../Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>]>>, "ValidDbChangeValues", ValidDbChangeValuesError>;
|
|
185
|
+
export type ValidDbChangeValues = typeof ValidDbChangeValues.Output;
|
|
168
186
|
export interface ValidDbChangeValuesError extends TypeError<"ValidDbChangeValues"> {
|
|
187
|
+
readonly value: DbChangeValues;
|
|
169
188
|
readonly invalidColumns: ReadonlyArray<string>;
|
|
170
189
|
}
|
|
171
190
|
/**
|
|
172
191
|
* A DbChange is a change to a table row. Together with a unique
|
|
173
192
|
* {@link Timestamp}, it forms a {@link CrdtMessage}.
|
|
174
193
|
*/
|
|
175
|
-
export declare const DbChange:
|
|
176
|
-
table:
|
|
177
|
-
id:
|
|
178
|
-
values:
|
|
179
|
-
isInsert:
|
|
180
|
-
isDelete:
|
|
194
|
+
export declare const DbChange: ObjectType<{
|
|
195
|
+
readonly table: typeof String;
|
|
196
|
+
readonly id: typeof Id;
|
|
197
|
+
readonly values: typeof ValidDbChangeValues;
|
|
198
|
+
readonly isInsert: typeof Boolean;
|
|
199
|
+
readonly isDelete: UnionType<readonly [typeof Boolean, typeof Null]>;
|
|
181
200
|
}>;
|
|
182
201
|
export interface DbChange extends InferType<typeof DbChange> {
|
|
183
202
|
}
|
|
@@ -195,9 +214,6 @@ export interface DbChange extends InferType<typeof DbChange> {
|
|
|
195
214
|
* storage](https://github.com/hoytech/negentropy), except we use a Skiplist to
|
|
196
215
|
* leverage SQLite indexes, which makes the code simpler.
|
|
197
216
|
*
|
|
198
|
-
* Note: A paid review by the SQLite team is planned, as they use the same
|
|
199
|
-
* algorithm for their rsync tool.
|
|
200
|
-
*
|
|
201
217
|
* The ideal storage for a Relay should use an architecture like
|
|
202
218
|
* [strfry](https://github.com/hoytech/strfry) (a KV storage), but with Skiplist
|
|
203
219
|
* to ensure that insertion order doesn't matter (local-first apps can often
|
|
@@ -251,6 +267,11 @@ export type StorageInsertTimestampStrategy = "append" | "prepend" | "insert";
|
|
|
251
267
|
*/
|
|
252
268
|
export declare const getTimestampInsertStrategy: (timestamp: TimestampBytes, firstTimestamp: TimestampBytes, lastTimestamp: TimestampBytes) => [strategy: StorageInsertTimestampStrategy, firstTimestamp: TimestampBytes, lastTimestamp: TimestampBytes];
|
|
253
269
|
export declare const timestampBytesToFingerprint: (timestamp: TimestampBytes) => Fingerprint;
|
|
270
|
+
/**
|
|
271
|
+
* Computes a brute-force {@link Fingerprint} from {@link TimestampBytes} values
|
|
272
|
+
* for tests and benchmarks.
|
|
273
|
+
*/
|
|
274
|
+
export declare const testFingerprintTimestamps: (timestamps: ReadonlyArray<TimestampBytes>) => Fingerprint;
|
|
254
275
|
export declare const getTimestampByIndex: (deps: SqliteDep) => (ownerId: OwnerIdBytes, index: NonNegativeInt) => TimestampBytes;
|
|
255
276
|
/** Reads owner usage from SQLite and returns default bounds when absent. */
|
|
256
277
|
export declare const readOwnerUsageOrDefault: (deps: SqliteDep) => (ownerIdBytes: OwnerIdBytes, initialTimestamp: TimestampBytes) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../../../src/local-first/Storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,
|
|
1
|
+
{"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../../../src/local-first/Storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EACL,OAAO,EAEP,EAAE,EACF,KAAK,SAAS,EAEd,cAAc,EACd,IAAI,EAGJ,KAAK,UAAU,EACf,WAAW,EAEX,MAAM,EACN,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C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