
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
grpc-typeorm-infrastructure
Advanced tools
Simple infrastructure implementation for TypeORM using gRPC Boom.
This library provides a simple wrapper around TypeORM functions in order to provide consistent and predictable error messages, it uses gRPC Boom to generate the gRPC-friendly error objects.
It is assumed that you are using the grpc
library.
npm install grpc-typeorm-infrastructure --save
Install the grpc
library:
npm install grpc --save
Create a TypeORM entity:
import {
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn
} from 'typeorm';
@Entity({ name: 'hero' })
export default class Hero {
@PrimaryGeneratedColumn()
public id?: number;
@Column({ name: 'name', length: 500 })
public name: string;
@Column({ name: 'identity', length: 500 })
public identity: string;
@Column({ name: 'hometown', length: 500 })
public hometown: string;
@Column({ name: 'age' })
public age: number;
@CreateDateColumn({ name: 'created_at', type: 'timestamp with time zone' })
public createdAt?: Date;
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp with time zone' })
public updatedAt?: Date;
@Column({ name: 'deleted_at', nullable: true, type: 'timestamp with time zone' })
public deletedAt?: Date;
}
Create a repository for the entity above:
import BaseRepository from 'grpc-typeorm-infrastructure';
import Hero from '@entities/hero.entity';
export default class HeroRepository extends BaseRepository<Hero> {
constructor() {
super(Hero.name);
}
}
Create a service for the entity above:
import { BaseService } from 'grpc-typeorm-infrastructure';
import Hero from '@entities/hero.entity';
export default class HeroService extends BaseService<Hero> {
constructor(heroRepository: HeroRepository) {
super(heroRepository);
}
public preSaveHook(hero: Hero): void {
// Executed before the save repository call
delete hero.id;
}
public preUpdateHook(hero: Hero) {
// Executed before the update repository call
delete hero.updatedAt;
}
public preDeleteHook(hero: Hero) {
// Executed before the delete repository call
hero.deletedAt = new Date();
}
public preResultHook(hero: Hero) {
// Executed before the result is returned
delete hero.deletedAt;
}
}
The base repository will give you access to the following methods:
getAll(options?: FindManyOptions<T>): Promise<T[]>;
findManyByFilter(options: FindManyOptions<T>): Promise<T[]>;
findOneById(id: number): Promise<T>;
findOneByIdWithOptions(id: number, options?: FindOneOptions<T>): Promise<T>;
findManyById(idList: number[], options?: FindOneOptions<T>): Promise<T[]>;
findOneByFilter(options: FindOneOptions<T>): Promise<T>;
save(record: T, options?: SaveOptions): Promise<T>;
saveAll(
records: T[],
options?: SaveOptions,
resolveRelations?: boolean
): Promise<T[]>;
updateOneById(id: number, record: T): Promise<T>;
deleteOneById(
id: number,
findOptions?: FindOneOptions<T>,
deleteOptions?: RemoveOptions
): Promise<T>;
deleteManyById(idList: number[], deleteOptions?: RemoveOptions): Promise<T>;
findOneWithQueryBuilder(
options: ISearchQueryBuilderOptions
): Promise<T | undefined>;
findManyWithQueryBuilder(options: ISearchQueryBuilderOptions): Promise<T[]>;
delete(record: T, options?: RemoveOptions);
The base service will give you access to the following methods:
preSaveHook(entity: T): void;
preUpdateHook(entity: T): void;
preDeleteHook(entity: T): void;
preResultHook(entity: T): void;
validId(id: number): boolean;
isValid(entity: T): Promise<boolean>;
findAll(): Promise<T[]>;
findAllByFilter(filter: FindManyOptions<T>): Promise<T[]>;
findOneById(id: number): Promise<T>;
findOneByFilter(filter: FindOneOptions<T>): Promise<T>;
findOneWithQueryBuilder(options: ISearchQueryBuilderOptions): Promise<T>;
findManyWithQueryBuilder(options: ISearchQueryBuilderOptions): Promise<T[]>;
search(limit: number, searchTerms: SearchTerm[]);
save(entity: T): Promise<T>;
saveAll(entities: T[]): Promise<T[]>;
update(entity: T, id: number): Promise<T>;
updateAll(entities: T[]): Promise<T[]>;
getSearchFilter(
limit: number,
searchTerms: SearchTerm[]
): ISearchQueryBuilderOptions;
delete(id: number): Promise<T>;
softDelete(id: number): Promise<T>;
FAQs
Simple infrastructure implementation for TypeORM using gRPC Boom.
The npm package grpc-typeorm-infrastructure receives a total of 2 weekly downloads. As such, grpc-typeorm-infrastructure popularity was classified as not popular.
We found that grpc-typeorm-infrastructure demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.