neon 8.11.0 → 8.11.2

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 (106) hide show
  1. package/README.md +1 -1
  2. package/dist/_chunks/api-GbEaBZJ5.js +388 -0
  3. package/dist/_chunks/api_keys-CNnnugbQ.js +281 -0
  4. package/dist/_chunks/ask-DVwy0eUL.js +155 -0
  5. package/dist/_chunks/auth-CIUtXByB.js +495 -0
  6. package/dist/_chunks/bootstrap-wPZWa1sT.js +499 -0
  7. package/dist/_chunks/branches-BNa1xX1L.js +460 -0
  8. package/dist/_chunks/bucket-BCdryTkD.js +409 -0
  9. package/dist/_chunks/checkout-CXIOydqZ.js +348 -0
  10. package/dist/_chunks/claim-DqAvAvDm.js +473 -0
  11. package/dist/_chunks/config-BH_qRHiG.js +1113 -0
  12. package/dist/_chunks/connection_string-DB4awPzZ.js +154 -0
  13. package/dist/_chunks/credentials-BSjE9fRR.js +146 -0
  14. package/dist/_chunks/data_api-Djxj5ZQD.js +263 -0
  15. package/dist/_chunks/databases-Dok4wru7.js +84 -0
  16. package/dist/_chunks/deploy-D7B0Xfjg.js +33 -0
  17. package/dist/_chunks/dev-CSvxAecE.js +945 -0
  18. package/dist/_chunks/diff-DhxxbdQE.js +178 -0
  19. package/dist/_chunks/docs-CrVybkTP.js +197 -0
  20. package/dist/_chunks/env-5HS5qQGd.js +284 -0
  21. package/dist/_chunks/feedback-CMayyTa8.js +88 -0
  22. package/dist/_chunks/functions-Q0zuvtnk.js +464 -0
  23. package/dist/_chunks/git-H32TNt6M.js +356 -0
  24. package/dist/_chunks/init-BkA6RilG.js +111 -0
  25. package/dist/_chunks/inspect-g0wekylj.js +90 -0
  26. package/dist/_chunks/ip_allow-5lLFvIuE.js +106 -0
  27. package/dist/_chunks/link-BgtkOBws.js +936 -0
  28. package/dist/_chunks/logs-DWkpjzIH.js +291 -0
  29. package/dist/_chunks/mcp-Bo-7TKc7.js +253 -0
  30. package/dist/_chunks/neon_auth-CBs1_3qu.js +822 -0
  31. package/dist/_chunks/open-CX3BT3Tp.js +33 -0
  32. package/dist/_chunks/operations-D4I-AxVs.js +37 -0
  33. package/dist/_chunks/orgs-xGfANwHQ.js +52 -0
  34. package/dist/_chunks/plugins-DqD7BDO1.js +169 -0
  35. package/dist/_chunks/profile-yXOiKk9R.js +672 -0
  36. package/dist/_chunks/projects-BwI2Uo0z.js +439 -0
  37. package/dist/_chunks/psql-BM-doe8e.js +64 -0
  38. package/dist/_chunks/realtime-BRqIyGR-.js +79 -0
  39. package/dist/_chunks/roles-B4w3YT_7.js +79 -0
  40. package/dist/_chunks/set_context-DbrwoImy.js +38 -0
  41. package/dist/_chunks/skills-DyiBXKS3.js +255 -0
  42. package/dist/_chunks/snapshots-RJBzW8GM.js +338 -0
  43. package/dist/_chunks/status-DV8Z2kw3.js +44 -0
  44. package/dist/_chunks/triggers-BrRo1z4b.js +302 -0
  45. package/dist/_chunks/user-dlOGXbX9.js +60 -0
  46. package/dist/_chunks/vpc_endpoints-CNb0YfMo.js +105 -0
  47. package/dist/auth_recovery.js +1 -1
  48. package/dist/commands/api.js +1 -388
  49. package/dist/commands/api_keys.js +1 -281
  50. package/dist/commands/ask.js +1 -155
  51. package/dist/commands/auth.js +1 -495
  52. package/dist/commands/bootstrap.js +1 -499
  53. package/dist/commands/branches.js +1 -460
  54. package/dist/commands/bucket.js +1 -409
  55. package/dist/commands/checkout.js +1 -348
  56. package/dist/commands/claim.js +1 -473
  57. package/dist/commands/config.js +1 -1113
  58. package/dist/commands/connection_string.js +1 -154
  59. package/dist/commands/credentials.js +1 -146
  60. package/dist/commands/data_api.js +1 -263
  61. package/dist/commands/databases.js +1 -84
  62. package/dist/commands/deploy.js +1 -33
  63. package/dist/commands/dev.js +1 -945
  64. package/dist/commands/diff.js +1 -178
  65. package/dist/commands/docs.js +1 -197
  66. package/dist/commands/env.js +1 -284
  67. package/dist/commands/feedback.js +1 -88
  68. package/dist/commands/functions.js +1 -464
  69. package/dist/commands/functions_new.js +6 -6
  70. package/dist/commands/git.js +1 -356
  71. package/dist/commands/index.js +45 -45
  72. package/dist/commands/init.js +1 -111
  73. package/dist/commands/inspect.js +1 -90
  74. package/dist/commands/ip_allow.js +1 -106
  75. package/dist/commands/link.js +1 -936
  76. package/dist/commands/logs.js +1 -291
  77. package/dist/commands/mcp.js +1 -253
  78. package/dist/commands/neon_auth.js +1 -822
  79. package/dist/commands/open.js +1 -33
  80. package/dist/commands/operations.js +1 -37
  81. package/dist/commands/orgs.js +1 -52
  82. package/dist/commands/plugins.js +1 -169
  83. package/dist/commands/profile.js +1 -672
  84. package/dist/commands/projects.js +1 -439
  85. package/dist/commands/psql.js +1 -64
  86. package/dist/commands/realtime.js +1 -79
  87. package/dist/commands/roles.js +1 -79
  88. package/dist/commands/set_context.js +1 -38
  89. package/dist/commands/skills.js +1 -255
  90. package/dist/commands/snapshots.js +1 -338
  91. package/dist/commands/status.js +1 -44
  92. package/dist/commands/subscribe.js +1 -1
  93. package/dist/commands/triggers.js +1 -302
  94. package/dist/commands/user.js +1 -60
  95. package/dist/commands/vpc_endpoints.js +1 -105
  96. package/dist/functions/registry.js +29 -151
  97. package/dist/functions/source.js +42 -2
  98. package/dist/index.js +1 -1
  99. package/dist/init/auth.js +3 -3
  100. package/dist/init/link.js +2 -2
  101. package/dist/init/run.js +3 -3
  102. package/dist/init/tooling.js +3 -3
  103. package/dist/mcp/mint.js +1 -1
  104. package/dist/test_utils/registry.js +1 -2
  105. package/dist/utils/package_manager.js +1 -0
  106. package/package.json +4 -2
