@oridune/epic-odm
Advanced tools
Comparing version 1.1.8 to 1.1.9
{ | ||
"name": "@oridune/epic-odm", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"description": "Install 1 ODM and code once with any database driver.", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -56,49 +56,54 @@ "use strict"; | ||
let Stages = []; | ||
Object.values(ModelOptions.relations).map((relation) => { | ||
// Get Model Options | ||
const RelationModelOptions = (0, model_1.getModelOptions)(relation.reference()); | ||
const FieldsListItem = fieldsList === null || fieldsList === void 0 ? void 0 : fieldsList[relation.name]; | ||
const FieldAttributes = fieldAttributes === null || fieldAttributes === void 0 ? void 0 : fieldAttributes[relation.name]; | ||
Stages = [ | ||
...Stages, | ||
// Reference Stage | ||
...(typeof FieldsListItem === "object" | ||
? [ | ||
{ | ||
$lookup: { | ||
from: RelationModelOptions.getResolvedName(), | ||
localField: relation.name, | ||
foreignField: "_id", | ||
as: relation.name, | ||
pipeline: CreateReferenceStages(relation.reference(), FieldsListItem, FieldAttributes || {}), | ||
let SortingStage = fieldAttributes.sort | ||
? [ | ||
{ | ||
$sort: (fieldAttributes.sort instanceof Array | ||
? fieldAttributes.sort | ||
: typeof fieldAttributes.sort === "string" | ||
? [fieldAttributes.sort] | ||
: []).reduce((fields, field) => (Object.assign(Object.assign({}, fields), { [field.replace(/^-/, "")]: /^-/.test(field) ? -1 : 1 })), {}), | ||
}, | ||
] | ||
: []; | ||
const Relations = Object.values(ModelOptions.relations); | ||
if (!Relations.length) | ||
Stages = SortingStage; | ||
else if (Relations.length) | ||
Relations.map((relation) => { | ||
// Get Model Options | ||
const RelationModelOptions = (0, model_1.getModelOptions)(relation.reference()); | ||
const FieldsListItem = fieldsList === null || fieldsList === void 0 ? void 0 : fieldsList[relation.name]; | ||
const FieldAttributes = fieldAttributes === null || fieldAttributes === void 0 ? void 0 : fieldAttributes[relation.name]; | ||
Stages = [ | ||
...Stages, | ||
// Reference Stage | ||
...(typeof FieldsListItem === "object" | ||
? [ | ||
{ | ||
$lookup: { | ||
from: RelationModelOptions.getResolvedName(), | ||
localField: relation.name, | ||
foreignField: "_id", | ||
as: relation.name, | ||
pipeline: CreateReferenceStages(relation.reference(), FieldsListItem, FieldAttributes || {}), | ||
}, | ||
}, | ||
}, | ||
] | ||
: []), | ||
// Sorting Stage | ||
...(fieldAttributes.sort | ||
? [ | ||
{ | ||
$sort: (fieldAttributes.sort instanceof Array | ||
? fieldAttributes.sort | ||
: typeof fieldAttributes.sort === "string" | ||
? [fieldAttributes.sort] | ||
: []).reduce((fields, field) => (Object.assign(Object.assign({}, fields), { [field.replace(/^-/, "")]: /^-/.test(field) ? -1 : 1 })), {}), | ||
}, | ||
] | ||
: []), | ||
// Unwind Stage | ||
...(typeof FieldsListItem === "object" && | ||
["OneToOne", "ManyToOne"].includes(relation.type) | ||
? [ | ||
{ | ||
$unwind: { | ||
path: `$${relation.name}`, | ||
preserveNullAndEmptyArrays: true, | ||
] | ||
: []), | ||
// Sorting Stage | ||
...SortingStage, | ||
// Unwind Stage | ||
...(typeof FieldsListItem === "object" && | ||
["OneToOne", "ManyToOne"].includes(relation.type) | ||
? [ | ||
{ | ||
$unwind: { | ||
path: `$${relation.name}`, | ||
preserveNullAndEmptyArrays: true, | ||
}, | ||
}, | ||
}, | ||
] | ||
: []), | ||
]; | ||
}); | ||
] | ||
: []), | ||
]; | ||
}); | ||
return Stages; | ||
@@ -105,0 +110,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
134771
2819