mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
Let an application ask the library catalog with its own fetch (#1810)
createApplicationTools({ library: { fetchImpl } }) hands the fetch to the library source, so a server that wants the application's credentials on its library routes answers the catalog instead of refusing it.
This commit is contained in:
1 parent
6b05cd58b9
commit
4f1a4a3f2a
4 files changed
+39
No files matched your search
@@ -54,6 +54,8 @@ function safeLocalStorage() {
|
||||
* (`createLibrarySource`).
|
||||
* @param {boolean} [options.requireCatalog] Offer only what the server's
|
||||
* catalog names, nothing while it does not answer; it is asked again later.
|
||||
* @param {typeof fetch} [options.fetchImpl] Asks the library server (its
|
||||
* catalog) in place of the page's fetch (`createLibrarySource`).
|
||||
*/
|
||||
export function createDataLibrary({
|
||||
entries = LIBRARY_ENTRIES,
|
||||
@@ -70,9 +72,11 @@ export function createDataLibrary({
|
||||
fetchTile = null,
|
||||
fetchData = null,
|
||||
requireCatalog = false,
|
||||
fetchImpl = undefined,
|
||||
source = createLibrarySource({
|
||||
entries,
|
||||
storage,
|
||||
fetchImpl,
|
||||
fetchTile,
|
||||
fetchData,
|
||||
requireCatalog,
|
||||
|
||||
@@ -862,3 +862,31 @@ test('a required catalog that does not answer offers nothing and is asked again
|
||||
assert.ok(calls.every((url) => url === '/api/library/catalog'));
|
||||
library.destroy();
|
||||
});
|
||||
|
||||
test("the library asks its catalog with the application's own fetch", async (t) => {
|
||||
const manager = sealedManager(t);
|
||||
const calls = [];
|
||||
const library = createDataLibrary({
|
||||
entries,
|
||||
ledger,
|
||||
dataManager: manager,
|
||||
services: {},
|
||||
storage: memoryStorage(null),
|
||||
initialHash: '',
|
||||
requireCatalog: true,
|
||||
fetchImpl: async (url) => {
|
||||
calls.push(String(url));
|
||||
return Response.json({
|
||||
entries: [{ id: 'night-lights', available: true, reason: null }],
|
||||
});
|
||||
},
|
||||
setTimer: () => {},
|
||||
clearTimer: () => {},
|
||||
});
|
||||
await library.start();
|
||||
assert.deepEqual(calls, ['/api/library/catalog']);
|
||||
assert.deepEqual(
|
||||
library.list().map(({ entry }) => entry.id),
|
||||
['night-lights'],
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user