@nestjs-transactional/core 1.0.0-alpha.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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +265 -0
  3. package/dist/bootstrap/transactional-methods.bootstrap.d.ts +42 -0
  4. package/dist/bootstrap/transactional-methods.bootstrap.js +129 -0
  5. package/dist/bootstrap/transactional-methods.bootstrap.js.map +1 -0
  6. package/dist/context/transaction-context-view.d.ts +38 -0
  7. package/dist/context/transaction-context-view.js +48 -0
  8. package/dist/context/transaction-context-view.js.map +1 -0
  9. package/dist/context/transaction.context.d.ts +114 -0
  10. package/dist/context/transaction.context.js +112 -0
  11. package/dist/context/transaction.context.js.map +1 -0
  12. package/dist/decorators/inject-decorators.d.ts +36 -0
  13. package/dist/decorators/inject-decorators.js +45 -0
  14. package/dist/decorators/inject-decorators.js.map +1 -0
  15. package/dist/decorators/transactional.decorator.d.ts +64 -0
  16. package/dist/decorators/transactional.decorator.js +82 -0
  17. package/dist/decorators/transactional.decorator.js.map +1 -0
  18. package/dist/index.d.ts +19 -0
  19. package/dist/index.js +35 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/interceptor/transactional.interceptor.d.ts +28 -0
  22. package/dist/interceptor/transactional.interceptor.js +56 -0
  23. package/dist/interceptor/transactional.interceptor.js.map +1 -0
  24. package/dist/internal/markers.d.ts +15 -0
  25. package/dist/internal/markers.js +18 -0
  26. package/dist/internal/markers.js.map +1 -0
  27. package/dist/manager/adapter.registry.d.ts +103 -0
  28. package/dist/manager/adapter.registry.js +179 -0
  29. package/dist/manager/adapter.registry.js.map +1 -0
  30. package/dist/manager/transaction.manager.d.ts +129 -0
  31. package/dist/manager/transaction.manager.js +412 -0
  32. package/dist/manager/transaction.manager.js.map +1 -0
  33. package/dist/module/transactional.module.d.ts +242 -0
  34. package/dist/module/transactional.module.js +374 -0
  35. package/dist/module/transactional.module.js.map +1 -0
  36. package/dist/observability/transaction-observer.d.ts +78 -0
  37. package/dist/observability/transaction-observer.js +18 -0
  38. package/dist/observability/transaction-observer.js.map +1 -0
  39. package/dist/testing/in-memory.adapter.d.ts +66 -0
  40. package/dist/testing/in-memory.adapter.js +83 -0
  41. package/dist/testing/in-memory.adapter.js.map +1 -0
  42. package/dist/testing/index.d.ts +2 -0
  43. package/dist/testing/index.js +18 -0
  44. package/dist/testing/index.js.map +1 -0
  45. package/dist/tokens/constants.d.ts +14 -0
  46. package/dist/tokens/constants.js +17 -0
  47. package/dist/tokens/constants.js.map +1 -0
  48. package/dist/tokens/index.d.ts +3 -0
  49. package/dist/tokens/index.js +11 -0
  50. package/dist/tokens/index.js.map +1 -0
  51. package/dist/tokens/token-utils.d.ts +52 -0
  52. package/dist/tokens/token-utils.js +67 -0
  53. package/dist/tokens/token-utils.js.map +1 -0
  54. package/dist/types/domain-event.d.ts +18 -0
  55. package/dist/types/domain-event.js +3 -0
  56. package/dist/types/domain-event.js.map +1 -0
  57. package/dist/types/errors.d.ts +50 -0
  58. package/dist/types/errors.js +61 -0
  59. package/dist/types/errors.js.map +1 -0
  60. package/dist/types/isolation.d.ts +11 -0
  61. package/dist/types/isolation.js +3 -0
  62. package/dist/types/isolation.js.map +1 -0
  63. package/dist/types/propagation.d.ts +63 -0
  64. package/dist/types/propagation.js +67 -0
  65. package/dist/types/propagation.js.map +1 -0
  66. package/dist/types/transaction-adapter.d.ts +72 -0
  67. package/dist/types/transaction-adapter.js +3 -0
  68. package/dist/types/transaction-adapter.js.map +1 -0
  69. package/dist/types/transaction-handle.d.ts +23 -0
  70. package/dist/types/transaction-handle.js +3 -0
  71. package/dist/types/transaction-handle.js.map +1 -0
  72. package/dist/types/transaction-options.d.ts +88 -0
  73. package/dist/types/transaction-options.js +3 -0
  74. package/dist/types/transaction-options.js.map +1 -0
  75. package/package.json +74 -0
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Default dataSource name used when none is specified to a token
3
+ * utility or inject decorator. Single-adapter consumers never need to
4
+ * type this string — the default argument on every helper substitutes
5
+ * it automatically.
6
+ *
7
+ * Multi-adapter consumers register additional dataSources by name
8
+ * (`'billing'`, `'inventory'`, ...). The string `'default'` is the
9
+ * convention for the always-present primary registration; ADR-018
10
+ * documents why this fixed name was chosen over alternatives like
11
+ * `'main'` or `'primary'`.
12
+ */
13
+ export declare const DEFAULT_DATA_SOURCE_NAME = "default";
14
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_DATA_SOURCE_NAME = void 0;
4
+ /**
5
+ * Default dataSource name used when none is specified to a token
6
+ * utility or inject decorator. Single-adapter consumers never need to
7
+ * type this string — the default argument on every helper substitutes
8
+ * it automatically.
9
+ *
10
+ * Multi-adapter consumers register additional dataSources by name
11
+ * (`'billing'`, `'inventory'`, ...). The string `'default'` is the
12
+ * convention for the always-present primary registration; ADR-018
13
+ * documents why this fixed name was chosen over alternatives like
14
+ * `'main'` or `'primary'`.
15
+ */
16
+ exports.DEFAULT_DATA_SOURCE_NAME = 'default';
17
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/tokens/constants.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACU,QAAA,wBAAwB,GAAG,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { DEFAULT_DATA_SOURCE_NAME } from './constants';
2
+ export { getTransactionContextRegistryToken, getTransactionContextToken, getTransactionManagerToken, getTransactionalAdapterToken, } from './token-utils';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTransactionalAdapterToken = exports.getTransactionManagerToken = exports.getTransactionContextToken = exports.getTransactionContextRegistryToken = exports.DEFAULT_DATA_SOURCE_NAME = void 0;
4
+ var constants_1 = require("./constants");
5
+ Object.defineProperty(exports, "DEFAULT_DATA_SOURCE_NAME", { enumerable: true, get: function () { return constants_1.DEFAULT_DATA_SOURCE_NAME; } });
6
+ var token_utils_1 = require("./token-utils");
7
+ Object.defineProperty(exports, "getTransactionContextRegistryToken", { enumerable: true, get: function () { return token_utils_1.getTransactionContextRegistryToken; } });
8
+ Object.defineProperty(exports, "getTransactionContextToken", { enumerable: true, get: function () { return token_utils_1.getTransactionContextToken; } });
9
+ Object.defineProperty(exports, "getTransactionManagerToken", { enumerable: true, get: function () { return token_utils_1.getTransactionManagerToken; } });
10
+ Object.defineProperty(exports, "getTransactionalAdapterToken", { enumerable: true, get: function () { return token_utils_1.getTransactionalAdapterToken; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":";;;AAAA,yCAAuD;AAA9C,qHAAA,wBAAwB,OAAA;AACjC,6CAKuB;AAJrB,iIAAA,kCAAkC,OAAA;AAClC,yHAAA,0BAA0B,OAAA;AAC1B,yHAAA,0BAA0B,OAAA;AAC1B,2HAAA,4BAA4B,OAAA"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Token utilities derive deterministic DI token strings from a
3
+ * dataSource name. They are the foundation of the multi-adapter
4
+ * architecture (ADR-018) — every package binds providers under
5
+ * `getXxxToken(dataSource)` and every consumer injects via the same
6
+ * function so the strings line up exactly.
7
+ *
8
+ * Format is `${dataSource}${Component}` (camelCase concat). The
9
+ * default dataSource is {@link DEFAULT_DATA_SOURCE_NAME} (`'default'`)
10
+ * — calling `getTransactionManagerToken()` yields
11
+ * `'defaultTransactionManager'`. A non-default name like `'billing'`
12
+ * yields `'billingTransactionManager'`.
13
+ *
14
+ * Empty-string `dataSource` produces a bare component string
15
+ * (`getTransactionManagerToken('')` → `'TransactionManager'`). That
16
+ * collides with the class-token shape NestJS uses for
17
+ * constructor-style injection (`@Inject(TransactionManager)`), so
18
+ * empty strings should be treated as a programming error at the call
19
+ * site. The default argument exists specifically to prevent users
20
+ * from hitting this case accidentally.
21
+ */
22
+ /**
23
+ * DI token for the per-dataSource `TransactionManager`.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * @Inject(getTransactionManagerToken('billing'))
28
+ * private readonly txManager: TransactionManager;
29
+ * ```
30
+ */
31
+ export declare function getTransactionManagerToken(dataSource?: string): string;
32
+ /**
33
+ * DI token for the per-dataSource `TransactionContext`. Each
34
+ * dataSource carries its own `AsyncLocalStorage` instance — see
35
+ * DD-023 — so cross-dataSource calls do not silently enrol into a
36
+ * sibling transaction.
37
+ */
38
+ export declare function getTransactionContextToken(dataSource?: string): string;
39
+ /**
40
+ * DI token for the per-dataSource `TransactionAdapter` instance —
41
+ * the concrete adapter (TypeORM, Prisma, ...) bound to the named
42
+ * dataSource. See DD-021.
43
+ */
44
+ export declare function getTransactionalAdapterToken(dataSource?: string): string;
45
+ /**
46
+ * DI token for the global `TransactionContextRegistry` — a
47
+ * process-wide singleton that maps dataSource names to their
48
+ * `TransactionContext` instances. Not parameterised by dataSource:
49
+ * exactly one registry per process serves all adapters.
50
+ */
51
+ export declare function getTransactionContextRegistryToken(): string;
52
+ //# sourceMappingURL=token-utils.d.ts.map
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTransactionManagerToken = getTransactionManagerToken;
4
+ exports.getTransactionContextToken = getTransactionContextToken;
5
+ exports.getTransactionalAdapterToken = getTransactionalAdapterToken;
6
+ exports.getTransactionContextRegistryToken = getTransactionContextRegistryToken;
7
+ const constants_1 = require("./constants");
8
+ /**
9
+ * Token utilities derive deterministic DI token strings from a
10
+ * dataSource name. They are the foundation of the multi-adapter
11
+ * architecture (ADR-018) — every package binds providers under
12
+ * `getXxxToken(dataSource)` and every consumer injects via the same
13
+ * function so the strings line up exactly.
14
+ *
15
+ * Format is `${dataSource}${Component}` (camelCase concat). The
16
+ * default dataSource is {@link DEFAULT_DATA_SOURCE_NAME} (`'default'`)
17
+ * — calling `getTransactionManagerToken()` yields
18
+ * `'defaultTransactionManager'`. A non-default name like `'billing'`
19
+ * yields `'billingTransactionManager'`.
20
+ *
21
+ * Empty-string `dataSource` produces a bare component string
22
+ * (`getTransactionManagerToken('')` → `'TransactionManager'`). That
23
+ * collides with the class-token shape NestJS uses for
24
+ * constructor-style injection (`@Inject(TransactionManager)`), so
25
+ * empty strings should be treated as a programming error at the call
26
+ * site. The default argument exists specifically to prevent users
27
+ * from hitting this case accidentally.
28
+ */
29
+ /**
30
+ * DI token for the per-dataSource `TransactionManager`.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * @Inject(getTransactionManagerToken('billing'))
35
+ * private readonly txManager: TransactionManager;
36
+ * ```
37
+ */
38
+ function getTransactionManagerToken(dataSource = constants_1.DEFAULT_DATA_SOURCE_NAME) {
39
+ return `${dataSource}TransactionManager`;
40
+ }
41
+ /**
42
+ * DI token for the per-dataSource `TransactionContext`. Each
43
+ * dataSource carries its own `AsyncLocalStorage` instance — see
44
+ * DD-023 — so cross-dataSource calls do not silently enrol into a
45
+ * sibling transaction.
46
+ */
47
+ function getTransactionContextToken(dataSource = constants_1.DEFAULT_DATA_SOURCE_NAME) {
48
+ return `${dataSource}TransactionContext`;
49
+ }
50
+ /**
51
+ * DI token for the per-dataSource `TransactionAdapter` instance —
52
+ * the concrete adapter (TypeORM, Prisma, ...) bound to the named
53
+ * dataSource. See DD-021.
54
+ */
55
+ function getTransactionalAdapterToken(dataSource = constants_1.DEFAULT_DATA_SOURCE_NAME) {
56
+ return `${dataSource}TransactionalAdapter`;
57
+ }
58
+ /**
59
+ * DI token for the global `TransactionContextRegistry` — a
60
+ * process-wide singleton that maps dataSource names to their
61
+ * `TransactionContext` instances. Not parameterised by dataSource:
62
+ * exactly one registry per process serves all adapters.
63
+ */
64
+ function getTransactionContextRegistryToken() {
65
+ return 'TransactionContextRegistry';
66
+ }
67
+ //# sourceMappingURL=token-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-utils.js","sourceRoot":"","sources":["../../src/tokens/token-utils.ts"],"names":[],"mappings":";;AAiCA,gEAIC;AAQD,gEAIC;AAOD,oEAIC;AAQD,gFAEC;AAtED,2CAAuD;AAEvD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;;;;GAQG;AACH,SAAgB,0BAA0B,CACxC,aAAqB,oCAAwB;IAE7C,OAAO,GAAG,UAAU,oBAAoB,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,0BAA0B,CACxC,aAAqB,oCAAwB;IAE7C,OAAO,GAAG,UAAU,oBAAoB,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,SAAgB,4BAA4B,CAC1C,aAAqB,oCAAwB;IAE7C,OAAO,GAAG,UAAU,sBAAsB,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,kCAAkC;IAChD,OAAO,4BAA4B,CAAC;AACtC,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Marker interface for domain events routed through the transactional
3
+ * event dispatcher. Purely structural — any value with a compatible shape
4
+ * satisfies it.
5
+ *
6
+ * Exists to document intent in handler and listener signatures and to keep
7
+ * cross-package type references consistent without importing
8
+ * `@nestjs/cqrs` into core.
9
+ */
10
+ export interface DomainEvent {
11
+ /**
12
+ * Wall-clock time at which the event was produced. Optional: some
13
+ * producers may omit it and let the dispatcher stamp it when the event
14
+ * is enqueued.
15
+ */
16
+ readonly occurredAt?: Date;
17
+ }
18
+ //# sourceMappingURL=domain-event.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=domain-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-event.js","sourceRoot":"","sources":["../../src/types/domain-event.ts"],"names":[],"mappings":""}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Base class for all errors thrown by `@nestjs-transactional` packages.
3
+ * Every subclass carries a stable {@link code} suitable for structured
4
+ * logging, metrics, and NestJS exception filters.
5
+ *
6
+ * The constructor sets `this.name` to the subclass name via `new.target`
7
+ * so that stack traces identify the concrete error type rather than
8
+ * generic `Error`.
9
+ */
10
+ export declare abstract class TransactionError extends Error {
11
+ /**
12
+ * Stable machine-readable error code. Part of the public contract —
13
+ * callers may rely on it for error handling; changes are breaking.
14
+ */
15
+ abstract readonly code: string;
16
+ constructor(message?: string);
17
+ }
18
+ /**
19
+ * Thrown when the current async context's transactional state does not
20
+ * satisfy the requested `PropagationMode`. Examples: `NEVER` invoked
21
+ * inside an active transaction; `MANDATORY` invoked outside of one; an
22
+ * adapter that does not support savepoints asked to run `NESTED`.
23
+ */
24
+ export declare class IllegalTransactionStateError extends TransactionError {
25
+ readonly code = "ILLEGAL_TRANSACTION_STATE";
26
+ }
27
+ /**
28
+ * Thrown when `TransactionManager.run` is asked to use an adapter
29
+ * (identified by type name + instance name) that was never registered
30
+ * with the core `AdapterRegistry`.
31
+ *
32
+ * The message lists both identifiers and points at the likely missing
33
+ * module registration so the fix is obvious from the stack trace.
34
+ */
35
+ export declare class TransactionAdapterNotFoundError extends TransactionError {
36
+ readonly code = "TRANSACTION_ADAPTER_NOT_FOUND";
37
+ readonly adapterName: string;
38
+ readonly instanceName: string;
39
+ constructor(adapterName: string, instanceName: string);
40
+ }
41
+ /**
42
+ * Thrown when an outbox producer fails to persist an event inside a
43
+ * transaction. Wrapping the underlying error lets callers distinguish
44
+ * outbox-write failures from business-logic errors when deciding on
45
+ * retry policy.
46
+ */
47
+ export declare class OutboxWriteError extends TransactionError {
48
+ readonly code = "OUTBOX_WRITE_ERROR";
49
+ }
50
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OutboxWriteError = exports.TransactionAdapterNotFoundError = exports.IllegalTransactionStateError = exports.TransactionError = void 0;
4
+ /**
5
+ * Base class for all errors thrown by `@nestjs-transactional` packages.
6
+ * Every subclass carries a stable {@link code} suitable for structured
7
+ * logging, metrics, and NestJS exception filters.
8
+ *
9
+ * The constructor sets `this.name` to the subclass name via `new.target`
10
+ * so that stack traces identify the concrete error type rather than
11
+ * generic `Error`.
12
+ */
13
+ class TransactionError extends Error {
14
+ constructor(message) {
15
+ super(message);
16
+ this.name = new.target.name;
17
+ }
18
+ }
19
+ exports.TransactionError = TransactionError;
20
+ /**
21
+ * Thrown when the current async context's transactional state does not
22
+ * satisfy the requested `PropagationMode`. Examples: `NEVER` invoked
23
+ * inside an active transaction; `MANDATORY` invoked outside of one; an
24
+ * adapter that does not support savepoints asked to run `NESTED`.
25
+ */
26
+ class IllegalTransactionStateError extends TransactionError {
27
+ code = 'ILLEGAL_TRANSACTION_STATE';
28
+ }
29
+ exports.IllegalTransactionStateError = IllegalTransactionStateError;
30
+ /**
31
+ * Thrown when `TransactionManager.run` is asked to use an adapter
32
+ * (identified by type name + instance name) that was never registered
33
+ * with the core `AdapterRegistry`.
34
+ *
35
+ * The message lists both identifiers and points at the likely missing
36
+ * module registration so the fix is obvious from the stack trace.
37
+ */
38
+ class TransactionAdapterNotFoundError extends TransactionError {
39
+ code = 'TRANSACTION_ADAPTER_NOT_FOUND';
40
+ adapterName;
41
+ instanceName;
42
+ constructor(adapterName, instanceName) {
43
+ super(`Transaction adapter not found: ${adapterName}:${instanceName}. ` +
44
+ `Did you register it via the corresponding transactional module ` +
45
+ `(e.g. TypeOrmTransactionalModule.forFeature())?`);
46
+ this.adapterName = adapterName;
47
+ this.instanceName = instanceName;
48
+ }
49
+ }
50
+ exports.TransactionAdapterNotFoundError = TransactionAdapterNotFoundError;
51
+ /**
52
+ * Thrown when an outbox producer fails to persist an event inside a
53
+ * transaction. Wrapping the underlying error lets callers distinguish
54
+ * outbox-write failures from business-logic errors when deciding on
55
+ * retry policy.
56
+ */
57
+ class OutboxWriteError extends TransactionError {
58
+ code = 'OUTBOX_WRITE_ERROR';
59
+ }
60
+ exports.OutboxWriteError = OutboxWriteError;
61
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,MAAsB,gBAAiB,SAAQ,KAAK;IAOlD,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAXD,4CAWC;AAED;;;;;GAKG;AACH,MAAa,4BAA6B,SAAQ,gBAAgB;IACvD,IAAI,GAAG,2BAA2B,CAAC;CAC7C;AAFD,oEAEC;AAED;;;;;;;GAOG;AACH,MAAa,+BAAgC,SAAQ,gBAAgB;IAC1D,IAAI,GAAG,+BAA+B,CAAC;IAEvC,WAAW,CAAS;IACpB,YAAY,CAAS;IAE9B,YAAY,WAAmB,EAAE,YAAoB;QACnD,KAAK,CACH,kCAAkC,WAAW,IAAI,YAAY,IAAI;YAC/D,iEAAiE;YACjE,iDAAiD,CACpD,CAAC;QACF,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF;AAfD,0EAeC;AAED;;;;;GAKG;AACH,MAAa,gBAAiB,SAAQ,gBAAgB;IAC3C,IAAI,GAAG,oBAAoB,CAAC;CACtC;AAFD,4CAEC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Standard SQL transaction isolation level, expressed as a string union
3
+ * rather than an enum — these values mirror an external protocol, and a
4
+ * union keeps them treatable as plain string literals in user code.
5
+ *
6
+ * Refer to the SQL standard (ISO/IEC 9075) for the precise read-phenomena
7
+ * guarantees of each level. Not every adapter/database supports every
8
+ * level; adapters map unsupported levels to an adapter-level error.
9
+ */
10
+ export type IsolationLevel = 'READ_UNCOMMITTED' | 'READ_COMMITTED' | 'REPEATABLE_READ' | 'SERIALIZABLE';
11
+ //# sourceMappingURL=isolation.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=isolation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isolation.js","sourceRoot":"","sources":["../../src/types/isolation.ts"],"names":[],"mappings":""}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Transaction propagation mode — how `@Transactional` behaves when invoked
3
+ * in the presence (or absence) of an already-active transaction.
4
+ *
5
+ * Modeled on Spring Framework's
6
+ * `org.springframework.transaction.annotation.Propagation`.
7
+ *
8
+ * @see https://docs.spring.io/spring-framework/reference/data-access/transaction/declarative/tx-propagation.html
9
+ */
10
+ export declare enum PropagationMode {
11
+ /**
12
+ * Join the current transaction if one exists; otherwise start a new one.
13
+ * The default mode — the common choice for business methods that want
14
+ * transactional safety without caring where they are called from.
15
+ */
16
+ REQUIRED = "REQUIRED",
17
+ /**
18
+ * Always start a new transaction, suspending the current one if present.
19
+ * The suspended transaction resumes when the new one completes (commit or
20
+ * rollback).
21
+ *
22
+ * Use for operations that must succeed or fail independently of the
23
+ * caller's transaction — e.g. audit logging that should persist even when
24
+ * the caller rolls back.
25
+ */
26
+ REQUIRES_NEW = "REQUIRES_NEW",
27
+ /**
28
+ * Run inside a nested transaction using `SAVEPOINT` semantics when a
29
+ * transaction is active. The nested scope can be rolled back without
30
+ * affecting the outer transaction.
31
+ *
32
+ * Requires adapter support for savepoints. On Postgres/MySQL via TypeORM
33
+ * this is implemented with `SAVEPOINT` / `ROLLBACK TO SAVEPOINT`.
34
+ *
35
+ * Outside of an existing transaction, behaves like {@link REQUIRED}.
36
+ */
37
+ NESTED = "NESTED",
38
+ /**
39
+ * Join the current transaction if one exists; otherwise run
40
+ * non-transactionally. Useful for read-oriented operations that should
41
+ * participate when called from a transactional context but not start
42
+ * one of their own.
43
+ */
44
+ SUPPORTS = "SUPPORTS",
45
+ /**
46
+ * Run non-transactionally, suspending the current transaction if one
47
+ * exists. The caller's transaction resumes after the method returns.
48
+ */
49
+ NOT_SUPPORTED = "NOT_SUPPORTED",
50
+ /**
51
+ * Run non-transactionally; throw `IllegalTransactionStateError` if a
52
+ * transaction is active. Use as an assertion that a method must not be
53
+ * invoked inside a transaction.
54
+ */
55
+ NEVER = "NEVER",
56
+ /**
57
+ * Join the current transaction if one exists; throw
58
+ * `IllegalTransactionStateError` if not. Use as an assertion that the
59
+ * caller must already be inside an active transaction.
60
+ */
61
+ MANDATORY = "MANDATORY"
62
+ }
63
+ //# sourceMappingURL=propagation.d.ts.map
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PropagationMode = void 0;
4
+ /**
5
+ * Transaction propagation mode — how `@Transactional` behaves when invoked
6
+ * in the presence (or absence) of an already-active transaction.
7
+ *
8
+ * Modeled on Spring Framework's
9
+ * `org.springframework.transaction.annotation.Propagation`.
10
+ *
11
+ * @see https://docs.spring.io/spring-framework/reference/data-access/transaction/declarative/tx-propagation.html
12
+ */
13
+ var PropagationMode;
14
+ (function (PropagationMode) {
15
+ /**
16
+ * Join the current transaction if one exists; otherwise start a new one.
17
+ * The default mode — the common choice for business methods that want
18
+ * transactional safety without caring where they are called from.
19
+ */
20
+ PropagationMode["REQUIRED"] = "REQUIRED";
21
+ /**
22
+ * Always start a new transaction, suspending the current one if present.
23
+ * The suspended transaction resumes when the new one completes (commit or
24
+ * rollback).
25
+ *
26
+ * Use for operations that must succeed or fail independently of the
27
+ * caller's transaction — e.g. audit logging that should persist even when
28
+ * the caller rolls back.
29
+ */
30
+ PropagationMode["REQUIRES_NEW"] = "REQUIRES_NEW";
31
+ /**
32
+ * Run inside a nested transaction using `SAVEPOINT` semantics when a
33
+ * transaction is active. The nested scope can be rolled back without
34
+ * affecting the outer transaction.
35
+ *
36
+ * Requires adapter support for savepoints. On Postgres/MySQL via TypeORM
37
+ * this is implemented with `SAVEPOINT` / `ROLLBACK TO SAVEPOINT`.
38
+ *
39
+ * Outside of an existing transaction, behaves like {@link REQUIRED}.
40
+ */
41
+ PropagationMode["NESTED"] = "NESTED";
42
+ /**
43
+ * Join the current transaction if one exists; otherwise run
44
+ * non-transactionally. Useful for read-oriented operations that should
45
+ * participate when called from a transactional context but not start
46
+ * one of their own.
47
+ */
48
+ PropagationMode["SUPPORTS"] = "SUPPORTS";
49
+ /**
50
+ * Run non-transactionally, suspending the current transaction if one
51
+ * exists. The caller's transaction resumes after the method returns.
52
+ */
53
+ PropagationMode["NOT_SUPPORTED"] = "NOT_SUPPORTED";
54
+ /**
55
+ * Run non-transactionally; throw `IllegalTransactionStateError` if a
56
+ * transaction is active. Use as an assertion that a method must not be
57
+ * invoked inside a transaction.
58
+ */
59
+ PropagationMode["NEVER"] = "NEVER";
60
+ /**
61
+ * Join the current transaction if one exists; throw
62
+ * `IllegalTransactionStateError` if not. Use as an assertion that the
63
+ * caller must already be inside an active transaction.
64
+ */
65
+ PropagationMode["MANDATORY"] = "MANDATORY";
66
+ })(PropagationMode || (exports.PropagationMode = PropagationMode = {}));
67
+ //# sourceMappingURL=propagation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propagation.js","sourceRoot":"","sources":["../../src/types/propagation.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,IAAY,eA0DX;AA1DD,WAAY,eAAe;IACzB;;;;OAIG;IACH,wCAAqB,CAAA;IAErB;;;;;;;;OAQG;IACH,gDAA6B,CAAA;IAE7B;;;;;;;;;OASG;IACH,oCAAiB,CAAA;IAEjB;;;;;OAKG;IACH,wCAAqB,CAAA;IAErB;;;OAGG;IACH,kDAA+B,CAAA;IAE/B;;;;OAIG;IACH,kCAAe,CAAA;IAEf;;;;OAIG;IACH,0CAAuB,CAAA;AACzB,CAAC,EA1DW,eAAe,+BAAf,eAAe,QA0D1B"}
@@ -0,0 +1,72 @@
1
+ import type { TransactionHandle } from './transaction-handle';
2
+ import type { TransactionOptions } from './transaction-options';
3
+ /**
4
+ * Port for ORM-specific transaction execution. Core defines this interface;
5
+ * each ORM integration package (for example
6
+ * `@nestjs-transactional/typeorm`) ships a concrete implementation.
7
+ *
8
+ * Adapters are deliberately minimal. The manager handles propagation,
9
+ * rollback classification, hook execution, and observability. Adapters only
10
+ * know how to execute a function inside a fresh transaction or a nested
11
+ * savepoint.
12
+ *
13
+ * @typeParam THandle - The adapter-specific handle type. Defaults to the
14
+ * base {@link TransactionHandle}; concrete adapters narrow this to their
15
+ * own extended handle (e.g. `TypeOrmTransactionHandle`).
16
+ */
17
+ export interface TransactionAdapter<THandle extends TransactionHandle = TransactionHandle> {
18
+ /**
19
+ * Adapter type identifier, e.g. `'typeorm'` or `'prisma'`. Used by the
20
+ * registry to route transactions to the correct adapter when
21
+ * `ExtendedTransactionOptions.adapter` is set.
22
+ */
23
+ readonly name: string;
24
+ /**
25
+ * Public dataSource name this adapter instance is bound to (DD-021).
26
+ * The single string identifier the multi-adapter API thinks in —
27
+ * `'default'`, `'billing'`, `'inventory'`, etc. Provided by the adapter
28
+ * (typically through its constructor) so consumers do not need to
29
+ * track adapter type and instance name separately.
30
+ *
31
+ * For backwards compatibility this is also the value used as the
32
+ * `instanceName` slot in {@link AdapterRegistration} when the adapter
33
+ * is auto-registered via `TransactionalModule.forRoot({ adapter })`.
34
+ */
35
+ readonly dataSourceName: string;
36
+ /**
37
+ * Execute `fn` inside a new transaction. The callback receives an opaque
38
+ * handle whose runtime type is the adapter-specific `THandle`.
39
+ *
40
+ * Contract:
41
+ * - If `fn` resolves, the adapter commits and returns the resolved value.
42
+ * - If `fn` rejects, the adapter rolls back and rethrows the error.
43
+ * - The adapter is responsible for transaction lifecycle only — hook
44
+ * firing, propagation logic, and rollback classification are the
45
+ * manager's job.
46
+ *
47
+ * @param options - Isolation, read-only flag, and timeout.
48
+ * @param fn - Async callback to execute inside the transaction.
49
+ * @returns The value resolved by `fn`.
50
+ */
51
+ runInTransaction<T>(options: TransactionOptions, fn: (handle: THandle) => Promise<T>): Promise<T>;
52
+ /**
53
+ * Execute `fn` inside a savepoint nested under `parent`. Used by the
54
+ * manager to implement `PropagationMode.NESTED`.
55
+ *
56
+ * Contract:
57
+ * - If `fn` resolves, the adapter releases the savepoint and returns
58
+ * the value.
59
+ * - If `fn` rejects, the adapter rolls back to the savepoint and
60
+ * rethrows the error.
61
+ * - The parent transaction is not affected by the inner rollback.
62
+ *
63
+ * Adapters that do not support savepoints should throw
64
+ * `IllegalTransactionStateError` with a clear, actionable message.
65
+ *
66
+ * @param parent - Handle of the enclosing transaction.
67
+ * @param fn - Async callback to execute inside the savepoint.
68
+ * @returns The value resolved by `fn`.
69
+ */
70
+ runInSavepoint<T>(parent: THandle, fn: (handle: THandle) => Promise<T>): Promise<T>;
71
+ }
72
+ //# sourceMappingURL=transaction-adapter.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=transaction-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-adapter.js","sourceRoot":"","sources":["../../src/types/transaction-adapter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Opaque handle returned by a `TransactionAdapter` while a transaction is
3
+ * active. Adapter implementations extend this interface with their own
4
+ * runtime fields (for example, the TypeORM adapter adds `entityManager`).
5
+ *
6
+ * Core code only sees {@link id} and {@link adapterName}; adapter-specific
7
+ * helpers cast to the narrower handle type to read their own fields.
8
+ */
9
+ export interface TransactionHandle {
10
+ /**
11
+ * Unique identifier of this transaction, assigned by the adapter on
12
+ * begin. Used by observability hooks, logging, and debugging to correlate
13
+ * events with a single transaction lifetime.
14
+ */
15
+ readonly id: string;
16
+ /**
17
+ * Name of the adapter that owns this handle. Matches the adapter's
18
+ * `name` property and the key under which it is registered in the
19
+ * `AdapterRegistry`.
20
+ */
21
+ readonly adapterName: string;
22
+ }
23
+ //# sourceMappingURL=transaction-handle.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=transaction-handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-handle.js","sourceRoot":"","sources":["../../src/types/transaction-handle.ts"],"names":[],"mappings":""}