@decaf-ts/decorator-validation
Version:
simple decorator based validation engine
36 lines • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Serialization = void 0;
const constants_js_1 = require("./constants.cjs");
class Serialization {
static { this.current = constants_js_1.DefaultSerializationMethod; }
constructor() { }
static get(key) {
if (key in this.cache)
return this.cache[key];
throw new Error(`No serialization method registered under ${key}`);
}
static register(key, func, setDefault = false) {
if (key in this.cache)
throw new Error(`Serialization method ${key} already registered`);
this.cache[key] = new func();
if (setDefault)
this.current = key;
}
static serialize(obj, method, ...args) {
if (!method)
return this.get(this.current).serialize(obj, ...args);
return this.get(method).serialize(obj, ...args);
}
static deserialize(obj, method, ...args) {
if (!method)
return this.get(this.current).deserialize(obj, ...args);
return this.get(method).deserialize(obj, ...args);
}
static setDefault(method) {
this.current = this.get(method);
}
}
exports.Serialization = Serialization;
//# sourceMappingURL=serialization.js.map
//# sourceMappingURL=serialization.cjs.map