neon 8.20.1 → 8.22.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 CHANGED
@@ -1179,6 +1179,26 @@ neon credentials revoke nak_live_…
1179
1179
 
1180
1180
  All sub-commands honor the [global options](#global-options), including `--output json|yaml|table`.
1181
1181
 
1182
+ ## Postgres (`postgres`)
1183
+
1184
+ `neon postgres` (aliases `neon pg` and `neon lakebase`) groups the Postgres commands: `computes`, `databases`, `roles`, `connection-string` (`cs`), and `psql`. `neon postgres roles list` and `neon roles list` run the same command; the top-level spellings keep working.
1185
+
1186
+ `neon postgres computes` (aliases `compute`, `endpoints`, `endpoint`) manages the computes in a project:
1187
+
1188
+ ```bash
1189
+ neon postgres computes list # the .neon branch's computes, else every compute in the project
1190
+ neon postgres computes list --branch main
1191
+ neon postgres computes list --all-branches # every compute in the project, even when .neon pins a branch
1192
+ neon postgres computes get ep-cool-king-123456
1193
+ neon postgres computes update ep-cool-king-123456 --cu 0.25-2 --suspend-timeout 600
1194
+ neon postgres computes suspend ep-cool-king-123456
1195
+ neon postgres computes start ep-cool-king-123456
1196
+ neon postgres computes restart ep-cool-king-123456
1197
+ neon postgres computes delete ep-cool-king-123456
1198
+ ```
1199
+
1200
+ `update`, `start`, `suspend`, `restart`, and `delete` wait until the change is applied. `update`, `start`, `suspend`, and `restart` then print the compute as the API reports it; `delete` prints a confirmation on stderr. `--no-wait` returns as soon as the API accepts the request. `update` sends only the flags you pass and fails without one. To add a compute, use `neon branches add-compute`.
1201
+
1182
1202
  ## Database diagnostics (`inspect`)
1183
1203
 
1184
1204
  `neon inspect db stalled-queries` takes a read-only snapshot of active queries that have run for more than 30 seconds and groups parallel workers with their leader. Oldest group first. Table output shows duration, wait event, blocking pids, role, query group, and query. `--output json` adds timestamps, query IDs, pids, database, and the rest of the row. A blocking pid can belong to an idle-in-transaction backend this command does not list; `neon inspect db locks` shows lock holders.
@@ -1511,9 +1531,10 @@ Id Name Project Created At Last Used At Last
1511
1531
  | [ip-allow](https://neon.com/docs/reference/cli-ip-allow) | `list`, `add`, `remove`, `reset` | Manage IP Allow |
1512
1532
  | [me](https://neon.com/docs/reference/cli-me) | | Show current user |
1513
1533
  | [branches](https://neon.com/docs/reference/cli-branches) | `list`, `create`, `rename`, `add-compute`, `set-default`, `set-expiration`, `delete`, `get` | Manage branches |
1534
+ | postgres (`pg`, `lakebase`) | `computes`, `databases`, `roles`, `connection-string`, `psql` | Manage Postgres and connect to it |
1514
1535
  | [databases](https://neon.com/docs/reference/cli-databases) | `list`, `create`, `delete` | Manage databases |
1515
1536
  | function | `deploy`, `list`, `get`, `delete`, `domains list`, `domains register`, `domains delete` | Manage Neon Functions |
1516
- | [roles](https://neon.com/docs/reference/cli-roles) | `list`, `create`, `delete` | Manage roles |
1537
+ | [roles](https://neon.com/docs/reference/cli-roles) | `list`, `get`, `create`, `reset-password`, `delete` | Manage roles |
1517
1538
  | [operations](https://neon.com/docs/reference/cli-operations) | `list`, `get` | Manage operations |
1518
1539
  | logs | `query`, `fields`, `field-values` | Query branch logs (Beta) |
1519
1540
  | inspect | `db stalled-queries` | Inspect Postgres diagnostics |
@@ -0,0 +1,208 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
+ import { log } from "../log.js";
3
+ import { endpointUpdateRequest } from "../parameters.gen.js";
4
+ import { writer } from "../writer.js";
5
+ import { fillSingleProject, resolveBranchFromProps } from "../utils/enrichers.js";
6
+ import { getComputeUnits } from "../utils/compute_units.js";
7
+ // src/commands/computes.ts
8
+ var computes_exports = /* @__PURE__ */ __exportAll({
9
+ aliases: () => aliases,
10
+ builder: () => builder,
11
+ builderFor: () => builderFor,
12
+ command: () => command,
13
+ deleteCompute: () => deleteCompute,
14
+ describe: () => describe,
15
+ get: () => get,
16
+ handler: () => handler,
17
+ list: () => list,
18
+ restart: () => restart,
19
+ start: () => start,
20
+ suspend: () => suspend,
21
+ update: () => update
22
+ });
23
+ const COMPUTE_FIELDS = [
24
+ "id",
25
+ "branch_id",
26
+ "type",
27
+ "current_state",
28
+ "autoscaling_limit_min_cu",
29
+ "autoscaling_limit_max_cu"
30
+ ];
31
+ const COMPUTE_DETAIL_FIELDS = [
32
+ "id",
33
+ "name",
34
+ "branch_id",
35
+ "type",
36
+ "current_state",
37
+ "pending_state",
38
+ "host",
39
+ "region_id",
40
+ "autoscaling_limit_min_cu",
41
+ "autoscaling_limit_max_cu",
42
+ "suspend_timeout_seconds",
43
+ "disabled",
44
+ "last_active",
45
+ "created_at"
46
+ ];
47
+ const waitOption = { wait: {
48
+ describe: "Wait until the change is applied. Use --no-wait to return as soon as the API accepts it",
49
+ type: "boolean",
50
+ default: true
51
+ } };
52
+ const command = "computes";
53
+ const aliases = [
54
+ "compute",
55
+ "endpoints",
56
+ "endpoint"
57
+ ];
58
+ const describe = "Manage Postgres computes";
59
+ const builderFor = (usage) => (argv) => argv.usage(`$0 ${usage} <sub-command> [options]`).options({ "project-id": {
60
+ describe: "Project ID",
61
+ type: "string"
62
+ } }).middleware(fillSingleProject).command("list", "List computes. Lists the branch's computes when --branch is passed or .neon pins one, otherwise every compute in the project", (yargs) => yargs.options({
63
+ branch: {
64
+ describe: "Branch ID or name",
65
+ type: "string"
66
+ },
67
+ "all-branches": {
68
+ describe: "List every compute in the project, ignoring --branch and the branch .neon pins",
69
+ type: "boolean",
70
+ default: false
71
+ }
72
+ }), (args) => list(args)).command("get <id>", "Get a compute", (yargs) => yargs, (args) => get(args)).command("update <id>", "Update a compute's size, scale-to-zero timeout, name, or connection access", (yargs) => yargs.options({
73
+ cu: {
74
+ 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\").",
75
+ type: "string"
76
+ },
77
+ "suspend-timeout": {
78
+ describe: endpointUpdateRequest["endpoint.suspend_timeout_seconds"].description,
79
+ type: "number"
80
+ },
81
+ name: {
82
+ describe: "Name of the compute",
83
+ type: "string"
84
+ },
85
+ disabled: {
86
+ describe: "Restrict connections to the compute. Disabling schedules a suspend. Use --disabled=false to allow connections again.",
87
+ type: "boolean"
88
+ },
89
+ ...waitOption
90
+ }), (args) => update(args)).command("start <id>", "Start a compute", (yargs) => yargs.options(waitOption), (args) => start(args)).command("suspend <id>", "Suspend a compute", (yargs) => yargs.options(waitOption), (args) => suspend(args)).command("restart <id>", "Restart a compute", (yargs) => yargs.options(waitOption), (args) => restart(args)).command("delete <id>", "Delete a compute", (yargs) => yargs.options(waitOption), (args) => deleteCompute(args));
91
+ const builder = builderFor("computes");
92
+ const handler = (args) => {
93
+ return args;
94
+ };
95
+ const sdk = async (props) => {
96
+ const { fromSdkError, getNeonClient } = await import("../neon_client.js");
97
+ return {
98
+ neon: getNeonClient(props),
99
+ fail: (error) => fromSdkError(error, props.apiHost)
100
+ };
101
+ };
102
+ const writeCompute = (props, compute, humanTitle) => {
103
+ writer(props).end(compute, {
104
+ fields: COMPUTE_DETAIL_FIELDS,
105
+ humanTitle
106
+ });
107
+ };
108
+ const list = async (props) => {
109
+ const { neon, fail } = await sdk(props);
110
+ if (props.allBranches || props.branch === void 0) {
111
+ const computes = await neon.postgres.endpoints.list({ projectId: props.projectId }).catch((error) => {
112
+ throw fail(error);
113
+ });
114
+ writer(props).end(computes, {
115
+ fields: COMPUTE_FIELDS,
116
+ humanTitle: `Computes in project ${props.projectId}`,
117
+ emptyMessage: `No computes in project ${props.projectId}.`
118
+ });
119
+ return;
120
+ }
121
+ const { branchId, branch } = await resolveBranchFromProps(props);
122
+ const computes = await neon.postgres.endpoints.listByBranch({
123
+ projectId: props.projectId,
124
+ branchId
125
+ }).catch((error) => {
126
+ throw fail(error);
127
+ });
128
+ const branchLabel = branch?.name ?? branchId;
129
+ writer(props).end(computes, {
130
+ fields: COMPUTE_FIELDS,
131
+ humanTitle: `Computes on ${branchLabel}`,
132
+ emptyMessage: `No computes on ${branchLabel}.`
133
+ });
134
+ };
135
+ const get = async (props) => {
136
+ const { neon, fail } = await sdk(props);
137
+ const compute = await neon.postgres.endpoints.get({
138
+ projectId: props.projectId,
139
+ endpointId: props.id
140
+ }).catch((error) => {
141
+ throw fail(error);
142
+ });
143
+ writeCompute(props, compute);
144
+ };
145
+ const updateRequest = (props) => {
146
+ const endpoint = {
147
+ ...props.cu === void 0 ? {} : getComputeUnits(props.cu),
148
+ ...props.suspendTimeout === void 0 ? {} : { suspend_timeout_seconds: props.suspendTimeout },
149
+ ...props.name === void 0 ? {} : { name: props.name },
150
+ ...props.disabled === void 0 ? {} : { disabled: props.disabled }
151
+ };
152
+ if (Object.keys(endpoint).length === 0) throw new Error("Nothing to update. Pass --cu, --suspend-timeout, --name, or --disabled.");
153
+ return endpoint;
154
+ };
155
+ /**
156
+ * Mutations return the compute as it was when the request was accepted, so after waiting
157
+ * the compute is read again to show the state the change produced.
158
+ */
159
+ const mutate = async (props, action, run) => {
160
+ const { neon, fail } = await sdk(props);
161
+ const params = {
162
+ projectId: props.projectId,
163
+ endpointId: props.id
164
+ };
165
+ try {
166
+ const accepted = await run(neon, params, { waitForReadiness: props.wait });
167
+ if (!props.wait) {
168
+ writeCompute(props, accepted, `Compute ${props.id}: ${action.verb} accepted, not yet applied`);
169
+ return;
170
+ }
171
+ writeCompute(props, await neon.postgres.endpoints.get(params), `Compute ${props.id} ${action.done}`);
172
+ } catch (error) {
173
+ throw fail(error);
174
+ }
175
+ };
176
+ const update = (props) => {
177
+ const endpoint = updateRequest(props);
178
+ return mutate(props, {
179
+ verb: "update",
180
+ done: "updated"
181
+ }, (neon, params, opts) => neon.postgres.endpoints.update({
182
+ ...params,
183
+ ...endpoint
184
+ }, opts));
185
+ };
186
+ const start = (props) => mutate(props, {
187
+ verb: "start",
188
+ done: "started"
189
+ }, (neon, params, opts) => neon.postgres.endpoints.start(params, opts));
190
+ const suspend = (props) => mutate(props, {
191
+ verb: "suspend",
192
+ done: "suspended"
193
+ }, (neon, params, opts) => neon.postgres.endpoints.suspend(params, opts));
194
+ const restart = (props) => mutate(props, {
195
+ verb: "restart",
196
+ done: "restarted"
197
+ }, (neon, params, opts) => neon.postgres.endpoints.restart(params, opts));
198
+ const deleteCompute = async (props) => {
199
+ const { neon, fail } = await sdk(props);
200
+ await neon.postgres.endpoints.delete({
201
+ projectId: props.projectId,
202
+ endpointId: props.id
203
+ }, { waitForReadiness: props.wait }).catch((error) => {
204
+ throw fail(error);
205
+ });
206
+ log.info(props.wait ? `Compute ${props.id} deleted` : `Compute ${props.id}: delete accepted, not yet applied`);
207
+ };
208
+ export { computes_exports as a, get as c, restart as d, start as f, command as i, handler as l, update as m, builder as n, deleteCompute as o, suspend as p, builderFor as r, describe as s, aliases as t, list as u };
@@ -10,6 +10,7 @@ var connection_string_exports = /* @__PURE__ */ __exportAll({
10
10
  SSL_MODES: () => SSL_MODES,
11
11
  aliases: () => aliases,
12
12
  builder: () => builder,
13
+ builderFor: () => builderFor,
13
14
  command: () => command,
14
15
  describe: () => describe,
15
16
  handler: () => handler
@@ -23,8 +24,8 @@ const SSL_MODES = [
23
24
  const command = "connection-string [branch]";
24
25
  const aliases = ["cs"];
25
26
  const describe = "Get connection string";
26
- const builder = (argv) => {
27
- return argv.usage("$0 connection-string [branch] [options]").example("$0 cs main", "Get connection string for the main branch").example("$0 cs main@2024-01-01T00:00:00Z", "Get connection string for the main branch at a specific point in time").example("$0 cs main@0/234235", "Get connection string for the main branch at a specific LSN").positional("branch", {
27
+ const builderFor = (usage) => (argv) => {
28
+ return argv.usage(`$0 ${usage} [branch] [options]`).example("$0 cs main", "Get connection string for the main branch").example("$0 cs main@2024-01-01T00:00:00Z", "Get connection string for the main branch at a specific point in time").example("$0 cs main@0/234235", "Get connection string for the main branch at a specific LSN").positional("branch", {
28
29
  describe: `Branch name or id. Defaults to the default branch if omitted. Can be written in the point-in-time format: "branch@timestamp" or "branch@lsn"`,
29
30
  type: "string"
30
31
  }).options({
@@ -78,6 +79,7 @@ const builder = (argv) => {
78
79
  }
79
80
  }).middleware(fillSingleProject);
80
81
  };
82
+ const builder = builderFor("connection-string");
81
83
  const handler = async (props) => {
82
84
  const projectId = props.projectId;
83
85
  const parsedPIT = props.branch ? parsePITBranch(props.branch) : {
@@ -150,4 +152,4 @@ const handler = async (props) => {
150
152
  ] });
151
153
  else process.stdout.write(connectionString.toString() + "\n");
152
154
  };
153
- export { connection_string_exports as a, command as i, aliases as n, describe as o, builder as r, handler as s, SSL_MODES as t };
155
+ export { command as a, handler as c, builderFor as i, aliases as n, connection_string_exports as o, builder as r, describe as s, SSL_MODES as t };
@@ -8,6 +8,7 @@ var databases_exports = /* @__PURE__ */ __exportAll({
8
8
  DATABASE_FIELDS: () => DATABASE_FIELDS,
9
9
  aliases: () => aliases,
10
10
  builder: () => builder,
11
+ builderFor: () => builderFor,
11
12
  command: () => command,
12
13
  create: () => create,
13
14
  deleteDb: () => deleteDb,
@@ -23,7 +24,7 @@ const DATABASE_FIELDS = [
23
24
  const command = "databases";
24
25
  const describe = "Manage databases";
25
26
  const aliases = ["database", "db"];
26
- const builder = (argv) => argv.usage("$0 databases <sub-command> [options]").options({
27
+ const builderFor = (usage) => (argv) => argv.usage(`$0 ${usage} <sub-command> [options]`).options({
27
28
  "project-id": {
28
29
  describe: "Project ID",
29
30
  type: "string"
@@ -43,6 +44,7 @@ const builder = (argv) => argv.usage("$0 databases <sub-command> [options]").opt
43
44
  type: "string"
44
45
  }
45
46
  }), (args) => create(args)).command("delete <database>", "Delete a database", (yargs) => yargs, (args) => deleteDb(args));
47
+ const builder = builderFor("databases");
46
48
  const handler = (args) => {
47
49
  return args;
48
50
  };
@@ -85,4 +87,4 @@ const deleteDb = async (props) => {
85
87
  }
86
88
  log.info(`Database "${props.database}" not found on branch ${branch?.name ?? branchId}; nothing to delete.`);
87
89
  };
88
- export { create as a, describe as c, command as i, handler as l, aliases as n, databases_exports as o, builder as r, deleteDb as s, DATABASE_FIELDS as t, list as u };
90
+ export { command as a, deleteDb as c, list as d, builderFor as i, describe as l, aliases as n, create as o, builder as r, databases_exports as s, DATABASE_FIELDS as t, handler as u };
@@ -0,0 +1,31 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
+ import { a as computes_exports } from "./computes-OKFUNFee.js";
3
+ import { o as connection_string_exports } from "./connection_string-6WhV4WFx.js";
4
+ import { s as databases_exports } from "./databases-B-qY303S.js";
5
+ import { o as psql_exports } from "./psql-BcxiPR4W.js";
6
+ import { f as roles_exports } from "./roles-BELJqjTy.js";
7
+ // src/commands/postgres.ts
8
+ var postgres_exports = /* @__PURE__ */ __exportAll({
9
+ aliases: () => aliases,
10
+ builder: () => builder,
11
+ command: () => command,
12
+ describe: () => describe,
13
+ handler: () => handler
14
+ });
15
+ const nested = (group) => ({
16
+ command: group.command,
17
+ aliases: group.aliases,
18
+ describe: group.describe,
19
+ builder: group.builderFor(`postgres ${group.command.split(" ")[0]}`),
20
+ handler: async (args) => {
21
+ await group.handler(args);
22
+ }
23
+ });
24
+ const command = "postgres";
25
+ const aliases = ["pg", "lakebase"];
26
+ const describe = "Manage Postgres computes, databases, and roles, and connect with psql or a connection string";
27
+ const builder = (argv) => argv.usage("$0 postgres <sub-command> [options]").command(nested(computes_exports)).command(nested(databases_exports)).command(nested(roles_exports)).command(nested(connection_string_exports)).command(nested(psql_exports));
28
+ const handler = (args) => {
29
+ return args;
30
+ };
31
+ export { handler as a, describe as i, builder as n, postgres_exports as o, command as r, aliases as t };
@@ -1,18 +1,19 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
2
  import { EndpointType } from "../utils/api_enums.js";
3
3
  import { fillSingleProject } from "../utils/enrichers.js";
4
- import { s as handler$1, t as SSL_MODES } from "./connection_string-C9e7N4xk.js";
4
+ import { c as handler$1, t as SSL_MODES } from "./connection_string-6WhV4WFx.js";
5
5
  // src/commands/psql.ts
6
6
  var psql_exports = /* @__PURE__ */ __exportAll({
7
7
  builder: () => builder,
8
+ builderFor: () => builderFor,
8
9
  command: () => command,
9
10
  describe: () => describe,
10
11
  handler: () => handler
11
12
  });
12
13
  const command = "psql [branch]";
13
14
  const describe = "Connect to a database via psql";
14
- const builder = (argv) => {
15
- return argv.usage("$0 psql [branch] [options] [-- psql-args]").example("$0 psql", "Connect to the default branch via psql").example("$0 psql main", "Connect to the main branch via psql").example("$0 psql main -- -c \"SELECT 1\"", "Run a single query against the main branch").example("$0 psql main@2024-01-01T00:00:00Z", "Connect to the main branch at a specific point in time").positional("branch", {
15
+ const builderFor = (usage) => (argv) => {
16
+ return argv.usage(`$0 ${usage} [branch] [options] [-- psql-args]`).example("$0 psql", "Connect to the default branch via psql").example("$0 psql main", "Connect to the main branch via psql").example("$0 psql main -- -c \"SELECT 1\"", "Run a single query against the main branch").example("$0 psql main@2024-01-01T00:00:00Z", "Connect to the main branch at a specific point in time").positional("branch", {
16
17
  describe: `Branch name or id. Defaults to the default branch if omitted. Can be written in the point-in-time format: "branch@timestamp" or "branch@lsn"`,
17
18
  type: "string"
18
19
  }).options({
@@ -52,6 +53,7 @@ const builder = (argv) => {
52
53
  }
53
54
  }).middleware(fillSingleProject);
54
55
  };
56
+ const builder = builderFor("psql");
55
57
  const handler = async (props) => {
56
58
  await handler$1({
57
59
  ...props,
@@ -60,4 +62,4 @@ const handler = async (props) => {
60
62
  extended: false
61
63
  });
62
64
  };
63
- export { psql_exports as a, handler as i, command as n, describe as r, builder as t };
65
+ export { handler as a, describe as i, builderFor as n, psql_exports as o, command as r, builder as t };
@@ -7,12 +7,15 @@ import { fillSingleProject, resolveBranchFromProps } from "../utils/enrichers.js
7
7
  var roles_exports = /* @__PURE__ */ __exportAll({
8
8
  aliases: () => aliases,
9
9
  builder: () => builder,
10
+ builderFor: () => builderFor,
10
11
  command: () => command,
11
12
  create: () => create,
12
13
  deleteRole: () => deleteRole,
13
14
  describe: () => describe,
15
+ get: () => get,
14
16
  handler: () => handler,
15
- list: () => list
17
+ list: () => list,
18
+ resetPassword: () => resetPassword
16
19
  });
17
20
  const ROLES_FIELDS = ["name", "created_at"];
18
21
  const CREATED_ROLE_FIELDS = [
@@ -20,6 +23,14 @@ const CREATED_ROLE_FIELDS = [
20
23
  "password",
21
24
  "created_at"
22
25
  ];
26
+ const ROLE_DETAIL_FIELDS = [
27
+ "name",
28
+ "branch_id",
29
+ "protected",
30
+ "authentication_method",
31
+ "created_at",
32
+ "updated_at"
33
+ ];
23
34
  const ROLE_ACCESS = [
24
35
  "admin",
25
36
  "read_only",
@@ -28,7 +39,7 @@ const ROLE_ACCESS = [
28
39
  const command = "roles";
29
40
  const describe = "Manage roles";
30
41
  const aliases = ["role"];
31
- const builder = (argv) => argv.usage("$0 roles <sub-command> [options]").options({
42
+ const builderFor = (usage) => (argv) => argv.usage(`$0 ${usage} <sub-command> [options]`).options({
32
43
  "project-id": {
33
44
  describe: "Project ID",
34
45
  type: "string"
@@ -65,7 +76,12 @@ const builder = (argv) => argv.usage("$0 roles <sub-command> [options]").options
65
76
  }).check((args) => {
66
77
  if (args.access === "admin" && (args.database !== void 0 || args.schema !== void 0)) throw new Error("--database and --schema need --access read_only or --access read_write");
67
78
  return true;
68
- }), (args) => create(args)).command("delete <role>", "Delete a role", (yargs) => yargs, (args) => deleteRole(args));
79
+ }), (args) => create(args)).command("get <role>", "Get a role", (yargs) => yargs, (args) => get(args)).command("reset-password <role>", "Reset a role's password and print the new one", (yargs) => yargs.options({ wait: {
80
+ describe: "Wait until the compute applies the new password. Use --no-wait to return as soon as the API accepts the reset",
81
+ type: "boolean",
82
+ default: true
83
+ } }), (args) => resetPassword(args)).command("delete <role>", "Delete a role", (yargs) => yargs, (args) => deleteRole(args));
84
+ const builder = builderFor("roles");
69
85
  const handler = (args) => {
70
86
  return args;
71
87
  };
@@ -125,4 +141,32 @@ const deleteRole = async (props) => {
125
141
  }
126
142
  log.info(`Role "${props.role}" not found on branch ${branch?.name ?? branchId}; nothing to delete.`);
127
143
  };
128
- export { deleteRole as a, list as c, create as i, roles_exports as l, builder as n, describe as o, command as r, handler as s, aliases as t };
144
+ const get = async (props) => {
145
+ const { branchId } = await resolveBranchFromProps(props);
146
+ const { fromSdkError, getNeonClient } = await import("../neon_client.js");
147
+ const role = await getNeonClient(props).postgres.roles.get({
148
+ projectId: props.projectId,
149
+ branchId,
150
+ roleName: props.role
151
+ }).catch((error) => {
152
+ throw fromSdkError(error, props.apiHost);
153
+ });
154
+ writer(props).end(role, { fields: ROLE_DETAIL_FIELDS });
155
+ };
156
+ const resetPassword = async (props) => {
157
+ const { branchId, branch } = await resolveBranchFromProps(props);
158
+ const { fromSdkError, getNeonClient } = await import("../neon_client.js");
159
+ const role = await getNeonClient(props).postgres.roles.resetPassword({
160
+ projectId: props.projectId,
161
+ branchId,
162
+ roleName: props.role
163
+ }, { waitForReadiness: props.wait }).catch((error) => {
164
+ throw fromSdkError(error, props.apiHost);
165
+ });
166
+ const branchLabel = branch?.name ?? branchId;
167
+ writer(props).end(role, {
168
+ fields: CREATED_ROLE_FIELDS,
169
+ humanTitle: props.wait ? `Password reset for ${props.role} on ${branchLabel}` : `Password reset for ${props.role} on ${branchLabel} accepted, not yet applied`
170
+ });
171
+ };
172
+ export { create as a, get as c, resetPassword as d, roles_exports as f, command as i, handler as l, builder as n, deleteRole as o, builderFor as r, describe as s, aliases as t, list as u };
package/dist/api.js CHANGED
@@ -194,6 +194,15 @@ function unreadableBodyError(response, cause) {
194
194
  });
195
195
  }
196
196
  /**
197
+ * Encode one segment of a path built outside the SDK. `encodeURIComponent` leaves `.` and
198
+ * `..` intact, and URL parsing then resolves them as dot segments, so the request would go to
199
+ * a different route.
200
+ */
201
+ function pathSegment(name, value) {
202
+ if (value === "." || value === "..") throw new Error(`Path parameter ${name} cannot be "${value}".`);
203
+ return encodeURIComponent(value);
204
+ }
205
+ /**
197
206
  * Translate a thrown `fetch` failure into a {@link NeonApiError}. A request
198
207
  * timeout uses `ECONNABORTED` (matching the old axios behaviour, and excluded
199
208
  * from `isNetworkError`'s connectivity codes so it's still reported as a
@@ -313,6 +322,7 @@ const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }
313
322
  } catch (err) {
314
323
  throw networkError(err);
315
324
  }
325
+ if (result.error instanceof Error && "kind" in result.error && result.error.kind === "client") throw result.error;
316
326
  const response = result.response;
317
327
  if (!response) throw networkError(result.error ?? /* @__PURE__ */ new Error("No response from Neon API"));
318
328
  if (!response.ok) throw httpError(response, rawErrorBody(result.error) ?? result.data);
@@ -1088,4 +1098,4 @@ const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }
1088
1098
  }))
1089
1099
  };
1090
1100
  };
1091
- export { ContentType, DEFAULT_API_HOST, NeonApiError, RETRY_COUNT, UnreadableResponseError, cliFetch, codeFromBody, getApiClient, httpError, isNeonApiError, messageFromBody, retryOnLock };
1101
+ export { ContentType, DEFAULT_API_HOST, NeonApiError, RETRY_COUNT, UnreadableResponseError, cliFetch, codeFromBody, getApiClient, httpError, isNeonApiError, messageFromBody, pathSegment, retryOnLock, unreadableBodyError };
@@ -1,3 +1,4 @@
1
+ import { pathSegment } from "../api.js";
1
2
  // src/claimable/api.ts
2
3
  const REQUEST_TIMEOUT_MS = 6e4;
3
4
  const JWT_BEARER_GRANT = "urn:ietf:params:oauth:grant-type:jwt-bearer";
@@ -198,19 +199,19 @@ var ClaimableClient = class {
198
199
  }));
199
200
  }
200
201
  async credentials(projectId, accessToken) {
201
- return parseCredentialsResponse(await this.request(`/v1/projects/${encodeURIComponent(projectId)}/credentials`, { accessToken }));
202
+ return parseCredentialsResponse(await this.request(`/v1/projects/${pathSegment("project_id", projectId)}/credentials`, { accessToken }));
202
203
  }
203
204
  async createClaim(projectId, accessToken) {
204
- return parseClaimCodeResponse(await this.request(`/v1/projects/${encodeURIComponent(projectId)}/claim`, {
205
+ return parseClaimCodeResponse(await this.request(`/v1/projects/${pathSegment("project_id", projectId)}/claim`, {
205
206
  method: "POST",
206
207
  accessToken
207
208
  }));
208
209
  }
209
210
  async claimStatus(projectId, accessToken) {
210
- return parseClaimStatusResponse(await this.request(`/v1/projects/${encodeURIComponent(projectId)}/claim`, { accessToken }));
211
+ return parseClaimStatusResponse(await this.request(`/v1/projects/${pathSegment("project_id", projectId)}/claim`, { accessToken }));
211
212
  }
212
213
  async deleteProject(projectId, accessToken) {
213
- await this.request(`/v1/projects/${encodeURIComponent(projectId)}`, {
214
+ await this.request(`/v1/projects/${pathSegment("project_id", projectId)}`, {
214
215
  method: "DELETE",
215
216
  accessToken
216
217
  });
@@ -0,0 +1 @@
1
+ export { t as aliases, n as builder, r as builderFor, i as command, o as deleteCompute, s as describe, c as get, l as handler, u as list, d as restart, f as start, p as suspend, m as update } from "../_chunks/computes-OKFUNFee.js";
@@ -1 +1 @@
1
- export { t as SSL_MODES, n as aliases, r as builder, i as command, o as describe, s as handler } from "../_chunks/connection_string-C9e7N4xk.js";
1
+ export { t as SSL_MODES, n as aliases, r as builder, i as builderFor, a as command, s as describe, c as handler } from "../_chunks/connection_string-6WhV4WFx.js";
@@ -1 +1 @@
1
- export { t as DATABASE_FIELDS, n as aliases, r as builder, i as command, a as create, s as deleteDb, c as describe, l as handler, u as list } from "../_chunks/databases-B2Yapqme.js";
1
+ export { t as DATABASE_FIELDS, n as aliases, r as builder, i as builderFor, a as command, o as create, c as deleteDb, l as describe, u as handler, d as list } from "../_chunks/databases-B-qY303S.js";
@@ -14,10 +14,10 @@ import { r as branches_exports } from "../_chunks/branches-Bp-5z1lM.js";
14
14
  import { n as bucket_exports } from "../_chunks/bucket-D06bvDSa.js";
15
15
  import { n as checkout_exports } from "../_chunks/checkout-CNBIS3gA.js";
16
16
  import { o as claim_exports } from "../_chunks/claim-DhV0f_5o.js";
17
- import { a as connection_string_exports } from "../_chunks/connection_string-C9e7N4xk.js";
17
+ import { o as connection_string_exports } from "../_chunks/connection_string-6WhV4WFx.js";
18
18
  import { a as credentials_exports } from "../_chunks/credentials-BMBNmW0t.js";
19
19
  import { r as data_api_exports } from "../_chunks/data_api-CHDwvMTG.js";
20
- import { o as databases_exports } from "../_chunks/databases-B2Yapqme.js";
20
+ import { s as databases_exports } from "../_chunks/databases-B-qY303S.js";
21
21
  import { r as deploy_exports } from "../_chunks/deploy-Bs5gmi4Q.js";
22
22
  import { s as dev_exports } from "../_chunks/dev-DxiIp4c9.js";
23
23
  import { i as diff_exports } from "../_chunks/diff-dnxneH0u.js";
@@ -33,10 +33,11 @@ import { a as neon_auth_exports } from "../_chunks/neon_auth-C1CgNTGP.js";
33
33
  import { a as open_exports } from "../_chunks/open-T2nI89Oh.js";
34
34
  import { c as operations_exports } from "../_chunks/operations-D7qGkKo3.js";
35
35
  import { o as orgs_exports } from "../_chunks/orgs-Dpbr-K0A.js";
36
+ import { o as psql_exports } from "../_chunks/psql-BcxiPR4W.js";
37
+ import { f as roles_exports } from "../_chunks/roles-BELJqjTy.js";
38
+ import { o as postgres_exports } from "../_chunks/postgres-BhR1vUFM.js";
36
39
  import { o as profile_exports } from "../_chunks/profile-BAlM625e.js";
37
- import { a as psql_exports } from "../_chunks/psql-Bce4X0NG.js";
38
40
  import { s as realtime_exports } from "../_chunks/realtime-BwtzYf5a.js";
39
- import { l as roles_exports } from "../_chunks/roles-CNoDyRf4.js";
40
41
  import { a as set_context_exports } from "../_chunks/set_context-ompB6d2D.js";
41
42
  import { s as snapshots_exports } from "../_chunks/snapshots-DxNhjcco.js";
42
43
  import { a as status_exports } from "../_chunks/status-BlrzeKyA.js";
@@ -56,6 +57,7 @@ var commands_default = [
56
57
  vpc_endpoints_exports,
57
58
  neon_auth_exports,
58
59
  branches_exports,
60
+ postgres_exports,
59
61
  databases_exports,
60
62
  roles_exports,
61
63
  operations_exports,
@@ -71,6 +71,12 @@ const commandManifest = [
71
71
  describe: "Manage branches",
72
72
  load: () => import("./branches.js")
73
73
  },
74
+ {
75
+ command: "postgres",
76
+ aliases: ["pg", "lakebase"],
77
+ describe: "Manage Postgres computes, databases, and roles, and connect with psql or a connection string",
78
+ load: () => import("./postgres.js")
79
+ },
74
80
  {
75
81
  command: "databases",
76
82
  aliases: ["database", "db"],
@@ -0,0 +1 @@
1
+ export { t as aliases, n as builder, r as command, i as describe, a as handler } from "../_chunks/postgres-BhR1vUFM.js";
@@ -1 +1 @@
1
- export { t as builder, n as command, r as describe, i as handler } from "../_chunks/psql-Bce4X0NG.js";
1
+ export { t as builder, n as builderFor, r as command, i as describe, a as handler } from "../_chunks/psql-BcxiPR4W.js";
@@ -1 +1 @@
1
- export { t as aliases, n as builder, r as command, i as create, a as deleteRole, o as describe, s as handler, c as list } from "../_chunks/roles-CNoDyRf4.js";
1
+ export { t as aliases, n as builder, r as builderFor, i as command, a as create, o as deleteRole, s as describe, c as get, l as handler, u as list, d as resetPassword } from "../_chunks/roles-BELJqjTy.js";
@@ -1,5 +1,6 @@
1
+ import { pathSegment } from "./api.js";
1
2
  // src/custom_domains_api.ts
2
- const customDomainsPath = (projectId, branchId) => `/projects/${encodeURIComponent(projectId)}/branches/${encodeURIComponent(branchId)}/custom-domains`;
3
+ const customDomainsPath = (projectId, branchId) => `/projects/${pathSegment("project_id", projectId)}/branches/${pathSegment("branch_id", branchId)}/custom-domains`;
3
4
  const listCustomDomains = async (apiClient, projectId, branchId, { cursor, limit } = {}) => {
4
5
  const { data } = await apiClient.request({
5
6
  path: customDomainsPath(projectId, branchId),
@@ -28,7 +29,7 @@ const registerCustomDomain = async (apiClient, projectId, branchId, input) => {
28
29
  };
29
30
  const deleteCustomDomain = async (apiClient, projectId, branchId, domain) => {
30
31
  await apiClient.request({
31
- path: `${customDomainsPath(projectId, branchId)}/${encodeURIComponent(domain)}`,
32
+ path: `${customDomainsPath(projectId, branchId)}/${pathSegment("domain", domain)}`,
32
33
  method: "DELETE",
33
34
  secure: true
34
35
  });
@@ -1,6 +1,6 @@
1
- import "./api.js";
1
+ import { pathSegment } from "./api.js";
2
2
  // src/functions_api.ts
3
- const functionsPath = (projectId, branchId) => `/projects/${encodeURIComponent(projectId)}/branches/${encodeURIComponent(branchId)}/functions`;
3
+ const functionsPath = (projectId, branchId) => `/projects/${pathSegment("project_id", projectId)}/branches/${pathSegment("branch_id", branchId)}/functions`;
4
4
  const listFunctions = async (apiClient, projectId, branchId, { cursor, limit } = {}) => {
5
5
  const { data } = await apiClient.request({
6
6
  path: functionsPath(projectId, branchId),
@@ -19,7 +19,7 @@ const listFunctions = async (apiClient, projectId, branchId, { cursor, limit } =
19
19
  };
20
20
  const getFunction = async (apiClient, projectId, branchId, slug) => {
21
21
  const { data } = await apiClient.request({
22
- path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}`,
22
+ path: `${functionsPath(projectId, branchId)}/${pathSegment("slug", slug)}`,
23
23
  method: "GET",
24
24
  secure: true,
25
25
  format: "json"
@@ -28,7 +28,7 @@ const getFunction = async (apiClient, projectId, branchId, slug) => {
28
28
  };
29
29
  const deleteFunction = async (apiClient, projectId, branchId, slug) => {
30
30
  await apiClient.request({
31
- path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}`,
31
+ path: `${functionsPath(projectId, branchId)}/${pathSegment("slug", slug)}`,
32
32
  method: "DELETE",
33
33
  secure: true
34
34
  });
@@ -39,7 +39,7 @@ const createDeployment = async (apiClient, projectId, branchId, slug, params) =>
39
39
  form.append("runtime", params.runtime);
40
40
  if (params.environment) form.append("environment", params.environment);
41
41
  await apiClient.request({
42
- path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}/deployments`,
42
+ path: `${functionsPath(projectId, branchId)}/${pathSegment("slug", slug)}/deployments`,
43
43
  method: "POST",
44
44
  type: "multipart/form-data",
45
45
  body: form,
@@ -1,4 +1,4 @@
1
- import { cliFetch, httpError } from "./api.js";
1
+ import { cliFetch, httpError, unreadableBodyError } from "./api.js";
2
2
  import { NeonApiError, createNeonClient } from "@neon/sdk";
3
3
  // src/neon_client.ts
4
4
  /**
@@ -21,7 +21,7 @@ const getNeonClient = ({ apiKey, apiHost, requestTimeoutMs }) => createNeonClien
21
21
  */
22
22
  function fromSdkError(error, apiHost) {
23
23
  const base = apiHost ?? "https://console.neon.tech/api/v2";
24
- if (error instanceof NeonApiError && error.response?.url.startsWith(base)) return httpError(error.response, error.body);
24
+ if (error instanceof NeonApiError && error.response?.url.startsWith(base)) return error.response.ok ? unreadableBodyError(error.response, error.body) : httpError(error.response, error.body);
25
25
  return new Error(error instanceof Error ? error.message : String(error));
26
26
  }
27
27
  export { fromSdkError, getNeonClient };
@@ -1,6 +1,7 @@
1
+ import { pathSegment } from "./api.js";
1
2
  // src/storage_api.ts
2
- const bucketsPath = (projectId, branchId) => `/projects/${encodeURIComponent(projectId)}/branches/${encodeURIComponent(branchId)}/buckets`;
3
- const bucketPath = (projectId, branchId, bucketName) => `${bucketsPath(projectId, branchId)}/${encodeURIComponent(bucketName)}`;
3
+ const bucketsPath = (projectId, branchId) => `/projects/${pathSegment("project_id", projectId)}/branches/${pathSegment("branch_id", branchId)}/buckets`;
4
+ const bucketPath = (projectId, branchId, bucketName) => `${bucketsPath(projectId, branchId)}/${pathSegment("bucket_name", bucketName)}`;
4
5
  /**
5
6
  * Create a bucket on a branch.
6
7
  *
@@ -66,7 +67,7 @@ const listProjectBranchBucketObjects = (apiClient, { projectId, branchId, bucket
66
67
  * @request GET /projects/{project_id}/branches/{branch_id}/buckets/{bucket_name}/objects/{object_key}/download
67
68
  */
68
69
  const getProjectBranchBucketObject = (apiClient, { projectId, branchId, bucketName, objectKey }) => apiClient.request({
69
- path: `${bucketPath(projectId, branchId, bucketName)}/objects/${encodeURIComponent(objectKey)}/download`,
70
+ path: `${bucketPath(projectId, branchId, bucketName)}/objects/${pathSegment("object_key", objectKey)}/download`,
70
71
  method: "GET",
71
72
  format: "stream",
72
73
  secure: true
@@ -80,7 +81,7 @@ const getProjectBranchBucketObject = (apiClient, { projectId, branchId, bucketNa
80
81
  * @request DELETE /projects/{project_id}/branches/{branch_id}/buckets/{bucket_name}/objects/{object_key}
81
82
  */
82
83
  const deleteProjectBranchBucketObject = (apiClient, { projectId, branchId, bucketName, objectKey }) => apiClient.request({
83
- path: `${bucketPath(projectId, branchId, bucketName)}/objects/${encodeURIComponent(objectKey)}`,
84
+ path: `${bucketPath(projectId, branchId, bucketName)}/objects/${pathSegment("object_key", objectKey)}`,
84
85
  method: "DELETE",
85
86
  secure: true
86
87
  });
@@ -122,7 +123,7 @@ const presignUpload = (apiClient, { projectId, branchId, bucketName, objectKey,
122
123
  if (contentType !== void 0) body.content_type = contentType;
123
124
  if (expiresInSeconds !== void 0) body.expires_in_seconds = expiresInSeconds;
124
125
  return apiClient.request({
125
- path: `${bucketPath(projectId, branchId, bucketName)}/objects/${encodeURIComponent(objectKey)}/presign`,
126
+ path: `${bucketPath(projectId, branchId, bucketName)}/objects/${pathSegment("object_key", objectKey)}/presign`,
126
127
  method: "POST",
127
128
  body,
128
129
  format: "json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "8.20.1",
3
+ "version": "8.22.0",
4
4
  "description": "CLI tool for Neon, the cloud backend primitives built around Lakebase Postgres",
5
5
  "keywords": [
6
6
  "neon",
@@ -73,10 +73,10 @@
73
73
  "yaml": "^2.9.0",
74
74
  "yargs": "17.7.2",
75
75
  "yoctocolors": "^2.1.2",
76
+ "@neon/config": "1.11.1",
77
+ "@neon/config-runtime": "1.11.5",
76
78
  "@neon/realtime": "0.2.0",
77
- "@neon/config-runtime": "1.11.4",
78
- "@neon/config": "1.11.0",
79
- "@neon/sdk": "7.8.1"
79
+ "@neon/sdk": "7.8.2"
80
80
  },
81
81
  "optionalDependencies": {
82
82
  "@napi-rs/keyring": "1.3.0",
@@ -113,9 +113,9 @@
113
113
  "typescript": "^5.9.0",
114
114
  "vitest": "^3.0.9",
115
115
  "@neon-internals/cli-core": "0.0.0",
116
- "@neon-internals/env-core": "0.0.42",
116
+ "@neon-internals/env-core": "0.0.43",
117
117
  "@neon/e2e-harness": "0.0.0",
118
- "@neon/env": "1.6.12",
118
+ "@neon/env": "1.6.13",
119
119
  "@neon/functions": "0.11.0"
120
120
  },
121
121
  "publishConfig": {