rdfjs / types

Authoritative TypeScript typings for all RDFJS specifications
MIT License
17 stars 13 forks source link

Modularizes Queryable and SparqlQueryable interfaces #32

Closed jacoscaz closed 2 years ago

jacoscaz commented 2 years ago

EDIT: I should premise that this PR builds on the feature/query branch, for which there is already an open PR at https://github.com/rdfjs/types/pull/30 .

This PR was inspired by @tpluscode's feedback as discussed on Gitter.im. The goal is to break down Queryable and SparqlQueryable into simpler, more modular interfaces that can be combined without loss in expressivity. I've opted to break them down based on query type (string vs. Algebra).

Example of what becomes possible with this PR:

import { 
  StringSparqlQueryable, 
  AlgebraSparqlQueryable, 
  StringQueryable, 
  AlgebraQueryable,
  BindingsResultSupport,
  QuadsResultSupport,
  QuerySourceContext,
  QueryStringContext,
  QueryAlgebraContext,
 } from './query/queryable';

interface SourceType {
  answer: 42;
}

type EngineType = StringSparqlQueryable<
  QuadsResultSupport & BindingsResultSupport,
  QueryStringContext & QueryAlgebraContext & QuerySourceContext<SourceType>,
> & AlgebraSparqlQueryable<
  QuadsResultSupport & BindingsResultSupport,
  QueryAlgebraContext & QuerySourceContext<SourceType>,
>;

const query = await ({} as EngineType).queryBindings({}, { sources: [{ answer: 42 }] });
changeset-bot[bot] commented 2 years ago

⚠️ No Changeset found

Latest commit: d47c8b12f8856210c3c7fb2c9d0cfd7ead0a7d1f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

jacoscaz commented 2 years ago

@rubensworks I did a small amount of manual testing to verify whether methods get correctly overloaded across interfaces but this could definitely do with more testing. Might be a good starting point for actual type tests, as per @tpluscode's comment in the other PR. I was waiting for preliminary feedback before committing further effort.

rubensworks commented 2 years ago

Might be a good starting point for actual type tests, as per @tpluscode's comment in the other PR. I was waiting for preliminary feedback before committing further effort.

Yep, I'm already working on those as we speak in #30