module Noir::TreeSitterAdonisJsExtractor

Overview

Tree-sitter-backed AdonisJS extractor.

AdonisJS exposes a Laravel-flavoured router via either Route (v5, @ioc:Adonis/Core/Route) or router (v6, @adonisjs/core/services/router). Both share the same shape:

Route.get('/users', 'UsersController.index')

Route.group(() => {
    Route.get('/posts', 'PostsController.index')
    Route.post('/posts', 'PostsController.store')
}).prefix('/api/v1').middleware('auth')

Route.resource('articles', 'ArticlesController').apiOnly()

The fluent modifiers (.prefix, .middleware, .as, .domain, .namespace, .where, .apiOnly, .only, .except) live on the result of the registration call. We walk the chain outermost-first so the modifiers can influence the prefix / resource action set before the inner registration emits.

Recognised:

Out of scope for this first cut:

Extended Modules

Defined in:

miniparsers/adonisjs_extractor_ts.cr

Constant Summary

ANY_VERBS = ["GET", "POST", "PUT", "DELETE", "PATCH"]
GROUP_METHOD = "group"
HTTP_VERB_METHODS = {"get" => "GET", "post" => "POST", "put" => "PUT", "delete" => "DELETE", "patch" => "PATCH", "options" => "OPTIONS", "head" => "HEAD"}
RESOURCE_ACTIONS = {"index" => {"GET", ""}, "store" => {"POST", ""}, "show" => {"GET", "/:id"}, "update" => {"PUT", "/:id"}, "destroy" => {"DELETE", "/:id"}}
TRANSPARENT_MODIFIERS = Set {"middleware", "as", "domain", "where", "namespace", "apiOnly"}

Modifiers that don't change the path or verb — we just walk the receiver with the same prefix.

Instance Method Summary

Instance Method Detail

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

[View source]