First Commit

This commit is contained in:
SowinskiBraeden committed 2020-11-25 09:10:06 -08:00
commit 601e886c14
2123 files changed
+334815

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
'use strict';
/*!
* ignore
*/
const MongooseMap = require('../types/map');
const SchemaType = require('../schematype');
/*!
* ignore
*/
class Map extends SchemaType {
constructor(key, options) {
super(key, options, 'Map');
this.$isSchemaMap = true;
}
cast(val, doc, init) {
if (val instanceof MongooseMap) {
return val;
}
if (init) {
const map = new MongooseMap({}, this.path, doc, this.$__schemaType);
if (val instanceof global.Map) {
for (const key of val.keys()) {
map.$init(key, map.$__schemaType.cast(val.get(key), doc, true));
}
} else {
for (const key of Object.keys(val)) {
map.$init(key, map.$__schemaType.cast(val[key], doc, true));
}
}
return map;
}
return new MongooseMap(val, this.path, doc, this.$__schemaType);
}
}
module.exports = Map;