module

Noir::JSServerlessFunctionExtractor

Reads the handler exports of a file-routed serverless function module (Cloudflare Pages Functions, Vercel Functions, Netlify Functions): which names it exports, where each handler's parameter list and body are, the inline config object, and the request params a handler body reads.

The URL comes from the file's location, so this layer only deals with the module's contents. Discovery and body ranges come from the syntax tree (Noir::JSHandlerTable); the request params are then read off the body text.

Constants

IDENT_RE = /\A[A-Za-z_$][\w$]*\z/
KNOWN_METHODS = JSHandlerTable::KNOWN_METHODS

Instance methods

config_key?(config : Config, key : String) : Bool
Source
config_object(content : String, path : String) : Config | Nil

The module's inline config object as string values by key, or nil: export const config = {...} (optionally typed or satisfies), or the config property of the default-exported object.

Source
config_strings(config : Config, key : String) : Array(String)

String values of key in a config object: path: "/a" or path: ["/a", "/b"] (also quoted keys). Non-literal values are ignored.

Source
default_handler(content : String, path : String, callees : Bool = false) : Handler | Nil

The module's default export (export default ... or CommonJS module.exports = ...). A default-exported object resolves to its fetch method, the Fetchable-module shape. Nil when there is none.

Source
exported_handler(content : String, path : String, name : String, callees : Bool = false) : Handler | Nil

The handler a module exports under name: export [async] function name(...), export const name = <fn>, CommonJS exports.name = <fn>, or export { local as name }. Nil when the module does not export it. callees also reads the handler's callees.

Source
extract_request_params(handler : Handler, endpoint : Endpoint, style : Symbol) : Nil

Request params a handler reads. style picks how the first parameter is interpreted:

  • :request — it is the request (Vercel/Netlify (req, ...)), or destructures one.
  • :context — it is an event context carrying .request and .params (Cloudflare Pages (context) / ({ request, params })).
  • :lambda — it is a Lambda-style event (Netlify v1 (event)): queryStringParameters, headers, a string body.
Source

Nested types