Skip to content

Commit b51b467

Browse files
feat(api): api update (#518)
1 parent dcb4323 commit b51b467

File tree

6 files changed

+138
-2
lines changed

6 files changed

+138
-2
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 37
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/val-town%2Fval-town-fdb8597c76fe77a92ca60e29d54dc0cc907861b822a699ed026232f758d5eaee.yml
1+
configured_endpoints: 38
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/val-town%2Fval-town-77a415f3dc452e48f6f1eb82618bfb4faf2192baf78f6a279efe4a725ca7d2f2.yml

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,13 @@ Methods:
198198

199199
Types:
200200

201+
- <code><a href="./src/resources/projects/files.ts">FileCreateResponse</a></code>
201202
- <code><a href="./src/resources/projects/files.ts">FileRetrieveResponse</a></code>
202203
- <code><a href="./src/resources/projects/files.ts">FileListResponse</a></code>
203204

204205
Methods:
205206

207+
- <code title="post /v1/projects/{project_id}/files/{path}">client.projects.files.<a href="./src/resources/projects/files.ts">create</a>(projectId, path, { ...params }) -> FileCreateResponse</code>
206208
- <code title="get /v1/projects/{project_id}/files/{path}">client.projects.files.<a href="./src/resources/projects/files.ts">retrieve</a>(projectId, path, { ...params }) -> FileRetrieveResponse</code>
207209
- <code title="get /v1/projects/{project_id}/files">client.projects.files.<a href="./src/resources/projects/files.ts">list</a>(projectId, { ...params }) -> FileListResponsesPageCursorURL</code>
208210
- <code title="get /v1/projects/{project_id}/files/{path}/content">client.projects.files.<a href="./src/resources/projects/files.ts">content</a>(projectId, path, { ...params }) -> Response</code>

src/resources/projects/files.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ import { PageCursorURL, type PageCursorURLParams } from '../../pagination';
88
import { type Response } from '../../_shims/index';
99

1010
export class Files extends APIResource {
11+
/**
12+
* [BETA] Create a new file, project val or directory
13+
*/
14+
create(
15+
projectId: string,
16+
path: string,
17+
params: FileCreateParams,
18+
options?: Core.RequestOptions,
19+
): Core.APIPromise<FileCreateResponse> {
20+
const { branch_id, ...body } = params;
21+
return this._client.post(`/v1/projects/${projectId}/files/${path}`, {
22+
query: { branch_id },
23+
body,
24+
...options,
25+
});
26+
}
27+
1128
/**
1229
* Get metadata for files and directories in a project at the specified path
1330
*/
@@ -80,6 +97,52 @@ export class Files extends APIResource {
8097

8198
export class FileListResponsesPageCursorURL extends PageCursorURL<FileListResponse> {}
8299

100+
/**
101+
* A File or Directory's Metadata
102+
*/
103+
export interface FileCreateResponse {
104+
/**
105+
* The id of the resource
106+
*/
107+
id: string;
108+
109+
links: FileCreateResponse.Links;
110+
111+
name: string;
112+
113+
path: string;
114+
115+
type: 'directory' | 'file' | 'interval' | 'http' | 'email' | 'script';
116+
117+
updatedAt: string;
118+
119+
version: number;
120+
}
121+
122+
export namespace FileCreateResponse {
123+
export interface Links {
124+
/**
125+
* The URL of this resource on Val Town
126+
*/
127+
html: string;
128+
129+
/**
130+
* The URL of this resource's source code as a module
131+
*/
132+
module: string;
133+
134+
/**
135+
* The URL of this resource on this API
136+
*/
137+
self: string;
138+
139+
/**
140+
* This resource's web endpoint, where it serves a website or API
141+
*/
142+
endpoint?: string;
143+
}
144+
}
145+
83146
/**
84147
* A paginated result set
85148
*/
@@ -186,6 +249,48 @@ export namespace FileListResponse {
186249
}
187250
}
188251

252+
export type FileCreateParams = FileCreateParams.Variant0 | FileCreateParams.Variant1;
253+
254+
export declare namespace FileCreateParams {
255+
export interface Variant0 {
256+
/**
257+
* Body param:
258+
*/
259+
type: 'directory';
260+
261+
/**
262+
* Query param: Id of the branch to create the file on. Defaults to main if not
263+
* provided.
264+
*/
265+
branch_id?: string;
266+
267+
/**
268+
* Body param:
269+
*/
270+
content?: null;
271+
}
272+
273+
export interface Variant1 {
274+
/**
275+
* Body param: Project file and val content. Null or an empty string will create an
276+
* empty file. When creating a directory, you can send null, an empty string, or
277+
* omit the content field entirely.
278+
*/
279+
content: string;
280+
281+
/**
282+
* Body param:
283+
*/
284+
type: 'file' | 'interval' | 'http' | 'email' | 'script';
285+
286+
/**
287+
* Query param: Id of the branch to create the file on. Defaults to main if not
288+
* provided.
289+
*/
290+
branch_id?: string;
291+
}
292+
}
293+
189294
export interface FileRetrieveParams {
190295
/**
191296
* Maximum items to return in each paginated response
@@ -266,9 +371,11 @@ Files.FileListResponsesPageCursorURL = FileListResponsesPageCursorURL;
266371

267372
export declare namespace Files {
268373
export {
374+
type FileCreateResponse as FileCreateResponse,
269375
type FileRetrieveResponse as FileRetrieveResponse,
270376
type FileListResponse as FileListResponse,
271377
FileListResponsesPageCursorURL as FileListResponsesPageCursorURL,
378+
type FileCreateParams as FileCreateParams,
272379
type FileRetrieveParams as FileRetrieveParams,
273380
type FileListParams as FileListParams,
274381
type FileContentParams as FileContentParams,

src/resources/projects/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ export {
1212
export {
1313
FileListResponsesPageCursorURL,
1414
Files,
15+
type FileCreateResponse,
1516
type FileRetrieveResponse,
1617
type FileListResponse,
18+
type FileCreateParams,
1719
type FileRetrieveParams,
1820
type FileListParams,
1921
type FileContentParams,

src/resources/projects/projects.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
import * as FilesAPI from './files';
1616
import {
1717
FileContentParams,
18+
FileCreateParams,
19+
FileCreateResponse,
1820
FileListParams,
1921
FileListResponse,
2022
FileListResponsesPageCursorURL,
@@ -251,9 +253,11 @@ export declare namespace Projects {
251253

252254
export {
253255
Files as Files,
256+
type FileCreateResponse as FileCreateResponse,
254257
type FileRetrieveResponse as FileRetrieveResponse,
255258
type FileListResponse as FileListResponse,
256259
FileListResponsesPageCursorURL as FileListResponsesPageCursorURL,
260+
type FileCreateParams as FileCreateParams,
257261
type FileRetrieveParams as FileRetrieveParams,
258262
type FileListParams as FileListParams,
259263
type FileContentParams as FileContentParams,

tests/api-resources/projects/files.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ const client = new ValTown({
99
});
1010

1111
describe('resource files', () => {
12+
test('create: only required params', async () => {
13+
const responsePromise = client.projects.files.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path', {
14+
type: 'directory',
15+
});
16+
const rawResponse = await responsePromise.asResponse();
17+
expect(rawResponse).toBeInstanceOf(Response);
18+
const response = await responsePromise;
19+
expect(response).not.toBeInstanceOf(Response);
20+
const dataAndResponse = await responsePromise.withResponse();
21+
expect(dataAndResponse.data).toBe(response);
22+
expect(dataAndResponse.response).toBe(rawResponse);
23+
});
24+
25+
test('create: required and optional params', async () => {
26+
const response = await client.projects.files.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path', {
27+
type: 'directory',
28+
branch_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
29+
content: null,
30+
});
31+
});
32+
1233
test('retrieve: only required params', async () => {
1334
const responsePromise = client.projects.files.retrieve('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path', {
1435
limit: 1,

0 commit comments

Comments
 (0)