-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathinternal.ts
More file actions
111 lines (98 loc) · 2.2 KB
/
internal.ts
File metadata and controls
111 lines (98 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Internal types and utilities for AST analysis.
* These are implementation details not exposed in the public API.
*/
import type { RouteMethod } from "./types"
/**
* Valid HTTP methods plus WEBSOCKET, used for decorator validation.
* Lowercase for case-insensitive comparison during extraction.
*/
export const ROUTE_METHODS: ReadonlySet<string> = new Set([
"get",
"post",
"put",
"delete",
"patch",
"options",
"head",
"websocket",
])
/** Normalizes a method string to a valid RouteMethod. Returns "GET" for invalid methods. */
export function normalizeMethod(method: string): RouteMethod {
return ROUTE_METHODS.has(method.toLowerCase())
? (method.toUpperCase() as RouteMethod)
: "GET"
}
export interface RouteInfo {
// The router or app that owns this route
owner: string
method: string
path: string
function: string
line: number
column: number
docstring?: string
}
export type RouterType = "APIRouter" | "FastAPI" | "Unknown"
export interface RouterInfo {
variableName: string
type: RouterType
prefix: string
tags: string[]
line: number
column: number
}
export interface ImportedName {
name: string
alias: string | null
}
export interface ImportInfo {
modulePath: string
names: string[]
namedImports: ImportedName[]
isRelative: boolean
relativeDots: number
}
export interface IncludeRouterInfo {
// The app or router with the include_router call
owner: string
router: string
prefix: string
tags: string[]
}
export interface MountInfo {
// The app that owns this sub application mount
owner: string
path: string
app: string
}
export interface FileAnalysis {
filePath: string
routes: RouteInfo[]
routers: RouterInfo[]
includeRouters: IncludeRouterInfo[]
mounts: MountInfo[]
imports: ImportInfo[]
}
export interface RouterNode {
filePath: string
variableName: string
type: RouterType
prefix: string
tags: string[]
line: number
column: number
routes: {
method: string
path: string
function: string
line: number
column: number
docstring?: string
}[]
children: { router: RouterNode; prefix: string; tags: string[] }[]
}
export interface EntryPoint {
filePath: string
variableName?: string
}