Last active
October 18, 2021 10:45
-
-
Save rubensworks/1ecedf592e851981ff89c869c1284056 to your computer and use it in GitHub Desktop.
This file contains 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
interface Queryable<SourceType> { | |
query(query: string, context?: QueryStringContext<SourceType>): Promise<QueryResult> | |
} | |
interface QueryableAlgebra<SourceType> { | |
query(query: Algebra, context?: QueryAlgebraContext<SourceType>): Promise<QueryResult> | |
} | |
// TODO: what about update queries? | |
type QueryResult = QueryResultBindings | QueryResultQuads | QueryResultBoolean; // TODO: should we open this up for other types? | |
interface QueryResultBindings { | |
type: 'bindings'; | |
metadata: () => Metadata; | |
bindings: Stream<Bindings>; // This should be a lazy stream | |
variables: RDF.Variable[]; | |
} | |
interface QueryResultQuads { | |
type: 'quads'; | |
metadata: () => Metadata; | |
quads: Stream<RDF.Quad>; // This should be a lazy stream | |
} | |
interface QueryResultBoolean { | |
type: 'boolean'; | |
metadata: () => Metadata; // TODO: do we need this here? | |
booleanResult: Promise<boolean>; // TODO: make this lazy behind a lambda? | |
} | |
interface Metadata { | |
cardinality?: number; // Cardinality estimate | |
[key: string]: any; // For any other custom metadata entries. | |
} | |
interface Bindings { | |
type: 'bindings'; | |
get(variable: RDF.Variable): RDF.Term; | |
keys(): RDF.Variable[]; | |
entries(): [RDF.Variable, RDF.Term][]; | |
size: number; | |
} | |
interface BindingsFactory { | |
createBindings(entries: [RDF.Variable, RDF.Term][]): Bindings; | |
mergeBindings(bindings: Bindings[]): Bindings; | |
} | |
// SourceType can be anything the query engine defines | |
// TODO: we may consider defining some standards, like 'string', RDF.Source, ... | |
interface QueryContext<SourceType> { | |
sources?: SourceType[]; | |
queryTimestamp?: Date; // Required for certain SPARQL operations such as NOW(). | |
[key: string]: any; // For any other custom metadata entries. | |
} | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment