neon 2.47.0 → 3.1.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 (198) hide show
  1. package/README.md +54 -0
  2. package/dist/_shared/auth_selection.js +76 -79
  3. package/dist/_shared/credentials.js +166 -187
  4. package/dist/_shared/env-core/env.js +395 -0
  5. package/dist/_shared/env-core/reuse-secrets.js +179 -0
  6. package/dist/_shared/paths.js +129 -126
  7. package/dist/_shared/profiles.js +192 -242
  8. package/dist/_shared/secure_file.js +36 -38
  9. package/dist/_virtual/_rolldown/runtime.js +13 -0
  10. package/dist/analytics.js +163 -207
  11. package/dist/api.js +815 -758
  12. package/dist/auth.js +121 -141
  13. package/dist/auth_context.js +39 -53
  14. package/dist/cli.js +4 -7
  15. package/dist/commands/api.js +220 -250
  16. package/dist/commands/api_keys.js +251 -314
  17. package/dist/commands/auth.js +283 -328
  18. package/dist/commands/bootstrap.js +372 -437
  19. package/dist/commands/branches.js +304 -455
  20. package/dist/commands/bucket.js +374 -514
  21. package/dist/commands/checkout.js +213 -298
  22. package/dist/commands/config.js +575 -658
  23. package/dist/commands/connection_string.js +137 -165
  24. package/dist/commands/data_api.js +238 -260
  25. package/dist/commands/databases.js +67 -76
  26. package/dist/commands/deploy.js +31 -25
  27. package/dist/commands/dev.js +642 -681
  28. package/dist/commands/diff.js +156 -200
  29. package/dist/commands/env.js +243 -303
  30. package/dist/commands/functions.js +275 -341
  31. package/dist/commands/index.js +70 -65
  32. package/dist/commands/init.js +84 -119
  33. package/dist/commands/inspect.js +55 -55
  34. package/dist/commands/ip_allow.js +88 -120
  35. package/dist/commands/link.js +874 -1019
  36. package/dist/commands/logs.js +291 -0
  37. package/dist/commands/neon_auth.js +725 -933
  38. package/dist/commands/operations.js +34 -25
  39. package/dist/commands/orgs.js +28 -18
  40. package/dist/commands/profile.js +614 -845
  41. package/dist/commands/projects.js +313 -373
  42. package/dist/commands/psql.js +60 -58
  43. package/dist/commands/roles.js +55 -58
  44. package/dist/commands/schema_diff.js +87 -131
  45. package/dist/commands/set_context.js +34 -26
  46. package/dist/commands/snapshots.js +288 -413
  47. package/dist/commands/status.js +41 -37
  48. package/dist/commands/user.js +21 -10
  49. package/dist/commands/vpc_endpoints.js +85 -113
  50. package/dist/config.js +7 -6
  51. package/dist/config_format.js +50 -66
  52. package/dist/config_template.js +128 -157
  53. package/dist/context.js +183 -235
  54. package/dist/current_branch_fast_path.js +40 -49
  55. package/dist/dev/env.js +313 -394
  56. package/dist/dev/functions.js +54 -64
  57. package/dist/dev/inputs.js +46 -58
  58. package/dist/dev/runtime.js +135 -164
  59. package/dist/dev/websocket.js +766 -959
  60. package/dist/env.js +27 -33
  61. package/dist/env_file.js +118 -132
  62. package/dist/env_services.js +36 -38
  63. package/dist/errors.js +57 -68
  64. package/dist/functions_api.js +45 -43
  65. package/dist/help.js +189 -140
  66. package/dist/index.js +182 -257
  67. package/dist/init/agents.js +137 -118
  68. package/dist/init/auth.js +58 -68
  69. package/dist/init/bootstrap.js +325 -396
  70. package/dist/init/build_config.js +4 -2
  71. package/dist/init/detect_agent.js +56 -101
  72. package/dist/init/editors.js +35 -52
  73. package/dist/init/enrich_output.js +51 -66
  74. package/dist/init/extension.js +134 -171
  75. package/dist/init/inspect.js +179 -266
  76. package/dist/init/interactive.js +510 -622
  77. package/dist/init/neonctl.js +117 -168
  78. package/dist/init/orchestrate.js +157 -173
  79. package/dist/init/phases/auth.js +188 -202
  80. package/dist/init/phases/cleanup.js +23 -23
  81. package/dist/init/phases/db.js +251 -277
  82. package/dist/init/phases/getting_started.js +213 -223
  83. package/dist/init/phases/mcp.js +174 -224
  84. package/dist/init/phases/migrations.js +247 -248
  85. package/dist/init/phases/neon_auth.js +114 -133
  86. package/dist/init/phases/setup.js +546 -703
  87. package/dist/init/phases/skills.js +75 -86
  88. package/dist/init/phases/status.js +72 -67
  89. package/dist/init/resolve_context.js +102 -99
  90. package/dist/init/route_command.js +91 -98
  91. package/dist/init/skills.js +174 -218
  92. package/dist/init/vsix.js +77 -99
  93. package/dist/log.js +17 -16
  94. package/dist/neon_services.js +104 -129
  95. package/dist/parameters.gen.js +481 -471
  96. package/dist/pkg.js +17 -19
  97. package/dist/profile_keys.js +44 -47
  98. package/dist/psql/cli.js +44 -47
  99. package/dist/psql/command/cmd_cond.js +231 -406
  100. package/dist/psql/command/cmd_connect.js +557 -764
  101. package/dist/psql/command/cmd_copy.js +727 -983
  102. package/dist/psql/command/cmd_describe.js +1499 -1688
  103. package/dist/psql/command/cmd_format.js +733 -905
  104. package/dist/psql/command/cmd_io.js +1293 -2082
  105. package/dist/psql/command/cmd_lo.js +297 -359
  106. package/dist/psql/command/cmd_meta.js +727 -878
  107. package/dist/psql/command/cmd_misc.js +138 -172
  108. package/dist/psql/command/cmd_pipeline.js +547 -1099
  109. package/dist/psql/command/cmd_restrict.js +119 -155
  110. package/dist/psql/command/cmd_show.js +529 -688
  111. package/dist/psql/command/dispatch.js +261 -325
  112. package/dist/psql/command/inputQueue.js +35 -33
  113. package/dist/psql/command/shared.js +49 -63
  114. package/dist/psql/complete/filenames.js +90 -133
  115. package/dist/psql/complete/index.js +59 -97
  116. package/dist/psql/complete/matcher.js +236 -300
  117. package/dist/psql/complete/psqlVars.js +218 -223
  118. package/dist/psql/complete/queries.js +159 -177
  119. package/dist/psql/complete/rules.js +1493 -2299
  120. package/dist/psql/core/common.js +762 -1180
  121. package/dist/psql/core/help.js +456 -546
  122. package/dist/psql/core/mainloop.js +692 -1302
  123. package/dist/psql/core/prompt.js +391 -408
  124. package/dist/psql/core/settings.js +429 -644
  125. package/dist/psql/core/sqlHelp.js +480 -554
  126. package/dist/psql/core/startup.js +626 -815
  127. package/dist/psql/core/syncVars.js +67 -110
  128. package/dist/psql/core/variables.js +156 -278
  129. package/dist/psql/describe/formatters.js +884 -1285
  130. package/dist/psql/describe/processNamePattern.js +173 -260
  131. package/dist/psql/describe/queries.js +1368 -2403
  132. package/dist/psql/describe/versionGate.js +32 -41
  133. package/dist/psql/index.js +1414 -1927
  134. package/dist/psql/io/history.js +232 -271
  135. package/dist/psql/io/input.js +103 -108
  136. package/dist/psql/io/lineEditor/buffer.js +238 -319
  137. package/dist/psql/io/lineEditor/complete.js +135 -213
  138. package/dist/psql/io/lineEditor/filename.js +139 -148
  139. package/dist/psql/io/lineEditor/index.js +653 -870
  140. package/dist/psql/io/lineEditor/keymap.js +544 -702
  141. package/dist/psql/io/lineEditor/vt100.js +294 -341
  142. package/dist/psql/io/pgpass.js +158 -187
  143. package/dist/psql/io/pgservice.js +146 -183
  144. package/dist/psql/io/psqlrc.js +328 -403
  145. package/dist/psql/print/aligned.js +1020 -1683
  146. package/dist/psql/print/asciidoc.js +180 -214
  147. package/dist/psql/print/crosstab.js +281 -442
  148. package/dist/psql/print/csv.js +48 -70
  149. package/dist/psql/print/html.js +195 -226
  150. package/dist/psql/print/json.js +75 -88
  151. package/dist/psql/print/latex.js +291 -364
  152. package/dist/psql/print/pager.js +171 -242
  153. package/dist/psql/print/troff.js +194 -226
  154. package/dist/psql/print/unaligned.js +69 -95
  155. package/dist/psql/print/units.js +167 -169
  156. package/dist/psql/scanner/slash.js +428 -483
  157. package/dist/psql/scanner/sql.js +445 -889
  158. package/dist/psql/scanner/stringutils.js +309 -379
  159. package/dist/psql/types/index.js +2 -7
  160. package/dist/psql/types/scanner.js +25 -22
  161. package/dist/psql/wire/connection.js +2042 -2803
  162. package/dist/psql/wire/copy.js +84 -100
  163. package/dist/psql/wire/notify.js +39 -59
  164. package/dist/psql/wire/pipeline.js +305 -518
  165. package/dist/psql/wire/protocol.js +349 -417
  166. package/dist/psql/wire/sasl.js +180 -265
  167. package/dist/psql/wire/tls.js +400 -561
  168. package/dist/storage_api.js +115 -129
  169. package/dist/test_utils/fixtures.js +94 -113
  170. package/dist/test_utils/oauth_server.js +10 -7
  171. package/dist/test_utils/project_dir.js +33 -0
  172. package/dist/utils/ai_gateway_notice.js +131 -162
  173. package/dist/utils/api_enums.js +21 -28
  174. package/dist/utils/auth.js +10 -4
  175. package/dist/utils/branch_notice.js +20 -19
  176. package/dist/utils/branch_picker.js +83 -89
  177. package/dist/utils/cli_name.js +15 -12
  178. package/dist/utils/compute_units.js +20 -27
  179. package/dist/utils/config_diff.js +127 -158
  180. package/dist/utils/enrichers.js +95 -148
  181. package/dist/utils/esbuild.js +133 -147
  182. package/dist/utils/flags.js +35 -47
  183. package/dist/utils/formats.js +8 -15
  184. package/dist/utils/git_diff.js +69 -80
  185. package/dist/utils/inspect_db.js +101 -143
  186. package/dist/utils/inspect_queries.js +179 -142
  187. package/dist/utils/middlewares.js +37 -44
  188. package/dist/utils/openapi.js +87 -99
  189. package/dist/utils/package_manager.js +312 -110
  190. package/dist/utils/point_in_time.js +49 -53
  191. package/dist/utils/psql.js +89 -106
  192. package/dist/utils/service_picker.js +55 -58
  193. package/dist/utils/string.js +5 -5
  194. package/dist/utils/ui.js +38 -55
  195. package/dist/utils/write_sync.js +26 -35
  196. package/dist/utils/zip.js +4 -3
  197. package/dist/writer.js +67 -87
  198. package/package.json +9 -7
