Comparing version 1.16.5 to 1.17.0
@@ -36,11 +36,13 @@ import { EndpointType } from '@neondatabase/api-client'; | ||
}, | ||
endpoint: { | ||
describe: 'Create a branch with or without an endpoint. By default branch is created with a read-write endpoint. To create a branch without endpoint use --no-endpoint', | ||
compute: { | ||
describe: 'Create a branch with or without a compute. By default branch is created with a read-write compute. To create a branch without compute use --no-compute', | ||
type: 'boolean', | ||
default: true, | ||
}, | ||
readonly: { | ||
describe: 'Create a read-only branch', | ||
type: 'boolean', | ||
implies: 'endpoint', | ||
type: { | ||
describe: 'Type of compute to add', | ||
type: 'string', | ||
implies: 'compute', | ||
default: EndpointType.ReadWrite, | ||
choices: Object.values(EndpointType), | ||
}, | ||
@@ -50,2 +52,10 @@ }), async (args) => await create(args)) | ||
.command('set-primary <id|name>', 'Set a branch as primary', (yargs) => yargs, async (args) => await setPrimary(args)) | ||
.command('add-compute <id|name>', 'Add a compute to a branch', (yargs) => yargs.options({ | ||
type: { | ||
type: 'string', | ||
choices: Object.values(EndpointType), | ||
describe: 'Type of compute to add', | ||
default: EndpointType.ReadOnly, | ||
}, | ||
}), async (args) => await addCompute(args)) | ||
.command('delete <id|name>', 'Delete a branch', (yargs) => yargs, async (args) => await deleteBranch(args)) | ||
@@ -99,8 +109,6 @@ .command('get <id|name>', 'Get a branch', (yargs) => yargs, async (args) => await get(args)); | ||
}, | ||
endpoints: props.endpoint | ||
endpoints: props.compute | ||
? [ | ||
{ | ||
type: props.readonly | ||
? EndpointType.ReadOnly | ||
: EndpointType.ReadWrite, | ||
type: props.type, | ||
}, | ||
@@ -161,1 +169,13 @@ ] | ||
}; | ||
const addCompute = async (props) => { | ||
const branchId = await branchIdFromProps(props); | ||
const { data } = await retryOnLock(() => props.apiClient.createProjectEndpoint(props.projectId, { | ||
endpoint: { | ||
branch_id: branchId, | ||
type: props.type, | ||
}, | ||
})); | ||
writer(props).end(data.endpoint, { | ||
fields: ['id', 'host'], | ||
}); | ||
}; |
@@ -34,3 +34,4 @@ import { describe } from '@jest/globals'; | ||
'test_branch', | ||
'--readonly', | ||
'--type', | ||
'read_only', | ||
], | ||
@@ -50,3 +51,3 @@ expected: { | ||
'test_branch', | ||
'--no-endpoint', | ||
'--no-compute', | ||
], | ||
@@ -159,2 +160,9 @@ expected: { | ||
}); | ||
testCliCommand({ | ||
name: 'add compute', | ||
args: ['branches', 'add-compute', 'test_branch', '--project-id', 'test'], | ||
expected: { | ||
snapshot: true, | ||
}, | ||
}); | ||
}); |
@@ -66,3 +66,3 @@ import { EndpointType } from '@neondatabase/api-client'; | ||
} | ||
throw new Error(`Multiple roles found for the branch, please provide one with the --role.name option: ${data.roles | ||
throw new Error(`Multiple roles found for the branch, please provide one with the --role-name option: ${data.roles | ||
.map((r) => r.name) | ||
@@ -81,3 +81,3 @@ .join(', ')}`); | ||
} | ||
throw new Error(`Multiple databases found for the branch, please provide one with the --database.name option: ${data.databases | ||
throw new Error(`Multiple databases found for the branch, please provide one with the --database-name option: ${data.databases | ||
.map((d) => d.name) | ||
@@ -84,0 +84,0 @@ .join(', ')}`); |
@@ -8,3 +8,3 @@ { | ||
"type": "module", | ||
"version": "1.16.5", | ||
"version": "1.17.0", | ||
"description": "CLI tool for NeonDB Cloud management", | ||
@@ -11,0 +11,0 @@ "main": "index.js", |
77590
1923