neonctl 1.19.1 → 1.20.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.
@@ -1,5 +1,6 @@
1
1
  import { EndpointType } from '@neondatabase/api-client';
2
2
  import { branchIdFromProps, fillSingleProject } from '../utils/enrichers.js';
3
+ import { writer } from '../writer.js';
3
4
  export const command = 'connection-string [branch]';
4
5
  export const aliases = ['cs'];
5
6
  export const describe = 'Get connection string';
@@ -38,6 +39,11 @@ export const builder = (argv) => {
38
39
  choices: Object.values(EndpointType),
39
40
  describe: 'Endpoint type',
40
41
  },
42
+ extended: {
43
+ type: 'boolean',
44
+ describe: 'Show extended information',
45
+ default: false,
46
+ },
41
47
  })
42
48
  .middleware(fillSingleProject);
43
49
  };
@@ -81,14 +87,14 @@ export const handler = async (props) => {
81
87
  .map((d) => d.name)
82
88
  .join(', ')}`);
83
89
  }));
84
- const { data: password } = await props.apiClient.getProjectBranchRolePassword(props.projectId, endpoint.branch_id, role);
90
+ const { data: { password }, } = await props.apiClient.getProjectBranchRolePassword(props.projectId, endpoint.branch_id, role);
85
91
  const host = props.pooled
86
92
  ? endpoint.host.replace(endpoint.id, `${endpoint.id}-pooler`)
87
93
  : endpoint.host;
88
94
  const connectionString = new URL(`postgres://${host}`);
89
95
  connectionString.pathname = database;
90
96
  connectionString.username = role;
91
- connectionString.password = password.password;
97
+ connectionString.password = password;
92
98
  if (props.prisma) {
93
99
  connectionString.searchParams.set('connect_timeout', '30');
94
100
  if (props.pooled) {
@@ -96,5 +102,17 @@ export const handler = async (props) => {
96
102
  connectionString.searchParams.set('pgbouncer', 'true');
97
103
  }
98
104
  }
99
- process.stdout.write(connectionString.toString() + '\n');
105
+ if (props.extended) {
106
+ writer(props).end({
107
+ connection_string: connectionString.toString(),
108
+ host,
109
+ role,
110
+ password,
111
+ database,
112
+ options: connectionString.searchParams.toString(),
113
+ }, { fields: ['host', 'role', 'password', 'database'] });
114
+ }
115
+ else {
116
+ process.stdout.write(connectionString.toString() + '\n');
117
+ }
100
118
  };
@@ -34,7 +34,7 @@ describe('connection_string', () => {
34
34
  },
35
35
  });
36
36
  testCliCommand({
37
- name: 'connection_string branch id',
37
+ name: 'connection_string branch id 8 digits',
38
38
  args: [
39
39
  'connection-string',
40
40
  'br-cloudy-branch-12345678',
@@ -66,40 +66,6 @@ describe('connection_string', () => {
66
66
  snapshot: true,
67
67
  },
68
68
  });
69
- testCliCommand({
70
- name: 'connection_string pooled branch id',
71
- args: [
72
- 'connection-string',
73
- 'br-sunny-branch-123456',
74
- '--project-id',
75
- 'test',
76
- '--database-name',
77
- 'test_db',
78
- '--role-name',
79
- 'test_role',
80
- '--pooled',
81
- ],
82
- expected: {
83
- snapshot: true,
84
- },
85
- });
86
- testCliCommand({
87
- name: 'connection_string pooled branch id',
88
- args: [
89
- 'connection-string',
90
- 'br-cloudy-branch-12345678',
91
- '--project-id',
92
- 'test',
93
- '--database-name',
94
- 'test_db',
95
- '--role-name',
96
- 'test_role',
97
- '--pooled',
98
- ],
99
- expected: {
100
- snapshot: true,
101
- },
102
- });
103
69
  testCliCommand({
104
70
  name: 'connection_string prisma',
105
71
  args: [
@@ -117,40 +83,6 @@ describe('connection_string', () => {
117
83
  snapshot: true,
118
84
  },
119
85
  });
120
- testCliCommand({
121
- name: 'connection_string pooled branch id',
122
- args: [
123
- 'connection-string',
124
- 'br-sunny-branch-123456',
125
- '--project-id',
126
- 'test',
127
- '--database-name',
128
- 'test_db',
129
- '--role-name',
130
- 'test_role',
131
- '--pooled',
132
- ],
133
- expected: {
134
- snapshot: true,
135
- },
136
- });
137
- testCliCommand({
138
- name: 'connection_string pooled branch id',
139
- args: [
140
- 'connection-string',
141
- 'br-cloudy-branch-12345678',
142
- '--project-id',
143
- 'test',
144
- '--database-name',
145
- 'test_db',
146
- '--role-name',
147
- 'test_role',
148
- '--pooled',
149
- ],
150
- expected: {
151
- snapshot: true,
152
- },
153
- });
154
86
  testCliCommand({
155
87
  name: 'connection_string prisma pooled',
156
88
  args: [
@@ -170,28 +102,10 @@ describe('connection_string', () => {
170
102
  },
171
103
  });
172
104
  testCliCommand({
173
- name: 'connection_string prisma pooled branch id',
105
+ name: 'connection_string prisma pooled extended',
174
106
  args: [
175
107
  'connection-string',
176
- 'br-sunny-branch-123456',
177
- '--project-id',
178
- 'test',
179
- '--database-name',
180
- 'test_db',
181
- '--role-name',
182
- 'test_role',
183
- '--prisma',
184
- '--pooled',
185
- ],
186
- expected: {
187
- snapshot: true,
188
- },
189
- });
190
- testCliCommand({
191
- name: 'connection_string prisma pooled branch id',
192
- args: [
193
- 'connection-string',
194
- 'br-cloudy-branch-12345678',
108
+ 'test_branch',
195
109
  '--project-id',
196
110
  'test',
197
111
  '--database-name',
@@ -200,6 +114,7 @@ describe('connection_string', () => {
200
114
  'test_role',
201
115
  '--prisma',
202
116
  '--pooled',
117
+ '--extended',
203
118
  ],
204
119
  expected: {
205
120
  snapshot: true,
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "git@github.com:neondatabase/neonctl.git"
6
6
  },
7
7
  "type": "module",
8
- "version": "1.19.1",
8
+ "version": "1.20.0",
9
9
  "description": "CLI tool for NeonDB Cloud management",
10
10
  "main": "index.js",
11
11
  "author": "NeonDB",