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

fauna

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fauna - npm Package Compare versions

Comparing version 0.7.2 to 0.8.0

2

dist/browser/index.js

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

var Ee=(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 o=(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)},p=(t,e,r,n)=>(Qe(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),_e=(t,e,r,n)=>({set _(s){p(t,e,s,r)},get _(){return o(t,e,n)}}),m=(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 V=class extends Error{constructor(...e){super(...e)}},u=class extends V{httpStatus;code;queryInfo;constraint_failures;constructor(e,r){super(e.error.message),Error.captureStackTrace&&Error.captureStackTrace(this,u),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}},q=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,q),this.name="QueryRuntimeError"}},C=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,C),this.name="QueryCheckError"}},O=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,O),this.name="InvalidRequestError"}},re=class extends u{abort;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,C),this.name="AbortError",this.abort=e.error.abort}},F=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,F),this.name="AuthenticationError"}},W=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,W),this.name="AuthorizationError"}},ne=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,O),this.name="ContendedTransactionError"}},M=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,M),this.name="ThrottlingError"}},j=class extends u{stats;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,j),this.name="QueryTimeoutError",this.stats=e.stats}},v=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,v),this.name="ServiceInternalError"}},$=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,$),this.name="ServiceTimeoutError"}},h=class extends V{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,h),this.name="ClientError"}},k=class extends V{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,k),this.name="ClientClosedError"}},b=class extends V{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,b),this.name="NetworkError"}},x=class extends V{httpStatus;constructor(e){super(e.message),Error.captureStackTrace&&Error.captureStackTrace(this,x),this.name="ProtocolError",this.httpStatus=e.httpStatus}};var se=class{#e;constructor({url:e}){this.#e=new URL("/query/1",e).toString()}async request({data:e,headers:r,method:n,client_timeout_ms:s}){let i=await fetch(this.#e,{method:n,headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(e),signal:AbortSignal.timeout(s)}).catch(c=>{throw new b("The network connection encountered a problem.",{cause:c})}),d=i.status,l={};i.headers.forEach((c,S)=>l[S]=c);let g=await i.text();return{status:d,body:g,headers:l}}close(){}};var L;try{L=Ee("node:http2")}catch{L=void 0}var z,oe,ie,A,y,de,De,J,ue,le,He,me,Ve,U=class{constructor({http2_session_idle_ms:e,url:r}){a(this,J);a(this,le);a(this,me);a(this,oe,void 0);a(this,ie,void 0);a(this,A,0);a(this,y,void 0);if(L===void 0)throw new Error("Your platform does not support Node's http2 library");p(this,oe,e),p(this,ie,r),p(this,y,null)}static getClient(e){var s;let r=m(s=U,de,De).call(s,e);o(U,z).has(r)||o(U,z).set(r,new U(e));let n=o(U,z).get(r);return _e(n,A)._++,n}async request(e){let r=0,n;do try{return await m(this,me,Ve).call(this,e)}catch(s){if(s?.code!=="ERR_HTTP2_GOAWAY_SESSION")throw new b("The network connection encountered a problem.",{cause:s});n=s,r++}while(r<3);throw new b("The network connection encountered a problem.",{cause:n})}close(){this.isClosed()||(_e(this,A)._--,o(this,A)===0&&o(this,y)&&!o(this,y).closed&&o(this,y).close())}isClosed(){return o(this,A)===0}},G=U;z=new WeakMap,oe=new WeakMap,ie=new WeakMap,A=new WeakMap,y=new WeakMap,de=new WeakSet,De=function({http2_session_idle_ms:e,url:r}){return`${r}|${e}`},J=new WeakSet,ue=function(){p(this,A,0),o(this,y)&&!o(this,y).closed&&o(this,y).close()},le=new WeakSet,He=function(){if(!o(this,y)||o(this,y).closed){let e=L.connect(o(this,ie)).once("error",()=>m(this,J,ue).call(this)).once("goaway",()=>m(this,J,ue).call(this));e.setTimeout(o(this,oe),()=>{m(this,J,ue).call(this)}),p(this,y,e)}return o(this,y)},me=new WeakSet,Ve=function({client_timeout_ms:e,data:r,headers:n,method:s}){return new Promise((i,d)=>{let l,g=c=>{let S=Number(c[L.constants.HTTP2_HEADER_STATUS]),P="";l.on("data",xe=>{P+=xe}),l.on("end",()=>{i({status:S,body:P,headers:c})})};try{let c={...n,[L.constants.HTTP2_HEADER_PATH]:"/query/1",[L.constants.HTTP2_HEADER_METHOD]:s};l=m(this,le,He).call(this).request(c).setEncoding("utf8").on("error",P=>{d(P)}).on("response",g),l.write(JSON.stringify(r),"utf8"),l.setTimeout(e,()=>{l.destroy(new Error("Client timeout"))}),l.end()}catch(c){d(c)}})},a(G,de),a(G,z,new Map);var Pe=t=>tt()?G.getClient(t):new se(t),Ce=t=>t instanceof Object&&"body"in t&&"headers"in t&&"status"in t,tt=()=>{if(typeof process<"u"&&process.release?.name==="node")try{return Ee("node:http2"),!0}catch{return!1}return!1};var rt=/(?:\d{4}|[\u2212-]\d{4,}|\+\d{5,})/,nt=/(?:0[1-9]|1[0-2])/,st=/(?:0[1-9]|[12]\d|3[01])/,qe=/(?:[01][0-9]|2[0-3])/,ae=/(?:[0-5][0-9])/,ot=/(?:\.\d+)/,Oe=new RegExp(`(${rt.source}-(${nt.source})-(${st.source}))`),it=new RegExp(`(${qe.source}:${ae.source}:${ae.source}${ot.source}?)`),at=new RegExp(`([zZ]|[+\u2212-]${qe.source}(?::?${ae.source}|:${ae.source}:${ae.source}))`),Fe=new RegExp(`^${Oe.source}$`),We=new RegExp(`^${Oe.source}`),Me=new RegExp(`^${Oe.source}T${it.source}${at.source}$`);var E=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(Me.exec(e)===null)throw new RangeError(`(regex) Expected an ISO date string but received '${e}'`);return new E(e)}static fromDate(e){return new E(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=Fe.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 h(`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 N=class{coll;id;constructor({coll:e,id:r}){this.id=r,typeof e=="string"?this.coll=new I(e):this.coll=e}},K=class extends N{ts;constructor(e){let{coll:r,id:n,ts:s,...i}=e;super({coll:r,id:n}),this.ts=s,Object.assign(this,i)}toObject(){return{...this}}},B=class{coll;name;constructor({coll:e,name:r}){this.name=r,typeof e=="string"?this.coll=new I(e):this.coll=e}},Z=class extends B{ts;data;constructor(e){let{coll:r,name:n,ts:s,data:i,...d}=e;super({coll:r,name:n}),this.ts=s,this.data=i||{},Object.assign(this,d)}toObject(){return{...this}}},I=class{name;constructor(e){this.name=e}},ee=class{ref;cause;constructor(e,r){this.ref=e,this.cause=r}};var _=class{data;after;constructor({data:e,after:r}){this.data=e,this.after=r}},D=class{after;constructor(e){this.after=e}},R=class{#e;constructor(e,r){if(r instanceof Function)this.#e=ut(e,r);else if(r instanceof _||r instanceof D)this.#e=je(e,r);else throw new TypeError(`Expected 'Page<T> | EmbeddedSet | (() => Promise<T | Page<T> | EmbeddedSet>)', but received ${JSON.stringify(r)}`)}static fromQuery(e,r){return new R(e,async()=>(await e.query(r)).data)}static fromPageable(e,r){return new R(e,r)}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=dt(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){let r=e;for(r instanceof _&&(yield r.data);r.after;){let n=Ae`Set.paginate(${r.after})`;r=(await t.query(n)).data,yield r.data}}async function*ut(t,e){let r=await e();if(r instanceof _||r instanceof D){for await(let n of je(t,r))yield n;return}yield[r]}async function*dt(t){for await(let e of t)for(let r of e)yield r}var H=class{static encode(e){return fe(e)}static decode(e){return JSON.parse(e,(r,n)=>{if(n==null)return null;if(n["@mod"])return new I(n["@mod"]);if(n["@doc"]){if(typeof n["@doc"]=="string"){let[i,d]=n["@doc"].split(":");return new N({coll:i,id:d})}let s=n["@doc"];return s.id?new K(s):new Z(s)}else if(n["@ref"]){let s=n["@ref"],i;return s.id?i=new N(s):i=new B(s),"exists"in s&&s.exists===!1?new ee(i,s.cause):i}else{if(n["@set"])return typeof n["@set"]=="string"?new D(n["@set"]):new _(n["@set"]);if(n["@int"])return Number(n["@int"]);if(n["@long"])return BigInt(n["@long"]);if(n["@double"])return Number(n["@double"]);if(n["@date"])return Q.from(n["@date"]);if(n["@time"])return E.from(n["@time"]);if(n["@object"])return n["@object"]}return n})}},ve=BigInt("-9223372036854775808"),$e=BigInt("9223372036854775807"),f={bigint:t=>{if(t<ve||t>$e)throw new RangeError("Precision loss when converting BigInt to Fauna type");return{"@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`${t}`.includes(".")?{"@double":t.toString()}:t>=-(2**31)&&t<=2**31-1?{"@int":t.toString()}:Number.isSafeInteger(t)?{"@long":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]=fe(t[n]));return e?{"@object":r}:r},array:t=>{let e=[];for(let r in t)e.push(fe(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 h("Page could not be encoded. Fauna does not accept encoded Set values, yet. Use Page.data and Page.after as arguments, instead.")}},fe=t=>{if(t===void 0)throw new TypeError("Passing undefined as a QueryValue is not supported");switch(typeof t){case"bigint":return f.bigint(t);case"string":return f.string(t);case"number":return f.number(t);case"boolean":return t;case"object":return t==null?null:Array.isArray(t)?f.array(t):t instanceof Date?f.date(t):t instanceof Q?f.faunadate(t):t instanceof E?f.faunatime(t):t instanceof I?f.module(t):t instanceof K?f.document(t):t instanceof N?f.documentReference(t):t instanceof Z?f.namedDocument(t):t instanceof B?f.namedDocumentReference(t):t instanceof ee?fe(t.ref):t instanceof _||t instanceof D?f.set(t):f.object(t)}};function Ae(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,i)=>{if(i===this.#e.length-1)return s===""?[]:[s];let d=this.#t[i],l;if(d instanceof X){let g=d.toQuery(e);l=g.query,r={...r,...g.arguments}}else l={value:H.encode(d)};return[s,l].filter(g=>g!=="")})},arguments:r}}};var Le="0.7.2";var pe;try{pe=Ee("node:os")}catch{pe=void 0}var Be=()=>{let t={driver:["javascript",Le].join("-"),env:"unknown",os:"unknown",runtime:"unknown"},e=!1;try{e=global instanceof ServiceWorkerGlobalScope}catch{}return lt()?(t.runtime=["nodejs",process.version].join("-"),t.env=ft(),t.os=[pe.platform(),pe.release()].join("-")):e?(t.runtime=Ue(navigator),t.env="Service Worker",t.os=Ge(navigator)):(t.runtime=Ue(navigator),t.env="browser",t.os=Ge(navigator)),Object.entries(t).filter(([r,n])=>n!=="unknown").map(r=>r.join("=")).join("; ")},lt=()=>typeof window>"u"&&typeof process<"u"&&process.versions!=null&&process.versions.node!=null,Ue=t=>{let e=t.appName,r=""+parseFloat(t.appVersion),n,s,i;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)),(i=r.indexOf(";"))!=-1&&(r=r.substring(0,i)),(i=r.indexOf(" "))!=-1&&(r=r.substring(0,i)),(i=r.indexOf(")"))!=-1&&(r=r.substring(0,i)),[e,r].join("-")},Ge=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 i=r[s];if(i.r.test(t.userAgent)){e=i.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("-")},mt=typeof window<"u"?window:typeof globalThis<"u"?globalThis:typeof global<"u"?global:self,ft=()=>{if(!(typeof process<"u"&&process&&process.env))return"unkown";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 mt?.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 Xe=t=>t instanceof Object&&"data"in t,Ye=t=>t instanceof Object&&"error"in t&&t.error instanceof Object&&"code"in t.error&&"message"in t.error;var pt={client_timeout_buffer_ms:5e3,endpoint:Re.default,format:"tagged",http2_session_idle_ms:5e3,max_conns:10,query_timeout_ms:5e3},ge,w,Y,T,te,ce,Ne,Te,ze,he,Je,be,Ke,we,Ze,Se,et,Ie=class{constructor(e,r){a(this,ce);a(this,Te);a(this,he);a(this,be);a(this,we);a(this,Se);a(this,w,void 0);a(this,Y,void 0);a(this,T,void 0);a(this,te,!1);p(this,w,{...pt,...e,secret:m(this,Te,ze).call(this,e)}),m(this,Se,et).call(this),r?p(this,Y,r):p(this,Y,Pe({url:o(this,w).endpoint.toString(),http2_session_idle_ms:o(this,w).http2_session_idle_ms}))}get lastTxnTs(){return o(this,T)}set lastTxnTs(e){p(this,T,o(this,T)?Math.max(e,o(this,T)):e)}get clientConfiguration(){let{secret:e,...r}=o(this,w);return r}close(){if(o(this,te))throw new k("Your client is closed. You cannot close it again.");o(this,Y).close(),p(this,te,!0)}paginate(e){return e instanceof X?R.fromQuery(this,e):R.fromPageable(this,e)}async query(e,r){if(o(this,te))throw new k("Your client is closed. No further requests can be issued.");return m(this,be,Ke).call(this,e.toQuery(r))}},ye=Ie;ge=new WeakMap,w=new WeakMap,Y=new WeakMap,T=new WeakMap,te=new WeakMap,ce=new WeakSet,Ne=function(e){if(e instanceof h||e instanceof b||e instanceof x||e instanceof u)return e;if(Ce(e)){if(Ye(e.body)){let r=e.body,n=e.status;return m(this,he,Je).call(this,r,n)}return new x({message:`Response is in an unkown format: ${e.body}`,httpStatus:e.status})}return new h("A client level error occurred. Fauna was not called.",{cause:e})},Te=new WeakSet,ze=function(e){let r;typeof process=="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},he=new WeakSet,Je=function(e,r){switch(r){case 400:return yt.includes(e.error.code)?new C(e,r):e.error.code==="invalid_request"?new O(e,r):e.error.code==="abort"&&e.error.abort!==void 0?new re(e,r):new q(e,r);case 401:return new F(e,r);case 403:return new W(e,r);case 409:return new ne(e,r);case 429:return new M(e,r);case 440:return new j(e,r);case 500:return new v(e,r);case 503:return new $(e,r);default:return new u(e,r)}},be=new WeakSet,Ke=async function(e){try{let r={Authorization:`Bearer ${o(this,w).secret}`};m(this,we,Ze).call(this,{...this.clientConfiguration,...e},r);let n={...o(this,w),...e},s=n.format==="tagged"||e.format==="tagged",i=s?H.encode(e.arguments):e.arguments,d={query:e.query,arguments:i},l=n.query_timeout_ms+o(this,w).client_timeout_buffer_ms,g=await o(this,Y).request({data:d,headers:r,method:"POST",client_timeout_ms:l}),c;try{if(c={...g,body:s?H.decode(g.body):JSON.parse(g.body)},c.body.query_tags){let P=c.body.query_tags.split(",").map(xe=>xe.split("="));c.body.query_tags=Object.fromEntries(P)}}catch(P){throw new x({message:`Error parsing response as JSON: ${P}`,httpStatus:g.status})}if(!Xe(c.body))throw m(this,ce,Ne).call(this,c);let S=c.body.txn_ts;return(o(this,T)===void 0&&S!==void 0||S!==void 0&&o(this,T)!==void 0&&o(this,T)<S)&&p(this,T,S),c.body}catch(r){throw m(this,ce,Ne).call(this,r)}},we=new WeakSet,Ze=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,i=`x-${n[0].replaceAll("_","-")}`;n[0]==="query_tags"?s=Object.entries(n[1]).map(d=>d.join("=")).join(","):typeof n[1]=="string"?s=n[1]:s=String(n[1]),n[0]==="traceparent"&&(i=n[0]),r[i]=s}r["x-last-txn-ts"]===void 0&&o(this,T)!==void 0&&(r["x-last-txn-ts"]=o(this,T)),r["x-driver-env"]=o(Ie,ge)},Se=new WeakSet,et=function(){let e=o(this,w);if(["client_timeout_buffer_ms","endpoint","format","http2_session_idle_ms","max_conns","query_timeout_ms"].forEach(n=>{if(e[n]===void 0)throw new TypeError(`ClientConfiguration option '${n}' must be defined.`)}),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(ye,ge,Be());var yt=["invalid_function_definition","invalid_identifier","invalid_query","invalid_syntax","invalid_type"];export{re as AbortError,F as AuthenticationError,W as AuthorizationError,ye as Client,k as ClientClosedError,h as ClientError,ne as ContendedTransactionError,Q as DateStub,K as Document,N as DocumentReference,D as EmbeddedSet,se as FetchClient,O as InvalidRequestError,$e as LONG_MAX,ve as LONG_MIN,I as Module,Z as NamedDocument,B as NamedDocumentReference,b as NetworkError,G as NodeHTTP2Client,ee as NullDocument,_ as Page,x as ProtocolError,C as QueryCheckError,q as QueryRuntimeError,j as QueryTimeoutError,u as ServiceError,v as ServiceInternalError,$ as ServiceTimeoutError,R as SetIterator,H as TaggedTypeFormat,M as ThrottlingError,E as TimeStub,Re as endpoints,Ae as fql,Pe as getDefaultHTTPClient,Ce 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 o=(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),Re=(t,e,r,n)=>({set _(s){m(t,e,s,r)},get _(){return o(t,e,n)}}),f=(t,e,r)=>(Qe(t,e,"access private method"),r);var Ce={default:new URL("https://db.fauna.com"),local:new URL("http://localhost:8443"),localhost:new URL("http://localhost:8443")};var q=class extends Error{constructor(...e){super(...e)}},u=class extends q{httpStatus;code;queryInfo;constraint_failures;constructor(e,r){super(e.error.message),Error.captureStackTrace&&Error.captureStackTrace(this,u),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}},V=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,V),this.name="QueryRuntimeError"}},P=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,P),this.name="QueryCheckError"}},O=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,O),this.name="InvalidRequestError"}},re=class extends u{abort;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,P),this.name="AbortError",this.abort=e.error.abort}},F=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,F),this.name="AuthenticationError"}},W=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,W),this.name="AuthorizationError"}},ne=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,O),this.name="ContendedTransactionError"}},M=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,M),this.name="ThrottlingError"}},v=class extends u{stats;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,v),this.name="QueryTimeoutError",this.stats=e.stats}},j=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,j),this.name="ServiceInternalError"}},$=class extends u{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,$),this.name="ServiceTimeoutError"}},b=class extends q{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,b),this.name="ClientError"}},k=class extends q{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,k),this.name="ClientClosedError"}},w=class extends q{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,w),this.name="NetworkError"}},x=class extends q{httpStatus;constructor(e){super(e.message),Error.captureStackTrace&&Error.captureStackTrace(this,x),this.name="ProtocolError",this.httpStatus=e.httpStatus}};var se=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 i=await fetch(this.#e,{method:n,headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(e),signal:AbortSignal.timeout(s),keepalive:this.#t}).catch(c=>{throw new w("The network connection encountered a problem.",{cause:c})}),d=i.status,l={};i.headers.forEach((c,S)=>l[S]=c);let g=await i.text();return{status:d,body:g,headers:l}}close(){}};var L;try{L=_e("node:http2")}catch{L=void 0}var z,oe,ie,ae,A,y,le,He,J,de,me,qe,fe,Ve,U=class{constructor({http2_session_idle_ms:e,url:r,http2_max_streams:n}){a(this,J);a(this,me);a(this,fe);a(this,oe,void 0);a(this,ie,void 0);a(this,ae,void 0);a(this,A,0);a(this,y,void 0);if(L===void 0)throw new Error("Your platform does not support Node's http2 library");m(this,oe,e),m(this,ie,n),m(this,ae,r),m(this,y,null)}static getClient(e){var s;let r=f(s=U,le,He).call(s,e);o(U,z).has(r)||o(U,z).set(r,new U(e));let n=o(U,z).get(r);return Re(n,A)._++,n}async request(e){let r=0,n;do try{return await f(this,fe,Ve).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()||(Re(this,A)._--,o(this,A)===0&&o(this,y)&&!o(this,y).closed&&o(this,y).close())}isClosed(){return o(this,A)===0}},G=U;z=new WeakMap,oe=new WeakMap,ie=new WeakMap,ae=new WeakMap,A=new WeakMap,y=new WeakMap,le=new WeakSet,He=function({http2_session_idle_ms:e,url:r}){return`${r}|${e}`},J=new WeakSet,de=function(){m(this,A,0),o(this,y)&&!o(this,y).closed&&o(this,y).close()},me=new WeakSet,qe=function(){if(!o(this,y)||o(this,y).closed){let e=L.connect(o(this,ae),{peerMaxConcurrentStreams:o(this,ie)}).once("error",()=>f(this,J,de).call(this)).once("goaway",()=>f(this,J,de).call(this));e.setTimeout(o(this,oe),()=>{f(this,J,de).call(this)}),m(this,y,e)}return o(this,y)},fe=new WeakSet,Ve=function({client_timeout_ms:e,data:r,headers:n,method:s}){return new Promise((i,d)=>{let l,g=c=>{let S=Number(c[L.constants.HTTP2_HEADER_STATUS]),C="";l.on("data",Ee=>{C+=Ee}),l.on("end",()=>{i({status:S,body:C,headers:c})})};try{let c={...n,[L.constants.HTTP2_HEADER_PATH]:"/query/1",[L.constants.HTTP2_HEADER_METHOD]:s};l=f(this,me,qe).call(this).request(c).setEncoding("utf8").on("error",C=>{d(C)}).on("response",g),l.write(JSON.stringify(r),"utf8"),l.setTimeout(e,()=>{l.destroy(new Error("Client timeout"))}),l.end()}catch(c){d(c)}})},a(G,le),a(G,z,new Map);var Pe=t=>rt()?G.getClient(t):new se(t),Oe=t=>t instanceof Object&&"body"in t&&"headers"in t&&"status"in t,rt=()=>{if(typeof process<"u"&&process.release?.name==="node")try{return _e("node:http2"),!0}catch{return!1}return!1};var nt=/(?:\d{4}|[\u2212-]\d{4,}|\+\d{5,})/,st=/(?:0[1-9]|1[0-2])/,ot=/(?:0[1-9]|[12]\d|3[01])/,Fe=/(?:[01][0-9]|2[0-3])/,ce=/(?:[0-5][0-9])/,it=/(?:\.\d+)/,ke=new RegExp(`(${nt.source}-(${st.source})-(${ot.source}))`),at=new RegExp(`(${Fe.source}:${ce.source}:${ce.source}${it.source}?)`),ct=new RegExp(`([zZ]|[+\u2212-]${Fe.source}(?::?${ce.source}|:${ce.source}:${ce.source}))`),We=new RegExp(`^${ke.source}$`),Me=new RegExp(`^${ke.source}`),ve=new RegExp(`^${ke.source}T${at.source}${ct.source}$`);var E=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(e)}static fromDate(e){return new E(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}")`}},_=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=We.exec(e);if(r===null)throw new RangeError(`Expected a plain date string but received '${e}'`);return new _(r[0])}static fromDate(e){let r=e.toISOString(),n=Me.exec(r);if(n===null)throw new b(`Failed to parse date '${e}'`);return new _(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 N=class{coll;id;constructor({coll:e,id:r}){this.id=r,typeof e=="string"?this.coll=new I(e):this.coll=e}},K=class extends N{ts;constructor(e){let{coll:r,id:n,ts:s,...i}=e;super({coll:r,id:n}),this.ts=s,Object.assign(this,i)}toObject(){return{...this}}},B=class{coll;name;constructor({coll:e,name:r}){this.name=r,typeof e=="string"?this.coll=new I(e):this.coll=e}},Z=class extends B{ts;data;constructor(e){let{coll:r,name:n,ts:s,data:i,...d}=e;super({coll:r,name:n}),this.ts=s,this.data=i||{},Object.assign(this,d)}toObject(){return{...this}}},I=class{name;constructor(e){this.name=e}},ee=class{ref;cause;constructor(e,r){this.ref=e,this.cause=r}};var Q=class{data;after;constructor({data:e,after:r}){this.data=e,this.after=r}},D=class{after;constructor(e){this.after=e}},R=class{#e;constructor(e,r){if(r instanceof Function)this.#e=dt(e,r);else if(r instanceof Q||r instanceof D)this.#e=je(e,r);else throw new TypeError(`Expected 'Page<T> | EmbeddedSet | (() => Promise<T | Page<T> | EmbeddedSet>)', but received ${JSON.stringify(r)}`)}static fromQuery(e,r){return new R(e,async()=>(await e.query(r)).data)}static fromPageable(e,r){return new R(e,r)}flatten(){return new Ae(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}},Ae=class{#e;constructor(e){this.#e=lt(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){let r=e;for(r instanceof Q&&(yield r.data);r.after;){let n=Ne`Set.paginate(${r.after})`;r=(await t.query(n)).data,yield r.data}}async function*dt(t,e){let r=await e();if(r instanceof Q||r instanceof D){for await(let n of je(t,r))yield n;return}yield[r]}async function*lt(t){for await(let e of t)for(let r of e)yield r}var H=class{static encode(e){return pe(e)}static decode(e){return JSON.parse(e,(r,n)=>{if(n==null)return null;if(n["@mod"])return new I(n["@mod"]);if(n["@doc"]){if(typeof n["@doc"]=="string"){let[i,d]=n["@doc"].split(":");return new N({coll:i,id:d})}let s=n["@doc"];return s.id?new K(s):new Z(s)}else if(n["@ref"]){let s=n["@ref"],i;return s.id?i=new N(s):i=new B(s),"exists"in s&&s.exists===!1?new ee(i,s.cause):i}else{if(n["@set"])return typeof n["@set"]=="string"?new D(n["@set"]):new Q(n["@set"]);if(n["@int"])return Number(n["@int"]);if(n["@long"])return BigInt(n["@long"]);if(n["@double"])return Number(n["@double"]);if(n["@date"])return _.from(n["@date"]);if(n["@time"])return E.from(n["@time"]);if(n["@object"])return n["@object"]}return n})}},$e=BigInt("-9223372036854775808"),Le=BigInt("9223372036854775807"),p={bigint:t=>{if(t<$e||t>Le)throw new RangeError("Precision loss when converting BigInt to Fauna type");return{"@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`${t}`.includes(".")?{"@double":t.toString()}:t>=-(2**31)&&t<=2**31-1?{"@int":t.toString()}:Number.isSafeInteger(t)?{"@long":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]=pe(t[n]));return e?{"@object":r}:r},array:t=>{let e=[];for(let r in t)e.push(pe(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.")}},pe=t=>{if(t===void 0)throw new TypeError("Passing undefined as a QueryValue is not supported");switch(typeof t){case"bigint":return p.bigint(t);case"string":return p.string(t);case"number":return p.number(t);case"boolean":return t;case"object":return t==null?null:Array.isArray(t)?p.array(t):t instanceof Date?p.date(t):t instanceof _?p.faunadate(t):t instanceof E?p.faunatime(t):t instanceof I?p.module(t):t instanceof K?p.document(t):t instanceof N?p.documentReference(t):t instanceof Z?p.namedDocument(t):t instanceof B?p.namedDocumentReference(t):t instanceof ee?pe(t.ref):t instanceof Q||t instanceof D?p.set(t):p.object(t)}};function Ne(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,i)=>{if(i===this.#e.length-1)return s===""?[]:[s];let d=this.#t[i],l;if(d instanceof X){let g=d.toQuery(e);l=g.query,r={...r,...g.arguments}}else l={value:H.encode(d)};return[s,l].filter(g=>g!=="")})},arguments:r}}};var Ue="0.8.0";var ye;try{ye=_e("node:os")}catch{ye=void 0}var Xe=()=>{let t={driver:["javascript",Ue].join("-"),env:"unknown",os:"unknown",runtime:"unknown"},e=!1;try{e=global instanceof ServiceWorkerGlobalScope}catch{}return mt()?(t.runtime=["nodejs",process.version].join("-"),t.env=pt(),t.os=[ye.platform(),ye.release()].join("-")):e?(t.runtime=Ge(navigator),t.env="Service Worker",t.os=Be(navigator)):(t.runtime=Ge(navigator),t.env="browser",t.os=Be(navigator)),Object.entries(t).filter(([r,n])=>n!=="unknown").map(r=>r.join("=")).join("; ")},mt=()=>typeof window>"u"&&typeof process<"u"&&process.versions!=null&&process.versions.node!=null,Ge=t=>{let e=t.appName,r=""+parseFloat(t.appVersion),n,s,i;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)),(i=r.indexOf(";"))!=-1&&(r=r.substring(0,i)),(i=r.indexOf(" "))!=-1&&(r=r.substring(0,i)),(i=r.indexOf(")"))!=-1&&(r=r.substring(0,i)),[e,r].join("-")},Be=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 i=r[s];if(i.r.test(t.userAgent)){e=i.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("-")},ft=typeof window<"u"?window:typeof globalThis<"u"?globalThis:typeof global<"u"?global:self,pt=()=>{if(!(typeof process<"u"&&process&&process.env))return"unkown";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 ft?.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 Ye=t=>t instanceof Object&&"data"in t,ze=t=>t instanceof Object&&"error"in t&&t.error instanceof Object&&"code"in t.error&&"message"in t.error;var yt={client_timeout_buffer_ms:5e3,endpoint:Ce.default,format:"tagged",http2_session_idle_ms:5e3,http2_max_streams:100,fetch_keepalive:!1,query_timeout_ms:5e3},Te,T,Y,h,te,ue,Ie,he,Je,be,Ke,we,Ze,Se,et,xe,tt,De=class{constructor(e,r){a(this,ue);a(this,he);a(this,be);a(this,we);a(this,Se);a(this,xe);a(this,T,void 0);a(this,Y,void 0);a(this,h,void 0);a(this,te,!1);m(this,T,{...yt,...e,secret:f(this,he,Je).call(this,e)}),f(this,xe,tt).call(this),r?m(this,Y,r):m(this,Y,Pe({url:o(this,T).endpoint.toString(),http2_session_idle_ms:o(this,T).http2_session_idle_ms,http2_max_streams:o(this,T).http2_max_streams,fetch_keepalive:o(this,T).fetch_keepalive}))}get lastTxnTs(){return o(this,h)}set lastTxnTs(e){m(this,h,o(this,h)?Math.max(e,o(this,h)):e)}get clientConfiguration(){let{secret:e,...r}=o(this,T);return r}close(){if(o(this,te))throw new k("Your client is closed. You cannot close it again.");o(this,Y).close(),m(this,te,!0)}paginate(e){return e instanceof X?R.fromQuery(this,e):R.fromPageable(this,e)}async query(e,r){if(o(this,te))throw new k("Your client is closed. No further requests can be issued.");return f(this,we,Ze).call(this,e.toQuery(r))}},ge=De;Te=new WeakMap,T=new WeakMap,Y=new WeakMap,h=new WeakMap,te=new WeakMap,ue=new WeakSet,Ie=function(e){if(e instanceof b||e instanceof w||e instanceof x||e instanceof u)return e;if(Oe(e)){if(ze(e.body)){let r=e.body,n=e.status;return f(this,be,Ke).call(this,r,n)}return new x({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})},he=new WeakSet,Je=function(e){let r;typeof process=="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},be=new WeakSet,Ke=function(e,r){switch(r){case 400:return gt.includes(e.error.code)?new P(e,r):e.error.code==="invalid_request"?new O(e,r):e.error.code==="abort"&&e.error.abort!==void 0?new re(e,r):new V(e,r);case 401:return new F(e,r);case 403:return new W(e,r);case 409:return new ne(e,r);case 429:return new M(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 u(e,r)}},we=new WeakSet,Ze=async function(e){try{let r={Authorization:`Bearer ${o(this,T).secret}`};f(this,Se,et).call(this,{...this.clientConfiguration,...e},r);let n={...o(this,T),...e},s=n.format==="tagged"||e.format==="tagged",i=s?H.encode(e.arguments):e.arguments,d={query:e.query,arguments:i},l=n.query_timeout_ms+o(this,T).client_timeout_buffer_ms,g=await o(this,Y).request({data:d,headers:r,method:"POST",client_timeout_ms:l}),c;try{if(c={...g,body:s?H.decode(g.body):JSON.parse(g.body)},c.body.query_tags){let C=c.body.query_tags.split(",").map(Ee=>Ee.split("="));c.body.query_tags=Object.fromEntries(C)}}catch(C){throw new x({message:`Error parsing response as JSON: ${C}`,httpStatus:g.status})}if(!Ye(c.body))throw f(this,ue,Ie).call(this,c);let S=c.body.txn_ts;return(o(this,h)===void 0&&S!==void 0||S!==void 0&&o(this,h)!==void 0&&o(this,h)<S)&&m(this,h,S),c.body}catch(r){throw f(this,ue,Ie).call(this,r)}},Se=new WeakSet,et=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,i=`x-${n[0].replaceAll("_","-")}`;n[0]==="query_tags"?s=Object.entries(n[1]).map(d=>d.join("=")).join(","):typeof n[1]=="string"?s=n[1]:s=String(n[1]),n[0]==="traceparent"&&(i=n[0]),r[i]=s}r["x-last-txn-ts"]===void 0&&o(this,h)!==void 0&&(r["x-last-txn-ts"]=o(this,h)),r["x-driver-env"]=o(De,Te)},xe=new WeakSet,tt=function(){let e=o(this,T);if(["client_timeout_buffer_ms","endpoint","format","http2_session_idle_ms","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(ge,Te,Xe());var gt=["invalid_function_definition","invalid_identifier","invalid_query","invalid_syntax","invalid_type"];export{re as AbortError,F as AuthenticationError,W as AuthorizationError,ge as Client,k as ClientClosedError,b as ClientError,ne as ContendedTransactionError,_ as DateStub,K as Document,N as DocumentReference,D as EmbeddedSet,se as FetchClient,O as InvalidRequestError,Le as LONG_MAX,$e as LONG_MIN,I as Module,Z as NamedDocument,B as NamedDocumentReference,w as NetworkError,G as NodeHTTP2Client,ee as NullDocument,Q as Page,x as ProtocolError,P as QueryCheckError,V as QueryRuntimeError,v as QueryTimeoutError,u as ServiceError,j as ServiceInternalError,$ as ServiceTimeoutError,R as SetIterator,H as TaggedTypeFormat,M as ThrottlingError,E as TimeStub,Ce as endpoints,Ne as fql,Pe as getDefaultHTTPClient,Oe as isHTTPResponse};
//# sourceMappingURL=index.js.map

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

import { ValueFormat } from "./wire-protocol";
import type { ValueFormat } from "./wire-protocol";
/**

@@ -14,7 +14,7 @@ * Configuration for a client.

*/
client_timeout_buffer_ms: number;
client_timeout_buffer_ms?: number;
/**
* The {@link URL} of Fauna to call. See {@link endpoints} for some default options.
*/
endpoint: URL;
endpoint?: URL;
/**

@@ -36,3 +36,3 @@ * Determines the encoded format expected for the query `arguments` field, and

*/
format: ValueFormat;
format?: ValueFormat;
/**

@@ -42,12 +42,27 @@ * Time in milliseconds the client will keep an HTTP2 session open after all

*/
http2_session_idle_ms: number;
http2_session_idle_ms?: number;
/**
* The maximum number of connections to a make to Fauna.
* The maximum number of HTTP2 streams to execute in parallel
* to Fauna per HTTP2 session.
* Only relevant to certain HTTP2 clients.
* @remarks
* Relevant to clients using the {@link NodeHTTP2Client} provided,
* or any custom HTTP2Clients you implement that support this feature.
*/
max_conns: number;
http2_max_streams?: number;
/**
* When true will keep executing a request even if the page
* that fired the request is no longer executing. Only relevant
* to underlying clients using the {@link https://fetch.spec.whatwg.org/ | Fetch standard}.
* By default set to false.
* @remarks
* Relevant to clients using the {@link FetchClient} provided,
* or any custom HTTP Clients you implement using the Fetch standard.
*/
fetch_keepalive?: boolean;
/**
* A secret for your Fauna DB, used to authorize your queries.
* @see https://docs.fauna.com/fauna/current/security/keys
*/
secret: string;
secret?: string;
/**

@@ -59,3 +74,3 @@ * The timeout of each query, in milliseconds. This controls the maximum amount of

*/
query_timeout_ms: number;
query_timeout_ms?: number;
/**

@@ -62,0 +77,0 @@ * If true, unconditionally run the query as strictly serialized.

@@ -6,3 +6,2 @@ import { ClientConfiguration } from "./client-configuration";

import { type QueryRequestHeaders, type QuerySuccess, type QueryValue } from "./wire-protocol";
export declare const DEFAULT_CLIENT_CONFIG: Omit<ClientConfiguration, "secret">;
/**

@@ -22,3 +21,2 @@ * Client for calling Fauna.

* endpoint: endpoints.cloud,
* max_conns: 10,
* secret: "foo",

@@ -30,3 +28,3 @@ * query_timeout_ms: 60_000,

*/
constructor(clientConfiguration?: Partial<ClientConfiguration>, httpClient?: HTTPClient);
constructor(clientConfiguration?: ClientConfiguration, httpClient?: HTTPClient);
/**

@@ -33,0 +31,0 @@ * @returns the last transaction time seen by this client, or undefined if this client has not seen a transaction time.

@@ -9,3 +9,3 @@ /** following reference needed to include types for experimental fetch API in Node */

#private;
constructor({ url }: HTTPClientOptions);
constructor({ url, fetch_keepalive }: HTTPClientOptions);
/** {@inheritDoc HTTPClient.request} */

@@ -12,0 +12,0 @@ request({ data, headers: requestHeaders, method, client_timeout_ms, }: HTTPRequest): Promise<HTTPResponse>;

@@ -30,2 +30,4 @@ import { QueryRequest } from "../wire-protocol";

http2_session_idle_ms: number;
http2_max_streams: number;
fetch_keepalive: boolean;
};

