@nathapp/nestjs-prisma 3.0.0 → 3.1.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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +186 -28
- package/CHANGELOG.md +33 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/prisma.interfaces.d.ts +1 -0
- package/dist/prisma.module.js +60 -4
- package/dist/prisma.module.js.map +1 -1
- package/dist/transaction/index.d.ts +2 -0
- package/dist/transaction/index.js +19 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction/prisma-transaction-manager.d.ts +13 -0
- package/dist/transaction/prisma-transaction-manager.js +49 -0
- package/dist/transaction/prisma-transaction-manager.js.map +1 -0
- package/dist/transaction/prisma-transaction.constants.d.ts +2 -0
- package/dist/transaction/prisma-transaction.constants.js +9 -0
- package/dist/transaction/prisma-transaction.constants.js.map +1 -0
- package/lib/index.ts +1 -0
- package/lib/prisma.interfaces.ts +9 -0
- package/lib/prisma.module.ts +76 -6
- package/lib/transaction/index.ts +2 -0
- package/lib/transaction/prisma-transaction-manager.ts +77 -0
- package/lib/transaction/prisma-transaction.constants.ts +13 -0
- package/package.json +3 -2
- package/test/prisma-transaction-manager.spec.ts +285 -0
- package/test/transparent-transaction.spec.ts +332 -0
package/.turbo/turbo-build.log
CHANGED
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,43 +1,201 @@
|
|
|
1
1
|
|
|
2
|
-
> @nathapp/nestjs-prisma@3.0.
|
|
2
|
+
> @nathapp/nestjs-prisma@3.0.1 test
|
|
3
3
|
> jest --config ./test/jest-test.json
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
PASS test/lifecycle.spec.ts (19.171 s)
|
|
8
|
-
FAIL test/pagination/paginate.spec.ts (19.04 s)
|
|
9
|
-
● Paginate › concurrent execution › should call findMany and count in parallel
|
|
5
|
+
FAIL test/transaction.spec.ts
|
|
6
|
+
● Test suite failed to run
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
Cannot find module './dist' from '../nestjs-common/index.js'
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
Require stack:
|
|
11
|
+
/home/ubuntu/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-common/index.js
|
|
12
|
+
lib/errors/prisma-error.mapper.ts
|
|
13
|
+
lib/prisma.service.ts
|
|
14
|
+
test/transaction.spec.ts
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
338 | expect(mockModel.count).toHaveBeenCalled();
|
|
22
|
-
339 | });
|
|
16
|
+
15 | };
|
|
17
|
+
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
> 17 | __exportStar(require("./dist"), exports);
|
|
19
|
+
| ^
|
|
20
|
+
18 |
|
|
23
21
|
|
|
24
|
-
at
|
|
22
|
+
at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:427:11)
|
|
23
|
+
at Object.<anonymous> (../nestjs-common/index.js:17:14)
|
|
24
|
+
at Object.<anonymous> (lib/errors/prisma-error.mapper.ts:1:1)
|
|
25
|
+
at Object.<anonymous> (lib/prisma.service.ts:3:1)
|
|
26
|
+
at Object.<anonymous> (test/transaction.spec.ts:2:1)
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
PASS test/prisma.decorator.spec.ts (19.261 s)
|
|
29
|
-
PASS test/error-mapping.spec.ts (9.508 s)
|
|
30
|
-
PASS test/prisma-exception-filter.spec.ts
|
|
28
|
+
FAIL test/prisma.module.spec.ts
|
|
29
|
+
● Test suite failed to run
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
Cannot find module './dist' from '../nestjs-common/index.js'
|
|
32
|
+
|
|
33
|
+
Require stack:
|
|
34
|
+
/home/ubuntu/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-common/index.js
|
|
35
|
+
lib/errors/prisma-error.mapper.ts
|
|
36
|
+
lib/prisma.service.ts
|
|
37
|
+
lib/prisma.module.ts
|
|
38
|
+
test/prisma.module.spec.ts
|
|
39
|
+
|
|
40
|
+
15 | };
|
|
41
|
+
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
> 17 | __exportStar(require("./dist"), exports);
|
|
43
|
+
| ^
|
|
44
|
+
18 |
|
|
45
|
+
|
|
46
|
+
at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:427:11)
|
|
47
|
+
at Object.<anonymous> (../nestjs-common/index.js:17:14)
|
|
48
|
+
at Object.<anonymous> (lib/errors/prisma-error.mapper.ts:1:1)
|
|
49
|
+
at Object.<anonymous> (lib/prisma.service.ts:3:1)
|
|
50
|
+
at Object.<anonymous> (lib/prisma.module.ts:3:1)
|
|
51
|
+
at Object.<anonymous> (test/prisma.module.spec.ts:3:1)
|
|
52
|
+
|
|
53
|
+
FAIL test/prisma.service.spec.ts
|
|
54
|
+
● Test suite failed to run
|
|
55
|
+
|
|
56
|
+
Cannot find module './dist' from '../nestjs-common/index.js'
|
|
57
|
+
|
|
58
|
+
Require stack:
|
|
59
|
+
/home/ubuntu/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-common/index.js
|
|
60
|
+
lib/errors/prisma-error.mapper.ts
|
|
61
|
+
lib/prisma.service.ts
|
|
62
|
+
test/prisma.service.spec.ts
|
|
63
|
+
|
|
64
|
+
15 | };
|
|
65
|
+
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
|
+
> 17 | __exportStar(require("./dist"), exports);
|
|
67
|
+
| ^
|
|
68
|
+
18 |
|
|
69
|
+
|
|
70
|
+
at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:427:11)
|
|
71
|
+
at Object.<anonymous> (../nestjs-common/index.js:17:14)
|
|
72
|
+
at Object.<anonymous> (lib/errors/prisma-error.mapper.ts:1:1)
|
|
73
|
+
at Object.<anonymous> (lib/prisma.service.ts:3:1)
|
|
74
|
+
at Object.<anonymous> (test/prisma.service.spec.ts:2:1)
|
|
75
|
+
|
|
76
|
+
FAIL test/lifecycle.spec.ts
|
|
77
|
+
● Test suite failed to run
|
|
78
|
+
|
|
79
|
+
Cannot find module './dist' from '../nestjs-common/index.js'
|
|
80
|
+
|
|
81
|
+
Require stack:
|
|
82
|
+
/home/ubuntu/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-common/index.js
|
|
83
|
+
lib/errors/prisma-error.mapper.ts
|
|
84
|
+
lib/prisma.service.ts
|
|
85
|
+
test/lifecycle.spec.ts
|
|
86
|
+
|
|
87
|
+
15 | };
|
|
88
|
+
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
|
89
|
+
> 17 | __exportStar(require("./dist"), exports);
|
|
90
|
+
| ^
|
|
91
|
+
18 |
|
|
92
|
+
|
|
93
|
+
at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:427:11)
|
|
94
|
+
at Object.<anonymous> (../nestjs-common/index.js:17:14)
|
|
95
|
+
at Object.<anonymous> (lib/errors/prisma-error.mapper.ts:1:1)
|
|
96
|
+
at Object.<anonymous> (lib/prisma.service.ts:3:1)
|
|
97
|
+
at Object.<anonymous> (test/lifecycle.spec.ts:2:1)
|
|
98
|
+
|
|
99
|
+
FAIL test/pagination/paginate.spec.ts
|
|
100
|
+
● Test suite failed to run
|
|
101
|
+
|
|
102
|
+
Cannot find module './dist' from '../nestjs-common/index.js'
|
|
103
|
+
|
|
104
|
+
Require stack:
|
|
105
|
+
/home/ubuntu/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-common/index.js
|
|
106
|
+
lib/pagination/paginate.ts
|
|
107
|
+
test/pagination/paginate.spec.ts
|
|
108
|
+
|
|
109
|
+
15 | };
|
|
110
|
+
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
|
111
|
+
> 17 | __exportStar(require("./dist"), exports);
|
|
112
|
+
| ^
|
|
113
|
+
18 |
|
|
114
|
+
|
|
115
|
+
at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:427:11)
|
|
116
|
+
at Object.<anonymous> (../nestjs-common/index.js:17:14)
|
|
117
|
+
at Object.<anonymous> (lib/pagination/paginate.ts:1:1)
|
|
118
|
+
at Object.<anonymous> (test/pagination/paginate.spec.ts:1:1)
|
|
119
|
+
|
|
120
|
+
FAIL test/prisma.decorator.spec.ts
|
|
121
|
+
● Test suite failed to run
|
|
122
|
+
|
|
123
|
+
Cannot find module './dist' from '../nestjs-common/index.js'
|
|
124
|
+
|
|
125
|
+
Require stack:
|
|
126
|
+
/home/ubuntu/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-common/index.js
|
|
127
|
+
lib/errors/prisma-error.mapper.ts
|
|
128
|
+
lib/prisma.service.ts
|
|
129
|
+
lib/prisma.module.ts
|
|
130
|
+
test/prisma.decorator.spec.ts
|
|
131
|
+
|
|
132
|
+
15 | };
|
|
133
|
+
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
|
134
|
+
> 17 | __exportStar(require("./dist"), exports);
|
|
135
|
+
| ^
|
|
136
|
+
18 |
|
|
137
|
+
|
|
138
|
+
at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:427:11)
|
|
139
|
+
at Object.<anonymous> (../nestjs-common/index.js:17:14)
|
|
140
|
+
at Object.<anonymous> (lib/errors/prisma-error.mapper.ts:1:1)
|
|
141
|
+
at Object.<anonymous> (lib/prisma.service.ts:3:1)
|
|
142
|
+
at Object.<anonymous> (lib/prisma.module.ts:3:1)
|
|
143
|
+
at Object.<anonymous> (test/prisma.decorator.spec.ts:4:1)
|
|
144
|
+
|
|
145
|
+
FAIL test/prisma-exception-filter.spec.ts
|
|
146
|
+
● Test suite failed to run
|
|
147
|
+
|
|
148
|
+
Cannot find module './dist' from '../nestjs-common/index.js'
|
|
149
|
+
|
|
150
|
+
Require stack:
|
|
151
|
+
/home/ubuntu/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-common/index.js
|
|
152
|
+
lib/errors/prisma-error.mapper.ts
|
|
153
|
+
lib/filter/prisma-exception.filter.ts
|
|
154
|
+
test/prisma-exception-filter.spec.ts
|
|
155
|
+
|
|
156
|
+
15 | };
|
|
157
|
+
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
|
158
|
+
> 17 | __exportStar(require("./dist"), exports);
|
|
159
|
+
| ^
|
|
160
|
+
18 |
|
|
161
|
+
|
|
162
|
+
at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:427:11)
|
|
163
|
+
at Object.<anonymous> (../nestjs-common/index.js:17:14)
|
|
164
|
+
at Object.<anonymous> (lib/errors/prisma-error.mapper.ts:1:1)
|
|
165
|
+
at Object.<anonymous> (lib/filter/prisma-exception.filter.ts:6:1)
|
|
166
|
+
at Object.<anonymous> (test/prisma-exception-filter.spec.ts:6:1)
|
|
167
|
+
|
|
168
|
+
FAIL test/error-mapping.spec.ts
|
|
169
|
+
● Test suite failed to run
|
|
170
|
+
|
|
171
|
+
Cannot find module './dist' from '../nestjs-common/index.js'
|
|
172
|
+
|
|
173
|
+
Require stack:
|
|
174
|
+
/home/ubuntu/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-common/index.js
|
|
175
|
+
test/error-mapping.spec.ts
|
|
176
|
+
|
|
177
|
+
15 | };
|
|
178
|
+
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
|
179
|
+
> 17 | __exportStar(require("./dist"), exports);
|
|
180
|
+
| ^
|
|
181
|
+
18 |
|
|
182
|
+
|
|
183
|
+
at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:427:11)
|
|
184
|
+
at Object.<anonymous> (../nestjs-common/index.js:17:14)
|
|
185
|
+
at Object.<anonymous> (test/error-mapping.spec.ts:1:1)
|
|
186
|
+
|
|
187
|
+
PASS test/prisma-transaction-manager.spec.ts
|
|
188
|
+
PASS test/prisma.health.spec.ts
|
|
189
|
+
|
|
190
|
+
Test Suites: 8 failed, 2 passed, 10 total
|
|
191
|
+
Tests: 37 passed, 37 total
|
|
34
192
|
Snapshots: 0 total
|
|
35
|
-
Time:
|
|
193
|
+
Time: 5.12 s
|
|
36
194
|
Ran all test suites.
|
|
37
195
|
npm error Lifecycle script `test` failed with error:
|
|
38
196
|
npm error code 1
|
|
39
|
-
npm error path /
|
|
40
|
-
npm error workspace @nathapp/nestjs-prisma@3.0.
|
|
41
|
-
npm error location /
|
|
197
|
+
npm error path /home/ubuntu/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-prisma
|
|
198
|
+
npm error workspace @nathapp/nestjs-prisma@3.0.1
|
|
199
|
+
npm error location /home/ubuntu/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-prisma
|
|
42
200
|
npm error command failed
|
|
43
201
|
npm error command sh -c jest --config ./test/jest-test.json
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @nathapp/nestjs-prisma
|
|
2
2
|
|
|
3
|
+
## 3.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- feat: add transparent transaction support via `transaction: true` option
|
|
8
|
+
|
|
9
|
+
**nestjs-prisma:**
|
|
10
|
+
|
|
11
|
+
- `PrismaModule.forRoot({ transaction: true })` wraps the injected client in a transparent proxy
|
|
12
|
+
- Repos automatically use the transaction client inside `txManager.run()` — no code changes needed
|
|
13
|
+
- Provides `TRANSACTION_MANAGER` token from `@nathapp/nestjs-data`
|
|
14
|
+
- `PrismaTransactionManager` accepts optional shared AsyncLocalStorage for proxy integration
|
|
15
|
+
|
|
16
|
+
**nestjs-typeorm:**
|
|
17
|
+
|
|
18
|
+
- `TypeOrmExModule.forRoot({ transaction: true })` provides `TRANSACTION_MANAGER` token
|
|
19
|
+
- TypeORM repos use explicit injection pattern (`@Optional() @Inject(TRANSACTION_MANAGER)`)
|
|
20
|
+
- Transparent proxy not feasible for TypeORM (repos hold manager references at creation time)
|
|
21
|
+
- `TypeOrmTransactionManager` accepts optional shared AsyncLocalStorage
|
|
22
|
+
|
|
23
|
+
## 3.0.1
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Add ITransactionManager interface and ORM-specific implementations
|
|
28
|
+
|
|
29
|
+
- **nestjs-data**: New package with `ITransactionManager` interface and `TRANSACTION_MANAGER` DI token for ORM-agnostic transaction management via AsyncLocalStorage
|
|
30
|
+
- **nestjs-prisma**: Add `PrismaTransactionManager` implementing `ITransactionManager` with Prisma interactive transactions
|
|
31
|
+
- **nestjs-typeorm**: Add `TypeOrmTransactionManager` implementing `ITransactionManager` with TypeORM QueryRunner transactions
|
|
32
|
+
|
|
33
|
+
- Updated dependencies
|
|
34
|
+
- @nathapp/nestjs-data@3.0.1
|
|
35
|
+
|
|
3
36
|
## 3.0.0
|
|
4
37
|
|
|
5
38
|
### Major Changes
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -24,4 +24,5 @@ __exportStar(require("./pagination"), exports);
|
|
|
24
24
|
__exportStar(require("./testing"), exports);
|
|
25
25
|
__exportStar(require("./errors/prisma-error.mapper"), exports);
|
|
26
26
|
__exportStar(require("./filter/prisma-exception.filter"), exports);
|
|
27
|
+
__exportStar(require("./transaction"), exports);
|
|
27
28
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sDAAoC;AACpC,kDAAgC;AAChC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,4CAA0B;AAC1B,+DAA6C;AAC7C,mEAAiD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sDAAoC;AACpC,kDAAgC;AAChC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,4CAA0B;AAC1B,+DAA6C;AAC7C,mEAAiD;AACjD,gDAA8B"}
|
package/dist/prisma.module.js
CHANGED
|
@@ -9,23 +9,71 @@ var PrismaModule_1;
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.PrismaModule = void 0;
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
|
+
const async_hooks_1 = require("async_hooks");
|
|
13
|
+
const nestjs_data_1 = require("@nathapp/nestjs-data");
|
|
12
14
|
const prisma_service_1 = require("./prisma.service");
|
|
15
|
+
const prisma_transaction_manager_1 = require("./transaction/prisma-transaction-manager");
|
|
13
16
|
const prisma_constants_1 = require("./prisma.constants");
|
|
17
|
+
const prisma_transaction_constants_1 = require("./transaction/prisma-transaction.constants");
|
|
18
|
+
function patchWithTransactionProxy(prismaService, als) {
|
|
19
|
+
const originalClient = prismaService.client;
|
|
20
|
+
const proxy = new Proxy(originalClient, {
|
|
21
|
+
get(target, prop, receiver) {
|
|
22
|
+
const txClient = als.getStore();
|
|
23
|
+
if (txClient)
|
|
24
|
+
return Reflect.get(txClient, prop, receiver);
|
|
25
|
+
return Reflect.get(target, prop, receiver);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(prismaService, 'client', {
|
|
29
|
+
get: () => proxy,
|
|
30
|
+
configurable: true,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
14
33
|
let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
15
34
|
static forRoot(options) {
|
|
16
|
-
const { isGlobal = true, name } = options;
|
|
35
|
+
const { isGlobal = true, name, transaction } = options;
|
|
17
36
|
const connectionToken = (0, prisma_constants_1.getPrismaToken)(name);
|
|
37
|
+
const providers = [];
|
|
38
|
+
let als;
|
|
39
|
+
if (transaction) {
|
|
40
|
+
als = new async_hooks_1.AsyncLocalStorage();
|
|
41
|
+
providers.push({
|
|
42
|
+
provide: prisma_transaction_constants_1.PRISMA_TRANSACTION_ALS,
|
|
43
|
+
useValue: als,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const capturedAls = als;
|
|
47
|
+
let originalClient;
|
|
18
48
|
const prismaServiceProvider = {
|
|
19
49
|
provide: connectionToken,
|
|
20
|
-
useFactory: () =>
|
|
50
|
+
useFactory: () => {
|
|
51
|
+
const service = new prisma_service_1.PrismaService(options);
|
|
52
|
+
if (capturedAls) {
|
|
53
|
+
originalClient = service.client;
|
|
54
|
+
patchWithTransactionProxy(service, capturedAls);
|
|
55
|
+
}
|
|
56
|
+
return service;
|
|
57
|
+
},
|
|
21
58
|
};
|
|
22
|
-
|
|
59
|
+
providers.push(prismaServiceProvider);
|
|
23
60
|
if (!name || name === 'default') {
|
|
24
61
|
providers.push({
|
|
25
62
|
provide: prisma_service_1.PrismaService,
|
|
26
63
|
useExisting: connectionToken,
|
|
27
64
|
});
|
|
28
65
|
}
|
|
66
|
+
if (transaction && capturedAls) {
|
|
67
|
+
providers.push({
|
|
68
|
+
provide: prisma_transaction_manager_1.PrismaTransactionManager,
|
|
69
|
+
useFactory: () => new prisma_transaction_manager_1.PrismaTransactionManager(originalClient, capturedAls),
|
|
70
|
+
inject: [connectionToken],
|
|
71
|
+
});
|
|
72
|
+
providers.push({
|
|
73
|
+
provide: nestjs_data_1.TRANSACTION_MANAGER,
|
|
74
|
+
useExisting: prisma_transaction_manager_1.PrismaTransactionManager,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
29
77
|
return {
|
|
30
78
|
module: PrismaModule_1,
|
|
31
79
|
global: isGlobal,
|
|
@@ -62,7 +110,15 @@ let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
|
62
110
|
},
|
|
63
111
|
{
|
|
64
112
|
provide: connectionToken,
|
|
65
|
-
useFactory: (moduleOptions) =>
|
|
113
|
+
useFactory: (moduleOptions) => {
|
|
114
|
+
const service = new prisma_service_1.PrismaService(moduleOptions);
|
|
115
|
+
if (moduleOptions.transaction) {
|
|
116
|
+
const als = new async_hooks_1.AsyncLocalStorage();
|
|
117
|
+
patchWithTransactionProxy(service, als);
|
|
118
|
+
service.__transactionAls = als;
|
|
119
|
+
}
|
|
120
|
+
return service;
|
|
121
|
+
},
|
|
66
122
|
inject: [prisma_constants_1.PRISMA_MODULE_OPTIONS],
|
|
67
123
|
},
|
|
68
124
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.module.js","sourceRoot":"","sources":["../lib/prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;
|
|
1
|
+
{"version":3,"file":"prisma.module.js","sourceRoot":"","sources":["../lib/prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,6CAAgD;AAChD,sDAA2D;AAE3D,qDAAiD;AACjD,yFAAoF;AACpF,yDAA2E;AAC3E,6FAAoF;AAMpF,SAAS,yBAAyB,CAChC,aAA+B,EAC/B,GAAwC;IAExC,MAAM,cAAc,GAAG,aAAa,CAAC,MAAM,CAAC;IAC5C,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,cAAc,EAAE;QACtC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;YAChC,IAAI,QAAQ;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC3D,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;KACF,C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,EAAE,CACzD,MAAM,cAAc,CAAC,mBAAmB,EAAE;oBAC5C,MAAM,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC;iBAC9B;gBACD;oBACE,OAAO,EAAE,eAAe;oBACxB,UAAU,EAAE,CAAC,aAAkC,EAAE,EAAE,CAAC,IAAI,8BAAa,CAAC,aAAa,CAAC;oBACpF,MAAM,EAAE,CAAC,wCAAqB,CAAC;iBAChC;aACF,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,qFAAqF,CAAC,CAAC;IACzG,CAAC;CACF,CAAA;AAxJY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,YAAY,CAwJxB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./prisma-transaction-manager"), exports);
|
|
18
|
+
__exportStar(require("./prisma-transaction.constants"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/transaction/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C;AAC7C,iEAA+C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
import { ITransactionManager } from '@nathapp/nestjs-data';
|
|
3
|
+
import { PrismaClientLike } from '../prisma.interfaces';
|
|
4
|
+
export declare class PrismaTransactionManager implements ITransactionManager {
|
|
5
|
+
private readonly prisma;
|
|
6
|
+
private readonly als;
|
|
7
|
+
constructor(prisma: PrismaClientLike & {
|
|
8
|
+
$transaction: Function;
|
|
9
|
+
}, externalAls?: AsyncLocalStorage<PrismaClientLike>);
|
|
10
|
+
run<T>(fn: () => Promise<T>): Promise<T>;
|
|
11
|
+
getClient<C = unknown>(): C;
|
|
12
|
+
isInTransaction(): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PrismaTransactionManager = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const async_hooks_1 = require("async_hooks");
|
|
18
|
+
const prisma_constants_1 = require("../prisma.constants");
|
|
19
|
+
const prisma_transaction_constants_1 = require("./prisma-transaction.constants");
|
|
20
|
+
let PrismaTransactionManager = class PrismaTransactionManager {
|
|
21
|
+
constructor(prisma, externalAls) {
|
|
22
|
+
this.prisma = prisma;
|
|
23
|
+
this.als = externalAls !== null && externalAls !== void 0 ? externalAls : new async_hooks_1.AsyncLocalStorage();
|
|
24
|
+
}
|
|
25
|
+
async run(fn) {
|
|
26
|
+
if (this.als.getStore()) {
|
|
27
|
+
return fn();
|
|
28
|
+
}
|
|
29
|
+
return this.prisma.$transaction(async (tx) => {
|
|
30
|
+
return this.als.run(tx, fn);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getClient() {
|
|
34
|
+
var _a;
|
|
35
|
+
return ((_a = this.als.getStore()) !== null && _a !== void 0 ? _a : this.prisma);
|
|
36
|
+
}
|
|
37
|
+
isInTransaction() {
|
|
38
|
+
return this.als.getStore() !== undefined;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.PrismaTransactionManager = PrismaTransactionManager;
|
|
42
|
+
exports.PrismaTransactionManager = PrismaTransactionManager = __decorate([
|
|
43
|
+
(0, common_1.Injectable)(),
|
|
44
|
+
__param(0, (0, common_1.Inject)((0, prisma_constants_1.getPrismaToken)())),
|
|
45
|
+
__param(1, (0, common_1.Optional)()),
|
|
46
|
+
__param(1, (0, common_1.Inject)(prisma_transaction_constants_1.PRISMA_TRANSACTION_ALS)),
|
|
47
|
+
__metadata("design:paramtypes", [Object, async_hooks_1.AsyncLocalStorage])
|
|
48
|
+
], PrismaTransactionManager);
|
|
49
|
+
//# sourceMappingURL=prisma-transaction-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma-transaction-manager.js","sourceRoot":"","s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true });
|
|
3
|
+
exports.getPrismaTransactionAlsToken = exports.PRISMA_TRANSACTION_ALS = void 0;
|
|
4
|
+
exports.PRISMA_TRANSACTION_ALS = Symbol('PRISMA_TRANSACTION_ALS');
|
|
5
|
+
const getPrismaTransactionAlsToken = (name) => name && name !== 'default'
|
|
6
|
+
? `PRISMA_TRANSACTION_ALS_${name}`
|
|
7
|
+
: exports.PRISMA_TRANSACTION_ALS;
|
|
8
|
+
exports.getPrismaTransactionAlsToken = getPrismaTransactionAlsToken;
|
|
9
|
+
//# sourceMappingURL=prisma-transaction.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma-transaction.constants.js","sourceRoot":"","sources":["../../lib/transaction/prisma-transaction.constants.ts"],"names":[],"mappings":";;;AAIa,QAAA,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAKhE,MAAM,4BAA4B,GAAG,CAAC,IAAa,EAAmB,EAAE,CAC7E,IAAI,IAAI,IAAI,KAAK,SAAS;IACxB,CAAC,CAAC,0BAA0B,IAAI,EAAE;IAClC,CAAC,CAAC,8BAA6B,CAAC;AAHvB,QAAA,4BAA4B,gCAGL"}
|
package/lib/index.ts
CHANGED
package/lib/prisma.interfaces.ts
CHANGED
|
@@ -25,6 +25,15 @@ export interface PrismaModuleOptions {
|
|
|
25
25
|
|
|
26
26
|
/** Enable logging of Prisma queries. Default: false */
|
|
27
27
|
logging?: boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Enable transparent transaction support.
|
|
31
|
+
* When true, the injected Prisma client is wrapped in a proxy that
|
|
32
|
+
* automatically resolves to the transaction client inside `txManager.run()`.
|
|
33
|
+
* Also provides TRANSACTION_MANAGER token.
|
|
34
|
+
* Default: false
|
|
35
|
+
*/
|
|
36
|
+
transaction?: boolean;
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
export interface PrismaModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|