UNPKG

octonom

Version:

Object Document Mapper for any database

44 lines 1.86 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const model_1 = require("../model"); const schema_1 = require("./schema"); class ModelSchema { constructor(options) { this.options = options; } create(value, sanitizeOptions = {}) { if (value === undefined && !this.options.required) { return undefined; } const modelInstance = new this.options.model(value || {}, sanitizeOptions); const instance = modelInstance[model_1.getShadowInstance](); return instance; } populate(instance, populateReference) { return __awaiter(this, void 0, void 0, function* () { if (typeof populateReference !== 'object') { throw new Error('populateReference must be an object.'); } return instance.value.populate(populateReference); }); } toObject(instance, options) { return instance.value.toObject(); } validate(instance) { return __awaiter(this, void 0, void 0, function* () { yield instance.value.validate(); yield schema_1.validate(this.options, instance); }); } } exports.ModelSchema = ModelSchema; //# sourceMappingURL=model.js.map