@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
package/CHANGELOG.md CHANGED
@@ -1,15 +1,187 @@
1
1
  # @powersync/service-module-postgres-storage
2
2
 
3
- ## 0.0.0-dev-20260602073133
3
+ ## 0.0.0-dev-20260909133214
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [70b00a4]
8
+ - @powersync/service-sync-rules@0.0.0-dev-20260909133214
9
+ - @powersync/lib-services-framework@0.0.0-dev-20260909133214
10
+ - @powersync/service-jpgwire@0.0.0-dev-20260909133214
11
+ - @powersync/service-core@0.0.0-dev-20260909133214
12
+ - @powersync/lib-service-postgres@0.0.0-dev-20260909133214
13
+
14
+ ## 0.19.0
15
+
16
+ ### Minor Changes
17
+
18
+ - 189bd9e: Add storage_version: 4 as a stable storage version.
19
+ - 33a3c23: Add optional version_label for sync configs.
20
+
21
+ ### Patch Changes
22
+
23
+ - 332d649: [MongoDB Storage] Support incremental parameter compacting jobs.
24
+ - fccdff2: Add object storage metrics, and storage metrics split by sync config.
25
+ - 4e4063b: Optimize runtime type checks, closes https://github.com/powersync-ja/powersync-service/issues/771.
26
+ - 4037e8f: Add storage.default_storage_version config option.
27
+ - a997c88: Restructure MongoDB V3 bucket compacting.
28
+ - Updated dependencies [e11c54b]
29
+ - Updated dependencies [4b6a23e]
30
+ - Updated dependencies [189bd9e]
31
+ - Updated dependencies [bb08068]
32
+ - Updated dependencies [0077a8d]
33
+ - Updated dependencies [332d649]
34
+ - Updated dependencies [33a3c23]
35
+ - Updated dependencies [fccdff2]
36
+ - Updated dependencies [989d9e1]
37
+ - Updated dependencies [646c0de]
38
+ - Updated dependencies [cc121b3]
39
+ - Updated dependencies [4e4063b]
40
+ - Updated dependencies [2407f71]
41
+ - Updated dependencies [10131ca]
42
+ - Updated dependencies [4037e8f]
43
+ - Updated dependencies [3972bac]
44
+ - Updated dependencies [dd7a22f]
45
+ - Updated dependencies [a997c88]
46
+ - @powersync/service-core@1.26.0
47
+ - @powersync/service-sync-rules@0.41.0
48
+ - @powersync/service-types@0.18.0
49
+ - @powersync/lib-service-postgres@0.5.4
50
+ - @powersync/lib-services-framework@0.10.1
51
+ - @powersync/service-jpgwire@0.21.23
52
+
53
+ ## 0.18.0
54
+
55
+ ### Minor Changes
56
+
57
+ - 798d739: Add source-owned `SourceTable` reconciliation.
58
+
59
+ `resolveTables()` now queries all overlapping persisted candidates and passes them to a
60
+ source-provided reconciler that returns compatible and incompatible tables, can return
61
+ modified compatible copies, and supplies values used for potential new records. Storage persists allowlisted
62
+ source metadata differences but never interprets them. MongoDB v1/v3 and PostgreSQL storage were
63
+ refactored to this candidate-first model (PostgreSQL gains a nullable `source_metadata` JSONB column
64
+ via migration).
65
+
66
+ ### Patch Changes
67
+
68
+ - 798d739: Fix hydration of replica id column type ids in Postgres bucket storage.
69
+
70
+ `source_tables.replica_id_columns` is persisted with a `type_oid` key, but the decoding codec declared
71
+ `typeId`, so every `SourceTable` read back from a row lost its column type ids. This affected
72
+ `getSourceTableStatus()` and the tables returned for dropping, and now also the identity comparison
73
+ used by source table reconciliation. The codec matches the persisted key - no data migration is
74
+ needed.
75
+
76
+ - Updated dependencies [27b56cb]
77
+ - Updated dependencies [798d739]
78
+ - @powersync/service-core@1.25.0
79
+
80
+ ## 0.17.0
81
+
82
+ ### Minor Changes
83
+
84
+ - 2189250: Add `/sync/checkpoint-request` for client-supplied checkpoint request ids, previously called write checkpoint ids. The route returns the stored `checkpoint_request_id`, storage now treats managed request ids as monotonic per user/client, custom checkpoint request ids continue to use the existing `checkpoint` field for backwards compatibility, and `checkpoint_requested_at` metadata lets compact jobs remove expired request-derived checkpoint records.
85
+
86
+ This release includes storage migrations for the checkpoint request metadata. Self-hosters should run migrations as part of the upgrade.
87
+
88
+ ### Patch Changes
89
+
90
+ - 294f334: Clear the replication error flag outside the flush transaction. Clearing it inside the REPEATABLE READ replication transaction conflicts with concurrent keepalive updates on the same sync_rules row, causing serialization failures that retry the entire flush when multiple writers are active.
91
+ - 0a511c2: Delete rows in batches when clearing storage for a replication stream. A single DELETE covering the entire group can run for hours on large deployments and never complete once it exceeds statement or socket timeouts; batched deletes make durable progress and can be safely retried or aborted.
92
+ - c4860c9: Improve Postgres sync throughput by reading bucket data with ordered, per-bucket index range scans that stop once the requested batch is full.
93
+ - 63707af: Stability and performance fixes for MongoDB storage V3.
94
+ - 123c801: Reconnect PostgreSQL notification connections and restore `LISTEN` subscriptions when the underlying connection is terminated. Harden connection-slot retries and lease handling, and publish checkpoint notifications atomically with checkpoint updates.
95
+ - Updated dependencies [087b61e]
96
+ - Updated dependencies [2189250]
97
+ - Updated dependencies [922f974]
98
+ - Updated dependencies [c4860c9]
99
+ - Updated dependencies [483415d]
100
+ - Updated dependencies [8daa300]
101
+ - Updated dependencies [aab068b]
102
+ - Updated dependencies [123c801]
103
+ - Updated dependencies [37591e9]
104
+ - Updated dependencies [be42e25]
105
+ - Updated dependencies [cb4c627]
106
+ - @powersync/service-core@1.24.0
107
+ - @powersync/lib-services-framework@0.10.0
108
+ - @powersync/service-types@0.17.0
109
+ - @powersync/service-sync-rules@0.40.0
110
+ - @powersync/lib-service-postgres@0.5.3
111
+ - @powersync/service-jpgwire@0.21.22
112
+
113
+ ## 0.16.3
114
+
115
+ ### Patch Changes
116
+
117
+ - Updated dependencies [ea71bf3]
118
+ - Updated dependencies [ea31f64]
119
+ - Updated dependencies [edc6ed4]
120
+ - @powersync/service-sync-rules@0.39.0
121
+ - @powersync/service-core@1.23.3
122
+ - @powersync/lib-services-framework@0.9.8
123
+ - @powersync/service-jpgwire@0.21.21
124
+ - @powersync/lib-service-postgres@0.5.2
125
+
126
+ ## 0.16.2
127
+
128
+ ### Patch Changes
129
+
130
+ - e4f683d: [MongoDB Storage] Add experimental option to allow reading data from secondaries.
131
+ - c2edf86: Add `api.parameters.bucket_count_cache_ttl_minutes` configuration option.
132
+ - df9ab1e: Batch concurrent write checkpoint requests and increase request limits to improve throughput.
133
+ - Updated dependencies [71d4a0a]
134
+ - Updated dependencies [e4f683d]
135
+ - Updated dependencies [71d4a0a]
136
+ - Updated dependencies [a6ae678]
137
+ - Updated dependencies [c2edf86]
138
+ - Updated dependencies [df9ab1e]
139
+ - @powersync/service-core@1.23.2
140
+ - @powersync/service-sync-rules@0.38.1
141
+ - @powersync/service-types@0.16.1
142
+ - @powersync/lib-services-framework@0.9.7
143
+ - @powersync/lib-service-postgres@0.5.1
144
+
145
+ ## 0.16.1
146
+
147
+ ### Patch Changes
148
+
149
+ - 7e65360: Restructure replication locks for updated sync config.
150
+ - Updated dependencies [7e65360]
151
+ - @powersync/service-core@1.23.1
152
+
153
+ ## 0.16.0
154
+
155
+ ### Minor Changes
156
+
157
+ - a91a08f: [Experimental] Enable incremental reprocessing for MongoDB source + MongoDB storage. This includes significant changes to the v3 storage format.
158
+
159
+ ### Patch Changes
160
+
161
+ - 101ea67: Include table names in "Cannot mark snapshot done while source tables still require snapshotting" error.
162
+ - Updated dependencies [a91a08f]
163
+ - Updated dependencies [184c39f]
164
+ - Updated dependencies [c3f75df]
165
+ - Updated dependencies [4bd35ea]
166
+ - @powersync/service-core@1.23.0
167
+ - @powersync/lib-service-postgres@0.5.0
168
+ - @powersync/service-types@0.16.0
169
+ - @powersync/service-sync-rules@0.38.0
170
+ - @powersync/lib-services-framework@0.9.6
171
+ - @powersync/service-jpgwire@0.21.20
172
+
173
+ ## 0.15.0
4
174
 
