Skip to content

Nebutra/provider-factory

Repository files navigation

@nebutra/provider-factory

Public mirror for @nebutra/provider-factory from Nebutra/Nebutra-Sailor.

This repository is generated from the Nebutra Sailor monorepo. Package releases are cut from the monorepo and mirrored here for discovery, standalone cloning, and contribution intake.

  • Canonical source: packages/platform/provider-factory in Nebutra/Nebutra-Sailor
  • Package registry: npm and GitHub Packages
  • Contributions: open issues or PRs here; maintainers port accepted changes back into the monorepo source package

Neutral provider-resolution primitive for provider-agnostic Nebutra packages.

This package centralizes the shared selection rule used by cache, queue, search, notifications, vault, uploads, and similar packages:

explicit provider -> environment provider -> detector chain -> fallback

It does not instantiate concrete providers. Domain packages still own their provider-specific imports and setup.

Installation

pnpm add @nebutra/provider-factory

Usage

import {
  assertProviderAllowed,
  envPresent,
  resolveProviderType,
} from "@nebutra/provider-factory";

type CacheProvider = "memory" | "redis";

const provider = resolveProviderType<CacheProvider>({
  explicit: undefined,
  envVarName: "CACHE_PROVIDER",
  detectors: [{ provider: "redis", when: envPresent("REDIS_URL") }],
  fallback: "memory",
});

assertProviderAllowed(provider, {
  disallowedInProd: ["memory"],
  overrideEnv: "ALLOW_MEMORY_CACHE_IN_PROD",
  hint: "Configure REDIS_URL or set CACHE_PROVIDER=redis",
});

API

Export Description
resolveProviderType(input) Apply explicit, env, detector, fallback precedence
envPresent(name) Build a detector predicate from an environment variable
assertProviderAllowed(provider, options) Refuse unsafe providers in production unless explicitly overridden
ProviderDetector<T> Detector shape
ResolveProviderInput<T> Resolver input shape
ProdGuardOptions<T> Production guard options

License

MIT

About

Provider resolution primitive for explicit, environment, detection-chain, and fallback selection.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors