[]previous and next page

@shadow-js/dusk/server

The 298 exports of @shadow-js/dusk/server: 96 functions, 9 classes, 139 interfaces, 28 types, 25 consts and 1 component.

Everything @shadow-js/dusk/server exports, from the TSDoc of its entry point.

Functions#

  • absoluteUrl: A full, absolute URL for a path: the base is metadataBase when given, else the origin of the request (or of the origin string or URL passed).
  • addressKey: The key a rate limiter should use for an address.
  • after: Runs task after the response has been sent.
  • all: Passes when every guard passes, in order.
  • any: Passes when at least one guard passes.
  • apiHandler: Builds an API handler with validated input and a typed context.
  • apiRoute: Defines an API route module.
  • bindServerFn: Gives a server function the id and url the build assigned to it.
  • buildCsp: Builds the header value.
  • cacheData: Caches the result of an async function under a key, for the handler of the current request.
  • cachedFetch: Fetches a public GET URL through the data cache (see the file comment).
  • cacheTags: Tags the page that is being rendered, so a later revalidateTag with one of the tags discards it.
  • chainHead: The head tags and JSON-LD blocks of a resolved chain.
  • chainRoutesOf: The routes of a rendered chain that the metadata reads, outermost first, from matches and their specs.
  • checkCsrf: Decides whether a request may change state.
  • checkFraming: Checks the headers that frame the body.
  • checkRedirectTarget: Validates a redirect target and returns the string to put in Location, or the error that explains why it is not allowed.
  • compileHostRules: Compiles host patterns into a predicate.
  • createCookieSigner: Creates a signer.
  • createDataCache: Creates a data cache over a store.
  • createEventLog: Creates a bounded event log.
  • createFetch: Wraps a handler as the { fetch(request, env, ctx) } module that Workers, Vercel and Netlify expect.
  • createHandler: Creates the request handler: the single fetch(Request) => Response contract that adapters, the dev server, the test client and prerendering all call.
  • createKey: Creates a typed key for event.set / event.get.
  • createKeyValueCacheStore: A CacheStore over a Redis-like client.
  • createKvCacheStore: The ISR page cache over a KV store.
  • createKvRateLimitStore: Token buckets over a KV store.
  • createKvSessionStore: Sessions over a KV store.
  • createMemoryCacheStore: An in-process cache store: a Map kept in least-recently-used order, bounded by maxEntries.
  • createMemoryKVStore: The in-process store: a bounded least-recently-used table of JSON text.
  • createMemoryRateLimitStore: A bounded in-memory store: at most maxKeys buckets, least recently used evicted first, so a flood of distinct keys cannot grow memory.
  • createMemorySessionStore: An in-memory session store for development and single-process servers.
  • createRateLimiter: Creates a rate limiter.
  • createSessionManager: Creates a session manager: signed id cookie, server-side data, idle and absolute lifetimes, periodic id rotation, explicit regenerate() against fixation.
  • defaultCspDirectives: The strict defaults: same-origin everything, scripts only from this origin or with the nonce, no plugins, no framing, no foreign form targets.
  • defineEnv: Describes the environment of the app.
  • defineGuard: Identity helper that types a reusable guard.
  • defineLocals: Declares a typed group of locals with defaults.
  • draftMode: Whether draft mode is on for the current request (its cookie verifies with the secret).
  • encodeFrame: Encodes one frame the server sends: a single final frame, unmasked, with the shortest length encoding.
  • executeServerFn: Runs a server function definition: validation, middleware, then the handler.
  • fail: Makes a failure result.
  • file: A file answer: the bytes (or a Blob) with the headers a download needs, and the conditional and range requests answered from the request.
  • formatSseEvent: Formats one event as the bytes of the stream: retry, id, event, then one data line per line of the payload, then the blank line that ends the event.
  • formToObject: Converts form data to a plain object.
  • geoOf: The geo a platform reported for a request.
  • getLocals: The locals of the request being handled.
  • getRequestEvent: The event of the request being handled.
  • html: An HTML response (text/html; charset=utf-8).
  • isFailure: True for a value fail made (or one that has its shape, after the wire).
  • isJsonContentType: True when a Content-Type header names JSON (application/json, application/*+json).
  • isStandardSchema: True when value has the Standard Schema shape.
  • json: A JSON response.
  • limitBody: Returns a request whose body errors with BodyTooLargeError as soon as more than maxBodyBytes have been read.
  • manifestJson: The text of a web app manifest: compact JSON (as Next writes it) with the display mode and every address checked.
  • manifestRoute: An API route handler that serves the web app manifest.
  • mergeHandlerOptions: Merges the handler options of the file (baked) with the entry's (user).
  • normalizeIp: Normalizes an IP address: IPv4 stays as is, IPv6 is written in full lower-case groups, and an IPv4-mapped IPv6 address (::ffff:1.2.3.4) becomes the IPv4 address.
  • normalizeOrigins: Normalizes origins to scheme://host[:port] form.
  • parseCookies: Parses a Cookie header.
  • parseJsonSafe: Parses JSON from untrusted input and rejects what could pollute a prototype later: a __proto__ key anywhere, a constructor or prototype key holding an object, and nesting deeper than 64 levels.
  • platformHost: Builds the host object passed to handler.fetch.
  • readFormLimited: Reads a multipart/form-data or application/x-www-form-urlencoded body and checks its entries against the form caps: the number of fields and of files, the size of a file, the size of a text field and the total of the text fields.
  • readJson: Reads and parses a JSON request body safely (see parseJsonSafe).
  • readJsonLimited: Reads and parses a JSON request body safely (see parseJsonSafe), never more than maxBytes.
  • readTextLimited: Reads a request body as text, never more than maxBytes (a smaller limit than the handler's, for endpoints that accept less).
  • resolveChain: Resolves a matched chain, outermost route first.
  • resolveClientAddress: Chooses the client address.
  • resolveRedirectTarget: Like checkRedirectTarget, but throws.
  • revalidatePath: Discards the cached page at a path, so the next request renders it again.
  • revalidateTag: Discards every cached page indexed under a tag.
  • rewrite: Returns a rewrite answer for middleware: return rewrite("/internal/path").
  • robotsRoute: An API route handler that serves robots.txt.
  • robotsTxt: The text of robots.txt, written as Next writes it: User-Agent lines, the rules, a blank line after each group, then the Host line and one Sitemap line per file.
  • runtimeEnvironment: The environment of a runtime that has no process.env of its own (Deno-based edge runtimes): Deno.env when it exists, else process.env, else undefined.
  • runWithEvent: Runs callback with event as the current request event.
  • safeImageFetch: Creates a fetch that only connects to addresses refuse allows.
  • secureHeaderEntries: The headers added to every response, as name-value pairs, for the given options.
  • serializeCookie: Builds a Set-Cookie value.
  • serverFn: Defines a server function.
  • serverOptionsFromConfig: The handler options a baked configuration stands for.
  • setFlash: Sets a value that the next page shows once, read with useFlash() on the page.
  • sharpProcessor: A processor that resizes and converts raster images with sharp.
  • signIn: Signs a visitor in: gives the session a new id first, then stores values in it.
  • sitemapIndexRoute: An API route handler that serves the sitemap index of several sitemaps.
  • sitemapIndexXml: The index file of several sitemaps (generateSitemaps): one <sitemap> per file, laid out like sitemapXml.
  • sitemapRoute: An API route handler that serves sitemap.xml from a function of the request event.
  • sitemapXml: The XML of one sitemap file, written as Next writes it: one element per line, the namespaces in Next's order, a final newline.
  • text: A plain text response (text/plain; charset=utf-8).
  • timing: Measures fn under name for the request that is running (getRequestEvent().timing.measure): the same as event.timing.measure, for code that has no event at hand.
  • tryGetRequestEvent: The event of the request being handled, or undefined outside a request or where the runtime has no AsyncLocalStorage.
  • useRequestLocals: Same as getLocals, named for use inside a loader or a server function body.
  • validate: Validates value with a Standard Schema.
  • validateRouting: Validates the declarative routing and compiles every pattern.
  • waitUntil: Keeps promise running after the response is sent.
  • xmlEscape: XML text escaping for element content and attribute values.

Classes#

  • BodyTooLargeError: Thrown while a request body is read when it grows past the limit.
  • DuskError: Error with a stable diagnostic code, for conditions the caller can fix.
  • EnvError: Thrown at startup when the environment does not match its schema.
  • FrameReader: Reads the frames a peer sends.
  • RedirectBlockedError: Thrown when a redirect target is not allowed (an open-redirect attempt or a misconfiguration).
  • RequestTimeoutError: Thrown by the handler when the request outlives its time budget.
  • SseOverflowError: A consumer fell so far behind that the stream was closed.
  • ValidationError: Thrown when input does not pass its schema.
  • WebSocketProtocolError: A protocol violation: the connection is closed with code.

Interfaces#

Types#

  • ApiHandler: A handler of one HTTP method of an API route.
  • ApiResult: What an API route handler may return.
  • AppComponent: The root component of the app.
  • CacheControlOption: The option, as written.
  • CacheLifePreset: The built-in profile names.
  • ChainErrorHandler: Called with an error a metadata function threw, and the route it belongs to.
  • ChangeFrequency: changefreq values of the sitemap protocol.
  • CsrfReason: Why a request was accepted or rejected.
  • EnvField: A variable description.
  • EnvShape: Variable name to description.
  • EnvSource: Where variables are read from.
  • ErrorPhase: Where an error was caught.
  • FeatureName: The names of the features.
  • FormLimitsOptions: The caps a form read is held to: the app's security.limits.form, then the route's overrides.
  • GeoPlatform: The platforms whose geo the adapter entries read (see geoOf).
  • Guard: A guard: a check that runs before a server function's input is validated or its handler runs, and before an API route method's body is read.
  • HttpMethod: HTTP methods the handler dispatches.
  • InferInput: The input type of a schema.
  • InferOutput: The output type of a schema.
  • Middleware: Middleware: runs around the rest of the request.
  • Next: Continues the middleware chain.
  • ServerFnMiddleware: Middleware of a server function.
  • ServerFnRateLimitOption: What serverFn({ rateLimit }) accepts: a limiter, or a limiter with a caller key and a cost.
  • SharpFactory: Creates an instance from the encoded bytes of an image.
  • SseHandler: A stream route's handler: `export function SSE(event, stream) { ...
  • StandardSchemaV1Result: Result of validating: a value, or issues.
  • UpgradeDecision: The answer to a WebSocket upgrade: refused with a response, or accepted.
  • WsEvent: One thing a client sent.

Constants#

components#