@coderich/autograph 0.13.47 → 0.13.49
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/Pipeline.js
CHANGED
|
@@ -117,7 +117,9 @@ module.exports = class Pipeline {
|
|
|
117
117
|
const ids = Util.filterBy(Util.ensureArray(value), (a, b) => `${a}` === `${b}`);
|
|
118
118
|
if (!ids.length) return undefined;
|
|
119
119
|
return resolver.match(type).flags(query.flags).where({ [fkField]: ids }).count().then((count) => {
|
|
120
|
-
if (count !== ids.length)
|
|
120
|
+
if (count !== ids.length) {
|
|
121
|
+
throw Boom.notFound(`${type} Not Found`);
|
|
122
|
+
}
|
|
121
123
|
});
|
|
122
124
|
}, { itemize: false });
|
|
123
125
|
|
|
@@ -65,8 +65,10 @@ module.exports = class QueryResolver extends QueryBuilder {
|
|
|
65
65
|
return this.#get(query).then((doc) => {
|
|
66
66
|
const [key] = Object.keys(input);
|
|
67
67
|
const values = get(this.#model.transformers.input.transform(input), key, []);
|
|
68
|
-
const $
|
|
69
|
-
|
|
68
|
+
const $doc = Util.pathmap(key, doc, (arr) => {
|
|
69
|
+
return arr.filter(el => values.every(v => `${v}` !== `${el}`));
|
|
70
|
+
});
|
|
71
|
+
return this.#resolver.match(this.#model.name).id(doc.id).save($doc);
|
|
70
72
|
});
|
|
71
73
|
}
|
|
72
74
|
case 'pullMany': {
|
|
@@ -110,11 +112,11 @@ module.exports = class QueryResolver extends QueryBuilder {
|
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
#resolveReferentialIntegrity(doc) {
|
|
113
|
-
const { id } = doc;
|
|
114
115
|
const txn = this.#resolver.transaction(false);
|
|
115
116
|
|
|
116
117
|
return txn.run(Util.promiseChain(this.#model.referentialIntegrity.map(({ model, field, path }) => () => {
|
|
117
|
-
const { onDelete, isArray } = field;
|
|
118
|
+
const { onDelete, isArray, fkField } = field;
|
|
119
|
+
const id = doc[fkField];
|
|
118
120
|
const $path = path.join('.');
|
|
119
121
|
const where = field.isVirtual ? { [field.model.pkField]: get(doc, field.linkBy) } : { [$path]: id };
|
|
120
122
|
|
package/src/schema/Schema.js
CHANGED
|
@@ -527,11 +527,15 @@ module.exports = class Schema {
|
|
|
527
527
|
});
|
|
528
528
|
|
|
529
529
|
// Helper methods
|
|
530
|
+
const resolvePathCache = {};
|
|
530
531
|
this.#schema.resolvePath = (path, prop = 'key') => {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
532
|
+
resolvePathCache[path] ??= (() => {
|
|
533
|
+
const [modelKey, ...fieldKeys] = path.split('.');
|
|
534
|
+
const $model = Object.values(this.#schema.models).find(el => el[prop] === modelKey);
|
|
535
|
+
if (!$model || !fieldKeys.length) return $model;
|
|
536
|
+
return fieldKeys.reduce((parent, key) => Object.values(parent.fields || parent.model.fields).find(el => el[prop] === key) || parent, $model);
|
|
537
|
+
})();
|
|
538
|
+
return resolvePathCache[path];
|
|
535
539
|
};
|
|
536
540
|
|
|
537
541
|
// Mutate typeDefs
|