UNPKG

4.74 kBTypeScriptView Raw
1// Copyright © 2018 IBM Corp. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import * as nano from 'nano';
16import { CoreOptions } from 'request';
17
18declare function cloudant(
19 config: cloudant.Configuration | string,
20 callback?: (error: any, client?: cloudant.ServerScope, pong?: any) => void
21): cloudant.ServerScope;
22
23declare namespace cloudant {
24 type Callback<R> = (error: any, response: R, headers?: any) => void;
25
26 interface ApiKey {
27 key: string;
28 password: string;
29 }
30
31 interface Configuration {
32 account?: string;
33 password?: string;
34 vcapInstanceName?: string;
35 vcapServices?: string;
36 url?: string;
37 cookie?: string;
38 requestDefaults?: CoreOptions;
39 log?(id: string, args: any): void;
40 parseUrl?: boolean;
41 request?(params: any): void;
42 plugins?: any;
43 maxAttempt?: number;
44 }
45
46 interface CORS {
47 enable_cors: boolean;
48 allow_credentials: boolean;
49 origins: string[];
50 }
51
52 interface GeoParams {
53 include_docs?: boolean;
54 bookmark?: string;
55 format?: string;
56 limit?: number;
57 skip?: number;
58 stale?: string;
59 bbox?: number[];
60 lat?: number;
61 lon?: number;
62 rangex?: number;
63 rangey?: number;
64 radius?: number;
65 g?: any;
66 relation?: string;
67 nearest?: boolean;
68 }
69
70 interface GeoResult {
71 bookmark: string;
72 features: any[];
73 row: any[];
74 type: string;
75 }
76
77 interface Query {
78 // https://console.bluemix.net/docs/services/Cloudant/api/cloudant_query.html#query
79 (definition?: any, callback?: Callback<any>): Promise<any>;
80
81 // https://console.bluemix.net/docs/services/Cloudant/api/cloudant_query.html#deleting-an-index
82 del(spec: QueryDeleteSpec, callback?: Callback<any>): Promise<any>;
83 }
84
85 interface QueryDeleteSpec {
86 ddoc: string;
87 name: string;
88 }
89
90 interface SearchParams {
91 q: string;
92 include_docs?: boolean;
93 bookmark?: string;
94 limit?: number;
95 skip?: number;
96 stale?: string;
97 }
98
99 interface Security {
100 [key: string]: any;
101 }
102
103 // Server Scope
104 // ============
105
106 interface ServerScope extends nano.ServerScope {
107 db: nano.DatabaseScope;
108 use(db: string): DocumentScope<any>;
109 scope(db: string): DocumentScope<any>;
110
111 // https://console.bluemix.net/docs/services/Cloudant/api/authorization.html#api-keys
112 generate_api_key(callback?: Callback<ApiKey>): Promise<any>;
113
114 // https://console.bluemix.net/docs/services/Cloudant/api/cors.html#reading-the-cors-configuration
115 get_cors(callback?: Callback<any>): Promise<any>;
116
117 // https://console.bluemix.net/docs/services/Cloudant/api/account.html#ping
118 ping(callback?: Callback<any>): Promise<any>;
119
120 // https://console.bluemix.net/docs/services/Cloudant/api/cors.html#setting-the-cors-configuration
121 set_cors(cors: CORS, callback?: Callback<any>): Promise<any>;
122 }
123
124 // Document Scope
125 // ==============
126
127 interface DocumentScope<D> extends nano.DocumentScope<D> {
128 // https://console.bluemix.net/docs/services/Cloudant/api/cloudant_query.html
129 index: Query;
130
131 // https://console.bluemix.net/docs/services/Cloudant/api/document.html#the-_bulk_get-endpoint
132 bulk_get(options: nano.BulkModifyDocsWrapper, callback?: Callback<any>): Promise<any>;
133
134 // https://console.bluemix.net/docs/services/Cloudant/api/cloudant-geo.html#cloudant-geospatial
135 geo(
136 designname: string,
137 docname: string,
138 params: GeoParams,
139 callback?: Callback<GeoResult>
140 ): Promise<any>;
141
142 // https://console.bluemix.net/docs/services/Cloudant/api/authorization.html#viewing-permissions
143 get_security(callback?: Callback<Security>): Promise<any>;
144
145 // https://console.bluemix.net/docs/services/Cloudant/api/authorization.html#modifying-permissions
146 set_security(Security: Security, callback?: Callback<any>): Promise<any>;
147 }
148}
149
150export = cloudant;