@nathapp/nestjs-prisma 4.0.0 → 4.0.1

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 (43) hide show
  1. package/package.json +4 -4
  2. package/.eslintrc.js +0 -8
  3. package/.turbo/turbo-build.log +0 -4
  4. package/CHANGELOG.md +0 -314
  5. package/docs/20260215-fix-plan-prisma.md +0 -37
  6. package/docs/20260215-review-prisma.md +0 -598
  7. package/docs/20260216-plan-prisma-a-minus.md +0 -70
  8. package/lib/errors/prisma-error.mapper.ts +0 -164
  9. package/lib/filter/prisma-exception.filter.ts +0 -67
  10. package/lib/index.ts +0 -12
  11. package/lib/pagination/index.ts +0 -1
  12. package/lib/pagination/paginate.ts +0 -44
  13. package/lib/prisma.constants.ts +0 -40
  14. package/lib/prisma.decorator.ts +0 -8
  15. package/lib/prisma.health.ts +0 -40
  16. package/lib/prisma.interfaces.ts +0 -51
  17. package/lib/prisma.module.ts +0 -281
  18. package/lib/prisma.service.ts +0 -179
  19. package/lib/repository/abstract-prisma.repository.ts +0 -138
  20. package/lib/repository/index.ts +0 -1
  21. package/lib/testing/index.ts +0 -1
  22. package/lib/testing/prisma-testing.utils.ts +0 -29
  23. package/lib/transaction/index.ts +0 -2
  24. package/lib/transaction/prisma-transaction-manager.ts +0 -77
  25. package/lib/transaction/prisma-transaction.constants.ts +0 -29
  26. package/test/error-mapping.spec.ts +0 -231
  27. package/test/jest-nax.json +0 -27
  28. package/test/jest-test.json +0 -29
  29. package/test/lifecycle.spec.ts +0 -241
  30. package/test/multi-db-als.spec.ts +0 -142
  31. package/test/multi-db-transaction.spec.ts +0 -75
  32. package/test/pagination/paginate.spec.ts +0 -359
  33. package/test/prisma-exception-filter.spec.ts +0 -213
  34. package/test/prisma-transaction-manager.spec.ts +0 -285
  35. package/test/prisma.decorator.spec.ts +0 -257
  36. package/test/prisma.health.spec.ts +0 -226
  37. package/test/prisma.module.spec.ts +0 -506
  38. package/test/prisma.service.spec.ts +0 -359
  39. package/test/repository/abstract-prisma.repository.spec.ts +0 -157
  40. package/test/transaction-manager-e2e.spec.ts +0 -496
  41. package/test/transaction.spec.ts +0 -371
  42. package/test/transparent-transaction.spec.ts +0 -500
  43. package/tsconfig.json +0 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathapp/nestjs-prisma",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "NestJS Prisma integration with multi-database support",
