Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
ngasull/classicWorks with
•JSR Score100%•This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers



Published7 months ago (0.1.2)
Type-safe dynamic runtime state API
Type-safe dynamic runtime state API.
- Declare a key for a specific runtime type
- Provide the typed data in an async closure
- Retrieve data directly in user modules
End-to-end declare, provide & use summary
End-to-end declare, provide & use summary
import { Context } from "@classic/context"; import { assert } from "@std/assert"; type User = { id: bigint; name: string; }; // Shared code - export this key to provider and consumers export const $user = Context.for<User>("user"); // Provider code const john = { id: 42n, name: "John", }; $user.provide(john, () => { // Consumer code - `user` is correctly typed as `User` assert($user.use() === john); });
Use functions: expect context transparently in custom logic
Use functions: expect context transparently in custom logic
import { Context } from "@classic/context"; import { assert } from "@std/assert"; type User = { id: bigint; name: string; }; export const $user = Context.for<User>("user"); export const getUserId = () => $user.use().id; // Provider code $user.provide({ id: 42n, name: "John" }, () => { // Looks the same, but only exposes read access assert(getUserId() === 42n); });
Built and signed on
GitHub Actions
Add Package
deno add jsr:@classic/context
Import symbol
import * as context from "@classic/context";
Import directly with a jsr specifier
import * as context from "jsr:@classic/context";
Add Package
pnpm i jsr:@classic/context
pnpm dlx jsr add @classic/context
Import symbol
import * as context from "@classic/context";
Add Package
yarn add jsr:@classic/context
yarn dlx jsr add @classic/context
Import symbol
import * as context from "@classic/context";
Add Package
vlt install jsr:@classic/context
Import symbol
import * as context from "@classic/context";
Add Package
npx jsr add @classic/context
Import symbol
import * as context from "@classic/context";
Add Package
bunx jsr add @classic/context
Import symbol
import * as context from "@classic/context";