Comparing version 1.0.0 to 1.0.1
@@ -1,2 +0,2 @@ | ||
var _e=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var Qe=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)};var i=(t,e,r)=>(Qe(t,e,"read from private field"),r?r.call(t):e.get(t)),a=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},m=(t,e,r,n)=>(Qe(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),Oe=(t,e,r,n)=>({set _(s){m(t,e,s,r)},get _(){return i(t,e,n)}}),p=(t,e,r)=>(Qe(t,e,"access private method"),r);var Re={default:new URL("https://db.fauna.com"),local:new URL("http://localhost:8443"),localhost:new URL("http://localhost:8443")};var C=class extends Error{constructor(...e){super(...e)}},c=class extends C{httpStatus;code;queryInfo;constraint_failures;constructor(e,r){super(e.error.message),Error.captureStackTrace&&Error.captureStackTrace(this,c),this.name="ServiceError",this.code=e.error.code,this.httpStatus=r;let n={txn_ts:e.txn_ts,summary:e.summary,query_tags:e.query_tags,stats:e.stats};this.queryInfo=n,this.constraint_failures=e.error.constraint_failures}},H=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,H),this.name="QueryRuntimeError"}},P=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,P),this.name="QueryCheckError"}},N=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,N),this.name="InvalidRequestError"}},ne=class extends c{abort;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,P),this.name="AbortError",this.abort=e.error.abort}},F=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,F),this.name="AuthenticationError"}},M=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,M),this.name="AuthorizationError"}},se=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,N),this.name="ContendedTransactionError"}},W=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,W),this.name="ThrottlingError"}},v=class extends c{stats;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,v),this.name="QueryTimeoutError",this.stats=e.stats}},j=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,j),this.name="ServiceInternalError"}},$=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,$),this.name="ServiceTimeoutError"}},b=class extends C{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,b),this.name="ClientError"}},k=class extends C{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,k),this.name="ClientClosedError"}},w=class extends C{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,w),this.name="NetworkError"}},E=class extends C{httpStatus;constructor(e){super(e.message),Error.captureStackTrace&&Error.captureStackTrace(this,E),this.name="ProtocolError",this.httpStatus=e.httpStatus}};var oe=class{#e;#t;constructor({url:e,fetch_keepalive:r}){this.#e=new URL("/query/1",e).toString(),this.#t=r}async request({data:e,headers:r,method:n,client_timeout_ms:s}){let o=await fetch(this.#e,{method:n,headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(e),signal:AbortSignal.timeout(s),keepalive:this.#t}).catch(l=>{throw new w("The network connection encountered a problem.",{cause:l})}),u=o.status,d={};o.headers.forEach((l,g)=>d[g]=l);let S=await o.text();return{status:u,body:S,headers:d}}close(){}};var L;try{L=_e("node:http2")}catch{L=void 0}var z,ie,ae,ue,I,f,me,Ve,J,le,pe,qe,fe,He,U=class{constructor({http2_session_idle_ms:e,url:r,http2_max_streams:n}){a(this,J);a(this,pe);a(this,fe);a(this,ie,void 0);a(this,ae,void 0);a(this,ue,void 0);a(this,I,0);a(this,f,void 0);if(L===void 0)throw new Error("Your platform does not support Node's http2 library");m(this,ie,e),m(this,ae,n),m(this,ue,r),m(this,f,null)}static getClient(e){var s;let r=p(s=U,me,Ve).call(s,e);i(U,z).has(r)||i(U,z).set(r,new U(e));let n=i(U,z).get(r);return Oe(n,I)._++,n}async request(e){let r=0,n;do try{return await p(this,fe,He).call(this,e)}catch(s){if(s?.code!=="ERR_HTTP2_GOAWAY_SESSION")throw new w("The network connection encountered a problem.",{cause:s});n=s,r++}while(r<3);throw new w("The network connection encountered a problem.",{cause:n})}close(){this.isClosed()||(Oe(this,I)._--,i(this,I)===0&&i(this,f)&&!i(this,f).closed&&i(this,f).close())}isClosed(){return i(this,I)===0}},G=U;z=new WeakMap,ie=new WeakMap,ae=new WeakMap,ue=new WeakMap,I=new WeakMap,f=new WeakMap,me=new WeakSet,Ve=function({http2_session_idle_ms:e,url:r}){return`${r}|${e}`},J=new WeakSet,le=function(){m(this,I,0),i(this,f)&&!i(this,f).closed&&i(this,f).close()},pe=new WeakSet,qe=function(){if(!i(this,f)||i(this,f).closed||i(this,f).destroyed){let e=L.connect(i(this,ue),{peerMaxConcurrentStreams:i(this,ae)}).once("error",()=>p(this,J,le).call(this)).once("goaway",()=>p(this,J,le).call(this));e.setTimeout(i(this,ie),()=>{p(this,J,le).call(this)}),m(this,f,e)}return i(this,f)},fe=new WeakSet,He=function({client_timeout_ms:e,data:r,headers:n,method:s}){return new Promise((o,u)=>{let d,S=l=>{let g=Number(l[L.constants.HTTP2_HEADER_STATUS]),x="";d.on("data",re=>{x+=re}),d.on("end",()=>{o({status:g,body:x,headers:l})})};try{let l={...n,[L.constants.HTTP2_HEADER_PATH]:"/query/1",[L.constants.HTTP2_HEADER_METHOD]:s};d=p(this,pe,qe).call(this).request(l).setEncoding("utf8").on("error",x=>{u(x)}).on("response",S),d.write(JSON.stringify(r),"utf8"),d.setTimeout(e,()=>{d.destroy(new Error("Client timeout"))}),d.end()}catch(l){u(l)}})},a(G,me),a(G,z,new Map);var Ce=t=>ot()?G.getClient(t):new oe(t),Pe=t=>t instanceof Object&&"body"in t&&"headers"in t&&"status"in t,ot=()=>{if(typeof process<"u"&&process&&process.release?.name==="node")try{return _e("node:http2"),!0}catch{return!1}return!1};var it=/(?:\d{4}|[\u2212-]\d{4,}|\+\d{5,})/,at=/(?:0[1-9]|1[0-2])/,ut=/(?:0[1-9]|[12]\d|3[01])/,Fe=/(?:[01][0-9]|2[0-3])/,ce=/(?:[0-5][0-9])/,ct=/(?:\.\d+)/,Ne=new RegExp(`(${it.source}-(${at.source})-(${ut.source}))`),dt=new RegExp(`(${Fe.source}:${ce.source}:${ce.source}${ct.source}?)`),lt=new RegExp(`([zZ]|[+\u2212-]${Fe.source}(?::?${ce.source}|:${ce.source}:${ce.source}))`),Me=new RegExp(`^${Ne.source}$`),We=new RegExp(`^${Ne.source}`),ve=new RegExp(`^${Ne.source}T${dt.source}${lt.source}$`);var _=class{isoString;constructor(e){this.isoString=e}static from(e){if(typeof e!="string")throw new TypeError(`Expected string but received ${typeof e}: ${e}`);if(ve.exec(e)===null)throw new RangeError(`(regex) Expected an ISO date string but received '${e}'`);return new _(e)}static fromDate(e){return new _(e.toISOString())}toDate(){let e=new Date(this.isoString);if(e.toString()==="Invalid Date")throw new RangeError("Fauna Date could not be converted to Javascript Date");return e}toString(){return`TimeStub("${this.isoString}")`}},Q=class{dateString;constructor(e){this.dateString=e}static from(e){if(typeof e!="string")throw new TypeError(`Expected string but received ${typeof e}: ${e}`);let r=Me.exec(e);if(r===null)throw new RangeError(`Expected a plain date string but received '${e}'`);return new Q(r[0])}static fromDate(e){let r=e.toISOString(),n=We.exec(r);if(n===null)throw new b(`Failed to parse date '${e}'`);return new Q(n[0])}toDate(){let e=new Date(this.dateString+"T00:00:00Z");if(e.toString()==="Invalid Date")throw new RangeError("Fauna Date could not be converted to Javascript Date");return e}toString(){return`DateStub("${this.dateString}")`}};var A=class{coll;id;constructor({coll:e,id:r}){this.id=r,typeof e=="string"?this.coll=new D(e):this.coll=e}},K=class extends A{ts;constructor(e){let{coll:r,id:n,ts:s,...o}=e;super({coll:r,id:n}),this.ts=s,Object.assign(this,o)}toObject(){return{...this}}},B=class{coll;name;constructor({coll:e,name:r}){this.name=r,typeof e=="string"?this.coll=new D(e):this.coll=e}},Z=class extends B{ts;data;constructor(e){let{coll:r,name:n,ts:s,data:o,...u}=e;super({coll:r,name:n}),this.ts=s,this.data=o||{},Object.assign(this,u)}toObject(){return{...this}}},D=class{name;constructor(e){this.name=e}},ee=class{ref;cause;constructor(e,r){this.ref=e,this.cause=r}};var O=class{data;after;constructor({data:e,after:r}){this.data=e,this.after=r}},V=class{after;constructor(e){this.after=e}},R=class{#e;constructor(e,r,n){if(n=n??{},r instanceof Function)this.#e=pt(e,r,n);else if(r instanceof O||r instanceof V)this.#e=je(e,r,n);else throw new TypeError(`Expected 'Page<T> | EmbeddedSet | (() => Promise<T | Page<T> | EmbeddedSet>)', but received ${JSON.stringify(r)}`)}static fromQuery(e,r,n){return new R(e,async()=>(await e.query(r,n)).data,n)}static fromPageable(e,r,n){return new R(e,r,n)}flatten(){return new ke(this)}async next(){return this.#e.next()}async return(){return this.#e.return()}async throw(e){return this.#e.throw(e)}[Symbol.asyncIterator](){return this}},ke=class{#e;constructor(e){this.#e=ft(e)}async next(){return this.#e.next()}async return(){return this.#e.return()}async throw(e){return this.#e.throw(e)}[Symbol.asyncIterator](){return this}};async function*je(t,e,r){let n=e;for(n instanceof O&&(yield n.data);n.after;){let s=Ie`Set.paginate(${n.after})`;n=(await t.query(s,r)).data,yield n.data}}async function*pt(t,e,r){let n=await e();if(n instanceof O||n instanceof V){for await(let s of je(t,n,r))yield s;return}yield[n]}async function*ft(t){for await(let e of t)for(let r of e)yield r}var q=class{static encode(e){return ye(e)}static decode(e,r){return JSON.parse(e,(n,s)=>{if(s==null)return null;if(s["@mod"])return new D(s["@mod"]);if(s["@doc"]){if(typeof s["@doc"]=="string"){let[u,d]=s["@doc"].split(":");return new A({coll:u,id:d})}let o=s["@doc"];return o.id?new K(o):new Z(o)}else if(s["@ref"]){let o=s["@ref"],u;return o.id?u=new A(o):u=new B(o),"exists"in o&&o.exists===!1?new ee(u,o.cause):u}else{if(s["@set"])return typeof s["@set"]=="string"?new V(s["@set"]):new O(s["@set"]);if(s["@int"])return Number(s["@int"]);if(s["@long"]){let o=BigInt(s["@long"]);return r.long_type==="number"?((o>Number.MAX_SAFE_INTEGER||o<Number.MIN_SAFE_INTEGER)&&console.warn("Value is too large to be represented as a number. Returning as Number with loss of precision. Use long_type 'bigint' instead."),Number(o)):o}else{if(s["@double"])return Number(s["@double"]);if(s["@date"])return Q.from(s["@date"]);if(s["@time"])return _.from(s["@time"]);if(s["@object"])return s["@object"]}}return s})}},Ue=BigInt("-9223372036854775808"),Ge=BigInt("9223372036854775807"),$e=-(2**31),Le=2**31-1,y={bigint:t=>{if(t<Ue||t>Ge)throw new RangeError("BigInt value exceeds max magnitude for a 64-bit Fauna long. Use a 'number' to represent doubles beyond that limit.");return t>=$e&&t<=Le?{"@int":t.toString()}:{"@long":t.toString()}},number:t=>{if(t===Number.POSITIVE_INFINITY||t===Number.NEGATIVE_INFINITY)throw new RangeError(`Cannot convert ${t} to a Fauna type.`);return Number.isInteger(t)?t>=$e&&t<=Le?{"@int":t.toString()}:Number.isSafeInteger(t)?{"@long":t.toString()}:{"@double":t.toString()}:{"@double":t.toString()}},string:t=>t,object:t=>{let e=!1,r={};for(let n in t)n.startsWith("@")&&(e=!0),t[n]!==void 0&&(r[n]=ye(t[n]));return e?{"@object":r}:r},array:t=>{let e=[];for(let r in t)e.push(ye(t[r]));return e},date:t=>({"@time":t.toISOString()}),faunadate:t=>({"@date":t.dateString}),faunatime:t=>({"@time":t.isoString}),module:t=>({"@mod":t.name}),documentReference:t=>({"@ref":{id:t.id,coll:{"@mod":t.coll.name}}}),document:t=>({"@ref":{id:t.id,coll:{"@mod":t.coll.name}}}),namedDocumentReference:t=>({"@ref":{name:t.name,coll:{"@mod":t.coll.name}}}),namedDocument:t=>({"@ref":{name:t.name,coll:{"@mod":t.coll.name}}}),set:t=>{throw new b("Page could not be encoded. Fauna does not accept encoded Set values, yet. Use Page.data and Page.after as arguments, instead.")}},ye=t=>{if(t===void 0)throw new TypeError("Passing undefined as a QueryValue is not supported");switch(typeof t){case"bigint":return y.bigint(t);case"string":return y.string(t);case"number":return y.number(t);case"boolean":return t;case"object":return t==null?null:Array.isArray(t)?y.array(t):t instanceof Date?y.date(t):t instanceof Q?y.faunadate(t):t instanceof _?y.faunatime(t):t instanceof D?y.module(t):t instanceof K?y.document(t):t instanceof A?y.documentReference(t):t instanceof Z?y.namedDocument(t):t instanceof B?y.namedDocumentReference(t):t instanceof ee?ye(t.ref):t instanceof O||t instanceof V?y.set(t):y.object(t)}};function Ie(t,...e){return new X(t,...e)}var X=class{#e;#t;constructor(e,...r){if(e.length===0||e.length!==r.length+1)throw new Error("invalid query constructed");this.#e=e,this.#t=r}toQuery(e={}){return{...this.#r(e),...e}}#r(e){if(this.#e.length===1)return{query:{fql:[this.#e[0]]},arguments:{}};let r={};return{query:{fql:this.#e.flatMap((s,o)=>{if(o===this.#e.length-1)return s===""?[]:[s];let u=this.#t[o],d;if(u instanceof X){let S=u.toQuery(e);d=S.query,r={...r,...S.arguments}}else d={value:q.encode(u)};return[s,d].filter(S=>S!=="")})},arguments:r}}};var Be="1.0.0";var ge;try{ge=_e("node:os")}catch{ge=void 0}var ze=()=>{let t={driver:["javascript",Be].join("-"),env:"unknown",os:"unknown",runtime:"unknown"};try{let e=typeof window>"u"&&typeof process<"u"&&process.versions!=null&&process.versions.node!=null,r=typeof window<"u"&&typeof window.document<"u",n=typeof self=="object"&&self.constructor&&self.constructor.name==="DedicatedWorkerGlobalScope";e?(t.runtime=["nodejs",process.version].join("-"),t.env=gt(),t.os=[ge.platform(),ge.release()].join("-")):n?(t.runtime=Xe(navigator),t.env="Service Worker",t.os=Ye(navigator)):r?(t.runtime=Xe(navigator),t.env="browser",t.os=Ye(navigator)):typeof EdgeRuntime!="string"&&(t.runtime="Vercel Edge Runtime",t.env="edge")}catch{}return Object.entries(t).filter(([e,r])=>r!=="unknown").map(e=>e.join("=")).join("; ")},Xe=t=>{let e=t.appName,r=""+parseFloat(t.appVersion),n,s,o;return(s=t.userAgent.indexOf("Opera"))!=-1?(e="Opera",r=t.userAgent.substring(s+6),(s=t.userAgent.indexOf("Version"))!=-1&&(r=t.userAgent.substring(s+8))):(s=t.userAgent.indexOf("MSIE"))!=-1?(e="Microsoft Internet Explorer",r=t.userAgent.substring(s+5)):e=="Netscape"&&t.userAgent.indexOf("Trident/")!=-1?(e="Microsoft Internet Explorer",r=t.userAgent.substring(s+5),(s=t.userAgent.indexOf("rv:"))!=-1&&(r=t.userAgent.substring(s+3))):(s=t.userAgent.indexOf("Chrome"))!=-1?(e="Chrome",r=t.userAgent.substring(s+7)):(s=t.userAgent.indexOf("Safari"))!=-1?(e="Safari",r=t.userAgent.substring(s+7),(s=t.userAgent.indexOf("Version"))!=-1&&(r=t.userAgent.substring(s+8)),t.userAgent.indexOf("CriOS")!=-1&&(e="Chrome")):(s=t.userAgent.indexOf("Firefox"))!=-1?(e="Firefox",r=t.userAgent.substring(s+8)):(n=t.userAgent.lastIndexOf(" ")+1)<(s=t.userAgent.lastIndexOf("/"))&&(e=t.userAgent.substring(n,s),r=t.userAgent.substring(s+1),e.toLowerCase()==e.toUpperCase()&&(e=t.appName)),(o=r.indexOf(";"))!=-1&&(r=r.substring(0,o)),(o=r.indexOf(" "))!=-1&&(r=r.substring(0,o)),(o=r.indexOf(")"))!=-1&&(r=r.substring(0,o)),[e,r].join("-")},Ye=t=>{let e="unknown",r=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(let s in r){let o=r[s];if(o.r.test(t.userAgent)){e=o.s;break}}let n="unknown";if(/Windows/.test(e)){let s=/Windows (.*)/.exec(e);s&&(n=s[1]),e="Windows"}switch(e){case"Mac OS":case"Mac OS X":case"Android":{let s=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(t.userAgent);s&&(n=s[1]);break}case"iOS":{let s=/OS (\d+)_(\d+)_?(\d+)?/.exec(t.appVersion);s&&(n=s[1]+"."+s[2]+"."+(s[3]??0));break}}return[e,n].join("-")},yt=typeof window<"u"?window:typeof globalThis<"u"?globalThis:typeof global<"u"?global:self,gt=()=>{if(!(typeof process<"u"&&process&&process.env&&typeof process.env=="object"))return"unknown";let e=[{name:"Netlify",check:function(){return!!process.env.NETLIFY_IMAGES_CDN_DOMAIN}},{name:"Vercel",check:function(){return!!process.env.VERCEL}},{name:"Heroku",check:function(){return!!process.env.PATH&&process.env.PATH.indexOf(".heroku")!==-1}},{name:"AWS Lambda",check:function(){return!!process.env.AWS_LAMBDA_FUNCTION_VERSION}},{name:"GCP Cloud Functions",check:function(){return!!process.env._&&process.env._.indexOf("google")!==-1}},{name:"GCP Compute Instances",check:function(){return!!process.env.GOOGLE_CLOUD_PROJECT}},{name:"Azure Cloud Functions",check:function(){return!!process.env.WEBSITE_FUNCTIONS_AZUREMONITOR_CATEGORIES}},{name:"Azure Compute",check:function(){return!!process.env.ORYX_ENV_TYPE&&!!process.env.WEBSITE_INSTANCE_ID&&process.env.ORYX_ENV_TYPE==="AppService"}},{name:"Mongo Stitch",check:function(){return typeof yt?.StitchError=="function"}},{name:"Render",check:function(){return!!process.env.RENDER_SERVICE_ID}},{name:"Begin",check:function(){return!!process.env.BEGIN_DATA_SCOPE_ID}}].find(r=>r.check());return e?e.name:"unknown"};var Je=t=>t instanceof Object&&"data"in t,Ke=t=>t instanceof Object&&"error"in t&&t.error instanceof Object&&"code"in t.error&&"message"in t.error;var Tt={client_timeout_buffer_ms:5e3,endpoint:Re.default,format:"tagged",http2_session_idle_ms:5e3,http2_max_streams:100,long_type:"number",fetch_keepalive:!1,query_timeout_ms:5e3},he,T,Y,h,te,de,Ae,be,Ze,we,et,Se,tt,xe,rt,Ee,nt,De=class{constructor(e,r){a(this,de);a(this,be);a(this,we);a(this,Se);a(this,xe);a(this,Ee);a(this,T,void 0);a(this,Y,void 0);a(this,h,void 0);a(this,te,!1);m(this,T,{...Tt,...e,secret:p(this,be,Ze).call(this,e)}),p(this,Ee,nt).call(this),r?m(this,Y,r):m(this,Y,Ce({url:i(this,T).endpoint.toString(),http2_session_idle_ms:i(this,T).http2_session_idle_ms,http2_max_streams:i(this,T).http2_max_streams,fetch_keepalive:i(this,T).fetch_keepalive}))}get lastTxnTs(){return i(this,h)}set lastTxnTs(e){m(this,h,i(this,h)?Math.max(e,i(this,h)):e)}get clientConfiguration(){let{secret:e,...r}=i(this,T);return r}close(){if(i(this,te))throw new k("Your client is closed. You cannot close it again.");i(this,Y).close(),m(this,te,!0)}paginate(e,r){return e instanceof X?R.fromQuery(this,e,r):R.fromPageable(this,e,r)}async query(e,r){if(i(this,te))throw new k("Your client is closed. No further requests can be issued.");let n=e.toQuery(r).query;return p(this,Se,tt).call(this,n,r)}},Te=De;he=new WeakMap,T=new WeakMap,Y=new WeakMap,h=new WeakMap,te=new WeakMap,de=new WeakSet,Ae=function(e){if(e instanceof b||e instanceof w||e instanceof E||e instanceof c)return e;if(Pe(e)){if(Ke(e.body)){let r=e.body,n=e.status;return p(this,we,et).call(this,r,n)}return new E({message:`Response is in an unkown format: ${e.body}`,httpStatus:e.status})}return new b("A client level error occurred. Fauna was not called.",{cause:e})},be=new WeakSet,Ze=function(e){let r;typeof process<"u"&&process&&typeof process=="object"&&process.env&&typeof process.env=="object"&&(r=process.env.FAUNA_SECRET);let n=e?.secret||r;if(n===void 0)throw new Error("You must provide a secret to the driver. Set it in an environmental variable named FAUNA_SECRET or pass it to the Client constructor.");return n},we=new WeakSet,et=function(e,r){switch(r){case 400:return ht.includes(e.error.code)?new P(e,r):e.error.code==="invalid_request"?new N(e,r):e.error.code==="abort"&&e.error.abort!==void 0?new ne(e,r):new H(e,r);case 401:return new F(e,r);case 403:return new M(e,r);case 409:return new se(e,r);case 429:return new W(e,r);case 440:return new v(e,r);case 500:return new j(e,r);case 503:return new $(e,r);default:return new c(e,r)}},Se=new WeakSet,tt=async function(e,r){try{let n={...i(this,T),...r},s={Authorization:`Bearer ${i(this,T).secret}`};p(this,xe,rt).call(this,n,s);let o=n.format==="tagged",u=n.arguments?o?q.encode(n.arguments):n.arguments:void 0,d={query:e,arguments:u},S=n.query_timeout_ms+i(this,T).client_timeout_buffer_ms,l=await i(this,Y).request({client_timeout_ms:S,data:d,headers:s,method:"POST"}),g;try{if(g={...l,body:o?q.decode(l.body,{long_type:n.long_type}):JSON.parse(l.body)},g.body.query_tags){let re=g.body.query_tags.split(",").map(st=>st.split("="));g.body.query_tags=Object.fromEntries(re)}}catch(re){throw new E({message:`Error parsing response as JSON: ${re}`,httpStatus:l.status})}if(!Je(g.body))throw p(this,de,Ae).call(this,g);let x=g.body.txn_ts;return(i(this,h)===void 0&&x!==void 0||x!==void 0&&i(this,h)!==void 0&&i(this,h)<x)&&m(this,h,x),g.body}catch(n){throw p(this,de,Ae).call(this,n)}},xe=new WeakSet,rt=function(e,r){for(let n of Object.entries(e))if(["format","query_timeout_ms","linearized","max_contention_retries","traceparent","typecheck","query_tags"].includes(n[0])){let s,o=`x-${n[0].replaceAll("_","-")}`;n[0]==="query_tags"?s=Object.entries(n[1]).map(u=>u.join("=")).join(","):typeof n[1]=="string"?s=n[1]:s=String(n[1]),n[0]==="traceparent"&&(o=n[0]),r[o]=s}r["x-last-txn-ts"]===void 0&&i(this,h)!==void 0&&(r["x-last-txn-ts"]=i(this,h)),r["x-driver-env"]=i(De,he)},Ee=new WeakSet,nt=function(){let e=i(this,T);if(["client_timeout_buffer_ms","endpoint","format","http2_session_idle_ms","long_type","query_timeout_ms","fetch_keepalive","http2_max_streams"].forEach(n=>{if(e[n]===void 0)throw new TypeError(`ClientConfiguration option '${n}' must be defined.`)}),e.http2_max_streams<=0)throw new RangeError("'http2_max_streams' must be greater than zero.");if(e.client_timeout_buffer_ms<=0)throw new RangeError("'client_timeout_buffer_ms' must be greater than zero.");if(e.query_timeout_ms<=0)throw new RangeError("'query_timeout_ms' must be greater than zero.")},a(Te,he,ze());var ht=["invalid_function_definition","invalid_identifier","invalid_query","invalid_syntax","invalid_type"];export{ne as AbortError,F as AuthenticationError,M as AuthorizationError,Te as Client,k as ClientClosedError,b as ClientError,se as ContendedTransactionError,Q as DateStub,K as Document,A as DocumentReference,V as EmbeddedSet,C as FaunaError,oe as FetchClient,N as InvalidRequestError,Ge as LONG_MAX,Ue as LONG_MIN,D as Module,Z as NamedDocument,B as NamedDocumentReference,w as NetworkError,G as NodeHTTP2Client,ee as NullDocument,O as Page,E as ProtocolError,P as QueryCheckError,H as QueryRuntimeError,v as QueryTimeoutError,c as ServiceError,j as ServiceInternalError,$ as ServiceTimeoutError,R as SetIterator,q as TaggedTypeFormat,W as ThrottlingError,_ as TimeStub,Re as endpoints,Ie as fql,Ce as getDefaultHTTPClient,Pe as isHTTPResponse}; | ||
var _e=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var Qe=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)};var i=(t,e,r)=>(Qe(t,e,"read from private field"),r?r.call(t):e.get(t)),u=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},m=(t,e,r,s)=>(Qe(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r),Oe=(t,e,r,s)=>({set _(n){m(t,e,n,r)},get _(){return i(t,e,s)}}),p=(t,e,r)=>(Qe(t,e,"access private method"),r);var Re={default:new URL("https://db.fauna.com"),local:new URL("http://localhost:8443"),localhost:new URL("http://localhost:8443")};var C=class extends Error{constructor(...e){super(...e)}},c=class extends C{httpStatus;code;queryInfo;constraint_failures;constructor(e,r){super(e.error.message),Error.captureStackTrace&&Error.captureStackTrace(this,c),this.name="ServiceError",this.code=e.error.code,this.httpStatus=r;let s={txn_ts:e.txn_ts,summary:e.summary,query_tags:e.query_tags,stats:e.stats};this.queryInfo=s,this.constraint_failures=e.error.constraint_failures}},H=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,H),this.name="QueryRuntimeError"}},P=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,P),this.name="QueryCheckError"}},N=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,N),this.name="InvalidRequestError"}},ne=class extends c{abort;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,P),this.name="AbortError",this.abort=e.error.abort}},F=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,F),this.name="AuthenticationError"}},M=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,M),this.name="AuthorizationError"}},se=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,N),this.name="ContendedTransactionError"}},W=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,W),this.name="ThrottlingError"}},v=class extends c{stats;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,v),this.name="QueryTimeoutError",this.stats=e.stats}},j=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,j),this.name="ServiceInternalError"}},$=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,$),this.name="ServiceTimeoutError"}},w=class extends C{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,w),this.name="ClientError"}},k=class extends C{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,k),this.name="ClientClosedError"}},S=class extends C{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,S),this.name="NetworkError"}},E=class extends C{httpStatus;constructor(e){super(e.message),Error.captureStackTrace&&Error.captureStackTrace(this,E),this.name="ProtocolError",this.httpStatus=e.httpStatus}};var oe=class{#e;#t;constructor({url:e,fetch_keepalive:r}){this.#e=new URL("/query/1",e).toString(),this.#t=r}async request({data:e,headers:r,method:s,client_timeout_ms:n}){let o=AbortSignal.timeout===void 0?(()=>{let d=new AbortController,T=d.signal;return setTimeout(()=>d.abort(),n),T})():AbortSignal.timeout(n),a=await fetch(this.#e,{method:s,headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(e),signal:o,keepalive:this.#t}).catch(d=>{throw new S("The network connection encountered a problem.",{cause:d})}),l=a.status,x={};a.headers.forEach((d,T)=>x[T]=d);let g=await a.text();return{status:l,body:g,headers:x}}close(){}};var L;try{L=_e("node:http2")}catch{L=void 0}var z,ie,ae,ue,I,f,me,Ve,J,le,pe,qe,fe,He,U=class{constructor({http2_session_idle_ms:e,url:r,http2_max_streams:s}){u(this,J);u(this,pe);u(this,fe);u(this,ie,void 0);u(this,ae,void 0);u(this,ue,void 0);u(this,I,0);u(this,f,void 0);if(L===void 0)throw new Error("Your platform does not support Node's http2 library");m(this,ie,e),m(this,ae,s),m(this,ue,r),m(this,f,null)}static getClient(e){var n;let r=p(n=U,me,Ve).call(n,e);i(U,z).has(r)||i(U,z).set(r,new U(e));let s=i(U,z).get(r);return Oe(s,I)._++,s}async request(e){let r=0,s;do try{return await p(this,fe,He).call(this,e)}catch(n){if(n?.code!=="ERR_HTTP2_GOAWAY_SESSION")throw new S("The network connection encountered a problem.",{cause:n});s=n,r++}while(r<3);throw new S("The network connection encountered a problem.",{cause:s})}close(){this.isClosed()||(Oe(this,I)._--,i(this,I)===0&&i(this,f)&&!i(this,f).closed&&i(this,f).close())}isClosed(){return i(this,I)===0}},G=U;z=new WeakMap,ie=new WeakMap,ae=new WeakMap,ue=new WeakMap,I=new WeakMap,f=new WeakMap,me=new WeakSet,Ve=function({http2_session_idle_ms:e,url:r}){return`${r}|${e}`},J=new WeakSet,le=function(){m(this,I,0),i(this,f)&&!i(this,f).closed&&i(this,f).close()},pe=new WeakSet,qe=function(){if(!i(this,f)||i(this,f).closed||i(this,f).destroyed){let e=L.connect(i(this,ue),{peerMaxConcurrentStreams:i(this,ae)}).once("error",()=>p(this,J,le).call(this)).once("goaway",()=>p(this,J,le).call(this));e.setTimeout(i(this,ie),()=>{p(this,J,le).call(this)}),m(this,f,e)}return i(this,f)},fe=new WeakSet,He=function({client_timeout_ms:e,data:r,headers:s,method:n}){return new Promise((o,a)=>{let l,x=g=>{let d=Number(g[L.constants.HTTP2_HEADER_STATUS]),T="";l.on("data",re=>{T+=re}),l.on("end",()=>{o({status:d,body:T,headers:g})})};try{let g={...s,[L.constants.HTTP2_HEADER_PATH]:"/query/1",[L.constants.HTTP2_HEADER_METHOD]:n};l=p(this,pe,qe).call(this).request(g).setEncoding("utf8").on("error",T=>{a(T)}).on("response",x),l.write(JSON.stringify(r),"utf8"),l.setTimeout(e,()=>{l.destroy(new Error("Client timeout"))}),l.end()}catch(g){a(g)}})},u(G,me),u(G,z,new Map);var Ce=t=>ot()?G.getClient(t):new oe(t),Pe=t=>t instanceof Object&&"body"in t&&"headers"in t&&"status"in t,ot=()=>{if(typeof process<"u"&&process&&process.release?.name==="node")try{return _e("node:http2"),!0}catch{return!1}return!1};var it=/(?:\d{4}|[\u2212-]\d{4,}|\+\d{5,})/,at=/(?:0[1-9]|1[0-2])/,ut=/(?:0[1-9]|[12]\d|3[01])/,Fe=/(?:[01][0-9]|2[0-3])/,ce=/(?:[0-5][0-9])/,ct=/(?:\.\d+)/,Ne=new RegExp(`(${it.source}-(${at.source})-(${ut.source}))`),dt=new RegExp(`(${Fe.source}:${ce.source}:${ce.source}${ct.source}?)`),lt=new RegExp(`([zZ]|[+\u2212-]${Fe.source}(?::?${ce.source}|:${ce.source}:${ce.source}))`),Me=new RegExp(`^${Ne.source}$`),We=new RegExp(`^${Ne.source}`),ve=new RegExp(`^${Ne.source}T${dt.source}${lt.source}$`);var _=class{isoString;constructor(e){this.isoString=e}static from(e){if(typeof e!="string")throw new TypeError(`Expected string but received ${typeof e}: ${e}`);if(ve.exec(e)===null)throw new RangeError(`(regex) Expected an ISO date string but received '${e}'`);return new _(e)}static fromDate(e){return new _(e.toISOString())}toDate(){let e=new Date(this.isoString);if(e.toString()==="Invalid Date")throw new RangeError("Fauna Date could not be converted to Javascript Date");return e}toString(){return`TimeStub("${this.isoString}")`}},Q=class{dateString;constructor(e){this.dateString=e}static from(e){if(typeof e!="string")throw new TypeError(`Expected string but received ${typeof e}: ${e}`);let r=Me.exec(e);if(r===null)throw new RangeError(`Expected a plain date string but received '${e}'`);return new Q(r[0])}static fromDate(e){let r=e.toISOString(),s=We.exec(r);if(s===null)throw new w(`Failed to parse date '${e}'`);return new Q(s[0])}toDate(){let e=new Date(this.dateString+"T00:00:00Z");if(e.toString()==="Invalid Date")throw new RangeError("Fauna Date could not be converted to Javascript Date");return e}toString(){return`DateStub("${this.dateString}")`}};var A=class{coll;id;constructor({coll:e,id:r}){this.id=r,typeof e=="string"?this.coll=new D(e):this.coll=e}},K=class extends A{ts;constructor(e){let{coll:r,id:s,ts:n,...o}=e;super({coll:r,id:s}),this.ts=n,Object.assign(this,o)}toObject(){return{...this}}},B=class{coll;name;constructor({coll:e,name:r}){this.name=r,typeof e=="string"?this.coll=new D(e):this.coll=e}},Z=class extends B{ts;data;constructor(e){let{coll:r,name:s,ts:n,data:o,...a}=e;super({coll:r,name:s}),this.ts=n,this.data=o||{},Object.assign(this,a)}toObject(){return{...this}}},D=class{name;constructor(e){this.name=e}},ee=class{ref;cause;constructor(e,r){this.ref=e,this.cause=r}};var O=class{data;after;constructor({data:e,after:r}){this.data=e,this.after=r}},V=class{after;constructor(e){this.after=e}},R=class{#e;constructor(e,r,s){if(s=s??{},r instanceof Function)this.#e=pt(e,r,s);else if(r instanceof O||r instanceof V)this.#e=je(e,r,s);else throw new TypeError(`Expected 'Page<T> | EmbeddedSet | (() => Promise<T | Page<T> | EmbeddedSet>)', but received ${JSON.stringify(r)}`)}static fromQuery(e,r,s){return new R(e,async()=>(await e.query(r,s)).data,s)}static fromPageable(e,r,s){return new R(e,r,s)}flatten(){return new ke(this)}async next(){return this.#e.next()}async return(){return this.#e.return()}async throw(e){return this.#e.throw(e)}[Symbol.asyncIterator](){return this}},ke=class{#e;constructor(e){this.#e=ft(e)}async next(){return this.#e.next()}async return(){return this.#e.return()}async throw(e){return this.#e.throw(e)}[Symbol.asyncIterator](){return this}};async function*je(t,e,r){let s=e;for(s instanceof O&&(yield s.data);s.after;){let n=Ie`Set.paginate(${s.after})`;s=(await t.query(n,r)).data,yield s.data}}async function*pt(t,e,r){let s=await e();if(s instanceof O||s instanceof V){for await(let n of je(t,s,r))yield n;return}yield[s]}async function*ft(t){for await(let e of t)for(let r of e)yield r}var q=class{static encode(e){return ye(e)}static decode(e,r){return JSON.parse(e,(s,n)=>{if(n==null)return null;if(n["@mod"])return new D(n["@mod"]);if(n["@doc"]){if(typeof n["@doc"]=="string"){let[a,l]=n["@doc"].split(":");return new A({coll:a,id:l})}let o=n["@doc"];return o.id?new K(o):new Z(o)}else if(n["@ref"]){let o=n["@ref"],a;return o.id?a=new A(o):a=new B(o),"exists"in o&&o.exists===!1?new ee(a,o.cause):a}else{if(n["@set"])return typeof n["@set"]=="string"?new V(n["@set"]):new O(n["@set"]);if(n["@int"])return Number(n["@int"]);if(n["@long"]){let o=BigInt(n["@long"]);return r.long_type==="number"?((o>Number.MAX_SAFE_INTEGER||o<Number.MIN_SAFE_INTEGER)&&console.warn("Value is too large to be represented as a number. Returning as Number with loss of precision. Use long_type 'bigint' instead."),Number(o)):o}else{if(n["@double"])return Number(n["@double"]);if(n["@date"])return Q.from(n["@date"]);if(n["@time"])return _.from(n["@time"]);if(n["@object"])return n["@object"]}}return n})}},Ue=BigInt("-9223372036854775808"),Ge=BigInt("9223372036854775807"),$e=-(2**31),Le=2**31-1,y={bigint:t=>{if(t<Ue||t>Ge)throw new RangeError("BigInt value exceeds max magnitude for a 64-bit Fauna long. Use a 'number' to represent doubles beyond that limit.");return t>=$e&&t<=Le?{"@int":t.toString()}:{"@long":t.toString()}},number:t=>{if(t===Number.POSITIVE_INFINITY||t===Number.NEGATIVE_INFINITY)throw new RangeError(`Cannot convert ${t} to a Fauna type.`);return Number.isInteger(t)?t>=$e&&t<=Le?{"@int":t.toString()}:Number.isSafeInteger(t)?{"@long":t.toString()}:{"@double":t.toString()}:{"@double":t.toString()}},string:t=>t,object:t=>{let e=!1,r={};for(let s in t)s.startsWith("@")&&(e=!0),t[s]!==void 0&&(r[s]=ye(t[s]));return e?{"@object":r}:r},array:t=>{let e=[];for(let r in t)e.push(ye(t[r]));return e},date:t=>({"@time":t.toISOString()}),faunadate:t=>({"@date":t.dateString}),faunatime:t=>({"@time":t.isoString}),module:t=>({"@mod":t.name}),documentReference:t=>({"@ref":{id:t.id,coll:{"@mod":t.coll.name}}}),document:t=>({"@ref":{id:t.id,coll:{"@mod":t.coll.name}}}),namedDocumentReference:t=>({"@ref":{name:t.name,coll:{"@mod":t.coll.name}}}),namedDocument:t=>({"@ref":{name:t.name,coll:{"@mod":t.coll.name}}}),set:t=>{throw new w("Page could not be encoded. Fauna does not accept encoded Set values, yet. Use Page.data and Page.after as arguments, instead.")}},ye=t=>{if(t===void 0)throw new TypeError("Passing undefined as a QueryValue is not supported");switch(typeof t){case"bigint":return y.bigint(t);case"string":return y.string(t);case"number":return y.number(t);case"boolean":return t;case"object":return t==null?null:Array.isArray(t)?y.array(t):t instanceof Date?y.date(t):t instanceof Q?y.faunadate(t):t instanceof _?y.faunatime(t):t instanceof D?y.module(t):t instanceof K?y.document(t):t instanceof A?y.documentReference(t):t instanceof Z?y.namedDocument(t):t instanceof B?y.namedDocumentReference(t):t instanceof ee?ye(t.ref):t instanceof O||t instanceof V?y.set(t):y.object(t)}};function Ie(t,...e){return new X(t,...e)}var X=class{#e;#t;constructor(e,...r){if(e.length===0||e.length!==r.length+1)throw new Error("invalid query constructed");this.#e=e,this.#t=r}toQuery(e={}){return{...this.#r(e),...e}}#r(e){if(this.#e.length===1)return{query:{fql:[this.#e[0]]},arguments:{}};let r={};return{query:{fql:this.#e.flatMap((n,o)=>{if(o===this.#e.length-1)return n===""?[]:[n];let a=this.#t[o],l;if(a instanceof X){let x=a.toQuery(e);l=x.query,r={...r,...x.arguments}}else l={value:q.encode(a)};return[n,l].filter(x=>x!=="")})},arguments:r}}};var Be="1.0.1";var ge;try{ge=_e("node:os")}catch{ge=void 0}var ze=()=>{let t={driver:["javascript",Be].join("-"),env:"unknown",os:"unknown",runtime:"unknown"};try{let e=typeof window>"u"&&typeof process<"u"&&process.versions!=null&&process.versions.node!=null,r=typeof window<"u"&&typeof window.document<"u",s=typeof self=="object"&&self.constructor&&self.constructor.name==="DedicatedWorkerGlobalScope";e?(t.runtime=["nodejs",process.version].join("-"),t.env=gt(),t.os=[ge.platform(),ge.release()].join("-")):s?(t.runtime=Xe(navigator),t.env="Service Worker",t.os=Ye(navigator)):r?(t.runtime=Xe(navigator),t.env="browser",t.os=Ye(navigator)):typeof EdgeRuntime!="string"&&(t.runtime="Vercel Edge Runtime",t.env="edge")}catch{}return Object.entries(t).filter(([e,r])=>r!=="unknown").map(e=>e.join("=")).join("; ")},Xe=t=>{let e=t.appName,r=""+parseFloat(t.appVersion),s,n,o;return(n=t.userAgent.indexOf("Opera"))!=-1?(e="Opera",r=t.userAgent.substring(n+6),(n=t.userAgent.indexOf("Version"))!=-1&&(r=t.userAgent.substring(n+8))):(n=t.userAgent.indexOf("MSIE"))!=-1?(e="Microsoft Internet Explorer",r=t.userAgent.substring(n+5)):e=="Netscape"&&t.userAgent.indexOf("Trident/")!=-1?(e="Microsoft Internet Explorer",r=t.userAgent.substring(n+5),(n=t.userAgent.indexOf("rv:"))!=-1&&(r=t.userAgent.substring(n+3))):(n=t.userAgent.indexOf("Chrome"))!=-1?(e="Chrome",r=t.userAgent.substring(n+7)):(n=t.userAgent.indexOf("Safari"))!=-1?(e="Safari",r=t.userAgent.substring(n+7),(n=t.userAgent.indexOf("Version"))!=-1&&(r=t.userAgent.substring(n+8)),t.userAgent.indexOf("CriOS")!=-1&&(e="Chrome")):(n=t.userAgent.indexOf("Firefox"))!=-1?(e="Firefox",r=t.userAgent.substring(n+8)):(s=t.userAgent.lastIndexOf(" ")+1)<(n=t.userAgent.lastIndexOf("/"))&&(e=t.userAgent.substring(s,n),r=t.userAgent.substring(n+1),e.toLowerCase()==e.toUpperCase()&&(e=t.appName)),(o=r.indexOf(";"))!=-1&&(r=r.substring(0,o)),(o=r.indexOf(" "))!=-1&&(r=r.substring(0,o)),(o=r.indexOf(")"))!=-1&&(r=r.substring(0,o)),[e,r].join("-")},Ye=t=>{let e="unknown",r=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(let n in r){let o=r[n];if(o.r.test(t.userAgent)){e=o.s;break}}let s="unknown";if(/Windows/.test(e)){let n=/Windows (.*)/.exec(e);n&&(s=n[1]),e="Windows"}switch(e){case"Mac OS":case"Mac OS X":case"Android":{let n=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(t.userAgent);n&&(s=n[1]);break}case"iOS":{let n=/OS (\d+)_(\d+)_?(\d+)?/.exec(t.appVersion);n&&(s=n[1]+"."+n[2]+"."+(n[3]??0));break}}return[e,s].join("-")},yt=typeof window<"u"?window:typeof globalThis<"u"?globalThis:typeof global<"u"?global:self,gt=()=>{if(!(typeof process<"u"&&process&&process.env&&typeof process.env=="object"))return"unknown";let e=[{name:"Netlify",check:function(){return!!process.env.NETLIFY_IMAGES_CDN_DOMAIN}},{name:"Vercel",check:function(){return!!process.env.VERCEL}},{name:"Heroku",check:function(){return!!process.env.PATH&&process.env.PATH.indexOf(".heroku")!==-1}},{name:"AWS Lambda",check:function(){return!!process.env.AWS_LAMBDA_FUNCTION_VERSION}},{name:"GCP Cloud Functions",check:function(){return!!process.env._&&process.env._.indexOf("google")!==-1}},{name:"GCP Compute Instances",check:function(){return!!process.env.GOOGLE_CLOUD_PROJECT}},{name:"Azure Cloud Functions",check:function(){return!!process.env.WEBSITE_FUNCTIONS_AZUREMONITOR_CATEGORIES}},{name:"Azure Compute",check:function(){return!!process.env.ORYX_ENV_TYPE&&!!process.env.WEBSITE_INSTANCE_ID&&process.env.ORYX_ENV_TYPE==="AppService"}},{name:"Mongo Stitch",check:function(){return typeof yt?.StitchError=="function"}},{name:"Render",check:function(){return!!process.env.RENDER_SERVICE_ID}},{name:"Begin",check:function(){return!!process.env.BEGIN_DATA_SCOPE_ID}}].find(r=>r.check());return e?e.name:"unknown"};var Je=t=>t instanceof Object&&"data"in t,Ke=t=>t instanceof Object&&"error"in t&&t.error instanceof Object&&"code"in t.error&&"message"in t.error;var Tt={client_timeout_buffer_ms:5e3,endpoint:Re.default,format:"tagged",http2_session_idle_ms:5e3,http2_max_streams:100,long_type:"number",fetch_keepalive:!1,query_timeout_ms:5e3},he,h,Y,b,te,de,Ae,be,Ze,we,et,Se,tt,xe,rt,Ee,nt,De=class{constructor(e,r){u(this,de);u(this,be);u(this,we);u(this,Se);u(this,xe);u(this,Ee);u(this,h,void 0);u(this,Y,void 0);u(this,b,void 0);u(this,te,!1);m(this,h,{...Tt,...e,secret:p(this,be,Ze).call(this,e)}),p(this,Ee,nt).call(this),r?m(this,Y,r):m(this,Y,Ce({url:i(this,h).endpoint.toString(),http2_session_idle_ms:i(this,h).http2_session_idle_ms,http2_max_streams:i(this,h).http2_max_streams,fetch_keepalive:i(this,h).fetch_keepalive}))}get lastTxnTs(){return i(this,b)}set lastTxnTs(e){m(this,b,i(this,b)?Math.max(e,i(this,b)):e)}get clientConfiguration(){let{secret:e,...r}=i(this,h);return r}close(){if(i(this,te))throw new k("Your client is closed. You cannot close it again.");i(this,Y).close(),m(this,te,!0)}paginate(e,r){return e instanceof X?R.fromQuery(this,e,r):R.fromPageable(this,e,r)}async query(e,r){if(i(this,te))throw new k("Your client is closed. No further requests can be issued.");let s=e.toQuery(r).query;return p(this,Se,tt).call(this,s,r)}},Te=De;he=new WeakMap,h=new WeakMap,Y=new WeakMap,b=new WeakMap,te=new WeakMap,de=new WeakSet,Ae=function(e){if(e instanceof w||e instanceof S||e instanceof E||e instanceof c)return e;if(Pe(e)){if(Ke(e.body)){let r=e.body,s=e.status;return p(this,we,et).call(this,r,s)}return new E({message:`Response is in an unkown format: ${e.body}`,httpStatus:e.status})}return new w("A client level error occurred. Fauna was not called.",{cause:e})},be=new WeakSet,Ze=function(e){let r;typeof process<"u"&&process&&typeof process=="object"&&process.env&&typeof process.env=="object"&&(r=process.env.FAUNA_SECRET);let s=e?.secret||r;if(s===void 0)throw new Error("You must provide a secret to the driver. Set it in an environmental variable named FAUNA_SECRET or pass it to the Client constructor.");return s},we=new WeakSet,et=function(e,r){switch(r){case 400:return ht.includes(e.error.code)?new P(e,r):e.error.code==="invalid_request"?new N(e,r):e.error.code==="abort"&&e.error.abort!==void 0?new ne(e,r):new H(e,r);case 401:return new F(e,r);case 403:return new M(e,r);case 409:return new se(e,r);case 429:return new W(e,r);case 440:return new v(e,r);case 500:return new j(e,r);case 503:return new $(e,r);default:return new c(e,r)}},Se=new WeakSet,tt=async function(e,r){try{let s={...i(this,h),...r},n={Authorization:`Bearer ${i(this,h).secret}`};p(this,xe,rt).call(this,s,n);let o=s.format==="tagged",a=s.arguments?o?q.encode(s.arguments):s.arguments:void 0,l={query:e,arguments:a},x=s.query_timeout_ms+i(this,h).client_timeout_buffer_ms,g=await i(this,Y).request({client_timeout_ms:x,data:l,headers:n,method:"POST"}),d;try{if(d={...g,body:o?q.decode(g.body,{long_type:s.long_type}):JSON.parse(g.body)},d.body.query_tags){let re=d.body.query_tags.split(",").map(st=>st.split("="));d.body.query_tags=Object.fromEntries(re)}}catch(re){throw new E({message:`Error parsing response as JSON: ${re}`,httpStatus:g.status})}if(!Je(d.body))throw p(this,de,Ae).call(this,d);let T=d.body.txn_ts;return(i(this,b)===void 0&&T!==void 0||T!==void 0&&i(this,b)!==void 0&&i(this,b)<T)&&m(this,b,T),d.body}catch(s){throw p(this,de,Ae).call(this,s)}},xe=new WeakSet,rt=function(e,r){for(let s of Object.entries(e))if(["format","query_timeout_ms","linearized","max_contention_retries","traceparent","typecheck","query_tags"].includes(s[0])){let n,o=`x-${s[0].replaceAll("_","-")}`;s[0]==="query_tags"?n=Object.entries(s[1]).map(a=>a.join("=")).join(","):typeof s[1]=="string"?n=s[1]:n=String(s[1]),s[0]==="traceparent"&&(o=s[0]),r[o]=n}r["x-last-txn-ts"]===void 0&&i(this,b)!==void 0&&(r["x-last-txn-ts"]=i(this,b)),r["x-driver-env"]=i(De,he)},Ee=new WeakSet,nt=function(){let e=i(this,h);if(["client_timeout_buffer_ms","endpoint","format","http2_session_idle_ms","long_type","query_timeout_ms","fetch_keepalive","http2_max_streams"].forEach(s=>{if(e[s]===void 0)throw new TypeError(`ClientConfiguration option '${s}' must be defined.`)}),e.http2_max_streams<=0)throw new RangeError("'http2_max_streams' must be greater than zero.");if(e.client_timeout_buffer_ms<=0)throw new RangeError("'client_timeout_buffer_ms' must be greater than zero.");if(e.query_timeout_ms<=0)throw new RangeError("'query_timeout_ms' must be greater than zero.")},u(Te,he,ze());var ht=["invalid_function_definition","invalid_identifier","invalid_query","invalid_syntax","invalid_type"];export{ne as AbortError,F as AuthenticationError,M as AuthorizationError,Te as Client,k as ClientClosedError,w as ClientError,se as ContendedTransactionError,Q as DateStub,K as Document,A as DocumentReference,V as EmbeddedSet,C as FaunaError,oe as FetchClient,N as InvalidRequestError,Ge as LONG_MAX,Ue as LONG_MIN,D as Module,Z as NamedDocument,B as NamedDocumentReference,S as NetworkError,G as NodeHTTP2Client,ee as NullDocument,O as Page,E as ProtocolError,P as QueryCheckError,H as QueryRuntimeError,v as QueryTimeoutError,c as ServiceError,j as ServiceInternalError,$ as ServiceTimeoutError,R as SetIterator,q as TaggedTypeFormat,W as ThrottlingError,_ as TimeStub,Re as endpoints,Ie as fql,Ce as getDefaultHTTPClient,Pe as isHTTPResponse}; | ||
//# sourceMappingURL=index.js.map |
@@ -286,2 +286,8 @@ "use strict"; | ||
}) { | ||
const signal = AbortSignal.timeout === void 0 ? (() => { | ||
const controller = new AbortController(); | ||
const signal2 = controller.signal; | ||
setTimeout(() => controller.abort(), client_timeout_ms); | ||
return signal2; | ||
})() : AbortSignal.timeout(client_timeout_ms); | ||
const response = await fetch(this.#url, { | ||
@@ -291,3 +297,3 @@ method, | ||
body: JSON.stringify(data), | ||
signal: AbortSignal.timeout(client_timeout_ms), | ||
signal, | ||
keepalive: this.#keepalive | ||
@@ -1002,3 +1008,3 @@ }).catch((error) => { | ||
// src/util/package-version.ts | ||
var packageVersion = "1.0.0"; | ||
var packageVersion = "1.0.1"; | ||
@@ -1005,0 +1011,0 @@ // src/util/environment.ts |
/** The current package version. */ | ||
export declare const packageVersion = "1.0.0"; | ||
export declare const packageVersion = "1.0.1"; |
{ | ||
"name": "fauna", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A driver to query Fauna databases in browsers, Node.js, and other Javascript runtimes", | ||
@@ -5,0 +5,0 @@ "homepage": "https://fauna.com", |
@@ -31,2 +31,12 @@ /** following reference needed to include types for experimental fetch API in Node */ | ||
}: HTTPRequest): Promise<HTTPResponse> { | ||
const signal = | ||
AbortSignal.timeout === undefined | ||
? (() => { | ||
const controller = new AbortController(); | ||
const signal = controller.signal; | ||
setTimeout(() => controller.abort(), client_timeout_ms); | ||
return signal; | ||
})() | ||
: AbortSignal.timeout(client_timeout_ms); | ||
const response = await fetch(this.#url, { | ||
@@ -36,3 +46,3 @@ method, | ||
body: JSON.stringify(data), | ||
signal: AbortSignal.timeout(client_timeout_ms), | ||
signal, | ||
keepalive: this.#keepalive, | ||
@@ -39,0 +49,0 @@ }).catch((error) => { |
//THIS FILE IS AUTOGENERATED. DO NOT EDIT. SEE .husky/pre-commit | ||
/** The current package version. */ | ||
export const packageVersion = "1.0.0"; | ||
export const packageVersion = "1.0.1"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
499318
5948