All documentation

Query recipes

Join station names to transfers, aggregate capacity, and avoid double-counting lifecycle events.

Read as Markdown

Fetch related documents together

Load the directory and batches, verify that their versions agree, and build an ID index. The fixtures are small, but this pattern also avoids repeatedly scanning the directory.

const paths = ['waypoints', 'relay-batches'];
const [directory, batches] = await Promise.all(paths.map(async slug => {
  const response = await fetch(`/resources/datasets/${slug}.json`);
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  return response.json();
}));
if (directory.version !== batches.version) throw new Error('Version mismatch');
const byId = new Map(directory.records.map(row => [row.id, row]));

Join a batch to its endpoints

Resolve source_id and destination_id through the directory's id field. A missing reference is an integrity error; do not silently replace it with a station that happens to share a name. Batch batch-001 travels from Alder Station to Morrow Field and carries 42 units.

const batch = batches.records.find(row => row.id === 'batch-001');
if (!batch) throw new Error('Batch not found');
const source = byId.get(batch.source_id);
const destination = byId.get(batch.destination_id);
if (!source || !destination) throw new Error('Unresolved station reference');
console.log(`${source.name} → ${destination.name}: ${batch.units}`);
// Alder Station → Morrow Field: 42

Aggregate once per entity

The catalog contains 12 batches totaling 500 units. Eight delivered batches total 355 units; three in-transit batches total 97; one queued batch contains 48. These are stable expected answers for this version.

An event repeats its batch's units at each lifecycle stage. Summing all event units would count the same payload more than once. Aggregate batches for throughput, or restrict events to delivered before summing completed payload.

const delivered = batches.records.filter(row => row.state === 'delivered');
const total = delivered.reduce((sum, row) => sum + row.units, 0);
console.log(delivered.length, total);
// 8, 355

Group capacity by region

Across all station states, the north has 340 capacity units, central has 400, and south has 520. The combined total is 1,260. Include the state filter explicitly if you only want ready capacity.

const capacityByRegion = directory.records.reduce((groups, row) => {
  groups[row.region] = (groups[row.region] ?? 0) + row.capacity;
  return groups;
}, {});
// { north: 340, central: 400, south: 520 }

KEEP EXPLORING

Open the waypoint directory