@nathapp/nestjs-prisma 4.0.3 → 4.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/CLAUDE.md CHANGED
@@ -13,12 +13,12 @@ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
13
13
 
14
14
  **Language:** TypeScript
15
15
 
16
- **Key dependencies:** @nathapp/typescript-config, @golevelup/ts-jest, typescript
16
+ **Key dependencies:** @nathapp/typescript-config, @golevelup/ts-jest, @prisma/client, prisma, typescript
17
17
 
18
18
  ---
19
19
  # @nathapp/nestjs-prisma
20
20
 
21
- Prisma 6 wrapper with multi-database support.
21
+ Prisma 7 wrapper with multi-database support.
22
22
 
23
23
  ## Commands
24
24
  - Test: `npx jest --config test/jest-test.json --no-coverage`
@@ -41,6 +41,11 @@ Note: PrismaModule's transparent transaction proxy already auto-routes
41
41
  `transaction: true`. The abstract repo's value is the `IRepository` contract
42
42
  (decoupling), not transaction wiring.
43
43
 
44
+ `PrismaService.withTransaction(callback, options)` shares that same
45
+ connection-specific transaction context. Calls made through
46
+ `prismaService.client` and repository methods inside its callback use the
47
+ transaction client; nested `withTransaction` calls reuse the active client.
48
+
44
49
  **Limitations:**
45
50
  - Structurally assumes the primary key property is named `"id"`. Schemas using a
46
51
  different PK name must bypass this base class.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @nathapp/nestjs-prisma
2
2
 
3
- Prisma 6 wrapper for NestJS with multi-database support, transactions, an
3
+ Prisma 7 wrapper for NestJS with multi-database support, transactions, an
4
4
  `IRepository`-compatible abstract repository, pagination, and error mapping.
5
5
 
6
6
  ## Installation
@@ -9,10 +9,18 @@ Prisma 6 wrapper for NestJS with multi-database support, transactions, an
9
9
  npm install @nathapp/nestjs-prisma
