@powersync/service-module-mongodb-storage 0.0.0-dev-20250317113118 → 0.0.0-dev-20250325131118

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.
@@ -74,6 +74,7 @@ export class PowerSyncMongo {
74
74
  await this.instance.deleteOne({});
75
75
  await this.locks.deleteMany({});
76
76
  await this.bucket_state.deleteMany({});
77
+ await this.custom_write_checkpoints.deleteMany({});
77
78
  }
78
79
 
79
80
  /**
@@ -75,13 +75,22 @@ export interface SourceTableDocument {
75
75
  snapshot_done: boolean | undefined;
76
76
  }
77
77
 
78
+ /**
79
+ * Record the state of each bucket.
80
+ *
81
+ * Right now, this is just used to track when buckets are updated, for efficient incremental sync.
82
+ * In the future, this could be used to track operation counts, both for diagnostic purposes, and for
83
+ * determining when a compact and/or defragment could be beneficial.
84
+ *
85
+ * Note: There is currently no migration to populate this collection from existing data - it is only
86
+ * populated by new updates.
87
+ */
78
88
  export interface BucketStateDocument {
79
89
  _id: {
80
90
  g: number;
81
91
  b: string;
82
92
  };
83
93
  last_op: bigint;
84
- op_count: number;
85
94
  }
86
95
 
87
96
  export interface IdSequenceDocument {
@@ -357,6 +357,74 @@ exports[`sync - mongodb > sync legacy non-raw data 1`] = `
357
357
  ]
358
358
  `;
359
359
 
360
+ exports[`sync - mongodb > sync updates to data query only 1`] = `
361
+ [
362
+ {
363
+ "checkpoint": {
364
+ "buckets": [
365
+ {
366
+ "bucket": "by_user["user1"]",
367
+ "checksum": 0,
368
+ "count": 0,
369
+ "priority": 3,
370
+ },
371
+ ],
372
+ "last_op_id": "1",
373
+ "write_checkpoint": undefined,
374
+ },
375
+ },
376
+ {
377
+ "checkpoint_complete": {
378
+ "last_op_id": "1",
379
+ },
380
+ },
381
+ ]
382
+ `;
383
+
384
+ exports[`sync - mongodb > sync updates to data query only 2`] = `
385
+ [
386
+ {
387
+ "checkpoint_diff": {
388
+ "last_op_id": "2",
389
+ "removed_buckets": [],
390
+ "updated_buckets": [
391
+ {
392
+ "bucket": "by_user["user1"]",
393
+ "checksum": 1418351250,
394
+ "count": 1,
395
+ "priority": 3,
396
+ },
397
+ ],
398
+ "write_checkpoint": undefined,
399
+ },
400
+ },
401
+ {
402
+ "data": {
403
+ "after": "0",
404
+ "bucket": "by_user["user1"]",
405
+ "data": [
406
+ {
407
+ "checksum": 1418351250n,
408
+ "data": "{"id":"list1","user_id":"user1","name":"User 1"}",
409
+ "object_id": "list1",
410
+ "object_type": "lists",
411
+ "op": "PUT",
412
+ "op_id": "2",
413
+ "subkey": "0ffb7b58-d14d-5efa-be6c-c8eda74ab7a8",
414
+ },
415
+ ],
416
+ "has_more": false,
417
+ "next_after": "2",
418
+ },
419
+ },
420
+ {
421
+ "checkpoint_complete": {
422
+ "last_op_id": "2",
423
+ },
424
+ },
425
+ ]
426
+ `;
427
+
360
428
  exports[`sync - mongodb > sync updates to global data 1`] = `
361
429
  [
362
430
  {
@@ -468,3 +536,106 @@ exports[`sync - mongodb > sync updates to global data 3`] = `
468
536
  },
469
537
  ]
470
538
  `;
539
+
540
+ exports[`sync - mongodb > sync updates to parameter query + data 1`] = `
541
+ [
542
+ {
543
+ "checkpoint": {
544
+ "buckets": [],
545
+ "last_op_id": "0",
546
+ "write_checkpoint": undefined,
547
+ },
548
+ },
549
+ {
550
+ "checkpoint_complete": {
551
+ "last_op_id": "0",
552
+ },
553
+ },
554
+ ]
555
+ `;
556
+
557
+ exports[`sync - mongodb > sync updates to parameter query + data 2`] = `
558
+ [
559
+ {
560
+ "checkpoint_diff": {
561
+ "last_op_id": "2",
562
+ "removed_buckets": [],
563
+ "updated_buckets": [
564
+ {
565
+ "bucket": "by_user["user1"]",
566
+ "checksum": 1418351250,
567
+ "count": 1,
568
+ "priority": 3,
569
+ },
570
+ ],
571
+ "write_checkpoint": undefined,
572
+ },
573
+ },
574
+ {
575
+ "data": {
576
+ "after": "0",
577
+ "bucket": "by_user["user1"]",
578
+ "data": [
579
+ {
580
+ "checksum": 1418351250n,
581
+ "data": "{"id":"list1","user_id":"user1","name":"User 1"}",
582
+ "object_id": "list1",
583
+ "object_type": "lists",
584
+ "op": "PUT",
585
+ "op_id": "1",
586
+ "subkey": "0ffb7b58-d14d-5efa-be6c-c8eda74ab7a8",
587
+ },
588
+ ],
589
+ "has_more": false,
590
+ "next_after": "1",
591
+ },
592
+ },
593
+ {
594
+ "checkpoint_complete": {
595
+ "last_op_id": "2",
596
+ },
597
+ },
598
+ ]
599
+ `;
600
+
601
+ exports[`sync - mongodb > sync updates to parameter query only 1`] = `
602
+ [
603
+ {
604
+ "checkpoint": {
605
+ "buckets": [],
606
+ "last_op_id": "0",
607
+ "write_checkpoint": undefined,
608
+ },
609
+ },
610
+ {
611
+ "checkpoint_complete": {
612
+ "last_op_id": "0",
613
+ },
614
+ },
615
+ ]
616
+ `;
617
+
618
+ exports[`sync - mongodb > sync updates to parameter query only 2`] = `
619
+ [
620
+ {
621
+ "checkpoint_diff": {
622
+ "last_op_id": "1",
623
+ "removed_buckets": [],
624
+ "updated_buckets": [
625
+ {
626
+ "bucket": "by_user["user1"]",
627
+ "checksum": 0,
628
+ "count": 0,
629
+ "priority": 3,
630
+ },
631
+ ],
632
+ "write_checkpoint": undefined,
633
+ },
634
+ },
635
+ {
636
+ "checkpoint_complete": {
637
+ "last_op_id": "1",
638
+ },
639
+ },
640
+ ]
641
+ `;
package/test/src/setup.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import { container } from '@powersync/lib-services-framework';
2
- import { test_utils } from '@powersync/service-core-tests';
3
2
  import { beforeAll, beforeEach } from 'vitest';
3
+ import { METRICS_HELPER } from '@powersync/service-core-tests';
4
4
 
5
5
  beforeAll(async () => {
6
6
  // Executes for every test file
7
7
  container.registerDefaults();
8
- await test_utils.initMetrics();
9
8
  });
10
9
 
11
10
  beforeEach(async () => {
12
- await test_utils.resetMetrics();
11
+ METRICS_HELPER.resetMetrics();
13
12
  });