neon 3.0.0 → 3.1.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.
Files changed (207) hide show
  1. package/README.md +70 -5
  2. package/dist/_chunks/auth_selection-DGgq6ifc.js +83 -0
  3. package/dist/_chunks/cmd_pipeline-CUbBO9U_.js +2818 -0
  4. package/dist/_chunks/credentials-MYdHdKah.js +188 -0
  5. package/dist/_chunks/env-NbA61JR3.js +585 -0
  6. package/dist/_chunks/env_services-Tz9G4JeT.js +531 -0
  7. package/dist/_chunks/paths-DMq0Lt7a.js +151 -0
  8. package/dist/_chunks/profiles-Ir29rqns.js +217 -0
  9. package/dist/_chunks/psql-DWH-kc69.js +2169 -0
  10. package/dist/_chunks/rolldown-runtime-D7D4PA-g.js +13 -0
  11. package/dist/_chunks/secure_file-BucZj4yQ.js +39 -0
  12. package/dist/analytics.js +163 -207
  13. package/dist/api.js +815 -758
  14. package/dist/auth.js +121 -141
  15. package/dist/auth_context.js +39 -53
  16. package/dist/cli.js +4 -7
  17. package/dist/commands/api.js +220 -250
  18. package/dist/commands/api_keys.js +251 -314
  19. package/dist/commands/auth.js +283 -328
  20. package/dist/commands/bootstrap.js +372 -437
  21. package/dist/commands/branches.js +304 -455
  22. package/dist/commands/bucket.js +374 -514
  23. package/dist/commands/checkout.js +213 -298
  24. package/dist/commands/config.js +573 -690
  25. package/dist/commands/connection_string.js +137 -165
  26. package/dist/commands/data_api.js +238 -260
  27. package/dist/commands/databases.js +67 -76
  28. package/dist/commands/deploy.js +31 -25
  29. package/dist/commands/dev.js +639 -719
  30. package/dist/commands/diff.js +156 -200
  31. package/dist/commands/env.js +255 -305
  32. package/dist/commands/functions.js +275 -355
  33. package/dist/commands/index.js +70 -65
  34. package/dist/commands/init.js +84 -119
  35. package/dist/commands/inspect.js +55 -55
  36. package/dist/commands/ip_allow.js +88 -120
  37. package/dist/commands/link.js +874 -1019
  38. package/dist/commands/logs.js +291 -0
  39. package/dist/commands/neon_auth.js +725 -933
  40. package/dist/commands/operations.js +34 -25
  41. package/dist/commands/orgs.js +28 -18
  42. package/dist/commands/profile.js +615 -846
  43. package/dist/commands/projects.js +313 -373
  44. package/dist/commands/psql.js +60 -58
  45. package/dist/commands/roles.js +55 -58
  46. package/dist/commands/schema_diff.js +87 -131
  47. package/dist/commands/set_context.js +34 -26
  48. package/dist/commands/snapshots.js +288 -413
  49. package/dist/commands/status.js +41 -37
  50. package/dist/commands/user.js +21 -10
  51. package/dist/commands/vpc_endpoints.js +85 -113
  52. package/dist/config.js +7 -6
  53. package/dist/config_format.js +50 -66
  54. package/dist/config_template.js +128 -157
  55. package/dist/context.js +183 -235
  56. package/dist/current_branch_fast_path.js +40 -49
  57. package/dist/dev/env.js +2 -446
  58. package/dist/dev/functions.js +54 -68
  59. package/dist/dev/inputs.js +46 -58
  60. package/dist/dev/runtime.js +135 -164
  61. package/dist/dev/websocket.js +766 -959
  62. package/dist/env.js +27 -33
  63. package/dist/env_file.js +118 -132
  64. package/dist/env_services.js +2 -51
  65. package/dist/errors.js +57 -68
  66. package/dist/functions_api.js +45 -43
  67. package/dist/help.js +189 -140
  68. package/dist/index.js +182 -257
  69. package/dist/init/agents.js +137 -118
  70. package/dist/init/auth.js +58 -68
  71. package/dist/init/bootstrap.js +325 -396
  72. package/dist/init/build_config.js +4 -2
  73. package/dist/init/detect_agent.js +56 -101
  74. package/dist/init/editors.js +35 -52
  75. package/dist/init/enrich_output.js +51 -66
  76. package/dist/init/extension.js +134 -171
  77. package/dist/init/inspect.js +179 -266
  78. package/dist/init/interactive.js +510 -622
  79. package/dist/init/neonctl.js +117 -168
  80. package/dist/init/orchestrate.js +157 -173
  81. package/dist/init/phases/auth.js +188 -202
  82. package/dist/init/phases/cleanup.js +23 -23
  83. package/dist/init/phases/db.js +251 -277
  84. package/dist/init/phases/getting_started.js +213 -223
  85. package/dist/init/phases/mcp.js +174 -224
  86. package/dist/init/phases/migrations.js +247 -248
  87. package/dist/init/phases/neon_auth.js +114 -133
  88. package/dist/init/phases/setup.js +546 -703
  89. package/dist/init/phases/skills.js +75 -86
  90. package/dist/init/phases/status.js +72 -67
  91. package/dist/init/resolve_context.js +102 -99
  92. package/dist/init/route_command.js +91 -98
  93. package/dist/init/skills.js +174 -218
  94. package/dist/init/vsix.js +77 -99
  95. package/dist/log.js +17 -16
  96. package/dist/neon_services.js +104 -129
  97. package/dist/parameters.gen.js +481 -471
  98. package/dist/pkg.js +17 -19
  99. package/dist/profile_keys.js +44 -47
  100. package/dist/psql/cli.js +44 -47
  101. package/dist/psql/command/cmd_cond.js +231 -406
  102. package/dist/psql/command/cmd_connect.js +557 -764
  103. package/dist/psql/command/cmd_copy.js +728 -984
  104. package/dist/psql/command/cmd_describe.js +1499 -1688
  105. package/dist/psql/command/cmd_format.js +733 -905
  106. package/dist/psql/command/cmd_io.js +2 -2193
  107. package/dist/psql/command/cmd_lo.js +297 -359
  108. package/dist/psql/command/cmd_meta.js +727 -878
  109. package/dist/psql/command/cmd_misc.js +138 -172
  110. package/dist/psql/command/cmd_pipeline.js +2 -1148
  111. package/dist/psql/command/cmd_restrict.js +119 -155
  112. package/dist/psql/command/cmd_show.js +529 -688
  113. package/dist/psql/command/dispatch.js +260 -325
  114. package/dist/psql/command/inputQueue.js +35 -33
  115. package/dist/psql/command/shared.js +49 -63
  116. package/dist/psql/complete/filenames.js +90 -133
  117. package/dist/psql/complete/index.js +59 -97
  118. package/dist/psql/complete/matcher.js +236 -300
  119. package/dist/psql/complete/psqlVars.js +218 -223
  120. package/dist/psql/complete/queries.js +159 -177
  121. package/dist/psql/complete/rules.js +1493 -2299
  122. package/dist/psql/core/common.js +2 -1253
  123. package/dist/psql/core/help.js +456 -546
  124. package/dist/psql/core/mainloop.js +692 -1303
  125. package/dist/psql/core/prompt.js +391 -408
  126. package/dist/psql/core/settings.js +429 -644
  127. package/dist/psql/core/sqlHelp.js +480 -554
  128. package/dist/psql/core/startup.js +2 -846
  129. package/dist/psql/core/syncVars.js +67 -110
  130. package/dist/psql/core/variables.js +156 -278
  131. package/dist/psql/describe/formatters.js +884 -1285
  132. package/dist/psql/describe/processNamePattern.js +173 -260
  133. package/dist/psql/describe/queries.js +1368 -2403
  134. package/dist/psql/describe/versionGate.js +32 -41
  135. package/dist/psql/index.js +2 -2030
  136. package/dist/psql/io/history.js +232 -271
  137. package/dist/psql/io/input.js +103 -108
  138. package/dist/psql/io/lineEditor/buffer.js +238 -319
  139. package/dist/psql/io/lineEditor/complete.js +135 -213
  140. package/dist/psql/io/lineEditor/filename.js +139 -148
  141. package/dist/psql/io/lineEditor/index.js +653 -870
  142. package/dist/psql/io/lineEditor/keymap.js +544 -702
  143. package/dist/psql/io/lineEditor/vt100.js +294 -341
  144. package/dist/psql/io/pgpass.js +158 -187
  145. package/dist/psql/io/pgservice.js +146 -183
  146. package/dist/psql/io/psqlrc.js +328 -403
  147. package/dist/psql/print/aligned.js +1020 -1683
  148. package/dist/psql/print/asciidoc.js +180 -214
  149. package/dist/psql/print/crosstab.js +281 -442
  150. package/dist/psql/print/csv.js +48 -70
  151. package/dist/psql/print/html.js +195 -226
  152. package/dist/psql/print/json.js +75 -88
  153. package/dist/psql/print/latex.js +291 -364
  154. package/dist/psql/print/pager.js +171 -242
  155. package/dist/psql/print/troff.js +194 -226
  156. package/dist/psql/print/unaligned.js +69 -95
  157. package/dist/psql/print/units.js +167 -169
  158. package/dist/psql/scanner/slash.js +428 -483
  159. package/dist/psql/scanner/sql.js +445 -889
  160. package/dist/psql/scanner/stringutils.js +309 -379
  161. package/dist/psql/types/index.js +8 -7
  162. package/dist/psql/types/scanner.js +25 -22
  163. package/dist/psql/wire/connection.js +2042 -2803
  164. package/dist/psql/wire/copy.js +84 -100
  165. package/dist/psql/wire/notify.js +39 -59
  166. package/dist/psql/wire/pipeline.js +305 -518
  167. package/dist/psql/wire/protocol.js +349 -417
  168. package/dist/psql/wire/sasl.js +180 -265
  169. package/dist/psql/wire/tls.js +400 -561
  170. package/dist/storage_api.js +115 -129
  171. package/dist/test_utils/fixtures.js +94 -113
  172. package/dist/test_utils/oauth_server.js +10 -7
  173. package/dist/test_utils/project_dir.js +33 -0
  174. package/dist/utils/ai_gateway_notice.js +131 -162
  175. package/dist/utils/api_enums.js +21 -28
  176. package/dist/utils/auth.js +10 -4
  177. package/dist/utils/branch_notice.js +20 -19
  178. package/dist/utils/branch_picker.js +83 -89
  179. package/dist/utils/cli_name.js +15 -12
  180. package/dist/utils/compute_units.js +20 -27
  181. package/dist/utils/config_diff.js +127 -158
  182. package/dist/utils/enrichers.js +95 -148
  183. package/dist/utils/esbuild.js +130 -189
  184. package/dist/utils/flags.js +35 -47
  185. package/dist/utils/formats.js +8 -15
  186. package/dist/utils/git_diff.js +69 -80
  187. package/dist/utils/inspect_db.js +101 -143
  188. package/dist/utils/inspect_queries.js +179 -142
  189. package/dist/utils/middlewares.js +39 -45
  190. package/dist/utils/openapi.js +87 -99
  191. package/dist/utils/package_manager.js +312 -110
  192. package/dist/utils/point_in_time.js +49 -53
  193. package/dist/utils/psql.js +89 -106
  194. package/dist/utils/service_picker.js +55 -58
  195. package/dist/utils/string.js +5 -5
  196. package/dist/utils/ui.js +38 -55
  197. package/dist/utils/write_sync.js +26 -35
  198. package/dist/utils/zip.js +4 -3
  199. package/dist/writer.js +67 -87
  200. package/package.json +11 -6
  201. package/dist/_shared/auth_selection.js +0 -86
  202. package/dist/_shared/credentials.js +0 -209
  203. package/dist/_shared/env-core/env.js +0 -558
  204. package/dist/_shared/env-core/reuse-secrets.js +0 -223
  205. package/dist/_shared/paths.js +0 -148
  206. package/dist/_shared/profiles.js +0 -276
  207. package/dist/_shared/secure_file.js +0 -43
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,2 @@
1
- import { NEON_ENV_VAR_KEYS } from "./_shared/env-core/env.js";
2
- import { NEON_SERVICES } from "./neon_services.js";
3
- /**
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");
9
- /** 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
- };
13
- /** The OS-level env vars each service contributes to a pulled `.env`. */
14
- 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: [],
21
- };
22
- /**
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
- */
28
- const SERVICE_OWNED_ENV_KEYS = {
29
- ...SERVICE_ENV_KEYS,
30
- "object-storage": [],
31
- };
32
- /**
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;
37
- /** 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;
45
- };
46
- /**
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]);
1
+ import { a as envKeysForSelection, c as ownedEnvServiceKeys, d as servicesForEnvKeys, i as ENV_PULL_UNAVAILABLE, l as parseEnvPullKeys, n as ENV_PULL_KEYS, o as envPullFlagValue, r as ENV_PULL_SERVICES, s as envServiceKeys, t as BRANCH_ENV_KEY, u as serviceForEnvKey } from "./_chunks/env_services-Tz9G4JeT.js";
2
+ export { BRANCH_ENV_KEY, ENV_PULL_KEYS, ENV_PULL_SERVICES, ENV_PULL_UNAVAILABLE, envKeysForSelection, envPullFlagValue, envServiceKeys, ownedEnvServiceKeys, parseEnvPullKeys, serviceForEnvKey, servicesForEnvKeys };
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 };
@@ -1,48 +1,50 @@
1
- import { ContentType } from "./api.js";
1
+ import "./api.js";
2
+ //#region src/functions_api.ts
2
3
  const functionsPath = (projectId, branchId) => `/projects/${encodeURIComponent(projectId)}/branches/${encodeURIComponent(branchId)}/functions`;
3
- export const listFunctions = async (apiClient, projectId, branchId, { cursor, limit } = {}) => {
4
- const { data } = await apiClient.request({
5
- path: functionsPath(projectId, branchId),
6
- method: "GET",
7
- query: { cursor, limit },
8
- secure: true,
9
- format: "json",
10
- });
11
- return { functions: data.functions ?? [], next: data.pagination?.next };
4
+ const listFunctions = async (apiClient, projectId, branchId, { cursor, limit } = {}) => {
5
+ const { data } = await apiClient.request({
6
+ path: functionsPath(projectId, branchId),
7
+ method: "GET",
8
+ query: {
9
+ cursor,
10
+ limit
11
+ },
12
+ secure: true,
13
+ format: "json"
14
+ });
15
+ return {
16
+ functions: data.functions ?? [],
17
+ next: data.pagination?.next
18
+ };
12
19
  };
13
- export const getFunction = async (apiClient, projectId, branchId, slug) => {
14
- const { data } = await apiClient.request({
15
- path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}`,
16
- method: "GET",
17
- secure: true,
18
- format: "json",
19
- });
20
- return data.function;
20
+ const getFunction = async (apiClient, projectId, branchId, slug) => {
21
+ const { data } = await apiClient.request({
22
+ path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}`,
23
+ method: "GET",
24
+ secure: true,
25
+ format: "json"
26
+ });
27
+ return data.function;
21
28
  };
22
- export const deleteFunction = async (apiClient, projectId, branchId, slug) => {
23
- await apiClient.request({
24
- path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}`,
25
- method: "DELETE",
26
- secure: true,
27
- });
29
+ const deleteFunction = async (apiClient, projectId, branchId, slug) => {
30
+ await apiClient.request({
31
+ path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}`,
32
+ method: "DELETE",
33
+ secure: true
34
+ });
28
35
  };
29
- export const createDeployment = async (apiClient, projectId, branchId, slug, params) => {
30
- const form = new FormData();
31
- // TS 5.9 types `Uint8Array` as `Uint8Array<ArrayBufferLike>`, which is not
32
- // assignable to `BlobPart` (it wants an `ArrayBuffer`-backed view, not a
33
- // possibly-`SharedArrayBuffer` one). The bundle is always a plain
34
- // `Uint8Array` over a regular `ArrayBuffer`, so the cast is safe.
35
- form.append("zip", new Blob([params.zip]), "bundle.zip");
36
- form.append("runtime", params.runtime);
37
- if (params.environment)
38
- form.append("environment", params.environment);
39
- // The deploy POST returns an operation the CLI cannot poll; the body is
40
- // ignored. We only need the request to succeed.
41
- await apiClient.request({
42
- path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}/deployments`,
43
- method: "POST",
44
- type: ContentType.FormData,
45
- body: form,
46
- secure: true,
47
- });
36
+ const createDeployment = async (apiClient, projectId, branchId, slug, params) => {
37
+ const form = new FormData();
38
+ form.append("zip", new Blob([params.zip]), "bundle.zip");
39
+ form.append("runtime", params.runtime);
40
+ if (params.environment) form.append("environment", params.environment);
41
+ await apiClient.request({
42
+ path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}/deployments`,
43
+ method: "POST",
44
+ type: "multipart/form-data",
45
+ body: form,
46
+ secure: true
47
+ });
48
48
  };
49
+ //#endregion
50
+ export { createDeployment, deleteFunction, getFunction, listFunctions };