5
5
  "scripts": {
6
6
  "clean": "rimraf dist/ .turbo/",
@@ -19,13 +19,13 @@
19
19
  "types": "dist/index.d.ts",
20
20
  "main": "dist/index.js",
21
21
  "dependencies": {
22
- "@nathapp/nestjs-common": "^4.0.0",
23
- "@nathapp/nestjs-data": "^4.0.0"
22
+ "@nathapp/nestjs-common": "^4.0.1",
23
+ "@nathapp/nestjs-data": "^4.0.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@nathapp/eslint-config": "1.0.1",
27
27
  "@nathapp/typescript-config": "1.0.1",
28
- "@golevelup/ts-jest": "^0.6.1",
28
+ "@golevelup/ts-jest": "^3.0.0",
29
29
  "eslint": "^8.57.0",
30
30
  "typescript": "^5"
31
31
  },
package/.eslintrc.js DELETED
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: ["@nathapp/eslint-config/library.js"],
4
- parser: "@typescript-eslint/parser",
5
- parserOptions: {
6
- project: true,
7
- },
8
- };
@@ -1,4 +0,0 @@
1
-
2
- > @nathapp/nestjs-prisma@4.0.0 build
3
- > rimraf dist && tsc -p tsconfig.json
4
-
package/CHANGELOG.md DELETED
@@ -1,314 +0,0 @@
1
- # @nathapp/nestjs-prisma
2
-
3
- ## 4.0.0
4
-
5
- ### Major Changes
6
-
7
- - 2319e9d: BREAKING: drop NestJS 8/9 peer ranges and require Node ^20.19.0 || >=22.12.0. Support NestJS 12. Peer ranges now cover NestJS 10, 11 and 12 (Node ^20.19.0 || >=22.12.0 is required because NestJS 12 is ESM-only). The configurable module builder no longer deep-imports a directory that is unresolvable on NestJS 12, and TwoFactorGuard / TwoFactorForceGuard redeclare their constructor DI metadata because NestJS 12 no longer inherits @Optional() from base classes.
8
-
9
- Other consumer-facing changes:
10
-
11
- - `@nathapp/nestjs-health`: `@nestjs/terminus` moved from `dependencies` to `peerDependencies` (`^11.0.0 || ^12.0.0`) so NestJS 12 apps can use terminus 12. Install `@nestjs/terminus` in your app.
12
- - Optional-package loading (`loadPackage`) now throws a descriptive `Error` (original error on `cause`) instead of logging and calling `process.exit(1)` when an optional package is missing.
13
-
14
- ### Patch Changes
15
-
16
- - Updated dependencies [668055b]
17
- - Updated dependencies [2319e9d]
18
- - @nathapp/nestjs-common@4.0.0
19
- - @nathapp/nestjs-data@4.0.0
20
-
21
- ## 4.0.0-rc.0
22
-
23
- ### Major Changes
24
-
25
- - c3aeb46: BREAKING: drop NestJS 8/9 peer ranges and require Node ^20.19.0 || >=22.12.0. Support NestJS 12. Peer ranges now cover NestJS 10, 11 and 12 (Node ^20.19.0 || >=22.12.0 is required because NestJS 12 is ESM-only). The configurable module builder no longer deep-imports a directory that is unresolvable on NestJS 12, and TwoFactorGuard / TwoFactorForceGuard redeclare their constructor DI metadata because NestJS 12 no longer inherits @Optional() from base classes.
26
-
27
- Other consumer-facing changes:
28
-
29
- - `@nathapp/nestjs-health`: `@nestjs/terminus` moved from `dependencies` to `peerDependencies` (`^11.0.0 || ^12.0.0`) so NestJS 12 apps can use terminus 12. Install `@nestjs/terminus` in your app.
30
- - Optional-package loading (`loadPackage`) now throws a descriptive `Error` (original error on `cause`) instead of logging and calling `process.exit(1)` when an optional package is missing.
31
-
32
- ### Patch Changes
33
-
34
- - Updated dependencies [c3aeb46]
35
- - @nathapp/nestjs-common@4.0.0-rc.0
36
- - @nathapp/nestjs-data@4.0.0-rc.0
37
-
38
- ## 3.3.0
39
-
40
- ### Patch Changes
41
-
42
- - @nathapp/nestjs-common@3.3.0
43
- - @nathapp/nestjs-data@3.3.0
44
-
45
- ## 3.2.2
46
-
47
- ### Patch Changes
48
-
49
- - 73d5885: Comprehensive code review of the entire NestJS monorepo covering security, memory leaks, performance, and correctness bugs. All CRITICAL/HIGH/MEDIUM findings fixed; only LOW findings remain.
50
-
51
- ### Security Fixes
52
-
53
- - **nestjs-typeorm**: `DatabaseErrorMapper` now strips raw DB error details (`originalError`, `dbCode`, `dbErrno`) from `AppException.args` — these are logged server-side instead of exposed in HTTP responses
54
- - **nestjs-notification**: `EmailProvider` now extracts `err.message` instead of `JSON.stringify(err)` (which always returned `"{}"` for Error objects)
55
- - **nestjs-common**: `createAsyncOptionsProvider` throws on invalid async options instead of silently returning a broken provider
56
- - **nestjs-queue**: RabbitMQ provider logs and re-queues sanitized error messages (strips raw stack traces from DLQ metadata)
57
- - **nestjs-storage**: OSS callback validates pub-key URL prefix before fetching (prevents SSRF)
58
-
59
- ### Memory Leak Fixes
60
-
61
- - **nestjs-notification**: `UserTokenStore.addToken()` was pushing to a local array copy without calling `cache.set()` — tokens were lost immediately after being added
62
- - **nestjs-cache**: Validated config warning uses NestJS `Logger` (not `console.warn`) for consistent log routing
63
- - **nestjs-common**: `RequestIpSecurity` uses NestJS `Logger` instead of `console.warn`
64
- - **nestjs-queue**: BullMQ/Kafka/RabbitMQ providers properly clean up workers, event listeners, and queues in `close()`
65
-
66
- ### Bug Fixes
67
-
68
- - **nestjs-queue**: Restored BullMQ branch in idempotency provider switch (was accidentally removed)
69
- - **nestjs-queue**: RabbitMQ `resume()` remains warn-only — does not throw (interface contract)
70
- - **nestjs-auth**: JWT refresh strategy passes `undefined` (not `{}`) as req when `passReqToCallback=false`
71
- - **nestjs-microservices**: `canActivateGrpc` now calls `strategyProvider.validate()` and sets `request.user = principal` (not raw JWT payload)
72
- - **nestjs-storage**: OSS callback signature verification stays on RSA-MD5 (Alibaba OSS protocol mandates MD5)
73
-
74
- ### Code Quality
75
-
76
- - **nestjs-common**: `sanitizeHeader` strips non-word characters (spaces become empty) — documented in tests
77
- - **nestjs-common**: `isValidLocaleCode` enforces strict `xx_XX` format (bare `en` is invalid)
78
- - **nestjs-queue**: TypeScript union casts use `as unknown as T` pattern to avoid overlap errors
79
-
80
- - Updated dependencies [73d5885]
81
- - @nathapp/nestjs-common@3.2.3
82
-
83
- ## 3.2.1
84
-
85
- ### Patch Changes
86
-
87
- - 0610b83: Fix Exception Bug on nestjs-common
88
- - Updated dependencies [0610b83]
89
- - @nathapp/nestjs-common@3.2.1
90
- - @nathapp/nestjs-data@3.2.1
91
-
92
- ## 3.2.0
93
-
94
- ### Minor Changes
95
-
96
- - 1876b9a: ### nestjs-auth
97
-
98
- - Add JWKS support via `JwksJwtStrategyProvider` and `createJwksStrategyProvider` factory — enables remote key resolution through `jwks-rsa` (optional peer dep)
99
- - Add `validateJwksOptions` security guard and `JwksOptions` interface
100
- - Export `JwksJwtStrategyProvider` and `JwksOptions` from the public API
101
- - Fix permission guard and JWT module immutability issues from code review
102
-
103
- ### nestjs-typeorm
104
-
105
- - Add `AbstractTypeOrmRepository<TDomain, TEntity, TId>` — portable `IRepository` implementation decoupled from TypeORM internals
106
- - Add `TYPEORM_TRANSACTION_ALS` DI token and publish it from `forRoot`/`forRootAsync`
107
- - `forCustomRepository` now instantiates `AbstractTypeOrmRepository` subclasses with the correct per-DataSource tx manager token
108
- - Add `getTypeOrmTransactionManagerToken(name?)` helper for multi-DataSource wiring
109
- - Named DataSource tx tokens no longer collide; default DataSource still aliases the global `TRANSACTION_MANAGER` symbol
110
-
111
- ### nestjs-prisma
112
-
113
- - Add `getPrismaTransactionManagerToken(name?)` helper for multi-DataSource wiring
114
- - `forRoot` / `forRootAsync` register named tx manager token + default-only guard to prevent collision
115
-
116
- ### nestjs-data
117
-
118
- - Add `IRepository<TDomain, TId>` portable repository contract
119
- - Fix missing `@nathapp/nestjs-common` peer dep for turborepo build resolution
120
-
121
- ### nestjs-common
122
-
123
- - Add `request-ip` utility for extracting client IP across Express and Fastify adapters
124
-
125
- ### nestjs-cache
126
-
127
- - Fix cache interceptor, cache manager, and cache tag registry immutability and type issues
128
-
129
- ### nestjs-app
130
-
131
- - Fix `nathapp.ts` and `app-factory.ts` code review findings (immutability, error handling)
132
-
133
- ### nestjs-queue
134
-
135
- - Upgrade `uuid` dependency from `^9.0.0` to `^11.1.1` (security)
136
- - Fix BullMQ health check to use `IRedisClient.info()` (aligned with BullMQ interface)
137
-
138
- ### nestjs-notification
139
-
140
- - Upgrade `nodemailer` dev dep from `^7` to `^8` — resolves SMTP command injection CVEs (GHSA-c7w3-x93f-qmm8, GHSA-vvjj-xcjg-gr5g)
141
-
142
- ### nestjs-storage
143
-
144
- - Fix code review findings (immutability, validation)
145
-
146
- ### nestjs-throttler
147
-
148
- - Fix code review findings
149
-
150
- ### All packages
151
-
152
- - Upgrade AJV to v8 (removes root override that broke `@fastify/ajv-compiler`)
153
- - Align all package versions to 3.1.3 as baseline for this minor release
154
-
155
- ### Patch Changes
156
-
157
- - Updated dependencies [1876b9a]
158
- - @nathapp/nestjs-common@3.2.0
159
- - @nathapp/nestjs-data@3.2.0
160
-
161
- ## 3.1.3
162
-
163
- ### Patch Changes
164
-
165
- - a48beb2: transaction manager symbol bug fix
166
- - Updated dependencies [a48beb2]
167
- - @nathapp/nestjs-data@3.0.4
168
-
169
- ## 3.1.2
170
-
171
- ### Patch Changes
172
-
173
- - cb97b64: fix typeorm and transactionManager issue
174
- - Updated dependencies [cb97b64]
175
- - @nathapp/nestjs-data@3.0.3
176
-
177
- ## 3.1.1
178
-
179
- ### Patch Changes
180
-
181
- - a448f5b: add irepository and abstract repository
182
- - Updated dependencies [a448f5b]
183
- - @nathapp/nestjs-data@3.0.2
184
-
185
- ## 3.1.0
186
-
187
- ### Minor Changes
188
-
189
- - feat: add transparent transaction support via `transaction: true` option
190
-
191
- **nestjs-prisma:**
192
-
193
- - `PrismaModule.forRoot({ transaction: true })` wraps the injected client in a transparent proxy
194
- - Repos automatically use the transaction client inside `txManager.run()` — no code changes needed
195
- - Provides `TRANSACTION_MANAGER` token from `@nathapp/nestjs-data`
196
- - `PrismaTransactionManager` accepts optional shared AsyncLocalStorage for proxy integration
197
-
198
- **nestjs-typeorm:**
199
-
200
- - `TypeOrmExModule.forRoot({ transaction: true })` provides `TRANSACTION_MANAGER` token
201
- - TypeORM repos use explicit injection pattern (`@Optional() @Inject(TRANSACTION_MANAGER)`)
202
- - Transparent proxy not feasible for TypeORM (repos hold manager references at creation time)
203
- - `TypeOrmTransactionManager` accepts optional shared AsyncLocalStorage
204
-
205
- ## 3.0.1
206
-
207
- ### Patch Changes
208
-
209
- - Add ITransactionManager interface and ORM-specific implementations
210
-
211
- - **nestjs-data**: New package with `ITransactionManager` interface and `TRANSACTION_MANAGER` DI token for ORM-agnostic transaction management via AsyncLocalStorage
212
- - **nestjs-prisma**: Add `PrismaTransactionManager` implementing `ITransactionManager` with Prisma interactive transactions
213
- - **nestjs-typeorm**: Add `TypeOrmTransactionManager` implementing `ITransactionManager` with TypeORM QueryRunner transactions
214
-
215
- - Updated dependencies
216
- - @nathapp/nestjs-data@3.0.1
217
-
218
- ## 3.0.0
219
-
220
- ### Major Changes
221
-
222
- - 86a36b8: # 🚀 v3.0.0 Monorepo Enterprise Upgrade
223
-
224
- This release brings significant security hardening, strict typing, improved observability, and comprehensive documentation across the entire Nathapp NestJS ecosystem.
225
-
226
- ## ⚠️ Breaking Changes
227
-
228
- ### nestjs-common
229
-
230
- - **Trust Proxy (Fail-Closed)**: Trust proxy is now disabled by default. Production deployments behind a reverse proxy MUST configure `trustedProxies` or use a preset (`cloudflare`, `aws-alb`, `nginx-local`, etc.). See `docs/trust-proxy-security.md`.
231
- - **SerializableInterceptor**: Now uses pure transformation — original response objects are no longer mutated. Primitives in arrays are preserved correctly.
232
- - **AppException**: Now generic `AppException<T>` for strict argument typing.
233
-
234
- ### nestjs-logging
235
-
236
- - **Redaction**: Default redact paths are now constrained to 3 levels deep (`*.*.key`).
237
- - **Structured Logs**: Standardized field names for ELK/Loki/Datadog compatibility.
238
- - **Graceful Drain**: Logger now implements `OnModuleDestroy` to flush pending writes on shutdown.
239
-
240
- ### nestjs-typeorm
241
-
242
- - **Connection Validation**: `TypeOrmExModule.forRoot()` now throws `"Connection Not Supported"` when no valid connection type is provided (previously defaulted silently to MySQL).
243
-
244
- ## 🔒 Security
245
-
246
- - **nestjs-common**: Trust proxy fail-closed default prevents IP spoofing when misconfigured. Comprehensive security documentation with provider presets.
247
- - **nestjs-storage**: GDrive refreshToken security best practices documented. Provider capability matrix added.
248
- - **nestjs-throttler**: Documented that `getTracker()` executes synchronously — no async TOCTOU race condition in rate limiting.
249
- - **nestjs-typeorm**: Stored procedure name validation with whitelist pattern (`/^[a-zA-Z_][a-zA-Z0-9_.]*$/`) prevents SQL injection.
250
- - **nestjs-cache**: Tag registry now receives TTL for proper expiration of tag-to-key mappings.
251
- - **nestjs-microservices**: Fixed gRPC Bearer token extraction whitespace bug. Full test coverage for all guards.
252
- - **nestjs-auth-2fa**: Timing-safe TOTP verification prevents timing attacks.
253
-
254
- ## ✨ Features & Improvements
255
-
256
- - **nestjs-storage**: Added native support for **Azure Blob Storage** and **Google Cloud Storage**. Provider capability matrix documents supported methods per provider.
257
- - **nestjs-microservices**: Full guard coverage (100%), Service Identity JWT + HMAC authentication, `ServicePermissionRegistry` for fine-grained access control.
258
- - **nestjs-typeorm**: Automatic mapping of database errors to `AppException` via `TypeOrmExceptionFilter`.
259
- - **nestjs-auth-2fa**: `BaseTwoFactorGuard` with flexible policy engine. DI-aware provider factory with comprehensive architectural documentation.
260
- - **nestjs-cache**: Deep-cloning of cached objects to prevent cross-request state leakage. Touch fallback avoided for distributed strategies (race condition prevention).
261
- - **nestjs-queue**: Race-condition fixes in BullMQ/RabbitMQ batch accumulators.
262
- - **nestjs-prisma**: `PrismaExceptionFilter` and transaction helper. Parallel query execution validated.
263
- - **nestjs-auth**: Comprehensive JSDoc on all public APIs. All TODO comments resolved.
264
- - **nestjs-common**: `ConfigurableModuleBuilder` with `externallyConfigured()` support.
265
- - **Global**: 2,500+ tests across all 13 packages. Comprehensive JSDoc for all public APIs.
266
-
267
- ## 📚 Documentation
268
-
269
- - `nestjs-common/docs/trust-proxy-security.md` — IP spoofing risks, preset configurations, verification steps
270
- - `nestjs-storage/docs/gdrive-security.md` — refreshToken security best practices
271
- - `nestjs-storage/docs/provider-capabilities.md` — method support matrix per provider
272
- - All packages: JSDoc on public APIs, MIGRATION.md guides where applicable
273
-
274
- ### Patch Changes
275
-
276
- - Updated dependencies [86a36b8]
277
- - @nathapp/nestjs-common@3.0.0
278
-
279
- ## 3.0.0-rc.0
280
-
281
- ### Major Changes
282
-
283
- - # 🚀 v3.0.0-rc Monorepo Enterprise Upgrade
284
-
285
- This release brings significant security, reliability, and observability improvements across the entire Nathapp ecosystem.
286
-
287
- ## ⚠️ [BREAKING CHANGES]
288
-
289
- ### nestjs-common
290
-
291
- - **Trust Proxy (Fail-Closed)**: Trust proxy is now disabled by default. Production deployments MUST configure `trustedProxies` or use a preset (`cloudflare`, `aws-alb`, etc.).
292
- - **SerializableInterceptor**: Now uses pure transformation. Original response objects are no longer mutated.
293
- - **AppException**: Now generic `AppException<T>` for strict argument typing.
294
-
295
- ### nestjs-logging
296
-
297
- - **Redaction**: Default redact paths are now constrained to 3 levels deep (`*.*.key`).
298
- - **Structured Logs**: Standardized field names for ELK/Loki/Datadog compatibility.
299
-
300
- ## ✨ Features & Improvements
301
-
302
- - **nestjs-storage**: Added native support for **Azure Blob Storage** and **Google Cloud Storage**.
303
- - **nestjs-microservices**: Full guard coverage and secured gRPC Bearer token extraction.
304
- - **nestjs-typeorm**: Automatic mapping of database errors to `AppException`.
305
- - **nestjs-auth-2fa**: Timing-safe TOTP verification and flexible policy engine.
306
- - **nestjs-cache**: Deep-cloning of cached objects to prevent cross-request state leakage.
307
- - **nestjs-queue**: Race-condition fixes in BullMQ/RabbitMQ batch accumulators.
308
- - **nestjs-throttler**: Added async trust proxy support.
309
- - **Global**: Comprehensive JSDoc for all public APIs across all packages.
310
-
311
- ### Patch Changes
312
-
313
- - Updated dependencies
314
- - @nathapp/nestjs-common@3.0.0-rc.0
@@ -1,37 +0,0 @@
1
- # Fix Plan: @nathapp/nestjs-prisma Enterprise Upgrade
2
- **Date:** 2026-02-15
3
- **Branch:** feat/monorepo-enterprise-upgrade
4
-
5
- ## Phase 1: Error Handling & Security
6
- ### Fix P1: Prisma Error -> AppException Mapping
7
- **Files:**
8
- - `packages/nestjs-prisma/lib/errors/prisma-error.mapper.ts` (New)
9
- - `packages/nestjs-prisma/lib/filter/prisma-exception.filter.ts` (New)
10
- **Impact:** Standardizes error reporting for Prisma-based services.
11
- **Change:** Implement a mapper for Prisma Client Known Request Errors (P2002, P2025, etc.) and a global filter.
12
-
13
- ## Phase 2: Lifecycle & Reliability
14
- ### Fix P2: Event Listener Memory Leak
15
- **File:** `packages/nestjs-prisma/lib/prisma.service.ts`
16
- **Impact:** Prevents memory leaks during hot-reloads or module destruction.
17
- **Change:** Ensure `$on('query', ...)` listeners are properly cleaned up in `onModuleDestroy()`.
18
-
19
- ## Phase 3: Transaction Support
20
- ### Fix P3: Transaction Helper Utility
21
- **File:** `packages/nestjs-prisma/lib/prisma.service.ts`
22
- **Impact:** Simplifies transactional logic for consumers.
23
- **Change:** Add a `withTransaction()` helper that wraps the native `$transaction` API with standard error mapping.
24
-
25
- ## Test Strategy
26
- - Mode: two-session-tdd
27
- - TDD targets:
28
- - `packages/nestjs-prisma/test/error-mapping.spec.ts` (Prisma error codes to AppException)
29
- - `packages/nestjs-prisma/test/lifecycle.spec.ts` (Listener cleanup verification)
30
- - `packages/nestjs-prisma/test/transaction.spec.ts` (Transaction success/rollback)
31
- - Test-after targets:
32
- - `packages/nestjs-prisma/test/prisma.service.spec.ts` (Regression check)
33
-
34
- ## Commits
35
- - `feat(nestjs-prisma): implement PrismaExceptionFilter for AppException consistency`
36
- - `fix(nestjs-prisma): resolve memory leak in query event listeners`
37
- - `feat(nestjs-prisma): add withTransaction helper with standard error mapping`