"use strict";var ee=Object.create;var m=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var oe=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),ie=(s,e)=>{for(var r in e)m(s,r,{get:e[r],enumerable:!0})},v=(s,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of te(e))!ne.call(s,o)&&o!==r&&m(s,o,{get:()=>e[o],enumerable:!(t=re(e,o))||t.enumerable});return s};var k=(s,e,r)=>(r=s!=null?ee(se(s)):{},v(e||!s||!s.__esModule?m(r,"default",{value:s,enumerable:!0}):r,s)),ae=s=>v(m({},"__esModule",{value:!0}),s);var Z=oe((Ke,$)=>{$.exports=Worker});var he={};ie(he,{AsyncDuckDB:()=>N,AsyncDuckDBConnection:()=>E,AsyncDuckDBDispatcher:()=>A,AsyncPreparedStatement:()=>_,AsyncResultStreamIterator:()=>p,ConsoleLogger:()=>g,DuckDBAccessMode:()=>M,DuckDBDataProtocol:()=>W,LogEvent:()=>Q,LogLevel:()=>G,LogOrigin:()=>q,LogTopic:()=>x,PACKAGE_NAME:()=>P,PACKAGE_VERSION:()=>L,PACKAGE_VERSION_MAJOR:()=>_e,PACKAGE_VERSION_MINOR:()=>Re,PACKAGE_VERSION_PATCH:()=>Te,StatusCode:()=>Y,TokenType:()=>B,VoidLogger:()=>y,WorkerRequestType:()=>S,WorkerResponseType:()=>h,WorkerTask:()=>a,createWorker:()=>ge,getJsDelivrBundles:()=>ke,getLogEventLabel:()=>ce,getLogLevelLabel:()=>de,getLogOriginLabel:()=>le,getLogTopicLabel:()=>ue,getPlatformFeatures:()=>J,isFirefox:()=>be,isNode:()=>U,isSafari:()=>Ie,selectBundle:()=>ye});module.exports=ae(he);var M=(o=>(o[o.UNDEFINED=0]="UNDEFINED",o[o.AUTOMATIC=1]="AUTOMATIC",o[o.READ_ONLY=2]="READ_ONLY",o[o.READ_WRITE=3]="READ_WRITE",o))(M||{});var B=(n=>(n[n.IDENTIFIER=0]="IDENTIFIER",n[n.NUMERIC_CONSTANT=1]="NUMERIC_CONSTANT",n[n.STRING_CONSTANT=2]="STRING_CONSTANT",n[n.OPERATOR=3]="OPERATOR",n[n.KEYWORD=4]="KEYWORD",n[n.COMMENT=5]="COMMENT",n))(B||{});var G=(i=>(i[i.NONE=0]="NONE",i[i.DEBUG=1]="DEBUG",i[i.INFO=2]="INFO",i[i.WARNING=3]="WARNING",i[i.ERROR=4]="ERROR",i))(G||{}),x=(n=>(n[n.NONE=0]="NONE",n[n.CONNECT=1]="CONNECT",n[n.DISCONNECT=2]="DISCONNECT",n[n.OPEN=3]="OPEN",n[n.QUERY=4]="QUERY",n[n.INSTANTIATE=5]="INSTANTIATE",n))(x||{}),Q=(n=>(n[n.NONE=0]="NONE",n[n.OK=1]="OK",n[n.ERROR=2]="ERROR",n[n.START=3]="START",n[n.RUN=4]="RUN",n[n.CAPTURE=5]="CAPTURE",n))(Q||{}),q=(i=>(i[i.NONE=0]="NONE",i[i.WEB_WORKER=1]="WEB_WORKER",i[i.NODE_WORKER=2]="NODE_WORKER",i[i.BINDINGS=3]="BINDINGS",i[i.ASYNC_DUCKDB=4]="ASYNC_DUCKDB",i))(q||{}),y=class{log(e){}},g=class{constructor(e=2){this.level=e}log(e){e.level>=this.level&&console.log(e)}};function de(s){switch(s){case 0:return"NONE";case 1:return"DEBUG";case 2:return"INFO";case 3:return"WARNING";case 4:return"ERROR";default:return"?"}}function ce(s){switch(s){case 0:return"NONE";case 1:return"OK";case 2:return"ERROR";case 3:return"START";case 4:return"RUN";case 5:return"CAPTURE";default:return"?"}}function ue(s){switch(s){case 1:return"CONNECT";case 2:return"DISCONNECT";case 5:return"INSTANTIATE";case 3:return"OPEN";case 4:return"QUERY";default:return"?"}}function le(s){switch(s){case 0:return"NONE";case 1:return"WEB WORKER";case 2:return"NODE WORKER";case 3:return"DUCKDB BINDINGS";case 4:return"DUCKDB";default:return"?"}}var Y=(e=>(e[e.SUCCESS=0]="SUCCESS",e))(Y||{});var l=k(require("apache-arrow"));var E=class{constructor(e,r){this._bindings=e,this._conn=r}get bindings(){return this._bindings}async close(){return this._bindings.disconnect(this._conn)}useUnsafe(e){return e(this._bindings,this._conn)}async query(e){this._bindings.logger.log({timestamp:new Date,level:2,origin:4,topic:4,event:4,value:e});let r=await this._bindings.runQuery(this._conn,e),t=l.RecordBatchReader.from(r);return console.assert(t.isSync(),"Reader is not sync"),console.assert(t.isFile(),"Reader is not file"),new l.Table(t)}async send(e){this._bindings.logger.log({timestamp:new Date,level:2,origin:4,topic:4,event:4,value:e});let r=await this._bindings.startPendingQuery(this._conn,e);for(;r==null;)r=await this._bindings.pollPendingQuery(this._conn);let t=new p(this._bindings,this._conn,r),o=await l.RecordBatchReader.from(t);return console.assert(o.isAsync()),console.assert(o.isStream()),o}async cancelSent(){return await this._bindings.cancelPendingQuery(this._conn)}async getTableNames(e){return await this._bindings.getTableNames(this._conn,e)}async prepare(e){let r=await this._bindings.createPrepared(this._conn,e);return new _(this._bindings,this._conn,r)}async insertArrowTable(e,r){let t=l.tableToIPC(e,"stream");await this.insertArrowFromIPCStream(t,r)}async insertArrowFromIPCStream(e,r){await this._bindings.insertArrowFromIPCStream(this._conn,e,r)}async insertCSVFromPath(e,r){await this._bindings.insertCSVFromPath(this._conn,e,r)}async insertJSONFromPath(e,r){await this._bindings.insertJSONFromPath(this._conn,e,r)}},p=class{constructor(e,r,t){this.db=e;this.conn=r;this.header=t;this._first=!0,this._depleted=!1,this._inFlight=null}async next(){if(this._first)return this._first=!1,{done:!1,value:this.header};if(this._depleted)return{done:!0,value:null};let e;return this._inFlight!=null?(e=await this._inFlight,this._inFlight=null):e=await this.db.fetchQueryResults(this.conn),this._depleted=e.length==0,this._depleted||(this._inFlight=this.db.fetchQueryResults(this.conn)),{done:this._depleted,value:e}}[Symbol.asyncIterator](){return this}},_=class{constructor(e,r,t){this.bindings=e,this.connectionId=r,this.statementId=t}async close(){await this.bindings.closePrepared(this.connectionId,this.statementId)}async query(...e){let r=await this.bindings.runPrepared(this.connectionId,this.statementId,e),t=l.RecordBatchReader.from(r);return console.assert(t.isSync()),console.assert(t.isFile()),new l.Table(t)}async send(...e){let r=await this.bindings.sendPrepared(this.connectionId,this.statementId,e),t=new p(this.bindings,this.connectionId,r),o=await l.RecordBatchReader.from(t);return console.assert(o.isAsync()),console.assert(o.isStream()),o}};var S=(c=>(c.CANCEL_PENDING_QUERY="CANCEL_PENDING_QUERY",c.CLOSE_PREPARED="CLOSE_PREPARED",c.COLLECT_FILE_STATISTICS="COLLECT_FILE_STATISTICS",c.CONNECT="CONNECT",c.COPY_FILE_TO_BUFFER="COPY_FILE_TO_BUFFER",c.COPY_FILE_TO_PATH="COPY_FILE_TO_PATH",c.CREATE_PREPARED="CREATE_PREPARED",c.DISCONNECT="DISCONNECT",c.DROP_FILE="DROP_FILE",c.DROP_FILES="DROP_FILES",c.EXPORT_FILE_STATISTICS="EXPORT_FILE_STATISTICS",c.FETCH_QUERY_RESULTS="FETCH_QUERY_RESULTS",c.FLUSH_FILES="FLUSH_FILES",c.GET_FEATURE_FLAGS="GET_FEATURE_FLAGS",c.GET_TABLE_NAMES="GET_TABLE_NAMES",c.GET_VERSION="GET_VERSION",c.GLOB_FILE_INFOS="GLOB_FILE_INFOS",c.INSERT_ARROW_FROM_IPC_STREAM="INSERT_ARROW_FROM_IPC_STREAM",c.INSERT_CSV_FROM_PATH="IMPORT_CSV_FROM_PATH",c.INSERT_JSON_FROM_PATH="IMPORT_JSON_FROM_PATH",c.INSTANTIATE="INSTANTIATE",c.OPEN="OPEN",c.PING="PING",c.POLL_PENDING_QUERY="POLL_PENDING_QUERY",c.REGISTER_FILE_BUFFER="REGISTER_FILE_BUFFER",c.REGISTER_FILE_HANDLE="REGISTER_FILE_HANDLE",c.REGISTER_FILE_URL="REGISTER_FILE_URL",c.RESET="RESET",c.RUN_PREPARED="RUN_PREPARED",c.RUN_QUERY="RUN_QUERY",c.SEND_PREPARED="SEND_PREPARED",c.START_PENDING_QUERY="START_PENDING_QUERY",c.TOKENIZE="TOKENIZE",c))(S||{}),h=(u=>(u.CONNECTION_INFO="CONNECTION_INFO",u.ERROR="ERROR",u.FEATURE_FLAGS="FEATURE_FLAGS",u.FILE_BUFFER="FILE_BUFFER",u.FILE_INFOS="FILE_INFOS",u.FILE_SIZE="FILE_SIZE",u.FILE_STATISTICS="FILE_STATISTICS",u.INSTANTIATE_PROGRESS="INSTANTIATE_PROGRESS",u.LOG="LOG",u.OK="OK",u.PREPARED_STATEMENT_ID="PREPARED_STATEMENT_ID",u.QUERY_PLAN="QUERY_PLAN",u.QUERY_RESULT="QUERY_RESULT",u.QUERY_RESULT_CHUNK="QUERY_RESULT_CHUNK",u.QUERY_RESULT_HEADER="QUERY_RESULT_HEADER",u.QUERY_RESULT_HEADER_OR_NULL="QUERY_RESULT_HEADER_OR_NULL",u.REGISTERED_FILE="REGISTERED_FILE",u.SCRIPT_TOKENS="SCRIPT_TOKENS",u.SUCCESS="SUCCESS",u.TABLE_NAMES="TABLE_NAMES",u.VERSION_STRING="VERSION_STRING",u))(h||{}),a=class{constructor(e,r){this.promiseResolver=()=>{};this.promiseRejecter=()=>{};this.type=e,this.data=r,this.promise=new Promise((t,o)=>{this.promiseResolver=t,this.promiseRejecter=o})}};var d=k(require("apache-arrow"));function R(s){switch(s.typeId){case d.Type.Binary:return{sqlType:"binary"};case d.Type.Bool:return{sqlType:"bool"};case d.Type.Date:return{sqlType:"date"};case d.Type.DateDay:return{sqlType:"date32[d]"};case d.Type.DateMillisecond:return{sqlType:"date64[ms]"};case d.Type.Decimal:{let e=s;return{sqlType:"decimal",precision:e.precision,scale:e.scale}}case d.Type.Float:return{sqlType:"float"};case d.Type.Float16:return{sqlType:"float16"};case d.Type.Float32:return{sqlType:"float32"};case d.Type.Float64:return{sqlType:"float64"};case d.Type.Int:return{sqlType:"int32"};case d.Type.Int16:return{sqlType:"int16"};case d.Type.Int32:return{sqlType:"int32"};case d.Type.Int64:return{sqlType:"int64"};case d.Type.Uint16:return{sqlType:"uint16"};case d.Type.Uint32:return{sqlType:"uint32"};case d.Type.Uint64:return{sqlType:"uint64"};case d.Type.Uint8:return{sqlType:"uint8"};case d.Type.IntervalDayTime:return{sqlType:"interval[dt]"};case d.Type.IntervalYearMonth:return{sqlType:"interval[m]"};case d.Type.List:return{sqlType:"list",valueType:R(s.valueType)};case d.Type.FixedSizeBinary:return{sqlType:"fixedsizebinary",byteWidth:s.byteWidth};case d.Type.Null:return{sqlType:"null"};case d.Type.Utf8:return{sqlType:"utf8"};case d.Type.Struct:return{sqlType:"struct",fields:s.children.map(r=>T(r.name,r.type))};case d.Type.Map:{let e=s;return{sqlType:"map",keyType:R(e.keyType),valueType:R(e.valueType)}}case d.Type.Time:return{sqlType:"time[s]"};case d.Type.TimeMicrosecond:return{sqlType:"time[us]"};case d.Type.TimeMillisecond:return{sqlType:"time[ms]"};case d.Type.TimeNanosecond:return{sqlType:"time[ns]"};case d.Type.TimeSecond:return{sqlType:"time[s]"};case d.Type.Timestamp:return{sqlType:"timestamp",timezone:s.timezone||void 0};case d.Type.TimestampSecond:return{sqlType:"timestamp[s]",timezone:s.timezone||void 0};case d.Type.TimestampMicrosecond:return{sqlType:"timestamp[us]",timezone:s.timezone||void 0};case d.Type.TimestampNanosecond:return{sqlType:"timestamp[ns]",timezone:s.timezone||void 0};case d.Type.TimestampMillisecond:return{sqlType:"timestamp[ms]",timezone:s.timezone||void 0}}throw new Error("unsupported arrow type: ".concat(s.toString()))}function T(s,e){let r=R(e);return r.name=s,r}var Ee=new TextEncoder,N=class{constructor(e,r=null){this._onInstantiationProgress=[];this._worker=null;this._workerShutdownPromise=null;this._workerShutdownResolver=()=>{};this._nextMessageId=0;this._pendingRequests=new Map;this._logger=e,this._onMessageHandler=this.onMessage.bind(this),this._onErrorHandler=this.onError.bind(this),this._onCloseHandler=this.onClose.bind(this),r!=null&&this.attach(r)}get logger(){return this._logger}attach(e){this._worker=e,this._worker.addEventListener("message",this._onMessageHandler),this._worker.addEventListener("error",this._onErrorHandler),this._worker.addEventListener("close",this._onCloseHandler),this._workerShutdownPromise=new Promise((r,t)=>{this._workerShutdownResolver=r})}detach(){this._worker&&(this._worker.removeEventListener("message",this._onMessageHandler),this._worker.removeEventListener("error",this._onErrorHandler),this._worker.removeEventListener("close",this._onCloseHandler),this._worker=null,this._workerShutdownResolver(null),this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{})}async terminate(){this._worker&&(this._worker.terminate(),this._worker=null,this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{})}async postTask(e,r=[]){if(!this._worker){console.error("cannot send a message since the worker is not set!");return}let t=this._nextMessageId++;return this._pendingRequests.set(t,e),this._worker.postMessage({messageId:t,type:e.type,data:e.data},r),await e.promise}onMessage(e){var o;let r=e.data;switch(r.type){case"LOG":{this._logger.log(r.data);return}case"INSTANTIATE_PROGRESS":{for(let i of this._onInstantiationProgress)i(r.data);return}}let t=this._pendingRequests.get(r.requestId);if(!t){console.warn("unassociated response: [".concat(r.requestId,", ").concat(r.type.toString(),"]"));return}if(this._pendingRequests.delete(r.requestId),r.type=="ERROR"){let i=new Error(r.data.message);i.name=r.data.name,(o=Object.getOwnPropertyDescriptor(i,"stack"))!=null&&o.writable&&(i.stack=r.data.stack),t.promiseRejecter(i);return}switch(t.type){case"CLOSE_PREPARED":case"COLLECT_FILE_STATISTICS":case"COPY_FILE_TO_PATH":case"DISCONNECT":case"DROP_FILE":case"DROP_FILES":case"FLUSH_FILES":case"INSERT_ARROW_FROM_IPC_STREAM":case"IMPORT_CSV_FROM_PATH":case"IMPORT_JSON_FROM_PATH":case"OPEN":case"PING":case"REGISTER_FILE_BUFFER":case"REGISTER_FILE_HANDLE":case"REGISTER_FILE_URL":case"RESET":if(r.type=="OK"){t.promiseResolver(r.data);return}break;case"INSTANTIATE":if(this._onInstantiationProgress=[],r.type=="OK"){t.promiseResolver(r.data);return}break;case"GLOB_FILE_INFOS":if(r.type=="FILE_INFOS"){t.promiseResolver(r.data);return}break;case"GET_VERSION":if(r.type=="VERSION_STRING"){t.promiseResolver(r.data);return}break;case"GET_FEATURE_FLAGS":if(r.type=="FEATURE_FLAGS"){t.promiseResolver(r.data);return}break;case"GET_TABLE_NAMES":if(r.type=="TABLE_NAMES"){t.promiseResolver(r.data);return}break;case"TOKENIZE":if(r.type=="SCRIPT_TOKENS"){t.promiseResolver(r.data);return}break;case"COPY_FILE_TO_BUFFER":if(r.type=="FILE_BUFFER"){t.promiseResolver(r.data);return}break;case"EXPORT_FILE_STATISTICS":if(r.type=="FILE_STATISTICS"){t.promiseResolver(r.data);return}break;case"CONNECT":if(r.type=="CONNECTION_INFO"){t.promiseResolver(r.data);return}break;case"RUN_PREPARED":case"RUN_QUERY":if(r.type=="QUERY_RESULT"){t.promiseResolver(r.data);return}break;case"SEND_PREPARED":if(r.type=="QUERY_RESULT_HEADER"){t.promiseResolver(r.data);return}break;case"START_PENDING_QUERY":if(r.type=="QUERY_RESULT_HEADER_OR_NULL"){t.promiseResolver(r.data);return}break;case"POLL_PENDING_QUERY":if(r.type=="QUERY_RESULT_HEADER_OR_NULL"){t.promiseResolver(r.data);return}break;case"CANCEL_PENDING_QUERY":if(this._onInstantiationProgress=[],r.type=="SUCCESS"){t.promiseResolver(r.data);return}break;case"FETCH_QUERY_RESULTS":if(r.type=="QUERY_RESULT_CHUNK"){t.promiseResolver(r.data);return}break;case"CREATE_PREPARED":if(r.type=="PREPARED_STATEMENT_ID"){t.promiseResolver(r.data);return}break}t.promiseRejecter(new Error("unexpected response type: ".concat(r.type.toString())))}onError(e){console.error(e),console.error("error in duckdb worker: ".concat(e.message)),this._pendingRequests.clear()}onClose(){if(this._workerShutdownResolver(null),this._pendingRequests.size!=0){console.warn("worker terminated with ".concat(this._pendingRequests.size," pending requests"));return}this._pendingRequests.clear()}async reset(){let e=new a("RESET",null);return await this.postTask(e)}async ping(){let e=new a("PING",null);await this.postTask(e)}async dropFile(e){let r=new a("DROP_FILE",e);return await this.postTask(r)}async dropFiles(){let e=new a("DROP_FILES",null);return await this.postTask(e)}async flushFiles(){let e=new a("FLUSH_FILES",null);return await this.postTask(e)}async instantiate(e,r=null,t=o=>{}){this._onInstantiationProgress.push(t);let o=new a("INSTANTIATE",[e,r]);return await this.postTask(o)}async getVersion(){let e=new a("GET_VERSION",null);return await this.postTask(e)}async getFeatureFlags(){let e=new a("GET_FEATURE_FLAGS",null);return await this.postTask(e)}async open(e){let r=new a("OPEN",e);await this.postTask(r)}async tokenize(e){let r=new a("TOKENIZE",e);return await this.postTask(r)}async connectInternal(){let e=new a("CONNECT",null);return await this.postTask(e)}async connect(){let e=await this.connectInternal();return new E(this,e)}async disconnect(e){let r=new a("DISCONNECT",e);await this.postTask(r)}async runQuery(e,r){let t=new a("RUN_QUERY",[e,r]);return await this.postTask(t)}async startPendingQuery(e,r){let t=new a("START_PENDING_QUERY",[e,r]);return await this.postTask(t)}async pollPendingQuery(e){let r=new a("POLL_PENDING_QUERY",e);return await this.postTask(r)}async cancelPendingQuery(e){let r=new a("CANCEL_PENDING_QUERY",e);return await this.postTask(r)}async fetchQueryResults(e){let r=new a("FETCH_QUERY_RESULTS",e);return await this.postTask(r)}async getTableNames(e,r){let t=new a("GET_TABLE_NAMES",[e,r]);return await this.postTask(t)}async createPrepared(e,r){let t=new a("CREATE_PREPARED",[e,r]);return await this.postTask(t)}async closePrepared(e,r){let t=new a("CLOSE_PREPARED",[e,r]);await this.postTask(t)}async runPrepared(e,r,t){let o=new a("RUN_PREPARED",[e,r,t]);return await this.postTask(o)}async sendPrepared(e,r,t){let o=new a("SEND_PREPARED",[e,r,t]);return await this.postTask(o)}async globFiles(e){let r=new a("GLOB_FILE_INFOS",e);return await this.postTask(r)}async registerFileText(e,r){let t=Ee.encode(r);await this.registerFileBuffer(e,t)}async registerFileURL(e,r,t,o){r===void 0&&(r=e);let i=new a("REGISTER_FILE_URL",[e,r,t,o]);await this.postTask(i)}async registerEmptyFileBuffer(e){}async registerFileBuffer(e,r){let t=new a("REGISTER_FILE_BUFFER",[e,r]);await this.postTask(t,[r.buffer])}async registerFileHandle(e,r,t,o){let i=new a("REGISTER_FILE_HANDLE",[e,r,t,o]);await this.postTask(i,[])}async collectFileStatistics(e,r){let t=new a("COLLECT_FILE_STATISTICS",[e,r]);await this.postTask(t,[])}async exportFileStatistics(e){let r=new a("EXPORT_FILE_STATISTICS",e);return await this.postTask(r,[])}async copyFileToBuffer(e){let r=new a("COPY_FILE_TO_BUFFER",e);return await this.postTask(r)}async copyFileToPath(e,r){let t=new a("COPY_FILE_TO_PATH",[e,r]);await this.postTask(t)}async insertArrowFromIPCStream(e,r,t){if(r.length==0)return;let o=new a("INSERT_ARROW_FROM_IPC_STREAM",[e,r,t]);await this.postTask(o,[r.buffer])}async insertCSVFromPath(e,r,t){if(t.columns!==void 0){let i=[];for(let n in t.columns){let I=t.columns[n];i.push(T(n,I))}t.columnsFlat=i,delete t.columns}let o=new a("IMPORT_CSV_FROM_PATH",[e,r,t]);await this.postTask(o)}async insertJSONFromPath(e,r,t){if(t.columns!==void 0){let i=[];for(let n in t.columns){let I=t.columns[n];i.push(T(n,I))}t.columnsFlat=i,delete t.columns}let o=new a("IMPORT_JSON_FROM_PATH",[e,r,t]);await this.postTask(o)}};var A=class{constructor(){this._bindings=null;this._nextMessageId=0}log(e){this.postMessage({messageId:this._nextMessageId++,requestId:0,type:"LOG",data:e},[])}sendOK(e){this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"OK",data:null},[])}failWith(e,r){let t={name:r.name,message:r.message,stack:r.stack||void 0};this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"ERROR",data:t},[])}async onMessage(e){switch(e.type){case"PING":this.sendOK(e);return;case"INSTANTIATE":this._bindings!=null&&this.failWith(e,new Error("duckdb already initialized"));try{this._bindings=await this.instantiate(e.data[0],e.data[1],r=>{this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"INSTANTIATE_PROGRESS",data:r},[])}),this.sendOK(e)}catch(r){console.log(r),this._bindings=null,this.failWith(e,r)}return;default:break}if(!this._bindings)return this.failWith(e,new Error("duckdb is not initialized"));try{switch(e.type){case"GET_VERSION":this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"VERSION_STRING",data:this._bindings.getVersion()},[]);break;case"GET_FEATURE_FLAGS":this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"FEATURE_FLAGS",data:this._bindings.getFeatureFlags()},[]);break;case"RESET":this._bindings.reset(),this.sendOK(e);break;case"OPEN":this._bindings.open(e.data),this.sendOK(e);break;case"DROP_FILE":this._bindings.dropFile(e.data),this.sendOK(e);break;case"DROP_FILES":this._bindings.dropFiles(),this.sendOK(e);break;case"FLUSH_FILES":this._bindings.flushFiles(),this.sendOK(e);break;case"CONNECT":{let r=this._bindings.connect();this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"CONNECTION_INFO",data:r.useUnsafe((t,o)=>o)},[]);break}case"DISCONNECT":this._bindings.disconnect(e.data),this.sendOK(e);break;case"CREATE_PREPARED":{let r=this._bindings.createPrepared(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"PREPARED_STATEMENT_ID",data:r},[]);break}case"CLOSE_PREPARED":{this._bindings.closePrepared(e.data[0],e.data[1]),this.sendOK(e);break}case"RUN_PREPARED":{let r=this._bindings.runPrepared(e.data[0],e.data[1],e.data[2]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"QUERY_RESULT",data:r},[r.buffer]);break}case"RUN_QUERY":{let r=this._bindings.runQuery(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"QUERY_RESULT",data:r},[r.buffer]);break}case"SEND_PREPARED":{let r=this._bindings.sendPrepared(e.data[0],e.data[1],e.data[2]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"QUERY_RESULT_HEADER",data:r},[r.buffer]);break}case"START_PENDING_QUERY":{let r=this._bindings.startPendingQuery(e.data[0],e.data[1]),t=[];r&&t.push(r.buffer),this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"QUERY_RESULT_HEADER_OR_NULL",data:r},t);break}case"POLL_PENDING_QUERY":{let r=this._bindings.pollPendingQuery(e.data),t=[];r&&t.push(r.buffer),this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"QUERY_RESULT_HEADER_OR_NULL",data:r},t);break}case"CANCEL_PENDING_QUERY":{let r=this._bindings.cancelPendingQuery(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"SUCCESS",data:r},[]);break}case"FETCH_QUERY_RESULTS":{let r=this._bindings.fetchQueryResults(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"QUERY_RESULT_CHUNK",data:r},[r.buffer]);break}case"GET_TABLE_NAMES":{let r=this._bindings.getTableNames(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"TABLE_NAMES",data:r},[]);break}case"GLOB_FILE_INFOS":{let r=this._bindings.globFiles(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"FILE_INFOS",data:r},[]);break}case"REGISTER_FILE_URL":this._bindings.registerFileURL(e.data[0],e.data[1],e.data[2],e.data[3]),this.sendOK(e);break;case"REGISTER_FILE_BUFFER":this._bindings.registerFileBuffer(e.data[0],e.data[1]),this.sendOK(e);break;case"REGISTER_FILE_HANDLE":this._bindings.registerFileHandle(e.data[0],e.data[1],e.data[2],e.data[3]),this.sendOK(e);break;case"COPY_FILE_TO_PATH":this._bindings.copyFileToPath(e.data[0],e.data[1]),this.sendOK(e);break;case"COPY_FILE_TO_BUFFER":{let r=this._bindings.copyFileToBuffer(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"FILE_BUFFER",data:r},[]);break}case"COLLECT_FILE_STATISTICS":this._bindings.collectFileStatistics(e.data[0],e.data[1]),this.sendOK(e);break;case"EXPORT_FILE_STATISTICS":{this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"FILE_STATISTICS",data:this._bindings.exportFileStatistics(e.data)},[]);break}case"INSERT_ARROW_FROM_IPC_STREAM":{this._bindings.insertArrowFromIPCStream(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case"IMPORT_CSV_FROM_PATH":{this._bindings.insertCSVFromPath(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case"IMPORT_JSON_FROM_PATH":{this._bindings.insertJSONFromPath(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case"TOKENIZE":{let r=this._bindings.tokenize(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:"SCRIPT_TOKENS",data:r},[]);break}}}catch(r){return console.log(r),this.failWith(e,r)}}};var H=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,3,1,0,1,10,14,1,12,0,65,0,65,0,65,0,252,10,0,0,11])),j=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,8,1,6,0,6,64,25,11,11]));var K=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]));var V=()=>(async s=>{try{return typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(s)}catch(e){return!1}})(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]));var b={name:"@duckdb/duckdb-wasm",version:"1.28.1-dev181.0",description:"DuckDB powered by WebAssembly",license:"MIT",repository:{type:"git",url:"https://github.com/duckdb/duckdb-wasm.git"},keywords:["sql","duckdb","relational","database","data","query","wasm","analytics","olap","arrow","parquet","json","csv"],dependencies:{"apache-arrow":"^15.0.0"},devDependencies:{"@types/emscripten":"^1.39.10","@types/jasmine":"^5.1.4","@typescript-eslint/eslint-plugin":"^6.21.0","@typescript-eslint/parser":"^6.21.0",esbuild:"^0.20.1",eslint:"^8.56.0","eslint-plugin-jasmine":"^4.1.3","eslint-plugin-react":"^7.34.0","fast-glob":"^3.3.2",jasmine:"^5.1.0","jasmine-core":"^5.1.2","jasmine-spec-reporter":"^7.0.0","js-sha256":"^0.11.0",karma:"^6.4.2","karma-chrome-launcher":"^3.2.0","karma-coverage":"^2.2.1","karma-firefox-launcher":"^2.1.3","karma-jasmine":"^5.1.0","karma-jasmine-html-reporter":"^2.1.0","karma-sourcemap-loader":"^0.4.0","karma-spec-reporter":"^0.0.36","make-dir":"^4.0.0",nyc:"^15.1.0",prettier:"^3.2.5",puppeteer:"^21.7.0",rimraf:"^5.0.5",s3rver:"^3.7.1",typedoc:"^0.25.7",typescript:"^5.3.3","wasm-feature-detect":"^1.6.1","web-worker":"^1.2.0"},scripts:{"build:debug":"node bundle.mjs debug && tsc --emitDeclarationOnly","build:release":"node bundle.mjs release && tsc --emitDeclarationOnly",docs:"typedoc",report:"node ./coverage.mjs","test:node":"node --enable-source-maps ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs","test:node:debug":"node --inspect-brk --enable-source-maps ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs","test:node:coverage":"nyc -r json --report-dir ./coverage/node node ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs","test:firefox":"karma start ./karma/tests-firefox.cjs","test:chrome":"karma start ./karma/tests-chrome.cjs","test:chrome:eh":"karma start ./karma/tests-chrome-eh.cjs","test:chrome:coverage":"karma start ./karma/tests-chrome-coverage.cjs","test:browser":"karma start ./karma/tests-all.cjs","test:browser:debug":"karma start ./karma/tests-debug.cjs",test:"npm run test:chrome && npm run test:node","test:coverage":"npm run test:chrome:coverage && npm run test:node:coverage && npm run report",lint:"eslint src test"},files:["dist","!dist/tests-*","!dist/duckdb-browser-mvp.worker.js.map","!dist/types/test"],main:"dist/duckdb-browser.cjs",module:"dist/duckdb-browser.mjs",types:"dist/duckdb-browser.d.ts",jsdelivr:"dist/duckdb-browser.cjs",unpkg:"dist/duckdb-browser.mjs",sideEffects:!1,browser:{fs:!1,path:!1,perf_hooks:!1,os:!1,worker_threads:!1},exports:{"./dist/duckdb-mvp.wasm":"./dist/duckdb-mvp.wasm","./dist/duckdb-eh.wasm":"./dist/duckdb-eh.wasm","./dist/duckdb-coi.wasm":"./dist/duckdb-coi.wasm","./dist/duckdb-browser":"./dist/duckdb-browser.mjs","./dist/duckdb-browser.cjs":"./dist/duckdb-browser.cjs","./dist/duckdb-browser.mjs":"./dist/duckdb-browser.mjs","./dist/duckdb-browser-blocking":"./dist/duckdb-browser-blocking.mjs","./dist/duckdb-browser-blocking.mjs":"./dist/duckdb-browser-blocking.mjs","./dist/duckdb-browser-blocking.cjs":"./dist/duckdb-browser-blocking.cjs","./dist/duckdb-browser-coi.pthread.worker.js":"./dist/duckdb-browser-coi.pthread.worker.js","./dist/duckdb-browser-coi.worker.js":"./dist/duckdb-browser-coi.worker.js","./dist/duckdb-browser-eh.worker.js":"./dist/duckdb-browser-eh.worker.js","./dist/duckdb-browser-mvp.worker.js":"./dist/duckdb-browser-mvp.worker.js","./dist/duckdb-node":"./dist/duckdb-node.cjs","./dist/duckdb-node.cjs":"./dist/duckdb-node.cjs","./dist/duckdb-node-blocking":"./dist/duckdb-node-blocking.cjs","./dist/duckdb-node-blocking.cjs":"./dist/duckdb-node-blocking.cjs","./dist/duckdb-node-eh.worker.cjs":"./dist/duckdb-node-eh.worker.cjs","./dist/duckdb-node-mvp.worker.cjs":"./dist/duckdb-node-mvp.worker.cjs","./blocking":{browser:{types:"./dist/duckdb-browser-blocking.d.ts",import:"./dist/duckdb-browser-blocking.mjs",require:"./dist/duckdb-browser-blocking.cjs"},node:{types:"./dist/duckdb-node-blocking.d.ts",require:"./dist/duckdb-node-blocking.cjs",import:"./dist/duckdb-node-blocking.cjs"},types:"./dist/duckdb-browser-blocking.d.ts",import:"./dist/duckdb-browser-blocking.mjs",require:"./dist/duckdb-browser-blocking.cjs"},".":{browser:{types:"./dist/duckdb-browser.d.ts",import:"./dist/duckdb-browser.mjs",require:"./dist/duckdb-browser.cjs"},node:{types:"./dist/duckdb-node.d.ts",import:"./dist/duckdb-node.cjs",require:"./dist/duckdb-node.cjs"},types:"./dist/duckdb-browser.d.ts",import:"./dist/duckdb-browser.mjs",require:"./dist/duckdb-browser.cjs"}}};var P=b.name,L=b.version,D=b.version.split("."),_e=D[0],Re=D[1],Te=D[2];var U=()=>typeof navigator>"u",z=()=>U()?"node":navigator.userAgent,be=()=>z().includes("Firefox"),Ie=()=>/^((?!chrome|android).)*safari/i.test(z());function ke(){let s="https://cdn.jsdelivr.net/npm/".concat(P,"@").concat(L,"/dist/");return{mvp:{mainModule:"".concat(s,"duckdb-mvp.wasm"),mainWorker:"".concat(s,"duckdb-browser-mvp.worker.js")},eh:{mainModule:"".concat(s,"duckdb-eh.wasm"),mainWorker:"".concat(s,"duckdb-browser-eh.worker.js")}}}var O=null,w=null,F=null,f=null,C=null;async function J(){return O==null&&(O=typeof BigInt64Array<"u"),w==null&&(w=await j()),F==null&&(F=await V()),f==null&&(f=await K()),C==null&&(C=await H()),{bigInt64Array:O,crossOriginIsolated:U()||globalThis.crossOriginIsolated||!1,wasmExceptions:w,wasmSIMD:f,wasmThreads:F,wasmBulkMemory:C}}async function ye(s){let e=await J();if(e.wasmExceptions){if(e.wasmSIMD&&e.wasmThreads&&e.crossOriginIsolated&&s.coi)return{mainModule:s.coi.mainModule,mainWorker:s.coi.mainWorker,pthreadWorker:s.coi.pthreadWorker};if(s.eh)return{mainModule:s.eh.mainModule,mainWorker:s.eh.mainWorker,pthreadWorker:null}}return{mainModule:s.mvp.mainModule,mainWorker:s.mvp.mainWorker,pthreadWorker:null}}var X=k(Z());async function ge(s){let e=new Request(s),r=await fetch(e),t=URL.createObjectURL(await r.blob());return new X.default(t)}function Se(){let s=new TextDecoder;return e=>(typeof SharedArrayBuffer<"u"&&e.buffer instanceof SharedArrayBuffer&&(e=new Uint8Array(e)),s.decode(e))}var ze=Se();var W=(n=>(n[n.BUFFER=0]="BUFFER",n[n.NODE_FS=1]="NODE_FS",n[n.BROWSER_FILEREADER=2]="BROWSER_FILEREADER",n[n.BROWSER_FSACCESS=3]="BROWSER_FSACCESS",n[n.HTTP=4]="HTTP",n[n.S3=5]="S3",n))(W||{}); //# sourceMappingURL=duckdb-browser.cjs.map