@alline/core
Version:
Core for Alline.
35 lines • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelDeserializer = exports.ModelSerializer = void 0;
const tapable_1 = require("tapable");
class ModelSerializer {
constructor() {
this.serializeHooks = {
before: new tapable_1.AsyncSeriesWaterfallHook(["data", "ctx"]),
after: new tapable_1.AsyncSeriesHook(["data", "ctx"])
};
}
async serialize(data, ctx) {
const { before, after } = this.serializeHooks;
const newData = await before.promise(data, ctx);
await this.onSerialize(newData, ctx);
await after.promise(data, ctx);
}
}
exports.ModelSerializer = ModelSerializer;
class ModelDeserializer {
constructor() {
this.deserializeHooks = {
before: new tapable_1.AsyncSeriesHook(["ctx"]),
after: new tapable_1.AsyncSeriesWaterfallHook(["data", "ctx"])
};
}
async deserialize(ctx) {
const { before, after } = this.deserializeHooks;
await before.promise(ctx);
const data = await this.onDeserialize(ctx);
return after.promise(data, ctx);
}
}
exports.ModelDeserializer = ModelDeserializer;
//# sourceMappingURL=serialize.js.map