UNPKG

nextpay-querystring

Version:

Thư viện QueryString của NextPay - Chuyển đổi QueryString thành điều kiện select cho MongoDB và MySQL với kiểm soát bảo mật

34 lines 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FieldDescriptionContainer = void 0; /* eslint-disable max-classes-per-file */ const exceptions_1 = require("../utils/exceptions"); class FieldDescriptionContainer { constructor(...fieldDescriptions) { this.rules = new Map(); this.fieldCounter = new Map(); fieldDescriptions.forEach(fd => { this.rules.set(fd.field, fd); this.fieldCounter.set(fd.field, 0); }); } getFieldDescription(variable) { const fieldName = variable.lexeme.slice(1, variable.lexeme.length - 1); if (!this.rules.has(fieldName)) { throw (0, exceptions_1.fieldNotExistedException)(fieldName); } return this.rules.get(fieldName); } incOccurrence(...variables) { variables.forEach(v => { const fieldName = v.lexeme.slice(1, v.lexeme.length - 1); if (!this.fieldCounter.has(fieldName)) { throw (0, exceptions_1.fieldNotExistedException)(fieldName); } const value = this.fieldCounter.get(fieldName) || 0; this.fieldCounter.set(fieldName, value + 1); }); } } exports.FieldDescriptionContainer = FieldDescriptionContainer; //# sourceMappingURL=fieldDescription.js.map