Skip to content

Commit 2804eac

Browse files
committed
Add nano.info()
1 parent f04b24f commit 2804eac

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ See [Migration Guide for switching from Nano 6.x to 7.x](migration_6_to_7.md).
5252
- [nano.config](#nanoconfig)
5353
- [nano.updates([params], [callback])](#nanoupdatesparams-callback)
5454
- [nano.followUpdates([params], [callback])](#nanofollowupdatesparams-callback)
55+
- [nano.info([callback])](#nanoinfocallback)
5556
- [Document functions](#document-functions)
5657
- [db.insert(doc, [params], [callback])](#dbinsertdoc-params-callback)
5758
- [db.destroy(docname, rev, [callback])](#dbdestroydocname-rev-callback)
@@ -546,6 +547,10 @@ process.nextTick( () => {
546547
});
547548
```
548549

550+
### nano.info([callback])
551+
552+
Get meta information about database instance.
553+
549554
## Document functions
550555

551556
### db.insert(doc, [params], [callback])

lib/nano.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,28 @@ declare namespace nano {
4848
followUpdates(callback: Callback<any>): void;
4949
followUpdates(params: any, callback: Callback<any>): void;
5050
uuids(num: number, callback?: Callback<any>): Promise<UUIDObject>;
51+
// https://docs.couchdb.org/en/stable/api/server/common.html#api-server-root
52+
info(callback?: Callback<InfoResponse>): Promise<InfoResponse>;
5153
}
5254

5355
interface FollowEmitter extends EventEmitter {
5456
follow(): void;
5557
}
56-
58+
5759
interface UUIDObject {
5860
uuids: string[]
5961
}
6062

63+
// https://docs.couchdb.org/en/stable/api/server/common.html#api-server-root
64+
interface InfoResponse {
65+
couchdb: string;
66+
version: string;
67+
git_sha: string;
68+
uuid: string;
69+
features: string[];
70+
vendor: { name: string }
71+
}
72+
6173
interface DatabaseCreateParams {
6274
n?: number;
6375
partitioned?: boolean;

lib/nano.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ module.exports = exports = function dbScope (cfg) {
331331
return relax({ db: '_session' }, callback)
332332
}
333333

334+
// https://docs.couchdb.org/en/latest/api/server/common.html#api-server-root
335+
function info (callback) {
336+
return relax({ path: '' }, callback)
337+
}
338+
334339
// http://docs.couchdb.org/en/latest/api/server/common.html#get--_db_updates
335340
function updates (qs0, callback0) {
336341
const { opts, callback } = getCallback(qs0, callback0)
@@ -1186,7 +1191,8 @@ module.exports = exports = function dbScope (cfg) {
11861191
session: session,
11871192
updates: updates,
11881193
followUpdates: followUpdates,
1189-
uuids: uuids
1194+
uuids: uuids,
1195+
info: info
11901196
})
11911197

11921198
const db = maybeExtractDatabaseComponent()

test/nano.info.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
2+
// use this file except in compliance with the License. You may obtain a copy of
3+
// the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
9+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
// License for the specific language governing permissions and limitations under
11+
// the License.
12+
13+
const Nano = require('../lib/nano')
14+
const COUCH_URL = 'http://localhost:5984'
15+
const nano = Nano(COUCH_URL)
16+
const nock = require('nock')
17+
18+
afterEach(() => {
19+
nock.cleanAll()
20+
})
21+
22+
test('should be able to get info - GET / - nano.info', async () => {
23+
// mocks
24+
// https://docs.couchdb.org/en/stable/api/server/common.html#api-server-root
25+
const response = {
26+
couchdb: 'Welcome',
27+
version: '3.1.0',
28+
git_sha: 'ff0feea20',
29+
uuid: '396b43eec08b8827026730270d5fe0ce',
30+
features: ['access-ready', 'partitioned', 'pluggable-storage-engines', 'reshard', 'scheduler'],
31+
vendor: { name: 'The Apache Software Foundation' }
32+
}
33+
const scope = nock(COUCH_URL)
34+
.get('/')
35+
.reply(200, response)
36+
37+
// test GET /_session
38+
const p = await nano.info()
39+
expect(p).toStrictEqual(response)
40+
expect(scope.isDone()).toBe(true)
41+
})

0 commit comments

Comments
 (0)