Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 9f255ac

Browse files
authored
Merge pull request #295 from cloudant/291-fix-ts-cloudant-init
291 fix ts cloudant init
2 parents 7c033fa + 7b8c0e4 commit 9f255ac

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# UNRELEASED
22
- [FIXED] Add missing `maxAttempt` parameter to TypeScript definition.
3+
- [FIXED] Include client initialization callback in TypeScript definition.
34
- [FIXED] Removed test and lint data that bloated npm package size.
45
- [FIXED] Support Cloudant query when using promises request plugin.
56

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,7 @@ type. For example:
784784
```js
785785
import * as Cloudant from '@cloudant/cloudant';
786786

787-
var cloudant = Cloudant({ account: 'me', password: 'password', plugins: [ 'promises' ] });
788-
var client = cloudant as Cloudant.ServerScope;
787+
var client = Cloudant({ account: 'me', password: 'password', plugins: [ 'promises' ] });
789788

790789
(client.db.list() as any).then((d) => { console.log(d); });
791790
```

types/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import * as nano from 'nano';
1616
import { Request, CoreOptions } from "request";
1717

1818
declare function cloudant(
19-
config: cloudant.Configuration | string
20-
): cloudant.ServerScope | cloudant.DocumentScope<any>;
19+
config: cloudant.Configuration | string,
20+
callback?: (error: any, client?: cloudant.ServerScope, pong?: any) => void
21+
): cloudant.ServerScope;
2122

2223
declare namespace cloudant {
2324
type Callback<R> = (error: any, response: R, headers?: any) => void;

types/tests.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,21 @@ const config: cloudant.Configuration = {
2727

2828
const cfgInstance = cloudant(config);
2929

30+
/*
31+
* Run Initialization Callback
32+
*/
33+
cloudant(config, (error, client, pong) => {
34+
if (error) {
35+
return;
36+
} else if (client) {
37+
client.db.list((error, allDbs) => {});
38+
}
39+
});
40+
3041
/*
3142
* Server Scope
3243
*/
33-
const instance = <cloudant.ServerScope> cloudant(
34-
"http://localhost:5984/emails"
35-
);
44+
const instance = cloudant("http://localhost:5984");
3645

3746
instance.ping((pong) => {});
3847

0 commit comments

Comments
 (0)