@@ -30,19 +30,60 @@ public struct Package {
30
30
case sourceControl( url: URL )
31
31
}
32
32
33
+ public struct Resource : Sendable {
34
+ public let name : String
35
+ public let type : String
36
+ public let checksum : String ?
37
+ public let signing : Signing ?
38
+ }
39
+
40
+ public struct Signing : Sendable {
41
+ public let signatureBase64Encoded : String
42
+ public let signatureFormat : String
43
+ }
44
+
45
+ public struct Author : Sendable {
46
+ public let name : String
47
+ public let email : String ?
48
+ public let description : String ?
49
+ public let organization : Organization ?
50
+ public let url : URL ?
51
+ }
52
+
53
+ public struct Organization : Sendable {
54
+ public let name : String
55
+ public let email : String ?
56
+ public let description : String ?
57
+ public let url : URL ?
58
+ }
59
+
33
60
public let identity : PackageIdentity
34
61
public let location : String ?
35
62
public let branches : [ String ]
36
63
public let versions : [ Version ]
37
- public let readmeURL : URL ?
38
64
public let source : Source
39
65
40
- fileprivate init ( identity: PackageIdentity , location: String ? = nil , branches: [ String ] = [ ] , versions: [ Version ] , readmeURL: URL ? = nil , source: Source ) {
66
+ // Per version metadata based on the latest version that we include here for convenience.
67
+ public let licenseURL : URL ?
68
+ public let readmeURL : URL ?
69
+ public let repositoryURLs : [ URL ] ?
70
+ public let resources : [ Resource ]
71
+ public let author : Author ?
72
+ public let description : String ?
73
+ public let latestVersion : Version ?
74
+
75
+ fileprivate init ( identity: PackageIdentity , location: String ? = nil , branches: [ String ] = [ ] , versions: [ Version ] , licenseURL: URL ? = nil , readmeURL: URL ? = nil , repositoryURLs: [ URL ] ? , resources: [ Resource ] , author: Author ? , description: String ? , latestVersion: Version ? = nil , source: Source ) {
41
76
self . identity = identity
42
77
self . location = location
43
78
self . branches = branches
44
79
self . versions = versions
80
+ self . licenseURL = licenseURL
45
81
self . readmeURL = readmeURL
82
+ self . repositoryURLs = repositoryURLs
83
+ self . resources = resources
84
+ self . author = author
85
+ self . description = description
86
+ self . latestVersion = latestVersion
46
87
self . source = source
47
88
}
48
89
}
@@ -80,11 +121,20 @@ public struct PackageSearchClient {
80
121
}
81
122
return nil
82
123
}
83
-
84
- private func getReadMeURL(
124
+
125
+ private struct Metadata {
126
+ public let licenseURL : URL ?
127
+ public let readmeURL : URL ?
128
+ public let repositoryURLs : [ URL ] ?
129
+ public let resources : [ Package . Resource ]
130
+ public let author : Package . Author ?
131
+ public let description : String ?
132
+ }
133
+
134
+ private func getVersionMetadata(
85
135
package : PackageIdentity ,
86
136
version: Version ,
87
- callback: @escaping ( Result < URL ? , Error > ) -> Void
137
+ callback: @escaping ( Result < Metadata , Error > ) -> Void
88
138
) {
89
139
self . registryClient. getPackageVersionMetadata (
90
140
package : package ,
@@ -93,7 +143,16 @@ public struct PackageSearchClient {
93
143
observabilityScope: observabilityScope,
94
144
callbackQueue: DispatchQueue . sharedConcurrent
95
145
) { result in
96
- callback ( result. tryMap { metadata in metadata. readmeURL } )
146
+ callback ( result. tryMap { metadata in
147
+ Metadata (
148
+ licenseURL: metadata. licenseURL,
149
+ readmeURL: metadata. readmeURL,
150
+ repositoryURLs: metadata. repositoryURLs,
151
+ resources: metadata. resources. map { . init( $0) } ,
152
+ author: metadata. author. map { . init( $0) } ,
153
+ description: metadata. description
154
+ )
155
+ } )
97
156
}
98
157
}
99
158
@@ -111,7 +170,13 @@ public struct PackageSearchClient {
111
170
Package ( identity: $0. package . identity,
112
171
location: $0. package . location,
113
172
versions: $0. package . versions. map { $0. version } ,
173
+ licenseURL: nil ,
114
174
readmeURL: $0. package . readmeURL,
175
+ repositoryURLs: nil ,
176
+ resources: [ ] ,
177
+ author: nil ,
178
+ description: nil ,
179
+ latestVersion: nil , // this only makes sense in connection with providing versioned metadata
115
180
source: . indexAndCollections( collections: $0. collections, indexes: $0. indexes)
116
181
)
117
182
}
@@ -149,7 +214,13 @@ public struct PackageSearchClient {
149
214
location: url. absoluteString,
150
215
branches: branches,
151
216
versions: versions,
217
+ licenseURL: nil ,
152
218
readmeURL: self . guessReadMeURL ( baseURL: url, defaultBranch: try repository. getDefaultBranch ( ) ) ,
219
+ repositoryURLs: nil ,
220
+ resources: [ ] ,
221
+ author: nil ,
222
+ description: nil ,
223
+ latestVersion: nil , // this only makes sense in connection with providing versioned metadata
153
224
source: . sourceControl( url: url) )
154
225
return callback ( . success( [ package ] ) )
155
226
}
@@ -174,25 +245,52 @@ public struct PackageSearchClient {
174
245
175
246
// See if the latest package version has readmeURL set
176
247
if let version = versions. first {
177
- self . getReadMeURL ( package : identity, version: version) { result in
248
+ self . getVersionMetadata ( package : identity, version: version) { result in
249
+ let licenseURL : URL ?
178
250
let readmeURL : URL ?
179
- if case . success( . some( let readmeURLForVersion) ) = result {
180
- readmeURL = readmeURLForVersion
251
+ let repositoryURLs : [ URL ] ?
252
+ let resources : [ Package . Resource ]
253
+ let author : Package . Author ?
254
+ let description : String ?
255
+ if case . success( let metadata) = result {
256
+ licenseURL = metadata. licenseURL
257
+ readmeURL = metadata. readmeURL
258
+ repositoryURLs = metadata. repositoryURLs
259
+ resources = metadata. resources
260
+ author = metadata. author
261
+ description = metadata. description
181
262
} else {
263
+ licenseURL = nil
182
264
readmeURL = self . guessReadMeURL ( alternateLocations: metadata. alternateLocations)
265
+ repositoryURLs = nil
266
+ resources = [ ]
267
+ author = nil
268
+ description = nil
183
269
}
184
-
270
+
185
271
return callback ( . success( [ Package ( identity: identity,
186
272
versions: metadata. versions,
273
+ licenseURL: licenseURL,
187
274
readmeURL: readmeURL,
275
+ repositoryURLs: repositoryURLs,
276
+ resources: resources,
277
+ author: author,
278
+ description: description,
279
+ latestVersion: version,
188
280
source: . registry( url: metadata. registry. url)
189
281
) ] ) )
190
282
}
191
283
} else {
192
284
let readmeURL : URL ? = self . guessReadMeURL ( alternateLocations: metadata. alternateLocations)
193
285
return callback ( . success( [ Package ( identity: identity,
194
286
versions: metadata. versions,
287
+ licenseURL: nil ,
195
288
readmeURL: readmeURL,
289
+ repositoryURLs: nil ,
290
+ resources: [ ] ,
291
+ author: nil ,
292
+ description: nil ,
293
+ latestVersion: nil , // this only makes sense in connection with providing versioned metadata
196
294
source: . registry( url: metadata. registry. url)
197
295
) ] ) )
198
296
}
@@ -243,3 +341,45 @@ public struct PackageSearchClient {
243
341
}
244
342
}
245
343
}
344
+
345
+ fileprivate extension Package . Signing {
346
+ init ( _ signing: RegistryClient . PackageVersionMetadata . Signing ) {
347
+ self . init (
348
+ signatureBase64Encoded: signing. signatureBase64Encoded,
349
+ signatureFormat: signing. signatureFormat
350
+ )
351
+ }
352
+ }
353
+
354
+ fileprivate extension Package . Resource {
355
+ init ( _ resource: RegistryClient . PackageVersionMetadata . Resource ) {
356
+ self . init (
357
+ name: resource. name,
358
+ type: resource. type,
359
+ checksum: resource. checksum,
360
+ signing: resource. signing. map { . init( $0) } )
361
+ }
362
+ }
363
+
364
+ fileprivate extension Package . Author {
365
+ init ( _ author: RegistryClient . PackageVersionMetadata . Author ) {
366
+ self . init (
367
+ name: author. name,
368
+ email: author. email,
369
+ description: author. description,
370
+ organization: author. organization. map { . init( $0) } ,
371
+ url: author. url
372
+ )
373
+ }
374
+ }
375
+
376
+ fileprivate extension Package . Organization {
377
+ init ( _ organization: RegistryClient . PackageVersionMetadata . Organization ) {
378
+ self . init (
379
+ name: organization. name,
380
+ email: organization. email,
381
+ description: organization. description,
382
+ url: organization. url
383
+ )
384
+ }
385
+ }
0 commit comments