@nathapp/nestjs-prisma 3.0.0-rc.4
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/.eslintrc.js +8 -0
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +43 -0
- package/CHANGELOG.md +38 -0
- package/CLAUDE.md +17 -0
- package/dist/errors/prisma-error.mapper.d.ts +20 -0
- package/dist/errors/prisma-error.mapper.js +53 -0
- package/dist/errors/prisma-error.mapper.js.map +1 -0
- package/dist/filter/prisma-exception.filter.d.ts +5 -0
- package/dist/filter/prisma-exception.filter.js +43 -0
- package/dist/filter/prisma-exception.filter.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +18 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/pagination/paginate.d.ts +11 -0
- package/dist/pagination/paginate.js +27 -0
- package/dist/pagination/paginate.js.map +1 -0
- package/dist/prisma.constants.d.ts +3 -0
- package/dist/prisma.constants.js +10 -0
- package/dist/prisma.constants.js.map +1 -0
- package/dist/prisma.decorator.d.ts +1 -0
- package/dist/prisma.decorator.js +8 -0
- package/dist/prisma.decorator.js.map +1 -0
- package/dist/prisma.health.d.ts +10 -0
- package/dist/prisma.health.js +46 -0
- package/dist/prisma.health.js.map +1 -0
- package/dist/prisma.interfaces.d.ts +24 -0
- package/dist/prisma.interfaces.js +3 -0
- package/dist/prisma.interfaces.js.map +1 -0
- package/dist/prisma.module.d.ts +7 -0
- package/dist/prisma.module.js +109 -0
- package/dist/prisma.module.js.map +1 -0
- package/dist/prisma.service.d.ts +17 -0
- package/dist/prisma.service.js +122 -0
- package/dist/prisma.service.js.map +1 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +18 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/prisma-testing.utils.d.ts +8 -0
- package/dist/testing/prisma-testing.utils.js +24 -0
- package/dist/testing/prisma-testing.utils.js.map +1 -0
- package/docs/20260215-fix-plan-prisma.md +37 -0
- package/docs/20260215-review-prisma.md +598 -0
- package/docs/20260216-plan-prisma-a-minus.md +70 -0
- package/lib/errors/prisma-error.mapper.ts +140 -0
- package/lib/filter/prisma-exception.filter.ts +62 -0
- package/lib/index.ts +10 -0
- package/lib/pagination/index.ts +1 -0
- package/lib/pagination/paginate.ts +44 -0
- package/lib/prisma.constants.ts +10 -0
- package/lib/prisma.decorator.ts +8 -0
- package/lib/prisma.health.ts +40 -0
- package/lib/prisma.interfaces.ts +41 -0
- package/lib/prisma.module.ts +115 -0
- package/lib/prisma.service.ts +180 -0
- package/lib/testing/index.ts +1 -0
- package/lib/testing/prisma-testing.utils.ts +29 -0
- package/package.json +31 -0
- package/test/error-mapping.spec.ts +192 -0
- package/test/jest-test.json +24 -0
- package/test/lifecycle.spec.ts +241 -0
- package/test/pagination/paginate.spec.ts +359 -0
- package/test/prisma-exception-filter.spec.ts +213 -0
- package/test/prisma.decorator.spec.ts +257 -0
- package/test/prisma.health.spec.ts +226 -0
- package/test/prisma.module.spec.ts +397 -0
- package/test/prisma.service.spec.ts +359 -0
- package/test/transaction.spec.ts +371 -0
- package/tsconfig.json +9 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
> @nathapp/nestjs-prisma@3.0.0-rc.0 test
|
|
3
|
+
> jest --config ./test/jest-test.json
|
|
4
|
+
|
|
5
|
+
PASS test/prisma.health.spec.ts (10.382 s)
|
|
6
|
+
PASS test/prisma.service.spec.ts (19.029 s)
|
|
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
|
|
10
|
+
|
|
11
|
+
expect(received).toBeLessThan(expected)
|
|
12
|
+
|
|
13
|
+
Expected: < 100
|
|
14
|
+
Received: 114
|
|
15
|
+
|
|
16
|
+
334 | // In CI environments, timer precision may vary.
|
|
17
|
+
335 | // We just want to ensure it's reasonably fast and definitely parallel (not 200ms+ serial)
|
|
18
|
+
> 336 | expect(duration).toBeLessThan(100);
|
|
19
|
+
| ^
|
|
20
|
+
337 | expect(mockModel.findMany).toHaveBeenCalled();
|
|
21
|
+
338 | expect(mockModel.count).toHaveBeenCalled();
|
|
22
|
+
339 | });
|
|
23
|
+
|
|
24
|
+
at Object.<anonymous> (test/pagination/paginate.spec.ts:336:24)
|
|
25
|
+
|
|
26
|
+
PASS test/transaction.spec.ts (19.436 s)
|
|
27
|
+
PASS test/prisma.module.spec.ts (19.565 s)
|
|
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
|
|
31
|
+
|
|
32
|
+
Test Suites: 1 failed, 8 passed, 9 total
|
|
33
|
+
Tests: 1 failed, 1 skipped, 134 passed, 136 total
|
|
34
|
+
Snapshots: 0 total
|
|
35
|
+
Time: 24.395 s
|
|
36
|
+
Ran all test suites.
|
|
37
|
+
npm error Lifecycle script `test` failed with error:
|
|
38
|
+
npm error code 1
|
|
39
|
+
npm error path /Users/subrinaai/Desktop/workspace/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-prisma
|
|
40
|
+
npm error workspace @nathapp/nestjs-prisma@3.0.0-rc.0
|
|
41
|
+
npm error location /Users/subrinaai/Desktop/workspace/subrina-coder/projects/nathapp-nestjs-core/repos/nathapp-nestjs/packages/nestjs-prisma
|
|
42
|
+
npm error command failed
|
|
43
|
+
npm error command sh -c jest --config ./test/jest-test.json
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @nathapp/nestjs-prisma
|
|
2
|
+
|
|
3
|
+
## 3.0.0-rc.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- # 🚀 v3.0.0-rc Monorepo Enterprise Upgrade
|
|
8
|
+
|
|
9
|
+
This release brings significant security, reliability, and observability improvements across the entire Nathapp ecosystem.
|
|
10
|
+
|
|
11
|
+
## ⚠️ [BREAKING CHANGES]
|
|
12
|
+
|
|
13
|
+
### nestjs-common
|
|
14
|
+
|
|
15
|
+
- **Trust Proxy (Fail-Closed)**: Trust proxy is now disabled by default. Production deployments MUST configure `trustedProxies` or use a preset (`cloudflare`, `aws-alb`, etc.).
|
|
16
|
+
- **SerializableInterceptor**: Now uses pure transformation. Original response objects are no longer mutated.
|
|
17
|
+
- **AppException**: Now generic `AppException<T>` for strict argument typing.
|
|
18
|
+
|
|
19
|
+
### nestjs-logging
|
|
20
|
+
|
|
21
|
+
- **Redaction**: Default redact paths are now constrained to 3 levels deep (`*.*.key`).
|
|
22
|
+
- **Structured Logs**: Standardized field names for ELK/Loki/Datadog compatibility.
|
|
23
|
+
|
|
24
|
+
## ✨ Features & Improvements
|
|
25
|
+
|
|
26
|
+
- **nestjs-storage**: Added native support for **Azure Blob Storage** and **Google Cloud Storage**.
|
|
27
|
+
- **nestjs-microservices**: Full guard coverage and secured gRPC Bearer token extraction.
|
|
28
|
+
- **nestjs-typeorm**: Automatic mapping of database errors to `AppException`.
|
|
29
|
+
- **nestjs-auth-2fa**: Timing-safe TOTP verification and flexible policy engine.
|
|
30
|
+
- **nestjs-cache**: Deep-cloning of cached objects to prevent cross-request state leakage.
|
|
31
|
+
- **nestjs-queue**: Race-condition fixes in BullMQ/RabbitMQ batch accumulators.
|
|
32
|
+
- **nestjs-throttler**: Added async trust proxy support.
|
|
33
|
+
- **Global**: Comprehensive JSDoc for all public APIs across all packages.
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies
|
|
38
|
+
- @nathapp/nestjs-common@3.0.0-rc.0
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @nathapp/nestjs-prisma
|
|
2
|
+
|
|
3
|
+
Prisma 6 wrapper with multi-database support.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
- Test: `npx jest --config test/jest-test.json --no-coverage`
|
|
7
|
+
- Build: `npx tsc`
|
|
8
|
+
|
|
9
|
+
## Architecture
|
|
10
|
+
- `PrismaModule.forRoot({ url })` — single database.
|
|
11
|
+
- `PrismaModule.forRoot({ databases: { db1: { url }, db2: { url } } })` — multi-database.
|
|
12
|
+
- `PrismaService` wraps `PrismaClient` (composition, not inheritance) for multi-db flexibility.
|
|
13
|
+
- Pagination uses `Page<T>` from `@nathapp/nestjs-common`.
|
|
14
|
+
|
|
15
|
+
## Gotchas
|
|
16
|
+
- Error-case tests must use `await expect(module.compile()).rejects.toThrow()` — NestJS `compile()` eagerly instantiates providers.
|
|
17
|
+
- `prisma` is a peer dependency — consumers must install it.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AppException } from '@nathapp/nestjs-common';
|
|
2
|
+
export declare const PRISMA_ERROR_CODES: {
|
|
3
|
+
readonly VALUE_TOO_LONG: "VALUE_TOO_LONG";
|
|
4
|
+
readonly RECORD_NOT_FOUND: "RECORD_NOT_FOUND";
|
|
5
|
+
readonly DUPLICATE_ENTRY: "DUPLICATE_ENTRY";
|
|
6
|
+
readonly INVALID_REFERENCE: "INVALID_REFERENCE";
|
|
7
|
+
readonly RELATION_VIOLATION: "RELATION_VIOLATION";
|
|
8
|
+
readonly CONNECTION_TIMEOUT: "CONNECTION_TIMEOUT";
|
|
9
|
+
readonly DATABASE_ERROR: "DATABASE_ERROR";
|
|
10
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
11
|
+
};
|
|
12
|
+
export declare class PrismaAppException extends AppException {
|
|
13
|
+
readonly stringCode: string;
|
|
14
|
+
constructor(numericCode: number, stringCode: string, args?: Record<string, unknown>, httpStatus?: number);
|
|
15
|
+
get code(): any;
|
|
16
|
+
}
|
|
17
|
+
export declare class PrismaErrorMapper {
|
|
18
|
+
private static readonly ERROR_MAP;
|
|
19
|
+
static map(error: any): PrismaAppException;
|
|
20
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrismaErrorMapper = exports.PrismaAppException = exports.PRISMA_ERROR_CODES = void 0;
|
|
4
|
+
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
5
|
+
const library_1 = require("@prisma/client/runtime/library");
|
|
6
|
+
exports.PRISMA_ERROR_CODES = {
|
|
7
|
+
VALUE_TOO_LONG: 'VALUE_TOO_LONG',
|
|
8
|
+
RECORD_NOT_FOUND: 'RECORD_NOT_FOUND',
|
|
9
|
+
DUPLICATE_ENTRY: 'DUPLICATE_ENTRY',
|
|
10
|
+
INVALID_REFERENCE: 'INVALID_REFERENCE',
|
|
11
|
+
RELATION_VIOLATION: 'RELATION_VIOLATION',
|
|
12
|
+
CONNECTION_TIMEOUT: 'CONNECTION_TIMEOUT',
|
|
13
|
+
DATABASE_ERROR: 'DATABASE_ERROR',
|
|
14
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
15
|
+
};
|
|
16
|
+
class PrismaAppException extends nestjs_common_1.AppException {
|
|
17
|
+
constructor(numericCode, stringCode, args, httpStatus) {
|
|
18
|
+
super(numericCode, args, 'prisma', httpStatus);
|
|
19
|
+
this.stringCode = stringCode;
|
|
20
|
+
}
|
|
21
|
+
get code() {
|
|
22
|
+
return this.stringCode;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.PrismaAppException = PrismaAppException;
|
|
26
|
+
class PrismaErrorMapper {
|
|
27
|
+
static map(error) {
|
|
28
|
+
if (!error) {
|
|
29
|
+
return new PrismaAppException(9999, exports.PRISMA_ERROR_CODES.UNKNOWN_ERROR, { message: 'An unknown error occurred' }, 500);
|
|
30
|
+
}
|
|
31
|
+
const isPrismaError = error instanceof library_1.PrismaClientKnownRequestError ||
|
|
32
|
+
(typeof error === 'object' && 'code' in error && typeof error.code === 'string' && error.code.startsWith('P'));
|
|
33
|
+
if (isPrismaError) {
|
|
34
|
+
const errorConfig = this.ERROR_MAP[error.code];
|
|
35
|
+
if (errorConfig) {
|
|
36
|
+
return new PrismaAppException(errorConfig.numericCode, errorConfig.stringCode, error.meta || {}, errorConfig.httpStatus);
|
|
37
|
+
}
|
|
38
|
+
return new PrismaAppException(9998, exports.PRISMA_ERROR_CODES.DATABASE_ERROR, { prismaCode: error.code, message: error.message }, 500);
|
|
39
|
+
}
|
|
40
|
+
return new PrismaAppException(9999, exports.PRISMA_ERROR_CODES.UNKNOWN_ERROR, { message: error.message || String(error) }, 500);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.PrismaErrorMapper = PrismaErrorMapper;
|
|
44
|
+
PrismaErrorMapper.ERROR_MAP = {
|
|
45
|
+
P1008: { httpStatus: 503, numericCode: 1008, stringCode: exports.PRISMA_ERROR_CODES.CONNECTION_TIMEOUT },
|
|
46
|
+
P2000: { httpStatus: 400, numericCode: 2000, stringCode: exports.PRISMA_ERROR_CODES.VALUE_TOO_LONG },
|
|
47
|
+
P2001: { httpStatus: 404, numericCode: 2001, stringCode: exports.PRISMA_ERROR_CODES.RECORD_NOT_FOUND },
|
|
48
|
+
P2002: { httpStatus: 409, numericCode: 2002, stringCode: exports.PRISMA_ERROR_CODES.DUPLICATE_ENTRY },
|
|
49
|
+
P2003: { httpStatus: 400, numericCode: 2003, stringCode: exports.PRISMA_ERROR_CODES.INVALID_REFERENCE },
|
|
50
|
+
P2014: { httpStatus: 409, numericCode: 2014, stringCode: exports.PRISMA_ERROR_CODES.RELATION_VIOLATION },
|
|
51
|
+
P2025: { httpStatus: 404, numericCode: 2025, stringCode: exports.PRISMA_ERROR_CODES.RECORD_NOT_FOUND },
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=prisma-error.mapper.js.map
|
|
@@ -0,0 +1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,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,5 @@
|
|
|
1
|
+
import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
|
|
2
|
+
import { PrismaClientKnownRequestError, PrismaClientValidationError } from '@prisma/client/runtime/library';
|
|
3
|
+
export declare class PrismaExceptionFilter implements ExceptionFilter {
|
|
4
|
+
catch(exception: PrismaClientKnownRequestError | PrismaClientValidationError, host: ArgumentsHost): void;
|
|
5
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PrismaExceptionFilter = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const library_1 = require("@prisma/client/runtime/library");
|
|
12
|
+
const prisma_error_mapper_1 = require("../errors/prisma-error.mapper");
|
|
13
|
+
let PrismaExceptionFilter = class PrismaExceptionFilter {
|
|
14
|
+
catch(exception, host) {
|
|
15
|
+
const ctx = host.switchToHttp();
|
|
16
|
+
const response = ctx.getResponse();
|
|
17
|
+
if (exception instanceof library_1.PrismaClientValidationError) {
|
|
18
|
+
response.status(400).json({
|
|
19
|
+
success: false,
|
|
20
|
+
error: {
|
|
21
|
+
code: prisma_error_mapper_1.PRISMA_ERROR_CODES.DATABASE_ERROR,
|
|
22
|
+
message: 'Invalid query parameters',
|
|
23
|
+
args: { message: exception.message },
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const appException = prisma_error_mapper_1.PrismaErrorMapper.map(exception);
|
|
29
|
+
response.status(appException.httpStatus || 500).json({
|
|
30
|
+
success: false,
|
|
31
|
+
error: {
|
|
32
|
+
code: appException.code,
|
|
33
|
+
message: appException.message || 'A database error occurred',
|
|
34
|
+
args: appException.args,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.PrismaExceptionFilter = PrismaExceptionFilter;
|
|
40
|
+
exports.PrismaExceptionFilter = PrismaExceptionFilter = __decorate([
|
|
41
|
+
(0, common_1.Catch)(library_1.PrismaClientKnownRequestError, library_1.PrismaClientValidationError)
|
|
42
|
+
], PrismaExceptionFilter);
|
|
43
|
+
//# sourceMappingURL=prisma-exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma-exception.filter.js","sourceRoot":"","sources":["../../lib/filter/prisma-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAuE;AACvE,4DAGwC;AACxC,uEAAsF;AAyB/E,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAChC,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;YACrD,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACxB,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,wCAAkB,CAAC,cAAc;oBACvC,OAAO,EAAE,0BAA0B;oBACnC,IAAI,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE;iBACrC;aACF,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAGD,MAAM,YAAY,GAAG,uCAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAGtD,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;YACnD,OAAO,EAAE,KAAK;YACd,KAAK,EAAE;gBACL,IAAI,EAAE,YAAY,CAAC,IAAI;gBACvB,OAAO,EAAE,YAAY,CAAC,OAAO,IAAI,2BAA2B;gBAC5D,IAAI,EAAE,YAAY,CAAC,IAAI;aACxB;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA/BY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,cAAK,EAAC,uCAA6B,EAAE,qCAA2B,CAAC;GACrD,qBAAqB,CA+BjC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './prisma.constants';
|
|
2
|
+
export * from './prisma.interfaces';
|
|
3
|
+
export * from './prisma.module';
|
|
4
|
+
export * from './prisma.service';
|
|
5
|
+
export * from './prisma.decorator';
|
|
6
|
+
export * from './prisma.health';
|
|
7
|
+
export * from './pagination';
|
|
8
|
+
export * from './testing';
|
|
9
|
+
export * from './errors/prisma-error.mapper';
|
|
10
|
+
export * from './filter/prisma-exception.filter';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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.constants"), exports);
|
|
18
|
+
__exportStar(require("./prisma.interfaces"), exports);
|
|
19
|
+
__exportStar(require("./prisma.module"), exports);
|
|
20
|
+
__exportStar(require("./prisma.service"), exports);
|
|
21
|
+
__exportStar(require("./prisma.decorator"), exports);
|
|
22
|
+
__exportStar(require("./prisma.health"), exports);
|
|
23
|
+
__exportStar(require("./pagination"), exports);
|
|
24
|
+
__exportStar(require("./testing"), exports);
|
|
25
|
+
__exportStar(require("./errors/prisma-error.mapper"), exports);
|
|
26
|
+
__exportStar(require("./filter/prisma-exception.filter"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './paginate';
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./paginate"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/pagination/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Page } from '@nathapp/nestjs-common';
|
|
2
|
+
import type { IPageOption } from '@nathapp/nestjs-common';
|
|
3
|
+
export declare function Paginate<T>(model: {
|
|
4
|
+
findMany(args?: any): Promise<T[]>;
|
|
5
|
+
count(args?: any): Promise<number>;
|
|
6
|
+
}, pageOption: IPageOption | any, args?: {
|
|
7
|
+
where?: any;
|
|
8
|
+
orderBy?: any;
|
|
9
|
+
include?: any;
|
|
10
|
+
select?: any;
|
|
11
|
+
}): Promise<Page<T>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Paginate = Paginate;
|
|
4
|
+
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
5
|
+
async function Paginate(model, pageOption, args) {
|
|
6
|
+
const { skip, take } = (0, nestjs_common_1.resolvePageOption)(pageOption);
|
|
7
|
+
const findManyArgs = {
|
|
8
|
+
skip,
|
|
9
|
+
take,
|
|
10
|
+
};
|
|
11
|
+
if (args) {
|
|
12
|
+
if (args.where !== undefined)
|
|
13
|
+
findManyArgs.where = args.where;
|
|
14
|
+
if (args.orderBy !== undefined)
|
|
15
|
+
findManyArgs.orderBy = args.orderBy;
|
|
16
|
+
if (args.include !== undefined)
|
|
17
|
+
findManyArgs.include = args.include;
|
|
18
|
+
if (args.select !== undefined)
|
|
19
|
+
findManyArgs.select = args.select;
|
|
20
|
+
}
|
|
21
|
+
const [records, total] = await Promise.all([
|
|
22
|
+
model.findMany(findManyArgs),
|
|
23
|
+
model.count({ where: args === null || args === void 0 ? void 0 : args.where }),
|
|
24
|
+
]);
|
|
25
|
+
return new nestjs_common_1.Page(pageOption, total, records);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=paginate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginate.js","sourceRoot":"","sources":["../../lib/pagination/paginate.ts"],"names":[],"mappings":";;AAUA,4BAiCC;AA3CD,0DAAiE;AAU1D,KAAK,UAAU,QAAQ,CAC5B,KAGC,EACD,UAA6B,EAC7B,IAKC;IAED,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAA,iCAAiB,EAAC,UAAU,CAAC,CAAC;IAErD,MAAM,YAAY,GAAQ;QACxB,IAAI;QACJ,IAAI;KACL,CAAC;IAEF,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;YAAE,YAAY,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAC9D,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;YAAE,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QACpE,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;YAAE,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QACpE,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACnE,CAAC;IAED,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACzC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC;QAC5B,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,EAAE,CAAC;KACpC,CAAC,CAAC;IAEH,OAAO,IAAI,oBAAI,CAAI,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPrismaToken = exports.PRISMA_MODULE_OPTIONS = exports.DEFAULT_PRISMA_CONNECTION = void 0;
|
|
4
|
+
exports.DEFAULT_PRISMA_CONNECTION = 'default';
|
|
5
|
+
exports.PRISMA_MODULE_OPTIONS = Symbol('PRISMA_MODULE_OPTIONS');
|
|
6
|
+
const getPrismaToken = (name) => name && name !== exports.DEFAULT_PRISMA_CONNECTION
|
|
7
|
+
? `PRISMA_SERVICE_${name}`
|
|
8
|
+
: 'PRISMA_SERVICE_DEFAULT';
|
|
9
|
+
exports.getPrismaToken = getPrismaToken;
|
|
10
|
+
//# sourceMappingURL=prisma.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.constants.js","sourceRoot":"","sources":["../lib/prisma.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,yBAAyB,GAAG,SAAS,CAAC;AACtC,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAK9D,MAAM,cAAc,GAAG,CAAC,IAAa,EAAU,EAAE,CACtD,IAAI,IAAI,IAAI,KAAK,iCAAyB;IACxC,CAAC,CAAC,kBAAkB,IAAI,EAAE;IAC1B,CAAC,CAAC,wBAAwB,CAAC;AAHlB,QAAA,cAAc,kBAGI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const InjectPrisma: (name?: string) => PropertyDecorator & ParameterDecorator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectPrisma = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const prisma_constants_1 = require("./prisma.constants");
|
|
6
|
+
const InjectPrisma = (name) => (0, common_1.Inject)((0, prisma_constants_1.getPrismaToken)(name));
|
|
7
|
+
exports.InjectPrisma = InjectPrisma;
|
|
8
|
+
//# sourceMappingURL=prisma.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.decorator.js","sourceRoot":"","sources":["../lib/prisma.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,yDAAoD;AAM7C,MAAM,YAAY,GAAG,CAAC,IAAa,EAAE,EAAE,CAAC,IAAA,eAAM,EAAC,IAAA,iCAAc,EAAC,IAAI,CAAC,CAAC,CAAC;AAA/D,QAAA,YAAY,gBAAmD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PrismaService } from './prisma.service';
|
|
2
|
+
export interface HealthCheckResult {
|
|
3
|
+
status: 'up' | 'down';
|
|
4
|
+
message?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class PrismaHealthIndicator {
|
|
7
|
+
private readonly prismaService;
|
|
8
|
+
constructor(prismaService: PrismaService);
|
|
9
|
+
isHealthy(): Promise<HealthCheckResult>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PrismaHealthIndicator = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
let PrismaHealthIndicator = class PrismaHealthIndicator {
|
|
15
|
+
constructor(prismaService) {
|
|
16
|
+
this.prismaService = prismaService;
|
|
17
|
+
}
|
|
18
|
+
async isHealthy() {
|
|
19
|
+
try {
|
|
20
|
+
const client = this.prismaService.client;
|
|
21
|
+
if (client.$queryRaw) {
|
|
22
|
+
if (!this.prismaService.isConnected) {
|
|
23
|
+
return { status: 'down', message: 'Not connected' };
|
|
24
|
+
}
|
|
25
|
+
await client.$queryRaw `SELECT 1`;
|
|
26
|
+
return { status: 'up' };
|
|
27
|
+
}
|
|
28
|
+
if (this.prismaService.isConnected) {
|
|
29
|
+
return { status: 'up' };
|
|
30
|
+
}
|
|
31
|
+
return { status: 'down', message: 'Not connected' };
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const message = error && typeof error === 'object' && 'message' in error
|
|
35
|
+
? String(error.message)
|
|
36
|
+
: 'Health check failed';
|
|
37
|
+
return { status: 'down', message };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.PrismaHealthIndicator = PrismaHealthIndicator;
|
|
42
|
+
exports.PrismaHealthIndicator = PrismaHealthIndicator = __decorate([
|
|
43
|
+
(0, common_1.Injectable)(),
|
|
44
|
+
__metadata("design:paramtypes", [Function])
|
|
45
|
+
], PrismaHealthIndicator);
|
|
46
|
+
//# sourceMappingURL=prisma.health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.health.js","sourceRoot":"","sources":["../lib/prisma.health.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AASrC,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAChC,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAE7D,KAAK,CAAC,SAAS;QACb,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,MAAa,CAAC;YAGhD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;gBAErB,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;oBACpC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;gBACtD,CAAC;gBACD,MAAM,MAAM,CAAC,SAAS,CAAA,UAAU,CAAC;gBACjC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;YAC1B,CAAC;YAGD,IAAI,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;gBACnC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;YAC1B,CAAC;YAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK;gBACtE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;gBACvB,CAAC,CAAC,qBAAqB,CAAC;YAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QACrC,CAAC;IACH,CAAC;CACF,CAAA;AA9BY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;;GACA,qBAAqB,CA8BjC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
export interface PrismaClientLike {
|
|
3
|
+
$connect(): Promise<void>;
|
|
4
|
+
$disconnect(): Promise<void>;
|
|
5
|
+
$on?(event: string, listener: (...args: any[]) => void): void;
|
|
6
|
+
}
|
|
7
|
+
export interface PrismaModuleOptions {
|
|
8
|
+
name?: string;
|
|
9
|
+
client?: new (options?: any) => PrismaClientLike;
|
|
10
|
+
clientOptions?: Record<string, any>;
|
|
11
|
+
isGlobal?: boolean;
|
|
12
|
+
logging?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface PrismaModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
15
|
+
name?: string;
|
|
16
|
+
isGlobal?: boolean;
|
|
17
|
+
useFactory?: (...args: any[]) => PrismaModuleOptions | Promise<PrismaModuleOptions>;
|
|
18
|
+
inject?: any[];
|
|
19
|
+
useClass?: Type<PrismaOptionsFactory>;
|
|
20
|
+
useExisting?: Type<PrismaOptionsFactory>;
|
|
21
|
+
}
|
|
22
|
+
export interface PrismaOptionsFactory {
|
|
23
|
+
createPrismaOptions(): PrismaModuleOptions | Promise<PrismaModuleOptions>;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.interfaces.js","sourceRoot":"","sources":["../lib/prisma.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import type { PrismaModuleOptions, PrismaModuleAsyncOptions } from './prisma.interfaces';
|
|
3
|
+
export declare class PrismaModule {
|
|
4
|
+
static forRoot(options: PrismaModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: PrismaModuleAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncProviders;
|
|
7
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
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 PrismaModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.PrismaModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const prisma_service_1 = require("./prisma.service");
|
|
13
|
+
const prisma_constants_1 = require("./prisma.constants");
|
|
14
|
+
let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
15
|
+
static forRoot(options) {
|
|
16
|
+
const { isGlobal = true, name } = options;
|
|
17
|
+
const connectionToken = (0, prisma_constants_1.getPrismaToken)(name);
|
|
18
|
+
const prismaServiceProvider = {
|
|
19
|
+
provide: connectionToken,
|
|
20
|
+
useFactory: () => new prisma_service_1.PrismaService(options),
|
|
21
|
+
};
|
|
22
|
+
const providers = [prismaServiceProvider];
|
|
23
|
+
if (!name || name === 'default') {
|
|
24
|
+
providers.push({
|
|
25
|
+
provide: prisma_service_1.PrismaService,
|
|
26
|
+
useExisting: connectionToken,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
module: PrismaModule_1,
|
|
31
|
+
global: isGlobal,
|
|
32
|
+
providers,
|
|
33
|
+
exports: providers,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
static forRootAsync(options) {
|
|
37
|
+
const { isGlobal = true, name } = options;
|
|
38
|
+
const connectionToken = (0, prisma_constants_1.getPrismaToken)(name);
|
|
39
|
+
const asyncProviders = this.createAsyncProviders(options, connectionToken);
|
|
40
|
+
const providers = [...asyncProviders];
|
|
41
|
+
if (!name || name === 'default') {
|
|
42
|
+
providers.push({
|
|
43
|
+
provide: prisma_service_1.PrismaService,
|
|
44
|
+
useExisting: connectionToken,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
module: PrismaModule_1,
|
|
49
|
+
global: isGlobal,
|
|
50
|
+
imports: options.imports || [],
|
|
51
|
+
providers,
|
|
52
|
+
exports: providers,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
static createAsyncProviders(options, connectionToken) {
|
|
56
|
+
if (options.useFactory) {
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
provide: prisma_constants_1.PRISMA_MODULE_OPTIONS,
|
|
60
|
+
useFactory: options.useFactory,
|
|
61
|
+
inject: options.inject || [],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
provide: connectionToken,
|
|
65
|
+
useFactory: (moduleOptions) => new prisma_service_1.PrismaService(moduleOptions),
|
|
66
|
+
inject: [prisma_constants_1.PRISMA_MODULE_OPTIONS],
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
if (options.useClass) {
|
|
71
|
+
return [
|
|
72
|
+
{
|
|
73
|
+
provide: options.useClass,
|
|
74
|
+
useClass: options.useClass,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
provide: prisma_constants_1.PRISMA_MODULE_OPTIONS,
|
|
78
|
+
useFactory: async (optionsFactory) => await optionsFactory.createPrismaOptions(),
|
|
79
|
+
inject: [options.useClass],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
provide: connectionToken,
|
|
83
|
+
useFactory: (moduleOptions) => new prisma_service_1.PrismaService(moduleOptions),
|
|
84
|
+
inject: [prisma_constants_1.PRISMA_MODULE_OPTIONS],
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
if (options.useExisting) {
|
|
89
|
+
return [
|
|
90
|
+
{
|
|
91
|
+
provide: prisma_constants_1.PRISMA_MODULE_OPTIONS,
|
|
92
|
+
useFactory: async (optionsFactory) => await optionsFactory.createPrismaOptions(),
|
|
93
|
+
inject: [options.useExisting],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
provide: connectionToken,
|
|
97
|
+
useFactory: (moduleOptions) => new prisma_service_1.PrismaService(moduleOptions),
|
|
98
|
+
inject: [prisma_constants_1.PRISMA_MODULE_OPTIONS],
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
throw new Error('Invalid PrismaModuleAsyncOptions: must provide useFactory, useClass, or useExisting');
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
exports.PrismaModule = PrismaModule;
|
|
106
|
+
exports.PrismaModule = PrismaModule = PrismaModule_1 = __decorate([
|
|
107
|
+
(0, common_1.Module)({})
|
|
108
|
+
], PrismaModule);
|
|
109
|
+
//# sourceMappingURL=prisma.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.module.js","sourceRoot":"","sources":["../lib/prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AAEjE,qDAAiD;AACjD,yDAA2E;AAGpE,IAAM,YAAY,oBAAlB,MAAM,YAAY;IACvB,MAAM,CAAC,OAAO,CAAC,OAA4B;QACzC,MAAM,EAAE,QAAQ,GAAG,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QAC1C,MAAM,eAAe,GAAG,IAAA,iCAAc,EAAC,IAAI,CAAC,CAAC;QAE7C,MAAM,qBAAqB,G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