|
| 1 | +/** |
| 2 | + * Types for messages exchanged during jsonrpc communication with the |
| 3 | + * the CodeQL query server. |
| 4 | + * |
| 5 | + * This file exists in the queryserver and in the vscode extension, and |
| 6 | + * should be kept in sync between them. |
| 7 | + * |
| 8 | + * A note about the namespaces below, which look like they are |
| 9 | + * essentially enums, namely Severity, ResultColumnKind, and |
| 10 | + * QueryResultType. By design, for the sake of extensibility, clients |
| 11 | + * receiving messages of this protocol are supposed to accept any |
| 12 | + * number for any of these types. We commit to the given meaning of |
| 13 | + * the numbers listed in constants in the namespaces, and we commit to |
| 14 | + * the fact that any unknown QueryResultType value counts as an error. |
| 15 | + */ |
| 16 | + |
| 17 | +import * as rpc from 'vscode-jsonrpc'; |
| 18 | +import * as shared from './messages-shared'; |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +/** |
| 23 | + * Parameters to clear the cache |
| 24 | + */ |
| 25 | +export interface ClearCacheParams { |
| 26 | + /** |
| 27 | + * The dataset for which we want to clear the cache |
| 28 | + */ |
| 29 | + db: string; |
| 30 | + /** |
| 31 | + * Whether the cache should actually be cleared. |
| 32 | + */ |
| 33 | + dryRun: boolean; |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * Parameters for trimming the cache of a dataset |
| 38 | + */ |
| 39 | +export interface TrimCacheParams { |
| 40 | + /** |
| 41 | + * The dataset that we want to trim the cache of. |
| 42 | + */ |
| 43 | + db: string; |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * The result of trimming or clearing the cache. |
| 48 | + */ |
| 49 | +export interface ClearCacheResult { |
| 50 | + /** |
| 51 | + * A user friendly message saying what was or would be |
| 52 | + * deleted. |
| 53 | + */ |
| 54 | + deletionMessage: string; |
| 55 | +} |
| 56 | + |
| 57 | + |
| 58 | +export type QueryResultType = number; |
| 59 | +/** |
| 60 | + * The result of running a query. This namespace is intentionally not |
| 61 | + * an enum, see "for the sake of extensibility" comment above. |
| 62 | + */ |
| 63 | +// eslint-disable-next-line @typescript-eslint/no-namespace |
| 64 | +export namespace QueryResultType { |
| 65 | + /** |
| 66 | + * The query ran successfully |
| 67 | + */ |
| 68 | + export const SUCCESS = 0; |
| 69 | + /** |
| 70 | + * The query failed due to an reason |
| 71 | + * that isn't listed |
| 72 | + */ |
| 73 | + export const OTHER_ERROR = 1; |
| 74 | + /** |
| 75 | + * The query failed do to compilation erorrs |
| 76 | + */ |
| 77 | + export const COMPILATION_ERROR = 2; |
| 78 | + /** |
| 79 | + * The query failed due to running out of |
| 80 | + * memory |
| 81 | + */ |
| 82 | + export const OOM = 3; |
| 83 | + /** |
| 84 | + * The query failed because it was cancelled. |
| 85 | + */ |
| 86 | + export const CANCELLATION = 4; |
| 87 | + /** |
| 88 | + * The dbscheme basename was not the same |
| 89 | + */ |
| 90 | + export const DBSCHEME_MISMATCH_NAME = 5; |
| 91 | + /** |
| 92 | + * No upgrade was found |
| 93 | + */ |
| 94 | + export const DBSCHEME_NO_UPGRADE = 6; |
| 95 | +} |
| 96 | + |
| 97 | + |
| 98 | +export interface RegisterDatabasesParams { |
| 99 | + databases: string[]; |
| 100 | +} |
| 101 | + |
| 102 | +export interface DeregisterDatabasesParams { |
| 103 | + databases: string[]; |
| 104 | +} |
| 105 | + |
| 106 | +export type RegisterDatabasesResult = { |
| 107 | + registeredDatabases: string[]; |
| 108 | +}; |
| 109 | + |
| 110 | +export type DeregisterDatabasesResult = { |
| 111 | + registeredDatabases: string[]; |
| 112 | +}; |
| 113 | + |
| 114 | + |
| 115 | +export interface RunQueryParams { |
| 116 | + /** |
| 117 | + * The path of the query |
| 118 | + */ |
| 119 | + queryPath: string, |
| 120 | + /** |
| 121 | + * The output path |
| 122 | + */ |
| 123 | + outputPath: string, |
| 124 | + /** |
| 125 | + * The database path |
| 126 | + */ |
| 127 | + db: string, |
| 128 | + additionalPacks: string[], |
| 129 | + target: CompilationTarget, |
| 130 | + externalInputs: Record<string, string>, |
| 131 | + singletonExternalInputs: Record<string, string>, |
| 132 | + dilPath?: string, |
| 133 | + logPath?: string |
| 134 | +} |
| 135 | + |
| 136 | +export interface RunQueryResult { |
| 137 | + resultType: QueryResultType, |
| 138 | + message?: string, |
| 139 | + expectedDbschemeName?: string, |
| 140 | + evaluationTime: number; |
| 141 | +} |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | +export interface UpgradeParams { |
| 146 | + db: string, |
| 147 | + additionalPacks: string[], |
| 148 | +} |
| 149 | + |
| 150 | +export type UpgradeResult = Record<string, unknown>; |
| 151 | + |
| 152 | +export type ClearPackCacheParams = Record<string, unknown>; |
| 153 | +export type ClearPackCacheResult = Record<string, unknown>; |
| 154 | + |
| 155 | +/** |
| 156 | + * A position within a QL file. |
| 157 | + */ |
| 158 | +export type Position = shared.Position; |
| 159 | + |
| 160 | +/** |
| 161 | + * The way of compiling the query, as a normal query |
| 162 | + * or a subset of it. Note that precisely one of the two options should be set. |
| 163 | + */ |
| 164 | +export type CompilationTarget = shared.CompilationTarget; |
| 165 | + |
| 166 | +export type QuickEvalOptions = shared.QuickEvalOptions; |
| 167 | + |
| 168 | +export type WithProgressId<T> = shared.WithProgressId<T>; |
| 169 | +export type ProgressMessage = shared.ProgressMessage; |
| 170 | + |
| 171 | +/** |
| 172 | + * Clear the cache of a dataset |
| 173 | + */ |
| 174 | +export const clearCache = new rpc.RequestType<WithProgressId<ClearCacheParams>, ClearCacheResult, void, void>('evaluation/clearCache'); |
| 175 | +/** |
| 176 | + * Trim the cache of a dataset |
| 177 | + */ |
| 178 | +export const trimCache = new rpc.RequestType<WithProgressId<TrimCacheParams>, ClearCacheResult, void, void>('evaluation/trimCache'); |
| 179 | + |
| 180 | +/** |
| 181 | + * Clear the pack cache |
| 182 | + */ |
| 183 | +export const clearPackCache = new rpc.RequestType<WithProgressId<ClearPackCacheParams>, ClearPackCacheResult, void, void>('evaluation/clearPackCache'); |
| 184 | + |
| 185 | +/** |
| 186 | + * Run a query on a database |
| 187 | + */ |
| 188 | +export const runQuery = new rpc.RequestType<WithProgressId<RunQueryParams>, RunQueryResult, void, void>('evaluation/runQuery'); |
| 189 | + |
| 190 | +export const registerDatabases = new rpc.RequestType< |
| 191 | + WithProgressId<RegisterDatabasesParams>, |
| 192 | + RegisterDatabasesResult, |
| 193 | + void, |
| 194 | + void |
| 195 | +>('evaluation/registerDatabases'); |
| 196 | + |
| 197 | +export const deregisterDatabases = new rpc.RequestType< |
| 198 | + WithProgressId<DeregisterDatabasesParams>, |
| 199 | + DeregisterDatabasesResult, |
| 200 | + void, |
| 201 | + void |
| 202 | +>('evaluation/deregisterDatabases'); |
| 203 | + |
| 204 | + |
| 205 | +export const upgradeDatabase = new rpc.RequestType< |
| 206 | + WithProgressId<UpgradeParams>, |
| 207 | + UpgradeResult, |
| 208 | + void, |
| 209 | + void |
| 210 | +>('evaluation/upgrade'); |
| 211 | + |
| 212 | +/** |
| 213 | + * A notification that the progress has been changed. |
| 214 | + */ |
| 215 | +export const progress = shared.progress; |
0 commit comments