"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lik_1 = require("lik"); /** * saveable - saveable decorator to be used on class properties */ function svDb() { return (target, key) => { console.log('called sva'); if (!target.saveableProperties) { target.saveableProperties = []; } target.saveableProperties.push(key); }; } exports.svDb = svDb; class DbDoc { /** * class constructor */ constructor() { this.name = this.constructor['name']; this.collection = this.constructor['dbCollection']; } /** * saves this instance but not any connected items * may lead to data inconsistencies, but is faster */ save() { let saveableObject = {}; // is not exposed to outside, so any is ok here for (let propertyNameString of this.saveableProperties) { saveableObject[propertyNameString] = this[propertyNameString]; } switch (this.creationType) { case 'db': this.collection; // TODO implement collection.update() break; case 'new': this.collection.insertOne(saveableObject); } } /** * also store any referenced objects to DB * better for data consistency */ saveDeep(savedMapArg = null) { if (!savedMapArg) { savedMapArg = new lik_1.Objectmap(); } savedMapArg.add(this); this.save(); for (let propertyKey in this) { let property = this[propertyKey]; if (property instanceof DbDoc && !savedMapArg.checkForObject(property)) { property.saveDeep(savedMapArg); } } } } exports.DbDoc = DbDoc; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBLDZCQUErQjtBQU8vQjs7R0FFRztBQUNIO0lBQ0UsTUFBTSxDQUFDLENBQUMsTUFBa0IsRUFBRSxHQUFXLEVBQUUsRUFBRTtRQUN6QyxPQUFPLENBQUMsR0FBRyxDQUFDLFlBQVksQ0FBQyxDQUFBO1FBQ3pCLEVBQUUsQ0FBQyxDQUFDLENBQUMsTUFBTSxDQUFDLGtCQUFrQixDQUFDLENBQUMsQ0FBQztZQUFDLE1BQU0sQ0FBQyxrQkFBa0IsR0FBRyxFQUFFLENBQUE7UUFBQyxDQUFDO1FBQ2xFLE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