Skip to content
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c60e950
docs: fix bruno path
joshunrau Jun 9, 2025
96ef524
refactor: extract PrismaExtension
joshunrau Jun 9, 2025
c91ef4d
refactor: simplify prisma types
joshunrau Jun 9, 2025
aa4c843
chore: update prisma
joshunrau Jun 9, 2025
72a1b7b
chore: merge branch 'main' into dev
joshunrau Jun 9, 2025
b30ebc3
refactor: replace ExtendedPrismaClient with PrismaClientLike where po…
joshunrau Jun 9, 2025
0a0958f
refactor: allow passing all PrismaClientOptions
joshunrau Jun 9, 2025
9537607
refactor: adjust PrismaModuleOptions
joshunrau Jun 9, 2025
a2eafc9
refactor: use custom prisma client constructor
joshunrau Jun 9, 2025
99e807a
refactor: remove generic
joshunrau Jun 9, 2025
c29a680
refactor: remove PrismaClientFactory
joshunrau Jun 9, 2025
4c36acf
refactor: prisma generics
joshunrau Jun 9, 2025
1c01f4b
refactor: fix generic implementations
joshunrau Jun 10, 2025
d0d92f2
chore: add applySwaggerMetadata utility
joshunrau Jun 10, 2025
2c05fa0
chore: update applySwaggerMetadata
joshunrau Jun 10, 2025
b175daf
chore: adjust io
joshunrau Jun 10, 2025
25a66c4
chore: apply swagger metadata in decorators
joshunrau Jun 10, 2025
2aefe1a
refactor: applySwaggerMetadata implementation
joshunrau Jun 10, 2025
2aa178a
chore: remove IntersectionType
joshunrau Jun 10, 2025
38e0a46
test: restore coverage to 100%
joshunrau Jun 10, 2025
84c702d
feat: allow users to define custom prisma extensions
joshunrau Jun 10, 2025
38b2796
refactor: centralize user types
joshunrau Jun 10, 2025
2c97691
refactor: move custom user types
joshunrau Jun 10, 2025
e78e094
refactor: move jwt payload to UserTypes
joshunrau Jun 10, 2025
ccdbea8
refactor: locale type
joshunrau Jun 10, 2025
0caf5de
chore: remove CustomTypeOptions
joshunrau Jun 10, 2025
782f293
refactor: remove Zod schemas for token payload and metadata
joshunrau Jun 10, 2025
844e2ef
fix: issue where mixin class names are set to target
joshunrau Jun 10, 2025
3f9ef5d
chore: update types
joshunrau Jun 11, 2025
c17be4c
refactor: swagger metadata
joshunrau Jun 11, 2025
cc239a9
refactor: update swagger metadata
joshunrau Jun 11, 2025
8b246ea
chore: handle required in swagger metadata
joshunrau Jun 11, 2025
dbec69a
test: update
joshunrau Jun 11, 2025
1c5ba88
test: update
joshunrau Jun 11, 2025
522258b
chore: update getSwaggerPropertyMetadata to handle other cases
joshunrau Jun 11, 2025
c1b7c9b
test: update
joshunrau Jun 11, 2025
3311b67
test: array case
joshunrau Jun 11, 2025
c5f8a0e
test: error case in swagger metadata
joshunrau Jun 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bruno/collection.bru
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ script:pre-request {
const baseUrl = 'http://localhost:5500';
const username = 'admin';
const password = 'password';
const response = await axios.post(`${baseUrl}/v1/auth/login`, {
const response = await axios.post(`${baseUrl}/auth/login`, {
username,
password
});
Expand Down
4 changes: 4 additions & 0 deletions example/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */

import { PrismaClient } from '@prisma/client';

Check failure on line 3 in example/app.ts

View workflow job for this annotation

GitHub Actions / ci

Module '"@prisma/client"' has no exported member 'PrismaClient'.
import { z } from 'zod/v4';

import { $BaseEnv, AppFactory, AuthModule, CryptoService } from '../src/index.js';
Expand Down Expand Up @@ -55,6 +56,9 @@
}
},
prisma: {
client: {
constructor: PrismaClient
},
dbPrefix: 'libnest-example',
useInMemoryDbForTesting: true
},
Expand Down
4 changes: 2 additions & 2 deletions example/cats/cats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Injectable, InternalServerErrorException } from '@nestjs/common';

import { InjectPrismaClient } from '../../src/index.js';

import type { ExtendedPrismaClient } from '../../src/index.js';
import type { PrismaClientLike } from '../../src/index.js';
import type { Cat } from './schemas/cat.schema.js';

