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

@jojoxd/tsed-util

v1.3.2

Published

Generic Ts.ED Utilities

Downloads

3

Readme

@jojoxd/tsed-util

Multiple small modules to make Ts.ED a bit better.

You can check out the test/integration directory for usages.

Note: Most peer dependencies are marked as optional,
read below to find out what dependencies are needed for which functionality.

MikroORM

yarn install @jojoxd/tsed-util @tsed/mikro-orm @mikro-orm/core

Usage:

import { InjectRepository } from "@jojoxd/tsed-util/mikro-orm";
import { Entity, EntityRepository } from "@mikro-orm/core";

export class MyEntityRepository extends EntityRepository<MyEntity> {}

@Entity({ repository: () => MyEntityRepository, })
export class MyEntity {}

export class MyService
{
    @InjectRepository(MyEntity)
    protected readonly myEntityRepository!: MyEntityRepository;

    // With a specific contextName:
    @InjectRepository(MyEntity, "context")
    protected readonly myContextEntityRepository!: MyEntityRepository;
}

express-session

Note: The ProviderScope should be set to REQUEST on the services you use @InjectSession() in.

// Session.d.ts
import {ParamOptions} from "@tsed/platform-params";
import {Session as ExpressSession} from "express-session";

declare module "@tsed/common"
{
    // As we are re-declaring the interface, we need to re-define the Session decorator
    export function Session(expression: string): ParameterDecorator;
    export function Session(options: Partial<ParamOptions>): ParameterDecorator;
    export function Session(): ParameterDecorator;

    // Your session variables go here
    export interface Session extends ExpressSession
    {
        mySessionVariable?: string;
    }
}
// service.ts
import { Injectable, ProviderScope } from "@tsed/di";

// NOTE: Session is just a re-export of Session in "@tsed/common"
import { InjectSession, Session } from "@jojoxd/tsed-util/express-session";

@Injectable({ scope: ProviderScope.REQUEST, })
export class MyService
{
    @InjectSession()
    protected readonly session?: Session;

    public test()
    {
        const sessionVariable = this.session?.mySessionVariable;
    
        // express-session functions are also available:
        this.session?.save();
    }
}

Redoc

yarn install @jojoxd/tsed-util @tsed/swagger @tsed/schema
// Server.ts
import "@tsed/swagger";
import { defineRedocSettings } from "@jojoxd/tsed-util/redoc";

@Configuration({
    swagger: [
        defineRedocSettings({
            // All your spec options go here, mostly the same as the swagger config
            path: '/api/docs',
        }),
    ],
})
export class Server {}

Scheduler

The scheduler is used to schedule jobs using node-scheduler.

yarn install @jojoxd/tsed-util node-scheduler
// Server.ts
import "@jojoxd/tsed-util/scheduler";
import "./MyScheduler";

@Configuration({
    scheduler: {
        // Maybe only enable in production
        enabled: process.env.NODE_ENV === "production",

        disableScheduleSummary: false,
        logging: true,
    }
})
export class Server {}

// MyScheduler.ts
import { Scheduler, Schedule } from "@jojoxd/tsed-util/scheduler";

@Scheduler({ namespace: "some-namespace", })
class MyScheduler
{
    // This is a Service, so @Inject will work here

    @Schedule({ name: "My Job", rule: "*/5 * * * * *", })
    runMyJob()
    {
        // Do something every 5 seconds
    }
}

Prometheus

Prometheus adds metrics to your app.

yarn install @jojoxd/tsed-util prom-client express-prom-bundle
// Server.ts
import "@jojoxd/tsed-util/prometheus";

@Configuration({
    prometheus: {
        enabled: true,
        path: '/metrics',

        collectDefaultMetrics: true,
        options: { /* Options of express-prom-bundle */ }
    }
})
export class Server {}