effect-pulumi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +283 -0
- package/dist/index.cjs +247 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +366 -0
- package/dist/index.d.ts +366 -0
- package/dist/index.js +211 -0
- package/dist/index.js.map +1 -0
- package/package.json +90 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Piers Karsenbarg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# effect-pulumi
|
|
2
|
+
|
|
3
|
+
[](https://github.com/pierskarsenbarg/effect-pulumi/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
Gives Pulumi programs Effect's composability — typed errors, sequenced
|
|
6
|
+
dependent resources, and structured result inspection — without hand-wrapping
|
|
7
|
+
every resource constructor.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
Mixing Effect and Pulumi by hand means wrapping every constructor and every
|
|
12
|
+
data-source call yourself:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
const bucket = yield* Effect.try({
|
|
16
|
+
try: () => new aws.s3.Bucket("assets", { forceDestroy: true }),
|
|
17
|
+
catch: (cause) => new InfraError({ cause }),
|
|
18
|
+
});
|
|
19
|
+
const ami = yield* Effect.tryPromise({
|
|
20
|
+
try: () => aws.ec2.getAmi({ mostRecent: true, owners: ["amazon"] }),
|
|
21
|
+
catch: (cause) => new InfraError({ cause }),
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`effectify` wraps the provider package once, and both collapse to plain calls
|
|
26
|
+
with a shared, typed error channel:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const eaws = effectify(aws);
|
|
30
|
+
|
|
31
|
+
const bucket = yield* eaws.s3.Bucket("assets", { forceDestroy: true });
|
|
32
|
+
const ami = yield* eaws.ec2.getAmi({ mostRecent: true, owners: ["amazon"] });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm install effect-pulumi
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Requires Node.js ≥ 22 (the floor `@pulumi/pulumi` itself sets). The peer
|
|
42
|
+
ranges are `@pulumi/pulumi ^3.0.0` and `effect ^3.0.0`, currently verified
|
|
43
|
+
against `@pulumi/pulumi` 3.255 and `effect` 3.22.
|
|
44
|
+
|
|
45
|
+
`@pulumi/pulumi` and `effect` are peer dependencies — this library extends
|
|
46
|
+
your Pulumi and Effect runtimes, so it must use the same copies you do rather
|
|
47
|
+
than bundle its own. npm 7+ installs peers automatically; on pnpm or Yarn you
|
|
48
|
+
may need them explicitly:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
npm install @pulumi/pulumi effect
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Ships as dual ESM + CommonJS, so it works from a conventional CJS Pulumi
|
|
55
|
+
program as well as an ESM one:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { effectify } from "effect-pulumi"; // ESM
|
|
59
|
+
const { effectify } = require("effect-pulumi"); // CJS
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick start
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import * as aws from "@pulumi/aws";
|
|
66
|
+
import { Effect } from "effect";
|
|
67
|
+
import { effectify, fromOutput, fromOutputs } from "effect-pulumi";
|
|
68
|
+
|
|
69
|
+
const eaws = effectify(aws); // wrap the provider package once
|
|
70
|
+
|
|
71
|
+
const program = Effect.gen(function* () {
|
|
72
|
+
const bucket = yield* eaws.s3.Bucket("assets", { forceDestroy: true });
|
|
73
|
+
// ^ Effect<aws.s3.Bucket, PulumiError> — no Effect.sync / Effect.try
|
|
74
|
+
|
|
75
|
+
const object = yield* eaws.s3.BucketObject("readme", {
|
|
76
|
+
bucket: fromOutput(bucket.id), // an Effect in an args slot, auto-resolved
|
|
77
|
+
key: "readme.txt",
|
|
78
|
+
content: "hello",
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return yield* fromOutputs({ id: bucket.id, key: object.key });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// In a classic (ESM) Pulumi project this is the whole entrypoint: run the
|
|
85
|
+
// Effect at module load and export the results as stack outputs.
|
|
86
|
+
export const { id, key } = await Effect.runPromise(program);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Alternatively, hand `program` to the [Automation API](#automation-api) as an
|
|
90
|
+
inline program and deploy it from the same process.
|
|
91
|
+
|
|
92
|
+
The full version of the program above lives in
|
|
93
|
+
[`test/s3-bucket-program.ts`](test/s3-bucket-program.ts). It sits in `test/`
|
|
94
|
+
rather than `examples/` because it is a fixture rather than a project you can
|
|
95
|
+
run — its only consumer today is the mocked suite in `npm test`, exercising a
|
|
96
|
+
real `@pulumi/aws` package under Pulumi's mocks, no cloud account involved.
|
|
97
|
+
|
|
98
|
+
For examples you can actually deploy, see [`examples/`](examples/) — those use
|
|
99
|
+
`@pulumi/random`, whose resources take no inputs from one another, so they
|
|
100
|
+
don't show `fromOutput` or an Effect in an args slot. For that, see
|
|
101
|
+
[`test/random-password-file-program.ts`](test/random-password-file-program.ts):
|
|
102
|
+
a `RandomPassword`'s Output flows into a `local.File`'s args, and it's
|
|
103
|
+
deployed for real by `npm run test:live` — no cloud credentials needed, since
|
|
104
|
+
`@pulumi/local` only touches the local filesystem.
|
|
105
|
+
|
|
106
|
+
## What `effectify` does
|
|
107
|
+
|
|
108
|
+
`effectify(mod)` returns a lazy, memoized proxy over a provider package:
|
|
109
|
+
|
|
110
|
+
| Export kind | Result |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| `CustomResource` subclass | `(name, args, opts?) => Effect<R, PulumiError>`, and any **top-level** args field may additionally be an `Effect` (several resolve concurrently) |
|
|
113
|
+
| `ComponentResource` subclass | `(name, args, opts?) => Effect<R, PulumiError>`, args passed through verbatim — never auto-lifted |
|
|
114
|
+
| Namespace object (`aws.s3`) | Recursively proxied, lazily |
|
|
115
|
+
| Invoke function (`aws.s3.getBucket`) | Returns `Effect<R, PulumiError>` instead of `Promise<R>` |
|
|
116
|
+
| `*Output` invoke variant (`getBucketOutput`) | Passed through untouched (returns an `Output`, as upstream) |
|
|
117
|
+
| Enums, plain values, sync functions | Passed through untouched |
|
|
118
|
+
|
|
119
|
+
Semantics worth knowing:
|
|
120
|
+
|
|
121
|
+
- **Outputs still work exactly as in vanilla Pulumi.** `effectify` only
|
|
122
|
+
*additionally* accepts `Effect`s; passing a bare `Output<T>` or `Input<T>`
|
|
123
|
+
needs no unwrapping or rewrapping.
|
|
124
|
+
- **Statics survive the wrapping.** `eaws.s3.Bucket.get(name, id)` (adopt an
|
|
125
|
+
existing resource), `isInstance`, and any other codegen'd static forward to
|
|
126
|
+
the original class — `instanceof` works too — so the wrapped package can be
|
|
127
|
+
the only import a program needs.
|
|
128
|
+
- **Component args are never lifted.** Component args aren't guaranteed to be
|
|
129
|
+
`Input<T>`-shaped the way codegen'd `CustomResource` args are — a component
|
|
130
|
+
may do synchronous work on a bare primitive in its constructor — so passing
|
|
131
|
+
an `Effect` where a component expects a primitive is a type error. See
|
|
132
|
+
[Component resources](#component-resources) for the patterns this implies.
|
|
133
|
+
- **Invokes start when you call them.** Whether a function is async is only
|
|
134
|
+
knowable by calling it, so `eaws.getAmi(args)` fires the invoke immediately
|
|
135
|
+
and hands back an Effect that resolves the already-in-flight call — the
|
|
136
|
+
failure still lands in the typed error channel, but `Effect.retry` re-awaits
|
|
137
|
+
the same call rather than re-invoking. To re-invoke per attempt, defer the
|
|
138
|
+
call site: `Effect.suspend(() => eaws.getAmi(args))`.
|
|
139
|
+
|
|
140
|
+
Resource registration stays synchronous under the hood; `Effect.try` runs its
|
|
141
|
+
thunk immediately. This removes wrapper boilerplate, not Pulumi's execution
|
|
142
|
+
model.
|
|
143
|
+
|
|
144
|
+
## Component resources
|
|
145
|
+
|
|
146
|
+
Component resources are fully supported as *consumers*: `effectify` detects
|
|
147
|
+
any class extending `pulumi.ComponentResource` — your own, or those in a
|
|
148
|
+
component-based package like `@pulumi/awsx` — and wraps its constructor into
|
|
149
|
+
an Effect factory, exactly like a custom resource. Construction errors land
|
|
150
|
+
in the typed error channel, and the component sequences with `yield*` like
|
|
151
|
+
everything else.
|
|
152
|
+
|
|
153
|
+
What differs is the args object. Custom resource args can carry `Effect`
|
|
154
|
+
fields because codegen guarantees they are all `Input<T>`-shaped, so
|
|
155
|
+
substituting a resolved value is always legal. Component args are
|
|
156
|
+
hand-authored: a component may take a bare `replicas: number` and do
|
|
157
|
+
synchronous arithmetic on it inside its constructor, and an `Effect` silently
|
|
158
|
+
swapped in there would break it. So for components, `effectify` refuses at
|
|
159
|
+
the type level instead of guessing — resolve your Effects first, then
|
|
160
|
+
construct with plain values:
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
const eawsx = effectify(awsx);
|
|
164
|
+
|
|
165
|
+
const program = Effect.gen(function* () {
|
|
166
|
+
// ✗ type error — component args are never auto-lifted:
|
|
167
|
+
// eawsx.ecs.Cluster("app", { vpcId: fromOutput(vpc.id) })
|
|
168
|
+
|
|
169
|
+
// ✓ resolve first, then pass a plain value (or just pass the Output —
|
|
170
|
+
// Input<T>-typed component args accept those as in vanilla Pulumi):
|
|
171
|
+
const vpcId = yield* fromOutput(vpc.id);
|
|
172
|
+
const cluster = yield* eawsx.ecs.Cluster("app", { vpcId });
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
*Authoring* a component is different: a `ComponentResource` constructor is
|
|
177
|
+
synchronous, so you cannot `yield*` inside it. Write a component's internals
|
|
178
|
+
in plain Pulumi — its children are ordinary constructor calls — and use
|
|
179
|
+
`effectify` at the program level, where composition actually happens. The
|
|
180
|
+
wrapped and unwrapped worlds interoperate freely: a component built from raw
|
|
181
|
+
Pulumi children can itself be constructed through an effectified package,
|
|
182
|
+
and its `Output` properties flow into `fromOutput`/`fromOutputs` like any
|
|
183
|
+
other resource's.
|
|
184
|
+
|
|
185
|
+
## Automation API
|
|
186
|
+
|
|
187
|
+
`deploy` runs `createOrSelectStack` → config → `up` as one pipeline, returning
|
|
188
|
+
the stack handle alongside the result so callers can tear down without
|
|
189
|
+
re-selecting.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
const exit = await Effect.runPromiseExit(
|
|
193
|
+
deploy({
|
|
194
|
+
stackName,
|
|
195
|
+
projectName,
|
|
196
|
+
program: inlineProgram("dev"),
|
|
197
|
+
up: { onOutput: (out) => process.stdout.write(out) },
|
|
198
|
+
})
|
|
199
|
+
);
|
|
200
|
+
// Exit/Cause instead of a thrown, stringified error
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Every operation forwards the matching Pulumi options type — `UpOptions`,
|
|
204
|
+
`PreviewOptions`, `RefreshOptions`, `DestroyOptions`, `RemoveOptions`. Pass
|
|
205
|
+
`onOutput` to stream the CLI's progress; without it a multi-minute deploy
|
|
206
|
+
prints nothing until it finishes. Stacks can be inline programs
|
|
207
|
+
(`projectName` + `program`) or an existing project on disk (`workDir`).
|
|
208
|
+
|
|
209
|
+
Previewing is opt-in via `preview: true` (or a `PreviewOptions` object), and
|
|
210
|
+
its result comes back on `DeployResult.preview`. It is off by default because
|
|
211
|
+
a preview is a full engine run against the provider, so previewing and then
|
|
212
|
+
immediately upping does the work twice — and `up` surfaces the same failures.
|
|
213
|
+
|
|
214
|
+
Teardown is two steps. `destroyStack` removes the resources but leaves the
|
|
215
|
+
stack registered with the backend; `teardownStack` destroys and then deletes
|
|
216
|
+
it, which is what you want for per-run stacks. `RemoveOptions.force` deletes a
|
|
217
|
+
stack while leaving its resources alive and billing — it is reachable, but it
|
|
218
|
+
orphans them.
|
|
219
|
+
|
|
220
|
+
## Handling failures
|
|
221
|
+
|
|
222
|
+
Failures are values with types, not stringified stack traces. `PulumiError`
|
|
223
|
+
covers resource construction and Output resolution; `AutomationError` adds
|
|
224
|
+
the lifecycle `stage` it came from. Both derive `.message` from the
|
|
225
|
+
underlying cause, so they read well even outside Effect.
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import { Effect } from "effect";
|
|
229
|
+
import { deploy } from "effect-pulumi";
|
|
230
|
+
|
|
231
|
+
const guarded = deploy({ stackName, projectName, program }).pipe(
|
|
232
|
+
// Transient engine failures during `up` are worth another attempt; a
|
|
233
|
+
// failure creating the stack or setting config is not.
|
|
234
|
+
Effect.retry({ times: 2, while: (error) => error.stage === "up" }),
|
|
235
|
+
Effect.catchTag("AutomationError", (error) =>
|
|
236
|
+
Effect.fail(new Error(`deploy failed at ${error.stage}: ${error.message}`))
|
|
237
|
+
)
|
|
238
|
+
);
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The same works inside a program: `Effect.catchTag("PulumiError", …)` around a
|
|
242
|
+
resource, or `Effect.exit` / `runPromiseExit` at the edge to inspect the full
|
|
243
|
+
`Cause`.
|
|
244
|
+
|
|
245
|
+
## API
|
|
246
|
+
|
|
247
|
+
| Export | What it does |
|
|
248
|
+
| --- | --- |
|
|
249
|
+
| `effectify(mod)` | Wrap a provider package (or any namespace) once; see the table above |
|
|
250
|
+
| `fromOutput(output)` | `Output<T>` → `Effect<T, PulumiError>`; resolves to the unknown sentinel during `preview` instead of throwing |
|
|
251
|
+
| `fromOutputs(record)` | Record of Outputs → `Effect` of the resolved record |
|
|
252
|
+
| `deploy(opts)` | Select/create stack → apply config → optional preview → `up`; returns `{ stack, result, preview? }` |
|
|
253
|
+
| `createOrSelectStack(opts)` | Inline (`projectName` + `program`) or local (`workDir`) stack |
|
|
254
|
+
| `setStackConfig(stack, config)` | Apply a whole config map in one `setAllConfig` round-trip |
|
|
255
|
+
| `previewStack(stack, opts?)` | `pulumi preview`, returning the `PreviewResult` |
|
|
256
|
+
| `upStack(stack, opts?)` | `pulumi up`, returning the `UpResult` |
|
|
257
|
+
| `refreshStack(stack, opts?)` | Re-sync state from the actual cloud resources |
|
|
258
|
+
| `stackOutputs(stack)` | Read current outputs without running an update |
|
|
259
|
+
| `destroyStack(stack, opts?)` | Destroy resources; the stack stays registered |
|
|
260
|
+
| `removeStack(stack, opts?)` | Delete the stack from the backend |
|
|
261
|
+
| `teardownStack(stack, opts?)` | Destroy then remove — skips the remove if the destroy failed |
|
|
262
|
+
| `PulumiError` | Construction / Output-resolution failure; carries `cause` |
|
|
263
|
+
| `AutomationError` | Lifecycle failure; carries `stage` and `cause` |
|
|
264
|
+
|
|
265
|
+
## Scripts
|
|
266
|
+
|
|
267
|
+
| Command | What it does |
|
|
268
|
+
| --- | --- |
|
|
269
|
+
| `npm run build` | Build dual ESM + CJS (`tsup`) with declarations to `dist/` |
|
|
270
|
+
| `npm run typecheck` | Type-check everything, including tests and examples |
|
|
271
|
+
| `npm run lint` | Lint with `oxlint` (`npm run lint:fix` applies safe fixes) |
|
|
272
|
+
| `npm run format` | Format with `oxfmt` (`npm run format:check` asserts instead) |
|
|
273
|
+
| `npm run check` | `typecheck` + `lint` + `format:check`, the pre-commit sweep |
|
|
274
|
+
| `npm test` | Unit + mocked-provider tests. No credentials needed |
|
|
275
|
+
| `npm run test:package` | Builds, packs a tarball and consumes it from ESM and CJS projects |
|
|
276
|
+
| `npm run test:live` | Deploys `test/s3-bucket-program.ts` against real AWS, then destroys it |
|
|
277
|
+
|
|
278
|
+
`npm test` never runs the live harness: it's excluded in `vitest.config.ts`
|
|
279
|
+
and additionally gated on `EFFECT_PULUMI_RUN_LIVE_TESTS=1`. The live harness
|
|
280
|
+
picks up credentials from the environment the normal way each provider expects
|
|
281
|
+
(e.g. `AWS_PROFILE` / `AWS_ACCESS_KEY_ID`), and uses
|
|
282
|
+
`Effect.acquireRelease` + `Effect.scoped` so the stack is destroyed even when
|
|
283
|
+
an assertion fails.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var effect = require('effect');
|
|
4
|
+
var pulumi2 = require('@pulumi/pulumi');
|
|
5
|
+
var index_js = require('@pulumi/pulumi/automation/index.js');
|
|
6
|
+
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var pulumi2__namespace = /*#__PURE__*/_interopNamespace(pulumi2);
|
|
26
|
+
|
|
27
|
+
// src/errors.ts
|
|
28
|
+
var describeCause = (cause) => cause instanceof Error ? cause.message : String(cause);
|
|
29
|
+
var PulumiError = class extends effect.Data.TaggedError("PulumiError") {
|
|
30
|
+
/** Derived so anything reading `.message` — plain logging, test failure
|
|
31
|
+
* output, non-Effect error handling — sees the underlying failure instead
|
|
32
|
+
* of an empty string. */
|
|
33
|
+
get message() {
|
|
34
|
+
return describeCause(this.cause);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var AutomationError = class extends effect.Data.TaggedError("AutomationError") {
|
|
38
|
+
/** `"<stage> failed: <cause>"` — the stage is included because the cause
|
|
39
|
+
* alone rarely says which operation produced it. */
|
|
40
|
+
get message() {
|
|
41
|
+
return `${this.stage} failed: ${describeCause(this.cause)}`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var fromOutput = (output) => effect.Effect.tryPromise({
|
|
45
|
+
try: () => output.promise(true),
|
|
46
|
+
catch: (cause) => new PulumiError({ cause })
|
|
47
|
+
});
|
|
48
|
+
var fromOutputs = (outputs) => fromOutput(pulumi2__namespace.all(outputs));
|
|
49
|
+
var isResourceConstructor = (value) => typeof value === "function" && (value === pulumi2__namespace.Resource || value.prototype instanceof pulumi2__namespace.Resource);
|
|
50
|
+
var isComponentResourceConstructor = (Ctor) => Ctor === pulumi2__namespace.ComponentResource || Ctor.prototype instanceof pulumi2__namespace.ComponentResource;
|
|
51
|
+
var isNamespace = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52
|
+
var isArgsObject = (value) => isNamespace(value);
|
|
53
|
+
var isPromiseLike = (value) => typeof value === "object" && value !== null && typeof value.then === "function";
|
|
54
|
+
var proxyCache = /* @__PURE__ */ new WeakMap();
|
|
55
|
+
var isEffect = (value) => effect.Effect.isEffect(value);
|
|
56
|
+
function resolveLiftedArgs(args) {
|
|
57
|
+
if (!isArgsObject(args)) {
|
|
58
|
+
return effect.Effect.succeed(args);
|
|
59
|
+
}
|
|
60
|
+
const effectEntries = Object.entries(args).filter(([, v]) => isEffect(v));
|
|
61
|
+
if (effectEntries.length === 0) {
|
|
62
|
+
return effect.Effect.succeed(args);
|
|
63
|
+
}
|
|
64
|
+
return effect.Effect.map(
|
|
65
|
+
effect.Effect.all(
|
|
66
|
+
effectEntries.map(
|
|
67
|
+
([key, effectValue]) => effect.Effect.map(
|
|
68
|
+
effectValue,
|
|
69
|
+
(resolved) => [key, resolved]
|
|
70
|
+
)
|
|
71
|
+
),
|
|
72
|
+
{ concurrency: "unbounded" }
|
|
73
|
+
),
|
|
74
|
+
(resolved) => ({ ...args, ...Object.fromEntries(resolved) })
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function wrapCustomResourceCtor(Ctor) {
|
|
78
|
+
return (name, args, opts) => effect.Effect.gen(function* () {
|
|
79
|
+
const resolvedArgs = yield* resolveLiftedArgs(args);
|
|
80
|
+
return yield* effect.Effect.try({
|
|
81
|
+
try: () => new Ctor(name, resolvedArgs, opts),
|
|
82
|
+
catch: (cause) => new PulumiError({ cause })
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function wrapComponentResourceCtor(Ctor) {
|
|
87
|
+
return (name, args, opts) => effect.Effect.try({
|
|
88
|
+
try: () => new Ctor(name, args, opts),
|
|
89
|
+
catch: (cause) => new PulumiError({ cause })
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
var withStatics = (factory, Ctor) => new Proxy(factory, {
|
|
93
|
+
get: (target, prop, receiver) => Reflect.has(target, prop) ? Reflect.get(target, prop, receiver) : Reflect.get(Ctor, prop),
|
|
94
|
+
has: (target, prop) => Reflect.has(target, prop) || Reflect.has(Ctor, prop)
|
|
95
|
+
});
|
|
96
|
+
function wrapResourceCtor(Ctor) {
|
|
97
|
+
const factory = isComponentResourceConstructor(Ctor) ? wrapComponentResourceCtor(Ctor) : wrapCustomResourceCtor(
|
|
98
|
+
Ctor
|
|
99
|
+
);
|
|
100
|
+
return withStatics(factory, Ctor);
|
|
101
|
+
}
|
|
102
|
+
function wrapInvokeLike(fn) {
|
|
103
|
+
return new Proxy(fn, {
|
|
104
|
+
apply(target, thisArg, args) {
|
|
105
|
+
const result = Reflect.apply(target, thisArg, args);
|
|
106
|
+
if (!isPromiseLike(result)) {
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
result.then(void 0, () => {
|
|
110
|
+
});
|
|
111
|
+
return effect.Effect.tryPromise({
|
|
112
|
+
try: () => result,
|
|
113
|
+
catch: (cause) => new PulumiError({ cause })
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
var wrapperCache = /* @__PURE__ */ new WeakMap();
|
|
119
|
+
function effectifyValue(value) {
|
|
120
|
+
if (isResourceConstructor(value)) {
|
|
121
|
+
const cached = wrapperCache.get(value);
|
|
122
|
+
if (cached) return cached;
|
|
123
|
+
const wrapped = wrapResourceCtor(value);
|
|
124
|
+
wrapperCache.set(value, wrapped);
|
|
125
|
+
return wrapped;
|
|
126
|
+
}
|
|
127
|
+
if (typeof value === "function") {
|
|
128
|
+
const cached = wrapperCache.get(value);
|
|
129
|
+
if (cached) return cached;
|
|
130
|
+
const wrapped = wrapInvokeLike(value);
|
|
131
|
+
wrapperCache.set(value, wrapped);
|
|
132
|
+
return wrapped;
|
|
133
|
+
}
|
|
134
|
+
if (isNamespace(value)) {
|
|
135
|
+
return effectifyInner(value);
|
|
136
|
+
}
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
function effectifyInner(mod) {
|
|
140
|
+
const cached = proxyCache.get(mod);
|
|
141
|
+
if (cached) return cached;
|
|
142
|
+
const proxy = new Proxy(/* @__PURE__ */ Object.create(null), {
|
|
143
|
+
get(_target, prop) {
|
|
144
|
+
return effectifyValue(Reflect.get(mod, prop));
|
|
145
|
+
},
|
|
146
|
+
has(_target, prop) {
|
|
147
|
+
return Reflect.has(mod, prop);
|
|
148
|
+
},
|
|
149
|
+
ownKeys() {
|
|
150
|
+
return Reflect.ownKeys(mod);
|
|
151
|
+
},
|
|
152
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
153
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);
|
|
154
|
+
if (!descriptor) return void 0;
|
|
155
|
+
return {
|
|
156
|
+
value: effectifyValue(Reflect.get(mod, prop)),
|
|
157
|
+
enumerable: descriptor.enumerable,
|
|
158
|
+
configurable: true,
|
|
159
|
+
writable: true
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
set() {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
proxyCache.set(mod, proxy);
|
|
167
|
+
return proxy;
|
|
168
|
+
}
|
|
169
|
+
function effectify(mod) {
|
|
170
|
+
return effectifyInner(mod);
|
|
171
|
+
}
|
|
172
|
+
var isLocal = (opts) => "workDir" in opts;
|
|
173
|
+
var createOrSelectStack = (opts) => effect.Effect.tryPromise({
|
|
174
|
+
try: () => isLocal(opts) ? index_js.LocalWorkspace.createOrSelectStack(
|
|
175
|
+
{ stackName: opts.stackName, workDir: opts.workDir },
|
|
176
|
+
opts.workspaceOptions
|
|
177
|
+
) : index_js.LocalWorkspace.createOrSelectStack(
|
|
178
|
+
{
|
|
179
|
+
stackName: opts.stackName,
|
|
180
|
+
projectName: opts.projectName,
|
|
181
|
+
program: opts.program
|
|
182
|
+
},
|
|
183
|
+
opts.workspaceOptions
|
|
184
|
+
),
|
|
185
|
+
catch: (cause) => new AutomationError({ stage: "createOrSelectStack", cause })
|
|
186
|
+
});
|
|
187
|
+
var setStackConfig = (stack, config) => !config || Object.keys(config).length === 0 ? effect.Effect.void : effect.Effect.tryPromise({
|
|
188
|
+
try: () => stack.setAllConfig(config),
|
|
189
|
+
catch: (cause) => new AutomationError({ stage: "setConfig", cause })
|
|
190
|
+
});
|
|
191
|
+
var previewStack = (stack, opts) => effect.Effect.tryPromise({
|
|
192
|
+
try: () => stack.preview(opts),
|
|
193
|
+
catch: (cause) => new AutomationError({ stage: "preview", cause })
|
|
194
|
+
});
|
|
195
|
+
var upStack = (stack, opts) => effect.Effect.tryPromise({
|
|
196
|
+
try: () => stack.up(opts),
|
|
197
|
+
catch: (cause) => new AutomationError({ stage: "up", cause })
|
|
198
|
+
});
|
|
199
|
+
var refreshStack = (stack, opts) => effect.Effect.tryPromise({
|
|
200
|
+
try: () => stack.refresh(opts),
|
|
201
|
+
catch: (cause) => new AutomationError({ stage: "refresh", cause })
|
|
202
|
+
});
|
|
203
|
+
var stackOutputs = (stack) => effect.Effect.tryPromise({
|
|
204
|
+
try: () => stack.outputs(),
|
|
205
|
+
catch: (cause) => new AutomationError({ stage: "outputs", cause })
|
|
206
|
+
});
|
|
207
|
+
var destroyStack = (stack, opts) => effect.Effect.tryPromise({
|
|
208
|
+
try: () => stack.destroy(opts),
|
|
209
|
+
catch: (cause) => new AutomationError({ stage: "destroy", cause })
|
|
210
|
+
});
|
|
211
|
+
var removeStack = (stack, opts) => effect.Effect.tryPromise({
|
|
212
|
+
try: () => stack.workspace.removeStack(stack.name, opts),
|
|
213
|
+
catch: (cause) => new AutomationError({ stage: "removeStack", cause })
|
|
214
|
+
});
|
|
215
|
+
var teardownStack = (stack, opts) => effect.Effect.gen(function* () {
|
|
216
|
+
const result = yield* destroyStack(stack, opts?.destroy);
|
|
217
|
+
yield* removeStack(stack, opts?.remove);
|
|
218
|
+
return result;
|
|
219
|
+
});
|
|
220
|
+
var deploy = (opts) => effect.Effect.gen(function* () {
|
|
221
|
+
const stack = yield* createOrSelectStack(opts);
|
|
222
|
+
yield* setStackConfig(stack, opts.config);
|
|
223
|
+
const preview = opts.preview ? yield* previewStack(
|
|
224
|
+
stack,
|
|
225
|
+
typeof opts.preview === "boolean" ? void 0 : opts.preview
|
|
226
|
+
) : void 0;
|
|
227
|
+
const result = yield* upStack(stack, opts.up);
|
|
228
|
+
return { stack, result, preview };
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
exports.AutomationError = AutomationError;
|
|
232
|
+
exports.PulumiError = PulumiError;
|
|
233
|
+
exports.createOrSelectStack = createOrSelectStack;
|
|
234
|
+
exports.deploy = deploy;
|
|
235
|
+
exports.destroyStack = destroyStack;
|
|
236
|
+
exports.effectify = effectify;
|
|
237
|
+
exports.fromOutput = fromOutput;
|
|
238
|
+
exports.fromOutputs = fromOutputs;
|
|
239
|
+
exports.previewStack = previewStack;
|
|
240
|
+
exports.refreshStack = refreshStack;
|
|
241
|
+
exports.removeStack = removeStack;
|
|
242
|
+
exports.setStackConfig = setStackConfig;
|
|
243
|
+
exports.stackOutputs = stackOutputs;
|
|
244
|
+
exports.teardownStack = teardownStack;
|
|
245
|
+
exports.upStack = upStack;
|
|
246
|
+
//# sourceMappingURL=index.cjs.map
|
|
247
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/output-bridge.ts","../src/effectify.ts","../src/automation.ts"],"names":["Data","Effect","pulumi","pulumi2","LocalWorkspace"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,aAAA,GAAgB,CAAC,KAAA,KACrB,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAgBhD,IAAM,WAAA,GAAN,cAA0BA,WAAA,CAAK,WAAA,CAAY,aAAa,CAAA,CAI5D;AAAA;AAAA;AAAA;AAAA,EAID,IAAI,OAAA,GAAkB;AACpB,IAAA,OAAO,aAAA,CAAc,KAAK,KAAK,CAAA;AAAA,EACjC;AACF;AAoBO,IAAM,eAAA,GAAN,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,EAAA,OAAO,WAAA,CAAY,KAAA,EAAO,IAAA,EAAM,MAAM,CAAA;AACtC,EAAA,OAAO,MAAA;AACT,CAAC;AAyDI,IAAM,MAAA,GAAS,CACpB,IAAA,KAEAA,aAAAA,CAAO,IAAI,aAAa;AACtB,EAAA,MAAM,KAAA,GAAQ,OAAO,mBAAA,CAAoB,IAAI,CAAA;AAC7C,EAAA,OAAO,cAAA,CAAe,KAAA,EAAO,IAAA,CAAK,MAAM,CAAA;AAExC,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,OAAA,GACjB,OAAO,YAAA;AAAA,IACL,KAAA;AAAA,IACA,OAAO,IAAA,CAAK,OAAA,KAAY,SAAA,GAAY,SAAY,IAAA,CAAK;AAAA,GACvD,GACA,MAAA;AAEJ,EAAA,MAAM,MAAA,GAAS,OAAO,OAAA,CAAQ,KAAA,EAAO,KAAK,EAAE,CAAA;AAC5C,EAAA,OAAO,EAAE,KAAA,EAAO,MAAA,EAAQ,OAAA,EAAQ;AAClC,CAAC","file":"index.cjs","sourcesContent":["import { Data } from \"effect\";\n\nconst describeCause = (cause: unknown): string =>\n cause instanceof Error ? cause.message : String(cause);\n\n/**\n * Any synchronous failure constructing a resource (bad args, provider\n * validation, etc.), or a failure resolving an Output's promise.\n *\n * Tagged `\"PulumiError\"`, so it can be matched by tag rather than by\n * `instanceof`:\n *\n * @example\n * ```ts\n * program.pipe(\n * Effect.catchTag(\"PulumiError\", (e) => Effect.logError(e.message))\n * );\n * ```\n */\nexport class PulumiError extends Data.TaggedError(\"PulumiError\")<{\n /** The original thrown value or rejection reason, unwrapped and unmodified.\n * Not necessarily an `Error`. */\n readonly cause: unknown;\n}> {\n /** Derived so anything reading `.message` — plain logging, test failure\n * output, non-Effect error handling — sees the underlying failure instead\n * of an empty string. */\n get message(): string {\n return describeCause(this.cause);\n }\n}\n\n/**\n * Failure from an Automation API lifecycle call (up/preview/destroy/select).\n *\n * `stage` says which call failed, which matters most in the composite\n * operations: a failed `deploy` could have died selecting the stack, applying\n * config, or running the update, and the three want different responses.\n *\n * @example\n * ```ts\n * deploy(opts).pipe(\n * Effect.catchTag(\"AutomationError\", (e) =>\n * e.stage === \"createOrSelectStack\"\n * ? Effect.fail(new BackendUnreachable())\n * : Effect.logError(e.message)\n * )\n * );\n * ```\n */\nexport class AutomationError extends Data.TaggedError(\"AutomationError\")<{\n /** Which Automation API call failed. Named for the wrapper that raised it,\n * so `deploy`'s failures still report the underlying stage. */\n readonly stage:\n | \"createOrSelectStack\"\n | \"setConfig\"\n | \"up\"\n | \"preview\"\n | \"refresh\"\n | \"outputs\"\n | \"destroy\"\n | \"removeStack\";\n /** The rejection reason from the Automation API. For a failed update this is\n * usually a `CommandError` carrying the CLI's stdout and stderr. */\n readonly cause: unknown;\n}> {\n /** `\"<stage> failed: <cause>\"` — the stage is included because the cause\n * alone rarely says which operation produced it. */\n get message(): string {\n return `${this.stage} failed: ${describeCause(this.cause)}`;\n }\n}\n","import * as pulumi from \"@pulumi/pulumi\";\nimport { Effect } from \"effect\";\nimport { PulumiError } from \"./errors.js\";\n\n/** `Output.promise()` is how the Pulumi runtime itself gets a settled value out\n * of an Output, but it is not part of the public `Output<T>` surface. */\ninterface PromisableOutput<T> {\n promise(withUnknowns?: boolean): Promise<T>;\n}\n\n/**\n * Lift a single Output into an Effect.\n *\n * `withUnknowns: true` matters during `pulumi preview`, where a not-yet-created\n * resource's outputs have no value: it resolves to Pulumi's unknown sentinel\n * instead of throwing, so a program that reads outputs still previews cleanly.\n *\n * @param output - The Output to resolve.\n * @returns An Effect yielding the settled value, failing with\n * {@link PulumiError} if the underlying promise rejects.\n *\n * @example\n * ```ts\n * const bucket = yield* eaws.s3.Bucket(\"assets\", {});\n * const id = yield* fromOutput(bucket.id); // string\n * ```\n *\n * @remarks Reading an Output only makes sense inside a running Pulumi program.\n * During `preview` the value may be the unknown sentinel rather than real data,\n * so don't branch on it to decide what to create.\n */\nexport const fromOutput = <T>(\n output: pulumi.Output<T>\n): Effect.Effect<T, PulumiError> =>\n Effect.tryPromise({\n try: () => (output as unknown as PromisableOutput<T>).promise(true),\n catch: (cause) => new PulumiError({ cause }),\n });\n\n/**\n * Lift a record of Outputs into a single Effect of the resolved record — use\n * this right after constructing a resource to grab several fields at once.\n *\n * Resolves them together via `pulumi.all`, so it costs one await rather than\n * one per field.\n *\n * @param outputs - A record whose values are all Outputs. Interfaces work as\n * well as object literals; the constraint is self-referential rather than\n * `Record<string, Output<any>>` precisely so interface-typed bags are accepted.\n * @returns An Effect yielding the same record with each value unwrapped.\n *\n * @example\n * ```ts\n * const bucket = yield* eaws.s3.Bucket(\"assets\", {});\n * const { id, arn } = yield* fromOutputs({ id: bucket.id, arn: bucket.arn });\n * ```\n */\nexport const fromOutputs = <T extends { [K in keyof T]: pulumi.Output<any> }>(\n outputs: T\n): Effect.Effect<{ [K in keyof T]: pulumi.Unwrap<T[K]> }, PulumiError> =>\n fromOutput(pulumi.all(outputs) as pulumi.Output<any>);\n","/**\n * effectify — auto-wrap a Pulumi provider package (e.g. @pulumi/aws,\n * @pulumi/cloudflare) so every resource constructor becomes an\n * Effect-returning factory, without the caller ever writing `Effect.sync`.\n *\n * Usage:\n *\n * import * as aws from \"@pulumi/aws\";\n * const eaws = effectify(aws);\n *\n * const program = Effect.gen(function* () {\n * const bucket = yield* eaws.s3.Bucket(\"my-bucket\", { forceDestroy: true });\n * // ^ Effect<aws.s3.Bucket, PulumiError> — no manual wrapping\n * });\n *\n * How it works:\n * - Every Pulumi resource class extends `pulumi.Resource` under the hood\n * (via CustomResource / ComponentResource). That's the runtime marker\n * used to tell \"this export is a resource constructor\" apart from \"this\n * export is a namespace object\" (e.g. `aws.s3`) or \"this export is an\n * invoke function\" (e.g. `aws.s3.getBucket`).\n * - Namespace objects get recursively proxied (lazily, memoized).\n * - CustomResource constructors get wrapped so any field in their args\n * object may *additionally* be an Effect — resolved (concurrently, they\n * are independent by construction) before construction. This is safe\n * because codegen guarantees CustomResource args are always\n * Record<string, Input<T>>.\n * - Wrapped constructors keep their static members: `Bucket.get(...)`,\n * `Bucket.isInstance(...)` and friends forward to the original class, so\n * the wrapped package can be the only import a program needs.\n * - ComponentResource constructors get wrapped with no arg-lifting — args\n * pass through exactly as declared, since component args aren't\n * guaranteed to be Input<T>-shaped (hand-authored, may do synchronous\n * work on a bare primitive inside the constructor).\n * - Invoke functions (`aws.s3.getBucket`) return an Effect instead of a\n * Promise. There is no runtime marker for \"this function is async\", so\n * the wrapper calls the function and inspects the result: a thenable\n * becomes an Effect, anything else is returned as-is. That means the\n * invoke *starts* at the call site (see the caveat on `wrapInvokeLike`);\n * `*Output` invoke variants return an Output, which is not thenable, so\n * they pass through untouched — matching the type-level mapping, which\n * only rewrites Promise-returning signatures.\n * - Everything else (enums, plain values, non-resource classes) passes\n * through untouched.\n *\n * Resource registration remains synchronous under the hood — Effect.try\n * runs its thunk immediately. This only removes hand-written wrapper\n * boilerplate, not Pulumi's execution model.\n */\n\nimport * as pulumi from \"@pulumi/pulumi\";\nimport { Effect } from \"effect\";\nimport { PulumiError } from \"./errors.js\";\n\n// ---------------------------------------------------------------------------\n// Runtime type guards\n// ---------------------------------------------------------------------------\n\nconst isResourceConstructor = (\n value: unknown\n): value is new (...args: any[]) => pulumi.Resource =>\n typeof value === \"function\" &&\n (value === (pulumi.Resource as unknown) ||\n value.prototype instanceof pulumi.Resource);\n\nconst isComponentResourceConstructor = (\n Ctor: Function\n): Ctor is new (...args: any[]) => pulumi.ComponentResource =>\n Ctor === (pulumi.ComponentResource as unknown) ||\n Ctor.prototype instanceof pulumi.ComponentResource;\n\n/** An object whose string-keyed properties we only ever *read*. Distinct from\n * `Record<string, unknown>`, which additionally claims the properties are\n * writable and that the object declares an index signature — neither is true\n * of a codegen'd `BucketArgs`, and neither is something this module relies on. */\ntype UnknownProps = { readonly [key: string]: unknown };\n\n/** Is this a namespace to recurse into? The narrowed type is only ever handed\n * to `effectifyInner`, which takes `object` — so claim exactly that and no\n * more. */\nconst isNamespace = (value: unknown): value is object =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/** Is this an args object whose entries we can scan for Effects? Same runtime\n * check as `isNamespace`, but a different question, so it gets the narrowing\n * that question needs: `object` would make `Object.entries` infer `any` values\n * and silently drop the `isEffect` filter's type safety. */\nconst isArgsObject = (value: unknown): value is UnknownProps =>\n isNamespace(value);\n\n/** Note: `pulumi.Output` is deliberately not thenable, so `*Output` invoke\n * variants fail this check and pass through unwrapped — keeping the runtime\n * behaviour aligned with the type mapping, which only rewrites\n * Promise-returning signatures. */\nconst isPromiseLike = (value: unknown): value is PromiseLike<unknown> =>\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { then?: unknown }).then === \"function\";\n\n// ---------------------------------------------------------------------------\n// Type-level mapping\n// ---------------------------------------------------------------------------\n\n/** Allow any field of a CustomResource args object to *additionally* be an\n * Effect. Homomorphic, so optional fields stay optional and plain\n * `Input<T>`/`Output<T>` values keep working untouched. */\ntype LiftedArgs<A> = A extends object\n ? { [K in keyof A]: A[K] | Effect.Effect<A[K], PulumiError> }\n : A;\n\n/** Apply `LiftedArgs` to the second constructor parameter (the args object),\n * leaving `name` and `opts` alone. Mapping over the parameter tuple\n * homomorphically preserves labels and optionality, so constructors whose\n * args are optional stay callable as `Bucket(\"name\")`. */\ntype LiftArgsParam<P extends readonly unknown[]> = {\n [K in keyof P]: K extends \"1\" ? LiftedArgs<P[K]> : P[K];\n};\n\n/** The class's static side, minus `prototype`: `keyof` on a constructor type\n * yields exactly the statics (own and inherited, e.g. codegen'd `get` and\n * `isInstance`), which the runtime wrapper forwards to the original class. */\ntype StaticMembers<T> = Omit<T, \"prototype\">;\n\n/**\n * The type of {@link effectify}'s result: `T` with every resource constructor\n * and every `Promise`-returning invoke rewritten, and everything else left\n * alone.\n *\n * The cases, in the order they are tried:\n *\n * | Input | Becomes |\n * | --------------------------- | ---------------------------------------------- |\n * | `ComponentResource` class | factory returning `Effect`, args **not** lifted |\n * | `CustomResource` class | factory returning `Effect`, args lifted |\n * | other class | unchanged |\n * | `(...) => Promise<R>` | `(...) => Effect<R, PulumiError>` |\n * | other function | unchanged (includes `*Output` invokes) |\n * | object | mapped recursively |\n * | anything else | unchanged |\n *\n * Statics survive on the wrapped constructors, so `Bucket.get` and\n * `Bucket.isInstance` remain callable.\n */\nexport type Effectify<T> = T extends abstract new (\n ...params: infer P\n) => infer R\n ? R extends pulumi.ComponentResource\n ? ((...params: P) => Effect.Effect<R, PulumiError>) & StaticMembers<T>\n : R extends pulumi.CustomResource\n ? ((...params: LiftArgsParam<P>) => Effect.Effect<R, PulumiError>) &\n StaticMembers<T>\n : T\n : T extends (...args: infer A) => Promise<infer R>\n ? (...args: A) => Effect.Effect<R, PulumiError>\n : T extends (...args: any[]) => any\n ? T\n : T extends object\n ? { [K in keyof T]: Effectify<T[K]> }\n : T;\n\n// ---------------------------------------------------------------------------\n// Runtime implementation\n// ---------------------------------------------------------------------------\n\nconst proxyCache = new WeakMap<object, unknown>();\n\nconst isEffect = (value: unknown): value is Effect.Effect<unknown, unknown> =>\n Effect.isEffect(value);\n\nfunction resolveLiftedArgs(args: unknown): Effect.Effect<unknown, PulumiError> {\n if (!isArgsObject(args)) {\n return Effect.succeed(args);\n }\n\n const effectEntries = Object.entries(args).filter(([, v]) => isEffect(v));\n\n if (effectEntries.length === 0) {\n return Effect.succeed(args);\n }\n\n // The arg Effects are independent of one another, so resolve them\n // concurrently — it matters when several of them await slow Outputs.\n return Effect.map(\n Effect.all(\n effectEntries.map(([key, effectValue]) =>\n Effect.map(\n effectValue as Effect.Effect<unknown, PulumiError>,\n (resolved) => [key, resolved] as const\n )\n ),\n { concurrency: \"unbounded\" }\n ),\n (resolved) => ({ ...args, ...Object.fromEntries(resolved) })\n );\n}\n\nfunction wrapCustomResourceCtor(\n Ctor: new (...args: any[]) => pulumi.CustomResource\n) {\n return (name: string, args?: unknown, opts?: unknown) =>\n Effect.gen(function* () {\n const resolvedArgs = yield* resolveLiftedArgs(args);\n return yield* Effect.try({\n try: () => new Ctor(name, resolvedArgs, opts),\n catch: (cause) => new PulumiError({ cause }),\n });\n });\n}\n\nfunction wrapComponentResourceCtor(\n Ctor: new (...args: any[]) => pulumi.ComponentResource\n) {\n return (name: string, args?: unknown, opts?: unknown) =>\n Effect.try({\n try: () => new Ctor(name, args, opts),\n catch: (cause) => new PulumiError({ cause }),\n });\n}\n\n/** Forward static members (codegen'd `get`, `isInstance`, …) from the class\n * onto the factory. The factory's own and inherited properties (`name`,\n * `length`, `call`, …) win; anything else falls through to the class, so new\n * statics keep working without being enumerated here. A bonus of forwarding\n * `prototype` is that `x instanceof wrapped` still works. */\nconst withStatics = <F extends object>(factory: F, Ctor: Function): F =>\n new Proxy(factory, {\n get: (target, prop, receiver) =>\n Reflect.has(target, prop)\n ? Reflect.get(target, prop, receiver)\n : Reflect.get(Ctor, prop),\n has: (target, prop) => Reflect.has(target, prop) || Reflect.has(Ctor, prop),\n });\n\nfunction wrapResourceCtor(Ctor: new (...args: any[]) => pulumi.Resource) {\n const factory = isComponentResourceConstructor(Ctor)\n ? wrapComponentResourceCtor(Ctor)\n : wrapCustomResourceCtor(\n Ctor as new (...args: any[]) => pulumi.CustomResource\n );\n return withStatics(factory, Ctor);\n}\n\n/** Turn a Promise-returning invoke into an Effect-returning one, leaving\n * synchronous functions' behaviour untouched.\n *\n * A Proxy over the original function (rather than a new function) so `name`,\n * `length`, own properties and prototype all survive; only the call itself is\n * intercepted.\n *\n * Caveat, stated openly: whether a function is async is only knowable by\n * calling it, so the invoke *starts* when the factory is called — the Effect\n * resolves an already-in-flight Promise rather than deferring the call. Two\n * consequences:\n * - `Effect.retry` re-awaits the same call instead of re-invoking. To\n * re-invoke per attempt, wrap the call site: `Effect.suspend(() =>\n * eaws.getAmi(args))`.\n * - A discarded Effect must not surface as an unhandled rejection, so the\n * rejection is pre-observed on a side branch before the Effect awaits it.\n */\nfunction wrapInvokeLike(fn: Function): Function {\n return new Proxy(fn, {\n apply(target, thisArg, args) {\n const result = Reflect.apply(target, thisArg, args);\n if (!isPromiseLike(result)) {\n return result;\n }\n result.then(undefined, () => {});\n return Effect.tryPromise({\n try: () => result as Promise<unknown>,\n catch: (cause) => new PulumiError({ cause }),\n });\n },\n });\n}\n\n/** Wrapped constructors are cached so repeated reads of the same property\n * hand back the same function — identity checks like\n * `eaws.s3.Bucket === eaws.s3.Bucket` hold, and the `get` and\n * `getOwnPropertyDescriptor` traps agree on a property's value. */\nconst wrapperCache = new WeakMap<object, unknown>();\n\nfunction effectifyValue(value: unknown): unknown {\n if (isResourceConstructor(value)) {\n const cached = wrapperCache.get(value);\n if (cached) return cached;\n const wrapped = wrapResourceCtor(value);\n wrapperCache.set(value, wrapped);\n return wrapped;\n }\n\n if (typeof value === \"function\") {\n const cached = wrapperCache.get(value);\n if (cached) return cached;\n const wrapped = wrapInvokeLike(value);\n wrapperCache.set(value, wrapped);\n return wrapped;\n }\n\n if (isNamespace(value)) {\n return effectifyInner(value);\n }\n\n return value; // plain value, enum member, type-only export\n}\n\nfunction effectifyInner<T extends object>(mod: T): Effectify<T> {\n const cached = proxyCache.get(mod);\n if (cached) return cached as Effectify<T>;\n\n // The proxy target is a fresh plain object rather than `mod` itself: ES\n // module namespace objects (and @pulumi/aws's lazily-defined namespace\n // getters) expose non-configurable own properties, and a `get` trap that\n // returns a wrapper instead of the real value would violate the proxy\n // invariants for those. Forwarding to `mod` from a closure sidesteps that\n // entirely while keeping the lazy-loading behaviour intact.\n const proxy = new Proxy(Object.create(null) as T, {\n get(_target, prop) {\n return effectifyValue(Reflect.get(mod, prop));\n },\n has(_target, prop) {\n return Reflect.has(mod, prop);\n },\n ownKeys() {\n return Reflect.ownKeys(mod);\n },\n getOwnPropertyDescriptor(_target, prop) {\n const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);\n if (!descriptor) return undefined;\n // Must be reported as configurable — the target does not actually have\n // the property, so claiming otherwise breaks the proxy invariants.\n return {\n value: effectifyValue(Reflect.get(mod, prop)),\n enumerable: descriptor.enumerable,\n configurable: true,\n writable: true,\n };\n },\n set() {\n return false; // the wrapper is read-only\n },\n }) as Effectify<T>;\n\n proxyCache.set(mod, proxy);\n return proxy;\n}\n\n/**\n * Wrap a provider package (or any namespace) once, turning every resource\n * constructor into an `Effect`-returning factory and every `Promise`-returning\n * invoke into an `Effect`-returning function.\n *\n * Call this once per package at module scope and export the result — the\n * wrapper is cached, so repeated calls and repeated property reads hand back\n * the same objects, but there is no reason to re-wrap.\n *\n * @param mod - The provider package, or any namespace within one. Not mutated;\n * the result is a read-only proxy that forwards to it.\n * @returns A same-shaped view of `mod`, typed by {@link Effectify}.\n *\n * @example Constructing a resource\n * ```ts\n * import * as aws from \"@pulumi/aws\";\n * const eaws = effectify(aws);\n *\n * const program = Effect.gen(function* () {\n * const bucket = yield* eaws.s3.Bucket(\"assets\", { forceDestroy: true });\n * return bucket.id;\n * });\n * ```\n *\n * @example Passing an Effect as an argument\n * A `CustomResource`'s args may hold Effects, which are resolved concurrently\n * before the resource is constructed:\n * ```ts\n * yield* eaws.s3.BucketObject(\"readme\", {\n * bucket: bucketIdEffect,\n * content: \"hello\",\n * });\n * ```\n *\n * @throws Nothing. Failures surface in the returned Effect's error channel as\n * {@link PulumiError} — including synchronous throws from the constructor.\n *\n * @see {@link Effectify} for the type-level mapping.\n */\nexport function effectify<T extends object>(mod: T): Effectify<T> {\n return effectifyInner(mod);\n}\n","import type {\n ConfigMap,\n DestroyOptions,\n DestroyResult,\n LocalWorkspaceOptions,\n OutputMap,\n PreviewOptions,\n PreviewResult,\n PulumiFn,\n RefreshOptions,\n RefreshResult,\n RemoveOptions,\n Stack,\n UpOptions,\n UpResult,\n} from \"@pulumi/pulumi/automation/index.js\";\nimport { LocalWorkspace } from \"@pulumi/pulumi/automation/index.js\";\nimport { Effect } from \"effect\";\nimport { AutomationError } from \"./errors.js\";\n\n// ---------------------------------------------------------------------------\n// Primitives\n//\n// Each wraps one Automation API call, tagging failures with the stage they\n// came from. They are exported individually so callers can assemble their own\n// lifecycle — `deploy` below is only the common path.\n//\n// Every operation takes the matching Pulumi options type. That includes\n// `onOutput`: pass it to stream the CLI's progress as it happens. Without it\n// nothing is printed during what may be a multi-minute operation (the text is\n// still captured on the result's `stdout`, and on the error when one is\n// thrown, but only once the operation has finished).\n// ---------------------------------------------------------------------------\n\n/** Arguments for an inline program — the Pulumi program is a function in this\n * process, with no `Pulumi.yaml` on disk. */\nexport interface InlineStackOptions {\n /** Stack to select, created if absent. */\n readonly stackName: string;\n /** Project name to register the stack under. Chosen freely here, since\n * there is no `Pulumi.yaml` to take it from — but it is part of the stack's\n * identity in the backend, so changing it later points at a different\n * stack. */\n readonly projectName: string;\n /** The program itself. Runs in this process, so it needs no separate Node\n * runtime and can close over values from the caller. */\n readonly program: PulumiFn;\n readonly workspaceOptions?: LocalWorkspaceOptions;\n}\n\n/** Arguments for a local program — an existing Pulumi project on disk. */\nexport interface LocalStackOptions {\n /** Stack to select, created if absent. */\n readonly stackName: string;\n /** Directory holding the project's `Pulumi.yaml`. Its `name:` supplies the\n * project name, which is why there is no `projectName` here. */\n readonly workDir: string;\n readonly workspaceOptions?: LocalWorkspaceOptions;\n}\n\n/** Either flavour of stack. Discriminated at runtime by the presence of\n * `workDir`, so the two are not interchangeable: an inline program needs\n * `projectName`, a local one takes it from `Pulumi.yaml`. */\nexport type StackOptions = InlineStackOptions | LocalStackOptions;\n\nconst isLocal = (opts: StackOptions): opts is LocalStackOptions =>\n \"workDir\" in opts;\n\n/** Select the stack, creating it if it does not exist, and return the handle\n * every other operation here takes.\n *\n * Creating the workspace is itself work — it may write files and shell out to\n * the CLI — so hold on to the returned `Stack` rather than re-selecting before\n * each operation. */\nexport const createOrSelectStack = (\n opts: StackOptions\n): Effect.Effect<Stack, AutomationError> =>\n Effect.tryPromise({\n try: () =>\n isLocal(opts)\n ? LocalWorkspace.createOrSelectStack(\n { stackName: opts.stackName, workDir: opts.workDir },\n opts.workspaceOptions\n )\n : LocalWorkspace.createOrSelectStack(\n {\n stackName: opts.stackName,\n projectName: opts.projectName,\n program: opts.program,\n },\n opts.workspaceOptions\n ),\n catch: (cause) =>\n new AutomationError({ stage: \"createOrSelectStack\", cause }),\n });\n\n/** Apply the whole config map in one `setAllConfig` call — a single CLI\n * round-trip, where per-key `setConfig` costs one `pulumi config set`\n * invocation each. */\nexport const setStackConfig = (\n stack: Stack,\n config: ConfigMap | undefined\n): Effect.Effect<void, AutomationError> =>\n !config || Object.keys(config).length === 0\n ? Effect.void\n : Effect.tryPromise({\n try: () => stack.setAllConfig(config),\n catch: (cause) => new AutomationError({ stage: \"setConfig\", cause }),\n });\n\n/** Compute the plan without applying it.\n *\n * A preview is a full engine run against the provider, not a cheap check — see\n * {@link DeployOptions.preview} before pairing one with an `up`. */\nexport const previewStack = (\n stack: Stack,\n opts?: PreviewOptions\n): Effect.Effect<PreviewResult, AutomationError> =>\n Effect.tryPromise({\n try: () => stack.preview(opts),\n catch: (cause) => new AutomationError({ stage: \"preview\", cause }),\n });\n\n/** Apply the program: create, update and delete resources to match it.\n *\n * The result carries the stack's outputs and a summary; pass `onOutput` to\n * watch progress while it runs. */\nexport const upStack = (\n stack: Stack,\n opts?: UpOptions\n): Effect.Effect<UpResult, AutomationError> =>\n Effect.tryPromise({\n try: () => stack.up(opts),\n catch: (cause) => new AutomationError({ stage: \"up\", cause }),\n });\n\n/** Refresh the stack's state from the actual cloud resources, without\n * changing them — what to run when state may have drifted (manual console\n * edits, a crashed update) before deciding what to do about it. */\nexport const refreshStack = (\n stack: Stack,\n opts?: RefreshOptions\n): Effect.Effect<RefreshResult, AutomationError> =>\n Effect.tryPromise({\n try: () => stack.refresh(opts),\n catch: (cause) => new AutomationError({ stage: \"refresh\", cause }),\n });\n\n/** Read the stack's current outputs without running an update. */\nexport const stackOutputs = (\n stack: Stack\n): Effect.Effect<OutputMap, AutomationError> =>\n Effect.tryPromise({\n try: () => stack.outputs(),\n catch: (cause) => new AutomationError({ stage: \"outputs\", cause }),\n });\n\n/** Destroy the stack's resources. The stack itself remains registered with\n * the backend — see `removeStack` / `teardownStack` to delete it too. */\nexport const destroyStack = (\n stack: Stack,\n opts?: DestroyOptions\n): Effect.Effect<DestroyResult, AutomationError> =>\n Effect.tryPromise({\n try: () => stack.destroy(opts),\n catch: (cause) => new AutomationError({ stage: \"destroy\", cause }),\n });\n\n/** Delete the stack and its configuration and history from the backend.\n *\n * This does not destroy resources — run `destroyStack` first, or use\n * `teardownStack`. Pulumi refuses to remove a stack that still has resources\n * unless `RemoveOptions.force` is set, and forcing it orphans them: they keep\n * existing and billing with nothing tracking them. */\nexport const removeStack = (\n stack: Stack,\n opts?: RemoveOptions\n): Effect.Effect<void, AutomationError> =>\n Effect.tryPromise({\n try: () => stack.workspace.removeStack(stack.name, opts),\n catch: (cause) => new AutomationError({ stage: \"removeStack\", cause }),\n });\n\n/** Full teardown: destroy the resources, then delete the stack.\n *\n * `destroyStack` alone leaves an empty stack behind, so anything creating\n * stacks per-run (ephemeral environments, tests naming stacks by timestamp)\n * accumulates them in the backend. */\nexport const teardownStack = (\n stack: Stack,\n opts?: { readonly destroy?: DestroyOptions; readonly remove?: RemoveOptions }\n): Effect.Effect<DestroyResult, AutomationError> =>\n Effect.gen(function* () {\n const result = yield* destroyStack(stack, opts?.destroy);\n yield* removeStack(stack, opts?.remove);\n return result;\n });\n\n// ---------------------------------------------------------------------------\n// Convenience lifecycle\n// ---------------------------------------------------------------------------\n\n/** {@link deploy}'s arguments: the stack to target, plus what to do with it. */\nexport type DeployOptions = StackOptions & {\n /** Config to apply before the update, in one `setAllConfig` call. Keys are\n * fully qualified (`\"my-project:myKey\"`). */\n readonly config?: ConfigMap;\n /** Options forwarded to the update — `onOutput` to stream progress,\n * `parallel`, `target`, and so on. */\n readonly up?: UpOptions;\n /** Run `preview` before `up`, returning its result.\n *\n * Off by default: a preview is a full engine run against the provider, so\n * previewing and then immediately upping does the work twice. `up` reports\n * the same failures, so this earns its cost only when you want the plan\n * itself. */\n readonly preview?: PreviewOptions | boolean;\n};\n\n/** What {@link deploy} hands back. */\nexport interface DeployResult {\n /** The selected stack, so teardown needs no second `createOrSelectStack`. */\n readonly stack: Stack;\n /** The update's result — `outputs` and `summary` live here. */\n readonly result: UpResult;\n /** Present only when `preview` was requested. */\n readonly preview?: PreviewResult;\n}\n\n/**\n * Select or create the stack, apply config, optionally preview, then up.\n *\n * The common path, assembled from the primitives above. Anything more\n * involved — refreshing first, inspecting the plan before deciding, retrying a\n * stage — should compose those directly rather than grow options here.\n *\n * @param opts - Which stack, and what to do with it.\n * @returns The stack handle alongside the results, so callers can tear down\n * afterwards without re-selecting.\n *\n * @example Deploy, use the outputs, then always tear down\n * ```ts\n * Effect.scoped(\n * Effect.gen(function* () {\n * const { result } = yield* Effect.acquireRelease(\n * deploy({ stackName, projectName, program, up: { onOutput } }),\n * ({ stack }) => teardownStack(stack).pipe(Effect.ignore)\n * );\n * return result.outputs.bucketId?.value;\n * })\n * );\n * ```\n */\nexport const deploy = (\n opts: DeployOptions\n): Effect.Effect<DeployResult, AutomationError> =>\n Effect.gen(function* () {\n const stack = yield* createOrSelectStack(opts);\n yield* setStackConfig(stack, opts.config);\n\n const preview = opts.preview\n ? yield* previewStack(\n stack,\n typeof opts.preview === \"boolean\" ? undefined : opts.preview\n )\n : undefined;\n\n const result = yield* upStack(stack, opts.up);\n return { stack, result, preview };\n });\n"]}
|