Skip to content

TypeScript API / laikacms/storage/webdav / WebDavDataSource

Class: WebDavDataSource ​

Talks WebDAV (RFC 4918) over fetch. Owns URL construction, auth headers, multistatus parsing and HTTP-status-to-LaikaError mapping, so the repository can stay a thin orchestration layer.

Keys handed to this datasource are POSIX-style paths relative to the storage root, with no leading slash; the empty string addresses the root collection.

Constructors ​

Constructor ​

ts
new WebDavDataSource(config, availableExtensions?): WebDavDataSource;

Parameters ​

ParameterTypeDefault value
configWebDavConfigundefined
availableExtensionsreadonly string[][]

Returns ​

WebDavDataSource

Methods ​

deleteResource() ​

ts
deleteResource(key): Promise<LaikaResult<void>>;

DELETE a resource (file or collection) addressed by its full key.

Parameters ​

ParameterType
keystring

Returns ​

Promise<LaikaResult<void>>


describe() ​

ts
describe(key): string;

Combine the configured base path with a key — exposed for logging/diagnostics.

Parameters ​

ParameterType
keystring

Returns ​

string


ensureCollection() ​

ts
ensureCollection(dirKey): Promise<LaikaResult<void>>;

Ensure the collection at dirKey and every ancestor exists, issuing MKCOL top-down. A 405/301 on an existing collection is treated as success — MKCOL is not idempotent across servers.

Parameters ​

ParameterType
dirKeystring

Returns ​

Promise<LaikaResult<void>>


listChildren() ​

ts
listChildren(key): Promise<LaikaResult<WebDavResource[]>>;

PROPFIND with Depth: 1 and return the direct children of key, excluding the collection itself. A missing collection surfaces as a NotFoundError.

Parameters ​

ParameterType
keystring

Returns ​

Promise<LaikaResult<WebDavResource[]>>


readFile() ​

ts
readFile(key, extension): Promise<LaikaResult<string>>;

GET the raw body of ${key}.${extension}.

Parameters ​

ParameterType
keystring
extensionstring

Returns ​

Promise<LaikaResult<string>>


resolveExisting() ​

ts
resolveExisting(key): Promise<LaikaResult<
  | {
  extension: string;
  resource: WebDavResource;
}
| null>>;

Probe each registered file extension for key and return the first that exists. Mirrors the filesystem datasource: keys are extension-free at the repository boundary.

Parameters ​

ParameterType
keystring

Returns ​

Promise<LaikaResult< | { extension: string; resource: WebDavResource; } | null>>


statResource() ​

ts
statResource(key): Promise<LaikaResult<WebDavResource | null>>;

PROPFIND a single resource. Resolves to null when the server reports 404/410 so callers can treat "absent" as a value rather than an error.

Parameters ​

ParameterType
keystring

Returns ​

Promise<LaikaResult<WebDavResource | null>>


writeFile() ​

ts
writeFile(
   key, 
   extension, 
   content
): Promise<LaikaResult<void>>;

PUT content to ${key}.${extension}, creating any missing parent collections first.

Parameters ​

ParameterType
keystring
extensionstring
contentstring

Returns ​

Promise<LaikaResult<void>>

Released under the MIT License.