Skip to content

Commit

Permalink
chore(internal): update APIResource structure (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Nov 16, 2023
1 parent 4cf475a commit 38a4e5f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 40 deletions.
21 changes: 0 additions & 21 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,27 +564,6 @@ export abstract class APIClient {
}
}

export class APIResource {
protected client: APIClient;
constructor(client: APIClient) {
this.client = client;

this.get = client.get.bind(client);
this.post = client.post.bind(client);
this.patch = client.patch.bind(client);
this.put = client.put.bind(client);
this.delete = client.delete.bind(client);
this.getAPIList = client.getAPIList.bind(client);
}

protected get: APIClient['get'];
protected post: APIClient['post'];
protected patch: APIClient['patch'];
protected put: APIClient['put'];
protected delete: APIClient['delete'];
protected getAPIList: APIClient['getAPIList'];
}

export type PageInfo = { url: URL } | { params: Record<string, unknown> | null };

export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
Expand Down
19 changes: 3 additions & 16 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,9 @@
import type { Anthropic } from './index';

export class APIResource {
protected client: Anthropic;
constructor(client: Anthropic) {
this.client = client;
protected _client: Anthropic;

this.get = client.get.bind(client);
this.post = client.post.bind(client);
this.patch = client.patch.bind(client);
this.put = client.put.bind(client);
this.delete = client.delete.bind(client);
this.getAPIList = client.getAPIList.bind(client);
constructor(client: Anthropic) {
this._client = client;
}

protected get: Anthropic['get'];
protected post: Anthropic['post'];
protected patch: Anthropic['patch'];
protected put: Anthropic['put'];
protected delete: Anthropic['delete'];
protected getAPIList: Anthropic['getAPIList'];
}
9 changes: 6 additions & 3 deletions src/resources/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ export class Completions extends APIResource {
body: CompletionCreateParams,
options?: Core.RequestOptions,
): APIPromise<Completion> | APIPromise<Stream<Completion>> {
return this.post('/v1/complete', { body, timeout: 600000, ...options, stream: body.stream ?? false }) as
| APIPromise<Completion>
| APIPromise<Stream<Completion>>;
return this._client.post('/v1/complete', {
body,
timeout: 600000,
...options,
stream: body.stream ?? false,
}) as APIPromise<Completion> | APIPromise<Stream<Completion>>;
}
}

Expand Down

0 comments on commit 38a4e5f

Please sign in to comment.