@@ -46,6 +46,7 @@ use tokio::io::AsyncSeekExt;
4646use tokio:: sync:: RwLock ;
4747use tokio_util:: io:: SyncIoBridge ;
4848use wasm_pkg_common:: config:: RegistryConfig ;
49+ use wasm_pkg_common:: metadata:: { LOCAL_PROTOCOL , OCI_PROTOCOL , WARG_PROTOCOL } ;
4950pub use wasm_pkg_common:: {
5051 config:: { Config , CustomConfig , RegistryMapping } ,
5152 digest:: ContentDigest ,
@@ -219,76 +220,6 @@ impl Client {
219220 . ok_or_else ( || Error :: NoRegistryForNamespace ( package. namespace ( ) . clone ( ) ) )
220221 }
221222
222- fn resolve_backend (
223- & self ,
224- registry : & Registry ,
225- registry_meta : RegistryMetadata ,
226- ) -> Result < InnerClient , Error > {
227- let registry_config = self
228- . config
229- . registry_config ( & registry)
230- . cloned ( )
231- . unwrap_or_default ( ) ;
232-
233- let backend_type = match registry_config. default_backend ( ) {
234- // If the local config specifies a backend type, use it
235- Some ( backend_type) => Some ( backend_type) ,
236- None => {
237- // If the registry metadata indicates a preferred protocol, use it
238- let preferred_protocol = registry_meta. preferred_protocol ( ) ;
239- // ...except registry metadata cannot force a local backend
240- if preferred_protocol == Some ( "local" ) {
241- return Err ( Error :: InvalidRegistryMetadata ( anyhow ! (
242- "registry metadata with 'local' protocol not allowed"
243- ) ) ) ;
244- }
245- preferred_protocol
246- }
247- }
248- // Otherwise use the default backend
249- . unwrap_or ( "oci" ) ;
250-
251- todo ! ( ) ;
252- }
253-
254- fn resolve_metadata (
255- & self ,
256- package : & PackageRef ,
257- registry_config : & RegistryConfig ,
258- registry_override : bool ,
259- registry : & Registry ,
260- ) -> & RegistryMetadata {
261- if let Some ( metadata) = self
262- . config
263- . package_registry_override ( package)
264- . and_then ( |mapping| mapping. metadata ( ) )
265- {
266- return metadata;
267- }
268-
269- let _ = self
270- . config
271- . namespace_registry ( package. namespace ( ) )
272- . and_then ( |mapping| {
273- // If the overridden registry matches the registry we are trying to resolve, we
274- // should use the metadata, otherwise we'll need to fetch the metadata from the
275- // registry
276- match ( mapping, registry_override) {
277- ( RegistryMapping :: Custom ( custom) , true ) if custom. registry == * registry => {
278- Some ( custom. metadata . clone ( ) )
279- }
280- ( RegistryMapping :: Custom ( custom) , false ) => Some ( custom. metadata . clone ( ) ) ,
281- _ => None ,
282- }
283- } ) ;
284- todo ! ( ) ;
285- }
286-
287- async fn has_registry ( & self , registry : & Registry ) -> bool {
288- let sources = self . sources . read ( ) . await ;
289- sources. contains_key ( registry)
290- }
291-
292223 async fn resolve_source (
293224 & self ,
294225 package : & PackageRef ,
@@ -308,7 +239,7 @@ impl Client {
308239 . unwrap_or_default ( ) ;
309240
310241 // Skip fetching metadata for "local" source
311- let should_fetch_meta = registry_config. default_backend ( ) != Some ( "local" ) ;
242+ let should_fetch_meta = registry_config. default_backend ( ) != LOCAL_PROTOCOL . into ( ) ;
312243 let maybe_metadata = self
313244 . config
314245 . package_registry_override ( package)
@@ -353,7 +284,7 @@ impl Client {
353284 // If the registry metadata indicates a preferred protocol, use it
354285 let preferred_protocol = registry_meta. preferred_protocol ( ) ;
355286 // ...except registry metadata cannot force a local backend
356- if preferred_protocol == Some ( "local" ) {
287+ if preferred_protocol == Some ( LOCAL_PROTOCOL ) {
357288 return Err ( Error :: InvalidRegistryMetadata ( anyhow ! (
358289 "registry metadata with 'local' protocol not allowed"
359290 ) ) ) ;
@@ -362,17 +293,17 @@ impl Client {
362293 }
363294 }
364295 // Otherwise use the default backend
365- . unwrap_or ( "oci" ) ;
296+ . unwrap_or ( OCI_PROTOCOL ) ;
366297 tracing:: debug!( ?backend_type, "Resolved backend type" ) ;
367298
368299 let source: InnerClient = match backend_type {
369- "local" => Box :: new ( LocalBackend :: new ( registry_config) ?) ,
370- "oci" => Box :: new ( OciBackend :: new (
300+ LOCAL_PROTOCOL => Box :: new ( LocalBackend :: new ( registry_config) ?) ,
301+ OCI_PROTOCOL => Box :: new ( OciBackend :: new (
371302 & registry,
372303 & registry_config,
373304 & registry_meta,
374305 ) ?) ,
375- "warg" => {
306+ WARG_PROTOCOL => {
376307 Box :: new ( WargBackend :: new ( & registry, & registry_config, & registry_meta) . await ?)
377308 }
378309 other => {
0 commit comments