@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
44 lines • 1.42 kB
JavaScript
/**
* @module Serde
*/
import { DeserializationSerdeError, SerializationSerdeError, } from "../../../../serde/contracts/_module-exports.js";
import { SuperJSON } from "superjson-cjs";
/**
*
* IMPORT_PATH: `"@daiso-tech/core/serde/adapters"`
* @group Adapters
*/
export class SuperJsonSerdeAdapter {
superJson = new SuperJSON();
registerCustom(transformer) {
this.superJson.registerCustom({
isApplicable(value) {
return transformer.isApplicable(value);
},
serialize(deserializedValue) {
return transformer.serialize(deserializedValue);
},
deserialize(serializedValue) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return transformer.deserialize(serializedValue);
},
}, transformer.name);
}
serialize(value) {
try {
return this.superJson.stringify(value);
}
catch (error) {
throw new SerializationSerdeError(`Serialization error "${String(error)}" occured`, error);
}
}
deserialize(value) {
try {
return this.superJson.parse(value);
}
catch (error) {
throw new DeserializationSerdeError(`Deserialization error "${String(error)}" occured`, error);
}
}
}
//# sourceMappingURL=super-json-serde-adapter.js.map