@coderich/autograph 0.14.2 → 0.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/data/Resolver.js
CHANGED
|
@@ -245,7 +245,7 @@ module.exports = class Resolver {
|
|
|
245
245
|
model = this.#schema.models[model];
|
|
246
246
|
|
|
247
247
|
return Object.defineProperties(Util.map(result, (doc) => {
|
|
248
|
-
const $doc = model.docTransform(doc);
|
|
248
|
+
const $doc = model.docTransform(doc, { resolver: this, context: this.#context });
|
|
249
249
|
|
|
250
250
|
// Assign useful/needed meta data
|
|
251
251
|
return Object.defineProperties($doc, {
|
|
@@ -40,8 +40,12 @@ module.exports = class QueryResolver extends QueryBuilder {
|
|
|
40
40
|
}
|
|
41
41
|
case 'updateOne': {
|
|
42
42
|
return this.#get(query).then((doc) => {
|
|
43
|
-
const
|
|
44
|
-
|
|
43
|
+
const cloned = query.clone({ doc });
|
|
44
|
+
Object.defineProperty(cloned.toObject(), 'merged', {
|
|
45
|
+
get() { return mergeDeep({}, doc, Util.unflatten(this.input, { safe: true })); },
|
|
46
|
+
enumerable: true,
|
|
47
|
+
});
|
|
48
|
+
return this.#resolver.resolve(cloned);
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
51
|
case 'updateMany': {
|
package/src/schema/Schema.js
CHANGED
|
@@ -473,15 +473,15 @@ module.exports = class Schema {
|
|
|
473
473
|
|
|
474
474
|
// Deserialize/docs special case handling for performance
|
|
475
475
|
const docFields = Object.values($model.fields);
|
|
476
|
-
$model.docTransform = (doc) => {
|
|
476
|
+
$model.docTransform = (doc, args = {}) => {
|
|
477
477
|
if (doc == null) return doc;
|
|
478
478
|
const out = {};
|
|
479
479
|
for (const docField of docFields) {
|
|
480
480
|
let value = docField.key in doc ? doc[docField.key] : docField.defaultValue;
|
|
481
481
|
if (value === undefined) continue; // eslint-disable-line
|
|
482
482
|
if (docField.isArray) value = value == null ? value : Util.ensureArray(value);
|
|
483
|
-
if (docField.isEmbedded) value = Util.map(value, v => docField.model.docTransform(v));
|
|
484
|
-
if (docField.pipelines.deserialize.length) value = Pipeline.resolve({ model: $model, field: docField, value }, 'deserialize');
|
|
483
|
+
if (docField.isEmbedded) value = Util.map(value, v => docField.model.docTransform(v, args));
|
|
484
|
+
if (docField.pipelines.deserialize.length) value = Pipeline.resolve({ ...args, model: $model, field: docField, value }, 'deserialize');
|
|
485
485
|
out[docField.name] = value;
|
|
486
486
|
}
|
|
487
487
|
return out;
|