GitHubnpm

API Reference

All public exports from @cmj/juice/runtime and @cmj/juice/client.

@cmj/juice/runtime

ExportTypeDescription
createRouter(manifest, options?) => (req: Request) => ResponseCreates a WinterCG-compatible fetch handler from a flight manifest.
redirect(url: string, status?: number) => neverThrows a redirect Response. Works in components, actions, and middleware.
cache(fn: Function) => FunctionWraps an async function with request-scoped memoization. Identity-based keys.
setContext(req, key, value) => voidAttach a value to the request context. Accepts string or typed ContextKey.
getContext(req, key) => T | undefinedRead a value from the request context. Type inferred from ContextKey.
createContextKey<T>(name: string) => ContextKey<T>Create a typed context key for compile-time safe context passing.
createActionContext(req, params) => ActionContextCreates an ActionContext for server actions needing request access.

Type Exports

TypeDescription
RouterOptionsConfiguration for createRouter(). See Router Options reference.
FlightManifestThe manifest generated by the Vite plugin at build time.
ActionContext<TRoute>Second argument to server actions. Provides request, cookies, typed params.
ParsedBodyDiscriminated union: form | json | text.
ExtractRouteParams<T>Type-level extraction of route params from a pattern string.
PagePropsInterface augmented by juice-env.d.ts for typed page props.
JuiceMiddleware(req: Request, next: () => Promise<Response>) => Response | Promise<Response>
ContextKey<T>Branded key carrying value type at compile time. Runtime: { name: string }.
CacheAdapterInterface for cross-request cache: get(key) and set(key, value, ttl?).

@cmj/juice/client

ExportTypeDescription
LinkReact componentSPA navigation link with RSC prefetching. Renders a standard <a> tag.
useRouter() => RouterHook returning pathname, push(), replace(), prefetch().
initNavigation(setPage, options?) => voidInitializes the Navigation API interceptor for SPA transitions.

Client Type Exports

TypeDescription
NavigationOptionsOptions for initNavigation(): viewTransitions, prefetching.
LinkPropsProps for the Link component. Extends standard anchor attributes.
PrefetchStrategy'hover' | 'viewport' | 'none'
RouterReturn type of useRouter().