@influxdata/influxdb3-client
Version:
The Client that provides a simple and convenient way to interact with InfluxDB 3.
6 lines • 285 kB
JavaScript
"use strict";var influxdb=(()=>{var Jn=Object.defineProperty;var Zf=Object.getOwnPropertyDescriptor;var Qf=Object.getOwnPropertyNames;var td=Object.prototype.hasOwnProperty;var ed=(r,t,e)=>t in r?Jn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var Ue=(r,t)=>{for(var e in t)Jn(r,e,{get:t[e],enumerable:!0})},rd=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Qf(t))!td.call(r,n)&&n!==e&&Jn(r,n,{get:()=>t[n],enumerable:!(i=Zf(t,n))||i.enumerable});return r};var id=r=>rd(Jn({},"__esModule",{value:!0}),r);var z=(r,t,e)=>ed(r,typeof t!="symbol"?t+"":t,e);var im={};Ue(im,{AbortError:()=>Li,DEFAULT_ConnectionOptions:()=>ra,DEFAULT_QueryOptions:()=>Kn,DEFAULT_WriteOptions:()=>ia,GetFieldTypeMissmatchError:()=>Yn,HttpError:()=>re,IllegalArgumentError:()=>ur,InfluxDBClient:()=>qn,Log:()=>Nr,Point:()=>Ui,PointValues:()=>fr,RequestTimedOutError:()=>ta,collectAll:()=>wl,consoleLogger:()=>cl,convertTime:()=>ha,convertTimeToNanos:()=>da,createTextDecoderCombiner:()=>ea,currentTime:()=>ml,dateToProtocolTimestamp:()=>yl,escape:()=>Er,fromConnectionString:()=>na,fromEnv:()=>sa,isNumber:()=>ri,parsePrecision:()=>ca,precisionToV2ApiString:()=>oa,precisionToV3ApiString:()=>aa,setLogger:()=>sd,useProcessHrtime:()=>pl,writableDataToLineProtocol:()=>pa});function nd(r){if(!r||typeof r!="object"||Array.isArray(r))return;let t=typeof r.message=="string"?r.message:void 0;if(t)return t;let e=typeof r.error=="string"?r.error:void 0,i=r.data;if(e&&Array.isArray(i)){let n=[];for(let s of i){if(!s||typeof s!="object"||Array.isArray(s))continue;let o=s.line_number,a=s.error_message,c=s.original_line;o!=null&&typeof a=="string"&&a.length>0&&typeof c=="string"&&c.length>0?n.push(` line ${o}: ${a} (${c})`):typeof a=="string"&&a.length>0&&n.push(` ${a}`)}return n.length?`${e}:
${n.join(`
`)}`:e}if(i&&typeof i=="object"&&!Array.isArray(i)){let n=i.error_message;if(typeof n=="string"&&n.length>0)return n}if(e)return e}var ur=class r extends Error{constructor(t){super(t),this.name="IllegalArgumentError",Object.setPrototypeOf(this,r.prototype)}},re=class r extends Error{constructor(e,i,n,s,o,a){var c;super();this.statusCode=e;this.statusMessage=i;this.body=n;this.contentType=s;this.headers=o;z(this,"code");z(this,"json");if(Object.setPrototypeOf(this,r.prototype),a)this.message=a;else if(n&&(s!=null&&s.startsWith("application/json")||!s))try{this.json=JSON.parse(n),typeof((c=this.json)==null?void 0:c.code)=="string"&&(this.code=this.json.code);let l=nd(this.json);l&&(this.message=l)}catch(l){}this.message||(this.message=`${e} ${i} : ${n}`),this.name="HttpError"}statusCode;statusMessage;body;contentType;headers},ta=class r extends Error{constructor(){super(),Object.setPrototypeOf(this,r.prototype),this.name="RequestTimedOutError",this.message="Request timed out"}},Li=class r extends Error{constructor(){super(),this.name="AbortError",Object.setPrototypeOf(this,r.prototype),this.message="Response aborted"}};function ea(){let r=new TextDecoder("utf-8");return{concat(t,e){let i=new Uint8Array(t.length+e.length);return i.set(t),i.set(e,t.length),i},copy(t,e,i){let n=new Uint8Array(i-e);return n.set(t.subarray(e,i)),n},toUtf8String(t,e,i){return r.decode(t.subarray(e,i))}}}var ra={timeout:void 0,writeTimeout:1e4,queryTimeout:6e4},ia={precision:"ns",gzipThreshold:1e3,noSync:!1},Kn={type:"sql"};function na(r){if(!r)throw Error("Connection string not set!");let t=new URL(r.trim(),"http://localhost"),e={host:r.indexOf("://")>0?t.origin+t.pathname:t.pathname};return t.searchParams.has("token")&&(e.token=t.searchParams.get("token")),t.searchParams.has("authScheme")&&(e.authScheme=t.searchParams.get("authScheme")),t.searchParams.has("database")&&(e.database=t.searchParams.get("database")),t.searchParams.has("timeout")&&(e.timeout=parseInt(t.searchParams.get("timeout"))),t.searchParams.has("precision")&&(e.writeOptions||(e.writeOptions={}),e.writeOptions.precision=ca(t.searchParams.get("precision"))),t.searchParams.has("gzipThreshold")&&(e.writeOptions||(e.writeOptions={}),e.writeOptions.gzipThreshold=parseInt(t.searchParams.get("gzipThreshold"))),t.searchParams.has("writeNoSync")&&(e.writeOptions||(e.writeOptions={}),e.writeOptions.noSync=al(t.searchParams.get("writeNoSync"))),e}function sa(){if(!process.env.INFLUX_HOST)throw Error("INFLUX_HOST variable not set!");if(!process.env.INFLUX_TOKEN)throw Error("INFLUX_TOKEN variable not set!");let r={host:process.env.INFLUX_HOST.trim()};if(process.env.INFLUX_TOKEN&&(r.token=process.env.INFLUX_TOKEN.trim()),process.env.INFLUX_AUTH_SCHEME&&(r.authScheme=process.env.INFLUX_AUTH_SCHEME.trim()),process.env.INFLUX_DATABASE&&(r.database=process.env.INFLUX_DATABASE.trim()),process.env.INFLUX_TIMEOUT&&(r.timeout=parseInt(process.env.INFLUX_TIMEOUT.trim())),process.env.INFLUX_PRECISION&&(r.writeOptions||(r.writeOptions={}),r.writeOptions.precision=ca(process.env.INFLUX_PRECISION)),process.env.INFLUX_GZIP_THRESHOLD&&(r.writeOptions||(r.writeOptions={}),r.writeOptions.gzipThreshold=parseInt(process.env.INFLUX_GZIP_THRESHOLD)),process.env.INFLUX_WRITE_NO_SYNC&&(r.writeOptions||(r.writeOptions={}),r.writeOptions.noSync=al(process.env.INFLUX_WRITE_NO_SYNC)),process.env.INFLUX_GRPC_OPTIONS){let t=process.env.INFLUX_GRPC_OPTIONS.split(",");r.grpcOptions||(r.grpcOptions={});for(let e of t){let i=e.split("=");if(i.length!=2)continue;let n=parseInt(i[1]);Number.isNaN(n)&&(n=parseFloat(i[1]),Number.isNaN(n)&&(n=i[1])),r.grpcOptions[i[0]]=n}}return r}function al(r){return["true","1","t","y","yes"].includes(r.trim().toLowerCase())}function oa(r){switch(r){case"ns":case"us":case"ms":case"s":return r;default:throw Error(`Unsupported precision '${r}'`)}}function aa(r){switch(r){case"ns":return"nanosecond";case"us":return"microsecond";case"ms":return"millisecond";case"s":return"second";default:throw Error(`Unsupported precision '${r}'`)}}function ca(r){switch(r.trim().toLowerCase()){case"ns":case"nanosecond":return"ns";case"us":case"microsecond":return"us";case"ms":case"millisecond":return"ms";case"s":case"second":return"s";default:throw Error(`Unsupported precision '${r}'`)}}var cl={error(r,t){console.error(`ERROR: ${r}`,t||"")},warn(r,t){console.warn(`WARN: ${r}`,t||"")}},Xn=cl,Nr={error(r,t){Xn.error(r,t)},warn(r,t){Xn.warn(r,t)}};function sd(r){let t=Xn;return Xn=r,t}function la(r,t){return function(e){let i="",n=0,s=0;for(;s<e.length;){let o=r.indexOf(e[s]);o>=0&&(i+=e.substring(n,s),i+=t[o],n=s+1),s++}return n==0?e:(n<e.length&&(i+=e.substring(n,e.length)),i)}}function od(r,t){let e=la(r,t);return i=>`"${e(i)}"`}var Er={measurement:la(`,
\r `,["\\,","\\ ","\\n","\\r","\\t"]),quoted:od('"\\',['\\"',"\\\\"]),tag:la(`, =
\r `,["\\,","\\ ","\\=","\\n","\\r","\\t"])};var hl="000000000";function pl(r){return!1}pl(!0);var ll=Date.now(),ua=0;function fa(){{let r=Date.now();r!==ll?(ll=r,ua=0):ua++;let t=String(ua);return String(r)+hl.substr(0,6-t.length)+t}}function ul(){return String(Date.now())+hl.substr(0,3)}function fl(){return String(Date.now())}function dl(){return String(Math.floor(Date.now()/1e3))}var ml={s:dl,ms:fl,us:ul,ns:fa,seconds:dl,millis:fl,micros:ul,nanos:fa},yl={s:r=>`${Math.floor(r.getTime()/1e3)}`,ms:r=>`${r.getTime()}`,us:r=>`${r.getTime()}000`,ns:r=>`${r.getTime()}000000`};function da(r){return r===void 0?fa():typeof r=="string"?r.length>0?r:void 0:r instanceof Date?`${r.getTime()}000000`:String(typeof r=="number"?Math.floor(r):r)}var ha=(r,t="ns")=>r===void 0?ml[t]():typeof r=="string"?r.length>0?r:void 0:r instanceof Date?yl[t](r):String(typeof r=="number"?Math.floor(r):r);var ei=r=>{throw r},gl=r=>r!==void 0,bl=r=>r instanceof Array||r instanceof Object&&typeof r.length=="number"&&(r.length===0||Object.getOwnPropertyNames(r).some(t=>t==="0")),_l=r=>{let t=new Uint8Array(4);return t[0]=r>>0,t[1]=r>>8,t[2]=r>>16,t[3]=r>>24,t},wl=async r=>{let t=[];for await(let e of r)t.push(e);return t},ri=r=>r===null||typeof r=="string"&&(r===""||r.indexOf(" ")!==-1)?!1:r!==""&&!isNaN(Number(r==null?void 0:r.toString())),Il=r=>ri(r)?typeof r=="string"?Number(r)>=0:typeof r=="number"&&r>=0:!1;var pa=(r,t,e)=>{let i=bl(r)&&typeof r!="string"?Array.from(r):[r];return i.length===0?[]:typeof i[0]=="string"?i:i.map(s=>s.toLineProtocol(void 0,t,e)).filter(gl)};var ad=r=>typeof r=="number"?"float":typeof r=="string"?"string":typeof r=="boolean"?"boolean":void 0,Yn=class r extends Error{constructor(t,e,i){super(`field ${t} of type ${i} doesn't match expected type ${e}!`),this.name="GetFieldTypeMissmatchError",Object.setPrototypeOf(this,r.prototype)}},fr=class r{constructor(){z(this,"_name");z(this,"_time");z(this,"_tags",{});z(this,"_fields",{})}getMeasurement(){return this._name}setMeasurement(t){return this._name=t,this}getTimestamp(){return this._time}setTimestamp(t){return this._time=t,this}getTag(t){return this._tags[t]}setTag(t,e){return this._tags[t]=e,this}removeTag(t){return delete this._tags[t],this}getTagNames(){return Object.keys(this._tags)}getFloatField(t){return this.getField(t,"float")}setFloatField(t,e){let i;if(typeof e=="number"?i=e:i=parseFloat(e),!isFinite(i))throw new Error(`invalid float value for field '${t}': '${e}'!`);return this._fields[t]=["float",i],this}getIntegerField(t){return this.getField(t,"integer")}setIntegerField(t,e){let i;if(typeof e=="number"?i=e:i=parseInt(String(e)),isNaN(i)||i<=-9223372036854776e3||i>=9223372036854776e3)throw new Error(`invalid integer value for field '${t}': '${e}'!`);return this._fields[t]=["integer",Math.floor(i)],this}getUintegerField(t){return this.getField(t,"uinteger")}setUintegerField(t,e){if(typeof e=="number"){if(isNaN(e)||e<0||e>Number.MAX_SAFE_INTEGER)throw new Error(`uint value for field '${t}' out of range: ${e}`);this._fields[t]=["uinteger",Math.floor(e)]}else{let i=String(e);for(let n=0;n<i.length;n++){let s=i.charCodeAt(n);if(s<48||s>57)throw new Error(`uint value has an unsupported character at pos ${n}: ${e}`)}if(i.length>20||i.length===20&&i.localeCompare("18446744073709551615")>0)throw new Error(`uint value for field '${t}' out of range: ${i}`);this._fields[t]=["uinteger",+i]}return this}getStringField(t){return this.getField(t,"string")}setStringField(t,e){return e!=null&&(typeof e!="string"&&(e=String(e)),this._fields[t]=["string",e]),this}getBooleanField(t){return this.getField(t,"boolean")}setBooleanField(t,e){return this._fields[t]=["boolean",!!e],this}getField(t,e){let i=this._fields[t];if(!i)return;let[n,s]=i;if(e!==void 0&&e!==n)throw new Yn(t,e,n);return s}getFieldType(t){let e=this._fields[t];if(e)return e[0]}setField(t,e,i){switch(i!=null?i:ad(e)){case"string":return this.setStringField(t,e);case"boolean":return this.setBooleanField(t,e);case"float":return this.setFloatField(t,e);case"integer":return this.setIntegerField(t,e);case"uinteger":return this.setUintegerField(t,e);case void 0:return this;default:throw new Error(`invalid field type for field '${t}': type -> ${i}, value -> ${e}!`)}}setFields(t){for(let[e,i]of Object.entries(t))this.setField(e,i);return this}removeField(t){return delete this._fields[t],this}getFieldNames(){return Object.keys(this._fields)}hasFields(){return this.getFieldNames().length>0}copy(){let t=new r;return t._name=this._name,t._time=this._time,t._tags=Object.fromEntries(Object.entries(this._tags)),t._fields=Object.fromEntries(Object.entries(this._fields).map(e=>[...e])),t}asPoint(t){return Ui.fromValues(t?this.setMeasurement(t):this)}};var cd=(r,t)=>{switch(r){case"string":return Er.quoted(t);case"boolean":return t?"T":"F";case"float":return`${t}`;case"integer":return`${t}i`;case"uinteger":return`${t}u`}},ld=(r,t)=>{if(!t)return[];let e=new Set(r);return Object.keys(t).filter(i=>!e.has(i)).sort()},ud=(r,t)=>{if(!t||t.length===0)return r;let e=new Set(r),i=[],n=new Set;for(let o of t)!o||n.has(o)||!e.has(o)||(i.push(o),n.add(o),e.delete(o));let s=Array.from(e).sort();return i.concat(s)},Ui=class r{constructor(t){z(this,"_values");t instanceof fr?this._values=t:this._values=new fr,typeof t=="string"&&this._values.setMeasurement(t)}static measurement(t){return new r(t)}static fromValues(t){if(!t.getMeasurement()||t.getMeasurement()==="")throw new Error("Cannot convert values to point without measurement set!");return new r(t)}getMeasurement(){return this._values.getMeasurement()}setMeasurement(t){return t!==""&&this._values.setMeasurement(t),this}getTimestamp(){return this._values.getTimestamp()}setTimestamp(t){return this._values.setTimestamp(t),this}getTag(t){return this._values.getTag(t)}setTag(t,e){return this._values.setTag(t,e),this}removeTag(t){return this._values.removeTag(t),this}getTagNames(){return this._values.getTagNames()}getFloatField(t){return this._values.getFloatField(t)}setFloatField(t,e){return this._values.setFloatField(t,e),this}getIntegerField(t){return this._values.getIntegerField(t)}setIntegerField(t,e){return this._values.setIntegerField(t,e),this}getUintegerField(t){return this._values.getUintegerField(t)}setUintegerField(t,e){return this._values.setUintegerField(t,e),this}getStringField(t){return this._values.getStringField(t)}setStringField(t,e){return this._values.setStringField(t,e),this}getBooleanField(t){return this._values.getBooleanField(t)}setBooleanField(t,e){return this._values.setBooleanField(t,e),this}getField(t,e){return this._values.getField(t,e)}getFieldType(t){return this._values.getFieldType(t)}setField(t,e,i){return this._values.setField(t,e,i),this}setFields(t){return this._values.setFields(t),this}removeField(t){return this._values.removeField(t),this}getFieldNames(){return this._values.getFieldNames()}hasFields(){return this._values.hasFields()}copy(){return new r(this._values.copy())}toLineProtocol(t,e,i){if(!this._values.getMeasurement())return;let n="";if(this._values.getFieldNames().sort().forEach(u=>{if(u){let d=this._values.getFieldType(u),p=this._values.getField(u);if(d===void 0||p===void 0)return;let m=cd(d,p);n.length>0&&(n+=","),n+=`${Er.tag(u)}=${m}`}}),n.length===0)return;let s="",o=this._values.getTagNames().sort(),a=ld(o,e);ud(a.concat(o),i).forEach(u=>{if(u){let d=this._values.getTag(u),p=d!==void 0?d:e==null?void 0:e[u];p&&(s+=",",s+=`${Er.tag(u)}=${Er.tag(p)}`)}});let l=this._values.getTimestamp();return t?typeof t=="string"?l=ha(l,t):l=t(l):l=da(l),`${Er.measurement(this.getMeasurement())}${s} ${n}${l!==void 0?` ${l}`:""}`}toString(){let t=this.toLineProtocol(void 0);return t||`invalid point: ${JSON.stringify(this,void 0)}`}};function ma(r={}){let t=0,e={next:i=>{if(t===0&&r.next&&i!==null&&i!==void 0)return r.next(i)},error:i=>{t===0&&(t=1,r.error&&r.error(i))},complete:()=>{t===0&&(t=2,r.complete&&r.complete())},responseStarted:(i,n)=>{r.responseStarted&&r.responseStarted(i,n)}};return r.useCancellable&&(e.useCancellable=r.useCancellable.bind(r)),r.useResume&&(e.useResume=r.useResume.bind(r)),e}function Zn(r){let t={};return r.headers.forEach((e,i)=>{let n=t[i];n===void 0?t[i]=e:Array.isArray(n)?n.push(e):t[i]=[n,e]}),t}var Mi=class{constructor(t){this._connectionOptions=t;z(this,"chunkCombiner",ea());z(this,"_defaultHeaders");z(this,"_url");z(this,"requestDecorator",function(){});var e;if(this._defaultHeaders={"content-type":"application/json; charset=utf-8",...t.headers},this._connectionOptions.token){let i=(e=this._connectionOptions.authScheme)!=null?e:"Token";this._defaultHeaders.Authorization=`${i} ${this._connectionOptions.token}`}this._url=String(this._connectionOptions.host),this._url.endsWith("/")&&(this._url=this._url.substring(0,this._url.length-1)),this._url.endsWith("/api/v2")&&(this._url=this._url.substring(0,this._url.length-7),Nr.warn(`Please remove '/api/v2' context path from InfluxDB base url, using ${this._url} !`))}_connectionOptions;send(t,e,i,n){let s=ma(n),o=!1,a=i.signal,c,l=()=>{},u=l;if(n&&n.useCancellable){let d=new AbortController;a||(a=d.signal,i={...i,signal:a}),a.addEventListener("abort",()=>{u()}),n.useCancellable({cancel(){o=!0,d.abort()},isCancelled(){return o||a.aborted}})}this._fetch(t,e,i).then(async d=>{if(n!=null&&n.responseStarted&&s.responseStarted(Zn(d),d.status),await this._throwOnErrorResponse(d),d.body){let p=d.body.getReader(),m;do{if(c&&await c,o)break;if(m=await p.read(),s.next(m.value)===!1){let _=s.useResume;if(!_){let j="Unable to pause, useResume is not configured!";return await p.cancel(j),Promise.reject(new Error(j))}c=new Promise(j=>{u=()=>{j(),c=void 0,u=l},_(u)})}}while(!m.done)}else if(d.arrayBuffer){let p=await d.arrayBuffer();s.next(new Uint8Array(p))}else{let p=await d.text();s.next(new TextEncoder().encode(p))}}).catch(d=>{o||s.error(d)}).finally(()=>s.complete())}async _throwOnErrorResponse(t){if(t.status>=300){let e="";try{if(e=await t.text(),!e){let i=t.headers.get("x-influxdb-error");i&&(e=i)}}catch(i){throw Nr.warn("Unable to receive error body",i),new re(t.status,t.statusText,void 0,t.headers.get("content-type"),Zn(t))}throw new re(t.status,t.statusText,e,t.headers.get("content-type"),Zn(t))}}async*iterate(t,e,i){var s;let n=await this._fetch(t,e,i);if(await this._throwOnErrorResponse(n),n.body){let o=n.body.getReader();for(;;){let{value:a,done:c}=await o.read();if(c)break;if((s=i.signal)!=null&&s.aborted)throw await n.body.cancel(),new Li;yield a}}else if(n.arrayBuffer){let o=await n.arrayBuffer();yield new Uint8Array(o)}else{let o=await n.text();yield new TextEncoder().encode(o)}}async request(t,e,i,n){var l,u;let s=await this._fetch(t,e,i),{headers:o}=s,a=o.get("content-type")||"";n&&n(Zn(s),s.status),await this._throwOnErrorResponse(s);let c=(u=(l=i.headers)==null?void 0:l.accept)!=null?u:a;if(c.includes("json"))return await s.json();if(c.includes("text")||c.startsWith("application/csv"))return await s.text()}_fetch(t,e,i){let{method:n,headers:s,...o}=i,a=`${this._url}${t}`,c={method:n,body:n==="GET"||n==="HEAD"?void 0:typeof e=="string"?e:JSON.stringify(e),headers:{...this._defaultHeaders,...s},credentials:"omit",...this._connectionOptions.transportOptions,...o};return this.requestDecorator(c,i,a),fetch(a,c)}};function Lr(r){let t=typeof r;if(t=="object"){if(Array.isArray(r))return"array";if(r===null)return"null"}return t}function ya(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)}var Me="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),Qn=[];for(let r=0;r<Me.length;r++)Qn[Me[r].charCodeAt(0)]=r;Qn[45]=Me.indexOf("+");Qn[95]=Me.indexOf("/");function Ri(r){let t=r.length*3/4;r[r.length-2]=="="?t-=2:r[r.length-1]=="="&&(t-=1);let e=new Uint8Array(t),i=0,n=0,s,o=0;for(let a=0;a<r.length;a++){if(s=Qn[r.charCodeAt(a)],s===void 0)switch(r[a]){case"=":n=0;case`
`:case"\r":case" ":case" ":continue;default:throw Error("invalid base64 string.")}switch(n){case 0:o=s,n=1;break;case 1:e[i++]=o<<2|(s&48)>>4,o=s,n=2;break;case 2:e[i++]=(o&15)<<4|(s&60)>>2,o=s,n=3;break;case 3:e[i++]=(o&3)<<6|s,n=0;break}}if(n==1)throw Error("invalid base64 string.");return e.subarray(0,i)}function Ci(r){let t="",e=0,i,n=0;for(let s=0;s<r.length;s++)switch(i=r[s],e){case 0:t+=Me[i>>2],n=(i&3)<<4,e=1;break;case 1:t+=Me[n|i>>4],n=(i&15)<<2,e=2;break;case 2:t+=Me[n|i>>6],t+=Me[i&63],e=0;break}return e&&(t+=Me[n],t+="=",e==1&&(t+="=")),t}var Ur;(function(r){r.symbol=Symbol.for("protobuf-ts/unknown"),r.onRead=(e,i,n,s,o)=>{(t(i)?i[r.symbol]:i[r.symbol]=[]).push({no:n,wireType:s,data:o})},r.onWrite=(e,i,n)=>{for(let{no:s,wireType:o,data:a}of r.list(i))n.tag(s,o).raw(a)},r.list=(e,i)=>{if(t(e)){let n=e[r.symbol];return i?n.filter(s=>s.no==i):n}return[]},r.last=(e,i)=>r.list(e,i).slice(-1)[0];let t=e=>e&&Array.isArray(e[r.symbol])})(Ur||(Ur={}));function ga(r,t){return Object.assign(Object.assign({},r),t)}var st;(function(r){r[r.Varint=0]="Varint",r[r.Bit64=1]="Bit64",r[r.LengthDelimited=2]="LengthDelimited",r[r.StartGroup=3]="StartGroup",r[r.EndGroup=4]="EndGroup",r[r.Bit32=5]="Bit32"})(st||(st={}));function vl(){let r=0,t=0;for(let i=0;i<28;i+=7){let n=this.buf[this.pos++];if(r|=(n&127)<<i,(n&128)==0)return this.assertBounds(),[r,t]}let e=this.buf[this.pos++];if(r|=(e&15)<<28,t=(e&112)>>4,(e&128)==0)return this.assertBounds(),[r,t];for(let i=3;i<=31;i+=7){let n=this.buf[this.pos++];if(t|=(n&127)<<i,(n&128)==0)return this.assertBounds(),[r,t]}throw new Error("invalid varint")}function es(r,t,e){for(let s=0;s<28;s=s+7){let o=r>>>s,a=!(!(o>>>7)&&t==0),c=(a?o|128:o)&255;if(e.push(c),!a)return}let i=r>>>28&15|(t&7)<<4,n=t>>3!=0;if(e.push((n?i|128:i)&255),!!n){for(let s=3;s<31;s=s+7){let o=t>>>s,a=!!(o>>>7),c=(a?o|128:o)&255;if(e.push(c),!a)return}e.push(t>>>31&1)}}var ts=65536*65536;function ba(r){let t=r[0]=="-";t&&(r=r.slice(1));let e=1e6,i=0,n=0;function s(o,a){let c=Number(r.slice(o,a));n*=e,i=i*e+c,i>=ts&&(n=n+(i/ts|0),i=i%ts)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),[t,i,n]}function rs(r,t){if(t>>>0<=2097151)return""+(ts*t+(r>>>0));let e=r&16777215,i=(r>>>24|t<<8)>>>0&16777215,n=t>>16&65535,s=e+i*6777216+n*6710656,o=i+n*8147497,a=n*2,c=1e7;s>=c&&(o+=Math.floor(s/c),s%=c),o>=c&&(a+=Math.floor(o/c),o%=c);function l(u,d){let p=u?String(u):"";return d?"0000000".slice(p.length)+p:p}return l(a,0)+l(o,a)+l(s,1)}function _a(r,t){if(r>=0){for(;r>127;)t.push(r&127|128),r=r>>>7;t.push(r)}else{for(let e=0;e<9;e++)t.push(r&127|128),r=r>>7;t.push(1)}}function Sl(){let r=this.buf[this.pos++],t=r&127;if((r&128)==0)return this.assertBounds(),t;if(r=this.buf[this.pos++],t|=(r&127)<<7,(r&128)==0)return this.assertBounds(),t;if(r=this.buf[this.pos++],t|=(r&127)<<14,(r&128)==0)return this.assertBounds(),t;if(r=this.buf[this.pos++],t|=(r&127)<<21,(r&128)==0)return this.assertBounds(),t;r=this.buf[this.pos++],t|=(r&15)<<28;for(let e=5;(r&128)!==0&&e<10;e++)r=this.buf[this.pos++];if((r&128)!=0)throw new Error("invalid varint");return this.assertBounds(),t>>>0}var tt;function fd(){let r=new DataView(new ArrayBuffer(8));tt=globalThis.BigInt!==void 0&&typeof r.getBigInt64=="function"&&typeof r.getBigUint64=="function"&&typeof r.setBigInt64=="function"&&typeof r.setBigUint64=="function"?{MIN:BigInt("-9223372036854775808"),MAX:BigInt("9223372036854775807"),UMIN:BigInt("0"),UMAX:BigInt("18446744073709551615"),C:BigInt,V:r}:void 0}fd();function xl(r){if(!r)throw new Error("BigInt unavailable, see https://github.com/timostamm/protobuf-ts/blob/v1.0.8/MANUAL.md#bigint-support")}var Tl=/^-?[0-9]+$/,ns=4294967296,is=2147483648,ss=class{constructor(t,e){this.lo=t|0,this.hi=e|0}isZero(){return this.lo==0&&this.hi==0}toNumber(){let t=this.hi*ns+(this.lo>>>0);if(!Number.isSafeInteger(t))throw new Error("cannot convert to safe number");return t}},ht=class r extends ss{static from(t){if(tt)switch(typeof t){case"string":if(t=="0")return this.ZERO;if(t=="")throw new Error("string is no integer");t=tt.C(t);case"number":if(t===0)return this.ZERO;t=tt.C(t);case"bigint":if(!t)return this.ZERO;if(t<tt.UMIN)throw new Error("signed value for ulong");if(t>tt.UMAX)throw new Error("ulong too large");return tt.V.setBigUint64(0,t,!0),new r(tt.V.getInt32(0,!0),tt.V.getInt32(4,!0))}else switch(typeof t){case"string":if(t=="0")return this.ZERO;if(t=t.trim(),!Tl.test(t))throw new Error("string is no integer");let[e,i,n]=ba(t);if(e)throw new Error("signed value for ulong");return new r(i,n);case"number":if(t==0)return this.ZERO;if(!Number.isSafeInteger(t))throw new Error("number is no integer");if(t<0)throw new Error("signed value for ulong");return new r(t,t/ns)}throw new Error("unknown value "+typeof t)}toString(){return tt?this.toBigInt().toString():rs(this.lo,this.hi)}toBigInt(){return xl(tt),tt.V.setInt32(0,this.lo,!0),tt.V.setInt32(4,this.hi,!0),tt.V.getBigUint64(0,!0)}};ht.ZERO=new ht(0,0);var X=class r extends ss{static from(t){if(tt)switch(typeof t){case"string":if(t=="0")return this.ZERO;if(t=="")throw new Error("string is no integer");t=tt.C(t);case"number":if(t===0)return this.ZERO;t=tt.C(t);case"bigint":if(!t)return this.ZERO;if(t<tt.MIN)throw new Error("signed long too small");if(t>tt.MAX)throw new Error("signed long too large");return tt.V.setBigInt64(0,t,!0),new r(tt.V.getInt32(0,!0),tt.V.getInt32(4,!0))}else switch(typeof t){case"string":if(t=="0")return this.ZERO;if(t=t.trim(),!Tl.test(t))throw new Error("string is no integer");let[e,i,n]=ba(t);if(e){if(n>is||n==is&&i!=0)throw new Error("signed long too small")}else if(n>=is)throw new Error("signed long too large");let s=new r(i,n);return e?s.negate():s;case"number":if(t==0)return this.ZERO;if(!Number.isSafeInteger(t))throw new Error("number is no integer");return t>0?new r(t,t/ns):new r(-t,-t/ns).negate()}throw new Error("unknown value "+typeof t)}isNegative(){return(this.hi&is)!==0}negate(){let t=~this.hi,e=this.lo;return e?e=~e+1:t+=1,new r(e,t)}toString(){if(tt)return this.toBigInt().toString();if(this.isNegative()){let t=this.negate();return"-"+rs(t.lo,t.hi)}return rs(this.lo,this.hi)}toBigInt(){return xl(tt),tt.V.setInt32(0,this.lo,!0),tt.V.setInt32(4,this.hi,!0),tt.V.getBigInt64(0,!0)}};X.ZERO=new X(0,0);var Bl={readUnknownField:!0,readerFactory:r=>new wa(r)};function Ol(r){return r?Object.assign(Object.assign({},Bl),r):Bl}var wa=class{constructor(t,e){this.varint64=vl,this.uint32=Sl,this.buf=t,this.len=t.length,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.textDecoder=e!=null?e:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0})}tag(){let t=this.uint32(),e=t>>>3,i=t&7;if(e<=0||i<0||i>5)throw new Error("illegal tag: field no "+e+" wire type "+i);return[e,i]}skip(t){let e=this.pos;switch(t){case st.Varint:for(;this.buf[this.pos++]&128;);break;case st.Bit64:this.pos+=4;case st.Bit32:this.pos+=4;break;case st.LengthDelimited:let i=this.uint32();this.pos+=i;break;case st.StartGroup:let n;for(;(n=this.tag()[1])!==st.EndGroup;)this.skip(n);break;default:throw new Error("cant skip wire type "+t)}return this.assertBounds(),this.buf.subarray(e,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)}int64(){return new X(...this.varint64())}uint64(){return new ht(...this.varint64())}sint64(){let[t,e]=this.varint64(),i=-(t&1);return t=(t>>>1|(e&1)<<31)^i,e=e>>>1^i,new X(t,e)}bool(){let[t,e]=this.varint64();return t!==0||e!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return new ht(this.sfixed32(),this.sfixed32())}sfixed64(){return new X(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let t=this.uint32(),e=this.pos;return this.pos+=t,this.assertBounds(),this.buf.subarray(e,e+t)}string(){return this.textDecoder.decode(this.bytes())}};function M(r,t){if(!r)throw new Error(t)}function Ia(r,t){throw new Error(t!=null?t:"Unexpected object: "+r)}var dd=34028234663852886e22,hd=-34028234663852886e22,pd=4294967295,md=2147483647,yd=-2147483648;function Re(r){if(typeof r!="number")throw new Error("invalid int 32: "+typeof r);if(!Number.isInteger(r)||r>md||r<yd)throw new Error("invalid int 32: "+r)}function dr(r){if(typeof r!="number")throw new Error("invalid uint 32: "+typeof r);if(!Number.isInteger(r)||r>pd||r<0)throw new Error("invalid uint 32: "+r)}function Mr(r){if(typeof r!="number")throw new Error("invalid float 32: "+typeof r);if(Number.isFinite(r)&&(r>dd||r<hd))throw new Error("invalid float 32: "+r)}var Dl={writeUnknownFields:!0,writerFactory:()=>new va};function Al(r){return r?Object.assign(Object.assign({},Dl),r):Dl}var va=class{constructor(t){this.stack=[],this.textEncoder=t!=null?t:new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let t=0;for(let n=0;n<this.chunks.length;n++)t+=this.chunks[n].length;let e=new Uint8Array(t),i=0;for(let n=0;n<this.chunks.length;n++)e.set(this.chunks[n],i),i+=this.chunks[n].length;return this.chunks=[],e}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let t=this.finish(),e=this.stack.pop();if(!e)throw new Error("invalid state, fork stack empty");return this.chunks=e.chunks,this.buf=e.buf,this.uint32(t.byteLength),this.raw(t)}tag(t,e){return this.uint32((t<<3|e)>>>0)}raw(t){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(t),this}uint32(t){for(dr(t);t>127;)this.buf.push(t&127|128),t=t>>>7;return this.buf.push(t),this}int32(t){return Re(t),_a(t,this.buf),this}bool(t){return this.buf.push(t?1:0),this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){let e=this.textEncoder.encode(t);return this.uint32(e.byteLength),this.raw(e)}float(t){Mr(t);let e=new Uint8Array(4);return new DataView(e.buffer).setFloat32(0,t,!0),this.raw(e)}double(t){let e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t,!0),this.raw(e)}fixed32(t){dr(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){Re(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return Re(t),t=(t<<1^t>>31)>>>0,_a(t,this.buf),this}sfixed64(t){let e=new Uint8Array(8),i=new DataView(e.buffer),n=X.from(t);return i.setInt32(0,n.lo,!0),i.setInt32(4,n.hi,!0),this.raw(e)}fixed64(t){let e=new Uint8Array(8),i=new DataView(e.buffer),n=ht.from(t);return i.setInt32(0,n.lo,!0),i.setInt32(4,n.hi,!0),this.raw(e)}int64(t){let e=X.from(t);return es(e.lo,e.hi,this.buf),this}sint64(t){let e=X.from(t),i=e.hi>>31,n=e.lo<<1^i,s=(e.hi<<1|e.lo>>>31)^i;return es(n,s,this.buf),this}uint64(t){let e=ht.from(t);return es(e.lo,e.hi,this.buf),this}};var Fl={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0},Nl={ignoreUnknownFields:!1};function Sa(r){return r?Object.assign(Object.assign({},Nl),r):Nl}function xa(r){return r?Object.assign(Object.assign({},Fl),r):Fl}function Ta(r,t){var e,i;let n=Object.assign(Object.assign({},r),t);return n.typeRegistry=[...(e=r==null?void 0:r.typeRegistry)!==null&&e!==void 0?e:[],...(i=t==null?void 0:t.typeRegistry)!==null&&i!==void 0?i:[]],n}var os=Symbol.for("protobuf-ts/message-type");function ii(r){let t=!1,e=[];for(let i=0;i<r.length;i++){let n=r.charAt(i);n=="_"?t=!0:/\d/.test(n)?(e.push(n),t=!0):t?(e.push(n.toUpperCase()),t=!1):i==0?e.push(n.toLowerCase()):e.push(n)}return e.join("")}var h;(function(r){r[r.DOUBLE=1]="DOUBLE",r[r.FLOAT=2]="FLOAT",r[r.INT64=3]="INT64",r[r.UINT64=4]="UINT64",r[r.INT32=5]="INT32",r[r.FIXED64=6]="FIXED64",r[r.FIXED32=7]="FIXED32",r[r.BOOL=8]="BOOL",r[r.STRING=9]="STRING",r[r.BYTES=12]="BYTES",r[r.UINT32=13]="UINT32",r[r.SFIXED32=15]="SFIXED32",r[r.SFIXED64=16]="SFIXED64",r[r.SINT32=17]="SINT32",r[r.SINT64=18]="SINT64"})(h||(h={}));var Dt;(function(r){r[r.BIGINT=0]="BIGINT",r[r.STRING=1]="STRING",r[r.NUMBER=2]="NUMBER"})(Dt||(Dt={}));var ki;(function(r){r[r.NO=0]="NO",r[r.PACKED=1]="PACKED",r[r.UNPACKED=2]="UNPACKED"})(ki||(ki={}));function El(r){var t,e,i,n;return r.localName=(t=r.localName)!==null&&t!==void 0?t:ii(r.name),r.jsonName=(e=r.jsonName)!==null&&e!==void 0?e:ii(r.name),r.repeat=(i=r.repeat)!==null&&i!==void 0?i:ki.NO,r.opt=(n=r.opt)!==null&&n!==void 0?n:r.repeat||r.oneof?!1:r.kind=="message",r}function Ll(r){if(typeof r!="object"||r===null||!r.hasOwnProperty("oneofKind"))return!1;switch(typeof r.oneofKind){case"string":return r[r.oneofKind]===void 0?!1:Object.keys(r).length==2;case"undefined":return Object.keys(r).length==1;default:return!1}}var as=class{constructor(t){var e;this.fields=(e=t.fields)!==null&&e!==void 0?e:[]}prepare(){if(this.data)return;let t=[],e=[],i=[];for(let n of this.fields)if(n.oneof)i.includes(n.oneof)||(i.push(n.oneof),t.push(n.oneof),e.push(n.oneof));else switch(e.push(n.localName),n.kind){case"scalar":case"enum":(!n.opt||n.repeat)&&t.push(n.localName);break;case"message":n.repeat&&t.push(n.localName);break;case"map":t.push(n.localName);break}this.data={req:t,known:e,oneofs:Object.values(i)}}is(t,e,i=!1){if(e<0)return!0;if(t==null||typeof t!="object")return!1;this.prepare();let n=Object.keys(t),s=this.data;if(n.length<s.req.length||s.req.some(o=>!n.includes(o))||!i&&n.some(o=>!s.known.includes(o)))return!1;if(e<1)return!0;for(let o of s.oneofs){let a=t[o];if(!Ll(a))return!1;if(a.oneofKind===void 0)continue;let c=this.fields.find(l=>l.localName===a.oneofKind);if(!c||!this.field(a[a.oneofKind],c,i,e))return!1}for(let o of this.fields)if(o.oneof===void 0&&!this.field(t[o.localName],o,i,e))return!1;return!0}field(t,e,i,n){let s=e.repeat;switch(e.kind){case"scalar":return t===void 0?e.opt:s?this.scalars(t,e.T,n,e.L):this.scalar(t,e.T,e.L);case"enum":return t===void 0?e.opt:s?this.scalars(t,h.INT32,n):this.scalar(t,h.INT32);case"message":return t===void 0?!0:s?this.messages(t,e.T(),i,n):this.message(t,e.T(),i,n);case"map":if(typeof t!="object"||t===null)return!1;if(n<2)return!0;if(!this.mapKeys(t,e.K,n))return!1;switch(e.V.kind){case"scalar":return this.scalars(Object.values(t),e.V.T,n,e.V.L);case"enum":return this.scalars(Object.values(t),h.INT32,n);case"message":return this.messages(Object.values(t),e.V.T(),i,n)}break}return!0}message(t,e,i,n){return i?e.isAssignable(t,n):e.is(t,n)}messages(t,e,i,n){if(!Array.isArray(t))return!1;if(n<2)return!0;if(i){for(let s=0;s<t.length&&s<n;s++)if(!e.isAssignable(t[s],n-1))return!1}else for(let s=0;s<t.length&&s<n;s++)if(!e.is(t[s],n-1))return!1;return!0}scalar(t,e,i){let n=typeof t;switch(e){case h.UINT64:case h.FIXED64:case h.INT64:case h.SFIXED64:case h.SINT64:switch(i){case Dt.BIGINT:return n=="bigint";case Dt.NUMBER:return n=="number"&&!isNaN(t);default:return n=="string"}case h.BOOL:return n=="boolean";case h.STRING:return n=="string";case h.BYTES:return t instanceof Uint8Array;case h.DOUBLE:case h.FLOAT:return n=="number"&&!isNaN(t);default:return n=="number"&&Number.isInteger(t)}}scalars(t,e,i,n){if(!Array.isArray(t))return!1;if(i<2)return!0;if(Array.isArray(t)){for(let s=0;s<t.length&&s<i;s++)if(!this.scalar(t[s],e,n))return!1}return!0}mapKeys(t,e,i){let n=Object.keys(t);switch(e){case h.INT32:case h.FIXED32:case h.SFIXED32:case h.SINT32:case h.UINT32:return this.scalars(n.slice(0,i).map(s=>parseInt(s)),e,i);case h.BOOL:return this.scalars(n.slice(0,i).map(s=>s=="true"?!0:s=="false"?!1:s),e,i);default:return this.scalars(n,e,i,Dt.STRING)}}};function Lt(r,t){switch(t){case Dt.BIGINT:return r.toBigInt();case Dt.NUMBER:return r.toNumber();default:return r.toString()}}var cs=class{constructor(t){this.info=t}prepare(){var t;if(this.fMap===void 0){this.fMap={};let e=(t=this.info.fields)!==null&&t!==void 0?t:[];for(let i of e)this.fMap[i.name]=i,this.fMap[i.jsonName]=i,this.fMap[i.localName]=i}}assert(t,e,i){if(!t){let n=Lr(i);throw(n=="number"||n=="boolean")&&(n=i.toString()),new Error(`Cannot parse JSON ${n} for ${this.info.typeName}#${e}`)}}read(t,e,i){this.prepare();let n=[];for(let[s,o]of Object.entries(t)){let a=this.fMap[s];if(!a){if(!i.ignoreUnknownFields)throw new Error(`Found unknown field while reading ${this.info.typeName} from JSON format. JSON key: ${s}`);continue}let c=a.localName,l;if(a.oneof){if(o===null&&(a.kind!=="enum"||a.T()[0]!=="google.protobuf.NullValue"))continue;if(n.includes(a.oneof))throw new Error(`Multiple members of the oneof group "${a.oneof}" of ${this.info.typeName} are present in JSON.`);n.push(a.oneof),l=e[a.oneof]={oneofKind:c}}else l=e;if(a.kind=="map"){if(o===null)continue;this.assert(ya(o),a.name,o);let u=l[c];for(let[d,p]of Object.entries(o)){this.assert(p!==null,a.name+" map value",null);let m;switch(a.V.kind){case"message":m=a.V.T().internalJsonRead(p,i);break;case"enum":if(m=this.enum(a.V.T(),p,a.name,i.ignoreUnknownFields),m===!1)continue;break;case"scalar":m=this.scalar(p,a.V.T,a.V.L,a.name);break}this.assert(m!==void 0,a.name+" map value",p);let _=d;a.K==h.BOOL&&(_=_=="true"?!0:_=="false"?!1:_),_=this.scalar(_,a.K,Dt.STRING,a.name).toString(),u[_]=m}}else if(a.repeat){if(o===null)continue;this.assert(Array.isArray(o),a.name,o);let u=l[c];for(let d of o){this.assert(d!==null,a.name,null);let p;switch(a.kind){case"message":p=a.T().internalJsonRead(d,i);break;case"enum":if(p=this.enum(a.T(),d,a.name,i.ignoreUnknownFields),p===!1)continue;break;case"scalar":p=this.scalar(d,a.T,a.L,a.name);break}this.assert(p!==void 0,a.name,o),u.push(p)}}else switch(a.kind){case"message":if(o===null&&a.T().typeName!="google.protobuf.Value"){this.assert(a.oneof===void 0,a.name+" (oneof member)",null);continue}l[c]=a.T().internalJsonRead(o,i,l[c]);break;case"enum":if(o===null)continue;let u=this.enum(a.T(),o,a.name,i.ignoreUnknownFields);if(u===!1)continue;l[c]=u;break;case"scalar":if(o===null)continue;l[c]=this.scalar(o,a.T,a.L,a.name);break}}}enum(t,e,i,n){if(t[0]=="google.protobuf.NullValue"&&M(e===null||e==="NULL_VALUE",`Unable to parse field ${this.info.typeName}#${i}, enum ${t[0]} only accepts null.`),e===null)return 0;switch(typeof e){case"number":return M(Number.isInteger(e),`Unable to parse field ${this.info.typeName}#${i}, enum can only be integral number, got ${e}.`),e;case"string":let s=e;t[2]&&e.substring(0,t[2].length)===t[2]&&(s=e.substring(t[2].length));let o=t[1][s];return typeof o=="undefined"&&n?!1:(M(typeof o=="number",`Unable to parse field ${this.info.typeName}#${i}, enum ${t[0]} has no value for "${e}".`),o)}M(!1,`Unable to parse field ${this.info.typeName}#${i}, cannot parse enum value from ${typeof e}".`)}scalar(t,e,i,n){let s;try{switch(e){case h.DOUBLE:case h.FLOAT:if(t===null)return 0;if(t==="NaN")return Number.NaN;if(t==="Infinity")return Number.POSITIVE_INFINITY;if(t==="-Infinity")return Number.NEGATIVE_INFINITY;if(t===""){s="empty string";break}if(typeof t=="string"&&t.trim().length!==t.length){s="extra whitespace";break}if(typeof t!="string"&&typeof t!="number")break;let o=Number(t);if(Number.isNaN(o)){s="not a number";break}if(!Number.isFinite(o)){s="too large or small";break}return e==h.FLOAT&&Mr(o),o;case h.INT32:case h.FIXED32:case h.SFIXED32:case h.SINT32:case h.UINT32:if(t===null)return 0;let a;if(typeof t=="number"?a=t:t===""?s="empty string":typeof t=="string"&&(t.trim().length!==t.length?s="extra whitespace":a=Number(t)),a===void 0)break;return e==h.UINT32?dr(a):Re(a),a;case h.INT64:case h.SFIXED64:case h.SINT64:if(t===null)return Lt(X.ZERO,i);if(typeof t!="number"&&typeof t!="string")break;return Lt(X.from(t),i);case h.FIXED64:case h.UINT64:if(t===null)return Lt(ht.ZERO,i);if(typeof t!="number"&&typeof t!="string")break;return Lt(ht.from(t),i);case h.BOOL:if(t===null)return!1;if(typeof t!="boolean")break;return t;case h.STRING:if(t===null)return"";if(typeof t!="string"){s="extra whitespace";break}try{encodeURIComponent(t)}catch(c){c="invalid UTF8";break}return t;case h.BYTES:if(t===null||t==="")return new Uint8Array(0);if(typeof t!="string")break;return Ri(t)}}catch(o){s=o.message}this.assert(!1,n+(s?" - "+s:""),t)}};var ls=class{constructor(t){var e;this.fields=(e=t.fields)!==null&&e!==void 0?e:[]}write(t,e){let i={},n=t;for(let s of this.fields){if(!s.oneof){let l=this.field(s,n[s.localName],e);l!==void 0&&(i[e.useProtoFieldName?s.name:s.jsonName]=l);continue}let o=n[s.oneof];if(o.oneofKind!==s.localName)continue;let a=s.kind=="scalar"||s.kind=="enum"?Object.assign(Object.assign({},e),{emitDefaultValues:!0}):e,c=this.field(s,o[s.localName],a);M(c!==void 0),i[e.useProtoFieldName?s.name:s.jsonName]=c}return i}field(t,e,i){let n;if(t.kind=="map"){M(typeof e=="object"&&e!==null);let s={};switch(t.V.kind){case"scalar":for(let[c,l]of Object.entries(e)){let u=this.scalar(t.V.T,l,t.name,!1,!0);M(u!==void 0),s[c.toString()]=u}break;case"message":let o=t.V.T();for(let[c,l]of Object.entries(e)){let u=this.message(o,l,t.name,i);M(u!==void 0),s[c.toString()]=u}break;case"enum":let a=t.V.T();for(let[c,l]of Object.entries(e)){M(l===void 0||typeof l=="number");let u=this.enum(a,l,t.name,!1,!0,i.enumAsInteger);M(u!==void 0),s[c.toString()]=u}break}(i.emitDefaultValues||Object.keys(s).length>0)&&(n=s)}else if(t.repeat){M(Array.isArray(e));let s=[];switch(t.kind){case"scalar":for(let c=0;c<e.length;c++){let l=this.scalar(t.T,e[c],t.name,t.opt,!0);M(l!==void 0),s.push(l)}break;case"enum":let o=t.T();for(let c=0;c<e.length;c++){M(e[c]===void 0||typeof e[c]=="number");let l=this.enum(o,e[c],t.name,t.opt,!0,i.enumAsInteger);M(l!==void 0),s.push(l)}break;case"message":let a=t.T();for(let c=0;c<e.length;c++){let l=this.message(a,e[c],t.name,i);M(l!==void 0),s.push(l)}break}(i.emitDefaultValues||s.length>0||i.emitDefaultValues)&&(n=s)}else switch(t.kind){case"scalar":n=this.scalar(t.T,e,t.name,t.opt,i.emitDefaultValues);break;case"enum":n=this.enum(t.T(),e,t.name,t.opt,i.emitDefaultValues,i.enumAsInteger);break;case"message":n=this.message(t.T(),e,t.name,i);break}return n}enum(t,e,i,n,s,o){if(t[0]=="google.protobuf.NullValue")return!s&&!n?void 0:null;if(e===void 0){M(n);return}if(!(e===0&&!s&&!n))return M(typeof e=="number"),M(Number.isInteger(e)),o||!t[1].hasOwnProperty(e)?e:t[2]?t[2]+t[1][e]:t[1][e]}message(t,e,i,n){return e===void 0?n.emitDefaultValues?null:void 0:t.internalJsonWrite(e,n)}scalar(t,e,i,n,s){if(e===void 0){M(n);return}let o=s||n;switch(t){case h.INT32:case h.SFIXED32:case h.SINT32:return e===0?o?0:void 0:(Re(e),e);case h.FIXED32:case h.UINT32:return e===0?o?0:void 0:(dr(e),e);case h.FLOAT:Mr(e);case h.DOUBLE:return e===0?o?0:void 0:(M(typeof e=="number"),Number.isNaN(e)?"NaN":e===Number.POSITIVE_INFINITY?"Infinity":e===Number.NEGATIVE_INFINITY?"-Infinity":e);case h.STRING:return e===""?o?"":void 0:(M(typeof e=="string"),e);case h.BOOL:return e===!1?o?!1:void 0:(M(typeof e=="boolean"),e);case h.UINT64:case h.FIXED64:M(typeof e=="number"||typeof e=="string"||typeof e=="bigint");let a=ht.from(e);return a.isZero()&&!o?void 0:a.toString();case h.INT64:case h.SFIXED64:case h.SINT64:M(typeof e=="number"||typeof e=="string"||typeof e=="bigint");let c=X.from(e);return c.isZero()&&!o?void 0:c.toString();case h.BYTES:return M(e instanceof Uint8Array),e.byteLength?Ci(e):o?"":void 0}}};function Vi(r,t=Dt.STRING){switch(r){case h.BOOL:return!1;case h.UINT64:case h.FIXED64:return Lt(ht.ZERO,t);case h.INT64:case h.SFIXED64:case h.SINT64:return Lt(X.ZERO,t);case h.DOUBLE:case h.FLOAT:return 0;case h.BYTES:return new Uint8Array(0);case h.STRING:return"";default:return 0}}var us=class{constructor(t){this.info=t}prepare(){var t;if(!this.fieldNoToField){let e=(t=this.info.fields)!==null&&t!==void 0?t:[];this.fieldNoToField=new Map(e.map(i=>[i.no,i]))}}read(t,e,i,n){this.prepare();let s=n===void 0?t.len:t.pos+n;for(;t.pos<s;){let[o,a]=t.tag(),c=this.fieldNoToField.get(o);if(!c){let p=i.readUnknownField;if(p=="throw")throw new Error(`Unknown field ${o} (wire type ${a}) for ${this.info.typeName}`);let m=t.skip(a);p!==!1&&(p===!0?Ur.onRead:p)(this.info.typeName,e,o,a,m);continue}let l=e,u=c.repeat,d=c.localName;switch(c.oneof&&(l=l[c.oneof],l.oneofKind!==d&&(l=e[c.oneof]={oneofKind:d})),c.kind){case"scalar":case"enum":let p=c.kind=="enum"?h.INT32:c.T,m=c.kind=="scalar"?c.L:void 0;if(u){let at=l[d];if(a==st.LengthDelimited&&p!=h.STRING&&p!=h.BYTES){let dt=t.uint32()+t.pos;for(;t.pos<dt;)at.push(this.scalar(t,p,m))}else at.push(this.scalar(t,p,m))}else l[d]=this.scalar(t,p,m);break;case"message":if(u){let at=l[d],dt=c.T().internalBinaryRead(t,t.uint32(),i);at.push(dt)}else l[d]=c.T().internalBinaryRead(t,t.uint32(),i,l[d]);break;case"map":let[_,j]=this.mapEntry(c,t,i);l[d][_]=j;break}}}mapEntry(t,e,i){let n=e.uint32(),s=e.pos+n,o,a;for(;e.pos<s;){let[c,l]=e.tag();switch(c){case 1:t.K==h.BOOL?o=e.bool().toString():o=this.scalar(e,t.K,Dt.STRING);break;case 2:switch(t.V.kind){case"scalar":a=this.scalar(e,t.V.T,t.V.L);break;case"enum":a=e.int32();break;case"message":a=t.V.T().internalBinaryRead(e,e.uint32(),i);break}break;default:throw new Error(`Unknown field ${c} (wire type ${l}) in map entry for ${this.info.typeName}#${t.name}`)}}if(o===void 0){let c=Vi(t.K);o=t.K==h.BOOL?c.toString():c}if(a===void 0)switch(t.V.kind){case"scalar":a=Vi(t.V.T,t.V.L);break;case"enum":a=0;break;case"message":a=t.V.T().create();break}return[o,a]}scalar(t,e,i){switch(e){case h.INT32:return t.int32();case h.STRING:return t.string();case h.BOOL:return t.bool();case h.DOUBLE:return t.double();case h.FLOAT:return t.float();case h.INT64:return Lt(t.int64(),i);case h.UINT64:return Lt(t.uint64(),i);case h.FIXED64:return Lt(t.fixed64(),i);case h.FIXED32:return t.fixed32();case h.BYTES:return t.bytes();case h.UINT32:return t.uint32();case h.SFIXED32:return t.sfixed32();case h.SFIXED64:return Lt(t.sfixed64(),i);case h.SINT32:return t.sint32();case h.SINT64:return Lt(t.sint64(),i)}}};var fs=class{constructor(t){this.info=t}prepare(){if(!this.fields){let t=this.info.fields?this.info.fields.concat():[];this.fields=t.sort((e,i)=>e.no-i.no)}}write(t,e,i){this.prepare();for(let s of this.fields){let o,a,c=s.repeat,l=s.localName;if(s.oneof){let u=t[s.oneof];if(u.oneofKind!==l)continue;o=u[l],a=!0}else o=t[l],a=!1;switch(s.kind){case"scalar":case"enum":let u=s.kind=="enum"?h.INT32:s.T;if(c)if(M(Array.isArray(o)),c==ki.PACKED)this.packed(e,u,s.no,o);else for(let d of o)this.scalar(e,u,s.no,d,!0);else o===void 0?M(s.opt):this.scalar(e,u,s.no,o,a||s.opt);break;case"message":if(c){M(Array.isArray(o));for(let d of o)this.message(e,i,s.T(),s.no,d)}else this.message(e,i,s.T(),s.no,o);break;case"map":M(typeof o=="object"&&o!==null);for(let[d,p]of Object.entries(o))this.mapEntry(e,i,s,d,p);break}}let n=i.writeUnknownFields;n!==!1&&(n===!0?Ur.onWrite:n)(this.info.typeName,t,e)}mapEntry(t,e,i,n,s){t.tag(i.no,st.LengthDelimited),t.fork();let o=n;switch(i.K){case h.INT32:case h.FIXED32:case h.UINT32:case h.SFIXED32:case h.SINT32:o=Number.parseInt(n);break;case h.BOOL:M(n=="true"||n=="false"),o=n=="true";break}switch(this.scalar(t,i.K,1,o,!0),i.V.kind){case"scalar":this.scalar(t,i.V.T,2,s,!0);break;case"enum":this.scalar(t,h.INT32,2,s,!0);break;case"message":this.message(t,e,i.V.T(),2,s);break}t.join()}message(t,e,i,n,s){s!==void 0&&(i.internalBinaryWrite(s,t.tag(n,st.LengthDelimited).fork(),e),t.join())}scalar(t,e,i,n,s){let[o,a,c]=this.scalarInfo(e,n);(!c||s)&&(t.tag(i,o),t[a](n))}packed(t,e,i,n){if(!n.length)return;M(e!==h.BYTES&&e!==h.STRING),t.tag(i,st.LengthDelimited),t.fork();let[,s]=this.scalarInfo(e);for(let o=0;o<n.length;o++)t[s](n[o]);t.join()}scalarInfo(t,e){let i=st.Varint,n,s=e===void 0,o=e===0;switch(t){case h.INT32:n="int32";break;case h.STRING:o=s||!e.length,i=st.LengthDelimited,n="string";break;case h.BOOL:o=e===!1,n="bool";break;case h.UINT32:n="uint32";break;case h.DOUBLE:i=st.Bit64,n="double";break;case h.FLOAT:i=st.Bit32,n="float";break;case h.INT64:o=s||X.from(e).isZero(),n="int64";break;case h.UINT64:o=s||ht.from(e).isZero(),n="uint64";break;case h.FIXED64:o=s||ht.from(e).isZero(),i=st.Bit64,n="fixed64";break;case h.BYTES:o=s||!e.byteLength,i=st.LengthDelimited,n="bytes";break;case h.FIXED32:i=st.Bit32,n="fixed32";break;case h.SFIXED32:i=st.Bit32,n="sfixed32";break;case h.SFIXED64:o=s||X.from(e).isZero(),i=st.Bit64,n="sfixed64";break;case h.SINT32:n="sint32";break;case h.SINT64:o=s||X.from(e).isZero(),n="sint64";break}return[i,n,s||o]}};function Ul(r){let t=r.messagePrototype?Object.create(r.messagePrototype):Object.defineProperty({},os,{value:r});for(let e of r.fields){let i=e.localName;if(!e.opt)if(e.oneof)t[e.oneof]={oneofKind:void 0};else if(e.repeat)t[i]=[];else switch(e.kind){case"scalar":t[i]=Vi(e.T,e.L);break;case"enum":t[i]=0;break;case"map":t[i]={};break}}return t}function ds(r,t,e){let i,n=e,s;for(let o of r.fields){let a=o.localName;if(o.oneof){let c=n[o.oneof];if((c==null?void 0:c.oneofKind)==null)continue;if(i=c[a],s=t[o.oneof],s.oneofKind=c.oneofKind,i==null){delete s[a];continue}}else if(i=n[a],s=t,i==null)continue;switch(o.repeat&&(s[a].length=i.length),o.kind){case"scalar":case"enum":if(o.repeat)for(let l=0;l<i.length;l++)s[a][l]=i[l];else s[a]=i;break;case"message":let c=o.T();if(o.repeat)for(let l=0;l<i.length;l++)s[a][l]=c.create(i[l]);else s[a]===void 0?s[a]=c.create(i):c.mergePartial(s[a],i);break;case"map":switch(o.V.kind){case"scalar":case"enum":Object.assign(s[a],i);break;case"message":let l=o.V.T();for(let u of Object.keys(i))s[a][u]=l.create(i[u]);break}break}}}function Cl(r,t,e){if(t===e)return!0;if(!t||!e)return!1;for(let i of r.fields){let n=i.localName,s=i.oneof?t[i.oneof][n]:t[n],o=i.oneof?e[i.oneof][n]:e[n];switch(i.kind){case"enum":case"scalar":let a=i.kind=="enum"?h.INT32:i.T;if(!(i.repeat?Ml(a,s,o):kl(a,s,o)))return!1;break;case"map":if(!(i.V.kind=="message"?Rl(i.V.T(),hs(s),hs(o)):Ml(i.V.kind=="enum"?h.INT32:i.V.T,hs(s),hs(o))))return!1;break;case"message":let c=i.T();if(!(i.repeat?Rl(c,s,o):c.equals(s,o)))return!1;break}}return!0}var hs=Object.values;function kl(r,t,e){if(t===e)return!0;if(r!==h.BYTES)return!1;let i=t,n=e;if(i.length!==n.length)return!1;for(let s=0;s<i.length;s++)if(i[s]!=n[s])return!1;return!0}function Ml(r,t,e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!kl(r,t[i],e[i]))return!1;return!0}function Rl(r,t,e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!r.equals(t[i],e[i]))return!1;return!0}var Vl=Object.getOwnPropertyDescriptors(Object.getPrototypeOf({})),gd=Vl[os]={},rt=class{constructor(t,e,i){this.defaultCheckDepth=16,this.typeName=t,this.fields=e.map(El),this.options=i!=null?i:{},gd.value=this,this.messagePrototype=Object.create(null,Vl),this.refTypeCheck=new as(this),this.refJsonReader=new cs(this),this.refJsonWriter=new ls(this),this.refBinReader=new us(this),this.refBinWriter=new fs(this)}create(t){let e=Ul(this);return t!==void 0&&ds(this,e,t),e}clone(t){let e=this.create();return ds(this,e,t),e}equals(t,e){return Cl(this,t,e)}is(t,e=this.defaultCheckDepth){return this.refTypeCheck.is(t,e,!1)}isAssignable(t,e=this.defaultCheckDepth){return this.refTypeCheck.is(t,e,!0)}mergePartial(t,e){ds(this,t,e)}fromBinary(t,e){let i=Ol(e);return this.internalBinaryRead(i.readerFactory(t),t.byteLength,i)}fromJson(t,e){return this.internalJsonRead(t,Sa(e))}fromJsonString(t,e){let i=JSON.parse(t);return this.fromJson(i,e)}toJson(t,e){return this.internalJsonWrite(t,xa(e))}toJsonString(t,e){var i;let n=this.toJson(t,e);return JSON.stringify(n,null,(i=e==null?void 0:e.prettySpaces)!==null&&i!==void 0?i:0)}toBinary(t,e){let i=Al(e);return this.internalBinaryWrite(t,i.writerFactory(),i).finish()}in