A fluent builder interface for creating value storage handlers handlers.
textFile(options?: Readonly<FileValueHandlerOptions>): FluentHandler
Create a new text file value storage handler. This handler stores strings as plain text files.
binaryFile(options?: Readonly<FileValueHandlerOptions>): FluentHandler
Create a new binary file value storage handler. The handler can store Uint8Array
, ArrayBuffer
and
ArrayBufferView
values. No other value types are handled.
jsonFile(options?: Readonly<JsonFileValueHandlerOptions>): FluentHandler
Create a new JSON file value storage handler. This handler serializes values to JSON and writes them to files.
The JSON defaults to a prettified format with line breaks and indentation. Use the
JsonFileValueHandlerOptions.compact
option to use a compact JSON format, instead.
customFile(options: Readonly<CustomFileValueHandlerOptions>): FluentHandler
Create a storage handler that serializes values using a provided serializer function and writes the resulting string to a file.
arrayToDirectory(options: Readonly<ArrayToDirectoryHandlerOptions>): FluentHandler
Create a storage handler that stores arrays of objects as directories, where the name of each entry in the directory is derived from the contents of the corresponding object. The provided handlers are used to store the items.
Array directory value storage handlers only respond to canStoreValue
when the value is an array.
The intent is to write out a directory where the array contents are stored as directories, each representing an
object in the array. The name of each directory is taken from a property in the object. The
keyProperty
parameter determines which property is used
to name directory entries.
If the array items are found not to be objects or not to contain the key property, the handler's storeValue
method will reject with a TypeError
.
The handlers in the options
parameter are evaluated in order when processing each property in the object to
store. If a handler's canStoreValue
method returns true
for a property, it will be used to store the value.
If no handler can store an object-valued property, the directory object storage handler will serve as the fallback,
recursively storing that value. Remaining non-object values cause an error to be raised or are either ignored,
depending on the value of the ValueStorageHandlerOptions.strict
option.
objectToDirectory(options: Readonly<ObjectToDirectoryHandlerOptions>): FluentHandler
Create a storage handler that stores objects as directories. Each directory entry corresponds to a property in the value object. The provided handlers are used to store the items.
Directory value storage handlers only respond to canStoreValue
when the value is an object.
The handlers in the options
parameter are evaluated in order when processing each property in the object to
store. If a handler's canStoreValue
method returns true
for a property, it will be used to store the value.
If no handler can store an object-valued property, the directory object storage handler will serve as the fallback,
recursively storing that value. Remaining non-object values cause an error to be raised or are either ignored,
depending on the value of the ValueStorageHandlerOptions.strict
option.