@@ -2,6 +2,8 @@ import 'dart:async';
22import 'dart:convert' ;
33import 'dart:io' ;
44
5+ import 'package:_pub_shared/data/advisories_api.dart' ;
6+ import 'package:_pub_shared/data/package_api.dart' ;
57import 'package:clock/clock.dart' ;
68import 'package:gcloud/storage.dart' ;
79import 'package:logging/logging.dart' ;
@@ -43,7 +45,8 @@ final class ExportedApi {
4345 ExportedPackage ._(this , packageName);
4446
4547 /// Interface for writing `/api/package-name-completion-data`
46- ExportedJsonFile get packageNameCompletionData => ExportedJsonFile ._(
48+ ExportedJsonFile <Map <String , Object ?>> get packageNameCompletionData =>
49+ ExportedJsonFile <Map <String , Object ?>>._(
4750 this ,
4851 '/api/package-name-completion-data' ,
4952 Duration (hours: 8 ),
@@ -178,7 +181,7 @@ final class ExportedPackage {
178181
179182 ExportedPackage ._(this ._owner, this ._package);
180183
181- ExportedJsonFile _suffix (String suffix) => ExportedJsonFile ._(
184+ ExportedJsonFile < T > _suffix < T > (String suffix) => ExportedJsonFile < T > ._(
182185 _owner,
183186 '/api/packages/$_package $suffix ' ,
184187 Duration (minutes: 10 ),
@@ -187,10 +190,11 @@ final class ExportedPackage {
187190 /// Interface for writing `/api/packages/<package>` .
188191 ///
189192 /// Which contains version listing information.
190- ExportedJsonFile get versions => _suffix ('' );
193+ ExportedJsonFile < PackageData > get versions => _suffix < PackageData > ('' );
191194
192195 /// Interface for writing `/api/packages/<package>/advisories` .
193- ExportedJsonFile get advisories => _suffix ('/advisories' );
196+ ExportedJsonFile <ListAdvisoriesResponse > get advisories =>
197+ _suffix <ListAdvisoriesResponse >('/advisories' );
194198
195199 /// Interace for writing `/api/archives/<package>-<version>.tar.gz` .
196200 ExportedBlob tarball (String version) => ExportedBlob ._(
@@ -239,7 +243,7 @@ sealed class ExportedObject {
239243/// * `Content-Type` ,
240244/// * `Content-Encoding` , and,
241245/// * `Cache-Control` .
242- final class ExportedJsonFile extends ExportedObject {
246+ final class ExportedJsonFile < T > extends ExportedObject {
243247 static final _jsonGzip = json.fuse (utf8).fuse (gzip);
244248 final Duration _maxAge;
245249
@@ -256,7 +260,7 @@ final class ExportedJsonFile extends ExportedObject {
256260 );
257261
258262 /// Write [data] as gzipped JSON in UTF-8 format.
259- Future <void > write (Map < String , Object ?> data) async {
263+ Future <void > write (T data) async {
260264 final gzipped = _jsonGzip.encode (data);
261265 await Future .wait (_owner._prefixes.map ((prefix) async {
262266 await _owner._pool.withResource (() async {
0 commit comments