class

Analyzer::Javascript::Fastify

Inherits Analyzer::Javascript::JavascriptEngine < Analyzer < FileHelper < Reference < Object

Constants

AUTO_PREFIX_RE = /\bautoPrefix\s*=\s*['"]([^'"]+)['"]/
AUTOLOAD_MARKERS_RE = Regex.union("@fastify/autoload", "fastify-autoload")

Markers that a file configures @fastify/autoload. Both the scoped package and the legacy bare name are matched so older projects work. Precompiled once — a single PCRE2-JIT scan replaces two naive String#includes? substring scans. Regex.union auto-escapes each literal, so it is provably equivalent to the OR-of-includes? it replaces.

EXPORTED_PLUGIN_NAME = /(?:export\s+default|module\.exports\s*=)\s*(?:[\w$.]+\s*\(\s*)?([A-Za-z_$][\w$]*)\s*[;)\n]/

module.exports = routes / export default fp(routes): registered elsewhere.

EXPORTED_PLUGIN_PARAM = /(?:export\s+default|module\.exports\s*=)\s*(?:[\w$.]+\s*\(\s*)?(?:async\s+)?(?:function\s*[\w$]*\s*\(\s*([A-Za-z_$][\w$]*)|\(\s*([A-Za-z_$][\w$]*)|([A-Za-z_$][\w$]*)\s*=>)/

Optionally wrapped: module.exports = fp(async function (f) {…}).

FASTIFY_INSTANCE_NAME = /\A(?:fastify|app|server|instance)\z|(?:App|Server)\z/

.query( is every database and search client's method, so unlike route({ …, handler }) the call shape cannot vouch for the receiver. It has to be a Fastify instance: conventionally named, or the first parameter of a plugin function (inline in register(…), a function handed to register(name, …), or a module's default export).

FUNCTION_FIRST_PARAM = /function\s+([A-Za-z_$][\w$]*)\s*\(\s*([A-Za-z_$][\w$]*)|(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\s+)?(?:function\s*[\w$]*\s*\(\s*([A-Za-z_$][\w$]*)|\(\s*([A-Za-z_$][\w$]*)|([A-Za-z_$][\w$]*)\s*=>)/
HTTP_METHODS = ["get", "post", "put", "delete", "patch", "options", "head", "query"] of ::String
INLINE_PLUGIN_PARAM = /\.register\s*\(\s*(?:async\s+)?(?:function\s*[\w$]*\s*\(\s*([A-Za-z_$][\w$]*)|\(\s*([A-Za-z_$][\w$]*)|([A-Za-z_$][\w$]*)\s*=>)/
PACKAGE_MARKERS = ["\"fastify\"", "\"@fastify/", "\"fastify-plugin\"", "\"@platformatic/"]
QUERY_METHOD_GATE_RE = /\baddHttpMethod\b|fastify-http-query/

Cheap per-file gate ahead of the comment strip the markers are read from.

QUERY_METHOD_MARKERS_RE = Regex.union(/\baddHttpMethod\s*\(\s*['"]QUERY['"]/i, /fastify-http-query/)

Markers indicating that HTTP QUERY method support is registered.

REGISTERED_PLUGIN_NAME = /\.register\s*\(\s*([A-Za-z_$][\w$]*)\s*[,)]/
ROUTE_CALL_RES = HTTP_METHODS.map do |m| {m, /\b(?:fastify|app|server)\s*\.\s*#{m}\s*\(\s*['"]([^'"]+)['"]/} end.to_h

Compiled once — an interpolated regex literal would otherwise be rebuilt (full PCRE2 compile) for every method on every line.

SCHEMA_PARAM_TYPES = {"querystring" => "query", "query" => "query", "body" => "json", "headers" => "header"}

A route's schema is its declared input, validated by Fastify itself.

Class methods

tech_name
Source

Instance methods

analyze
Source
line_to_endpoint(line : String, has_query : Bool = true) : Endpoint
Source
line_to_param(line : String) : Param
Source
tech

Instance-side view of the same declaration. The per-file rescues live on this base class, which has no way to name the analyzer that is running inside them, so a skipped file could not be attributed to a tech. Deriving it from analyzer_for keeps the name written exactly once.

Source

Nested types