feat(client): expose fs read in promise client (#34504)

This commit is contained in:
Kit Langton 2026-06-29 19:21:18 -04:00 committed by GitHub
commit ecfa918760
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 227 additions and 63 deletions

View file

@ -87,6 +87,8 @@ import type {
PermissionsGetOutput,
PermissionsReplyInput,
PermissionsReplyOutput,
FilesReadInput,
FilesReadOutput,
FilesListInput,
FilesListOutput,
FilesFindInput,
@ -155,6 +157,7 @@ interface RequestDescriptor {
readonly successStatus: number
readonly declaredStatuses: ReadonlyArray<number>
readonly empty: boolean
readonly binary?: true
}
export function make(options: ClientOptions) {
@ -200,6 +203,7 @@ export function make(options: ClientOptions) {
const request = async <A>(descriptor: RequestDescriptor, requestOptions?: RequestOptions): Promise<A> => {
const response = await execute(descriptor, requestOptions)
if (response.status !== descriptor.successStatus) return responseError(response, descriptor)
if (descriptor.binary) return new Uint8Array(await response.arrayBuffer()) as A
if (descriptor.empty) {
try {
await response.body?.cancel()
@ -840,6 +844,19 @@ export function make(options: ClientOptions) {
),
},
files: {
read: (input: FilesReadInput, requestOptions?: RequestOptions) =>
request<FilesReadOutput>(
{
method: "GET",
path: `/api/fs/read/${encodePath(input.path)}`,
query: { location: input["location"] },
successStatus: 200,
declaredStatuses: [401, 400],
empty: false,
binary: true,
},
requestOptions,
),
list: (input?: FilesListInput, requestOptions?: RequestOptions) =>
request<FilesListOutput>(
{
@ -1143,6 +1160,10 @@ export function make(options: ClientOptions) {
}
}
function encodePath(value: string): string {
return value.split("/").map(encodeURIComponent).join("/")
}
function appendQuery(params: URLSearchParams, key: string, value: unknown): void {
if (value === undefined || value === null) return
if (Array.isArray(value)) {

View file

@ -2572,6 +2572,15 @@ export type PermissionsReplyInput = {
export type PermissionsReplyOutput = void
export type FilesReadInput = {
readonly location?: {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
}["location"]
readonly path: string
}
export type FilesReadOutput = globalThis.Uint8Array
export type FilesListInput = {
readonly location?: {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined