neon 3.0.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 +354 -517
  5. package/dist/_shared/env-core/reuse-secrets.js +159 -203
  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 +573 -690
  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 +639 -719
  28. package/dist/commands/diff.js +156 -200
  29. package/dist/commands/env.js +243 -303
  30. package/dist/commands/functions.js +275 -355
  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 -68
  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 +130 -189
  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 +7 -5
@@ -1,285 +1,263 @@
1
- import { isNeonApiError, retryOnLock } from "../api.js";
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { log } from "../log.js";
3
+ import { isNeonApiError, retryOnLock } from "../api.js";
3
4
  import { getCliName } from "../utils/cli_name.js";
4
- import { branchIdFromProps, fillSingleProject, resolveSingleDatabase, } from "../utils/enrichers.js";
5
5
  import { writer } from "../writer.js";
6
+ import { branchIdFromProps, fillSingleProject, resolveSingleDatabase } from "../utils/enrichers.js";
7
+ //#region src/commands/data_api.ts
8
+ var data_api_exports = /* @__PURE__ */ __exportAll({
9
+ builder: () => builder,
10
+ command: () => command,
11
+ describe: () => describe,
12
+ handler: () => handler
13
+ });
6
14
  const SETTINGS_FIELDS = [
7
- "db_aggregates_enabled",
8
- "db_anon_role",
9
- "db_extra_search_path",
10
- "db_max_rows",
11
- "db_schemas",
12
- "jwt_role_claim_key",
13
- "jwt_cache_max_lifetime",
14
- "openapi_mode",
15
- "server_cors_allowed_origins",
16
- "server_timing_enabled",
15
+ "db_aggregates_enabled",
16
+ "db_anon_role",
17
+ "db_extra_search_path",
18
+ "db_max_rows",
19
+ "db_schemas",
20
+ "jwt_role_claim_key",
21
+ "jwt_cache_max_lifetime",
22
+ "openapi_mode",
23
+ "server_cors_allowed_origins",
24
+ "server_timing_enabled"
17
25
  ];
18
26
  const settingsFlags = {
19
- "db-aggregates-enabled": {
20
- type: "boolean",
21
- describe: "Enable aggregate functions in queries",
22
- },
23
- "db-anon-role": {
24
- type: "string",
25
- describe: "Database role used for anonymous (unauthenticated) requests",
26
- },
27
- "db-extra-search-path": {
28
- type: "string",
29
- describe: "Extra schemas appended to the search path",
30
- },
31
- "db-max-rows": {
32
- type: "number",
33
- describe: "Maximum number of rows returned by a single request",
34
- },
35
- "db-schemas": {
36
- type: "string",
37
- describe: "Comma-separated list of schemas exposed via the Data API",
38
- },
39
- "jwt-role-claim-key": {
40
- type: "string",
41
- describe: "JWT claim path used to extract the role",
42
- },
43
- "jwt-cache-max-lifetime": {
44
- type: "number",
45
- describe: "Maximum JWT cache lifetime in seconds",
46
- },
47
- "openapi-mode": {
48
- type: "string",
49
- choices: ["ignore-privileges", "disabled"],
50
- describe: "OpenAPI mode",
51
- },
52
- "server-cors-allowed-origins": {
53
- type: "string",
54
- describe: "CORS allowed origins",
55
- },
56
- "server-timing-enabled": {
57
- type: "boolean",
58
- describe: "Enable Server-Timing response headers",
59
- },
27
+ "db-aggregates-enabled": {
28
+ type: "boolean",
29
+ describe: "Enable aggregate functions in queries"
30
+ },
31
+ "db-anon-role": {
32
+ type: "string",
33
+ describe: "Database role used for anonymous (unauthenticated) requests"
34
+ },
35
+ "db-extra-search-path": {
36
+ type: "string",
37
+ describe: "Extra schemas appended to the search path"
38
+ },
39
+ "db-max-rows": {
40
+ type: "number",
41
+ describe: "Maximum number of rows returned by a single request"
42
+ },
43
+ "db-schemas": {
44
+ type: "string",
45
+ describe: "Comma-separated list of schemas exposed via the Data API"
46
+ },
47
+ "jwt-role-claim-key": {
48
+ type: "string",
49
+ describe: "JWT claim path used to extract the role"
50
+ },
51
+ "jwt-cache-max-lifetime": {
52
+ type: "number",
53
+ describe: "Maximum JWT cache lifetime in seconds"
54
+ },
55
+ "openapi-mode": {
56
+ type: "string",
57
+ choices: ["ignore-privileges", "disabled"],
58
+ describe: "OpenAPI mode"
59
+ },
60
+ "server-cors-allowed-origins": {
61
+ type: "string",
62
+ describe: "CORS allowed origins"
63
+ },
64
+ "server-timing-enabled": {
65
+ type: "boolean",
66
+ describe: "Enable Server-Timing response headers"
67
+ }
60
68
  };
