Skip to content

Commit

Permalink
feat: update via SDK Studio (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Mar 10, 2024
1 parent fc0e3df commit 32d2349
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 68 deletions.
9 changes: 4 additions & 5 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@ Types:

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 }) -> WorkersKVKeysCursorPagination</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 }) -> WorkersKVKeysCursorLimitPagination</code>

### Metadata

Expand Down Expand Up @@ -2574,7 +2574,7 @@ Types:

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 }) -> WorkersObjectsCursorPagination</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 }) -> WorkersObjectsCursorLimitPagination</code>

# Queues

Expand Down Expand Up @@ -3550,7 +3550,7 @@ Methods:

- <code title="post /accounts/{account_id}/rules/lists/{list_id}/items">client.rules.lists.items.<a href="./src/resources/rules/lists/items.ts">create</a>(listId, [ ...body ]) -> ItemCreateResponse | null</code>
- <code title="put /accounts/{account_id}/rules/lists/{list_id}/items">client.rules.lists.items.<a href="./src/resources/rules/lists/items.ts">update</a>(listId, [ ...body ]) -> ItemUpdateResponse | null</code>
- <code title="get /accounts/{account_id}/rules/lists/{list_id}/items">client.rules.lists.items.<a href="./src/resources/rules/lists/items.ts">list</a>(listId, { ...params }) -> ItemListResponse | null</code>
- <code title="get /accounts/{account_id}/rules/lists/{list_id}/items">client.rules.lists.items.<a href="./src/resources/rules/lists/items.ts">list</a>(listId, { ...params }) -> ItemListResponsesCursorPagination</code>
- <code title="delete /accounts/{account_id}/rules/lists/{list_id}/items">client.rules.lists.items.<a href="./src/resources/rules/lists/items.ts">delete</a>(listId, { ...params }) -> ItemDeleteResponse | null</code>
- <code title="get /accounts/{account_identifier}/rules/lists/{list_id}/items/{item_id}">client.rules.lists.items.<a href="./src/resources/rules/lists/items.ts">get</a>(accountIdentifier, listId, itemId) -> ItemGetResponse | null</code>

Expand Down Expand Up @@ -3870,13 +3870,12 @@ Methods:
Types:

- <code><a href="./src/resources/r2/buckets.ts">R2Bucket</a></code>
- <code><a href="./src/resources/r2/buckets.ts">BucketListResponse</a></code>
- <code><a href="./src/resources/r2/buckets.ts">BucketDeleteResponse</a></code>

Methods:

- <code title="post /accounts/{account_id}/r2/buckets">client.r2.buckets.<a href="./src/resources/r2/buckets.ts">create</a>({ ...params }) -> R2Bucket</code>
- <code title="get /accounts/{account_id}/r2/buckets">client.r2.buckets.<a href="./src/resources/r2/buckets.ts">list</a>({ ...params }) -> BucketListResponse</code>
- <code title="get /accounts/{account_id}/r2/buckets">client.r2.buckets.<a href="./src/resources/r2/buckets.ts">list</a>({ ...params }) -> R2BucketsCursorPagination</code>
- <code title="delete /accounts/{account_id}/r2/buckets/{bucket_name}">client.r2.buckets.<a href="./src/resources/r2/buckets.ts">delete</a>(bucketName, { ...params }) -> BucketDeleteResponse</code>
- <code title="get /accounts/{account_id}/r2/buckets/{bucket_name}">client.r2.buckets.<a href="./src/resources/r2/buckets.ts">get</a>(bucketName, { ...params }) -> R2Bucket</code>

Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ export namespace Cloudflare {
export import CursorPaginationParams = Pagination.CursorPaginationParams;
export import CursorPaginationResponse = Pagination.CursorPaginationResponse;

export import CursorLimitPagination = Pagination.CursorLimitPagination;
export import CursorLimitPaginationParams = Pagination.CursorLimitPaginationParams;
export import CursorLimitPaginationResponse = Pagination.CursorLimitPaginationResponse;

export import Accounts = API.Accounts;
export import Account = API.Account;
export import AccountUpdateResponse = API.AccountUpdateResponse;
Expand Down
72 changes: 71 additions & 1 deletion src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export namespace CursorPaginationResponse {
}

export interface CursorPaginationParams {
limit?: number;
per_page?: number;

cursor?: string;
}
Expand Down Expand Up @@ -193,3 +193,73 @@ export class CursorPagination<Item> extends AbstractPage<Item> implements Cursor
};
}
}

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

result_info: CursorLimitPaginationResponse.ResultInfo;
}

export namespace CursorLimitPaginationResponse {
export interface ResultInfo {
count?: number;

cursor?: string;

per_page?: number;
}
}

