Skip to content

feat(archive-reader): expose the scheme a value announces by its syntax - #331

Merged
mbret merged 2 commits into
masterfrom
claude/export-inferred-identifier-scheme
Aug 27, 2026
Merged

feat(archive-reader): expose the scheme a value announces by its syntax#331
mbret merged 2 commits into
masterfrom
claude/export-inferred-identifier-scheme

Conversation

@mbret

@mbret mbret commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Why

Resolution gives an identifier that announces no scheme one from its own syntax — an absolute http(s) link is a URL, a Bookland number an ISBN, another well-formed barcode a GTIN, anything else Unknown. That belief was private to metadata/opf/resolve.ts.

A consumer holding the package document itself needs the same reading, for the same reason it needs the scheme attributes and the ONIX crosswalk from #329 and #330. Concretely, in oboku's OPF writer:

<dc:identifier id="isbn-id">9783161484100</dc:identifier>
<meta refines="#isbn-id" property="display-seq">1</meta>

identifiers reports that as { value: "9783161484100", scheme: "ISBN" }. The writer, reading the element as untagged, does not match it against the patch's ISBN entry — so it builds a replacement and deletes the original, losing its id and the refinement pointing at it. Verified against that exact document.

What changed

inferredIdentifierScheme moves from resolve.ts to utils/inferIdentifierScheme.ts as inferIdentifierScheme, and is exported. resolve.ts imports it; its behaviour is unchanged.

Read-side vocabulary, like the others — nothing about writing is exported.

Testing

  • 5 new unit cases: links with and without a host, other URI schemes, Bookland numbers however written (hyphenated, urn:isbn:-prefixed), non-Bookland barcodes as GTIN, and everything else as Unknown
  • 353 tests pass, up from 348, none modified — the existing resolver suites already cover the inference through identifiers
  • tsc and biome clean

Docs

gitbook/archive-reader/identifiers.md gains it next to the two vocabularies from #330, with the reason a container editor needs it.

🤖 Generated with Claude Code

Resolution gives an untyped identifier a scheme from its own syntax — an
absolute link is a `URL`, a Bookland number an `ISBN`, another barcode a
`GTIN`. That belief was private to the OPF resolver.

A consumer holding the container itself has to share it: an untyped
`<dc:identifier>` holding a Bookland number is an `ISBN` in `identifiers`,
so a writer reading it as untagged builds a second element beside the one
the reader reported rather than editing it.

Moved to `utils/inferIdentifierScheme.ts` and exported, alongside the
scheme vocabulary the same consumers already read from here.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
prose-reader-demo Ready Ready Preview Aug 27, 2026 11:30am
prose-reader-front Ready Ready Preview Aug 27, 2026 11:30am

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c0c82c6986

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/archive-reader/src/utils/inferIdentifierScheme.ts Outdated
…ring

Inference only ever answers with four of the known schemes, but the public
declaration said `string` — so a caller could not assign the result to a
scheme field and got no exhaustive narrowing from it.

`InferredIdentifierScheme` names those four, drawn out of
`KnownMetadataIdentifierScheme` with `Extract` rather than restated, so
renaming one there fails to compile here.

Caught by Codex on the first version of this export.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@mbret
mbret merged commit 7a04e55 into master Aug 27, 2026
11 checks passed
@mbret
mbret deleted the claude/export-inferred-identifier-scheme branch August 27, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant