Skip to content

Commit 77ddbd4

Browse files
committed
wip
1 parent de268e7 commit 77ddbd4

File tree

1 file changed

+88
-48
lines changed

1 file changed

+88
-48
lines changed

src/pages/PackageDetail/darkPackagesApi.ts

Lines changed: 88 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,41 @@ import { SubModule, PackageData } from "./types";
22

33
// API Response Types
44
export interface ApiFunction {
5-
name?: { name: string };
6-
parameters?: Array<{ name: string; typ: any }>;
7-
returnType?: any;
8-
description?: string;
5+
location?: {
6+
owner: string;
7+
modules: string[];
8+
name: string;
9+
};
10+
entity?: {
11+
parameters?: Array<{ name: string; typ: any }>;
12+
returnType?: any;
13+
description?: string;
14+
deprecated?: any;
15+
};
916
}
1017

1118
export interface ApiType {
12-
name?: { name: string };
13-
description?: string;
19+
location?: {
20+
owner: string;
21+
modules: string[];
22+
name: string;
23+
};
24+
entity?: {
25+
description?: string;
26+
deprecated?: any;
27+
};
1428
}
1529

1630
export interface ApiValue {
17-
name?: { name: string };
18-
description?: string;
31+
location?: {
32+
owner: string;
33+
modules: string[];
34+
name: string;
35+
};
36+
entity?: {
37+
description?: string;
38+
deprecated?: any;
39+
};
1940
}
2041

2142
export interface ApiResponse {
@@ -58,14 +79,16 @@ export interface ProcessedItemData {
5879
}
5980

6081
export interface TypeDefinition {
61-
declaration: any;
62-
deprecated: any;
63-
description: string;
64-
id: string;
65-
name: {
82+
location?: {
83+
owner: string;
6684
modules: string[];
6785
name: string;
68-
owner: string;
86+
};
87+
entity?: {
88+
id?: string;
89+
declaration?: any;
90+
deprecated?: any;
91+
description?: string;
6992
};
7093
}
7194

@@ -101,9 +124,14 @@ const UUID_REGEX =
101124
class DarkPackagesApi {
102125
private readonly baseUrl = "http://dark-packages.dlio.localhost:11001/search";
103126
private readonly typeUrl =
104-
"http://dark-packages.dlio.localhost:11001/type/get";
127+
"http://dark-packages.dlio.localhost:11001/type/get/with-location";
105128
private readonly typeCache = new Map<string, string>();
106129

130+
// Extract name from location
131+
private extractName(item: ApiFunction | ApiType | ApiValue): string {
132+
return item.location?.name ?? "Unknown";
133+
}
134+
107135
private async fetchData(url: string): Promise<ApiResponse> {
108136
try {
109137
const response = await fetch(url);
@@ -113,7 +141,8 @@ class DarkPackagesApi {
113141
`HTTP error! status: ${response.status} - ${errorText}`,
114142
);
115143
}
116-
return await response.json();
144+
const data = await response.json();
145+
return data;
117146
} catch (error) {
118147
console.error("API Fetch Error:", error);
119148
throw error;
@@ -146,7 +175,7 @@ class DarkPackagesApi {
146175
}
147176

148177
private getTypeNameFromDefinition(typeDef: TypeDefinition): string {
149-
return typeDef.name.name;
178+
return typeDef.location?.name ?? "Unknown";
150179
}
151180

152181
private async resolveCachedOrFetchType(typeId: string): Promise<string> {
@@ -217,7 +246,9 @@ class DarkPackagesApi {
217246
}
218247

219248
private async getTypeString(typeObj: any): Promise<string> {
220-
if (!typeObj) return "Unknown";
249+
if (!typeObj) {
250+
return "Unknown";
251+
}
221252

222253
// Handle primitive types
223254
const primitiveType = await this.processPrimitiveType(typeObj);
@@ -344,16 +375,21 @@ class DarkPackagesApi {
344375
}
345376

346377
private async createFunctionSignature(fn: ApiFunction): Promise<string> {
347-
const name = fn.name?.name || "Unknown";
348-
const params = await this.processParameters(fn.parameters);
378+
const name = this.extractName(fn);
379+
380+
// Extract parameters and returnType from entity
381+
const parameters = fn.entity?.parameters;
382+
const returnType = fn.entity?.returnType;
383+
384+
const params = await this.processParameters(parameters);
349385

350386
// Filter out unit parameters for display, but keep all function types
351387
const displayParams = params.filter(p => !UNIT_TYPES.has(p.type));
352388

353389
const paramStr = displayParams.map(p => `${p.name}: ${p.type}`).join(", ");
354-
const returnType = await this.getTypeString(fn.returnType);
390+
const returnTypeStr = await this.getTypeString(returnType);
355391

356-
return `${name}(${paramStr}) : ${returnType}`;
392+
return `${name}(${paramStr}) : ${returnTypeStr}`;
357393
}
358394

359395
async searchModuleData(moduleName: string): Promise<ApiResponse> {
@@ -466,25 +502,29 @@ class DarkPackagesApi {
466502

467503
const functionList = await Promise.all(
468504
(apiData.fns || []).map(async (fn: ApiFunction) => ({
469-
name: fn.name?.name || "Unknown",
505+
name: this.extractName(fn),
470506
signature: await this.createFunctionSignature(fn),
471-
description: fn.description || "No description available",
507+
description: fn.entity?.description || "No description available",
472508
})),
473509
);
474510

475-
const typeList = (apiData.types || []).map((type: ApiType) => ({
476-
name: type.name?.name || "Unknown",
477-
description:
478-
type.description ||
479-
`Type definition for ${type.name?.name || "Unknown"}`,
480-
}));
511+
const typeList = (apiData.types || []).map((type: ApiType) => {
512+
const name = this.extractName(type);
513+
const description = type.entity?.description;
514+
return {
515+
name,
516+
description: description || `Type definition for ${name}`,
517+
};
518+
});
481519

482-
const valueList = (apiData.values || []).map((value: ApiValue) => ({
483-
name: value.name?.name || "Unknown",
484-
description:
485-
value.description ||
486-
`Value definition for ${value.name?.name || "Unknown"}`,
487-
}));
520+
const valueList = (apiData.values || []).map((value: ApiValue) => {
521+
const name = this.extractName(value);
522+
const description = value.entity?.description;
523+
return {
524+
name,
525+
description: description || `Value definition for ${name}`,
526+
};
527+
});
488528

489529
return {
490530
name: displayName,
@@ -519,31 +559,31 @@ class DarkPackagesApi {
519559

520560
const fullFunctionData = await Promise.all(
521561
(apiData.fns || []).map(async (fn: ApiFunction) => ({
522-
name: fn.name?.name || "Unknown",
562+
name: this.extractName(fn),
523563
signature: await this.createFunctionSignature(fn),
524-
description: fn.description || "No description available",
564+
description: fn.entity?.description || "No description available",
525565
})),
526566
);
527567

528568
const fullTypeData = (apiData.types || []).map((type: ApiType) => ({
529-
name: type.name?.name || "Unknown",
530-
description: type.description || "No description available",
569+
name: this.extractName(type),
570+
description: type.entity?.description || "No description available",
531571
}));
532572

533573
const fullValueData = (apiData.values || []).map((value: ApiValue) => ({
534-
name: value.name?.name || "Unknown",
535-
description: value.description || "No description available",
574+
name: this.extractName(value),
575+
description: value.entity?.description || "No description available",
536576
}));
537577

538578
return {
539-
functions: (apiData.fns || []).map(
540-
(fn: ApiFunction) => fn.name?.name || "Unknown",
579+
functions: (apiData.fns || []).map((fn: ApiFunction) =>
580+
this.extractName(fn),
541581
),
542-
types: (apiData.types || []).map(
543-
(type: ApiType) => type.name?.name || "Unknown",
582+
types: (apiData.types || []).map((type: ApiType) =>
583+
this.extractName(type),
544584
),
545-
values: (apiData.values || []).map(
546-
(value: ApiValue) => value.name?.name || "Unknown",
585+
values: (apiData.values || []).map((value: ApiValue) =>
586+
this.extractName(value),
547587
),
548588
submodules: processedSubmodules,
549589
fullFunctionData,

0 commit comments

Comments
 (0)