@m1212e/rumble 0.8.2 → 0.8.4

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/index.d.cts CHANGED
@@ -5,9 +5,11 @@ import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
5
5
  import { PgEnum } from 'drizzle-orm/pg-core';
6
6
  import * as _pothos_plugin_drizzle from '@pothos/plugin-drizzle';
7
7
  import { DrizzleClient } from '@pothos/plugin-drizzle';
8
+ import * as fets from 'fets';
8
9
  import * as graphql_yoga from 'graphql-yoga';
9
10
  import { createPubSub, YogaServerOptions } from 'graphql-yoga';
10
11
  import * as drizzle_orm from 'drizzle-orm';
12
+ import { useSofa } from 'sofa-api';
11
13
 
12
14
  declare const pluginName = "ManualFiltersPlugin";
13
15
 
@@ -336,14 +338,31 @@ declare const rumble: <UserContext extends Record<string, any>, DB extends Gener
336
338
  * @example
337
339
  *
338
340
  * ```ts
341
+ *
339
342
  import { createServer } from "node:http";
340
- * const server = createServer(createYoga());
341
- server.listen(3000, () => {
343
+ * const server = createServer(createYoga());
344
+ server.listen(3000, () => {
342
345
  console.info("Visit http://localhost:3000/graphql");
343
- });
344
- * ```
346
+ });
347
+ * ```
348
+ * https://the-guild.dev/graphql/yoga-server/docs#server
345
349
  */
346
350
  createYoga: (args?: Omit<YogaServerOptions<RequestEvent, any>, "schema" | "context"> | undefined) => graphql_yoga.YogaServerInstance<RequestEvent, {}>;
351
+ /**
352
+ * Creates a sofa instance to offer a REST API.
353
+ ```ts
354
+ import express from 'express';
355
+
356
+ const app = express();
357
+ const sofa = createSofa(...);
358
+
359
+ app.use('/api', useSofa({ schema }));
360
+ ```
361
+ * https://the-guild.dev/graphql/sofa-api/docs#usage
362
+ */
363
+ createSofa: (args: Omit<Parameters<typeof useSofa>[0], "schema" | "context">) => fets.Router<any, {}, {
364
+ [TKey: string]: never;
365
+ }>;
347
366
  /**
348
367
  * A function for creating default objects for your schema
349
368
  */
package/index.d.ts CHANGED
@@ -5,9 +5,11 @@ import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
5
5
  import { PgEnum } from 'drizzle-orm/pg-core';
6
6
  import * as _pothos_plugin_drizzle from '@pothos/plugin-drizzle';
7
7
  import { DrizzleClient } from '@pothos/plugin-drizzle';
8
+ import * as fets from 'fets';
8
9
  import * as graphql_yoga from 'graphql-yoga';
9
10
  import { createPubSub, YogaServerOptions } from 'graphql-yoga';
10
11
  import * as drizzle_orm from 'drizzle-orm';
12
+ import { useSofa } from 'sofa-api';
11
13
 
12
14
  declare const pluginName = "ManualFiltersPlugin";
13
15
 
@@ -336,14 +338,31 @@ declare const rumble: <UserContext extends Record<string, any>, DB extends Gener
336
338
  * @example
337
339
  *
338
340
  * ```ts
341
+ *
339
342
  import { createServer } from "node:http";