10
10
  ```
11
11
 
12
- `@prisma/client` is a peer dependency — install it in your consuming app; you
13
- will also want the `prisma` CLI installed there for migrations. This package is
14
- part of the `@nathapp/nestjs-*` peer-layer stack and builds on
15
- `@nathapp/nestjs-common` and `@nathapp/nestjs-data`.
12
+ `@prisma/client` 7.x is a peer dependency. Install it, the `prisma` CLI, and
13
+ the driver adapter for your database in your consuming app:
14
+
15
+ ```bash
16
+ npm install @prisma/client@^7.10.0 @prisma/adapter-pg@^7.10.0 # PostgreSQL
17
+ npm install @prisma/client@^7.10.0 @prisma/adapter-mariadb@^7.10.0 # MySQL / MariaDB
18
+ npm install -D prisma@^7.10.0
19
+ ```
20
+
21
+ Always pin `prisma@^7`: the `latest` tag of the `prisma` package may point at a
22
+ Prisma 8 release candidate. This package is part of the `@nathapp/nestjs-*`
23
+ peer-layer stack and builds on `@nathapp/nestjs-common` and `@nathapp/nestjs-data`.
16
24
 
17
25
  ## What it provides
18
26
 
@@ -39,6 +47,79 @@ part of the `@nathapp/nestjs-*` peer-layer stack and builds on
39
47
  the DI tokens for a named connection's `PrismaService` /
40
48
  `ITransactionManager`.
41
49
  - Prisma testing utilities under the `testing` export.
50
+ - `getUniqueConstraintTarget(error)` — the conflicting fields (or constraint name)
51
+ of a P2002 error, from `meta.target` or the Prisma 7 driver-adapter error shape.
52
+
53
+ ## Prisma 7 setup
54
+
55
+ ```prisma
56
+ generator client {
57
+ provider = "prisma-client"
58
+ output = "../src/generated/prisma"
59
+ moduleFormat = "cjs"
60
+ }
61
+
62
+ datasource db {
63
+ provider = "postgresql"
64
+ }
65
+ ```
66
+
67
+ ```ts
68
+ // prisma.config.ts
69
+ import 'dotenv/config';
70
+ import { defineConfig, env } from 'prisma/config';
71
+
72
+ export default defineConfig({
73
+ schema: 'prisma/schema.prisma',
74
+ migrations: { path: 'prisma/migrations' },
75
+ datasource: { url: env('DATABASE_URL') },
76
+ });
77
+ ```
78
+
79
+ ```ts
80
+ // app wiring
81
+ import { PrismaPg } from '@prisma/adapter-pg';
82
+ import { PrismaClient } from './generated/prisma/client';
83
+
84
+ PrismaModule.forRoot({
85
+ client: PrismaClient,
86
+ clientOptions: { adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL! }) },
87
+ transaction: true,
88
+ });
89
+ ```
90
+
91
+ For MySQL, use `provider = "mysql"` and
92
+ `new PrismaMariaDb({ host, port, user, password, database })` from `@prisma/adapter-mariadb`.
93
+ The generated client is TypeScript source in your project, so import `PrismaClient`
94
+ from your generator `output` path, not from `@prisma/client`.
95
+
96
+ Query logging (`logging: true`) needs the client to emit query events: pass
97
+ `clientOptions: { adapter, log: [{ emit: 'event', level: 'query' }] }`.
98
+
99
+ Upgrading from 4.x (Prisma 6): switch the generator to `prisma-client` with
100
+ `moduleFormat = "cjs"`, move the datasource `url` to `prisma.config.ts`, and replace
101
+ any `clientOptions.datasources` / `datasourceUrl` with `clientOptions.adapter`.
102
+
103
+ ### Keeping `npm audit` clean on Prisma 7
104
+
105
+ Prisma 7.10.x exact-pins two transitives (`deepmerge-ts@7.1.5` and `mysql2@3.15.3`)
106
+ that carry high-severity advisories; `prisma@7.10.0` also brings old `js-yaml`
107
+ through its Istanbul dev chain. npm `overrides` do not propagate to consumers, so
108
+ add them to your app's root `package.json` to keep `npm audit` at zero:
109
+
110
+ ```json
111
+ {
112
+ "overrides": {
113
+ "deepmerge-ts": "^8.0.2",
114
+ "mysql2": "^3.24.5",
115
+ "js-yaml@^3.13.1": "4.3.2"
116
+ }
117
+ }
118
+ ```
119
+
120
+ Re-verify with `npx prisma generate` and `db push` after adding them (verified safe
121
+ on 7.10.0). A future Prisma 7.x patch may update its own pins; re-check the
122
+ advisories when you bump.
42
123
 
43
124
  ## Usage
44
125
 
@@ -48,10 +129,13 @@ Single-DB setup and a repository implementation:
48
129
  import { Module, Inject, Injectable } from '@nestjs/common';
49
130
  import { PrismaModule, AbstractPrismaRepository } from '@nathapp/nestjs-prisma';
50
131
  import { TRANSACTION_MANAGER, ITransactionManager, IRepository } from '@nathapp/nestjs-data';
51
- import { PrismaClient } from '@prisma/client';
132
+ import { PrismaPg } from '@prisma/adapter-pg';
133
+ import { PrismaClient } from './generated/prisma/client';
52
134
 
53
135
  interface User { id: string; email: string; name: string }
54
136
 
137
+ const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL! });
138
+
55
139
  @Injectable()
56
140
  export class PrismaUserRepository extends AbstractPrismaRepository<User, any, string> {
57
141
  constructor(@Inject(TRANSACTION_MANAGER) tx: ITransactionManager) { super(tx); }
@@ -69,7 +153,7 @@ export class PrismaUserRepository extends AbstractPrismaRepository<User, any, st
69
153
  export const USER_REPOSITORY = Symbol('USER_REPOSITORY');
70
154
 
71
155
  @Module({
72
- imports: [PrismaModule.forRoot({ client: PrismaClient, transaction: true })],
156
+ imports: [PrismaModule.forRoot({ client: PrismaClient, clientOptions: { adapter }, transaction: true })],
73
157
  providers: [
74
158
  PrismaUserRepository,
75
159
  { provide: USER_REPOSITORY, useExisting: PrismaUserRepository },
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PrismaErrorMapper = exports.PrismaAppException = exports.PRISMA_ERROR_CODES = void 0;
4
4
  const nestjs_common_1 = require("@nathapp/nestjs-common");
5
- const library_1 = require("@prisma/client/runtime/library");
5
+ const client_1 = require("@prisma/client/runtime/client");
6
6
  const common_1 = require("@nestjs/common");
7
+ const unique_constraint_target_1 = require("./unique-constraint-target");
7
8
  exports.PRISMA_ERROR_CODES = {
8
9
  VALUE_TOO_LONG: 'VALUE_TOO_LONG',
9
10
  RECORD_NOT_FOUND: 'RECORD_NOT_FOUND',
@@ -26,18 +27,16 @@ class PrismaAppException extends nestjs_common_1.AppException {
26
27
  exports.PrismaAppException = PrismaAppException;
27
28
  class PrismaErrorMapper {
28
29
  static map(error) {
29
- var _a;
30
30
  if (!error) {
31
31
  return new PrismaAppException(9999, exports.PRISMA_ERROR_CODES.UNKNOWN_ERROR, { message: 'An unknown error occurred' }, 500);
32
32
  }
33
- const isPrismaError = error instanceof library_1.PrismaClientKnownRequestError ||
33
+ const isPrismaError = error instanceof client_1.PrismaClientKnownRequestError ||
34
34
  (typeof error === 'object' && 'code' in error && typeof error.code === 'string' && error.code.startsWith('P'));
35
35
  if (isPrismaError) {
36
36
  const errorConfig = this.ERROR_MAP[error.code];
37
37
  if (errorConfig) {
38
- const safeArgs = error.code === 'P2002' && ((_a = error.meta) === null || _a === void 0 ? void 0 : _a.target)
39
- ? { target: error.meta.target }
40
- : {};
38
+ const target = error.code === 'P2002' ? (0, unique_constraint_target_1.getUniqueConstraintTarget)(error) : undefined;
39
+ const safeArgs = target !== undefined ? { target } : {};
41
40
  this.logger.error(`Prisma error ${error.code}: ${error.message}`, { meta: error.meta, clientVersion: error.clientVersion });
42
41
  return new PrismaAppException(errorConfig.numericCode, errorConfig.stringCode, safeArgs, errorConfig.httpStatus);
43
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prisma-error.mapper.js","sourceRoot":"","sources":["../../lib/errors/prisma-error.mapper.ts"],"names":[],"mappings":";;;AAAA,0DAAsD;AACtD,4DAA+E;AAC/E,2CAAwC;AAe3B,QAAA,kBAAkB,GAAG;IAChC,cAAc,EAAE,gBAAgB;IAChC,gBAAgB,EAAE,kBAAkB;IACpC,eAAe,EAAE,iBAAiB;IAClC,iBAAiB,EAAE,mBAAmB;IACtC,kBAAkB,EAAE,oBAAoB;IACxC,kBAAkB,EAAE,oBAAoB;IACxC,cAAc,EAAE,gBAAgB;IAChC,aAAa,EAAE,eAAe;CACtB,CAAC;AAMX,MAAa,kBAAmB,SAAQ,4BAAY;IAGlD,YACE,WAAmB,EACnB,UAAkB,EAClB,IAA8B,EAC9B,UAAmB;QAEnB,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAKD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF;AAnBD,gDAmBC;AAMD,MAAa,iBAAiB;IAuC5B,MAAM,CAAC,GAAG,CAAC,KAAU;;QAEnB,IAAI,CAAC,KAAK,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AyGC;AAxGyB,wBAAM,GAAG,IAAI,eAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAM5C,2BAAS,GAG7B;IAEF,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,kBAAkB,EAAE;IAGhG,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,cAAc,EAAE;IAG5F,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,gBAAgB,EAAE;IAG9F,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,eAAe,EAAE;IAG7F,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,iBAAiB,EAAE;IAG/F,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,kBAAkB,EAAE;IAGhG,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,gBAAgB,EAAE;CAC/F,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type UniqueConstraintTarget = string | string[];
2
+ export declare function getUniqueConstraintTarget(error: unknown): UniqueConstraintTarget | undefined;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUniqueConstraintTarget = getUniqueConstraintTarget;
4
+ function isStringArray(value) {
5
+ return Array.isArray(value) && value.every((item) => typeof item === 'string');
6
+ }
7
+ function getUniqueConstraintTarget(error) {
8
+ var _a;
9
+ if (typeof error !== 'object' || error === null)
10
+ return undefined;
11
+ const meta = error.meta;
12
+ if (typeof meta !== 'object' || meta === null)
13
+ return undefined;
14
+ const { target, driverAdapterError } = meta;
15
+ if (typeof target === 'string' || isStringArray(target))
16
+ return target;
17
+ const constraint = (_a = driverAdapterError === null || driverAdapterError === void 0 ? void 0 : driverAdapterError.cause) === null || _a === void 0 ? void 0 : _a.constraint;
18
+ if (isStringArray(constraint === null || constraint === void 0 ? void 0 : constraint.fields))
19
+ return constraint.fields;
20
+ if (typeof (constraint === null || constraint === void 0 ? void 0 : constraint.index) === 'string')
21
+ return constraint.index;
22
+ return undefined;
23
+ }
24
+ //# sourceMappingURL=unique-constraint-target.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unique-constraint-target.js","sourceRoot":"","sources":["../../lib/errors/unique-constraint-target.ts"],"names":[],"mappings":";;AAgBA,8DAaC;AAxBD,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC;AACjF,CAAC;AASD,SAAgB,yBAAyB,CAAC,KAAc;;IACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAClE,MAAM,IAAI,GAAI,KAA4B,CAAC,IAAI,CAAC;IAChD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAEhE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,IAA0D,CAAC;IAClG,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,aAAa,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAEvE,MAAM,UAAU,GAAG,MAAC,kBAAqG,aAArG,kBAAkB,uBAAlB,kBAAkB,CAClC,KAAK,0CAAE,UAAU,CAAC;IACtB,IAAI,aAAa,CAAC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,CAAC;QAAE,OAAO,UAAU,CAAC,MAAM,CAAC;IAChE,IAAI,OAAO,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,KAAK,CAAA,KAAK,QAAQ;QAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACnE,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
2
  import { HttpAdapterHost } from '@nestjs/core';
3
- import { PrismaClientKnownRequestError, PrismaClientValidationError } from '@prisma/client/runtime/library';
3
+ import { PrismaClientKnownRequestError, PrismaClientValidationError } from '@prisma/client/runtime/client';
4
4
  export declare class PrismaExceptionFilter implements ExceptionFilter {
5
5
  private readonly httpAdapterHost?;
6
6
  private readonly logger;
@@ -16,7 +16,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.PrismaExceptionFilter = void 0;
17
17
  const common_1 = require("@nestjs/common");
18
18
  const core_1 = require("@nestjs/core");
19
- const library_1 = require("@prisma/client/runtime/library");
19
+ const client_1 = require("@prisma/client/runtime/client");
20
20
  const prisma_error_mapper_1 = require("../errors/prisma-error.mapper");
21
21
  let PrismaExceptionFilter = PrismaExceptionFilter_1 = class PrismaExceptionFilter {
22
22
  constructor(httpAdapterHost) {
@@ -36,7 +36,7 @@ let PrismaExceptionFilter = PrismaExceptionFilter_1 = class PrismaExceptionFilte
36
36
  catch(exception, host) {
37
37
  const ctx = host.switchToHttp();
38
38
  const response = ctx.getResponse();
39
- if (exception instanceof library_1.PrismaClientValidationError) {
39
+ if (exception instanceof client_1.PrismaClientValidationError) {
40
40
  this.logger.error('PrismaClientValidationError', { message: exception.message });
41
41
  this.reply(response, 400, {
42
42
  success: false,
@@ -61,7 +61,7 @@ let PrismaExceptionFilter = PrismaExceptionFilter_1 = class PrismaExceptionFilte
61
61
  };
62
62
  exports.PrismaExceptionFilter = PrismaExceptionFilter;
63
63
  exports.PrismaExceptionFilter = PrismaExceptionFilter = PrismaExceptionFilter_1 = __decorate([
64
- (0, common_1.Catch)(library_1.PrismaClientKnownRequestError, library_1.PrismaClientValidationError),
64
+ (0, common_1.Catch)(client_1.PrismaClientKnownRequestError, client_1.PrismaClientValidationError),
65
65
  __param(0, (0, common_1.Optional)()),
66
66
  __metadata("design:paramtypes", [core_1.HttpAdapterHost])
67
67
  ], PrismaExceptionFilter);
@@ -1 +1 @@
1
- {"version":3,"file":"prisma-exception.filter.js","sourceRoot":"","sources":["../../lib/filter/prisma-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyF;AACzF,uCAA+C;AAC/C,4DAGwC;AACxC,uEAAsF;AA+B/E,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAGhC,YAAwB,eAAkD;QAAjC,oBAAe,GAAf,eAAe,CAAkB;QAFzD,WAAM,GAAG,IAAI,eAAM,CAAC,uBAAqB,CAAC,IAAI,CAAC,CAAC;IAEY,CAAC;IAEtE,KAAK,CAAC,QAAa,EAAE,MAAc,EAAE,IAAa;;QACxD,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,eAAe,0CAAE,WAAW,CAAC;QAClD,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,SAAsE,EAAE,IAAmB;QAC/F,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAGnC,IAAI,SAAS,YAAY,qCAA2B,EAAE,CAAC;YAErD,IAAI,CA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E,oCAA2B,CAAC;IAInD,WAAA,IAAA,iBAAQ,GAAE,CAAA;qCAAoC,sBAAe;GAH/D,qBAAqB,CA+CjC"}
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from './prisma.health';
7
7
  export * from './pagination';
8
8
  export * from './testing';
9
9
  export * from './errors/prisma-error.mapper';
10
+ export * from './errors/unique-constraint-target';
10
11
  export * from './filter/prisma-exception.filter';
11
12
  export * from './transaction';
12
13
  export * from './repository';
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ __exportStar(require("./prisma.health"), exports);
23
23
  __exportStar(require("./pagination"), exports);
24
24
  __exportStar(require("./testing"), exports);
25
25
  __exportStar(require("./errors/prisma-error.mapper"), exports);
26
+ __exportStar(require("./errors/unique-constraint-target"), exports);
26
27
  __exportStar(require("./filter/prisma-exception.filter"), exports);
27
28
  __exportStar(require("./transaction"), exports);
28
29
  __exportStar(require("./repository"), exports);
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;AACjD,gDAA8B;AAC9B,+CAA6B"}
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,oEAAkD;AAClD,mEAAiD;AACjD,gDAA8B;AAC9B,+CAA6B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathapp/nestjs-prisma",
3
- "version": "4.0.3",
3
+ "version": "4.1.0",
4
4
  "description": "NestJS Prisma integration with multi-database support",
5
5
  "scripts": {
6
6
  "clean": "rimraf dist/ .turbo/",
@@ -20,20 +20,22 @@
20
20
  "types": "dist/index.d.ts",
21
21
  "main": "dist/index.js",
22
22
  "dependencies": {
23
- "@nathapp/nestjs-common": "^4.0.3",
24
- "@nathapp/nestjs-data": "^4.0.3"
23
+ "@nathapp/nestjs-common": "^4.1.0",
24
+ "@nathapp/nestjs-data": "^4.1.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@nathapp/eslint-config": "1.0.1",
28
28
  "@nathapp/typescript-config": "1.0.1",
29
29
  "@golevelup/ts-jest": "^3.0.0",
30
+ "@prisma/client": "^7.10.0",
30
31
  "eslint": "^8.57.0",
32
+ "prisma": "^7.10.0",
31
33
  "typescript": "^5"
32
34
  },
33
35
  "peerDependencies": {
34
36
  "@nathapp/nestjs-common": "^4.0.0-rc.0",
35
37
  "@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
36
38
  "@nestjs/core": "^10.0.0 || ^11.0.0 || ^12.0.0",
37
- "@prisma/client": "^6.0.0"
39
+ "@prisma/client": "^7.0.0"
38
40
  }
39
41
  }