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,460 +1 @@
1
- import { t as __exportAll } from "../_chunks/rolldown-runtime-8H4AJuhK.js";
2
- import { log } from "../log.js";
3
- import { retryOnLock } from "../api.js";
4
- import { contextBranch, readContextFile } from "../context.js";
5
- import { branchCreateRequest } from "../parameters.gen.js";
6
- import { writer } from "../writer.js";
7
- import { EndpointType } from "../utils/api_enums.js";
8
- import { looksLikeBranchId, looksLikeLSN, looksLikeTimestamp, toIso } from "../utils/formats.js";
9
- import { branchIdFromProps, fillSingleProject, resolveBranchFromProps } from "../utils/enrichers.js";
10
- import { getComputeUnits } from "../utils/compute_units.js";
11
- import { psql } from "../utils/psql.js";
12
- import { parsePointInTime } from "../utils/point_in_time.js";
13
- import { parseSchemaDiffParams, schemaDiff } from "./schema_diff.js";
14
- import chalk from "chalk";
15
- //#region src/commands/branches.ts
16
- var branches_exports = /* @__PURE__ */ __exportAll({
17
- BRANCH_FIELDS: () => BRANCH_FIELDS,
18
- aliases: () => aliases,
19
- builder: () => builder,
20
- command: () => command,
21
- describe: () => describe,
22
- handler: () => handler
23
- });
24
- const BRANCH_FIELDS = [
25
- "name",
26
- "id",
27
- "current_state",
28
- "expires_at",
29
- "created_at"
30
- ];
31
- const BRANCH_FIELDS_RESET = [...BRANCH_FIELDS, "last_reset_at"];
32
- const BRANCH_DETAIL_FIELDS = [
33
- "name",
34
- "id",
35
- "parent_id",
36
- "current_state",
37
- "expires_at",
38
- "created_at",
39
- "created_by",
40
- "last_reset_at",
41
- "logical_size"
42
- ];
43
- /**
44
- * The branch `.neon` pins, by name (preferred) or id, when `.neon` links this same project;
45
- * a `--project-id` pointing elsewhere makes its branch not current.
46
- */
47
- const currentBranchOf = (props) => {
48
- const context = readContextFile(props.contextFile);
49
- return context.projectId === props.projectId ? contextBranch(context) : void 0;
50
- };
51
- const branchNameCell = (br, labels) => {
52
- const tags = [];
53
- if (br.default) tags.push(chalk.cyan("[default]"));
54
- if (br.protected) tags.push(chalk.yellow("[protected]"));
55
- if (labels.annotations?.[br.id]?.value.anonymized) tags.push(chalk.dim("[anon]"));
56
- if (labels.current !== void 0 && (br.id === labels.current || br.name === labels.current)) tags.push(chalk.green("[current]"));
57
- tags.push(br.name);
58
- return tags.join(" ");
59
- };
60
- const stateCell = (state) => {
61
- if (!state) return "";
62
- if (state === "ready") return chalk.green(state);
63
- if (state === "init" || state === "resetting") return chalk.yellow(state);
64
- return chalk.dim(state);
65
- };
66
- const formatBytes = (bytes) => {
67
- const units = [
68
- "bytes",
69
- "KiB",
70
- "MiB",
71
- "GiB",
72
- "TiB"
73
- ];
74
- let value = bytes;
75
- let unit = 0;
76
- while (value >= 1024 && unit < units.length - 1) {
77
- value /= 1024;
78
- unit++;
79
- }
80
- return unit === 0 ? `${bytes} bytes` : `${value.toFixed(1)} ${units[unit]}`;
81
- };
82
- const branchColumns = (labels) => ({
83
- name: (br) => branchNameCell(br, labels),
84
- current_state: (br) => stateCell(br.current_state),
85
- expires_at: (br) => br.expires_at || "never",
86
- created_by: (br) => br.created_by?.name ?? "",
87
- logical_size: (br) => br.logical_size === void 0 ? "" : formatBytes(br.logical_size)
88
- });
89
- const command = "branches";
90
- const describe = "Manage branches";
91
- const aliases = ["branch"];
92
- const builder = (argv) => argv.usage("$0 branches <sub-command> [options]").options({ "project-id": {
93
- describe: "Project ID",
94
- type: "string"
95
- } }).middleware(fillSingleProject).middleware((args) => {
96
- args.branchId ??= args.id;
97
- }).command("list", "List branches", (yargs) => yargs, (args) => list(args)).command("create", "Create a branch", (yargs) => yargs.options({
98
- secrets: {
99
- describe: "Include connection credentials in command output. Use --no-secrets to omit them",
100
- type: "boolean",
101
- default: true
102
- },
103
- name: branchCreateRequest["branch.name"],
104
- parent: {
105
- describe: "Parent branch name or id or timestamp or LSN. Defaults to the default branch",
106
- type: "string"
107
- },
108
- compute: {
109
- describe: "Create a branch with or without a compute. By default branch is created with a read-write compute. To create a branch without compute use --no-compute",
110
- type: "boolean",
111
- default: true
112
- },
113
- type: {
114
- describe: "Type of compute to add",
115
- type: "string",
116
- implies: "compute",
117
- default: EndpointType.ReadWrite,
118
- choices: Object.values(EndpointType)
119
- },
120
- "suspend-timeout": {
121
- describe: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week).",
122
- type: "number",
123
- implies: "compute",
124
- default: 0
125
- },
126
- cu: {
127
- 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\").",
128
- type: "string",
129
- implies: "compute"
130
- },
131
- psql: {
132
- type: "boolean",
133
- describe: "Connect to a new branch via psql",
134
- default: false
135
- },
136
- fallback: {
137
- type: "boolean",
138
- describe: "Force the embedded TypeScript psql fallback (for testing)",
139
- default: false,
140
- hidden: true
141
- },
142
- annotation: {
143
- type: "string",
144
- hidden: true,
145
- default: "{}"
146
- },
147
- "schema-only": {
148
- describe: "Create a schema-only branch. Requires exactly one read-write compute.",
149
- type: "boolean",
150
- default: false
151
- },
152
- "expires-at": {
153
- describe: "Set an expiration date for the branch. Accepts a date string (e.g., 2024-12-31T23:59:59Z).",
154
- type: "string",
155
- requiresArg: true
156
- },
157
- protected: {
158
- describe: branchCreateRequest["branch.protected"].description,
159
- type: "boolean"
160
- }
161
- }), (args) => create(args)).command("reset <id|name>", "Reset a branch", (yargs) => yargs.options({
162
- parent: {
163
- describe: "Reset to a parent branch",
164
- type: "boolean",
165
- default: false
166
- },
167
- "preserve-under-name": { describe: "Name under which to preserve the old branch" }
168
- }), (args) => reset(args)).command("restore <target-id|name> <source>[@(timestamp|lsn)]", "Restores a branch to a specific point in time\n<source> can be: ^self, ^parent, or <source-branch-id|name>", (yargs) => yargs.middleware((args) => {
169
- args.id = args.targetId;
170
- args.pointInTime = args["source@(timestamp"];
171
- args.branchId = args.id;
172
- }).usage("$0 branches restore <target-id|name> <source>[@(timestamp|lsn)]").options({ "preserve-under-name": { describe: "Name under which to preserve the old branch" } }).example([
173
- ["$0 branches restore main br-source-branch-123456", "Restores main to the head of the branch with id br-source-branch-123456"],
174
- ["$0 branches restore main source@2021-01-01T00:00:00Z", "Restores main to the timestamp 2021-01-01T00:00:00Z of the source branch"],
175
- ["$0 branches restore my-branch ^self@0/123456", "Restores my-branch to the LSN 0/123456 from its own history"],
176
- ["$0 branches restore my-branch ^parent", "Restore my-branch to the head of its parent branch"]
177
- ]), (args) => restore(args)).command("rename <id|name> <new-name>", "Rename a branch", (yargs) => yargs, (args) => rename(args)).command("set-default <id|name>", "Set a branch as default", (yargs) => yargs, (args) => setDefault(args)).command({
178
- command: "set-expiration <id|name>",
179
- describe: "Set an expiration date for the branch",
180
- builder: (yargs) => yargs.options({ "expires-at": {
181
- describe: "Set a expiration date for the branch. If omitted, expiration will be removed. Format [RFC3339]: 2024-12-31T23:59:59Z",
182
- type: "string",
183
- requiresArg: false
184
- } }),
185
- handler: (args) => setExpiration(args)
186
- }).command("add-compute <id|name>", "Add a compute to a branch", (yargs) => yargs.options({
187
- type: {
188
- type: "string",
189
- choices: Object.values(EndpointType),
190
- describe: "Type of compute to add",
191
- default: EndpointType.ReadOnly
192
- },
193
- cu: {
194
- 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\").",
195
- type: "string"
196
- },
197
- name: {
198
- type: "string",
199
- describe: "Optional name of the compute"
200
- }
201
- }), (args) => addCompute(args)).command("delete <id|name>", "Delete a branch", (yargs) => yargs, (args) => deleteBranch(args)).command("get <id|name>", "Get a branch", (yargs) => yargs, (args) => get(args)).command({
202
- command: "schema-diff [base-branch] [compare-source[@(timestamp|lsn)]]",
203
- aliases: ["sd"],
204
- describe: "Compare the latest schemas of any two branches, or compare a branch to its own or another branch's history.",
205
- builder: (yargs) => {
206
- return yargs.middleware((args) => args.compareSource = args["compare-source@(timestamp"]).middleware(parseSchemaDiffParams).options({ database: {
207
- alias: "db",
208
- type: "string",
209
- description: "Name of the database for which the schema comparison is performed"
210
- } }).example([
211
- ["$0 branches schema-diff main br-compare-branch-123456", "Compares the main branch to the head of the branch with ID br-compare-branch-123456"],
212
- ["$0 branches schema-diff main compare@2024-06-01T00:00:00Z", "Compares the main branch to the state of the compare branch at timestamp 2024-06-01T00:00:00.000Z"],
213
- ["$0 branches schema-diff my-branch ^self@0/123456", "Compares my-branch to LSN 0/123456 from its own history"],
214
- ["$0 branches schema-diff my-branch ^parent", "Compares my-branch to the head of its parent branch"],
215
- ["$0 branches schema-diff", "If a branch is specified in 'set-context', compares this branch to its parent. Otherwise, compares the default branch to its parent."]
216
- ]);
217
- },
218
- handler: (args) => schemaDiff(args)
219
- });
220
- const handler = (args) => {
221
- return args;
222
- };
223
- const list = async (props) => {
224
- const { data: { branches, annotations } } = await props.apiClient.listProjectBranches({ projectId: props.projectId });
225
- writer(props).end(branches, {
226
- fields: BRANCH_FIELDS,
227
- renderColumns: branchColumns({
228
- annotations,
229
- current: currentBranchOf(props)
230
- })
231
- });
232
- };
233
- const parseAnnotation = (value) => {
234
- try {
235
- return JSON.parse(value);
236
- } catch (err) {
237
- const message = err instanceof Error ? err.message : String(err);
238
- throw new Error(`Failed to parse --annotation JSON: ${message}`);
239
- }
240
- };
241
- const create = async (props) => {
242
- const branches = await props.apiClient.listProjectBranches({ projectId: props.projectId }).then(({ data }) => data.branches);
243
- const parentProps = (() => {
244
- if (!props.parent) {
245
- const branch = branches.find((b) => b.default);
246
- if (!branch) throw new Error("No default branch found");
247
- return { parent_id: branch.id };
248
- }
249
- if (looksLikeLSN(props.parent)) return { parent_lsn: props.parent };
250
- if (looksLikeTimestamp(props.parent)) return { parent_timestamp: props.parent };
251
- if (looksLikeBranchId(props.parent)) return { parent_id: props.parent };
252
- const branch = branches.find((b) => b.name === props.parent);
253
- if (!branch) throw new Error(`Branch ${props.parent} not found`);
254
- return { parent_id: branch.id };
255
- })();
256
- const annotationValue = props.annotation ? parseAnnotation(props.annotation) : void 0;
257
- if (props.schemaOnly) {
258
- if (!props.compute) throw new Error("Schema-only branches require a compute endpoint");
259
- if (props.type !== EndpointType.ReadWrite) throw new Error("Schema-only branches require a read-write compute endpoint");
260
- }
261
- const { data } = await retryOnLock(() => props.apiClient.createProjectBranch(props.projectId, {
262
- branch: {
263
- name: props.name,
264
- ...parentProps,
265
- ...props.schemaOnly ? { init_source: "schema-only" } : {},
266
- ...props["expires-at"] ? { expires_at: toIso(props["expires-at"], "--expires-at") } : {},
267
- ...props.protected !== void 0 ? { protected: props.protected } : {}
268
- },
269
- endpoints: props.compute ? [{
270
- type: props.type,
271
- suspend_timeout_seconds: props.suspendTimeout === 0 ? void 0 : props.suspendTimeout,
272
- ...props.cu ? getComputeUnits(props.cu) : void 0
273
- }] : [],
274
- annotation_value: annotationValue
275
- }));
276
- if (branches.find((b) => b.id === data.branch.parent_id)?.protected) log.warning("The parent branch is protected; a unique role password has been generated for the new branch.");
277
- const out = writer(props);
278
- const endpoints = data.endpoints ?? [];
279
- const connectionUris = data.connection_uris ?? [];
280
- const writeEndpoints = endpoints.length > 0;
281
- const writeUris = props.secrets && connectionUris.length > 0;
282
- if (!props.secrets && (props.output === "json" || props.output === "yaml") && !writeEndpoints) out.write({ branch: data.branch }, {
283
- fields: ["branch"],
284
- title: "branch"
285
- });
286
- else {
287
- out.write(data.branch, {
288
- fields: BRANCH_FIELDS,
289
- title: "branch",
290
- humanTitle: "Branch",
291
- emptyMessage: "No branches have been found.",
292
- renderColumns: branchColumns({ current: currentBranchOf(props) })
293
- });
294
- if (writeEndpoints) out.write(endpoints, {
295
- fields: ["id", "created_at"],
296
- title: "endpoints",
297
- humanTitle: "Compute",
298
- emptyMessage: "No endpoints have been found."
299
- });
300
- if (writeUris) out.write(connectionUris, {
301
- fields: ["connection_uri"],
302
- title: "connection_uris",
303
- humanTitle: "Connection string",
304
- emptyMessage: "No connection uris have been found"
305
- });
306
- }
307
- out.end();
308
- if (props.psql) {
309
- if (!data.connection_uris?.length) throw new Error(`Branch ${data.branch.id} doesn't have a connection uri`);
310
- const connection_uri = data.connection_uris[0].connection_uri;
311
- const psqlArgs = props["--"];
312
- await psql(connection_uri, psqlArgs, { mode: props.fallback ? "ts" : "auto" });
313
- }
314
- };
315
- const rename = async (props) => {
316
- const { branchId, listing } = await resolveBranchFromProps(props);
317
- const { data } = await retryOnLock(() => props.apiClient.updateProjectBranch(props.projectId, branchId, { branch: { name: props.newName } }));
318
- writer(props).end(data.branch, {
319
- fields: BRANCH_FIELDS,
320
- renderColumns: branchColumns({
321
- annotations: listing?.annotations,
322
- current: currentBranchOf(props)
323
- })
324
- });
325
- };
326
- const setDefault = async (props) => {
327
- const { branchId, listing } = await resolveBranchFromProps(props);
328
- const { data } = await retryOnLock(() => props.apiClient.setDefaultProjectBranch(props.projectId, branchId));
329
- writer(props).end(data.branch, {
330
- fields: BRANCH_FIELDS,
331
- renderColumns: branchColumns({
332
- annotations: listing?.annotations,
333
- current: currentBranchOf(props)
334
- })
335
- });
336
- };
337
- const deleteBranch = async (props) => {
338
- const { branchId, listing } = await resolveBranchFromProps(props);
339
- const { data } = await retryOnLock(() => props.apiClient.deleteProjectBranch(props.projectId, branchId));
340
- if (data) writer(props).end(data.branch, {
341
- fields: BRANCH_FIELDS,
342
- renderColumns: branchColumns({
343
- annotations: listing?.annotations,
344
- current: currentBranchOf(props)
345
- })
346
- });
347
- };
348
- const get = async (props) => {
349
- const resolved = await resolveBranchFromProps(props);
350
- let branch = resolved.branch;
351
- let annotations = resolved.listing?.annotations;
352
- if (!branch) {
353
- const { data } = await props.apiClient.getProjectBranch(props.projectId, resolved.branchId);
354
- branch = data.branch;
355
- annotations = data.annotation ? { [data.branch.id]: data.annotation } : void 0;
356
- }
357
- writer(props).end(branch, {
358
- fields: BRANCH_DETAIL_FIELDS,
359
- renderColumns: branchColumns({
360
- annotations,
361
- current: currentBranchOf(props)
362
- })
363
- });
364
- };
365
- const addCompute = async (props) => {
366
- const branchId = await branchIdFromProps(props);
367
- const computeName = props.name ? { name: props.name } : null;
368
- const { data } = await retryOnLock(() => props.apiClient.createProjectEndpoint(props.projectId, { endpoint: {
369
- branch_id: branchId,
370
- type: props.type,
371
- ...props.cu ? getComputeUnits(props.cu) : void 0,
372
- ...computeName
373
- } }));
374
- writer(props).end(data.endpoint, { fields: ["id", "host"] });
375
- };
376
- const reset = async (props) => {
377
- if (!props.parent) throw new Error("Only resetting to parent is supported for now");
378
- const { branchId, branch, listing } = await resolveBranchFromProps(props);
379
- const parent_id = branch?.parent_id ?? (await props.apiClient.getProjectBranch(props.projectId, branchId)).data.branch.parent_id;
380
- if (!parent_id) throw new Error("Branch has no parent");
381
- const { data } = await retryOnLock(() => props.apiClient.restoreProjectBranch(props.projectId, branchId, {
382
- source_branch_id: parent_id,
383
- preserve_under_name: props.preserveUnderName || void 0
384
- }));
385
- writer(props).end(data.branch, {
386
- fields: BRANCH_FIELDS_RESET,
387
- renderColumns: branchColumns({
388
- annotations: listing?.annotations,
389
- current: currentBranchOf(props)
390
- })
391
- });
392
- };
393
- const restore = async (props) => {
394
- const { branchId: targetBranchId, branch: targetBranch, listing } = await resolveBranchFromProps({
395
- apiClient: props.apiClient,
396
- projectId: props.projectId,
397
- id: props.id
398
- });
399
- const pointInTime = await parsePointInTime({
400
- pointInTime: props.pointInTime,
401
- targetBranchId,
402
- projectId: props.projectId,
403
- api: props.apiClient,
404
- branches: listing?.branches,
405
- targetBranch
406
- });
407
- if (props.output === "table") {
408
- const nameOf = (id) => listing?.branches.find((b) => b.id === id)?.name ?? id;
409
- const point = pointInTime.tag === "lsn" ? `LSN ${pointInTime.lsn} of` : pointInTime.tag === "timestamp" ? `timestamp ${pointInTime.timestamp} of` : "the head of";
410
- log.info(`Restoring ${nameOf(targetBranchId)} to ${point} ${nameOf(pointInTime.branchId)}`);
411
- } else log.info(`Restoring branch ${targetBranchId} to the branch ${pointInTime.branchId} ${pointInTime.tag === "lsn" && "LSN " + pointInTime.lsn || pointInTime.tag === "timestamp" && "timestamp " + pointInTime.timestamp || "head"}`);
412
- const { data } = await retryOnLock(() => props.apiClient.restoreProjectBranch(props.projectId, targetBranchId, {
413
- source_branch_id: pointInTime.branchId,
414
- preserve_under_name: props.preserveUnderName || void 0,
415
- ...pointInTime.tag === "lsn" && { source_lsn: pointInTime.lsn },
416
- ...pointInTime.tag === "timestamp" && { source_timestamp: pointInTime.timestamp }
417
- }));
418
- const labels = {
419
- annotations: listing?.annotations,
420
- current: currentBranchOf(props)
421
- };
422
- const writeInst = writer(props).write(data.branch, {
423
- title: "Restored branch",
424
- fields: [
425
- "id",
426
- "name",
427
- "last_reset_at"
428
- ],
429
- emptyMessage: "No branches have been restored.",
430
- renderColumns: branchColumns(labels)
431
- });
432
- const parentId = data.branch.parent_id;
433
- if (props.preserveUnderName && parentId) {
434
- const { data } = await props.apiClient.getProjectBranch(props.projectId, parentId);
435
- writeInst.write(data.branch, {
436
- title: "Backup branch",
437
- fields: ["id", "name"],
438
- emptyMessage: "Backup branch has not been found.",
439
- renderColumns: branchColumns(labels)
440
- });
441
- }
442
- writeInst.end();
443
- };
444
- const setExpiration = async (props) => {
445
- const { branchId, listing } = await resolveBranchFromProps({
446
- ...props,
447
- id: props.branchId
448
- });
449
- const expiresAt = typeof props.expiresAt === "string" ? toIso(props.expiresAt, "--expires-at") : null;
450
- const { data } = await retryOnLock(() => props.apiClient.updateProjectBranch(props.projectId, branchId, { branch: { expires_at: expiresAt } }));
451
- writer(props).end(data.branch, {
452
- fields: BRANCH_FIELDS,
453
- renderColumns: branchColumns({
454
- annotations: listing?.annotations,
455
- current: currentBranchOf(props)
456
- })
457
- });
458
- };
459
- //#endregion
460
- export { BRANCH_FIELDS, aliases, builder, command, describe, handler, branches_exports as t };
1
+ export { t as BRANCH_FIELDS, n as aliases, i as builder, a as command, o as describe, s as handler } from "../_chunks/branches-BNa1xX1L.js";