powersync 0.7.0 → 0.8.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 +33 -24
- package/dist/commands/instance/create.d.ts +18 -2
- package/dist/commands/instance/create.js +95 -86
- package/dist/commands/instance/deploy.d.ts +5 -1
- package/dist/commands/instance/deploy.js +37 -37
- package/dist/commands.utils.d.ts +2 -2
- package/dist/commands.utils.js +46 -7
- package/dist/connection.utils.d.ts +56 -0
- package/dist/connection.utils.js +76 -0
- package/dist/instance-command-flags.d.ts +13 -0
- package/dist/instance-command-flags.js +22 -0
- package/dist/service/accounts.client.js +1 -1
- package/dist/service/powersync.client.js +1 -1
- package/dist/service/utils.js +1 -1
- package/dist/utils.d.ts +7 -0
- package/oclif.manifest.json +72 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ EXAMPLES
|
|
|
90
90
|
$ npx powersync init
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
_See code: [src/commands/init.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
93
|
+
_See code: [src/commands/init.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/init.ts)_
|
|
94
94
|
|
|
95
95
|
## `powersync instance config`
|
|
96
96
|
|
|
@@ -107,7 +107,7 @@ EXAMPLES
|
|
|
107
107
|
$ npx powersync instance config
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
_See code: [src/commands/instance/config.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
110
|
+
_See code: [src/commands/instance/config.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/config.ts)_
|
|
111
111
|
|
|
112
112
|
## `powersync instance create`
|
|
113
113
|
|
|
@@ -115,8 +115,8 @@ Create a new instance.
|
|
|
115
115
|
|
|
116
116
|
```
|
|
117
117
|
USAGE
|
|
118
|
-
$ npx powersync instance create [-
|
|
119
|
-
<value>] [-s] [-j <value>] [-b]
|
|
118
|
+
$ npx powersync instance create [-i <value>] [--protocol <value>] [-r <value>] [-t postgresql|mongodb] [-n <value>] [-h
|
|
119
|
+
<value>] [-w <value>] [-a <value>] [-o <value>] [-s] [-j <value>] [-b]
|
|
120
120
|
|
|
121
121
|
FLAGS
|
|
122
122
|
-a, --jwtAudiences=<value> JWT audiences (comma separated).
|
|
@@ -128,7 +128,10 @@ FLAGS
|
|
|
128
128
|
-o, --port=<value> Port number to connect to database.
|
|
129
129
|
-r, --region=<value> Region to deploy instance to.
|
|
130
130
|
-s, --skipInteraction Skip interactivity.
|
|
131
|
+
-t, --connectionType=<option> Type of database connection.
|
|
132
|
+
<options: postgresql|mongodb>
|
|
131
133
|
-w, --jwksUri=<value> JWKS URI (must include https://).
|
|
134
|
+
--protocol=<value> Database protocol to use (e.g., for MongoDB: mongodb+srv or mongodb).
|
|
132
135
|
|
|
133
136
|
DESCRIPTION
|
|
134
137
|
Create a new instance.
|
|
@@ -137,7 +140,7 @@ EXAMPLES
|
|
|
137
140
|
$ npx powersync instance create
|
|
138
141
|
```
|
|
139
142
|
|
|
140
|
-
_See code: [src/commands/instance/create.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
143
|
+
_See code: [src/commands/instance/create.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/create.ts)_
|
|
141
144
|
|
|
142
145
|
## `powersync instance deploy`
|
|
143
146
|
|
|
@@ -145,16 +148,22 @@ Deploy changes to an existing instance.
|
|
|
145
148
|
|
|
146
149
|
```
|
|
147
150
|
USAGE
|
|
148
|
-
$ npx powersync instance deploy [
|
|
151
|
+
$ npx powersync instance deploy [--protocol <value>] [-r <value>] [-t postgresql|mongodb] [-n <value>] [-h <value>] [-w
|
|
152
|
+
<value>] [-a <value>] [-o <value>] [-s] [-j <value>] [-b]
|
|
149
153
|
|
|
150
154
|
FLAGS
|
|
151
|
-
-a, --jwtAudiences=<value>
|
|
152
|
-
-b, --[no-]useSupabaseAuth
|
|
153
|
-
-h, --hostname=<value>
|
|
154
|
-
-
|
|
155
|
-
-
|
|
156
|
-
-
|
|
157
|
-
-
|
|
155
|
+
-a, --jwtAudiences=<value> JWT audiences (comma separated).
|
|
156
|
+
-b, --[no-]useSupabaseAuth Use Supabase auth.
|
|
157
|
+
-h, --hostname=<value> Hostname to connect to database.
|
|
158
|
+
-j, --supabaseJWTSecret=<value> Supabase JWT secret
|
|
159
|
+
-n, --databaseName=<value> Name of the database.
|
|
160
|
+
-o, --port=<value> Port number to connect to database.
|
|
161
|
+
-r, --region=<value> Region to deploy instance to.
|
|
162
|
+
-s, --skipInteraction Skip interactivity.
|
|
163
|
+
-t, --connectionType=<option> Type of database connection.
|
|
164
|
+
<options: postgresql|mongodb>
|
|
165
|
+
-w, --jwksUri=<value> JWKS URI (must include https://).
|
|
166
|
+
--protocol=<value> Database protocol to use (e.g., for MongoDB: mongodb+srv or mongodb).
|
|
158
167
|
|
|
159
168
|
DESCRIPTION
|
|
160
169
|
Deploy changes to an existing instance.
|
|
@@ -163,7 +172,7 @@ EXAMPLES
|
|
|
163
172
|
$ npx powersync instance deploy
|
|
164
173
|
```
|
|
165
174
|
|
|
166
|
-
_See code: [src/commands/instance/deploy.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
175
|
+
_See code: [src/commands/instance/deploy.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/deploy.ts)_
|
|
167
176
|
|
|
168
177
|
## `powersync instance destroy`
|
|
169
178
|
|
|
@@ -183,7 +192,7 @@ EXAMPLES
|
|
|
183
192
|
$ npx powersync instance destroy
|
|
184
193
|
```
|
|
185
194
|
|
|
186
|
-
_See code: [src/commands/instance/destroy.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
195
|
+
_See code: [src/commands/instance/destroy.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/destroy.ts)_
|
|
187
196
|
|
|
188
197
|
## `powersync instance generate-dev-token`
|
|
189
198
|
|
|
@@ -204,7 +213,7 @@ EXAMPLES
|
|
|
204
213
|
$ npx powersync instance generate-dev-token
|
|
205
214
|
```
|
|
206
215
|
|
|
207
|
-
_See code: [src/commands/instance/generate-dev-token.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
216
|
+
_See code: [src/commands/instance/generate-dev-token.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/generate-dev-token.ts)_
|
|
208
217
|
|
|
209
218
|
## `powersync instance schema`
|
|
210
219
|
|
|
@@ -221,7 +230,7 @@ EXAMPLES
|
|
|
221
230
|
$ npx powersync instance schema
|
|
222
231
|
```
|
|
223
232
|
|
|
224
|
-
_See code: [src/commands/instance/schema.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
233
|
+
_See code: [src/commands/instance/schema.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/schema.ts)_
|
|
225
234
|
|
|
226
235
|
## `powersync instance set`
|
|
227
236
|
|
|
@@ -243,7 +252,7 @@ EXAMPLES
|
|
|
243
252
|
$ npx powersync instance set --instanceId=1234
|
|
244
253
|
```
|
|
245
254
|
|
|
246
|
-
_See code: [src/commands/instance/set.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
255
|
+
_See code: [src/commands/instance/set.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/set.ts)_
|
|
247
256
|
|
|
248
257
|
## `powersync instance status`
|
|
249
258
|
|
|
@@ -268,7 +277,7 @@ EXAMPLES
|
|
|
268
277
|
$ npx powersync instance status --orgId=1234 --projectId=1234 --instanceId=1234 --authToken=1234
|
|
269
278
|
```
|
|
270
279
|
|
|
271
|
-
_See code: [src/commands/instance/status.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
280
|
+
_See code: [src/commands/instance/status.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/status.ts)_
|
|
272
281
|
|
|
273
282
|
## `powersync instance stop`
|
|
274
283
|
|
|
@@ -288,7 +297,7 @@ EXAMPLES
|
|
|
288
297
|
$ npx powersync instance stop
|
|
289
298
|
```
|
|
290
299
|
|
|
291
|
-
_See code: [src/commands/instance/stop.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
300
|
+
_See code: [src/commands/instance/stop.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/stop.ts)_
|
|
292
301
|
|
|
293
302
|
## `powersync instance sync-rules deploy`
|
|
294
303
|
|
|
@@ -313,7 +322,7 @@ EXAMPLES
|
|
|
313
322
|
$ npx powersync instance sync-rules deploy -f path/to/file
|
|
314
323
|
```
|
|
315
324
|
|
|
316
|
-
_See code: [src/commands/instance/sync-rules/deploy.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
325
|
+
_See code: [src/commands/instance/sync-rules/deploy.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/sync-rules/deploy.ts)_
|
|
317
326
|
|
|
318
327
|
## `powersync instance sync-rules generate-schema`
|
|
319
328
|
|
|
@@ -339,7 +348,7 @@ EXAMPLES
|
|
|
339
348
|
$ npx powersync instance sync-rules generate-schema -f path/to/file
|
|
340
349
|
```
|
|
341
350
|
|
|
342
|
-
_See code: [src/commands/instance/sync-rules/generate-schema.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
351
|
+
_See code: [src/commands/instance/sync-rules/generate-schema.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/sync-rules/generate-schema.ts)_
|
|
343
352
|
|
|
344
353
|
## `powersync instance sync-rules validate`
|
|
345
354
|
|
|
@@ -363,7 +372,7 @@ EXAMPLES
|
|
|
363
372
|
$ npx powersync instance sync-rules validate -f path/to/file
|
|
364
373
|
```
|
|
365
374
|
|
|
366
|
-
_See code: [src/commands/instance/sync-rules/validate.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
375
|
+
_See code: [src/commands/instance/sync-rules/validate.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instance/sync-rules/validate.ts)_
|
|
367
376
|
|
|
368
377
|
## `powersync instances`
|
|
369
378
|
|
|
@@ -380,5 +389,5 @@ EXAMPLES
|
|
|
380
389
|
$ npx powersync instances
|
|
381
390
|
```
|
|
382
391
|
|
|
383
|
-
_See code: [src/commands/instances.ts](https://github.com/powersync-ja/cli/blob/v0.
|
|
392
|
+
_See code: [src/commands/instances.ts](https://github.com/powersync-ja/cli/blob/v0.8.0/src/commands/instances.ts)_
|
|
384
393
|
<!-- commandsstop -->
|
|
@@ -3,18 +3,34 @@ export default class InstanceCreate extends Command {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
connectionType: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
7
|
databaseName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
8
|
databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
9
|
databaseUsername: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
10
|
hostname: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
11
|
jwksUri: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
12
|
jwtAudiences: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
|
-
name: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
13
13
|
port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
14
|
-
region: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
15
14
|
skipInteraction: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
16
15
|
supabaseJWTSecret: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
17
16
|
useSupabaseAuth: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
17
|
+
name: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
18
|
+
protocol: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
19
|
+
region: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
18
20
|
};
|
|
19
21
|
run(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Create deployment configuration from flags and answers
|
|
24
|
+
* @param flags - Command flags from CLI
|
|
25
|
+
* @param answers - User answers from interactive prompts
|
|
26
|
+
* @returns Object containing deployment config and database connection
|
|
27
|
+
*/
|
|
28
|
+
private createDeployConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Gather user input through interactive prompts if needed
|
|
31
|
+
* @param flags - Command flags from CLI
|
|
32
|
+
* @param regions - Available regions for deployment
|
|
33
|
+
* @returns Object containing user answers and questions that were asked
|
|
34
|
+
*/
|
|
35
|
+
private gatherInputs;
|
|
20
36
|
}
|
|
@@ -1,92 +1,75 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
import { Command, Flags, ux } from '@oclif/core';
|
|
2
3
|
import inquirer from 'inquirer';
|
|
3
4
|
import ora from 'ora';
|
|
4
5
|
import { generateCommonDeployQuestions } from '../../commands.utils.js';
|
|
6
|
+
import { buildDatabaseConnection } from '../../connection.utils.js';
|
|
7
|
+
import { generateCommonInstanceConfigFlags } from '../../instance-command-flags.js';
|
|
5
8
|
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
6
9
|
import { bold, checkThatEnvVariablesAreSet, green, red, updateEnvFileVariableValue } from '../../utils.js';
|
|
7
10
|
export default class InstanceCreate extends Command {
|
|
8
11
|
static description = 'Create a new instance.';
|
|
9
12
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
10
13
|
static flags = {
|
|
11
|
-
databaseName: Flags.string({ char: 'n', description: 'Name of the database.' }),
|
|
12
|
-
databasePassword: Flags.string({ char: 'p', description: 'Password of the database.', hidden: true }),
|
|
13
|
-
databaseUsername: Flags.string({ char: 'u', description: 'Username of the database.', hidden: true }),
|
|
14
|
-
hostname: Flags.string({ char: 'h', description: 'Hostname to connect to database.' }),
|
|
15
|
-
jwksUri: Flags.string({ char: 'w', description: 'JWKS URI (must include https://).' }),
|
|
16
|
-
jwtAudiences: Flags.string({ char: 'a', default: '', description: 'JWT audiences (comma separated).' }),
|
|
17
14
|
name: Flags.string({ char: 'i', description: 'Name of the instance.' }),
|
|
18
|
-
|
|
15
|
+
protocol: Flags.string({ description: 'Database protocol to use (e.g., for MongoDB: mongodb+srv or mongodb).' }),
|
|
19
16
|
region: Flags.string({ char: 'r', description: 'Region to deploy instance to.' }),
|
|
20
|
-
|
|
21
|
-
supabaseJWTSecret: Flags.string({ allowNo: true, char: 'j', description: 'Supabase JWT secret' }),
|
|
22
|
-
useSupabaseAuth: Flags.boolean({ allowNo: true, char: 'b', description: 'Use Supabase auth.' })
|
|
17
|
+
...generateCommonInstanceConfigFlags()
|
|
23
18
|
};
|
|
24
19
|
async run() {
|
|
25
20
|
checkThatEnvVariablesAreSet(this.config.bin);
|
|
26
|
-
const
|
|
21
|
+
const parsed = await this.parse(InstanceCreate);
|
|
22
|
+
const flags = parsed.flags;
|
|
27
23
|
const regions = await PowerSyncClient.getRegions();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
jwtAudiences: undefined,
|
|
35
|
-
name: undefined,
|
|
36
|
-
port: undefined,
|
|
37
|
-
region: undefined,
|
|
38
|
-
useSupabaseAuth: undefined
|
|
39
|
-
};
|
|
40
|
-
if (!flags.skipInteraction) {
|
|
41
|
-
const questions = [
|
|
42
|
-
{
|
|
43
|
-
message: 'What do you want to name your instance?',
|
|
44
|
-
name: 'name',
|
|
45
|
-
type: 'input',
|
|
46
|
-
validate(value) {
|
|
47
|
-
return value.length > 3 ? true : 'Please enter a name with at least 3 characters.';
|
|
48
|
-
},
|
|
49
|
-
when: !flags.name
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
choices: regions.map((region) => region.toUpperCase()),
|
|
53
|
-
message: 'What region do you want to use?',
|
|
54
|
-
name: 'region',
|
|
55
|
-
type: 'list',
|
|
56
|
-
when: !flags.region
|
|
57
|
-
},
|
|
58
|
-
...generateCommonDeployQuestions(flags)
|
|
59
|
-
];
|
|
60
|
-
answers = await inquirer.prompt(questions);
|
|
24
|
+
const { answers } = await this.gatherInputs(flags, regions);
|
|
25
|
+
const { config, connection } = this.createDeployConfig(flags, answers);
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
const connectionResponse = await PowerSyncClient.testConnection(connection);
|
|
28
|
+
if (connectionResponse.error) {
|
|
29
|
+
return ux.error(red(`There was an issue testing the connection from the PowerSync service to your database: ${connectionResponse.error}. Please double-check your entered values.`), { exit: 1 });
|
|
61
30
|
}
|
|
31
|
+
const spinner = ora({
|
|
32
|
+
prefixText: 'Creating instance.\n',
|
|
33
|
+
spinner: 'moon',
|
|
34
|
+
suffixText: '\nThis may take a few minutes.\n'
|
|
35
|
+
});
|
|
36
|
+
spinner.start();
|
|
62
37
|
const instanceName = flags.name || answers.name;
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
38
|
+
const instance = await PowerSyncClient.createInstance(instanceName);
|
|
39
|
+
await PowerSyncClient.deployInstance(config, instance.id);
|
|
40
|
+
const status = await PowerSyncClient.waitForStatusChange(instance.id);
|
|
41
|
+
spinner.stop();
|
|
42
|
+
if (status === 'failed') {
|
|
43
|
+
return ux.error(red(`There was an error creating the instance. Please try again.`), { exit: 1 });
|
|
44
|
+
}
|
|
45
|
+
updateEnvFileVariableValue(PowerSyncClient.ENV_VARIABLES.INSTANCE_ID, instance.id);
|
|
46
|
+
ux.log(green(`Instance with id ${bold(instance.id)} has been created successfully.`));
|
|
47
|
+
ux.log(green(`Current instance has been set to ${bold(instance.id)}.`));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create deployment configuration from flags and answers
|
|
51
|
+
* @param flags - Command flags from CLI
|
|
52
|
+
* @param answers - User answers from interactive prompts
|
|
53
|
+
* @returns Object containing deployment config and database connection
|
|
54
|
+
*/
|
|
55
|
+
createDeployConfig(flags, answers) {
|
|
68
56
|
const region = flags.region?.toLowerCase() || answers.region?.toLowerCase();
|
|
69
57
|
const useSupabaseAuth = flags.useSupabaseAuth || answers.useSupabaseAuth;
|
|
70
58
|
const jwksUri = flags.jwksUri || answers.jwksUri;
|
|
71
59
|
const answerAudiences = answers.jwtAudiences ? answers.jwtAudiences.split(',') : [];
|
|
72
60
|
const flagsAudiences = flags.jwtAudiences ? flags.jwtAudiences.split(',') : [];
|
|
73
|
-
const audiences = [...flagsAudiences, ...answerAudiences];
|
|
61
|
+
const audiences = [...new Set([...flagsAudiences, ...answerAudiences])];
|
|
74
62
|
const supabaseJWTSecret = flags.supabaseJWTSecret ?? answers.supabaseJWTSecret;
|
|
75
|
-
//
|
|
76
|
-
const connection = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
sslmode: 'verify-full',
|
|
86
|
-
tag: 'default',
|
|
87
|
-
type: 'postgresql',
|
|
88
|
-
username: databaseUsername
|
|
89
|
-
};
|
|
63
|
+
// Build database connection based on type
|
|
64
|
+
const connection = buildDatabaseConnection({
|
|
65
|
+
connectionType: flags.connectionType || answers.connectionType,
|
|
66
|
+
databaseName: flags.databaseName || answers.databaseName,
|
|
67
|
+
databasePassword: flags.databasePassword || answers.databasePassword,
|
|
68
|
+
databaseUsername: flags.databaseUsername || answers.databaseUsername,
|
|
69
|
+
hostname: flags.hostname || answers.hostname,
|
|
70
|
+
port: flags.port || answers.port,
|
|
71
|
+
protocol: flags.protocol || answers.protocol
|
|
72
|
+
});
|
|
90
73
|
const config = {
|
|
91
74
|
client_auth: {
|
|
92
75
|
additional_audiences: audiences || undefined,
|
|
@@ -98,31 +81,57 @@ export default class InstanceCreate extends Command {
|
|
|
98
81
|
}
|
|
99
82
|
: undefined
|
|
100
83
|
},
|
|
101
|
-
region,
|
|
84
|
+
region: region,
|
|
102
85
|
replication: {
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
87
|
connections: [connection]
|
|
104
88
|
}
|
|
105
89
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
90
|
+
return { config, connection };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Gather user input through interactive prompts if needed
|
|
94
|
+
* @param flags - Command flags from CLI
|
|
95
|
+
* @param regions - Available regions for deployment
|
|
96
|
+
* @returns Object containing user answers and questions that were asked
|
|
97
|
+
*/
|
|
98
|
+
async gatherInputs(flags, regions) {
|
|
99
|
+
const answers = {
|
|
100
|
+
connectionType: undefined,
|
|
101
|
+
databaseName: undefined,
|
|
102
|
+
databasePassword: undefined,
|
|
103
|
+
databaseUsername: undefined,
|
|
104
|
+
hostname: undefined,
|
|
105
|
+
jwksUri: undefined,
|
|
106
|
+
jwtAudiences: undefined,
|
|
107
|
+
name: undefined,
|
|
108
|
+
port: undefined,
|
|
109
|
+
region: undefined,
|
|
110
|
+
useSupabaseAuth: undefined
|
|
111
|
+
};
|
|
112
|
+
if (flags.skipInteraction) {
|
|
113
|
+
return { answers, questions: [] };
|
|
123
114
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
115
|
+
const questions = [
|
|
116
|
+
{
|
|
117
|
+
message: 'What do you want to name your instance?',
|
|
118
|
+
name: 'name',
|
|
119
|
+
type: 'input',
|
|
120
|
+
validate(value) {
|
|
121
|
+
return value.length > 3 ? true : 'Please enter a name with at least 3 characters.';
|
|
122
|
+
},
|
|
123
|
+
when: !flags.name
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
choices: regions.map((region) => region.toUpperCase()),
|
|
127
|
+
message: 'What region do you want to use?',
|
|
128
|
+
name: 'region',
|
|
129
|
+
type: 'list',
|
|
130
|
+
when: !flags.region
|
|
131
|
+
},
|
|
132
|
+
...generateCommonDeployQuestions(flags)
|
|
133
|
+
];
|
|
134
|
+
const promptAnswers = await inquirer.prompt(questions);
|
|
135
|
+
return { answers: promptAnswers, questions };
|
|
127
136
|
}
|
|
128
137
|
}
|
|
@@ -3,15 +3,19 @@ export default class InstanceDeploy extends Command {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
connectionType: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
7
|
databaseName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
8
|
databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
9
|
databaseUsername: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
10
|
hostname: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
11
|
jwksUri: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
-
jwtAudiences: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string
|
|
12
|
+
jwtAudiences: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
13
|
port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
13
14
|
skipInteraction: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
15
|
+
supabaseJWTSecret: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
14
16
|
useSupabaseAuth: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
17
|
+
protocol: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
18
|
+
region: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
15
19
|
};
|
|
16
20
|
run(): Promise<void>;
|
|
17
21
|
}
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
import { Command, Flags, ux } from '@oclif/core';
|
|
2
3
|
import inquirer from 'inquirer';
|
|
3
4
|
import ora from 'ora';
|
|
4
5
|
import { generateCommonDeployQuestions } from '../../commands.utils.js';
|
|
6
|
+
import { buildDatabaseConnection } from '../../connection.utils.js';
|
|
7
|
+
import { generateCommonInstanceConfigFlags } from '../../instance-command-flags.js';
|
|
5
8
|
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
6
9
|
import { bold, checkThatEnvVariablesAreSet, green, red } from '../../utils.js';
|
|
7
10
|
export default class InstanceDeploy extends Command {
|
|
8
11
|
static description = 'Deploy changes to an existing instance.';
|
|
9
12
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
10
13
|
static flags = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
hostname: Flags.string({ char: 'h', description: 'Hostname to connect to database.' }),
|
|
15
|
-
jwksUri: Flags.string({ char: 'w', description: 'JWKS URI (must include https://).' }),
|
|
16
|
-
jwtAudiences: Flags.string({ char: 'a', description: 'JWT audiences (comma separated).' }),
|
|
17
|
-
port: Flags.integer({ char: 'o', description: 'Port number to connect to database.' }),
|
|
18
|
-
skipInteraction: Flags.boolean({ char: 's', description: 'Skip interactivity.' }),
|
|
19
|
-
useSupabaseAuth: Flags.boolean({ allowNo: true, char: 'b', description: 'Use Supabase auth.' })
|
|
14
|
+
protocol: Flags.string({ description: 'Database protocol to use (e.g., for MongoDB: mongodb+srv or mongodb).' }),
|
|
15
|
+
region: Flags.string({ char: 'r', description: 'Region to deploy instance to.' }),
|
|
16
|
+
...generateCommonInstanceConfigFlags()
|
|
20
17
|
};
|
|
21
18
|
async run() {
|
|
22
19
|
checkThatEnvVariablesAreSet(this.config.bin, true);
|
|
23
|
-
const
|
|
20
|
+
const parsed = await this.parse(InstanceDeploy);
|
|
21
|
+
const flags = parsed.flags;
|
|
24
22
|
let answers = {
|
|
23
|
+
connectionType: undefined,
|
|
25
24
|
databaseName: undefined,
|
|
26
25
|
databasePassword: undefined,
|
|
27
26
|
databaseUsername: undefined,
|
|
28
27
|
hostname: undefined,
|
|
29
|
-
jwksAudiences: undefined,
|
|
30
28
|
jwksUri: undefined,
|
|
29
|
+
jwtAudiences: undefined,
|
|
31
30
|
port: undefined,
|
|
31
|
+
protocol: undefined,
|
|
32
|
+
region: undefined,
|
|
32
33
|
useSupabaseAuth: undefined
|
|
33
34
|
};
|
|
34
35
|
if (!flags.skipInteraction) {
|
|
35
36
|
const questions = generateCommonDeployQuestions(flags);
|
|
36
37
|
answers = await inquirer.prompt(questions);
|
|
37
38
|
}
|
|
38
|
-
const port = flags.port || answers.port;
|
|
39
|
-
const password = flags.databasePassword || answers.databasePassword;
|
|
40
|
-
const hostname = flags.hostname || answers.hostname;
|
|
41
|
-
const databaseName = flags.databaseName || answers.databaseName;
|
|
42
|
-
const databaseUsername = flags.databaseUsername || answers.databaseUsername;
|
|
43
39
|
const useSupabaseAuth = flags.useSupabaseAuth || answers.useSupabaseAuth;
|
|
44
40
|
const jwksUri = flags.jwksUri || answers.jwksUri;
|
|
45
|
-
const answerAudiences = answers.
|
|
46
|
-
const flagsAudiences = flags.
|
|
47
|
-
const audiences = flagsAudiences
|
|
41
|
+
const answerAudiences = answers.jwtAudiences ? answers.jwtAudiences.split(',') : [];
|
|
42
|
+
const flagsAudiences = flags.jwtAudiences ? flags.jwtAudiences.split(',') : [];
|
|
43
|
+
const audiences = [...new Set([...flagsAudiences, ...answerAudiences])];
|
|
44
|
+
const supabaseJWTSecret = flags.supabaseJWTSecret ?? answers.supabaseJWTSecret;
|
|
48
45
|
const instanceConfig = await PowerSyncClient.getInstanceConfig();
|
|
49
|
-
const
|
|
46
|
+
const region = instanceConfig.config?.region || flags.region || answers.region;
|
|
47
|
+
if (!region) {
|
|
48
|
+
ux.error(red(`No region is configured for this instance. Please specify a region in the instance configuration or via command flags before deploying.`), { exit: 1 });
|
|
49
|
+
}
|
|
50
|
+
const connection = buildDatabaseConnection({
|
|
51
|
+
connectionType: flags.connectionType || answers.connectionType,
|
|
52
|
+
databaseName: flags.databaseName || answers.databaseName,
|
|
53
|
+
databasePassword: flags.databasePassword || answers.databasePassword,
|
|
54
|
+
databaseUsername: flags.databaseUsername || answers.databaseUsername,
|
|
55
|
+
hostname: flags.hostname || answers.hostname,
|
|
56
|
+
port: flags.port || answers.port,
|
|
57
|
+
protocol: flags.protocol || answers.protocol
|
|
58
|
+
});
|
|
50
59
|
const config = {
|
|
51
60
|
client_auth: {
|
|
52
61
|
additional_audiences: audiences || undefined,
|
|
53
62
|
jwks_uri: jwksUri || undefined,
|
|
54
|
-
supabase: useSupabaseAuth
|
|
63
|
+
supabase: useSupabaseAuth,
|
|
64
|
+
supabase_jwt_secret: supabaseJWTSecret
|
|
65
|
+
? {
|
|
66
|
+
secret: supabaseJWTSecret
|
|
67
|
+
}
|
|
68
|
+
: undefined
|
|
55
69
|
},
|
|
56
70
|
region,
|
|
57
71
|
replication: {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
database: databaseName,
|
|
61
|
-
debug_api: false,
|
|
62
|
-
hostname,
|
|
63
|
-
name: 'Default',
|
|
64
|
-
password: {
|
|
65
|
-
secret: password
|
|
66
|
-
},
|
|
67
|
-
port: Number(port),
|
|
68
|
-
sslmode: 'verify-full',
|
|
69
|
-
tag: 'default',
|
|
70
|
-
type: 'postgresql',
|
|
71
|
-
username: databaseUsername
|
|
72
|
-
}
|
|
73
|
-
]
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
connections: [connection]
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
const spinner = ora({
|
package/dist/commands.utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const generateCommonDeployQuestions: (flags: any) =>
|
|
1
|
+
import type { DistinctQuestion } from 'inquirer';
|
|
2
|
+
export declare const generateCommonDeployQuestions: (flags: any) => DistinctQuestion[];
|
package/dist/commands.utils.js
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
2
|
export const generateCommonDeployQuestions = (flags) => [
|
|
3
|
+
// Connection Type Selection
|
|
4
|
+
{
|
|
5
|
+
choices: [
|
|
6
|
+
{ name: 'PostgreSQL', value: 'postgresql' },
|
|
7
|
+
{ name: 'MongoDB', value: 'mongodb' }
|
|
8
|
+
],
|
|
9
|
+
default: 'postgresql',
|
|
10
|
+
message: 'What type of database are you connecting to?',
|
|
11
|
+
name: 'connectionType',
|
|
12
|
+
type: 'list',
|
|
13
|
+
when: !flags.connectionType
|
|
14
|
+
},
|
|
15
|
+
// Common Database Connection Fields
|
|
3
16
|
{
|
|
4
17
|
message: 'What is your database hostname?',
|
|
5
18
|
name: 'hostname',
|
|
@@ -10,7 +23,10 @@ export const generateCommonDeployQuestions = (flags) => [
|
|
|
10
23
|
when: !flags.hostname
|
|
11
24
|
},
|
|
12
25
|
{
|
|
13
|
-
default
|
|
26
|
+
default(answers) {
|
|
27
|
+
const connType = flags.connectionType || answers.connectionType;
|
|
28
|
+
return connType === 'mongodb' ? 27_017 : 5432;
|
|
29
|
+
},
|
|
14
30
|
message: 'What is the port number of your database?',
|
|
15
31
|
name: 'port',
|
|
16
32
|
type: 'input',
|
|
@@ -24,24 +40,35 @@ export const generateCommonDeployQuestions = (flags) => [
|
|
|
24
40
|
when: !flags.port
|
|
25
41
|
},
|
|
26
42
|
{
|
|
27
|
-
default
|
|
43
|
+
default(answers) {
|
|
44
|
+
const connType = flags.connectionType || answers.connectionType;
|
|
45
|
+
return connType === 'postgresql' ? 'postgres' : undefined;
|
|
46
|
+
},
|
|
28
47
|
message: 'What is your database name?',
|
|
29
48
|
name: 'databaseName',
|
|
30
49
|
type: 'input',
|
|
31
50
|
validate(value) {
|
|
32
51
|
return value.length > 0 ? true : 'Please enter your database name.';
|
|
33
52
|
},
|
|
34
|
-
when
|
|
53
|
+
when() {
|
|
54
|
+
if (flags.databaseName) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
35
59
|
},
|
|
36
60
|
{
|
|
37
|
-
default
|
|
61
|
+
default(answers) {
|
|
62
|
+
const connType = flags.connectionType || answers.connectionType;
|
|
63
|
+
return connType === 'postgresql' ? 'postgres' : undefined;
|
|
64
|
+
},
|
|
38
65
|
message: 'What is your database username?',
|
|
39
66
|
name: 'databaseUsername',
|
|
40
67
|
type: 'input',
|
|
41
68
|
validate(value) {
|
|
42
69
|
return value.length > 0 ? true : 'Please enter your database username.';
|
|
43
70
|
},
|
|
44
|
-
when: !flags.
|
|
71
|
+
when: !flags.databaseUserName
|
|
45
72
|
},
|
|
46
73
|
{
|
|
47
74
|
message: 'What is your database password?',
|
|
@@ -52,13 +79,25 @@ export const generateCommonDeployQuestions = (flags) => [
|
|
|
52
79
|
},
|
|
53
80
|
when: !flags.databasePassword
|
|
54
81
|
},
|
|
82
|
+
{
|
|
83
|
+
default: 'mongodb+srv',
|
|
84
|
+
message: 'What is your database protocol? (e.g., mongodb, mongodb+srv)',
|
|
85
|
+
name: 'protocol',
|
|
86
|
+
type: 'input',
|
|
87
|
+
validate(value) {
|
|
88
|
+
return value.length > 0 ? true : 'Please enter your database protocol.';
|
|
89
|
+
},
|
|
90
|
+
when: (answers) => (flags.connectionType === 'mongodb' || answers.connectionType === 'mongodb') && !flags.protocol
|
|
91
|
+
},
|
|
92
|
+
// Authentication Questions (existing)
|
|
55
93
|
{
|
|
56
94
|
default: false,
|
|
57
95
|
message: 'Are you using Supabase auth?',
|
|
58
96
|
name: 'useSupabaseAuth',
|
|
59
97
|
type: 'confirm',
|
|
60
|
-
|
|
61
|
-
|
|
98
|
+
when: (answers) => flags.useSupabaseAuth === null &&
|
|
99
|
+
!flags.jwksUri &&
|
|
100
|
+
(flags.connectionType === 'postgresql' || answers.connectionType === 'postgresql')
|
|
62
101
|
},
|
|
63
102
|
{
|
|
64
103
|
message: 'Enter the Supabase JWT secret (see https://docs.powersync.com/installation/authentication-setup/supabase-auth#supabase-auth)',
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ConnectionType } from '@journeyapps-platform/types-powersync';
|
|
2
|
+
export interface ConnectionParams {
|
|
3
|
+
connectionType?: string;
|
|
4
|
+
databaseName?: string;
|
|
5
|
+
databasePassword?: string;
|
|
6
|
+
databaseUsername?: string;
|
|
7
|
+
hostname?: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
protocol?: string;
|
|
10
|
+
}
|
|
11
|
+
interface PostgreSQLConnection {
|
|
12
|
+
database: string;
|
|
13
|
+
hostname: string;
|
|
14
|
+
name: string;
|
|
15
|
+
password: {
|
|
16
|
+
secret: string;
|
|
17
|
+
};
|
|
18
|
+
port: number;
|
|
19
|
+
sslmode?: 'verify-ca' | 'verify-full';
|
|
20
|
+
tag: string;
|
|
21
|
+
type: ConnectionType.POSTGRES;
|
|
22
|
+
username?: string;
|
|
23
|
+
}
|
|
24
|
+
interface MongoDBConnection {
|
|
25
|
+
database?: string;
|
|
26
|
+
hostname?: string;
|
|
27
|
+
name: string;
|
|
28
|
+
password?: {
|
|
29
|
+
secret: string;
|
|
30
|
+
};
|
|
31
|
+
post_images?: 'auto_configure' | 'off' | 'read_only';
|
|
32
|
+
tag: string;
|
|
33
|
+
type: ConnectionType.MONGODB;
|
|
34
|
+
uri?: string;
|
|
35
|
+
username?: string;
|
|
36
|
+
}
|
|
37
|
+
export type DatabaseConnection = MongoDBConnection | PostgreSQLConnection;
|
|
38
|
+
/**
|
|
39
|
+
* Build PostgreSQL connection object
|
|
40
|
+
* @param params - Connection parameters for PostgreSQL
|
|
41
|
+
* @returns PostgreSQL connection configuration object
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildPostgreSQLConnection(params: ConnectionParams): PostgreSQLConnection;
|
|
44
|
+
/**
|
|
45
|
+
* Build MongoDB connection object
|
|
46
|
+
* @param params - Connection parameters for MongoDB
|
|
47
|
+
* @returns MongoDB connection configuration object
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildMongoDBConnection(params: ConnectionParams): MongoDBConnection;
|
|
50
|
+
/**
|
|
51
|
+
* Build database connection object based on connection type
|
|
52
|
+
* @param params - Connection parameters including connection type
|
|
53
|
+
* @returns Database connection configuration object for the specified type
|
|
54
|
+
*/
|
|
55
|
+
export declare function buildDatabaseConnection(params: ConnectionParams): DatabaseConnection;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build PostgreSQL connection object
|
|
3
|
+
* @param params - Connection parameters for PostgreSQL
|
|
4
|
+
* @returns PostgreSQL connection configuration object
|
|
5
|
+
*/
|
|
6
|
+
export function buildPostgreSQLConnection(params) {
|
|
7
|
+
if (!params.hostname) {
|
|
8
|
+
throw new Error('Hostname is required for PostgreSQL connection');
|
|
9
|
+
}
|
|
10
|
+
if (!params.databaseName) {
|
|
11
|
+
throw new Error('Database name is required for PostgreSQL connection');
|
|
12
|
+
}
|
|
13
|
+
if (!params.databasePassword) {
|
|
14
|
+
throw new Error('Database password is required for PostgreSQL connection');
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
database: params.databaseName,
|
|
18
|
+
hostname: params.hostname,
|
|
19
|
+
name: 'Default',
|
|
20
|
+
password: {
|
|
21
|
+
secret: params.databasePassword
|
|
22
|
+
},
|
|
23
|
+
port: params.port || 5432,
|
|
24
|
+
sslmode: 'verify-full',
|
|
25
|
+
tag: 'default',
|
|
26
|
+
type: 'postgresql',
|
|
27
|
+
username: params.databaseUsername
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build MongoDB connection object
|
|
32
|
+
* @param params - Connection parameters for MongoDB
|
|
33
|
+
* @returns MongoDB connection configuration object
|
|
34
|
+
*/
|
|
35
|
+
export function buildMongoDBConnection(params) {
|
|
36
|
+
const { databaseName, databasePassword, databaseUsername, hostname } = params;
|
|
37
|
+
if (!hostname) {
|
|
38
|
+
throw new Error('Hostname or connection string is required for MongoDB connection');
|
|
39
|
+
}
|
|
40
|
+
if (!databaseName) {
|
|
41
|
+
throw new Error('Database name or connection string is required for MongoDB connection');
|
|
42
|
+
}
|
|
43
|
+
const credentials = databaseUsername ? `${databaseUsername}${databasePassword ? `:${databasePassword}` : ''}@` : '';
|
|
44
|
+
const protocol = params.protocol || 'mongodb+srv';
|
|
45
|
+
const port = params.port && protocol !== 'mongodb+srv' ? `:${params.port}` : '';
|
|
46
|
+
const uri = `${protocol}://${credentials}${hostname}${port}/${databaseName}`;
|
|
47
|
+
return {
|
|
48
|
+
database: databaseName,
|
|
49
|
+
name: 'Default',
|
|
50
|
+
password: databasePassword ? { secret: databasePassword } : undefined,
|
|
51
|
+
post_images: 'auto_configure',
|
|
52
|
+
tag: 'default',
|
|
53
|
+
type: 'mongodb',
|
|
54
|
+
uri,
|
|
55
|
+
username: databaseUsername
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Build database connection object based on connection type
|
|
60
|
+
* @param params - Connection parameters including connection type
|
|
61
|
+
* @returns Database connection configuration object for the specified type
|
|
62
|
+
*/
|
|
63
|
+
export function buildDatabaseConnection(params) {
|
|
64
|
+
const connectionType = params.connectionType || 'postgresql';
|
|
65
|
+
switch (connectionType) {
|
|
66
|
+
case 'postgresql': {
|
|
67
|
+
return buildPostgreSQLConnection(params);
|
|
68
|
+
}
|
|
69
|
+
case 'mongodb': {
|
|
70
|
+
return buildMongoDBConnection(params);
|
|
71
|
+
}
|
|
72
|
+
default: {
|
|
73
|
+
throw new Error(`Unsupported connection type: ${connectionType}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const generateCommonInstanceConfigFlags: () => {
|
|
2
|
+
connectionType: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
3
|
+
databaseName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
4
|
+
databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
5
|
+
databaseUsername: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
|
+
hostname: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
jwksUri: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
jwtAudiences: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
|
+
port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
+
skipInteraction: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
11
|
+
supabaseJWTSecret: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
|
+
useSupabaseAuth: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
export const generateCommonInstanceConfigFlags = () => ({
|
|
3
|
+
// Connection flags
|
|
4
|
+
connectionType: Flags.string({
|
|
5
|
+
char: 't',
|
|
6
|
+
description: 'Type of database connection.',
|
|
7
|
+
options: ['postgresql', 'mongodb']
|
|
8
|
+
}),
|
|
9
|
+
// Common database flags
|
|
10
|
+
databaseName: Flags.string({ char: 'n', description: 'Name of the database.' }),
|
|
11
|
+
databasePassword: Flags.string({ char: 'p', description: 'Password of the database.', hidden: true }),
|
|
12
|
+
databaseUsername: Flags.string({ char: 'u', description: 'Username of the database.', hidden: true }),
|
|
13
|
+
hostname: Flags.string({ char: 'h', description: 'Hostname to connect to database.' }),
|
|
14
|
+
// JWT/Auth flags
|
|
15
|
+
jwksUri: Flags.string({ char: 'w', description: 'JWKS URI (must include https://).' }),
|
|
16
|
+
jwtAudiences: Flags.string({ char: 'a', default: '', description: 'JWT audiences (comma separated).' }),
|
|
17
|
+
port: Flags.integer({ char: 'o', description: 'Port number to connect to database.' }),
|
|
18
|
+
// General flags
|
|
19
|
+
skipInteraction: Flags.boolean({ char: 's', description: 'Skip interactivity.' }),
|
|
20
|
+
supabaseJWTSecret: Flags.string({ allowNo: true, char: 'j', description: 'Supabase JWT secret' }),
|
|
21
|
+
useSupabaseAuth: Flags.boolean({ allowNo: true, char: 'b', description: 'Use Supabase auth.' })
|
|
22
|
+
});
|
|
@@ -11157,7 +11157,7 @@ var files = [
|
|
|
11157
11157
|
"/dist",
|
|
11158
11158
|
"/oclif.manifest.json"
|
|
11159
11159
|
];
|
|
11160
|
-
var version = "0.
|
|
11160
|
+
var version = "0.8.0";
|
|
11161
11161
|
var bugs = "https://github.com/powersync-ja/cli/issues";
|
|
11162
11162
|
var types = "dist/index.d.ts";
|
|
11163
11163
|
var exports = "./lib/index.js";
|
|
@@ -47503,7 +47503,7 @@ var files = [
|
|
|
47503
47503
|
"/dist",
|
|
47504
47504
|
"/oclif.manifest.json"
|
|
47505
47505
|
];
|
|
47506
|
-
var version = "0.
|
|
47506
|
+
var version = "0.8.0";
|
|
47507
47507
|
var bugs = "https://github.com/powersync-ja/cli/issues";
|
|
47508
47508
|
var types$2 = "dist/index.d.ts";
|
|
47509
47509
|
var exports = "./lib/index.js";
|
package/dist/service/utils.js
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import type { FlagInput } from '@oclif/core/lib/interfaces/parser.js';
|
|
2
|
+
/**
|
|
3
|
+
* Oclif flags include {[flag: string]: any} which allows for any additional flag members.
|
|
4
|
+
* This makes using flags vulnerable to typos and errors.
|
|
5
|
+
* This helper type only exposes the declared flag members in the type.
|
|
6
|
+
*/
|
|
7
|
+
export type StrictFlags<T> = T extends FlagInput<infer U> ? U : never;
|
|
1
8
|
export declare const checkThatEnvVariablesAreSet: (cliName: string, requiresInstanceId?: boolean) => undefined;
|
|
2
9
|
export declare const updateEnvFileVariableValue: (variableName: string, newValue: string) => void;
|
|
3
10
|
export declare const bold: (text: string) => string;
|
package/oclif.manifest.json
CHANGED
|
@@ -78,6 +78,41 @@
|
|
|
78
78
|
"<%= config.bin %> <%= command.id %>"
|
|
79
79
|
],
|
|
80
80
|
"flags": {
|
|
81
|
+
"name": {
|
|
82
|
+
"char": "i",
|
|
83
|
+
"description": "Name of the instance.",
|
|
84
|
+
"name": "name",
|
|
85
|
+
"hasDynamicHelp": false,
|
|
86
|
+
"multiple": false,
|
|
87
|
+
"type": "option"
|
|
88
|
+
},
|
|
89
|
+
"protocol": {
|
|
90
|
+
"description": "Database protocol to use (e.g., for MongoDB: mongodb+srv or mongodb).",
|
|
91
|
+
"name": "protocol",
|
|
92
|
+
"hasDynamicHelp": false,
|
|
93
|
+
"multiple": false,
|
|
94
|
+
"type": "option"
|
|
95
|
+
},
|
|
96
|
+
"region": {
|
|
97
|
+
"char": "r",
|
|
98
|
+
"description": "Region to deploy instance to.",
|
|
99
|
+
"name": "region",
|
|
100
|
+
"hasDynamicHelp": false,
|
|
101
|
+
"multiple": false,
|
|
102
|
+
"type": "option"
|
|
103
|
+
},
|
|
104
|
+
"connectionType": {
|
|
105
|
+
"char": "t",
|
|
106
|
+
"description": "Type of database connection.",
|
|
107
|
+
"name": "connectionType",
|
|
108
|
+
"hasDynamicHelp": false,
|
|
109
|
+
"multiple": false,
|
|
110
|
+
"options": [
|
|
111
|
+
"postgresql",
|
|
112
|
+
"mongodb"
|
|
113
|
+
],
|
|
114
|
+
"type": "option"
|
|
115
|
+
},
|
|
81
116
|
"databaseName": {
|
|
82
117
|
"char": "n",
|
|
83
118
|
"description": "Name of the database.",
|
|
@@ -129,14 +164,6 @@
|
|
|
129
164
|
"multiple": false,
|
|
130
165
|
"type": "option"
|
|
131
166
|
},
|
|
132
|
-
"name": {
|
|
133
|
-
"char": "i",
|
|
134
|
-
"description": "Name of the instance.",
|
|
135
|
-
"name": "name",
|
|
136
|
-
"hasDynamicHelp": false,
|
|
137
|
-
"multiple": false,
|
|
138
|
-
"type": "option"
|
|
139
|
-
},
|
|
140
167
|
"port": {
|
|
141
168
|
"char": "o",
|
|
142
169
|
"description": "Port number to connect to database.",
|
|
@@ -145,14 +172,6 @@
|
|
|
145
172
|
"multiple": false,
|
|
146
173
|
"type": "option"
|
|
147
174
|
},
|
|
148
|
-
"region": {
|
|
149
|
-
"char": "r",
|
|
150
|
-
"description": "Region to deploy instance to.",
|
|
151
|
-
"name": "region",
|
|
152
|
-
"hasDynamicHelp": false,
|
|
153
|
-
"multiple": false,
|
|
154
|
-
"type": "option"
|
|
155
|
-
},
|
|
156
175
|
"skipInteraction": {
|
|
157
176
|
"char": "s",
|
|
158
177
|
"description": "Skip interactivity.",
|
|
@@ -200,6 +219,33 @@
|
|
|
200
219
|
"<%= config.bin %> <%= command.id %>"
|
|
201
220
|
],
|
|
202
221
|
"flags": {
|
|
222
|
+
"protocol": {
|
|
223
|
+
"description": "Database protocol to use (e.g., for MongoDB: mongodb+srv or mongodb).",
|
|
224
|
+
"name": "protocol",
|
|
225
|
+
"hasDynamicHelp": false,
|
|
226
|
+
"multiple": false,
|
|
227
|
+
"type": "option"
|
|
228
|
+
},
|
|
229
|
+
"region": {
|
|
230
|
+
"char": "r",
|
|
231
|
+
"description": "Region to deploy instance to.",
|
|
232
|
+
"name": "region",
|
|
233
|
+
"hasDynamicHelp": false,
|
|
234
|
+
"multiple": false,
|
|
235
|
+
"type": "option"
|
|
236
|
+
},
|
|
237
|
+
"connectionType": {
|
|
238
|
+
"char": "t",
|
|
239
|
+
"description": "Type of database connection.",
|
|
240
|
+
"name": "connectionType",
|
|
241
|
+
"hasDynamicHelp": false,
|
|
242
|
+
"multiple": false,
|
|
243
|
+
"options": [
|
|
244
|
+
"postgresql",
|
|
245
|
+
"mongodb"
|
|
246
|
+
],
|
|
247
|
+
"type": "option"
|
|
248
|
+
},
|
|
203
249
|
"databaseName": {
|
|
204
250
|
"char": "n",
|
|
205
251
|
"description": "Name of the database.",
|
|
@@ -246,6 +292,7 @@
|
|
|
246
292
|
"char": "a",
|
|
247
293
|
"description": "JWT audiences (comma separated).",
|
|
248
294
|
"name": "jwtAudiences",
|
|
295
|
+
"default": "",
|
|
249
296
|
"hasDynamicHelp": false,
|
|
250
297
|
"multiple": false,
|
|
251
298
|
"type": "option"
|
|
@@ -265,6 +312,14 @@
|
|
|
265
312
|
"allowNo": false,
|
|
266
313
|
"type": "boolean"
|
|
267
314
|
},
|
|
315
|
+
"supabaseJWTSecret": {
|
|
316
|
+
"char": "j",
|
|
317
|
+
"description": "Supabase JWT secret",
|
|
318
|
+
"name": "supabaseJWTSecret",
|
|
319
|
+
"hasDynamicHelp": false,
|
|
320
|
+
"multiple": false,
|
|
321
|
+
"type": "option"
|
|
322
|
+
},
|
|
268
323
|
"useSupabaseAuth": {
|
|
269
324
|
"char": "b",
|
|
270
325
|
"description": "Use Supabase auth.",
|
|
@@ -641,5 +696,5 @@
|
|
|
641
696
|
]
|
|
642
697
|
}
|
|
643
698
|
},
|
|
644
|
-
"version": "0.
|
|
699
|
+
"version": "0.8.0"
|
|
645
700
|
}
|