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
@@ -0,0 +1,38 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { log } from "../log.js";
3
+ import { applyContext } from "../context.js";
4
+ import { getCliName } from "../utils/cli_name.js";
5
+ //#region src/commands/set_context.ts
6
+ var set_context_exports = /* @__PURE__ */ __exportAll({
7
+ builder: () => builder,
8
+ command: () => command,
9
+ describe: () => describe,
10
+ handler: () => handler
11
+ });
12
+ const command = "set-context";
13
+ const describe = `Deprecated: use \`${getCliName()} link\`. Set the .neon context (raw write).`;
14
+ const builder = (argv) => argv.usage("$0 set-context [options]").options({
15
+ "project-id": {
16
+ describe: "Project ID",
17
+ type: "string"
18
+ },
19
+ "org-id": {
20
+ describe: "Organization ID",
21
+ type: "string"
22
+ },
23
+ "branch-id": {
24
+ describe: "Branch ID",
25
+ type: "string"
26
+ }
27
+ });
28
+ const handler = (props) => {
29
+ log.warning(`\`${getCliName()} set-context\` is deprecated and will be removed in a future release. Use \`${getCliName()} link\` instead — it verifies inputs and writes a complete context (or \`${getCliName()} link --no-checks --org-id … --project-id … --branch …\` for an offline write).`);
30
+ const context = {
31
+ projectId: props.projectId,
32
+ orgId: props.orgId,
33
+ branchId: props.branchId
34
+ };
35
+ applyContext(props.contextFile, context);
36
+ };
37
+ //#endregion
38
+ export { set_context_exports as a, handler as i, command as n, describe as r, builder as t };
@@ -0,0 +1,255 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { log } from "../log.js";
3
+ import { recordCommandSuccessExtras } from "../analytics.js";
4
+ import { helpCsv, helpEpilogue } from "../utils/help_text.js";
5
+ import { getAgentDisplayName } from "../mcp/agents.js";
6
+ import "../init/agents.js";
7
+ import { mappedSkillsAgentNames, skillsInstallableAgents } from "../skills/targets.js";
8
+ import { writer } from "../writer.js";
9
+ import { noPassthrough } from "../utils/flags.js";
10
+ import { AGENT_SKILLS_SKIP_MESSAGE } from "../init/copy.js";
11
+ import { canPickAgentsInteractively, skippableAgentPicker } from "../utils/agent_picker.js";
12
+ import { skillsHelpValues, skillsYesHelp } from "../skills/catalog.js";
13
+ import { confirmSkillsUpdate } from "../skills/wizard.js";
14
+ import { assertSkillsCanRun, resolveSkillsPlan } from "../skills/plan.js";
15
+ import { assertSkillsNode, neonSkillsRetryCommand, neonSkillsUpdateRetryCommand, runSkillsCli, skillsAddArgs, skillsMetadata, skillsUpdateArgs, skillsUpdateDetail, skillsUpdateHadNothing } from "../skills/run.js";
16
+ //#region src/commands/skills.ts
17
+ var skills_exports = /* @__PURE__ */ __exportAll({
18
+ aliases: () => aliases,
19
+ builder: () => builder,
20
+ command: () => command,
21
+ describe: () => describe,
22
+ handler: () => handler,
23
+ installSkills: () => installSkills,
24
+ reportSkillsInstall: () => reportSkillsInstall,
25
+ skillsInstallError: () => skillsInstallError
26
+ });
27
+ const scopeLabel = (scope) => scope === "project" ? "this directory" : "user-level";
28
+ const coerceAgents = (value) => {
29
+ if (value === void 0) return [];
30
+ const list = Array.isArray(value) ? value : [value];
31
+ if (list.length === 0) throw new Error("--agent needs a value. Pass one, or omit the flag entirely.");
32
+ return list.map((item) => {
33
+ if (typeof item !== "string" || item.trim() === "") throw new Error("--agent needs a value. Pass one, or omit the flag entirely.");
34
+ return item;
35
+ });
36
+ };
37
+ const coerceSkills = (value) => {
38
+ if (value === void 0) return [];
39
+ const list = Array.isArray(value) ? value : [value];
40
+ if (list.length === 0) throw new Error("--skill needs a value. Pass one, or omit the flag entirely.");
41
+ return list.map((item) => {
42
+ if (typeof item !== "string" || item.trim() === "") throw new Error("--skill needs a value. Pass one, or omit the flag entirely.");
43
+ return item;
44
+ });
45
+ };
46
+ const command = "skills";
47
+ const aliases = ["skill"];
48
+ const describe = "Install Neon agent skills into coding agents";
49
+ const builder = (argv) => argv.usage("$0 skills [command] [options]").command("update", "Update installed skills to the latest versions", (yargs) => yargs.usage("$0 skills update [options]").options({
50
+ yes: { describe: "Skip the confirm prompt" },
51
+ global: {
52
+ type: "boolean",
53
+ default: false,
54
+ describe: "Update user-level skills (skills CLI -g). Default is this directory"
55
+ }
56
+ }).example("$0 skills update", "Interactive: confirm, then update skills in this directory").example("$0 skills update -y", "Update skills in this directory without prompting").example("$0 skills update --global -y", "Update user-level skills").strict().hide("agent").hide("skill").check((args) => {
57
+ noPassthrough("skills update")(args);
58
+ const agents = args.agent;
59
+ if (Array.isArray(agents) && agents.length > 0) throw new Error("neon skills update does not take --agent. It refreshes every installed skill in this directory (or --global).");
60
+ const skills = args.skill;
61
+ if (Array.isArray(skills) && skills.length > 0) throw new Error("neon skills update does not take --skill. It refreshes every installed skill in this directory (or --global).");
62
+ return true;
63
+ }), (args) => updateHandler(args)).options({
64
+ yes: {
65
+ alias: "y",
66
+ type: "boolean",
67
+ default: false,
68
+ describe: "Skip prompts. Detected agents (project folders, else the host CLI agent). --global uses installed apps, else the host CLI agent"
69
+ },
70
+ global: {
71
+ type: "boolean",
72
+ default: false,
73
+ describe: "Install user-level skills (skills CLI -g). Default is this directory"
74
+ },
75
+ agent: {
76
+ alias: "a",
77
+ type: "array",
78
+ string: true,
79
+ describe: "Coding agent to install into (repeatable). Skips the agent picker. Values listed below",
80
+ coerce: coerceAgents
81
+ },
82
+ skill: {
83
+ alias: "s",
84
+ type: "array",
85
+ string: true,
86
+ describe: "Skill to install (repeatable). Skips the skill picker. Does not select agents. Values listed below",
87
+ coerce: coerceSkills
88
+ }
89
+ }).example("$0 skills", "Interactive: this directory, then agents, then skills").example("$0 skills -y", "This directory, detected agents (project folders, else the host CLI agent), the default skills").example("$0 skills -y -s neon -s neon-ai-gateway", "Named skills into detected agents").example("$0 skills -s neon -s neon-ai-gateway --agent cursor", "Named skills into a named agent").example("$0 skills --global", "Install user-level skills").epilogue(helpEpilogue(helpCsv("Supported agents", skillsInstallableAgents()), "Supported skills, by source repo:", skillsHelpValues(), skillsYesHelp())).strict().check(noPassthrough("skills"));
90
+ /**
91
+ * Plans and runs the skills install for every resolved source/invocation. No CLI-only
92
+ * concerns here (no `writer` table, no `recordCommandSuccessExtras`): a caller that only
93
+ * wants the outcome — `neon init` / `neon bootstrap` — gets it without rendering a table.
94
+ */
95
+ const installSkills = async (options) => {
96
+ assertSkillsNode();
97
+ const cwd = options.cwd ?? process.cwd();
98
+ const yes = options.yes === true;
99
+ const interactive = canPickAgentsInteractively() && !yes;
100
+ const plan = await resolveSkillsPlan({
101
+ global: options.global === true,
102
+ agents: options.agents ?? [],
103
+ skills: options.skills ?? [],
104
+ yes,
105
+ cwd,
106
+ interactive,
107
+ pickAgents: skippableAgentPicker(options.allowAgentSkip, AGENT_SKILLS_SKIP_MESSAGE)
108
+ });
109
+ const mapped = mappedSkillsAgentNames(plan.agents);
110
+ for (const agent of plan.skipped) log.warning("Skipping %s: no skills mapping.", getAgentDisplayName(agent));
111
+ const metadata = skillsMetadata("skills");
112
+ const rows = [];
113
+ const failed = [];
114
+ const scope = scopeLabel(plan.scope);
115
+ for (const invocation of plan.invocations) {
116
+ const skills = invocation.skills.join(", ");
117
+ const args = skillsAddArgs({
118
+ source: invocation.source,
119
+ skills: invocation.skills,
120
+ agents: mapped,
121
+ global: plan.scope === "global",
122
+ metadata
123
+ });
124
+ try {
125
+ await runSkillsCli({
126
+ args,
127
+ cwd
128
+ });
129
+ rows.push({
130
+ scope,
131
+ skills,
132
+ agents: mapped.join(", "),
133
+ status: "installed"
134
+ });
135
+ } catch (error) {
136
+ const message = error instanceof Error ? error.message : String(error);
137
+ rows.push({
138
+ scope,
139
+ skills,
140
+ agents: mapped.join(", "),
141
+ status: "failed",
142
+ error: "skills CLI failed"
143
+ });
144
+ failed.push({
145
+ label: skills,
146
+ message,
147
+ skills: invocation.skills
148
+ });
149
+ }
150
+ }
151
+ return {
152
+ scope: plan.scope,
153
+ agents: plan.agents,
154
+ rows,
155
+ failed
156
+ };
157
+ };
158
+ /** The exact error `neon skills` throws for a failed outcome, or `undefined` on success. */
159
+ const skillsInstallError = (outcome) => {
160
+ const { failed, rows, scope, agents } = outcome;
161
+ if (failed.length === 0) return;
162
+ const first = failed[0];
163
+ if (first === void 0) return /* @__PURE__ */ new Error("Failed to install Neon agent skills.");
164
+ const retry = neonSkillsRetryCommand({
165
+ skills: failed.flatMap((row) => row.skills),
166
+ agents,
167
+ global: scope === "global"
168
+ });
169
+ if (first.message.includes("needs npx (Node.js)") || first.message.includes("needs Node.js")) return new Error(first.message);
170
+ if (failed.length === rows.length) return /* @__PURE__ */ new Error(`${first.message}\nRetry with: ${retry}`);
171
+ return /* @__PURE__ */ new Error(`Failed to install Neon agent skills for: ${failed.map((row) => row.label).join(", ")}.\n${first.message}\nRetry with: ${retry}`);
172
+ };
173
+ /** Writes the results table and, on success, the "Wrote ... skills" line. Shared by `neon skills` and any in-process caller that wants the same human output. */
174
+ const reportSkillsInstall = (props, outcome) => {
175
+ const out = writer(props);
176
+ out.write(outcome.rows, {
177
+ fields: [
178
+ "scope",
179
+ "skills",
180
+ "agents",
181
+ "status",
182
+ "error"
183
+ ],
184
+ title: "Skills"
185
+ });
186
+ out.end();
187
+ if (outcome.failed.length === 0) log.info(outcome.scope === "project" ? "Wrote skills in this directory." : "Wrote user-level skills.");
188
+ };
189
+ const handler = async (props) => {
190
+ const outcome = await installSkills({
191
+ cwd: props.cwd,
192
+ yes: props.yes,
193
+ global: props.global,
194
+ agents: props.agent,
195
+ skills: props.skill
196
+ });
197
+ reportSkillsInstall(props, outcome);
198
+ const error = skillsInstallError(outcome);
199
+ if (error) throw error;
200
+ recordCommandSuccessExtras({ scope: outcome.scope });
201
+ };
202
+ const updateHandler = async (props) => {
203
+ assertSkillsNode();
204
+ const cwd = process.cwd();
205
+ const yes = props.yes === true;
206
+ const interactive = canPickAgentsInteractively() && !yes;
207
+ assertSkillsCanRun({
208
+ yes,
209
+ interactive,
210
+ action: "update"
211
+ });
212
+ const scope = props.global === true ? "global" : "project";
213
+ if (interactive) {
214
+ if (!await confirmSkillsUpdate({ scope })) {
215
+ log.info("Aborted. Nothing was written.");
216
+ return;
217
+ }
218
+ }
219
+ const rows = [];
220
+ const args = skillsUpdateArgs({ global: scope === "global" });
221
+ let failure;
222
+ try {
223
+ const result = await runSkillsCli({
224
+ args,
225
+ cwd
226
+ });
227
+ const output = `${result.stdout}\n${result.stderr}`;
228
+ rows.push({
229
+ scope: scopeLabel(scope),
230
+ status: skillsUpdateHadNothing(output) ? "none" : "updated",
231
+ detail: skillsUpdateDetail(output)
232
+ });
233
+ } catch (error) {
234
+ failure = error instanceof Error ? error.message : String(error);
235
+ rows.push({
236
+ scope: scopeLabel(scope),
237
+ status: "failed",
238
+ error: "skills CLI failed"
239
+ });
240
+ }
241
+ const out = writer(props);
242
+ out.write(rows, {
243
+ fields: [
244
+ "scope",
245
+ "status",
246
+ "detail",
247
+ "error"
248
+ ],
249
+ title: "Skills"
250
+ });
251
+ out.end();
252
+ if (failure !== void 0) throw new Error(failure.includes("needs npx (Node.js)") || failure.includes("needs Node.js") ? failure : `${failure}\nRetry with: ${neonSkillsUpdateRetryCommand(scope === "global")}`);
253
+ };
254
+ //#endregion
255
+ export { handler as a, skillsInstallError as c, describe as i, skills_exports as l, builder as n, installSkills as o, command as r, reportSkillsInstall as s, aliases as t };
@@ -0,0 +1,338 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { log } from "../log.js";
3
+ import { isNeonApiError, retryOnLock } from "../api.js";
4
+ import { writer } from "../writer.js";
5
+ import { looksLikeBranchId, looksLikeLSN, looksLikeSnapshotId, looksLikeTimestamp, toIso } from "../utils/formats.js";
6
+ import { branchIdResolve, fillSingleProject, resolveBranchRef } from "../utils/enrichers.js";
7
+ import { t as BRANCH_FIELDS } from "./branches-BNa1xX1L.js";
8
+ //#region src/commands/snapshots.ts
9
+ var snapshots_exports = /* @__PURE__ */ __exportAll({
10
+ SNAPSHOT_FIELDS: () => SNAPSHOT_FIELDS,
11
+ aliases: () => aliases,
12
+ builder: () => builder,
13
+ command: () => command,
14
+ describe: () => describe,
15
+ handler: () => handler
16
+ });
17
+ const SNAPSHOT_FIELDS = [
18
+ "id",
19
+ "name",
20
+ "source_branch_id",
21
+ "expires_at",
22
+ "created_at"
23
+ ];
24
+ const SCHEDULE_FIELDS = [
25
+ "frequency",
26
+ "hour",
27
+ "day",
28
+ "month",
29
+ "retention_seconds"
30
+ ];
31
+ const OPERATION_FIELDS = [
32
+ "id",
33
+ "action",
34
+ "status"
35
+ ];
36
+ const SNAPSHOT_FREQUENCIES = [
37
+ "daily",
38
+ "weekly",
39
+ "monthly"
40
+ ];
41
+ const SNAPSHOT_REF = {
42
+ describe: "Snapshot id or name. An id match wins over a name.",
43
+ type: "string"
44
+ };
45
+ /** Narrow an arbitrary string to a supported {@link SnapshotFrequency}. */
46
+ const isSnapshotFrequency = (value) => SNAPSHOT_FREQUENCIES.some((frequency) => frequency === value);
47
+ const command = "snapshots";
48
+ const describe = "Manage snapshots";
49
+ const aliases = ["snapshot"];
50
+ const builder = (argv) => argv.usage("$0 snapshots <sub-command> [options]").options({ "project-id": {
51
+ describe: "Project ID",
52
+ type: "string"
53
+ } }).middleware(fillSingleProject).command("list", "List snapshots in the project", (yargs) => yargs, (args) => list(args)).command("get <id>", "Get a snapshot by id or name", (yargs) => yargs.positional("id", SNAPSHOT_REF), (args) => get(args)).command("create", "Create a snapshot from a branch", (yargs) => yargs.strict().options({
54
+ branch: {
55
+ alias: "b",
56
+ describe: "Branch id or name to snapshot. Defaults to the branch in your context, or the project's default branch.",
57
+ type: "string"
58
+ },
59
+ name: {
60
+ describe: "A name for the snapshot",
61
+ type: "string"
62
+ },
63
+ timestamp: {
64
+ describe: "Take the snapshot at this point in time (RFC 3339, e.g. 2025-01-01T00:00:00Z). Must fall within the branch's restore window. Mutually exclusive with --lsn.",
65
+ type: "string"
66
+ },
67
+ lsn: {
68
+ describe: "Take the snapshot at this LSN (e.g. 0/1F3C8A0). Must fall within the branch's restore window. Mutually exclusive with --timestamp.",
69
+ type: "string"
70
+ },
71
+ "expires-at": {
72
+ describe: "When the snapshot is automatically deleted (RFC 3339, e.g. 2025-12-31T23:59:59Z). Omit to keep it indefinitely.",
73
+ type: "string"
74
+ }
75
+ }).conflicts("timestamp", "lsn").example([
76
+ ["$0 snapshots create", "Snapshot the head of the context/default branch"],
77
+ ["$0 snapshots create --branch main --name pre-migration", "Snapshot the head of main with a name"],
78
+ ["$0 snapshots create --branch main --timestamp 2025-01-01T00:00:00Z", "Snapshot main at a point in time"],
79
+ ["$0 snapshots create --branch main --lsn 0/1F3C8A0 --expires-at 2025-12-31T23:59:59Z", "Snapshot main at an LSN, auto-deleting at the given time"]
80
+ ]), (args) => create(args)).command("update <id>", "Update a snapshot's name or expiration", (yargs) => yargs.positional("id", SNAPSHOT_REF).options({
81
+ name: {
82
+ describe: "Rename the snapshot",
83
+ type: "string"
84
+ },
85
+ "expires-at": {
86
+ describe: "Set when the snapshot expires (RFC 3339). Mutually exclusive with --clear-expiration.",
87
+ type: "string"
88
+ },
89
+ "clear-expiration": {
90
+ describe: "Clear the expiration so the snapshot is kept indefinitely.",
91
+ type: "boolean"
92
+ }
93
+ }).conflicts("expires-at", "clear-expiration"), (args) => update(args)).command("delete <id>", "Delete a snapshot by id or name", (yargs) => yargs.positional("id", SNAPSHOT_REF), (args) => deleteSnapshot(args)).command("restore <id>", "Restore a snapshot into a branch", (yargs) => yargs.positional("id", SNAPSHOT_REF).options({
94
+ name: {
95
+ describe: "Name for the newly restored branch. Auto-generated when omitted.",
96
+ type: "string"
97
+ },
98
+ "target-branch": {
99
+ describe: "Branch id or name to restore the snapshot onto. Defaults to the snapshot's source branch. Recommended when you intend to finalize (replace an existing branch).",
100
+ type: "string"
101
+ },
102
+ finalize: {
103
+ describe: "Finalize the restore immediately: move computes onto the restored branch and swap it in for the target. Without this, the restore is left un-finalized so you can inspect it first, then run `snapshots finalize <branch>`.",
104
+ type: "boolean",
105
+ default: false
106
+ }
107
+ }).example([
108
+ ["$0 snapshots restore snap-1234 --name recovered", "Restore a snapshot to a new branch named 'recovered'"],
109
+ ["$0 snapshots restore snap-1234 --target-branch main --finalize", "Restore onto main and swap it in immediately"],
110
+ ["$0 snapshots restore snap-1234 --target-branch main", "Restore onto main un-finalized to preview, then run `snapshots finalize`"]
111
+ ]), (args) => restore(args)).command("finalize <branch>", "Finalize a previewed snapshot restore (swap the restored branch in)", (yargs) => yargs.options({ name: {
112
+ describe: "Name to give the replaced (old) branch. Auto-generated when omitted.",
113
+ type: "string"
114
+ } }), (args) => finalize(args)).command("schedule", "Manage the automatic snapshot (backup) schedule of a branch", (yargs) => yargs.usage("$0 snapshots schedule <sub-command> [options]").command("get", "Get a branch's automatic snapshot schedule", (yargs) => yargs.options({ branch: {
115
+ alias: "b",
116
+ describe: "Branch id or name. Defaults to the branch in your context, or the project's default branch.",
117
+ type: "string"
118
+ } }), (args) => scheduleGet(args)).command("set", "Set a branch's automatic snapshot schedule", (yargs) => yargs.options({
119
+ branch: {
120
+ alias: "b",
121
+ describe: "Branch id or name. Defaults to the branch in your context, or the project's default branch.",
122
+ type: "string"
123
+ },
124
+ frequency: {
125
+ describe: "How often to take snapshots. Builds a single-entry schedule together with --hour/--day/--month/--retention.",
126
+ choices: SNAPSHOT_FREQUENCIES,
127
+ type: "string"
128
+ },
129
+ hour: {
130
+ describe: "Hour of the day (0-23) to take the snapshot (used with --frequency).",
131
+ type: "number"
132
+ },
133
+ day: {
134
+ describe: "Day of the week/month (1-31) to take the snapshot (used with --frequency).",
135
+ type: "number"
136
+ },
137
+ month: {
138
+ describe: "Month of the year (1-12) to take the snapshot (used with --frequency).",
139
+ type: "number"
140
+ },
141
+ retention: {
142
+ describe: "How long to keep each snapshot, in seconds (min 3600). Omit to keep indefinitely.",
143
+ type: "number"
144
+ },
145
+ schedule: {
146
+ describe: "Full schedule as JSON, for multi-entry schedules, e.g. '[{\"frequency\":\"daily\",\"hour\":3,\"retention_seconds\":604800}]'. Overrides the single-entry flags.",
147
+ type: "string"
148
+ }
149
+ }).example([["$0 snapshots schedule set --branch main --frequency daily --hour 3 --retention 604800", "A daily 03:00 snapshot kept for 7 days"], ["$0 snapshots schedule set --branch main --schedule '[{\"frequency\":\"weekly\",\"day\":1,\"hour\":2},{\"frequency\":\"daily\",\"hour\":3}]'", "A multi-entry schedule via JSON"]]), (args) => scheduleSet(args)), () => {});
150
+ const handler = (args) => {
151
+ return args;
152
+ };
153
+ /** Narrow an unknown parsed JSON value to a plain object without type casting. */
154
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
155
+ /**
156
+ * Resolve a snapshot from an id **or** a name. Snapshot names are not guaranteed
157
+ * unique, so an id match wins; a name that resolves to more than one snapshot is a
158
+ * hard error asking the user to disambiguate by id.
159
+ */
160
+ const resolveSnapshot = async (props) => {
161
+ const { data: { snapshots } } = await props.apiClient.listSnapshots(props.projectId);
162
+ const byId = snapshots.find((s) => s.id === props.id);
163
+ if (byId) return byId;
164
+ const byName = snapshots.filter((s) => s.name === props.id);
165
+ if (byName.length === 1) return byName[0];
166
+ if (byName.length > 1) throw new Error(`Multiple snapshots are named "${props.id}". Re-run with the snapshot id:\n${byName.map((s) => ` ${s.id}`).join("\n")}`);
167
+ throw new Error(`Snapshot "${props.id}" not found.\nAvailable snapshots: ${snapshots.map((s) => `${s.name} (${s.id})`).join(", ") || "none"}`);
168
+ };
169
+ /**
170
+ * Runs `call` on the snapshot `props.id` names. An id goes straight to the API without the
171
+ * listing; a 404 sends it through {@link resolveSnapshot}, since a name can look like an id.
172
+ * When the listing has that id, the 404 was about something else (a target branch), so it stands.
173
+ */
174
+ const withSnapshotId = async (props, call) => {
175
+ let notFound;
176
+ if (looksLikeSnapshotId(props.id)) try {
177
+ return await call(props.id);
178
+ } catch (err) {
179
+ if (!(isNeonApiError(err) && err.status === 404)) throw err;
180
+ notFound = err;
181
+ }
182
+ const snapshot = await resolveSnapshot(props);
183
+ if (notFound && snapshot.id === props.id) throw notFound;
184
+ return call(snapshot.id);
185
+ };
186
+ /** A `br-…` id needs no branch listing; a name or the context/default branch does. */
187
+ const snapshotBranchId = async (props) => props.branch && looksLikeBranchId(props.branch) ? props.branch : (await resolveBranchRef(props)).branchId;
188
+ const list = async (props) => {
189
+ const { data: { snapshots } } = await props.apiClient.listSnapshots(props.projectId);
190
+ writer(props).end(snapshots, {
191
+ fields: SNAPSHOT_FIELDS,
192
+ title: "snapshots",
193
+ emptyMessage: "No snapshots found. Create one with:\n> neon snapshots create --help",
194
+ renderColumns: { expires_at: (s) => s.expires_at || "never" }
195
+ });
196
+ };
197
+ const get = async (props) => {
198
+ const snapshot = await resolveSnapshot(props);
199
+ writer(props).end(snapshot, {
200
+ fields: SNAPSHOT_FIELDS,
201
+ renderColumns: { expires_at: (s) => s.expires_at || "never" }
202
+ });
203
+ };
204
+ const create = async (props) => {
205
+ if (props.lsn !== void 0 && !looksLikeLSN(props.lsn)) throw new Error(`Invalid --lsn value: "${props.lsn}". Expected an LSN like 0/1F3C8A0.`);
206
+ if (props.timestamp !== void 0 && !looksLikeTimestamp(props.timestamp)) throw new Error(`Invalid --timestamp value: "${props.timestamp}". Use an RFC 3339 timestamp, e.g. 2025-01-01T00:00:00Z.`);
207
+ const branchId = await snapshotBranchId(props);
208
+ const { data } = await retryOnLock(() => props.apiClient.createSnapshot(props.projectId, branchId, {
209
+ name: props.name,
210
+ timestamp: props.timestamp,
211
+ lsn: props.lsn,
212
+ expires_at: props.expiresAt ? toIso(props.expiresAt, "--expires-at") : void 0
213
+ }));
214
+ writer(props).end(data.snapshot, {
215
+ fields: SNAPSHOT_FIELDS,
216
+ title: "snapshot",
217
+ renderColumns: { expires_at: (s) => s.expires_at || "never" }
218
+ });
219
+ };
220
+ const update = async (props) => {
221
+ if (props.name === void 0 && props.expiresAt === void 0 && !props.clearExpiration) throw new Error("Nothing to update. Pass --name, --expires-at, or --clear-expiration.");
222
+ const expiresAt = props.clearExpiration ? null : props.expiresAt !== void 0 ? toIso(props.expiresAt, "--expires-at") : void 0;
223
+ const { data } = await withSnapshotId(props, (snapshotId) => retryOnLock(() => props.apiClient.updateSnapshot(props.projectId, snapshotId, { snapshot: {
224
+ name: props.name,
225
+ expires_at: expiresAt
226
+ } })));
227
+ writer(props).end(data.snapshot, {
228
+ fields: SNAPSHOT_FIELDS,
229
+ renderColumns: { expires_at: (s) => s.expires_at || "never" }
230
+ });
231
+ };
232
+ const deleteSnapshot = async (props) => {
233
+ const snapshot = await resolveSnapshot(props);
234
+ await retryOnLock(() => props.apiClient.deleteSnapshot(props.projectId, snapshot.id));
235
+ writer(props).end(snapshot, {
236
+ fields: SNAPSHOT_FIELDS,
237
+ renderColumns: { expires_at: (s) => s.expires_at || "never" }
238
+ });
239
+ };
240
+ const restore = async (props) => {
241
+ const { data } = await withSnapshotId(props, async (snapshotId) => {
242
+ const targetBranchId = props.targetBranch ? await branchIdResolve({
243
+ branch: props.targetBranch,
244
+ projectId: props.projectId,
245
+ apiClient: props.apiClient
246
+ }) : void 0;
247
+ return retryOnLock(() => props.apiClient.restoreSnapshot(props.projectId, snapshotId, {
248
+ name: props.name,
249
+ target_branch_id: targetBranchId,
250
+ finalize_restore: props.finalize
251
+ }));
252
+ });
253
+ const out = writer(props).write(data.branch, {
254
+ fields: BRANCH_FIELDS,
255
+ title: "restored branch"
256
+ });
257
+ if (data.operations?.length) out.write(data.operations, {
258
+ fields: OPERATION_FIELDS,
259
+ title: "operations"
260
+ });
261
+ out.end();
262
+ if (!props.finalize) log.info(`Restore left un-finalized. Inspect branch ${data.branch.id}, then run:\n neon snapshots finalize ${data.branch.id} --project-id ${props.projectId}`);
263
+ };
264
+ const finalize = async (props) => {
265
+ const branchId = await branchIdResolve({
266
+ branch: props.branch,
267
+ projectId: props.projectId,
268
+ apiClient: props.apiClient
269
+ });
270
+ const { data } = await retryOnLock(() => props.apiClient.finalizeRestoreBranch(props.projectId, branchId, props.name ? { name: props.name } : void 0));
271
+ writer(props).end(data.operations ?? [], {
272
+ fields: OPERATION_FIELDS,
273
+ title: "operations",
274
+ emptyMessage: `Finalized restore for branch ${branchId}.`
275
+ });
276
+ };
277
+ const scheduleGet = async (props) => {
278
+ const branchId = await snapshotBranchId(props);
279
+ const { data } = await props.apiClient.getSnapshotSchedule(props.projectId, branchId);
280
+ writer(props).end(data.schedule, {
281
+ fields: SCHEDULE_FIELDS,
282
+ title: "schedule",
283
+ emptyMessage: "No automatic snapshot schedule is configured."
284
+ });
285
+ };
286
+ /**
287
+ * Validate an untrusted parsed value as a {@link BackupScheduleItem}[] without any
288
+ * type casting, throwing a clear error for the first invalid field it finds.
289
+ */
290
+ const parseScheduleJson = (raw) => {
291
+ let parsed;
292
+ try {
293
+ parsed = JSON.parse(raw);
294
+ } catch {
295
+ throw new Error("--schedule must be valid JSON.");
296
+ }
297
+ if (!Array.isArray(parsed)) throw new Error("--schedule must be a JSON array of schedule entries, e.g. '[{\"frequency\":\"daily\",\"hour\":3}]'.");
298
+ return parsed.map((entry, index) => {
299
+ if (!isRecord(entry)) throw new Error(`--schedule entry ${index} must be an object.`);
300
+ const record = entry;
301
+ const frequency = record.frequency;
302
+ if (typeof frequency !== "string") throw new Error(`--schedule entry ${index} is missing a string "frequency".`);
303
+ if (!isSnapshotFrequency(frequency)) throw new Error(`--schedule entry ${index} has an unsupported "frequency": "${frequency}". Use one of: ${SNAPSHOT_FREQUENCIES.join(", ")}.`);
304
+ const item = { frequency };
305
+ for (const key of [
306
+ "hour",
307
+ "day",
308
+ "month",
309
+ "retention_seconds"
310
+ ]) {
311
+ const value = record[key];
312
+ if (value === void 0) continue;
313
+ if (typeof value !== "number") throw new Error(`--schedule entry ${index} field "${key}" must be a number.`);
314
+ item[key] = value;
315
+ }
316
+ return item;
317
+ });
318
+ };
319
+ const scheduleSet = async (props) => {
320
+ let schedule;
321
+ if (props.schedule) schedule = parseScheduleJson(props.schedule);
322
+ else if (props.frequency) {
323
+ const item = { frequency: props.frequency };
324
+ if (props.hour !== void 0) item.hour = props.hour;
325
+ if (props.day !== void 0) item.day = props.day;
326
+ if (props.month !== void 0) item.month = props.month;
327
+ if (props.retention !== void 0) item.retention_seconds = props.retention;
328
+ schedule = [item];
329
+ } else throw new Error("Provide --frequency (optionally with --hour/--day/--month/--retention) or --schedule <json>.");
330
+ const branchId = await snapshotBranchId(props);
331
+ await retryOnLock(() => props.apiClient.setSnapshotSchedule(props.projectId, branchId, { schedule }));
332
+ writer(props).end(schedule, {
333
+ fields: SCHEDULE_FIELDS,
334
+ title: "schedule"
335
+ });
336
+ };
337
+ //#endregion
338
+ export { describe as a, command as i, aliases as n, handler as o, builder as r, snapshots_exports as s, SNAPSHOT_FIELDS as t };
@@ -0,0 +1,44 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { fillSingleProject } from "../utils/enrichers.js";
3
+ import { y as status } from "./config-BH_qRHiG.js";
4
+ //#region src/commands/status.ts
5
+ var status_exports = /* @__PURE__ */ __exportAll({
6
+ builder: () => builder,
7
+ command: () => command,
8
+ describe: () => describe,
9
+ handler: () => handler
10
+ });
11
+ /**
12
+ * `neon status` is a top-level alias for `neon config status` — the most-reached-for
13
+ * config subcommand. It mirrors that command's options (including `--current-branch`,
14
+ * the offline branch probe) and delegates to the same `status` handler.
15
+ *
16
+ * Because it has a handler but no subcommands, `status` must also be listed in
17
+ * `NO_SUBCOMMANDS_VERBS` (see index.ts) so the help-fallback middleware doesn't
18
+ * intercept a bare `neon status`.
19
+ */
20
+ const command = "status";
21
+ const describe = "Show the branch's live Neon state (alias of `config status`)";
22
+ const builder = (argv) => argv.usage("$0 status [options]").options({
23
+ "project-id": {
24
+ describe: "Project ID",
25
+ type: "string"
26
+ },
27
+ branch: {
28
+ describe: "Branch ID or name",
29
+ type: "string"
30
+ },
31
+ "config-json": {
32
+ describe: "Print only the branch's live config as neon.ts-shaped JSON (services + branch tuning + preview), to stdout. Useful for scripting or copying into a neon.ts.",
33
+ type: "boolean",
34
+ default: false
35
+ },
36
+ "current-branch": {
37
+ describe: "Print only the linked branch name from the local .neon file (no network). Exits non-zero when no branch is pinned.",
38
+ type: "boolean",
39
+ default: false
40
+ }
41
+ }).middleware(fillSingleProject);
42
+ const handler = (args) => status(args);
43
+ //#endregion
44
+ export { status_exports as a, handler as i, command as n, describe as r, builder as t };