neon 3.0.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.
Files changed (198) hide show
  1. package/README.md +54 -0
  2. package/dist/_shared/auth_selection.js +76 -79
  3. package/dist/_shared/credentials.js +166 -187
  4. package/dist/_shared/env-core/env.js +354 -517
  5. package/dist/_shared/env-core/reuse-secrets.js +159 -203
  6. package/dist/_shared/paths.js +129 -126
  7. package/dist/_shared/profiles.js +192 -242
  8. package/dist/_shared/secure_file.js +36 -38
  9. package/dist/_virtual/_rolldown/runtime.js +13 -0
  10. package/dist/analytics.js +163 -207
  11. package/dist/api.js +815 -758
  12. package/dist/auth.js +121 -141
  13. package/dist/auth_context.js +39 -53
  14. package/dist/cli.js +4 -7
  15. package/dist/commands/api.js +220 -250
  16. package/dist/commands/api_keys.js +251 -314
  17. package/dist/commands/auth.js +283 -328
  18. package/dist/commands/bootstrap.js +372 -437
  19. package/dist/commands/branches.js +304 -455
  20. package/dist/commands/bucket.js +374 -514
  21. package/dist/commands/checkout.js +213 -298
  22. package/dist/commands/config.js +573 -690
  23. package/dist/commands/connection_string.js +137 -165
  24. package/dist/commands/data_api.js +238 -260
  25. package/dist/commands/databases.js +67 -76
  26. package/dist/commands/deploy.js +31 -25
  27. package/dist/commands/dev.js +639 -719
  28. package/dist/commands/diff.js +156 -200
  29. package/dist/commands/env.js +243 -303
  30. package/dist/commands/functions.js +275 -355
  31. package/dist/commands/index.js +70 -65
  32. package/dist/commands/init.js +84 -119
  33. package/dist/commands/inspect.js +55 -55
  34. package/dist/commands/ip_allow.js +88 -120
  35. package/dist/commands/link.js +874 -1019
  36. package/dist/commands/logs.js +291 -0
  37. package/dist/commands/neon_auth.js +725 -933
  38. package/dist/commands/operations.js +34 -25
  39. package/dist/commands/orgs.js +28 -18
  40. package/dist/commands/profile.js +614 -845
  41. package/dist/commands/projects.js +313 -373
  42. package/dist/commands/psql.js +60 -58
  43. package/dist/commands/roles.js +55 -58
  44. package/dist/commands/schema_diff.js +87 -131
  45. package/dist/commands/set_context.js +34 -26
  46. package/dist/commands/snapshots.js +288 -413
  47. package/dist/commands/status.js +41 -37
  48. package/dist/commands/user.js +21 -10
  49. package/dist/commands/vpc_endpoints.js +85 -113
  50. package/dist/config.js +7 -6
  51. package/dist/config_format.js +50 -66
  52. package/dist/config_template.js +128 -157
  53. package/dist/context.js +183 -235
  54. package/dist/current_branch_fast_path.js +40 -49
  55. package/dist/dev/env.js +313 -394
  56. package/dist/dev/functions.js +54 -68
  57. package/dist/dev/inputs.js +46 -58
  58. package/dist/dev/runtime.js +135 -164
  59. package/dist/dev/websocket.js +766 -959
  60. package/dist/env.js +27 -33
  61. package/dist/env_file.js +118 -132
  62. package/dist/env_services.js +36 -38
  63. package/dist/errors.js +57 -68
  64. package/dist/functions_api.js +45 -43
  65. package/dist/help.js +189 -140
  66. package/dist/index.js +182 -257
  67. package/dist/init/agents.js +137 -118
  68. package/dist/init/auth.js +58 -68
  69. package/dist/init/bootstrap.js +325 -396
  70. package/dist/init/build_config.js +4 -2
  71. package/dist/init/detect_agent.js +56 -101
  72. package/dist/init/editors.js +35 -52
  73. package/dist/init/enrich_output.js +51 -66
  74. package/dist/init/extension.js +134 -171
  75. package/dist/init/inspect.js +179 -266
  76. package/dist/init/interactive.js +510 -622
  77. package/dist/init/neonctl.js +117 -168
  78. package/dist/init/orchestrate.js +157 -173
  79. package/dist/init/phases/auth.js +188 -202
  80. package/dist/init/phases/cleanup.js +23 -23
  81. package/dist/init/phases/db.js +251 -277
  82. package/dist/init/phases/getting_started.js +213 -223
  83. package/dist/init/phases/mcp.js +174 -224
  84. package/dist/init/phases/migrations.js +247 -248
  85. package/dist/init/phases/neon_auth.js +114 -133
  86. package/dist/init/phases/setup.js +546 -703
  87. package/dist/init/phases/skills.js +75 -86
  88. package/dist/init/phases/status.js +72 -67
  89. package/dist/init/resolve_context.js +102 -99
  90. package/dist/init/route_command.js +91 -98
  91. package/dist/init/skills.js +174 -218
  92. package/dist/init/vsix.js +77 -99
  93. package/dist/log.js +17 -16
  94. package/dist/neon_services.js +104 -129
  95. package/dist/parameters.gen.js +481 -471
  96. package/dist/pkg.js +17 -19
  97. package/dist/profile_keys.js +44 -47
  98. package/dist/psql/cli.js +44 -47
  99. package/dist/psql/command/cmd_cond.js +231 -406
  100. package/dist/psql/command/cmd_connect.js +557 -764
  101. package/dist/psql/command/cmd_copy.js +727 -983
  102. package/dist/psql/command/cmd_describe.js +1499 -1688
  103. package/dist/psql/command/cmd_format.js +733 -905
  104. package/dist/psql/command/cmd_io.js +1293 -2082
  105. package/dist/psql/command/cmd_lo.js +297 -359
  106. package/dist/psql/command/cmd_meta.js +727 -878
  107. package/dist/psql/command/cmd_misc.js +138 -172
  108. package/dist/psql/command/cmd_pipeline.js +547 -1099
  109. package/dist/psql/command/cmd_restrict.js +119 -155
  110. package/dist/psql/command/cmd_show.js +529 -688
  111. package/dist/psql/command/dispatch.js +261 -325
  112. package/dist/psql/command/inputQueue.js +35 -33
  113. package/dist/psql/command/shared.js +49 -63
  114. package/dist/psql/complete/filenames.js +90 -133
  115. package/dist/psql/complete/index.js +59 -97
  116. package/dist/psql/complete/matcher.js +236 -300
  117. package/dist/psql/complete/psqlVars.js +218 -223
  118. package/dist/psql/complete/queries.js +159 -177
  119. package/dist/psql/complete/rules.js +1493 -2299
  120. package/dist/psql/core/common.js +762 -1180
  121. package/dist/psql/core/help.js +456 -546
  122. package/dist/psql/core/mainloop.js +692 -1302
  123. package/dist/psql/core/prompt.js +391 -408
  124. package/dist/psql/core/settings.js +429 -644
  125. package/dist/psql/core/sqlHelp.js +480 -554
  126. package/dist/psql/core/startup.js +626 -815
  127. package/dist/psql/core/syncVars.js +67 -110
  128. package/dist/psql/core/variables.js +156 -278
  129. package/dist/psql/describe/formatters.js +884 -1285
  130. package/dist/psql/describe/processNamePattern.js +173 -260
  131. package/dist/psql/describe/queries.js +1368 -2403
  132. package/dist/psql/describe/versionGate.js +32 -41
  133. package/dist/psql/index.js +1414 -1927
  134. package/dist/psql/io/history.js +232 -271
  135. package/dist/psql/io/input.js +103 -108
  136. package/dist/psql/io/lineEditor/buffer.js +238 -319
  137. package/dist/psql/io/lineEditor/complete.js +135 -213
  138. package/dist/psql/io/lineEditor/filename.js +139 -148
  139. package/dist/psql/io/lineEditor/index.js +653 -870
  140. package/dist/psql/io/lineEditor/keymap.js +544 -702
  141. package/dist/psql/io/lineEditor/vt100.js +294 -341
  142. package/dist/psql/io/pgpass.js +158 -187
  143. package/dist/psql/io/pgservice.js +146 -183
  144. package/dist/psql/io/psqlrc.js +328 -403
  145. package/dist/psql/print/aligned.js +1020 -1683
  146. package/dist/psql/print/asciidoc.js +180 -214
  147. package/dist/psql/print/crosstab.js +281 -442
  148. package/dist/psql/print/csv.js +48 -70
  149. package/dist/psql/print/html.js +195 -226
  150. package/dist/psql/print/json.js +75 -88
  151. package/dist/psql/print/latex.js +291 -364
  152. package/dist/psql/print/pager.js +171 -242
  153. package/dist/psql/print/troff.js +194 -226
  154. package/dist/psql/print/unaligned.js +69 -95
  155. package/dist/psql/print/units.js +167 -169
  156. package/dist/psql/scanner/slash.js +428 -483
  157. package/dist/psql/scanner/sql.js +445 -889
  158. package/dist/psql/scanner/stringutils.js +309 -379
  159. package/dist/psql/types/index.js +2 -7
  160. package/dist/psql/types/scanner.js +25 -22
  161. package/dist/psql/wire/connection.js +2042 -2803
  162. package/dist/psql/wire/copy.js +84 -100
  163. package/dist/psql/wire/notify.js +39 -59
  164. package/dist/psql/wire/pipeline.js +305 -518
  165. package/dist/psql/wire/protocol.js +349 -417
  166. package/dist/psql/wire/sasl.js +180 -265
  167. package/dist/psql/wire/tls.js +400 -561
  168. package/dist/storage_api.js +115 -129
  169. package/dist/test_utils/fixtures.js +94 -113
  170. package/dist/test_utils/oauth_server.js +10 -7
  171. package/dist/test_utils/project_dir.js +33 -0
  172. package/dist/utils/ai_gateway_notice.js +131 -162
  173. package/dist/utils/api_enums.js +21 -28
  174. package/dist/utils/auth.js +10 -4
  175. package/dist/utils/branch_notice.js +20 -19
  176. package/dist/utils/branch_picker.js +83 -89
  177. package/dist/utils/cli_name.js +15 -12
  178. package/dist/utils/compute_units.js +20 -27
  179. package/dist/utils/config_diff.js +127 -158
  180. package/dist/utils/enrichers.js +95 -148
  181. package/dist/utils/esbuild.js +130 -189
  182. package/dist/utils/flags.js +35 -47
  183. package/dist/utils/formats.js +8 -15
  184. package/dist/utils/git_diff.js +69 -80
  185. package/dist/utils/inspect_db.js +101 -143
  186. package/dist/utils/inspect_queries.js +179 -142
  187. package/dist/utils/middlewares.js +37 -44
  188. package/dist/utils/openapi.js +87 -99
  189. package/dist/utils/package_manager.js +312 -110
  190. package/dist/utils/point_in_time.js +49 -53
  191. package/dist/utils/psql.js +89 -106
  192. package/dist/utils/service_picker.js +55 -58
  193. package/dist/utils/string.js +5 -5
  194. package/dist/utils/ui.js +38 -55
  195. package/dist/utils/write_sync.js +26 -35
  196. package/dist/utils/zip.js +4 -3
  197. package/dist/writer.js +67 -87
  198. package/package.json +7 -5