export interface CursorLimitPaginationParams {
limit?: number;

cursor?: string;
}

export class CursorLimitPagination<Item>
extends AbstractPage<Item>
implements CursorLimitPaginationResponse<Item>
{
result: Array<Item>;

result_info: CursorLimitPaginationResponse.ResultInfo;

constructor(
client: APIClient,
response: Response,
body: CursorLimitPaginationResponse<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<CursorLimitPaginationParams> | 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, ObjectListParams, WorkersObjectsCursorPagination, Objects } from './objects';
export { WorkersObject, ObjectListParams, WorkersObjectsCursorLimitPagination, 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 WorkersObjectsCursorPagination = ObjectsAPI.WorkersObjectsCursorPagination;
export import WorkersObjectsCursorLimitPagination = ObjectsAPI.WorkersObjectsCursorLimitPagination;
export import ObjectListParams = ObjectsAPI.ObjectListParams;
}
12 changes: 6 additions & 6 deletions src/resources/durable-objects/namespaces/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +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';
import { CursorLimitPagination, type CursorLimitPaginationParams } from 'cloudflare/pagination';

export class Objects extends APIResource {
/**
Expand All @@ -13,17 +13,17 @@ export class Objects extends APIResource {
id: string,
params: ObjectListParams,
options?: Core.RequestOptions,
): Core.PagePromise<WorkersObjectsCursorPagination, WorkersObject> {
): Core.PagePromise<WorkersObjectsCursorLimitPagination, WorkersObject> {
const { account_id, ...query } = params;
return this._client.getAPIList(
`/accounts/${account_id}/workers/durable_objects/namespaces/${id}/objects`,
WorkersObjectsCursorPagination,
WorkersObjectsCursorLimitPagination,
{ query, ...options },
);
}
}

export class WorkersObjectsCursorPagination extends CursorPagination<WorkersObject> {}
export class WorkersObjectsCursorLimitPagination extends CursorLimitPagination<WorkersObject> {}

export interface WorkersObject {
/**
Expand All @@ -37,7 +37,7 @@ export interface WorkersObject {
hasStoredData?: boolean;
}

export interface ObjectListParams extends CursorPaginationParams {
export interface ObjectListParams extends CursorLimitPaginationParams {
/**
* Path param: Identifier
*/
Expand All @@ -46,6 +46,6 @@ export interface ObjectListParams extends CursorPaginationParams {

export namespace Objects {
export import WorkersObject = ObjectsAPI.WorkersObject;
export import WorkersObjectsCursorPagination = ObjectsAPI.WorkersObjectsCursorPagination;
export import WorkersObjectsCursorLimitPagination = ObjectsAPI.WorkersObjectsCursorLimitPagination;
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, KeyListParams, WorkersKVKeysCursorPagination, Keys } from './keys';
export { WorkersKVKey, KeyListParams, WorkersKVKeysCursorLimitPagination, Keys } from './keys';
export {
WorkersKVNamespace,
NamespaceUpdateResponse,
Expand Down
12 changes: 6 additions & 6 deletions src/resources/kv/namespaces/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +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';
import { CursorLimitPagination, type CursorLimitPaginationParams } from 'cloudflare/pagination';

export class Keys extends APIResource {
/**
Expand All @@ -13,17 +13,17 @@ export class Keys extends APIResource {
namespaceId: string,
params: KeyListParams,
options?: Core.RequestOptions,
): Core.PagePromise<WorkersKVKeysCursorPagination, WorkersKVKey> {
): Core.PagePromise<WorkersKVKeysCursorLimitPagination, WorkersKVKey> {
const { account_id, ...query } = params;
return this._client.getAPIList(
`/accounts/${account_id}/storage/kv/namespaces/${namespaceId}/keys`,
WorkersKVKeysCursorPagination,
WorkersKVKeysCursorLimitPagination,
{ query, ...options },
);
}
}

export class WorkersKVKeysCursorPagination extends CursorPagination<WorkersKVKey> {}
export class WorkersKVKeysCursorLimitPagination extends CursorLimitPagination<WorkersKVKey> {}

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

export interface KeyListParams extends CursorPaginationParams {
export interface KeyListParams extends CursorLimitPaginationParams {
/**
* Path param: Identifier
*/
Expand All @@ -63,6 +63,6 @@ export interface KeyListParams extends CursorPaginationParams {

export namespace Keys {
export import WorkersKVKey = KeysAPI.WorkersKVKey;
export import WorkersKVKeysCursorPagination = KeysAPI.WorkersKVKeysCursorPagination;
export import WorkersKVKeysCursorLimitPagination = KeysAPI.WorkersKVKeysCursorLimitPagination;
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 WorkersKVKeysCursorPagination = KeysAPI.WorkersKVKeysCursorPagination;
export import WorkersKVKeysCursorLimitPagination = KeysAPI.WorkersKVKeysCursorLimitPagination;
export import KeyListParams = KeysAPI.KeyListParams;
export import Metadata = MetadataAPI.Metadata;
export import MetadataGetResponse = MetadataAPI.MetadataGetResponse;
Expand Down
34 changes: 13 additions & 21 deletions src/resources/r2/buckets.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 BucketsAPI from 'cloudflare/resources/r2/buckets';
import { CursorPagination, type CursorPaginationParams } from 'cloudflare/pagination';

export class Buckets extends APIResource {
/**
Expand All @@ -20,13 +21,15 @@ export class Buckets extends APIResource {
/**
* Lists all R2 buckets on your account
*/
list(params: BucketListParams, options?: Core.RequestOptions): Core.APIPromise<BucketListResponse> {
list(
params: BucketListParams,
options?: Core.RequestOptions,
): Core.PagePromise<R2BucketsCursorPagination, R2Bucket> {
const { account_id, ...query } = params;
return (
this._client.get(`/accounts/${account_id}/r2/buckets`, { query, ...options }) as Core.APIPromise<{
result: BucketListResponse;
}>
)._thenUnwrap((obj) => obj.result);
return this._client.getAPIList(`/accounts/${account_id}/r2/buckets`, R2BucketsCursorPagination, {
query,
...options,
});
}

/**
Expand Down Expand Up @@ -58,6 +61,8 @@ export class Buckets extends APIResource {
}
}

export class R2BucketsCursorPagination extends CursorPagination<R2Bucket> {}

/**
* A single R2 bucket
*/
Expand All @@ -78,8 +83,6 @@ export interface R2Bucket {
name?: string;
}

export type BucketListResponse = Array<R2Bucket>;

export type BucketDeleteResponse = unknown;

export interface BucketCreateParams {
Expand All @@ -99,18 +102,12 @@ export interface BucketCreateParams {
locationHint?: 'apac' | 'eeur' | 'enam' | 'weur' | 'wnam';
}

export interface BucketListParams {
export interface BucketListParams extends CursorPaginationParams {
/**
* Path param: Account ID
*/
account_id: string;

/**
* Query param: Pagination cursor received during the last List Buckets call. R2
* buckets are paginated using cursors instead of page numbers.
*/
cursor?: string;

/**
* Query param: Direction to order buckets
*/
Expand All @@ -127,11 +124,6 @@ export interface BucketListParams {
*/
order?: 'name';

/**
* Query param: Maximum number of buckets to return in a single call
*/
per_page?: number;

/**
* Query param: Bucket name to start searching after. Buckets are ordered
* lexicographically.
Expand All @@ -155,8 +147,8 @@ export interface BucketGetParams {

export namespace Buckets {
export import R2Bucket = BucketsAPI.R2Bucket;
export import BucketListResponse = BucketsAPI.BucketListResponse;
export import BucketDeleteResponse = BucketsAPI.BucketDeleteResponse;
export import R2BucketsCursorPagination = BucketsAPI.R2BucketsCursorPagination;
export import BucketCreateParams = BucketsAPI.BucketCreateParams;
export import BucketListParams = BucketsAPI.BucketListParams;
export import BucketDeleteParams = BucketsAPI.BucketDeleteParams;
Expand Down
2 changes: 1 addition & 1 deletion src/resources/r2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
export { R2 } from './r2';
export {
R2Bucket,
BucketListResponse,
BucketDeleteResponse,
BucketCreateParams,
BucketListParams,
BucketDeleteParams,
BucketGetParams,
R2BucketsCursorPagination,
Buckets,
} from './buckets';
export {
Expand Down
2 changes: 1 addition & 1 deletion src/resources/r2/r2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export class R2 extends APIResource {
export namespace R2 {
export import Buckets = BucketsAPI.Buckets;
export import R2Bucket = BucketsAPI.R2Bucket;
export import BucketListResponse = BucketsAPI.BucketListResponse;
export import BucketDeleteResponse = BucketsAPI.BucketDeleteResponse;
export import R2BucketsCursorPagination = BucketsAPI.R2BucketsCursorPagination;
export import BucketCreateParams = BucketsAPI.BucketCreateParams;
export import BucketListParams = BucketsAPI.BucketListParams;
export import BucketDeleteParams = BucketsAPI.BucketDeleteParams;
Expand Down
1 change: 1 addition & 0 deletions src/resources/rules/lists/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
ItemUpdateParams,
ItemListParams,
ItemDeleteParams,
ItemListResponsesCursorPagination,
Items,
} from './items';
export {
Expand Down
Loading

0 comments on commit 32d2349

Please sign in to comment.