@coderich/autograph 0.13.103 → 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 +1 -1
- package/src/data/Emitter.js +5 -1
- package/src/data/Resolver.js +7 -10
- package/src/data/Transaction.js +5 -5
package/package.json
CHANGED
package/src/data/Emitter.js
CHANGED
|
@@ -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(
|
|
28
|
+
const value = fn(basicData);
|
|
25
29
|
if (value !== undefined && !(value instanceof Promise)) throw new AbortEarlyError(value);
|
|
26
30
|
});
|
|
27
31
|
|
package/src/data/Resolver.js
CHANGED
|
@@ -142,10 +142,11 @@ module.exports = class Resolver {
|
|
|
142
142
|
* @returns {*} - The promise resolution
|
|
143
143
|
*/
|
|
144
144
|
run(promise) {
|
|
145
|
-
return
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
return promise.catch((e) => {
|
|
146
|
+
return this.rollback().then(() => Promise.reject(e));
|
|
147
|
+
}).then((results) => {
|
|
148
|
+
return this.commit().then(() => results);
|
|
149
|
+
});
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
/**
|
|
@@ -308,7 +309,7 @@ module.exports = class Resolver {
|
|
|
308
309
|
const type = query.isMutation ? 'Mutation' : 'Query';
|
|
309
310
|
const event = this.#createEvent(query);
|
|
310
311
|
|
|
311
|
-
|
|
312
|
+
return Emitter.emit(`pre${type}`, event).then(async (resultEarly) => {
|
|
312
313
|
if (resultEarly !== undefined) return resultEarly; // Nothing to validate/transform
|
|
313
314
|
// if (query.crud === 'update' && Util.isEqual({ added: {}, updated: {}, deleted: {} }, Util.changeset(query.doc, query.input))) return query.doc;
|
|
314
315
|
|
|
@@ -319,9 +320,7 @@ module.exports = class Resolver {
|
|
|
319
320
|
}
|
|
320
321
|
|
|
321
322
|
return thunk(tquery);
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
promise.then((result) => {
|
|
323
|
+
}).then((result) => {
|
|
325
324
|
event.result = result; // backwards compat
|
|
326
325
|
query.result = result;
|
|
327
326
|
return Emitter.emit(`post${type}`, event);
|
|
@@ -330,8 +329,6 @@ module.exports = class Resolver {
|
|
|
330
329
|
// const { data = {} } = e;
|
|
331
330
|
// throw Boom.boomify(e, { data: { ...event, ...data } });
|
|
332
331
|
});
|
|
333
|
-
|
|
334
|
-
return promise;
|
|
335
332
|
}
|
|
336
333
|
|
|
337
334
|
#createEvent(query) {
|
package/src/data/Transaction.js
CHANGED
|
@@ -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
|
-
|
|
50
|
-
|
|
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
|
};
|