# SPECS data API — `/data/v1/`

The machine-readable half of <https://specs.theproductionreport.com/>. Every document
is built by `app/build.py` from the **same merged dataset the page embeds**
(`load_data()` → `build_data_api()`), so the API and the page cannot disagree.

Base URL: `https://specs.theproductionreport.com/data/v1/`

This file is the human-readable contract. It is generated into `dist/data/README.md`,
outside `v1/`, so it is not part of the v1 document set and does not change any hash.
Source: `app/data-api.md` in <https://github.com/urbanrhino-lab/specs>.

## Start at the manifest: `index.json`

`write_data_api()` writes one manifest beside the documents:

| Field | Meaning |
|---|---|
| `schema_version` | `DATA_API_SCHEMA_VERSION` (currently `1`) |
| `package_version` | dataset package version |
| `build_version` | the API stamp — see *Versions* below |
| `last_verified` | the dataset's verification date (`platforms.last_verified`) |
| `generated_from` | the source repository |
| `endpoints[]` | one entry per document: `name`, `path`, `immutable_path`, `schema`, `count`, `bytes`, `sha256` |
| `schemas[]` | one entry per published JSON Schema: `name`, `path`, `bytes`, `sha256` — see *JSON Schemas* below |
| `index_schema`, `platform_documents_schema` | the schema paths for `index.json` itself and for every `platforms/<id>.json` |
| `platform_documents[]` | one entry per platform document: `id`, `path`, `immutable_path`, `bytes`, `sha256` — see *Per-platform documents* below |

`count` is the number of rows in the document's main list, or `null` for the two
documents that have no single list (`safe-zones.json`, `freshness.json`).
`sha256` is the hex digest of the document's exact bytes as served.

**To sync:** fetch `index.json`, compare each `sha256` with the one you stored, and
fetch only the documents whose hash moved. Any file in `v1/` that is not listed in the
manifest is deleted at build time, so the manifest is the complete set.

## Documents

Every document carries the same head — `schema_version`, `package_version`,
`build_version`, `last_verified` — plus `count` where it has one main list.

| Path | Contents (`build_data_api()`) |
|---|---|
| `platforms.json` | `platforms[]`: each platform, with its `aspect_ratios` (`supported`, `recommended`, `note`), `safe_zone_profile_id`, `preset_note`, `audio_delivery` and `resolution_delivery` joined on |
| `presets.json` | `presets[]`: compression presets, each with its `ffmpeg_command_template` (or `null`) |
| `qc-rule-sets.json` | `rule_sets[]`: QC rule sets |
| `aspect-profiles.json` | `profiles{}`: per-platform supported / recommended aspect ratios, keyed by platform id |
| `shared-file-groups.json` | `groups[]`: per preset, which platforms are safe, conditional or not safe to share one export file |
| `requirements.json` | `requirements[]`: per-platform codecs, bitrate / file-size / loudness limits and text-placement rules |
| `safe-zones.json` | `house_standard` (`per_aspect`, `categories`, `note`), `platform_ui_zones`, `measurement_profiles`, `platform_assignments` |
| `freshness.json` | `stale_after_days`, `verified{}` per platform, `changelog[]` of spec changes |
| `unknowns.json` | `unknowns[]`: the "ask the vendor" queue — every field in a platform document whose value is a sentinel (see *Undocumented is a value* below): `platform_id`, `document` (`platforms/<id>.json`), `field` (a JSON pointer into it), `value`, and the platform's `sources`; plus the `pattern` used (`unknowns_document()`) |

## Structured delivery fields (URB-4310)

Three machine-readable fields sit beside the prose they restate in `platforms.json`
(and so in each `platforms/<id>.json`). They are additive. The prose fields
(`accepted.frame_rates_fps`, `audio_delivery.channels`, `.loudness`, `.peak`) keep
their keys and values. **An absent key means the source does not say. It does not
mean "none".** Read the prose for anything these fields leave out.

**`accepted.frame_rates[]`**: the platform's exhaustive accepted frame-rate set, using
the MovieLabs MDDF Common Metadata FrameRate convention (an integer base, plus a
`1000/1001` multiplier for the NTSC rates):

```json
[{"fps": 24, "multiplier": "1000/1001", "rational": "24000/1001"}, {"fps": 24}, {"fps": 25}]
```

| Key | Type | Meaning |
|---|---|---|
| `fps` | integer | base rate |
| `multiplier` | `"1000/1001"` | present only for the NTSC rates (23.976, 29.97, 47.95, 59.94) |
| `rational` | string | the exact rate, e.g. `"30000/1001"`; present exactly when `multiplier` is |

- `23.98` and `23.976` are the same rate in the prose. Both become one entry.
- The set is the one the page's engine uses (`acceptedFpsSet()` in `app/engine.js`): array values under `frame_rates_fps`, `constant_frame_rate_fps` or `frame_rate_allowed_fps`, up to two levels inside `accepted`, unioned and sorted.
- A bare number (`frame_rate_max_fps: 30`, a single recommended rate) is a ceiling or a suggestion, not a set, so it produces no field.
- The NTSC table is read from `engine.js` at build time, so there is only one copy of it.

**`audio_delivery.soundfields[]`**: the channel layouts the platform's cited source
names, as MovieLabs OMC Utility soundfield codes. Only these 15 codes are allowed:
`M DM ST LtRt 30 40 50 51 51EX 60 61 70 71 DNS SDS`.
- A source that gives only a channel count ("2 channels") names no layout, so the key is omitted. Two channels could be stereo, Lt/Rt or dual mono.
- The list names layouts. It does not say whether they are alternatives or one package (for example "5.1 plus a stereo mix"); `channels` carries that.

