@m1212e/rumble 0.11.1 → 0.11.2
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.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.js +2 -2
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import {access,rm,mkdir,writeFile}from'fs/promises';import {join}from'path';import {merge,capitalize,cloneDeep}from'es-toolkit';import {pipe,merge as merge$1,empty,map,onPush,toObservable,fromValue,toPromise}from'wonka';import {EnvelopArmorPlugin}from'@escape.tech/graphql-armor';import {useDisableIntrospection}from'@graphql-yoga/plugin-disable-introspection';import {createYoga,createPubSub}from'graphql-yoga';import {useSofa}from'sofa-api';import {sql,One,relationsFilterToSQL}from'drizzle-orm';import {toCamelCase}from'drizzle-orm/casing';import {PgEnumColumn,PgTable}from'drizzle-orm/pg-core';import {plural,singular}from'pluralize';import {MySqlTable}from'drizzle-orm/mysql-core';import {SQLiteTable}from'drizzle-orm/sqlite-core';import kr,{BasePlugin}from'@pothos/core';import Vr from'@pothos/plugin-drizzle';import Mr,{subscribeOptionsFromIterator}from'@pothos/plugin-smart-subscriptions';import {JSONResolver,DateResolver,DateTimeISOResolver}from'graphql-scalars';function et({apiUrl:e,rumbleImportPath:t,useExternalUrqlClient:n,availableSubscriptions:r}){let o=[],i="";return typeof n=="string"?o.push(`import { urqlClient } from "${n}";`):(o.push("import { Client, fetchExchange } from '@urql/core';"),o.push("import { cacheExchange } from '@urql/exchange-graphcache';")),o.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,
|
@@ -93,7 +93,7 @@ spurious results.`)}}return false};function pt(e,t){let[n,r]=t?[e,t]:[void 0,e]
|
|
93
93
|
}`}function Hn(e,t){let n=false,r=false;for(let l=0;l<3;l++)e instanceof M&&(r=true,e=e.ofType),e instanceof U&&(n=true,e=e.ofType);let o=e.name;r&&(o+="[]"),n||(o+=" | null");let i=e instanceof J,s=new Map;for(let l of t??[])s.set(l.name,Zn(l.type));if(i){let l=s.entries().every(([,p])=>p.includes("| undefined"));return `(${(t??[]).length>0?`p${l?"?":""}: {
|
94
94
|
${s.entries().map(([p,a])=>` ${p}${a.includes("| undefined")?"?":""}: ${a}`).toArray().join(`,
|
95
95
|
`)}
|
96
|
-
}`:""}) => ${o}`}else return o}function Xn(e){let t=false,n=false;for(let o=0;o<3;o++)e instanceof M&&(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 Zn(e){let t="unknown",n=true;return e instanceof U&&(n=false,e=e.ofType),(e instanceof K||e instanceof W)&&(t=e.name),n&&(t+=" | null | undefined"),t}function er(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 tr(e){return e.getValues().map(t=>`"${t.name}"`).join(" | ")}async function Me({outputPath:e,schema:t,rumbleImportPath:n="@m1212e/rumble",apiUrl:r,useExternalUrqlClient:o=false}){await
|
96
|
+
}`:""}) => ${o}`}else return o}function Xn(e){let t=false,n=false;for(let o=0;o<3;o++)e instanceof M&&(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 Zn(e){let t="unknown",n=true;return e instanceof U&&(n=false,e=e.ofType),(e instanceof K||e instanceof W)&&(t=e.name),n&&(t+=" | null | undefined"),t}function er(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 tr(e){return e.getValues().map(t=>`"${t.name}"`).join(" | ")}async function Me({outputPath:e,schema:t,rumbleImportPath:n="@m1212e/rumble",apiUrl:r,useExternalUrqlClient:o=false}){try{await access(e),await rm(e,{recursive:!0,force:!0});}catch{}await mkdir(e,{recursive:true}),e.endsWith("/")||(e+="/");let i=[],s="",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())Ve(a)!==p&&(s+=`
|
97
97
|
export type ${p} = ${Ve(a)};
|
98
98
|
`);let u=et({apiUrl:r,useExternalUrqlClient:o,rumbleImportPath:n,availableSubscriptions:new Set(Object.keys(t.getSubscriptionType()?.getFields()||{}))});i.push(...u.imports),s+=u.code,await writeFile(join(e,"client.ts"),`${i.join(`
|
99
99
|
`)}
|