@Injectable()
export class CatsService {
constructor(@InjectPrismaClient() private readonly prismaClient: ExtendedPrismaClient) {}
constructor(@InjectPrismaClient() private readonly prismaClient: PrismaClientLike) {}

async create(cat: Omit<Cat, '_id'>): Promise<Cat> {
const id = crypto.randomUUID();
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@nestjs/core": "^11.0.11",
"@nestjs/platform-express": "^11.0.11",
"@nestjs/testing": "^11.0.11",
"@prisma/client": "^6.5.0",
"@prisma/client": "^6.9.0",
"express": "^5.0.1",
"mongodb": "^6.14.2",
"neverthrow": "^8.2.0",
Expand All @@ -91,8 +91,8 @@
"@nestjs/passport": "^11.0.5",
"@nestjs/swagger": "^11.0.6",
"@nestjs/throttler": "^6.4.0",
"@prisma/engines": "^6.5.0",
"@prisma/get-platform": "^6.5.0",
"@prisma/engines": "^6.9.0",
"@prisma/get-platform": "^6.9.0",
"@swc-node/register": "^1.10.10",
"@swc/core": "^1.11.10",
"@swc/helpers": "^0.5.17",
Expand Down Expand Up @@ -131,7 +131,7 @@
"husky": "^9.1.7",
"knip": "^5.46.0",
"prettier": "^3.5.3",
"prisma": "^6.5.0",
"prisma": "^6.9.0",
"typedoc": "^0.27.0",
"typedoc-material-theme": "^1.3.0",
"typedoc-plugin-zod": "^1.4.0",
Expand Down
113 changes: 47 additions & 66 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 24 additions & 13 deletions src/app/__tests__/app.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import { GlobalExceptionFilter } from '../../filters/global-exception.filter.js'
import { delay } from '../../middleware/delay.middleware.js';
import { ConfigService } from '../../modules/config/config.service.js';
import { CryptoService } from '../../modules/crypto/crypto.service.js';
import { MONGO_CONNECTION_TOKEN } from '../../modules/prisma/prisma.config.js';
import { PrismaFactory } from '../../modules/prisma/prisma.factory.js';
import { ValidationPipe } from '../../pipes/validation.pipe.js';
import { $BaseEnv } from '../../schemas/env.schema.js';
import { AppFactory } from '../app.factory.js';

import type { MongoConnection } from '../../modules/prisma/connection.factory.js';
import type { PrismaModuleOptions } from '../../modules/prisma/prisma.config.js';
import type { BaseEnv } from '../../schemas/env.schema.js';
import type { CreateAppOptions } from '../app.factory.js';
Expand Down Expand Up @@ -47,6 +44,15 @@ const defaultEnv = {
const defaultAppOptions: CreateAppOptions = {
envSchema: $BaseEnv,
prisma: {
client: {
constructor: vi.fn(() => {
return {
$connect: vi.fn(),
$disconnect: vi.fn(),
$extends: vi.fn().mockReturnThis()
} as any;
})
},
dbPrefix: null
},
version: '1'
Expand Down Expand Up @@ -123,19 +129,24 @@ describe('AppFactory', () => {
});

it('should create an app with a custom prisma configuration', async () => {
const createClient = vi.spyOn(PrismaFactory.prototype, 'createClient');
const prisma: PrismaModuleOptions = {
dbPrefix: 'example',
omit: {
user: {
password: true
client: {
constructor: defaultAppOptions.prisma.client.constructor,
options: {
omit: {
user: {
password: true
}
}
}
}
},
dbPrefix: 'example'
};
const app = await createAppContainer({ prisma }).createApplicationInstance();
const mongoConnection: MongoConnection = app.get(MONGO_CONNECTION_TOKEN);
expect(createClient).toHaveBeenCalledExactlyOnceWith({ omit: prisma.omit });
expect(mongoConnection.url.href).toBe(`${defaultEnv.MONGO_URI}/example-test`);
await createAppContainer({ prisma }).createApplicationInstance();
expect(prisma.client.constructor).toHaveBeenLastCalledWith({
datasourceUrl: `${defaultEnv.MONGO_URI}/example-test`,
...prisma.client.options
});
});
});

Expand Down
6 changes: 4 additions & 2 deletions src/app/app.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { JSONLogger } from '../modules/logging/json.logger.js';
import { AbstractAppContainer } from './app.base.js';
import { configureApp } from './app.utils.js';

import type { DefaultPrismaGlobalOmitConfig } from '../modules/prisma/prisma.config.js';
import type { DefaultPrismaClientOptions } from '../modules/prisma/prisma.config.js';
import type { LibnestExtendedPrismaClient } from '../modules/prisma/prisma.extensions.js';
import type { BaseEnv } from '../schemas/env.schema.js';
import type { AppContainerParams } from './app.base.js';

export class AppContainer<
TEnv extends BaseEnv,
_TPrismaGlobalOmitConfig extends DefaultPrismaGlobalOmitConfig
_TPrismaClientOptions extends DefaultPrismaClientOptions,
_TExtendedPrismaClient extends LibnestExtendedPrismaClient
> extends AbstractAppContainer<TEnv> {
constructor(params: AppContainerParams<TEnv>) {
super(params);
Expand Down
Loading
Loading