Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosInstance } from 'axios';
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';

export class Client {
public axios: AxiosInstance;
Expand All @@ -21,9 +21,9 @@ export class Client {
});
}

public post(path: string, params: {} = {}, headers: {} = {}): Promise<any> {
public post(path: string, data: any = null, params: AxiosRequestConfig = {}): Promise<any> {
return new Promise((resolve, reject) => {
this.axios.post(path, params, { headers, })
this.axios.post(path, data, params)
.then((resp) => {
resolve(resp.data);
})
Expand Down
24 changes: 16 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client } from './client';
import { AxiosPromise } from 'axios';
import { AxiosPromise, AxiosRequestConfig } from 'axios';

export interface TableRow {
_key: string;
Expand Down Expand Up @@ -60,6 +60,8 @@ export type EdgesOptionsSpec = OffsetLimitSpec & {
export interface FileUploadOptionsSpec {
type: UploadType;
data: string | File;
key?: string;
overwrite?: boolean;
}

export interface CreateGraphOptionsSpec {
Expand Down Expand Up @@ -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<Array<{}>> {
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,
},
});
}

Expand All @@ -174,7 +182,7 @@ class MultinetAPI {
}

public aql(workspace: string, query: string): Promise<any[]> {
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 {
Expand Down