@evolu/common 7.3.0 → 7.4.1
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/Buffer.d.ts +2 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +1 -0
- package/dist/src/Callbacks.d.ts +1 -1
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Callbacks.js +1 -1
- package/dist/src/Console.d.ts +1 -9
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +1 -41
- package/dist/src/Instances.d.ts.map +1 -1
- package/dist/src/Redacted.d.ts +89 -0
- package/dist/src/Redacted.d.ts.map +1 -0
- package/dist/src/Redacted.js +48 -0
- package/dist/src/Type.d.ts +5 -9
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +0 -202
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Owner.d.ts +4 -0
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Public.d.ts +6 -1
- package/dist/src/local-first/Public.d.ts.map +1 -1
- package/dist/src/local-first/Public.js +6 -1
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Sync.d.ts.map +1 -1
- package/dist/src/local-first/Sync.js +10 -13
- package/dist/src/local-first/index.d.ts +9 -1
- package/dist/src/local-first/index.d.ts.map +1 -1
- package/dist/src/local-first/index.js +9 -1
- package/package.json +3 -4
- package/src/Buffer.ts +2 -1
- package/src/Callbacks.ts +1 -1
- package/src/Console.ts +1 -10
- package/src/Instances.ts +4 -2
- package/src/Redacted.ts +118 -0
- package/src/Type.ts +229 -221
- package/src/index.ts +1 -0
- package/src/local-first/Evolu.ts +3 -2
- package/src/local-first/Owner.ts +4 -0
- package/src/local-first/Public.ts +6 -1
- package/src/local-first/Storage.ts +10 -12
- package/src/local-first/Sync.ts +10 -21
- package/src/local-first/index.ts +9 -1
package/src/local-first/Evolu.ts
CHANGED
|
@@ -465,8 +465,9 @@ export type EvoluError =
|
|
|
465
465
|
| TimestampError
|
|
466
466
|
| TransferableError;
|
|
467
467
|
|
|
468
|
-
interface InternalEvoluInstance<
|
|
469
|
-
extends
|
|
468
|
+
interface InternalEvoluInstance<
|
|
469
|
+
S extends EvoluSchema = EvoluSchema,
|
|
470
|
+
> extends Evolu<S> {
|
|
470
471
|
/**
|
|
471
472
|
* Ensure tables and columns defined in {@link EvoluSchema} exist in the
|
|
472
473
|
* database. This function is for hot reloading.
|
package/src/local-first/Owner.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { TimestampBytes } from "./Timestamp.js";
|
|
|
28
28
|
*/
|
|
29
29
|
export interface ReadonlyOwner {
|
|
30
30
|
readonly id: OwnerId;
|
|
31
|
+
/** TODO: Wrap with `Redacted` in the next major version. */
|
|
31
32
|
readonly encryptionKey: OwnerEncryptionKey;
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -63,6 +64,7 @@ export interface ReadonlyOwner {
|
|
|
63
64
|
* @see {@link createSharedReadonlyOwner}
|
|
64
65
|
*/
|
|
65
66
|
export interface Owner extends ReadonlyOwner {
|
|
67
|
+
/** TODO: Wrap with `Redacted` in the next major version. */
|
|
66
68
|
readonly writeKey: OwnerWriteKey;
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -184,6 +186,8 @@ export interface AppOwner extends Owner {
|
|
|
184
186
|
* The mnemonic that was used to derive the AppOwner keys. Optional when the
|
|
185
187
|
* AppOwner is created from external keys to avoid sharing the mnemonic with
|
|
186
188
|
* the Evolu app.
|
|
189
|
+
*
|
|
190
|
+
* TODO: Wrap with `Redacted` in the next major version.
|
|
187
191
|
*/
|
|
188
192
|
readonly mnemonic?: Mnemonic | null;
|
|
189
193
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Public local-first API exported from "@evolu/common"
|
|
3
|
+
*
|
|
4
|
+
* This module provides the supported consumer-facing API for Evolu's
|
|
5
|
+
* local-first system: prefer importing from `@evolu/common` (this module) when
|
|
6
|
+
* using Evolu in applications. If you require access to lower level internals,
|
|
7
|
+
* consider importing from `@evolu/common/local-first`.
|
|
3
8
|
*
|
|
4
9
|
* @module
|
|
5
10
|
*/
|
|
@@ -273,8 +273,7 @@ export const ValidDbChangeValues = brand(
|
|
|
273
273
|
);
|
|
274
274
|
export type ValidDbChangeValues = typeof ValidDbChangeValues.Type;
|
|
275
275
|
|
|
276
|
-
export interface ValidDbChangeValuesError
|
|
277
|
-
extends TypeError<"ValidDbChangeValues"> {
|
|
276
|
+
export interface ValidDbChangeValuesError extends TypeError<"ValidDbChangeValues"> {
|
|
278
277
|
readonly invalidColumns: ReadonlyArray<string>;
|
|
279
278
|
}
|
|
280
279
|
|
|
@@ -324,16 +323,15 @@ export type DbChange = typeof DbChange.Type;
|
|
|
324
323
|
* users, and when it goes down, nothing happens, because it will be
|
|
325
324
|
* synchronized later.
|
|
326
325
|
*/
|
|
327
|
-
export interface BaseSqliteStorage
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
> {
|
|
326
|
+
export interface BaseSqliteStorage extends Pick<
|
|
327
|
+
Storage,
|
|
328
|
+
| "getSize"
|
|
329
|
+
| "fingerprint"
|
|
330
|
+
| "fingerprintRanges"
|
|
331
|
+
| "findLowerBound"
|
|
332
|
+
| "iterate"
|
|
333
|
+
| "deleteOwner"
|
|
334
|
+
> {
|
|
337
335
|
/** Inserts a timestamp for an owner into the skiplist-based storage. */
|
|
338
336
|
readonly insertTimestamp: (
|
|
339
337
|
ownerId: OwnerIdBytes,
|
package/src/local-first/Sync.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
NonEmptyArray,
|
|
6
6
|
NonEmptyReadonlyArray,
|
|
7
7
|
} from "../Array.js";
|
|
8
|
-
import {
|
|
8
|
+
import { assertNonEmptyReadonlyArray } from "../Assert.js";
|
|
9
9
|
import { Brand } from "../Brand.js";
|
|
10
10
|
import { ConsoleDep } from "../Console.js";
|
|
11
11
|
import {
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
SymmetricCryptoDecryptError,
|
|
14
14
|
SymmetricCryptoDep,
|
|
15
15
|
} from "../Crypto.js";
|
|
16
|
-
import { eqArrayNumber } from "../Eq.js";
|
|
17
16
|
import { createTransferableError, TransferableError } from "../Error.js";
|
|
18
17
|
import { constFalse, constTrue } from "../Function.js";
|
|
19
18
|
import { createRecord, getProperty, objectToEntries } from "../Object.js";
|
|
@@ -32,7 +31,6 @@ import {
|
|
|
32
31
|
import { AbortError, createMutex } from "../Task.js";
|
|
33
32
|
import { TimeDep } from "../Time.js";
|
|
34
33
|
import {
|
|
35
|
-
Boolean,
|
|
36
34
|
DateIso,
|
|
37
35
|
Id,
|
|
38
36
|
IdBytes,
|
|
@@ -593,19 +591,14 @@ const createClientStorage =
|
|
|
593
591
|
}
|
|
594
592
|
|
|
595
593
|
const { rows } = result.value;
|
|
596
|
-
assertNonEmptyReadonlyArray(
|
|
597
|
-
|
|
598
|
-
"Every timestamp must have rows in evolu_history or quarantine",
|
|
599
|
-
);
|
|
594
|
+
assertNonEmptyReadonlyArray(rows, "Every timestamp must have rows");
|
|
595
|
+
const firstRow = firstInArray(rows);
|
|
600
596
|
|
|
601
|
-
const { table, id } = firstInArray(rows);
|
|
602
597
|
const values = createRecord<string, SqliteValue>();
|
|
603
|
-
let isInsert;
|
|
604
|
-
let isDelete:
|
|
598
|
+
let isInsert: DbChange["isInsert"] = false;
|
|
599
|
+
let isDelete: DbChange["isDelete"] = null;
|
|
605
600
|
|
|
606
601
|
for (const r of rows) {
|
|
607
|
-
assert(r.table === table, "All rows must have the same table");
|
|
608
|
-
assert(eqArrayNumber(r.id, id), "All rows must have the same Id");
|
|
609
602
|
switch (r.column) {
|
|
610
603
|
case "createdAt":
|
|
611
604
|
isInsert = true;
|
|
@@ -614,24 +607,20 @@ const createClientStorage =
|
|
|
614
607
|
isInsert = false;
|
|
615
608
|
break;
|
|
616
609
|
case "isDeleted":
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
);
|
|
621
|
-
isDelete = sqliteBooleanToBoolean(r.value);
|
|
610
|
+
if (SqliteBoolean.is(r.value)) {
|
|
611
|
+
isDelete = sqliteBooleanToBoolean(r.value);
|
|
612
|
+
}
|
|
622
613
|
break;
|
|
623
614
|
default:
|
|
624
615
|
values[r.column] = r.value;
|
|
625
616
|
}
|
|
626
617
|
}
|
|
627
618
|
|
|
628
|
-
assert(Boolean.is(isInsert), "isInsert must be in evolu_history");
|
|
629
|
-
|
|
630
619
|
const message: CrdtMessage = {
|
|
631
620
|
timestamp: timestampBytesToTimestamp(timestamp),
|
|
632
621
|
change: DbChange.orThrow({
|
|
633
|
-
table:
|
|
634
|
-
id: idBytesToId(
|
|
622
|
+
table: firstRow.table,
|
|
623
|
+
id: idBytesToId(firstRow.id),
|
|
635
624
|
values,
|
|
636
625
|
isInsert,
|
|
637
626
|
isDelete,
|
package/src/local-first/index.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Internal local-first modules re-exported from "@evolu/common/local-first"
|
|
3
|
+
*
|
|
4
|
+
* These exports expose the internal building blocks of Evolu's local-first
|
|
5
|
+
* implementation (Db, Relay, Sync, Query, Storage, Timestamp, etc.). They are
|
|
6
|
+
* primarily intended for use within Evolu packages and for advanced use-cases
|
|
7
|
+
* that require direct access to local-first internals.
|
|
8
|
+
*
|
|
9
|
+
* Public consumers should us top-level exports from `@evolu/common` unless you
|
|
10
|
+
* have a specific need to import these internals.
|
|
3
11
|
*
|
|
4
12
|
* @module
|
|
5
13
|
*/
|