@hpcc-js/wasm 2.18.1 → 2.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/duckdb.js CHANGED
@@ -8,4 +8,3 @@ return true;`)}function Md(i){return typeof i!="bigint"?te(i):`${te(i)}n`}var Ns
8
8
  ${this.toArray().join(`,
9
9
  `)}
10
10
  ]`}concat(...t){let e=this.schema,r=this.data.concat(t.flatMap(({data:n})=>n));return new i(e,r.map(n=>new tt(e,n)))}slice(t,e){let r=this.schema;[t,e]=Fr({length:this.numRows},t,e);let n=uo(this.data,this._offsets,t,e);return new i(r,n.map(o=>new tt(r,o)))}getChild(t){return this.getChildAt(this.schema.fields.findIndex(e=>e.name===t))}getChildAt(t){if(t>-1&&t<this.schema.fields.length){let e=this.data.map(r=>r.children[t]);if(e.length===0){let{type:r}=this.schema.fields[t],n=X({type:r,length:0,nullCount:0});e.push(n._changeLengthAndBackfillNullBitmap(this.numRows))}return new W(e)}return null}setChild(t,e){var r;return this.setChildAt((r=this.schema.fields)===null||r===void 0?void 0:r.findIndex(n=>n.name===t),e)}setChildAt(t,e){let r=this.schema,n=[...this.batches];if(t>-1&&t<this.numCols){e||(e=new W([X({type:new Et,length:this.numRows})]));let o=r.fields.slice(),s=o[t].clone({type:e.type}),a=this.schema.fields.map((c,B)=>this.getChildAt(B));[o[t],a[t]]=[s,e],[r,n]=So(r,a)}return new i(r,n)}select(t){let e=this.schema.fields.reduce((r,n,o)=>r.set(n.name,o),new Map);return this.selectAt(t.map(r=>e.get(r)).filter(r=>r>-1))}selectAt(t){let e=this.schema.selectAt(t),r=this.batches.map(n=>n.selectAt(t));return new i(e,r)}assign(t){let e=this.schema.fields,[r,n]=t.schema.fields.reduce((a,c,B)=>{let[d,l]=a,D=e.findIndex(y=>y.name===c.name);return~D?l[D]=B:d.push(B),a},[[],[]]),o=this.schema.assign(t.schema),s=[...e.map((a,c)=>[c,n[c]]).map(([a,c])=>c===void 0?this.getChildAt(a):t.getChildAt(c)),...r.map(a=>t.getChildAt(a))].filter(Boolean);return new i(...So(o,s))}};gc=Symbol.toStringTag;Mt[gc]=(i=>(i.schema=null,i.batches=[],i._offsets=new Uint32Array([0]),i._nullCount=-1,i[Symbol.isConcatSpreadable]=!0,i.isValid=ri(vr),i.get=ri(ot.getVisitFn(u.Struct)),i.set=Bo(yt.getVisitFn(u.Struct)),i.indexOf=lo(Ci.getVisitFn(u.Struct)),i.getByteLength=ri(gt.getVisitFn(u.Struct)),"Table"))(Mt.prototype);var Tc,tt=class i{constructor(...t){switch(t.length){case 2:{if([this.schema]=t,!(this.schema instanceof S))throw new TypeError("RecordBatch constructor expects a [Schema, Data] pair.");if([,this.data=X({nullCount:0,type:new Q(this.schema.fields),children:this.schema.fields.map(e=>X({type:e.type,nullCount:0}))})]=t,!(this.data instanceof U))throw new TypeError("RecordBatch constructor expects a [Schema, Data] pair.");[this.schema,this.data]=Nc(this.schema,this.data.children);break}case 1:{let[e]=t,{fields:r,children:n,length:o}=Object.keys(e).reduce((c,B,d)=>(c.children[d]=e[B],c.length=Math.max(c.length,e[B].length),c.fields[d]=_.new({name:B,type:e[B].type,nullable:!0}),c),{length:0,fields:new Array,children:new Array}),s=new S(r),a=X({type:new Q(r),length:o,children:n,nullCount:0});[this.schema,this.data]=Nc(s,a.children,o);break}default:throw new TypeError("RecordBatch constructor expects an Object mapping names to child Data, or a [Schema, Data] pair.")}}get dictionaries(){return this._dictionaries||(this._dictionaries=Zc(this.schema.fields,this.data.children))}get numCols(){return this.schema.fields.length}get numRows(){return this.data.length}get nullCount(){return this.data.nullCount}isValid(t){return this.data.getValid(t)}get(t){return ot.visit(this.data,t)}set(t,e){return yt.visit(this.data,t,e)}indexOf(t,e){return Ci.visit(this.data,t,e)}getByteLength(t){return gt.visit(this.data,t)}[Symbol.iterator](){return zi.visit(new W([this.data]))}toArray(){return[...this]}concat(...t){return new Mt(this.schema,[this,...t])}slice(t,e){let[r]=new W([this.data]).slice(t,e).data;return new i(this.schema,r)}getChild(t){var e;return this.getChildAt((e=this.schema.fields)===null||e===void 0?void 0:e.findIndex(r=>r.name===t))}getChildAt(t){return t>-1&&t<this.schema.fields.length?new W([this.data.children[t]]):null}setChild(t,e){var r;return this.setChildAt((r=this.schema.fields)===null||r===void 0?void 0:r.findIndex(n=>n.name===t),e)}setChildAt(t,e){let r=this.schema,n=this.data;if(t>-1&&t<this.numCols){e||(e=new W([X({type:new Et,length:this.numRows})]));let o=r.fields.slice(),s=n.children.slice(),a=o[t].clone({type:e.type});[o[t],s[t]]=[a,e.data[0]],r=new S(o,new Map(this.schema.metadata)),n=X({type:new Q(o),children:s})}return new i(r,n)}select(t){let e=this.schema.select(t),r=new Q(e.fields),n=[];for(let o of t){let s=this.schema.fields.findIndex(a=>a.name===o);~s&&(n[s]=this.data.children[s])}return new i(e,X({type:r,length:this.numRows,children:n}))}selectAt(t){let e=this.schema.selectAt(t),r=t.map(o=>this.data.children[o]).filter(Boolean),n=X({type:new Q(e.fields),length:this.numRows,children:r});return new i(e,n)}};Tc=Symbol.toStringTag;tt[Tc]=(i=>(i._nullCount=-1,i[Symbol.isConcatSpreadable]=!0,"RecordBatch"))(tt.prototype);function Nc(i,t,e=t.reduce((r,n)=>Math.max(r,n.length),0)){var r;let n=[...i.fields],o=[...t],s=(e+63&-64)>>3;for(let[a,c]of i.fields.entries()){let B=t[a];(!B||B.length!==e)&&(n[a]=c.clone({nullable:!0}),o[a]=(r=B?._changeLengthAndBackfillNullBitmap(e))!==null&&r!==void 0?r:X({type:c.type,length:e,nullCount:e,nullBitmap:new Uint8Array(s)}))}return[i.assign(n),X({type:new Q(n),length:e,children:o})]}function Zc(i,t,e=new Map){var r,n;if(((r=i?.length)!==null&&r!==void 0?r:0)>0&&i?.length===t?.length)for(let o=-1,s=i.length;++o<s;){let{type:a}=i[o],c=t[o];for(let B of[c,...((n=c?.dictionary)===null||n===void 0?void 0:n.data)||[]])Zc(a.children,B?.children,e);if(h.isDictionary(a)){let{id:B}=a;if(!e.has(B))c?.dictionary&&e.set(B,c.dictionary);else if(e.get(B)!==c.dictionary)throw new Error("Cannot create Schema containing two different dictionaries with the same Id")}}return e}var xi=class extends tt{constructor(t){let e=t.fields.map(n=>X({type:n.type})),r=X({type:new Q(t.fields),nullCount:0,children:e});super(t,r)}};var Bn;(function(i){i[i.BUFFER=0]="BUFFER"})(Bn||(Bn={}));var dn;(function(i){i[i.LZ4_FRAME=0]="LZ4_FRAME",i[i.ZSTD=1]="ZSTD"})(dn||(dn={}));var Uo=class i{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsBodyCompression(t,e){return(e||new i).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsBodyCompression(t,e){return t.setPosition(t.position()+4),(e||new i).__init(t.readInt32(t.position())+t.position(),t)}codec(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readInt8(this.bb_pos+t):dn.LZ4_FRAME}method(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readInt8(this.bb_pos+t):Bn.BUFFER}static startBodyCompression(t){t.startObject(2)}static addCodec(t,e){t.addFieldInt8(0,e,dn.LZ4_FRAME)}static addMethod(t,e){t.addFieldInt8(1,e,Bn.BUFFER)}static endBodyCompression(t){return t.endObject()}static createBodyCompression(t,e,r){return i.startBodyCompression(t),i.addCodec(t,e),i.addMethod(t,r),i.endBodyCompression(t)}};var tr=class{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}offset(){return this.bb.readInt64(this.bb_pos)}length(){return this.bb.readInt64(this.bb_pos+8)}static sizeOf(){return 16}static createBuffer(t,e,r){return t.prep(8,16),t.writeInt64(BigInt(r??0)),t.writeInt64(BigInt(e??0)),t.offset()}};var er=class{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}length(){return this.bb.readInt64(this.bb_pos)}nullCount(){return this.bb.readInt64(this.bb_pos+8)}static sizeOf(){return 16}static createFieldNode(t,e,r){return t.prep(8,16),t.writeInt64(BigInt(r??0)),t.writeInt64(BigInt(e??0)),t.offset()}};var Zt=class i{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsRecordBatch(t,e){return(e||new i).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsRecordBatch(t,e){return t.setPosition(t.position()+4),(e||new i).__init(t.readInt32(t.position())+t.position(),t)}length(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readInt64(this.bb_pos+t):BigInt("0")}nodes(t,e){let r=this.bb.__offset(this.bb_pos,6);return r?(e||new er).__init(this.bb.__vector(this.bb_pos+r)+t*16,this.bb):null}nodesLength(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}buffers(t,e){let r=this.bb.__offset(this.bb_pos,8);return r?(e||new tr).__init(this.bb.__vector(this.bb_pos+r)+t*16,this.bb):null}buffersLength(){let t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}compression(t){let e=this.bb.__offset(this.bb_pos,10);return e?(t||new Uo).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}static startRecordBatch(t){t.startObject(4)}static addLength(t,e){t.addFieldInt64(0,e,BigInt("0"))}static addNodes(t,e){t.addFieldOffset(1,e,0)}static startNodesVector(t,e){t.startVector(16,e,8)}static addBuffers(t,e){t.addFieldOffset(2,e,0)}static startBuffersVector(t,e){t.startVector(16,e,8)}static addCompression(t,e){t.addFieldOffset(3,e,0)}static endRecordBatch(t){return t.endObject()}};var ke=class i{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsDictionaryBatch(t,e){return(e||new i).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsDictionaryBatch(t,e){return t.setPosition(t.position()+4),(e||new i).__init(t.readInt32(t.position())+t.position(),t)}id(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readInt64(this.bb_pos+t):BigInt("0")}data(t){let e=this.bb.__offset(this.bb_pos,6);return e?(t||new Zt).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}isDelta(){let t=this.bb.__offset(this.bb_pos,8);return t?!!this.bb.readInt8(this.bb_pos+t):!1}static startDictionaryBatch(t){t.startObject(3)}static addId(t,e){t.addFieldInt64(0,e,BigInt("0"))}static addData(t,e){t.addFieldOffset(1,e,0)}static addIsDelta(t,e){t.addFieldInt8(2,+e,0)}static endDictionaryBatch(t){return t.endObject()}};var ir;(function(i){i[i.NONE=0]="NONE",i[i.Schema=1]="Schema",i[i.DictionaryBatch=2]="DictionaryBatch",i[i.RecordBatch=3]="RecordBatch",i[i.Tensor=4]="Tensor",i[i.SparseTensor=5]="SparseTensor"})(ir||(ir={}));var le=class i{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsMessage(t,e){return(e||new i).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMessage(t,e){return t.setPosition(t.position()+4),(e||new i).__init(t.readInt32(t.position())+t.position(),t)}version(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readInt16(this.bb_pos+t):oi.V1}headerType(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readUint8(this.bb_pos+t):ir.NONE}header(t){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__union(t,this.bb_pos+e):null}bodyLength(){let t=this.bb.__offset(this.bb_pos,10);return t?this.bb.readInt64(this.bb_pos+t):BigInt("0")}customMetadata(t,e){let r=this.bb.__offset(this.bb_pos,12);return r?(e||new ut).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+t*4),this.bb):null}customMetadataLength(){let t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}static startMessage(t){t.startObject(5)}static addVersion(t,e){t.addFieldInt16(0,e,oi.V1)}static addHeaderType(t,e){t.addFieldInt8(1,e,ir.NONE)}static addHeader(t,e){t.addFieldOffset(2,e,0)}static addBodyLength(t,e){t.addFieldInt64(3,e,BigInt("0"))}static addCustomMetadata(t,e){t.addFieldOffset(4,e,0)}static createCustomMetadataVector(t,e){t.startVector(4,e.length,4);for(let r=e.length-1;r>=0;r--)t.addOffset(e[r]);return t.endVector()}static startCustomMetadataVector(t,e){t.startVector(4,e,4)}static endMessage(t){return t.endObject()}static finishMessageBuffer(t,e){t.finish(e)}static finishSizePrefixedMessageBuffer(t,e){t.finish(e,void 0,!0)}static createMessage(t,e,r,n,o,s){return i.startMessage(t),i.addVersion(t,e),i.addHeaderType(t,r),i.addHeader(t,n),i.addBodyLength(t,o),i.addCustomMetadata(t,s),i.endMessage(t)}};var Ks=class extends O{visit(t,e){return t==null||e==null?void 0:super.visit(t,e)}visitNull(t,e){return mr.startNull(e),mr.endNull(e)}visitInt(t,e){return ue.startInt(e),ue.addBitWidth(e,t.bitWidth),ue.addIsSigned(e,t.isSigned),ue.endInt(e)}visitFloat(t,e){return di.startFloatingPoint(e),di.addPrecision(e,t.precision),di.endFloatingPoint(e)}visitBinary(t,e){return Rr.startBinary(e),Rr.endBinary(e)}visitBool(t,e){return pr.startBool(e),pr.endBool(e)}visitUtf8(t,e){return _r.startUtf8(e),_r.endUtf8(e)}visitDecimal(t,e){return Ce.startDecimal(e),Ce.addScale(e,t.scale),Ce.addPrecision(e,t.precision),Ce.addBitWidth(e,t.bitWidth),Ce.endDecimal(e)}visitDate(t,e){return ai.startDate(e),ai.addUnit(e,t.unit),ai.endDate(e)}visitTime(t,e){return Ze.startTime(e),Ze.addUnit(e,t.unit),Ze.addBitWidth(e,t.bitWidth),Ze.endTime(e)}visitTimestamp(t,e){let r=t.timezone&&e.createString(t.timezone)||void 0;return Se.startTimestamp(e),Se.addUnit(e,t.unit),r!==void 0&&Se.addTimezone(e,r),Se.endTimestamp(e)}visitInterval(t,e){return li.startInterval(e),li.addUnit(e,t.unit),li.endInterval(e)}visitDuration(t,e){return ci.startDuration(e),ci.addUnit(e,t.unit),ci.endDuration(e)}visitList(t,e){return Hr.startList(e),Hr.endList(e)}visitStruct(t,e){return Yr.startStruct_(e),Yr.endStruct_(e)}visitUnion(t,e){de.startTypeIdsVector(e,t.typeIds.length);let r=de.createTypeIdsVector(e,t.typeIds);return de.startUnion(e),de.addMode(e,t.mode),de.addTypeIds(e,r),de.endUnion(e)}visitDictionary(t,e){let r=this.visit(t.indices,e);return Me.startDictionaryEncoding(e),Me.addId(e,BigInt(t.id)),Me.addIsOrdered(e,t.isOrdered),r!==void 0&&Me.addIndexType(e,r),Me.endDictionaryEncoding(e)}visitFixedSizeBinary(t,e){return ui.startFixedSizeBinary(e),ui.addByteWidth(e,t.byteWidth),ui.endFixedSizeBinary(e)}visitFixedSizeList(t,e){return Bi.startFixedSizeList(e),Bi.addListSize(e,t.listSize),Bi.endFixedSizeList(e)}visitMap(t,e){return fi.startMap(e),fi.addKeysSorted(e,t.keysSorted),fi.endMap(e)}},Jo=new Ks;function jc(i,t=new Map){return new S(gd(i,t),jo(i.metadata),t)}function Vs(i){return new wt(i.count,zc(i.columns),Qc(i.columns))}function Pc(i){return new mt(Vs(i.data),i.id,i.isDelta)}function gd(i,t){return(i.fields||[]).filter(Boolean).map(e=>_.fromJSON(e,t))}function Sc(i,t){return(i.children||[]).filter(Boolean).map(e=>_.fromJSON(e,t))}function zc(i){return(i||[]).reduce((t,e)=>[...t,new Kt(e.count,Nd(e.VALIDITY)),...zc(e.children)],[])}function Qc(i,t=[]){for(let e=-1,r=(i||[]).length;++e<r;){let n=i[e];n.VALIDITY&&t.push(new Ht(t.length,n.VALIDITY.length)),n.TYPE_ID&&t.push(new Ht(t.length,n.TYPE_ID.length)),n.OFFSET&&t.push(new Ht(t.length,n.OFFSET.length)),n.DATA&&t.push(new Ht(t.length,n.DATA.length)),t=Qc(n.children,t)}return t}function Nd(i){return(i||[]).reduce((t,e)=>t+ +(e===0),0)}function Kc(i,t){let e,r,n,o,s,a;return!t||!(o=i.dictionary)?(s=Jc(i,Sc(i,t)),n=new _(i.name,s,i.nullable,jo(i.metadata))):t.has(e=o.id)?(r=(r=o.indexType)?Uc(r):new De,a=new Gt(t.get(e),r,e,o.isOrdered),n=new _(i.name,a,i.nullable,jo(i.metadata))):(r=(r=o.indexType)?Uc(r):new De,t.set(e,s=Jc(i,Sc(i,t))),a=new Gt(s,r,e,o.isOrdered),n=new _(i.name,a,i.nullable,jo(i.metadata))),n||null}function jo(i=[]){return new Map(i.map(({key:t,value:e})=>[t,e]))}function Uc(i){return new rt(i.isSigned,i.bitWidth)}function Jc(i,t){let e=i.type.name;switch(e){case"NONE":return new Et;case"null":return new Et;case"binary":return new Xe;case"utf8":return new He;case"bool":return new me;case"list":return new re((t||[])[0]);case"struct":return new Q(t||[]);case"struct_":return new Q(t||[])}switch(e){case"int":{let r=i.type;return new rt(r.isSigned,r.bitWidth)}case"floatingpoint":{let r=i.type;return new bt(k[r.precision])}case"decimal":{let r=i.type;return new Ye(r.scale,r.precision,r.bitWidth)}case"date":{let r=i.type;return new xe(ht[r.unit])}case"time":{let r=i.type;return new ie(F[r.unit],r.bitWidth)}case"timestamp":{let r=i.type;return new _e(F[r.unit],r.timezone)}case"interval":{let r=i.type;return new Ge(It[r.unit])}case"duration":{let r=i.type;return new We(F[r.unit])}case"union":{let r=i.type,[n,...o]=(r.mode+"").toLowerCase(),s=n.toUpperCase()+o.join("");return new ne(z[s],r.typeIds||[],t||[])}case"fixedsizebinary":{let r=i.type;return new ge(r.byteWidth)}case"fixedsizelist":{let r=i.type;return new oe(r.listSize,(t||[])[0])}case"map":{let r=i.type;return new se((t||[])[0],r.keysSorted)}}throw new Error(`Unrecognized type: "${e}"`)}var Td=pi,Zd=Nt,Yt=class i{static fromJSON(t,e){let r=new i(0,$.V5,e);return r._createHeader=Sd(t,e),r}static decode(t){t=new Zd(b(t));let e=le.getRootAsMessage(t),r=e.bodyLength(),n=e.version(),o=e.headerType(),s=new i(r,n,o);return s._createHeader=Ud(e,o),s}static encode(t){let e=new Td,r=-1;return t.isSchema()?r=S.encode(e,t.header()):t.isRecordBatch()?r=wt.encode(e,t.header()):t.isDictionaryBatch()&&(r=mt.encode(e,t.header())),le.startMessage(e),le.addVersion(e,$.V5),le.addHeader(e,r),le.addHeaderType(e,t.headerType),le.addBodyLength(e,BigInt(t.bodyLength)),le.finishMessageBuffer(e,le.endMessage(e)),e.asUint8Array()}static from(t,e=0){if(t instanceof S)return new i(0,$.V5,N.Schema,t);if(t instanceof wt)return new i(e,$.V5,N.RecordBatch,t);if(t instanceof mt)return new i(e,$.V5,N.DictionaryBatch,t);throw new Error(`Unrecognized Message header: ${t}`)}get type(){return this.headerType}get version(){return this._version}get headerType(){return this._headerType}get bodyLength(){return this._bodyLength}header(){return this._createHeader()}isSchema(){return this.headerType===N.Schema}isRecordBatch(){return this.headerType===N.RecordBatch}isDictionaryBatch(){return this.headerType===N.DictionaryBatch}constructor(t,e,r,n){this._version=e,this._headerType=r,this.body=new Uint8Array(0),n&&(this._createHeader=()=>n),this._bodyLength=Lt(t)}},wt=class{get nodes(){return this._nodes}get length(){return this._length}get buffers(){return this._buffers}constructor(t,e,r){this._nodes=e,this._buffers=r,this._length=Lt(t)}},mt=class{get id(){return this._id}get data(){return this._data}get isDelta(){return this._isDelta}get length(){return this.data.length}get nodes(){return this.data.nodes}get buffers(){return this.data.buffers}constructor(t,e,r=!1){this._data=t,this._isDelta=r,this._id=Lt(e)}},Ht=class{constructor(t,e){this.offset=Lt(t),this.length=Lt(e)}},Kt=class{constructor(t,e){this.length=Lt(t),this.nullCount=Lt(e)}};function Sd(i,t){return()=>{switch(t){case N.Schema:return S.fromJSON(i);case N.RecordBatch:return wt.fromJSON(i);case N.DictionaryBatch:return mt.fromJSON(i)}throw new Error(`Unrecognized Message type: { name: ${N[t]}, type: ${t} }`)}}function Ud(i,t){return()=>{switch(t){case N.Schema:return S.decode(i.header(new Xt),new Map,i.version());case N.RecordBatch:return wt.decode(i.header(new Zt),i.version());case N.DictionaryBatch:return mt.decode(i.header(new ke),i.version())}throw new Error(`Unrecognized Message type: { name: ${N[t]}, type: ${t} }`)}}_.encode=Ad;_.decode=qd;_.fromJSON=Kc;S.encode=$d;S.decode=Jd;S.fromJSON=jc;wt.encode=tl;wt.decode=jd;wt.fromJSON=Vs;mt.encode=el;mt.decode=Pd;mt.fromJSON=Pc;Kt.encode=il;Kt.decode=Qd;Ht.encode=rl;Ht.decode=zd;function Jd(i,t=new Map,e=$.V5){let r=kd(i,t);return new S(r,Po(i),t,e)}function jd(i,t=$.V5){if(i.compression()!==null)throw new Error("Record batch compression not implemented");return new wt(i.length(),Kd(i),Vd(i,t))}function Pd(i,t=$.V5){return new mt(wt.decode(i.data(),t),i.id(),i.isDelta())}function zd(i){return new Ht(i.offset(),i.length())}function Qd(i){return new Kt(i.length(),i.nullCount())}function Kd(i){let t=[];for(let e,r=-1,n=-1,o=i.nodesLength();++r<o;)(e=i.nodes(r))&&(t[++n]=Kt.decode(e));return t}function Vd(i,t){let e=[];for(let r,n=-1,o=-1,s=i.buffersLength();++n<s;)(r=i.buffers(n))&&(t<$.V4&&(r.bb_pos+=8*(n+1)),e[++o]=Ht.decode(r));return e}function kd(i,t){let e=[];for(let r,n=-1,o=-1,s=i.fieldsLength();++n<s;)(r=i.fields(n))&&(e[++o]=_.decode(r,t));return e}function Vc(i,t){let e=[];for(let r,n=-1,o=-1,s=i.childrenLength();++n<s;)(r=i.children(n))&&(e[++o]=_.decode(r,t));return e}function qd(i,t){let e,r,n,o,s,a;return!t||!(a=i.dictionary())?(n=qc(i,Vc(i,t)),r=new _(i.name(),n,i.nullable(),Po(i))):t.has(e=Lt(a.id()))?(o=(o=a.indexType())?kc(o):new De,s=new Gt(t.get(e),o,e,a.isOrdered()),r=new _(i.name(),s,i.nullable(),Po(i))):(o=(o=a.indexType())?kc(o):new De,t.set(e,n=qc(i,Vc(i,t))),s=new Gt(n,o,e,a.isOrdered()),r=new _(i.name(),s,i.nullable(),Po(i))),r||null}function Po(i){let t=new Map;if(i)for(let e,r,n=-1,o=Math.trunc(i.customMetadataLength());++n<o;)(e=i.customMetadata(n))&&(r=e.key())!=null&&t.set(r,e.value());return t}function kc(i){return new rt(i.isSigned(),i.bitWidth())}function qc(i,t){let e=i.typeType();switch(e){case K.NONE:return new Et;case K.Null:return new Et;case K.Binary:return new Xe;case K.Utf8:return new He;case K.Bool:return new me;case K.List:return new re((t||[])[0]);case K.Struct_:return new Q(t||[])}switch(e){case K.Int:{let r=i.type(new ue);return new rt(r.isSigned(),r.bitWidth())}case K.FloatingPoint:{let r=i.type(new di);return new bt(r.precision())}case K.Decimal:{let r=i.type(new Ce);return new Ye(r.scale(),r.precision(),r.bitWidth())}case K.Date:{let r=i.type(new ai);return new xe(r.unit())}case K.Time:{let r=i.type(new Ze);return new ie(r.unit(),r.bitWidth())}case K.Timestamp:{let r=i.type(new Se);return new _e(r.unit(),r.timezone())}case K.Interval:{let r=i.type(new li);return new Ge(r.unit())}case K.Duration:{let r=i.type(new ci);return new We(r.unit())}case K.Union:{let r=i.type(new de);return new ne(r.mode(),r.typeIdsArray()||[],t||[])}case K.FixedSizeBinary:{let r=i.type(new ui);return new ge(r.byteWidth())}case K.FixedSizeList:{let r=i.type(new Bi);return new oe(r.listSize(),(t||[])[0])}case K.Map:{let r=i.type(new fi);return new se((t||[])[0],r.keysSorted())}}throw new Error(`Unrecognized type: "${K[e]}" (${e})`)}function $d(i,t){let e=t.fields.map(o=>_.encode(i,o));Xt.startFieldsVector(i,e.length);let r=Xt.createFieldsVector(i,e),n=t.metadata&&t.metadata.size>0?Xt.createCustomMetadataVector(i,[...t.metadata].map(([o,s])=>{let a=i.createString(`${o}`),c=i.createString(`${s}`);return ut.startKeyValue(i),ut.addKey(i,a),ut.addValue(i,c),ut.endKeyValue(i)})):-1;return Xt.startSchema(i),Xt.addFields(i,r),Xt.addEndianness(i,nl?si.Little:si.Big),n!==-1&&Xt.addCustomMetadata(i,n),Xt.endSchema(i)}function Ad(i,t){let e=-1,r=-1,n=-1,o=t.type,s=t.typeId;h.isDictionary(o)?(s=o.dictionary.typeId,n=Jo.visit(o,i),r=Jo.visit(o.dictionary,i)):r=Jo.visit(o,i);let a=(o.children||[]).map(d=>_.encode(i,d)),c=Dt.createChildrenVector(i,a),B=t.metadata&&t.metadata.size>0?Dt.createCustomMetadataVector(i,[...t.metadata].map(([d,l])=>{let D=i.createString(`${d}`),y=i.createString(`${l}`);return ut.startKeyValue(i),ut.addKey(i,D),ut.addValue(i,y),ut.endKeyValue(i)})):-1;return t.name&&(e=i.createString(t.name)),Dt.startField(i),Dt.addType(i,r),Dt.addTypeType(i,s),Dt.addChildren(i,c),Dt.addNullable(i,!!t.nullable),e!==-1&&Dt.addName(i,e),n!==-1&&Dt.addDictionary(i,n),B!==-1&&Dt.addCustomMetadata(i,B),Dt.endField(i)}function tl(i,t){let e=t.nodes||[],r=t.buffers||[];Zt.startNodesVector(i,e.length);for(let s of e.slice().reverse())Kt.encode(i,s);let n=i.endVector();Zt.startBuffersVector(i,r.length);for(let s of r.slice().reverse())Ht.encode(i,s);let o=i.endVector();return Zt.startRecordBatch(i),Zt.addLength(i,BigInt(t.length)),Zt.addNodes(i,n),Zt.addBuffers(i,o),Zt.endRecordBatch(i)}function el(i,t){let e=wt.encode(i,t.data);return ke.startDictionaryBatch(i),ke.addId(i,BigInt(t.id)),ke.addIsDelta(i,t.isDelta),ke.addData(i,e),ke.endDictionaryBatch(i)}function il(i,t){return er.createFieldNode(i,BigInt(t.length),BigInt(t.nullCount))}function rl(i,t){return tr.createBuffer(i,BigInt(t.offset),BigInt(t.length))}var nl=(()=>{let i=new ArrayBuffer(2);return new DataView(i).setInt16(0,256,!0),new Int16Array(i)[0]===256})();var qs=i=>`Expected ${N[i]} Message in stream, but was null or length 0.`,$s=i=>`Header pointer of flatbuffer-encoded ${N[i]} Message is null or length 0.`,$c=(i,t)=>`Expected to read ${i} metadata bytes, but only read ${t}.`,Ac=(i,t)=>`Expected to read ${i} bytes for message body, but only read ${t}.`,rr=class{constructor(t){this.source=t instanceof pe?t:new pe(t)}[Symbol.iterator](){return this}next(){let t;return(t=this.readMetadataLength()).done?V:t.value===-1&&(t=this.readMetadataLength()).done?V:(t=this.readMetadata(t.value)).done?V:t}throw(t){return this.source.throw(t)}return(t){return this.source.return(t)}readMessage(t){let e;if((e=this.next()).done)return null;if(t!=null&&e.value.headerType!==t)throw new Error(qs(t));return e.value}readMessageBody(t){if(t<=0)return new Uint8Array(0);let e=b(this.source.read(t));if(e.byteLength<t)throw new Error(Ac(t,e.byteLength));return e.byteOffset%8===0&&e.byteOffset+e.byteLength<=e.buffer.byteLength?e:e.slice()}readSchema(t=!1){let e=N.Schema,r=this.readMessage(e),n=r?.header();if(t&&!n)throw new Error($s(e));return n}readMetadataLength(){let t=this.source.read(zo),e=t&&new Nt(t),r=e?.readInt32(0)||0;return{done:r===0,value:r}}readMetadata(t){let e=this.source.read(t);if(!e)return V;if(e.byteLength<t)throw new Error($c(t,e.byteLength));return{done:!1,value:Yt.decode(e)}}},ln=class{constructor(t,e){this.source=t instanceof zt?t:Rn(t)?new hi(t,e):new zt(t)}[Symbol.asyncIterator](){return this}next(){return f(this,void 0,void 0,function*(){let t;return(t=yield this.readMetadataLength()).done?V:t.value===-1&&(t=yield this.readMetadataLength()).done?V:(t=yield this.readMetadata(t.value)).done?V:t})}throw(t){return f(this,void 0,void 0,function*(){return yield this.source.throw(t)})}return(t){return f(this,void 0,void 0,function*(){return yield this.source.return(t)})}readMessage(t){return f(this,void 0,void 0,function*(){let e;if((e=yield this.next()).done)return null;if(t!=null&&e.value.headerType!==t)throw new Error(qs(t));return e.value})}readMessageBody(t){return f(this,void 0,void 0,function*(){if(t<=0)return new Uint8Array(0);let e=b(yield this.source.read(t));if(e.byteLength<t)throw new Error(Ac(t,e.byteLength));return e.byteOffset%8===0&&e.byteOffset+e.byteLength<=e.buffer.byteLength?e:e.slice()})}readSchema(t=!1){return f(this,void 0,void 0,function*(){let e=N.Schema,r=yield this.readMessage(e),n=r?.header();if(t&&!n)throw new Error($s(e));return n})}readMetadataLength(){return f(this,void 0,void 0,function*(){let t=yield this.source.read(zo),e=t&&new Nt(t),r=e?.readInt32(0)||0;return{done:r===0,value:r}})}readMetadata(t){return f(this,void 0,void 0,function*(){let e=yield this.source.read(t);if(!e)return V;if(e.byteLength<t)throw new Error($c(t,e.byteLength));return{done:!1,value:Yt.decode(e)}})}},fn=class extends rr{constructor(t){super(new Uint8Array(0)),this._schema=!1,this._body=[],this._batchIndex=0,this._dictionaryIndex=0,this._json=t instanceof Gr?t:new Gr(t)}next(){let{_json:t}=this;if(!this._schema)return this._schema=!0,{done:!1,value:Yt.fromJSON(t.schema,N.Schema)};if(this._dictionaryIndex<t.dictionaries.length){let e=t.dictionaries[this._dictionaryIndex++];return this._body=e.data.columns,{done:!1,value:Yt.fromJSON(e,N.DictionaryBatch)}}if(this._batchIndex<t.batches.length){let e=t.batches[this._batchIndex++];return this._body=e.columns,{done:!1,value:Yt.fromJSON(e,N.RecordBatch)}}return this._body=[],V}readMessageBody(t){return e(this._body);function e(r){return(r||[]).reduce((n,o)=>[...n,...o.VALIDITY&&[o.VALIDITY]||[],...o.TYPE_ID&&[o.TYPE_ID]||[],...o.OFFSET&&[o.OFFSET]||[],...o.DATA&&[o.DATA]||[],...e(o.children)],[])}}readMessage(t){let e;if((e=this.next()).done)return null;if(t!=null&&e.value.headerType!==t)throw new Error(qs(t));return e.value}readSchema(){let t=N.Schema,e=this.readMessage(t),r=e?.header();if(!e||!r)throw new Error($s(t));return r}},zo=4,ks="ARROW1",nr=new Uint8Array(ks.length);for(let i=0;i<ks.length;i+=1)nr[i]=ks.codePointAt(i);function Qo(i,t=0){for(let e=-1,r=nr.length;++e<r;)if(nr[e]!==i[t+e])return!1;return!0}var or=nr.length,As=or+zo,tu=or*2+zo;var Ot=class i extends Li{constructor(t){super(),this._impl=t}get closed(){return this._impl.closed}get schema(){return this._impl.schema}get autoDestroy(){return this._impl.autoDestroy}get dictionaries(){return this._impl.dictionaries}get numDictionaries(){return this._impl.numDictionaries}get numRecordBatches(){return this._impl.numRecordBatches}get footer(){return this._impl.isFile()?this._impl.footer:null}isSync(){return this._impl.isSync()}isAsync(){return this._impl.isAsync()}isFile(){return this._impl.isFile()}isStream(){return this._impl.isStream()}next(){return this._impl.next()}throw(t){return this._impl.throw(t)}return(t){return this._impl.return(t)}cancel(){return this._impl.cancel()}reset(t){return this._impl.reset(t),this._DOMStream=void 0,this._nodeStream=void 0,this}open(t){let e=this._impl.open(t);return qt(e)?e.then(()=>this):this}readRecordBatch(t){return this._impl.isFile()?this._impl.readRecordBatch(t):null}[Symbol.iterator](){return this._impl[Symbol.iterator]()}[Symbol.asyncIterator](){return this._impl[Symbol.asyncIterator]()}toDOMStream(){return ft.toDOMStream(this.isSync()?{[Symbol.iterator]:()=>this}:{[Symbol.asyncIterator]:()=>this})}toNodeStream(){return ft.toNodeStream(this.isSync()?{[Symbol.iterator]:()=>this}:{[Symbol.asyncIterator]:()=>this},{objectMode:!0})}static throughNode(t){throw new Error('"throughNode" not available in this environment')}static throughDOM(t,e){throw new Error('"throughDOM" not available in this environment')}static from(t){return t instanceof i?t:Mn(t)?sl(t):Rn(t)?ul(t):qt(t)?f(this,void 0,void 0,function*(){return yield i.from(yield t)}):pn(t)||yr(t)||bn(t)||Ut(t)?cl(new zt(t)):al(new pe(t))}static readAll(t){return t instanceof i?t.isSync()?eu(t):iu(t):Mn(t)||ArrayBuffer.isView(t)||$t(t)||Cn(t)?eu(t):iu(t)}},be=class extends Ot{constructor(t){super(t),this._impl=t}readAll(){return[...this]}[Symbol.iterator](){return this._impl[Symbol.iterator]()}[Symbol.asyncIterator](){return xt(this,arguments,function*(){yield m(yield*gi(kt(this[Symbol.iterator]())))})}},yi=class extends Ot{constructor(t){super(t),this._impl=t}readAll(){var t,e,r,n;return f(this,void 0,void 0,function*(){let o=new Array;try{for(var s=!0,a=kt(this),c;c=yield a.next(),t=c.done,!t;s=!0){n=c.value,s=!1;let B=n;o.push(B)}}catch(B){e={error:B}}finally{try{!s&&!t&&(r=a.return)&&(yield r.call(a))}finally{if(e)throw e.error}}return o})}[Symbol.iterator](){throw new Error("AsyncRecordBatchStreamReader is not Iterable")}[Symbol.asyncIterator](){return this._impl[Symbol.asyncIterator]()}},wi=class extends be{constructor(t){super(t),this._impl=t}},hn=class extends yi{constructor(t){super(t),this._impl=t}},Ko=class{get numDictionaries(){return this._dictionaryIndex}get numRecordBatches(){return this._recordBatchIndex}constructor(t=new Map){this.closed=!1,this.autoDestroy=!0,this._dictionaryIndex=0,this._recordBatchIndex=0,this.dictionaries=t}isSync(){return!1}isAsync(){return!1}isFile(){return!1}isStream(){return!1}reset(t){return this._dictionaryIndex=0,this._recordBatchIndex=0,this.schema=t,this.dictionaries=new Map,this}_loadRecordBatch(t,e){let r=this._loadVectors(t,e,this.schema.fields),n=X({type:new Q(this.schema.fields),length:t.length,children:r});return new tt(this.schema,n)}_loadDictionaryBatch(t,e){let{id:r,isDelta:n}=t,{dictionaries:o,schema:s}=this,a=o.get(r);if(n||!a){let c=s.dictionaries.get(r),B=this._loadVectors(t.data,e,[c]);return(a&&n?a.concat(new W(B)):new W(B)).memoize()}return a.memoize()}_loadVectors(t,e,r){return new Tr(e,t.nodes,t.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(r)}},sr=class extends Ko{constructor(t,e){super(e),this._reader=Mn(t)?new fn(this._handle=t):new rr(this._handle=t)}isSync(){return!0}isStream(){return!0}[Symbol.iterator](){return this}cancel(){!this.closed&&(this.closed=!0)&&(this.reset()._reader.return(),this._reader=null,this.dictionaries=null)}open(t){return this.closed||(this.autoDestroy=ru(this,t),this.schema||(this.schema=this._reader.readSchema())||this.cancel()),this}throw(t){return!this.closed&&this.autoDestroy&&(this.closed=!0)?this.reset()._reader.throw(t):V}return(t){return!this.closed&&this.autoDestroy&&(this.closed=!0)?this.reset()._reader.return(t):V}next(){if(this.closed)return V;let t,{_reader:e}=this;for(;t=this._readNextMessageAndValidate();)if(t.isSchema())this.reset(t.header());else if(t.isRecordBatch()){this._recordBatchIndex++;let r=t.header(),n=e.readMessageBody(t.bodyLength);return{done:!1,value:this._loadRecordBatch(r,n)}}else if(t.isDictionaryBatch()){this._dictionaryIndex++;let r=t.header(),n=e.readMessageBody(t.bodyLength),o=this._loadDictionaryBatch(r,n);this.dictionaries.set(r.id,o)}return this.schema&&this._recordBatchIndex===0?(this._recordBatchIndex++,{done:!1,value:new xi(this.schema)}):this.return()}_readNextMessageAndValidate(t){return this._reader.readMessage(t)}},ar=class extends Ko{constructor(t,e){super(e),this._reader=new ln(this._handle=t)}isAsync(){return!0}isStream(){return!0}[Symbol.asyncIterator](){return this}cancel(){return f(this,void 0,void 0,function*(){!this.closed&&(this.closed=!0)&&(yield this.reset()._reader.return(),this._reader=null,this.dictionaries=null)})}open(t){return f(this,void 0,void 0,function*(){return this.closed||(this.autoDestroy=ru(this,t),this.schema||(this.schema=yield this._reader.readSchema())||(yield this.cancel())),this})}throw(t){return f(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.throw(t):V})}return(t){return f(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.return(t):V})}next(){return f(this,void 0,void 0,function*(){if(this.closed)return V;let t,{_reader:e}=this;for(;t=yield this._readNextMessageAndValidate();)if(t.isSchema())yield this.reset(t.header());else if(t.isRecordBatch()){this._recordBatchIndex++;let r=t.header(),n=yield e.readMessageBody(t.bodyLength);return{done:!1,value:this._loadRecordBatch(r,n)}}else if(t.isDictionaryBatch()){this._dictionaryIndex++;let r=t.header(),n=yield e.readMessageBody(t.bodyLength),o=this._loadDictionaryBatch(r,n);this.dictionaries.set(r.id,o)}return this.schema&&this._recordBatchIndex===0?(this._recordBatchIndex++,{done:!1,value:new xi(this.schema)}):yield this.return()})}_readNextMessageAndValidate(t){return f(this,void 0,void 0,function*(){return yield this._reader.readMessage(t)})}},Vo=class extends sr{get footer(){return this._footer}get numDictionaries(){return this._footer?this._footer.numDictionaries:0}get numRecordBatches(){return this._footer?this._footer.numRecordBatches:0}constructor(t,e){super(t instanceof Wr?t:new Wr(t),e)}isSync(){return!0}isFile(){return!0}open(t){if(!this.closed&&!this._footer){this.schema=(this._footer=this._readFooter()).schema;for(let e of this._footer.dictionaryBatches())e&&this._readDictionaryBatch(this._dictionaryIndex++)}return super.open(t)}readRecordBatch(t){var e;if(this.closed)return null;this._footer||this.open();let r=(e=this._footer)===null||e===void 0?void 0:e.getRecordBatch(t);if(r&&this._handle.seek(r.offset)){let n=this._reader.readMessage(N.RecordBatch);if(n?.isRecordBatch()){let o=n.header(),s=this._reader.readMessageBody(n.bodyLength);return this._loadRecordBatch(o,s)}}return null}_readDictionaryBatch(t){var e;let r=(e=this._footer)===null||e===void 0?void 0:e.getDictionaryBatch(t);if(r&&this._handle.seek(r.offset)){let n=this._reader.readMessage(N.DictionaryBatch);if(n?.isDictionaryBatch()){let o=n.header(),s=this._reader.readMessageBody(n.bodyLength),a=this._loadDictionaryBatch(o,s);this.dictionaries.set(o.id,a)}}}_readFooter(){let{_handle:t}=this,e=t.size-As,r=t.readInt32(e),n=t.readAt(e-r,r);return Ue.decode(n)}_readNextMessageAndValidate(t){var e;if(this._footer||this.open(),this._footer&&this._recordBatchIndex<this.numRecordBatches){let r=(e=this._footer)===null||e===void 0?void 0:e.getRecordBatch(this._recordBatchIndex);if(r&&this._handle.seek(r.offset))return this._reader.readMessage(t)}return null}},ta=class extends ar{get footer(){return this._footer}get numDictionaries(){return this._footer?this._footer.numDictionaries:0}get numRecordBatches(){return this._footer?this._footer.numRecordBatches:0}constructor(t,...e){let r=typeof e[0]!="number"?e.shift():void 0,n=e[0]instanceof Map?e.shift():void 0;super(t instanceof hi?t:new hi(t,r),n)}isFile(){return!0}isAsync(){return!0}open(t){let e=Object.create(null,{open:{get:()=>super.open}});return f(this,void 0,void 0,function*(){if(!this.closed&&!this._footer){this.schema=(this._footer=yield this._readFooter()).schema;for(let r of this._footer.dictionaryBatches())r&&(yield this._readDictionaryBatch(this._dictionaryIndex++))}return yield e.open.call(this,t)})}readRecordBatch(t){var e;return f(this,void 0,void 0,function*(){if(this.closed)return null;this._footer||(yield this.open());let r=(e=this._footer)===null||e===void 0?void 0:e.getRecordBatch(t);if(r&&(yield this._handle.seek(r.offset))){let n=yield this._reader.readMessage(N.RecordBatch);if(n?.isRecordBatch()){let o=n.header(),s=yield this._reader.readMessageBody(n.bodyLength);return this._loadRecordBatch(o,s)}}return null})}_readDictionaryBatch(t){var e;return f(this,void 0,void 0,function*(){let r=(e=this._footer)===null||e===void 0?void 0:e.getDictionaryBatch(t);if(r&&(yield this._handle.seek(r.offset))){let n=yield this._reader.readMessage(N.DictionaryBatch);if(n?.isDictionaryBatch()){let o=n.header(),s=yield this._reader.readMessageBody(n.bodyLength),a=this._loadDictionaryBatch(o,s);this.dictionaries.set(o.id,a)}}})}_readFooter(){return f(this,void 0,void 0,function*(){let{_handle:t}=this;t._pending&&(yield t._pending);let e=t.size-As,r=yield t.readInt32(e),n=yield t.readAt(e-r,r);return Ue.decode(n)})}_readNextMessageAndValidate(t){return f(this,void 0,void 0,function*(){if(this._footer||(yield this.open()),this._footer&&this._recordBatchIndex<this.numRecordBatches){let e=this._footer.getRecordBatch(this._recordBatchIndex);if(e&&(yield this._handle.seek(e.offset)))return yield this._reader.readMessage(t)}return null})}},ea=class extends sr{constructor(t,e){super(t,e)}_loadVectors(t,e,r){return new Fo(e,t.nodes,t.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(r)}};function ru(i,t){return t&&typeof t.autoDestroy=="boolean"?t.autoDestroy:i.autoDestroy}function*eu(i){let t=Ot.from(i);try{if(!t.open({autoDestroy:!1}).closed)do yield t;while(!t.reset().open().closed)}finally{t.cancel()}}function iu(i){return xt(this,arguments,function*(){let e=yield m(Ot.from(i));try{if(!(yield m(e.open({autoDestroy:!1}))).closed)do yield yield m(e);while(!(yield m(e.reset().open())).closed)}finally{yield m(e.cancel())}})}function sl(i){return new be(new ea(i))}function al(i){let t=i.peek(or+7&-8);return t&&t.byteLength>=4?Qo(t)?new wi(new Vo(i.read())):new be(new sr(i)):new be(new sr(function*(){}()))}function cl(i){return f(this,void 0,void 0,function*(){let t=yield i.peek(or+7&-8);return t&&t.byteLength>=4?Qo(t)?new wi(new Vo(yield i.read())):new yi(new ar(i)):new yi(new ar(function(){return xt(this,arguments,function*(){})}()))})}function ul(i){return f(this,void 0,void 0,function*(){let{size:t}=yield i.stat(),e=new hi(i,t);return t>=tu&&Qo(yield e.readAt(0,or+7&-8))?new hn(new ta(e)):new yi(new ar(e))})}var et=class i extends O{static assemble(...t){let e=n=>n.flatMap(o=>Array.isArray(o)?e(o):o instanceof tt?o.data.children:o.data),r=new i;return r.visitMany(e(t)),r}constructor(){super(),this._byteLength=0,this._nodes=[],this._buffers=[],this._bufferRegions=[]}visit(t){if(t instanceof W)return this.visitMany(t.data),this;let{type:e}=t;if(!h.isDictionary(e)){let{length:r}=t;if(r>2147483647)throw new RangeError("Cannot write arrays larger than 2^31 - 1 in length");if(h.isUnion(e))this.nodes.push(new Kt(r,0));else{let{nullCount:n}=t;h.isNull(e)||fe.call(this,n<=0?new Uint8Array(0):vi(t.offset,r,t.nullBitmap)),this.nodes.push(new Kt(r,n))}}return super.visit(t)}visitNull(t){return this}visitDictionary(t){return this.visit(t.clone(t.type.indices))}get nodes(){return this._nodes}get buffers(){return this._buffers}get byteLength(){return this._byteLength}get bufferRegions(){return this._bufferRegions}};function fe(i){let t=i.byteLength+7&-8;return this.buffers.push(i),this.bufferRegions.push(new Ht(this._byteLength,t)),this._byteLength+=t,this}function Bl(i){var t;let{type:e,length:r,typeIds:n,valueOffsets:o}=i;if(fe.call(this,n),e.mode===z.Sparse)return ia.call(this,i);if(e.mode===z.Dense){if(i.offset<=0)return fe.call(this,o),ia.call(this,i);{let s=new Int32Array(r),a=Object.create(null),c=Object.create(null);for(let B,d,l=-1;++l<r;)(B=n[l])!==void 0&&((d=a[B])===void 0&&(d=a[B]=o[l]),s[l]=o[l]-d,c[B]=((t=c[B])!==null&&t!==void 0?t:0)+1);fe.call(this,s),this.visitMany(i.children.map((B,d)=>{let l=e.typeIds[d],D=a[l],y=c[l];return B.slice(D,Math.min(r,y))}))}}return this}function dl(i){let t;return i.nullCount>=i.length?fe.call(this,new Uint8Array(0)):(t=i.values)instanceof Uint8Array?fe.call(this,vi(i.offset,i.length,t)):fe.call(this,Mi(i.values))}function qe(i){return fe.call(this,i.values.subarray(0,i.length*i.stride))}function nu(i){let{length:t,values:e,valueOffsets:r}=i,{[0]:n,[t]:o}=r,s=Math.min(o-n,e.byteLength-n);return fe.call(this,Xn(-n,t+1,r)),fe.call(this,e.subarray(n,n+s)),this}function ra(i){let{length:t,valueOffsets:e}=i;if(e){let{[0]:r,[t]:n}=e;return fe.call(this,Xn(-r,t+1,e)),this.visit(i.children[0].slice(r,n-r))}return this.visit(i.children[0])}function ia(i){return this.visitMany(i.type.children.map((t,e)=>i.children[e]).filter(Boolean))[0]}et.prototype.visitBool=dl;et.prototype.visitInt=qe;et.prototype.visitFloat=qe;et.prototype.visitUtf8=nu;et.prototype.visitBinary=nu;et.prototype.visitFixedSizeBinary=qe;et.prototype.visitDate=qe;et.prototype.visitTimestamp=qe;et.prototype.visitTime=qe;et.prototype.visitDecimal=qe;et.prototype.visitList=ra;et.prototype.visitStruct=ia;et.prototype.visitUnion=Bl;et.prototype.visitInterval=qe;et.prototype.visitDuration=qe;et.prototype.visitFixedSizeList=ra;et.prototype.visitMap=ra;var _i=class extends Li{static throughNode(t){throw new Error('"throughNode" not available in this environment')}static throughDOM(t,e){throw new Error('"throughDOM" not available in this environment')}constructor(t){super(),this._position=0,this._started=!1,this._sink=new Re,this._schema=null,this._dictionaryBlocks=[],this._recordBatchBlocks=[],this._dictionaryDeltaOffsets=new Map,Ft(t)||(t={autoDestroy:!0,writeLegacyIpcFormat:!1}),this._autoDestroy=typeof t.autoDestroy=="boolean"?t.autoDestroy:!0,this._writeLegacyIpcFormat=typeof t.writeLegacyIpcFormat=="boolean"?t.writeLegacyIpcFormat:!1}toString(t=!1){return this._sink.toString(t)}toUint8Array(t=!1){return this._sink.toUint8Array(t)}writeAll(t){return qt(t)?t.then(e=>this.writeAll(e)):Ut(t)?oa(this,t):na(this,t)}get closed(){return this._sink.closed}[Symbol.asyncIterator](){return this._sink[Symbol.asyncIterator]()}toDOMStream(t){return this._sink.toDOMStream(t)}toNodeStream(t){return this._sink.toNodeStream(t)}close(){return this.reset()._sink.close()}abort(t){return this.reset()._sink.abort(t)}finish(){return this._autoDestroy?this.close():this.reset(this._sink,this._schema),this}reset(t=this._sink,e=null){return t===this._sink||t instanceof Re?this._sink=t:(this._sink=new Re,t&&Ma(t)?this.toDOMStream({type:"bytes"}).pipeTo(t):t&&Ca(t)&&this.toNodeStream({objectMode:!1}).pipe(t)),this._started&&this._schema&&this._writeFooter(this._schema),this._started=!1,this._dictionaryBlocks=[],this._recordBatchBlocks=[],this._dictionaryDeltaOffsets=new Map,(!e||!Yi(e,this._schema))&&(e==null?(this._position=0,this._schema=null):(this._started=!0,this._schema=e,this._writeSchema(e))),this}write(t){let e=null;if(this._sink){if(t==null)return this.finish()&&void 0;if(t instanceof Mt&&!(e=t.schema))return this.finish()&&void 0;if(t instanceof tt&&!(e=t.schema))return this.finish()&&void 0}else throw new Error("RecordBatchWriter is closed");if(e&&!Yi(e,this._schema)){if(this._started&&this._autoDestroy)return this.close();this.reset(this._sink,e)}t instanceof tt?t instanceof xi||this._writeRecordBatch(t):t instanceof Mt?this.writeAll(t.batches):$t(t)&&this.writeAll(t)}_writeMessage(t,e=8){let r=e-1,n=Yt.encode(t),o=n.byteLength,s=this._writeLegacyIpcFormat?4:8,a=o+s+r&~r,c=a-o-s;return t.headerType===N.RecordBatch?this._recordBatchBlocks.push(new Je(a,t.bodyLength,this._position)):t.headerType===N.DictionaryBatch&&this._dictionaryBlocks.push(new Je(a,t.bodyLength,this._position)),this._writeLegacyIpcFormat||this._write(Int32Array.of(-1)),this._write(Int32Array.of(a-s)),o>0&&this._write(n),this._writePadding(c)}_write(t){if(this._started){let e=b(t);e&&e.byteLength>0&&(this._sink.write(e),this._position+=e.byteLength)}return this}_writeSchema(t){return this._writeMessage(Yt.from(t))}_writeFooter(t){return this._writeLegacyIpcFormat?this._write(Int32Array.of(0)):this._write(Int32Array.of(-1,0))}_writeMagic(){return this._write(nr)}_writePadding(t){return t>0?this._write(new Uint8Array(t)):this}_writeRecordBatch(t){let{byteLength:e,nodes:r,bufferRegions:n,buffers:o}=et.assemble(t),s=new wt(t.numRows,r,n),a=Yt.from(s,e);return this._writeDictionaries(t)._writeMessage(a)._writeBodyBuffers(o)}_writeDictionaryBatch(t,e,r=!1){this._dictionaryDeltaOffsets.set(e,t.length+(this._dictionaryDeltaOffsets.get(e)||0));let{byteLength:n,nodes:o,bufferRegions:s,buffers:a}=et.assemble(new W([t])),c=new wt(t.length,o,s),B=new mt(c,e,r),d=Yt.from(B,n);return this._writeMessage(d)._writeBodyBuffers(a)}_writeBodyBuffers(t){let e,r,n;for(let o=-1,s=t.length;++o<s;)(e=t[o])&&(r=e.byteLength)>0&&(this._write(e),(n=(r+7&-8)-r)>0&&this._writePadding(n));return this}_writeDictionaries(t){for(let[e,r]of t.dictionaries){let n=this._dictionaryDeltaOffsets.get(e)||0;if(n===0||(r=r?.slice(n)).length>0)for(let o of r.data)this._writeDictionaryBatch(o,e,n>0),n+=o.length}return this}},Gi=class i extends _i{static writeAll(t,e){let r=new i(e);return qt(t)?t.then(n=>r.writeAll(n)):Ut(t)?oa(r,t):na(r,t)}},Wi=class i extends _i{static writeAll(t){let e=new i;return qt(t)?t.then(r=>e.writeAll(r)):Ut(t)?oa(e,t):na(e,t)}constructor(){super(),this._autoDestroy=!0}_writeSchema(t){return this._writeMagic()._writePadding(2)}_writeFooter(t){let e=Ue.encode(new Ue(t,$.V5,this._recordBatchBlocks,this._dictionaryBlocks));return super._writeFooter(t)._write(e)._write(Int32Array.of(e.byteLength))._writeMagic()}};function na(i,t){let e=t;t instanceof Mt&&(e=t.batches,i.reset(void 0,t.schema));for(let r of e)i.write(r);return i.finish()}function oa(i,t){var e,r,n,o,s,a,c;return f(this,void 0,void 0,function*(){try{for(e=!0,r=kt(t);n=yield r.next(),o=n.done,!o;e=!0){c=n.value,e=!1;let B=c;i.write(B)}}catch(B){s={error:B}}finally{try{!e&&!o&&(a=r.return)&&(yield a.call(r))}finally{if(s)throw s.error}}return i.finish()})}function ou(i,t){if(Ut(i))return fl(i,t);if($t(i))return ll(i,t);throw new Error("toDOMStream() must be called with an Iterable or AsyncIterable")}function ll(i,t){let e=null,r=t?.type==="bytes"||!1,n=t?.highWaterMark||Math.pow(2,24);return new ReadableStream(Object.assign(Object.assign({},t),{start(s){o(s,e||(e=i[Symbol.iterator]()))},pull(s){e?o(s,e):s.close()},cancel(){(e?.return&&e.return()||!0)&&(e=null)}}),Object.assign({highWaterMark:r?n:void 0},t));function o(s,a){let c,B=null,d=s.desiredSize||null;for(;!(B=a.next(r?d:null)).done;)if(ArrayBuffer.isView(B.value)&&(c=b(B.value))&&(d!=null&&r&&(d=d-c.byteLength+1),B.value=c),s.enqueue(B.value),d!=null&&--d<=0)return;s.close()}}function fl(i,t){let e=null,r=t?.type==="bytes"||!1,n=t?.highWaterMark||Math.pow(2,24);return new ReadableStream(Object.assign(Object.assign({},t),{start(s){return f(this,void 0,void 0,function*(){yield o(s,e||(e=i[Symbol.asyncIterator]()))})},pull(s){return f(this,void 0,void 0,function*(){e?yield o(s,e):s.close()})},cancel(){return f(this,void 0,void 0,function*(){(e?.return&&(yield e.return())||!0)&&(e=null)})}}),Object.assign({highWaterMark:r?n:void 0},t));function o(s,a){return f(this,void 0,void 0,function*(){let c,B=null,d=s.desiredSize||null;for(;!(B=yield a.next(r?d:null)).done;)if(ArrayBuffer.isView(B.value)&&(c=b(B.value))&&(d!=null&&r&&(d=d-c.byteLength+1),B.value=c),s.enqueue(B.value),d!=null&&--d<=0)return;s.close()})}}function cu(i){return new sa(i)}var sa=class{constructor(t){this._numChunks=0,this._finished=!1,this._bufferedSize=0;let{["readableStrategy"]:e,["writableStrategy"]:r,["queueingStrategy"]:n="count"}=t,o=Ea(t,["readableStrategy","writableStrategy","queueingStrategy"]);this._controller=null,this._builder=Xi(o),this._getSize=n!=="bytes"?su:au;let{["highWaterMark"]:s=n==="bytes"?Math.pow(2,14):1e3}=Object.assign({},e),{["highWaterMark"]:a=n==="bytes"?Math.pow(2,14):1e3}=Object.assign({},r);this.readable=new ReadableStream({cancel:()=>{this._builder.clear()},pull:c=>{this._maybeFlush(this._builder,this._controller=c)},start:c=>{this._maybeFlush(this._builder,this._controller=c)}},{highWaterMark:s,size:n!=="bytes"?su:au}),this.writable=new WritableStream({abort:()=>{this._builder.clear()},write:()=>{this._maybeFlush(this._builder,this._controller)},close:()=>{this._maybeFlush(this._builder.finish(),this._controller)}},{highWaterMark:a,size:c=>this._writeValueAndReturnChunkSize(c)})}_writeValueAndReturnChunkSize(t){let e=this._bufferedSize;return this._bufferedSize=this._getSize(this._builder.append(t)),this._bufferedSize-e}_maybeFlush(t,e){e!=null&&(this._bufferedSize>=e.desiredSize&&++this._numChunks&&this._enqueue(e,t.toVector()),t.finished&&((t.length>0||this._numChunks===0)&&++this._numChunks&&this._enqueue(e,t.toVector()),!this._finished&&(this._finished=!0)&&this._enqueue(e,null)))}_enqueue(t,e){this._bufferedSize=0,this._controller=null,e==null?t.close():t.enqueue(e)}},su=i=>{var t;return(t=i?.length)!==null&&t!==void 0?t:0},au=i=>{var t;return(t=i?.byteLength)!==null&&t!==void 0?t:0};function ko(i,t){let e=new Re,r=null,n=new ReadableStream({cancel(){return f(this,void 0,void 0,function*(){yield e.close()})},start(a){return f(this,void 0,void 0,function*(){yield s(a,r||(r=yield o()))})},pull(a){return f(this,void 0,void 0,function*(){r?yield s(a,r):a.close()})}});return{writable:new WritableStream(e,Object.assign({highWaterMark:Math.pow(2,14)},i)),readable:n};function o(){return f(this,void 0,void 0,function*(){return yield(yield Ot.from(e)).open(t)})}function s(a,c){return f(this,void 0,void 0,function*(){let B=a.desiredSize,d=null;for(;!(d=yield c.next()).done;)if(a.enqueue(d.value),B!=null&&--B<=0)return;a.close()})}}function qo(i,t){let e=new this(i),r=new zt(e),n=new ReadableStream({cancel(){return f(this,void 0,void 0,function*(){yield r.cancel()})},pull(s){return f(this,void 0,void 0,function*(){yield o(s)})},start(s){return f(this,void 0,void 0,function*(){yield o(s)})}},Object.assign({highWaterMark:Math.pow(2,14)},t));return{writable:new WritableStream(e,i),readable:n};function o(s){return f(this,void 0,void 0,function*(){let a=null,c=s.desiredSize;for(;a=yield r.read(c||null);)if(s.enqueue(a),c!=null&&(c-=a.byteLength)<=0)return;s.close()})}}function $o(i,t="stream"){return(t==="stream"?Gi:Wi).writeAll(i).toUint8Array(!0)}var Ol=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},Os),Js),_s),Ds),ls),xs),ys),{compareSchemas:Yi,compareFields:Gc,compareTypes:Wc});ft.toDOMStream=ou;q.throughDOM=cu;Ot.throughDOM=ko;wi.throughDOM=ko;be.throughDOM=ko;_i.throughDOM=qo;Wi.throughDOM=qo;Gi.throughDOM=qo;var Dl=Object.create,Bu=Object.defineProperty,Fl=Object.getOwnPropertyDescriptor,Il=Object.getOwnPropertyNames,El=Object.getPrototypeOf,vl=Object.prototype.hasOwnProperty,Ml=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),Cl=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Il(t))!vl.call(i,n)&&n!==e&&Bu(i,n,{get:()=>t[n],enumerable:!(r=Fl(t,n))||r.enumerable});return i},Rl=(i,t,e)=>(e=i!=null?Dl(El(i)):{},Cl(t||!i||!i.__esModule?Bu(e,"default",{value:i,enumerable:!0}):e,i)),pl=Ml((i,t)=>{t.exports=Worker}),Ll=(i=>(i[i.UNDEFINED=0]="UNDEFINED",i[i.AUTOMATIC=1]="AUTOMATIC",i[i.READ_ONLY=2]="READ_ONLY",i[i.READ_WRITE=3]="READ_WRITE",i))(Ll||{}),bl=(i=>(i[i.IDENTIFIER=0]="IDENTIFIER",i[i.NUMERIC_CONSTANT=1]="NUMERIC_CONSTANT",i[i.STRING_CONSTANT=2]="STRING_CONSTANT",i[i.OPERATOR=3]="OPERATOR",i[i.KEYWORD=4]="KEYWORD",i[i.COMMENT=5]="COMMENT",i))(bl||{}),Xl=(i=>(i[i.NONE=0]="NONE",i[i.DEBUG=1]="DEBUG",i[i.INFO=2]="INFO",i[i.WARNING=3]="WARNING",i[i.ERROR=4]="ERROR",i))(Xl||{}),Hl=(i=>(i[i.NONE=0]="NONE",i[i.CONNECT=1]="CONNECT",i[i.DISCONNECT=2]="DISCONNECT",i[i.OPEN=3]="OPEN",i[i.QUERY=4]="QUERY",i[i.INSTANTIATE=5]="INSTANTIATE",i))(Hl||{}),ml=(i=>(i[i.NONE=0]="NONE",i[i.OK=1]="OK",i[i.ERROR=2]="ERROR",i[i.START=3]="START",i[i.RUN=4]="RUN",i[i.CAPTURE=5]="CAPTURE",i))(ml||{}),Yl=(i=>(i[i.NONE=0]="NONE",i[i.WEB_WORKER=1]="WEB_WORKER",i[i.NODE_WORKER=2]="NODE_WORKER",i[i.BINDINGS=3]="BINDINGS",i[i.ASYNC_DUCKDB=4]="ASYNC_DUCKDB",i))(Yl||{});var du=class{constructor(i=2){this.level=i}log(i){i.level>=this.level&&console.log(i)}};var xl=(i=>(i[i.SUCCESS=0]="SUCCESS",i))(xl||{}),_l=class{constructor(i,t){this._bindings=i,this._conn=t}get bindings(){return this._bindings}async close(){return this._bindings.disconnect(this._conn)}useUnsafe(i){return i(this._bindings,this._conn)}async query(i){this._bindings.logger.log({timestamp:new Date,level:2,origin:4,topic:4,event:4,value:i});let t=await this._bindings.runQuery(this._conn,i),e=Ot.from(t);return console.assert(e.isSync(),"Reader is not sync"),console.assert(e.isFile(),"Reader is not file"),new Mt(e)}async send(i){this._bindings.logger.log({timestamp:new Date,level:2,origin:4,topic:4,event:4,value:i});let t=await this._bindings.startPendingQuery(this._conn,i);for(;t==null;)t=await this._bindings.pollPendingQuery(this._conn);let e=new lu(this._bindings,this._conn,t),r=await Ot.from(e);return console.assert(r.isAsync()),console.assert(r.isStream()),r}async cancelSent(){return await this._bindings.cancelPendingQuery(this._conn)}async getTableNames(i){return await this._bindings.getTableNames(this._conn,i)}async prepare(i){let t=await this._bindings.createPrepared(this._conn,i);return new Gl(this._bindings,this._conn,t)}async insertArrowTable(i,t){let e=$o(i,"stream");await this.insertArrowFromIPCStream(e,t)}async insertArrowFromIPCStream(i,t){await this._bindings.insertArrowFromIPCStream(this._conn,i,t)}async insertCSVFromPath(i,t){await this._bindings.insertCSVFromPath(this._conn,i,t)}async insertJSONFromPath(i,t){await this._bindings.insertJSONFromPath(this._conn,i,t)}},lu=class{constructor(i,t,e){this.db=i,this.conn=t,this.header=e,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 i;return this._inFlight!=null?(i=await this._inFlight,this._inFlight=null):i=await this.db.fetchQueryResults(this.conn),this._depleted=i.length==0,this._depleted||(this._inFlight=this.db.fetchQueryResults(this.conn)),{done:this._depleted,value:i}}[Symbol.asyncIterator](){return this}},Gl=class{constructor(i,t,e){this.bindings=i,this.connectionId=t,this.statementId=e}async close(){await this.bindings.closePrepared(this.connectionId,this.statementId)}async query(...i){let t=await this.bindings.runPrepared(this.connectionId,this.statementId,i),e=Ot.from(t);return console.assert(e.isSync()),console.assert(e.isFile()),new Mt(e)}async send(...i){let t=await this.bindings.sendPrepared(this.connectionId,this.statementId,i),e=new lu(this.bindings,this.connectionId,t),r=await Ot.from(e);return console.assert(r.isAsync()),console.assert(r.isStream()),r}},Wl=(i=>(i.CANCEL_PENDING_QUERY="CANCEL_PENDING_QUERY",i.CLOSE_PREPARED="CLOSE_PREPARED",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.CREATE_PREPARED="CREATE_PREPARED",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_TABLE_NAMES="GET_TABLE_NAMES",i.GET_VERSION="GET_VERSION",i.GLOB_FILE_INFOS="GLOB_FILE_INFOS",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.POLL_PENDING_QUERY="POLL_PENDING_QUERY",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_PREPARED="RUN_PREPARED",i.RUN_QUERY="RUN_QUERY",i.SEND_PREPARED="SEND_PREPARED",i.START_PENDING_QUERY="START_PENDING_QUERY",i.TOKENIZE="TOKENIZE",i))(Wl||{}),gl=(i=>(i.CONNECTION_INFO="CONNECTION_INFO",i.ERROR="ERROR",i.FEATURE_FLAGS="FEATURE_FLAGS",i.FILE_BUFFER="FILE_BUFFER",i.FILE_INFOS="FILE_INFOS",i.FILE_SIZE="FILE_SIZE",i.FILE_STATISTICS="FILE_STATISTICS",i.INSTANTIATE_PROGRESS="INSTANTIATE_PROGRESS",i.LOG="LOG",i.OK="OK",i.PREPARED_STATEMENT_ID="PREPARED_STATEMENT_ID",i.QUERY_PLAN="QUERY_PLAN",i.QUERY_RESULT="QUERY_RESULT",i.QUERY_RESULT_CHUNK="QUERY_RESULT_CHUNK",i.QUERY_RESULT_HEADER="QUERY_RESULT_HEADER",i.QUERY_RESULT_HEADER_OR_NULL="QUERY_RESULT_HEADER_OR_NULL",i.REGISTERED_FILE="REGISTERED_FILE",i.SCRIPT_TOKENS="SCRIPT_TOKENS",i.SUCCESS="SUCCESS",i.TABLE_NAMES="TABLE_NAMES",i.VERSION_STRING="VERSION_STRING",i))(gl||{}),T=class{constructor(i,t){this.promiseResolver=()=>{},this.promiseRejecter=()=>{},this.type=i,this.data=t,this.promise=new Promise((e,r)=>{this.promiseResolver=e,this.promiseRejecter=r})}};function Ao(i){switch(i.typeId){case u.Binary:return{sqlType:"binary"};case u.Bool:return{sqlType:"bool"};case u.Date:return{sqlType:"date"};case u.DateDay:return{sqlType:"date32[d]"};case u.DateMillisecond:return{sqlType:"date64[ms]"};case u.Decimal:{let t=i;return{sqlType:"decimal",precision:t.precision,scale:t.scale}}case u.Float:return{sqlType:"float"};case u.Float16:return{sqlType:"float16"};case u.Float32:return{sqlType:"float32"};case u.Float64:return{sqlType:"float64"};case u.Int:return{sqlType:"int32"};case u.Int16:return{sqlType:"int16"};case u.Int32:return{sqlType:"int32"};case u.Int64:return{sqlType:"int64"};case u.Uint16:return{sqlType:"uint16"};case u.Uint32:return{sqlType:"uint32"};case u.Uint64:return{sqlType:"uint64"};case u.Uint8:return{sqlType:"uint8"};case u.IntervalDayTime:return{sqlType:"interval[dt]"};case u.IntervalYearMonth:return{sqlType:"interval[m]"};case u.List:return{sqlType:"list",valueType:Ao(i.valueType)};case u.FixedSizeBinary:return{sqlType:"fixedsizebinary",byteWidth:i.byteWidth};case u.Null:return{sqlType:"null"};case u.Utf8:return{sqlType:"utf8"};case u.Struct:return{sqlType:"struct",fields:i.children.map(t=>aa(t.name,t.type))};case u.Map:{let t=i;return{sqlType:"map",keyType:Ao(t.keyType),valueType:Ao(t.valueType)}}case u.Time:return{sqlType:"time[s]"};case u.TimeMicrosecond:return{sqlType:"time[us]"};case u.TimeMillisecond:return{sqlType:"time[ms]"};case u.TimeNanosecond:return{sqlType:"time[ns]"};case u.TimeSecond:return{sqlType:"time[s]"};case u.Timestamp:return{sqlType:"timestamp",timezone:i.timezone||void 0};case u.TimestampSecond:return{sqlType:"timestamp[s]",timezone:i.timezone||void 0};case u.TimestampMicrosecond:return{sqlType:"timestamp[us]",timezone:i.timezone||void 0};case u.TimestampNanosecond:return{sqlType:"timestamp[ns]",timezone:i.timezone||void 0};case u.TimestampMillisecond:return{sqlType:"timestamp[ms]",timezone:i.timezone||void 0}}throw new Error("unsupported arrow type: ".concat(i.toString()))}function aa(i,t){let e=Ao(t);return e.name=i,e}var Nl=new TextEncoder,fu=class{constructor(i,t=null){this._onInstantiationProgress=[],this._worker=null,this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{},this._nextMessageId=0,this._pendingRequests=new Map,this._logger=i,this._onMessageHandler=this.onMessage.bind(this),this._onErrorHandler=this.onError.bind(this),this._onCloseHandler=this.onClose.bind(this),t!=null&&this.attach(t)}get logger(){return this._logger}attach(i){this._worker=i,this._worker.addEventListener("message",this._onMessageHandler),this._worker.addEventListener("error",this._onErrorHandler),this._worker.addEventListener("close",this._onCloseHandler),this._workerShutdownPromise=new Promise((t,e)=>{this._workerShutdownResolver=t})}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(i,t=[]){if(!this._worker){console.error("cannot send a message since the worker is not set!");return}let e=this._nextMessageId++;return this._pendingRequests.set(e,i),this._worker.postMessage({messageId:e,type:i.type,data:i.data},t),await i.promise}onMessage(i){var t;let e=i.data;switch(e.type){case"LOG":{this._logger.log(e.data);return}case"INSTANTIATE_PROGRESS":{for(let n of this._onInstantiationProgress)n(e.data);return}}let r=this._pendingRequests.get(e.requestId);if(!r){console.warn("unassociated response: [".concat(e.requestId,", ").concat(e.type.toString(),"]"));return}if(this._pendingRequests.delete(e.requestId),e.type=="ERROR"){let n=new Error(e.data.message);n.name=e.data.name,(t=Object.getOwnPropertyDescriptor(n,"stack"))!=null&&t.writable&&(n.stack=e.data.stack),r.promiseRejecter(n);return}switch(r.type){case"CLOSE_PREPARED":case"COLLECT_FILE_STATISTICS":case"COPY_FILE_TO_PATH":case"DISCONNECT":case"DROP_FILE":case"DROP_FILES":case"FLUSH_FILES":case"INSERT_ARROW_FROM_IPC_STREAM":case"IMPORT_CSV_FROM_PATH":case"IMPORT_JSON_FROM_PATH":case"OPEN":case"PING":case"REGISTER_FILE_BUFFER":case"REGISTER_FILE_HANDLE":case"REGISTER_FILE_URL":case"RESET":if(e.type=="OK"){r.promiseResolver(e.data);return}break;case"INSTANTIATE":if(this._onInstantiationProgress=[],e.type=="OK"){r.promiseResolver(e.data);return}break;case"GLOB_FILE_INFOS":if(e.type=="FILE_INFOS"){r.promiseResolver(e.data);return}break;case"GET_VERSION":if(e.type=="VERSION_STRING"){r.promiseResolver(e.data);return}break;case"GET_FEATURE_FLAGS":if(e.type=="FEATURE_FLAGS"){r.promiseResolver(e.data);return}break;case"GET_TABLE_NAMES":if(e.type=="TABLE_NAMES"){r.promiseResolver(e.data);return}break;case"TOKENIZE":if(e.type=="SCRIPT_TOKENS"){r.promiseResolver(e.data);return}break;case"COPY_FILE_TO_BUFFER":if(e.type=="FILE_BUFFER"){r.promiseResolver(e.data);return}break;case"EXPORT_FILE_STATISTICS":if(e.type=="FILE_STATISTICS"){r.promiseResolver(e.data);return}break;case"CONNECT":if(e.type=="CONNECTION_INFO"){r.promiseResolver(e.data);return}break;case"RUN_PREPARED":case"RUN_QUERY":if(e.type=="QUERY_RESULT"){r.promiseResolver(e.data);return}break;case"SEND_PREPARED":if(e.type=="QUERY_RESULT_HEADER"){r.promiseResolver(e.data);return}break;case"START_PENDING_QUERY":if(e.type=="QUERY_RESULT_HEADER_OR_NULL"){r.promiseResolver(e.data);return}break;case"POLL_PENDING_QUERY":if(e.type=="QUERY_RESULT_HEADER_OR_NULL"){r.promiseResolver(e.data);return}break;case"CANCEL_PENDING_QUERY":if(this._onInstantiationProgress=[],e.type=="SUCCESS"){r.promiseResolver(e.data);return}break;case"FETCH_QUERY_RESULTS":if(e.type=="QUERY_RESULT_CHUNK"){r.promiseResolver(e.data);return}break;case"CREATE_PREPARED":if(e.type=="PREPARED_STATEMENT_ID"){r.promiseResolver(e.data);return}break}r.promiseRejecter(new Error("unexpected response type: ".concat(e.type.toString())))}onError(i){console.error(i),console.error("error in duckdb worker: ".concat(i.message)),this._pendingRequests.clear()}onClose(){if(this._workerShutdownResolver(null),this._pendingRequests.size!=0){console.warn("worker terminated with ".concat(this._pendingRequests.size," pending requests"));return}this._pendingRequests.clear()}async reset(){let i=new T("RESET",null);return await this.postTask(i)}async ping(){let i=new T("PING",null);await this.postTask(i)}async dropFile(i){let t=new T("DROP_FILE",i);return await this.postTask(t)}async dropFiles(){let i=new T("DROP_FILES",null);return await this.postTask(i)}async flushFiles(){let i=new T("FLUSH_FILES",null);return await this.postTask(i)}async instantiate(i,t=null,e=r=>{}){this._onInstantiationProgress.push(e);let r=new T("INSTANTIATE",[i,t]);return await this.postTask(r)}async getVersion(){let i=new T("GET_VERSION",null);return await this.postTask(i)}async getFeatureFlags(){let i=new T("GET_FEATURE_FLAGS",null);return await this.postTask(i)}async open(i){let t=new T("OPEN",i);await this.postTask(t)}async tokenize(i){let t=new T("TOKENIZE",i);return await this.postTask(t)}async connectInternal(){let i=new T("CONNECT",null);return await this.postTask(i)}async connect(){let i=await this.connectInternal();return new _l(this,i)}async disconnect(i){let t=new T("DISCONNECT",i);await this.postTask(t)}async runQuery(i,t){let e=new T("RUN_QUERY",[i,t]);return await this.postTask(e)}async startPendingQuery(i,t){let e=new T("START_PENDING_QUERY",[i,t]);return await this.postTask(e)}async pollPendingQuery(i){let t=new T("POLL_PENDING_QUERY",i);return await this.postTask(t)}async cancelPendingQuery(i){let t=new T("CANCEL_PENDING_QUERY",i);return await this.postTask(t)}async fetchQueryResults(i){let t=new T("FETCH_QUERY_RESULTS",i);return await this.postTask(t)}async getTableNames(i,t){let e=new T("GET_TABLE_NAMES",[i,t]);return await this.postTask(e)}async createPrepared(i,t){let e=new T("CREATE_PREPARED",[i,t]);return await this.postTask(e)}async closePrepared(i,t){let e=new T("CLOSE_PREPARED",[i,t]);await this.postTask(e)}async runPrepared(i,t,e){let r=new T("RUN_PREPARED",[i,t,e]);return await this.postTask(r)}async sendPrepared(i,t,e){let r=new T("SEND_PREPARED",[i,t,e]);return await this.postTask(r)}async globFiles(i){let t=new T("GLOB_FILE_INFOS",i);return await this.postTask(t)}async registerFileText(i,t){let e=Nl.encode(t);await this.registerFileBuffer(i,e)}async registerFileURL(i,t,e,r){t===void 0&&(t=i);let n=new T("REGISTER_FILE_URL",[i,t,e,r]);await this.postTask(n)}async registerEmptyFileBuffer(i){let t=new T("REGISTER_FILE_BUFFER",[i,new Uint8Array]);await this.postTask(t)}async registerFileBuffer(i,t){let e=new T("REGISTER_FILE_BUFFER",[i,t]);await this.postTask(e,[t.buffer])}async registerFileHandle(i,t,e,r){let n=new T("REGISTER_FILE_HANDLE",[i,t,e,r]);await this.postTask(n,[])}async collectFileStatistics(i,t){let e=new T("COLLECT_FILE_STATISTICS",[i,t]);await this.postTask(e,[])}async exportFileStatistics(i){let t=new T("EXPORT_FILE_STATISTICS",i);return await this.postTask(t,[])}async copyFileToBuffer(i){let t=new T("COPY_FILE_TO_BUFFER",i);return await this.postTask(t)}async copyFileToPath(i,t){let e=new T("COPY_FILE_TO_PATH",[i,t]);await this.postTask(e)}async insertArrowFromIPCStream(i,t,e){if(t.length==0)return;let r=new T("INSERT_ARROW_FROM_IPC_STREAM",[i,t,e]);await this.postTask(r,[t.buffer])}async insertCSVFromPath(i,t,e){if(e.columns!==void 0){let n=[];for(let o in e.columns){let s=e.columns[o];n.push(aa(o,s))}e.columnsFlat=n,delete e.columns}let r=new T("IMPORT_CSV_FROM_PATH",[i,t,e]);await this.postTask(r)}async insertJSONFromPath(i,t,e){if(e.columns!==void 0){let n=[];for(let o in e.columns){let s=e.columns[o];n.push(aa(o,s))}e.columnsFlat=n,delete e.columns}let r=new T("IMPORT_JSON_FROM_PATH",[i,t,e]);await this.postTask(r)}};var ca={name:"@duckdb/duckdb-wasm",version:"1.28.1-dev106.0",description:"DuckDB powered by WebAssembly",license:"MIT",repository:{type:"git",url:"https://github.com/duckdb/duckdb-wasm.git"},keywords:["sql","duckdb","relational","database","data","query","wasm","analytics","olap","arrow","parquet","json","csv"],dependencies:{"apache-arrow":"^14.0.1"},devDependencies:{"@types/emscripten":"^1.39.10","@types/jasmine":"^5.1.4","@typescript-eslint/eslint-plugin":"^6.18.0","@typescript-eslint/parser":"^6.18.0",esbuild:"^0.20.0",eslint:"^8.56.0","eslint-plugin-jasmine":"^4.1.3","eslint-plugin-react":"^7.33.2","fast-glob":"^3.3.2",jasmine:"^5.1.0","jasmine-core":"^5.1.1","jasmine-spec-reporter":"^7.0.0","js-sha256":"^0.11.0",karma:"^6.4.2","karma-chrome-launcher":"^3.2.0","karma-coverage":"^2.2.1","karma-firefox-launcher":"^2.1.2","karma-jasmine":"^5.1.0","karma-jasmine-html-reporter":"^2.1.0","karma-sourcemap-loader":"^0.4.0","karma-spec-reporter":"^0.0.36","make-dir":"^4.0.0",nyc:"^15.1.0",prettier:"^3.2.4",puppeteer:"^21.7.0",rimraf:"^5.0.5",s3rver:"^3.7.1",typedoc:"^0.25.7",typescript:"^5.3.3","wasm-feature-detect":"^1.6.1","web-worker":"^1.2.0"},scripts:{"build:debug":"node bundle.mjs debug && tsc --emitDeclarationOnly","build:release":"node bundle.mjs release && tsc --emitDeclarationOnly",docs:"typedoc",report:"node ./coverage.mjs","test:node":"node --enable-source-maps ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs","test:node:debug":"node --inspect-brk --enable-source-maps ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs","test:node:coverage":"nyc -r json --report-dir ./coverage/node node ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs","test:firefox":"karma start ./karma/tests-firefox.cjs","test:chrome":"karma start ./karma/tests-chrome.cjs","test:chrome:eh":"karma start ./karma/tests-chrome-eh.cjs","test:chrome:coverage":"karma start ./karma/tests-chrome-coverage.cjs","test:browser":"karma start ./karma/tests-all.cjs","test:browser:debug":"karma start ./karma/tests-debug.cjs",test:"npm run test:chrome && npm run test:node","test:coverage":"npm run test:chrome:coverage && npm run test:node:coverage && npm run report",lint:"eslint src test"},files:["dist","!dist/types/test"],main:"dist/duckdb-browser.cjs",module:"dist/duckdb-browser.mjs",types:"dist/duckdb-browser.d.ts",jsdelivr:"dist/duckdb-browser.cjs",unpkg:"dist/duckdb-browser.mjs",sideEffects:!1,browser:{fs:!1,path:!1,perf_hooks:!1,os:!1,worker_threads:!1},exports:{"./dist/duckdb-mvp.wasm":"./dist/duckdb-mvp.wasm","./dist/duckdb-eh.wasm":"./dist/duckdb-eh.wasm","./dist/duckdb-coi.wasm":"./dist/duckdb-coi.wasm","./dist/duckdb-browser":"./dist/duckdb-browser.mjs","./dist/duckdb-browser.cjs":"./dist/duckdb-browser.cjs","./dist/duckdb-browser.mjs":"./dist/duckdb-browser.mjs","./dist/duckdb-browser-blocking":"./dist/duckdb-browser-blocking.mjs","./dist/duckdb-browser-blocking.mjs":"./dist/duckdb-browser-blocking.mjs","./dist/duckdb-browser-blocking.cjs":"./dist/duckdb-browser-blocking.cjs","./dist/duckdb-browser-coi.pthread.worker.js":"./dist/duckdb-browser-coi.pthread.worker.js","./dist/duckdb-browser-coi.worker.js":"./dist/duckdb-browser-coi.worker.js","./dist/duckdb-browser-eh.worker.js":"./dist/duckdb-browser-eh.worker.js","./dist/duckdb-browser-mvp.worker.js":"./dist/duckdb-browser-mvp.worker.js","./dist/duckdb-node":"./dist/duckdb-node.cjs","./dist/duckdb-node.cjs":"./dist/duckdb-node.cjs","./dist/duckdb-node-blocking":"./dist/duckdb-node-blocking.cjs","./dist/duckdb-node-blocking.cjs":"./dist/duckdb-node-blocking.cjs","./dist/duckdb-node-eh.worker.cjs":"./dist/duckdb-node-eh.worker.cjs","./dist/duckdb-node-mvp.worker.cjs":"./dist/duckdb-node-mvp.worker.cjs","./blocking":{browser:{types:"./dist/duckdb-browser-blocking.d.ts",import:"./dist/duckdb-browser-blocking.mjs",require:"./dist/duckdb-browser-blocking.cjs"},node:{types:"./dist/duckdb-node-blocking.d.ts",require:"./dist/duckdb-node-blocking.cjs",import:"./dist/duckdb-node-blocking.cjs"},types:"./dist/duckdb-browser-blocking.d.ts",import:"./dist/duckdb-browser-blocking.mjs",require:"./dist/duckdb-browser-blocking.cjs"},".":{browser:{types:"./dist/duckdb-browser.d.ts",import:"./dist/duckdb-browser.mjs",require:"./dist/duckdb-browser.cjs"},node:{types:"./dist/duckdb-node.d.ts",import:"./dist/duckdb-node.cjs",require:"./dist/duckdb-node.cjs"},types:"./dist/duckdb-browser.d.ts",import:"./dist/duckdb-browser.mjs",require:"./dist/duckdb-browser.cjs"}}},iv=ca.name,rv=ca.version,ua=ca.version.split("."),nv=ua[0],ov=ua[1],sv=ua[2];var av=Rl(pl());function Tl(){let i=new TextDecoder;return t=>(typeof SharedArrayBuffer<"u"&&t.buffer instanceof SharedArrayBuffer&&(t=new Uint8Array(t)),i.decode(t))}var cv=Tl(),Zl=(i=>(i[i.BUFFER=0]="BUFFER",i[i.NODE_FS=1]="NODE_FS",i[i.BROWSER_FILEREADER=2]="BROWSER_FILEREADER",i[i.BROWSER_FSACCESS=3]="BROWSER_FSACCESS",i[i.HTTP=4]="HTTP",i[i.S3=5]="S3",i))(Zl||{});var hu=class i{constructor(t,e){this._version=e;this.db=t}db;static load(){let t=URL.createObjectURL(new Blob([Fa()],{type:"text/javascript"})),e=new Worker(t);URL.revokeObjectURL(t);let r=new du,n=new fu(r,e),o=URL.createObjectURL(new Blob([Da()],{type:"application/wasm"}));return n.instantiate(o,null).then(async()=>(URL.revokeObjectURL(o),new i(n,await n.getVersion())))}static unload(){}version(){return this._version}};export{hu as DuckDB};
