neonctl 2.37.1 → 2.38.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 (159) hide show
  1. package/README.md +15 -700
  2. package/bin/cli.js +3 -0
  3. package/package.json +8 -75
  4. package/dist/analytics.js +0 -168
  5. package/dist/api.js +0 -720
  6. package/dist/auth.js +0 -125
  7. package/dist/callback.html +0 -60
  8. package/dist/cli.js +0 -9
  9. package/dist/commands/api.js +0 -278
  10. package/dist/commands/auth.js +0 -214
  11. package/dist/commands/bootstrap.js +0 -481
  12. package/dist/commands/branches.js +0 -488
  13. package/dist/commands/bucket.js +0 -549
  14. package/dist/commands/checkout.js +0 -321
  15. package/dist/commands/config.js +0 -626
  16. package/dist/commands/connection_string.js +0 -172
  17. package/dist/commands/data_api.js +0 -284
  18. package/dist/commands/databases.js +0 -82
  19. package/dist/commands/deploy.js +0 -26
  20. package/dist/commands/dev.js +0 -698
  21. package/dist/commands/diff.js +0 -222
  22. package/dist/commands/env.js +0 -189
  23. package/dist/commands/functions.js +0 -373
  24. package/dist/commands/index.js +0 -62
  25. package/dist/commands/init.js +0 -73
  26. package/dist/commands/inspect.js +0 -65
  27. package/dist/commands/ip_allow.js +0 -137
  28. package/dist/commands/link.js +0 -1121
  29. package/dist/commands/neon_auth.js +0 -1028
  30. package/dist/commands/operations.js +0 -28
  31. package/dist/commands/orgs.js +0 -24
  32. package/dist/commands/projects.js +0 -413
  33. package/dist/commands/psql.js +0 -62
  34. package/dist/commands/roles.js +0 -65
  35. package/dist/commands/schema_diff.js +0 -151
  36. package/dist/commands/set_context.js +0 -29
  37. package/dist/commands/snapshots.js +0 -455
  38. package/dist/commands/status.js +0 -40
  39. package/dist/commands/user.js +0 -15
  40. package/dist/commands/vpc_endpoints.js +0 -134
  41. package/dist/config.js +0 -11
  42. package/dist/config_format.js +0 -72
  43. package/dist/context.js +0 -231
  44. package/dist/current_branch_fast_path.js +0 -55
  45. package/dist/dev/env.js +0 -244
  46. package/dist/dev/functions.js +0 -70
  47. package/dist/dev/inputs.js +0 -63
  48. package/dist/dev/runtime.js +0 -146
  49. package/dist/env.js +0 -36
  50. package/dist/env_file.js +0 -159
  51. package/dist/errors.js +0 -80
  52. package/dist/functions_api.js +0 -48
  53. package/dist/help.js +0 -146
  54. package/dist/index.js +0 -240
  55. package/dist/log.js +0 -18
  56. package/dist/parameters.gen.js +0 -480
  57. package/dist/pkg.js +0 -25
  58. package/dist/psql/cli.js +0 -53
  59. package/dist/psql/command/cmd_cond.js +0 -437
  60. package/dist/psql/command/cmd_connect.js +0 -820
  61. package/dist/psql/command/cmd_copy.js +0 -1035
  62. package/dist/psql/command/cmd_describe.js +0 -1815
  63. package/dist/psql/command/cmd_format.js +0 -948
  64. package/dist/psql/command/cmd_io.js +0 -2193
  65. package/dist/psql/command/cmd_lo.js +0 -393
  66. package/dist/psql/command/cmd_meta.js +0 -969
  67. package/dist/psql/command/cmd_misc.js +0 -187
  68. package/dist/psql/command/cmd_pipeline.js +0 -1148
  69. package/dist/psql/command/cmd_restrict.js +0 -171
  70. package/dist/psql/command/cmd_show.js +0 -766
  71. package/dist/psql/command/dispatch.js +0 -343
  72. package/dist/psql/command/inputQueue.js +0 -42
  73. package/dist/psql/command/shared.js +0 -71
  74. package/dist/psql/complete/filenames.js +0 -139
  75. package/dist/psql/complete/index.js +0 -104
  76. package/dist/psql/complete/matcher.js +0 -315
  77. package/dist/psql/complete/psqlVars.js +0 -249
  78. package/dist/psql/complete/queries.js +0 -493
  79. package/dist/psql/complete/rules.js +0 -2424
  80. package/dist/psql/core/common.js +0 -1253
  81. package/dist/psql/core/help.js +0 -576
  82. package/dist/psql/core/mainloop.js +0 -1360
  83. package/dist/psql/core/prompt.js +0 -439
  84. package/dist/psql/core/settings.js +0 -686
  85. package/dist/psql/core/sqlHelp.js +0 -1066
  86. package/dist/psql/core/startup.js +0 -846
  87. package/dist/psql/core/syncVars.js +0 -116
  88. package/dist/psql/core/variables.js +0 -287
  89. package/dist/psql/describe/formatters.js +0 -1330
  90. package/dist/psql/describe/processNamePattern.js +0 -270
  91. package/dist/psql/describe/queries.js +0 -2452
  92. package/dist/psql/describe/versionGate.js +0 -44
  93. package/dist/psql/index.js +0 -2030
  94. package/dist/psql/io/history.js +0 -299
  95. package/dist/psql/io/input.js +0 -120
  96. package/dist/psql/io/lineEditor/buffer.js +0 -325
  97. package/dist/psql/io/lineEditor/complete.js +0 -227
  98. package/dist/psql/io/lineEditor/filename.js +0 -159
  99. package/dist/psql/io/lineEditor/index.js +0 -893
  100. package/dist/psql/io/lineEditor/keymap.js +0 -745
  101. package/dist/psql/io/lineEditor/vt100.js +0 -363
  102. package/dist/psql/io/pgpass.js +0 -202
  103. package/dist/psql/io/pgservice.js +0 -194
  104. package/dist/psql/io/psqlrc.js +0 -422
  105. package/dist/psql/print/aligned.js +0 -1748
  106. package/dist/psql/print/asciidoc.js +0 -230
  107. package/dist/psql/print/crosstab.js +0 -463
  108. package/dist/psql/print/csv.js +0 -76
  109. package/dist/psql/print/html.js +0 -240
  110. package/dist/psql/print/json.js +0 -96
  111. package/dist/psql/print/latex.js +0 -379
  112. package/dist/psql/print/pager.js +0 -267
  113. package/dist/psql/print/troff.js +0 -240
  114. package/dist/psql/print/unaligned.js +0 -99
  115. package/dist/psql/print/units.js +0 -188
  116. package/dist/psql/scanner/slash.js +0 -515
  117. package/dist/psql/scanner/sql.js +0 -914
  118. package/dist/psql/scanner/stringutils.js +0 -394
  119. package/dist/psql/types/backslash.js +0 -1
  120. package/dist/psql/types/connection.js +0 -1
  121. package/dist/psql/types/index.js +0 -7
  122. package/dist/psql/types/printer.js +0 -1
  123. package/dist/psql/types/repl.js +0 -1
  124. package/dist/psql/types/scanner.js +0 -24
  125. package/dist/psql/types/settings.js +0 -1
  126. package/dist/psql/types/variables.js +0 -1
  127. package/dist/psql/wire/connection.js +0 -2857
  128. package/dist/psql/wire/copy.js +0 -108
  129. package/dist/psql/wire/notify.js +0 -59
  130. package/dist/psql/wire/pipeline.js +0 -521
  131. package/dist/psql/wire/protocol.js +0 -466
  132. package/dist/psql/wire/sasl.js +0 -294
  133. package/dist/psql/wire/tls.js +0 -602
  134. package/dist/storage_api.js +0 -147
  135. package/dist/test_utils/fixtures.js +0 -121
  136. package/dist/test_utils/oauth_server.js +0 -9
  137. package/dist/types.js +0 -1
  138. package/dist/utils/ai_gateway_notice.js +0 -180
  139. package/dist/utils/api_enums.js +0 -33
  140. package/dist/utils/auth.js +0 -5
  141. package/dist/utils/branch_notice.js +0 -22
  142. package/dist/utils/branch_picker.js +0 -103
  143. package/dist/utils/compute_units.js +0 -28
  144. package/dist/utils/config_diff.js +0 -185
  145. package/dist/utils/enrichers.js +0 -161
  146. package/dist/utils/esbuild.js +0 -158
  147. package/dist/utils/formats.js +0 -18
  148. package/dist/utils/git_diff.js +0 -90
  149. package/dist/utils/inspect_db.js +0 -153
  150. package/dist/utils/inspect_queries.js +0 -372
  151. package/dist/utils/middlewares.js +0 -20
  152. package/dist/utils/openapi.js +0 -114
  153. package/dist/utils/package_manager.js +0 -68
  154. package/dist/utils/point_in_time.js +0 -56
  155. package/dist/utils/psql.js +0 -120
  156. package/dist/utils/string.js +0 -5
  157. package/dist/utils/ui.js +0 -59
  158. package/dist/utils/zip.js +0 -4
  159. package/dist/writer.js +0 -97
