Comparing version 10.0.0 to 10.1.0
const EventEmitter = require('events').EventEmitter | ||
const AbortController = global.AbortController || require('node-abort-controller').AbortController | ||
const stream = require('stream') | ||
@@ -106,2 +107,3 @@ const EVENT_BATCH = 'batch' | ||
this.paused = false | ||
this.abortController = null | ||
} | ||
@@ -120,2 +122,5 @@ | ||
this.continue = false | ||
if (this.abortController) { | ||
this.abortController.abort() | ||
} | ||
} | ||
@@ -153,2 +158,3 @@ | ||
if (!self.paused) { | ||
self.abortController = new AbortController() | ||
// formulate changes feed longpoll HTTP request | ||
@@ -159,2 +165,3 @@ const req = { | ||
path: '_changes', | ||
signal: self.abortController.signal, | ||
qs: { | ||
@@ -181,2 +188,3 @@ feed: 'longpoll', | ||
const data = await self.request(req) | ||
self.abortController = null | ||
delay = 0 | ||
@@ -183,0 +191,0 @@ |
141
lib/nano.js
@@ -13,18 +13,15 @@ // Licensed under the Apache License, Version 2.0 (the 'License'); you may not | ||
const { HttpsCookieAgent, HttpCookieAgent } = require('http-cookie-agent/http') | ||
const { URL } = require('url') | ||
const assert = require('assert') | ||
const querystring = require('qs') | ||
const axios = require('axios').default | ||
const axiosCookieJarSupport = require('axios-cookiejar-support').default | ||
const tough = require('tough-cookie') | ||
axiosCookieJarSupport(axios) | ||
const cookieJar = new tough.CookieJar() | ||
const axios = require('axios') | ||
const { CookieJar } = require('tough-cookie') | ||
const cookieJar = new CookieJar() | ||
const stream = require('stream') | ||
const http = require('http') | ||
const https = require('https') | ||
const pkg = require('../package.json') | ||
const AGENT_DEFAULTS = { keepAlive: true, maxSockets: 50, keepAliveMsecs: 30000 } | ||
const AGENT_DEFAULTS = { jar: cookieJar, keepAlive: true, maxSockets: 50, keepAliveMsecs: 30000 } | ||
const SCRUBBED_STR = 'XXXXXX' | ||
const defaultHttpAgent = new http.Agent(AGENT_DEFAULTS) | ||
const defaultHttpsAgent = new https.Agent(AGENT_DEFAULTS) | ||
const defaultHttpAgent = new HttpCookieAgent(AGENT_DEFAULTS) | ||
const defaultHttpsAgent = new HttpsCookieAgent(AGENT_DEFAULTS) | ||
const ChangesReader = require('./changesreader.js') | ||
@@ -133,6 +130,16 @@ const MultiPartFactory = require('./multipart.js') | ||
uri: scrubURL(req.url), | ||
statusCode: statusCode | ||
statusCode | ||
}, response.headers) | ||
if (!response.status) { | ||
log({ err: 'socket', body: body, headers: responseHeaders }) | ||
if (axios.isCancel(response)) { | ||
if (resolve) { | ||
resolve('canceled') | ||
} | ||
if (callback) { | ||
callback(null, 'canceled', responseHeaders) | ||
} | ||
return | ||
} | ||
log({ err: 'socket', body, headers: responseHeaders }) | ||
if (reject) { | ||
@@ -142,7 +149,5 @@ reject(new Error(`error happened in your connection. Reason: ${response.message}`)) | ||
if (callback) { | ||
const returnError = { | ||
message: `error happened in your connection. Reason: ${response.message}`, | ||
scope: 'socket', | ||
errid: 'request' | ||
} | ||
const returnError = new Error(`error happened in your connection. Reason: ${response.message}`) | ||
returnError.scope = 'socket' | ||
returnError.errid = 'request' | ||
callback(returnError) | ||
@@ -163,3 +168,3 @@ } | ||
if (statusCode >= 200 && statusCode < 400) { | ||
log({ err: null, body: body, headers: responseHeaders }) | ||
log({ err: null, body, headers: responseHeaders }) | ||
if (resolve) { | ||
@@ -189,3 +194,3 @@ resolve(body) | ||
log({ err: 'couch', body: body, headers: responseHeaders }) | ||
log({ err: 'couch', body, headers: responseHeaders }) | ||
@@ -226,3 +231,3 @@ const message = body.message || 'couch returned ' + statusCode | ||
uri: req.url, | ||
statusCode: statusCode | ||
statusCode | ||
}, response.headers) | ||
@@ -271,3 +276,3 @@ | ||
method: (opts.method || 'GET'), | ||
headers: headers, | ||
headers, | ||
uri: cfg.url | ||
@@ -282,2 +287,6 @@ }, { | ||
if (opts.signal) { | ||
req.signal = opts.signal | ||
} | ||
if (isJar) { | ||
@@ -387,4 +396,4 @@ req.jar = cookieJar | ||
delete req.qs | ||
req.paramsSerializer = (params) => { | ||
return querystring.stringify(params, { arrayFormat: 'brackets' }) | ||
req.paramsSerializer = { | ||
serialize: (params) => querystring.stringify(params, { arrayFormat: 'brackets' }) | ||
} | ||
@@ -412,2 +421,8 @@ req.data = req.body | ||
req.httpsAgent = cfg.requestDefaults.agent || defaultHttpsAgent | ||
req.httpAgent.jar = req.httpAgent.jar ? req.httpAgent.jar : cookieJar | ||
req.httpsAgent.jar = req.httpsAgent.jar ? req.httpsAgent.jar : cookieJar | ||
const ax = axios.create({ | ||
httpAgent: req.httpAgent, | ||
httpsAgent: req.httpsAgent | ||
}) | ||
@@ -418,3 +433,3 @@ // actually do the HTTP request | ||
const outStream = new stream.PassThrough() | ||
axios(req) | ||
ax(req) | ||
.then((response) => { | ||
@@ -428,3 +443,3 @@ response.data.pipe(outStream) | ||
if (typeof callback === 'function') { | ||
axios(req).then((response) => { | ||
ax(req).then((response) => { | ||
responseHandler(response, req, opts, null, null, callback) | ||
@@ -436,3 +451,3 @@ }).catch((e) => { | ||
return new Promise((resolve, reject) => { | ||
axios(req).then((response) => { | ||
ax(req).then((response) => { | ||
responseHandler(response, req, opts, resolve, reject) | ||
@@ -454,3 +469,3 @@ }).catch((e) => { | ||
name: username, | ||
password: password | ||
password | ||
} | ||
@@ -581,3 +596,3 @@ }, callback) | ||
count = count || 1 | ||
return relax({ method: 'GET', path: '_uuids', qs: { count: count } }, callback) | ||
return relax({ method: 'GET', path: '_uuids', qs: { count } }, callback) | ||
} | ||
@@ -619,3 +634,3 @@ | ||
path: id, | ||
qs: Object.assign(opts, { rev: rev }) | ||
qs: Object.assign(opts, { rev }) | ||
} | ||
@@ -662,3 +677,3 @@ return relax(req, callback) | ||
method: 'DELETE', | ||
qs: { rev: rev } | ||
qs: { rev } | ||
}, callback) | ||
@@ -792,3 +807,3 @@ } | ||
qs: qs1, | ||
body: body, | ||
body, | ||
stream: meta.stream | ||
@@ -804,3 +819,3 @@ }, callback) | ||
qs: qs1, | ||
body: body | ||
body | ||
}, callback) | ||
@@ -865,3 +880,3 @@ } else { | ||
method: 'PUT', | ||
body: body | ||
body | ||
}, callback) | ||
@@ -933,4 +948,4 @@ } | ||
doc: docName, | ||
qs: qs, | ||
multipart: multipart | ||
qs, | ||
multipart | ||
}, callback) | ||
@@ -966,3 +981,3 @@ } | ||
method: 'PUT', | ||
contentType: contentType, | ||
contentType, | ||
doc: docName, | ||
@@ -1014,3 +1029,3 @@ qs: opts, | ||
doc: docName, | ||
qs: qs | ||
qs | ||
}, callback) | ||
@@ -1082,3 +1097,3 @@ } | ||
path: '_partition/' + encodeURIComponent(partitionKey) + '/_all_docs', | ||
qs: qs, | ||
qs, | ||
stream: true | ||
@@ -1169,4 +1184,4 @@ }) | ||
changesReader: new ChangesReader(dbName, relax), | ||
auth: auth, | ||
session: session, | ||
auth, | ||
session, | ||
insert: insertDoc, | ||
@@ -1180,3 +1195,3 @@ get: getDoc, | ||
fetch: fetchDocs, | ||
fetchRevs: fetchRevs, | ||
fetchRevs, | ||
config: { url: cfg.url, db: dbName }, | ||
@@ -1195,3 +1210,3 @@ multipart: { | ||
atomic: updateWithHandler, | ||
updateWithHandler: updateWithHandler, | ||
updateWithHandler, | ||
baseView: view, | ||
@@ -1202,7 +1217,7 @@ search: viewSearch, | ||
viewAsStream: viewDocsAsStream, | ||
find: find, | ||
findAsStream: findAsStream, | ||
createIndex: createIndex, | ||
viewWithList: viewWithList, | ||
viewWithListAsStream: viewWithListAsStream, | ||
find, | ||
findAsStream, | ||
createIndex, | ||
viewWithList, | ||
viewWithListAsStream, | ||
server: serverScope, | ||
@@ -1220,11 +1235,11 @@ replication: { | ||
}, | ||
partitionInfo: partitionInfo, | ||
partitionedList: partitionedList, | ||
partitionedListAsStream: partitionedListAsStream, | ||
partitionedFind: partitionedFind, | ||
partitionedFindAsStream: partitionedFindAsStream, | ||
partitionedSearch: partitionedSearch, | ||
partitionedSearchAsStream: partitionedSearchAsStream, | ||
partitionedView: partitionedView, | ||
partitionedViewAsStream: partitionedViewAsStream | ||
partitionInfo, | ||
partitionedList, | ||
partitionedListAsStream, | ||
partitionedFind, | ||
partitionedFindAsStream, | ||
partitionedSearch, | ||
partitionedSearchAsStream, | ||
partitionedView, | ||
partitionedViewAsStream | ||
} | ||
@@ -1257,3 +1272,3 @@ | ||
changes: changesDb, | ||
updates: updates | ||
updates | ||
}, | ||
@@ -1263,9 +1278,9 @@ use: docModule, | ||
request: relax, | ||
relax: relax, | ||
relax, | ||
dinosaur: relax, | ||
auth: auth, | ||
session: session, | ||
updates: updates, | ||
uuids: uuids, | ||
info: info | ||
auth, | ||
session, | ||
updates, | ||
uuids, | ||
info | ||
}) | ||
@@ -1272,0 +1287,0 @@ |
@@ -7,3 +7,3 @@ { | ||
"repository": "http://github.com/apache/couchdb-nano", | ||
"version": "10.0.0", | ||
"version": "10.1.0", | ||
"author": "Apache CouchDB <dev@couchdb.apache.org> (http://couchdb.apache.org)", | ||
@@ -21,14 +21,15 @@ "keywords": [ | ||
"dependencies": { | ||
"@types/tough-cookie": "^4.0.0", | ||
"axios": "^0.26.1", | ||
"axios-cookiejar-support": "^1.0.1", | ||
"qs": "^6.10.3", | ||
"tough-cookie": "^4.0.0" | ||
"http-cookie-agent": "^4.0.2", | ||
"@types/tough-cookie": "^4.0.2", | ||
"axios": "^1.1.3", | ||
"qs": "^6.11.0", | ||
"tough-cookie": "^4.1.2", | ||
"node-abort-controller": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.22", | ||
"jest": "^27.5.1", | ||
"nock": "^13.2.4", | ||
"standard": "^16.0.4", | ||
"typescript": "^4.1.3" | ||
"@types/node": "^18.11.9", | ||
"jest": "^29.2.2", | ||
"nock": "^13.2.9", | ||
"standard": "^17.0.0", | ||
"typescript": "^4.8.4" | ||
}, | ||
@@ -43,3 +44,3 @@ "scripts": { | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14" | ||
}, | ||
@@ -46,0 +47,0 @@ "pre-commit": [ |
@@ -522,3 +522,3 @@ [![NPM](http://img.shields.io/npm/v/nano.svg?style=flat-square)](https://www.npmjs.com/package/nano) | ||
const alice = nano.use('alice') | ||
const response alice.insert({ _id: 'myid', happy: true }) | ||
const response = await alice.insert({ _id: 'myid', happy: true }) | ||
``` | ||
@@ -549,3 +549,3 @@ | ||
or with optional query string `params`: | ||
or with optional [query string `params`](https://docs.couchdb.org/en/stable/api/document/common.html#get--db-docid): | ||
@@ -556,2 +556,10 @@ ```js | ||
If you pass `attachments=true`, the `doc._attachments.attachmentNameN.data` fields will contain the | ||
[base-64 encoded attachments](https://docs.couchdb.org/en/stable/json-structure.html#document-with-attachments). | ||
Or, you can use [`db.multipart.get`](https://github.com/DougReeder/couchdb-nano#dbmultipartgetdocname-params-callback) | ||
and parse the returned buffer to get the document and attachments. | ||
See the [attachments methods](https://github.com/apache/couchdb-nano#attachments-functions) to retrieve | ||
*just* an attachment. | ||
### db.head(docname, [callback]) | ||
@@ -648,3 +656,3 @@ | ||
1. `changesReader.start()` - to listen to changes indefinitely by repeated "long poll" requests. This mode continues to poll for changes forever. | ||
1. `changesReader.start()` - to listen to changes indefinitely by repeated "long poll" requests. This mode continues to poll for changes until `changesReader.stop()` is called, at which point any active long poll will be canceled. | ||
2. `changesReader.get()` - to listen to changes until the end of the changes feed is reached, by repeated "long poll" requests. Once a response with zero changes is received, the 'end' event will indicate the end of the changes and polling will stop. | ||
@@ -964,3 +972,3 @@ 3. `changesReader.spool()` - listen to changes in one long HTTP request. (as opposed to repeated round trips) - spool is faster but less reliable. | ||
Get `docname` together with its attachments via `multipart/related` request with optional query string additions `params`. The multipart response body is a `Buffer`. | ||
Get `docname` together with its attachments via `multipart/related` request with optional [query string additions](https://docs.couchdb.org/en/stable/api/document/common.html#get--db-docid). The multipart response body is a `Buffer`. | ||
@@ -967,0 +975,0 @@ ```js |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
177289
2986
1366
1
6
+ Addedhttp-cookie-agent@^4.0.2
+ Addednode-abort-controller@^3.0.1
+ Addedagent-base@6.0.2(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.7(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedhttp-cookie-agent@4.0.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-abort-controller@3.1.1(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
- Removedaxios-cookiejar-support@^1.0.1
- Removedaxios@0.26.1(transitive)
- Removedaxios-cookiejar-support@1.0.1(transitive)
- Removedis-redirect@1.0.0(transitive)
- Removedpify@5.0.0(transitive)
Updated@types/tough-cookie@^4.0.2
Updatedaxios@^1.1.3
Updatedqs@^6.11.0
Updatedtough-cookie@^4.1.2