neon 2.47.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -0
- package/dist/_shared/auth_selection.js +76 -79
- package/dist/_shared/credentials.js +166 -187
- package/dist/_shared/env-core/env.js +395 -0
- package/dist/_shared/env-core/reuse-secrets.js +179 -0
- package/dist/_shared/paths.js +129 -126
- package/dist/_shared/profiles.js +192 -242
- package/dist/_shared/secure_file.js +36 -38
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/analytics.js +163 -207
- package/dist/api.js +815 -758
- package/dist/auth.js +121 -141
- package/dist/auth_context.js +39 -53
- package/dist/cli.js +4 -7
- package/dist/commands/api.js +220 -250
- package/dist/commands/api_keys.js +251 -314
- package/dist/commands/auth.js +283 -328
- package/dist/commands/bootstrap.js +372 -437
- package/dist/commands/branches.js +304 -455
- package/dist/commands/bucket.js +374 -514
- package/dist/commands/checkout.js +213 -298
- package/dist/commands/config.js +575 -658
- package/dist/commands/connection_string.js +137 -165
- package/dist/commands/data_api.js +238 -260
- package/dist/commands/databases.js +67 -76
- package/dist/commands/deploy.js +31 -25
- package/dist/commands/dev.js +642 -681
- package/dist/commands/diff.js +156 -200
- package/dist/commands/env.js +243 -303
- package/dist/commands/functions.js +275 -341
- package/dist/commands/index.js +70 -65
- package/dist/commands/init.js +84 -119
- package/dist/commands/inspect.js +55 -55
- package/dist/commands/ip_allow.js +88 -120
- package/dist/commands/link.js +874 -1019
- package/dist/commands/logs.js +291 -0
- package/dist/commands/neon_auth.js +725 -933
- package/dist/commands/operations.js +34 -25
- package/dist/commands/orgs.js +28 -18
- package/dist/commands/profile.js +614 -845
- package/dist/commands/projects.js +313 -373
- package/dist/commands/psql.js +60 -58
- package/dist/commands/roles.js +55 -58
- package/dist/commands/schema_diff.js +87 -131
- package/dist/commands/set_context.js +34 -26
- package/dist/commands/snapshots.js +288 -413
- package/dist/commands/status.js +41 -37
- package/dist/commands/user.js +21 -10
- package/dist/commands/vpc_endpoints.js +85 -113
- package/dist/config.js +7 -6
- package/dist/config_format.js +50 -66
- package/dist/config_template.js +128 -157
- package/dist/context.js +183 -235
- package/dist/current_branch_fast_path.js +40 -49
- package/dist/dev/env.js +313 -394
- package/dist/dev/functions.js +54 -64
- package/dist/dev/inputs.js +46 -58
- package/dist/dev/runtime.js +135 -164
- package/dist/dev/websocket.js +766 -959
- package/dist/env.js +27 -33
- package/dist/env_file.js +118 -132
- package/dist/env_services.js +36 -38
- package/dist/errors.js +57 -68
- package/dist/functions_api.js +45 -43
- package/dist/help.js +189 -140
- package/dist/index.js +182 -257
- package/dist/init/agents.js +137 -118
- package/dist/init/auth.js +58 -68
- package/dist/init/bootstrap.js +325 -396
- package/dist/init/build_config.js +4 -2
- package/dist/init/detect_agent.js +56 -101
- package/dist/init/editors.js +35 -52
- package/dist/init/enrich_output.js +51 -66
- package/dist/init/extension.js +134 -171
- package/dist/init/inspect.js +179 -266
- package/dist/init/interactive.js +510 -622
- package/dist/init/neonctl.js +117 -168
- package/dist/init/orchestrate.js +157 -173
- package/dist/init/phases/auth.js +188 -202
- package/dist/init/phases/cleanup.js +23 -23
- package/dist/init/phases/db.js +251 -277
- package/dist/init/phases/getting_started.js +213 -223
- package/dist/init/phases/mcp.js +174 -224
- package/dist/init/phases/migrations.js +247 -248
- package/dist/init/phases/neon_auth.js +114 -133
- package/dist/init/phases/setup.js +546 -703
- package/dist/init/phases/skills.js +75 -86
- package/dist/init/phases/status.js +72 -67
- package/dist/init/resolve_context.js +102 -99
- package/dist/init/route_command.js +91 -98
- package/dist/init/skills.js +174 -218
- package/dist/init/vsix.js +77 -99
- package/dist/log.js +17 -16
- package/dist/neon_services.js +104 -129
- package/dist/parameters.gen.js +481 -471
- package/dist/pkg.js +17 -19
- package/dist/profile_keys.js +44 -47
- package/dist/psql/cli.js +44 -47
- package/dist/psql/command/cmd_cond.js +231 -406
- package/dist/psql/command/cmd_connect.js +557 -764
- package/dist/psql/command/cmd_copy.js +727 -983
- package/dist/psql/command/cmd_describe.js +1499 -1688
- package/dist/psql/command/cmd_format.js +733 -905
- package/dist/psql/command/cmd_io.js +1293 -2082
- package/dist/psql/command/cmd_lo.js +297 -359
- package/dist/psql/command/cmd_meta.js +727 -878
- package/dist/psql/command/cmd_misc.js +138 -172
- package/dist/psql/command/cmd_pipeline.js +547 -1099
- package/dist/psql/command/cmd_restrict.js +119 -155
- package/dist/psql/command/cmd_show.js +529 -688
- package/dist/psql/command/dispatch.js +261 -325
- package/dist/psql/command/inputQueue.js +35 -33
- package/dist/psql/command/shared.js +49 -63
- package/dist/psql/complete/filenames.js +90 -133
- package/dist/psql/complete/index.js +59 -97
- package/dist/psql/complete/matcher.js +236 -300
- package/dist/psql/complete/psqlVars.js +218 -223
- package/dist/psql/complete/queries.js +159 -177
- package/dist/psql/complete/rules.js +1493 -2299
- package/dist/psql/core/common.js +762 -1180
- package/dist/psql/core/help.js +456 -546
- package/dist/psql/core/mainloop.js +692 -1302
- package/dist/psql/core/prompt.js +391 -408
- package/dist/psql/core/settings.js +429 -644
- package/dist/psql/core/sqlHelp.js +480 -554
- package/dist/psql/core/startup.js +626 -815
- package/dist/psql/core/syncVars.js +67 -110
- package/dist/psql/core/variables.js +156 -278
- package/dist/psql/describe/formatters.js +884 -1285
- package/dist/psql/describe/processNamePattern.js +173 -260
- package/dist/psql/describe/queries.js +1368 -2403
- package/dist/psql/describe/versionGate.js +32 -41
- package/dist/psql/index.js +1414 -1927
- package/dist/psql/io/history.js +232 -271
- package/dist/psql/io/input.js +103 -108
- package/dist/psql/io/lineEditor/buffer.js +238 -319
- package/dist/psql/io/lineEditor/complete.js +135 -213
- package/dist/psql/io/lineEditor/filename.js +139 -148
- package/dist/psql/io/lineEditor/index.js +653 -870
- package/dist/psql/io/lineEditor/keymap.js +544 -702
- package/dist/psql/io/lineEditor/vt100.js +294 -341
- package/dist/psql/io/pgpass.js +158 -187
- package/dist/psql/io/pgservice.js +146 -183
- package/dist/psql/io/psqlrc.js +328 -403
- package/dist/psql/print/aligned.js +1020 -1683
- package/dist/psql/print/asciidoc.js +180 -214
- package/dist/psql/print/crosstab.js +281 -442
- package/dist/psql/print/csv.js +48 -70
- package/dist/psql/print/html.js +195 -226
- package/dist/psql/print/json.js +75 -88
- package/dist/psql/print/latex.js +291 -364
- package/dist/psql/print/pager.js +171 -242
- package/dist/psql/print/troff.js +194 -226
- package/dist/psql/print/unaligned.js +69 -95
- package/dist/psql/print/units.js +167 -169
- package/dist/psql/scanner/slash.js +428 -483
- package/dist/psql/scanner/sql.js +445 -889
- package/dist/psql/scanner/stringutils.js +309 -379
- package/dist/psql/types/index.js +2 -7
- package/dist/psql/types/scanner.js +25 -22
- package/dist/psql/wire/connection.js +2042 -2803
- package/dist/psql/wire/copy.js +84 -100
- package/dist/psql/wire/notify.js +39 -59
- package/dist/psql/wire/pipeline.js +305 -518
- package/dist/psql/wire/protocol.js +349 -417
- package/dist/psql/wire/sasl.js +180 -265
- package/dist/psql/wire/tls.js +400 -561
- package/dist/storage_api.js +115 -129
- package/dist/test_utils/fixtures.js +94 -113
- package/dist/test_utils/oauth_server.js +10 -7
- package/dist/test_utils/project_dir.js +33 -0
- package/dist/utils/ai_gateway_notice.js +131 -162
- package/dist/utils/api_enums.js +21 -28
- package/dist/utils/auth.js +10 -4
- package/dist/utils/branch_notice.js +20 -19
- package/dist/utils/branch_picker.js +83 -89
- package/dist/utils/cli_name.js +15 -12
- package/dist/utils/compute_units.js +20 -27
- package/dist/utils/config_diff.js +127 -158
- package/dist/utils/enrichers.js +95 -148
- package/dist/utils/esbuild.js +133 -147
- package/dist/utils/flags.js +35 -47
- package/dist/utils/formats.js +8 -15
- package/dist/utils/git_diff.js +69 -80
- package/dist/utils/inspect_db.js +101 -143
- package/dist/utils/inspect_queries.js +179 -142
- package/dist/utils/middlewares.js +37 -44
- package/dist/utils/openapi.js +87 -99
- package/dist/utils/package_manager.js +312 -110
- package/dist/utils/point_in_time.js +49 -53
- package/dist/utils/psql.js +89 -106
- package/dist/utils/service_picker.js +55 -58
- package/dist/utils/string.js +5 -5
- package/dist/utils/ui.js +38 -55
- package/dist/utils/write_sync.js +26 -35
- package/dist/utils/zip.js +4 -3
- package/dist/writer.js +67 -87
- package/package.json +9 -7
|
@@ -1,455 +1,330 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { log } from "../log.js";
|
|
3
|
-
import {
|
|
4
|
-
import { looksLikeLSN, looksLikeTimestamp } from "../utils/formats.js";
|
|
3
|
+
import { retryOnLock } from "../api.js";
|
|
5
4
|
import { writer } from "../writer.js";
|
|
5
|
+
import { looksLikeLSN, looksLikeTimestamp } from "../utils/formats.js";
|
|
6
|
+
import { branchIdResolve, fillSingleProject, resolveBranchRef } from "../utils/enrichers.js";
|
|
6
7
|
import { BRANCH_FIELDS } from "./branches.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
"created_at",
|
|
22
|
+
"expires_at"
|
|
13
23
|
];
|
|
14
24
|
const SCHEDULE_FIELDS = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
"frequency",
|
|
26
|
+
"hour",
|
|
27
|
+
"day",
|
|
28
|
+
"month",
|
|
29
|
+
"retention_seconds"
|
|
20
30
|
];
|
|
21
31
|
const OPERATION_FIELDS = [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
"id",
|
|
33
|
+
"action",
|
|
34
|
+
"status"
|
|
25
35
|
];
|
|
26
|
-
// The values the Neon API accepts for a backup-schedule entry's `frequency`
|
|
27
|
-
// (per the OpenAPI `BackupScheduleItem` description). `satisfies` fails the
|
|
28
|
-
// build if a value listed here leaves the SDK's `SnapshotFrequency` union, so
|
|
29
|
-
// the CLI can never offer a frequency the API rejects.
|
|
30
36
|
const SNAPSHOT_FREQUENCIES = [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
"daily",
|
|
38
|
+
"weekly",
|
|
39
|
+
"monthly"
|
|
34
40
|
];
|
|
35
41
|
/** Narrow an arbitrary string to a supported {@link SnapshotFrequency}. */
|
|
36
42
|
const isSnapshotFrequency = (value) => SNAPSHOT_FREQUENCIES.some((frequency) => frequency === value);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
name: {
|
|
143
|
-
describe: "Name to give the replaced (old) branch. Auto-generated when omitted.",
|
|
144
|
-
type: "string",
|
|
145
|
-
},
|
|
146
|
-
}), (args) => finalize(args))
|
|
147
|
-
.command("schedule", "Manage the automatic snapshot (backup) schedule of a branch", (yargs) => yargs
|
|
148
|
-
.usage("$0 snapshots schedule <sub-command> [options]")
|
|
149
|
-
.command("get", "Get a branch's automatic snapshot schedule", (yargs) => yargs.options({
|
|
150
|
-
branch: {
|
|
151
|
-
alias: "b",
|
|
152
|
-
describe: "Branch id or name. Defaults to the branch in your context, or the project's default branch.",
|
|
153
|
-
type: "string",
|
|
154
|
-
},
|
|
155
|
-
}), (args) => scheduleGet(args))
|
|
156
|
-
.command("set", "Set a branch's automatic snapshot schedule", (yargs) => yargs
|
|
157
|
-
.options({
|
|
158
|
-
branch: {
|
|
159
|
-
alias: "b",
|
|
160
|
-
describe: "Branch id or name. Defaults to the branch in your context, or the project's default branch.",
|
|
161
|
-
type: "string",
|
|
162
|
-
},
|
|
163
|
-
frequency: {
|
|
164
|
-
describe: "How often to take snapshots. Builds a single-entry schedule together with --hour/--day/--month/--retention.",
|
|
165
|
-
choices: SNAPSHOT_FREQUENCIES,
|
|
166
|
-
type: "string",
|
|
167
|
-
},
|
|
168
|
-
hour: {
|
|
169
|
-
describe: "Hour of the day (0-23) to take the snapshot (used with --frequency).",
|
|
170
|
-
type: "number",
|
|
171
|
-
},
|
|
172
|
-
day: {
|
|
173
|
-
describe: "Day of the week/month (1-31) to take the snapshot (used with --frequency).",
|
|
174
|
-
type: "number",
|
|
175
|
-
},
|
|
176
|
-
month: {
|
|
177
|
-
describe: "Month of the year (1-12) to take the snapshot (used with --frequency).",
|
|
178
|
-
type: "number",
|
|
179
|
-
},
|
|
180
|
-
retention: {
|
|
181
|
-
describe: "How long to keep each snapshot, in seconds (min 3600). Omit to keep indefinitely.",
|
|
182
|
-
type: "number",
|
|
183
|
-
},
|
|
184
|
-
schedule: {
|
|
185
|
-
describe: 'Full schedule as JSON, for multi-entry schedules, e.g. \'[{"frequency":"daily","hour":3,"retention_seconds":604800}]\'. Overrides the single-entry flags.',
|
|
186
|
-
type: "string",
|
|
187
|
-
},
|
|
188
|
-
})
|
|
189
|
-
.example([
|
|
190
|
-
[
|
|
191
|
-
"$0 snapshots schedule set --branch main --frequency daily --hour 3 --retention 604800",
|
|
192
|
-
"A daily 03:00 snapshot kept for 7 days",
|
|
193
|
-
],
|
|
194
|
-
[
|
|
195
|
-
'$0 snapshots schedule set --branch main --schedule \'[{"frequency":"weekly","day":1,"hour":2},{"frequency":"daily","hour":3}]\'',
|
|
196
|
-
"A multi-entry schedule via JSON",
|
|
197
|
-
],
|
|
198
|
-
]), (args) => scheduleSet(args))
|
|
199
|
-
.demandCommand(1, "Specify `get` or `set`."), () => { })
|
|
200
|
-
.demandCommand(1, "Specify a snapshots sub-command.");
|
|
201
|
-
export const handler = (args) => {
|
|
202
|
-
return args;
|
|
43
|
+
const command = "snapshots";
|
|
44
|
+
const describe = "Manage snapshots";
|
|
45
|
+
const aliases = ["snapshot"];
|
|
46
|
+
const builder = (argv) => argv.usage("$0 snapshots <sub-command> [options]").options({ "project-id": {
|
|
47
|
+
describe: "Project ID",
|
|
48
|
+
type: "string"
|
|
49
|
+
} }).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, (args) => get(args)).command("create", "Create a snapshot from a branch", (yargs) => yargs.options({
|
|
50
|
+
branch: {
|
|
51
|
+
alias: "b",
|
|
52
|
+
describe: "Branch id or name to snapshot. Defaults to the branch in your context, or the project's default branch.",
|
|
53
|
+
type: "string"
|
|
54
|
+
},
|
|
55
|
+
name: {
|
|
56
|
+
describe: "A name for the snapshot",
|
|
57
|
+
type: "string"
|
|
58
|
+
},
|
|
59
|
+
timestamp: {
|
|
60
|
+
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.",
|
|
61
|
+
type: "string"
|
|
62
|
+
},
|
|
63
|
+
lsn: {
|
|
64
|
+
describe: "Take the snapshot at this LSN (e.g. 0/1F3C8A0). Must fall within the branch's restore window. Mutually exclusive with --timestamp.",
|
|
65
|
+
type: "string"
|
|
66
|
+
},
|
|
67
|
+
"expires-at": {
|
|
68
|
+
describe: "When the snapshot is automatically deleted (RFC 3339, e.g. 2025-12-31T23:59:59Z). Omit to keep it indefinitely.",
|
|
69
|
+
type: "string"
|
|
70
|
+
}
|
|
71
|
+
}).conflicts("timestamp", "lsn").example([
|
|
72
|
+
["$0 snapshots create", "Snapshot the head of the context/default branch"],
|
|
73
|
+
["$0 snapshots create --branch main --name pre-migration", "Snapshot the head of main with a name"],
|
|
74
|
+
["$0 snapshots create --branch main --timestamp 2025-01-01T00:00:00Z", "Snapshot main at a point in time"],
|
|
75
|
+
["$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"]
|
|
76
|
+
]), (args) => create(args)).command("update <id>", "Update a snapshot's name or expiration", (yargs) => yargs.options({
|
|
77
|
+
name: {
|
|
78
|
+
describe: "Rename the snapshot",
|
|
79
|
+
type: "string"
|
|
80
|
+
},
|
|
81
|
+
"expires-at": {
|
|
82
|
+
describe: "Set when the snapshot expires (RFC 3339). Mutually exclusive with --clear-expiration.",
|
|
83
|
+
type: "string"
|
|
84
|
+
},
|
|
85
|
+
"clear-expiration": {
|
|
86
|
+
describe: "Clear the expiration so the snapshot is kept indefinitely.",
|
|
87
|
+
type: "boolean"
|
|
88
|
+
}
|
|
89
|
+
}).conflicts("expires-at", "clear-expiration"), (args) => update(args)).command("delete <id>", "Delete a snapshot by id or name", (yargs) => yargs, (args) => deleteSnapshot(args)).command("restore <id>", "Restore a snapshot into a branch", (yargs) => yargs.options({
|
|
90
|
+
name: {
|
|
91
|
+
describe: "Name for the newly restored branch. Auto-generated when omitted.",
|
|
92
|
+
type: "string"
|
|
93
|
+
},
|
|
94
|
+
"target-branch": {
|
|
95
|
+
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).",
|
|
96
|
+
type: "string"
|
|
97
|
+
},
|
|
98
|
+
finalize: {
|
|
99
|
+
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>`.",
|
|
100
|
+
type: "boolean",
|
|
101
|
+
default: false
|
|
102
|
+
}
|
|
103
|
+
}).example([
|
|
104
|
+
["$0 snapshots restore snap-1234 --name recovered", "Restore a snapshot to a new branch named 'recovered'"],
|
|
105
|
+
["$0 snapshots restore snap-1234 --target-branch main --finalize", "Restore onto main and swap it in immediately"],
|
|
106
|
+
["$0 snapshots restore snap-1234 --target-branch main", "Restore onto main un-finalized to preview, then run `snapshots finalize`"]
|
|
107
|
+
]), (args) => restore(args)).command("finalize <branch>", "Finalize a previewed snapshot restore (swap the restored branch in)", (yargs) => yargs.options({ name: {
|
|
108
|
+
describe: "Name to give the replaced (old) branch. Auto-generated when omitted.",
|
|
109
|
+
type: "string"
|
|
110
|
+
} }), (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: {
|
|
111
|
+
alias: "b",
|
|
112
|
+
describe: "Branch id or name. Defaults to the branch in your context, or the project's default branch.",
|
|
113
|
+
type: "string"
|
|
114
|
+
} }), (args) => scheduleGet(args)).command("set", "Set a branch's automatic snapshot schedule", (yargs) => yargs.options({
|
|
115
|
+
branch: {
|
|
116
|
+
alias: "b",
|
|
117
|
+
describe: "Branch id or name. Defaults to the branch in your context, or the project's default branch.",
|
|
118
|
+
type: "string"
|
|
119
|
+
},
|
|
120
|
+
frequency: {
|
|
121
|
+
describe: "How often to take snapshots. Builds a single-entry schedule together with --hour/--day/--month/--retention.",
|
|
122
|
+
choices: SNAPSHOT_FREQUENCIES,
|
|
123
|
+
type: "string"
|
|
124
|
+
},
|
|
125
|
+
hour: {
|
|
126
|
+
describe: "Hour of the day (0-23) to take the snapshot (used with --frequency).",
|
|
127
|
+
type: "number"
|
|
128
|
+
},
|
|
129
|
+
day: {
|
|
130
|
+
describe: "Day of the week/month (1-31) to take the snapshot (used with --frequency).",
|
|
131
|
+
type: "number"
|
|
132
|
+
},
|
|
133
|
+
month: {
|
|
134
|
+
describe: "Month of the year (1-12) to take the snapshot (used with --frequency).",
|
|
135
|
+
type: "number"
|
|
136
|
+
},
|
|
137
|
+
retention: {
|
|
138
|
+
describe: "How long to keep each snapshot, in seconds (min 3600). Omit to keep indefinitely.",
|
|
139
|
+
type: "number"
|
|
140
|
+
},
|
|
141
|
+
schedule: {
|
|
142
|
+
describe: "Full schedule as JSON, for multi-entry schedules, e.g. '[{\"frequency\":\"daily\",\"hour\":3,\"retention_seconds\":604800}]'. Overrides the single-entry flags.",
|
|
143
|
+
type: "string"
|
|
144
|
+
}
|
|
145
|
+
}).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)).demandCommand(1, "Specify `get` or `set`."), () => {}).demandCommand(1, "Specify a snapshots sub-command.");
|
|
146
|
+
const handler = (args) => {
|
|
147
|
+
return args;
|
|
203
148
|
};
|
|
204
149
|
/** Narrow an unknown parsed JSON value to a plain object without type casting. */
|
|
205
150
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
206
151
|
/** Normalize a user-supplied date to an ISO 8601 string, or throw a friendly error. */
|
|
207
152
|
const toIso = (value, flag) => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
return new Date(ms).toISOString();
|
|
153
|
+
const ms = Date.parse(value);
|
|
154
|
+
if (Number.isNaN(ms)) throw new Error(`Invalid ${flag} value: "${value}". Use an RFC 3339 timestamp, e.g. 2025-12-31T23:59:59Z.`);
|
|
155
|
+
return new Date(ms).toISOString();
|
|
213
156
|
};
|
|
214
157
|
/**
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
158
|
+
* Resolve a snapshot from an id **or** a name. Snapshot names are not guaranteed
|
|
159
|
+
* unique, so an id match wins; a name that resolves to more than one snapshot is a
|
|
160
|
+
* hard error asking the user to disambiguate by id.
|
|
161
|
+
*/
|
|
219
162
|
const resolveSnapshot = async (props) => {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return byName[0];
|
|
228
|
-
}
|
|
229
|
-
if (byName.length > 1) {
|
|
230
|
-
throw new Error(`Multiple snapshots are named "${props.id}". Re-run with the snapshot id:\n${byName
|
|
231
|
-
.map((s) => ` ${s.id}`)
|
|
232
|
-
.join("\n")}`);
|
|
233
|
-
}
|
|
234
|
-
throw new Error(`Snapshot "${props.id}" not found.\nAvailable snapshots: ${snapshots.map((s) => `${s.name} (${s.id})`).join(", ") ||
|
|
235
|
-
"none"}`);
|
|
163
|
+
const { data: { snapshots } } = await props.apiClient.listSnapshots(props.projectId);
|
|
164
|
+
const byId = snapshots.find((s) => s.id === props.id);
|
|
165
|
+
if (byId) return byId;
|
|
166
|
+
const byName = snapshots.filter((s) => s.name === props.id);
|
|
167
|
+
if (byName.length === 1) return byName[0];
|
|
168
|
+
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")}`);
|
|
169
|
+
throw new Error(`Snapshot "${props.id}" not found.\nAvailable snapshots: ${snapshots.map((s) => `${s.name} (${s.id})`).join(", ") || "none"}`);
|
|
236
170
|
};
|
|
237
171
|
const list = async (props) => {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
},
|
|
246
|
-
});
|
|
172
|
+
const { data: { snapshots } } = await props.apiClient.listSnapshots(props.projectId);
|
|
173
|
+
writer(props).end(snapshots, {
|
|
174
|
+
fields: SNAPSHOT_FIELDS,
|
|
175
|
+
title: "snapshots",
|
|
176
|
+
emptyMessage: "No snapshots found. Create one with:\n> neon snapshots create --help",
|
|
177
|
+
renderColumns: { expires_at: (s) => s.expires_at || "never" }
|
|
178
|
+
});
|
|
247
179
|
};
|
|
248
180
|
const get = async (props) => {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
},
|
|
255
|
-
});
|
|
181
|
+
const snapshot = await resolveSnapshot(props);
|
|
182
|
+
writer(props).end(snapshot, {
|
|
183
|
+
fields: SNAPSHOT_FIELDS,
|
|
184
|
+
renderColumns: { expires_at: (s) => s.expires_at || "never" }
|
|
185
|
+
});
|
|
256
186
|
};
|
|
257
187
|
const create = async (props) => {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}));
|
|
276
|
-
writer(props).end(data.snapshot, {
|
|
277
|
-
fields: SNAPSHOT_FIELDS,
|
|
278
|
-
title: "snapshot",
|
|
279
|
-
renderColumns: {
|
|
280
|
-
expires_at: (s) => s.expires_at || "never",
|
|
281
|
-
},
|
|
282
|
-
});
|
|
188
|
+
if (props.lsn !== void 0 && !looksLikeLSN(props.lsn)) throw new Error(`Invalid --lsn value: "${props.lsn}". Expected an LSN like 0/1F3C8A0.`);
|
|
189
|
+
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.`);
|
|
190
|
+
const { branchId } = await resolveBranchRef({
|
|
191
|
+
...props,
|
|
192
|
+
branch: props.branch
|
|
193
|
+
});
|
|
194
|
+
const { data } = await retryOnLock(() => props.apiClient.createSnapshot(props.projectId, branchId, {
|
|
195
|
+
name: props.name,
|
|
196
|
+
timestamp: props.timestamp,
|
|
197
|
+
lsn: props.lsn,
|
|
198
|
+
expires_at: props.expiresAt ? toIso(props.expiresAt, "--expires-at") : void 0
|
|
199
|
+
}));
|
|
200
|
+
writer(props).end(data.snapshot, {
|
|
201
|
+
fields: SNAPSHOT_FIELDS,
|
|
202
|
+
title: "snapshot",
|
|
203
|
+
renderColumns: { expires_at: (s) => s.expires_at || "never" }
|
|
204
|
+
});
|
|
283
205
|
};
|
|
284
206
|
const update = async (props) => {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
: props.expiresAt !== undefined
|
|
297
|
-
? toIso(props.expiresAt, "--expires-at")
|
|
298
|
-
: undefined;
|
|
299
|
-
const { data } = await retryOnLock(() => props.apiClient.updateSnapshot(props.projectId, snapshot.id, {
|
|
300
|
-
snapshot: {
|
|
301
|
-
name: props.name,
|
|
302
|
-
expires_at: expiresAt,
|
|
303
|
-
},
|
|
304
|
-
}));
|
|
305
|
-
writer(props).end(data.snapshot, {
|
|
306
|
-
fields: SNAPSHOT_FIELDS,
|
|
307
|
-
renderColumns: {
|
|
308
|
-
expires_at: (s) => s.expires_at || "never",
|
|
309
|
-
},
|
|
310
|
-
});
|
|
207
|
+
if (props.name === void 0 && props.expiresAt === void 0 && !props.clearExpiration) throw new Error("Nothing to update. Pass --name, --expires-at, or --clear-expiration.");
|
|
208
|
+
const snapshot = await resolveSnapshot(props);
|
|
209
|
+
const expiresAt = props.clearExpiration ? null : props.expiresAt !== void 0 ? toIso(props.expiresAt, "--expires-at") : void 0;
|
|
210
|
+
const { data } = await retryOnLock(() => props.apiClient.updateSnapshot(props.projectId, snapshot.id, { snapshot: {
|
|
211
|
+
name: props.name,
|
|
212
|
+
expires_at: expiresAt
|
|
213
|
+
} }));
|
|
214
|
+
writer(props).end(data.snapshot, {
|
|
215
|
+
fields: SNAPSHOT_FIELDS,
|
|
216
|
+
renderColumns: { expires_at: (s) => s.expires_at || "never" }
|
|
217
|
+
});
|
|
311
218
|
};
|
|
312
219
|
const deleteSnapshot = async (props) => {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
renderColumns: {
|
|
320
|
-
expires_at: (s) => s.expires_at || "never",
|
|
321
|
-
},
|
|
322
|
-
});
|
|
220
|
+
const snapshot = await resolveSnapshot(props);
|
|
221
|
+
await retryOnLock(() => props.apiClient.deleteSnapshot(props.projectId, snapshot.id));
|
|
222
|
+
writer(props).end(snapshot, {
|
|
223
|
+
fields: SNAPSHOT_FIELDS,
|
|
224
|
+
renderColumns: { expires_at: (s) => s.expires_at || "never" }
|
|
225
|
+
});
|
|
323
226
|
};
|
|
324
227
|
const restore = async (props) => {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
out.end();
|
|
349
|
-
if (!props.finalize) {
|
|
350
|
-
log.info(`Restore left un-finalized. Inspect branch ${data.branch.id}, then run:\n neon snapshots finalize ${data.branch.id} --project-id ${props.projectId}`);
|
|
351
|
-
}
|
|
228
|
+
const snapshot = await resolveSnapshot(props);
|
|
229
|
+
const targetBranchId = props.targetBranch ? await branchIdResolve({
|
|
230
|
+
branch: props.targetBranch,
|
|
231
|
+
projectId: props.projectId,
|
|
232
|
+
apiClient: props.apiClient
|
|
233
|
+
}) : void 0;
|
|
234
|
+
const { data } = await retryOnLock(() => props.apiClient.restoreSnapshot(props.projectId, snapshot.id, {
|
|
235
|
+
name: props.name,
|
|
236
|
+
target_branch_id: targetBranchId,
|
|
237
|
+
finalize_restore: props.finalize
|
|
238
|
+
}));
|
|
239
|
+
const out = writer(props).write(data.branch, {
|
|
240
|
+
fields: BRANCH_FIELDS,
|
|
241
|
+
title: "restored branch"
|
|
242
|
+
});
|
|
243
|
+
if (data.operations?.length) out.write(data.operations, {
|
|
244
|
+
fields: OPERATION_FIELDS,
|
|
245
|
+
title: "operations"
|
|
246
|
+
});
|
|
247
|
+
out.end();
|
|
248
|
+
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}`);
|
|
352
249
|
};
|
|
353
250
|
const finalize = async (props) => {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
251
|
+
const branchId = await branchIdResolve({
|
|
252
|
+
branch: props.branch,
|
|
253
|
+
projectId: props.projectId,
|
|
254
|
+
apiClient: props.apiClient
|
|
255
|
+
});
|
|
256
|
+
const { data } = await retryOnLock(() => props.apiClient.finalizeRestoreBranch(props.projectId, branchId, props.name ? { name: props.name } : void 0));
|
|
257
|
+
writer(props).end(data.operations ?? [], {
|
|
258
|
+
fields: OPERATION_FIELDS,
|
|
259
|
+
title: "operations",
|
|
260
|
+
emptyMessage: `Finalized restore for branch ${branchId}.`
|
|
261
|
+
});
|
|
365
262
|
};
|
|
366
263
|
const scheduleGet = async (props) => {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
264
|
+
const { branchId } = await resolveBranchRef({
|
|
265
|
+
...props,
|
|
266
|
+
branch: props.branch
|
|
267
|
+
});
|
|
268
|
+
const { data } = await props.apiClient.getSnapshotSchedule(props.projectId, branchId);
|
|
269
|
+
writer(props).end(data.schedule, {
|
|
270
|
+
fields: SCHEDULE_FIELDS,
|
|
271
|
+
title: "schedule",
|
|
272
|
+
emptyMessage: "No automatic snapshot schedule is configured."
|
|
273
|
+
});
|
|
377
274
|
};
|
|
378
275
|
/**
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
276
|
+
* Validate an untrusted parsed value as a {@link BackupScheduleItem}[] without any
|
|
277
|
+
* type casting, throwing a clear error for the first invalid field it finds.
|
|
278
|
+
*/
|
|
382
279
|
const parseScheduleJson = (raw) => {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
"retention_seconds",
|
|
411
|
-
]) {
|
|
412
|
-
const value = record[key];
|
|
413
|
-
if (value === undefined) {
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
if (typeof value !== "number") {
|
|
417
|
-
throw new Error(`--schedule entry ${index} field "${key}" must be a number.`);
|
|
418
|
-
}
|
|
419
|
-
item[key] = value;
|
|
420
|
-
}
|
|
421
|
-
return item;
|
|
422
|
-
});
|
|
280
|
+
let parsed;
|
|
281
|
+
try {
|
|
282
|
+
parsed = JSON.parse(raw);
|
|
283
|
+
} catch {
|
|
284
|
+
throw new Error("--schedule must be valid JSON.");
|
|
285
|
+
}
|
|
286
|
+
if (!Array.isArray(parsed)) throw new Error("--schedule must be a JSON array of schedule entries, e.g. '[{\"frequency\":\"daily\",\"hour\":3}]'.");
|
|
287
|
+
return parsed.map((entry, index) => {
|
|
288
|
+
if (!isRecord(entry)) throw new Error(`--schedule entry ${index} must be an object.`);
|
|
289
|
+
const record = entry;
|
|
290
|
+
const frequency = record.frequency;
|
|
291
|
+
if (typeof frequency !== "string") throw new Error(`--schedule entry ${index} is missing a string "frequency".`);
|
|
292
|
+
if (!isSnapshotFrequency(frequency)) throw new Error(`--schedule entry ${index} has an unsupported "frequency": "${frequency}". Use one of: ${SNAPSHOT_FREQUENCIES.join(", ")}.`);
|
|
293
|
+
const item = { frequency };
|
|
294
|
+
for (const key of [
|
|
295
|
+
"hour",
|
|
296
|
+
"day",
|
|
297
|
+
"month",
|
|
298
|
+
"retention_seconds"
|
|
299
|
+
]) {
|
|
300
|
+
const value = record[key];
|
|
301
|
+
if (value === void 0) continue;
|
|
302
|
+
if (typeof value !== "number") throw new Error(`--schedule entry ${index} field "${key}" must be a number.`);
|
|
303
|
+
item[key] = value;
|
|
304
|
+
}
|
|
305
|
+
return item;
|
|
306
|
+
});
|
|
423
307
|
};
|
|
424
308
|
const scheduleSet = async (props) => {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
throw new Error("Provide --frequency (optionally with --hour/--day/--month/--retention) or --schedule <json>.");
|
|
447
|
-
}
|
|
448
|
-
await retryOnLock(() => props.apiClient.setSnapshotSchedule(props.projectId, branchId, {
|
|
449
|
-
schedule,
|
|
450
|
-
}));
|
|
451
|
-
writer(props).end(schedule, {
|
|
452
|
-
fields: SCHEDULE_FIELDS,
|
|
453
|
-
title: "schedule",
|
|
454
|
-
});
|
|
309
|
+
const { branchId } = await resolveBranchRef({
|
|
310
|
+
...props,
|
|
311
|
+
branch: props.branch
|
|
312
|
+
});
|
|
313
|
+
let schedule;
|
|
314
|
+
if (props.schedule) schedule = parseScheduleJson(props.schedule);
|
|
315
|
+
else if (props.frequency) {
|
|
316
|
+
const item = { frequency: props.frequency };
|
|
317
|
+
if (props.hour !== void 0) item.hour = props.hour;
|
|
318
|
+
if (props.day !== void 0) item.day = props.day;
|
|
319
|
+
if (props.month !== void 0) item.month = props.month;
|
|
320
|
+
if (props.retention !== void 0) item.retention_seconds = props.retention;
|
|
321
|
+
schedule = [item];
|
|
322
|
+
} else throw new Error("Provide --frequency (optionally with --hour/--day/--month/--retention) or --schedule <json>.");
|
|
323
|
+
await retryOnLock(() => props.apiClient.setSnapshotSchedule(props.projectId, branchId, { schedule }));
|
|
324
|
+
writer(props).end(schedule, {
|
|
325
|
+
fields: SCHEDULE_FIELDS,
|
|
326
|
+
title: "schedule"
|
|
327
|
+
});
|
|
455
328
|
};
|
|
329
|
+
//#endregion
|
|
330
|
+
export { SNAPSHOT_FIELDS, aliases, builder, command, describe, handler, snapshots_exports };
|