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

@based/graphql

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@based/graphql - npm Package Compare versions

Comparing version 1.0.6 to 1.0.8

dist/index.ts

2

build/index.js

@@ -22,3 +22,3 @@ const { build } = require('esbuild')

build({
outfile: join(__dirname, '../dist/bundle.js'),
outfile: join(__dirname, '../dist/index.js'),
bundle: true,

@@ -25,0 +25,0 @@ minify: true,

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

var Je=Object.create;var P=Object.defineProperty,we=Object.defineProperties,Be=Object.getOwnPropertyDescriptor,je=Object.getOwnPropertyDescriptors,Qe=Object.getOwnPropertyNames,Ne=Object.getOwnPropertySymbols,Pe=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable;var Oe=(e,n,t)=>n in e?P(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Te=(e,n)=>{for(var t in n||(n={}))ge.call(n,t)&&Oe(e,t,n[t]);if(Ne)for(var t of Ne(n))Me.call(n,t)&&Oe(e,t,n[t]);return e},Fe=(e,n)=>we(e,je(n)),Ee=e=>P(e,"__esModule",{value:!0});var ze=(e,n)=>{Ee(e);for(var t in n)P(e,t,{get:n[t],enumerable:!0})},Ue=(e,n,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Qe(n))!ge.call(e,i)&&i!=="default"&&P(e,i,{get:()=>n[i],enumerable:!(t=Be(n,i))||t.enumerable});return e},R=e=>Ue(Ee(P(e!=null?Je(Pe(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);ze(exports,{createGet:()=>ce,createMutation:()=>fe,createOperations:()=>qe,genSchema:()=>se,handleGraphqlVariables:()=>pe,parseGraphql:()=>C.parse});var C=R(require("graphql"));function te(){return` deleteNode(id: ID): Boolean
`}function ie(e,n={}){let t=`type Mutation {
var Y=Object.defineProperty,we=Object.defineProperties,Je=Object.getOwnPropertyDescriptor,je=Object.getOwnPropertyDescriptors,Qe=Object.getOwnPropertyNames,Oe=Object.getOwnPropertySymbols;var Te=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var ge=(e,n,t)=>n in e?Y(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Fe=(e,n)=>{for(var t in n||(n={}))Te.call(n,t)&&ge(e,t,n[t]);if(Oe)for(var t of Oe(n))Pe.call(n,t)&&ge(e,t,n[t]);return e},Ee=(e,n)=>we(e,je(n));var ze=(e,n)=>{for(var t in n)Y(e,t,{get:n[t],enumerable:!0})},Me=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Qe(n))!Te.call(e,r)&&r!==t&&Y(e,r,{get:()=>n[r],enumerable:!(i=Je(n,r))||i.enumerable});return e};var Ue=e=>Me(Y({},"__esModule",{value:!0}),e);var en={};ze(en,{createGet:()=>fe,createMutation:()=>de,createOperations:()=>qe,genSchema:()=>ae,handleGraphqlVariables:()=>me,parseGraphql:()=>R.parse});module.exports=Ue(en);var R=require("graphql");function ne(){return` deleteNode(id: ID): Boolean
`}function te(e,n={}){let t=`type Mutation {
`;t+=" setRoot(input: RootInput): Root",t+=`

@@ -8,5 +8,5 @@ `,t+=" callFn(name: String!, payload: JSON): JSON",t+=`

`,t+=`
`}for(let i in n)n[i].observable||(t+=` ${i}(payload: JSON): JSON`);return t+=te(),t+=`}
`}for(let i in n)n[i].observable||(t+=` ${i}(payload: JSON): JSON`);return t+=ne(),t+=`}
`,t}function re(e,n={}){let t=`type Query {
`,t}function ie(e,n={}){let t=`type Query {
`;t+=` node(id: ID): Node

@@ -17,3 +17,3 @@ `,t+=` root: Root

`,t+=`}
`,t}var be=`_all: BasedOperator
`,t}var Ve=`_all: BasedOperator
_value(v: JSON!): JSON!

@@ -23,3 +23,3 @@ _aggregate(edgeField: String!, function: AggregateFunction!, args: [JSON!], filter: Filter): Float

_inheritItem: Node!
`,Ie=`id: ID!
`,be=`id: ID!
type: String!

@@ -29,10 +29,10 @@

parents(filter: Filter, recursive: Boolean): [Node!]
children(filter: Filter, recursive: Boolean): [Node!]
parents(filter: Filter, sortBy: SortBy, recursive: Boolean): [Node!]
children(filter: Filter, sortBy: SortBy, recursive: Boolean): [Node!]
ancestors(filter: Filter): [Node!]
descendants(filter: Filter): [Node!]
${be}`,Ze=`aliases: StringSetInput
ancestors(filter: Filter, sortBy: SortBy): [Node!]
descendants(filter: Filter, sortBy: SortBy): [Node!]
${Ve}`,Ze=`aliases: StringSetInput
parents: ReferencesInput
children: ReferencesInput`,Y={id:"ID!",type:"String!",int:"Int",timestamp:"Int",float:"Float",number:"Float",string:"String",email:"String",phone:"String",digest:"String",url:"String",boolean:"Boolean",reference:"Node",references:"[Node!]",text:"Language",json:"JSON"},Ve=Fe(Te({},Y),{text:"LanguageInput",reference:"ID",references:"ReferencesInput"}),We=new Set(["id","type","aliases","parents","children","ancestors","descendants"]);function Ye(e){(e==null?void 0:e.length)||(e=["en"]);let n=e.map(i=>` ${i}: String`).join(`
children: ReferencesInput`,H={id:"ID!",type:"String!",int:"Int",timestamp:"Int",float:"Float",number:"Float",string:"String",email:"String",phone:"String",digest:"String",url:"String",boolean:"Boolean",reference:"Node",references:"[Node!]",text:"Language",json:"JSON"},Ie=Ee(Fe({},H),{text:"LanguageInput",reference:"ID",references:"ReferencesInput"}),We=new Set(["id","type","aliases","parents","children","ancestors","descendants"]);function Ye(e){e!=null&&e.length||(e=["en"]);let n=e.map(i=>` ${i}: String`).join(`
`);return`

@@ -46,8 +46,8 @@ type Language {

}
`}function oe(e){return["object","record","json"].includes(e.items.type)?"JSON":Y[e.items.type]}function ae(e,n,t,i=!0){n=n[0].toUpperCase()+n.slice(1);let r=new Set(i?["children","parents"]:[]),o="",d="",l="";for(let f in t){if(We.has(f))continue;let c=t[f];if(d+=`
`}function re(e){return["object","record","json"].includes(e.items.type)?"JSON":H[e.items.type]}function oe(e,n,t,i=!0){n=n[0].toUpperCase()+n.slice(1);let r=new Set(i?["children","parents"]:[]),a="",u="",l="";for(let f in t){if(We.has(f))continue;let c=t[f];if(u+=`
`,l+=`
`,c.type==="object"){let $=f[0].toUpperCase()+f.slice(1),N=`${n}${$}`;o+=ae(e,N,c.properties,!1),d+=`${f}: ${N}`,l+=`${f}: ${N}Input`,o+=j(n,c,N)}else if(c.type==="record")d+=`${f}: JSON`,l+=`${f}: JSON`,o+=j(n,c,"JSON");else if(c.type==="array")d+=`${f}: [JSON]`,l+=`${f}: [JSON]`,o+=j(n,c,"[JSON]");else if(c.type==="set")d+=`${f}: [${oe(c)}!]`,l+=`${f}: [${oe(c)}!]`,o+=j(n,c,`[${oe(c)}!]`);else if(c.type==="references"){r.add(f);let $=Y.references,N=Ve[c.type];d+=`${f}(filter: Filter, recursive: Boolean): ${$}`,l+=`${f}: ${N}`,o+=j(n,c,$)}else{let $=Y[c.type],N=Ve[c.type];d+=`${f}: ${$}`,l+=`${f}: ${N}`,o+=j(n,c,$)}c.timeseries}let a="";if(r.size){a+=`enum ${n}TraverseByTypeFields {`;for(let f of r)a+=` ${f}
`;a+=`}
`,c.type==="object"){let v=f[0].toUpperCase()+f.slice(1),N=`${n}${v}`;a+=oe(e,N,c.properties,!1),u+=`${f}: ${N}`,l+=`${f}: ${N}Input`,a+=Q(n,c,N)}else if(c.type==="record")u+=`${f}: JSON`,l+=`${f}: JSON`,a+=Q(n,c,"JSON");else if(c.type==="array")u+=`${f}: [JSON]`,l+=`${f}: [JSON]`,a+=Q(n,c,"[JSON]");else if(c.type==="set")u+=`${f}: [${re(c)}!]`,l+=`${f}: [${re(c)}!]`,a+=Q(n,c,`[${re(c)}!]`);else if(c.type==="references"){r.add(f);let v=H.references,N=Ie[c.type];u+=`${f}(filter: Filter, sortBy: SortBy, recursive: Boolean): ${v}`,l+=`${f}: ${N}`,a+=Q(n,c,v)}else{let v=H[c.type],N=Ie[c.type];u+=`${f}: ${v}`,l+=`${f}: ${N}`,a+=Q(n,c,v)}c.timeseries}let o="";if(r.size){o+=`enum ${n}TraverseByTypeFields {`;for(let f of r)o+=` ${f}
`;o+=`}
`,a+=`input ${n}TraverseByTypeExpression {
`,o+=`input ${n}TraverseByTypeExpression {
all: [${n}TraverseByTypeFields!]

@@ -57,11 +57,11 @@ first: [${n}TraverseByTypeFields!]

`}let s=`
${o}
${a}
type ${n}${i?" implements Node":""} {
${i?Ie:be}
${i?be:Ve}
${r.size?"_traverse(traverse: TraverseByType, filter: Filter, recursive: Boolean = false): [Node!]":""}
${r.size?"_traverse(traverse: TraverseByType, filter: Filter, sortBy: SortBy, recursive: Boolean = false): [Node!]":""}
${d.slice(3)}
${u.slice(3)}
}
`,u=`
`,d=`
input ${n}Input {

@@ -71,5 +71,5 @@ ${i?Ze:""}

}
`;return a+s+u}function j(e,n,t){if(!n.timeseries)return"";console.log("YES HAS TIMESERIES",e,n,t)}function He(){return`
`;return o+s+d}function Q(e,n,t){if(!n.timeseries)return"";console.log("YES HAS TIMESERIES",e,n,t)}function He(){return`
interface Node {
${Ie}
${be}
}

@@ -93,2 +93,12 @@ `}function Ke(e){let n=`

enum SortByOrder {
DESC
ASC
}
input SortBy {
field: String!
order: SortByOrder
}
input Filter {

@@ -134,8 +144,8 @@ op: FilterOperation!

`,n+=" root";for(let i in e.types)n+=` ${i}`;return n+=`}
`,n}function se(e,n={}){let t="";t+=`scalar JSON
`,n}function ae(e,n={}){let t="";t+=`scalar JSON
`,t+=`scalar BasedOperator
`,t+=`directive @default(value: JSON!) on FIELD
`,t+=`directive @inherit(type: [NodeType]) on FIELD
`,t+=Ye(e==null?void 0:e.languages),t+=He(),t+=Ke(e),t+=ae(e,"root",e.rootType.fields);for(let i in e.types){let r=e.types[i];t+=ae(e,i,r.fields)}return t+=`
`,t+=ie(e,n),t+=`
`,t+=re(e,n),t}var U=R(require("graphql"));function Xe(e,n){return n.startsWith("ro")?"root":e.prefixToTypeMapping[n.substr(0,2)]}function he(e,n,t){if(!t||t===""||typeof t!="string")return null;let i=Xe(e,n),r=t.split("."),o=i==="root"?e.rootType:e.types[i];if(!o||!o.fields)return null;let d=r[0];if(d.endsWith("]")){for(let a=d.length-1;a>=0;a--)if(d[a]==="["){d=d.slice(0,a);break}}let l=o.fields[d];if(!l)return null;for(let a=1;a<r.length;a++){let s=r[a];if(s.endsWith("]")){for(let u=s.length-1;u>=0;u--)if(s[u]==="["){s=s.slice(0,u);break}}if(!l)return null;if(l.type==="text"&&a===r.length-1)return{type:"string"};if(l.values)l=l.values;else if(l.type==="array")l=l.items,l=l.properties[s];else{if(!l.properties)return null;l=l.properties[s]}}return l}function ke(e){return e.schemas[e.db||"default"]}function M(e,n={}){if(!!e){if(e.kind==="StringValue")return e.value;if(e.kind==="FloatValue")return Number(e.value);if(e.kind==="IntValue")return Number(e.value);if(e.kind==="ListValue")return e.values.map(t=>M(t,n));if(e.kind==="Variable")return{$var:e.name.value};throw new Error(`String or variable name requried for references, ${JSON.stringify(e,null,2)} given`)}}function E(e,n={}){if(!!e){if(e.kind==="StringValue")return e.value;if(e.kind==="Variable")return{$var:e.name.value};throw new Error(`String or variable name requried for references, ${JSON.stringify(e,null,2)} given`)}}function Ge(e,n={}){if(e.kind==="IntValue")return Number(e.value);if(e.kind==="FloatValue")return Number(e.value);if(e.kind==="Variable")return{$var:e.name.value};throw new Error(`String or variable name requried for references, ${JSON.stringify(e,null,2)} given`)}function k(e,n){return ke(e).types[n]?n:n[0].toLowerCase()+n.slice(1)}function H(e,n,t){var o;let i=ke(e),r=n==="root"?"ro":(o=i==null?void 0:i.types[n])==null?void 0:o.prefix;if(!!r)return he(i,r,t.slice(1))}var De=R(require("graphql"));function K(e,n,t,i={},r=""){if(t.kind!=="ObjectValue")return;let o={};for(let d of t.fields){let l=d.name.value,a=d.value;if((a==null?void 0:a.kind)==="NullValue"){o[l]={$delete:!0};continue}let s=`${r}.${l}`,u=Ae(e,n,a,i,s);u!==void 0&&(o[l]=u)}return o}function Ae(e,n,t,i={},r=""){var d;let o=H(e,n,r);if(!!o){if(t.kind==="Variable")return{$var:(d=t==null?void 0:t.name)==null?void 0:d.value};switch(o.type){case"set":case"references":let l={ADD:"$add",REMOVE:"$delete",SET:"$value"};if(t.kind!=="ObjectValue")throw new Error(`Invalid payload ${t} for ${r}`);let a,s;if(t.fields[0].name.value==="op"?(a=t.fields[0].value,s=t.fields[1].value):(a=t.fields[1].value,s=t.fields[0].value),a.kind!=="EnumValue")throw new Error(`Invalid references operation ${a} in ${t} for ${r}`);if(s.kind!=="ListValue")throw new Error(`Invalid references ids argument ${s} in ${t} for ${r}`);if(a=a.value,!l[a])throw new Error(`Invalid references operation ${a}, should be one of ${JSON.stringify(Object.keys(l))} for ${r}`);return s=s.values.map(u=>E(u,i)),{[l[a]]:s};case"object":if(t.kind!=="ObjectValue")throw new Error(`Trying to set a non-object value ${t} to object field ${r}`);return K(e,n,t,i,r);case"url":case"phone":case"digest":case"string":case"reference":return E(t,i);case"float":case"int":case"number":return Ge(t,i);case"json":return t.kind==="ObjectValue"?JSON.parse((0,De.print)(t).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):t==null?void 0:t.value;default:console.log("CATCHALL",o,t);return}}}var L=R(require("graphql"));var le=R(require("graphql"));function x(e){return!e||!e.length?{}:e.reduce((n,t)=>{var d,l;let i=(d=t==null?void 0:t.name)==null?void 0:d.value,r=(l=t==null?void 0:t.arguments[0])==null?void 0:l.value;if((r==null?void 0:r.kind)==="ListValue")for(let a of r==null?void 0:r.values)(a==null?void 0:a.kind)==="EnumValue"&&(a.kind="StringValue");let o=r?r.kind==="ObjectValue"?JSON.parse((0,le.print)(r).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,le.print)(r)):!0;return Object.assign(n,{[i]:o})},{})}function X(e,n){return n.default?(e.$default=n.default,!0):n.inherit?(e.$inherit=n.inherit===!0?!0:{$type:n.inherit},!0):!1}function h(e,n,t={}){if(!(e==null?void 0:e.value)&&!(n==null?void 0:n.size))return;let i=[];if(e==null?void 0:e.value){if((e==null?void 0:e.value.kind)!=="ObjectValue")throw new Error(`Invalid filter ${JSON.stringify(e.value,null,2)}`);let r=ue(e.value,t);i.push(r)}return(n==null?void 0:n.size)&&i.push({$field:"type",$operator:"=",$value:[...n]}),i}function ue(e,n={}){var s,u,f,c,$,N;let t={EQ:"=",NEQ:"!=",LT:"<",GT:">",EXISTS:"exists",NOT_EXISTS:"notExists",HAS:"has"};if(e.kind!=="ObjectValue")return;let i=(u=(s=e.fields.find(y=>{var m;return((m=y==null?void 0:y.name)==null?void 0:m.value)==="op"}))==null?void 0:s.value)==null?void 0:u.value,r=E((f=e.fields.find(y=>{var m;return((m=y==null?void 0:y.name)==null?void 0:m.value)==="field"}))==null?void 0:f.value,n),o=M((c=e.fields.find(y=>{var m;return((m=y==null?void 0:y.name)==null?void 0:m.value)==="value"}))==null?void 0:c.value,n);if(!t[i]||!r||o===void 0||o===null)return;let d=($=e.fields.find(y=>{var m;return((m=y==null?void 0:y.name)==null?void 0:m.value)==="and"}))==null?void 0:$.value,l=(N=e.fields.find(y=>{var m;return((m=y==null?void 0:y.name)==null?void 0:m.value)==="or"}))==null?void 0:N.value,a={$operator:t[i],$field:r,$value:o};return d?a.$and=ue(d,n):l&&(a.$or=ue(l,n)),a}function xe(e,n){var a,s,u;let t=E((a=e.arguments.find(f=>f.name.value==="edgeField"))==null?void 0:a.value,n);if(!t)return;let i=(s=e.arguments.find(f=>f.name.value==="function"))==null?void 0:s.value,r=i==null?void 0:i.value.toLowerCase();if(!r)return;let o=M((u=e.arguments.find(f=>f.name.value==="args"))==null?void 0:u.value),d=e.arguments.find(f=>f.name.value==="filter"),l=h(d,new Set,n);return{$aggregate:{$traverse:t,$function:{$name:r,$args:o},$filter:l}}}function Le(e){var t,i;if(!e.arguments)return{$inherit:!0};let n=(i=(t=e.arguments[0])==null?void 0:t.value)==null?void 0:i.values.map(r=>r.value);return n.length?{$inherit:{$type:n}}:{$inherit:!0}}var Re=R(require("graphql"));var de=R(require("graphql"));function A(e){var i;let n=(i=e.arguments[0])==null?void 0:i.value;if(!n||e.arguments.length>1)throw new Error("Too many arguments given to _value, should be 1 of type JSON");return{$value:n.kind==="ObjectValue"?JSON.parse((0,de.print)(n).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,de.print)(n))}}function Ce(e,n,t,i,r={}){var a;let o={},d=t.selectionSet,l=new Set;for(let s of d.selections)if(s.kind==="InlineFragment"){let u=k(e,s.typeCondition.name.value);l.add(u);let f=G(e,u,s.selectionSet,r);o.$fieldsByType||(o.$fieldsByType={}),o.$fieldsByType[u]=f}else{if(s.kind!==Re.Kind.FIELD)return;let u=(a=s==null?void 0:s.alias)==null?void 0:a.value,f=s.name.value,c=x(s.directives);f==="__typename"?(f="type",u||(u="type")):f==="_all"?c.default?o.$default=c.default:o.$all=!0:f==="_value"&&u?o[u]=A(s):o[u||f]=w(e,c,n,s,i,r,`.${f}`)}if(!!l.size)return o.$inherit={$item:[...l]},o}function z(e,n,{name:t,alias:i},r,o,d,l,a){if(t==="__typename")a.__typename={$field:"type"};else if(t==="_all")X(a,o)||(a.$all=!0);else if(t==="_value"&&i)a[i]=A(r);else if(t==="_aggregate"&&i)a[i]=xe(r,l);else if(t==="_inherit"&&i)a[i]=Le(r);else if(t==="_inheritItem"&&i)a[i]=Ce(e,n,r,d,l);else return!1;return!0}function G(e,n,t,i,r={},o=""){var l,a,s;let d={};for(let u of t.selections){if(u.kind==="InlineFragment"){if(k(e,u.typeCondition.name.value)!==n)continue;for(let S of u.selectionSet.selections){if(S.kind!==L.Kind.FIELD)continue;let O=(l=S==null?void 0:S.alias)==null?void 0:l.value,b=S.name.value,D=`${o}.${b}`,_=w(e,x(S.directives),n,S,i,r,D);_!==void 0&&(d[O||b]=_)}continue}else if(u.kind===L.Kind.FRAGMENT_SPREAD){let m=i[u.name.value];if(!m)continue;let S=k(e,m.typeCondition.name.value);if(S==="node"&&(S=n),S!==n)continue;for(let O of m.selectionSet.selections){if(O.kind!==L.Kind.FIELD)continue;let b=(a=O==null?void 0:O.alias)==null?void 0:a.value,D=O.name.value,_=x(O.directives);if(z(e,n,{name:D,alias:b},O,_,i,r,d))continue;let W=`${o}.${D}`,Q=w(e,x(O.directives),n,O,i,r,W);Q!==void 0&&(d[b||D]=Q)}continue}let f=(s=u==null?void 0:u.alias)==null?void 0:s.value,c=u.name.value,$=x(u.directives);if(z(e,n,{name:c,alias:f},u,$,i,r,d))continue;let N=`${o}.${c}`,y=w(e,$,n,u,i,r,N);y!==void 0&&(d[f||c]=y)}return d}function w(e,n,t,i,r,o={},d=""){var s,u,f,c,$,N,y,m,S,O,b,D,_,W,Q,ye,Se;if(i.kind!==L.Kind.FIELD)return;let l=H(e,t,d);if(!l)if(i.name.value==="_traverse")l={type:"references"};else return;if(i.selectionSet){let J=i.name.value,_e=i.arguments,q=null,$e=i.selectionSet,ve=null;for(let v of _e)if(((s=v==null?void 0:v.name)==null?void 0:s.value)==="traverse"){if(((u=v==null?void 0:v.value)==null?void 0:u.kind)!=="ObjectValue")continue;J={};let B=(f=v==null?void 0:v.value)==null?void 0:f.fields;for(let I of B){if(((c=I==null?void 0:I.value)==null?void 0:c.kind)!=="ObjectValue")continue;let ee=($=I==null?void 0:I.name)==null?void 0:$.value,p=(N=I==null?void 0:I.value)==null?void 0:N.fields[0],g=(y=p==null?void 0:p.name)==null?void 0:y.value;if(!["all","first"].includes(g))throw new Error(`Unsupported field for _traverse.traverse ${g}`);if(((m=p==null?void 0:p.value)==null?void 0:m.kind)!=="ListValue")continue;let T=((S=p==null?void 0:p.value)==null?void 0:S.values.map(ne=>ne==null?void 0:ne.value))||[],V=ee==="_any"?"$any":ee;T.length?J[V]={[`$${g}`]:T}:J[V]=!1}J.$any||(J.$any=!1)}else if(((O=v==null?void 0:v.name)==null?void 0:O.value)==="filter")ve=v;else if(((b=v==null?void 0:v.name)==null?void 0:b.value)==="recursive"&&((D=v==null?void 0:v.value)==null?void 0:D.kind)==="BooleanValue")q=(_=v==null?void 0:v.value)==null?void 0:_.value;else throw new Error(`Unsupported arg for _traverse ${(W=v==null?void 0:v.name)==null?void 0:W.value}`);let F={};switch(l.type){case"references":let v=!1,B=new Set;for(let p of $e.selections)if(p.kind==="InlineFragment"){let g=k(e,p.typeCondition.name.value);B.add(g);let T=G(e,g,p.selectionSet,o);F.$fieldsByType||(F.$fieldsByType={}),F.$fieldsByType[g]=T}else if(p.kind===L.Kind.FRAGMENT_SPREAD){let g=r[p.name.value];if(!g)continue;let T=k(e,g.typeCondition.name.value);B.add(T);let V=G(e,T,g.selectionSet,o);F.$fieldsByType||(F.$fieldsByType={}),F.$fieldsByType[T]=V}else{if(p.kind!==L.Kind.FIELD)continue;v=!0;let g=(Q=p==null?void 0:p.alias)==null?void 0:Q.value,T=p.name.value,V=x(p.directives);z(e,t,{name:T,alias:g},p,r,V,o,F)||(F[g||T]=w(e,V,t,p,r,o,`.${T}`))}F.$list={$find:{$traverse:J}};let I=h(ve,v?new Set:B,o);return I&&(F.$list.$find.$filter=I),q!==null&&(F.$list.$find.$recursive=q),F;case"reference":for(let p of $e.selections)if(p.kind==="InlineFragment"){let g=k(e,p.typeCondition.name.value),T=G(e,g,p.selectionSet,o);F.$fieldsByType||(F.$fieldsByType={}),F.$fieldsByType[g]=T}else if(p.kind===L.Kind.FRAGMENT_SPREAD){let g=r[p.name.value];if(!g)continue;let T=k(e,g.typeCondition.name.value);B.add(T);let V=G(e,T,g.selectionSet,o);F.$fieldsByType||(F.$fieldsByType={}),F.$fieldsByType[T]=V}else{if(p.kind!==L.Kind.FIELD)return;let g=(ye=p==null?void 0:p.alias)==null?void 0:ye.value,T=p.name.value,V=x(p.directives);z(e,t,{name:T,alias:g},p,V,r,o,F)||(F[g||T]=w(e,V,t,p,r,o,`.${T}`))}return F;case"object":return G(e,t,i.selectionSet,o,d);default:return((Se=i==null?void 0:i.alias)==null?void 0:Se.value)?{$field:d.slice(1)}:!0}}let a={$field:d.slice(1)};return X(a,n),a}function fe(e,n,t,i={}){var $,N,y;let r,o,d;if(n.name.value==="callFn"){let m=n.arguments.findIndex(D=>D.name.value==="name"),S=E(n.arguments[m].value,i),O=(N=($=n==null?void 0:n.arguments)==null?void 0:$[1-m])==null?void 0:N.value,b=O?O.kind==="ObjectValue"?JSON.parse((0,U.print)(O).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,U.print)(O)):!0;return{fnCall:{name:S,payload:b}}}else if(n.name.value.startsWith("create"))r=n.name.value.slice(6),o=n.arguments[0];else if(n.name.value.startsWith("set")){r=n.name.value.slice(3);let m=n.arguments.findIndex(S=>S.name.value==="input");o=n.arguments[m],r==="Root"?d="root":d=E(n.arguments[1-m].value,i)}else if(n.name.value==="deleteNode"){if(d=E(n.arguments[0].value,i),!d)throw new Error("Can't delete nodes without id argument");return{delete:{$id:d,$db:e.db||"default"}}}else{let m=n.name.value,S=(y=n.arguments[0])==null?void 0:y.value,O=S?S.kind==="ObjectValue"?JSON.parse((0,U.print)(S).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,U.print)(S)):!0;return{fnCall:{name:m,payload:O}}}let l=k(e,r);if(o.name.value!=="input")throw new Error(`Argument 'input' is required by mutation ${n.name.value}`);let a=o.value,s=K(e,l,a,i),u=Object.assign({},s,{type:l,$db:e.db||"default"});d?u.$id=d:u.$operation="insert";let f=G(e,l,n.selectionSet,t,i);f.$db=e.db||"default";let c=Object.keys(f);return c.length===1&&(c[0]==="type"||c[0]==="id")?{set:u}:c.length===2&&c.every(m=>["type","id"].includes(m))?{set:u}:{set:u,get:f}}var Z=R(require("graphql"));function ce(e,n,t,i={}){var s,u,f,c,$,N;let r=(s=n==null?void 0:n.name)==null?void 0:s.value;if(r==="observeFn"){let y=n.arguments.findIndex(b=>b.name.value==="name"),m=E(n.arguments[y].value,i),S=(f=(u=n==null?void 0:n.arguments)==null?void 0:u[1-y])==null?void 0:f.value,O=!S||!S.kind||S.kind==="NullValue"?void 0:S.kind==="ObjectValue"?JSON.parse((0,Z.print)(S).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,Z.print)(S));return{fnObserve:{name:m,payload:O}}}let o=r==="node"?"root":r;if(!(o==="root"||!!e.schemas[e.db||"default"].types[o])){let y=r,m=($=(c=n==null?void 0:n.arguments)==null?void 0:c[0])==null?void 0:$.value,S=!m||!m.kind||m.kind==="NullValue"?void 0:m.kind==="ObjectValue"?JSON.parse((0,Z.print)(m).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,Z.print)(m));return{fnObserve:{name:y,payload:S}}}let l=n.name.value==="root"?"root":E((N=n==null?void 0:n.arguments[0])==null?void 0:N.value,i),a=G(e,o,n.selectionSet,t,i);return a.$alias=l,a.$db=e.db||"default",{get:a}}function me(e){if(e.kind===C.Kind.LIST_TYPE){let n=me(e.type);return n.list=!0,n}else if((e==null?void 0:e.kind)===C.Kind.NON_NULL_TYPE){let n=me(e.type);return n.required=!0,n}return{type:e.name.value,required:!1,list:!1}}function qe(e,n){var a;let t,i={};for(let s of n.definitions)s.kind===C.Kind.OPERATION_DEFINITION?t=s:s.kind===C.Kind.FRAGMENT_DEFINITION&&(i[(a=s==null?void 0:s.name)==null?void 0:a.value]=s);if(!t.selectionSet)return;let r=((t==null?void 0:t.variableDefinitions)||[]).reduce((s,u)=>{var $,N;let f=(N=($=u==null?void 0:u.variable)==null?void 0:$.name)==null?void 0:N.value,c=u==null?void 0:u.type;return s[f]=me(c),s},{}),o,d;t.operation==="query"?(o="GET",d=ce):(o="SET",d=fe);let l={};return t.selectionSet.selections.map(async s=>{var $;if(s.kind!==C.Kind.FIELD)return;let u=($=s==null?void 0:s.alias)==null?void 0:$.value,f=s.name.value,c=d(e,s,i,r);l[u||f]=c}),{ops:l,opType:o,variables:r,db:e.db||"default"}}function pe(e,n,t){if(typeof n!="object")return n;if(Array.isArray(n))return n.map(r=>pe(e,r,t));if(n==null?void 0:n.$var){let r=n.$var;if(e.variables[r].required&&!t[r])throw new Error(`Variable ${r} required, but not provided`);return t[r]}let i={};for(let r in n)i[r]=pe(e,n[r],t);return i}0&&(module.exports={createGet,createMutation,createOperations,genSchema,handleGraphqlVariables,parseGraphql});
`,t+=Ye(e==null?void 0:e.languages),t+=He(),t+=Ke(e),t+=oe(e,"root",e.rootType.fields);for(let i in e.types){let r=e.types[i];t+=oe(e,i,r.fields)}return t+=`
`,t+=te(e,n),t+=`
`,t+=ie(e,n),t}var U=require("graphql");function Xe(e,n){return n.startsWith("ro")?"root":e.prefixToTypeMapping[n.substr(0,2)]}function he(e,n,t){if(!t||t===""||typeof t!="string")return null;let i=Xe(e,n),r=t.split("."),a=i==="root"?e.rootType:e.types[i];if(!a||!a.fields)return null;let u=r[0];if(u.endsWith("]")){for(let o=u.length-1;o>=0;o--)if(u[o]==="["){u=u.slice(0,o);break}}let l=a.fields[u];if(!l)return null;for(let o=1;o<r.length;o++){let s=r[o];if(s.endsWith("]")){for(let d=s.length-1;d>=0;d--)if(s[d]==="["){s=s.slice(0,d);break}}if(!l)return null;if(l.type==="text"&&o===r.length-1)return{type:"string"};if(l.values)l=l.values;else if(l.type==="array")l=l.items,l=l.properties[s];else{if(!l.properties)return null;l=l.properties[s]}}return l}function ke(e){return e.schemas[e.db||"default"]}function w(e,n={}){if(!!e){if(e.kind==="StringValue")return e.value;if(e.kind==="EnumValue")return e.value;if(e.kind==="FloatValue")return Number(e.value);if(e.kind==="IntValue")return Number(e.value);if(e.kind==="ListValue")return e.values.map(t=>w(t,n));if(e.kind==="Variable")return{$var:e.name.value};throw new Error(`String or variable name requried for references, ${JSON.stringify(e,null,2)} given`)}}function E(e,n={}){if(!!e){if(e.kind==="StringValue")return e.value;if(e.kind==="Variable")return{$var:e.name.value};throw new Error(`String or variable name requried for references, ${JSON.stringify(e,null,2)} given`)}}function De(e,n={}){if(e.kind==="IntValue")return Number(e.value);if(e.kind==="FloatValue")return Number(e.value);if(e.kind==="Variable")return{$var:e.name.value};throw new Error(`String or variable name requried for references, ${JSON.stringify(e,null,2)} given`)}function k(e,n){return ke(e).types[n]?n:n[0].toLowerCase()+n.slice(1)}function K(e,n,t){var a;let i=ke(e),r=n==="root"?"ro":(a=i==null?void 0:i.types[n])==null?void 0:a.prefix;if(!!r)return he(i,r,t.slice(1))}var Ge=require("graphql");function X(e,n,t,i={},r=""){if(t.kind!=="ObjectValue")return;let a={};for(let u of t.fields){let l=u.name.value,o=u.value;if((o==null?void 0:o.kind)==="NullValue"){a[l]={$delete:!0};continue}let s=`${r}.${l}`,d=Ae(e,n,o,i,s);d!==void 0&&(a[l]=d)}return a}function Ae(e,n,t,i={},r=""){var u;let a=K(e,n,r);if(!!a){if(t.kind==="Variable")return{$var:(u=t==null?void 0:t.name)==null?void 0:u.value};switch(a.type){case"set":case"references":let l={ADD:"$add",REMOVE:"$delete",SET:"$value"};if(t.kind!=="ObjectValue")throw new Error(`Invalid payload ${t} for ${r}`);let o,s;if(t.fields[0].name.value==="op"?(o=t.fields[0].value,s=t.fields[1].value):(o=t.fields[1].value,s=t.fields[0].value),o.kind!=="EnumValue")throw new Error(`Invalid references operation ${o} in ${t} for ${r}`);if(s.kind!=="ListValue")throw new Error(`Invalid references ids argument ${s} in ${t} for ${r}`);if(o=o.value,!l[o])throw new Error(`Invalid references operation ${o}, should be one of ${JSON.stringify(Object.keys(l))} for ${r}`);return s=s.values.map(d=>E(d,i)),{[l[o]]:s};case"object":if(t.kind!=="ObjectValue")throw new Error(`Trying to set a non-object value ${t} to object field ${r}`);return X(e,n,t,i,r);case"url":case"phone":case"digest":case"string":case"reference":return E(t,i);case"float":case"int":case"number":return De(t,i);case"json":return t.kind==="ObjectValue"?JSON.parse((0,Ge.print)(t).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):t==null?void 0:t.value;default:console.log("CATCHALL",a,t);return}}}var B=require("graphql");var se=require("graphql");function L(e){return!e||!e.length?{}:e.reduce((n,t)=>{var u,l;let i=(u=t==null?void 0:t.name)==null?void 0:u.value,r=(l=t==null?void 0:t.arguments[0])==null?void 0:l.value;if((r==null?void 0:r.kind)==="ListValue")for(let o of r==null?void 0:r.values)(o==null?void 0:o.kind)==="EnumValue"&&(o.kind="StringValue");let a=r?r.kind==="ObjectValue"?JSON.parse((0,se.print)(r).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,se.print)(r)):!0;return Object.assign(n,{[i]:a})},{})}function h(e,n){return n.default?(e.$default=n.default,!0):n.inherit?(e.$inherit=n.inherit===!0?!0:{$type:n.inherit},!0):!1}function A(e,n,t={}){if(!(e!=null&&e.value)&&!(n!=null&&n.size))return;let i=[];if(e!=null&&e.value){if((e==null?void 0:e.value.kind)!=="ObjectValue")throw new Error(`Invalid filter ${JSON.stringify(e.value,null,2)}`);let r=le(e.value,t);i.push(r)}return n!=null&&n.size&&i.push({$field:"type",$operator:"=",$value:[...n]}),i}function le(e,n={}){var s,d,f,c,v,N;let t={EQ:"=",NEQ:"!=",LT:"<",GT:">",EXISTS:"exists",NOT_EXISTS:"notExists",HAS:"has"};if(e.kind!=="ObjectValue")return;let i=(d=(s=e.fields.find(p=>{var m;return((m=p==null?void 0:p.name)==null?void 0:m.value)==="op"}))==null?void 0:s.value)==null?void 0:d.value,r=E((f=e.fields.find(p=>{var m;return((m=p==null?void 0:p.name)==null?void 0:m.value)==="field"}))==null?void 0:f.value,n),a=w((c=e.fields.find(p=>{var m;return((m=p==null?void 0:p.name)==null?void 0:m.value)==="value"}))==null?void 0:c.value,n);if(!t[i]||!r||a===void 0||a===null)return;let u=(v=e.fields.find(p=>{var m;return((m=p==null?void 0:p.name)==null?void 0:m.value)==="and"}))==null?void 0:v.value,l=(N=e.fields.find(p=>{var m;return((m=p==null?void 0:p.name)==null?void 0:m.value)==="or"}))==null?void 0:N.value,o={$operator:t[i],$field:r,$value:a};return u?o.$and=le(u,n):l&&(o.$or=le(l,n)),o}function xe(e,n={}){var u,l;if(!(e!=null&&e.value))return;let t=e.value;if((t==null?void 0:t.kind)!=="ObjectValue")return;let i=E((u=t.fields.find(o=>{var s;return((s=o==null?void 0:o.name)==null?void 0:s.value)==="field"}))==null?void 0:u.value,n),r=w((l=t.fields.find(o=>{var s;return((s=o==null?void 0:o.name)==null?void 0:s.value)==="order"}))==null?void 0:l.value,n),a=r&&r.toLowerCase()||"desc";return{$field:i,$order:a}}function Le(e,n){var o,s,d;let t=E((o=e.arguments.find(f=>f.name.value==="edgeField"))==null?void 0:o.value,n);if(!t)return;let i=(s=e.arguments.find(f=>f.name.value==="function"))==null?void 0:s.value,r=i==null?void 0:i.value.toLowerCase();if(!r)return;let a=w((d=e.arguments.find(f=>f.name.value==="args"))==null?void 0:d.value),u=e.arguments.find(f=>f.name.value==="filter"),l=A(u,new Set,n);return{$aggregate:{$traverse:t,$function:{$name:r,$args:a},$filter:l}}}function Be(e){var t,i;if(!e.arguments)return{$inherit:!0};let n=(i=(t=e.arguments[0])==null?void 0:t.value)==null?void 0:i.values.map(r=>r.value);return n.length?{$inherit:{$type:n}}:{$inherit:!0}}var Re=require("graphql");var ue=require("graphql");function q(e){var i;let n=(i=e.arguments[0])==null?void 0:i.value;if(!n||e.arguments.length>1)throw new Error("Too many arguments given to _value, should be 1 of type JSON");return{$value:n.kind==="ObjectValue"?JSON.parse((0,ue.print)(n).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,ue.print)(n))}}function Ce(e,n,t,i,r={}){var o;let a={},u=t.selectionSet,l=new Set;for(let s of u.selections)if(s.kind==="InlineFragment"){let d=k(e,s.typeCondition.name.value);l.add(d);let f=D(e,d,s.selectionSet,r);a.$fieldsByType||(a.$fieldsByType={}),a.$fieldsByType[d]=f}else{if(s.kind!==Re.Kind.FIELD)return;let d=(o=s==null?void 0:s.alias)==null?void 0:o.value,f=s.name.value,c=L(s.directives);f==="__typename"?(f="type",d||(d="type")):f==="_all"?c.default?a.$default=c.default:a.$all=!0:f==="_value"&&d?a[d]=q(s):a[d||f]=J(e,c,n,s,i,r,`.${f}`)}if(!!l.size)return a.$inherit={$item:[...l]},a}function M(e,n,{name:t,alias:i},r,a,u,l,o){if(t==="__typename")o.__typename={$field:"type"};else if(t==="_all")h(o,a)||(o.$all=!0);else if(t==="_value"&&i)o[i]=q(r);else if(t==="_aggregate"&&i)o[i]=Le(r,l);else if(t==="_inherit"&&i)o[i]=Be(r);else if(t==="_inheritItem"&&i)o[i]=Ce(e,n,r,u,l);else return!1;return!0}function D(e,n,t,i,r={},a=""){var l,o,s;let u={};for(let d of t.selections){if(d.kind==="InlineFragment"){if(k(e,d.typeCondition.name.value)!==n)continue;for(let y of d.selectionSet.selections){if(y.kind!==B.Kind.FIELD)continue;let O=(l=y==null?void 0:y.alias)==null?void 0:l.value,V=y.name.value,G=`${a}.${V}`,C=J(e,L(y.directives),n,y,i,r,G);C!==void 0&&(u[O||V]=C)}continue}else if(d.kind===B.Kind.FRAGMENT_SPREAD){let m=i[d.name.value];if(!m)continue;let y=k(e,m.typeCondition.name.value);if(y==="node"&&(y=n),y!==n)continue;for(let O of m.selectionSet.selections){if(O.kind!==B.Kind.FIELD)continue;let V=(o=O==null?void 0:O.alias)==null?void 0:o.value,G=O.name.value,C=L(O.directives);if(M(e,n,{name:G,alias:V},O,C,i,r,u))continue;let W=`${a}.${G}`,P=J(e,L(O.directives),n,O,i,r,W);P!==void 0&&(u[V||G]=P)}continue}let f=(s=d==null?void 0:d.alias)==null?void 0:s.value,c=d.name.value,v=L(d.directives);if(M(e,n,{name:c,alias:f},d,v,i,r,u))continue;let N=`${a}.${c}`,p=J(e,v,n,d,i,r,N);p!==void 0&&(u[f||c]=p)}return u}function J(e,n,t,i,r,a={},u=""){var s,d,f,c,v,N,p,m,y,O,V,G,C,W,P,pe,ye,Se;if(i.kind!==B.Kind.FIELD)return;let l=K(e,t,u);if(!l)if(i.name.value==="_traverse")l={type:"references"};else return;if(i.selectionSet){let _=i.name.value,_e=i.arguments,ee=null,$e=i.selectionSet,ve=null,Ne=null;for(let S of _e)if(((s=S==null?void 0:S.name)==null?void 0:s.value)==="traverse"){if(((d=S==null?void 0:S.value)==null?void 0:d.kind)!=="ObjectValue")continue;_={};let j=(f=S==null?void 0:S.value)==null?void 0:f.fields;for(let b of j){if(((c=b==null?void 0:b.value)==null?void 0:c.kind)!=="ObjectValue")continue;let z=(v=b==null?void 0:b.name)==null?void 0:v.value,x=(N=b==null?void 0:b.value)==null?void 0:N.fields[0],$=(p=x==null?void 0:x.name)==null?void 0:p.value;if(!["all","first"].includes($))throw new Error(`Unsupported field for _traverse.traverse ${$}`);if(((m=x==null?void 0:x.value)==null?void 0:m.kind)!=="ListValue")continue;let g=((y=x==null?void 0:x.value)==null?void 0:y.values.map(I=>I==null?void 0:I.value))||[],F=z==="_any"?"$any":z;g.length?_[F]={[`$${$}`]:g}:_[F]=!1}_.$any||(_.$any=!1)}else if(((O=S==null?void 0:S.name)==null?void 0:O.value)==="filter")ve=S;else if(((V=S==null?void 0:S.name)==null?void 0:V.value)==="sortBy")Ne=S;else if(((G=S==null?void 0:S.name)==null?void 0:G.value)==="recursive"&&((C=S==null?void 0:S.value)==null?void 0:C.kind)==="BooleanValue")ee=(W=S==null?void 0:S.value)==null?void 0:W.value;else throw new Error(`Unsupported arg for _traverse ${(P=S==null?void 0:S.name)==null?void 0:P.value}`);let T={};switch(l.type){case"references":let S=!1,j=new Set;for(let $ of $e.selections)if($.kind==="InlineFragment"){let g=k(e,$.typeCondition.name.value);j.add(g);let F=D(e,g,$.selectionSet,a);T.$fieldsByType||(T.$fieldsByType={}),T.$fieldsByType[g]=F}else if($.kind===B.Kind.FRAGMENT_SPREAD){let g=r[$.name.value];if(!g)continue;let F=k(e,g.typeCondition.name.value);j.add(F);let I=D(e,F,g.selectionSet,a);T.$fieldsByType||(T.$fieldsByType={}),T.$fieldsByType[F]=I}else{if($.kind!==B.Kind.FIELD)continue;S=!0;let g=(pe=$==null?void 0:$.alias)==null?void 0:pe.value,F=$.name.value,I=L($.directives);M(e,t,{name:F,alias:g},$,r,I,a,T)||(T[g||F]=J(e,I,t,$,r,a,`.${F}`))}T.$list={$find:{$traverse:_}};let b=A(ve,S?new Set:j,a),z=xe(Ne,a);return b&&(T.$list.$find.$filter=b),z&&(T.$list.$sort=z),ee!==null&&(T.$list.$find.$recursive=ee),T;case"reference":for(let $ of $e.selections)if($.kind==="InlineFragment"){let g=k(e,$.typeCondition.name.value),F=D(e,g,$.selectionSet,a);T.$fieldsByType||(T.$fieldsByType={}),T.$fieldsByType[g]=F}else if($.kind===B.Kind.FRAGMENT_SPREAD){let g=r[$.name.value];if(!g)continue;let F=k(e,g.typeCondition.name.value);j.add(F);let I=D(e,F,g.selectionSet,a);T.$fieldsByType||(T.$fieldsByType={}),T.$fieldsByType[F]=I}else{if($.kind!==B.Kind.FIELD)return;let g=(ye=$==null?void 0:$.alias)==null?void 0:ye.value,F=$.name.value,I=L($.directives);M(e,t,{name:F,alias:g},$,I,r,a,T)||(T[g||F]=J(e,I,t,$,r,a,`.${F}`))}return T;case"object":return D(e,t,i.selectionSet,a,u);default:return((Se=i==null?void 0:i.alias)==null?void 0:Se.value)?{$field:u.slice(1)}:!0}}let o={$field:u.slice(1)};return h(o,n),o}function de(e,n,t,i={}){var v,N,p;let r,a,u;if(n.name.value==="callFn"){let m=n.arguments.findIndex(G=>G.name.value==="name"),y=E(n.arguments[m].value,i),O=(N=(v=n==null?void 0:n.arguments)==null?void 0:v[1-m])==null?void 0:N.value,V=O?O.kind==="ObjectValue"?JSON.parse((0,U.print)(O).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,U.print)(O)):!0;return{fnCall:{name:y,payload:V}}}else if(n.name.value.startsWith("create"))r=n.name.value.slice(6),a=n.arguments[0];else if(n.name.value.startsWith("set")){r=n.name.value.slice(3);let m=n.arguments.findIndex(y=>y.name.value==="input");a=n.arguments[m],r==="Root"?u="root":u=E(n.arguments[1-m].value,i)}else if(n.name.value==="deleteNode"){if(u=E(n.arguments[0].value,i),!u)throw new Error("Can't delete nodes without id argument");return{delete:{$id:u,$db:e.db||"default"}}}else{let m=n.name.value,y=(p=n.arguments[0])==null?void 0:p.value,O=y?y.kind==="ObjectValue"?JSON.parse((0,U.print)(y).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,U.print)(y)):!0;return{fnCall:{name:m,payload:O}}}let l=k(e,r);if(a.name.value!=="input")throw new Error(`Argument 'input' is required by mutation ${n.name.value}`);let o=a.value,s=X(e,l,o,i),d=Object.assign({},s,{type:l,$db:e.db||"default"});u&&(d.$id=u);let f=D(e,l,n.selectionSet,t,i);f.$db=e.db||"default";let c=Object.keys(f);return c.length===1&&(c[0]==="type"||c[0]==="id")?{set:d}:c.length===2&&c.every(m=>["type","id"].includes(m))?{set:d}:{set:d,get:f}}var Z=require("graphql");function fe(e,n,t,i={}){var s,d,f,c,v,N;let r=(s=n==null?void 0:n.name)==null?void 0:s.value;if(r==="observeFn"){let p=n.arguments.findIndex(V=>V.name.value==="name"),m=E(n.arguments[p].value,i),y=(f=(d=n==null?void 0:n.arguments)==null?void 0:d[1-p])==null?void 0:f.value,O=!y||!y.kind||y.kind==="NullValue"?void 0:y.kind==="ObjectValue"?JSON.parse((0,Z.print)(y).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,Z.print)(y));return{fnObserve:{name:m,payload:O}}}let a=r==="node"?"root":r;if(!(a==="root"||!!e.schemas[e.db||"default"].types[a])){let p=r,m=(v=(c=n==null?void 0:n.arguments)==null?void 0:c[0])==null?void 0:v.value,y=!m||!m.kind||m.kind==="NullValue"?void 0:m.kind==="ObjectValue"?JSON.parse((0,Z.print)(m).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,Z.print)(m));return{fnObserve:{name:p,payload:y}}}let l=n.name.value==="root"?"root":E((N=n==null?void 0:n.arguments[0])==null?void 0:N.value,i),o=D(e,a,n.selectionSet,t,i);return o.$alias=l,o.$db=e.db||"default",{get:o}}function ce(e){if(e.kind===R.Kind.LIST_TYPE){let n=ce(e.type);return n.list=!0,n}else if((e==null?void 0:e.kind)===R.Kind.NON_NULL_TYPE){let n=ce(e.type);return n.required=!0,n}return{type:e.name.value,required:!1,list:!1}}function qe(e,n){var o;let t,i={};for(let s of n.definitions)s.kind===R.Kind.OPERATION_DEFINITION?t=s:s.kind===R.Kind.FRAGMENT_DEFINITION&&(i[(o=s==null?void 0:s.name)==null?void 0:o.value]=s);if(!t.selectionSet)return;let r=((t==null?void 0:t.variableDefinitions)||[]).reduce((s,d)=>{var v,N;let f=(N=(v=d==null?void 0:d.variable)==null?void 0:v.name)==null?void 0:N.value,c=d==null?void 0:d.type;return s[f]=ce(c),s},{}),a,u;t.operation==="query"?(a="GET",u=fe):(a="SET",u=de);let l={};return t.selectionSet.selections.map(async s=>{var v;if(s.kind!==R.Kind.FIELD)return;let d=(v=s==null?void 0:s.alias)==null?void 0:v.value,f=s.name.value,c=u(e,s,i,r);l[d||f]=c}),{ops:l,opType:a,variables:r,db:e.db||"default"}}function me(e,n,t){if(typeof n!="object")return n;if(Array.isArray(n))return n.map(r=>me(e,r,t));if(n!=null&&n.$var){let r=n.$var;if(e.variables[r].required&&!t[r])throw new Error(`Variable ${r} required, but not provided`);return t[r]}let i={};for(let r in n)i[r]=me(e,n[r],t);return i}0&&(module.exports={createGet,createMutation,createOperations,genSchema,handleGraphqlVariables,parseGraphql});
import { DocumentNode, parse } from 'graphql';
import { Schema, GetOptions, SetOptions } from '@based/types';
import genSchema from './schema';
export { genSchema };
import { createMutation } from './mutation';
import { createGet } from './query';
export { genSchema };
export declare type BasedOp = {

@@ -8,0 +8,0 @@ get?: GetOptions;

@@ -1,106 +0,142 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleGraphqlVariables = exports.createOperations = exports.parseGraphql = exports.createMutation = exports.createGet = exports.genSchema = void 0;
const graphql_1 = require("graphql");
Object.defineProperty(exports, "parseGraphql", { enumerable: true, get: function () { return graphql_1.parse; } });
const schema_1 = __importDefault(require("./schema"));
exports.genSchema = schema_1.default;
const mutation_1 = require("./mutation");
Object.defineProperty(exports, "createMutation", { enumerable: true, get: function () { return mutation_1.createMutation; } });
const query_1 = require("./query");
Object.defineProperty(exports, "createGet", { enumerable: true, get: function () { return query_1.createGet; } });
function convertArgType(vType) {
if (vType.kind === graphql_1.Kind.LIST_TYPE) {
const nested = convertArgType(vType.type);
nested.list = true;
return nested;
}
else if (vType?.kind === graphql_1.Kind.NON_NULL_TYPE) {
const nested = convertArgType(vType.type);
nested.required = true;
return nested;
}
// } else if (vType?.kind === Kind.NAMED_TYPE) {
return {
type: vType.name.value,
required: false,
list: false,
};
var Y=Object.defineProperty,we=Object.defineProperties,Je=Object.getOwnPropertyDescriptor,je=Object.getOwnPropertyDescriptors,Qe=Object.getOwnPropertyNames,Oe=Object.getOwnPropertySymbols;var Te=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var ge=(e,n,t)=>n in e?Y(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Fe=(e,n)=>{for(var t in n||(n={}))Te.call(n,t)&&ge(e,t,n[t]);if(Oe)for(var t of Oe(n))Pe.call(n,t)&&ge(e,t,n[t]);return e},Ee=(e,n)=>we(e,je(n));var ze=(e,n)=>{for(var t in n)Y(e,t,{get:n[t],enumerable:!0})},Me=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Qe(n))!Te.call(e,r)&&r!==t&&Y(e,r,{get:()=>n[r],enumerable:!(i=Je(n,r))||i.enumerable});return e};var Ue=e=>Me(Y({},"__esModule",{value:!0}),e);var en={};ze(en,{createGet:()=>fe,createMutation:()=>de,createOperations:()=>qe,genSchema:()=>ae,handleGraphqlVariables:()=>me,parseGraphql:()=>R.parse});module.exports=Ue(en);var R=require("graphql");function ne(){return` deleteNode(id: ID): Boolean
`}function te(e,n={}){let t=`type Mutation {
`;t+=" setRoot(input: RootInput): Root",t+=`
`,t+=" callFn(name: String!, payload: JSON): JSON",t+=`
`;for(let i in e.types){i=i[0].toUpperCase()+i.slice(1);let r=`${i}Input`;t+=` set${i}(id: ID, input: ${r}): ${i}`,t+=`
`,t+=` create${i}(input: ${r}): ${i}`,t+=`
`,t+=`
`}for(let i in n)n[i].observable||(t+=` ${i}(payload: JSON): JSON`);return t+=ne(),t+=`}
`,t}function ie(e,n={}){let t=`type Query {
`;t+=` node(id: ID): Node
`,t+=` root: Root
`,t+=" observeFn(name: String!, payload: JSON): JSON";for(let i in e.types){let r=i[0].toUpperCase()+i.slice(1);t+=` ${i}(id: ID): ${r}
`}for(let i in n)n[i].observable&&!e.types[i]&&(t+=` ${i}(payload: JSON): JSON`);return t+=`
`,t+=`}
`,t}var Ve=`_all: BasedOperator
_value(v: JSON!): JSON!
_aggregate(edgeField: String!, function: AggregateFunction!, args: [JSON!], filter: Filter): Float
_inherit(type: [NodeType]): JSON
_inheritItem: Node!
`,be=`id: ID!
type: String!
aliases: [String!]
parents(filter: Filter, sortBy: SortBy, recursive: Boolean): [Node!]
children(filter: Filter, sortBy: SortBy, recursive: Boolean): [Node!]
ancestors(filter: Filter, sortBy: SortBy): [Node!]
descendants(filter: Filter, sortBy: SortBy): [Node!]
${Ve}`,Ze=`aliases: StringSetInput
parents: ReferencesInput
children: ReferencesInput`,H={id:"ID!",type:"String!",int:"Int",timestamp:"Int",float:"Float",number:"Float",string:"String",email:"String",phone:"String",digest:"String",url:"String",boolean:"Boolean",reference:"Node",references:"[Node!]",text:"Language",json:"JSON"},Ie=Ee(Fe({},H),{text:"LanguageInput",reference:"ID",references:"ReferencesInput"}),We=new Set(["id","type","aliases","parents","children","ancestors","descendants"]);function Ye(e){e!=null&&e.length||(e=["en"]);let n=e.map(i=>` ${i}: String`).join(`
`);return`
type Language {
${n}
}
function createOperations(ctx, document) {
let graphqlAst;
let fragments = {};
for (const d of document.definitions) {
if (d.kind === graphql_1.Kind.OPERATION_DEFINITION) {
graphqlAst = d;
}
else if (d.kind === graphql_1.Kind.FRAGMENT_DEFINITION) {
fragments[d?.name?.value] = d;
}
}
if (!graphqlAst.selectionSet) {
return;
}
const fullVars = (graphqlAst?.variableDefinitions || []).reduce((acc, v) => {
const vName = v?.variable?.name?.value;
const vType = v?.type;
acc[vName] = convertArgType(vType);
return acc;
}, {});
let opType;
let opFn;
if (graphqlAst.operation === 'query') {
opType = 'GET';
opFn = query_1.createGet;
}
else {
opType = 'SET';
opFn = mutation_1.createMutation;
}
const responseBody = {};
graphqlAst.selectionSet.selections.map(async (def) => {
if (def.kind !== graphql_1.Kind.FIELD) {
// TODO: ?
return undefined;
}
const alias = def?.alias?.value;
const name = def.name.value;
const op = opFn(ctx, def, fragments, fullVars);
responseBody[alias || name] = op;
});
return {
ops: responseBody,
opType,
variables: fullVars,
db: ctx.db || 'default',
};
input LanguageInput {
${n}
}
exports.createOperations = createOperations;
function handleGraphqlVariables(op, cur, variables) {
if (typeof cur !== 'object') {
return cur;
}
if (Array.isArray(cur)) {
return cur.map((n) => {
return handleGraphqlVariables(op, n, variables);
});
}
if (cur?.$var) {
const varName = cur.$var;
const varEntry = op.variables[varName];
if (varEntry.required && !variables[varName]) {
throw new Error(`Variable ${varName} required, but not provided`);
}
return variables[varName];
}
const newObj = {};
for (const k in cur) {
newObj[k] = handleGraphqlVariables(op, cur[k], variables);
}
return newObj;
`}function re(e){return["object","record","json"].includes(e.items.type)?"JSON":H[e.items.type]}function oe(e,n,t,i=!0){n=n[0].toUpperCase()+n.slice(1);let r=new Set(i?["children","parents"]:[]),a="",u="",l="";for(let f in t){if(We.has(f))continue;let c=t[f];if(u+=`
`,l+=`
`,c.type==="object"){let v=f[0].toUpperCase()+f.slice(1),N=`${n}${v}`;a+=oe(e,N,c.properties,!1),u+=`${f}: ${N}`,l+=`${f}: ${N}Input`,a+=Q(n,c,N)}else if(c.type==="record")u+=`${f}: JSON`,l+=`${f}: JSON`,a+=Q(n,c,"JSON");else if(c.type==="array")u+=`${f}: [JSON]`,l+=`${f}: [JSON]`,a+=Q(n,c,"[JSON]");else if(c.type==="set")u+=`${f}: [${re(c)}!]`,l+=`${f}: [${re(c)}!]`,a+=Q(n,c,`[${re(c)}!]`);else if(c.type==="references"){r.add(f);let v=H.references,N=Ie[c.type];u+=`${f}(filter: Filter, sortBy: SortBy, recursive: Boolean): ${v}`,l+=`${f}: ${N}`,a+=Q(n,c,v)}else{let v=H[c.type],N=Ie[c.type];u+=`${f}: ${v}`,l+=`${f}: ${N}`,a+=Q(n,c,v)}c.timeseries}let o="";if(r.size){o+=`enum ${n}TraverseByTypeFields {`;for(let f of r)o+=` ${f}
`;o+=`}
`,o+=`input ${n}TraverseByTypeExpression {
all: [${n}TraverseByTypeFields!]
first: [${n}TraverseByTypeFields!]
}
exports.handleGraphqlVariables = handleGraphqlVariables;
//# sourceMappingURL=index.js.map
`}let s=`
${a}
type ${n}${i?" implements Node":""} {
${i?be:Ve}
${r.size?"_traverse(traverse: TraverseByType, filter: Filter, sortBy: SortBy, recursive: Boolean = false): [Node!]":""}
${u.slice(3)}
}
`,d=`
input ${n}Input {
${i?Ze:""}
${l.slice(3)}
}
`;return o+s+d}function Q(e,n,t){if(!n.timeseries)return"";console.log("YES HAS TIMESERIES",e,n,t)}function He(){return`
interface Node {
${be}
}
`}function Ke(e){let n=`
enum AggregateFunction {
SUM
AVG
COUNT
}
enum FilterOperation {
EQ
NEQ
LT
GT
EXISTS
NOT_EXISTS
HAS
}
enum SortByOrder {
DESC
ASC
}
input SortBy {
field: String!
order: SortByOrder
}
input Filter {
op: FilterOperation!
field: String!
value: JSON!
and: Filter
or: Filter
}
enum ReferencesInputOperation {
ADD
REMOVE
SET
}
input ReferencesInput {
op: ReferencesInputOperation,
ids: [ID!]
}
enum SetInputOperation {
ADD
REMOVE
SET
}
input AnyTraverseByTypeExpression {
all: [String!]
first: [String!]
}
`,t=["String","Int","JSON","Float"];for(let i of t)n+=`
input ${i}SetInput {
op: SetInputOperation,
values: [${i}!]
}
`;n+=`input TraverseByType {
`;for(let i in e.types){let r=i[0].toUpperCase()+i.slice(1);n+=` ${i}: ${r}TraverseByTypeExpression
`}n+=` _any: AnyTraverseByTypeExpression
`,n+=`}
`,n+=`enum NodeType {
`,n+=" root";for(let i in e.types)n+=` ${i}`;return n+=`}
`,n}function ae(e,n={}){let t="";t+=`scalar JSON
`,t+=`scalar BasedOperator
`,t+=`directive @default(value: JSON!) on FIELD
`,t+=`directive @inherit(type: [NodeType]) on FIELD
`,t+=Ye(e==null?void 0:e.languages),t+=He(),t+=Ke(e),t+=oe(e,"root",e.rootType.fields);for(let i in e.types){let r=e.types[i];t+=oe(e,i,r.fields)}return t+=`
`,t+=te(e,n),t+=`
`,t+=ie(e,n),t}var U=require("graphql");function Xe(e,n){return n.startsWith("ro")?"root":e.prefixToTypeMapping[n.substr(0,2)]}function he(e,n,t){if(!t||t===""||typeof t!="string")return null;let i=Xe(e,n),r=t.split("."),a=i==="root"?e.rootType:e.types[i];if(!a||!a.fields)return null;let u=r[0];if(u.endsWith("]")){for(let o=u.length-1;o>=0;o--)if(u[o]==="["){u=u.slice(0,o);break}}let l=a.fields[u];if(!l)return null;for(let o=1;o<r.length;o++){let s=r[o];if(s.endsWith("]")){for(let d=s.length-1;d>=0;d--)if(s[d]==="["){s=s.slice(0,d);break}}if(!l)return null;if(l.type==="text"&&o===r.length-1)return{type:"string"};if(l.values)l=l.values;else if(l.type==="array")l=l.items,l=l.properties[s];else{if(!l.properties)return null;l=l.properties[s]}}return l}function ke(e){return e.schemas[e.db||"default"]}function w(e,n={}){if(!!e){if(e.kind==="StringValue")return e.value;if(e.kind==="EnumValue")return e.value;if(e.kind==="FloatValue")return Number(e.value);if(e.kind==="IntValue")return Number(e.value);if(e.kind==="ListValue")return e.values.map(t=>w(t,n));if(e.kind==="Variable")return{$var:e.name.value};throw new Error(`String or variable name requried for references, ${JSON.stringify(e,null,2)} given`)}}function E(e,n={}){if(!!e){if(e.kind==="StringValue")return e.value;if(e.kind==="Variable")return{$var:e.name.value};throw new Error(`String or variable name requried for references, ${JSON.stringify(e,null,2)} given`)}}function De(e,n={}){if(e.kind==="IntValue")return Number(e.value);if(e.kind==="FloatValue")return Number(e.value);if(e.kind==="Variable")return{$var:e.name.value};throw new Error(`String or variable name requried for references, ${JSON.stringify(e,null,2)} given`)}function k(e,n){return ke(e).types[n]?n:n[0].toLowerCase()+n.slice(1)}function K(e,n,t){var a;let i=ke(e),r=n==="root"?"ro":(a=i==null?void 0:i.types[n])==null?void 0:a.prefix;if(!!r)return he(i,r,t.slice(1))}var Ge=require("graphql");function X(e,n,t,i={},r=""){if(t.kind!=="ObjectValue")return;let a={};for(let u of t.fields){let l=u.name.value,o=u.value;if((o==null?void 0:o.kind)==="NullValue"){a[l]={$delete:!0};continue}let s=`${r}.${l}`,d=Ae(e,n,o,i,s);d!==void 0&&(a[l]=d)}return a}function Ae(e,n,t,i={},r=""){var u;let a=K(e,n,r);if(!!a){if(t.kind==="Variable")return{$var:(u=t==null?void 0:t.name)==null?void 0:u.value};switch(a.type){case"set":case"references":let l={ADD:"$add",REMOVE:"$delete",SET:"$value"};if(t.kind!=="ObjectValue")throw new Error(`Invalid payload ${t} for ${r}`);let o,s;if(t.fields[0].name.value==="op"?(o=t.fields[0].value,s=t.fields[1].value):(o=t.fields[1].value,s=t.fields[0].value),o.kind!=="EnumValue")throw new Error(`Invalid references operation ${o} in ${t} for ${r}`);if(s.kind!=="ListValue")throw new Error(`Invalid references ids argument ${s} in ${t} for ${r}`);if(o=o.value,!l[o])throw new Error(`Invalid references operation ${o}, should be one of ${JSON.stringify(Object.keys(l))} for ${r}`);return s=s.values.map(d=>E(d,i)),{[l[o]]:s};case"object":if(t.kind!=="ObjectValue")throw new Error(`Trying to set a non-object value ${t} to object field ${r}`);return X(e,n,t,i,r);case"url":case"phone":case"digest":case"string":case"reference":return E(t,i);case"float":case"int":case"number":return De(t,i);case"json":return t.kind==="ObjectValue"?JSON.parse((0,Ge.print)(t).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):t==null?void 0:t.value;default:console.log("CATCHALL",a,t);return}}}var B=require("graphql");var se=require("graphql");function L(e){return!e||!e.length?{}:e.reduce((n,t)=>{var u,l;let i=(u=t==null?void 0:t.name)==null?void 0:u.value,r=(l=t==null?void 0:t.arguments[0])==null?void 0:l.value;if((r==null?void 0:r.kind)==="ListValue")for(let o of r==null?void 0:r.values)(o==null?void 0:o.kind)==="EnumValue"&&(o.kind="StringValue");let a=r?r.kind==="ObjectValue"?JSON.parse((0,se.print)(r).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,se.print)(r)):!0;return Object.assign(n,{[i]:a})},{})}function h(e,n){return n.default?(e.$default=n.default,!0):n.inherit?(e.$inherit=n.inherit===!0?!0:{$type:n.inherit},!0):!1}function A(e,n,t={}){if(!(e!=null&&e.value)&&!(n!=null&&n.size))return;let i=[];if(e!=null&&e.value){if((e==null?void 0:e.value.kind)!=="ObjectValue")throw new Error(`Invalid filter ${JSON.stringify(e.value,null,2)}`);let r=le(e.value,t);i.push(r)}return n!=null&&n.size&&i.push({$field:"type",$operator:"=",$value:[...n]}),i}function le(e,n={}){var s,d,f,c,v,N;let t={EQ:"=",NEQ:"!=",LT:"<",GT:">",EXISTS:"exists",NOT_EXISTS:"notExists",HAS:"has"};if(e.kind!=="ObjectValue")return;let i=(d=(s=e.fields.find(p=>{var m;return((m=p==null?void 0:p.name)==null?void 0:m.value)==="op"}))==null?void 0:s.value)==null?void 0:d.value,r=E((f=e.fields.find(p=>{var m;return((m=p==null?void 0:p.name)==null?void 0:m.value)==="field"}))==null?void 0:f.value,n),a=w((c=e.fields.find(p=>{var m;return((m=p==null?void 0:p.name)==null?void 0:m.value)==="value"}))==null?void 0:c.value,n);if(!t[i]||!r||a===void 0||a===null)return;let u=(v=e.fields.find(p=>{var m;return((m=p==null?void 0:p.name)==null?void 0:m.value)==="and"}))==null?void 0:v.value,l=(N=e.fields.find(p=>{var m;return((m=p==null?void 0:p.name)==null?void 0:m.value)==="or"}))==null?void 0:N.value,o={$operator:t[i],$field:r,$value:a};return u?o.$and=le(u,n):l&&(o.$or=le(l,n)),o}function xe(e,n={}){var u,l;if(!(e!=null&&e.value))return;let t=e.value;if((t==null?void 0:t.kind)!=="ObjectValue")return;let i=E((u=t.fields.find(o=>{var s;return((s=o==null?void 0:o.name)==null?void 0:s.value)==="field"}))==null?void 0:u.value,n),r=w((l=t.fields.find(o=>{var s;return((s=o==null?void 0:o.name)==null?void 0:s.value)==="order"}))==null?void 0:l.value,n),a=r&&r.toLowerCase()||"desc";return{$field:i,$order:a}}function Le(e,n){var o,s,d;let t=E((o=e.arguments.find(f=>f.name.value==="edgeField"))==null?void 0:o.value,n);if(!t)return;let i=(s=e.arguments.find(f=>f.name.value==="function"))==null?void 0:s.value,r=i==null?void 0:i.value.toLowerCase();if(!r)return;let a=w((d=e.arguments.find(f=>f.name.value==="args"))==null?void 0:d.value),u=e.arguments.find(f=>f.name.value==="filter"),l=A(u,new Set,n);return{$aggregate:{$traverse:t,$function:{$name:r,$args:a},$filter:l}}}function Be(e){var t,i;if(!e.arguments)return{$inherit:!0};let n=(i=(t=e.arguments[0])==null?void 0:t.value)==null?void 0:i.values.map(r=>r.value);return n.length?{$inherit:{$type:n}}:{$inherit:!0}}var Re=require("graphql");var ue=require("graphql");function q(e){var i;let n=(i=e.arguments[0])==null?void 0:i.value;if(!n||e.arguments.length>1)throw new Error("Too many arguments given to _value, should be 1 of type JSON");return{$value:n.kind==="ObjectValue"?JSON.parse((0,ue.print)(n).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,ue.print)(n))}}function Ce(e,n,t,i,r={}){var o;let a={},u=t.selectionSet,l=new Set;for(let s of u.selections)if(s.kind==="InlineFragment"){let d=k(e,s.typeCondition.name.value);l.add(d);let f=D(e,d,s.selectionSet,r);a.$fieldsByType||(a.$fieldsByType={}),a.$fieldsByType[d]=f}else{if(s.kind!==Re.Kind.FIELD)return;let d=(o=s==null?void 0:s.alias)==null?void 0:o.value,f=s.name.value,c=L(s.directives);f==="__typename"?(f="type",d||(d="type")):f==="_all"?c.default?a.$default=c.default:a.$all=!0:f==="_value"&&d?a[d]=q(s):a[d||f]=J(e,c,n,s,i,r,`.${f}`)}if(!!l.size)return a.$inherit={$item:[...l]},a}function M(e,n,{name:t,alias:i},r,a,u,l,o){if(t==="__typename")o.__typename={$field:"type"};else if(t==="_all")h(o,a)||(o.$all=!0);else if(t==="_value"&&i)o[i]=q(r);else if(t==="_aggregate"&&i)o[i]=Le(r,l);else if(t==="_inherit"&&i)o[i]=Be(r);else if(t==="_inheritItem"&&i)o[i]=Ce(e,n,r,u,l);else return!1;return!0}function D(e,n,t,i,r={},a=""){var l,o,s;let u={};for(let d of t.selections){if(d.kind==="InlineFragment"){if(k(e,d.typeCondition.name.value)!==n)continue;for(let y of d.selectionSet.selections){if(y.kind!==B.Kind.FIELD)continue;let O=(l=y==null?void 0:y.alias)==null?void 0:l.value,V=y.name.value,G=`${a}.${V}`,C=J(e,L(y.directives),n,y,i,r,G);C!==void 0&&(u[O||V]=C)}continue}else if(d.kind===B.Kind.FRAGMENT_SPREAD){let m=i[d.name.value];if(!m)continue;let y=k(e,m.typeCondition.name.value);if(y==="node"&&(y=n),y!==n)continue;for(let O of m.selectionSet.selections){if(O.kind!==B.Kind.FIELD)continue;let V=(o=O==null?void 0:O.alias)==null?void 0:o.value,G=O.name.value,C=L(O.directives);if(M(e,n,{name:G,alias:V},O,C,i,r,u))continue;let W=`${a}.${G}`,P=J(e,L(O.directives),n,O,i,r,W);P!==void 0&&(u[V||G]=P)}continue}let f=(s=d==null?void 0:d.alias)==null?void 0:s.value,c=d.name.value,v=L(d.directives);if(M(e,n,{name:c,alias:f},d,v,i,r,u))continue;let N=`${a}.${c}`,p=J(e,v,n,d,i,r,N);p!==void 0&&(u[f||c]=p)}return u}function J(e,n,t,i,r,a={},u=""){var s,d,f,c,v,N,p,m,y,O,V,G,C,W,P,pe,ye,Se;if(i.kind!==B.Kind.FIELD)return;let l=K(e,t,u);if(!l)if(i.name.value==="_traverse")l={type:"references"};else return;if(i.selectionSet){let _=i.name.value,_e=i.arguments,ee=null,$e=i.selectionSet,ve=null,Ne=null;for(let S of _e)if(((s=S==null?void 0:S.name)==null?void 0:s.value)==="traverse"){if(((d=S==null?void 0:S.value)==null?void 0:d.kind)!=="ObjectValue")continue;_={};let j=(f=S==null?void 0:S.value)==null?void 0:f.fields;for(let b of j){if(((c=b==null?void 0:b.value)==null?void 0:c.kind)!=="ObjectValue")continue;let z=(v=b==null?void 0:b.name)==null?void 0:v.value,x=(N=b==null?void 0:b.value)==null?void 0:N.fields[0],$=(p=x==null?void 0:x.name)==null?void 0:p.value;if(!["all","first"].includes($))throw new Error(`Unsupported field for _traverse.traverse ${$}`);if(((m=x==null?void 0:x.value)==null?void 0:m.kind)!=="ListValue")continue;let g=((y=x==null?void 0:x.value)==null?void 0:y.values.map(I=>I==null?void 0:I.value))||[],F=z==="_any"?"$any":z;g.length?_[F]={[`$${$}`]:g}:_[F]=!1}_.$any||(_.$any=!1)}else if(((O=S==null?void 0:S.name)==null?void 0:O.value)==="filter")ve=S;else if(((V=S==null?void 0:S.name)==null?void 0:V.value)==="sortBy")Ne=S;else if(((G=S==null?void 0:S.name)==null?void 0:G.value)==="recursive"&&((C=S==null?void 0:S.value)==null?void 0:C.kind)==="BooleanValue")ee=(W=S==null?void 0:S.value)==null?void 0:W.value;else throw new Error(`Unsupported arg for _traverse ${(P=S==null?void 0:S.name)==null?void 0:P.value}`);let T={};switch(l.type){case"references":let S=!1,j=new Set;for(let $ of $e.selections)if($.kind==="InlineFragment"){let g=k(e,$.typeCondition.name.value);j.add(g);let F=D(e,g,$.selectionSet,a);T.$fieldsByType||(T.$fieldsByType={}),T.$fieldsByType[g]=F}else if($.kind===B.Kind.FRAGMENT_SPREAD){let g=r[$.name.value];if(!g)continue;let F=k(e,g.typeCondition.name.value);j.add(F);let I=D(e,F,g.selectionSet,a);T.$fieldsByType||(T.$fieldsByType={}),T.$fieldsByType[F]=I}else{if($.kind!==B.Kind.FIELD)continue;S=!0;let g=(pe=$==null?void 0:$.alias)==null?void 0:pe.value,F=$.name.value,I=L($.directives);M(e,t,{name:F,alias:g},$,r,I,a,T)||(T[g||F]=J(e,I,t,$,r,a,`.${F}`))}T.$list={$find:{$traverse:_}};let b=A(ve,S?new Set:j,a),z=xe(Ne,a);return b&&(T.$list.$find.$filter=b),z&&(T.$list.$sort=z),ee!==null&&(T.$list.$find.$recursive=ee),T;case"reference":for(let $ of $e.selections)if($.kind==="InlineFragment"){let g=k(e,$.typeCondition.name.value),F=D(e,g,$.selectionSet,a);T.$fieldsByType||(T.$fieldsByType={}),T.$fieldsByType[g]=F}else if($.kind===B.Kind.FRAGMENT_SPREAD){let g=r[$.name.value];if(!g)continue;let F=k(e,g.typeCondition.name.value);j.add(F);let I=D(e,F,g.selectionSet,a);T.$fieldsByType||(T.$fieldsByType={}),T.$fieldsByType[F]=I}else{if($.kind!==B.Kind.FIELD)return;let g=(ye=$==null?void 0:$.alias)==null?void 0:ye.value,F=$.name.value,I=L($.directives);M(e,t,{name:F,alias:g},$,I,r,a,T)||(T[g||F]=J(e,I,t,$,r,a,`.${F}`))}return T;case"object":return D(e,t,i.selectionSet,a,u);default:return((Se=i==null?void 0:i.alias)==null?void 0:Se.value)?{$field:u.slice(1)}:!0}}let o={$field:u.slice(1)};return h(o,n),o}function de(e,n,t,i={}){var v,N,p;let r,a,u;if(n.name.value==="callFn"){let m=n.arguments.findIndex(G=>G.name.value==="name"),y=E(n.arguments[m].value,i),O=(N=(v=n==null?void 0:n.arguments)==null?void 0:v[1-m])==null?void 0:N.value,V=O?O.kind==="ObjectValue"?JSON.parse((0,U.print)(O).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,U.print)(O)):!0;return{fnCall:{name:y,payload:V}}}else if(n.name.value.startsWith("create"))r=n.name.value.slice(6),a=n.arguments[0];else if(n.name.value.startsWith("set")){r=n.name.value.slice(3);let m=n.arguments.findIndex(y=>y.name.value==="input");a=n.arguments[m],r==="Root"?u="root":u=E(n.arguments[1-m].value,i)}else if(n.name.value==="deleteNode"){if(u=E(n.arguments[0].value,i),!u)throw new Error("Can't delete nodes without id argument");return{delete:{$id:u,$db:e.db||"default"}}}else{let m=n.name.value,y=(p=n.arguments[0])==null?void 0:p.value,O=y?y.kind==="ObjectValue"?JSON.parse((0,U.print)(y).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,U.print)(y)):!0;return{fnCall:{name:m,payload:O}}}let l=k(e,r);if(a.name.value!=="input")throw new Error(`Argument 'input' is required by mutation ${n.name.value}`);let o=a.value,s=X(e,l,o,i),d=Object.assign({},s,{type:l,$db:e.db||"default"});u&&(d.$id=u);let f=D(e,l,n.selectionSet,t,i);f.$db=e.db||"default";let c=Object.keys(f);return c.length===1&&(c[0]==="type"||c[0]==="id")?{set:d}:c.length===2&&c.every(m=>["type","id"].includes(m))?{set:d}:{set:d,get:f}}var Z=require("graphql");function fe(e,n,t,i={}){var s,d,f,c,v,N;let r=(s=n==null?void 0:n.name)==null?void 0:s.value;if(r==="observeFn"){let p=n.arguments.findIndex(V=>V.name.value==="name"),m=E(n.arguments[p].value,i),y=(f=(d=n==null?void 0:n.arguments)==null?void 0:d[1-p])==null?void 0:f.value,O=!y||!y.kind||y.kind==="NullValue"?void 0:y.kind==="ObjectValue"?JSON.parse((0,Z.print)(y).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,Z.print)(y));return{fnObserve:{name:m,payload:O}}}let a=r==="node"?"root":r;if(!(a==="root"||!!e.schemas[e.db||"default"].types[a])){let p=r,m=(v=(c=n==null?void 0:n.arguments)==null?void 0:c[0])==null?void 0:v.value,y=!m||!m.kind||m.kind==="NullValue"?void 0:m.kind==="ObjectValue"?JSON.parse((0,Z.print)(m).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ')):JSON.parse((0,Z.print)(m));return{fnObserve:{name:p,payload:y}}}let l=n.name.value==="root"?"root":E((N=n==null?void 0:n.arguments[0])==null?void 0:N.value,i),o=D(e,a,n.selectionSet,t,i);return o.$alias=l,o.$db=e.db||"default",{get:o}}function ce(e){if(e.kind===R.Kind.LIST_TYPE){let n=ce(e.type);return n.list=!0,n}else if((e==null?void 0:e.kind)===R.Kind.NON_NULL_TYPE){let n=ce(e.type);return n.required=!0,n}return{type:e.name.value,required:!1,list:!1}}function qe(e,n){var o;let t,i={};for(let s of n.definitions)s.kind===R.Kind.OPERATION_DEFINITION?t=s:s.kind===R.Kind.FRAGMENT_DEFINITION&&(i[(o=s==null?void 0:s.name)==null?void 0:o.value]=s);if(!t.selectionSet)return;let r=((t==null?void 0:t.variableDefinitions)||[]).reduce((s,d)=>{var v,N;let f=(N=(v=d==null?void 0:d.variable)==null?void 0:v.name)==null?void 0:N.value,c=d==null?void 0:d.type;return s[f]=ce(c),s},{}),a,u;t.operation==="query"?(a="GET",u=fe):(a="SET",u=de);let l={};return t.selectionSet.selections.map(async s=>{var v;if(s.kind!==R.Kind.FIELD)return;let d=(v=s==null?void 0:s.alias)==null?void 0:v.value,f=s.name.value,c=u(e,s,i,r);l[d||f]=c}),{ops:l,opType:a,variables:r,db:e.db||"default"}}function me(e,n,t){if(typeof n!="object")return n;if(Array.isArray(n))return n.map(r=>me(e,r,t));if(n!=null&&n.$var){let r=n.$var;if(e.variables[r].required&&!t[r])throw new Error(`Variable ${r} required, but not provided`);return t[r]}let i={};for(let r in n)i[r]=me(e,n[r],t);return i}0&&(module.exports={createGet,createMutation,createOperations,genSchema,handleGraphqlVariables,parseGraphql});

@@ -92,3 +92,4 @@ "use strict";

else {
setPayload.$operation = 'insert';
// TODO: should be able to enable this
// setPayload.$operation = 'insert'
}

@@ -95,0 +96,0 @@ const selection = (0, selection_1.selectionSetToGet)(ctx, type, graphqlAst.selectionSet, fragments, variables);

@@ -19,7 +19,7 @@ "use strict";

parents(filter: Filter, recursive: Boolean): [Node!]
children(filter: Filter, recursive: Boolean): [Node!]
parents(filter: Filter, sortBy: SortBy, recursive: Boolean): [Node!]
children(filter: Filter, sortBy: SortBy, recursive: Boolean): [Node!]
ancestors(filter: Filter): [Node!]
descendants(filter: Filter): [Node!]
ancestors(filter: Filter, sortBy: SortBy): [Node!]
descendants(filter: Filter, sortBy: SortBy): [Node!]
${allField}`;

@@ -130,3 +130,3 @@ const nodeInputFields = `aliases: StringSetInput

const inputType = INPUT_FIELD_TYPES[field.type];
typeFields += `${fieldName}(filter: Filter, recursive: Boolean): ${type}`;
typeFields += `${fieldName}(filter: Filter, sortBy: SortBy, recursive: Boolean): ${type}`;
inputTypeFields += `${fieldName}: ${inputType}`;

@@ -167,3 +167,3 @@ nestedTypes += compileTimeseriesType(typeName, field, type);

${refFields.size
? `_traverse(traverse: TraverseByType, filter: Filter, recursive: Boolean = false): [Node!]`
? `_traverse(traverse: TraverseByType, filter: Filter, sortBy: SortBy, recursive: Boolean = false): [Node!]`
: ''}

@@ -217,2 +217,12 @@

enum SortByOrder {
DESC
ASC
}
input SortBy {
field: String!
order: SortByOrder
}
input Filter {

@@ -219,0 +229,0 @@ op: FilterOperation!

@@ -9,2 +9,3 @@ "use strict";

const filter_1 = require("./filter");
const sort_1 = require("./sort");
const specialFields_1 = require("./specialFields");

@@ -101,2 +102,3 @@ function selectionSetToGet(ctx, type, graphqlAst, fragments, variables = {}, path = '') {

let filterAst = null;
let sortAst = null;
for (const arg of args) {

@@ -140,2 +142,5 @@ if (arg?.name?.value === 'traverse') {

}
else if (arg?.name?.value === 'sortBy') {
sortAst = arg;
}
else if (arg?.name?.value === 'recursive' &&

@@ -192,5 +197,9 @@ arg?.value?.kind === 'BooleanValue') {

const filter = (0, filter_1.filterToFindFilter)(filterAst, hasNonInline ? new Set() : typeFilter, variables);
const sortBy = (0, sort_1.compileSort)(sortAst, variables);
if (filter) {
refGetOpts.$list.$find.$filter = filter;
}
if (sortBy) {
refGetOpts.$list.$sort = sortBy;
}
if (recursive !== null) {

@@ -197,0 +206,0 @@ // TODO

@@ -80,2 +80,5 @@ "use strict";

}
else if (v.kind === 'EnumValue') {
return v.value;
}
else if (v.kind === 'FloatValue') {

@@ -82,0 +85,0 @@ return Number(v.value);

{
"name": "@based/graphql",
"version": "1.0.6",
"main": "dist/bundle.js",
"version": "1.0.8",
"main": "dist/index.js",
"scripts": {

@@ -6,0 +6,0 @@ "buildBundle": "node ./build/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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