Skip to content

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 .keep marker 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 ​

ts
new WebStorageDataSource(
   storageProvider, 
   namespace, 
   availableExtensions?
): WebStorageDataSource;

Parameters ​

ParameterTypeDefault value
storageProviderWebStorageProviderundefined
namespacestringundefined
availableExtensionsstring[][]

Returns ​

WebStorageDataSource

Methods ​

createOrUpdate() ​

ts
createOrUpdate(
   key, 
   content, 
   extension
): Promise<LaikaResult<{
  key: string;
}>>;

Parameters ​

ParameterType
keystring
contentstring
extensionstring

Returns ​

Promise<LaikaResult<{ key: string; }>>


deleteObjects() ​

ts
deleteObjects(keys): AsyncGenerator<LaikaResult<string>>;

Delete objects by their logical key. Directories are not recursively removed (mirrors storage-r2).

Parameters ​

ParameterType
keysreadonly string[]

Returns ​

AsyncGenerator<LaikaResult<string>>


findExistingObjectExtension() ​

ts
findExistingObjectExtension(key): Promise<string | null>;

Check if an object exists with any of the available extensions. Returns the extension if found.

Parameters ​

ParameterType
keystring

Returns ​

Promise<string | null>


getFolderMeta() ​

ts
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 ​

ParameterType
keystring

Returns ​

Promise<LaikaResult<{ createdAt: Date; updatedAt: Date; }>>


getObjectContents() ​

ts
getObjectContents(key): Promise<LaikaResult<{
  content: string;
  extension: string;
  key: string;
}>>;

Parameters ​

ParameterType
keystring

Returns ​

Promise<LaikaResult<{ content: string; extension: string; key: string; }>>


getObjectMeta() ​

ts
getObjectMeta(key): Promise<LaikaResult<{
  createdAt: Date;
  extension: string;
  key: string;
  updatedAt: Date;
}>>;

Parameters ​

ParameterType
keystring

Returns ​

Promise<LaikaResult<{ createdAt: Date; extension: string; key: string; updatedAt: Date; }>>


listDirectory() ​

ts
listDirectory(prefix): Promise<LaikaResult<WebStorageEntry[]>>;

List the immediate children of prefix (one level — same delimiter semantics as R2's listDirectory).

Parameters ​

ParameterType
prefixstring

Returns ​

Promise<LaikaResult<WebStorageEntry[]>>

Released under the MIT License.