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

rttist

v1.0.0-beta.8

Published

Abstract declarations for TypeScript runtime reflection

Downloads

194

Readme

rttist License MIT

What is RTTIST?

RTTIST (pronounced /ˈɑː(r)tɪst/, like artist) is a TypeScript runtime reflection system inspired by the C#'s reflection.

It consists of several parts:

  • Metadata Generator - TypeGen - a standalone command-line tool that generates metadata from TypeScript types.
  • Runtime Library - a library that provides runtime reflection functionality.
  • Transformers - a set of transformers that extend the functionality of the TypeScript build/bundle tools.

To access base functionality, you only need to install the TypeGen and the runtime library. The transformers are optional. They are only needed if you want to use the extended functionality. TypeGen is a standalone noninvasive command-line tool. It does not depend on your project setup; it is completely decoupled from your build/bundle tool.

Here is a small example:

import { Type } from "rttist";
import { Metadata } from "./metadata.typelib"; // this file is generated by TypeGen

const typeIController: Type = getType<IController>();

const controllerCtors = Promise.all(
        Metadata.getTypes()
        .filter(
            (type) =>
                type.isClass() &&
                !type.abstract &&
                type.exported &&
                type.isDerivedFrom(typeIController)
        )
        .map((type) => type.module.import().then(m => m?.[type.name]))
    );

const controllerInstances = controllerCtors.map(Ctor => new Ctor());

In this example, we get all exported non-abstract classes that are derived from the IController interface and create instances of them.

Module metadata.typelib is generated by the TypeGen. It exports Metadata object which is instance of the MetadataLibrary. It contains metadata for all types and modules in the project.

It is useful for many things, such as:

  • serialization/deserialization,
  • validation,
  • dependency injection,
  • frameworks and libraries.

For more information see our website rttist.org and docs docs.rttist.org.

Supported Build/Bundle Tools

Thanks to RTTIST's flexible architecture, it seamlessly integrates with a variety of build and bundle tools.

However, it's important to note that certain build and bundle tools may come with limitations, hindering the full breadth of RTTIST's capabilities. For the ultimate experience, you have to use the TypeScript compiler directly. Unlike other tools, the TypeScript compiler's TypeChecker empowers us to reflect inferred types, unlocking a deeper level of code understanding.

While we provide custom plugins for the most widely used tools, you have the flexibility to create your own if necessary. We provide TS to TS compiler (npm: @rttist/ts-loader-wasm), implemented in Rust, that can be used in any plugin for any build/bundle tool in a loader.

For now, we provide plugins for:

  • esbuild,
  • Vite (work in progress - ~90 %),
  • SWC (work in progress - ~90 %),
  • ttypescript (work in progress).

Alpha Warning!

This project is currently under development.
There may still be major changes.

If you have any issues or questions or just want to give us feedback, join our Discord.

Showcase

import { getType } from "./metadata.typelib";
import { Type, PropertyInfo, MethodInfo } from "rttist";

interface Employee {
    name: string;
    salary: number;
    sayHello();
    sayHello(toSomebody: string);
}

const type: Type = getType<Employee>();

if (type.isInterface()) {
    const properties = type.getProperties().map((prop: PropertyInfo) => prop.name);
    const methods = type.getMethods().map((method: MethodInfo) => method.name);

    console.log(properties); // > [ name, salary ]
    console.log(methods); // > [ sayHello ]

    const sayHelloMethod: MethodInfo = type.getMethods().find(m => m.name === "sayHello");
    const signatures = sayHelloMethod.getSignatures()
        .map(sig => {
            const parameters = sig.getParameters()
                .map(param => param.name + ": " + param.type.name);

            return `sayHello(${parameters.join(", ")})`
        });

    console.log(signatures); // > [ sayHello(), sayHello(toSomebody: string) ]
}

License

This project is licensed under the MIT license.