mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
Serve the Data Library from any server, and let a server shape it (#1807)
A server can answer the library with createLibraryHandler, a fetch handler, and shape what it offers: hide entries (listed: false) or route browser-direct ones through itself (fetch: proxied). View-bounded entries ask for a grid-snapped box, and GeoParquet is read on the server within it. Applications can pass their own tile and data fetchers (createApplicationTools({library: {fetchTile, fetchData}})), and with library.requireCatalog a catalog that does not answer offers nothing and is asked again later. Tile paths have one spelling: integer z/x/y without leading zeros, within the grid and the entry's zooms. A server's index and partition reads are bounded and counted against its subrequest limit.
This commit is contained in:
1 parent
7b4c84a717
commit
9554d6ea71
15 files changed
+1510
-395
No files matched your search
@@ -0,0 +1,110 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createLibrarySource } from './source.js';
|
||||
import { libraryEntry } from './catalog.js';
|
||||
import { libraryViewBox } from './manifest.js';
|
||||
import { libraryImagerySpec } from './layers.js';
|
||||
|
||||
const tiles = libraryEntry('usgs-topo');
|
||||
const view = libraryEntry('fema-usa-structures');
|
||||
const entries = [tiles, view];
|
||||
|
||||
function serverSaying(rows, calls = []) {
|
||||
return async (url, options) => {
|
||||
calls.push({ url: String(url), options });
|
||||
if (String(url).endsWith('/catalog'))
|
||||
return Response.json({ entries: rows });
|
||||
return Response.json({ features: [], truncated: false });
|
||||
};
|
||||
}
|
||||
|
||||
test('the server can hide an entry and route a browser-direct one through itself', async () => {
|
||||
const source = createLibrarySource({
|
||||
entries,
|
||||
storage: null,
|
||||
fetchImpl: serverSaying([
|
||||
{ id: tiles.id, available: true, reason: null, fetch: 'proxied' },
|
||||
{
|
||||
id: view.id,
|
||||
available: false,
|
||||
reason: 'operator-disabled',
|
||||
listed: false,
|
||||
},
|
||||
]),
|
||||
});
|
||||
assert.equal(source.tileTemplate(tiles), tiles.source.url);
|
||||
const { availability } = await source.getAvailability();
|
||||
assert.deepEqual(availability.get(view.id), {
|
||||
available: false,
|
||||
reason: 'operator-disabled',
|
||||
listed: false,
|
||||
});
|
||||
assert.equal(availability.get(tiles.id).available, true);
|
||||
assert.equal(
|
||||
source.tileTemplate(tiles),
|
||||
`/api/library/tile/${tiles.id}/{z}/{x}/{y}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('a routed view-bounded dataset asks the server for its snapped box, through the host fetch', async () => {
|
||||
const calls = [];
|
||||
const asked = [];
|
||||
const source = createLibrarySource({
|
||||
entries,
|
||||
storage: null,
|
||||
fetchImpl: serverSaying(
|
||||
[{ id: view.id, available: true, reason: null, fetch: 'proxied' }],
|
||||
calls,
|
||||
),
|
||||
fetchData: async ({ entry, url }) => {
|
||||
asked.push({ entry: entry.id, url });
|
||||
return Response.json({ features: [], truncated: true });
|
||||
},
|
||||
});
|
||||
await source.getAvailability();
|
||||
const bbox = [-77.031, 38.889, -77.02, 38.9];
|
||||
const result = await source.loadDataset(view, { bbox });
|
||||
assert.equal(result.truncated, true);
|
||||
assert.deepEqual(asked, [
|
||||
{
|
||||
entry: view.id,
|
||||
url: `/api/library/data/${view.id}?bbox=${libraryViewBox(bbox).join(',')}`,
|
||||
},
|
||||
]);
|
||||
// No box, nothing asked.
|
||||
assert.deepEqual(await source.loadDataset(view), {
|
||||
features: [],
|
||||
truncated: false,
|
||||
});
|
||||
assert.equal(asked.length, 1);
|
||||
assert.equal(calls.length, 1);
|
||||
});
|
||||
|
||||
test("a host's tile fetch reaches the imagery spec, told the entry", async () => {
|
||||
const seen = [];
|
||||
const source = createLibrarySource({
|
||||
entries,
|
||||
storage: null,
|
||||
fetchTile: async ({ entry, url }) => {
|
||||
seen.push([entry.id, url]);
|
||||
return { missing: true };
|
||||
},
|
||||
});
|
||||
const spec = libraryImagerySpec(
|
||||
tiles,
|
||||
source.tileTemplate(tiles),
|
||||
source.tileFetch(tiles),
|
||||
);
|
||||
assert.deepEqual(await spec.fetchTile({ tile: {}, url: 'u' }), {
|
||||
missing: true,
|
||||
});
|
||||
assert.deepEqual(seen, [[tiles.id, 'u']]);
|
||||
assert.equal(
|
||||
'fetchTile' in libraryImagerySpec(tiles, tiles.source.url),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
createLibrarySource({ entries, storage: null }).tileFetch(tiles),
|
||||
null,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user