Skip to content

Commit

Permalink
feat: add export namespace table sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
EiffelFly committed Feb 13, 2025
1 parent 4355324 commit 870515f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "instill-sdk",
"version": "0.14.0-rc.31",
"version": "0.14.0-rc.33",
"description": "Instill AI's Typescript SDK",
"repository": "https://github.com/instill-ai/typescript-sdk.git",
"bugs": "https://github.com/instill-ai/community/issues",
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/src/chat/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./ChatClient";
export * from "./types";
export * from "./constant";
19 changes: 19 additions & 0 deletions packages/sdk/src/table/TableClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
CreateNamespaceTableRowResponse,
DeleteNamespaceTableRequest,
DeleteNamespaceTableRowRequest,
ExportNamespaceTableRequest,
ExportNamespaceTableResponse,
GetNamespaceTableColumnDefinitionsRequest,
GetNamespaceTableColumnDefinitionsResponse,
GetNamespaceTableRequest,
Expand Down Expand Up @@ -348,4 +350,21 @@ export class TableClient extends APIResource {
return Promise.reject(error);
}
}

async exportNamespaceTable(props: ExportNamespaceTableRequest) {
const { namespaceId, tableUid, format } = props;

try {
const data = await this._client.post<ExportNamespaceTableResponse>(
`/namespaces/${namespaceId}/tables/${tableUid}/export`,
{
body: JSON.stringify({ format }),
},
);

return Promise.resolve(data);
} catch (error) {
return Promise.reject(error);
}
}
}
15 changes: 15 additions & 0 deletions packages/sdk/src/table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,18 @@ export type MoveNamespaceTableRowRequest = {
rowUids: string[];
beforeRowUid?: string;
};

export type ExportFormat =
| "EXPORT_FORMAT_UNSPECIFIED"
| "EXPORT_FORMAT_CSV"
| "EXPORT_FORMAT_PARQUET";

export type ExportNamespaceTableRequest = {
namespaceId: string;
tableUid: string;
format: ExportFormat;
};

export type ExportNamespaceTableResponse = {
data: string;
};
2 changes: 1 addition & 1 deletion packages/toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@instill-ai/toolkit",
"version": "0.116.0-rc.26",
"version": "0.116.0-rc.28",
"description": "Instill AI's frontend toolkit",
"repository": "https://github.com/instill-ai/design-system.git",
"bugs": "https://github.com/instill-ai/design-system/issues",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./useCreateNamespaceTable";
export * from "./useCreateNamespaceTableRow";
export * from "./useDeleteNamespaceTable";
export * from "./useDeleteNamespaceTableRow";
export * from "./useExportNamespaceTable";
export * from "./useGetNamespaceTable";
export * from "./useGetNamespaceTableColumnDefinitions";
export * from "./useListNamespaceTableRows";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";

import type { ExportNamespaceTableRequest, Nullable } from "instill-sdk";
import { useMutation } from "@tanstack/react-query";

import { getInstillCatalogAPIClient } from "../../sdk-helper";

export function useExportNamespaceTable() {
return useMutation({
mutationFn: async ({
payload,
accessToken,
}: {
payload: ExportNamespaceTableRequest;
accessToken: Nullable<string>;
}) => {
if (!accessToken) {
throw new Error("accessToken is required");
}

if (!payload.namespaceId) {
throw new Error("namespaceId is required");
}

if (!payload.tableUid) {
throw new Error("tableUid is required");
}

const client = getInstillCatalogAPIClient({ accessToken });
await client.table.exportNamespaceTable(payload);
},
});
}

0 comments on commit 870515f

Please sign in to comment.