@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,88 @@
1
+ import type { Type } from '@nestjs/common';
2
+ import type { IsolationLevel } from './isolation';
3
+ import type { PropagationMode } from './propagation';
4
+ /**
5
+ * Options passed by the core runtime down into an adapter's
6
+ * `runInTransaction`. They describe the per-transaction runtime parameters
7
+ * that are meaningful to the adapter itself — propagation, rollback rules,
8
+ * and adapter selection are handled at the manager level and never reach
9
+ * the adapter.
10
+ */
11
+ export interface TransactionOptions {
12
+ /**
13
+ * SQL isolation level for the transaction. Omit to use the adapter's
14
+ * default (typically the database default, e.g. `READ_COMMITTED` on
15
+ * Postgres).
16
+ */
17
+ readonly isolation?: IsolationLevel;
18
+ /**
19
+ * Hint that the transaction will only issue reads. Adapters may use this
20
+ * to route to a read replica or to issue `SET TRANSACTION READ ONLY`.
21
+ * It is a hint, not an enforcement — writes may still be attempted and
22
+ * may be rejected by the database.
23
+ */
24
+ readonly readOnly?: boolean;
25
+ /**
26
+ * Transaction timeout in milliseconds. If the adapter supports
27
+ * transaction-level timeouts (e.g. `statement_timeout` on Postgres),
28
+ * exceeding this triggers a rollback. Omit for no timeout.
29
+ */
30
+ readonly timeout?: number;
31
+ }
32
+ /**
33
+ * Options accepted by `TransactionManager.run` and by the `@Transactional`
34
+ * decorator. Extends {@link TransactionOptions} with manager-level
35
+ * concerns: which adapter to use, propagation, and rollback classification.
36
+ */
37
+ export interface ExtendedTransactionOptions extends TransactionOptions {
38
+ /**
39
+ * Name of the adapter type to use, e.g. `'typeorm'` or `'prisma'`.
40
+ * Select explicitly when multiple adapter types are registered in the
41
+ * same application. If omitted, the default adapter (as configured in
42
+ * `TransactionalModule.forRoot`) is used.
43
+ */
44
+ readonly adapter?: string;
45
+ /**
46
+ * Name of the specific adapter instance to use, e.g. `'primary'` or
47
+ * `'billing'`. Used for multi-datasource setups where the same adapter
48
+ * type is registered against multiple DataSources. If omitted, the
49
+ * instance registered with `isDefault: true` is used.
50
+ *
51
+ * Prefer {@link ExtendedTransactionOptions.dataSource} for new code —
52
+ * it identifies the dataSource directly without needing to also know
53
+ * the adapter type. `adapterInstance` is preserved for backwards
54
+ * compatibility with single-adapter call sites.
55
+ */
56
+ readonly adapterInstance?: string;
57
+ /**
58
+ * Public dataSource name to target (DD-020). When set, the manager
59
+ * resolves the adapter via {@link AdapterRegistry.getByDataSource}
60
+ * and uses this name as the active-transaction Map key suffix —
61
+ * cross-dataSource enrolment is structurally impossible (DD-023).
62
+ *
63
+ * Mutually exclusive with the `adapter` / `adapterInstance` pair —
64
+ * if `dataSource` is set, the others are ignored. If omitted, the
65
+ * legacy resolution path (`adapter` + `adapterInstance`, falling
66
+ * back to registry defaults) is used. Single-adapter consumers
67
+ * never need to set this explicitly.
68
+ */
69
+ readonly dataSource?: string;
70
+ /**
71
+ * How this transaction should relate to an already-active transaction
72
+ * on the current async context. Defaults to {@link PropagationMode.REQUIRED}.
73
+ */
74
+ readonly propagation?: PropagationMode;
75
+ /**
76
+ * Error classes that should trigger a rollback even when the default
77
+ * classification would not. An empty or omitted list means the default
78
+ * policy: roll back on any thrown error.
79
+ */
80
+ readonly rollbackFor?: readonly Type<Error>[];
81
+ /**
82
+ * Error classes that should NOT trigger a rollback. When a thrown error
83
+ * is an instance of any class in this list, the transaction is committed
84
+ * and the error is rethrown to the caller.
85
+ */
86
+ readonly noRollbackFor?: readonly Type<Error>[];
87
+ }
88
+ //# sourceMappingURL=transaction-options.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=transaction-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-options.js","sourceRoot":"","sources":["../../src/types/transaction-options.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@nestjs-transactional/core",
3
+ "version": "1.0.0-alpha.0",
4
+ "description": "Declarative transaction management for NestJS — core primitives (AsyncLocalStorage context, TransactionManager, @Transactional decorator, adapter port)",
5
+ "license": "MIT",
6
+ "author": "Igor Golovanov",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/igorgolovanov/nestjs-transactional.git",
10
+ "directory": "packages/core"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/igorgolovanov/nestjs-transactional/issues"
14
+ },
15
+ "homepage": "https://github.com/igorgolovanov/nestjs-transactional/tree/main/packages/core#readme",
16
+ "keywords": [
17
+ "nestjs",
18
+ "transaction",
19
+ "transactional",
20
+ "spring",
21
+ "async-local-storage",
22
+ "declarative"
23
+ ],
24
+ "engines": {
25
+ "node": ">=22.11.0"
26
+ },
27
+ "main": "dist/index.js",
28
+ "types": "dist/index.d.ts",
29
+ "files": [
30
+ "dist/**/*.js",
31
+ "dist/**/*.d.ts",
32
+ "dist/**/*.js.map",
33
+ "!dist/**/*.spec.*"
34
+ ],
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "default": "./dist/index.js"
39
+ },
40
+ "./testing": {
41
+ "types": "./dist/testing/index.d.ts",
42
+ "default": "./dist/testing/index.js"
43
+ }
44
+ },
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "provenance": true
48
+ },
49
+ "peerDependencies": {
50
+ "@nestjs/common": "^10.0.0 || ^11.0.0",
51
+ "@nestjs/core": "^10.0.0 || ^11.0.0",
52
+ "reflect-metadata": "^0.1.13 || ^0.2.0",
53
+ "rxjs": "^7.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "@nestjs/common": "^11.0.0",
57
+ "@nestjs/core": "^11.0.0",
58
+ "@nestjs/platform-express": "^11.0.0",
59
+ "@nestjs/testing": "^11.0.0",
60
+ "@types/supertest": "^6.0.2",
61
+ "reflect-metadata": "^0.2.2",
62
+ "rxjs": "^7.8.1",
63
+ "supertest": "^7.0.0"
64
+ },
65
+ "scripts": {
66
+ "build": "tsc -p tsconfig.build.json",
67
+ "clean": "rimraf dist *.tsbuildinfo coverage",
68
+ "test": "jest",
69
+ "test:watch": "jest --watch",
70
+ "test:cov": "jest --coverage",
71
+ "type-check": "tsc --noEmit",
72
+ "lint": "eslint \"src/**/*.ts\""
73
+ }
74
+ }