package/dist/env.js CHANGED
@@ -1,36 +1,30 @@
1
- export const isCi = () => {
2
- return process.env.CI !== "false" && Boolean(process.env.CI);
1
+ //#region src/env.ts
2
+ const isCi = () => {
3
+ return process.env.CI !== "false" && Boolean(process.env.CI);
3
4
  };
4
- export const isDebug = () => {
5
- return Boolean(process.env.DEBUG);
5
+ const isDebug = () => {
6
+ return Boolean(process.env.DEBUG);
6
7
  };
7
- export const getGithubEnvVars = (env) => {
8
- const vars = [
9
- // github action info
10
- "GITHUB_ACTION_PATH",
11
- // source github repository
12
- "GITHUB_REPOSITORY",
13
- // environment info
14
- "GITHUB_RUN_ID",
15
- "GITHUB_RUN_NUMBER",
16
- "GITHUB_SERVER_URL",
17
- "GITHUB_WORKFLOW_REF",
18
- "RUNNER_ARCH",
19
- "RUNNER_ENVIRONMENT",
20
- "RUNNER_OS",
21
- ];
22
- const map = new Map();
23
- vars.forEach((v) => {
24
- let value = env[v];
25
- if (value === undefined || value === "") {
26
- return;
27
- }
28
- if (v === "GITHUB_ACTION_PATH") {
29
- value = value.includes("actions/")
30
- ? value.replace(/^.*actions\/(.+)$/, "$1")
31
- : value;
32
- }
33
- map.set(v, value);
34
- });
35
- return Object.fromEntries(map);
8
+ const getGithubEnvVars = (env) => {
9
+ const vars = [
10
+ "GITHUB_ACTION_PATH",
11
+ "GITHUB_REPOSITORY",
12
+ "GITHUB_RUN_ID",
13
+ "GITHUB_RUN_NUMBER",
14
+ "GITHUB_SERVER_URL",
15
+ "GITHUB_WORKFLOW_REF",
16
+ "RUNNER_ARCH",
17
+ "RUNNER_ENVIRONMENT",
18
+ "RUNNER_OS"
19
+ ];
20
+ const map = /* @__PURE__ */ new Map();
21
+ vars.forEach((v) => {
22
+ let value = env[v];
23
+ if (value === void 0 || value === "") return;
24
+ if (v === "GITHUB_ACTION_PATH") value = value.includes("actions/") ? value.replace(/^.*actions\/(.+)$/, "$1") : value;
25
+ map.set(v, value);
26
+ });
27
+ return Object.fromEntries(map);
36
28
  };
29
+ //#endregion
30
+ export { getGithubEnvVars, isCi, isDebug };
package/dist/env_file.js CHANGED
@@ -1,159 +1,145 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
+ //#region src/env_file.ts
3
4
  /**
4
- * Default dotenv file `env pull` writes to: `.env` when one already exists in the working
5
- * directory (update where secrets already live), otherwise `.env.local` — matching the
6
- * `vercel env pull` convention. An explicit `--file` always wins over this.
7
- */
8
- export const resolveEnvFilePath = (cwd, file) => {
9
- if (file)
10
- return join(cwd, file);
11
- if (existsSync(join(cwd, ".env")))
12
- return join(cwd, ".env");
13
- return join(cwd, ".env.local");
5
+ * Default dotenv file `env pull` writes to: `.env` when one already exists in the working
6
+ * directory (update where secrets already live), otherwise `.env.local` — matching the
7
+ * `vercel env pull` convention. An explicit `--file` always wins over this.
8
+ */
9
+ const resolveEnvFilePath = (cwd, file) => {
10
+ if (file) return join(cwd, file);
11
+ if (existsSync(join(cwd, ".env"))) return join(cwd, ".env");
12
+ return join(cwd, ".env.local");
14
13
  };
15
14
  /**
16
- * Merge `updates` into the dotenv content at `path`, preserving every other line
17
- * (comments, blank lines, unrelated keys) and the file's existing order. Keys present in
18
- * both are updated in place; keys only in `updates` are appended. A non-existent file is
19
- * treated as empty. When `managedKeys` is given, any owned key on disk that is absent from
20
- * `updates` is removed. Returns the keys written and the (managed) keys removed.
21
- */
22
- export const mergeEnvFile = (path, updates, options = {}) => {
23
- const original = existsSync(path) ? readFileSync(path, "utf8") : "";
24
- const { content, written, removed } = mergeEnvContent(original, updates, options);
25
- writeFileSync(path, content);
26
- return { written, removed };
15
+ * Merge `updates` into the dotenv content at `path`, preserving every other line
16
+ * (comments, blank lines, unrelated keys) and the file's existing order. Keys present in
17
+ * both are updated in place; keys only in `updates` are appended. A non-existent file is
18
+ * treated as empty. When `managedKeys` is given, any owned key on disk that is absent from
19
+ * `updates` is removed. Returns the keys written and the (managed) keys removed.
20
+ */
21
+ const mergeEnvFile = (path, updates, options = {}) => {
22
+ const original = existsSync(path) ? readFileSync(path, "utf8") : "";
23
+ const { content, written, removed } = mergeEnvContent(original, updates, options);
24
+ writeFileSync(path, content);
25
+ return {
26
+ written,
27
+ removed
28
+ };
27
29
  };
28
30
  /**
29
- * Pure core of {@link mergeEnvFile}: takes the current file content and the updates, and
30
- * returns the new content plus which keys were written / removed. Kept side-effect-free so
31
- * it can be unit-tested without touching the filesystem.
32
- */
33
- export const mergeEnvContent = (original, updates, options = {}) => {
34
- const keys = Object.keys(updates);
35
- // Owned keys the current pull did not produce: stale Neon-managed vars to prune. Anything
36
- // not in `managedKeys` is always kept, so a user's own lines are never removed.
37
- const stale = new Set([...(options.managedKeys ?? [])].filter((key) => !(key in updates)));
38
- if (keys.length === 0 && stale.size === 0) {
39
- return { content: original, written: [], removed: [] };
40
- }
41
- const remaining = new Set(keys);
42
- const removed = [];
43
- const lines = original === "" ? [] : original.split("\n");
44
- // Walk the file: drop stale owned lines, update existing keys in place (so their position
45
- // and any surrounding comments are preserved), and pass everything else through untouched.
46
- const updatedLines = [];
47
- for (const line of lines) {
48
- const key = parseKey(line);
49
- if (key !== null && stale.has(key)) {
50
- removed.push(key);
51
- continue;
52
- }
53
- if (key !== null && remaining.has(key)) {
54
- remaining.delete(key);
55
- updatedLines.push(formatLine(key, updates[key]));
56
- continue;
57
- }
58
- updatedLines.push(line);
59
- }
60
- // Append keys that weren't already present, in the order they were given.
61
- const appended = keys
62
- .filter((key) => remaining.has(key))
63
- .map((key) => formatLine(key, updates[key]));
64
- const body = trimTrailingBlank(updatedLines);
65
- const content = [...body, ...appended].join("\n");
66
- return {
67
- // A dotenv file ends with a trailing newline.
68
- content: content === "" ? "" : `${content}\n`,
69
- written: keys,
70
- removed,
71
- };
31
+ * Pure core of {@link mergeEnvFile}: takes the current file content and the updates, and
32
+ * returns the new content plus which keys were written / removed. Kept side-effect-free so
33
+ * it can be unit-tested without touching the filesystem.
34
+ */
35
+ const mergeEnvContent = (original, updates, options = {}) => {
36
+ const keys = Object.keys(updates);
37
+ const stale = new Set([...options.managedKeys ?? []].filter((key) => !(key in updates)));
38
+ if (keys.length === 0 && stale.size === 0) return {
39
+ content: original,
40
+ written: [],
41
+ removed: []
42
+ };
43
+ const remaining = new Set(keys);
44
+ const removed = [];
45
+ const lines = original === "" ? [] : original.split("\n");
46
+ const updatedLines = [];
47
+ for (const line of lines) {
48
+ const key = parseKey(line);
49
+ if (key !== null && stale.has(key)) {
50
+ removed.push(key);
51
+ continue;
52
+ }
53
+ if (key !== null && remaining.has(key)) {
54
+ remaining.delete(key);
55
+ updatedLines.push(formatLine(key, updates[key]));
56
+ continue;
57
+ }
58
+ updatedLines.push(line);
59
+ }
60
+ const appended = keys.filter((key) => remaining.has(key)).map((key) => formatLine(key, updates[key]));
61
+ const content = [...trimTrailingBlank(updatedLines), ...appended].join("\n");
62
+ return {
63
+ content: content === "" ? "" : `${content}\n`,
64
+ written: keys,
65
+ removed
66
+ };
72
67
  };
73
68
  /**
74
- * Read a dotenv file at `path` into a plain `{ KEY: value }` map. A non-existent file is an
75
- * error (callers pass an explicit `--env` path, so a typo should fail loudly rather than
76
- * silently load nothing). Quotes are stripped and `\"` / `\\` unescaped, matching the
77
- * quoting {@link mergeEnvFile} writes. Comments, blank lines, and non-assignment lines are
78
- * ignored.
79
- */
80
- export const readEnvFile = (path) => {
81
- if (!existsSync(path)) {
82
- throw new Error(`Env file not found: ${path}`);
83
- }
84
- const out = {};
85
- for (const line of readFileSync(path, "utf8").split("\n")) {
86
- const parsed = parseAssignment(line);
87
- if (parsed)
88
- out[parsed.key] = parsed.value;
89
- }
90
- return out;
69
+ * Read a dotenv file at `path` into a plain `{ KEY: value }` map. A non-existent file is an
70
+ * error (callers pass an explicit `--env` path, so a typo should fail loudly rather than
71
+ * silently load nothing). Quotes are stripped and `\"` / `\\` unescaped, matching the
72
+ * quoting {@link mergeEnvFile} writes. Comments, blank lines, and non-assignment lines are
73
+ * ignored.
74
+ */
75
+ const readEnvFile = (path) => {
76
+ if (!existsSync(path)) throw new Error(`Env file not found: ${path}`);
77
+ const out = {};
78
+ for (const line of readFileSync(path, "utf8").split("\n")) {
79
+ const parsed = parseAssignment(line);
80
+ if (parsed) out[parsed.key] = parsed.value;
81
+ }
82
+ return out;
91
83
  };
92
84
  /**
93
- * Load a dotenv file into `process.env` so values are available to anything read later
94
- * (e.g. a `neon.ts` whose function `env` values come from `process.env.X`). Existing
95
- * `process.env` entries are **not** overridden — an already-exported var wins over the
96
- * file, matching dotenv's default. Returns the keys that were applied.
97
- */
98
- export const loadEnvFileIntoProcess = (path) => {
99
- const parsed = readEnvFile(path);
100
- const applied = [];
101
- for (const [key, value] of Object.entries(parsed)) {
102
- if (process.env[key] === undefined) {
103
- process.env[key] = value;
104
- applied.push(key);
105
- }
106
- }
107
- return applied;
85
+ * Load a dotenv file into `process.env` so values are available to anything read later
86
+ * (e.g. a `neon.ts` whose function `env` values come from `process.env.X`). Existing
87
+ * `process.env` entries are **not** overridden — an already-exported var wins over the
88
+ * file, matching dotenv's default. Returns the keys that were applied.
89
+ */
90
+ const loadEnvFileIntoProcess = (path) => {
91
+ const parsed = readEnvFile(path);
92
+ const applied = [];
93
+ for (const [key, value] of Object.entries(parsed)) if (process.env[key] === void 0) {
94
+ process.env[key] = value;
95
+ applied.push(key);
96
+ }
97
+ return applied;
108
98
  };
109
99
  /**
110
- * Extract the variable name from a dotenv line, or `null` for comments / blank lines / any
111
- * line that isn't a `KEY=value` assignment. Tolerates a leading `export ` and surrounding
112
- * whitespace, matching common `.env` styles.
113
- */
100
+ * Extract the variable name from a dotenv line, or `null` for comments / blank lines / any
101
+ * line that isn't a `KEY=value` assignment. Tolerates a leading `export ` and surrounding
102
+ * whitespace, matching common `.env` styles.
103
+ */
114
104
  const parseKey = (line) => {
115
- const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(line);
116
- return match ? match[1] : null;
105
+ const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(line);
106
+ return match ? match[1] : null;
117
107
  };
118
108
  /**
119
- * Parse a `KEY=value` dotenv line into its key and unquoted value, or `null` for
120
- * comments / blank lines / non-assignments. Mirrors {@link formatLine}'s quoting.
121
- */
109
+ * Parse a `KEY=value` dotenv line into its key and unquoted value, or `null` for
110
+ * comments / blank lines / non-assignments. Mirrors {@link formatLine}'s quoting.
111
+ */
122
112
  const parseAssignment = (line) => {
123
- const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(line);
124
- const key = match?.[1];
125
- const raw = match?.[2];
126
- if (key === undefined || raw === undefined)
127
- return null;
128
- return { key, value: unquote(raw.trim()) };
113
+ const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(line);
114
+ const key = match?.[1];
115
+ const raw = match?.[2];
116
+ if (key === void 0 || raw === void 0) return null;
117
+ return {
118
+ key,
119
+ value: unquote(raw.trim())
120
+ };
129
121
  };
130
122
  /** Strip matching surrounding quotes and unescape `\"` / `\\` inside double quotes. */
131
123
  const unquote = (value) => {
132
- if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
133
- return value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, "\\");
134
- }
135
- if (value.length >= 2 && value.startsWith("'") && value.endsWith("'")) {
136
- return value.slice(1, -1);
137
- }
138
- return value;
124
+ if (value.length >= 2 && value.startsWith("\"") && value.endsWith("\"")) return value.slice(1, -1).replace(/\\"/g, "\"").replace(/\\\\/g, "\\");
125
+ if (value.length >= 2 && value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1);
126
+ return value;
139
127
  };
140
128
  /**
141
- * Render a `KEY=value` line. The value is wrapped in double quotes when it contains
142
- * characters that would otherwise break parsing (spaces, `#`, quotes, `=`), with inner
143
- * quotes/backslashes escaped — Neon connection strings and URLs are safe either way, but
144
- * quoting defensively avoids surprises for tools that re-parse the file.
145
- */
129
+ * Render a `KEY=value` line. The value is wrapped in double quotes when it contains
130
+ * characters that would otherwise break parsing (spaces, `#`, quotes, `=`), with inner
131
+ * quotes/backslashes escaped — Neon connection strings and URLs are safe either way, but
132
+ * quoting defensively avoids surprises for tools that re-parse the file.
133
+ */
146
134
  const formatLine = (key, value) => {
147
- const needsQuotes = /[\s#"'=]/.test(value);
148
- if (!needsQuotes)
149
- return `${key}=${value}`;
150
- const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
151
- return `${key}="${escaped}"`;
135
+ if (!/[\s#"'=]/.test(value)) return `${key}=${value}`;
136
+ return `${key}="${value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
152
137
  };
153
138
  /** Drop trailing blank lines so we don't accumulate them across repeated merges. */
154
139
  const trimTrailingBlank = (lines) => {
155
- const out = [...lines];
156
- while (out.length > 0 && out[out.length - 1]?.trim() === "")
157
- out.pop();
158
- return out;
140
+ const out = [...lines];
141
+ while (out.length > 0 && out[out.length - 1]?.trim() === "") out.pop();
142
+ return out;
159
143
  };
144
+ //#endregion
145
+ export { loadEnvFileIntoProcess, mergeEnvContent, mergeEnvFile, readEnvFile, resolveEnvFilePath };
@@ -1,51 +1,49 @@
1
- import { NEON_ENV_VAR_KEYS } from "./_shared/env-core/env.js";
2
1
  import { NEON_SERVICES } from "./neon_services.js";
2
+ import { NEON_ENV_VAR_KEYS } from "./_shared/env-core/env.js";
3
+ //#region src/env_services.ts
3
4
  /**
4
- * The services `env pull --service` can select: every Neon service that produces branch env
5
- * vars. `functions` is the one left out — a function's env comes from the local `neon.ts`,
6
- * never from the branch, so there is nothing to pull.
7
- */
8
- export const ENV_PULL_SERVICES = NEON_SERVICES.filter((service) => service !== "functions");
5
+ * The services `env pull --service` can select: every Neon service that produces branch env
6
+ * vars. `functions` is the one left out — a function's env comes from the local `neon.ts`,
7
+ * never from the branch, so there is nothing to pull.
8
+ */
9
+ const ENV_PULL_SERVICES = NEON_SERVICES.filter((service) => service !== "functions");
9
10
  /** Why the services `env pull` leaves out are not selectable, for the refusal message. */
10
- export const ENV_PULL_UNAVAILABLE = {
11
- functions: "a function's env comes from your neon.ts, not from the branch, so there is nothing to pull",
12
- };
11
+ const ENV_PULL_UNAVAILABLE = { functions: "a function's env comes from your neon.ts, not from the branch, so there is nothing to pull" };
13
12
  /** The OS-level env vars each service contributes to a pulled `.env`. */
14
13
  const SERVICE_ENV_KEYS = {
15
- postgres: Object.values(NEON_ENV_VAR_KEYS.postgres),
16
- auth: Object.values(NEON_ENV_VAR_KEYS.auth),
17
- "data-api": Object.values(NEON_ENV_VAR_KEYS.dataApi),
18
- "object-storage": Object.values(NEON_ENV_VAR_KEYS.storage),
19
- "ai-gateway": Object.values(NEON_ENV_VAR_KEYS.aiGateway),
20
- functions: [],
14
+ postgres: Object.values(NEON_ENV_VAR_KEYS.postgres),
15
+ auth: Object.values(NEON_ENV_VAR_KEYS.auth),
16
+ "data-api": Object.values(NEON_ENV_VAR_KEYS.dataApi),
17
+ "object-storage": Object.values(NEON_ENV_VAR_KEYS.storage),
18
+ "ai-gateway": Object.values(NEON_ENV_VAR_KEYS.aiGateway),
19
+ functions: []
21
20
  };
22
21
  /**
23
- * The subset of {@link SERVICE_ENV_KEYS} a pull *owns*, and so may prune from the target file
24
- * when the branch no longer has it. Object storage is deliberately absent: it is emitted under
25
- * the third-party `AWS_*` names, which collide with credentials a user may set by hand, so
26
- * `env pull` only ever writes them.
27
- */
22
+ * The subset of {@link SERVICE_ENV_KEYS} a pull *owns*, and so may prune from the target file
23
+ * when the branch no longer has it. Object storage is deliberately absent: it is emitted under
24
+ * the third-party `AWS_*` names, which collide with credentials a user may set by hand, so
25
+ * `env pull` only ever writes them.
26
+ */
28
27
  const SERVICE_OWNED_ENV_KEYS = {
29
- ...SERVICE_ENV_KEYS,
30
- "object-storage": [],
28
+ ...SERVICE_ENV_KEYS,
29
+ "object-storage": []
31
30
  };
32
31
  /**
33
- * Branch identity. Not a service — every branch has a name — so a scoped pull refreshes it
34
- * alongside whatever services were selected.
35
- */
36
- export const BRANCH_ENV_KEY = NEON_ENV_VAR_KEYS.branch.name;
32
+ * Branch identity. Not a service — every branch has a name — so a scoped pull refreshes it
33
+ * alongside whatever services were selected.
34
+ */
35
+ const BRANCH_ENV_KEY = NEON_ENV_VAR_KEYS.branch.name;
37
36
  /** Every env var the selected services contribute, plus branch identity. */
38
- export const envServiceKeys = (services) => {
39
- const keys = new Set([BRANCH_ENV_KEY]);
40
- for (const service of services) {
41
- for (const key of SERVICE_ENV_KEYS[service])
42
- keys.add(key);
43
- }
44
- return keys;
37
+ const envServiceKeys = (services) => {
38
+ const keys = /* @__PURE__ */ new Set([BRANCH_ENV_KEY]);
39
+ for (const service of services) for (const key of SERVICE_ENV_KEYS[service]) keys.add(key);
40
+ return keys;
45
41
  };
46
42
  /**
47
- * The env vars a pull scoped to `services` may prune. Narrower than the unscoped set on
48
- * purpose: `env pull -s ai-gateway` says nothing about `DATABASE_URL`, so it must leave it
49
- * alone rather than treat its absence from this pull as "the branch no longer has it".
50
- */
51
- export const ownedEnvServiceKeys = (services) => services.flatMap((service) => SERVICE_OWNED_ENV_KEYS[service]);
43
+ * The env vars a pull scoped to `services` may prune. Narrower than the unscoped set on
44
+ * purpose: `env pull -s ai-gateway` says nothing about `DATABASE_URL`, so it must leave it
45
+ * alone rather than treat its absence from this pull as "the branch no longer has it".
46
+ */
47
+ const ownedEnvServiceKeys = (services) => services.flatMap((service) => SERVICE_OWNED_ENV_KEYS[service]);
48
+ //#endregion
49
+ export { BRANCH_ENV_KEY, ENV_PULL_SERVICES, ENV_PULL_UNAVAILABLE, envServiceKeys, ownedEnvServiceKeys };
package/dist/errors.js CHANGED
@@ -1,80 +1,69 @@
1
+ //#region src/errors.ts
1
2
  const ERROR_MATCHERS = [
2
- [/^Unknown command: (.*)$/, "UNKNOWN_COMMAND"],
3
- [/^Missing required argument: (.*)$/, "MISSING_ARGUMENT"],
4
- [/^Failed to open web browser. (.*)$/, "AUTH_BROWSER_FAILED"],
3
+ [/^Unknown command: (.*)$/, "UNKNOWN_COMMAND"],
4
+ [/^Missing required argument: (.*)$/, "MISSING_ARGUMENT"],
5
+ [/^Failed to open web browser. (.*)$/, "AUTH_BROWSER_FAILED"]
5
6
  ];
6
- export const matchErrorCode = (message) => {
7
- if (!message) {
8
- return "UNKNOWN_ERROR";
9
- }
10
- for (const [matcher, code] of ERROR_MATCHERS) {
11
- const match = message.match(matcher);
12
- if (match) {
13
- return code;
14
- }
15
- }
16
- return "UNKNOWN_ERROR";
7
+ const matchErrorCode = (message) => {
8
+ if (!message) return "UNKNOWN_ERROR";
9
+ for (const [matcher, code] of ERROR_MATCHERS) if (message.match(matcher)) return code;
10
+ return "UNKNOWN_ERROR";
17
11
  };
18
12
  /**
19
- * The single, human-readable line shown when the CLI couldn't reach the Neon API because
20
- * of a connection-level failure (DNS, refused/reset connection, offline). It replaces the
21
- * cryptic `fetch failed` / empty axios message a network blip otherwise surfaces (see
22
- * {@link isNetworkError}), pointing at the two things the user can actually check.
23
- */
24
- export const NETWORK_ERROR_MESSAGE = "Could not reach the Neon API. Please check your internet connection and try again. " +
25
- "If your connection is fine and this keeps happening, check https://neonstatus.com for ongoing incidents.";
13
+ * The single, human-readable line shown when the CLI couldn't reach the Neon API because
14
+ * of a connection-level failure (DNS, refused/reset connection, offline). It replaces the
15
+ * cryptic `fetch failed` / empty axios message a network blip otherwise surfaces (see
16
+ * {@link isNetworkError}), pointing at the two things the user can actually check.
17
+ */
18
+ const NETWORK_ERROR_MESSAGE = "Could not reach the Neon API. Please check your internet connection and try again. If your connection is fine and this keeps happening, check https://neonstatus.com for ongoing incidents.";
26
19
  /**
27
- * Node-level socket/DNS error codes that mean the request never reached the server — a
28
- * genuine connectivity problem rather than an API response we should surface. Deliberately
29
- * excludes `ECONNABORTED` (axios' timeout), which the CLI already reports as a timeout.
30
- */
31
- const NETWORK_ERROR_CODES = new Set([
32
- "ECONNREFUSED",
33
- "ECONNRESET",
34
- "ETIMEDOUT",
35
- "ENOTFOUND",
36
- "EAI_AGAIN",
37
- "EPIPE",
38
- "EHOSTUNREACH",
39
- "ENETUNREACH",
40
- "EHOSTDOWN",
41
- "ENETDOWN",
20
+ * Node-level socket/DNS error codes that mean the request never reached the server — a
21
+ * genuine connectivity problem rather than an API response we should surface. Deliberately
22
+ * excludes `ECONNABORTED` (axios' timeout), which the CLI already reports as a timeout.
23
+ */
24
+ const NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
25
+ "ECONNREFUSED",
26
+ "ECONNRESET",
27
+ "ETIMEDOUT",
28
+ "ENOTFOUND",
29
+ "EAI_AGAIN",
30
+ "EPIPE",
31
+ "EHOSTUNREACH",
32
+ "ENETUNREACH",
33
+ "EHOSTDOWN",
34
+ "ENETDOWN"
42
35
  ]);
43
36
  /**
44
- * Message fragments that mark a connection-level failure across our two transports: the
45
- * `@neon/sdk` / global `fetch` path (used by `env pull` / `config` / `deploy`, and `link`'s
46
- * bundled env pull) throws a bare `TypeError: fetch failed` / "Failed to fetch", while the
47
- * axios `api-client` path throws an `AxiosError` whose message is "Network Error".
48
- */
37
+ * Message fragments that mark a connection-level failure across our two transports: the
38
+ * `@neon/sdk` / global `fetch` path (used by `env pull` / `config` / `deploy`, and `link`'s
39
+ * bundled env pull) throws a bare `TypeError: fetch failed` / "Failed to fetch", while the
40
+ * axios `api-client` path throws an `AxiosError` whose message is "Network Error".
41
+ */
49
42
  const NETWORK_ERROR_MESSAGE_PATTERN = /fetch failed|failed to fetch|network error/i;
50
43
  const readErrorCode = (value) => {
51
- if (value === null || typeof value !== "object")
52
- return undefined;
53
- const code = value.code;
54
- return typeof code === "string" ? code : undefined;
44
+ if (value === null || typeof value !== "object") return void 0;
45
+ const code = value.code;
46
+ return typeof code === "string" ? code : void 0;
55
47
  };
56
48
  /**
57
- * Whether `err` is a connection-level failure (the network blip the user sees as a cryptic
58
- * `fetch failed`, or no message at all on the axios path) rather than an actual API response.
59
- *
60
- * A Node `fetch` failure is a bare `TypeError: fetch failed` whose underlying `cause` carries
61
- * the real socket `code` (e.g. `ECONNREFUSED`, `ENOTFOUND`, `EAI_AGAIN`), so we walk the
62
- * `cause` chain checking both the code and the message. This is what lets the CLI swap the
63
- * confusing default for {@link NETWORK_ERROR_MESSAGE}. It matches only failures where no
64
- * response was ever received, so it never masks a real 4xx/5xx the user needs to see.
65
- */
66
- export const isNetworkError = (err) => {
67
- let current = err;
68
- for (let depth = 0; depth < 6 && current !== null && current !== undefined; depth++) {
69
- const code = readErrorCode(current);
70
- if (code !== undefined && NETWORK_ERROR_CODES.has(code)) {
71
- return true;
72
- }
73
- if (current instanceof Error &&
74
- NETWORK_ERROR_MESSAGE_PATTERN.test(current.message)) {
75
- return true;
76
- }
77
- current = current.cause;
78
- }
79
- return false;
49
+ * Whether `err` is a connection-level failure (the network blip the user sees as a cryptic
50
+ * `fetch failed`, or no message at all on the axios path) rather than an actual API response.
51
+ *
52
+ * A Node `fetch` failure is a bare `TypeError: fetch failed` whose underlying `cause` carries
53
+ * the real socket `code` (e.g. `ECONNREFUSED`, `ENOTFOUND`, `EAI_AGAIN`), so we walk the
54
+ * `cause` chain checking both the code and the message. This is what lets the CLI swap the
55
+ * confusing default for {@link NETWORK_ERROR_MESSAGE}. It matches only failures where no
56
+ * response was ever received, so it never masks a real 4xx/5xx the user needs to see.
57
+ */
58
+ const isNetworkError = (err) => {
59
+ let current = err;
60
+ for (let depth = 0; depth < 6 && current !== null && current !== void 0; depth++) {
61
+ const code = readErrorCode(current);
62
+ if (code !== void 0 && NETWORK_ERROR_CODES.has(code)) return true;
63
+ if (current instanceof Error && NETWORK_ERROR_MESSAGE_PATTERN.test(current.message)) return true;
64
+ current = current.cause;
65
+ }
66
+ return false;
80
67
  };
68
+ //#endregion
69
+ export { NETWORK_ERROR_MESSAGE, isNetworkError, matchErrorCode };