@coderich/autograph 0.13.101 → 0.13.103

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.101",
4
+ "version": "0.13.103",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -47,6 +47,7 @@ module.exports = class Resolver {
47
47
  clone() {
48
48
  return new Resolver({
49
49
  schema: this.#schema,
50
+ xschema: this.#xschema,
50
51
  context: this.#context,
51
52
  });
52
53
  }
@@ -141,11 +142,10 @@ module.exports = class Resolver {
141
142
  * @returns {*} - The promise resolution
142
143
  */
143
144
  run(promise) {
144
- return promise.then((results) => {
145
- return this.commit().then(() => results);
146
- }).catch((e) => {
147
- return this.rollback().then(() => Promise.reject(e));
148
- });
145
+ return this.commit().then(() => promise);
146
+ // return this.commit().then(() => promise).catch((e) => {
147
+ // return this.rollback().then(() => Promise.reject(e));
148
+ // });
149
149
  }
150
150
 
151
151
  /**
@@ -231,6 +231,8 @@ module.exports = class Resolver {
231
231
  return thunk(tquery).then((result) => {
232
232
  if (flags?.required && (result == null || result?.length === 0)) throw Boom.notFound(`${model} Not Found`);
233
233
  return result;
234
+ }).finally(() => {
235
+ query.resolve();
234
236
  });
235
237
  });
236
238
  }
@@ -306,7 +308,7 @@ module.exports = class Resolver {
306
308
  const type = query.isMutation ? 'Mutation' : 'Query';
307
309
  const event = this.#createEvent(query);
308
310
 
309
- return Emitter.emit(`pre${type}`, event).then(async (resultEarly) => {
311
+ const promise = Emitter.emit(`pre${type}`, event).then(async (resultEarly) => {
310
312
  if (resultEarly !== undefined) return resultEarly; // Nothing to validate/transform
311
313
  // if (query.crud === 'update' && Util.isEqual({ added: {}, updated: {}, deleted: {} }, Util.changeset(query.doc, query.input))) return query.doc;
312
314
 
@@ -317,7 +319,9 @@ module.exports = class Resolver {
317
319
  }
318
320
 
319
321
  return thunk(tquery);
320
- }).then((result) => {
322
+ });
323
+
324
+ promise.then((result) => {
321
325
  event.result = result; // backwards compat
322
326
  query.result = result;
323
327
  return Emitter.emit(`post${type}`, event);
@@ -326,6 +330,8 @@ module.exports = class Resolver {
326
330
  // const { data = {} } = e;
327
331
  // throw Boom.boomify(e, { data: { ...event, ...data } });
328
332
  });
333
+
334
+ return promise;
329
335
  }
330
336
 
331
337
  #createEvent(query) {
@@ -45,7 +45,7 @@ module.exports = class Transaction {
45
45
  }
46
46
 
47
47
  #close(op) {
48
- return Promise.all(this.#queries.map(q => q.promise())).then(() => {
48
+ return Promise.all(this.#queries.map(q => q.promise())).finally(() => {
49
49
  return Promise.all(Array.from(this.#sourceMap.entries()).map(([client, promise]) => {
50
50
  return promise.then(transaction => transaction[op]());
51
51
  }));
@@ -1,5 +1,5 @@
1
1
  const Util = require('@coderich/util');
2
- const { isGlob, globToRegex, mergeDeep, JSONParse } = require('../service/AppService');
2
+ const { isGlob, globToRegex, mergeDeep, JSONParse, withResolvers } = require('../service/AppService');
3
3
 
4
4
  module.exports = class Query {
5
5
  #config;
@@ -8,20 +8,30 @@ module.exports = class Query {
8
8
  #schema;
9
9
  #model;
10
10
  #query;
11
+ #resolution;
11
12
 
12
13
  constructor(config) {
13
- const { schema, context, resolver, query } = config;
14
+ const { schema, context, resolver, query, resolution = withResolvers() } = config;
14
15
  this.#config = config;
15
16
  this.#resolver = resolver;
16
17
  this.#context = context;
17
18
  this.#schema = schema;
18
19
  this.#model = schema.models[query.model];
19
20
  this.#query = query;
21
+ this.#resolution = resolution;
22
+ }
23
+
24
+ promise() {
25
+ return this.#resolution.promise;
26
+ }
27
+
28
+ resolve() {
29
+ this.#resolution.resolve();
20
30
  }
21
31
 
22
32
  clone(query) {
23
33
  query = { ...this.#query, ...query }; // NO deepMerge here; must replace fields entirely
24
- return new Query({ ...this.#config, query });
34
+ return new Query({ ...this.#config, query, resolution: this.#resolution });
25
35
  }
26
36
 
27
37
  toObject() {
@@ -26,17 +26,8 @@ module.exports = class QueryResolver extends QueryBuilder {
26
26
  }
27
27
 
28
28
  terminate() {
29
- return this.#terminate().then((result) => {
30
- this.#resolution.resolve(result);
31
- return result;
32
- }).catch((e) => {
33
- this.#resolution.reject(e);
34
- return Promise.reject(e);
35
- });
36
- }
37
-
38
- #terminate() {
39
29
  const query = super.terminate();
30
+ query.promise().then(this.#resolution.resolve).catch(this.#resolution.reject);
40
31
  const { op, args: { input } } = query.toObject();
41
32
 
42
33
  // Resolve