@zudojs/transactions 1.2.1 → 1.3.0
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/README.md +11 -2
- package/dist/adapter/adapter.core.d.ts +0 -1
- package/dist/adapter/adapter.core.js +0 -1
- package/dist/adapter/index.d.ts +0 -1
- package/dist/adapter/index.js +0 -1
- package/dist/context/context.core.d.ts +15 -1
- package/dist/context/context.core.js +18 -1
- package/dist/context/context.handle.d.ts +2 -2
- package/dist/context/context.handle.js +4 -4
- package/dist/context/index.d.ts +1 -2
- package/dist/context/index.js +1 -2
- package/dist/hooks/hooks.core.d.ts +0 -1
- package/dist/hooks/hooks.core.js +0 -1
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/manager/index.d.ts +0 -1
- package/dist/manager/index.js +0 -1
- package/dist/manager/manager.capabilities.d.ts +0 -1
- package/dist/manager/manager.capabilities.js +0 -1
- package/dist/manager/manager.commit.d.ts +0 -1
- package/dist/manager/manager.commit.js +8 -4
- package/dist/manager/manager.core.d.ts +9 -44
- package/dist/manager/manager.core.js +23 -9
- package/dist/manager/manager.events.d.ts +0 -1
- package/dist/manager/manager.events.js +0 -1
- package/dist/manager/manager.propagation.d.ts +7 -1
- package/dist/manager/manager.propagation.js +3 -4
- package/dist/manager/manager.retry.d.ts +0 -1
- package/dist/manager/manager.retry.js +0 -1
- package/dist/registry/index.d.ts +0 -1
- package/dist/registry/index.js +0 -1
- package/dist/registry/registry.core.d.ts +0 -1
- package/dist/registry/registry.core.js +0 -1
- package/dist/transaction/index.d.ts +0 -1
- package/dist/transaction/index.js +0 -1
- package/dist/transaction/transaction.core.d.ts +4 -2
- package/dist/transaction/transaction.core.js +13 -8
- package/dist/transaction/transaction.internal.d.ts +16 -1
- package/dist/transaction/transaction.internal.js +2 -1
- package/dist/transaction/transaction.participant.d.ts +0 -1
- package/dist/transaction/transaction.participant.js +1 -1
- package/dist/transaction/transaction.savepoint.d.ts +0 -1
- package/dist/transaction/transaction.savepoint.js +0 -1
- package/dist/transaction/transactionStateMachine.d.ts +0 -1
- package/dist/transaction/transactionStateMachine.js +0 -1
- package/dist/transactionErrors/index.d.ts +0 -1
- package/dist/transactionErrors/index.js +0 -1
- package/dist/transactionErrors/transactionError.base.d.ts +0 -1
- package/dist/transactionErrors/transactionError.base.js +0 -1
- package/dist/transactionErrors/transactionError.types.d.ts +0 -1
- package/dist/transactionErrors/transactionError.types.js +0 -1
- package/dist/transactionTypes/index.d.ts +1 -1
- package/dist/transactionTypes/index.js +1 -1
- package/dist/transactionTypes/transaction.interface.d.ts +0 -1
- package/dist/transactionTypes/transaction.interface.js +0 -1
- package/dist/transactionTypes/transactionAdapter.d.ts +0 -1
- package/dist/transactionTypes/transactionAdapter.js +0 -1
- package/dist/transactionTypes/transactionHooks.d.ts +0 -1
- package/dist/transactionTypes/transactionHooks.js +0 -1
- package/dist/transactionTypes/transactionManager.d.ts +52 -0
- package/dist/transactionTypes/transactionManager.js +10 -0
- package/dist/transactionTypes/transactionState.d.ts +0 -1
- package/dist/transactionTypes/transactionState.js +0 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/utils.helper.d.ts +0 -1
- package/dist/utils/utils.helper.js +0 -1
- package/dist/utils/utils.signal.d.ts +0 -1
- package/dist/utils/utils.signal.js +0 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -17,9 +17,9 @@ npm install @zudojs/transactions
|
|
|
17
17
|
## Quick Start
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
|
-
import { createTransactionManager } from "@zudojs/transactions";
|
|
20
|
+
import { createTransactionManager, type TransactionManager } from "@zudojs/transactions";
|
|
21
21
|
|
|
22
|
-
const manager = createTransactionManager({ adapter: databaseAdapter });
|
|
22
|
+
const manager: TransactionManager = createTransactionManager({ adapter: databaseAdapter });
|
|
23
23
|
|
|
24
24
|
// `run` opens a transaction, commits on success, rolls back on a throw.
|
|
25
25
|
const orderId = await manager.run(async (transaction) => {
|
|
@@ -166,6 +166,15 @@ the transaction.
|
|
|
166
166
|
`manager.commit()` / `manager.rollback()` releases its timer and registry entry.
|
|
167
167
|
- Failures thrown by `afterCommit` callbacks never undo the commit; they are
|
|
168
168
|
reported to `hooks.onError` as an `AggregateError`.
|
|
169
|
+
- A finished transaction is never joined. `afterCommit`/`afterRollback`
|
|
170
|
+
callbacks and hooks run in the scope that enclosed the transaction (the
|
|
171
|
+
outer transaction of a `requires_new`, otherwise none), and
|
|
172
|
+
`manager.getCurrent()`, `getCurrentHandle()`, `currentTransactionHandle()`
|
|
173
|
+
and `begin()` all read the scope through `currentTransaction()`, which
|
|
174
|
+
ignores a committed, rolled-back or failed transaction still held by the
|
|
175
|
+
context. Work started from an after-commit callback, or by a timer armed
|
|
176
|
+
inside the callback that fires after the commit, therefore starts a new
|
|
177
|
+
root transaction instead of a participant on a closed one.
|
|
169
178
|
- `retry` replays only attempts that opened their own transaction. An attempt
|
|
170
179
|
that joined an enclosing transaction has marked it rollback-only and is not
|
|
171
180
|
replayed.
|
|
@@ -16,4 +16,3 @@ export declare function createInMemoryAdapter(): TransactionAdapter;
|
|
|
16
16
|
* Create an adapter with custom capabilities.
|
|
17
17
|
*/
|
|
18
18
|
export declare function createAdapter(implementation: TransactionAdapter, capabilities: TransactionAdapterCapabilities): TransactionAdapter;
|
|
19
|
-
//# sourceMappingURL=adapter.core.d.ts.map
|
package/dist/adapter/index.d.ts
CHANGED
package/dist/adapter/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module context/context
|
|
5
5
|
*/
|
|
6
|
+
import type { Transaction } from "../transactionTypes/transaction.interface.js";
|
|
6
7
|
import type { TransactionContext } from "../transactionTypes/transactionAdapter.js";
|
|
7
8
|
/**
|
|
8
9
|
* Create a transaction context backed by AsyncLocalStorage.
|
|
@@ -16,4 +17,17 @@ export declare function getDefaultContext(): TransactionContext;
|
|
|
16
17
|
* Reset the default context (useful for testing).
|
|
17
18
|
*/
|
|
18
19
|
export declare function resetDefaultContext(): void;
|
|
19
|
-
|
|
20
|
+
/**
|
|
21
|
+
* The transaction in scope for the current async execution: the context's
|
|
22
|
+
* stored transaction unless it has already committed, rolled back or
|
|
23
|
+
* failed.
|
|
24
|
+
*
|
|
25
|
+
* A store outlives the transaction it holds. Work started while the store
|
|
26
|
+
* is active (`afterCommit` callbacks, timers armed inside the callback,
|
|
27
|
+
* jobs queued from it) inherits it, and `context.get()` then hands back a
|
|
28
|
+
* finished transaction that a new `run()` would join as a participant and
|
|
29
|
+
* fail on. The manager consults this instead, so such work starts afresh.
|
|
30
|
+
*
|
|
31
|
+
* @param context - The context to read; defaults to the default context.
|
|
32
|
+
*/
|
|
33
|
+
export declare function currentTransaction(context?: TransactionContext): Transaction | undefined;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @module context/context
|
|
5
5
|
*/
|
|
6
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
|
+
import { isTerminal } from "../transaction/transactionStateMachine.js";
|
|
7
8
|
/**
|
|
8
9
|
* Create a transaction context backed by AsyncLocalStorage.
|
|
9
10
|
*/
|
|
@@ -38,4 +39,20 @@ export function getDefaultContext() {
|
|
|
38
39
|
export function resetDefaultContext() {
|
|
39
40
|
defaultContext = undefined;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
/**
|
|
43
|
+
* The transaction in scope for the current async execution: the context's
|
|
44
|
+
* stored transaction unless it has already committed, rolled back or
|
|
45
|
+
* failed.
|
|
46
|
+
*
|
|
47
|
+
* A store outlives the transaction it holds. Work started while the store
|
|
48
|
+
* is active (`afterCommit` callbacks, timers armed inside the callback,
|
|
49
|
+
* jobs queued from it) inherits it, and `context.get()` then hands back a
|
|
50
|
+
* finished transaction that a new `run()` would join as a participant and
|
|
51
|
+
* fail on. The manager consults this instead, so such work starts afresh.
|
|
52
|
+
*
|
|
53
|
+
* @param context - The context to read; defaults to the default context.
|
|
54
|
+
*/
|
|
55
|
+
export function currentTransaction(context = getDefaultContext()) {
|
|
56
|
+
const transaction = context.get();
|
|
57
|
+
return transaction && !isTerminal(transaction.state) ? transaction : undefined;
|
|
58
|
+
}
|
|
@@ -28,9 +28,9 @@ export declare function getTransactionHandle<THandle = unknown>(transaction: Tra
|
|
|
28
28
|
*
|
|
29
29
|
* Uses the default context unless one is supplied; pass the same context
|
|
30
30
|
* the manager was created with when it was given a custom one (or call the
|
|
31
|
-
* manager's `getCurrentHandle()`).
|
|
31
|
+
* manager's `getCurrentHandle()`). A finished transaction still held by
|
|
32
|
+
* the store yields `undefined`; see `currentTransaction`.
|
|
32
33
|
*
|
|
33
34
|
* @typeParam THandle - The handle type your adapter's `begin()` returns.
|
|
34
35
|
*/
|
|
35
36
|
export declare function currentTransactionHandle<THandle = unknown>(context?: TransactionContext): THandle | undefined;
|
|
36
|
-
//# sourceMappingURL=context.handle.d.ts.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module context/context.handle
|
|
5
5
|
*/
|
|
6
6
|
import { connectionHandle } from "../transaction/transaction.internal.js";
|
|
7
|
-
import { getDefaultContext } from "./context.core.js";
|
|
7
|
+
import { currentTransaction, getDefaultContext } from "./context.core.js";
|
|
8
8
|
/**
|
|
9
9
|
* The adapter handle a transaction runs on: whatever the adapter's
|
|
10
10
|
* `begin()` returned (for example a database client or connection bound to
|
|
@@ -30,12 +30,12 @@ export function getTransactionHandle(transaction) {
|
|
|
30
30
|
*
|
|
31
31
|
* Uses the default context unless one is supplied; pass the same context
|
|
32
32
|
* the manager was created with when it was given a custom one (or call the
|
|
33
|
-
* manager's `getCurrentHandle()`).
|
|
33
|
+
* manager's `getCurrentHandle()`). A finished transaction still held by
|
|
34
|
+
* the store yields `undefined`; see `currentTransaction`.
|
|
34
35
|
*
|
|
35
36
|
* @typeParam THandle - The handle type your adapter's `begin()` returns.
|
|
36
37
|
*/
|
|
37
38
|
export function currentTransactionHandle(context = getDefaultContext()) {
|
|
38
|
-
const transaction = context
|
|
39
|
+
const transaction = currentTransaction(context);
|
|
39
40
|
return transaction ? getTransactionHandle(transaction) : undefined;
|
|
40
41
|
}
|
|
41
|
-
//# sourceMappingURL=context.handle.js.map
|
package/dist/context/index.d.ts
CHANGED
|
@@ -3,6 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module context
|
|
5
5
|
*/
|
|
6
|
-
export { createTransactionContext, getDefaultContext, resetDefaultContext, } from "./context.core.js";
|
|
6
|
+
export { createTransactionContext, currentTransaction, getDefaultContext, resetDefaultContext, } from "./context.core.js";
|
|
7
7
|
export { getTransactionHandle, currentTransactionHandle, } from "./context.handle.js";
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/context/index.js
CHANGED
|
@@ -3,6 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module context
|
|
5
5
|
*/
|
|
6
|
-
export { createTransactionContext, getDefaultContext, resetDefaultContext, } from "./context.core.js";
|
|
6
|
+
export { createTransactionContext, currentTransaction, getDefaultContext, resetDefaultContext, } from "./context.core.js";
|
|
7
7
|
export { getTransactionHandle, currentTransactionHandle, } from "./context.handle.js";
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -8,4 +8,3 @@ import type { TransactionHooks } from "../transactionTypes/transactionHooks.js";
|
|
|
8
8
|
* Merge multiple hook sets into one. Later hooks run after earlier ones.
|
|
9
9
|
*/
|
|
10
10
|
export declare function mergeHooks(...hookSets: readonly TransactionHooks[]): TransactionHooks;
|
|
11
|
-
//# sourceMappingURL=hooks.core.d.ts.map
|
package/dist/hooks/hooks.core.js
CHANGED
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -17,4 +17,3 @@ export * from "./hooks/index.js";
|
|
|
17
17
|
export * from "./registry/index.js";
|
|
18
18
|
export * from "./utils/index.js";
|
|
19
19
|
export { createTransactionManager, createEmitter, type TransactionEmitter, type TransactionManagerOptions, } from "./manager/index.js";
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
package/dist/manager/index.d.ts
CHANGED
|
@@ -11,4 +11,3 @@ export { assertAdapterSupports } from "./manager.capabilities.js";
|
|
|
11
11
|
export { withRetry } from "./manager.retry.js";
|
|
12
12
|
export { createEmitter } from "./manager.events.js";
|
|
13
13
|
export type { TransactionEmitter } from "./manager.events.js";
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/manager/index.js
CHANGED
|
@@ -9,4 +9,3 @@ export { resolvePropagation, suspendsTransaction, } from "./manager.propagation.
|
|
|
9
9
|
export { assertAdapterSupports } from "./manager.capabilities.js";
|
|
10
10
|
export { withRetry } from "./manager.retry.js";
|
|
11
11
|
export { createEmitter } from "./manager.events.js";
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -23,4 +23,3 @@ import type { TransactionAdapter } from "../transactionTypes/transactionAdapter.
|
|
|
23
23
|
* @throws {TransactionCapabilityError} when another capability is missing.
|
|
24
24
|
*/
|
|
25
25
|
export declare function assertAdapterSupports(adapter: TransactionAdapter, options: TransactionOptions | undefined): void;
|
|
26
|
-
//# sourceMappingURL=manager.capabilities.d.ts.map
|
|
@@ -39,4 +39,3 @@ export declare function commitTransaction(transaction: Transaction, adapter: Tra
|
|
|
39
39
|
* @throws {TransactionRollbackError} when the adapter refuses the rollback.
|
|
40
40
|
*/
|
|
41
41
|
export declare function rollbackTransaction(transaction: Transaction, adapter: TransactionAdapter, reason?: unknown, hooks?: TransactionHooks, emit?: TransactionEmitter): Promise<void>;
|
|
42
|
-
//# sourceMappingURL=manager.commit.d.ts.map
|
|
@@ -126,7 +126,10 @@ export async function commitTransaction(transaction, adapter, hooks, emit = noop
|
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
if (hooks?.afterCommit && transaction.kind !== "savepoint") {
|
|
129
|
-
|
|
129
|
+
// Detached: the transaction is finished, so work the hook starts must
|
|
130
|
+
// not inherit its context (see TransactionInternals._detach).
|
|
131
|
+
const afterCommit = hooks.afterCommit;
|
|
132
|
+
await internals(transaction)._detach(() => afterCommit({ transaction }));
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
/**
|
|
@@ -171,7 +174,8 @@ export async function rollbackTransaction(transaction, adapter, reason, hooks, e
|
|
|
171
174
|
});
|
|
172
175
|
}
|
|
173
176
|
emit(TRANSACTION_EVENTS.ROLLED_BACK, transaction, reason);
|
|
174
|
-
if (hooks?.afterRollback)
|
|
175
|
-
|
|
177
|
+
if (hooks?.afterRollback) {
|
|
178
|
+
const afterRollback = hooks.afterRollback;
|
|
179
|
+
await internals(transaction)._detach(() => afterRollback({ transaction }));
|
|
180
|
+
}
|
|
176
181
|
}
|
|
177
|
-
//# sourceMappingURL=manager.commit.js.map
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module manager/manager
|
|
5
5
|
*/
|
|
6
|
-
import type { Transaction, TransactionOptions } from "../transactionTypes/transaction.interface.js";
|
|
7
6
|
import type { TransactionAdapter, TransactionContext } from "../transactionTypes/transactionAdapter.js";
|
|
8
7
|
import type { TransactionEventHandler, TransactionHooks, TransactionRegistry } from "../transactionTypes/transactionHooks.js";
|
|
8
|
+
import type { TransactionManager } from "../transactionTypes/transactionManager.js";
|
|
9
9
|
/** Options for creating a transaction manager. */
|
|
10
10
|
export interface TransactionManagerOptions {
|
|
11
11
|
readonly adapter: TransactionAdapter;
|
|
@@ -23,47 +23,12 @@ export interface TransactionManagerOptions {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Create a transaction manager.
|
|
26
|
+
*
|
|
27
|
+
* The manager reads the transaction in scope through `currentTransaction`,
|
|
28
|
+
* so a transaction that has finished but whose context is still active
|
|
29
|
+
* (inside an `afterCommit` callback, or in a timer armed during the
|
|
30
|
+
* transaction) is never joined; a new `run()` there opens a fresh
|
|
31
|
+
* transaction. After-commit and after-rollback callbacks and hooks run in
|
|
32
|
+
* the scope that enclosed the transaction, not inside its context.
|
|
26
33
|
*/
|
|
27
|
-
export declare function createTransactionManager(options: TransactionManagerOptions):
|
|
28
|
-
/**
|
|
29
|
-
* Begin a transaction, applying the requested propagation mode.
|
|
30
|
-
*
|
|
31
|
-
* With the default `required` propagation inside an existing transaction
|
|
32
|
-
* this returns a participant: a handle that observes the enclosing
|
|
33
|
-
* transaction but never commits it.
|
|
34
|
-
*/
|
|
35
|
-
begin(opts?: TransactionOptions): Promise<Transaction>;
|
|
36
|
-
/**
|
|
37
|
-
* Run a callback inside a transaction, committing or rolling back around it.
|
|
38
|
-
*
|
|
39
|
-
* Only a transaction this call opened is completed here: joining an
|
|
40
|
-
* enclosing transaction must not commit it, and a failure inside a
|
|
41
|
-
* participant marks the enclosing transaction rollback-only instead.
|
|
42
|
-
*
|
|
43
|
-
* When the transaction times out, `transaction.signal` aborts and this
|
|
44
|
-
* stops waiting for the callback: the transaction is rolled back and
|
|
45
|
-
* the call rejects with `TransactionTimeoutError`. An error raised
|
|
46
|
-
* after a successful commit (for example by an `afterCommit` hook) is
|
|
47
|
-
* rethrown without attempting a rollback.
|
|
48
|
-
*/
|
|
49
|
-
run<T>(callback: (transaction: Transaction) => Promise<T>, opts?: TransactionOptions): Promise<T>;
|
|
50
|
-
/**
|
|
51
|
-
* Commit a transaction. Participants and committed transactions are no-ops.
|
|
52
|
-
*
|
|
53
|
-
* Completing a transaction opened with `begin()` also releases its
|
|
54
|
-
* timeout timer and registry entry; both used to be released only by
|
|
55
|
-
* `run()`, so hand-managed transactions stayed in the registry forever.
|
|
56
|
-
*/
|
|
57
|
-
commit(transaction: Transaction): Promise<void>;
|
|
58
|
-
/** Roll back a transaction, or mark the joined transaction rollback-only. */
|
|
59
|
-
rollback(transaction: Transaction, reason?: unknown): Promise<void>;
|
|
60
|
-
/** The transaction in scope for the current async execution, if any. */
|
|
61
|
-
getCurrent(): Transaction | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* The adapter handle (what `adapter.begin()` returned) of the
|
|
64
|
-
* transaction in scope for the current async execution, or `undefined`
|
|
65
|
-
* outside a transaction. See `getTransactionHandle`.
|
|
66
|
-
*/
|
|
67
|
-
getCurrentHandle<THandle = unknown>(): THandle | undefined;
|
|
68
|
-
};
|
|
69
|
-
//# sourceMappingURL=manager.core.d.ts.map
|
|
34
|
+
export declare function createTransactionManager(options: TransactionManagerOptions): TransactionManager;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module manager/manager
|
|
5
5
|
*/
|
|
6
|
-
import { getDefaultContext } from "../context/context.core.js";
|
|
7
|
-
import { internals } from "../transaction/transaction.internal.js";
|
|
6
|
+
import { currentTransaction, getDefaultContext, } from "../context/context.core.js";
|
|
7
|
+
import { internals, } from "../transaction/transaction.internal.js";
|
|
8
8
|
import { isTerminal } from "../transaction/transactionStateMachine.js";
|
|
9
9
|
import { TransactionRollbackError } from "../transactionErrors/transactionError.types.js";
|
|
10
10
|
import { getTransactionHandle } from "../context/context.handle.js";
|
|
@@ -19,6 +19,13 @@ function isFinished(transaction) {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Create a transaction manager.
|
|
22
|
+
*
|
|
23
|
+
* The manager reads the transaction in scope through `currentTransaction`,
|
|
24
|
+
* so a transaction that has finished but whose context is still active
|
|
25
|
+
* (inside an `afterCommit` callback, or in a timer armed during the
|
|
26
|
+
* transaction) is never joined; a new `run()` there opens a fresh
|
|
27
|
+
* transaction. After-commit and after-rollback callbacks and hooks run in
|
|
28
|
+
* the scope that enclosed the transaction, not inside its context.
|
|
22
29
|
*/
|
|
23
30
|
export function createTransactionManager(options) {
|
|
24
31
|
const { adapter, hooks, registry } = options;
|
|
@@ -70,15 +77,20 @@ export function createTransactionManager(options) {
|
|
|
70
77
|
*/
|
|
71
78
|
async begin(opts) {
|
|
72
79
|
const propagation = opts?.propagation ?? "required";
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
const enclosing = currentTransaction(context);
|
|
81
|
+
const current = suspendsTransaction(propagation) ? undefined : enclosing;
|
|
82
|
+
// Post-completion work returns to whatever enclosed this transaction:
|
|
83
|
+
// the outer transaction of a `requires_new`, or no transaction at all.
|
|
84
|
+
const detach = enclosing
|
|
85
|
+
? (work) => context.run(enclosing, work)
|
|
86
|
+
: (work) => context.exit(work);
|
|
76
87
|
const transaction = await resolvePropagation(propagation, {
|
|
77
88
|
current,
|
|
78
89
|
opts,
|
|
79
90
|
adapter,
|
|
80
91
|
hooks,
|
|
81
92
|
emit,
|
|
93
|
+
detach,
|
|
82
94
|
});
|
|
83
95
|
if (owns(transaction)) {
|
|
84
96
|
registry?.register(transaction);
|
|
@@ -172,9 +184,12 @@ export function createTransactionManager(options) {
|
|
|
172
184
|
release(transaction);
|
|
173
185
|
}
|
|
174
186
|
},
|
|
175
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* The transaction in scope for the current async execution, if any. A
|
|
189
|
+
* finished transaction still held by the context is not in scope.
|
|
190
|
+
*/
|
|
176
191
|
getCurrent() {
|
|
177
|
-
return context
|
|
192
|
+
return currentTransaction(context);
|
|
178
193
|
},
|
|
179
194
|
/**
|
|
180
195
|
* The adapter handle (what `adapter.begin()` returned) of the
|
|
@@ -182,9 +197,8 @@ export function createTransactionManager(options) {
|
|
|
182
197
|
* outside a transaction. See `getTransactionHandle`.
|
|
183
198
|
*/
|
|
184
199
|
getCurrentHandle() {
|
|
185
|
-
const current = context
|
|
200
|
+
const current = currentTransaction(context);
|
|
186
201
|
return current ? getTransactionHandle(current) : undefined;
|
|
187
202
|
},
|
|
188
203
|
};
|
|
189
204
|
}
|
|
190
|
-
//# sourceMappingURL=manager.core.js.map
|
|
@@ -11,6 +11,7 @@ import type { Transaction, TransactionOptions } from "../transactionTypes/transa
|
|
|
11
11
|
import type { TransactionAdapter } from "../transactionTypes/transactionAdapter.js";
|
|
12
12
|
import type { TransactionHooks } from "../transactionTypes/transactionHooks.js";
|
|
13
13
|
import type { TransactionPropagation } from "../transactionTypes/transactionState.js";
|
|
14
|
+
import { type TransactionDetach } from "../transaction/transaction.internal.js";
|
|
14
15
|
import type { TransactionEmitter } from "./manager.events.js";
|
|
15
16
|
/** Everything a propagation branch may need. */
|
|
16
17
|
export interface PropagationContext {
|
|
@@ -20,6 +21,12 @@ export interface PropagationContext {
|
|
|
20
21
|
readonly hooks: TransactionHooks | undefined;
|
|
21
22
|
/** Lifecycle event emitter. Defaults to discarding events. */
|
|
22
23
|
readonly emit?: TransactionEmitter;
|
|
24
|
+
/**
|
|
25
|
+
* Runs after-commit / after-rollback work in the scope that enclosed the
|
|
26
|
+
* new transaction, so it does not inherit the finished transaction's
|
|
27
|
+
* context. Defaults to running the work in place.
|
|
28
|
+
*/
|
|
29
|
+
readonly detach?: TransactionDetach;
|
|
23
30
|
}
|
|
24
31
|
/**
|
|
25
32
|
* Open a root transaction against the adapter and make it active.
|
|
@@ -40,4 +47,3 @@ export declare function beginRoot(context: PropagationContext, parentId?: string
|
|
|
40
47
|
export declare function resolvePropagation(propagation: TransactionPropagation, context: PropagationContext): Promise<Transaction>;
|
|
41
48
|
/** Whether a propagation mode runs its body outside any transaction. */
|
|
42
49
|
export declare function suspendsTransaction(propagation: TransactionPropagation): boolean;
|
|
43
|
-
//# sourceMappingURL=manager.propagation.d.ts.map
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { createTransaction } from "../transaction/transaction.core.js";
|
|
11
11
|
import { createNonTransactional, createParticipant, } from "../transaction/transaction.participant.js";
|
|
12
|
-
import { connectionHandle, internals, } from "../transaction/transaction.internal.js";
|
|
12
|
+
import { connectionHandle, internals, runInPlace, } from "../transaction/transaction.internal.js";
|
|
13
13
|
import { SavepointError, TransactionCapabilityError, TransactionPropagationError, } from "../transactionErrors/transactionError.types.js";
|
|
14
14
|
import { assertAdapterSupports } from "./manager.capabilities.js";
|
|
15
15
|
import { noopEmitter, TRANSACTION_EVENTS } from "./manager.events.js";
|
|
@@ -24,7 +24,7 @@ export async function beginRoot(context, parentId) {
|
|
|
24
24
|
const { adapter, hooks, opts } = context;
|
|
25
25
|
const emit = context.emit ?? noopEmitter;
|
|
26
26
|
assertAdapterSupports(adapter, opts);
|
|
27
|
-
const transaction = createTransaction(opts, parentId, "root");
|
|
27
|
+
const transaction = createTransaction(opts, parentId, "root", undefined, context.detach ?? runInPlace);
|
|
28
28
|
if (hooks?.beforeBegin)
|
|
29
29
|
await hooks.beforeBegin({ transaction });
|
|
30
30
|
try {
|
|
@@ -56,7 +56,7 @@ async function beginSavepoint(parent, context) {
|
|
|
56
56
|
// rule violation, and TransactionCapabilityError names what is missing.
|
|
57
57
|
throw new TransactionCapabilityError("savepoints, required by nested transactions");
|
|
58
58
|
}
|
|
59
|
-
const child = createTransaction(opts, parent.id, "savepoint", parent);
|
|
59
|
+
const child = createTransaction(opts, parent.id, "savepoint", parent, context.detach ?? runInPlace);
|
|
60
60
|
if (hooks?.beforeBegin)
|
|
61
61
|
await hooks.beforeBegin({ transaction: child });
|
|
62
62
|
const savepoint = `sp_${child.id}`;
|
|
@@ -119,4 +119,3 @@ export async function resolvePropagation(propagation, context) {
|
|
|
119
119
|
export function suspendsTransaction(propagation) {
|
|
120
120
|
return propagation === "not_supported" || propagation === "requires_new";
|
|
121
121
|
}
|
|
122
|
-
//# sourceMappingURL=manager.propagation.js.map
|
|
@@ -17,4 +17,3 @@ import type { TransactionRetryOptions } from "../transactionTypes/transaction.in
|
|
|
17
17
|
* @throws The last error when every attempt fails.
|
|
18
18
|
*/
|
|
19
19
|
export declare function withRetry<T>(options: TransactionRetryOptions | undefined, operation: (attempt: number) => Promise<T>): Promise<T>;
|
|
20
|
-
//# sourceMappingURL=manager.retry.d.ts.map
|
package/dist/registry/index.d.ts
CHANGED
package/dist/registry/index.js
CHANGED
|
@@ -6,4 +6,3 @@ export { createNonTransactional, createParticipant, } from "./transaction.partic
|
|
|
6
6
|
export { canTransition, createTransitionFunction, isTerminal, } from "./transactionStateMachine.js";
|
|
7
7
|
export { asSavepointHandle } from "./transaction.internal.js";
|
|
8
8
|
export type { SavepointHandle } from "./transaction.internal.js";
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -5,4 +5,3 @@ export { createTransaction } from "./transaction.core.js";
|
|
|
5
5
|
export { createNonTransactional, createParticipant, } from "./transaction.participant.js";
|
|
6
6
|
export { canTransition, createTransitionFunction, isTerminal, } from "./transactionStateMachine.js";
|
|
7
7
|
export { asSavepointHandle } from "./transaction.internal.js";
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { Transaction, TransactionOptions } from "../transactionTypes/transaction.interface.js";
|
|
5
5
|
import type { TransactionKind } from "../transactionTypes/transactionState.js";
|
|
6
|
+
import { type TransactionDetach } from "./transaction.internal.js";
|
|
6
7
|
/**
|
|
7
8
|
* Create a new Transaction instance.
|
|
8
9
|
*
|
|
@@ -11,6 +12,7 @@ import type { TransactionKind } from "../transactionTypes/transactionState.js";
|
|
|
11
12
|
* @param kind - How this handle relates to the adapter transaction.
|
|
12
13
|
* @param parent - The enclosing transaction of a savepoint. Its callbacks
|
|
13
14
|
* are deferred to `parent` on release instead of running.
|
|
15
|
+
* @param detach - Runs after-commit / after-rollback work in the scope
|
|
16
|
+
* that enclosed the transaction. Defaults to running it in place.
|
|
14
17
|
*/
|
|
15
|
-
export declare function createTransaction(options?: TransactionOptions, parentId?: string, kind?: TransactionKind, parent?: Transaction): Transaction;
|
|
16
|
-
//# sourceMappingURL=transaction.core.d.ts.map
|
|
18
|
+
export declare function createTransaction(options?: TransactionOptions, parentId?: string, kind?: TransactionKind, parent?: Transaction, detach?: TransactionDetach): Transaction;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { randomBytes } from "node:crypto";
|
|
5
5
|
import { TransactionRollbackError, TransactionRollbackOnlyError, TransactionStateError, TransactionTimeoutError, } from "../transactionErrors/transactionError.types.js";
|
|
6
6
|
import { canTransition, createTransitionFunction, } from "./transactionStateMachine.js";
|
|
7
|
-
import { attachInternals } from "./transaction.internal.js";
|
|
7
|
+
import { attachInternals, runInPlace, } from "./transaction.internal.js";
|
|
8
8
|
import { deferCallbacksToParent } from "./transaction.savepoint.js";
|
|
9
9
|
/**
|
|
10
10
|
* Generate a unique transaction ID.
|
|
@@ -12,12 +12,15 @@ import { deferCallbacksToParent } from "./transaction.savepoint.js";
|
|
|
12
12
|
function generateTransactionId() {
|
|
13
13
|
return `txn_${randomBytes(16).toString("hex")}`;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Runs callbacks in order, collecting failures rather than aborting. Each
|
|
17
|
+
* runs detached from the finished transaction's context.
|
|
18
|
+
*/
|
|
19
|
+
async function runCallbacks(callbacks, detach) {
|
|
17
20
|
const errors = [];
|
|
18
21
|
for (const callback of callbacks.splice(0)) {
|
|
19
22
|
try {
|
|
20
|
-
await callback
|
|
23
|
+
await detach(callback);
|
|
21
24
|
}
|
|
22
25
|
catch (error) {
|
|
23
26
|
errors.push(error);
|
|
@@ -33,8 +36,10 @@ async function runCallbacks(callbacks) {
|
|
|
33
36
|
* @param kind - How this handle relates to the adapter transaction.
|
|
34
37
|
* @param parent - The enclosing transaction of a savepoint. Its callbacks
|
|
35
38
|
* are deferred to `parent` on release instead of running.
|
|
39
|
+
* @param detach - Runs after-commit / after-rollback work in the scope
|
|
40
|
+
* that enclosed the transaction. Defaults to running it in place.
|
|
36
41
|
*/
|
|
37
|
-
export function createTransaction(options = {}, parentId, kind = "root", parent) {
|
|
42
|
+
export function createTransaction(options = {}, parentId, kind = "root", parent, detach = runInPlace) {
|
|
38
43
|
let state = "pending";
|
|
39
44
|
let rollbackOnly = false;
|
|
40
45
|
let rollbackOnlyReason;
|
|
@@ -106,7 +111,7 @@ export function createTransaction(options = {}, parentId, kind = "root", parent)
|
|
|
106
111
|
afterRollbackCallbacks.length = 0;
|
|
107
112
|
// The commit stands whatever the callbacks do; their failures are
|
|
108
113
|
// kept for the manager to report instead of being dropped.
|
|
109
|
-
callbackErrors = await runCallbacks(afterCommitCallbacks);
|
|
114
|
+
callbackErrors = await runCallbacks(afterCommitCallbacks, detach);
|
|
110
115
|
},
|
|
111
116
|
async rollback(reason) {
|
|
112
117
|
if (state === "rolled_back" || state === "failed")
|
|
@@ -120,7 +125,7 @@ export function createTransaction(options = {}, parentId, kind = "root", parent)
|
|
|
120
125
|
transition("rolling_back");
|
|
121
126
|
transition("rolled_back");
|
|
122
127
|
afterCommitCallbacks.length = 0;
|
|
123
|
-
const errors = await runCallbacks(afterRollbackCallbacks);
|
|
128
|
+
const errors = await runCallbacks(afterRollbackCallbacks, detach);
|
|
124
129
|
if (errors.length > 0) {
|
|
125
130
|
throw new TransactionRollbackError(id, {
|
|
126
131
|
cause: new AggregateError(errors, "after-rollback callback failures"),
|
|
@@ -154,6 +159,6 @@ export function createTransaction(options = {}, parentId, kind = "root", parent)
|
|
|
154
159
|
},
|
|
155
160
|
_getRollbackOnlyReason: () => rollbackOnlyReason,
|
|
156
161
|
_drainCallbackErrors: () => callbackErrors.splice(0),
|
|
162
|
+
_detach: detach,
|
|
157
163
|
});
|
|
158
164
|
}
|
|
159
|
-
//# sourceMappingURL=transaction.core.js.map
|
|
@@ -39,7 +39,23 @@ export interface TransactionInternals {
|
|
|
39
39
|
* trace. The manager drains them and reports them to `hooks.onError`.
|
|
40
40
|
*/
|
|
41
41
|
_drainCallbackErrors(): unknown[];
|
|
42
|
+
/**
|
|
43
|
+
* Run work in the scope that enclosed this transaction, rather than in
|
|
44
|
+
* the transaction's own context.
|
|
45
|
+
*
|
|
46
|
+
* After-commit and after-rollback callbacks and hooks run once the
|
|
47
|
+
* transaction has finished, yet they used to run with its context still
|
|
48
|
+
* active, so anything they started (a timer, a queued job) inherited a
|
|
49
|
+
* finished transaction and joined it. The manager supplies this from the
|
|
50
|
+
* context the transaction was begun in; a transaction created without a
|
|
51
|
+
* manager runs the work in place.
|
|
52
|
+
*/
|
|
53
|
+
_detach<T>(work: () => Promise<T>): Promise<T>;
|
|
42
54
|
}
|
|
55
|
+
/** Runs post-completion work in the scope enclosing a transaction. */
|
|
56
|
+
export type TransactionDetach = <T>(work: () => Promise<T>) => Promise<T>;
|
|
57
|
+
/** The detach used when no manager supplied one: run the work in place. */
|
|
58
|
+
export declare const runInPlace: TransactionDetach;
|
|
43
59
|
/**
|
|
44
60
|
* Access the manager-only surface of a transaction.
|
|
45
61
|
*
|
|
@@ -82,4 +98,3 @@ export declare function connectionHandle(transaction: Transaction): unknown;
|
|
|
82
98
|
* @returns The savepoint handle, or undefined when it is a plain handle.
|
|
83
99
|
*/
|
|
84
100
|
export declare function asSavepointHandle(handle: unknown): SavepointHandle | undefined;
|
|
85
|
-
//# sourceMappingURL=transaction.internal.d.ts.map
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
* steal the adapter handle.
|
|
18
18
|
*/
|
|
19
19
|
export const TRANSACTION_INTERNALS = Symbol("zudojs.transaction.internals");
|
|
20
|
+
/** The detach used when no manager supplied one: run the work in place. */
|
|
21
|
+
export const runInPlace = (work) => work();
|
|
20
22
|
/**
|
|
21
23
|
* Access the manager-only surface of a transaction.
|
|
22
24
|
*
|
|
@@ -79,4 +81,3 @@ export function asSavepointHandle(handle) {
|
|
|
79
81
|
}
|
|
80
82
|
return undefined;
|
|
81
83
|
}
|
|
82
|
-
//# sourceMappingURL=transaction.internal.js.map
|
|
@@ -28,4 +28,3 @@ export declare function createParticipant(parent: Transaction): Transaction;
|
|
|
28
28
|
* @returns A transaction handle bound to no adapter transaction.
|
|
29
29
|
*/
|
|
30
30
|
export declare function createNonTransactional(options?: TransactionOptions): Transaction;
|
|
31
|
-
//# sourceMappingURL=transaction.participant.d.ts.map
|
|
@@ -81,6 +81,7 @@ export function createParticipant(parent) {
|
|
|
81
81
|
_markTimedOut: refuse,
|
|
82
82
|
_getRollbackOnlyReason: () => internals(parent)._getRollbackOnlyReason(),
|
|
83
83
|
_drainCallbackErrors: () => [],
|
|
84
|
+
_detach: (work) => internals(parent)._detach(work),
|
|
84
85
|
});
|
|
85
86
|
return Object.freeze(participant);
|
|
86
87
|
}
|
|
@@ -99,4 +100,3 @@ export function createNonTransactional(options = {}) {
|
|
|
99
100
|
internals(txn)._transition("active");
|
|
100
101
|
return txn;
|
|
101
102
|
}
|
|
102
|
-
//# sourceMappingURL=transaction.participant.js.map
|
|
@@ -21,4 +21,3 @@ import type { Transaction } from "../transactionTypes/transaction.interface.js";
|
|
|
21
21
|
* @param afterRollback - The savepoint's pending after-rollback callbacks.
|
|
22
22
|
*/
|
|
23
23
|
export declare function deferCallbacksToParent(parent: Transaction, afterCommit: Array<() => Promise<void>>, afterRollback: Array<() => Promise<void>>): void;
|
|
24
|
-
//# sourceMappingURL=transaction.savepoint.d.ts.map
|
|
@@ -16,4 +16,3 @@ export declare function createTransitionFunction(getState: () => TransactionStat
|
|
|
16
16
|
export declare function canTransition(from: TransactionState, to: TransactionState): boolean;
|
|
17
17
|
/** Whether a state admits no further transitions. */
|
|
18
18
|
export declare function isTerminal(state: TransactionState): boolean;
|
|
19
|
-
//# sourceMappingURL=transactionStateMachine.d.ts.map
|
|
@@ -3,4 +3,3 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { TransactionError, type TransactionErrorOptions, } from "./transactionError.base.js";
|
|
5
5
|
export { TransactionStateError, TransactionTimeoutError, TransactionCommitError, TransactionRollbackError, TransactionRollbackOnlyError, TransactionAdapterError, TransactionPropagationError, TransactionIsolationError, SavepointError, TransactionRequiredError, TransactionUnexpectedError, TransactionCapabilityError, } from "./transactionError.types.js";
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -3,4 +3,3 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { TransactionError, } from "./transactionError.base.js";
|
|
5
5
|
export { TransactionStateError, TransactionTimeoutError, TransactionCommitError, TransactionRollbackError, TransactionRollbackOnlyError, TransactionAdapterError, TransactionPropagationError, TransactionIsolationError, SavepointError, TransactionRequiredError, TransactionUnexpectedError, TransactionCapabilityError, } from "./transactionError.types.js";
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -6,4 +6,3 @@
|
|
|
6
6
|
* across both import paths.
|
|
7
7
|
*/
|
|
8
8
|
export { TransactionStateError, TransactionTimeoutError, TransactionCommitError, TransactionRollbackError, TransactionRollbackOnlyError, TransactionAdapterError, TransactionPropagationError, TransactionIsolationError, SavepointError, TransactionRequiredError, TransactionUnexpectedError, TransactionCapabilityError, } from "@zudojs/errors";
|
|
9
|
-
//# sourceMappingURL=transactionError.types.d.ts.map
|
|
@@ -6,4 +6,3 @@
|
|
|
6
6
|
* across both import paths.
|
|
7
7
|
*/
|
|
8
8
|
export { TransactionStateError, TransactionTimeoutError, TransactionCommitError, TransactionRollbackError, TransactionRollbackOnlyError, TransactionAdapterError, TransactionPropagationError, TransactionIsolationError, SavepointError, TransactionRequiredError, TransactionUnexpectedError, TransactionCapabilityError, } from "@zudojs/errors";
|
|
9
|
-
//# sourceMappingURL=transactionError.types.js.map
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
export { type TransactionState, type TransactionKind, type TransactionPropagation, type TransactionIsolationLevel, } from "./transactionState.js";
|
|
7
7
|
export { type Transaction, type TransactionOptions, type TransactionRetryOptions, type TransactionRetryPredicate, } from "./transaction.interface.js";
|
|
8
8
|
export { type TransactionHandle, type TransactionAdapterCapabilities, type TransactionAdapter, type TransactionContext, } from "./transactionAdapter.js";
|
|
9
|
+
export { type TransactionManager } from "./transactionManager.js";
|
|
9
10
|
export { type TransactionHookContext, type TransactionErrorContext, type TransactionHooks, type TransactionRegistry, TRANSACTION_EVENTS, type TransactionEvent, type TransactionEventHandler, } from "./transactionHooks.js";
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
export {} from "./transactionState.js";
|
|
7
7
|
export {} from "./transaction.interface.js";
|
|
8
8
|
export {} from "./transactionAdapter.js";
|
|
9
|
+
export {} from "./transactionManager.js";
|
|
9
10
|
export { TRANSACTION_EVENTS, } from "./transactionHooks.js";
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transaction manager contract.
|
|
3
|
+
*
|
|
4
|
+
* `createTransactionManager` returned an anonymous object type, so a
|
|
5
|
+
* consumer that wanted to hold, inject or mock a manager had to write
|
|
6
|
+
* `ReturnType<typeof createTransactionManager>`. This is that type, named.
|
|
7
|
+
*
|
|
8
|
+
* @module transactionTypes/transactionManager
|
|
9
|
+
*/
|
|
10
|
+
import type { Transaction, TransactionOptions } from "./transaction.interface.js";
|
|
11
|
+
/**
|
|
12
|
+
* Coordinates begin, commit, rollback and context propagation for
|
|
13
|
+
* transactions opened against one adapter.
|
|
14
|
+
*/
|
|
15
|
+
export interface TransactionManager {
|
|
16
|
+
/**
|
|
17
|
+
* Begin a transaction, applying the requested propagation mode.
|
|
18
|
+
*
|
|
19
|
+
* With the default `required` propagation inside an existing transaction
|
|
20
|
+
* this returns a participant: a handle that observes the enclosing
|
|
21
|
+
* transaction but never commits it. A transaction opened here must be
|
|
22
|
+
* completed with `commit()` or `rollback()`.
|
|
23
|
+
*/
|
|
24
|
+
begin(options?: TransactionOptions): Promise<Transaction>;
|
|
25
|
+
/**
|
|
26
|
+
* Run a callback inside a transaction, committing or rolling back around
|
|
27
|
+
* it. Only a transaction this call opened is completed here; a failure
|
|
28
|
+
* inside a participant marks the enclosing transaction rollback-only.
|
|
29
|
+
*/
|
|
30
|
+
run<T>(callback: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Commit a transaction. Participants and committed transactions are
|
|
33
|
+
* no-ops; a rollback-only transaction is rolled back and the call
|
|
34
|
+
* rejects.
|
|
35
|
+
*/
|
|
36
|
+
commit(transaction: Transaction): Promise<void>;
|
|
37
|
+
/** Roll back a transaction, or mark the joined transaction rollback-only. */
|
|
38
|
+
rollback(transaction: Transaction, reason?: unknown): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* The transaction in scope for the current async execution, if any. A
|
|
41
|
+
* transaction that has already committed, rolled back or failed is not
|
|
42
|
+
* in scope, even when its context is still the active store (for example
|
|
43
|
+
* inside an `afterCommit` callback).
|
|
44
|
+
*/
|
|
45
|
+
getCurrent(): Transaction | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The adapter handle (what `adapter.begin()` returned) of the transaction
|
|
48
|
+
* in scope for the current async execution, or `undefined` outside a
|
|
49
|
+
* transaction. See `getTransactionHandle`.
|
|
50
|
+
*/
|
|
51
|
+
getCurrentHandle<THandle = unknown>(): THandle | undefined;
|
|
52
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transaction manager contract.
|
|
3
|
+
*
|
|
4
|
+
* `createTransactionManager` returned an anonymous object type, so a
|
|
5
|
+
* consumer that wanted to hold, inject or mock a manager had to write
|
|
6
|
+
* `ReturnType<typeof createTransactionManager>`. This is that type, named.
|
|
7
|
+
*
|
|
8
|
+
* @module transactionTypes/transactionManager
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -18,4 +18,3 @@ export type TransactionPropagation = "required" | "requires_new" | "supports" |
|
|
|
18
18
|
export type TransactionKind = "root" | "participant" | "savepoint" | "none";
|
|
19
19
|
/** Database isolation levels. */
|
|
20
20
|
export type TransactionIsolationLevel = "read_uncommitted" | "read_committed" | "repeatable_read" | "serializable";
|
|
21
|
-
//# sourceMappingURL=transactionState.d.ts.map
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zudojs/transactions",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Transaction lifecycle and coordination with state machine, AsyncLocalStorage context propagation, savepoints, hooks, and adapter abstraction.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"!dist/.tsbuildinfo"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@zudojs/errors": "1.
|
|
28
|
+
"@zudojs/errors": "1.4.0"
|
|
29
29
|
},
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">=24.0.0"
|