Implement actionable TODOs: typed errors, term type checks, lang string direction#32
Implement actionable TODOs: typed errors, term type checks, lang string direction#32
Conversation
…ection, and missing tests Co-authored-by: jeswr <63333554+jeswr@users.noreply.github.com> Agent-Logs-Url: https://github.com/rdfjs/wrapper/sessions/035a1c66-f819-453e-8236-8513bc7eaf1c
| // TODO: Lang string dictionary value mapping | ||
| export function langStringToLiteral(value: ILangString, dataset: DatasetCore, factory: DataFactory): TermWrapper | undefined { | ||
| // TODO: Fix bug in N3.JS function literal line 340 (test languageOrDataType === 'string') | ||
| // Then re-establish proper factory method | ||
| //return new TermWrapper(factory.literal(value.string, { language: value.lang } ), dataset, factory) | ||
| return new TermWrapper(factory.literal(value.string, value.lang), dataset, factory) |
There was a problem hiding this comment.
@langsamu could you please check that you are satisfied that these TODO's are resolved by this PR -- they are the only ones I am not sure on
There was a problem hiding this comment.
Note that I have asked co-pilot to perform a regression test in 04994ce -- can you please confirm that this means the N3.js bug is indeed fixed.
There was a problem hiding this comment.
Pull request overview
Implements previously-marked TODOs in the RDF/JS wrapper library by introducing typed error classes, enforcing termType guards in ValueMapping, and adding RDF 1.2 directional language-string support across term/value mappings and tests.
Changes:
- Added exported typed errors for singular-arity failures and value-mapping term-type mismatches.
- Implemented
termTypechecks acrossValueMappingconversions and updated tests accordingly. - Updated lang-string mappings to round-trip RDF 1.2
directionand expanded unit test coverage for several TODO areas.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/unit/vocabulary/Example.ts | Adds new example predicates used by new nullable/set mapping tests. |
| test/unit/term_wrapper.test.ts | Updates/extends tests for typed errors, sets, nullable object mapping, and lang-string direction shape. |
| test/unit/model/Parent.ts | Adds hasNullableChild and hasStringSet mappings to support new tests. |
| src/mod.ts | Re-exports newly introduced error classes as part of the public API. |
| src/mapping/ValueMapping.ts | Adds termType guards and throws ValueMappingError; returns lang-string direction. |
| src/mapping/TermMapping.ts | Uses RDF 1.2 lang-string factory overload including { language, direction }. |
| src/ValueMappingError.ts | Introduces typed error for value-mapping term-type mismatches. |
| src/TermWrapper.ts | Replaces generic singular() errors with typed singular-arity errors. |
| src/SingularTooManyValuesError.ts | Introduces typed error for singular() when multiple values exist. |
| src/SingularNoValueError.ts | Introduces typed error for singular() when no values exist. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: jeswr <63333554+jeswr@users.noreply.github.com> Agent-Logs-Url: https://github.com/rdfjs/wrapper/sessions/a2c0ddac-9ffa-4459-b5df-c3cee6c630e2
Added round-trip tests for |
|
@copilot please add a test to make sure that the bug for which the following comment has been removed "TODO: Fix bug in N3.JS function literal line 340 (test languageOrDataType === 'string')" has actually been resolved. Looking at the changelog of N3.js; I think that a different error was being fixed there. |
Co-authored-by: jeswr <63333554+jeswr@users.noreply.github.com> Agent-Logs-Url: https://github.com/rdfjs/wrapper/sessions/21e9d5f5-87a3-48df-89bc-854e1898bbb5
Added a regression test ( |
|
Errors have been done elsewhere and the mapping API has evolved. |
Implements the open TODOs that don't require design decisions, covering typed error classes, term type guards in
ValueMapping, RDF 1.2 directional language string support, and the missing test coverage they called for.Typed error classes
Three exported error classes replace anonymous
Errorthrows:ValueMappingError— thrown when a value mapping receives the wrongtermTypeSingularNoValueError— thrown bysingular()when no quad matchesSingularTooManyValuesError— thrown bysingular()when multiple quads matchAll three are exported from
mod.ts.ValueMappingterm type checksEvery mapping function now guards on
termTypebefore converting:Affected functions:
blankNodeToString,literalToDate,literalToLangString,literalToNumber,literalToBoolean,literalToString,iriToString.RDF 1.2 directional language strings
The N3.js bug referenced in
langStringToLiteralis fixed in v2.0.3.literalToLangStringnow populatesdirectionandlangStringToLiteralpasses{ language, direction }to the factory:Tests
All implemented TODOs in
term_wrapper.test.tsare resolved:SingularNoValueError/SingularTooManyValuesErrorspecificallydescribe("Set")block underArity Mappingcovers set cardinality behaviourChild | undefined) tested via newhasNullableChildproperty on theParentmodelhasStringSet: Set<string>propertyValueMapping"Type Errors" subsection covers allValueMappingErrorthrow pathsdirection: 'rtl'anddirection: 'ltr'assert thatliteralToLangStringpreserves the RDF 1.2 direction valuefactory.literal(text, { language })object form): callsTermMapping.langStringToLiteraland asserts the resulting term'slanguageis set correctly, guarding against any future N3.js regression in object-form language handlingOriginal prompt
Created from VS Code.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.