neon 8.10.0 → 8.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1007,7 +1007,7 @@ Default table output is `Feedback received. Thank you!`. `--output json` and `--
1007
1007
 
1008
1008
  ## Search neon.com (`docs search`)
1009
1009
 
1010
- `neon docs search <query>` searches neon.com: the docs, API reference, PostgreSQL tutorial, guides, FAQs, changelog, and blog. It does not log in and does not use your Neon account. It uses the same search as the neon.com search box.
1010
+ `neon docs search <query>` searches neon.com: the docs, API reference, PostgreSQL tutorial, guides, FAQs, changelog, and blog. It does not log in and does not use your Neon account. It uses the same search as the neon.com search box. The search service records the query, the CLI version, and the detected coding agent; `--no-analytics` turns that off.
1011
1011
 
1012
1012
  ```bash
1013
1013
  neon docs search "reset a branch"
@@ -1015,7 +1015,7 @@ neon docs search "create branch" --category api --category docs
1015
1015
  neon docs search "pg_dump" --limit 5 --output json
1016
1016
  ```
1017
1017
 
1018
- `--category` limits results to `docs`, `api`, `postgresql`, `guides`, `faqs`, `blog`, or `changelog`; repeat it for more than one. `--limit` is 1 to 40, default 10. Default table output is one row per page: title, the section that matched, and URL. `--output json` and `--output yaml` print an array of hits with `title`, `url`, `category`, `breadcrumb`, `heading`, and `excerpt`, in rank order. No match prints `No results for "<query>".` and exits 0 (`[]` in JSON).
1018
+ `--category` limits results to `docs`, `api`, `postgresql`, `guides`, `faqs`, `blog`, or `changelog`; repeat it for more than one. `--limit` is 1 to 40, default 10. Default output is one block per result: `Title › Section` on one line, cut to the terminal width, and the full URL under it. `--output json` and `--output yaml` print an array of hits with `title`, `url`, `category`, `breadcrumb`, `heading`, and `excerpt`, in rank order. No match prints `No results for "<query>".` and exits 0 (`[]` in JSON).
1019
1019
 
1020
1020
  ## Install the Neon plugin (`plugins`)
1021
1021
 
@@ -1543,7 +1543,7 @@ Global options are supported with any Neon CLI command.
1543
1543
 
1544
1544
  - <a id="analytics"></a>`--analytics`
1545
1545
 
1546
- Analytics are enabled by default to gather information about the CLI commands and options that are used by our customers. This data collection assists in offering support, and allows for a better understanding of typical usage patterns so that we can improve user experience. Neon does not collect user-defined data, such as project IDs or command payloads, except the question passed to `neon ask --prompt`. When the CLI fails on an internal bug (a JavaScript `TypeError`, `ReferenceError`, `RangeError`, or `SyntaxError`), it also sends that error to Neon's Sentry: the error type, the message only when it is a standard JavaScript message that names nothing but code (any other message is replaced), the stack trace with file paths cut to the package (`neon/dist/...`), the CLI and Node.js versions, and whether it ran in CI or a coding agent. To opt-out of analytics data collection and error reports, specify `--no-analytics` or `--analytics false`.
1546
+ Analytics are enabled by default to gather information about the CLI commands and options that are used by our customers. This data collection assists in offering support, and allows for a better understanding of typical usage patterns so that we can improve user experience. Neon does not collect user-defined data, such as project IDs or command payloads, except the question passed to `neon ask --prompt` and the query passed to `neon docs search`. The Neon search service records each `neon docs search` query with the CLI version and the detected coding agent; with `--no-analytics` it records nothing. When the CLI fails on an internal bug (a JavaScript `TypeError`, `ReferenceError`, `RangeError`, or `SyntaxError`), it also sends that error to Neon's Sentry: the error type, the message only when it is a standard JavaScript message that names nothing but code (any other message is replaced), the stack trace with file paths cut to the package (`neon/dist/...`), the CLI and Node.js versions, and whether it ran in CI or a coding agent. To opt-out of analytics data collection and error reports, specify `--no-analytics` or `--analytics false`.
1547
1547
 
1548
1548
  - <a id="version"></a>`-v, --version`
1549
1549
 
@@ -1,7 +1,11 @@
1
1
  import { t as __exportAll } from "../_chunks/rolldown-runtime-8H4AJuhK.js";
2
+ import { getCliAgent, isCi } from "../env.js";
3
+ import pkg_default from "../pkg.js";
2
4
  import { isNetworkError } from "../errors.js";
5
+ import { resolveOutputWidth, stripAnsi, truncateTo } from "../human_table.js";
3
6
  import { writer } from "../writer.js";
4
7
  import { single } from "../utils/flags.js";
8
+ import chalk from "chalk";
5
9
  //#region src/commands/docs.ts
6
10
  var docs_exports = /* @__PURE__ */ __exportAll({
7
11
  DEFAULT_SITE_SEARCH_URL: () => DEFAULT_SITE_SEARCH_URL,
@@ -11,8 +15,10 @@ var docs_exports = /* @__PURE__ */ __exportAll({
11
15
  builder: () => builder,
12
16
  command: () => command,
13
17
  describe: () => describe,
18
+ formatSearchResults: () => formatSearchResults,
14
19
  parseSearchHits: () => parseSearchHits,
15
- resolveSiteSearchUrl: () => resolveSiteSearchUrl
20
+ resolveSiteSearchUrl: () => resolveSiteSearchUrl,
21
+ siteSearchHeaders: () => siteSearchHeaders
16
22
  });
17
23
  const DEFAULT_SITE_SEARCH_URL = "https://br-frosty-cell-a5smzg39-assistant.compute.c-1.us-east-2.aws.neon.tech/site-search";
18
24
  const SITE_SEARCH_CATEGORIES = [
@@ -76,22 +82,56 @@ const search = async (props) => {
76
82
  }),
77
83
  query,
78
84
  limit: props.limit,
79
- categories: props.category ? [...new Set(props.category)] : void 0
85
+ categories: props.category ? [...new Set(props.category)] : void 0,
86
+ headers: siteSearchHeaders({
87
+ analytics: props.analytics,
88
+ agent: getCliAgent(process.env),
89
+ version: pkg_default.version
90
+ })
80
91
  });
81
- writer(props).end(hits, {
82
- fields: [
83
- "title",
84
- "heading",
85
- "url"
86
- ],
87
- emptyMessage: `No results for "${query}".`,
88
- renderColumns: { heading: (hit) => sectionOf(hit) }
92
+ const emptyMessage = `No results for "${query}".`;
93
+ if (props.output === "json" || props.output === "yaml") {
94
+ writer(props).end(hits, {
95
+ fields: [
96
+ "title",
97
+ "heading",
98
+ "url"
99
+ ],
100
+ emptyMessage
101
+ });
102
+ return;
103
+ }
104
+ const text = formatSearchResults(hits, {
105
+ emptyMessage,
106
+ width: resolveOutputWidth(process.stdout, void 0, {
107
+ stdout: process.stdout,
108
+ envColumns: process.env.COLUMNS
109
+ })
89
110
  });
111
+ process.stdout.write(process.env.NO_COLOR || isCi() ? stripAnsi(text) : text);
90
112
  };
113
+ function formatSearchResults(hits, opts) {
114
+ if (hits.length === 0) return `\n${opts.emptyMessage}\n`;
115
+ return hits.map((hit) => {
116
+ const section = sectionOf(hit).split(" > ").filter(Boolean);
117
+ const line = [hit.title, ...section].join(" › ");
118
+ const shown = opts.width === void 0 ? line : truncateTo(line, opts.width);
119
+ return `${chalk.bold(shown)}\n ${chalk.cyan(hit.url)}\n`;
120
+ }).join("\n");
121
+ }
91
122
  function sectionOf(hit) {
92
123
  const parts = hit.heading.split(" > ");
93
124
  return (parts[0] === hit.title ? parts.slice(1) : parts).join(" > ");
94
125
  }
126
+ function siteSearchHeaders(opts) {
127
+ return {
128
+ "Content-Type": "application/json",
129
+ "User-Agent": `neon/${opts.version}`,
130
+ "x-neon-source": "cli",
131
+ ...opts.agent ? { "x-neon-client": encodeURIComponent(opts.agent) } : {},
132
+ ...opts.analytics ? {} : { "x-neon-analytics": "off" }
133
+ };
134
+ }
95
135
  function isTimeout(error) {
96
136
  return error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError");
97
137
  }
@@ -100,7 +140,7 @@ async function searchSite(opts) {
100
140
  try {
101
141
  const response = await fetch(opts.url, {
102
142
  method: "POST",
103
- headers: { "Content-Type": "application/json" },
143
+ headers: opts.headers,
104
144
  body: JSON.stringify({
105
145
  query: opts.query,
106
146
  limit: opts.limit,
@@ -154,4 +194,4 @@ function parseSearchHits(raw) {
154
194
  });
155
195
  }
156
196
  //#endregion
157
- export { DEFAULT_SITE_SEARCH_URL, MAX_LIMIT, MAX_QUERY_LENGTH, SITE_SEARCH_CATEGORIES, builder, command, describe, parseSearchHits, resolveSiteSearchUrl, docs_exports as t };
197
+ export { DEFAULT_SITE_SEARCH_URL, MAX_LIMIT, MAX_QUERY_LENGTH, SITE_SEARCH_CATEGORIES, builder, command, describe, formatSearchResults, parseSearchHits, resolveSiteSearchUrl, siteSearchHeaders, docs_exports as t };
@@ -226,4 +226,4 @@ function charWidth(code) {
226
226
  return 1;
227
227
  }
228
228
  //#endregion
229
- export { displayWidth, formatHumanChunk, parseColumns, resolveOutputWidth, stripAnsi, titleCaseField };
229
+ export { displayWidth, formatHumanChunk, parseColumns, resolveOutputWidth, stripAnsi, titleCaseField, truncateTo };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "8.10.0",
3
+ "version": "8.10.2",
4
4
  "description": "CLI tool for Neon, the cloud backend primitives built around Lakebase Postgres",
5
5
  "keywords": [
6
6
  "neon",
@@ -70,8 +70,8 @@
70
70
  "yaml": "^2.9.0",
71
71
  "yargs": "17.7.2",
72
72
  "yoctocolors": "^2.1.2",
73
- "@neon/config": "1.9.3",
74
73
  "@neon/realtime": "0.1.2",
74
+ "@neon/config": "1.9.3",
75
75
  "@neon/sdk": "7.4.0",
76
76
  "@neon/config-runtime": "1.10.2"
77
77
  },