5
175
  ### Minor Changes
6
176
 
7
177
  - e2bf1ad: [Internal] rework resolveTables to handle multiple SourceTables.
8
178
  - 15e2466: [MongoDB] Support snapshotting concurrently with streaming in storage v3+.
179
+ - ebeaa3b: [Postgres] Skip storing a redundant copy of replicated rows in `current_data` for tables with `REPLICA IDENTITY FULL`.
9
180
 
10
181
  ### Patch Changes
11
182
 
12
183
  - 6e2a57e: Refactor HydratedSyncConfig to support multiple SyncConfigs.
184
+ - Updated dependencies [17fd96b]
13
185
  - Updated dependencies [6e2a57e]
14
186
  - Updated dependencies [ec6df9f]
15
187
  - Updated dependencies [99d33d5]
@@ -22,13 +194,14 @@
22
194
  - Updated dependencies [92cc83b]
23
195
  - Updated dependencies [0aab0f9]
24
196
  - Updated dependencies [15e2466]
197
+ - Updated dependencies [ebeaa3b]
25
198
  - Updated dependencies [b116857]
26
199
  - Updated dependencies [a94b6c3]
27
- - @powersync/service-sync-rules@0.0.0-dev-20260602073133
28
- - @powersync/service-core@0.0.0-dev-20260602073133
29
- - @powersync/lib-services-framework@0.0.0-dev-20260602073133
30
- - @powersync/service-jpgwire@0.0.0-dev-20260602073133
31
- - @powersync/lib-service-postgres@0.0.0-dev-20260602073133
200
+ - @powersync/service-core@1.22.0
201
+ - @powersync/service-sync-rules@0.37.0
202
+ - @powersync/lib-services-framework@0.9.5
203
+ - @powersync/service-jpgwire@0.21.19
204
+ - @powersync/lib-service-postgres@0.4.28
32
205
 
