powersync 0.8.0 → 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.
Files changed (135) hide show
  1. package/LICENSE +67 -0
  2. package/README.md +1376 -173
  3. package/bin/dev.cmd +3 -3
  4. package/bin/dev.js +20 -7
  5. package/bin/run.cmd +3 -3
  6. package/bin/run.js +9 -5
  7. package/dist/api/cloud/create-cloud-instance.d.ts +15 -0
  8. package/dist/api/cloud/create-cloud-instance.js +19 -0
  9. package/dist/api/cloud/fetch-cloud-config.d.ts +12 -0
  10. package/dist/api/cloud/fetch-cloud-config.js +18 -0
  11. package/dist/api/cloud/fetch-cloud-sync-rules-content.d.ts +7 -0
  12. package/dist/api/cloud/fetch-cloud-sync-rules-content.js +26 -0
  13. package/dist/api/cloud/test-connection.d.ts +16 -0
  14. package/dist/api/cloud/test-connection.js +36 -0
  15. package/dist/api/cloud/validate-cloud-link-config.d.ts +17 -0
  16. package/dist/api/cloud/validate-cloud-link-config.js +47 -0
  17. package/dist/api/cloud/wait-for-operation.d.ts +16 -0
  18. package/dist/api/cloud/wait-for-operation.js +33 -0
  19. package/dist/api/cloud/write-cloud-link.d.ts +10 -0
  20. package/dist/api/cloud/write-cloud-link.js +21 -0
  21. package/dist/api/display-status.d.ts +4 -0
  22. package/dist/api/display-status.js +80 -0
  23. package/dist/api/ide/configure-vscode-ide.d.ts +14 -0
  24. package/dist/api/ide/configure-vscode-ide.js +62 -0
  25. package/dist/api/login-server.d.ts +26 -0
  26. package/dist/api/login-server.js +137 -0
  27. package/dist/api/run-validation-tests.d.ts +63 -0
  28. package/dist/api/run-validation-tests.js +202 -0
  29. package/dist/api/self-hosted/fetch-self-hosted-sync-rules-content.d.ts +7 -0
  30. package/dist/api/self-hosted/fetch-self-hosted-sync-rules-content.js +26 -0
  31. package/dist/commands/configure/ide.d.ts +8 -0
  32. package/dist/commands/configure/ide.js +58 -0
  33. package/dist/commands/configure/index.d.ts +8 -0
  34. package/dist/commands/configure/index.js +11 -0
  35. package/dist/commands/deploy/index.d.ts +48 -0
  36. package/dist/commands/deploy/index.js +333 -0
  37. package/dist/commands/deploy/service-config.d.ts +14 -0
  38. package/dist/commands/deploy/service-config.js +30 -0
  39. package/dist/commands/deploy/sync-config.d.ts +24 -0
  40. package/dist/commands/deploy/sync-config.js +103 -0
  41. package/dist/commands/destroy.d.ts +14 -0
  42. package/dist/commands/destroy.js +62 -0
  43. package/dist/commands/fetch/config.d.ts +14 -0
  44. package/dist/commands/fetch/config.js +33 -0
  45. package/dist/commands/fetch/index.d.ts +13 -0
  46. package/dist/commands/fetch/index.js +16 -0
  47. package/dist/commands/fetch/instances.d.ts +47 -0
  48. package/dist/commands/fetch/instances.js +177 -0
  49. package/dist/commands/fetch/status.d.ts +18 -0
  50. package/dist/commands/fetch/status.js +60 -0
  51. package/dist/commands/{instance/schema.d.ts → generate/index.d.ts} +3 -1
  52. package/dist/commands/generate/index.js +11 -0
  53. package/dist/commands/generate/schema.d.ts +19 -0
  54. package/dist/commands/generate/schema.js +72 -0
  55. package/dist/commands/generate/token.d.ts +25 -0
  56. package/dist/commands/generate/token.js +124 -0
  57. package/dist/commands/init/cloud.d.ts +11 -0
  58. package/dist/commands/init/cloud.js +64 -0
  59. package/dist/commands/{init.d.ts → init/index.d.ts} +2 -1
  60. package/dist/commands/init/index.js +11 -0
  61. package/dist/commands/init/self-hosted.d.ts +11 -0
  62. package/dist/commands/init/self-hosted.js +60 -0
  63. package/dist/commands/link/cloud.d.ts +15 -0
  64. package/dist/commands/link/cloud.js +111 -0
  65. package/dist/commands/{instance/config.d.ts → link/index.d.ts} +3 -1
  66. package/dist/commands/link/index.js +11 -0
  67. package/dist/commands/link/self-hosted.d.ts +12 -0
  68. package/dist/commands/link/self-hosted.js +54 -0
  69. package/dist/commands/login.d.ts +8 -0
  70. package/dist/commands/login.js +107 -0
  71. package/dist/commands/logout.d.ts +8 -0
  72. package/dist/commands/logout.js +19 -0
  73. package/dist/commands/migrate/index.d.ts +7 -0
  74. package/dist/commands/migrate/index.js +10 -0
  75. package/dist/commands/migrate/sync-rules.d.ts +15 -0
  76. package/dist/commands/migrate/sync-rules.js +51 -0
  77. package/dist/commands/{instances.d.ts → pull/index.d.ts} +3 -1
  78. package/dist/commands/pull/index.js +11 -0
  79. package/dist/commands/pull/instance.d.ts +14 -0
  80. package/dist/commands/pull/instance.js +108 -0
  81. package/dist/commands/status.d.ts +1 -0
  82. package/dist/commands/status.js +2 -0
  83. package/dist/commands/stop.d.ts +14 -0
  84. package/dist/commands/stop.js +62 -0
  85. package/dist/commands/validate.d.ts +16 -0
  86. package/dist/commands/validate.js +165 -0
  87. package/dist/help.d.ts +31 -0
  88. package/dist/help.js +123 -0
  89. package/oclif.manifest.json +1259 -330
  90. package/package.json +104 -75
  91. package/templates/cloud/powersync/cli.yaml +3 -0
  92. package/templates/cloud/powersync/service.yaml +174 -0
  93. package/templates/cloud/powersync/sync-config.yaml +22 -0
  94. package/templates/self-hosted/base/powersync/cli.yaml +3 -0
  95. package/templates/self-hosted/base/powersync/service.yaml +243 -0
  96. package/templates/self-hosted/base/powersync/sync-config.yaml +22 -0
  97. package/templates/vscode/settings.json +3 -0
  98. package/dist/commands/init.js +0 -66
  99. package/dist/commands/instance/config.js +0 -23
  100. package/dist/commands/instance/create.d.ts +0 -36
  101. package/dist/commands/instance/create.js +0 -137
  102. package/dist/commands/instance/deploy.d.ts +0 -21
  103. package/dist/commands/instance/deploy.js +0 -91
  104. package/dist/commands/instance/destroy.d.ts +0 -9
  105. package/dist/commands/instance/destroy.js +0 -46
  106. package/dist/commands/instance/generate-dev-token.d.ts +0 -10
  107. package/dist/commands/instance/generate-dev-token.js +0 -54
  108. package/dist/commands/instance/schema.js +0 -20
  109. package/dist/commands/instance/set.d.ts +0 -9
  110. package/dist/commands/instance/set.js +0 -31
  111. package/dist/commands/instance/status.d.ts +0 -12
  112. package/dist/commands/instance/status.js +0 -50
  113. package/dist/commands/instance/stop.d.ts +0 -9
  114. package/dist/commands/instance/stop.js +0 -42
  115. package/dist/commands/instance/sync-rules/deploy.d.ts +0 -10
  116. package/dist/commands/instance/sync-rules/deploy.js +0 -49
  117. package/dist/commands/instance/sync-rules/generate-schema.d.ts +0 -10
  118. package/dist/commands/instance/sync-rules/generate-schema.js +0 -56
  119. package/dist/commands/instance/sync-rules/validate.d.ts +0 -9
  120. package/dist/commands/instance/sync-rules/validate.js +0 -29
  121. package/dist/commands/instances.js +0 -29
  122. package/dist/commands.utils.d.ts +0 -2
  123. package/dist/commands.utils.js +0 -131
  124. package/dist/connection.utils.d.ts +0 -56
  125. package/dist/connection.utils.js +0 -76
  126. package/dist/constants.d.ts +0 -8
  127. package/dist/constants.js +0 -10
  128. package/dist/instance-command-flags.d.ts +0 -13
  129. package/dist/instance-command-flags.js +0 -22
  130. package/dist/service/accounts.client.js +0 -11307
  131. package/dist/service/powersync.client.js +0 -75510
  132. package/dist/service/types.js +0 -1
  133. package/dist/service/utils.js +0 -153
  134. package/dist/utils.d.ts +0 -14
  135. 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()
