Skip to content

Commit

Permalink
add makePublic/private, archive and unarchive
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed Feb 15, 2024
1 parent 8a1143b commit d502e6a
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/api/query.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -73,4 +76,56 @@ export class QueryAPI extends Router {
// throw new DuneError(responseJson, "UpdateQueryResponse", err);
}
}

public async archiveQuery(queryId: number): Promise<boolean> {
const responseJson = await this._post<EditQueryResponse>(`/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<boolean> {
const responseJson = await this._post<EditQueryResponse>(
`/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<void> {
const responseJson = await this._post<EditQueryResponse>(`/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<void> {
const responseJson = await this._post<EditQueryResponse>(
`/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);
}
}
}

0 comments on commit d502e6a

Please sign in to comment.