@evolu/common 6.0.1-preview.19 → 6.0.1-preview.20
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/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +1 -1
- package/dist/src/Buffer.d.ts +1 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +1 -1
- package/dist/src/CallbackRegistry.d.ts +53 -0
- package/dist/src/CallbackRegistry.d.ts.map +1 -0
- package/dist/src/CallbackRegistry.js +25 -0
- 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 +48 -37
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +27 -50
- package/dist/src/Evolu/Db.d.ts +138 -66
- package/dist/src/Evolu/Db.d.ts.map +1 -1
- package/dist/src/Evolu/Db.js +248 -645
- 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 +79 -116
- package/dist/src/Evolu/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu/Evolu.js +275 -132
- 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 +144 -0
- package/dist/src/Evolu/LocalAuth.d.ts.map +1 -0
- package/dist/src/Evolu/LocalAuth.js +171 -0
- package/dist/src/Evolu/Owner.d.ts +129 -83
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +80 -89
- 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 +114 -191
- package/dist/src/Evolu/Protocol.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.js +409 -416
- 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.js +3 -3
- package/dist/src/Evolu/Relay.d.ts +1 -2
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +11 -9
- package/dist/src/Evolu/Schema.d.ts +88 -27
- package/dist/src/Evolu/Schema.d.ts.map +1 -1
- package/dist/src/Evolu/Schema.js +141 -24
- package/dist/src/Evolu/Storage.d.ts +158 -14
- package/dist/src/Evolu/Storage.d.ts.map +1 -1
- package/dist/src/Evolu/Storage.js +32 -32
- package/dist/src/Evolu/Sync.d.ts +77 -13
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +453 -20
- package/dist/src/Evolu/Timestamp.d.ts +29 -27
- package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
- package/dist/src/Evolu/Timestamp.js +20 -18
- package/dist/src/ManyToManyMap.d.ts +74 -10
- package/dist/src/ManyToManyMap.d.ts.map +1 -1
- package/dist/src/ManyToManyMap.js +41 -6
- package/dist/src/Random.d.ts +3 -2
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/RefCountedResourceManager.d.ts +119 -0
- package/dist/src/RefCountedResourceManager.d.ts.map +1 -0
- package/dist/src/RefCountedResourceManager.js +197 -0
- package/dist/src/Result.d.ts +144 -22
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +5 -2
- package/dist/src/Sqlite.d.ts +20 -4
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +50 -8
- package/dist/src/Task.d.ts +511 -0
- package/dist/src/Task.d.ts.map +1 -0
- package/dist/src/Task.js +410 -0
- package/dist/src/Time.d.ts +59 -0
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +87 -4
- package/dist/src/Type.d.ts +431 -341
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +458 -466
- package/dist/src/WebSocket.d.ts +5 -2
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +12 -13
- 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 +2 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -3
- package/package.json +7 -7
- package/src/Assert.ts +2 -4
- package/src/Buffer.ts +1 -1
- package/src/CallbackRegistry.ts +84 -0
- package/src/Console.ts +91 -11
- package/src/Crypto.ts +78 -91
- package/src/Evolu/Db.ts +455 -947
- package/src/Evolu/Diff.ts +7 -5
- package/src/Evolu/Evolu.ts +545 -307
- package/src/Evolu/Internal.ts +0 -2
- package/src/Evolu/LocalAuth.ts +422 -0
- package/src/Evolu/Owner.ts +191 -131
- package/src/Evolu/Platform.ts +9 -9
- package/src/Evolu/Protocol.ts +536 -653
- package/src/Evolu/Public.ts +7 -9
- package/src/Evolu/PublicKysely.ts +3 -3
- package/src/Evolu/Relay.ts +17 -12
- package/src/Evolu/Schema.ts +271 -66
- package/src/Evolu/Storage.ts +263 -55
- package/src/Evolu/Sync.ts +758 -37
- package/src/Evolu/Timestamp.ts +30 -35
- package/src/ManyToManyMap.ts +127 -24
- package/src/Random.ts +3 -2
- package/src/RefCountedResourceManager.ts +368 -0
- package/src/Result.ts +149 -23
- package/src/Sqlite.ts +59 -24
- package/src/Task.ts +779 -0
- package/src/Time.ts +168 -4
- package/src/Type.ts +657 -695
- package/src/WebSocket.ts +23 -17
- package/src/Worker.ts +72 -23
- package/src/index.ts +2 -3
- package/dist/src/Callbacks.d.ts +0 -20
- package/dist/src/Callbacks.d.ts.map +0 -1
- package/dist/src/Callbacks.js +0 -18
- package/dist/src/Evolu/Config.d.ts +0 -82
- 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/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/Callbacks.ts +0 -43
- package/src/Evolu/Config.ts +0 -97
- package/src/Evolu/Kysely.ts +0 -38
- package/src/NanoId.ts +0 -39
- package/src/Promise.ts +0 -295
package/dist/src/Evolu/Owner.js
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
|
|
1
|
+
import * as bip39 from "@scure/bip39";
|
|
2
|
+
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
3
|
+
import { createSlip21, EncryptionKey, Entropy16, Entropy32, } from "../Crypto.js";
|
|
4
|
+
import { brand, Id, IdBytes, idBytesToId, idToIdBytes, } from "../Type.js";
|
|
2
5
|
/**
|
|
3
|
-
*
|
|
6
|
+
* 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
|
|
4
7
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - **{@link OwnerId}**: Globally unique public identifier
|
|
9
|
-
* - **{@link EncryptionKey}**: Symmetric encryption key for data protection
|
|
10
|
-
* - **{@link WriteKey}**: Authentication token for write operations
|
|
11
|
-
*
|
|
12
|
-
* Every Evolu app has at least one owner, the {@link AppOwner}. There are
|
|
13
|
-
* several owner variants for different use cases:
|
|
14
|
-
*
|
|
15
|
-
* **{@link ShardOwner}**: Derived from {@link AppOwner} for partitioning data and
|
|
16
|
-
* selective synchronization using {@link createShardOwner}
|
|
17
|
-
*
|
|
18
|
-
* **{@link SharedOwner}**: Created for collaboration with write access, not
|
|
19
|
-
* meant to be shared directly
|
|
20
|
-
*
|
|
21
|
-
* **{@link SharedReadonlyOwner}**: Read-only version for safe data sharing,
|
|
22
|
-
* created from {@link SharedOwner} using {@link createSharedReadonlyOwner}
|
|
23
|
-
*
|
|
24
|
-
* Owners are designed for data synchronization and backup. Authentication
|
|
25
|
-
* systems built on public/private key cryptography use these primitives. This
|
|
26
|
-
* design ensures Evolu Relay knows as little as possible - it only sees
|
|
27
|
-
* Timestamp, OwnerId, and EncryptedDbChange.
|
|
28
|
-
*
|
|
29
|
-
* @module
|
|
8
|
+
* Can be created using {@link createOwnerSecret} or converted from a
|
|
9
|
+
* {@link Mnemonic} using {@link mnemonicToOwnerSecret}.
|
|
30
10
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
export const OwnerSecret = brand("OwnerSecret", Entropy32);
|
|
12
|
+
/** Creates a {@link OwnerSecret}. */
|
|
13
|
+
export const createOwnerSecret = (deps) => deps.randomBytes.create(32);
|
|
14
|
+
/** Converts an {@link OwnerSecret} to a {@link Mnemonic}. */
|
|
15
|
+
export const ownerSecretToMnemonic = (secret) => bip39.entropyToMnemonic(secret, wordlist);
|
|
16
|
+
/** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
|
|
17
|
+
export const mnemonicToOwnerSecret = (mnemonic) => bip39.mnemonicToEntropy(mnemonic, wordlist);
|
|
33
18
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* This branded {@link Id} type, generated by {@link createSlip21Id}, is a
|
|
37
|
-
* 21-character {@link Base64Url} string (126 bits of entropy), providing a
|
|
38
|
-
* compact, shareable, and secure identifier for UI use, tied to the owner's
|
|
39
|
-
* mnemonic and derivation path.
|
|
19
|
+
* OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}.
|
|
20
|
+
* Branded from {@link Id} to leverage existing helpers like {@link idToIdBytes}.
|
|
40
21
|
*/
|
|
41
22
|
export const OwnerId = brand("OwnerId", Id);
|
|
42
|
-
|
|
23
|
+
/** Bytes representation of {@link OwnerId}. */
|
|
24
|
+
export const OwnerIdBytes = brand("OwnerIdBytes", IdBytes);
|
|
25
|
+
export const ownerIdToOwnerIdBytes = (ownerId) => idToIdBytes(ownerId);
|
|
26
|
+
export const ownerIdBytesToOwnerId = (ownerIdBytes) => idBytesToId(ownerIdBytes);
|
|
27
|
+
export const ownerWriteKeyLength = 16;
|
|
28
|
+
export const OwnerEncryptionKey = brand("OwnerEncryptionKey", EncryptionKey);
|
|
43
29
|
/**
|
|
44
|
-
* A secure token
|
|
45
|
-
*
|
|
30
|
+
* A secure token for write operations. It's derived from {@link OwnerSecret} by
|
|
31
|
+
* default and can be rotated via {@link createOwnerWriteKey}.
|
|
46
32
|
*/
|
|
47
|
-
export const
|
|
48
|
-
/** Creates a randomly generated {@link
|
|
49
|
-
export const
|
|
50
|
-
/** Creates an {@link Owner} from a {@link Mnemonic} using SLIP-21 key derivation. */
|
|
51
|
-
export const createOwner = (mnemonic) => {
|
|
52
|
-
const seed = mnemonicToMnemonicSeed(mnemonic);
|
|
53
|
-
return createOwnerFromMnemonicSeed(seed);
|
|
54
|
-
};
|
|
33
|
+
export const OwnerWriteKey = brand("OwnerWriteKey", Entropy16);
|
|
34
|
+
/** Creates a randomly generated {@link OwnerWriteKey}. */
|
|
35
|
+
export const createOwnerWriteKey = (deps) => deps.randomBytes.create(16);
|
|
55
36
|
/**
|
|
56
|
-
* Creates an {@link Owner} from a {@link
|
|
37
|
+
* Creates an {@link Owner} from a {@link OwnerSecret} using SLIP-21 key
|
|
57
38
|
* derivation.
|
|
39
|
+
*
|
|
40
|
+
* This is an internal helper function, use:
|
|
41
|
+
*
|
|
42
|
+
* - {@link createAppOwner}
|
|
43
|
+
* - {@link createShardOwner}
|
|
44
|
+
* - {@link createSharedOwner}
|
|
45
|
+
* - {@link createSharedReadonlyOwner}
|
|
58
46
|
*/
|
|
59
|
-
export const
|
|
60
|
-
id:
|
|
61
|
-
encryptionKey: createSlip21(
|
|
62
|
-
|
|
63
|
-
"Encryption Key",
|
|
64
|
-
]),
|
|
65
|
-
writeKey: createSlip21(seed, ["Evolu", "Write Key"]).slice(0, 16),
|
|
47
|
+
export const createOwner = (secret) => ({
|
|
48
|
+
id: ownerIdBytesToOwnerId(OwnerIdBytes.orThrow(createSlip21(secret, ["Evolu", "OwnerIdBytes"]).slice(0, 16))),
|
|
49
|
+
encryptionKey: OwnerEncryptionKey.orThrow(createSlip21(secret, ["Evolu", "OwnerEncryptionKey"])),
|
|
50
|
+
writeKey: OwnerWriteKey.orThrow(createSlip21(secret, ["Evolu", "OwnerWriteKey"]).slice(0, 16)),
|
|
66
51
|
});
|
|
67
|
-
|
|
52
|
+
/** Creates an {@link AppOwner} from an {@link OwnerSecret}. */
|
|
53
|
+
export const createAppOwner = (secret) => ({
|
|
68
54
|
type: "AppOwner",
|
|
69
|
-
mnemonic,
|
|
70
|
-
...createOwner(
|
|
55
|
+
mnemonic: ownerSecretToMnemonic(secret),
|
|
56
|
+
...createOwner(secret),
|
|
71
57
|
});
|
|
58
|
+
/** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
|
|
59
|
+
export const createShardOwner = (secret, transports) => {
|
|
60
|
+
return {
|
|
61
|
+
type: "ShardOwner",
|
|
62
|
+
...createOwner(secret),
|
|
63
|
+
...(transports && { transports }),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
72
66
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
67
|
+
* Derives a {@link ShardOwner} from an {@link AppOwner} using the specified path.
|
|
68
|
+
*
|
|
69
|
+
* **Advantages of derived owners:**
|
|
75
70
|
*
|
|
76
|
-
*
|
|
71
|
+
* - **Deterministic**: Same path always produces the same ShardOwner across all
|
|
72
|
+
* devices
|
|
73
|
+
* - **Immediate availability**: Can be hardcoded and used before sync occurs
|
|
74
|
+
* - **Consistent setup**: All devices start with identical data structure
|
|
75
|
+
* - **Lifecycle management**: Can implement epoch patterns for clean data
|
|
76
|
+
* deletion and recreation
|
|
77
77
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* ]);
|
|
84
|
-
* ```
|
|
78
|
+
* **Common patterns:**
|
|
79
|
+
*
|
|
80
|
+
* - Use paths like `["shard", 1]` for versioned data lifecycle
|
|
81
|
+
* - Use paths like `["project", "MyApp", 1]` for named partitions with versions
|
|
82
|
+
* - Each device can derive the same owners and set up initial structure
|
|
85
83
|
*/
|
|
86
|
-
export const
|
|
87
|
-
|
|
88
|
-
* The shardSeed is never shared or persisted, only used for SLIP-21
|
|
89
|
-
* derivation to create shard-specific keys.
|
|
90
|
-
*/
|
|
91
|
-
const shardSeed = createSlip21(appOwner.encryptionKey, path);
|
|
84
|
+
export const deriveShardOwner = (owner, path, transports) => {
|
|
85
|
+
const secret = createSlip21(owner.encryptionKey, path);
|
|
92
86
|
return {
|
|
93
87
|
type: "ShardOwner",
|
|
94
|
-
...
|
|
88
|
+
...createOwner(secret),
|
|
89
|
+
...(transports && { transports }),
|
|
95
90
|
};
|
|
96
91
|
};
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Creates a {@link SharedOwner} from an {@link OwnerSecret} for collaborative
|
|
94
|
+
* write access.
|
|
95
|
+
*
|
|
96
|
+
* Use {@link createSharedReadonlyOwner} to create a read-only version for
|
|
97
|
+
* sharing.
|
|
98
|
+
*/
|
|
99
|
+
export const createSharedOwner = (secret, transports) => {
|
|
100
100
|
return {
|
|
101
101
|
type: "SharedOwner",
|
|
102
|
-
|
|
103
|
-
...
|
|
102
|
+
...createOwner(secret),
|
|
103
|
+
...(transports && { transports }),
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
106
|
/** Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner}. */
|
|
@@ -108,14 +108,5 @@ export const createSharedReadonlyOwner = (sharedOwner) => ({
|
|
|
108
108
|
type: "SharedReadonlyOwner",
|
|
109
109
|
id: sharedOwner.id,
|
|
110
110
|
encryptionKey: sharedOwner.encryptionKey,
|
|
111
|
+
...(sharedOwner.transports && { transports: sharedOwner.transports }),
|
|
111
112
|
});
|
|
112
|
-
/**
|
|
113
|
-
* Rotates the {@link WriteKey} for an {@link AppOwner}, {@link ShardOwner}, or
|
|
114
|
-
* {@link SharedOwner}, returning a new instance with the updated key.
|
|
115
|
-
*/
|
|
116
|
-
export const rotateWriteKey = (owner, newWriteKey) => {
|
|
117
|
-
return {
|
|
118
|
-
...owner,
|
|
119
|
-
writeKey: newWriteKey,
|
|
120
|
-
};
|
|
121
|
-
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Config } from "./Config.js";
|
|
2
1
|
/**
|
|
3
2
|
* FlushSync is for libraries like React to flush updates synchronously inside
|
|
4
3
|
* the provided callback to ensure the DOM is updated immediately.
|
|
@@ -13,11 +12,14 @@ export type FlushSync = (callback: () => void) => void;
|
|
|
13
12
|
export interface FlushSyncDep {
|
|
14
13
|
readonly flushSync: FlushSync;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Reload the app in a platform-specific way.
|
|
17
|
+
*
|
|
18
|
+
* - **Web**: Redirects to the specified URL
|
|
19
|
+
* - **React Native**: Restarts the app (URL parameter ignored)
|
|
20
|
+
*/
|
|
21
|
+
export type ReloadApp = (url: string) => void;
|
|
22
|
+
export interface ReloadAppDep {
|
|
23
|
+
readonly reloadApp: ReloadApp;
|
|
22
24
|
}
|
|
23
25
|
//# sourceMappingURL=Platform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Platform.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;AAEvD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B"}
|