-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the new table endpoints in the SDK: - https://docs.dune.com/api-reference/tables/endpoint/create - https://docs.dune.com/api-reference/tables/endpoint/insert Additionally `uploadCsv` was moved from client with the new endpoints into Table API to consolidate all table endpoints in one file. Skipped tests (that work) were added.
- Loading branch information
Showing
13 changed files
with
250 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Router } from "./router"; | ||
import { | ||
CreateTableResult, | ||
DuneError, | ||
SuccessResponse, | ||
UploadCSVArgs, | ||
CreateTableArgs, | ||
InsertTableArgs, | ||
InsertTableResult, | ||
} from "../types"; | ||
import { withDefaults } from "../utils"; | ||
|
||
/** | ||
* Table Management Interface (includes uploadCSV) | ||
* https://docs.dune.com/api-reference/tables/ | ||
*/ | ||
export class TableAPI extends Router { | ||
/** | ||
* Allows for anyone to upload a CSV as a table in Dune. | ||
* The size limit per upload is currently 200MB. | ||
* Storage is limited by plan, 1MB on free, 15GB on plus, and 50GB on premium. | ||
* | ||
* @param args UploadCSVParams relevant fields related to dataset upload. | ||
* @returns boolean representing if upload was successful. | ||
*/ | ||
async uploadCsv(args: UploadCSVArgs): Promise<boolean> { | ||
const response = await this.post<SuccessResponse>("table/upload/csv", args); | ||
try { | ||
return Boolean(response.success); | ||
} catch (err) { | ||
throw new DuneError(`UploadCsvResponse ${JSON.stringify(response)}`); | ||
} | ||
} | ||
|
||
/** | ||
* https://docs.dune.com/api-reference/tables/endpoint/create | ||
* The create table endpoint allows you to create an empty table | ||
* with a specific schema in Dune. | ||
* | ||
* The only limitations are: | ||
* - If a table already exists with the same name, the request will fail. | ||
* - Column names in the table can’t start with a special character or a digit. | ||
* @param args | ||
*/ | ||
async create(args: CreateTableArgs): Promise<CreateTableResult> { | ||
return this.post<CreateTableResult>( | ||
"table/create", | ||
withDefaults<CreateTableArgs>(args, { description: "", is_private: false }), | ||
); | ||
} | ||
|
||
/** | ||
* https://docs.dune.com/api-reference/tables/endpoint/insert | ||
* The insert table endpoint allows you to insert data into an existing table in Dune. | ||
* The only limitations are: | ||
* - The file has to be in json or csv format | ||
* - The file has to have the same schema as the table | ||
* @param args | ||
* @returns | ||
*/ | ||
async insert(args: InsertTableArgs): Promise<InsertTableResult> { | ||
return this.post<InsertTableResult>( | ||
`table/${args.namespace}/${args.table_name}/insert`, | ||
args.data, | ||
args.content_type, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from "./client"; | ||
export * from "./error"; | ||
export * from "./query"; | ||
export * from "./queryParameter"; | ||
export * from "./requestPayload"; | ||
export * from "./response"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.