**`audio_delivery.loudness_spec`**: numeric integrated loudness, published only where
the source states a target.

| Key | Type | Meaning |
|---|---|---|
| `target` | number | integrated loudness target |
| `unit` | `"LKFS"` \| `"LUFS"` | as the vendor writes it (the two are the same scale) |
| `tolerance` | number, optional | ± in LU |
| `true_peak_max_dbtp` | number, optional | only when the vendor says *true* peak. A sample-peak or dBFS ceiling stays in the `peak` prose |

Both audio fields come from `app/audio-structured.json`, a hand-curated overlay. Each
row cites a `source_url` that the platform itself lists, plus the vendor's words
(`quote`). A platform with no row has neither key.

## Per-platform documents: `platforms/<id>.json`

One document per platform id, built by `platform_documents()` as that platform's
slice of the documents above. Nothing in it is not also in an aggregate document.

| Field | Contents |
|---|---|
| head | the same `schema_version`, `package_version`, `build_version`, `last_verified` |
| `platform_id` | the platform id |
| `platform` | its record from `platforms.json`, joins included |
| `requirements` | its row from `requirements.json` |
| `safe_zones` | `profile`: its assigned measurement profile from `safe-zones.json` (or `null`); `platform_ui_zones`: its UI keep-clear overlay (or `null`) |
| `verified` | its date from `freshness.json` |
| `changelog` | the `freshness.json` changelog entries naming this platform |

They are listed under `platform_documents` in `index.json`, **not** under `endpoints`,
so a consumer that iterates `endpoints` fetches exactly what it did before. Each has its
own `sha256`, so a sync can fetch only the platforms that moved. Each also has an
`immutable_path` (`sha/<sha256>/platforms/<id>.json`), served like the endpoints'
copies. A platform that leaves the dataset loses its document at the next build.

## JSON Schemas: `schema/<name>.schema.json`

Every document type has a JSON Schema (draft 2020-12) at `v1/schema/`: one per
endpoint (named by the endpoint's `schema` field), `platform-document.schema.json` for
the per-platform documents, and `index.schema.json` for the manifest. They are written
in `app/api-schema/` and published by `write_data_api()`; each has its own `sha256` in
`schemas[]`.

The schemas pin what a consumer may rely on: the head, every list's row shape, the
required fields and their types, and `null` wherever the build can emit one. Because
`/v1` is additive, objects may gain fields, so unknown properties are allowed. A
removed field or a changed type is a `/v2` change, and the build's tests fail on it:
`test_build.py` validates every emitted document against its schema on every build.

## Undocumented is a value, not a gap

Where a vendor publishes nothing, the value is the literal string

    not_publicly_documented_or_vendor_confirmation_required

— not a plausible number and not an omitted field. An absent field and an undocumented
one are different claims; treat this string as "confirm with the vendor". The page
renders it as "not publicly documented — confirm with vendor".

`unknowns.json` collects these into one queue. A value counts when it is a single
snake_case token containing `_confirmation_required` or `not_publicly_documented`.
Prose that only mentions one does not count, and fields named `*_id` are skipped:
`default_qc_rule_set_id: "vendor_confirmation_required"` names a rule set, it does
not say a value is unknown. Entries are sorted by platform, then field.

## Byte stability

`canon_bytes()` serialises every document (and the manifest) as JSON with keys sorted,
separators `,` and `:` (no whitespace), non-ASCII characters kept as UTF-8, and one
trailing newline. Nothing in a document is time-dependent, so a rebuild from unchanged
source reproduces identical bytes and identical `sha256` values. Consumers may rely on
an unchanged hash meaning unchanged content.

## Versions

`build_version` in the API is `api_version()`: `<last_verified>·<7 hex>`, where the hex
is the start of a sha256 over every document's name and `canon_bytes()`, built with the
stamp blank so it cannot feed back into itself. It moves exactly when API content moves.
It is **not** the page's version: a change to the page's layout or code does not touch
the API.

## Compatibility

`/v1/` changes only additively: new documents or new fields. Nothing is renamed or
removed in place. **A breaking change ships at a new `/v2/` path**, and `/v1/` keeps
its shape.

## HTTP

Served from `dist/` by Vercel (`vercel.json`). Under `/data/`:
`Access-Control-Allow-Origin: *`, methods `GET, HEAD, OPTIONS`, and
`Cache-Control: public, max-age=300, s-maxage=3600, stale-while-revalidate=86400`.
The documents under `/data/v1/` are served as `application/json; charset=utf-8`.

### Content-addressed copies (no cache skew)

Every endpoint in `index.json` also carries `immutable_path`, for example
`sha/<sha256>/platforms.json`. That file's bytes are exactly the document whose
`sha256` the manifest lists. It is served `Cache-Control: public, max-age=31536000,
immutable`, and `index.json` itself is served `no-cache`.

**To sync without skew:** fetch `index.json`, then fetch each changed endpoint's
`immutable_path` instead of its plain `path`. A CDN may cache the plain path for up to
an hour, so it can briefly return a different build than the manifest you just read.
The content-addressed copy cannot.

Only the current build's copies are published. If you fetch an `immutable_path` from
an older manifest, you get a 404 rather than the wrong bytes: re-read `index.json` and
retry.
