module

Noir::TreeSitterHapiExtractor

Tree-sitter-backed Hapi extractor.

Hapi routes are object-literal configs passed to server.route({...}) (or an array of them):

server.route({
    method: 'GET',
    path: '/users/{id}',
    handler: (request, h) => { ... }
});

server.route([
    { method: 'POST', path: '/users', handler: ... },
    { method: ['PUT', 'PATCH'], path: '/users/{id}', handler: ... },
]);

Recognised:

  • Single object or array-of-objects route config.
  • method: as a string, an array of strings, or '*' (any-method — fans out to GET/POST/PUT/DELETE/PATCH).
  • path: as a string literal.
  • handler: arrow function — body scanned for request.query.X, request.headers['x'] / request.headers.x, request.payload, request.state.X.

Out of scope for this first cut:

  • options.validate constraint synthesis (Joi schemas).
  • Pre-handler chains (pre: [...]).
  • server.route registered through plugins / wildcards in the receiver (api.route, etc.) — receiver name is ignored, so only the .route(...) shape matters.

Constants

ANY_METHOD_VERBS = ["GET", "POST", "PUT", "DELETE", "PATCH"]
HTTP_VERBS = Set {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"}
STRING_LITERAL_TYPES = Set {"string", "template_string"}

path: is written as either a quoted string or a backtick template literal — tree-sitter-javascript emits template_string for the latter. decode_string has always known how to unwrap both; the gate below rejecting backticks dropped the whole route object.

Instance methods

extract_routes(source : String, include_callees : Bool = false) : Array(Route)
Source

Nested types