123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- 'use strict';
- const SchemaType = require('../schematype');
- const symbols = require('./symbols');
- const isObject = require('../helpers/isObject');
- const utils = require('../utils');
- function Mixed(path, options) {
- if (options && options.default) {
- const def = options.default;
- if (Array.isArray(def) && def.length === 0) {
-
- options.default = Array;
- } else if (!options.shared && isObject(def) && Object.keys(def).length === 0) {
-
- options.default = function() {
- return {};
- };
- }
- }
- SchemaType.call(this, path, options, 'Mixed');
- this[symbols.schemaMixedSymbol] = true;
- }
- Mixed.schemaName = 'Mixed';
- Mixed.defaultOptions = {};
- Mixed.prototype = Object.create(SchemaType.prototype);
- Mixed.prototype.constructor = Mixed;
- Mixed.get = SchemaType.get;
- Mixed.set = SchemaType.set;
- Mixed.prototype.cast = function(val) {
- if (val instanceof Error) {
- return utils.errorToPOJO(val);
- }
- return val;
- };
- Mixed.prototype.castForQuery = function($cond, val) {
- if (arguments.length === 2) {
- return val;
- }
- return $cond;
- };
- module.exports = Mixed;
|