Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
utils.forOwn(query, (config, keyword) => {
if (reserved.indexOf(keyword) === -1) {
if (utils.isObject(config)) {
query.where[keyword] = config;
} else {
query.where[keyword] = {
'==': config
};
}
delete query[keyword];
}
});
loadHasOne (mapper, def, records, __opts) {
if (utils.isObject(records) && !utils.isArray(records)) {
return Adapter.prototype.loadHasOne.call(this, mapper, def, records, __opts);
}
throw new Error('findAll with hasOne not supported!');
},
utils.forOwn(query, (config, keyword) => {
if (reserved.indexOf(keyword) === -1) {
if (utils.isObject(config)) {
query.where[keyword] = config
} else {
query.where[keyword] = {
'==': config
}
}
delete query[keyword]
}
})
val.forEach(function (v) {
if (toString.call(v) === '[object Date]') {
v = v.toISOString()
} else if (utils.isObject(v)) {
v = utils.toJson(v)
}
parts.push(`${encode(key)}=${encode(v)}`)
})
})
for (let id in itemsIndexed[type]) {
let item:any = itemsIndexed[type][id];
item.attributes[resource.idAttribute] = id;
if (!item.relationships || !Object.keys(item.relationships)) continue;
for (let relationField in (item.relationships || {})) {
let relation:any = resource.relationByField[relationField]
if (!relation || !item.relationships[relationField] || !item.relationships[relationField].data) {
continue;
}
if (relation.type === 'belongsTo' || relation.type === 'hasOne') {
let link:any = item.relationships[relationField].data
if (!utils.isObject(link)) {
this.warn('Wrong relation somewhere, object expected', relation);
continue;
}
if (itemsIndexed[link.type] && itemsIndexed[link.type][link.id]) {
let itemLinked:any = itemsIndexed[link.type][link.id];
item.attributes[relation.localField] = itemLinked.attributes;
}
} else if (relation.type === 'hasMany') {
let links:any = item.relationships[relationField].data
if (!utils.isArray(links)) {
this.warn('Wrong relation somewhere, array expected');
continue;
}
item.attributes[relation.localField] = [];
utils.forOwn(where, (clause, field) => {
if (!utils.isObject(clause)) {
clause = {
'==': clause
}
}
utils.forOwn(clause, (expr, op) => {
fields.push(field)
ops.push(op)
predicates.push(expr)
})
})
return {
utils.forOwn(query.where, function (criteria, field) {
if (!utils.isObject(criteria)) {
query.where[field] = {
'==': criteria
}
}
utils.forOwn(criteria, function (v, op) {
if (op === '==' || op === '===' || op === 'contains') {
mongoQuery[field] = v
} else if (op === '!=' || op === '!==' || op === 'notContains') {
mongoQuery[field] = mongoQuery[field] || {}
mongoQuery[field].$ne = v
} else if (op === '>') {
mongoQuery[field] = mongoQuery[field] || {}
mongoQuery[field].$gt = v
} else if (op === '>=') {
mongoQuery[field] = mongoQuery[field] || {}
mongoQuery[field].$gte = v
for (let id in itemsIndexed[type]) {
let item:any = itemsIndexed[type][id];
item.attributes[resource.idAttribute] = id;
if (!item.relationships || !Object.keys(item.relationships)) continue;
for (let relationField in (item.relationships || {})) {
let relation:any = resource.relationByField[relationField]
if (!relation || !item.relationships[relationField] || !item.relationships[relationField].data) {
continue;
}
if (relation.type === 'belongsTo' || relation.type === 'hasOne') {
let link:any = item.relationships[relationField].data
if (!utils.isObject(link)) {
this.warn(WARNING.WRONG_RELATION_OBJECT_EXPECTED, relation);
continue;
}
if (itemsIndexed[link.type] && itemsIndexed[link.type][link.id]) {
let itemLinked:any = itemsIndexed[link.type][link.id];
item.attributes[relation.localField] = itemLinked.attributes;
}
} else if (relation.type === 'hasMany') {
let links:any = item.relationships[relationField].data
if (!utils.isArray(links)) {
this.warn(WARNING.WRONG_RELATION_ARRAY_EXPECTED);
continue;
}
item.attributes[relation.localField] = [];
utils.forOwn(query, function (config, keyword) {
if (reserved.indexOf(keyword) === -1) {
if (utils.isObject(config)) {
query.where[keyword] = config
} else {
query.where[keyword] = {
'==': config
}
}
delete query[keyword]
}
})
utils.forOwn(query, (config, keyword) => {
if (reserved.indexOf(keyword) === -1) {
if (utils.isObject(config)) {
query.where[keyword] = config
} else {
query.where[keyword] = {
'==': config
}
}
delete query[keyword]
}
})