@@ -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
}
@@ -78,19 +119,37 @@ public struct PackageSearchClient {
78
119
}
79
120
return nil
80
121
}
81
-
82
- private func getReadMeURL(
122
+
123
+ private struct Metadata {
124
+ public let licenseURL : URL ?
125
+ public let readmeURL : URL ?
126
+ public let repositoryURLs : [ URL ] ?
127
+ public let resources : [ Package . Resource ]
128
+ public let author : Package . Author ?
129
+ public let description : String ?
130
+ }
131
+
132
+ private func getVersionMetadata(
83
133
package : PackageIdentity ,
84
134
version: Version ,
85
- callback: @escaping ( Result < URL ? , Error > ) -> Void
135
+ callback: @escaping ( Result < Metadata , Error > ) -> Void
86
136
) {
87
137
self . registryClient. getPackageVersionMetadata (
88
138
package : package ,
89
139
version: version,
90
140
observabilityScope: observabilityScope,
91
141
callbackQueue: DispatchQueue . sharedConcurrent
92
142
) { result in
93
- callback ( result. tryMap { metadata in metadata. readmeURL } )
143
+ callback ( result. tryMap { metadata in
144
+ Metadata (
145
+ licenseURL: metadata. licenseURL,
146
+ readmeURL: metadata. readmeURL,
147
+ repositoryURLs: metadata. repositoryURLs,
148
+ resources: metadata. resources. map { . init( $0) } ,
149
+ author: metadata. author. map { . init( $0) } ,
150
+ description: metadata. description
151
+ )
152
+ } )
94
153
}
95
154
}
96
155
@@ -108,7 +167,13 @@ public struct PackageSearchClient {
108
167
Package ( identity: $0. package . identity,
109
168
location: $0. package . location,
110
169
versions: $0. package . versions. map { $0. version } ,
170
+ licenseURL: nil ,
111
171
readmeURL: $0. package . readmeURL,
172
+ repositoryURLs: nil ,
173
+ resources: [ ] ,
174
+ author: nil ,
175
+ description: nil ,
176
+ latestVersion: nil , // this only makes sense in connection with providing versioned metadata
112
177
source: . indexAndCollections( collections: $0. collections, indexes: $0. indexes)
113
178
)
114
179
}
@@ -146,7 +211,13 @@ public struct PackageSearchClient {
146
211
location: url. absoluteString,
147
212
branches: branches,
148
213
versions: versions,
214
+ licenseURL: nil ,
149
215
readmeURL: self . guessReadMeURL ( baseURL: url, defaultBranch: try repository. getDefaultBranch ( ) ) ,
216
+ repositoryURLs: nil ,
217
+ resources: [ ] ,
218
+ author: nil ,
219
+ description: nil ,
220
+ latestVersion: nil , // this only makes sense in connection with providing versioned metadata
150
221
source: . sourceControl( url: url) )
151
222
return callback ( . success( [ package ] ) )
152
223
}
@@ -171,25 +242,52 @@ public struct PackageSearchClient {
171
242
172
243
// See if the latest package version has readmeURL set
173
244
if let version = versions. first {
174
- self . getReadMeURL ( package : identity, version: version) { result in
245
+ self . getVersionMetadata ( package : identity, version: version) { result in
246
+ let licenseURL : URL ?
175
247
let readmeURL : URL ?
176
- if case . success( . some( let readmeURLForVersion) ) = result {
177
- readmeURL = readmeURLForVersion
248
+ let repositoryURLs : [ URL ] ?
249
+ let resources : [ Package . Resource ]
250
+ let author : Package . Author ?
251
+ let description : String ?
252
+ if case . success( let metadata) = result {
253
+ licenseURL = metadata. licenseURL
254
+ readmeURL = metadata. readmeURL
255
+ repositoryURLs = metadata. repositoryURLs
256
+ resources = metadata. resources
257
+ author = metadata. author
258
+ description = metadata. description
178
259
} else {
260
+ licenseURL = nil
179
261
readmeURL = self . guessReadMeURL ( alternateLocations: metadata. alternateLocations)
262
+ repositoryURLs = nil
263
+ resources = [ ]
264
+ author = nil
265
+ description = nil
180
266
}
181
-
267
+
182
268
return callback ( . success( [ Package ( identity: identity,
183
269
versions: metadata. versions,
270
+ licenseURL: licenseURL,
184
271
readmeURL: readmeURL,
272
+ repositoryURLs: repositoryURLs,
273
+ resources: resources,
274
+ author: author,
275
+ description: description,
276
+ latestVersion: version,
185
277
source: . registry( url: metadata. registry. url)
186
278
) ] ) )
187
279
}
188
280
} else {
189
281
let readmeURL : URL ? = self . guessReadMeURL ( alternateLocations: metadata. alternateLocations)
190
282
return callback ( . success( [ Package ( identity: identity,
191
283
versions: metadata. versions,
284
+ licenseURL: nil ,
192
285
readmeURL: readmeURL,
286
+ repositoryURLs: nil ,
287
+ resources: [ ] ,
288
+ author: nil ,
289
+ description: nil ,
290
+ latestVersion: nil , // this only makes sense in connection with providing versioned metadata
193
291
source: . registry( url: metadata. registry. url)
194
292
) ] ) )
195
293
}
@@ -240,3 +338,45 @@ public struct PackageSearchClient {
240
338
}
241
339
}
242
340
}
341
+
342
+ fileprivate extension Package . Signing {
343
+ init ( _ signing: RegistryClient . PackageVersionMetadata . Signing ) {
344
+ self . init (
345
+ signatureBase64Encoded: signing. signatureBase64Encoded,
346
+ signatureFormat: signing. signatureFormat
347
+ )
348
+ }
349
+ }
350
+
351
+ fileprivate extension Package . Resource {
352
+ init ( _ resource: RegistryClient . PackageVersionMetadata . Resource ) {
353
+ self . init (
354
+ name: resource. name,
355
+ type: resource. type,
356
+ checksum: resource. checksum,
357
+ signing: resource. signing. map { . init( $0) } )
358
+ }
359
+ }
360
+
361
+ fileprivate extension Package . Author {
362
+ init ( _ author: RegistryClient . PackageVersionMetadata . Author ) {
363
+ self . init (
364
+ name: author. name,
365
+ email: author. email,
366
+ description: author. description,
367
+ organization: author. organization. map { . init( $0) } ,
368
+ url: author. url
369
+ )
370
+ }
371
+ }
372
+
373
+ fileprivate extension Package . Organization {
374
+ init ( _ organization: RegistryClient . PackageVersionMetadata . Organization ) {
375
+ self . init (
376
+ name: organization. name,
377
+ email: organization. email,
378
+ description: organization. description,
379
+ url: organization. url
380
+ )
381
+ }
382
+ }
0 commit comments