TypeScript API / laikacms/storage/web / WebStorageDataSource
Class: WebStorageDataSource
WebStorageDataSource provides low-level operations for interacting with a Web Storage-shaped backing store (localStorage, sessionStorage, or an injected in-memory shim). Web Storage is a flat key-value store, so this implementation simulates a hierarchical file system the same way R2DataSource does for Cloudflare R2:
- Folders are represented by key prefixes.
- Empty folders are represented by
.keepmarker entries. - File extensions are handled transparently and encoded in the physical key.
Every physical key is namespaced as ${namespace}:${logicalKeyWithExtension} so that repositories sharing one Storage under different namespaces never observe each other's keys (or unrelated data already in that Storage) — see listPhysicalEntries, the single point all reads/writes/listings funnel through for the namespace-prefix filter.
Constructors
Constructor
new WebStorageDataSource(
storageProvider,
namespace,
availableExtensions?
): WebStorageDataSource;Parameters
| Parameter | Type | Default value |
|---|---|---|
storageProvider | WebStorageProvider | undefined |
namespace | string | undefined |
availableExtensions | string[] | [] |
Returns
WebStorageDataSource
Methods
createOrUpdate()
createOrUpdate(
key,
content,
extension
): Promise<LaikaResult<{
key: string;
}>>;Parameters
| Parameter | Type |
|---|---|
key | string |
content | string |
extension | string |
Returns
Promise<LaikaResult<{ key: string; }>>
deleteObjects()
deleteObjects(keys): AsyncGenerator<LaikaResult<string>>;Delete objects by their logical key. Directories are not recursively removed (mirrors storage-r2).
Parameters
| Parameter | Type |
|---|---|
keys | readonly string[] |
Returns
AsyncGenerator<LaikaResult<string>>
findExistingObjectExtension()
findExistingObjectExtension(key): Promise<string | null>;Check if an object exists with any of the available extensions. Returns the extension if found.
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Promise<string | null>
getFolderMeta()
getFolderMeta(key): Promise<LaikaResult<{
createdAt: Date;
updatedAt: Date;
}>>;A "folder" has no physical record on its own; its existence is implied by any physical key beginning with ${key}/, or by an explicit .keep marker written by createFolder. Timestamps are synthesized (the flat store keeps none for a synthetic folder).
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Promise<LaikaResult<{ createdAt: Date; updatedAt: Date; }>>
getObjectContents()
getObjectContents(key): Promise<LaikaResult<{
content: string;
extension: string;
key: string;
}>>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Promise<LaikaResult<{ content: string; extension: string; key: string; }>>
getObjectMeta()
getObjectMeta(key): Promise<LaikaResult<{
createdAt: Date;
extension: string;
key: string;
updatedAt: Date;
}>>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Promise<LaikaResult<{ createdAt: Date; extension: string; key: string; updatedAt: Date; }>>
listDirectory()
listDirectory(prefix): Promise<LaikaResult<WebStorageEntry[]>>;List the immediate children of prefix (one level — same delimiter semantics as R2's listDirectory).
Parameters
| Parameter | Type |
|---|---|
prefix | string |
Returns
Promise<LaikaResult<WebStorageEntry[]>>