FileStorageV2 class
A file-backed provider for the structured StorageV2 contract.
This is the V2 counterpart to FileStorage. Values are stored in state.json, while
generated storage versions are stored separately in state.versions.json; an eTag property
in an application value is therefore preserved. Reads and mutations return a result for every
requested key and support create-only, replace, and expected-version conditions.
Like FileStorage, this provider is for development, local testing, and single-instance deployments. It does not provide cross-process concurrency or multi-key atomicity.
- Extends
Constructors
| File |
Creates a V2 file storage provider. |
Methods
| delete(string[], Storage |
Deletes items and their versions from the local state files. |
| read<T>(string[]) | Reads items and their stored versions from the local state files. |
| write<T>(Record<string, T>, Storage |
Writes cloned items and generated versions to the local state files. |
Constructor Details
FileStorageV2(string)
Creates a V2 file storage provider.
new FileStorageV2(folder: string)
Parameters
- folder
-
string
The absolute or relative folder where state.json is stored.
Method Details
delete(string[], StorageDeleteOptions)
Deletes items and their versions from the local state files.
function delete(keys: string[], options?: StorageDeleteOptions): Promise<StorageDeleteResults>
Parameters
- keys
-
string[]
The keys to delete. Empty batches are valid.
- options
- StorageDeleteOptions
An optional expected storage version.
Returns
Promise<StorageDeleteResults>
A result for every supplied key.
read<T>(string[])
Reads items and their stored versions from the local state files.
function read<T>(keys: string[]): Promise<StorageReadResults<T>>
Parameters
- keys
-
string[]
The keys to read. Empty batches are valid.
Returns
Promise<StorageReadResults<T>>
A result for every key, with notFound for missing items. Returned values are cloned.
write<T>(Record<string, T>, StorageWriteOptions)
Writes cloned items and generated versions to the local state files.
function write<T>(changes: Record<string, T>, options?: StorageWriteOptions): Promise<StorageWriteResults>
Parameters
- changes
-
Record<string, T>
The values to write, keyed by storage key.
- options
- StorageWriteOptions
Create-only, replace, or expected-version conditions.
Returns
Promise<StorageWriteResults>
A result for every supplied key, including concurrency-condition outcomes.