Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (fieldSchema.type) {
let fieldType = fieldSchema.type();
if (fieldType.$schema.collectionName) {
if (value !== null) {
let isArray = Array.isArray(value);
if (!isArray || value.length) {
if ((isArray ? value[0] : value) instanceof ObjectId) {
this[KEY_VALUES].set(name, isArray ? value.slice() : value);
} else {
if (
isArray &&
value.length == 1 &&
!(value[0] instanceof BaseModel) &&
isSingular(name)
) {
value = value[0];
isArray = false;
}
if (!((isArray ? value[0] : value) instanceof BaseModel)) {
value = isArray
? value.map(
(itemData: Object) =>
new fieldType(itemData, db)
)
: new fieldType(value, db);
data[name] = value;
}
this._validateFieldValue(name, fieldSchema, value);
pluralize.isSingular = (word: string) => require('pluralize').isSingular(word)
}
let value = value_ === undefined ? null : value_;
if (fieldSchema.type) {
let fieldType = fieldSchema.type();
if (fieldType.$schema.collectionName) {
if (value !== null) {
let isArray = Array.isArray(value);
if (!isArray || value.length) {
if ((isArray ? value[0] : value) instanceof mongodb_1.ObjectId) {
this[exports.KEY_VALUES].set(name, isArray ? value.slice() : value);
}
else {
if (isArray &&
value.length == 1 &&
!(value[0] instanceof BaseModel) &&
pluralize_1.isSingular(name)) {
value = value[0];
isArray = false;
}
if (!((isArray ? value[0] : value) instanceof BaseModel)) {
value = isArray
? value.map((itemData) => new fieldType(itemData, db))
: new fieldType(value, db);
data[name] = value;
}
this._validateFieldValue(name, fieldSchema, value);
let valuePromise = Promise.resolve(value);
valuePromise[exports.KEY_VALUE] = isArray ? value.slice() : value;
this[exports.KEY_VALUES].set(name, valuePromise);
}
continue;
}