@@ -5,13 +5,9 @@ import * as RDF from '../data-model';
5
5
import { Bindings , Query , ResultStream } from './common' ;
6
6
7
7
/**
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.
9
9
*/
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 {
15
11
/**
16
12
* The date that should be used by SPARQL operations such as NOW().
17
13
*/
@@ -23,9 +19,9 @@ export interface QueryContext<SourceType> {
23
19
}
24
20
25
21
/**
26
- * Context object in the case the passed query is a string.
22
+ * Context properties in the case the passed query is a string.
27
23
*/
28
- export interface QueryStringContext < SourceType > extends QueryContext < SourceType > {
24
+ export interface QueryStringContext extends QueryContext {
29
25
/**
30
26
* The format in which the query string is defined.
31
27
* Defaults to { language: 'sparql', version: '1.1' }
@@ -38,9 +34,19 @@ export interface QueryStringContext<SourceType> extends QueryContext<SourceType>
38
34
}
39
35
40
36
/**
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.
42
38
*/
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
+ }
44
50
45
51
/**
46
52
* Represents a specific query format
@@ -61,83 +67,91 @@ export interface QueryFormat {
61
67
extensions ?: string [ ] ;
62
68
}
63
69
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
-
71
70
/**
72
71
* 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.
76
73
* @param SupportedMetadataType The allowed metadata types.
77
- * @param QueryType The allowed query types.
78
74
* @param QueryStringContextType Type of the string-based query context.
79
- * @param QueryAlgebraContextType Type of the algebra-based query context.
80
75
*/
81
- export interface Queryable <
82
- QueryFormatTypesAvailable extends string | Algebra ,
83
- SourceType ,
76
+ export interface StringQueryable <
84
77
SupportedMetadataType ,
85
- QueryType extends Query < SupportedMetadataType > ,
86
- QueryStringContextType extends QueryStringContext < SourceType > ,
87
- QueryAlgebraContextType extends QueryAlgebraContext < SourceType > ,
78
+ QueryStringContextType extends QueryStringContext = QueryStringContext ,
88
79
> {
89
80
/**
90
- * Initiate a given query.
81
+ * Initiate a given query provided as a string .
91
82
*
92
83
* This will produce a future to a query result, which has to be executed to obtain the query results.
93
84
*
94
85
* This can reject given an unsupported or invalid query.
95
86
*
96
87
* @see Query
97
88
*/
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 > > ;
102
90
}
103
91
104
92
/**
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.
106
118
*
107
119
* This interface guarantees that result objects are of the expected type as defined by the SPARQL spec.
108
120
*/
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
116
122
& ( 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 > > ;
121
124
} : unknown )
122
125
& ( 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 > ;
127
127
} : unknown )
128
128
& ( 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 > > ;
133
130
} : unknown )
134
131
& ( 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 > ;
139
153
} : unknown )
140
- ;
154
+ ;
141
155
142
156
export type SparqlResultSupport = BindingsResultSupport & VoidResultSupport & QuadsResultSupport & BooleanResultSupport ;
143
157
export type BindingsResultSupport = { bindings : true } ;
0 commit comments