|
| 1 | +import { |
| 2 | + LocalQueryInfo, |
| 3 | + CompletedQueryInfo, |
| 4 | + InitialQueryInfo, |
| 5 | +} from "../../query-results"; |
| 6 | +import { QueryEvaluationInfo } from "../../run-queries-shared"; |
| 7 | +import { QueryHistoryInfo } from "../query-history-info"; |
| 8 | +import { VariantAnalysisHistoryItem } from "../variant-analysis-history-item"; |
| 9 | +import { |
| 10 | + CompletedQueryInfoData, |
| 11 | + QueryEvaluationInfoData, |
| 12 | + InitialQueryInfoData, |
| 13 | + LocalQueryDataItem, |
| 14 | +} from "./local-query-data-item"; |
| 15 | +import { QueryHistoryDataItem } from "./query-history-data"; |
| 16 | + |
| 17 | +// Maps Query History Data Models to Domain Models |
| 18 | + |
| 19 | +export function mapQueryHistoryToDomainModels( |
| 20 | + queries: QueryHistoryDataItem[], |
| 21 | +): QueryHistoryInfo[] { |
| 22 | + return queries.map((d) => { |
| 23 | + if (d.t === "variant-analysis") { |
| 24 | + const query: VariantAnalysisHistoryItem = d; |
| 25 | + return query; |
| 26 | + } else if (d.t === "local") { |
| 27 | + return mapLocalQueryDataItemToDomainModel(d); |
| 28 | + } |
| 29 | + |
| 30 | + throw Error( |
| 31 | + `Unexpected or corrupted query history file. Unknown query history item: ${JSON.stringify( |
| 32 | + d, |
| 33 | + )}`, |
| 34 | + ); |
| 35 | + }); |
| 36 | +} |
| 37 | + |
| 38 | +function mapLocalQueryDataItemToDomainModel( |
| 39 | + localQuery: LocalQueryDataItem, |
| 40 | +): LocalQueryInfo { |
| 41 | + return new LocalQueryInfo( |
| 42 | + mapInitialQueryInfoDataToDomainModel(localQuery.initialInfo), |
| 43 | + undefined, |
| 44 | + localQuery.failureReason, |
| 45 | + localQuery.completedQuery && |
| 46 | + mapCompletedQueryInfoDataToDomainModel(localQuery.completedQuery), |
| 47 | + localQuery.evalLogLocation, |
| 48 | + localQuery.evalLogSummaryLocation, |
| 49 | + localQuery.jsonEvalLogSummaryLocation, |
| 50 | + localQuery.evalLogSummarySymbolsLocation, |
| 51 | + ); |
| 52 | +} |
| 53 | + |
| 54 | +function mapCompletedQueryInfoDataToDomainModel( |
| 55 | + completedQuery: CompletedQueryInfoData, |
| 56 | +): CompletedQueryInfo { |
| 57 | + return new CompletedQueryInfo( |
| 58 | + mapQueryEvaluationInfoDataToDomainModel(completedQuery.query), |
| 59 | + { |
| 60 | + runId: completedQuery.result.runId, |
| 61 | + queryId: completedQuery.result.queryId, |
| 62 | + resultType: completedQuery.result.resultType, |
| 63 | + evaluationTime: completedQuery.result.evaluationTime, |
| 64 | + message: completedQuery.result.message, |
| 65 | + logFileLocation: completedQuery.result.logFileLocation, |
| 66 | + }, |
| 67 | + completedQuery.logFileLocation, |
| 68 | + completedQuery.successful ?? completedQuery.sucessful, |
| 69 | + completedQuery.message, |
| 70 | + completedQuery.interpretedResultsSortState, |
| 71 | + completedQuery.resultCount, |
| 72 | + completedQuery.sortedResultsInfo, |
| 73 | + ); |
| 74 | +} |
| 75 | + |
| 76 | +function mapInitialQueryInfoDataToDomainModel( |
| 77 | + initialInfo: InitialQueryInfoData, |
| 78 | +): InitialQueryInfo { |
| 79 | + return { |
| 80 | + userSpecifiedLabel: initialInfo.userSpecifiedLabel, |
| 81 | + queryText: initialInfo.queryText, |
| 82 | + isQuickQuery: initialInfo.isQuickQuery, |
| 83 | + isQuickEval: initialInfo.isQuickEval, |
| 84 | + quickEvalPosition: initialInfo.quickEvalPosition, |
| 85 | + queryPath: initialInfo.queryPath, |
| 86 | + databaseInfo: { |
| 87 | + databaseUri: initialInfo.databaseInfo.databaseUri, |
| 88 | + name: initialInfo.databaseInfo.name, |
| 89 | + }, |
| 90 | + start: new Date(initialInfo.start), |
| 91 | + id: initialInfo.id, |
| 92 | + }; |
| 93 | +} |
| 94 | + |
| 95 | +function mapQueryEvaluationInfoDataToDomainModel( |
| 96 | + evaluationInfo: QueryEvaluationInfoData, |
| 97 | +): QueryEvaluationInfo { |
| 98 | + return new QueryEvaluationInfo( |
| 99 | + evaluationInfo.querySaveDir, |
| 100 | + evaluationInfo.dbItemPath, |
| 101 | + evaluationInfo.databaseHasMetadataFile, |
| 102 | + evaluationInfo.quickEvalPosition, |
| 103 | + evaluationInfo.metadata, |
| 104 | + ); |
| 105 | +} |
0 commit comments