refactor(sparql-importer): replace import result classes with discriminated union#212
Open
refactor(sparql-importer): replace import result classes with discriminated union#212
Conversation
…inated union
- Replace ImportSuccessful, ImportFailed, NotSupported classes with
interfaces carrying a `type` discriminant ('successful', 'failed',
'not-supported')
- Add ImportResult union type for the Importer.import() return type
- Update sparql-qlever Importer to return plain objects instead of
class instances
- Replace instanceof checks with type-property checks in pipeline's
ImportResolver and all tests
- Change value imports to type-only imports where possible
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
ImportSuccessful,ImportFailed, andNotSupportedclasses in@lde/sparql-importerwith interfaces carrying atypediscriminant ('successful','failed','not-supported')ImportResultunion type as the return type forImporter.import()@lde/sparql-qleverto return plain objects instead of class instancesinstanceofchecks withresult.type === '...'comparisons in@lde/pipeline'sImportResolverand all testsThis eliminates
instanceoffailures that occur when npm doesn't dedupe@lde/sparql-importeracross packages — with a discriminated union there's no prototype chain to compare, so the check works regardless of how many copies of the package are installed.