@neondatabase/config-runtime 0.0.0 → 0.2.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 (43) hide show
  1. package/LICENSE.md +178 -0
  2. package/dist/index.d.ts +6 -0
  3. package/dist/index.js +6 -0
  4. package/dist/lib/function-bundle.d.ts +34 -0
  5. package/dist/lib/function-bundle.d.ts.map +1 -0
  6. package/dist/lib/function-bundle.js +65 -0
  7. package/dist/lib/function-bundle.js.map +1 -0
  8. package/dist/lib/operations.d.ts +77 -0
  9. package/dist/lib/operations.d.ts.map +1 -0
  10. package/dist/lib/operations.js +61 -0
  11. package/dist/lib/operations.js.map +1 -0
  12. package/dist/lib/pull-config.d.ts +63 -0
  13. package/dist/lib/pull-config.d.ts.map +1 -0
  14. package/dist/lib/pull-config.js +113 -0
  15. package/dist/lib/pull-config.js.map +1 -0
  16. package/dist/lib/push-config.d.ts +111 -0
  17. package/dist/lib/push-config.d.ts.map +1 -0
  18. package/dist/lib/push-config.js +400 -0
  19. package/dist/lib/push-config.js.map +1 -0
  20. package/dist/v1.d.ts +6 -0
  21. package/dist/v1.js +6 -0
  22. package/package.json +69 -22
  23. package/e2e/conflict.e2e.test.ts +0 -34
  24. package/e2e/helpers.ts +0 -204
  25. package/e2e/lifecycle.e2e.test.ts +0 -50
  26. package/e2e/load-env.ts +0 -29
  27. package/e2e/setup.ts +0 -24
  28. package/src/index.ts +0 -5
  29. package/src/lib/fake-neon-api.ts +0 -782
  30. package/src/lib/function-bundle.test.ts +0 -60
  31. package/src/lib/function-bundle.ts +0 -104
  32. package/src/lib/operations.test.ts +0 -150
  33. package/src/lib/operations.ts +0 -103
  34. package/src/lib/pull-config.test.ts +0 -51
  35. package/src/lib/pull-config.ts +0 -215
  36. package/src/lib/push-config.test.ts +0 -421
  37. package/src/lib/push-config.ts +0 -619
  38. package/src/v1.test.ts +0 -30
  39. package/src/v1.ts +0 -74
  40. package/tsconfig.json +0 -4
  41. package/tsdown.config.ts +0 -22
  42. package/vitest.config.ts +0 -19
  43. package/vitest.e2e.config.ts +0 -29
