@syncular/client 0.0.6-239 → 0.0.6-240
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/query-public.d.ts +2 -1
- package/dist/query-public.d.ts.map +1 -1
- package/dist/query-public.js +32 -12
- package/dist/query-public.js.map +1 -1
- package/package.json +3 -3
- package/src/query-public.ts +83 -12
package/dist/query-public.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This wrapper keeps query-builder tracking isolated per chain so branching a
|
|
5
5
|
* base Kysely builder does not leak joined tables into sibling branches.
|
|
6
6
|
*/
|
|
7
|
+
import { type ColumnCodecDialect, type ColumnCodecSource } from '@syncular/core';
|
|
7
8
|
import type { Kysely } from 'kysely';
|
|
8
9
|
import type { FingerprintCollector } from './query/FingerprintCollector';
|
|
9
10
|
import { type MutationTimestampSource } from './query/fingerprint';
|
|
@@ -15,5 +16,5 @@ type TrackedSelectFrom<DB> = Kysely<DB>['selectFrom'];
|
|
|
15
16
|
export interface QueryContext<DB extends SyncClientDb = SyncClientDb> {
|
|
16
17
|
selectFrom: TrackedSelectFrom<DB>;
|
|
17
18
|
}
|
|
18
|
-
export declare function createQueryContext<DB extends SyncClientDb>(db: Kysely<DB>, scopeCollector: Set<string>, fingerprintCollector: FingerprintCollector, engine: MutationTimestampSource, keyField?: string, fingerprintMode?: FingerprintMode): QueryContext<DB>;
|
|
19
|
+
export declare function createQueryContext<DB extends SyncClientDb>(db: Kysely<DB>, scopeCollector: Set<string>, fingerprintCollector: FingerprintCollector, engine: MutationTimestampSource, keyField?: string, fingerprintMode?: FingerprintMode, codecSource?: ColumnCodecSource, codecDialect?: ColumnCodecDialect): QueryContext<DB>;
|
|
19
20
|
//# sourceMappingURL=query-public.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-public.d.ts","sourceRoot":"","sources":["../src/query-public.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAA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,CAAC,EAAE,CAAC,CAAC;CACnC;AAED,wBAAgB,kBAAkB,CAAC,EAAE,SAAS,YAAY,EACxD,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,EACd,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,EAC3B,oBAAoB,EAAE,oBAAoB,EAC1C,MAAM,EAAE,uBAAuB,EAC/B,QAAQ,SAAO,EACf,eAAe,GAAE,eAAwB,EACzC,WAAW,CAAC,EAAE,iBAAiB,EAC/B,YAAY,GAAE,kBAA6B,GAC1C,YAAY,CAAC,EAAE,CAAC,CAalB"}
|
package/dist/query-public.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This wrapper keeps query-builder tracking isolated per chain so branching a
|
|
5
5
|
* base Kysely builder does not leak joined tables into sibling branches.
|
|
6
6
|
*/
|
|
7
|
+
import { applyCodecsFromDbRow, createTableColumnCodecsResolver, } from '@syncular/core';
|
|
7
8
|
import { computeRowFingerprint, computeValueFingerprint, hasKeyField, } from './query/fingerprint.js';
|
|
8
9
|
export { FingerprintCollector } from './query/FingerprintCollector.js';
|
|
9
10
|
export { canFingerprint, computeFingerprint, } from './query/fingerprint.js';
|
|
@@ -62,15 +63,29 @@ function addTrackedTablesToScopeCollector(scopeCollector, trackedTables) {
|
|
|
62
63
|
scopeCollector.add(trackedTable);
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
|
-
function
|
|
66
|
+
function decodeRow(row, table, resolveCodecs, codecDialect) {
|
|
67
|
+
if (!isRecord(row))
|
|
68
|
+
return row;
|
|
69
|
+
return applyCodecsFromDbRow(row, resolveCodecs(table, row), codecDialect);
|
|
70
|
+
}
|
|
71
|
+
function decodeRows(rows, primaryTable, resolveCodecs, codecDialect) {
|
|
72
|
+
if (!resolveCodecs || !primaryTable)
|
|
73
|
+
return rows;
|
|
74
|
+
if (Array.isArray(rows)) {
|
|
75
|
+
return rows.map((row) => decodeRow(row, primaryTable, resolveCodecs, codecDialect));
|
|
76
|
+
}
|
|
77
|
+
return decodeRow(rows, primaryTable, resolveCodecs, codecDialect);
|
|
78
|
+
}
|
|
79
|
+
function createExecuteProxy(builder, primaryTable, trackedTables, scopeCollector, collector, engine, keyField, fingerprintMode, resolveCodecs, codecDialect) {
|
|
66
80
|
return new Proxy(builder, {
|
|
67
81
|
get(target, prop, receiver) {
|
|
68
82
|
if (prop === 'execute') {
|
|
69
83
|
return async () => {
|
|
70
84
|
const rows = await target.execute();
|
|
85
|
+
const decoded = decodeRows(rows, primaryTable, resolveCodecs, codecDialect);
|
|
71
86
|
addTrackedTablesToScopeCollector(scopeCollector, trackedTables);
|
|
72
87
|
addFingerprint({
|
|
73
|
-
rows,
|
|
88
|
+
rows: decoded,
|
|
74
89
|
primaryTable,
|
|
75
90
|
trackedTables,
|
|
76
91
|
collector,
|
|
@@ -78,15 +93,16 @@ function createExecuteProxy(builder, primaryTable, trackedTables, scopeCollector
|
|
|
78
93
|
keyField,
|
|
79
94
|
fingerprintMode,
|
|
80
95
|
});
|
|
81
|
-
return
|
|
96
|
+
return decoded;
|
|
82
97
|
};
|
|
83
98
|
}
|
|
84
99
|
if (prop === 'executeTakeFirst') {
|
|
85
100
|
return async () => {
|
|
86
101
|
const row = await target.executeTakeFirst();
|
|
102
|
+
const decoded = decodeRows(row, primaryTable, resolveCodecs, codecDialect);
|
|
87
103
|
addTrackedTablesToScopeCollector(scopeCollector, trackedTables);
|
|
88
104
|
addFingerprint({
|
|
89
|
-
rows:
|
|
105
|
+
rows: decoded,
|
|
90
106
|
primaryTable,
|
|
91
107
|
trackedTables,
|
|
92
108
|
collector,
|
|
@@ -94,15 +110,16 @@ function createExecuteProxy(builder, primaryTable, trackedTables, scopeCollector
|
|
|
94
110
|
keyField,
|
|
95
111
|
fingerprintMode,
|
|
96
112
|
});
|
|
97
|
-
return
|
|
113
|
+
return decoded;
|
|
98
114
|
};
|
|
99
115
|
}
|
|
100
116
|
if (prop === 'executeTakeFirstOrThrow') {
|
|
101
117
|
return async () => {
|
|
102
118
|
const row = await target.executeTakeFirstOrThrow();
|
|
119
|
+
const decoded = decodeRows(row, primaryTable, resolveCodecs, codecDialect);
|
|
103
120
|
addTrackedTablesToScopeCollector(scopeCollector, trackedTables);
|
|
104
121
|
addFingerprint({
|
|
105
|
-
rows:
|
|
122
|
+
rows: decoded,
|
|
106
123
|
primaryTable,
|
|
107
124
|
trackedTables,
|
|
108
125
|
collector,
|
|
@@ -110,7 +127,7 @@ function createExecuteProxy(builder, primaryTable, trackedTables, scopeCollector
|
|
|
110
127
|
keyField,
|
|
111
128
|
fingerprintMode,
|
|
112
129
|
});
|
|
113
|
-
return
|
|
130
|
+
return decoded;
|
|
114
131
|
};
|
|
115
132
|
}
|
|
116
133
|
const value = Reflect.get(target, prop, receiver);
|
|
@@ -130,23 +147,26 @@ function createExecuteProxy(builder, primaryTable, trackedTables, scopeCollector
|
|
|
130
147
|
if (!isExecutableQuery(result)) {
|
|
131
148
|
return result;
|
|
132
149
|
}
|
|
133
|
-
return createExecuteProxy(result, primaryTable, nextTrackedTables, scopeCollector, collector, engine, keyField, fingerprintMode);
|
|
150
|
+
return createExecuteProxy(result, primaryTable, nextTrackedTables, scopeCollector, collector, engine, keyField, fingerprintMode, resolveCodecs, codecDialect);
|
|
134
151
|
};
|
|
135
152
|
},
|
|
136
153
|
});
|
|
137
154
|
}
|
|
138
|
-
function createTrackedSelectFrom(db, scopeCollector, fingerprintCollector, engine, keyField = 'id', fingerprintMode = 'auto') {
|
|
155
|
+
function createTrackedSelectFrom(db, scopeCollector, fingerprintCollector, engine, keyField = 'id', fingerprintMode = 'auto', codecSource, codecDialect = 'sqlite') {
|
|
156
|
+
const resolveCodecs = codecSource
|
|
157
|
+
? createTableColumnCodecsResolver(codecSource, { dialect: codecDialect })
|
|
158
|
+
: undefined;
|
|
139
159
|
const selectFrom = (...args) => {
|
|
140
160
|
const trackedTables = new Set(extractTrackedTableNames(args[0]));
|
|
141
161
|
const primaryTable = Array.from(trackedTables)[0] ?? null;
|
|
142
162
|
const builder = db.selectFrom(...args);
|
|
143
|
-
return createExecuteProxy(builder, primaryTable, trackedTables, scopeCollector, fingerprintCollector, engine, keyField, fingerprintMode);
|
|
163
|
+
return createExecuteProxy(builder, primaryTable, trackedTables, scopeCollector, fingerprintCollector, engine, keyField, fingerprintMode, resolveCodecs, codecDialect);
|
|
144
164
|
};
|
|
145
165
|
return selectFrom;
|
|
146
166
|
}
|
|
147
|
-
export function createQueryContext(db, scopeCollector, fingerprintCollector, engine, keyField = 'id', fingerprintMode = 'auto') {
|
|
167
|
+
export function createQueryContext(db, scopeCollector, fingerprintCollector, engine, keyField = 'id', fingerprintMode = 'auto', codecSource, codecDialect = 'sqlite') {
|
|
148
168
|
return {
|
|
149
|
-
selectFrom: createTrackedSelectFrom(db, scopeCollector, fingerprintCollector, engine, keyField, fingerprintMode),
|
|
169
|
+
selectFrom: createTrackedSelectFrom(db, scopeCollector, fingerprintCollector, engine, keyField, fingerprintMode, codecSource, codecDialect),
|
|
150
170
|
};
|
|
151
171
|
}
|
|
152
172
|
//# sourceMappingURL=query-public.js.map
|
package/dist/query-public.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-public.js","sourceRoot":"","sources":["../src/query-public.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"query-public.js","sourceRoot":"","sources":["../src/query-public.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,oBAAoB,EAGpB,+BAA+B,GAEhC,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,WAAW,GAEZ,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EACL,cAAc,EACd,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAc7B,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,WAAW;IACX,UAAU;IACV,W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S,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACzE,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QAC1D,MAAM,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;QAEvC,OAAO,kBAAkB,CACvB,OAAO,EACP,YAAY,EACZ,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,MAAM,EACN,QAAQ,EACR,eAAe,EACf,aAAa,EACb,YAAY,CACW,CAAC;IAAA,CAC3B,CAAC;IAEF,OAAO,UAAmC,CAAC;AAAA,CAC5C;AAMD,MAAM,UAAU,kBAAkB,CAChC,EAAc,EACd,cAA2B,EAC3B,oBAA0C,EAC1C,MAA+B,EAC/B,QAAQ,GAAG,IAAI,EACf,eAAe,GAAoB,MAAM,EACzC,WAA+B,EAC/B,YAAY,GAAuB,QAAQ,EACzB;IAClB,OAAO;QACL,UAAU,EAAE,uBAAuB,CACjC,EAAE,EACF,cAAc,EACd,oBAAoB,EACpB,MAAM,EACN,QAAQ,EACR,eAAe,EACf,WAAW,EACX,YAAY,CACb;KACF,CAAC;AAAA,CACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/client",
|
|
3
|
-
"version": "0.0.6-
|
|
3
|
+
"version": "0.0.6-240",
|
|
4
4
|
"description": "Client-side sync engine with offline-first support, outbox, and conflict resolution",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Benjamin Kniffler",
|
|
@@ -119,8 +119,8 @@
|
|
|
119
119
|
"release": "bunx syncular-publish"
|
|
120
120
|
},
|
|
121
121
|
"dependencies": {
|
|
122
|
-
"@syncular/core": "0.0.6-
|
|
123
|
-
"@syncular/transport-http": "0.0.6-
|
|
122
|
+
"@syncular/core": "0.0.6-240",
|
|
123
|
+
"@syncular/transport-http": "0.0.6-240"
|
|
124
124
|
},
|
|
125
125
|
"peerDependencies": {
|
|
126
126
|
"kysely": "*"
|
package/src/query-public.ts
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
* base Kysely builder does not leak joined tables into sibling branches.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {
|
|
9
|
+
applyCodecsFromDbRow,
|
|
10
|
+
type ColumnCodecDialect,
|
|
11
|
+
type ColumnCodecSource,
|
|
12
|
+
createTableColumnCodecsResolver,
|
|
13
|
+
type TableColumnCodecs,
|
|
14
|
+
} from '@syncular/core';
|
|
8
15
|
import type { Kysely } from 'kysely';
|
|
9
16
|
import type { FingerprintCollector } from './query/FingerprintCollector';
|
|
10
17
|
import {
|
|
@@ -123,6 +130,36 @@ function addTrackedTablesToScopeCollector(
|
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
132
|
|
|
133
|
+
type CodecsResolver = (
|
|
134
|
+
table: string,
|
|
135
|
+
row: Record<string, unknown>
|
|
136
|
+
) => TableColumnCodecs;
|
|
137
|
+
|
|
138
|
+
function decodeRow(
|
|
139
|
+
row: unknown,
|
|
140
|
+
table: string,
|
|
141
|
+
resolveCodecs: CodecsResolver,
|
|
142
|
+
codecDialect: ColumnCodecDialect
|
|
143
|
+
): unknown {
|
|
144
|
+
if (!isRecord(row)) return row;
|
|
145
|
+
return applyCodecsFromDbRow(row, resolveCodecs(table, row), codecDialect);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function decodeRows(
|
|
149
|
+
rows: unknown,
|
|
150
|
+
primaryTable: string | null,
|
|
151
|
+
resolveCodecs: CodecsResolver | undefined,
|
|
152
|
+
codecDialect: ColumnCodecDialect
|
|
153
|
+
): unknown {
|
|
154
|
+
if (!resolveCodecs || !primaryTable) return rows;
|
|
155
|
+
if (Array.isArray(rows)) {
|
|
156
|
+
return rows.map((row) =>
|
|
157
|
+
decodeRow(row, primaryTable, resolveCodecs, codecDialect)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
return decodeRow(rows, primaryTable, resolveCodecs, codecDialect);
|
|
161
|
+
}
|
|
162
|
+
|
|
126
163
|
function createExecuteProxy<B extends ExecutableQuery>(
|
|
127
164
|
builder: B,
|
|
128
165
|
primaryTable: string | null,
|
|
@@ -131,16 +168,24 @@ function createExecuteProxy<B extends ExecutableQuery>(
|
|
|
131
168
|
collector: FingerprintCollector,
|
|
132
169
|
engine: MutationTimestampSource,
|
|
133
170
|
keyField: string,
|
|
134
|
-
fingerprintMode: FingerprintMode
|
|
171
|
+
fingerprintMode: FingerprintMode,
|
|
172
|
+
resolveCodecs: CodecsResolver | undefined,
|
|
173
|
+
codecDialect: ColumnCodecDialect
|
|
135
174
|
): B {
|
|
136
175
|
return new Proxy(builder, {
|
|
137
176
|
get(target, prop, receiver) {
|
|
138
177
|
if (prop === 'execute') {
|
|
139
178
|
return async () => {
|
|
140
179
|
const rows = await target.execute();
|
|
180
|
+
const decoded = decodeRows(
|
|
181
|
+
rows,
|
|
182
|
+
primaryTable,
|
|
183
|
+
resolveCodecs,
|
|
184
|
+
codecDialect
|
|
185
|
+
);
|
|
141
186
|
addTrackedTablesToScopeCollector(scopeCollector, trackedTables);
|
|
142
187
|
addFingerprint({
|
|
143
|
-
rows,
|
|
188
|
+
rows: decoded,
|
|
144
189
|
primaryTable,
|
|
145
190
|
trackedTables,
|
|
146
191
|
collector,
|
|
@@ -148,16 +193,22 @@ function createExecuteProxy<B extends ExecutableQuery>(
|
|
|
148
193
|
keyField,
|
|
149
194
|
fingerprintMode,
|
|
150
195
|
});
|
|
151
|
-
return
|
|
196
|
+
return decoded;
|
|
152
197
|
};
|
|
153
198
|
}
|
|
154
199
|
|
|
155
200
|
if (prop === 'executeTakeFirst') {
|
|
156
201
|
return async () => {
|
|
157
202
|
const row = await target.executeTakeFirst();
|
|
203
|
+
const decoded = decodeRows(
|
|
204
|
+
row,
|
|
205
|
+
primaryTable,
|
|
206
|
+
resolveCodecs,
|
|
207
|
+
codecDialect
|
|
208
|
+
);
|
|
158
209
|
addTrackedTablesToScopeCollector(scopeCollector, trackedTables);
|
|
159
210
|
addFingerprint({
|
|
160
|
-
rows:
|
|
211
|
+
rows: decoded,
|
|
161
212
|
primaryTable,
|
|
162
213
|
trackedTables,
|
|
163
214
|
collector,
|
|
@@ -165,16 +216,22 @@ function createExecuteProxy<B extends ExecutableQuery>(
|
|
|
165
216
|
keyField,
|
|
166
217
|
fingerprintMode,
|
|
167
218
|
});
|
|
168
|
-
return
|
|
219
|
+
return decoded;
|
|
169
220
|
};
|
|
170
221
|
}
|
|
171
222
|
|
|
172
223
|
if (prop === 'executeTakeFirstOrThrow') {
|
|
173
224
|
return async () => {
|
|
174
225
|
const row = await target.executeTakeFirstOrThrow();
|
|
226
|
+
const decoded = decodeRows(
|
|
227
|
+
row,
|
|
228
|
+
primaryTable,
|
|
229
|
+
resolveCodecs,
|
|
230
|
+
codecDialect
|
|
231
|
+
);
|
|
175
232
|
addTrackedTablesToScopeCollector(scopeCollector, trackedTables);
|
|
176
233
|
addFingerprint({
|
|
177
|
-
rows:
|
|
234
|
+
rows: decoded,
|
|
178
235
|
primaryTable,
|
|
179
236
|
trackedTables,
|
|
180
237
|
collector,
|
|
@@ -182,7 +239,7 @@ function createExecuteProxy<B extends ExecutableQuery>(
|
|
|
182
239
|
keyField,
|
|
183
240
|
fingerprintMode,
|
|
184
241
|
});
|
|
185
|
-
return
|
|
242
|
+
return decoded;
|
|
186
243
|
};
|
|
187
244
|
}
|
|
188
245
|
|
|
@@ -217,7 +274,9 @@ function createExecuteProxy<B extends ExecutableQuery>(
|
|
|
217
274
|
collector,
|
|
218
275
|
engine,
|
|
219
276
|
keyField,
|
|
220
|
-
fingerprintMode
|
|
277
|
+
fingerprintMode,
|
|
278
|
+
resolveCodecs,
|
|
279
|
+
codecDialect
|
|
221
280
|
);
|
|
222
281
|
};
|
|
223
282
|
},
|
|
@@ -230,8 +289,14 @@ function createTrackedSelectFrom<DB extends SyncClientDb>(
|
|
|
230
289
|
fingerprintCollector: FingerprintCollector,
|
|
231
290
|
engine: MutationTimestampSource,
|
|
232
291
|
keyField = 'id',
|
|
233
|
-
fingerprintMode: FingerprintMode = 'auto'
|
|
292
|
+
fingerprintMode: FingerprintMode = 'auto',
|
|
293
|
+
codecSource?: ColumnCodecSource,
|
|
294
|
+
codecDialect: ColumnCodecDialect = 'sqlite'
|
|
234
295
|
): TrackedSelectFrom<DB> {
|
|
296
|
+
const resolveCodecs = codecSource
|
|
297
|
+
? createTableColumnCodecsResolver(codecSource, { dialect: codecDialect })
|
|
298
|
+
: undefined;
|
|
299
|
+
|
|
235
300
|
const selectFrom = (...args: SelectFromArgs<DB>) => {
|
|
236
301
|
const trackedTables = new Set<string>(extractTrackedTableNames(args[0]));
|
|
237
302
|
const primaryTable = Array.from(trackedTables)[0] ?? null;
|
|
@@ -245,7 +310,9 @@ function createTrackedSelectFrom<DB extends SyncClientDb>(
|
|
|
245
310
|
fingerprintCollector,
|
|
246
311
|
engine,
|
|
247
312
|
keyField,
|
|
248
|
-
fingerprintMode
|
|
313
|
+
fingerprintMode,
|
|
314
|
+
resolveCodecs,
|
|
315
|
+
codecDialect
|
|
249
316
|
) as SelectFromResult<DB>;
|
|
250
317
|
};
|
|
251
318
|
|
|
@@ -262,7 +329,9 @@ export function createQueryContext<DB extends SyncClientDb>(
|
|
|
262
329
|
fingerprintCollector: FingerprintCollector,
|
|
263
330
|
engine: MutationTimestampSource,
|
|
264
331
|
keyField = 'id',
|
|
265
|
-
fingerprintMode: FingerprintMode = 'auto'
|
|
332
|
+
fingerprintMode: FingerprintMode = 'auto',
|
|
333
|
+
codecSource?: ColumnCodecSource,
|
|
334
|
+
codecDialect: ColumnCodecDialect = 'sqlite'
|
|
266
335
|
): QueryContext<DB> {
|
|
267
336
|
return {
|
|
268
337
|
selectFrom: createTrackedSelectFrom(
|
|
@@ -271,7 +340,9 @@ export function createQueryContext<DB extends SyncClientDb>(
|
|
|
271
340
|
fingerprintCollector,
|
|
272
341
|
engine,
|
|
273
342
|
keyField,
|
|
274
|
-
fingerprintMode
|
|
343
|
+
fingerprintMode,
|
|
344
|
+
codecSource,
|
|
345
|
+
codecDialect
|
|
275
346
|
),
|
|
276
347
|
};
|
|
277
348
|
}
|