feat: add initial project configuration and smoke tests

- Created pnpm workspace configuration to manage packages.
- Added a placeholder .gitkeep file in the scripts directory.
- Implemented a smoke test script to validate core API and web endpoints.
- Established TypeScript base configuration for consistent compilation settings.
- Introduced Turbo configuration for task management and build processes.
This commit is contained in:
KinSun
2026-03-13 10:30:16 +08:00
commit 9d5616fdc6
68 changed files with 9851 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import { Test, TestingModule } from '@nestjs/testing';
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { PrismaService } from '../prisma.service.js';
import { ConfigService } from '@nestjs/config';
describe('PrismaService', () => {
let service: PrismaService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
PrismaService,
{
provide: ConfigService,
useValue: {
getOrThrow: vi.fn().mockReturnValue('postgresql://test:test@localhost:5432/test'),
},
},
],
}).compile();
service = module.get<PrismaService>(PrismaService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
it('should expose PrismaClient methods directly (extends pattern)', () => {
expect(typeof service.$connect).toBe('function');
expect(typeof service.$disconnect).toBe('function');
});
});

View File

@@ -0,0 +1,9 @@
import { Global, Module } from '@nestjs/common';
import { PrismaService } from './prisma.service.js';
@Global()
@Module({
providers: [PrismaService],
exports: [PrismaService],
})
export class PrismaModule {}

View File

@@ -0,0 +1,33 @@
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PrismaClient } from '../generated/prisma/client';
import { PrismaPg } from '@prisma/adapter-pg';
/**
* NestJS-managed Prisma service for Prisma 7.
*
* Follows the official NestJS + Prisma 7 recipe:
* - Uses `prisma-client` generator with `moduleFormat = "cjs"`
* - Extends PrismaClient directly for full type-safe API access
* - Uses PrismaPg driver adapter with connectionString
*
* Usage in feature modules:
* constructor(private readonly prisma: PrismaService) {}
* await this.prisma.placeholder.findMany();
*/
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
constructor(configService: ConfigService) {
const databaseUrl = configService.getOrThrow<string>('DATABASE_URL');
const adapter = new PrismaPg({ connectionString: databaseUrl });
super({ adapter });
}
async onModuleInit(): Promise<void> {
await this.$connect();
}
async onModuleDestroy(): Promise<void> {
await this.$disconnect();
}
}