'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var configure = require('../lib/configure.js');
var toUrlSearchParams = require('../lib/to-url-search-params.js');
var httpRpcWireFormat = require('../lib/http-rpc-wire-format.js');

const createPeers = configure.configure(api => {
  async function peers(topic, options = {}) {
    const res = await api.post('pubsub/peers', {
      signal: options.signal,
      searchParams: toUrlSearchParams.toUrlSearchParams({
        arg: httpRpcWireFormat.textToUrlSafeRpc(topic),
        ...options
      }),
      headers: options.headers
    });
    const {Strings} = await res.json();
    return Strings || [];
  }
  return peers;
});

exports.createPeers = createPeers;
