@evolu/common 6.0.1-preview.9 → 7.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/README.md +2 -2
- package/dist/src/Array.d.ts +256 -12
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +215 -9
- package/dist/src/Assert.d.ts +0 -13
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +0 -15
- package/dist/src/Brand.d.ts +75 -0
- package/dist/src/Brand.d.ts.map +1 -0
- package/dist/src/Brand.js +1 -0
- package/dist/src/Buffer.d.ts +1 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +8 -7
- package/dist/src/Cache.d.ts +44 -0
- package/dist/src/Cache.d.ts.map +1 -0
- package/dist/src/Cache.js +52 -0
- package/dist/src/Callbacks.d.ts +45 -12
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Callbacks.js +14 -7
- package/dist/src/Console.d.ts +31 -6
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +72 -9
- package/dist/src/Crypto.d.ts +56 -42
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +40 -53
- package/dist/src/Evolu/Db.d.ts +162 -74
- package/dist/src/Evolu/Db.d.ts.map +1 -1
- package/dist/src/Evolu/Db.js +284 -702
- package/dist/src/Evolu/Diff.d.ts +3 -3
- package/dist/src/Evolu/Diff.d.ts.map +1 -1
- package/dist/src/Evolu/Diff.js +7 -5
- package/dist/src/Evolu/Evolu.d.ts +213 -133
- package/dist/src/Evolu/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu/Evolu.js +189 -180
- package/dist/src/Evolu/Internal.d.ts +0 -2
- package/dist/src/Evolu/Internal.d.ts.map +1 -1
- package/dist/src/Evolu/Internal.js +0 -2
- package/dist/src/Evolu/LocalAuth.d.ts +150 -0
- package/dist/src/Evolu/LocalAuth.d.ts.map +1 -0
- package/dist/src/Evolu/LocalAuth.js +174 -0
- package/dist/src/Evolu/Owner.d.ts +273 -120
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +130 -104
- package/dist/src/Evolu/Platform.d.ts +9 -7
- package/dist/src/Evolu/Platform.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.d.ts +268 -240
- package/dist/src/Evolu/Protocol.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.js +595 -447
- package/dist/src/Evolu/Public.d.ts +6 -8
- package/dist/src/Evolu/Public.d.ts.map +1 -1
- package/dist/src/Evolu/Public.js +2 -3
- package/dist/src/Evolu/PublicKysely.d.ts.map +1 -1
- package/dist/src/Evolu/PublicKysely.js +3 -4
- package/dist/src/Evolu/Query.d.ts +2 -1
- package/dist/src/Evolu/Query.d.ts.map +1 -1
- package/dist/src/Evolu/Query.js +1 -1
- package/dist/src/Evolu/Relay.d.ts +91 -8
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +214 -88
- package/dist/src/Evolu/Schema.d.ts +125 -47
- package/dist/src/Evolu/Schema.d.ts.map +1 -1
- package/dist/src/Evolu/Schema.js +175 -31
- package/dist/src/Evolu/Storage.d.ts +249 -27
- package/dist/src/Evolu/Storage.d.ts.map +1 -1
- package/dist/src/Evolu/Storage.js +198 -92
- package/dist/src/Evolu/Sync.d.ts +68 -13
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +469 -20
- package/dist/src/Evolu/Timestamp.d.ts +83 -30
- package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
- package/dist/src/Evolu/Timestamp.js +79 -34
- package/dist/src/Identicon.d.ts +35 -0
- package/dist/src/Identicon.d.ts.map +1 -0
- package/dist/src/Identicon.js +143 -0
- package/dist/src/Instances.d.ts +34 -0
- package/dist/src/Instances.d.ts.map +1 -0
- package/dist/src/Instances.js +44 -0
- package/dist/src/Number.d.ts +4 -3
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +5 -4
- package/dist/src/Object.d.ts +10 -4
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +9 -3
- package/dist/src/Platform.d.ts +20 -0
- package/dist/src/Platform.d.ts.map +1 -0
- package/dist/src/Platform.js +22 -0
- package/dist/src/Random.d.ts +3 -2
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Relation.d.ts +79 -0
- package/dist/src/Relation.d.ts.map +1 -0
- package/dist/src/Relation.js +127 -0
- package/dist/src/Resources.d.ts +118 -0
- package/dist/src/Resources.d.ts.map +1 -0
- package/dist/src/Resources.js +197 -0
- package/dist/src/Result.d.ts +184 -52
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +30 -241
- package/dist/src/Skiplist.js +2 -1
- package/dist/src/Sqlite.d.ts +89 -5
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +136 -9
- package/dist/src/Task.d.ts +586 -0
- package/dist/src/Task.d.ts.map +1 -0
- package/dist/src/Task.js +469 -0
- package/dist/src/Time.d.ts +66 -1
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +99 -5
- package/dist/src/Type.d.ts +676 -343
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +718 -467
- package/dist/src/Types.d.ts +1 -75
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/WebSocket.d.ts +5 -2
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +12 -18
- package/dist/src/Worker.d.ts +39 -11
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +22 -4
- package/dist/src/index.d.ts +8 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -3
- package/package.json +14 -13
- package/src/Array.ts +301 -19
- package/src/Assert.ts +0 -21
- package/src/Brand.ts +75 -0
- package/src/Buffer.ts +7 -7
- package/src/Cache.ts +85 -0
- package/src/Callbacks.ts +62 -22
- package/src/Console.ts +91 -11
- package/src/Crypto.ts +94 -90
- package/src/Evolu/Db.ts +519 -1026
- package/src/Evolu/Diff.ts +7 -5
- package/src/Evolu/Evolu.ts +476 -360
- package/src/Evolu/Internal.ts +0 -2
- package/src/Evolu/LocalAuth.ts +463 -0
- package/src/Evolu/Owner.ts +355 -228
- package/src/Evolu/Platform.ts +9 -9
- package/src/Evolu/Protocol.ts +846 -742
- package/src/Evolu/Public.ts +7 -14
- package/src/Evolu/PublicKysely.ts +4 -5
- package/src/Evolu/Query.ts +3 -2
- package/src/Evolu/Relay.ts +406 -103
- package/src/Evolu/Schema.ts +323 -91
- package/src/Evolu/Storage.ts +559 -137
- package/src/Evolu/Sync.ts +819 -36
- package/src/Evolu/Timestamp.ts +90 -58
- package/src/Identicon.ts +197 -0
- package/src/Instances.ts +90 -0
- package/src/Number.ts +6 -10
- package/src/Object.ts +13 -5
- package/src/Platform.ts +26 -0
- package/src/Random.ts +3 -2
- package/src/Relation.ts +234 -0
- package/src/Resources.ts +367 -0
- package/src/Result.ts +191 -54
- package/src/Skiplist.ts +1 -1
- package/src/Sqlite.ts +152 -17
- package/src/Task.ts +901 -0
- package/src/Time.ts +180 -5
- package/src/Type.ts +1135 -730
- package/src/Types.ts +1 -77
- package/src/WebSocket.ts +27 -25
- package/src/Worker.ts +72 -23
- package/src/index.ts +8 -3
- package/dist/src/Evolu/Config.d.ts +0 -69
- package/dist/src/Evolu/Config.d.ts.map +0 -1
- package/dist/src/Evolu/Config.js +0 -9
- package/dist/src/Evolu/Kysely.d.ts +0 -6
- package/dist/src/Evolu/Kysely.d.ts.map +0 -1
- package/dist/src/Evolu/Kysely.js +0 -21
- package/dist/src/ManyToManyMap.d.ts +0 -26
- package/dist/src/ManyToManyMap.d.ts.map +0 -1
- package/dist/src/ManyToManyMap.js +0 -92
- package/dist/src/NanoId.d.ts +0 -27
- package/dist/src/NanoId.d.ts.map +0 -1
- package/dist/src/NanoId.js +0 -6
- package/dist/src/Promise.d.ts +0 -180
- package/dist/src/Promise.d.ts.map +0 -1
- package/dist/src/Promise.js +0 -176
- package/src/Evolu/Config.ts +0 -83
- package/src/Evolu/Kysely.ts +0 -38
- package/src/ManyToManyMap.ts +0 -140
- package/src/NanoId.ts +0 -39
- package/src/Promise.ts +0 -295
package/dist/src/Crypto.js
CHANGED
|
@@ -3,70 +3,57 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import { xchacha20poly1305 } from "@noble/ciphers/chacha";
|
|
7
|
-
import { hmac } from "@noble/hashes/hmac";
|
|
8
|
-
import { sha512 } from "@noble/hashes/sha2";
|
|
9
|
-
import { randomBytes } from "@noble/hashes/utils";
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export const createRandomBytes = (
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
7
|
+
import { hmac } from "@noble/hashes/hmac.js";
|
|
8
|
+
import { sha512 } from "@noble/hashes/sha2.js";
|
|
9
|
+
import { randomBytes, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
10
|
+
import { trySync } from "./Result.js";
|
|
11
|
+
import { brand, length, NonNegativeInt, Uint8Array } from "./Type.js";
|
|
12
|
+
const Entropy = brand("Entropy", Uint8Array);
|
|
13
|
+
export const Entropy16 = length(16)(Entropy);
|
|
14
|
+
export const Entropy32 = length(32)(Entropy);
|
|
15
|
+
export const Entropy64 = length(64)(Entropy);
|
|
16
|
+
export const createRandomBytes = () => ({
|
|
17
|
+
create: randomBytes,
|
|
18
|
+
});
|
|
19
19
|
/**
|
|
20
20
|
* SLIP21.
|
|
21
21
|
*
|
|
22
22
|
* https://github.com/satoshilabs/slips/blob/master/slip-0021.md
|
|
23
23
|
*/
|
|
24
24
|
export const createSlip21 = (seed, path) => {
|
|
25
|
-
let
|
|
26
|
-
for (const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
e[0] = 0;
|
|
30
|
-
e.set(p, 1);
|
|
31
|
-
m = hmac(sha512, m.slice(0, 32), e);
|
|
25
|
+
let currentNode = hmac(sha512, utf8ToBytes("Symmetric key seed"), seed);
|
|
26
|
+
for (const element of path) {
|
|
27
|
+
const label = typeof element === "number" ? element.toString() : element;
|
|
28
|
+
currentNode = deriveSlip21Node(label, currentNode);
|
|
32
29
|
}
|
|
33
|
-
return
|
|
30
|
+
return currentNode.slice(32, 64);
|
|
34
31
|
};
|
|
35
32
|
/**
|
|
36
|
-
*
|
|
37
|
-
* derived key.
|
|
33
|
+
* Derives a single node in the SLIP-21 hierarchical key derivation.
|
|
38
34
|
*
|
|
39
|
-
*
|
|
40
|
-
* compact, human-readable, and shareable identifier suitable for UI display or
|
|
41
|
-
* URL use. While this lowers entropy, 126 bits remains cryptographically secure
|
|
42
|
-
* for uniqueness and unpredictability in most applications (comparable to
|
|
43
|
-
* UUIDv4's 122 bits).
|
|
44
|
-
*
|
|
45
|
-
* See https://github.com/satoshilabs/slips/blob/master/slip-0021.md
|
|
35
|
+
* @see {@link createSlip21}
|
|
46
36
|
*/
|
|
47
|
-
export const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
return id;
|
|
37
|
+
export const deriveSlip21Node = (label, parentNode) => {
|
|
38
|
+
const labelBytes = utf8ToBytes(label);
|
|
39
|
+
const message = new globalThis.Uint8Array(labelBytes.byteLength + 1);
|
|
40
|
+
message[0] = 0;
|
|
41
|
+
message.set(labelBytes, 1);
|
|
42
|
+
return hmac(sha512, parentNode.slice(0, 32), message);
|
|
55
43
|
};
|
|
56
44
|
/** The encryption key for {@link SymmetricCrypto}. */
|
|
57
|
-
export const EncryptionKey = brand("EncryptionKey",
|
|
58
|
-
export const createEncryptionKey = (seed) => createSlip21(seed, ["Evolu", "Encryption Key"]);
|
|
45
|
+
export const EncryptionKey = brand("EncryptionKey", Entropy32);
|
|
59
46
|
/**
|
|
60
47
|
* XChaCha20-Poly1305 encryption
|
|
61
48
|
*
|
|
62
49
|
* https://github.com/paulmillr/noble-ciphers?tab=readme-ov-file#which-cipher-should-i-pick
|
|
63
50
|
*/
|
|
64
51
|
export const createSymmetricCrypto = (deps) => {
|
|
65
|
-
const nonceLength =
|
|
52
|
+
const nonceLength = NonNegativeInt.orThrow(24);
|
|
66
53
|
const symmetricCrypto = {
|
|
67
54
|
nonceLength,
|
|
68
55
|
encrypt: (plaintext, encryptionKey) => {
|
|
69
|
-
const nonce = deps.
|
|
56
|
+
const nonce = deps.randomBytes.create(nonceLength);
|
|
70
57
|
const ciphertext = xchacha20poly1305(encryptionKey, nonce).encrypt(plaintext);
|
|
71
58
|
return { nonce, ciphertext };
|
|
72
59
|
},
|
|
@@ -81,22 +68,22 @@ export const createSymmetricCrypto = (deps) => {
|
|
|
81
68
|
* Returns the PADMÉ padded length for a given input length.
|
|
82
69
|
*
|
|
83
70
|
* PADMÉ limits information leakage about the length of the plain-text for a
|
|
84
|
-
* wide range of encrypted data sizes.
|
|
85
|
-
*
|
|
71
|
+
* wide range of encrypted data sizes.
|
|
72
|
+
*
|
|
73
|
+
* See the PURBs paper for details: https://bford.info/pub/sec/purb.pdf
|
|
86
74
|
*/
|
|
87
|
-
export const
|
|
75
|
+
export const createPadmePaddedLength = (length) => {
|
|
88
76
|
if (length <= 0)
|
|
89
|
-
return 0;
|
|
77
|
+
return NonNegativeInt.orThrow(0);
|
|
90
78
|
const e = 31 - Math.clz32(length >>> 0);
|
|
91
79
|
const s = 32 - Math.clz32(e >>> 0);
|
|
92
80
|
const z = Math.max(0, e - s);
|
|
93
81
|
const mask = (1 << z) - 1;
|
|
94
|
-
return ((length + mask) & ~mask);
|
|
82
|
+
return NonNegativeInt.orThrow((length + mask) & ~mask);
|
|
95
83
|
};
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return (padmePaddedLength(length) - length);
|
|
84
|
+
/** Creates a PADMÉ padding array of zeros for the given input length. */
|
|
85
|
+
export const createPadmePadding = (length) => {
|
|
86
|
+
const paddedLength = createPadmePaddedLength(length);
|
|
87
|
+
const paddingLength = NonNegativeInt.orThrow(paddedLength - length);
|
|
88
|
+
return new globalThis.Uint8Array(paddingLength);
|
|
102
89
|
};
|
package/dist/src/Evolu/Db.d.ts
CHANGED
|
@@ -1,45 +1,153 @@
|
|
|
1
1
|
import { NonEmptyReadonlyArray } from "../Array.js";
|
|
2
2
|
import { CallbackId } from "../Callbacks.js";
|
|
3
|
-
import { ConsoleDep } from "../Console.js";
|
|
4
|
-
import {
|
|
3
|
+
import { ConsoleConfig, ConsoleDep } from "../Console.js";
|
|
4
|
+
import { EncryptionKey, RandomBytesDep, SymmetricCryptoDecryptError } from "../Crypto.js";
|
|
5
5
|
import { TransferableError } from "../Error.js";
|
|
6
|
-
import { NanoIdLibDep } from "../NanoId.js";
|
|
7
6
|
import { RandomDep } from "../Random.js";
|
|
8
|
-
import {
|
|
9
|
-
import { Result } from "../Result.js";
|
|
10
|
-
import { CreateSqliteDriverDep, SafeSql, SqliteDep, SqliteError, SqliteRow } from "../Sqlite.js";
|
|
7
|
+
import { CreateSqliteDriverDep, SqliteError } from "../Sqlite.js";
|
|
11
8
|
import { TimeDep } from "../Time.js";
|
|
12
9
|
import { Id, Mnemonic, SimpleName } from "../Type.js";
|
|
10
|
+
import { CreateWebSocketDep } from "../WebSocket.js";
|
|
13
11
|
import { Worker } from "../Worker.js";
|
|
14
|
-
import { Config } from "./Config.js";
|
|
15
12
|
import { QueryPatches } from "./Diff.js";
|
|
16
|
-
import { AppOwner,
|
|
17
|
-
import {
|
|
13
|
+
import { AppOwner, OwnerTransport } from "./Owner.js";
|
|
14
|
+
import { ProtocolError } from "./Protocol.js";
|
|
18
15
|
import { Query } from "./Query.js";
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
16
|
+
import { DbSchema, MutationChange } from "./Schema.js";
|
|
17
|
+
import { SyncOwner } from "./Sync.js";
|
|
18
|
+
import { TimestampConfig, TimestampError } from "./Timestamp.js";
|
|
19
|
+
export interface DbConfig extends ConsoleConfig, TimestampConfig {
|
|
20
|
+
/**
|
|
21
|
+
* The name of the Evolu instance. Evolu is multitenant - it can run multiple
|
|
22
|
+
* instances concurrently. Each instance must have a unique name.
|
|
23
|
+
*
|
|
24
|
+
* The instance name is used as the SQLite database filename for persistent
|
|
25
|
+
* storage, ensuring that database files are separated and invisible to each
|
|
26
|
+
* other.
|
|
27
|
+
*
|
|
28
|
+
* The default value is: `Evolu`.
|
|
29
|
+
*
|
|
30
|
+
* ### Example
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* // name: SimpleName.orThrow("MyApp")
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
readonly name: SimpleName;
|
|
37
|
+
/**
|
|
38
|
+
* Transport configuration for data sync and backup. Supports single transport
|
|
39
|
+
* or multiple transports simultaneously for redundancy.
|
|
40
|
+
*
|
|
41
|
+
* **Redundancy:** The ideal setup uses at least two completely independent
|
|
42
|
+
* relays - for example, a home relay and a geographically separate relay.
|
|
43
|
+
* Data is sent to both relays simultaneously, providing true redundancy
|
|
44
|
+
* similar to using two independent clouds. This eliminates vendor lock-in and
|
|
45
|
+
* ensures your app continues working regardless of circumstances - whether
|
|
46
|
+
* home relay hardware is stolen or a remote relay provider shuts down.
|
|
47
|
+
*
|
|
48
|
+
* Currently supports:
|
|
49
|
+
*
|
|
50
|
+
* - WebSocket: Real-time bidirectional communication with relay servers
|
|
51
|
+
*
|
|
52
|
+
* Empty transports create local-only instances. Transports can be dynamically
|
|
53
|
+
* added and removed for any owner (including {@link AppOwner}) via
|
|
54
|
+
* {@link Evolu#useOwner}.
|
|
55
|
+
*
|
|
56
|
+
* Use {@link createOwnerWebSocketTransport} to create WebSocket transport
|
|
57
|
+
* configurations with proper URL formatting and {@link OwnerId} inclusion. The
|
|
58
|
+
* {@link OwnerId} in the URL enables relay authentication, allowing relay
|
|
59
|
+
* servers to control access (e.g., for paid tiers or private instances).
|
|
60
|
+
*
|
|
61
|
+
* The default value is:
|
|
62
|
+
*
|
|
63
|
+
* `{ type: "WebSocket", url: "wss://free.evoluhq.com" }`.
|
|
64
|
+
*
|
|
65
|
+
* ### Example
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* // Single WebSocket relay
|
|
69
|
+
* transports: [{ type: "WebSocket", url: "wss://relay1.example.com" }];
|
|
70
|
+
*
|
|
71
|
+
* // Multiple WebSocket relays for redundancy
|
|
72
|
+
* transports: [
|
|
73
|
+
* { type: "WebSocket", url: "wss://relay1.example.com" },
|
|
74
|
+
* { type: "WebSocket", url: "wss://relay2.example.com" },
|
|
75
|
+
* { type: "WebSocket", url: "wss://relay3.example.com" },
|
|
76
|
+
* ];
|
|
77
|
+
*
|
|
78
|
+
* // Local-only instance (no sync) - useful for device settings or when relay
|
|
79
|
+
* // URL will be provided later (e.g., after authentication), allowing users
|
|
80
|
+
* // to work offline before the app connects
|
|
81
|
+
* transports: [];
|
|
82
|
+
*
|
|
83
|
+
* // Using createOwnerWebSocketTransport helper for relay authentication
|
|
84
|
+
* transports: [
|
|
85
|
+
* createOwnerWebSocketTransport({
|
|
86
|
+
* url: "ws://localhost:4000",
|
|
87
|
+
* ownerId,
|
|
88
|
+
* }),
|
|
89
|
+
* ];
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
readonly transports: ReadonlyArray<OwnerTransport>;
|
|
93
|
+
/**
|
|
94
|
+
* External AppOwner to use when creating Evolu instance. Use this when you
|
|
95
|
+
* want to manage AppOwner creation and persistence externally (e.g., with
|
|
96
|
+
* your own authentication system). If omitted, Evolu will automatically
|
|
97
|
+
* create and persist an AppOwner locally.
|
|
98
|
+
*
|
|
99
|
+
* For device-specific settings and account management state, we can use a
|
|
100
|
+
* separate local-only Evolu instance via `transports: []`.
|
|
101
|
+
*
|
|
102
|
+
* ### Example
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* const ConfigId = id("Config");
|
|
106
|
+
* type ConfigId = typeof ConfigId.Type;
|
|
107
|
+
*
|
|
108
|
+
* const DeviceSchema = {
|
|
109
|
+
* config: {
|
|
110
|
+
* id: ConfigId,
|
|
111
|
+
* key: NonEmptyString50,
|
|
112
|
+
* value: NonEmptyString50,
|
|
113
|
+
* },
|
|
114
|
+
* };
|
|
115
|
+
*
|
|
116
|
+
* // Local-only instance for device settings (no sync)
|
|
117
|
+
* const deviceEvolu = createEvolu(evoluReactWebDeps)(DeviceSchema, {
|
|
118
|
+
* name: SimpleName.orThrow("MyApp-Device"),
|
|
119
|
+
* transports: [], // No sync - stays local to device
|
|
120
|
+
* });
|
|
121
|
+
*
|
|
122
|
+
* // Main synced instance for user data
|
|
123
|
+
* const evolu = createEvolu(evoluReactWebDeps)(MainSchema, {
|
|
124
|
+
* name: SimpleName.orThrow("MyApp"),
|
|
125
|
+
* // Default transports for sync
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
readonly externalAppOwner?: AppOwner;
|
|
130
|
+
/**
|
|
131
|
+
* Use in-memory SQLite database instead of persistent storage. Useful for
|
|
132
|
+
* testing or temporary data that doesn't need persistence.
|
|
133
|
+
*
|
|
134
|
+
* In-memory databases exist only in RAM and are completely destroyed when the
|
|
135
|
+
* process ends, making them forensically safe for sensitive data.
|
|
136
|
+
*
|
|
137
|
+
* The default value is: `false`.
|
|
138
|
+
*/
|
|
139
|
+
readonly inMemory?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Encryption key for the SQLite database.
|
|
142
|
+
*
|
|
143
|
+
* Note: If an unencrypted SQLite database already exists and you provide an
|
|
144
|
+
* encryptionKey, SQLite will throw an error.
|
|
145
|
+
*
|
|
146
|
+
* @experimental
|
|
147
|
+
*/
|
|
148
|
+
readonly encryptionKey?: EncryptionKey;
|
|
149
|
+
}
|
|
150
|
+
export declare const defaultDbConfig: DbConfig;
|
|
43
151
|
export type DbWorker = Worker<DbWorkerInput, DbWorkerOutput>;
|
|
44
152
|
export type CreateDbWorker = (name: SimpleName) => DbWorker;
|
|
45
153
|
export interface CreateDbWorkerDep {
|
|
@@ -47,13 +155,14 @@ export interface CreateDbWorkerDep {
|
|
|
47
155
|
}
|
|
48
156
|
export type DbWorkerInput = {
|
|
49
157
|
readonly type: "init";
|
|
50
|
-
readonly config:
|
|
158
|
+
readonly config: DbConfig;
|
|
51
159
|
readonly dbSchema: DbSchema;
|
|
52
|
-
|
|
160
|
+
} | {
|
|
161
|
+
readonly type: "getAppOwner";
|
|
53
162
|
} | {
|
|
54
163
|
readonly type: "mutate";
|
|
55
164
|
readonly tabId: Id;
|
|
56
|
-
readonly changes: NonEmptyReadonlyArray<
|
|
165
|
+
readonly changes: NonEmptyReadonlyArray<MutationChange>;
|
|
57
166
|
readonly onCompleteIds: ReadonlyArray<CallbackId>;
|
|
58
167
|
readonly subscribedQueries: ReadonlyArray<Query>;
|
|
59
168
|
} | {
|
|
@@ -74,20 +183,24 @@ export type DbWorkerInput = {
|
|
|
74
183
|
} | {
|
|
75
184
|
readonly type: "export";
|
|
76
185
|
readonly onCompleteId: CallbackId;
|
|
186
|
+
} | {
|
|
187
|
+
readonly type: "useOwner";
|
|
188
|
+
readonly use: boolean;
|
|
189
|
+
readonly owner: SyncOwner;
|
|
77
190
|
};
|
|
78
191
|
export type DbWorkerOutput = {
|
|
79
|
-
readonly type: "onInit";
|
|
80
|
-
readonly owner: AppOwner;
|
|
81
|
-
} | {
|
|
82
192
|
readonly type: "onError";
|
|
83
|
-
readonly error:
|
|
193
|
+
readonly error: ProtocolError | SqliteError | SymmetricCryptoDecryptError | TimestampError | TransferableError;
|
|
194
|
+
} | {
|
|
195
|
+
readonly type: "onGetAppOwner";
|
|
196
|
+
readonly appOwner: AppOwner;
|
|
84
197
|
} | {
|
|
85
|
-
readonly type: "
|
|
198
|
+
readonly type: "onQueryPatches";
|
|
86
199
|
readonly tabId: Id;
|
|
87
|
-
readonly
|
|
200
|
+
readonly queryPatches: ReadonlyArray<QueryPatches>;
|
|
88
201
|
readonly onCompleteIds: ReadonlyArray<CallbackId>;
|
|
89
202
|
} | {
|
|
90
|
-
readonly type: "
|
|
203
|
+
readonly type: "refreshQueries";
|
|
91
204
|
readonly tabId?: Id;
|
|
92
205
|
} | {
|
|
93
206
|
readonly type: "onReset";
|
|
@@ -98,37 +211,12 @@ export type DbWorkerOutput = {
|
|
|
98
211
|
readonly onCompleteId: CallbackId;
|
|
99
212
|
readonly file: Uint8Array;
|
|
100
213
|
};
|
|
101
|
-
export type DbWorkerPlatformDeps =
|
|
102
|
-
export interface
|
|
103
|
-
readonly
|
|
214
|
+
export type DbWorkerPlatformDeps = ConsoleDep & CreateSqliteDriverDep & CreateWebSocketDep & RandomBytesDep & RandomDep & TimeDep;
|
|
215
|
+
export interface PostMessageDep {
|
|
216
|
+
readonly postMessage: (message: DbWorkerOutput) => void;
|
|
104
217
|
}
|
|
105
|
-
export
|
|
106
|
-
|
|
107
|
-
* Get the current database schema by reading SQLite metadata.
|
|
108
|
-
*
|
|
109
|
-
* TODO: Refactor out Evolu stuff and move it to Sqlite.
|
|
110
|
-
*/
|
|
111
|
-
export declare const getDbSchema: (deps: SqliteDep) => ({ allIndexes }?: {
|
|
112
|
-
allIndexes?: boolean;
|
|
113
|
-
}) => Result<DbSchema, SqliteError>;
|
|
114
|
-
export interface DbSnapshot {
|
|
115
|
-
readonly schema: DbSchema;
|
|
116
|
-
readonly tables: Array<{
|
|
117
|
-
name: string;
|
|
118
|
-
rows: ReadonlyArray<SqliteRow>;
|
|
119
|
-
}>;
|
|
120
|
-
}
|
|
121
|
-
export declare const getDbSnapshot: (deps: SqliteDep) => DbSnapshot;
|
|
122
|
-
export declare const createAppTable: (tableName: string, columns: ReadonlyArray<string>) => SafeSql;
|
|
123
|
-
export declare const applyMessageToTimestampAndHistoryTables: (deps: SqliteDep & ClientStorageDep) => (ownerId: BinaryOwnerId, message: CrdtMessage) => Result<void, SqliteError>;
|
|
124
|
-
export declare const maybeMigrateToVersion0: (deps: SqliteDep) => (schema: DbSchema) => Result<{
|
|
125
|
-
readonly messages: ReadonlyArray<CrdtMessage>;
|
|
126
|
-
readonly mnemonic: Mnemonic;
|
|
127
|
-
readonly lastTimestamp: Timestamp;
|
|
128
|
-
} | null, SqliteError>;
|
|
129
|
-
export interface ClientStorage extends SqliteStorageBase, Storage {
|
|
130
|
-
}
|
|
131
|
-
export interface ClientStorageDep {
|
|
132
|
-
readonly storage: ClientStorage;
|
|
218
|
+
export interface AppOwnerDep {
|
|
219
|
+
readonly appOwner: AppOwner;
|
|
133
220
|
}
|
|
221
|
+
export declare const createDbWorkerForPlatform: (platformDeps: DbWorkerPlatformDeps) => DbWorker;
|
|
134
222
|
//# sourceMappingURL=Db.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Db.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Db.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Db.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAEL,aAAa,EACb,cAAc,EACd,2BAA2B,EAC5B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