Back to Atlas map viewer
SOURCE / PINNED RELEASE

Made of little things.

Atlas map viewer

Release
1d2807e80b44…
Author-recorded commit
43810ed2b368…
License
LICENSE
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-4757dbabc86

Archive hash verified: 8db6876d96c460ac…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

packages/format/src/catalog.ts
import { validateTransportMetadata } from "./routing-contract";
import { validateRasters } from "./raster";
import { parseTree, type TreeOffer } from "../../hashtree/src/offer";
import { MAP_LAYERS, type Manifest } from "./index";
export interface MapOffer {
  id: string;
  url: string;
  api?: string;
  bytes: number;
  manifest: Manifest;
  hashtree?: TreeOffer;
}
import { httpUrl, mapReference } from "./urls";
export { httpUrl, mapReference } from "./urls";
/** Offers are discovery hints. The reader validates the actual package, and its
 * snapshot must agree before a catalog offer can participate in a composition. */
export function parseCatalog(value: unknown, base: string): MapOffer[] {
  const maps = (value as { maps?: unknown })?.maps;
  if (!Array.isArray(maps) || maps.length > 1000)
    throw new Error("Invalid Atlas catalog");
  const seen = new Set<string>();
  return maps.map((m) => {
    const f = m?.manifest;
    if (
      !m ||
      typeof m.id !== "string" ||
      typeof m.url !== "string" ||
      (m.api !== undefined && typeof m.api !== "string") ||
      !Number.isSafeInteger(m.bytes) ||
      m.bytes <= 0 ||
      !f ||
      typeof f.name !== "string" ||
      !/^[a-f0-9]{64}$/.test(f.snapshot) ||
      !Array.isArray(f.bounds) ||
      f.bounds.length !== 4 ||
      !f.bounds.every(Number.isFinite) ||
      f.bounds[0] >= f.bounds[2] ||
      f.bounds[1] >= f.bounds[3] ||
      f.bounds[0] < -180 ||
      f.bounds[2] > 180 ||
      f.bounds[1] < -90 ||
      f.bounds[3] > 90 ||
      !Number.isInteger(f.minZoom) ||
      !Number.isInteger(f.maxZoom) ||
      f.minZoom < 0 ||
      f.maxZoom > 18 ||
      f.minZoom > f.maxZoom ||
      !Array.isArray(f.capabilities) ||
      !f.capabilities.every((s: unknown) => typeof s === "string") ||
      (f.tileLayers !== undefined &&
        (!Array.isArray(f.tileLayers) ||
          !f.tileLayers.every((s: unknown) => MAP_LAYERS.includes(s as never))))
    )
      throw new Error("Invalid map offer in catalog");
    validateRasters(f.rasters);
    validateTransportMetadata(f.transport, f.capabilities);
    const hashtree = m.hashtree ? parseTree(m.hashtree, m.bytes) : undefined;
    const url = mapReference(m.url, base, hashtree?.root);
    if (url.startsWith("htree:") && !hashtree)
      throw new Error(
        "Content-addressed map offers require a Hashtree descriptor",
      );
    if (seen.has(url)) throw new Error("Duplicate map URL in catalog");
    seen.add(url);
    return {
      id: m.id,
      url,
      ...(m.api !== undefined ? { api: httpUrl(m.api, base) } : {}),
      bytes: m.bytes,
      manifest: f,
      ...(hashtree ? { hashtree } : {}),
    };
  });
}