UNPKG

bandcamp-fetch

Version:
71 lines 3.57 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _LimiterAutocompleteAPI_limiter; Object.defineProperty(exports, "__esModule", { value: true }); exports.LimiterAutocompleteAPI = exports.AutocompleteItemType = void 0; const Constants_js_1 = require("../utils/Constants.js"); const AutocompleteResultsParser_js_1 = __importDefault(require("./AutocompleteResultsParser.js")); const BaseAPI_js_1 = __importDefault(require("../common/BaseAPI.js")); const Fetcher_js_1 = require("../utils/Fetcher.js"); var AutocompleteItemType; (function (AutocompleteItemType) { AutocompleteItemType["Tag"] = "Tag"; AutocompleteItemType["Location"] = "Location"; })(AutocompleteItemType || (exports.AutocompleteItemType = AutocompleteItemType = {})); class AutocompleteAPI extends BaseAPI_js_1.default { getSuggestions(params) { if (params.itemType === AutocompleteItemType.Tag) { return this.getAutocompleteTags(params); } return this.getAutocompleteLocations(params); } /** * @internal */ async getAutocompleteTags(params) { const payload = { prefix: params.query }; const json = await this.fetch(Constants_js_1.URLS.AUTOCOMPLETE.TAG, true, Fetcher_js_1.FetchMethod.POST, payload); return AutocompleteResultsParser_js_1.default.parseTags(json); } /** * @internal */ async getAutocompleteLocations(params) { const payload = { q: params.query, n: params.limit || 5, geocoder_fallback: true }; const json = await this.fetch(Constants_js_1.URLS.AUTOCOMPLETE.LOCATION, true, Fetcher_js_1.FetchMethod.POST, payload); return AutocompleteResultsParser_js_1.default.parseLocations(json); } } exports.default = AutocompleteAPI; class LimiterAutocompleteAPI extends AutocompleteAPI { constructor(params) { super(params); _LimiterAutocompleteAPI_limiter.set(this, void 0); __classPrivateFieldSet(this, _LimiterAutocompleteAPI_limiter, params.limiter, "f"); } getSuggestions(params) { return __classPrivateFieldGet(this, _LimiterAutocompleteAPI_limiter, "f").schedule(() => super.getSuggestions(params)); } } exports.LimiterAutocompleteAPI = LimiterAutocompleteAPI; _LimiterAutocompleteAPI_limiter = new WeakMap(); //# sourceMappingURL=AutocompleteAPI.js.map