From d5e446d1a5c036280b3fe4e97da0b2d6a25e3fc3 Mon Sep 17 00:00:00 2001 From: Jacob Nesbitt Date: Thu, 26 Mar 2020 12:06:57 -0400 Subject: [PATCH 1/7] Update client.post and uploadTable, aql functions --- src/client.ts | 6 +++--- src/index.ts | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/client.ts b/src/client.ts index 3bfc184..155926e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,4 +1,4 @@ -import axios, { AxiosInstance } from 'axios'; +import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; export class Client { public axios: AxiosInstance; @@ -21,9 +21,9 @@ export class Client { }); } - public post(path: string, params: {} = {}, headers: {} = {}): Promise { + public post(path: string, data: any = null, params: AxiosRequestConfig = {}): Promise { return new Promise((resolve, reject) => { - this.axios.post(path, params, { headers, }) + this.axios.post(path, data, params) .then((resp) => { resolve(resp.data); }) diff --git a/src/index.ts b/src/index.ts index 896d055..fe1342f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { Client } from './client'; -import { AxiosPromise } from 'axios'; +import { AxiosPromise, AxiosRequestConfig } from 'axios'; export interface TableRow { _key: string; @@ -142,7 +142,7 @@ class MultinetAPI { return this.client.axios.put(`workspaces/${workspace}/name`, null, { params: { name }}); } - public async uploadTable(workspace: string, table: string, options: FileUploadOptionsSpec): Promise> { + public async uploadTable(workspace: string, table: string, options: FileUploadOptionsSpec, params: AxiosRequestConfig = {}): Promise> { let text; if (typeof options.data === 'string') { text = options.data; @@ -151,7 +151,8 @@ class MultinetAPI { } return this.client.post(`/${options.type}/${workspace}/${table}`, text, { - 'Content-Type': 'text/plain', + headers: { 'Content-Type': 'text/plain' }, + ...params }); } @@ -174,7 +175,7 @@ class MultinetAPI { } public aql(workspace: string, query: string): Promise { - return this.client.post(`/workspaces/${workspace}/aql`, query, {'Content-Type': 'text/plain'}); + return this.client.post(`/workspaces/${workspace}/aql`, query, { headers: { 'Content-Type': 'text/plain' }}); } public downloadGraph(workspace: string, graph: string): AxiosPromise { From 461e032d359f0f23d32c1f6bf449f14afa1d6de1 Mon Sep 17 00:00:00 2001 From: Jacob Nesbitt Date: Thu, 26 Mar 2020 12:20:05 -0400 Subject: [PATCH 2/7] Fix linting errors --- src/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index fe1342f..053be1b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -139,10 +139,15 @@ class MultinetAPI { } public renameWorkspace(workspace: string, name: string): AxiosPromise { - return this.client.axios.put(`workspaces/${workspace}/name`, null, { params: { name }}); + return this.client.axios.put(`workspaces/${workspace}/name`, null, { params: { name } }); } - public async uploadTable(workspace: string, table: string, options: FileUploadOptionsSpec, params: AxiosRequestConfig = {}): Promise> { + public async uploadTable( + workspace: string, + table: string, + options: FileUploadOptionsSpec, + params: AxiosRequestConfig = {} + ): Promise> { let text; if (typeof options.data === 'string') { text = options.data; @@ -152,7 +157,7 @@ class MultinetAPI { return this.client.post(`/${options.type}/${workspace}/${table}`, text, { headers: { 'Content-Type': 'text/plain' }, - ...params + ...params, }); } @@ -175,7 +180,7 @@ class MultinetAPI { } public aql(workspace: string, query: string): Promise { - return this.client.post(`/workspaces/${workspace}/aql`, query, { headers: { 'Content-Type': 'text/plain' }}); + return this.client.post(`/workspaces/${workspace}/aql`, query, { headers: { 'Content-Type': 'text/plain' } }); } public downloadGraph(workspace: string, graph: string): AxiosPromise { From 12f8cafde8d82603b82a2b06064122bca843d5d9 Mon Sep 17 00:00:00 2001 From: Jacob Nesbitt Date: Thu, 26 Mar 2020 15:12:54 -0400 Subject: [PATCH 3/7] Repalce axios params object with specific options --- src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 053be1b..cc70710 100644 --- a/src/index.ts +++ b/src/index.ts @@ -146,7 +146,8 @@ class MultinetAPI { workspace: string, table: string, options: FileUploadOptionsSpec, - params: AxiosRequestConfig = {} + key?: string, + overwrite?: boolean, ): Promise> { let text; if (typeof options.data === 'string') { @@ -157,7 +158,10 @@ class MultinetAPI { return this.client.post(`/${options.type}/${workspace}/${table}`, text, { headers: { 'Content-Type': 'text/plain' }, - ...params, + params: { + key: key || undefined, + overwrite: overwrite || undefined, + } }); } From 4132d679c8cb65c6824113033a3ecdf2a2e46a96 Mon Sep 17 00:00:00 2001 From: Jacob Nesbitt Date: Fri, 27 Mar 2020 10:58:34 -0400 Subject: [PATCH 4/7] Move key and overwrite into FileUploadOptionsSpec Add object destructure --- src/index.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index cc70710..3fb62b7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,6 +60,8 @@ export type EdgesOptionsSpec = OffsetLimitSpec & { export interface FileUploadOptionsSpec { type: UploadType; data: string | File; + key?: string, + overwrite?: boolean; } export interface CreateGraphOptionsSpec { @@ -142,21 +144,17 @@ class MultinetAPI { return this.client.axios.put(`workspaces/${workspace}/name`, null, { params: { name } }); } - public async uploadTable( - workspace: string, - table: string, - options: FileUploadOptionsSpec, - key?: string, - overwrite?: boolean, - ): Promise> { + public async uploadTable(workspace: string, table: string, options: FileUploadOptionsSpec): Promise> { + const { type, data, key, overwrite } = options; let text; - if (typeof options.data === 'string') { - text = options.data; + + if (typeof data === 'string') { + text = data; } else { - text = await fileToText(options.data); + text = await fileToText(data); } - return this.client.post(`/${options.type}/${workspace}/${table}`, text, { + return this.client.post(`/${type}/${workspace}/${table}`, text, { headers: { 'Content-Type': 'text/plain' }, params: { key: key || undefined, From 04ed29555d0e682b16877031d61b625f103efa81 Mon Sep 17 00:00:00 2001 From: Jacob Nesbitt Date: Fri, 27 Mar 2020 11:43:07 -0400 Subject: [PATCH 5/7] Fix comma in interface --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 3fb62b7..8c8eba7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,7 +60,7 @@ export type EdgesOptionsSpec = OffsetLimitSpec & { export interface FileUploadOptionsSpec { type: UploadType; data: string | File; - key?: string, + key?: string; overwrite?: boolean; } From 2f87af8c8fcc832dc1aa77e74ad61218b594d303 Mon Sep 17 00:00:00 2001 From: Jacob Nesbitt Date: Fri, 27 Mar 2020 11:45:43 -0400 Subject: [PATCH 6/7] Fix trailing comma --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 8c8eba7..9004e7f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -159,7 +159,7 @@ class MultinetAPI { params: { key: key || undefined, overwrite: overwrite || undefined, - } + }, }); } From 961551e3c4463ad4485ed76e39a189be388b81cd Mon Sep 17 00:00:00 2001 From: Roni Choudhury Date: Fri, 27 Mar 2020 13:44:42 -0400 Subject: [PATCH 7/7] Bump version number for release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ac45944..d009794 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "multinet", - "version": "0.11.0", + "version": "0.12.0", "description": "Multinet client library", "main": "dist/index.js", "types": "dist/index.d.ts",