@coderich/autograph 0.13.102 → 0.13.104

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.102",
4
+ "version": "0.13.104",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -18,10 +18,14 @@ class Emitter extends EventEmitter {
18
18
  return prev[isBasic ? 0 : 1].push(wrapper) && prev;
19
19
  }, [[], []]);
20
20
 
21
+ // Basic functions are not designed to be bound to the query execution so we need an isolated resolver from any transactions
22
+ const resolver = data?.resolver?.clone();
23
+ const basicData = { ...data, resolver };
24
+
21
25
  return new Promise((resolve, reject) => {
22
26
  // Basic functions run first; if they return a value they abort the flow of execution
23
27
  basicFuncs.sort(Emitter.sort).forEach((fn) => {
24
- const value = fn(data);
28
+ const value = fn(basicData);
25
29
  if (value !== undefined && !(value instanceof Promise)) throw new AbortEarlyError(value);
26
30
  });
27
31
 
@@ -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,10 +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) => {
145
+ return promise.catch((e) => {
147
146
  return this.rollback().then(() => Promise.reject(e));
147
+ }).then((results) => {
148
+ return this.commit().then(() => results);
148
149
  });
149
150
  }
150
151
 
@@ -45,10 +45,10 @@ module.exports = class Transaction {
45
45
  }
46
46
 
47
47
  #close(op) {
48
- return Promise.all(this.#queries.map(q => q.promise())).finally(() => {
49
- return Promise.all(Array.from(this.#sourceMap.entries()).map(([client, promise]) => {
50
- return promise.then(transaction => transaction[op]());
51
- }));
52
- });
48
+ // return Promise.all(this.#queries.map(q => q.promise())).finally(() => {
49
+ return Promise.all(Array.from(this.#sourceMap.entries()).map(([client, promise]) => {
50
+ return promise.then(transaction => transaction[op]());
51
+ }));
52
+ // });
53
53
  }
54
54
  };