@narrative.io/data-collaboration-sdk-ts 0.0.142 → 0.0.143
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/inference/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { BaseApi } from "../base-api";
|
|
2
|
+
const defaultEndpoint = "csv/format-schema/multipart";
|
|
3
|
+
const endpointToFileTypes = {
|
|
4
|
+
[defaultEndpoint]: ["csv", "txt"],
|
|
5
|
+
"json/schema/multipart": ["json", "jsonl"],
|
|
6
|
+
"parquet/schema/multipart": ["parquet"],
|
|
7
|
+
};
|
|
2
8
|
/**
|
|
3
9
|
* The name of the resource to be used in API requests.
|
|
4
10
|
* @constant
|
|
@@ -11,12 +17,6 @@ const resourceName = "inference";
|
|
|
11
17
|
* @extends BaseApi
|
|
12
18
|
*/
|
|
13
19
|
export class InferenceApi extends BaseApi {
|
|
14
|
-
defaultEndpoint = "csv/format-schema/multipart";
|
|
15
|
-
endpointToFileTypes = {
|
|
16
|
-
[this.defaultEndpoint]: ["csv", "txt"],
|
|
17
|
-
"json/schema/multipart": ["json", "jsonl"],
|
|
18
|
-
"parquet/schema/multipart": ["parquet"],
|
|
19
|
-
};
|
|
20
20
|
makeFileExtension(file) {
|
|
21
21
|
return file.name.split(".")?.pop();
|
|
22
22
|
}
|
|
@@ -27,20 +27,23 @@ export class InferenceApi extends BaseApi {
|
|
|
27
27
|
* @returns {Promise<Schema>} A promise that resolves with the schema.
|
|
28
28
|
*/
|
|
29
29
|
async inferFileSchema(file) {
|
|
30
|
+
console.log("file", file);
|
|
30
31
|
const extension = this.makeFileExtension(file);
|
|
31
32
|
let endpointForExtension;
|
|
32
33
|
let endpoint;
|
|
34
|
+
console.log("endpointToFileTypes", endpointToFileTypes);
|
|
33
35
|
if (extension !== undefined) {
|
|
34
|
-
endpointForExtension = Object.keys(
|
|
35
|
-
return
|
|
36
|
+
endpointForExtension = Object.keys(endpointToFileTypes).find((key) => {
|
|
37
|
+
return endpointToFileTypes[key].includes(extension);
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
40
|
if (endpointForExtension === undefined) {
|
|
39
|
-
endpoint =
|
|
41
|
+
endpoint = defaultEndpoint;
|
|
40
42
|
}
|
|
41
43
|
else {
|
|
42
44
|
endpoint = endpointForExtension;
|
|
43
45
|
}
|
|
46
|
+
console.log("endpoint", endpoint);
|
|
44
47
|
const formData = new FormData();
|
|
45
48
|
formData.append("file", file);
|
|
46
49
|
return await this.post(`${resourceName}/${endpoint}`, formData);
|