powersync 0.1.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/README.md +339 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +9 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +8 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.js +49 -0
- package/dist/commands/instance/config.d.ts +6 -0
- package/dist/commands/instance/config.js +23 -0
- package/dist/commands/instance/create.d.ts +16 -0
- package/dist/commands/instance/create.js +163 -0
- package/dist/commands/instance/deploy.d.ts +15 -0
- package/dist/commands/instance/deploy.js +142 -0
- package/dist/commands/instance/destroy.d.ts +9 -0
- package/dist/commands/instance/destroy.js +42 -0
- package/dist/commands/instance/schema.d.ts +6 -0
- package/dist/commands/instance/schema.js +20 -0
- package/dist/commands/instance/set.d.ts +9 -0
- package/dist/commands/instance/set.js +31 -0
- package/dist/commands/instance/status.d.ts +6 -0
- package/dist/commands/instance/status.js +21 -0
- package/dist/commands/instance/stop.d.ts +9 -0
- package/dist/commands/instance/stop.js +42 -0
- package/dist/commands/instance/sync-rules/deploy.d.ts +10 -0
- package/dist/commands/instance/sync-rules/deploy.js +49 -0
- package/dist/commands/instance/sync-rules/generate-schema.d.ts +10 -0
- package/dist/commands/instance/sync-rules/generate-schema.js +55 -0
- package/dist/commands/instance/sync-rules/validate.d.ts +9 -0
- package/dist/commands/instance/sync-rules/validate.js +29 -0
- package/dist/commands/instances.d.ts +6 -0
- package/dist/commands/instances.js +20 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/powersync-sdk/accounts/api.d.ts +717 -0
- package/dist/powersync-sdk/accounts/api.js +182 -0
- package/dist/powersync-sdk/accounts/client.d.ts +1096 -0
- package/dist/powersync-sdk/accounts/client.js +124 -0
- package/dist/powersync-sdk/accounts/codecs.d.ts +32 -0
- package/dist/powersync-sdk/accounts/codecs.js +93 -0
- package/dist/powersync-sdk/accounts/index.d.ts +4 -0
- package/dist/powersync-sdk/accounts/index.js +4 -0
- package/dist/powersync-sdk/accounts/models.d.ts +260 -0
- package/dist/powersync-sdk/accounts/models.js +96 -0
- package/dist/powersync-sdk/accounts/routes.d.ts +44 -0
- package/dist/powersync-sdk/accounts/routes.js +45 -0
- package/dist/powersync-sdk/accounts/source.d.ts +76 -0
- package/dist/powersync-sdk/accounts/source.js +32 -0
- package/dist/powersync-sdk/errors/errors.d.ts +62 -0
- package/dist/powersync-sdk/errors/errors.js +115 -0
- package/dist/powersync-sdk/errors/index.d.ts +2 -0
- package/dist/powersync-sdk/errors/index.js +2 -0
- package/dist/powersync-sdk/errors/utils.d.ts +4 -0
- package/dist/powersync-sdk/errors/utils.js +18 -0
- package/dist/powersync-sdk/fetch-clients/codecs.d.ts +4 -0
- package/dist/powersync-sdk/fetch-clients/codecs.js +34 -0
- package/dist/powersync-sdk/fetch-clients/decoders.d.ts +3 -0
- package/dist/powersync-sdk/fetch-clients/decoders.js +35 -0
- package/dist/powersync-sdk/fetch-clients/definitions.d.ts +97 -0
- package/dist/powersync-sdk/fetch-clients/definitions.js +22 -0
- package/dist/powersync-sdk/fetch-clients/errors.d.ts +7 -0
- package/dist/powersync-sdk/fetch-clients/errors.js +19 -0
- package/dist/powersync-sdk/fetch-clients/index.d.ts +5 -0
- package/dist/powersync-sdk/fetch-clients/index.js +5 -0
- package/dist/powersync-sdk/fetch-clients/node-client.d.ts +9 -0
- package/dist/powersync-sdk/fetch-clients/node-client.js +107 -0
- package/dist/powersync-sdk/fetch-clients/request.d.ts +11 -0
- package/dist/powersync-sdk/fetch-clients/request.js +138 -0
- package/dist/powersync-sdk/fetch-clients/streaming.d.ts +65 -0
- package/dist/powersync-sdk/fetch-clients/streaming.js +99 -0
- package/dist/powersync-sdk/fetch-clients/utils.d.ts +13 -0
- package/dist/powersync-sdk/fetch-clients/utils.js +43 -0
- package/dist/powersync-sdk/fetch-clients/web-client.d.ts +14 -0
- package/dist/powersync-sdk/fetch-clients/web-client.js +56 -0
- package/dist/powersync-sdk/json/index.d.ts +4 -0
- package/dist/powersync-sdk/json/index.js +3 -0
- package/dist/powersync-sdk/json/json.d.ts +5 -0
- package/dist/powersync-sdk/json/json.js +35 -0
- package/dist/powersync-sdk/json/json_container.d.ts +18 -0
- package/dist/powersync-sdk/json/json_container.js +28 -0
- package/dist/powersync-sdk/json/json_stringify.d.ts +36 -0
- package/dist/powersync-sdk/json/json_stringify.js +162 -0
- package/dist/powersync-sdk/powersync/client.d.ts +449 -0
- package/dist/powersync-sdk/powersync/client.js +53 -0
- package/dist/powersync-sdk/powersync/config/HostedConfig.d.ts +327 -0
- package/dist/powersync-sdk/powersync/config/HostedConfig.js +92 -0
- package/dist/powersync-sdk/powersync/config/PowerSyncConfig.d.ts +211 -0
- package/dist/powersync-sdk/powersync/config/PowerSyncConfig.js +97 -0
- package/dist/powersync-sdk/powersync/config/normalize.d.ts +32 -0
- package/dist/powersync-sdk/powersync/config/normalize.js +85 -0
- package/dist/powersync-sdk/powersync/definitions.d.ts +149 -0
- package/dist/powersync-sdk/powersync/definitions.js +97 -0
- package/dist/powersync-sdk/powersync/index.d.ts +8 -0
- package/dist/powersync-sdk/powersync/index.js +8 -0
- package/dist/powersync-sdk/powersync/internal_routes.d.ts +247 -0
- package/dist/powersync-sdk/powersync/internal_routes.js +69 -0
- package/dist/powersync-sdk/powersync/routes.d.ts +779 -0
- package/dist/powersync-sdk/powersync/routes.js +191 -0
- package/dist/powersync-sdk/sdk-clients/endpoints.d.ts +31 -0
- package/dist/powersync-sdk/sdk-clients/endpoints.js +48 -0
- package/dist/powersync-sdk/sdk-clients/index.d.ts +3 -0
- package/dist/powersync-sdk/sdk-clients/index.js +3 -0
- package/dist/powersync-sdk/sdk-clients/pagination.d.ts +14 -0
- package/dist/powersync-sdk/sdk-clients/pagination.js +21 -0
- package/dist/powersync-sdk/sdk-clients/sdk-client.d.ts +17 -0
- package/dist/powersync-sdk/sdk-clients/sdk-client.js +30 -0
- package/dist/powersync-sdk/streaming/bson/buffer-array.d.ts +31 -0
- package/dist/powersync-sdk/streaming/bson/buffer-array.js +79 -0
- package/dist/powersync-sdk/streaming/bson/constants.d.ts +2 -0
- package/dist/powersync-sdk/streaming/bson/constants.js +1 -0
- package/dist/powersync-sdk/streaming/bson/decoder.d.ts +10 -0
- package/dist/powersync-sdk/streaming/bson/decoder.js +62 -0
- package/dist/powersync-sdk/streaming/bson/encoder.d.ts +10 -0
- package/dist/powersync-sdk/streaming/bson/encoder.js +23 -0
- package/dist/powersync-sdk/streaming/bson/header.d.ts +11 -0
- package/dist/powersync-sdk/streaming/bson/header.js +52 -0
- package/dist/powersync-sdk/streaming/bson/index.d.ts +5 -0
- package/dist/powersync-sdk/streaming/bson/index.js +5 -0
- package/dist/powersync-sdk/streaming/core/backpressure.d.ts +15 -0
- package/dist/powersync-sdk/streaming/core/backpressure.js +34 -0
- package/dist/powersync-sdk/streaming/core/cross-stream.d.ts +6 -0
- package/dist/powersync-sdk/streaming/core/cross-stream.js +17 -0
- package/dist/powersync-sdk/streaming/core/index.d.ts +4 -0
- package/dist/powersync-sdk/streaming/core/index.js +4 -0
- package/dist/powersync-sdk/streaming/core/node-utils.d.ts +7 -0
- package/dist/powersync-sdk/streaming/core/node-utils.js +11 -0
- package/dist/powersync-sdk/streaming/core/transformers.d.ts +41 -0
- package/dist/powersync-sdk/streaming/core/transformers.js +70 -0
- package/dist/powersync-sdk/streaming/core/utils.d.ts +36 -0
- package/dist/powersync-sdk/streaming/core/utils.js +66 -0
- package/dist/powersync-sdk/streaming/index.d.ts +3 -0
- package/dist/powersync-sdk/streaming/index.js +3 -0
- package/dist/powersync-sdk/streaming/web.d.ts +4 -0
- package/dist/powersync-sdk/streaming/web.js +4 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.d.ts +2 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.js +36 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.d.ts +2 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.js +58 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.d.ts +18 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.js +348 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.js +118 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.js +131 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.js +134 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.js +122 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.js +158 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.d.ts +14 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.js +165 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.js +207 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.d.ts +30 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.js +29 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.d.ts +2 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.js +111 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.d.ts +9 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.js +9 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.d.ts +5 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.js +9 -0
- package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.d.ts +12 -0
- package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.js +35 -0
- package/dist/powersync-sdk/sync-rules/ExpressionType.d.ts +33 -0
- package/dist/powersync-sdk/sync-rules/ExpressionType.js +62 -0
- package/dist/powersync-sdk/sync-rules/IdSequence.d.ts +4 -0
- package/dist/powersync-sdk/sync-rules/IdSequence.js +7 -0
- package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.d.ts +12 -0
- package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.js +38 -0
- package/dist/powersync-sdk/sync-rules/SchemaGenerator.d.ts +14 -0
- package/dist/powersync-sdk/sync-rules/SchemaGenerator.js +24 -0
- package/dist/powersync-sdk/sync-rules/SourceTableInterface.d.ts +5 -0
- package/dist/powersync-sdk/sync-rules/SourceTableInterface.js +1 -0
- package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.d.ts +37 -0
- package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.js +116 -0
- package/dist/powersync-sdk/sync-rules/SqlDataQuery.d.ts +39 -0
- package/dist/powersync-sdk/sync-rules/SqlDataQuery.js +245 -0
- package/dist/powersync-sdk/sync-rules/SqlParameterQuery.d.ts +43 -0
- package/dist/powersync-sdk/sync-rules/SqlParameterQuery.js +254 -0
- package/dist/powersync-sdk/sync-rules/SqlSyncRules.d.ts +52 -0
- package/dist/powersync-sdk/sync-rules/SqlSyncRules.js +252 -0
- package/dist/powersync-sdk/sync-rules/StaticSchema.d.ts +26 -0
- package/dist/powersync-sdk/sync-rules/StaticSchema.js +71 -0
- package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.d.ts +24 -0
- package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.js +71 -0
- package/dist/powersync-sdk/sync-rules/TablePattern.d.ts +17 -0
- package/dist/powersync-sdk/sync-rules/TablePattern.js +56 -0
- package/dist/powersync-sdk/sync-rules/TableQuerySchema.d.ts +9 -0
- package/dist/powersync-sdk/sync-rules/TableQuerySchema.js +41 -0
- package/dist/powersync-sdk/sync-rules/errors.d.ts +22 -0
- package/dist/powersync-sdk/sync-rules/errors.js +60 -0
- package/dist/powersync-sdk/sync-rules/generators.d.ts +6 -0
- package/dist/powersync-sdk/sync-rules/generators.js +6 -0
- package/dist/powersync-sdk/sync-rules/index.d.ts +17 -0
- package/dist/powersync-sdk/sync-rules/index.js +17 -0
- package/dist/powersync-sdk/sync-rules/json_schema.d.ts +3 -0
- package/dist/powersync-sdk/sync-rules/json_schema.js +50 -0
- package/dist/powersync-sdk/sync-rules/sql_filters.d.ts +91 -0
- package/dist/powersync-sdk/sync-rules/sql_filters.js +491 -0
- package/dist/powersync-sdk/sync-rules/sql_functions.d.ts +53 -0
- package/dist/powersync-sdk/sync-rules/sql_functions.js +755 -0
- package/dist/powersync-sdk/sync-rules/sql_support.d.ts +22 -0
- package/dist/powersync-sdk/sync-rules/sql_support.js +208 -0
- package/dist/powersync-sdk/sync-rules/types.d.ts +174 -0
- package/dist/powersync-sdk/sync-rules/types.js +9 -0
- package/dist/powersync-sdk/sync-rules/utils.d.ts +45 -0
- package/dist/powersync-sdk/sync-rules/utils.js +163 -0
- package/dist/service/accounts.client.d.ts +26 -0
- package/dist/service/accounts.client.js +26 -0
- package/dist/service/powersync.client.d.ts +269 -0
- package/dist/service/powersync.client.js +135 -0
- package/dist/service/types.d.ts +69 -0
- package/dist/service/types.js +1 -0
- package/dist/service/utils.d.ts +5 -0
- package/dist/service/utils.js +7 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +52 -0
- package/oclif.manifest.json +514 -0
- package/package.json +81 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/* eslint-disable unicorn/filename-case */
|
|
2
|
+
/* eslint-disable camelcase */
|
|
3
|
+
import * as t from 'ts-codec';
|
|
4
|
+
export const postgresConnection = t.object({
|
|
5
|
+
/** Required for verify-ca, optional for verify-full */
|
|
6
|
+
cacert: t.string.optional(),
|
|
7
|
+
client_certificate: t.string.optional(),
|
|
8
|
+
client_private_key: t.string.optional(),
|
|
9
|
+
database: t.string.optional(),
|
|
10
|
+
/** Expose "execute-sql" */
|
|
11
|
+
debug_api: t.boolean.optional(),
|
|
12
|
+
/** Expose database credentials */
|
|
13
|
+
demo_database: t.boolean.optional(),
|
|
14
|
+
hostname: t.string.optional(),
|
|
15
|
+
/** Unique identifier for the connection - optional when a single connection is present. */
|
|
16
|
+
id: t.string.optional(),
|
|
17
|
+
password: t.string.optional(),
|
|
18
|
+
port: t.number.optional(),
|
|
19
|
+
/**
|
|
20
|
+
* Prefix for the slot name. Defaults to "powersync_"
|
|
21
|
+
*/
|
|
22
|
+
slot_name_prefix: t.string.optional(),
|
|
23
|
+
/** Defaults to verify-full */
|
|
24
|
+
sslmode: t.literal('verify-full').or(t.literal('verify-ca')).or(t.literal('disable')).optional(),
|
|
25
|
+
/** Tag used as reference in sync rules. Defaults to "default". Does not have to be unique. */
|
|
26
|
+
tag: t.string.optional(),
|
|
27
|
+
type: t.literal('postgresql'),
|
|
28
|
+
uri: t.string.optional(),
|
|
29
|
+
username: t.string.optional()
|
|
30
|
+
});
|
|
31
|
+
export const jwkRSA = t.object({
|
|
32
|
+
alg: t.literal('RS256').or(t.literal('RS384')).or(t.literal('RS512')).optional(),
|
|
33
|
+
e: t.string,
|
|
34
|
+
kid: t.string,
|
|
35
|
+
kty: t.literal('RSA'),
|
|
36
|
+
n: t.string,
|
|
37
|
+
use: t.string.optional()
|
|
38
|
+
});
|
|
39
|
+
export const jwkHmac = t.object({
|
|
40
|
+
alg: t.literal('HS256').or(t.literal('HS384')).or(t.literal('HS512')),
|
|
41
|
+
k: t.string,
|
|
42
|
+
/**
|
|
43
|
+
* undefined kid indicates it can match any JWT, with or without a kid.
|
|
44
|
+
* Use a kid wherever possible.
|
|
45
|
+
*/
|
|
46
|
+
kid: t.string.optional(),
|
|
47
|
+
kty: t.literal('oct'),
|
|
48
|
+
use: t.string.optional()
|
|
49
|
+
});
|
|
50
|
+
const jwk = t.union(jwkRSA, jwkHmac);
|
|
51
|
+
export const strictJwks = t.object({
|
|
52
|
+
keys: t.array(jwk)
|
|
53
|
+
});
|
|
54
|
+
export const storageConfig = t.object({
|
|
55
|
+
database: t.string.optional(),
|
|
56
|
+
password: t.string.optional(),
|
|
57
|
+
type: t.literal('mongodb'),
|
|
58
|
+
uri: t.string,
|
|
59
|
+
username: t.string.optional()
|
|
60
|
+
});
|
|
61
|
+
export const powerSyncConfig = t.object({
|
|
62
|
+
api: t
|
|
63
|
+
.object({
|
|
64
|
+
tokens: t.array(t.string).optional()
|
|
65
|
+
})
|
|
66
|
+
.optional(),
|
|
67
|
+
client_auth: t
|
|
68
|
+
.object({
|
|
69
|
+
audience: t.array(t.string).optional(),
|
|
70
|
+
jwks: strictJwks.optional(),
|
|
71
|
+
jwks_uri: t.string.or(t.array(t.string)).optional(),
|
|
72
|
+
supabase: t.boolean.optional()
|
|
73
|
+
})
|
|
74
|
+
.optional(),
|
|
75
|
+
dev: t
|
|
76
|
+
.object({
|
|
77
|
+
crud_api: t.boolean.optional(),
|
|
78
|
+
demo_auth: t.boolean.optional(),
|
|
79
|
+
demo_client: t.boolean.optional(),
|
|
80
|
+
demo_password: t.string.optional()
|
|
81
|
+
})
|
|
82
|
+
.optional(),
|
|
83
|
+
metadata: t.record(t.string).optional(),
|
|
84
|
+
port: t.number.optional(),
|
|
85
|
+
replication: t
|
|
86
|
+
.object({
|
|
87
|
+
connections: t.array(postgresConnection).optional()
|
|
88
|
+
})
|
|
89
|
+
.optional(),
|
|
90
|
+
storage: storageConfig,
|
|
91
|
+
sync_rules: t
|
|
92
|
+
.object({
|
|
93
|
+
content: t.string.optional(),
|
|
94
|
+
path: t.string.optional()
|
|
95
|
+
})
|
|
96
|
+
.optional()
|
|
97
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PostgresConnection } from './PowerSyncConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validate and normalize connection options.
|
|
4
|
+
*
|
|
5
|
+
* Returns destructured options.
|
|
6
|
+
*/
|
|
7
|
+
export declare function normalizeConnection(options: PostgresConnection): NormalizedPostgresConnection;
|
|
8
|
+
export interface NormalizedPostgresConnection {
|
|
9
|
+
cacert: string | undefined;
|
|
10
|
+
client_certificate: string | undefined;
|
|
11
|
+
client_private_key: string | undefined;
|
|
12
|
+
database: string;
|
|
13
|
+
hostname: string;
|
|
14
|
+
id: string;
|
|
15
|
+
password: string;
|
|
16
|
+
port: number;
|
|
17
|
+
sslmode: 'disable' | 'verify-ca' | 'verify-full';
|
|
18
|
+
tag: string;
|
|
19
|
+
username: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check whether the port is in a "safe" range.
|
|
23
|
+
*
|
|
24
|
+
* We do not support connecting to "privileged" ports.
|
|
25
|
+
*/
|
|
26
|
+
export declare function validatePort(port: number | string): number;
|
|
27
|
+
/**
|
|
28
|
+
* Construct a postgres URI, without username, password or ssl options.
|
|
29
|
+
*
|
|
30
|
+
* Only contains hostname, port, database.
|
|
31
|
+
*/
|
|
32
|
+
export declare function baseUri(options: NormalizedPostgresConnection): string;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/* eslint-disable eqeqeq */
|
|
2
|
+
/* eslint-disable no-eq-null */
|
|
3
|
+
/* eslint-disable camelcase */
|
|
4
|
+
/* eslint-disable unicorn/consistent-destructuring */
|
|
5
|
+
/* eslint-disable complexity */
|
|
6
|
+
import * as urijs from 'uri-js';
|
|
7
|
+
/**
|
|
8
|
+
* Validate and normalize connection options.
|
|
9
|
+
*
|
|
10
|
+
* Returns destructured options.
|
|
11
|
+
*/
|
|
12
|
+
export function normalizeConnection(options) {
|
|
13
|
+
let uri;
|
|
14
|
+
if (options.uri) {
|
|
15
|
+
uri = urijs.parse(options.uri);
|
|
16
|
+
if (uri.scheme !== 'postgresql' && uri.scheme !== 'postgres') {
|
|
17
|
+
// eslint-disable-next-line prettier/prettier
|
|
18
|
+
`Invalid URI - protocol must be postgresql, got ${uri.scheme}`;
|
|
19
|
+
}
|
|
20
|
+
else if (uri.scheme !== 'postgresql') {
|
|
21
|
+
uri.scheme = 'postgresql';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
uri = urijs.parse('postgresql:///');
|
|
26
|
+
}
|
|
27
|
+
const hostname = options.hostname ?? uri.host ?? '';
|
|
28
|
+
const port = validatePort(options.port ?? uri.port ?? 5432);
|
|
29
|
+
const database = options.database ?? uri.path?.slice(1) ?? '';
|
|
30
|
+
const [uri_username, uri_password] = (uri.userinfo ?? '').split(':');
|
|
31
|
+
const username = options.username ?? uri_username ?? '';
|
|
32
|
+
const password = options.password ?? uri_password ?? '';
|
|
33
|
+
const sslmode = options.sslmode ?? 'verify-full'; // Configuration not supported via URI
|
|
34
|
+
const { cacert } = options;
|
|
35
|
+
if (sslmode === 'verify-ca' && cacert == null) {
|
|
36
|
+
throw new Error('Explicit cacert is required for sslmode=verify-ca');
|
|
37
|
+
}
|
|
38
|
+
if (hostname === '') {
|
|
39
|
+
throw new Error(`hostname required`);
|
|
40
|
+
}
|
|
41
|
+
if (username === '') {
|
|
42
|
+
throw new Error(`username required`);
|
|
43
|
+
}
|
|
44
|
+
if (password === '') {
|
|
45
|
+
throw new Error(`password required`);
|
|
46
|
+
}
|
|
47
|
+
if (database === '') {
|
|
48
|
+
throw new Error(`database required`);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
cacert,
|
|
52
|
+
client_certificate: options.client_certificate ?? undefined,
|
|
53
|
+
client_private_key: options.client_private_key ?? undefined,
|
|
54
|
+
database,
|
|
55
|
+
hostname,
|
|
56
|
+
id: options.id ?? 'default',
|
|
57
|
+
password,
|
|
58
|
+
port,
|
|
59
|
+
sslmode,
|
|
60
|
+
tag: options.tag ?? 'default',
|
|
61
|
+
username
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check whether the port is in a "safe" range.
|
|
66
|
+
*
|
|
67
|
+
* We do not support connecting to "privileged" ports.
|
|
68
|
+
*/
|
|
69
|
+
export function validatePort(port) {
|
|
70
|
+
if (typeof port === 'string') {
|
|
71
|
+
port = Number(port);
|
|
72
|
+
}
|
|
73
|
+
if (port >= 1024 && port <= 49151) {
|
|
74
|
+
return port;
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`Port ${port} not supported`);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Construct a postgres URI, without username, password or ssl options.
|
|
80
|
+
*
|
|
81
|
+
* Only contains hostname, port, database.
|
|
82
|
+
*/
|
|
83
|
+
export function baseUri(options) {
|
|
84
|
+
return `postgresql://${options.hostname}:${options.port}/${options.database}`;
|
|
85
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import * as t from 'ts-codec';
|
|
2
|
+
export declare const InstanceId: t.ObjectCodec<{
|
|
3
|
+
app_id: t.IdentityCodec<t.CodecType.String>;
|
|
4
|
+
id: t.IdentityCodec<t.CodecType.String>;
|
|
5
|
+
org_id: t.IdentityCodec<t.CodecType.String>;
|
|
6
|
+
}>;
|
|
7
|
+
export type InstanceId = t.Encoded<typeof InstanceId>;
|
|
8
|
+
export declare const AppId: t.ObjectCodec<{
|
|
9
|
+
app_id: t.IdentityCodec<t.CodecType.String>;
|
|
10
|
+
org_id: t.IdentityCodec<t.CodecType.String>;
|
|
11
|
+
}>;
|
|
12
|
+
export type AppId = t.Encoded<typeof AppId>;
|
|
13
|
+
export declare const ReplicationError: t.ObjectCodec<{
|
|
14
|
+
/** Warning: Could indicate an issue. Fatal: Prevents replicating. */
|
|
15
|
+
level: t.Union<t.Codec<"warning", "warning", string, t.CodecProps>, t.LiteralCodec<"fatal">>;
|
|
16
|
+
message: t.IdentityCodec<t.CodecType.String>;
|
|
17
|
+
}>;
|
|
18
|
+
export type ReplicationError = t.Encoded<typeof ReplicationError>;
|
|
19
|
+
export declare const TableInfo: t.ObjectCodec<{
|
|
20
|
+
/** Used in data replication */
|
|
21
|
+
data_queries: t.IdentityCodec<t.CodecType.Boolean>;
|
|
22
|
+
/** Also included in the global errors array. */
|
|
23
|
+
errors: t.ArrayCodec<t.ObjectCodec<{
|
|
24
|
+
/** Warning: Could indicate an issue. Fatal: Prevents replicating. */
|
|
25
|
+
level: t.Union<t.Codec<"warning", "warning", string, t.CodecProps>, t.LiteralCodec<"fatal">>;
|
|
26
|
+
message: t.IdentityCodec<t.CodecType.String>;
|
|
27
|
+
}>>;
|
|
28
|
+
name: t.IdentityCodec<t.CodecType.String>;
|
|
29
|
+
/** Used for parameter query replication */
|
|
30
|
+
parameter_queries: t.IdentityCodec<t.CodecType.Boolean>;
|
|
31
|
+
/** Specified if this table is part of a wildcard pattern. */
|
|
32
|
+
pattern: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
|
|
33
|
+
/** Usually just ['id'] */
|
|
34
|
+
replication_id: t.ArrayCodec<t.IdentityCodec<t.CodecType.String>>;
|
|
35
|
+
schema: t.IdentityCodec<t.CodecType.String>;
|
|
36
|
+
}>;
|
|
37
|
+
export type TableInfo = t.Encoded<typeof TableInfo>;
|
|
38
|
+
export declare const SyncRulesStatus: t.ObjectCodec<{
|
|
39
|
+
connections: t.ArrayCodec<t.ObjectCodec<{
|
|
40
|
+
id: t.IdentityCodec<t.CodecType.String>;
|
|
41
|
+
/**
|
|
42
|
+
* Once initial replication is done, this moves over to
|
|
43
|
+
* logical replication.
|
|
44
|
+
*/
|
|
45
|
+
initial_replication_done: t.IdentityCodec<t.CodecType.Boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* The last time we created a new checkpoint. In other words, a transaction
|
|
48
|
+
* was successfully replicated.
|
|
49
|
+
*/
|
|
50
|
+
last_checkpoint_ts: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
|
|
51
|
+
/**
|
|
52
|
+
* The last time any replication activity was recorded.
|
|
53
|
+
*
|
|
54
|
+
* This is typically (but not always) updated together with last_lsn
|
|
55
|
+
*/
|
|
56
|
+
last_keepalive_ts: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
|
|
57
|
+
/**
|
|
58
|
+
* The last LSN that has been replicated. This may be in the middle of a transaction.
|
|
59
|
+
*/
|
|
60
|
+
last_lsn: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
|
|
61
|
+
/** Replication lag in bytes. undefined if we cannot calculate this. */
|
|
62
|
+
replication_lag_bytes: t.OptionalCodec<t.Codec<number, number, string, t.CodecProps>>;
|
|
63
|
+
/**
|
|
64
|
+
* PostgreSQL logical replication slot name.
|
|
65
|
+
*/
|
|
66
|
+
slot_name: t.IdentityCodec<t.CodecType.String>;
|
|
67
|
+
tables: t.ArrayCodec<t.ObjectCodec<{
|
|
68
|
+
/** Used in data replication */
|
|
69
|
+
data_queries: t.IdentityCodec<t.CodecType.Boolean>;
|
|
70
|
+
/** Also included in the global errors array. */
|
|
71
|
+
errors: t.ArrayCodec<t.ObjectCodec<{
|
|
72
|
+
/** Warning: Could indicate an issue. Fatal: Prevents replicating. */
|
|
73
|
+
level: t.Union<t.Codec<"warning", "warning", string, t.CodecProps>, t.LiteralCodec<"fatal">>;
|
|
74
|
+
message: t.IdentityCodec<t.CodecType.String>;
|
|
75
|
+
}>>;
|
|
76
|
+
name: t.IdentityCodec<t.CodecType.String>;
|
|
77
|
+
/** Used for parameter query replication */
|
|
78
|
+
parameter_queries: t.IdentityCodec<t.CodecType.Boolean>;
|
|
79
|
+
/** Specified if this table is part of a wildcard pattern. */
|
|
80
|
+
pattern: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
|
|
81
|
+
/** Usually just ['id'] */
|
|
82
|
+
replication_id: t.ArrayCodec<t.IdentityCodec<t.CodecType.String>>;
|
|
83
|
+
schema: t.IdentityCodec<t.CodecType.String>;
|
|
84
|
+
}>>;
|
|
85
|
+
tag: t.IdentityCodec<t.CodecType.String>;
|
|
86
|
+
}>>;
|
|
87
|
+
content: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
|
|
88
|
+
/** Sync-rule-level errors */
|
|
89
|
+
errors: t.ArrayCodec<t.ObjectCodec<{
|
|
90
|
+
/** Warning: Could indicate an issue. Fatal: Prevents replicating. */
|
|
91
|
+
level: t.Union<t.Codec<"warning", "warning", string, t.CodecProps>, t.LiteralCodec<"fatal">>;
|
|
92
|
+
message: t.IdentityCodec<t.CodecType.String>;
|
|
93
|
+
}>>;
|
|
94
|
+
}>;
|
|
95
|
+
export type SyncRulesStatus = t.Encoded<typeof SyncRulesStatus>;
|
|
96
|
+
export declare const ConnectionStatus: t.ObjectCodec<{
|
|
97
|
+
connected: t.IdentityCodec<t.CodecType.Boolean>;
|
|
98
|
+
/** Connection-level errors */
|
|
99
|
+
errors: t.ArrayCodec<t.ObjectCodec<{
|
|
100
|
+
/** Warning: Could indicate an issue. Fatal: Prevents replicating. */
|
|
101
|
+
level: t.Union<t.Codec<"warning", "warning", string, t.CodecProps>, t.LiteralCodec<"fatal">>;
|
|
102
|
+
message: t.IdentityCodec<t.CodecType.String>;
|
|
103
|
+
}>>;
|
|
104
|
+
id: t.IdentityCodec<t.CodecType.String>;
|
|
105
|
+
postgres_uri: t.IdentityCodec<t.CodecType.String>;
|
|
106
|
+
}>;
|
|
107
|
+
export type ConnectionStatus = t.Encoded<typeof ConnectionStatus>;
|
|
108
|
+
export declare const DatabaseSchema: t.ObjectCodec<{
|
|
109
|
+
name: t.IdentityCodec<t.CodecType.String>;
|
|
110
|
+
tables: t.ArrayCodec<t.ObjectCodec<{
|
|
111
|
+
columns: t.ArrayCodec<t.ObjectCodec<{
|
|
112
|
+
name: t.IdentityCodec<t.CodecType.String>;
|
|
113
|
+
/**
|
|
114
|
+
* Internal postgres type, e.g. "varchar[]".
|
|
115
|
+
*/
|
|
116
|
+
pg_type: t.IdentityCodec<t.CodecType.String>;
|
|
117
|
+
/**
|
|
118
|
+
* Full type name, e.g. "character varying(255)[]"
|
|
119
|
+
*/
|
|
120
|
+
type: t.IdentityCodec<t.CodecType.String>;
|
|
121
|
+
}>>;
|
|
122
|
+
name: t.IdentityCodec<t.CodecType.String>;
|
|
123
|
+
}>>;
|
|
124
|
+
}>;
|
|
125
|
+
export type DatabaseSchema = t.Encoded<typeof DatabaseSchema>;
|
|
126
|
+
export declare const InstanceSchema: t.ObjectCodec<{
|
|
127
|
+
connections: t.ArrayCodec<t.ObjectCodec<{
|
|
128
|
+
id: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
|
|
129
|
+
schemas: t.ArrayCodec<t.ObjectCodec<{
|
|
130
|
+
name: t.IdentityCodec<t.CodecType.String>;
|
|
131
|
+
tables: t.ArrayCodec<t.ObjectCodec<{
|
|
132
|
+
columns: t.ArrayCodec<t.ObjectCodec<{
|
|
133
|
+
name: t.IdentityCodec<t.CodecType.String>;
|
|
134
|
+
/**
|
|
135
|
+
* Internal postgres type, e.g. "varchar[]".
|
|
136
|
+
*/
|
|
137
|
+
pg_type: t.IdentityCodec<t.CodecType.String>;
|
|
138
|
+
/**
|
|
139
|
+
* Full type name, e.g. "character varying(255)[]"
|
|
140
|
+
*/
|
|
141
|
+
type: t.IdentityCodec<t.CodecType.String>;
|
|
142
|
+
}>>;
|
|
143
|
+
name: t.IdentityCodec<t.CodecType.String>;
|
|
144
|
+
}>>;
|
|
145
|
+
}>>;
|
|
146
|
+
tag: t.IdentityCodec<t.CodecType.String>;
|
|
147
|
+
}>>;
|
|
148
|
+
}>;
|
|
149
|
+
export type InstanceSchema = t.Encoded<typeof InstanceSchema>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import * as t from 'ts-codec';
|
|
3
|
+
export const InstanceId = t.object({
|
|
4
|
+
app_id: t.string,
|
|
5
|
+
id: t.string,
|
|
6
|
+
org_id: t.string
|
|
7
|
+
});
|
|
8
|
+
export const AppId = t.object({
|
|
9
|
+
app_id: t.string,
|
|
10
|
+
org_id: t.string
|
|
11
|
+
});
|
|
12
|
+
export const ReplicationError = t.object({
|
|
13
|
+
/** Warning: Could indicate an issue. Fatal: Prevents replicating. */
|
|
14
|
+
level: t.literal('warning').or(t.literal('fatal')),
|
|
15
|
+
message: t.string
|
|
16
|
+
});
|
|
17
|
+
export const TableInfo = t.object({
|
|
18
|
+
/** Used in data replication */
|
|
19
|
+
data_queries: t.boolean,
|
|
20
|
+
/** Also included in the global errors array. */
|
|
21
|
+
errors: t.array(ReplicationError),
|
|
22
|
+
name: t.string,
|
|
23
|
+
/** Used for parameter query replication */
|
|
24
|
+
parameter_queries: t.boolean,
|
|
25
|
+
/** Specified if this table is part of a wildcard pattern. */
|
|
26
|
+
pattern: t.string.optional(),
|
|
27
|
+
/** Usually just ['id'] */
|
|
28
|
+
replication_id: t.array(t.string),
|
|
29
|
+
schema: t.string
|
|
30
|
+
});
|
|
31
|
+
export const SyncRulesStatus = t.object({
|
|
32
|
+
connections: t.array(t.object({
|
|
33
|
+
id: t.string,
|
|
34
|
+
/**
|
|
35
|
+
* Once initial replication is done, this moves over to
|
|
36
|
+
* logical replication.
|
|
37
|
+
*/
|
|
38
|
+
initial_replication_done: t.boolean,
|
|
39
|
+
/**
|
|
40
|
+
* The last time we created a new checkpoint. In other words, a transaction
|
|
41
|
+
* was successfully replicated.
|
|
42
|
+
*/
|
|
43
|
+
last_checkpoint_ts: t.string.optional(),
|
|
44
|
+
/**
|
|
45
|
+
* The last time any replication activity was recorded.
|
|
46
|
+
*
|
|
47
|
+
* This is typically (but not always) updated together with last_lsn
|
|
48
|
+
*/
|
|
49
|
+
last_keepalive_ts: t.string.optional(),
|
|
50
|
+
/**
|
|
51
|
+
* The last LSN that has been replicated. This may be in the middle of a transaction.
|
|
52
|
+
*/
|
|
53
|
+
last_lsn: t.string.optional(),
|
|
54
|
+
/** Replication lag in bytes. undefined if we cannot calculate this. */
|
|
55
|
+
replication_lag_bytes: t.number.optional(),
|
|
56
|
+
/**
|
|
57
|
+
* PostgreSQL logical replication slot name.
|
|
58
|
+
*/
|
|
59
|
+
slot_name: t.string,
|
|
60
|
+
tables: t.array(TableInfo),
|
|
61
|
+
tag: t.string
|
|
62
|
+
})),
|
|
63
|
+
content: t.string.optional(),
|
|
64
|
+
/** Sync-rule-level errors */
|
|
65
|
+
errors: t.array(ReplicationError)
|
|
66
|
+
});
|
|
67
|
+
export const ConnectionStatus = t.object({
|
|
68
|
+
connected: t.boolean,
|
|
69
|
+
/** Connection-level errors */
|
|
70
|
+
errors: t.array(ReplicationError),
|
|
71
|
+
id: t.string,
|
|
72
|
+
postgres_uri: t.string
|
|
73
|
+
});
|
|
74
|
+
export const DatabaseSchema = t.object({
|
|
75
|
+
name: t.string,
|
|
76
|
+
tables: t.array(t.object({
|
|
77
|
+
columns: t.array(t.object({
|
|
78
|
+
name: t.string,
|
|
79
|
+
/**
|
|
80
|
+
* Internal postgres type, e.g. "varchar[]".
|
|
81
|
+
*/
|
|
82
|
+
pg_type: t.string,
|
|
83
|
+
/**
|
|
84
|
+
* Full type name, e.g. "character varying(255)[]"
|
|
85
|
+
*/
|
|
86
|
+
type: t.string
|
|
87
|
+
})),
|
|
88
|
+
name: t.string
|
|
89
|
+
}))
|
|
90
|
+
});
|
|
91
|
+
export const InstanceSchema = t.object({
|
|
92
|
+
connections: t.array(t.object({
|
|
93
|
+
id: t.string.optional(),
|
|
94
|
+
schemas: t.array(DatabaseSchema),
|
|
95
|
+
tag: t.string
|
|
96
|
+
}))
|
|
97
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * as hostedConfig from './config/HostedConfig.js';
|
|
2
|
+
export { HostedPostgresConnection, HostedSecret, HostedSecretRef, HostedSecretValue, PowerSyncHostedConfig, isHostedSecretValue, powerSyncHostedConfig } from './config/HostedConfig.js';
|
|
3
|
+
export * as configFile from './config/PowerSyncConfig.js';
|
|
4
|
+
export { PostgresConnection } from './config/PowerSyncConfig.js';
|
|
5
|
+
export * as internal_routes from './internal_routes.js';
|
|
6
|
+
export * as routes from './routes.js';
|
|
7
|
+
export * from './definitions.js';
|
|
8
|
+
export * from './config/normalize.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
export * as hostedConfig from './config/HostedConfig.js';
|
|
3
|
+
export { isHostedSecretValue, powerSyncHostedConfig } from './config/HostedConfig.js';
|
|
4
|
+
export * as configFile from './config/PowerSyncConfig.js';
|
|
5
|
+
export * as internal_routes from './internal_routes.js';
|
|
6
|
+
export * as routes from './routes.js';
|
|
7
|
+
export * from './definitions.js';
|
|
8
|
+
export * from './config/normalize.js';
|