{"version":3,"file":"KeyManagementModuleConfig.mjs","names":[],"sources":["../../../src/modules/kms/KeyManagementModuleConfig.ts"],"sourcesContent":["import { KeyManagementError } from './error/KeyManagementError'\nimport type { KeyManagementService } from './KeyManagementService'\n\nexport interface KeyManagementModuleConfigOptions {\n  /**\n   * The backends to use for key management and cryptographic operations.\n   */\n  backends?: KeyManagementService[]\n\n  /**\n   * The default backend to use, indicated by the `backend` property\n   * on the `KeyManagementService` instance.\n   *\n   * If provided and it doesn't match an entry in the `backends` array\n   * an error will be thrown.\n   *\n   * If not provided, the first backend from the `backends` array will be used.\n   */\n  defaultBackend?: string\n}\n\nexport class KeyManagementModuleConfig {\n  #defaultBackend?: string\n  #backends: KeyManagementService[]\n\n  public constructor(options: KeyManagementModuleConfigOptions) {\n    this.#backends = options.backends ?? []\n\n    if (options.defaultBackend) {\n      const defaultBackend = this.#backends.find((kms) => kms.backend === options.defaultBackend)\n      if (!defaultBackend) {\n        throw new KeyManagementError(\n          `Default backend '${options.defaultBackend}' provided in KeyManagementModuleConfig, but not found in 'backends'. Make sure the backend identifier matches with a registered backend.`\n        )\n      }\n      this.#defaultBackend = options.defaultBackend\n    }\n  }\n\n  public get backends() {\n    return this.#backends\n  }\n\n  public registerBackend(backend: KeyManagementService) {\n    this.backends.push(backend)\n  }\n\n  public get defaultBackend() {\n    const backend = this.backends.find((kms) => !this.#defaultBackend || this.#defaultBackend === kms.backend)\n    if (!backend) {\n      throw new KeyManagementError('Unable to determine default backend. ')\n    }\n\n    return backend\n  }\n}\n"],"mappings":";;;;;;;;;;AAqBA,IAAa,4BAAb,MAAuC;CAIrC,AAAO,YAAY,SAA2C;;;AAC5D,0CAAiB,QAAQ,YAAY,EAAE;AAEvC,MAAI,QAAQ,gBAAgB;AAE1B,OAAI,mCADmB,KAAc,CAAC,MAAM,QAAQ,IAAI,YAAY,QAAQ,eAAe,CAEzF,OAAM,IAAI,mBACR,oBAAoB,QAAQ,eAAe,2IAC5C;AAEH,iDAAuB,QAAQ,eAAc;;;CAIjD,IAAW,WAAW;AACpB,2CAAO,KAAc;;CAGvB,AAAO,gBAAgB,SAA+B;AACpD,OAAK,SAAS,KAAK,QAAQ;;CAG7B,IAAW,iBAAiB;EAC1B,MAAM,UAAU,KAAK,SAAS,MAAM,QAAQ,yCAAC,KAAoB,4CAAI,KAAoB,KAAK,IAAI,QAAQ;AAC1G,MAAI,CAAC,QACH,OAAM,IAAI,mBAAmB,wCAAwC;AAGvE,SAAO"}