@@ -43,11 +43,9 @@ base mixin PubDevSupport on ToolsSupport {
43
43
try {
44
44
result = jsonDecode (await _client.read (searchUrl));
45
45
46
- final packageNames =
47
- dig <List >(result, ['packages' ])
48
- .take (_resultsLimit)
49
- .map ((p) => dig <String >(p, ['package' ]))
50
- .toList ();
46
+ final packageNames = dig <List >(result, [
47
+ 'packages' ,
48
+ ]).take (_resultsLimit).map ((p) => dig <String >(p, ['package' ])).toList ();
51
49
52
50
if (packageNames.isEmpty) {
53
51
return CallToolResult (
@@ -71,15 +69,17 @@ base mixin PubDevSupport on ToolsSupport {
71
69
}
72
70
73
71
// Retrieve information about all the packages in parallel.
74
- final subQueryFutures =
75
- packageNames
76
- .map (
77
- (packageName) => (
78
- versionListing: retrieve ('api/packages/$packageName ' ),
79
- score: retrieve ('api/packages/$packageName /score' ),
80
- ),
81
- )
82
- .toList ();
72
+ final subQueryFutures = packageNames
73
+ .map (
74
+ (packageName) => (
75
+ versionListing: retrieve ('api/packages/$packageName ' ),
76
+ score: retrieve ('api/packages/$packageName /score' ),
77
+ docIndex: retrieve (
78
+ 'documentation/$packageName /latest/index.json' ,
79
+ ),
80
+ ),
81
+ )
82
+ .toList ();
83
83
84
84
// Aggregate the retrieved information about each package into a
85
85
// TextContent.
@@ -88,6 +88,17 @@ base mixin PubDevSupport on ToolsSupport {
88
88
final packageName = packageNames[i];
89
89
final versionListing = await subQueryFutures[i].versionListing;
90
90
final scoreResult = await subQueryFutures[i].score;
91
+ final libraryDocs = {
92
+ for (var object
93
+ in ((await subQueryFutures[i].docIndex) as List ? )
94
+ ? .cast <Map <String , Object ?>>() ??
95
+ < Map <String , Object ?>> [])
96
+ if (! object.containsKey ('enclosedBy' ))
97
+ object['name' ] as String : Uri .https (
98
+ 'pub.dev' ,
99
+ 'documentation/$packageName /latest/${object ['href' ]}' ,
100
+ ).toString (),
101
+ };
91
102
results.add (
92
103
TextContent (
93
104
text: jsonEncode ({
@@ -97,12 +108,28 @@ base mixin PubDevSupport on ToolsSupport {
97
108
'latest' ,
98
109
'version' ,
99
110
]),
100
- 'description' : dig <String >(versionListing, [
111
+ 'description' : ? dig <String ? >(versionListing, [
101
112
'latest' ,
102
113
'pubspec' ,
103
114
'description' ,
104
115
]),
116
+ 'homepage' : ? dig <String ?>(versionListing, [
117
+ 'latest' ,
118
+ 'pubspec' ,
119
+ 'homepage' ,
120
+ ]),
121
+ 'repository' : ? dig <String ?>(versionListing, [
122
+ 'latest' ,
123
+ 'pubspec' ,
124
+ 'repository' ,
125
+ ]),
126
+ 'documentation' : ? dig <String ?>(versionListing, [
127
+ 'latest' ,
128
+ 'pubspec' ,
129
+ 'documentation' ,
130
+ ]),
105
131
},
132
+ if (libraryDocs.isNotEmpty) ...{'libraries' : libraryDocs},
106
133
if (scoreResult != null ) ...{
107
134
'scores' : {
108
135
'pubPoints' : dig <int >(scoreResult, ['grantedPoints' ]),
@@ -112,19 +139,15 @@ base mixin PubDevSupport on ToolsSupport {
112
139
'downloadCount30Days' ,
113
140
]),
114
141
},
115
- 'topics' :
116
- dig <List >(
117
- scoreResult,
118
- ['tags' ],
119
- ).where ((t) => (t as String ).startsWith ('topic:' )).toList (),
120
- 'licenses' :
121
- dig <List >(scoreResult, ['tags' ])
122
- .where ((t) => (t as String ).startsWith ('license' ))
123
- .toList (),
124
- 'publisher' :
125
- dig <List >(scoreResult, ['tags' ])
126
- .where ((t) => (t as String ).startsWith ('publisher:' ))
127
- .firstOrNull,
142
+ 'topics' : dig <List >(scoreResult, [
143
+ 'tags' ,
144
+ ]).where ((t) => (t as String ).startsWith ('topic:' )).toList (),
145
+ 'licenses' : dig <List >(scoreResult, [
146
+ 'tags' ,
147
+ ]).where ((t) => (t as String ).startsWith ('license' )).toList (),
148
+ 'publisher' : dig <List >(scoreResult, ['tags' ])
149
+ .where ((t) => (t as String ).startsWith ('publisher:' ))
150
+ .firstOrNull,
128
151
},
129
152
}),
130
153
),
0 commit comments