@andrewscwei/mongodb-odm
Advanced tools
Comparing version 0.15.0 to 0.16.0
@@ -37,3 +37,3 @@ /** | ||
*/ | ||
static randomFields<T = {}>(fixedFields?: DocumentFragment<T>, { includeOptionals }?: ModelRandomFieldsOptions): DocumentFragment<T>; | ||
static randomFields<T = {}>(fixedFields?: DocumentFragment<T>, { includeOptionals }?: ModelRandomFieldsOptions): Promise<DocumentFragment<T>>; | ||
/** | ||
@@ -40,0 +40,0 @@ * Generates an aggregation pipeline specifically for the schema associated |
@@ -63,24 +63,26 @@ "use strict"; | ||
static randomFields(fixedFields = {}, { includeOptionals = false } = {}) { | ||
const o = {}; | ||
const fields = this.schema.fields; | ||
for (const key in fields) { | ||
if (!fields.hasOwnProperty(key)) | ||
continue; | ||
// If key is already present in the fixed fields, omit. | ||
if (o.hasOwnProperty(key)) | ||
continue; | ||
const fieldSpecs = fields[key]; | ||
// If `includeOptionals` is not set, skip all the optional fields. | ||
if (!includeOptionals && !fieldSpecs.required) | ||
continue; | ||
// Use provided random function if provided in the schema. | ||
if (fieldSpecs.random) | ||
o[key] = fieldSpecs.random(); | ||
} | ||
for (const key in fixedFields) { | ||
if (!fixedFields.hasOwnProperty(key)) | ||
continue; | ||
o[key] = fixedFields[key]; | ||
} | ||
return o; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const o = {}; | ||
const fields = this.schema.fields; | ||
for (const key in fields) { | ||
if (!fields.hasOwnProperty(key)) | ||
continue; | ||
// If key is already present in the fixed fields, omit. | ||
if (o.hasOwnProperty(key)) | ||
continue; | ||
const fieldSpecs = fields[key]; | ||
// If `includeOptionals` is not set, skip all the optional fields. | ||
if (!includeOptionals && !fieldSpecs.required) | ||
continue; | ||
// Use provided random function if provided in the schema. | ||
if (fieldSpecs.random) | ||
o[key] = fieldSpecs.random(); | ||
} | ||
for (const key in fixedFields) { | ||
if (!fixedFields.hasOwnProperty(key)) | ||
continue; | ||
o[key] = fixedFields[key]; | ||
} | ||
return o; | ||
}); | ||
} | ||
@@ -200,3 +202,3 @@ /** | ||
// Apply before insert handler. | ||
const t = yield this.beforeInsert(doc || this.randomFields(), Object.assign({ strict: true }, options)); | ||
const t = yield this.beforeInsert(doc || (yield this.randomFields()), Object.assign({ strict: true }, options)); | ||
log(`${this.schema.model}.insertOne:`, JSON.stringify(t, null, 0)); | ||
@@ -505,6 +507,6 @@ const collection = yield this.getCollection(); | ||
*/ | ||
static findAndReplaceOne(query, replacement = this.randomFields(), options = {}) { | ||
static findAndReplaceOne(query, replacement, options = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const q = yield this.beforeDelete(query, options); | ||
const r = yield this.beforeInsert(replacement, options); | ||
const r = yield this.beforeInsert(replacement || (yield this.randomFields()), options); | ||
log(`${this.schema.model}.replaceOne:`, JSON.stringify(q, null, 0), JSON.stringify(r, null, 0)); | ||
@@ -511,0 +513,0 @@ const collection = yield this.getCollection(); |
{ | ||
"name": "@andrewscwei/mongodb-odm", | ||
"version": "0.15.0", | ||
"version": "0.16.0", | ||
"description": "ODM for MongoDB", | ||
@@ -33,8 +33,8 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@sindresorhus/is": "^0.12.0", | ||
"@types/mongodb": "^3.1.12", | ||
"@sindresorhus/is": "^0.13.0", | ||
"@types/mongodb": "^3.1.14", | ||
"bcrypt": "^3.0.2", | ||
"debug": "^4.1.0", | ||
"lodash": "^4.17.11", | ||
"mongodb": "^3.1.8" | ||
"mongodb": "^3.1.9" | ||
}, | ||
@@ -44,5 +44,5 @@ "devDependencies": { | ||
"@types/debug": "^0.0.31", | ||
"@types/dotenv": "^4.0.3", | ||
"@types/dotenv": "^6.1.0", | ||
"@types/faker": "^4.1.4", | ||
"@types/lodash": "^4.14.117", | ||
"@types/lodash": "^4.14.118", | ||
"@types/mocha": "^5.2.5", | ||
@@ -55,5 +55,5 @@ "dotenv": "^6.1.0", | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.1.3" | ||
"typescript": "^3.1.6" | ||
}, | ||
"types": "build/index.d.ts" | ||
} |
Sorry, the diff of this file is not supported yet
242717
3685
+ Added@sindresorhus/is@0.13.0(transitive)
- Removed@sindresorhus/is@0.12.0(transitive)
Updated@sindresorhus/is@^0.13.0
Updated@types/mongodb@^3.1.14
Updatedmongodb@^3.1.9