npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nestjs-typeorm3-kit

v0.1.8

Published

NestJS utilities for TypeORM v0.3+

Readme

nestjs-typeorm3-kit

npm MIT License

[Node.js] nestjs-typeorm3-kit

Installation

NPM

npm install nestjs-typeorm3-kit typeorm-transactional

Yarn

yarn add nestjs-typeorm3-kit typeorm-transactional

pnpm

pnpm add nestjs-typeorm3-kit typeorm-transactional

bun

bun add nestjs-typeorm3-kit typeorm-transactional

Config after install

Use @DefEntityRepository

For using @DefEntityRepository instead of @EntityRepository of typeorm 0.2, you need to add the following code in main.ts or app.module.ts:

import { TypeOrmModule } from "@nestjs/typeorm";

TypeOrmModule.forRootAsync({
  useFactory: () => ({
    type: "postgres",
    host: "localhost",
    port: 5432,
    username: "postgres",
    password: "Abc12345",
    database: "primary_db",
    entities: [join(__dirname, "./domains/primary/**/*.entity.{ts,js}")],
    synchronize: true,
    autoLoadEntities: true,
    retryAttempts: 2,
    retryDelay: 1000,
  }),
  dataSourceFactory: async (options: DataSourceOptions) => {
    if (!options) {
      throw new Error("Invalid options passed");
    }
    return addTransactionalDataSource({
      dataSource: new DataSource(options),
      name: PRIMARY_CONNECTION,
    });
  },
});

Use RepositoryWrapper fix findOne typeOrm (change return first to return null)

import { RepositoryWrapper } from "nestjs-typeorm3-kit";

export class BaseRepo<Entity> extends RepositoryWrapper<Entity> {}

create Repository module Use @DefRepositoryModule

import { Module } from "@nestjs/common";
import { join } from "path";

import { PRIMARY_CONNECTION } from "~/common/constants";
import { DefRepositoryModule } from "nestjs-typeorm3-kit";
@Module({
  imports: [
    DefRepositoryModule.forRootAsync({
      useFactory: () => ({
        globPattern: join(__dirname, "./**/*.repo.{ts,js}"),
        dataSource: PRIMARY_CONNECTION,
      }),
    }),
  ],
  exports: [DefRepositoryModule],
})
export class PrimaryRepoModule {}

or

import { Module } from "@nestjs/common";
import { join } from "path";

import { PRIMARY_CONNECTION } from "~/common/constants";
import { DefRepositoryModule } from "nestjs-typeorm3-kit";
@Module({
  imports: [
    DefRepositoryModule.forFeature([BookRepo, PhotoRepo], PRIMARY_CONNECTION),
  ],
  exports: [DefRepositoryModule],
})
export class PrimaryRepoModule {}

Use @DefTransaction

import { Injectable } from "@nestjs/common";
import { DefTransaction, InjectRepo } from "nestjs-typeorm3-kit";
import { PhotoRepo } from "~/domains/primary/photo/photo.repo";
import { BookRepo } from "~/domains/primary/book/book.repo";

const PRIMARY_CONNECTION = "default";
const SECONDARY_CONNECTION = "secondary_db";
@Injectable()
export class DemoService {
  constructor(
    readonly photoRepo: PhotoRepo,
    @InjectRepo(BookRepo, PRIMARY_CONNECTION)
    readonly bookRepo: BookRepo
  ) {}

  @DefTransaction()
  create(body: any) {
    return this.photoRepo.save(body);
  }
}

// secondary connection
@Injectable()
export class DemoService {
  constructor(
    @InjectRepo(ExampleRepo, SECONDARY_CONNECTION)
    readonly exampleRepo: ExampleRepo,
    @InjectRepo(DataLogRepo, SECONDARY_CONNECTION)
    readonly dataLogRepo: DataLogRepo
  ) {}

  @DefTransaction({ connectionName: SECONDARY_CONNECTION })
  create(body: any) {
    return this.photoRepo.save(body);
  }
}

Use wraper Controller and ChildModule

import { DefController } from "nestjs-typeorm3-kit";

@Controller("demo")
export class DemoController {
  constructor(private readonly demoService: DemoService) {}

  @DefGet()
  list(@Query() query: any) {
    return this.demoService.list(query);
  }

  @DefPost()
  create(@Body() body: any) {
    return this.demoService.create(body);
  }
}

// child module suport prefix route and API TAG swagger
@ChildModule({
  prefix: REFIX_MODULE.client,
  imports: [PrimaryRepoModule, SecondaryRepoModule],
  providers: [DemoService, ExampleService],
  controllers: [ExampleController, DemoController],
})
export class ClientModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {}
}
// setup swagger beautiful in main.ts
// main.ts
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import { getFromContainer, MetadataStorage } from "class-validator";
import { SchemasObject } from "@nestjs/swagger/dist/interfaces/open-api-spec.interface";

import { validationMetadatasToSchemas } from "class-validator-jsonschema";
import { setupTransactionContext } from "nestjs-typeorm3-kit";
import { INestApplication } from "@nestjs/common";

const configSwagger = (app: INestApplication) => {
  const options = new DocumentBuilder()
    .setTitle("SWAGGER_TITLE")
    .setDescription("SWAGGER_DESCRIPTION")
    .setVersion("SWAGGER_VERSION")
    .addSecurity("bearer", {
      type: "http",
      scheme: "bearer",
      bearerFormat: "JWT",
    })
    .build();

  const document = SwaggerModule.createDocument(app as any, options, {
    // extraModels: [PageResponse]
  });
  configSwaggerDocument(app, document, "swagger");
};

async function bootstrap() {
  setupTransactionContext();
  const app = await NestFactory.create(AppModule);
  const port = process.env.PORT || 3000;
  app.enableCors({ origin: "*" });
  configSwagger(app);
  await app.listen(port);
  console.log(
    `Server start on port ${port}. Open http://localhost:${port} to see results`
  );
  console.log(`API DOCUMENT Open http://localhost:${port}/swagger`);
  console.log(`API DOCUMENT JSON Open http://localhost:${port}/swagger-json`);
  console.log("TIMEZONE: ", process.env.TZ);
}
bootstrap();

Swagger UI

Example

Example

Full document in wiki github

FULL DOCUMENT