@powersync/service-module-postgres-storage 0.0.0-dev-20260602073133 → 0.0.0-dev-20260909133214

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 (133) hide show
  1. package/CHANGELOG.md +179 -6
  2. package/dist/migrations/scripts/1782950400000-checkpoint-requested-at.d.ts +3 -0
  3. package/dist/migrations/scripts/1782950400000-checkpoint-requested-at.js +42 -0
  4. package/dist/migrations/scripts/1782950400000-checkpoint-requested-at.js.map +1 -0
  5. package/dist/migrations/scripts/1784900000000-source-metadata.d.ts +3 -0
  6. package/dist/migrations/scripts/1784900000000-source-metadata.js +22 -0
  7. package/dist/migrations/scripts/1784900000000-source-metadata.js.map +1 -0
  8. package/dist/migrations/scripts/1788000000000-sync-config-version-label.d.ts +3 -0
  9. package/dist/migrations/scripts/1788000000000-sync-config-version-label.js +12 -0
  10. package/dist/migrations/scripts/1788000000000-sync-config-version-label.js.map +1 -0
  11. package/dist/{@types/storage → storage}/PostgresBucketStorageFactory.d.ts +14 -12
  12. package/dist/storage/PostgresBucketStorageFactory.js +73 -62
  13. package/dist/storage/PostgresBucketStorageFactory.js.map +1 -1
  14. package/dist/{@types/storage → storage}/PostgresCompactor.d.ts +3 -1
  15. package/dist/storage/PostgresCompactor.js +21 -1
  16. package/dist/storage/PostgresCompactor.js.map +1 -1
  17. package/dist/storage/PostgresReportStorage.js.map +1 -1
  18. package/dist/storage/PostgresStorageProvider.js +3 -1
  19. package/dist/storage/PostgresStorageProvider.js.map +1 -1
  20. package/dist/{@types/storage → storage}/PostgresSyncRulesStorage.d.ts +39 -13
  21. package/dist/storage/PostgresSyncRulesStorage.js +266 -181
  22. package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
  23. package/dist/{@types/storage → storage}/batch/PostgresBucketBatch.d.ts +10 -26
  24. package/dist/storage/batch/PostgresBucketBatch.js +290 -286
  25. package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
  26. package/dist/{@types/storage → storage}/checkpoints/PostgresWriteCheckpointAPI.d.ts +2 -2
  27. package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.js +163 -26
  28. package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.js.map +1 -1
  29. package/dist/{@types/storage → storage}/current-data-store.d.ts +8 -2
  30. package/dist/storage/current-data-store.js +66 -11
  31. package/dist/storage/current-data-store.js.map +1 -1
  32. package/dist/{@types/storage → storage}/storage-index.d.ts +1 -0
  33. package/dist/storage/storage-index.js +1 -0
  34. package/dist/storage/storage-index.js.map +1 -1
  35. package/dist/storage/sync-rules/PostgresPersistedSyncConfigContent.d.ts +17 -0
  36. package/dist/storage/sync-rules/PostgresPersistedSyncConfigContent.js +94 -0
  37. package/dist/storage/sync-rules/PostgresPersistedSyncConfigContent.js.map +1 -0
  38. package/dist/{@types/types → types}/models/ActiveCheckpoint.d.ts +2 -2
  39. package/dist/types/models/ActiveCheckpoint.js +3 -2
  40. package/dist/types/models/ActiveCheckpoint.js.map +1 -1
  41. package/dist/{@types/types → types}/models/ActiveCheckpointNotification.d.ts +2 -2
  42. package/dist/types/models/BucketData.d.ts +22 -0
  43. package/dist/types/models/BucketData.js +7 -6
  44. package/dist/types/models/BucketData.js.map +1 -1
  45. package/dist/{@types/types → types}/models/CurrentData.d.ts +1 -1
  46. package/dist/types/models/CurrentData.js +2 -1
  47. package/dist/types/models/CurrentData.js.map +1 -1
  48. package/dist/{@types/types → types}/models/SdkReporting.d.ts +3 -3
  49. package/dist/types/models/SdkReporting.js +3 -5
  50. package/dist/types/models/SdkReporting.js.map +1 -1
  51. package/dist/{@types/types → types}/models/SourceTable.d.ts +13 -8
  52. package/dist/types/models/SourceTable.js +11 -6
  53. package/dist/types/models/SourceTable.js.map +1 -1
  54. package/dist/{@types/types → types}/models/SyncRules.d.ts +11 -10
  55. package/dist/types/models/SyncRules.js +12 -11
  56. package/dist/types/models/SyncRules.js.map +1 -1
  57. package/dist/{@types/types → types}/models/WriteCheckpoint.d.ts +2 -0
  58. package/dist/types/models/WriteCheckpoint.js +6 -2
  59. package/dist/types/models/WriteCheckpoint.js.map +1 -1
  60. package/dist/{@types/types → types}/types.d.ts +2 -0
  61. package/dist/utils/checkpoints.d.ts +9 -0
  62. package/dist/utils/checkpoints.js +26 -0
  63. package/dist/utils/checkpoints.js.map +1 -0
  64. package/dist/utils/test-utils.js +2 -2
  65. package/dist/utils/test-utils.js.map +1 -1
  66. package/package.json +10 -22
  67. package/src/migrations/scripts/1782950400000-checkpoint-requested-at.ts +51 -0
  68. package/src/migrations/scripts/1784900000000-source-metadata.ts +31 -0
  69. package/src/migrations/scripts/1788000000000-sync-config-version-label.ts +18 -0
  70. package/src/storage/PostgresBucketStorageFactory.ts +82 -65
  71. package/src/storage/PostgresCompactor.ts +25 -1
  72. package/src/storage/PostgresReportStorage.ts +1 -2
  73. package/src/storage/PostgresStorageProvider.ts +3 -1
  74. package/src/storage/PostgresSyncRulesStorage.ts +295 -196
  75. package/src/storage/batch/PostgresBucketBatch.ts +321 -310
  76. package/src/storage/checkpoints/PostgresWriteCheckpointAPI.ts +176 -26
  77. package/src/storage/current-data-store.ts +66 -11
  78. package/src/storage/storage-index.ts +1 -0
  79. package/src/storage/sync-rules/PostgresPersistedSyncConfigContent.ts +105 -0
  80. package/src/types/models/ActiveCheckpoint.ts +3 -2
  81. package/src/types/models/BucketData.ts +7 -6
  82. package/src/types/models/CurrentData.ts +2 -1
  83. package/src/types/models/SdkReporting.ts +4 -4
  84. package/src/types/models/SourceTable.ts +12 -6
  85. package/src/types/models/SyncRules.ts +12 -11
  86. package/src/types/models/WriteCheckpoint.ts +6 -2
  87. package/src/utils/checkpoints.ts +31 -0
  88. package/src/utils/test-utils.ts +2 -2
  89. package/test/src/__snapshots__/storage_sync.test.ts.snap +44 -1621
  90. package/test/src/checkpoint_notifications.test.ts +528 -0
  91. package/test/src/migrations.test.ts +1 -1
  92. package/test/src/storage.test.ts +235 -11
  93. package/test/src/storage_compacting.test.ts +17 -9
  94. package/test/src/storage_sync.test.ts +55 -8
  95. package/test/src/util.ts +1 -1
  96. package/test/tsconfig.json +1 -3
  97. package/tsconfig.json +1 -4
  98. package/tsconfig.tsbuildinfo +1 -0
  99. package/dist/.tsbuildinfo +0 -1
  100. package/dist/@types/storage/sync-rules/PostgresPersistedSyncRulesContent.d.ts +0 -9
  101. package/dist/@types/types/models/BucketData.d.ts +0 -22
  102. package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js +0 -49
  103. package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js.map +0 -1
  104. package/src/storage/sync-rules/PostgresPersistedSyncRulesContent.ts +0 -54
  105. /package/dist/{@types/index.d.ts → index.d.ts} +0 -0
  106. /package/dist/{@types/migrations → migrations}/PostgresMigrationAgent.d.ts +0 -0
  107. /package/dist/{@types/migrations → migrations}/PostgresMigrationStore.d.ts +0 -0
  108. /package/dist/{@types/migrations → migrations}/migration-utils.d.ts +0 -0
  109. /package/dist/{@types/migrations → migrations}/scripts/1684951997326-init.d.ts +0 -0
  110. /package/dist/{@types/migrations → migrations}/scripts/1749024804042-snapshot-progress.d.ts +0 -0
  111. /package/dist/{@types/migrations → migrations}/scripts/1756282360128-connection-reporting.d.ts +0 -0
  112. /package/dist/{@types/migrations → migrations}/scripts/1771232439485-storage-version.d.ts +0 -0
  113. /package/dist/{@types/migrations → migrations}/scripts/1771424826685-current-data-pending-deletes.d.ts +0 -0
  114. /package/dist/{@types/migrations → migrations}/scripts/1771491856000-sync-plan.d.ts +0 -0
  115. /package/dist/{@types/module → module}/PostgresStorageModule.d.ts +0 -0
  116. /package/dist/{@types/storage → storage}/PostgresReportStorage.d.ts +0 -0
  117. /package/dist/{@types/storage → storage}/PostgresStorageProvider.d.ts +0 -0
  118. /package/dist/{@types/storage → storage}/batch/OperationBatch.d.ts +0 -0
  119. /package/dist/{@types/storage → storage}/batch/PostgresPersistedBatch.d.ts +0 -0
  120. /package/dist/{@types/storage → storage}/table-id.d.ts +0 -0
  121. /package/dist/{@types/types → types}/codecs.d.ts +0 -0
  122. /package/dist/{@types/types → types}/models/BucketParameters.d.ts +0 -0
  123. /package/dist/{@types/types → types}/models/Instance.d.ts +0 -0
  124. /package/dist/{@types/types → types}/models/Migration.d.ts +0 -0
  125. /package/dist/{@types/types → types}/models/json.d.ts +0 -0
  126. /package/dist/{@types/types → types}/models/models-index.d.ts +0 -0
  127. /package/dist/{@types/utils → utils}/application-name.d.ts +0 -0
  128. /package/dist/{@types/utils → utils}/bson.d.ts +0 -0
  129. /package/dist/{@types/utils → utils}/bucket-data.d.ts +0 -0
  130. /package/dist/{@types/utils → utils}/db.d.ts +0 -0
  131. /package/dist/{@types/utils → utils}/test-utils.d.ts +0 -0
  132. /package/dist/{@types/utils → utils}/ts-codec.d.ts +0 -0
  133. /package/dist/{@types/utils → utils}/utils-index.d.ts +0 -0
@@ -1,9 +0,0 @@
1
- import * as lib_postgres from '@powersync/lib-service-postgres';
2
- import { storage } from '@powersync/service-core';
3
- import { models } from '../../types/types.js';
4
- export declare class PostgresPersistedSyncRulesContent extends storage.PersistedSyncRulesContent {
5
- private db;
6
- current_lock: storage.ReplicationLock | null;
7
- constructor(db: lib_postgres.DatabaseClient, row: models.SyncRulesDecoded);
8
- lock(): Promise<storage.ReplicationLock>;
9
- }
@@ -1,22 +0,0 @@
1
- import * as t from 'ts-codec';
2
- export declare enum OpType {
3
- PUT = "PUT",
4
- REMOVE = "REMOVE",
5
- MOVE = "MOVE",
6
- CLEAR = "CLEAR"
7
- }
8
- export declare const BucketData: t.ObjectCodec<{
9
- group_id: t.Codec<number, number, "pg_number", t.CodecProps>;
10
- bucket_name: t.IdentityCodec<t.CodecType.String>;
11
- op_id: t.Codec<bigint, string | number, string, t.CodecProps>;
12
- op: t.EnumCodec<typeof OpType>;
13
- source_table: t.Union<t.Codec<null, null, string, t.CodecProps>, t.IdentityCodec<t.CodecType.String>>;
14
- source_key: t.Union<t.Codec<null, null, string, t.CodecProps>, t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>>;
15
- table_name: t.Union<t.Codec<string, string, string, t.CodecProps>, t.Codec<null, null, t.CodecType.Null, t.CodecProps>>;
16
- row_id: t.Union<t.Codec<string, string, string, t.CodecProps>, t.Codec<null, null, t.CodecType.Null, t.CodecProps>>;
17
- checksum: t.Codec<bigint, string | number, string, t.CodecProps>;
18
- data: t.Union<t.Codec<null, null, string, t.CodecProps>, t.IdentityCodec<t.CodecType.String>>;
19
- target_op: t.Union<t.Codec<null, null, string, t.CodecProps>, t.Codec<bigint, string | number, string, t.CodecProps>>;
20
- }>;
21
- export type BucketData = t.Encoded<typeof BucketData>;
22
- export type BucketDataDecoded = t.Decoded<typeof BucketData>;
@@ -1,49 +0,0 @@
1
- import * as lib_postgres from '@powersync/lib-service-postgres';
2
- import { ErrorCode, ServiceError } from '@powersync/lib-services-framework';
3
- import { storage } from '@powersync/service-core';
4
- export class PostgresPersistedSyncRulesContent extends storage.PersistedSyncRulesContent {
5
- db;
6
- current_lock = null;
7
- constructor(db, row) {
8
- super({
9
- id: Number(row.id),
10
- sync_rules_content: row.content,
11
- compiled_plan: row.sync_plan,
12
- last_checkpoint_lsn: row.last_checkpoint_lsn,
13
- slot_name: row.slot_name,
14
- last_fatal_error: row.last_fatal_error,
15
- last_checkpoint_ts: row.last_checkpoint_ts ? new Date(row.last_checkpoint_ts) : null,
16
- last_keepalive_ts: row.last_keepalive_ts ? new Date(row.last_keepalive_ts) : null,
17
- active: row.state == 'ACTIVE',
18
- storageVersion: row.storage_version ?? storage.LEGACY_STORAGE_VERSION
19
- });
20
- this.db = db;
21
- }
22
- async lock() {
23
- const manager = new lib_postgres.PostgresLockManager({
24
- db: this.db,
25
- name: `sync_rules_${this.id}_${this.slot_name}`
26
- });
27
- const lockHandle = await manager.acquire();
28
- if (!lockHandle) {
29
- throw new ServiceError(ErrorCode.PSYNC_S1003, `Replication stream is locked by another process, standing by.`);
30
- }
31
- const interval = setInterval(async () => {
32
- try {
33
- await lockHandle.refresh();
34
- }
35
- catch (e) {
36
- this.logger.error('Failed to refresh lock', e);
37
- clearInterval(interval);
38
- }
39
- }, 30_130);
40
- return (this.current_lock = {
41
- sync_rules_id: this.id,
42
- release: async () => {
43
- clearInterval(interval);
44
- return lockHandle.release();
45
- }
46
- });
47
- }
48
- }
49
- //# sourceMappingURL=PostgresPersistedSyncRulesContent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresPersistedSyncRulesContent.js","sourceRoot":"","sources":["../../../src/storage/sync-rules/PostgresPersistedSyncRulesContent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGlD,MAAM,OAAO,iCAAkC,SAAQ,OAAO,CAAC,yBAAyB;IAI5E;IAHV,YAAY,GAAmC,IAAI,CAAC;IAEpD,YACU,EAA+B,EACvC,GAA4B;QAE5B,KAAK,CAAC;YACJ,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,kBAAkB,EAAE,GAAG,CAAC,OAAO;YAC/B,aAAa,EAAE,GAAG,CAAC,SAAS;YAC5B,mBAAmB,EAAE,GAAG,CAAC,mBAAmB;YAC5C,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;YACtC,kBAAkB,EAAE,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI;YACpF,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI;YACjF,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,QAAQ;YAC7B,cAAc,EAAE,GAAG,CAAC,eAAe,IAAI,OAAO,CAAC,sBAAsB;SACtE,CAAC,CAAC;QAdK,OAAE,GAAF,EAAE,CAA6B;IAezC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,mBAAmB,CAAC;YACnD,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,cAAc,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,SAAS,EAAE;SAChD,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,YAAY,CAAC,SAAS,CAAC,WAAW,EAAE,+DAA+D,CAAC,CAAC;QACjH,CAAC;QAED,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;YACtC,IAAI,CAAC;gBACH,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;YAC7B,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;gBAC/C,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC,EAAE,MAAM,CAAC,CAAC;QAEX,OAAO,CAAC,IAAI,CAAC,YAAY,GAAG;YAC1B,aAAa,EAAE,IAAI,CAAC,EAAE;YACtB,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,aAAa,CAAC,QAAQ,CAAC,CAAC;gBACxB,OAAO,UAAU,CAAC,OAAO,EAAE,CAAC;YAC9B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,54 +0,0 @@
1
- import * as lib_postgres from '@powersync/lib-service-postgres';
2
- import { ErrorCode, ServiceError } from '@powersync/lib-services-framework';
3
- import { storage } from '@powersync/service-core';
4
- import { models } from '../../types/types.js';
5
-
6
- export class PostgresPersistedSyncRulesContent extends storage.PersistedSyncRulesContent {
7
- current_lock: storage.ReplicationLock | null = null;
8
-
9
- constructor(
10
- private db: lib_postgres.DatabaseClient,
11
- row: models.SyncRulesDecoded
12
- ) {
13
- super({
14
- id: Number(row.id),
15
- sync_rules_content: row.content,
16
- compiled_plan: row.sync_plan,
17
- last_checkpoint_lsn: row.last_checkpoint_lsn,
18
- slot_name: row.slot_name,
19
- last_fatal_error: row.last_fatal_error,
20
- last_checkpoint_ts: row.last_checkpoint_ts ? new Date(row.last_checkpoint_ts) : null,
21
- last_keepalive_ts: row.last_keepalive_ts ? new Date(row.last_keepalive_ts) : null,
22
- active: row.state == 'ACTIVE',
23
- storageVersion: row.storage_version ?? storage.LEGACY_STORAGE_VERSION
24
- });
25
- }
26
-
27
- async lock(): Promise<storage.ReplicationLock> {
28
- const manager = new lib_postgres.PostgresLockManager({
29
- db: this.db,
30
- name: `sync_rules_${this.id}_${this.slot_name}`
31
- });
32
- const lockHandle = await manager.acquire();
33
- if (!lockHandle) {
34
- throw new ServiceError(ErrorCode.PSYNC_S1003, `Replication stream is locked by another process, standing by.`);
35
- }
36
-
37
- const interval = setInterval(async () => {
38
- try {
39
- await lockHandle.refresh();
40
- } catch (e) {
41
- this.logger.error('Failed to refresh lock', e);
42
- clearInterval(interval);
43
- }
44
- }, 30_130);
45
-
46
- return (this.current_lock = {
47
- sync_rules_id: this.id,
48
- release: async () => {
49
- clearInterval(interval);
50
- return lockHandle.release();
51
- }
52
- });
53
- }
54
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes