UNPKG

typescript-mysql-model

Version:

{ "version": "1.2.46", "name": "typescript-mysql-model", "description": "", "main": "index.js", "types": "index.d.ts", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url":

38 lines 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Cleaner { constructor(schema) { this.schema = schema; } cleanFromDictionary(item, allowedKeys) { if (!item) { return undefined; } const copy = JSON.parse(JSON.stringify(item)); const itemsKeys = Object.keys(copy); const tKeys = new Set(Object.keys(allowedKeys)); for (const key of itemsKeys) { if (!tKeys.has(key)) { delete copy[key]; } } delete copy.createdAt; return copy; } cleanByArray(item, allowedKeys) { if (!item) { return undefined; } const dictionary = allowedKeys.reduce((obj, key) => { obj[key] = null; return obj; }, {}); return this.cleanFromDictionary(item, dictionary); } cleanByTableName(item, tableName) { const table = this.schema.tables[tableName]; return this.cleanFromDictionary(item, table); } } exports.Cleaner = Cleaner; //# sourceMappingURL=cleaner.js.map