Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.32.0"
".": "0.33.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 37
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/val-town%2Fval-town-d84dfa83575ab69d557d177944a1fa6146ad9fdd6fc555f6bb352a48f6a1daa0.yml
configured_endpoints: 38
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/val-town%2Fval-town-fdb8597c76fe77a92ca60e29d54dc0cc907861b822a699ed026232f758d5eaee.yml
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.33.0 (2025-03-05)

Full Changelog: [v0.32.0...v0.33.0](https://github.com/val-town/sdk/compare/v0.32.0...v0.33.0)

### Features

* **api:** api update ([#516](https://github.com/val-town/sdk/issues/516)) ([dcb4323](https://github.com/val-town/sdk/commit/dcb43232442ca0235309808436ef038c1b0a5f23))
* **api:** api update ([#518](https://github.com/val-town/sdk/issues/518)) ([b51b467](https://github.com/val-town/sdk/commit/b51b4670a45e3baec2b10154dd7605e1be7268e2))

## 0.32.0 (2025-03-03)

Full Changelog: [v0.31.0...v0.32.0](https://github.com/val-town/sdk/compare/v0.31.0...v0.32.0)
Expand Down
2 changes: 2 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ Methods:

Types:

- <code><a href="./src/resources/projects/files.ts">FileCreateResponse</a></code>
- <code><a href="./src/resources/projects/files.ts">FileRetrieveResponse</a></code>
- <code><a href="./src/resources/projects/files.ts">FileListResponse</a></code>

Methods:

- <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>
- <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>
- <code title="get /v1/projects/{project_id}/files">client.projects.files.<a href="./src/resources/projects/files.ts">list</a>(projectId, { ...params }) -> FileListResponsesPageCursorURL</code>
- <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>
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@valtown/sdk",
"version": "0.32.0",
"version": "0.33.0",
"exports": "./index.ts",
"publish": {
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@valtown/sdk",
"version": "0.32.0",
"version": "0.33.0",
"description": "The official TypeScript library for the Val Town API",
"author": "Val Town <support@val.town>",
"types": "dist/index.d.ts",
Expand Down
107 changes: 107 additions & 0 deletions src/resources/projects/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ import { PageCursorURL, type PageCursorURLParams } from '../../pagination';
import { type Response } from '../../_shims/index';

export class Files extends APIResource {
/**
* [BETA] Create a new file, project val or directory
*/
create(
projectId: string,
path: string,
params: FileCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<FileCreateResponse> {
const { branch_id, ...body } = params;
return this._client.post(`/v1/projects/${projectId}/files/${path}`, {
query: { branch_id },
body,
...options,
});
}

/**
* Get metadata for files and directories in a project at the specified path
*/
Expand Down Expand Up @@ -80,6 +97,52 @@ export class Files extends APIResource {

export class FileListResponsesPageCursorURL extends PageCursorURL<FileListResponse> {}

/**
* A File or Directory's Metadata
*/
export interface FileCreateResponse {
/**
* The id of the resource
*/
id: string;

links: FileCreateResponse.Links;

name: string;

path: string;

type: 'directory' | 'file' | 'interval' | 'http' | 'email' | 'script';

updatedAt: string;

version: number;
}

export namespace FileCreateResponse {
export interface Links {
/**
* The URL of this resource on Val Town
*/
html: string;

/**
* The URL of this resource's source code as a module
*/
module: string;

/**
* The URL of this resource on this API
*/
self: string;

/**
* This resource's web endpoint, where it serves a website or API
*/
endpoint?: string;
}
}

/**
* A paginated result set
*/
Expand Down Expand Up @@ -186,6 +249,48 @@ export namespace FileListResponse {
}
}

export type FileCreateParams = FileCreateParams.Variant0 | FileCreateParams.Variant1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stainless got this type union right!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmcw wow cool, go stainless!!


export declare namespace FileCreateParams {
export interface Variant0 {
/**
* Body param:
*/
type: 'directory';

/**
* Query param: Id of the branch to create the file on. Defaults to main if not
* provided.
*/
branch_id?: string;

/**
* Body param:
*/
content?: null;
}

export interface Variant1 {
/**
* Body param: Project file and val content. Null or an empty string will create an
* empty file. When creating a directory, you can send null, an empty string, or
* omit the content field entirely.
*/
content: string;

/**
* Body param:
*/
type: 'file' | 'interval' | 'http' | 'email' | 'script';

/**
* Query param: Id of the branch to create the file on. Defaults to main if not
* provided.
*/
branch_id?: string;
}
}

export interface FileRetrieveParams {
/**
* Maximum items to return in each paginated response
Expand Down Expand Up @@ -266,9 +371,11 @@ Files.FileListResponsesPageCursorURL = FileListResponsesPageCursorURL;

export declare namespace Files {
export {
type FileCreateResponse as FileCreateResponse,
type FileRetrieveResponse as FileRetrieveResponse,
type FileListResponse as FileListResponse,
FileListResponsesPageCursorURL as FileListResponsesPageCursorURL,
type FileCreateParams as FileCreateParams,
type FileRetrieveParams as FileRetrieveParams,
type FileListParams as FileListParams,
type FileContentParams as FileContentParams,
Expand Down
2 changes: 2 additions & 0 deletions src/resources/projects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export {
export {
FileListResponsesPageCursorURL,
Files,
type FileCreateResponse,
type FileRetrieveResponse,
type FileListResponse,
type FileCreateParams,
type FileRetrieveParams,
type FileListParams,
type FileContentParams,
Expand Down
4 changes: 4 additions & 0 deletions src/resources/projects/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
import * as FilesAPI from './files';
import {
FileContentParams,
FileCreateParams,
FileCreateResponse,
FileListParams,
FileListResponse,
FileListResponsesPageCursorURL,
Expand Down Expand Up @@ -251,9 +253,11 @@ export declare namespace Projects {

export {
Files as Files,
type FileCreateResponse as FileCreateResponse,
type FileRetrieveResponse as FileRetrieveResponse,
type FileListResponse as FileListResponse,
FileListResponsesPageCursorURL as FileListResponsesPageCursorURL,
type FileCreateParams as FileCreateParams,
type FileRetrieveParams as FileRetrieveParams,
type FileListParams as FileListParams,
type FileContentParams as FileContentParams,
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '0.32.0'; // x-release-please-version
export const VERSION = '0.33.0'; // x-release-please-version
27 changes: 24 additions & 3 deletions tests/api-resources/projects/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ const client = new ValTown({
});

describe('resource files', () => {
test('create: only required params', async () => {
const responsePromise = client.projects.files.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path', {
type: 'directory',
});
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('create: required and optional params', async () => {
const response = await client.projects.files.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path', {
type: 'directory',
branch_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
content: null,
});
});

test('retrieve: only required params', async () => {
const responsePromise = client.projects.files.retrieve('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path', {
limit: 1,
Expand All @@ -27,7 +48,7 @@ describe('resource files', () => {
const response = await client.projects.files.retrieve('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path', {
limit: 1,
offset: 0,
branch_id: 'branch_id',
branch_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
version: 0,
});
});
Expand All @@ -50,7 +71,7 @@ describe('resource files', () => {
const response = await client.projects.files.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
limit: 1,
offset: 0,
branch_id: 'branch_id',
branch_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
recursive: true,
version: 0,
});
Expand All @@ -72,7 +93,7 @@ describe('resource files', () => {
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
'path',
{
branch_id: 'branch_id',
branch_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
version: 0,
'Cache-Control': 'Cache-Control',
'If-Match': 'If-Match',
Expand Down