From 03c9088a02519d9caae52937c574c400e1617f57 Mon Sep 17 00:00:00 2001 From: Supan Adit Pratama Date: Sat, 26 Oct 2024 19:15:42 +0700 Subject: [PATCH] wip: prisma support --- libs/prisma/src/index.ts | 2 + libs/prisma/src/prisma.module.ts | 8 +++ libs/prisma/src/prisma.service.spec.ts | 18 ++++++ libs/prisma/src/prisma.service.ts | 9 +++ libs/prisma/tsconfig.lib.json | 9 +++ nest-cli.json | 9 +++ package-lock.json | 90 ++++++++++++++++++++++++++ package.json | 7 +- test/jest-e2e.json | 4 +- tsconfig.json | 6 ++ 10 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 libs/prisma/src/index.ts create mode 100644 libs/prisma/src/prisma.module.ts create mode 100644 libs/prisma/src/prisma.service.spec.ts create mode 100644 libs/prisma/src/prisma.service.ts create mode 100644 libs/prisma/tsconfig.lib.json diff --git a/libs/prisma/src/index.ts b/libs/prisma/src/index.ts new file mode 100644 index 0000000..8bb71d7 --- /dev/null +++ b/libs/prisma/src/index.ts @@ -0,0 +1,2 @@ +export * from './prisma.module'; +export * from './prisma.service'; diff --git a/libs/prisma/src/prisma.module.ts b/libs/prisma/src/prisma.module.ts new file mode 100644 index 0000000..ec0ce32 --- /dev/null +++ b/libs/prisma/src/prisma.module.ts @@ -0,0 +1,8 @@ +import { Module } from '@nestjs/common'; +import { PrismaService } from './prisma.service'; + +@Module({ + providers: [PrismaService], + exports: [PrismaService], +}) +export class PrismaModule {} diff --git a/libs/prisma/src/prisma.service.spec.ts b/libs/prisma/src/prisma.service.spec.ts new file mode 100644 index 0000000..a68cb9e --- /dev/null +++ b/libs/prisma/src/prisma.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { PrismaService } from './prisma.service'; + +describe('PrismaService', () => { + let service: PrismaService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [PrismaService], + }).compile(); + + service = module.get(PrismaService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/libs/prisma/src/prisma.service.ts b/libs/prisma/src/prisma.service.ts new file mode 100644 index 0000000..359f950 --- /dev/null +++ b/libs/prisma/src/prisma.service.ts @@ -0,0 +1,9 @@ +import { Injectable, OnModuleInit } from '@nestjs/common'; +import { PrismaClient } from '@prisma/client'; + +@Injectable() +export class PrismaService extends PrismaClient implements OnModuleInit { + async onModuleInit() { + await this.$connect(); + } +} diff --git a/libs/prisma/tsconfig.lib.json b/libs/prisma/tsconfig.lib.json new file mode 100644 index 0000000..e350873 --- /dev/null +++ b/libs/prisma/tsconfig.lib.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "../../dist/libs/prisma" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] +} diff --git a/nest-cli.json b/nest-cli.json index ee8a6db..c85f899 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -15,6 +15,15 @@ "compilerOptions": { "tsConfigPath": "libs/skeleton/tsconfig.lib.json" } + }, + "prisma": { + "type": "library", + "root": "libs/prisma", + "entryFile": "index", + "sourceRoot": "libs/prisma/src", + "compilerOptions": { + "tsConfigPath": "libs/prisma/tsconfig.lib.json" + } } } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8d79c21..60de65a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", + "@prisma/client": "^5.21.1", "esm": "^3.2.25", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1" @@ -31,6 +32,7 @@ "eslint-plugin-prettier": "^5.0.0", "jest": "^29.5.0", "prettier": "^3.0.0", + "prisma": "^5.21.1", "source-map-support": "^0.5.21", "supertest": "^7.0.0", "ts-jest": "^29.1.0", @@ -2036,6 +2038,74 @@ "url": "https://opencollective.com/unts" } }, + "node_modules/@prisma/client": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.21.1.tgz", + "integrity": "sha512-3n+GgbAZYjaS/k0M03yQsQfR1APbr411r74foknnsGpmhNKBG49VuUkxIU6jORgvJPChoD4WC4PqoHImN1FP0w==", + "hasInstallScript": true, + "license": "Apache-2.0", + "engines": { + "node": ">=16.13" + }, + "peerDependencies": { + "prisma": "*" + }, + "peerDependenciesMeta": { + "prisma": { + "optional": true + } + } + }, + "node_modules/@prisma/debug": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.21.1.tgz", + "integrity": "sha512-uY8SAhcnORhvgtOrNdvWS98Aq/nkQ9QDUxrWAgW8XrCZaI3j2X7zb7Xe6GQSh6xSesKffFbFlkw0c2luHQviZA==", + "devOptional": true, + "license": "Apache-2.0" + }, + "node_modules/@prisma/engines": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.21.1.tgz", + "integrity": "sha512-hGVTldUkIkTwoV8//hmnAAiAchi4oMEKD3aW5H2RrnI50tTdwza7VQbTTAyN3OIHWlK5DVg6xV7X8N/9dtOydA==", + "devOptional": true, + "hasInstallScript": true, + "license": "Apache-2.0", + "dependencies": { + "@prisma/debug": "5.21.1", + "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "@prisma/fetch-engine": "5.21.1", + "@prisma/get-platform": "5.21.1" + } + }, + "node_modules/@prisma/engines-version": { + "version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz", + "integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==", + "devOptional": true, + "license": "Apache-2.0" + }, + "node_modules/@prisma/fetch-engine": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.21.1.tgz", + "integrity": "sha512-70S31vgpCGcp9J+mh/wHtLCkVezLUqe/fGWk3J3JWZIN7prdYSlr1C0niaWUyNK2VflLXYi8kMjAmSxUVq6WGQ==", + "devOptional": true, + "license": "Apache-2.0", + "dependencies": { + "@prisma/debug": "5.21.1", + "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "@prisma/get-platform": "5.21.1" + } + }, + "node_modules/@prisma/get-platform": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.21.1.tgz", + "integrity": "sha512-sRxjL3Igst3ct+e8ya/x//cDXmpLbZQ5vfps2N4tWl4VGKQAmym77C/IG/psSMsQKszc8uFC/q1dgmKFLUgXZQ==", + "devOptional": true, + "license": "Apache-2.0", + "dependencies": { + "@prisma/debug": "5.21.1" + } + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -7385,6 +7455,26 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/prisma": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.21.1.tgz", + "integrity": "sha512-PB+Iqzld/uQBPaaw2UVIk84kb0ITsLajzsxzsadxxl54eaU5Gyl2/L02ysivHxK89t7YrfQJm+Ggk37uvM70oQ==", + "devOptional": true, + "hasInstallScript": true, + "license": "Apache-2.0", + "dependencies": { + "@prisma/engines": "5.21.1" + }, + "bin": { + "prisma": "build/index.js" + }, + "engines": { + "node": ">=16.13" + }, + "optionalDependencies": { + "fsevents": "2.3.3" + } + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", diff --git a/package.json b/package.json index 3198603..9613576 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", + "@prisma/client": "^5.21.1", "esm": "^3.2.25", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1" @@ -43,6 +44,7 @@ "eslint-plugin-prettier": "^5.0.0", "jest": "^29.5.0", "prettier": "^3.0.0", + "prisma": "^5.21.1", "source-map-support": "^0.5.21", "supertest": "^7.0.0", "ts-jest": "^29.1.0", @@ -72,7 +74,8 @@ "/libs/" ], "moduleNameMapper": { - "^@autocrud/skeleton(|/.*)$": "/libs/skeleton/src/$1" + "^@autocrud/skeleton(|/.*)$": "/libs/skeleton/src/$1", + "^@autocrud/prisma(|/.*)$": "/libs/prisma/src/$1" } } -} \ No newline at end of file +} diff --git a/test/jest-e2e.json b/test/jest-e2e.json index 7bd7c70..0cae2df 100644 --- a/test/jest-e2e.json +++ b/test/jest-e2e.json @@ -12,6 +12,8 @@ }, "moduleNameMapper": { "@autocrud/skeleton/(.*)": "/../libs/skeleton/src/$1", - "@autocrud/skeleton": "/../libs/skeleton/src" + "@autocrud/skeleton": "/../libs/skeleton/src", + "@autocrud/prisma/(.*)": "/../libs/prisma/src/$1", + "@autocrud/prisma": "/../libs/prisma/src" } } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 791086a..a2de892 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,6 +23,12 @@ ], "@autocrud/skeleton/*": [ "libs/skeleton/src/*" + ], + "@autocrud/prisma": [ + "libs/prisma/src" + ], + "@autocrud/prisma/*": [ + "libs/prisma/src/*" ] } }