import type { Algebra } from '@comunica/utils-algebra'; import type * as RDF from '@rdfjs/types'; import type { AsyncIterator } from 'asynciterator'; import type { BindingsStream } from './Bindings'; import type { IActionContext } from './IActionContext'; import type { QueryAlgebraContext, QueryStringContext } from './IQueryContext'; import type { IQueryExplained, QueryEnhanced, QueryExplainMode } from './IQueryOperationResult'; import type { QuerySourceUnidentified } from './IQuerySource'; export type QueryFormatType = string | Algebra.Operation; export type SourceType = QuerySourceUnidentified; export type QueryType = QueryEnhanced & { context?: IActionContext; }; /** * Base interface for a Comunica query engine. */ export interface IQueryEngine extends RDF.StringQueryable, RDF.AlgebraQueryable, RDF.StringSparqlQueryable, RDF.AlgebraSparqlQueryable { /** * Query the bindings results of a SELECT query. * @param query A query string or algebra object. * Algebra objects must not contain blank nodes. They should be converted to variables. * @param context A context. */ queryBindings: (query: QueryFormatTypeInner, context?: QueryFormatTypeInner extends string ? QueryStringContextInner : QueryAlgebraContextInner) => Promise; /** * Query the quad results of a CONSTRUCT or DESCRIBE query. * @param query A query string or algebra object. * Algebra objects must not contain blank nodes. They should be converted to variables. * @param context A context. */ queryQuads: (query: QueryFormatTypeInner, context?: QueryFormatTypeInner extends string ? QueryStringContextInner : QueryAlgebraContextInner) => Promise & RDF.ResultStream>; /** * Query the boolean result of an ASK query. * @param query A query string or algebra object. * Algebra objects must not contain blank nodes. They should be converted to variables. * @param context A context. */ queryBoolean: (query: QueryFormatTypeInner, context?: QueryFormatTypeInner extends string ? QueryStringContextInner : QueryAlgebraContextInner) => Promise; /** * Execute an UPDATE query. * @param query A query string or algebra object. * Algebra objects must not contain blank nodes. They should be converted to variables. * @param context A context. */ queryVoid: (query: QueryFormatTypeInner, context?: QueryFormatTypeInner extends string ? QueryStringContextInner : QueryAlgebraContextInner) => Promise; /** * Initiate a given query. * 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. * * This method is prefered in case you don't know beforehand what type of query will be executed, * or if you require access to the metadata of the results. * * @param query A query string or algebra object. * Algebra objects must not contain blank nodes. They should be converted to variables. * @param context A context. */ query: (query: QueryFormatTypeInner, context?: QueryFormatTypeInner extends string ? QueryStringContextInner : QueryAlgebraContextInner) => Promise; /** * Explain the given query * @param {string | Algebra.Operation} query A query string or algebra. * Algebra objects must not contain blank nodes. * They should be converted to variables. * @param context A query context. * @param explainMode The explain mode. * @return {Promise} * A promise that resolves to the query output. */ explain: (query: QueryFormatTypeInner, context: QueryFormatTypeInner extends string ? QueryStringContextInner : QueryAlgebraContextInner, explainMode: QueryExplainMode) => Promise; /** * @param context An optional context. * @return {Promise<{[p: string]: number}>} All available SPARQL (weighted) result media types. */ getResultMediaTypes: (context?: IActionContext) => Promise>; /** * @param context An optional context. * @return {Promise<{[p: string]: number}>} All available SPARQL result media type formats. */ getResultMediaTypeFormats: (context?: IActionContext) => Promise>; /** * Convert a query result to a string stream based on a certain media type. * @param {QueryType} queryResult A query result. * @param {string} mediaType A media type. * @param {IActionContext} context An optional context. * @return {Promise} A text stream. */ resultToString: (queryResult: QueryType, mediaType?: string, context?: any) => any; /** * Invalidate all internal caches related to the given page URL. * If no page URL is given, then all pages will be invalidated. * @param {string} url The page URL to invalidate. * @return {Promise} A promise resolving when the caches have been invalidated. */ invalidateHttpCache: (url?: string) => Promise; }