pqb 0.17.6 → 0.17.7
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/dist/index.d.ts +17 -0
- package/dist/index.js +27 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7135,8 +7135,25 @@ type Arg = {
|
|
|
7135
7135
|
$queryBuilder: Query;
|
|
7136
7136
|
} | Query;
|
|
7137
7137
|
declare const testTransaction: {
|
|
7138
|
+
/**
|
|
7139
|
+
* Start a test transaction.
|
|
7140
|
+
* The returned promise is resolved immediately when transaction starts, not waiting for it to end.
|
|
7141
|
+
*
|
|
7142
|
+
* @param arg - ORM instance or a queryable instance (such as db.someTable).
|
|
7143
|
+
*/
|
|
7138
7144
|
start(arg: Arg): Promise<void>;
|
|
7145
|
+
/**
|
|
7146
|
+
* Rollback a test transaction.
|
|
7147
|
+
*
|
|
7148
|
+
* @param arg - the same ORM or query argument passed into the `testTransaction.start`.
|
|
7149
|
+
*/
|
|
7139
7150
|
rollback(arg: Arg): Promise<void> | undefined;
|
|
7151
|
+
/**
|
|
7152
|
+
* Will roll back the current `testTransaction` (won't have any effect if it was rolled back already),
|
|
7153
|
+
* and if there's no nested test transactions left, it will close the db connection.
|
|
7154
|
+
*
|
|
7155
|
+
* @param arg - the same ORM or query argument passed into the `testTransaction.start`.
|
|
7156
|
+
*/
|
|
7140
7157
|
close(arg: Arg): Promise<void>;
|
|
7141
7158
|
};
|
|
7142
7159
|
|
package/dist/index.js
CHANGED
|
@@ -10195,12 +10195,18 @@ class Rollback extends Error {
|
|
|
10195
10195
|
const trxForTest = Symbol("trxForTest");
|
|
10196
10196
|
const argToDb = (arg) => "$queryBuilder" in arg ? arg.$queryBuilder : arg;
|
|
10197
10197
|
const testTransaction = {
|
|
10198
|
+
/**
|
|
10199
|
+
* Start a test transaction.
|
|
10200
|
+
* The returned promise is resolved immediately when transaction starts, not waiting for it to end.
|
|
10201
|
+
*
|
|
10202
|
+
* @param arg - ORM instance or a queryable instance (such as db.someTable).
|
|
10203
|
+
*/
|
|
10198
10204
|
start(arg) {
|
|
10199
10205
|
var _a, _b;
|
|
10200
10206
|
const db = argToDb(arg);
|
|
10201
10207
|
const { transactionStorage } = db.internal;
|
|
10202
10208
|
const { getStore } = transactionStorage;
|
|
10203
|
-
const adapter = db.baseQuery.q;
|
|
10209
|
+
const { adapter } = db.baseQuery.q;
|
|
10204
10210
|
const data = {
|
|
10205
10211
|
adapter: {
|
|
10206
10212
|
query: adapter.query,
|
|
@@ -10232,17 +10238,30 @@ const testTransaction = {
|
|
|
10232
10238
|
});
|
|
10233
10239
|
});
|
|
10234
10240
|
},
|
|
10241
|
+
/**
|
|
10242
|
+
* Rollback a test transaction.
|
|
10243
|
+
*
|
|
10244
|
+
* @param arg - the same ORM or query argument passed into the `testTransaction.start`.
|
|
10245
|
+
*/
|
|
10235
10246
|
rollback(arg) {
|
|
10236
|
-
var _a
|
|
10247
|
+
var _a;
|
|
10237
10248
|
const db = argToDb(arg);
|
|
10238
|
-
const data =
|
|
10239
|
-
|
|
10240
|
-
|
|
10241
|
-
|
|
10242
|
-
|
|
10249
|
+
const data = db.internal[trxForTest];
|
|
10250
|
+
const last = data == null ? void 0 : data.pop();
|
|
10251
|
+
if (!last)
|
|
10252
|
+
return;
|
|
10253
|
+
if ((data == null ? void 0 : data.length) === 1) {
|
|
10254
|
+
Object.assign(db.baseQuery.q.adapter, data[0].adapter);
|
|
10243
10255
|
}
|
|
10244
|
-
|
|
10256
|
+
(_a = last.reject) == null ? void 0 : _a.call(last, new Rollback());
|
|
10257
|
+
return last.promise;
|
|
10245
10258
|
},
|
|
10259
|
+
/**
|
|
10260
|
+
* Will roll back the current `testTransaction` (won't have any effect if it was rolled back already),
|
|
10261
|
+
* and if there's no nested test transactions left, it will close the db connection.
|
|
10262
|
+
*
|
|
10263
|
+
* @param arg - the same ORM or query argument passed into the `testTransaction.start`.
|
|
10264
|
+
*/
|
|
10246
10265
|
async close(arg) {
|
|
10247
10266
|
var _a;
|
|
10248
10267
|
const db = argToDb(arg);
|