@polygonlabs/staking-api-client 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +72 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @polygonlabs/staking-api-client
|
|
2
2
|
|
|
3
|
+
## 1.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#350](https://github.com/0xPolygon/staking-api/pull/350) [`ed5352e`](https://github.com/0xPolygon/staking-api/commit/ed5352eb831079b745244b952be0f490755c208d) Thanks [@shan8851](https://github.com/shan8851)! - Document paging through lists with the cursor operations in the README: the `nextCursor` loop, the page-size and filter rules, and a `useInfiniteQuery` example for React
|
|
8
|
+
|
|
3
9
|
## 1.8.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -32,6 +32,78 @@ client.setConfig({ baseUrl: 'https://staking-api.polygon.technology' });
|
|
|
32
32
|
const { data } = await getAllValidatorsV3();
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
## Paging through lists
|
|
36
|
+
|
|
37
|
+
Use the cursor operations (`*PageV2` / `*PageV3`, served on the `/page`
|
|
38
|
+
routes) for every paged list. The offset operations (`limit`/`offset`) are
|
|
39
|
+
being deprecated: a deep offset makes the server walk and bill every
|
|
40
|
+
skipped row, while a cursor page is a single index seek, and its fixed URL
|
|
41
|
+
lets the Cloudflare edge serve it once for every client.
|
|
42
|
+
|
|
43
|
+
Leave out `cursor` to get the first page. Each page returns
|
|
44
|
+
`pagination.nextCursor`. Pass it back as `cursor` until it comes back as
|
|
45
|
+
`null`, which happens exactly on the last page:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { getCheckpointsSignedPageV3 } from '@polygonlabs/staking-api-client';
|
|
49
|
+
|
|
50
|
+
let cursor: string | undefined;
|
|
51
|
+
do {
|
|
52
|
+
const { data } = await getCheckpointsSignedPageV3({
|
|
53
|
+
path: { validatorId: 7 },
|
|
54
|
+
query: { cursor, limit: 100 },
|
|
55
|
+
throwOnError: true
|
|
56
|
+
});
|
|
57
|
+
for (const checkpoint of data.result.checkpointsSigned) {
|
|
58
|
+
// ...
|
|
59
|
+
}
|
|
60
|
+
cursor = data.pagination.nextCursor ?? undefined;
|
|
61
|
+
} while (cursor);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Rules a walk must follow:
|
|
65
|
+
|
|
66
|
+
- **The cursor is opaque.** Don't build or edit one. A cursor that doesn't
|
|
67
|
+
decode is a `400`, never a silent first page.
|
|
68
|
+
- **`limit` is one of 20, 50, 100 or 500**, and defaults to 20. Any other
|
|
69
|
+
value is a `400`. The fixed list keeps URLs identical across clients so
|
|
70
|
+
the edge cache is shared.
|
|
71
|
+
- **Send the same filters on every page** (e.g. `startTimestamp` /
|
|
72
|
+
`endTimestamp`). The cursor holds only the position, not the filters.
|
|
73
|
+
- **Totals and counters appear on the first page only** (`pagination.total`,
|
|
74
|
+
and `numberOfCheckpointsSigned` / `numberOfCheckpointsMissed` on
|
|
75
|
+
checkpoints). Later pages omit them so they stay byte-identical and
|
|
76
|
+
cacheable. Delegator pages carry no `total` at all.
|
|
77
|
+
|
|
78
|
+
### React
|
|
79
|
+
|
|
80
|
+
The `/react` entry point has no `*InfiniteOptions` factory for the cursor
|
|
81
|
+
operations: the codegen plugin skips infinite queries for any operation with
|
|
82
|
+
a registered query schema, and every cursor operation has one. Call the SDK
|
|
83
|
+
function from `useInfiniteQuery` instead:
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
87
|
+
|
|
88
|
+
import { getCheckpointsSignedPageV3 } from '@polygonlabs/staking-api-client';
|
|
89
|
+
|
|
90
|
+
const useCheckpoints = (validatorId: number) =>
|
|
91
|
+
useInfiniteQuery({
|
|
92
|
+
queryKey: ['checkpoints-signed', validatorId],
|
|
93
|
+
initialPageParam: undefined as string | undefined,
|
|
94
|
+
queryFn: async ({ pageParam, signal }) => {
|
|
95
|
+
const { data } = await getCheckpointsSignedPageV3({
|
|
96
|
+
path: { validatorId },
|
|
97
|
+
query: { cursor: pageParam },
|
|
98
|
+
signal,
|
|
99
|
+
throwOnError: true
|
|
100
|
+
});
|
|
101
|
+
return data;
|
|
102
|
+
},
|
|
103
|
+
getNextPageParam: (lastPage) => lastPage.pagination.nextCursor ?? undefined
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
35
107
|
## Entry points
|
|
36
108
|
|
|
37
109
|
- `@polygonlabs/staking-api-client` — the fetch-based SDK: one function per
|