From 42aa0bea47478746a7b11b1ce6dc76a8335c9f57 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Sun, 14 Jul 2024 14:02:39 +0000 Subject: [PATCH] feat(api): update via SDK Studio --- .stats.yml | 2 +- api.md | 4 +++ src/index.ts | 1 + src/resources/files.ts | 35 ++++++++++++++++++++++++ src/resources/index.ts | 2 +- tests/api-resources/files.test.ts | 44 +++++++++++++++++++++++++++++++ 6 files changed, 86 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index b2a2ac22..468de8f6 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 12 +configured_endpoints: 15 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-2aa0ec0ea99873da5dac6ecf610efdd6ccfe5601d2400f8c475d994cd47c2c36.yml diff --git a/api.md b/api.md index 75a1a6c4..56043867 100644 --- a/api.md +++ b/api.md @@ -55,8 +55,12 @@ Methods: Types: - File +- FileDeleteResponse Methods: +- client.files.retrieve(fileId) -> File - client.files.list({ ...params }) -> FilesCursorPage +- client.files.delete(fileId) -> FileDeleteResponse +- client.files.download(fileId) -> Response - client.files.upload({ ...params }) -> File diff --git a/src/index.ts b/src/index.ts index 8a59f4cb..b70c1924 100644 --- a/src/index.ts +++ b/src/index.ts @@ -218,6 +218,7 @@ export namespace Writer { export import Files = API.Files; export import File = API.File; + export import FileDeleteResponse = API.FileDeleteResponse; export import FilesCursorPage = API.FilesCursorPage; export import FileListParams = API.FileListParams; export import FileUploadParams = API.FileUploadParams; diff --git a/src/resources/files.ts b/src/resources/files.ts index 41b78127..1de80ada 100644 --- a/src/resources/files.ts +++ b/src/resources/files.ts @@ -5,8 +5,16 @@ import { isRequestOptions } from '../core'; import * as Core from '../core'; import * as FilesAPI from './files'; import { CursorPage, type CursorPageParams } from '../pagination'; +import { type Response } from '../_shims/index'; export class Files extends APIResource { + /** + * Retrieve file + */ + retrieve(fileId: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.get(`/v1/files/${fileId}`, options); + } + /** * List files */ @@ -22,6 +30,20 @@ export class Files extends APIResource { return this._client.getAPIList('/v1/files', FilesCursorPage, { query, ...options }); } + /** + * Delete file + */ + delete(fileId: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.delete(`/v1/files/${fileId}`, options); + } + + /** + * Download file + */ + download(fileId: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.get(`/v1/files/${fileId}/download`, { ...options, __binaryResponse: true }); + } + /** * Upload file */ @@ -70,6 +92,18 @@ export interface File { name: string; } +export interface FileDeleteResponse { + /** + * A unique identifier of the deleted graph. + */ + id: string; + + /** + * Indicates whether the graph was successfully deleted. + */ + deleted: boolean; +} + export interface FileListParams extends CursorPageParams { /** * The unique identifier of the graph to which the files belong. @@ -114,6 +148,7 @@ export interface FileUploadParams { export namespace Files { export import File = FilesAPI.File; + export import FileDeleteResponse = FilesAPI.FileDeleteResponse; export import FilesCursorPage = FilesAPI.FilesCursorPage; export import FileListParams = FilesAPI.FileListParams; export import FileUploadParams = FilesAPI.FileUploadParams; diff --git a/src/resources/index.ts b/src/resources/index.ts index fe07bfea..facce82d 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -16,7 +16,7 @@ export { CompletionCreateParamsStreaming, Completions, } from './completions'; -export { File, FileListParams, FileUploadParams, FilesCursorPage, Files } from './files'; +export { File, FileDeleteResponse, FileListParams, FileUploadParams, FilesCursorPage, Files } from './files'; export { Graph, GraphCreateResponse, diff --git a/tests/api-resources/files.test.ts b/tests/api-resources/files.test.ts index 4a98c1ab..0fa3cd00 100644 --- a/tests/api-resources/files.test.ts +++ b/tests/api-resources/files.test.ts @@ -9,6 +9,24 @@ const writer = new Writer({ }); describe('resource files', () => { + test('retrieve', async () => { + const responsePromise = writer.files.retrieve('file_id'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('retrieve: request options instead of params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect(writer.files.retrieve('file_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + Writer.NotFoundError, + ); + }); + test('list', async () => { const responsePromise = writer.files.list(); const rawResponse = await responsePromise.asResponse(); @@ -43,6 +61,32 @@ describe('resource files', () => { ).rejects.toThrow(Writer.NotFoundError); }); + test('delete', async () => { + const responsePromise = writer.files.delete('file_id'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('delete: request options instead of params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect(writer.files.delete('file_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + Writer.NotFoundError, + ); + }); + + // requests with binary data not yet supported in test environment + test.skip('download: request options instead of params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect(writer.files.download('file_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + Writer.NotFoundError, + ); + }); + // requests with binary data not yet supported in test environment test.skip('upload: only required params', async () => { const responsePromise = writer.files.upload({