@powersync/service-module-postgres-storage 0.0.0-dev-20250507154604 → 0.0.0-dev-20250617143654

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +54 -9
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/@types/migrations/scripts/1749024804042-snapshot-progress.d.ts +3 -0
  4. package/dist/@types/storage/PostgresSyncRulesStorage.d.ts +0 -1
  5. package/dist/@types/storage/PostgresTestStorageFactoryGenerator.d.ts +5 -1
  6. package/dist/@types/storage/batch/PostgresBucketBatch.d.ts +9 -2
  7. package/dist/@types/storage/checkpoints/PostgresWriteCheckpointAPI.d.ts +2 -3
  8. package/dist/@types/storage/sync-rules/PostgresPersistedSyncRulesContent.d.ts +1 -0
  9. package/dist/@types/types/models/SourceTable.d.ts +3 -0
  10. package/dist/@types/types/models/SyncRules.d.ts +4 -0
  11. package/dist/@types/types/types.d.ts +2 -2
  12. package/dist/migrations/scripts/1684951997326-init.js.map +1 -1
  13. package/dist/migrations/scripts/1749024804042-snapshot-progress.js +110 -0
  14. package/dist/migrations/scripts/1749024804042-snapshot-progress.js.map +1 -0
  15. package/dist/storage/PostgresSyncRulesStorage.js +15 -7
  16. package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
  17. package/dist/storage/PostgresTestStorageFactoryGenerator.js +48 -37
  18. package/dist/storage/PostgresTestStorageFactoryGenerator.js.map +1 -1
  19. package/dist/storage/batch/PostgresBucketBatch.js +80 -27
  20. package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
  21. package/dist/storage/batch/PostgresPersistedBatch.js +1 -1
  22. package/dist/storage/batch/PostgresPersistedBatch.js.map +1 -1
  23. package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.js +1 -5
  24. package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.js.map +1 -1
  25. package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js +2 -0
  26. package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js.map +1 -1
  27. package/dist/types/models/SourceTable.js +5 -2
  28. package/dist/types/models/SourceTable.js.map +1 -1
  29. package/dist/types/models/SyncRules.js +4 -0
  30. package/dist/types/models/SyncRules.js.map +1 -1
  31. package/package.json +9 -10
  32. package/src/migrations/scripts/1684951997326-init.ts +0 -1
  33. package/src/migrations/scripts/1749024804042-snapshot-progress.ts +43 -0
  34. package/src/storage/PostgresSyncRulesStorage.ts +15 -10
  35. package/src/storage/PostgresTestStorageFactoryGenerator.ts +48 -36
  36. package/src/storage/batch/PostgresBucketBatch.ts +95 -30
  37. package/src/storage/batch/PostgresPersistedBatch.ts +1 -1
  38. package/src/storage/checkpoints/PostgresWriteCheckpointAPI.ts +5 -10
  39. package/src/storage/sync-rules/PostgresPersistedSyncRulesContent.ts +2 -0
  40. package/src/types/models/SourceTable.ts +5 -2
  41. package/src/types/models/SyncRules.ts +4 -0
  42. package/test/src/__snapshots__/storage_sync.test.ts.snap +147 -0
  43. package/test/src/migrations.test.ts +10 -2
  44. package/test/src/util.ts +7 -2
@@ -309,6 +309,153 @@ exports[`sync - postgres > sync global data 1`] = `
309
309
  ]
310
310
  `;
311
311
 
