1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | class Cleaner {
|
4 | constructor(schema) {
|
5 | this.schema = schema;
|
6 | }
|
7 | cleanFromDictionary(item, allowedKeys) {
|
8 | if (!item) {
|
9 | return undefined;
|
10 | }
|
11 | const copy = JSON.parse(JSON.stringify(item));
|
12 | const itemsKeys = Object.keys(copy);
|
13 | const tKeys = new Set(Object.keys(allowedKeys));
|
14 | for (const key of itemsKeys) {
|
15 | if (!tKeys.has(key)) {
|
16 | delete copy[key];
|
17 | }
|
18 | }
|
19 | delete copy.createdAt;
|
20 | return copy;
|
21 | }
|
22 | cleanByArray(item, allowedKeys) {
|
23 | if (!item) {
|
24 | return undefined;
|
25 | }
|
26 | const dictionary = allowedKeys.reduce((obj, key) => {
|
27 | obj[key] = null;
|
28 | return obj;
|
29 | }, {});
|
30 | return this.cleanFromDictionary(item, dictionary);
|
31 | }
|
32 | cleanByTableName(item, tableName) {
|
33 | const table = this.schema.tables[tableName];
|
34 | return this.cleanFromDictionary(item, table);
|
35 | }
|
36 | }
|
37 | exports.Cleaner = Cleaner;
|
38 |
|
\ | No newline at end of file |