Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@duckdb/duckdb-wasm

Package Overview
Dependencies
Maintainers
3
Versions
322
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@duckdb/duckdb-wasm - npm Package Compare versions

Comparing version 0.0.41-dev235.0 to 0.0.41-dev242.0

2

dist/duckdb-esm.js

@@ -1,2 +0,2 @@

import{AsyncByteQueue as z,RecordBatchReader as F,RecordBatchStreamWriter as q,Table as x}from"apache-arrow";var A=class{constructor(e,r,t){this.bindings=e;this.conn=r;this.header=t;this._first=!0,this._depleted=!1}next(){if(this._first)return this._first=!1,{done:!1,value:this.header};if(this._depleted)return{done:!0,value:null};let e=this.bindings.fetchQueryResults(this.conn);return this._depleted=e.length==0,{done:this._depleted,value:e}}[Symbol.iterator](){return this}},C=class{constructor(e,r){this._bindings=e,this._conn=r}get handle(){return this._conn}close(){this._bindings.disconnect(this._conn)}runQuery(e){let r=this._bindings.runQuery(this._conn,e),t=F.from(r);return console.assert(t.isSync()),console.assert(t.isFile()),x.from(t)}sendQuery(e){let r=this._bindings.sendQuery(this._conn,e),t=new A(this._bindings,this._conn,r),i=F.from(t);return console.assert(i.isSync()),console.assert(i.isStream()),i}createPreparedStatement(e){return this._bindings.createPreparedStatement(this._conn,e)}closePreparedStatement(e){this._bindings.closePreparedStatement(this._conn,e)}runPreparedStatement(e,r){let t=this._bindings.runPreparedStatement(this._conn,e,r),i=F.from(t);return console.assert(i.isSync()),console.assert(i.isFile()),x.from(i)}sendPreparedStatement(e,r){let t=this._bindings.sendPreparedStatement(this._conn,e,r),i=new A(this._bindings,this._conn,t),s=F.from(i);return console.assert(s.isSync()),console.assert(s.isStream()),s}insertArrowTable(e,r){e.schema.fields.length==0&&console.warn("The schema is empty! If you used arrow.Table.from, consider constructing schema and batches manually"),this.insertArrowBatches(e.schema,e.chunks,r)}insertArrowBatches(e,r,t){e.fields.length==0&&console.warn("The schema is empty! If you used arrow.Table.from, consider constructing schema and batches manually");let i=new z,s=new q().reset(i,e);s.writeAll(r),s.close();let c=s.toUint8Array(!0);this._bindings.insertArrowFromIPCStream(this._conn,c,t)}insertCSVFromPath(e,r){this._bindings.insertCSVFromPath(this._conn,e,r)}insertJSONFromPath(e,r){this._bindings.insertJSONFromPath(this._conn,e,r)}};var p;(function(e){e[e.SUCCESS=0]="SUCCESS"})(p||(p={}));function $(){let n=new TextDecoder;return e=>(typeof SharedArrayBuffer!="undefined"&&e.buffer instanceof SharedArrayBuffer&&(e=new Uint8Array(e)),n.decode(e))}var Z=$();function Ae(n,e){console.error(e),n.ccall("duckdb_web_fail_with",null,["string"],[e])}function w(n,e,r){let t=n.HEAPU8.subarray(e,e+r),i=new Uint8Array(new ArrayBuffer(t.byteLength));return i.set(t),i}function _(n,e,r){return Z(n.HEAPU8.subarray(e,e+r))}var G;(function(t){t[t.BUFFER=0]="BUFFER",t[t.NATIVE=1]="NATIVE",t[t.HTTP=3]="HTTP"})(G||(G={}));function E(n,e,r,t){let i=n.stackSave(),s=n.stackAlloc(3*8);r.unshift("number"),t.unshift(s),n.ccall(e,null,r,t);let c=n.HEAPF64[(s>>3)+0],h=n.HEAPF64[(s>>3)+1],k=n.HEAPF64[(s>>3)+2];return n.stackRestore(i),[c,h,k]}function b(n){n.ccall("duckdb_web_clear_response",null,[],[])}var Ce={testPlatformFeature:(n,e)=>!1,openFile:(n,e)=>{},syncFile:(n,e)=>{},closeFile:(n,e)=>{},getLastFileModificationTime:(n,e)=>0,getFileSize:(n,e)=>0,truncateFile:(n,e,r)=>{},readFile:(n,e,r,t,i)=>0,writeFile:(n,e,r,t,i)=>0,removeDirectory:(n,e,r)=>{},checkDirectory:(n,e,r)=>!1,createDirectory:(n,e,r)=>{},listDirectoryEntries:(n,e,r)=>!1,glob:(n,e,r)=>{},moveFile:(n,e,r,t,i)=>{},checkFile:(n,e,r)=>!1,removeFile:(n,e,r)=>{}};var P=class{constructor(e){let r=new Float64Array(e.buffer,e.byteOffset,e.byteLength/8),t=new Uint8Array(new ArrayBuffer(e.byteLength));t.set(e.subarray(7*8)),this.totalFileReadsCold=r[0],this.totalFileReadsAhead=r[1],this.totalFileReadsCached=r[2],this.totalFileWrites=r[3],this.totalPageAccesses=r[4],this.totalPageLoads=r[5],this.blockSize=r[6],this.blockStats=t}getBlockStats(e,r){return r=r||{file_reads_cold:0,file_reads_ahead:0,file_reads_cached:0,file_writes:0,page_accesses:0,page_loads:0},r.file_writes=this.blockStats[e*3+0]&15,r.file_reads_cold=this.blockStats[e*3+0]>>4,r.file_reads_ahead=this.blockStats[e*3+1]&15,r.file_reads_cached=this.blockStats[e*3+1]>>4,r.page_accesses=this.blockStats[e*3+1]&15,r.page_loads=this.blockStats[e*3+1]>>4,r}};import{Type as l}from"apache-arrow";function I(n,e){switch(e.typeId){case l.Binary:return{name:n,type:"binary"};case l.Bool:return{name:n,type:"bool"};case l.Date:return{name:n,type:"date"};case l.DateDay:return{name:n,type:"date32[d]"};case l.DateMillisecond:return{name:n,type:"date64[ms]"};case l.Decimal:{let r=e;return{name:n,type:"decimal",precision:r.precision,scale:r.scale}}case l.Float:return{name:n,type:"float"};case l.Float16:return{name:n,type:"float16"};case l.Float32:return{name:n,type:"float32"};case l.Float64:return{name:n,type:"float64"};case l.Int:return{name:n,type:"int32"};case l.Int16:return{name:n,type:"int16"};case l.Int32:return{name:n,type:"int32"};case l.Int64:return{name:n,type:"int64"};case l.Uint16:return{name:n,type:"uint16"};case l.Uint32:return{name:n,type:"uint32"};case l.Uint64:return{name:n,type:"uint64"};case l.Uint8:return{name:n,type:"uint8"};case l.IntervalDayTime:return{name:n,type:"interval[dt]"};case l.IntervalYearMonth:return{name:n,type:"interval[m]"};case l.List:{let r=e;return{name:n,type:"list",children:[I(r.valueField.name,r.valueField.type)]}}case l.FixedSizeBinary:return{name:n,type:"fixedsizebinary",byteWidth:e.byteWidth};case l.Null:return{name:n,type:"null"};case l.Utf8:return{name:n,type:"utf8"};case l.Struct:return{name:n,type:"struct",children:e.children.map(t=>I(t.name,t.type))};case l.Time:return{name:n,type:"time[s]"};case l.TimeMicrosecond:return{name:n,type:"time[us]"};case l.TimeMillisecond:return{name:n,type:"time[ms]"};case l.TimeNanosecond:return{name:n,type:"time[ns]"};case l.TimeSecond:return{name:n,type:"time[s]"};case l.Timestamp:return{name:n,type:"timestamp",timezone:e.timezone||void 0};case l.TimestampSecond:return{name:n,type:"timestamp[s]",timezone:e.timezone||void 0};case l.TimestampMicrosecond:return{name:n,type:"timestamp[us]",timezone:e.timezone||void 0};case l.TimestampNanosecond:return{name:n,type:"timestamp[ns]",timezone:e.timezone||void 0};case l.TimestampMillisecond:return{name:n,type:"timestamp[ms]",timezone:e.timezone||void 0}}throw new Error(`unsupported arrow type: ${e.toString()}`)}var H;(function(s){s[s.WASM_EXCEPTIONS=1]="WASM_EXCEPTIONS",s[s.WASM_THREADS=2]="WASM_THREADS",s[s.WASM_SIMD=4]="WASM_SIMD",s[s.WASM_BULK_MEMORY=8]="WASM_BULK_MEMORY",s[s.EMIT_BIGINT=16]="EMIT_BIGINT"})(H||(H={}));var X=class{constructor(e,r){this._instance=null;this._initPromise=null;this._initPromiseResolver=()=>{};this._logger=e,this._runtime=r}get logger(){return this._logger}get mod(){return this._instance}get pthread(){return this.mod.PThread||null}async instantiate(){return this._instance!=null?this:(this._initPromise!=null&&await this._initPromise,this._initPromise=new Promise(e=>{this._initPromiseResolver=e}),this._instance=await this.instantiateImpl({print:console.log.bind(console),printErr:console.log.bind(console),onRuntimeInitialized:this._initPromiseResolver}),await this._initPromise,this._initPromise=null,this)}open(e){let[r,t,i]=E(this.mod,"duckdb_web_open",["string"],[JSON.stringify(e)]);if(r!==p.SUCCESS)throw new Error(_(this.mod,t,i));b(this.mod)}reset(){let[e,r,t]=E(this.mod,"duckdb_web_reset",[],[]);if(e!==p.SUCCESS)throw new Error(_(this.mod,r,t));b(this.mod)}getVersion(){let[e,r,t]=E(this.mod,"duckdb_web_get_version",[],[]);if(e!==p.SUCCESS)throw new Error(_(this.mod,r,t));let i=_(this.mod,r,t);return b(this.mod),i}getFeatureFlags(){return this.mod.ccall("duckdb_web_get_feature_flags","number",[],[])}tokenize(e){let[r,t,i]=E(this.mod,"duckdb_web_tokenize",["string"],[e]);if(r!==p.SUCCESS)throw new Error(_(this.mod,t,i));let s=_(this.mod,t,i);return b(this.mod),JSON.parse(s)}connect(){let e=this.mod.ccall("duckdb_web_connect","number",[],[]);return new C(this,e)}disconnect(e){this.mod.ccall("duckdb_web_disconnect",null,["number"],[e])}runQuery(e,r){let[t,i,s]=E(this.mod,"duckdb_web_query_run",["number","string"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));let c=w(this.mod,i,s);return b(this.mod),c}sendQuery(e,r){let[t,i,s]=E(this.mod,"duckdb_web_query_send",["number","string"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));let c=w(this.mod,i,s);return b(this.mod),c}fetchQueryResults(e){let[r,t,i]=E(this.mod,"duckdb_web_query_fetch_results",["number"],[e]);if(r!==p.SUCCESS)throw new Error(_(this.mod,t,i));let s=w(this.mod,t,i);return b(this.mod),s}createPreparedStatement(e,r){let[t,i,s]=E(this.mod,"duckdb_web_prepared_statement_create",["number","string"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));return b(this.mod),i}closePreparedStatement(e,r){let[t,i,s]=E(this.mod,"duckdb_web_prepared_statement_close",["number","number"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));b(this.mod)}runPreparedStatement(e,r,t){let[i,s,c]=E(this.mod,"duckdb_web_prepared_statement_run",["number","number","string"],[e,r,JSON.stringify(t)]);if(i!==p.SUCCESS)throw new Error(_(this.mod,s,c));let h=w(this.mod,s,c);return b(this.mod),h}sendPreparedStatement(e,r,t){let[i,s,c]=E(this.mod,"duckdb_web_prepared_statement_send",["number","number","string"],[e,r,JSON.stringify(t)]);if(i!==p.SUCCESS)throw new Error(_(this.mod,s,c));let h=w(this.mod,s,c);return b(this.mod),h}insertArrowFromIPCStream(e,r,t){let i=this.mod._malloc(r.length);this.mod.HEAPU8.subarray(i,i+r.length).set(r);let c=t?JSON.stringify(t):"",[h,k,f]=E(this.mod,"duckdb_web_insert_arrow_from_ipc_stream",["number","number","number","string"],[e,i,r.length,c]);if(h!==p.SUCCESS)throw new Error(_(this.mod,k,f))}insertCSVFromPath(e,r,t){if(t.columns!==void 0){t.columnsFlat=[];for(let f in t.columns)t.columnsFlat.push(I(f,t.columns[f]))}let i={...t};i.columns=i.columnsFlat,delete i.columnsFlat;let s=JSON.stringify(i),[c,h,k]=E(this.mod,"duckdb_web_insert_csv_from_path",["number","string","string"],[e,r,s]);if(c!==p.SUCCESS)throw new Error(_(this.mod,h,k))}insertJSONFromPath(e,r,t){if(t.columns!==void 0){t.columnsFlat=[];for(let f in t.columns)t.columnsFlat.push(I(f,t.columns[f]))}let i={...t};i.columns=i.columnsFlat,delete i.columnsFlat;let s=JSON.stringify(i),[c,h,k]=E(this.mod,"duckdb_web_insert_json_from_path",["number","string","string"],[e,r,s]);if(c!==p.SUCCESS)throw new Error(_(this.mod,h,k))}finishInsert(e,r){}registerFileURL(e,r){r===void 0&&(r=e);let[t,i,s]=E(this.mod,"duckdb_web_fs_register_file_url",["string","string"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));b(this.mod)}registerFileBuffer(e,r){let t=this.mod._malloc(r.length);this.mod.HEAPU8.subarray(t,t+r.length).set(r);let[s,c,h]=E(this.mod,"duckdb_web_fs_register_file_buffer",["string","number","number"],[e,t,r.length]);if(s!==p.SUCCESS)throw new Error(_(this.mod,c,h));b(this.mod)}registerFileHandle(e,r){let[t,i,s]=E(this.mod,"duckdb_web_fs_register_file_url",["string","string"],[e,e]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));if(b(this.mod),globalThis.DUCKDB_RUNTIME._files=(globalThis.DUCKDB_RUNTIME._files||new Map).set(e,r),this.pthread){for(let c of this.pthread.runningWorkers)c.postMessage({cmd:"registerFileHandle",fileName:e,fileHandle:r});for(let c of this.pthread.unusedWorkers)c.postMessage({cmd:"dropFileHandle",fileName:e})}}dropFile(e){return this.mod.ccall("duckdb_web_fs_drop_file","boolean",["string"],[e])}dropFiles(){this.mod.ccall("duckdb_web_fs_drop_files",null,[],[])}flushFiles(){this.mod.ccall("duckdb_web_flush_files",null,[],[])}copyFileToPath(e,r){let[t,i,s]=E(this.mod,"duckdb_web_copy_file_to_path",["string","string"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));b(this.mod)}copyFileToBuffer(e){let[r,t,i]=E(this.mod,"duckdb_web_copy_file_to_buffer",["string"],[e]);if(r!==p.SUCCESS)throw new Error(_(this.mod,t,i));let s=this.mod.HEAPU8.subarray(t,t+i),c=new Uint8Array(s.length);return c.set(s),b(this.mod),c}collectFileStatistics(e,r){let[t,i,s]=E(this.mod,"duckdb_web_collect_file_stats",["string","boolean"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s))}exportFileStatistics(e){let[r,t,i]=E(this.mod,"duckdb_web_export_file_stats",["string"],[e]);if(r!==p.SUCCESS)throw new Error(_(this.mod,t,i));return new P(this.mod.HEAPU8.subarray(t,t+i))}};var V;(function(r){r.ROW_ARRAY="row-array",r.COLUMN_OBJECT="column-object"})(V||(V={}));var Q;(function(r){r[r.APPEND=0]="APPEND",r[r.IMPORT=1]="IMPORT"})(Q||(Q={}));var R;(function(s){s[s.NONE=0]="NONE",s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARNING=3]="WARNING",s[s.ERROR=4]="ERROR"})(R||(R={}));var y;(function(s){s[s.NONE=0]="NONE",s[s.CONNECT=1]="CONNECT",s[s.DISCONNECT=2]="DISCONNECT",s[s.OPEN=3]="OPEN",s[s.QUERY=4]="QUERY"})(y||(y={}));var g;(function(c){c[c.NONE=0]="NONE",c[c.OK=1]="OK",c[c.ERROR=2]="ERROR",c[c.START=3]="START",c[c.RUN=4]="RUN",c[c.CAPTURE=5]="CAPTURE"})(g||(g={}));var S;(function(s){s[s.NONE=0]="NONE",s[s.WEB_WORKER=1]="WEB_WORKER",s[s.NODE_WORKER=2]="NODE_WORKER",s[s.BINDINGS=3]="BINDINGS",s[s.ASYNC_DUCKDB=4]="ASYNC_DUCKDB"})(S||(S={}));var ee=class{log(e){}},re=class{log(e){console.log(e)}};function tr(n){switch(n){case 0:return"NONE";case 1:return"DEBUG";case 2:return"INFO";case 3:return"WARNING";case 4:return"ERROR";default:return"?"}}function nr(n){switch(n){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 sr(n){switch(n){case 1:return"CONNECT";case 2:return"DISCONNECT";case 3:return"OPEN";case 4:return"QUERY";default:return"?"}}function ir(n){switch(n){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"?"}}import{AsyncByteQueue as ne,RecordBatchReader as K,RecordBatchStreamWriter as se,Table as te}from"apache-arrow";var Y=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}},D=class{constructor(e,r){this._instance=e,this._conn=r}get instance(){return this._instance}async close(){return this._instance.disconnect(this._conn)}async runQuery(e){this._instance.logger.log({timestamp:new Date,level:R.INFO,origin:S.ASYNC_DUCKDB,topic:y.QUERY,event:g.RUN,value:e});let r=await this._instance.runQuery(this._conn,e),t=K.from(r);return console.assert(t.isSync()),console.assert(t.isFile()),te.from(t)}async sendQuery(e){this._instance.logger.log({timestamp:new Date,level:R.INFO,origin:S.ASYNC_DUCKDB,topic:y.QUERY,event:g.RUN,value:e});let r=await this._instance.sendQuery(this._conn,e),t=new Y(this._instance,this._conn,r),i=await K.from(t);return console.assert(i.isAsync()),console.assert(i.isStream()),i}async insertArrowTable(e,r){e.schema.fields.length==0&&console.warn("The schema is empty! If you used arrow.Table.from, consider constructing schema and batches manually"),await this.insertArrowBatches(e.schema,e.chunks,r)}async insertArrowBatches(e,r,t){let i=new ne,s=new se().reset(i,e);s.writeAll(r),s.close();let c=s.toUint8Array(!0);await this._instance.insertArrowFromIPCStream(this._conn,c,t)}async insertCSVFromPath(e,r){await this._instance.insertCSVFromPath(this._conn,e,r)}async insertJSONFromPath(e,r){await this._instance.insertJSONFromPath(this._conn,e,r)}};var o;(function(a){a.COLLECT_FILE_STATISTICS="COLLECT_FILE_STATISTICS",a.CONNECT="CONNECT",a.COPY_FILE_TO_BUFFER="COPY_FILE_TO_BUFFER",a.COPY_FILE_TO_PATH="COPY_FILE_TO_PATH",a.DISCONNECT="DISCONNECT",a.DROP_FILE="DROP_FILE",a.DROP_FILES="DROP_FILES",a.EXPORT_FILE_STATISTICS="EXPORT_FILE_STATISTICS",a.FETCH_QUERY_RESULTS="FETCH_QUERY_RESULTS",a.FLUSH_FILES="FLUSH_FILES",a.GET_FEATURE_FLAGS="GET_FEATURE_FLAGS",a.GET_VERSION="GET_VERSION",a.INSERT_ARROW_FROM_IPC_STREAM="INSERT_ARROW_FROM_IPC_STREAM",a.INSERT_CSV_FROM_PATH="IMPORT_CSV_FROM_PATH",a.INSERT_JSON_FROM_PATH="IMPORT_JSON_FROM_PATH",a.INSTANTIATE="INSTANTIATE",a.OPEN="OPEN",a.PING="PING",a.REGISTER_FILE_BUFFER="REGISTER_FILE_BUFFER",a.REGISTER_FILE_HANDLE="REGISTER_FILE_HANDLE",a.REGISTER_FILE_URL="REGISTER_FILE_URL",a.RESET="RESET",a.RUN_QUERY="RUN_QUERY",a.SEND_QUERY="SEND_QUERY",a.TOKENIZE="TOKENIZE"})(o||(o={}));var u;(function(d){d.CONNECTION_INFO="CONNECTION_INFO",d.ERROR="ERROR",d.FEATURE_FLAGS="FEATURE_FLAGS",d.FILE_BUFFER="FILE_BUFFER",d.FILE_SIZE="FILE_SIZE",d.FILE_STATISTICS="FILE_STATISTICS",d.LOG="LOG",d.OK="OK",d.QUERY_PLAN="QUERY_PLAN",d.QUERY_RESULT="QUERY_RESULT",d.QUERY_RESULT_CHUNK="QUERY_RESULT_CHUNK",d.QUERY_START="QUERY_START",d.REGISTERED_FILE="REGISTERED_FILE",d.SCRIPT_TOKENS="SCRIPT_TOKENS",d.SUCCESS="SUCCESS",d.VERSION_STRING="VERSION_STRING"})(u||(u={}));var m=class{constructor(e,r){this.promiseResolver=()=>{};this.promiseRejecter=()=>{};this.type=e,this.data=r,this.promise=new Promise((t,i)=>{this.promiseResolver=t,this.promiseRejecter=i})}};var ie=class{constructor(e,r=null){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}),await e.promise}onMessage(e){let r=e.data;r.type==u.LOG&&this._logger.log(r.data);let t=this._pendingRequests.get(r.requestId);if(!t){console.warn(`unassociated response: [${r.requestId}, ${r.type.toString()}]`);return}if(this._pendingRequests.delete(r.requestId),r.type==u.ERROR){let i=new Error(r.data.message);i.name=r.data.name,i.stack=r.data.stack,t.promiseRejecter(i);return}switch(t.type){case o.COLLECT_FILE_STATISTICS:case o.COPY_FILE_TO_PATH:case o.DISCONNECT:case o.DROP_FILES:case o.FLUSH_FILES:case o.INSERT_ARROW_FROM_IPC_STREAM:case o.INSERT_CSV_FROM_PATH:case o.INSERT_JSON_FROM_PATH:case o.INSTANTIATE:case o.OPEN:case o.PING:case o.REGISTER_FILE_BUFFER:case o.REGISTER_FILE_HANDLE:case o.REGISTER_FILE_URL:case o.RESET:if(r.type==u.OK){t.promiseResolver(r.data);return}break;case o.GET_VERSION:if(r.type==u.VERSION_STRING){t.promiseResolver(r.data);return}break;case o.GET_FEATURE_FLAGS:if(r.type==u.FEATURE_FLAGS){t.promiseResolver(r.data);return}break;case o.TOKENIZE:if(r.type==u.SCRIPT_TOKENS){t.promiseResolver(r.data);return}break;case o.DROP_FILE:if(r.type==u.SUCCESS){t.promiseResolver(r.data);return}break;case o.COPY_FILE_TO_BUFFER:if(r.type==u.FILE_BUFFER){t.promiseResolver(r.data);return}break;case o.EXPORT_FILE_STATISTICS:if(r.type==u.FILE_STATISTICS){t.promiseResolver(r.data);return}break;case o.CONNECT:if(r.type==u.CONNECTION_INFO){t.promiseResolver(r.data);return}break;case o.RUN_QUERY:if(r.type==u.QUERY_RESULT){t.promiseResolver(r.data);return}break;case o.SEND_QUERY:if(r.type==u.QUERY_START){t.promiseResolver(r.data);return}break;case o.FETCH_QUERY_RESULTS:if(r.type==u.QUERY_RESULT_CHUNK){t.promiseResolver(r.data);return}break}t.promiseRejecter(new Error(`unexpected response type: ${r.type.toString()}`))}onError(e){console.error(e),console.error(`error in duckdb worker: ${e.message}`),this._pendingRequests.clear()}onClose(){if(this._workerShutdownResolver(null),this._pendingRequests.size!=0){console.warn(`worker terminated with ${this._pendingRequests.size} pending requests`);return}this._pendingRequests.clear()}async reset(){let e=new m(o.RESET,null);return await this.postTask(e)}async ping(){let e=new m(o.PING,null);await this.postTask(e)}async dropFile(e){let r=new m(o.DROP_FILE,e);return await this.postTask(r)}async dropFiles(){let e=new m(o.DROP_FILES,null);return await this.postTask(e)}async flushFiles(){let e=new m(o.FLUSH_FILES,null);return await this.postTask(e)}async instantiate(e,r=null){let t=new m(o.INSTANTIATE,[e,r]);return await this.postTask(t)}async getVersion(){let e=new m(o.GET_VERSION,null);return await this.postTask(e)}async getFeatureFlags(){let e=new m(o.GET_FEATURE_FLAGS,null);return await this.postTask(e)}async open(e){let r=new m(o.OPEN,e);await this.postTask(r)}async tokenize(e){let r=new m(o.TOKENIZE,e);return await this.postTask(r)}async connectInternal(){let e=new m(o.CONNECT,null);return await this.postTask(e)}async connect(){let e=await this.connectInternal();return new D(this,e)}async disconnect(e){let r=new m(o.DISCONNECT,e);await this.postTask(r)}async runQuery(e,r){let t=new m(o.RUN_QUERY,[e,r]);return await this.postTask(t)}async sendQuery(e,r){let t=new m(o.SEND_QUERY,[e,r]);return await this.postTask(t)}async fetchQueryResults(e){let r=new m(o.FETCH_QUERY_RESULTS,e);return await this.postTask(r)}async registerFileURL(e,r){r===void 0&&(r=e);let t=new m(o.REGISTER_FILE_URL,[e,r]);await this.postTask(t)}async registerEmptyFileBuffer(e){let r=new m(o.REGISTER_FILE_BUFFER,[e,new Uint8Array]);await this.postTask(r)}async registerFileBuffer(e,r){let t=new m(o.REGISTER_FILE_BUFFER,[e,r]);await this.postTask(t,[r.buffer])}async registerFileHandle(e,r){let t=new m(o.REGISTER_FILE_HANDLE,[e,r]);await this.postTask(t,[])}async collectFileStatistics(e,r){let t=new m(o.COLLECT_FILE_STATISTICS,[e,r]);await this.postTask(t,[])}async exportFileStatistics(e){let r=new m(o.EXPORT_FILE_STATISTICS,e);return await this.postTask(r,[])}async copyFileToBuffer(e){let r=new m(o.COPY_FILE_TO_BUFFER,e);return await this.postTask(r)}async copyFileToPath(e,r){let t=new m(o.COPY_FILE_TO_PATH,[e,r]);await this.postTask(t)}async insertArrowFromIPCStream(e,r,t){let i=new m(o.INSERT_ARROW_FROM_IPC_STREAM,[e,r,t]);await this.postTask(i,[r.buffer])}async insertCSVFromPath(e,r,t){if(t.columns!==void 0){let s=[];for(let c in t.columns){let h=t.columns[c];s.push(I(c,h))}t.columnsFlat=s,delete t.columns}let i=new m(o.INSERT_CSV_FROM_PATH,[e,r,t]);await this.postTask(i)}async insertJSONFromPath(e,r,t){if(t.columns!==void 0){let s=[];for(let c in t.columns){let h=t.columns[c];s.push(I(c,h))}t.columnsFlat=s,delete t.columns}let i=new m(o.INSERT_JSON_FROM_PATH,[e,r,t]);await this.postTask(i)}};var oe=class{constructor(){this._bindings=null;this._nextMessageId=0}log(e){this.postMessage({messageId:this._nextMessageId++,requestId:0,type:u.LOG,data:e},[])}sendOK(e){this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.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:u.ERROR,data:t},[])}async onMessage(e){switch(e.type){case o.PING:this.sendOK(e);return;case o.INSTANTIATE:this._bindings!=null&&this.failWith(e,new Error("duckdb already initialized"));try{this._bindings=await this.instantiate(e.data[0],e.data[1]),this.sendOK(e)}catch(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 o.GET_VERSION:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.VERSION_STRING,data:this._bindings.getVersion()},[]);break;case o.GET_FEATURE_FLAGS:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.FEATURE_FLAGS,data:this._bindings.getFeatureFlags()},[]);break;case o.RESET:this._bindings.reset(),this.sendOK(e);break;case o.OPEN:this._bindings.open(e.data),this.sendOK(e);break;case o.DROP_FILE:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.SUCCESS,data:this._bindings.dropFile(e.data)},[]);break;case o.DROP_FILES:this._bindings.dropFiles(),this.sendOK(e);break;case o.FLUSH_FILES:this._bindings.flushFiles(),this.sendOK(e);break;case o.CONNECT:{let r=this._bindings.connect();this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.CONNECTION_INFO,data:r.handle},[]);break}case o.DISCONNECT:this._bindings.disconnect(e.data),this.sendOK(e);break;case o.RUN_QUERY:{let r=this._bindings.runQuery(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.QUERY_RESULT,data:r},[r.buffer]);break}case o.SEND_QUERY:{let r=this._bindings.sendQuery(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.QUERY_START,data:r},[r.buffer]);break}case o.FETCH_QUERY_RESULTS:{let r=this._bindings.fetchQueryResults(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.QUERY_RESULT_CHUNK,data:r},[r.buffer]);break}case o.REGISTER_FILE_URL:this._bindings.registerFileURL(e.data[0],e.data[1]),this.sendOK(e);break;case o.REGISTER_FILE_BUFFER:this._bindings.registerFileBuffer(e.data[0],e.data[1]),this.sendOK(e);break;case o.REGISTER_FILE_HANDLE:this._bindings.registerFileHandle(e.data[0],e.data[1]),this.sendOK(e);break;case o.COPY_FILE_TO_PATH:this._bindings.copyFileToPath(e.data[0],e.data[1]),this.sendOK(e);break;case o.COPY_FILE_TO_BUFFER:{let r=this._bindings.copyFileToBuffer(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.FILE_BUFFER,data:r},[]);break}case o.COLLECT_FILE_STATISTICS:this._bindings.collectFileStatistics(e.data[0],e.data[1]),this.sendOK(e);break;case o.EXPORT_FILE_STATISTICS:{this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.FILE_STATISTICS,data:this._bindings.exportFileStatistics(e.data)},[]);break}case o.INSERT_ARROW_FROM_IPC_STREAM:{this._bindings.insertArrowFromIPCStream(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case o.INSERT_CSV_FROM_PATH:{this._bindings.insertCSVFromPath(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case o.INSERT_JSON_FROM_PATH:{this._bindings.insertJSONFromPath(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case o.TOKENIZE:{let r=this._bindings.tokenize(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.SCRIPT_TOKENS,data:r},[]);break}}}catch(r){return this.failWith(e,r)}}};import{bulkMemory as we,exceptions as Ie,simd as fe,threads as ke}from"wasm-feature-detect";var ae="@duckdb/duckdb-wasm",ce="0.0.41-dev235.0",le="DuckDB powered by WebAssembly",de={type:"git",url:"https://github.com/duckdb/duckdb-wasm.git"},ue="MIT",me={"apache-arrow":"^4.0.0","wasm-feature-detect":"^1.2.11"},pe={"@types/emscripten":"^1.39.4","@types/jasmine":"^3.9.1","@typescript-eslint/eslint-plugin":"^4.33.0","@typescript-eslint/parser":"^4.33.0",esbuild:"^0.13.4",eslint:"^7.32.0","eslint-config-prettier":"^8.3.0","eslint-plugin-jasmine":"^4.1.2","eslint-plugin-prettier":"^4.0.0","eslint-plugin-react":"^7.26.1",jasmine:"3.9.0","jasmine-core":"^3.8.0","jasmine-spec-reporter":"^7.0.0",karma:"^6.3.4","karma-chrome-launcher":"^3.1.0","karma-coverage":"^2.0.3","karma-firefox-launcher":"^2.1.1","karma-jasmine":"^4.0.1","karma-jasmine-html-reporter":"^1.7.0","karma-sourcemap-loader":"^0.3.8","karma-spec-reporter":"^0.0.32","make-dir":"^3.1.0",nyc:"^15.1.0",prettier:"^2.4.1",puppeteer:"^10.4.0",rimraf:"^3.0.2",typedoc:"^0.22.5",typescript:"^4.4.3","web-worker":"^1.1.0"},_e={fsevents:"*"},Ee={"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 --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js","test:node:filter":'node --enable-source-maps --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js --filter="CSV"',"test:node:coverage":"nyc -r json --report-dir ./coverage/node node --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js","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:browsers":"karma start ./karma/tests-all.cjs","test: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 types"},he=["dist","!dist/types/test"],be="./dist/duckdb-node-async.js",Te="./dist/duckdb-node-async.d.ts",ge="./dist/duckdb-esm.js",Re={"./dist/duckdb-node-async.js":"./dist/duckdb-browser-async.js","temp-write":!1,worker_threads:!1,perf_hooks:!1,fs:!1,os:!1,path:!1,buffer:!1,crypto:!1},O={name:ae,version:ce,description:le,repository:de,license:ue,dependencies:me,devDependencies:pe,optionalDependencies:_e,scripts:Ee,files:he,main:be,types:Te,module:ge,browser:Re};var j=O.name,J=O.version,U=O.version.split("."),Cr=U[0],Pr=U[1],Dr=U[2];function N(n){let e=`importScripts("${n}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))}function Br(){let n=`https://cdn.jsdelivr.net/npm/${j}@${J}/dist/`;return{asyncDefault:{mainModule:`${n}duckdb.wasm`,mainWorker:N(`${n}duckdb-browser-async.worker.js`)},asyncNext:{mainModule:`${n}duckdb-next.wasm`,mainWorker:N(`${n}duckdb-browser-async-next.worker.js`)},asyncNextCOI:{mainModule:`${n}duckdb-next-coi.wasm`,mainWorker:N(`${n}duckdb-browser-async-next-coi.worker.js`),pthreadWorker:N(`${n}duckdb-browser-async-next-coi.pthread.worker.js`)}}}var L=null,v=null,B=null,M=null,W=null;function Se(){return typeof process!="undefined"&&process.release.name==="node"}async function ye(){return L==null&&(L=typeof BigInt64Array!="undefined"),v==null&&(v=await Ie()),B==null&&(B=await ke()),M==null&&(M=await fe()),W==null&&(W=await we()),{bigInt64Array:L,crossOriginIsolated:Se()||globalThis.crossOriginIsolated||!1,wasmExceptions:v,wasmSIMD:M,wasmThreads:B,wasmBulkMemory:W}}async function Mr(n){let e=await ye();if(e.wasmExceptions&&e.wasmSIMD){if(e.wasmThreads&&e.crossOriginIsolated&&n.asyncNextCOI)return{mainModule:n.asyncNextCOI.mainModule,mainWorker:n.asyncNextCOI.mainWorker,pthreadWorker:n.asyncNextCOI.pthreadWorker};if(n.asyncNext)return{mainModule:n.asyncNext.mainModule,mainWorker:n.asyncNext.mainWorker,pthreadWorker:null}}return{mainModule:n.asyncDefault.mainModule,mainWorker:n.asyncDefault.mainWorker,pthreadWorker:null}}export{ie as AsyncDuckDB,D as AsyncDuckDBConnection,oe as AsyncDuckDBDispatcher,re as ConsoleLogger,Ce as DEFAULT_RUNTIME,X as DuckDBBindings,C as DuckDBConnection,G as DuckDBDataProtocol,H as DuckDBFeature,P as FileStatistics,Q as InsertMode,V as JSONTableShape,g as LogEvent,R as LogLevel,S as LogOrigin,y as LogTopic,j as PACKAGE_NAME,J as PACKAGE_VERSION,Cr as PACKAGE_VERSION_MAJOR,Pr as PACKAGE_VERSION_MINOR,Dr as PACKAGE_VERSION_PATCH,p as StatusCode,ee as VoidLogger,o as WorkerRequestType,u as WorkerResponseType,m as WorkerTask,E as callSRet,w as copyBuffer,Z as decodeText,b as dropResponseBuffers,Ae as failWith,Br as getJsDelivrBundles,nr as getLogEventLabel,tr as getLogLevelLabel,ir as getLogOriginLabel,sr as getLogTopicLabel,ye as getPlatformFeatures,_ as readString,Mr as selectBundle};
import{AsyncByteQueue as z,RecordBatchReader as F,RecordBatchStreamWriter as q,Table as x}from"apache-arrow";var A=class{constructor(e,r,t){this.bindings=e;this.conn=r;this.header=t;this._first=!0,this._depleted=!1}next(){if(this._first)return this._first=!1,{done:!1,value:this.header};if(this._depleted)return{done:!0,value:null};let e=this.bindings.fetchQueryResults(this.conn);return this._depleted=e.length==0,{done:this._depleted,value:e}}[Symbol.iterator](){return this}},C=class{constructor(e,r){this._bindings=e,this._conn=r}get handle(){return this._conn}close(){this._bindings.disconnect(this._conn)}runQuery(e){let r=this._bindings.runQuery(this._conn,e),t=F.from(r);return console.assert(t.isSync()),console.assert(t.isFile()),x.from(t)}sendQuery(e){let r=this._bindings.sendQuery(this._conn,e),t=new A(this._bindings,this._conn,r),i=F.from(t);return console.assert(i.isSync()),console.assert(i.isStream()),i}createPreparedStatement(e){return this._bindings.createPreparedStatement(this._conn,e)}closePreparedStatement(e){this._bindings.closePreparedStatement(this._conn,e)}runPreparedStatement(e,r){let t=this._bindings.runPreparedStatement(this._conn,e,r),i=F.from(t);return console.assert(i.isSync()),console.assert(i.isFile()),x.from(i)}sendPreparedStatement(e,r){let t=this._bindings.sendPreparedStatement(this._conn,e,r),i=new A(this._bindings,this._conn,t),s=F.from(i);return console.assert(s.isSync()),console.assert(s.isStream()),s}insertArrowTable(e,r){e.schema.fields.length==0&&console.warn("The schema is empty! If you used arrow.Table.from, consider constructing schema and batches manually"),this.insertArrowBatches(e.schema,e.chunks,r)}insertArrowBatches(e,r,t){e.fields.length==0&&console.warn("The schema is empty! If you used arrow.Table.from, consider constructing schema and batches manually");let i=new z,s=new q().reset(i,e);s.writeAll(r),s.close();let c=s.toUint8Array(!0);this._bindings.insertArrowFromIPCStream(this._conn,c,t)}insertCSVFromPath(e,r){this._bindings.insertCSVFromPath(this._conn,e,r)}insertJSONFromPath(e,r){this._bindings.insertJSONFromPath(this._conn,e,r)}};var p;(function(e){e[e.SUCCESS=0]="SUCCESS"})(p||(p={}));function $(){let n=new TextDecoder;return e=>(typeof SharedArrayBuffer!="undefined"&&e.buffer instanceof SharedArrayBuffer&&(e=new Uint8Array(e)),n.decode(e))}var Z=$();function Ae(n,e){console.error(e),n.ccall("duckdb_web_fail_with",null,["string"],[e])}function w(n,e,r){let t=n.HEAPU8.subarray(e,e+r),i=new Uint8Array(new ArrayBuffer(t.byteLength));return i.set(t),i}function _(n,e,r){return Z(n.HEAPU8.subarray(e,e+r))}var G;(function(t){t[t.BUFFER=0]="BUFFER",t[t.NATIVE=1]="NATIVE",t[t.HTTP=3]="HTTP"})(G||(G={}));function E(n,e,r,t){let i=n.stackSave(),s=n.stackAlloc(3*8);r.unshift("number"),t.unshift(s),n.ccall(e,null,r,t);let c=n.HEAPF64[(s>>3)+0],h=n.HEAPF64[(s>>3)+1],k=n.HEAPF64[(s>>3)+2];return n.stackRestore(i),[c,h,k]}function b(n){n.ccall("duckdb_web_clear_response",null,[],[])}var Ce={testPlatformFeature:(n,e)=>!1,openFile:(n,e)=>{},syncFile:(n,e)=>{},closeFile:(n,e)=>{},getLastFileModificationTime:(n,e)=>0,getFileSize:(n,e)=>0,truncateFile:(n,e,r)=>{},readFile:(n,e,r,t,i)=>0,writeFile:(n,e,r,t,i)=>0,removeDirectory:(n,e,r)=>{},checkDirectory:(n,e,r)=>!1,createDirectory:(n,e,r)=>{},listDirectoryEntries:(n,e,r)=>!1,glob:(n,e,r)=>{},moveFile:(n,e,r,t,i)=>{},checkFile:(n,e,r)=>!1,removeFile:(n,e,r)=>{}};var P=class{constructor(e){let r=new Float64Array(e.buffer,e.byteOffset,e.byteLength/8),t=new Uint8Array(new ArrayBuffer(e.byteLength));t.set(e.subarray(7*8)),this.totalFileReadsCold=r[0],this.totalFileReadsAhead=r[1],this.totalFileReadsCached=r[2],this.totalFileWrites=r[3],this.totalPageAccesses=r[4],this.totalPageLoads=r[5],this.blockSize=r[6],this.blockStats=t}getBlockStats(e,r){return r=r||{file_reads_cold:0,file_reads_ahead:0,file_reads_cached:0,file_writes:0,page_accesses:0,page_loads:0},r.file_writes=this.blockStats[e*3+0]&15,r.file_reads_cold=this.blockStats[e*3+0]>>4,r.file_reads_ahead=this.blockStats[e*3+1]&15,r.file_reads_cached=this.blockStats[e*3+1]>>4,r.page_accesses=this.blockStats[e*3+1]&15,r.page_loads=this.blockStats[e*3+1]>>4,r}};import{Type as l}from"apache-arrow";function I(n,e){switch(e.typeId){case l.Binary:return{name:n,type:"binary"};case l.Bool:return{name:n,type:"bool"};case l.Date:return{name:n,type:"date"};case l.DateDay:return{name:n,type:"date32[d]"};case l.DateMillisecond:return{name:n,type:"date64[ms]"};case l.Decimal:{let r=e;return{name:n,type:"decimal",precision:r.precision,scale:r.scale}}case l.Float:return{name:n,type:"float"};case l.Float16:return{name:n,type:"float16"};case l.Float32:return{name:n,type:"float32"};case l.Float64:return{name:n,type:"float64"};case l.Int:return{name:n,type:"int32"};case l.Int16:return{name:n,type:"int16"};case l.Int32:return{name:n,type:"int32"};case l.Int64:return{name:n,type:"int64"};case l.Uint16:return{name:n,type:"uint16"};case l.Uint32:return{name:n,type:"uint32"};case l.Uint64:return{name:n,type:"uint64"};case l.Uint8:return{name:n,type:"uint8"};case l.IntervalDayTime:return{name:n,type:"interval[dt]"};case l.IntervalYearMonth:return{name:n,type:"interval[m]"};case l.List:{let r=e;return{name:n,type:"list",children:[I(r.valueField.name,r.valueField.type)]}}case l.FixedSizeBinary:return{name:n,type:"fixedsizebinary",byteWidth:e.byteWidth};case l.Null:return{name:n,type:"null"};case l.Utf8:return{name:n,type:"utf8"};case l.Struct:return{name:n,type:"struct",children:e.children.map(t=>I(t.name,t.type))};case l.Time:return{name:n,type:"time[s]"};case l.TimeMicrosecond:return{name:n,type:"time[us]"};case l.TimeMillisecond:return{name:n,type:"time[ms]"};case l.TimeNanosecond:return{name:n,type:"time[ns]"};case l.TimeSecond:return{name:n,type:"time[s]"};case l.Timestamp:return{name:n,type:"timestamp",timezone:e.timezone||void 0};case l.TimestampSecond:return{name:n,type:"timestamp[s]",timezone:e.timezone||void 0};case l.TimestampMicrosecond:return{name:n,type:"timestamp[us]",timezone:e.timezone||void 0};case l.TimestampNanosecond:return{name:n,type:"timestamp[ns]",timezone:e.timezone||void 0};case l.TimestampMillisecond:return{name:n,type:"timestamp[ms]",timezone:e.timezone||void 0}}throw new Error(`unsupported arrow type: ${e.toString()}`)}var H;(function(s){s[s.WASM_EXCEPTIONS=1]="WASM_EXCEPTIONS",s[s.WASM_THREADS=2]="WASM_THREADS",s[s.WASM_SIMD=4]="WASM_SIMD",s[s.WASM_BULK_MEMORY=8]="WASM_BULK_MEMORY",s[s.EMIT_BIGINT=16]="EMIT_BIGINT"})(H||(H={}));var X=class{constructor(e,r){this._instance=null;this._initPromise=null;this._initPromiseResolver=()=>{};this._logger=e,this._runtime=r}get logger(){return this._logger}get mod(){return this._instance}get pthread(){return this.mod.PThread||null}async instantiate(){return this._instance!=null?this:(this._initPromise!=null&&await this._initPromise,this._initPromise=new Promise(e=>{this._initPromiseResolver=e}),this._instance=await this.instantiateImpl({print:console.log.bind(console),printErr:console.log.bind(console),onRuntimeInitialized:this._initPromiseResolver}),await this._initPromise,this._initPromise=null,this)}open(e){let[r,t,i]=E(this.mod,"duckdb_web_open",["string"],[JSON.stringify(e)]);if(r!==p.SUCCESS)throw new Error(_(this.mod,t,i));b(this.mod)}reset(){let[e,r,t]=E(this.mod,"duckdb_web_reset",[],[]);if(e!==p.SUCCESS)throw new Error(_(this.mod,r,t));b(this.mod)}getVersion(){let[e,r,t]=E(this.mod,"duckdb_web_get_version",[],[]);if(e!==p.SUCCESS)throw new Error(_(this.mod,r,t));let i=_(this.mod,r,t);return b(this.mod),i}getFeatureFlags(){return this.mod.ccall("duckdb_web_get_feature_flags","number",[],[])}tokenize(e){let[r,t,i]=E(this.mod,"duckdb_web_tokenize",["string"],[e]);if(r!==p.SUCCESS)throw new Error(_(this.mod,t,i));let s=_(this.mod,t,i);return b(this.mod),JSON.parse(s)}connect(){let e=this.mod.ccall("duckdb_web_connect","number",[],[]);return new C(this,e)}disconnect(e){this.mod.ccall("duckdb_web_disconnect",null,["number"],[e])}runQuery(e,r){let[t,i,s]=E(this.mod,"duckdb_web_query_run",["number","string"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));let c=w(this.mod,i,s);return b(this.mod),c}sendQuery(e,r){let[t,i,s]=E(this.mod,"duckdb_web_query_send",["number","string"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));let c=w(this.mod,i,s);return b(this.mod),c}fetchQueryResults(e){let[r,t,i]=E(this.mod,"duckdb_web_query_fetch_results",["number"],[e]);if(r!==p.SUCCESS)throw new Error(_(this.mod,t,i));let s=w(this.mod,t,i);return b(this.mod),s}createPreparedStatement(e,r){let[t,i,s]=E(this.mod,"duckdb_web_prepared_statement_create",["number","string"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));return b(this.mod),i}closePreparedStatement(e,r){let[t,i,s]=E(this.mod,"duckdb_web_prepared_statement_close",["number","number"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));b(this.mod)}runPreparedStatement(e,r,t){let[i,s,c]=E(this.mod,"duckdb_web_prepared_statement_run",["number","number","string"],[e,r,JSON.stringify(t)]);if(i!==p.SUCCESS)throw new Error(_(this.mod,s,c));let h=w(this.mod,s,c);return b(this.mod),h}sendPreparedStatement(e,r,t){let[i,s,c]=E(this.mod,"duckdb_web_prepared_statement_send",["number","number","string"],[e,r,JSON.stringify(t)]);if(i!==p.SUCCESS)throw new Error(_(this.mod,s,c));let h=w(this.mod,s,c);return b(this.mod),h}insertArrowFromIPCStream(e,r,t){let i=this.mod._malloc(r.length);this.mod.HEAPU8.subarray(i,i+r.length).set(r);let c=t?JSON.stringify(t):"",[h,k,f]=E(this.mod,"duckdb_web_insert_arrow_from_ipc_stream",["number","number","number","string"],[e,i,r.length,c]);if(h!==p.SUCCESS)throw new Error(_(this.mod,k,f))}insertCSVFromPath(e,r,t){if(t.columns!==void 0){t.columnsFlat=[];for(let f in t.columns)t.columnsFlat.push(I(f,t.columns[f]))}let i={...t};i.columns=i.columnsFlat,delete i.columnsFlat;let s=JSON.stringify(i),[c,h,k]=E(this.mod,"duckdb_web_insert_csv_from_path",["number","string","string"],[e,r,s]);if(c!==p.SUCCESS)throw new Error(_(this.mod,h,k))}insertJSONFromPath(e,r,t){if(t.columns!==void 0){t.columnsFlat=[];for(let f in t.columns)t.columnsFlat.push(I(f,t.columns[f]))}let i={...t};i.columns=i.columnsFlat,delete i.columnsFlat;let s=JSON.stringify(i),[c,h,k]=E(this.mod,"duckdb_web_insert_json_from_path",["number","string","string"],[e,r,s]);if(c!==p.SUCCESS)throw new Error(_(this.mod,h,k))}finishInsert(e,r){}registerFileURL(e,r){r===void 0&&(r=e);let[t,i,s]=E(this.mod,"duckdb_web_fs_register_file_url",["string","string"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));b(this.mod)}registerFileBuffer(e,r){let t=this.mod._malloc(r.length);this.mod.HEAPU8.subarray(t,t+r.length).set(r);let[s,c,h]=E(this.mod,"duckdb_web_fs_register_file_buffer",["string","number","number"],[e,t,r.length]);if(s!==p.SUCCESS)throw new Error(_(this.mod,c,h));b(this.mod)}registerFileHandle(e,r){let[t,i,s]=E(this.mod,"duckdb_web_fs_register_file_url",["string","string"],[e,e]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));if(b(this.mod),globalThis.DUCKDB_RUNTIME._files=(globalThis.DUCKDB_RUNTIME._files||new Map).set(e,r),this.pthread){for(let c of this.pthread.runningWorkers)c.postMessage({cmd:"registerFileHandle",fileName:e,fileHandle:r});for(let c of this.pthread.unusedWorkers)c.postMessage({cmd:"dropFileHandle",fileName:e})}}dropFile(e){return this.mod.ccall("duckdb_web_fs_drop_file","boolean",["string"],[e])}dropFiles(){this.mod.ccall("duckdb_web_fs_drop_files",null,[],[])}flushFiles(){this.mod.ccall("duckdb_web_flush_files",null,[],[])}copyFileToPath(e,r){let[t,i,s]=E(this.mod,"duckdb_web_copy_file_to_path",["string","string"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s));b(this.mod)}copyFileToBuffer(e){let[r,t,i]=E(this.mod,"duckdb_web_copy_file_to_buffer",["string"],[e]);if(r!==p.SUCCESS)throw new Error(_(this.mod,t,i));let s=this.mod.HEAPU8.subarray(t,t+i),c=new Uint8Array(s.length);return c.set(s),b(this.mod),c}collectFileStatistics(e,r){let[t,i,s]=E(this.mod,"duckdb_web_collect_file_stats",["string","boolean"],[e,r]);if(t!==p.SUCCESS)throw new Error(_(this.mod,i,s))}exportFileStatistics(e){let[r,t,i]=E(this.mod,"duckdb_web_export_file_stats",["string"],[e]);if(r!==p.SUCCESS)throw new Error(_(this.mod,t,i));return new P(this.mod.HEAPU8.subarray(t,t+i))}};var V;(function(r){r.ROW_ARRAY="row-array",r.COLUMN_OBJECT="column-object"})(V||(V={}));var Q;(function(r){r[r.APPEND=0]="APPEND",r[r.IMPORT=1]="IMPORT"})(Q||(Q={}));var R;(function(s){s[s.NONE=0]="NONE",s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARNING=3]="WARNING",s[s.ERROR=4]="ERROR"})(R||(R={}));var y;(function(s){s[s.NONE=0]="NONE",s[s.CONNECT=1]="CONNECT",s[s.DISCONNECT=2]="DISCONNECT",s[s.OPEN=3]="OPEN",s[s.QUERY=4]="QUERY"})(y||(y={}));var g;(function(c){c[c.NONE=0]="NONE",c[c.OK=1]="OK",c[c.ERROR=2]="ERROR",c[c.START=3]="START",c[c.RUN=4]="RUN",c[c.CAPTURE=5]="CAPTURE"})(g||(g={}));var S;(function(s){s[s.NONE=0]="NONE",s[s.WEB_WORKER=1]="WEB_WORKER",s[s.NODE_WORKER=2]="NODE_WORKER",s[s.BINDINGS=3]="BINDINGS",s[s.ASYNC_DUCKDB=4]="ASYNC_DUCKDB"})(S||(S={}));var ee=class{log(e){}},re=class{log(e){console.log(e)}};function tr(n){switch(n){case 0:return"NONE";case 1:return"DEBUG";case 2:return"INFO";case 3:return"WARNING";case 4:return"ERROR";default:return"?"}}function nr(n){switch(n){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 sr(n){switch(n){case 1:return"CONNECT";case 2:return"DISCONNECT";case 3:return"OPEN";case 4:return"QUERY";default:return"?"}}function ir(n){switch(n){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"?"}}import{AsyncByteQueue as ne,RecordBatchReader as K,RecordBatchStreamWriter as se,Table as te}from"apache-arrow";var Y=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}},D=class{constructor(e,r){this._instance=e,this._conn=r}get instance(){return this._instance}async close(){return this._instance.disconnect(this._conn)}async runQuery(e){this._instance.logger.log({timestamp:new Date,level:R.INFO,origin:S.ASYNC_DUCKDB,topic:y.QUERY,event:g.RUN,value:e});let r=await this._instance.runQuery(this._conn,e),t=K.from(r);return console.assert(t.isSync()),console.assert(t.isFile()),te.from(t)}async sendQuery(e){this._instance.logger.log({timestamp:new Date,level:R.INFO,origin:S.ASYNC_DUCKDB,topic:y.QUERY,event:g.RUN,value:e});let r=await this._instance.sendQuery(this._conn,e),t=new Y(this._instance,this._conn,r),i=await K.from(t);return console.assert(i.isAsync()),console.assert(i.isStream()),i}async insertArrowTable(e,r){e.schema.fields.length==0&&console.warn("The schema is empty! If you used arrow.Table.from, consider constructing schema and batches manually"),await this.insertArrowBatches(e.schema,e.chunks,r)}async insertArrowBatches(e,r,t){let i=new ne,s=new se().reset(i,e);s.writeAll(r),s.close();let c=s.toUint8Array(!0);await this._instance.insertArrowFromIPCStream(this._conn,c,t)}async insertCSVFromPath(e,r){await this._instance.insertCSVFromPath(this._conn,e,r)}async insertJSONFromPath(e,r){await this._instance.insertJSONFromPath(this._conn,e,r)}};var o;(function(a){a.COLLECT_FILE_STATISTICS="COLLECT_FILE_STATISTICS",a.CONNECT="CONNECT",a.COPY_FILE_TO_BUFFER="COPY_FILE_TO_BUFFER",a.COPY_FILE_TO_PATH="COPY_FILE_TO_PATH",a.DISCONNECT="DISCONNECT",a.DROP_FILE="DROP_FILE",a.DROP_FILES="DROP_FILES",a.EXPORT_FILE_STATISTICS="EXPORT_FILE_STATISTICS",a.FETCH_QUERY_RESULTS="FETCH_QUERY_RESULTS",a.FLUSH_FILES="FLUSH_FILES",a.GET_FEATURE_FLAGS="GET_FEATURE_FLAGS",a.GET_VERSION="GET_VERSION",a.INSERT_ARROW_FROM_IPC_STREAM="INSERT_ARROW_FROM_IPC_STREAM",a.INSERT_CSV_FROM_PATH="IMPORT_CSV_FROM_PATH",a.INSERT_JSON_FROM_PATH="IMPORT_JSON_FROM_PATH",a.INSTANTIATE="INSTANTIATE",a.OPEN="OPEN",a.PING="PING",a.REGISTER_FILE_BUFFER="REGISTER_FILE_BUFFER",a.REGISTER_FILE_HANDLE="REGISTER_FILE_HANDLE",a.REGISTER_FILE_URL="REGISTER_FILE_URL",a.RESET="RESET",a.RUN_QUERY="RUN_QUERY",a.SEND_QUERY="SEND_QUERY",a.TOKENIZE="TOKENIZE"})(o||(o={}));var u;(function(d){d.CONNECTION_INFO="CONNECTION_INFO",d.ERROR="ERROR",d.FEATURE_FLAGS="FEATURE_FLAGS",d.FILE_BUFFER="FILE_BUFFER",d.FILE_SIZE="FILE_SIZE",d.FILE_STATISTICS="FILE_STATISTICS",d.LOG="LOG",d.OK="OK",d.QUERY_PLAN="QUERY_PLAN",d.QUERY_RESULT="QUERY_RESULT",d.QUERY_RESULT_CHUNK="QUERY_RESULT_CHUNK",d.QUERY_START="QUERY_START",d.REGISTERED_FILE="REGISTERED_FILE",d.SCRIPT_TOKENS="SCRIPT_TOKENS",d.SUCCESS="SUCCESS",d.VERSION_STRING="VERSION_STRING"})(u||(u={}));var m=class{constructor(e,r){this.promiseResolver=()=>{};this.promiseRejecter=()=>{};this.type=e,this.data=r,this.promise=new Promise((t,i)=>{this.promiseResolver=t,this.promiseRejecter=i})}};var ie=class{constructor(e,r=null){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}),await e.promise}onMessage(e){let r=e.data;r.type==u.LOG&&this._logger.log(r.data);let t=this._pendingRequests.get(r.requestId);if(!t){console.warn(`unassociated response: [${r.requestId}, ${r.type.toString()}]`);return}if(this._pendingRequests.delete(r.requestId),r.type==u.ERROR){let i=new Error(r.data.message);i.name=r.data.name,i.stack=r.data.stack,t.promiseRejecter(i);return}switch(t.type){case o.COLLECT_FILE_STATISTICS:case o.COPY_FILE_TO_PATH:case o.DISCONNECT:case o.DROP_FILES:case o.FLUSH_FILES:case o.INSERT_ARROW_FROM_IPC_STREAM:case o.INSERT_CSV_FROM_PATH:case o.INSERT_JSON_FROM_PATH:case o.INSTANTIATE:case o.OPEN:case o.PING:case o.REGISTER_FILE_BUFFER:case o.REGISTER_FILE_HANDLE:case o.REGISTER_FILE_URL:case o.RESET:if(r.type==u.OK){t.promiseResolver(r.data);return}break;case o.GET_VERSION:if(r.type==u.VERSION_STRING){t.promiseResolver(r.data);return}break;case o.GET_FEATURE_FLAGS:if(r.type==u.FEATURE_FLAGS){t.promiseResolver(r.data);return}break;case o.TOKENIZE:if(r.type==u.SCRIPT_TOKENS){t.promiseResolver(r.data);return}break;case o.DROP_FILE:if(r.type==u.SUCCESS){t.promiseResolver(r.data);return}break;case o.COPY_FILE_TO_BUFFER:if(r.type==u.FILE_BUFFER){t.promiseResolver(r.data);return}break;case o.EXPORT_FILE_STATISTICS:if(r.type==u.FILE_STATISTICS){t.promiseResolver(r.data);return}break;case o.CONNECT:if(r.type==u.CONNECTION_INFO){t.promiseResolver(r.data);return}break;case o.RUN_QUERY:if(r.type==u.QUERY_RESULT){t.promiseResolver(r.data);return}break;case o.SEND_QUERY:if(r.type==u.QUERY_START){t.promiseResolver(r.data);return}break;case o.FETCH_QUERY_RESULTS:if(r.type==u.QUERY_RESULT_CHUNK){t.promiseResolver(r.data);return}break}t.promiseRejecter(new Error(`unexpected response type: ${r.type.toString()}`))}onError(e){console.error(e),console.error(`error in duckdb worker: ${e.message}`),this._pendingRequests.clear()}onClose(){if(this._workerShutdownResolver(null),this._pendingRequests.size!=0){console.warn(`worker terminated with ${this._pendingRequests.size} pending requests`);return}this._pendingRequests.clear()}async reset(){let e=new m(o.RESET,null);return await this.postTask(e)}async ping(){let e=new m(o.PING,null);await this.postTask(e)}async dropFile(e){let r=new m(o.DROP_FILE,e);return await this.postTask(r)}async dropFiles(){let e=new m(o.DROP_FILES,null);return await this.postTask(e)}async flushFiles(){let e=new m(o.FLUSH_FILES,null);return await this.postTask(e)}async instantiate(e,r=null){let t=new m(o.INSTANTIATE,[e,r]);return await this.postTask(t)}async getVersion(){let e=new m(o.GET_VERSION,null);return await this.postTask(e)}async getFeatureFlags(){let e=new m(o.GET_FEATURE_FLAGS,null);return await this.postTask(e)}async open(e){let r=new m(o.OPEN,e);await this.postTask(r)}async tokenize(e){let r=new m(o.TOKENIZE,e);return await this.postTask(r)}async connectInternal(){let e=new m(o.CONNECT,null);return await this.postTask(e)}async connect(){let e=await this.connectInternal();return new D(this,e)}async disconnect(e){let r=new m(o.DISCONNECT,e);await this.postTask(r)}async runQuery(e,r){let t=new m(o.RUN_QUERY,[e,r]);return await this.postTask(t)}async sendQuery(e,r){let t=new m(o.SEND_QUERY,[e,r]);return await this.postTask(t)}async fetchQueryResults(e){let r=new m(o.FETCH_QUERY_RESULTS,e);return await this.postTask(r)}async registerFileURL(e,r){r===void 0&&(r=e);let t=new m(o.REGISTER_FILE_URL,[e,r]);await this.postTask(t)}async registerEmptyFileBuffer(e){let r=new m(o.REGISTER_FILE_BUFFER,[e,new Uint8Array]);await this.postTask(r)}async registerFileBuffer(e,r){let t=new m(o.REGISTER_FILE_BUFFER,[e,r]);await this.postTask(t,[r.buffer])}async registerFileHandle(e,r){let t=new m(o.REGISTER_FILE_HANDLE,[e,r]);await this.postTask(t,[])}async collectFileStatistics(e,r){let t=new m(o.COLLECT_FILE_STATISTICS,[e,r]);await this.postTask(t,[])}async exportFileStatistics(e){let r=new m(o.EXPORT_FILE_STATISTICS,e);return await this.postTask(r,[])}async copyFileToBuffer(e){let r=new m(o.COPY_FILE_TO_BUFFER,e);return await this.postTask(r)}async copyFileToPath(e,r){let t=new m(o.COPY_FILE_TO_PATH,[e,r]);await this.postTask(t)}async insertArrowFromIPCStream(e,r,t){let i=new m(o.INSERT_ARROW_FROM_IPC_STREAM,[e,r,t]);await this.postTask(i,[r.buffer])}async insertCSVFromPath(e,r,t){if(t.columns!==void 0){let s=[];for(let c in t.columns){let h=t.columns[c];s.push(I(c,h))}t.columnsFlat=s,delete t.columns}let i=new m(o.INSERT_CSV_FROM_PATH,[e,r,t]);await this.postTask(i)}async insertJSONFromPath(e,r,t){if(t.columns!==void 0){let s=[];for(let c in t.columns){let h=t.columns[c];s.push(I(c,h))}t.columnsFlat=s,delete t.columns}let i=new m(o.INSERT_JSON_FROM_PATH,[e,r,t]);await this.postTask(i)}};var oe=class{constructor(){this._bindings=null;this._nextMessageId=0}log(e){this.postMessage({messageId:this._nextMessageId++,requestId:0,type:u.LOG,data:e},[])}sendOK(e){this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.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:u.ERROR,data:t},[])}async onMessage(e){switch(e.type){case o.PING:this.sendOK(e);return;case o.INSTANTIATE:this._bindings!=null&&this.failWith(e,new Error("duckdb already initialized"));try{this._bindings=await this.instantiate(e.data[0],e.data[1]),this.sendOK(e)}catch(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 o.GET_VERSION:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.VERSION_STRING,data:this._bindings.getVersion()},[]);break;case o.GET_FEATURE_FLAGS:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.FEATURE_FLAGS,data:this._bindings.getFeatureFlags()},[]);break;case o.RESET:this._bindings.reset(),this.sendOK(e);break;case o.OPEN:this._bindings.open(e.data),this.sendOK(e);break;case o.DROP_FILE:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.SUCCESS,data:this._bindings.dropFile(e.data)},[]);break;case o.DROP_FILES:this._bindings.dropFiles(),this.sendOK(e);break;case o.FLUSH_FILES:this._bindings.flushFiles(),this.sendOK(e);break;case o.CONNECT:{let r=this._bindings.connect();this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.CONNECTION_INFO,data:r.handle},[]);break}case o.DISCONNECT:this._bindings.disconnect(e.data),this.sendOK(e);break;case o.RUN_QUERY:{let r=this._bindings.runQuery(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.QUERY_RESULT,data:r},[r.buffer]);break}case o.SEND_QUERY:{let r=this._bindings.sendQuery(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.QUERY_START,data:r},[r.buffer]);break}case o.FETCH_QUERY_RESULTS:{let r=this._bindings.fetchQueryResults(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.QUERY_RESULT_CHUNK,data:r},[r.buffer]);break}case o.REGISTER_FILE_URL:this._bindings.registerFileURL(e.data[0],e.data[1]),this.sendOK(e);break;case o.REGISTER_FILE_BUFFER:this._bindings.registerFileBuffer(e.data[0],e.data[1]),this.sendOK(e);break;case o.REGISTER_FILE_HANDLE:this._bindings.registerFileHandle(e.data[0],e.data[1]),this.sendOK(e);break;case o.COPY_FILE_TO_PATH:this._bindings.copyFileToPath(e.data[0],e.data[1]),this.sendOK(e);break;case o.COPY_FILE_TO_BUFFER:{let r=this._bindings.copyFileToBuffer(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.FILE_BUFFER,data:r},[]);break}case o.COLLECT_FILE_STATISTICS:this._bindings.collectFileStatistics(e.data[0],e.data[1]),this.sendOK(e);break;case o.EXPORT_FILE_STATISTICS:{this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.FILE_STATISTICS,data:this._bindings.exportFileStatistics(e.data)},[]);break}case o.INSERT_ARROW_FROM_IPC_STREAM:{this._bindings.insertArrowFromIPCStream(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case o.INSERT_CSV_FROM_PATH:{this._bindings.insertCSVFromPath(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case o.INSERT_JSON_FROM_PATH:{this._bindings.insertJSONFromPath(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case o.TOKENIZE:{let r=this._bindings.tokenize(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:u.SCRIPT_TOKENS,data:r},[]);break}}}catch(r){return this.failWith(e,r)}}};import{bulkMemory as we,exceptions as Ie,simd as fe,threads as ke}from"wasm-feature-detect";var ae="@duckdb/duckdb-wasm",ce="0.0.41-dev242.0",le="DuckDB powered by WebAssembly",de={type:"git",url:"https://github.com/duckdb/duckdb-wasm.git"},ue="MIT",me={"apache-arrow":"^4.0.0","wasm-feature-detect":"^1.2.11"},pe={"@types/emscripten":"^1.39.4","@types/jasmine":"^3.9.1","@typescript-eslint/eslint-plugin":"^4.33.0","@typescript-eslint/parser":"^4.33.0",esbuild:"^0.13.4",eslint:"^7.32.0","eslint-config-prettier":"^8.3.0","eslint-plugin-jasmine":"^4.1.2","eslint-plugin-prettier":"^4.0.0","eslint-plugin-react":"^7.26.1",jasmine:"3.9.0","jasmine-core":"^3.8.0","jasmine-spec-reporter":"^7.0.0",karma:"^6.3.4","karma-chrome-launcher":"^3.1.0","karma-coverage":"^2.0.3","karma-firefox-launcher":"^2.1.1","karma-jasmine":"^4.0.1","karma-jasmine-html-reporter":"^1.7.0","karma-sourcemap-loader":"^0.3.8","karma-spec-reporter":"^0.0.32","make-dir":"^3.1.0",nyc:"^15.1.0",prettier:"^2.4.1",puppeteer:"^10.4.0",rimraf:"^3.0.2",typedoc:"^0.22.5",typescript:"^4.4.3","web-worker":"^1.1.0"},_e={fsevents:"*"},Ee={"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 --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js","test:node:filter":'node --enable-source-maps --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js --filter="CSV"',"test:node:coverage":"nyc -r json --report-dir ./coverage/node node --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js","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:browsers":"karma start ./karma/tests-all.cjs","test: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 types"},he=["dist","!dist/types/test"],be="./dist/duckdb-node-async.js",Te="./dist/duckdb-node-async.d.ts",ge="./dist/duckdb-esm.js",Re={"./dist/duckdb-node-async.js":"./dist/duckdb-browser-async.js","temp-write":!1,worker_threads:!1,perf_hooks:!1,fs:!1,os:!1,path:!1,buffer:!1,crypto:!1},O={name:ae,version:ce,description:le,repository:de,license:ue,dependencies:me,devDependencies:pe,optionalDependencies:_e,scripts:Ee,files:he,main:be,types:Te,module:ge,browser:Re};var j=O.name,J=O.version,U=O.version.split("."),Cr=U[0],Pr=U[1],Dr=U[2];function N(n){let e=`importScripts("${n}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))}function Br(){let n=`https://cdn.jsdelivr.net/npm/${j}@${J}/dist/`;return{asyncDefault:{mainModule:`${n}duckdb.wasm`,mainWorker:N(`${n}duckdb-browser-async.worker.js`)},asyncNext:{mainModule:`${n}duckdb-next.wasm`,mainWorker:N(`${n}duckdb-browser-async-next.worker.js`)},asyncNextCOI:{mainModule:`${n}duckdb-next-coi.wasm`,mainWorker:N(`${n}duckdb-browser-async-next-coi.worker.js`),pthreadWorker:N(`${n}duckdb-browser-async-next-coi.pthread.worker.js`)}}}var L=null,v=null,B=null,M=null,W=null;function Se(){return typeof process!="undefined"&&process.release.name==="node"}async function ye(){return L==null&&(L=typeof BigInt64Array!="undefined"),v==null&&(v=await Ie()),B==null&&(B=await ke()),M==null&&(M=await fe()),W==null&&(W=await we()),{bigInt64Array:L,crossOriginIsolated:Se()||globalThis.crossOriginIsolated||!1,wasmExceptions:v,wasmSIMD:M,wasmThreads:B,wasmBulkMemory:W}}async function Mr(n){let e=await ye();if(e.wasmExceptions&&e.wasmSIMD){if(e.wasmThreads&&e.crossOriginIsolated&&n.asyncNextCOI)return{mainModule:n.asyncNextCOI.mainModule,mainWorker:n.asyncNextCOI.mainWorker,pthreadWorker:n.asyncNextCOI.pthreadWorker};if(n.asyncNext)return{mainModule:n.asyncNext.mainModule,mainWorker:n.asyncNext.mainWorker,pthreadWorker:null}}return{mainModule:n.asyncDefault.mainModule,mainWorker:n.asyncDefault.mainWorker,pthreadWorker:null}}export{ie as AsyncDuckDB,D as AsyncDuckDBConnection,oe as AsyncDuckDBDispatcher,re as ConsoleLogger,Ce as DEFAULT_RUNTIME,X as DuckDBBindings,C as DuckDBConnection,G as DuckDBDataProtocol,H as DuckDBFeature,P as FileStatistics,Q as InsertMode,V as JSONTableShape,g as LogEvent,R as LogLevel,S as LogOrigin,y as LogTopic,j as PACKAGE_NAME,J as PACKAGE_VERSION,Cr as PACKAGE_VERSION_MAJOR,Pr as PACKAGE_VERSION_MINOR,Dr as PACKAGE_VERSION_PATCH,p as StatusCode,ee as VoidLogger,o as WorkerRequestType,u as WorkerResponseType,m as WorkerTask,E as callSRet,w as copyBuffer,Z as decodeText,b as dropResponseBuffers,Ae as failWith,Br as getJsDelivrBundles,nr as getLogEventLabel,tr as getLogLevelLabel,ir as getLogOriginLabel,sr as getLogTopicLabel,ye as getPlatformFeatures,_ as readString,Mr as selectBundle};
//# sourceMappingURL=duckdb-esm.js.map

@@ -1,2 +0,2 @@

var Y=Object.create;var y=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var U=t=>y(t,"__esModule",{value:!0});var q=(t,e)=>{U(t);for(var r in e)y(t,r,{get:e[r],enumerable:!0})},J=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Q(e))!j.call(t,n)&&n!=="default"&&y(t,n,{get:()=>e[n],enumerable:!(r=V(e,n))||r.enumerable});return t},F=t=>J(U(y(t!=null?Y(K(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);q(exports,{AsyncDuckDB:()=>M,AsyncDuckDBConnection:()=>k,AsyncDuckDBDispatcher:()=>B,ConsoleLogger:()=>W,LogEvent:()=>T,LogLevel:()=>_,LogOrigin:()=>R,LogTopic:()=>I,StatusCode:()=>w,VoidLogger:()=>D,WorkerRequestType:()=>s,WorkerResponseType:()=>l,WorkerTask:()=>d,getJsDelivrBundles:()=>Te,getLogEventLabel:()=>$,getLogLevelLabel:()=>z,getLogOriginLabel:()=>X,getLogTopicLabel:()=>Z,getPlatformFeatures:()=>H,selectBundle:()=>Re});var _;(function(a){a[a.NONE=0]="NONE",a[a.DEBUG=1]="DEBUG",a[a.INFO=2]="INFO",a[a.WARNING=3]="WARNING",a[a.ERROR=4]="ERROR"})(_||(_={}));var I;(function(a){a[a.NONE=0]="NONE",a[a.CONNECT=1]="CONNECT",a[a.DISCONNECT=2]="DISCONNECT",a[a.OPEN=3]="OPEN",a[a.QUERY=4]="QUERY"})(I||(I={}));var T;(function(u){u[u.NONE=0]="NONE",u[u.OK=1]="OK",u[u.ERROR=2]="ERROR",u[u.START=3]="START",u[u.RUN=4]="RUN",u[u.CAPTURE=5]="CAPTURE"})(T||(T={}));var R;(function(a){a[a.NONE=0]="NONE",a[a.WEB_WORKER=1]="WEB_WORKER",a[a.NODE_WORKER=2]="NODE_WORKER",a[a.BINDINGS=3]="BINDINGS",a[a.ASYNC_DUCKDB=4]="ASYNC_DUCKDB"})(R||(R={}));var D=class{log(e){}},W=class{log(e){console.log(e)}};function z(t){switch(t){case 0:return"NONE";case 1:return"DEBUG";case 2:return"INFO";case 3:return"WARNING";case 4:return"ERROR";default:return"?"}}function $(t){switch(t){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 Z(t){switch(t){case 1:return"CONNECT";case 2:return"DISCONNECT";case 3:return"OPEN";case 4:return"QUERY";default:return"?"}}function X(t){switch(t){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 w;(function(e){e[e.SUCCESS=0]="SUCCESS"})(w||(w={}));var m=F(require("apache-arrow")),v=class{constructor(e,r,n){this.db=e;this.conn=r;this.header=n;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}},k=class{constructor(e,r){this._instance=e,this._conn=r}get instance(){return this._instance}async close(){return this._instance.disconnect(this._conn)}async runQuery(e){this._instance.logger.log({timestamp:new Date,level:_.INFO,origin:R.ASYNC_DUCKDB,topic:I.QUERY,event:T.RUN,value:e});let r=await this._instance.runQuery(this._conn,e),n=m.RecordBatchReader.from(r);return console.assert(n.isSync()),console.assert(n.isFile()),m.Table.from(n)}async sendQuery(e){this._instance.logger.log({timestamp:new Date,level:_.INFO,origin:R.ASYNC_DUCKDB,topic:I.QUERY,event:T.RUN,value:e});let r=await this._instance.sendQuery(this._conn,e),n=new v(this._instance,this._conn,r),E=await m.RecordBatchReader.from(n);return console.assert(E.isAsync()),console.assert(E.isStream()),E}async insertArrowTable(e,r){e.schema.fields.length==0&&console.warn("The schema is empty! If you used arrow.Table.from, consider constructing schema and batches manually"),await this.insertArrowBatches(e.schema,e.chunks,r)}async insertArrowBatches(e,r,n){let E=new m.AsyncByteQueue,a=new m.RecordBatchStreamWriter().reset(E,e);a.writeAll(r),a.close();let u=a.toUint8Array(!0);await this._instance.insertArrowFromIPCStream(this._conn,u,n)}async insertCSVFromPath(e,r){await this._instance.insertCSVFromPath(this._conn,e,r)}async insertJSONFromPath(e,r){await this._instance.insertJSONFromPath(this._conn,e,r)}};var s;(function(i){i.COLLECT_FILE_STATISTICS="COLLECT_FILE_STATISTICS",i.CONNECT="CONNECT",i.COPY_FILE_TO_BUFFER="COPY_FILE_TO_BUFFER",i.COPY_FILE_TO_PATH="COPY_FILE_TO_PATH",i.DISCONNECT="DISCONNECT",i.DROP_FILE="DROP_FILE",i.DROP_FILES="DROP_FILES",i.EXPORT_FILE_STATISTICS="EXPORT_FILE_STATISTICS",i.FETCH_QUERY_RESULTS="FETCH_QUERY_RESULTS",i.FLUSH_FILES="FLUSH_FILES",i.GET_FEATURE_FLAGS="GET_FEATURE_FLAGS",i.GET_VERSION="GET_VERSION",i.INSERT_ARROW_FROM_IPC_STREAM="INSERT_ARROW_FROM_IPC_STREAM",i.INSERT_CSV_FROM_PATH="IMPORT_CSV_FROM_PATH",i.INSERT_JSON_FROM_PATH="IMPORT_JSON_FROM_PATH",i.INSTANTIATE="INSTANTIATE",i.OPEN="OPEN",i.PING="PING",i.REGISTER_FILE_BUFFER="REGISTER_FILE_BUFFER",i.REGISTER_FILE_HANDLE="REGISTER_FILE_HANDLE",i.REGISTER_FILE_URL="REGISTER_FILE_URL",i.RESET="RESET",i.RUN_QUERY="RUN_QUERY",i.SEND_QUERY="SEND_QUERY",i.TOKENIZE="TOKENIZE"})(s||(s={}));var l;(function(c){c.CONNECTION_INFO="CONNECTION_INFO",c.ERROR="ERROR",c.FEATURE_FLAGS="FEATURE_FLAGS",c.FILE_BUFFER="FILE_BUFFER",c.FILE_SIZE="FILE_SIZE",c.FILE_STATISTICS="FILE_STATISTICS",c.LOG="LOG",c.OK="OK",c.QUERY_PLAN="QUERY_PLAN",c.QUERY_RESULT="QUERY_RESULT",c.QUERY_RESULT_CHUNK="QUERY_RESULT_CHUNK",c.QUERY_START="QUERY_START",c.REGISTERED_FILE="REGISTERED_FILE",c.SCRIPT_TOKENS="SCRIPT_TOKENS",c.SUCCESS="SUCCESS",c.VERSION_STRING="VERSION_STRING"})(l||(l={}));var d=class{constructor(e,r){this.promiseResolver=()=>{};this.promiseRejecter=()=>{};this.type=e,this.data=r,this.promise=new Promise((n,E)=>{this.promiseResolver=n,this.promiseRejecter=E})}};var o=F(require("apache-arrow"));function S(t,e){switch(e.typeId){case o.Type.Binary:return{name:t,type:"binary"};case o.Type.Bool:return{name:t,type:"bool"};case o.Type.Date:return{name:t,type:"date"};case o.Type.DateDay:return{name:t,type:"date32[d]"};case o.Type.DateMillisecond:return{name:t,type:"date64[ms]"};case o.Type.Decimal:{let r=e;return{name:t,type:"decimal",precision:r.precision,scale:r.scale}}case o.Type.Float:return{name:t,type:"float"};case o.Type.Float16:return{name:t,type:"float16"};case o.Type.Float32:return{name:t,type:"float32"};case o.Type.Float64:return{name:t,type:"float64"};case o.Type.Int:return{name:t,type:"int32"};case o.Type.Int16:return{name:t,type:"int16"};case o.Type.Int32:return{name:t,type:"int32"};case o.Type.Int64:return{name:t,type:"int64"};case o.Type.Uint16:return{name:t,type:"uint16"};case o.Type.Uint32:return{name:t,type:"uint32"};case o.Type.Uint64:return{name:t,type:"uint64"};case o.Type.Uint8:return{name:t,type:"uint8"};case o.Type.IntervalDayTime:return{name:t,type:"interval[dt]"};case o.Type.IntervalYearMonth:return{name:t,type:"interval[m]"};case o.Type.List:{let r=e;return{name:t,type:"list",children:[S(r.valueField.name,r.valueField.type)]}}case o.Type.FixedSizeBinary:return{name:t,type:"fixedsizebinary",byteWidth:e.byteWidth};case o.Type.Null:return{name:t,type:"null"};case o.Type.Utf8:return{name:t,type:"utf8"};case o.Type.Struct:return{name:t,type:"struct",children:e.children.map(n=>S(n.name,n.type))};case o.Type.Time:return{name:t,type:"time[s]"};case o.Type.TimeMicrosecond:return{name:t,type:"time[us]"};case o.Type.TimeMillisecond:return{name:t,type:"time[ms]"};case o.Type.TimeNanosecond:return{name:t,type:"time[ns]"};case o.Type.TimeSecond:return{name:t,type:"time[s]"};case o.Type.Timestamp:return{name:t,type:"timestamp",timezone:e.timezone||void 0};case o.Type.TimestampSecond:return{name:t,type:"timestamp[s]",timezone:e.timezone||void 0};case o.Type.TimestampMicrosecond:return{name:t,type:"timestamp[us]",timezone:e.timezone||void 0};case o.Type.TimestampNanosecond:return{name:t,type:"timestamp[ns]",timezone:e.timezone||void 0};case o.Type.TimestampMillisecond:return{name:t,type:"timestamp[ms]",timezone:e.timezone||void 0}}throw new Error(`unsupported arrow type: ${e.toString()}`)}var M=class{constructor(e,r=null){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,n)=>{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 n=this._nextMessageId++;return this._pendingRequests.set(n,e),this._worker.postMessage({messageId:n,type:e.type,data:e.data}),await e.promise}onMessage(e){let r=e.data;r.type==l.LOG&&this._logger.log(r.data);let n=this._pendingRequests.get(r.requestId);if(!n){console.warn(`unassociated response: [${r.requestId}, ${r.type.toString()}]`);return}if(this._pendingRequests.delete(r.requestId),r.type==l.ERROR){let E=new Error(r.data.message);E.name=r.data.name,E.stack=r.data.stack,n.promiseRejecter(E);return}switch(n.type){case s.COLLECT_FILE_STATISTICS:case s.COPY_FILE_TO_PATH:case s.DISCONNECT:case s.DROP_FILES:case s.FLUSH_FILES:case s.INSERT_ARROW_FROM_IPC_STREAM:case s.INSERT_CSV_FROM_PATH:case s.INSERT_JSON_FROM_PATH:case s.INSTANTIATE:case s.OPEN:case s.PING:case s.REGISTER_FILE_BUFFER:case s.REGISTER_FILE_HANDLE:case s.REGISTER_FILE_URL:case s.RESET:if(r.type==l.OK){n.promiseResolver(r.data);return}break;case s.GET_VERSION:if(r.type==l.VERSION_STRING){n.promiseResolver(r.data);return}break;case s.GET_FEATURE_FLAGS:if(r.type==l.FEATURE_FLAGS){n.promiseResolver(r.data);return}break;case s.TOKENIZE:if(r.type==l.SCRIPT_TOKENS){n.promiseResolver(r.data);return}break;case s.DROP_FILE:if(r.type==l.SUCCESS){n.promiseResolver(r.data);return}break;case s.COPY_FILE_TO_BUFFER:if(r.type==l.FILE_BUFFER){n.promiseResolver(r.data);return}break;case s.EXPORT_FILE_STATISTICS:if(r.type==l.FILE_STATISTICS){n.promiseResolver(r.data);return}break;case s.CONNECT:if(r.type==l.CONNECTION_INFO){n.promiseResolver(r.data);return}break;case s.RUN_QUERY:if(r.type==l.QUERY_RESULT){n.promiseResolver(r.data);return}break;case s.SEND_QUERY:if(r.type==l.QUERY_START){n.promiseResolver(r.data);return}break;case s.FETCH_QUERY_RESULTS:if(r.type==l.QUERY_RESULT_CHUNK){n.promiseResolver(r.data);return}break}n.promiseRejecter(new Error(`unexpected response type: ${r.type.toString()}`))}onError(e){console.error(e),console.error(`error in duckdb worker: ${e.message}`),this._pendingRequests.clear()}onClose(){if(this._workerShutdownResolver(null),this._pendingRequests.size!=0){console.warn(`worker terminated with ${this._pendingRequests.size} pending requests`);return}this._pendingRequests.clear()}async reset(){let e=new d(s.RESET,null);return await this.postTask(e)}async ping(){let e=new d(s.PING,null);await this.postTask(e)}async dropFile(e){let r=new d(s.DROP_FILE,e);return await this.postTask(r)}async dropFiles(){let e=new d(s.DROP_FILES,null);return await this.postTask(e)}async flushFiles(){let e=new d(s.FLUSH_FILES,null);return await this.postTask(e)}async instantiate(e,r=null){let n=new d(s.INSTANTIATE,[e,r]);return await this.postTask(n)}async getVersion(){let e=new d(s.GET_VERSION,null);return await this.postTask(e)}async getFeatureFlags(){let e=new d(s.GET_FEATURE_FLAGS,null);return await this.postTask(e)}async open(e){let r=new d(s.OPEN,e);await this.postTask(r)}async tokenize(e){let r=new d(s.TOKENIZE,e);return await this.postTask(r)}async connectInternal(){let e=new d(s.CONNECT,null);return await this.postTask(e)}async connect(){let e=await this.connectInternal();return new k(this,e)}async disconnect(e){let r=new d(s.DISCONNECT,e);await this.postTask(r)}async runQuery(e,r){let n=new d(s.RUN_QUERY,[e,r]);return await this.postTask(n)}async sendQuery(e,r){let n=new d(s.SEND_QUERY,[e,r]);return await this.postTask(n)}async fetchQueryResults(e){let r=new d(s.FETCH_QUERY_RESULTS,e);return await this.postTask(r)}async registerFileURL(e,r){r===void 0&&(r=e);let n=new d(s.REGISTER_FILE_URL,[e,r]);await this.postTask(n)}async registerEmptyFileBuffer(e){let r=new d(s.REGISTER_FILE_BUFFER,[e,new Uint8Array]);await this.postTask(r)}async registerFileBuffer(e,r){let n=new d(s.REGISTER_FILE_BUFFER,[e,r]);await this.postTask(n,[r.buffer])}async registerFileHandle(e,r){let n=new d(s.REGISTER_FILE_HANDLE,[e,r]);await this.postTask(n,[])}async collectFileStatistics(e,r){let n=new d(s.COLLECT_FILE_STATISTICS,[e,r]);await this.postTask(n,[])}async exportFileStatistics(e){let r=new d(s.EXPORT_FILE_STATISTICS,e);return await this.postTask(r,[])}async copyFileToBuffer(e){let r=new d(s.COPY_FILE_TO_BUFFER,e);return await this.postTask(r)}async copyFileToPath(e,r){let n=new d(s.COPY_FILE_TO_PATH,[e,r]);await this.postTask(n)}async insertArrowFromIPCStream(e,r,n){let E=new d(s.INSERT_ARROW_FROM_IPC_STREAM,[e,r,n]);await this.postTask(E,[r.buffer])}async insertCSVFromPath(e,r,n){if(n.columns!==void 0){let a=[];for(let u in n.columns){let N=n.columns[u];a.push(S(u,N))}n.columnsFlat=a,delete n.columns}let E=new d(s.INSERT_CSV_FROM_PATH,[e,r,n]);await this.postTask(E)}async insertJSONFromPath(e,r,n){if(n.columns!==void 0){let a=[];for(let u in n.columns){let N=n.columns[u];a.push(S(u,N))}n.columnsFlat=a,delete n.columns}let E=new d(s.INSERT_JSON_FROM_PATH,[e,r,n]);await this.postTask(E)}};var B=class{constructor(){this._bindings=null;this._nextMessageId=0}log(e){this.postMessage({messageId:this._nextMessageId++,requestId:0,type:l.LOG,data:e},[])}sendOK(e){this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.OK,data:null},[])}failWith(e,r){let n={name:r.name,message:r.message,stack:r.stack||void 0};this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.ERROR,data:n},[])}async onMessage(e){switch(e.type){case s.PING:this.sendOK(e);return;case s.INSTANTIATE:this._bindings!=null&&this.failWith(e,new Error("duckdb already initialized"));try{this._bindings=await this.instantiate(e.data[0],e.data[1]),this.sendOK(e)}catch(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 s.GET_VERSION:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.VERSION_STRING,data:this._bindings.getVersion()},[]);break;case s.GET_FEATURE_FLAGS:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.FEATURE_FLAGS,data:this._bindings.getFeatureFlags()},[]);break;case s.RESET:this._bindings.reset(),this.sendOK(e);break;case s.OPEN:this._bindings.open(e.data),this.sendOK(e);break;case s.DROP_FILE:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.SUCCESS,data:this._bindings.dropFile(e.data)},[]);break;case s.DROP_FILES:this._bindings.dropFiles(),this.sendOK(e);break;case s.FLUSH_FILES:this._bindings.flushFiles(),this.sendOK(e);break;case s.CONNECT:{let r=this._bindings.connect();this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.CONNECTION_INFO,data:r.handle},[]);break}case s.DISCONNECT:this._bindings.disconnect(e.data),this.sendOK(e);break;case s.RUN_QUERY:{let r=this._bindings.runQuery(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.QUERY_RESULT,data:r},[r.buffer]);break}case s.SEND_QUERY:{let r=this._bindings.sendQuery(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.QUERY_START,data:r},[r.buffer]);break}case s.FETCH_QUERY_RESULTS:{let r=this._bindings.fetchQueryResults(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.QUERY_RESULT_CHUNK,data:r},[r.buffer]);break}case s.REGISTER_FILE_URL:this._bindings.registerFileURL(e.data[0],e.data[1]),this.sendOK(e);break;case s.REGISTER_FILE_BUFFER:this._bindings.registerFileBuffer(e.data[0],e.data[1]),this.sendOK(e);break;case s.REGISTER_FILE_HANDLE:this._bindings.registerFileHandle(e.data[0],e.data[1]),this.sendOK(e);break;case s.COPY_FILE_TO_PATH:this._bindings.copyFileToPath(e.data[0],e.data[1]),this.sendOK(e);break;case s.COPY_FILE_TO_BUFFER:{let r=this._bindings.copyFileToBuffer(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.FILE_BUFFER,data:r},[]);break}case s.COLLECT_FILE_STATISTICS:this._bindings.collectFileStatistics(e.data[0],e.data[1]),this.sendOK(e);break;case s.EXPORT_FILE_STATISTICS:{this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.FILE_STATISTICS,data:this._bindings.exportFileStatistics(e.data)},[]);break}case s.INSERT_ARROW_FROM_IPC_STREAM:{this._bindings.insertArrowFromIPCStream(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case s.INSERT_CSV_FROM_PATH:{this._bindings.insertCSVFromPath(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case s.INSERT_JSON_FROM_PATH:{this._bindings.insertJSONFromPath(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case s.TOKENIZE:{let r=this._bindings.tokenize(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.SCRIPT_TOKENS,data:r},[]);break}}}catch(r){return this.failWith(e,r)}}};var g=F(require("wasm-feature-detect"));var ee="@duckdb/duckdb-wasm",re="0.0.41-dev235.0",te="DuckDB powered by WebAssembly",se={type:"git",url:"https://github.com/duckdb/duckdb-wasm.git"},ne="MIT",ie={"apache-arrow":"^4.0.0","wasm-feature-detect":"^1.2.11"},ae={"@types/emscripten":"^1.39.4","@types/jasmine":"^3.9.1","@typescript-eslint/eslint-plugin":"^4.33.0","@typescript-eslint/parser":"^4.33.0",esbuild:"^0.13.4",eslint:"^7.32.0","eslint-config-prettier":"^8.3.0","eslint-plugin-jasmine":"^4.1.2","eslint-plugin-prettier":"^4.0.0","eslint-plugin-react":"^7.26.1",jasmine:"3.9.0","jasmine-core":"^3.8.0","jasmine-spec-reporter":"^7.0.0",karma:"^6.3.4","karma-chrome-launcher":"^3.1.0","karma-coverage":"^2.0.3","karma-firefox-launcher":"^2.1.1","karma-jasmine":"^4.0.1","karma-jasmine-html-reporter":"^1.7.0","karma-sourcemap-loader":"^0.3.8","karma-spec-reporter":"^0.0.32","make-dir":"^3.1.0",nyc:"^15.1.0",prettier:"^2.4.1",puppeteer:"^10.4.0",rimraf:"^3.0.2",typedoc:"^0.22.5",typescript:"^4.4.3","web-worker":"^1.1.0"},oe={fsevents:"*"},ce={"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 --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js","test:node:filter":'node --enable-source-maps --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js --filter="CSV"',"test:node:coverage":"nyc -r json --report-dir ./coverage/node node --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js","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:browsers":"karma start ./karma/tests-all.cjs","test: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 types"},le=["dist","!dist/types/test"],de="./dist/duckdb-node-async.js",ue="./dist/duckdb-node-async.d.ts",Ee="./dist/duckdb-esm.js",pe={"./dist/duckdb-node-async.js":"./dist/duckdb-browser-async.js","temp-write":!1,worker_threads:!1,perf_hooks:!1,fs:!1,os:!1,path:!1,buffer:!1,crypto:!1},h={name:ee,version:re,description:te,repository:se,license:ne,dependencies:ie,devDependencies:ae,optionalDependencies:oe,scripts:ce,files:le,main:de,types:ue,module:Ee,browser:pe};var x=h.name,G=h.version,b=h.version.split("."),Ve=b[0],Qe=b[1],Ke=b[2];function O(t){let e=`importScripts("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))}function Te(){let t=`https://cdn.jsdelivr.net/npm/${x}@${G}/dist/`;return{asyncDefault:{mainModule:`${t}duckdb.wasm`,mainWorker:O(`${t}duckdb-browser-async.worker.js`)},asyncNext:{mainModule:`${t}duckdb-next.wasm`,mainWorker:O(`${t}duckdb-browser-async-next.worker.js`)},asyncNextCOI:{mainModule:`${t}duckdb-next-coi.wasm`,mainWorker:O(`${t}duckdb-browser-async-next-coi.worker.js`),pthreadWorker:O(`${t}duckdb-browser-async-next-coi.pthread.worker.js`)}}}var C=null,A=null,f=null,L=null,P=null;function _e(){return typeof process!="undefined"&&process.release.name==="node"}async function H(){return C==null&&(C=typeof BigInt64Array!="undefined"),A==null&&(A=await g.exceptions()),f==null&&(f=await g.threads()),L==null&&(L=await g.simd()),P==null&&(P=await g.bulkMemory()),{bigInt64Array:C,crossOriginIsolated:_e()||globalThis.crossOriginIsolated||!1,wasmExceptions:A,wasmSIMD:L,wasmThreads:f,wasmBulkMemory:P}}async function Re(t){let e=await H();if(e.wasmExceptions&&e.wasmSIMD){if(e.wasmThreads&&e.crossOriginIsolated&&t.asyncNextCOI)return{mainModule:t.asyncNextCOI.mainModule,mainWorker:t.asyncNextCOI.mainWorker,pthreadWorker:t.asyncNextCOI.pthreadWorker};if(t.asyncNext)return{mainModule:t.asyncNext.mainModule,mainWorker:t.asyncNext.mainWorker,pthreadWorker:null}}return{mainModule:t.asyncDefault.mainModule,mainWorker:t.asyncDefault.mainWorker,pthreadWorker:null}}0&&(module.exports={AsyncDuckDB,AsyncDuckDBConnection,AsyncDuckDBDispatcher,ConsoleLogger,LogEvent,LogLevel,LogOrigin,LogTopic,StatusCode,VoidLogger,WorkerRequestType,WorkerResponseType,WorkerTask,getJsDelivrBundles,getLogEventLabel,getLogLevelLabel,getLogOriginLabel,getLogTopicLabel,getPlatformFeatures,selectBundle});
var Y=Object.create;var y=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var U=t=>y(t,"__esModule",{value:!0});var q=(t,e)=>{U(t);for(var r in e)y(t,r,{get:e[r],enumerable:!0})},J=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Q(e))!j.call(t,n)&&n!=="default"&&y(t,n,{get:()=>e[n],enumerable:!(r=V(e,n))||r.enumerable});return t},F=t=>J(U(y(t!=null?Y(K(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);q(exports,{AsyncDuckDB:()=>M,AsyncDuckDBConnection:()=>k,AsyncDuckDBDispatcher:()=>B,ConsoleLogger:()=>W,LogEvent:()=>T,LogLevel:()=>_,LogOrigin:()=>R,LogTopic:()=>I,StatusCode:()=>w,VoidLogger:()=>D,WorkerRequestType:()=>s,WorkerResponseType:()=>l,WorkerTask:()=>d,getJsDelivrBundles:()=>Te,getLogEventLabel:()=>$,getLogLevelLabel:()=>z,getLogOriginLabel:()=>X,getLogTopicLabel:()=>Z,getPlatformFeatures:()=>H,selectBundle:()=>Re});var _;(function(a){a[a.NONE=0]="NONE",a[a.DEBUG=1]="DEBUG",a[a.INFO=2]="INFO",a[a.WARNING=3]="WARNING",a[a.ERROR=4]="ERROR"})(_||(_={}));var I;(function(a){a[a.NONE=0]="NONE",a[a.CONNECT=1]="CONNECT",a[a.DISCONNECT=2]="DISCONNECT",a[a.OPEN=3]="OPEN",a[a.QUERY=4]="QUERY"})(I||(I={}));var T;(function(u){u[u.NONE=0]="NONE",u[u.OK=1]="OK",u[u.ERROR=2]="ERROR",u[u.START=3]="START",u[u.RUN=4]="RUN",u[u.CAPTURE=5]="CAPTURE"})(T||(T={}));var R;(function(a){a[a.NONE=0]="NONE",a[a.WEB_WORKER=1]="WEB_WORKER",a[a.NODE_WORKER=2]="NODE_WORKER",a[a.BINDINGS=3]="BINDINGS",a[a.ASYNC_DUCKDB=4]="ASYNC_DUCKDB"})(R||(R={}));var D=class{log(e){}},W=class{log(e){console.log(e)}};function z(t){switch(t){case 0:return"NONE";case 1:return"DEBUG";case 2:return"INFO";case 3:return"WARNING";case 4:return"ERROR";default:return"?"}}function $(t){switch(t){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 Z(t){switch(t){case 1:return"CONNECT";case 2:return"DISCONNECT";case 3:return"OPEN";case 4:return"QUERY";default:return"?"}}function X(t){switch(t){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 w;(function(e){e[e.SUCCESS=0]="SUCCESS"})(w||(w={}));var m=F(require("apache-arrow")),v=class{constructor(e,r,n){this.db=e;this.conn=r;this.header=n;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}},k=class{constructor(e,r){this._instance=e,this._conn=r}get instance(){return this._instance}async close(){return this._instance.disconnect(this._conn)}async runQuery(e){this._instance.logger.log({timestamp:new Date,level:_.INFO,origin:R.ASYNC_DUCKDB,topic:I.QUERY,event:T.RUN,value:e});let r=await this._instance.runQuery(this._conn,e),n=m.RecordBatchReader.from(r);return console.assert(n.isSync()),console.assert(n.isFile()),m.Table.from(n)}async sendQuery(e){this._instance.logger.log({timestamp:new Date,level:_.INFO,origin:R.ASYNC_DUCKDB,topic:I.QUERY,event:T.RUN,value:e});let r=await this._instance.sendQuery(this._conn,e),n=new v(this._instance,this._conn,r),E=await m.RecordBatchReader.from(n);return console.assert(E.isAsync()),console.assert(E.isStream()),E}async insertArrowTable(e,r){e.schema.fields.length==0&&console.warn("The schema is empty! If you used arrow.Table.from, consider constructing schema and batches manually"),await this.insertArrowBatches(e.schema,e.chunks,r)}async insertArrowBatches(e,r,n){let E=new m.AsyncByteQueue,a=new m.RecordBatchStreamWriter().reset(E,e);a.writeAll(r),a.close();let u=a.toUint8Array(!0);await this._instance.insertArrowFromIPCStream(this._conn,u,n)}async insertCSVFromPath(e,r){await this._instance.insertCSVFromPath(this._conn,e,r)}async insertJSONFromPath(e,r){await this._instance.insertJSONFromPath(this._conn,e,r)}};var s;(function(i){i.COLLECT_FILE_STATISTICS="COLLECT_FILE_STATISTICS",i.CONNECT="CONNECT",i.COPY_FILE_TO_BUFFER="COPY_FILE_TO_BUFFER",i.COPY_FILE_TO_PATH="COPY_FILE_TO_PATH",i.DISCONNECT="DISCONNECT",i.DROP_FILE="DROP_FILE",i.DROP_FILES="DROP_FILES",i.EXPORT_FILE_STATISTICS="EXPORT_FILE_STATISTICS",i.FETCH_QUERY_RESULTS="FETCH_QUERY_RESULTS",i.FLUSH_FILES="FLUSH_FILES",i.GET_FEATURE_FLAGS="GET_FEATURE_FLAGS",i.GET_VERSION="GET_VERSION",i.INSERT_ARROW_FROM_IPC_STREAM="INSERT_ARROW_FROM_IPC_STREAM",i.INSERT_CSV_FROM_PATH="IMPORT_CSV_FROM_PATH",i.INSERT_JSON_FROM_PATH="IMPORT_JSON_FROM_PATH",i.INSTANTIATE="INSTANTIATE",i.OPEN="OPEN",i.PING="PING",i.REGISTER_FILE_BUFFER="REGISTER_FILE_BUFFER",i.REGISTER_FILE_HANDLE="REGISTER_FILE_HANDLE",i.REGISTER_FILE_URL="REGISTER_FILE_URL",i.RESET="RESET",i.RUN_QUERY="RUN_QUERY",i.SEND_QUERY="SEND_QUERY",i.TOKENIZE="TOKENIZE"})(s||(s={}));var l;(function(c){c.CONNECTION_INFO="CONNECTION_INFO",c.ERROR="ERROR",c.FEATURE_FLAGS="FEATURE_FLAGS",c.FILE_BUFFER="FILE_BUFFER",c.FILE_SIZE="FILE_SIZE",c.FILE_STATISTICS="FILE_STATISTICS",c.LOG="LOG",c.OK="OK",c.QUERY_PLAN="QUERY_PLAN",c.QUERY_RESULT="QUERY_RESULT",c.QUERY_RESULT_CHUNK="QUERY_RESULT_CHUNK",c.QUERY_START="QUERY_START",c.REGISTERED_FILE="REGISTERED_FILE",c.SCRIPT_TOKENS="SCRIPT_TOKENS",c.SUCCESS="SUCCESS",c.VERSION_STRING="VERSION_STRING"})(l||(l={}));var d=class{constructor(e,r){this.promiseResolver=()=>{};this.promiseRejecter=()=>{};this.type=e,this.data=r,this.promise=new Promise((n,E)=>{this.promiseResolver=n,this.promiseRejecter=E})}};var o=F(require("apache-arrow"));function S(t,e){switch(e.typeId){case o.Type.Binary:return{name:t,type:"binary"};case o.Type.Bool:return{name:t,type:"bool"};case o.Type.Date:return{name:t,type:"date"};case o.Type.DateDay:return{name:t,type:"date32[d]"};case o.Type.DateMillisecond:return{name:t,type:"date64[ms]"};case o.Type.Decimal:{let r=e;return{name:t,type:"decimal",precision:r.precision,scale:r.scale}}case o.Type.Float:return{name:t,type:"float"};case o.Type.Float16:return{name:t,type:"float16"};case o.Type.Float32:return{name:t,type:"float32"};case o.Type.Float64:return{name:t,type:"float64"};case o.Type.Int:return{name:t,type:"int32"};case o.Type.Int16:return{name:t,type:"int16"};case o.Type.Int32:return{name:t,type:"int32"};case o.Type.Int64:return{name:t,type:"int64"};case o.Type.Uint16:return{name:t,type:"uint16"};case o.Type.Uint32:return{name:t,type:"uint32"};case o.Type.Uint64:return{name:t,type:"uint64"};case o.Type.Uint8:return{name:t,type:"uint8"};case o.Type.IntervalDayTime:return{name:t,type:"interval[dt]"};case o.Type.IntervalYearMonth:return{name:t,type:"interval[m]"};case o.Type.List:{let r=e;return{name:t,type:"list",children:[S(r.valueField.name,r.valueField.type)]}}case o.Type.FixedSizeBinary:return{name:t,type:"fixedsizebinary",byteWidth:e.byteWidth};case o.Type.Null:return{name:t,type:"null"};case o.Type.Utf8:return{name:t,type:"utf8"};case o.Type.Struct:return{name:t,type:"struct",children:e.children.map(n=>S(n.name,n.type))};case o.Type.Time:return{name:t,type:"time[s]"};case o.Type.TimeMicrosecond:return{name:t,type:"time[us]"};case o.Type.TimeMillisecond:return{name:t,type:"time[ms]"};case o.Type.TimeNanosecond:return{name:t,type:"time[ns]"};case o.Type.TimeSecond:return{name:t,type:"time[s]"};case o.Type.Timestamp:return{name:t,type:"timestamp",timezone:e.timezone||void 0};case o.Type.TimestampSecond:return{name:t,type:"timestamp[s]",timezone:e.timezone||void 0};case o.Type.TimestampMicrosecond:return{name:t,type:"timestamp[us]",timezone:e.timezone||void 0};case o.Type.TimestampNanosecond:return{name:t,type:"timestamp[ns]",timezone:e.timezone||void 0};case o.Type.TimestampMillisecond:return{name:t,type:"timestamp[ms]",timezone:e.timezone||void 0}}throw new Error(`unsupported arrow type: ${e.toString()}`)}var M=class{constructor(e,r=null){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,n)=>{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 n=this._nextMessageId++;return this._pendingRequests.set(n,e),this._worker.postMessage({messageId:n,type:e.type,data:e.data}),await e.promise}onMessage(e){let r=e.data;r.type==l.LOG&&this._logger.log(r.data);let n=this._pendingRequests.get(r.requestId);if(!n){console.warn(`unassociated response: [${r.requestId}, ${r.type.toString()}]`);return}if(this._pendingRequests.delete(r.requestId),r.type==l.ERROR){let E=new Error(r.data.message);E.name=r.data.name,E.stack=r.data.stack,n.promiseRejecter(E);return}switch(n.type){case s.COLLECT_FILE_STATISTICS:case s.COPY_FILE_TO_PATH:case s.DISCONNECT:case s.DROP_FILES:case s.FLUSH_FILES:case s.INSERT_ARROW_FROM_IPC_STREAM:case s.INSERT_CSV_FROM_PATH:case s.INSERT_JSON_FROM_PATH:case s.INSTANTIATE:case s.OPEN:case s.PING:case s.REGISTER_FILE_BUFFER:case s.REGISTER_FILE_HANDLE:case s.REGISTER_FILE_URL:case s.RESET:if(r.type==l.OK){n.promiseResolver(r.data);return}break;case s.GET_VERSION:if(r.type==l.VERSION_STRING){n.promiseResolver(r.data);return}break;case s.GET_FEATURE_FLAGS:if(r.type==l.FEATURE_FLAGS){n.promiseResolver(r.data);return}break;case s.TOKENIZE:if(r.type==l.SCRIPT_TOKENS){n.promiseResolver(r.data);return}break;case s.DROP_FILE:if(r.type==l.SUCCESS){n.promiseResolver(r.data);return}break;case s.COPY_FILE_TO_BUFFER:if(r.type==l.FILE_BUFFER){n.promiseResolver(r.data);return}break;case s.EXPORT_FILE_STATISTICS:if(r.type==l.FILE_STATISTICS){n.promiseResolver(r.data);return}break;case s.CONNECT:if(r.type==l.CONNECTION_INFO){n.promiseResolver(r.data);return}break;case s.RUN_QUERY:if(r.type==l.QUERY_RESULT){n.promiseResolver(r.data);return}break;case s.SEND_QUERY:if(r.type==l.QUERY_START){n.promiseResolver(r.data);return}break;case s.FETCH_QUERY_RESULTS:if(r.type==l.QUERY_RESULT_CHUNK){n.promiseResolver(r.data);return}break}n.promiseRejecter(new Error(`unexpected response type: ${r.type.toString()}`))}onError(e){console.error(e),console.error(`error in duckdb worker: ${e.message}`),this._pendingRequests.clear()}onClose(){if(this._workerShutdownResolver(null),this._pendingRequests.size!=0){console.warn(`worker terminated with ${this._pendingRequests.size} pending requests`);return}this._pendingRequests.clear()}async reset(){let e=new d(s.RESET,null);return await this.postTask(e)}async ping(){let e=new d(s.PING,null);await this.postTask(e)}async dropFile(e){let r=new d(s.DROP_FILE,e);return await this.postTask(r)}async dropFiles(){let e=new d(s.DROP_FILES,null);return await this.postTask(e)}async flushFiles(){let e=new d(s.FLUSH_FILES,null);return await this.postTask(e)}async instantiate(e,r=null){let n=new d(s.INSTANTIATE,[e,r]);return await this.postTask(n)}async getVersion(){let e=new d(s.GET_VERSION,null);return await this.postTask(e)}async getFeatureFlags(){let e=new d(s.GET_FEATURE_FLAGS,null);return await this.postTask(e)}async open(e){let r=new d(s.OPEN,e);await this.postTask(r)}async tokenize(e){let r=new d(s.TOKENIZE,e);return await this.postTask(r)}async connectInternal(){let e=new d(s.CONNECT,null);return await this.postTask(e)}async connect(){let e=await this.connectInternal();return new k(this,e)}async disconnect(e){let r=new d(s.DISCONNECT,e);await this.postTask(r)}async runQuery(e,r){let n=new d(s.RUN_QUERY,[e,r]);return await this.postTask(n)}async sendQuery(e,r){let n=new d(s.SEND_QUERY,[e,r]);return await this.postTask(n)}async fetchQueryResults(e){let r=new d(s.FETCH_QUERY_RESULTS,e);return await this.postTask(r)}async registerFileURL(e,r){r===void 0&&(r=e);let n=new d(s.REGISTER_FILE_URL,[e,r]);await this.postTask(n)}async registerEmptyFileBuffer(e){let r=new d(s.REGISTER_FILE_BUFFER,[e,new Uint8Array]);await this.postTask(r)}async registerFileBuffer(e,r){let n=new d(s.REGISTER_FILE_BUFFER,[e,r]);await this.postTask(n,[r.buffer])}async registerFileHandle(e,r){let n=new d(s.REGISTER_FILE_HANDLE,[e,r]);await this.postTask(n,[])}async collectFileStatistics(e,r){let n=new d(s.COLLECT_FILE_STATISTICS,[e,r]);await this.postTask(n,[])}async exportFileStatistics(e){let r=new d(s.EXPORT_FILE_STATISTICS,e);return await this.postTask(r,[])}async copyFileToBuffer(e){let r=new d(s.COPY_FILE_TO_BUFFER,e);return await this.postTask(r)}async copyFileToPath(e,r){let n=new d(s.COPY_FILE_TO_PATH,[e,r]);await this.postTask(n)}async insertArrowFromIPCStream(e,r,n){let E=new d(s.INSERT_ARROW_FROM_IPC_STREAM,[e,r,n]);await this.postTask(E,[r.buffer])}async insertCSVFromPath(e,r,n){if(n.columns!==void 0){let a=[];for(let u in n.columns){let N=n.columns[u];a.push(S(u,N))}n.columnsFlat=a,delete n.columns}let E=new d(s.INSERT_CSV_FROM_PATH,[e,r,n]);await this.postTask(E)}async insertJSONFromPath(e,r,n){if(n.columns!==void 0){let a=[];for(let u in n.columns){let N=n.columns[u];a.push(S(u,N))}n.columnsFlat=a,delete n.columns}let E=new d(s.INSERT_JSON_FROM_PATH,[e,r,n]);await this.postTask(E)}};var B=class{constructor(){this._bindings=null;this._nextMessageId=0}log(e){this.postMessage({messageId:this._nextMessageId++,requestId:0,type:l.LOG,data:e},[])}sendOK(e){this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.OK,data:null},[])}failWith(e,r){let n={name:r.name,message:r.message,stack:r.stack||void 0};this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.ERROR,data:n},[])}async onMessage(e){switch(e.type){case s.PING:this.sendOK(e);return;case s.INSTANTIATE:this._bindings!=null&&this.failWith(e,new Error("duckdb already initialized"));try{this._bindings=await this.instantiate(e.data[0],e.data[1]),this.sendOK(e)}catch(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 s.GET_VERSION:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.VERSION_STRING,data:this._bindings.getVersion()},[]);break;case s.GET_FEATURE_FLAGS:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.FEATURE_FLAGS,data:this._bindings.getFeatureFlags()},[]);break;case s.RESET:this._bindings.reset(),this.sendOK(e);break;case s.OPEN:this._bindings.open(e.data),this.sendOK(e);break;case s.DROP_FILE:this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.SUCCESS,data:this._bindings.dropFile(e.data)},[]);break;case s.DROP_FILES:this._bindings.dropFiles(),this.sendOK(e);break;case s.FLUSH_FILES:this._bindings.flushFiles(),this.sendOK(e);break;case s.CONNECT:{let r=this._bindings.connect();this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.CONNECTION_INFO,data:r.handle},[]);break}case s.DISCONNECT:this._bindings.disconnect(e.data),this.sendOK(e);break;case s.RUN_QUERY:{let r=this._bindings.runQuery(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.QUERY_RESULT,data:r},[r.buffer]);break}case s.SEND_QUERY:{let r=this._bindings.sendQuery(e.data[0],e.data[1]);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.QUERY_START,data:r},[r.buffer]);break}case s.FETCH_QUERY_RESULTS:{let r=this._bindings.fetchQueryResults(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.QUERY_RESULT_CHUNK,data:r},[r.buffer]);break}case s.REGISTER_FILE_URL:this._bindings.registerFileURL(e.data[0],e.data[1]),this.sendOK(e);break;case s.REGISTER_FILE_BUFFER:this._bindings.registerFileBuffer(e.data[0],e.data[1]),this.sendOK(e);break;case s.REGISTER_FILE_HANDLE:this._bindings.registerFileHandle(e.data[0],e.data[1]),this.sendOK(e);break;case s.COPY_FILE_TO_PATH:this._bindings.copyFileToPath(e.data[0],e.data[1]),this.sendOK(e);break;case s.COPY_FILE_TO_BUFFER:{let r=this._bindings.copyFileToBuffer(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.FILE_BUFFER,data:r},[]);break}case s.COLLECT_FILE_STATISTICS:this._bindings.collectFileStatistics(e.data[0],e.data[1]),this.sendOK(e);break;case s.EXPORT_FILE_STATISTICS:{this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.FILE_STATISTICS,data:this._bindings.exportFileStatistics(e.data)},[]);break}case s.INSERT_ARROW_FROM_IPC_STREAM:{this._bindings.insertArrowFromIPCStream(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case s.INSERT_CSV_FROM_PATH:{this._bindings.insertCSVFromPath(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case s.INSERT_JSON_FROM_PATH:{this._bindings.insertJSONFromPath(e.data[0],e.data[1],e.data[2]),this.sendOK(e);break}case s.TOKENIZE:{let r=this._bindings.tokenize(e.data);this.postMessage({messageId:this._nextMessageId++,requestId:e.messageId,type:l.SCRIPT_TOKENS,data:r},[]);break}}}catch(r){return this.failWith(e,r)}}};var g=F(require("wasm-feature-detect"));var ee="@duckdb/duckdb-wasm",re="0.0.41-dev242.0",te="DuckDB powered by WebAssembly",se={type:"git",url:"https://github.com/duckdb/duckdb-wasm.git"},ne="MIT",ie={"apache-arrow":"^4.0.0","wasm-feature-detect":"^1.2.11"},ae={"@types/emscripten":"^1.39.4","@types/jasmine":"^3.9.1","@typescript-eslint/eslint-plugin":"^4.33.0","@typescript-eslint/parser":"^4.33.0",esbuild:"^0.13.4",eslint:"^7.32.0","eslint-config-prettier":"^8.3.0","eslint-plugin-jasmine":"^4.1.2","eslint-plugin-prettier":"^4.0.0","eslint-plugin-react":"^7.26.1",jasmine:"3.9.0","jasmine-core":"^3.8.0","jasmine-spec-reporter":"^7.0.0",karma:"^6.3.4","karma-chrome-launcher":"^3.1.0","karma-coverage":"^2.0.3","karma-firefox-launcher":"^2.1.1","karma-jasmine":"^4.0.1","karma-jasmine-html-reporter":"^1.7.0","karma-sourcemap-loader":"^0.3.8","karma-spec-reporter":"^0.0.32","make-dir":"^3.1.0",nyc:"^15.1.0",prettier:"^2.4.1",puppeteer:"^10.4.0",rimraf:"^3.0.2",typedoc:"^0.22.5",typescript:"^4.4.3","web-worker":"^1.1.0"},oe={fsevents:"*"},ce={"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 --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js","test:node:filter":'node --enable-source-maps --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js --filter="CSV"',"test:node:coverage":"nyc -r json --report-dir ./coverage/node node --experimental-wasm-eh ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.js","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:browsers":"karma start ./karma/tests-all.cjs","test: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 types"},le=["dist","!dist/types/test"],de="./dist/duckdb-node-async.js",ue="./dist/duckdb-node-async.d.ts",Ee="./dist/duckdb-esm.js",pe={"./dist/duckdb-node-async.js":"./dist/duckdb-browser-async.js","temp-write":!1,worker_threads:!1,perf_hooks:!1,fs:!1,os:!1,path:!1,buffer:!1,crypto:!1},h={name:ee,version:re,description:te,repository:se,license:ne,dependencies:ie,devDependencies:ae,optionalDependencies:oe,scripts:ce,files:le,main:de,types:ue,module:Ee,browser:pe};var x=h.name,G=h.version,b=h.version.split("."),Ve=b[0],Qe=b[1],Ke=b[2];function O(t){let e=`importScripts("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))}function Te(){let t=`https://cdn.jsdelivr.net/npm/${x}@${G}/dist/`;return{asyncDefault:{mainModule:`${t}duckdb.wasm`,mainWorker:O(`${t}duckdb-browser-async.worker.js`)},asyncNext:{mainModule:`${t}duckdb-next.wasm`,mainWorker:O(`${t}duckdb-browser-async-next.worker.js`)},asyncNextCOI:{mainModule:`${t}duckdb-next-coi.wasm`,mainWorker:O(`${t}duckdb-browser-async-next-coi.worker.js`),pthreadWorker:O(`${t}duckdb-browser-async-next-coi.pthread.worker.js`)}}}var C=null,A=null,f=null,L=null,P=null;function _e(){return typeof process!="undefined"&&process.release.name==="node"}async function H(){return C==null&&(C=typeof BigInt64Array!="undefined"),A==null&&(A=await g.exceptions()),f==null&&(f=await g.threads()),L==null&&(L=await g.simd()),P==null&&(P=await g.bulkMemory()),{bigInt64Array:C,crossOriginIsolated:_e()||globalThis.crossOriginIsolated||!1,wasmExceptions:A,wasmSIMD:L,wasmThreads:f,wasmBulkMemory:P}}async function Re(t){let e=await H();if(e.wasmExceptions&&e.wasmSIMD){if(e.wasmThreads&&e.crossOriginIsolated&&t.asyncNextCOI)return{mainModule:t.asyncNextCOI.mainModule,mainWorker:t.asyncNextCOI.mainWorker,pthreadWorker:t.asyncNextCOI.pthreadWorker};if(t.asyncNext)return{mainModule:t.asyncNext.mainModule,mainWorker:t.asyncNext.mainWorker,pthreadWorker:null}}return{mainModule:t.asyncDefault.mainModule,mainWorker:t.asyncDefault.mainWorker,pthreadWorker:null}}0&&(module.exports={AsyncDuckDB,AsyncDuckDBConnection,AsyncDuckDBDispatcher,ConsoleLogger,LogEvent,LogLevel,LogOrigin,LogTopic,StatusCode,VoidLogger,WorkerRequestType,WorkerResponseType,WorkerTask,getJsDelivrBundles,getLogEventLabel,getLogLevelLabel,getLogOriginLabel,getLogTopicLabel,getPlatformFeatures,selectBundle});
//# sourceMappingURL=duckdb-node-async.js.map
{
"name": "@duckdb/duckdb-wasm",
"version": "0.0.41-dev235.0",
"version": "0.0.41-dev242.0",
"description": "DuckDB powered by WebAssembly",

@@ -5,0 +5,0 @@ "repository": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc