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
12 changes: 7 additions & 5 deletions src/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
WorkspacePermissionsSpec,
Workspace,
AQLQuerySpec,
ColumnType,
} from './index';

function fileToText(file: File): Promise<string> {
Expand Down Expand Up @@ -61,7 +62,7 @@ export interface MultinetAxiosInstance extends AxiosInstance {
uploadTable(workspace: string, table: string, options: TableUploadOptionsSpec, config?: AxiosRequestConfig): AxiosPromise<Array<{}>>;
deleteTable(workspace: string, table: string): AxiosPromise<string>;
columnTypes(workspace: string, table: string): AxiosPromise<ColumnTypes>;
uploadNetwork(workspace: string, network: string, options: NetworkUploadOptionsSpec, config?: AxiosRequestConfig): AxiosPromise<Array<{}>>;
uploadNetwork(workspace: string, network: string, data: File, nodeColumns: Record<string, ColumnType>, edgeColumns: Record<string, ColumnType>, config?: AxiosRequestConfig): AxiosPromise<Array<{}>>;
createNetwork(workspace: string, network: string, options: CreateNetworkOptionsSpec): AxiosPromise<CreateNetworkOptionsSpec>;
deleteNetwork(workspace: string, network: string): AxiosPromise<string>;
aql(workspace: string, payload: AQLQuerySpec): AxiosPromise<any[]>;
Expand Down Expand Up @@ -183,7 +184,7 @@ export function multinetAxiosInstance(config: AxiosRequestConfig): MultinetAxios
}

// else if json
return this.post(`workspaces/${workspace}/uploads/json/`, {
return this.post(`workspaces/${workspace}/uploads/json_table/`, {
field_value: fieldValue.value,
edge: edgeTable,
table_name: table,
Expand All @@ -199,18 +200,19 @@ export function multinetAxiosInstance(config: AxiosRequestConfig): MultinetAxios
return this.get(`workspaces/${workspace}/tables/${table}/annotations/`);
};

Proto.uploadNetwork = async function(workspace: string, network: string, options: NetworkUploadOptionsSpec): Promise<AxiosResponse<Array<{}>>> {
const { type, data } = options;
Proto.uploadNetwork = async function(workspace: string, network: string, data: File, nodeColumns: Record<string, ColumnType>, edgeColumns: Record<string, ColumnType>): Promise<AxiosResponse<Array<{}>>> {
const s3ffClient = new S3FileFieldClient({
baseUrl: `${this.defaults.baseURL}/s3-upload/`,
apiConfig: this.defaults,
});

const fieldValue = await s3ffClient.uploadFile(data, 'api.Upload.blob');

return this.post(`workspaces/${workspace}/uploads/${type}/`, {
return this.post(`workspaces/${workspace}/uploads/json_network/`, {
field_value: fieldValue.value,
network_name: network,
node_columns: nodeColumns,
edge_columns: edgeColumns,
});
};

Expand Down
27 changes: 4 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,6 @@ export interface Workspace {

export type TableType = 'all' | 'node' | 'edge';

export type TableUploadType = 'csv';
export type NetworkUploadType = 'nested_json' | 'newick' | 'd3_json';
export type UploadType = TableUploadType | NetworkUploadType;

export function validTableUploadType(type: string): type is TableUploadType {
return type === 'csv';
}

export function validNetworkUploadType(type: string): type is NetworkUploadType {
return ['nested_json', 'newick', 'd3_json'].includes(type);
}

export function validUploadType(type: string): type is UploadType {
return validTableUploadType(type) || validNetworkUploadType(type);
}

export type Direction = 'all' | 'incoming' | 'outgoing';

export interface TablesOptionsSpec {
Expand All @@ -113,7 +97,7 @@ export type EdgesOptionsSpec = OffsetLimitSpec & {
direction?: Direction;
};

export type ColumnType = 'number' | 'label' | 'category' | 'date' | 'boolean';
export type ColumnType = 'primary key' | 'edge source' | 'edge target' | 'label' | 'string' | 'boolean' | 'category' | 'number' | 'date' | 'ignored';

export interface ColumnTypes {
[key: string]: ColumnType;
Expand All @@ -122,17 +106,14 @@ export interface ColumnTypes {
export interface TableUploadOptionsSpec {
data: File;
edgeTable: boolean;
columnTypes?: {
[key: string]: ColumnType;
};
columnTypes?: Record<string, ColumnType>;
fileType: 'json' | 'csv';
delimiter?: string;
quoteChar?: string;
}

export interface NetworkUploadOptionsSpec {
data: File;
type: NetworkUploadType;
}

export interface CreateNetworkOptionsSpec {
Expand Down Expand Up @@ -258,8 +239,8 @@ class MultinetAPI {
return types;
}

public async uploadNetwork(workspace: string, network: string, options: NetworkUploadOptionsSpec): Promise<Array<{}>> {
return (await this.axios.uploadNetwork(workspace, network, options)).data;
public async uploadNetwork(workspace: string, network: string, data: File, nodeColumns: Record<string, ColumnType>, edgeColumns: Record<string, ColumnType>): Promise<Array<{}>> {
return (await this.axios.uploadNetwork(workspace, network, data, nodeColumns, edgeColumns)).data;
}

public async createNetwork(workspace: string, network: string, options: CreateNetworkOptionsSpec): Promise<CreateNetworkOptionsSpec> {
Expand Down