@@ -1,394 +1,334 @@
1
- import prompts from "prompts";
2
- import { isNeonApiError, messageFromBody } from "../api.js";
3
- import { updateContextFile } from "../context.js";
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
4
2
  import { isCi } from "../env.js";
5
3
  import { log } from "../log.js";
6
- import { projectCreateRequest, projectUpdateRequest, } from "../parameters.gen.js";
4
+ import { isNeonApiError, messageFromBody } from "../api.js";
5
+ import { updateContextFile } from "../context.js";
7
6
  import { getCliName } from "../utils/cli_name.js";
7
+ import { writer } from "../writer.js";
8
+ import { projectCreateRequest, projectUpdateRequest } from "../parameters.gen.js";
8
9
  import { getComputeUnits } from "../utils/compute_units.js";
9
10
  import { psql } from "../utils/psql.js";
10
- import { writer } from "../writer.js";
11
- export const PROJECT_FIELDS = [
12
- "id",
13
- "name",
14
- "region_id",
15
- "created_at",
11
+ import prompts from "prompts";
12
+ //#region src/commands/projects.ts
13
+ var projects_exports = /* @__PURE__ */ __exportAll({
14
+ PROJECT_FIELDS: () => PROJECT_FIELDS,
15
+ REGIONS: () => REGIONS,
16
+ aliases: () => aliases,
17
+ builder: () => builder,
18
+ command: () => command,
19
+ describe: () => describe,
20
+ handler: () => handler
21
+ });
22
+ const PROJECT_FIELDS = [
23
+ "id",
24
+ "name",
25
+ "region_id",
26
+ "created_at"
16
27
  ];
17
- export const REGIONS = [
18
- "aws-us-west-2",
19
- "aws-ap-southeast-1",
20
- "aws-ap-southeast-2",
21
- "aws-eu-central-1",
22
- "aws-us-east-2",
23
- "aws-us-east-1",
24
- "azure-eastus2",
28
+ const REGIONS = [
29
+ "aws-us-west-2",
30
+ "aws-ap-southeast-1",
31
+ "aws-ap-southeast-2",
32
+ "aws-eu-central-1",
33
+ "aws-us-east-2",
34
+ "aws-us-east-1",
35
+ "azure-eastus2"
25
36
  ];
26
37
  const PROJECTS_LIST_LIMIT = 100;
27
- export const command = "projects";
28
- export const describe = "Manage projects";
29
- export const aliases = ["project"];
30
- export const builder = (argv) => {
31
- return argv
32
- .usage("$0 projects <sub-command> [options]")
33
- .middleware((args) => {
34
- // Provide alias for analytics
35
- args.projectId = args.id;
36
- })
37
- .command("list", "List projects", (yargs) => yargs.options({
38
- "org-id": {
39
- describe: "List projects of a given organization",
40
- type: "string",
41
- },
42
- "recoverable-only": {
43
- describe: "List only deleted projects within their deletion grace period",
44
- type: "boolean",
45
- },
46
- }), async (args) => {
47
- await handleMissingOrgId(args, list);
48
- })
49
- .command("create", "Create a project", (yargs) => yargs.options({
50
- "block-public-connections": {
51
- describe: projectCreateRequest["project.settings.block_public_connections"].description,
52
- type: "boolean",
53
- },
54
- "block-vpc-connections": {
55
- describe: projectCreateRequest["project.settings.block_vpc_connections"].description,
56
- type: "boolean",
57
- },
58
- hipaa: {
59
- describe: projectCreateRequest["project.settings.hipaa"]
60
- .description,
61
- type: "boolean",
62
- },
63
- name: {
64
- describe: projectCreateRequest["project.name"].description,
65
- type: "string",
66
- },
67
- "region-id": {
68
- describe: `The region ID. Possible values: ${REGIONS.join(", ")}`,
69
- type: "string",
70
- },
71
- "org-id": {
72
- describe: "The project's organization ID",
73
- type: "string",
74
- },
75
- psql: {
76
- type: "boolean",
77
- describe: "Connect to a new project via psql",
78
- default: false,
79
- },
80
- fallback: {
81
- type: "boolean",
82
- describe: "Force the embedded TypeScript psql fallback (for testing)",
83
- default: false,
84
- hidden: true,
85
- },
86
- database: {
87
- describe: projectCreateRequest["project.branch.database_name"]
88
- .description,
89
- type: "string",
90
- },
91
- role: {
92
- describe: projectCreateRequest["project.branch.role_name"]
93
- .description,
94
- type: "string",
95
- },
96
- "pg-version": {
97
- describe: "Major PostgreSQL version (14–19). Version 19 is available only in regions where it has been enabled.",
98
- type: "number",
99
- choices: [14, 15, 16, 17, 18, 19],
100
- },
101
- "set-context": {
102
- type: "boolean",
103
- describe: "Set the current context to the new project",
104
- default: false,
105
- },
106
- cu: {
107
- 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").',
108
- type: "string",
109
- },
110
- }), async (args) => {
111
- await handleMissingOrgId(args, create);
112
- })
113
- .command("update <id>", "Update a project", (yargs) => yargs.options({
114
- "block-vpc-connections": {
115
- describe: projectUpdateRequest["project.settings.block_vpc_connections"].description +
116
- " Use --block-vpc-connections=false to set the value to false.",
117
- type: "boolean",
118
- },
119
- "block-public-connections": {
120
- describe: projectUpdateRequest["project.settings.block_public_connections"].description +
121
- " Use --block-public-connections=false to set the value to false.",
122
- type: "boolean",
123
- },
124
- hipaa: {
125
- describe: projectUpdateRequest["project.settings.hipaa"]
126
- .description,
127
- type: "boolean",
128
- },
129
- cu: {
130
- 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").',
131
- type: "string",
132
- },
133
- name: {
134
- describe: projectUpdateRequest["project.name"].description,
135
- type: "string",
136
- },
137
- "enable-logical-replication": {
138
- describe: "Enable logical replication for all project endpoints. This suspends active endpoints and cannot be disabled.",
139
- type: "boolean",
140
- },
141
- yes: {
142
- type: "boolean",
143
- default: false,
144
- describe: "Skip the confirmation prompt when enabling logical replication.",
145
- },
146
- }), async (args) => {
147
- await update(args);
148
- })
149
- .command("delete <id>", "Delete a project", (yargs) => yargs, async (args) => {
150
- await deleteProject(args);
151
- })
152
- .command("recover <id>", "Recovers a deleted project during the deletion grace period", (yargs) => yargs, async (args) => {
153
- await recover(args);
154
- })
155
- .command("get <id>", "Get a project", (yargs) => yargs, async (args) => {
156
- await get(args);
157
- });
38
+ const command = "projects";
39
+ const describe = "Manage projects";
40
+ const aliases = ["project"];
41
+ const builder = (argv) => {
42
+ return argv.usage("$0 projects <sub-command> [options]").middleware((args) => {
43
+ args.projectId = args.id;
44
+ }).command("list", "List projects", (yargs) => yargs.options({
45
+ "org-id": {
46
+ describe: "List projects of a given organization",
47
+ type: "string"
48
+ },
49
+ "recoverable-only": {
50
+ describe: "List only deleted projects within their deletion grace period",
51
+ type: "boolean"
52
+ }
53
+ }), async (args) => {
54
+ await handleMissingOrgId(args, list);
55
+ }).command("create", "Create a project", (yargs) => yargs.options({
56
+ "block-public-connections": {
57
+ describe: projectCreateRequest["project.settings.block_public_connections"].description,
58
+ type: "boolean"
59
+ },
60
+ "block-vpc-connections": {
61
+ describe: projectCreateRequest["project.settings.block_vpc_connections"].description,
62
+ type: "boolean"
63
+ },
64
+ hipaa: {
65
+ describe: projectCreateRequest["project.settings.hipaa"].description,
66
+ type: "boolean"
67
+ },
68
+ name: {
69
+ describe: projectCreateRequest["project.name"].description,
70
+ type: "string"
71
+ },
72
+ "region-id": {
73
+ describe: `The region ID. Possible values: ${REGIONS.join(", ")}`,
74
+ type: "string"
75
+ },
76
+ "org-id": {
77
+ describe: "The project's organization ID",
78
+ type: "string"
79
+ },
80
+ psql: {
81
+ type: "boolean",
82
+ describe: "Connect to a new project via psql",
83
+ default: false
84
+ },
85
+ fallback: {
86
+ type: "boolean",
87
+ describe: "Force the embedded TypeScript psql fallback (for testing)",
88
+ default: false,
89
+ hidden: true
90
+ },
91
+ database: {
92
+ describe: projectCreateRequest["project.branch.database_name"].description,
93
+ type: "string"
94
+ },
95
+ role: {
96
+ describe: projectCreateRequest["project.branch.role_name"].description,
97
+ type: "string"
98
+ },
99
+ "pg-version": {
100
+ describe: "Major PostgreSQL version (14–19). Version 19 is available only in regions where it has been enabled.",
101
+ type: "number",
102
+ choices: [
103
+ 14,
104
+ 15,
105
+ 16,
106
+ 17,
107
+ 18,
108
+ 19
109
+ ]
110
+ },
111
+ "set-context": {
112
+ type: "boolean",
113
+ describe: "Set the current context to the new project",
114
+ default: false
115
+ },
116
+ cu: {
117
+ 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\").",
118
+ type: "string"
119
+ }
120
+ }), async (args) => {
121
+ await handleMissingOrgId(args, create);
122
+ }).command("update <id>", "Update a project", (yargs) => yargs.options({
123
+ "block-vpc-connections": {
124
+ describe: projectUpdateRequest["project.settings.block_vpc_connections"].description + " Use --block-vpc-connections=false to set the value to false.",
125
+ type: "boolean"
126
+ },
127
+ "block-public-connections": {
128
+ describe: projectUpdateRequest["project.settings.block_public_connections"].description + " Use --block-public-connections=false to set the value to false.",
129
+ type: "boolean"
130
+ },
131
+ hipaa: {
132
+ describe: projectUpdateRequest["project.settings.hipaa"].description,
133
+ type: "boolean"
134
+ },
135
+ cu: {
136
+ 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\").",
137
+ type: "string"
138
+ },
139
+ name: {
140
+ describe: projectUpdateRequest["project.name"].description,
141
+ type: "string"
142
+ },
143
+ "enable-logical-replication": {
144
+ describe: "Enable logical replication for all project endpoints. This suspends active endpoints and cannot be disabled.",
145
+ type: "boolean"
146
+ },
147
+ yes: {
148
+ type: "boolean",
149
+ default: false,
150
+ describe: "Skip the confirmation prompt when enabling logical replication."
151
+ }
152
+ }), async (args) => {
153
+ await update(args);
154
+ }).command("delete <id>", "Delete a project", (yargs) => yargs, async (args) => {
155
+ await deleteProject(args);
156
+ }).command("recover <id>", "Recovers a deleted project during the deletion grace period", (yargs) => yargs, async (args) => {
157
+ await recover(args);
158
+ }).command("get <id>", "Get a project", (yargs) => yargs, async (args) => {
159
+ await get(args);
160
+ });
158
161
  };
159
- export const handler = (args) => {
160
- return args;
162
+ const handler = (args) => {
163
+ return args;
161
164
  };
162
165
  const list = async (props) => {
163
- const getList = async (fn) => {
164
- const result = [];
165
- let cursor;
166
- let end = false;
167
- while (!end) {
168
- const { data } = await fn({
169
- limit: PROJECTS_LIST_LIMIT,
170
- org_id: props.orgId,
171
- recoverable: props.recoverableOnly,
172
- cursor,
173
- });
174
- result.push(...data.projects);
175
- cursor = data.pagination?.cursor;
176
- log.debug("Got %d projects, with cursor: %s", data.projects.length, cursor);
177
- if (data.projects.length < PROJECTS_LIST_LIMIT) {
178
- end = true;
179
- }
180
- }
181
- return result;
182
- };
183
- const ownedProjects = await getList(props.apiClient.listProjects);
184
- const sharedProjects = props.orgId || props.recoverableOnly
185
- ? []
186
- : await getList(props.apiClient.listSharedProjects);
187
- const out = writer(props);
188
- out.write(ownedProjects, {
189
- fields: props.recoverableOnly
190
- ? [...PROJECT_FIELDS, "deleted_at", "recoverable_until"]
191
- : PROJECT_FIELDS,
192
- title: "Projects",
193
- emptyMessage: props.recoverableOnly
194
- ? "You don't have any recoverable projects."
195
- : "You don't have any projects yet. See how to create a new project:\n> neon projects create --help",
196
- });
197
- if (!props.orgId && !props.recoverableOnly) {
198
- // We don't list shared projects when listing recoverable projects
199
- out.write(sharedProjects, {
200
- fields: PROJECT_FIELDS,
201
- title: "Shared with you",
202
- emptyMessage: "No projects have been shared with you",
203
- });
204
- }
205
- out.end();
166
+ const getList = async (fn) => {
167
+ const result = [];
168
+ let cursor;
169
+ let end = false;
170
+ while (!end) {
171
+ const { data } = await fn({
172
+ limit: PROJECTS_LIST_LIMIT,
173
+ org_id: props.orgId,
174
+ recoverable: props.recoverableOnly,
175
+ cursor
176
+ });
177
+ result.push(...data.projects);
178
+ cursor = data.pagination?.cursor;
179
+ log.debug("Got %d projects, with cursor: %s", data.projects.length, cursor);
180
+ if (data.projects.length < PROJECTS_LIST_LIMIT) end = true;
181
+ }
182
+ return result;
183
+ };
184
+ const ownedProjects = await getList(props.apiClient.listProjects);
185
+ const sharedProjects = props.orgId || props.recoverableOnly ? [] : await getList(props.apiClient.listSharedProjects);
186
+ const out = writer(props);
187
+ out.write(ownedProjects, {
188
+ fields: props.recoverableOnly ? [
189
+ ...PROJECT_FIELDS,
190
+ "deleted_at",
191
+ "recoverable_until"
192
+ ] : PROJECT_FIELDS,
193
+ title: "Projects",
194
+ emptyMessage: props.recoverableOnly ? "You don't have any recoverable projects." : "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) out.write(sharedProjects, {
197
+ fields: PROJECT_FIELDS,
198
+ title: "Shared with you",
199
+ emptyMessage: "No projects have been shared with you"
200
+ });
201
+ out.end();
206
202
  };
207
203
  const create = async (props) => {
208
- const project = {};
209
- if (props.hipaa !== undefined) {
210
- if (!project.settings) {
211
- project.settings = {};
212
- }
213
- project.settings.hipaa = props.hipaa;
214
- }
215
- if (props.blockPublicConnections !== undefined) {
216
- if (!project.settings) {
217
- project.settings = {};
218
- }
219
- project.settings.block_public_connections =
220
- props.blockPublicConnections;
221
- }
222
- if (props.blockVpcConnections !== undefined) {
223
- if (!project.settings) {
224
- project.settings = {};
225
- }
226
- project.settings.block_vpc_connections = props.blockVpcConnections;
227
- }
228
- if (props.name) {
229
- project.name = props.name;
230
- }
231
- if (props.regionId) {
232
- project.region_id = props.regionId;
233
- }
234
- if (props.orgId) {
235
- project.org_id = props.orgId;
236
- }
237
- project.branch = {};
238
- if (props.database) {
239
- project.branch.database_name = props.database;
240
- }
241
- if (props.role) {
242
- project.branch.role_name = props.role;
243
- }
244
- if (props.pgVersion !== undefined) {
245
- project.pg_version = props.pgVersion;
246
- }
247
- if (props.cu) {
248
- project.default_endpoint_settings = props.cu
249
- ? getComputeUnits(props.cu)
250
- : undefined;
251
- }
252
- const { data } = await props.apiClient.createProject({
253
- project,
254
- });
255
- if (props.setContext) {
256
- updateContextFile(props.contextFile, {
257
- projectId: data.project.id,
258
- });
259
- }
260
- const out = writer(props);
261
- out.write(data.project, { fields: PROJECT_FIELDS, title: "Project" });
262
- out.write(data.connection_uris, {
263
- fields: ["connection_uri"],
264
- title: "Connection URIs",
265
- });
266
- out.end();
267
- if (props.psql) {
268
- const connection_uri = data.connection_uris[0].connection_uri;
269
- const psqlArgs = props["--"];
270
- await psql(connection_uri, psqlArgs, {
271
- mode: props.fallback ? "ts" : "auto",
272
- });
273
- }
204
+ const project = {};
205
+ if (props.hipaa !== void 0) {
206
+ if (!project.settings) project.settings = {};
207
+ project.settings.hipaa = props.hipaa;
208
+ }
209
+ if (props.blockPublicConnections !== void 0) {
210
+ if (!project.settings) project.settings = {};
211
+ project.settings.block_public_connections = props.blockPublicConnections;
212
+ }
213
+ if (props.blockVpcConnections !== void 0) {
214
+ if (!project.settings) project.settings = {};
215
+ project.settings.block_vpc_connections = props.blockVpcConnections;
216
+ }
217
+ if (props.name) project.name = props.name;
218
+ if (props.regionId) project.region_id = props.regionId;
219
+ if (props.orgId) project.org_id = props.orgId;
220
+ project.branch = {};
221
+ if (props.database) project.branch.database_name = props.database;
222
+ if (props.role) project.branch.role_name = props.role;
223
+ if (props.pgVersion !== void 0) project.pg_version = props.pgVersion;
224
+ if (props.cu) project.default_endpoint_settings = props.cu ? getComputeUnits(props.cu) : void 0;
225
+ const { data } = await props.apiClient.createProject({ project });
226
+ if (props.setContext) updateContextFile(props.contextFile, { projectId: data.project.id });
227
+ const out = writer(props);
228
+ out.write(data.project, {
229
+ fields: PROJECT_FIELDS,
230
+ title: "Project"
231
+ });
232
+ out.write(data.connection_uris, {
233
+ fields: ["connection_uri"],
234
+ title: "Connection URIs"
235
+ });
236
+ out.end();
237
+ if (props.psql) {
238
+ const connection_uri = data.connection_uris[0].connection_uri;
239
+ const psqlArgs = props["--"];
240
+ await psql(connection_uri, psqlArgs, { mode: props.fallback ? "ts" : "auto" });
241
+ }
274
242
  };
275
243
  const deleteProject = async (props) => {
276
- const { data } = await props.apiClient.deleteProject(props.id);
277
- writer(props).end(data.project, {
278
- fields: PROJECT_FIELDS,
279
- });
244
+ const { data } = await props.apiClient.deleteProject(props.id);
245
+ writer(props).end(data.project, { fields: PROJECT_FIELDS });
280
246
  };
281
247
  const update = async (props) => {
282
- const project = {};
283
- if (props.enableLogicalReplication !== undefined) {
284
- if (!props.enableLogicalReplication) {
285
- throw new Error("Logical replication cannot be disabled once it has been enabled.");
286
- }
287
- if (!props.yes) {
288
- if (isCi() || !process.stdin.isTTY) {
289
- throw new Error("Enabling logical replication requires confirmation. Re-run interactively or pass --yes.");
290
- }
291
- const { proceed } = await prompts({
292
- onState: onPromptState,
293
- type: "confirm",
294
- name: "proceed",
295
- message: "Enable logical replication? This suspends active endpoints and cannot be undone.",
296
- initial: false,
297
- });
298
- if (!proceed) {
299
- log.info("Logical replication was not enabled.");
300
- return;
301
- }
302
- }
303
- project.settings = {
304
- enable_logical_replication: true,
305
- };
306
- }
307
- if (props.hipaa !== undefined) {
308
- if (!project.settings) {
309
- project.settings = {};
310
- }
311
- project.settings.hipaa = props.hipaa;
312
- }
313
- if (props.blockPublicConnections !== undefined) {
314
- if (!project.settings) {
315
- project.settings = {};
316
- }
317
- project.settings.block_public_connections =
318
- props.blockPublicConnections;
319
- }
320
- if (props.blockVpcConnections !== undefined) {
321
- if (!project.settings) {
322
- project.settings = {};
323
- }
324
- project.settings.block_vpc_connections = props.blockVpcConnections;
325
- }
326
- if (props.name) {
327
- project.name = props.name;
328
- }
329
- if (props.cu) {
330
- project.default_endpoint_settings = props.cu
331
- ? getComputeUnits(props.cu)
332
- : undefined;
333
- }
334
- const { data } = await props.apiClient.updateProject(props.id, {
335
- project,
336
- });
337
- writer(props).end(data.project, { fields: PROJECT_FIELDS });
248
+ const project = {};
249
+ if (props.enableLogicalReplication !== void 0) {
250
+ if (!props.enableLogicalReplication) throw new Error("Logical replication cannot be disabled once it has been enabled.");
251
+ if (!props.yes) {
252
+ if (isCi() || !process.stdin.isTTY) throw new Error("Enabling logical replication requires confirmation. Re-run interactively or pass --yes.");
253
+ const { proceed } = await prompts({
254
+ onState: onPromptState,
255
+ type: "confirm",
256
+ name: "proceed",
257
+ message: "Enable logical replication? This suspends active endpoints and cannot be undone.",
258
+ initial: false
259
+ });
260
+ if (!proceed) {
261
+ log.info("Logical replication was not enabled.");
262
+ return;
263
+ }
264
+ }
265
+ project.settings = { enable_logical_replication: true };
266
+ }
267
+ if (props.hipaa !== void 0) {
268
+ if (!project.settings) project.settings = {};
269
+ project.settings.hipaa = props.hipaa;
270
+ }
271
+ if (props.blockPublicConnections !== void 0) {
272
+ if (!project.settings) project.settings = {};
273
+ project.settings.block_public_connections = props.blockPublicConnections;
274
+ }
275
+ if (props.blockVpcConnections !== void 0) {
276
+ if (!project.settings) project.settings = {};
277
+ project.settings.block_vpc_connections = props.blockVpcConnections;
278
+ }
279
+ if (props.name) project.name = props.name;
280
+ if (props.cu) project.default_endpoint_settings = props.cu ? getComputeUnits(props.cu) : void 0;
281
+ const { data } = await props.apiClient.updateProject(props.id, { project });
282
+ writer(props).end(data.project, { fields: PROJECT_FIELDS });
338
283
  };
339
284
  const recover = async (props) => {
340
- const { data } = await props.apiClient.recoverProject(props.id);
341
- writer(props).end(data.project, { fields: PROJECT_FIELDS });
285
+ const { data } = await props.apiClient.recoverProject(props.id);
286
+ writer(props).end(data.project, { fields: PROJECT_FIELDS });
342
287
  };
343
288
  const get = async (props) => {
344
- const { data } = await props.apiClient.getProject(props.id);
345
- writer(props).end(data.project, { fields: PROJECT_FIELDS });
289
+ const { data } = await props.apiClient.getProject(props.id);
290
+ writer(props).end(data.project, { fields: PROJECT_FIELDS });
346
291
  };
347
292
  const handleMissingOrgId = async (args, cmd) => {
348
- try {
349
- await cmd(args);
350
- }
351
- catch (err) {
352
- if (!isCi() && isOrgIdError(err)) {
353
- const orgId = await selectOrg(args);
354
- await cmd({ ...args, orgId });
355
- }
356
- else {
357
- throw err;
358
- }
359
- }
293
+ try {
294
+ await cmd(args);
295
+ } catch (err) {
296
+ if (!isCi() && isOrgIdError(err)) {
297
+ const orgId = await selectOrg(args);
298
+ await cmd({
299
+ ...args,
300
+ orgId
301
+ });
302
+ } else throw err;
303
+ }
360
304
  };
361
305
  const isOrgIdError = (err) => {
362
- return (isNeonApiError(err) &&
363
- err.status === 400 &&
364
- messageFromBody(err.data)?.includes("org_id is required"));
306
+ return isNeonApiError(err) && err.status === 400 && messageFromBody(err.data)?.includes("org_id is required");
365
307
  };
366
308
  const selectOrg = async (props) => {
367
- const { data: { organizations }, } = await props.apiClient.getCurrentUserOrganizations();
368
- if (!organizations?.length) {
369
- throw new Error(`You don't belong to any organizations. Please create an organization first.`);
370
- }
371
- const { orgId } = await prompts({
372
- onState: onPromptState,
373
- type: "select",
374
- name: "orgId",
375
- message: `What organization would you like to use?`,
376
- choices: organizations.map((org) => ({
377
- title: `${org.name} (${org.id})`,
378
- value: org.id,
379
- })),
380
- initial: 0,
381
- });
382
- const { save } = await prompts({
383
- onState: onPromptState,
384
- type: "confirm",
385
- name: "save",
386
- message: `Would you like to use this organization by default?`,
387
- initial: true,
388
- });
389
- if (save) {
390
- updateContextFile(props.contextFile, { orgId });
391
- writer(props).text(`
309
+ const { data: { organizations } } = await props.apiClient.getCurrentUserOrganizations();
310
+ if (!organizations?.length) throw new Error(`You don't belong to any organizations. Please create an organization first.`);
311
+ const { orgId } = await prompts({
312
+ onState: onPromptState,
313
+ type: "select",
314
+ name: "orgId",
315
+ message: `What organization would you like to use?`,
316
+ choices: organizations.map((org) => ({
317
+ title: `${org.name} (${org.id})`,
318
+ value: org.id
319
+ })),
320
+ initial: 0
321
+ });
322
+ const { save } = await prompts({
323
+ onState: onPromptState,
324
+ type: "confirm",
325
+ name: "save",
326
+ message: `Would you like to use this organization by default?`,
327
+ initial: true
328
+ });
329
+ if (save) {
330
+ updateContextFile(props.contextFile, { orgId });
331
+ writer(props).text(`
392
332
  The organization ID has been saved in ${props.contextFile}
393
333
 
394
334
  If you'd like to change the default organization later, use
@@ -400,15 +340,15 @@ Or to clear the context file and forget the default organization
400
340
  ${getCliName()} link --clear
401
341
 
402
342
  `);
403
- }
404
- return orgId;
343
+ }
344
+ return orgId;
405
345
  };
406
346
  const onPromptState = (state) => {
407
- if (state.aborted) {
408
- // If we don't re-enable the terminal cursor before exiting
409
- // the program, the cursor will remain hidden
410
- process.stdout.write("\x1B[?25h");
411
- process.stdout.write("\n");
412
- process.exit(1);
413
- }
347
+ if (state.aborted) {
348
+ process.stdout.write("\x1B[?25h");
349
+ process.stdout.write("\n");
350
+ process.exit(1);
351
+ }
414
352
  };
353
+ //#endregion
354
+ export { PROJECT_FIELDS, REGIONS, aliases, builder, command, describe, handler, projects_exports };