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 1.0.2 to 1.1.0

2

dist/browser/index.js

@@ -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)),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.2";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){e!==void 0&&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};
var Qe=(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 Oe=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)};var i=(t,e,r)=>(Oe(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)},p=(t,e,r,n)=>(Oe(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),Re=(t,e,r,n)=>({set _(s){p(t,e,s,r)},get _(){return i(t,e,n)}}),m=(t,e,r)=>(Oe(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 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"}},v=class extends c{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,v),this.name="ThrottlingError"}},W=class extends c{stats;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,W),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"}},I=class extends C{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,I),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=AbortSignal.timeout===void 0?(()=>{let d=new AbortController,T=d.signal;return setTimeout(()=>d.abort(),s),T})():AbortSignal.timeout(s),a=await fetch(this.#e,{method:n,headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(e),signal:o,keepalive:this.#t}).catch(d=>{throw new w("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=Qe("node:http2")}catch{L=void 0}var z,ie,ae,ue,A,f,me,qe,J,le,pe,He,fe,Fe,U=class{constructor({http2_session_idle_ms:e,url:r,http2_max_streams:n}){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,A,0);u(this,f,void 0);if(L===void 0)throw new Error("Your platform does not support Node's http2 library");p(this,ie,e),p(this,ae,n),p(this,ue,r),p(this,f,null)}static getClient(e){var s;let r=m(s=U,me,qe).call(s,e);i(U,z).has(r)||i(U,z).set(r,new U(e));let n=i(U,z).get(r);return Re(n,A)._++,n}async request(e){let r=0,n;do try{return await m(this,fe,Fe).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)._--,i(this,A)===0&&i(this,f)&&!i(this,f).closed&&i(this,f).close())}isClosed(){return i(this,A)===0}},G=U;z=new WeakMap,ie=new WeakMap,ae=new WeakMap,ue=new WeakMap,A=new WeakMap,f=new WeakMap,me=new WeakSet,qe=function({http2_session_idle_ms:e,url:r}){return`${r}|${e}`},J=new WeakSet,le=function(){p(this,A,0),i(this,f)&&!i(this,f).closed&&i(this,f).close()},pe=new WeakSet,He=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",()=>m(this,J,le).call(this)).once("goaway",()=>m(this,J,le).call(this));e.setTimeout(i(this,ie),()=>{m(this,J,le).call(this)}),p(this,f,e)}return i(this,f)},fe=new WeakSet,Fe=function({client_timeout_ms:e,data:r,headers:n,method:s}){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={...n,[L.constants.HTTP2_HEADER_PATH]:"/query/1",[L.constants.HTTP2_HEADER_METHOD]:s};l=m(this,pe,He).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 Pe=t=>at()?G.getClient(t):new oe(t),Ne=t=>t instanceof Object&&"body"in t&&"headers"in t&&"status"in t,at=()=>{if(typeof process<"u"&&process&&process.release?.name==="node")try{return Qe("node:http2"),!0}catch{return!1}return!1};var ut=/(?:\d{4}|[\u2212-]\d{4,}|\+\d{5,})/,ct=/(?:0[1-9]|1[0-2])/,dt=/(?:0[1-9]|[12]\d|3[01])/,Me=/(?:[01][0-9]|2[0-3])/,ce=/(?:[0-5][0-9])/,lt=/(?:\.\d+)/,Ie=new RegExp(`(${ut.source}-(${ct.source})-(${dt.source}))`),mt=new RegExp(`(${Me.source}:${ce.source}:${ce.source}${lt.source}?)`),pt=new RegExp(`([zZ]|[+\u2212-]${Me.source}(?::?${ce.source}|:${ce.source}:${ce.source}))`),ve=new RegExp(`^${Ie.source}$`),We=new RegExp(`^${Ie.source}`),je=new RegExp(`^${Ie.source}T${mt.source}${pt.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(je.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=ve.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 k=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 k{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,...a}=e;super({coll:r,name:n}),this.ts=s,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,n){if(n=n??{},r instanceof Function)this.#e=yt(e,r,n);else if(r instanceof O||r instanceof V)this.#e=$e(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 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=gt(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*$e(t,e,r){let n=e;for(n instanceof O&&(yield n.data);n.after;){let s=ke`Set.paginate(${n.after})`;n=(await t.query(s,r)).data,yield n.data}}async function*yt(t,e,r){let n=await e();if(n instanceof O||n instanceof V){for await(let s of $e(t,n,r))yield s;return}yield[n]}async function*gt(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[a,l]=s["@doc"].split(":");return new k({coll:a,id:l})}let o=s["@doc"];return o.id?new K(o):new Z(o)}else if(s["@ref"]){let o=s["@ref"],a;return o.id?a=new k(o):a=new B(o),"exists"in o&&o.exists===!1?new ee(a,o.cause):a}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})}},Ge=BigInt("-9223372036854775808"),Be=BigInt("9223372036854775807"),Le=-(2**31),Ue=2**31-1,y={bigint:t=>{if(t<Ge||t>Be)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>=Le&&t<=Ue?{"@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>=Le&&t<=Ue?{"@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 k?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 ke(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 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[s,l].filter(x=>x!=="")})},arguments:r}}};var Xe="1.1.0";var ge;try{ge=Qe("node:os")}catch{ge=void 0}var Je=()=>{let t={driver:["javascript",Xe].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=ht(),t.os=[ge.platform(),ge.release()].join("-")):n?(t.runtime=Ye(navigator),t.env="Service Worker",t.os=ze(navigator)):r?(t.runtime=Ye(navigator),t.env="browser",t.os=ze(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("; ")},Ye=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("-")},ze=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("-")},Tt=typeof window<"u"?window:typeof globalThis<"u"?globalThis:typeof global<"u"?global:self,ht=()=>{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 Tt?.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 Ke=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 bt={client_timeout_buffer_ms:5e3,format:"tagged",http2_session_idle_ms:5e3,http2_max_streams:100,long_type:"number",fetch_keepalive:!1,query_timeout_ms:5e3},he,S,Y,h,te,de,De,be,et,we,tt,Se,rt,xe,nt,Ee,st,_e,ot,Ve=class{constructor(e,r){u(this,de);u(this,be);u(this,we);u(this,Se);u(this,xe);u(this,Ee);u(this,_e);u(this,S,void 0);u(this,Y,void 0);u(this,h,void 0);u(this,te,!1);p(this,S,{...bt,...e,secret:m(this,be,et).call(this,e),endpoint:m(this,we,tt).call(this,e)}),m(this,_e,ot).call(this),r?p(this,Y,r):p(this,Y,Pe({url:i(this,S).endpoint.toString(),http2_session_idle_ms:i(this,S).http2_session_idle_ms,http2_max_streams:i(this,S).http2_max_streams,fetch_keepalive:i(this,S).fetch_keepalive}))}get lastTxnTs(){return i(this,h)}set lastTxnTs(e){e!==void 0&&p(this,h,i(this,h)?Math.max(e,i(this,h)):e)}get clientConfiguration(){let{...e}=i(this,S);return e}close(){if(i(this,te))throw new I("Your client is closed. You cannot close it again.");i(this,Y).close(),p(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 I("Your client is closed. No further requests can be issued.");let n=e.toQuery(r).query;return m(this,xe,nt).call(this,n,r)}},Te=Ve;he=new WeakMap,S=new WeakMap,Y=new WeakMap,h=new WeakMap,te=new WeakMap,de=new WeakSet,De=function(e){if(e instanceof b||e instanceof w||e instanceof E||e instanceof c)return e;if(Ne(e)){if(Ze(e.body)){let r=e.body,n=e.status;return m(this,Se,rt).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,et=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 TypeError("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,tt=function(e){if(e&&"endpoint"in e&&e.endpoint===void 0)throw new TypeError("ClientConfiguration option endpoint must be defined.");let r;return typeof process<"u"&&process&&typeof process=="object"&&process.env&&typeof process.env=="object"&&(r=process.env.FAUNA_ENDPOINT?new URL(process.env.FAUNA_ENDPOINT):void 0),e?.endpoint??r??Ce.default},Se=new WeakSet,rt=function(e,r){switch(r){case 400:return wt.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 v(e,r);case 440:return new W(e,r);case 500:return new j(e,r);case 503:return new $(e,r);default:return new c(e,r)}},xe=new WeakSet,nt=async function(e,r){try{let n={...i(this,S),...r},s={Authorization:`Bearer ${n.secret}`};m(this,Ee,st).call(this,n,s);let o=n.format==="tagged",a=n.arguments?o?q.encode(n.arguments):n.arguments:void 0,l={query:e,arguments:a},x=n.query_timeout_ms+i(this,S).client_timeout_buffer_ms,g=await i(this,Y).request({client_timeout_ms:x,data:l,headers:s,method:"POST"}),d;try{if(d={...g,body:o?q.decode(g.body,{long_type:n.long_type}):JSON.parse(g.body)},d.body.query_tags){let re=d.body.query_tags.split(",").map(it=>it.split("="));d.body.query_tags=Object.fromEntries(re)}}catch(re){throw new E({message:`Error parsing response as JSON: ${re}`,httpStatus:g.status})}if(!Ke(d.body))throw m(this,de,De).call(this,d);let T=d.body.txn_ts;return(i(this,h)===void 0&&T!==void 0||T!==void 0&&i(this,h)!==void 0&&i(this,h)<T)&&p(this,h,T),d.body}catch(n){throw m(this,de,De).call(this,n)}},Ee=new WeakSet,st=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(a=>a.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(Ve,he)},_e=new WeakSet,ot=function(){let e=i(this,S);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.")},u(Te,he,Je());var wt=["invalid_function_definition","invalid_identifier","invalid_query","invalid_syntax","invalid_type"];export{ne as AbortError,F as AuthenticationError,M as AuthorizationError,Te as Client,I as ClientClosedError,b as ClientError,se as ContendedTransactionError,Q as DateStub,K as Document,k as DocumentReference,V as EmbeddedSet,C as FaunaError,oe as FetchClient,N as InvalidRequestError,Be as LONG_MAX,Ge 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,W as QueryTimeoutError,c as ServiceError,j as ServiceInternalError,$ as ServiceTimeoutError,R as SetIterator,q as TaggedTypeFormat,v as ThrottlingError,_ as TimeStub,Ce as endpoints,ke as fql,Pe as getDefaultHTTPClient,Ne as isHTTPResponse};
//# sourceMappingURL=index.js.map

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

/**
* Return the {@link ClientConfiguration} of this client, save for the secret.
* Return the {@link ClientConfiguration} of this client.
*/
get clientConfiguration(): Omit<ClientConfiguration, "secret">;
get clientConfiguration(): ClientConfiguration;
/**

@@ -44,0 +44,0 @@ * Closes the underlying HTTP client. Subsquent query or close calls

@@ -1006,3 +1006,3 @@ "use strict";

// src/util/package-version.ts
var packageVersion = "1.0.2";
var packageVersion = "1.1.0";

@@ -1253,3 +1253,2 @@ // src/util/environment.ts

client_timeout_buffer_ms: 5e3,
endpoint: endpoints.default,
format: "tagged",

@@ -1262,3 +1261,3 @@ http2_session_idle_ms: 5e3,

};
var _driverEnvHeader, _clientConfiguration, _httpClient, _lastTxnTs, _isClosed, _getError, getError_fn, _getSecret, getSecret_fn, _getServiceError, getServiceError_fn, _query, query_fn, _setHeaders, setHeaders_fn, _validateConfiguration, validateConfiguration_fn;
var _driverEnvHeader, _clientConfiguration, _httpClient, _lastTxnTs, _isClosed, _getError, getError_fn, _getSecret, getSecret_fn, _getEndpoint, getEndpoint_fn, _getServiceError, getServiceError_fn, _query, query_fn, _setHeaders, setHeaders_fn, _validateConfiguration, validateConfiguration_fn;
var _Client = class {

@@ -1268,2 +1267,3 @@ constructor(clientConfiguration, httpClient) {

__privateAdd(this, _getSecret);
__privateAdd(this, _getEndpoint);
__privateAdd(this, _getServiceError);

@@ -1280,3 +1280,4 @@ __privateAdd(this, _query);

...clientConfiguration,
secret: __privateMethod(this, _getSecret, getSecret_fn).call(this, clientConfiguration)
secret: __privateMethod(this, _getSecret, getSecret_fn).call(this, clientConfiguration),
endpoint: __privateMethod(this, _getEndpoint, getEndpoint_fn).call(this, clientConfiguration)
});

@@ -1304,4 +1305,4 @@ __privateMethod(this, _validateConfiguration, validateConfiguration_fn).call(this);

get clientConfiguration() {
const { secret, ...rest } = __privateGet(this, _clientConfiguration);
return rest;
const { ...copy } = __privateGet(this, _clientConfiguration);
return copy;
}

@@ -1364,9 +1365,9 @@ close() {

getSecret_fn = function(partialClientConfig) {
let fallback = void 0;
let env_secret = void 0;
if (typeof process !== "undefined" && process && typeof process === "object" && process.env && typeof process.env === "object") {
fallback = process.env["FAUNA_SECRET"];
env_secret = process.env["FAUNA_SECRET"];
}
const maybeSecret = partialClientConfig?.secret || fallback;
const maybeSecret = partialClientConfig?.secret ?? env_secret;
if (maybeSecret === void 0) {
throw new Error(
throw new TypeError(
"You must provide a secret to the driver. Set it in an environmental variable named FAUNA_SECRET or pass it to the Client constructor."

@@ -1377,2 +1378,15 @@ );

};
_getEndpoint = new WeakSet();
getEndpoint_fn = function(partialClientConfig) {
if (partialClientConfig && "endpoint" in partialClientConfig && partialClientConfig.endpoint === void 0) {
throw new TypeError(
`ClientConfiguration option endpoint must be defined.`
);
}
let env_endpoint = void 0;
if (typeof process !== "undefined" && process && typeof process === "object" && process.env && typeof process.env === "object") {
env_endpoint = process.env["FAUNA_ENDPOINT"] ? new URL(process.env["FAUNA_ENDPOINT"]) : void 0;
}
return partialClientConfig?.endpoint ?? env_endpoint ?? endpoints.default;
};
_getServiceError = new WeakSet();

@@ -1421,3 +1435,3 @@ getServiceError_fn = function(failure, httpStatus) {

const headers = {
Authorization: `Bearer ${__privateGet(this, _clientConfiguration).secret}`
Authorization: `Bearer ${requestConfig.secret}`
};

@@ -1424,0 +1438,0 @@ __privateMethod(this, _setHeaders, setHeaders_fn).call(this, requestConfig, headers);

/** The current package version. */
export declare const packageVersion = "1.0.2";
export declare const packageVersion = "1.1.0";

@@ -72,2 +72,6 @@ import { DateStub, Document, DocumentReference, EmbeddedSet, Module, NamedDocument, NamedDocumentReference, NullDocument, Page, TimeStub } from "./values";

typecheck?: boolean;
/**
* Secret to use instead of the client's secret.
*/
secret?: string;
}

@@ -74,0 +78,0 @@ /**

{
"name": "fauna",
"version": "1.0.2",
"version": "1.1.0",
"description": "A driver to query Fauna databases in browsers, Node.js, and other Javascript runtimes",

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

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

ClientConfiguration & RequiredClientConfig,
"secret"
"secret" | "endpoint"
> = {
client_timeout_buffer_ms: 5000,
endpoint: endpoints.default,
format: "tagged",

@@ -110,2 +109,3 @@ http2_session_idle_ms: 5000,

secret: this.#getSecret(clientConfiguration),
endpoint: this.#getEndpoint(clientConfiguration),
};

@@ -146,8 +146,7 @@

/**
* Return the {@link ClientConfiguration} of this client, save for the secret.
* Return the {@link ClientConfiguration} of this client.
*/
get clientConfiguration(): Omit<ClientConfiguration, "secret"> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { secret, ...rest } = this.#clientConfiguration;
return rest;
get clientConfiguration(): ClientConfiguration {
const { ...copy } = this.#clientConfiguration;
return copy;
}

@@ -301,3 +300,3 @@

#getSecret(partialClientConfig?: ClientConfiguration): string {
let fallback = undefined;
let env_secret = undefined;
if (

@@ -310,8 +309,8 @@ typeof process !== "undefined" &&

) {
fallback = process.env["FAUNA_SECRET"];
env_secret = process.env["FAUNA_SECRET"];
}
const maybeSecret = partialClientConfig?.secret || fallback;
const maybeSecret = partialClientConfig?.secret ?? env_secret;
if (maybeSecret === undefined) {
throw new Error(
throw new TypeError(
"You must provide a secret to the driver. Set it \

@@ -325,2 +324,31 @@ in an environmental variable named FAUNA_SECRET or pass it to the Client\

#getEndpoint(partialClientConfig?: ClientConfiguration): URL {
// If the user explicitly sets the endpoint to undefined, we should throw a
// TypeError, rather than override with the default endpoint.
if (
partialClientConfig &&
"endpoint" in partialClientConfig &&
partialClientConfig.endpoint === undefined
) {
throw new TypeError(
`ClientConfiguration option endpoint must be defined.`
);
}
let env_endpoint: URL | undefined = undefined;
if (
typeof process !== "undefined" &&
process &&
typeof process === "object" &&
process.env &&
typeof process.env === "object"
) {
env_endpoint = process.env["FAUNA_ENDPOINT"]
? new URL(process.env["FAUNA_ENDPOINT"])
: undefined;
}
return partialClientConfig?.endpoint ?? env_endpoint ?? endpoints.default;
}
#getServiceError(failure: QueryFailure, httpStatus: number): ServiceError {

@@ -375,3 +403,3 @@ switch (httpStatus) {

const headers = {
Authorization: `Bearer ${this.#clientConfiguration.secret}`,
Authorization: `Bearer ${requestConfig.secret}`,
};

@@ -378,0 +406,0 @@ this.#setHeaders(requestConfig, headers);

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

@@ -96,2 +96,7 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars

typecheck?: boolean;
/**
* Secret to use instead of the client's secret.
*/
secret?: string;
}

@@ -98,0 +103,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