@infracraft/pulumi 1.8.0 → 1.10.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.
- package/dist/agents/hint.cjs +51 -0
- package/dist/agents/hint.cjs.map +1 -0
- package/dist/agents/hint.d.cts +45 -0
- package/dist/agents/hint.d.cts.map +1 -0
- package/dist/agents/hint.d.mts +45 -0
- package/dist/agents/hint.d.mts.map +1 -0
- package/dist/agents/hint.mjs +49 -0
- package/dist/agents/hint.mjs.map +1 -0
- package/dist/neon/branch.cjs +3 -11
- package/dist/neon/branch.cjs.map +1 -1
- package/dist/neon/branch.d.cts +3 -11
- package/dist/neon/branch.d.cts.map +1 -1
- package/dist/neon/branch.d.mts +3 -11
- package/dist/neon/branch.d.mts.map +1 -1
- package/dist/neon/branch.mjs +3 -11
- package/dist/neon/branch.mjs.map +1 -1
- package/dist/railway/environment.cjs +6 -13
- package/dist/railway/environment.cjs.map +1 -1
- package/dist/railway/environment.d.cts +4 -10
- package/dist/railway/environment.d.cts.map +1 -1
- package/dist/railway/environment.d.mts +4 -10
- package/dist/railway/environment.d.mts.map +1 -1
- package/dist/railway/environment.mjs +6 -13
- package/dist/railway/environment.mjs.map +1 -1
- package/dist/vercel/project.cjs +6 -13
- package/dist/vercel/project.cjs.map +1 -1
- package/dist/vercel/project.d.cts +4 -11
- package/dist/vercel/project.d.cts.map +1 -1
- package/dist/vercel/project.d.mts +4 -11
- package/dist/vercel/project.d.mts.map +1 -1
- package/dist/vercel/project.mjs +6 -13
- package/dist/vercel/project.mjs.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_chunk = require('../chunk-BVYJZCqc.cjs');
|
|
3
|
+
let _pulumi_pulumi = require("@pulumi/pulumi");
|
|
4
|
+
_pulumi_pulumi = require_chunk.__toESM(_pulumi_pulumi, 1);
|
|
5
|
+
|
|
6
|
+
//#region src/agents/hint.ts
|
|
7
|
+
/**
|
|
8
|
+
* Generic infracraft reminders, prepended to every hint. These hold for any
|
|
9
|
+
* infracraft stack regardless of the consuming project.
|
|
10
|
+
*/
|
|
11
|
+
const INFRACRAFT_DEFAULTS = [
|
|
12
|
+
"Adopt-or-create: re-running is safe — existing resources are adopted, missing ones created",
|
|
13
|
+
"Shared resources (Railway services/projects, Neon projects) have no-op deletes — destroy never removes them",
|
|
14
|
+
"Mark shared/production resources protect:true — pulumi destroy aborts on protected resources"
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Emits a delimited `<infracraft-hint>` block of reminders for AI coding agents
|
|
18
|
+
* operating this Pulumi stack — modeled on Vercel's `AGENTS.md` guidance: a
|
|
19
|
+
* delimited block, an agent-directed intro, then terse directive bullets.
|
|
20
|
+
*
|
|
21
|
+
* No-op for humans (no agent env var) unless `enabled` is forced. Call it once at
|
|
22
|
+
* the top of your Pulumi program; the infracraft defaults are always included and
|
|
23
|
+
* `project` lines are appended.
|
|
24
|
+
*
|
|
25
|
+
* @param options Project reminders, channel, and detection override.
|
|
26
|
+
* @returns Nothing; emits to the chosen channel as a side effect.
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* agentHint({
|
|
30
|
+
* project: [
|
|
31
|
+
* "production is protected — `unprotect <urn>` first for a deliberate change",
|
|
32
|
+
* "feature env = imports:[staging], zero config; pulumi destroy is safe",
|
|
33
|
+
* ],
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function agentHint(options = {}) {
|
|
38
|
+
if (!(options.enabled ?? (!!process.env.CLAUDECODE || !!process.env.AI_AGENT))) return;
|
|
39
|
+
const block = [
|
|
40
|
+
"<infracraft-hint>",
|
|
41
|
+
"Reminders for AI agents operating this Pulumi stack:",
|
|
42
|
+
...[...INFRACRAFT_DEFAULTS, ...options.project ?? []].map((line) => `- ${line}`),
|
|
43
|
+
"</infracraft-hint>"
|
|
44
|
+
].join("\n");
|
|
45
|
+
if (options.channel === "pulumi-log") _pulumi_pulumi.log.info(block);
|
|
46
|
+
else process.stderr.write(`${block}\n`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.agentHint = agentHint;
|
|
51
|
+
//# sourceMappingURL=hint.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hint.cjs","names":[],"sources":["../../src/agents/hint.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\n\n/**\n * Generic infracraft reminders, prepended to every hint. These hold for any\n * infracraft stack regardless of the consuming project.\n */\nconst INFRACRAFT_DEFAULTS = [\n\t\"Adopt-or-create: re-running is safe — existing resources are adopted, missing ones created\",\n\t\"Shared resources (Railway services/projects, Neon projects) have no-op deletes — destroy never removes them\",\n\t\"Mark shared/production resources protect:true — pulumi destroy aborts on protected resources\",\n];\n\n/** Options for {@link agentHint}. */\nexport interface AgentHintOptions {\n\t/** Project-specific reminders appended after the infracraft defaults. */\n\tproject?: string[];\n\n\t/**\n\t * Force the hint on or off. Defaults to auto-detecting an AI coding agent via\n\t * the `CLAUDECODE` / `AI_AGENT` environment variables.\n\t */\n\tenabled?: boolean;\n\n\t/**\n\t * Where to write the hint. `\"stderr\"` (default) prints it prominently the\n\t * instant the program loads, before Pulumi's own output — modeled on how the\n\t * Vercel CLI surfaces agent guidance. `\"pulumi-log\"` routes it through\n\t * `pulumi.log.info` (lands in the Diagnostics section instead).\n\t */\n\tchannel?: \"stderr\" | \"pulumi-log\";\n}\n\n/**\n * Emits a delimited `<infracraft-hint>` block of reminders for AI coding agents\n * operating this Pulumi stack — modeled on Vercel's `AGENTS.md` guidance: a\n * delimited block, an agent-directed intro, then terse directive bullets.\n *\n * No-op for humans (no agent env var) unless `enabled` is forced. Call it once at\n * the top of your Pulumi program; the infracraft defaults are always included and\n * `project` lines are appended.\n *\n * @param options Project reminders, channel, and detection override.\n * @returns Nothing; emits to the chosen channel as a side effect.\n * @example\n * ```typescript\n * agentHint({\n * project: [\n * \"production is protected — `unprotect <urn>` first for a deliberate change\",\n * \"feature env = imports:[staging], zero config; pulumi destroy is safe\",\n * ],\n * });\n * ```\n */\nexport function agentHint(options: AgentHintOptions = {}): void {\n\tconst enabled =\n\t\toptions.enabled ?? (!!process.env.CLAUDECODE || !!process.env.AI_AGENT);\n\n\tif (!enabled) {\n\t\treturn;\n\t}\n\n\tconst lines = [...INFRACRAFT_DEFAULTS, ...(options.project ?? [])];\n\n\tconst block = [\n\t\t\"<infracraft-hint>\",\n\t\t\"Reminders for AI agents operating this Pulumi stack:\",\n\t\t...lines.map((line) => `- ${line}`),\n\t\t\"</infracraft-hint>\",\n\t].join(\"\\n\");\n\n\tif (options.channel === \"pulumi-log\") {\n\t\tpulumi.log.info(block);\n\t} else {\n\t\tprocess.stderr.write(`${block}\\n`);\n\t}\n}\n"],"mappings":";;;;;;;;;;AAMA,MAAM,sBAAsB;CAC3B;CACA;CACA;AACD;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,UAAU,UAA4B,CAAC,GAAS;CAI/D,IAAI,EAFH,QAAQ,YAAY,CAAC,CAAC,QAAQ,IAAI,cAAc,CAAC,CAAC,QAAQ,IAAI,YAG9D;CAKD,MAAM,QAAQ;EACb;EACA;EACA,GAAG,CALW,GAAG,qBAAqB,GAAI,QAAQ,WAAW,CAAC,CAKvD,EAAE,KAAK,SAAS,KAAK,MAAM;EAClC;CACD,EAAE,KAAK,IAAI;CAEX,IAAI,QAAQ,YAAY,cACvB,eAAO,IAAI,KAAK,KAAK;MAErB,QAAQ,OAAO,MAAM,GAAG,MAAM,GAAG;AAEnC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { t as __name } from "../chunk-OPjESj5l.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/agents/hint.d.ts
|
|
4
|
+
/** Options for {@link agentHint}. */
|
|
5
|
+
interface AgentHintOptions {
|
|
6
|
+
/** Project-specific reminders appended after the infracraft defaults. */
|
|
7
|
+
project?: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Force the hint on or off. Defaults to auto-detecting an AI coding agent via
|
|
10
|
+
* the `CLAUDECODE` / `AI_AGENT` environment variables.
|
|
11
|
+
*/
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Where to write the hint. `"stderr"` (default) prints it prominently the
|
|
15
|
+
* instant the program loads, before Pulumi's own output — modeled on how the
|
|
16
|
+
* Vercel CLI surfaces agent guidance. `"pulumi-log"` routes it through
|
|
17
|
+
* `pulumi.log.info` (lands in the Diagnostics section instead).
|
|
18
|
+
*/
|
|
19
|
+
channel?: "stderr" | "pulumi-log";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Emits a delimited `<infracraft-hint>` block of reminders for AI coding agents
|
|
23
|
+
* operating this Pulumi stack — modeled on Vercel's `AGENTS.md` guidance: a
|
|
24
|
+
* delimited block, an agent-directed intro, then terse directive bullets.
|
|
25
|
+
*
|
|
26
|
+
* No-op for humans (no agent env var) unless `enabled` is forced. Call it once at
|
|
27
|
+
* the top of your Pulumi program; the infracraft defaults are always included and
|
|
28
|
+
* `project` lines are appended.
|
|
29
|
+
*
|
|
30
|
+
* @param options Project reminders, channel, and detection override.
|
|
31
|
+
* @returns Nothing; emits to the chosen channel as a side effect.
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* agentHint({
|
|
35
|
+
* project: [
|
|
36
|
+
* "production is protected — `unprotect <urn>` first for a deliberate change",
|
|
37
|
+
* "feature env = imports:[staging], zero config; pulumi destroy is safe",
|
|
38
|
+
* ],
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function agentHint(options?: AgentHintOptions): void;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { AgentHintOptions, agentHint };
|
|
45
|
+
//# sourceMappingURL=hint.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hint.d.cts","names":[],"sources":["../../src/agents/hint.ts"],"mappings":";;;;UAaiB,gBAAA;;EAEhB,OAAA;EAFgC;;;;EAQhC,OAAA;EAQA;;AAAO;AAwBR;;;EAxBC,OAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;iBAwBe,SAAA,CAAU,OAA8B,GAArB,gBAAqB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { t as __name } from "../chunk-OPjESj5l.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/agents/hint.d.ts
|
|
4
|
+
/** Options for {@link agentHint}. */
|
|
5
|
+
interface AgentHintOptions {
|
|
6
|
+
/** Project-specific reminders appended after the infracraft defaults. */
|
|
7
|
+
project?: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Force the hint on or off. Defaults to auto-detecting an AI coding agent via
|
|
10
|
+
* the `CLAUDECODE` / `AI_AGENT` environment variables.
|
|
11
|
+
*/
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Where to write the hint. `"stderr"` (default) prints it prominently the
|
|
15
|
+
* instant the program loads, before Pulumi's own output — modeled on how the
|
|
16
|
+
* Vercel CLI surfaces agent guidance. `"pulumi-log"` routes it through
|
|
17
|
+
* `pulumi.log.info` (lands in the Diagnostics section instead).
|
|
18
|
+
*/
|
|
19
|
+
channel?: "stderr" | "pulumi-log";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Emits a delimited `<infracraft-hint>` block of reminders for AI coding agents
|
|
23
|
+
* operating this Pulumi stack — modeled on Vercel's `AGENTS.md` guidance: a
|
|
24
|
+
* delimited block, an agent-directed intro, then terse directive bullets.
|
|
25
|
+
*
|
|
26
|
+
* No-op for humans (no agent env var) unless `enabled` is forced. Call it once at
|
|
27
|
+
* the top of your Pulumi program; the infracraft defaults are always included and
|
|
28
|
+
* `project` lines are appended.
|
|
29
|
+
*
|
|
30
|
+
* @param options Project reminders, channel, and detection override.
|
|
31
|
+
* @returns Nothing; emits to the chosen channel as a side effect.
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* agentHint({
|
|
35
|
+
* project: [
|
|
36
|
+
* "production is protected — `unprotect <urn>` first for a deliberate change",
|
|
37
|
+
* "feature env = imports:[staging], zero config; pulumi destroy is safe",
|
|
38
|
+
* ],
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function agentHint(options?: AgentHintOptions): void;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { AgentHintOptions, agentHint };
|
|
45
|
+
//# sourceMappingURL=hint.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hint.d.mts","names":[],"sources":["../../src/agents/hint.ts"],"mappings":";;;;UAaiB,gBAAA;;EAEhB,OAAA;EAFgC;;;;EAQhC,OAAA;EAQA;;AAAO;AAwBR;;;EAxBC,OAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;iBAwBe,SAAA,CAAU,OAA8B,GAArB,gBAAqB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { t as __name } from "../chunk-OPjESj5l.mjs";
|
|
2
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
3
|
+
|
|
4
|
+
//#region src/agents/hint.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generic infracraft reminders, prepended to every hint. These hold for any
|
|
7
|
+
* infracraft stack regardless of the consuming project.
|
|
8
|
+
*/
|
|
9
|
+
const INFRACRAFT_DEFAULTS = [
|
|
10
|
+
"Adopt-or-create: re-running is safe — existing resources are adopted, missing ones created",
|
|
11
|
+
"Shared resources (Railway services/projects, Neon projects) have no-op deletes — destroy never removes them",
|
|
12
|
+
"Mark shared/production resources protect:true — pulumi destroy aborts on protected resources"
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Emits a delimited `<infracraft-hint>` block of reminders for AI coding agents
|
|
16
|
+
* operating this Pulumi stack — modeled on Vercel's `AGENTS.md` guidance: a
|
|
17
|
+
* delimited block, an agent-directed intro, then terse directive bullets.
|
|
18
|
+
*
|
|
19
|
+
* No-op for humans (no agent env var) unless `enabled` is forced. Call it once at
|
|
20
|
+
* the top of your Pulumi program; the infracraft defaults are always included and
|
|
21
|
+
* `project` lines are appended.
|
|
22
|
+
*
|
|
23
|
+
* @param options Project reminders, channel, and detection override.
|
|
24
|
+
* @returns Nothing; emits to the chosen channel as a side effect.
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* agentHint({
|
|
28
|
+
* project: [
|
|
29
|
+
* "production is protected — `unprotect <urn>` first for a deliberate change",
|
|
30
|
+
* "feature env = imports:[staging], zero config; pulumi destroy is safe",
|
|
31
|
+
* ],
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function agentHint(options = {}) {
|
|
36
|
+
if (!(options.enabled ?? (!!process.env.CLAUDECODE || !!process.env.AI_AGENT))) return;
|
|
37
|
+
const block = [
|
|
38
|
+
"<infracraft-hint>",
|
|
39
|
+
"Reminders for AI agents operating this Pulumi stack:",
|
|
40
|
+
...[...INFRACRAFT_DEFAULTS, ...options.project ?? []].map((line) => `- ${line}`),
|
|
41
|
+
"</infracraft-hint>"
|
|
42
|
+
].join("\n");
|
|
43
|
+
if (options.channel === "pulumi-log") pulumi.log.info(block);
|
|
44
|
+
else process.stderr.write(`${block}\n`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { agentHint };
|
|
49
|
+
//# sourceMappingURL=hint.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hint.mjs","names":[],"sources":["../../src/agents/hint.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\n\n/**\n * Generic infracraft reminders, prepended to every hint. These hold for any\n * infracraft stack regardless of the consuming project.\n */\nconst INFRACRAFT_DEFAULTS = [\n\t\"Adopt-or-create: re-running is safe — existing resources are adopted, missing ones created\",\n\t\"Shared resources (Railway services/projects, Neon projects) have no-op deletes — destroy never removes them\",\n\t\"Mark shared/production resources protect:true — pulumi destroy aborts on protected resources\",\n];\n\n/** Options for {@link agentHint}. */\nexport interface AgentHintOptions {\n\t/** Project-specific reminders appended after the infracraft defaults. */\n\tproject?: string[];\n\n\t/**\n\t * Force the hint on or off. Defaults to auto-detecting an AI coding agent via\n\t * the `CLAUDECODE` / `AI_AGENT` environment variables.\n\t */\n\tenabled?: boolean;\n\n\t/**\n\t * Where to write the hint. `\"stderr\"` (default) prints it prominently the\n\t * instant the program loads, before Pulumi's own output — modeled on how the\n\t * Vercel CLI surfaces agent guidance. `\"pulumi-log\"` routes it through\n\t * `pulumi.log.info` (lands in the Diagnostics section instead).\n\t */\n\tchannel?: \"stderr\" | \"pulumi-log\";\n}\n\n/**\n * Emits a delimited `<infracraft-hint>` block of reminders for AI coding agents\n * operating this Pulumi stack — modeled on Vercel's `AGENTS.md` guidance: a\n * delimited block, an agent-directed intro, then terse directive bullets.\n *\n * No-op for humans (no agent env var) unless `enabled` is forced. Call it once at\n * the top of your Pulumi program; the infracraft defaults are always included and\n * `project` lines are appended.\n *\n * @param options Project reminders, channel, and detection override.\n * @returns Nothing; emits to the chosen channel as a side effect.\n * @example\n * ```typescript\n * agentHint({\n * project: [\n * \"production is protected — `unprotect <urn>` first for a deliberate change\",\n * \"feature env = imports:[staging], zero config; pulumi destroy is safe\",\n * ],\n * });\n * ```\n */\nexport function agentHint(options: AgentHintOptions = {}): void {\n\tconst enabled =\n\t\toptions.enabled ?? (!!process.env.CLAUDECODE || !!process.env.AI_AGENT);\n\n\tif (!enabled) {\n\t\treturn;\n\t}\n\n\tconst lines = [...INFRACRAFT_DEFAULTS, ...(options.project ?? [])];\n\n\tconst block = [\n\t\t\"<infracraft-hint>\",\n\t\t\"Reminders for AI agents operating this Pulumi stack:\",\n\t\t...lines.map((line) => `- ${line}`),\n\t\t\"</infracraft-hint>\",\n\t].join(\"\\n\");\n\n\tif (options.channel === \"pulumi-log\") {\n\t\tpulumi.log.info(block);\n\t} else {\n\t\tprocess.stderr.write(`${block}\\n`);\n\t}\n}\n"],"mappings":";;;;;;;;AAMA,MAAM,sBAAsB;CAC3B;CACA;CACA;AACD;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,UAAU,UAA4B,CAAC,GAAS;CAI/D,IAAI,EAFH,QAAQ,YAAY,CAAC,CAAC,QAAQ,IAAI,cAAc,CAAC,CAAC,QAAQ,IAAI,YAG9D;CAKD,MAAM,QAAQ;EACb;EACA;EACA,GAAG,CALW,GAAG,qBAAqB,GAAI,QAAQ,WAAW,CAAC,CAKvD,EAAE,KAAK,SAAS,KAAK,MAAM;EAClC;CACD,EAAE,KAAK,IAAI;CAEX,IAAI,QAAQ,YAAY,cACvB,OAAO,IAAI,KAAK,KAAK;MAErB,QAAQ,OAAO,MAAM,GAAG,MAAM,GAAG;AAEnC"}
|
package/dist/neon/branch.cjs
CHANGED
|
@@ -23,7 +23,6 @@ var NeonBranchResourceProvider = class {
|
|
|
23
23
|
async create(inputs) {
|
|
24
24
|
const client = new require_neon_client.NeonClient(inputs.apiKey);
|
|
25
25
|
let branchId = await findBranchByName(client, inputs.projectId, inputs.name);
|
|
26
|
-
const wasAdopted = branchId !== void 0;
|
|
27
26
|
if (branchId) if (inputs.parentName) _pulumi_pulumi.log.warn(`Adopting existing Neon branch "${inputs.name}" — parentName "${inputs.parentName}" is ignored for adopted branches (existing lineage preserved).`);
|
|
28
27
|
else _pulumi_pulumi.log.info(`Adopting existing Neon branch "${inputs.name}" (${branchId})`);
|
|
29
28
|
else {
|
|
@@ -37,10 +36,7 @@ var NeonBranchResourceProvider = class {
|
|
|
37
36
|
}
|
|
38
37
|
return {
|
|
39
38
|
id: branchId,
|
|
40
|
-
outs: {
|
|
41
|
-
...inputs,
|
|
42
|
-
wasAdopted
|
|
43
|
-
}
|
|
39
|
+
outs: { ...inputs }
|
|
44
40
|
};
|
|
45
41
|
}
|
|
46
42
|
async read(id, props) {
|
|
@@ -54,14 +50,10 @@ var NeonBranchResourceProvider = class {
|
|
|
54
50
|
};
|
|
55
51
|
}
|
|
56
52
|
/**
|
|
57
|
-
* Deletes the branch
|
|
58
|
-
*
|
|
53
|
+
* Deletes the branch. Protection of shared/production branches is the consumer's
|
|
54
|
+
* responsibility via the `protect` resource option, not provider logic.
|
|
59
55
|
*/
|
|
60
56
|
async delete(id, props) {
|
|
61
|
-
if (props.wasAdopted !== false) {
|
|
62
|
-
_pulumi_pulumi.log.warn(`Neon branch "${props.name}" deletion skipped — adopted (not created by Pulumi)`);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
57
|
const client = new require_neon_client.NeonClient(props.apiKey);
|
|
66
58
|
try {
|
|
67
59
|
await client.delete(`/projects/${props.projectId}/branches/${id}`);
|
package/dist/neon/branch.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.cjs","names":["NeonClient","pulumi"],"sources":["../../src/neon/branch.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport { NeonClient } from \"./client\";\nimport type { NeonProject } from \"./project\";\nimport type { NeonProvider } from \"./provider\";\n\n/** Resolved inputs for the Neon branch dynamic provider. */\nexport interface NeonBranchInputs {\n\t/** Neon API key. */\n\tapiKey: string;\n\n\t/** Neon project ID (e.g. `\"quiet-forest-69719462\"`). */\n\tprojectId: string;\n\n\t/** Branch display name (e.g. `\"production\"`, `\"development\"`). */\n\tname: string;\n\n\t/**\n\t * Parent branch NAME. Resolved to `parent_id` inside `create()` via\n\t * `findBranchByName`. Omit for project-root branches.\n\t */\n\tparentName?: string;\n}\n\n/** Persisted state for the Neon branch. */\ninterface NeonBranchOutputs extends NeonBranchInputs {\n\t/**\n\t * Whether this branch already existed and was adopted (vs. created by us).\n\t * `delete()` only removes branches we created. Absent on state written before\n\t * this field existed, which is treated as adopted (the safe, non-destructive\n\t * default) so a feature env's destroy never deletes the adopted production branch.\n\t */\n\twasAdopted?: boolean;\n}\n\n/** Neon API response for a branch. */\ninterface BranchResponse {\n\tbranch: {\n\t\tid: string;\n\t\tname: string;\n\t\tproject_id: string;\n\t};\n}\n\n/** Neon API response for branch creation. */\ninterface BranchCreateResponse {\n\tbranch: {\n\t\tid: string;\n\t\tname: string;\n\t\tproject_id: string;\n\t};\n}\n\n/** Neon API response for listing branches. */\ninterface BranchListResponse {\n\tbranches: Array<{\n\t\tid: string;\n\t\tname: string;\n\t}>;\n}\n\n/**\n * Finds an existing Neon branch by name within a project.\n */\nasync function findBranchByName(\n\tclient: NeonClient,\n\tprojectId: string,\n\tname: string,\n): Promise<string | undefined> {\n\tconst result = await client.get<BranchListResponse>(\n\t\t`/projects/${projectId}/branches`,\n\t);\n\n\tconst match = result.branches.find((b) => b.name === name);\n\n\treturn match?.id;\n}\n\n/**\n * Dynamic provider implementing CRUD for Neon branches.\n *\n * Uses adopt-or-create on `create()`: finds an existing branch by name\n * before creating a new one. When `parentName` is supplied, resolves it\n * to a `parent_id` and includes it in the POST body.\n */\n/** @internal Exported only for unit testing; not part of the public API surface. */\nexport class NeonBranchResourceProvider\n\timplements pulumi.dynamic.ResourceProvider\n{\n\tasync create(inputs: NeonBranchInputs): Promise<pulumi.dynamic.CreateResult> {\n\t\tconst client = new NeonClient(inputs.apiKey);\n\n\t\tlet branchId = await findBranchByName(\n\t\t\tclient,\n\t\t\tinputs.projectId,\n\t\t\tinputs.name,\n\t\t);\n\n\t\tconst wasAdopted = branchId !== undefined;\n\n\t\tif (branchId) {\n\t\t\tif (inputs.parentName) {\n\t\t\t\tpulumi.log.warn(\n\t\t\t\t\t`Adopting existing Neon branch \"${inputs.name}\" — parentName \"${inputs.parentName}\" is ignored for adopted branches (existing lineage preserved).`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tpulumi.log.info(\n\t\t\t\t\t`Adopting existing Neon branch \"${inputs.name}\" (${branchId})`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tconst body: { branch: { name: string; parent_id?: string } } = {\n\t\t\t\tbranch: { name: inputs.name },\n\t\t\t};\n\n\t\t\tif (inputs.parentName) {\n\t\t\t\tconst parentId = await findBranchByName(\n\t\t\t\t\tclient,\n\t\t\t\t\tinputs.projectId,\n\t\t\t\t\tinputs.parentName,\n\t\t\t\t);\n\n\t\t\t\tif (!parentId) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Neon parent branch \"${inputs.parentName}\" not found in project ${inputs.projectId}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tbody.branch.parent_id = parentId;\n\t\t\t}\n\n\t\t\tconst result = await client.post<BranchCreateResponse>(\n\t\t\t\t`/projects/${inputs.projectId}/branches`,\n\t\t\t\tbody,\n\t\t\t);\n\n\t\t\tbranchId = result.branch.id;\n\t\t}\n\n\t\treturn { id: branchId, outs: { ...inputs, wasAdopted } };\n\t}\n\n\tasync read(\n\t\tid: string,\n\t\tprops: NeonBranchOutputs,\n\t): Promise<pulumi.dynamic.ReadResult> {\n\t\tconst client = new NeonClient(props.apiKey);\n\n\t\tconst result = await client.get<BranchResponse>(\n\t\t\t`/projects/${props.projectId}/branches/${id}`,\n\t\t);\n\n\t\t// parentName is preserved from prior state (props): the Neon API does not expose\n\t\t// a branch's parent on GET /branches/:id, so it cannot be re-derived here.\n\t\treturn {\n\t\t\tid: result.branch.id,\n\t\t\tprops: { ...props, name: result.branch.name },\n\t\t};\n\t}\n\n\t/**\n\t * Deletes the branch only if we created it. Adopted branches (and state written\n\t * before `wasAdopted` existed) are left untouched.\n\t */\n\tasync delete(id: string, props: NeonBranchOutputs): Promise<void> {\n\t\tif (props.wasAdopted !== false) {\n\t\t\tpulumi.log.warn(\n\t\t\t\t`Neon branch \"${props.name}\" deletion skipped — adopted (not created by Pulumi)`,\n\t\t\t);\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst client = new NeonClient(props.apiKey);\n\n\t\ttry {\n\t\t\tawait client.delete(`/projects/${props.projectId}/branches/${id}`);\n\t\t} catch {\n\t\t\tpulumi.log.warn(`Failed to delete Neon branch (may already be deleted)`);\n\t\t}\n\t}\n\n\tasync diff(\n\t\t_id: string,\n\t\tolds: NeonBranchOutputs,\n\t\tnews: NeonBranchInputs,\n\t): Promise<pulumi.dynamic.DiffResult> {\n\t\tconst replaces: string[] = [];\n\n\t\tif (olds.projectId !== news.projectId) {\n\t\t\treplaces.push(\"projectId\");\n\t\t}\n\n\t\tif (olds.parentName !== news.parentName) {\n\t\t\treplaces.push(\"parentName\");\n\t\t}\n\n\t\treturn {\n\t\t\tchanges: replaces.length > 0 || olds.name !== news.name,\n\t\t\treplaces,\n\t\t\tdeleteBeforeReplace: true,\n\t\t};\n\t}\n}\n\n/** Internal dynamic resource — not part of the public API. */\nclass NeonBranchResource extends pulumi.dynamic.Resource {\n\tpublic declare readonly branchId: pulumi.Output<string>;\n\n\tconstructor(\n\t\tname: string,\n\t\targs: {\n\t\t\tapiKey: pulumi.Input<string>;\n\t\t\tprojectId: pulumi.Input<string>;\n\t\t\tname: pulumi.Input<string>;\n\t\t\t/** Name of the parent branch; omit for project-root branches. */\n\t\t\tparentName?: pulumi.Input<string>;\n\t\t},\n\t\topts?: pulumi.CustomResourceOptions,\n\t) {\n\t\tsuper(new NeonBranchResourceProvider(), name, { ...args }, opts);\n\t}\n}\n\n/** Options type for NeonBranch — replaces Pulumi's native `provider` field. */\ntype NeonBranchOptions = Omit<pulumi.ComponentResourceOptions, \"provider\"> & {\n\t/** Neon authentication context. */\n\tprovider: NeonProvider;\n\n\t/** Neon project context. */\n\tproject: NeonProject;\n};\n\n/** Args for NeonBranch. */\nexport interface NeonBranchArgs {\n\t/** Branch display name. */\n\tname: pulumi.Input<string>;\n\n\t/**\n\t * Name of the parent branch to branch from (copy-on-write). Omit to\n\t * branch from the project root (Neon default branch).\n\t */\n\tparent?: pulumi.Input<string>;\n}\n\n/**\n * Manages a Neon branch with adopt-or-create semantics.\n *\n * @example\n * ```typescript\n * // Root branch (Neon default parent)\n * const production = new NeonBranch(\"production\", {\n * name: \"production\",\n * }, { provider, project });\n *\n * // Copy-on-write branch from production\n * const staging = new NeonBranch(\"staging\", {\n * name: \"staging\",\n * parent: \"production\",\n * }, { provider, project });\n * ```\n */\nexport class NeonBranch extends pulumi.ComponentResource {\n\t/** Neon branch ID. */\n\tpublic readonly id: pulumi.Output<string>;\n\n\tconstructor(name: string, args: NeonBranchArgs, opts: NeonBranchOptions) {\n\t\tconst { provider, project, ...pulumiOpts } = opts;\n\n\t\tsuper(\"infracraft:neon:Branch\", name, {}, pulumiOpts);\n\n\t\tconst resource = new NeonBranchResource(\n\t\t\t`${name}-resource`,\n\t\t\t{\n\t\t\t\tapiKey: provider.apiKey,\n\t\t\t\tprojectId: project.id,\n\t\t\t\tname: args.name,\n\t\t\t\tparentName: args.parent,\n\t\t\t},\n\t\t\t{ parent: this },\n\t\t);\n\n\t\tthis.id = resource.id;\n\n\t\tthis.registerOutputs({ id: this.id });\n\t}\n}\n"],"mappings":";;;;;;;;;;AA+DA,eAAe,iBACd,QACA,WACA,MAC8B;CAO9B,QAFc,MAJO,OAAO,IAC3B,aAAa,UAAU,UACxB,GAEqB,SAAS,MAAM,MAAM,EAAE,SAAS,IAE1C,GAAG;AACf;;;;;;;;;AAUA,IAAa,6BAAb,MAEA;CACC,MAAM,OAAO,QAAgE;EAC5E,MAAM,SAAS,IAAIA,+BAAW,OAAO,MAAM;EAE3C,IAAI,WAAW,MAAM,iBACpB,QACA,OAAO,WACP,OAAO,IACR;EAEA,MAAM,aAAa,aAAa;EAEhC,IAAI,UACH,IAAI,OAAO,YACV,eAAO,IAAI,KACV,kCAAkC,OAAO,KAAK,kBAAkB,OAAO,WAAW,gEACnF;OAEA,eAAO,IAAI,KACV,kCAAkC,OAAO,KAAK,KAAK,SAAS,EAC7D;OAEK;GACN,MAAM,OAAyD,EAC9D,QAAQ,EAAE,MAAM,OAAO,KAAK,EAC7B;GAEA,IAAI,OAAO,YAAY;IACtB,MAAM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GAAG,IAAI;CAChE;AACD;;;;;;;;;;;;;;;;;;AAwCA,IAAa,aAAb,cAAgCA,eAAO,kBAAkB;CAIxD,YAAY,MAAc,MAAsB,MAAyB;EACxE,MAAM,EAAE,UAAU,SAAS,GAAG,eAAe;EAE7C,MAAM,0BAA0B,MAAM,CAAC,GAAG,UAAU;EAEpD,MAAM,WAAW,IAAI,mBACpB,GAAG,KAAK,YACR;GACC,QAAQ,SAAS;GACjB,WAAW,QAAQ;GACnB,MAAM,KAAK;GACX,YAAY,KAAK;EAClB,GACA,EAAE,QAAQ,KAAK,CAChB;EAEA,KAAK,KAAK,SAAS;EAEnB,KAAK,gBAAgB,EAAE,IAAI,KAAK,GAAG,CAAC;CACrC;AACD"}
|
|
1
|
+
{"version":3,"file":"branch.cjs","names":["NeonClient","pulumi"],"sources":["../../src/neon/branch.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport { NeonClient } from \"./client\";\nimport type { NeonProject } from \"./project\";\nimport type { NeonProvider } from \"./provider\";\n\n/** Resolved inputs for the Neon branch dynamic provider. */\nexport interface NeonBranchInputs {\n\t/** Neon API key. */\n\tapiKey: string;\n\n\t/** Neon project ID (e.g. `\"quiet-forest-69719462\"`). */\n\tprojectId: string;\n\n\t/** Branch display name (e.g. `\"production\"`, `\"development\"`). */\n\tname: string;\n\n\t/**\n\t * Parent branch NAME. Resolved to `parent_id` inside `create()` via\n\t * `findBranchByName`. Omit for project-root branches.\n\t */\n\tparentName?: string;\n}\n\n/** Persisted state for the Neon branch. */\ninterface NeonBranchOutputs extends NeonBranchInputs {}\n\n/** Neon API response for a branch. */\ninterface BranchResponse {\n\tbranch: {\n\t\tid: string;\n\t\tname: string;\n\t\tproject_id: string;\n\t};\n}\n\n/** Neon API response for branch creation. */\ninterface BranchCreateResponse {\n\tbranch: {\n\t\tid: string;\n\t\tname: string;\n\t\tproject_id: string;\n\t};\n}\n\n/** Neon API response for listing branches. */\ninterface BranchListResponse {\n\tbranches: Array<{\n\t\tid: string;\n\t\tname: string;\n\t}>;\n}\n\n/**\n * Finds an existing Neon branch by name within a project.\n */\nasync function findBranchByName(\n\tclient: NeonClient,\n\tprojectId: string,\n\tname: string,\n): Promise<string | undefined> {\n\tconst result = await client.get<BranchListResponse>(\n\t\t`/projects/${projectId}/branches`,\n\t);\n\n\tconst match = result.branches.find((b) => b.name === name);\n\n\treturn match?.id;\n}\n\n/**\n * Dynamic provider implementing CRUD for Neon branches.\n *\n * Uses adopt-or-create on `create()`: finds an existing branch by name\n * before creating a new one. When `parentName` is supplied, resolves it\n * to a `parent_id` and includes it in the POST body.\n */\n/** @internal Exported only for unit testing; not part of the public API surface. */\nexport class NeonBranchResourceProvider\n\timplements pulumi.dynamic.ResourceProvider\n{\n\tasync create(inputs: NeonBranchInputs): Promise<pulumi.dynamic.CreateResult> {\n\t\tconst client = new NeonClient(inputs.apiKey);\n\n\t\tlet branchId = await findBranchByName(\n\t\t\tclient,\n\t\t\tinputs.projectId,\n\t\t\tinputs.name,\n\t\t);\n\n\t\tif (branchId) {\n\t\t\tif (inputs.parentName) {\n\t\t\t\tpulumi.log.warn(\n\t\t\t\t\t`Adopting existing Neon branch \"${inputs.name}\" — parentName \"${inputs.parentName}\" is ignored for adopted branches (existing lineage preserved).`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tpulumi.log.info(\n\t\t\t\t\t`Adopting existing Neon branch \"${inputs.name}\" (${branchId})`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tconst body: { branch: { name: string; parent_id?: string } } = {\n\t\t\t\tbranch: { name: inputs.name },\n\t\t\t};\n\n\t\t\tif (inputs.parentName) {\n\t\t\t\tconst parentId = await findBranchByName(\n\t\t\t\t\tclient,\n\t\t\t\t\tinputs.projectId,\n\t\t\t\t\tinputs.parentName,\n\t\t\t\t);\n\n\t\t\t\tif (!parentId) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Neon parent branch \"${inputs.parentName}\" not found in project ${inputs.projectId}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tbody.branch.parent_id = parentId;\n\t\t\t}\n\n\t\t\tconst result = await client.post<BranchCreateResponse>(\n\t\t\t\t`/projects/${inputs.projectId}/branches`,\n\t\t\t\tbody,\n\t\t\t);\n\n\t\t\tbranchId = result.branch.id;\n\t\t}\n\n\t\treturn { id: branchId, outs: { ...inputs } };\n\t}\n\n\tasync read(\n\t\tid: string,\n\t\tprops: NeonBranchOutputs,\n\t): Promise<pulumi.dynamic.ReadResult> {\n\t\tconst client = new NeonClient(props.apiKey);\n\n\t\tconst result = await client.get<BranchResponse>(\n\t\t\t`/projects/${props.projectId}/branches/${id}`,\n\t\t);\n\n\t\t// parentName is preserved from prior state (props): the Neon API does not expose\n\t\t// a branch's parent on GET /branches/:id, so it cannot be re-derived here.\n\t\treturn {\n\t\t\tid: result.branch.id,\n\t\t\tprops: { ...props, name: result.branch.name },\n\t\t};\n\t}\n\n\t/**\n\t * Deletes the branch. Protection of shared/production branches is the consumer's\n\t * responsibility via the `protect` resource option, not provider logic.\n\t */\n\tasync delete(id: string, props: NeonBranchOutputs): Promise<void> {\n\t\tconst client = new NeonClient(props.apiKey);\n\n\t\ttry {\n\t\t\tawait client.delete(`/projects/${props.projectId}/branches/${id}`);\n\t\t} catch {\n\t\t\tpulumi.log.warn(`Failed to delete Neon branch (may already be deleted)`);\n\t\t}\n\t}\n\n\tasync diff(\n\t\t_id: string,\n\t\tolds: NeonBranchOutputs,\n\t\tnews: NeonBranchInputs,\n\t): Promise<pulumi.dynamic.DiffResult> {\n\t\tconst replaces: string[] = [];\n\n\t\tif (olds.projectId !== news.projectId) {\n\t\t\treplaces.push(\"projectId\");\n\t\t}\n\n\t\tif (olds.parentName !== news.parentName) {\n\t\t\treplaces.push(\"parentName\");\n\t\t}\n\n\t\treturn {\n\t\t\tchanges: replaces.length > 0 || olds.name !== news.name,\n\t\t\treplaces,\n\t\t\tdeleteBeforeReplace: true,\n\t\t};\n\t}\n}\n\n/** Internal dynamic resource — not part of the public API. */\nclass NeonBranchResource extends pulumi.dynamic.Resource {\n\tpublic declare readonly branchId: pulumi.Output<string>;\n\n\tconstructor(\n\t\tname: string,\n\t\targs: {\n\t\t\tapiKey: pulumi.Input<string>;\n\t\t\tprojectId: pulumi.Input<string>;\n\t\t\tname: pulumi.Input<string>;\n\t\t\t/** Name of the parent branch; omit for project-root branches. */\n\t\t\tparentName?: pulumi.Input<string>;\n\t\t},\n\t\topts?: pulumi.CustomResourceOptions,\n\t) {\n\t\tsuper(new NeonBranchResourceProvider(), name, { ...args }, opts);\n\t}\n}\n\n/** Options type for NeonBranch — replaces Pulumi's native `provider` field. */\ntype NeonBranchOptions = Omit<pulumi.ComponentResourceOptions, \"provider\"> & {\n\t/** Neon authentication context. */\n\tprovider: NeonProvider;\n\n\t/** Neon project context. */\n\tproject: NeonProject;\n};\n\n/** Args for NeonBranch. */\nexport interface NeonBranchArgs {\n\t/** Branch display name. */\n\tname: pulumi.Input<string>;\n\n\t/**\n\t * Name of the parent branch to branch from (copy-on-write). Omit to\n\t * branch from the project root (Neon default branch).\n\t */\n\tparent?: pulumi.Input<string>;\n}\n\n/**\n * Manages a Neon branch with adopt-or-create semantics.\n *\n * @example\n * ```typescript\n * // Root branch (Neon default parent)\n * const production = new NeonBranch(\"production\", {\n * name: \"production\",\n * }, { provider, project });\n *\n * // Copy-on-write branch from production\n * const staging = new NeonBranch(\"staging\", {\n * name: \"staging\",\n * parent: \"production\",\n * }, { provider, project });\n * ```\n */\nexport class NeonBranch extends pulumi.ComponentResource {\n\t/** Neon branch ID. */\n\tpublic readonly id: pulumi.Output<string>;\n\n\tconstructor(name: string, args: NeonBranchArgs, opts: NeonBranchOptions) {\n\t\tconst { provider, project, ...pulumiOpts } = opts;\n\n\t\tsuper(\"infracraft:neon:Branch\", name, {}, pulumiOpts);\n\n\t\tconst resource = new NeonBranchResource(\n\t\t\t`${name}-resource`,\n\t\t\t{\n\t\t\t\tapiKey: provider.apiKey,\n\t\t\t\tprojectId: project.id,\n\t\t\t\tname: args.name,\n\t\t\t\tparentName: args.parent,\n\t\t\t},\n\t\t\t{ parent: this },\n\t\t);\n\n\t\tthis.id = resource.id;\n\n\t\tthis.registerOutputs({ id: this.id });\n\t}\n}\n"],"mappings":";;;;;;;;;;AAuDA,eAAe,iBACd,QACA,WACA,MAC8B;CAO9B,QAFc,MAJO,OAAO,IAC3B,aAAa,UAAU,UACxB,GAEqB,SAAS,MAAM,MAAM,EAAE,SAAS,IAE1C,GAAG;AACf;;;;;;;;;AAUA,IAAa,6BAAb,MAEA;CACC,MAAM,OAAO,QAAgE;EAC5E,MAAM,SAAS,IAAIA,+BAAW,OAAO,MAAM;EAE3C,IAAI,WAAW,MAAM,iBACpB,QACA,OAAO,WACP,OAAO,IACR;EAEA,IAAI,UACH,IAAI,OAAO,YACV,eAAO,IAAI,KACV,kCAAkC,OAAO,KAAK,kBAAkB,OAAO,WAAW,gEACnF;OAEA,eAAO,IAAI,KACV,kCAAkC,OAAO,KAAK,KAAK,SAAS,EAC7D;OAEK;GACN,MAAM,OAAyD,EAC9D,QAAQ,EAAE,MAAM,OAAO,KAAK,EAC7B;GAEA,IAAI,OAAO,YAAY;IACtB,MAAM,WAAW,MAAM,iBACtB,QACA,OAAO,WACP,OAAO,UACR;IAEA,IAAI,CAAC,UACJ,MAAM,IAAI,MACT,uBAAuB,OAAO,WAAW,yBAAyB,OAAO,WAC1E;IAGD,KAAK,OAAO,YAAY;GACzB;GAOA,YAAW,MALU,OAAO,KAC3B,aAAa,OAAO,UAAU,YAC9B,IACD,GAEkB,OAAO;EAC1B;EAEA,OAAO;GAAE,IAAI;GAAU,MAAM,EAAE,GAAG,OAAO;EAAE;CAC5C;CAEA,MAAM,KACL,IACA,OACqC;EAGrC,MAAM,SAAS,MAAM,IAFFA,+BAAW,MAAM,MAEV,EAAE,IAC3B,aAAa,MAAM,UAAU,YAAY,IAC1C;EAIA,OAAO;GACN,IAAI,OAAO,OAAO;GAClB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** Persisted state for the Neon branch. */
|
|
22
|
-
interface NeonBranchOutputs extends NeonBranchInputs {
|
|
23
|
-
/**
|
|
24
|
-
* Whether this branch already existed and was adopted (vs. created by us).
|
|
25
|
-
* `delete()` only removes branches we created. Absent on state written before
|
|
26
|
-
* this field existed, which is treated as adopted (the safe, non-destructive
|
|
27
|
-
* default) so a feature env's destroy never deletes the adopted production branch.
|
|
28
|
-
*/
|
|
29
|
-
wasAdopted?: boolean;
|
|
30
|
-
}
|
|
22
|
+
interface NeonBranchOutputs extends NeonBranchInputs {}
|
|
31
23
|
/**
|
|
32
24
|
* Dynamic provider implementing CRUD for Neon branches.
|
|
33
25
|
*
|
|
@@ -40,8 +32,8 @@ declare class NeonBranchResourceProvider implements pulumi.dynamic.ResourceProvi
|
|
|
40
32
|
create(inputs: NeonBranchInputs): Promise<pulumi.dynamic.CreateResult>;
|
|
41
33
|
read(id: string, props: NeonBranchOutputs): Promise<pulumi.dynamic.ReadResult>;
|
|
42
34
|
/**
|
|
43
|
-
* Deletes the branch
|
|
44
|
-
*
|
|
35
|
+
* Deletes the branch. Protection of shared/production branches is the consumer's
|
|
36
|
+
* responsibility via the `protect` resource option, not provider logic.
|
|
45
37
|
*/
|
|
46
38
|
delete(id: string, props: NeonBranchOutputs): Promise<void>;
|
|
47
39
|
diff(_id: string, olds: NeonBranchOutputs, news: NeonBranchInputs): Promise<pulumi.dynamic.DiffResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.d.cts","names":[],"sources":["../../src/neon/branch.ts"],"mappings":";;;;;;;UAMiB,gBAAA;;EAEhB,MAAA;EAFgC;EAKhC,SAAA;EALgC;EAQhC,IAAA;EAHA;;;;EASA,UAAA;AAAA;;UAIS,iBAAA,SAA0B,gBAAgB;
|
|
1
|
+
{"version":3,"file":"branch.d.cts","names":[],"sources":["../../src/neon/branch.ts"],"mappings":";;;;;;;UAMiB,gBAAA;;EAEhB,MAAA;EAFgC;EAKhC,SAAA;EALgC;EAQhC,IAAA;EAHA;;;;EASA,UAAA;AAAA;;UAIS,iBAAA,SAA0B,gBAAgB;AAAA;AAqDpD;;;;;;;cAAa,0BAAA,YACD,MAAA,CAAO,OAAA,CAAQ,gBAAA;EAEpB,MAAA,CAAO,MAAA,EAAQ,gBAAA,GAAmB,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,YAAA;EAmDzD,IAAA,CACL,EAAA,UACA,KAAA,EAAO,iBAAA,GACL,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,UAAA;EAmB0B;;;;EAA9C,MAAA,CAAO,EAAA,UAAY,KAAA,EAAO,iBAAA,GAAoB,OAAA;EAU9C,IAAA,CACL,GAAA,UACA,IAAA,EAAM,iBAAA,EACN,IAAA,EAAM,gBAAA,GACJ,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,UAAA;AAAA;;KAuCtB,iBAAA,GAAoB,IAAA,CAAK,MAAA,CAAO,wBAAA;EAhIlB,mCAkIlB,QAAA,EAAU,YAAA,EAhIJ;EAmIN,OAAA,EAAS,WAAA;AAAA;;UAIO,cAAA;EAvIuC;EAyIvD,IAAA,EAAM,MAAA,CAAO,KAAA;EAtFP;;;;EA4FN,MAAA,GAAS,MAAA,CAAO,KAAK;AAAA;;;;;;;;;;;;;;;;;;cAoBT,UAAA,SAAmB,MAAA,CAAO,iBAAA;EA5EF;EAAA,SA8EpB,EAAA,EAAI,MAAA,CAAO,MAAA;cAEf,IAAA,UAAc,IAAA,EAAM,cAAA,EAAgB,IAAA,EAAM,iBAAA;AAAA"}
|
package/dist/neon/branch.d.mts
CHANGED
|
@@ -19,15 +19,7 @@ interface NeonBranchInputs {
|
|
|
19
19
|
parentName?: string;
|
|
20
20
|
}
|
|
21
21
|
/** Persisted state for the Neon branch. */
|
|
22
|
-
interface NeonBranchOutputs extends NeonBranchInputs {
|
|
23
|
-
/**
|
|
24
|
-
* Whether this branch already existed and was adopted (vs. created by us).
|
|
25
|
-
* `delete()` only removes branches we created. Absent on state written before
|
|
26
|
-
* this field existed, which is treated as adopted (the safe, non-destructive
|
|
27
|
-
* default) so a feature env's destroy never deletes the adopted production branch.
|
|
28
|
-
*/
|
|
29
|
-
wasAdopted?: boolean;
|
|
30
|
-
}
|
|
22
|
+
interface NeonBranchOutputs extends NeonBranchInputs {}
|
|
31
23
|
/**
|
|
32
24
|
* Dynamic provider implementing CRUD for Neon branches.
|
|
33
25
|
*
|
|
@@ -40,8 +32,8 @@ declare class NeonBranchResourceProvider implements pulumi.dynamic.ResourceProvi
|
|
|
40
32
|
create(inputs: NeonBranchInputs): Promise<pulumi.dynamic.CreateResult>;
|
|
41
33
|
read(id: string, props: NeonBranchOutputs): Promise<pulumi.dynamic.ReadResult>;
|
|
42
34
|
/**
|
|
43
|
-
* Deletes the branch
|
|
44
|
-
*
|
|
35
|
+
* Deletes the branch. Protection of shared/production branches is the consumer's
|
|
36
|
+
* responsibility via the `protect` resource option, not provider logic.
|
|
45
37
|
*/
|
|
46
38
|
delete(id: string, props: NeonBranchOutputs): Promise<void>;
|
|
47
39
|
diff(_id: string, olds: NeonBranchOutputs, news: NeonBranchInputs): Promise<pulumi.dynamic.DiffResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.d.mts","names":[],"sources":["../../src/neon/branch.ts"],"mappings":";;;;;;;UAMiB,gBAAA;;EAEhB,MAAA;EAFgC;EAKhC,SAAA;EALgC;EAQhC,IAAA;EAHA;;;;EASA,UAAA;AAAA;;UAIS,iBAAA,SAA0B,gBAAgB;
|
|
1
|
+
{"version":3,"file":"branch.d.mts","names":[],"sources":["../../src/neon/branch.ts"],"mappings":";;;;;;;UAMiB,gBAAA;;EAEhB,MAAA;EAFgC;EAKhC,SAAA;EALgC;EAQhC,IAAA;EAHA;;;;EASA,UAAA;AAAA;;UAIS,iBAAA,SAA0B,gBAAgB;AAAA;AAqDpD;;;;;;;cAAa,0BAAA,YACD,MAAA,CAAO,OAAA,CAAQ,gBAAA;EAEpB,MAAA,CAAO,MAAA,EAAQ,gBAAA,GAAmB,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,YAAA;EAmDzD,IAAA,CACL,EAAA,UACA,KAAA,EAAO,iBAAA,GACL,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,UAAA;EAmB0B;;;;EAA9C,MAAA,CAAO,EAAA,UAAY,KAAA,EAAO,iBAAA,GAAoB,OAAA;EAU9C,IAAA,CACL,GAAA,UACA,IAAA,EAAM,iBAAA,EACN,IAAA,EAAM,gBAAA,GACJ,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,UAAA;AAAA;;KAuCtB,iBAAA,GAAoB,IAAA,CAAK,MAAA,CAAO,wBAAA;EAhIlB,mCAkIlB,QAAA,EAAU,YAAA,EAhIJ;EAmIN,OAAA,EAAS,WAAA;AAAA;;UAIO,cAAA;EAvIuC;EAyIvD,IAAA,EAAM,MAAA,CAAO,KAAA;EAtFP;;;;EA4FN,MAAA,GAAS,MAAA,CAAO,KAAK;AAAA;;;;;;;;;;;;;;;;;;cAoBT,UAAA,SAAmB,MAAA,CAAO,iBAAA;EA5EF;EAAA,SA8EpB,EAAA,EAAI,MAAA,CAAO,MAAA;cAEf,IAAA,UAAc,IAAA,EAAM,cAAA,EAAgB,IAAA,EAAM,iBAAA;AAAA"}
|
package/dist/neon/branch.mjs
CHANGED
|
@@ -21,7 +21,6 @@ var NeonBranchResourceProvider = class {
|
|
|
21
21
|
async create(inputs) {
|
|
22
22
|
const client = new NeonClient(inputs.apiKey);
|
|
23
23
|
let branchId = await findBranchByName(client, inputs.projectId, inputs.name);
|
|
24
|
-
const wasAdopted = branchId !== void 0;
|
|
25
24
|
if (branchId) if (inputs.parentName) pulumi.log.warn(`Adopting existing Neon branch "${inputs.name}" — parentName "${inputs.parentName}" is ignored for adopted branches (existing lineage preserved).`);
|
|
26
25
|
else pulumi.log.info(`Adopting existing Neon branch "${inputs.name}" (${branchId})`);
|
|
27
26
|
else {
|
|
@@ -35,10 +34,7 @@ var NeonBranchResourceProvider = class {
|
|
|
35
34
|
}
|
|
36
35
|
return {
|
|
37
36
|
id: branchId,
|
|
38
|
-
outs: {
|
|
39
|
-
...inputs,
|
|
40
|
-
wasAdopted
|
|
41
|
-
}
|
|
37
|
+
outs: { ...inputs }
|
|
42
38
|
};
|
|
43
39
|
}
|
|
44
40
|
async read(id, props) {
|
|
@@ -52,14 +48,10 @@ var NeonBranchResourceProvider = class {
|
|
|
52
48
|
};
|
|
53
49
|
}
|
|
54
50
|
/**
|
|
55
|
-
* Deletes the branch
|
|
56
|
-
*
|
|
51
|
+
* Deletes the branch. Protection of shared/production branches is the consumer's
|
|
52
|
+
* responsibility via the `protect` resource option, not provider logic.
|
|
57
53
|
*/
|
|
58
54
|
async delete(id, props) {
|
|
59
|
-
if (props.wasAdopted !== false) {
|
|
60
|
-
pulumi.log.warn(`Neon branch "${props.name}" deletion skipped — adopted (not created by Pulumi)`);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
55
|
const client = new NeonClient(props.apiKey);
|
|
64
56
|
try {
|
|
65
57
|
await client.delete(`/projects/${props.projectId}/branches/${id}`);
|
package/dist/neon/branch.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.mjs","names":[],"sources":["../../src/neon/branch.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport { NeonClient } from \"./client\";\nimport type { NeonProject } from \"./project\";\nimport type { NeonProvider } from \"./provider\";\n\n/** Resolved inputs for the Neon branch dynamic provider. */\nexport interface NeonBranchInputs {\n\t/** Neon API key. */\n\tapiKey: string;\n\n\t/** Neon project ID (e.g. `\"quiet-forest-69719462\"`). */\n\tprojectId: string;\n\n\t/** Branch display name (e.g. `\"production\"`, `\"development\"`). */\n\tname: string;\n\n\t/**\n\t * Parent branch NAME. Resolved to `parent_id` inside `create()` via\n\t * `findBranchByName`. Omit for project-root branches.\n\t */\n\tparentName?: string;\n}\n\n/** Persisted state for the Neon branch. */\ninterface NeonBranchOutputs extends NeonBranchInputs {\n\t/**\n\t * Whether this branch already existed and was adopted (vs. created by us).\n\t * `delete()` only removes branches we created. Absent on state written before\n\t * this field existed, which is treated as adopted (the safe, non-destructive\n\t * default) so a feature env's destroy never deletes the adopted production branch.\n\t */\n\twasAdopted?: boolean;\n}\n\n/** Neon API response for a branch. */\ninterface BranchResponse {\n\tbranch: {\n\t\tid: string;\n\t\tname: string;\n\t\tproject_id: string;\n\t};\n}\n\n/** Neon API response for branch creation. */\ninterface BranchCreateResponse {\n\tbranch: {\n\t\tid: string;\n\t\tname: string;\n\t\tproject_id: string;\n\t};\n}\n\n/** Neon API response for listing branches. */\ninterface BranchListResponse {\n\tbranches: Array<{\n\t\tid: string;\n\t\tname: string;\n\t}>;\n}\n\n/**\n * Finds an existing Neon branch by name within a project.\n */\nasync function findBranchByName(\n\tclient: NeonClient,\n\tprojectId: string,\n\tname: string,\n): Promise<string | undefined> {\n\tconst result = await client.get<BranchListResponse>(\n\t\t`/projects/${projectId}/branches`,\n\t);\n\n\tconst match = result.branches.find((b) => b.name === name);\n\n\treturn match?.id;\n}\n\n/**\n * Dynamic provider implementing CRUD for Neon branches.\n *\n * Uses adopt-or-create on `create()`: finds an existing branch by name\n * before creating a new one. When `parentName` is supplied, resolves it\n * to a `parent_id` and includes it in the POST body.\n */\n/** @internal Exported only for unit testing; not part of the public API surface. */\nexport class NeonBranchResourceProvider\n\timplements pulumi.dynamic.ResourceProvider\n{\n\tasync create(inputs: NeonBranchInputs): Promise<pulumi.dynamic.CreateResult> {\n\t\tconst client = new NeonClient(inputs.apiKey);\n\n\t\tlet branchId = await findBranchByName(\n\t\t\tclient,\n\t\t\tinputs.projectId,\n\t\t\tinputs.name,\n\t\t);\n\n\t\tconst wasAdopted = branchId !== undefined;\n\n\t\tif (branchId) {\n\t\t\tif (inputs.parentName) {\n\t\t\t\tpulumi.log.warn(\n\t\t\t\t\t`Adopting existing Neon branch \"${inputs.name}\" — parentName \"${inputs.parentName}\" is ignored for adopted branches (existing lineage preserved).`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tpulumi.log.info(\n\t\t\t\t\t`Adopting existing Neon branch \"${inputs.name}\" (${branchId})`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tconst body: { branch: { name: string; parent_id?: string } } = {\n\t\t\t\tbranch: { name: inputs.name },\n\t\t\t};\n\n\t\t\tif (inputs.parentName) {\n\t\t\t\tconst parentId = await findBranchByName(\n\t\t\t\t\tclient,\n\t\t\t\t\tinputs.projectId,\n\t\t\t\t\tinputs.parentName,\n\t\t\t\t);\n\n\t\t\t\tif (!parentId) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Neon parent branch \"${inputs.parentName}\" not found in project ${inputs.projectId}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tbody.branch.parent_id = parentId;\n\t\t\t}\n\n\t\t\tconst result = await client.post<BranchCreateResponse>(\n\t\t\t\t`/projects/${inputs.projectId}/branches`,\n\t\t\t\tbody,\n\t\t\t);\n\n\t\t\tbranchId = result.branch.id;\n\t\t}\n\n\t\treturn { id: branchId, outs: { ...inputs, wasAdopted } };\n\t}\n\n\tasync read(\n\t\tid: string,\n\t\tprops: NeonBranchOutputs,\n\t): Promise<pulumi.dynamic.ReadResult> {\n\t\tconst client = new NeonClient(props.apiKey);\n\n\t\tconst result = await client.get<BranchResponse>(\n\t\t\t`/projects/${props.projectId}/branches/${id}`,\n\t\t);\n\n\t\t// parentName is preserved from prior state (props): the Neon API does not expose\n\t\t// a branch's parent on GET /branches/:id, so it cannot be re-derived here.\n\t\treturn {\n\t\t\tid: result.branch.id,\n\t\t\tprops: { ...props, name: result.branch.name },\n\t\t};\n\t}\n\n\t/**\n\t * Deletes the branch only if we created it. Adopted branches (and state written\n\t * before `wasAdopted` existed) are left untouched.\n\t */\n\tasync delete(id: string, props: NeonBranchOutputs): Promise<void> {\n\t\tif (props.wasAdopted !== false) {\n\t\t\tpulumi.log.warn(\n\t\t\t\t`Neon branch \"${props.name}\" deletion skipped — adopted (not created by Pulumi)`,\n\t\t\t);\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst client = new NeonClient(props.apiKey);\n\n\t\ttry {\n\t\t\tawait client.delete(`/projects/${props.projectId}/branches/${id}`);\n\t\t} catch {\n\t\t\tpulumi.log.warn(`Failed to delete Neon branch (may already be deleted)`);\n\t\t}\n\t}\n\n\tasync diff(\n\t\t_id: string,\n\t\tolds: NeonBranchOutputs,\n\t\tnews: NeonBranchInputs,\n\t): Promise<pulumi.dynamic.DiffResult> {\n\t\tconst replaces: string[] = [];\n\n\t\tif (olds.projectId !== news.projectId) {\n\t\t\treplaces.push(\"projectId\");\n\t\t}\n\n\t\tif (olds.parentName !== news.parentName) {\n\t\t\treplaces.push(\"parentName\");\n\t\t}\n\n\t\treturn {\n\t\t\tchanges: replaces.length > 0 || olds.name !== news.name,\n\t\t\treplaces,\n\t\t\tdeleteBeforeReplace: true,\n\t\t};\n\t}\n}\n\n/** Internal dynamic resource — not part of the public API. */\nclass NeonBranchResource extends pulumi.dynamic.Resource {\n\tpublic declare readonly branchId: pulumi.Output<string>;\n\n\tconstructor(\n\t\tname: string,\n\t\targs: {\n\t\t\tapiKey: pulumi.Input<string>;\n\t\t\tprojectId: pulumi.Input<string>;\n\t\t\tname: pulumi.Input<string>;\n\t\t\t/** Name of the parent branch; omit for project-root branches. */\n\t\t\tparentName?: pulumi.Input<string>;\n\t\t},\n\t\topts?: pulumi.CustomResourceOptions,\n\t) {\n\t\tsuper(new NeonBranchResourceProvider(), name, { ...args }, opts);\n\t}\n}\n\n/** Options type for NeonBranch — replaces Pulumi's native `provider` field. */\ntype NeonBranchOptions = Omit<pulumi.ComponentResourceOptions, \"provider\"> & {\n\t/** Neon authentication context. */\n\tprovider: NeonProvider;\n\n\t/** Neon project context. */\n\tproject: NeonProject;\n};\n\n/** Args for NeonBranch. */\nexport interface NeonBranchArgs {\n\t/** Branch display name. */\n\tname: pulumi.Input<string>;\n\n\t/**\n\t * Name of the parent branch to branch from (copy-on-write). Omit to\n\t * branch from the project root (Neon default branch).\n\t */\n\tparent?: pulumi.Input<string>;\n}\n\n/**\n * Manages a Neon branch with adopt-or-create semantics.\n *\n * @example\n * ```typescript\n * // Root branch (Neon default parent)\n * const production = new NeonBranch(\"production\", {\n * name: \"production\",\n * }, { provider, project });\n *\n * // Copy-on-write branch from production\n * const staging = new NeonBranch(\"staging\", {\n * name: \"staging\",\n * parent: \"production\",\n * }, { provider, project });\n * ```\n */\nexport class NeonBranch extends pulumi.ComponentResource {\n\t/** Neon branch ID. */\n\tpublic readonly id: pulumi.Output<string>;\n\n\tconstructor(name: string, args: NeonBranchArgs, opts: NeonBranchOptions) {\n\t\tconst { provider, project, ...pulumiOpts } = opts;\n\n\t\tsuper(\"infracraft:neon:Branch\", name, {}, pulumiOpts);\n\n\t\tconst resource = new NeonBranchResource(\n\t\t\t`${name}-resource`,\n\t\t\t{\n\t\t\t\tapiKey: provider.apiKey,\n\t\t\t\tprojectId: project.id,\n\t\t\t\tname: args.name,\n\t\t\t\tparentName: args.parent,\n\t\t\t},\n\t\t\t{ parent: this },\n\t\t);\n\n\t\tthis.id = resource.id;\n\n\t\tthis.registerOutputs({ id: this.id });\n\t}\n}\n"],"mappings":";;;;;;;;AA+DA,eAAe,iBACd,QACA,WACA,MAC8B;CAO9B,QAFc,MAJO,OAAO,IAC3B,aAAa,UAAU,UACxB,GAEqB,SAAS,MAAM,MAAM,EAAE,SAAS,IAE1C,GAAG;AACf;;;;;;;;;AAUA,IAAa,6BAAb,MAEA;CACC,MAAM,OAAO,QAAgE;EAC5E,MAAM,SAAS,IAAI,WAAW,OAAO,MAAM;EAE3C,IAAI,WAAW,MAAM,iBACpB,QACA,OAAO,WACP,OAAO,IACR;EAEA,MAAM,aAAa,aAAa;EAEhC,IAAI,UACH,IAAI,OAAO,YACV,OAAO,IAAI,KACV,kCAAkC,OAAO,KAAK,kBAAkB,OAAO,WAAW,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AK;GACnD;GACA,qBAAqB;EACtB;CACD;AACD;;AAGA,IAAM,qBAAN,cAAiC,OAAO,QAAQ,SAAS;CAGxD,YACC,MACA,MAOA,MACC;EACD,MAAM,IAAI,2BAA2B,GAAG,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI;CAChE;AACD;;;;;;;;;;;;;;;;;;AAwCA,IAAa,aAAb,cAAgC,OAAO,kBAAkB;CAIxD,YAAY,MAAc,MAAsB,MAAyB;EACxE,MAAM,EAAE,UAAU,SAAS,GAAG,eAAe;EAE7C,MAAM,0BAA0B,MAAM,CAAC,GAAG,UAAU;EAEpD,MAAM,WAAW,IAAI,mBACpB,GAAG,KAAK,YACR;GACC,QAAQ,SAAS;GACjB,WAAW,QAAQ;GACnB,MAAM,KAAK;GACX,YAAY,KAAK;EAClB,GACA,EAAE,QAAQ,KAAK,CAChB;EAEA,KAAK,KAAK,SAAS;EAEnB,KAAK,gBAAgB,EAAE,IAAI,KAAK,GAAG,CAAC;CACrC;AACD"}
|
|
1
|
+
{"version":3,"file":"branch.mjs","names":[],"sources":["../../src/neon/branch.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport { NeonClient } from \"./client\";\nimport type { NeonProject } from \"./project\";\nimport type { NeonProvider } from \"./provider\";\n\n/** Resolved inputs for the Neon branch dynamic provider. */\nexport interface NeonBranchInputs {\n\t/** Neon API key. */\n\tapiKey: string;\n\n\t/** Neon project ID (e.g. `\"quiet-forest-69719462\"`). */\n\tprojectId: string;\n\n\t/** Branch display name (e.g. `\"production\"`, `\"development\"`). */\n\tname: string;\n\n\t/**\n\t * Parent branch NAME. Resolved to `parent_id` inside `create()` via\n\t * `findBranchByName`. Omit for project-root branches.\n\t */\n\tparentName?: string;\n}\n\n/** Persisted state for the Neon branch. */\ninterface NeonBranchOutputs extends NeonBranchInputs {}\n\n/** Neon API response for a branch. */\ninterface BranchResponse {\n\tbranch: {\n\t\tid: string;\n\t\tname: string;\n\t\tproject_id: string;\n\t};\n}\n\n/** Neon API response for branch creation. */\ninterface BranchCreateResponse {\n\tbranch: {\n\t\tid: string;\n\t\tname: string;\n\t\tproject_id: string;\n\t};\n}\n\n/** Neon API response for listing branches. */\ninterface BranchListResponse {\n\tbranches: Array<{\n\t\tid: string;\n\t\tname: string;\n\t}>;\n}\n\n/**\n * Finds an existing Neon branch by name within a project.\n */\nasync function findBranchByName(\n\tclient: NeonClient,\n\tprojectId: string,\n\tname: string,\n): Promise<string | undefined> {\n\tconst result = await client.get<BranchListResponse>(\n\t\t`/projects/${projectId}/branches`,\n\t);\n\n\tconst match = result.branches.find((b) => b.name === name);\n\n\treturn match?.id;\n}\n\n/**\n * Dynamic provider implementing CRUD for Neon branches.\n *\n * Uses adopt-or-create on `create()`: finds an existing branch by name\n * before creating a new one. When `parentName` is supplied, resolves it\n * to a `parent_id` and includes it in the POST body.\n */\n/** @internal Exported only for unit testing; not part of the public API surface. */\nexport class NeonBranchResourceProvider\n\timplements pulumi.dynamic.ResourceProvider\n{\n\tasync create(inputs: NeonBranchInputs): Promise<pulumi.dynamic.CreateResult> {\n\t\tconst client = new NeonClient(inputs.apiKey);\n\n\t\tlet branchId = await findBranchByName(\n\t\t\tclient,\n\t\t\tinputs.projectId,\n\t\t\tinputs.name,\n\t\t);\n\n\t\tif (branchId) {\n\t\t\tif (inputs.parentName) {\n\t\t\t\tpulumi.log.warn(\n\t\t\t\t\t`Adopting existing Neon branch \"${inputs.name}\" — parentName \"${inputs.parentName}\" is ignored for adopted branches (existing lineage preserved).`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tpulumi.log.info(\n\t\t\t\t\t`Adopting existing Neon branch \"${inputs.name}\" (${branchId})`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tconst body: { branch: { name: string; parent_id?: string } } = {\n\t\t\t\tbranch: { name: inputs.name },\n\t\t\t};\n\n\t\t\tif (inputs.parentName) {\n\t\t\t\tconst parentId = await findBranchByName(\n\t\t\t\t\tclient,\n\t\t\t\t\tinputs.projectId,\n\t\t\t\t\tinputs.parentName,\n\t\t\t\t);\n\n\t\t\t\tif (!parentId) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Neon parent branch \"${inputs.parentName}\" not found in project ${inputs.projectId}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tbody.branch.parent_id = parentId;\n\t\t\t}\n\n\t\t\tconst result = await client.post<BranchCreateResponse>(\n\t\t\t\t`/projects/${inputs.projectId}/branches`,\n\t\t\t\tbody,\n\t\t\t);\n\n\t\t\tbranchId = result.branch.id;\n\t\t}\n\n\t\treturn { id: branchId, outs: { ...inputs } };\n\t}\n\n\tasync read(\n\t\tid: string,\n\t\tprops: NeonBranchOutputs,\n\t): Promise<pulumi.dynamic.ReadResult> {\n\t\tconst client = new NeonClient(props.apiKey);\n\n\t\tconst result = await client.get<BranchResponse>(\n\t\t\t`/projects/${props.projectId}/branches/${id}`,\n\t\t);\n\n\t\t// parentName is preserved from prior state (props): the Neon API does not expose\n\t\t// a branch's parent on GET /branches/:id, so it cannot be re-derived here.\n\t\treturn {\n\t\t\tid: result.branch.id,\n\t\t\tprops: { ...props, name: result.branch.name },\n\t\t};\n\t}\n\n\t/**\n\t * Deletes the branch. Protection of shared/production branches is the consumer's\n\t * responsibility via the `protect` resource option, not provider logic.\n\t */\n\tasync delete(id: string, props: NeonBranchOutputs): Promise<void> {\n\t\tconst client = new NeonClient(props.apiKey);\n\n\t\ttry {\n\t\t\tawait client.delete(`/projects/${props.projectId}/branches/${id}`);\n\t\t} catch {\n\t\t\tpulumi.log.warn(`Failed to delete Neon branch (may already be deleted)`);\n\t\t}\n\t}\n\n\tasync diff(\n\t\t_id: string,\n\t\tolds: NeonBranchOutputs,\n\t\tnews: NeonBranchInputs,\n\t): Promise<pulumi.dynamic.DiffResult> {\n\t\tconst replaces: string[] = [];\n\n\t\tif (olds.projectId !== news.projectId) {\n\t\t\treplaces.push(\"projectId\");\n\t\t}\n\n\t\tif (olds.parentName !== news.parentName) {\n\t\t\treplaces.push(\"parentName\");\n\t\t}\n\n\t\treturn {\n\t\t\tchanges: replaces.length > 0 || olds.name !== news.name,\n\t\t\treplaces,\n\t\t\tdeleteBeforeReplace: true,\n\t\t};\n\t}\n}\n\n/** Internal dynamic resource — not part of the public API. */\nclass NeonBranchResource extends pulumi.dynamic.Resource {\n\tpublic declare readonly branchId: pulumi.Output<string>;\n\n\tconstructor(\n\t\tname: string,\n\t\targs: {\n\t\t\tapiKey: pulumi.Input<string>;\n\t\t\tprojectId: pulumi.Input<string>;\n\t\t\tname: pulumi.Input<string>;\n\t\t\t/** Name of the parent branch; omit for project-root branches. */\n\t\t\tparentName?: pulumi.Input<string>;\n\t\t},\n\t\topts?: pulumi.CustomResourceOptions,\n\t) {\n\t\tsuper(new NeonBranchResourceProvider(), name, { ...args }, opts);\n\t}\n}\n\n/** Options type for NeonBranch — replaces Pulumi's native `provider` field. */\ntype NeonBranchOptions = Omit<pulumi.ComponentResourceOptions, \"provider\"> & {\n\t/** Neon authentication context. */\n\tprovider: NeonProvider;\n\n\t/** Neon project context. */\n\tproject: NeonProject;\n};\n\n/** Args for NeonBranch. */\nexport interface NeonBranchArgs {\n\t/** Branch display name. */\n\tname: pulumi.Input<string>;\n\n\t/**\n\t * Name of the parent branch to branch from (copy-on-write). Omit to\n\t * branch from the project root (Neon default branch).\n\t */\n\tparent?: pulumi.Input<string>;\n}\n\n/**\n * Manages a Neon branch with adopt-or-create semantics.\n *\n * @example\n * ```typescript\n * // Root branch (Neon default parent)\n * const production = new NeonBranch(\"production\", {\n * name: \"production\",\n * }, { provider, project });\n *\n * // Copy-on-write branch from production\n * const staging = new NeonBranch(\"staging\", {\n * name: \"staging\",\n * parent: \"production\",\n * }, { provider, project });\n * ```\n */\nexport class NeonBranch extends pulumi.ComponentResource {\n\t/** Neon branch ID. */\n\tpublic readonly id: pulumi.Output<string>;\n\n\tconstructor(name: string, args: NeonBranchArgs, opts: NeonBranchOptions) {\n\t\tconst { provider, project, ...pulumiOpts } = opts;\n\n\t\tsuper(\"infracraft:neon:Branch\", name, {}, pulumiOpts);\n\n\t\tconst resource = new NeonBranchResource(\n\t\t\t`${name}-resource`,\n\t\t\t{\n\t\t\t\tapiKey: provider.apiKey,\n\t\t\t\tprojectId: project.id,\n\t\t\t\tname: args.name,\n\t\t\t\tparentName: args.parent,\n\t\t\t},\n\t\t\t{ parent: this },\n\t\t);\n\n\t\tthis.id = resource.id;\n\n\t\tthis.registerOutputs({ id: this.id });\n\t}\n}\n"],"mappings":";;;;;;;;AAuDA,eAAe,iBACd,QACA,WACA,MAC8B;CAO9B,QAFc,MAJO,OAAO,IAC3B,aAAa,UAAU,UACxB,GAEqB,SAAS,MAAM,MAAM,EAAE,SAAS,IAE1C,GAAG;AACf;;;;;;;;;AAUA,IAAa,6BAAb,MAEA;CACC,MAAM,OAAO,QAAgE;EAC5E,MAAM,SAAS,IAAI,WAAW,OAAO,MAAM;EAE3C,IAAI,WAAW,MAAM,iBACpB,QACA,OAAO,WACP,OAAO,IACR;EAEA,IAAI,UACH,IAAI,OAAO,YACV,OAAO,IAAI,KACV,kCAAkC,OAAO,KAAK,kBAAkB,OAAO,WAAW,gEACnF;OAEA,OAAO,IAAI,KACV,kCAAkC,OAAO,KAAK,KAAK,SAAS,EAC7D;OAEK;GACN,MAAM,OAAyD,EAC9D,QAAQ,EAAE,MAAM,OAAO,KAAK,EAC7B;GAEA,IAAI,OAAO,YAAY;IACtB,MAAM,WAAW,MAAM,iBACtB,QACA,OAAO,WACP,OAAO,UACR;IAEA,IAAI,CAAC,UACJ,MAAM,IAAI,MACT,uBAAuB,OAAO,WAAW,yBAAyB,OAAO,WAC1E;IAGD,KAAK,OAAO,YAAY;GACzB;GAOA,YAAW,MALU,OAAO,KAC3B,aAAa,OAAO,UAAU,YAC9B,IACD,GAEkB,OAAO;EAC1B;EAEA,OAAO;GAAE,IAAI;GAAU,MAAM,EAAE,GAAG,OAAO;EAAE;CAC5C;CAEA,MAAM,KAC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AAG,CAAC;CACrC;AACD"}
|
|
@@ -53,7 +53,6 @@ var RailwayEnvironmentResourceProvider = class {
|
|
|
53
53
|
async create(inputs) {
|
|
54
54
|
const client = new require_railway_client.RailwayClient(inputs.token);
|
|
55
55
|
let environmentId = await findEnvironmentId(client, inputs.projectId, inputs.name);
|
|
56
|
-
const wasAdopted = environmentId !== void 0;
|
|
57
56
|
if (environmentId) _pulumi_pulumi.log.info(`Adopting existing Railway environment "${inputs.name}" (${environmentId})`);
|
|
58
57
|
else {
|
|
59
58
|
let sourceEnvironmentId;
|
|
@@ -71,8 +70,7 @@ var RailwayEnvironmentResourceProvider = class {
|
|
|
71
70
|
}
|
|
72
71
|
const outs = {
|
|
73
72
|
...inputs,
|
|
74
|
-
environmentId
|
|
75
|
-
wasAdopted
|
|
73
|
+
environmentId
|
|
76
74
|
};
|
|
77
75
|
return {
|
|
78
76
|
id: environmentId,
|
|
@@ -90,25 +88,20 @@ var RailwayEnvironmentResourceProvider = class {
|
|
|
90
88
|
}
|
|
91
89
|
};
|
|
92
90
|
}
|
|
93
|
-
async update(_id,
|
|
91
|
+
async update(_id, _olds, news) {
|
|
94
92
|
const environmentId = await findEnvironmentId(new require_railway_client.RailwayClient(news.token), news.projectId, news.name);
|
|
95
93
|
if (!environmentId) throw new Error(`Railway environment "${news.name}" not found in project ${news.projectId}`);
|
|
96
94
|
return { outs: {
|
|
97
95
|
...news,
|
|
98
|
-
environmentId
|
|
99
|
-
wasAdopted: olds.wasAdopted
|
|
96
|
+
environmentId
|
|
100
97
|
} };
|
|
101
98
|
}
|
|
102
99
|
/**
|
|
103
|
-
* Deletes the environment
|
|
104
|
-
*
|
|
105
|
-
*
|
|
100
|
+
* Deletes the environment (which cascades its per-environment service instances).
|
|
101
|
+
* Protection of the shared production environment is the consumer's responsibility
|
|
102
|
+
* via the `protect` resource option, not provider logic.
|
|
106
103
|
*/
|
|
107
104
|
async delete(_id, props) {
|
|
108
|
-
if (props.wasAdopted !== false) {
|
|
109
|
-
_pulumi_pulumi.log.warn(`Railway environment "${props.name}" deletion skipped — adopted (not created by Pulumi)`);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
105
|
const client = new require_railway_client.RailwayClient(props.token);
|
|
113
106
|
try {
|
|
114
107
|
await client.query(ENVIRONMENT_DELETE_MUTATION, { id: props.environmentId });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.cjs","names":["RailwayClient","pulumi"],"sources":["../../src/railway/environment.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport { RailwayClient } from \"./client\";\nimport type { RailwayProject } from \"./project\";\nimport type { RailwayProvider } from \"./provider\";\n\n/** Resolved inputs for the Railway environment dynamic provider. */\ninterface RailwayEnvironmentInputs {\n\t/** Railway API bearer token. */\n\ttoken: string;\n\n\t/** Railway project UUID. */\n\tprojectId: string;\n\n\t/** Environment display name (e.g. `\"production\"`, `\"staging\"`). */\n\tname: string;\n\n\t/** Name of an existing environment to fork from when creating a new one. */\n\tsource?: string;\n}\n\n/** Persisted state for the Railway environment. */\ninterface RailwayEnvironmentOutputs extends RailwayEnvironmentInputs {\n\t/** Railway-assigned environment UUID. */\n\tenvironmentId: string;\n\n\t/**\n\t * Whether this environment already existed and was adopted (vs. created by us).\n\t * `delete()` only removes environments we created. Absent on state written before\n\t * this field existed, which is treated as adopted (the safe, non-destructive default).\n\t */\n\twasAdopted?: boolean;\n}\n\nconst ENVIRONMENT_CREATE_MUTATION = `\n mutation EnvironmentCreate($input: EnvironmentCreateInput!) {\n environmentCreate(input: $input) {\n id\n name\n }\n }\n`;\n\nconst ENVIRONMENT_DELETE_MUTATION = `\n mutation($id: String!) { environmentDelete(id: $id) }\n`;\n\nconst PROJECT_ENVIRONMENTS_QUERY = `\n query($projectId: String!) {\n project(id: $projectId) {\n environments {\n edges {\n node {\n id\n name\n }\n }\n }\n }\n }\n`;\n\n/**\n * Queries a project's environments and resolves the ID for the given name.\n */\nasync function findEnvironmentId(\n\tclient: RailwayClient,\n\tprojectId: string,\n\tname: string,\n): Promise<string | undefined> {\n\tconst result = await client.query<{\n\t\tproject: {\n\t\t\tenvironments: {\n\t\t\t\tedges: Array<{ node: { id: string; name: string } }>;\n\t\t\t};\n\t\t};\n\t}>(PROJECT_ENVIRONMENTS_QUERY, { projectId });\n\n\tconst match = result.project.environments.edges.find(\n\t\t(edge) => edge.node.name === name,\n\t);\n\n\treturn match?.node.id;\n}\n\n/**\n * Dynamic provider that resolves or creates a Railway environment by name.\n *\n * @internal Exported only for unit testing; not part of the public API surface.\n */\nexport class RailwayEnvironmentResourceProvider\n\timplements pulumi.dynamic.ResourceProvider\n{\n\t/**\n\t * Adopts an existing Railway environment when found by name, or creates a new\n\t * one (optionally forked from a source environment) when not found.\n\t *\n\t * @param inputs Resolved provider inputs including token, projectId, name, and optional source.\n\t * @returns Pulumi dynamic create result with the environment UUID as the resource ID.\n\t * @throws {Error} When `source` is provided but cannot be resolved to an environment ID.\n\t */\n\tasync create(\n\t\tinputs: RailwayEnvironmentInputs,\n\t): Promise<pulumi.dynamic.CreateResult> {\n\t\tconst client = new RailwayClient(inputs.token);\n\n\t\tlet environmentId = await findEnvironmentId(\n\t\t\tclient,\n\t\t\tinputs.projectId,\n\t\t\tinputs.name,\n\t\t);\n\n\t\tconst wasAdopted = environmentId !== undefined;\n\n\t\tif (environmentId) {\n\t\t\tpulumi.log.info(\n\t\t\t\t`Adopting existing Railway environment \"${inputs.name}\" (${environmentId})`,\n\t\t\t);\n\t\t} else {\n\t\t\tlet sourceEnvironmentId: string | undefined;\n\n\t\t\tif (inputs.source) {\n\t\t\t\tsourceEnvironmentId = await findEnvironmentId(\n\t\t\t\t\tclient,\n\t\t\t\t\tinputs.projectId,\n\t\t\t\t\tinputs.source,\n\t\t\t\t);\n\n\t\t\t\tif (!sourceEnvironmentId) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Railway source environment \"${inputs.source}\" not found in project ${inputs.projectId}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst result = await client.query<{\n\t\t\t\tenvironmentCreate: { id: string; name: string };\n\t\t\t}>(ENVIRONMENT_CREATE_MUTATION, {\n\t\t\t\tinput: {\n\t\t\t\t\tprojectId: inputs.projectId,\n\t\t\t\t\tname: inputs.name,\n\t\t\t\t\t// skipInitialDeploys: hold deploys so a forked env doesn't run with inherited\n\t\t\t\t\t// source/production variables before our RailwayVariable resources overwrite them.\n\t\t\t\t\tskipInitialDeploys: true,\n\t\t\t\t\t...(sourceEnvironmentId ? { sourceEnvironmentId } : {}),\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tenvironmentId = result.environmentCreate.id;\n\n\t\t\tpulumi.log.info(\n\t\t\t\t`Created Railway environment \"${inputs.name}\" (${environmentId})`,\n\t\t\t);\n\t\t}\n\n\t\tconst outs: RailwayEnvironmentOutputs = {\n\t\t\t...inputs,\n\t\t\tenvironmentId,\n\t\t\twasAdopted,\n\t\t};\n\n\t\treturn { id: environmentId, outs };\n\t}\n\n\tasync read(\n\t\t_id: string,\n\t\tprops: RailwayEnvironmentOutputs,\n\t): Promise<pulumi.dynamic.ReadResult> {\n\t\tconst client = new RailwayClient(props.token);\n\n\t\tconst environmentId = await findEnvironmentId(\n\t\t\tclient,\n\t\t\tprops.projectId,\n\t\t\tprops.name,\n\t\t);\n\n\t\tif (!environmentId) {\n\t\t\tthrow new Error(\n\t\t\t\t`Railway environment \"${props.name}\" not found during refresh`,\n\t\t\t);\n\t\t}\n\n\t\treturn { id: environmentId, props: { ...props, environmentId } };\n\t}\n\n\tasync update(\n\t\t_id: string,\n\t\tolds: RailwayEnvironmentOutputs,\n\t\tnews: RailwayEnvironmentInputs,\n\t): Promise<pulumi.dynamic.UpdateResult> {\n\t\tconst client = new RailwayClient(news.token);\n\n\t\tconst environmentId = await findEnvironmentId(\n\t\t\tclient,\n\t\t\tnews.projectId,\n\t\t\tnews.name,\n\t\t);\n\n\t\tif (!environmentId) {\n\t\t\tthrow new Error(\n\t\t\t\t`Railway environment \"${news.name}\" not found in project ${news.projectId}`,\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\touts: { ...news, environmentId, wasAdopted: olds.wasAdopted },\n\t\t};\n\t}\n\n\t/**\n\t * Deletes the environment only if we created it. Adopted environments (and\n\t * state written before `wasAdopted` existed) are left untouched, so a feature\n\t * env's destroy never removes the shared production environment.\n\t */\n\tasync delete(_id: string, props: RailwayEnvironmentOutputs): Promise<void> {\n\t\tif (props.wasAdopted !== false) {\n\t\t\tpulumi.log.warn(\n\t\t\t\t`Railway environment \"${props.name}\" deletion skipped — adopted (not created by Pulumi)`,\n\t\t\t);\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst client = new RailwayClient(props.token);\n\n\t\ttry {\n\t\t\tawait client.query(ENVIRONMENT_DELETE_MUTATION, {\n\t\t\t\tid: props.environmentId,\n\t\t\t});\n\n\t\t\tpulumi.log.info(\n\t\t\t\t`Deleted Railway environment \"${props.name}\" (${props.environmentId})`,\n\t\t\t);\n\t\t} catch {\n\t\t\tpulumi.log.warn(\n\t\t\t\t`Failed to delete Railway environment \"${props.name}\" (may already be deleted)`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync diff(\n\t\t_id: string,\n\t\tolds: RailwayEnvironmentOutputs,\n\t\tnews: RailwayEnvironmentInputs,\n\t): Promise<pulumi.dynamic.DiffResult> {\n\t\tconst replaces: string[] = [];\n\n\t\tif (olds.projectId !== news.projectId) {\n\t\t\treplaces.push(\"projectId\");\n\t\t}\n\n\t\tif (olds.name !== news.name) {\n\t\t\treplaces.push(\"name\");\n\t\t}\n\n\t\treturn {\n\t\t\tchanges: replaces.length > 0,\n\t\t\treplaces,\n\t\t\tdeleteBeforeReplace: true,\n\t\t};\n\t}\n}\n\n/** Internal dynamic resource — not part of the public API. */\nclass RailwayEnvironmentResource extends pulumi.dynamic.Resource {\n\tpublic declare readonly environmentId: pulumi.Output<string>;\n\n\tconstructor(\n\t\tname: string,\n\t\targs: {\n\t\t\ttoken: pulumi.Input<string>;\n\t\t\tprojectId: pulumi.Input<string>;\n\t\t\tname: pulumi.Input<string>;\n\t\t\tsource?: pulumi.Input<string>;\n\t\t},\n\t\topts?: pulumi.CustomResourceOptions,\n\t) {\n\t\tsuper(\n\t\t\tnew RailwayEnvironmentResourceProvider(),\n\t\t\tname,\n\t\t\t{\n\t\t\t\t...args,\n\t\t\t\tenvironmentId: undefined,\n\t\t\t},\n\t\t\topts,\n\t\t);\n\t}\n}\n\n/** Options type for RailwayEnvironment — replaces Pulumi's native `provider` field. */\ntype RailwayEnvironmentOptions = Omit<\n\tpulumi.ComponentResourceOptions,\n\t\"provider\"\n> & {\n\t/** Railway authentication context. */\n\tprovider: RailwayProvider;\n\n\t/** Railway project context to resolve the environment from. */\n\tproject: RailwayProject;\n};\n\n/** Args for RailwayEnvironment. */\nexport interface RailwayEnvironmentArgs {\n\t/** Environment display name (e.g. `\"production\"`, `\"staging\"`). */\n\tname: pulumi.Input<string>;\n\n\t/**\n\t * Name of an existing environment to fork from when this environment is created.\n\t * Evaluated only at creation time — changing `source` after the environment exists\n\t * has no effect (an existing environment is never re-forked).\n\t */\n\tsource?: pulumi.Input<string>;\n}\n\n/**\n * Resolves or creates a Railway environment by name within a project.\n *\n * When the named environment already exists it is adopted (no mutation).\n * When it does not exist it is created — optionally forked from a source\n * environment so the new env inherits service instances and variables.\n *\n * @example\n * ```typescript\n * // Adopt or create \"production\" (no source)\n * const production = new RailwayEnvironment(\"production\", {\n * name: \"production\",\n * }, { provider, project });\n *\n * // Adopt or create \"staging\", forked from \"production\"\n * const staging = new RailwayEnvironment(\"staging\", {\n * name: \"staging\",\n * source: \"production\",\n * }, { provider, project });\n *\n * // Use environmentId downstream\n * const service = new RailwayService(\"api\", { name: \"api\" }, {\n * provider, project, environment: staging,\n * });\n * ```\n */\nexport class RailwayEnvironment extends pulumi.ComponentResource {\n\t/** Railway environment UUID. */\n\tpublic readonly id: pulumi.Output<string>;\n\n\tconstructor(\n\t\tname: string,\n\t\targs: RailwayEnvironmentArgs,\n\t\topts: RailwayEnvironmentOptions,\n\t) {\n\t\tconst { provider, project, ...pulumiOpts } = opts;\n\n\t\tsuper(\"infracraft:railway:Environment\", name, {}, pulumiOpts);\n\n\t\tconst resource = new RailwayEnvironmentResource(\n\t\t\t`${name}-resource`,\n\t\t\t{\n\t\t\t\ttoken: provider.token,\n\t\t\t\tprojectId: project.id,\n\t\t\t\tname: args.name,\n\t\t\t\tsource: args.source,\n\t\t\t},\n\t\t\t{ parent: this },\n\t\t);\n\n\t\tthis.id = resource.environmentId;\n\n\t\tthis.registerOutputs({ id: this.id });\n\t}\n}\n"],"mappings":";;;;;;;AAiCA,MAAM,8BAA8B;;;;;;;;AASpC,MAAM,8BAA8B;;;AAIpC,MAAM,6BAA6B;;;;;;;;;;;;;;;;;AAkBnC,eAAe,kBACd,QACA,WACA,MAC8B;CAa9B,QAJc,MARO,OAAO,MAMzB,4BAA4B,EAAE,UAAU,CAAC,GAEvB,QAAQ,aAAa,MAAM,MAC9C,SAAS,KAAK,KAAK,SAAS,IAGnB,GAAG,KAAK;AACpB;;;;;;AAOA,IAAa,qCAAb,MAEA;;;;;;;;;CASC,MAAM,OACL,QACuC;EACvC,MAAM,SAAS,IAAIA,qCAAc,OAAO,KAAK;EAE7C,IAAI,gBAAgB,MAAM,kBACzB,QACA,OAAO,WACP,OAAO,IACR;EAEA,MAAM,aAAa,kBAAkB;EAErC,IAAI,eACH,eAAO,IAAI,KACV,0CAA0C,OAAO,KAAK,KAAK,cAAc,EAC1E;OACM;GACN,IAAI;GAEJ,IAAI,OAAO,QAAQ;IAClB,sBAAsB,MAAM,kBAC3B,QACA,OAAO,WACP,OAAO,MACR;IAEA,IAAI,CAAC,qBACJ,MAAM,IAAI,MACT,+BAA+B,OAAO,OAAO,yBAAyB,OAAO,WAC9E;GAEF;GAeA,iBAAgB,MAbK,OAAO,MAEzB,6BAA6B,EAC/B,OAAO;IACN,WAAW,OAAO;IAClB,MAAM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AAqB,CAAC;EAE5B,IAAI,KAAK,cAAc,KAAK,WAC3B,SAAS,KAAK,WAAW;EAG1B,IAAI,KAAK,SAAS,KAAK,MACtB,SAAS,KAAK,MAAM;EAGrB,OAAO;GACN,SAAS,SAAS,SAAS;GAC3B;GACA,qBAAqB;EACtB;CACD;AACD;;AAGA,IAAM,6BAAN,cAAyCC,eAAO,QAAQ,SAAS;CAGhE,YACC,MACA,MAMA,MACC;EACD,MACC,IAAI,mCAAmC,GACvC,MACA;GACC,GAAG;GACH,eAAe;EAChB,GACA,IACD;CACD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,IAAa,qBAAb,cAAwCA,eAAO,kBAAkB;CAIhE,YACC,MACA,MACA,MACC;EACD,MAAM,EAAE,UAAU,SAAS,GAAG,eAAe;EAE7C,MAAM,kCAAkC,MAAM,CAAC,GAAG,UAAU;EAE5D,MAAM,WAAW,IAAI,2BACpB,GAAG,KAAK,YACR;GACC,OAAO,SAAS;GAChB,WAAW,QAAQ;GACnB,MAAM,KAAK;GACX,QAAQ,KAAK;EACd,GACA,EAAE,QAAQ,KAAK,CAChB;EAEA,KAAK,KAAK,SAAS;EAEnB,KAAK,gBAAgB,EAAE,IAAI,KAAK,GAAG,CAAC;CACrC;AACD"}
|
|
1
|
+
{"version":3,"file":"environment.cjs","names":["RailwayClient","pulumi"],"sources":["../../src/railway/environment.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport { RailwayClient } from \"./client\";\nimport type { RailwayProject } from \"./project\";\nimport type { RailwayProvider } from \"./provider\";\n\n/** Resolved inputs for the Railway environment dynamic provider. */\ninterface RailwayEnvironmentInputs {\n\t/** Railway API bearer token. */\n\ttoken: string;\n\n\t/** Railway project UUID. */\n\tprojectId: string;\n\n\t/** Environment display name (e.g. `\"production\"`, `\"staging\"`). */\n\tname: string;\n\n\t/** Name of an existing environment to fork from when creating a new one. */\n\tsource?: string;\n}\n\n/** Persisted state for the Railway environment. */\ninterface RailwayEnvironmentOutputs extends RailwayEnvironmentInputs {\n\t/** Railway-assigned environment UUID. */\n\tenvironmentId: string;\n}\n\nconst ENVIRONMENT_CREATE_MUTATION = `\n mutation EnvironmentCreate($input: EnvironmentCreateInput!) {\n environmentCreate(input: $input) {\n id\n name\n }\n }\n`;\n\nconst ENVIRONMENT_DELETE_MUTATION = `\n mutation($id: String!) { environmentDelete(id: $id) }\n`;\n\nconst PROJECT_ENVIRONMENTS_QUERY = `\n query($projectId: String!) {\n project(id: $projectId) {\n environments {\n edges {\n node {\n id\n name\n }\n }\n }\n }\n }\n`;\n\n/**\n * Queries a project's environments and resolves the ID for the given name.\n */\nasync function findEnvironmentId(\n\tclient: RailwayClient,\n\tprojectId: string,\n\tname: string,\n): Promise<string | undefined> {\n\tconst result = await client.query<{\n\t\tproject: {\n\t\t\tenvironments: {\n\t\t\t\tedges: Array<{ node: { id: string; name: string } }>;\n\t\t\t};\n\t\t};\n\t}>(PROJECT_ENVIRONMENTS_QUERY, { projectId });\n\n\tconst match = result.project.environments.edges.find(\n\t\t(edge) => edge.node.name === name,\n\t);\n\n\treturn match?.node.id;\n}\n\n/**\n * Dynamic provider that resolves or creates a Railway environment by name.\n *\n * @internal Exported only for unit testing; not part of the public API surface.\n */\nexport class RailwayEnvironmentResourceProvider\n\timplements pulumi.dynamic.ResourceProvider\n{\n\t/**\n\t * Adopts an existing Railway environment when found by name, or creates a new\n\t * one (optionally forked from a source environment) when not found.\n\t *\n\t * @param inputs Resolved provider inputs including token, projectId, name, and optional source.\n\t * @returns Pulumi dynamic create result with the environment UUID as the resource ID.\n\t * @throws {Error} When `source` is provided but cannot be resolved to an environment ID.\n\t */\n\tasync create(\n\t\tinputs: RailwayEnvironmentInputs,\n\t): Promise<pulumi.dynamic.CreateResult> {\n\t\tconst client = new RailwayClient(inputs.token);\n\n\t\tlet environmentId = await findEnvironmentId(\n\t\t\tclient,\n\t\t\tinputs.projectId,\n\t\t\tinputs.name,\n\t\t);\n\n\t\tif (environmentId) {\n\t\t\tpulumi.log.info(\n\t\t\t\t`Adopting existing Railway environment \"${inputs.name}\" (${environmentId})`,\n\t\t\t);\n\t\t} else {\n\t\t\tlet sourceEnvironmentId: string | undefined;\n\n\t\t\tif (inputs.source) {\n\t\t\t\tsourceEnvironmentId = await findEnvironmentId(\n\t\t\t\t\tclient,\n\t\t\t\t\tinputs.projectId,\n\t\t\t\t\tinputs.source,\n\t\t\t\t);\n\n\t\t\t\tif (!sourceEnvironmentId) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Railway source environment \"${inputs.source}\" not found in project ${inputs.projectId}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst result = await client.query<{\n\t\t\t\tenvironmentCreate: { id: string; name: string };\n\t\t\t}>(ENVIRONMENT_CREATE_MUTATION, {\n\t\t\t\tinput: {\n\t\t\t\t\tprojectId: inputs.projectId,\n\t\t\t\t\tname: inputs.name,\n\t\t\t\t\t// skipInitialDeploys: hold deploys so a forked env doesn't run with inherited\n\t\t\t\t\t// source/production variables before our RailwayVariable resources overwrite them.\n\t\t\t\t\tskipInitialDeploys: true,\n\t\t\t\t\t...(sourceEnvironmentId ? { sourceEnvironmentId } : {}),\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tenvironmentId = result.environmentCreate.id;\n\n\t\t\tpulumi.log.info(\n\t\t\t\t`Created Railway environment \"${inputs.name}\" (${environmentId})`,\n\t\t\t);\n\t\t}\n\n\t\tconst outs: RailwayEnvironmentOutputs = { ...inputs, environmentId };\n\n\t\treturn { id: environmentId, outs };\n\t}\n\n\tasync read(\n\t\t_id: string,\n\t\tprops: RailwayEnvironmentOutputs,\n\t): Promise<pulumi.dynamic.ReadResult> {\n\t\tconst client = new RailwayClient(props.token);\n\n\t\tconst environmentId = await findEnvironmentId(\n\t\t\tclient,\n\t\t\tprops.projectId,\n\t\t\tprops.name,\n\t\t);\n\n\t\tif (!environmentId) {\n\t\t\tthrow new Error(\n\t\t\t\t`Railway environment \"${props.name}\" not found during refresh`,\n\t\t\t);\n\t\t}\n\n\t\treturn { id: environmentId, props: { ...props, environmentId } };\n\t}\n\n\tasync update(\n\t\t_id: string,\n\t\t_olds: RailwayEnvironmentOutputs,\n\t\tnews: RailwayEnvironmentInputs,\n\t): Promise<pulumi.dynamic.UpdateResult> {\n\t\tconst client = new RailwayClient(news.token);\n\n\t\tconst environmentId = await findEnvironmentId(\n\t\t\tclient,\n\t\t\tnews.projectId,\n\t\t\tnews.name,\n\t\t);\n\n\t\tif (!environmentId) {\n\t\t\tthrow new Error(\n\t\t\t\t`Railway environment \"${news.name}\" not found in project ${news.projectId}`,\n\t\t\t);\n\t\t}\n\n\t\treturn { outs: { ...news, environmentId } };\n\t}\n\n\t/**\n\t * Deletes the environment (which cascades its per-environment service instances).\n\t * Protection of the shared production environment is the consumer's responsibility\n\t * via the `protect` resource option, not provider logic.\n\t */\n\tasync delete(_id: string, props: RailwayEnvironmentOutputs): Promise<void> {\n\t\tconst client = new RailwayClient(props.token);\n\n\t\ttry {\n\t\t\tawait client.query(ENVIRONMENT_DELETE_MUTATION, {\n\t\t\t\tid: props.environmentId,\n\t\t\t});\n\n\t\t\tpulumi.log.info(\n\t\t\t\t`Deleted Railway environment \"${props.name}\" (${props.environmentId})`,\n\t\t\t);\n\t\t} catch {\n\t\t\tpulumi.log.warn(\n\t\t\t\t`Failed to delete Railway environment \"${props.name}\" (may already be deleted)`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync diff(\n\t\t_id: string,\n\t\tolds: RailwayEnvironmentOutputs,\n\t\tnews: RailwayEnvironmentInputs,\n\t): Promise<pulumi.dynamic.DiffResult> {\n\t\tconst replaces: string[] = [];\n\n\t\tif (olds.projectId !== news.projectId) {\n\t\t\treplaces.push(\"projectId\");\n\t\t}\n\n\t\tif (olds.name !== news.name) {\n\t\t\treplaces.push(\"name\");\n\t\t}\n\n\t\treturn {\n\t\t\tchanges: replaces.length > 0,\n\t\t\treplaces,\n\t\t\tdeleteBeforeReplace: true,\n\t\t};\n\t}\n}\n\n/** Internal dynamic resource — not part of the public API. */\nclass RailwayEnvironmentResource extends pulumi.dynamic.Resource {\n\tpublic declare readonly environmentId: pulumi.Output<string>;\n\n\tconstructor(\n\t\tname: string,\n\t\targs: {\n\t\t\ttoken: pulumi.Input<string>;\n\t\t\tprojectId: pulumi.Input<string>;\n\t\t\tname: pulumi.Input<string>;\n\t\t\tsource?: pulumi.Input<string>;\n\t\t},\n\t\topts?: pulumi.CustomResourceOptions,\n\t) {\n\t\tsuper(\n\t\t\tnew RailwayEnvironmentResourceProvider(),\n\t\t\tname,\n\t\t\t{\n\t\t\t\t...args,\n\t\t\t\tenvironmentId: undefined,\n\t\t\t},\n\t\t\topts,\n\t\t);\n\t}\n}\n\n/** Options type for RailwayEnvironment — replaces Pulumi's native `provider` field. */\ntype RailwayEnvironmentOptions = Omit<\n\tpulumi.ComponentResourceOptions,\n\t\"provider\"\n> & {\n\t/** Railway authentication context. */\n\tprovider: RailwayProvider;\n\n\t/** Railway project context to resolve the environment from. */\n\tproject: RailwayProject;\n};\n\n/** Args for RailwayEnvironment. */\nexport interface RailwayEnvironmentArgs {\n\t/** Environment display name (e.g. `\"production\"`, `\"staging\"`). */\n\tname: pulumi.Input<string>;\n\n\t/**\n\t * Name of an existing environment to fork from when this environment is created.\n\t * Evaluated only at creation time — changing `source` after the environment exists\n\t * has no effect (an existing environment is never re-forked).\n\t */\n\tsource?: pulumi.Input<string>;\n}\n\n/**\n * Resolves or creates a Railway environment by name within a project.\n *\n * When the named environment already exists it is adopted (no mutation).\n * When it does not exist it is created — optionally forked from a source\n * environment so the new env inherits service instances and variables.\n *\n * @example\n * ```typescript\n * // Adopt or create \"production\" (no source)\n * const production = new RailwayEnvironment(\"production\", {\n * name: \"production\",\n * }, { provider, project });\n *\n * // Adopt or create \"staging\", forked from \"production\"\n * const staging = new RailwayEnvironment(\"staging\", {\n * name: \"staging\",\n * source: \"production\",\n * }, { provider, project });\n *\n * // Use environmentId downstream\n * const service = new RailwayService(\"api\", { name: \"api\" }, {\n * provider, project, environment: staging,\n * });\n * ```\n */\nexport class RailwayEnvironment extends pulumi.ComponentResource {\n\t/** Railway environment UUID. */\n\tpublic readonly id: pulumi.Output<string>;\n\n\tconstructor(\n\t\tname: string,\n\t\targs: RailwayEnvironmentArgs,\n\t\topts: RailwayEnvironmentOptions,\n\t) {\n\t\tconst { provider, project, ...pulumiOpts } = opts;\n\n\t\tsuper(\"infracraft:railway:Environment\", name, {}, pulumiOpts);\n\n\t\tconst resource = new RailwayEnvironmentResource(\n\t\t\t`${name}-resource`,\n\t\t\t{\n\t\t\t\ttoken: provider.token,\n\t\t\t\tprojectId: project.id,\n\t\t\t\tname: args.name,\n\t\t\t\tsource: args.source,\n\t\t\t},\n\t\t\t{ parent: this },\n\t\t);\n\n\t\tthis.id = resource.environmentId;\n\n\t\tthis.registerOutputs({ id: this.id });\n\t}\n}\n"],"mappings":";;;;;;;AA0BA,MAAM,8BAA8B;;;;;;;;AASpC,MAAM,8BAA8B;;;AAIpC,MAAM,6BAA6B;;;;;;;;;;;;;;;;;AAkBnC,eAAe,kBACd,QACA,WACA,MAC8B;CAa9B,QAJc,MARO,OAAO,MAMzB,4BAA4B,EAAE,UAAU,CAAC,GAEvB,QAAQ,aAAa,MAAM,MAC9C,SAAS,KAAK,KAAK,SAAS,IAGnB,GAAG,KAAK;AACpB;;;;;;AAOA,IAAa,qCAAb,MAEA;;;;;;;;;CASC,MAAM,OACL,QACuC;EACvC,MAAM,SAAS,IAAIA,qCAAc,OAAO,KAAK;EAE7C,IAAI,gBAAgB,MAAM,kBACzB,QACA,OAAO,WACP,OAAO,IACR;EAEA,IAAI,eACH,eAAO,IAAI,KACV,0CAA0C,OAAO,KAAK,KAAK,cAAc,EAC1E;OACM;GACN,IAAI;GAEJ,IAAI,OAAO,QAAQ;IAClB,sBAAsB,MAAM,kBAC3B,QACA,OAAO,WACP,OAAO,MACR;IAEA,IAAI,CAAC,qBACJ,MAAM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,KACL,KACA,MACA,MACqC;EACrC,MAAM,WAAqB,CAAC;EAE5B,IAAI,KAAK,cAAc,KAAK,WAC3B,SAAS,KAAK,WAAW;EAG1B,IAAI,KAAK,SAAS,KAAK,MACtB,SAAS,KAAK,MAAM;EAGrB,OAAO;GACN,SAAS,SAAS,SAAS;GAC3B;GACA,qBAAqB;EACtB;CACD;AACD;;AAGA,IAAM,6BAAN,cAAyCC,eAAO,QAAQ,SAAS;CAGhE,YACC,MACA,MAMA,MACC;EACD,MACC,IAAI,mCAAmC,GACvC,MACA;GACC,GAAG;GACH,eAAe;EAChB,GACA,IACD;CACD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,IAAa,qBAAb,cAAwCA,eAAO,kBAAkB;CAIhE,YACC,MACA,MACA,MACC;EACD,MAAM,EAAE,UAAU,SAAS,GAAG,eAAe;EAE7C,MAAM,kCAAkC,MAAM,CAAC,GAAG,UAAU;EAE5D,MAAM,WAAW,IAAI,2BACpB,GAAG,KAAK,YACR;GACC,OAAO,SAAS;GAChB,WAAW,QAAQ;GACnB,MAAM,KAAK;GACX,QAAQ,KAAK;EACd,GACA,EAAE,QAAQ,KAAK,CAChB;EAEA,KAAK,KAAK,SAAS;EAEnB,KAAK,gBAAgB,EAAE,IAAI,KAAK,GAAG,CAAC;CACrC;AACD"}
|
|
@@ -19,12 +19,6 @@ interface RailwayEnvironmentInputs {
|
|
|
19
19
|
interface RailwayEnvironmentOutputs extends RailwayEnvironmentInputs {
|
|
20
20
|
/** Railway-assigned environment UUID. */
|
|
21
21
|
environmentId: string;
|
|
22
|
-
/**
|
|
23
|
-
* Whether this environment already existed and was adopted (vs. created by us).
|
|
24
|
-
* `delete()` only removes environments we created. Absent on state written before
|
|
25
|
-
* this field existed, which is treated as adopted (the safe, non-destructive default).
|
|
26
|
-
*/
|
|
27
|
-
wasAdopted?: boolean;
|
|
28
22
|
}
|
|
29
23
|
/**
|
|
30
24
|
* Dynamic provider that resolves or creates a Railway environment by name.
|
|
@@ -42,11 +36,11 @@ declare class RailwayEnvironmentResourceProvider implements pulumi.dynamic.Resou
|
|
|
42
36
|
*/
|
|
43
37
|
create(inputs: RailwayEnvironmentInputs): Promise<pulumi.dynamic.CreateResult>;
|
|
44
38
|
read(_id: string, props: RailwayEnvironmentOutputs): Promise<pulumi.dynamic.ReadResult>;
|
|
45
|
-
update(_id: string,
|
|
39
|
+
update(_id: string, _olds: RailwayEnvironmentOutputs, news: RailwayEnvironmentInputs): Promise<pulumi.dynamic.UpdateResult>;
|
|
46
40
|
/**
|
|
47
|
-
* Deletes the environment
|
|
48
|
-
*
|
|
49
|
-
*
|
|
41
|
+
* Deletes the environment (which cascades its per-environment service instances).
|
|
42
|
+
* Protection of the shared production environment is the consumer's responsibility
|
|
43
|
+
* via the `protect` resource option, not provider logic.
|
|
50
44
|
*/
|
|
51
45
|
delete(_id: string, props: RailwayEnvironmentOutputs): Promise<void>;
|
|
52
46
|
diff(_id: string, olds: RailwayEnvironmentOutputs, news: RailwayEnvironmentInputs): Promise<pulumi.dynamic.DiffResult>;
|