powersync 0.7.1 → 0.9.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/LICENSE +67 -0
- package/README.md +1376 -165
- package/bin/dev.cmd +3 -3
- package/bin/dev.js +20 -7
- package/bin/run.cmd +3 -3
- package/bin/run.js +9 -5
- package/dist/api/cloud/create-cloud-instance.d.ts +15 -0
- package/dist/api/cloud/create-cloud-instance.js +19 -0
- package/dist/api/cloud/fetch-cloud-config.d.ts +12 -0
- package/dist/api/cloud/fetch-cloud-config.js +18 -0
- package/dist/api/cloud/fetch-cloud-sync-rules-content.d.ts +7 -0
- package/dist/api/cloud/fetch-cloud-sync-rules-content.js +26 -0
- package/dist/api/cloud/test-connection.d.ts +16 -0
- package/dist/api/cloud/test-connection.js +36 -0
- package/dist/api/cloud/validate-cloud-link-config.d.ts +17 -0
- package/dist/api/cloud/validate-cloud-link-config.js +47 -0
- package/dist/api/cloud/wait-for-operation.d.ts +16 -0
- package/dist/api/cloud/wait-for-operation.js +33 -0
- package/dist/api/cloud/write-cloud-link.d.ts +10 -0
- package/dist/api/cloud/write-cloud-link.js +21 -0
- package/dist/api/display-status.d.ts +4 -0
- package/dist/api/display-status.js +80 -0
- package/dist/api/ide/configure-vscode-ide.d.ts +14 -0
- package/dist/api/ide/configure-vscode-ide.js +62 -0
- package/dist/api/login-server.d.ts +26 -0
- package/dist/api/login-server.js +137 -0
- package/dist/api/run-validation-tests.d.ts +63 -0
- package/dist/api/run-validation-tests.js +202 -0
- package/dist/api/self-hosted/fetch-self-hosted-sync-rules-content.d.ts +7 -0
- package/dist/api/self-hosted/fetch-self-hosted-sync-rules-content.js +26 -0
- package/dist/commands/configure/ide.d.ts +8 -0
- package/dist/commands/configure/ide.js +58 -0
- package/dist/commands/configure/index.d.ts +8 -0
- package/dist/commands/configure/index.js +11 -0
- package/dist/commands/deploy/index.d.ts +48 -0
- package/dist/commands/deploy/index.js +333 -0
- package/dist/commands/deploy/service-config.d.ts +14 -0
- package/dist/commands/deploy/service-config.js +30 -0
- package/dist/commands/deploy/sync-config.d.ts +24 -0
- package/dist/commands/deploy/sync-config.js +103 -0
- package/dist/commands/destroy.d.ts +14 -0
- package/dist/commands/destroy.js +62 -0
- package/dist/commands/fetch/config.d.ts +14 -0
- package/dist/commands/fetch/config.js +33 -0
- package/dist/commands/fetch/index.d.ts +13 -0
- package/dist/commands/fetch/index.js +16 -0
- package/dist/commands/fetch/instances.d.ts +47 -0
- package/dist/commands/fetch/instances.js +177 -0
- package/dist/commands/fetch/status.d.ts +18 -0
- package/dist/commands/fetch/status.js +60 -0
- package/dist/commands/{instance/schema.d.ts → generate/index.d.ts} +3 -1
- package/dist/commands/generate/index.js +11 -0
- package/dist/commands/generate/schema.d.ts +19 -0
- package/dist/commands/generate/schema.js +72 -0
- package/dist/commands/generate/token.d.ts +25 -0
- package/dist/commands/generate/token.js +124 -0
- package/dist/commands/init/cloud.d.ts +11 -0
- package/dist/commands/init/cloud.js +64 -0
- package/dist/commands/{init.d.ts → init/index.d.ts} +2 -1
- package/dist/commands/init/index.js +11 -0
- package/dist/commands/init/self-hosted.d.ts +11 -0
- package/dist/commands/init/self-hosted.js +60 -0
- package/dist/commands/link/cloud.d.ts +15 -0
- package/dist/commands/link/cloud.js +111 -0
- package/dist/commands/{instance/config.d.ts → link/index.d.ts} +3 -1
- package/dist/commands/link/index.js +11 -0
- package/dist/commands/link/self-hosted.d.ts +12 -0
- package/dist/commands/link/self-hosted.js +54 -0
- package/dist/commands/login.d.ts +8 -0
- package/dist/commands/login.js +107 -0
- package/dist/commands/logout.d.ts +8 -0
- package/dist/commands/logout.js +19 -0
- package/dist/commands/migrate/index.d.ts +7 -0
- package/dist/commands/migrate/index.js +10 -0
- package/dist/commands/migrate/sync-rules.d.ts +15 -0
- package/dist/commands/migrate/sync-rules.js +51 -0
- package/dist/commands/{instances.d.ts → pull/index.d.ts} +3 -1
- package/dist/commands/pull/index.js +11 -0
- package/dist/commands/pull/instance.d.ts +14 -0
- package/dist/commands/pull/instance.js +108 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +2 -0
- package/dist/commands/stop.d.ts +14 -0
- package/dist/commands/stop.js +62 -0
- package/dist/commands/validate.d.ts +16 -0
- package/dist/commands/validate.js +165 -0
- package/dist/help.d.ts +31 -0
- package/dist/help.js +123 -0
- package/oclif.manifest.json +1250 -275
- package/package.json +104 -75
- package/templates/cloud/powersync/cli.yaml +3 -0
- package/templates/cloud/powersync/service.yaml +174 -0
- package/templates/cloud/powersync/sync-config.yaml +22 -0
- package/templates/self-hosted/base/powersync/cli.yaml +3 -0
- package/templates/self-hosted/base/powersync/service.yaml +243 -0
- package/templates/self-hosted/base/powersync/sync-config.yaml +22 -0
- package/templates/vscode/settings.json +3 -0
- package/dist/commands/init.js +0 -66
- package/dist/commands/instance/config.js +0 -23
- package/dist/commands/instance/create.d.ts +0 -20
- package/dist/commands/instance/create.js +0 -121
- package/dist/commands/instance/deploy.d.ts +0 -18
- package/dist/commands/instance/deploy.js +0 -91
- package/dist/commands/instance/destroy.d.ts +0 -9
- package/dist/commands/instance/destroy.js +0 -46
- package/dist/commands/instance/generate-dev-token.d.ts +0 -10
- package/dist/commands/instance/generate-dev-token.js +0 -54
- package/dist/commands/instance/schema.js +0 -20
- package/dist/commands/instance/set.d.ts +0 -9
- package/dist/commands/instance/set.js +0 -31
- package/dist/commands/instance/status.d.ts +0 -12
- package/dist/commands/instance/status.js +0 -50
- package/dist/commands/instance/stop.d.ts +0 -9
- package/dist/commands/instance/stop.js +0 -42
- package/dist/commands/instance/sync-rules/deploy.d.ts +0 -10
- package/dist/commands/instance/sync-rules/deploy.js +0 -49
- package/dist/commands/instance/sync-rules/generate-schema.d.ts +0 -10
- package/dist/commands/instance/sync-rules/generate-schema.js +0 -56
- package/dist/commands/instance/sync-rules/validate.d.ts +0 -9
- package/dist/commands/instance/sync-rules/validate.js +0 -29
- package/dist/commands/instances.js +0 -29
- package/dist/commands.utils.d.ts +0 -2
- package/dist/commands.utils.js +0 -92
- package/dist/constants.d.ts +0 -8
- package/dist/constants.js +0 -10
- package/dist/instance-command-flags.d.ts +0 -12
- package/dist/instance-command-flags.js +0 -13
- package/dist/service/accounts.client.js +0 -11307
- package/dist/service/powersync.client.js +0 -75510
- package/dist/service/types.js +0 -1
- package/dist/service/utils.js +0 -153
- package/dist/utils.d.ts +0 -14
- package/dist/utils.js +0 -68
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# See https://docs.powersync.com/sync/advanced/compatibility
|
|
2
|
+
config:
|
|
3
|
+
edition: 3
|
|
4
|
+
|
|
5
|
+
# Define Sync Streams to control which data is synced to each user
|
|
6
|
+
# Docs: https://docs.powersync.com/sync/streams/overview
|
|
7
|
+
streams:
|
|
8
|
+
global:
|
|
9
|
+
# Streams without parameters sync the same data to all users
|
|
10
|
+
auto_subscribe: true
|
|
11
|
+
queries:
|
|
12
|
+
# Sync all rows
|
|
13
|
+
- SELECT * FROM mytable
|
|
14
|
+
# Only sync some rows
|
|
15
|
+
- SELECT * FROM mytable WHERE mycolumn = false
|
|
16
|
+
# Wildcards can be used, useful in development to quickly sync all tables
|
|
17
|
+
#- SELECT * FROM "%"
|
|
18
|
+
|
|
19
|
+
by_user:
|
|
20
|
+
# Only sync rows belonging to the user, using fields from the auth token
|
|
21
|
+
auto_subscribe: true
|
|
22
|
+
query: SELECT * FROM mytable WHERE mytable.user_id = auth.user_id()
|
package/dist/commands/init.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Command, ux } from '@oclif/core';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import { ENV_FILE_PATH, POWERSYNC_DIRECTORY } from '../constants.js';
|
|
5
|
-
import * as AccountsClient from '../service/accounts.client.js';
|
|
6
|
-
import { green, red } from '../utils.js';
|
|
7
|
-
export default class Init extends Command {
|
|
8
|
-
static description = 'Initialize the CLI.';
|
|
9
|
-
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
async catch(error) {
|
|
12
|
-
if ('errorData' in error && error.errorData.status === 401) {
|
|
13
|
-
return ux.error(red(`You are using an invalid API token. Please double-check your token.`), { exit: 1 });
|
|
14
|
-
}
|
|
15
|
-
throw error;
|
|
16
|
-
}
|
|
17
|
-
async run() {
|
|
18
|
-
const authTokenQuestions = [
|
|
19
|
-
{
|
|
20
|
-
message: 'Enter your API token (https://docs.powersync.com/usage/tools/cli#personal-access-token):',
|
|
21
|
-
name: 'authToken',
|
|
22
|
-
type: 'password',
|
|
23
|
-
validate(value) {
|
|
24
|
-
return value.length > 0 ? true : 'Please enter your API token.';
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
];
|
|
28
|
-
const authTokenAnswers = await inquirer.prompt(authTokenQuestions);
|
|
29
|
-
const organizations = await AccountsClient.getOrgs(authTokenAnswers.authToken);
|
|
30
|
-
const numberOfOrganizations = organizations.count;
|
|
31
|
-
const SUPPORT_MESSAGE = 'Please contact support for assistance - support@powersync.com.';
|
|
32
|
-
if (numberOfOrganizations === 0) {
|
|
33
|
-
return ux.error(red(`No organizations found. ${SUPPORT_MESSAGE}`), {
|
|
34
|
-
exit: 1
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
if (numberOfOrganizations > 1) {
|
|
38
|
-
return ux.error(red(`Multiple organizations found. ${SUPPORT_MESSAGE}`), { exit: 1 });
|
|
39
|
-
}
|
|
40
|
-
const projects = await AccountsClient.getPowerSyncProjects(authTokenAnswers.authToken);
|
|
41
|
-
if (projects.length === 0) {
|
|
42
|
-
return ux.error(red(`No projects found. ${SUPPORT_MESSAGE}`), { exit: 1 });
|
|
43
|
-
}
|
|
44
|
-
const projectQuestions = [
|
|
45
|
-
{
|
|
46
|
-
choices: projects,
|
|
47
|
-
message: 'Which project would you like to use?',
|
|
48
|
-
name: 'projectId',
|
|
49
|
-
type: 'list'
|
|
50
|
-
}
|
|
51
|
-
];
|
|
52
|
-
const projectAnswers = await inquirer.prompt(projectQuestions);
|
|
53
|
-
const orgId = organizations.objects[0].id;
|
|
54
|
-
if (!fs.existsSync(POWERSYNC_DIRECTORY)) {
|
|
55
|
-
fs.mkdirSync(POWERSYNC_DIRECTORY);
|
|
56
|
-
}
|
|
57
|
-
if (fs.existsSync(ENV_FILE_PATH)) {
|
|
58
|
-
fs.unlinkSync(ENV_FILE_PATH);
|
|
59
|
-
}
|
|
60
|
-
fs.writeFileSync(ENV_FILE_PATH, `ORG_ID=${orgId}\nPROJECT_ID=${projectAnswers.projectId}\nAUTH_TOKEN=${authTokenAnswers.authToken}\n`);
|
|
61
|
-
ux.log(green('CLI has been initialized'));
|
|
62
|
-
ux.log(`Run ${green(`"npx ${this.config.bin} instances"`)} to view your instances or`);
|
|
63
|
-
ux.log(`run ${green(`"npx ${this.config.bin} instance create"`)} to create an instance or`);
|
|
64
|
-
ux.log(`run ${green(`"npx ${this.config.bin} instance set"`)} to use an already created instance.`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Command, ux } from '@oclif/core';
|
|
2
|
-
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
3
|
-
import { checkThatEnvVariablesAreSet, red } from '../../utils.js';
|
|
4
|
-
export default class InstanceConfig extends Command {
|
|
5
|
-
static description = 'Display the instance config.';
|
|
6
|
-
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
7
|
-
async run() {
|
|
8
|
-
checkThatEnvVariablesAreSet(this.config.bin, true);
|
|
9
|
-
const config = await PowerSyncClient.getInstanceConfig();
|
|
10
|
-
if (!config) {
|
|
11
|
-
return this.log(red('No instance config found.'));
|
|
12
|
-
}
|
|
13
|
-
const formattedConfig = {
|
|
14
|
-
auth: config.config?.client_auth,
|
|
15
|
-
// Assume there is only a single connection
|
|
16
|
-
connection: config.config?.replication?.connections[0],
|
|
17
|
-
id: config.id,
|
|
18
|
-
name: config.name,
|
|
19
|
-
region: config.config?.region
|
|
20
|
-
};
|
|
21
|
-
ux.styledObject(formattedConfig, ['id', 'name', 'region', 'connection', 'auth']);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Command } from '@oclif/core';
|
|
2
|
-
export default class InstanceCreate extends Command {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
databaseName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
-
databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
-
databaseUsername: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
|
-
hostname: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
-
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, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
|
-
port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
13
|
-
skipInteraction: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
14
|
-
supabaseJWTSecret: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
15
|
-
useSupabaseAuth: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
16
|
-
name: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
17
|
-
region: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
18
|
-
};
|
|
19
|
-
run(): Promise<void>;
|
|
20
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { Command, Flags, ux } from '@oclif/core';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import ora from 'ora';
|
|
4
|
-
import { generateCommonDeployQuestions } from '../../commands.utils.js';
|
|
5
|
-
import { generateCommonInstanceConfigFlags } from '../../instance-command-flags.js';
|
|
6
|
-
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
7
|
-
import { bold, checkThatEnvVariablesAreSet, green, red, updateEnvFileVariableValue } from '../../utils.js';
|
|
8
|
-
export default class InstanceCreate extends Command {
|
|
9
|
-
static description = 'Create a new instance.';
|
|
10
|
-
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
11
|
-
static flags = {
|
|
12
|
-
name: Flags.string({ char: 'i', description: 'Name of the instance.' }),
|
|
13
|
-
region: Flags.string({ char: 'r', description: 'Region to deploy instance to.' }),
|
|
14
|
-
...generateCommonInstanceConfigFlags()
|
|
15
|
-
};
|
|
16
|
-
async run() {
|
|
17
|
-
checkThatEnvVariablesAreSet(this.config.bin);
|
|
18
|
-
const parsed = await this.parse(InstanceCreate);
|
|
19
|
-
const flags = parsed.flags;
|
|
20
|
-
const regions = await PowerSyncClient.getRegions();
|
|
21
|
-
let answers = {
|
|
22
|
-
databaseName: undefined,
|
|
23
|
-
databasePassword: undefined,
|
|
24
|
-
databaseUsername: undefined,
|
|
25
|
-
hostname: undefined,
|
|
26
|
-
jwksUri: undefined,
|
|
27
|
-
jwtAudiences: undefined,
|
|
28
|
-
name: undefined,
|
|
29
|
-
port: undefined,
|
|
30
|
-
region: undefined,
|
|
31
|
-
useSupabaseAuth: undefined
|
|
32
|
-
};
|
|
33
|
-
if (!flags.skipInteraction) {
|
|
34
|
-
const questions = [
|
|
35
|
-
{
|
|
36
|
-
message: 'What do you want to name your instance?',
|
|
37
|
-
name: 'name',
|
|
38
|
-
type: 'input',
|
|
39
|
-
validate(value) {
|
|
40
|
-
return value.length > 3 ? true : 'Please enter a name with at least 3 characters.';
|
|
41
|
-
},
|
|
42
|
-
when: !flags.name
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
choices: regions.map((region) => region.toUpperCase()),
|
|
46
|
-
message: 'What region do you want to use?',
|
|
47
|
-
name: 'region',
|
|
48
|
-
type: 'list',
|
|
49
|
-
when: !flags.region
|
|
50
|
-
},
|
|
51
|
-
...generateCommonDeployQuestions(flags)
|
|
52
|
-
];
|
|
53
|
-
answers = await inquirer.prompt(questions);
|
|
54
|
-
}
|
|
55
|
-
const instanceName = flags.name || answers.name;
|
|
56
|
-
const port = flags.port || answers.port;
|
|
57
|
-
const password = flags.databasePassword || answers.databasePassword;
|
|
58
|
-
const hostname = flags.hostname || answers.hostname;
|
|
59
|
-
const databaseName = flags.databaseName || answers.databaseName;
|
|
60
|
-
const databaseUsername = flags.databaseUsername || answers.databaseUsername;
|
|
61
|
-
const region = flags.region?.toLowerCase() || answers.region?.toLowerCase();
|
|
62
|
-
const useSupabaseAuth = flags.useSupabaseAuth || answers.useSupabaseAuth;
|
|
63
|
-
const jwksUri = flags.jwksUri || answers.jwksUri;
|
|
64
|
-
const answerAudiences = answers.jwtAudiences ? answers.jwtAudiences.split(',') : [];
|
|
65
|
-
const flagsAudiences = flags.jwtAudiences ? flags.jwtAudiences.split(',') : [];
|
|
66
|
-
const audiences = [...new Set([...flagsAudiences, ...answerAudiences])];
|
|
67
|
-
const supabaseJWTSecret = flags.supabaseJWTSecret ?? answers.supabaseJWTSecret;
|
|
68
|
-
// TODO, support other connection types
|
|
69
|
-
const connection = {
|
|
70
|
-
database: databaseName,
|
|
71
|
-
debug_api: false,
|
|
72
|
-
hostname,
|
|
73
|
-
name: 'Default',
|
|
74
|
-
password: {
|
|
75
|
-
secret: password
|
|
76
|
-
},
|
|
77
|
-
port: Number(port),
|
|
78
|
-
sslmode: 'verify-full',
|
|
79
|
-
tag: 'default',
|
|
80
|
-
type: 'postgresql',
|
|
81
|
-
username: databaseUsername
|
|
82
|
-
};
|
|
83
|
-
const config = {
|
|
84
|
-
client_auth: {
|
|
85
|
-
additional_audiences: audiences || undefined,
|
|
86
|
-
jwks_uri: jwksUri || undefined,
|
|
87
|
-
supabase: useSupabaseAuth,
|
|
88
|
-
supabase_jwt_secret: supabaseJWTSecret
|
|
89
|
-
? {
|
|
90
|
-
secret: supabaseJWTSecret
|
|
91
|
-
}
|
|
92
|
-
: undefined
|
|
93
|
-
},
|
|
94
|
-
region: region,
|
|
95
|
-
replication: {
|
|
96
|
-
connections: [connection]
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const connectionResponse = await PowerSyncClient.testConnection(connection);
|
|
100
|
-
if (connectionResponse.error) {
|
|
101
|
-
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 });
|
|
102
|
-
}
|
|
103
|
-
const spinner = ora({
|
|
104
|
-
prefixText: 'Creating instance.\n',
|
|
105
|
-
spinner: 'moon',
|
|
106
|
-
suffixText: '\nThis may take a few minutes.\n'
|
|
107
|
-
});
|
|
108
|
-
spinner.start();
|
|
109
|
-
const instance = await PowerSyncClient.createInstance(instanceName);
|
|
110
|
-
await PowerSyncClient.deployInstance(config, instance.id);
|
|
111
|
-
let status = 'pending';
|
|
112
|
-
status = await PowerSyncClient.waitForStatusChange(instance.id);
|
|
113
|
-
spinner.stop();
|
|
114
|
-
if (status === 'failed') {
|
|
115
|
-
return ux.error(red(`There was an error creating the instance. Please try again.`), { exit: 1 });
|
|
116
|
-
}
|
|
117
|
-
updateEnvFileVariableValue(PowerSyncClient.ENV_VARIABLES.INSTANCE_ID, instance.id);
|
|
118
|
-
ux.log(green(`Instance with id ${bold(instance.id)} has been created successfully.`));
|
|
119
|
-
ux.log(green(`Current instance has been set to ${bold(instance.id)}.`));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Command } from '@oclif/core';
|
|
2
|
-
export default class InstanceDeploy extends Command {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
databaseName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
-
databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
-
databaseUsername: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
|
-
hostname: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
-
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, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
|
-
port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
13
|
-
skipInteraction: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
14
|
-
supabaseJWTSecret: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
15
|
-
useSupabaseAuth: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
16
|
-
};
|
|
17
|
-
run(): Promise<void>;
|
|
18
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Command, ux } from '@oclif/core';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import ora from 'ora';
|
|
4
|
-
import { generateCommonDeployQuestions } from '../../commands.utils.js';
|
|
5
|
-
import { generateCommonInstanceConfigFlags } from '../../instance-command-flags.js';
|
|
6
|
-
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
7
|
-
import { bold, checkThatEnvVariablesAreSet, green, red } from '../../utils.js';
|
|
8
|
-
export default class InstanceDeploy extends Command {
|
|
9
|
-
static description = 'Deploy changes to an existing instance.';
|
|
10
|
-
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
11
|
-
static flags = {
|
|
12
|
-
...generateCommonInstanceConfigFlags()
|
|
13
|
-
};
|
|
14
|
-
async run() {
|
|
15
|
-
checkThatEnvVariablesAreSet(this.config.bin, true);
|
|
16
|
-
const parsed = await this.parse(InstanceDeploy);
|
|
17
|
-
const flags = parsed.flags;
|
|
18
|
-
let answers = {
|
|
19
|
-
databaseName: undefined,
|
|
20
|
-
databasePassword: undefined,
|
|
21
|
-
databaseUsername: undefined,
|
|
22
|
-
hostname: undefined,
|
|
23
|
-
jwksUri: undefined,
|
|
24
|
-
jwtAudiences: undefined,
|
|
25
|
-
port: undefined,
|
|
26
|
-
useSupabaseAuth: undefined
|
|
27
|
-
};
|
|
28
|
-
if (!flags.skipInteraction) {
|
|
29
|
-
const questions = generateCommonDeployQuestions(flags);
|
|
30
|
-
answers = await inquirer.prompt(questions);
|
|
31
|
-
}
|
|
32
|
-
const port = flags.port || answers.port;
|
|
33
|
-
const password = flags.databasePassword || answers.databasePassword;
|
|
34
|
-
const hostname = flags.hostname || answers.hostname;
|
|
35
|
-
const databaseName = flags.databaseName || answers.databaseName;
|
|
36
|
-
const databaseUsername = flags.databaseUsername || answers.databaseUsername;
|
|
37
|
-
const useSupabaseAuth = flags.useSupabaseAuth || answers.useSupabaseAuth;
|
|
38
|
-
const jwksUri = flags.jwksUri || answers.jwksUri;
|
|
39
|
-
const answerAudiences = answers.jwtAudiences ? answers.jwtAudiences.split(',') : [];
|
|
40
|
-
const flagsAudiences = flags.jwtAudiences ? flags.jwtAudiences.split(',') : [];
|
|
41
|
-
const audiences = [...new Set([...flagsAudiences, ...answerAudiences])];
|
|
42
|
-
const supabaseJWTSecret = flags.supabaseJWTSecret ?? answers.supabaseJWTSecret;
|
|
43
|
-
const instanceConfig = await PowerSyncClient.getInstanceConfig();
|
|
44
|
-
const { region } = instanceConfig.config;
|
|
45
|
-
const config = {
|
|
46
|
-
client_auth: {
|
|
47
|
-
additional_audiences: audiences || undefined,
|
|
48
|
-
jwks_uri: jwksUri || undefined,
|
|
49
|
-
supabase: useSupabaseAuth,
|
|
50
|
-
supabase_jwt_secret: supabaseJWTSecret
|
|
51
|
-
? {
|
|
52
|
-
secret: supabaseJWTSecret
|
|
53
|
-
}
|
|
54
|
-
: undefined
|
|
55
|
-
},
|
|
56
|
-
region,
|
|
57
|
-
replication: {
|
|
58
|
-
connections: [
|
|
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
|
-
]
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const spinner = ora({
|
|
77
|
-
prefixText: 'Deploying instance.\n',
|
|
78
|
-
spinner: 'moon',
|
|
79
|
-
suffixText: '\nThis may take a few minutes.\n'
|
|
80
|
-
});
|
|
81
|
-
spinner.start();
|
|
82
|
-
const instance = await PowerSyncClient.deployInstance(config, process.env.INSTANCE_ID);
|
|
83
|
-
let status = 'pending';
|
|
84
|
-
status = await PowerSyncClient.waitForStatusChange(instance.id);
|
|
85
|
-
spinner.stop();
|
|
86
|
-
if (status === 'failed') {
|
|
87
|
-
ux.error(red(`There was an error deploying the instance. Please try again.`), { exit: 1 });
|
|
88
|
-
}
|
|
89
|
-
ux.log(green(`Instance with id ${bold(instance.id)} has been deployed successfully.`));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Command } from '@oclif/core';
|
|
2
|
-
export default class InstanceDestroy extends Command {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
skipConfirmation: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
7
|
-
};
|
|
8
|
-
run(): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Command, Flags, ux } from '@oclif/core';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import ora from 'ora';
|
|
4
|
-
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
5
|
-
import { bold, checkThatEnvVariablesAreSet, green, red } from '../../utils.js';
|
|
6
|
-
export default class InstanceDestroy extends Command {
|
|
7
|
-
static description = 'Destroy the current instance - THIS CANNOT BE UNDONE.';
|
|
8
|
-
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
9
|
-
static flags = {
|
|
10
|
-
skipConfirmation: Flags.boolean({ char: 's', description: 'Ignore confirmation question.' })
|
|
11
|
-
};
|
|
12
|
-
async run() {
|
|
13
|
-
checkThatEnvVariablesAreSet(this.config.bin, true);
|
|
14
|
-
const { flags } = await this.parse(InstanceDestroy);
|
|
15
|
-
const config = await PowerSyncClient.getInstanceConfig();
|
|
16
|
-
const questions = [
|
|
17
|
-
{
|
|
18
|
-
message: `Please type ${red(config.name)} to confirm you want to destroy this instance.\n`,
|
|
19
|
-
name: 'areYouSure',
|
|
20
|
-
type: 'input',
|
|
21
|
-
validate(input) {
|
|
22
|
-
if (input !== config.name) {
|
|
23
|
-
return `Please type ${red(config.name)} to confirm you want to destroy this instance.\n`;
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
26
|
-
},
|
|
27
|
-
when: !flags.skipConfirmation
|
|
28
|
-
}
|
|
29
|
-
];
|
|
30
|
-
await inquirer.prompt(questions);
|
|
31
|
-
const spinner = ora({
|
|
32
|
-
prefixText: 'Destroying instance\n',
|
|
33
|
-
spinner: 'moon',
|
|
34
|
-
suffixText: '\nThis may take a few minutes'
|
|
35
|
-
});
|
|
36
|
-
spinner.start();
|
|
37
|
-
const instance = await PowerSyncClient.destroyInstance();
|
|
38
|
-
let status = 'pending';
|
|
39
|
-
status = await PowerSyncClient.waitForStatusChange(instance.id);
|
|
40
|
-
spinner.stop();
|
|
41
|
-
if (status === 'failed') {
|
|
42
|
-
ux.error(red(`There was an error destroying the instance. Please try again.`), { exit: 1 });
|
|
43
|
-
}
|
|
44
|
-
ux.log(green(`Instance with id ${bold(instance.id)} has been destroyed.`));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from '@oclif/core';
|
|
2
|
-
export default class InstanceGenerateDevToken extends Command {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
expiresInSeconds: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
-
userId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
-
};
|
|
9
|
-
run(): Promise<void>;
|
|
10
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Command, Flags, ux } from '@oclif/core';
|
|
2
|
-
import clipboard from 'clipboardy';
|
|
3
|
-
import inquirer from 'inquirer';
|
|
4
|
-
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
5
|
-
import { bold, checkThatEnvVariablesAreSet, convertSeconds, green } from '../../utils.js';
|
|
6
|
-
export default class InstanceGenerateDevToken extends Command {
|
|
7
|
-
static description = 'Generate a developer token using the Token subject/ User ID.';
|
|
8
|
-
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
9
|
-
static flags = {
|
|
10
|
-
expiresInSeconds: Flags.string({
|
|
11
|
-
char: 'e',
|
|
12
|
-
description: 'The token expiry in seconds.'
|
|
13
|
-
}),
|
|
14
|
-
userId: Flags.string({ char: 'u', description: 'The Token subject/User ID for the developer token' })
|
|
15
|
-
};
|
|
16
|
-
async run() {
|
|
17
|
-
checkThatEnvVariablesAreSet(this.config.bin, true);
|
|
18
|
-
const { flags } = await this.parse(InstanceGenerateDevToken);
|
|
19
|
-
const questions = [
|
|
20
|
-
{
|
|
21
|
-
message: 'Please enter the Token subject/ User ID to use for the developer token.',
|
|
22
|
-
name: 'userId',
|
|
23
|
-
type: 'input',
|
|
24
|
-
when: !flags.userId
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
default: 43_200,
|
|
28
|
-
message: 'Please enter the token expiry in seconds (Defaults to 12 hours).',
|
|
29
|
-
name: 'expiresInSeconds',
|
|
30
|
-
type: 'input',
|
|
31
|
-
validate(value) {
|
|
32
|
-
const number = Number.parseFloat(value);
|
|
33
|
-
if (Number.isNaN(number)) {
|
|
34
|
-
return 'Please enter a valid number.';
|
|
35
|
-
}
|
|
36
|
-
return String(value).length > 0 ? true : 'Please enter a valid number.';
|
|
37
|
-
},
|
|
38
|
-
when: !flags.expiresInSeconds
|
|
39
|
-
}
|
|
40
|
-
];
|
|
41
|
-
const answers = await inquirer.prompt(questions);
|
|
42
|
-
const userId = flags.userId || answers.userId;
|
|
43
|
-
const expiresInSeconds = Number(flags.expiresInSeconds) || answers.expiresInSeconds;
|
|
44
|
-
const developerToken = await PowerSyncClient.generateDevToken(userId, expiresInSeconds);
|
|
45
|
-
clipboard.writeSync(developerToken);
|
|
46
|
-
clipboard.readSync();
|
|
47
|
-
ux.log(green(`Developer token generated successfully.
|
|
48
|
-
Token has been copied to your clipboard.
|
|
49
|
-
Token details:
|
|
50
|
-
Expires in: ${bold(convertSeconds(expiresInSeconds))}
|
|
51
|
-
JWT:
|
|
52
|
-
${bold(developerToken)}`));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/* eslint-disable perfectionist/sort-objects */
|
|
2
|
-
import { Command, ux } from '@oclif/core';
|
|
3
|
-
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
4
|
-
import { checkThatEnvVariablesAreSet } from '../../utils.js';
|
|
5
|
-
export default class InstanceSchema extends Command {
|
|
6
|
-
static description = 'View the schema of the current instance.';
|
|
7
|
-
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
8
|
-
async run() {
|
|
9
|
-
checkThatEnvVariablesAreSet(this.config.bin, true);
|
|
10
|
-
const result = await PowerSyncClient.getInstanceSchema();
|
|
11
|
-
result.connections[0].schemas.map((schema) => {
|
|
12
|
-
ux.log(`\nSCHEMA: ${schema.name}\n`);
|
|
13
|
-
ux.table(schema.tables, {
|
|
14
|
-
name: {},
|
|
15
|
-
columns: {}
|
|
16
|
-
});
|
|
17
|
-
return null;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Command } from '@oclif/core';
|
|
2
|
-
export default class InstanceSet extends Command {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
instanceId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
-
};
|
|
8
|
-
run(): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Command, Flags, ux } from '@oclif/core';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
4
|
-
import { ENV_VARIABLES } from '../../service/powersync.client.js';
|
|
5
|
-
import { bold, checkThatEnvVariablesAreSet, green, updateEnvFileVariableValue } from '../../utils.js';
|
|
6
|
-
export default class InstanceSet extends Command {
|
|
7
|
-
static description = 'Set the current instance.';
|
|
8
|
-
static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --instanceId=1234'];
|
|
9
|
-
static flags = {
|
|
10
|
-
instanceId: Flags.string({ char: 'i', description: 'Instance ID to change to.' })
|
|
11
|
-
};
|
|
12
|
-
async run() {
|
|
13
|
-
checkThatEnvVariablesAreSet(this.config.bin);
|
|
14
|
-
const { flags } = await this.parse(InstanceSet);
|
|
15
|
-
const list = await PowerSyncClient.getInstancesList();
|
|
16
|
-
const instances = list.instances.map((instance) => ({ name: instance.name, value: instance.id }));
|
|
17
|
-
const questions = [
|
|
18
|
-
{
|
|
19
|
-
choices: instances,
|
|
20
|
-
message: 'Which instance would you like to change to?',
|
|
21
|
-
name: 'instanceId',
|
|
22
|
-
type: 'list',
|
|
23
|
-
when: !flags.instanceId
|
|
24
|
-
}
|
|
25
|
-
];
|
|
26
|
-
const answers = await inquirer.prompt(questions);
|
|
27
|
-
const instanceId = flags.instanceId || answers.instanceId;
|
|
28
|
-
updateEnvFileVariableValue(ENV_VARIABLES.INSTANCE_ID, instanceId);
|
|
29
|
-
ux.log(green(`Current instance has been set to ${bold(instanceId)}`));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Command } from '@oclif/core';
|
|
2
|
-
export default class InstanceStatus extends Command {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
authToken: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
-
instanceId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
-
orgId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
|
-
projectId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
-
};
|
|
11
|
-
run(): Promise<void>;
|
|
12
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Command, Flags, ux } from '@oclif/core';
|
|
2
|
-
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
3
|
-
import { checkThatEnvVariablesAreSet, green, red } from '../../utils.js';
|
|
4
|
-
export default class InstanceStatus extends Command {
|
|
5
|
-
static description = 'View the status of the current instance. View the status of a different instance by using flags.';
|
|
6
|
-
static examples = [
|
|
7
|
-
'<%= config.bin %> <%= command.id %>',
|
|
8
|
-
'<%= config.bin %> <%= command.id %> --orgId=1234 --projectId=1234 --instanceId=1234 --authToken=1234'
|
|
9
|
-
];
|
|
10
|
-
static flags = {
|
|
11
|
-
authToken: Flags.string({
|
|
12
|
-
char: 't',
|
|
13
|
-
description: 'Override current auth token.'
|
|
14
|
-
}),
|
|
15
|
-
instanceId: Flags.string({
|
|
16
|
-
char: 'i',
|
|
17
|
-
description: 'Override current instance by providing the ID of a different instance.'
|
|
18
|
-
}),
|
|
19
|
-
orgId: Flags.string({
|
|
20
|
-
char: 'o',
|
|
21
|
-
description: 'Override current organization by providing the ID of a different organization.'
|
|
22
|
-
}),
|
|
23
|
-
projectId: Flags.string({
|
|
24
|
-
char: 'p',
|
|
25
|
-
description: 'Override current project by providing the ID of a different project.'
|
|
26
|
-
})
|
|
27
|
-
};
|
|
28
|
-
async run() {
|
|
29
|
-
const { flags } = await this.parse(InstanceStatus);
|
|
30
|
-
if (!flags.authToken || !flags.instanceId || !flags.orgId || !flags.projectId) {
|
|
31
|
-
checkThatEnvVariablesAreSet(this.config.bin, true);
|
|
32
|
-
}
|
|
33
|
-
const diagnostics = await PowerSyncClient.getInstanceDiagnostics({
|
|
34
|
-
authToken: flags.authToken,
|
|
35
|
-
instanceId: flags.instanceId,
|
|
36
|
-
orgId: flags.orgId,
|
|
37
|
-
projectId: flags.projectId
|
|
38
|
-
});
|
|
39
|
-
const { errors } = diagnostics.connections[0];
|
|
40
|
-
if (errors.length > 0) {
|
|
41
|
-
ux.log(red(`❌ Errors found:`));
|
|
42
|
-
errors.map((error) => {
|
|
43
|
-
ux.log(red(`Level: ${error.level}`));
|
|
44
|
-
return ux.log(red(`Message: ${error.message}\n`));
|
|
45
|
-
});
|
|
46
|
-
return ux.exit(1);
|
|
47
|
-
}
|
|
48
|
-
ux.log(green(`✅ Instance is operational and no errors were found.`));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Command } from '@oclif/core';
|
|
2
|
-
export default class InstanceDeactivate extends Command {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
skipConfirmation: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
7
|
-
};
|
|
8
|
-
run(): Promise<void>;
|
|
9
|
-
}
|