This document is the primary written guide for using and contributing to @jonloucks/contracts-ts.
@jonloucks/contracts-ts provides TypeScript contracts and promisor patterns to support dependency inversion, runtime validation, and controlled lifecycle management.
Key goals:
npm install @jonloucks/contracts-ts
Supported Node.js versions for development and CI are:
20.19.0+22.13.0+24.ximport { createContract } from "@jonloucks/contracts-ts";
import { bind, createSingleton, enforce, guardFunctions } from "@jonloucks/contracts-ts/api/Convenience";
interface Logger {
log(message: string): void;
}
const LOGGER = createContract<Logger>({
name: "Logger",
test: (obj: unknown): obj is Logger => guardFunctions(obj, "log")
});
bind(LOGGER, createSingleton(() => ({
log: (message: string) => console.log(message)
})));
const logger = enforce(LOGGER);
logger.log("Hello contracts-ts");
v2.0.0 intentionally narrows root exports.
@jonloucks/contracts-ts)Use for essential core exports:
CONTRACTScreateContractcreateContractsContractExceptionVERSIONUse convenience modules for broader helpers:
@jonloucks/contracts-ts/api/Convenience@jonloucks/contracts-ts/auxiliary/ConvenienceUse explicit modules for focused dependencies:
@jonloucks/contracts-ts/api/*@jonloucks/contracts-ts/auxiliary/*Defines the shape and runtime validator for a dependency.
Provides the implementation deliverable for a contract.
Associates a contract with a promisor using bind strategies.
enforce(contract) requires a present deliverableclaim(contract) returns an optional deliverableUse createSingleton for one shared implementation instance.
Use createLifeCycle when open/close behavior must be coordinated.
Use createExtractor to map a promisor deliverable into another value.
index.ts no longer exports broad helper surfaces)"type": "module")@jonloucks/contracts-ts/auxiliary/Functional removed@jonloucks/contracts-ts/api/Types@jonloucks/contracts-ts/api/Convenience for core helper imports@jonloucks/contracts-ts/auxiliary/Convenience or direct auxiliary/* imports for functional/auxiliary helpers@jonloucks/contracts-ts/auxiliary/Transform for transform type aliases/utilitiesnpm install
npm run build
npm test
npm run lint
npm run docs
notes/release-notes-v*.md