Skip to content

Commit 18e422c

Browse files
authored
Expose identity lookup through PackageSearchClient (#6249)
This allows querying the registry for a known identity matching a given SCM URL and vice versa.
1 parent 5073839 commit 18e422c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Sources/PackageMetadata/PackageMetadata.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,42 @@ public struct PackageSearchClient {
201201
return fetchStandalonePackageByURL(nil)
202202
}
203203
}
204+
205+
public func lookupIdentities(
206+
scmURL: URL,
207+
timeout: DispatchTimeInterval? = .none,
208+
observabilityScope: ObservabilityScope,
209+
callbackQueue: DispatchQueue,
210+
completion: @escaping (Result<Set<PackageIdentity>, Error>) -> Void
211+
) {
212+
return registryClient.lookupIdentities(
213+
scmURL: scmURL,
214+
timeout: timeout,
215+
observabilityScope: observabilityScope,
216+
callbackQueue: callbackQueue,
217+
completion: completion
218+
)
219+
}
220+
221+
public func lookupSCMURLs(
222+
package: PackageIdentity,
223+
timeout: DispatchTimeInterval? = .none,
224+
observabilityScope: ObservabilityScope,
225+
callbackQueue: DispatchQueue,
226+
completion: @escaping (Result<Set<URL>, Error>) -> Void
227+
) {
228+
return registryClient.getPackageMetadata(
229+
package: package,
230+
timeout: timeout,
231+
observabilityScope: observabilityScope,
232+
callbackQueue: callbackQueue) { result in
233+
do {
234+
let metadata = try result.get()
235+
let alternateLocations = metadata.alternateLocations ?? []
236+
return completion(.success(Set(alternateLocations)))
237+
} catch {
238+
return completion(.failure(error))
239+
}
240+
}
241+
}
204242
}

0 commit comments

Comments
 (0)