import * as Output from "./Output.ts"; import type { ResourceLike } from "./Resource.ts"; // special runtime-only symbol for probing the Ref proxy for its metadata const RefMetadata = Symbol.for("alchemy/RefMetadata"); export const isRef = (s: any): s is Ref => s && s[RefMetadata] !== undefined; export const getRefMetadata = ( ref: Ref, ): RefMetadata => (ref as any)[RefMetadata]; export interface Ref { /** @internal phantom */ Ref: R; } export interface RefMetadata { id: R["LogicalId"]; stack?: string; stage?: string; } export const ref = ({ stack, id, stage, }: RefMetadata): Ref => { const ref = new Proxy( {}, { get: (_, prop) => { if (prop === RefMetadata) { return { stack, stage, id, } satisfies RefMetadata; } return (Output.of(ref) as any)[prop]; }, }, ) as Ref; return ref; };