11
- //# sourceMappingURL=duckdb.js.map
@@ -8,4 +8,3 @@ return true;`)}function bd(e){return typeof e!="bigint"?te(e):`${te(e)}n`}var Ts
8
8
  ${this.toArray().join(`,
9
9
  `)}
10
10
  ]`}concat(...t){let i=this.schema,r=this.data.concat(t.flatMap(({data:n})=>n));return new e(i,r.map(n=>new tt(i,n)))}slice(t,i){let r=this.schema;[t,i]=Fr({length:this.numRows},t,i);let n=uo(this.data,this._offsets,t,i);return new e(r,n.map(o=>new tt(r,o)))}getChild(t){return this.getChildAt(this.schema.fields.findIndex(i=>i.name===t))}getChildAt(t){if(t>-1&&t<this.schema.fields.length){let i=this.data.map(r=>r.children[t]);if(i.length===0){let{type:r}=this.schema.fields[t],n=X({type:r,length:0,nullCount:0});i.push(n._changeLengthAndBackfillNullBitmap(this.numRows))}return new W(i)}return null}setChild(t,i){var r;return this.setChildAt((r=this.schema.fields)===null||r===void 0?void 0:r.findIndex(n=>n.name===t),i)}setChildAt(t,i){let r=this.schema,n=[...this.batches];if(t>-1&&t<this.numCols){i||(i=new W([X({type:new Et,length:this.numRows})]));let o=r.fields.slice(),s=o[t].clone({type:i.type}),a=this.schema.fields.map((c,B)=>this.getChildAt(B));[o[t],a[t]]=[s,i],[r,n]=So(r,a)}return new e(r,n)}select(t){let i=this.schema.fields.reduce((r,n,o)=>r.set(n.name,o),new Map);return this.selectAt(t.map(r=>i.get(r)).filter(r=>r>-1))}selectAt(t){let i=this.schema.selectAt(t),r=this.batches.map(n=>n.selectAt(t));return new e(i,r)}assign(t){let i=this.schema.fields,[r,n]=t.schema.fields.reduce((a,c,B)=>{let[d,l]=a,D=i.findIndex(y=>y.name===c.name);return~D?l[D]=B:d.push(B),a},[[],[]]),o=this.schema.assign(t.schema),s=[...i.map((a,c)=>[c,n[c]]).map(([a,c])=>c===void 0?this.getChildAt(a):t.getChildAt(c)),...r.map(a=>t.getChildAt(a))].filter(Boolean);return new e(...So(o,s))}};Tc=Symbol.toStringTag;Mt[Tc]=(e=>(e.schema=null,e.batches=[],e._offsets=new Uint32Array([0]),e._nullCount=-1,e[Symbol.isConcatSpreadable]=!0,e.isValid=ni(vr),e.get=ni(ot.getVisitFn(u.Struct)),e.set=Bo(yt.getVisitFn(u.Struct)),e.indexOf=lo(Ci.getVisitFn(u.Struct)),e.getByteLength=ni(gt.getVisitFn(u.Struct)),"Table"))(Mt.prototype);var Sc,tt=class e{constructor(...t){switch(t.length){case 2:{if([this.schema]=t,!(this.schema instanceof S))throw new TypeError("RecordBatch constructor expects a [Schema, Data] pair.");if([,this.data=X({nullCount:0,type:new Q(this.schema.fields),children:this.schema.fields.map(i=>X({type:i.type,nullCount:0}))})]=t,!(this.data instanceof U))throw new TypeError("RecordBatch constructor expects a [Schema, Data] pair.");[this.schema,this.data]=Zc(this.schema,this.data.children);break}case 1:{let[i]=t,{fields:r,children:n,length:o}=Object.keys(i).reduce((c,B,d)=>(c.children[d]=i[B],c.length=Math.max(c.length,i[B].length),c.fields[d]=_.new({name:B,type:i[B].type,nullable:!0}),c),{length:0,fields:new Array,children:new Array}),s=new S(r),a=X({type:new Q(r),length:o,children:n,nullCount:0});[this.schema,this.data]=Zc(s,a.children,o);break}default:throw new TypeError("RecordBatch constructor expects an Object mapping names to child Data, or a [Schema, Data] pair.")}}get dictionaries(){return this._dictionaries||(this._dictionaries=Uc(this.schema.fields,this.data.children))}get numCols(){return this.schema.fields.length}get numRows(){return this.data.length}get nullCount(){return this.data.nullCount}isValid(t){return this.data.getValid(t)}get(t){return ot.visit(this.data,t)}set(t,i){return yt.visit(this.data,t,i)}indexOf(t,i){return Ci.visit(this.data,t,i)}getByteLength(t){return gt.visit(this.data,t)}[Symbol.iterator](){return zi.visit(new W([this.data]))}toArray(){return[...this]}concat(...t){return new Mt(this.schema,[this,...t])}slice(t,i){let[r]=new W([this.data]).slice(t,i).data;return new e(this.schema,r)}getChild(t){var i;return this.getChildAt((i=this.schema.fields)===null||i===void 0?void 0:i.findIndex(r=>r.name===t))}getChildAt(t){return t>-1&&t<this.schema.fields.length?new W([this.data.children[t]]):null}setChild(t,i){var r;return this.setChildAt((r=this.schema.fields)===null||r===void 0?void 0:r.findIndex(n=>n.name===t),i)}setChildAt(t,i){let r=this.schema,n=this.data;if(t>-1&&t<this.numCols){i||(i=new W([X({type:new Et,length:this.numRows})]));let o=r.fields.slice(),s=n.children.slice(),a=o[t].clone({type:i.type});[o[t],s[t]]=[a,i.data[0]],r=new S(o,new Map(this.schema.metadata)),n=X({type:new Q(o),children:s})}return new e(r,n)}select(t){let i=this.schema.select(t),r=new Q(i.fields),n=[];for(let o of t){let s=this.schema.fields.findIndex(a=>a.name===o);~s&&(n[s]=this.data.children[s])}return new e(i,X({type:r,length:this.numRows,children:n}))}selectAt(t){let i=this.schema.selectAt(t),r=t.map(o=>this.data.children[o]).filter(Boolean),n=X({type:new Q(i.fields),length:this.numRows,children:r});return new e(i,n)}};Sc=Symbol.toStringTag;tt[Sc]=(e=>(e._nullCount=-1,e[Symbol.isConcatSpreadable]=!0,"RecordBatch"))(tt.prototype);function Zc(e,t,i=t.reduce((r,n)=>Math.max(r,n.length),0)){var r;let n=[...e.fields],o=[...t],s=(i+63&-64)>>3;for(let[a,c]of e.fields.entries()){let B=t[a];(!B||B.length!==i)&&(n[a]=c.clone({nullable:!0}),o[a]=(r=B?._changeLengthAndBackfillNullBitmap(i))!==null&&r!==void 0?r:X({type:c.type,length:i,nullCount:i,nullBitmap:new Uint8Array(s)}))}return[e.assign(n),X({type:new Q(n),length:i,children:o})]}function Uc(e,t,i=new Map){var r,n;if(((r=e?.length)!==null&&r!==void 0?r:0)>0&&e?.length===t?.length)for(let o=-1,s=e.length;++o<s;){let{type:a}=e[o],c=t[o];for(let B of[c,...((n=c?.dictionary)===null||n===void 0?void 0:n.data)||[]])Uc(a.children,B?.children,i);if(h.isDictionary(a)){let{id:B}=a;if(!i.has(B))c?.dictionary&&i.set(B,c.dictionary);else if(i.get(B)!==c.dictionary)throw new Error("Cannot create Schema containing two different dictionaries with the same Id")}}return i}var xi=class extends tt{constructor(t){let i=t.fields.map(n=>X({type:n.type})),r=X({type:new Q(t.fields),nullCount:0,children:i});super(t,r)}};var Bn;(function(e){e[e.BUFFER=0]="BUFFER"})(Bn||(Bn={}));var dn;(function(e){e[e.LZ4_FRAME=0]="LZ4_FRAME",e[e.ZSTD=1]="ZSTD"})(dn||(dn={}));var Uo=class e{constructor(){this.bb=null,this.bb_pos=0}__init(t,i){return this.bb_pos=t,this.bb=i,this}static getRootAsBodyCompression(t,i){return(i||new e).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsBodyCompression(t,i){return t.setPosition(t.position()+4),(i||new e).__init(t.readInt32(t.position())+t.position(),t)}codec(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readInt8(this.bb_pos+t):dn.LZ4_FRAME}method(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readInt8(this.bb_pos+t):Bn.BUFFER}static startBodyCompression(t){t.startObject(2)}static addCodec(t,i){t.addFieldInt8(0,i,dn.LZ4_FRAME)}static addMethod(t,i){t.addFieldInt8(1,i,Bn.BUFFER)}static endBodyCompression(t){return t.endObject()}static createBodyCompression(t,i,r){return e.startBodyCompression(t),e.addCodec(t,i),e.addMethod(t,r),e.endBodyCompression(t)}};var tr=class{constructor(){this.bb=null,this.bb_pos=0}__init(t,i){return this.bb_pos=t,this.bb=i,this}offset(){return this.bb.readInt64(this.bb_pos)}length(){return this.bb.readInt64(this.bb_pos+8)}static sizeOf(){return 16}static createBuffer(t,i,r){return t.prep(8,16),t.writeInt64(BigInt(r??0)),t.writeInt64(BigInt(i??0)),t.offset()}};var er=class{constructor(){this.bb=null,this.bb_pos=0}__init(t,i){return this.bb_pos=t,this.bb=i,this}length(){return this.bb.readInt64(this.bb_pos)}nullCount(){return this.bb.readInt64(this.bb_pos+8)}static sizeOf(){return 16}static createFieldNode(t,i,r){return t.prep(8,16),t.writeInt64(BigInt(r??0)),t.writeInt64(BigInt(i??0)),t.offset()}};var Zt=class e{constructor(){this.bb=null,this.bb_pos=0}__init(t,i){return this.bb_pos=t,this.bb=i,this}static getRootAsRecordBatch(t,i){return(i||new e).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsRecordBatch(t,i){return t.setPosition(t.position()+4),(i||new e).__init(t.readInt32(t.position())+t.position(),t)}length(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readInt64(this.bb_pos+t):BigInt("0")}nodes(t,i){let r=this.bb.__offset(this.bb_pos,6);return r?(i||new er).__init(this.bb.__vector(this.bb_pos+r)+t*16,this.bb):null}nodesLength(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}buffers(t,i){let r=this.bb.__offset(this.bb_pos,8);return r?(i||new tr).__init(this.bb.__vector(this.bb_pos+r)+t*16,this.bb):null}buffersLength(){let t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}compression(t){let i=this.bb.__offset(this.bb_pos,10);return i?(t||new Uo).__init(this.bb.__indirect(this.bb_pos+i),this.bb):null}static startRecordBatch(t){t.startObject(4)}static addLength(t,i){t.addFieldInt64(0,i,BigInt("0"))}static addNodes(t,i){t.addFieldOffset(1,i,0)}static startNodesVector(t,i){t.startVector(16,i,8)}static addBuffers(t,i){t.addFieldOffset(2,i,0)}static startBuffersVector(t,i){t.startVector(16,i,8)}static addCompression(t,i){t.addFieldOffset(3,i,0)}static endRecordBatch(t){return t.endObject()}};var ke=class e{constructor(){this.bb=null,this.bb_pos=0}__init(t,i){return this.bb_pos=t,this.bb=i,this}static getRootAsDictionaryBatch(t,i){return(i||new e).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsDictionaryBatch(t,i){return t.setPosition(t.position()+4),(i||new e).__init(t.readInt32(t.position())+t.position(),t)}id(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readInt64(this.bb_pos+t):BigInt("0")}data(t){let i=this.bb.__offset(this.bb_pos,6);return i?(t||new Zt).__init(this.bb.__indirect(this.bb_pos+i),this.bb):null}isDelta(){let t=this.bb.__offset(this.bb_pos,8);return t?!!this.bb.readInt8(this.bb_pos+t):!1}static startDictionaryBatch(t){t.startObject(3)}static addId(t,i){t.addFieldInt64(0,i,BigInt("0"))}static addData(t,i){t.addFieldOffset(1,i,0)}static addIsDelta(t,i){t.addFieldInt8(2,+i,0)}static endDictionaryBatch(t){return t.endObject()}};var ir;(function(e){e[e.NONE=0]="NONE",e[e.Schema=1]="Schema",e[e.DictionaryBatch=2]="DictionaryBatch",e[e.RecordBatch=3]="RecordBatch",e[e.Tensor=4]="Tensor",e[e.SparseTensor=5]="SparseTensor"})(ir||(ir={}));var le=class e{constructor(){this.bb=null,this.bb_pos=0}__init(t,i){return this.bb_pos=t,this.bb=i,this}static getRootAsMessage(t,i){return(i||new e).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMessage(t,i){return t.setPosition(t.position()+4),(i||new e).__init(t.readInt32(t.position())+t.position(),t)}version(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readInt16(this.bb_pos+t):si.V1}headerType(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readUint8(this.bb_pos+t):ir.NONE}header(t){let i=this.bb.__offset(this.bb_pos,8);return i?this.bb.__union(t,this.bb_pos+i):null}bodyLength(){let t=this.bb.__offset(this.bb_pos,10);return t?this.bb.readInt64(this.bb_pos+t):BigInt("0")}customMetadata(t,i){let r=this.bb.__offset(this.bb_pos,12);return r?(i||new ut).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+t*4),this.bb):null}customMetadataLength(){let t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}static startMessage(t){t.startObject(5)}static addVersion(t,i){t.addFieldInt16(0,i,si.V1)}static addHeaderType(t,i){t.addFieldInt8(1,i,ir.NONE)}static addHeader(t,i){t.addFieldOffset(2,i,0)}static addBodyLength(t,i){t.addFieldInt64(3,i,BigInt("0"))}static addCustomMetadata(t,i){t.addFieldOffset(4,i,0)}static createCustomMetadataVector(t,i){t.startVector(4,i.length,4);for(let r=i.length-1;r>=0;r--)t.addOffset(i[r]);return t.endVector()}static startCustomMetadataVector(t,i){t.startVector(4,i,4)}static endMessage(t){return t.endObject()}static finishMessageBuffer(t,i){t.finish(i)}static finishSizePrefixedMessageBuffer(t,i){t.finish(i,void 0,!0)}static createMessage(t,i,r,n,o,s){return e.startMessage(t),e.addVersion(t,i),e.addHeaderType(t,r),e.addHeader(t,n),e.addBodyLength(t,o),e.addCustomMetadata(t,s),e.endMessage(t)}};var Vs=class extends O{visit(t,i){return t==null||i==null?void 0:super.visit(t,i)}visitNull(t,i){return mr.startNull(i),mr.endNull(i)}visitInt(t,i){return ue.startInt(i),ue.addBitWidth(i,t.bitWidth),ue.addIsSigned(i,t.isSigned),ue.endInt(i)}visitFloat(t,i){return li.startFloatingPoint(i),li.addPrecision(i,t.precision),li.endFloatingPoint(i)}visitBinary(t,i){return Rr.startBinary(i),Rr.endBinary(i)}visitBool(t,i){return pr.startBool(i),pr.endBool(i)}visitUtf8(t,i){return _r.startUtf8(i),_r.endUtf8(i)}visitDecimal(t,i){return Ce.startDecimal(i),Ce.addScale(i,t.scale),Ce.addPrecision(i,t.precision),Ce.addBitWidth(i,t.bitWidth),Ce.endDecimal(i)}visitDate(t,i){return ci.startDate(i),ci.addUnit(i,t.unit),ci.endDate(i)}visitTime(t,i){return Ze.startTime(i),Ze.addUnit(i,t.unit),Ze.addBitWidth(i,t.bitWidth),Ze.endTime(i)}visitTimestamp(t,i){let r=t.timezone&&i.createString(t.timezone)||void 0;return Se.startTimestamp(i),Se.addUnit(i,t.unit),r!==void 0&&Se.addTimezone(i,r),Se.endTimestamp(i)}visitInterval(t,i){return fi.startInterval(i),fi.addUnit(i,t.unit),fi.endInterval(i)}visitDuration(t,i){return ui.startDuration(i),ui.addUnit(i,t.unit),ui.endDuration(i)}visitList(t,i){return Hr.startList(i),Hr.endList(i)}visitStruct(t,i){return Yr.startStruct_(i),Yr.endStruct_(i)}visitUnion(t,i){de.startTypeIdsVector(i,t.typeIds.length);let r=de.createTypeIdsVector(i,t.typeIds);return de.startUnion(i),de.addMode(i,t.mode),de.addTypeIds(i,r),de.endUnion(i)}visitDictionary(t,i){let r=this.visit(t.indices,i);return Me.startDictionaryEncoding(i),Me.addId(i,BigInt(t.id)),Me.addIsOrdered(i,t.isOrdered),r!==void 0&&Me.addIndexType(i,r),Me.endDictionaryEncoding(i)}visitFixedSizeBinary(t,i){return Bi.startFixedSizeBinary(i),Bi.addByteWidth(i,t.byteWidth),Bi.endFixedSizeBinary(i)}visitFixedSizeList(t,i){return di.startFixedSizeList(i),di.addListSize(i,t.listSize),di.endFixedSizeList(i)}visitMap(t,i){return hi.startMap(i),hi.addKeysSorted(i,t.keysSorted),hi.endMap(i)}},Jo=new Vs;function zc(e,t=new Map){return new S(Ud(e,t),jo(e.metadata),t)}function ks(e){return new wt(e.count,Kc(e.columns),Vc(e.columns))}function Qc(e){return new mt(ks(e.data),e.id,e.isDelta)}function Ud(e,t){return(e.fields||[]).filter(Boolean).map(i=>_.fromJSON(i,t))}function Jc(e,t){return(e.children||[]).filter(Boolean).map(i=>_.fromJSON(i,t))}function Kc(e){return(e||[]).reduce((t,i)=>[...t,new Kt(i.count,Jd(i.VALIDITY)),...Kc(i.children)],[])}function Vc(e,t=[]){for(let i=-1,r=(e||[]).length;++i<r;){let n=e[i];n.VALIDITY&&t.push(new Ht(t.length,n.VALIDITY.length)),n.TYPE_ID&&t.push(new Ht(t.length,n.TYPE_ID.length)),n.OFFSET&&t.push(new Ht(t.length,n.OFFSET.length)),n.DATA&&t.push(new Ht(t.length,n.DATA.length)),t=Vc(n.children,t)}return t}function Jd(e){return(e||[]).reduce((t,i)=>t+ +(i===0),0)}function kc(e,t){let i,r,n,o,s,a;return!t||!(o=e.dictionary)?(s=Pc(e,Jc(e,t)),n=new _(e.name,s,e.nullable,jo(e.metadata))):t.has(i=o.id)?(r=(r=o.indexType)?jc(r):new De,a=new Gt(t.get(i),r,i,o.isOrdered),n=new _(e.name,a,e.nullable,jo(e.metadata))):(r=(r=o.indexType)?jc(r):new De,t.set(i,s=Pc(e,Jc(e,t))),a=new Gt(s,r,i,o.isOrdered),n=new _(e.name,a,e.nullable,jo(e.metadata))),n||null}function jo(e=[]){return new Map(e.map(({key:t,value:i})=>[t,i]))}function jc(e){return new rt(e.isSigned,e.bitWidth)}function Pc(e,t){let i=e.type.name;switch(i){case"NONE":return new Et;case"null":return new Et;case"binary":return new Xe;case"utf8":return new He;case"bool":return new me;case"list":return new re((t||[])[0]);case"struct":return new Q(t||[]);case"struct_":return new Q(t||[])}switch(i){case"int":{let r=e.type;return new rt(r.isSigned,r.bitWidth)}case"floatingpoint":{let r=e.type;return new bt(k[r.precision])}case"decimal":{let r=e.type;return new Ye(r.scale,r.precision,r.bitWidth)}case"date":{let r=e.type;return new xe(ht[r.unit])}case"time":{let r=e.type;return new ie(F[r.unit],r.bitWidth)}case"timestamp":{let r=e.type;return new _e(F[r.unit],r.timezone)}case"interval":{let r=e.type;return new Ge(It[r.unit])}case"duration":{let r=e.type;return new We(F[r.unit])}case"union":{let r=e.type,[n,...o]=(r.mode+"").toLowerCase(),s=n.toUpperCase()+o.join("");return new ne(z[s],r.typeIds||[],t||[])}case"fixedsizebinary":{let r=e.type;return new ge(r.byteWidth)}case"fixedsizelist":{let r=e.type;return new oe(r.listSize,(t||[])[0])}case"map":{let r=e.type;return new se((t||[])[0],r.keysSorted)}}throw new Error(`Unrecognized type: "${i}"`)}var jd=pi,Pd=Nt,Yt=class e{static fromJSON(t,i){let r=new e(0,$.V5,i);return r._createHeader=zd(t,i),r}static decode(t){t=new Pd(b(t));let i=le.getRootAsMessage(t),r=i.bodyLength(),n=i.version(),o=i.headerType(),s=new e(r,n,o);return s._createHeader=Qd(i,o),s}static encode(t){let i=new jd,r=-1;return t.isSchema()?r=S.encode(i,t.header()):t.isRecordBatch()?r=wt.encode(i,t.header()):t.isDictionaryBatch()&&(r=mt.encode(i,t.header())),le.startMessage(i),le.addVersion(i,$.V5),le.addHeader(i,r),le.addHeaderType(i,t.headerType),le.addBodyLength(i,BigInt(t.bodyLength)),le.finishMessageBuffer(i,le.endMessage(i)),i.asUint8Array()}static from(t,i=0){if(t instanceof S)return new e(0,$.V5,N.Schema,t);if(t instanceof wt)return new e(i,$.V5,N.RecordBatch,t);if(t instanceof mt)return new e(i,$.V5,N.DictionaryBatch,t);throw new Error(`Unrecognized Message header: ${t}`)}get type(){return this.headerType}get version(){return this._version}get headerType(){return this._headerType}get bodyLength(){return this._bodyLength}header(){return this._createHeader()}isSchema(){return this.headerType===N.Schema}isRecordBatch(){return this.headerType===N.RecordBatch}isDictionaryBatch(){return this.headerType===N.DictionaryBatch}constructor(t,i,r,n){this._version=i,this._headerType=r,this.body=new Uint8Array(0),n&&(this._createHeader=()=>n),this._bodyLength=Lt(t)}},wt=class{get nodes(){return this._nodes}get length(){return this._length}get buffers(){return this._buffers}constructor(t,i,r){this._nodes=i,this._buffers=r,this._length=Lt(t)}},mt=class{get id(){return this._id}get data(){return this._data}get isDelta(){return this._isDelta}get length(){return this.data.length}get nodes(){return this.data.nodes}get buffers(){return this.data.buffers}constructor(t,i,r=!1){this._data=t,this._isDelta=r,this._id=Lt(i)}},Ht=class{constructor(t,i){this.offset=Lt(t),this.length=Lt(i)}},Kt=class{constructor(t,i){this.length=Lt(t),this.nullCount=Lt(i)}};function zd(e,t){return()=>{switch(t){case N.Schema:return S.fromJSON(e);case N.RecordBatch:return wt.fromJSON(e);case N.DictionaryBatch:return mt.fromJSON(e)}throw new Error(`Unrecognized Message type: { name: ${N[t]}, type: ${t} }`)}}function Qd(e,t){return()=>{switch(t){case N.Schema:return S.decode(e.header(new Xt),new Map,e.version());case N.RecordBatch:return wt.decode(e.header(new Zt),e.version());case N.DictionaryBatch:return mt.decode(e.header(new ke),e.version())}throw new Error(`Unrecognized Message type: { name: ${N[t]}, type: ${t} }`)}}_.encode=nl;_.decode=il;_.fromJSON=kc;S.encode=rl;S.decode=Kd;S.fromJSON=zc;wt.encode=ol;wt.decode=Vd;wt.fromJSON=ks;mt.encode=sl;mt.decode=kd;mt.fromJSON=Qc;Kt.encode=al;Kt.decode=$d;Ht.encode=cl;Ht.decode=qd;function Kd(e,t=new Map,i=$.V5){let r=el(e,t);return new S(r,Po(e),t,i)}function Vd(e,t=$.V5){if(e.compression()!==null)throw new Error("Record batch compression not implemented");return new wt(e.length(),Ad(e),tl(e,t))}function kd(e,t=$.V5){return new mt(wt.decode(e.data(),t),e.id(),e.isDelta())}function qd(e){return new Ht(e.offset(),e.length())}function $d(e){return new Kt(e.length(),e.nullCount())}function Ad(e){let t=[];for(let i,r=-1,n=-1,o=e.nodesLength();++r<o;)(i=e.nodes(r))&&(t[++n]=Kt.decode(i));return t}function tl(e,t){let i=[];for(let r,n=-1,o=-1,s=e.buffersLength();++n<s;)(r=e.buffers(n))&&(t<$.V4&&(r.bb_pos+=8*(n+1)),i[++o]=Ht.decode(r));return i}function el(e,t){let i=[];for(let r,n=-1,o=-1,s=e.fieldsLength();++n<s;)(r=e.fields(n))&&(i[++o]=_.decode(r,t));return i}function qc(e,t){let i=[];for(let r,n=-1,o=-1,s=e.childrenLength();++n<s;)(r=e.children(n))&&(i[++o]=_.decode(r,t));return i}function il(e,t){let i,r,n,o,s,a;return!t||!(a=e.dictionary())?(n=Ac(e,qc(e,t)),r=new _(e.name(),n,e.nullable(),Po(e))):t.has(i=Lt(a.id()))?(o=(o=a.indexType())?$c(o):new De,s=new Gt(t.get(i),o,i,a.isOrdered()),r=new _(e.name(),s,e.nullable(),Po(e))):(o=(o=a.indexType())?$c(o):new De,t.set(i,n=Ac(e,qc(e,t))),s=new Gt(n,o,i,a.isOrdered()),r=new _(e.name(),s,e.nullable(),Po(e))),r||null}function Po(e){let t=new Map;if(e)for(let i,r,n=-1,o=Math.trunc(e.customMetadataLength());++n<o;)(i=e.customMetadata(n))&&(r=i.key())!=null&&t.set(r,i.value());return t}function $c(e){return new rt(e.isSigned(),e.bitWidth())}function Ac(e,t){let i=e.typeType();switch(i){case K.NONE:return new Et;case K.Null:return new Et;case K.Binary:return new Xe;case K.Utf8:return new He;case K.Bool:return new me;case K.List:return new re((t||[])[0]);case K.Struct_:return new Q(t||[])}switch(i){case K.Int:{let r=e.type(new ue);return new rt(r.isSigned(),r.bitWidth())}case K.FloatingPoint:{let r=e.type(new li);return new bt(r.precision())}case K.Decimal:{let r=e.type(new Ce);return new Ye(r.scale(),r.precision(),r.bitWidth())}case K.Date:{let r=e.type(new ci);return new xe(r.unit())}case K.Time:{let r=e.type(new Ze);return new ie(r.unit(),r.bitWidth())}case K.Timestamp:{let r=e.type(new Se);return new _e(r.unit(),r.timezone())}case K.Interval:{let r=e.type(new fi);return new Ge(r.unit())}case K.Duration:{let r=e.type(new ui);return new We(r.unit())}case K.Union:{let r=e.type(new de);return new ne(r.mode(),r.typeIdsArray()||[],t||[])}case K.FixedSizeBinary:{let r=e.type(new Bi);return new ge(r.byteWidth())}case K.FixedSizeList:{let r=e.type(new di);return new oe(r.listSize(),(t||[])[0])}case K.Map:{let r=e.type(new hi);return new se((t||[])[0],r.keysSorted())}}throw new Error(`Unrecognized type: "${K[i]}" (${i})`)}function rl(e,t){let i=t.fields.map(o=>_.encode(e,o));Xt.startFieldsVector(e,i.length);let r=Xt.createFieldsVector(e,i),n=t.metadata&&t.metadata.size>0?Xt.createCustomMetadataVector(e,[...t.metadata].map(([o,s])=>{let a=e.createString(`${o}`),c=e.createString(`${s}`);return ut.startKeyValue(e),ut.addKey(e,a),ut.addValue(e,c),ut.endKeyValue(e)})):-1;return Xt.startSchema(e),Xt.addFields(e,r),Xt.addEndianness(e,ul?ai.Little:ai.Big),n!==-1&&Xt.addCustomMetadata(e,n),Xt.endSchema(e)}function nl(e,t){let i=-1,r=-1,n=-1,o=t.type,s=t.typeId;h.isDictionary(o)?(s=o.dictionary.typeId,n=Jo.visit(o,e),r=Jo.visit(o.dictionary,e)):r=Jo.visit(o,e);let a=(o.children||[]).map(d=>_.encode(e,d)),c=Dt.createChildrenVector(e,a),B=t.metadata&&t.metadata.size>0?Dt.createCustomMetadataVector(e,[...t.metadata].map(([d,l])=>{let D=e.createString(`${d}`),y=e.createString(`${l}`);return ut.startKeyValue(e),ut.addKey(e,D),ut.addValue(e,y),ut.endKeyValue(e)})):-1;return t.name&&(i=e.createString(t.name)),Dt.startField(e),Dt.addType(e,r),Dt.addTypeType(e,s),Dt.addChildren(e,c),Dt.addNullable(e,!!t.nullable),i!==-1&&Dt.addName(e,i),n!==-1&&Dt.addDictionary(e,n),B!==-1&&Dt.addCustomMetadata(e,B),Dt.endField(e)}function ol(e,t){let i=t.nodes||[],r=t.buffers||[];Zt.startNodesVector(e,i.length);for(let s of i.slice().reverse())Kt.encode(e,s);let n=e.endVector();Zt.startBuffersVector(e,r.length);for(let s of r.slice().reverse())Ht.encode(e,s);let o=e.endVector();return Zt.startRecordBatch(e),Zt.addLength(e,BigInt(t.length)),Zt.addNodes(e,n),Zt.addBuffers(e,o),Zt.endRecordBatch(e)}function sl(e,t){let i=wt.encode(e,t.data);return ke.startDictionaryBatch(e),ke.addId(e,BigInt(t.id)),ke.addIsDelta(e,t.isDelta),ke.addData(e,i),ke.endDictionaryBatch(e)}function al(e,t){return er.createFieldNode(e,BigInt(t.length),BigInt(t.nullCount))}function cl(e,t){return tr.createBuffer(e,BigInt(t.offset),BigInt(t.length))}var ul=(()=>{let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]===256})();var $s=e=>`Expected ${N[e]} Message in stream, but was null or length 0.`,As=e=>`Header pointer of flatbuffer-encoded ${N[e]} Message is null or length 0.`,tu=(e,t)=>`Expected to read ${e} metadata bytes, but only read ${t}.`,eu=(e,t)=>`Expected to read ${e} bytes for message body, but only read ${t}.`,rr=class{constructor(t){this.source=t instanceof pe?t:new pe(t)}[Symbol.iterator](){return this}next(){let t;return(t=this.readMetadataLength()).done?V:t.value===-1&&(t=this.readMetadataLength()).done?V:(t=this.readMetadata(t.value)).done?V:t}throw(t){return this.source.throw(t)}return(t){return this.source.return(t)}readMessage(t){let i;if((i=this.next()).done)return null;if(t!=null&&i.value.headerType!==t)throw new Error($s(t));return i.value}readMessageBody(t){if(t<=0)return new Uint8Array(0);let i=b(this.source.read(t));if(i.byteLength<t)throw new Error(eu(t,i.byteLength));return i.byteOffset%8===0&&i.byteOffset+i.byteLength<=i.buffer.byteLength?i:i.slice()}readSchema(t=!1){let i=N.Schema,r=this.readMessage(i),n=r?.header();if(t&&!n)throw new Error(As(i));return n}readMetadataLength(){let t=this.source.read(zo),i=t&&new Nt(t),r=i?.readInt32(0)||0;return{done:r===0,value:r}}readMetadata(t){let i=this.source.read(t);if(!i)return V;if(i.byteLength<t)throw new Error(tu(t,i.byteLength));return{done:!1,value:Yt.decode(i)}}},ln=class{constructor(t,i){this.source=t instanceof zt?t:Rn(t)?new yi(t,i):new zt(t)}[Symbol.asyncIterator](){return this}next(){return f(this,void 0,void 0,function*(){let t;return(t=yield this.readMetadataLength()).done?V:t.value===-1&&(t=yield this.readMetadataLength()).done?V:(t=yield this.readMetadata(t.value)).done?V:t})}throw(t){return f(this,void 0,void 0,function*(){return yield this.source.throw(t)})}return(t){return f(this,void 0,void 0,function*(){return yield this.source.return(t)})}readMessage(t){return f(this,void 0,void 0,function*(){let i;if((i=yield this.next()).done)return null;if(t!=null&&i.value.headerType!==t)throw new Error($s(t));return i.value})}readMessageBody(t){return f(this,void 0,void 0,function*(){if(t<=0)return new Uint8Array(0);let i=b(yield this.source.read(t));if(i.byteLength<t)throw new Error(eu(t,i.byteLength));return i.byteOffset%8===0&&i.byteOffset+i.byteLength<=i.buffer.byteLength?i:i.slice()})}readSchema(t=!1){return f(this,void 0,void 0,function*(){let i=N.Schema,r=yield this.readMessage(i),n=r?.header();if(t&&!n)throw new Error(As(i));return n})}readMetadataLength(){return f(this,void 0,void 0,function*(){let t=yield this.source.read(zo),i=t&&new Nt(t),r=i?.readInt32(0)||0;return{done:r===0,value:r}})}readMetadata(t){return f(this,void 0,void 0,function*(){let i=yield this.source.read(t);if(!i)return V;if(i.byteLength<t)throw new Error(tu(t,i.byteLength));return{done:!1,value:Yt.decode(i)}})}},fn=class extends rr{constructor(t){super(new Uint8Array(0)),this._schema=!1,this._body=[],this._batchIndex=0,this._dictionaryIndex=0,this._json=t instanceof Gr?t:new Gr(t)}next(){let{_json:t}=this;if(!this._schema)return this._schema=!0,{done:!1,value:Yt.fromJSON(t.schema,N.Schema)};if(this._dictionaryIndex<t.dictionaries.length){let i=t.dictionaries[this._dictionaryIndex++];return this._body=i.data.columns,{done:!1,value:Yt.fromJSON(i,N.DictionaryBatch)}}if(this._batchIndex<t.batches.length){let i=t.batches[this._batchIndex++];return this._body=i.columns,{done:!1,value:Yt.fromJSON(i,N.RecordBatch)}}return this._body=[],V}readMessageBody(t){return i(this._body);function i(r){return(r||[]).reduce((n,o)=>[...n,...o.VALIDITY&&[o.VALIDITY]||[],...o.TYPE_ID&&[o.TYPE_ID]||[],...o.OFFSET&&[o.OFFSET]||[],...o.DATA&&[o.DATA]||[],...i(o.children)],[])}}readMessage(t){let i;if((i=this.next()).done)return null;if(t!=null&&i.value.headerType!==t)throw new Error($s(t));return i.value}readSchema(){let t=N.Schema,i=this.readMessage(t),r=i?.header();if(!i||!r)throw new Error(As(t));return r}},zo=4,qs="ARROW1",nr=new Uint8Array(qs.length);for(let e=0;e<qs.length;e+=1)nr[e]=qs.codePointAt(e);function Qo(e,t=0){for(let i=-1,r=nr.length;++i<r;)if(nr[i]!==e[t+i])return!1;return!0}var or=nr.length,ta=or+zo,iu=or*2+zo;var Ot=class e extends Li{constructor(t){super(),this._impl=t}get closed(){return this._impl.closed}get schema(){return this._impl.schema}get autoDestroy(){return this._impl.autoDestroy}get dictionaries(){return this._impl.dictionaries}get numDictionaries(){return this._impl.numDictionaries}get numRecordBatches(){return this._impl.numRecordBatches}get footer(){return this._impl.isFile()?this._impl.footer:null}isSync(){return this._impl.isSync()}isAsync(){return this._impl.isAsync()}isFile(){return this._impl.isFile()}isStream(){return this._impl.isStream()}next(){return this._impl.next()}throw(t){return this._impl.throw(t)}return(t){return this._impl.return(t)}cancel(){return this._impl.cancel()}reset(t){return this._impl.reset(t),this._DOMStream=void 0,this._nodeStream=void 0,this}open(t){let i=this._impl.open(t);return qt(i)?i.then(()=>this):this}readRecordBatch(t){return this._impl.isFile()?this._impl.readRecordBatch(t):null}[Symbol.iterator](){return this._impl[Symbol.iterator]()}[Symbol.asyncIterator](){return this._impl[Symbol.asyncIterator]()}toDOMStream(){return ft.toDOMStream(this.isSync()?{[Symbol.iterator]:()=>this}:{[Symbol.asyncIterator]:()=>this})}toNodeStream(){return ft.toNodeStream(this.isSync()?{[Symbol.iterator]:()=>this}:{[Symbol.asyncIterator]:()=>this},{objectMode:!0})}static throughNode(t){throw new Error('"throughNode" not available in this environment')}static throughDOM(t,i){throw new Error('"throughDOM" not available in this environment')}static from(t){return t instanceof e?t:Mn(t)?dl(t):Rn(t)?hl(t):qt(t)?f(this,void 0,void 0,function*(){return yield e.from(yield t)}):pn(t)||yr(t)||bn(t)||Ut(t)?fl(new zt(t)):ll(new pe(t))}static readAll(t){return t instanceof e?t.isSync()?ru(t):nu(t):Mn(t)||ArrayBuffer.isView(t)||$t(t)||Cn(t)?ru(t):nu(t)}},be=class extends Ot{constructor(t){super(t),this._impl=t}readAll(){return[...this]}[Symbol.iterator](){return this._impl[Symbol.iterator]()}[Symbol.asyncIterator](){return xt(this,arguments,function*(){yield m(yield*gi(kt(this[Symbol.iterator]())))})}},wi=class extends Ot{constructor(t){super(t),this._impl=t}readAll(){var t,i,r,n;return f(this,void 0,void 0,function*(){let o=new Array;try{for(var s=!0,a=kt(this),c;c=yield a.next(),t=c.done,!t;s=!0){n=c.value,s=!1;let B=n;o.push(B)}}catch(B){i={error:B}}finally{try{!s&&!t&&(r=a.return)&&(yield r.call(a))}finally{if(i)throw i.error}}return o})}[Symbol.iterator](){throw new Error("AsyncRecordBatchStreamReader is not Iterable")}[Symbol.asyncIterator](){return this._impl[Symbol.asyncIterator]()}},Oi=class extends be{constructor(t){super(t),this._impl=t}},hn=class extends wi{constructor(t){super(t),this._impl=t}},Ko=class{get numDictionaries(){return this._dictionaryIndex}get numRecordBatches(){return this._recordBatchIndex}constructor(t=new Map){this.closed=!1,this.autoDestroy=!0,this._dictionaryIndex=0,this._recordBatchIndex=0,this.dictionaries=t}isSync(){return!1}isAsync(){return!1}isFile(){return!1}isStream(){return!1}reset(t){return this._dictionaryIndex=0,this._recordBatchIndex=0,this.schema=t,this.dictionaries=new Map,this}_loadRecordBatch(t,i){let r=this._loadVectors(t,i,this.schema.fields),n=X({type:new Q(this.schema.fields),length:t.length,children:r});return new tt(this.schema,n)}_loadDictionaryBatch(t,i){let{id:r,isDelta:n}=t,{dictionaries:o,schema:s}=this,a=o.get(r);if(n||!a){let c=s.dictionaries.get(r),B=this._loadVectors(t.data,i,[c]);return(a&&n?a.concat(new W(B)):new W(B)).memoize()}return a.memoize()}_loadVectors(t,i,r){return new Tr(i,t.nodes,t.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(r)}},sr=class extends Ko{constructor(t,i){super(i),this._reader=Mn(t)?new fn(this._handle=t):new rr(this._handle=t)}isSync(){return!0}isStream(){return!0}[Symbol.iterator](){return this}cancel(){!this.closed&&(this.closed=!0)&&(this.reset()._reader.return(),this._reader=null,this.dictionaries=null)}open(t){return this.closed||(this.autoDestroy=ou(this,t),this.schema||(this.schema=this._reader.readSchema())||this.cancel()),this}throw(t){return!this.closed&&this.autoDestroy&&(this.closed=!0)?this.reset()._reader.throw(t):V}return(t){return!this.closed&&this.autoDestroy&&(this.closed=!0)?this.reset()._reader.return(t):V}next(){if(this.closed)return V;let t,{_reader:i}=this;for(;t=this._readNextMessageAndValidate();)if(t.isSchema())this.reset(t.header());else if(t.isRecordBatch()){this._recordBatchIndex++;let r=t.header(),n=i.readMessageBody(t.bodyLength);return{done:!1,value:this._loadRecordBatch(r,n)}}else if(t.isDictionaryBatch()){this._dictionaryIndex++;let r=t.header(),n=i.readMessageBody(t.bodyLength),o=this._loadDictionaryBatch(r,n);this.dictionaries.set(r.id,o)}return this.schema&&this._recordBatchIndex===0?(this._recordBatchIndex++,{done:!1,value:new xi(this.schema)}):this.return()}_readNextMessageAndValidate(t){return this._reader.readMessage(t)}},ar=class extends Ko{constructor(t,i){super(i),this._reader=new ln(this._handle=t)}isAsync(){return!0}isStream(){return!0}[Symbol.asyncIterator](){return this}cancel(){return f(this,void 0,void 0,function*(){!this.closed&&(this.closed=!0)&&(yield this.reset()._reader.return(),this._reader=null,this.dictionaries=null)})}open(t){return f(this,void 0,void 0,function*(){return this.closed||(this.autoDestroy=ou(this,t),this.schema||(this.schema=yield this._reader.readSchema())||(yield this.cancel())),this})}throw(t){return f(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.throw(t):V})}return(t){return f(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.return(t):V})}next(){return f(this,void 0,void 0,function*(){if(this.closed)return V;let t,{_reader:i}=this;for(;t=yield this._readNextMessageAndValidate();)if(t.isSchema())yield this.reset(t.header());else if(t.isRecordBatch()){this._recordBatchIndex++;let r=t.header(),n=yield i.readMessageBody(t.bodyLength);return{done:!1,value:this._loadRecordBatch(r,n)}}else if(t.isDictionaryBatch()){this._dictionaryIndex++;let r=t.header(),n=yield i.readMessageBody(t.bodyLength),o=this._loadDictionaryBatch(r,n);this.dictionaries.set(r.id,o)}return this.schema&&this._recordBatchIndex===0?(this._recordBatchIndex++,{done:!1,value:new xi(this.schema)}):yield this.return()})}_readNextMessageAndValidate(t){return f(this,void 0,void 0,function*(){return yield this._reader.readMessage(t)})}},Vo=class extends sr{get footer(){return this._footer}get numDictionaries(){return this._footer?this._footer.numDictionaries:0}get numRecordBatches(){return this._footer?this._footer.numRecordBatches:0}constructor(t,i){super(t instanceof Wr?t:new Wr(t),i)}isSync(){return!0}isFile(){return!0}open(t){if(!this.closed&&!this._footer){this.schema=(this._footer=this._readFooter()).schema;for(let i of this._footer.dictionaryBatches())i&&this._readDictionaryBatch(this._dictionaryIndex++)}return super.open(t)}readRecordBatch(t){var i;if(this.closed)return null;this._footer||this.open();let r=(i=this._footer)===null||i===void 0?void 0:i.getRecordBatch(t);if(r&&this._handle.seek(r.offset)){let n=this._reader.readMessage(N.RecordBatch);if(n?.isRecordBatch()){let o=n.header(),s=this._reader.readMessageBody(n.bodyLength);return this._loadRecordBatch(o,s)}}return null}_readDictionaryBatch(t){var i;let r=(i=this._footer)===null||i===void 0?void 0:i.getDictionaryBatch(t);if(r&&this._handle.seek(r.offset)){let n=this._reader.readMessage(N.DictionaryBatch);if(n?.isDictionaryBatch()){let o=n.header(),s=this._reader.readMessageBody(n.bodyLength),a=this._loadDictionaryBatch(o,s);this.dictionaries.set(o.id,a)}}}_readFooter(){let{_handle:t}=this,i=t.size-ta,r=t.readInt32(i),n=t.readAt(i-r,r);return Ue.decode(n)}_readNextMessageAndValidate(t){var i;if(this._footer||this.open(),this._footer&&this._recordBatchIndex<this.numRecordBatches){let r=(i=this._footer)===null||i===void 0?void 0:i.getRecordBatch(this._recordBatchIndex);if(r&&this._handle.seek(r.offset))return this._reader.readMessage(t)}return null}},ea=class extends ar{get footer(){return this._footer}get numDictionaries(){return this._footer?this._footer.numDictionaries:0}get numRecordBatches(){return this._footer?this._footer.numRecordBatches:0}constructor(t,...i){let r=typeof i[0]!="number"?i.shift():void 0,n=i[0]instanceof Map?i.shift():void 0;super(t instanceof yi?t:new yi(t,r),n)}isFile(){return!0}isAsync(){return!0}open(t){let i=Object.create(null,{open:{get:()=>super.open}});return f(this,void 0,void 0,function*(){if(!this.closed&&!this._footer){this.schema=(this._footer=yield this._readFooter()).schema;for(let r of this._footer.dictionaryBatches())r&&(yield this._readDictionaryBatch(this._dictionaryIndex++))}return yield i.open.call(this,t)})}readRecordBatch(t){var i;return f(this,void 0,void 0,function*(){if(this.closed)return null;this._footer||(yield this.open());let r=(i=this._footer)===null||i===void 0?void 0:i.getRecordBatch(t);if(r&&(yield this._handle.seek(r.offset))){let n=yield this._reader.readMessage(N.RecordBatch);if(n?.isRecordBatch()){let o=n.header(),s=yield this._reader.readMessageBody(n.bodyLength);return this._loadRecordBatch(o,s)}}return null})}_readDictionaryBatch(t){var i;return f(this,void 0,void 0,function*(){let r=(i=this._footer)===null||i===void 0?void 0:i.getDictionaryBatch(t);if(r&&(yield this._handle.seek(r.offset))){let n=yield this._reader.readMessage(N.DictionaryBatch);if(n?.isDictionaryBatch()){let o=n.header(),s=yield this._reader.readMessageBody(n.bodyLength),a=this._loadDictionaryBatch(o,s);this.dictionaries.set(o.id,a)}}})}_readFooter(){return f(this,void 0,void 0,function*(){let{_handle:t}=this;t._pending&&(yield t._pending);let i=t.size-ta,r=yield t.readInt32(i),n=yield t.readAt(i-r,r);return Ue.decode(n)})}_readNextMessageAndValidate(t){return f(this,void 0,void 0,function*(){if(this._footer||(yield this.open()),this._footer&&this._recordBatchIndex<this.numRecordBatches){let i=this._footer.getRecordBatch(this._recordBatchIndex);if(i&&(yield this._handle.seek(i.offset)))return yield this._reader.readMessage(t)}return null})}},ia=class extends sr{constructor(t,i){super(t,i)}_loadVectors(t,i,r){return new Fo(i,t.nodes,t.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(r)}};function ou(e,t){return t&&typeof t.autoDestroy=="boolean"?t.autoDestroy:e.autoDestroy}function*ru(e){let t=Ot.from(e);try{if(!t.open({autoDestroy:!1}).closed)do yield t;while(!t.reset().open().closed)}finally{t.cancel()}}function nu(e){return xt(this,arguments,function*(){let i=yield m(Ot.from(e));try{if(!(yield m(i.open({autoDestroy:!1}))).closed)do yield yield m(i);while(!(yield m(i.reset().open())).closed)}finally{yield m(i.cancel())}})}function dl(e){return new be(new ia(e))}function ll(e){let t=e.peek(or+7&-8);return t&&t.byteLength>=4?Qo(t)?new Oi(new Vo(e.read())):new be(new sr(e)):new be(new sr(function*(){}()))}function fl(e){return f(this,void 0,void 0,function*(){let t=yield e.peek(or+7&-8);return t&&t.byteLength>=4?Qo(t)?new Oi(new Vo(yield e.read())):new wi(new ar(e)):new wi(new ar(function(){return xt(this,arguments,function*(){})}()))})}function hl(e){return f(this,void 0,void 0,function*(){let{size:t}=yield e.stat(),i=new yi(e,t);return t>=iu&&Qo(yield i.readAt(0,or+7&-8))?new hn(new ea(i)):new wi(new ar(i))})}var et=class e extends O{static assemble(...t){let i=n=>n.flatMap(o=>Array.isArray(o)?i(o):o instanceof tt?o.data.children:o.data),r=new e;return r.visitMany(i(t)),r}constructor(){super(),this._byteLength=0,this._nodes=[],this._buffers=[],this._bufferRegions=[]}visit(t){if(t instanceof W)return this.visitMany(t.data),this;let{type:i}=t;if(!h.isDictionary(i)){let{length:r}=t;if(r>2147483647)throw new RangeError("Cannot write arrays larger than 2^31 - 1 in length");if(h.isUnion(i))this.nodes.push(new Kt(r,0));else{let{nullCount:n}=t;h.isNull(i)||fe.call(this,n<=0?new Uint8Array(0):vi(t.offset,r,t.nullBitmap)),this.nodes.push(new Kt(r,n))}}return super.visit(t)}visitNull(t){return this}visitDictionary(t){return this.visit(t.clone(t.type.indices))}get nodes(){return this._nodes}get buffers(){return this._buffers}get byteLength(){return this._byteLength}get bufferRegions(){return this._bufferRegions}};function fe(e){let t=e.byteLength+7&-8;return this.buffers.push(e),this.bufferRegions.push(new Ht(this._byteLength,t)),this._byteLength+=t,this}function yl(e){var t;let{type:i,length:r,typeIds:n,valueOffsets:o}=e;if(fe.call(this,n),i.mode===z.Sparse)return ra.call(this,e);if(i.mode===z.Dense){if(e.offset<=0)return fe.call(this,o),ra.call(this,e);{let s=new Int32Array(r),a=Object.create(null),c=Object.create(null);for(let B,d,l=-1;++l<r;)(B=n[l])!==void 0&&((d=a[B])===void 0&&(d=a[B]=o[l]),s[l]=o[l]-d,c[B]=((t=c[B])!==null&&t!==void 0?t:0)+1);fe.call(this,s),this.visitMany(e.children.map((B,d)=>{let l=i.typeIds[d],D=a[l],y=c[l];return B.slice(D,Math.min(r,y))}))}}return this}function wl(e){let t;return e.nullCount>=e.length?fe.call(this,new Uint8Array(0)):(t=e.values)instanceof Uint8Array?fe.call(this,vi(e.offset,e.length,t)):fe.call(this,Mi(e.values))}function qe(e){return fe.call(this,e.values.subarray(0,e.length*e.stride))}function su(e){let{length:t,values:i,valueOffsets:r}=e,{[0]:n,[t]:o}=r,s=Math.min(o-n,i.byteLength-n);return fe.call(this,Xn(-n,t+1,r)),fe.call(this,i.subarray(n,n+s)),this}function na(e){let{length:t,valueOffsets:i}=e;if(i){let{[0]:r,[t]:n}=i;return fe.call(this,Xn(-r,t+1,i)),this.visit(e.children[0].slice(r,n-r))}return this.visit(e.children[0])}function ra(e){return this.visitMany(e.type.children.map((t,i)=>e.children[i]).filter(Boolean))[0]}et.prototype.visitBool=wl;et.prototype.visitInt=qe;et.prototype.visitFloat=qe;et.prototype.visitUtf8=su;et.prototype.visitBinary=su;et.prototype.visitFixedSizeBinary=qe;et.prototype.visitDate=qe;et.prototype.visitTimestamp=qe;et.prototype.visitTime=qe;et.prototype.visitDecimal=qe;et.prototype.visitList=na;et.prototype.visitStruct=ra;et.prototype.visitUnion=yl;et.prototype.visitInterval=qe;et.prototype.visitDuration=qe;et.prototype.visitFixedSizeList=na;et.prototype.visitMap=na;var _i=class extends Li{static throughNode(t){throw new Error('"throughNode" not available in this environment')}static throughDOM(t,i){throw new Error('"throughDOM" not available in this environment')}constructor(t){super(),this._position=0,this._started=!1,this._sink=new Re,this._schema=null,this._dictionaryBlocks=[],this._recordBatchBlocks=[],this._dictionaryDeltaOffsets=new Map,Ft(t)||(t={autoDestroy:!0,writeLegacyIpcFormat:!1}),this._autoDestroy=typeof t.autoDestroy=="boolean"?t.autoDestroy:!0,this._writeLegacyIpcFormat=typeof t.writeLegacyIpcFormat=="boolean"?t.writeLegacyIpcFormat:!1}toString(t=!1){return this._sink.toString(t)}toUint8Array(t=!1){return this._sink.toUint8Array(t)}writeAll(t){return qt(t)?t.then(i=>this.writeAll(i)):Ut(t)?sa(this,t):oa(this,t)}get closed(){return this._sink.closed}[Symbol.asyncIterator](){return this._sink[Symbol.asyncIterator]()}toDOMStream(t){return this._sink.toDOMStream(t)}toNodeStream(t){return this._sink.toNodeStream(t)}close(){return this.reset()._sink.close()}abort(t){return this.reset()._sink.abort(t)}finish(){return this._autoDestroy?this.close():this.reset(this._sink,this._schema),this}reset(t=this._sink,i=null){return t===this._sink||t instanceof Re?this._sink=t:(this._sink=new Re,t&&Ra(t)?this.toDOMStream({type:"bytes"}).pipeTo(t):t&&pa(t)&&this.toNodeStream({objectMode:!1}).pipe(t)),this._started&&this._schema&&this._writeFooter(this._schema),this._started=!1,this._dictionaryBlocks=[],this._recordBatchBlocks=[],this._dictionaryDeltaOffsets=new Map,(!i||!Yi(i,this._schema))&&(i==null?(this._position=0,this._schema=null):(this._started=!0,this._schema=i,this._writeSchema(i))),this}write(t){let i=null;if(this._sink){if(t==null)return this.finish()&&void 0;if(t instanceof Mt&&!(i=t.schema))return this.finish()&&void 0;if(t instanceof tt&&!(i=t.schema))return this.finish()&&void 0}else throw new Error("RecordBatchWriter is closed");if(i&&!Yi(i,this._schema)){if(this._started&&this._autoDestroy)return this.close();this.reset(this._sink,i)}t instanceof tt?t instanceof xi||this._writeRecordBatch(t):t instanceof Mt?this.writeAll(t.batches):$t(t)&&this.writeAll(t)}_writeMessage(t,i=8){let r=i-1,n=Yt.encode(t),o=n.byteLength,s=this._writeLegacyIpcFormat?4:8,a=o+s+r&~r,c=a-o-s;return t.headerType===N.RecordBatch?this._recordBatchBlocks.push(new Je(a,t.bodyLength,this._position)):t.headerType===N.DictionaryBatch&&this._dictionaryBlocks.push(new Je(a,t.bodyLength,this._position)),this._writeLegacyIpcFormat||this._write(Int32Array.of(-1)),this._write(Int32Array.of(a-s)),o>0&&this._write(n),this._writePadding(c)}_write(t){if(this._started){let i=b(t);i&&i.byteLength>0&&(this._sink.write(i),this._position+=i.byteLength)}return this}_writeSchema(t){return this._writeMessage(Yt.from(t))}_writeFooter(t){return this._writeLegacyIpcFormat?this._write(Int32Array.of(0)):this._write(Int32Array.of(-1,0))}_writeMagic(){return this._write(nr)}_writePadding(t){return t>0?this._write(new Uint8Array(t)):this}_writeRecordBatch(t){let{byteLength:i,nodes:r,bufferRegions:n,buffers:o}=et.assemble(t),s=new wt(t.numRows,r,n),a=Yt.from(s,i);return this._writeDictionaries(t)._writeMessage(a)._writeBodyBuffers(o)}_writeDictionaryBatch(t,i,r=!1){this._dictionaryDeltaOffsets.set(i,t.length+(this._dictionaryDeltaOffsets.get(i)||0));let{byteLength:n,nodes:o,bufferRegions:s,buffers:a}=et.assemble(new W([t])),c=new wt(t.length,o,s),B=new mt(c,i,r),d=Yt.from(B,n);return this._writeMessage(d)._writeBodyBuffers(a)}_writeBodyBuffers(t){let i,r,n;for(let o=-1,s=t.length;++o<s;)(i=t[o])&&(r=i.byteLength)>0&&(this._write(i),(n=(r+7&-8)-r)>0&&this._writePadding(n));return this}_writeDictionaries(t){for(let[i,r]of t.dictionaries){let n=this._dictionaryDeltaOffsets.get(i)||0;if(n===0||(r=r?.slice(n)).length>0)for(let o of r.data)this._writeDictionaryBatch(o,i,n>0),n+=o.length}return this}},Gi=class e extends _i{static writeAll(t,i){let r=new e(i);return qt(t)?t.then(n=>r.writeAll(n)):Ut(t)?sa(r,t):oa(r,t)}},Wi=class e extends _i{static writeAll(t){let i=new e;return qt(t)?t.then(r=>i.writeAll(r)):Ut(t)?sa(i,t):oa(i,t)}constructor(){super(),this._autoDestroy=!0}_writeSchema(t){return this._writeMagic()._writePadding(2)}_writeFooter(t){let i=Ue.encode(new Ue(t,$.V5,this._recordBatchBlocks,this._dictionaryBlocks));return super._writeFooter(t)._write(i)._write(Int32Array.of(i.byteLength))._writeMagic()}};function oa(e,t){let i=t;t instanceof Mt&&(i=t.batches,e.reset(void 0,t.schema));for(let r of i)e.write(r);return e.finish()}function sa(e,t){var i,r,n,o,s,a,c;return f(this,void 0,void 0,function*(){try{for(i=!0,r=kt(t);n=yield r.next(),o=n.done,!o;i=!0){c=n.value,i=!1;let B=c;e.write(B)}}catch(B){s={error:B}}finally{try{!i&&!o&&(a=r.return)&&(yield a.call(r))}finally{if(s)throw s.error}}return e.finish()})}function au(e,t){if(Ut(e))return Dl(e,t);if($t(e))return Ol(e,t);throw new Error("toDOMStream() must be called with an Iterable or AsyncIterable")}function Ol(e,t){let i=null,r=t?.type==="bytes"||!1,n=t?.highWaterMark||Math.pow(2,24);return new ReadableStream(Object.assign(Object.assign({},t),{start(s){o(s,i||(i=e[Symbol.iterator]()))},pull(s){i?o(s,i):s.close()},cancel(){(i?.return&&i.return()||!0)&&(i=null)}}),Object.assign({highWaterMark:r?n:void 0},t));function o(s,a){let c,B=null,d=s.desiredSize||null;for(;!(B=a.next(r?d:null)).done;)if(ArrayBuffer.isView(B.value)&&(c=b(B.value))&&(d!=null&&r&&(d=d-c.byteLength+1),B.value=c),s.enqueue(B.value),d!=null&&--d<=0)return;s.close()}}function Dl(e,t){let i=null,r=t?.type==="bytes"||!1,n=t?.highWaterMark||Math.pow(2,24);return new ReadableStream(Object.assign(Object.assign({},t),{start(s){return f(this,void 0,void 0,function*(){yield o(s,i||(i=e[Symbol.asyncIterator]()))})},pull(s){return f(this,void 0,void 0,function*(){i?yield o(s,i):s.close()})},cancel(){return f(this,void 0,void 0,function*(){(i?.return&&(yield i.return())||!0)&&(i=null)})}}),Object.assign({highWaterMark:r?n:void 0},t));function o(s,a){return f(this,void 0,void 0,function*(){let c,B=null,d=s.desiredSize||null;for(;!(B=yield a.next(r?d:null)).done;)if(ArrayBuffer.isView(B.value)&&(c=b(B.value))&&(d!=null&&r&&(d=d-c.byteLength+1),B.value=c),s.enqueue(B.value),d!=null&&--d<=0)return;s.close()})}}function Bu(e){return new aa(e)}var aa=class{constructor(t){this._numChunks=0,this._finished=!1,this._bufferedSize=0;let{["readableStrategy"]:i,["writableStrategy"]:r,["queueingStrategy"]:n="count"}=t,o=Ma(t,["readableStrategy","writableStrategy","queueingStrategy"]);this._controller=null,this._builder=Xi(o),this._getSize=n!=="bytes"?cu:uu;let{["highWaterMark"]:s=n==="bytes"?Math.pow(2,14):1e3}=Object.assign({},i),{["highWaterMark"]:a=n==="bytes"?Math.pow(2,14):1e3}=Object.assign({},r);this.readable=new ReadableStream({cancel:()=>{this._builder.clear()},pull:c=>{this._maybeFlush(this._builder,this._controller=c)},start:c=>{this._maybeFlush(this._builder,this._controller=c)}},{highWaterMark:s,size:n!=="bytes"?cu:uu}),this.writable=new WritableStream({abort:()=>{this._builder.clear()},write:()=>{this._maybeFlush(this._builder,this._controller)},close:()=>{this._maybeFlush(this._builder.finish(),this._controller)}},{highWaterMark:a,size:c=>this._writeValueAndReturnChunkSize(c)})}_writeValueAndReturnChunkSize(t){let i=this._bufferedSize;return this._bufferedSize=this._getSize(this._builder.append(t)),this._bufferedSize-i}_maybeFlush(t,i){i!=null&&(this._bufferedSize>=i.desiredSize&&++this._numChunks&&this._enqueue(i,t.toVector()),t.finished&&((t.length>0||this._numChunks===0)&&++this._numChunks&&this._enqueue(i,t.toVector()),!this._finished&&(this._finished=!0)&&this._enqueue(i,null)))}_enqueue(t,i){this._bufferedSize=0,this._controller=null,i==null?t.close():t.enqueue(i)}},cu=e=>{var t;return(t=e?.length)!==null&&t!==void 0?t:0},uu=e=>{var t;return(t=e?.byteLength)!==null&&t!==void 0?t:0};function ko(e,t){let i=new Re,r=null,n=new ReadableStream({cancel(){return f(this,void 0,void 0,function*(){yield i.close()})},start(a){return f(this,void 0,void 0,function*(){yield s(a,r||(r=yield o()))})},pull(a){return f(this,void 0,void 0,function*(){r?yield s(a,r):a.close()})}});return{writable:new WritableStream(i,Object.assign({highWaterMark:Math.pow(2,14)},e)),readable:n};function o(){return f(this,void 0,void 0,function*(){return yield(yield Ot.from(i)).open(t)})}function s(a,c){return f(this,void 0,void 0,function*(){let B=a.desiredSize,d=null;for(;!(d=yield c.next()).done;)if(a.enqueue(d.value),B!=null&&--B<=0)return;a.close()})}}function qo(e,t){let i=new this(e),r=new zt(i),n=new ReadableStream({cancel(){return f(this,void 0,void 0,function*(){yield r.cancel()})},pull(s){return f(this,void 0,void 0,function*(){yield o(s)})},start(s){return f(this,void 0,void 0,function*(){yield o(s)})}},Object.assign({highWaterMark:Math.pow(2,14)},t));return{writable:new WritableStream(i,e),readable:n};function o(s){return f(this,void 0,void 0,function*(){let a=null,c=s.desiredSize;for(;a=yield r.read(c||null);)if(s.enqueue(a),c!=null&&(c-=a.byteLength)<=0)return;s.close()})}}function $o(e,t="stream"){return(t==="stream"?Gi:Wi).writeAll(e).toUint8Array(!0)}var vl=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},Ds),js),Gs),Fs),fs),_s),ws),{compareSchemas:Yi,compareFields:gc,compareTypes:Nc});ft.toDOMStream=au;q.throughDOM=Bu;Ot.throughDOM=ko;Oi.throughDOM=ko;be.throughDOM=ko;_i.throughDOM=qo;Wi.throughDOM=qo;Gi.throughDOM=qo;var Ml=Object.create,lu=Object.defineProperty,Cl=Object.getOwnPropertyDescriptor,Rl=Object.getOwnPropertyNames,pl=Object.getPrototypeOf,Ll=Object.prototype.hasOwnProperty,bl=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Xl=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Rl(t))!Ll.call(e,n)&&n!==i&&lu(e,n,{get:()=>t[n],enumerable:!(r=Cl(t,n))||r.enumerable});return e},Hl=(e,t,i)=>(i=e!=null?Ml(pl(e)):{},Xl(t||!e||!e.__esModule?lu(i,"default",{value:e,enumerable:!0}):i,e)),ml=bl((e,t)=>{t.exports=Worker}),Yl=(e=>(e[e.UNDEFINED=0]="UNDEFINED",e[e.AUTOMATIC=1]="AUTOMATIC",e[e.READ_ONLY=2]="READ_ONLY",e[e.READ_WRITE=3]="READ_WRITE",e))(Yl||{}),xl=(e=>(e[e.IDENTIFIER=0]="IDENTIFIER",e[e.NUMERIC_CONSTANT=1]="NUMERIC_CONSTANT",e[e.STRING_CONSTANT=2]="STRING_CONSTANT",e[e.OPERATOR=3]="OPERATOR",e[e.KEYWORD=4]="KEYWORD",e[e.COMMENT=5]="COMMENT",e))(xl||{}),_l=(e=>(e[e.NONE=0]="NONE",e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARNING=3]="WARNING",e[e.ERROR=4]="ERROR",e))(_l||{}),Gl=(e=>(e[e.NONE=0]="NONE",e[e.CONNECT=1]="CONNECT",e[e.DISCONNECT=2]="DISCONNECT",e[e.OPEN=3]="OPEN",e[e.QUERY=4]="QUERY",e[e.INSTANTIATE=5]="INSTANTIATE",e))(Gl||{}),Wl=(e=>(e[e.NONE=0]="NONE",e[e.OK=1]="OK",e[e.ERROR=2]="ERROR",e[e.START=3]="START",e[e.RUN=4]="RUN",e[e.CAPTURE=5]="CAPTURE",e))(Wl||{}),gl=(e=>(e[e.NONE=0]="NONE",e[e.WEB_WORKER=1]="WEB_WORKER",e[e.NODE_WORKER=2]="NODE_WORKER",e[e.BINDINGS=3]="BINDINGS",e[e.ASYNC_DUCKDB=4]="ASYNC_DUCKDB",e))(gl||{});var fu=class{constructor(e=2){this.level=e}log(e){e.level>=this.level&&console.log(e)}};var Nl=(e=>(e[e.SUCCESS=0]="SUCCESS",e))(Nl||{}),Tl=class{constructor(e,t){this._bindings=e,this._conn=t}get bindings(){return this._bindings}async close(){return this._bindings.disconnect(this._conn)}useUnsafe(e){return e(this._bindings,this._conn)}async query(e){this._bindings.logger.log({timestamp:new Date,level:2,origin:4,topic:4,event:4,value:e});let t=await this._bindings.runQuery(this._conn,e),i=Ot.from(t);return console.assert(i.isSync(),"Reader is not sync"),console.assert(i.isFile(),"Reader is not file"),new Mt(i)}async send(e){this._bindings.logger.log({timestamp:new Date,level:2,origin:4,topic:4,event:4,value:e});let t=await this._bindings.startPendingQuery(this._conn,e);for(;t==null;)t=await this._bindings.pollPendingQuery(this._conn);let i=new hu(this._bindings,this._conn,t),r=await Ot.from(i);return console.assert(r.isAsync()),console.assert(r.isStream()),r}async cancelSent(){return await this._bindings.cancelPendingQuery(this._conn)}async getTableNames(e){return await this._bindings.getTableNames(this._conn,e)}async prepare(e){let t=await this._bindings.createPrepared(this._conn,e);return new Zl(this._bindings,this._conn,t)}async insertArrowTable(e,t){let i=$o(e,"stream");await this.insertArrowFromIPCStream(i,t)}async insertArrowFromIPCStream(e,t){await this._bindings.insertArrowFromIPCStream(this._conn,e,t)}async insertCSVFromPath(e,t){await this._bindings.insertCSVFromPath(this._conn,e,t)}async insertJSONFromPath(e,t){await this._bindings.insertJSONFromPath(this._conn,e,t)}},hu=class{constructor(e,t,i){this.db=e,this.conn=t,this.header=i,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}},Zl=class{constructor(e,t,i){this.bindings=e,this.connectionId=t,this.statementId=i}async close(){await this.bindings.closePrepared(this.connectionId,this.statementId)}async query(...e){let t=await this.bindings.runPrepared(this.connectionId,this.statementId,e),i=Ot.from(t);return console.assert(i.isSync()),console.assert(i.isFile()),new Mt(i)}async send(...e){let t=await this.bindings.sendPrepared(this.connectionId,this.statementId,e),i=new hu(this.bindings,this.connectionId,t),r=await Ot.from(i);return console.assert(r.isAsync()),console.assert(r.isStream()),r}},Sl=(e=>(e.CANCEL_PENDING_QUERY="CANCEL_PENDING_QUERY",e.CLOSE_PREPARED="CLOSE_PREPARED",e.COLLECT_FILE_STATISTICS="COLLECT_FILE_STATISTICS",e.CONNECT="CONNECT",e.COPY_FILE_TO_BUFFER="COPY_FILE_TO_BUFFER",e.COPY_FILE_TO_PATH="COPY_FILE_TO_PATH",e.CREATE_PREPARED="CREATE_PREPARED",e.DISCONNECT="DISCONNECT",e.DROP_FILE="DROP_FILE",e.DROP_FILES="DROP_FILES",e.EXPORT_FILE_STATISTICS="EXPORT_FILE_STATISTICS",e.FETCH_QUERY_RESULTS="FETCH_QUERY_RESULTS",e.FLUSH_FILES="FLUSH_FILES",e.GET_FEATURE_FLAGS="GET_FEATURE_FLAGS",e.GET_TABLE_NAMES="GET_TABLE_NAMES",e.GET_VERSION="GET_VERSION",e.GLOB_FILE_INFOS="GLOB_FILE_INFOS",e.INSERT_ARROW_FROM_IPC_STREAM="INSERT_ARROW_FROM_IPC_STREAM",e.INSERT_CSV_FROM_PATH="IMPORT_CSV_FROM_PATH",e.INSERT_JSON_FROM_PATH="IMPORT_JSON_FROM_PATH",e.INSTANTIATE="INSTANTIATE",e.OPEN="OPEN",e.PING="PING",e.POLL_PENDING_QUERY="POLL_PENDING_QUERY",e.REGISTER_FILE_BUFFER="REGISTER_FILE_BUFFER",e.REGISTER_FILE_HANDLE="REGISTER_FILE_HANDLE",e.REGISTER_FILE_URL="REGISTER_FILE_URL",e.RESET="RESET",e.RUN_PREPARED="RUN_PREPARED",e.RUN_QUERY="RUN_QUERY",e.SEND_PREPARED="SEND_PREPARED",e.START_PENDING_QUERY="START_PENDING_QUERY",e.TOKENIZE="TOKENIZE",e))(Sl||{}),Ul=(e=>(e.CONNECTION_INFO="CONNECTION_INFO",e.ERROR="ERROR",e.FEATURE_FLAGS="FEATURE_FLAGS",e.FILE_BUFFER="FILE_BUFFER",e.FILE_INFOS="FILE_INFOS",e.FILE_SIZE="FILE_SIZE",e.FILE_STATISTICS="FILE_STATISTICS",e.INSTANTIATE_PROGRESS="INSTANTIATE_PROGRESS",e.LOG="LOG",e.OK="OK",e.PREPARED_STATEMENT_ID="PREPARED_STATEMENT_ID",e.QUERY_PLAN="QUERY_PLAN",e.QUERY_RESULT="QUERY_RESULT",e.QUERY_RESULT_CHUNK="QUERY_RESULT_CHUNK",e.QUERY_RESULT_HEADER="QUERY_RESULT_HEADER",e.QUERY_RESULT_HEADER_OR_NULL="QUERY_RESULT_HEADER_OR_NULL",e.REGISTERED_FILE="REGISTERED_FILE",e.SCRIPT_TOKENS="SCRIPT_TOKENS",e.SUCCESS="SUCCESS",e.TABLE_NAMES="TABLE_NAMES",e.VERSION_STRING="VERSION_STRING",e))(Ul||{}),T=class{constructor(e,t){this.promiseResolver=()=>{},this.promiseRejecter=()=>{},this.type=e,this.data=t,this.promise=new Promise((i,r)=>{this.promiseResolver=i,this.promiseRejecter=r})}};function Ao(e){switch(e.typeId){case u.Binary:return{sqlType:"binary"};case u.Bool:return{sqlType:"bool"};case u.Date:return{sqlType:"date"};case u.DateDay:return{sqlType:"date32[d]"};case u.DateMillisecond:return{sqlType:"date64[ms]"};case u.Decimal:{let t=e;return{sqlType:"decimal",precision:t.precision,scale:t.scale}}case u.Float:return{sqlType:"float"};case u.Float16:return{sqlType:"float16"};case u.Float32:return{sqlType:"float32"};case u.Float64:return{sqlType:"float64"};case u.Int:return{sqlType:"int32"};case u.Int16:return{sqlType:"int16"};case u.Int32:return{sqlType:"int32"};case u.Int64:return{sqlType:"int64"};case u.Uint16:return{sqlType:"uint16"};case u.Uint32:return{sqlType:"uint32"};case u.Uint64:return{sqlType:"uint64"};case u.Uint8:return{sqlType:"uint8"};case u.IntervalDayTime:return{sqlType:"interval[dt]"};case u.IntervalYearMonth:return{sqlType:"interval[m]"};case u.List:return{sqlType:"list",valueType:Ao(e.valueType)};case u.FixedSizeBinary:return{sqlType:"fixedsizebinary",byteWidth:e.byteWidth};case u.Null:return{sqlType:"null"};case u.Utf8:return{sqlType:"utf8"};case u.Struct:return{sqlType:"struct",fields:e.children.map(t=>ca(t.name,t.type))};case u.Map:{let t=e;return{sqlType:"map",keyType:Ao(t.keyType),valueType:Ao(t.valueType)}}case u.Time:return{sqlType:"time[s]"};case u.TimeMicrosecond:return{sqlType:"time[us]"};case u.TimeMillisecond:return{sqlType:"time[ms]"};case u.TimeNanosecond:return{sqlType:"time[ns]"};case u.TimeSecond:return{sqlType:"time[s]"};case u.Timestamp:return{sqlType:"timestamp",timezone:e.timezone||void 0};case u.TimestampSecond:return{sqlType:"timestamp[s]",timezone:e.timezone||void 0};case u.TimestampMicrosecond:return{sqlType:"timestamp[us]",timezone:e.timezone||void 0};case u.TimestampNanosecond:return{sqlType:"timestamp[ns]",timezone:e.timezone||void 0};case u.TimestampMillisecond:return{sqlType:"timestamp[ms]",timezone:e.timezone||void 0}}throw new Error("unsupported arrow type: ".concat(e.toString()))}function ca(e,t){let i=Ao(t);return i.name=e,i}var Jl=new TextEncoder,yu=class{constructor(e,t=null){this._onInstantiationProgress=[],this._worker=null,this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{},this._nextMessageId=0,this._pendingRequests=new Map,this._logger=e,this._onMessageHandler=this.onMessage.bind(this),this._onErrorHandler=this.onError.bind(this),this._onCloseHandler=this.onClose.bind(this),t!=null&&this.attach(t)}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((t,i)=>{this._workerShutdownResolver=t})}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,t=[]){if(!this._worker){console.error("cannot send a message since the worker is not set!");return}let i=this._nextMessageId++;return this._pendingRequests.set(i,e),this._worker.postMessage({messageId:i,type:e.type,data:e.data},t),await e.promise}onMessage(e){var t;let i=e.data;switch(i.type){case"LOG":{this._logger.log(i.data);return}case"INSTANTIATE_PROGRESS":{for(let n of this._onInstantiationProgress)n(i.data);return}}let r=this._pendingRequests.get(i.requestId);if(!r){console.warn("unassociated response: [".concat(i.requestId,", ").concat(i.type.toString(),"]"));return}if(this._pendingRequests.delete(i.requestId),i.type=="ERROR"){let n=new Error(i.data.message);n.name=i.data.name,(t=Object.getOwnPropertyDescriptor(n,"stack"))!=null&&t.writable&&(n.stack=i.data.stack),r.promiseRejecter(n);return}switch(r.type){case"CLOSE_PREPARED":case"COLLECT_FILE_STATISTICS":case"COPY_FILE_TO_PATH":case"DISCONNECT":case"DROP_FILE":case"DROP_FILES":case"FLUSH_FILES":case"INSERT_ARROW_FROM_IPC_STREAM":case"IMPORT_CSV_FROM_PATH":case"IMPORT_JSON_FROM_PATH":case"OPEN":case"PING":case"REGISTER_FILE_BUFFER":case"REGISTER_FILE_HANDLE":case"REGISTER_FILE_URL":case"RESET":if(i.type=="OK"){r.promiseResolver(i.data);return}break;case"INSTANTIATE":if(this._onInstantiationProgress=[],i.type=="OK"){r.promiseResolver(i.data);return}break;case"GLOB_FILE_INFOS":if(i.type=="FILE_INFOS"){r.promiseResolver(i.data);return}break;case"GET_VERSION":if(i.type=="VERSION_STRING"){r.promiseResolver(i.data);return}break;case"GET_FEATURE_FLAGS":if(i.type=="FEATURE_FLAGS"){r.promiseResolver(i.data);return}break;case"GET_TABLE_NAMES":if(i.type=="TABLE_NAMES"){r.promiseResolver(i.data);return}break;case"TOKENIZE":if(i.type=="SCRIPT_TOKENS"){r.promiseResolver(i.data);return}break;case"COPY_FILE_TO_BUFFER":if(i.type=="FILE_BUFFER"){r.promiseResolver(i.data);return}break;case"EXPORT_FILE_STATISTICS":if(i.type=="FILE_STATISTICS"){r.promiseResolver(i.data);return}break;case"CONNECT":if(i.type=="CONNECTION_INFO"){r.promiseResolver(i.data);return}break;case"RUN_PREPARED":case"RUN_QUERY":if(i.type=="QUERY_RESULT"){r.promiseResolver(i.data);return}break;case"SEND_PREPARED":if(i.type=="QUERY_RESULT_HEADER"){r.promiseResolver(i.data);return}break;case"START_PENDING_QUERY":if(i.type=="QUERY_RESULT_HEADER_OR_NULL"){r.promiseResolver(i.data);return}break;case"POLL_PENDING_QUERY":if(i.type=="QUERY_RESULT_HEADER_OR_NULL"){r.promiseResolver(i.data);return}break;case"CANCEL_PENDING_QUERY":if(this._onInstantiationProgress=[],i.type=="SUCCESS"){r.promiseResolver(i.data);return}break;case"FETCH_QUERY_RESULTS":if(i.type=="QUERY_RESULT_CHUNK"){r.promiseResolver(i.data);return}break;case"CREATE_PREPARED":if(i.type=="PREPARED_STATEMENT_ID"){r.promiseResolver(i.data);return}break}r.promiseRejecter(new Error("unexpected response type: ".concat(i.type.toString())))}onError(e){console.error(e),console.error("error in duckdb worker: ".concat(e.message)),this._pendingRequests.clear()}onClose(){if(this._workerShutdownResolver(null),this._pendingRequests.size!=0){console.warn("worker terminated with ".concat(this._pendingRequests.size," pending requests"));return}this._pendingRequests.clear()}async reset(){let e=new T("RESET",null);return await this.postTask(e)}async ping(){let e=new T("PING",null);await this.postTask(e)}async dropFile(e){let t=new T("DROP_FILE",e);return await this.postTask(t)}async dropFiles(){let e=new T("DROP_FILES",null);return await this.postTask(e)}async flushFiles(){let e=new T("FLUSH_FILES",null);return await this.postTask(e)}async instantiate(e,t=null,i=r=>{}){this._onInstantiationProgress.push(i);let r=new T("INSTANTIATE",[e,t]);return await this.postTask(r)}async getVersion(){let e=new T("GET_VERSION",null);return await this.postTask(e)}async getFeatureFlags(){let e=new T("GET_FEATURE_FLAGS",null);return await this.postTask(e)}async open(e){let t=new T("OPEN",e);await this.postTask(t)}async tokenize(e){let t=new T("TOKENIZE",e);return await this.postTask(t)}async connectInternal(){let e=new T("CONNECT",null);return await this.postTask(e)}async connect(){let e=await this.connectInternal();return new Tl(this,e)}async disconnect(e){let t=new T("DISCONNECT",e);await this.postTask(t)}async runQuery(e,t){let i=new T("RUN_QUERY",[e,t]);return await this.postTask(i)}async startPendingQuery(e,t){let i=new T("START_PENDING_QUERY",[e,t]);return await this.postTask(i)}async pollPendingQuery(e){let t=new T("POLL_PENDING_QUERY",e);return await this.postTask(t)}async cancelPendingQuery(e){let t=new T("CANCEL_PENDING_QUERY",e);return await this.postTask(t)}async fetchQueryResults(e){let t=new T("FETCH_QUERY_RESULTS",e);return await this.postTask(t)}async getTableNames(e,t){let i=new T("GET_TABLE_NAMES",[e,t]);return await this.postTask(i)}async createPrepared(e,t){let i=new T("CREATE_PREPARED",[e,t]);return await this.postTask(i)}async closePrepared(e,t){let i=new T("CLOSE_PREPARED",[e,t]);await this.postTask(i)}async runPrepared(e,t,i){let r=new T("RUN_PREPARED",[e,t,i]);return await this.postTask(r)}async sendPrepared(e,t,i){let r=new T("SEND_PREPARED",[e,t,i]);return await this.postTask(r)}async globFiles(e){let t=new T("GLOB_FILE_INFOS",e);return await this.postTask(t)}async registerFileText(e,t){let i=Jl.encode(t);await this.registerFileBuffer(e,i)}async registerFileURL(e,t,i,r){t===void 0&&(t=e);let n=new T("REGISTER_FILE_URL",[e,t,i,r]);await this.postTask(n)}async registerEmptyFileBuffer(e){let t=new T("REGISTER_FILE_BUFFER",[e,new Uint8Array]);await this.postTask(t)}async registerFileBuffer(e,t){let i=new T("REGISTER_FILE_BUFFER",[e,t]);await this.postTask(i,[t.buffer])}async registerFileHandle(e,t,i,r){let n=new T("REGISTER_FILE_HANDLE",[e,t,i,r]);await this.postTask(n,[])}async collectFileStatistics(e,t){let i=new T("COLLECT_FILE_STATISTICS",[e,t]);await this.postTask(i,[])}async exportFileStatistics(e){let t=new T("EXPORT_FILE_STATISTICS",e);return await this.postTask(t,[])}async copyFileToBuffer(e){let t=new T("COPY_FILE_TO_BUFFER",e);return await this.postTask(t)}async copyFileToPath(e,t){let i=new T("COPY_FILE_TO_PATH",[e,t]);await this.postTask(i)}async insertArrowFromIPCStream(e,t,i){if(t.length==0)return;let r=new T("INSERT_ARROW_FROM_IPC_STREAM",[e,t,i]);await this.postTask(r,[t.buffer])}async insertCSVFromPath(e,t,i){if(i.columns!==void 0){let n=[];for(let o in i.columns){let s=i.columns[o];n.push(ca(o,s))}i.columnsFlat=n,delete i.columns}let r=new T("IMPORT_CSV_FROM_PATH",[e,t,i]);await this.postTask(r)}async insertJSONFromPath(e,t,i){if(i.columns!==void 0){let n=[];for(let o in i.columns){let s=i.columns[o];n.push(ca(o,s))}i.columnsFlat=n,delete i.columns}let r=new T("IMPORT_JSON_FROM_PATH",[e,t,i]);await this.postTask(r)}};var ua={name:"@duckdb/duckdb-wasm",version:"1.28.1-dev106.0",description:"DuckDB powered by WebAssembly",license:"MIT",repository:{type:"git",url:"https://github.com/duckdb/duckdb-wasm.git"},keywords:["sql","duckdb","relational","database","data","query","wasm","analytics","olap","arrow","parquet","json","csv"],dependencies:{"apache-arrow":"^14.0.1"},devDependencies:{"@types/emscripten":"^1.39.10","@types/jasmine":"^5.1.4","@typescript-eslint/eslint-plugin":"^6.18.0","@typescript-eslint/parser":"^6.18.0",esbuild:"^0.20.0",eslint:"^8.56.0","eslint-plugin-jasmine":"^4.1.3","eslint-plugin-react":"^7.33.2","fast-glob":"^3.3.2",jasmine:"^5.1.0","jasmine-core":"^5.1.1","jasmine-spec-reporter":"^7.0.0","js-sha256":"^0.11.0",karma:"^6.4.2","karma-chrome-launcher":"^3.2.0","karma-coverage":"^2.2.1","karma-firefox-launcher":"^2.1.2","karma-jasmine":"^5.1.0","karma-jasmine-html-reporter":"^2.1.0","karma-sourcemap-loader":"^0.4.0","karma-spec-reporter":"^0.0.36","make-dir":"^4.0.0",nyc:"^15.1.0",prettier:"^3.2.4",puppeteer:"^21.7.0",rimraf:"^5.0.5",s3rver:"^3.7.1",typedoc:"^0.25.7",typescript:"^5.3.3","wasm-feature-detect":"^1.6.1","web-worker":"^1.2.0"},scripts:{"build:debug":"node bundle.mjs debug && tsc --emitDeclarationOnly","build:release":"node bundle.mjs release && tsc --emitDeclarationOnly",docs:"typedoc",report:"node ./coverage.mjs","test:node":"node --enable-source-maps ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs","test:node:debug":"node --inspect-brk --enable-source-maps ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs","test:node:coverage":"nyc -r json --report-dir ./coverage/node node ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs","test:firefox":"karma start ./karma/tests-firefox.cjs","test:chrome":"karma start ./karma/tests-chrome.cjs","test:chrome:eh":"karma start ./karma/tests-chrome-eh.cjs","test:chrome:coverage":"karma start ./karma/tests-chrome-coverage.cjs","test:browser":"karma start ./karma/tests-all.cjs","test:browser:debug":"karma start ./karma/tests-debug.cjs",test:"npm run test:chrome && npm run test:node","test:coverage":"npm run test:chrome:coverage && npm run test:node:coverage && npm run report",lint:"eslint src test"},files:["dist","!dist/types/test"],main:"dist/duckdb-browser.cjs",module:"dist/duckdb-browser.mjs",types:"dist/duckdb-browser.d.ts",jsdelivr:"dist/duckdb-browser.cjs",unpkg:"dist/duckdb-browser.mjs",sideEffects:!1,browser:{fs:!1,path:!1,perf_hooks:!1,os:!1,worker_threads:!1},exports:{"./dist/duckdb-mvp.wasm":"./dist/duckdb-mvp.wasm","./dist/duckdb-eh.wasm":"./dist/duckdb-eh.wasm","./dist/duckdb-coi.wasm":"./dist/duckdb-coi.wasm","./dist/duckdb-browser":"./dist/duckdb-browser.mjs","./dist/duckdb-browser.cjs":"./dist/duckdb-browser.cjs","./dist/duckdb-browser.mjs":"./dist/duckdb-browser.mjs","./dist/duckdb-browser-blocking":"./dist/duckdb-browser-blocking.mjs","./dist/duckdb-browser-blocking.mjs":"./dist/duckdb-browser-blocking.mjs","./dist/duckdb-browser-blocking.cjs":"./dist/duckdb-browser-blocking.cjs","./dist/duckdb-browser-coi.pthread.worker.js":"./dist/duckdb-browser-coi.pthread.worker.js","./dist/duckdb-browser-coi.worker.js":"./dist/duckdb-browser-coi.worker.js","./dist/duckdb-browser-eh.worker.js":"./dist/duckdb-browser-eh.worker.js","./dist/duckdb-browser-mvp.worker.js":"./dist/duckdb-browser-mvp.worker.js","./dist/duckdb-node":"./dist/duckdb-node.cjs","./dist/duckdb-node.cjs":"./dist/duckdb-node.cjs","./dist/duckdb-node-blocking":"./dist/duckdb-node-blocking.cjs","./dist/duckdb-node-blocking.cjs":"./dist/duckdb-node-blocking.cjs","./dist/duckdb-node-eh.worker.cjs":"./dist/duckdb-node-eh.worker.cjs","./dist/duckdb-node-mvp.worker.cjs":"./dist/duckdb-node-mvp.worker.cjs","./blocking":{browser:{types:"./dist/duckdb-browser-blocking.d.ts",import:"./dist/duckdb-browser-blocking.mjs",require:"./dist/duckdb-browser-blocking.cjs"},node:{types:"./dist/duckdb-node-blocking.d.ts",require:"./dist/duckdb-node-blocking.cjs",import:"./dist/duckdb-node-blocking.cjs"},types:"./dist/duckdb-browser-blocking.d.ts",import:"./dist/duckdb-browser-blocking.mjs",require:"./dist/duckdb-browser-blocking.cjs"},".":{browser:{types:"./dist/duckdb-browser.d.ts",import:"./dist/duckdb-browser.mjs",require:"./dist/duckdb-browser.cjs"},node:{types:"./dist/duckdb-node.d.ts",import:"./dist/duckdb-node.cjs",require:"./dist/duckdb-node.cjs"},types:"./dist/duckdb-browser.d.ts",import:"./dist/duckdb-browser.mjs",require:"./dist/duckdb-browser.cjs"}}},cv=ua.name,uv=ua.version,Ba=ua.version.split("."),Bv=Ba[0],dv=Ba[1],lv=Ba[2];var fv=Hl(ml());function jl(){let e=new TextDecoder;return t=>(typeof SharedArrayBuffer<"u"&&t.buffer instanceof SharedArrayBuffer&&(t=new Uint8Array(t)),e.decode(t))}var hv=jl(),Pl=(e=>(e[e.BUFFER=0]="BUFFER",e[e.NODE_FS=1]="NODE_FS",e[e.BROWSER_FILEREADER=2]="BROWSER_FILEREADER",e[e.BROWSER_FSACCESS=3]="BROWSER_FSACCESS",e[e.HTTP=4]="HTTP",e[e.S3=5]="S3",e))(Pl||{});var da=class e{constructor(t,i){this._version=i;this.db=t}db;static load(){let t=URL.createObjectURL(new Blob([Ea()],{type:"text/javascript"})),i=new Worker(t);URL.revokeObjectURL(t);let r=new fu,n=new yu(r,i),o=URL.createObjectURL(new Blob([Ia()],{type:"application/wasm"}));return n.instantiate(o,null).then(async()=>(URL.revokeObjectURL(o),new e(n,await n.getVersion())))}static unload(){}version(){return this._version}};return Eu(zl);})();
11
- //# sourceMappingURL=duckdb.umd.js.map