UNPKG

8.31 kBTypeScriptView Raw
1/**
2 * Contains the results of a view query.
3 *
4 * @category Views
5 */
6export declare class ViewResult<TValue = any, TKey = any> {
7 /**
8 * The rows which have been returned by the query.
9 */
10 rows: ViewRow<TKey, TValue>[];
11 /**
12 * The meta-data which has been returned by the query.
13 */
14 meta: ViewMetaData;
15 /**
16 * @internal
17 */
18 constructor(data: ViewResult);
19}
20/**
21 * Contains the meta-data that is returend from a view query.
22 *
23 * @category Views
24 */
25export declare class ViewMetaData {
26 /**
27 * The total number of rows available in the index that match the query.
28 */
29 totalRows?: number;
30 /**
31 * Contains various pieces of debug information exposed by the view service.
32 */
33 debug?: any;
34 /**
35 * @internal
36 */
37 constructor(data: {
38 totalRows?: number;
39 debug?: any;
40 });
41 /**
42 * Same as {@link ViewMetaData.totalRows}, but represented as
43 * the raw server-side value.
44 *
45 * @deprecated Use {@link ViewMetaData.totalRows} instead.
46 */
47 get total_rows(): number | undefined;
48}
49/**
50 * Contains the contents of a single row returned by a view query.
51 *
52 * @category Views
53 */
54export declare class ViewRow<TValue = any, TKey = any> {
55 /**
56 * The value for this row.
57 */
58 value: TValue;
59 /**
60 * The key for this row.
61 */
62 key?: TKey;
63 /**
64 * The id for this row.
65 */
66 id?: string;
67 /**
68 * @internal
69 */
70 constructor(data: ViewRow);
71}
72/**
73 * Specifies the namespace for the associated Design Document.
74 *
75 * @category Views
76 */
77export declare enum DesignDocumentNamespace {
78 /**
79 * Indicates that the Design Document namespace is within the development environment.
80 */
81 Development = "development",
82 /**
83 * Indicates that the Design Document namespace is within the producion environment.
84 */
85 Production = "production"
86}
87/**
88 * Represents the various scan consistency options that are available when
89 * querying against the views service.
90 *
91 * @category Views
92 */
93export declare enum ViewScanConsistency {
94 /**
95 * Indicates that no specific consistency is required, this is the fastest
96 * options, but results may not include the most recent operations which have
97 * been performed.
98 */
99 NotBounded = "ok",
100 /**
101 * Indicates that the results to the query should include all operations that
102 * have occurred up until the query was started. This incurs a performance
103 * penalty of waiting for the index to catch up to the most recent operations,
104 * but provides the highest level of consistency.
105 */
106 RequestPlus = "false",
107 /**
108 * Indicates that the results of the query should behave according to similar
109 * semantics as NotBounded, but following the execution of the query the index
110 * should begin updating such that following queries will likely include up
111 * to date data.
112 */
113 UpdateAfter = "update_after"
114}
115/**
116 * Specifies the ordering mode of a view query.
117 *
118 * @category Views
119 */
120export declare enum ViewOrdering {
121 /**
122 * Indicates that results should be returned in ascending order.
123 */
124 Ascending = "false",
125 /**
126 * Indicates that results should be returned in descending order.
127 */
128 Descending = "true"
129}
130/**
131 * Specifies the error handling mode for a view query.
132 *
133 * @category Views
134 */
135export declare enum ViewErrorMode {
136 /**
137 * Indicates that if an error occurs during the execution of the view query,
138 * the query should continue to process and include any available results.
139 */
140 Continue = "continue",
141 /**
142 * Indicates that if an error occurs during the execution of the view query,
143 * the query should be aborted immediately rather than attempting to continue.
144 */
145 Stop = "stop"
146}
147/**
148 * Specifies the key range for a view query.
149 *
150 * @category Views
151 */
152export interface ViewQueryKeyRange {
153 /**
154 * Specifies the first key that should be included in the results.
155 */
156 start?: string | string[];
157 /**
158 * Specifies the last key that should be included in the results.
159 */
160 end?: string | string[];
161 /**
162 * Specifies whether the end key should be considered inclusive or exclusive.
163 */
164 inclusiveEnd?: boolean;
165 /**
166 * Same as {@link ViewQueryKeyRange.inclusiveEnd}, but represented as
167 * the raw server-side value instead.
168 *
169 * @deprecated Use {@link ViewQueryKeyRange.inclusiveEnd} instead.
170 */
171 inclusive_end?: boolean;
172}
173/**
174 * Specifies the id range for a view query.
175 *
176 * @category Views
177 */
178export interface ViewQueryIdRange {
179 /**
180 * Specifies the first id that should be included in the results.
181 */
182 start?: string;
183 /**
184 * Specifies the last id (inclusively) that should be included in the results.
185 */
186 end?: string;
187}
188/**
189 * @category Views
190 */
191export interface ViewQueryOptions {
192 /**
193 * Specifies the consistency requirements when executing the query.
194 *
195 * @see ViewScanConsistency
196 */
197 scanConsistency?: ViewScanConsistency;
198 /**
199 * Specifies the number of results to skip from the index before returning
200 * results.
201 */
202 skip?: number;
203 /**
204 * Specifies the limit to the number of results that should be returned.
205 */
206 limit?: number;
207 /**
208 * Specifies the ordering that should be used when returning results.
209 */
210 order?: ViewOrdering;
211 /**
212 * Specifies whether reduction should be performed as part of the query.
213 */
214 reduce?: boolean;
215 /**
216 * Specifies whether the results should be grouped together.
217 */
218 group?: boolean;
219 /**
220 * Specifies the level to which results should be group.
221 */
222 groupLevel?: number;
223 /**
224 * Specifies a specific key which should be fetched from the index.
225 */
226 key?: string;
227 /**
228 * Specifies a list of keys which should be fetched from the index.
229 */
230 keys?: string[];
231 /**
232 * Specifies a range of keys that should be fetched from the index.
233 */
234 range?: ViewQueryKeyRange;
235 /**
236 * Specifies a range of ids that should be fetched from the index.
237 */
238 idRange?: ViewQueryIdRange;
239 /**
240 * Indicates whether the query should force the entire set of document in the index
241 * to be included in the result. This is on by default for production views and off
242 * by default for development views (only a subset of results may be returned).
243 */
244 fullSet?: boolean;
245 /**
246 * Specifies the error-handling behaviour that should be used when an error occurs.
247 */
248 onError?: ViewErrorMode;
249 /**
250 * The timeout for this operation, represented in milliseconds.
251 */
252 timeout?: number;
253 /**
254 * Same as {@link ViewQueryOptions.scanConsistency}, but represented as
255 * the raw server-side value instead.
256 *
257 * @deprecated Use {@link ViewQueryOptions.scanConsistency} instead.
258 */
259 stale?: string | ViewScanConsistency;
260 /**
261 * Same as {@link ViewQueryOptions.groupLevel}, but represented as
262 * the raw server-side value instead.
263 *
264 * @deprecated Use {@link ViewQueryOptions.groupLevel} instead.
265 */
266 group_level?: number;
267 /**
268 * Same as {@link ViewQueryOptions.idRange}, but represented as
269 * the raw server-side value instead.
270 *
271 * @deprecated Use {@link ViewQueryOptions.idRange} instead.
272 */
273 id_range?: ViewQueryIdRange;
274 /**
275 * Same as {@link ViewQueryOptions.fullSet}, but represented as
276 * the raw server-side value instead.
277 *
278 * @deprecated Use {@link ViewQueryOptions.fullSet} instead.
279 */
280 full_set?: boolean;
281 /**
282 * Same as {@link ViewQueryOptions.onError}, but represented as
283 * the raw server-side value instead.
284 *
285 * @deprecated Use {@link ViewQueryOptions.onError} instead.
286 */
287 on_error?: ViewErrorMode;
288 /**
289 * Specifies any additional parameters which should be passed to the view engine
290 * when executing the view query.
291 */
292 raw?: {
293 [key: string]: string;
294 };
295 /**
296 * Specifies the design document namespace to use when executing the view query.
297 */
298 namespace?: DesignDocumentNamespace;
299}