33
206
  ## 0.14.0
34
207
 
@@ -0,0 +1,3 @@
1
+ import { migrations } from '@powersync/service-core';
2
+ export declare const up: migrations.PowerSyncMigrationFunction;
3
+ export declare const down: migrations.PowerSyncMigrationFunction;
@@ -0,0 +1,42 @@
1
+ import { openMigrationDB } from '../migration-utils.js';
2
+ export const up = async (context) => {
3
+ const { service_context: { configuration } } = context;
4
+ await using client = openMigrationDB(configuration.storage);
5
+ await client.transaction(async (db) => {
6
+ await db.sql `
7
+ ALTER TABLE write_checkpoints
8
+ ADD COLUMN checkpoint_requested_at TIMESTAMP WITH TIME ZONE
9
+ `.execute();
10
+ await db.sql `
11
+ ALTER TABLE custom_write_checkpoints
12
+ ADD COLUMN checkpoint_requested_at TIMESTAMP WITH TIME ZONE
13
+ `.execute();
14
+ await db.sql `
15
+ CREATE INDEX write_checkpoints_checkpoint_requested_at ON write_checkpoints (checkpoint_requested_at)
16
+ WHERE
17
+ checkpoint_requested_at IS NOT NULL
18
+ `.execute();
19
+ await db.sql `
20
+ CREATE INDEX custom_write_checkpoints_checkpoint_requested_at ON custom_write_checkpoints (checkpoint_requested_at)
21
+ WHERE
22
+ checkpoint_requested_at IS NOT NULL
23
+ `.execute();
24
+ });
25
+ };
26
+ export const down = async (context) => {
27
+ const { service_context: { configuration } } = context;
28
+ await using client = openMigrationDB(configuration.storage);
29
+ await client.transaction(async (db) => {
30
+ // Also drops the write_checkpoints_checkpoint_requested_at index.
31
+ await db.sql `
32
+ ALTER TABLE write_checkpoints
33
+ DROP COLUMN checkpoint_requested_at
34
+ `.execute();
35
+ // Also drops the custom_write_checkpoints_checkpoint_requested_at index.
36
+ await db.sql `
37
+ ALTER TABLE custom_write_checkpoints
38
+ DROP COLUMN checkpoint_requested_at
39
+ `.execute();
40
+ });
41
+ };
42
+ //# sourceMappingURL=1782950400000-checkpoint-requested-at.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"1782950400000-checkpoint-requested-at.js","sourceRoot":"","sources":["../../../src/migrations/scripts/1782950400000-checkpoint-requested-at.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IACzE,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IACZ,YAAY,MAAM,GAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAE5D,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QACpC,MAAM,EAAE,CAAC,GAAG,CAAA;;;KAGX,CAAC,OAAO,EAAE,CAAC;QACZ,MAAM,EAAE,CAAC,GAAG,CAAA;;;KAGX,CAAC,OAAO,EAAE,CAAC;QACZ,MAAM,EAAE,CAAC,GAAG,CAAA;;;;KAIX,CAAC,OAAO,EAAE,CAAC;QACZ,MAAM,EAAE,CAAC,GAAG,CAAA;;;;KAIX,CAAC,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IAC3E,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IACZ,YAAY,MAAM,GAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAE5D,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QACpC,kEAAkE;QAClE,MAAM,EAAE,CAAC,GAAG,CAAA;;;KAGX,CAAC,OAAO,EAAE,CAAC;QACZ,yEAAyE;QACzE,MAAM,EAAE,CAAC,GAAG,CAAA;;;KAGX,CAAC,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { migrations } from '@powersync/service-core';
2
+ export declare const up: migrations.PowerSyncMigrationFunction;
3
+ export declare const down: migrations.PowerSyncMigrationFunction;
@@ -0,0 +1,22 @@
1
+ import { openMigrationDB } from '../migration-utils.js';
2
+ export const up = async (context) => {
3
+ const { service_context: { configuration } } = context;
4
+ await using client = openMigrationDB(configuration.storage);
5
+ await client.transaction(async (db) => {
6
+ await db.sql `
7
+ ALTER TABLE source_tables
8
+ ADD COLUMN source_metadata JSONB
9
+ `.execute();
10
+ });
11
+ };
12
+ export const down = async (context) => {
13
+ const { service_context: { configuration } } = context;
14
+ await using client = openMigrationDB(configuration.storage);
15
+ await client.transaction(async (db) => {
16
+ await db.sql `
17
+ ALTER TABLE source_tables
18
+ DROP COLUMN source_metadata
19
+ `.execute();
20
+ });
21
+ };
22
+ //# sourceMappingURL=1784900000000-source-metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"1784900000000-source-metadata.js","sourceRoot":"","sources":["../../../src/migrations/scripts/1784900000000-source-metadata.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IACzE,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IACZ,YAAY,MAAM,GAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAE5D,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QACpC,MAAM,EAAE,CAAC,GAAG,CAAA;;;KAGX,CAAC,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IAC3E,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IACZ,YAAY,MAAM,GAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAE5D,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QACpC,MAAM,EAAE,CAAC,GAAG,CAAA;;;KAGX,CAAC,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { migrations } from '@powersync/service-core';
2
+ export declare const up: migrations.PowerSyncMigrationFunction;
3
+ export declare const down: migrations.PowerSyncMigrationFunction;
@@ -0,0 +1,12 @@
1
+ import { openMigrationDB } from '../migration-utils.js';
2
+ export const up = async (context) => {
3
+ const { service_context: { configuration } } = context;
4
+ await using client = openMigrationDB(configuration.storage);
5
+ await client.sql `ALTER TABLE sync_rules ADD COLUMN version_label TEXT`.execute();
6
+ };
7
+ export const down = async (context) => {
8
+ const { service_context: { configuration } } = context;
9
+ await using client = openMigrationDB(configuration.storage);
10
+ await client.sql `ALTER TABLE sync_rules DROP COLUMN version_label`.execute();
11
+ };
12
+ //# sourceMappingURL=1788000000000-sync-config-version-label.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"1788000000000-sync-config-version-label.js","sourceRoot":"","sources":["../../../src/migrations/scripts/1788000000000-sync-config-version-label.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IACzE,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IACZ,YAAY,MAAM,GAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC5D,MAAM,MAAM,CAAC,GAAG,CAAA,sDAAsD,CAAC,OAAO,EAAE,CAAC;AACnF,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IAC3E,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IACZ,YAAY,MAAM,GAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC5D,MAAM,MAAM,CAAC,GAAG,CAAA,kDAAkD,CAAC,OAAO,EAAE,CAAC;AAC/E,CAAC,CAAC"}
@@ -1,34 +1,36 @@
1
- import { framework, GetIntanceOptions, storage, SyncRulesBucketStorage } from '@powersync/service-core';
1
+ import { framework, GetIntanceOptions, storage } from '@powersync/service-core';
2
2
  import * as pg_wire from '@powersync/service-jpgwire';
