Skip to content

WEBDEV-8920: Add fetchMetadataField for modeled single-field lookups - #18

Open
jbuckner wants to merge 4 commits into
mainfrom
WEBDEV-8920-fetch-metadata-field
Open

WEBDEV-8920: Add fetchMetadataField for modeled single-field lookups#18
jbuckner wants to merge 4 commits into
mainfrom
WEBDEV-8920-fetch-metadata-field

Conversation

@jbuckner

@jbuckner jbuckner commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

fetchMetadataValue returns the raw API value, so callers wanting a modeled field build one themselves. The motivating case: collection is a list on an item in several collections but a bare string on an item in one, so reading [0] is wrong half the time.

const result = await metadataService.fetchMetadataField('bra-bfr', 'collection');
result.success?.value;  // 'kodi_archive'
result.success?.values; // ['kodi_archive', 'community']

Takes a field name, not a field class, and derives both the runtime class and the return type from Metadata's own getter. So the field-name-to-field-type mapping isn't duplicated here, and a field added to Metadata works without a change in this package. addeddate comes back as a Date without being told to.

MetadataFieldKey is derived the same way, so only real fields are reachable (identifier and rawMetadata are rejected at compile time). It comes from iaux-item-metadata 1.5.0, where it landed on WEBDEV-8923.

Also rejects a value that isn't a scalar or array of scalars, which would otherwise construct a field whose String() is '[object Object]' inside a successful result.

Heads up for consumers: required member on MetadataServiceInterface, so implementors must add it. Offshoot's MockMetadataService does — that lands with the version bump there.

🤖 Generated with Claude Code

https://claude.ai/code/session_017GxnijHsZmBrHkcuJ5XYf9

fetchMetadataValue hands back the raw API value, so callers that want a modeled
field construct one themselves. Reading an item's primary collection meant
`new StringField(raw).value`, and the reason it needs a field at all is easy to
miss: collection is a list on an item in several collections but a bare string
on an item in one, so reading [0] is wrong half the time.

Takes a field name rather than a field class, and derives both the class and
the return type from Metadata's own getter, so the mapping from field name to
field type isn't duplicated here and a field added to Metadata is available
without a change in this package. MetadataFieldKey is derived the same way, so
only real fields are reachable — identifier and rawMetadata aren't.

    const result = await metadataService.fetchMetadataField('bra-bfr', 'collection');
    result.success?.value;  // 'kodi_archive'

Rejects a value that isn't a scalar or array of scalars, which would otherwise
construct a field whose String() is '[object Object]' inside a successful
result.

Note for consumers: this is a required member of MetadataServiceInterface, so
anything implementing that interface has to add it. Offshoot's
MockMetadataService does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GxnijHsZmBrHkcuJ5XYf9
@codecov-commenter

codecov-commenter commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.46154% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.67%. Comparing base (1c72838) to head (00ac134).

Files with missing lines Patch % Lines
src/metadata-service.ts 78.46% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #18      +/-   ##
==========================================
- Coverage   93.14%   90.67%   -2.48%     
==========================================
  Files           4        4              
  Lines         321      386      +65     
  Branches       28       38      +10     
==========================================
+ Hits          299      350      +51     
- Misses         18       32      +14     
  Partials        4        4              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

jbuckner and others added 3 commits August 19, 2026 17:04
It's derived from Metadata and describes Metadata's shape, so it belongs in
iaux-item-metadata rather than here. Leaving it unexported means moving it there
is an internal refactor instead of a breaking removal. Calling
fetchMetadataField with a field-name literal doesn't need the name.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GxnijHsZmBrHkcuJ5XYf9
* origin/main:
  WEBDEV-8921: Gitignore .claude/worktrees (#17)
The type lives next to Metadata now (WEBDEV-8923), so drop the local
copy and take it from the package.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019VzfA4RksuDWvNvUq5oQgm
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.

2 participants