@coderich/autograph 0.13.89 → 0.13.91

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coderich/autograph",
3
3
  "main": "index.js",
4
- "version": "0.13.89",
4
+ "version": "0.13.91",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -219,17 +219,19 @@ module.exports = class QueryBuilder {
219
219
  args = args.flat();
220
220
  const { id, limit } = this.#query;
221
221
  const suffix = id || limit === 1 || (crud === 'create' && args.length < 2) ? 'One' : 'Many';
222
- let input = suffix === 'One' ? args[0] : args;
223
- if (input === undefined) input = {};
224
- if (id !== undefined) input.id = id;
225
- this.#query.args.input = input;
226
- return this.terminate(Object.assign(this.#query, {
227
- op: `${crud}${suffix}`,
228
- key: `${crud}${this.#query.model}`,
229
- crud: ['push', 'pull', 'splice'].includes(crud) ? 'update' : crud,
230
- input,
231
- isMutation: true,
232
- }));
222
+ const op = `${crud}${suffix}`;
223
+ const key = `${crud}${this.#query.model}`;
224
+ const $crud = ['push', 'pull', 'splice'].includes(crud) ? 'update' : crud;
225
+ let input;
226
+
227
+ if (['create', 'update'].includes($crud)) {
228
+ input = op === 'createMany' ? args : args[0];
229
+ if (input === undefined) input = {};
230
+ if (id !== undefined) input.id = id;
231
+ this.#query.args.input = input;
232
+ }
233
+
234
+ return this.terminate(Object.assign(this.#query, { op, key, crud: $crud, input, isMutation: true }));
233
235
  }
234
236
 
235
237
  #propCheck(prop, ...checks) {
@@ -54,7 +54,7 @@ module.exports = class QueryResolver extends QueryBuilder {
54
54
  });
55
55
  }
56
56
  case 'pushMany': {
57
- const [[key, values]] = Object.entries(input[0]);
57
+ const [[key, values]] = Object.entries(input);
58
58
  return this.#find(query).then((docs) => {
59
59
  return this.#resolver.transaction(false).run(Promise.all(docs.map(doc => this.#resolver.match(this.#model.name).id(doc.id).push(key, values))));
60
60
  });
@@ -72,7 +72,7 @@ module.exports = class QueryResolver extends QueryBuilder {
72
72
  });
73
73
  }
74
74
  case 'pullMany': {
75
- const [[key, values]] = Object.entries(input[0]);
75
+ const [[key, values]] = Object.entries(input);
76
76
  return this.#find(query).then((docs) => {
77
77
  return this.#resolver.transaction(false).run(Promise.all(docs.map(doc => this.#resolver.match(this.#model.name).id(doc.id).pull(key, values))));
78
78
  });