An implementation of interface HandlerBuilder
that provides default versions of the known
value storage handlers.
DefaultHandlerBuilder(fileWriter?: FileWriter,directoryCreator?: DirectoryCreator,)
arrayToDirectory(options: Readonly<ArrayToDirectoryHandlerOptions>): FluentHandler
Create a new storage handler for arrays of objects, writing them to a directory -- this handler writes array contents to directories in the file system, delegating to other handlers for the actual storage of the object's properties.
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.
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
.
Note: In the case of sparse arrays, only the items with values will be written out.
The handlers 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 recursively store that value, too. Remaining
non-object values cause an error to be raised or are either ignored, depending on the value of the
ValueStorageHandlerOptions.strict
option.
binaryFile(options?: Readonly<FileValueHandlerOptions>): FluentHandler
Create a new value storage handler for (opaque) binary files, using the builder's file writer.
The handler can store Uint8Array
, ArrayBuffer
and ArrayBufferView
instances.
No other types are handled.
customFile(options: Readonly<CustomFileValueHandlerOptions>): FluentHandler
Create a new value storage handler for custom text files, using the builder's file writer and a caller-provided serializer function.
jsonFile(options?: Readonly<JsonFileValueHandlerOptions>): FluentHandler
Create a new value storage handler for JSON files, using the builder's file writer.
objectToDirectory(options: Readonly<ObjectToDirectoryHandlerOptions>): FluentHandler
Create a new directory object storage handler -- this handler writes object contents to directories in the file system, delegating to other handlers for the actual storage of the object's properties.
Directory value storage handlers only respond to canStoreValue
when the value is an object.
The handlers 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 recursively store that value, too. Remaining
non-object values cause an error to be raised or are either ignored, depending on the value of the
ValueStorageHandlerOptions.strict
option.
textFile(options?: Readonly<FileValueHandlerOptions>): FluentHandler
Create a new value storage handler for plain text files, using the builder's file writer.