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", 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..9004e7f 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; @@ -60,6 +60,8 @@ export type EdgesOptionsSpec = OffsetLimitSpec & { export interface FileUploadOptionsSpec { type: UploadType; data: string | File; + key?: string; + overwrite?: boolean; } export interface CreateGraphOptionsSpec { @@ -139,19 +141,25 @@ 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): 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, { - 'Content-Type': 'text/plain', + return this.client.post(`/${type}/${workspace}/${table}`, text, { + headers: { 'Content-Type': 'text/plain' }, + params: { + key: key || undefined, + overwrite: overwrite || undefined, + }, }); } @@ -174,7 +182,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 {