OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, 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 | |
5 library pubserver.repository; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import 'package:pub_semver/pub_semver.dart'; | |
10 | |
11 /// Represents information about a specific version of a pub package. | |
12 class PackageVersion { | |
13 /// The name of the package. | |
14 final String packageName; | |
15 | |
16 /// The version string of the package. | |
17 final String versionString; | |
18 | |
19 /// The pubspec yaml file of the package | |
20 final String pubspecYaml; | |
21 | |
22 Version _cached; | |
23 | |
24 /// The version of the package as a [Version] object. | |
25 Version get version { | |
26 if (_cached != null) return _cached; | |
27 _cached = new Version.parse(versionString); | |
28 return _cached; | |
29 } | |
30 | |
31 PackageVersion(this.packageName, this.versionString, this.pubspecYaml); | |
32 | |
33 int get hashCode => | |
34 packageName.hashCode ^ versionString.hashCode ^ pubspecYaml.hashCode; | |
35 | |
36 bool operator==(other) { | |
37 return other is PackageVersion && | |
38 other.packageName == packageName && | |
39 other.versionString == versionString && | |
40 other.pubspecYaml == pubspecYaml; | |
41 } | |
42 | |
43 String toString() => 'PackageVersion: $packageName/$versionString'; | |
44 } | |
45 | |
46 | |
47 /// Information obtained when starting an asynchronous upload. | |
48 class AsyncUploadInfo { | |
49 /// The endpoint where the uploaded data should be posted. | |
50 /// | |
51 /// The upload is a POST to [uri] with the headers [fields] in the HTTP | |
52 /// request. The body of the POST request must be a valid tar.gz file. | |
53 final Uri uri; | |
54 | |
55 /// The fields the uploader should add to the multipart upload. | |
56 final Map<String, String> fields; | |
57 | |
58 AsyncUploadInfo(this.uri, this.fields); | |
59 } | |
60 | |
61 /// Exception for unauthorized access attempts. | |
62 /// | |
63 /// Uploading a new package from an unauthorized user will result in an | |
64 /// [UnauthorizedAccess] exception. | |
65 class UnauthorizedAccess implements Exception { | |
66 final String message; | |
67 | |
68 UnauthorizedAccess(this.message); | |
69 | |
70 String toString() => 'UnauthorizedAccess: $message'; | |
71 } | |
72 | |
73 /// Represents a pub repository. | |
74 abstract class PackageRepository { | |
75 /// Returns the known versions of [package]. | |
76 Stream<PackageVersion> versions(String package); | |
77 | |
78 /// Whether the [version] of [package] exists. | |
79 Future<PackageVersion> lookupVersion(String package, String version); | |
80 | |
81 | |
82 /// Whether this package repository supports uploading packages. | |
83 bool get supportsUpload => false; | |
84 | |
85 /// Uploads a new pub package. | |
86 /// | |
87 /// [data] must be a stream of a valid .tar.gz file. | |
88 Future upload(Stream<List<int>> data) | |
89 => new Future.error(new UnsupportedError('No upload support.')); | |
90 | |
91 /// Whether this package repository supports asynchronous uploads. | |
92 bool get supportsAsyncUpload => false; | |
93 | |
94 /// Starts a new upload. | |
95 /// | |
96 /// The given [baseRedirectUrl] instructs the uploading client to make a GET | |
97 /// request to this location once the upload is complete. It might contain | |
98 /// additional query parameters and must be supplied to `finishAsyncUpload`. | |
99 /// | |
100 /// The returned [AsyncUploadInfo] specifies where the tar.gz file should be | |
101 /// posted to and what headers should be supplied. | |
102 Future<AsyncUploadInfo> startAsyncUpload(Uri redirectUrl) | |
103 => new Future.error(new UnsupportedError('No async upload support.')); | |
104 | |
105 /// Finishes the upload of a package. | |
106 Future finishAsyncUpload(Uri uri) | |
107 => new Future.error(new UnsupportedError('No async upload support.')); | |
108 | |
109 | |
110 /// Downloads a pub package. | |
111 Future<Stream> download(String package, String version); | |
112 | |
113 /// Whether this package repository supports download URLs. | |
114 bool get supportsDownloadUrl => false; | |
115 | |
116 /// A permanent download URL to a package (if supported). | |
117 Future<Uri> downloadUrl(String package, String version) | |
118 => new Future.error(new UnsupportedError('No download link support.')); | |
119 } | |
OLD | NEW |