Supplier Logo

Supplier

Powerful, type-inferred, and hyper-minimalistic library for server request propagation and dependency injection using a novel Supply Chain Architecture

Zero Runtime Overhead

Pure functions and objects with compile-time optimization

Type-Safe

Full TypeScript inference throughout the dependency chain

Context Switching

Powerful resupply() for dynamic dependency injection

Quick Start

Get up and running with Supplier in minutes. Here's how easy it is to implement powerful dependency injection.

Installation

bash
npm install supplier

Basic Usage

typescript
import { register, parcel } from "supplier";

// Create a resource
const ConfigResource = register("config")
  .asResource<{ apiUrl: string }>();

// Create a service
const ApiService = register("api").asService({
  factory: ($) => {
    const config = $(ConfigResource.id);
    return { fetch: (path) => `${config.apiUrl}${path}` };
  }
});

// Supply and use
const api = ApiService.supply(
  parcel(ConfigResource.supply({ apiUrl: "https://api.com" }))
);

console.log(api.value.fetch("/users")); // "https://api.com/users"

Context Switching

typescript
// Resupply with different context
const testApi = apiService.resupply(
  parcel(ConfigResource.supply({ 
    apiUrl: "http://localhost:3000" 
  }))
);

// Same service, different config!
console.log(testApi.value.fetch("/users")); 
// "http://localhost:3000/users"

💡 Pro Tip

Supplier's resupply()method enables powerful testing scenarios and runtime dependency overrides without affecting the original service configuration.

Features

Everything you need for modern dependency injection, designed for performance and developer experience.

Zero Runtime Overhead

Pure functions and objects with compile-time optimization. No reflection, no runtime magic.

Type-Safe

Full TypeScript inference throughout the dependency chain. Catch errors at compile time.

Context Switching

Powerful resupply() for dynamic dependency injection and testing scenarios.

Minimalistic API

Learn the entire API in minutes. Simple, intuitive, and powerful.

Tiny Bundle Size

Minimal footprint with zero dependencies. Perfect for performance-critical applications.

Open Source

MIT licensed and community-driven. Contribute on GitHub and shape the future.

See It In Action

Check out our interactive example with 4-level deep component hierarchy demonstrating context switching and dependency injection.

View Live Example