Appearance
Clashfinder Ingestion Worker & API Implementation
This document details the design and implementation of the Clashfinder JSON API contract, the Worker API ingestion endpoint (POST /api/ingest), and the relational data mapping to conform to the client storage contract.
Deliverables
1. API Contract Definition
Created 14-clashfinder-api-contract.md to define the TypeScript data mappings:
- Maps Clashfinder JSON schemas (event, days, stages, acts) to local D1 relational tables (
festivals,stages,bands,sets). - Normalizes date strings (
'YYYY-MM-DD') and time strings ('HH:MM') to Unix epoch millisecond timestamps.
2. Edge Ingestion Endpoint
Implemented the POST /api/ingest route inside index.ts:
- Receives a JSON payload containing the parsed Clashfinder data.
- Relational Seeding:
- Inserts/updates the festival into the
festivalstable and retrieves the unique ID. - Sequentially populates the
stagestable, storing mapped integer IDs. - Populates the
bandstable with unique band name records. - Inserts individual scheduled acts into the
setstable using the mappedfestival_id,stage_id, andband_id, resolving time collisions using SQLON CONFLICTconstraints.
- Inserts/updates the festival into the
3. Edge Data Retrieval Mapping
Updated the GET /api/data route inside index.ts:
Refactored the band querying logic to perform an SQL
JOINbetween thesetsandbandstables:sqlSELECT s.id as id, s.stage_id as stage_id, b.name as name, (s.date || 'T' || s.start_time || ':00') as start_time, (s.date || 'T' || s.end_time || ':00') as end_time FROM sets s JOIN bands b ON s.band_id = b.id;Formats dates and times dynamically on the Edge Worker to return epoch millisecond numbers for
start_timeandend_time, ensuring strict parity with the client PWA's Dexie schema contract.