You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2020/06/10 17:09:22 UTC
[couchdb-nano] branch master updated: Add nano.info()
This is an automated email from the ASF dual-hosted git repository.
jan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
The following commit(s) were added to refs/heads/master by this push:
new 2804eac Add nano.info()
new c7751ae Merge pull request #226 from YC/info
2804eac is described below
commit 2804eac0f80671eeefc15a89140265bef20e8b76
Author: Steven Tang <st...@gmail.com>
AuthorDate: Tue Jun 9 21:35:05 2020 +1000
Add nano.info()
---
README.md | 5 +++++
lib/nano.d.ts | 14 +++++++++++++-
lib/nano.js | 8 +++++++-
test/nano.info.test.js | 41 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 5f182bd..541b00c 100644
--- a/README.md
+++ b/README.md
@@ -52,6 +52,7 @@ See [Migration Guide for switching from Nano 6.x to 7.x](migration_6_to_7.md).
- [nano.config](#nanoconfig)
- [nano.updates([params], [callback])](#nanoupdatesparams-callback)
- [nano.followUpdates([params], [callback])](#nanofollowupdatesparams-callback)
+ - [nano.info([callback])](#nanoinfocallback)
- [Document functions](#document-functions)
- [db.insert(doc, [params], [callback])](#dbinsertdoc-params-callback)
- [db.destroy(docname, rev, [callback])](#dbdestroydocname-rev-callback)
@@ -546,6 +547,10 @@ process.nextTick( () => {
});
```
+### nano.info([callback])
+
+Get meta information about database instance.
+
## Document functions
### db.insert(doc, [params], [callback])
diff --git a/lib/nano.d.ts b/lib/nano.d.ts
index 8484c4a..8f778bb 100644
--- a/lib/nano.d.ts
+++ b/lib/nano.d.ts
@@ -48,16 +48,28 @@ declare namespace nano {
followUpdates(callback: Callback<any>): void;
followUpdates(params: any, callback: Callback<any>): void;
uuids(num: number, callback?: Callback<any>): Promise<UUIDObject>;
+ // https://docs.couchdb.org/en/stable/api/server/common.html#api-server-root
+ info(callback?: Callback<InfoResponse>): Promise<InfoResponse>;
}
interface FollowEmitter extends EventEmitter {
follow(): void;
}
-
+
interface UUIDObject {
uuids: string[]
}
+ // https://docs.couchdb.org/en/stable/api/server/common.html#api-server-root
+ interface InfoResponse {
+ couchdb: string;
+ version: string;
+ git_sha: string;
+ uuid: string;
+ features: string[];
+ vendor: { name: string }
+ }
+
interface DatabaseCreateParams {
n?: number;
partitioned?: boolean;
diff --git a/lib/nano.js b/lib/nano.js
index 3d0fd55..977b925 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -331,6 +331,11 @@ module.exports = exports = function dbScope (cfg) {
return relax({ db: '_session' }, callback)
}
+ // https://docs.couchdb.org/en/latest/api/server/common.html#api-server-root
+ function info (callback) {
+ return relax({ path: '' }, callback)
+ }
+
// http://docs.couchdb.org/en/latest/api/server/common.html#get--_db_updates
function updates (qs0, callback0) {
const { opts, callback } = getCallback(qs0, callback0)
@@ -1186,7 +1191,8 @@ module.exports = exports = function dbScope (cfg) {
session: session,
updates: updates,
followUpdates: followUpdates,
- uuids: uuids
+ uuids: uuids,
+ info: info
})
const db = maybeExtractDatabaseComponent()
diff --git a/test/nano.info.test.js b/test/nano.info.test.js
new file mode 100644
index 0000000..6cb8717
--- /dev/null
+++ b/test/nano.info.test.js
@@ -0,0 +1,41 @@
+// 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('../lib/nano')
+const COUCH_URL = 'http://localhost:5984'
+const nano = Nano(COUCH_URL)
+const nock = require('nock')
+
+afterEach(() => {
+ nock.cleanAll()
+})
+
+test('should be able to get info - GET / - nano.info', async () => {
+ // mocks
+ // https://docs.couchdb.org/en/stable/api/server/common.html#api-server-root
+ const response = {
+ couchdb: 'Welcome',
+ version: '3.1.0',
+ git_sha: 'ff0feea20',
+ uuid: '396b43eec08b8827026730270d5fe0ce',
+ features: ['access-ready', 'partitioned', 'pluggable-storage-engines', 'reshard', 'scheduler'],
+ vendor: { name: 'The Apache Software Foundation' }
+ }
+ const scope = nock(COUCH_URL)
+ .get('/')
+ .reply(200, response)
+
+ // test GET /_session
+ const p = await nano.info()
+ expect(p).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
+})