You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2020/02/27 16:09:54 UTC
[couchdb-nano] branch axios created (now 58a38c7)
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a change to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git.
at 58a38c7 ensure tests run in env=node mode
This branch includes the following new commits:
new 07b4e63 stash changes
new 396c9ae merge conflict fixed
new 4c5d0fd remove db.copy function - axios does not support COPY HTTP method
new d60b9b0 alter the way attachment.insertAsStream works
new c918f77 typescript update
new 62c6864 Merge branch 'master' into axios
new cc7c571 combine attachment.insert attachment.insertAsStream
new 6469bf9 ensure db.head passes the test
new 132a70b configure default http agent, user-agent string and gzipping
new 8344ea6 added tests for gzip/user-agent headers + TypeScript defs
new afc6dc6 merge master into axios branch
new 58a38c7 ensure tests run in env=node mode
The 12 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[couchdb-nano] 12/12: ensure tests run in env=node mode
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 58a38c793c1977440a3fe149f3b251fd7d392ff4
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 27 16:06:03 2020 +0000
ensure tests run in env=node mode
---
README.md | 9 +--------
package-lock.json | 22 ++++++++++++++--------
package.json | 4 ++--
3 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md
index 7af5e3b..7a0eed3 100644
--- a/README.md
+++ b/README.md
@@ -1277,16 +1277,9 @@ To run (and configure) the test suite simply:
``` sh
cd nano
npm install
-npm test
+npm run test
```
-After adding a new test you can run it individually (with verbose output) using:
-
-``` sh
-nano_env=testing node tests/doc/list.js list_doc_params
-```
-
-where `list_doc_params` is the test name.
## Meta
diff --git a/package-lock.json b/package-lock.json
index ceea9f2..f3f82f7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4930,6 +4930,12 @@
"path-exists": "^3.0.0"
}
},
+ "lodash": {
+ "version": "4.17.15",
+ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
+ "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
+ "dev": true
+ },
"lodash.sortby": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
@@ -5126,22 +5132,22 @@
"dev": true
},
"nock": {
- "version": "11.7.2",
- "resolved": "https://registry.npmjs.org/nock/-/nock-11.7.2.tgz",
- "integrity": "sha512-7swr5bL1xBZ5FctyubjxEVySXOSebyqcL7Vy1bx1nS9IUqQWj81cmKjVKJLr8fHhtzI1MV8nyCdENA/cGcY1+Q==",
+ "version": "12.0.1",
+ "resolved": "https://registry.npmjs.org/nock/-/nock-12.0.1.tgz",
+ "integrity": "sha512-f5u5k7O5D2YXH2WEFQVLLPa36D5C0dxU9Lrg6KOuaFCMDt7yd1W4S3hbZClCMczxc4EZ0k1bEhPeMWSewrxYNw==",
"dev": true,
"requires": {
"debug": "^4.1.0",
"json-stringify-safe": "^5.0.1",
"lodash": "^4.17.13",
- "mkdirp": "^0.5.0",
+ "mkdirp": "^1.0.0",
"propagate": "^2.0.0"
},
"dependencies": {
- "lodash": {
- "version": "4.17.15",
- "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
- "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
+ "mkdirp": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.3.tgz",
+ "integrity": "sha512-6uCP4Qc0sWsgMLy1EOqqS/3rjDHOEnsStVr/4vtAIK2Y5i2kA7lFFejYrpIyiN9w0pYf4ckeCYT9f1r1P9KX5g==",
"dev": true
}
}
diff --git a/package.json b/package.json
index 4065aa5..d5303b9 100644
--- a/package.json
+++ b/package.json
@@ -25,14 +25,14 @@
},
"devDependencies": {
"jest": "^25.1.0",
- "nock": "^11.7.2",
+ "nock": "^12.0.1",
"standard": "^14.3.1",
"typescript": "^3.7.5"
},
"scripts": {
"standard": "standard --fix",
"test": "standard && tsc lib/nano.d.ts && npm run jest",
- "jest": "jest test/* --coverage"
+ "jest": "jest test/* --coverage --env node"
},
"main": "./lib/nano.js",
"types": "./lib/nano.d.ts",
[couchdb-nano] 03/12: remove db.copy function - axios does not
support COPY HTTP method
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 4c5d0fdde6ea59b31de299b298425e4456b34d16
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 13 15:00:05 2020 +0000
remove db.copy function - axios does not support COPY HTTP method
---
README.md | 12 ----
lib/nano.d.ts | 9 ---
lib/nano.js | 45 --------------
test/document.copy.test.js | 144 ---------------------------------------------
4 files changed, 210 deletions(-)
diff --git a/README.md b/README.md
index 94a2118..d5cd8bd 100644
--- a/README.md
+++ b/README.md
@@ -57,7 +57,6 @@ See [Migration Guide for switching from Nano 6.x to 7.x](migration_6_to_7.md).
- [db.destroy(docname, rev, [callback])](#dbdestroydocname-rev-callback)
- [db.get(docname, [params], [callback])](#dbgetdocname-params-callback)
- [db.head(docname, [callback])](#dbheaddocname-callback)
- - [db.copy(src_doc, dest_doc, opts, [callback])](#dbcopysrc_doc-dest_doc-opts-callback)
- [db.bulk(docs, [params], [callback])](#dbbulkdocs-params-callback)
- [db.list([params], [callback])](#dblistparams-callback)
- [db.listAsStream([params])](#dblistasstreamparams)
@@ -617,17 +616,6 @@ alice.head('rabbit').then((headers) => {
*Note:* if you call `alice.head` in the callback style, the headers are returned to you as the third argument of the callback function.
-### db.copy(src_doc, dest_doc, opts, [callback])
-
-Copies the contents (and attachments) of a document
-to a new document, or overwrite an existing target document
-
-```js
-alice.copy('rabbit', 'rabbit2', { overwrite: true }).then((body) => {
- console.log(body);
-});
-```
-
### db.bulk(docs, [params], [callback])
Bulk operations(update/delete/insert) on the database, refer to the
diff --git a/lib/nano.d.ts b/lib/nano.d.ts
index d91917c..4de9a95 100644
--- a/lib/nano.d.ts
+++ b/lib/nano.d.ts
@@ -150,15 +150,6 @@ declare namespace nano {
get(docname: string, params?: DocumentGetParams, callback?: Callback<DocumentGetResponse & D>): Promise<DocumentGetResponse & D>;
// http://docs.couchdb.org/en/latest/api/document/common.html#head--db-docid
head(docname: string, callback?: Callback<any>): Promise<any>;
- // http://docs.couchdb.org/en/latest/api/document/common.html#copy--db-docid
- copy(src_document: string, dst_document: string, callback?: Callback<DocumentCopyResponse>): Promise<DocumentCopyResponse>;
- // http://docs.couchdb.org/en/latest/api/document/common.html#copy--db-docid
- copy(
- src_document: string,
- dst_document: string,
- options: DocumentCopyOptions,
- callback?: Callback<DocumentCopyResponse>
- ): Promise<DocumentCopyResponse>;
// http://docs.couchdb.org/en/latest/api/document/common.html#delete--db-docid
destroy(docname: string, rev: string, callback?: Callback<DocumentDestroyResponse>): Promise<DocumentDestroyResponse>;
bulk(docs: BulkModifyDocsWrapper, callback?: Callback<DocumentInsertResponse[]>): Promise<DocumentInsertResponse[]>;
diff --git a/lib/nano.js b/lib/nano.js
index d7a5ac9..9268207 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -615,50 +615,6 @@ module.exports = exports = function dbScope (cfg) {
}
}
- // http://docs.couchdb.org/en/latest/api/document/common.html#copy--db-docid
- function copyDoc (docSrc, docDest, opts0, callback0) {
- const { opts, callback } = getCallback(opts0, callback0)
-
- if (missing(docSrc, docDest)) {
- return callbackOrRejectError(callback)
- }
-
- const qs = {
- db: dbName,
- doc: docSrc,
- method: 'COPY',
- headers: { Destination: docDest }
- }
-
- if (opts.overwrite) {
- const p = headDoc(docDest).then(
- function (h) {
- if (h.etag) {
- qs.headers.Destination += '?rev=' +
- h.etag.substring(1, h.etag.length - 1)
- }
- return relax(qs, callback)
- },
- function (e) {
- if (e && e.statusCode !== 404) {
- if (callback) {
- callback(e)
- } else {
- return Promise.reject(e)
- }
- } else {
- return relax(qs, callback)
- }
- }
- )
- if (!callback) {
- return p
- }
- } else {
- return relax(qs, callback)
- }
- }
-
// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#get--db-_all_docs
function listDoc (qs0, callback0) {
const { opts, callback } = getCallback(qs0, callback0)
@@ -1126,7 +1082,6 @@ module.exports = exports = function dbScope (cfg) {
insert: insertDoc,
get: getDoc,
head: headDoc,
- copy: copyDoc,
destroy: destroyDoc,
bulk: bulksDoc,
list: listDoc,
diff --git a/test/document.copy.test.js b/test/document.copy.test.js
deleted file mode 100644
index 47891f6..0000000
--- a/test/document.copy.test.js
+++ /dev/null
@@ -1,144 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-const Nano = require('..')
-const COUCH_URL = 'http://localhost:5984'
-const nano = Nano(COUCH_URL)
-const nock = require('nock')
-
-afterEach(() => {
- nock.cleanAll()
-})
-
-test('should be able to copy a document - db.copy', async () => {
- // mocks
- const response = { ok: true, id: 'rabbit2', rev: '1-123' }
- const scope = nock(COUCH_URL, { reqheaders: { destination: 'rabbit2' } })
- .intercept('/db/rabbit1', 'COPY')
- .reply(200, response)
-
- // test COPY /db/id
- const db = nano.db.use('db')
- const p = await db.copy('rabbit1', 'rabbit2')
- expect(p).toStrictEqual(response)
- expect(scope.isDone()).toBe(true)
-})
-
-test('should detect missing source doc id - db.copy', async () => {
- const db = nano.db.use('db')
- await expect(db.copy(undefined, 'rabbbit2')).rejects.toThrow('Invalid parameters')
-})
-
-test('should detect missing target doc id - db.copy', async () => {
- const db = nano.db.use('db')
- await expect(db.copy('rabbit1')).rejects.toThrow('Invalid parameters')
-})
-
-test('should be able to copy a document in overwrite mode - db.copy', async () => {
- // mocks
- const response = { ok: true, id: 'rabbit2', rev: '1-123' }
- const scope = nock(COUCH_URL)
- .head('/db/rabbit2')
- .reply(200, '', { ETag: '1-123' })
- .intercept('/db/rabbit1', 'COPY')
- .reply(200, response)
-
- // test HEAD /db/id2 + COPY /db/id1
- const db = nano.db.use('db')
- const p = await db.copy('rabbit1', 'rabbit2', { overwrite: true })
- expect(p).toStrictEqual(response)
- expect(scope.isDone()).toBe(true)
-})
-
-test('should be able to handle an error in overwrite mode # 1 - db.copy', async () => {
- // mocks
- const response = 'Internal server error'
- const scope = nock(COUCH_URL)
- .head('/db/rabbit2')
- .reply(200, '', { ETag: '1-123' })
- .intercept('/db/rabbit1', 'COPY')
- .reply(500, response)
-
- // test GET /db
- const db = nano.db.use('db')
- await expect(db.copy('rabbit1', 'rabbit2', { overwrite: true })).rejects.toThrow(response)
- expect(scope.isDone()).toBe(true)
-})
-
-test('should be able to handle an error in overwrite mode # 2 - db.copy', async () => {
- // mocks
- const response = 'Internal server error'
- const scope = nock(COUCH_URL)
- .head('/db/rabbit2')
- .reply(500, response)
-
- // test GET /db
- const db = nano.db.use('db')
- await expect(db.copy('rabbit1', 'rabbit2', { overwrite: true })).rejects.toThrow(response)
- expect(scope.isDone()).toBe(true)
-})
-
-test('should be able to handle an error in overwrite mode # 3 - db.copy', () => {
- // mocks
- const response = 'Internal server error'
- const scope = nock(COUCH_URL)
- .head('/db/rabbit2')
- .reply(500, response)
-
- // test GET /db
- return new Promise((resolve, reject) => {
- const db = nano.db.use('db')
- db.copy('rabbit1', 'rabbit2', { overwrite: true }, (err, data) => {
- expect(err).not.toBeNull()
- expect(scope.isDone()).toBe(true)
- resolve()
- })
- })
-})
-
-test('should be able to copy a document in overwrite mode missing target - db.copy', async () => {
- // mocks
- const response = { ok: true, id: 'rabbit2', rev: '1-123' }
- const errResponse = {
- error: 'not_found',
- reason: 'missing'
- }
- const scope = nock(COUCH_URL)
- .head('/db/rabbit2')
- .reply(404, errResponse)
- .intercept('/db/rabbit1', 'COPY')
- .reply(200, response)
-
- // test GET /db
- const db = nano.db.use('db')
- const p = await db.copy('rabbit1', 'rabbit2', { overwrite: true })
- expect(p).toStrictEqual(response)
- expect(scope.isDone()).toBe(true)
-})
-
-test('should detect invalid parameters - db.copy', async () => {
- const db = nano.db.use('db')
- await expect(db.copy()).rejects.toThrowError('Invalid parameters')
- await expect(db.copy('')).rejects.toThrowError('Invalid parameters')
- await expect(db.copy('', 'rabbit2')).rejects.toThrowError('Invalid parameters')
- await expect(db.copy('rabbit1', '')).rejects.toThrowError('Invalid parameters')
-})
-
-test('should detect missing parameters (callback) - db.copy', () => {
- return new Promise((resolve, reject) => {
- const db = nano.db.use('db')
- db.copy(undefined, undefined, (err, data) => {
- expect(err).not.toBeNull()
- resolve()
- })
- })
-})
[couchdb-nano] 09/12: configure default http agent,
user-agent string and gzipping
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 132a70bd5d22522f83c13a3318e6322c7d42b8de
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Fri Feb 14 08:10:25 2020 +0000
configure default http agent, user-agent string and gzipping
---
lib/nano.js | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/nano.js b/lib/nano.js
index ee76018..254aeee 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -19,6 +19,10 @@ const follow = require('cloudant-follow')
const logger = require('./logger')
const INVALID_PARAMETERS_ERROR = new Error('Invalid parameters')
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 }
function isEmpty (val) {
return val == null || !(Object.keys(val) || val).length
@@ -199,7 +203,9 @@ module.exports = exports = function dbScope (cfg) {
const headers = {
'content-type': 'application/json',
- accept: 'application/json'
+ accept: 'application/json',
+ 'user-agent': `${pkg.name}/${pkg.version} (Node.js ${process.version})`,
+ 'Accept-Encoding': 'deflate, gzip'
}
const req = Object.assign({
@@ -321,6 +327,8 @@ module.exports = exports = function dbScope (cfg) {
} else if (opts.dontParse) {
req.responseType = 'arraybuffer'
}
+ req.httpAgent = cfg.requestDefaults.agent || new http.Agent(AGENT_DEFAULTS)
+ req.httpsAgent = cfg.requestDefaults.agent || new https.Agent(AGENT_DEFAULTS)
// actually do the HTTP request
if (opts.stream) {
[couchdb-nano] 10/12: added tests for gzip/user-agent headers +
TypeScript defs
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 8344ea642088f0fb1166a9aa1260efc453581d86
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Fri Feb 14 08:15:26 2020 +0000
added tests for gzip/user-agent headers + TypeScript defs
---
lib/nano.d.ts | 2 ++
test/nano.request.test.js | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/lib/nano.d.ts b/lib/nano.d.ts
index 2e56b59..3ecac47 100644
--- a/lib/nano.d.ts
+++ b/lib/nano.d.ts
@@ -18,6 +18,8 @@ declare function nano(
declare namespace nano {
interface requestDefaultsOptions {
timeout: number;
+ agent: any;
+ headers: object;
};
interface Configuration {
diff --git a/test/nano.request.test.js b/test/nano.request.test.js
index 3b16df0..8b04158 100644
--- a/test/nano.request.test.js
+++ b/test/nano.request.test.js
@@ -474,3 +474,39 @@ test('check request doesn\'t mangle bodies containing functions - nano.request',
expect(p).toStrictEqual(response)
expect(scope.isDone()).toBe(true)
})
+
+test('check request sends user-agent header - nano.request', async () => {
+ // mocks
+ const response = { ok: true }
+ const scope = nock(COUCH_URL, { reqheaders: { 'user-agent': /^nano/ } })
+ .get('/db?a=1&b=2')
+ .reply(200, response)
+
+ // test GET /db?a=1&b=2
+ const req = {
+ method: 'get',
+ db: 'db',
+ qs: { a: 1, b: 2 }
+ }
+ const p = await nano.request(req)
+ expect(p).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
+})
+
+test('check request sends headers for gzipped responses - nano.request', async () => {
+ // mocks
+ const response = { ok: true }
+ const scope = nock(COUCH_URL, { reqheaders: { 'accept-encoding': /gzip/ } })
+ .get('/db?a=1&b=2')
+ .reply(200, response)
+
+ // test GET /db?a=1&b=2
+ const req = {
+ method: 'get',
+ db: 'db',
+ qs: { a: 1, b: 2 }
+ }
+ const p = await nano.request(req)
+ expect(p).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
+})
[couchdb-nano] 06/12: Merge branch 'master' into axios
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 62c68640964b7edab711c1654e3855b70c5f61d3
Merge: c918f77 df6c040
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 13 18:10:48 2020 +0000
Merge branch 'master' into axios
README.md | 2 +-
lib/nano.d.ts | 38 ++++++++++++++++++++++++++++----------
lib/nano.js | 2 +-
test/document.get.test.js | 14 ++++++++++++++
test/document.insert.test.js | 32 ++++++++++++++++++++++++++++++++
5 files changed, 76 insertions(+), 12 deletions(-)
diff --cc lib/nano.d.ts
index 3c648c8,c5d155b..a8ff89e
--- a/lib/nano.d.ts
+++ b/lib/nano.d.ts
@@@ -153,9 -151,18 +154,9 @@@ declare namespace nano
get(docname: string, params?: DocumentGetParams, callback?: Callback<DocumentGetResponse & D>): Promise<DocumentGetResponse & D>;
// http://docs.couchdb.org/en/latest/api/document/common.html#head--db-docid
head(docname: string, callback?: Callback<any>): Promise<any>;
- // http://docs.couchdb.org/en/latest/api/document/common.html#copy--db-docid
- copy(src_document: string, dst_document: string, callback?: Callback<DocumentCopyResponse>): Promise<DocumentCopyResponse>;
- // http://docs.couchdb.org/en/latest/api/document/common.html#copy--db-docid
- copy(
- src_document: string,
- dst_document: string,
- options: DocumentCopyOptions,
- callback?: Callback<DocumentCopyResponse>
- ): Promise<DocumentCopyResponse>;
// http://docs.couchdb.org/en/latest/api/document/common.html#delete--db-docid
destroy(docname: string, rev: string, callback?: Callback<DocumentDestroyResponse>): Promise<DocumentDestroyResponse>;
- bulk(docs: BulkModifyDocsWrapper, callback?: Callback<DocumentInsertResponse[]>): Promise<DocumentInsertResponse[]>;
+ bulk(docs: BulkModifyDocsWrapper, callback?: Callback<DocumentBulkResponse[]>): Promise<DocumentBulkResponse[]>;
bulk(docs: BulkModifyDocsWrapper, params: any, callback?: Callback<DocumentInsertResponse[]>): Promise<DocumentInsertResponse[]>;
// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#get--db-_all_docs
list(callback?: Callback<DocumentListResponse<D>>): Promise<DocumentListResponse<D>>;
[couchdb-nano] 04/12: alter the way attachment.insertAsStream works
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit d60b9b04547d922a44aa825ef09045201f9b2153
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 13 16:11:18 2020 +0000
alter the way attachment.insertAsStream works
---
README.md | 7 ++-----
lib/nano.d.ts | 8 ++++----
lib/nano.js | 1 -
test/attachment.insertAsStream.test.js | 22 ++++++----------------
4 files changed, 12 insertions(+), 26 deletions(-)
diff --git a/README.md b/README.md
index d5cd8bd..f383a3a 100644
--- a/README.md
+++ b/README.md
@@ -953,11 +953,8 @@ It may be more memory-efficient to pipe a stream of data from a source (file, ne
```js
const rs = fs.createReadStream('logo.png');
- const is = db.attachment.insertAsStream('mydoc', 'logo.png', null, 'image/png',
- { rev: '12-150985a725ec88be471921a54ce91452' }).on('end', () => {
- console.log('done')
- });
- rs.pipe(is);
+ const reply = await db.attachment.insertAsStream('mydoc', 'logo.png', rs, 'image/png',
+ { rev: '12-150985a725ec88be471921a54ce91452' })
```
### db.attachment.get(docname, attname, [params], [callback])
diff --git a/lib/nano.d.ts b/lib/nano.d.ts
index 4de9a95..e93f419 100644
--- a/lib/nano.d.ts
+++ b/lib/nano.d.ts
@@ -363,16 +363,16 @@ declare namespace nano {
insertAsStream(
docname: string,
attname: string,
- att: any,
+ att: NodeJS.ReadReadStream,
contenttype: string
- ): Request;
+ ): Promise<DocumentInsertResponse>;
insertAsStream(
docname: string,
attname: string,
- att: any,
+ att: NodeJS.ReadReadStream,
contenttype: string,
params: any
- ): Request
+ ): Promise<DocumentInsertResponse>
get(docname: string, attname: string, callback?: Callback<Buffer>): Promise<Buffer>;
getAsStream(docname: string, attname: string): Request;
get(
diff --git a/lib/nano.js b/lib/nano.js
index 9268207..6603736 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -878,7 +878,6 @@ module.exports = exports = function dbScope (cfg) {
doc: docName,
qs: opts,
body: att,
- stream: true,
dontStringify: true
})
}
diff --git a/test/attachment.insertAsStream.test.js b/test/attachment.insertAsStream.test.js
index f7a3022..2d196ff 100644
--- a/test/attachment.insertAsStream.test.js
+++ b/test/attachment.insertAsStream.test.js
@@ -30,7 +30,7 @@ afterEach(() => {
nock.cleanAll()
})
-test('should be able to insert document attachment as stream - PUT /db/docname/attachment - db.attachment.insertAsStream', () => {
+test('should be able to insert document attachment as stream - PUT /db/docname/attachment - db.attachment.insertAsStream', async () => {
// mocks
const response = { ok: true, id: 'docname', rev: '2-456' }
const scope = nock(COUCH_URL, { reqheaders: { 'content-type': 'image/jpg' } })
@@ -38,19 +38,9 @@ test('should be able to insert document attachment as stream - PUT /db/docname/a
.reply(200, response)
// test PUT /db/docname/attachment
- return new Promise((resolve, reject) => {
- const rs = fs.createReadStream('./test/logo.jpg')
- const db = nano.db.use('db')
- let reply = ''
- const is = db.attachment.insertAsStream('docname', 'logo.jpg', null, 'image/jpg', { rev: '1-150' })
- .on('data', (data) => {
- reply += data.toString()
- })
- .on('end', () => {
- expect(reply).toStrictEqual(JSON.stringify(response))
- expect(scope.isDone()).toBe(true)
- resolve()
- })
- rs.pipe(is)
- })
+ const rs = fs.createReadStream('./test/logo.jpg')
+ const db = nano.db.use('db')
+ const reply = await db.attachment.insertAsStream('docname', 'logo.jpg', rs, 'image/jpg', { rev: '1-150' })
+ expect(reply).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
})
[couchdb-nano] 08/12: ensure db.head passes the test
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 6469bf9881e7469a6eb44cd4b6879cdd78352d37
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 13 20:45:54 2020 +0000
ensure db.head passes the test
---
lib/nano.js | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/lib/nano.js b/lib/nano.js
index 48c89ca..ee76018 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -94,16 +94,17 @@ module.exports = exports = function dbScope (cfg) {
return str
}
const responseHandler = function (response, req, opts, resolve, reject, callback) {
+ const statusCode = response.status || (response.response && response.response.status) || 500
if (response.isAxiosError && response.response) {
response = response.response
}
let body = response.data
- response.statusCode = response.status
+ response.statusCode = statusCode
// let parsed
const responseHeaders = Object.assign({
uri: req.url,
- statusCode: response.statusCode
+ statusCode: statusCode
}, response.headers)
if (!response.status) {
log({ err: 'socket', body: body, headers: responseHeaders })
@@ -130,7 +131,7 @@ module.exports = exports = function dbScope (cfg) {
try { parsed = JSON.parse(body) } catch (err) { parsed = body }
} */
- if (responseHeaders.statusCode >= 200 && responseHeaders.statusCode < 400) {
+ if (statusCode >= 200 && statusCode < 400) {
log({ err: null, body: body, headers: responseHeaders })
if (resolve) {
resolve(body)
@@ -163,9 +164,9 @@ module.exports = exports = function dbScope (cfg) {
}
const errors = errs.merge({
- message: 'couch returned ' + req.statusCode,
+ message: 'couch returned ' + statusCode,
scope: 'couch',
- statusCode: req.statusCode,
+ statusCode: statusCode,
request: req,
headers: responseHeaders,
errid: 'non_200'
[couchdb-nano] 05/12: typescript update
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit c918f77ed53b9d592fd54c930c8a65f82f585e3d
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 13 16:17:37 2020 +0000
typescript update
---
lib/nano.d.ts | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/lib/nano.d.ts b/lib/nano.d.ts
index e93f419..3c648c8 100644
--- a/lib/nano.d.ts
+++ b/lib/nano.d.ts
@@ -9,17 +9,20 @@
/// <reference types="node" />
import { EventEmitter } from "events";
-import { CoreOptions, Request } from "request";
declare function nano(
config: nano.Configuration | string
): nano.ServerScope;
declare namespace nano {
+ interface requestDefaultsOptions {
+ timeout: number;
+ };
+
interface Configuration {
url: string;
cookie?: string;
- requestDefaults?: CoreOptions;
+ requestDefaults?: requestDefaultsOptions;
log?(id: string, args: any): void;
parseUrl?: boolean;
request?(params: any): void;
@@ -72,7 +75,7 @@ declare namespace nano {
destroy(name: string, callback?: Callback<OkResponse>): Promise<OkResponse>;
// http://docs.couchdb.org/en/latest/api/server/common.html#get--_all_dbs
list(callback?: Callback<string[]>): Promise<string[]>;
- listAsStream(): Request;
+ listAsStream(): NodeJS.ReadStream;
use<D>(db: string): DocumentScope<D>;
compact(name: string, callback?: Callback<OkResponse>): Promise<OkResponse>;
// http://docs.couchdb.org/en/latest/api/database/compact.html#post--db-_compact
@@ -95,9 +98,9 @@ declare namespace nano {
// http://docs.couchdb.org/en/latest/api/database/compact.html#post--db-_compact
changes(name: string, params: DatabaseChangesParams, callback?: Callback<DatabaseChangesResponse>): Promise<DatabaseChangesResponse>;
// http://docs.couchdb.org/en/latest/api/database/changes.html#get--db-_changes
- changesAsStream(name: string): Request;
+ changesAsStream(name: string): NodeJS.ReadStream;
// http://docs.couchdb.org/en/latest/api/database/compact.html#post--db-_compact
- changesAsStream(name: string, params: DatabaseChangesParams): Request;
+ changesAsStream(name: string, params: DatabaseChangesParams): NodeJS.ReadStream;
follow(source: string, callback?: Callback<any>): EventEmitter;
follow(source: string, params: DatabaseScopeFollowUpdatesParams, callback?: Callback<any>): EventEmitter;
followUpdates(params?: any, callback?: Callback<any>): EventEmitter;
@@ -159,9 +162,9 @@ declare namespace nano {
// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#get--db-_all_docs
list(params: DocumentListParams, callback?: Callback<DocumentListResponse<D>>): Promise<DocumentListResponse<D>>;
// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#get--db-_all_docs
- listAsStream(): Request;
+ listAsStream(): NodeJS.ReadStream;
// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#get--db-_all_docs
- listAsStream(params: DocumentListParams): Request;
+ listAsStream(params: DocumentListParams): NodeJS.ReadStream;
// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_all_docs
fetch(docnames: BulkFetchDocsWrapper, callback?: Callback<DocumentFetchResponse<D>>): Promise<DocumentFetchResponse<D>>;
// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_all_docs
@@ -239,7 +242,7 @@ declare namespace nano {
designname: string,
searchname: string,
params: DocumentSearchParams
- ): Request;
+ ): NodeJS.ReadStream;
baseView<V>(
designname: string,
viewname: string,
@@ -267,14 +270,14 @@ declare namespace nano {
viewAsStream<V>(
designname: string,
viewname: string
- ): Request;
+ ): NodeJS.ReadStream;
// http://docs.couchdb.org/en/latest/api/ddoc/views.html#get--db-_design-ddoc-_view-view
// http://docs.couchdb.org/en/latest/api/ddoc/views.html#post--db-_design-ddoc-_view-view
viewAsStream<V>(
designname: string,
viewname: string,
params: DocumentViewParams
- ): Request;
+ ): NodeJS.ReadStream;
// http://docs.couchdb.org/en/latest/api/ddoc/render.html#db-design-design-doc-list-list-name-view-name
viewWithList(
designname: string,
@@ -296,9 +299,9 @@ declare namespace nano {
//https://docs.couchdb.org/en/latest/partitioned-dbs/index.html
partitionInfo(partitionKey: string, callback?: Callback<PartitionInfoResponse<D>>): Promise <PartitionInfoResponse>;
partitionedList(partitionKey: string, params?: DocumentListParams, callback?: Callback<DocumentListResponse<D>>): Promise<DocumentListResponse<D>>;
- partitionedListAsStream(partitionKey: string, params?: DocumentListParams): Request;
+ partitionedListAsStream(partitionKey: string, params?: DocumentListParams): NodeJS.ReadStream;
partitionedFind(partitionKey: string, query: MangoQuery, callback?: Callback<MangoResponse<D>>): Promise <MangoResponse<D>>;
- partitionedFindAsStream(partitionKey: string, query: MangoQuery): Request;
+ partitionedFindAsStream(partitionKey: string, query: MangoQuery): NodeJS.ReadStream;
partitionedViewpartitionedSearch<V>(
partitionKey: string,
designname: string,
@@ -311,7 +314,7 @@ declare namespace nano {
designname: string,
searchname: string,
params: DocumentSearchParams
- ): Request;
+ ): NodeJS.ReadStream;
partitionedView<V>(
partitionKey: string,
designname: string,
@@ -324,7 +327,7 @@ declare namespace nano {
designname: string,
viewname: string,
params: DocumentViewParams
- ): Request;
+ ): NodeJS.ReadStream;
}
interface AttachmentData {
@@ -374,7 +377,7 @@ declare namespace nano {
params: any
): Promise<DocumentInsertResponse>
get(docname: string, attname: string, callback?: Callback<Buffer>): Promise<Buffer>;
- getAsStream(docname: string, attname: string): Request;
+ getAsStream(docname: string, attname: string): NodeJS.ReadStream;
get(
docname: string,
attname: string,
@@ -1348,7 +1351,7 @@ declare namespace nano {
}
// http://docs.couchdb.org/en/latest/api/database/find.html#db-index
- interface CreateIndexRequest {
+ interface CreateIndexRequest{
// JSON object describing the index to create
index: {
// Array of field names following the sort syntax.
[couchdb-nano] 02/12: merge conflict fixed
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 396c9aeebbb1f0c4987b2a09b8d07eb1441a25d9
Merge: 07b4e63 6cf919b
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 13 13:49:29 2020 +0000
merge conflict fixed
lib/nano.js | 315 +++++++++---------------------
package-lock.json | 151 ++++++++++++++
test/attachment.destroy.test.js | 2 +-
test/attachment.get.test.js | 2 +-
test/attachment.getAsStream.test.js | 2 +-
test/attachment.insert.test.js | 2 +-
test/attachment.insertAsStream.test.js | 2 +-
test/database.changes.test.js | 2 +-
test/database.changesAsStream.test.js | 4 +-
test/database.compact.test.js | 2 +-
test/database.create.test.js | 2 +-
test/database.destroy.test.js | 2 +-
test/database.follow.test.js | 2 +-
test/database.get.test.js | 2 +-
test/database.listAsStream.test.js | 2 +-
test/database.replicate.test.js | 2 +-
test/database.replication.disable.test.js | 2 +-
test/database.replication.enable.test.js | 2 +-
test/database.replication.query.test.js | 2 +-
test/design.atomic.test.js | 4 +-
test/design.createIndex.test.js | 2 +-
test/design.find.test.js | 2 +-
test/design.findAsStream.test.js | 2 +-
test/design.search.test.js | 2 +-
test/design.searchAsStream.test.js | 2 +-
test/design.show.test.js | 2 +-
test/design.view.test.js | 2 +-
test/design.viewAsStream.test.js | 2 +-
test/document.copy.test.js | 4 +-
test/document.destroy.test.js | 2 +-
test/document.fetch.test.js | 2 +-
test/document.fetchRevs.test.js | 2 +-
test/document.get.test.js | 2 +-
test/document.head.test.js | 4 +-
test/document.listAsStream.test.js | 2 +-
test/multipart.get.test.js | 2 +-
test/multipart.insert.test.js | 2 +-
test/nano.request.test.js | 8 +-
test/nano.timeout.test.js | 2 +-
test/nano.uuids.test.js | 2 +-
40 files changed, 291 insertions(+), 265 deletions(-)
diff --cc lib/nano.js
index c77f040,79fbfb5..d7a5ac9
--- a/lib/nano.js
+++ b/lib/nano.js
@@@ -10,10 -10,10 +10,10 @@@
// License for the specific language governing permissions and limitations under
// the License.
- const URL = require('url').URL
+ const { URL } = require('url')
const assert = require('assert')
-const querystring = require('querystring')
-const request = require('request')
+const querystring = require('qs')
+const axios = require('axios').default
const errs = require('errs')
const follow = require('cloudant-follow')
const logger = require('./logger')
diff --cc package-lock.json
index 39a6004,18f6963..7ebe2d8
--- a/package-lock.json
+++ b/package-lock.json
@@@ -937,6 -937,11 +937,14 @@@
"@babel/types": "^7.3.0"
}
},
++<<<<<<< HEAD
++=======
+ "@types/caseless": {
+ "version": "0.12.2",
+ "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
+ "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w=="
+ },
++>>>>>>> master
"@types/color-name": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
@@@ -966,6 -971,34 +974,37 @@@
"requires": {
"@types/istanbul-lib-coverage": "*",
"@types/istanbul-lib-report": "*"
++<<<<<<< HEAD
++=======
+ }
+ },
+ "@types/node": {
+ "version": "13.7.0",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.0.tgz",
+ "integrity": "sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ=="
+ },
+ "@types/request": {
+ "version": "2.48.4",
+ "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.4.tgz",
+ "integrity": "sha512-W1t1MTKYR8PxICH+A4HgEIPuAC3sbljoEVfyZbeFJJDbr30guDspJri2XOaM2E+Un7ZjrihaDi7cf6fPa2tbgw==",
+ "requires": {
+ "@types/caseless": "*",
+ "@types/node": "*",
+ "@types/tough-cookie": "*",
+ "form-data": "^2.5.0"
+ },
+ "dependencies": {
+ "form-data": {
+ "version": "2.5.1",
+ "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
+ "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
+ "requires": {
+ "asynckit": "^0.4.0",
+ "combined-stream": "^1.0.6",
+ "mime-types": "^2.1.12"
+ }
+ }
++>>>>>>> master
}
},
"@types/stack-utils": {
@@@ -974,6 -1007,11 +1013,14 @@@
"integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==",
"dev": true
},
++<<<<<<< HEAD
++=======
+ "@types/tough-cookie": {
+ "version": "2.3.6",
+ "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.6.tgz",
+ "integrity": "sha512-wHNBMnkoEBiRAd3s8KTKwIuO9biFtTf0LehITzBhSco+HQI0xkXZbLOD55SW3Aqw3oUkHstkm5SPv58yaAdFPQ=="
+ },
++>>>>>>> master
"@types/yargs": {
"version": "15.0.3",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.3.tgz",
@@@ -1170,14 -1208,6 +1217,17 @@@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz",
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
},
++<<<<<<< HEAD
+ "axios": {
+ "version": "0.19.2",
+ "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
+ "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
+ "requires": {
+ "follow-redirects": "1.5.10"
+ }
+ },
++=======
++>>>>>>> master
"babel-jest": {
"version": "25.1.0",
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-25.1.0.tgz",
@@@ -1226,14 -1256,14 +1276,25 @@@
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
++<<<<<<< HEAD
+ "dev": true
+ },
+ "has-flag": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
+ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
+ "dev": true
+ },
++=======
+ "dev": true
+ },
+ "has-flag": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
+ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
+ "dev": true
+ },
++>>>>>>> master
"supports-color": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz",
@@@ -1283,6 -1313,6 +1344,92 @@@
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"dev": true
++<<<<<<< HEAD
++ },
++ "base": {
++ "version": "0.11.2",
++ "resolved": "https://registry.npmjs.org/base/-/base-0.11.2.tgz",
++ "integrity": "sha512-5T6P4xPgpp0YDFvSWwEZ4NoE3aM4QBQXDzmVbraCkFj8zHM+mba8SyqB5DbZWyR7mYHo6Y7BdQo3MoA4m0TeQg==",
++ "dev": true,
++ "requires": {
++ "cache-base": "^1.0.1",
++ "class-utils": "^0.3.5",
++ "component-emitter": "^1.2.1",
++ "define-property": "^1.0.0",
++ "isobject": "^3.0.1",
++ "mixin-deep": "^1.2.0",
++ "pascalcase": "^0.1.1"
++ },
++ "dependencies": {
++ "define-property": {
++ "version": "1.0.0",
++ "resolved": "https://registry.npmjs.org/define-property/-/define-property-1.0.0.tgz",
++ "integrity": "sha1-dp66rz9KY6rTr56NMEybvnm/sOY=",
++ "dev": true,
++ "requires": {
++ "is-descriptor": "^1.0.0"
++ }
++ },
++ "is-accessor-descriptor": {
++ "version": "1.0.0",
++ "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-1.0.0.tgz",
++ "integrity": "sha512-m5hnHTkcVsPfqx3AKlyttIPb7J+XykHvJP2B9bZDjlhLIoEq4XoK64Vg7boZlVWYK6LUY94dYPEE7Lh0ZkZKcQ==",
++ "dev": true,
++ "requires": {
++ "kind-of": "^6.0.0"
++ }
++ },
++ "is-data-descriptor": {
++ "version": "1.0.0",
++ "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-1.0.0.tgz",
++ "integrity": "sha512-jbRXy1FmtAoCjQkVmIVYwuuqDFUbaOeDjmed1tOGPrsMhtJA4rD9tkgA0F1qJ3gRFRXcHYVkdeaP50Q5rE/jLQ==",
++ "dev": true,
++ "requires": {
++ "kind-of": "^6.0.0"
++ }
++ },
++ "is-descriptor": {
++ "version": "1.0.2",
++ "resolved": "https://registry.npmjs.org/is-descriptor/-/is-descriptor-1.0.2.tgz",
++ "integrity": "sha512-2eis5WqQGV7peooDyLmNEPUrps9+SXX5c9pL3xEB+4e9HnGuDa7mB7kHxHw4CbqS9k1T2hOH3miL8n8WtiYVtg==",
++ "dev": true,
++ "requires": {
++ "is-accessor-descriptor": "^1.0.0",
++ "is-data-descriptor": "^1.0.0",
++ "kind-of": "^6.0.2"
++ }
++ }
++ }
++ },
++ "bcrypt-pbkdf": {
++ "version": "1.0.2",
++ "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
++ "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=",
++ "optional": true,
++ "requires": {
++ "tweetnacl": "^0.14.3"
++ }
++ },
++ "brace-expansion": {
++ "version": "1.1.11",
++ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
++ "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
++ "dev": true,
++ "requires": {
++ "balanced-match": "^1.0.0",
++ "concat-map": "0.0.1"
++ }
++ },
++ "braces": {
++ "version": "3.0.2",
++ "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
++ "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
++ "dev": true,
++ "requires": {
++ "fill-range": "^7.0.1"
++ }
++ },
++=======
},
"base": {
"version": "0.11.2",
@@@ -1367,6 -1397,6 +1514,7 @@@
"fill-range": "^7.0.1"
}
},
++>>>>>>> master
"browser-process-hrtime": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/browser-process-hrtime/-/browser-process-hrtime-0.1.3.tgz",
@@@ -2652,29 -2682,6 +2800,32 @@@
"integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==",
"dev": true
},
++<<<<<<< HEAD
+ "follow-redirects": {
+ "version": "1.5.10",
+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
+ "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
+ "requires": {
+ "debug": "=3.1.0"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
+ "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
+ "requires": {
+ "ms": "2.0.0"
+ }
+ },
+ "ms": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
+ }
+ }
+ },
++=======
++>>>>>>> master
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
[couchdb-nano] 01/12: stash changes
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 07b4e63ead16aea281b3381bf8a08e650deffbb8
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 13 10:18:27 2020 +0000
stash changes
---
lib/nano.js | 184 ++++++++++++++++++++++++++++++++----------------------
package-lock.json | 82 ++++++++++++------------
package.json | 6 +-
3 files changed, 152 insertions(+), 120 deletions(-)
diff --git a/lib/nano.js b/lib/nano.js
index b4cc0d0..c77f040 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -12,12 +12,13 @@
const URL = require('url').URL
const assert = require('assert')
-const querystring = require('querystring')
-const request = require('request')
+const querystring = require('qs')
+const axios = require('axios').default
const errs = require('errs')
const follow = require('cloudant-follow')
const logger = require('./logger')
const INVALID_PARAMETERS_ERROR = new Error('Invalid parameters')
+const stream = require('stream')
function isEmpty (val) {
return val == null || !(Object.keys(val) || val).length
@@ -51,8 +52,6 @@ module.exports = exports = function dbScope (cfg) {
serverScope.config = cfg
cfg.requestDefaults = cfg.requestDefaults || {}
- const httpAgent = (typeof cfg.request === 'function') ? cfg.request
- : request.defaults(cfg.requestDefaults)
const followAgent = (typeof cfg.follow === 'function') ? cfg.follow : follow
const log = typeof cfg.log === 'function' ? cfg.log : logger(cfg)
const parseUrl = 'parseUrl' in cfg ? cfg.parseUrl : true
@@ -79,85 +78,89 @@ module.exports = exports = function dbScope (cfg) {
}
return str
}
- const responseHandler = function (req, opts, resolve, reject, callback) {
- return function (err, response = { statusCode: 500 }, body = '') {
- let parsed
- const responseHeaders = Object.assign({
- uri: req.uri,
- statusCode: response.statusCode
- }, response.headers)
- if (err) {
- log({ err: 'socket', body: body, headers: responseHeaders })
- const returnError = errs.merge(err, {
+ const responseHandler = function (response, req, opts, resolve, reject, callback) {
+ if (response.isAxiosError && response.response) {
+ response = response.response
+ }
+ let body = response.data
+ response.statusCode = response.status
+
+ // let parsed
+ const responseHeaders = Object.assign({
+ uri: req.url,
+ statusCode: response.statusCode
+ }, response.headers)
+ if (!response.status) {
+ log({ err: 'socket', body: body, headers: responseHeaders })
+ if (reject) {
+ reject(new Error('error happened in your connection'))
+ }
+ if (callback) {
+ const returnError = {
message: 'error happened in your connection',
scope: 'socket',
errid: 'request'
- })
- if (reject) {
- reject(returnError)
- }
- if (callback) {
- callback(returnError)
}
- return
+ callback(returnError)
}
+ return
+ }
- delete responseHeaders.server
- delete responseHeaders['content-length']
+ delete responseHeaders.server
+ delete responseHeaders['content-length']
- if (opts.dontParse) {
- parsed = body
- } else {
- try { parsed = JSON.parse(body) } catch (err) { parsed = body }
- }
+ /* if (opts.dontParse) {
+ parsed = body
+ } else {
+ try { parsed = JSON.parse(body) } catch (err) { parsed = body }
+ } */
- if (responseHeaders.statusCode >= 200 && responseHeaders.statusCode < 400) {
- log({ err: null, body: parsed, headers: responseHeaders })
- if (resolve) {
- resolve(parsed)
- }
- if (callback) {
- callback(null, parsed, responseHeaders)
- }
- return
+ if (responseHeaders.statusCode >= 200 && responseHeaders.statusCode < 400) {
+ log({ err: null, body: body, headers: responseHeaders })
+ if (resolve) {
+ resolve(body)
}
+ if (callback) {
+ callback(null, body, responseHeaders)
+ }
+ return
+ }
- log({ err: 'couch', body: parsed, headers: responseHeaders })
+ log({ err: 'couch', body: body, headers: responseHeaders })
- // cloudant stacktrace
- if (typeof parsed === 'string') {
- parsed = { message: parsed }
- }
+ // cloudant stacktrace
+ if (typeof body === 'string') {
+ body = { message: body }
+ }
- if (!parsed.message && (parsed.reason || parsed.error)) {
- parsed.message = (parsed.reason || parsed.error)
- }
+ if (!body.message && (body.reason || body.error)) {
+ body.message = (body.reason || body.error)
+ }
- // fix cloudant issues where they give an erlang stacktrace as js
- delete parsed.stack
+ // fix cloudant issues where they give an erlang stacktrace as js
+ delete body.stack
- // scrub credentials
- req.uri = scrub(req.uri)
- responseHeaders.uri = scrub(responseHeaders.uri)
- if (req.headers.cookie) {
- req.headers.cookie = 'XXXXXXX'
- }
+ // scrub credentials
+ req.url = scrub(req.url)
+ responseHeaders.url = scrub(responseHeaders.url)
+ if (req.headers.cookie) {
+ req.headers.cookie = 'XXXXXXX'
+ }
- const errors = errs.merge({
- message: 'couch returned ' + responseHeaders.statusCode,
- scope: 'couch',
- statusCode: responseHeaders.statusCode,
- request: req,
- headers: responseHeaders,
- errid: 'non_200'
- }, errs.create(parsed))
+ const errors = errs.merge({
+ message: 'couch returned ' + req.statusCode,
+ scope: 'couch',
+ statusCode: req.statusCode,
+ request: req,
+ headers: responseHeaders,
+ errid: 'non_200'
+ }, errs.create(body))
- if (reject) {
- reject(errors)
- }
- if (callback) {
- callback(errors)
- }
+ if (reject) {
+ reject(errors)
+ }
+ if (callback) {
+ callback(errors)
}
}
@@ -183,11 +186,11 @@ module.exports = exports = function dbScope (cfg) {
accept: 'application/json'
}
- const req = {
+ const req = Object.assign({
method: (opts.method || 'GET'),
headers: headers,
uri: cfg.url
- }
+ }, cfg.requestDefaults)
// https://github.com/mikeal/request#requestjar
const isJar = opts.jar || cfg.jar
@@ -283,17 +286,46 @@ module.exports = exports = function dbScope (cfg) {
log(req)
+ // This where the HTTP request is made.
+ // Nano used to use the now-deprecated "request" library but now we're going to
+ // use axios, so let's modify the "req" object to suit axios
+ req.url = req.uri
+ delete req.uri
+ req.method = req.method.toLowerCase()
+ req.params = req.qs
+ delete req.qs
+ req.paramsSerializer = (params) => {
+ return querystring.stringify(params, { arrayFormat: 'brackets' })
+ }
+ req.data = req.body
+ delete req.body
+ req.maxRedirects = 0
+ if (opts.stream) {
+ req.responseType = 'stream'
+ } else if (opts.dontParse) {
+ req.responseType = 'arraybuffer'
+ }
+
+ // actually do the HTTP request
if (opts.stream) {
// return the Request object for streaming
- return httpAgent(req)
+ const outStream = new stream.PassThrough()
+ axios(req).then((response) => { response.data.pipe(outStream) })
+ return outStream
} else {
if (typeof callback === 'function') {
- // return nothing - feedback via the callback function
- httpAgent(req, responseHandler(req, opts, null, null, callback))
+ axios(req).then((response) => {
+ responseHandler(response, req, opts, null, null, callback)
+ }).catch((e) => {
+ responseHandler(e, req, opts, null, null, callback)
+ })
} else {
- // return a Promise
- return new Promise(function (resolve, reject) {
- httpAgent(req, responseHandler(req, opts, resolve, reject))
+ return new Promise((resolve, reject) => {
+ axios(req).then((response) => {
+ responseHandler(response, req, opts, resolve, reject)
+ }).catch((e) => {
+ responseHandler(e, req, opts, resolve, reject)
+ })
})
}
}
@@ -422,7 +454,7 @@ module.exports = exports = function dbScope (cfg) {
function followDb (dbName, qs0, callback0) {
const { opts, callback } = getCallback(qs0, callback0)
opts.db = urlResolveFix(cfg.url, encodeURIComponent(dbName))
- opts.httpAgent = httpAgent
+ // opts.httpAgent = httpAgent
if (typeof callback === 'function') {
return followAgent(opts, callback)
} else {
diff --git a/package-lock.json b/package-lock.json
index 18f6963..39a6004 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -937,11 +937,6 @@
"@babel/types": "^7.3.0"
}
},
- "@types/caseless": {
- "version": "0.12.2",
- "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
- "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w=="
- },
"@types/color-name": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
@@ -973,45 +968,12 @@
"@types/istanbul-lib-report": "*"
}
},
- "@types/node": {
- "version": "13.7.0",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.0.tgz",
- "integrity": "sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ=="
- },
- "@types/request": {
- "version": "2.48.4",
- "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.4.tgz",
- "integrity": "sha512-W1t1MTKYR8PxICH+A4HgEIPuAC3sbljoEVfyZbeFJJDbr30guDspJri2XOaM2E+Un7ZjrihaDi7cf6fPa2tbgw==",
- "requires": {
- "@types/caseless": "*",
- "@types/node": "*",
- "@types/tough-cookie": "*",
- "form-data": "^2.5.0"
- },
- "dependencies": {
- "form-data": {
- "version": "2.5.1",
- "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
- "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
- "requires": {
- "asynckit": "^0.4.0",
- "combined-stream": "^1.0.6",
- "mime-types": "^2.1.12"
- }
- }
- }
- },
"@types/stack-utils": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz",
"integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==",
"dev": true
},
- "@types/tough-cookie": {
- "version": "2.3.6",
- "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.6.tgz",
- "integrity": "sha512-wHNBMnkoEBiRAd3s8KTKwIuO9biFtTf0LehITzBhSco+HQI0xkXZbLOD55SW3Aqw3oUkHstkm5SPv58yaAdFPQ=="
- },
"@types/yargs": {
"version": "15.0.3",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.3.tgz",
@@ -1208,6 +1170,14 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz",
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
},
+ "axios": {
+ "version": "0.19.2",
+ "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
+ "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
+ "requires": {
+ "follow-redirects": "1.5.10"
+ }
+ },
"babel-jest": {
"version": "25.1.0",
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-25.1.0.tgz",
@@ -2682,6 +2652,29 @@
"integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==",
"dev": true
},
+ "follow-redirects": {
+ "version": "1.5.10",
+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
+ "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
+ "requires": {
+ "debug": "=3.1.0"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
+ "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
+ "requires": {
+ "ms": "2.0.0"
+ }
+ },
+ "ms": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
+ }
+ }
+ },
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
@@ -5832,9 +5825,9 @@
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
},
"qs": {
- "version": "6.5.2",
- "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
- "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
+ "version": "6.9.1",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.1.tgz",
+ "integrity": "sha512-Cxm7/SS/y/Z3MHWSxXb8lIFqgqBowP5JMlTUFyJN88y0SGQhVmZnqFK/PeuMX9LzUyWsqqhNxIyg0jlzq946yA=="
},
"react-is": {
"version": "16.12.0",
@@ -5931,6 +5924,13 @@
"tough-cookie": "~2.4.3",
"tunnel-agent": "^0.6.0",
"uuid": "^3.3.2"
+ },
+ "dependencies": {
+ "qs": {
+ "version": "6.5.2",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
+ "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
+ }
}
},
"request-promise-core": {
diff --git a/package.json b/package.json
index 7cf621d..2ec5360 100644
--- a/package.json
+++ b/package.json
@@ -17,11 +17,11 @@
"database"
],
"dependencies": {
- "@types/request": "^2.48.4",
+ "axios": "^0.19.2",
"cloudant-follow": "^0.18.2",
"debug": "^4.1.1",
"errs": "^0.3.2",
- "request": "^2.88.0"
+ "qs": "^6.9.1"
},
"devDependencies": {
"async": "^2.6.2",
@@ -32,7 +32,7 @@
"scripts": {
"standard": "standard --fix",
"test": "standard && npm run jest",
- "jest": "jest test/* --coverage"
+ "jest": "jest test/* --coverage --env=node"
},
"main": "./lib/nano.js",
"types": "./lib/nano.d.ts",
[couchdb-nano] 11/12: merge master into axios branch
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit afc6dc6edf3e8a3e45b3f24819b07be1bd466783
Merge: 8344ea6 9994f85
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 27 15:53:37 2020 +0000
merge master into axios branch
lib/nano.d.ts | 85 +++++++++++++++++----------------------
lib/nano.js | 2 +-
package-lock.json | 21 +++-------
package.json | 12 +++---
scripts/run_couchdb_on_travis.sh | 9 +++--
scripts/stop_couchdb_on_travis.sh | 2 +-
test/notnocked.test.js | 2 +-
7 files changed, 57 insertions(+), 76 deletions(-)
diff --cc lib/nano.d.ts
index 3ecac47,3cecf38..a6e5496
--- a/lib/nano.d.ts
+++ b/lib/nano.d.ts
@@@ -16,12 -17,6 +16,12 @@@ declare function nano
): nano.ServerScope;
declare namespace nano {
+ interface requestDefaultsOptions {
+ timeout: number;
+ agent: any;
+ headers: object;
- };
++ }
+
interface Configuration {
url: string;
cookie?: string;
@@@ -101,12 -101,14 +106,14 @@@
// http://docs.couchdb.org/en/latest/api/database/compact.html#post--db-_compact
changes(name: string, params: DatabaseChangesParams, callback?: Callback<DatabaseChangesResponse>): Promise<DatabaseChangesResponse>;
// http://docs.couchdb.org/en/latest/api/database/changes.html#get--db-_changes
- changesAsStream(name: string): Request;
+ changesAsStream(name: string): NodeJS.ReadStream;
// http://docs.couchdb.org/en/latest/api/database/compact.html#post--db-_compact
- changesAsStream(name: string, params: DatabaseChangesParams): Request;
+ changesAsStream(name: string, params: DatabaseChangesParams): NodeJS.ReadStream;
- follow(source: string, callback?: Callback<any>): EventEmitter;
- follow(source: string, params: DatabaseScopeFollowUpdatesParams, callback?: Callback<any>): EventEmitter;
- followUpdates(params?: any, callback?: Callback<any>): EventEmitter;
+ follow(source: string, params?: DatabaseScopeFollowUpdatesParams): FollowEmitter;
+ follow(source: string, params: DatabaseScopeFollowUpdatesParams, callback: Callback<any>);
+ followUpdates(params?: any): FollowEmitter;
+ followUpdates(params: DatabaseScopeFollowUpdatesParams, callback: Callback<any>);
+ followUpdates(callback: Callback<any>);
// http://docs.couchdb.org/en/latest/api/server/common.html#get--_db_updates
updates(callback?: Callback<DatabaseUpdatesResponse>): Promise<DatabaseUpdatesResponse>;
// http://docs.couchdb.org/en/latest/api/server/common.html#get--_db_updates
@@@ -300,11 -312,11 +308,11 @@@
find(query: MangoQuery, callback?: Callback<MangoResponse<D>>): Promise <MangoResponse<D>>;
server: ServerScope;
//https://docs.couchdb.org/en/latest/partitioned-dbs/index.html
- partitionInfo(partitionKey: string, callback?: Callback<PartitionInfoResponse<D>>): Promise <PartitionInfoResponse>;
- partitionedList(partitionKey: string, params?: DocumentListParams, callback?: Callback<DocumentListResponse<D>>): Promise<DocumentListResponse<D>>;
- partitionedListAsStream(partitionKey: string, params?: DocumentListParams): NodeJS.ReadStream;
+ partitionInfo(partitionKey: string, callback?: Callback<PartitionInfoResponse>): Promise <PartitionInfoResponse>;
+ partitionedList(partitionKey: string, params?: DocumentFetchParams, callback?: Callback<DocumentListResponse<D>>): Promise<DocumentListResponse<D>>;
- partitionedListAsStream(partitionKey: string, params?: DocumentFetchParams): Request;
++ partitionedListAsStream(partitionKey: string, params?: DocumentFetchParams): NodeJS.ReadStream;
partitionedFind(partitionKey: string, query: MangoQuery, callback?: Callback<MangoResponse<D>>): Promise <MangoResponse<D>>;
- partitionedFindAsStream(partitionKey: string, query: MangoQuery): Request;
+ partitionedFindAsStream(partitionKey: string, query: MangoQuery): NodeJS.ReadStream;
partitionedViewpartitionedSearch<V>(
partitionKey: string,
designname: string,
diff --cc package.json
index 2ec5360,3f3802a..4065aa5
--- a/package.json
+++ b/package.json
@@@ -21,13 -21,13 +21,13 @@@
"cloudant-follow": "^0.18.2",
"debug": "^4.1.1",
"errs": "^0.3.2",
- "request": "^2.88.0"
+ "qs": "^6.9.1"
},
"devDependencies": {
- "async": "^2.6.2",
"jest": "^25.1.0",
"nock": "^11.7.2",
- "standard": "^14.3.1"
+ "standard": "^14.3.1",
+ "typescript": "^3.7.5"
},
"scripts": {
"standard": "standard --fix",
[couchdb-nano] 07/12: combine attachment.insert
attachment.insertAsStream
Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit cc7c571e1c5d6ae5309bfa2ccf7c1882c4e89196
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 13 20:22:31 2020 +0000
combine attachment.insert attachment.insertAsStream
---
README.md | 9 +-
lib/nano.d.ts | 13 ---
lib/nano.js | 16 +---
package-lock.json | 151 ---------------------------------
test/attachment.insert.test.js | 26 ++++++
test/attachment.insertAsStream.test.js | 46 ----------
6 files changed, 29 insertions(+), 232 deletions(-)
diff --git a/README.md b/README.md
index 0ea1d8f..7af5e3b 100644
--- a/README.md
+++ b/README.md
@@ -949,13 +949,8 @@ fs.readFile('rabbit.png', (err, data) => {
### db.attachment.insertAsStream(docname, attname, att, contenttype, [params])
-It may be more memory-efficient to pipe a stream of data from a source (file, network etc) to a CouchDB attachment:
-
-```js
- const rs = fs.createReadStream('logo.png');
- const reply = await db.attachment.insertAsStream('mydoc', 'logo.png', rs, 'image/png',
- { rev: '12-150985a725ec88be471921a54ce91452' })
-```
+As of Nano 9.x, the function `db.attachment.insertAsStream` is now deprecated. Now simply pass
+a readable stream to `db.attachment.insert` as the third paramseter.
### db.attachment.get(docname, attname, [params], [callback])
diff --git a/lib/nano.d.ts b/lib/nano.d.ts
index a8ff89e..2e56b59 100644
--- a/lib/nano.d.ts
+++ b/lib/nano.d.ts
@@ -364,19 +364,6 @@ declare namespace nano {
params: any,
callback?: Callback<DocumentInsertResponse>
): Promise<DocumentInsertResponse>;
- insertAsStream(
- docname: string,
- attname: string,
- att: NodeJS.ReadReadStream,
- contenttype: string
- ): Promise<DocumentInsertResponse>;
- insertAsStream(
- docname: string,
- attname: string,
- att: NodeJS.ReadReadStream,
- contenttype: string,
- params: any
- ): Promise<DocumentInsertResponse>
get(docname: string, attname: string, callback?: Callback<Buffer>): Promise<Buffer>;
getAsStream(docname: string, attname: string): NodeJS.ReadStream;
get(
diff --git a/lib/nano.js b/lib/nano.js
index 19f2692..48c89ca 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -444,7 +444,7 @@ module.exports = exports = function dbScope (cfg) {
function followDb (dbName, qs0, callback0) {
const { opts, callback } = getCallback(qs0, callback0)
opts.db = urlResolveFix(cfg.url, encodeURIComponent(dbName))
- // opts.httpAgent = httpAgent
+ opts.httpAgent = require('request')
if (typeof callback === 'function') {
return followAgent(opts, callback)
} else {
@@ -869,19 +869,6 @@ module.exports = exports = function dbScope (cfg) {
}, callback)
}
- function insertAttAsStream (docName, attName, att, contentType, opts) {
- return relax({
- db: dbName,
- att: attName,
- method: 'PUT',
- contentType: contentType,
- doc: docName,
- qs: opts,
- body: att,
- dontStringify: true
- })
- }
-
function getAtt (docName, attName, qs0, callback0) {
const { opts, callback } = getCallback(qs0, callback0)
@@ -1094,7 +1081,6 @@ module.exports = exports = function dbScope (cfg) {
},
attachment: {
insert: insertAtt,
- insertAsStream: insertAttAsStream,
get: getAtt,
getAsStream: getAttAsStream,
destroy: destroyAtt
diff --git a/package-lock.json b/package-lock.json
index 7ebe2d8..39a6004 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -937,14 +937,6 @@
"@babel/types": "^7.3.0"
}
},
-<<<<<<< HEAD
-=======
- "@types/caseless": {
- "version": "0.12.2",
- "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
- "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w=="
- },
->>>>>>> master
"@types/color-name": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
@@ -974,37 +966,6 @@
"requires": {
"@types/istanbul-lib-coverage": "*",
"@types/istanbul-lib-report": "*"
-<<<<<<< HEAD
-=======
- }
- },
- "@types/node": {
- "version": "13.7.0",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.0.tgz",
- "integrity": "sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ=="
- },
- "@types/request": {
- "version": "2.48.4",
- "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.4.tgz",
- "integrity": "sha512-W1t1MTKYR8PxICH+A4HgEIPuAC3sbljoEVfyZbeFJJDbr30guDspJri2XOaM2E+Un7ZjrihaDi7cf6fPa2tbgw==",
- "requires": {
- "@types/caseless": "*",
- "@types/node": "*",
- "@types/tough-cookie": "*",
- "form-data": "^2.5.0"
- },
- "dependencies": {
- "form-data": {
- "version": "2.5.1",
- "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
- "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
- "requires": {
- "asynckit": "^0.4.0",
- "combined-stream": "^1.0.6",
- "mime-types": "^2.1.12"
- }
- }
->>>>>>> master
}
},
"@types/stack-utils": {
@@ -1013,14 +974,6 @@
"integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==",
"dev": true
},
-<<<<<<< HEAD
-=======
- "@types/tough-cookie": {
- "version": "2.3.6",
- "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.6.tgz",
- "integrity": "sha512-wHNBMnkoEBiRAd3s8KTKwIuO9biFtTf0LehITzBhSco+HQI0xkXZbLOD55SW3Aqw3oUkHstkm5SPv58yaAdFPQ=="
- },
->>>>>>> master
"@types/yargs": {
"version": "15.0.3",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.3.tgz",
@@ -1217,7 +1170,6 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz",
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
},
-<<<<<<< HEAD
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
@@ -1226,8 +1178,6 @@
"follow-redirects": "1.5.10"
}
},
-=======
->>>>>>> master
"babel-jest": {
"version": "25.1.0",
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-25.1.0.tgz",
@@ -1276,16 +1226,6 @@
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
-<<<<<<< HEAD
- "dev": true
- },
- "has-flag": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
- "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
- "dev": true
- },
-=======
"dev": true
},
"has-flag": {
@@ -1294,7 +1234,6 @@
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true
},
->>>>>>> master
"supports-color": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz",
@@ -1344,92 +1283,6 @@
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"dev": true
-<<<<<<< HEAD
- },
- "base": {
- "version": "0.11.2",
- "resolved": "https://registry.npmjs.org/base/-/base-0.11.2.tgz",
- "integrity": "sha512-5T6P4xPgpp0YDFvSWwEZ4NoE3aM4QBQXDzmVbraCkFj8zHM+mba8SyqB5DbZWyR7mYHo6Y7BdQo3MoA4m0TeQg==",
- "dev": true,
- "requires": {
- "cache-base": "^1.0.1",
- "class-utils": "^0.3.5",
- "component-emitter": "^1.2.1",
- "define-property": "^1.0.0",
- "isobject": "^3.0.1",
- "mixin-deep": "^1.2.0",
- "pascalcase": "^0.1.1"
- },
- "dependencies": {
- "define-property": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/define-property/-/define-property-1.0.0.tgz",
- "integrity": "sha1-dp66rz9KY6rTr56NMEybvnm/sOY=",
- "dev": true,
- "requires": {
- "is-descriptor": "^1.0.0"
- }
- },
- "is-accessor-descriptor": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-1.0.0.tgz",
- "integrity": "sha512-m5hnHTkcVsPfqx3AKlyttIPb7J+XykHvJP2B9bZDjlhLIoEq4XoK64Vg7boZlVWYK6LUY94dYPEE7Lh0ZkZKcQ==",
- "dev": true,
- "requires": {
- "kind-of": "^6.0.0"
- }
- },
- "is-data-descriptor": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-1.0.0.tgz",
- "integrity": "sha512-jbRXy1FmtAoCjQkVmIVYwuuqDFUbaOeDjmed1tOGPrsMhtJA4rD9tkgA0F1qJ3gRFRXcHYVkdeaP50Q5rE/jLQ==",
- "dev": true,
- "requires": {
- "kind-of": "^6.0.0"
- }
- },
- "is-descriptor": {
- "version": "1.0.2",
- "resolved": "https://registry.npmjs.org/is-descriptor/-/is-descriptor-1.0.2.tgz",
- "integrity": "sha512-2eis5WqQGV7peooDyLmNEPUrps9+SXX5c9pL3xEB+4e9HnGuDa7mB7kHxHw4CbqS9k1T2hOH3miL8n8WtiYVtg==",
- "dev": true,
- "requires": {
- "is-accessor-descriptor": "^1.0.0",
- "is-data-descriptor": "^1.0.0",
- "kind-of": "^6.0.2"
- }
- }
- }
- },
- "bcrypt-pbkdf": {
- "version": "1.0.2",
- "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
- "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=",
- "optional": true,
- "requires": {
- "tweetnacl": "^0.14.3"
- }
- },
- "brace-expansion": {
- "version": "1.1.11",
- "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
- "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
- "dev": true,
- "requires": {
- "balanced-match": "^1.0.0",
- "concat-map": "0.0.1"
- }
- },
- "braces": {
- "version": "3.0.2",
- "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
- "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
- "dev": true,
- "requires": {
- "fill-range": "^7.0.1"
- }
- },
-=======
},
"base": {
"version": "0.11.2",
@@ -1514,7 +1367,6 @@
"fill-range": "^7.0.1"
}
},
->>>>>>> master
"browser-process-hrtime": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/browser-process-hrtime/-/browser-process-hrtime-0.1.3.tgz",
@@ -2800,7 +2652,6 @@
"integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==",
"dev": true
},
-<<<<<<< HEAD
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
@@ -2824,8 +2675,6 @@
}
}
},
-=======
->>>>>>> master
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
diff --git a/test/attachment.insert.test.js b/test/attachment.insert.test.js
index f1d08b2..9125e01 100644
--- a/test/attachment.insert.test.js
+++ b/test/attachment.insert.test.js
@@ -14,7 +14,18 @@ const Nano = require('..')
const COUCH_URL = 'http://localhost:5984'
const nano = Nano(COUCH_URL)
const nock = require('nock')
+const fs = require('fs')
const image = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64')
+const image2 = Buffer.from(''.concat(
+ 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAsV',
+ 'BMVEUAAAD////////////////////////5ur3rEBn////////////////wDBL/',
+ 'AADuBAe9EB3IEBz/7+//X1/qBQn2AgP/f3/ilpzsDxfpChDtDhXeCA76AQH/v7',
+ '/84eLyWV/uc3bJPEf/Dw/uw8bRWmP1h4zxSlD6YGHuQ0f6g4XyQkXvCA36MDH6',
+ 'wMH/z8/yAwX64ODeh47BHiv/Ly/20dLQLTj98PDXWmP/Pz//39/wGyJ7Iy9JAA',
+ 'AADHRSTlMAbw8vf08/bz+Pv19jK/W3AAAAg0lEQVR4Xp3LRQ4DQRBD0QqTm4Y5',
+ 'zMxw/4OleiJlHeUtv2X6RbNO1Uqj9g0RMCuQO0vBIg4vMFeOpCWIWmDOw82fZx',
+ 'vaND1c8OG4vrdOqD8YwgpDYDxRgkSm5rwu0nQVBJuMg++pLXZyr5jnc1BaH4GT',
+ 'LvEliY253nA3pVhQqdPt0f/erJkMGMB8xucAAAAASUVORK5CYII='), 'base64')
afterEach(() => {
nock.cleanAll()
@@ -67,3 +78,18 @@ test('should detect missing parameters (callback) - db.attachment.insert', () =>
})
})
})
+
+test('should be able to insert document attachment as stream - PUT /db/docname/attachment - db.attachment.insert', async () => {
+ // mocks
+ const response = { ok: true, id: 'docname', rev: '2-456' }
+ const scope = nock(COUCH_URL, { reqheaders: { 'content-type': 'image/jpg' } })
+ .put('/db/docname/logo.jpg?rev=1-150', image2)
+ .reply(200, response)
+
+ // test PUT /db/docname/attachment
+ const rs = fs.createReadStream('./test/logo.jpg')
+ const db = nano.db.use('db')
+ const reply = await db.attachment.insert('docname', 'logo.jpg', rs, 'image/jpg', { rev: '1-150' })
+ expect(reply).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
+})
diff --git a/test/attachment.insertAsStream.test.js b/test/attachment.insertAsStream.test.js
deleted file mode 100644
index 2d196ff..0000000
--- a/test/attachment.insertAsStream.test.js
+++ /dev/null
@@ -1,46 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-const Nano = require('..')
-const COUCH_URL = 'http://localhost:5984'
-const nano = Nano(COUCH_URL)
-const nock = require('nock')
-const fs = require('fs')
-const image = Buffer.from(''.concat(
- 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAsV',
- 'BMVEUAAAD////////////////////////5ur3rEBn////////////////wDBL/',
- 'AADuBAe9EB3IEBz/7+//X1/qBQn2AgP/f3/ilpzsDxfpChDtDhXeCA76AQH/v7',
- '/84eLyWV/uc3bJPEf/Dw/uw8bRWmP1h4zxSlD6YGHuQ0f6g4XyQkXvCA36MDH6',
- 'wMH/z8/yAwX64ODeh47BHiv/Ly/20dLQLTj98PDXWmP/Pz//39/wGyJ7Iy9JAA',
- 'AADHRSTlMAbw8vf08/bz+Pv19jK/W3AAAAg0lEQVR4Xp3LRQ4DQRBD0QqTm4Y5',
- 'zMxw/4OleiJlHeUtv2X6RbNO1Uqj9g0RMCuQO0vBIg4vMFeOpCWIWmDOw82fZx',
- 'vaND1c8OG4vrdOqD8YwgpDYDxRgkSm5rwu0nQVBJuMg++pLXZyr5jnc1BaH4GT',
- 'LvEliY253nA3pVhQqdPt0f/erJkMGMB8xucAAAAASUVORK5CYII='), 'base64')
-
-afterEach(() => {
- nock.cleanAll()
-})
-
-test('should be able to insert document attachment as stream - PUT /db/docname/attachment - db.attachment.insertAsStream', async () => {
- // mocks
- const response = { ok: true, id: 'docname', rev: '2-456' }
- const scope = nock(COUCH_URL, { reqheaders: { 'content-type': 'image/jpg' } })
- .put('/db/docname/logo.jpg?rev=1-150', image)
- .reply(200, response)
-
- // test PUT /db/docname/attachment
- const rs = fs.createReadStream('./test/logo.jpg')
- const db = nano.db.use('db')
- const reply = await db.attachment.insertAsStream('docname', 'logo.jpg', rs, 'image/jpg', { rev: '1-150' })
- expect(reply).toStrictEqual(response)
- expect(scope.isDone()).toBe(true)
-})