powersync 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -65
- package/dist/commands/init.js +23 -14
- package/dist/commands/instance/config.js +1 -1
- package/dist/commands/instance/create.js +30 -27
- package/dist/commands/instance/deploy.js +8 -8
- package/dist/commands/instance/destroy.js +13 -9
- package/dist/commands/instance/schema.js +1 -1
- package/dist/commands/instance/set.js +2 -2
- package/dist/commands/instance/status.d.ts +6 -0
- package/dist/commands/instance/status.js +23 -6
- package/dist/commands/instance/stop.js +3 -3
- package/dist/commands/instance/sync-rules/deploy.js +3 -3
- package/dist/commands/instance/sync-rules/generate-schema.js +4 -4
- package/dist/commands/instance/sync-rules/validate.js +2 -2
- package/dist/commands/instances.js +12 -3
- package/dist/constants.js +1 -1
- package/dist/service/accounts.client.js +11 -2
- package/dist/service/powersync.client.js +139 -72
- package/dist/service/utils.js +13 -1
- package/dist/utils.js +12 -8
- package/oclif.manifest.json +76 -44
- package/package.json +12 -2
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { Command, ux } from '@oclif/core';
|
|
1
|
+
import { Command, Flags, ux } from '@oclif/core';
|
|
2
2
|
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
3
3
|
import { checkForValidEnvFile, green, red } from '../../utils.js';
|
|
4
4
|
export default class InstanceStatus extends Command {
|
|
5
|
-
static description = '
|
|
6
|
-
static examples = [
|
|
5
|
+
static description = 'View the status of the current instance.';
|
|
6
|
+
static examples = [
|
|
7
|
+
'<%= config.bin %> <%= command.id %>',
|
|
8
|
+
'<%= config.bin %> <%= command.id %> --orgId=1234 --appId=1234 --instanceId=1234 --authToken=1234'
|
|
9
|
+
];
|
|
10
|
+
static flags = {
|
|
11
|
+
appId: Flags.string({ char: 'a', description: 'app id to use' }),
|
|
12
|
+
authToken: Flags.string({ char: 't', description: 'auth token to use' }),
|
|
13
|
+
instanceId: Flags.string({ char: 'i', description: 'instance id to use' }),
|
|
14
|
+
orgId: Flags.string({ char: 'o', description: 'org id to use' })
|
|
15
|
+
};
|
|
7
16
|
async run() {
|
|
8
|
-
|
|
9
|
-
|
|
17
|
+
const { flags } = await this.parse(InstanceStatus);
|
|
18
|
+
if (!flags.authToken || !flags.instanceId || !flags.orgId || !flags.appId) {
|
|
19
|
+
checkForValidEnvFile(this.config.bin, true);
|
|
20
|
+
}
|
|
21
|
+
const diagnostics = await PowerSyncClient.getInstanceDiagnostics({
|
|
22
|
+
appId: flags.appId,
|
|
23
|
+
authToken: flags.authToken,
|
|
24
|
+
instanceId: flags.instanceId,
|
|
25
|
+
orgId: flags.orgId
|
|
26
|
+
});
|
|
10
27
|
const { errors } = diagnostics.connections[0];
|
|
11
28
|
if (errors.length > 0) {
|
|
12
|
-
ux.log(red(`❌
|
|
29
|
+
ux.log(red(`❌ Errors found:`));
|
|
13
30
|
errors.map((error) => {
|
|
14
31
|
ux.log(red(`Level: ${error.level}`));
|
|
15
32
|
return ux.log(red(`Message: ${error.message}\n`));
|
|
@@ -4,10 +4,10 @@ import ora from 'ora';
|
|
|
4
4
|
import * as PowerSyncClient from '../../service/powersync.client.js';
|
|
5
5
|
import { bold, checkForValidEnvFile, red, yellow } from '../../utils.js';
|
|
6
6
|
export default class InstanceDeactivate extends Command {
|
|
7
|
-
static description = '
|
|
8
|
-
static examples = ['<%= config.bin %> <%= command.id %>'
|
|
7
|
+
static description = 'Stop the current instance.';
|
|
8
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
9
9
|
static flags = {
|
|
10
|
-
skipConfirmation: Flags.boolean({ char: 's', description: 'Ignore confirmation question' })
|
|
10
|
+
skipConfirmation: Flags.boolean({ char: 's', description: 'Ignore confirmation question.' })
|
|
11
11
|
};
|
|
12
12
|
async run() {
|
|
13
13
|
checkForValidEnvFile(this.config.bin, true);
|
|
@@ -5,15 +5,15 @@ import ora from 'ora';
|
|
|
5
5
|
import * as PowerSyncClient from '../../../service/powersync.client.js';
|
|
6
6
|
import { bold, checkForValidEnvFile, green, red } from '../../../utils.js';
|
|
7
7
|
export default class SyncRulesDeploy extends Command {
|
|
8
|
-
static description = '
|
|
8
|
+
static description = 'Deploy sync rules from a local file to the current instance.';
|
|
9
9
|
static examples = [
|
|
10
10
|
'<%= config.bin %> <%= command.id %>',
|
|
11
11
|
'<%= config.bin %> <%= command.id %> --filePath path/to/file',
|
|
12
12
|
'<%= config.bin %> <%= command.id %> -f path/to/file'
|
|
13
13
|
];
|
|
14
14
|
static flags = {
|
|
15
|
-
filePath: Flags.string({ char: 'f', description: 'Path to the file', required: true }),
|
|
16
|
-
skipConfirmation: Flags.boolean({ char: 's', description: 'Ignore confirmation question' })
|
|
15
|
+
filePath: Flags.string({ char: 'f', description: 'Path to the file.', required: true }),
|
|
16
|
+
skipConfirmation: Flags.boolean({ char: 's', description: 'Ignore confirmation question.' })
|
|
17
17
|
};
|
|
18
18
|
async run() {
|
|
19
19
|
checkForValidEnvFile(this.config.bin, true);
|
|
@@ -5,17 +5,17 @@ import { LANGUAGES } from '../../../constants.js';
|
|
|
5
5
|
import * as PowerSyncClient from '../../../service/powersync.client.js';
|
|
6
6
|
import { checkForValidEnvFile, green, red } from '../../../utils.js';
|
|
7
7
|
export default class SyncRulesGenerateSchema extends Command {
|
|
8
|
-
static description = '
|
|
8
|
+
static description = 'Generate schema in your language from sync rules.';
|
|
9
9
|
static examples = [
|
|
10
10
|
'<%= config.bin %> <%= command.id %>',
|
|
11
11
|
'<%= config.bin %> <%= command.id %> --filePath path/to/file',
|
|
12
12
|
'<%= config.bin %> <%= command.id %> -f path/to/file'
|
|
13
13
|
];
|
|
14
14
|
static flags = {
|
|
15
|
-
filePath: Flags.string({ char: 'f', description: 'Path to the file', required: true }),
|
|
15
|
+
filePath: Flags.string({ char: 'f', description: 'Path to the file.', required: true }),
|
|
16
16
|
language: Flags.string({
|
|
17
17
|
char: 'l',
|
|
18
|
-
description: 'Choose language for output',
|
|
18
|
+
description: 'Choose language for output.',
|
|
19
19
|
options: LANGUAGES
|
|
20
20
|
})
|
|
21
21
|
};
|
|
@@ -41,7 +41,7 @@ export default class SyncRulesGenerateSchema extends Command {
|
|
|
41
41
|
});
|
|
42
42
|
const { errors } = syncRules;
|
|
43
43
|
if (errors.length > 0) {
|
|
44
|
-
ux.log(red(`❌
|
|
44
|
+
ux.log(red(`❌ Sync rule errors found:`));
|
|
45
45
|
errors.map((error) => {
|
|
46
46
|
return ux.log(red(error.message));
|
|
47
47
|
});
|
|
@@ -3,14 +3,14 @@ import fs from 'node:fs';
|
|
|
3
3
|
import * as PowerSyncClient from '../../../service/powersync.client.js';
|
|
4
4
|
import { checkForValidEnvFile, green, red } from '../../../utils.js';
|
|
5
5
|
export default class SyncRulesValidate extends Command {
|
|
6
|
-
static description = '
|
|
6
|
+
static description = 'Validate sync rules from a local file.';
|
|
7
7
|
static examples = [
|
|
8
8
|
'<%= config.bin %> <%= command.id %>',
|
|
9
9
|
'<%= config.bin %> <%= command.id %> --filePath path/to/file',
|
|
10
10
|
'<%= config.bin %> <%= command.id %> -f path/to/file'
|
|
11
11
|
];
|
|
12
12
|
static flags = {
|
|
13
|
-
filePath: Flags.string({ char: 'f', description: 'Path to the file', required: true })
|
|
13
|
+
filePath: Flags.string({ char: 'f', description: 'Path to the file.', required: true })
|
|
14
14
|
};
|
|
15
15
|
async run() {
|
|
16
16
|
checkForValidEnvFile(this.config.bin, true);
|
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
import { Command, ux } from '@oclif/core';
|
|
2
|
+
import * as AccountsClient from '../service/accounts.client.js';
|
|
2
3
|
import * as PowerSyncClient from '../service/powersync.client.js';
|
|
3
|
-
import { checkForValidEnvFile, green, red } from '../utils.js';
|
|
4
|
+
import { bold, checkForValidEnvFile, green, red } from '../utils.js';
|
|
4
5
|
export default class InstancesList extends Command {
|
|
5
|
-
static description = '
|
|
6
|
+
static description = 'View list of instances.';
|
|
6
7
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
7
8
|
async run() {
|
|
8
9
|
checkForValidEnvFile(this.config.bin, false);
|
|
10
|
+
const app = await AccountsClient.getCurrentPowerSyncApp();
|
|
9
11
|
const list = await PowerSyncClient.getInstancesList();
|
|
10
12
|
const { instances } = list;
|
|
11
13
|
if (instances.length === 0) {
|
|
12
14
|
return ux.log(`It seems like you have ${red('no')} instances. Run ${green('"powersync instance create"')} to create your first instance.`);
|
|
13
15
|
}
|
|
16
|
+
ux.log(`Your ${bold('app')} is currently set to ${green(app.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
|
+
}
|
|
14
23
|
ux.table(instances, {
|
|
15
24
|
id: { header: 'ID' },
|
|
16
25
|
name: { minWidth: 7 }
|
|
17
26
|
}, { printLine: this.log.bind(this) });
|
|
18
|
-
ux.log(`\
|
|
27
|
+
ux.log(`\nRun ${green(`"${this.config.bin} instance set"`)} to use one of the instances.`);
|
|
19
28
|
}
|
|
20
29
|
}
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { homedir } from 'node:os';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
export const POWERSYNC_DIRECTORY = path.join(homedir(), '
|
|
3
|
+
export const POWERSYNC_DIRECTORY = path.join(homedir(), '/.powersync');
|
|
4
4
|
export const ENV_FILE_PATH = `${POWERSYNC_DIRECTORY}/.env.powersync`;
|
|
5
5
|
export const ENDPOINTS = {
|
|
6
6
|
ACCOUNTS_URL: 'https://accounts.journeyapps.com',
|
|
@@ -11093,7 +11093,7 @@ main$1.exports.populate = DotenvModule.populate;
|
|
|
11093
11093
|
|
|
11094
11094
|
main$1.exports = DotenvModule;
|
|
11095
11095
|
|
|
11096
|
-
const POWERSYNC_DIRECTORY = path$1.join(homedir(), "
|
|
11096
|
+
const POWERSYNC_DIRECTORY = path$1.join(homedir(), "/.powersync");
|
|
11097
11097
|
const ENV_FILE_PATH = `${POWERSYNC_DIRECTORY}/.env.powersync`;
|
|
11098
11098
|
const ENDPOINTS = {
|
|
11099
11099
|
ACCOUNTS_URL: "https://accounts.journeyapps.com",
|
|
@@ -11126,5 +11126,14 @@ const getPowerSyncApps = async (bearerToken) => {
|
|
|
11126
11126
|
const apps = response.objects.filter((obj) => obj.features.includes(dist$4.ProjectFeatureFlags.POWERSYNC)).map((obj) => ({ name: obj.name, value: obj.id }));
|
|
11127
11127
|
return apps;
|
|
11128
11128
|
};
|
|
11129
|
+
const getCurrentPowerSyncApp = async () => {
|
|
11130
|
+
const headers = generateHeader(process.env.CARDINAL_TOKEN);
|
|
11131
|
+
const response = await accountsClient(headers).listApps({});
|
|
11132
|
+
const app = response.objects.find((obj) => obj.id === process.env.APP_ID);
|
|
11133
|
+
if (!app) {
|
|
11134
|
+
throw new Error("No app found.");
|
|
11135
|
+
}
|
|
11136
|
+
return app;
|
|
11137
|
+
};
|
|
11129
11138
|
|
|
11130
|
-
export { accountsClient, getOrgs, getPowerSyncApps };
|
|
11139
|
+
export { accountsClient, getCurrentPowerSyncApp, getOrgs, getPowerSyncApps };
|
|
@@ -11482,7 +11482,7 @@ main$1.exports.populate = DotenvModule.populate;
|
|
|
11482
11482
|
|
|
11483
11483
|
main$1.exports = DotenvModule;
|
|
11484
11484
|
|
|
11485
|
-
const POWERSYNC_DIRECTORY = path$1.join(homedir(), "
|
|
11485
|
+
const POWERSYNC_DIRECTORY = path$1.join(homedir(), "/.powersync");
|
|
11486
11486
|
const ENV_FILE_PATH = `${POWERSYNC_DIRECTORY}/.env.powersync`;
|
|
11487
11487
|
const ENDPOINTS = {
|
|
11488
11488
|
ACCOUNTS_URL: "https://accounts.journeyapps.com",
|
|
@@ -11494,6 +11494,18 @@ const generateHeader = (bearerToken) => ({
|
|
|
11494
11494
|
Authorization: `Bearer ${bearerToken}`,
|
|
11495
11495
|
ContentType: "application/json"
|
|
11496
11496
|
});
|
|
11497
|
+
const checkAppId = (appId) => {
|
|
11498
|
+
if (!appId)
|
|
11499
|
+
throw new Error("No app id found");
|
|
11500
|
+
};
|
|
11501
|
+
const checkOrgId = (orgId) => {
|
|
11502
|
+
if (!orgId)
|
|
11503
|
+
throw new Error("No org id found");
|
|
11504
|
+
};
|
|
11505
|
+
const checkInstanceId = (instanceId) => {
|
|
11506
|
+
if (!instanceId)
|
|
11507
|
+
throw new Error("No instance id found");
|
|
11508
|
+
};
|
|
11497
11509
|
|
|
11498
11510
|
const ALIAS = Symbol.for('yaml.alias');
|
|
11499
11511
|
const DOC = Symbol.for('yaml.document');
|
|
@@ -37347,85 +37359,132 @@ const schemaGenerators = {
|
|
|
37347
37359
|
};
|
|
37348
37360
|
|
|
37349
37361
|
config_1({ path: ENV_FILE_PATH });
|
|
37350
|
-
const { APP_ID,
|
|
37362
|
+
const { APP_ID, AUTH_TOKEN, INSTANCE_ID, ORG_ID } = process.env;
|
|
37351
37363
|
var ENV_VARIABLES;
|
|
37352
37364
|
(function(ENV_VARIABLES2) {
|
|
37353
37365
|
ENV_VARIABLES2["APP_ID"] = "APP_ID";
|
|
37354
|
-
ENV_VARIABLES2["
|
|
37366
|
+
ENV_VARIABLES2["AUTH_TOKEN"] = "AUTH_TOKEN";
|
|
37355
37367
|
ENV_VARIABLES2["INSTANCE_ID"] = "INSTANCE_ID";
|
|
37356
37368
|
ENV_VARIABLES2["ORG_ID"] = "ORG_ID";
|
|
37357
37369
|
})(ENV_VARIABLES || (ENV_VARIABLES = {}));
|
|
37358
|
-
const powerSyncClient = (
|
|
37359
|
-
|
|
37360
|
-
|
|
37361
|
-
|
|
37362
|
-
if (!APP_ID) {
|
|
37363
|
-
throw new Error(`${ENV_VARIABLES.APP_ID} is not set in environment`);
|
|
37370
|
+
const powerSyncClient = ({ authToken } = {}) => {
|
|
37371
|
+
const finalToken = authToken || AUTH_TOKEN;
|
|
37372
|
+
if (!finalToken) {
|
|
37373
|
+
throw new Error("No auth token found");
|
|
37364
37374
|
}
|
|
37365
|
-
|
|
37366
|
-
throw new Error(`${ENV_VARIABLES.ORG_ID} is not set in environment`);
|
|
37367
|
-
}
|
|
37368
|
-
if (requiresInstanceId && !INSTANCE_ID) {
|
|
37369
|
-
throw new Error(`${ENV_VARIABLES.INSTANCE_ID} is not set in environment. You need to set an instance using \`powersync instance set\``);
|
|
37370
|
-
}
|
|
37371
|
-
const HEADERS = generateHeader(CARDINAL_TOKEN);
|
|
37375
|
+
const HEADERS = generateHeader(finalToken);
|
|
37372
37376
|
return new Client_1({
|
|
37373
37377
|
client: dist$4.createWebNetworkClient({ headers: HEADERS }),
|
|
37374
37378
|
endpoint: ENDPOINTS.POWERSYNC_URL
|
|
37375
37379
|
});
|
|
37376
37380
|
};
|
|
37377
|
-
const getInstancesList = async () =>
|
|
37378
|
-
|
|
37379
|
-
|
|
37380
|
-
|
|
37381
|
-
|
|
37382
|
-
|
|
37383
|
-
|
|
37384
|
-
|
|
37385
|
-
|
|
37386
|
-
|
|
37387
|
-
|
|
37388
|
-
|
|
37389
|
-
|
|
37390
|
-
|
|
37391
|
-
|
|
37392
|
-
|
|
37393
|
-
|
|
37394
|
-
|
|
37395
|
-
})
|
|
37396
|
-
const
|
|
37397
|
-
|
|
37398
|
-
|
|
37399
|
-
|
|
37400
|
-
|
|
37401
|
-
|
|
37402
|
-
|
|
37403
|
-
|
|
37404
|
-
|
|
37405
|
-
|
|
37406
|
-
|
|
37407
|
-
|
|
37408
|
-
|
|
37409
|
-
|
|
37410
|
-
|
|
37411
|
-
|
|
37412
|
-
|
|
37413
|
-
|
|
37414
|
-
|
|
37415
|
-
|
|
37416
|
-
|
|
37417
|
-
|
|
37418
|
-
|
|
37419
|
-
|
|
37420
|
-
|
|
37421
|
-
|
|
37422
|
-
|
|
37423
|
-
|
|
37424
|
-
|
|
37425
|
-
|
|
37426
|
-
|
|
37427
|
-
});
|
|
37381
|
+
const getInstancesList = async () => {
|
|
37382
|
+
checkOrgId(ORG_ID);
|
|
37383
|
+
checkAppId(APP_ID);
|
|
37384
|
+
return powerSyncClient().listInstances({
|
|
37385
|
+
app_id: APP_ID,
|
|
37386
|
+
org_id: ORG_ID
|
|
37387
|
+
});
|
|
37388
|
+
};
|
|
37389
|
+
const getInstanceConfig = async () => {
|
|
37390
|
+
checkOrgId(ORG_ID);
|
|
37391
|
+
checkAppId(APP_ID);
|
|
37392
|
+
checkInstanceId(INSTANCE_ID);
|
|
37393
|
+
return powerSyncClient().getInstanceConfig({
|
|
37394
|
+
app_id: APP_ID,
|
|
37395
|
+
id: INSTANCE_ID,
|
|
37396
|
+
org_id: ORG_ID
|
|
37397
|
+
});
|
|
37398
|
+
};
|
|
37399
|
+
const getInstanceDiagnostics = async ({ appId, authToken, instanceId, orgId }) => {
|
|
37400
|
+
const finalAppId = appId || APP_ID;
|
|
37401
|
+
const finalInstanceId = instanceId || INSTANCE_ID;
|
|
37402
|
+
const finalOrgId = orgId || ORG_ID;
|
|
37403
|
+
checkOrgId(finalOrgId);
|
|
37404
|
+
checkAppId(finalAppId);
|
|
37405
|
+
checkInstanceId(finalInstanceId);
|
|
37406
|
+
return powerSyncClient({ authToken }).getInstanceDiagnostics({
|
|
37407
|
+
app_id: finalAppId,
|
|
37408
|
+
id: finalInstanceId,
|
|
37409
|
+
org_id: finalOrgId
|
|
37410
|
+
});
|
|
37411
|
+
};
|
|
37412
|
+
const getInstanceSchema = async () => {
|
|
37413
|
+
checkOrgId(ORG_ID);
|
|
37414
|
+
checkAppId(APP_ID);
|
|
37415
|
+
checkInstanceId(INSTANCE_ID);
|
|
37416
|
+
return powerSyncClient().getInstanceSchema({
|
|
37417
|
+
app_id: APP_ID,
|
|
37418
|
+
id: INSTANCE_ID,
|
|
37419
|
+
org_id: ORG_ID
|
|
37420
|
+
});
|
|
37421
|
+
};
|
|
37422
|
+
const getInstanceStatus = async (instanceId) => {
|
|
37423
|
+
const finalInstanceId = instanceId || INSTANCE_ID;
|
|
37424
|
+
checkOrgId(ORG_ID);
|
|
37425
|
+
checkAppId(APP_ID);
|
|
37426
|
+
checkInstanceId(finalInstanceId);
|
|
37427
|
+
return powerSyncClient().getInstanceStatus({
|
|
37428
|
+
app_id: APP_ID,
|
|
37429
|
+
id: instanceId ?? INSTANCE_ID,
|
|
37430
|
+
org_id: ORG_ID
|
|
37431
|
+
});
|
|
37432
|
+
};
|
|
37433
|
+
const destroyInstance = async () => {
|
|
37434
|
+
checkOrgId(ORG_ID);
|
|
37435
|
+
checkAppId(APP_ID);
|
|
37436
|
+
checkInstanceId(INSTANCE_ID);
|
|
37437
|
+
return powerSyncClient().destroyInstance({
|
|
37438
|
+
app_id: APP_ID,
|
|
37439
|
+
id: INSTANCE_ID,
|
|
37440
|
+
org_id: ORG_ID
|
|
37441
|
+
});
|
|
37442
|
+
};
|
|
37443
|
+
const deactivateInstance = async () => {
|
|
37444
|
+
checkOrgId(ORG_ID);
|
|
37445
|
+
checkAppId(APP_ID);
|
|
37446
|
+
checkInstanceId(INSTANCE_ID);
|
|
37447
|
+
return powerSyncClient().deactivateInstance({
|
|
37448
|
+
app_id: APP_ID,
|
|
37449
|
+
id: INSTANCE_ID,
|
|
37450
|
+
org_id: ORG_ID
|
|
37451
|
+
});
|
|
37452
|
+
};
|
|
37453
|
+
const createInstance = async (name) => {
|
|
37454
|
+
checkOrgId(ORG_ID);
|
|
37455
|
+
checkAppId(APP_ID);
|
|
37456
|
+
checkInstanceId(INSTANCE_ID);
|
|
37457
|
+
return powerSyncClient().createInstance({
|
|
37458
|
+
app_id: APP_ID,
|
|
37459
|
+
name,
|
|
37460
|
+
org_id: ORG_ID
|
|
37461
|
+
});
|
|
37462
|
+
};
|
|
37463
|
+
const testConnection = async (connection) => {
|
|
37464
|
+
checkOrgId(ORG_ID);
|
|
37465
|
+
checkAppId(APP_ID);
|
|
37466
|
+
checkInstanceId(INSTANCE_ID);
|
|
37467
|
+
return powerSyncClient().testConnection({
|
|
37468
|
+
app_id: APP_ID,
|
|
37469
|
+
connection,
|
|
37470
|
+
id: INSTANCE_ID,
|
|
37471
|
+
org_id: ORG_ID
|
|
37472
|
+
});
|
|
37473
|
+
};
|
|
37474
|
+
const deployInstance = async (config, instanceId) => {
|
|
37475
|
+
checkOrgId(ORG_ID);
|
|
37476
|
+
checkAppId(APP_ID);
|
|
37477
|
+
return powerSyncClient().deployInstance({
|
|
37478
|
+
app_id: APP_ID,
|
|
37479
|
+
config,
|
|
37480
|
+
id: instanceId,
|
|
37481
|
+
org_id: ORG_ID
|
|
37482
|
+
});
|
|
37483
|
+
};
|
|
37428
37484
|
const validateSyncRules = async (syncRules) => {
|
|
37485
|
+
checkOrgId(ORG_ID);
|
|
37486
|
+
checkAppId(APP_ID);
|
|
37487
|
+
checkInstanceId(INSTANCE_ID);
|
|
37429
37488
|
return powerSyncClient().validateSyncRules({
|
|
37430
37489
|
app_id: APP_ID,
|
|
37431
37490
|
id: INSTANCE_ID,
|
|
@@ -37434,6 +37493,9 @@ const validateSyncRules = async (syncRules) => {
|
|
|
37434
37493
|
});
|
|
37435
37494
|
};
|
|
37436
37495
|
const deploySyncRules = async (syncRules) => {
|
|
37496
|
+
checkOrgId(ORG_ID);
|
|
37497
|
+
checkAppId(APP_ID);
|
|
37498
|
+
checkInstanceId(INSTANCE_ID);
|
|
37437
37499
|
const config = await getInstanceConfig();
|
|
37438
37500
|
if (!config.config) {
|
|
37439
37501
|
throw new Error("No instance config found");
|
|
@@ -37449,11 +37511,16 @@ const deploySyncRules = async (syncRules) => {
|
|
|
37449
37511
|
sync_rules: syncRules
|
|
37450
37512
|
});
|
|
37451
37513
|
};
|
|
37452
|
-
const processSyncRules = async () =>
|
|
37453
|
-
|
|
37454
|
-
|
|
37455
|
-
|
|
37456
|
-
|
|
37514
|
+
const processSyncRules = async () => {
|
|
37515
|
+
checkOrgId(ORG_ID);
|
|
37516
|
+
checkAppId(APP_ID);
|
|
37517
|
+
checkInstanceId(INSTANCE_ID);
|
|
37518
|
+
powerSyncClient().reprocessSyncRules({
|
|
37519
|
+
app_id: APP_ID,
|
|
37520
|
+
id: INSTANCE_ID,
|
|
37521
|
+
org_id: ORG_ID
|
|
37522
|
+
});
|
|
37523
|
+
};
|
|
37457
37524
|
const waitForStatusChange = async (instanceId) => {
|
|
37458
37525
|
const interval = 5e3;
|
|
37459
37526
|
try {
|
package/dist/service/utils.js
CHANGED
|
@@ -3,5 +3,17 @@ const generateHeader = (bearerToken) => ({
|
|
|
3
3
|
Authorization: `Bearer ${bearerToken}`,
|
|
4
4
|
ContentType: "application/json"
|
|
5
5
|
});
|
|
6
|
+
const checkAppId = (appId) => {
|
|
7
|
+
if (!appId)
|
|
8
|
+
throw new Error("No app id found");
|
|
9
|
+
};
|
|
10
|
+
const checkOrgId = (orgId) => {
|
|
11
|
+
if (!orgId)
|
|
12
|
+
throw new Error("No org id found");
|
|
13
|
+
};
|
|
14
|
+
const checkInstanceId = (instanceId) => {
|
|
15
|
+
if (!instanceId)
|
|
16
|
+
throw new Error("No instance id found");
|
|
17
|
+
};
|
|
6
18
|
|
|
7
|
-
export { generateHeader };
|
|
19
|
+
export { checkAppId, checkInstanceId, checkOrgId, generateHeader };
|
package/dist/utils.js
CHANGED
|
@@ -3,10 +3,12 @@ import fs from 'node:fs';
|
|
|
3
3
|
import { ENV_FILE_PATH } from './constants.js';
|
|
4
4
|
import { ENV_VARIABLES } from './service/powersync.client.js';
|
|
5
5
|
export const checkForValidEnvFile = (cliName, requiresInstanceId = false) => {
|
|
6
|
-
|
|
6
|
+
const { APP_ID, AUTH_TOKEN, INSTANCE_ID, ORG_ID } = process.env;
|
|
7
|
+
const allEnvVariablesSet = APP_ID && AUTH_TOKEN && ORG_ID && (INSTANCE_ID || !requiresInstanceId);
|
|
8
|
+
if (!allEnvVariablesSet && !fs.existsSync(ENV_FILE_PATH)) {
|
|
7
9
|
ux.error(`CLI has not been initialized. Please run ${green(`"${cliName} init"`)}.`, { exit: 1 });
|
|
8
10
|
}
|
|
9
|
-
const requiredProperties = [ENV_VARIABLES.APP_ID, ENV_VARIABLES.
|
|
11
|
+
const requiredProperties = [ENV_VARIABLES.APP_ID, ENV_VARIABLES.AUTH_TOKEN, ENV_VARIABLES.ORG_ID];
|
|
10
12
|
const missingProperties = requiredProperties.filter((prop) => !process.env[prop]);
|
|
11
13
|
if (missingProperties.length > 0) {
|
|
12
14
|
return ux.error(`It appears you have not initialized the CLI. Please run ${green(`"${cliName} init"`)}.`, {
|
|
@@ -14,16 +16,18 @@ export const checkForValidEnvFile = (cliName, requiresInstanceId = false) => {
|
|
|
14
16
|
});
|
|
15
17
|
}
|
|
16
18
|
if (requiresInstanceId && !process.env[ENV_VARIABLES.INSTANCE_ID]) {
|
|
17
|
-
return ux.error(`
|
|
19
|
+
return ux.error(`This command requires a configured instance. Please set one by running ${green('"powersync instance set"')}.`, {
|
|
18
20
|
exit: 1
|
|
19
21
|
});
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
export const updateEnvFileVariableValue = (variableName, newValue) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
if (!fs.existsSync(ENV_FILE_PATH)) {
|
|
26
|
+
// We assume they are either using flags or exporting the variables themselves
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
25
29
|
try {
|
|
26
|
-
const data = fs.readFileSync(
|
|
30
|
+
const data = fs.readFileSync(ENV_FILE_PATH, 'utf8');
|
|
27
31
|
const lines = data.split('\n');
|
|
28
32
|
let variableFound = false;
|
|
29
33
|
// Find and update the desired variable
|
|
@@ -40,10 +44,10 @@ export const updateEnvFileVariableValue = (variableName, newValue) => {
|
|
|
40
44
|
lines.push(variableName + '=' + newValue);
|
|
41
45
|
}
|
|
42
46
|
const updatedContent = lines.join('\n');
|
|
43
|
-
fs.writeFileSync(
|
|
47
|
+
fs.writeFileSync(ENV_FILE_PATH, updatedContent, 'utf8');
|
|
44
48
|
}
|
|
45
49
|
catch (error) {
|
|
46
|
-
|
|
50
|
+
throw new Error('Error updating environment file: ' + error);
|
|
47
51
|
}
|
|
48
52
|
};
|
|
49
53
|
export const bold = (text) => ux.colorize('bold', text);
|