3
3
  import * as lib_postgres from '@powersync/lib-service-postgres';
4
4
  import { NormalizedPostgresStorageConfig } from '../types/types.js';
5
- import { PostgresPersistedSyncRulesContent } from './sync-rules/PostgresPersistedSyncRulesContent.js';
5
+ import { PostgresPersistedReplicationStream } from './sync-rules/PostgresPersistedSyncConfigContent.js';
6
6
  export type PostgresBucketStorageOptions = {
7
7
  config: NormalizedPostgresStorageConfig;
8
- slot_name_prefix: string;
8
+ replicationStreamNamePrefix: string;
9
+ checksumCacheTtlMs?: number;
10
+ defaultStorageVersion?: number;
9
11
  };
10
12
  export declare class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
11
13
  protected options: PostgresBucketStorageOptions;
12
14
  [framework.DO_NOT_LOG]: boolean;
13
15
  readonly db: lib_postgres.DatabaseClient;
14
- readonly slot_name_prefix: string;
16
+ readonly replicationStreamNamePrefix: string;
15
17
  private activeStorageCache;
16
18
  constructor(options: PostgresBucketStorageOptions);
17
19
  [Symbol.asyncDispose](): Promise<void>;
18
20
  prepareStatements(connection: pg_wire.PgConnection): Promise<void>;
