@remit/drizzle-service 0.0.1 → 0.0.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/package.json +1 -1
- package/src/repos/cascade-delete.sqlite.test.ts +1 -1
- package/src/repos/cascade-delete.test.ts +1 -1
- package/src/repos/i4-account.test.ts +1 -1
- package/src/repos/i4-mailbox.sqlite.test.ts +63 -0
- package/src/repos/i4-mailbox.test.ts +24 -1
- package/src/repos/unit-of-work.ts +4 -1
package/package.json
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { after, before, describe, test } from "node:test";
|
|
4
|
+
import { mailboxTable } from "../schema.js";
|
|
5
|
+
import { createSqliteTestDb } from "../test-db-sqlite.js";
|
|
6
|
+
import { MailboxRepo } from "./i4-mailbox.js";
|
|
7
|
+
|
|
8
|
+
function makeMailboxInput(accountId: string, fullPath = "INBOX") {
|
|
9
|
+
return {
|
|
10
|
+
accountId,
|
|
11
|
+
namespaceType: "personal" as const,
|
|
12
|
+
namespacePrefix: "",
|
|
13
|
+
hierarchyDelimiter: "/",
|
|
14
|
+
fullPath,
|
|
15
|
+
uidValidity: 1,
|
|
16
|
+
uidNext: 1,
|
|
17
|
+
highestModseq: "0",
|
|
18
|
+
messageCount: 0,
|
|
19
|
+
unseenCount: 0,
|
|
20
|
+
deletedCount: 0,
|
|
21
|
+
totalSize: 0,
|
|
22
|
+
lastSyncUid: 0,
|
|
23
|
+
highWaterMarkUid: 0,
|
|
24
|
+
lastMessageSyncAt: Date.now(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe("MailboxRepo (sqlite)", () => {
|
|
29
|
+
let close: () => Promise<void>;
|
|
30
|
+
let repo: MailboxRepo;
|
|
31
|
+
|
|
32
|
+
before(async () => {
|
|
33
|
+
const testDb = await createSqliteTestDb({ mailbox: mailboxTable });
|
|
34
|
+
close = testDb.close;
|
|
35
|
+
repo = new MailboxRepo(testDb.db as never);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
after(async () => {
|
|
39
|
+
await close();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("highestModseq round-trips a value above 2^53 without loss (reader#9)", async () => {
|
|
43
|
+
const accountId = randomUUID();
|
|
44
|
+
const modseq = "18446744073709551615";
|
|
45
|
+
|
|
46
|
+
const created = await repo.create({
|
|
47
|
+
...makeMailboxInput(accountId),
|
|
48
|
+
highestModseq: modseq,
|
|
49
|
+
});
|
|
50
|
+
assert.equal(created.highestModseq, modseq);
|
|
51
|
+
|
|
52
|
+
const fetched = await repo.get(accountId, created.mailboxId);
|
|
53
|
+
assert.equal(fetched.highestModseq, modseq);
|
|
54
|
+
assert.equal(BigInt(fetched.highestModseq) > 2n ** 53n, true);
|
|
55
|
+
|
|
56
|
+
const updated = await repo.update(accountId, created.mailboxId, {
|
|
57
|
+
highestModseq: "9007199254740993",
|
|
58
|
+
});
|
|
59
|
+
assert.equal(updated.highestModseq, "9007199254740993");
|
|
60
|
+
const reread = await repo.get(accountId, created.mailboxId);
|
|
61
|
+
assert.equal(reread.highestModseq, "9007199254740993");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -12,7 +12,7 @@ function makeMailboxInput(accountId: string, fullPath = "INBOX") {
|
|
|
12
12
|
fullPath,
|
|
13
13
|
uidValidity: 1,
|
|
14
14
|
uidNext: 1,
|
|
15
|
-
highestModseq: 0,
|
|
15
|
+
highestModseq: "0",
|
|
16
16
|
messageCount: 0,
|
|
17
17
|
unseenCount: 5,
|
|
18
18
|
deletedCount: 0,
|
|
@@ -49,6 +49,29 @@ describe("MailboxRepo", () => {
|
|
|
49
49
|
await repo.delete(accountId, mailbox.mailboxId);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
test("highestModseq round-trips a value above 2^53 without loss (reader#9)", async () => {
|
|
53
|
+
const accountId = randomId();
|
|
54
|
+
const modseq = "18446744073709551615";
|
|
55
|
+
const created = await repo.create({
|
|
56
|
+
...makeMailboxInput(accountId),
|
|
57
|
+
highestModseq: modseq,
|
|
58
|
+
});
|
|
59
|
+
assert.equal(created.highestModseq, modseq);
|
|
60
|
+
|
|
61
|
+
const fetched = await repo.get(accountId, created.mailboxId);
|
|
62
|
+
assert.equal(fetched.highestModseq, modseq);
|
|
63
|
+
assert.equal(BigInt(fetched.highestModseq) > 2n ** 53n, true);
|
|
64
|
+
|
|
65
|
+
const updated = await repo.update(accountId, created.mailboxId, {
|
|
66
|
+
highestModseq: "9007199254740993",
|
|
67
|
+
});
|
|
68
|
+
assert.equal(updated.highestModseq, "9007199254740993");
|
|
69
|
+
const reread = await repo.get(accountId, created.mailboxId);
|
|
70
|
+
assert.equal(reread.highestModseq, "9007199254740993");
|
|
71
|
+
|
|
72
|
+
await repo.delete(accountId, created.mailboxId);
|
|
73
|
+
});
|
|
74
|
+
|
|
52
75
|
test("batchGet: WHERE id = ANY($1)", async () => {
|
|
53
76
|
const accountId = randomId();
|
|
54
77
|
const m1 = await repo.create(makeMailboxInput(accountId, "INBOX"));
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
IUnitOfWork,
|
|
3
|
+
UnitOfWorkRepositories,
|
|
4
|
+
} from "@remit/data-ports";
|
|
2
5
|
import type { Db } from "../db.js";
|
|
3
6
|
import type { MessageDataSchema } from "../schema/message-data.js";
|
|
4
7
|
import { runInTransaction } from "../tx.js";
|