neon 8.17.1 → 8.18.1
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 +6 -3
- package/dist/_chunks/{roles-BVc69rjG.js → roles-CNoDyRf4.js} +46 -1
- package/dist/api.js +11 -2
- package/dist/commands/index.js +1 -1
- package/dist/commands/roles.js +1 -1
- package/dist/commands/subscribe.js +28 -15
- package/dist/neon_client.js +27 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -330,9 +330,12 @@ neon realtime subscribe "SELECT id, title, completed FROM realtime_todos ORDER B
|
|
|
330
330
|
The default terminal output is append-only. It identifies the selected project,
|
|
331
331
|
branch, and database; prints the initial result once; reports connection-state
|
|
332
332
|
changes; and then prints each published change set with its transaction IDs, a compact
|
|
333
|
-
`+insert ~update -delete` summary, and the affected rows.
|
|
334
|
-
|
|
335
|
-
|
|
333
|
+
`+insert ~update -delete` summary, and the affected rows. Row moves appear as
|
|
334
|
+
`↔ move` with a separate `↔` count and retain the row's values. It does not take
|
|
335
|
+
over the terminal or require keyboard navigation. Pass `--changes` to display the
|
|
336
|
+
raw `rows` and `changes` events instead of the materialized view. Raw table output
|
|
337
|
+
includes each move's `after_row_id` destination, with `(head)` for the first
|
|
338
|
+
position, and counts moves separately from removals.
|
|
336
339
|
|
|
337
340
|
For scripts and agents, JSON output is a JSON Lines stream with one complete event
|
|
338
341
|
per line. YAML output uses one document per event:
|
|
@@ -20,6 +20,11 @@ const CREATED_ROLE_FIELDS = [
|
|
|
20
20
|
"password",
|
|
21
21
|
"created_at"
|
|
22
22
|
];
|
|
23
|
+
const ROLE_ACCESS = [
|
|
24
|
+
"admin",
|
|
25
|
+
"read_only",
|
|
26
|
+
"read_write"
|
|
27
|
+
];
|
|
23
28
|
const command = "roles";
|
|
24
29
|
const describe = "Manage roles";
|
|
25
30
|
const aliases = ["role"];
|
|
@@ -32,7 +37,7 @@ const builder = (argv) => argv.usage("$0 roles <sub-command> [options]").options
|
|
|
32
37
|
describe: "Branch ID or name",
|
|
33
38
|
type: "string"
|
|
34
39
|
}
|
|
35
|
-
}).middleware(fillSingleProject).command("list", "List roles", (yargs) => yargs, (args) => list(args)).command("create", "Create a role", (yargs) => yargs.options({
|
|
40
|
+
}).middleware(fillSingleProject).command("list", "List roles", (yargs) => yargs, (args) => list(args)).command("create", "Create a role. By default it joins neon_superuser (admin on every database); pass --access read_only or read_write for a scoped role", (yargs) => yargs.options({
|
|
36
41
|
name: {
|
|
37
42
|
describe: "Role name",
|
|
38
43
|
type: "string",
|
|
@@ -41,7 +46,25 @@ const builder = (argv) => argv.usage("$0 roles <sub-command> [options]").options
|
|
|
41
46
|
"no-login": {
|
|
42
47
|
describe: "Create a passwordless role that cannot login",
|
|
43
48
|
boolean: true
|
|
49
|
+
},
|
|
50
|
+
access: {
|
|
51
|
+
describe: "admin joins neon_superuser. read_only grants SELECT; read_write adds INSERT, UPDATE, DELETE. Scoped roles are created with SQL as the database owner and cover tables that owner owns, now and later",
|
|
52
|
+
type: "string",
|
|
53
|
+
choices: ROLE_ACCESS,
|
|
54
|
+
default: "admin"
|
|
55
|
+
},
|
|
56
|
+
database: {
|
|
57
|
+
describe: "Database a read_only or read_write role is scoped to. Defaults to the branch's only database",
|
|
58
|
+
type: "string"
|
|
59
|
+
},
|
|
60
|
+
schema: {
|
|
61
|
+
describe: "Schema a read_only or read_write role can use. Repeat for more. Defaults to public",
|
|
62
|
+
type: "string",
|
|
63
|
+
array: true
|
|
44
64
|
}
|
|
65
|
+
}).check((args) => {
|
|
66
|
+
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
|
+
return true;
|
|
45
68
|
}), (args) => create(args)).command("delete <role>", "Delete a role", (yargs) => yargs, (args) => deleteRole(args));
|
|
46
69
|
const handler = (args) => {
|
|
47
70
|
return args;
|
|
@@ -59,6 +82,28 @@ const list = async (props) => {
|
|
|
59
82
|
const create = async (props) => {
|
|
60
83
|
const noLogin = props["no-login"] === true || props.login === false;
|
|
61
84
|
const { branchId, branch } = await resolveBranchFromProps(props);
|
|
85
|
+
if (props.access === "read_only" || props.access === "read_write") {
|
|
86
|
+
const { fromSdkError, getNeonClient } = await import("../neon_client.js");
|
|
87
|
+
let role;
|
|
88
|
+
try {
|
|
89
|
+
role = await getNeonClient(props).postgres.roles.create({
|
|
90
|
+
projectId: props.projectId,
|
|
91
|
+
branchId,
|
|
92
|
+
name: props.name,
|
|
93
|
+
...noLogin ? { no_login: true } : {},
|
|
94
|
+
access: props.access,
|
|
95
|
+
...props.database === void 0 ? {} : { databaseName: props.database },
|
|
96
|
+
...props.schema === void 0 ? {} : { schemas: props.schema }
|
|
97
|
+
}, { waitForReadiness: true });
|
|
98
|
+
} catch (error) {
|
|
99
|
+
throw fromSdkError(error, props.apiHost);
|
|
100
|
+
}
|
|
101
|
+
writer(props).end(role, {
|
|
102
|
+
fields: CREATED_ROLE_FIELDS,
|
|
103
|
+
humanTitle: `Role created on ${branch?.name ?? branchId}`
|
|
104
|
+
});
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
62
107
|
const { data } = await retryOnLock(() => props.apiClient.createProjectBranchRole(props.projectId, branchId, { role: {
|
|
63
108
|
name: props.name,
|
|
64
109
|
...noLogin ? { no_login: true } : {}
|
package/dist/api.js
CHANGED
|
@@ -258,7 +258,7 @@ const RETRY_DELAY = 3e3;
|
|
|
258
258
|
const retryOnLock = async (fn) => {
|
|
259
259
|
let attempt = 0;
|
|
260
260
|
let errOut;
|
|
261
|
-
while (attempt <
|
|
261
|
+
while (attempt < 5) try {
|
|
262
262
|
return await fn();
|
|
263
263
|
} catch (err) {
|
|
264
264
|
errOut = err;
|
|
@@ -287,6 +287,15 @@ async function readJsonBody(response) {
|
|
|
287
287
|
return text;
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
+
/** The fetch {@link getApiClient} sends requests with, for clients built outside it. */
|
|
291
|
+
const cliFetch = (requestTimeoutMs = REQUEST_TIMEOUT_MS) => {
|
|
292
|
+
const fetchWithTimeout = makeTimedFetch(validateRequestTimeout(requestTimeoutMs));
|
|
293
|
+
return (input, init) => {
|
|
294
|
+
const request = new Request(input, init);
|
|
295
|
+
request.headers.set("User-Agent", USER_AGENT);
|
|
296
|
+
return fetchWithTimeout(request);
|
|
297
|
+
};
|
|
298
|
+
};
|
|
290
299
|
const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }) => {
|
|
291
300
|
const baseUrl = apiHost ?? "https://console.neon.tech/api/v2";
|
|
292
301
|
const fetchWithTimeout = makeTimedFetch(validateRequestTimeout(requestTimeoutMs));
|
|
@@ -1079,4 +1088,4 @@ const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }
|
|
|
1079
1088
|
}))
|
|
1080
1089
|
};
|
|
1081
1090
|
};
|
|
1082
|
-
export { ContentType, DEFAULT_API_HOST, NeonApiError, UnreadableResponseError, codeFromBody, getApiClient, isNeonApiError, messageFromBody, retryOnLock };
|
|
1091
|
+
export { ContentType, DEFAULT_API_HOST, NeonApiError, RETRY_COUNT, UnreadableResponseError, cliFetch, codeFromBody, getApiClient, httpError, isNeonApiError, messageFromBody, retryOnLock };
|
package/dist/commands/index.js
CHANGED
|
@@ -36,7 +36,7 @@ import { o as orgs_exports } from "../_chunks/orgs-Dpbr-K0A.js";
|
|
|
36
36
|
import { o as profile_exports } from "../_chunks/profile-BAlM625e.js";
|
|
37
37
|
import { a as psql_exports } from "../_chunks/psql-Bce4X0NG.js";
|
|
38
38
|
import { s as realtime_exports } from "../_chunks/realtime-BwtzYf5a.js";
|
|
39
|
-
import { l as roles_exports } from "../_chunks/roles-
|
|
39
|
+
import { l as roles_exports } from "../_chunks/roles-CNoDyRf4.js";
|
|
40
40
|
import { a as set_context_exports } from "../_chunks/set_context-ompB6d2D.js";
|
|
41
41
|
import { s as snapshots_exports } from "../_chunks/snapshots-DxNhjcco.js";
|
|
42
42
|
import { a as status_exports } from "../_chunks/status-BlrzeKyA.js";
|
package/dist/commands/roles.js
CHANGED
|
@@ -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-
|
|
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";
|
|
@@ -171,11 +171,13 @@ const renderTableEvent = (out, event, now) => {
|
|
|
171
171
|
const rows = event.changes.map((change) => ({
|
|
172
172
|
type: change.type,
|
|
173
173
|
row_id: change.rowId,
|
|
174
|
+
after_row_id: change.type === "move" ? change.afterRowId ?? "(head)" : void 0,
|
|
174
175
|
row: change.type === "upsert" ? change.row : void 0
|
|
175
176
|
}));
|
|
176
177
|
renderRows(out, rows, [
|
|
177
178
|
"type",
|
|
178
179
|
"row_id",
|
|
180
|
+
"after_row_id",
|
|
179
181
|
"row"
|
|
180
182
|
], `${timestamp(now)} ${transactionLabel(event.txids)} · ${rawChangeSummary(event.changes)}`, "Changes event contains no row changes.");
|
|
181
183
|
};
|
|
@@ -210,13 +212,14 @@ const renderHumanChanges = (out, event, rowsById, now) => {
|
|
|
210
212
|
const inserted = changes.filter((change) => change.operation === "+ insert");
|
|
211
213
|
const updated = changes.filter((change) => change.operation === "~ update");
|
|
212
214
|
const deleted = changes.filter((change) => change.operation === "- delete");
|
|
215
|
+
const moved = changes.filter((change) => change.operation === "↔ move");
|
|
213
216
|
const rowFieldsInChanges = rowFields(changes.flatMap((change) => change.row ? [change.row] : []));
|
|
214
217
|
const operationField = uniqueOperationField(rowFieldsInChanges);
|
|
215
218
|
const rows = changes.map((change) => ({
|
|
216
219
|
...change.row ?? {},
|
|
217
220
|
[operationField]: change.operation
|
|
218
221
|
}));
|
|
219
|
-
renderRows(out, rows, [operationField, ...rowFieldsInChanges], `${timestamp(now)} ${transactionLabel(event.txids)} · +${inserted.length} ~${updated.length} -${deleted.length}`, "Transaction contains no row changes.");
|
|
222
|
+
renderRows(out, rows, [operationField, ...rowFieldsInChanges], `${timestamp(now)} ${transactionLabel(event.txids)} · +${inserted.length} ~${updated.length} -${deleted.length}${moved.length ? ` ↔${moved.length}` : ""}`, "Transaction contains no row changes.");
|
|
220
223
|
};
|
|
221
224
|
const renderRows = (out, rows, fields, title, emptyMessage) => {
|
|
222
225
|
writer({
|
|
@@ -229,20 +232,29 @@ const renderRows = (out, rows, fields, title, emptyMessage) => {
|
|
|
229
232
|
if (rows.length === 0) out.write(`${emptyMessage}\n`);
|
|
230
233
|
};
|
|
231
234
|
const classifyChanges = (changes, rowsById) => changes.map((change) => {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
switch (change.type) {
|
|
236
|
+
case "upsert": {
|
|
237
|
+
const operation = rowsById.has(change.rowId) ? "~ update" : "+ insert";
|
|
238
|
+
rowsById.set(change.rowId, change.row);
|
|
239
|
+
return {
|
|
240
|
+
operation,
|
|
241
|
+
row: change.row
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
case "remove": {
|
|
245
|
+
const row = rowsById.get(change.rowId);
|
|
246
|
+
rowsById.delete(change.rowId);
|
|
247
|
+
return {
|
|
248
|
+
operation: "- delete",
|
|
249
|
+
...row ? { row } : {}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
case "move": return {
|
|
253
|
+
operation: "↔ move",
|
|
254
|
+
row: rowsById.get(change.rowId)
|
|
238
255
|
};
|
|
256
|
+
default: throw new Error(`Unsupported Realtime change: ${change}`);
|
|
239
257
|
}
|
|
240
|
-
const row = rowsById.get(change.rowId);
|
|
241
|
-
rowsById.delete(change.rowId);
|
|
242
|
-
return {
|
|
243
|
-
operation: "- delete",
|
|
244
|
-
...row ? { row } : {}
|
|
245
|
-
};
|
|
246
258
|
});
|
|
247
259
|
const uniqueOperationField = (fields) => {
|
|
248
260
|
for (const candidate of [
|
|
@@ -260,8 +272,9 @@ const transactionLabel = (txids) => {
|
|
|
260
272
|
};
|
|
261
273
|
const rawChangeSummary = (changes) => {
|
|
262
274
|
const upserts = changes.filter((change) => change.type === "upsert").length;
|
|
263
|
-
const removals = changes.
|
|
264
|
-
|
|
275
|
+
const removals = changes.filter((change) => change.type === "remove").length;
|
|
276
|
+
const moves = changes.filter((change) => change.type === "move").length;
|
|
277
|
+
return `${upserts} upsert${upserts === 1 ? "" : "s"}, ${removals} removal${removals === 1 ? "" : "s"}${moves ? `, ${moves} move${moves === 1 ? "" : "s"}` : ""}`;
|
|
265
278
|
};
|
|
266
279
|
const rowCount = (count) => `${count} ${count === 1 ? "row" : "rows"}`;
|
|
267
280
|
const timestamp = (now) => `[${now().toISOString()}]`;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { cliFetch, httpError } from "./api.js";
|
|
2
|
+
import { NeonApiError, createNeonClient } from "@neon/sdk";
|
|
3
|
+
// src/neon_client.ts
|
|
4
|
+
/**
|
|
5
|
+
* The `@neon/sdk` ergonomic client, for commands that run one of its multi-step workflows,
|
|
6
|
+
* with the timeout, debug logging, user agent, and 423 retries of `getApiClient`. Throws;
|
|
7
|
+
* pass failures through {@link fromSdkError}.
|
|
8
|
+
*/
|
|
9
|
+
const getNeonClient = ({ apiKey, apiHost, requestTimeoutMs }) => createNeonClient({
|
|
10
|
+
apiKey,
|
|
11
|
+
baseUrl: apiHost ?? "https://console.neon.tech/api/v2",
|
|
12
|
+
fetch: cliFetch(requestTimeoutMs),
|
|
13
|
+
retries: 5,
|
|
14
|
+
throwOnError: true
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Map an error from {@link getNeonClient} for the top-level handler. A management API
|
|
18
|
+
* response becomes the CLI's `NeonApiError`, so 401 and SSO recovery apply. Anything else
|
|
19
|
+
* keeps the SDK's message and drops its `cause`, so a socket code deep in the chain cannot
|
|
20
|
+
* turn a "role was created, but…" message into the generic connectivity hint.
|
|
21
|
+
*/
|
|
22
|
+
function fromSdkError(error, apiHost) {
|
|
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);
|
|
25
|
+
return new Error(error instanceof Error ? error.message : String(error));
|
|
26
|
+
}
|
|
27
|
+
export { fromSdkError, getNeonClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neon",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.18.1",
|
|
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-runtime": "1.11.
|
|
77
|
-
"@neon/config": "1.10.0",
|
|
76
|
+
"@neon/config-runtime": "1.11.2",
|
|
78
77
|
"@neon/realtime": "0.1.2",
|
|
79
|
-
"@neon/sdk": "7.
|
|
78
|
+
"@neon/sdk": "7.8.0",
|
|
79
|
+
"@neon/config": "1.10.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.
|
|
116
|
+
"@neon-internals/env-core": "0.0.40",
|
|
117
117
|
"@neon/e2e-harness": "0.0.0",
|
|
118
|
-
"@neon/env": "1.6.
|
|
118
|
+
"@neon/env": "1.6.10",
|
|
119
119
|
"@neon/functions": "0.11.0"
|
|
120
120
|
},
|
|
121
121
|
"publishConfig": {
|