Skip to content

Commit

Permalink
feat: update via SDK Studio (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Mar 10, 2024
1 parent 1133eb8 commit fc0e3df
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 66 deletions.
6 changes: 2 additions & 4 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2524,11 +2524,10 @@ Methods:
Types:

- <code><a href="./src/resources/kv/namespaces/keys.ts">WorkersKVKey</a></code>
- <code><a href="./src/resources/kv/namespaces/keys.ts">KeyListResponse</a></code>

Methods:

- <code title="get /accounts/{account_id}/storage/kv/namespaces/{namespace_id}/keys">client.kv.namespaces.keys.<a href="./src/resources/kv/namespaces/keys.ts">list</a>(namespaceId, { ...params }) -> KeyListResponse</code>
- <code title="get /accounts/{account_id}/storage/kv/namespaces/{namespace_id}/keys">client.kv.namespaces.keys.<a href="./src/resources/kv/namespaces/keys.ts">list</a>(namespaceId, { ...params }) -> WorkersKVKeysCursorPagination</code>

### Metadata

Expand Down Expand Up @@ -2572,11 +2571,10 @@ Methods:
Types:

- <code><a href="./src/resources/durable-objects/namespaces/objects.ts">WorkersObject</a></code>
- <code><a href="./src/resources/durable-objects/namespaces/objects.ts">ObjectListResponse</a></code>

Methods:

- <code title="get /accounts/{account_id}/workers/durable_objects/namespaces/{id}/objects">client.durableObjects.namespaces.objects.<a href="./src/resources/durable-objects/namespaces/objects.ts">list</a>(id, { ...params }) -> ObjectListResponse | null</code>
- <code title="get /accounts/{account_id}/workers/durable_objects/namespaces/{id}/objects">client.durableObjects.namespaces.objects.<a href="./src/resources/durable-objects/namespaces/objects.ts">list</a>(id, { ...params }) -> WorkersObjectsCursorPagination</code>

# Queues

Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
67 changes: 67 additions & 0 deletions src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,70 @@ export class V4PagePaginationArray<Item>
return { params: { page: currentPage + 1 } };
}
}

export interface CursorPaginationResponse<Item> {
result: Array<Item>;

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<Item> extends AbstractPage<Item> implements CursorPaginationResponse<Item> {
result: Array<Item>;

result_info: CursorPaginationResponse.ResultInfo;

constructor(
client: APIClient,
response: Response,
body: CursorPaginationResponse<Item>,
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<CursorPaginationParams> | 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,
},
};
}
}
2 changes: 1 addition & 1 deletion src/resources/durable-objects/namespaces/index.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion src/resources/durable-objects/namespaces/namespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
35 changes: 11 additions & 24 deletions src/resources/durable-objects/namespaces/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -12,17 +13,18 @@ export class Objects extends APIResource {
id: string,
params: ObjectListParams,
options?: Core.RequestOptions,
): Core.APIPromise<ObjectListResponse | null> {
): Core.PagePromise<WorkersObjectsCursorPagination, WorkersObject> {
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<WorkersObject> {}

export interface WorkersObject {
/**
* ID of the Durable Object.
Expand All @@ -35,30 +37,15 @@ export interface WorkersObject {
hasStoredData?: boolean;
}

export type ObjectListResponse = Array<WorkersObject>;

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;
}
2 changes: 1 addition & 1 deletion src/resources/kv/namespaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 11 additions & 25 deletions src/resources/kv/namespaces/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -12,17 +13,18 @@ export class Keys extends APIResource {
namespaceId: string,
params: KeyListParams,
options?: Core.RequestOptions,
): Core.APIPromise<KeyListResponse> {
): Core.PagePromise<WorkersKVKeysCursorPagination, WorkersKVKey> {
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<WorkersKVKey> {}

/**
* A name for a value. A value stored under a given key may be retrieved via the
* same key.
Expand All @@ -46,28 +48,12 @@ export interface WorkersKVKey {
metadata?: unknown;
}

export type KeyListResponse = Array<WorkersKVKey>;

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.
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion src/resources/kv/namespaces/namespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit fc0e3df

Please sign in to comment.