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
@@ -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
- }
@@ -1,42 +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, red, yellow } from '../../utils.js';
6
- export default class InstanceDeactivate extends Command {
7
- static description = 'Stop the current instance.';
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(InstanceDeactivate);
15
- const questions = [
16
- {
17
- message: 'Are you sure you want to do stop the instance?',
18
- name: 'areYouSure',
19
- type: 'confirm',
20
- when: !flags.skipConfirmation
21
- }
22
- ];
23
- const answers = await inquirer.prompt(questions);
24
- if (!answers.areYouSure && !flags.skipConfirmation) {
25
- return ux.log('Instance will not be stopped.');
26
- }
27
- const spinner = ora({
28
- prefixText: 'Stopping instance.\n ',
29
- spinner: 'moon',
30
- suffixText: '\nThis may take a few minutes.\n'
31
- });
32
- spinner.start();
33
- const instance = await PowerSyncClient.deactivateInstance();
34
- let status = 'pending';
35
- status = await PowerSyncClient.waitForStatusChange(instance.id);
36
- spinner.stop();
37
- if (status === 'failed') {
38
- return ux.error(red(`There was an error stopping the instance. Please try again.`), { exit: 1 });
39
- }
40
- ux.log(yellow(`Instance with id ${bold(instance.id)} has been stopped.`));
41
- }
42
- }
@@ -1,10 +0,0 @@
1
- import { Command } from '@oclif/core';
2
- export default class SyncRulesDeploy extends Command {
3
- static description: string;
4
- static examples: string[];
5
- static flags: {
6
- filePath: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
7
- skipConfirmation: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
8
- };
9
- run(): Promise<void>;
10
- }
@@ -1,49 +0,0 @@
1
- import { Command, Flags, ux } from '@oclif/core';
2
- import inquirer from 'inquirer';
3
- import fs from 'node:fs';
4
- import ora from 'ora';
5
- import * as PowerSyncClient from '../../../service/powersync.client.js';
6
- import { bold, checkThatEnvVariablesAreSet, green, red } from '../../../utils.js';
7
- export default class SyncRulesDeploy extends Command {
8
- static description = 'Deploy sync rules from a local sync rules config file to the current instance.';
9
- static examples = [
10
- '<%= config.bin %> <%= command.id %>',
11
- '<%= config.bin %> <%= command.id %> --filePath path/to/file',
12
- '<%= config.bin %> <%= command.id %> -f path/to/file'
13
- ];
14
- static flags = {
15
- filePath: Flags.string({ char: 'f', description: 'Path to the sync rules config file.', required: true }),
16
- skipConfirmation: Flags.boolean({ char: 's', description: 'Ignore confirmation question.' })
17
- };
18
- async run() {
19
- checkThatEnvVariablesAreSet(this.config.bin, true);
20
- const { flags } = await this.parse(SyncRulesDeploy);
21
- const questions = [
22
- {
23
- message: 'Are you sure you want to do deploy sync files?',
24
- name: 'areYouSure',
25
- type: 'confirm',
26
- when: !flags.skipConfirmation
27
- }
28
- ];
29
- const answers = await inquirer.prompt(questions);
30
- if (!answers.areYouSure && !flags.skipConfirmation) {
31
- return ux.log(red('Sync files were not deployed.'));
32
- }
33
- const syncRules = fs.readFileSync(flags.filePath, 'utf8');
34
- const spinner = ora({
35
- prefixText: 'Deploying sync rules to instance.\n',
36
- spinner: 'moon',
37
- suffixText: '\nThis may take a few minutes.\n'
38
- });
39
- spinner.start();
40
- const instance = await PowerSyncClient.deploySyncRules(syncRules);
41
- let status = 'pending';
42
- status = await PowerSyncClient.waitForStatusChange(instance.id);
43
- spinner.stop();
44
- if (status === 'failed') {
45
- return ux.error(red('There was an error creating the instance. Please try again.'), { exit: 1 });
46
- }
47
- ux.log(green(`Sync rules have successfully been deployed to instance with id ${bold(instance.id)}.`));
48
- }
49
- }
@@ -1,10 +0,0 @@
1
- import { Command } from '@oclif/core';
2
- export default class SyncRulesGenerateSchema extends Command {
3
- static description: string;
4
- static examples: string[];
5
- static flags: {
6
- filePath: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
7
- language: 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,56 +0,0 @@
1
- import { Command, Flags, ux } from '@oclif/core';
2
- import inquirer from 'inquirer';
3
- import fs from 'node:fs';
4
- import { LANGUAGES } from '../../../constants.js';
5
- import * as PowerSyncClient from '../../../service/powersync.client.js';
6
- import { checkThatEnvVariablesAreSet, green, red } from '../../../utils.js';
7
- export default class SyncRulesGenerateSchema extends Command {
8
- static description = 'Generate schema in your language from your sync rules config file.';
9
- static examples = [
10
- '<%= config.bin %> <%= command.id %>',
11
- '<%= config.bin %> <%= command.id %> --filePath path/to/file',
12
- '<%= config.bin %> <%= command.id %> -f path/to/file'
13
- ];
14
- static flags = {
15
- filePath: Flags.string({ char: 'f', description: 'Path to the sync rules config file.', required: true }),
16
- language: Flags.string({
17
- char: 'l',
18
- description: 'Choose language for output.',
19
- options: LANGUAGES
20
- })
21
- };
22
- async run() {
23
- checkThatEnvVariablesAreSet(this.config.bin, true);
24
- const { flags } = await this.parse(SyncRulesGenerateSchema);
25
- const questions = [
26
- {
27
- choices: LANGUAGES,
28
- message: 'Which language would you like to output to?',
29
- name: 'language',
30
- type: 'list',
31
- when: !flags.language
32
- }
33
- ];
34
- const answers = await inquirer.prompt(questions);
35
- const schema = await PowerSyncClient.getInstanceSchema();
36
- const parsedSchema = new PowerSyncClient.StaticSchema(schema.connections);
37
- const syncRulesFromFile = fs.readFileSync(flags.filePath, 'utf8');
38
- const syncRules = PowerSyncClient.SqlSyncRules.fromYaml(syncRulesFromFile, {
39
- defaultSchema: 'public',
40
- schema: parsedSchema,
41
- throwOnError: false
42
- });
43
- const { errors } = syncRules;
44
- if (errors.length > 0) {
45
- ux.log(red(`❌ Sync rule errors found:`));
46
- errors.map((error) => {
47
- return ux.log(red(error.message));
48
- });
49
- return ux.exit(1);
50
- }
51
- const language = flags.language || answers.language;
52
- const generator = PowerSyncClient.schemaGenerators[language];
53
- const languageSchema = await generator.generate(syncRules, parsedSchema);
54
- ux.log(green(languageSchema));
55
- }
56
- }
@@ -1,9 +0,0 @@
1
- import { Command } from '@oclif/core';
2
- export default class SyncRulesValidate extends Command {
3
- static description: string;
4
- static examples: string[];
5
- static flags: {
6
- filePath: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
7
- };
8
- run(): Promise<void>;
9
- }
@@ -1,29 +0,0 @@
1
- import { Command, Flags, ux } from '@oclif/core';
2
- import fs from 'node:fs';
3
- import * as PowerSyncClient from '../../../service/powersync.client.js';
4
- import { checkThatEnvVariablesAreSet, green, red } from '../../../utils.js';
5
- export default class SyncRulesValidate extends Command {
6
- static description = 'Validate sync rules from a local sync rules config file.';
7
- static examples = [
8
- '<%= config.bin %> <%= command.id %>',
9
- '<%= config.bin %> <%= command.id %> --filePath path/to/file',
10
- '<%= config.bin %> <%= command.id %> -f path/to/file'
11
- ];
12
- static flags = {
13
- filePath: Flags.string({ char: 'f', description: 'Path to the sync rules config file.', required: true })
14
- };
15
- async run() {
16
- checkThatEnvVariablesAreSet(this.config.bin, true);
17
- const { flags } = await this.parse(SyncRulesValidate);
18
- const syncRules = fs.readFileSync(flags.filePath, 'utf8');
19
- const validation = await PowerSyncClient.validateSyncRules(syncRules);
20
- if (validation.errors.length > 0) {
21
- ux.log(red(`❌ errors found:`));
22
- for (const error of validation.errors) {
23
- ux.log(red(error.message));
24
- }
25
- return ux.exit(1);
26
- }
27
- ux.log(green('✅ Sync rules are valid'));
28
- }
29
- }
@@ -1,29 +0,0 @@
1
- import { Command, ux } from '@oclif/core';
2
- import * as AccountsClient from '../service/accounts.client.js';
3
- import * as PowerSyncClient from '../service/powersync.client.js';
4
- import { bold, checkThatEnvVariablesAreSet, green, red } from '../utils.js';
5
- export default class InstancesList extends Command {
6
- static description = 'View list of instances.';
7
- static examples = ['<%= config.bin %> <%= command.id %>'];
8
- async run() {
9
- checkThatEnvVariablesAreSet(this.config.bin, false);
10
- const project = await AccountsClient.getCurrentPowerSyncProject();
11
- const list = await PowerSyncClient.getInstancesList();
12
- const { instances } = list;
13
- if (instances.length === 0) {
14
- return ux.log(`It seems like you have ${red('no')} instances. Run ${green(`"npx ${this.config.bin} instance create"`)} to create your first instance.`);
15
- }
16
- ux.log(`Your ${bold('project')} is currently set to ${green(project.name)}.`);
17
- if (process.env.INSTANCE_ID) {
18
- const currentInstance = instances.find((instance) => instance.id === process.env.INSTANCE_ID);
19
- if (currentInstance) {
20
- ux.log(`Your ${bold('instance')} is currently set to ${green(currentInstance.name)}.\n`);
21
- }
22
- }
23
- ux.table(instances, {
24
- id: { header: 'ID' },
25
- name: { minWidth: 7 }
26
- }, { printLine: this.log.bind(this) });
27
- ux.log(`\nRun ${green(`"npx ${this.config.bin} instance set"`)} to use one of the instances.`);
28
- }
29
- }
@@ -1,2 +0,0 @@
1
- import type { DistinctQuestion } from 'inquirer';
2
- export declare const generateCommonDeployQuestions: (flags: any) => DistinctQuestion[];
@@ -1,131 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
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
16
- {
17
- message: 'What is your database hostname?',
18
- name: 'hostname',
19
- type: 'input',
20
- validate(value) {
21
- return value.length > 0 ? true : 'Please enter your hostname.';
22
- },
23
- when: !flags.hostname
24
- },
25
- {
26
- default(answers) {
27
- const connType = flags.connectionType || answers.connectionType;
28
- return connType === 'mongodb' ? 27_017 : 5432;
29
- },
30
- message: 'What is the port number of your database?',
31
- name: 'port',
32
- type: 'input',
33
- validate(value) {
34
- const number = Number.parseFloat(value);
35
- if (Number.isNaN(number)) {
36
- return 'Please enter a valid port number.';
37
- }
38
- return String(value).length > 0 ? true : 'Please enter your port number.';
39
- },
40
- when: !flags.port
41
- },
42
- {
43
- default(answers) {
44
- const connType = flags.connectionType || answers.connectionType;
45
- return connType === 'postgresql' ? 'postgres' : undefined;
46
- },
47
- message: 'What is your database name?',
48
- name: 'databaseName',
49
- type: 'input',
50
- validate(value) {
51
- return value.length > 0 ? true : 'Please enter your database name.';
52
- },
53
- when() {
54
- if (flags.databaseName) {
55
- return false;
56
- }
57
- return true;
58
- }
59
- },
60
- {
61
- default(answers) {
62
- const connType = flags.connectionType || answers.connectionType;
63
- return connType === 'postgresql' ? 'postgres' : undefined;
64
- },
65
- message: 'What is your database username?',
66
- name: 'databaseUsername',
67
- type: 'input',
68
- validate(value) {
69
- return value.length > 0 ? true : 'Please enter your database username.';
70
- },
71
- when: !flags.databaseUserName
72
- },
73
- {
74
- message: 'What is your database password?',
75
- name: 'databasePassword',
76
- type: 'password',
77
- validate(value) {
78
- return value.length > 0 ? true : 'Please enter your password.';
79
- },
80
- when: !flags.databasePassword
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)
93
- {
94
- default: false,
95
- message: 'Are you using Supabase auth?',
96
- name: 'useSupabaseAuth',
97
- type: 'confirm',
98
- when: (answers) => flags.useSupabaseAuth === null &&
99
- !flags.jwksUri &&
100
- (flags.connectionType === 'postgresql' || answers.connectionType === 'postgresql')
101
- },
102
- {
103
- message: 'Enter the Supabase JWT secret (see https://docs.powersync.com/installation/authentication-setup/supabase-auth#supabase-auth)',
104
- name: 'supabaseJWTSecret',
105
- type: 'password',
106
- when: (answers) => (flags.useSupabaseAuth || answers.useSupabaseAuth) && !flags.supabaseJWTSecret
107
- },
108
- {
109
- message: 'Enter your JWKS URI (must include https://)?',
110
- name: 'jwksUri',
111
- type: 'input',
112
- validate(value) {
113
- const urlRegex = /^(https?|ftp):\/\/[^\s#$./?].\S*$/i;
114
- return urlRegex.test(value) ? true : 'Please enter a valid URL.';
115
- },
116
- when: (answers) => !flags.jwksUri && !answers.useSupabaseAuth
117
- },
118
- {
119
- default: false,
120
- message: 'Do you want to add audiences?',
121
- name: 'useAudiences',
122
- type: 'confirm',
123
- when: !flags.jwksUri
124
- },
125
- {
126
- message: 'Enter your JWT Audiences? (comma separated)',
127
- name: 'jwtAudiences',
128
- type: 'input',
129
- when: (answers) => answers.useAudiences
130
- }
131
- ];
@@ -1,56 +0,0 @@
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 {};
@@ -1,76 +0,0 @@
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
- }
@@ -1,8 +0,0 @@
1
- export declare const APP_NAME = "POWERSYNC_CLI";
2
- export declare const POWERSYNC_DIRECTORY: string;
3
- export declare const ENV_FILE_PATH: string;
4
- export declare const ENDPOINTS: {
5
- ACCOUNTS_URL: string;
6
- POWERSYNC_URL: string;
7
- };
8
- export declare const LANGUAGES: string[];
package/dist/constants.js DELETED
@@ -1,10 +0,0 @@
1
- import { homedir } from 'node:os';
2
- import path from 'node:path';
3
- export const APP_NAME = 'POWERSYNC_CLI';
4
- export const POWERSYNC_DIRECTORY = path.join(homedir(), '/.powersync');
5
- export const ENV_FILE_PATH = `${POWERSYNC_DIRECTORY}/.env.powersync`;
6
- export const ENDPOINTS = {
7
- ACCOUNTS_URL: 'https://accounts.journeyapps.com',
8
- POWERSYNC_URL: 'https://powersync-api.journeyapps.com'
9
- };
10
- export const LANGUAGES = ['js', 'dart'];
@@ -1,13 +0,0 @@
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
- };
@@ -1,22 +0,0 @@
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
- });