@infracraft/pulumi 1.7.0 → 1.8.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/neon/branch.cjs +13 -1
- package/dist/neon/branch.cjs.map +1 -1
- package/dist/neon/branch.d.cts +13 -1
- package/dist/neon/branch.d.cts.map +1 -1
- package/dist/neon/branch.d.mts +13 -1
- package/dist/neon/branch.d.mts.map +1 -1
- package/dist/neon/branch.mjs +13 -1
- package/dist/neon/branch.mjs.map +1 -1
- package/dist/railway/environment.cjs +26 -5
- package/dist/railway/environment.cjs.map +1 -1
- package/dist/railway/environment.d.cts +13 -2
- package/dist/railway/environment.d.cts.map +1 -1
- package/dist/railway/environment.d.mts +13 -2
- package/dist/railway/environment.d.mts.map +1 -1
- package/dist/railway/environment.mjs +26 -5
- package/dist/railway/environment.mjs.map +1 -1
- package/dist/railway/service.cjs +6 -12
- package/dist/railway/service.cjs.map +1 -1
- package/dist/railway/service.d.cts.map +1 -1
- package/dist/railway/service.d.mts.map +1 -1
- package/dist/railway/service.mjs +6 -12
- package/dist/railway/service.mjs.map +1 -1
- package/dist/vercel/project.cjs +31 -14
- package/dist/vercel/project.cjs.map +1 -1
- package/dist/vercel/project.d.cts +33 -1
- package/dist/vercel/project.d.cts.map +1 -1
- package/dist/vercel/project.d.mts +33 -1
- package/dist/vercel/project.d.mts.map +1 -1
- package/dist/vercel/project.mjs +31 -15
- package/dist/vercel/project.mjs.map +1 -1
- package/package.json +1 -1
package/dist/neon/branch.cjs
CHANGED
|
@@ -23,6 +23,7 @@ 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;
|
|
26
27
|
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).`);
|
|
27
28
|
else _pulumi_pulumi.log.info(`Adopting existing Neon branch "${inputs.name}" (${branchId})`);
|
|
28
29
|
else {
|
|
@@ -36,7 +37,10 @@ var NeonBranchResourceProvider = class {
|
|
|
36
37
|
}
|
|
37
38
|
return {
|
|
38
39
|
id: branchId,
|
|
39
|
-
outs: {
|
|
40
|
+
outs: {
|
|
41
|
+
...inputs,
|
|
42
|
+
wasAdopted
|
|
43
|
+
}
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
46
|
async read(id, props) {
|
|
@@ -49,7 +53,15 @@ var NeonBranchResourceProvider = class {
|
|
|
49
53
|
}
|
|
50
54
|
};
|
|
51
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Deletes the branch only if we created it. Adopted branches (and state written
|
|
58
|
+
* before `wasAdopted` existed) are left untouched.
|
|
59
|
+
*/
|
|
52
60
|
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
|
+
}
|
|
53
65
|
const client = new require_neon_client.NeonClient(props.apiKey);
|
|
54
66
|
try {
|
|
55
67
|
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\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\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,WAC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,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\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,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;IAAE,GAAG;IAAQ;GAAW;EAAE;CACxD;CAEA,MAAM,KACL,IACA,O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A,EAAE,QAAQ,KAAK,CAChB;EAEA,KAAK,KAAK,SAAS;EAEnB,KAAK,gBAAgB,EAAE,IAAI,KAAK,GAAG,CAAC;CACrC;AACD"}
|
package/dist/neon/branch.d.cts
CHANGED
|
@@ -19,7 +19,15 @@ interface NeonBranchInputs {
|
|
|
19
19
|
parentName?: string;
|
|
20
20
|
}
|
|
21
21
|
/** Persisted state for the Neon branch. */
|
|
22
|
-
interface NeonBranchOutputs extends NeonBranchInputs {
|
|
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
|
+
}
|
|
23
31
|
/**
|
|
24
32
|
* Dynamic provider implementing CRUD for Neon branches.
|
|
25
33
|
*
|
|
@@ -31,6 +39,10 @@ interface NeonBranchOutputs extends NeonBranchInputs {}
|
|
|
31
39
|
declare class NeonBranchResourceProvider implements pulumi.dynamic.ResourceProvider {
|
|
32
40
|
create(inputs: NeonBranchInputs): Promise<pulumi.dynamic.CreateResult>;
|
|
33
41
|
read(id: string, props: NeonBranchOutputs): Promise<pulumi.dynamic.ReadResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes the branch only if we created it. Adopted branches (and state written
|
|
44
|
+
* before `wasAdopted` existed) are left untouched.
|
|
45
|
+
*/
|
|
34
46
|
delete(id: string, props: NeonBranchOutputs): Promise<void>;
|
|
35
47
|
diff(_id: string, olds: NeonBranchOutputs, news: NeonBranchInputs): Promise<pulumi.dynamic.DiffResult>;
|
|
36
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.d.cts","names":[],"sources":["../../src/neon/branch.ts"],"mappings":";;;;;;;UAMiB,g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,IAAA,EAAM,iBAAA;AAAA"}
|
package/dist/neon/branch.d.mts
CHANGED
|
@@ -19,7 +19,15 @@ interface NeonBranchInputs {
|
|
|
19
19
|
parentName?: string;
|
|
20
20
|
}
|
|
21
21
|
/** Persisted state for the Neon branch. */
|
|
22
|
-
interface NeonBranchOutputs extends NeonBranchInputs {
|
|
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
|
+
}
|
|
23
31
|
/**
|
|
24
32
|
* Dynamic provider implementing CRUD for Neon branches.
|
|
25
33
|
*
|
|
@@ -31,6 +39,10 @@ interface NeonBranchOutputs extends NeonBranchInputs {}
|
|
|
31
39
|
declare class NeonBranchResourceProvider implements pulumi.dynamic.ResourceProvider {
|
|
32
40
|
create(inputs: NeonBranchInputs): Promise<pulumi.dynamic.CreateResult>;
|
|
33
41
|
read(id: string, props: NeonBranchOutputs): Promise<pulumi.dynamic.ReadResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes the branch only if we created it. Adopted branches (and state written
|
|
44
|
+
* before `wasAdopted` existed) are left untouched.
|
|
45
|
+
*/
|
|
34
46
|
delete(id: string, props: NeonBranchOutputs): Promise<void>;
|
|
35
47
|
diff(_id: string, olds: NeonBranchOutputs, news: NeonBranchInputs): Promise<pulumi.dynamic.DiffResult>;
|
|
36
48
|
}
|
|
@@ -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;;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ourceProvider = 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;
|
|
24
25
|
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).`);
|
|
25
26
|
else pulumi.log.info(`Adopting existing Neon branch "${inputs.name}" (${branchId})`);
|
|
26
27
|
else {
|
|
@@ -34,7 +35,10 @@ var NeonBranchResourceProvider = class {
|
|
|
34
35
|
}
|
|
35
36
|
return {
|
|
36
37
|
id: branchId,
|
|
37
|
-
outs: {
|
|
38
|
+
outs: {
|
|
39
|
+
...inputs,
|
|
40
|
+
wasAdopted
|
|
41
|
+
}
|
|
38
42
|
};
|
|
39
43
|
}
|
|
40
44
|
async read(id, props) {
|
|
@@ -47,7 +51,15 @@ var NeonBranchResourceProvider = class {
|
|
|
47
51
|
}
|
|
48
52
|
};
|
|
49
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Deletes the branch only if we created it. Adopted branches (and state written
|
|
56
|
+
* before `wasAdopted` existed) are left untouched.
|
|
57
|
+
*/
|
|
50
58
|
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
|
+
}
|
|
51
63
|
const client = new NeonClient(props.apiKey);
|
|
52
64
|
try {
|
|
53
65
|
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\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\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,M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AAa,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\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,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,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AAM,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"}
|
|
@@ -13,6 +13,9 @@ const ENVIRONMENT_CREATE_MUTATION = `
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
`;
|
|
16
|
+
const ENVIRONMENT_DELETE_MUTATION = `
|
|
17
|
+
mutation($id: String!) { environmentDelete(id: $id) }
|
|
18
|
+
`;
|
|
16
19
|
const PROJECT_ENVIRONMENTS_QUERY = `
|
|
17
20
|
query($projectId: String!) {
|
|
18
21
|
project(id: $projectId) {
|
|
@@ -50,6 +53,7 @@ var RailwayEnvironmentResourceProvider = class {
|
|
|
50
53
|
async create(inputs) {
|
|
51
54
|
const client = new require_railway_client.RailwayClient(inputs.token);
|
|
52
55
|
let environmentId = await findEnvironmentId(client, inputs.projectId, inputs.name);
|
|
56
|
+
const wasAdopted = environmentId !== void 0;
|
|
53
57
|
if (environmentId) _pulumi_pulumi.log.info(`Adopting existing Railway environment "${inputs.name}" (${environmentId})`);
|
|
54
58
|
else {
|
|
55
59
|
let sourceEnvironmentId;
|
|
@@ -67,7 +71,8 @@ var RailwayEnvironmentResourceProvider = class {
|
|
|
67
71
|
}
|
|
68
72
|
const outs = {
|
|
69
73
|
...inputs,
|
|
70
|
-
environmentId
|
|
74
|
+
environmentId,
|
|
75
|
+
wasAdopted
|
|
71
76
|
};
|
|
72
77
|
return {
|
|
73
78
|
id: environmentId,
|
|
@@ -85,16 +90,32 @@ var RailwayEnvironmentResourceProvider = class {
|
|
|
85
90
|
}
|
|
86
91
|
};
|
|
87
92
|
}
|
|
88
|
-
async update(_id,
|
|
93
|
+
async update(_id, olds, news) {
|
|
89
94
|
const environmentId = await findEnvironmentId(new require_railway_client.RailwayClient(news.token), news.projectId, news.name);
|
|
90
95
|
if (!environmentId) throw new Error(`Railway environment "${news.name}" not found in project ${news.projectId}`);
|
|
91
96
|
return { outs: {
|
|
92
97
|
...news,
|
|
93
|
-
environmentId
|
|
98
|
+
environmentId,
|
|
99
|
+
wasAdopted: olds.wasAdopted
|
|
94
100
|
} };
|
|
95
101
|
}
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Deletes the environment only if we created it. Adopted environments (and
|
|
104
|
+
* state written before `wasAdopted` existed) are left untouched, so a feature
|
|
105
|
+
* env's destroy never removes the shared production environment.
|
|
106
|
+
*/
|
|
107
|
+
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
|
+
const client = new require_railway_client.RailwayClient(props.token);
|
|
113
|
+
try {
|
|
114
|
+
await client.query(ENVIRONMENT_DELETE_MUTATION, { id: props.environmentId });
|
|
115
|
+
_pulumi_pulumi.log.info(`Deleted Railway environment "${props.name}" (${props.environmentId})`);
|
|
116
|
+
} catch {
|
|
117
|
+
_pulumi_pulumi.log.warn(`Failed to delete Railway environment "${props.name}" (may already be deleted)`);
|
|
118
|
+
}
|
|
98
119
|
}
|
|
99
120
|
async diff(_id, olds, news) {
|
|
100
121
|
const replaces = [];
|
|
@@ -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\nconst ENVIRONMENT_CREATE_MUTATION = `\n mutation EnvironmentCreate($input: EnvironmentCreateInput!) {\n environmentCreate(input: $input) {\n id\n name\n }\n }\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\tasync delete(): Promise<void> {\n\t\tpulumi.log.warn(\n\t\t\t\"Railway environment deletion skipped — environments are not deleted by Pulumi\",\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,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,IAAI,MACT,+BAA+B,OAAO,OAAO,yBAAyB,OAAO,WAC9E;GAEF;GAeA,iBAAgB,MAbK,OAAO,MAEzB,6BAA6B,EAC/B,OAAO;IACN,WAAW,OAAO;IAClB,MAAM,OAAO;IAGb,oBAAoB;IACpB,GAAI,sBAAsB,EAAE,oBAAoB,IAAI,CAAC;GACtD,EACD,CAAC,GAEsB,kBAAkB;GAEzC,eAAO,IAAI,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E,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\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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I,KACV,yCAAyC,MAAM,KAAK,2BACrD;EACD;CACD;CAEA,MAAM,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,6 +19,12 @@ 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;
|
|
22
28
|
}
|
|
23
29
|
/**
|
|
24
30
|
* Dynamic provider that resolves or creates a Railway environment by name.
|
|
@@ -36,8 +42,13 @@ declare class RailwayEnvironmentResourceProvider implements pulumi.dynamic.Resou
|
|
|
36
42
|
*/
|
|
37
43
|
create(inputs: RailwayEnvironmentInputs): Promise<pulumi.dynamic.CreateResult>;
|
|
38
44
|
read(_id: string, props: RailwayEnvironmentOutputs): Promise<pulumi.dynamic.ReadResult>;
|
|
39
|
-
update(_id: string,
|
|
40
|
-
|
|
45
|
+
update(_id: string, olds: RailwayEnvironmentOutputs, news: RailwayEnvironmentInputs): Promise<pulumi.dynamic.UpdateResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Deletes the environment only if we created it. Adopted environments (and
|
|
48
|
+
* state written before `wasAdopted` existed) are left untouched, so a feature
|
|
49
|
+
* env's destroy never removes the shared production environment.
|
|
50
|
+
*/
|
|
51
|
+
delete(_id: string, props: RailwayEnvironmentOutputs): Promise<void>;
|
|
41
52
|
diff(_id: string, olds: RailwayEnvironmentOutputs, news: RailwayEnvironmentInputs): Promise<pulumi.dynamic.DiffResult>;
|
|
42
53
|
}
|
|
43
54
|
/** Options type for RailwayEnvironment — replaces Pulumi's native `provider` field. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.cts","names":[],"sources":["../../src/railway/environment.ts"],"mappings":";;;;;;;UAMU,wBAAA;;EAET,KAAA;EAFiC;EAKjC,SAAA;EALiC;EAQjC,IAAA;EAHA;EAMA,MAAA;AAAA;;UAIS,yBAAA,SAAkC,wBAAwB;EAA1D;EAET,
|
|
1
|
+
{"version":3,"file":"environment.d.cts","names":[],"sources":["../../src/railway/environment.ts"],"mappings":";;;;;;;UAMU,wBAAA;;EAET,KAAA;EAFiC;EAKjC,SAAA;EALiC;EAQjC,IAAA;EAHA;EAMA,MAAA;AAAA;;UAIS,yBAAA,SAAkC,wBAAwB;EAA1D;EAET,aAAA;;;;;;EAOA,UAAA;AAAA;AA2DD;;;;;AAAA,cAAa,kCAAA,YACD,MAAA,CAAO,OAAA,CAAQ,gBAAA;EA2ElB;;;;;;;;EAjEF,MAAA,CACL,MAAA,EAAQ,wBAAA,GACN,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,YAAA;EA6DpB,IAAA,CACL,GAAA,UACA,KAAA,EAAO,yBAAA,GACL,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,UAAA;EAkBpB,MAAA,CACL,GAAA,UACA,IAAA,EAAM,yBAAA,EACN,IAAA,EAAM,wBAAA,GACJ,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,YAAA;EAuDf;;;;;EA9BL,MAAA,CAAO,GAAA,UAAa,KAAA,EAAO,yBAAA,GAA4B,OAAA;EA0BvD,IAAA,CACL,GAAA,UACA,IAAA,EAAM,yBAAA,EACN,IAAA,EAAM,wBAAA,GACJ,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,UAAA;AAAA;;KA8CtB,yBAAA,GAA4B,IAAA,CAChC,MAAA,CAAO,wBAAA;EA7LN,sCAiMD,QAAA,EAAU,eAAA,EAhMC;EAmMX,OAAA,EAAS,cAAA;AAAA;;UAIO,sBAAA;EAxIR;EA0IR,IAAA,EAAM,MAAA,CAAO,KAAA;EAzIV;;;;;EAgJH,MAAA,GAAS,MAAA,CAAO,KAAK;AAAA;;;;;;;;;;;;;;;;;;;;;;;;AAnEe;AAiBpC;;cA+EY,kBAAA,SAA2B,MAAA,CAAO,iBAAA;EAjD9C;EAAA,SAmDgB,EAAA,EAAI,MAAA,CAAO,MAAA;cAG1B,IAAA,UACA,IAAA,EAAM,sBAAA,EACN,IAAA,EAAM,yBAAA;AAAA"}
|
|
@@ -19,6 +19,12 @@ 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;
|
|
22
28
|
}
|
|
23
29
|
/**
|
|
24
30
|
* Dynamic provider that resolves or creates a Railway environment by name.
|
|
@@ -36,8 +42,13 @@ declare class RailwayEnvironmentResourceProvider implements pulumi.dynamic.Resou
|
|
|
36
42
|
*/
|
|
37
43
|
create(inputs: RailwayEnvironmentInputs): Promise<pulumi.dynamic.CreateResult>;
|
|
38
44
|
read(_id: string, props: RailwayEnvironmentOutputs): Promise<pulumi.dynamic.ReadResult>;
|
|
39
|
-
update(_id: string,
|
|
40
|
-
|
|
45
|
+
update(_id: string, olds: RailwayEnvironmentOutputs, news: RailwayEnvironmentInputs): Promise<pulumi.dynamic.UpdateResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Deletes the environment only if we created it. Adopted environments (and
|
|
48
|
+
* state written before `wasAdopted` existed) are left untouched, so a feature
|
|
49
|
+
* env's destroy never removes the shared production environment.
|
|
50
|
+
*/
|
|
51
|
+
delete(_id: string, props: RailwayEnvironmentOutputs): Promise<void>;
|
|
41
52
|
diff(_id: string, olds: RailwayEnvironmentOutputs, news: RailwayEnvironmentInputs): Promise<pulumi.dynamic.DiffResult>;
|
|
42
53
|
}
|
|
43
54
|
/** Options type for RailwayEnvironment — replaces Pulumi's native `provider` field. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.mts","names":[],"sources":["../../src/railway/environment.ts"],"mappings":";;;;;;;UAMU,wBAAA;;EAET,KAAA;EAFiC;EAKjC,SAAA;EALiC;EAQjC,IAAA;EAHA;EAMA,MAAA;AAAA;;UAIS,yBAAA,SAAkC,wBAAwB;EAA1D;EAET,
|
|
1
|
+
{"version":3,"file":"environment.d.mts","names":[],"sources":["../../src/railway/environment.ts"],"mappings":";;;;;;;UAMU,wBAAA;;EAET,KAAA;EA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ATION = `
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
`;
|
|
14
|
+
const ENVIRONMENT_DELETE_MUTATION = `
|
|
15
|
+
mutation($id: String!) { environmentDelete(id: $id) }
|
|
16
|
+
`;
|
|
14
17
|
const PROJECT_ENVIRONMENTS_QUERY = `
|
|
15
18
|
query($projectId: String!) {
|
|
16
19
|
project(id: $projectId) {
|
|
@@ -48,6 +51,7 @@ var RailwayEnvironmentResourceProvider = class {
|
|
|
48
51
|
async create(inputs) {
|
|
49
52
|
const client = new RailwayClient(inputs.token);
|
|
50
53
|
let environmentId = await findEnvironmentId(client, inputs.projectId, inputs.name);
|
|
54
|
+
const wasAdopted = environmentId !== void 0;
|
|
51
55
|
if (environmentId) pulumi.log.info(`Adopting existing Railway environment "${inputs.name}" (${environmentId})`);
|
|
52
56
|
else {
|
|
53
57
|
let sourceEnvironmentId;
|
|
@@ -65,7 +69,8 @@ var RailwayEnvironmentResourceProvider = class {
|
|
|
65
69
|
}
|
|
66
70
|
const outs = {
|
|
67
71
|
...inputs,
|
|
68
|
-
environmentId
|
|
72
|
+
environmentId,
|
|
73
|
+
wasAdopted
|
|
69
74
|
};
|
|
70
75
|
return {
|
|
71
76
|
id: environmentId,
|
|
@@ -83,16 +88,32 @@ var RailwayEnvironmentResourceProvider = class {
|
|
|
83
88
|
}
|
|
84
89
|
};
|
|
85
90
|
}
|
|
86
|
-
async update(_id,
|
|
91
|
+
async update(_id, olds, news) {
|
|
87
92
|
const environmentId = await findEnvironmentId(new RailwayClient(news.token), news.projectId, news.name);
|
|
88
93
|
if (!environmentId) throw new Error(`Railway environment "${news.name}" not found in project ${news.projectId}`);
|
|
89
94
|
return { outs: {
|
|
90
95
|
...news,
|
|
91
|
-
environmentId
|
|
96
|
+
environmentId,
|
|
97
|
+
wasAdopted: olds.wasAdopted
|
|
92
98
|
} };
|
|
93
99
|
}
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Deletes the environment only if we created it. Adopted environments (and
|
|
102
|
+
* state written before `wasAdopted` existed) are left untouched, so a feature
|
|
103
|
+
* env's destroy never removes the shared production environment.
|
|
104
|
+
*/
|
|
105
|
+
async delete(_id, props) {
|
|
106
|
+
if (props.wasAdopted !== false) {
|
|
107
|
+
pulumi.log.warn(`Railway environment "${props.name}" deletion skipped — adopted (not created by Pulumi)`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const client = new RailwayClient(props.token);
|
|
111
|
+
try {
|
|
112
|
+
await client.query(ENVIRONMENT_DELETE_MUTATION, { id: props.environmentId });
|
|
113
|
+
pulumi.log.info(`Deleted Railway environment "${props.name}" (${props.environmentId})`);
|
|
114
|
+
} catch {
|
|
115
|
+
pulumi.log.warn(`Failed to delete Railway environment "${props.name}" (may already be deleted)`);
|
|
116
|
+
}
|
|
96
117
|
}
|
|
97
118
|
async diff(_id, olds, news) {
|
|
98
119
|
const replaces = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.mjs","names":[],"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 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\tasync delete(): Promise<void> {\n\t\tpulumi.log.warn(\n\t\t\t\"Railway environment deletion skipped — environments are not deleted by Pulumi\",\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,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ChE;CAEA,MAAM,OACL,KACA,OACA,MACuC;EAGvC,MAAM,gBAAgB,MAAM,kBAC3B,IAHkB,cAAc,KAAK,KAGhC,GACL,KAAK,WACL,KAAK,IACN;EAEA,IAAI,CAAC,eACJ,MAAM,IAAI,MACT,wBAAwB,KAAK,KAAK,yBAAyB,KAAK,WACjE;EAGD,OAAO,EAAE,MAAM;GAAE,GAAG;GAAM;EAAc,EAAE;CAC3C;CAEA,MAAM,SAAwB;EAC7B,OAAO,IAAI,KACV,+EACD;CACD;CAEA,MAAM,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,cAAyC,OAAO,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,cAAwC,OAAO,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.mjs","names":[],"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{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GACA,IACD;CACD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,IAAa,qBAAb,cAAwC,OAAO,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"}
|
package/dist/railway/service.cjs
CHANGED
|
@@ -87,9 +87,6 @@ const SERVICE_CONNECT = `
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
`;
|
|
90
|
-
const SERVICE_DELETE = `
|
|
91
|
-
mutation($id: String!) { serviceDelete(id: $id) }
|
|
92
|
-
`;
|
|
93
90
|
/**
|
|
94
91
|
* Applies service instance configuration (builder, commands, healthcheck).
|
|
95
92
|
* Retries without healthcheck fields if the first call fails.
|
|
@@ -200,16 +197,13 @@ var RailwayServiceResourceProvider = class {
|
|
|
200
197
|
};
|
|
201
198
|
}
|
|
202
199
|
/**
|
|
203
|
-
*
|
|
200
|
+
* Deletion is a no-op. A Railway service is a project-level resource shared
|
|
201
|
+
* across environments (forked environments adopt it by name), so a single
|
|
202
|
+
* environment's destroy must never delete it. Deleting the *environment*
|
|
203
|
+
* removes that environment's service instances instead.
|
|
204
204
|
*/
|
|
205
|
-
async delete(
|
|
206
|
-
|
|
207
|
-
try {
|
|
208
|
-
await client.query(SERVICE_DELETE, { id });
|
|
209
|
-
_pulumi_pulumi.log.info(`Deleted Railway service "${props.name}" (${id})`);
|
|
210
|
-
} catch {
|
|
211
|
-
_pulumi_pulumi.log.warn(`Failed to delete Railway service "${props.name}" (${id}) — may already be deleted`);
|
|
212
|
-
}
|
|
205
|
+
async delete() {
|
|
206
|
+
_pulumi_pulumi.log.warn("Railway service deletion skipped — services are project-level; delete the environment to remove its instances");
|
|
213
207
|
}
|
|
214
208
|
/**
|
|
215
209
|
* Compares old and new inputs to determine what changed.
|