From e7b5794e813c6a32418e77e8a203b1b6ee28cc8c Mon Sep 17 00:00:00 2001 From: Roni Choudhury Date: Thu, 3 Dec 2020 10:13:49 -0500 Subject: [PATCH] Add methods for retrieving table metadata and column types --- src/index.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/index.ts b/src/index.ts index 3813de5..81ffbb6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -77,6 +77,21 @@ export type EdgesOptionsSpec = OffsetLimitSpec & { export type ColumnType = 'number' | 'label' | 'category' | 'date' | 'boolean'; +export interface ColumnTypesEntry { + key: string; + type: ColumnType; +} + +export interface ColumnTypes { + [key: string]: ColumnType; +} + +export interface TableMetadata { + table: { + columns: ColumnTypesEntry[]; + }; +} + export interface FileUploadOptionsSpec { type: UploadType; data: string | File; @@ -234,6 +249,20 @@ class MultinetAPI { return this.client.delete(`/workspaces/${workspace}/tables/${table}`); } + public tableMetadata(workspace: string, table: string): Promise { + return this.client.get(`/workspaces/${workspace}/tables/${table}/metadata`); + } + + public async tableColumnTypes(workspace: string, table: string): Promise { + const metadata = await this.tableMetadata(workspace, table); + + const types: ColumnTypes = {}; + metadata.table.columns.forEach((entry) => { + types[entry.key] = entry.type; + }); + return types; + } + public createGraph(workspace: string, graph: string, options: CreateGraphOptionsSpec): Promise { return this.client.post(`/workspaces/${workspace}/graphs/${graph}`, { edge_table: options.edgeTable,