@remit/drizzle-service 0.0.104 → 0.0.105
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/bound-parameters.test.ts +57 -0
- package/src/bound-parameters.ts +49 -0
- package/src/databases.ts +10 -9
- package/src/db.ts +1 -0
- package/src/index.ts +4 -0
- package/src/repair/junk-only-address.sqlite.test.ts +9 -5
- package/src/repos/account.conformance.sqlite.test.ts +9 -5
- package/src/repos/calendar-event-index.conformance.d1.test.ts +1 -1
- package/src/repos/calendar-event-index.conformance.sqlite.test.ts +3 -1
- package/src/repos/calendar-event-index.ts +36 -21
- package/src/repos/calendar-store.ts +17 -10
- package/src/repos/cascade-delete.test.ts +9 -2
- package/src/repos/cascade-delete.ts +2 -1
- package/src/repos/envelope.d1.test.ts +66 -0
- package/src/repos/envelope.sqlite.test.ts +5 -1
- package/src/repos/envelope.test.ts +5 -1
- package/src/repos/envelope.ts +40 -31
- package/src/repos/i4-account.test.ts +17 -10
- package/src/repos/i4-address-junk-move.sqlite.test.ts +9 -5
- package/src/repos/i4-mailbox-special-use.sqlite.test.ts +9 -5
- package/src/repos/i4-mailbox.sqlite.test.ts +17 -10
- package/src/repos/i4-mailbox.test.ts +17 -10
- package/src/repos/i4-outbox-attachment.test.ts +9 -5
- package/src/repos/message.sqlite.test.ts +5 -1
- package/src/repos/message.test.ts +5 -1
- package/src/repos/sync-warning.ts +35 -22
- package/src/repos/thread-message-body-muted.sqlite.test.ts +9 -5
- package/src/repos/thread-message-field-terms.sqlite.test.ts +9 -5
- package/src/repos/thread-message.sqlite.test.ts +9 -5
- package/src/repos/thread-message.test.ts +33 -20
- package/src/search/thread-message-search.sqlite.test.ts +13 -6
- package/src/search/thread-message-search.ts +14 -17
- package/src/sqlite-repositories.ts +6 -3
- package/src/test-d1.ts +36 -19
- package/src/test-stores.ts +15 -2
package/src/test-d1.ts
CHANGED
|
@@ -1,40 +1,57 @@
|
|
|
1
1
|
import { drizzle } from "drizzle-orm/d1";
|
|
2
2
|
import { Miniflare } from "miniflare";
|
|
3
3
|
import { asyncBatch } from "./batch.js";
|
|
4
|
+
import type { SqliteLimits } from "./bound-parameters.js";
|
|
4
5
|
import { syncStore } from "./databases.js";
|
|
5
|
-
import {
|
|
6
|
+
import type { SqliteStore } from "./db.js";
|
|
7
|
+
import {
|
|
8
|
+
type MigrationSet,
|
|
9
|
+
migrationStatements,
|
|
10
|
+
} from "./test-shipped-sqlite-schema.js";
|
|
6
11
|
import { createShippedSqliteDb } from "./test-sqlite.js";
|
|
7
12
|
import type { OpenTestStores } from "./test-stores.js";
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const CLOUDFLARE_LIMITS: SqliteLimits = { maxBoundParameters: 100 };
|
|
15
|
+
|
|
16
|
+
/** One in-process D1 database migrated with a committed set, written through `db.batch()`. */
|
|
17
|
+
export const openD1TestStore = async (
|
|
18
|
+
set: MigrationSet,
|
|
19
|
+
): Promise<{
|
|
20
|
+
store: SqliteStore<Record<string, unknown>>;
|
|
21
|
+
close: () => Promise<void>;
|
|
22
|
+
}> => {
|
|
16
23
|
const miniflare = new Miniflare({
|
|
17
24
|
modules: true,
|
|
18
25
|
script: "export default {};",
|
|
19
|
-
d1Databases: {
|
|
26
|
+
d1Databases: { DB: set },
|
|
20
27
|
});
|
|
21
|
-
const d1 = await miniflare.getD1Database("
|
|
22
|
-
const statements = migrationStatements(
|
|
28
|
+
const d1 = await miniflare.getD1Database("DB");
|
|
29
|
+
const statements = migrationStatements(set).filter(
|
|
23
30
|
(statement) => statement.trim() !== "",
|
|
24
31
|
);
|
|
25
32
|
await d1.batch(statements.map((statement) => d1.prepare(statement)));
|
|
26
|
-
const
|
|
33
|
+
const db = drizzle(d1);
|
|
34
|
+
return {
|
|
35
|
+
store: { db, batch: asyncBatch(db), ...CLOUDFLARE_LIMITS },
|
|
36
|
+
close: () => miniflare.dispose(),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The stores a Cloudflare deployment runs the app repositories on: the app
|
|
42
|
+
* database on an in-process D1, migrated with the committed app set, written
|
|
43
|
+
* through `db.batch()`. The mail and search sets stay on a synchronous handle,
|
|
44
|
+
* as they do in the tenant mail Durable Object.
|
|
45
|
+
*/
|
|
46
|
+
export const openD1TestStores: OpenTestStores = async () => {
|
|
47
|
+
const app = await openD1TestStore("app");
|
|
27
48
|
const shipped = createShippedSqliteDb();
|
|
28
|
-
const local = syncStore(shipped.db);
|
|
49
|
+
const local = syncStore(shipped.db, CLOUDFLARE_LIMITS);
|
|
29
50
|
return {
|
|
30
|
-
stores: {
|
|
31
|
-
app: { db: app, batch: asyncBatch(app) },
|
|
32
|
-
mail: local,
|
|
33
|
-
search: local,
|
|
34
|
-
},
|
|
51
|
+
stores: { app: app.store, mail: local, search: local },
|
|
35
52
|
close: async () => {
|
|
36
53
|
shipped.close();
|
|
37
|
-
await
|
|
54
|
+
await app.close();
|
|
38
55
|
},
|
|
39
56
|
};
|
|
40
57
|
};
|
package/src/test-stores.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BETTER_SQLITE3_LIMITS } from "./bound-parameters.js";
|
|
1
2
|
import { type SqliteStores, syncStores } from "./databases.js";
|
|
2
3
|
import {
|
|
3
4
|
calendarEventIndexTable,
|
|
@@ -16,7 +17,13 @@ export type OpenTestStores = () => Promise<{
|
|
|
16
17
|
/** The whole schema on one in-memory better-sqlite3 handle that plays all three databases. */
|
|
17
18
|
export const openSqliteTestStores: OpenTestStores = async () => {
|
|
18
19
|
const { db, close } = await createTestDb();
|
|
19
|
-
return {
|
|
20
|
+
return {
|
|
21
|
+
stores: syncStores(
|
|
22
|
+
{ app: db, mail: db, search: db },
|
|
23
|
+
BETTER_SQLITE3_LIMITS,
|
|
24
|
+
),
|
|
25
|
+
close,
|
|
26
|
+
};
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
/** The three calendar tables alone on one in-memory better-sqlite3 handle. */
|
|
@@ -26,5 +33,11 @@ export const openCalendarSqliteTestStores: OpenTestStores = async () => {
|
|
|
26
33
|
calendarObjects: calendarObjectTable,
|
|
27
34
|
calendarEventIndexes: calendarEventIndexTable,
|
|
28
35
|
});
|
|
29
|
-
return {
|
|
36
|
+
return {
|
|
37
|
+
stores: syncStores(
|
|
38
|
+
{ app: db, mail: db, search: db },
|
|
39
|
+
BETTER_SQLITE3_LIMITS,
|
|
40
|
+
),
|
|
41
|
+
close,
|
|
42
|
+
};
|
|
30
43
|
};
|