@coderich/autograph 0.13.27 → 0.13.29

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.27",
4
+ "version": "0.13.29",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -286,22 +286,17 @@ module.exports = class Resolver {
286
286
  }
287
287
 
288
288
  #createSystemEvent($query, thunk = () => {}) {
289
- const query = $query.toObject();
289
+ let query = $query.toObject();
290
290
  const type = query.isMutation ? 'Mutation' : 'Query';
291
- const event = { schema: this.#schema, context: this.#context, resolver: this, query };
292
-
293
- // Backwards compat
294
- Object.assign(event, query);
295
- query.match = query.where;
296
- query.toObject = () => query;
297
- event.merged = event.input;
298
- event.input = event.args?.input;
291
+ let event = this.#createEvent(query);
299
292
 
300
293
  return Emitter.emit(`pre${type}`, event).then(async (resultEarly) => {
301
294
  if (resultEarly !== undefined) return resultEarly; // Nothing to validate/transform
302
295
  // if (query.crud === 'update' && Util.isEqual({ added: {}, updated: {}, deleted: {} }, Util.changeset(query.doc, query.input))) return query.doc;
303
- const tquery = await $query.transform();
304
- // await Emitter.emit('validate', event); // We need to re-connect tquery to event
296
+ const tquery = await $query.transform(false);
297
+ query = tquery.toObject();
298
+ event = this.#createEvent(query)
299
+ if (query.isMutation) await Emitter.emit('validate', event);
305
300
  return thunk(tquery);
306
301
  }).then((result) => {
307
302
  event.doc ??= result; // Case of create
@@ -314,6 +309,19 @@ module.exports = class Resolver {
314
309
  });
315
310
  }
316
311
 
312
+ #createEvent(query) {
313
+ const event = { schema: this.#schema, context: this.#context, resolver: this, query };
314
+
315
+ // Backwards compat
316
+ Object.assign(event, query);
317
+ query.match = query.where;
318
+ query.toObject = () => query;
319
+ event.merged = event.input;
320
+ event.input = event.args?.input;
321
+
322
+ return event;
323
+ }
324
+
317
325
  static $loader(name, resolver, config) {
318
326
  if (!name) return loaders;
319
327
  if (!resolver) return loaders[name];
@@ -62,12 +62,18 @@ module.exports = class Query {
62
62
  /**
63
63
  * Transform entire query via pipeline. At minimum, pipeline is needed to unflatten the data...
64
64
  */
65
- transform() {
65
+ transform(asClone = true) {
66
66
  return Promise.all([
67
67
  this.pipeline('input', this.#query.input),
68
68
  this.#query.isNative ? this.#query.where : this.pipeline('where', this.#query.where ?? {}),
69
69
  this.pipeline('sort', this.#query.sort),
70
- ]).then(([input, where, sort]) => this.clone({ input, where, sort }));
70
+ ]).then(([input, where, sort]) => {
71
+ if (asClone) return this.clone({ input, where, sort });
72
+ this.#query.input = input;
73
+ this.#query.where = where;
74
+ this.#query.sort = sort;
75
+ return this;
76
+ });
71
77
  }
72
78
 
73
79
  /**