const{parentPort}=require("worker_threads"),{Index}=require("flexsearch");let index,options;parentPort.on("message",async function(a){const b=a.task,c=a.id;let d=a.args;switch(b){case"init":options=a.options||{};let e=options.config;e&&(options=Object.assign({},options,require(e)),delete options.worker),index=new Index(options),parentPort.postMessage({id:c});break;default:let f;if("export"===b){if(!options.export||"function"!=typeof options.export)throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\".");d[1]?(d[0]=options.export,d[2]=0,d[3]=1):d=null}if("import"===b){if(!options.import||"function"!=typeof options.import)throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\".");if(d[0]){const a=await options.import.call(index,d[0]);index.import(d[0],a)}}else f=d&&index[b].apply(index,d),f&&f.then&&(f=await f),f&&f.await&&(f=await f.await),"search"===b&&f.result&&(f=f.result);parentPort.postMessage("search"===b?{id:c,msg:f}:{id:c});}});