constructor<T>(asset: Constructor<T>)
View sourceAssociates the exporter with an asset constructor.
The constructor is assigned directly to Exporter#asset. No
validation or other initialization is performed.
Class
Abstract contract for converting typed asset values into request bodies.
Use a subclass for one asset constructor. Concrete exporters provide the
conversion for each request-body format they support and use
Exporter#getExtensions to return the exact extension labels that
identify those formats. A conversion can use
TypeRegistry for reflected or nested typed values.
import { Exporter } from '@wimaengine/asset'
class TextAsset {
constructor(value) {
this.value = value
}
}
class TextExporter extends Exporter {
constructor() {
super(TextAsset)
}
async serialize(asset, _typeRegistry) {
return asset.value
}
getExtensions() {
return ['txt']
}
}
const exporter = new TextExporter()constructor<T>(asset: Constructor<T>)Associates the exporter with an asset constructor.
The constructor is assigned directly to Exporter#asset. No
validation or other initialization is performed.
Asset constructor associated with values handled by this exporter.
The constructor is stored as supplied; this class does not validate it.
serialize(_asset: T, _typeRegistry: TypeRegistry): Promise<BodyInit>Converts an asset value into the body used by a save request.
A concrete exporter should resolve a value accepted by BodyInit;
the resolved value is supplied as the request body. Use the
TypeRegistry argument when the output format needs reflected or
nested typed values.
The base implementation always rejects with an Error because it has no
serialization format to produce.
getExtensions(): string[]Returns the extension labels supported by this exporter.
Each returned label is matched literally against the extension extracted from a save path. Omit the leading dot; spelling and case must match exactly, and no normalization is applied. Return one label for each supported output format.
The base implementation always throws an Error because it does not know
which formats the concrete exporter supports. The empty array below is
only an unreachable fallback after the throw.