@@ -32,0 +34,0 @@ /**

@@ -274,4 +274,6 @@ "use strict";

#url;
constructor({ url }) {
#keepalive;
constructor({ url, fetch_keepalive }) {
this.#url = new URL("/query/1", url).toString();
this.#keepalive = fetch_keepalive;
}

@@ -288,3 +290,4 @@ async request({

body: JSON.stringify(data),
signal: AbortSignal.timeout(client_timeout_ms)
signal: AbortSignal.timeout(client_timeout_ms),
keepalive: this.#keepalive
}).catch((error) => {

@@ -316,5 +319,9 @@ throw new NetworkError("The network connection encountered a problem.", {

}
var _clients, _http2_session_idle_ms, _url, _numberOfUsers, _session, _getClientKey, getClientKey_fn, _closeForAll, closeForAll_fn, _connect, connect_fn, _doRequest, doRequest_fn;
var _clients, _http2_session_idle_ms, _http2_max_streams, _url, _numberOfUsers, _session, _getClientKey, getClientKey_fn, _closeForAll, closeForAll_fn, _connect, connect_fn, _doRequest, doRequest_fn;
var _NodeHTTP2Client = class {
constructor({ http2_session_idle_ms, url }) {
constructor({
http2_session_idle_ms,
url,
http2_max_streams
}) {
__privateAdd(this, _closeForAll);

@@ -324,2 +331,3 @@ __privateAdd(this, _connect);

__privateAdd(this, _http2_session_idle_ms, void 0);
__privateAdd(this, _http2_max_streams, void 0);
__privateAdd(this, _url, void 0);

@@ -332,2 +340,3 @@ __privateAdd(this, _numberOfUsers, 0);

__privateSet(this, _http2_session_idle_ms, http2_session_idle_ms);
__privateSet(this, _http2_max_streams, http2_max_streams);
__privateSet(this, _url, url);

@@ -388,2 +397,3 @@ __privateSet(this, _session, null);

_http2_session_idle_ms = new WeakMap();
_http2_max_streams = new WeakMap();
_url = new WeakMap();

@@ -406,3 +416,5 @@ _numberOfUsers = new WeakMap();

if (!__privateGet(this, _session) || __privateGet(this, _session).closed) {
const new_session = http2.connect(__privateGet(this, _url)).once("error", () => __privateMethod(this, _closeForAll, closeForAll_fn).call(this)).once("goaway", () => __privateMethod(this, _closeForAll, closeForAll_fn).call(this));
const new_session = http2.connect(__privateGet(this, _url), {
peerMaxConcurrentStreams: __privateGet(this, _http2_max_streams)
}).once("error", () => __privateMethod(this, _closeForAll, closeForAll_fn).call(this)).once("goaway", () => __privateMethod(this, _closeForAll, closeForAll_fn).call(this));
new_session.setTimeout(__privateGet(this, _http2_session_idle_ms), () => {

@@ -973,3 +985,3 @@ __privateMethod(this, _closeForAll, closeForAll_fn).call(this);

// src/util/package-version.ts
var packageVersion = "0.7.2";
var packageVersion = "0.8.0";

@@ -1219,3 +1231,4 @@ // src/util/environment.ts

http2_session_idle_ms: 5e3,
max_conns: 10,
http2_max_streams: 100,
fetch_keepalive: false,
query_timeout_ms: 5e3

@@ -1245,3 +1258,5 @@ };

url: __privateGet(this, _clientConfiguration).endpoint.toString(),
http2_session_idle_ms: __privateGet(this, _clientConfiguration).http2_session_idle_ms
http2_session_idle_ms: __privateGet(this, _clientConfiguration).http2_session_idle_ms,
http2_max_streams: __privateGet(this, _clientConfiguration).http2_max_streams,
fetch_keepalive: __privateGet(this, _clientConfiguration).fetch_keepalive
}));

@@ -1458,4 +1473,5 @@ } else {

"http2_session_idle_ms",
"max_conns",
"query_timeout_ms"
"query_timeout_ms",
"fetch_keepalive",
"http2_max_streams"
];

@@ -1469,2 +1485,5 @@ required_options.forEach((option) => {

});
if (config.http2_max_streams <= 0) {
throw new RangeError(`'http2_max_streams' must be greater than zero.`);
}
if (config.client_timeout_buffer_ms <= 0) {

@@ -1471,0 +1490,0 @@ throw new RangeError(

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

export declare const packageVersion = "0.7.2";
/** The current package version. */
export declare const packageVersion = "0.8.0";
{
"name": "fauna",
"version": "0.7.2",
"version": "0.8.0",
"description": "A driver to query Fauna databases in browsers, Node.js, and other Javascript runtimes",

@@ -5,0 +5,0 @@ "homepage": "https://fauna.com",

@@ -145,3 +145,3 @@ > **WARNING**

"Collection exists now!"
}`)
}`);
```

@@ -246,5 +246,2 @@

endpoint: endpoints.default,
// note this will change names during the early access beta
// to reflect HTTP/2 semantics
max_conns: 10,

@@ -251,0 +248,0 @@ // set default query options

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

import { ValueFormat } from "./wire-protocol";
import type { ValueFormat } from "./wire-protocol";

@@ -15,3 +15,3 @@ /**

*/
client_timeout_buffer_ms: number;
client_timeout_buffer_ms?: number;

@@ -21,3 +21,3 @@ /**

*/
endpoint: URL;
endpoint?: URL;

@@ -40,3 +40,3 @@ /**

*/
format: ValueFormat;
format?: ValueFormat;

@@ -47,14 +47,30 @@ /**

*/
http2_session_idle_ms: number;
http2_session_idle_ms?: number;
/**
* The maximum number of connections to a make to Fauna.
* The maximum number of HTTP2 streams to execute in parallel
* to Fauna per HTTP2 session.
* Only relevant to certain HTTP2 clients.
* @remarks
* Relevant to clients using the {@link NodeHTTP2Client} provided,
* or any custom HTTP2Clients you implement that support this feature.
*/
max_conns: number;
http2_max_streams?: number;
/**
* When true will keep executing a request even if the page
* that fired the request is no longer executing. Only relevant
* to underlying clients using the {@link https://fetch.spec.whatwg.org/ | Fetch standard}.
* By default set to false.
* @remarks
* Relevant to clients using the {@link FetchClient} provided,
* or any custom HTTP Clients you implement using the Fetch standard.
*/
fetch_keepalive?: boolean;
/**
* A secret for your Fauna DB, used to authorize your queries.
* @see https://docs.fauna.com/fauna/current/security/keys
*/
secret: string;
secret?: string;

@@ -69,3 +85,3 @@ // Query options

*/
query_timeout_ms: number;
query_timeout_ms?: number;

@@ -72,0 +88,0 @@ /**

@@ -37,5 +37,20 @@ import { ClientConfiguration, endpoints } from "./client-configuration";

type QueryValue,
type ValueFormat,
} from "./wire-protocol";
export const DEFAULT_CLIENT_CONFIG: Omit<ClientConfiguration, "secret"> = {
interface RequiredClientConfig {
client_timeout_buffer_ms: number;
endpoint: URL;
format: ValueFormat;
http2_session_idle_ms: number;
http2_max_streams: number;
fetch_keepalive: boolean;
secret: string;
query_timeout_ms: number;
}
const DEFAULT_CLIENT_CONFIG: Omit<
ClientConfiguration & RequiredClientConfig,
"secret"
> = {
client_timeout_buffer_ms: 5000,

@@ -45,3 +60,4 @@ endpoint: endpoints.default,

http2_session_idle_ms: 5000,
max_conns: 10,
http2_max_streams: 100,
fetch_keepalive: false,
query_timeout_ms: 5000,

@@ -58,3 +74,3 @@ };

/** The {@link ClientConfiguration} */
readonly #clientConfiguration: ClientConfiguration;
readonly #clientConfiguration: ClientConfiguration & RequiredClientConfig;
/** The underlying {@link HTTPClient} client. */

@@ -76,3 +92,2 @@ readonly #httpClient: HTTPClient;

* endpoint: endpoints.cloud,
* max_conns: 10,
* secret: "foo",

@@ -85,3 +100,3 @@ * query_timeout_ms: 60_000,

constructor(
clientConfiguration?: Partial<ClientConfiguration>,
clientConfiguration?: ClientConfiguration,
httpClient?: HTTPClient

@@ -101,2 +116,4 @@ ) {

http2_session_idle_ms: this.#clientConfiguration.http2_session_idle_ms,
http2_max_streams: this.#clientConfiguration.http2_max_streams,
fetch_keepalive: this.#clientConfiguration.fetch_keepalive,
});

@@ -273,3 +290,3 @@ } else {

#getSecret(partialClientConfig?: Partial<ClientConfiguration>): string {
#getSecret(partialClientConfig?: ClientConfiguration): string {
let fallback = undefined;

@@ -465,4 +482,5 @@ if (typeof process === "object") {

"http2_session_idle_ms",
"max_conns",
"query_timeout_ms",
"fetch_keepalive",
"http2_max_streams",
];

@@ -477,2 +495,6 @@ required_options.forEach((option) => {

if (config.http2_max_streams <= 0) {
throw new RangeError(`'http2_max_streams' must be greater than zero.`);
}
if (config.client_timeout_buffer_ms <= 0) {

@@ -479,0 +501,0 @@ throw new RangeError(

@@ -17,5 +17,7 @@ /** following reference needed to include types for experimental fetch API in Node */

#url: string;
#keepalive: boolean;
constructor({ url }: HTTPClientOptions) {
constructor({ url, fetch_keepalive }: HTTPClientOptions) {
this.#url = new URL("/query/1", url).toString();
this.#keepalive = fetch_keepalive;
}

@@ -35,2 +37,3 @@

signal: AbortSignal.timeout(client_timeout_ms),
keepalive: this.#keepalive,
}).catch((error) => {

@@ -37,0 +40,0 @@ throw new NetworkError("The network connection encountered a problem.", {

@@ -38,2 +38,4 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars

http2_session_idle_ms: number;
http2_max_streams: number;
fetch_keepalive: boolean;
};

@@ -40,0 +42,0 @@

@@ -29,2 +29,3 @@ let http2: any;

#http2_session_idle_ms: number;
#http2_max_streams: number;
#url: string;

@@ -34,3 +35,7 @@ #numberOfUsers = 0;

private constructor({ http2_session_idle_ms, url }: HTTPClientOptions) {
private constructor({
http2_session_idle_ms,
url,
http2_max_streams,
}: HTTPClientOptions) {
if (http2 === undefined) {

@@ -41,2 +46,3 @@ throw new Error("Your platform does not support Node's http2 library");

this.#http2_session_idle_ms = http2_session_idle_ms;
this.#http2_max_streams = http2_max_streams;
this.#url = url;

@@ -137,3 +143,5 @@ this.#session = null;

const new_session: ClientHttp2Session = http2
.connect(this.#url)
.connect(this.#url, {
peerMaxConcurrentStreams: this.#http2_max_streams,
})
.once("error", () => this.#closeForAll())

@@ -140,0 +148,0 @@ .once("goaway", () => this.#closeForAll());

@@ -1,1 +0,4 @@

export const packageVersion = "0.7.2";
//THIS FILE IS AUTOGENERATED. DO NOT EDIT. SEE .husky/pre-commit
/** The current package version. */
export const packageVersion = "0.8.0";

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc