UNPKG

breeze-sequelize

Version:
58 lines 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** Maps EntityType names to arrays of EntityInfo */ class SaveMap { constructor(sequelizeSaveHandler) { // make sequelizeSaveHandler non-enumerable so it won't be in Object.keys() Object.defineProperty(this, "sequelizeSaveHandler", { value: sequelizeSaveHandler }); } getEntityType(entityTypeName) { return this.sequelizeSaveHandler.metadataStore.getEntityType(entityTypeName); } getEntityInfosOfType(entityTypeName) { const entityType = this.getEntityType(entityTypeName); // entityType.name is fully qualified. return this[entityType.name] || []; } /** Add an entity to the map */ addEntity(entityTypeName, entity, entityState = "Added") { const entityType = this.getEntityType(entityTypeName); entityTypeName = entityType.name; // fully qualified now. const entityInfo = { entity: entity, entityType: entityType, wasAddedOnServer: true, entityAspect: { entityTypeName: entityTypeName, entityState: entityState } }; const entityInfoList = this[entityTypeName]; if (entityInfoList) { entityInfoList.push(entityInfo); } else { this[entityTypeName] = [entityInfo]; } return entityInfo; } /** Add an error to the entityErrors collection */ addEntityError(entityInfo, errorName, errorMessage, propertyName) { if (!this.entityErrors) { this.entityErrors = []; } const entityType = entityInfo.entityType; const keyValues = entityType.keyProperties.map(kp => entityInfo.entity[kp.nameOnServer]); this.entityErrors.push({ entityTypeName: entityType.name, errorName: errorName, errorMessage: errorMessage, propertyName: propertyName, keyValues: keyValues }); } /** Set the error message to return to the client */ setErrorMessage(errorMessage) { this.errorMessage = errorMessage; } } exports.SaveMap = SaveMap; //# sourceMappingURL=SaveMap.js.map