-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAlgorithmExecutable.ts
More file actions
56 lines (45 loc) · 1.14 KB
/
Copy pathAlgorithmExecutable.ts
File metadata and controls
56 lines (45 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { HttpClient } from './HttpClient';
import { getContentType, Input, Json } from './ContentTypeHelper';
import { URLSearchParams } from 'url';
class AlgorithmExecutable {
private client: HttpClient;
private path: string;
public constructor(client: HttpClient, path: string) {
this.client = client;
this.path = path;
}
pipe(
input: Input,
version?: string,
output = 'raw',
stdout = false,
timeout = 300
) {
const contentType = getContentType(input);
const pathname = version ? `${this.path}/${version}/` : `${this.path}/`;
const params = new URLSearchParams({
timeout: timeout.toString(),
stdout: stdout.toString(),
output,
});
const fullPath = `${pathname}?${params.toString()}`;
return this.client.post(fullPath, input, contentType);
}
}
interface AlgoResponse {
async?: boolean;
error?: Error;
metadata?: MetaData;
request_id?: string;
result?: string | Json;
}
interface Error {
message: string;
stacktrace: string;
}
interface MetaData {
content_type: string;
duration: string;
stdout: string;
}
export { AlgorithmExecutable, AlgoResponse };