Purely-functional strictly-typed IoC/DI for TypeScript

Overview

INJECTABLE-TS

Purely-functional strictly-typed IoC/DI for TypeScript.

Overview

This project aims at providing lightweight inversion of control (IoC) and dependency injection (DI) tooling for large JavaScript/TypeScript applications.

Motivation

While the concepts of IoC and DI are not new and there are multiple implementations of them available for JavaScript and TypeScript, most of them are built around the concept of a single container with all registered dependencies (or multiple containers).

While such approach might work for some projects, it still introduces tight coupling in the code. We have to either manually register all dependencies in such container (which can be quite tedious), or delegate it to a framework which will register them automatically on a single global container which makes the code not portable.

While the issues above might seem synthetic, there's still another major downside of such approach - there is no way to statically check whether all required dependencies are actually registered on the container. If any of requested dependencies is missing, container throws in runtime which makes the code impure and indeterminate.

So, the goals of this project are to:

  • provide a purely-functional solution for automatic IoC/DI
  • provide compile-time guarantees that all required dependencies are always available for the caller.

Features

  • 🤝 - strictly typed, your code can finally be trusted
  • λ - purely functional, your code is determinate, composable, without side-effects
  • 👻 - transparent, your code requires no additional infrastructure like containers and frameworks, it just works
  • ⚡️ - efficient, your code is cached and only runs when its dependencies change
  • ⚛️ - React integration, your code can be seamlessly integrated into any React application

Structure

The project is split into several packages, and you can find documentation for them in the corresponding readme files.

Changelog

Read more here

Contributions & Development

Repository structure

This repository is powered by nx. This means that subpackages are built into a single directory /dist.

Publishing

This repository uses lerna ONLY for bumping versions until it's supported natively by nx.

Make sure NOT to call lerna bootstrap and other commands.

lerna version <version>

Then

npm run deploy
You might also like...

The Blog system developed by nest.js based on node.js and the database orm used typeorm, the development language used TypeScript

 The Blog system developed by nest.js based on node.js and the database orm used typeorm, the development language used TypeScript

考拉的 Nest 实战学习系列 readme 中有很多要说的,今天刚开源还没来及更新,晚些慢慢写,其实本人最近半年多没怎么写后端代码,主要在做低代码和中台么内容,操作的也不是原生数据库而是元数据Meta,文中的原生数据库操作也当作复习下,数据库的操作为了同时适合前端和Node开发小伙伴,所以并不是很

Dec 22, 2022

First NestJS project powered by TypeScript (Simple CRUD)

First Nest TS (TypeScript) First NestJS project powered by TypeScript (Simple CRUD) Routes Get All GET http://localhost:3000/products/ Get one GET htt

Feb 22, 2022

Battery-included GraphQL Server in TypeScript

jenova Battery-included GraphQL Server in TypeScript Jenova is built on top of GraphQL Helix and Envelop. The goal is to provde an easy to easy, batte

Feb 21, 2022

XML/HTML parser and processing library for JavaScript and TypeScript

XML/HTML parser and processing library for JavaScript and TypeScript

[VIEW DOCUMENTATION] Robin is an XML parser and processing library that supports a sane version of HTML. It features a set of DOM utilities, including

Oct 5, 2022

Nestjs + Typescript + GraphQL

Nestjs Boilerplate: Nestjs + Typescript + GraphQL How to run Install dependencies yarn install Start server for development yarn start:dev Start ser

Jun 27, 2022

TypeScript client for Tile38 geo-database

Tile38-ts tier.engineering · Report Bug · Request Feature Table of Contents About The Project Built With Getting Started Requirements Installation Com

Dec 29, 2022

A tiny wrapper around pg that makes PostgreSQL a lot of fun to use. Written in TypeScript.

A tiny wrapper around pg that makes PostgreSQL a lot of fun to use. Written in TypeScript.

A tiny wrapper around pg that makes PostgreSQL a lot of fun to use. Written in TypeScript.

Nov 29, 2022

This is a boilerplate for Nodejs (Nestjs/typescript) that can be used to make http server application.

Hexagonal architecture Table of Contents Overview Code architecture source code Service build information Regular user Advanced user Deployment Helm K

Sep 13, 2022

Validate and auto-generate TypeScript types from raw SQL queries in PostgreSQL.

SafeQL Write SQL Queries With Confidence • Get started Install I would first recommend follow the instructions in the documentation. npm install --sav

Dec 28, 2022
Comments
  • feat(core): add keys to tokens

    feat(core): add keys to tokens

    This PR adds a key: Key property to the result of token call - this makes it much easier to work with tokens by eliminating the need of exporting separate key constants:

    // before
    const FOO_KEY = 'foo'
    const foo = token(FOO_KEY)<string>()
    const bar = injectable(foo, foo => 'result')
    const result = bar({[FOO_KEY]: 'foo'})
    
    // after
    const foo = token('foo')<string>()
    const bar = injectable(foo, foo => 'result')
    const result = bar({[foo.key]: 'foo'})
    

    BREAKING CHANGE: fp-ts package is removed as useless

    cc @devfive @fyzu @mankdev

    Notes:

    • it seems @injectable-ts/fp-ts is absolutely useless as we can't force constraints on the E argument in interface URItoKind2<E, A> so that E is of shape UnknownInjectableTree
    • I had to change how types are encoded on Injectable interface and how they are inferred using InjectableValue/InjectableDependencies - we relied on type argument position before (first is for dependencies, second is for value) but this breaks if we have a TokenInjectable with 3 type arguments; so now we store the arguments as virtual fields (similar to zod schemas)
    • it don't really like all this new mess with type casts but it won't work otherwise (see above ☝️ )
    opened by raveclassic 2
  • feat(core): add optional token

    feat(core): add optional token

    Sometimes some dependencies are optional, but now there is no way to specify such dependencies correctly.

    My suggestion is to add an optional token:

    const foo = tokenOptional('foo')<'foo'>()
    
    const bar = injectable(foo, (foo: 'foo' | undefined) =>
      foo !== undefined ? `${foo}bar` : 'baz'
    )
    
    bar({}) // ✅ valid
    
    opened by Fyzu 2
Owner
Kirill Agalakov
Kirill Agalakov
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite datab

MikroORM 5.4k Dec 31, 2022
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server & SQLite

Prisma Quickstart • Website • Docs • Examples • Blog • Slack • Twitter • Prisma 1 What is Prisma? Prisma is a next-generation ORM that consists of the

Prisma 28k Jan 2, 2023
TypeScript clients for databases that prevent SQL Injection

Safe From HTML Injection Using tagged template literals for queries, e.g. db.query(sql`SELECT * FROM users WHERE id=${userID}`); makes it virtually im

Forbes Lindesay 478 Dec 21, 2022
generate bare minimum node typescript setup asap

nd.ts ?? generate bare minimum node typescript setup asap npx nd.ts This CLI setups the node.ts starter with simple command. tell the project name ??

Ayush 27 Dec 24, 2022
Anonymify - Outils TypeScript pour l'anonymisation des données en langue Française, compatible Node.js et dans les browsers.

@socialgouv/anonymify Outils TypeScript pour l'anonymisation des données en langue Française. Compatible Node.js et dans les navigateurs Démo : https:

Fabrique numérique des Ministères Sociaux 4 Nov 16, 2022
just a graphql example created by typescript + fastify + mikro-orm(postgresql) + mercurius(graphql adaptor) + type-graphql

fastify-mikro-orm-mercurius-graphql-example A MikroORM boilerplate for GraphQL made with Fastify, Mercurius, Typescript using TypeGraphQL ?? Packages

Vigen 10 Aug 28, 2022
GraphQL Projects Study Cases with TypeScript/Node.js & Other Stacks

GraphQL Projects Study Cases with TypeScript/Node.js & Other Stacks A real world projects with intention of studying a little bit more about GraphQL w

Glaucia Lemos 15 Dec 5, 2022
Morpheus is database migration tool for Neo4j written in Typescript.

Morpheus Morpheus is a database migration tool for Neo4j written in Typescript. Morpheus is a modern, open-source, database migration tool for Neo4j.

Mariano Zunino 10 Dec 3, 2022
A template of Rust + WebAssembly with TypeScript (🦀 + 🕸️ = 💖)

rust-wasm-ts-template This repository is a template of Rust + WebAssembly with TypeScript ( ?? + ??️ = ?? ). Requirements The Rust Toolchain wasm-pack

Chris Ohk 20 Aug 26, 2022
A typescript data mapping tool. To support mutual transforming between domain model and orm entity.

ts-data-mapper A typescript mapping tool supports mutual transforming between domain model and orm entity. In most case, domain model is not fully com

zed 8 Mar 26, 2022