Am

Ampulla: Modern TypeScript DI with NestJS Ergonomics

Hacker News

Ampulla: Modern TypeScript DI with NestJS Ergonomics

Yes, yet another DI library for TypeScript. A few things kept bothering me about the existing ones, in order of how much they hurt. - *Type safety requires a special dance.* InversifyJS has ServiceIdentifier<T>, but it is really easy to break the typing. TypeDI tokens are untyped strings. NestJS suffers mostly same, unless you use full classes as dependency tokens. TSyringe infers from constructor metadata, but all of it relies on legacy "reflect-metadata" and decorators mechanism that (a) is soon to be gone, (b) requires additional wiring. - *Async leaks into callers.* InversifyJS has container.getAsync() for providers that might have been initialized asynchronously. That means every call site needs to know whether what it's asking for was async. The complexity never stays contained. NestJS gets this right: await everything at bootstrap, then get() is always synchronous. Initialized means ready. - *Wiring is imperative.* InversifyJS has you call manually .bind(Token).to(Implementation) for every provider. It works, but it's ugly. NestJS figured out the right answer: declare what a module owns, what it needs, what it exposes, and let the container figure the rest out. That declarative model is the thing I wanted most, but it comes with an entire framework. NestJS gets hairy when your single app starts accepting just Nats JetStream in addition to HTTP. - *reflect-metadata.* Every major TS DI library runs on TS "experimentalDecorators" plus a global runtime polyfill for TypeScript metadata. TC39 Stage 3 decorators shipped in TypeScript 5.0, and are soon to be natively supported in JS engines. No flags, no polyfills. Ampulla is my attempt at fixing all four: injection<T>() tokens that carry their type intrinsically, a declarative @Module/@Injectable model lifted straight from NestJS, async-safe bootstrapping where container.get() is always synchronous, and TC39 decorators throughout. It's intentionally just a DI container, not a framework. There is no HTTP server, no router, no CLI included. Optional adapters for Hono and H3 are included but tree-shakeable. The whole npm package has zero runtime dependencies. Very early, 1.0.0 published just today. DI is not the most popular topic on HN, but existing DI in TypeScript is annoying enough that I had to publish something new. GitHub: https://github.com/ukstv/ampulla | npm: npm install ampulla

Share card

Actual performance

1points
Did not reach leaderboard

Launch Intel predictions

Analyze your own launch →
Indie HackersFits the IH revenue-focused audience · Missing: supports, reddit linkedin, podcasting
83%83% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Product HuntOn track for Day 1 leaderboard · Strong signals: model, new, single · Missing: mac, agents, macos
61%61% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
AppSumoMay struggle as an AppSumo deal · Strong signals: plus, soon · Missing: platform, intuitive, reviews
42%42% predicted probability of success on AppSumo, based on ML models trained on real launch data.
TrustMRRLess likely to generate early MRR · Strong signals: way · Missing: mobile apps, ios, personal
35%35% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
Hacker NewsMay not resonate with HN audience · Strong signals: exist, existing, ide · Missing: https docs, excited, just released
33%33% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
Acquire.comPre-revenue stage for this audience · Strong signals: arr · Missing: mrr, revenue, profit
18%18% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

Ce
Cerialize – Typescript serialization by annotation39%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Cerialize – Typescript serialization by annotation

Hacker News1
Sc
Scala-ts – Scala to TypeScript compiler41%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Scala-ts – Scala to TypeScript compiler

Hacker News66
Ha
Hapi with Typescript51%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Hapi with Typescript

Hacker News2
JS
JSONSchema to TypeScript compiler51%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

JSONSchema to TypeScript compiler

Hacker News72
Tr
Transpile Scala to TypeScript29%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Transpile Scala to TypeScript

Hacker News1
Ge
Get started modding Factorio in TypeScript44%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Get started modding Factorio in TypeScript

Hacker News69
We
WebSockets Explained with TypeScript64%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

WebSockets Explained with TypeScript

Hacker News3
A
A BubbleShooter Implementation in TypeScript38%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

A BubbleShooter Implementation in TypeScript

Hacker News2
Bi
Binary Serialization with TypeScript40%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Binary Serialization with TypeScript

Hacker News2
Du
DuoCode 1.0 bridges the gap between C# and TypeScript31%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

DuoCode 1.0 bridges the gap between C# and TypeScript

Hacker News7