1
1
import { APIInterface } from "./APIInterface.mjs" ;
2
2
3
+ // TODO: The Webpack way to get the WASM would be something like:
4
+ //import QueryWasm from "gbz-base/target/wasm32-wasi/release/query.wasm";
5
+ // if the export mapping is broken, or
6
+ //import QueryWasm from "gbz-base/query.wasm";
7
+ // if it is working. In Jest, not only is the export mapping not working, but
8
+ // also it can't get us a fetch-able string from the import like Webpack does.
9
+ // So we will need some fancy Jest config to mock the WASM file into a js
10
+ // module that does *something*, and also to mock fetch() into something that
11
+ // can fetch it. Or else we need to hide that all behind something that can
12
+ // fetch the WASM on either Webpack or Jest with its own strategies/by being
13
+ // swapped out.
14
+
3
15
/**
4
16
* API implementation that uses tools compiled to WebAssembly, client-side.
5
17
*/
6
18
export class GBZBaseAPI extends APIInterface {
7
19
constructor ( ) {
8
20
super ( ) ;
21
+
22
+ // We can take user uploads, in which case we need to hold on to them somewhere.
23
+ // This holds all the file objects.
24
+ this . files = [ ] ;
25
+
26
+ // We need to index all their names by type.
27
+ this . filesByType = { } ;
28
+
29
+ // We need to set up our WASM
9
30
}
10
31
11
32
async getChunkedData ( viewTarget , cancelSignal ) {
@@ -18,16 +39,46 @@ export class GBZBaseAPI extends APIInterface {
18
39
}
19
40
20
41
async getFilenames ( cancelSignal ) {
21
- return {
42
+ // Set up an empty response.
43
+ let response = {
22
44
files : [ ] ,
23
45
bedFiles : [ ]
24
46
} ;
47
+
48
+ for ( let type of this . filesByType ) {
49
+ if ( type == "bed" ) {
50
+ // Just send all these files in bedFiles.
51
+ response . bedFiles = this . filesByType [ type ] ;
52
+ } else {
53
+ for ( let fileName of this . filesByType [ type ] ) {
54
+ // We sens a name/type record for each non-BED file
55
+ response . files . push ( { name : fileName , type : type } ) ;
56
+ }
57
+ }
58
+ }
59
+
60
+ return response ;
25
61
}
26
62
27
63
subscribeToFilenameChanges ( handler , cancelSignal ) {
28
64
return { } ;
29
65
}
30
66
67
+ async putFile ( fileType , file , cancelSignal ) {
68
+ // We track files just by array index.
69
+ let fileName = this . files . length . toString ( ) ;
70
+ // Just hang on to the File object.
71
+ this . files . push ( file ) ;
72
+
73
+ if ( this . filesByType [ fileType ] === undefined ) {
74
+ this . filesByType [ fileType ] = [ ] ;
75
+ }
76
+ // Index the name we produced by type.
77
+ this . filesByType [ fileType ] . push ( fileName ) ;
78
+
79
+ return fileName ;
80
+ }
81
+
31
82
async getBedRegions ( bedFile , cancelSignal ) {
32
83
return {
33
84
bedRegions : [ ]
0 commit comments