19
- getInstance(syncRules: storage.PersistedSyncRulesContent, options?: GetIntanceOptions): storage.SyncRulesBucketStorage;
21
+ getInstance(replicationStream: storage.PersistedReplicationStream, options?: GetIntanceOptions): storage.SyncRulesBucketStorage;
20
22
  getStorageMetrics(): Promise<storage.StorageMetrics>;
21
23
  getPowerSyncInstanceId(): Promise<string>;
22
24
  getSystemIdentifier(): Promise<storage.BucketStorageSystemIdentifier>;
23
- updateSyncRules(options: storage.UpdateSyncRulesOptions): Promise<PostgresPersistedSyncRulesContent>;
25
+ updateSyncRules(options: storage.UpdateSyncRulesOptions): Promise<PostgresPersistedReplicationStream>;
24
26
  /**
25
27
  * Lazy-initializes storage-version-specific structures, if needed.
26
28
  */
27
29
  private initializeStorageVersion;
28
- restartReplication(sync_rules_group_id: number): Promise<void>;
29
- getActiveSyncRulesContent(): Promise<storage.PersistedSyncRulesContent | null>;
30
- getNextSyncRulesContent(): Promise<storage.PersistedSyncRulesContent | null>;
31
- getReplicatingSyncRules(): Promise<storage.PersistedSyncRulesContent[]>;
32
- getStoppedSyncRules(): Promise<storage.PersistedSyncRulesContent[]>;
33
- getActiveStorage(): Promise<SyncRulesBucketStorage | null>;
30
+ restartReplication(replicationStreamId: number): Promise<void>;
31
+ getActiveSyncConfig(): Promise<storage.ResolvedSyncConfig | null>;
32
+ getDeployingSyncConfig(): Promise<storage.ResolvedSyncConfig | null>;
33
+ getReplicatingReplicationStreams(): Promise<storage.PersistedReplicationStream[]>;
34
+ getStoppedReplicationStreams(): Promise<storage.PersistedReplicationStream[]>;
35
+ private resolvedSyncConfigFromRow;
34
36
  }
@@ -5,14 +5,13 @@ import * as lib_postgres from '@powersync/lib-service-postgres';
5
5
  import { models } from '../types/types.js';
6
6
  import { getStorageApplicationName } from '../utils/application-name.js';
7
7
  import { NOTIFICATION_CHANNEL, STORAGE_SCHEMA_NAME } from '../utils/db.js';
8
- import { notifySyncRulesUpdate } from './batch/PostgresBucketBatch.js';
9
8
  import { PostgresSyncRulesStorage } from './PostgresSyncRulesStorage.js';
