UNPKG

burdy

Version:

Open Source Headless Platform

29 lines (28 loc) 948 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const typeorm_1 = require("typeorm"); const AutoJson = () => (target, propertyKey) => { const basePropertyName = `__autoJson__${propertyKey}`; const serializeProperty = `${basePropertyName}__serialize`; const deserializeProperty = `${basePropertyName}__deserialize`; target[serializeProperty] = function () { try { this[propertyKey] = JSON.stringify(this[propertyKey]); } catch (e) { // } }; target[deserializeProperty] = function () { try { this[propertyKey] = JSON.parse(this[propertyKey]); } catch (e) { // } }; (0, typeorm_1.BeforeInsert)()(target, serializeProperty); (0, typeorm_1.BeforeUpdate)()(target, serializeProperty); (0, typeorm_1.AfterLoad)()(target, deserializeProperty); }; exports.default = AutoJson;