@evolu/common 6.0.1-preview.8 → 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 +214 -134
- 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 +600 -454
- 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 +15 -14
- 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 +477 -361
- 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 +842 -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
|
@@ -1,160 +1,313 @@
|
|
|
1
|
+
import { NonEmptyReadonlyArray } from "../Array.js";
|
|
2
|
+
import { EncryptionKey, RandomBytesDep } from "../Crypto.js";
|
|
3
|
+
import { Mnemonic, NonNegativeInt } from "../Type.js";
|
|
4
|
+
import { TimestampBytes } from "./Timestamp.js";
|
|
1
5
|
/**
|
|
2
|
-
*
|
|
6
|
+
* The Owner represents ownership of data in Evolu. Every database change is
|
|
7
|
+
* assigned to an owner, enabling sync functionality and access control.
|
|
3
8
|
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* {@link
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
9
|
+
* Owners enable **partial sync** - applications can choose which owners to
|
|
10
|
+
* sync, allowing selective data synchronization based on specific needs.
|
|
11
|
+
*
|
|
12
|
+
* Owners also provide **real data deletion** - while individual changes in
|
|
13
|
+
* local-first/distributed systems can only be marked as deleted, entire owners
|
|
14
|
+
* can be completely deleted from both relays and devices (except for
|
|
15
|
+
* {@link AppOwner}, which must be preserved for sync coordination).
|
|
16
|
+
*
|
|
17
|
+
* Evolu provides different owner types depending on their use case:
|
|
18
|
+
*
|
|
19
|
+
* - **Coordination**: {@link AppOwner} for sync coordination and long-term
|
|
20
|
+
* persistence
|
|
21
|
+
* - **Data partitioning**: {@link ShardOwner} for partitioning application data
|
|
22
|
+
* - **Collaboration**: {@link SharedOwner} for collaborative write access
|
|
23
|
+
* - **Data sharing**: {@link SharedReadonlyOwner} for read-only access to shared
|
|
24
|
+
* data
|
|
25
|
+
*
|
|
26
|
+
* Owners are cryptographically derived from an {@link OwnerSecret} using
|
|
27
|
+
* SLIP-21, ensuring secure and deterministic key generation:
|
|
28
|
+
*
|
|
29
|
+
* - {@link OwnerId}: Globally unique public identifier
|
|
30
|
+
* - {@link EncryptionKey}: Symmetric encryption key for data protection
|
|
31
|
+
* - {@link OwnerWriteKey}: Authentication token for write operations (rotatable)
|
|
32
|
+
*
|
|
33
|
+
* @see {@link createOwner}
|
|
29
34
|
*/
|
|
30
35
|
export interface Owner {
|
|
31
|
-
readonly mnemonic: Mnemonic;
|
|
32
|
-
readonly createdAt: DateIsoString;
|
|
33
36
|
readonly id: OwnerId;
|
|
34
|
-
readonly encryptionKey:
|
|
35
|
-
readonly writeKey:
|
|
36
|
-
}
|
|
37
|
-
export interface OwnerWithWriteAccess {
|
|
38
|
-
readonly id: OwnerId;
|
|
39
|
-
readonly encryptionKey: EncryptionKey;
|
|
40
|
-
readonly writeKey: WriteKey;
|
|
37
|
+
readonly encryptionKey: OwnerEncryptionKey;
|
|
38
|
+
readonly writeKey: OwnerWriteKey;
|
|
41
39
|
}
|
|
42
40
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* This branded {@link Id} type, generated by {@link createSlip21Id}, is a
|
|
46
|
-
* 21-character {@link Base64Url} string (126 bits of entropy), providing a
|
|
47
|
-
* compact, shareable, and secure identifier for UI use, tied to the owner's
|
|
48
|
-
* mnemonic and derivation path.
|
|
41
|
+
* OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}.
|
|
42
|
+
* Branded from {@link Id} to leverage existing helpers like {@link idToIdBytes}.
|
|
49
43
|
*/
|
|
50
|
-
export declare const OwnerId: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>, "Id", import("../Type.js").
|
|
44
|
+
export declare const OwnerId: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>, "Id", import("../Type.js").IdError, import("../Type.js").StringError>, "OwnerId", import("../Type.js").BrandWithoutRefineError<"OwnerId", import("../Type.js").StringError | import("../Type.js").IdError>, never>;
|
|
51
45
|
export type OwnerId = typeof OwnerId.Type;
|
|
52
|
-
|
|
46
|
+
/** Bytes representation of {@link OwnerId}. */
|
|
47
|
+
export declare const OwnerIdBytes: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("../Type.js").Uint8ArrayError, Uint8Array<ArrayBufferLike>, import("../Type.js").Uint8ArrayError>, "Length16", import("../Type.js").LengthError<16>, import("../Type.js").Uint8ArrayError>, "IdBytes", import("../Type.js").BrandWithoutRefineError<"IdBytes", import("../Type.js").LengthError<16> | import("../Type.js").Uint8ArrayError>, never>, "OwnerIdBytes", import("../Type.js").BrandWithoutRefineError<"OwnerIdBytes", import("../Type.js").BrandWithoutRefineError<"IdBytes", import("../Type.js").LengthError<16> | import("../Type.js").Uint8ArrayError>>, never>;
|
|
48
|
+
export type OwnerIdBytes = typeof OwnerIdBytes.Type;
|
|
49
|
+
export declare const ownerIdToOwnerIdBytes: (ownerId: OwnerId) => OwnerIdBytes;
|
|
50
|
+
export declare const ownerIdBytesToOwnerId: (ownerIdBytes: OwnerIdBytes) => OwnerId;
|
|
51
|
+
export declare const ownerWriteKeyLength: number & import("../Brand.js").Brand<"Int"> & import("../Brand.js").Brand<"NonNegative">;
|
|
52
|
+
export declare const OwnerEncryptionKey: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("../Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length32", import("../Type.js").LengthError<32>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, "EncryptionKey", import("../Type.js").BrandWithoutRefineError<"EncryptionKey", import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError> | import("../Type.js").LengthError<32>>, never>, "OwnerEncryptionKey", import("../Type.js").BrandWithoutRefineError<"OwnerEncryptionKey", import("../Type.js").BrandWithoutRefineError<"EncryptionKey", import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError> | import("../Type.js").LengthError<32>>>, never>;
|
|
53
|
+
export type OwnerEncryptionKey = typeof OwnerEncryptionKey.Type;
|
|
53
54
|
/**
|
|
54
|
-
* A secure token
|
|
55
|
-
*
|
|
55
|
+
* A secure token for write operations. It's derived from {@link OwnerSecret} by
|
|
56
|
+
* default and can be rotated via {@link createOwnerWriteKey}.
|
|
56
57
|
*/
|
|
57
|
-
export declare const
|
|
58
|
-
export type
|
|
58
|
+
export declare const OwnerWriteKey: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("../Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length16", import("../Type.js").LengthError<16>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, "OwnerWriteKey", import("../Type.js").BrandWithoutRefineError<"OwnerWriteKey", import("../Type.js").LengthError<16> | import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, never>;
|
|
59
|
+
export type OwnerWriteKey = typeof OwnerWriteKey.Type;
|
|
59
60
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
|
|
61
|
+
* 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
|
|
62
|
+
*
|
|
63
|
+
* Can be created using {@link createOwnerSecret} or converted from a
|
|
64
|
+
* {@link Mnemonic} using {@link mnemonicToOwnerSecret}.
|
|
65
|
+
*/
|
|
66
|
+
export declare const OwnerSecret: import("../Type.js").BrandType<import("../Type.js").BrandType<import("../Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("../Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length32", import("../Type.js").LengthError<32>, import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError>>, "OwnerSecret", import("../Type.js").BrandWithoutRefineError<"OwnerSecret", import("../Type.js").BrandWithoutRefineError<"Entropy", import("../Type.js").Uint8ArrayError> | import("../Type.js").LengthError<32>>, never>;
|
|
67
|
+
export type OwnerSecret = typeof OwnerSecret.Type;
|
|
68
|
+
/** Creates a {@link OwnerSecret}. */
|
|
69
|
+
export declare const createOwnerSecret: (deps: RandomBytesDep) => OwnerSecret;
|
|
70
|
+
/** Converts an {@link OwnerSecret} to a {@link Mnemonic}. */
|
|
71
|
+
export declare const ownerSecretToMnemonic: (secret: OwnerSecret) => Mnemonic;
|
|
72
|
+
/** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
|
|
73
|
+
export declare const mnemonicToOwnerSecret: (mnemonic: Mnemonic) => OwnerSecret;
|
|
74
|
+
/** Creates a randomly generated {@link OwnerWriteKey}. */
|
|
75
|
+
export declare const createOwnerWriteKey: (deps: RandomBytesDep) => OwnerWriteKey;
|
|
76
|
+
/**
|
|
77
|
+
* Creates an {@link Owner} from a {@link OwnerSecret} using SLIP-21 key
|
|
78
|
+
* derivation.
|
|
79
|
+
*
|
|
80
|
+
* This is an internal helper function, use:
|
|
81
|
+
*
|
|
82
|
+
* - {@link createAppOwner}
|
|
83
|
+
* - {@link createShardOwner}
|
|
84
|
+
* - {@link createSharedOwner}
|
|
85
|
+
* - {@link createSharedReadonlyOwner}
|
|
86
|
+
*/
|
|
87
|
+
export declare const createOwner: (secret: OwnerSecret) => Owner;
|
|
88
|
+
/**
|
|
89
|
+
* The AppOwner represents the application owner. It's created using a
|
|
90
|
+
* cryptographically secure random generator or derived from an external source,
|
|
91
|
+
* e.g., mnemonic stored securely in a hardware device.
|
|
92
|
+
*
|
|
93
|
+
* While it's possible to store all application data in AppOwner, the better
|
|
94
|
+
* approach is to use it only for sync coordination. Storing all app data in
|
|
95
|
+
* AppOwner means that data will be stored/synced forever. And that's a problem
|
|
96
|
+
* if we want to provide real data deletion or in-app data migration without
|
|
97
|
+
* data duplication. In local-first apps/distributed systems, we can't delete
|
|
98
|
+
* individual changes, we only mark them as deleted, otherwise sync could not
|
|
99
|
+
* work.
|
|
100
|
+
*
|
|
101
|
+
* If we really want to delete data or at least avoid syncing it, we must store
|
|
102
|
+
* it using a different owner than AppOwner, e.g. {@link ShardOwner} or
|
|
103
|
+
* {@link SharedOwner}, and delete that owner. The AppOwner itself must be
|
|
104
|
+
* preserved because it coordinates deletion information across devices. Other
|
|
105
|
+
* devices need to sync the information that an owner was deleted so they can
|
|
106
|
+
* delete their local data as well.
|
|
107
|
+
*
|
|
108
|
+
* ### Privacy Considerations
|
|
109
|
+
*
|
|
110
|
+
* AppOwner must never be shared with anyone, except for its {@link OwnerId},
|
|
111
|
+
* which can be used for authorization with
|
|
112
|
+
* {@link createOwnerWebSocketTransport}. It's safe because OwnerId is
|
|
113
|
+
* pseudonymous (it can't be assigned to a specific person).
|
|
114
|
+
*
|
|
115
|
+
* For data sharing scenarios, use {@link SharedOwner} and
|
|
116
|
+
* {@link SharedReadonlyOwner} instead, which are designed specifically for
|
|
117
|
+
* collaborative access.
|
|
65
118
|
*/
|
|
66
119
|
export interface AppOwner extends Owner {
|
|
67
120
|
readonly type: "AppOwner";
|
|
121
|
+
/**
|
|
122
|
+
* The mnemonic that was used to derive the AppOwner keys. Optional when the
|
|
123
|
+
* AppOwner is created from external keys to avoid sharing the mnemonic with
|
|
124
|
+
* the Evolu app.
|
|
125
|
+
*/
|
|
126
|
+
readonly mnemonic?: Mnemonic | null;
|
|
68
127
|
}
|
|
128
|
+
/** Creates an {@link AppOwner} from an {@link OwnerSecret}. */
|
|
129
|
+
export declare const createAppOwner: (secret: OwnerSecret) => AppOwner;
|
|
69
130
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
131
|
+
* An {@link Owner} for sharding data.
|
|
132
|
+
*
|
|
133
|
+
* ShardOwners are the recommended storage location for most application data
|
|
134
|
+
* because they can be completely deleted (both on relays and devices) and
|
|
135
|
+
* conditionally synced.
|
|
136
|
+
*
|
|
137
|
+
* Can be created from {@link OwnerSecret} via {@link createShardOwner} or
|
|
138
|
+
* deterministically derived from {@link AppOwner} using
|
|
139
|
+
* {@link deriveShardOwner}.
|
|
78
140
|
*/
|
|
79
|
-
export interface ShardOwner {
|
|
141
|
+
export interface ShardOwner extends Owner {
|
|
80
142
|
readonly type: "ShardOwner";
|
|
81
|
-
readonly
|
|
82
|
-
readonly writeKey: WriteKey;
|
|
143
|
+
readonly transports?: ReadonlyArray<OwnerTransport>;
|
|
83
144
|
}
|
|
145
|
+
/** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
|
|
146
|
+
export declare const createShardOwner: (secret: OwnerSecret, transports?: ReadonlyArray<OwnerTransport>) => ShardOwner;
|
|
84
147
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
148
|
+
* Derives a {@link ShardOwner} from an {@link AppOwner} using the specified path.
|
|
149
|
+
*
|
|
150
|
+
* **Advantages of derived owners:**
|
|
151
|
+
*
|
|
152
|
+
* - **Deterministic**: Same path always produces the same ShardOwner across all
|
|
153
|
+
* devices
|
|
154
|
+
* - **Immediate availability**: Can be hardcoded and used before sync occurs
|
|
155
|
+
* - **Consistent setup**: All devices start with identical data structure
|
|
156
|
+
* - **Lifecycle management**: Can implement epoch patterns for clean data
|
|
157
|
+
* deletion and recreation
|
|
158
|
+
*
|
|
159
|
+
* **Common patterns:**
|
|
160
|
+
*
|
|
161
|
+
* - Use paths like `["shard", 1]` for versioned data lifecycle
|
|
162
|
+
* - Use paths like `["project", "MyApp", 1]` for named partitions with versions
|
|
163
|
+
* - Each device can derive the same owners and set up initial structure
|
|
94
164
|
*/
|
|
95
|
-
export
|
|
165
|
+
export declare const deriveShardOwner: (owner: AppOwner, path: NonEmptyReadonlyArray<string | number>, transports?: ReadonlyArray<OwnerTransport>) => ShardOwner;
|
|
166
|
+
/** An {@link Owner} for collaborative data with write access. */
|
|
167
|
+
export interface SharedOwner extends Owner {
|
|
96
168
|
readonly type: "SharedOwner";
|
|
97
|
-
readonly
|
|
98
|
-
readonly writeKey: WriteKey;
|
|
169
|
+
readonly transports?: ReadonlyArray<OwnerTransport>;
|
|
99
170
|
}
|
|
100
171
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
172
|
+
* Creates a {@link SharedOwner} from an {@link OwnerSecret} for collaborative
|
|
173
|
+
* write access.
|
|
174
|
+
*
|
|
175
|
+
* Use {@link createSharedReadonlyOwner} to create a read-only version for
|
|
176
|
+
* sharing.
|
|
177
|
+
*/
|
|
178
|
+
export declare const createSharedOwner: (secret: OwnerSecret, transports?: ReadonlyArray<OwnerTransport>) => SharedOwner;
|
|
179
|
+
/**
|
|
180
|
+
* Read-only version of a {@link SharedOwner} for data sharing. Contains only the
|
|
181
|
+
* {@link OwnerId} and {@link EncryptionKey} needed for others to read the shared
|
|
182
|
+
* data without write access.
|
|
106
183
|
*/
|
|
107
184
|
export interface SharedReadonlyOwner {
|
|
108
185
|
readonly type: "SharedReadonlyOwner";
|
|
109
|
-
readonly
|
|
186
|
+
readonly id: OwnerId;
|
|
187
|
+
readonly encryptionKey: EncryptionKey;
|
|
188
|
+
readonly transports?: ReadonlyArray<OwnerTransport>;
|
|
110
189
|
}
|
|
190
|
+
/** Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner}. */
|
|
191
|
+
export declare const createSharedReadonlyOwner: (sharedOwner: SharedOwner) => SharedReadonlyOwner;
|
|
111
192
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
export declare const createAppOwner: (deps: TimeDep & CreateRandomBytesDep & CreateMnemonicDep) => (mnemonic?: string & import("../Types.js").Brand<"Trimmed"> & import("../Types.js").Brand<"MinLength1"> & import("../Types.js").Brand<"Mnemonic">) => AppOwner;
|
|
116
|
-
/**
|
|
117
|
-
* Creates a {@link ShardOwner} for sharding app data with a freshly generated
|
|
118
|
-
* mnemonic. Unlike {@link createAppOwner}, it doesn’t accept an existing
|
|
119
|
-
* mnemonic because ShardOwner mnemonics are always generated and restored
|
|
120
|
-
* automatically via database sync.
|
|
121
|
-
*/
|
|
122
|
-
export declare const createShardOwner: (deps: TimeDep & CreateRandomBytesDep & CreateMnemonicDep) => ShardOwner;
|
|
123
|
-
/**
|
|
124
|
-
* Creates a fresh {@link SharedOwner} for sharing data with write access. Takes
|
|
125
|
-
* no arguments as both `mnemonic` and rotatable `writeKey` are newly generated;
|
|
126
|
-
* when shared, recipients use the provided `mnemonic` and `writeKey` directly
|
|
127
|
-
* as a {@link SharedOwner} without needing to recreate it.
|
|
193
|
+
* Transport configuration for connecting to relays.
|
|
194
|
+
*
|
|
195
|
+
* Currently only WebSocket, in the future Bluetooth, LocalNetwork, etc.
|
|
128
196
|
*/
|
|
129
|
-
export
|
|
197
|
+
export type OwnerTransport = OwnerWebSocketTransport;
|
|
130
198
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
199
|
+
* WebSocket transport configuration.
|
|
200
|
+
*
|
|
201
|
+
* ### Authentication via URL
|
|
202
|
+
*
|
|
203
|
+
* The {@link OwnerId} is passed as a URL query parameter. While this approach is
|
|
204
|
+
* generally discouraged for authentication tokens (they get logged), it's safe
|
|
205
|
+
* here because OwnerId is pseudonymous and used only for access verification -
|
|
206
|
+
* it provides no ability to read encrypted data or write changes.
|
|
207
|
+
*
|
|
208
|
+
* See: [HTTP headers in Websockets client
|
|
209
|
+
* API](https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api/74564827#74564827)
|
|
210
|
+
*
|
|
211
|
+
* ### Error Handling
|
|
212
|
+
*
|
|
213
|
+
* When a relay rejects a connection (invalid OwnerId, unauthorized owner, or
|
|
214
|
+
* server error), the browser WebSocket API does not expose the specific HTTP
|
|
215
|
+
* status code or reason - it only reports a generic connection failure. The
|
|
216
|
+
* client automatically retries with exponential backoff and jitter, eventually
|
|
217
|
+
* succeeding once the configuration or server issue is resolved.
|
|
218
|
+
*
|
|
219
|
+
* Legitimate clients will be properly configured with valid credentials, so
|
|
220
|
+
* automatic retry is OK.
|
|
221
|
+
*
|
|
222
|
+
* @see {@link createOwnerWebSocketTransport}
|
|
223
|
+
* @see {@link parseOwnerIdFromOwnerWebSocketTransportUrl}
|
|
134
224
|
*/
|
|
135
|
-
export
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
225
|
+
export interface OwnerWebSocketTransport {
|
|
226
|
+
readonly type: "WebSocket";
|
|
227
|
+
readonly url: string;
|
|
228
|
+
}
|
|
139
229
|
/**
|
|
140
|
-
*
|
|
141
|
-
* {@link
|
|
142
|
-
*
|
|
143
|
-
*
|
|
230
|
+
* Creates an {@link OwnerWebSocketTransport} for the given relay URL and
|
|
231
|
+
* {@link OwnerId}.
|
|
232
|
+
*
|
|
233
|
+
* The URL must be a WebSocket base URL without query parameters or fragments
|
|
234
|
+
* (e.g., `wss://relay.evolu.dev`, not `wss://relay.evolu.dev?foo=bar`). The
|
|
235
|
+
* function appends the `ownerId` as a query parameter.
|
|
236
|
+
*
|
|
237
|
+
* ### Example
|
|
238
|
+
*
|
|
239
|
+
* ```ts
|
|
240
|
+
* // Create transport "wss://relay.evolu.dev?ownerId=..."
|
|
241
|
+
* const transport = createOwnerWebSocketTransport({
|
|
242
|
+
* url: "wss://relay.evolu.dev",
|
|
243
|
+
* ownerId: owner.id,
|
|
244
|
+
* });
|
|
245
|
+
*
|
|
246
|
+
* // Use with createEvolu
|
|
247
|
+
* const evolu = createEvolu(deps)(Schema, {
|
|
248
|
+
* transports: [transport],
|
|
249
|
+
* });
|
|
250
|
+
* ```
|
|
144
251
|
*/
|
|
145
|
-
export
|
|
146
|
-
readonly
|
|
147
|
-
readonly
|
|
148
|
-
};
|
|
252
|
+
export declare const createOwnerWebSocketTransport: (config: {
|
|
253
|
+
readonly url: string;
|
|
254
|
+
readonly ownerId: OwnerId;
|
|
255
|
+
}) => OwnerWebSocketTransport;
|
|
149
256
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
257
|
+
* Extracts {@link OwnerId} from an {@link OwnerWebSocketTransport} URL query
|
|
258
|
+
* string.
|
|
259
|
+
*
|
|
260
|
+
* Parses the query string `?ownerId=...` and validates that the extracted value
|
|
261
|
+
* is a valid {@link OwnerId}.
|
|
262
|
+
*
|
|
263
|
+
* ### Example
|
|
264
|
+
*
|
|
265
|
+
* ```ts
|
|
266
|
+
* parseOwnerIdFromOwnerWebSocketTransportUrl(
|
|
267
|
+
* "/sync?ownerId=_12345678abcdefgh",
|
|
268
|
+
* );
|
|
269
|
+
* // Returns: OwnerId or null
|
|
270
|
+
* ```
|
|
153
271
|
*/
|
|
154
|
-
export declare const
|
|
272
|
+
export declare const parseOwnerIdFromOwnerWebSocketTransportUrl: (url: string) => OwnerId | null;
|
|
273
|
+
/** Base interface for all owner errors. */
|
|
274
|
+
export interface BaseOwnerError {
|
|
275
|
+
readonly ownerId: OwnerId;
|
|
276
|
+
}
|
|
155
277
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
278
|
+
* Usage data for an {@link OwnerId}.
|
|
279
|
+
*
|
|
280
|
+
* Tracks storage usage to enforce quotas if needed, and some other stuff.
|
|
281
|
+
*
|
|
282
|
+
* TODO:
|
|
283
|
+
*
|
|
284
|
+
* - Add transferredBytes for billing and monitoring network usage.
|
|
158
285
|
*/
|
|
159
|
-
export
|
|
286
|
+
export interface OwnerUsage {
|
|
287
|
+
/** The {@link Owner} this usage data belongs to. */
|
|
288
|
+
readonly ownerId: OwnerIdBytes;
|
|
289
|
+
/**
|
|
290
|
+
* Total logical data bytes stored.
|
|
291
|
+
*
|
|
292
|
+
* Measures the size of {@link EncryptedDbChange}s only, excluding
|
|
293
|
+
* {@link Storage} implementation overhead (with SqliteStorage: indexes,
|
|
294
|
+
* skiplist columns, etc.). This provides:
|
|
295
|
+
*
|
|
296
|
+
* - **Predictable measurement** - same data = same byte count across all
|
|
297
|
+
* instances
|
|
298
|
+
* - **Quota enforcement** - consistent billing/limits independent of storage
|
|
299
|
+
* implementation
|
|
300
|
+
* - **Overhead tracking** - actual Storage size can be compared against this to
|
|
301
|
+
* monitor efficiency
|
|
302
|
+
*/
|
|
303
|
+
readonly storedBytes: NonNegativeInt;
|
|
304
|
+
/** Tracks the earliest timestamp for timestamp insertion strategies. */
|
|
305
|
+
readonly firstTimestamp: TimestampBytes | null;
|
|
306
|
+
/**
|
|
307
|
+
* Tracks the latest timestamp for timestamp insertion strategies.
|
|
308
|
+
*
|
|
309
|
+
* Free relays can use it to identify inactive accounts for cleanup.
|
|
310
|
+
*/
|
|
311
|
+
readonly lastTimestamp: TimestampBytes | null;
|
|
312
|
+
}
|
|
160
313
|
//# sourceMappingURL=Owner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Owner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Owner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAEL,aAAa,EAGb,cAAc,EACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAML,QAAQ,EACR,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,aAAa,EAAE,kBAAkB,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;CAClC;AAED;;;GAGG;AACH,eAAO,MAAM,OAAO,mZAAuB,CAAC;AAC5C,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAC;AAE1C,+CAA+C;AAC/C,eAAO,MAAM,YAAY,uvBAAiC,CAAC;AAC3D,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;AAEpD,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,KAAG,YACnB,CAAC;AAEvC,eAAO,MAAM,qBAAqB,GAAI,cAAc,YAAY,KAAG,OAClB,CAAC;AAElD,eAAO,MAAM,mBAAmB,0FAA6B,CAAC;AAE9D,eAAO,MAAM,kBAAkB,8/BAA6C,CAAC;AAC7E,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,aAAa,wrBAAoC,CAAC;AAC/D,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAC;AAEtD;;;;;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