From fc0e3df7a7617630a04034afaebe2b244b14213c Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Sun, 10 Mar 2024 01:45:44 +0000
Subject: [PATCH] feat: update via SDK Studio (#125)
---
api.md | 6 +-
src/index.ts | 4 ++
src/pagination.ts | 67 +++++++++++++++++++
.../durable-objects/namespaces/index.ts | 2 +-
.../durable-objects/namespaces/namespaces.ts | 2 +-
.../durable-objects/namespaces/objects.ts | 35 +++-------
src/resources/kv/namespaces/index.ts | 2 +-
src/resources/kv/namespaces/keys.ts | 36 +++-------
src/resources/kv/namespaces/namespaces.ts | 2 +-
yarn.lock | 18 ++---
10 files changed, 108 insertions(+), 66 deletions(-)
diff --git a/api.md b/api.md
index a50de488dc..1c44b710f5 100644
--- a/api.md
+++ b/api.md
@@ -2524,11 +2524,10 @@ Methods:
Types:
- WorkersKVKey
-- KeyListResponse
Methods:
-- client.kv.namespaces.keys.list(namespaceId, { ...params }) -> KeyListResponse
+- client.kv.namespaces.keys.list(namespaceId, { ...params }) -> WorkersKVKeysCursorPagination
### Metadata
@@ -2572,11 +2571,10 @@ Methods:
Types:
- WorkersObject
-- ObjectListResponse
Methods:
-- client.durableObjects.namespaces.objects.list(id, { ...params }) -> ObjectListResponse | null
+- client.durableObjects.namespaces.objects.list(id, { ...params }) -> WorkersObjectsCursorPagination
# Queues
diff --git a/src/index.ts b/src/index.ts
index d130ead5d1..dfd8ebacac 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -378,6 +378,10 @@ export namespace Cloudflare {
export import V4PagePaginationArrayParams = Pagination.V4PagePaginationArrayParams;
export import V4PagePaginationArrayResponse = Pagination.V4PagePaginationArrayResponse;
+ export import CursorPagination = Pagination.CursorPagination;
+ export import CursorPaginationParams = Pagination.CursorPaginationParams;
+ export import CursorPaginationResponse = Pagination.CursorPaginationResponse;
+
export import Accounts = API.Accounts;
export import Account = API.Account;
export import AccountUpdateResponse = API.AccountUpdateResponse;
diff --git a/src/pagination.ts b/src/pagination.ts
index dfe446319f..34f239573b 100644
--- a/src/pagination.ts
+++ b/src/pagination.ts
@@ -126,3 +126,70 @@ export class V4PagePaginationArray-
return { params: { page: currentPage + 1 } };
}
}
+
+export interface CursorPaginationResponse
- {
+ result: Array
- ;
+
+ result_info: CursorPaginationResponse.ResultInfo;
+}
+
+export namespace CursorPaginationResponse {
+ export interface ResultInfo {
+ count?: number;
+
+ cursor?: string;
+
+ per_page?: number;
+ }
+}
+
+export interface CursorPaginationParams {
+ limit?: number;
+
+ cursor?: string;
+}
+
+export class CursorPagination
- extends AbstractPage
- implements CursorPaginationResponse
- {
+ result: Array
- ;
+
+ result_info: CursorPaginationResponse.ResultInfo;
+
+ constructor(
+ client: APIClient,
+ response: Response,
+ body: CursorPaginationResponse
- ,
+ options: FinalRequestOptions,
+ ) {
+ super(client, response, body, options);
+
+ this.result = body.result || [];
+ this.result_info = body.result_info || {};
+ }
+
+ getPaginatedItems(): Item[] {
+ return this.result ?? [];
+ }
+
+ // @deprecated Please use `nextPageInfo()` instead
+ nextPageParams(): Partial | null {
+ const info = this.nextPageInfo();
+ if (!info) return null;
+ if ('params' in info) return info.params;
+ const params = Object.fromEntries(info.url.searchParams);
+ if (!Object.keys(params).length) return null;
+ return params;
+ }
+
+ nextPageInfo(): PageInfo | null {
+ const cursor = this.result_info?.cursor;
+ if (!cursor) {
+ return null;
+ }
+
+ return {
+ params: {
+ cursor: cursor,
+ },
+ };
+ }
+}
diff --git a/src/resources/durable-objects/namespaces/index.ts b/src/resources/durable-objects/namespaces/index.ts
index 984d90ddcd..ec2984d060 100644
--- a/src/resources/durable-objects/namespaces/index.ts
+++ b/src/resources/durable-objects/namespaces/index.ts
@@ -1,4 +1,4 @@
// File generated from our OpenAPI spec by Stainless.
export { WorkersNamespace, NamespaceListResponse, NamespaceListParams, Namespaces } from './namespaces';
-export { WorkersObject, ObjectListResponse, ObjectListParams, Objects } from './objects';
+export { WorkersObject, ObjectListParams, WorkersObjectsCursorPagination, Objects } from './objects';
diff --git a/src/resources/durable-objects/namespaces/namespaces.ts b/src/resources/durable-objects/namespaces/namespaces.ts
index 277b59af1e..c090bcb05c 100644
--- a/src/resources/durable-objects/namespaces/namespaces.ts
+++ b/src/resources/durable-objects/namespaces/namespaces.ts
@@ -50,6 +50,6 @@ export namespace Namespaces {
export import NamespaceListParams = NamespacesAPI.NamespaceListParams;
export import Objects = ObjectsAPI.Objects;
export import WorkersObject = ObjectsAPI.WorkersObject;
- export import ObjectListResponse = ObjectsAPI.ObjectListResponse;
+ export import WorkersObjectsCursorPagination = ObjectsAPI.WorkersObjectsCursorPagination;
export import ObjectListParams = ObjectsAPI.ObjectListParams;
}
diff --git a/src/resources/durable-objects/namespaces/objects.ts b/src/resources/durable-objects/namespaces/objects.ts
index f4e164e93c..272a0de680 100644
--- a/src/resources/durable-objects/namespaces/objects.ts
+++ b/src/resources/durable-objects/namespaces/objects.ts
@@ -3,6 +3,7 @@
import * as Core from 'cloudflare/core';
import { APIResource } from 'cloudflare/resource';
import * as ObjectsAPI from 'cloudflare/resources/durable-objects/namespaces/objects';
+import { CursorPagination, type CursorPaginationParams } from 'cloudflare/pagination';
export class Objects extends APIResource {
/**
@@ -12,17 +13,18 @@ export class Objects extends APIResource {
id: string,
params: ObjectListParams,
options?: Core.RequestOptions,
- ): Core.APIPromise {
+ ): Core.PagePromise {
const { account_id, ...query } = params;
- return (
- this._client.get(`/accounts/${account_id}/workers/durable_objects/namespaces/${id}/objects`, {
- query,
- ...options,
- }) as Core.APIPromise<{ result: ObjectListResponse | null }>
- )._thenUnwrap((obj) => obj.result);
+ return this._client.getAPIList(
+ `/accounts/${account_id}/workers/durable_objects/namespaces/${id}/objects`,
+ WorkersObjectsCursorPagination,
+ { query, ...options },
+ );
}
}
+export class WorkersObjectsCursorPagination extends CursorPagination {}
+
export interface WorkersObject {
/**
* ID of the Durable Object.
@@ -35,30 +37,15 @@ export interface WorkersObject {
hasStoredData?: boolean;
}
-export type ObjectListResponse = Array;
-
-export interface ObjectListParams {
+export interface ObjectListParams extends CursorPaginationParams {
/**
* Path param: Identifier
*/
account_id: string;
-
- /**
- * Query param: Opaque token indicating the position from which to continue when
- * requesting the next set of records. A valid value for the cursor can be obtained
- * from the cursors object in the result_info structure.
- */
- cursor?: string;
-
- /**
- * Query param: The number of objects to return. The cursor attribute may be used
- * to iterate over the next batch of objects if there are more than the limit.
- */
- limit?: number;
}
export namespace Objects {
export import WorkersObject = ObjectsAPI.WorkersObject;
- export import ObjectListResponse = ObjectsAPI.ObjectListResponse;
+ export import WorkersObjectsCursorPagination = ObjectsAPI.WorkersObjectsCursorPagination;
export import ObjectListParams = ObjectsAPI.ObjectListParams;
}
diff --git a/src/resources/kv/namespaces/index.ts b/src/resources/kv/namespaces/index.ts
index 0fa1cd5b2f..699bb872b5 100644
--- a/src/resources/kv/namespaces/index.ts
+++ b/src/resources/kv/namespaces/index.ts
@@ -11,7 +11,7 @@ export {
ValueGetParams,
Values,
} from './values';
-export { WorkersKVKey, KeyListResponse, KeyListParams, Keys } from './keys';
+export { WorkersKVKey, KeyListParams, WorkersKVKeysCursorPagination, Keys } from './keys';
export {
WorkersKVNamespace,
NamespaceUpdateResponse,
diff --git a/src/resources/kv/namespaces/keys.ts b/src/resources/kv/namespaces/keys.ts
index 0d91e647b1..855f82d2ae 100644
--- a/src/resources/kv/namespaces/keys.ts
+++ b/src/resources/kv/namespaces/keys.ts
@@ -3,6 +3,7 @@
import * as Core from 'cloudflare/core';
import { APIResource } from 'cloudflare/resource';
import * as KeysAPI from 'cloudflare/resources/kv/namespaces/keys';
+import { CursorPagination, type CursorPaginationParams } from 'cloudflare/pagination';
export class Keys extends APIResource {
/**
@@ -12,17 +13,18 @@ export class Keys extends APIResource {
namespaceId: string,
params: KeyListParams,
options?: Core.RequestOptions,
- ): Core.APIPromise {
+ ): Core.PagePromise {
const { account_id, ...query } = params;
- return (
- this._client.get(`/accounts/${account_id}/storage/kv/namespaces/${namespaceId}/keys`, {
- query,
- ...options,
- }) as Core.APIPromise<{ result: KeyListResponse }>
- )._thenUnwrap((obj) => obj.result);
+ return this._client.getAPIList(
+ `/accounts/${account_id}/storage/kv/namespaces/${namespaceId}/keys`,
+ WorkersKVKeysCursorPagination,
+ { query, ...options },
+ );
}
}
+export class WorkersKVKeysCursorPagination extends CursorPagination {}
+
/**
* A name for a value. A value stored under a given key may be retrieved via the
* same key.
@@ -46,28 +48,12 @@ export interface WorkersKVKey {
metadata?: unknown;
}
-export type KeyListResponse = Array;
-
-export interface KeyListParams {
+export interface KeyListParams extends CursorPaginationParams {
/**
* Path param: Identifier
*/
account_id: string;
- /**
- * Query param: Opaque token indicating the position from which to continue when
- * requesting the next set of records if the amount of list results was limited by
- * the limit parameter. A valid value for the cursor can be obtained from the
- * `cursors` object in the `result_info` structure.
- */
- cursor?: string;
-
- /**
- * Query param: The number of keys to return. The cursor attribute may be used to
- * iterate over the next batch of keys if there are more than the limit.
- */
- limit?: number;
-
/**
* Query param: A string prefix used to filter down which keys will be returned.
* Exact matches and any key names that begin with the prefix will be returned.
@@ -77,6 +63,6 @@ export interface KeyListParams {
export namespace Keys {
export import WorkersKVKey = KeysAPI.WorkersKVKey;
- export import KeyListResponse = KeysAPI.KeyListResponse;
+ export import WorkersKVKeysCursorPagination = KeysAPI.WorkersKVKeysCursorPagination;
export import KeyListParams = KeysAPI.KeyListParams;
}
diff --git a/src/resources/kv/namespaces/namespaces.ts b/src/resources/kv/namespaces/namespaces.ts
index e53ef4ed90..97d6d1db46 100644
--- a/src/resources/kv/namespaces/namespaces.ts
+++ b/src/resources/kv/namespaces/namespaces.ts
@@ -168,7 +168,7 @@ export namespace Namespaces {
export import BulkDeleteParams = BulkAPI.BulkDeleteParams;
export import Keys = KeysAPI.Keys;
export import WorkersKVKey = KeysAPI.WorkersKVKey;
- export import KeyListResponse = KeysAPI.KeyListResponse;
+ export import WorkersKVKeysCursorPagination = KeysAPI.WorkersKVKeysCursorPagination;
export import KeyListParams = KeysAPI.KeyListParams;
export import Metadata = MetadataAPI.Metadata;
export import MetadataGetResponse = MetadataAPI.MetadataGetResponse;
diff --git a/yarn.lock b/yarn.lock
index 050acfb9b5..7820c7b289 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1366,7 +1366,7 @@ default-browser@^4.0.0:
execa "^7.1.1"
titleize "^3.0.0"
-define-data-property@^1.1.2:
+define-data-property@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/define-data-property/-/define-data-property-1.1.4.tgz#894dc141bb7d3060ae4366f6a0107e68fbe48c5e"
integrity sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==
@@ -1808,7 +1808,7 @@ get-caller-file@^2.0.5:
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
-get-intrinsic@^1.1.3, get-intrinsic@^1.2.3, get-intrinsic@^1.2.4:
+get-intrinsic@^1.1.3, get-intrinsic@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.2.4.tgz#e385f5a4b5227d449c3eabbad05494ef0abbeadd"
integrity sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==
@@ -1911,7 +1911,7 @@ has-flag@^4.0.0:
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
-has-property-descriptors@^1.0.1:
+has-property-descriptors@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz#963ed7d071dc7bf5f084c5bfbe0d1b6222586854"
integrity sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==
@@ -3073,16 +3073,16 @@ semver@^7.5.3, semver@^7.5.4:
lru-cache "^6.0.0"
set-function-length@^1.2.1:
- version "1.2.1"
- resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.1.tgz#47cc5945f2c771e2cf261c6737cf9684a2a5e425"
- integrity sha512-j4t6ccc+VsKwYHso+kElc5neZpjtq9EnRICFZtWyBsLojhmeF/ZBd/elqm22WJh/BziDe/SBiOeAt0m2mfLD0g==
+ version "1.2.2"
+ resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.2.tgz#aac72314198eaed975cf77b2c3b6b880695e5449"
+ integrity sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==
dependencies:
- define-data-property "^1.1.2"
+ define-data-property "^1.1.4"
es-errors "^1.3.0"
function-bind "^1.1.2"
- get-intrinsic "^1.2.3"
+ get-intrinsic "^1.2.4"
gopd "^1.0.1"
- has-property-descriptors "^1.0.1"
+ has-property-descriptors "^1.0.2"
shebang-command@^2.0.0:
version "2.0.0"