@syncular/client-react 0.0.1-96 → 0.0.1-98
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/client-react",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-98",
|
|
4
4
|
"description": "React hooks and bindings for the Syncular client",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Benjamin Kniffler",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
32
|
"bun": "./src/index.ts",
|
|
33
|
+
"browser": "./src/index.ts",
|
|
33
34
|
"import": {
|
|
34
35
|
"types": "./dist/index.d.ts",
|
|
35
36
|
"default": "./dist/index.js"
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
ensureSyncSchema,
|
|
26
26
|
pull,
|
|
27
27
|
pushCommit,
|
|
28
|
+
readSnapshotChunk,
|
|
28
29
|
recordClientCursor,
|
|
29
30
|
type ServerSyncDialect,
|
|
30
31
|
type ServerTableHandler,
|
|
@@ -364,6 +365,33 @@ function createInProcessTransport(
|
|
|
364
365
|
): SyncTransport {
|
|
365
366
|
const syncDb = server.db;
|
|
366
367
|
|
|
368
|
+
async function streamToBytes(
|
|
369
|
+
stream: ReadableStream<Uint8Array>
|
|
370
|
+
): Promise<Uint8Array> {
|
|
371
|
+
const reader = stream.getReader();
|
|
372
|
+
try {
|
|
373
|
+
const chunks: Uint8Array[] = [];
|
|
374
|
+
let total = 0;
|
|
375
|
+
while (true) {
|
|
376
|
+
const { done, value } = await reader.read();
|
|
377
|
+
if (done) break;
|
|
378
|
+
if (!value) continue;
|
|
379
|
+
chunks.push(value);
|
|
380
|
+
total += value.length;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const merged = new Uint8Array(total);
|
|
384
|
+
let offset = 0;
|
|
385
|
+
for (const chunk of chunks) {
|
|
386
|
+
merged.set(chunk, offset);
|
|
387
|
+
offset += chunk.length;
|
|
388
|
+
}
|
|
389
|
+
return merged;
|
|
390
|
+
} finally {
|
|
391
|
+
reader.releaseLock();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
367
395
|
return {
|
|
368
396
|
async sync(request) {
|
|
369
397
|
const result: { ok: true; push?: any; pull?: any } = { ok: true };
|
|
@@ -409,8 +437,17 @@ function createInProcessTransport(
|
|
|
409
437
|
return result;
|
|
410
438
|
},
|
|
411
439
|
|
|
412
|
-
async fetchSnapshotChunk() {
|
|
413
|
-
|
|
440
|
+
async fetchSnapshotChunk(request) {
|
|
441
|
+
const chunk = await readSnapshotChunk(syncDb, request.chunkId);
|
|
442
|
+
if (!chunk) {
|
|
443
|
+
throw new Error(`Snapshot chunk not found: ${request.chunkId}`);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (chunk.body instanceof Uint8Array) {
|
|
447
|
+
return new Uint8Array(chunk.body);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return streamToBytes(chunk.body);
|
|
414
451
|
},
|
|
415
452
|
};
|
|
416
453
|
}
|