@openmeter/client 1.0.0-beta-2af6231af002 → 1.0.0-beta-8eb6a5bc1722
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/dist/lib/paginate.d.ts +12 -6
- package/dist/lib/paginate.js +23 -9
- package/dist/lib/version.d.ts +1 -1
- package/dist/lib/version.js +1 -1
- package/package.json +1 -1
package/dist/lib/paginate.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ interface CursorEnvelope<TItem> {
|
|
|
34
34
|
meta: {
|
|
35
35
|
page: {
|
|
36
36
|
next: string | null;
|
|
37
|
+
previous?: string | null;
|
|
37
38
|
};
|
|
38
39
|
};
|
|
39
40
|
}
|
|
@@ -45,12 +46,17 @@ interface CursorRequest {
|
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
|
-
* Iterates every item of a cursor-paginated list operation
|
|
49
|
-
* `
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
49
|
+
* Iterates every item of a cursor-paginated list operation. Despite carrying a
|
|
50
|
+
* `format: uri` annotation in the spec, `next` and `previous` are the opaque
|
|
51
|
+
* cursor tokens the API expects back verbatim in `page.after` or
|
|
52
|
+
* `page.before` on the following request — not URIs to fetch directly.
|
|
53
|
+
*
|
|
54
|
+
* The caller's request picks the direction. With `page.before`, the walk goes
|
|
55
|
+
* backward: it follows `meta.page.previous` through `page.before`, so it never
|
|
56
|
+
* returns items past the caller's bound. Otherwise it follows `meta.page.next`
|
|
57
|
+
* through `page.after`. A page request never carries both cursors, which the
|
|
58
|
+
* API rejects; a request that starts with both throws before any fetch. Every
|
|
59
|
+
* other field on `request` is sent unchanged on every page fetch.
|
|
54
60
|
*/
|
|
55
61
|
export declare function paginateCursor<TItem, TReq extends CursorRequest>(fetchPage: (req: TReq, options?: RequestOptions) => Promise<Result<CursorEnvelope<TItem>>>, request: TReq, options?: RequestOptions): AsyncGenerator<TItem, void, undefined>;
|
|
56
62
|
export {};
|
package/dist/lib/paginate.js
CHANGED
|
@@ -38,23 +38,37 @@ export async function* paginatePages(fetchPage, request, options) {
|
|
|
38
38
|
throw new PaginationLimitExceededError(MAX_PAGINATION_PAGES);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
* Iterates every item of a cursor-paginated list operation
|
|
42
|
-
* `
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
41
|
+
* Iterates every item of a cursor-paginated list operation. Despite carrying a
|
|
42
|
+
* `format: uri` annotation in the spec, `next` and `previous` are the opaque
|
|
43
|
+
* cursor tokens the API expects back verbatim in `page.after` or
|
|
44
|
+
* `page.before` on the following request — not URIs to fetch directly.
|
|
45
|
+
*
|
|
46
|
+
* The caller's request picks the direction. With `page.before`, the walk goes
|
|
47
|
+
* backward: it follows `meta.page.previous` through `page.before`, so it never
|
|
48
|
+
* returns items past the caller's bound. Otherwise it follows `meta.page.next`
|
|
49
|
+
* through `page.after`. A page request never carries both cursors, which the
|
|
50
|
+
* API rejects; a request that starts with both throws before any fetch. Every
|
|
51
|
+
* other field on `request` is sent unchanged on every page fetch.
|
|
47
52
|
*/
|
|
48
53
|
export async function* paginateCursor(fetchPage, request, options) {
|
|
54
|
+
if (request.page?.after !== undefined && request.page?.before !== undefined) {
|
|
55
|
+
throw new Error('cursor pagination cannot use both page.after and page.before');
|
|
56
|
+
}
|
|
57
|
+
const backward = request.page?.before !== undefined;
|
|
49
58
|
let req = request;
|
|
50
59
|
for (let page = 0; page < MAX_PAGINATION_PAGES; page++) {
|
|
51
60
|
const res = unwrap(await fetchPage(req, options));
|
|
52
61
|
yield* res.data;
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
62
|
+
const cursor = backward ? res.meta.page.previous : res.meta.page.next;
|
|
63
|
+
if (!cursor || res.data.length === 0) {
|
|
55
64
|
return;
|
|
56
65
|
}
|
|
57
|
-
req = {
|
|
66
|
+
req = {
|
|
67
|
+
...req,
|
|
68
|
+
page: backward
|
|
69
|
+
? { ...req.page, before: cursor }
|
|
70
|
+
: { ...req.page, after: cursor },
|
|
71
|
+
};
|
|
58
72
|
}
|
|
59
73
|
throw new PaginationLimitExceededError(MAX_PAGINATION_PAGES);
|
|
60
74
|
}
|
package/dist/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.0-beta-
|
|
1
|
+
export declare const SDK_VERSION = "1.0.0-beta-8eb6a5bc1722";
|
package/dist/lib/version.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
// The committed value is a dev placeholder. The publish flow
|
|
3
3
|
// (`make -C api/spec publish-aip-sdk`) stamps the real release version here
|
|
4
4
|
// before `pnpm publish`, after `pnpm version` updates package.json.
|
|
5
|
-
export const SDK_VERSION = '1.0.0-beta-
|
|
5
|
+
export const SDK_VERSION = '1.0.0-beta-8eb6a5bc1722';
|