@@ -1,28 +0,0 @@
1
- import { fillSingleProject } from "../utils/enrichers.js";
2
- import { writer } from "../writer.js";
3
- const OPERATIONS_FIELDS = ["id", "action", "status", "created_at"];
4
- export const command = "operations";
5
- export const describe = "Manage operations";
6
- export const aliases = ["operation"];
7
- export const builder = (argv) => argv
8
- .usage("$0 operations <sub-command> [options]")
9
- .options({
10
- "project-id": {
11
- describe: "Project ID",
12
- type: "string",
13
- },
14
- })
15
- .middleware(fillSingleProject)
16
- .command("list", "List operations", (yargs) => yargs, (args) => list(args));
17
- export const handler = (args) => {
18
- return args;
19
- };
20
- export const list = async (props) => {
21
- const { data } = await props.apiClient.listProjectOperations({
22
- projectId: props.projectId,
23
- limit: props.limit,
24
- });
25
- writer(props).end(data.operations, {
26
- fields: OPERATIONS_FIELDS,
27
- });
28
- };
@@ -1,24 +0,0 @@
1
- import { writer } from "../writer.js";
2
- const ORG_FIELDS = ["id", "name"];
3
- export const command = "orgs";
4
- export const describe = "Manage organizations";
5
- export const aliases = ["org"];
6
- export const builder = (argv) => {
7
- return argv.usage("$0 orgs <sub-command> [options]").command("list", "List organizations", (yargs) => yargs, async (args) => {
8
- // @ts-expect-error: TODO - Assert `args` is `CommonProps`
9
- await list(args);
10
- });
11
- };
12
- export const handler = (args) => {
13
- return args;
14
- };
15
- const list = async (props) => {
16
- const out = writer(props);
17
- const { data: { organizations }, } = await props.apiClient.getCurrentUserOrganizations();
18
- out.write(organizations, {
19
- fields: ORG_FIELDS,
20
- title: "Organizations",
21
- emptyMessage: "You are not a member of any organization.",
22
- });
23
- out.end();
24
- };
@@ -1,413 +0,0 @@
1
- import prompts from "prompts";
2
- import { isNeonApiError, messageFromBody } from "../api.js";
3
- import { updateContextFile } from "../context.js";
4
- import { isCi } from "../env.js";
5
- import { log } from "../log.js";
6
- import { projectCreateRequest, projectUpdateRequest, } from "../parameters.gen.js";
7
- import { getComputeUnits } from "../utils/compute_units.js";
8
- import { psql } from "../utils/psql.js";
9
- import { writer } from "../writer.js";
10
- export const PROJECT_FIELDS = [
11
- "id",
12
- "name",
13
- "region_id",
14
- "created_at",
15
- ];
16
- export const REGIONS = [
17
- "aws-us-west-2",
18
- "aws-ap-southeast-1",
19
- "aws-ap-southeast-2",
20
- "aws-eu-central-1",
21
- "aws-us-east-2",
22
- "aws-us-east-1",
23
- "azure-eastus2",
24
- ];
25
- const PROJECTS_LIST_LIMIT = 100;
26
- export const command = "projects";
27
- export const describe = "Manage projects";
28
- export const aliases = ["project"];
29
- export const builder = (argv) => {
30
- return argv
31
- .usage("$0 projects <sub-command> [options]")
32
- .middleware((args) => {
33
- // Provide alias for analytics
34
- args.projectId = args.id;
35
- })
36
- .command("list", "List projects", (yargs) => yargs.options({
37
- "org-id": {
38
- describe: "List projects of a given organization",
39
- type: "string",
40
- },
41
- "recoverable-only": {
42
- describe: "List only deleted projects within their deletion grace period",
43
- type: "boolean",
44
- },
45
- }), async (args) => {
46
- await handleMissingOrgId(args, list);
47
- })
48
- .command("create", "Create a project", (yargs) => yargs.options({
49
- "block-public-connections": {
50
- describe: projectCreateRequest["project.settings.block_public_connections"].description,
51
- type: "boolean",
52
- },
53
- "block-vpc-connections": {
54
- describe: projectCreateRequest["project.settings.block_vpc_connections"].description,
55
- type: "boolean",
56
- },
57
- hipaa: {
58
- describe: projectCreateRequest["project.settings.hipaa"]
59
- .description,
60
- type: "boolean",
61
- },
62
- name: {
63
- describe: projectCreateRequest["project.name"].description,
64
- type: "string",
65
- },
66
- "region-id": {
67
- describe: `The region ID. Possible values: ${REGIONS.join(", ")}`,
68
- type: "string",
69
- },
70
- "org-id": {
71
- describe: "The project's organization ID",
72
- type: "string",
73
- },
74
- psql: {
75
- type: "boolean",
76
- describe: "Connect to a new project via psql",
77
- default: false,
78
- },
79
- fallback: {
80
- type: "boolean",
81
- describe: "Force the embedded TypeScript psql fallback (for testing)",
82
- default: false,
83
- hidden: true,
84
- },
85
- database: {
86
- describe: projectCreateRequest["project.branch.database_name"]
87
- .description,
88
- type: "string",
89
- },
90
- role: {
91
- describe: projectCreateRequest["project.branch.role_name"]
92
- .description,
93
- type: "string",
94
- },
95
- "pg-version": {
96
- describe: "Major PostgreSQL version (14–19). Version 19 is available only in regions where it has been enabled.",
97
- type: "number",
98
- choices: [14, 15, 16, 17, 18, 19],
99
- },
100
- "set-context": {
101
- type: "boolean",
102
- describe: "Set the current context to the new project",
103
- default: false,
104
- },
105
- cu: {
106
- describe: 'The number of Compute Units. Could be a fixed size (e.g. "2") or a range delimited by a dash (e.g. "0.5-3").',
107
- type: "string",
108
- },
109
- }), async (args) => {
110
- await handleMissingOrgId(args, create);
111
- })
112
- .command("update <id>", "Update a project", (yargs) => yargs.options({
113
- "block-vpc-connections": {
114
- describe: projectUpdateRequest["project.settings.block_vpc_connections"].description +
115
- " Use --block-vpc-connections=false to set the value to false.",
116
- type: "boolean",
117
- },
118
- "block-public-connections": {
119
- describe: projectUpdateRequest["project.settings.block_public_connections"].description +
120
- " Use --block-public-connections=false to set the value to false.",
121
- type: "boolean",
122
- },
123
- hipaa: {
124
- describe: projectUpdateRequest["project.settings.hipaa"]
125
- .description,
126
- type: "boolean",
127
- },
128
- cu: {
129
- describe: 'The number of Compute Units. Could be a fixed size (e.g. "2") or a range delimited by a dash (e.g. "0.5-3").',
130
- type: "string",
131
- },
132
- name: {
133
- describe: projectUpdateRequest["project.name"].description,
134
- type: "string",
135
- },
136
- "enable-logical-replication": {
137
- describe: "Enable logical replication for all project endpoints. This suspends active endpoints and cannot be disabled.",
138
- type: "boolean",
139
- },
140
- yes: {
141
- type: "boolean",
142
- default: false,
143
- describe: "Skip the confirmation prompt when enabling logical replication.",
144
- },
145
- }), async (args) => {
146
- await update(args);
147
- })
148
- .command("delete <id>", "Delete a project", (yargs) => yargs, async (args) => {
149
- await deleteProject(args);
150
- })
151
- .command("recover <id>", "Recovers a deleted project during the deletion grace period", (yargs) => yargs, async (args) => {
152
- await recover(args);
153
- })
154
- .command("get <id>", "Get a project", (yargs) => yargs, async (args) => {
155
- await get(args);
156
- });
157
- };
158
- export const handler = (args) => {
159
- return args;
160
- };
161
- const list = async (props) => {
162
- const getList = async (fn) => {
163
- const result = [];
164
- let cursor;
165
- let end = false;
166
- while (!end) {
167
- const { data } = await fn({
168
- limit: PROJECTS_LIST_LIMIT,
169
- org_id: props.orgId,
170
- recoverable: props.recoverableOnly,
171
- cursor,
172
- });
173
- result.push(...data.projects);
174
- cursor = data.pagination?.cursor;
175
- log.debug("Got %d projects, with cursor: %s", data.projects.length, cursor);
176
- if (data.projects.length < PROJECTS_LIST_LIMIT) {
177
- end = true;
178
- }
179
- }
180
- return result;
181
- };
182
- const ownedProjects = await getList(props.apiClient.listProjects);
183
- const sharedProjects = props.orgId || props.recoverableOnly
184
- ? []
185
- : await getList(props.apiClient.listSharedProjects);
186
- const out = writer(props);
187
- out.write(ownedProjects, {
188
- fields: props.recoverableOnly
189
- ? [...PROJECT_FIELDS, "deleted_at", "recoverable_until"]
190
- : PROJECT_FIELDS,
191
- title: "Projects",
192
- emptyMessage: props.recoverableOnly
193
- ? "You don't have any recoverable projects."
194
- : "You don't have any projects yet. See how to create a new project:\n> neon projects create --help",
195
- });
196
- if (!props.orgId && !props.recoverableOnly) {
197
- // We don't list shared projects when listing recoverable projects
198
- out.write(sharedProjects, {
199
- fields: PROJECT_FIELDS,
200
- title: "Shared with you",
201
- emptyMessage: "No projects have been shared with you",
202
- });
203
- }
204
- out.end();
205
- };
206
- const create = async (props) => {
207
- const project = {};
208
- if (props.hipaa !== undefined) {
209
- if (!project.settings) {
210
- project.settings = {};
211
- }
212
- project.settings.hipaa = props.hipaa;
213
- }
214
- if (props.blockPublicConnections !== undefined) {
215
- if (!project.settings) {
216
- project.settings = {};
217
- }
218
- project.settings.block_public_connections =
219
- props.blockPublicConnections;
220
- }
221
- if (props.blockVpcConnections !== undefined) {
222
- if (!project.settings) {
223
- project.settings = {};
224
- }
225
- project.settings.block_vpc_connections = props.blockVpcConnections;
226
- }
227
- if (props.name) {
228
- project.name = props.name;
229
- }
230
- if (props.regionId) {
231
- project.region_id = props.regionId;
232
- }
233
- if (props.orgId) {
234
- project.org_id = props.orgId;
235
- }
236
- project.branch = {};
237
- if (props.database) {
238
- project.branch.database_name = props.database;
239
- }
240
- if (props.role) {
241
- project.branch.role_name = props.role;
242
- }
243
- if (props.pgVersion !== undefined) {
244
- project.pg_version = props.pgVersion;
245
- }
246
- if (props.cu) {
247
- project.default_endpoint_settings = props.cu
248
- ? getComputeUnits(props.cu)
249
- : undefined;
250
- }
251
- const { data } = await props.apiClient.createProject({
252
- project,
253
- });
254
- if (props.setContext) {
255
- updateContextFile(props.contextFile, {
256
- projectId: data.project.id,
257
- });
258
- }
259
- const out = writer(props);
260
- out.write(data.project, { fields: PROJECT_FIELDS, title: "Project" });
261
- out.write(data.connection_uris, {
262
- fields: ["connection_uri"],
263
- title: "Connection URIs",
264
- });
265
- out.end();
266
- if (props.psql) {
267
- const connection_uri = data.connection_uris[0].connection_uri;
268
- const psqlArgs = props["--"];
269
- await psql(connection_uri, psqlArgs, {
270
- mode: props.fallback ? "ts" : "auto",
271
- });
272
- }
273
- };
274
- const deleteProject = async (props) => {
275
- const { data } = await props.apiClient.deleteProject(props.id);
276
- writer(props).end(data.project, {
277
- fields: PROJECT_FIELDS,
278
- });
279
- };
280
- const update = async (props) => {
281
- const project = {};
282
- if (props.enableLogicalReplication !== undefined) {
283
- if (!props.enableLogicalReplication) {
284
- throw new Error("Logical replication cannot be disabled once it has been enabled.");
285
- }
286
- if (!props.yes) {
287
- if (isCi() || !process.stdin.isTTY) {
288
- throw new Error("Enabling logical replication requires confirmation. Re-run interactively or pass --yes.");
289
- }
290
- const { proceed } = await prompts({
291
- onState: onPromptState,
292
- type: "confirm",
293
- name: "proceed",
294
- message: "Enable logical replication? This suspends active endpoints and cannot be undone.",
295
- initial: false,
296
- });
297
- if (!proceed) {
298
- log.info("Logical replication was not enabled.");
299
- return;
300
- }
301
- }
302
- project.settings = {
303
- enable_logical_replication: true,
304
- };
305
- }
306
- if (props.hipaa !== undefined) {
307
- if (!project.settings) {
308
- project.settings = {};
309
- }
310
- project.settings.hipaa = props.hipaa;
311
- }
312
- if (props.blockPublicConnections !== undefined) {
313
- if (!project.settings) {
314
- project.settings = {};
315
- }
316
- project.settings.block_public_connections =
317
- props.blockPublicConnections;
318
- }
319
- if (props.blockVpcConnections !== undefined) {
320
- if (!project.settings) {
321
- project.settings = {};
322
- }
323
- project.settings.block_vpc_connections = props.blockVpcConnections;
324
- }
325
- if (props.name) {
326
- project.name = props.name;
327
- }
328
- if (props.cu) {
329
- project.default_endpoint_settings = props.cu
330
- ? getComputeUnits(props.cu)
331
- : undefined;
332
- }
333
- const { data } = await props.apiClient.updateProject(props.id, {
334
- project,
335
- });
336
- writer(props).end(data.project, { fields: PROJECT_FIELDS });
337
- };
338
- const recover = async (props) => {
339
- const { data } = await props.apiClient.recoverProject(props.id);
340
- writer(props).end(data.project, { fields: PROJECT_FIELDS });
341
- };
342
- const get = async (props) => {
343
- const { data } = await props.apiClient.getProject(props.id);
344
- writer(props).end(data.project, { fields: PROJECT_FIELDS });
345
- };
346
- const handleMissingOrgId = async (args, cmd) => {
347
- try {
348
- await cmd(args);
349
- }
350
- catch (err) {
351
- if (!isCi() && isOrgIdError(err)) {
352
- const orgId = await selectOrg(args);
353
- await cmd({ ...args, orgId });
354
- }
355
- else {
356
- throw err;
357
- }
358
- }
359
- };
360
- const isOrgIdError = (err) => {
361
- return (isNeonApiError(err) &&
362
- err.status === 400 &&
363
- messageFromBody(err.data)?.includes("org_id is required"));
364
- };
365
- const selectOrg = async (props) => {
366
- const { data: { organizations }, } = await props.apiClient.getCurrentUserOrganizations();
367
- if (!organizations?.length) {
368
- throw new Error(`You don't belong to any organizations. Please create an organization first.`);
369
- }
370
- const { orgId } = await prompts({
371
- onState: onPromptState,
372
- type: "select",
373
- name: "orgId",
374
- message: `What organization would you like to use?`,
375
- choices: organizations.map((org) => ({
376
- title: `${org.name} (${org.id})`,
377
- value: org.id,
378
- })),
379
- initial: 0,
380
- });
381
- const { save } = await prompts({
382
- onState: onPromptState,
383
- type: "confirm",
384
- name: "save",
385
- message: `Would you like to use this organization by default?`,
386
- initial: true,
387
- });
388
- if (save) {
389
- updateContextFile(props.contextFile, { orgId });
390
- writer(props).text(`
391
- The organization ID has been saved in ${props.contextFile}
392
-
393
- If you'd like to change the default organization later, use
394
-
395
- neonctl link --org-id <org_id>
396
-
397
- Or to clear the context file and forget the default organization
398
-
399
- neonctl link --clear
400
-
401
- `);
402
- }
403
- return orgId;
404
- };
405
- const onPromptState = (state) => {
406
- if (state.aborted) {
407
- // If we don't re-enable the terminal cursor before exiting
408
- // the program, the cursor will remain hidden
409
- process.stdout.write("\x1B[?25h");
410
- process.stdout.write("\n");
411
- process.exit(1);
412
- }
413
- };
@@ -1,62 +0,0 @@
1
- import { EndpointType } from "../utils/api_enums.js";
2
- import { fillSingleProject } from "../utils/enrichers.js";
3
- import { handler as connectionStringHandler, SSL_MODES, } from "./connection_string.js";
4
- export const command = "psql [branch]";
5
- export const describe = "Connect to a database via psql";
6
- export const builder = (argv) => {
7
- return argv
8
- .usage("$0 psql [branch] [options] [-- psql-args]")
9
- .example("$0 psql", "Connect to the default branch via psql")
10
- .example("$0 psql main", "Connect to the main branch via psql")
11
- .example('$0 psql main -- -c "SELECT 1"', "Run a single query against the main branch")
12
- .example("$0 psql main@2024-01-01T00:00:00Z", "Connect to the main branch at a specific point in time")
13
- .positional("branch", {
14
- describe: `Branch name or id. Defaults to the default branch if omitted. Can be written in the point-in-time format: "branch@timestamp" or "branch@lsn"`,
15
- type: "string",
16
- })
17
- .options({
18
- "project-id": {
19
- type: "string",
20
- describe: "Project ID",
21
- },
22
- "role-name": {
23
- type: "string",
24
- describe: "Role name",
25
- },
26
- "database-name": {
27
- type: "string",
28
- describe: "Database name",
29
- },
30
- pooled: {
31
- type: "boolean",
32
- describe: "Use pooled connection",
33
- default: false,
34
- },
35
- "endpoint-type": {
36
- type: "string",
37
- choices: Object.values(EndpointType),
38
- describe: "Endpoint type",
39
- },
40
- ssl: {
41
- type: "string",
42
- choices: SSL_MODES,
43
- default: "require",
44
- describe: "SSL mode",
45
- },
46
- fallback: {
47
- type: "boolean",
48
- describe: "Force the embedded TypeScript psql fallback (for testing)",
49
- default: false,
50
- hidden: true,
51
- },
52
- })
53
- .middleware(fillSingleProject);
54
- };
55
- export const handler = async (props) => {
56
- await connectionStringHandler({
57
- ...props,
58
- psql: true,
59
- prisma: false,
60
- extended: false,
61
- });
62
- };
@@ -1,65 +0,0 @@
1
- import { retryOnLock } from "../api.js";
2
- import { branchIdFromProps, fillSingleProject } from "../utils/enrichers.js";
3
- import { writer } from "../writer.js";
4
- const ROLES_FIELDS = ["name", "created_at"];
5
- export const command = "roles";
6
- export const describe = "Manage roles";
7
- export const aliases = ["role"];
8
- export const builder = (argv) => argv
9
- .usage("$0 roles <sub-command> [options]")
10
- .options({
11
- "project-id": {
12
- describe: "Project ID",
13
- type: "string",
14
- },
15
- branch: {
16
- describe: "Branch ID or name",
17
- type: "string",
18
- },
19
- })
20
- .middleware(fillSingleProject)
21
- .command("list", "List roles", (yargs) => yargs, (args) => list(args))
22
- .command("create", "Create a role", (yargs) => yargs.options({
23
- name: {
24
- describe: "Role name",
25
- type: "string",
26
- demandOption: true,
27
- },
28
- "no-login": {
29
- describe: "Create a passwordless role that cannot login",
30
- boolean: true,
31
- },
32
- }), (args) => create(args))
33
- .command("delete <role>", "Delete a role", (yargs) => yargs, (args) => deleteRole(args));
34
- export const handler = (args) => {
35
- return args;
36
- };
37
- export const list = async (props) => {
38
- const branchId = await branchIdFromProps(props);
39
- const { data } = await props.apiClient.listProjectBranchRoles(props.projectId, branchId);
40
- writer(props).end(data.roles, {
41
- fields: ROLES_FIELDS,
42
- });
43
- };
44
- export const create = async (props) => {
45
- const branchId = await branchIdFromProps(props);
46
- const { data } = await retryOnLock(() => props.apiClient.createProjectBranchRole(props.projectId, branchId, {
47
- role: {
48
- name: props.name,
49
- no_login: props["no-login"],
50
- },
51
- }));
52
- writer(props).end(data.role, {
53
- fields: ROLES_FIELDS,
54
- });
55
- };
56
- export const deleteRole = async (props) => {
57
- const branchId = await branchIdFromProps(props);
58
- const { data } = await retryOnLock(() => props.apiClient.deleteProjectBranchRole(props.projectId, branchId, props.role));
59
- // A 204 (role already gone) carries no body; only a 200 returns the role.
60
- if (data) {
61
- writer(props).end(data.role, {
62
- fields: ROLES_FIELDS,
63
- });
64
- }
65
- };