From 9b04a6d42025c9a4664fc175bd82eaf1ddbab501 Mon Sep 17 00:00:00 2001 From: Roni Choudhury Date: Wed, 18 Nov 2020 13:56:33 -0500 Subject: [PATCH 1/2] Add column typing argument to upload function --- src/index.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 4c83f69..d20a6ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -75,11 +75,16 @@ export type EdgesOptionsSpec = OffsetLimitSpec & { direction?: Direction; }; +export type ColumnType = 'number' | 'label' | 'category' | 'date' | 'boolean'; + export interface FileUploadOptionsSpec { type: UploadType; data: string | File; key?: string; overwrite?: boolean; + columnTypes?: { + [key: string]: ColumnType; + }; } export interface CreateGraphOptionsSpec { @@ -189,7 +194,7 @@ class MultinetAPI { ): Promise> { const headers = config ? config.headers : undefined; const params = config ? config.params : undefined; - const { type, data, key, overwrite } = options; + const { type, data, key, overwrite, columnTypes } = options; let text; @@ -199,6 +204,20 @@ class MultinetAPI { text = await fileToText(data); } + let metadata; + if (columnTypes) { + const columns = Object.keys(columnTypes).map((column) => ({ + key: column, + type: columnTypes[column], + })); + + metadata = metadata || {}; + metadata = { + ...metadata, + columns, + }; + } + return this.client.post(`/${type}/${workspace}/${table}`, text, { ...config, headers: { ...headers, 'Content-Type': 'text/plain' }, @@ -206,6 +225,7 @@ class MultinetAPI { ...params, key: key || undefined, overwrite: overwrite || undefined, + metadata: metadata || undefined, }, }); } From c374bb0fe2970c91301e1fcf3aa25d86e653b8ec Mon Sep 17 00:00:00 2001 From: Roni Choudhury <2903332+waxlamp@users.noreply.github.com> Date: Fri, 20 Nov 2020 13:23:54 -0500 Subject: [PATCH 2/2] Simplify logic for forming `metadata` object Co-authored-by: Jacob Nesbitt --- src/index.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index d20a6ba..3813de5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -211,11 +211,7 @@ class MultinetAPI { type: columnTypes[column], })); - metadata = metadata || {}; - metadata = { - ...metadata, - columns, - }; + metadata = { columns }; } return this.client.post(`/${type}/${workspace}/${table}`, text, {