UNPKG

hydrate-mongodb

Version:
52 lines (51 loc) 2.15 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var mappingBase_1 = require("./mappingBase"); var mappingModel_1 = require("./mappingModel"); var ConverterMapping = (function (_super) { __extends(ConverterMapping, _super); function ConverterMapping(converter) { var _this = _super.call(this, 8192) || this; _this.converter = converter; return _this; } ConverterMapping.prototype.read = function (context, value) { if (value == null) return null; var result = this.converter.convertToObjectProperty(value); if (result === undefined) { context.addError("Unable to convert '" + value + "' to object property."); } return result; }; ConverterMapping.prototype.write = function (context, value) { if (value == null) return null; var result = this.converter.convertToDocumentField(value); if (result === undefined) { context.addError("Unable to convert '" + value + "' to document field."); } return result; }; ConverterMapping.prototype.areEqual = function (documentValue1, documentValue2) { if (documentValue1 === documentValue2) return true; if (documentValue1 === null || documentValue2 === null) return false; if (documentValue1 !== documentValue1 && documentValue2 !== documentValue2) return true; return this.converter.areEqual(documentValue1, documentValue2); }; return ConverterMapping; }(mappingBase_1.MappingBase)); exports.ConverterMapping = ConverterMapping;