MCPcopy Create free account
hub / github.com/Houseofmvps/codesight / adaptPlugin

Function adaptPlugin

src/ast/native-loader.ts:304–359  ·  view source on GitHub ↗

Map a raw LoadedPlugin to codesight's domain types. A method is exposed only * when the plugin exports the matching capability (so callers can detect it).

(loaded: LoadedPlugin)

Source from the content-addressed store, hash-verified

302/** Map a raw LoadedPlugin to codesight's domain types. A method is exposed only
303 * when the plugin exports the matching capability (so callers can detect it). */
304function adaptPlugin(loaded: LoadedPlugin): NativePlugin {
305 const np: NativePlugin = {};
306
307 if (loaded.routes) {
308 np.routes = (file, content, framework, tags) => {
309 const raw = loaded.routes!(content);
310 if (!Array.isArray(raw)) return null;
311 return raw.map((x: any): RouteInfo => {
312 const path = String(x?.path ?? "");
313 return {
314 method: String(x?.method ?? "ALL"),
315 path,
316 file,
317 tags,
318 framework,
319 params: Array.isArray(x?.params) ? x.params.map(String) : extractPathParams(path),
320 confidence: "native",
321 ...(Array.isArray(x?.middleware) ? { middleware: x.middleware.map(String) } : {}),
322 };
323 });
324 };
325 }
326
327 if (loaded.schemas) {
328 np.schemas = (_file, content) => {
329 const raw = loaded.schemas!(content);
330 if (!Array.isArray(raw)) return null;
331 return raw.map((m: any): SchemaModel => ({
332 name: String(m?.name ?? ""),
333 fields: (Array.isArray(m?.fields) ? m.fields : []).map((f: any): SchemaField => ({
334 name: String(f?.name ?? ""),
335 type: String(f?.type ?? "unknown"),
336 flags: Array.isArray(f?.flags) ? f.flags.map(String) : [],
337 })),
338 relations: (Array.isArray(m?.relations) ? m.relations : []).map(String),
339 orm: (m?.orm ?? "unknown") as ORM,
340 confidence: "native",
341 }));
342 };
343 }
344
345 // `imports` is part of the published contract and exercised by the conformance
346 // test, but no scan dispatches to it yet (see detectors/graph.ts).
347 if (loaded.imports) {
348 np.imports = (file, content) => {
349 const raw = loaded.imports!(content);
350 if (!Array.isArray(raw)) return null;
351 return raw.map((x: any): ImportEdge => ({
352 from: file,
353 to: typeof x === "string" ? x : String(x?.to ?? ""),
354 }));
355 };
356 }
357
358 return np;
359}
360
361function extractPathParams(path: string): string[] {

Callers 2

buildNativeRegistryFunction · 0.85
getNativePluginFunction · 0.85

Calls 1

extractPathParamsFunction · 0.70

Tested by

no test coverage detected