@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
297 lines (296 loc) • 23.4 kB
TypeScript
import { type CallContextQuery } from './catalog/call-context-query/call-context-query-format';
import type { BaseQueryFormat, BaseQueryResult, BasicQueryData } from './base-query-format';
import { type VirtualQueryArgumentsWithType } from './virtual-query/virtual-queries';
import type { VirtualCompoundConstraint } from './virtual-query/compound-query';
import { type DataflowQuery } from './catalog/dataflow-query/dataflow-query-format';
import { type IdMapQuery } from './catalog/id-map-query/id-map-query-format';
import { type NormalizedAstQuery } from './catalog/normalized-ast-query/normalized-ast-query-format';
import { type StaticSliceQuery } from './catalog/static-slice-query/static-slice-query-format';
import { type DataflowClusterQuery } from './catalog/cluster-query/cluster-query-format';
import { type DependenciesQuery } from './catalog/dependencies-query/dependencies-query-format';
import type { OutputFormatter } from '../util/text/ansi';
import Joi from 'joi';
import { type LocationMapQuery } from './catalog/location-map-query/location-map-query-format';
import { type ConfigQuery } from './catalog/config-query/config-query-format';
import { type SearchQuery } from './catalog/search-query/search-query-format';
import { type HappensBeforeQuery } from './catalog/happens-before-query/happens-before-query-format';
import { type ResolveValueQuery } from './catalog/resolve-value-query/resolve-value-query-format';
import { type DataflowLensQuery } from './catalog/dataflow-lens-query/dataflow-lens-query-format';
import { type ProjectQuery } from './catalog/project-query/project-query-format';
import { type OriginQuery } from './catalog/origin-query/origin-query-format';
import { type LinterQuery } from './catalog/linter-query/linter-query-format';
import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
import { type ControlFlowQuery } from './catalog/control-flow-query/control-flow-query-format';
import { type DfShapeQuery } from './catalog/df-shape-query/df-shape-query-format';
import type { AsyncOrSync } from 'ts-essentials';
import type { FlowrConfig } from '../config';
import { type InspectHigherOrderQuery } from './catalog/inspect-higher-order-query/inspect-higher-order-query-format';
import type { ReadonlyFlowrAnalysisProvider } from '../project/flowr-analyzer';
import type { ReplOutput } from '../cli/repl/commands/repl-main';
import type { CommandCompletions } from '../cli/repl/core';
import type { FilesQuery } from './catalog/files-query/files-query-format';
import type { CallGraphQuery } from './catalog/call-graph-query/call-graph-query-format';
import type { InspectRecursionQuery } from './catalog/inspect-recursion-query/inspect-recursion-query-format';
import type { DoesCallQuery } from './catalog/does-call-query/does-call-query-format';
import type { InspectExceptionQuery } from './catalog/inspect-exceptions-query/inspect-exception-query-format';
import type { InputSourcesQuery } from './catalog/input-sources-query/input-sources-query-format';
import type { ProvenanceQuery } from './catalog/provenance-query/provenance-query-format';
/**
* These are all queries that can be executed from within flowR
*/
export type Query = CallContextQuery | ConfigQuery | SearchQuery | DataflowQuery | DoesCallQuery | CallGraphQuery | ControlFlowQuery | DataflowLensQuery | FilesQuery | DfShapeQuery | NormalizedAstQuery | IdMapQuery | DataflowClusterQuery | StaticSliceQuery | DependenciesQuery | LocationMapQuery | HappensBeforeQuery | InspectExceptionQuery | InspectHigherOrderQuery | InspectRecursionQuery | ResolveValueQuery | ProjectQuery | OriginQuery | LinterQuery | ProvenanceQuery | InputSourcesQuery;
export type QueryArgumentsWithType<QueryType extends BaseQueryFormat['type']> = Query & {
type: QueryType;
};
export type QueryExecutor<Query extends BaseQueryFormat, Result extends Promise<BaseQueryResult>> = (data: BasicQueryData, query: readonly Query[]) => Result;
/**
* The result of parsing a query line from, e.g., the repl.
*/
export interface ParsedQueryLine<QueryType extends BaseQueryFormat['type']> {
/** The parsed query or queries from the line. */
query: QueryArgumentsWithType<QueryType> | QueryArgumentsWithType<QueryType>[] | undefined;
/** Optional R code associated with the query. */
rCode?: string;
}
export interface SupportedQuery<QueryType extends BaseQueryFormat['type'] = BaseQueryFormat['type']> {
executor: QueryExecutor<QueryArgumentsWithType<QueryType>, Promise<BaseQueryResult>>;
/** optional completion in, e.g., the repl */
completer?: (splitLine: readonly string[], startingNewArg: boolean, config: FlowrConfig) => CommandCompletions;
/** optional query construction from an, e.g., repl line */
fromLine?: (output: ReplOutput, splitLine: readonly string[], config: FlowrConfig) => ParsedQueryLine<QueryType>;
/**
* Generates an ASCII summary of the query result to be printed in, e.g., the REPL.
* @returns whether a summary was produced (`true` if so, `false` if not, in this case a default/generic summary will be created)
*/
asciiSummarizer: (formatter: OutputFormatter, analyzer: ReadonlyFlowrAnalysisProvider, queryResults: BaseQueryResult, resultStrings: string[], query: readonly Query[]) => AsyncOrSync<boolean>;
jsonFormatter?: (queryResults: BaseQueryResult) => object;
schema: Joi.ObjectSchema;
/**
* Flattens the involved query nodes to be added to a flowR search when the {@link fromQuery} function is used based on the given result after this query is executed.
* If this query does not involve any nodes, an empty array can be returned.
*/
flattenInvolvedNodes: (queryResults: BaseQueryResult, query: readonly Query[]) => NodeId[];
}
export declare const SupportedQueries: {
readonly 'call-context': {
readonly executor: typeof import("./catalog/call-context-query/call-context-query-executor").executeCallContextQueries;
readonly asciiSummarizer: (formatter: OutputFormatter, analyzer: ReadonlyFlowrAnalysisProvider, queryResults: BaseQueryResult, result: string[]) => Promise<boolean>;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly config: {
readonly executor: typeof import("./catalog/config-query/config-query-executor").executeConfigQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: unknown, queryResults: BaseQueryResult, result: string[], queries: readonly Query[]) => true;
readonly completer: (partialLine: readonly string[], _startingNewArg: boolean, config: FlowrConfig) => CommandCompletions;
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"config">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: () => never[];
};
readonly 'control-flow': {
readonly executor: typeof import("./catalog/control-flow-query/control-flow-query-executor").executeControlFlowQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => Promise<boolean>;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly 'call-graph': {
readonly executor: typeof import("./catalog/call-graph-query/call-graph-query-executor").executeCallGraphQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly dataflow: {
readonly executor: typeof import("./catalog/dataflow-query/dataflow-query-executor").executeDataflowQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly 'does-call': {
readonly executor: typeof import("./catalog/does-call-query/does-call-query-executor").executeDoesCallQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, processed: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => Promise<boolean>;
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"does-call">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly 'dataflow-lens': {
readonly executor: typeof import("./catalog/dataflow-lens-query/dataflow-lens-query-executor").executeDataflowLensQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: () => never[];
};
readonly 'df-shape': {
readonly executor: typeof import("./catalog/df-shape-query/df-shape-query-executor").executeDfShapeQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly jsonFormatter: (queryResults: BaseQueryResult) => object;
readonly fromLine: (_output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"df-shape">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: () => never[];
};
readonly files: {
readonly executor: typeof import("./catalog/files-query/files-query-executor").executeFileQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly completer: (line: readonly string[], startingNewArg: boolean, _config: FlowrConfig) => CommandCompletions;
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"files">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (_: BaseQueryResult) => NodeId[];
};
readonly 'id-map': {
readonly executor: typeof import("./catalog/id-map-query/id-map-query-executor").executeIdMapQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: () => never[];
};
readonly 'normalized-ast': {
readonly executor: typeof import("./catalog/normalized-ast-query/normalized-ast-query-executor").executeNormalizedAstQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: () => never[];
};
readonly 'dataflow-cluster': {
readonly executor: typeof import("./catalog/cluster-query/cluster-query-executor").executeDataflowClusterQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => Promise<boolean>;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly 'static-slice': {
readonly executor: typeof import("./catalog/static-slice-query/static-slice-query-executor").executeStaticSliceQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"static-slice">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly provenance: {
readonly executor: typeof import("./catalog/provenance-query/provenance-query-executor").executeProvenanceQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => Promise<boolean>;
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"provenance">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly 'input-sources': {
readonly executor: typeof import("./catalog/input-sources-query/input-sources-query-executor").executeInputSourcesQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => Promise<boolean>;
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"input-sources">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly dependencies: {
readonly executor: typeof import("./catalog/dependencies-query/dependencies-query-executor").executeDependenciesQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[], queries: readonly Query[]) => true;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult, query: readonly Query[]) => NodeId[];
};
readonly 'location-map': {
readonly executor: typeof import("./catalog/location-map-query/location-map-query-executor").executeLocationMapQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: unknown, queryResults: BaseQueryResult, result: string[]) => true;
readonly fromLine: (_output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"location-map">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: () => never[];
};
readonly search: {
readonly executor: typeof import("./catalog/search-query/search-query-executor").executeSearch;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly 'happens-before': {
readonly executor: typeof import("./catalog/happens-before-query/happens-before-query-executor").executeHappensBefore;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: () => never[];
};
readonly 'inspect-exception': {
readonly executor: typeof import("./catalog/inspect-exceptions-query/inspect-exception-query-executor").executeExceptionQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, processed: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => Promise<boolean>;
readonly fromLine: (_output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"inspect-exception">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly 'inspect-higher-order': {
readonly executor: typeof import("./catalog/inspect-higher-order-query/inspect-higher-order-query-executor").executeHigherOrderQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, processed: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => Promise<boolean>;
readonly fromLine: (_output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"inspect-higher-order">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly 'inspect-recursion': {
readonly executor: typeof import("./catalog/inspect-recursion-query/inspect-recursion-query-executor").executeRecursionQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, processed: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => Promise<boolean>;
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"inspect-recursion">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly 'resolve-value': {
readonly executor: typeof import("./catalog/resolve-value-query/resolve-value-query-executor").executeResolveValueQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"resolve-value">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: () => never[];
};
readonly project: {
readonly executor: typeof import("./catalog/project-query/project-query-executor").executeProjectQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: () => never[];
};
readonly origin: {
readonly executor: typeof import("./catalog/origin-query/origin-query-executor").executeResolveValueQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"origin">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
};
readonly linter: {
readonly executor: typeof import("./catalog/linter-query/linter-query-executor").executeLinterQuery;
readonly asciiSummarizer: (formatter: OutputFormatter, analyzer: ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
readonly completer: (line: readonly string[], startingNewArg: boolean, _config: FlowrConfig) => CommandCompletions;
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"linter">;
readonly schema: Joi.ObjectSchema<any>;
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => ((string & {
__brand?: "node-id";
}) | (number & {
__brand?: "node-id";
}))[];
};
};
export type SupportedQueryTypes = keyof typeof SupportedQueries;
export type QueryResult<Type extends Query['type']> = Promise<ReturnType<typeof SupportedQueries[Type]['executor']>>;
/**
* Executes a set of queries that are all of the same type.
* Only use this function if you are sure all queries are of the same type.
* Otherwise, use {@link executeQueries}.
*/
export declare function executeQueriesOfSameType<SpecificQuery extends Query>(data: BasicQueryData, queries: readonly SpecificQuery[]): QueryResult<SpecificQuery['type']>;
export type QueryResults<Base extends SupportedQueryTypes = SupportedQueryTypes> = {
readonly [QueryType in Base]: Awaited<QueryResult<QueryType>>;
} & BaseQueryResult;
type OmitFromValues<T, K extends string | number | symbol> = {
[P in keyof T]?: Omit<T[P], K>;
};
export type QueryResultsWithoutMeta<Queries extends Query> = OmitFromValues<Omit<QueryResults<Queries['type']>, '.meta'>, '.meta'>;
export type Queries<Base extends SupportedQueryTypes = SupportedQueryTypes, VirtualArguments extends VirtualCompoundConstraint<Base> = VirtualCompoundConstraint<Base>> = readonly (QueryArgumentsWithType<Base> | VirtualQueryArgumentsWithType<Base, VirtualArguments>)[];
/**
* This is the main query execution function that takes a set of queries and executes them on the given data.
* @see {@link executeQueriesOfSameType}
*/
export declare function executeQueries<Base extends SupportedQueryTypes, VirtualArguments extends VirtualCompoundConstraint<Base> = VirtualCompoundConstraint<Base>>(data: BasicQueryData, queries: Queries<Base, VirtualArguments>): Promise<QueryResults<Base>>;
/**
* Produces a Joi schema representing all supported queries.
*/
export declare function SupportedQueriesSchema(): Joi.AlternativesSchema<any>;
export declare const CompoundQuerySchema: Joi.ObjectSchema<any>;
/**
* Produces a Joi schema representing all virtual queries.
*/
export declare function VirtualQuerySchema(): Joi.AlternativesSchema<any>;
/**
* Produces a Joi schema representing any supported query (including virtual queries).
*/
export declare function AnyQuerySchema(): Joi.AlternativesSchema<any>;
/**
* Produces a Joi schema representing an array of supported queries.
*/
export declare function QueriesSchema(): Joi.ArraySchema<any[]>;
/**
* Wraps a function that executes a REPL query and, if it fails, checks whether there were any requests to analyze.
*/
export declare function genericWrapReplFailIfNoRequest<T>(fn: () => Promise<T>, output: ReplOutput, analyzer: ReadonlyFlowrAnalysisProvider): Promise<T | undefined>;
export {};