11import { APIInterface } from "./APIInterface.mjs" ;
22
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+
315/**
416 * API implementation that uses tools compiled to WebAssembly, client-side.
517 */
618export class GBZBaseAPI extends APIInterface {
719 constructor ( ) {
820 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
930 }
1031
1132 async getChunkedData ( viewTarget , cancelSignal ) {
@@ -18,16 +39,46 @@ export class GBZBaseAPI extends APIInterface {
1839 }
1940
2041 async getFilenames ( cancelSignal ) {
21- return {
42+ // Set up an empty response.
43+ let response = {
2244 files : [ ] ,
2345 bedFiles : [ ]
2446 } ;
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 ;
2561 }
2662
2763 subscribeToFilenameChanges ( handler , cancelSignal ) {
2864 return { } ;
2965 }
3066
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+
3182 async getBedRegions ( bedFile , cancelSignal ) {
3283 return {
3384 bedRegions : [ ]
0 commit comments