@remit/drizzle-service 0.0.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/drizzle-service",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Drizzle ORM service parameterized by dialect (Postgres / SQLite)",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -74,7 +74,7 @@ describe("createSqliteCascadeDeleter", () => {
74
74
  fullPath: "INBOX",
75
75
  uidValidity: 1,
76
76
  uidNext: 1,
77
- highestModseq: 0,
77
+ highestModseq: "0",
78
78
  messageCount: 0,
79
79
  unseenCount: 0,
80
80
  deletedCount: 0,
@@ -73,7 +73,7 @@ describe("runDrizzleCascadeDelete", () => {
73
73
  fullPath: "INBOX",
74
74
  uidValidity: 1,
75
75
  uidNext: 1,
76
- highestModseq: 0,
76
+ highestModseq: "0",
77
77
  messageCount: 0,
78
78
  unseenCount: 0,
79
79
  deletedCount: 0,
@@ -168,7 +168,7 @@ describe("AccountRepo", () => {
168
168
  fullPath: "INBOX",
169
169
  uidValidity: 1,
170
170
  uidNext: 1,
171
- highestModseq: 0,
171
+ highestModseq: "0",
172
172
  messageCount: 0,
173
173
  unseenCount: 0,
174
174
  deletedCount: 0,
@@ -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"));