diff --git a/src/extractors/fastapi.ts b/src/extractors/fastapi.ts index 0524a6d..b2a3d5c 100644 --- a/src/extractors/fastapi.ts +++ b/src/extractors/fastapi.ts @@ -59,7 +59,8 @@ export const fastapi: Extractor = { const funcParams = m[6]!; const line = lines.lineAt(m.index); - if (httpMethod === "WEBSOCKET") httpMethod = "WS"; + const isWebSocket = httpMethod === "WEBSOCKET"; + if (isWebSocket) httpMethod = "WS"; const prefix = routerPrefixes[varName] ?? ""; const fullPath = normalizePath(prefix + routePath); @@ -83,6 +84,7 @@ export const fastapi: Extractor = { endpoints.push( endpoint({ method: httpMethod, + kind: isWebSocket ? "websocket" : "api", path: fullPath, handler: funcName, file: rel, diff --git a/src/extractors/server-actions.ts b/src/extractors/server-actions.ts index ba4aaa2..ce3c0f6 100644 --- a/src/extractors/server-actions.ts +++ b/src/extractors/server-actions.ts @@ -218,6 +218,7 @@ export const serverActions: Extractor = { endpoints.push( endpoint({ method: "ACTION", + kind: "action", path: `/${moduleName}/${exp.name}`, handler: exp.name, file: rel, diff --git a/src/format-impact.ts b/src/format-impact.ts index 07fcd5d..3820fc2 100644 --- a/src/format-impact.ts +++ b/src/format-impact.ts @@ -108,6 +108,7 @@ export function formatImpactJson(result: ImpactResult): string { affected: result.affected.map((a) => { const obj: Record = { method: a.endpoint.method, + kind: a.endpoint.kind, path: a.endpoint.path, handler: a.endpoint.handler, file: a.endpoint.file, @@ -151,6 +152,7 @@ export function formatImpactNdjson(result: ImpactResult): string { for (const a of result.affected) { const obj: Record = { method: a.endpoint.method, + kind: a.endpoint.kind, path: a.endpoint.path, handler: a.endpoint.handler, file: a.endpoint.file, diff --git a/src/format.ts b/src/format.ts index ddfcbd2..2d3cdb8 100644 --- a/src/format.ts +++ b/src/format.ts @@ -212,6 +212,7 @@ export function formatJson(result: MapResult, options?: FormatOptions): string { endpoints: endpoints.all.map((e) => { const obj: Record = { method: e.method, + kind: e.kind, path: e.path, handler: e.handler, file: e.file, @@ -263,6 +264,7 @@ export function formatNdjson( for (const e of endpoints) { const obj: Record = { method: e.method, + kind: e.kind, path: e.path, handler: e.handler, file: e.file, diff --git a/src/index.ts b/src/index.ts index 546b8e5..52779a7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ export type { AffectedEndpoint, DiffHunk, EndpointInfo, + EndpointKind, FunctionDef, FrameworkId, HttpMethod, diff --git a/src/types.ts b/src/types.ts index aafb80d..b992df0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -19,6 +19,8 @@ export type HttpMethod = | "WS" | "ACTION"; +export type EndpointKind = "api" | "page" | "action" | "websocket"; + export type ServiceType = | "nextjs" | "lambda" @@ -37,6 +39,7 @@ export interface ServiceInfo { export interface EndpointInfo { method: HttpMethod; + kind: EndpointKind; path: string; handler: string; file: string; diff --git a/src/utils.ts b/src/utils.ts index 8237e7d..39d82c0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ import type { EndpointInfo, + EndpointKind, FrameworkId, HttpMethod, ParamInfo, @@ -100,6 +101,7 @@ export function endpoint(e: { file: string; line: number; framework: FrameworkId; + kind?: EndpointKind; params?: ParamInfo[]; auth?: string[]; service?: string; @@ -108,6 +110,7 @@ export function endpoint(e: { }): EndpointInfo { const ep: EndpointInfo = { method: e.method as HttpMethod, + kind: e.kind ?? "api", path: e.path, handler: e.handler, file: e.file,