@@ -0,0 +1,3 @@
1
+ {
2
+ "yaml.customTags": ["!env scalar"]
3
+ }
@@ -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,36 +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
- connectionType: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
7
- databaseName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
- databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
- databaseUsername: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
- hostname: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
- jwksUri: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
- jwtAudiences: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
13
- port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
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>;
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>;
20
- };
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;
36
- }
@@ -1,137 +0,0 @@
1
- /* eslint-disable camelcase */
2
- import { Command, Flags, ux } from '@oclif/core';
3
- import inquirer from 'inquirer';
4
- import ora from 'ora';
5
- import { generateCommonDeployQuestions } from '../../commands.utils.js';
6
- import { buildDatabaseConnection } from '../../connection.utils.js';
7
- import { generateCommonInstanceConfigFlags } from '../../instance-command-flags.js';
8
- import * as PowerSyncClient from '../../service/powersync.client.js';
9
- import { bold, checkThatEnvVariablesAreSet, green, red, updateEnvFileVariableValue } from '../../utils.js';
10
- export default class InstanceCreate extends Command {
11
- static description = 'Create a new instance.';
12
- static examples = ['<%= config.bin %> <%= command.id %>'];
13
- static flags = {
14
- name: Flags.string({ char: 'i', description: 'Name of the instance.' }),
15
- protocol: Flags.string({ description: 'Database protocol to use (e.g., for MongoDB: mongodb+srv or mongodb).' }),
16
- region: Flags.string({ char: 'r', description: 'Region to deploy instance to.' }),
17
- ...generateCommonInstanceConfigFlags()
18
- };
19
- async run() {
20
- checkThatEnvVariablesAreSet(this.config.bin);
21
- const parsed = await this.parse(InstanceCreate);
22
- const flags = parsed.flags;
23
- const regions = await PowerSyncClient.getRegions();
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 });
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();
37
- const instanceName = flags.name || answers.name;
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) {
56
- const region = flags.region?.toLowerCase() || answers.region?.toLowerCase();
57
- const useSupabaseAuth = flags.useSupabaseAuth || answers.useSupabaseAuth;
58
- const jwksUri = flags.jwksUri || answers.jwksUri;
59
- const answerAudiences = answers.jwtAudiences ? answers.jwtAudiences.split(',') : [];
60
- const flagsAudiences = flags.jwtAudiences ? flags.jwtAudiences.split(',') : [];
61
- const audiences = [...new Set([...flagsAudiences, ...answerAudiences])];
62
- const supabaseJWTSecret = flags.supabaseJWTSecret ?? answers.supabaseJWTSecret;
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
- });
73
- const config = {
74
- client_auth: {
75
- additional_audiences: audiences || undefined,
76
- jwks_uri: jwksUri || undefined,
77
- supabase: useSupabaseAuth,
78
- supabase_jwt_secret: supabaseJWTSecret
79
- ? {
80
- secret: supabaseJWTSecret
81
- }
82
- : undefined
83
- },
84
- region: region,
85
- replication: {
86
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- connections: [connection]
88
- }
89
- };
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: [] };
114
- }
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 };
136
- }
137
- }
@@ -1,21 +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
- connectionType: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
7
- databaseName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
- databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
- databaseUsername: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
- hostname: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
- jwksUri: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
- jwtAudiences: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
13
- port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
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>;
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>;
19
- };
20
- run(): Promise<void>;
21
- }
@@ -1,91 +0,0 @@
1
- /* eslint-disable camelcase */
2
- import { Command, Flags, ux } from '@oclif/core';
3
- import inquirer from 'inquirer';
4
- import ora from 'ora';
5
- import { generateCommonDeployQuestions } from '../../commands.utils.js';
6
- import { buildDatabaseConnection } from '../../connection.utils.js';
7
- import { generateCommonInstanceConfigFlags } from '../../instance-command-flags.js';
8
- import * as PowerSyncClient from '../../service/powersync.client.js';
9
- import { bold, checkThatEnvVariablesAreSet, green, red } from '../../utils.js';
10
- export default class InstanceDeploy extends Command {
11
- static description = 'Deploy changes to an existing instance.';
12
- static examples = ['<%= config.bin %> <%= command.id %>'];
13
- static flags = {
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()
17
- };
18
- async run() {
19
- checkThatEnvVariablesAreSet(this.config.bin, true);
20
- const parsed = await this.parse(InstanceDeploy);
21
- const flags = parsed.flags;
22
- let answers = {
23
- connectionType: undefined,
24
- databaseName: undefined,
25
- databasePassword: undefined,
26
- databaseUsername: undefined,
27
- hostname: undefined,
28
- jwksUri: undefined,
29
- jwtAudiences: undefined,
30
- port: undefined,
31
- protocol: undefined,
32
- region: undefined,
33
- useSupabaseAuth: undefined
34
- };
35
- if (!flags.skipInteraction) {
36
- const questions = generateCommonDeployQuestions(flags);
37
- answers = await inquirer.prompt(questions);
38
- }
39
- const useSupabaseAuth = flags.useSupabaseAuth || answers.useSupabaseAuth;
40
- const jwksUri = flags.jwksUri || answers.jwksUri;
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;
45
- const instanceConfig = await PowerSyncClient.getInstanceConfig();
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
- });
59
- const config = {
60
- client_auth: {
61
- additional_audiences: audiences || undefined,
62
- jwks_uri: jwksUri || undefined,
63
- supabase: useSupabaseAuth,
64
- supabase_jwt_secret: supabaseJWTSecret
65
- ? {
66
- secret: supabaseJWTSecret
67
- }
68
- : undefined
69
- },
70
- region,
71
- replication: {
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- connections: [connection]
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
- }