-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathpagination.ts
369 lines (369 loc) · 11.5 KB
/
pagination.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import { BinaryReader, BinaryWriter } from "../../../../binary";
import { bytesFromBase64, base64FromBytes } from "../../../../helpers";
/**
* PageRequest is to be embedded in gRPC request messages for efficient
* pagination. Ex:
*
* message SomeRequest {
* Foo some_parameter = 1;
* PageRequest pagination = 2;
* }
*/
export interface PageRequest {
/**
* key is a value returned in PageResponse.next_key to begin
* querying the next page most efficiently. Only one of offset or key
* should be set.
*/
key: Uint8Array;
/**
* offset is a numeric offset that can be used when key is unavailable.
* It is less efficient than using key. Only one of offset or key should
* be set.
*/
offset: bigint;
/**
* limit is the total number of results to be returned in the result page.
* If left empty it will default to a value to be set by each app.
*/
limit: bigint;
/**
* count_total is set to true to indicate that the result set should include
* a count of the total number of items available for pagination in UIs.
* count_total is only respected when offset is used. It is ignored when key
* is set.
*/
countTotal: boolean;
/**
* reverse is set to true if results are to be returned in the descending order.
*
* Since: cosmos-sdk 0.43
*/
reverse: boolean;
}
export interface PageRequestProtoMsg {
typeUrl: "/cosmos.base.query.v1beta1.PageRequest";
value: Uint8Array;
}
/**
* PageRequest is to be embedded in gRPC request messages for efficient
* pagination. Ex:
*
* message SomeRequest {
* Foo some_parameter = 1;
* PageRequest pagination = 2;
* }
*/
export interface PageRequestAmino {
/**
* key is a value returned in PageResponse.next_key to begin
* querying the next page most efficiently. Only one of offset or key
* should be set.
*/
key?: string;
/**
* offset is a numeric offset that can be used when key is unavailable.
* It is less efficient than using key. Only one of offset or key should
* be set.
*/
offset?: string;
/**
* limit is the total number of results to be returned in the result page.
* If left empty it will default to a value to be set by each app.
*/
limit?: string;
/**
* count_total is set to true to indicate that the result set should include
* a count of the total number of items available for pagination in UIs.
* count_total is only respected when offset is used. It is ignored when key
* is set.
*/
count_total?: boolean;
/**
* reverse is set to true if results are to be returned in the descending order.
*
* Since: cosmos-sdk 0.43
*/
reverse?: boolean;
}
export interface PageRequestAminoMsg {
type: "cosmos-sdk/PageRequest";
value: PageRequestAmino;
}
/**
* PageRequest is to be embedded in gRPC request messages for efficient
* pagination. Ex:
*
* message SomeRequest {
* Foo some_parameter = 1;
* PageRequest pagination = 2;
* }
*/
export interface PageRequestSDKType {
key: Uint8Array;
offset: bigint;
limit: bigint;
count_total: boolean;
reverse: boolean;
}
/**
* PageResponse is to be embedded in gRPC response messages where the
* corresponding request message has used PageRequest.
*
* message SomeResponse {
* repeated Bar results = 1;
* PageResponse page = 2;
* }
*/
export interface PageResponse {
/**
* next_key is the key to be passed to PageRequest.key to
* query the next page most efficiently
*/
nextKey: Uint8Array;
/**
* total is total number of results available if PageRequest.count_total
* was set, its value is undefined otherwise
*/
total: bigint;
}
export interface PageResponseProtoMsg {
typeUrl: "/cosmos.base.query.v1beta1.PageResponse";
value: Uint8Array;
}
/**
* PageResponse is to be embedded in gRPC response messages where the
* corresponding request message has used PageRequest.
*
* message SomeResponse {
* repeated Bar results = 1;
* PageResponse page = 2;
* }
*/
export interface PageResponseAmino {
/**
* next_key is the key to be passed to PageRequest.key to
* query the next page most efficiently
*/
next_key?: string;
/**
* total is total number of results available if PageRequest.count_total
* was set, its value is undefined otherwise
*/
total?: string;
}
export interface PageResponseAminoMsg {
type: "cosmos-sdk/PageResponse";
value: PageResponseAmino;
}
/**
* PageResponse is to be embedded in gRPC response messages where the
* corresponding request message has used PageRequest.
*
* message SomeResponse {
* repeated Bar results = 1;
* PageResponse page = 2;
* }
*/
export interface PageResponseSDKType {
next_key: Uint8Array;
total: bigint;
}
function createBasePageRequest(): PageRequest {
return {
key: new Uint8Array(),
offset: BigInt(0),
limit: BigInt(0),
countTotal: false,
reverse: false
};
}
export const PageRequest = {
typeUrl: "/cosmos.base.query.v1beta1.PageRequest",
encode(message: PageRequest, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter {
if (message.key.length !== 0) {
writer.uint32(10).bytes(message.key);
}
if (message.offset !== BigInt(0)) {
writer.uint32(16).uint64(message.offset);
}
if (message.limit !== BigInt(0)) {
writer.uint32(24).uint64(message.limit);
}
if (message.countTotal === true) {
writer.uint32(32).bool(message.countTotal);
}
if (message.reverse === true) {
writer.uint32(40).bool(message.reverse);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): PageRequest {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePageRequest();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.key = reader.bytes();
break;
case 2:
message.offset = reader.uint64();
break;
case 3:
message.limit = reader.uint64();
break;
case 4:
message.countTotal = reader.bool();
break;
case 5:
message.reverse = reader.bool();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromPartial(object: Partial<PageRequest>): PageRequest {
const message = createBasePageRequest();
message.key = object.key ?? new Uint8Array();
message.offset = object.offset !== undefined && object.offset !== null ? BigInt(object.offset.toString()) : BigInt(0);
message.limit = object.limit !== undefined && object.limit !== null ? BigInt(object.limit.toString()) : BigInt(0);
message.countTotal = object.countTotal ?? false;
message.reverse = object.reverse ?? false;
return message;
},
fromAmino(object: PageRequestAmino): PageRequest {
const message = createBasePageRequest();
if (object.key !== undefined && object.key !== null) {
message.key = bytesFromBase64(object.key);
}
if (object.offset !== undefined && object.offset !== null) {
message.offset = BigInt(object.offset);
}
if (object.limit !== undefined && object.limit !== null) {
message.limit = BigInt(object.limit);
}
if (object.count_total !== undefined && object.count_total !== null) {
message.countTotal = object.count_total;
}
if (object.reverse !== undefined && object.reverse !== null) {
message.reverse = object.reverse;
}
return message;
},
toAmino(message: PageRequest): PageRequestAmino {
const obj: any = {};
obj.key = message.key ? base64FromBytes(message.key) : undefined;
obj.offset = message.offset !== BigInt(0) ? message.offset.toString() : undefined;
obj.limit = message.limit !== BigInt(0) ? message.limit.toString() : undefined;
obj.count_total = message.countTotal === false ? undefined : message.countTotal;
obj.reverse = message.reverse === false ? undefined : message.reverse;
return obj;
},
fromAminoMsg(object: PageRequestAminoMsg): PageRequest {
return PageRequest.fromAmino(object.value);
},
toAminoMsg(message: PageRequest): PageRequestAminoMsg {
return {
type: "cosmos-sdk/PageRequest",
value: PageRequest.toAmino(message)
};
},
fromProtoMsg(message: PageRequestProtoMsg): PageRequest {
return PageRequest.decode(message.value);
},
toProto(message: PageRequest): Uint8Array {
return PageRequest.encode(message).finish();
},
toProtoMsg(message: PageRequest): PageRequestProtoMsg {
return {
typeUrl: "/cosmos.base.query.v1beta1.PageRequest",
value: PageRequest.encode(message).finish()
};
}
};
function createBasePageResponse(): PageResponse {
return {
nextKey: new Uint8Array(),
total: BigInt(0)
};
}
export const PageResponse = {
typeUrl: "/cosmos.base.query.v1beta1.PageResponse",
encode(message: PageResponse, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter {
if (message.nextKey.length !== 0) {
writer.uint32(10).bytes(message.nextKey);
}
if (message.total !== BigInt(0)) {
writer.uint32(16).uint64(message.total);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): PageResponse {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePageResponse();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.nextKey = reader.bytes();
break;
case 2:
message.total = reader.uint64();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromPartial(object: Partial<PageResponse>): PageResponse {
const message = createBasePageResponse();
message.nextKey = object.nextKey ?? new Uint8Array();
message.total = object.total !== undefined && object.total !== null ? BigInt(object.total.toString()) : BigInt(0);
return message;
},
fromAmino(object: PageResponseAmino): PageResponse {
const message = createBasePageResponse();
if (object.next_key !== undefined && object.next_key !== null) {
message.nextKey = bytesFromBase64(object.next_key);
}
if (object.total !== undefined && object.total !== null) {
message.total = BigInt(object.total);
}
return message;
},
toAmino(message: PageResponse): PageResponseAmino {
const obj: any = {};
obj.next_key = message.nextKey ? base64FromBytes(message.nextKey) : undefined;
obj.total = message.total !== BigInt(0) ? message.total.toString() : undefined;
return obj;
},
fromAminoMsg(object: PageResponseAminoMsg): PageResponse {
return PageResponse.fromAmino(object.value);
},
toAminoMsg(message: PageResponse): PageResponseAminoMsg {
return {
type: "cosmos-sdk/PageResponse",
value: PageResponse.toAmino(message)
};
},
fromProtoMsg(message: PageResponseProtoMsg): PageResponse {
return PageResponse.decode(message.value);
},
toProto(message: PageResponse): Uint8Array {
return PageResponse.encode(message).finish();
},
toProtoMsg(message: PageResponse): PageResponseProtoMsg {
return {
typeUrl: "/cosmos.base.query.v1beta1.PageResponse",
value: PageResponse.encode(message).finish()
};
}
};