@@ -108,10 +108,36 @@ final case class Resolver[F[_]](repos: List[Registry], cache: Option[ResolverCac
108108 * Get list of available schemas for particular vendor and name part
109109 * Server supposed to return them in proper order
110110 */
111+ def listSchemasResult (vendor : Vendor , name : Name , model : Model )(implicit
112+ F : Monad [F ],
113+ L : RegistryLookup [F ],
114+ C : Clock [F ]
115+ ): F [Either [ResolutionError , SchemaListLookupResult ]] =
116+ listSchemasResult(vendor, name, model, None )
117+
118+ /**
119+ * Vendor, name, model are extracted from supplied schema key to call on the `listSchemas`. The important difference
120+ * from `listSchemas` is that it would invalidate cache, if returned list did not contain SchemaKey supplied in
121+ * argument. Making it a safer option is latest schema bound is known.
122+ */
123+ def listSchemasLikeResult (schemaKey : SchemaKey )(implicit
124+ F : Monad [F ],
125+ L : RegistryLookup [F ],
126+ C : Clock [F ]
127+ ): F [Either [ResolutionError , SchemaListLookupResult ]] =
128+ listSchemasResult(schemaKey.vendor, schemaKey.name, schemaKey.version.model, Some (schemaKey))
129+
130+ /**
131+ * Get list of available schemas for particular vendor and name part
132+ * Has an extra argument `mustIncludeKey` which is used to invalidate cache if SchemaKey supplied in it is not in the
133+ * list.
134+ * Server supposed to return them in proper order
135+ */
111136 def listSchemasResult (
112137 vendor : Vendor ,
113138 name : Name ,
114- model : Model
139+ model : Model ,
140+ mustIncludeKey : Option [SchemaKey ] = None
115141 )(implicit
116142 F : Monad [F ],
117143 L : RegistryLookup [F ],
@@ -140,7 +166,11 @@ final case class Resolver[F[_]](repos: List[Registry], cache: Option[ResolverCac
140166
141167 getSchemaListFromCache(vendor, name, model).flatMap {
142168 case Some (TimestampedItem (Right (schemaList), timestamp)) =>
143- Monad [F ].pure(Right (ResolverResult .Cached ((vendor, name, model), schemaList, timestamp)))
169+ if (mustIncludeKey.forall(schemaList.schemas.contains))
170+ Monad [F ].pure(Right (ResolverResult .Cached ((vendor, name, model), schemaList, timestamp)))
171+ else
172+ traverseRepos[F , SchemaList ](get, prioritize(vendor, allRepos.toList), Map .empty)
173+ .flatMap(handleAfterFetch)
144174 case Some (TimestampedItem (Left (failures), _)) =>
145175 retryCached[F , SchemaList ](get, vendor)(failures)
146176 .flatMap(handleAfterFetch)
@@ -165,6 +195,19 @@ final case class Resolver[F[_]](repos: List[Registry], cache: Option[ResolverCac
165195 ): F [Either [ResolutionError , SchemaList ]] =
166196 listSchemasResult(vendor, name, model).map(_.map(_.value))
167197
198+ /**
199+ * Vendor, name, model are extracted from supplied schema key to call on the `listSchemas`. The important difference
200+ * from `listSchemas` is that it would invalidate cache, if returned list did not contain SchemaKey supplied in
201+ * argument. Making it a safer option is latest schema bound is known.
202+ */
203+ def listSchemasLike (schemaKey : SchemaKey )(implicit
204+ F : Monad [F ],
205+ L : RegistryLookup [F ],
206+ C : Clock [F ]
207+ ): F [Either [ResolutionError , SchemaList ]] =
208+ listSchemasResult(schemaKey.vendor, schemaKey.name, schemaKey.version.model, Some (schemaKey))
209+ .map(_.map(_.value))
210+
168211 /** Get list of full self-describing schemas available on Iglu Server for particular vendor/name pair */
169212 def fetchSchemas (
170213 vendor : Vendor ,
@@ -365,6 +408,7 @@ object Resolver {
365408
366409 result.value
367410 }
411+
368412 def parseConfig (
369413 config : Json
370414 ): Either [DecodingFailure , ResolverConfig ] = {
0 commit comments