import Index from"../index.js";import{IndexOptions}from"../type.js";let index,options;export default(async function(a){a=a.data;const b=a.task,c=a.id;let d=a.args;switch(b){case"init":options=a.options||{};let e=options.config;e&&(options=options);const f=a.factory;f?(Function("return "+f)()(self),index=new self.FlexSearch.Index(options),delete self.FlexSearch):index=new Index(options),postMessage({id:c});break;default:let g;if("export"===b&&(d[1]?(d[0]=options.export,d[2]=0,d[3]=1):d=null),"import"!==b)g=d&&index[b].apply(index,d),g&&g.then&&(g=await g),g&&g.await&&(g=await g.await),"search"===b&&g.result&&(g=g.result);else if(d[0]){const a=await options.import.call(index,d[0]);index.import(d[0],a)}postMessage("search"===b?{id:c,msg:g}:{id:c});}});