or3-provider-sqlite 0.0.1 → 0.0.2
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/README.md +6 -3
- package/dist/module.json +1 -1
- package/dist/runtime/server/admin/adapters/sync-sqlite.js +12 -34
- package/dist/runtime/server/admin/stores/sqlite-store.js +64 -9
- package/dist/runtime/server/auth/sqlite-auth-workspace-store.d.ts +16 -1
- package/dist/runtime/server/auth/sqlite-auth-workspace-store.js +114 -3
- package/dist/runtime/server/db/migrate.js +45 -1
- package/dist/runtime/server/db/migrations/006_sync_snapshots.d.ts +10 -0
- package/dist/runtime/server/db/migrations/006_sync_snapshots.js +106 -0
- package/dist/runtime/server/db/migrations/007_device_cursor_ownership.d.ts +7 -0
- package/dist/runtime/server/db/migrations/007_device_cursor_ownership.js +5 -0
- package/dist/runtime/server/db/migrations/008_upload_intents.d.ts +4 -0
- package/dist/runtime/server/db/migrations/008_upload_intents.js +26 -0
- package/dist/runtime/server/db/schema.d.ts +40 -0
- package/dist/runtime/server/plugins/register.js +7 -0
- package/dist/runtime/server/sync/history-gc-policy.d.ts +13 -0
- package/dist/runtime/server/sync/history-gc-policy.js +8 -0
- package/dist/runtime/server/sync/sqlite-sync-gateway-adapter.d.ts +14 -2
- package/dist/runtime/server/sync/sqlite-sync-gateway-adapter.js +901 -67
- package/dist/runtime/server/webhooks/sqlite-webhook-store.d.ts +9 -0
- package/dist/runtime/server/webhooks/sqlite-webhook-store.js +521 -0
- package/package.json +5 -1
|
@@ -70,6 +70,7 @@ export interface DeviceCursorsTable {
|
|
|
70
70
|
id: string;
|
|
71
71
|
workspace_id: string;
|
|
72
72
|
device_id: string;
|
|
73
|
+
owner_user_id: string | null;
|
|
73
74
|
last_seen_version: number;
|
|
74
75
|
updated_at: Generated<number>;
|
|
75
76
|
}
|
|
@@ -80,6 +81,8 @@ export interface TombstonesTable {
|
|
|
80
81
|
pk: string;
|
|
81
82
|
deleted_at: number;
|
|
82
83
|
clock: number;
|
|
84
|
+
hlc: string;
|
|
85
|
+
op_id: string;
|
|
83
86
|
server_version: number;
|
|
84
87
|
created_at: Generated<number>;
|
|
85
88
|
}
|
|
@@ -90,10 +93,44 @@ export interface SyncedEntityTable {
|
|
|
90
93
|
clock: number;
|
|
91
94
|
hlc: string;
|
|
92
95
|
device_id: string;
|
|
96
|
+
op_id: string;
|
|
93
97
|
deleted: Generated<number>;
|
|
94
98
|
created_at: Generated<number>;
|
|
95
99
|
updated_at: Generated<number>;
|
|
96
100
|
}
|
|
101
|
+
export interface SyncSnapshotsTable {
|
|
102
|
+
id: string;
|
|
103
|
+
workspace_id: string;
|
|
104
|
+
high_watermark: number;
|
|
105
|
+
tables_json: string;
|
|
106
|
+
created_at: number;
|
|
107
|
+
expires_at: number;
|
|
108
|
+
}
|
|
109
|
+
export interface SyncSnapshotItemsTable {
|
|
110
|
+
snapshot_id: string;
|
|
111
|
+
table_name: string;
|
|
112
|
+
pk: string;
|
|
113
|
+
kind: string;
|
|
114
|
+
payload_json: string | null;
|
|
115
|
+
clock: number;
|
|
116
|
+
hlc: string;
|
|
117
|
+
op_id: string;
|
|
118
|
+
server_deleted_at: number | null;
|
|
119
|
+
}
|
|
120
|
+
export interface UploadIntentsTable {
|
|
121
|
+
id: string;
|
|
122
|
+
workspace_id: string;
|
|
123
|
+
hash: string;
|
|
124
|
+
mime_type: string;
|
|
125
|
+
size_bytes: number;
|
|
126
|
+
reserved_bytes: number;
|
|
127
|
+
expires_at: number;
|
|
128
|
+
status: 'active' | 'consumed' | 'cancelled' | 'expired';
|
|
129
|
+
storage_id: string | null;
|
|
130
|
+
created_at: number;
|
|
131
|
+
consumed_at: number | null;
|
|
132
|
+
cancelled_at: number | null;
|
|
133
|
+
}
|
|
97
134
|
export interface AdminUsersTable {
|
|
98
135
|
user_id: string;
|
|
99
136
|
created_at: number;
|
|
@@ -116,6 +153,9 @@ export interface Or3SqliteDb {
|
|
|
116
153
|
change_log: ChangeLogTable;
|
|
117
154
|
device_cursors: DeviceCursorsTable;
|
|
118
155
|
tombstones: TombstonesTable;
|
|
156
|
+
sync_snapshots: SyncSnapshotsTable;
|
|
157
|
+
sync_snapshot_items: SyncSnapshotItemsTable;
|
|
158
|
+
upload_intents: UploadIntentsTable;
|
|
119
159
|
s_threads: SyncedEntityTable;
|
|
120
160
|
s_messages: SyncedEntityTable;
|
|
121
161
|
s_projects: SyncedEntityTable;
|
|
@@ -2,8 +2,10 @@ import { registerAuthWorkspaceStore } from "~~/server/auth/store/registry";
|
|
|
2
2
|
import { registerProviderAdminAdapter } from "~~/server/admin/providers/registry";
|
|
3
3
|
import { registerAdminStoreProvider } from "~~/server/admin/stores/registry";
|
|
4
4
|
import { registerSyncGatewayAdapter } from "~~/server/sync/gateway/registry";
|
|
5
|
+
import { registerWebhookStore } from "~~/server/utils/webhooks/store/registry";
|
|
5
6
|
import { createSqliteAuthWorkspaceStore } from "../auth/sqlite-auth-workspace-store.js";
|
|
6
7
|
import { createSqliteSyncGatewayAdapter } from "../sync/sqlite-sync-gateway-adapter.js";
|
|
8
|
+
import { createSqliteWebhookStore } from "../webhooks/sqlite-webhook-store.js";
|
|
7
9
|
import {
|
|
8
10
|
createSqliteAdminUserStore,
|
|
9
11
|
createSqliteWorkspaceAccessStore,
|
|
@@ -31,6 +33,11 @@ export default defineNitroPlugin(async () => {
|
|
|
31
33
|
order: 100,
|
|
32
34
|
create: createSqliteSyncGatewayAdapter
|
|
33
35
|
});
|
|
36
|
+
registerWebhookStore({
|
|
37
|
+
id: SQLITE_PROVIDER_ID,
|
|
38
|
+
order: 100,
|
|
39
|
+
create: createSqliteWebhookStore
|
|
40
|
+
});
|
|
34
41
|
registerAdminStoreProvider({
|
|
35
42
|
id: SQLITE_PROVIDER_ID,
|
|
36
43
|
createWorkspaceAccessStore: createSqliteWorkspaceAccessStore,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sync history retention is deliberately fail-closed.
|
|
3
|
+
*
|
|
4
|
+
* An operator cannot enable this with environment configuration. The policy
|
|
5
|
+
* may change only after snapshot-at-high-watermark bootstrap is implemented
|
|
6
|
+
* and verified for SQLite deployments.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SYNC_HISTORY_GC_POLICY: Readonly<{
|
|
9
|
+
enabled: true;
|
|
10
|
+
snapshotBootstrapVerified: true;
|
|
11
|
+
reason: "SQLite history GC is guarded by the verified snapshot-v1 retention contract.";
|
|
12
|
+
}>;
|
|
13
|
+
export declare function canRunSyncHistoryGc(): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const SYNC_HISTORY_GC_POLICY = Object.freeze({
|
|
2
|
+
enabled: true,
|
|
3
|
+
snapshotBootstrapVerified: true,
|
|
4
|
+
reason: "SQLite history GC is guarded by the verified snapshot-v1 retention contract."
|
|
5
|
+
});
|
|
6
|
+
export function canRunSyncHistoryGc() {
|
|
7
|
+
return SYNC_HISTORY_GC_POLICY.enabled && SYNC_HISTORY_GC_POLICY.snapshotBootstrapVerified;
|
|
8
|
+
}
|
|
@@ -6,13 +6,25 @@
|
|
|
6
6
|
* (BEGIN IMMEDIATE prevents concurrent server_version races).
|
|
7
7
|
*/
|
|
8
8
|
import type { H3Event } from 'h3';
|
|
9
|
-
import type { SyncGatewayAdapter } from '~~/server/sync/gateway/types';
|
|
10
|
-
import type { PullRequest, PullResponse, PushBatch, PushResult } from '~~/shared/sync/types';
|
|
9
|
+
import type { CanonicalStorageQueryRequest, CanonicalStorageQueryResponse, SyncGatewayAdapter, UploadIntentConsumptionRequest, UploadIntentReservationRequest } from '~~/server/sync/gateway/types';
|
|
10
|
+
import type { PullRequest, PullResponse, PushBatch, PushResult, SnapshotRequest, SnapshotResponse } from '~~/shared/sync/types';
|
|
11
11
|
export declare class SqliteSyncGatewayAdapter implements SyncGatewayAdapter {
|
|
12
12
|
id: string;
|
|
13
|
+
readonly capabilities: {
|
|
14
|
+
readonly snapshotBootstrap: "snapshot-v1";
|
|
15
|
+
readonly historyRetention: "snapshot-v1";
|
|
16
|
+
};
|
|
13
17
|
private get db();
|
|
18
|
+
reserveUploadIntent(event: H3Event, input: UploadIntentReservationRequest): Promise<void>;
|
|
19
|
+
consumeUploadIntent(event: H3Event, input: UploadIntentConsumptionRequest): Promise<void>;
|
|
20
|
+
cancelUploadIntent(event: H3Event, input: {
|
|
21
|
+
workspaceId: string;
|
|
22
|
+
intentId: string;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
queryCanonicalStorage(event: H3Event, input: CanonicalStorageQueryRequest): Promise<CanonicalStorageQueryResponse>;
|
|
14
25
|
push(event: H3Event, input: PushBatch): Promise<PushResult>;
|
|
15
26
|
pull(event: H3Event, input: PullRequest): Promise<PullResponse>;
|
|
27
|
+
snapshot(event: H3Event, input: SnapshotRequest): Promise<SnapshotResponse>;
|
|
16
28
|
updateCursor(event: H3Event, input: {
|
|
17
29
|
scope: {
|
|
18
30
|
workspaceId: string;
|