{
  "version": 3,
  "sources": ["../../src/core/async-dependencies.ts"],
  "sourcesContent": ["import { App, StageSynthesisOptions } from \"aws-cdk-lib\";\nimport { IConstruct } from \"constructs\";\n\nconst tag = Symbol(\"cloudy-cdk-lib.AsyncDependencies\");\n\n/**\n * Represents a CDK app that may have been tagged with an\n * AsyncDependenciesContext.\n */\ninterface MaybeTaggedApp extends App {\n  [tag]?: AsyncDependenciesContext;\n}\n\n/**\n * Manages all of the async dependencies in a CDK application and makes sure\n * that the synth process doesn't start before that.\n *\n * When instantiated, the AsyncDependenciesContext will save itself in the CDK\n * app as a singleton, and will patch the `app.synth()` method, ensuring it\n * can't start before all of the async dependencies are fulfilled.\n */\nexport class AsyncDependenciesContext {\n  /**\n   * Returns the AsyncDependenciesContext of the app.\n   *\n   * @param node The construct node.\n   * @returns The AsyncDependenciesContext of the app.\n   */\n  static of(node: IConstruct) {\n    const root = node.node.root;\n    // if (!(root instanceof App)) {\n    if (!App.isApp(root)) {\n      throw new TypeError(\n        \"The root construct must be an instance of [cdk.App].\",\n      );\n    }\n\n    // Return any existing context, or create a new one.\n    const app: MaybeTaggedApp = root;\n    return app[tag] ?? new AsyncDependenciesContext(app);\n  }\n\n  /**\n   * Holds all of the dependencies promises.\n   */\n  private readonly promises: Promise<void>[] = [];\n\n  /**\n   * Creates a new AsyncDependenciesContext and patches the app so it can't\n   * synth before the dependencies are fulfilled.\n   * @param app The CDK app.\n   */\n  private constructor(app: App) {\n    Object.assign(app, { [tag]: this });\n  }\n\n  /**\n   * Add an async dependency to the app.\n   *\n   * @param dependency The promise that represents the dependency.\n   */\n  addAsyncDependency(dependency: Promise<void>) {\n    this.promises.push(dependency);\n  }\n\n  /**\n   * Creates a Promise that is resolved when all of the async dependencies\n   * resolve, or rejected when any async dependency fails.\n   */\n  async waitForAsyncDependencies() {\n    await Promise.all(this.promises);\n  }\n}\n\n/**\n * Waits for all of the async dependencies in the app to resolve.\n * @param app The CDK app.\n */\nexport async function waitForAsyncDependencies(app: App) {\n  const appDependencies = AsyncDependenciesContext.of(app);\n  await appDependencies.waitForAsyncDependencies();\n}\n\n/**\n * Synthesize this stage into a cloud assembly.\n *\n * Once an assembly has been synthesized, it cannot be modified. Subsequent\n * calls will return the same assembly.\n *\n * Waits for all of the async dependencies to resolve before starting to\n * synthesize.\n *\n * @see {@link App.synth()}\n */\nexport async function synth(app: App, options?: StageSynthesisOptions) {\n  await waitForAsyncDependencies(app);\n  return app.synth(options);\n}\n"],
  "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,EAAA,UAAAC,EAAA,6BAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAA2C,uBAG3C,MAAMC,EAAM,OAAO,kCAAkC,EAkB9C,MAAML,CAAyB,CA+B5B,YAAYM,EAAU,CAP9B,KAAiB,SAA4B,CAAC,EAQ5C,OAAO,OAAOA,EAAK,CAAE,CAACD,CAAG,EAAG,IAAK,CAAC,CACpC,CA1BA,OAAO,GAAGE,EAAkB,CAC1B,MAAMC,EAAOD,EAAK,KAAK,KAEvB,GAAI,CAAC,MAAI,MAAMC,CAAI,EACjB,MAAM,IAAI,UACR,sDACF,EAIF,MAAMF,EAAsBE,EAC5B,OAAOF,EAAID,CAAG,GAAK,IAAIL,EAAyBM,CAAG,CACrD,CAqBA,mBAAmBG,EAA2B,CAC5C,KAAK,SAAS,KAAKA,CAAU,CAC/B,CAMA,MAAM,0BAA2B,CAC/B,MAAM,QAAQ,IAAI,KAAK,QAAQ,CACjC,CACF,CAMA,eAAsBP,EAAyBI,EAAU,CAEvD,MADwBN,EAAyB,GAAGM,CAAG,EACjC,yBAAyB,CACjD,CAaA,eAAsBL,EAAMK,EAAUI,EAAiC,CACrE,aAAMR,EAAyBI,CAAG,EAC3BA,EAAI,MAAMI,CAAO,CAC1B",
  "names": ["async_dependencies_exports", "__export", "AsyncDependenciesContext", "synth", "waitForAsyncDependencies", "__toCommonJS", "import_aws_cdk_lib", "tag", "app", "node", "root", "dependency", "options"]
}
