Source: bemap-services-v2/search/bemap-autocomplete-v2.js

/**
 * BeNomad BeMap JavaScript API - Autocomplete v1.5 extension
 *
 * Adds a Promise-based `autocomplete(request)` to the existing
 * `bemap.Autocomplete` prototype — a **pure HTTP mapper** matching the
 * Flutter SDK `AutocompleteServer.autocomplete(request)` pattern.
 *
 * The DOM glue (debounced typeahead with keyboard navigation) lives in the
 * separate `bemap.helpers.attachAutocompleteToInput(service, input, opts)`
 * helper. A thin `prototype.attachToInput` delegate is preserved here for
 * ergonomics and backward-compat with code that already uses it.
 *
 * The legacy `query(map, query, listener)` and `autocomp(...)` methods are
 * left intact for retrocompat with code that still uses the jQuery-based
 * helper.
 *
 * @since 1.5.0
 */
(function() {

    if (typeof bemap === 'undefined' || !bemap.Autocomplete) return;

    /**
     * Lazily build a ServiceV2 helper instance bound to this Autocomplete's context.
     * @private
     */
    bemap.Autocomplete.prototype._v2 = function() {
        if (!this._v2Instance) {
            this._v2Instance = new bemap.ServiceV2(this.context, {});
        }
        return this._v2Instance;
    };

    /**
     * Send a typed autocomplete request. Pure HTTP mapper — no DOM, no map.
     *
     * @public
     * @since 1.5.0
     * @param {bemap.AutocompleteGeocodingRequest} request
     * @param {Object} [options]
     * @param {String} [options.geoserver]
     * @param {AbortSignal} [options.signal]
     * @return {Promise<bemap.AutocompleteGeocodingResponse>}
     */
    bemap.Autocomplete.prototype.autocomplete = function(request, options) {
        if (!(request instanceof bemap.AutocompleteGeocodingRequest)) {
            return Promise.reject(new bemap.Error({
                code: bemap.Error.NETWORK,
                message: 'Autocomplete.autocomplete requires a bemap.AutocompleteGeocodingRequest'
            }));
        }
        var opts = options || {};
        var body = request.toJson();
        body.geoserver = opts.geoserver || this.geoserver
            || (this.context && this.context.getGeoserver && this.context.getGeoserver());

        return this._v2()._post('service/geocoding/autocomplete/1.0', body, opts)
            .then(function(json) {
                return bemap.AutocompleteGeocodingResponse.fromJson(json);
            });
    };

    /**
     * Thin delegate to `bemap.helpers.attachAutocompleteToInput`. Kept on
     * the prototype for ergonomics. The full implementation (and full
     * JSDoc parameter list) lives in `bemap-autocomplete-attach.js`.
     *
     * @public
     * @since 1.5.0
     * @param {HTMLInputElement} inputEl
     * @param {Object} options See `bemap.helpers.attachAutocompleteToInput`.
     * @return {{ destroy: Function }}
     */
    bemap.Autocomplete.prototype.attachToInput = function(inputEl, options) {
        return bemap.helpers.attachAutocompleteToInput(this, inputEl, options);
    };

})();