or3-provider-sqlite 0.0.29 → 0.0.31

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.
Files changed (34) hide show
  1. package/README.md +93 -3
  2. package/dist/module.json +1 -1
  3. package/dist/runtime/server/admin/adapters/sync-sqlite.js +9 -0
  4. package/dist/runtime/server/background-jobs/sqlite-provider.js +18 -1
  5. package/dist/runtime/server/db/kysely.js +11 -2
  6. package/dist/runtime/server/db/migrate.js +27 -2
  7. package/dist/runtime/server/db/migration-schema.d.ts +2 -0
  8. package/dist/runtime/server/db/migration-schema.js +14 -0
  9. package/dist/runtime/server/db/migrations/006_sync_snapshots.js +10 -21
  10. package/dist/runtime/server/db/migrations/007_device_cursor_ownership.js +2 -1
  11. package/dist/runtime/server/db/migrations/019_background_generation_history.js +5 -16
  12. package/dist/runtime/server/db/migrations/021_background_request_usage.js +2 -1
  13. package/dist/runtime/server/db/migrations/033_tool_result_operation_ids.d.ts +4 -0
  14. package/dist/runtime/server/db/migrations/033_tool_result_operation_ids.js +35 -0
  15. package/dist/runtime/server/db/migrations/034_sync_intent_fingerprint.d.ts +3 -0
  16. package/dist/runtime/server/db/migrations/034_sync_intent_fingerprint.js +8 -0
  17. package/dist/runtime/server/db/migrations/035_sync_unavailable_records.d.ts +3 -0
  18. package/dist/runtime/server/db/migrations/035_sync_unavailable_records.js +24 -0
  19. package/dist/runtime/server/db/migrations/036_sync_history_incarnation.d.ts +3 -0
  20. package/dist/runtime/server/db/migrations/036_sync_history_incarnation.js +28 -0
  21. package/dist/runtime/server/db/schema.d.ts +5 -0
  22. package/dist/runtime/server/sync/canonical-project-ownership.d.ts +1 -1
  23. package/dist/runtime/server/sync/canonical-project-ownership.js +29 -12
  24. package/dist/runtime/server/sync/evidence-maintenance.d.ts +20 -0
  25. package/dist/runtime/server/sync/evidence-maintenance.js +130 -0
  26. package/dist/runtime/server/sync/history-incarnation.d.ts +8 -0
  27. package/dist/runtime/server/sync/history-incarnation.js +54 -0
  28. package/dist/runtime/server/sync/sqlite-sync-gateway-adapter.d.ts +28 -4
  29. package/dist/runtime/server/sync/sqlite-sync-gateway-adapter.js +804 -361
  30. package/dist/runtime/server/sync/unavailable-records.d.ts +30 -0
  31. package/dist/runtime/server/sync/unavailable-records.js +55 -0
  32. package/dist/runtime/server/utils/digest-uuid.d.ts +2 -0
  33. package/dist/runtime/server/utils/digest-uuid.js +7 -0
  34. package/package.json +1 -1
