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:57 UTC

[couchdb-nano] 03/12: remove db.copy function - axios does not support COPY HTTP method

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()
-    })
-  })
-})