API Reference
All public exports from @cmj/juice/runtime and @cmj/juice/client.
@cmj/juice/runtime
| Export | Type | Description |
|---|
createRouter | (manifest, options?) => (req: Request) => Response | Creates a WinterCG-compatible fetch handler from a flight manifest. |
redirect | (url: string, status?: number) => never | Throws a redirect Response. Works in components, actions, and middleware. |
cache | (fn: Function) => Function | Wraps an async function with request-scoped memoization. Identity-based keys. |
setContext | (req, key, value) => void | Attach a value to the request context. Accepts string or typed ContextKey. |
getContext | (req, key) => T | undefined | Read 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) => ActionContext | Creates an ActionContext for server actions needing request access. |
Type Exports
| Type | Description |
|---|
RouterOptions | Configuration for createRouter(). See Router Options reference. |
FlightManifest | The manifest generated by the Vite plugin at build time. |
ActionContext<TRoute> | Second argument to server actions. Provides request, cookies, typed params. |
ParsedBody | Discriminated union: form | json | text. |
ExtractRouteParams<T> | Type-level extraction of route params from a pattern string. |
PageProps | Interface 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 }. |
CacheAdapter | Interface for cross-request cache: get(key) and set(key, value, ttl?). |
@cmj/juice/client
| Export | Type | Description |
|---|
Link | React component | SPA navigation link with RSC prefetching. Renders a standard <a> tag. |
useRouter | () => Router | Hook returning pathname, push(), replace(), prefetch(). |
initNavigation | (setPage, options?) => void | Initializes the Navigation API interceptor for SPA transitions. |
Client Type Exports
| Type | Description |
|---|
NavigationOptions | Options for initNavigation(): viewTransitions, prefetching. |
LinkProps | Props for the Link component. Extends standard anchor attributes. |
PrefetchStrategy | 'hover' | 'viewport' | 'none' |
Router | Return type of useRouter(). |