{"version":3,"file":"resolver.cjs","sources":["../../../../src/resolver/generic/resolver.js"],"sourcesContent":["import { ensureString } from '../../utils';\nimport { WILDCARD } from './const';\n\n/**\n * @class\n * @abstract\n * @template T\n */\nclass Resolver {\n  /**\n   * Matching prefix - either a string, array of strings or wildcard pattern.\n   * @type {Array<string> | string | symbol}\n   * @prop prefix\n   */\n\n  /**\n   * Matching method - either a string, array of strings or wildcard pattern.\n   * @type {Array<string> | string | symbol}\n   * @prop method\n   *\n\n  /**\n   * Returns `true` if an entity with the provided identifier can be resolved using this resolver.\n   * @param {string} id - fully qualified identifier.\n   * @returns {boolean}\n   */\n  supports(id) {\n    ensureString(id);\n    const methods = [].concat(this.method);\n    const prefixes = [].concat(this.prefix);\n\n    return (\n      (methods.includes(WILDCARD)\n        || methods.includes(this.extractMethod(id)))\n      && (prefixes.includes(WILDCARD) || prefixes.includes(this.extractPrefix(id)))\n    );\n  }\n\n  /**\n   * Resolves an entity with the provided identifier.\n   * @abstract\n   * @param {string} id - fully qualified identifier.\n   * @returns {Promise<T>}\n   */\n  async resolve(id) {\n    throw new Error(\n      `Unimplemented \\`resolve\\` for \\`${this.constructor.name}\\`, can't resolve \\`${id}\\``,\n    );\n  }\n\n  /**\n   * Extracts a prefix from the provided identifier.\n   *\n   * @param {string} id\n   * @returns {string}\n   */\n  extractPrefix(id) {\n    ensureString(id);\n    const end = id.indexOf(':');\n\n    // eslint-disable-next-line no-bitwise\n    return ~end ? id.slice(0, end) : '';\n  }\n\n  /**\n   * Extracts a method from the provided identifier.\n   *\n   * @param {string} id\n   * @returns {string}\n   */\n  extractMethod(id) {\n    ensureString(id);\n    const start = id.indexOf(':');\n    const end = id.indexOf(':', start + 1);\n\n    // eslint-disable-next-line no-bitwise\n    return ~start && ~end ? id.slice(start + 1, end) : '';\n  }\n}\n\n/**\n * Resolves an entity if its identifier is supported.\n * Each resolver must have static `string` or `WILDCARD` symbol properties `prefix` and `METHOD`,\n * then the `supports` method will return `true` if they match the identifier.\n * In case the resolver must be used for any `prefix`/`METHOD` as default, use the `WILDCARD` symbol.\n */\nexport default Resolver;\n"],"names":["ensureString","WILDCARD"],"mappings":";;;;;;;;;;;;;AAGA;AACA;AACA;AACA;AACA;AACA,MAAM,QAAQ,CAAC;AACf;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,EAAE,QAAQ,CAAC,EAAE,EAAE;AACf,IAAIA,kBAAY,CAAC,EAAE,CAAC;AACpB,IAAI,MAAM,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;AAC1C,IAAI,MAAM,QAAQ,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;;AAE3C,IAAI;AACJ,MAAM,CAAC,OAAO,CAAC,QAAQ,CAACC,+BAAQ;AAChC,WAAW,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;AACnD,UAAU,QAAQ,CAAC,QAAQ,CAACA,+BAAQ,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;AAClF;AACA,EAAE;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,MAAM,OAAO,CAAC,EAAE,EAAE;AACpB,IAAI,MAAM,IAAI,KAAK;AACnB,MAAM,CAAC,gCAAgC,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAC,EAAE,CAAC;AAC3F,KAAK;AACL,EAAE;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,aAAa,CAAC,EAAE,EAAE;AACpB,IAAID,kBAAY,CAAC,EAAE,CAAC;AACpB,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;;AAE/B;AACA,IAAI,OAAO,CAAC,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC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