@m1212e/rumble 0.11.4 → 0.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/index.cjs +37 -37
- package/index.cjs.map +1 -1
- package/index.d.cts +0 -14
- package/index.d.ts +0 -14
- package/index.js +37 -37
- package/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -270,4 +270,16 @@ users.subscribe((s) => s?.at(0));
|
|
|
270
270
|
|
|
271
271
|
// you can directly access the values of an awaited result
|
|
272
272
|
console.log(users.firstName)
|
|
273
|
-
```
|
|
273
|
+
```
|
|
274
|
+
### Alternative
|
|
275
|
+
As an alternative to use the client generator with a fully instanciated rumble instance, you can also import the `generateFromSchema` function from rumble and pass it a standard `GraphQLSchema` object to generate the client:
|
|
276
|
+
```ts
|
|
277
|
+
import { generateFromSchema } from "@m1212e/rumble";
|
|
278
|
+
|
|
279
|
+
await generateFromSchema({
|
|
280
|
+
// a schema object: https://github.com/graphql/graphql-js/blob/60ae6c48b9c78332bf3d6036e7d931a3617d0674/src/type/schema.ts#L130
|
|
281
|
+
schema: yourGraphQLSchemaObject
|
|
282
|
+
outputPath: "./generated";
|
|
283
|
+
})
|
|
284
|
+
```
|
|
285
|
+
This might become handy in separate code bases for api and client.
|
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var promises=require('fs/promises'),path=require('path'),esToolkit=require('es-toolkit'),wonka=require('wonka'),graphqlArmor=require('@escape.tech/graphql-armor'),pluginDisableIntrospection=require('@graphql-yoga/plugin-disable-introspection'),graphqlYoga=require('graphql-yoga'),sofaApi=require('sofa-api'),drizzleOrm=require('drizzle-orm'),casing=require('drizzle-orm/casing'),pgCore=require('drizzle-orm/pg-core'),pluralize=require('pluralize'),mysqlCore=require('drizzle-orm/mysql-core'),sqliteCore=require('drizzle-orm/sqlite-core'),
|
|
1
|
+
'use strict';var promises=require('fs/promises'),path=require('path'),esToolkit=require('es-toolkit'),wonka=require('wonka'),graphqlArmor=require('@escape.tech/graphql-armor'),pluginDisableIntrospection=require('@graphql-yoga/plugin-disable-introspection'),graphqlYoga=require('graphql-yoga'),sofaApi=require('sofa-api'),drizzleOrm=require('drizzle-orm'),casing=require('drizzle-orm/casing'),pgCore=require('drizzle-orm/pg-core'),pluralize=require('pluralize'),mysqlCore=require('drizzle-orm/mysql-core'),sqliteCore=require('drizzle-orm/sqlite-core'),ri=require('@pothos/core'),ui=require('@pothos/plugin-drizzle'),pi=require('@pothos/plugin-smart-subscriptions'),graphqlScalars=require('graphql-scalars');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ri__default=/*#__PURE__*/_interopDefault(ri);var ui__default=/*#__PURE__*/_interopDefault(ui);var pi__default=/*#__PURE__*/_interopDefault(pi);function lt({apiUrl:e,rumbleImportPath:t,useExternalUrqlClient:n,availableSubscriptions:r}){let s=[],i="";return typeof n=="string"?s.push(`import { urqlClient } from "${n}";`):(s.push("import { Client, fetchExchange } from '@urql/core';"),s.push("import { cacheExchange } from '@urql/exchange-graphcache';")),s.push(`import { makeLiveQuery, makeMutation, makeSubscription, makeQuery } from '${t}';`),n||(i+=`
|
|
2
2
|
const urqlClient = new Client({
|
|
3
3
|
url: "${e??"PLEASE PROVIDE A URL WHEN GENERATING OR IMPORT AN EXTERNAL URQL CLIENT"}",
|
|
4
4
|
fetchSubscriptions: true,
|
|
@@ -18,7 +18,7 @@ export const client = {
|
|
|
18
18
|
*/
|
|
19
19
|
liveQuery: makeLiveQuery<Query>({
|
|
20
20
|
urqlClient,
|
|
21
|
-
availableSubscriptions: new Set([${r.values().toArray().map(
|
|
21
|
+
availableSubscriptions: new Set([${r.values().toArray().map(o=>`"${o}"`).join(", ")}]),
|
|
22
22
|
}),
|
|
23
23
|
/**
|
|
24
24
|
* A mutation that can be used to e.g. create, update or delete data.
|
|
@@ -38,15 +38,15 @@ export const client = {
|
|
|
38
38
|
query: makeQuery<Query>({
|
|
39
39
|
urqlClient,
|
|
40
40
|
}),
|
|
41
|
-
}`,{imports:
|
|
42
|
-
`,a=r.split(/\r\n|[\n\r]/g),m=a[
|
|
43
|
-
`)}function
|
|
41
|
+
}`,{imports:s,code:i}}function C(e,t){throw new Error(t)}function ce(e){return typeof e=="object"&&e!==null}function ut(e,t){throw new Error("Unexpected invariant triggered.")}var fn=/\r\n|[\n\r]/g;function re(e,t){let n=0,r=1;for(let s of e.body.matchAll(fn)){if(typeof s.index=="number"||ut(),s.index>=t)break;n=s.index+s[0].length,r+=1;}return {line:r,column:t+1-n}}function ct(e){return Qe(e.source,re(e.source,e.start))}function Qe(e,t){let n=e.locationOffset.column-1,r="".padStart(n)+e.body,s=t.line-1,i=e.locationOffset.line-1,o=t.line+i,l=t.line===1?n:0,u=t.column+l,p=`${e.name}:${o}:${u}
|
|
42
|
+
`,a=r.split(/\r\n|[\n\r]/g),m=a[s];if(m.length>120){let c=Math.floor(u/80),x=u%80,d=[];for(let y=0;y<m.length;y+=80)d.push(m.slice(y,y+80));return p+pt([[`${o} |`,d[0]],...d.slice(1,c+1).map(y=>["|",y]),["|","^".padStart(x)],["|",d[c+1]]])}return p+pt([[`${o-1} |`,a[s-1]],[`${o} |`,m],["|","^".padStart(u)],[`${o+1} |`,a[s+1]]])}function pt(e){let t=e.filter(([r,s])=>s!==void 0),n=Math.max(...t.map(([r])=>r.length));return t.map(([r,s])=>r.padStart(n)+(s?" "+s:"")).join(`
|
|
43
|
+
`)}function yn(e){let t=e[0];return t==null||"kind"in t||"length"in t?{nodes:t,source:e[1],positions:e[2],path:e[3],originalError:e[4],extensions:e[5]}:t}var O=class e extends Error{constructor(t,...n){var r,s,i;let{nodes:o,source:l,positions:u,path:p,originalError:a,extensions:m}=yn(n);super(t),this.name="GraphQLError",this.path=p??void 0,this.originalError=a??void 0,this.nodes=mt(Array.isArray(o)?o:o?[o]:void 0);let c=mt((r=this.nodes)===null||r===void 0?void 0:r.map(d=>d.loc).filter(d=>d!=null));this.source=l??(c==null||(s=c[0])===null||s===void 0?void 0:s.source),this.positions=u??c?.map(d=>d.start),this.locations=u&&l?u.map(d=>re(l,d)):c?.map(d=>re(d.source,d.start));let x=ce(a?.extensions)?a?.extensions:void 0;this.extensions=(i=m??x)!==null&&i!==void 0?i:Object.create(null),Object.defineProperties(this,{message:{writable:true,enumerable:true},name:{enumerable:false},nodes:{enumerable:false},source:{enumerable:false},positions:{enumerable:false},originalError:{enumerable:false}}),a!=null&&a.stack?Object.defineProperty(this,"stack",{value:a.stack,writable:true,configurable:true}):Error.captureStackTrace?Error.captureStackTrace(this,e):Object.defineProperty(this,"stack",{value:Error().stack,writable:true,configurable:true});}get[Symbol.toStringTag](){return "GraphQLError"}toString(){let t=this.message;if(this.nodes)for(let n of this.nodes)n.loc&&(t+=`
|
|
44
44
|
|
|
45
|
-
`+
|
|
45
|
+
`+ct(n.loc));else if(this.source&&this.locations)for(let n of this.locations)t+=`
|
|
46
46
|
|
|
47
|
-
`+
|
|
47
|
+
`+Qe(this.source,n);return t}toJSON(){let t={message:this.message};return this.locations!=null&&(t.locations=this.locations),this.path!=null&&(t.path=this.path),this.extensions!=null&&Object.keys(this.extensions).length>0&&(t.extensions=this.extensions),t}};function mt(e){return e===void 0||e.length===0?void 0:e}var ke={Name:[],Document:["definitions"],OperationDefinition:["name","variableDefinitions","directives","selectionSet"],VariableDefinition:["variable","type","defaultValue","directives"],Variable:["name"],SelectionSet:["selections"],Field:["alias","name","arguments","directives","selectionSet"],Argument:["name","value"],FragmentSpread:["name","directives"],InlineFragment:["typeCondition","directives","selectionSet"],FragmentDefinition:["name","variableDefinitions","typeCondition","directives","selectionSet"],IntValue:[],FloatValue:[],StringValue:[],BooleanValue:[],NullValue:[],EnumValue:[],ListValue:["values"],ObjectValue:["fields"],ObjectField:["name","value"],Directive:["name","arguments"],NamedType:["name"],ListType:["type"],NonNullType:["type"],SchemaDefinition:["description","directives","operationTypes"],OperationTypeDefinition:["type"],ScalarTypeDefinition:["description","name","directives"],ObjectTypeDefinition:["description","name","interfaces","directives","fields"],FieldDefinition:["description","name","arguments","type","directives"],InputValueDefinition:["description","name","type","defaultValue","directives"],InterfaceTypeDefinition:["description","name","interfaces","directives","fields"],UnionTypeDefinition:["description","name","directives","types"],EnumTypeDefinition:["description","name","directives","values"],EnumValueDefinition:["description","name","directives"],InputObjectTypeDefinition:["description","name","directives","fields"],DirectiveDefinition:["description","name","arguments","locations"],SchemaExtension:["directives","operationTypes"],ScalarTypeExtension:["name","directives"],ObjectTypeExtension:["name","interfaces","directives","fields"],InterfaceTypeExtension:["name","interfaces","directives","fields"],UnionTypeExtension:["name","directives","types"],EnumTypeExtension:["name","directives","values"],InputObjectTypeExtension:["name","directives","fields"]},dn=new Set(Object.keys(ke));function je(e){let t=e?.kind;return typeof t=="string"&&dn.has(t)}var ft;(function(e){e.QUERY="query",e.MUTATION="mutation",e.SUBSCRIPTION="subscription";})(ft||(ft={}));var B;(function(e){e.NAME="Name",e.DOCUMENT="Document",e.OPERATION_DEFINITION="OperationDefinition",e.VARIABLE_DEFINITION="VariableDefinition",e.SELECTION_SET="SelectionSet",e.FIELD="Field",e.ARGUMENT="Argument",e.FRAGMENT_SPREAD="FragmentSpread",e.INLINE_FRAGMENT="InlineFragment",e.FRAGMENT_DEFINITION="FragmentDefinition",e.VARIABLE="Variable",e.INT="IntValue",e.FLOAT="FloatValue",e.STRING="StringValue",e.BOOLEAN="BooleanValue",e.NULL="NullValue",e.ENUM="EnumValue",e.LIST="ListValue",e.OBJECT="ObjectValue",e.OBJECT_FIELD="ObjectField",e.DIRECTIVE="Directive",e.NAMED_TYPE="NamedType",e.LIST_TYPE="ListType",e.NON_NULL_TYPE="NonNullType",e.SCHEMA_DEFINITION="SchemaDefinition",e.OPERATION_TYPE_DEFINITION="OperationTypeDefinition",e.SCALAR_TYPE_DEFINITION="ScalarTypeDefinition",e.OBJECT_TYPE_DEFINITION="ObjectTypeDefinition",e.FIELD_DEFINITION="FieldDefinition",e.INPUT_VALUE_DEFINITION="InputValueDefinition",e.INTERFACE_TYPE_DEFINITION="InterfaceTypeDefinition",e.UNION_TYPE_DEFINITION="UnionTypeDefinition",e.ENUM_TYPE_DEFINITION="EnumTypeDefinition",e.ENUM_VALUE_DEFINITION="EnumValueDefinition",e.INPUT_OBJECT_TYPE_DEFINITION="InputObjectTypeDefinition",e.DIRECTIVE_DEFINITION="DirectiveDefinition",e.SCHEMA_EXTENSION="SchemaExtension",e.SCALAR_TYPE_EXTENSION="ScalarTypeExtension",e.OBJECT_TYPE_EXTENSION="ObjectTypeExtension",e.INTERFACE_TYPE_EXTENSION="InterfaceTypeExtension",e.UNION_TYPE_EXTENSION="UnionTypeExtension",e.ENUM_TYPE_EXTENSION="EnumTypeExtension",e.INPUT_OBJECT_TYPE_EXTENSION="InputObjectTypeExtension";})(B||(B={}));function _e(e){return e===9||e===32}function hn(e){return e>=48&&e<=57}function yt(e){return e>=97&&e<=122||e>=65&&e<=90}function dt(e){return yt(e)||e===95}function ht(e){return yt(e)||hn(e)||e===95}function bt(e,t){let n=e.replace(/"""/g,'\\"""'),r=n.split(/\r\n|[\n\r]/g),s=r.length===1,i=r.length>1&&r.slice(1).every(x=>x.length===0||_e(x.charCodeAt(0))),o=n.endsWith('\\"""'),l=e.endsWith('"')&&!o,u=e.endsWith("\\"),p=l||u,a=(!s||e.length>70||p||i||o),m="",c=s&&_e(e.charCodeAt(0));return (a&&!c||i)&&(m+=`
|
|
48
48
|
`),m+=n,(a||p)&&(m+=`
|
|
49
|
-
`),'"""'+m+'"""'}function
|
|
49
|
+
`),'"""'+m+'"""'}function w(e){return me(e,[])}function me(e,t){switch(typeof e){case "string":return JSON.stringify(e);case "function":return e.name?`[function ${e.name}]`:"[function]";case "object":return bn(e,t);default:return String(e)}}function bn(e,t){if(e===null)return "null";if(t.includes(e))return "[Circular]";let n=[...t,e];if(gn(e)){let r=e.toJSON();if(r!==e)return typeof r=="string"?r:me(r,n)}else if(Array.isArray(e))return xn(e,n);return Tn(e,n)}function gn(e){return typeof e.toJSON=="function"}function Tn(e,t){let n=Object.entries(e);return n.length===0?"{}":t.length>2?"["+Sn(e)+"]":"{ "+n.map(([s,i])=>s+": "+me(i,t)).join(", ")+" }"}function xn(e,t){if(e.length===0)return "[]";if(t.length>2)return "[Array]";let n=Math.min(10,e.length),r=e.length-n,s=[];for(let i=0;i<n;++i)s.push(me(e[i],t));return r===1?s.push("... 1 more item"):r>1&&s.push(`... ${r} more items`),"["+s.join(", ")+"]"}function Sn(e){let t=Object.prototype.toString.call(e).replace(/^\[object /,"").replace(/]$/,"");if(t==="Object"&&typeof e.constructor=="function"){let n=e.constructor.name;if(typeof n=="string"&&n!=="")return n}return t}var Dn=globalThis.process&&process.env.NODE_ENV==="production",z=Dn?function(t,n){return t instanceof n}:function(t,n){if(t instanceof n)return true;if(typeof t=="object"&&t!==null){var r;let s=n.prototype[Symbol.toStringTag],i=Symbol.toStringTag in t?t[Symbol.toStringTag]:(r=t.constructor)===null||r===void 0?void 0:r.name;if(s===i){let o=w(t);throw new Error(`Cannot use ${s} "${o}" from another module or realm.
|
|
50
50
|
|
|
51
51
|
Ensure that there is only one instance of "graphql" in the node_modules
|
|
52
52
|
directory. If different versions of "graphql" are the dependencies of other
|
|
@@ -57,55 +57,55 @@ https://yarnpkg.com/en/docs/selective-version-resolutions
|
|
|
57
57
|
Duplicate "graphql" modules cannot be used at the same time since different
|
|
58
58
|
versions may have different capabilities and behavior. The data from one
|
|
59
59
|
version used in the function from another could produce confusing and
|
|
60
|
-
spurious results.`)}}return false};function
|
|
60
|
+
spurious results.`)}}return false};function gt(e,t){let[n,r]=t?[e,t]:[void 0,e],s=" Did you mean ";n&&(s+=n+" ");let i=r.map(u=>`"${u}"`);switch(i.length){case 0:return "";case 1:return s+i[0]+"?";case 2:return s+i[0]+" or "+i[1]+"?"}let o=i.slice(0,5),l=o.pop();return s+o.join(", ")+", or "+l+"?"}function qe(e){return e}function Tt(e,t){let n=Object.create(null);for(let r of e)n[t(r)]=r;return n}function ie(e,t,n){let r=Object.create(null);for(let s of e)r[t(s)]=n(s);return r}function se(e,t){let n=Object.create(null);for(let r of Object.keys(e))n[r]=t(e[r],r);return n}function xt(e,t){let n=0,r=0;for(;n<e.length&&r<t.length;){let s=e.charCodeAt(n),i=t.charCodeAt(r);if(fe(s)&&fe(i)){let o=0;do++n,o=o*10+s-ze,s=e.charCodeAt(n);while(fe(s)&&o>0);let l=0;do++r,l=l*10+i-ze,i=t.charCodeAt(r);while(fe(i)&&l>0);if(o<l)return -1;if(o>l)return 1}else {if(s<i)return -1;if(s>i)return 1;++n,++r;}}return e.length-t.length}var ze=48,Nn=57;function fe(e){return !isNaN(e)&&ze<=e&&e<=Nn}function Dt(e,t){let n=Object.create(null),r=new Ue(e),s=Math.floor(e.length*.4)+1;for(let i of t){let o=r.measure(i,s);o!==void 0&&(n[i]=o);}return Object.keys(n).sort((i,o)=>{let l=n[i]-n[o];return l!==0?l:xt(i,o)})}var Ue=class{constructor(t){this._input=t,this._inputLowerCase=t.toLowerCase(),this._inputArray=St(this._inputLowerCase),this._rows=[new Array(t.length+1).fill(0),new Array(t.length+1).fill(0),new Array(t.length+1).fill(0)];}measure(t,n){if(this._input===t)return 0;let r=t.toLowerCase();if(this._inputLowerCase===r)return 1;let s=St(r),i=this._inputArray;if(s.length<i.length){let a=s;s=i,i=a;}let o=s.length,l=i.length;if(o-l>n)return;let u=this._rows;for(let a=0;a<=l;a++)u[0][a]=a;for(let a=1;a<=o;a++){let m=u[(a-1)%3],c=u[a%3],x=c[0]=a;for(let d=1;d<=l;d++){let y=s[a-1]===i[d-1]?0:1,T=Math.min(m[d]+1,c[d-1]+1,m[d-1]+y);if(a>1&&d>1&&s[a-1]===i[d-2]&&s[a-2]===i[d-1]){let N=u[(a-2)%3][d-2];T=Math.min(T,N+1);}T<x&&(x=T),c[d]=T;}if(x>n)return}let p=u[o%3][l];return p<=n?p:void 0}};function St(e){let t=e.length,n=new Array(t);for(let r=0;r<t;++r)n[r]=e.charCodeAt(r);return n}function _(e){if(e==null)return Object.create(null);if(Object.getPrototypeOf(e)===null)return e;let t=Object.create(null);for(let[n,r]of Object.entries(e))t[n]=r;return t}function Nt(e){return `"${e.replace(En,An)}"`}var En=/[\x00-\x1f\x22\x5c\x7f-\x9f]/g;function An(e){return Cn[e.charCodeAt(0)]}var Cn=["\\u0000","\\u0001","\\u0002","\\u0003","\\u0004","\\u0005","\\u0006","\\u0007","\\b","\\t","\\n","\\u000B","\\f","\\r","\\u000E","\\u000F","\\u0010","\\u0011","\\u0012","\\u0013","\\u0014","\\u0015","\\u0016","\\u0017","\\u0018","\\u0019","\\u001A","\\u001B","\\u001C","\\u001D","\\u001E","\\u001F","","",'\\"',"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","\\\\","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","\\u007F","\\u0080","\\u0081","\\u0082","\\u0083","\\u0084","\\u0085","\\u0086","\\u0087","\\u0088","\\u0089","\\u008A","\\u008B","\\u008C","\\u008D","\\u008E","\\u008F","\\u0090","\\u0091","\\u0092","\\u0093","\\u0094","\\u0095","\\u0096","\\u0097","\\u0098","\\u0099","\\u009A","\\u009B","\\u009C","\\u009D","\\u009E","\\u009F"];var In=Object.freeze({});function Et(e,t,n=ke){let r=new Map;for(let N of Object.values(B))r.set(N,Rn(t,N));let s,i=Array.isArray(e),o=[e],l=-1,u=[],p=e,a,m,c=[],x=[];do{l++;let N=l===o.length,g=N&&u.length!==0;if(N){if(a=x.length===0?void 0:c[c.length-1],p=m,m=x.pop(),g)if(i){p=p.slice();let R=0;for(let[I,E]of u){let b=I-R;E===null?(p.splice(b,1),R++):p[b]=E;}}else {p={...p};for(let[R,I]of u)p[R]=I;}l=s.index,o=s.keys,u=s.edits,i=s.inArray,s=s.prev;}else if(m){if(a=i?l:o[l],p=m[a],p==null)continue;c.push(a);}let D;if(!Array.isArray(p)){var d,y;je(p)||C(false,`Invalid AST Node: ${w(p)}.`);let R=N?(d=r.get(p.kind))===null||d===void 0?void 0:d.leave:(y=r.get(p.kind))===null||y===void 0?void 0:y.enter;if(D=R?.call(t,p,a,m,c,x),D===In)break;if(D===false){if(!N){c.pop();continue}}else if(D!==void 0&&(u.push([a,D]),!N))if(je(D))p=D;else {c.pop();continue}}if(D===void 0&&g&&u.push([a,p]),N)c.pop();else {var T;s={inArray:i,index:l,keys:o,edits:u,prev:s},i=Array.isArray(p),o=i?p:(T=n[p.kind])!==null&&T!==void 0?T:[],l=-1,u=[],m&&x.push(m),m=p;}}while(s!==void 0);return u.length!==0?u[u.length-1][1]:e}function Rn(e,t){let n=e[t];return typeof n=="object"?n:typeof n=="function"?{enter:n,leave:void 0}:{enter:e.enter,leave:e.leave}}function Ge(e){return Et(e,Ln)}var vn=80,Ln={Name:{leave:e=>e.value},Variable:{leave:e=>"$"+e.name},Document:{leave:e=>f(e.definitions,`
|
|
61
61
|
|
|
62
|
-
`)},OperationDefinition:{leave(e){let t=S("(",f(e.variableDefinitions,", "),")"),n=f([e.operation,f([e.name,t]),f(e.directives," ")]," ");return (n==="query"?"":n+" ")+e.selectionSet}},VariableDefinition:{leave:({variable:e,type:t,defaultValue:n,directives:r})=>e+": "+t+S(" = ",n)+S(" ",f(r," "))},SelectionSet:{leave:({selections:e})=>q(e)},Field:{leave({alias:e,name:t,arguments:n,directives:r,selectionSet:
|
|
63
|
-
`,
|
|
62
|
+
`)},OperationDefinition:{leave(e){let t=S("(",f(e.variableDefinitions,", "),")"),n=f([e.operation,f([e.name,t]),f(e.directives," ")]," ");return (n==="query"?"":n+" ")+e.selectionSet}},VariableDefinition:{leave:({variable:e,type:t,defaultValue:n,directives:r})=>e+": "+t+S(" = ",n)+S(" ",f(r," "))},SelectionSet:{leave:({selections:e})=>q(e)},Field:{leave({alias:e,name:t,arguments:n,directives:r,selectionSet:s}){let i=S("",e,": ")+t,o=i+S("(",f(n,", "),")");return o.length>vn&&(o=i+S(`(
|
|
63
|
+
`,ye(f(n,`
|
|
64
64
|
`)),`
|
|
65
|
-
)`)),f([
|
|
65
|
+
)`)),f([o,f(r," "),s]," ")}},Argument:{leave:({name:e,value:t})=>e+": "+t},FragmentSpread:{leave:({name:e,directives:t})=>"..."+e+S(" ",f(t," "))},InlineFragment:{leave:({typeCondition:e,directives:t,selectionSet:n})=>f(["...",S("on ",e),f(t," "),n]," ")},FragmentDefinition:{leave:({name:e,typeCondition:t,variableDefinitions:n,directives:r,selectionSet:s})=>`fragment ${e}${S("(",f(n,", "),")")} on ${t} ${S("",f(r," ")," ")}`+s},IntValue:{leave:({value:e})=>e},FloatValue:{leave:({value:e})=>e},StringValue:{leave:({value:e,block:t})=>t?bt(e):Nt(e)},BooleanValue:{leave:({value:e})=>e?"true":"false"},NullValue:{leave:()=>"null"},EnumValue:{leave:({value:e})=>e},ListValue:{leave:({values:e})=>"["+f(e,", ")+"]"},ObjectValue:{leave:({fields:e})=>"{"+f(e,", ")+"}"},ObjectField:{leave:({name:e,value:t})=>e+": "+t},Directive:{leave:({name:e,arguments:t})=>"@"+e+S("(",f(t,", "),")")},NamedType:{leave:({name:e})=>e},ListType:{leave:({type:e})=>"["+e+"]"},NonNullType:{leave:({type:e})=>e+"!"},SchemaDefinition:{leave:({description:e,directives:t,operationTypes:n})=>S("",e,`
|
|
66
66
|
`)+f(["schema",f(t," "),q(n)]," ")},OperationTypeDefinition:{leave:({operation:e,type:t})=>e+": "+t},ScalarTypeDefinition:{leave:({description:e,name:t,directives:n})=>S("",e,`
|
|
67
|
-
`)+f(["scalar",t,f(n," ")]," ")},ObjectTypeDefinition:{leave:({description:e,name:t,interfaces:n,directives:r,fields:
|
|
68
|
-
`)+f(["type",t,S("implements ",f(n," & ")),f(r," "),q(
|
|
69
|
-
`)+t+(
|
|
70
|
-
`,
|
|
67
|
+
`)+f(["scalar",t,f(n," ")]," ")},ObjectTypeDefinition:{leave:({description:e,name:t,interfaces:n,directives:r,fields:s})=>S("",e,`
|
|
68
|
+
`)+f(["type",t,S("implements ",f(n," & ")),f(r," "),q(s)]," ")},FieldDefinition:{leave:({description:e,name:t,arguments:n,type:r,directives:s})=>S("",e,`
|
|
69
|
+
`)+t+(At(n)?S(`(
|
|
70
|
+
`,ye(f(n,`
|
|
71
71
|
`)),`
|
|
72
|
-
)`):S("(",f(n,", "),")"))+": "+r+S(" ",f(
|
|
73
|
-
`)+f([t+": "+n,S("= ",r),f(
|
|
74
|
-
`)+f(["interface",t,S("implements ",f(n," & ")),f(r," "),q(
|
|
72
|
+
)`):S("(",f(n,", "),")"))+": "+r+S(" ",f(s," "))},InputValueDefinition:{leave:({description:e,name:t,type:n,defaultValue:r,directives:s})=>S("",e,`
|
|
73
|
+
`)+f([t+": "+n,S("= ",r),f(s," ")]," ")},InterfaceTypeDefinition:{leave:({description:e,name:t,interfaces:n,directives:r,fields:s})=>S("",e,`
|
|
74
|
+
`)+f(["interface",t,S("implements ",f(n," & ")),f(r," "),q(s)]," ")},UnionTypeDefinition:{leave:({description:e,name:t,directives:n,types:r})=>S("",e,`
|
|
75
75
|
`)+f(["union",t,f(n," "),S("= ",f(r," | "))]," ")},EnumTypeDefinition:{leave:({description:e,name:t,directives:n,values:r})=>S("",e,`
|
|
76
76
|
`)+f(["enum",t,f(n," "),q(r)]," ")},EnumValueDefinition:{leave:({description:e,name:t,directives:n})=>S("",e,`
|
|
77
77
|
`)+f([t,f(n," ")]," ")},InputObjectTypeDefinition:{leave:({description:e,name:t,directives:n,fields:r})=>S("",e,`
|
|
78
|
-
`)+f(["input",t,f(n," "),q(r)]," ")},DirectiveDefinition:{leave:({description:e,name:t,arguments:n,repeatable:r,locations:
|
|
79
|
-
`)+"directive @"+t+(
|
|
80
|
-
`,
|
|
78
|
+
`)+f(["input",t,f(n," "),q(r)]," ")},DirectiveDefinition:{leave:({description:e,name:t,arguments:n,repeatable:r,locations:s})=>S("",e,`
|
|
79
|
+
`)+"directive @"+t+(At(n)?S(`(
|
|
80
|
+
`,ye(f(n,`
|
|
81
81
|
`)),`
|
|
82
|
-
)`):S("(",f(n,", "),")"))+(r?" repeatable":"")+" on "+f(
|
|
83
|
-
`,
|
|
82
|
+
)`):S("(",f(n,", "),")"))+(r?" repeatable":"")+" on "+f(s," | ")},SchemaExtension:{leave:({directives:e,operationTypes:t})=>f(["extend schema",f(e," "),q(t)]," ")},ScalarTypeExtension:{leave:({name:e,directives:t})=>f(["extend scalar",e,f(t," ")]," ")},ObjectTypeExtension:{leave:({name:e,interfaces:t,directives:n,fields:r})=>f(["extend type",e,S("implements ",f(t," & ")),f(n," "),q(r)]," ")},InterfaceTypeExtension:{leave:({name:e,interfaces:t,directives:n,fields:r})=>f(["extend interface",e,S("implements ",f(t," & ")),f(n," "),q(r)]," ")},UnionTypeExtension:{leave:({name:e,directives:t,types:n})=>f(["extend union",e,f(t," "),S("= ",f(n," | "))]," ")},EnumTypeExtension:{leave:({name:e,directives:t,values:n})=>f(["extend enum",e,f(t," "),q(n)]," ")},InputObjectTypeExtension:{leave:({name:e,directives:t,fields:n})=>f(["extend input",e,f(t," "),q(n)]," ")}};function f(e,t=""){var n;return (n=e?.filter(r=>r).join(t))!==null&&n!==void 0?n:""}function q(e){return S(`{
|
|
83
|
+
`,ye(f(e,`
|
|
84
84
|
`)),`
|
|
85
|
-
}`)}function S(e,t,n=""){return t!=null&&t!==""?e+t+n:""}function
|
|
86
|
-
`))}function
|
|
87
|
-
`)))!==null&&t!==void 0?t:false}function ye(e,t){switch(e.kind){case B.NULL:return null;case B.INT:return parseInt(e.value,10);case B.FLOAT:return parseFloat(e.value);case B.STRING:case B.ENUM:case B.BOOLEAN:return e.value;case B.LIST:return e.values.map(n=>ye(n,t));case B.OBJECT:return ie(e.fields,n=>n.name.value,n=>ye(n.value,t));case B.VARIABLE:return t?.[e.name.value]}}function Q(e){if(e!=null||C(false,"Must provide name."),typeof e=="string"||C(false,"Expected name to be a string."),e.length===0)throw new L("Expected name to be a non-empty string.");for(let t=1;t<e.length;++t)if(!lt(e.charCodeAt(t)))throw new L(`Names must only contain [_a-zA-Z0-9] but "${e}" does not.`);if(!at(e.charCodeAt(0)))throw new L(`Names must start with [_a-zA-Z] but "${e}" does not.`);return e}function je(e){if(e==="true"||e==="false"||e==="null")throw new L(`Enum values cannot be named: ${e}`);return Q(e)}function be(e){return _e(e)||Qe(e)||ke(e)||qe(e)||ze(e)||Ue(e)||Ge(e)||ge(e)}function _e(e){return z(e,W)}function Qe(e){return z(e,J)}function ke(e){return z(e,se)}function qe(e){return z(e,ae)}function ze(e){return z(e,X)}function Ue(e){return z(e,K)}function Ge(e){return z(e,M)}function ge(e){return z(e,U)}var M=class{constructor(t){be(t)||C(false,`Expected ${P(t)} to be a GraphQL type.`),this.ofType=t;}get[Symbol.toStringTag](){return "GraphQLList"}toString(){return "["+String(this.ofType)+"]"}toJSON(){return this.toString()}},U=class{constructor(t){$e(t)||C(false,`Expected ${P(t)} to be a GraphQL nullable type.`),this.ofType=t;}get[Symbol.toStringTag](){return "GraphQLNonNull"}toString(){return String(this.ofType)+"!"}toJSON(){return this.toString()}};function $e(e){return be(e)&&!ge(e)}function Te(e){return typeof e=="function"?e():e}function xe(e){return typeof e=="function"?e():e}var W=class{constructor(t){var n,r,o,i;let s=(n=t.parseValue)!==null&&n!==void 0?n:Be;this.name=Q(t.name),this.description=t.description,this.specifiedByURL=t.specifiedByURL,this.serialize=(r=t.serialize)!==null&&r!==void 0?r:Be,this.parseValue=s,this.parseLiteral=(o=t.parseLiteral)!==null&&o!==void 0?o:(l,u)=>s(ye(l,u)),this.extensions=k(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(i=t.extensionASTNodes)!==null&&i!==void 0?i:[],t.specifiedByURL==null||typeof t.specifiedByURL=="string"||C(false,`${this.name} must provide "specifiedByURL" as a string, but got: ${P(t.specifiedByURL)}.`),t.serialize==null||typeof t.serialize=="function"||C(false,`${this.name} must provide "serialize" function. If this custom Scalar is also used as an input type, ensure "parseValue" and "parseLiteral" functions are also provided.`),t.parseLiteral&&(typeof t.parseValue=="function"&&typeof t.parseLiteral=="function"||C(false,`${this.name} must provide both "parseValue" and "parseLiteral" functions.`));}get[Symbol.toStringTag](){return "GraphQLScalarType"}toConfig(){return {name:this.name,description:this.description,specifiedByURL:this.specifiedByURL,serialize:this.serialize,parseValue:this.parseValue,parseLiteral:this.parseLiteral,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}},J=class{constructor(t){var n;this.name=Q(t.name),this.description=t.description,this.isTypeOf=t.isTypeOf,this.extensions=k(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(n=t.extensionASTNodes)!==null&&n!==void 0?n:[],this._fields=()=>xt(t),this._interfaces=()=>Tt(t),t.isTypeOf==null||typeof t.isTypeOf=="function"||C(false,`${this.name} must provide "isTypeOf" as a function, but got: ${P(t.isTypeOf)}.`);}get[Symbol.toStringTag](){return "GraphQLObjectType"}getFields(){return typeof this._fields=="function"&&(this._fields=this._fields()),this._fields}getInterfaces(){return typeof this._interfaces=="function"&&(this._interfaces=this._interfaces()),this._interfaces}toConfig(){return {name:this.name,description:this.description,interfaces:this.getInterfaces(),fields:St(this.getFields()),isTypeOf:this.isTypeOf,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}};function Tt(e){var t;let n=Te((t=e.interfaces)!==null&&t!==void 0?t:[]);return Array.isArray(n)||C(false,`${e.name} interfaces must be an Array or a function which returns an Array.`),n}function xt(e){let t=xe(e.fields);return Z(t)||C(false,`${e.name} fields must be an object with field names as keys or a function which returns such an object.`),oe(t,(n,r)=>{var o;Z(n)||C(false,`${e.name}.${r} field config must be an object.`),n.resolve==null||typeof n.resolve=="function"||C(false,`${e.name}.${r} field resolver must be a function if provided, but got: ${P(n.resolve)}.`);let i=(o=n.args)!==null&&o!==void 0?o:{};return Z(i)||C(false,`${e.name}.${r} args must be an object with argument names as keys.`),{name:Q(r),description:n.description,type:n.type,args:yn(i),resolve:n.resolve,subscribe:n.subscribe,deprecationReason:n.deprecationReason,extensions:k(n.extensions),astNode:n.astNode}})}function yn(e){return Object.entries(e).map(([t,n])=>({name:Q(t),description:n.description,type:n.type,defaultValue:n.defaultValue,deprecationReason:n.deprecationReason,extensions:k(n.extensions),astNode:n.astNode}))}function Z(e){return ce(e)&&!Array.isArray(e)}function St(e){return oe(e,t=>({description:t.description,type:t.type,args:hn(t.args),resolve:t.resolve,subscribe:t.subscribe,deprecationReason:t.deprecationReason,extensions:t.extensions,astNode:t.astNode}))}function hn(e){return ie(e,t=>t.name,t=>({description:t.description,type:t.type,defaultValue:t.defaultValue,deprecationReason:t.deprecationReason,extensions:t.extensions,astNode:t.astNode}))}var se=class{constructor(t){var n;this.name=Q(t.name),this.description=t.description,this.resolveType=t.resolveType,this.extensions=k(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(n=t.extensionASTNodes)!==null&&n!==void 0?n:[],this._fields=xt.bind(void 0,t),this._interfaces=Tt.bind(void 0,t),t.resolveType==null||typeof t.resolveType=="function"||C(false,`${this.name} must provide "resolveType" as a function, but got: ${P(t.resolveType)}.`);}get[Symbol.toStringTag](){return "GraphQLInterfaceType"}getFields(){return typeof this._fields=="function"&&(this._fields=this._fields()),this._fields}getInterfaces(){return typeof this._interfaces=="function"&&(this._interfaces=this._interfaces()),this._interfaces}toConfig(){return {name:this.name,description:this.description,interfaces:this.getInterfaces(),fields:St(this.getFields()),resolveType:this.resolveType,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}},ae=class{constructor(t){var n;this.name=Q(t.name),this.description=t.description,this.resolveType=t.resolveType,this.extensions=k(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(n=t.extensionASTNodes)!==null&&n!==void 0?n:[],this._types=bn.bind(void 0,t),t.resolveType==null||typeof t.resolveType=="function"||C(false,`${this.name} must provide "resolveType" as a function, but got: ${P(t.resolveType)}.`);}get[Symbol.toStringTag](){return "GraphQLUnionType"}getTypes(){return typeof this._types=="function"&&(this._types=this._types()),this._types}toConfig(){return {name:this.name,description:this.description,types:this.getTypes(),resolveType:this.resolveType,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}};function bn(e){let t=Te(e.types);return Array.isArray(t)||C(false,`Must provide Array of types or a function which returns such an array for Union ${e.name}.`),t}var X=class{constructor(t){var n;this.name=Q(t.name),this.description=t.description,this.extensions=k(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(n=t.extensionASTNodes)!==null&&n!==void 0?n:[],this._values=typeof t.values=="function"?t.values:gt(this.name,t.values),this._valueLookup=null,this._nameLookup=null;}get[Symbol.toStringTag](){return "GraphQLEnumType"}getValues(){return typeof this._values=="function"&&(this._values=gt(this.name,this._values())),this._values}getValue(t){return this._nameLookup===null&&(this._nameLookup=ct(this.getValues(),n=>n.name)),this._nameLookup[t]}serialize(t){this._valueLookup===null&&(this._valueLookup=new Map(this.getValues().map(r=>[r.value,r])));let n=this._valueLookup.get(t);if(n===void 0)throw new L(`Enum "${this.name}" cannot represent value: ${P(t)}`);return n.name}parseValue(t){if(typeof t!="string"){let r=P(t);throw new L(`Enum "${this.name}" cannot represent non-string value: ${r}.`+he(this,r))}let n=this.getValue(t);if(n==null)throw new L(`Value "${t}" does not exist in "${this.name}" enum.`+he(this,t));return n.value}parseLiteral(t,n){if(t.kind!==B.ENUM){let o=Fe(t);throw new L(`Enum "${this.name}" cannot represent non-enum value: ${o}.`+he(this,o),{nodes:t})}let r=this.getValue(t.value);if(r==null){let o=Fe(t);throw new L(`Value "${o}" does not exist in "${this.name}" enum.`+he(this,o),{nodes:t})}return r.value}toConfig(){let t=ie(this.getValues(),n=>n.name,n=>({description:n.description,value:n.value,deprecationReason:n.deprecationReason,extensions:n.extensions,astNode:n.astNode}));return {name:this.name,description:this.description,values:t,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}};function he(e,t){let n=e.getValues().map(o=>o.name),r=dt(t,n);return pt("the enum value",r)}function gt(e,t){return Z(t)||C(false,`${e} values must be an object with value names as keys.`),Object.entries(t).map(([n,r])=>(Z(r)||C(false,`${e}.${n} must refer to an object with a "value" key representing an internal value but got: ${P(r)}.`),{name:je(n),description:r.description,value:r.value!==void 0?r.value:n,deprecationReason:r.deprecationReason,extensions:k(r.extensions),astNode:r.astNode}))}var K=class{constructor(t){var n,r;this.name=Q(t.name),this.description=t.description,this.extensions=k(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(n=t.extensionASTNodes)!==null&&n!==void 0?n:[],this.isOneOf=(r=t.isOneOf)!==null&&r!==void 0?r:false,this._fields=gn.bind(void 0,t);}get[Symbol.toStringTag](){return "GraphQLInputObjectType"}getFields(){return typeof this._fields=="function"&&(this._fields=this._fields()),this._fields}toConfig(){let t=oe(this.getFields(),n=>({description:n.description,type:n.type,defaultValue:n.defaultValue,deprecationReason:n.deprecationReason,extensions:n.extensions,astNode:n.astNode}));return {name:this.name,description:this.description,fields:t,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes,isOneOf:this.isOneOf}}toString(){return this.name}toJSON(){return this.toString()}};function gn(e){let t=xe(e.fields);return Z(t)||C(false,`${e.name} fields must be an object with field names as keys or a function which returns such an object.`),oe(t,(n,r)=>(!("resolve"in n)||C(false,`${e.name}.${r} field has a resolve property, but Input Types cannot define resolvers.`),{name:Q(r),description:n.description,type:n.type,defaultValue:n.defaultValue,deprecationReason:n.deprecationReason,extensions:k(n.extensions),astNode:n.astNode}))}function Ve(e){if(e instanceof J)return Kn(e);if(e instanceof W)return er(e);if(e instanceof X)return tr(e);if(e instanceof K)return Yn(e)}function Kn(e){let t=new Map;for(let[n,r]of Object.entries(e.getFields()))t.set(n,Hn(r.type,r.args));return `{
|
|
85
|
+
}`)}function S(e,t,n=""){return t!=null&&t!==""?e+t+n:""}function ye(e){return S(" ",e.replace(/\n/g,`
|
|
86
|
+
`))}function At(e){var t;return (t=e?.some(n=>n.includes(`
|
|
87
|
+
`)))!==null&&t!==void 0?t:false}function de(e,t){switch(e.kind){case B.NULL:return null;case B.INT:return parseInt(e.value,10);case B.FLOAT:return parseFloat(e.value);case B.STRING:case B.ENUM:case B.BOOLEAN:return e.value;case B.LIST:return e.values.map(n=>de(n,t));case B.OBJECT:return ie(e.fields,n=>n.name.value,n=>de(n.value,t));case B.VARIABLE:return t?.[e.name.value]}}function j(e){if(e!=null||C(false,"Must provide name."),typeof e=="string"||C(false,"Expected name to be a string."),e.length===0)throw new O("Expected name to be a non-empty string.");for(let t=1;t<e.length;++t)if(!ht(e.charCodeAt(t)))throw new O(`Names must only contain [_a-zA-Z0-9] but "${e}" does not.`);if(!dt(e.charCodeAt(0)))throw new O(`Names must start with [_a-zA-Z] but "${e}" does not.`);return e}function $e(e){if(e==="true"||e==="false"||e==="null")throw new O(`Enum values cannot be named: ${e}`);return j(e)}function be(e){return Ve(e)||Me(e)||We(e)||Je(e)||Ke(e)||Ye(e)||He(e)||ge(e)}function Ve(e){return z(e,M)}function Me(e){return z(e,W)}function We(e){return z(e,oe)}function Je(e){return z(e,ae)}function Ke(e){return z(e,Y)}function Ye(e){return z(e,J)}function He(e){return z(e,V)}function ge(e){return z(e,U)}var V=class{constructor(t){be(t)||C(false,`Expected ${w(t)} to be a GraphQL type.`),this.ofType=t;}get[Symbol.toStringTag](){return "GraphQLList"}toString(){return "["+String(this.ofType)+"]"}toJSON(){return this.toString()}},U=class{constructor(t){Xe(t)||C(false,`Expected ${w(t)} to be a GraphQL nullable type.`),this.ofType=t;}get[Symbol.toStringTag](){return "GraphQLNonNull"}toString(){return String(this.ofType)+"!"}toJSON(){return this.toString()}};function Xe(e){return be(e)&&!ge(e)}function Te(e){return typeof e=="function"?e():e}function xe(e){return typeof e=="function"?e():e}var M=class{constructor(t){var n,r,s,i;let o=(n=t.parseValue)!==null&&n!==void 0?n:qe;this.name=j(t.name),this.description=t.description,this.specifiedByURL=t.specifiedByURL,this.serialize=(r=t.serialize)!==null&&r!==void 0?r:qe,this.parseValue=o,this.parseLiteral=(s=t.parseLiteral)!==null&&s!==void 0?s:(l,u)=>o(de(l,u)),this.extensions=_(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(i=t.extensionASTNodes)!==null&&i!==void 0?i:[],t.specifiedByURL==null||typeof t.specifiedByURL=="string"||C(false,`${this.name} must provide "specifiedByURL" as a string, but got: ${w(t.specifiedByURL)}.`),t.serialize==null||typeof t.serialize=="function"||C(false,`${this.name} must provide "serialize" function. If this custom Scalar is also used as an input type, ensure "parseValue" and "parseLiteral" functions are also provided.`),t.parseLiteral&&(typeof t.parseValue=="function"&&typeof t.parseLiteral=="function"||C(false,`${this.name} must provide both "parseValue" and "parseLiteral" functions.`));}get[Symbol.toStringTag](){return "GraphQLScalarType"}toConfig(){return {name:this.name,description:this.description,specifiedByURL:this.specifiedByURL,serialize:this.serialize,parseValue:this.parseValue,parseLiteral:this.parseLiteral,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}},W=class{constructor(t){var n;this.name=j(t.name),this.description=t.description,this.isTypeOf=t.isTypeOf,this.extensions=_(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(n=t.extensionASTNodes)!==null&&n!==void 0?n:[],this._fields=()=>Rt(t),this._interfaces=()=>It(t),t.isTypeOf==null||typeof t.isTypeOf=="function"||C(false,`${this.name} must provide "isTypeOf" as a function, but got: ${w(t.isTypeOf)}.`);}get[Symbol.toStringTag](){return "GraphQLObjectType"}getFields(){return typeof this._fields=="function"&&(this._fields=this._fields()),this._fields}getInterfaces(){return typeof this._interfaces=="function"&&(this._interfaces=this._interfaces()),this._interfaces}toConfig(){return {name:this.name,description:this.description,interfaces:this.getInterfaces(),fields:vt(this.getFields()),isTypeOf:this.isTypeOf,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}};function It(e){var t;let n=Te((t=e.interfaces)!==null&&t!==void 0?t:[]);return Array.isArray(n)||C(false,`${e.name} interfaces must be an Array or a function which returns an Array.`),n}function Rt(e){let t=xe(e.fields);return Z(t)||C(false,`${e.name} fields must be an object with field names as keys or a function which returns such an object.`),se(t,(n,r)=>{var s;Z(n)||C(false,`${e.name}.${r} field config must be an object.`),n.resolve==null||typeof n.resolve=="function"||C(false,`${e.name}.${r} field resolver must be a function if provided, but got: ${w(n.resolve)}.`);let i=(s=n.args)!==null&&s!==void 0?s:{};return Z(i)||C(false,`${e.name}.${r} args must be an object with argument names as keys.`),{name:j(r),description:n.description,type:n.type,args:On(i),resolve:n.resolve,subscribe:n.subscribe,deprecationReason:n.deprecationReason,extensions:_(n.extensions),astNode:n.astNode}})}function On(e){return Object.entries(e).map(([t,n])=>({name:j(t),description:n.description,type:n.type,defaultValue:n.defaultValue,deprecationReason:n.deprecationReason,extensions:_(n.extensions),astNode:n.astNode}))}function Z(e){return ce(e)&&!Array.isArray(e)}function vt(e){return se(e,t=>({description:t.description,type:t.type,args:Bn(t.args),resolve:t.resolve,subscribe:t.subscribe,deprecationReason:t.deprecationReason,extensions:t.extensions,astNode:t.astNode}))}function Bn(e){return ie(e,t=>t.name,t=>({description:t.description,type:t.type,defaultValue:t.defaultValue,deprecationReason:t.deprecationReason,extensions:t.extensions,astNode:t.astNode}))}var oe=class{constructor(t){var n;this.name=j(t.name),this.description=t.description,this.resolveType=t.resolveType,this.extensions=_(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(n=t.extensionASTNodes)!==null&&n!==void 0?n:[],this._fields=Rt.bind(void 0,t),this._interfaces=It.bind(void 0,t),t.resolveType==null||typeof t.resolveType=="function"||C(false,`${this.name} must provide "resolveType" as a function, but got: ${w(t.resolveType)}.`);}get[Symbol.toStringTag](){return "GraphQLInterfaceType"}getFields(){return typeof this._fields=="function"&&(this._fields=this._fields()),this._fields}getInterfaces(){return typeof this._interfaces=="function"&&(this._interfaces=this._interfaces()),this._interfaces}toConfig(){return {name:this.name,description:this.description,interfaces:this.getInterfaces(),fields:vt(this.getFields()),resolveType:this.resolveType,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}},ae=class{constructor(t){var n;this.name=j(t.name),this.description=t.description,this.resolveType=t.resolveType,this.extensions=_(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(n=t.extensionASTNodes)!==null&&n!==void 0?n:[],this._types=wn.bind(void 0,t),t.resolveType==null||typeof t.resolveType=="function"||C(false,`${this.name} must provide "resolveType" as a function, but got: ${w(t.resolveType)}.`);}get[Symbol.toStringTag](){return "GraphQLUnionType"}getTypes(){return typeof this._types=="function"&&(this._types=this._types()),this._types}toConfig(){return {name:this.name,description:this.description,types:this.getTypes(),resolveType:this.resolveType,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}};function wn(e){let t=Te(e.types);return Array.isArray(t)||C(false,`Must provide Array of types or a function which returns such an array for Union ${e.name}.`),t}var Y=class{constructor(t){var n;this.name=j(t.name),this.description=t.description,this.extensions=_(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(n=t.extensionASTNodes)!==null&&n!==void 0?n:[],this._values=typeof t.values=="function"?t.values:Ct(this.name,t.values),this._valueLookup=null,this._nameLookup=null;}get[Symbol.toStringTag](){return "GraphQLEnumType"}getValues(){return typeof this._values=="function"&&(this._values=Ct(this.name,this._values())),this._values}getValue(t){return this._nameLookup===null&&(this._nameLookup=Tt(this.getValues(),n=>n.name)),this._nameLookup[t]}serialize(t){this._valueLookup===null&&(this._valueLookup=new Map(this.getValues().map(r=>[r.value,r])));let n=this._valueLookup.get(t);if(n===void 0)throw new O(`Enum "${this.name}" cannot represent value: ${w(t)}`);return n.name}parseValue(t){if(typeof t!="string"){let r=w(t);throw new O(`Enum "${this.name}" cannot represent non-string value: ${r}.`+he(this,r))}let n=this.getValue(t);if(n==null)throw new O(`Value "${t}" does not exist in "${this.name}" enum.`+he(this,t));return n.value}parseLiteral(t,n){if(t.kind!==B.ENUM){let s=Ge(t);throw new O(`Enum "${this.name}" cannot represent non-enum value: ${s}.`+he(this,s),{nodes:t})}let r=this.getValue(t.value);if(r==null){let s=Ge(t);throw new O(`Value "${s}" does not exist in "${this.name}" enum.`+he(this,s),{nodes:t})}return r.value}toConfig(){let t=ie(this.getValues(),n=>n.name,n=>({description:n.description,value:n.value,deprecationReason:n.deprecationReason,extensions:n.extensions,astNode:n.astNode}));return {name:this.name,description:this.description,values:t,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}};function he(e,t){let n=e.getValues().map(s=>s.name),r=Dt(t,n);return gt("the enum value",r)}function Ct(e,t){return Z(t)||C(false,`${e} values must be an object with value names as keys.`),Object.entries(t).map(([n,r])=>(Z(r)||C(false,`${e}.${n} must refer to an object with a "value" key representing an internal value but got: ${w(r)}.`),{name:$e(n),description:r.description,value:r.value!==void 0?r.value:n,deprecationReason:r.deprecationReason,extensions:_(r.extensions),astNode:r.astNode}))}var J=class{constructor(t){var n,r;this.name=j(t.name),this.description=t.description,this.extensions=_(t.extensions),this.astNode=t.astNode,this.extensionASTNodes=(n=t.extensionASTNodes)!==null&&n!==void 0?n:[],this.isOneOf=(r=t.isOneOf)!==null&&r!==void 0?r:false,this._fields=Fn.bind(void 0,t);}get[Symbol.toStringTag](){return "GraphQLInputObjectType"}getFields(){return typeof this._fields=="function"&&(this._fields=this._fields()),this._fields}toConfig(){let t=se(this.getFields(),n=>({description:n.description,type:n.type,defaultValue:n.defaultValue,deprecationReason:n.deprecationReason,extensions:n.extensions,astNode:n.astNode}));return {name:this.name,description:this.description,fields:t,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes,isOneOf:this.isOneOf}}toString(){return this.name}toJSON(){return this.toString()}};function Fn(e){let t=xe(e.fields);return Z(t)||C(false,`${e.name} fields must be an object with field names as keys or a function which returns such an object.`),se(t,(n,r)=>(!("resolve"in n)||C(false,`${e.name}.${r} field has a resolve property, but Input Types cannot define resolvers.`),{name:j(r),description:n.description,type:n.type,defaultValue:n.defaultValue,deprecationReason:n.deprecationReason,extensions:_(n.extensions),astNode:n.astNode}))}function Ze(e){if(e instanceof W)return cr(e);if(e instanceof M)return hr(e);if(e instanceof Y)return br(e);if(e instanceof J)return mr(e)}function cr(e){let t=new Map;for(let[n,r]of Object.entries(e.getFields()))t.set(n,fr(r.type,r.args));return `{
|
|
88
88
|
${t.entries().map(([n,r])=>`${n}: ${r}`).toArray().join(`,
|
|
89
89
|
`)}
|
|
90
|
-
}`}function
|
|
90
|
+
}`}function mr(e){let t=new Map;for(let[n,r]of Object.entries(e.getFields()))t.set(n,yr(r.type));return `{
|
|
91
91
|
${t.entries().map(([n,r])=>`${n}${r.includes("| undefined")?"?":""}: ${r}`).toArray().join(`,
|
|
92
92
|
`)}
|
|
93
|
-
}`}function
|
|
94
|
-
${
|
|
93
|
+
}`}function fr(e,t){let n=false,r=false;for(let l=0;l<3;l++)e instanceof V&&(r=true,e=e.ofType),e instanceof U&&(n=true,e=e.ofType);let s=e.name;r&&(s+="[]"),n||(s+=" | null");let i=e instanceof W,o=new Map;for(let l of t??[])o.set(l.name,dr(l.type));if(i){let l=o.entries().every(([,p])=>p.includes("| undefined"));return `(${(t??[]).length>0?`p${l?"?":""}: {
|
|
94
|
+
${o.entries().map(([p,a])=>` ${p}${a.includes("| undefined")?"?":""}: ${a}`).toArray().join(`,
|
|
95
95
|
`)}
|
|
96
|
-
}`:""}) => ${
|
|
97
|
-
export type ${p} = ${
|
|
98
|
-
`);let u=
|
|
96
|
+
}`:""}) => ${s}`}else return s}function yr(e){let t=false,n=false;for(let s=0;s<3;s++)e instanceof V&&(n=true,e=e.ofType),e instanceof U&&(t=true,e=e.ofType);let r=e.name;return n&&(r+="[]"),t?n&&(r+=" | undefined"):r+=" | null | undefined",r}function dr(e){let t="unknown",n=true;return e instanceof U&&(n=false,e=e.ofType),(e instanceof J||e instanceof M)&&(t=e.name),n&&(t+=" | null | undefined"),t}function hr(e){switch(e.name){case "ID":return "string";case "String":return "string";case "Boolean":return "boolean";case "Int":return "number";case "Float":return "number";case "Date":return "Date";case "DateTime":return "Date";case "JSON":return "any";default:return "unknown"}}function br(e){return e.getValues().map(t=>`"${t.name}"`).join(" | ")}async function et({outputPath:e,schema:t,rumbleImportPath:n="@m1212e/rumble",apiUrl:r,useExternalUrqlClient:s=false}){try{await promises.access(e),await promises.rm(e,{recursive:!0,force:!0});}catch{}await promises.mkdir(e,{recursive:true}),e.endsWith("/")||(e+="/");let i=[],o="",l=new Map;for(let[p,a]of Object.entries(t.getTypeMap()))p.startsWith("__")||l.set(p,a);for(let[p,a]of l.entries())Ze(a)!==p&&(o+=`
|
|
97
|
+
export type ${p} = ${Ze(a)};
|
|
98
|
+
`);let u=lt({apiUrl:r,useExternalUrqlClient:s,rumbleImportPath:n,availableSubscriptions:new Set(Object.keys(t.getSubscriptionType()?.getFields()||{}))});i.push(...u.imports),o+=u.code,await promises.writeFile(path.join(e,"client.ts"),`${i.join(`
|
|
99
99
|
`)}
|
|
100
|
-
${
|
|
100
|
+
${o}`);}var ee="__args";function De({queryName:e,input:t,client:n,enableSubscription:r=false}){let s=`${esToolkit.capitalize(e)}Query`,i=Ne(t[ee]??{}),o=a=>`${a} ${s} { ${e}${i} { ${ue(t)} }}`,l,u=wonka.pipe(wonka.merge([n.query(o("query"),{}),r?n.subscription(o("subscription"),{}):wonka.empty]),wonka.map(a=>{let m=a.data?.[e];if(!m&&a.error)throw a.error;return m}),wonka.onPush(a=>{l&&Object.assign(l,a);})),p=new Promise(a=>{let m=wonka.toObservable(u).subscribe(c=>{m();let x=wonka.pipe(wonka.merge([u,wonka.fromValue(c)]),wonka.toObservable);l={...c,...x},a(l);}).unsubscribe;});return Object.assign(p,wonka.toObservable(u)),p}function Ot({mutationName:e,input:t,client:n}){let r=`${esToolkit.capitalize(e)}Mutation`,s=Ne(t[ee]??{}),i=wonka.pipe(n.mutation(`mutation ${r} { ${e}${s} { ${ue(t)} }}`,{}),wonka.map(u=>{let p=u.data?.[e];if(!p&&u.error)throw u.error;return p})),o=wonka.toObservable(i),l=wonka.toPromise(i).then(u=>(Object.assign(u,o),u));return Object.assign(l,o),l}function Bt({subscriptionName:e,input:t,client:n}){let r=`${esToolkit.capitalize(e)}Subscription`,s=Ne(t[ee]??{});return wonka.pipe(n.subscription(`subscription ${r} { ${e}${s} { ${ue(t)} }}`,{}),wonka.map(i=>{let o=i.data?.[e];if(!o&&i.error)throw i.error;return o}),wonka.toObservable)}function ue(e){return Object.entries(e).filter(([t])=>t!==ee).reduce((t,[n,r])=>{if(typeof r=="object"){if(r[ee]){let s=Ne(r[ee]);return t+=`${n}${s} { ${ue(r)} }
|
|
101
101
|
`,t}t+=`${n} { ${ue(r)} }
|
|
102
102
|
`;}else t+=`${n}
|
|
103
|
-
`;return t},"")}function Ne(e){let t=Object.entries(e);return t.length===0?"":`(${t.map(([n,r])=>`${n}: ${
|
|
103
|
+
`;return t},"")}function Ne(e){let t=Object.entries(e);return t.length===0?"":`(${t.map(([n,r])=>`${n}: ${wt(r)}`).join(", ")})`}function wt(e){switch(typeof e){case "string":return `"${e}"`;case "number":return `${e}`;case "bigint":return `${e}`;case "boolean":return `${e}`;case "symbol":throw new Error("Cannot stringify a symbol to send as gql arg");case "undefined":return "null";case "object":return `{ ${Object.entries(e).map(([t,n])=>`${t}: ${wt(n)}`).join(", ")} }`;case "function":throw new Error("Cannot stringify a function to send as gql arg")}}function Ir({urqlClient:e,availableSubscriptions:t}){return new Proxy({},{get:(n,r)=>s=>De({queryName:r,input:s,client:e,enableSubscription:t.has(r)})})}function Rr({urqlClient:e}){return new Proxy({},{get:(t,n)=>r=>Ot({mutationName:n,input:r,client:e})})}function vr({urqlClient:e}){return new Proxy({},{get:(t,n)=>r=>De({queryName:n,input:r,client:e,enableSubscription:false})})}function Lr({urqlClient:e}){return new Proxy({},{get:(t,n)=>r=>Bt({subscriptionName:n,input:r,client:e})})}var L=class extends Error{constructor(t){super(t),this.name="RumbleError";}},te=class extends O{};var rt=e=>{if(!e)throw new te("Value not found but required (findFirst)");return e},Or=e=>{let t=e.at(0);if(!t)throw new te("Value not found but required (firstEntry)");return t},Ft=async({filters:e,entities:t,context:n})=>Array.from((await Promise.all(e.map(r=>r({context:n,entities:t})))).reduce((r,s)=>(s.forEach(i=>r.add(i)),r),new Set));function Br(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>[t,n===null?void 0:n]))}function G(e){let t,n=false;return ()=>(n||(t=e(),n=true),t)}var Pt=["serial","int","integer","tinyint","smallint","mediumint"];function Ee(e){return Pt.includes(e)}var Qt=["real","decimal","double","float","numeric"];function Ae(e){return Qt.includes(e)}var kt=["string","text","varchar","char","text(256)"];function Ce(e){return kt.includes(e)}var jt=["uuid"];function Ie(e){return jt.includes(e)}var _t=["boolean"];function Re(e){return _t.includes(e)}var qt=["timestamp","datetime"];function ve(e){return qt.includes(e)}var zt=["date"];function Le(e){return zt.includes(e)}var Ut=["json"];function Oe(e){return Ut.includes(e)}var Be=(e,t)=>new L(`RumbleError: Unknown SQL type '${e}'. Please open an issue (https://github.com/m1212e/rumble/issues) so it can be added. (${t})`);function Gt(e){if(Ee(e))return {value1:1,value2:2};if(Ae(e))return {value1:1.1,value2:2.2};if(Ce(e))return {value1:"a",value2:"b"};if(Ie(e))return {value1:"fba31870-5528-42d7-b27e-2e5ee657aea5",value2:"fc65db81-c2d1-483d-8a25-a30e2cf6e02d"};if(Re(e))return {value1:true,value2:false};if(ve(e))return {value1:new Date(2022,1,1),value2:new Date(2022,1,2)};if(Le(e))return {value1:new Date(2022,1,1),value2:new Date(2022,1,2)};if(Oe(e))return {value1:{a:1},value2:{b:2}};throw Be(e,"Distinct")}var it=Symbol.for("drizzle:Name"),$t=Symbol.for("drizzle:Columns");function Q({dbName:e,tsName:t,table:n,db:r}){let s=n;if(t&&(s=r._.relations.schema[t]),e&&(s=Object.values(r._.relations.schema).find(i=>i[it]===e)),!s)throw new L(`Could not find schema for ${JSON.stringify({tsName:t,dbName:e,table:n?.[it]}).toString()}`);return {tableSchema:s,columns:s[$t],get primaryColumns(){return Object.entries(s[$t]).filter(([,i])=>i.primary).reduce((i,[o,l])=>(i[o]=l,i),{})},relations:r._.relations.config[t],dbName:s[it],get tsName(){return Object.entries(r._.relations.schema).find(([,i])=>i===s).at(0)}}}function Pr(e){return typeof e!="function"}function Qr(e){return typeof e=="function"&&e.constructor.name!=="AsyncFunction"}var kr=esToolkit.debounce((e,t)=>{console.warn(`
|
|
104
104
|
Warning! No abilities have been registered for
|
|
105
105
|
|
|
106
106
|
${e}/${t}
|
|
107
107
|
|
|
108
108
|
but has been accessed. This will block everything. If this is intended, you can ignore this warning. If not, please ensure that you register the ability in your ability builder.
|
|
109
|
-
`);},1e3),
|
|
110
|
-
Please ensure that you use the enum at least once as a column of a table!`);u=x.enumValues;}else if(i){let c=Object.entries(e._.relations.schema).find(([,x])=>x===i.config.enum);if(!c)throw new O(`Could not find enum in schema for ${i.name}!`);l=c[0],u=i.enumValues;}if(!l||!u)throw new O("Could not determine enum structure!");let p=s??`${esToolkit.capitalize(casing.toCamelCase(l))}Enum`,a=n.get(p);return a||(a=t.enumType(p,{values:u}),n.set(p,a),a)}};var wt={paths:{"/webhook":{post:{operationId:"webhook_create",description:"Creates a webhook subscription.",tags:[],parameters:[],requestBody:{content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookCreateBody"}}}},responses:{200:{description:"",content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookDetailResponse"}}}}}}},"/webhook/{id}":{post:{operationId:"webhook_update",description:"Updates a webhook subscription.",parameters:[{name:"id",in:"path",description:"The ID of the webhook to update",required:true,schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookCreateBody"}}}},responses:{200:{description:"",content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookDetailResponse"}}}}}},delete:{operationId:"webhook_delete",description:"Removes a webhook subscription.",tags:[],parameters:[{name:"id",in:"path",description:"The ID of the webhook to delete",required:true,schema:{type:"string"}}],responses:{200:{description:"",content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookDetailResponse"}}}}}}}},components:{schemas:{WebhookCreateBody:{type:"object",properties:{subscription:{description:"The subscription to subscribe to. In many cases, these match the available query IDs without the '_query' suffix. E.g., 'findFirstUser_query' -> 'findFirstUser'. See the graphql schema for more details on what subscriptions are available.",type:"string"},variables:{description:"The variables to pass to the subscription.",type:"object"},url:{description:"The URL to send the webhook to.",type:"string"}}},WebhookDetailResponse:{type:"object",properties:{id:{description:"The ID of the webhook. Can be used as reference in update or delete calls.",type:"string"}}},DateTime:{type:"string",format:"date-time"},Date:{type:"string",format:"date"}}}};function Ce({sqlType:e,fieldName:t}){let n;if(["serial","int","integer","tinyint","smallint","mediumint"].includes(e)&&(n="Int"),["real","decimal","double","float"].includes(e)&&(n="Float"),["string","text","varchar","char","text(256)"].includes(e)&&(t&&(t.toLowerCase().endsWith("_id")||t.toLowerCase().endsWith("id"))?n="ID":n="String"),["uuid"].includes(e)&&(n="ID"),["boolean"].includes(e)&&(n="Boolean"),["timestamp","datetime"].includes(e)&&(n="DateTime"),["date"].includes(e)&&(n="Date"),["json"].includes(e)&&(n="JSON"),n!==void 0)return n;throw Ee(e,"SQL to GQL")}function Rr(e){let t=new Set;for(let r of Object.values(e))typeof r=="object"&&(r instanceof pgCore.PgTable?t.add("postgres"):r instanceof mysqlCore.MySqlTable?t.add("mysql"):r instanceof sqliteCore.SQLiteTable&&t.add("sqlite"));let n=Array.from(t);if(n.length===1)return n[0];throw n.length===0?new Error("No tables found in schema, could not determine dialect"):new Error(`Multiple dialects found in schema: ${n.join(", ")}`)}function Pt(e){return Rr(e._.relations.schema)==="postgres"}async function jt(e){if(!Pt(e)){console.info("Database dialect is not compatible with search, skipping search initialization.");return}await e.execute(drizzleOrm.sql`CREATE EXTENSION IF NOT EXISTS pg_trgm;`);}function Ie({search:e,args:t,tableSchema:n,abilities:r}){if(e?.enabled&&t.search&&t.search.length>0){let o=esToolkit.cloneDeep(t.orderBy);t.orderBy=s=>{let l=drizzleOrm.sql.join(Object.entries(o??{}).map(([m,c])=>{if(c==="asc")return drizzleOrm.sql`${s[m]} ASC`;if(c==="desc")return drizzleOrm.sql`${s[m]} DESC`;throw new Error(`Invalid value ${c} for orderBy`)}),drizzleOrm.sql.raw(", ")),u=r.query.many.columns?Object.entries(n.columns).filter(([m])=>r.query.many.columns[m]):Object.entries(n.columns),p=drizzleOrm.sql`GREATEST(${drizzleOrm.sql.join(u.map(([m])=>drizzleOrm.sql`similarity(${s[m]}::TEXT, ${t.search})`),drizzleOrm.sql.raw(", "))}) DESC`;return o?drizzleOrm.sql.join([l,p],drizzleOrm.sql.raw(", ")):p};let i=esToolkit.cloneDeep(t.where);t.where={AND:[i??{},{RAW:s=>drizzleOrm.sql`GREATEST(${drizzleOrm.sql.join(Object.entries(n.columns).map(([l])=>drizzleOrm.sql`similarity(${s[l]}::TEXT, ${t.search})`),drizzleOrm.sql.raw(", "))}) > ${e.threshold??.1}`}]};}}var wr=e=>typeof e!="object"?false:!!Object.keys(e).some(t=>["args","nullable","query","subscribe","description","type","resolve"].find(n=>n===t)),_t=({db:e,search:t,schemaBuilder:n,makePubSubInstance:r,whereArgImplementer:o,orderArgImplementer:i,enumImplementer:s,abilityBuilder:l})=>({table:u,refName:p,readAction:a="read",adjust:m})=>{let c=_({db:e,tsName:u});Object.keys(c.primaryColumns).length===0&&console.warn(`Could not find primary key for ${u.toString()}. Cannot register subscriptions!`);let x=Object.values(c.primaryColumns)[0],{registerOnInstance:h}=r({table:u});return n.drizzleObject(u,{name:p??esToolkit.capitalize(u.toString()),subscribe:(y,T,N)=>{if(!x)return;let g=T[x.name];if(!g){console.warn(`Could not find primary key value for ${JSON.stringify(T)}. Cannot register subscription!`);return}h({instance:y,action:"updated",primaryKeyValue:g});},applyFilters:l?.z_registeredFilters?.[u]?.[a],fields:y=>{let T=c.columns,N=(E,b,d)=>{let A=Ce({sqlType:E,fieldName:b});switch(A){case "Int":return y.exposeInt(b,{nullable:d});case "String":return y.exposeString(b,{nullable:d});case "Boolean":return y.exposeBoolean(b,{nullable:d});case "Date":return y.field({type:"Date",resolve:v=>v[b],nullable:d});case "DateTime":return y.field({type:"DateTime",resolve:v=>v[b],nullable:d});case "Float":return y.exposeFloat(b,{nullable:d});case "ID":return y.exposeID(b,{nullable:d});case "JSON":return y.field({type:"JSON",resolve:v=>v[b],nullable:d});default:throw new O(`Unsupported object type ${A} for column ${b}`)}},g=new Map,D=m?.(new Proxy(y,{get:(E,b)=>typeof E[b]!="function"||b==="arg"||b==="builder"||b==="graphqlKind"||b==="kind"||b==="listRef"||b==="table"||b==="typename"||b==="variant"||b.toString().startsWith("boolean")||b.toString().startsWith("float")||b.toString().startsWith("id")||b.toString().startsWith("int")||b.toString().startsWith("string")||b.toString().startsWith("expose")?E[b]:(...d)=>{let A=E[b](...d),v=d.find(wr);if(!v)throw new O("Expected config object to be passed to adjust field");return g.set(A,{params:d,creatorFunction:E[b],configObject:v}),A}}))??{},R=Object.entries(T).reduce((E,[b,d])=>{if(D[b]){let{params:A,creatorFunction:v,configObject:Y}=g.get(D[b]);return typeof Y.nullable!="boolean"&&(Y.nullable=!d.notNull),D[b]=v.bind(y)(...A),E}if(Ae(d)){let A=s({enumColumn:d});E[b]=y.field({type:A,resolve:v=>v[b],nullable:!d.notNull});}else E[b]=N(d.getSQLType(),b,!d.notNull);return E},{}),I=Object.entries(c.relations??{}).reduce((E,[b,d])=>{let A=_({db:e,table:d.targetTable}),v=o({dbName:A.dbName}),Y=i({dbName:A.dbName}),H=r({table:A.tsName}),$=false,w=true,pe="many";d instanceof drizzleOrm.One&&(w=false,$=d.optional,pe="single");let Xe=(j,ne)=>{H.registerOnInstance({instance:j,action:"created"}),H.registerOnInstance({instance:j,action:"removed"});};if(D[b]){let{params:j,creatorFunction:ne,configObject:V}=g.get(D[b]);return typeof V.nullable!="boolean"&&(V.nullable=$),typeof V.subscribe!="function"&&(V.subscribe=Xe),D[b]=ne.bind(y)(...j),E}let Ze={where:y.arg({type:v,required:false}),orderBy:y.arg({type:Y,required:false}),...w?{offset:y.arg.int({required:false}),limit:y.arg.int({required:false})}:{},search:y.arg.string({required:false})};return (!t?.enabled||!w)&&delete Ze.search,E[b]=y.relation(b,{args:Ze,subscribe:Xe,nullable:$,description:`Get the ${pluralize.plural(A.tsName)} related to this ${pluralize.singular(c.tsName)}`,query:(j,ne)=>{j=JSON.parse(JSON.stringify(j)),w&&Ie({search:t,args:j,tableSchema:A,abilities:ne.abilities[A.tsName].filter(a)});let V=ne.abilities[A.tsName].filter(a,{inject:{where:j.where,limit:j.limit}}).query[pe];return j.offset&&(V.offset=j.offset),j.orderBy&&(V.orderBy=j.orderBy),V}}),E},{});return {...R,...I,...D}}})};var jr=e=>`${esToolkit.capitalize(casing.toCamelCase(e.toString()))}OrderInputArgument`,Qt=({db:e,schemaBuilder:t})=>{let n=new Map,r=G(()=>t.enumType("SortingParameter",{values:["asc","desc"]})),o=({table:i,refName:s,dbName:l})=>{let u=_({db:e,dbName:l,tsName:i}),p=s??jr(u.tsName),a=n.get(p);return a||(a=t.inputType(p,{fields:c=>{let x=Object.entries(u.columns).reduce((y,[T])=>(y[T]=c.field({type:r(),required:false}),y),{}),h=Object.entries(u.relations??{}).reduce((y,[T,N])=>{let g=_({db:e,table:N.targetTable}),D=o({dbName:g.dbName});return y[T]=c.field({type:D,required:false}),y},{});return {...x,...h}}}),n.set(p,a),a)};return o};var _r="RUMBLE_SUBSCRIPTION_NOTIFICATION",Qr="REMOVED",kr="UPDATED",qr="CREATED",qt=({subscriptions:e})=>{let t=e?graphqlYoga.createPubSub(...e):graphqlYoga.createPubSub();return {pubsub:t,makePubSubInstance:({table:r})=>{function o({action:i,tableName:s,primaryKeyValue:l}){let u;switch(i){case "created":u=qr;break;case "removed":u=Qr;break;case "updated":u=kr;break;default:throw new Error(`Unknown action: ${i}`)}return `${_r}/${s}${l?`/${l}`:""}/${u}`}return {registerOnInstance({instance:i,action:s,primaryKeyValue:l}){let u=o({tableName:r.toString(),action:s,primaryKeyValue:l});i.register(u);},created(){let i=o({tableName:r.toString(),action:"created"});return t.publish(i)},removed(){let i=o({tableName:r.toString(),action:"removed"});return t.publish(i)},updated(i){let l=(Array.isArray(i)?i:[i]).map(p=>o({tableName:r.toString(),action:"updated",primaryKeyValue:p})),u=Array.from(new Set(l));for(let p of u)t.publish(p);}}}}};var Gt=({db:e,schemaBuilder:t,search:n,whereArgImplementer:r,orderArgImplementer:o,makePubSubInstance:i})=>({table:s,readAction:l="read",listAction:u="read"})=>{let p=r({table:s}),a=o({table:s}),m=_({db:e,tsName:s}),c=Object.values(m.primaryColumns)[0],{registerOnInstance:x}=i({table:s});return t.queryFields(h=>{let y={where:h.arg({type:p,required:false}),orderBy:h.arg({type:a,required:false}),limit:h.arg.int({required:false}),offset:h.arg.int({required:false}),search:h.arg.string({required:false})};return n?.enabled||delete y.search,{[pluralize.plural(s.toString())]:h.drizzleField({type:[s],nullable:false,smartSubscription:true,description:`List all ${pluralize.plural(s.toString())}`,subscribe:(T,N,g,D,R)=>{x({instance:T,action:"created"}),x({instance:T,action:"removed"});},args:y,resolve:(T,N,g,D,R)=>{g=JSON.parse(JSON.stringify(g)),Ie({search:n,args:g,tableSchema:m,abilities:D.abilities[s].filter(u)});let I=D.abilities[s].filter(u,g.where||g.limit||g.offset?{inject:{where:g.where,limit:g.limit}}:void 0).query.many;g.offset&&(I.offset=g.offset),g.orderBy&&(I.orderBy=g.orderBy);let E=T(I);return I.columns&&(E.columns=I.columns),e.query[s].findMany(E)}}),[pluralize.singular(s.toString())]:h.drizzleField({type:s,nullable:false,smartSubscription:true,description:`Get a single ${pluralize.singular(s.toString())} by ID`,args:{id:h.arg.id({required:true})},resolve:(T,N,g,D,R)=>{g=JSON.parse(JSON.stringify(g));let I=D.abilities[s].filter(l,{inject:{where:{[c.name]:g.id}}}).query.single,E=T(I);return I.columns&&(E.columns=I.columns),e.query[s].findFirst(E).then(Ke)}})}})};var Vt="ManualFiltersPlugin",Mt=Vt,$t="applyFilters",He=class extends zr.BasePlugin{wrapResolve(t,n){return async(r,o,i,s)=>{let l,u=n?.type;if(u.kind==="List"?l=u.type?.ref.currentConfig.pothosOptions[$t]:u.kind==="Object"&&(l=u.ref.currentConfig.pothosOptions[$t]),!l||!Array.isArray(l)||l.length===0)return t(r,o,i,s);let p=await t(r,o,i,s),a=Array.isArray(p)?p:[p],m=Array.isArray(l)?l:[l],c=await Ct({filters:m,entities:a,context:i});return Array.isArray(p)?c:c[0]??null}}};zr__default.default.registerPlugin(Vt,He);var Vr=e=>`${esToolkit.capitalize(casing.toCamelCase(e.toString()))}WhereInputArgument`,Wt=({db:e,schemaBuilder:t,enumImplementer:n})=>{let r=new Map,o=({table:i,refName:s,dbName:l})=>{let u=_({db:e,dbName:l,tsName:i}),p=s??Vr(u.tsName),a=r.get(p);return a||(a=t.inputType(p,{fields:c=>{let x=(T,N)=>{let g=Ce({sqlType:T,fieldName:N});switch(g){case "Int":return c.field({type:"IntWhereInputArgument"});case "String":return c.field({type:"StringWhereInputArgument"});case "Boolean":return c.boolean({required:false});case "Date":return c.field({type:"DateWhereInputArgument"});case "DateTime":return c.field({type:"DateWhereInputArgument"});case "Float":return c.field({type:"FloatWhereInputArgument"});case "ID":return c.id({required:false});case "JSON":return c.field({type:"JSON",required:false});default:throw new O(`Unsupported argument type ${g} for column ${T}`)}},h=Object.entries(u.columns).reduce((T,[N,g])=>{if(Ae(g)){let D=n({enumColumn:g});T[N]=c.field({type:D,required:false});}else T[N]=x(g.getSQLType(),N);return T},{}),y=Object.entries(u.relations??{}).reduce((T,[N,g])=>{let D=_({db:e,table:g.targetTable}),R=o({dbName:D.dbName});return T[N]=c.field({type:R,required:false}),T},{});return {...h,...y}}}),r.set(p,a),a)};return o};function Jt(e){let t=e.inputRef("IntWhereInputArgument").implement({fields:i=>({eq:i.int(),ne:i.int(),gt:i.int(),gte:i.int(),lt:i.int(),lte:i.int(),in:i.intList(),notIn:i.intList(),like:i.string(),ilike:i.string(),notLike:i.string(),notIlike:i.string(),isNull:i.boolean(),isNotNull:i.boolean(),arrayOverlaps:i.intList(),arrayContained:i.intList(),arrayContains:i.intList(),AND:i.field({type:[t]}),OR:i.field({type:[t]}),NOT:i.field({type:t})})}),n=e.inputRef("FloatWhereInputArgument").implement({fields:i=>({eq:i.float(),ne:i.float(),gt:i.float(),gte:i.float(),lt:i.float(),lte:i.float(),in:i.floatList(),notIn:i.floatList(),like:i.string(),ilike:i.string(),notLike:i.string(),notIlike:i.string(),isNull:i.boolean(),isNotNull:i.boolean(),arrayOverlaps:i.floatList(),arrayContained:i.floatList(),arrayContains:i.floatList(),AND:i.field({type:[n]}),OR:i.field({type:[n]}),NOT:i.field({type:n})})}),r=e.inputRef("StringWhereInputArgument").implement({fields:i=>({eq:i.string(),ne:i.string(),gt:i.string(),gte:i.string(),lt:i.string(),lte:i.string(),in:i.stringList(),notIn:i.stringList(),like:i.string(),ilike:i.string(),notLike:i.string(),notIlike:i.string(),isNull:i.boolean(),isNotNull:i.boolean(),arrayOverlaps:i.stringList(),arrayContained:i.stringList(),arrayContains:i.stringList(),AND:i.field({type:[r]}),OR:i.field({type:[r]}),NOT:i.field({type:r})})}),o=e.inputRef("DateWhereInputArgument").implement({fields:i=>({eq:i.field({type:"Date"}),ne:i.field({type:"Date"}),gt:i.field({type:"Date"}),gte:i.field({type:"Date"}),lt:i.field({type:"Date"}),lte:i.field({type:"Date"}),in:i.field({type:["Date"]}),notIn:i.field({type:["Date"]}),like:i.string(),ilike:i.string(),notLike:i.string(),notIlike:i.string(),isNull:i.boolean(),isNotNull:i.boolean(),arrayOverlaps:i.field({type:["Date"]}),arrayContained:i.field({type:["Date"]}),arrayContains:i.field({type:["Date"]}),AND:i.field({type:[o]}),OR:i.field({type:[o]}),NOT:i.field({type:o})})});}var Kt=({db:e,disableDefaultObjects:t,pubsub:n,pothosConfig:r})=>{let o=new zr__default.default({...r,plugins:[Mt,Wr__default.default,Jr__default.default,...r?.plugins??[]],drizzle:{client:e,relations:e._.relations,getTableConfig(i){return {columns:Object.values(i[Symbol.for("drizzle:Columns")]),primaryKeys:Object.values(i[Symbol.for("drizzle:Columns")]).filter(s=>s.primary)}}},smartSubscriptions:{...Jr.subscribeOptionsFromIterator((i,s)=>n.subscribe(i))}});return o.addScalarType("JSON",graphqlScalars.JSONResolver),o.addScalarType("Date",graphqlScalars.DateResolver),o.addScalarType("DateTime",graphqlScalars.DateTimeISOResolver),Jt(o),t?.query||o.queryType({}),t?.subscription||o.subscriptionType({}),t?.mutation||o.mutationType({}),{schemaBuilder:o}};var ii=e=>{e.actions||(e.actions=["read","update","delete"]),e.defaultLimit===void 0&&(e.defaultLimit=100),e.search?.enabled&&jt(e.db);let t=vt(e),n=Lt({...e,abilityBuilder:t}),{makePubSubInstance:r,pubsub:o}=qt({...e}),{schemaBuilder:i}=Kt({...e,pubsub:o}),s=Bt({...e,schemaBuilder:i}),l=Wt({...e,schemaBuilder:i,enumImplementer:s}),u=Qt({...e,schemaBuilder:i}),p=_t({...e,schemaBuilder:i,makePubSubInstance:r,whereArgImplementer:l,orderArgImplementer:u,enumImplementer:s,abilityBuilder:t}),a=Gt({...e,schemaBuilder:i,whereArgImplementer:l,orderArgImplementer:u,makePubSubInstance:r}),m=G(()=>i.toSchema()),c=y=>{let T=y?.enableApiDocs??process?.env?.NODE_ENV==="development"??false;return graphqlYoga.createYoga({...y,graphiql:T,plugins:[...y?.plugins??[],...T?[]:[pluginDisableIntrospection.useDisableIntrospection(),graphqlArmor.EnvelopArmorPlugin()]].filter(Boolean),schema:m(),context:n})},x=y=>(y.openAPI&&esToolkit.merge(y.openAPI,wt),sofaApi.useSofa({...y,schema:m(),context:n})),h=Ot({...e,builtSchema:m});return {abilityBuilder:t,schemaBuilder:i,createYoga:c,createSofa:x,object:p,whereArg:l,orderArg:u,query:a,pubsub:r,enum_:s,clientCreator:h}};exports.RumbleError=O;exports.RumbleErrorSafe=te;exports.assertFindFirstExists=Ke;exports.assertFirstEntryExists=yr;exports.generateFromSchema=Me;exports.makeLiveQuery=cr;exports.makeMutation=mr;exports.makeQuery=fr;exports.makeSubscription=dr;exports.mapNullFieldsToUndefined=hr;exports.rumble=ii;//# sourceMappingURL=index.cjs.map
|
|
109
|
+
`);},1e3),Vt=({db:e,actions:t,defaultLimit:n})=>{let r={},s={},i={},o=l=>{for(let u of t)i[l]||(i[l]={}),i[l][u]||(i[l][u]=[]);return {allow:u=>{let p=s[l];p||(p={},s[l]=p);let a=Array.isArray(u)?u:[u];for(let m of a){let c=p[m];c||(c="unspecified",p[m]=c);}return {when:m=>{for(let c of a)p[c]==="unspecified"&&(p[c]=[]),p[c].push(m);}}},filter:u=>{let p=Array.isArray(u)?u:[u];return {by:a=>{for(let m of p)i[l][m].push(a);}}}}};for(let l of Object.keys(e.query))r[l]=o(l);return {...r,z_registeredQueryFilters:s,z_registeredFilters:i,z_buildWithUserContext:l=>{let u={},p=a=>({filter:(m,c)=>{let x=h=>{let A=G(()=>{if(!(!h?.where&&!c?.inject?.where)){if(c?.inject?.where&&h?.where)return {AND:[h?.where,c?.inject?.where]};if(c?.inject?.where&&!h?.where)return c?.inject?.where;if(!c?.inject?.where&&h?.where)return h?.where;!c?.inject?.where&&h?.where;}}),v=G(()=>{let k=A();if(!k)return;let pe=Q({tsName:a,db:e});return drizzleOrm.relationsFilterToSQL(pe.tableSchema,k)}),H=G(()=>{let k=h?.limit??n;return c?.inject?.limit&&(!k||k>c.inject.limit)&&(k=c.inject.limit),k??void 0}),X=G(()=>{if(!(!h?.columns&&!c?.inject?.columns))return {...h?.columns,...c?.inject?.columns}}),K={query:{single:{get where(){return A()},columns:X()},many:{get where(){return A()},columns:X(),get limit(){return H()}}},sql:{get where(){return v()}}};return X()||(delete K.query.many.columns,delete K.query.single.columns),K},d=()=>{let h=Q({db:e,tsName:a});if(Object.keys(h.primaryColumns).length===0)throw new L(`No primary key found for entity ${a.toString()}`);let A=Object.values(h.primaryColumns)[0],v=Gt(A.getSQLType());return {where:{AND:[{[A.name]:v.value1},{[A.name]:v.value2}]}}},y=s?.[a]?.[m];if(y==="unspecified")return x();y||(kr(a.toString(),m),y=[d()]);let T=y.filter(Pr),N=y.filter(Qr).map(h=>h(l)),g=N.some(h=>h==="allow"),D=[...T,...N].filter(h=>h!==void 0).filter(h=>h!=="allow");!g&&D.length===0&&(D=[d()]);let R;for(let h of D)h?.limit&&(R===void 0||h.limit>R)&&(R=h.limit);let I;for(let h of [...D,c?.inject])h?.columns&&(I===void 0?I=h.columns:I={...I,...h.columns});let E=g?[]:D.filter(h=>h?.where).map(h=>h.where),b=E.length>0?{OR:E}:void 0;return x({where:b,columns:I,limit:R})},runtimeFilters:m=>i[a][m]});for(let a of Object.keys(e.query))u[a]=p(a);return u}}};var Mt=({builtSchema:e})=>(process.env.NODE_ENV!=="development"&&console.warn("Running rumble client generation in non development mode. Are you sure this is correct?"),async({apiUrl:n,outputPath:r,rumbleImportPath:s,useExternalUrqlClient:i})=>{let o=e();await et({schema:o,outputPath:r,rumbleImportPath:s,apiUrl:n,useExternalUrqlClient:i});});var Wt=({context:e,abilityBuilder:t})=>async n=>{let r=e?await e(n):{};return {...r,abilities:t.z_buildWithUserContext(r)}};function we(e){return e instanceof pgCore.PgEnumColumn}var Jt=({db:e,schemaBuilder:t})=>{let n=new Map;return ({tsName:s,enumColumn:i,refName:o})=>{let l,u;if(s){let c=e._.relations.schema[s];l=s.toString();let x=Object.values(e._.relations.schema).filter(d=>typeof d=="object").map(d=>Object.values(d[Symbol.for("drizzle:Columns")])).flat(2).find(d=>d.config?.enum===c);if(!x)throw new L(`Could not find applied enum column for ${s.toString()}.
|
|
110
|
+
Please ensure that you use the enum at least once as a column of a table!`);u=x.enumValues;}else if(i){let c=Object.entries(e._.relations.schema).find(([,x])=>x===i.config.enum);if(!c)throw new L(`Could not find enum in schema for ${i.name}!`);l=c[0],u=i.enumValues;}if(!l||!u)throw new L("Could not determine enum structure!");let p=o??`${esToolkit.capitalize(casing.toCamelCase(l))}Enum`,a=n.get(p);return a||(a=t.enumType(p,{values:u}),n.set(p,a),a)}};var Kt={paths:{"/webhook":{post:{operationId:"webhook_create",description:"Creates a webhook subscription.",tags:[],parameters:[],requestBody:{content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookCreateBody"}}}},responses:{200:{description:"",content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookDetailResponse"}}}}}}},"/webhook/{id}":{post:{operationId:"webhook_update",description:"Updates a webhook subscription.",parameters:[{name:"id",in:"path",description:"The ID of the webhook to update",required:true,schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookCreateBody"}}}},responses:{200:{description:"",content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookDetailResponse"}}}}}},delete:{operationId:"webhook_delete",description:"Removes a webhook subscription.",tags:[],parameters:[{name:"id",in:"path",description:"The ID of the webhook to delete",required:true,schema:{type:"string"}}],responses:{200:{description:"",content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookDetailResponse"}}}}}}}},components:{schemas:{WebhookCreateBody:{type:"object",properties:{subscription:{description:"The subscription to subscribe to. In many cases, these match the available query IDs without the '_query' suffix. E.g., 'findFirstUser_query' -> 'findFirstUser'. See the graphql schema for more details on what subscriptions are available.",type:"string"},variables:{description:"The variables to pass to the subscription.",type:"object"},url:{description:"The URL to send the webhook to.",type:"string"}}},WebhookDetailResponse:{type:"object",properties:{id:{description:"The ID of the webhook. Can be used as reference in update or delete calls.",type:"string"}}},DateTime:{type:"string",format:"date-time"},Date:{type:"string",format:"date"}}}};function Fe({sqlType:e,fieldName:t}){let n;if(Ee(e)&&(n="Int"),Ae(e)&&(n="Float"),Ce(e)&&(t&&(t.toLowerCase().endsWith("_id")||t.toLowerCase().endsWith("id"))?n="ID":n="String"),Ie(e)&&(n="ID"),Re(e)&&(n="Boolean"),ve(e)&&(n="DateTime"),Le(e)&&(n="Date"),Oe(e)&&(n="JSON"),n!==void 0)return n;throw Be(e,"SQL to GQL")}function $r(e){let t=new Set;for(let r of Object.values(e))typeof r=="object"&&(r instanceof pgCore.PgTable?t.add("postgres"):r instanceof mysqlCore.MySqlTable?t.add("mysql"):r instanceof sqliteCore.SQLiteTable&&t.add("sqlite"));let n=Array.from(t);if(n.length===1)return n[0];throw n.length===0?new Error("No tables found in schema, could not determine dialect"):new Error(`Multiple dialects found in schema: ${n.join(", ")}`)}function Yt(e){return $r(e._.relations.schema)==="postgres"}async function Xt(e){if(!Yt(e)){console.info("Database dialect is not compatible with search, skipping search initialization.");return}await e.execute(drizzleOrm.sql`CREATE EXTENSION IF NOT EXISTS pg_trgm;`);}function Pe({search:e,args:t,tableSchema:n,abilities:r}){if(e?.enabled&&t.search&&t.search.length>0){let s=esToolkit.cloneDeep(t.orderBy);t.orderBy=o=>{let l=drizzleOrm.sql.join(Object.entries(s??{}).map(([m,c])=>{if(c==="asc")return drizzleOrm.sql`${o[m]} ASC`;if(c==="desc")return drizzleOrm.sql`${o[m]} DESC`;throw new Error(`Invalid value ${c} for orderBy`)}),drizzleOrm.sql.raw(", ")),u=r.query.many.columns?Object.entries(n.columns).filter(([m])=>r.query.many.columns[m]):Object.entries(n.columns),p=drizzleOrm.sql`GREATEST(${drizzleOrm.sql.join(u.map(([m])=>drizzleOrm.sql`similarity(${o[m]}::TEXT, ${t.search})`),drizzleOrm.sql.raw(", "))}) DESC`;return s?drizzleOrm.sql.join([l,p],drizzleOrm.sql.raw(", ")):p};let i=esToolkit.cloneDeep(t.where);t.where={AND:[i??{},{RAW:o=>drizzleOrm.sql`GREATEST(${drizzleOrm.sql.join(Object.entries(n.columns).map(([l])=>drizzleOrm.sql`similarity(${o[l]}::TEXT, ${t.search})`),drizzleOrm.sql.raw(", "))}) > ${e.threshold??.1}`}]};}}var Kr=e=>typeof e!="object"?false:!!Object.keys(e).some(t=>["args","nullable","query","subscribe","description","type","resolve"].find(n=>n===t)),Zt=({db:e,search:t,schemaBuilder:n,makePubSubInstance:r,whereArgImplementer:s,orderArgImplementer:i,enumImplementer:o,abilityBuilder:l})=>({table:u,refName:p,readAction:a="read",adjust:m})=>{let c=Q({db:e,tsName:u});Object.keys(c.primaryColumns).length===0&&console.warn(`Could not find primary key for ${u.toString()}. Cannot register subscriptions!`);let x=Object.values(c.primaryColumns)[0],{registerOnInstance:d}=r({table:u});return n.drizzleObject(u,{name:p??esToolkit.capitalize(u.toString()),subscribe:(y,T,N)=>{if(!x)return;let g=T[x.name];if(!g){console.warn(`Could not find primary key value for ${JSON.stringify(T)}. Cannot register subscription!`);return}d({instance:y,action:"updated",primaryKeyValue:g});},applyFilters:l?.z_registeredFilters?.[u]?.[a],fields:y=>{let T=c.columns,N=(E,b,h)=>{let A=Fe({sqlType:E,fieldName:b});switch(A){case "Int":return y.exposeInt(b,{nullable:h});case "String":return y.exposeString(b,{nullable:h});case "Boolean":return y.exposeBoolean(b,{nullable:h});case "Date":return y.field({type:"Date",resolve:v=>v[b],nullable:h});case "DateTime":return y.field({type:"DateTime",resolve:v=>v[b],nullable:h});case "Float":return y.exposeFloat(b,{nullable:h});case "ID":return y.exposeID(b,{nullable:h});case "JSON":return y.field({type:"JSON",resolve:v=>v[b],nullable:h});default:throw new L(`Unsupported object type ${A} for column ${b}`)}},g=new Map,D=m?.(new Proxy(y,{get:(E,b)=>typeof E[b]!="function"||b==="arg"||b==="builder"||b==="graphqlKind"||b==="kind"||b==="listRef"||b==="table"||b==="typename"||b==="variant"||b.toString().startsWith("boolean")||b.toString().startsWith("float")||b.toString().startsWith("id")||b.toString().startsWith("int")||b.toString().startsWith("string")||b.toString().startsWith("expose")?E[b]:(...h)=>{let A=E[b](...h),v=h.find(Kr);if(!v)throw new L("Expected config object to be passed to adjust field");return g.set(A,{params:h,creatorFunction:E[b],configObject:v}),A}}))??{},R=Object.entries(T).reduce((E,[b,h])=>{if(D[b]){let{params:A,creatorFunction:v,configObject:H}=g.get(D[b]);return typeof H.nullable!="boolean"&&(H.nullable=!h.notNull),D[b]=v.bind(y)(...A),E}if(we(h)){let A=o({enumColumn:h});E[b]=y.field({type:A,resolve:v=>v[b],nullable:!h.notNull});}else E[b]=N(h.getSQLType(),b,!h.notNull);return E},{}),I=Object.entries(c.relations??{}).reduce((E,[b,h])=>{let A=Q({db:e,table:h.targetTable}),v=s({dbName:A.dbName}),H=i({dbName:A.dbName}),X=r({table:A.tsName}),K=false,k=true,pe="many";h instanceof drizzleOrm.One&&(k=false,K=h.optional,pe="single");let ot=(P,ne)=>{X.registerOnInstance({instance:P,action:"created"}),X.registerOnInstance({instance:P,action:"removed"});};if(D[b]){let{params:P,creatorFunction:ne,configObject:$}=g.get(D[b]);return typeof $.nullable!="boolean"&&($.nullable=K),typeof $.subscribe!="function"&&($.subscribe=ot),D[b]=ne.bind(y)(...P),E}let at={where:y.arg({type:v,required:false}),orderBy:y.arg({type:H,required:false}),...k?{offset:y.arg.int({required:false}),limit:y.arg.int({required:false})}:{},search:y.arg.string({required:false})};return (!t?.enabled||!k)&&delete at.search,E[b]=y.relation(b,{args:at,subscribe:ot,nullable:K,description:`Get the ${pluralize.plural(A.tsName)} related to this ${pluralize.singular(c.tsName)}`,query:(P,ne)=>{P=JSON.parse(JSON.stringify(P)),k&&Pe({search:t,args:P,tableSchema:A,abilities:ne.abilities[A.tsName].filter(a)});let $=ne.abilities[A.tsName].filter(a,{inject:{where:P.where,limit:P.limit}}).query[pe];return P.offset&&($.offset=P.offset),P.orderBy&&($.orderBy=P.orderBy),$}}),E},{});return {...R,...I,...D}}})};var Xr=e=>`${esToolkit.capitalize(casing.toCamelCase(e.toString()))}OrderInputArgument`,en=({db:e,schemaBuilder:t})=>{let n=new Map,r=G(()=>t.enumType("SortingParameter",{values:["asc","desc"]})),s=({table:i,refName:o,dbName:l})=>{let u=Q({db:e,dbName:l,tsName:i}),p=o??Xr(u.tsName),a=n.get(p);return a||(a=t.inputType(p,{fields:c=>{let x=Object.entries(u.columns).reduce((y,[T])=>(y[T]=c.field({type:r(),required:false}),y),{}),d=Object.entries(u.relations??{}).reduce((y,[T,N])=>{let g=Q({db:e,table:N.targetTable}),D=s({dbName:g.dbName});return y[T]=c.field({type:D,required:false}),y},{});return {...x,...d}}}),n.set(p,a),a)};return s};var Zr="RUMBLE_SUBSCRIPTION_NOTIFICATION",ei="REMOVED",ti="UPDATED",ni="CREATED",nn=({subscriptions:e})=>{let t=e?graphqlYoga.createPubSub(...e):graphqlYoga.createPubSub();return {pubsub:t,makePubSubInstance:({table:r})=>{function s({action:i,tableName:o,primaryKeyValue:l}){let u;switch(i){case "created":u=ni;break;case "removed":u=ei;break;case "updated":u=ti;break;default:throw new Error(`Unknown action: ${i}`)}return `${Zr}/${o}${l?`/${l}`:""}/${u}`}return {registerOnInstance({instance:i,action:o,primaryKeyValue:l}){let u=s({tableName:r.toString(),action:o,primaryKeyValue:l});i.register(u);},created(){let i=s({tableName:r.toString(),action:"created"});return t.publish(i)},removed(){let i=s({tableName:r.toString(),action:"removed"});return t.publish(i)},updated(i){let l=(Array.isArray(i)?i:[i]).map(p=>s({tableName:r.toString(),action:"updated",primaryKeyValue:p})),u=Array.from(new Set(l));for(let p of u)t.publish(p);}}}}};var on=({db:e,schemaBuilder:t,search:n,whereArgImplementer:r,orderArgImplementer:s,makePubSubInstance:i})=>({table:o,readAction:l="read",listAction:u="read"})=>{let p=r({table:o}),a=s({table:o}),m=Q({db:e,tsName:o}),c=Object.values(m.primaryColumns)[0],{registerOnInstance:x}=i({table:o});return t.queryFields(d=>{let y={where:d.arg({type:p,required:false}),orderBy:d.arg({type:a,required:false}),limit:d.arg.int({required:false}),offset:d.arg.int({required:false}),search:d.arg.string({required:false})};return n?.enabled||delete y.search,{[pluralize.plural(o.toString())]:d.drizzleField({type:[o],nullable:false,smartSubscription:true,description:`List all ${pluralize.plural(o.toString())}`,subscribe:(T,N,g,D,R)=>{x({instance:T,action:"created"}),x({instance:T,action:"removed"});},args:y,resolve:(T,N,g,D,R)=>{g=JSON.parse(JSON.stringify(g)),Pe({search:n,args:g,tableSchema:m,abilities:D.abilities[o].filter(u)});let I=D.abilities[o].filter(u,g.where||g.limit||g.offset?{inject:{where:g.where,limit:g.limit}}:void 0).query.many;g.offset&&(I.offset=g.offset),g.orderBy&&(I.orderBy=g.orderBy);let E=T(I);return I.columns&&(E.columns=I.columns),e.query[o].findMany(E)}}),[pluralize.singular(o.toString())]:d.drizzleField({type:o,nullable:false,smartSubscription:true,description:`Get a single ${pluralize.singular(o.toString())} by ID`,args:{id:d.arg.id({required:true})},resolve:(T,N,g,D,R)=>{g=JSON.parse(JSON.stringify(g));let I=D.abilities[o].filter(l,{inject:{where:{[c.name]:g.id}}}).query.single,E=T(I);return I.columns&&(E.columns=I.columns),e.query[o].findFirst(E).then(rt)}})}})};var ln="ManualFiltersPlugin",un=ln,an="applyFilters",st=class extends ri.BasePlugin{wrapResolve(t,n){return async(r,s,i,o)=>{let l,u=n?.type;if(u.kind==="List"?l=u.type?.ref.currentConfig.pothosOptions[an]:u.kind==="Object"&&(l=u.ref.currentConfig.pothosOptions[an]),!l||!Array.isArray(l)||l.length===0)return t(r,s,i,o);let p=await t(r,s,i,o),a=Array.isArray(p)?p:[p],m=Array.isArray(l)?l:[l],c=await Ft({filters:m,entities:a,context:i});return Array.isArray(p)?c:c[0]??null}}};ri__default.default.registerPlugin(ln,st);var ai=e=>`${esToolkit.capitalize(casing.toCamelCase(e.toString()))}WhereInputArgument`,pn=({db:e,schemaBuilder:t,enumImplementer:n})=>{let r=new Map,s=({table:i,refName:o,dbName:l})=>{let u=Q({db:e,dbName:l,tsName:i}),p=o??ai(u.tsName),a=r.get(p);return a||(a=t.inputType(p,{fields:c=>{let x=(T,N)=>{let g=Fe({sqlType:T,fieldName:N});switch(g){case "Int":return c.field({type:"IntWhereInputArgument"});case "String":return c.field({type:"StringWhereInputArgument"});case "Boolean":return c.boolean({required:false});case "Date":return c.field({type:"DateWhereInputArgument"});case "DateTime":return c.field({type:"DateWhereInputArgument"});case "Float":return c.field({type:"FloatWhereInputArgument"});case "ID":return c.id({required:false});case "JSON":return c.field({type:"JSON",required:false});default:throw new L(`Unsupported argument type ${g} for column ${T}`)}},d=Object.entries(u.columns).reduce((T,[N,g])=>{if(we(g)){let D=n({enumColumn:g});T[N]=c.field({type:D,required:false});}else T[N]=x(g.getSQLType(),N);return T},{}),y=Object.entries(u.relations??{}).reduce((T,[N,g])=>{let D=Q({db:e,table:g.targetTable}),R=s({dbName:D.dbName});return T[N]=c.field({type:R,required:false}),T},{});return {...d,...y}}}),r.set(p,a),a)};return s};function cn(e){let t=e.inputRef("IntWhereInputArgument").implement({fields:i=>({eq:i.int(),ne:i.int(),gt:i.int(),gte:i.int(),lt:i.int(),lte:i.int(),in:i.intList(),notIn:i.intList(),like:i.string(),ilike:i.string(),notLike:i.string(),notIlike:i.string(),isNull:i.boolean(),isNotNull:i.boolean(),arrayOverlaps:i.intList(),arrayContained:i.intList(),arrayContains:i.intList(),AND:i.field({type:[t]}),OR:i.field({type:[t]}),NOT:i.field({type:t})})}),n=e.inputRef("FloatWhereInputArgument").implement({fields:i=>({eq:i.float(),ne:i.float(),gt:i.float(),gte:i.float(),lt:i.float(),lte:i.float(),in:i.floatList(),notIn:i.floatList(),like:i.string(),ilike:i.string(),notLike:i.string(),notIlike:i.string(),isNull:i.boolean(),isNotNull:i.boolean(),arrayOverlaps:i.floatList(),arrayContained:i.floatList(),arrayContains:i.floatList(),AND:i.field({type:[n]}),OR:i.field({type:[n]}),NOT:i.field({type:n})})}),r=e.inputRef("StringWhereInputArgument").implement({fields:i=>({eq:i.string(),ne:i.string(),gt:i.string(),gte:i.string(),lt:i.string(),lte:i.string(),in:i.stringList(),notIn:i.stringList(),like:i.string(),ilike:i.string(),notLike:i.string(),notIlike:i.string(),isNull:i.boolean(),isNotNull:i.boolean(),arrayOverlaps:i.stringList(),arrayContained:i.stringList(),arrayContains:i.stringList(),AND:i.field({type:[r]}),OR:i.field({type:[r]}),NOT:i.field({type:r})})}),s=e.inputRef("DateWhereInputArgument").implement({fields:i=>({eq:i.field({type:"Date"}),ne:i.field({type:"Date"}),gt:i.field({type:"Date"}),gte:i.field({type:"Date"}),lt:i.field({type:"Date"}),lte:i.field({type:"Date"}),in:i.field({type:["Date"]}),notIn:i.field({type:["Date"]}),like:i.string(),ilike:i.string(),notLike:i.string(),notIlike:i.string(),isNull:i.boolean(),isNotNull:i.boolean(),arrayOverlaps:i.field({type:["Date"]}),arrayContained:i.field({type:["Date"]}),arrayContains:i.field({type:["Date"]}),AND:i.field({type:[s]}),OR:i.field({type:[s]}),NOT:i.field({type:s})})});}var mn=({db:e,disableDefaultObjects:t,pubsub:n,pothosConfig:r})=>{let s=new ri__default.default({...r,plugins:[un,ui__default.default,pi__default.default,...r?.plugins??[]],drizzle:{client:e,relations:e._.relations,getTableConfig(i){return {columns:Object.values(i[Symbol.for("drizzle:Columns")]),primaryKeys:Object.values(i[Symbol.for("drizzle:Columns")]).filter(o=>o.primary)}}},smartSubscriptions:{...pi.subscribeOptionsFromIterator((i,o)=>n.subscribe(i))}});return s.addScalarType("JSON",graphqlScalars.JSONResolver),s.addScalarType("Date",graphqlScalars.DateResolver),s.addScalarType("DateTime",graphqlScalars.DateTimeISOResolver),cn(s),t?.query||s.queryType({}),t?.subscription||s.subscriptionType({}),t?.mutation||s.mutationType({}),{schemaBuilder:s}};var xi=e=>{e.actions||(e.actions=["read","update","delete"]),e.defaultLimit===void 0&&(e.defaultLimit=100),e.search?.enabled&&Xt(e.db);let t=Vt(e),n=Wt({...e,abilityBuilder:t}),{makePubSubInstance:r,pubsub:s}=nn({...e}),{schemaBuilder:i}=mn({...e,pubsub:s}),o=Jt({...e,schemaBuilder:i}),l=pn({...e,schemaBuilder:i,enumImplementer:o}),u=en({...e,schemaBuilder:i}),p=Zt({...e,schemaBuilder:i,makePubSubInstance:r,whereArgImplementer:l,orderArgImplementer:u,enumImplementer:o,abilityBuilder:t}),a=on({...e,schemaBuilder:i,whereArgImplementer:l,orderArgImplementer:u,makePubSubInstance:r}),m=G(()=>i.toSchema()),c=y=>{let T=y?.enableApiDocs??process?.env?.NODE_ENV==="development"??false;return graphqlYoga.createYoga({...y,graphiql:T,plugins:[...y?.plugins??[],...T?[]:[pluginDisableIntrospection.useDisableIntrospection(),graphqlArmor.EnvelopArmorPlugin()]].filter(Boolean),schema:m(),context:n})},x=y=>(y.openAPI&&esToolkit.merge(y.openAPI,Kt),sofaApi.useSofa({...y,schema:m(),context:n})),d=Mt({...e,builtSchema:m});return {abilityBuilder:t,schemaBuilder:i,createYoga:c,createSofa:x,object:p,whereArg:l,orderArg:u,query:a,pubsub:r,enum_:o,clientCreator:d}};exports.RumbleError=L;exports.RumbleErrorSafe=te;exports.assertFindFirstExists=rt;exports.assertFirstEntryExists=Or;exports.generateFromSchema=et;exports.makeLiveQuery=Ir;exports.makeMutation=Rr;exports.makeQuery=vr;exports.makeSubscription=Lr;exports.mapNullFieldsToUndefined=Br;exports.rumble=xi;//# sourceMappingURL=index.cjs.map
|
|
111
111
|
//# sourceMappingURL=index.cjs.map
|