@syncular/client 0.0.6-102 → 0.0.6-103

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",
3
- "version": "0.0.6-102",
3
+ "version": "0.0.6-103",
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",
@@ -46,8 +46,8 @@
46
46
  "release": "bunx syncular-publish"
47
47
  },
48
48
  "dependencies": {
49
- "@syncular/core": "0.0.6-102",
50
- "@syncular/transport-http": "0.0.6-102"
49
+ "@syncular/core": "0.0.6-103",
50
+ "@syncular/transport-http": "0.0.6-103"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "kysely": "*"
@@ -379,4 +379,98 @@ describe('applyPullResponse chunk streaming', () => {
379
379
  .executeTakeFirst();
380
380
  expect(Number(stateAfterFailure?.total ?? 0)).toBe(0);
381
381
  });
382
+
383
+ it('uses custom sha256 override for streamed chunk integrity checks', async () => {
384
+ const rows = Array.from({ length: 256 }, (_, index) => ({
385
+ id: `${index + 1}`,
386
+ name: `Item ${index + 1}`,
387
+ }));
388
+ const chunk = new Uint8Array(gzipSync(encodeSnapshotRows(rows)));
389
+
390
+ const transport: SyncTransport = {
391
+ async sync() {
392
+ return {};
393
+ },
394
+ async fetchSnapshotChunk() {
395
+ throw new Error('fetchSnapshotChunk should not be used');
396
+ },
397
+ async fetchSnapshotChunkStream() {
398
+ return createStreamFromBytes(chunk, 137);
399
+ },
400
+ };
401
+
402
+ const handlers: ClientHandlerCollection<TestDb> = [
403
+ createClientHandler({
404
+ table: 'items',
405
+ scopes: ['items:{id}'],
406
+ }),
407
+ ];
408
+
409
+ let sha256CallCount = 0;
410
+ const options = {
411
+ clientId: 'client-1',
412
+ subscriptions: [
413
+ {
414
+ id: 'items-sub',
415
+ table: 'items',
416
+ scopes: {},
417
+ },
418
+ ],
419
+ stateId: 'default',
420
+ sha256: async () => {
421
+ sha256CallCount += 1;
422
+ return 'expected-hash';
423
+ },
424
+ };
425
+
426
+ const response: SyncPullResponse = {
427
+ ok: true,
428
+ subscriptions: [
429
+ {
430
+ id: 'items-sub',
431
+ status: 'active',
432
+ scopes: {},
433
+ bootstrap: true,
434
+ bootstrapState: null,
435
+ nextCursor: 8,
436
+ commits: [],
437
+ snapshots: [
438
+ {
439
+ table: 'items',
440
+ rows: [],
441
+ chunks: [
442
+ {
443
+ id: 'chunk-1',
444
+ byteLength: chunk.length,
445
+ sha256: 'expected-hash',
446
+ encoding: 'json-row-frame-v1',
447
+ compression: 'gzip',
448
+ },
449
+ ],
450
+ isFirstPage: true,
451
+ isLastPage: true,
452
+ },
453
+ ],
454
+ },
455
+ ],
456
+ };
457
+
458
+ const pullState = await buildPullRequest(db, options);
459
+ await applyPullResponse(
460
+ db,
461
+ transport,
462
+ handlers,
463
+ options,
464
+ pullState,
465
+ response
466
+ );
467
+
468
+ expect(sha256CallCount).toBe(1);
469
+
470
+ const countResult = await sql<{ count: number }>`
471
+ select count(*) as count
472
+ from ${sql.table('items')}
473
+ `.execute(db);
474
+ expect(Number(countResult.rows[0]?.count ?? 0)).toBe(rows.length);
475
+ });
382
476
  });