Repository navigation
Phase 2: metadata.json sibling endpoint for indexing - #504
Merged
neuromechanist merged 2 commits intoMay 15, 2026
Merged
neuromechanist merged 2 commits into
neuromechanist merged 2 commits into
Conversation
Adds GET /<datasetId>/metadata.json on the data.nemar.org sub-app, returning a neuroschema v0.3.0 dataset document that combines: - The D1 catalog row (name, modalities, subject/task aggregates, sizes). - The parsed nemar_metadata.json enrichment payload (authors flattened from Record<name, AuthorEnrichmentV2> to Person[], MeSH keywords, related identifiers, contributors, dates, funding, license). - The full dataset_versions list under extensions.nemar.versions with cross-link manifest_url to the per-version Phase 1 manifest.json. - A derived BIDS subjects/sessions/modalities/tasks/runs tree from the latest version's S3 manifest under extensions.nemar.bids_index, so external viewers (eegdash-viewer, etc.) can resolve dataset shape in one fetch. Same public-only gate and 404-with-no-existence-leak as Phase 1. Partial inputs never 500: missing enrichment, missing versions, or a failed manifest fetch each degrade to null/empty fields rather than aborting. backend/src/services/data-router.ts: adds pure builders (buildDatasetMetadata, buildBidsIndex, buildPersonList, deriveSessions, formatBytes) plus exported types (NeuroschemaDataset, BidsIndex, NemarExtensionBlock, etc.). All synchronous and unit-testable. backend/src/routes/data.ts: metadataJsonHandler wires D1 + manifest I/O, registered before /:datasetId/:version so Hono cannot capture "metadata.json" as a version param. test/data-route.unit.test.ts: 18 new unit tests for the builders covering empty manifests, multi-session/multi-modality/multi-run accumulation, non-BIDS path skipping, sidecar inclusion, v1 and v2 author shapes, formatBytes edge cases, and the full assembler under no-enrichment / no-versions / no-manifest combinations. test/data-route.test.ts: extends the E2E suite (skips when nm099999 is not currently published) with a positive shape assertion and an unknown- dataset 404 check. docs/reference/data-api.md: documents the contract with the canonical example payload. Closes #496.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR504Version: 🤖 Updated on each push. |
- buildBidsIndex: register subjects whose only files lack a `_task-` token (anat, dwi, fmap are valid BIDS and the subject must still appear in the index). Modalities entry exists with empty tasks map; subject-level sidecars register the subject without a modality entry. Replaces the previous "missing task token rejects the row" semantics, which silently undercounted neuroimaging subjects. - formatBytes: switch from a two-tier (>=100 ? 0 : 2) to a three-tier precision rule (>=100 -> 0 decimals, >=10 -> 1 decimal, <10 -> 2 decimals). The previous rule produced "10.10 GB" and "99.50 GB" which disagreed with the documented "450 MB" / "150 GB" examples. New rule matches the docstring; the docstring is also expanded to spell out the tiers explicitly so a future maintainer cannot drift it. - metadataJsonHandler: log the race-case (row disappears between the visibility gate and the second SELECT) at warn level so operators can correlate it with deletion events or D1 replica lag. The previous code returned 404 silently for this anomaly. - metadataJsonHandler: corrupt enrichment_json now logs at console.error rather than console.warn. Persistent data corruption is not a transient warning; routing it to error makes it visible to any future exception-aggregation pipeline (Sentry is tracked in #478). - New unit tests: task-less subject registration (anat + dwi), subject-level sidecar (sub-01/sub-01_scans.tsv) registers the subject, mixed session/flat layouts under one subject, mid-tier formatBytes precision, v1 enrichment has no license -> rights empty, D1-description-null falls back to v2 enrichment description. - Drop stale "phase 1"/"phase 2" qualifiers from the file/section headers. The data.nemar.org route is now multi-phase; the per-phase label dates the comment without adding information. 52 unit tests pass (up from 48 in the PR's first commit).
Contributor
Author
/review-pr summaryRan the five applicable agents in parallel against this PR. No critical findings. Acted on the high-confidence important findings; deferred the broader ones with rationale. Acted on (commit 2407f3c)
Deferred with rationale
Final state
|
neuromechanist
merged commit May 15, 2026
bd8e59f
into
feature/issue-449-epic-data-https
1 check passed
This was referenced May 15, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2 of epic #449. Adds
GET https://data.nemar.org/<datasetId>/metadata.json, a public anonymous endpoint that returns a neuroschema v0.3.0datasetdocument combining:nemar_metadata.jsonenrichment payload (authors flattened fromRecord<name, AuthorEnrichmentV2>toPerson[], MeSH keywords, related identifiers, contributors, dates, funding, license, pipeline stage).dataset_versionslist underextensions.nemar.versionswith a cross-linkmanifest_urlto the per-version Phase 1manifest.json.subjects -> sessions -> modalities -> tasks -> runstree from the latest version's S3 manifest underextensions.nemar.bids_index.This is the contract @bruAristimunha asked for in #449: external indexers / viewers (eegdash-viewer etc.) can resolve
dataset -> subjects/tasks/runs -> filesin one fetch. The wire format intentionally uses neuroschema (~/Documents/git/nemar/neuroschema/schema/core/dataset.schema.json, exampledataset-nm000108.json) so it slots into the existing FAIR ecosystem and the schema is reusable by other consumers.Same public-only gate as Phase 1 -- private/unknown collapse to 404 with no existence leak. Partial inputs never 500: missing enrichment, no versions yet, or a failed manifest fetch each degrade to
null/empty fields rather than aborting.Closes #496.
Test plan
buildBidsIndex,buildPersonList,deriveSessions,formatBytes,buildDatasetMetadata).tsc --noEmitclean.datacite.test.ts,dataset-metadata-columns.test.ts) still pass (148 tests, 0 fail).test/data-route.test.ts) against a deployed dev backend after merge -- 2 new positive/404 tests added; skip gracefully when nm099999 is unpublished.