{"version":3,"file":"ProgramRepositoryInterface.mjs","sources":["../../src/ProgramRepositoryInterface.ts"],"sourcesContent":["import type {\n  PublicKey,\n  PublicKeyInput,\n} from '@metaplex-foundation/umi-public-keys';\nimport type { ClusterFilter } from './Cluster';\nimport type { ErrorWithLogs, Program } from './Program';\nimport type { Transaction } from './Transaction';\nimport { InterfaceImplementationMissingError, ProgramError } from './errors';\n\n/**\n * Defines the interface for a program repository.\n * It allows us to register and retrieve programs when needed.\n *\n * @category Context and Interfaces\n */\nexport interface ProgramRepositoryInterface {\n  /**\n   * Whether a given program is registered in the repository.\n   *\n   * @param identifier The name or public key of the program to check.\n   * @param clusterFilter The cluster filter to apply. Defaults to `\"current\"`.\n   */\n  has(identifier: string | PublicKey, clusterFilter?: ClusterFilter): boolean;\n\n  /**\n   * Gets a program from the repository.\n   * Throws an error if the program is not found.\n   *\n   * @param identifier The name or public key of the program to retrieve.\n   * @param clusterFilter The cluster filter to apply. Defaults to `\"current\"`.\n   * @typeParam T - The type of the program to retrieve. Defaults to `Program`.\n   */\n  get<T extends Program = Program>(\n    identifier: string | PublicKey,\n    clusterFilter?: ClusterFilter\n  ): T;\n\n  /**\n   * Gets the public key of a program from the repository,\n   * with an optional fallback public key.\n   *\n   * Throws an error if the program is not found and no fallback is provided.\n   *\n   * @param identifier The name or public key of the program to retrieve.\n   * @param fallback The fallback public key to use if the program is not found.\n   * Defaults to not using a fallback public key.\n   * @param clusterFilter The cluster filter to apply. Defaults to `\"current\"`.\n   */\n  getPublicKey(\n    identifier: string | PublicKey,\n    fallback?: PublicKeyInput,\n    clusterFilter?: ClusterFilter\n  ): PublicKey;\n\n  /**\n   * Gets all programs from the repository matching the given cluster filter.\n   * Defaults to getting all programs from the current cluster.\n   *\n   * @param clusterFilter The cluster filter to apply. Defaults to `\"current\"`.\n   */\n  all(clusterFilter?: ClusterFilter): Program[];\n\n  /**\n   * Registers a new program in the repository.\n   *\n   * @param program The program to register.\n   * @param overrides Whether to register and prioritize\n   * the given program even if a program with the same\n   * public key already exists. Defaults to `true`.\n   */\n  add(program: Program, overrides?: boolean): void;\n\n  /**\n   * Creates a binding between a name and a program identifier.\n   * This can be used to create redirections or aliases when resolving programs.\n   *\n   * @param abstract The name of the binding.\n   * @param concrete The identifier this binding should resolve to.\n   */\n  bind(abstract: string, concrete: string | PublicKey): void;\n\n  /**\n   * Removes a binding using its name.\n   *\n   * @param abstract The name of the binding to remove.\n   */\n  unbind(abstract: string): void;\n\n  /**\n   * Creates a cloned instance of the repository.\n   *\n   * @returns A new repository instance with the same programs and bindings.\n   */\n  clone(): ProgramRepositoryInterface;\n\n  /**\n   * Resolves a custom program error from a transaction error.\n   *\n   * @param error The raw error to resolve containing the program logs.\n   * @param transaction The transaction that caused the error.\n   * @returns The resolved program error, or `null` if the error cannot be resolved.\n   */\n  resolveError(\n    error: ErrorWithLogs,\n    transaction: Transaction\n  ): ProgramError | null;\n}\n\n/**\n * An implementation of the {@link ProgramRepositoryInterface} that throws an error when called.\n * @category Programs\n */\nexport function createNullProgramRepository(): ProgramRepositoryInterface {\n  const errorHandler = () => {\n    throw new InterfaceImplementationMissingError(\n      'ProgramRepositoryInterface',\n      'programs'\n    );\n  };\n  return {\n    has: errorHandler,\n    get: errorHandler,\n    getPublicKey: errorHandler,\n    all: errorHandler,\n    add: errorHandler,\n    bind: errorHandler,\n    unbind: errorHandler,\n    clone: errorHandler,\n    resolveError: errorHandler,\n  };\n}\n"],"names":["createNullProgramRepository","errorHandler","InterfaceImplementationMissingError","has","get","getPublicKey","all","add","bind","unbind","clone","resolveError"],"mappings":";;AASA;AACA;AACA;AACA;AACA;AACA;;AA8FA;AACA;AACA;AACA;AACO,SAASA,2BAA2B,GAA+B;EACxE,MAAMC,YAAY,GAAG,MAAM;AACzB,IAAA,MAAM,IAAIC,mCAAmC,CAC3C,4BAA4B,EAC5B,UAAU,CACX,CAAA;GACF,CAAA;EACD,OAAO;AACLC,IAAAA,GAAG,EAAEF,YAAY;AACjBG,IAAAA,GAAG,EAAEH,YAAY;AACjBI,IAAAA,YAAY,EAAEJ,YAAY;AAC1BK,IAAAA,GAAG,EAAEL,YAAY;AACjBM,IAAAA,GAAG,EAAEN,YAAY;AACjBO,IAAAA,IAAI,EAAEP,YAAY;AAClBQ,IAAAA,MAAM,EAAER,YAAY;AACpBS,IAAAA,KAAK,EAAET,YAAY;AACnBU,IAAAA,YAAY,EAAEV,YAAAA;GACf,CAAA;AACH;;;;"}