@evolu/common 7.2.1 → 7.2.3
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/Object.d.ts +16 -1
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +16 -1
- package/dist/src/Order.d.ts +2 -1
- package/dist/src/Order.d.ts.map +1 -1
- package/dist/src/Order.js +1 -0
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +4 -1
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +5 -11
- package/dist/src/local-first/Diff.js +2 -2
- package/dist/src/local-first/Evolu.d.ts +14 -11
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +8 -5
- package/dist/src/local-first/Owner.d.ts +39 -42
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +22 -29
- package/dist/src/local-first/Protocol.d.ts +6 -6
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +2 -2
- package/dist/src/local-first/Public.d.ts +1 -0
- package/dist/src/local-first/Public.d.ts.map +1 -1
- package/dist/src/local-first/Storage.d.ts +3 -3
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Sync.d.ts +10 -17
- package/dist/src/local-first/Sync.d.ts.map +1 -1
- package/dist/src/local-first/Sync.js +108 -130
- package/dist/src/local-first/Timestamp.d.ts +13 -0
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +14 -1
- package/package.json +1 -1
- package/src/Object.ts +20 -1
- package/src/Order.ts +2 -1
- package/src/WebSocket.ts +6 -1
- package/src/local-first/Db.ts +5 -12
- package/src/local-first/Diff.ts +2 -2
- package/src/local-first/Evolu.ts +27 -15
- package/src/local-first/Owner.ts +47 -57
- package/src/local-first/Protocol.ts +8 -8
- package/src/local-first/Public.ts +1 -0
- package/src/local-first/Storage.ts +3 -3
- package/src/local-first/Sync.ts +123 -175
- package/src/local-first/Timestamp.ts +14 -1
package/dist/src/Object.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ type StringKeyOf<T> = Extract<keyof T, string>;
|
|
|
24
24
|
*
|
|
25
25
|
* ```ts
|
|
26
26
|
* type UserId = string & { readonly __brand: "UserId" };
|
|
27
|
-
* const users
|
|
27
|
+
* const users = createRecord<UserId, string>();
|
|
28
28
|
* const entries = objectToEntries(users); // [UserId, string][]
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
@@ -37,5 +37,20 @@ export declare const objectToEntries: <T extends Record<string, any>>(record: T)
|
|
|
37
37
|
export declare const mapObject: <K extends string, V, U>(record: ReadonlyRecord<K, V>, fn: (value: V, key: K) => U) => ReadonlyRecord<K, U>;
|
|
38
38
|
/** Conditionally excludes a property from an object. */
|
|
39
39
|
export declare const excludeProp: <T extends object, K extends keyof T>(obj: T, prop: K, condition?: boolean) => typeof condition extends true ? T : Omit<T, K>;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a prototype-less object typed as `Record<K, V>`.
|
|
42
|
+
*
|
|
43
|
+
* Use this function when you need a plain record without a prototype chain
|
|
44
|
+
* (e.g. when keys are controlled by external sources) to avoid prototype
|
|
45
|
+
* pollution and accidental collisions with properties like `__proto__`.
|
|
46
|
+
*
|
|
47
|
+
* Example:
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* const values = createRecord<string, SqliteValue>();
|
|
51
|
+
* values["__proto__"] = someValue; // safe, no prototype pollution
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const createRecord: <K extends string = string, V = unknown>() => Record<K, V>;
|
|
40
55
|
export {};
|
|
41
56
|
//# sourceMappingURL=Object.d.ts.map
|
package/dist/src/Object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Object.d.ts","sourceRoot":"","sources":["../../src/Object.ts"],"names":[],"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 +18,7 @@ export const isPlainObject = (value) => Object.prototype.toString.call(value) ==
|
|
|
18
18
|
*
|
|
19
19
|
* ```ts
|
|
20
20
|
* type UserId = string & { readonly __brand: "UserId" };
|
|
21
|
-
* const users
|
|
21
|
+
* const users = createRecord<UserId, string>();
|
|
22
22
|
* const entries = objectToEntries(users); // [UserId, string][]
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
@@ -40,3 +40,18 @@ export const excludeProp = (obj, prop, condition) => {
|
|
|
40
40
|
const { [prop]: _, ...rest } = obj;
|
|
41
41
|
return rest;
|
|
42
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Creates a prototype-less object typed as `Record<K, V>`.
|
|
45
|
+
*
|
|
46
|
+
* Use this function when you need a plain record without a prototype chain
|
|
47
|
+
* (e.g. when keys are controlled by external sources) to avoid prototype
|
|
48
|
+
* pollution and accidental collisions with properties like `__proto__`.
|
|
49
|
+
*
|
|
50
|
+
* Example:
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* const values = createRecord<string, SqliteValue>();
|
|
54
|
+
* values["__proto__"] = someValue; // safe, no prototype pollution
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export const createRecord = () => Object.create(null);
|
package/dist/src/Order.d.ts
CHANGED
|
@@ -81,5 +81,6 @@ export declare const orderNumber: Order<number>;
|
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
83
|
export declare const orderBigInt: Order<bigint>;
|
|
84
|
-
|
|
84
|
+
/** An {@link Order} for Uint8Array. */
|
|
85
|
+
export declare const orderUint8Array: Order<Uint8Array>;
|
|
85
86
|
//# sourceMappingURL=Order.d.ts.map
|
package/dist/src/Order.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Order.d.ts","sourceRoot":"","sources":["../../src/Order.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,C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Y,GACtB,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC,CAEhB,CAAC;AAEhB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,MAAM,CAAgC,CAAC;AAEvE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,eAAuC,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,eAAuC,CAAC;AAEhE,uCAAuC;AACvC,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,UAAU,CAU7C,CAAC"}
|
package/dist/src/Order.js
CHANGED
|
@@ -65,6 +65,7 @@ export const orderNumber = createOrder((a, b) => a < b);
|
|
|
65
65
|
* ```
|
|
66
66
|
*/
|
|
67
67
|
export const orderBigInt = createOrder((a, b) => a < b);
|
|
68
|
+
/** An {@link Order} for Uint8Array. */
|
|
68
69
|
export const orderUint8Array = (a, b) => {
|
|
69
70
|
if (a.byteLength > b.byteLength)
|
|
70
71
|
return 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocket.d.ts","sourceRoot":"","sources":["../../src/WebSocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAS,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAG5D,yDAAyD;AACzD,MAAM,WAAW,SAAU,SAAQ,UAAU;IAC3C;;;OAGG;IACH,IAAI,EAAE,CACJ,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,GAAG,eAAe,KACpD,MAAM,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IAEtC,QAAQ,CAAC,aAAa,EAAE,MAAM,mBAAmB,CAAC;IAElD,oEAAoE;IACpE,QAAQ,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ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AAI,EAAE,+BAA+B,CAAC;IAC/C,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,eAAe,EAAE,eA6H7B,CAAC"}
|
package/dist/src/WebSocket.js
CHANGED
|
@@ -47,7 +47,10 @@ export const createWebSocket = (url, { protocols, binaryType, onOpen, onClose, o
|
|
|
47
47
|
socket.onclose = null;
|
|
48
48
|
socket.onmessage = null;
|
|
49
49
|
socket.onerror = null;
|
|
50
|
-
socket.
|
|
50
|
+
if (socket.readyState !== socket.CLOSING &&
|
|
51
|
+
socket.readyState !== socket.CLOSED) {
|
|
52
|
+
socket.close();
|
|
53
|
+
}
|
|
51
54
|
socket = null;
|
|
52
55
|
};
|
|
53
56
|
// To prevent a memory leak from pending connection promise.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Db.d.ts","sourceRoot":"","sources":["../../../src/local-first/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,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAEL,qBAAqB,EAIrB,WAAW,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAGL,MAAM,EAC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B,CAAC;IAChC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;CACrB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B,CAAC;AAEN,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAC3C,qBAAqB,GACrB,kBAAkB,GAClB,cAAc,GACd,SAAS,GACT,OAAO,CAAC;AAgBV,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CACzD;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED,eAAO,MAAM,yBAAyB,GACpC,cAAc,oBAAoB,KACjC,QAQC,CAAC"}
|
|
@@ -18,8 +18,11 @@ export const defaultDbConfig = {
|
|
|
18
18
|
maxDrift: 5 * 60 * 1000,
|
|
19
19
|
enableLogging: false,
|
|
20
20
|
};
|
|
21
|
-
export const createDbWorkerForPlatform = (platformDeps) => createInitializedWorkerWithHandlers({
|
|
22
|
-
|
|
21
|
+
export const createDbWorkerForPlatform = (platformDeps) => createInitializedWorkerWithHandlers({
|
|
22
|
+
init: createInit(platformDeps),
|
|
23
|
+
handlers,
|
|
24
|
+
});
|
|
25
|
+
const createInit = (platformDeps) => async (initMessage, postMessage) => {
|
|
23
26
|
platformDeps.console.enabled = initMessage.config.enableLogging ?? false;
|
|
24
27
|
const sqliteResult = await createSqlite(platformDeps)(initMessage.config.name, {
|
|
25
28
|
memory: initMessage.config.inMemory ?? false,
|
|
@@ -41,15 +44,6 @@ const createDbWorkerDeps = (platformDeps) => async (initMessage, postMessage) =>
|
|
|
41
44
|
const currentVersion = sqlite.exec(sql `select protocolVersion from evolu_version limit 1;`);
|
|
42
45
|
if (!currentVersion.ok)
|
|
43
46
|
return currentVersion;
|
|
44
|
-
// TODO: Handle version migrations here if needed
|
|
45
|
-
// const [{ protocolVersion }] = protocolVersionResult.value.rows;
|
|
46
|
-
// if (protocolVersion < currentProtocolVersion) {
|
|
47
|
-
// const migrateResult = migrateDatabase({ sqlite })(
|
|
48
|
-
// protocolVersion,
|
|
49
|
-
// currentProtocolVersion
|
|
50
|
-
// );
|
|
51
|
-
// if (!migrateResult.ok) return migrateResult;
|
|
52
|
-
// }
|
|
53
47
|
const configResult = sqlite.exec(sql `
|
|
54
48
|
select
|
|
55
49
|
clock,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRandomBytes } from "../Crypto.js";
|
|
2
|
-
import { isPlainObject } from "../Object.js";
|
|
2
|
+
import { createRecord, isPlainObject } from "../Object.js";
|
|
3
3
|
import { orderUint8Array } from "../Order.js";
|
|
4
4
|
import { createId, String } from "../Type.js";
|
|
5
5
|
export const applyPatches = (patches, current) => patches.reduce((next, patch) => {
|
|
@@ -89,7 +89,7 @@ const parse = (obj) => {
|
|
|
89
89
|
return obj;
|
|
90
90
|
};
|
|
91
91
|
const parseObject = (obj) => {
|
|
92
|
-
const result =
|
|
92
|
+
const result = createRecord();
|
|
93
93
|
for (const key in obj) {
|
|
94
94
|
result[key] = parse(obj[key]);
|
|
95
95
|
}
|
|
@@ -341,31 +341,34 @@ export interface Evolu<S extends EvoluSchema = EvoluSchema> extends Disposable {
|
|
|
341
341
|
*/
|
|
342
342
|
readonly exportDatabase: () => Promise<Uint8Array<ArrayBuffer>>;
|
|
343
343
|
/**
|
|
344
|
-
* Use
|
|
345
|
-
* broadcasted changes. Returns a function to stop using the owner.
|
|
344
|
+
* Use a {@link SyncOwner}. Returns a {@link UnuseOwner}.
|
|
346
345
|
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
346
|
+
* Using an owner means syncing it with its transports, or the transports
|
|
347
|
+
* defined in Evolu config if the owner has no transports defined.
|
|
348
|
+
*
|
|
349
|
+
* Transport are automatically deduplicated and reference-counted, so multiple
|
|
350
|
+
* owners using the same transport will share a single connection.
|
|
350
351
|
*
|
|
351
352
|
* ### Example
|
|
352
353
|
*
|
|
353
354
|
* ```ts
|
|
354
|
-
* // Use an owner (starts syncing
|
|
355
|
-
* const
|
|
355
|
+
* // Use an owner (starts syncing).
|
|
356
|
+
* const unuseOwner = evolu.useOwner(shardOwner);
|
|
356
357
|
*
|
|
357
358
|
* // Later, stop using the owner.
|
|
358
|
-
*
|
|
359
|
+
* unuseOwner();
|
|
359
360
|
*
|
|
360
361
|
* // Bulk operations.
|
|
361
|
-
* const
|
|
362
|
-
* // Later:
|
|
362
|
+
* const unuseOwners = owners.map((owner) => evolu.useOwner(owner));
|
|
363
|
+
* // Later: for (const unuse of unuseOwners) unuse();
|
|
363
364
|
* ```
|
|
364
365
|
*
|
|
365
366
|
* @experimental
|
|
366
367
|
*/
|
|
367
|
-
readonly useOwner: (owner: SyncOwner) =>
|
|
368
|
+
readonly useOwner: (owner: SyncOwner) => UnuseOwner;
|
|
368
369
|
}
|
|
370
|
+
/** Function returned by {@link Evolu#useOwner} to stop using an {@link SyncOwner}. */
|
|
371
|
+
export type UnuseOwner = () => void;
|
|
369
372
|
/** Represents errors that can occur in Evolu. */
|
|
370
373
|
export type EvoluError = ProtocolError | SqliteError | SymmetricCryptoDecryptError | TimestampError | TransferableError;
|
|
371
374
|
export type EvoluDeps = ConsoleDep & CreateDbWorkerDep & Partial<FlushSyncDep> & RandomBytesDep & ReloadAppDep & TimeDep;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Evolu.d.ts","sourceRoot":"","sources":["../../../src/local-first/Evolu.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AA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,OAAO,CAAC;AAUV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,WAAW,GACrB,MAAM,SAAS,MACf,CAAC,SAAS,WAAW,EACpB,QAAQ,cAAc,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,EAC/D,SAAS,WAAW,KACnB,KAAK,CAAC,CAAC,CAQK,CAAC;AA2alB,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,GAAG,EACvC,eAAe,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACtD,UAAU,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,KAChD,KAAK,CAAC,CAAC,CAeT,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { pack } from "msgpackr";
|
|
2
2
|
import { dedupeArray, isNonEmptyArray, isNonEmptyReadonlyArray, } from "../Array.js";
|
|
3
|
-
import { assertNonEmptyReadonlyArray } from "../Assert.js";
|
|
3
|
+
import { assert, assertNonEmptyReadonlyArray } from "../Assert.js";
|
|
4
4
|
import { createCallbacks } from "../Callbacks.js";
|
|
5
5
|
import { eqArrayNumber } from "../Eq.js";
|
|
6
6
|
import { exhaustiveCheck } from "../Function.js";
|
|
7
7
|
import { createInstances } from "../Instances.js";
|
|
8
8
|
import { err, ok } from "../Result.js";
|
|
9
|
-
import { isSqlMutation, SqliteBoolean, } from "../Sqlite.js";
|
|
9
|
+
import { isSqlMutation, SqliteBoolean, sqliteBooleanToBoolean, } from "../Sqlite.js";
|
|
10
10
|
import { createStore } from "../Store.js";
|
|
11
11
|
import { createId, } from "../Type.js";
|
|
12
12
|
import { defaultDbConfig } from "./Db.js";
|
|
@@ -193,13 +193,16 @@ const createEvoluInstance = (deps) => (schema, config) => {
|
|
|
193
193
|
}
|
|
194
194
|
else {
|
|
195
195
|
const { id: _, isDeleted, ...values } = result.value;
|
|
196
|
-
const dbChange =
|
|
196
|
+
const dbChange = {
|
|
197
197
|
table,
|
|
198
198
|
id,
|
|
199
199
|
values,
|
|
200
200
|
isInsert: kind === "insert" || kind === "upsert",
|
|
201
|
-
isDelete: SqliteBoolean.is(isDeleted)
|
|
202
|
-
|
|
201
|
+
isDelete: SqliteBoolean.is(isDeleted)
|
|
202
|
+
? sqliteBooleanToBoolean(isDeleted)
|
|
203
|
+
: null,
|
|
204
|
+
};
|
|
205
|
+
assert(DbChange.is(dbChange), `Invalid DbChange for table '${table}': Please check schema type errors.`);
|
|
203
206
|
mutateMicrotaskQueue.push([
|
|
204
207
|
{ ...dbChange, ownerId: options?.ownerId },
|
|
205
208
|
options?.onComplete,
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { NonEmptyReadonlyArray } from "../Array.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RandomBytesDep } from "../Crypto.js";
|
|
3
3
|
import { Mnemonic, NonNegativeInt } from "../Type.js";
|
|
4
4
|
import { TimestampBytes } from "./Timestamp.js";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* assigned to an owner, enabling sync functionality and access control.
|
|
6
|
+
* {@link Owner} without a {@link OwnerWriteKey}.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
|
|
8
|
+
* @see {@link createSharedReadonlyOwner}
|
|
9
|
+
*/
|
|
10
|
+
export interface ReadonlyOwner {
|
|
11
|
+
readonly id: OwnerId;
|
|
12
|
+
readonly encryptionKey: OwnerEncryptionKey;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The Owner represents ownership of data in Evolu. Every database change is
|
|
16
|
+
* assigned to an owner and encrypted with its {@link OwnerEncryptionKey}. Owners
|
|
17
|
+
* allow partial sync, only the {@link AppOwner} is synced by default.
|
|
11
18
|
*
|
|
12
|
-
* Owners also provide
|
|
13
|
-
* local-first/distributed systems can only be
|
|
14
|
-
*
|
|
19
|
+
* Owners can also provide real data deletion, while individual changes in
|
|
20
|
+
* local-first/distributed systems can only be soft deleted, entire owners can
|
|
21
|
+
* be completely deleted from both relays and devices (except for
|
|
15
22
|
* {@link AppOwner}, which must be preserved for sync coordination).
|
|
16
23
|
*
|
|
17
24
|
* Evolu provides different owner types depending on their use case:
|
|
@@ -27,28 +34,29 @@ import { TimestampBytes } from "./Timestamp.js";
|
|
|
27
34
|
* SLIP-21, ensuring secure and deterministic key generation:
|
|
28
35
|
*
|
|
29
36
|
* - {@link OwnerId}: Globally unique public identifier
|
|
30
|
-
* - {@link
|
|
37
|
+
* - {@link OwnerEncryptionKey}: Symmetric encryption key for data protection
|
|
31
38
|
* - {@link OwnerWriteKey}: Authentication token for write operations (rotatable)
|
|
32
39
|
*
|
|
33
|
-
* @see {@link
|
|
40
|
+
* @see {@link createAppOwner}
|
|
41
|
+
* @see {@link createShardOwner}
|
|
42
|
+
* @see {@link createSharedOwner}
|
|
43
|
+
* @see {@link createSharedReadonlyOwner}
|
|
34
44
|
*/
|
|
35
|
-
export interface Owner {
|
|
36
|
-
readonly id: OwnerId;
|
|
37
|
-
readonly encryptionKey: OwnerEncryptionKey;
|
|
45
|
+
export interface Owner extends ReadonlyOwner {
|
|
38
46
|
readonly writeKey: OwnerWriteKey;
|
|
39
47
|
}
|
|
40
|
-
/**
|
|
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}.
|
|
43
|
-
*/
|
|
48
|
+
/** OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}. */
|
|
44
49
|
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>;
|
|
45
50
|
export type OwnerId = typeof OwnerId.Type;
|
|
46
51
|
/** Bytes representation of {@link OwnerId}. */
|
|
47
52
|
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
53
|
export type OwnerIdBytes = typeof OwnerIdBytes.Type;
|
|
54
|
+
/** Converts {@link OwnerId} to {@link OwnerIdBytes}. */
|
|
49
55
|
export declare const ownerIdToOwnerIdBytes: (ownerId: OwnerId) => OwnerIdBytes;
|
|
56
|
+
/** Converts {@link OwnerIdBytes} to {@link OwnerId}. */
|
|
50
57
|
export declare const ownerIdBytesToOwnerId: (ownerIdBytes: OwnerIdBytes) => OwnerId;
|
|
51
58
|
export declare const ownerWriteKeyLength: number & import("../Brand.js").Brand<"Int"> & import("../Brand.js").Brand<"NonNegative">;
|
|
59
|
+
/** Symmetric encryption key for {@link Owner} data protection. */
|
|
52
60
|
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
61
|
export type OwnerEncryptionKey = typeof OwnerEncryptionKey.Type;
|
|
54
62
|
/**
|
|
@@ -57,6 +65,14 @@ export type OwnerEncryptionKey = typeof OwnerEncryptionKey.Type;
|
|
|
57
65
|
*/
|
|
58
66
|
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
67
|
export type OwnerWriteKey = typeof OwnerWriteKey.Type;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new random {@link OwnerWriteKey} for rotation.
|
|
70
|
+
*
|
|
71
|
+
* The initial OwnerWriteKey is deterministically derived from
|
|
72
|
+
* {@link OwnerSecret}. Use `createOwnerWriteKey` to rotate (replace) the write
|
|
73
|
+
* key without changing the owner identity.
|
|
74
|
+
*/
|
|
75
|
+
export declare const createOwnerWriteKey: (deps: RandomBytesDep) => OwnerWriteKey;
|
|
60
76
|
/**
|
|
61
77
|
* 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
|
|
62
78
|
*
|
|
@@ -71,20 +87,6 @@ export declare const createOwnerSecret: (deps: RandomBytesDep) => OwnerSecret;
|
|
|
71
87
|
export declare const ownerSecretToMnemonic: (secret: OwnerSecret) => Mnemonic;
|
|
72
88
|
/** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
|
|
73
89
|
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
90
|
/**
|
|
89
91
|
* The AppOwner represents the application owner. It's created using a
|
|
90
92
|
* cryptographically secure random generator or derived from an external source,
|
|
@@ -140,10 +142,9 @@ export declare const createAppOwner: (secret: OwnerSecret) => AppOwner;
|
|
|
140
142
|
*/
|
|
141
143
|
export interface ShardOwner extends Owner {
|
|
142
144
|
readonly type: "ShardOwner";
|
|
143
|
-
readonly transports?: ReadonlyArray<OwnerTransport>;
|
|
144
145
|
}
|
|
145
146
|
/** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
|
|
146
|
-
export declare const createShardOwner: (secret: OwnerSecret
|
|
147
|
+
export declare const createShardOwner: (secret: OwnerSecret) => ShardOwner;
|
|
147
148
|
/**
|
|
148
149
|
* Derives a {@link ShardOwner} from an {@link AppOwner} using the specified path.
|
|
149
150
|
*
|
|
@@ -162,11 +163,10 @@ export declare const createShardOwner: (secret: OwnerSecret, transports?: Readon
|
|
|
162
163
|
* - Use paths like `["project", "MyApp", 1]` for named partitions with versions
|
|
163
164
|
* - Each device can derive the same owners and set up initial structure
|
|
164
165
|
*/
|
|
165
|
-
export declare const deriveShardOwner: (owner: AppOwner, path: NonEmptyReadonlyArray<string | number
|
|
166
|
+
export declare const deriveShardOwner: (owner: AppOwner, path: NonEmptyReadonlyArray<string | number>) => ShardOwner;
|
|
166
167
|
/** An {@link Owner} for collaborative data with write access. */
|
|
167
168
|
export interface SharedOwner extends Owner {
|
|
168
169
|
readonly type: "SharedOwner";
|
|
169
|
-
readonly transports?: ReadonlyArray<OwnerTransport>;
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
172
|
* Creates a {@link SharedOwner} from an {@link OwnerSecret} for collaborative
|
|
@@ -175,17 +175,14 @@ export interface SharedOwner extends Owner {
|
|
|
175
175
|
* Use {@link createSharedReadonlyOwner} to create a read-only version for
|
|
176
176
|
* sharing.
|
|
177
177
|
*/
|
|
178
|
-
export declare const createSharedOwner: (secret: OwnerSecret
|
|
178
|
+
export declare const createSharedOwner: (secret: OwnerSecret) => SharedOwner;
|
|
179
179
|
/**
|
|
180
180
|
* Read-only version of a {@link SharedOwner} for data sharing. Contains only the
|
|
181
181
|
* {@link OwnerId} and {@link EncryptionKey} needed for others to read the shared
|
|
182
182
|
* data without write access.
|
|
183
183
|
*/
|
|
184
|
-
export interface SharedReadonlyOwner {
|
|
184
|
+
export interface SharedReadonlyOwner extends ReadonlyOwner {
|
|
185
185
|
readonly type: "SharedReadonlyOwner";
|
|
186
|
-
readonly id: OwnerId;
|
|
187
|
-
readonly encryptionKey: EncryptionKey;
|
|
188
|
-
readonly transports?: ReadonlyArray<OwnerTransport>;
|
|
189
186
|
}
|
|
190
187
|
/** Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner}. */
|
|
191
188
|
export declare const createSharedReadonlyOwner: (sharedOwner: SharedOwner) => SharedReadonlyOwner;
|
|
@@ -270,8 +267,8 @@ export declare const createOwnerWebSocketTransport: (config: {
|
|
|
270
267
|
* ```
|
|
271
268
|
*/
|
|
272
269
|
export declare const parseOwnerIdFromOwnerWebSocketTransportUrl: (url: string) => OwnerId | null;
|
|
273
|
-
/**
|
|
274
|
-
export interface
|
|
270
|
+
/** Common interface implemented by all owner domain errors. */
|
|
271
|
+
export interface OwnerError {
|
|
275
272
|
readonly ownerId: OwnerId;
|
|
276
273
|
}
|
|
277
274
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/local-first/Owner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/local-first/Owner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAKL,cAAc,EACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAML,QAAQ,EACR,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,aAAa,EAAE,kBAAkB,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,WAAW,KAAM,SAAQ,aAAa;IAC1C,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;CAClC;AAED,iFAAiF;AACjF,eAAO,MAAM,OAAO,mZAAuB,CAAC;AAC5C,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAC;AAE1C,+CAA+C;AAC/C,eAAO,MAAM,YAAY,uvB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,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAE/B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;IAErC,wEAAwE;IACxE,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,EAAE,cAAc,GAAG,IAAI,CAAC;CAC/C"}
|
|
@@ -3,22 +3,30 @@ import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
|
3
3
|
import { createSlip21, EncryptionKey, Entropy16, Entropy32, } from "../Crypto.js";
|
|
4
4
|
import { getOrNull } from "../Result.js";
|
|
5
5
|
import { brand, Id, IdBytes, idBytesToId, idToIdBytes, NonNegativeInt, } from "../Type.js";
|
|
6
|
-
/**
|
|
7
|
-
* OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}.
|
|
8
|
-
* Branded from {@link Id} to leverage existing helpers like {@link idToIdBytes}.
|
|
9
|
-
*/
|
|
6
|
+
/** OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}. */
|
|
10
7
|
export const OwnerId = brand("OwnerId", Id);
|
|
11
8
|
/** Bytes representation of {@link OwnerId}. */
|
|
12
9
|
export const OwnerIdBytes = brand("OwnerIdBytes", IdBytes);
|
|
10
|
+
/** Converts {@link OwnerId} to {@link OwnerIdBytes}. */
|
|
13
11
|
export const ownerIdToOwnerIdBytes = (ownerId) => idToIdBytes(ownerId);
|
|
12
|
+
/** Converts {@link OwnerIdBytes} to {@link OwnerId}. */
|
|
14
13
|
export const ownerIdBytesToOwnerId = (ownerIdBytes) => idBytesToId(ownerIdBytes);
|
|
15
14
|
export const ownerWriteKeyLength = NonNegativeInt.orThrow(16);
|
|
15
|
+
/** Symmetric encryption key for {@link Owner} data protection. */
|
|
16
16
|
export const OwnerEncryptionKey = brand("OwnerEncryptionKey", EncryptionKey);
|
|
17
17
|
/**
|
|
18
18
|
* A secure token for write operations. It's derived from {@link OwnerSecret} by
|
|
19
19
|
* default and can be rotated via {@link createOwnerWriteKey}.
|
|
20
20
|
*/
|
|
21
21
|
export const OwnerWriteKey = brand("OwnerWriteKey", Entropy16);
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new random {@link OwnerWriteKey} for rotation.
|
|
24
|
+
*
|
|
25
|
+
* The initial OwnerWriteKey is deterministically derived from
|
|
26
|
+
* {@link OwnerSecret}. Use `createOwnerWriteKey` to rotate (replace) the write
|
|
27
|
+
* key without changing the owner identity.
|
|
28
|
+
*/
|
|
29
|
+
export const createOwnerWriteKey = (deps) => deps.randomBytes.create(16);
|
|
22
30
|
/**
|
|
23
31
|
* 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
|
|
24
32
|
*
|
|
@@ -32,36 +40,26 @@ export const createOwnerSecret = (deps) => deps.randomBytes.create(32);
|
|
|
32
40
|
export const ownerSecretToMnemonic = (secret) => bip39.entropyToMnemonic(secret, wordlist);
|
|
33
41
|
/** Converts a {@link Mnemonic} to an {@link OwnerSecret}. */
|
|
34
42
|
export const mnemonicToOwnerSecret = (mnemonic) => bip39.mnemonicToEntropy(mnemonic, wordlist);
|
|
35
|
-
/** Creates a randomly generated {@link OwnerWriteKey}. */
|
|
36
|
-
export const createOwnerWriteKey = (deps) => deps.randomBytes.create(16);
|
|
37
43
|
/**
|
|
38
44
|
* Creates an {@link Owner} from a {@link OwnerSecret} using SLIP-21 key
|
|
39
45
|
* derivation.
|
|
40
|
-
*
|
|
41
|
-
* This is an internal helper function, use:
|
|
42
|
-
*
|
|
43
|
-
* - {@link createAppOwner}
|
|
44
|
-
* - {@link createShardOwner}
|
|
45
|
-
* - {@link createSharedOwner}
|
|
46
|
-
* - {@link createSharedReadonlyOwner}
|
|
47
46
|
*/
|
|
48
|
-
|
|
47
|
+
const createOwner = (secret) => ({
|
|
49
48
|
id: ownerIdBytesToOwnerId(OwnerIdBytes.orThrow(createSlip21(secret, ["Evolu", "OwnerIdBytes"]).slice(0, 16))),
|
|
50
49
|
encryptionKey: OwnerEncryptionKey.orThrow(createSlip21(secret, ["Evolu", "OwnerEncryptionKey"])),
|
|
51
50
|
writeKey: OwnerWriteKey.orThrow(createSlip21(secret, ["Evolu", "OwnerWriteKey"]).slice(0, 16)),
|
|
52
51
|
});
|
|
53
52
|
/** Creates an {@link AppOwner} from an {@link OwnerSecret}. */
|
|
54
53
|
export const createAppOwner = (secret) => ({
|
|
54
|
+
...createOwner(secret),
|
|
55
55
|
type: "AppOwner",
|
|
56
56
|
mnemonic: ownerSecretToMnemonic(secret),
|
|
57
|
-
...createOwner(secret),
|
|
58
57
|
});
|
|
59
58
|
/** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
|
|
60
|
-
export const createShardOwner = (secret
|
|
59
|
+
export const createShardOwner = (secret) => {
|
|
61
60
|
return {
|
|
62
|
-
type: "ShardOwner",
|
|
63
61
|
...createOwner(secret),
|
|
64
|
-
|
|
62
|
+
type: "ShardOwner",
|
|
65
63
|
};
|
|
66
64
|
};
|
|
67
65
|
/**
|
|
@@ -82,12 +80,11 @@ export const createShardOwner = (secret, transports) => {
|
|
|
82
80
|
* - Use paths like `["project", "MyApp", 1]` for named partitions with versions
|
|
83
81
|
* - Each device can derive the same owners and set up initial structure
|
|
84
82
|
*/
|
|
85
|
-
export const deriveShardOwner = (owner, path
|
|
83
|
+
export const deriveShardOwner = (owner, path) => {
|
|
86
84
|
const secret = createSlip21(owner.encryptionKey, path);
|
|
87
85
|
return {
|
|
88
|
-
type: "ShardOwner",
|
|
89
86
|
...createOwner(secret),
|
|
90
|
-
|
|
87
|
+
type: "ShardOwner",
|
|
91
88
|
};
|
|
92
89
|
};
|
|
93
90
|
/**
|
|
@@ -97,19 +94,15 @@ export const deriveShardOwner = (owner, path, transports) => {
|
|
|
97
94
|
* Use {@link createSharedReadonlyOwner} to create a read-only version for
|
|
98
95
|
* sharing.
|
|
99
96
|
*/
|
|
100
|
-
export const createSharedOwner = (secret
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
...(transports && { transports }),
|
|
105
|
-
};
|
|
106
|
-
};
|
|
97
|
+
export const createSharedOwner = (secret) => ({
|
|
98
|
+
...createOwner(secret),
|
|
99
|
+
type: "SharedOwner",
|
|
100
|
+
});
|
|
107
101
|
/** Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner}. */
|
|
108
102
|
export const createSharedReadonlyOwner = (sharedOwner) => ({
|
|
109
103
|
type: "SharedReadonlyOwner",
|
|
110
104
|
id: sharedOwner.id,
|
|
111
105
|
encryptionKey: sharedOwner.encryptionKey,
|
|
112
|
-
...(sharedOwner.transports && { transports: sharedOwner.transports }),
|
|
113
106
|
});
|
|
114
107
|
/**
|
|
115
108
|
* Creates an {@link OwnerWebSocketTransport} for the given relay URL and
|