nestjs-prisma
Advanced tools
Comparing version 0.22.0 to 0.23.0-dev.0
@@ -68,7 +68,7 @@ "use strict"; | ||
}; | ||
exports.CustomPrismaModule = CustomPrismaModule; | ||
CustomPrismaModule.logger = new common_1.Logger(CustomPrismaModule_1.name); | ||
CustomPrismaModule = CustomPrismaModule_1 = __decorate([ | ||
exports.CustomPrismaModule = CustomPrismaModule = CustomPrismaModule_1 = __decorate([ | ||
(0, common_1.Module)({}) | ||
], CustomPrismaModule); | ||
exports.CustomPrismaModule = CustomPrismaModule; | ||
//# sourceMappingURL=custom-prisma.module.js.map |
@@ -23,3 +23,4 @@ "use strict"; | ||
}; | ||
CustomPrismaService = __decorate([ | ||
exports.CustomPrismaService = CustomPrismaService; | ||
exports.CustomPrismaService = CustomPrismaService = __decorate([ | ||
(0, common_1.Injectable)(), | ||
@@ -29,3 +30,2 @@ __param(0, (0, common_1.Inject)(custom_prisma_constants_1.CUSTOM_PRISMA_CLIENT)), | ||
], CustomPrismaService); | ||
exports.CustomPrismaService = CustomPrismaService; | ||
//# sourceMappingURL=custom-prisma.service.js.map |
@@ -1,14 +0,21 @@ | ||
import { ArgumentsHost, ContextType, HttpException, HttpServer } from '@nestjs/common'; | ||
import { ArgumentsHost, HttpException, HttpServer } from '@nestjs/common'; | ||
import { BaseExceptionFilter, HttpAdapterHost } from '@nestjs/core'; | ||
import { Prisma } from '@prisma/client'; | ||
export declare type GqlContextType = 'graphql' | ContextType; | ||
export declare type GqlContextType = 'graphql'; | ||
export type ErrorCodesStatusMapping = { | ||
[key: string]: number; | ||
[key: string]: number | { | ||
statusCode?: number; | ||
errorMessage?: string; | ||
}; | ||
}; | ||
export declare class PrismaClientExceptionFilter extends BaseExceptionFilter { | ||
private errorCodesStatusMapping; | ||
constructor(applicationRef?: HttpServer, errorCodesStatusMapping?: ErrorCodesStatusMapping | null); | ||
private readonly defaultMapping; | ||
private readonly userDefinedMapping?; | ||
constructor(applicationRef?: HttpServer, errorCodesStatusMapping?: ErrorCodesStatusMapping); | ||
catch(exception: Prisma.PrismaClientKnownRequestError, host: ArgumentsHost): void | Prisma.PrismaClientKnownRequestError | HttpException; | ||
private catchClientKnownRequestError; | ||
private exceptionShortMessage; | ||
private userDefinedStatusCode; | ||
private defaultStatusCode; | ||
private userDefinedExceptionMessage; | ||
private defaultExceptionMessage; | ||
} | ||
@@ -15,0 +22,0 @@ export declare function providePrismaClientExceptionFilter(errorCodesStatusMapping?: ErrorCodesStatusMapping): { |
@@ -17,5 +17,5 @@ "use strict"; | ||
let PrismaClientExceptionFilter = class PrismaClientExceptionFilter extends core_1.BaseExceptionFilter { | ||
constructor(applicationRef, errorCodesStatusMapping = null) { | ||
constructor(applicationRef, errorCodesStatusMapping) { | ||
super(applicationRef); | ||
this.errorCodesStatusMapping = { | ||
this.defaultMapping = { | ||
P2000: common_1.HttpStatus.BAD_REQUEST, | ||
@@ -25,5 +25,3 @@ P2002: common_1.HttpStatus.CONFLICT, | ||
}; | ||
if (errorCodesStatusMapping) { | ||
this.errorCodesStatusMapping = Object.assign(this.errorCodesStatusMapping, errorCodesStatusMapping); | ||
} | ||
this.userDefinedMapping = errorCodesStatusMapping; | ||
} | ||
@@ -34,6 +32,8 @@ catch(exception, host) { | ||
catchClientKnownRequestError(exception, host) { | ||
const statusCode = this.errorCodesStatusMapping[exception.code]; | ||
const message = `[${exception.code}]: ` + this.exceptionShortMessage(exception.message); | ||
const statusCode = this.userDefinedStatusCode(exception) || | ||
this.defaultStatusCode(exception); | ||
const message = this.userDefinedExceptionMessage(exception) || | ||
this.defaultExceptionMessage(exception); | ||
if (host.getType() === 'http') { | ||
if (!Object.keys(this.errorCodesStatusMapping).includes(exception.code)) { | ||
if (statusCode === undefined) { | ||
return super.catch(exception, host); | ||
@@ -44,3 +44,3 @@ } | ||
else if (host.getType() === 'graphql') { | ||
if (!Object.keys(this.errorCodesStatusMapping).includes(exception.code)) { | ||
if (statusCode === undefined) { | ||
return exception; | ||
@@ -51,15 +51,33 @@ } | ||
} | ||
exceptionShortMessage(message) { | ||
const shortMessage = message.substring(message.indexOf('→')); | ||
return shortMessage | ||
.substring(shortMessage.indexOf('\n')) | ||
.replace(/\n/g, '') | ||
.trim(); | ||
userDefinedStatusCode(exception) { | ||
var _a; | ||
const userDefinedValue = (_a = this.userDefinedMapping) === null || _a === void 0 ? void 0 : _a[exception.code]; | ||
return typeof userDefinedValue === 'number' | ||
? userDefinedValue | ||
: userDefinedValue === null || userDefinedValue === void 0 ? void 0 : userDefinedValue.statusCode; | ||
} | ||
defaultStatusCode(exception) { | ||
return this.defaultMapping[exception.code]; | ||
} | ||
userDefinedExceptionMessage(exception) { | ||
var _a; | ||
const userDefinedValue = (_a = this.userDefinedMapping) === null || _a === void 0 ? void 0 : _a[exception.code]; | ||
return typeof userDefinedValue === 'number' | ||
? undefined | ||
: userDefinedValue === null || userDefinedValue === void 0 ? void 0 : userDefinedValue.errorMessage; | ||
} | ||
defaultExceptionMessage(exception) { | ||
const shortMessage = exception.message.substring(exception.message.indexOf('→')); | ||
return (`[${exception.code}]: ` + | ||
shortMessage | ||
.substring(shortMessage.indexOf('\n')) | ||
.replace(/\n/g, '') | ||
.trim()); | ||
} | ||
}; | ||
PrismaClientExceptionFilter = __decorate([ | ||
exports.PrismaClientExceptionFilter = PrismaClientExceptionFilter; | ||
exports.PrismaClientExceptionFilter = PrismaClientExceptionFilter = __decorate([ | ||
(0, common_1.Catch)(client_1.Prisma === null || client_1.Prisma === void 0 ? void 0 : client_1.Prisma.PrismaClientKnownRequestError), | ||
__metadata("design:paramtypes", [Object, Object]) | ||
], PrismaClientExceptionFilter); | ||
exports.PrismaClientExceptionFilter = PrismaClientExceptionFilter; | ||
function providePrismaClientExceptionFilter(errorCodesStatusMapping) { | ||
@@ -66,0 +84,0 @@ return { |
@@ -66,3 +66,4 @@ "use strict"; | ||
}; | ||
PrismaModule = PrismaModule_1 = __decorate([ | ||
exports.PrismaModule = PrismaModule; | ||
exports.PrismaModule = PrismaModule = PrismaModule_1 = __decorate([ | ||
(0, common_1.Module)({ | ||
@@ -73,3 +74,2 @@ providers: [prisma_service_1.PrismaService], | ||
], PrismaModule); | ||
exports.PrismaModule = PrismaModule; | ||
//# sourceMappingURL=prisma.module.js.map |
@@ -33,3 +33,4 @@ "use strict"; | ||
}; | ||
PrismaService = __decorate([ | ||
exports.PrismaService = PrismaService; | ||
exports.PrismaService = PrismaService = __decorate([ | ||
(0, common_1.Injectable)(), | ||
@@ -40,3 +41,2 @@ __param(0, (0, common_1.Optional)()), | ||
], PrismaService); | ||
exports.PrismaService = PrismaService; | ||
//# sourceMappingURL=prisma.service.js.map |
{ | ||
"name": "nestjs-prisma", | ||
"version": "0.22.0", | ||
"version": "0.23.0-dev.0", | ||
"description": "Library and schematics to add Prisma integration to a NestJS application", | ||
@@ -44,20 +44,20 @@ "scripts": { | ||
"devDependencies": { | ||
"@nestjs/common": "9.4.0", | ||
"@nestjs/core": "9.4.0", | ||
"@nestjs/platform-express": "9.4.0", | ||
"@prisma/client": "^5.0.0", | ||
"@nestjs/common": "10.2.7", | ||
"@nestjs/core": "10.2.7", | ||
"@nestjs/platform-express": "10.2.7", | ||
"@prisma/client": "^5.5.2", | ||
"@types/jasmine": "3.8.2", | ||
"@types/node": "^16.18.25", | ||
"@typescript-eslint/eslint-plugin": "5.38.1", | ||
"@typescript-eslint/parser": "5.38.1", | ||
"eslint": "8.24.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"@typescript-eslint/eslint-plugin": "6.9.1", | ||
"@typescript-eslint/parser": "6.9.1", | ||
"eslint": "8.52.0", | ||
"eslint-config-prettier": "9.0.0", | ||
"eslint-plugin-prettier": "5.0.1", | ||
"jasmine": "^3.6.3", | ||
"prettier": "2.8.8", | ||
"prisma": "^5.0.0", | ||
"prettier": "3.0.3", | ||
"prisma": "^5.5.2", | ||
"reflect-metadata": "0.1.13", | ||
"rxjs": "^7.8.1", | ||
"typescript": "~4.9.5" | ||
"typescript": "^5.1.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187867
82