Skip to content

Commit e1ed69a

Browse files
committed
Refactor client storage row processing logic
Removed unnecessary assertions and simplified row validation.
1 parent 859e331 commit e1ed69a

2 files changed

Lines changed: 15 additions & 21 deletions

File tree

.changeset/rare-pears-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@evolu/common": patch
3+
---
4+
5+
Removed unnecessary assertions and simplified row validation in client storage row processing logic.

packages/common/src/local-first/Sync.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import {
55
NonEmptyArray,
66
NonEmptyReadonlyArray,
77
} from "../Array.js";
8-
import { assert, assertNonEmptyReadonlyArray } from "../Assert.js";
8+
import { assertNonEmptyReadonlyArray } from "../Assert.js";
99
import { Brand } from "../Brand.js";
1010
import { ConsoleDep } from "../Console.js";
1111
import {
1212
RandomBytesDep,
1313
SymmetricCryptoDecryptError,
1414
SymmetricCryptoDep,
1515
} from "../Crypto.js";
16-
import { eqArrayNumber } from "../Eq.js";
1716
import { createTransferableError, TransferableError } from "../Error.js";
1817
import { constFalse, constTrue } from "../Function.js";
1918
import { createRecord, getProperty, objectToEntries } from "../Object.js";
@@ -32,7 +31,6 @@ import {
3231
import { AbortError, createMutex } from "../Task.js";
3332
import { TimeDep } from "../Time.js";
3433
import {
35-
Boolean,
3634
DateIso,
3735
Id,
3836
IdBytes,
@@ -593,19 +591,14 @@ const createClientStorage =
593591
}
594592

595593
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);
600596

601-
const { table, id } = firstInArray(rows);
602597
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;
605600

606601
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");
609602
switch (r.column) {
610603
case "createdAt":
611604
isInsert = true;
@@ -614,24 +607,20 @@ const createClientStorage =
614607
isInsert = false;
615608
break;
616609
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+
}
622613
break;
623614
default:
624615
values[r.column] = r.value;
625616
}
626617
}
627618

628-
assert(Boolean.is(isInsert), "isInsert must be in evolu_history");
629-
630619
const message: CrdtMessage = {
631620
timestamp: timestampBytesToTimestamp(timestamp),
632621
change: DbChange.orThrow({
633-
table: rows[0].table,
634-
id: idBytesToId(rows[0].id),
622+
table: firstRow.table,
623+
id: idBytesToId(firstRow.id),
635624
values,
636625
isInsert,
637626
isDelete,

0 commit comments

Comments
 (0)