@powersync/service-module-postgres 0.3.0 → 0.5.0
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 +38 -0
- package/dist/api/PostgresRouteAPIAdapter.js +15 -10
- package/dist/api/PostgresRouteAPIAdapter.js.map +1 -1
- package/dist/auth/SupabaseKeyCollector.js +2 -2
- package/dist/auth/SupabaseKeyCollector.js.map +1 -1
- package/dist/module/PostgresModule.d.ts +4 -2
- package/dist/module/PostgresModule.js +11 -3
- package/dist/module/PostgresModule.js.map +1 -1
- package/dist/replication/ConnectionManagerFactory.d.ts +1 -1
- package/dist/replication/PgManager.js.map +1 -1
- package/dist/replication/PgRelation.js +2 -1
- package/dist/replication/PgRelation.js.map +1 -1
- package/dist/replication/WalStream.js +9 -7
- package/dist/replication/WalStream.js.map +1 -1
- package/dist/replication/WalStreamReplicator.d.ts +1 -0
- package/dist/replication/WalStreamReplicator.js +4 -0
- package/dist/replication/WalStreamReplicator.js.map +1 -1
- package/dist/replication/replication-utils.d.ts +1 -1
- package/dist/replication/replication-utils.js +14 -16
- package/dist/replication/replication-utils.js.map +1 -1
- package/dist/types/types.d.ts +55 -52
- package/dist/types/types.js +11 -98
- package/dist/types/types.js.map +1 -1
- package/dist/utils/migration_lib.js +2 -1
- package/dist/utils/migration_lib.js.map +1 -1
- package/dist/utils/pgwire_utils.d.ts +6 -5
- package/dist/utils/pgwire_utils.js +14 -41
- package/dist/utils/pgwire_utils.js.map +1 -1
- package/package.json +10 -8
- package/src/api/PostgresRouteAPIAdapter.ts +15 -11
- package/src/auth/SupabaseKeyCollector.ts +2 -2
- package/src/module/PostgresModule.ts +22 -5
- package/src/replication/ConnectionManagerFactory.ts +1 -1
- package/src/replication/PgManager.ts +1 -0
- package/src/replication/PgRelation.ts +2 -1
- package/src/replication/WalStream.ts +16 -7
- package/src/replication/WalStreamReplicator.ts +5 -0
- package/src/replication/replication-utils.ts +20 -17
- package/src/types/types.ts +16 -136
- package/src/utils/migration_lib.ts +2 -1
- package/src/utils/pgwire_utils.ts +15 -42
- package/test/src/__snapshots__/schema_changes.test.ts.snap +5 -0
- package/test/src/env.ts +4 -1
- package/test/src/large_batch.test.ts +17 -2
- package/test/src/schema_changes.test.ts +8 -3
- package/test/src/setup.ts +5 -1
- package/test/src/slow_tests.test.ts +120 -32
- package/test/src/util.ts +7 -2
- package/test/src/wal_stream.test.ts +7 -2
- package/test/src/wal_stream_utils.ts +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replication-utils.js","sourceRoot":"","sources":["../../src/replication/replication-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AAErD,OAAO,
|
|
1
|
+
{"version":3,"file":"replication-utils.js","sourceRoot":"","sources":["../../src/replication/replication-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AAErD,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAiB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAUjE,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,EAAmB,EACnB,UAAkB,EAClB,IAA6B;IAE7B,MAAM,SAAS,GAAG,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,kBAAkB,CAAC;IAC5E,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC,EAAE,EAAE;QACnD,SAAS,EAAE;;;;;4CAK6B,SAAS;;wDAEG;QACpD,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;KAC9C,CAAC,CAAC;IAEH,OAAO,QAAQ,CAA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,CAAC;AACL,CAAC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
|
+
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
1
2
|
import * as service_types from '@powersync/service-types';
|
|
2
3
|
import * as t from 'ts-codec';
|
|
4
|
+
export declare const validatePort: typeof lib_postgres.validatePort;
|
|
5
|
+
export declare const baseUri: typeof lib_postgres.baseUri;
|
|
6
|
+
export type NormalizedPostgresConnectionConfig = lib_postgres.NormalizedBasePostgresConnectionConfig;
|
|
3
7
|
export declare const POSTGRES_CONNECTION_TYPE: "postgresql";
|
|
4
|
-
export interface NormalizedPostgresConnectionConfig {
|
|
5
|
-
id: string;
|
|
6
|
-
tag: string;
|
|
7
|
-
hostname: string;
|
|
8
|
-
port: number;
|
|
9
|
-
database: string;
|
|
10
|
-
username: string;
|
|
11
|
-
password: string;
|
|
12
|
-
sslmode: 'verify-full' | 'verify-ca' | 'disable';
|
|
13
|
-
cacert: string | undefined;
|
|
14
|
-
client_certificate: string | undefined;
|
|
15
|
-
client_private_key: string | undefined;
|
|
16
|
-
}
|
|
17
8
|
export declare const PostgresConnectionConfig: t.Intersection<t.Codec<{
|
|
18
9
|
type: string;
|
|
19
10
|
id?: string | undefined;
|
|
20
11
|
tag?: string | undefined;
|
|
21
12
|
debug_api?: boolean | undefined;
|
|
13
|
+
} & {
|
|
14
|
+
type: "postgresql";
|
|
15
|
+
id?: string | undefined;
|
|
16
|
+
tag?: string | undefined;
|
|
17
|
+
uri?: string | undefined;
|
|
18
|
+
hostname?: string | undefined;
|
|
19
|
+
port?: number | undefined;
|
|
20
|
+
username?: string | undefined;
|
|
21
|
+
password?: string | undefined;
|
|
22
|
+
database?: string | undefined;
|
|
23
|
+
sslmode?: "verify-full" | "verify-ca" | "disable" | undefined;
|
|
24
|
+
cacert?: string | undefined;
|
|
25
|
+
client_certificate?: string | undefined;
|
|
26
|
+
client_private_key?: string | undefined;
|
|
27
|
+
tls_servername?: string | undefined;
|
|
28
|
+
reject_ip_ranges?: string[] | undefined;
|
|
29
|
+
slot_name_prefix?: string | undefined;
|
|
22
30
|
}, {
|
|
23
31
|
type: string;
|
|
24
32
|
id?: string | undefined;
|
|
25
33
|
tag?: string | undefined;
|
|
26
34
|
debug_api?: boolean | undefined;
|
|
27
|
-
}
|
|
28
|
-
type:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/** Expose database credentials */
|
|
46
|
-
demo_database: t.OptionalCodec<t.Codec<boolean, boolean, string, t.CodecProps>>;
|
|
47
|
-
/**
|
|
48
|
-
* Prefix for the slot name. Defaults to "powersync_"
|
|
49
|
-
*/
|
|
50
|
-
slot_name_prefix: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
|
|
51
|
-
}>>;
|
|
35
|
+
} & {
|
|
36
|
+
type: "postgresql";
|
|
37
|
+
id?: string | undefined;
|
|
38
|
+
tag?: string | undefined;
|
|
39
|
+
uri?: string | undefined;
|
|
40
|
+
hostname?: string | undefined;
|
|
41
|
+
port?: string | number | undefined;
|
|
42
|
+
username?: string | undefined;
|
|
43
|
+
password?: string | undefined;
|
|
44
|
+
database?: string | undefined;
|
|
45
|
+
sslmode?: "verify-full" | "verify-ca" | "disable" | undefined;
|
|
46
|
+
cacert?: string | undefined;
|
|
47
|
+
client_certificate?: string | undefined;
|
|
48
|
+
client_private_key?: string | undefined;
|
|
49
|
+
tls_servername?: string | undefined;
|
|
50
|
+
reject_ip_ranges?: string[] | undefined;
|
|
51
|
+
slot_name_prefix?: string | undefined;
|
|
52
|
+
}, string, t.CodecProps>, t.ObjectCodec<{}>>;
|
|
52
53
|
/**
|
|
53
54
|
* Config input specified when starting services
|
|
54
55
|
*/
|
|
@@ -57,22 +58,24 @@ export type PostgresConnectionConfig = t.Decoded<typeof PostgresConnectionConfig
|
|
|
57
58
|
* Resolved version of {@link PostgresConnectionConfig}
|
|
58
59
|
*/
|
|
59
60
|
export type ResolvedConnectionConfig = PostgresConnectionConfig & NormalizedPostgresConnectionConfig;
|
|
61
|
+
export declare function isPostgresConfig(config: service_types.configFile.DataSourceConfig): config is PostgresConnectionConfig;
|
|
60
62
|
/**
|
|
61
63
|
* Validate and normalize connection options.
|
|
62
64
|
*
|
|
63
65
|
* Returns destructured options.
|
|
64
66
|
*/
|
|
65
|
-
export declare function normalizeConnectionConfig(options: PostgresConnectionConfig):
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
export declare function normalizeConnectionConfig(options: PostgresConnectionConfig): {
|
|
68
|
+
id: string;
|
|
69
|
+
tag: string;
|
|
70
|
+
hostname: string;
|
|
71
|
+
port: number;
|
|
72
|
+
database: string;
|
|
73
|
+
username: string;
|
|
74
|
+
password: string;
|
|
75
|
+
sslmode: "verify-full" | "verify-ca" | "disable";
|
|
76
|
+
cacert: string | undefined;
|
|
77
|
+
tls_servername: string | undefined;
|
|
78
|
+
lookup: import("net").LookupFunction | undefined;
|
|
79
|
+
client_certificate: string | undefined;
|
|
80
|
+
client_private_key: string | undefined;
|
|
81
|
+
};
|
package/dist/types/types.js
CHANGED
|
@@ -1,111 +1,24 @@
|
|
|
1
|
+
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
1
2
|
import * as service_types from '@powersync/service-types';
|
|
2
3
|
import * as t from 'ts-codec';
|
|
3
|
-
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/** Tag used as reference in sync rules. Defaults to "default". Does not have to be unique. */
|
|
10
|
-
tag: t.string.optional(),
|
|
11
|
-
uri: t.string.optional(),
|
|
12
|
-
hostname: t.string.optional(),
|
|
13
|
-
port: service_types.configFile.portCodec.optional(),
|
|
14
|
-
username: t.string.optional(),
|
|
15
|
-
password: t.string.optional(),
|
|
16
|
-
database: t.string.optional(),
|
|
17
|
-
/** Defaults to verify-full */
|
|
18
|
-
sslmode: t.literal('verify-full').or(t.literal('verify-ca')).or(t.literal('disable')).optional(),
|
|
19
|
-
/** Required for verify-ca, optional for verify-full */
|
|
20
|
-
cacert: t.string.optional(),
|
|
21
|
-
client_certificate: t.string.optional(),
|
|
22
|
-
client_private_key: t.string.optional(),
|
|
23
|
-
/** Expose database credentials */
|
|
24
|
-
demo_database: t.boolean.optional(),
|
|
25
|
-
/**
|
|
26
|
-
* Prefix for the slot name. Defaults to "powersync_"
|
|
27
|
-
*/
|
|
28
|
-
slot_name_prefix: t.string.optional()
|
|
4
|
+
// Maintain backwards compatibility by exporting these
|
|
5
|
+
export const validatePort = lib_postgres.validatePort;
|
|
6
|
+
export const baseUri = lib_postgres.baseUri;
|
|
7
|
+
export const POSTGRES_CONNECTION_TYPE = lib_postgres.POSTGRES_CONNECTION_TYPE;
|
|
8
|
+
export const PostgresConnectionConfig = service_types.configFile.DataSourceConfig.and(lib_postgres.BasePostgresConnectionConfig).and(t.object({
|
|
9
|
+
// Add any replication connection specific config here in future
|
|
29
10
|
}));
|
|
11
|
+
export function isPostgresConfig(config) {
|
|
12
|
+
return config.type == lib_postgres.POSTGRES_CONNECTION_TYPE;
|
|
13
|
+
}
|
|
30
14
|
/**
|
|
31
15
|
* Validate and normalize connection options.
|
|
32
16
|
*
|
|
33
17
|
* Returns destructured options.
|
|
34
18
|
*/
|
|
35
19
|
export function normalizeConnectionConfig(options) {
|
|
36
|
-
let uri;
|
|
37
|
-
if (options.uri) {
|
|
38
|
-
uri = urijs.parse(options.uri);
|
|
39
|
-
if (uri.scheme != 'postgresql' && uri.scheme != 'postgres') {
|
|
40
|
-
`Invalid URI - protocol must be postgresql, got ${uri.scheme}`;
|
|
41
|
-
}
|
|
42
|
-
else if (uri.scheme != 'postgresql') {
|
|
43
|
-
uri.scheme = 'postgresql';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
uri = urijs.parse('postgresql:///');
|
|
48
|
-
}
|
|
49
|
-
const hostname = options.hostname ?? uri.host ?? '';
|
|
50
|
-
const port = validatePort(options.port ?? uri.port ?? 5432);
|
|
51
|
-
const database = options.database ?? uri.path?.substring(1) ?? '';
|
|
52
|
-
const [uri_username, uri_password] = (uri.userinfo ?? '').split(':');
|
|
53
|
-
const username = options.username ?? uri_username ?? '';
|
|
54
|
-
const password = options.password ?? uri_password ?? '';
|
|
55
|
-
const sslmode = options.sslmode ?? 'verify-full'; // Configuration not supported via URI
|
|
56
|
-
const cacert = options.cacert;
|
|
57
|
-
if (sslmode == 'verify-ca' && cacert == null) {
|
|
58
|
-
throw new Error('Explicit cacert is required for sslmode=verify-ca');
|
|
59
|
-
}
|
|
60
|
-
if (hostname == '') {
|
|
61
|
-
throw new Error(`hostname required`);
|
|
62
|
-
}
|
|
63
|
-
if (username == '') {
|
|
64
|
-
throw new Error(`username required`);
|
|
65
|
-
}
|
|
66
|
-
if (password == '') {
|
|
67
|
-
throw new Error(`password required`);
|
|
68
|
-
}
|
|
69
|
-
if (database == '') {
|
|
70
|
-
throw new Error(`database required`);
|
|
71
|
-
}
|
|
72
20
|
return {
|
|
73
|
-
|
|
74
|
-
tag: options.tag ?? 'default',
|
|
75
|
-
hostname,
|
|
76
|
-
port,
|
|
77
|
-
database,
|
|
78
|
-
username,
|
|
79
|
-
password,
|
|
80
|
-
sslmode,
|
|
81
|
-
cacert,
|
|
82
|
-
client_certificate: options.client_certificate ?? undefined,
|
|
83
|
-
client_private_key: options.client_private_key ?? undefined
|
|
21
|
+
...lib_postgres.normalizeConnectionConfig(options)
|
|
84
22
|
};
|
|
85
23
|
}
|
|
86
|
-
export function isPostgresConfig(config) {
|
|
87
|
-
return config.type == POSTGRES_CONNECTION_TYPE;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Check whether the port is in a "safe" range.
|
|
91
|
-
*
|
|
92
|
-
* We do not support connecting to "privileged" ports.
|
|
93
|
-
*/
|
|
94
|
-
export function validatePort(port) {
|
|
95
|
-
if (typeof port == 'string') {
|
|
96
|
-
port = parseInt(port);
|
|
97
|
-
}
|
|
98
|
-
if (port < 1024) {
|
|
99
|
-
throw new Error(`Port ${port} not supported`);
|
|
100
|
-
}
|
|
101
|
-
return port;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Construct a postgres URI, without username, password or ssl options.
|
|
105
|
-
*
|
|
106
|
-
* Only contains hostname, port, database.
|
|
107
|
-
*/
|
|
108
|
-
export function baseUri(options) {
|
|
109
|
-
return `postgresql://${options.hostname}:${options.port}/${options.database}`;
|
|
110
|
-
}
|
|
111
24
|
//# sourceMappingURL=types.js.map
|
package/dist/types/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,sDAAsD;AACtD,MAAM,CAAC,MAAM,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC;AACtD,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC;AAE5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC,wBAAwB,CAAC;AAE9E,MAAM,CAAC,MAAM,wBAAwB,GAAG,aAAa,CAAC,UAAU,CAAC,gBAAgB,CAAC,GAAG,CACnF,YAAY,CAAC,4BAA4B,CAC1C,CAAC,GAAG,CACH,CAAC,CAAC,MAAM,CAAC;AACP,gEAAgE;CACjE,CAAC,CACH,CAAC;AAYF,MAAM,UAAU,gBAAgB,CAC9B,MAAiD;IAEjD,OAAO,MAAM,CAAC,IAAI,IAAI,YAAY,CAAC,wBAAwB,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAiC;IACzE,OAAO;QACL,GAAG,YAAY,CAAC,yBAAyB,CAAC,OAAO,CAAC;KACN,CAAC;AACjD,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ServiceAssertionError } from '@powersync/lib-services-framework';
|
|
1
2
|
// Very loosely based on https://github.com/porsager/postgres-shift/
|
|
2
3
|
export class Migrations {
|
|
3
4
|
constructor() {
|
|
@@ -5,7 +6,7 @@ export class Migrations {
|
|
|
5
6
|
}
|
|
6
7
|
add(id, name, up) {
|
|
7
8
|
if (this.migrations.length > 0 && this.migrations[this.migrations.length - 1].id >= id) {
|
|
8
|
-
throw new
|
|
9
|
+
throw new ServiceAssertionError('Migration ids must be strictly incrementing');
|
|
9
10
|
}
|
|
10
11
|
this.migrations.push({ id, up, name });
|
|
11
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration_lib.js","sourceRoot":"","sources":["../../src/utils/migration_lib.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migration_lib.js","sourceRoot":"","sources":["../../src/utils/migration_lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAW1E,oEAAoE;AACpE,MAAM,OAAO,UAAU;IAAvB;QACU,eAAU,GAAgB,EAAE,CAAC;IAkEvC,CAAC;IAhEC,GAAG,CAAC,EAAU,EAAE,IAAY,EAAE,EAAqB;QACjD,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,C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AAC,CAAC;QACV,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,EAAuB;QACzC,OAAO,EAAE;aACN,KAAK,CACJ;;;;KAIH,CACE;aACA,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAW,EAAE,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,EAAuB;QACjD,MAAM,EAAE,CAAC,KAAK,CAAC;;;;;KAKd,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as pgwire from '@powersync/service-jpgwire';
|
|
2
|
-
import {
|
|
2
|
+
import { DatabaseInputRow, SqliteRow } from '@powersync/service-sync-rules';
|
|
3
3
|
/**
|
|
4
4
|
* pgwire message -> SQLite row.
|
|
5
5
|
* @param message
|
|
@@ -10,7 +10,8 @@ export declare function constructAfterRecord(message: pgwire.PgoutputInsert | pg
|
|
|
10
10
|
* @param message
|
|
11
11
|
*/
|
|
12
12
|
export declare function constructBeforeRecord(message: pgwire.PgoutputDelete | pgwire.PgoutputUpdate): SqliteRow | undefined;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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,14 +1,13 @@
|
|
|
1
1
|
// Adapted from https://github.com/kagis/pgwire/blob/0dc927f9f8990a903f238737326e53ba1c8d094f/mod.js#L2218
|
|
2
2
|
import * as pgwire from '@powersync/service-jpgwire';
|
|
3
3
|
import { toSyncRulesRow } from '@powersync/service-sync-rules';
|
|
4
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
5
4
|
/**
|
|
6
5
|
* pgwire message -> SQLite row.
|
|
7
6
|
* @param message
|
|
8
7
|
*/
|
|
9
8
|
export function constructAfterRecord(message) {
|
|
10
9
|
const rawData = message.afterRaw;
|
|
11
|
-
const record =
|
|
10
|
+
const record = decodeTuple(message.relation, rawData);
|
|
12
11
|
return toSyncRulesRow(record);
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
@@ -20,51 +19,25 @@ export function constructBeforeRecord(message) {
|
|
|
20
19
|
if (rawData == null) {
|
|
21
20
|
return undefined;
|
|
22
21
|
}
|
|
23
|
-
const record =
|
|
22
|
+
const record = decodeTuple(message.relation, rawData);
|
|
24
23
|
return toSyncRulesRow(record);
|
|
25
24
|
}
|
|
26
|
-
export function escapeIdentifier(identifier) {
|
|
27
|
-
return `"${identifier.replace(/"/g, '""').replace(/\./g, '"."')}"`;
|
|
28
|
-
}
|
|
29
|
-
export function autoParameter(arg) {
|
|
30
|
-
if (arg == null) {
|
|
31
|
-
return { type: 'varchar', value: null };
|
|
32
|
-
}
|
|
33
|
-
else if (typeof arg == 'string') {
|
|
34
|
-
return { type: 'varchar', value: arg };
|
|
35
|
-
}
|
|
36
|
-
else if (typeof arg == 'number') {
|
|
37
|
-
if (Number.isInteger(arg)) {
|
|
38
|
-
return { type: 'int8', value: arg };
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return { type: 'float8', value: arg };
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else if (typeof arg == 'boolean') {
|
|
45
|
-
return { type: 'bool', value: arg };
|
|
46
|
-
}
|
|
47
|
-
else if (typeof arg == 'bigint') {
|
|
48
|
-
return { type: 'int8', value: arg };
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
throw new Error(`Unsupported query parameter: ${typeof arg}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
25
|
/**
|
|
55
|
-
*
|
|
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.
|
|
56
28
|
*/
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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);
|
|
61
36
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
throw e;
|
|
65
|
-
}
|
|
66
|
-
logger.warn('Query error, retrying', e);
|
|
37
|
+
else {
|
|
38
|
+
result[columnName] = rawval;
|
|
67
39
|
}
|
|
68
40
|
}
|
|
41
|
+
return result;
|
|
69
42
|
}
|
|
70
43
|
//# sourceMappingURL=pgwire_utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgwire_utils.js","sourceRoot":"","sources":["../../src/utils/pgwire_utils.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAE1G,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"pgwire_utils.js","sourceRoot":"","sources":["../../src/utils/pgwire_utils.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAE1G,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAA+B,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE5F;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAsD;IACzF,MAAM,OAAO,GAAI,OAAe,CAAC,QAAQ,CAAC;IAE1C,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtD,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAsD;IAC1F,MAAM,OAAO,GAAI,OAAe,CAAC,SAAS,CAAC;IAC3C,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtD,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,QAAiC,EAAE,QAA6B;IAC1F,IAAI,MAAM,GAAwB,EAAE,CAAC;IACrC,KAAK,IAAI,UAAU,IAAI,QAAQ,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;QACpC,MAAM,OAAO,GAAI,QAAgB,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC1E,IAAI,OAAO,MAAM,IAAI,QAAQ,IAAI,OAAO,EAAE,CAAC;YACzC,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7D,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.5.0",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"license": "FSL-1.1-Apache-2.0",
|
|
11
11
|
"type": "module",
|
|
@@ -27,17 +27,19 @@
|
|
|
27
27
|
"ts-codec": "^1.3.0",
|
|
28
28
|
"uuid": "^9.0.1",
|
|
29
29
|
"uri-js": "^4.4.1",
|
|
30
|
-
"@powersync/lib-services-framework": "0.
|
|
31
|
-
"@powersync/service-
|
|
32
|
-
"@powersync/service-
|
|
30
|
+
"@powersync/lib-services-framework": "0.5.0",
|
|
31
|
+
"@powersync/lib-service-postgres": "0.2.0",
|
|
32
|
+
"@powersync/service-core": "0.16.0",
|
|
33
|
+
"@powersync/service-jpgwire": "0.19.0",
|
|
33
34
|
"@powersync/service-jsonbig": "0.17.10",
|
|
34
|
-
"@powersync/service-sync-rules": "0.23.
|
|
35
|
-
"@powersync/service-types": "0.7.
|
|
35
|
+
"@powersync/service-sync-rules": "0.23.2",
|
|
36
|
+
"@powersync/service-types": "0.7.1"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@types/uuid": "^9.0.4",
|
|
39
|
-
"@powersync/service-core-tests": "0.
|
|
40
|
-
"@powersync/service-module-mongodb-storage": "0.1
|
|
40
|
+
"@powersync/service-core-tests": "0.3.1",
|
|
41
|
+
"@powersync/service-module-mongodb-storage": "0.3.1",
|
|
42
|
+
"@powersync/service-module-postgres-storage": "0.1.1"
|
|
41
43
|
},
|
|
42
44
|
"scripts": {
|
|
43
45
|
"build": "tsc -b",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
|
+
import { ErrorCode, ServiceError } from '@powersync/lib-services-framework';
|
|
1
3
|
import { api, ParseSyncRulesOptions } from '@powersync/service-core';
|
|
2
4
|
import * as pgwire from '@powersync/service-jpgwire';
|
|
3
|
-
|
|
4
5
|
import * as sync_rules from '@powersync/service-sync-rules';
|
|
5
6
|
import * as service_types from '@powersync/service-types';
|
|
6
7
|
import * as replication_utils from '../replication/replication-utils.js';
|
|
7
|
-
import * as types from '../types/types.js';
|
|
8
|
-
import * as pg_utils from '../utils/pgwire_utils.js';
|
|
9
8
|
import { getDebugTableInfo } from '../replication/replication-utils.js';
|
|
10
9
|
import { PUBLICATION_NAME } from '../replication/WalStream.js';
|
|
10
|
+
import * as types from '../types/types.js';
|
|
11
11
|
|
|
12
12
|
export class PostgresRouteAPIAdapter implements api.RouteAPI {
|
|
13
13
|
connectionTag: string;
|
|
@@ -53,7 +53,7 @@ export class PostgresRouteAPIAdapter implements api.RouteAPI {
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
try {
|
|
56
|
-
await
|
|
56
|
+
await lib_postgres.retriedQuery(this.pool, `SELECT 'PowerSync connection test'`);
|
|
57
57
|
} catch (e) {
|
|
58
58
|
return {
|
|
59
59
|
...base,
|
|
@@ -94,7 +94,7 @@ export class PostgresRouteAPIAdapter implements api.RouteAPI {
|
|
|
94
94
|
try {
|
|
95
95
|
const result = await this.pool.query({
|
|
96
96
|
statement: query,
|
|
97
|
-
params: params.map(
|
|
97
|
+
params: params.map(lib_postgres.autoParameter)
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
return service_types.internal_routes.ExecuteSqlResponse.encode({
|
|
@@ -146,7 +146,7 @@ export class PostgresRouteAPIAdapter implements api.RouteAPI {
|
|
|
146
146
|
if (tablePattern.isWildcard) {
|
|
147
147
|
patternResult.tables = [];
|
|
148
148
|
const prefix = tablePattern.tablePrefix;
|
|
149
|
-
const results = await
|
|
149
|
+
const results = await lib_postgres.retriedQuery(this.pool, {
|
|
150
150
|
statement: `SELECT c.oid AS relid, c.relname AS table_name
|
|
151
151
|
FROM pg_class c
|
|
152
152
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
@@ -169,7 +169,7 @@ export class PostgresRouteAPIAdapter implements api.RouteAPI {
|
|
|
169
169
|
patternResult.tables.push(details);
|
|
170
170
|
}
|
|
171
171
|
} else {
|
|
172
|
-
const results = await
|
|
172
|
+
const results = await lib_postgres.retriedQuery(this.pool, {
|
|
173
173
|
statement: `SELECT c.oid AS relid, c.relname AS table_name
|
|
174
174
|
FROM pg_class c
|
|
175
175
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
@@ -215,7 +215,7 @@ export class PostgresRouteAPIAdapter implements api.RouteAPI {
|
|
|
215
215
|
async getReplicationLag(options: api.ReplicationLagOptions): Promise<number | undefined> {
|
|
216
216
|
const { bucketStorage } = options;
|
|
217
217
|
const slotName = bucketStorage.slot_name;
|
|
218
|
-
const results = await
|
|
218
|
+
const results = await lib_postgres.retriedQuery(this.pool, {
|
|
219
219
|
statement: `SELECT
|
|
220
220
|
slot_name,
|
|
221
221
|
confirmed_flush_lsn,
|
|
@@ -229,7 +229,11 @@ FROM pg_replication_slots WHERE slot_name = $1 LIMIT 1;`,
|
|
|
229
229
|
return Number(row.lsn_distance);
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
throw new
|
|
232
|
+
throw new ServiceError({
|
|
233
|
+
status: 500,
|
|
234
|
+
code: ErrorCode.PSYNC_S4001,
|
|
235
|
+
description: `Could not determine replication lag for slot ${slotName}`
|
|
236
|
+
});
|
|
233
237
|
}
|
|
234
238
|
|
|
235
239
|
async getReplicationHead(): Promise<string> {
|
|
@@ -237,7 +241,7 @@ FROM pg_replication_slots WHERE slot_name = $1 LIMIT 1;`,
|
|
|
237
241
|
// However, on Aurora (Postgres compatible), it can return an entirely different LSN,
|
|
238
242
|
// causing the write checkpoints to never be replicated back to the client.
|
|
239
243
|
// For those, we need to use pg_current_wal_lsn() instead.
|
|
240
|
-
const { results } = await
|
|
244
|
+
const { results } = await lib_postgres.retriedQuery(
|
|
241
245
|
this.pool,
|
|
242
246
|
{ statement: `SELECT pg_current_wal_lsn() as lsn` },
|
|
243
247
|
{ statement: `SELECT pg_logical_emit_message(false, 'powersync', 'ping')` }
|
|
@@ -250,7 +254,7 @@ FROM pg_replication_slots WHERE slot_name = $1 LIMIT 1;`,
|
|
|
250
254
|
|
|
251
255
|
async getConnectionSchema(): Promise<service_types.DatabaseSchema[]> {
|
|
252
256
|
// https://github.com/Borvik/vscode-postgres/blob/88ec5ed061a0c9bced6c5d4ec122d0759c3f3247/src/language/server.ts
|
|
253
|
-
const results = await
|
|
257
|
+
const results = await lib_postgres.retriedQuery(
|
|
254
258
|
this.pool,
|
|
255
259
|
`SELECT
|
|
256
260
|
tbl.schemaname,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
1
2
|
import { auth } from '@powersync/service-core';
|
|
2
3
|
import * as pgwire from '@powersync/service-jpgwire';
|
|
3
4
|
import * as jose from 'jose';
|
|
4
5
|
|
|
5
6
|
import * as types from '../types/types.js';
|
|
6
|
-
import * as pgwire_utils from '../utils/pgwire_utils.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Fetches key from the Supabase database.
|
|
@@ -39,7 +39,7 @@ export class SupabaseKeyCollector implements auth.KeyCollector {
|
|
|
39
39
|
let row: { jwt_secret: string };
|
|
40
40
|
try {
|
|
41
41
|
const rows = pgwire.pgwireRows(
|
|
42
|
-
await
|
|
42
|
+
await lib_postgres.retriedQuery(this.pool, `SELECT current_setting('app.settings.jwt_secret') as jwt_secret`)
|
|
43
43
|
);
|
|
44
44
|
row = rows[0] as any;
|
|
45
45
|
} catch (e) {
|