opusdev/vector-similarity-api
1
1'use strict'2 3const Client = require('./lib/dispatcher/client')4const Dispatcher = require('./lib/dispatcher/dispatcher')5const Pool = require('./lib/dispatcher/pool')6const BalancedPool = require('./lib/dispatcher/balanced-pool')7const Agent = require('./lib/dispatcher/agent')8const ProxyAgent = require('./lib/dispatcher/proxy-agent')9const EnvHttpProxyAgent = require('./lib/dispatcher/env-http-proxy-agent')10const RetryAgent = require('./lib/dispatcher/retry-agent')11const errors = require('./lib/core/errors')12const util = require('./lib/core/util')13const { InvalidArgumentError } = errors14const api = require('./lib/api')15const buildConnector = require('./lib/core/connect')16const MockClient = require('./lib/mock/mock-client')17const MockAgent = require('./lib/mock/mock-agent')18const MockPool = require('./lib/mock/mock-pool')19const mockErrors = require('./lib/mock/mock-errors')20const RetryHandler = require('./lib/handler/retry-handler')21const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global')22const DecoratorHandler = require('./lib/handler/decorator-handler')23const RedirectHandler = require('./lib/handler/redirect-handler')24const createRedirectInterceptor = require('./lib/interceptor/redirect-interceptor')25 26Object.assign(Dispatcher.prototype, api)27 28module.exports.Dispatcher = Dispatcher29module.exports.Client = Client30module.exports.Pool = Pool31module.exports.BalancedPool = BalancedPool32module.exports.Agent = Agent33module.exports.ProxyAgent = ProxyAgent34module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent35module.exports.RetryAgent = RetryAgent36module.exports.RetryHandler = RetryHandler37 38module.exports.DecoratorHandler = DecoratorHandler39module.exports.RedirectHandler = RedirectHandler40module.exports.createRedirectInterceptor = createRedirectInterceptor41module.exports.interceptors = {42 redirect: require('./lib/interceptor/redirect'),43 retry: require('./lib/interceptor/retry'),44 dump: require('./lib/interceptor/dump'),45 dns: require('./lib/interceptor/dns')46}47 48module.exports.buildConnector = buildConnector49module.exports.errors = errors50module.exports.util = {51 parseHeaders: util.parseHeaders,52 headerNameToString: util.headerNameToString53}54 55function makeDispatcher (fn) {56 return (url, opts, handler) => {57 if (typeof opts === 'function') {58 handler = opts59 opts = null60 }61 62 if (!url || (typeof url !== 'string' && typeof url !== 'object' && !(url instanceof URL))) {63 throw new InvalidArgumentError('invalid url')64 }65 66 if (opts != null && typeof opts !== 'object') {67 throw new InvalidArgumentError('invalid opts')68 }69 70 if (opts && opts.path != null) {71 if (typeof opts.path !== 'string') {72 throw new InvalidArgumentError('invalid opts.path')73 }74 75 let path = opts.path76 if (!opts.path.startsWith('/')) {77 path = `/${path}`78 }79 80 url = new URL(util.parseOrigin(url).origin + path)81 } else {82 if (!opts) {83 opts = typeof url === 'object' ? url : {}84 }85 86 url = util.parseURL(url)87 }88 89 const { agent, dispatcher = getGlobalDispatcher() } = opts90 91 if (agent) {92 throw new InvalidArgumentError('unsupported opts.agent. Did you mean opts.client?')93 }94 95 return fn.call(dispatcher, {96 ...opts,97 origin: url.origin,98 path: url.search ? `${url.pathname}${url.search}` : url.pathname,99 method: opts.method || (opts.body ? 'PUT' : 'GET')100 }, handler)101 }102}103 104module.exports.setGlobalDispatcher = setGlobalDispatcher105module.exports.getGlobalDispatcher = getGlobalDispatcher106 107const fetchImpl = require('./lib/web/fetch').fetch108module.exports.fetch = async function fetch (init, options = undefined) {109 try {110 return await fetchImpl(init, options)111 } catch (err) {112 if (err && typeof err === 'object') {113 Error.captureStackTrace(err)114 }115 116 throw err117 }118}119module.exports.Headers = require('./lib/web/fetch/headers').Headers120module.exports.Response = require('./lib/web/fetch/response').Response121module.exports.Request = require('./lib/web/fetch/request').Request122module.exports.FormData = require('./lib/web/fetch/formdata').FormData123module.exports.File = globalThis.File ?? require('node:buffer').File124module.exports.FileReader = require('./lib/web/fileapi/filereader').FileReader125 126const { setGlobalOrigin, getGlobalOrigin } = require('./lib/web/fetch/global')127 128module.exports.setGlobalOrigin = setGlobalOrigin129module.exports.getGlobalOrigin = getGlobalOrigin130 131const { CacheStorage } = require('./lib/web/cache/cachestorage')132const { kConstruct } = require('./lib/web/cache/symbols')133 134// Cache & CacheStorage are tightly coupled with fetch. Even if it may run135// in an older version of Node, it doesn't have any use without fetch.136module.exports.caches = new CacheStorage(kConstruct)137 138const { deleteCookie, getCookies, getSetCookies, setCookie } = require('./lib/web/cookies')139 140module.exports.deleteCookie = deleteCookie141module.exports.getCookies = getCookies142module.exports.getSetCookies = getSetCookies143module.exports.setCookie = setCookie144 145const { parseMIMEType, serializeAMimeType } = require('./lib/web/fetch/data-url')146 147module.exports.parseMIMEType = parseMIMEType148module.exports.serializeAMimeType = serializeAMimeType149 150const { CloseEvent, ErrorEvent, MessageEvent } = require('./lib/web/websocket/events')151module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket152module.exports.CloseEvent = CloseEvent153module.exports.ErrorEvent = ErrorEvent154module.exports.MessageEvent = MessageEvent155 156module.exports.request = makeDispatcher(api.request)157module.exports.stream = makeDispatcher(api.stream)158module.exports.pipeline = makeDispatcher(api.pipeline)159module.exports.connect = makeDispatcher(api.connect)160module.exports.upgrade = makeDispatcher(api.upgrade)161 162module.exports.MockClient = MockClient163module.exports.MockPool = MockPool164module.exports.MockAgent = MockAgent165module.exports.mockErrors = mockErrors166 167const { EventSource } = require('./lib/web/eventsource/eventsource')168 169module.exports.EventSource = EventSource170 