@powersync/service-module-postgres 0.0.0-dev-20260225160713 → 0.0.0-dev-20260511080634

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 (84) hide show
  1. package/dist/api/PostgresRouteAPIAdapter.d.ts +1 -1
  2. package/dist/api/PostgresRouteAPIAdapter.js +63 -72
  3. package/dist/api/PostgresRouteAPIAdapter.js.map +1 -1
  4. package/dist/module/PostgresModule.js.map +1 -1
  5. package/dist/replication/MissingReplicationSlotError.d.ts +41 -0
  6. package/dist/replication/MissingReplicationSlotError.js +33 -0
  7. package/dist/replication/MissingReplicationSlotError.js.map +1 -0
  8. package/dist/replication/PgManager.js +3 -2
  9. package/dist/replication/PgManager.js.map +1 -1
  10. package/dist/replication/PostgresErrorRateLimiter.js +1 -1
  11. package/dist/replication/PostgresErrorRateLimiter.js.map +1 -1
  12. package/dist/replication/SnapshotQuery.js +8 -7
  13. package/dist/replication/SnapshotQuery.js.map +1 -1
  14. package/dist/replication/WalStream.d.ts +46 -16
  15. package/dist/replication/WalStream.js +203 -69
  16. package/dist/replication/WalStream.js.map +1 -1
  17. package/dist/replication/WalStreamReplicationJob.d.ts +1 -1
  18. package/dist/replication/WalStreamReplicationJob.js +9 -6
  19. package/dist/replication/WalStreamReplicationJob.js.map +1 -1
  20. package/dist/replication/WalStreamReplicator.d.ts +0 -1
  21. package/dist/replication/WalStreamReplicator.js +0 -22
  22. package/dist/replication/WalStreamReplicator.js.map +1 -1
  23. package/dist/replication/replication-index.d.ts +3 -1
  24. package/dist/replication/replication-index.js +3 -1
  25. package/dist/replication/replication-index.js.map +1 -1
  26. package/dist/replication/replication-utils.d.ts +3 -11
  27. package/dist/replication/replication-utils.js +103 -165
  28. package/dist/replication/replication-utils.js.map +1 -1
  29. package/dist/replication/rquery.d.ts +5 -0
  30. package/dist/replication/rquery.js +35 -0
  31. package/dist/replication/rquery.js.map +1 -0
  32. package/dist/replication/wal-budget-utils.d.ts +23 -0
  33. package/dist/replication/wal-budget-utils.js +57 -0
  34. package/dist/replication/wal-budget-utils.js.map +1 -0
  35. package/dist/types/registry.js +1 -1
  36. package/dist/types/registry.js.map +1 -1
  37. package/dist/utils/errors.d.ts +2 -0
  38. package/dist/utils/errors.js +30 -0
  39. package/dist/utils/errors.js.map +1 -0
  40. package/package.json +17 -13
  41. package/sql/check-source-configuration.plpgsql +13 -0
  42. package/sql/debug-tables-info-batched.plpgsql +230 -0
  43. package/CHANGELOG.md +0 -794
  44. package/src/api/PostgresRouteAPIAdapter.ts +0 -356
  45. package/src/index.ts +0 -1
  46. package/src/module/PostgresModule.ts +0 -122
  47. package/src/replication/ConnectionManagerFactory.ts +0 -33
  48. package/src/replication/PgManager.ts +0 -122
  49. package/src/replication/PgRelation.ts +0 -41
  50. package/src/replication/PostgresErrorRateLimiter.ts +0 -48
  51. package/src/replication/SnapshotQuery.ts +0 -213
  52. package/src/replication/WalStream.ts +0 -1138
  53. package/src/replication/WalStreamReplicationJob.ts +0 -138
  54. package/src/replication/WalStreamReplicator.ts +0 -79
  55. package/src/replication/replication-index.ts +0 -5
  56. package/src/replication/replication-utils.ts +0 -398
  57. package/src/types/registry.ts +0 -275
  58. package/src/types/resolver.ts +0 -227
  59. package/src/types/types.ts +0 -44
  60. package/src/utils/application-name.ts +0 -8
  61. package/src/utils/migration_lib.ts +0 -80
  62. package/src/utils/populate_test_data.ts +0 -37
  63. package/src/utils/populate_test_data_worker.ts +0 -53
  64. package/src/utils/postgres_version.ts +0 -8
  65. package/test/src/checkpoints.test.ts +0 -88
  66. package/test/src/chunked_snapshots.test.ts +0 -160
  67. package/test/src/env.ts +0 -11
  68. package/test/src/large_batch.test.ts +0 -239
  69. package/test/src/pg_test.test.ts +0 -729
  70. package/test/src/resuming_snapshots.test.ts +0 -163
  71. package/test/src/route_api_adapter.test.ts +0 -62
  72. package/test/src/schema_changes.test.ts +0 -675
  73. package/test/src/setup.ts +0 -12
  74. package/test/src/slow_tests.test.ts +0 -412
  75. package/test/src/storage_combination.test.ts +0 -35
  76. package/test/src/types/registry.test.ts +0 -149
  77. package/test/src/util.ts +0 -145
  78. package/test/src/validation.test.ts +0 -63
  79. package/test/src/wal_stream.test.ts +0 -618
  80. package/test/src/wal_stream_utils.ts +0 -292
  81. package/test/tsconfig.json +0 -27
  82. package/tsconfig.json +0 -34
  83. package/tsconfig.tsbuildinfo +0 -1
  84. package/vitest.config.ts +0 -3
package/test/src/util.ts DELETED
@@ -1,145 +0,0 @@
1
- import { PostgresRouteAPIAdapter } from '@module/api/PostgresRouteAPIAdapter.js';
2
- import * as types from '@module/types/types.js';
3
- import * as lib_postgres from '@powersync/lib-service-postgres';
4
- import { logger } from '@powersync/lib-services-framework';
5
- import {
6
- BucketStorageFactory,
7
- CURRENT_STORAGE_VERSION,
8
- InternalOpId,
9
- LEGACY_STORAGE_VERSION,
10
- TestStorageFactory
11
- } from '@powersync/service-core';
12
- import * as pgwire from '@powersync/service-jpgwire';
13
- import * as mongo_storage from '@powersync/service-module-mongodb-storage';
14
- import * as postgres_storage from '@powersync/service-module-postgres-storage';
15
- import { describe, TestOptions } from 'vitest';
16
- import { env } from './env.js';
17
-
18
- export const TEST_URI = env.PG_TEST_URL;
19
-
20
- export const INITIALIZED_MONGO_STORAGE_FACTORY = mongo_storage.test_utils.mongoTestStorageFactoryGenerator({
21
- url: env.MONGO_TEST_URL,
22
- isCI: env.CI
23
- });
24
-
25
- export const INITIALIZED_POSTGRES_STORAGE_FACTORY = postgres_storage.test_utils.postgresTestStorageFactoryGenerator({
26
- url: env.PG_STORAGE_TEST_URL
27
- });
28
-
29
- const TEST_STORAGE_VERSIONS = [LEGACY_STORAGE_VERSION, CURRENT_STORAGE_VERSION];
30
-
31
- export interface StorageVersionTestContext {
32
- factory: TestStorageFactory;
33
- storageVersion: number;
34
- }
35
-
36
- export function describeWithStorage(options: TestOptions, fn: (context: StorageVersionTestContext) => void) {
37
- const describeFactory = (storageName: string, factory: TestStorageFactory) => {
38
- describe(`${storageName} storage`, options, function () {
39
- for (const storageVersion of TEST_STORAGE_VERSIONS) {
40
- describe(`storage v${storageVersion}`, function () {
41
- fn({
42
- factory,
43
- storageVersion
44
- });
45
- });
46
- }
47
- });
48
- };
49
-
50
- if (env.TEST_MONGO_STORAGE) {
51
- describeFactory('mongodb', INITIALIZED_MONGO_STORAGE_FACTORY);
52
- }
53
-
54
- if (env.TEST_POSTGRES_STORAGE) {
55
- describeFactory('postgres', INITIALIZED_POSTGRES_STORAGE_FACTORY);
56
- }
57
- }
58
-
59
- export const TEST_CONNECTION_OPTIONS = types.normalizeConnectionConfig({
60
- type: 'postgresql',
61
- uri: TEST_URI,
62
- sslmode: 'disable'
63
- });
64
-
65
- export async function clearTestDb(db: pgwire.PgClient) {
66
- await db.query(
67
- "select pg_drop_replication_slot(slot_name) from pg_replication_slots where active = false and slot_name like 'test_%'"
68
- );
69
-
70
- await db.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
71
- try {
72
- await db.query(`DROP PUBLICATION powersync`);
73
- } catch (e) {
74
- // Ignore
75
- }
76
-
77
- await db.query(`CREATE PUBLICATION powersync FOR ALL TABLES`);
78
-
79
- const tableRows = pgwire.pgwireRows(
80
- await db.query(`SELECT table_name FROM information_schema.tables where table_schema = 'public'`)
81
- );
82
- for (let row of tableRows) {
83
- const name = row.table_name;
84
- if (name.startsWith('test_')) {
85
- await db.query(`DROP TABLE public.${lib_postgres.escapeIdentifier(name)}`);
86
- }
87
- }
88
-
89
- const domainRows = pgwire.pgwireRows(
90
- await db.query(`
91
- SELECT typname,typtype
92
- FROM pg_type t
93
- LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
94
- WHERE n.nspname = 'public' AND typarray != 0
95
- `)
96
- );
97
- for (let row of domainRows) {
98
- if (row.typtype == 'd') {
99
- await db.query(`DROP DOMAIN public.${lib_postgres.escapeIdentifier(row.typname)} CASCADE`);
100
- } else {
101
- await db.query(`DROP TYPE public.${lib_postgres.escapeIdentifier(row.typname)} CASCADE`);
102
- }
103
- }
104
- }
105
-
106
- export async function connectPgWire(type?: 'replication' | 'standard') {
107
- const db = await pgwire.connectPgWire(TEST_CONNECTION_OPTIONS, { type, applicationName: 'powersync-tests' });
108
- return db;
109
- }
110
-
111
- export function connectPgPool() {
112
- const db = pgwire.connectPgWirePool(TEST_CONNECTION_OPTIONS);
113
- return db;
114
- }
115
-
116
- export async function getClientCheckpoint(
117
- db: pgwire.PgClient,
118
- storageFactory: BucketStorageFactory,
119
- options?: { timeout?: number }
120
- ): Promise<InternalOpId> {
121
- const start = Date.now();
122
-
123
- const api = new PostgresRouteAPIAdapter(db);
124
- const lsn = await api.createReplicationHead(async (lsn) => lsn);
125
-
126
- // This old API needs a persisted checkpoint id.
127
- // Since we don't use LSNs anymore, the only way to get that is to wait.
128
-
129
- const timeout = options?.timeout ?? 50_000;
130
-
131
- logger.info(`Waiting for LSN checkpoint: ${lsn}`);
132
- while (Date.now() - start < timeout) {
133
- const storage = await storageFactory.getActiveStorage();
134
- const cp = await storage?.getCheckpoint();
135
-
136
- if (cp?.lsn != null && cp.lsn >= lsn) {
137
- logger.info(`Got write checkpoint: ${lsn} : ${cp.checkpoint}`);
138
- return cp.checkpoint;
139
- }
140
-
141
- await new Promise((resolve) => setTimeout(resolve, 30));
142
- }
143
-
144
- throw new Error('Timeout while waiting for checkpoint');
145
- }
@@ -1,63 +0,0 @@
1
- import { getDebugTablesInfo } from '@module/replication/replication-utils.js';
2
- import { expect, test } from 'vitest';
3
-
4
- import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
5
- import { WalStreamTestContext } from './wal_stream_utils.js';
6
- import { updateSyncRulesFromYaml } from '@powersync/service-core';
7
-
8
- test('validate tables', async () => {
9
- await using context = await WalStreamTestContext.open(INITIALIZED_MONGO_STORAGE_FACTORY);
10
- const { pool } = context;
11
-
12
- await pool.query(`CREATE TABLE test_data(id uuid primary key default uuid_generate_v4(), description text)`);
13
-
14
- const syncRuleContent = `
15
- bucket_definitions:
16
- global:
17
- data:
18
- - SELECT id, description FROM "test_data"
19
- - SELECT * FROM "other"
20
- - SELECT * FROM "other%"
21
- `;
22
-
23
- const syncRules = await context.factory.updateSyncRules(updateSyncRulesFromYaml(syncRuleContent));
24
-
25
- const tablePatterns = syncRules.parsed({ defaultSchema: 'public' }).sync_rules.config.getSourceTables();
26
- const tableInfo = await getDebugTablesInfo({
27
- db: pool,
28
- publicationName: context.publicationName,
29
- connectionTag: context.connectionTag,
30
- tablePatterns: tablePatterns,
31
- syncRules: syncRules.parsed({ defaultSchema: 'public' }).sync_rules.config
32
- });
33
- expect(tableInfo).toEqual([
34
- {
35
- schema: 'public',
36
- pattern: 'test_data',
37
- wildcard: false,
38
- table: {
39
- schema: 'public',
40
- name: 'test_data',
41
- replication_id: ['id'],
42
- pattern: undefined,
43
- data_queries: true,
44
- parameter_queries: false,
45
- errors: []
46
- }
47
- },
48
- {
49
- schema: 'public',
50
- pattern: 'other',
51
- wildcard: false,
52
- table: {
53
- schema: 'public',
54
- name: 'other',
55
- replication_id: [],
56
- data_queries: true,
57
- parameter_queries: false,
58
- errors: [{ level: 'warning', message: 'Table "public"."other" not found.' }]
59
- }
60
- },
61
- { schema: 'public', pattern: 'other%', wildcard: true, tables: [] }
62
- ]);
63
- });