@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.
Files changed (45) hide show
  1. package/dist/src/Buffer.d.ts +2 -1
  2. package/dist/src/Buffer.d.ts.map +1 -1
  3. package/dist/src/Buffer.js +1 -0
  4. package/dist/src/Callbacks.d.ts +1 -1
  5. package/dist/src/Callbacks.d.ts.map +1 -1
  6. package/dist/src/Callbacks.js +1 -1
  7. package/dist/src/Console.d.ts +1 -9
  8. package/dist/src/Console.d.ts.map +1 -1
  9. package/dist/src/Console.js +1 -41
  10. package/dist/src/Instances.d.ts.map +1 -1
  11. package/dist/src/Redacted.d.ts +89 -0
  12. package/dist/src/Redacted.d.ts.map +1 -0
  13. package/dist/src/Redacted.js +48 -0
  14. package/dist/src/Type.d.ts +5 -9
  15. package/dist/src/Type.d.ts.map +1 -1
  16. package/dist/src/Type.js +0 -202
  17. package/dist/src/index.d.ts +1 -0
  18. package/dist/src/index.d.ts.map +1 -1
  19. package/dist/src/index.js +1 -0
  20. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  21. package/dist/src/local-first/Owner.d.ts +4 -0
  22. package/dist/src/local-first/Owner.d.ts.map +1 -1
  23. package/dist/src/local-first/Public.d.ts +6 -1
  24. package/dist/src/local-first/Public.d.ts.map +1 -1
  25. package/dist/src/local-first/Public.js +6 -1
  26. package/dist/src/local-first/Storage.d.ts.map +1 -1
  27. package/dist/src/local-first/Sync.d.ts.map +1 -1
  28. package/dist/src/local-first/Sync.js +10 -13
  29. package/dist/src/local-first/index.d.ts +9 -1
  30. package/dist/src/local-first/index.d.ts.map +1 -1
  31. package/dist/src/local-first/index.js +9 -1
  32. package/package.json +3 -4
  33. package/src/Buffer.ts +2 -1
  34. package/src/Callbacks.ts +1 -1
  35. package/src/Console.ts +1 -10
  36. package/src/Instances.ts +4 -2
  37. package/src/Redacted.ts +118 -0
  38. package/src/Type.ts +229 -221
  39. package/src/index.ts +1 -0
  40. package/src/local-first/Evolu.ts +3 -2
  41. package/src/local-first/Owner.ts +4 -0
  42. package/src/local-first/Public.ts +6 -1
  43. package/src/local-first/Storage.ts +10 -12
  44. package/src/local-first/Sync.ts +10 -21
  45. package/src/local-first/index.ts +9 -1
@@ -465,8 +465,9 @@ export type EvoluError =
465
465
  | TimestampError
466
466
  | TransferableError;
467
467
 
468
- interface InternalEvoluInstance<S extends EvoluSchema = EvoluSchema>
469
- extends Evolu<S> {
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.
@@ -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
- * Local-first code to be imported from "@evolu/common"
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
- extends Pick<
329
- Storage,
330
- | "getSize"
331
- | "fingerprint"
332
- | "fingerprintRanges"
333
- | "findLowerBound"
334
- | "iterate"
335
- | "deleteOwner"
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,
@@ -5,7 +5,7 @@ import {
5
5
  NonEmptyArray,
6
6
  NonEmptyReadonlyArray,
7
7
  } from "../Array.js";
8
- import { assert, assertNonEmptyReadonlyArray } from "../Assert.js";
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
- rows,
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: boolean | null = null;
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
- assert(
618
- SqliteBoolean.is(r.value),
619
- "isDeleted column must contain a valid SqliteBoolean",
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: rows[0].table,
634
- id: idBytesToId(rows[0].id),
622
+ table: firstRow.table,
623
+ id: idBytesToId(firstRow.id),
635
624
  values,
636
625
  isInsert,
637
626
  isDelete,
@@ -1,5 +1,13 @@
1
1
  /**
2
- * Local-first code to be imported from "@evolu/common/local-first"
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
  */