@powersync/service-module-postgres-storage 0.0.0-dev-20260803144812 → 0.0.0-dev-20260929095716
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/CHANGELOG.md +125 -8
- package/dist/migrations/scripts/1784900000000-source-metadata.d.ts +3 -0
- package/dist/migrations/scripts/1784900000000-source-metadata.js +22 -0
- package/dist/migrations/scripts/1784900000000-source-metadata.js.map +1 -0
- package/dist/migrations/scripts/1788000000000-sync-config-version-label.d.ts +3 -0
- package/dist/migrations/scripts/1788000000000-sync-config-version-label.js +12 -0
- package/dist/migrations/scripts/1788000000000-sync-config-version-label.js.map +1 -0
- package/dist/storage/PostgresBucketStorageFactory.d.ts +2 -1
- package/dist/storage/PostgresBucketStorageFactory.js +27 -14
- package/dist/storage/PostgresBucketStorageFactory.js.map +1 -1
- package/dist/storage/PostgresStorageProvider.js +3 -2
- package/dist/storage/PostgresStorageProvider.js.map +1 -1
- package/dist/storage/PostgresSyncRulesStorage.d.ts +4 -3
- package/dist/storage/PostgresSyncRulesStorage.js +17 -5
- package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
- package/dist/storage/batch/PostgresBucketBatch.d.ts +2 -2
- package/dist/storage/batch/PostgresBucketBatch.js +63 -94
- package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
- package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.d.ts +1 -1
- package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.js +2 -2
- package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/sync-rules/PostgresPersistedSyncConfigContent.d.ts +3 -2
- package/dist/storage/sync-rules/PostgresPersistedSyncConfigContent.js +12 -5
- package/dist/storage/sync-rules/PostgresPersistedSyncConfigContent.js.map +1 -1
- package/dist/types/models/ActiveCheckpoint.d.ts +2 -2
- package/dist/types/models/ActiveCheckpoint.js +3 -2
- package/dist/types/models/ActiveCheckpoint.js.map +1 -1
- package/dist/types/models/ActiveCheckpointNotification.d.ts +2 -2
- package/dist/types/models/BucketData.d.ts +6 -6
- package/dist/types/models/BucketData.js +7 -6
- package/dist/types/models/BucketData.js.map +1 -1
- package/dist/types/models/CurrentData.d.ts +1 -1
- package/dist/types/models/CurrentData.js +2 -1
- package/dist/types/models/CurrentData.js.map +1 -1
- package/dist/types/models/SdkReporting.d.ts +3 -3
- package/dist/types/models/SdkReporting.js +3 -5
- package/dist/types/models/SdkReporting.js.map +1 -1
- package/dist/types/models/SourceTable.d.ts +13 -8
- package/dist/types/models/SourceTable.js +11 -6
- package/dist/types/models/SourceTable.js.map +1 -1
- package/dist/types/models/SyncRules.d.ts +11 -10
- package/dist/types/models/SyncRules.js +12 -11
- package/dist/types/models/SyncRules.js.map +1 -1
- package/dist/types/models/WriteCheckpoint.d.ts +2 -2
- package/dist/types/models/WriteCheckpoint.js +3 -2
- package/dist/types/models/WriteCheckpoint.js.map +1 -1
- package/dist/types/types.d.ts +2 -0
- package/dist/utils/test-utils.d.ts +2 -1
- package/dist/utils/test-utils.js +3 -3
- package/dist/utils/test-utils.js.map +1 -1
- package/package.json +8 -8
- package/src/migrations/scripts/1784900000000-source-metadata.ts +31 -0
- package/src/migrations/scripts/1788000000000-sync-config-version-label.ts +18 -0
- package/src/storage/PostgresBucketStorageFactory.ts +30 -14
- package/src/storage/PostgresStorageProvider.ts +9 -5
- package/src/storage/PostgresSyncRulesStorage.ts +21 -6
- package/src/storage/batch/PostgresBucketBatch.ts +67 -98
- package/src/storage/checkpoints/PostgresWriteCheckpointAPI.ts +2 -2
- package/src/storage/sync-rules/PostgresPersistedSyncConfigContent.ts +24 -11
- package/src/types/models/ActiveCheckpoint.ts +3 -2
- package/src/types/models/BucketData.ts +7 -6
- package/src/types/models/CurrentData.ts +2 -1
- package/src/types/models/SdkReporting.ts +4 -4
- package/src/types/models/SourceTable.ts +12 -6
- package/src/types/models/SyncRules.ts +12 -11
- package/src/types/models/WriteCheckpoint.ts +3 -2
- package/src/utils/test-utils.ts +23 -9
- package/test/src/__snapshots__/storage_sync.test.ts.snap +0 -995
- package/test/src/checkpoint_notifications.test.ts +8 -2
- package/test/src/migrations.test.ts +8 -4
- package/test/src/storage.test.ts +12 -4
- package/test/src/storage_compacting.test.ts +2 -2
- package/test/src/storage_sync.test.ts +44 -0
- package/test/src/util.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { JsonValue } from '@powersync/service-core';
|
|
2
|
+
import { orNull } from '@powersync/service-types';
|
|
1
3
|
import * as t from 'ts-codec';
|
|
2
4
|
import { bigint, hexBuffer, jsonb, jsonb_raw, pgwire_number } from '../codecs.js';
|
|
3
5
|
|
|
@@ -14,21 +16,25 @@ export const ColumnDescriptor = t.object({
|
|
|
14
16
|
/**
|
|
15
17
|
* Some data sources have a type id that can be used to identify the type of the column
|
|
16
18
|
*/
|
|
17
|
-
|
|
19
|
+
type_oid: t.number.optional()
|
|
18
20
|
});
|
|
19
21
|
|
|
20
22
|
export const SourceTable = t.object({
|
|
21
23
|
id: t.string,
|
|
22
24
|
group_id: pgwire_number,
|
|
23
25
|
connection_id: bigint,
|
|
24
|
-
relation_id:
|
|
26
|
+
relation_id: orNull(jsonb_raw<StoredRelationId>()),
|
|
25
27
|
schema_name: t.string,
|
|
26
28
|
table_name: t.string,
|
|
27
|
-
replica_id_columns:
|
|
29
|
+
replica_id_columns: orNull(jsonb(t.array(ColumnDescriptor))),
|
|
28
30
|
snapshot_done: t.boolean,
|
|
29
|
-
snapshot_total_estimated_count:
|
|
30
|
-
snapshot_replicated_count:
|
|
31
|
-
snapshot_last_key:
|
|
31
|
+
snapshot_total_estimated_count: orNull(bigint),
|
|
32
|
+
snapshot_replicated_count: orNull(bigint),
|
|
33
|
+
snapshot_last_key: orNull(hexBuffer),
|
|
34
|
+
/**
|
|
35
|
+
* Source-specific metadata. Null for legacy records.
|
|
36
|
+
*/
|
|
37
|
+
source_metadata: orNull(jsonb_raw<JsonValue>())
|
|
32
38
|
});
|
|
33
39
|
|
|
34
40
|
export type SourceTable = t.Encoded<typeof SourceTable>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { framework, storage } from '@powersync/service-core';
|
|
2
|
-
import { ReplicationError } from '@powersync/service-types';
|
|
2
|
+
import { orNull, ReplicationError } from '@powersync/service-types';
|
|
3
3
|
import * as t from 'ts-codec';
|
|
4
4
|
import { bigint, pgwire_number } from '../codecs.js';
|
|
5
5
|
import { jsonContainerObject } from './json.js';
|
|
@@ -16,42 +16,43 @@ export const SyncRules = t.object({
|
|
|
16
16
|
/**
|
|
17
17
|
* May be set if snapshot_done = false, if the replication stream requires it.
|
|
18
18
|
*/
|
|
19
|
-
snapshot_lsn:
|
|
19
|
+
snapshot_lsn: orNull(t.string),
|
|
20
20
|
/**
|
|
21
21
|
* The last consistent checkpoint.
|
|
22
22
|
*
|
|
23
23
|
* There may be higher OpIds used in the database if we're in the middle of replicating a large transaction.
|
|
24
24
|
*/
|
|
25
|
-
last_checkpoint:
|
|
25
|
+
last_checkpoint: orNull(bigint),
|
|
26
26
|
/**
|
|
27
27
|
* The LSN associated with the last consistent checkpoint.
|
|
28
28
|
*/
|
|
29
|
-
last_checkpoint_lsn:
|
|
29
|
+
last_checkpoint_lsn: orNull(t.string),
|
|
30
30
|
/**
|
|
31
31
|
* If set, no new checkpoints may be created < this value.
|
|
32
32
|
*/
|
|
33
|
-
no_checkpoint_before:
|
|
33
|
+
no_checkpoint_before: orNull(t.string),
|
|
34
34
|
slot_name: t.string,
|
|
35
35
|
/**
|
|
36
36
|
* Last time we persisted a checkpoint.
|
|
37
37
|
*
|
|
38
38
|
* This may be old if no data is incoming.
|
|
39
39
|
*/
|
|
40
|
-
last_checkpoint_ts:
|
|
40
|
+
last_checkpoint_ts: orNull(framework.codecs.date),
|
|
41
41
|
/**
|
|
42
42
|
* Last time we persisted a checkpoint or keepalive.
|
|
43
43
|
*
|
|
44
44
|
* This should stay fairly current while replicating.
|
|
45
45
|
*/
|
|
46
|
-
last_keepalive_ts:
|
|
46
|
+
last_keepalive_ts: orNull(framework.codecs.date),
|
|
47
47
|
/**
|
|
48
48
|
* If an error is stopping replication, it will be stored here.
|
|
49
49
|
*/
|
|
50
|
-
last_fatal_error:
|
|
51
|
-
keepalive_op:
|
|
52
|
-
storage_version:
|
|
50
|
+
last_fatal_error: orNull(t.string),
|
|
51
|
+
keepalive_op: orNull(bigint),
|
|
52
|
+
storage_version: orNull(pgwire_number).optional(),
|
|
53
|
+
version_label: orNull(t.string).optional(),
|
|
53
54
|
content: t.string,
|
|
54
|
-
sync_plan:
|
|
55
|
+
sync_plan: orNull(
|
|
55
56
|
jsonContainerObject(
|
|
56
57
|
t.object({
|
|
57
58
|
plan: t.any,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { framework } from '@powersync/service-core';
|
|
2
|
+
import { orNull } from '@powersync/service-types';
|
|
2
3
|
import * as t from 'ts-codec';
|
|
3
4
|
import { bigint, jsonb } from '../codecs.js';
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ export const WriteCheckpoint = t.object({
|
|
|
6
7
|
user_id: t.string,
|
|
7
8
|
lsns: jsonb(t.record(t.string)),
|
|
8
9
|
write_checkpoint: bigint,
|
|
9
|
-
checkpoint_requested_at:
|
|
10
|
+
checkpoint_requested_at: orNull(framework.codecs.date)
|
|
10
11
|
});
|
|
11
12
|
|
|
12
13
|
export type WriteCheckpoint = t.Encoded<typeof WriteCheckpoint>;
|
|
@@ -16,7 +17,7 @@ export const CustomWriteCheckpoint = t.object({
|
|
|
16
17
|
user_id: t.string,
|
|
17
18
|
write_checkpoint: bigint,
|
|
18
19
|
sync_rules_id: bigint,
|
|
19
|
-
checkpoint_requested_at:
|
|
20
|
+
checkpoint_requested_at: orNull(framework.codecs.date)
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
export type CustomWriteCheckpoint = t.Encoded<typeof CustomWriteCheckpoint>;
|
package/src/utils/test-utils.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { createLogger, logger as defaultLogger, transports } from '@powersync/lib-services-framework';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
framework,
|
|
4
|
+
PowerSyncMigrationManager,
|
|
5
|
+
ServiceContext,
|
|
6
|
+
SqlSyncConfigParser,
|
|
7
|
+
SyncConfigParser,
|
|
8
|
+
TestStorageOptions
|
|
9
|
+
} from '@powersync/service-core';
|
|
3
10
|
import { PostgresMigrationAgent } from '../migrations/PostgresMigrationAgent.js';
|
|
4
11
|
import { PostgresBucketStorageFactory } from '../storage/PostgresBucketStorageFactory.js';
|
|
5
12
|
import { PostgresReportStorage } from '../storage/PostgresReportStorage.js';
|
|
@@ -8,6 +15,7 @@ import { truncateTables } from './db.js';
|
|
|
8
15
|
|
|
9
16
|
export type PostgresTestStorageOptions = {
|
|
10
17
|
url: string;
|
|
18
|
+
syncConfigParser?: SyncConfigParser;
|
|
11
19
|
/**
|
|
12
20
|
* Vitest can cause issues when loading .ts files for migrations.
|
|
13
21
|
* This allows for providing a custom PostgresMigrationAgent.
|
|
@@ -71,10 +79,13 @@ export function postgresTestSetup(factoryOptions: PostgresTestStorageOptions) {
|
|
|
71
79
|
const clearStorage = async () => {
|
|
72
80
|
await runMigrations({ down: false, up: true });
|
|
73
81
|
|
|
74
|
-
await using storageFactory = new PostgresBucketStorageFactory(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
await using storageFactory = new PostgresBucketStorageFactory(
|
|
83
|
+
{
|
|
84
|
+
config: TEST_CONNECTION_OPTIONS,
|
|
85
|
+
replicationStreamNamePrefix: 'test_'
|
|
86
|
+
},
|
|
87
|
+
factoryOptions.syncConfigParser ?? new SqlSyncConfigParser()
|
|
88
|
+
);
|
|
78
89
|
await truncateTables(storageFactory.db);
|
|
79
90
|
};
|
|
80
91
|
|
|
@@ -100,10 +111,13 @@ export function postgresTestSetup(factoryOptions: PostgresTestStorageOptions) {
|
|
|
100
111
|
await clearStorage();
|
|
101
112
|
}
|
|
102
113
|
|
|
103
|
-
return new PostgresBucketStorageFactory(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
return new PostgresBucketStorageFactory(
|
|
115
|
+
{
|
|
116
|
+
config: TEST_CONNECTION_OPTIONS,
|
|
117
|
+
replicationStreamNamePrefix: 'test_'
|
|
118
|
+
},
|
|
119
|
+
factoryOptions.syncConfigParser ?? new SqlSyncConfigParser()
|
|
120
|
+
);
|
|
107
121
|
} catch (ex) {
|
|
108
122
|
// Vitest does not display these errors nicely when using the `await using` syntx
|
|
109
123
|
console.error(ex, ex.cause);
|