effect-pulumi 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/output-bridge.ts","../src/effectify.ts","../src/automation.ts"],"names":["pulumi","Effect"],"mappings":";;;;;AAEA,IAAM,aAAA,GAAgB,CAAC,KAAA,KACrB,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAgBhD,IAAM,WAAA,GAAN,cAA0B,IAAA,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,cAA8B,IAAA,CAAK,WAAA,CAAY,iBAAiB,CAAA,CAepE;AAAA;AAAA;AAAA,EAGD,IAAI,OAAA,GAAkB;AACpB,IAAA,OAAO,GAAG,IAAA,CAAK,KAAK,YAAY,aAAA,CAAc,IAAA,CAAK,KAAK,CAAC,CAAA,CAAA;AAAA,EAC3D;AACF;ACxCO,IAAM,UAAA,GAAa,CACxB,MAAA,KAEA,MAAA,CAAO,UAAA,CAAW;AAAA,EAChB,GAAA,EAAK,MAAO,MAAA,CAA0C,OAAA,CAAQ,IAAI,CAAA;AAAA,EAClE,OAAO,CAAC,KAAA,KAAU,IAAI,WAAA,CAAY,EAAE,OAAO;AAC7C,CAAC;AAoBI,IAAM,cAAc,CACzB,OAAA,KAEA,UAAA,CAAkBA,OAAA,CAAA,GAAA,CAAI,OAAO,CAAuB;ACFtD,IAAM,qBAAA,GAAwB,CAC5B,KAAA,KAEA,OAAO,UAAU,UAAA,KAChB,KAAA,KAAkB,OAAA,CAAA,QAAA,IACjB,KAAA,CAAM,SAAA,YAA4B,OAAA,CAAA,QAAA,CAAA;A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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"]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/errors.ts","../src/output-bridge.ts","../src/effectify.ts","../src/automation.ts"],"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"],"mappings":";;;;AAEA,MAAM,iBAAiB,UACrB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;;;;;;;;;;;;;;;AAgBvD,IAAa,cAAb,cAAiC,KAAK,YAAY,aAAa,CAAC,CAI7D;;;;CAID,IAAI,UAAkB;EACpB,OAAO,cAAc,KAAK,KAAK;CACjC;AACF;;;;;;;;;;;;;;;;;;;AAoBA,IAAa,kBAAb,cAAqC,KAAK,YAAY,iBAAiB,CAAC,CAerE;;;CAGD,IAAI,UAAkB;EACpB,OAAO,GAAG,KAAK,MAAM,WAAW,cAAc,KAAK,KAAK;CAC1D;AACF;;;;;;;;;;;;;;;;;;;;;;;;ACxCA,MAAa,cACX,WAEA,OAAO,WAAW;CAChB,WAAY,OAA0C,QAAQ,IAAI;CAClE,QAAQ,UAAU,IAAI,YAAY,EAAE,MAAM,CAAC;AAC7C,CAAC;;;;;;;;;;;;;;;;;;;AAoBH,MAAa,eACX,YAEA,WAAW,OAAO,IAAI,OAAO,CAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACFtD,MAAM,yBACJ,UAEA,OAAO,UAAU,eAChB,UAAW,OAAO,YACjB,MAAM,qBAAqB,OAAO;AAEtC,MAAM,kCACJ,SAEA,SAAU,OAAO,qBACjB,KAAK,qBAAqB,OAAO;;;;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,OAAO,oBAAoB,IAAI;CAC7C,OAAO,eAAe,OAAO,KAAK,MAAM;CAExC,MAAM,UAAU,KAAK,UACjB,OAAO,aACL,OACA,OAAO,KAAK,YAAY,YAAY,KAAA,IAAY,KAAK,OACvD,IACA,KAAA;CAGJ,OAAO;EAAE;EAAO,QAAA,OADM,QAAQ,OAAO,KAAK,EAAE;EACpB;CAAQ;AAClC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-pulumi",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Effect bindings for Pulumi - wrap a provider package once and get Effect-returning resource factories, typed errors, and structured deploy results.",
5
5
  "keywords": [
6
6
  "effect",
@@ -45,7 +45,7 @@
45
45
  "./package.json": "./package.json"
46
46
  },
47
47
  "scripts": {
48
- "build": "tsup",
48
+ "build": "tsdown",
49
49
  "prepare": "npm run build",
50
50
  "typecheck": "tsc -p tsconfig.json",
51
51
  "lint": "oxlint",
@@ -55,13 +55,13 @@
55
55
  "check": "npm run typecheck && npm run lint && npm run format:check",
56
56
  "test": "vitest run",
57
57
  "test:watch": "vitest",
58
- "test:live": "EFFECT_PULUMI_RUN_LIVE_TESTS=1 vitest run --config vitest.live.config.ts",
58
+ "test:live": "vitest run --config vitest.live.config.ts",
59
59
  "test:package": "vitest run --config vitest.packaging.config.ts",
60
60
  "prepublishOnly": "npm run check && npm run test && npm run test:package"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "@pulumi/pulumi": "^3.0.0",
64
- "effect": "^3.0.0"
64
+ "effect": "^4.0.0"
65
65
  },
66
66
  "workspaces": [
67
67
  ".",
@@ -69,22 +69,21 @@
69
69
  "examples/automation-api-random-pet"
70
70
  ],
71
71
  "devDependencies": {
72
- "@effect/vitest": "^0.30.0",
72
+ "@effect/vitest": "^4.0.0",
73
73
  "@pulumi/aws": "^7.40.0",
74
74
  "@pulumi/local": "^0.1.6",
75
- "@pulumi/random": "^4.21.1",
76
75
  "@pulumi/pulumi": "^3.256.0",
77
- "effect": "^3.22.1",
78
- "oxfmt": "^0.62.0",
76
+ "@pulumi/random": "^4.21.1",
77
+ "effect": "^4.0.0",
78
+ "oxfmt": "^0.71.0",
79
79
  "oxlint": "^1.77.0",
80
- "tsup": "^8.5.1",
81
- "typescript": "^5.9.0",
82
- "vitest": "^4.1.10"
80
+ "tsdown": "^0.23.0",
81
+ "typescript": "^6.0.3",
82
+ "vitest": "^5.0.0"
83
83
  },
84
84
  "overrides": {
85
85
  "@effect/vitest": {
86
86
  "vitest": "$vitest"
87
87
  }
88
- },
89
- "dependencies": {}
88
+ }
90
89
  }