UNPKG

hydrate-mongodb

Version:
42 lines (41 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var mappingModel_1 = require("./mappingModel"); var persistenceError_1 = require("../persistenceError"); var MappingRegistry = (function () { function MappingRegistry() { this._mappings = new Map(); } MappingRegistry.prototype.addMappings = function (mappings) { var _this = this; mappings.forEach(function (x) { return _this.addMapping(x); }); }; MappingRegistry.prototype.addMapping = function (mapping) { if (!mapping.classConstructor) { throw new persistenceError_1.PersistenceError("Class mapping is missing classConstructor."); } if (this._mappings.has(mapping.classConstructor)) { throw new persistenceError_1.PersistenceError("Mapping '" + mapping.classConstructor.name + "' has already been registered."); } this._mappings.set(mapping.classConstructor, mapping); }; MappingRegistry.prototype.getEntityMappings = function () { var entities = []; this._mappings.forEach(function (mapping) { if ((mapping.flags & 1024) != 0) { entities.push(mapping); } }); return entities; }; MappingRegistry.prototype.getMappingForObject = function (obj) { return this.getMappingForConstructor(obj.constructor); }; MappingRegistry.prototype.getMappingForConstructor = function (ctr) { if (ctr) { return this._mappings.get(ctr); } }; return MappingRegistry; }()); exports.MappingRegistry = MappingRegistry;