
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
elysia-decorator
Advanced tools
This project provides a controller-based routing system for Elysia, a lightweight and fast web framework, using TypeScript decorators and Tsyringe for dependency injection. It simplifies the creation of RESTful APIs and WebSocket services with a clean, modular architecture.
@Get
, @Post
, @Put
, etc., and group them under @Controller
.@Param
and @Body
to access route parameters and request bodies.body
, response
, etc.).project-root/
├── src/
│ ├── app.controller.ts # Controller with route handlers
│ ├── app.module.ts # Module configuration
│ ├── app.service.ts # Business logic service
│ ├── app.dto.ts # Define data transfer objects
│ └── main.ts # Application entry point
└── tsconfig.json # TypeScript configuration
npm install elysia elysia-decorator tsyringe reflect-metadata
{
"compilerOptions": {
"resolveJsonModule": true,
"preserveSymlinks": true,
"target": "ES2021",
"lib": ["ESNext"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "ESNext",
"moduleResolution": "node",
"declaration": true,
"noEmit": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"baseUrl": ".",
"rootDir": "./src"
},
"exclude": ["node_modules"]
}
// src/app.dto.ts
import { type Static, Type } from 'elysia-decorator';
export const AppParams = Type.Object({
name: Type.String(),
});
export type AppParams = Static<typeof AppParams>;
export const AppPostSchema = Type.Object({
title: Type.String(),
content: Type.String(),
});
export type AppPostSchema = Static<typeof AppPostSchema>;
Define a service to encapsulate business logic:
// src/app.service.ts
import { injectable } from 'elysia-decorator';
import { AppPostSchema, AppParams } from './app.dto';
@injectable()
export class AppService {
getGreeting(params: AppParams) {
return `Hello, ${params.name}!`;
}
createPost(post: AppPostSchema) {
return { id: '123', ...post };
}
}
Define a controller with route handlers using decorators:
// src/app.controller.ts
import { type Context } from 'elysia';
import {
Controller,
Get,
Post,
Body,
Params,
Type,
Set,
} from 'elysia-decorator';
import { inject, injectable } from 'tsyringe';
import { AppParams, AppPostSchema } from './app.dto';
import { AppService } from './app.service';
@Controller('/v1')
@injectable()
export class AppController {
constructor(@inject(AppService) private appService: AppService) {}
@Get('/greet/:name', {
params: AppParams,
response: {
200: Type.String(),
},
})
async greeting(@Params() params: AppParams) {
return this.appService.getGreeting(params);
}
@Post('/posts', {
body: AppPostSchema,
response: {
201: Type.Object({
id: Type.String(),
title: Type.String(),
content: Type.String(),
}),
},
})
async createPost(@Body() body: AppPostSchema, @Set() set: Context['set']) {
set.status = 201;
return this.appService.createPost(body);
}
}
Create a module to configure your application:
// src/app.module.ts
import { Module } from 'elysia-decorator';
import { AppController } from './app.controller';
@Module({
controllers: [AppController],
})
export class AppModule {}
Initialize the Elysia app with the module:
/// src/main.tsimport { Elysia } from 'elysia';
import { useModule } from 'elysia-decorator';
import { AppModule } from './app.module';
const app = new Elysia().use(useModule(AppModule)).listen(3000);
console.log(`Server running at http://localhost:${app.server?.port}`);
bun run ./main.ts
GET Greeting
GET http://localhost:3000/v1/greet/John
Response: "Hello, John!" (200 OK)
POST Create Post
POST http://localhost:3000/v1/posts
{ "title": "My Post", "content": "Hello World" }
// Response: {
// "id": "123",
// "title": "My Post",
// "content": "Hello World"
// } (201 Created)
Use Tsyringe to inject services into controllers:
@injectable()
export class AppController {
constructor(@inject(AppService) private appService: AppService) {}
}
Contributions are welcome! Please submit a pull request or open an issue on GitHub.
FAQs
Elysia Decorator with auto DI
The npm package elysia-decorator receives a total of 13 weekly downloads. As such, elysia-decorator popularity was classified as not popular.
We found that elysia-decorator demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.