@@ -1,348 +1 @@
1
- import { t as __exportAll } from "../_chunks/rolldown-runtime-8H4AJuhK.js";
2
- import { isCi } from "../env.js";
3
- import { log } from "../log.js";
4
- import { isNeonApiError } from "../api.js";
5
- import { applyContext, contextBranch, readContextFile } from "../context.js";
6
- import { isClaimableEnvTarget } from "../claimable/state.js";
7
- import { getCliName } from "../utils/cli_name.js";
8
- import { loadEnvFileIntoProcess } from "../env_file.js";
9
- import { createBranch, pickBranchInteractively } from "../utils/branch_picker.js";
10
- import { looksLikeBranchId } from "../utils/formats.js";
11
- import { fillSingleProject, listAllProjectBranches } from "../utils/enrichers.js";
12
- import { buildCheckoutEvent, readGitContext } from "../utils/git.js";
13
- import { buildHookBranch, loadHookConfig, resolveHookEnv, runCheckoutAfterHook, runCheckoutBeforeHook, runCreateAfterHook, runCreateBeforeHook } from "../utils/hooks.js";
14
- import { autoPullEnvAfterPin } from "./env.js";
15
- import { applyPolicyOnCreate, createBranchFromPolicyOnCheckout, envFlag } from "./config.js";
16
- import { handler as handler$1 } from "./link.js";
17
- import chalk from "chalk";
18
- import prompts from "prompts";
19
- //#region src/commands/checkout.ts
20
- var checkout_exports = /* @__PURE__ */ __exportAll({
21
- builder: () => builder,
22
- command: () => command,
23
- describe: () => describe,
24
- formatCheckoutPolicyFailure: () => formatCheckoutPolicyFailure,
25
- handler: () => handler
26
- });
27
- const command = "checkout [id|name]";
28
- const describe = "Pin a branch in the local context (.neon) so subsequent commands target it";
29
- const formatCheckoutPolicyFailure = (opts) => {
30
- const cli = getCliName();
31
- const envArg = opts.env ? ` --env ${opts.env}` : "";
32
- return [
33
- `Branch ${opts.branchName} (${opts.branchId}) was created and checked out, but applying neon.ts to it failed: ${opts.failure}`,
34
- `The branch is usable but does not match the policy, and \`${cli} checkout\` never reconciles a branch that already exists.`,
35
- `Fix the cause above, then run \`${cli} deploy --update-existing${envArg}\` to apply the policy to it — or, if your policy only configures new branches (keyed on \`!branch.exists\`), delete the branch and check it out again: \`${cli} branches delete ${opts.branchName}\` then \`${cli} checkout ${opts.branchName} --create${envArg}\`.`
36
- ].join("\n");
37
- };
38
- const builder = (argv) => argv.usage("$0 checkout [id|name] [options]").positional("id", {
39
- describe: "Branch name or id to check out. Omit to pick interactively from the list of branches.",
40
- type: "string"
41
- }).options({
42
- "project-id": {
43
- describe: "Project ID",
44
- type: "string"
45
- },
46
- "env-pull": {
47
- describe: "Pull the branch's Neon env vars (DATABASE_URL, …) into a local .env after checkout. On by default; use --no-env-pull to skip (e.g. when injecting env at runtime with `neon-env run` / `neon dev`).",
48
- type: "boolean",
49
- default: true
50
- },
51
- create: {
52
- describe: "Create the named branch if it does not exist, then check it out",
53
- type: "boolean",
54
- default: false
55
- },
56
- ...envFlag,
57
- env: {
58
- ...envFlag.env,
59
- describe: envFlag.env.describe + " Used when this checkout creates a branch from neon.ts; ignored for an existing branch."
60
- }
61
- }).example([
62
- ["$0 checkout", "Pick a branch interactively from the project in the closest .neon file"],
63
- ["$0 checkout main", "Pin the branch named \"main\" in the closest .neon file"],
64
- ["$0 checkout dev --create", "Create and pin a missing branch named dev"],
65
- ["$0 checkout feat --create --env .env.local", "Create feat from neon.ts, loading Function env from .env.local first"],
66
- ["$0 checkout br-cool-snow-12345678 --project-id project-id-123", "Pin a branch by id for an explicit project"]
67
- ]);
68
- const handler = async (props) => {
69
- const previousBranch = contextBranch(readContextFile(props.contextFile));
70
- if (previousBranch) log.info("%s Currently on branch %s", chalk.dim("→"), chalk.cyan.bold(previousBranch));
71
- if (props.create && !props.id?.trim()) throw new Error(`No branch specified. Pass a branch name with --create (e.g. \`${getCliName()} checkout dev --create\`).`);
72
- const projectId = await resolveProjectId(props);
73
- if (props.create && props.env) try {
74
- loadEnvFileIntoProcess(props.env);
75
- } catch (err) {
76
- log.debug("checkout: could not preload --env for hook discovery (continuing): %s", err instanceof Error ? err.message : String(err));
77
- }
78
- const cwd = process.cwd();
79
- const git = readGitContext(cwd);
80
- const event = buildCheckoutEvent(git, props.id);
81
- const config = await loadHookConfig(cwd, props.contextFile);
82
- const hooks = config?.experimental?.hooks;
83
- if (props.id) {
84
- const renamed = await runCheckoutBeforeHook({
85
- hooks,
86
- event,
87
- git,
88
- cwd
89
- });
90
- if (renamed && renamed !== props.id) {
91
- log.info("%s checkout.before hook mapped %s → %s", chalk.dim("→"), chalk.cyan(props.id), chalk.cyan.bold(renamed));
92
- props.id = renamed;
93
- }
94
- }
95
- const orgRead = isClaimableEnvTarget({
96
- apiHost: props.apiHost,
97
- contextFile: props.contextFile,
98
- configDir: props.configDir ?? ""
99
- }) ? void 0 : resolveOrgId(props, projectId);
100
- orgRead?.catch(() => void 0);
101
- const { branchId, branchName, created, policyApplied, policyFailure } = await resolveBranchId(props, projectId, {
102
- hooks,
103
- git,
104
- event,
105
- cwd
106
- });
107
- const orgId = await (orgRead ?? resolveOrgId(props, projectId));
108
- applyContext(props.contextFile, {
109
- projectId,
110
- ...orgId ? { orgId } : {},
111
- branch: branchName
112
- });
113
- log.info("Checked out branch %s on project %s%s. Updated %s.", branchId, projectId, orgId ? ` (org ${orgId})` : "", props.contextFile);
114
- const failure = created && !policyApplied ? await applyPolicyOrDescribeFailure({
115
- projectId,
116
- branchId,
117
- branchName,
118
- contextFile: props.contextFile,
119
- ...props.apiKey ? { apiKey: props.apiKey } : {},
120
- ...props.apiHost ? { apiHost: props.apiHost } : {},
121
- ...props.color !== void 0 ? { color: props.color } : {},
122
- ...props.env ? { env: props.env } : {}
123
- }) : policyFailure;
124
- await autoPullEnvAfterPin({
125
- ...props,
126
- projectId,
127
- branch: branchId,
128
- envPull: props.envPull
129
- }, {
130
- branchId,
131
- branchName,
132
- usedDefault: false
133
- });
134
- const needsCreateAfter = created && hooks?.create?.after;
135
- if (config && (hooks?.checkout?.after || needsCreateAfter)) {
136
- const env = await resolveHookEnv(config, {
137
- projectId,
138
- branch: branchId,
139
- ...props.apiKey ? { apiKey: props.apiKey } : {},
140
- ...props.apiHost ? { apiHost: props.apiHost } : {}
141
- });
142
- if (env) {
143
- const branch = await buildHookBranch({
144
- apiClient: props.apiClient,
145
- projectId,
146
- branchId,
147
- created
148
- });
149
- if (hooks?.checkout?.after) await runCheckoutAfterHook({
150
- hooks,
151
- branch,
152
- env,
153
- git,
154
- event,
155
- cwd
156
- });
157
- if (needsCreateAfter) await runCreateAfterHook({
158
- hooks,
159
- branch,
160
- env,
161
- git,
162
- event,
163
- cwd
164
- });
165
- }
166
- }
167
- if (failure) throw new Error(formatCheckoutPolicyFailure({
168
- branchName,
169
- branchId,
170
- failure,
171
- ...props.env ? { env: props.env } : {}
172
- }));
173
- };
174
- /**
175
- * Apply the policy to a branch `checkout` just created bare, returning the failure message
176
- * instead of throwing it. The branch and the context pin already stand at this point, so a
177
- * failed apply must not abort the rest of the checkout — the handler reports it at the end.
178
- */
179
- const applyPolicyOrDescribeFailure = async (props) => {
180
- try {
181
- await applyPolicyOnCreate(props);
182
- return;
183
- } catch (err) {
184
- return err instanceof Error ? err.message : String(err);
185
- }
186
- };
187
- const resolveBranchId = async (props, projectId, hookCtx) => {
188
- const branches = await listAllProjectBranches(props.apiClient, projectId);
189
- if (!props.id) {
190
- const picked = await pickBranchInteractively(branches, {
191
- message: "Which branch would you like to check out?",
192
- nonInteractiveMessage: `No branch specified. Pass a branch name or id (e.g. \`${getCliName()} checkout main\`), or run interactively to pick one from a list.`
193
- });
194
- if (picked.kind === "existing") {
195
- const existing = branches.find((b) => b.id === picked.branchId);
196
- return {
197
- branchId: picked.branchId,
198
- branchName: existing?.name ?? picked.branchId,
199
- created: false,
200
- policyApplied: false
201
- };
202
- }
203
- return createCheckoutBranch(props, projectId, picked.name, branches, hookCtx);
204
- }
205
- const ref = props.id;
206
- if (looksLikeBranchId(ref)) {
207
- const byId = branches.find((b) => b.id === ref);
208
- if (byId) return {
209
- branchId: byId.id,
210
- branchName: byId.name ?? byId.id,
211
- created: false,
212
- policyApplied: false
213
- };
214
- throw new Error(notFoundMessage(ref, branches));
215
- }
216
- const byName = branches.find((b) => b.name === ref);
217
- if (byName) return {
218
- branchId: byName.id,
219
- branchName: byName.name ?? byName.id,
220
- created: false,
221
- policyApplied: false
222
- };
223
- if (props.create) return createCheckoutBranch(props, projectId, ref, branches, hookCtx);
224
- const missingName = notFoundMessage(ref, branches, { suggestCreate: true });
225
- if (isCi() || !process.stdout.isTTY) throw new Error(missingName);
226
- log.info(missingName);
227
- const { create } = await prompts({
228
- type: "confirm",
229
- name: "create",
230
- message: `Branch "${ref}" does not exist. Create it now?`,
231
- initial: true
232
- });
233
- if (!create) throw new Error(`Aborted: branch "${ref}" was not found and not created.`);
234
- return createCheckoutBranch(props, projectId, ref, branches, hookCtx);
235
- };
236
- /**
237
- * Create the branch to check out. When a `neon.ts` exists, route through the policy-driven
238
- * create so the new branch comes up branched from the policy's `parent` and configured with
239
- * its declared TTL / compute / services (evaluated as a *new* branch). Otherwise fall back to
240
- * a bare branch off the default — the handler then applies the policy (a no-op with no
241
- * `neon.ts`).
242
- */
243
- const createCheckoutBranch = async (props, projectId, name, branches, hookCtx) => {
244
- await runCreateBeforeHook({
245
- hooks: hookCtx.hooks,
246
- branchName: name,
247
- git: hookCtx.git,
248
- event: hookCtx.event,
249
- cwd: hookCtx.cwd
250
- });
251
- const fromPolicy = await createBranchFromPolicyOnCheckout({
252
- projectId,
253
- branchName: name,
254
- contextFile: props.contextFile,
255
- ...props.apiKey ? { apiKey: props.apiKey } : {},
256
- ...props.apiHost ? { apiHost: props.apiHost } : {},
257
- ...props.color !== void 0 ? { color: props.color } : {},
258
- ...props.env ? { env: props.env } : {}
259
- });
260
- if (fromPolicy) return {
261
- branchId: fromPolicy.branchId,
262
- branchName: name,
263
- created: true,
264
- policyApplied: true,
265
- ...fromPolicy.policyFailure ? { policyFailure: fromPolicy.policyFailure } : {}
266
- };
267
- return {
268
- branchId: await createBranch(props.apiClient, projectId, name, branches),
269
- branchName: name,
270
- created: true,
271
- policyApplied: false
272
- };
273
- };
274
- const notFoundMessage = (ref, branches, opts) => `Branch ${ref} not found.${opts?.suggestCreate ? " Pass --create to create it." : ""}\nAvailable branches: ${branches.map((b) => b.name).join(", ")}`;
275
- /**
276
- * Resolve the org id to heal into the context file.
277
- *
278
- * Prefer an org id we already know (from `--org-id`, the `.neon` file, or a
279
- * freshly-run `link`). Otherwise look it up from the project itself so the
280
- * `.neon` file ends up with an accurate `orgId` even when it was previously
281
- * missing. Projects on a personal account have no org; in that case (or if the
282
- * lookup fails for a non-auth reason) we return `undefined` and simply omit the
283
- * field rather than failing the checkout.
284
- */
285
- const resolveOrgId = async (props, projectId) => {
286
- if (props.orgId) return props.orgId;
287
- try {
288
- const { data } = await props.apiClient.getProject(projectId);
289
- return data.project.org_id ?? void 0;
290
- } catch (err) {
291
- if (isNeonApiError(err) && err.status === 401) throw err;
292
- log.debug("checkout: could not resolve org id for project %s: %s", projectId, err instanceof Error ? err.message : String(err));
293
- return;
294
- }
295
- };
296
- /**
297
- * Resolve the project id `checkout` should target.
298
- *
299
- * `props.projectId` is already populated from the `--project-id` flag or the
300
- * closest `.neon` file (via the global `enrichFromContext` middleware). When
301
- * it's still missing we try to auto-detect a single project (same behaviour as
302
- * `branches` / `connection-string`). If that fails we surface a telling error
303
- * and, in an interactive terminal, offer to run `neonctl link` in the current
304
- * folder so the user can pick a project/branch without having to re-run the
305
- * command by hand.
306
- */
307
- const resolveProjectId = async (props) => {
308
- if (props.projectId) return props.projectId;
309
- const autoDetected = await tryAutoDetectProject(props);
310
- if (autoDetected) return autoDetected;
311
- const missingProjectMessage = `Could not determine which Neon project to check out a branch from. Provide one via the --project-id flag or a .neon file (created by \`${getCliName()} link\` / \`${getCliName()} set-context\`).`;
312
- if (isCi() || !process.stdout.isTTY) throw new Error(missingProjectMessage);
313
- log.info(missingProjectMessage);
314
- const { runLink } = await prompts({
315
- type: "confirm",
316
- name: "runLink",
317
- message: `Run \`${getCliName()} link\` in the current folder to pick a project now?`,
318
- initial: true
319
- });
320
- if (!runLink) throw new Error("Aborted: no project selected. Re-run with --project-id or link a project first.");
321
- await handler$1({
322
- ...props,
323
- yes: false,
324
- clear: false,
325
- checks: true
326
- });
327
- const linked = readContextFile(props.contextFile);
328
- if (!linked.projectId) throw new Error(`Linking did not produce a project id. Re-run \`${getCliName()} checkout\` once the directory is linked.`);
329
- if (linked.orgId) props.orgId = linked.orgId;
330
- return linked.projectId;
331
- };
332
- /**
333
- * Best-effort single-project auto-detection. Returns the project id when the
334
- * API key maps to exactly one project, or `undefined` when the project can't be
335
- * determined unambiguously (zero or multiple projects) so the caller can fall
336
- * back to the interactive `link` flow.
337
- */
338
- const tryAutoDetectProject = async (props) => {
339
- try {
340
- return (await fillSingleProject(props)).projectId;
341
- } catch (err) {
342
- if (isNeonApiError(err)) throw err;
343
- log.debug("checkout: could not auto-detect a single project: %s", err instanceof Error ? err.message : String(err));
344
- return;
345
- }
346
- };
347
- //#endregion
348
- export { builder, command, describe, formatCheckoutPolicyFailure, handler, checkout_exports as t };
1
+ export { t as builder, r as command, i as describe, a as formatCheckoutPolicyFailure, o as handler } from "../_chunks/checkout-CXIOydqZ.js";