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.5.3 to 0.5.4

2

dist/browser/index.js

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

var J={default:new URL("https://db.fauna.com"),local:new URL("http://localhost:8443"),localhost:new URL("http://localhost:8443")};var D=class extends Error{constructor(...e){super(...e)}},i=class extends D{httpStatus;code;queryInfo;constraint_failures;constructor(e,r){super(e.error.message),Error.captureStackTrace&&Error.captureStackTrace(this,i),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}},b=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,b),this.name="QueryRuntimeError"}},S=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,S),this.name="QueryCheckError"}},x=class extends i{stats;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,x),this.name="QueryTimeoutError",this.stats=e.stats}},R=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,R),this.name="AuthenticationError"}},w=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,w),this.name="AuthorizationError"}},E=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,E),this.name="ThrottlingError"}},Q=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,Q),this.name="ServiceInternalError"}},O=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,O),this.name="ServiceTimeoutError"}},l=class extends D{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,l),this.name="ClientError"}},m=class extends D{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,m),this.name="NetworkError"}},g=class extends D{httpStatus;constructor(e){super(e.message),Error.captureStackTrace&&Error.captureStackTrace(this,g),this.name="ProtocolError",this.httpStatus=e.httpStatus}};var V=t=>t instanceof Object&&"data"in t,M=t=>t instanceof Object&&"error"in t&&t.error instanceof Object&&"code"in t.error&&"message"in t.error;var k=class{async request({data:e,headers:r,method:n,url:o}){let s=await fetch(o,{method:n,headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(e)}).catch(T=>{throw new m("The network connection encountered a problem.",{cause:T})}),a=s.status,c={};s.headers.forEach((T,j)=>c[j]=T);let d=await s.text();return{status:a,body:d,headers:c}}};import{NodeHTTP2Client as Y}from"../../src/http-client/node-http2-client";var L=()=>Z()?Y.getClient():new k,U=t=>t instanceof Object&&"body"in t&&"headers"in t&&"status"in t,Z=()=>process!==void 0&&process.release?.name==="node";var K=/(?:\d{4}|[\u2212-]\d{4,}|\+\d{5,})/,X=/(?:0[1-9]|1[0-2])/,v=/(?:0[1-9]|[12]\d|3[01])/,z=/(?:[01][0-9]|2[0-3])/,P=/(?:[0-5][0-9])/,ee=/(?:\.\d+)/,$=new RegExp(`(${K.source}-(${X.source})-(${v.source}))`),te=new RegExp(`(${z.source}:${P.source}:${P.source}${ee.source}?)`),re=new RegExp(`([zZ]|[+\u2212-]${z.source}(?::?${P.source}|:${P.source}:${P.source}))`),B=new RegExp(`^${$.source}$`),G=new RegExp(`^${$.source}`),W=new RegExp(`^${$.source}T${te.source}${re.source}$`);var p=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(W.exec(e)===null)throw new RangeError(`(regex) Expected an ISO date string but received '${e}'`);return new p(e)}static fromDate(e){return new p(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}")`}},y=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=B.exec(e);if(r===null)throw new RangeError(`Expected a plain date string but received '${e}'`);return new y(r[0])}static fromDate(e){let r=e.toISOString(),n=G.exec(r);if(n===null)throw new l(`Failed to parse date '${e}'`);return new y(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 f=class{coll;id;constructor({coll:e,id:r}){this.id=r,typeof e=="string"?this.coll=new h(e):this.coll=e}},C=class extends f{ts;constructor(e){let{coll:r,id:n,ts:o,...s}=e;super({coll:r,id:n}),this.ts=o,Object.assign(this,s)}toObject(){return{...this}}},N=class{coll;name;constructor({coll:e,name:r}){this.name=r,typeof e=="string"?this.coll=new h(e):this.coll=e}},F=class extends N{ts;data;constructor(e){let{coll:r,name:n,ts:o,data:s,...a}=e;super({coll:r,name:n}),this.ts=o,this.data=s||{},Object.assign(this,a)}toObject(){return{...this}}},h=class{name;constructor(e){this.name=e}};var _=class{data;after;constructor({data:e,after:r}){this.data=e,this.after=r}};var q=class{static encode(e){return H(e)}static decode(e){return JSON.parse(e,(r,n)=>{if(n==null)return null;if(n["@mod"])return new h(n["@mod"]);if(n["@doc"]){if(typeof n["@doc"]=="string"){let[s,a]=n["@doc"].split(":");return new f({coll:s,id:a})}let o=n["@doc"];return o.id?new C(o):new F(o)}else if(n["@ref"]){let o=n["@ref"];return o.id?new f(o):new N(o)}else{if(n["@set"])return 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 y.from(n["@date"]);if(n["@time"])return p.from(n["@time"]);if(n["@object"])return n["@object"]}return n})}},oe=BigInt("-9223372036854775808"),se=BigInt("9223372036854775807"),u={bigint:t=>{if(t<oe||t>se)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),r[n]=H(t[n]);return e?{"@object":r}:r},array:t=>{let e=[];for(let r in t)e.push(H(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=>({data:u.array(t.data),after:t.after})},H=t=>{switch(typeof t){case"bigint":return u.bigint(t);case"string":return u.string(t);case"number":return u.number(t);case"object":return t==null?null:Array.isArray(t)?u.array(t):t instanceof Date?u.date(t):t instanceof y?u.faunadate(t):t instanceof p?u.faunatime(t):t instanceof h?u.module(t):t instanceof C?u.document(t):t instanceof f?u.documentReference(t):t instanceof F?u.namedDocument(t):t instanceof N?u.namedDocumentReference(t):t instanceof _?u.set(t):u.object(t)}return t};var ae={endpoint:J.default,max_conns:10},A=class{#t;#r;#e;#n;constructor(e,r){this.#t={...ae,...e,secret:this.#s(e)},this.#n=new URL("/query/1",this.clientConfiguration.endpoint).toString(),r?this.#r=r:this.#r=L()}get lastTxnTs(){return this.#e}set lastTxnTs(e){this.#e=this.#e?Math.max(e,this.#e):e}get clientConfiguration(){let{secret:e,...r}=this.#t;return r}async query(e,r){return this.#i(e.toQuery(r))}#o(e){if(e instanceof l||e instanceof m||e instanceof g||e instanceof i)return e;if(U(e)){if(M(e.body)){let r=e.body,n=e.status;return this.#a(r,n)}return new g({message:`Response is in an unkown format: ${e.body}`,httpStatus:e.status})}return new l("A client level error occurred. Fauna was not called.",{cause:e})}#s(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}#a(e,r){switch(r){case 400:return r===400&&ie.includes(e.error.code)?new S(e,r):new b(e,r);case 401:return new R(e,r);case 403:return new w(e,r);case 429:return new E(e,r);case 440:return new x(e,r);case 500:return new Q(e,r);case 503:return new O(e,r);default:return new i(e,r)}}async#i(e){try{let r={Authorization:`Bearer ${this.#t.secret}`};this.#c({...this.clientConfiguration,...e},r);let n=(this.#t.format??"tagged")==="tagged"||e.format==="tagged",o=n?q.encode(e.arguments):e.arguments,s={query:e.query,arguments:o},a=await this.#r.request({url:this.#n,method:"POST",headers:r,data:s}),c;try{if(c={...a,body:n?q.decode(a.body):JSON.parse(a.body)},c.body.query_tags){let T=c.body.query_tags.split(",").map(j=>j.split("="));c.body.query_tags=Object.fromEntries(T)}}catch(T){throw new g({message:`Error parsing response as JSON: ${T}`,httpStatus:a.status})}if(!V(c.body))throw this.#o(c);let d=c.body.txn_ts;return(this.#e===void 0&&d!==void 0||d!==void 0&&this.#e!==void 0&&this.#e<d)&&(this.#e=d),c.body}catch(r){throw this.#o(r)}}#c(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 o,s=`x-${n[0].replaceAll("_","-")}`;n[0]==="query_tags"?o=Object.entries(n[1]).map(a=>a.join("=")).join(","):typeof n[1]=="string"?o=n[1]:o=String(n[1]),n[0]==="traceparent"&&(s=n[0]),r[s]=o}r["x-last-txn-ts"]===void 0&&this.#e!==void 0&&(r["x-last-txn-ts"]=this.#e)}},ie=["invalid_function_definition","invalid_identifier","invalid_query","invalid_syntax","invalid_type"];function ce(t,...e){return new I(t,...e)}var I=class{#t;#r;constructor(e,...r){if(e.length===0||e.length!==r.length+1)throw new Error("invalid query constructed");this.#t=e,this.#r=r}toQuery(e={}){return{...this.#e(e),...e}}#e(e){if(this.#t.length===1)return{query:{fql:[this.#t[0]]},arguments:{}};let r={};return{query:{fql:this.#t.flatMap((o,s)=>{if(s===this.#t.length-1)return o===""?[]:[o];let a=this.#r[s],c;if(a instanceof I){let d=a.toQuery(e);c=d.query,r={...r,...d.arguments}}else c={value:q.encode(a)};return[o,c].filter(d=>d!=="")})},arguments:r}}};export{R as AuthenticationError,w as AuthorizationError,A as Client,l as ClientError,y as DateStub,C as Document,f as DocumentReference,h as Module,F as NamedDocument,N as NamedDocumentReference,m as NetworkError,_ as Page,g as ProtocolError,S as QueryCheckError,b as QueryRuntimeError,x as QueryTimeoutError,i as ServiceError,Q as ServiceInternalError,O as ServiceTimeoutError,E as ThrottlingError,p as TimeStub,J as endpoints,ce as fql};
var N={default:new URL("https://db.fauna.com"),local:new URL("http://localhost:8443"),localhost:new URL("http://localhost:8443")};var F=class extends Error{constructor(...e){super(...e)}},i=class extends F{httpStatus;code;queryInfo;constraint_failures;constructor(e,r){super(e.error.message),Error.captureStackTrace&&Error.captureStackTrace(this,i),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}},b=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,b),this.name="QueryRuntimeError"}},x=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,x),this.name="QueryCheckError"}},Q=class extends i{stats;constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,Q),this.name="QueryTimeoutError",this.stats=e.stats}},S=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,S),this.name="AuthenticationError"}},w=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,w),this.name="AuthorizationError"}},R=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,R),this.name="ThrottlingError"}},E=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,E),this.name="ServiceInternalError"}},q=class extends i{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,q),this.name="ServiceTimeoutError"}},l=class extends F{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,l),this.name="ClientError"}},y=class extends F{constructor(e,r){super(e,r),Error.captureStackTrace&&Error.captureStackTrace(this,y),this.name="NetworkError"}},m=class extends F{httpStatus;constructor(e){super(e.message),Error.captureStackTrace&&Error.captureStackTrace(this,m),this.name="ProtocolError",this.httpStatus=e.httpStatus}};var M=t=>t instanceof Object&&"data"in t,L=t=>t instanceof Object&&"error"in t&&t.error instanceof Object&&"code"in t.error&&"message"in t.error;var V=class{async request({data:e,headers:r,method:n,url:o}){let s=await fetch(o,{method:n,headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(e)}).catch(T=>{throw new y("The network connection encountered a problem.",{cause:T})}),a=s.status,c={};s.headers.forEach((T,j)=>c[j]=T);let d=await s.text();return{status:a,body:d,headers:c}}};import{NodeHTTP2Client as Y}from"../../src/http-client/node-http2-client";var U=()=>Z()?Y.getClient():new V,z=t=>t instanceof Object&&"body"in t&&"headers"in t&&"status"in t,Z=()=>process!==void 0&&process.release?.name==="node";var K=/(?:\d{4}|[\u2212-]\d{4,}|\+\d{5,})/,X=/(?:0[1-9]|1[0-2])/,v=/(?:0[1-9]|[12]\d|3[01])/,J=/(?:[01][0-9]|2[0-3])/,I=/(?:[0-5][0-9])/,ee=/(?:\.\d+)/,$=new RegExp(`(${K.source}-(${X.source})-(${v.source}))`),te=new RegExp(`(${J.source}:${I.source}:${I.source}${ee.source}?)`),re=new RegExp(`([zZ]|[+\u2212-]${J.source}(?::?${I.source}|:${I.source}:${I.source}))`),B=new RegExp(`^${$.source}$`),G=new RegExp(`^${$.source}`),W=new RegExp(`^${$.source}T${te.source}${re.source}$`);var g=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(W.exec(e)===null)throw new RangeError(`(regex) Expected an ISO date string but received '${e}'`);return new g(e)}static fromDate(e){return new g(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}")`}},p=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=B.exec(e);if(r===null)throw new RangeError(`Expected a plain date string but received '${e}'`);return new p(r[0])}static fromDate(e){let r=e.toISOString(),n=G.exec(r);if(n===null)throw new l(`Failed to parse date '${e}'`);return new p(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 f=class{coll;id;constructor({coll:e,id:r}){this.id=r,typeof e=="string"?this.coll=new h(e):this.coll=e}},_=class extends f{ts;constructor(e){let{coll:r,id:n,ts:o,...s}=e;super({coll:r,id:n}),this.ts=o,Object.assign(this,s)}toObject(){return{...this}}},D=class{coll;name;constructor({coll:e,name:r}){this.name=r,typeof e=="string"?this.coll=new h(e):this.coll=e}},P=class extends D{ts;data;constructor(e){let{coll:r,name:n,ts:o,data:s,...a}=e;super({coll:r,name:n}),this.ts=o,this.data=s||{},Object.assign(this,a)}toObject(){return{...this}}},h=class{name;constructor(e){this.name=e}};var k=class{data;after;constructor({data:e,after:r}){this.data=e,this.after=r}};var C=class{static encode(e){return H(e)}static decode(e){return JSON.parse(e,(r,n)=>{if(n==null)return null;if(n["@mod"])return new h(n["@mod"]);if(n["@doc"]){if(typeof n["@doc"]=="string"){let[s,a]=n["@doc"].split(":");return new f({coll:s,id:a})}let o=n["@doc"];return o.id?new _(o):new P(o)}else if(n["@ref"]){let o=n["@ref"];return o.id?new f(o):new D(o)}else{if(n["@set"])return new k(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 p.from(n["@date"]);if(n["@time"])return g.from(n["@time"]);if(n["@object"])return n["@object"]}return n})}},oe=BigInt("-9223372036854775808"),se=BigInt("9223372036854775807"),u={bigint:t=>{if(t<oe||t>se)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]=H(t[n]));return e?{"@object":r}:r},array:t=>{let e=[];for(let r in t)e.push(H(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=>({data:u.array(t.data),after:t.after})},H=t=>{if(t===void 0)throw new TypeError("Passing undefined as a QueryValue is not supported");switch(typeof t){case"bigint":return u.bigint(t);case"string":return u.string(t);case"number":return u.number(t);case"boolean":return t;case"object":return t==null?null:Array.isArray(t)?u.array(t):t instanceof Date?u.date(t):t instanceof p?u.faunadate(t):t instanceof g?u.faunatime(t):t instanceof h?u.module(t):t instanceof _?u.document(t):t instanceof f?u.documentReference(t):t instanceof P?u.namedDocument(t):t instanceof D?u.namedDocumentReference(t):t instanceof k?u.set(t):u.object(t)}};var ae={endpoint:N.default,max_conns:10},A=class{#t;#r;#e;#n;constructor(e,r){this.#t={...ae,...e,secret:this.#s(e)},this.#n=new URL("/query/1",this.clientConfiguration.endpoint).toString(),r?this.#r=r:this.#r=U()}get lastTxnTs(){return this.#e}set lastTxnTs(e){this.#e=this.#e?Math.max(e,this.#e):e}get clientConfiguration(){let{secret:e,...r}=this.#t;return r}async query(e,r){return this.#i(e.toQuery(r))}#o(e){if(e instanceof l||e instanceof y||e instanceof m||e instanceof i)return e;if(z(e)){if(L(e.body)){let r=e.body,n=e.status;return this.#a(r,n)}return new m({message:`Response is in an unkown format: ${e.body}`,httpStatus:e.status})}return new l("A client level error occurred. Fauna was not called.",{cause:e})}#s(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}#a(e,r){switch(r){case 400:return r===400&&ie.includes(e.error.code)?new x(e,r):new b(e,r);case 401:return new S(e,r);case 403:return new w(e,r);case 429:return new R(e,r);case 440:return new Q(e,r);case 500:return new E(e,r);case 503:return new q(e,r);default:return new i(e,r)}}async#i(e){try{let r={Authorization:`Bearer ${this.#t.secret}`};this.#c({...this.clientConfiguration,...e},r);let n=(this.#t.format??"tagged")==="tagged"||e.format==="tagged",o=n?C.encode(e.arguments):e.arguments,s={query:e.query,arguments:o},a=await this.#r.request({url:this.#n,method:"POST",headers:r,data:s}),c;try{if(c={...a,body:n?C.decode(a.body):JSON.parse(a.body)},c.body.query_tags){let T=c.body.query_tags.split(",").map(j=>j.split("="));c.body.query_tags=Object.fromEntries(T)}}catch(T){throw new m({message:`Error parsing response as JSON: ${T}`,httpStatus:a.status})}if(!M(c.body))throw this.#o(c);let d=c.body.txn_ts;return(this.#e===void 0&&d!==void 0||d!==void 0&&this.#e!==void 0&&this.#e<d)&&(this.#e=d),c.body}catch(r){throw this.#o(r)}}#c(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 o,s=`x-${n[0].replaceAll("_","-")}`;n[0]==="query_tags"?o=Object.entries(n[1]).map(a=>a.join("=")).join(","):typeof n[1]=="string"?o=n[1]:o=String(n[1]),n[0]==="traceparent"&&(s=n[0]),r[s]=o}r["x-last-txn-ts"]===void 0&&this.#e!==void 0&&(r["x-last-txn-ts"]=this.#e)}},ie=["invalid_function_definition","invalid_identifier","invalid_query","invalid_syntax","invalid_type"];function ce(t,...e){return new O(t,...e)}var O=class{#t;#r;constructor(e,...r){if(e.length===0||e.length!==r.length+1)throw new Error("invalid query constructed");this.#t=e,this.#r=r}toQuery(e={}){return{...this.#e(e),...e}}#e(e){if(this.#t.length===1)return{query:{fql:[this.#t[0]]},arguments:{}};let r={};return{query:{fql:this.#t.flatMap((o,s)=>{if(s===this.#t.length-1)return o===""?[]:[o];let a=this.#r[s],c;if(a instanceof O){let d=a.toQuery(e);c=d.query,r={...r,...d.arguments}}else c={value:C.encode(a)};return[o,c].filter(d=>d!=="")})},arguments:r}}};export{S as AuthenticationError,w as AuthorizationError,A as Client,l as ClientError,p as DateStub,_ as Document,f as DocumentReference,h as Module,P as NamedDocument,D as NamedDocumentReference,y as NetworkError,k as Page,m as ProtocolError,x as QueryCheckError,b as QueryRuntimeError,Q as QueryTimeoutError,i as ServiceError,E as ServiceInternalError,q as ServiceTimeoutError,R as ThrottlingError,g as TimeStub,N as endpoints,ce as fql};
//# sourceMappingURL=index.js.map

@@ -5,3 +5,3 @@ export { Client } from "./client";

export { type Query, fql } from "./query-builder";
export { type JSONObject, type JSONValue, type QueryFailure, type QueryInfo, type QueryInterpolation, type QueryRequest, type QueryRequestHeaders, type QueryStats, type QuerySuccess, type Span, type ValueFragment, } from "./wire-protocol";
export { type QueryValueObject, type QueryValue, type QueryFailure, type QueryInfo, type QueryInterpolation, type QueryRequest, type QueryRequestHeaders, type QueryStats, type QuerySuccess, type Span, type ValueFragment, } from "./wire-protocol";
export { DateStub, Document, DocumentReference, type DocumentT, Module, NamedDocument, NamedDocumentReference, Page, TimeStub, } from "./values";

@@ -621,3 +621,5 @@ "use strict";

}
_out[k] = encode(input[k]);
if (input[k] !== void 0) {
_out[k] = encode(input[k]);
}
}

