-
Notifications
You must be signed in to change notification settings - Fork 0
Queryable and Filterable typings #7
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
Merged
Changes from 3 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
8d364bd
first draft of the Queryable spec
jacoscaz 04daba8
adds undefined as a possible return type of BindingsFactory.merge()
jacoscaz d017b32
drops strong metadata typization
jacoscaz ea71d63
adds all the interfaces and types from the WebIDL version of the Filt…
jacoscaz 14e403e
adds limit, offset and available orders based on #8
jacoscaz 3400d5e
drops use of generics in Queryable(Algebra)Context as per #7
jacoscaz e84c9a9
uses generics to allow implementors to specify supported return types…
jacoscaz 3857a75
renames value methods in intermediate result objects to execute() and…
jacoscaz 8b076ac
adds support for custom properties in QueryOperationCost
jacoscaz 79a5f80
aliases Algebra to any
jacoscaz 331a63c
makes Bindings extend Iterable
jacoscaz d24f360
moves mutation methods from Bindings to BindingsFactory
jacoscaz 93ed430
renames FilterableResult#quads() to #execute() to align with Queryabl…
jacoscaz c7a7e46
drops BaseQueryableResult
jacoscaz aeff5ba
FilterableResultMetadataCount becomes FilterableResultMetadataCount
jacoscaz bc10881
count becomes cardinality
jacoscaz e32c527
count becomes cardinality
jacoscaz 910f6ec
QueryableContext becomes QueryableStringContext
jacoscaz 75e2e51
offset becomes start, limit becomes length in FilterableSource
jacoscaz da34b6c
adds support for custom properties in FilterableResultMetadata
jacoscaz ee78abb
makes BindingsFactory#merge() return undefined on merge conflicts
jacoscaz 8e7f57c
merges QueryableResultMetadata and FilterableResultMetadata, Queryabl…
jacoscaz c24fb47
adds dedicated interface for execute() options
jacoscaz b1f2625
moves QueryResultBindings#variables into a dedicated interface extend…
jacoscaz 63c2d9e
Replace the "Queryable" prefix with "Query"
jacoscaz bba92c5
Replace the "Queryable" prefix with "Query"
jacoscaz 8b7abcb
renames QueryResult* to Query*
jacoscaz fc1d32a
drops isSupported()
jacoscaz 022adec
adds comments mentioning possible rejections in case of unsupported q…
jacoscaz 5e86528
renames type to resultType, refactors metadata to use specific methods
jacoscaz 1f6ca66
refactors high-level *Queryable interfaces into a single interface us…
jacoscaz a5fc74d
renames QueryResultExecuteOptions to QueryExecuteOptions
jacoscaz b12a29c
drops one layer of indirection when retrieving metadata
jacoscaz 035741f
fixes type resolution when dealing with metadata
jacoscaz e42a0fe
execute()'s options do not need to include the selected ordering's cost
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 |
---|---|---|
@@ -0,0 +1,140 @@ | ||
|
||
import RDF from '@rdfjs/types'; | ||
import {Algebra} from 'sparqlalgebrajs'; | ||
import {EventEmitter} from 'events'; // TODO: refer to underlying interface, not to the class | ||
|
||
/* | ||
* Helper union type | ||
*/ | ||
type TermName = 'subject' | 'predicate' | 'object' | 'graph'; | ||
|
||
/* | ||
* Custom typings for the RDF/JS Stream interface as the current | ||
* typings restrict the generic param Q to extensions of "BaseQuad", | ||
* meaning it cannot be used for Bindings. | ||
*/ | ||
export interface Stream<Q> extends EventEmitter { | ||
read(): Q | null; | ||
} | ||
|
||
/* | ||
* Map-like representation of Bindings as using plain objects could lead | ||
* to collisions between variable names and object properties. | ||
* Long-term goal: maintain compatibility with the native Map class. | ||
*/ | ||
interface Bindings { | ||
type: 'bindings'; | ||
get(variable: RDF.Variable): RDF.Term; | ||
keys(): RDF.Variable[]; | ||
entries(): [RDF.Variable, RDF.Term][]; | ||
size: number; | ||
} | ||
|
||
/* | ||
* Bindings objects are created using a dedicated factory, keeping in line | ||
* with DataFactory.quad(). This also helps with facilitating support for | ||
* immutability. Basic helper methods must also be provided for the most | ||
* common manipulations of bindings objects. | ||
*/ | ||
interface BindingsFactory { | ||
jacoscaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bindings(entries: [RDF.Variable, RDF.Term][]): Bindings; | ||
// NOTE: returns undefined in case of conflicting bindings, i.e. bindings | ||
// having the same variables. | ||
merge(bindings: Bindings[]): Bindings|undefined; | ||
} | ||
|
||
/* | ||
* Base interfaces to represent query results. These interfaces are generic | ||
* with respect to the types of query metadata objects. These can be extended | ||
* by implementors. | ||
*/ | ||
|
||
interface QueryResultMetadata<OrderItemsType> { | ||
cardinality?: number; | ||
order?: OrderItemsType[]; | ||
[key: string]: any; | ||
} | ||
|
||
interface BaseQueryResult<MetadataOrderType> { | ||
type: 'bindings' | 'quads' | 'boolean'; | ||
jacoscaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
metadata(opts: { [key: string]: any }): Promise<QueryResultMetadata<MetadataOrderType>>; | ||
} | ||
|
||
interface QueryResultBindings extends BaseQueryResult<RDF.Variable> { | ||
type: 'bindings'; | ||
stream(): Stream<Bindings>; | ||
jacoscaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
variables: RDF.Variable[]; | ||
jacoscaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
interface QueryResultQuads extends BaseQueryResult<TermName> { | ||
type: 'quads'; | ||
stream(): Stream<RDF.Quad>; | ||
} | ||
|
||
interface QueryResultBoolean extends BaseQueryResult<any> { | ||
type: 'boolean'; | ||
value(): Promise<boolean>; | ||
} | ||
|
||
type QueryResult = QueryResultBindings | QueryResultQuads | QueryResultBoolean;/* | ||
* Context objects provide a way to pass additional bits information to | ||
* implementors, such as but not limited to: | ||
* - data sources | ||
* - base IRI for IRI resolution | ||
* - timestamp for expression evaluation | ||
* - query language | ||
* - ... | ||
*/ | ||
|
||
// SourceType can be anything the query engine defines | ||
// TODO: we may consider defining some standards, like 'string', RDF.Source, ... | ||
interface QueryContext<SourceType> { | ||
sources: [SourceType, ...SourceType[]]; | ||
jacoscaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
queryTimestamp?: Date; // Required for certain SPARQL operations such as NOW(). | ||
} | ||
|
||
interface QueryStringContext<SourceType> extends QueryContext<SourceType> { | ||
queryFormat?: QueryFormat; // defaults to { language: 'SPARQL', version: '1.1', extensions: [] } | ||
baseIRI?: string; // Required for parsing SPARQL queries | ||
}; | ||
|
||
interface QueryAlgebraContext<SourceType> extends QueryContext<SourceType> {}; | ||
|
||
interface QueryFormat { | ||
language: string; // Like 'SPARQL' | ||
version: string; // Like '1.1' | ||
extensions: string[]; // TODO: leave the syntax of these extensions open for now? | ||
} | ||
|
||
type Algebra = {}; // TODO: define this (possible starting point: https://github.com/joachimvh/SPARQLAlgebra.js) | ||
|
||
/* | ||
* Generic query interfaces. These allow engines to return any type of result | ||
* object for any type of query, supporting the kind of flexibility required | ||
* by engines such as Comunica. | ||
*/ | ||
|
||
interface Queryable<SourceType> { | ||
query<MetadataType, ContextType extends QueryStringContext<SourceType>>(query: string, context?: ContextType): Promise<QueryResult>; | ||
} | ||
|
||
interface QueryableAlgebra<SourceType> { | ||
query<MetadataType, ContextType extends QueryAlgebraContext<SourceType>>(query: Algebra, context?: ContextType): Promise<QueryResult>; | ||
} | ||
|
||
/* | ||
* SPARQL-constrainted query interfaces. These interfaces guarantee that result | ||
* objects are of the expected type as defined by the SPARQL spec. | ||
*/ | ||
|
||
interface QueryableSparql<SourceType> { | ||
boolean?<ContextType extends QueryStringContext<SourceType>>(query: string, context?: ContextType): Promise<QueryResultBoolean>; | ||
bindings?<ContextType extends QueryStringContext<SourceType>>(query: string, context?: ContextType): Promise<QueryResultBindings>; | ||
jacoscaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
quads?<ContextType extends QueryStringContext<SourceType>>(query: string, context?: ContextType): Promise<QueryResultQuads>; | ||
} | ||
|
||
interface QueryableAlgebraSparql<SourceType> { | ||
boolean?<ContextType extends QueryAlgebraContext<SourceType>>(query: Algebra.Ask, context?: ContextType): Promise<QueryResultBoolean>; | ||
bindings?<ContextType extends QueryAlgebraContext<SourceType>>(query: Algebra.Project, context?: ContextType): Promise<QueryResultBindings>; | ||
quads?<ContextType extends QueryAlgebraContext<SourceType>>(query: Algebra.Construct, context?: ContextType): Promise<QueryResultQuads>; | ||
} |
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.