312
+ exports[`sync - postgres > sync interrupts low-priority buckets on new checkpoints (2) 1`] = `
313
+ [
314
+ {
315
+ "checkpoint": {
316
+ "buckets": [
317
+ {
318
+ "bucket": "b0a[]",
319
+ "checksum": -659831575,
320
+ "count": 2000,
321
+ "priority": 2,
322
+ },
323
+ {
324
+ "bucket": "b0b[]",
325
+ "checksum": -659831575,
326
+ "count": 2000,
327
+ "priority": 2,
328
+ },
329
+ {
330
+ "bucket": "b1[]",
331
+ "checksum": -1096116670,
332
+ "count": 1,
333
+ "priority": 1,
334
+ },
335
+ ],
336
+ "last_op_id": "4001",
337
+ "write_checkpoint": undefined,
338
+ },
339
+ },
340
+ {
341
+ "data": {
342
+ "after": "0",
343
+ "bucket": "b1[]",
344
+ "data": undefined,
345
+ "has_more": false,
346
+ "next_after": "1",
347
+ },
348
+ },
349
+ {
350
+ "partial_checkpoint_complete": {
351
+ "last_op_id": "4001",
352
+ "priority": 1,
353
+ },
354
+ },
355
+ {
356
+ "data": {
357
+ "after": "0",
358
+ "bucket": "b0a[]",
359
+ "data": undefined,
360
+ "has_more": true,
361
+ "next_after": "2000",
362
+ },
363
+ },
364
+ {
365
+ "data": {
366
+ "after": "2000",
367
+ "bucket": "b0a[]",
368
+ "data": undefined,
369
+ "has_more": true,
370
+ "next_after": "4000",
371
+ },
372
+ },
373
+ {
374
+ "checkpoint_diff": {
375
+ "last_op_id": "4004",
376
+ "removed_buckets": [],
377
+ "updated_buckets": [
378
+ {
379
+ "bucket": "b0a[]",
380
+ "checksum": 883076828,
381
+ "count": 2001,
382
+ "priority": 2,
383
+ },
384
+ {
385
+ "bucket": "b0b[]",
386
+ "checksum": 883076828,
387
+ "count": 2001,
388
+ "priority": 2,
389
+ },
390
+ {
391
+ "bucket": "b1[]",
392
+ "checksum": 1841937527,
393
+ "count": 2,
394
+ "priority": 1,
395
+ },
396
+ ],
397
+ "write_checkpoint": undefined,
398
+ },
399
+ },
400
+ {
401
+ "data": {
402
+ "after": "1",
403
+ "bucket": "b1[]",
404
+ "data": undefined,
405
+ "has_more": false,
406
+ "next_after": "4002",
407
+ },
408
+ },
409
+ {
410
+ "partial_checkpoint_complete": {
411
+ "last_op_id": "4004",
412
+ "priority": 1,
413
+ },
414
+ },
415
+ {
416
+ "data": {
417
+ "after": "4000",
418
+ "bucket": "b0a[]",
419
+ "data": undefined,
420
+ "has_more": false,
421
+ "next_after": "4003",
422
+ },
423
+ },
424
+ {
425
+ "data": {
426
+ "after": "0",
427
+ "bucket": "b0b[]",
428
+ "data": undefined,
429
+ "has_more": true,
430
+ "next_after": "1999",
431
+ },
432
+ },
433
+ {
434
+ "data": {
435
+ "after": "1999",
436
+ "bucket": "b0b[]",
437
+ "data": undefined,
438
+ "has_more": true,
439
+ "next_after": "3999",
440
+ },
441
+ },
442
+ {
443
+ "data": {
444
+ "after": "3999",
445
+ "bucket": "b0b[]",
446
+ "data": undefined,
447
+ "has_more": false,
448
+ "next_after": "4004",
449
+ },
450
+ },
451
+ {
452
+ "checkpoint_complete": {
453
+ "last_op_id": "4004",
454
+ },
455
+ },
456
+ ]
457
+ `;
458
+
312
459
  exports[`sync - postgres > sync legacy non-raw data 1`] = `
313
460
  [
314
461
  {
@@ -1,15 +1,23 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { beforeEach, describe, expect, it } from 'vitest';
2
2
 
3
+ import { Direction } from '@powersync/lib-services-framework';
3
4
  import { register } from '@powersync/service-core-tests';
4
5
  import { PostgresMigrationAgent } from '../../src/migrations/PostgresMigrationAgent.js';
5
6
  import { env } from './env.js';
6
- import { POSTGRES_STORAGE_FACTORY } from './util.js';
7
+ import { POSTGRES_STORAGE_FACTORY, POSTGRES_STORAGE_SETUP } from './util.js';
7
8
 
8
9
  const MIGRATION_AGENT_FACTORY = () => {
9
10
  return new PostgresMigrationAgent({ type: 'postgresql', uri: env.PG_STORAGE_TEST_URL, sslmode: 'disable' });
10
11
  };
11
12
 
12
13
  describe('Migrations', () => {
14
+ beforeEach(async () => {
15
+ // The migration tests clear the migration store, without running the down migrations.
16
+ // This ensures all the down migrations have been run before.
17
+ const setup = POSTGRES_STORAGE_SETUP;
18
+ await setup.migrate(Direction.Down);
19
+ });
20
+
13
21
  register.registerMigrationTests(MIGRATION_AGENT_FACTORY);
14
22
 
15
23
  it('Should have tables declared', async () => {
package/test/src/util.ts CHANGED
@@ -2,7 +2,10 @@ import path from 'path';
2
2
  import { fileURLToPath } from 'url';
3
3
  import { normalizePostgresStorageConfig } from '../../src//types/types.js';
4
4
  import { PostgresMigrationAgent } from '../../src/migrations/PostgresMigrationAgent.js';
5
- import { PostgresTestStorageFactoryGenerator } from '../../src/storage/PostgresTestStorageFactoryGenerator.js';
5
+ import {
6
+ postgresTestSetup,
7
+ PostgresTestStorageFactoryGenerator
8
+ } from '../../src/storage/PostgresTestStorageFactoryGenerator.js';
6
9
  import { env } from './env.js';
7
10
 
8
11
  const __filename = fileURLToPath(import.meta.url);
@@ -28,7 +31,9 @@ class TestPostgresMigrationAgent extends PostgresMigrationAgent {
28
31
  }
29
32
  }
30
33
 
31
- export const POSTGRES_STORAGE_FACTORY = PostgresTestStorageFactoryGenerator({
34
+ export const POSTGRES_STORAGE_SETUP = postgresTestSetup({
32
35
  url: env.PG_STORAGE_TEST_URL,
33
36
  migrationAgent: (config) => new TestPostgresMigrationAgent(config)
34
37
  });
38
+
39
+ export const POSTGRES_STORAGE_FACTORY = POSTGRES_STORAGE_SETUP.factory;