Skip to content

Commit

Permalink
Merge pull request #87 from multinet-app/upload-improvements
Browse files Browse the repository at this point in the history
Small fixes for new multinet table/network upload architecture
  • Loading branch information
JackWilb authored Aug 4, 2023
2 parents 19b37e1 + 341aa70 commit 0659c86
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
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

0 comments on commit 0659c86

Please sign in to comment.