package/LICENSE.md ADDED
@@ -0,0 +1,178 @@
1
+ # Apache License 2.0
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,6 @@
1
+ import { FunctionBundler, buildFunctionBundle } from "./lib/function-bundle.js";
2
+ import { PullConfigOptions, PulledBranchConfig, PulledPreview, pullConfig } from "./lib/pull-config.js";
3
+ import { PushConfigOptions, PushConfirmContext, pushConfig } from "./lib/push-config.js";
4
+ import { ApplyOptions, ConfigOperationOptions, apply, inspect, plan } from "./lib/operations.js";
5
+ import { AppliedChange, Config, ConfigLoadError, ConfigValidationError, ConflictReport, ErrorCode, LoadConfigOptions, MissingContextError, NeonApi, PlatformError, PushAbortedError, PushConflictError, PushResult, createNeonApiFromOptions, createRealNeonApi, defineConfig, loadConfigFromFile } from "./v1.js";
6
+ export { AppliedChange, ApplyOptions, Config, ConfigLoadError, ConfigOperationOptions, ConfigValidationError, ConflictReport, ErrorCode, FunctionBundler, LoadConfigOptions, MissingContextError, NeonApi, PlatformError, PullConfigOptions, PulledBranchConfig, PulledPreview, PushAbortedError, PushConfigOptions, PushConfirmContext, PushConflictError, PushResult, apply, buildFunctionBundle, createNeonApiFromOptions, createRealNeonApi, defineConfig, inspect, loadConfigFromFile, plan, pullConfig, pushConfig };
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { buildFunctionBundle } from "./lib/function-bundle.js";
2
+ import { pullConfig } from "./lib/pull-config.js";
3
+ import { pushConfig } from "./lib/push-config.js";
4
+ import { apply, inspect, plan } from "./lib/operations.js";
5
+ import { ConfigLoadError, ConfigValidationError, ErrorCode, MissingContextError, PlatformError, PushAbortedError, PushConflictError, createNeonApiFromOptions, createRealNeonApi, defineConfig, loadConfigFromFile } from "./v1.js";
6
+ export { ConfigLoadError, ConfigValidationError, ErrorCode, MissingContextError, PlatformError, PushAbortedError, PushConflictError, apply, buildFunctionBundle, createNeonApiFromOptions, createRealNeonApi, defineConfig, inspect, loadConfigFromFile, plan, pullConfig, pushConfig };
@@ -0,0 +1,34 @@
1
+ import { ResolvedFunctionConfig } from "@neondatabase/config";
2
+
3
+ //#region src/lib/function-bundle.d.ts
4
+
5
+ /**
6
+ * Builds the deployable ZIP bundle for a single function. The default
7
+ * implementation ({@link buildFunctionBundle}) shells out to esbuild, but
8
+ * `pushConfig` / `apply` accept a custom bundler so a consumer that can't ship
9
+ * esbuild's native binary (e.g. a single-file CLI) can supply its own — a WASM
10
+ * build, an esbuild binary on PATH, etc. — without this package dragging esbuild
11
+ * into their bundle.
12
+ */
13
+ type FunctionBundler = (fn: ResolvedFunctionConfig) => Promise<Uint8Array>;
14
+ /**
15
+ * Build the deployable bundle (a ZIP archive of the esbuild-bundled source) for a function.
16
+ *
17
+ * This is the **imperative shell** step of function deploys, and the reason it lives in
18
+ * `@neondatabase/config-runtime` rather than `@neondatabase/config`: it pulls in `esbuild`
19
+ * (a native binary) and `fflate`. Keeping it out of `@neondatabase/config` means a `neon.ts`
20
+ * that only imports `defineConfig` never drags esbuild into the user's dependency tree or
21
+ * bundle. Deploy-side consumers (the neonctl CLI, CI) import this package and get esbuild as
22
+ * a normal, auto-installed dependency.
23
+ *
24
+ * esbuild and fflate are loaded with a dynamic `import()` (not a static top-level import) so
25
+ * that nothing in this package's static graph names esbuild until a deploy actually runs —
26
+ * a second layer of protection on top of the package split.
27
+ *
28
+ * Mirrors: `esbuild <source> --bundle --outfile=out.js --sourcemap --minify`, then zips the
29
+ * emitted files into the archive the Functions deploy endpoint expects.
30
+ */
31
+ declare function buildFunctionBundle(fn: ResolvedFunctionConfig): Promise<Uint8Array>;
32
+ //#endregion
33
+ export { FunctionBundler, buildFunctionBundle };
34
+ //# sourceMappingURL=function-bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-bundle.d.ts","names":[],"sources":["../../src/lib/function-bundle.ts"],"mappings":";;;;;;AAeA;;;;;AAEY;AAmBU,KArBV,eAAA,GAqB6B,CAAA,EAAA,EApBpC,sBAoBoC,EAAA,GAnBpC,OAmBoC,CAnB5B,UAmB4B,CAAA;;;;;AAE/B;;;;;;;;;;;;;iBAFY,mBAAA,KACjB,yBACF,QAAQ"}
@@ -0,0 +1,65 @@
1
+ import { ErrorCode, PlatformError } from "@neondatabase/config";
2
+ import { basename } from "node:path";
3
+ //#region src/lib/function-bundle.ts
4
+ /**
5
+ * Build the deployable bundle (a ZIP archive of the esbuild-bundled source) for a function.
6
+ *
7
+ * This is the **imperative shell** step of function deploys, and the reason it lives in
8
+ * `@neondatabase/config-runtime` rather than `@neondatabase/config`: it pulls in `esbuild`
9
+ * (a native binary) and `fflate`. Keeping it out of `@neondatabase/config` means a `neon.ts`
10
+ * that only imports `defineConfig` never drags esbuild into the user's dependency tree or
11
+ * bundle. Deploy-side consumers (the neonctl CLI, CI) import this package and get esbuild as
12
+ * a normal, auto-installed dependency.
13
+ *
14
+ * esbuild and fflate are loaded with a dynamic `import()` (not a static top-level import) so
15
+ * that nothing in this package's static graph names esbuild until a deploy actually runs —
16
+ * a second layer of protection on top of the package split.
17
+ *
18
+ * Mirrors: `esbuild <source> --bundle --outfile=out.js --sourcemap --minify`, then zips the
19
+ * emitted files into the archive the Functions deploy endpoint expects.
20
+ */
21
+ async function buildFunctionBundle(fn) {
22
+ const esbuild = await loadEsbuild();
23
+ let result;
24
+ try {
25
+ result = await esbuild.build({
26
+ entryPoints: [fn.source],
27
+ bundle: true,
28
+ write: false,
29
+ outfile: "out.js",
30
+ sourcemap: true,
31
+ minify: true,
32
+ format: "esm",
33
+ platform: "node",
34
+ packages: "external",
35
+ logLevel: "silent"
36
+ });
37
+ } catch (cause) {
38
+ throw new PlatformError(ErrorCode.InvalidConfig, [`Failed to bundle function "${fn.slug}" from ${fn.source}.`, cause?.message ?? String(cause)].join(" "), { cause });
39
+ }
40
+ const entries = {};
41
+ for (const file of result.outputFiles ?? []) entries[basename(file.path)] = file.contents;
42
+ return zipBundle(entries);
43
+ }
44
+ async function zipBundle(entries) {
45
+ const { zipSync } = await loadFflate();
46
+ return zipSync(entries, { level: 6 });
47
+ }
48
+ async function loadEsbuild() {
49
+ try {
50
+ return await import("esbuild");
51
+ } catch (cause) {
52
+ throw new PlatformError(ErrorCode.InvalidConfig, ["Deploying Neon Functions requires `esbuild`, which could not be loaded.", "It is a dependency of @neondatabase/config-runtime — reinstall your dependencies (`pnpm install` / `npm install`)."].join(" "), { cause });
53
+ }
54
+ }
55
+ async function loadFflate() {
56
+ try {
57
+ return await import("fflate");
58
+ } catch (cause) {
59
+ throw new PlatformError(ErrorCode.InvalidConfig, ["Deploying Neon Functions requires `fflate`, which could not be loaded.", "It is a dependency of @neondatabase/config-runtime — reinstall your dependencies (`pnpm install` / `npm install`)."].join(" "), { cause });
60
+ }
61
+ }
62
+ //#endregion
63
+ export { buildFunctionBundle };
64
+
65
+ //# sourceMappingURL=function-bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-bundle.js","names":[],"sources":["../../src/lib/function-bundle.ts"],"sourcesContent":["import { basename } from \"node:path\";\nimport {\n\tErrorCode,\n\tPlatformError,\n\ttype ResolvedFunctionConfig,\n} from \"@neondatabase/config\";\n\n/**\n * Builds the deployable ZIP bundle for a single function. The default\n * implementation ({@link buildFunctionBundle}) shells out to esbuild, but\n * `pushConfig` / `apply` accept a custom bundler so a consumer that can't ship\n * esbuild's native binary (e.g. a single-file CLI) can supply its own — a WASM\n * build, an esbuild binary on PATH, etc. — without this package dragging esbuild\n * into their bundle.\n */\nexport type FunctionBundler = (\n\tfn: ResolvedFunctionConfig,\n) => Promise<Uint8Array>;\n\n/**\n * Build the deployable bundle (a ZIP archive of the esbuild-bundled source) for a function.\n *\n * This is the **imperative shell** step of function deploys, and the reason it lives in\n * `@neondatabase/config-runtime` rather than `@neondatabase/config`: it pulls in `esbuild`\n * (a native binary) and `fflate`. Keeping it out of `@neondatabase/config` means a `neon.ts`\n * that only imports `defineConfig` never drags esbuild into the user's dependency tree or\n * bundle. Deploy-side consumers (the neonctl CLI, CI) import this package and get esbuild as\n * a normal, auto-installed dependency.\n *\n * esbuild and fflate are loaded with a dynamic `import()` (not a static top-level import) so\n * that nothing in this package's static graph names esbuild until a deploy actually runs —\n * a second layer of protection on top of the package split.\n *\n * Mirrors: `esbuild <source> --bundle --outfile=out.js --sourcemap --minify`, then zips the\n * emitted files into the archive the Functions deploy endpoint expects.\n */\nexport async function buildFunctionBundle(\n\tfn: ResolvedFunctionConfig,\n): Promise<Uint8Array> {\n\tconst esbuild = await loadEsbuild();\n\n\tlet result: Awaited<ReturnType<typeof esbuild.build>>;\n\ttry {\n\t\tresult = await esbuild.build({\n\t\t\tentryPoints: [fn.source],\n\t\t\tbundle: true,\n\t\t\twrite: false,\n\t\t\t// Set an explicit outfile so the emitted files are named `out.js` / `out.js.map`\n\t\t\t// (with `write: false` and no outfile, esbuild labels the buffer `<stdout>`).\n\t\t\toutfile: \"out.js\",\n\t\t\tsourcemap: true,\n\t\t\tminify: true,\n\t\t\tformat: \"esm\",\n\t\t\tplatform: \"node\",\n\t\t\t// The Functions runtime provides Node built-ins; don't try to bundle them.\n\t\t\tpackages: \"external\",\n\t\t\tlogLevel: \"silent\",\n\t\t});\n\t} catch (cause) {\n\t\tthrow new PlatformError(\n\t\t\tErrorCode.InvalidConfig,\n\t\t\t[\n\t\t\t\t`Failed to bundle function \"${fn.slug}\" from ${fn.source}.`,\n\t\t\t\t(cause as Error)?.message ?? String(cause),\n\t\t\t].join(\" \"),\n\t\t\t{ cause },\n\t\t);\n\t}\n\n\tconst entries: Record<string, Uint8Array> = {};\n\t// `write: false` guarantees `outputFiles`, but the type is optional — guard for safety.\n\tfor (const file of result.outputFiles ?? []) {\n\t\t// esbuild returns absolute output paths; archive them under their basename\n\t\t// (`out.js`, `out.js.map`) so the bundle layout is stable regardless of cwd.\n\t\tentries[basename(file.path)] = file.contents;\n\t}\n\n\treturn zipBundle(entries);\n}\n\nasync function zipBundle(\n\tentries: Record<string, Uint8Array>,\n): Promise<Uint8Array> {\n\tconst { zipSync } = await loadFflate();\n\treturn zipSync(entries, { level: 6 });\n}\n\nasync function loadEsbuild(): Promise<typeof import(\"esbuild\")> {\n\ttry {\n\t\treturn await import(\"esbuild\");\n\t} catch (cause) {\n\t\tthrow new PlatformError(\n\t\t\tErrorCode.InvalidConfig,\n\t\t\t[\n\t\t\t\t\"Deploying Neon Functions requires `esbuild`, which could not be loaded.\",\n\t\t\t\t\"It is a dependency of @neondatabase/config-runtime — reinstall your dependencies (`pnpm install` / `npm install`).\",\n\t\t\t].join(\" \"),\n\t\t\t{ cause },\n\t\t);\n\t}\n}\n\nasync function loadFflate(): Promise<typeof import(\"fflate\")> {\n\ttry {\n\t\treturn await import(\"fflate\");\n\t} catch (cause) {\n\t\tthrow new PlatformError(\n\t\t\tErrorCode.InvalidConfig,\n\t\t\t[\n\t\t\t\t\"Deploying Neon Functions requires `fflate`, which could not be loaded.\",\n\t\t\t\t\"It is a dependency of @neondatabase/config-runtime — reinstall your dependencies (`pnpm install` / `npm install`).\",\n\t\t\t].join(\" \"),\n\t\t\t{ cause },\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoCA,eAAsB,oBACrB,IACsB;CACtB,MAAM,UAAU,MAAM,YAAY;CAElC,IAAI;CACJ,IAAI;EACH,SAAS,MAAM,QAAQ,MAAM;GAC5B,aAAa,CAAC,GAAG,MAAM;GACvB,QAAQ;GACR,OAAO;GAGP,SAAS;GACT,WAAW;GACX,QAAQ;GACR,QAAQ;GACR,UAAU;GAEV,UAAU;GACV,UAAU;EACX,CAAC;CACF,SAAS,OAAO;EACf,MAAM,IAAI,cACT,UAAU,eACV,CACC,8BAA8B,GAAG,KAAK,SAAS,GAAG,OAAO,IACxD,OAAiB,WAAW,OAAO,KAAK,CAC1C,EAAE,KAAK,GAAG,GACV,EAAE,MAAM,CACT;CACD;CAEA,MAAM,UAAsC,CAAC;CAE7C,KAAK,MAAM,QAAQ,OAAO,eAAe,CAAC,GAGzC,QAAQ,SAAS,KAAK,IAAI,KAAK,KAAK;CAGrC,OAAO,UAAU,OAAO;AACzB;AAEA,eAAe,UACd,SACsB;CACtB,MAAM,EAAE,YAAY,MAAM,WAAW;CACrC,OAAO,QAAQ,SAAS,EAAE,OAAO,EAAE,CAAC;AACrC;AAEA,eAAe,cAAiD;CAC/D,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,cACT,UAAU,eACV,CACC,2EACA,oHACD,EAAE,KAAK,GAAG,GACV,EAAE,MAAM,CACT;CACD;AACD;AAEA,eAAe,aAA+C;CAC7D,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,cACT,UAAU,eACV,CACC,0EACA,oHACD,EAAE,KAAK,GAAG,GACV,EAAE,MAAM,CACT;CACD;AACD"}
@@ -0,0 +1,77 @@
1
+ import { FunctionBundler } from "./function-bundle.js";
2
+ import { PulledBranchConfig } from "./pull-config.js";
3
+ import { PushConfigOptions } from "./push-config.js";
4
+ import { Config, PushResult } from "@neondatabase/config";
5
+
6
+ //#region src/lib/operations.d.ts
7
+
8
+ /**
9
+ * Where to run the operation and how to authenticate. Filesystem- and env-agnostic: the
10
+ * `projectId` and `branchId` are always passed explicitly by the caller (e.g. neonctl
11
+ * resolves them from `.neon` / `NEON_*` and forwards them here).
12
+ */
13
+ interface ConfigOperationOptions {
14
+ /**
15
+ * Neon project id. **Required** — the management API addresses branches through their
16
+ * project, so operations cannot run without it.
17
+ */
18
+ projectId: string;
19
+ /**
20
+ * Neon branch id (`br-…`). **Required.** Must already exist on the project; resolve
21
+ * branch names to ids before calling.
22
+ */
23
+ branchId: string;
24
+ /** Neon API key. Falls back to `NEON_API_KEY` / neonctl credentials. */
25
+ apiKey?: string;
26
+ /** Inject a custom NeonApi adapter (primarily for tests). */
27
+ api?: PushConfigOptions["api"];
28
+ }
29
+ /**
30
+ * Options accepted by {@link apply} on top of {@link ConfigOperationOptions}.
31
+ */
32
+ interface ApplyOptions extends ConfigOperationOptions {
33
+ /**
34
+ * Auto-confirm overriding existing remote settings (TTL, `protected`, compute
35
+ * settings) on the selected branch. Without it, drift is reported as a conflict.
36
+ */
37
+ updateExisting?: boolean;
38
+ /** Auto-confirm applying to a branch marked `protected` on Neon. */
39
+ allowProtectedBranch?: boolean;
40
+ /**
41
+ * Custom function bundler. Defaults to esbuild (`buildFunctionBundle`); inject
42
+ * your own to deploy functions without pulling esbuild's native binary into
43
+ * your build. See {@link FunctionBundler}.
44
+ */
45
+ bundleFunction?: FunctionBundler;
46
+ }
47
+ /**
48
+ * Read a branch's live Neon state as a plain object (project + branch metadata and the
49
+ * reverse-engineered `BranchConfig`). Network read only — never mutates.
50
+ *
51
+ * `projectId` and `branchId` are **required** (both in `options`).
52
+ */
53
+ declare function inspect(options: ConfigOperationOptions): Promise<PulledBranchConfig>;
54
+ /**
55
+ * Compute what {@link apply} would do for the given branch without mutating anything
56
+ * (dry-run plan). Returns the full {@link PushResult} with the planned changes in
57
+ * `applied` and any blocking drift in `conflicts` — the Neon equivalent of
58
+ * `terraform plan`.
59
+ *
60
+ * `projectId` and `branchId` are **required** (both in `options`).
61
+ */
62
+ declare function plan(config: Config, options: ConfigOperationOptions): Promise<PushResult>;
63
+ /**
64
+ * Apply a `neon.ts` policy to the given Neon branch and return the {@link PushResult}
65
+ * describing what changed — the Neon equivalent of `terraform apply`.
66
+ *
67
+ * `projectId` and `branchId` are **required** (both in `options`). Pass `updateExisting`
68
+ * to auto-confirm overriding existing remote settings and `allowProtectedBranch` to
69
+ * auto-confirm applying to a protected branch; otherwise drift is reported as a
70
+ * `PushConflictError`.
71
+ *
72
+ * Never creates projects or branches — both must already exist.
73
+ */
74
+ declare function apply(config: Config, options: ApplyOptions): Promise<PushResult>;
75
+ //#endregion
76
+ export { ApplyOptions, ConfigOperationOptions, apply, inspect, plan };
77
+ //# sourceMappingURL=operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.d.ts","names":[],"sources":["../../src/lib/operations.ts"],"mappings":";;;;;;;;;AAUA;AAoBA;;AAakB,UAjCD,sBAAA,CAiCC;;AAb0C;AAsB5D;;WACU,EAAA,MAAA;;;AACA;AAiBV;EAA0B,QAAA,EAAA,MAAA;;QAEhB,CAAA,EAAA,MAAA;;KACP,CAAA,EAlDI,iBAkDJ,CAAA,KAAA,CAAA;AAAO;AAuBV;;;AAEU,UArEO,YAAA,SAAqB,sBAqE5B,CAAA;;;AACA;;;;;;;;;;mBAzDQ;;;;;;;;iBASI,OAAA,UACZ,yBACP,QAAQ;;;;;;;;;iBAiBW,IAAA,SACb,iBACC,yBACP,QAAQ;;;;;;;;;;;;iBAuBW,KAAA,SACb,iBACC,eACP,QAAQ"}
@@ -0,0 +1,61 @@
1
+ import { pullConfig } from "./pull-config.js";
2
+ import { pushConfig } from "./push-config.js";
3
+ //#region src/lib/operations.ts
4
+ /**
5
+ * Read a branch's live Neon state as a plain object (project + branch metadata and the
6
+ * reverse-engineered `BranchConfig`). Network read only — never mutates.
7
+ *
8
+ * `projectId` and `branchId` are **required** (both in `options`).
9
+ */
10
+ async function inspect(options) {
11
+ return pullConfig({
12
+ projectId: options.projectId,
13
+ branchId: options.branchId,
14
+ ...options.api ? { api: options.api } : {},
15
+ ...options.apiKey ? { apiKey: options.apiKey } : {}
16
+ });
17
+ }
18
+ /**
19
+ * Compute what {@link apply} would do for the given branch without mutating anything
20
+ * (dry-run plan). Returns the full {@link PushResult} with the planned changes in
21
+ * `applied` and any blocking drift in `conflicts` — the Neon equivalent of
22
+ * `terraform plan`.
23
+ *
24
+ * `projectId` and `branchId` are **required** (both in `options`).
25
+ */
26
+ async function plan(config, options) {
27
+ return pushConfig(config, {
28
+ projectId: options.projectId,
29
+ branchId: options.branchId,
30
+ dryRun: true,
31
+ updateExisting: true,
32
+ ...options.api ? { api: options.api } : {},
33
+ ...options.apiKey ? { apiKey: options.apiKey } : {}
34
+ });
35
+ }
36
+ /**
37
+ * Apply a `neon.ts` policy to the given Neon branch and return the {@link PushResult}
38
+ * describing what changed — the Neon equivalent of `terraform apply`.
39
+ *
40
+ * `projectId` and `branchId` are **required** (both in `options`). Pass `updateExisting`
41
+ * to auto-confirm overriding existing remote settings and `allowProtectedBranch` to
42
+ * auto-confirm applying to a protected branch; otherwise drift is reported as a
43
+ * `PushConflictError`.
44
+ *
45
+ * Never creates projects or branches — both must already exist.
46
+ */
47
+ async function apply(config, options) {
48
+ return pushConfig(config, {
49
+ projectId: options.projectId,
50
+ branchId: options.branchId,
51
+ ...options.api ? { api: options.api } : {},
52
+ ...options.apiKey ? { apiKey: options.apiKey } : {},
53
+ ...options.updateExisting ? { updateExisting: true } : {},
54
+ ...options.allowProtectedBranch ? { allowProtectedBranch: true } : {},
55
+ ...options.bundleFunction ? { bundleFunction: options.bundleFunction } : {}
56
+ });
57
+ }
58
+ //#endregion
59
+ export { apply, inspect, plan };
60
+
61
+ //# sourceMappingURL=operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.js","names":[],"sources":["../../src/lib/operations.ts"],"sourcesContent":["import type { Config, PushResult } from \"@neondatabase/config\";\nimport type { FunctionBundler } from \"./function-bundle.js\";\nimport { type PulledBranchConfig, pullConfig } from \"./pull-config.js\";\nimport { type PushConfigOptions, pushConfig } from \"./push-config.js\";\n\n/**\n * Where to run the operation and how to authenticate. Filesystem- and env-agnostic: the\n * `projectId` and `branchId` are always passed explicitly by the caller (e.g. neonctl\n * resolves them from `.neon` / `NEON_*` and forwards them here).\n */\nexport interface ConfigOperationOptions {\n\t/**\n\t * Neon project id. **Required** — the management API addresses branches through their\n\t * project, so operations cannot run without it.\n\t */\n\tprojectId: string;\n\t/**\n\t * Neon branch id (`br-…`). **Required.** Must already exist on the project; resolve\n\t * branch names to ids before calling.\n\t */\n\tbranchId: string;\n\t/** Neon API key. Falls back to `NEON_API_KEY` / neonctl credentials. */\n\tapiKey?: string;\n\t/** Inject a custom NeonApi adapter (primarily for tests). */\n\tapi?: PushConfigOptions[\"api\"];\n}\n\n/**\n * Options accepted by {@link apply} on top of {@link ConfigOperationOptions}.\n */\nexport interface ApplyOptions extends ConfigOperationOptions {\n\t/**\n\t * Auto-confirm overriding existing remote settings (TTL, `protected`, compute\n\t * settings) on the selected branch. Without it, drift is reported as a conflict.\n\t */\n\tupdateExisting?: boolean;\n\t/** Auto-confirm applying to a branch marked `protected` on Neon. */\n\tallowProtectedBranch?: boolean;\n\t/**\n\t * Custom function bundler. Defaults to esbuild (`buildFunctionBundle`); inject\n\t * your own to deploy functions without pulling esbuild's native binary into\n\t * your build. See {@link FunctionBundler}.\n\t */\n\tbundleFunction?: FunctionBundler;\n}\n\n/**\n * Read a branch's live Neon state as a plain object (project + branch metadata and the\n * reverse-engineered `BranchConfig`). Network read only — never mutates.\n *\n * `projectId` and `branchId` are **required** (both in `options`).\n */\nexport async function inspect(\n\toptions: ConfigOperationOptions,\n): Promise<PulledBranchConfig> {\n\treturn pullConfig({\n\t\tprojectId: options.projectId,\n\t\tbranchId: options.branchId,\n\t\t...(options.api ? { api: options.api } : {}),\n\t\t...(options.apiKey ? { apiKey: options.apiKey } : {}),\n\t});\n}\n\n/**\n * Compute what {@link apply} would do for the given branch without mutating anything\n * (dry-run plan). Returns the full {@link PushResult} with the planned changes in\n * `applied` and any blocking drift in `conflicts` — the Neon equivalent of\n * `terraform plan`.\n *\n * `projectId` and `branchId` are **required** (both in `options`).\n */\nexport async function plan(\n\tconfig: Config,\n\toptions: ConfigOperationOptions,\n): Promise<PushResult> {\n\treturn pushConfig(config, {\n\t\tprojectId: options.projectId,\n\t\tbranchId: options.branchId,\n\t\tdryRun: true,\n\t\t// Surface the full would-apply list as plan steps without mutating anything.\n\t\tupdateExisting: true,\n\t\t...(options.api ? { api: options.api } : {}),\n\t\t...(options.apiKey ? { apiKey: options.apiKey } : {}),\n\t});\n}\n\n/**\n * Apply a `neon.ts` policy to the given Neon branch and return the {@link PushResult}\n * describing what changed — the Neon equivalent of `terraform apply`.\n *\n * `projectId` and `branchId` are **required** (both in `options`). Pass `updateExisting`\n * to auto-confirm overriding existing remote settings and `allowProtectedBranch` to\n * auto-confirm applying to a protected branch; otherwise drift is reported as a\n * `PushConflictError`.\n *\n * Never creates projects or branches — both must already exist.\n */\nexport async function apply(\n\tconfig: Config,\n\toptions: ApplyOptions,\n): Promise<PushResult> {\n\treturn pushConfig(config, {\n\t\tprojectId: options.projectId,\n\t\tbranchId: options.branchId,\n\t\t...(options.api ? { api: options.api } : {}),\n\t\t...(options.apiKey ? { apiKey: options.apiKey } : {}),\n\t\t...(options.updateExisting ? { updateExisting: true } : {}),\n\t\t...(options.allowProtectedBranch ? { allowProtectedBranch: true } : {}),\n\t\t...(options.bundleFunction\n\t\t\t? { bundleFunction: options.bundleFunction }\n\t\t\t: {}),\n\t});\n}\n"],"mappings":";;;;;;;;;AAoDA,eAAsB,QACrB,SAC8B;CAC9B,OAAO,WAAW;EACjB,WAAW,QAAQ;EACnB,UAAU,QAAQ;EAClB,GAAI,QAAQ,MAAM,EAAE,KAAK,QAAQ,IAAI,IAAI,CAAC;EAC1C,GAAI,QAAQ,SAAS,EAAE,QAAQ,QAAQ,OAAO,IAAI,CAAC;CACpD,CAAC;AACF;;;;;;;;;AAUA,eAAsB,KACrB,QACA,SACsB;CACtB,OAAO,WAAW,QAAQ;EACzB,WAAW,QAAQ;EACnB,UAAU,QAAQ;EAClB,QAAQ;EAER,gBAAgB;EAChB,GAAI,QAAQ,MAAM,EAAE,KAAK,QAAQ,IAAI,IAAI,CAAC;EAC1C,GAAI,QAAQ,SAAS,EAAE,QAAQ,QAAQ,OAAO,IAAI,CAAC;CACpD,CAAC;AACF;;;;;;;;;;;;AAaA,eAAsB,MACrB,QACA,SACsB;CACtB,OAAO,WAAW,QAAQ;EACzB,WAAW,QAAQ;EACnB,UAAU,QAAQ;EAClB,GAAI,QAAQ,MAAM,EAAE,KAAK,QAAQ,IAAI,IAAI,CAAC;EAC1C,GAAI,QAAQ,SAAS,EAAE,QAAQ,QAAQ,OAAO,IAAI,CAAC;EACnD,GAAI,QAAQ,iBAAiB,EAAE,gBAAgB,KAAK,IAAI,CAAC;EACzD,GAAI,QAAQ,uBAAuB,EAAE,sBAAsB,KAAK,IAAI,CAAC;EACrE,GAAI,QAAQ,iBACT,EAAE,gBAAgB,QAAQ,eAAe,IACzC,CAAC;CACL,CAAC;AACF"}
@@ -0,0 +1,63 @@
1
+ import { BranchConfig, BucketConfig, NeonApi, NeonBranchSnapshot, NeonBucketSnapshot, NeonEndpointSnapshot, NeonFunctionSnapshot, NeonProjectSnapshot } from "@neondatabase/config";
2
+
3
+ //#region src/lib/pull-config.d.ts
4
+ interface PullConfigOptions {
5
+ /** Neon project id (`<project>`). Required — the API addresses branches by project. */
6
+ projectId: string;
7
+ /** Neon branch id (`br-…`). Required. Resolve names to ids before calling. */
8
+ branchId: string;
9
+ /** Neon API key. Falls back to `NEON_API_KEY` / neonctl credentials. */
10
+ apiKey?: string;
11
+ /** Inject a custom NeonApi adapter (primarily for tests). */
12
+ api?: NeonApi;
13
+ }
14
+ /**
15
+ * Live Preview-feature state read back from a branch. Surfaced alongside `config` rather
16
+ * than inside it because functions cannot round-trip: the remote only knows the deployed
17
+ * bundle, not the local `source` path a {@link FunctionConfig} requires, so a pulled
18
+ * function is reported as `{ slug, name }` (no `source`).
19
+ */
20
+ interface PulledPreview {
21
+ buckets: BucketConfig[];
22
+ functions: Array<{
23
+ slug: string;
24
+ name: string;
25
+ }>;
26
+ aiGatewayEnabled: boolean;
27
+ }
28
+ interface PulledBranchConfig {
29
+ project: {
30
+ id: string;
31
+ name: string;
32
+ region: string;
33
+ pgVersion: number;
34
+ orgId?: string;
35
+ };
36
+ branch: {
37
+ id: string;
38
+ name: string;
39
+ parent?: string;
40
+ isDefault: boolean;
41
+ protected: boolean;
42
+ expiresAt?: string;
43
+ };
44
+ config: BranchConfig;
45
+ /**
46
+ * Live Preview-feature state, when the branch has any buckets/functions or an enabled
47
+ * AI Gateway. Omitted entirely when there is nothing to report.
48
+ */
49
+ preview?: PulledPreview;
50
+ }
51
+ declare function pullConfig(options: PullConfigOptions): Promise<PulledBranchConfig>;
52
+ declare function buildPulledBranchConfig(project: NeonProjectSnapshot, branch: NeonBranchSnapshot, branches: NeonBranchSnapshot[], endpoint: NeonEndpointSnapshot | undefined, previewState?: {
53
+ buckets: NeonBucketSnapshot[];
54
+ functions: NeonFunctionSnapshot[];
55
+ aiGatewayEnabled: boolean;
56
+ /** Whether a Neon Auth integration is enabled on the branch. */
57
+ authEnabled?: boolean;
58
+ /** Whether a Neon Data API integration is enabled on the branch. */
59
+ dataApiEnabled?: boolean;
60
+ }): PulledBranchConfig;
61
+ //#endregion
62
+ export { PullConfigOptions, PulledBranchConfig, PulledPreview, buildPulledBranchConfig, pullConfig };
63
+ //# sourceMappingURL=pull-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pull-config.d.ts","names":[],"sources":["../../src/lib/pull-config.ts"],"mappings":";;;UAgBiB,iBAAA;;EAAA,SAAA,EAAA,MAAA;EAiBA;EAAa,QAAA,EAAA,MAAA;;QAElB,CAAA,EAAA,MAAA;EAAK;EAIA,GAAA,CAAA,EAfV,OAeU;;;;AAqBO;AAGxB;;;AAEW,UAhCM,aAAA,CAgCN;SAAR,EA/BO,YA+BP,EAAA;EAAO,SAAA,EA9BE,KA8BF,CAAA;IA0DM,IAAA,EAAA,MAAA;IAAuB,IAAA,EAAA,MAAA;;kBAE9B,EAAA,OAAA;;AAEE,UAxFM,kBAAA,CAwFN;SAEA,EAAA;IACE,EAAA,EAAA,MAAA;IAOV,IAAA,EAAA,MAAA;IAAkB,MAAA,EAAA,MAAA;;;;;;;;;;;;UAlFZ;;;;;YAKE;;iBAGW,UAAA,UACZ,oBACP,QAAQ;iBA0DK,uBAAA,UACN,6BACD,8BACE,gCACA;WAEA;aACE;;;;;;IAOV"}
@@ -0,0 +1,113 @@
1
+ import { ErrorCode, PlatformError, createNeonApiFromOptions } from "@neondatabase/config";
2
+ //#region src/lib/pull-config.ts
3
+ async function pullConfig(options) {
4
+ const api = options.api ?? createApiFromOptions(options);
5
+ const projectId = options.projectId;
6
+ const project = await api.getProject(projectId);
7
+ const [branches, endpoints] = await Promise.all([api.listBranches(projectId), api.listEndpoints(projectId)]);
8
+ const branch = resolveBranch(options.branchId, branches);
9
+ const endpoint = endpoints.find((ep) => ep.type === "read_write" && ep.branchId === branch.id);
10
+ const probeDatabase = pickProbeDatabase(await api.listBranchDatabases(projectId, branch.id));
11
+ const [buckets, functions, aiGatewayEnabled, auth, dataApi] = await Promise.all([
12
+ api.listBranchBuckets(projectId, branch.id),
13
+ api.listBranchFunctions(projectId, branch.id),
14
+ api.getAiGatewayEnabled(projectId, branch.id),
15
+ api.getNeonAuth(projectId, branch.id),
16
+ probeDatabase ? api.getNeonDataApi(projectId, branch.id, probeDatabase) : Promise.resolve(null)
17
+ ]);
18
+ return buildPulledBranchConfig(project, branch, branches, endpoint, {
19
+ buckets,
20
+ functions,
21
+ aiGatewayEnabled,
22
+ authEnabled: auth !== null,
23
+ dataApiEnabled: dataApi !== null
24
+ });
25
+ }
26
+ /**
27
+ * Pick the database to probe for a Data API integration. Data API is enabled per
28
+ * branch + database; for read-back we only need to know whether *any* database has it
29
+ * on, so prefer the conventional default (`neondb`) and otherwise fall back to the first
30
+ * database. Returns `undefined` when the branch has no databases.
31
+ */
32
+ function pickProbeDatabase(databases) {
33
+ if (databases.length === 0) return void 0;
34
+ const byName = databases.find((d) => d.name === "neondb");
35
+ if (byName) return byName.name;
36
+ return databases[0].name;
37
+ }
38
+ function createApiFromOptions(options) {
39
+ return createNeonApiFromOptions("pullConfig", { ...options.apiKey ? { apiKey: options.apiKey } : {} });
40
+ }
41
+ function buildPulledBranchConfig(project, branch, branches, endpoint, previewState) {
42
+ const parent = branch.parentId ? branches.find((b) => b.id === branch.parentId) : void 0;
43
+ const config = {
44
+ ...previewState?.authEnabled ? { auth: {} } : {},
45
+ ...previewState?.dataApiEnabled ? { dataApi: {} } : {}
46
+ };
47
+ if (parent) config.parent = parent.name;
48
+ if (branch.expiresAt) config.ttl = branch.expiresAt;
49
+ if (branch.protected) config.protected = true;
50
+ if (endpoint) {
51
+ const compute = endpointToComputeSettings(endpoint, project);
52
+ if (compute) config.postgres = { computeSettings: compute };
53
+ }
54
+ const result = {
55
+ project: {
56
+ id: project.id,
57
+ name: project.name,
58
+ region: project.regionId,
59
+ pgVersion: project.pgVersion,
60
+ ...project.orgId ? { orgId: project.orgId } : {}
61
+ },
62
+ branch: {
63
+ id: branch.id,
64
+ name: branch.name,
65
+ ...parent ? { parent: parent.name } : {},
66
+ isDefault: branch.isDefault,
67
+ protected: branch.protected,
68
+ ...branch.expiresAt ? { expiresAt: branch.expiresAt } : {}
69
+ },
70
+ config
71
+ };
72
+ const preview = previewState ? buildPulledPreview(previewState) : void 0;
73
+ if (preview) result.preview = preview;
74
+ return result;
75
+ }
76
+ /**
77
+ * Reverse-engineer the {@link PulledPreview} from remote snapshots. Returns `undefined` when
78
+ * the branch has no Preview features so the field can be omitted entirely.
79
+ */
80
+ function buildPulledPreview(state) {
81
+ if (state.buckets.length === 0 && state.functions.length === 0 && !state.aiGatewayEnabled) return;
82
+ return {
83
+ buckets: state.buckets.map((b) => ({
84
+ name: b.name,
85
+ access: b.accessLevel
86
+ })),
87
+ functions: state.functions.map((f) => ({
88
+ slug: f.slug,
89
+ name: f.name
90
+ })),
91
+ aiGatewayEnabled: state.aiGatewayEnabled
92
+ };
93
+ }
94
+ function resolveBranch(branchId, branches) {
95
+ const match = branches.find((b) => b.id === branchId);
96
+ if (match) return match;
97
+ throw new PlatformError(ErrorCode.BranchNotFound, [`pullConfig: branch id ${JSON.stringify(branchId)} not found on project.`, `Available branches: ${branches.map((b) => `${b.name} (${b.id})`).join(", ") || "(none)"}.`].join(" "), { details: {
98
+ branchId,
99
+ available: branches.map((b) => b.id)
100
+ } });
101
+ }
102
+ function endpointToComputeSettings(endpoint, project) {
103
+ const defaults = project.defaultEndpointSettings;
104
+ const out = {};
105
+ if (endpoint.autoscalingLimitMinCu !== void 0 && endpoint.autoscalingLimitMinCu !== defaults?.autoscalingLimitMinCu) out.autoscalingLimitMinCu = endpoint.autoscalingLimitMinCu;
106
+ if (endpoint.autoscalingLimitMaxCu !== void 0 && endpoint.autoscalingLimitMaxCu !== defaults?.autoscalingLimitMaxCu) out.autoscalingLimitMaxCu = endpoint.autoscalingLimitMaxCu;
107
+ if (endpoint.suspendTimeout !== void 0 && endpoint.suspendTimeout !== defaults?.suspendTimeout) out.suspendTimeout = endpoint.suspendTimeout;
108
+ return Object.keys(out).length > 0 ? out : void 0;
109
+ }
110
+ //#endregion
111
+ export { buildPulledBranchConfig, pullConfig };
112
+
113
+ //# sourceMappingURL=pull-config.js.map