feat: return the whole cache from GET /layer/{layerName}/{cacheType} MAPCO-11508 - #174
Closed
razbroc wants to merge 2 commits into
Closed
feat: return the whole cache from GET /layer/{layerName}/{cacheType} MAPCO-11508#174razbroc wants to merge 2 commits into
razbroc wants to merge 2 commits into
Conversation
IMapProxyJsonDocument.caches was typed as a single IMapProxyCache rather than a map of them, so every caches[name] lookup resolved to any through the index signature, and the casts around those lookups were unchecked.
The endpoint returned only the cache source, the inner 'cache' section of a mapproxy cache. It now returns the whole cache as it is written in the configuration, alongside its name. The cache source stays at the same 'cache' key, so existing consumers read it unchanged and the new fields are additive. The cache is spread verbatim, so mapproxy options we do not model are returned too. Also: - ICacheObject and the unused ICacheName become IGetCacheResponse, which the request handler now actually declares as its response type. - a caches entry that is not an object, or holds no cache source, raises the existing NotFoundError instead of a 500 or a corrupt response. - adds the missing gpkgCache response schema, since geopackage is an accepted cacheType, with mapproxy's own option set and defaults.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Further information:
GET /layer/{layerName}/{cacheType}returned only the cache source — the innercachesection of a mapproxy cache. It now returns the whole cache as written in the configuration, alongside its name."Cache" means two things in a mapproxy config: the entry under
caches:(sources, grids, format, upscale_tiles, …) and its innercache:key that names the storage backend. This endpoint only ever exposed the second one.{ "cacheName": "example-layer", "cache": { "type": "s3", "directory": "…", "directory_layout": "tms" }, "sources": [], "grids": ["epsg4326dir"], "format": "image/png", "upscale_tiles": 18 }Not a breaking change
The cache source stays at the same
cachekey, so existing consumers readresponse.cache.*unchanged — the new fields are purely additive siblings. The only thing that would break is a consumer rejecting unknown response properties; none is known to.The cache is spread verbatim, so mapproxy options we do not model (
meta_size,cache_dir, …) are returned too. The response contract is deliberately "whatever the configuration holds" rather than our model of it —additionalPropertiesis left open and onlycacheName+cacheare required.cacheTypekeeps its existing dual role unchanged: it selects the cache (-redissuffix) and validates it (400 when the resolved cache is of a different type).Also in this PR
cacheswas mistyped (separate commit).IMapProxyJsonDocument.cacheswas declared as a singleIMapProxyCacheinstead of a map of them, so everycaches[name]lookup resolved toanythrough the index signature and the casts around them were unchecked. NowRecord<string, IMapProxyCache>, which typed four test lookups that had been silentlyany.ICacheObject/ICacheName→IGetCacheResponse. The request handler declaredICacheNameas its response type while the manager returnedICacheObject— the response type was wrong.ICacheNamehad no other users.cachesentry that is not an object, or an object with no cache source, reached.cache.typeand produced a 500 — and under verbatim spread would have produced corrupt output. It now raises the existingNotFoundError.gpkgCacheresponse schema.geopackageis an acceptedcacheType, butgetCacheResponse.cachehad no geopackage variant and no discriminator mapping for it, so a real geopackage cache would have failed schema validation. Added with mapproxy's own option set and defaults (filename,table_name,levels,directory— all optional,typealone required).NotFoundErrorwhere the code throwsBadRequestError; it passed only because Jest'stoThrow(errorInstance)compares the message, not the class.Verification
tscclean · 47 unit + 19 integration tests passing ·eslint0 problems ·redocly lintvalid. The typing-fix commit was checked to build, lint, and pass tests standalone before the feature commit went on top.