Skip to content

Adapters API

@diazoma/adapters has feed adapters for the wall. Each one implements FeedAdapter and only fetches and parses. It never renders, and the cursors it returns are opaque strings.

AdapterReadsCursor
JsonFeedAdapter({ url, search?, filters?, fetch? })a feed of the spec: { items, next }the server’s next, verbatim
WellKnownAdapter({ origin })/.well-known/wall.json (or <link rel="wall-manifest">). Builds a JsonFeedAdapter per feed and exposes brand, policy, filters and actionsbase64url(JSON { f: feed id, c: server cursor })
DomAdapter({ root?, mode? })the page itself: [data-wall-item], then JSON-LD, then clusters of similar siblingsbase64url(JSON { u: next url }), or { p: n } for infinite scroll
RssAdapter({ url })RSS 2.0 and Atomnone, unless the feed has <atom:link rel="next">
RecipeAdapter({ recipe })a recipe from @diazoma/recipe-schema: a JSON API (JSONPath, no eval) or the DOM (CSS selectors)base64url(JSON { page }) or { u }
import { WellKnownAdapter } from '@diazoma/adapters';
const adapter = await new WellKnownAdapter({ origin: location.origin }).ready();
new Wall({ mount, adapter, brand: adapter.brand });

WellKnownAdapter.capabilities() is synchronous, so call ready() before you pass the adapter to the wall.

  • DomAdapter mode: auto (the default), annotated, jsonld or heuristic. auto tries them in that order and stops at the first that finds items.
  • JsonFeedAdapter filters take { key, values, param? }. param is the query parameter, and defaults to key.
  • RssAdapter sizes is a function from an absolute image URL to smaller copies. See Image sizes.
  • Every adapter takes fetch (to replace the global one) and onWarning (to hear about dropped items).
  • RecipeAdapter source forces api or dom.

Invalid items are dropped and reported through onWarning. A manifest with "policy": "deny" makes page() reject with an AdapterError whose code is policy-denied.

Every adapter that reads a site description also passes on the site’s view: WellKnownAdapter from manifest.view, RecipeAdapter from recipe.view, and DomAdapter from the first <script type="application/json" data-wall-view> on the page. A panorama that is not an absolute http(s) URL is dropped.

WellKnownAdapter also sets login (from auth.login) and capabilities().links: the actions with mode: "deeplink".

Every adapter looks for smaller images when an item brings only image. See Image sizes.

Adapters use the global DOMParser. In a browser that is built in. In Node, call installDom() from @diazoma/adapters/node first. It installs linkedom’s.

runFixtures(recipe, dir) replays each fixture of a recipe through RecipeAdapter with a fixture-backed fetch, and checks at least one item with id, link, image and aspect. The diazoma-recipe run <recipe.json> command does the same from a shell and exits 1 on a failure. See Recipes.

dist/adapters.iife.js exposes window.DiazomaAdapters for pages without a bundler.