@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
|
@@ -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.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"Shared.d.ts","sourceRoot":"","sources":["../../../src/local-first/Shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAe3E,OAAO,EAAM,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EACL,UAAU,EAIV,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAgB,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,KAAK,EAAE,kBAAkB,EAAa,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EACV,YAAY,IAAI,kBAAkB,EAClC,yBAAyB,EACzB,uBAAuB,EAEvB,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACX,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAkB,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAIL,KAAK,kCAAkC,EACvC,KAAK,aAAa,EAClB,KAAK,eAAe,EAC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CACnC,CAAC;QACF,QAAQ,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,21 +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 {
|
|
61
|
+
import { disposable } from "../Function.js";
|
|
62
62
|
import { acquireLeaderLock } from "../LockManager.js";
|
|
63
|
-
import { structuralLookup } from "../Lookup.js";
|
|
63
|
+
import { createLookupMap, structuralLookup, } from "../Lookup.js";
|
|
64
64
|
import { createRefCountByKey } from "../RefCount.js";
|
|
65
65
|
import { createSharedResourceByKey, createSharedResourceByKeyWithClaims, } from "../Resource.js";
|
|
66
66
|
import { ok } from "../Result.js";
|
|
67
67
|
import { createStore } from "../Store.js";
|
|
68
|
-
import { AbortError, createMutex } from "../Task.js";
|
|
69
|
-
import {} from "../Type.js";
|
|
68
|
+
import { AbortError, createMutex, unabortable, } from "../Task.js";
|
|
70
69
|
import { createProtocolMessageForUnsubscribe, createProtocolMessageFromCrdtMessages, parseProtocolHeader, } from "./Protocol.js";
|
|
71
70
|
import { makePatches, } from "./Query.js";
|
|
72
71
|
export const consoleEntryOrErrorBroadcastChannelName = "evolu:console-entry-or-error";
|
|
72
|
+
/** Initializes the platform-agnostic Evolu SharedWorker. */
|
|
73
73
|
export const initSharedWorker = (self) => async (run) => {
|
|
74
74
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
75
75
|
try {
|
|
@@ -96,8 +96,8 @@ export const initSharedWorker = (self) => async (run) => {
|
|
|
96
96
|
}
|
|
97
97
|
case "CreateEvolu": {
|
|
98
98
|
void sharedWorkerRun(async (run) => {
|
|
99
|
-
const
|
|
100
|
-
|
|
99
|
+
const tenantLease = await run.ok(unabortable(tenantsByName.acquire(message)));
|
|
100
|
+
tenantLease.resource.addInstance(message, tenantLease.release);
|
|
101
101
|
return ok();
|
|
102
102
|
});
|
|
103
103
|
break;
|
|
@@ -113,7 +113,8 @@ export const initSharedWorker = (self) => async (run) => {
|
|
|
113
113
|
if (entry)
|
|
114
114
|
postConsoleEntryOrError({ type: "ConsoleEntry", entry });
|
|
115
115
|
}));
|
|
116
|
-
const
|
|
116
|
+
const currentTenantsByName = new Map();
|
|
117
|
+
const transports = disposer.use(await run.ok(createSharedResourceByKeyWithClaims((transport) => deps.createWebSocket(transport.url, {
|
|
117
118
|
binaryType: "arraybuffer",
|
|
118
119
|
onOpen: () => {
|
|
119
120
|
const ownerIds = transports.getClaimsForResource(transport);
|
|
@@ -161,19 +162,20 @@ export const initSharedWorker = (self) => async (run) => {
|
|
|
161
162
|
idleDisposeAfter: "3s",
|
|
162
163
|
resourceLookup: structuralLookup,
|
|
163
164
|
})));
|
|
164
|
-
const sharedWorkerRun = run.create(
|
|
165
|
+
const sharedWorkerRun = run.create({
|
|
166
|
+
...deps,
|
|
165
167
|
postConsoleEntryOrError,
|
|
166
168
|
tabLeaderPortStore,
|
|
167
169
|
transports,
|
|
168
170
|
});
|
|
169
|
-
const tenantsByName = disposer.use(await sharedWorkerRun.
|
|
171
|
+
const tenantsByName = disposer.use(await sharedWorkerRun.ok(createSharedResourceByKey((message) => createEvoluTenant(message, currentTenantsByName), {
|
|
172
|
+
idleDisposeAfter: "3s",
|
|
170
173
|
lookup: (message) => message.name,
|
|
171
174
|
})));
|
|
172
175
|
sharedWorkerReady.resolve();
|
|
173
176
|
const forEachTenant = (callback) => {
|
|
174
|
-
for (const tenant of
|
|
177
|
+
for (const tenant of currentTenantsByName.values())
|
|
175
178
|
callback(tenant);
|
|
176
|
-
}
|
|
177
179
|
};
|
|
178
180
|
return ok(disposer.move());
|
|
179
181
|
}
|
|
@@ -187,7 +189,7 @@ export const initSharedWorker = (self) => async (run) => {
|
|
|
187
189
|
await result_1;
|
|
188
190
|
}
|
|
189
191
|
};
|
|
190
|
-
const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, memoryOnly, }) => async (run) => {
|
|
192
|
+
const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, memoryOnly, }, currentTenantsByName) => async (run) => {
|
|
191
193
|
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
192
194
|
try {
|
|
193
195
|
const disposer = __addDisposableResource(env_2, new AsyncDisposableStack(), true);
|
|
@@ -235,8 +237,6 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
235
237
|
callbacks.execute(message.callbackId, message);
|
|
236
238
|
break;
|
|
237
239
|
}
|
|
238
|
-
default:
|
|
239
|
-
exhaustiveCheck(message);
|
|
240
240
|
}
|
|
241
241
|
};
|
|
242
242
|
tabLeaderPort.postMessage({
|
|
@@ -266,11 +266,9 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
266
266
|
case "ForSharedWorker":
|
|
267
267
|
handleResponseForSharedWorker(response);
|
|
268
268
|
break;
|
|
269
|
-
default:
|
|
270
|
-
exhaustiveCheck(response);
|
|
271
269
|
}
|
|
272
270
|
// Complete the current queue item and continue with the next one.
|
|
273
|
-
|
|
271
|
+
queue.shift();
|
|
274
272
|
queueRequestInFlight = false;
|
|
275
273
|
runQueue();
|
|
276
274
|
});
|
|
@@ -283,7 +281,12 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
283
281
|
dbWorkerPort?.postMessage({ type: "Dispose" });
|
|
284
282
|
dbWorkerPort = null;
|
|
285
283
|
queueRequestInFlight = false;
|
|
286
|
-
|
|
284
|
+
// The DbWorker holds this tenant leader lock while it is alive. Tenant
|
|
285
|
+
// disposal sends Dispose, then acquires the same lock to wait until the
|
|
286
|
+
// DbWorker releases it: either because Dispose was delivered or because
|
|
287
|
+
// the hosting tab closed. The wait is unabortable because tenant disposal
|
|
288
|
+
// must finish even after tenantRun receives an abort request.
|
|
289
|
+
const _ = __addDisposableResource(env_4, await tenantRun.ok(acquireLeaderLock(name)), true);
|
|
287
290
|
}
|
|
288
291
|
catch (e_4) {
|
|
289
292
|
env_4.error = e_4;
|
|
@@ -298,7 +301,6 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
298
301
|
disposer.defer(deps.tabLeaderPortStore.subscribe(initDbWorker));
|
|
299
302
|
initDbWorker();
|
|
300
303
|
await dbWorkerInited.promise;
|
|
301
|
-
const disposables = disposer.move();
|
|
302
304
|
const handleResponseForEvolu = (response, first) => {
|
|
303
305
|
const instance = instancesById.get(response.id);
|
|
304
306
|
if (!instance)
|
|
@@ -346,8 +348,6 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
346
348
|
case "Export":
|
|
347
349
|
instance.port.postMessage({ type: "OnExport", file: response.message.file }, [response.message.file.buffer]);
|
|
348
350
|
break;
|
|
349
|
-
default:
|
|
350
|
-
exhaustiveCheck(response.message);
|
|
351
351
|
}
|
|
352
352
|
};
|
|
353
353
|
const handleResponseForSharedWorker = (response) => {
|
|
@@ -382,28 +382,23 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
382
382
|
case "Broadcast":
|
|
383
383
|
case "NoResponse":
|
|
384
384
|
break;
|
|
385
|
-
default:
|
|
386
|
-
exhaustiveCheck(response.message.result.value);
|
|
387
385
|
}
|
|
388
386
|
}
|
|
389
387
|
break;
|
|
390
|
-
default:
|
|
391
|
-
exhaustiveCheck(response.message);
|
|
392
388
|
}
|
|
393
389
|
};
|
|
394
390
|
const sendProtocolMessagesByOwnerId = (protocolMessagesByOwnerId) => {
|
|
395
391
|
for (const [ownerId, protocolMessage] of protocolMessagesByOwnerId) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
continue;
|
|
392
|
+
deps.transports.forEachResourceForClaim(ownerId, (webSocket, transport) => {
|
|
393
|
+
if (!webSocket.isOpen())
|
|
394
|
+
return;
|
|
400
395
|
console.debug("sendProtocolMessage", {
|
|
401
396
|
ownerId,
|
|
402
397
|
url: transport.url,
|
|
403
398
|
byteLength: protocolMessage.byteLength,
|
|
404
399
|
});
|
|
405
400
|
webSocket.send(protocolMessage);
|
|
406
|
-
}
|
|
401
|
+
});
|
|
407
402
|
}
|
|
408
403
|
};
|
|
409
404
|
const getUsedOwnersById = (ownerIds) => {
|
|
@@ -419,19 +414,58 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
419
414
|
};
|
|
420
415
|
const toggleSyncOwner = (instance, syncOwner, action) => async (run) => {
|
|
421
416
|
if (action === "add") {
|
|
422
|
-
|
|
423
|
-
|
|
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
|
+
}
|
|
424
439
|
}
|
|
425
440
|
else {
|
|
426
441
|
instance.usedSyncOwners.decrement(syncOwner);
|
|
427
|
-
|
|
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
|
+
}
|
|
428
450
|
}
|
|
451
|
+
return ok();
|
|
429
452
|
};
|
|
430
|
-
|
|
453
|
+
disposer.defer(() => {
|
|
454
|
+
currentTenantsByName.delete(name);
|
|
455
|
+
});
|
|
456
|
+
const tenant = disposable({
|
|
431
457
|
addInstance: (message, onDisposed) => {
|
|
432
|
-
|
|
458
|
+
const disposer = new AsyncDisposableStack();
|
|
433
459
|
const instance = {
|
|
434
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
|
+
}),
|
|
435
469
|
port: deps.createMessagePort(message.evoluPort),
|
|
436
470
|
onDisposed,
|
|
437
471
|
rowsByQuery: new Map(),
|
|
@@ -442,10 +476,8 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
442
476
|
[Symbol.asyncDispose]: () => disposer.disposeAsync(),
|
|
443
477
|
};
|
|
444
478
|
instancesById.set(instance.id, instance);
|
|
445
|
-
const disposer = new AsyncDisposableStack();
|
|
446
479
|
disposer.defer(instance.onDisposed);
|
|
447
480
|
disposer.use(instance.usedSyncOwners);
|
|
448
|
-
disposer.use(instance.useOwnerMutex);
|
|
449
481
|
disposer.defer(async () => {
|
|
450
482
|
await tenantRun(instance.useOwnerMutex.withLock(async (run) => {
|
|
451
483
|
for (const syncOwner of instance.usedSyncOwners.keys()) {
|
|
@@ -461,15 +493,20 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
461
493
|
console.info("evoluDispose", { name, id: instance.id });
|
|
462
494
|
});
|
|
463
495
|
disposer.use(instance.port);
|
|
464
|
-
|
|
465
|
-
|
|
496
|
+
disposer.defer(() => {
|
|
497
|
+
instance.port.onMessage = null;
|
|
498
|
+
});
|
|
499
|
+
// The main-thread Evolu instance holds this per-instance leader lock
|
|
500
|
+
// while it is alive. Acquiring the same lock here means the main
|
|
501
|
+
// thread instance was disposed or its tab closed, so the tenant-side
|
|
502
|
+
// instance must dispose itself.
|
|
503
|
+
void tenantRun
|
|
504
|
+
.abortable(acquireLeaderLock(message.id))
|
|
505
|
+
.then((lock) => {
|
|
506
|
+
if (!lock.ok)
|
|
466
507
|
return;
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return lock[Symbol.asyncDispose]();
|
|
470
|
-
}
|
|
471
|
-
disposer.use(lock);
|
|
472
|
-
return disposer.disposeAsync();
|
|
508
|
+
disposer.use(lock.value);
|
|
509
|
+
return instance[Symbol.asyncDispose]();
|
|
473
510
|
});
|
|
474
511
|
instance.port.onMessage = (message) => {
|
|
475
512
|
switch (message.type) {
|
|
@@ -500,8 +537,6 @@ const createEvoluTenant = ({ name, consoleLevel, sqliteSchema, encryptionKey, me
|
|
|
500
537
|
}));
|
|
501
538
|
break;
|
|
502
539
|
}
|
|
503
|
-
default:
|
|
504
|
-
exhaustiveCheck(message);
|
|
505
540
|
}
|
|
506
541
|
};
|
|
507
542
|
},
|
|
@@ -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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