feat(sync): round trip cloud snapshots

This commit is contained in:
2026-05-16 00:01:28 -04:00
parent 06e947f43e
commit 40ab6b4874
22 changed files with 694 additions and 69 deletions
+8 -2
View File
@@ -15,6 +15,7 @@ export interface TestEnvOptions {
d1?: RecordedD1Database;
kvEntries?: [string, string][];
kvDeletes?: string[];
kvPuts?: [string, string][];
kvReads?: string[];
r2Deletes?: string[];
r2Gets?: string[];
@@ -51,6 +52,11 @@ export function testEnv(options: TestEnvOptions): Env {
options.kvReads?.push(key);
return Promise.resolve(values.get(key) ?? null);
},
put(key: string, value: string): Promise<void> {
options.kvPuts?.push([key, value]);
values.set(key, value);
return Promise.resolve();
},
delete(key: string): Promise<void> {
options.kvDeletes?.push(key);
values.delete(key);
@@ -110,12 +116,12 @@ export function testD1Database(rows: unknown[] | TestD1DatabaseOptions): Recorde
};
}
export function sessionDocument(deviceId = "device-01"): string {
export function sessionDocument(deviceId: string | null = "device-01"): string {
return JSON.stringify({
version: 1,
user_id: "user-01",
session_id: "session-01",
device_id: deviceId,
...(deviceId === null ? {} : { device_id: deviceId }),
expires_at: "2099-01-01T00:00:00.000Z",
});
}