UNPKG

6.82 kBTypeScriptView Raw
1// Copyright © 2018, 2019 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, Request } 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 vcapServiceName?: string;
37 url?: string;
38 cookie?: string;
39 requestDefaults?: CoreOptions;
40 log?(id: string, args: any): void;
41 parseUrl?: boolean;
42 request?(params: any): void;
43 plugins?: any;
44 maxAttempt?: number;
45 }
46
47 interface CORS {
48 enable_cors: boolean;
49 allow_credentials: boolean;
50 origins: string[];
51 }
52
53 interface DatabasePartitionInfo {
54 db_name: string;
55 sizes: {
56 active: number;
57 external: number;
58 };
59 partition: string;
60 doc_count: number;
61 doc_del_count: number;
62 }
63
64 interface GeoParams {
65 include_docs?: boolean;
66 bookmark?: string;
67 format?: string;
68 limit?: number;
69 skip?: number;
70 stale?: string;
71 bbox?: number[];
72 lat?: number;
73 lon?: number;
74 rangex?: number;
75 rangey?: number;
76 radius?: number;
77 g?: any;
78 relation?: string;
79 nearest?: boolean;
80 }
81
82 interface GeoResult {
83 bookmark: string;
84 features: any[];
85 row: any[];
86 type: string;
87 }
88
89 interface Query {
90 // https://console.bluemix.net/docs/services/Cloudant/api/cloudant_query.html#query
91 (definition?: any, callback?: Callback<any>): Promise<any>;
92
93 // https://console.bluemix.net/docs/services/Cloudant/api/cloudant_query.html#deleting-an-index
94 del(spec: QueryDeleteSpec, callback?: Callback<any>): Promise<any>;
95 }
96
97 interface QueryDeleteSpec {
98 ddoc: string;
99 name: string;
100 }
101
102 interface Security {
103 [key: string]: any;
104 }
105
106 // Server Scope
107 // ============
108
109 interface ServerScope extends nano.ServerScope {
110 db: nano.DatabaseScope;
111 use(db: string): DocumentScope<any>;
112 scope(db: string): DocumentScope<any>;
113
114 // https://console.bluemix.net/docs/services/Cloudant/api/authorization.html#api-keys
115 generate_api_key(callback?: Callback<ApiKey>): Promise<any>;
116
117 // https://console.bluemix.net/docs/services/Cloudant/api/cors.html#reading-the-cors-configuration
118 get_cors(callback?: Callback<any>): Promise<any>;
119
120 // https://console.bluemix.net/docs/services/Cloudant/api/account.html#ping
121 ping(callback?: Callback<any>): Promise<any>;
122
123 // https://console.bluemix.net/docs/services/Cloudant/api/cors.html#setting-the-cors-configuration
124 set_cors(cors: CORS, callback?: Callback<any>): Promise<any>;
125 }
126
127 // Document Scope
128 // ==============
129
130 interface DocumentScope<D> extends nano.DocumentScope<D> {
131 // https://console.bluemix.net/docs/services/Cloudant/api/cloudant_query.html
132 index: Query;
133
134 // https://console.bluemix.net/docs/services/Cloudant/api/document.html#the-_bulk_get-endpoint
135 bulk_get(options: nano.BulkModifyDocsWrapper, callback?: Callback<any>): Promise<any>;
136
137 // https://console.bluemix.net/docs/services/Cloudant/api/cloudant-geo.html#cloudant-geospatial
138 geo(
139 designname: string,
140 docname: string,
141 params: GeoParams,
142 callback?: Callback<GeoResult>
143 ): Promise<any>;
144
145 // https://console.bluemix.net/docs/services/Cloudant/api/authorization.html#viewing-permissions
146 get_security(callback?: Callback<Security>): Promise<any>;
147
148 // https://console.bluemix.net/docs/services/Cloudant/api/authorization.html#modifying-permissions
149 set_security(Security: Security, callback?: Callback<any>): Promise<any>;
150
151
152 // Partitioned Databases
153 // ---------------------
154
155 // https://cloud.ibm.com/docs/services/Cloudant/guides?topic=cloudant-database-partitioning
156
157 partitionInfo(
158 partitionKey: string,
159 callback?: Callback<DatabasePartitionInfo>
160 ): Promise<DatabasePartitionInfo>;
161
162 partitionedFind(
163 partitionKey: string,
164 selector: nano.MangoQuery,
165 callback?: Callback<nano.MangoResponse<D>>
166 ): Promise<nano.MangoResponse<D>>;
167
168 partitionedFindAsStream(
169 partitionKey: string,
170 selector: nano.MangoQuery
171 ): Request;
172
173 partitionedList(
174 partitionKey: string,
175 params: nano.DocumentFetchParams,
176 callback?: Callback<nano.DocumentListResponse<D>>
177 ): Promise<nano.DocumentListResponse<D>>;
178
179 partitionedListAsStream(
180 partitionKey: string,
181 params: nano.DocumentFetchParams
182 ): Request;
183
184 partitionedSearch<V>(
185 partitionKey: string,
186 designname: string,
187 searchname: string,
188 params: nano.DocumentSearchParams,
189 callback?: Callback<nano.DocumentSearchResponse<V>>
190 ): Promise<nano.DocumentSearchResponse<V>>;
191
192 partitionedSearchAsStream<V>(
193 partitionKey: string,
194 designname: string,
195 searchname: string,
196 params: nano.DocumentSearchParams
197 ): Request;
198
199 partitionedView<V>(
200 partitionKey: string,
201 designname: string,
202 viewname: string,
203 params: nano.DocumentViewParams,
204 callback?: Callback<nano.DocumentViewResponse<V,D>>
205 ): Promise<nano.DocumentViewResponse<V,D>>;
206
207 partitionedViewAsStream<V>(
208 partitionKey: string,
209 designname: string,
210 viewname: string,
211 params: nano.DocumentViewParams
212 ): Request;
213 }
214}
215
216export = cloudant;