import{N as q}from"./util-CNqBjtt6-GUXK7Yxz.js";import"./inherits_browser-nmOknR35-Bp0mvRSL.js";import"./index-69shuAsh-DF18H7zf.js";import"./_commonjsHelpers-B4e78b8K-W3E8ocG7.js";var p,d;function w(){if(d)return p;d=1;const c=q();class i{constructor(e,r){typeof e=="string"?this.#t(e):r!==void 0?this.#r(e,r):this.#e(e)}toPostgres(){const e=this.values,r=this.indices.map((s,n)=>c.format("%i:%f",s+1,e[n])).join(",");return c.format("{%s}/%d",r,this.dimensions)}toString(){return this.toPostgres()}toArray(){const e=Array(this.dimensions).fill(0);for(const[r,s]of this.indices.entries())e[s]=this.values[r];return e}#t(e){const r=e.split("/",2);this.dimensions=parseInt(r[1]),this.indices=[],this.values=[];const s=r[0].slice(1,-1).split(",");for(const n of s){const o=n.split(":",2);this.indices.push(parseInt(o[0])-1),this.values.push(parseFloat(o[1]))}}#e(e){this.dimensions=e.length,this.indices=[],this.values=[];for(const[r,s]of e.entries()){const n=Number(s);n!=0&&(this.indices.push(Number(r)),this.values.push(n))}}#r(e,r){this.dimensions=Number(r),this.indices=[],this.values=[];const s=e instanceof Map?e.entries():Object.entries(e);for(const[n,o]of s){const a=Number(o);a!=0&&(this.indices.push(Number(n)),this.values.push(a))}}}return p={SparseVector:i},p}var h,S;function A(){if(S)return h;S=1;const c=q(),{SparseVector:i}=w();function l(t){return t===null?null:t.substring(1,t.length-1).split(",").map(u=>parseFloat(u))}function e(t){return Array.isArray(t)?JSON.stringify(t.map(u=>Number(u))):t}const r=l,s=e;function n(t){return t===null?null:new i(t)}function o(t){return t instanceof i?t.toPostgres():t}function a(t){if(t===null)return null;if(t[0]=="[")return l(t);if(t[0]=="{")return n(t);throw new Error("invalid text representation")}function b(t){if(t===null)return null;if(Array.isArray(t))return e(t);if(t instanceof i)return o(t);throw new Error("expected array or sparse vector")}function f(t,u){if(u==null)return t;if(!Number.isInteger(u))throw new Error("expected integer");return c.format("%s(%d)",t,u)}function v(t){return f("vector",t)}function g(t){return f("halfvec",t)}function N(t){return f("bit",t)}function T(t){return f("sparsevec",t)}return h={fromSql:a,toSql:b,vectorFromSql:l,vectorToSql:e,halfvecFromSql:r,halfvecToSql:s,sparsevecFromSql:n,sparsevecToSql:o,sqlType:v,vectorType:v,halfvecType:g,bitType:N,sparsevecType:T,SparseVector:i},h}var m,y;function F(){if(y)return m;y=1;const{fromSql:c,toSql:i,SparseVector:l}=A();return m={fromSql:c,toSql:i,SparseVector:l},m}F();
