diff --git a/src/api/query.ts b/src/api/query.ts index d06e729..6c71481 100644 --- a/src/api/query.ts +++ b/src/api/query.ts @@ -1,8 +1,11 @@ // Assuming the existence of these imports based on your Python code import { Router } from "./router"; -import { DuneQuery, QueryParameter, CreateQueryResponse } from "../types"; +import { DuneQuery, QueryParameter, CreateQueryResponse, DuneError } from "../types"; import { CreateQueryPayload, UpdateQueryPayload } from "../types/requestPayload"; +interface EditQueryResponse { + query_id: number; +} export class QueryAPI extends Router { /** * Creates a Dune Query by ID @@ -73,4 +76,56 @@ export class QueryAPI extends Router { // throw new DuneError(responseJson, "UpdateQueryResponse", err); } } + + public async archiveQuery(queryId: number): Promise { + const responseJson = await this._post(`/query/${queryId}/archive`); + try { + const query = await this.getQuery(responseJson.query_id); + return query.is_archived; + } catch (err: any) { + throw new DuneError("ArchiveQueryResponse"); + // throw new DuneError(responseJson, "ArchiveQueryResponse", err); + } + } + + public async unarchiveQuery(queryId: number): Promise { + const responseJson = await this._post( + `/query/${queryId}/unarchive`, + ); + try { + const query = await this.getQuery(responseJson.query_id); + return query.is_archived; + } catch (err: any) { + throw new DuneError("UnarchiveQueryResponse"); + // throw new DuneError(responseJson, "UnarchiveQueryResponse", err); + } + } + + public async makePrivate(queryId: number): Promise { + const responseJson = await this._post(`/query/${queryId}/private`); + try { + const query = await this.getQuery(responseJson.query_id); + if (!query.is_private) { + throw new DuneError("Query was not made private!"); + } + } catch (err: any) { + throw new DuneError("MakePrivateResponse"); + // throw new DuneError(responseJson, "MakePrivateResponse", err); + } + } + + public async makePublic(queryId: number): Promise { + const responseJson = await this._post( + `/query/${queryId}/unprivate`, + ); + try { + const query = await this.getQuery(responseJson.query_id); + if (query.is_private) { + throw new DuneError("Query is still private."); + } + } catch (err: any) { + throw new DuneError("MakePublicResponse"); + // throw new DuneError(responseJson, "MakePublicResponse", err); + } + } }