@@ -1,20 +1,37 @@
1
1
  export function resolveCanonicalProjectOwnership(raw, workspaceId, threadId, explicitOwner) {
2
- if (explicitOwner) {
3
- if (typeof explicitOwner !== "string") throw new Error("Canonical project ownership is unresolved.");
4
- const owner = raw.prepare("SELECT id FROM s_projects WHERE workspace_id = ? AND id = ? AND COALESCE(deleted, 0) = 0").get(workspaceId, explicitOwner);
5
- return { projectId: owner ? explicitOwner : null, status: "resolved" };
2
+ const unresolved = { projectId: null, status: "unresolved" };
3
+ if (explicitOwner !== void 0 && explicitOwner !== null && explicitOwner !== "") {
4
+ if (typeof explicitOwner !== "string") return unresolved;
5
+ const owner2 = raw.prepare("SELECT id FROM s_projects WHERE workspace_id = ? AND id = ? AND COALESCE(deleted, 0) = 0").get(workspaceId, explicitOwner);
6
+ return { projectId: owner2 ? explicitOwner : null, status: "resolved" };
6
7
  }
7
- const projects = raw.prepare("SELECT id, data_json FROM s_projects WHERE workspace_id = ? AND COALESCE(deleted, 0) = 0").all(workspaceId);
8
- const owners = projects.filter((project) => {
9
- const payload = JSON.parse(project.data_json);
10
- const entries = typeof payload.data === "string" ? JSON.parse(payload.data) : payload.data ?? [];
11
- if (!Array.isArray(entries)) throw new Error("Canonical project membership is unresolved.");
12
- return entries.some((entry) => {
8
+ const select = `SELECT id,
9
+ CASE WHEN length(cast(data_json AS blob)) <= 262144 THEN data_json END AS data_json
10
+ FROM s_projects WHERE workspace_id = ? AND COALESCE(deleted, 0) = 0`;
11
+ const first = raw.prepare(`${select} ORDER BY id LIMIT 1`);
12
+ const next = raw.prepare(`${select} AND id > ? ORDER BY id LIMIT 1`);
13
+ let owner = null;
14
+ for (let project = first.get(workspaceId); project; project = next.get(workspaceId, project.id)) {
15
+ if (project.data_json === null) return unresolved;
16
+ let entries;
17
+ try {
18
+ const payload = JSON.parse(project.data_json);
19
+ if (!payload || Array.isArray(payload) || payload.id !== project.id) return unresolved;
20
+ entries = typeof payload.data === "string" ? JSON.parse(payload.data) : payload.data ?? [];
21
+ } catch {
22
+ return unresolved;
23
+ }
24
+ if (!Array.isArray(entries)) return unresolved;
25
+ const owns = entries.some((entry) => {
13
26
  if (typeof entry === "string") return entry.trim() === threadId;
14
27
  if (!entry || typeof entry !== "object" || Array.isArray(entry) || typeof entry.id !== "string") return false;
15
28
  const kind = typeof entry.kind === "string" ? entry.kind.trim().toLowerCase() : entry.kind;
16
29
  return (kind === void 0 || kind === "chat") && entry.id.trim() === threadId;
17
30
  });
18
- });
19
- return { projectId: owners[0]?.id ?? null, status: owners.length > 1 ? "conflict" : "resolved" };
31
+ if (owns) {
32
+ if (owner !== null) return { projectId: owner, status: "conflict" };
33
+ owner = project.id;
34
+ }
35
+ }
36
+ return { projectId: owner, status: "resolved" };
20
37
  }
@@ -0,0 +1,20 @@
1
+ import type { H3Event } from 'h3';
2
+ import type { PendingOp, PushResult } from '~~/shared/sync/types';
3
+ import type { D1SqlStatement } from '../db/d1.js';
4
+ export type RepairGuard = {
5
+ historyIncarnation: string;
6
+ id: string;
7
+ workspaceId: string;
8
+ table: string;
9
+ pk: string;
10
+ clock: number;
11
+ hlc: string;
12
+ opId: string;
13
+ deleted: number;
14
+ materialized: boolean;
15
+ tombstone: string | null;
16
+ };
17
+ export declare function repairAssertion(guard: RepairGuard): D1SqlStatement;
18
+ export declare function repairResolution(guard: RepairGuard, opId: string): D1SqlStatement;
19
+ /** Admin route authorization is supplied by the existing provider-admin action path. */
20
+ export declare function maintainEvidence(event: H3Event, workspaceId: string, action: string, input: Record<string, unknown>, write: (event: H3Event, op: PendingOp, guard: RepairGuard) => Promise<PushResult>, valid: (table: string, pk: string, payload: unknown, clock: number, hlc?: string, opId?: string) => boolean): Promise<Record<string, unknown>>;
@@ -0,0 +1,130 @@
1
+ import { historyAssertion, historyBatch, readHistoryIncarnation, validateExpectedHistory, historyChanged } from "./history-incarnation.js";
2
+ import { randomUUID } from "node:crypto";
3
+ import { incomingRevisionWins } from "~~/shared/sync/revision";
4
+ import { SyncChangeSchema, SnapshotItemSchema, SyncRecordIdentifierSchema } from "~~/shared/sync/schemas";
5
+ import { nextSyncClock } from "~~/shared/sync/prepare-sync-write";
6
+ import { SYNCED_TABLE_MAP } from "../db/schema.js";
7
+ import { boundedSyncPayload, syncRows } from "./unavailable-records.js";
8
+ export function repairAssertion(guard) {
9
+ const current = guard.materialized ? `EXISTS (SELECT 1 FROM ${guard.table} WHERE workspace_id = ? AND id = ?
10
+ AND clock IS ? AND hlc IS ? AND op_id IS ? AND deleted IS ?)` : `NOT EXISTS (SELECT 1 FROM ${guard.table} WHERE workspace_id = ? AND id = ?)`;
11
+ return {
12
+ sql: `SELECT json_extract('{}', CASE WHEN EXISTS (
13
+ SELECT 1 FROM sync_unavailable_records WHERE workspace_id = ? AND id = ? AND status = 'unresolved'
14
+ ) AND ${current}
15
+ AND (SELECT json_array(clock,hlc,op_id) FROM tombstones WHERE workspace_id = ? AND table_name = ? AND pk = ?) IS ?
16
+ THEN '$' ELSE 'OR3_SYNC_REPAIR_CHANGED' END)`,
17
+ parameters: [
18
+ guard.workspaceId,
19
+ guard.id,
20
+ guard.workspaceId,
21
+ guard.pk,
22
+ ...guard.materialized ? [guard.clock, guard.hlc, guard.opId, guard.deleted] : [],
23
+ guard.workspaceId,
24
+ guard.table.slice(2),
25
+ guard.pk,
26
+ guard.tombstone
27
+ ]
28
+ };
29
+ }
30
+ export function repairResolution(guard, opId) {
31
+ return { sql: `UPDATE sync_unavailable_records SET status = 'repaired', resolved_op_id = ?
32
+ WHERE workspace_id = ? AND id = ?`, parameters: [opId, guard.workspaceId, guard.id] };
33
+ }
34
+ export async function maintainEvidence(event, workspaceId, action, input, write, valid) {
35
+ if (action === "inspect") {
36
+ const after = typeof input.after === "string" ? input.after : "";
37
+ const items = await syncRows(`SELECT id,source,
38
+ CASE WHEN length(cast(locator AS blob)) <= 4096 THEN locator END AS locator,
39
+ CASE WHEN length(cast(revision AS blob)) <= 4096 THEN revision END AS revision,
40
+ reason,status,created_at,
41
+ length(cast(payload_json AS blob)) AS payload_bytes FROM sync_unavailable_records
42
+ WHERE workspace_id = ? AND id > ? ORDER BY id LIMIT 50`, workspaceId, after);
43
+ return { items, next: items.length === 50 ? items[49].id : null };
44
+ }
45
+ if (typeof input.id !== "string" || !input.id || input.id.length > 512) throw new Error("Evidence id required");
46
+ const [evidence] = await syncRows(`SELECT id,source,status,
47
+ ${boundedSyncPayload("metadata_json")} AS metadata_json, ${boundedSyncPayload("payload_json")} AS payload_json,
48
+ coalesce(length(cast(payload_json AS blob)),0) AS payload_bytes FROM sync_unavailable_records WHERE workspace_id = ? AND id = ?`, workspaceId, input.id);
49
+ if (!evidence) throw new Error("Evidence unavailable");
50
+ if (action === "export") {
51
+ const offset = input.offset ?? 0;
52
+ if (!Number.isSafeInteger(offset) || offset < 0) throw new Error("Invalid evidence export offset");
53
+ const [chunk] = await syncRows(`SELECT hex(substr(cast(payload_json AS blob),?,32768)) AS payloadHex,
54
+ hex(substr(cast(metadata_json AS blob),?,32768)) AS metadataHex,
55
+ max(coalesce(length(cast(payload_json AS blob)),0),length(cast(metadata_json AS blob))) AS totalBytes
56
+ FROM sync_unavailable_records WHERE workspace_id = ? AND id = ?`, offset + 1, offset + 1, workspaceId, input.id);
57
+ return { ...chunk, offset, chunkBytes: 32768 };
58
+ }
59
+ if (!evidence.metadata_json) throw new Error("Evidence metadata requires explicit offline recovery");
60
+ const metadata = JSON.parse(evidence.metadata_json);
61
+ if (action === "revalidate") {
62
+ let healthy = false;
63
+ try {
64
+ const payload = evidence.payload_json ? JSON.parse(evidence.payload_json) : void 0;
65
+ const revision = { clock: metadata.clock, hlc: metadata.hlc, opId: metadata.op_id };
66
+ const envelopeValid = evidence.source === "pull" ? SyncChangeSchema.safeParse({
67
+ serverVersion: metadata.server_version,
68
+ tableName: metadata.table_name,
69
+ pk: metadata.pk,
70
+ op: metadata.op,
71
+ payload,
72
+ stamp: { ...revision, deviceId: metadata.device_id }
73
+ }).success : evidence.source === "snapshot" ? SnapshotItemSchema.safeParse({ kind: metadata.kind, tableName: metadata.table_name, pk: metadata.pk, revision, payload, serverDeletedAt: metadata.server_deleted_at }).success : Number.isSafeInteger(metadata.clock) && metadata.clock >= 0 && !!metadata.hlc && !!metadata.op_id;
74
+ const deleted = metadata.op === "delete" || metadata.kind === "tombstone";
75
+ healthy = envelopeValid && evidence.payload_bytes <= 262144 && (deleted ? Object.hasOwn(SYNCED_TABLE_MAP, metadata.table_name) : valid(metadata.table_name, metadata.pk, payload, metadata.clock, metadata.hlc, metadata.op_id));
76
+ } catch {
77
+ }
78
+ return { id: evidence.id, valid: healthy, status: evidence.status };
79
+ }
80
+ if (action !== "repair") throw new Error("Unknown evidence action");
81
+ validateExpectedHistory(input.historyIncarnation);
82
+ const historyIncarnation = await readHistoryIncarnation();
83
+ if (input.historyIncarnation !== historyIncarnation || metadata.historyIncarnation !== historyIncarnation) historyChanged(historyIncarnation);
84
+ if (evidence.status !== "unresolved") return { id: evidence.id, status: evidence.status };
85
+ const table = Object.hasOwn(SYNCED_TABLE_MAP, metadata.table_name) ? SYNCED_TABLE_MAP[metadata.table_name] : void 0;
86
+ if (!table || !SyncRecordIdentifierSchema.safeParse(metadata.pk).success || !Number.isSafeInteger(metadata.clock) || metadata.clock < 0 || !metadata.hlc || !metadata.op_id) {
87
+ throw new Error("Unrepairable evidence revision or identity; no clock reset is permitted");
88
+ }
89
+ const [current] = await syncRows(
90
+ `SELECT clock,hlc,op_id,deleted FROM ${table} WHERE workspace_id = ? AND id = ?`,
91
+ workspaceId,
92
+ metadata.pk
93
+ );
94
+ const [tombstone] = await syncRows(
95
+ "SELECT json_array(clock,hlc,op_id) AS revision FROM tombstones WHERE workspace_id = ? AND table_name = ? AND pk = ?",
96
+ workspaceId,
97
+ metadata.table_name,
98
+ metadata.pk
99
+ );
100
+ const deletedRevision = tombstone ? JSON.parse(tombstone.revision) : void 0;
101
+ if (deletedRevision && (!Number.isSafeInteger(deletedRevision[0]) || deletedRevision[0] < 0 || !deletedRevision[1] || !deletedRevision[2])) throw new Error("Unrepairable deletion revision");
102
+ const newerDelete = deletedRevision && current && incomingRevisionWins(
103
+ { clock: deletedRevision[0], hlc: deletedRevision[1], opId: deletedRevision[2] },
104
+ { clock: current.clock, hlc: current.hlc, opId: current.op_id }
105
+ );
106
+ const winner = current ?? (deletedRevision ? { clock: deletedRevision[0], hlc: deletedRevision[1], op_id: deletedRevision[2], deleted: 1 } : void 0);
107
+ const isDeletion = metadata.op === "delete" || metadata.kind === "tombstone";
108
+ if (!winner || !current && !isDeletion || winner.clock !== metadata.clock || winner.hlc !== metadata.hlc || winner.op_id !== metadata.op_id || newerDelete) {
109
+ await historyBatch([historyAssertion(historyIncarnation), { sql: "UPDATE sync_unavailable_records SET status = 'superseded' WHERE workspace_id = ? AND id = ? AND status = 'unresolved'", parameters: [workspaceId, evidence.id] }], historyIncarnation);
110
+ return { id: evidence.id, status: "superseded" };
111
+ }
112
+ if (input.operation !== void 0 && input.operation !== "put" && input.operation !== "delete") throw new Error("Invalid repair operation");
113
+ if (!input.payload || typeof input.payload !== "object" || Array.isArray(input.payload)) throw new Error("Repair replacement payload required");
114
+ const opId = randomUUID();
115
+ const clock = nextSyncClock(winner.clock);
116
+ const op = {
117
+ id: opId,
118
+ tableName: metadata.table_name,
119
+ pk: metadata.pk,
120
+ operation: input.operation === "delete" ? "delete" : "put",
121
+ payload: input.payload,
122
+ stamp: { clock, hlc: `${Date.now().toString(36)}:000:repair`, opId, deviceId: "server:sync-repair" },
123
+ createdAt: Date.now(),
124
+ attempts: 0,
125
+ status: "pending"
126
+ };
127
+ const result = await write(event, op, { historyIncarnation, id: evidence.id, workspaceId, table, pk: metadata.pk, ...winner, opId: winner.op_id, materialized: !!current, tombstone: tombstone?.revision ?? null });
128
+ if (!result.results[0]?.success || result.results[0]?.applied === false) throw new Error(result.results[0]?.error ?? "Repair did not win");
129
+ return { id: evidence.id, status: "repaired", opId, serverVersion: result.results[0].serverVersion };
130
+ }
@@ -0,0 +1,8 @@
1
+ import { type D1SqlStatement } from '../db/d1.js';
2
+ export declare function validHistoryIncarnation(value: unknown): value is string;
3
+ export declare function historyChanged(historyIncarnation: string): never;
4
+ export declare function validateExpectedHistory(value: unknown): asserts value is string | null;
5
+ export declare function readHistoryIncarnation(): Promise<string>;
6
+ /** SQL assertion is evaluated inside the same atomic batch/transaction as writes. */
7
+ export declare function historyAssertion(expected: string): D1SqlStatement;
8
+ export declare function historyBatch(statements: D1SqlStatement[], expected?: string): Promise<void>;
@@ -0,0 +1,54 @@
1
+ import { createError } from "h3";
2
+ import { getRawDb, isD1Driver } from "../db/kysely.js";
3
+ import { d1All, d1Batch } from "../db/d1.js";
4
+ export function validHistoryIncarnation(value) {
5
+ return typeof value === "string" && /^[\x21-\x7e]{1,128}$/.test(value);
6
+ }
7
+ export function historyChanged(historyIncarnation) {
8
+ throw createError({
9
+ statusCode: 409,
10
+ statusMessage: "Sync history changed",
11
+ data: { code: "OR3_SYNC_HISTORY_CHANGED", historyIncarnation, requiresSnapshot: true }
12
+ });
13
+ }
14
+ export function validateExpectedHistory(value) {
15
+ if (value !== null && !validHistoryIncarnation(value)) {
16
+ throw createError({ statusCode: 400, statusMessage: "Invalid history incarnation" });
17
+ }
18
+ }
19
+ export async function readHistoryIncarnation() {
20
+ const query = "SELECT id,incarnation FROM sync_history LIMIT 2";
21
+ const rows = isD1Driver() ? await d1All(query) : getRawDb().prepare(query).all();
22
+ if (rows.length !== 1 || rows[0]?.id !== 1 || !validHistoryIncarnation(rows[0]?.incarnation)) {
23
+ throw new Error("Invalid sync history singleton; offline recovery required");
24
+ }
25
+ return rows[0].incarnation;
26
+ }
27
+ export function historyAssertion(expected) {
28
+ return {
29
+ sql: `SELECT json_extract('{}', CASE WHEN (SELECT incarnation FROM sync_history WHERE id=1) = ?
30
+ THEN '$' ELSE 'OR3_SYNC_HISTORY_CHANGED' END)`,
31
+ parameters: [expected]
32
+ };
33
+ }
34
+ export async function historyBatch(statements, expected) {
35
+ try {
36
+ if (isD1Driver()) {
37
+ await d1Batch(statements);
38
+ return;
39
+ }
40
+ const raw = getRawDb();
41
+ raw.transaction(() => {
42
+ for (const statement of statements) {
43
+ const prepared = raw.prepare(statement.sql);
44
+ if (prepared.reader) prepared.all(...statement.parameters ?? []);
45
+ else prepared.run(...statement.parameters ?? []);
46
+ }
47
+ }).immediate();
48
+ } catch (error) {
49
+ if (expected && String(error).includes("OR3_SYNC_HISTORY_CHANGED")) {
50
+ historyChanged(await readHistoryIncarnation());
51
+ }
52
+ throw error;
53
+ }
54
+ }
@@ -1,3 +1,4 @@
1
+ import { type RepairGuard } from './evidence-maintenance.js';
1
2
  import { SqliteExternalStorageGenerationUploadCoordinator } from '../storage/sqlite-generation-upload-coordinator.js';
2
3
  /**
3
4
  * SQLite implementation of SyncGatewayAdapter.
@@ -9,7 +10,7 @@ import { SqliteExternalStorageGenerationUploadCoordinator } from '../storage/sql
9
10
  import type { H3Event } from 'h3';
10
11
  import type { CanonicalStorageQueryRequest, CanonicalStorageQueryResponse, SyncGatewayAdapter, SyncMaintenanceState, UploadIntentConsumptionRequest, UploadIntentReservationRequest } from '~~/server/sync/gateway/types';
11
12
  import type { AdmitChatGenerationResult, CanonicalGenerationSnapshot, CanonicalHistoryActor, ChatGenerationAdmissionEnvelope, FinalizeChatGenerationResult } from '~~/shared/chat/background-history';
12
- import type { PullRequest, PullResponse, PushBatch, PushResult, SnapshotRequest, SnapshotResponse } from '~~/shared/sync/types';
13
+ import type { PullUnavailableRecord, SnapshotUnavailableRecord, PullRequest, PullResponse, PushBatch, PushResult, SnapshotRequest, SnapshotResponse } from '~~/shared/sync/types';
13
14
  import { type ToolResultArtifactRow } from '~~/shared/chat/tool-result-artifact';
14
15
  import { type CanonicalChatQuery, type CanonicalChatReadResult } from '~~/shared/chat/history-reader';
15
16
  export declare function pruneExpiredSyncSnapshots(): Promise<void>;
@@ -18,11 +19,15 @@ export declare class SqliteSyncGatewayAdapter implements SyncGatewayAdapter {
18
19
  private versionWatchers;
19
20
  watchVersion(event: H3Event, scope: {
20
21
  workspaceId: string;
21
- }, onVersion: (version: number) => void, onError: (error: unknown) => void): Promise<() => void>;
22
+ }, onVersion: (position: {
23
+ historyIncarnation: string;
24
+ version: number;
25
+ }) => void, onError: (error: unknown) => void): Promise<() => void>;
22
26
  /** Construct only on use, after the provider initializes its database. */
23
27
  get storageGenerationCoordinator(): SqliteExternalStorageGenerationUploadCoordinator | undefined;
24
28
  get capabilities(): {
25
29
  readonly snapshotBootstrap: "snapshot-v1";
30
+ readonly unavailableRecords: "v1";
26
31
  readonly historyRetention: "snapshot-v1";
27
32
  readonly retainedStorageMetadata: "v1";
28
33
  readonly atomicUploadQuota: "retained-v1";
@@ -35,9 +40,15 @@ export declare class SqliteSyncGatewayAdapter implements SyncGatewayAdapter {
35
40
  readonly retainedStorageMetadata: "v1";
36
41
  readonly atomicUploadQuota: "retained-v1";
37
42
  readonly externalStorageGenerations?: "v1" | undefined;
43
+ readonly historyIncarnation: "v1";
38
44
  readonly snapshotBootstrap: "snapshot-v1";
45
+ readonly unavailableRecords: "v1";
39
46
  readonly historyRetention: "snapshot-v1";
40
47
  };
48
+ getHistoryIncarnation(event: H3Event, scope: {
49
+ workspaceId: string;
50
+ }): Promise<string>;
51
+ private checkHistory;
41
52
  private get db();
42
53
  readChatHistory(actor: CanonicalHistoryActor, query: CanonicalChatQuery, signal?: AbortSignal): Promise<CanonicalChatReadResult>;
43
54
  private assertCanonicalActor;
@@ -67,8 +78,20 @@ export declare class SqliteSyncGatewayAdapter implements SyncGatewayAdapter {
67
78
  intentId: string;
68
79
  }): Promise<void>;
69
80
  queryCanonicalStorage(event: H3Event, input: CanonicalStorageQueryRequest): Promise<CanonicalStorageQueryResponse>;
70
- push(event: H3Event, input: PushBatch): Promise<PushResult>;
81
+ push(event: H3Event, input: PushBatch, repair?: RepairGuard): Promise<PushResult>;
71
82
  pull(event: H3Event, input: PullRequest): Promise<PullResponse>;
83
+ retainUnavailableRecord(event: H3Event, input: {
84
+ scope: {
85
+ workspaceId: string;
86
+ };
87
+ source: 'pull' | 'snapshot';
88
+ historyIncarnation?: string;
89
+ record: unknown;
90
+ marker: Omit<PullUnavailableRecord, 'evidenceRef'> | Omit<SnapshotUnavailableRecord, 'evidenceRef'>;
91
+ }): Promise<{
92
+ evidenceRef: string;
93
+ }>;
94
+ maintainUnavailableRecords(event: H3Event, workspaceId: string, action: string, input: Record<string, unknown>): Promise<Record<string, unknown>>;
72
95
  snapshot(event: H3Event, input: SnapshotRequest): Promise<SnapshotResponse>;
73
96
  /** Archives retain full Trash metadata; normal sync still emits tombstones. */
74
97
  backupSnapshot(event: H3Event, input: SnapshotRequest): Promise<SnapshotResponse>;
@@ -79,6 +102,7 @@ export declare class SqliteSyncGatewayAdapter implements SyncGatewayAdapter {
79
102
  };
80
103
  deviceId: string;
81
104
  version: number;
105
+ historyIncarnation?: string | null;
82
106
  }): Promise<void>;
83
107
  gcTombstones(event: H3Event, input: {
84
108
  scope: {
@@ -104,4 +128,4 @@ export declare class SqliteSyncGatewayAdapter implements SyncGatewayAdapter {
104
128
  }): void;
105
129
  failMaintenanceRun(error: string): void;
106
130
  }
107
- export declare function createSqliteSyncGatewayAdapter(): SyncGatewayAdapter;
131
+ export declare function createSqliteSyncGatewayAdapter(): SqliteSyncGatewayAdapter;