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

reliquery

v0.0.1

Published

**Note: this is HIGHLY experimental software. Basically nothing can be considered stable.**

Downloads

4

Readme

👑🔮 Reliquery 🔮👑

Note: this is HIGHLY experimental software. Basically nothing can be considered stable.

Reliquery is a configuration free, nominally typed, code generating DI container implemented as a Typescript transformer. The container should work predictably, incur no run-time overhead, and generally never need to be interacted with. Astute readers will note that this violates many of the fundamental design principles of TS in that it couples your code to its types, generated code changes based on type information, and code using Reliquery can not be considered as existing in a superset of JS. Proceed at your own risk.

Reliquery works by parsing your source files, collecting entities that are tagged as injectable, traversing their type hierarchies, and registering those entities as resolutions for their entire type hierarchy. This means, unlike most TS DI solutions, if you have an interface hierarchy such as A > B > C > D > E > F and a class MyClass that implements F, you can ask for any of those interfaces (or parent classes, or interfaces parent classes implement, and so on).

Once the injectable entities have been collected, a static singleton is generated that simply maps fully qualified names (a safe representation of original source path and exported symbol name, due to JS/TS having frequent name collisions) to either singletons or factory methods.

Finally, Reliquery rewrites the emitted JS at injection sites. A class constructor such as constructor(foo: MyFoo) {} will get invoked in the container as new FooUser(container.get('unique_string_of_MyFoo')). When you retrieve things from the container (via const myFoo = hydrate<MyFoo>()), that code is simply rewritten to the correct container.get() call. Modern JS runtimes should inline everything the container does, so the runtime overhead of Reliquery should be immeasurably small.

Installation

First, install reliquery and ttypescript:

yarn add --dev reliquery ttypescript

Next, add the relevant section to your tsconfig.json:

{
  "compilerOptions": {
    "plugins": [
      {
        "transform": "reliquery"
      }
    ]
  }
}

That's it! You're ready to use reliquery!

Usage

1. Annotate your classes

For factory classes:

import { Factory } from 'reliquery';

@Factory
export class CreatedMultipleTimes { /* ... */ }

For singleton classes:

import { Singleton } from 'reliquery';

@Singleton
export class CreatedOnce { /* ... */ }

Constructor parameters are automatically provided:

import { Singleton } from 'reliquery';

@Singleton
export class WithParameters { 
  constructor(first: CreatedMultipleTimes, second: CreatedOnce) { /* ... */ }
}
2. Access your hydrated instances
const myInstance: WithParameters = hydrate();

or

const myInstance = hydrate<WithParameters>();
3. That's it! Just compile using ttsc instead of tsc and enjoy the magic!