340
- * const server = createServer(createYoga());
341
- server.listen(3000, () => {
343
+ * const server = createServer(createYoga());
344
+ server.listen(3000, () => {
342
345
  console.info("Visit http://localhost:3000/graphql");
343
- });
344
- * ```
346
+ });
347
+ * ```
348
+ * https://the-guild.dev/graphql/yoga-server/docs#server
345
349
  */
346
350
  createYoga: (args?: Omit<YogaServerOptions<RequestEvent, any>, "schema" | "context"> | undefined) => graphql_yoga.YogaServerInstance<RequestEvent, {}>;
351
+ /**
352
+ * Creates a sofa instance to offer a REST API.
353
+ ```ts
354
+ import express from 'express';
355
+
356
+ const app = express();
357
+ const sofa = createSofa(...);
358
+
359
+ app.use('/api', useSofa({ schema }));
360
+ ```
361
+ * https://the-guild.dev/graphql/sofa-api/docs#usage
362
+ */
363
+ createSofa: (args: Omit<Parameters<typeof useSofa>[0], "schema" | "context">) => fets.Router<any, {}, {
364
+ [TKey: string]: never;
365
+ }>;
347
366
  /**
348
367
  * A function for creating default objects for your schema
349
368
  */
package/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import {createYoga,createPubSub}from'graphql-yoga';import {One,relationsFilterToSQL}from'drizzle-orm';import {toCamelCase}from'drizzle-orm/casing';import {PgEnumColumn}from'drizzle-orm/pg-core';import Be,{BasePlugin}from'@pothos/core';import Le from'@pothos/plugin-drizzle';import qe,{subscribeOptionsFromIterator}from'@pothos/plugin-smart-subscriptions';import {JSONResolver,DateResolver,DateTimeISOResolver}from'graphql-scalars';function M(t){return typeof t=="object"&&t!==null}function $(t,n){throw new Error("Unexpected invariant triggered.")}var ye=/\r\n|[\n\r]/g;function k(t,n){let o=0,u=1;for(let r of t.body.matchAll(ye)){if(typeof r.index=="number"||$(),r.index>=n)break;o=r.index+r[0].length,u+=1;}return {line:u,column:n+1-o}}function H(t){return W(t.source,k(t.source,t.start))}function W(t,n){let o=t.locationOffset.column-1,u="".padStart(o)+t.body,r=n.line-1,e=t.locationOffset.line-1,a=n.line+e,p=n.line===1?o:0,l=n.column+p,c=`${t.name}:${a}:${l}
2
- `,s=u.split(/\r\n|[\n\r]/g),g=s[r];if(g.length>120){let i=Math.floor(l/80),y=l%80,d=[];for(let b=0;b<g.length;b+=80)d.push(g.slice(b,b+80));return c+J([[`${a} |`,d[0]],...d.slice(1,i+1).map(b=>["|",b]),["|","^".padStart(y)],["|",d[i+1]]])}return c+J([[`${a-1} |`,s[r-1]],[`${a} |`,g],["|","^".padStart(l)],[`${a+1} |`,s[r+1]]])}function J(t){let n=t.filter(([u,r])=>r!==void 0),o=Math.max(...n.map(([u])=>u.length));return n.map(([u,r])=>u.padStart(o)+(r?" "+r:"")).join(`
3
- `)}function de(t){let n=t[0];return n==null||"kind"in n||"length"in n?{nodes:n,source:t[1],positions:t[2],path:t[3],originalError:t[4],extensions:t[5]}:n}var L=class t extends Error{constructor(n,...o){var u,r,e;let{nodes:a,source:p,positions:l,path:c,originalError:s,extensions:g}=de(o);super(n),this.name="GraphQLError",this.path=c??void 0,this.originalError=s??void 0,this.nodes=Y(Array.isArray(a)?a:a?[a]:void 0);let i=Y((u=this.nodes)===null||u===void 0?void 0:u.map(d=>d.loc).filter(d=>d!=null));this.source=p??(i==null||(r=i[0])===null||r===void 0?void 0:r.source),this.positions=l??i?.map(d=>d.start),this.locations=l&&p?l.map(d=>k(p,d)):i?.map(d=>k(d.source,d.start));let y=M(s?.extensions)?s?.extensions:void 0;this.extensions=(e=g??y)!==null&&e!==void 0?e: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}}),s!=null&&s.stack?Object.defineProperty(this,"stack",{value:s.stack,writable:true,configurable:true}):Error.captureStackTrace?Error.captureStackTrace(this,t):Object.defineProperty(this,"stack",{value:Error().stack,writable:true,configurable:true});}get[Symbol.toStringTag](){return "GraphQLError"}toString(){let n=this.message;if(this.nodes)for(let o of this.nodes)o.loc&&(n+=`
1
+ import {createYoga,createPubSub}from'graphql-yoga';import {useSofa}from'sofa-api';import {One,relationsFilterToSQL}from'drizzle-orm';import {toCamelCase}from'drizzle-orm/casing';import {PgEnumColumn}from'drizzle-orm/pg-core';import Pe,{BasePlugin}from'@pothos/core';import ke from'@pothos/plugin-drizzle';import qe,{subscribeOptionsFromIterator}from'@pothos/plugin-smart-subscriptions';import {JSONResolver,DateResolver,DateTimeISOResolver}from'graphql-scalars';function M(t){return typeof t=="object"&&t!==null}function $(t,n){throw new Error("Unexpected invariant triggered.")}var de=/\r\n|[\n\r]/g;function U(t,n){let o=0,u=1;for(let r of t.body.matchAll(de)){if(typeof r.index=="number"||$(),r.index>=n)break;o=r.index+r[0].length,u+=1;}return {line:u,column:n+1-o}}function H(t){return W(t.source,U(t.source,t.start))}function W(t,n){let o=t.locationOffset.column-1,u="".padStart(o)+t.body,r=n.line-1,e=t.locationOffset.line-1,a=n.line+e,p=n.line===1?o:0,l=n.column+p,c=`${t.name}:${a}:${l}
2
+ `,s=u.split(/\r\n|[\n\r]/g),b=s[r];if(b.length>120){let i=Math.floor(l/80),y=l%80,d=[];for(let g=0;g<b.length;g+=80)d.push(b.slice(g,g+80));return c+J([[`${a} |`,d[0]],...d.slice(1,i+1).map(g=>["|",g]),["|","^".padStart(y)],["|",d[i+1]]])}return c+J([[`${a-1} |`,s[r-1]],[`${a} |`,b],["|","^".padStart(l)],[`${a+1} |`,s[r+1]]])}function J(t){let n=t.filter(([u,r])=>r!==void 0),o=Math.max(...n.map(([u])=>u.length));return n.map(([u,r])=>u.padStart(o)+(r?" "+r:"")).join(`
3
+ `)}function fe(t){let n=t[0];return n==null||"kind"in n||"length"in n?{nodes:n,source:t[1],positions:t[2],path:t[3],originalError:t[4],extensions:t[5]}:n}var k=class t extends Error{constructor(n,...o){var u,r,e;let{nodes:a,source:p,positions:l,path:c,originalError:s,extensions:b}=fe(o);super(n),this.name="GraphQLError",this.path=c??void 0,this.originalError=s??void 0,this.nodes=Y(Array.isArray(a)?a:a?[a]:void 0);let i=Y((u=this.nodes)===null||u===void 0?void 0:u.map(d=>d.loc).filter(d=>d!=null));this.source=p??(i==null||(r=i[0])===null||r===void 0?void 0:r.source),this.positions=l??i?.map(d=>d.start),this.locations=l&&p?l.map(d=>U(p,d)):i?.map(d=>U(d.source,d.start));let y=M(s?.extensions)?s?.extensions:void 0;this.extensions=(e=b??y)!==null&&e!==void 0?e: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}}),s!=null&&s.stack?Object.defineProperty(this,"stack",{value:s.stack,writable:true,configurable:true}):Error.captureStackTrace?Error.captureStackTrace(this,t):Object.defineProperty(this,"stack",{value:Error().stack,writable:true,configurable:true});}get[Symbol.toStringTag](){return "GraphQLError"}toString(){let n=this.message;if(this.nodes)for(let o of this.nodes)o.loc&&(n+=`
4
4
 
5
5
  `+H(o.loc));else if(this.source&&this.locations)for(let o of this.locations)n+=`
6
6
 
7
- `+W(this.source,o);return n}toJSON(){let n={message:this.message};return this.locations!=null&&(n.locations=this.locations),this.path!=null&&(n.path=this.path),this.extensions!=null&&Object.keys(this.extensions).length>0&&(n.extensions=this.extensions),n}};function Y(t){return t===void 0||t.length===0?void 0:t}var R=class extends Error{constructor(n){super(n),this.name="RumbleError";}},q=class extends L{};var K=t=>{if(!t)throw new q("Value not found but required (findFirst)");return t},be=t=>{let n=t.at(0);if(!n)throw new q("Value not found but required (firstEntry)");return n},X=async({filters:t,entities:n,context:o})=>(await Promise.all(t.map(u=>u({context:o,entities:n})))).reduce((u,r)=>(u.push(...r),u),[]);function U(t){let n,o=false;return ()=>(o||(n=t(),o=true),n)}var Q=(t,n)=>new R(`RumbleError: Unknown SQL type '${t}'. Please open an issue (https://github.com/m1212e/rumble/issues) so it can be added. (${n})`);function Z(t){if(["serial","int","integer","tinyint","smallint","mediumint"].includes(t))return {value1:1,value2:2};if(["real","decimal","double","float"].includes(t))return {value1:1.1,value2:2.2};if(["string","text","varchar","char","text(256)"].includes(t))return {value1:"a",value2:"b"};if(["uuid"].includes(t))return {value1:"fba31870-5528-42d7-b27e-2e5ee657aea5",value2:"fc65db81-c2d1-483d-8a25-a30e2cf6e02d"};if(["boolean"].includes(t))return {value1:true,value2:false};if(["timestamp","datetime"].includes(t))return {value1:new Date(2022,1,1),value2:new Date(2022,1,2)};if(["date"].includes(t))return {value1:new Date(2022,1,1),value2:new Date(2022,1,2)};if(["json"].includes(t))return {value1:{a:1},value2:{b:2}};throw Q(t,"Distinct")}var _=Symbol.for("drizzle:Name"),ee=Symbol.for("drizzle:Columns");function N({dbName:t,tsName:n,table:o,db:u}){let r=o;if(n&&(r=u._.relations.schema[n]),t&&(r=Object.values(u._.relations.schema).find(e=>e[_]===t)),!r)throw new R(`Could not find schema for ${JSON.stringify({tsName:n,dbName:t,table:o?.[_]}).toString()}`);return {tableSchema:r,columns:r[ee],get primaryColumns(){return Object.entries(r[ee]).filter(([e,a])=>a.primary).reduce((e,[a,p])=>(e[a]=p,e),{})},relations:u._.relations.config[n],dbName:r[_],get tsName(){return Object.entries(u._.relations.schema).find(([e,a])=>a===r).at(0)}}}function he(t){return typeof t!="function"}function xe(t){return typeof t=="function"&&t.constructor.name!=="AsyncFunction"}var te=({db:t,actions:n,defaultLimit:o})=>{let u={},r={},e={},a=p=>{for(let l of n)e[p]||(e[p]={}),e[p][l]||(e[p][l]=[]);return {allow:l=>{let c=r[p];c||(c={},r[p]=c);let s=Array.isArray(l)?l:[l];for(let g of s){let i=c[g];i||(i="unspecified",c[g]=i);}return {when:g=>{for(let i of s)c[i]==="unspecified"&&(c[i]=[]),c[i].push(g);}}},filter:l=>{let c=Array.isArray(l)?l:[l];return {by:s=>{for(let g of c)e[p][g].push(s);}}}}};for(let p of Object.keys(t.query))u[p]=a(p);return {...u,registeredQueryFilters:r,registeredFilters:e,buildWithUserContext:p=>{let l={},c=s=>({filter:(g,i)=>{let y=m=>{let A=U(()=>{if(!(!m?.where&&!i?.inject?.where)){if(i?.inject?.where&&m?.where)return {AND:[m?.where,i?.inject?.where]};if(i?.inject?.where&&!m?.where)return i?.inject?.where;if(!i?.inject?.where&&m?.where)return m?.where;!i?.inject?.where&&m?.where;}}),P=U(()=>{let C=A();if(!C)return;let z=N({tsName:s,db:t});return relationsFilterToSQL(z.tableSchema,C)}),w=U(()=>{let C=m?.limit??o;return i?.inject?.limit&&(!C||C>i.inject.limit)&&(C=i.inject.limit),m?.limit&&(!C||m.limit>C)&&(C=m.limit),C??void 0}),v=U(()=>{if(!(!m?.columns&&!i?.inject?.columns))return {...m?.columns,...i?.inject?.columns}}),F={query:{single:{get where(){return A()},columns:v()},many:{get where(){return A()},columns:v(),get limit(){return w()}}},sql:{get where(){return P()},columns:v(),get limit(){return w()}}};return v()||(delete F.sql.columns,delete F.query.many.columns,delete F.query.single.columns),F},d=()=>{let m=N({db:t,tsName:s});if(Object.keys(m.primaryColumns).length===0)throw new R(`No primary key found for entity ${s.toString()}`);let A=Object.values(m.primaryColumns)[0],P=Z(A.getSQLType());return {where:{AND:[{[A.name]:P.value1},{[A.name]:P.value2}]}}},b=r?.[s]?.[g];if(b==="unspecified")return y();b||(b=[d()]);let h=b.filter(he),D=b.filter(xe).map(m=>m(p)),I=D.some(m=>m==="allow"),E=[...h,...D].filter(m=>m!==void 0).filter(m=>m!=="allow");!I&&E.length===0&&(E=[d()]);let x;for(let m of E)m?.limit&&(x===void 0||m.limit>x)&&(x=m.limit);let f;for(let m of [...E,i?.inject])m?.columns&&(f===void 0?f=m.columns:f={...f,...m.columns});let T=I?[]:E.filter(m=>m?.where).map(m=>m.where),S=T.length>0?{OR:T}:void 0;return y({where:S,columns:f,limit:x})},explicitFilters:g=>e[s][g]});for(let s of Object.keys(t.query))l[s]=c(s);return l}}};var ne=({context:t,abilityBuilder:n})=>async o=>{let u=t?await t(o):{};return {...u,abilities:n.buildWithUserContext(u)}};function B(t){return String(t).charAt(0).toUpperCase()+String(t).slice(1)}function j(t){return t instanceof PgEnumColumn}var re=({db:t,schemaBuilder:n})=>{let o=new Map;return ({tsName:r,enumColumn:e,refName:a})=>{let p,l;if(r){let i=t._.relations.schema[r];p=r.toString();let y=Object.values(t._.relations.schema).filter(d=>typeof d=="object").map(d=>Object.values(d[Symbol.for("drizzle:Columns")])).flat(2).find(d=>d.config?.enum===i);if(!y)throw new R(`Could not find applied enum column for ${r.toString()}.
8
- Please ensure that you use the enum at least once as a column of a table!`);l=y.enumValues;}else if(e){let i=Object.entries(t._.relations.schema).find(([y,d])=>d===e.config.enum);if(!i)throw new R(`Could not find enum in schema for ${e.name}!`);p=i[0],l=e.enumValues;}if(!p||!l)throw new R("Could not determine enum structure!");let c=a??`${B(toCamelCase(p))}Enum`,s=o.get(c);return s||(s=n.enumType(c,{values:l}),o.set(c,s),s)}};function G({sqlType:t,fieldName:n}){let o;if(["serial","int","integer","tinyint","smallint","mediumint"].includes(t)&&(o="Int"),["real","decimal","double","float"].includes(t)&&(o="Float"),["string","text","varchar","char","text(256)"].includes(t)&&(n&&(n.toLowerCase().endsWith("_id")||n.toLowerCase().endsWith("id"))?o="ID":o="String"),["uuid"].includes(t)&&(o="ID"),["boolean"].includes(t)&&(o="Boolean"),["timestamp","datetime"].includes(t)&&(o="DateTime"),["date"].includes(t)&&(o="Date"),["json"].includes(t)&&(o="JSON"),o!==void 0)return o;throw Q(t,"SQL to GQL")}var Se=t=>typeof t!="object"?false:!!Object.keys(t).some(n=>["args","nullable","query","subscribe","description","type","resolve"].find(o=>o===n)),ie=({db:t,schemaBuilder:n,makePubSubInstance:o,argImplementer:u,enumImplementer:r,abilityBuilder:e})=>({table:a,refName:p,readAction:l="read",adjust:c})=>{let s=N({db:t,tsName:a});Object.keys(s.primaryColumns).length===0&&console.warn(`Could not find primary key for ${a.toString()}. Cannot register subscriptions!`);let g=Object.values(s.primaryColumns)[0],{registerOnInstance:i}=o({table:a});return n.drizzleObject(a,{name:p??B(a.toString()),subscribe:(y,d,b)=>{if(!g)return;let h=d[g.name];if(!h){console.warn(`Could not find primary key value for ${JSON.stringify(d)}. Cannot register subscription!`);return}i({instance:y,action:"updated",primaryKeyValue:h});},applyFilters:e?.registeredFilters?.[a]?.[l],fields:y=>{let d=s.columns,b=(x,f,T)=>{let S=G({sqlType:x,fieldName:f});switch(S){case "Int":return y.exposeInt(f,{nullable:T});case "String":return y.exposeString(f,{nullable:T});case "Boolean":return y.exposeBoolean(f,{nullable:T});case "Date":return y.field({type:"Date",resolve:m=>m[f],nullable:T});case "DateTime":return y.field({type:"DateTime",resolve:m=>m[f],nullable:T});case "Float":return y.exposeFloat(f,{nullable:T});case "ID":return y.exposeID(f,{nullable:T});case "JSON":return y.field({type:"JSON",resolve:m=>m[f],nullable:T});default:throw new R(`Unsupported object type ${S} for column ${f}`)}},h=new Map,D=c?.(new Proxy(y,{get:(x,f)=>typeof x[f]=="function"?(...T)=>{let S=x[f](...T),m=T.find(Se);if(!m)throw new R("Expected config object to be passed to adjust field");return h.set(S,{params:T,creatorFunction:x[f],configObject:m}),S}:x[f]}))??{},I=Object.entries(d).reduce((x,[f,T])=>{if(D[f]){let{params:S,creatorFunction:m,configObject:A}=h.get(D[f]);return typeof A.nullable!="boolean"&&(A.nullable=!T.notNull),D[f]=m.bind(y)(...S),x}if(j(T)){let S=r({enumColumn:T});x[f]=y.field({type:S,resolve:m=>m[f],nullable:!T.notNull});}else x[f]=b(T.getSQLType(),f,!T.notNull);return x},{}),E=Object.entries(s.relations??{}).reduce((x,[f,T])=>{let S=N({db:t,table:T.targetTable}),m=u({dbName:S.dbName}),A=o({table:S.tsName}),P=false,w=true,v="many";T instanceof One&&(w=false,P=T.optional,v="single");let F=(C,z)=>{A.registerOnInstance({instance:C,action:"created"}),A.registerOnInstance({instance:C,action:"removed"});};if(D[f]){let{params:C,creatorFunction:z,configObject:O}=h.get(D[f]);return typeof O.nullable!="boolean"&&(O.nullable=P),typeof O.subscribe!="function"&&(O.subscribe=F),D[f]=z.bind(y)(...C),x}return x[f]=y.relation(f,{args:{where:y.arg({type:m,required:false}),...w?{offset:y.arg.int({required:false}),limit:y.arg.int({required:false})}:{}},subscribe:F,nullable:P,query:(C,z)=>{C=JSON.parse(JSON.stringify(C));let O=z.abilities[S.tsName].filter(l,{inject:{where:C.where,limit:C.limit}}).query[v];return C.offset&&(O.offset=C.offset),O}}),x},{});return {...I,...E,...D}}})};var Ie="RUMBLE_SUBSCRIPTION_NOTIFICATION",Ae="REMOVED",Ee="UPDATED",Ne="CREATED",se=({subscriptions:t,db:n})=>{let o=t?createPubSub(...t):createPubSub();return {pubsub:o,makePubSubInstance:({table:r})=>{function e({action:a,tableName:p,primaryKeyValue:l}){let c;switch(a){case "created":c=Ne;break;case "removed":c=Ae;break;case "updated":c=Ee;break;default:throw new Error(`Unknown action: ${a}`)}return `${Ie}/${p}${l?`/${l}`:""}/${c}`}return {registerOnInstance({instance:a,action:p,primaryKeyValue:l}){let c=e({tableName:r.toString(),action:p,primaryKeyValue:l});a.register(c);},created(){let a=e({tableName:r.toString(),action:"created"});return o.publish(a)},removed(a){let p=e({tableName:r.toString(),action:"removed"});return o.publish(p)},updated(a){let l=(Array.isArray(a)?a:[a]).map(s=>e({tableName:r.toString(),action:"updated",primaryKeyValue:s})),c=Array.from(new Set(l));for(let s of c)o.publish(s);}}}}};var ae=({db:t,schemaBuilder:n,argImplementer:o,makePubSubInstance:u})=>({table:r,readAction:e="read",listAction:a="read"})=>{let p=o({table:r}),{registerOnInstance:l}=u({table:r});return n.queryFields(c=>({[`findMany${B(r.toString())}`]:c.drizzleField({type:[r],nullable:false,smartSubscription:true,subscribe:(s,g,i,y,d)=>{l({instance:s,action:"created"}),l({instance:s,action:"removed"});},args:{where:c.arg({type:p,required:false}),limit:c.arg.int({required:false}),offset:c.arg.int({required:false})},resolve:(s,g,i,y,d)=>{i=JSON.parse(JSON.stringify(i));let b=y.abilities[r].filter(a,i.where||i.limit||i.offset?{inject:{where:i.where,limit:i.limit}}:void 0).query.many;i.offset&&(b.offset=i.offset);let h=s(b);return b.columns&&(h.columns=b.columns),t.query[r].findMany(h)}}),[`findFirst${B(r.toString())}`]:c.drizzleField({type:r,nullable:false,smartSubscription:true,args:{where:c.arg({type:p,required:false})},resolve:(s,g,i,y,d)=>{i=JSON.parse(JSON.stringify(i));let b=y.abilities[r].filter(e,i.where?{inject:{where:i.where}}:void 0).query.single,h=s(b);return b.columns&&(h.columns=b.columns),t.query[r].findFirst(h).then(K)}})}))};var le="ManualFiltersPlugin",ue=le,ve="applyFilters",V=class extends BasePlugin{wrapResolve(n,o){return async(u,r,e,a)=>{let p=(o?.type).type?.ref.currentConfig.pothosOptions[ve];if(!p||!Array.isArray(p)||p.length===0)return n(u,r,e,a);let l=await n(u,r,e,a),c=Array.isArray(l)?l:[l],s=Array.isArray(p)?p:[p],g=await X({filters:s,entities:c,context:e});return Array.isArray(l)?g:g[0]??null}}};Be.registerPlugin(le,V);var Oe=t=>`${B(toCamelCase(t.toString()))}WhereInputArgument`,pe=({db:t,schemaBuilder:n,enumImplementer:o})=>{let u=new Map,r=({table:e,refName:a,dbName:p})=>{let l=N({db:t,dbName:p,tsName:e}),c=a??Oe(l.tsName),s=u.get(c);return s||(s=n.inputType(c,{fields:i=>{let y=(h,D)=>{let I=G({sqlType:h,fieldName:D});switch(I){case "Int":return i.field({type:"IntWhereInputArgument"});case "String":return i.field({type:"StringWhereInputArgument"});case "Boolean":return i.boolean({required:false});case "Date":return i.field({type:"DateWhereInputArgument"});case "DateTime":return i.field({type:"DateWhereInputArgument"});case "Float":return i.field({type:"FloatWhereInputArgument"});case "ID":return i.id({required:false});case "JSON":return i.field({type:"JSON",required:false});default:throw new R(`Unsupported argument type ${I} for column ${h}`)}},d=Object.entries(l.columns).reduce((h,[D,I])=>{if(j(I)){let E=o({enumColumn:I});h[D]=i.field({type:E,required:false});}else h[D]=y(I.getSQLType(),D);return h},{}),b=Object.entries(l.relations??{}).reduce((h,[D,I])=>{let E=N({db:t,table:I.targetTable}),x=r({dbName:E.dbName});return h[D]=i.field({type:x,required:false}),h},{});return {...d,...b}}}),u.set(c,s),s)};return r};function me(t){let n=t.inputRef("IntWhereInputArgument").implement({fields:e=>({eq:e.int(),ne:e.int(),gt:e.int(),gte:e.int(),lt:e.int(),lte:e.int(),in:e.intList(),notIn:e.intList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.intList(),arrayContained:e.intList(),arrayContains:e.intList(),AND:e.field({type:[n]}),OR:e.field({type:[n]}),NOT:e.field({type:n})})}),o=t.inputRef("FloatWhereInputArgument").implement({fields:e=>({eq:e.float(),ne:e.float(),gt:e.float(),gte:e.float(),lt:e.float(),lte:e.float(),in:e.floatList(),notIn:e.floatList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.floatList(),arrayContained:e.floatList(),arrayContains:e.floatList(),AND:e.field({type:[o]}),OR:e.field({type:[o]}),NOT:e.field({type:o})})}),u=t.inputRef("StringWhereInputArgument").implement({fields:e=>({eq:e.string(),ne:e.string(),gt:e.string(),gte:e.string(),lt:e.string(),lte:e.string(),in:e.stringList(),notIn:e.stringList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.stringList(),arrayContained:e.stringList(),arrayContains:e.stringList(),AND:e.field({type:[u]}),OR:e.field({type:[u]}),NOT:e.field({type:u})})}),r=t.inputRef("DateWhereInputArgument").implement({fields:e=>({eq:e.field({type:"Date"}),ne:e.field({type:"Date"}),gt:e.field({type:"Date"}),gte:e.field({type:"Date"}),lt:e.field({type:"Date"}),lte:e.field({type:"Date"}),in:e.field({type:["Date"]}),notIn:e.field({type:["Date"]}),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.field({type:["Date"]}),arrayContained:e.field({type:["Date"]}),arrayContains:e.field({type:["Date"]}),AND:e.field({type:[r]}),OR:e.field({type:[r]}),NOT:e.field({type:r})})});}var ce=({db:t,disableDefaultObjects:n,pubsub:o,pothosConfig:u})=>{let r=new Be({...u,plugins:[ue,Le,qe,...u?.plugins??[]],drizzle:{client:t,relations:t._.relations,getTableConfig(e){return {columns:Object.values(e[Symbol.for("drizzle:Columns")]),primaryKeys:Object.values(e[Symbol.for("drizzle:Columns")]).filter(a=>a.primary)}}},smartSubscriptions:{...subscribeOptionsFromIterator((e,a)=>o.subscribe(e))}});return r.addScalarType("JSON",JSONResolver),r.addScalarType("Date",DateResolver),r.addScalarType("DateTime",DateTimeISOResolver),me(r),n?.query||r.queryType({}),n?.subscription||r.subscriptionType({}),n?.mutation||r.mutationType({}),{schemaBuilder:r}};var Ge=t=>{t.actions||(t.actions=["read","update","delete"]),t.defaultLimit===void 0&&(t.defaultLimit=100);let n=te(t),o=ne({...t,abilityBuilder:n}),{makePubSubInstance:u,pubsub:r}=se({...t}),{schemaBuilder:e}=ce({...t,pubsub:r}),a=re({...t,schemaBuilder:e}),p=pe({...t,schemaBuilder:e,enumImplementer:a}),l=ie({...t,schemaBuilder:e,makePubSubInstance:u,argImplementer:p,enumImplementer:a,abilityBuilder:n}),c=ae({...t,schemaBuilder:e,argImplementer:p,makePubSubInstance:u});return {abilityBuilder:n,schemaBuilder:e,createYoga:g=>createYoga({...g,schema:e.toSchema(),context:o}),object:l,arg:p,query:c,pubsub:u,enum_:a}};export{R as RumbleError,q as RumbleErrorSafe,K as assertFindFirstExists,be as assertFirstEntryExists,Ge as rumble};//# sourceMappingURL=index.js.map
7
+ `+W(this.source,o);return n}toJSON(){let n={message:this.message};return this.locations!=null&&(n.locations=this.locations),this.path!=null&&(n.path=this.path),this.extensions!=null&&Object.keys(this.extensions).length>0&&(n.extensions=this.extensions),n}};function Y(t){return t===void 0||t.length===0?void 0:t}var S=class extends Error{constructor(n){super(n),this.name="RumbleError";}},q=class extends k{};var _=t=>{if(!t)throw new q("Value not found but required (findFirst)");return t},he=t=>{let n=t.at(0);if(!n)throw new q("Value not found but required (firstEntry)");return n},X=async({filters:t,entities:n,context:o})=>(await Promise.all(t.map(u=>u({context:o,entities:n})))).reduce((u,r)=>(u.push(...r),u),[]);function z(t){let n,o=false;return ()=>(o||(n=t(),o=true),n)}var Q=(t,n)=>new S(`RumbleError: Unknown SQL type '${t}'. Please open an issue (https://github.com/m1212e/rumble/issues) so it can be added. (${n})`);function Z(t){if(["serial","int","integer","tinyint","smallint","mediumint"].includes(t))return {value1:1,value2:2};if(["real","decimal","double","float"].includes(t))return {value1:1.1,value2:2.2};if(["string","text","varchar","char","text(256)"].includes(t))return {value1:"a",value2:"b"};if(["uuid"].includes(t))return {value1:"fba31870-5528-42d7-b27e-2e5ee657aea5",value2:"fc65db81-c2d1-483d-8a25-a30e2cf6e02d"};if(["boolean"].includes(t))return {value1:true,value2:false};if(["timestamp","datetime"].includes(t))return {value1:new Date(2022,1,1),value2:new Date(2022,1,2)};if(["date"].includes(t))return {value1:new Date(2022,1,1),value2:new Date(2022,1,2)};if(["json"].includes(t))return {value1:{a:1},value2:{b:2}};throw Q(t,"Distinct")}var K=Symbol.for("drizzle:Name"),ee=Symbol.for("drizzle:Columns");function N({dbName:t,tsName:n,table:o,db:u}){let r=o;if(n&&(r=u._.relations.schema[n]),t&&(r=Object.values(u._.relations.schema).find(e=>e[K]===t)),!r)throw new S(`Could not find schema for ${JSON.stringify({tsName:n,dbName:t,table:o?.[K]}).toString()}`);return {tableSchema:r,columns:r[ee],get primaryColumns(){return Object.entries(r[ee]).filter(([e,a])=>a.primary).reduce((e,[a,p])=>(e[a]=p,e),{})},relations:u._.relations.config[n],dbName:r[K],get tsName(){return Object.entries(u._.relations.schema).find(([e,a])=>a===r).at(0)}}}function xe(t){return typeof t!="function"}function Ce(t){return typeof t=="function"&&t.constructor.name!=="AsyncFunction"}var te=({db:t,actions:n,defaultLimit:o})=>{let u={},r={},e={},a=p=>{for(let l of n)e[p]||(e[p]={}),e[p][l]||(e[p][l]=[]);return {allow:l=>{let c=r[p];c||(c={},r[p]=c);let s=Array.isArray(l)?l:[l];for(let b of s){let i=c[b];i||(i="unspecified",c[b]=i);}return {when:b=>{for(let i of s)c[i]==="unspecified"&&(c[i]=[]),c[i].push(b);}}},filter:l=>{let c=Array.isArray(l)?l:[l];return {by:s=>{for(let b of c)e[p][b].push(s);}}}}};for(let p of Object.keys(t.query))u[p]=a(p);return {...u,registeredQueryFilters:r,registeredFilters:e,buildWithUserContext:p=>{let l={},c=s=>({filter:(b,i)=>{let y=m=>{let A=z(()=>{if(!(!m?.where&&!i?.inject?.where)){if(i?.inject?.where&&m?.where)return {AND:[m?.where,i?.inject?.where]};if(i?.inject?.where&&!m?.where)return i?.inject?.where;if(!i?.inject?.where&&m?.where)return m?.where;!i?.inject?.where&&m?.where;}}),P=z(()=>{let C=A();if(!C)return;let L=N({tsName:s,db:t});return relationsFilterToSQL(L.tableSchema,C)}),w=z(()=>{let C=m?.limit??o;return i?.inject?.limit&&(!C||C>i.inject.limit)&&(C=i.inject.limit),m?.limit&&(!C||m.limit>C)&&(C=m.limit),C??void 0}),v=z(()=>{if(!(!m?.columns&&!i?.inject?.columns))return {...m?.columns,...i?.inject?.columns}}),F={query:{single:{get where(){return A()},columns:v()},many:{get where(){return A()},columns:v(),get limit(){return w()}}},sql:{get where(){return P()},columns:v(),get limit(){return w()}}};return v()||(delete F.sql.columns,delete F.query.many.columns,delete F.query.single.columns),F},d=()=>{let m=N({db:t,tsName:s});if(Object.keys(m.primaryColumns).length===0)throw new S(`No primary key found for entity ${s.toString()}`);let A=Object.values(m.primaryColumns)[0],P=Z(A.getSQLType());return {where:{AND:[{[A.name]:P.value1},{[A.name]:P.value2}]}}},g=r?.[s]?.[b];if(g==="unspecified")return y();g||(g=[d()]);let T=g.filter(xe),D=g.filter(Ce).map(m=>m(p)),I=D.some(m=>m==="allow"),E=[...T,...D].filter(m=>m!==void 0).filter(m=>m!=="allow");!I&&E.length===0&&(E=[d()]);let x;for(let m of E)m?.limit&&(x===void 0||m.limit>x)&&(x=m.limit);let f;for(let m of [...E,i?.inject])m?.columns&&(f===void 0?f=m.columns:f={...f,...m.columns});let h=I?[]:E.filter(m=>m?.where).map(m=>m.where),R=h.length>0?{OR:h}:void 0;return y({where:R,columns:f,limit:x})},explicitFilters:b=>e[s][b]});for(let s of Object.keys(t.query))l[s]=c(s);return l}}};var ne=({context:t,abilityBuilder:n})=>async o=>{let u=t?await t(o):{};return {...u,abilities:n.buildWithUserContext(u)}};function B(t){return String(t).charAt(0).toUpperCase()+String(t).slice(1)}function j(t){return t instanceof PgEnumColumn}var re=({db:t,schemaBuilder:n})=>{let o=new Map;return ({tsName:r,enumColumn:e,refName:a})=>{let p,l;if(r){let i=t._.relations.schema[r];p=r.toString();let y=Object.values(t._.relations.schema).filter(d=>typeof d=="object").map(d=>Object.values(d[Symbol.for("drizzle:Columns")])).flat(2).find(d=>d.config?.enum===i);if(!y)throw new S(`Could not find applied enum column for ${r.toString()}.
8
+ Please ensure that you use the enum at least once as a column of a table!`);l=y.enumValues;}else if(e){let i=Object.entries(t._.relations.schema).find(([y,d])=>d===e.config.enum);if(!i)throw new S(`Could not find enum in schema for ${e.name}!`);p=i[0],l=e.enumValues;}if(!p||!l)throw new S("Could not determine enum structure!");let c=a??`${B(toCamelCase(p))}Enum`,s=o.get(c);return s||(s=n.enumType(c,{values:l}),o.set(c,s),s)}};var ie={paths:{"/webhook":{post:{operationId:"webhook_create",description:"Creates a webhook subscription.",tags:[],parameters:[],requestBody:{content:{"application/json":{schema:{$ref:"#/components/schemas/WebhookCreateBody"}}}},responses:{200:{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:{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:{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"}}}}}};function G({sqlType:t,fieldName:n}){let o;if(["serial","int","integer","tinyint","smallint","mediumint"].includes(t)&&(o="Int"),["real","decimal","double","float"].includes(t)&&(o="Float"),["string","text","varchar","char","text(256)"].includes(t)&&(n&&(n.toLowerCase().endsWith("_id")||n.toLowerCase().endsWith("id"))?o="ID":o="String"),["uuid"].includes(t)&&(o="ID"),["boolean"].includes(t)&&(o="Boolean"),["timestamp","datetime"].includes(t)&&(o="DateTime"),["date"].includes(t)&&(o="Date"),["json"].includes(t)&&(o="JSON"),o!==void 0)return o;throw Q(t,"SQL to GQL")}var Ie=t=>typeof t!="object"?false:!!Object.keys(t).some(n=>["args","nullable","query","subscribe","description","type","resolve"].find(o=>o===n)),oe=({db:t,schemaBuilder:n,makePubSubInstance:o,argImplementer:u,enumImplementer:r,abilityBuilder:e})=>({table:a,refName:p,readAction:l="read",adjust:c})=>{let s=N({db:t,tsName:a});Object.keys(s.primaryColumns).length===0&&console.warn(`Could not find primary key for ${a.toString()}. Cannot register subscriptions!`);let b=Object.values(s.primaryColumns)[0],{registerOnInstance:i}=o({table:a});return n.drizzleObject(a,{name:p??B(a.toString()),subscribe:(y,d,g)=>{if(!b)return;let T=d[b.name];if(!T){console.warn(`Could not find primary key value for ${JSON.stringify(d)}. Cannot register subscription!`);return}i({instance:y,action:"updated",primaryKeyValue:T});},applyFilters:e?.registeredFilters?.[a]?.[l],fields:y=>{let d=s.columns,g=(x,f,h)=>{let R=G({sqlType:x,fieldName:f});switch(R){case "Int":return y.exposeInt(f,{nullable:h});case "String":return y.exposeString(f,{nullable:h});case "Boolean":return y.exposeBoolean(f,{nullable:h});case "Date":return y.field({type:"Date",resolve:m=>m[f],nullable:h});case "DateTime":return y.field({type:"DateTime",resolve:m=>m[f],nullable:h});case "Float":return y.exposeFloat(f,{nullable:h});case "ID":return y.exposeID(f,{nullable:h});case "JSON":return y.field({type:"JSON",resolve:m=>m[f],nullable:h});default:throw new S(`Unsupported object type ${R} for column ${f}`)}},T=new Map,D=c?.(new Proxy(y,{get:(x,f)=>typeof x[f]=="function"?(...h)=>{let R=x[f](...h),m=h.find(Ie);if(!m)throw new S("Expected config object to be passed to adjust field");return T.set(R,{params:h,creatorFunction:x[f],configObject:m}),R}:x[f]}))??{},I=Object.entries(d).reduce((x,[f,h])=>{if(D[f]){let{params:R,creatorFunction:m,configObject:A}=T.get(D[f]);return typeof A.nullable!="boolean"&&(A.nullable=!h.notNull),D[f]=m.bind(y)(...R),x}if(j(h)){let R=r({enumColumn:h});x[f]=y.field({type:R,resolve:m=>m[f],nullable:!h.notNull});}else x[f]=g(h.getSQLType(),f,!h.notNull);return x},{}),E=Object.entries(s.relations??{}).reduce((x,[f,h])=>{let R=N({db:t,table:h.targetTable}),m=u({dbName:R.dbName}),A=o({table:R.tsName}),P=false,w=true,v="many";h instanceof One&&(w=false,P=h.optional,v="single");let F=(C,L)=>{A.registerOnInstance({instance:C,action:"created"}),A.registerOnInstance({instance:C,action:"removed"});};if(D[f]){let{params:C,creatorFunction:L,configObject:O}=T.get(D[f]);return typeof O.nullable!="boolean"&&(O.nullable=P),typeof O.subscribe!="function"&&(O.subscribe=F),D[f]=L.bind(y)(...C),x}return x[f]=y.relation(f,{args:{where:y.arg({type:m,required:false}),...w?{offset:y.arg.int({required:false}),limit:y.arg.int({required:false})}:{}},subscribe:F,nullable:P,query:(C,L)=>{C=JSON.parse(JSON.stringify(C));let O=L.abilities[R.tsName].filter(l,{inject:{where:C.where,limit:C.limit}}).query[v];return C.offset&&(O.offset=C.offset),O}}),x},{});return {...I,...E,...D}}})};var Ae="RUMBLE_SUBSCRIPTION_NOTIFICATION",Ee="REMOVED",Ne="UPDATED",Be="CREATED",ae=({subscriptions:t,db:n})=>{let o=t?createPubSub(...t):createPubSub();return {pubsub:o,makePubSubInstance:({table:r})=>{function e({action:a,tableName:p,primaryKeyValue:l}){let c;switch(a){case "created":c=Be;break;case "removed":c=Ee;break;case "updated":c=Ne;break;default:throw new Error(`Unknown action: ${a}`)}return `${Ae}/${p}${l?`/${l}`:""}/${c}`}return {registerOnInstance({instance:a,action:p,primaryKeyValue:l}){let c=e({tableName:r.toString(),action:p,primaryKeyValue:l});a.register(c);},created(){let a=e({tableName:r.toString(),action:"created"});return o.publish(a)},removed(a){let p=e({tableName:r.toString(),action:"removed"});return o.publish(p)},updated(a){let l=(Array.isArray(a)?a:[a]).map(s=>e({tableName:r.toString(),action:"updated",primaryKeyValue:s})),c=Array.from(new Set(l));for(let s of c)o.publish(s);}}}}};var le=({db:t,schemaBuilder:n,argImplementer:o,makePubSubInstance:u})=>({table:r,readAction:e="read",listAction:a="read"})=>{let p=o({table:r}),{registerOnInstance:l}=u({table:r});return n.queryFields(c=>({[`findMany${B(r.toString())}`]:c.drizzleField({type:[r],nullable:false,smartSubscription:true,subscribe:(s,b,i,y,d)=>{l({instance:s,action:"created"}),l({instance:s,action:"removed"});},args:{where:c.arg({type:p,required:false}),limit:c.arg.int({required:false}),offset:c.arg.int({required:false})},resolve:(s,b,i,y,d)=>{i=JSON.parse(JSON.stringify(i));let g=y.abilities[r].filter(a,i.where||i.limit||i.offset?{inject:{where:i.where,limit:i.limit}}:void 0).query.many;i.offset&&(g.offset=i.offset);let T=s(g);return g.columns&&(T.columns=g.columns),t.query[r].findMany(T)}}),[`findFirst${B(r.toString())}`]:c.drizzleField({type:r,nullable:false,smartSubscription:true,args:{where:c.arg({type:p,required:false})},resolve:(s,b,i,y,d)=>{i=JSON.parse(JSON.stringify(i));let g=y.abilities[r].filter(e,i.where?{inject:{where:i.where}}:void 0).query.single,T=s(g);return g.columns&&(T.columns=g.columns),t.query[r].findFirst(T).then(_)}})}))};var ue="ManualFiltersPlugin",pe=ue,Fe="applyFilters",V=class extends BasePlugin{wrapResolve(n,o){return async(u,r,e,a)=>{let p=(o?.type).type?.ref.currentConfig.pothosOptions[Fe];if(!p||!Array.isArray(p)||p.length===0)return n(u,r,e,a);let l=await n(u,r,e,a),c=Array.isArray(l)?l:[l],s=Array.isArray(p)?p:[p],b=await X({filters:s,entities:c,context:e});return Array.isArray(l)?b:b[0]??null}}};Pe.registerPlugin(ue,V);var ze=t=>`${B(toCamelCase(t.toString()))}WhereInputArgument`,me=({db:t,schemaBuilder:n,enumImplementer:o})=>{let u=new Map,r=({table:e,refName:a,dbName:p})=>{let l=N({db:t,dbName:p,tsName:e}),c=a??ze(l.tsName),s=u.get(c);return s||(s=n.inputType(c,{fields:i=>{let y=(T,D)=>{let I=G({sqlType:T,fieldName:D});switch(I){case "Int":return i.field({type:"IntWhereInputArgument"});case "String":return i.field({type:"StringWhereInputArgument"});case "Boolean":return i.boolean({required:false});case "Date":return i.field({type:"DateWhereInputArgument"});case "DateTime":return i.field({type:"DateWhereInputArgument"});case "Float":return i.field({type:"FloatWhereInputArgument"});case "ID":return i.id({required:false});case "JSON":return i.field({type:"JSON",required:false});default:throw new S(`Unsupported argument type ${I} for column ${T}`)}},d=Object.entries(l.columns).reduce((T,[D,I])=>{if(j(I)){let E=o({enumColumn:I});T[D]=i.field({type:E,required:false});}else T[D]=y(I.getSQLType(),D);return T},{}),g=Object.entries(l.relations??{}).reduce((T,[D,I])=>{let E=N({db:t,table:I.targetTable}),x=r({dbName:E.dbName});return T[D]=i.field({type:x,required:false}),T},{});return {...d,...g}}}),u.set(c,s),s)};return r};function ce(t){let n=t.inputRef("IntWhereInputArgument").implement({fields:e=>({eq:e.int(),ne:e.int(),gt:e.int(),gte:e.int(),lt:e.int(),lte:e.int(),in:e.intList(),notIn:e.intList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.intList(),arrayContained:e.intList(),arrayContains:e.intList(),AND:e.field({type:[n]}),OR:e.field({type:[n]}),NOT:e.field({type:n})})}),o=t.inputRef("FloatWhereInputArgument").implement({fields:e=>({eq:e.float(),ne:e.float(),gt:e.float(),gte:e.float(),lt:e.float(),lte:e.float(),in:e.floatList(),notIn:e.floatList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.floatList(),arrayContained:e.floatList(),arrayContains:e.floatList(),AND:e.field({type:[o]}),OR:e.field({type:[o]}),NOT:e.field({type:o})})}),u=t.inputRef("StringWhereInputArgument").implement({fields:e=>({eq:e.string(),ne:e.string(),gt:e.string(),gte:e.string(),lt:e.string(),lte:e.string(),in:e.stringList(),notIn:e.stringList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.stringList(),arrayContained:e.stringList(),arrayContains:e.stringList(),AND:e.field({type:[u]}),OR:e.field({type:[u]}),NOT:e.field({type:u})})}),r=t.inputRef("DateWhereInputArgument").implement({fields:e=>({eq:e.field({type:"Date"}),ne:e.field({type:"Date"}),gt:e.field({type:"Date"}),gte:e.field({type:"Date"}),lt:e.field({type:"Date"}),lte:e.field({type:"Date"}),in:e.field({type:["Date"]}),notIn:e.field({type:["Date"]}),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.field({type:["Date"]}),arrayContained:e.field({type:["Date"]}),arrayContains:e.field({type:["Date"]}),AND:e.field({type:[r]}),OR:e.field({type:[r]}),NOT:e.field({type:r})})});}var ye=({db:t,disableDefaultObjects:n,pubsub:o,pothosConfig:u})=>{let r=new Pe({...u,plugins:[pe,ke,qe,...u?.plugins??[]],drizzle:{client:t,relations:t._.relations,getTableConfig(e){return {columns:Object.values(e[Symbol.for("drizzle:Columns")]),primaryKeys:Object.values(e[Symbol.for("drizzle:Columns")]).filter(a=>a.primary)}}},smartSubscriptions:{...subscribeOptionsFromIterator((e,a)=>o.subscribe(e))}});return r.addScalarType("JSON",JSONResolver),r.addScalarType("Date",DateResolver),r.addScalarType("DateTime",DateTimeISOResolver),ce(r),n?.query||r.queryType({}),n?.subscription||r.subscriptionType({}),n?.mutation||r.mutationType({}),{schemaBuilder:r}};var _e=t=>{t.actions||(t.actions=["read","update","delete"]),t.defaultLimit===void 0&&(t.defaultLimit=100);let n=te(t),o=ne({...t,abilityBuilder:n}),{makePubSubInstance:u,pubsub:r}=ae({...t}),{schemaBuilder:e}=ye({...t,pubsub:r}),a=re({...t,schemaBuilder:e}),p=me({...t,schemaBuilder:e,enumImplementer:a}),l=oe({...t,schemaBuilder:e,makePubSubInstance:u,argImplementer:p,enumImplementer:a,abilityBuilder:n}),c=le({...t,schemaBuilder:e,argImplementer:p,makePubSubInstance:u}),s=z(()=>e.toSchema());return {abilityBuilder:n,schemaBuilder:e,createYoga:y=>createYoga({...y,schema:s(),context:o}),createSofa:y=>(y.openAPI&&(y.openAPI={...ie,...y.openAPI}),useSofa({...y,schema:s(),context:o})),object:l,arg:p,query:c,pubsub:u,enum_:a}};export{S as RumbleError,q as RumbleErrorSafe,_ as assertFindFirstExists,he as assertFirstEntryExists,_e as rumble};//# sourceMappingURL=index.js.map
9
9
  //# sourceMappingURL=index.js.map