1+ // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
15import 'dart:async' ;
26import 'dart:convert' ;
37import 'dart:io' ;
48
9+ import 'package:_pub_shared/data/advisories_api.dart' ;
10+ import 'package:_pub_shared/data/package_api.dart' ;
511import 'package:clock/clock.dart' ;
612import 'package:gcloud/storage.dart' ;
713import 'package:logging/logging.dart' ;
@@ -43,7 +49,8 @@ final class ExportedApi {
4349 ExportedPackage ._(this , packageName);
4450
4551 /// Interface for writing `/api/package-name-completion-data`
46- ExportedJsonFile get packageNameCompletionData => ExportedJsonFile ._(
52+ ExportedJsonFile <Map <String , Object ?>> get packageNameCompletionData =>
53+ ExportedJsonFile <Map <String , Object ?>>._(
4754 this ,
4855 '/api/package-name-completion-data' ,
4956 Duration (hours: 8 ),
@@ -178,7 +185,7 @@ final class ExportedPackage {
178185
179186 ExportedPackage ._(this ._owner, this ._package);
180187
181- ExportedJsonFile _suffix (String suffix) => ExportedJsonFile ._(
188+ ExportedJsonFile < T > _suffix < T > (String suffix) => ExportedJsonFile < T > ._(
182189 _owner,
183190 '/api/packages/$_package $suffix ' ,
184191 Duration (minutes: 10 ),
@@ -187,10 +194,11 @@ final class ExportedPackage {
187194 /// Interface for writing `/api/packages/<package>` .
188195 ///
189196 /// Which contains version listing information.
190- ExportedJsonFile get versions => _suffix ('' );
197+ ExportedJsonFile < PackageData > get versions => _suffix < PackageData > ('' );
191198
192199 /// Interface for writing `/api/packages/<package>/advisories` .
193- ExportedJsonFile get advisories => _suffix ('/advisories' );
200+ ExportedJsonFile <ListAdvisoriesResponse > get advisories =>
201+ _suffix <ListAdvisoriesResponse >('/advisories' );
194202
195203 /// Interace for writing `/api/archives/<package>-<version>.tar.gz` .
196204 ExportedBlob tarball (String version) => ExportedBlob ._(
@@ -239,7 +247,7 @@ sealed class ExportedObject {
239247/// * `Content-Type` ,
240248/// * `Content-Encoding` , and,
241249/// * `Cache-Control` .
242- final class ExportedJsonFile extends ExportedObject {
250+ final class ExportedJsonFile < T > extends ExportedObject {
243251 static final _jsonGzip = json.fuse (utf8).fuse (gzip);
244252 final Duration _maxAge;
245253
@@ -256,7 +264,7 @@ final class ExportedJsonFile extends ExportedObject {
256264 );
257265
258266 /// Write [data] as gzipped JSON in UTF-8 format.
259- Future <void > write (Map < String , Object ?> data) async {
267+ Future <void > write (T data) async {
260268 final gzipped = _jsonGzip.encode (data);
261269 await Future .wait (_owner._prefixes.map ((prefix) async {
262270 await _owner._pool.withResource (() async {
0 commit comments