-
Notifications
You must be signed in to change notification settings - Fork 13
Modularizes Queryable and SparqlQueryable interfaces #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rubensworks
merged 6 commits into
rdfjs:feature/query
from
jacoscaz:feature/query-separate-interfaces
Feb 15, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3b7ba40
modularizes Queryable and SparqlQueryable interfaces
jacoscaz 61f5a6a
mentions the difference between queries provided as strings and queri…
jacoscaz d7ba23c
adds support for multiple algebra types, drops conceptual dependency …
jacoscaz a666eab
updates test to use modularized interfaces
jacoscaz 186c2b7
adds tests for Algebra interfaces
jacoscaz d47c8b1
drops redundant semicolons
jacoscaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,9 @@ import * as RDF from '../data-model'; | |
import { Bindings, Query, ResultStream } from './common'; | ||
|
||
/** | ||
* Context objects provide a way to pass additional bits information to the query engine when executing a query. | ||
* Context properties provide a way to pass additional bits information to the query engine when executing a query. | ||
*/ | ||
export interface QueryContext<SourceType> { | ||
/** | ||
* An array of data sources the query engine must use. | ||
*/ | ||
sources?: [SourceType, ...SourceType[]]; | ||
export interface QueryContext { | ||
/** | ||
* The date that should be used by SPARQL operations such as NOW(). | ||
*/ | ||
|
@@ -23,9 +19,9 @@ export interface QueryContext<SourceType> { | |
} | ||
|
||
/** | ||
* Context object in the case the passed query is a string. | ||
* Context properties in the case the passed query is a string. | ||
*/ | ||
export interface QueryStringContext<SourceType> extends QueryContext<SourceType> { | ||
export interface QueryStringContext extends QueryContext { | ||
/** | ||
* The format in which the query string is defined. | ||
* Defaults to { language: 'sparql', version: '1.1' } | ||
|
@@ -38,9 +34,19 @@ export interface QueryStringContext<SourceType> extends QueryContext<SourceType> | |
} | ||
|
||
/** | ||
* Context object in the case the passed query is an algebra object. | ||
* Context properties in the case the passed query is an algebra object. | ||
*/ | ||
export type QueryAlgebraContext<SourceType> = QueryContext<SourceType>; | ||
export type QueryAlgebraContext = QueryContext; | ||
|
||
/** | ||
* Context properties for engines that can query upon dynamic sets of sources. | ||
*/ | ||
export interface QuerySourceContext<SourceType> { | ||
/** | ||
* An array of data sources the query engine must use. | ||
*/ | ||
sources: [SourceType, ...SourceType[]]; | ||
} | ||
|
||
/** | ||
* Represents a specific query format | ||
|
@@ -61,83 +67,91 @@ export interface QueryFormat { | |
extensions?: string[]; | ||
} | ||
|
||
/** | ||
* Placeholder to represent SPARQL Algebra trees. | ||
* Algebra typings are TBD. Reference implementations include: | ||
* - https://www.npmjs.com/package/sparqlalgebrajs | ||
*/ | ||
export type Algebra = any; | ||
|
||
/** | ||
* Generic query engine interfaces. | ||
* It allow engines to return any type of result object for any type of query. | ||
* @param QueryFormatTypesAvailable The format of the query, either string or algebra object. | ||
* @param SourceType The allowed sources over which queries can be executed. | ||
* It allow engines to return any type of result object for string queries. | ||
* @param SupportedMetadataType The allowed metadata types. | ||
* @param QueryType The allowed query types. | ||
* @param QueryStringContextType Type of the string-based query context. | ||
* @param QueryAlgebraContextType Type of the algebra-based query context. | ||
*/ | ||
export interface Queryable< | ||
QueryFormatTypesAvailable extends string | Algebra, | ||
SourceType, | ||
export interface StringQueryable< | ||
SupportedMetadataType, | ||
QueryType extends Query<SupportedMetadataType>, | ||
jacoscaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
QueryStringContextType extends QueryStringContext<SourceType>, | ||
QueryAlgebraContextType extends QueryAlgebraContext<SourceType>, | ||
QueryStringContextType extends QueryStringContext = QueryStringContext, | ||
> { | ||
/** | ||
* Initiate a given query. | ||
* Initiate a given query provided as a string. | ||
* | ||
* This will produce a future to a query result, which has to be executed to obtain the query results. | ||
* | ||
* This can reject given an unsupported or invalid query. | ||
* | ||
* @see Query | ||
*/ | ||
query<QueryFormatType extends QueryFormatTypesAvailable>( | ||
query: QueryFormatType, | ||
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType, | ||
): Promise<QueryType>; | ||
query(query: string, context?: QueryStringContextType): Promise<Query<SupportedMetadataType>>; | ||
} | ||
|
||
/** | ||
* SPARQL-constrained query interface. | ||
* Generic query engine interfaces. | ||
* It allow engines to return any type of result object for Algebra queries. | ||
* @param AlgebraType The supported algebra types. | ||
* @param SupportedMetadataType The allowed metadata types. | ||
* @param QueryStringContextType Type of the algebra-based query context. | ||
*/ | ||
export interface AlgebraQueryable< | ||
AlgebraType, | ||
SupportedMetadataType, | ||
QueryAlgebraContextType extends QueryAlgebraContext = QueryAlgebraContext, | ||
> { | ||
/** | ||
* Initiate a given query provided as an Algebra object. | ||
* | ||
* This will produce a future to a query result, which has to be executed to obtain the query results. | ||
* | ||
* This can reject given an unsupported or invalid query. | ||
* | ||
* @see Query | ||
*/ | ||
query(query: AlgebraType, context?: QueryAlgebraContextType): Promise<Query<SupportedMetadataType>>; | ||
} | ||
|
||
/** | ||
* SPARQL-constrained query interface for queries provided as strings. | ||
* | ||
* This interface guarantees that result objects are of the expected type as defined by the SPARQL spec. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tsdoc doesn't mention the fact that it's string-queryable. |
||
*/ | ||
export type SparqlQueryable< | ||
QueryFormatTypesAvailable extends string | Algebra, | ||
SourceType, | ||
QueryStringContextType extends QueryStringContext<SourceType>, | ||
QueryAlgebraContextType extends QueryAlgebraContext<SourceType>, | ||
SupportedResultType, | ||
> = unknown | ||
export type StringSparqlQueryable<SupportedResultType, QueryStringContextType extends QueryStringContext = QueryStringContext> = unknown | ||
& (SupportedResultType extends BindingsResultSupport ? { | ||
queryBindings<QueryFormatType extends QueryFormatTypesAvailable>( | ||
query: QueryFormatType, | ||
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType, | ||
): Promise<ResultStream<Bindings>>; | ||
queryBindings(query: string, context?: QueryStringContextType): Promise<ResultStream<Bindings>>; | ||
} : unknown) | ||
& (SupportedResultType extends BooleanResultSupport ? { | ||
queryBoolean<QueryFormatType extends QueryFormatTypesAvailable>( | ||
query: QueryFormatType, | ||
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType, | ||
): Promise<boolean>; | ||
queryBoolean(query: string, context?: QueryStringContextType): Promise<boolean>; | ||
} : unknown) | ||
& (SupportedResultType extends QuadsResultSupport ? { | ||
queryQuads<QueryFormatType extends QueryFormatTypesAvailable>( | ||
query: QueryFormatType, | ||
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType, | ||
): Promise<ResultStream<RDF.Quad>>; | ||
queryQuads(query: string, context?: QueryStringContextType): Promise<ResultStream<RDF.Quad>>; | ||
} : unknown) | ||
& (SupportedResultType extends VoidResultSupport ? { | ||
queryVoid<QueryFormatType extends QueryFormatTypesAvailable>( | ||
query: QueryFormatType, | ||
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType, | ||
): Promise<void>; | ||
queryVoid(query: string, context?: QueryStringContextType): Promise<void>; | ||
} : unknown) | ||
; | ||
|
||
/** | ||
* SPARQL-constrainted query interface for queries provided as Algebra objects. | ||
* | ||
* This interface guarantees that result objects are of the expected type as defined by the SPARQL spec. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tsdoc doesn't mention the fact that it's algebra-queryable. |
||
*/ | ||
export type AlgebraSparqlQueryable<AlgebraType, SupportedResultType, QueryAlgebraContextType extends QueryAlgebraContext = QueryAlgebraContext> = unknown | ||
& (SupportedResultType extends BindingsResultSupport ? { | ||
queryBindings(query: AlgebraType, context?: QueryAlgebraContextType): Promise<ResultStream<Bindings>>; | ||
} : unknown) | ||
& (SupportedResultType extends BooleanResultSupport ? { | ||
queryBoolean(query: AlgebraType, context?: QueryAlgebraContextType): Promise<boolean>; | ||
} : unknown) | ||
& (SupportedResultType extends QuadsResultSupport ? { | ||
queryQuads(query: AlgebraType, context?: QueryAlgebraContextType): Promise<ResultStream<RDF.Quad>>; | ||
} : unknown) | ||
& (SupportedResultType extends VoidResultSupport ? { | ||
queryVoid(query: AlgebraType, context?: QueryAlgebraContextType): Promise<void>; | ||
} : unknown) | ||
; | ||
; | ||
|
||
export type SparqlResultSupport = BindingsResultSupport & VoidResultSupport & QuadsResultSupport & BooleanResultSupport; | ||
export type BindingsResultSupport = { bindings: true }; | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.