@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.
@@ -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, following
49
- * `meta.page.next` until the server stops returning one. Despite carrying a
50
- * `format: uri` annotation in the spec, `next` is the opaque cursor token the
51
- * API expects back verbatim in `page.after` on the following request — not a
52
- * URI to fetch directly. Every other field on `request` is sent unchanged on
53
- * every page fetch; only `page.after` advances.
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 {};
@@ -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, following
42
- * `meta.page.next` until the server stops returning one. Despite carrying a
43
- * `format: uri` annotation in the spec, `next` is the opaque cursor token the
44
- * API expects back verbatim in `page.after` on the following request — not a
45
- * URI to fetch directly. Every other field on `request` is sent unchanged on
46
- * every page fetch; only `page.after` advances.
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 next = res.meta.page.next;
54
- if (!next) {
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 = { ...req, page: { ...req.page, after: next } };
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
  }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.0-beta-2af6231af002";
1
+ export declare const SDK_VERSION = "1.0.0-beta-8eb6a5bc1722";
@@ -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-2af6231af002';
5
+ export const SDK_VERSION = '1.0.0-beta-8eb6a5bc1722';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmeter/client",
3
- "version": "1.0.0-beta-2af6231af002",
3
+ "version": "1.0.0-beta-8eb6a5bc1722",
4
4
  "description": "Official TypeScript SDK for the OpenMeter API — usage metering and billing",
5
5
  "keywords": [
6
6
  "openmeter",