61
- export const command = "data-api";
62
- export const describe = "Manage the Neon Data API for a database";
63
- export const builder = (argv) => argv
64
- .usage("$0 data-api <sub-command> [options]")
65
- .options({
66
- "project-id": {
67
- describe: "Project ID",
68
- type: "string",
69
- },
70
- branch: {
71
- describe: "Branch ID or name",
72
- type: "string",
73
- },
74
- database: {
75
- describe: "Database name",
76
- type: "string",
77
- },
78
- })
79
- .middleware(fillSingleProject)
80
- .command("create", "Provision the Neon Data API for a database", (yargs) => yargs.options({
81
- "auth-provider": {
82
- type: "string",
83
- choices: ["neon_auth", "external"],
84
- describe: "Authentication provider",
85
- },
86
- "jwks-url": {
87
- type: "string",
88
- describe: "URL that lists the JWKS (used with external auth)",
89
- },
90
- "provider-name": {
91
- type: "string",
92
- describe: "Name of the auth provider (e.g. Clerk, Stytch, Auth0)",
93
- },
94
- "jwt-audience": {
95
- type: "string",
96
- describe: "Expected JWT audience claim",
97
- },
98
- "add-default-grants": {
99
- type: "boolean",
100
- describe: "Grant all permissions on tables in the public schema to authenticated users",
101
- },
102
- "skip-auth-schema": {
103
- type: "boolean",
104
- describe: "Skip creating the auth schema and RLS functions",
105
- },
106
- ...settingsFlags,
107
- }), (args) => create(args))
108
- .command("get", "Show the Neon Data API status and settings", (yargs) => yargs, (args) => get(args))
109
- .command("update", "Update Neon Data API settings (merges with current settings by default)", (yargs) => yargs.options({
110
- replace: {
111
- type: "boolean",
112
- default: false,
113
- describe: "Replace settings with only the flags provided. Omitted settings revert to server defaults.",
114
- },
115
- ...settingsFlags,
116
- }), (args) => update(args))
117
- .command("refresh-schema", "Refresh the Data API schema cache without changing settings", (yargs) => yargs, (args) => refreshSchema(args))
118
- .command("delete", "Tear down the Neon Data API for a database", (yargs) => yargs, (args) => deleteDataApi(args));
119
- export const handler = (args) => {
120
- return args;
69
+ const command = "data-api";
70
+ const describe = "Manage the Neon Data API for a database";
71
+ const builder = (argv) => argv.usage("$0 data-api <sub-command> [options]").options({
72
+ "project-id": {
73
+ describe: "Project ID",
74
+ type: "string"
75
+ },
76
+ branch: {
77
+ describe: "Branch ID or name",
78
+ type: "string"
79
+ },
80
+ database: {
81
+ describe: "Database name",
82
+ type: "string"
83
+ }
84
+ }).middleware(fillSingleProject).command("create", "Provision the Neon Data API for a database", (yargs) => yargs.options({
85
+ "auth-provider": {
86
+ type: "string",
87
+ choices: ["neon_auth", "external"],
88
+ describe: "Authentication provider"
89
+ },
90
+ "jwks-url": {
91
+ type: "string",
92
+ describe: "URL that lists the JWKS (used with external auth)"
93
+ },
94
+ "provider-name": {
95
+ type: "string",
96
+ describe: "Name of the auth provider (e.g. Clerk, Stytch, Auth0)"
97
+ },
98
+ "jwt-audience": {
99
+ type: "string",
100
+ describe: "Expected JWT audience claim"
101
+ },
102
+ "add-default-grants": {
103
+ type: "boolean",
104
+ describe: "Grant all permissions on tables in the public schema to authenticated users"
105
+ },
106
+ "skip-auth-schema": {
107
+ type: "boolean",
108
+ describe: "Skip creating the auth schema and RLS functions"
109
+ },
110
+ ...settingsFlags
111
+ }), (args) => create(args)).command("get", "Show the Neon Data API status and settings", (yargs) => yargs, (args) => get(args)).command("update", "Update Neon Data API settings (merges with current settings by default)", (yargs) => yargs.options({
112
+ replace: {
113
+ type: "boolean",
114
+ default: false,
115
+ describe: "Replace settings with only the flags provided. Omitted settings revert to server defaults."
116
+ },
117
+ ...settingsFlags
118
+ }), (args) => update(args)).command("refresh-schema", "Refresh the Data API schema cache without changing settings", (yargs) => yargs, (args) => refreshSchema(args)).command("delete", "Tear down the Neon Data API for a database", (yargs) => yargs, (args) => deleteDataApi(args));
119
+ const handler = (args) => {
120
+ return args;
121
121
  };
122
122
  const TOP_LEVEL_CREATE_FIELDS = [
123
- "auth_provider",
124
- "jwks_url",
125
- "provider_name",
126
- "jwt_audience",
127
- "add_default_grants",
128
- "skip_auth_schema",
123
+ "auth_provider",
124
+ "jwks_url",
125
+ "provider_name",
126
+ "jwt_audience",
127
+ "add_default_grants",
128
+ "skip_auth_schema"
129
129
  ];
130
130
  const argKey = (snake) => snake.replace(/_/g, "-");
131
131
  const buildSettings = (args) => {
132
- const settings = {};
133
- for (const field of SETTINGS_FIELDS) {
134
- const value = args[argKey(field)];
135
- if (value === undefined)
136
- continue;
137
- if (field === "db_schemas" && typeof value === "string") {
138
- settings[field] = value
139
- .split(",")
140
- .map((s) => s.trim())
141
- .filter(Boolean);
142
- }
143
- else {
144
- settings[field] = value;
145
- }
146
- }
147
- return Object.keys(settings).length > 0
148
- ? settings
149
- : undefined;
132
+ const settings = {};
133
+ for (const field of SETTINGS_FIELDS) {
134
+ const value = args[argKey(field)];
135
+ if (value === void 0) continue;
136
+ if (field === "db_schemas" && typeof value === "string") settings[field] = value.split(",").map((s) => s.trim()).filter(Boolean);
137
+ else settings[field] = value;
138
+ }
139
+ return Object.keys(settings).length > 0 ? settings : void 0;
150
140
  };
151
141
  const buildCreateBody = (args) => {
152
- const body = {};
153
- for (const field of TOP_LEVEL_CREATE_FIELDS) {
154
- const value = args[argKey(field)];
155
- if (value !== undefined)
156
- body[field] = value;
157
- }
158
- const settings = buildSettings(args);
159
- if (settings)
160
- body.settings = settings;
161
- return body;
142
+ const body = {};
143
+ for (const field of TOP_LEVEL_CREATE_FIELDS) {
144
+ const value = args[argKey(field)];
145
+ if (value !== void 0) body[field] = value;
146
+ }
147
+ const settings = buildSettings(args);
148
+ if (settings) body.settings = settings;
149
+ return body;
162
150
  };
163
151
  const create = async (props) => {
164
- const branchId = await branchIdFromProps(props);
165
- const database = await resolveSingleDatabase({
166
- apiClient: props.apiClient,
167
- projectId: props.projectId,
168
- branchId,
169
- database: props.database,
170
- });
171
- const body = buildCreateBody(props);
172
- const { data } = await retryOnLock(() => props.apiClient.createProjectBranchDataApi(props.projectId, branchId, database, body));
173
- writer(props).end(data, { fields: ["url"] });
152
+ const branchId = await branchIdFromProps(props);
153
+ const database = await resolveSingleDatabase({
154
+ apiClient: props.apiClient,
155
+ projectId: props.projectId,
156
+ branchId,
157
+ database: props.database
158
+ });
159
+ const body = buildCreateBody(props);
160
+ const { data } = await retryOnLock(() => props.apiClient.createProjectBranchDataApi(props.projectId, branchId, database, body));
161
+ writer(props).end(data, { fields: ["url"] });
174
162
  };
175
- const GET_FIELDS = ["url", "status", "db_schemas"];
163
+ const GET_FIELDS = [
164
+ "url",
165
+ "status",
166
+ "db_schemas"
167
+ ];
176
168
  const get = async (props) => {
177
- const branchId = await branchIdFromProps(props);
178
- const database = await resolveSingleDatabase({
179
- apiClient: props.apiClient,
180
- projectId: props.projectId,
181
- branchId,
182
- database: props.database,
183
- });
184
- const { data } = await props.apiClient.getProjectBranchDataApi(props.projectId, branchId, database);
185
- // Drop available_schemas from json/yaml output (not part of the public surface).
186
- const { available_schemas: _ignored, ...publicData } = data;
187
- // For table output, flatten db_schemas onto the top-level for column rendering.
188
- const tableRow = {
189
- url: publicData.url,
190
- status: publicData.status,
191
- db_schemas: (publicData.settings?.db_schemas ?? []).join(", "),
192
- };
193
- if (props.output === "json" || props.output === "yaml") {
194
- writer(props).end(publicData, {
195
- fields: ["url", "status", "settings"],
196
- });
197
- return;
198
- }
199
- writer(props).end(tableRow, { fields: GET_FIELDS });
169
+ const branchId = await branchIdFromProps(props);
170
+ const database = await resolveSingleDatabase({
171
+ apiClient: props.apiClient,
172
+ projectId: props.projectId,
173
+ branchId,
174
+ database: props.database
175
+ });
176
+ const { data } = await props.apiClient.getProjectBranchDataApi(props.projectId, branchId, database);
177
+ const { available_schemas: _ignored, ...publicData } = data;
178
+ const tableRow = {
179
+ url: publicData.url,
180
+ status: publicData.status,
181
+ db_schemas: (publicData.settings?.db_schemas ?? []).join(", ")
182
+ };
183
+ if (props.output === "json" || props.output === "yaml") {
184
+ writer(props).end(publicData, { fields: [
185
+ "url",
186
+ "status",
187
+ "settings"
188
+ ] });
189
+ return;
190
+ }
191
+ writer(props).end(tableRow, { fields: GET_FIELDS });
200
192
  };
201
193
  const update = async (props) => {
202
- const branchId = await branchIdFromProps(props);
203
- const database = await resolveSingleDatabase({
204
- apiClient: props.apiClient,
205
- projectId: props.projectId,
206
- branchId,
207
- database: props.database,
208
- });
209
- const userSettings = buildSettings(props);
210
- if (!userSettings) {
211
- throw new Error("No settings flags provided. Pass at least one setting flag to update, or use `data-api refresh-schema` to refresh the schema cache without changing settings.");
212
- }
213
- let settings;
214
- if (props.replace) {
215
- settings = userSettings;
216
- }
217
- else {
218
- let current;
219
- try {
220
- const { data } = await props.apiClient.getProjectBranchDataApi(props.projectId, branchId, database);
221
- current = data.settings ?? undefined;
222
- }
223
- catch (err) {
224
- if (isNeonApiError(err) && err.status === 404) {
225
- throw new Error(`Data API is not provisioned for ${database} on branch ${branchId}. Run \`${getCliName()} data-api create\` first.`);
226
- }
227
- throw err;
228
- }
229
- if (!current) {
230
- throw new Error(`Could not read current Data API settings for ${database} on branch ${branchId}. Retry, or pass --replace to overwrite.`);
231
- }
232
- settings = { ...current, ...(userSettings ?? {}) };
233
- }
234
- const body = {};
235
- if (settings)
236
- body.settings = settings;
237
- try {
238
- await retryOnLock(() => props.apiClient.updateProjectBranchDataApi(props.projectId, branchId, database, body));
239
- }
240
- catch (err) {
241
- if (isNeonApiError(err) && err.status === 404) {
242
- throw new Error(`Data API is not provisioned for ${database} on branch ${branchId}. Run \`${getCliName()} data-api create\` first.`);
243
- }
244
- throw err;
245
- }
246
- log.info(`Data API settings updated for ${database} on branch ${branchId}`);
194
+ const branchId = await branchIdFromProps(props);
195
+ const database = await resolveSingleDatabase({
196
+ apiClient: props.apiClient,
197
+ projectId: props.projectId,
198
+ branchId,
199
+ database: props.database
200
+ });
201
+ const userSettings = buildSettings(props);
202
+ if (!userSettings) throw new Error("No settings flags provided. Pass at least one setting flag to update, or use `data-api refresh-schema` to refresh the schema cache without changing settings.");
203
+ let settings;
204
+ if (props.replace) settings = userSettings;
205
+ else {
206
+ let current;
207
+ try {
208
+ const { data } = await props.apiClient.getProjectBranchDataApi(props.projectId, branchId, database);
209
+ current = data.settings ?? void 0;
210
+ } catch (err) {
211
+ if (isNeonApiError(err) && err.status === 404) throw new Error(`Data API is not provisioned for ${database} on branch ${branchId}. Run \`${getCliName()} data-api create\` first.`);
212
+ throw err;
213
+ }
214
+ if (!current) throw new Error(`Could not read current Data API settings for ${database} on branch ${branchId}. Retry, or pass --replace to overwrite.`);
215
+ settings = {
216
+ ...current,
217
+ ...userSettings ?? {}
218
+ };
219
+ }
220
+ const body = {};
221
+ if (settings) body.settings = settings;
222
+ try {
223
+ await retryOnLock(() => props.apiClient.updateProjectBranchDataApi(props.projectId, branchId, database, body));
224
+ } catch (err) {
225
+ if (isNeonApiError(err) && err.status === 404) throw new Error(`Data API is not provisioned for ${database} on branch ${branchId}. Run \`${getCliName()} data-api create\` first.`);
226
+ throw err;
227
+ }
228
+ log.info(`Data API settings updated for ${database} on branch ${branchId}`);
247
229
  };
248
230
  const refreshSchema = async (props) => {
249
- const branchId = await branchIdFromProps(props);
250
- const database = await resolveSingleDatabase({
251
- apiClient: props.apiClient,
252
- projectId: props.projectId,
253
- branchId,
254
- database: props.database,
255
- });
256
- try {
257
- await retryOnLock(() => props.apiClient.updateProjectBranchDataApi(props.projectId, branchId, database, {}));
258
- }
259
- catch (err) {
260
- if (isNeonApiError(err) && err.status === 404) {
261
- throw new Error(`Data API is not provisioned for ${database} on branch ${branchId}. Run \`${getCliName()} data-api create\` first.`);
262
- }
263
- throw err;
264
- }
265
- log.info(`Data API schema cache refreshed for ${database} on branch ${branchId}`);
231
+ const branchId = await branchIdFromProps(props);
232
+ const database = await resolveSingleDatabase({
233
+ apiClient: props.apiClient,
234
+ projectId: props.projectId,
235
+ branchId,
236
+ database: props.database
237
+ });
238
+ try {
239
+ await retryOnLock(() => props.apiClient.updateProjectBranchDataApi(props.projectId, branchId, database, {}));
240
+ } catch (err) {
241
+ if (isNeonApiError(err) && err.status === 404) throw new Error(`Data API is not provisioned for ${database} on branch ${branchId}. Run \`${getCliName()} data-api create\` first.`);
242
+ throw err;
243
+ }
244
+ log.info(`Data API schema cache refreshed for ${database} on branch ${branchId}`);
266
245
  };
267
246
  const deleteDataApi = async (props) => {
268
- const branchId = await branchIdFromProps(props);
269
- const database = await resolveSingleDatabase({
270
- apiClient: props.apiClient,
271
- projectId: props.projectId,
272
- branchId,
273
- database: props.database,
274
- });
275
- try {
276
- await retryOnLock(() => props.apiClient.deleteProjectBranchDataApi(props.projectId, branchId, database));
277
- }
278
- catch (err) {
279
- if (isNeonApiError(err) && err.status === 404) {
280
- throw new Error(`Data API is not provisioned for ${database} on branch ${branchId}.`);
281
- }
282
- throw err;
283
- }
284
- log.info(`Data API deleted for ${database} on branch ${branchId}`);
247
+ const branchId = await branchIdFromProps(props);
248
+ const database = await resolveSingleDatabase({
249
+ apiClient: props.apiClient,
250
+ projectId: props.projectId,
251
+ branchId,
252
+ database: props.database
253
+ });
254
+ try {
255
+ await retryOnLock(() => props.apiClient.deleteProjectBranchDataApi(props.projectId, branchId, database));
256
+ } catch (err) {
257
+ if (isNeonApiError(err) && err.status === 404) throw new Error(`Data API is not provisioned for ${database} on branch ${branchId}.`);
258
+ throw err;
259
+ }
260
+ log.info(`Data API deleted for ${database} on branch ${branchId}`);
285
261
  };
262
+ //#endregion
263
+ export { builder, command, data_api_exports, describe, handler };