API reference

yatta/webdav

WebDAV over any store: methods, locks, PROPFIND, downloads.

7 exported symbols and 24 members, read from src/func/webdav.ts.

Construct

createStorageDavStore

function

Back WebDAV with the Yatta storage engine.

A key-value store has no real folders, so a collection is recorded as a marker file, `<path>/.dav-collection`. The name is reserved: a client cannot create, read, overwrite or list it as an ordinary file.

createStorageDavStore(storage: { upload(key: string, data: Uint8Array, options?: { contentType?: string; }): Promise<unknown>; download(key: string): Promise<{ arrayBuffer(): Promise<ArrayBuffer>; contentType: string; lastModified: Date; }>; head(key: string): Promise<{ size: number; contentType: string; lastModified: Date; }>; delete(key: string): Promise<void>; copy(src: string, dst: string): Promise<unknown>; move(src: string, dst: string): Promise<unknown>; exists(key: string): Promise<boolean>; list(options?: { prefix?: string; }): Promise<Array<{ path: string; size: number; contentType: string; lastModified: Date; }>>; }): DavStore
storage
Anything shaped like `yatta.js/storage`'s engine — the same object, not an adapter around it.

createWebDAVHandler

function

Build the WebDAV handler for a store.

createWebDAVHandler(store: DavStore, options?: WebDAVOptions): (req: Request) => Promise<Response>
store
Where the bytes live. Use `createStorageDavStore(storage)` to back it with the Yatta storage engine, or your own for tests.

Returns A `(req) => Promise<Response>` for a router or `Bun.serve`.

DavError

class

An error with an HTTP status, for a store that needs to say no.

`throw new DavError(403, "reserved name")` reaches the client as that status and message. Any other thrown error is logged and answered 500, so an internal detail never becomes the response body.

class DavError extends Error

1 member

  • statusproperty
    status: number

Types

DavEntry

interface

One path in the tree, with the metadata PROPFIND reports.

interface DavEntry

5 members

  • pathproperty
    path: string
  • isCollectionproperty
    isCollection: boolean
  • sizeproperty
    size: number
  • lastModifiedproperty
    lastModified: Date
  • contentTypeproperty
    contentType?: string

DavFile

interface

A file as the store returns it: the bytes plus what a browser needs.

interface DavFile

3 members

  • bodyproperty
    body: Uint8Array
  • contentTypeproperty
    contentType: string
  • lastModifiedproperty
    lastModified: Date

DavStore

interface

The small surface the handler needs from a backing store.

Paths never start with "/" and the root collection is `""`. Copy and move a whole collection only turn up as a `mkdir` plus per-file calls, except `move` on a single file, so a store that can rename cheaply should — reading a large file into memory to move it is the handler's fallback, not a requirement.

interface DavStore

10 members

  • get
    get(path: string): Promise<DavFile | null>
  • put
    put(path: string, body: Uint8Array, contentType?: string): Promise<void>
  • delete
    delete(path: string): Promise<boolean>
  • exists
    exists(path: string): Promise<boolean>
  • isCollection
    isCollection(path: string): Promise<boolean>
  • list
    list(path: string): Promise<DavEntry[]>
  • mkdir
    mkdir(path: string): Promise<void>
  • copy
    copy(src: string, dst: string): Promise<void>
  • move
    move(src: string, dst: string): Promise<void>
  • stat
    stat(path: string): Promise<DavEntry | null>?

WebDAVOptions

interface

How the handler behaves. Everything is optional; the defaults are a

interface WebDAVOptions

5 members

  • basePathproperty
    basePath?: string
  • defaultLockMsproperty
    defaultLockMs?: number
  • authenticateproperty
    authenticate?: (req: Request) => Promise<boolean | Response> | boolean | Response
  • readOnlyproperty
    readOnly?: boolean
  • maxBodyBytesproperty
    maxBodyBytes?: number
Tip
Most of the types above are inferred. You rarely import AuthConfig or JobPayload — declaring your schema once is enough for the rest to follow. See Typed keys.