@@ -5,13 +5,9 @@ import * as RDF from '../data-model';
55import { Bindings , Query , ResultStream } from './common' ;
66
77/**
8- * Context objects provide a way to pass additional bits information to the query engine when executing a query.
8+ * Context properties provide a way to pass additional bits information to the query engine when executing a query.
99 */
10- export interface QueryContext < SourceType > {
11- /**
12- * An array of data sources the query engine must use.
13- */
14- sources ?: [ SourceType , ...SourceType [ ] ] ;
10+ export interface QueryContext {
1511 /**
1612 * The date that should be used by SPARQL operations such as NOW().
1713 */
@@ -23,9 +19,9 @@ export interface QueryContext<SourceType> {
2319}
2420
2521/**
26- * Context object in the case the passed query is a string.
22+ * Context properties in the case the passed query is a string.
2723 */
28- export interface QueryStringContext < SourceType > extends QueryContext < SourceType > {
24+ export interface QueryStringContext extends QueryContext {
2925 /**
3026 * The format in which the query string is defined.
3127 * Defaults to { language: 'sparql', version: '1.1' }
@@ -38,9 +34,19 @@ export interface QueryStringContext<SourceType> extends QueryContext<SourceType>
3834}
3935
4036/**
41- * Context object in the case the passed query is an algebra object.
37+ * Context properties in the case the passed query is an algebra object.
4238 */
43- export type QueryAlgebraContext < SourceType > = QueryContext < SourceType > ;
39+ export type QueryAlgebraContext = QueryContext ;
40+
41+ /**
42+ * Context properties for engines that can query upon dynamic sets of sources.
43+ */
44+ export interface QuerySourceContext < SourceType > {
45+ /**
46+ * An array of data sources the query engine must use.
47+ */
48+ sources : [ SourceType , ...SourceType [ ] ] ;
49+ }
4450
4551/**
4652 * Represents a specific query format
@@ -61,83 +67,91 @@ export interface QueryFormat {
6167 extensions ?: string [ ] ;
6268}
6369
64- /**
65- * Placeholder to represent SPARQL Algebra trees.
66- * Algebra typings are TBD. Reference implementations include:
67- * - https://www.npmjs.com/package/sparqlalgebrajs
68- */
69- export type Algebra = any ;
70-
7170/**
7271 * Generic query engine interfaces.
73- * It allow engines to return any type of result object for any type of query.
74- * @param QueryFormatTypesAvailable The format of the query, either string or algebra object.
75- * @param SourceType The allowed sources over which queries can be executed.
72+ * It allow engines to return any type of result object for string queries.
7673 * @param SupportedMetadataType The allowed metadata types.
77- * @param QueryType The allowed query types.
7874 * @param QueryStringContextType Type of the string-based query context.
79- * @param QueryAlgebraContextType Type of the algebra-based query context.
8075 */
81- export interface Queryable <
82- QueryFormatTypesAvailable extends string | Algebra ,
83- SourceType ,
76+ export interface StringQueryable <
8477 SupportedMetadataType ,
85- QueryType extends Query < SupportedMetadataType > ,
86- QueryStringContextType extends QueryStringContext < SourceType > ,
87- QueryAlgebraContextType extends QueryAlgebraContext < SourceType > ,
78+ QueryStringContextType extends QueryStringContext = QueryStringContext ,
8879> {
8980 /**
90- * Initiate a given query.
81+ * Initiate a given query provided as a string .
9182 *
9283 * This will produce a future to a query result, which has to be executed to obtain the query results.
9384 *
9485 * This can reject given an unsupported or invalid query.
9586 *
9687 * @see Query
9788 */
98- query < QueryFormatType extends QueryFormatTypesAvailable > (
99- query : QueryFormatType ,
100- context ?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType ,
101- ) : Promise < QueryType > ;
89+ query ( query : string , context ?: QueryStringContextType ) : Promise < Query < SupportedMetadataType > > ;
10290}
10391
10492/**
105- * SPARQL-constrained query interface.
93+ * Generic query engine interfaces.
94+ * It allow engines to return any type of result object for Algebra queries.
95+ * @param AlgebraType The supported algebra types.
96+ * @param SupportedMetadataType The allowed metadata types.
97+ * @param QueryStringContextType Type of the algebra-based query context.
98+ */
99+ export interface AlgebraQueryable <
100+ AlgebraType ,
101+ SupportedMetadataType ,
102+ QueryAlgebraContextType extends QueryAlgebraContext = QueryAlgebraContext ,
103+ > {
104+ /**
105+ * Initiate a given query provided as an Algebra object.
106+ *
107+ * This will produce a future to a query result, which has to be executed to obtain the query results.
108+ *
109+ * This can reject given an unsupported or invalid query.
110+ *
111+ * @see Query
112+ */
113+ query ( query : AlgebraType , context ?: QueryAlgebraContextType ) : Promise < Query < SupportedMetadataType > > ;
114+ }
115+
116+ /**
117+ * SPARQL-constrained query interface for queries provided as strings.
106118 *
107119 * This interface guarantees that result objects are of the expected type as defined by the SPARQL spec.
108120 */
109- export type SparqlQueryable <
110- QueryFormatTypesAvailable extends string | Algebra ,
111- SourceType ,
112- QueryStringContextType extends QueryStringContext < SourceType > ,
113- QueryAlgebraContextType extends QueryAlgebraContext < SourceType > ,
114- SupportedResultType ,
115- > = unknown
121+ export type StringSparqlQueryable < SupportedResultType , QueryStringContextType extends QueryStringContext = QueryStringContext > = unknown
116122 & ( SupportedResultType extends BindingsResultSupport ? {
117- queryBindings < QueryFormatType extends QueryFormatTypesAvailable > (
118- query : QueryFormatType ,
119- context ?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType ,
120- ) : Promise < ResultStream < Bindings > > ;
123+ queryBindings ( query : string , context ?: QueryStringContextType ) : Promise < ResultStream < Bindings > > ;
121124} : unknown )
122125 & ( SupportedResultType extends BooleanResultSupport ? {
123- queryBoolean < QueryFormatType extends QueryFormatTypesAvailable > (
124- query : QueryFormatType ,
125- context ?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType ,
126- ) : Promise < boolean > ;
126+ queryBoolean ( query : string , context ?: QueryStringContextType ) : Promise < boolean > ;
127127} : unknown )
128128 & ( SupportedResultType extends QuadsResultSupport ? {
129- queryQuads < QueryFormatType extends QueryFormatTypesAvailable > (
130- query : QueryFormatType ,
131- context ?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType ,
132- ) : Promise < ResultStream < RDF . Quad > > ;
129+ queryQuads ( query : string , context ?: QueryStringContextType ) : Promise < ResultStream < RDF . Quad > > ;
133130} : unknown )
134131 & ( SupportedResultType extends VoidResultSupport ? {
135- queryVoid < QueryFormatType extends QueryFormatTypesAvailable > (
136- query : QueryFormatType ,
137- context ?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType ,
138- ) : Promise < void > ;
132+ queryVoid ( query : string , context ?: QueryStringContextType ) : Promise < void > ;
133+ } : unknown )
134+ ;
135+
136+ /**
137+ * SPARQL-constrainted query interface for queries provided as Algebra objects.
138+ *
139+ * This interface guarantees that result objects are of the expected type as defined by the SPARQL spec.
140+ */
141+ export type AlgebraSparqlQueryable < AlgebraType , SupportedResultType , QueryAlgebraContextType extends QueryAlgebraContext = QueryAlgebraContext > = unknown
142+ & ( SupportedResultType extends BindingsResultSupport ? {
143+ queryBindings ( query : AlgebraType , context ?: QueryAlgebraContextType ) : Promise < ResultStream < Bindings > > ;
144+ } : unknown )
145+ & ( SupportedResultType extends BooleanResultSupport ? {
146+ queryBoolean ( query : AlgebraType , context ?: QueryAlgebraContextType ) : Promise < boolean > ;
147+ } : unknown )
148+ & ( SupportedResultType extends QuadsResultSupport ? {
149+ queryQuads ( query : AlgebraType , context ?: QueryAlgebraContextType ) : Promise < ResultStream < RDF . Quad > > ;
150+ } : unknown )
151+ & ( SupportedResultType extends VoidResultSupport ? {
152+ queryVoid ( query : AlgebraType , context ?: QueryAlgebraContextType ) : Promise < void > ;
139153} : unknown )
140- ;
154+ ;
141155
142156export type SparqlResultSupport = BindingsResultSupport & VoidResultSupport & QuadsResultSupport & BooleanResultSupport ;
143157export type BindingsResultSupport = { bindings : true } ;
0 commit comments