@syncular/server 0.0.1-60 → 0.0.1
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/dist/clients.d.ts +0 -1
- package/dist/clients.d.ts.map +1 -1
- package/dist/clients.js.map +1 -1
- package/dist/dialect/types.d.ts +4 -17
- package/dist/dialect/types.d.ts.map +1 -1
- package/dist/proxy/handler.d.ts.map +1 -1
- package/dist/proxy/handler.js +0 -1
- package/dist/proxy/handler.js.map +1 -1
- package/dist/proxy/index.d.ts +2 -2
- package/dist/proxy/index.d.ts.map +1 -1
- package/dist/proxy/index.js.map +1 -1
- package/dist/proxy/oplog.d.ts +0 -1
- package/dist/proxy/oplog.d.ts.map +1 -1
- package/dist/proxy/oplog.js +3 -9
- package/dist/proxy/oplog.js.map +1 -1
- package/dist/proxy/registry.d.ts +11 -0
- package/dist/proxy/registry.d.ts.map +1 -1
- package/dist/proxy/registry.js +24 -0
- package/dist/proxy/registry.js.map +1 -1
- package/dist/proxy/types.d.ts +0 -2
- package/dist/proxy/types.d.ts.map +1 -1
- package/dist/pull.d.ts +0 -1
- package/dist/pull.d.ts.map +1 -1
- package/dist/pull.js +5 -23
- package/dist/pull.js.map +1 -1
- package/dist/push.d.ts +1 -13
- package/dist/push.d.ts.map +1 -1
- package/dist/push.js +7 -54
- package/dist/push.js.map +1 -1
- package/dist/realtime/types.d.ts +0 -2
- package/dist/realtime/types.d.ts.map +1 -1
- package/dist/schema.d.ts +0 -10
- package/dist/schema.d.ts.map +1 -1
- package/dist/shapes/create-handler.d.ts.map +1 -1
- package/dist/shapes/create-handler.js +26 -86
- package/dist/shapes/create-handler.js.map +1 -1
- package/dist/snapshot-chunks/db-metadata.d.ts.map +1 -1
- package/dist/snapshot-chunks/db-metadata.js +0 -3
- package/dist/snapshot-chunks/db-metadata.js.map +1 -1
- package/dist/snapshot-chunks/types.d.ts +0 -2
- package/dist/snapshot-chunks/types.d.ts.map +1 -1
- package/dist/snapshot-chunks.d.ts +0 -3
- package/dist/snapshot-chunks.d.ts.map +1 -1
- package/dist/snapshot-chunks.js +1 -8
- package/dist/snapshot-chunks.js.map +1 -1
- package/package.json +7 -28
- package/src/clients.ts +0 -1
- package/src/dialect/types.ts +6 -27
- package/src/proxy/handler.ts +0 -1
- package/src/proxy/index.ts +1 -2
- package/src/proxy/oplog.ts +3 -10
- package/src/proxy/registry.ts +33 -0
- package/src/proxy/types.ts +0 -2
- package/src/pull.ts +5 -27
- package/src/push.ts +8 -77
- package/src/realtime/types.ts +0 -2
- package/src/schema.ts +0 -10
- package/src/shapes/create-handler.ts +43 -108
- package/src/snapshot-chunks/db-metadata.ts +0 -3
- package/src/snapshot-chunks/types.ts +0 -2
- package/src/snapshot-chunks.ts +1 -12
package/dist/snapshot-chunks.js
CHANGED
|
@@ -32,8 +32,7 @@ export async function readSnapshotChunkRefByPageKey(db, args) {
|
|
|
32
32
|
select chunk_id, sha256, byte_length, encoding, compression
|
|
33
33
|
from ${sql.table('sync_snapshot_chunks')}
|
|
34
34
|
where
|
|
35
|
-
|
|
36
|
-
and scope_key = ${args.scopeKey}
|
|
35
|
+
scope_key = ${args.scopeKey}
|
|
37
36
|
and scope = ${args.scope}
|
|
38
37
|
and as_of_commit_seq = ${args.asOfCommitSeq}
|
|
39
38
|
and row_cursor = ${rowCursorKey}
|
|
@@ -68,7 +67,6 @@ export async function insertSnapshotChunk(db, args) {
|
|
|
68
67
|
await sql `
|
|
69
68
|
insert into ${sql.table('sync_snapshot_chunks')} (
|
|
70
69
|
chunk_id,
|
|
71
|
-
partition_id,
|
|
72
70
|
scope_key,
|
|
73
71
|
scope,
|
|
74
72
|
as_of_commit_seq,
|
|
@@ -85,7 +83,6 @@ export async function insertSnapshotChunk(db, args) {
|
|
|
85
83
|
)
|
|
86
84
|
values (
|
|
87
85
|
${args.chunkId},
|
|
88
|
-
${args.partitionId},
|
|
89
86
|
${args.scopeKey},
|
|
90
87
|
${args.scope},
|
|
91
88
|
${args.asOfCommitSeq},
|
|
@@ -101,7 +98,6 @@ export async function insertSnapshotChunk(db, args) {
|
|
|
101
98
|
${args.expiresAt}
|
|
102
99
|
)
|
|
103
100
|
on conflict (
|
|
104
|
-
partition_id,
|
|
105
101
|
scope_key,
|
|
106
102
|
scope,
|
|
107
103
|
as_of_commit_seq,
|
|
@@ -115,7 +111,6 @@ export async function insertSnapshotChunk(db, args) {
|
|
|
115
111
|
blob_hash = ${blobHash}
|
|
116
112
|
`.execute(db);
|
|
117
113
|
const ref = await readSnapshotChunkRefByPageKey(db, {
|
|
118
|
-
partitionId: args.partitionId,
|
|
119
114
|
scopeKey: args.scopeKey,
|
|
120
115
|
scope: args.scope,
|
|
121
116
|
asOfCommitSeq: args.asOfCommitSeq,
|
|
@@ -133,7 +128,6 @@ export async function readSnapshotChunk(db, chunkId, options) {
|
|
|
133
128
|
const rowResult = await sql `
|
|
134
129
|
select
|
|
135
130
|
chunk_id,
|
|
136
|
-
partition_id,
|
|
137
131
|
scope_key,
|
|
138
132
|
scope,
|
|
139
133
|
as_of_commit_seq,
|
|
@@ -178,7 +172,6 @@ export async function readSnapshotChunk(db, chunkId, options) {
|
|
|
178
172
|
}
|
|
179
173
|
return {
|
|
180
174
|
chunkId: row.chunk_id,
|
|
181
|
-
partitionId: row.partition_id,
|
|
182
175
|
scopeKey: row.scope_key,
|
|
183
176
|
scope: row.scope,
|
|
184
177
|
asOfCommitSeq: Number(row.as_of_commit_seq ?? 0),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-chunks.js","sourceRoot":"","sources":["../src/snapshot-chunks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAe,GAAG,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"snapshot-chunks.js","sourceRoot":"","sources":["../src/snapshot-chunks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAe,GAAG,EAAE,MAAM,QAAQ,CAAC;AA4B1C,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C,WAAW,IAAI,CAAC,CAAC;QACxC,IAAI;QACJ,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC;KAC3C,CAAC;AAAA,CACH;AAED,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,EAAc,EACd,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAChB;IACjB,MAAM,GAAG,GAAG,MAAM,GAAG,CAAA;kBACL,GAAG,CAAC,KAAK,CAAC,sBAAsB,CAAC;0BACzB,MAAM;GAC7B,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAEd,OAAO,MAAM,CAAC,GAAG,CAAC,eAAe,IAAI,CAAC,CAAC,CAAC;AAAA,CACzC"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/server",
|
|
3
|
-
"version": "0.0.1
|
|
4
|
-
"description": "Server-side sync engine with push/pull, pruning, and snapshot support",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"author": "Benjamin Kniffler",
|
|
7
|
-
"homepage": "https://syncular.dev",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "https://github.com/syncular/syncular.git",
|
|
11
|
-
"directory": "packages/server"
|
|
12
|
-
},
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/syncular/syncular/issues"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"sync",
|
|
18
|
-
"offline-first",
|
|
19
|
-
"realtime",
|
|
20
|
-
"database",
|
|
21
|
-
"typescript"
|
|
22
|
-
],
|
|
3
|
+
"version": "0.0.1",
|
|
23
4
|
"private": false,
|
|
24
5
|
"publishConfig": {
|
|
25
6
|
"access": "public"
|
|
@@ -58,20 +39,18 @@
|
|
|
58
39
|
"scripts": {
|
|
59
40
|
"test": "bun test --pass-with-no-tests",
|
|
60
41
|
"tsgo": "tsgo --noEmit",
|
|
61
|
-
"build": "rm -rf dist && tsgo"
|
|
62
|
-
"release": "bun pm pack --destination . && npm publish ./*.tgz --tag latest && rm -f ./*.tgz"
|
|
42
|
+
"build": "rm -rf dist && tsgo"
|
|
63
43
|
},
|
|
64
44
|
"dependencies": {
|
|
65
|
-
"@syncular/core": "
|
|
45
|
+
"@syncular/core": "workspace:*",
|
|
46
|
+
"zod": "^4.3.6"
|
|
66
47
|
},
|
|
67
48
|
"peerDependencies": {
|
|
68
|
-
"kysely": "^0.28.0"
|
|
69
|
-
"zod": "^4.0.0"
|
|
49
|
+
"kysely": "^0.28.0"
|
|
70
50
|
},
|
|
71
51
|
"devDependencies": {
|
|
72
|
-
"@syncular/config": "
|
|
73
|
-
"kysely": "*"
|
|
74
|
-
"zod": "*"
|
|
52
|
+
"@syncular/config": "workspace:*",
|
|
53
|
+
"kysely": "*"
|
|
75
54
|
},
|
|
76
55
|
"files": [
|
|
77
56
|
"dist",
|
package/src/clients.ts
CHANGED
package/src/dialect/types.ts
CHANGED
|
@@ -41,16 +41,10 @@ export interface ServerSyncDialect {
|
|
|
41
41
|
setRepeatableRead<DB extends SyncCoreDb>(trx: DbExecutor<DB>): Promise<void>;
|
|
42
42
|
|
|
43
43
|
/** Read the maximum committed commit_seq (0 if none) */
|
|
44
|
-
readMaxCommitSeq<DB extends SyncCoreDb>(
|
|
45
|
-
db: DbExecutor<DB>,
|
|
46
|
-
options?: { partitionId?: string }
|
|
47
|
-
): Promise<number>;
|
|
44
|
+
readMaxCommitSeq<DB extends SyncCoreDb>(db: DbExecutor<DB>): Promise<number>;
|
|
48
45
|
|
|
49
46
|
/** Read the minimum committed commit_seq (0 if none) */
|
|
50
|
-
readMinCommitSeq<DB extends SyncCoreDb>(
|
|
51
|
-
db: DbExecutor<DB>,
|
|
52
|
-
options?: { partitionId?: string }
|
|
53
|
-
): Promise<number>;
|
|
47
|
+
readMinCommitSeq<DB extends SyncCoreDb>(db: DbExecutor<DB>): Promise<number>;
|
|
54
48
|
|
|
55
49
|
/**
|
|
56
50
|
* Read the next commit sequence numbers that have changes for the given tables.
|
|
@@ -58,19 +52,13 @@ export interface ServerSyncDialect {
|
|
|
58
52
|
*/
|
|
59
53
|
readCommitSeqsForPull<DB extends SyncCoreDb>(
|
|
60
54
|
db: DbExecutor<DB>,
|
|
61
|
-
args: {
|
|
62
|
-
cursor: number;
|
|
63
|
-
limitCommits: number;
|
|
64
|
-
tables: string[];
|
|
65
|
-
partitionId?: string;
|
|
66
|
-
}
|
|
55
|
+
args: { cursor: number; limitCommits: number; tables: string[] }
|
|
67
56
|
): Promise<number[]>;
|
|
68
57
|
|
|
69
58
|
/** Read commit metadata for commit_seq values */
|
|
70
59
|
readCommits<DB extends SyncCoreDb>(
|
|
71
60
|
db: DbExecutor<DB>,
|
|
72
|
-
commitSeqs: number[]
|
|
73
|
-
options?: { partitionId?: string }
|
|
61
|
+
commitSeqs: number[]
|
|
74
62
|
): Promise<SyncCommitRow[]>;
|
|
75
63
|
|
|
76
64
|
/**
|
|
@@ -79,12 +67,7 @@ export interface ServerSyncDialect {
|
|
|
79
67
|
*/
|
|
80
68
|
readChangesForCommits<DB extends SyncCoreDb>(
|
|
81
69
|
db: DbExecutor<DB>,
|
|
82
|
-
args: {
|
|
83
|
-
commitSeqs: number[];
|
|
84
|
-
table: string;
|
|
85
|
-
scopes: ScopeValues;
|
|
86
|
-
partitionId?: string;
|
|
87
|
-
}
|
|
70
|
+
args: { commitSeqs: number[]; table: string; scopes: ScopeValues }
|
|
88
71
|
): Promise<SyncChangeRow[]>;
|
|
89
72
|
|
|
90
73
|
/**
|
|
@@ -100,7 +83,6 @@ export interface ServerSyncDialect {
|
|
|
100
83
|
scopes: ScopeValues;
|
|
101
84
|
cursor: number;
|
|
102
85
|
limitCommits: number;
|
|
103
|
-
partitionId?: string;
|
|
104
86
|
}
|
|
105
87
|
): Promise<
|
|
106
88
|
Array<{
|
|
@@ -130,7 +112,6 @@ export interface ServerSyncDialect {
|
|
|
130
112
|
scopes: ScopeValues;
|
|
131
113
|
cursor: number;
|
|
132
114
|
limitCommits: number;
|
|
133
|
-
partitionId?: string;
|
|
134
115
|
}
|
|
135
116
|
): AsyncGenerator<{
|
|
136
117
|
commit_seq: number;
|
|
@@ -162,7 +143,6 @@ export interface ServerSyncDialect {
|
|
|
162
143
|
recordClientCursor<DB extends SyncCoreDb>(
|
|
163
144
|
db: DbExecutor<DB>,
|
|
164
145
|
args: {
|
|
165
|
-
partitionId?: string;
|
|
166
146
|
clientId: string;
|
|
167
147
|
actorId: string;
|
|
168
148
|
cursor: number;
|
|
@@ -202,8 +182,7 @@ export interface ServerSyncDialect {
|
|
|
202
182
|
*/
|
|
203
183
|
readAffectedTablesFromChanges<DB extends SyncCoreDb>(
|
|
204
184
|
db: DbExecutor<DB>,
|
|
205
|
-
commitSeq: number
|
|
206
|
-
options?: { partitionId?: string }
|
|
185
|
+
commitSeq: number
|
|
207
186
|
): Promise<string[]>;
|
|
208
187
|
|
|
209
188
|
/**
|
package/src/proxy/handler.ts
CHANGED
package/src/proxy/index.ts
CHANGED
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
// Query execution
|
|
8
8
|
export {
|
|
9
|
-
type ExecuteProxyQueryArgs,
|
|
10
9
|
type ExecuteProxyQueryResult,
|
|
11
10
|
executeProxyQuery,
|
|
12
11
|
} from './handler';
|
|
13
12
|
// Mutation detection
|
|
14
|
-
export {
|
|
13
|
+
export { detectMutation } from './mutation-detector';
|
|
15
14
|
// Oplog creation
|
|
16
15
|
// Registry
|
|
17
16
|
export { ProxyTableRegistry } from './registry';
|
package/src/proxy/oplog.ts
CHANGED
|
@@ -29,13 +29,11 @@ export async function createOplogEntries<DB extends SyncCoreDb>(args: {
|
|
|
29
29
|
dialect: ServerSyncDialect;
|
|
30
30
|
actorId: string;
|
|
31
31
|
clientId: string;
|
|
32
|
-
partitionId?: string;
|
|
33
32
|
shape: ProxyTableHandler;
|
|
34
33
|
operation: SyncOp;
|
|
35
34
|
rows: Record<string, unknown>[];
|
|
36
35
|
}): Promise<{ commitSeq: number; affectedTables: string[] }> {
|
|
37
36
|
const { trx, dialect, actorId, clientId, shape, operation, rows } = args;
|
|
38
|
-
const partitionId = args.partitionId ?? 'default';
|
|
39
37
|
|
|
40
38
|
if (rows.length === 0) {
|
|
41
39
|
return { commitSeq: 0, affectedTables: [] };
|
|
@@ -47,7 +45,6 @@ export async function createOplogEntries<DB extends SyncCoreDb>(args: {
|
|
|
47
45
|
// Create commit record
|
|
48
46
|
const commitResult = await sql<{ commit_seq: number }>`
|
|
49
47
|
insert into ${sql.table('sync_commits')} (
|
|
50
|
-
partition_id,
|
|
51
48
|
actor_id,
|
|
52
49
|
client_id,
|
|
53
50
|
client_commit_id,
|
|
@@ -55,7 +52,6 @@ export async function createOplogEntries<DB extends SyncCoreDb>(args: {
|
|
|
55
52
|
result_json
|
|
56
53
|
)
|
|
57
54
|
values (
|
|
58
|
-
${partitionId},
|
|
59
55
|
${actorId},
|
|
60
56
|
${clientId},
|
|
61
57
|
${`proxy:${generateId()}`},
|
|
@@ -80,7 +76,6 @@ export async function createOplogEntries<DB extends SyncCoreDb>(args: {
|
|
|
80
76
|
|
|
81
77
|
return {
|
|
82
78
|
commit_seq: commitSeq,
|
|
83
|
-
partition_id: partitionId,
|
|
84
79
|
table: shape.table,
|
|
85
80
|
row_id: String(row[pk]),
|
|
86
81
|
op: operation,
|
|
@@ -94,7 +89,6 @@ export async function createOplogEntries<DB extends SyncCoreDb>(args: {
|
|
|
94
89
|
await sql`
|
|
95
90
|
insert into ${sql.table('sync_changes')} (
|
|
96
91
|
commit_seq,
|
|
97
|
-
partition_id,
|
|
98
92
|
"table",
|
|
99
93
|
row_id,
|
|
100
94
|
op,
|
|
@@ -106,7 +100,6 @@ export async function createOplogEntries<DB extends SyncCoreDb>(args: {
|
|
|
106
100
|
changes.map(
|
|
107
101
|
(c) => sql`(
|
|
108
102
|
${c.commit_seq},
|
|
109
|
-
${c.partition_id},
|
|
110
103
|
${c.table},
|
|
111
104
|
${c.row_id},
|
|
112
105
|
${c.op},
|
|
@@ -131,12 +124,12 @@ export async function createOplogEntries<DB extends SyncCoreDb>(args: {
|
|
|
131
124
|
// Insert table commits for subscription filtering
|
|
132
125
|
if (affectedTables.length > 0) {
|
|
133
126
|
await sql`
|
|
134
|
-
insert into ${sql.table('sync_table_commits')} (
|
|
127
|
+
insert into ${sql.table('sync_table_commits')} ("table", commit_seq)
|
|
135
128
|
values ${sql.join(
|
|
136
|
-
sortedAffectedTables.map((table) => sql`(${
|
|
129
|
+
sortedAffectedTables.map((table) => sql`(${table}, ${commitSeq})`),
|
|
137
130
|
sql`, `
|
|
138
131
|
)}
|
|
139
|
-
on conflict (
|
|
132
|
+
on conflict ("table", commit_seq) do nothing
|
|
140
133
|
`.execute(trx);
|
|
141
134
|
}
|
|
142
135
|
|
package/src/proxy/registry.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Registry for proxy table handlers.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { TableRegistry } from '../shapes/registry';
|
|
7
8
|
import type { ProxyTableHandler } from './types';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -54,3 +55,35 @@ export class ProxyTableRegistry {
|
|
|
54
55
|
return Array.from(this.handlers.values());
|
|
55
56
|
}
|
|
56
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Create a ProxyTableRegistry from existing ServerTableHandlers.
|
|
61
|
+
*
|
|
62
|
+
* This helper extracts extractScopes from ServerTableHandlers that define it,
|
|
63
|
+
* avoiding duplication of scope extraction logic.
|
|
64
|
+
*
|
|
65
|
+
* @param tables - The existing table registry
|
|
66
|
+
* @param tableNameMap - Map from table name to database table name
|
|
67
|
+
*/
|
|
68
|
+
export function createProxyRegistryFromTables(
|
|
69
|
+
tables: TableRegistry,
|
|
70
|
+
tableNameMap: Record<string, string>
|
|
71
|
+
): ProxyTableRegistry {
|
|
72
|
+
const registry = new ProxyTableRegistry();
|
|
73
|
+
|
|
74
|
+
for (const [tableName, dbTableName] of Object.entries(tableNameMap)) {
|
|
75
|
+
const handler = tables.get(tableName);
|
|
76
|
+
if (
|
|
77
|
+
handler &&
|
|
78
|
+
'extractScopes' in handler &&
|
|
79
|
+
typeof handler.extractScopes === 'function'
|
|
80
|
+
) {
|
|
81
|
+
registry.register({
|
|
82
|
+
table: dbTableName,
|
|
83
|
+
computeScopes: handler.extractScopes,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return registry;
|
|
89
|
+
}
|
package/src/proxy/types.ts
CHANGED
package/src/pull.ts
CHANGED
|
@@ -101,7 +101,6 @@ export async function pull<DB extends SyncCoreDb>(args: {
|
|
|
101
101
|
dialect: ServerSyncDialect;
|
|
102
102
|
shapes: TableRegistry<DB>;
|
|
103
103
|
actorId: string;
|
|
104
|
-
partitionId?: string;
|
|
105
104
|
request: SyncPullRequest;
|
|
106
105
|
/**
|
|
107
106
|
* Optional snapshot chunk storage adapter.
|
|
@@ -112,7 +111,6 @@ export async function pull<DB extends SyncCoreDb>(args: {
|
|
|
112
111
|
}): Promise<PullResult> {
|
|
113
112
|
const { request, dialect } = args;
|
|
114
113
|
const db = args.db;
|
|
115
|
-
const partitionId = args.partitionId ?? 'default';
|
|
116
114
|
|
|
117
115
|
// Validate and sanitize request limits
|
|
118
116
|
const limitCommits = sanitizeLimit(request.limitCommits, 50, 1, 500);
|
|
@@ -136,8 +134,8 @@ export async function pull<DB extends SyncCoreDb>(args: {
|
|
|
136
134
|
return dialect.executeInTransaction(db, async (trx) => {
|
|
137
135
|
await dialect.setRepeatableRead(trx);
|
|
138
136
|
|
|
139
|
-
const maxCommitSeq = await dialect.readMaxCommitSeq(trx
|
|
140
|
-
const minCommitSeq = await dialect.readMinCommitSeq(trx
|
|
137
|
+
const maxCommitSeq = await dialect.readMaxCommitSeq(trx);
|
|
138
|
+
const minCommitSeq = await dialect.readMinCommitSeq(trx);
|
|
141
139
|
|
|
142
140
|
const subResponses: SyncPullSubscriptionResponse[] = [];
|
|
143
141
|
const activeSubscriptions: { scopes: ScopeValues }[] = [];
|
|
@@ -245,9 +243,8 @@ export async function pull<DB extends SyncCoreDb>(args: {
|
|
|
245
243
|
const nowIso = new Date().toISOString();
|
|
246
244
|
|
|
247
245
|
// Use scope hash for caching
|
|
248
|
-
const cacheKey =
|
|
246
|
+
const cacheKey = scopesToCacheKey(effectiveScopes);
|
|
249
247
|
const cached = await readSnapshotChunkRefByPageKey(trx, {
|
|
250
|
-
partitionId,
|
|
251
248
|
scopeKey: cacheKey,
|
|
252
249
|
scope: nextTableName,
|
|
253
250
|
asOfCommitSeq: effectiveState.asOfCommitSeq,
|
|
@@ -276,7 +273,6 @@ export async function pull<DB extends SyncCoreDb>(args: {
|
|
|
276
273
|
// Use external chunk storage if available, otherwise fall back to inline
|
|
277
274
|
if (args.chunkStorage) {
|
|
278
275
|
chunkRef = await args.chunkStorage.storeChunk({
|
|
279
|
-
partitionId,
|
|
280
276
|
scopeKey: cacheKey,
|
|
281
277
|
scope: nextTableName,
|
|
282
278
|
asOfCommitSeq: effectiveState.asOfCommitSeq,
|
|
@@ -292,7 +288,6 @@ export async function pull<DB extends SyncCoreDb>(args: {
|
|
|
292
288
|
const chunkId = randomUUID();
|
|
293
289
|
chunkRef = await insertSnapshotChunk(trx, {
|
|
294
290
|
chunkId,
|
|
295
|
-
partitionId,
|
|
296
291
|
scopeKey: cacheKey,
|
|
297
292
|
scope: nextTableName,
|
|
298
293
|
asOfCommitSeq: effectiveState.asOfCommitSeq,
|
|
@@ -348,23 +343,9 @@ export async function pull<DB extends SyncCoreDb>(args: {
|
|
|
348
343
|
}
|
|
349
344
|
|
|
350
345
|
// Incremental pull for this subscription
|
|
351
|
-
// Read the commit window for this table up-front so the subscription cursor
|
|
352
|
-
// can advance past commits that don't match the requested scopes.
|
|
353
|
-
const scannedCommitSeqs = await dialect.readCommitSeqsForPull(trx, {
|
|
354
|
-
partitionId,
|
|
355
|
-
cursor,
|
|
356
|
-
limitCommits,
|
|
357
|
-
tables: [sub.shape],
|
|
358
|
-
});
|
|
359
|
-
const maxScannedCommitSeq =
|
|
360
|
-
scannedCommitSeqs.length > 0
|
|
361
|
-
? scannedCommitSeqs[scannedCommitSeqs.length - 1]!
|
|
362
|
-
: cursor;
|
|
363
|
-
|
|
364
346
|
// Use streaming when available to reduce memory pressure for large pulls
|
|
365
347
|
const pullRowStream = dialect.streamIncrementalPullRows
|
|
366
348
|
? dialect.streamIncrementalPullRows(trx, {
|
|
367
|
-
partitionId,
|
|
368
349
|
table: sub.shape,
|
|
369
350
|
scopes: effectiveScopes,
|
|
370
351
|
cursor,
|
|
@@ -397,7 +378,6 @@ export async function pull<DB extends SyncCoreDb>(args: {
|
|
|
397
378
|
} else {
|
|
398
379
|
// Non-streaming fallback: load all rows at once
|
|
399
380
|
const rows = await dialect.readIncrementalPullRows(trx, {
|
|
400
|
-
partitionId,
|
|
401
381
|
table: sub.shape,
|
|
402
382
|
scopes: effectiveScopes,
|
|
403
383
|
cursor,
|
|
@@ -409,18 +389,16 @@ export async function pull<DB extends SyncCoreDb>(args: {
|
|
|
409
389
|
}
|
|
410
390
|
}
|
|
411
391
|
|
|
412
|
-
nextCursor = Math.max(nextCursor, maxScannedCommitSeq);
|
|
413
|
-
|
|
414
392
|
if (incrementalRows.length === 0) {
|
|
415
393
|
subResponses.push({
|
|
416
394
|
id: sub.id,
|
|
417
395
|
status: 'active',
|
|
418
396
|
scopes: effectiveScopes,
|
|
419
397
|
bootstrap: false,
|
|
420
|
-
nextCursor,
|
|
398
|
+
nextCursor: cursor,
|
|
421
399
|
commits: [],
|
|
422
400
|
});
|
|
423
|
-
nextCursors.push(
|
|
401
|
+
nextCursors.push(cursor);
|
|
424
402
|
continue;
|
|
425
403
|
}
|
|
426
404
|
|