feat: symmetric literal mappings — LiteralFrom.bigint and LiteralFrom.symbol - #90
Draft
jeswr wants to merge 1 commit into
Draft
feat: symmetric literal mappings — LiteralFrom.bigint and LiteralFrom.symbol#90jeswr wants to merge 1 commit into
jeswr wants to merge 1 commit into
Conversation
LiteralAs.bigint and LiteralAs.symbol exist with no write-side counterparts, so bigint- and symbol-valued model properties can be read but not assigned. Add the symmetric term mappings: - LiteralFrom.bigint maps a bigint to an xsd:integer literal, so integers beyond Number.MAX_SAFE_INTEGER round-trip losslessly. - LiteralFrom.symbol maps a symbol registered in the global symbol registry (Symbol.for) to a string literal via Symbol.keyFor, mirroring how LiteralAs.symbol reads literals with Symbol.for. Unregistered symbols carry no key that could round-trip, so they are rejected with a TypeError (consistent with the input validation in ensure.ts). Round-trip coverage via Parent model properties plus direct lexical and datatype assertions in literalFrom.test.ts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Part of #7 — the smallest concrete gap there:
LiteralAs.bigintandLiteralAs.symbolexist with no write-side counterparts, so bigint- and symbol-valued model properties can be read but not assigned.What this does
Adds the two symmetric term mappings to
LiteralFrom:LiteralFrom.bigint(value, factory)— maps abigintto anxsd:integerliteral. Together withLiteralAs.bigint, integers beyondNumber.MAX_SAFE_INTEGERnow round-trip through RDF without loss of precision.LiteralFrom.symbol(value, factory)— maps a symbol registered in the global symbol registry (Symbol.for) to a plain string literal viaSymbol.keyFor, mirroring howLiteralAs.symbolreads literals back withSymbol.for. Unregistered symbols (plainSymbol()) carry no key that could round-trip, so they are rejected with aTypeError— the same built-in errorensure.tsuses for input validation (TermErrorwas considered, but its constructor requires an associated RDF/JSTerm, which does not exist on the write side).Both carry the dense JSDoc treatment (
@remarks, paired turtle/ts@example,@throws,@see);npx typedocpasses with no new warnings and the cross-links toLiteralAs.bigint/LiteralAs.symbolresolve.Tests
literalFrom.test.ts.Parentmodel properties (hasBigint,hasSymbol) using the existingRequiredAs/RequiredFrompattern, including abigintaboveNumber.MAX_SAFE_INTEGER.TypeErrorpath for unregistered symbols is asserted (new code is fully covered, including both branches of the guard).Scope
Deliberately limited to these two mappings to keep the diff reviewable. Further mappings discussed under #7 (
xsd:duration,xsd:time,xsd:gYear,rdf:JSON, …) are left as follow-ups. This PR does not close #7 and does not overlap with #61, #73 or #74 (none of them touch theLiteralFromwrite side).