Add cli bqrs -types

This commit is contained in:
alexet
2019-10-16 16:56:01 +01:00
committed by Jason Reed
parent 8d9a470208
commit fd728202ed
2 changed files with 118 additions and 8 deletions

View File

@@ -0,0 +1,79 @@
export const PAGE_SIZE = 1000;
export type ColumnKind = "f" | "i" | "s" | "b" | "d" | "e";
export interface Column {
name?: string,
kind: ColumnKind,
}
export interface ResultSetSchema {
name: string,
rows: number,
columns: Column[],
pagination?: PaginationInfo,
}
export function getResultSetSchema(resultSetName: string, resultSets: BQRSInfo): ResultSetSchema | undefined {
for (const schema of resultSets["result-sets"]) {
if (schema.name === resultSetName) {
return schema;
}
}
return undefined;
}
export interface PaginationInfo {
"step-size": number,
offsets: number[],
}
export interface BQRSInfo {
"result-sets": ResultSetSchema[]
}
export interface EntityValue {
url?: UrlValue,
label?: string
}
export interface LineColumnLocation {
uri: string
startLine: number,
startColumn: number,
endLine: number,
endColumn: number,
charOffset: never
charLength: never
}
export interface OffsetLengthLocation {
uri: string,
startLine: never,
startColumn: never,
endLine: never,
endColumn: never,
charOffset: number,
charLength: number,
}
export interface WholeFileLocation {
uri: string,
startLine: undefined,
startColumn: undefined,
endLine: undefined,
endColumn: undefined,
charOffset: undefined,
charLength: undefined,
}
export type UrlValue = LineColumnLocation | OffsetLengthLocation | WholeFileLocation | string;
export type ColumnValue = EntityValue | number | string | boolean;
export interface DecodedBqrsChunk {
tuples: ColumnValue[][],
next?: number
}

View File

@@ -1,17 +1,18 @@
import * as child_process from 'child_process';
import * as cpp from 'child-process-promise';
import * as child_process from 'child_process';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as sarif from 'sarif';
import * as tk from 'tree-kill';
import * as util from 'util';
import { SortDirection, QueryMetadata } from './interface-types';
import { Logger, ProgressReporter } from './logging';
import { Disposable, CancellationToken } from 'vscode';
import { DistributionProvider } from './distribution';
import { assertNever } from './helpers-pure';
import { Readable } from 'stream';
import { StringDecoder } from 'string_decoder';
import * as tk from 'tree-kill';
import * as util from 'util';
import { CancellationToken, Disposable } from 'vscode';
import { BQRSInfo, DecodedBqrsChunk } from "./bqrs-cli-types";
import { DistributionProvider } from './distribution';
import { assertNever } from './helpers-pure';
import { QueryMetadata, SortDirection } from './interface-types';
import { Logger, ProgressReporter } from './logging';
/**
* The version of the SARIF format that we are using.
@@ -471,6 +472,36 @@ export class CodeQLCliServer implements Disposable {
}
return await this.runJsonCodeQlCliCommand<string[]>(['resolve', 'ram'], args, "Resolving RAM settings", progressReporter);
}
/**
* Gets the headers (and optionally pagination info) of a bqrs.
* @param config The configuration containing the path to the CLI.
* @param bqrsPath The path to the vqrs.
*/
async bqrsInfo(bqrsPath: string, pageSize?: number): Promise<BQRSInfo> {
const subcommandArgs = (
pageSize ? ["--paginate-rows", pageSize.toString()] : []
).concat(
bqrsPath
);
return await this.runJsonCodeQlCliCommand<BQRSInfo>(['bqrs', 'info'], subcommandArgs, "Reading bqrs header");
}
/**
* Gets the results from a bqrs.
* @param config The configuration containing the path to the CLI.
* @param bqrsPath The path to the bqrs.
*/
async bqrsDecode(bqrsPath: string, resultSet: string, pageSize?: number, offset?: number): Promise<DecodedBqrsChunk> {
const subcommandArgs = [
"--entities=url,string",
"--result-set", resultSet,
].concat(
pageSize ? ["--rows", pageSize.toString()] : []
).concat(
offset ? ["--start-at", offset.toString()] : []
).concat([bqrsPath]);
return await this.runJsonCodeQlCliCommand<DecodedBqrsChunk>(['bqrs', 'decode'], subcommandArgs, "Reading bqrs data");
}
async interpretBqrs(metadata: { kind: string, id: string }, resultsPath: string, interpretedResultsPath: string, sourceInfo?: SourceInfo): Promise<sarif.Log> {