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 🙏

© 2024 – Pkg Stats / Ryan Hefner

rf-nestjs

v0.2.0

Published

This package contains with NestJS custom modules used by Request Finance.

Downloads

95

Readme

rf-nestjs

This package contains with NestJS custom modules used by Request Finance.

It uses ES6 modules to export different features.

Installation

# Optional. The easy way. Alternatively, pick only dependencies you need
pnpm config set auto-install-peers true --location project

pnpm i rf-nestjs

About peer dependencies

If you don't use a feature, you don't need to install dependencies for that feature. For instance, @google-cloud/pubsub is not needed if you don't use the pubsub feature.

NB: a missing dependency will cause a runtime error, not a compile error.

Features

config

Class-based configuration, based on class-validator and class-transformer. You can have multiple configuration classes (usually one per module), but they must have unique names.

Dependencies

pnpm i class-transformer class-validator dotenv-flow

Usage

// app.config.ts
import { Expose } from "class-transformer";
import { IsPort } from "class-validator";

export class AppConfig {
  @IsPort()
  @Expose({ name: "PORT" })
  port: number;
}

// app.module.ts
import { ConfigModule } from "rf-nestjs/config";
import { AppConfig } from "./app.config.js";

@Module({
  imports: [
    ConfigModule.forClass(AppConfig),
    // ...
  ],
})
export class AppModule {}

// main.ts
const config = app.get(AppConfig);
// OR in a service
@Injectable()
class MyService {
  constructor(config: AppConfig) {}
}

currency

A module to inject a CurrencyManager and a ChainManager based on data from Currency API. Optionally refreshes data regularly.

Dependencies

pnpm i @requestnetwork/currency @nestjs/schedule

Usage

import { Module } from "@nestjs/common";
import { ScheduleModule } from "@nestjs/schedule";
import { CurrencyModule } from "rf-nestjs/currency";

@Module({
  imports: [
    ScheduleModule.forRoot(),
    CurrencyModule.register({
      apiUrl: "https://api.request.finance/currency",
      // optional
      autoFetch: true,
      frequency: 10 * 60 * 1000,
    }),
  ],
  providers: [MyService],
})
export class MyModule {}

@Injectable()
export class MyService {
  constructor(private readonly cm: CurrencyManager) {}

  demo() {
    console.log(this.cm.from("EUR"));
  }
}

logger

Dependencies

pnpm i @rf-logger/logger @rf-logger/logger-nestjs

Usage

// logger.config.ts
import { Injectable } from "@nestjs/common";
import type { Options } from "@rf-logger/logger";
import { LogFormatEnum, type LogLevel, LogLevelEnum } from "@rf-logger/logger";
import { Expose } from "class-transformer";
import { IsEnum } from "class-validator";

@Injectable()
export class LoggerConfig implements Options {
  @Expose({ name: "LOG_LEVEL" })
  @IsEnum(LogLevelEnum)
  level: LogLevel;

  @Expose({ name: "LOG_FORMAT" })
  @IsEnum(LogFormatEnum)
  format: "json";

  // Optional
  // plugins = [AxiosPlugin];s
}

// app.module.ts
import { LoggerModule } from "rf-nestjs/logger";
import { LoggerConfig } from "./logger.config.js";

@Module({
  imports: [LoggerModule.forConfig(LoggerConfig)],
})
export class AppModule {}

// main.ts
import { Logger } from "@nestjs/common";

// ...
app.useLogger(app.get(Logger));
// ...

meta

Usage

See pubsub-scanner.service.ts in this repo.

pubsub

Dependencies

pnpm i @google-cloud/pubsub

Usage

import { Module } from "@nestjs/common";
import { ConfigModule } from "rf-nestjs/config";
import { SubscriptionModule } from "rf-nestjs/pubsub";

import { PubsubConfig } from "./pubsub.config.js";

@Module({
  imports: [
    SubscriptionModule.registerAsync({
      imports: [ConfigModule.forClass(PubsubConfig)],
      useFactory: (config: PubsubConfig) => ({
        publishedBy: "sync-api",
        projectId: config.googleProjectId,
        // if you have multiple subscriptions, you can use the `name` argument to retrieve the right options.
        getSubscription: () => ({
          subscriptionName: config.subscriptionName,
          maxMessages: config.maxSubscriberMessages,
        }),
      }),
      inject: [PubsubConfig],
    }),
  ],
})
export class PubsubModule {}

// then use in a controller like this:

import { Controller } from "@nestjs/common";
import { Subscriber } from "rf-nestjs/pubsub";

import { SyncMessageDto } from "./sync.dto.js";

@Controller()
export class SyncController {
  constructor() {}

  @Subscriber("my-sub-name")
  async batchTransaction(message: SyncMessageDto) {
    // the payload will be validated using the DTO, and the message will be rejected if invalid.
  }
}

Contributing

Deploying a local package

It's recommended to use yalc to develop locally, as pnpm link might cause depdency issues when resolving meta (ie @Subscriber).

Running example

pnpm nest start --entryFile example/main.js