This is an automated email from the ASF dual-hosted git repository. glynnbird pushed a commit to branch fetch in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 2b5e5af7977fdd6d268d800da0f8591b9f6c1c3e Author: Glynn Bird <[email protected]> AuthorDate: Thu Dec 15 09:49:35 2022 +0000 tidy up --- lib/nano.d.ts | 11 ++++++++--- lib/nano.js | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/nano.d.ts b/lib/nano.d.ts index d40d307..4dbd3a5 100644 --- a/lib/nano.d.ts +++ b/lib/nano.d.ts @@ -19,6 +19,8 @@ /// <reference types="node" /> import { EventEmitter } from "events"; +import { ConnectionOptions } from "tls"; +import undici from "undici"; /** nano entry function */ declare function nano( @@ -27,8 +29,11 @@ declare function nano( declare namespace nano { /** AgentOptionsConnect options */ - interface AgentOptionsConnect { - timeout?: number + interface AgentOptionsConnect extends ConnectionOptions { + socketPath: string, + maxCachedSessions: number, + timeout?: number, + servername: string } /** AgentOptions options */ interface AgentOptions { @@ -57,7 +62,7 @@ declare namespace nano { /** HTTP Agent options * @see README: {@link https://www.npmjs.com/package/nano#pool-size-and-open-sockets} */ - agent?: AgentOptions; + agentOptions?: AgentOptions | typeof undici.Agent | typeof undici.MockAgent | typeof undici.Dispatcher; /** Logging function * @see README: {@link https://www.npmjs.com/package/nano#logging} */ diff --git a/lib/nano.js b/lib/nano.js index 79bce3e..2836411 100644 --- a/lib/nano.js +++ b/lib/nano.js @@ -15,7 +15,7 @@ const assert = require('assert') const stream = require('stream') const Readable = stream.Readable const undici = require('undici') -const fetch = global.fetch || undici.fetch +const fetcher = fetch || global.fetch || undici.fetch const ChangesReader = require('./changesreader.js') const CookieJar = require('./cookie.js') const MultiPartFactory = require('./multipart.js') @@ -438,7 +438,7 @@ module.exports = exports = function dbScope (cfg) { if (opts.stream) { // return the Request object for streaming const outStream = new stream.PassThrough() - fetch(fetchOptions.url, fetchOptions).then((response) => { + fetcher(fetchOptions.url, fetchOptions).then((response) => { const readableWebStream = response.body const readableNodeStream = Readable.fromWeb ? Readable.fromWeb(readableWebStream) : Readable.from(readableWebStream) if (response.status > 300) { @@ -452,14 +452,14 @@ module.exports = exports = function dbScope (cfg) { return outStream } else { if (typeof callback === 'function') { - fetch(fetchOptions.url, fetchOptions).then((response) => { + fetcher(fetchOptions.url, fetchOptions).then((response) => { responseHandler(response, fetchOptions, opts, null, null, callback) }).catch((e) => { responseHandler(e, fetchOptions, opts, null, null, callback) }) } else { return new Promise((resolve, reject) => { - fetch(fetchOptions.url, fetchOptions).then((response) => { + fetcher(fetchOptions.url, fetchOptions).then((response) => { responseHandler(response, fetchOptions, opts, resolve, reject) }).catch((e) => { responseHandler(e, fetchOptions, opts, resolve, reject)