@@ -656,2 +658,5 @@ return wrapped ? { "@object": _out } : _out;

var encode = (input) => {
if (input === void 0) {
throw new TypeError("Passing undefined as a QueryValue is not supported");
}
switch (typeof input) {

@@ -664,2 +669,4 @@ case "bigint":

return encodeMap["number"](input);
case "boolean":
return input;
case "object":

@@ -691,5 +698,3 @@ if (input == null) {

}
break;
}
return input;
};

@@ -696,0 +701,0 @@

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

import type { JSONValue, QueryRequest, QueryRequestHeaders } from "./wire-protocol";
import type { QueryValue, QueryRequest, QueryRequestHeaders } from "./wire-protocol";
/**

@@ -6,3 +6,3 @@ * Creates a new Query. Accepts template literal inputs.

* the strings that are the basis of the query.
* @param queryArgs - an Array\<JSONValue | Query\> that
* @param queryArgs - an Array\<QueryValue | Query\> that
* constitute the arguments to inject between the queryFragments.

@@ -19,3 +19,3 @@ * @throws Error - if you call this method directly (not using template

*/
export declare function fql(queryFragments: ReadonlyArray<string>, ...queryArgs: (JSONValue | Query)[]): Query;
export declare function fql(queryFragments: ReadonlyArray<string>, ...queryArgs: (QueryValue | Query)[]): Query;
/**

@@ -28,3 +28,3 @@ * Internal class.

#private;
constructor(queryFragments: ReadonlyArray<string>, ...queryArgs: (JSONValue | Query)[]);
constructor(queryFragments: ReadonlyArray<string>, ...queryArgs: (QueryValue | Query)[]);
/**

@@ -31,0 +31,0 @@ * Converts this Query to a {@link QueryRequest} you can send

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

import { JSONObject } from "../wire-protocol";
import { QueryValueObject } from "../wire-protocol";
import { TimeStub } from "./date-time";

@@ -108,3 +108,3 @@ /**

*/
export declare class NamedDocument<T extends JSONObject = Record<string, never>> extends NamedDocumentReference {
export declare class NamedDocument<T extends QueryValueObject = Record<string, never>> extends NamedDocumentReference {
readonly ts: TimeStub;

@@ -161,2 +161,2 @@ readonly data: T;

*/
export type DocumentT<T extends JSONObject> = Document & T;
export type DocumentT<T extends QueryValueObject> = Document & T;

@@ -1,3 +0,3 @@

import { JSONValue } from "../wire-protocol";
export declare class Page<T extends JSONValue> {
import { QueryValue } from "../wire-protocol";
export declare class Page<T extends QueryValue> {
readonly data: T[];

@@ -4,0 +4,0 @@ readonly after?: string;

@@ -11,3 +11,3 @@ import { DateStub, Document, DocumentReference, Module, NamedDocument, NamedDocumentReference, Page, TimeStub } from "./values";

*/
arguments?: JSONObject;
arguments?: QueryValueObject;
}

@@ -166,3 +166,3 @@ export interface QueryRequestHeaders {

export type ValueFragment = {
value: JSONValue;
value: QueryValue;
};

@@ -209,10 +209,18 @@ /**

/**
* All objects returned from Fauna are valid JSON objects.
* A QueryValueObject is a plain javascript object where
* each value is a QueryValue.
* i.e. these objects can be set as values
* in the {@link fql} query creation function and can be
* returned in {@link QuerySuccess}.
*/
export type JSONObject = {
[key: string]: JSONValue;
export type QueryValueObject = {
[key: string]: QueryValue;
};
/**
* All values returned from Fauna are valid JSON values.
* A QueryValue can be sent as a value in a query,
* and received from query output.
* i.e. these are the types you can set as values
* in the {@link fql} query creation function and can be
* returned in {@link QuerySuccess}.
*/
export type JSONValue = null | string | number | bigint | boolean | JSONObject | Array<JSONValue> | DateStub | TimeStub | Module | Document | DocumentReference | NamedDocument | NamedDocumentReference | Page<JSONValue>;
export type QueryValue = null | string | number | bigint | boolean | QueryValueObject | Array<QueryValue> | DateStub | TimeStub | Module | Document | DocumentReference | NamedDocument | NamedDocumentReference | Page<QueryValue>;
{
"name": "fauna",
"version": "0.5.3",
"version": "0.5.4",
"description": "A driver to query Fauna databases in browsers, Node.js, and other Javascript runtimes",

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

@@ -123,6 +123,5 @@ > **WARNING**

The `fql` function is your gateway to building safe, reuseable Fauna queries.
It allows you compose queries from sub-queries and variables native to your program. Variables passed in our treated as unexecutable values in Fauna's API - preventing security issues like injection attacks.
It allows you compose queries from sub-queries and variables native to your program. Variables passed in are treated as unexecutable values in Fauna's API - preventing security issues like injection attacks.

@@ -155,2 +154,3 @@ for example:

### Pure FQL X via the `fql` function
The `fql` function can also create pure FQL X queries, for example:

@@ -182,3 +182,2 @@

```javascript

@@ -294,4 +293,8 @@ // a reusable FQL X lambda to create Users with validated parameters

The client can be configured for your specific environment. You can also provide query options that will be sent by default with every request
The driver use's a default ClientConfiguration. We recommend most users stick with the defaults.
If your environment needs different configuration however, the default ClientConfiguration can be overriden.
Furthermore, on each request you can provide query specific configuration that will override the setting in your client for that request only.
```typescript

@@ -304,2 +307,4 @@ import { Client, endpoints, type ClientConfiguration } from "fauna";

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

@@ -306,0 +311,0 @@

@@ -23,4 +23,4 @@ export { Client } from "./client";

export {
type JSONObject,
type JSONValue,
type QueryValueObject,
type QueryValue,
type QueryFailure,

@@ -27,0 +27,0 @@ type QueryInfo,

import { TaggedTypeFormat } from "./tagged-type";
import type {
JSONObject,
JSONValue,
QueryValueObject,
QueryValue,
QueryInterpolation,

@@ -14,3 +14,3 @@ QueryRequest,

* the strings that are the basis of the query.
* @param queryArgs - an Array\<JSONValue | Query\> that
* @param queryArgs - an Array\<QueryValue | Query\> that
* constitute the arguments to inject between the queryFragments.

@@ -29,3 +29,3 @@ * @throws Error - if you call this method directly (not using template

queryFragments: ReadonlyArray<string>,
...queryArgs: (JSONValue | Query)[]
...queryArgs: (QueryValue | Query)[]
): Query {

@@ -42,7 +42,7 @@ return new Query(queryFragments, ...queryArgs);

readonly #queryFragments: ReadonlyArray<string>;
readonly #queryArgs: (JSONValue | Query)[];
readonly #queryArgs: (QueryValue | Query)[];
constructor(
queryFragments: ReadonlyArray<string>,
...queryArgs: (JSONValue | Query)[]
...queryArgs: (QueryValue | Query)[]
) {

@@ -84,3 +84,3 @@ if (

let resultArgs: JSONObject = {};
let resultArgs: QueryValueObject = {};
const renderedFragments: (string | QueryInterpolation)[] =

@@ -87,0 +87,0 @@ this.#queryFragments.flatMap((fragment, i) => {

@@ -11,3 +11,3 @@ import {

} from "./values";
import { JSONObject, JSONValue } from "./wire-protocol";
import { QueryValueObject, QueryValue } from "./wire-protocol";

@@ -85,3 +85,3 @@ /**

type TaggedMod = { "@mod": string };
type TaggedObject = { "@object": JSONObject };
type TaggedObject = { "@object": QueryValueObject };
type TaggedRef = {

@@ -91,3 +91,3 @@ "@ref": { id: string; coll: TaggedMod } | { name: string; coll: TaggedMod };

// WIP: core does not accept `@set` tagged values
// type TaggedSet = { "@set": { data: JSONValue[]; after?: string } };
// type TaggedSet = { "@set": { data: QueryValue[]; after?: string } };
type TaggedTime = { "@time": string };

@@ -134,5 +134,5 @@

},
object: (input: JSONObject): TaggedObject | JSONObject => {
object: (input: QueryValueObject): TaggedObject | QueryValueObject => {
let wrapped = false;
const _out: JSONObject = {};
const _out: QueryValueObject = {};

@@ -143,8 +143,10 @@ for (const k in input) {

}
_out[k] = encode(input[k]);
if (input[k] !== undefined) {
_out[k] = encode(input[k]);
}
}
return wrapped ? { "@object": _out } : _out;
},
array: (input: Array<JSONValue>): Array<JSONValue> => {
const _out: JSONValue = [];
array: (input: Array<QueryValue>): Array<QueryValue> => {
const _out: QueryValue = [];
for (const i in input) _out.push(encode(input[i]));

@@ -179,3 +181,6 @@ return _out;

const encode = (input: JSONValue): JSONValue => {
const encode = (input: QueryValue): QueryValue => {
if (input === undefined) {
throw new TypeError("Passing undefined as a QueryValue is not supported");
}
switch (typeof input) {

@@ -188,2 +193,4 @@ case "bigint":

return encodeMap["number"](input);
case "boolean":
return input;
case "object":

@@ -217,6 +224,4 @@ if (input == null) {

}
break;
}
// default to encoding directly as the input
return input;
// anything here would be unreachable code
};

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

import { JSONObject } from "../wire-protocol";
import { QueryValueObject } from "../wire-protocol";
import { TimeStub } from "./date-time";

@@ -130,3 +130,3 @@

export class NamedDocument<
T extends JSONObject = Record<string, never>
T extends QueryValueObject = Record<string, never>
> extends NamedDocumentReference {

@@ -194,2 +194,2 @@ readonly ts: TimeStub;

*/
export type DocumentT<T extends JSONObject> = Document & T;
export type DocumentT<T extends QueryValueObject> = Document & T;

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

import { JSONValue } from "../wire-protocol";
import { QueryValue } from "../wire-protocol";
export class Page<T extends JSONValue> {
export class Page<T extends QueryValue> {
readonly data: T[];

@@ -5,0 +5,0 @@ readonly after?: string;

@@ -24,3 +24,3 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars

*/
arguments?: JSONObject;
arguments?: QueryValueObject;
}

@@ -199,3 +199,3 @@

*/
export type ValueFragment = { value: JSONValue };
export type ValueFragment = { value: QueryValue };

@@ -242,12 +242,20 @@ /**

/**
* All objects returned from Fauna are valid JSON objects.
* A QueryValueObject is a plain javascript object where
* each value is a QueryValue.
* i.e. these objects can be set as values
* in the {@link fql} query creation function and can be
* returned in {@link QuerySuccess}.
*/
export type JSONObject = {
[key: string]: JSONValue;
export type QueryValueObject = {
[key: string]: QueryValue;
};
/**
* All values returned from Fauna are valid JSON values.
* A QueryValue can be sent as a value in a query,
* and received from query output.
* i.e. these are the types you can set as values
* in the {@link fql} query creation function and can be
* returned in {@link QuerySuccess}.
*/
export type JSONValue =
export type QueryValue =
// plain javascript values

@@ -259,5 +267,5 @@ | null

| boolean
| JSONObject
| Array<JSONValue>
// fauna-provided classes
| QueryValueObject
| Array<QueryValue>
// client-provided classes
| DateStub

@@ -270,2 +278,2 @@ | TimeStub

| NamedDocumentReference
| Page<JSONValue>;
| Page<QueryValue>;

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