@powersync/service-module-postgres 0.16.1 → 0.16.3
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 +21 -0
- package/dist/api/PostgresRouteAPIAdapter.d.ts +1 -0
- package/dist/api/PostgresRouteAPIAdapter.js +8 -1
- package/dist/api/PostgresRouteAPIAdapter.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/module/PostgresModule.d.ts +1 -0
- package/dist/module/PostgresModule.js +9 -4
- package/dist/module/PostgresModule.js.map +1 -1
- package/dist/replication/ConnectionManagerFactory.d.ts +3 -1
- package/dist/replication/ConnectionManagerFactory.js +4 -2
- package/dist/replication/ConnectionManagerFactory.js.map +1 -1
- package/dist/replication/PgManager.d.ts +8 -2
- package/dist/replication/PgManager.js +5 -4
- package/dist/replication/PgManager.js.map +1 -1
- package/dist/replication/PgRelation.d.ts +1 -0
- package/dist/replication/PgRelation.js +7 -0
- package/dist/replication/PgRelation.js.map +1 -1
- package/dist/replication/WalStream.d.ts +6 -1
- package/dist/replication/WalStream.js +45 -33
- package/dist/replication/WalStream.js.map +1 -1
- package/dist/types/registry.d.ts +69 -0
- package/dist/types/registry.js +196 -0
- package/dist/types/registry.js.map +1 -0
- package/dist/types/resolver.d.ts +47 -0
- package/dist/types/resolver.js +191 -0
- package/dist/types/resolver.js.map +1 -0
- package/dist/types/types.d.ts +4 -1
- package/dist/types/types.js.map +1 -1
- package/dist/utils/postgres_version.d.ts +3 -0
- package/dist/utils/postgres_version.js +7 -0
- package/dist/utils/postgres_version.js.map +1 -0
- package/package.json +10 -10
- package/src/api/PostgresRouteAPIAdapter.ts +9 -1
- package/src/index.ts +0 -2
- package/src/module/PostgresModule.ts +10 -4
- package/src/replication/ConnectionManagerFactory.ts +6 -2
- package/src/replication/PgManager.ts +12 -4
- package/src/replication/PgRelation.ts +9 -0
- package/src/replication/WalStream.ts +49 -30
- package/src/types/registry.ts +278 -0
- package/src/types/resolver.ts +210 -0
- package/src/types/types.ts +5 -1
- package/src/utils/postgres_version.ts +8 -0
- package/test/src/checkpoints.test.ts +4 -2
- package/test/src/pg_test.test.ts +152 -5
- package/test/src/route_api_adapter.test.ts +60 -0
- package/test/src/schema_changes.test.ts +32 -0
- package/test/src/slow_tests.test.ts +3 -2
- package/test/src/types/registry.test.ts +149 -0
- package/test/src/util.ts +16 -0
- package/test/src/wal_stream.test.ts +24 -0
- package/test/src/wal_stream_utils.ts +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/pgwire_utils.d.ts +0 -17
- package/dist/utils/pgwire_utils.js +0 -43
- package/dist/utils/pgwire_utils.js.map +0 -1
- package/src/utils/pgwire_utils.ts +0 -48
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as pgwire from '@powersync/service-jpgwire';
|
|
2
|
-
import { DatabaseInputRow, SqliteInputRow } from '@powersync/service-sync-rules';
|
|
3
|
-
/**
|
|
4
|
-
* pgwire message -> SQLite row.
|
|
5
|
-
* @param message
|
|
6
|
-
*/
|
|
7
|
-
export declare function constructAfterRecord(message: pgwire.PgoutputInsert | pgwire.PgoutputUpdate): SqliteInputRow;
|
|
8
|
-
/**
|
|
9
|
-
* pgwire message -> SQLite row.
|
|
10
|
-
* @param message
|
|
11
|
-
*/
|
|
12
|
-
export declare function constructBeforeRecord(message: pgwire.PgoutputDelete | pgwire.PgoutputUpdate): SqliteInputRow | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* We need a high level of control over how values are decoded, to make sure there is no loss
|
|
15
|
-
* of precision in the process.
|
|
16
|
-
*/
|
|
17
|
-
export declare function decodeTuple(relation: pgwire.PgoutputRelation, tupleRaw: Record<string, any>): DatabaseInputRow;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Adapted from https://github.com/kagis/pgwire/blob/0dc927f9f8990a903f238737326e53ba1c8d094f/mod.js#L2218
|
|
2
|
-
import * as pgwire from '@powersync/service-jpgwire';
|
|
3
|
-
import { toSyncRulesRow } from '@powersync/service-sync-rules';
|
|
4
|
-
/**
|
|
5
|
-
* pgwire message -> SQLite row.
|
|
6
|
-
* @param message
|
|
7
|
-
*/
|
|
8
|
-
export function constructAfterRecord(message) {
|
|
9
|
-
const rawData = message.afterRaw;
|
|
10
|
-
const record = decodeTuple(message.relation, rawData);
|
|
11
|
-
return toSyncRulesRow(record);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* pgwire message -> SQLite row.
|
|
15
|
-
* @param message
|
|
16
|
-
*/
|
|
17
|
-
export function constructBeforeRecord(message) {
|
|
18
|
-
const rawData = message.beforeRaw;
|
|
19
|
-
if (rawData == null) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
const record = decodeTuple(message.relation, rawData);
|
|
23
|
-
return toSyncRulesRow(record);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* We need a high level of control over how values are decoded, to make sure there is no loss
|
|
27
|
-
* of precision in the process.
|
|
28
|
-
*/
|
|
29
|
-
export function decodeTuple(relation, tupleRaw) {
|
|
30
|
-
let result = {};
|
|
31
|
-
for (let columnName in tupleRaw) {
|
|
32
|
-
const rawval = tupleRaw[columnName];
|
|
33
|
-
const typeOid = relation._tupleDecoder._typeOids.get(columnName);
|
|
34
|
-
if (typeof rawval == 'string' && typeOid) {
|
|
35
|
-
result[columnName] = pgwire.PgType.decode(rawval, typeOid);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
result[columnName] = rawval;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=pgwire_utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pgwire_utils.js","sourceRoot":"","sources":["../../src/utils/pgwire_utils.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAE1G,OAAO,KAAK,MAAM,MAAM,4BAA4B,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
|
1
|
-
// Adapted from https://github.com/kagis/pgwire/blob/0dc927f9f8990a903f238737326e53ba1c8d094f/mod.js#L2218
|
|
2
|
-
|
|
3
|
-
import * as pgwire from '@powersync/service-jpgwire';
|
|
4
|
-
import { DatabaseInputRow, SqliteInputRow, toSyncRulesRow } from '@powersync/service-sync-rules';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* pgwire message -> SQLite row.
|
|
8
|
-
* @param message
|
|
9
|
-
*/
|
|
10
|
-
export function constructAfterRecord(message: pgwire.PgoutputInsert | pgwire.PgoutputUpdate): SqliteInputRow {
|
|
11
|
-
const rawData = (message as any).afterRaw;
|
|
12
|
-
|
|
13
|
-
const record = decodeTuple(message.relation, rawData);
|
|
14
|
-
return toSyncRulesRow(record);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* pgwire message -> SQLite row.
|
|
19
|
-
* @param message
|
|
20
|
-
*/
|
|
21
|
-
export function constructBeforeRecord(
|
|
22
|
-
message: pgwire.PgoutputDelete | pgwire.PgoutputUpdate
|
|
23
|
-
): SqliteInputRow | undefined {
|
|
24
|
-
const rawData = (message as any).beforeRaw;
|
|
25
|
-
if (rawData == null) {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
const record = decodeTuple(message.relation, rawData);
|
|
29
|
-
return toSyncRulesRow(record);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* We need a high level of control over how values are decoded, to make sure there is no loss
|
|
34
|
-
* of precision in the process.
|
|
35
|
-
*/
|
|
36
|
-
export function decodeTuple(relation: pgwire.PgoutputRelation, tupleRaw: Record<string, any>): DatabaseInputRow {
|
|
37
|
-
let result: Record<string, any> = {};
|
|
38
|
-
for (let columnName in tupleRaw) {
|
|
39
|
-
const rawval = tupleRaw[columnName];
|
|
40
|
-
const typeOid = (relation as any)._tupleDecoder._typeOids.get(columnName);
|
|
41
|
-
if (typeof rawval == 'string' && typeOid) {
|
|
42
|
-
result[columnName] = pgwire.PgType.decode(rawval, typeOid);
|
|
43
|
-
} else {
|
|
44
|
-
result[columnName] = rawval;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|