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 🙏

© 2025 – Pkg Stats / Ryan Hefner

meteorjs-decorators

v1.0.2

Published

Meteor decorators to make your Meteor app with NestJS-style pattern.

Readme

meteorjs-decorators

NestJS-style decorators for Meteor methods, publications, dependency injection, and DTO validation.

Why

  • Keep Meteor APIs in classes instead of scattered functions.
  • Reuse services with dependency injection and simple modules.
  • Validate inputs and normalize outputs with DTOs.

Install

npm install meteorjs-decorators

Setup

Ensure TypeScript decorator metadata is enabled (already used in this repo):

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Import reflect-metadata once on server startup:

import 'reflect-metadata';

Quick start

import { Controller, Method, Auth, Validate, Dto, Injectable, BaseController } from 'meteorjs-decorators';
import { RequestDto, ResponseDto } from 'meteorjs-decorators';
import { IsEmail, IsString } from 'class-validator';

class CreateUserDto extends RequestDto {
  @IsEmail()
  email!: string;

  @IsString()
  name!: string;
}

class UserResponseDto extends ResponseDto {
  id!: string;
  email!: string;
  name!: string;

  build(user: { _id: string; email: string; name: string }): UserResponseDto {
    this.id = user._id;
    this.email = user.email;
    this.name = user.name;
    return this.send();
  }
}

@Injectable()
class UsersService {
  create(input: CreateUserDto) {
    return Meteor.users.insert({ email: input.email, name: input.name });
  }
}

@Controller()
export class UsersController extends BaseController {
  constructor(private readonly usersService: UsersService) {
    super();
  }

  @Method('users.create')
  @Auth()
  @Validate(CreateUserDto)
  @Dto(UserResponseDto)
  async createUser(input: CreateUserDto) {
    const id = this.usersService.create(input);
    return { _id: id, email: input.email, name: input.name };
  }
}

Publications (with optional DTO mapping)

import { Publication, ReactiveDto, BasePublication, Injectable } from 'meteorjs-decorators';

@Injectable()
class UsersService {
  findByOrg(orgId: string) {
    return Meteor.users.find({ orgId });
  }
}

@Publication('users.byOrg')
export class UsersPublication extends BasePublication {
  constructor(private readonly usersService: UsersService) {
    super();
  }

  @Auth()
  @Validate(UsersRequestDto)
  @ReactiveDto(UserResponseDto)
  init(requestDto: UsersRequestDto) {
    return this.usersService.findByOrg(requestDto);
  }
}

Modules and DI

import { Module, forwardRef } from 'meteorjs-decorators';

@Module({
  imports: [forwardRef(() => AuthModule)],
  providers: [UsersService],
  controllers: [UsersController],
})
export class UsersModule {}

Use @Inject(token) when you need a custom token or to resolve circular deps:

import { Inject, Injectable, forwardRef } from 'meteorjs-decorators';

@Injectable()
class BillingService {
  constructor(@Inject(forwardRef(() => UsersService)) private readonly users: UsersService) {}
}

Entities and indexes

import { Entity, Index, BaseEntity } from 'meteorjs-decorators';

@Entity('widgets')
export class WidgetEntity extends BaseEntity {
  @Index({ name: 1 }, { unique: true })
  name!: string;
}

Decorators at a glance

  • @Controller() + @Method(name) register Meteor methods.
  • @Publication(name) registers a publication; extend BasePublication.
  • @ReactiveDto(DtoClass) maps cursor changes to DTOs.
  • @Injectable() registers a provider in the container.
  • @Inject(token) supplies a custom token or forwardRef.
  • @Module({ imports, providers, controllers }) sets up a module container.
  • @Auth() enforces logged-in users (this.__context.userId).
  • @CheckPermissions(...roles) enforces Roles (from alanning:roles).
  • @Validate(...dtosOrTypes) validates args with DTOs or primitive type names.
  • @Dto(DtoClass) transforms method results with a ResponseDto.
  • @Entity(name, collection?) attaches a collection and creates indexes.
  • @Index(spec, options?) defines Mongo indexes for an @Entity.

License

Apache-2.0. See LICENSE.

Notice

See NOTICE for attribution and required notices.