All files / languages/sparql/services sparql-query-state.ts

100% Statements 4/4
100% Branches 4/4
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133                                                                                                                                              6x   6x 2x   4x                                                                                                                
import { PrefixMap } from "@src/utilities";
import { Term } from "@rdfjs/types";
import { getFileName } from "@src/utilities/uri";
 
export type SparqlQueryType = 'bindings' | 'boolean' | 'quads' | 'void';
 
/**
 * The state of a SPARQL query execution.
 */
export interface SparqlQueryExecutionState {
	/**
	 * A unique identifier for the query execution.
	 */
	id: string;
	
	/**
	 * The TextDocument where the SPARQL query is defined. In case of a Notebook, this 
	 * is the IRI of the document that is associated with the cell.
	 */
	documentIri: string;
 
	/**
	 * The workspace relative URI of the `documentIri`.
	 */
	workspaceIri?: string;
 
	/**
	 * The IRI of the notebook file where the SPARQL query is run, if applicable.
	 */
	notebookIri?: string;
 
	/**
	 * Id of the notebook cell associated with the SPARQL query, if any.
	 */
	cellIndex?: number;
 
	/**
	 * The SPARQL query text.
	 */
	query?: string;
 
	/**
	 * The SPARQL query type.
	 */
	queryType?: SparqlQueryType;
 
	/**
	 * The time when the query was executed in milliseconds since midnight, January 1, 1970 UTC.
	 */
	startTime: number;
 
	/**
	 * The time when the query finished executing in milliseconds since midnight, January 1, 1970 UTC.
	 */
	endTime?: number;
 
	/**
	 * The error that occurred during query execution, if any.
	 */
	error?: any;
 
	/**
	 * The results of the query execution, if any.
	 */
	result?: BindingsResult | BooleanResult | QuadsResult;
}
 
/**
 * Get the formatted file name of the associated document or notebook cell.
 */
export function getDisplayName(queryState: SparqlQueryExecutionState): string {
	const fileName = getFileName(queryState.documentIri);
 
	if (queryState.notebookIri && queryState.cellIndex !== undefined) {
		return `${fileName.split('#')[0]}:Cell-${queryState.cellIndex}`;
	} else {
		return fileName;
	}
}
 
/**
 * Represents the results of a SPARQL query that returns bindings.
 */
export interface BindingsResult {
	/**
	 * The type of the result, which is always 'bindings' for SELECT queries.
	 */
	type: 'bindings';
 
	/**
	 * The column headers of the result table.
	 */
	columns: string[];
 
	/**
	 * The rows of the result table containing the data.
	 */
	rows: Record<string, Term>[];
 
	/**
	 * A map of namespace IRIs to prefixes defined in the document or the workspace.
	 */
	namespaceMap: PrefixMap;
}
 
export interface BooleanResult {
	/**
	 * The type of the result, which is always 'boolean' for ASK queries.
	 */
	type: 'boolean';
 
	/**
	 * Boolean result value for ASK queries.
	 */
	value: boolean;
}
 
export interface QuadsResult {
	/**
	 * The type of the result, which is always 'quads' for CONSTRUCT or DESCRIBE queries.
	 */
	type: 'quads';
 
	/**
	 * The returned RDF document in the given serialization format.
	 */
	document: string;
 
	/**
	 * The MIME type of the returned document.
	 */
	mimeType: string;
}