10
- import { PostgresPersistedSyncRulesContent } from './sync-rules/PostgresPersistedSyncRulesContent.js';
9
+ import { PostgresPersistedReplicationStream } from './sync-rules/PostgresPersistedSyncConfigContent.js';
11
10
  export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
12
11
  options;
13
12
  [framework.DO_NOT_LOG] = true;
14
13
  db;
15
- slot_name_prefix;
14
+ replicationStreamNamePrefix;
16
15
  activeStorageCache;
17
16
  constructor(options) {
18
17
  super();
@@ -23,7 +22,7 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
23
22
  notificationChannels: [NOTIFICATION_CHANNEL],
24
23
  applicationName: getStorageApplicationName()
25
24
  });
26
- this.slot_name_prefix = options.slot_name_prefix;
25
+ this.replicationStreamNamePrefix = options.replicationStreamNamePrefix;
27
26
  this.db.registerListener({
28
27
  connectionCreated: async (connection) => this.prepareStatements(connection)
29
28
  });
@@ -35,32 +34,34 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
35
34
  // It should be possible to prepare statements for some common operations here.
36
35
  // This has not been implemented yet.
37
36
  }
38
- getInstance(syncRules, options) {
39
- const storage = new PostgresSyncRulesStorage({
37
+ getInstance(replicationStream, options) {
38
+ const syncRuleStorage = new PostgresSyncRulesStorage({
40
39
  factory: this,
41
40
  db: this.db,
42
- sync_rules: syncRules,
43
- batchLimits: this.options.config.batch_limits
41
+ replicationStream,
42
+ batchLimits: this.options.config.batch_limits,
43
+ checksumCacheTtlMs: this.options.checksumCacheTtlMs
44
44
  });
45
45
  if (!options?.skipLifecycleHooks) {
46
- this.iterateListeners((cb) => cb.syncStorageCreated?.(storage));
46
+ this.iterateListeners((cb) => cb.syncStorageCreated?.(syncRuleStorage));
47
47
  }
48
- storage.registerListener({
48
+ syncRuleStorage.registerListener({
49
49
  batchStarted: (batch) => {
50
50
  batch.registerListener({
51
51
  replicationEvent: (payload) => this.iterateListeners((cb) => cb.replicationEvent?.(payload))
52
52
  });
53
53
  }
54
54
  });
55
- return storage;
55
+ return syncRuleStorage;
56
56
  }
57
57
  async getStorageMetrics() {
58
- const active_sync_rules = await this.getActiveSyncRules({ defaultSchema: 'public' });
59
- if (active_sync_rules == null) {
58
+ const activeSyncConfig = await this.getActiveSyncConfig();
59
+ if (activeSyncConfig == null) {
60
60
  return {
61
61
  operations_size_bytes: 0,
62
62
  parameters_size_bytes: 0,
63
- replication_size_bytes: 0
63
+ replication_size_bytes: 0,
64
+ object_storage_size_bytes: 0
64
65
  };
65
66
  }
66
67
  const sizes = await this.db.sql `
@@ -79,7 +80,8 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
79
80
  return {
80
81
  operations_size_bytes: Number(sizes.operations_size_bytes),
81
82
  parameters_size_bytes: Number(sizes.parameter_size_bytes),
82
- replication_size_bytes: Number(sizes.v1_current_size_bytes) + Number(sizes.v3_current_size_bytes)
83
+ replication_size_bytes: Number(sizes.v1_current_size_bytes) + Number(sizes.v3_current_size_bytes),
84
+ object_storage_size_bytes: 0
83
85
  };
84
86
  }
85
87
  async getPowerSyncInstanceId() {
@@ -124,10 +126,13 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
124
126
  };
125
127
  }
126
128
  async updateSyncRules(options) {
127
- const storageVersion = options.storageVersion ?? options.config.parsed.config.storageVersion ?? storage.CURRENT_STORAGE_VERSION;
129
+ const storageVersion = options.storageVersion ??
130
+ options.config.parsed.config.storageVersion ??
131
+ this.options.defaultStorageVersion ??
132
+ storage.CURRENT_STORAGE_VERSION;
128
133
  const storageConfig = storage.STORAGE_VERSION_CONFIG[storageVersion];
129
- if (storageConfig == null) {
130
- throw new framework.ServiceError(framework.ErrorCode.PSYNC_S1005, `Unsupported storage version ${storageVersion}`);
134
+ if (storageConfig == null || storageVersion >= storage.STORAGE_VERSION_4) {
135
+ throw new framework.ServiceError(framework.ErrorCode.PSYNC_S1005, `Unsupported storage version ${storageVersion} for PostgreSQL storage`);
131
136
  }
132
137
  await this.initializeStorageVersion(storageConfig);
133
138
  return this.db.transaction(async (db) => {
@@ -151,7 +156,8 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
151
156
  sync_plan,
152
157
  state,
153
158
  slot_name,
154
- storage_version
159
+ storage_version,
160
+ version_label
155
161
  )
156
162
  VALUES
157
163
  (
@@ -165,7 +171,7 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
165
171
  ${{ type: 'json', value: options.config.plan }},
166
172
  ${{ type: 'varchar', value: storage.SyncRuleState.PROCESSING }},
167
173
  CONCAT(
168
- ${{ type: 'varchar', value: this.slot_name_prefix }},
174
+ ${{ type: 'varchar', value: this.replicationStreamNamePrefix }},
169
175
  (
170
176
  SELECT
171
177
  id
@@ -175,15 +181,15 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
175
181
  '_',
176
182
  ${{ type: 'varchar', value: crypto.randomBytes(2).toString('hex') }}
177
183
  ),
178
- ${{ type: 'int4', value: storageVersion }}
184
+ ${{ type: 'int4', value: storageVersion }},
185
+ ${{ type: 'varchar', value: options.version_label ?? null }}
179
186
  )
180
187
  RETURNING
181
188
  *
182
189
  `
183
190
  .decoded(models.SyncRules)
184
191
  .first();
185
- await notifySyncRulesUpdate(this.db, newSyncRulesRow);
186
- return new PostgresPersistedSyncRulesContent(this.db, newSyncRulesRow);
192
+ return new PostgresPersistedReplicationStream(this.db, newSyncRulesRow);
187
193
  });
188
194
  }
189
195
  /**
@@ -211,38 +217,38 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
211
217
  pending_delete IS NOT NULL
212
218
  `.execute();
213
219
  }
214
- async restartReplication(sync_rules_group_id) {
215
- const next = await this.getNextSyncRulesContent();
216
- const active = await this.getActiveSyncRulesContent();
220
+ async restartReplication(replicationStreamId) {
221
+ const next = await this.getDeployingSyncConfig();
222
+ const active = await this.getActiveSyncConfig();
217
223
  // In both the below cases, we create a new replication stream.
218
224
  // The current one will continue serving sync requests until the next one has finished processing.
219
- if (next != null && next.id == sync_rules_group_id) {
225
+ if (next != null && next.content.replicationStreamId == replicationStreamId) {
220
226
  // We need to redo the "next" replication stream
221
- await this.updateSyncRules(next.asUpdateOptions());
227
+ await this.updateSyncRules(next.content.asUpdateOptions());
222
228
  // Pro-actively stop replicating
223
229
  await this.db.sql `
224
230
  UPDATE sync_rules
225
231
  SET
226
232
  state = ${{ value: storage.SyncRuleState.STOP, type: 'varchar' }}
227
233
  WHERE
228
- id = ${{ value: next.id, type: 'int4' }}
234
+ id = ${{ value: next.content.replicationStreamId, type: 'int4' }}
229
235
  AND state = ${{ value: storage.SyncRuleState.PROCESSING, type: 'varchar' }}
230
236
  `.execute();
231
237
  }
232
- else if (next == null && active?.id == sync_rules_group_id) {
238
+ else if (next == null && active?.content.replicationStreamId == replicationStreamId) {
233
239
  // Slot removed for "active" replication stream, while there is no "next" one.
234
- await this.updateSyncRules(active.asUpdateOptions());
240
+ await this.updateSyncRules(active.content.asUpdateOptions());
235
241
  // Pro-actively stop replicating, but still serve clients with existing data
236
242
  await this.db.sql `
237
243
  UPDATE sync_rules
238
244
  SET
239
245
  state = ${{ value: storage.SyncRuleState.ERRORED, type: 'varchar' }}
240
246
  WHERE
241
- id = ${{ value: active.id, type: 'int4' }}
247
+ id = ${{ value: active.content.replicationStreamId, type: 'int4' }}
242
248
  AND state = ${{ value: storage.SyncRuleState.ACTIVE, type: 'varchar' }}
243
249
  `.execute();
244
250
  }
245
- else if (next != null && active?.id == sync_rules_group_id) {
251
+ else if (next != null && active?.content.replicationStreamId == replicationStreamId) {
246
252
  // Already have "next" replication stream - don't update any.
247
253
  // Pro-actively stop replicating, but still serve clients with existing data
248
254
  await this.db.sql `
@@ -250,12 +256,12 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
250
256
  SET
251
257
  state = ${{ value: storage.SyncRuleState.ERRORED, type: 'varchar' }}
252
258
  WHERE
253
- id = ${{ value: active.id, type: 'int4' }}
259
+ id = ${{ value: active.content.replicationStreamId, type: 'int4' }}
254
260
  AND state = ${{ value: storage.SyncRuleState.ACTIVE, type: 'varchar' }}
255
261
  `.execute();
256
262
  }
257
263
  }
258
- async getActiveSyncRulesContent() {
264
+ async getActiveSyncConfig() {
259
265
  const activeRow = await this.db.sql `
260
266
  SELECT
261
267
  *
@@ -274,10 +280,10 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
274
280
  if (!activeRow) {
275
281
  return null;
276
282
  }
277
- return new PostgresPersistedSyncRulesContent(this.db, activeRow);
283
+ return this.resolvedSyncConfigFromRow(activeRow, { cacheActiveStorage: true });
278
284
  }
279
- async getNextSyncRulesContent() {
280
- const nextRow = await this.db.sql `
285
+ async getDeployingSyncConfig() {
286
+ const row = await this.db.sql `
281
287
  SELECT
282
288
  *
283
289
  FROM
@@ -291,12 +297,9 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
291
297
  `
292
298
  .decoded(models.SyncRules)
293
299
  .first();
294
- if (!nextRow) {
295
- return null;
296
- }
297
- return new PostgresPersistedSyncRulesContent(this.db, nextRow);
300
+ return row == null ? null : this.resolvedSyncConfigFromRow(row);
298
301
  }
299
- async getReplicatingSyncRules() {
302
+ async getReplicatingReplicationStreams() {
300
303
  const rows = await this.db.sql `
301
304
  SELECT
302
305
  *
@@ -308,9 +311,9 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
308
311
  `
309
312
  .decoded(models.SyncRules)
310
313
  .rows();
311
- return rows.map((row) => new PostgresPersistedSyncRulesContent(this.db, row));
314
+ return rows.map((row) => new PostgresPersistedReplicationStream(this.db, row));
312
315
  }
313
- async getStoppedSyncRules() {
316
+ async getStoppedReplicationStreams() {
314
317
  const rows = await this.db.sql `
315
318
  SELECT
316
319
  *
@@ -321,24 +324,32 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
321
324
  `
322
325
  .decoded(models.SyncRules)
323
326
  .rows();
324
- return rows.map((row) => new PostgresPersistedSyncRulesContent(this.db, row));
327
+ return rows.map((row) => new PostgresPersistedReplicationStream(this.db, row));
325
328
  }
326
- async getActiveStorage() {
327
- const content = await this.getActiveSyncRulesContent();
328
- if (content == null) {
329
- return null;
330
- }
331
- // It is important that this instance is cached.
332
- // Not for the instance construction itself, but to ensure that internal caches on the instance
333
- // are re-used properly.
334
- if (this.activeStorageCache?.group_id == content.id) {
335
- return this.activeStorageCache;
336
- }
337
- else {
338
- const instance = this.getInstance(content);
339
- this.activeStorageCache = instance;
340
- return instance;
341
- }
329
+ resolvedSyncConfigFromRow(row, options = {}) {
330
+ const stream = new PostgresPersistedReplicationStream(this.db, row);
331
+ const content = stream.syncConfigContent[0];
332
+ const thisFactory = this;
333
+ return {
334
+ content,
335
+ replicationStream: stream,
336
+ get storage() {
337
+ // It is important that this instance is cached.
338
+ // Not for the instance construction itself, but to ensure that internal caches on the instance
339
+ // are re-used properly.
340
+ if (options.cacheActiveStorage) {
341
+ const activeStorageCache = thisFactory.activeStorageCache;
342
+ if (activeStorageCache?.replicationStreamId == stream.replicationStreamId) {
343
+ return activeStorageCache;
344
+ }
345
+ }
346
+ const instance = thisFactory.getInstance(stream);
347
+ if (options.cacheActiveStorage) {
348
+ thisFactory.activeStorageCache = instance;
349
+ }
350
+ return instance;
351
+ }
352
+ };
342
353
  }
343
354
  }
344
355
  //# sourceMappingURL=PostgresBucketStorageFactory.js.map