@kyro-cms/core 0.12.70 → 0.13.0
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 +6 -0
- package/dist/{WebhookService-CGNSlclW.d.ts → WebhookService-BLi5Rz2m.d.ts} +1 -1
- package/dist/{WebhookService-CIQPD1We.d.cts → WebhookService-BcuD8tnn.d.cts} +1 -1
- package/dist/WebhookService-D5PSI5t6.d.cts +143 -0
- package/dist/WebhookService-DPCCn_12.d.ts +143 -0
- package/dist/WebhookService-Dncnbgm9.d.cts +143 -0
- package/dist/WebhookService-UY5p89Bj.d.ts +143 -0
- package/dist/WebhookService-YZXBCRXA.d.ts +143 -0
- package/dist/WebhookService-zrDmAx7L.d.cts +143 -0
- package/dist/api-handler-graphql.cjs +1 -1
- package/dist/api-handler-graphql.js +1 -1
- package/dist/api-handler-trpc.cjs +1 -1
- package/dist/api-handler-trpc.js +1 -1
- package/dist/api-handler.cjs +1 -1
- package/dist/api-handler.js +1 -1
- package/dist/base-B--L0lCn.d.cts +218 -0
- package/dist/base-BVoDPNjJ.d.cts +218 -0
- package/dist/{types-CpjuXbe7.d.cts → base-CAb9EYQs.d.ts} +69 -1
- package/dist/base-CyG7aF1e.d.cts +218 -0
- package/dist/{types-CpjuXbe7.d.ts → base-DOImeJ-F.d.ts} +69 -1
- package/dist/base-DbnwE42-.d.cts +218 -0
- package/dist/base-NyiSsD-n.d.ts +218 -0
- package/dist/base-xflndGDO.d.ts +218 -0
- package/dist/bootstrap-E24SGUJP.cjs +1 -0
- package/dist/bootstrap-QQ6D3OYG.js +1 -0
- package/dist/bootstrap-QVKSKXJF.cjs +1 -0
- package/dist/bootstrap-RILR44UM.cjs +1 -0
- package/dist/{bootstrap-WB6FDH2T.js → bootstrap-YFVE7MRG.js} +1 -1
- package/dist/bootstrap-ZRRUPRUR.js +1 -0
- package/dist/chunk-262YP5XA.cjs +1 -0
- package/dist/chunk-2FSOHXOU.cjs +56 -0
- package/dist/chunk-2OS5Y4LE.cjs +1 -0
- package/dist/chunk-2PXXQKN3.cjs +3 -0
- package/dist/chunk-355R4LS5.cjs +56 -0
- package/dist/chunk-35IVNLMA.js +122 -0
- package/dist/{chunk-XVPTVTQC.js → chunk-3GXLOYM3.js} +2 -2
- package/dist/chunk-3KZXF4US.js +2 -0
- package/dist/{chunk-Z552BTXA.cjs → chunk-3LAWUINR.cjs} +1 -1
- package/dist/chunk-3O3AVMWM.cjs +1 -0
- package/dist/{chunk-637PTUHF.js → chunk-3TAUNYEM.js} +1 -1
- package/dist/chunk-3U6MKWET.cjs +120 -0
- package/dist/chunk-4BMWWGJN.js +384 -0
- package/dist/chunk-5A7E7N4B.cjs +431 -0
- package/dist/chunk-6DD4J7LI.js +2 -0
- package/dist/chunk-6GGPY7U2.js +4 -0
- package/dist/chunk-6MNLRAKM.cjs +121 -0
- package/dist/chunk-6NBZDW53.js +133 -0
- package/dist/chunk-73Y63IPP.js +57 -0
- package/dist/chunk-7K6ZUNJM.js +4 -0
- package/dist/chunk-7NKNSRCB.cjs +448 -0
- package/dist/{chunk-IL2TMAHB.cjs → chunk-A35ZP72D.cjs} +3 -3
- package/dist/chunk-A3IOQOV6.js +2 -0
- package/dist/chunk-A3XVL6ED.cjs +3 -0
- package/dist/{chunk-OBH6EEAO.cjs → chunk-APDQ6ZTG.cjs} +5 -5
- package/dist/chunk-ATI2UZ7U.js +2 -0
- package/dist/chunk-B4AC23SG.js +122 -0
- package/dist/chunk-BD6XHMMM.cjs +2 -0
- package/dist/chunk-CH4TZZI5.js +449 -0
- package/dist/{chunk-TBTQXIHP.js → chunk-CHYVUWZ3.js} +1 -1
- package/dist/{chunk-6USPOWA4.js → chunk-CNHUCCQJ.js} +10 -10
- package/dist/chunk-CRP6PSCE.js +2 -0
- package/dist/chunk-DI6TCZSE.js +122 -0
- package/dist/chunk-DORUYZQV.cjs +1 -0
- package/dist/chunk-EFKEVWAD.js +4 -0
- package/dist/chunk-EI7FRSNY.js +57 -0
- package/dist/chunk-EON4XLKQ.cjs +1 -0
- package/dist/chunk-EUQAOYEO.cjs +121 -0
- package/dist/chunk-EVAUBT7H.js +57 -0
- package/dist/chunk-EYHD7HZE.cjs +1 -0
- package/dist/chunk-EYYIPA5N.js +432 -0
- package/dist/chunk-F2O4QO5N.cjs +383 -0
- package/dist/chunk-FBWLSWZ4.js +122 -0
- package/dist/{chunk-3XLXKGEU.cjs → chunk-FG3IFGJP.cjs} +1 -1
- package/dist/chunk-FGN6IMPY.cjs +3 -0
- package/dist/chunk-FK2BG4HU.js +3 -0
- package/dist/{chunk-MVZSSTCV.js → chunk-FUFS65Q5.js} +2 -2
- package/dist/chunk-GWIZT2P5.js +57 -0
- package/dist/chunk-H3FJ54KB.cjs +121 -0
- package/dist/chunk-HY3EAWB2.js +4 -0
- package/dist/chunk-I6UJVO2P.js +57 -0
- package/dist/chunk-IQSF6XRV.js +57 -0
- package/dist/chunk-IXGDTAES.js +4 -0
- package/dist/chunk-JA44K75G.js +2 -0
- package/dist/chunk-K5XGP57D.cjs +19 -0
- package/dist/chunk-KEITOXIP.js +2 -0
- package/dist/chunk-LPFRMQFQ.js +121 -0
- package/dist/chunk-LYU44UNN.cjs +56 -0
- package/dist/chunk-MDLJTZLV.cjs +1 -0
- package/dist/chunk-MJAODEFC.cjs +121 -0
- package/dist/chunk-MYHNTJLR.cjs +56 -0
- package/dist/chunk-N2YHO2WI.cjs +3 -0
- package/dist/chunk-N4FXLQE3.cjs +132 -0
- package/dist/chunk-NPBXLPOP.js +3 -0
- package/dist/chunk-ON5XJEPO.cjs +3 -0
- package/dist/chunk-OT2Z4XBD.cjs +1 -0
- package/dist/chunk-PFTBTWSC.cjs +1 -0
- package/dist/chunk-PTPVFLET.js +20 -0
- package/dist/chunk-PZDLPRJF.js +4 -0
- package/dist/chunk-Q5TFO66G.cjs +1 -0
- package/dist/chunk-QUTYCUST.js +4 -0
- package/dist/chunk-REKKBAQX.cjs +56 -0
- package/dist/chunk-REQ622YC.js +3 -0
- package/dist/chunk-RTNQP6BV.js +2 -0
- package/dist/chunk-RUJW47ZJ.js +2 -0
- package/dist/{chunk-SOCBJPYB.cjs → chunk-RVBSJ4UQ.cjs} +1 -1
- package/dist/chunk-RXYCFZJC.cjs +121 -0
- package/dist/chunk-RYHOWZLK.js +2 -0
- package/dist/chunk-S2MZNEBQ.cjs +1 -0
- package/dist/chunk-S73YERS2.js +57 -0
- package/dist/chunk-SBNMXQNO.cjs +2 -0
- package/dist/chunk-T3DJ3UTP.cjs +121 -0
- package/dist/{chunk-ZQETJ4T4.cjs → chunk-TCFL3UWT.cjs} +1 -1
- package/dist/chunk-TJZO7ZSX.cjs +3 -0
- package/dist/chunk-TKUNRCRH.js +4 -0
- package/dist/chunk-TQLCOMKC.js +4 -0
- package/dist/chunk-TRXYDWGE.cjs +1 -0
- package/dist/chunk-TS55CUNJ.js +57 -0
- package/dist/chunk-UFBJ3WOZ.js +2 -0
- package/dist/chunk-UQRVQUVR.js +2 -0
- package/dist/chunk-UW5W35NP.js +122 -0
- package/dist/chunk-VI7WCO2J.cjs +3 -0
- package/dist/chunk-W2GPP6RB.js +122 -0
- package/dist/chunk-WHOA7YJU.cjs +1 -0
- package/dist/chunk-WNRUPL26.js +2 -0
- package/dist/chunk-WXT2XW7T.js +13 -0
- package/dist/chunk-XFYSADHV.cjs +2 -0
- package/dist/chunk-XIAJQLGS.js +2 -0
- package/dist/chunk-XK6UB77Q.js +4 -0
- package/dist/chunk-Y2VHO66Q.cjs +3 -0
- package/dist/chunk-Y5O2OD7J.cjs +3 -0
- package/dist/chunk-YARB43JG.cjs +56 -0
- package/dist/chunk-YLCEMVYY.cjs +56 -0
- package/dist/chunk-YSOM57GK.cjs +3 -0
- package/dist/chunk-Z3UVDGYS.cjs +56 -0
- package/dist/{chunk-4OMQURN7.js → chunk-ZAKYTBEN.js} +1 -1
- package/dist/chunk-ZTLGK6R4.cjs +12 -0
- package/dist/chunk-ZUBJ6RLQ.cjs +1 -0
- package/dist/cli/index.cjs +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/client.cjs +109 -1
- package/dist/client.d.cts +1242 -6
- package/dist/client.d.ts +1242 -6
- package/dist/client.js +109 -2
- package/dist/drizzle/index.cjs +1 -1
- package/dist/drizzle/index.d.cts +3 -4
- package/dist/drizzle/index.d.ts +3 -4
- package/dist/drizzle/index.js +1 -1
- package/dist/fields/index.cjs +1 -1
- package/dist/fields/index.d.cts +2 -2
- package/dist/fields/index.d.ts +2 -2
- package/dist/fields/index.js +1 -1
- package/dist/graphql/index.d.cts +3 -3
- package/dist/graphql/index.d.ts +3 -3
- package/dist/{index-BHYGO3yF.d.cts → index-B9BFNOHd.d.cts} +2 -2
- package/dist/index-BMcYFpTv.d.cts +105 -0
- package/dist/{index-DTy4k1oU.d.ts → index-BttsFZDa.d.ts} +2 -2
- package/dist/index-CxA9uOv0.d.ts +105 -0
- package/dist/index-D6AXbuPI.d.ts +105 -0
- package/dist/index-DF0KDBaM.d.cts +105 -0
- package/dist/index-DG4Xu7gA.d.cts +105 -0
- package/dist/index-eHex8Iwj.d.ts +105 -0
- package/dist/index.cjs +43 -24
- package/dist/index.d.cts +167 -13
- package/dist/index.d.ts +167 -13
- package/dist/index.js +44 -25
- package/dist/lib-A2D63VXD.cjs +1 -0
- package/dist/lib-JQD2JAOO.js +2 -0
- package/dist/local-KR3AIGVA.cjs +1 -0
- package/dist/local-T7GISZBL.js +1 -0
- package/dist/mongo-auth-adapter-GR2CFFEA.js +1 -0
- package/dist/mongo-auth-adapter-UOO2LZUJ.cjs +1 -0
- package/dist/mongodb/index.cjs +1 -1
- package/dist/mongodb/index.d.cts +4 -4
- package/dist/mongodb/index.d.ts +4 -4
- package/dist/mongodb/index.js +1 -1
- package/dist/nodemailer-transport-3VWVUBM5.cjs +1 -0
- package/dist/nodemailer-transport-7RHATUKL.js +1 -0
- package/dist/nodemailer-transport-CHO2WKIY.js +1 -0
- package/dist/nodemailer-transport-ED2IXNGW.cjs +1 -0
- package/dist/postgres-auth-adapter-SK3N3OSS.js +1 -1
- package/dist/postgres-auth-adapter-ZO6HK5AK.cjs +1 -1
- package/dist/postgres-js-7YBZKGXG.cjs +1 -0
- package/dist/{postgres-js-WE3NBRFO.js → postgres-js-JLFIWOBH.js} +1 -1
- package/dist/rest/index.cjs +1 -1
- package/dist/rest/index.d.cts +4 -4
- package/dist/rest/index.d.ts +4 -4
- package/dist/rest/index.js +1 -1
- package/dist/templates/index.cjs +1 -1
- package/dist/templates/index.d.cts +2 -2
- package/dist/templates/index.d.ts +2 -2
- package/dist/templates/index.js +1 -1
- package/dist/trpc/index.cjs +1 -1
- package/dist/trpc/index.d.cts +3 -3
- package/dist/trpc/index.d.ts +3 -3
- package/dist/trpc/index.js +1 -1
- package/dist/types-B5Qz1svz.d.cts +822 -0
- package/dist/types-Bii0bhUV.d.cts +329 -0
- package/dist/types-Bii0bhUV.d.ts +329 -0
- package/dist/{types-CeAQSR87.d.cts → types-Bt2_ycUO.d.ts} +37 -2
- package/dist/types-C4wXHImf.d.ts +822 -0
- package/dist/types-DCWgPFmi.d.cts +822 -0
- package/dist/types-DROqAsr0.d.cts +330 -0
- package/dist/types-DROqAsr0.d.ts +330 -0
- package/dist/{types-BKPEavuy.d.cts → types-DlGSbh7I.d.cts} +1 -1
- package/dist/{types-BKPEavuy.d.ts → types-DlGSbh7I.d.ts} +1 -1
- package/dist/types-DsF64Wrc.d.cts +811 -0
- package/dist/{types-BWJx6zzm.d.ts → types-ZrjEVWfi.d.ts} +37 -2
- package/dist/types-dEy5JxvN.d.ts +822 -0
- package/dist/types-tVJc9YbX.d.cts +811 -0
- package/dist/ws/index.cjs +1 -1
- package/dist/ws/index.d.cts +121 -1
- package/dist/ws/index.d.ts +121 -1
- package/dist/ws/index.js +1 -1
- package/package.json +2 -2
- package/dist/base-Ds06wMo9.d.cts +0 -69
- package/dist/base-DxDXLyWe.d.ts +0 -69
- package/dist/bootstrap-XDT4MRML.cjs +0 -1
- package/dist/chunk-5M3FKE2V.js +0 -2
- package/dist/chunk-7FXEXHK6.js +0 -21
- package/dist/chunk-JSTDCK3Z.js +0 -2
- package/dist/chunk-JT36FTHY.cjs +0 -20
- package/dist/chunk-L2QXP26Q.js +0 -2
- package/dist/chunk-MRR7OTRX.js +0 -57
- package/dist/chunk-MVX2PYJJ.cjs +0 -1
- package/dist/chunk-MYGHZQMO.cjs +0 -1
- package/dist/chunk-OUAR4ZCU.cjs +0 -56
- package/dist/chunk-WCFHS7EZ.cjs +0 -1
- package/dist/index-D7kt5jT_.d.ts +0 -97
- package/dist/index-DPtCjn94.d.cts +0 -97
- package/dist/postgres-js-GXZX3AGZ.cjs +0 -1
- /package/dist/{chunk-XTTGHN3D.cjs → chunk-FLS2FJM6.cjs} +0 -0
- /package/dist/{chunk-KWGB3YNI.js → chunk-PFKVHUOT.js} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {c,a as a$2,b as b$1,e,h}from'./chunk-JV4HJBXW.js';import {a as a$4}from'./chunk-3TAUNYEM.js';import {n,M,p,q,o,w,G,E,s,t,u,v}from'./chunk-HRAY65XH.js';import {ia,oa,fa,ma,$,ha,ca,pa,ra,J}from'./chunk-3NSZZCOJ.js';import {a,c as c$1,b as b$2,d}from'./chunk-SLMIYECU.js';import {a as a$1}from'./chunk-P6JITOFF.js';import {a as a$3}from'./chunk-JA44K75G.js';import {g}from'./chunk-Y2YAKDEQ.js';if (typeof window === "undefined") { const { createRequire } = await import(/* @vite-ignore */ 'module'); createRequire(import.meta.url); }
|
|
2
|
+
g();g();g();function b(f,t="postgres"){switch(f.type){case "text":case "email":case "password":case "color":case "icon":return t==="sqlite"?"text":"varchar";case "textarea":case "code":case "markdown":case "secret":return "text";case "number":return f.integer?"integer":"decimal";case "checkbox":return "boolean";case "date":return "timestamp";case "select":case "radio":return t==="sqlite"?"text":"varchar";case "richtext":case "json":case "array":case "group":case "blocks":case "row":case "collapsible":case "tabs":return "jsonb";case "relationship":return t==="sqlite"?"text":"varchar";case "upload":return "jsonb";default:return "jsonb"}}function ue(f,t="postgres"){let i=f.slug.replace(/-/g,"_"),e=[];e.push(`export const ${i} = pgTable('${i}', {`),e.push(" id: uuid('id').primaryKey().defaultRandom(),");for(let s of f.fields){if(s.name==="id"||s.type==="password")continue;let n=b(s,t),o=s.required,a=` ${s.name}: pg.${n}('${s.name}')`;s.unique&&(a+=".unique()"),o||(a+=".nullable()"),s.defaultValue!==void 0&&(typeof s.defaultValue=="string"?a+=`.default('${s.defaultValue}')`:typeof s.defaultValue=="boolean"?a+=`.default(${s.defaultValue})`:a+=`.default(sql\`${JSON.stringify(s.defaultValue)}\`)`),a+=",",e.push(a);}return f.timestamps&&(e.push(" createdAt: pg.timestamp('created_at').defaultNow(),"),e.push(" updatedAt: pg.timestamp('updated_at').defaultNow(),")),e.push(` status: ${t==="sqlite"?"sqlite":"pg"}.varchar('status').default('draft'),`),e.push(` hasDraft: ${t==="sqlite"?"sqlite":"pg"}.boolean('hasDraft').default(false),`),e.push("});"),e.join(`
|
|
3
|
+
`)}function j(f,t){return Array.isArray(f)?f.map(i=>{if(!i||typeof i!="object")return i;let e=i.data?{...i.data}:void 0;if(!e)return i;let s=t.find(n=>n.slug===i.type||n.slug===i.slug);if(!s||!Array.isArray(s.fields))return i;for(let n of s.fields){if(n.name&&(n.type==="upload"||n.type==="image")&&e[n.name]){let o=e[n.name];Array.isArray(o)?e[n.name]=o.map(a=>typeof a=="string"?{id:a}:a):typeof o=="string"&&(e[n.name]={id:o});}if(n.type==="blocks"&&n.name&&e[n.name]){let o=n.blocks||[];e[n.name]=j(e[n.name],o);}}return {...i,data:e}}):f}function C(f){if(typeof f!="string")return f;let t=f.replace(/-/g,"").toLowerCase();return t.length===32?`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`:f}var O=class extends a{client;schema;_schemaEnsured=false;dialect;connectionString;versionsTableReady=false;rawClient;constructor(t){if(super(),this.schema=t.schema||{},t.connectionString){this.connectionString=t.connectionString;let i=t.connectionString.toLowerCase();i.startsWith("postgres://")||i.startsWith("postgresql://")?this.dialect="postgres":i.includes(".db")||i.includes("sqlite")||i.includes("file:")?this.dialect="sqlite":this.dialect=t.type||"postgres";}else this.rawClient=t.client,this.client=t.client,this.dialect=t.type||"sqlite";}prepareData(t,i){let e=super.prepareData(t,i);e.createdAt&&typeof e.createdAt=="string"&&(e.createdAt=new Date(e.createdAt)),e.updatedAt&&typeof e.updatedAt=="string"&&(e.updatedAt=new Date(e.updatedAt));for(let s of i.fields)if(s.type==="date"&&s.name){let n=e[s.name];n&&typeof n=="string"&&(e[s.name]=new Date(n));}for(let s of i.fields){let o=b(s,this.dialect)==="jsonb";if(s.type==="tabs"&&"tabs"in s&&s.name){let a=t[s.name];if(a&&typeof a=="object"){let r={};for(let[l,c]of Object.entries(a)){let u=s.tabs.flatMap(g=>g.fields).find(g=>g.name===l);(u?.type==="upload"||u?.type==="image"||u?.type==="list"||u?.type==="relationship-block")&&c?r[l]=Array.isArray(c)||typeof c=="object"?JSON.stringify(c):c:r[l]=c;}e[s.name]=this.dialect==="sqlite"||!o?JSON.stringify(r):r;}}else if(o&&s.name&&t[s.name]!==void 0&&t[s.name]!==null)e[s.name]=this.dialect==="sqlite"?JSON.stringify(t[s.name]):t[s.name];else if((s.type==="upload"||s.type==="image"||s.type==="list"||s.type==="relationship-block")&&s.name){let a=t[s.name];a!=null&&(e[s.name]=this.dialect==="sqlite"||!o?typeof a=="string"?a:JSON.stringify(a):a);}}for(let s of i.fields)if(s.name&&e[s.name]===""){let n=b(s,this.dialect);(n==="timestamp"||n==="jsonb"||n==="decimal"||n==="integer"||n==="numeric"||n==="boolean")&&(e[s.name]=null);}return e}async connect(){if(this.connectionString&&!this.client){if(this.dialect==="postgres"){let t,i;try{t=(await import('./src-QBADSZV4.js')).default,i=(await import('./postgres-js-JLFIWOBH.js')).drizzle;}catch{a$1(["postgres","drizzle-orm"]),t=(await import('./src-QBADSZV4.js')).default,i=(await import('./postgres-js-JLFIWOBH.js')).drizzle;}let e=t(this.connectionString,{onnotice:()=>{}});this.client=i(e,{schema:this.schema});}else if(this.dialect==="sqlite"){let t,i;try{t=(await import('better-sqlite3')).default,i=(await import('./better-sqlite3-B34RIU4C.js')).drizzle;}catch{a$1(["better-sqlite3","drizzle-orm"]),t=(await import('better-sqlite3')).default,i=(await import('./better-sqlite3-B34RIU4C.js')).drizzle;}let e=new t(this.connectionString.replace("file:",""));this.client=i(e,{schema:this.schema});}}if(this.rawClient&&typeof this.rawClient.prepare=="function"&&typeof this.client?.select!="function"){let{drizzle:t}=await import('./d1-HPB6B253.js');this.client=t(this.rawClient,{schema:this.schema});}this.connected=true;}async init(t,i=[]){if(await super.init(t,i),(this.connectionString&&!this.client||this.rawClient&&typeof this.client?.select!="function")&&await this.connect(),this.client&&!this._schemaEnsured){for(let s of t){let n=this.getTableName(s.slug);this.schema[n]||(this.schema[n]=this.createTableFromConfig(s));}await this.ensureCollectionTables(t);let e=i.map(s=>({slug:`_globals_${s.slug}`,fields:s.fields,label:s.label}));for(let s of e){let n=this.getTableName(s.slug);this.schema[n]||(this.schema[n]=this.createTableFromConfig(s,true)),this.collections.has(s.slug)||this.collections.set(s.slug,s);}await this.ensureCollectionTables(e),this._schemaEnsured=true;}}createTableFromConfig(t,i=false){let e$1=this.getTableName(t.slug),s={id:i?ia("id").primaryKey():oa("id").primaryKey().defaultRandom()};for(let n of t.fields){if(!n.name||n.name==="id"||n.type==="password")continue;let o=b(n,this.dialect),a=n.name.replace(/-/g,"_"),r=a.replace(/([A-Z])/g,"_$1").toLowerCase(),l;if(this.dialect==="sqlite")switch(o){case "varchar":case "text":l=c(r);break;case "integer":l=a$2(r);break;case "decimal":case "numeric":l=b$1(r);break;case "boolean":l=a$2(r,{mode:"boolean"});break;case "timestamp":l=c(r);break;case "jsonb":l=c(r);break;default:l=c(r);}else switch(o){case "varchar":l=pa(r,{length:255});break;case "integer":l=ca(r);break;case "decimal":l=ha(r);break;case "boolean":l=$(r);break;case "timestamp":l=ma(r);break;case "jsonb":l=fa(r);break;default:l=ia(r);}n.required||(l=l.default(null)),s[a]=l;}return s.createdAt||(s.createdAt=this.dialect==="sqlite"?c("created_at").default(new Date().toISOString()):ma("created_at").defaultNow()),s.updatedAt||(s.updatedAt=this.dialect==="sqlite"?c("updated_at").default(new Date().toISOString()):ma("updated_at").defaultNow()),e$1!=="users"&&e$1!=="audit_logs"&&(s.status||(s.status=this.dialect==="sqlite"?c("status").default("draft"):pa("status",{length:20}).default("draft")),s.hasDraft||(s.hasDraft=this.dialect==="sqlite"?a$2("hasDraft",{mode:"boolean"}).default(false):$("hasDraft").default(false))),this.dialect==="sqlite"?e(e$1,s):ra(e$1,s)}async ensureCollectionTables(t){let i=[];for(let e of t){let s=e.slug.startsWith("_globals_"),n=this.getTableName(e.slug),o=this.generateCreateColumns(e),a=e.fields.some(u=>u.name==="createdAt"),r=e.fields.some(u=>u.name==="updatedAt"),l=e.fields.some(u=>u.name==="status"),c=e.fields.some(u=>u.name==="hasDraft");if(this.dialect==="postgres"){let u=s?'"id" TEXT PRIMARY KEY':'"id" UUID PRIMARY KEY DEFAULT gen_random_uuid()';i.push(`
|
|
4
|
+
CREATE TABLE IF NOT EXISTS "${n}" (
|
|
5
|
+
${u},
|
|
6
|
+
${o}
|
|
7
|
+
${a?"":'"created_at" TIMESTAMP NOT NULL DEFAULT NOW(),'}
|
|
8
|
+
${r?"":'"updated_at" TIMESTAMP NOT NULL DEFAULT NOW(),'}
|
|
9
|
+
${l?"":`"status" VARCHAR(20) DEFAULT 'draft',`}
|
|
10
|
+
${c?"":'"hasDraft" BOOLEAN DEFAULT false'}
|
|
11
|
+
)
|
|
12
|
+
`);}else i.push(`
|
|
13
|
+
CREATE TABLE IF NOT EXISTS "${n}" (
|
|
14
|
+
"id" TEXT PRIMARY KEY,
|
|
15
|
+
${o}
|
|
16
|
+
${a?"":`"created_at" TEXT NOT NULL DEFAULT (datetime('now')),`}
|
|
17
|
+
${r?"":`"updated_at" TEXT NOT NULL DEFAULT (datetime('now')),`}
|
|
18
|
+
${l?"":`"status" TEXT DEFAULT 'draft',`}
|
|
19
|
+
${c?"":'"hasDraft" INTEGER DEFAULT 0'}
|
|
20
|
+
)
|
|
21
|
+
`);}if(i.length>0)if(this.dialect==="postgres")await this.executeRaw(J.raw(i.join(`;
|
|
22
|
+
`)));else for(let e of i)await this.executeRaw(J.raw(e));for(let e of t){let s=this.getTableName(e.slug);s==="users"||s==="audit_logs"||await this.syncTableColumns(e,s);}}getColumnSqlDefinition(t,i){let e=b(t,i),s=t.name.replace(/-/g,"_").replace(/([A-Z])/g,"_$1").toLowerCase(),n=this.columnSqlType(e,i);return `"${s}" ${n} DEFAULT NULL`}columnSqlType(t,i){if(i==="sqlite")switch(t){case "varchar":return "TEXT";case "text":return "TEXT";case "integer":return "INTEGER";case "decimal":case "numeric":return "NUMERIC";case "boolean":return "INTEGER";case "timestamp":return "TEXT";case "jsonb":return "TEXT";default:return "TEXT"}switch(t){case "varchar":return "VARCHAR(255)";case "text":return "TEXT";case "integer":return "INTEGER";case "decimal":case "numeric":return "DECIMAL";case "boolean":return "BOOLEAN";case "timestamp":return "TIMESTAMP";case "jsonb":return "JSONB";default:return "TEXT"}}getExpectedColumnDefs(t,i){let e={},s=t.slug.startsWith("_globals_"),n=t.fields.some(l=>l.name==="createdAt"),o=t.fields.some(l=>l.name==="updatedAt"),a=t.fields.some(l=>l.name==="status"),r=t.fields.some(l=>l.name==="hasDraft");this.dialect==="postgres"?(e.id=s?'"id" TEXT PRIMARY KEY':'"id" UUID PRIMARY KEY DEFAULT gen_random_uuid()',n||(e.created_at='"created_at" TIMESTAMP DEFAULT NULL'),o||(e.updated_at='"updated_at" TIMESTAMP DEFAULT NULL'),a||(e.status='"status" VARCHAR(20) DEFAULT NULL'),r||(e.hasDraft='"hasDraft" BOOLEAN DEFAULT NULL')):(e.id='"id" TEXT PRIMARY KEY',n||(e.created_at='"created_at" TEXT DEFAULT NULL'),o||(e.updated_at='"updated_at" TEXT DEFAULT NULL'),a||(e.status='"status" TEXT DEFAULT NULL'),r||(e.hasDraft='"hasDraft" INTEGER DEFAULT NULL'));for(let l of t.fields){if(!l.name||l.name==="id")continue;let c=this.getColumnSqlDefinition(l,this.dialect),u=l.name.replace(/-/g,"_").replace(/([A-Z])/g,"_$1").toLowerCase();e[u]=c;}return e}async syncTableColumns(t,i){let e;try{if(this.dialect==="postgres"){let o=await this.executeRaw(J`SELECT column_name, data_type, character_maximum_length FROM information_schema.columns WHERE table_name = ${i}`);e=new Map(o.map(a=>[a.column_name,{type:a.data_type,maxLen:a.character_maximum_length}]));}else {let o=await this.executeRaw(J`PRAGMA table_info("${J.raw(i)}")`);e=new Map(o.map(a=>[a.name,{type:a.type,maxLen:null}]));}}catch{return}let s=this.getExpectedColumnDefs(t,i),n=Object.keys(s).filter(o=>!e.has(o));if(n.length>0){let o=n.map(a=>`ALTER TABLE "${i}" ADD COLUMN ${s[a]}`);await this.executeRaw(J.raw(o.join(`;
|
|
23
|
+
`)));}if(this.dialect==="postgres")for(let o of t.fields){if(!o.name||o.name==="id")continue;let a=b(o,this.dialect),r=o.name.replace(/-/g,"_").replace(/([A-Z])/g,"_$1").toLowerCase(),l=e.get(r);!l||l.type!=="character varying"||(a==="text"?await this.executeRaw(J.raw(`ALTER TABLE "${i}" ALTER COLUMN "${r}" TYPE TEXT`)):a==="jsonb"&&(await this.executeRaw(J.raw(`ALTER TABLE "${i}" ALTER COLUMN "${r}" DROP DEFAULT`)),await this.executeRaw(J.raw(`ALTER TABLE "${i}" ALTER COLUMN "${r}" TYPE JSONB USING (CASE WHEN "${r}" IS NULL THEN NULL WHEN "${r}"::text ~ '^\\s*\\{' THEN "${r}"::jsonb ELSE jsonb_build_object('id', "${r}"::text) END)`))));}}generateCreateColumns(t){let i=[];for(let e of t.fields){if(!e.name||e.name==="id")continue;let s=b(e,this.dialect),n=e.name.replace(/-/g,"_").replace(/([A-Z])/g,"_$1").toLowerCase(),o=e.required?"NOT NULL":"DEFAULT NULL",a;if(this.dialect==="sqlite")switch(s){case "varchar":case "text":a=`TEXT ${o}`;break;case "integer":a=`INTEGER ${o}`;break;case "decimal":case "numeric":a=`NUMERIC ${o}`;break;case "boolean":a=`INTEGER ${o}`;break;case "timestamp":a=`TEXT ${o}`;break;case "jsonb":a=`TEXT ${o}`;break;default:a=`TEXT ${o}`;}else switch(s){case "varchar":a=`VARCHAR(255) ${o}`;break;case "integer":a=`INTEGER ${o}`;break;case "decimal":a=`DECIMAL ${o}`;break;case "boolean":a=`BOOLEAN ${o}`;break;case "timestamp":a=`TIMESTAMP ${o}`;break;case "jsonb":a=`JSONB ${o}`;break;default:a=`TEXT ${o}`;}i.push(`"${n}" ${a}`);}return i.join(`,
|
|
24
|
+
`)+(i.length>0?",":"")}async disconnect(){this.connected=false;}async find(t){let{collection:i,where:e={},sort:s,limit:n$1=10,page:o=1,tenantId:a,select:r,draft:l}=t,c=this.getCollection(i),u=this.getTable(i),m={...e};this.tenantContext&&c.tenantScoped&&(m=c$1({where:m},i,this.tenantContext,b$2).where||{});let g=this.buildWhereClause(m,c,u,a),y=c.fields.find(h=>h.name==="status"),p$1=y?.type==="select"&&Array.isArray(y.options)&&y.options.some(h=>h.value==="published");!l&&u.status&&p$1&&g.push(n(u.status,"published"));let E=this.parseSort(s),A=!l&&u.status&&p$1?{...m,status:"published"}:m,fe=await this.count({collection:i,where:A,tenantId:a}),pe=(o-1)*n$1,z=[];try{let h=u[E.field]||u.createdAt||u.id,$=E.direction==="asc"?h:M(h),D=this.client.select().from(u);g.length>0&&(D=D.where(p(...g))),z=await D.orderBy($).limit(n$1).offset(pe);}catch(h){console.error("[DrizzleAdapter] Query error:",h);}let R=z.map(h=>this.processResult(h,c));return this.tenantContext&&!this.tenantContext.isSuperAdmin&&(R=R.filter(h=>d(h,i,this.tenantContext,b$2))),l&&(R=await Promise.all(R.map(async h=>{let $=await this.executeRaw(J`
|
|
25
|
+
SELECT * FROM kyro_versions
|
|
26
|
+
WHERE collection_slug = ${i}
|
|
27
|
+
AND document_id = ${h.id}
|
|
28
|
+
ORDER BY created_at DESC
|
|
29
|
+
LIMIT 1
|
|
30
|
+
`);if($.length>0){let D=$[0],w=D.data;for(;typeof w=="string";)try{w=JSON.parse(w);}catch{break}return (!w||typeof w!="object"||Array.isArray(w))&&(w={}),{...h,...w,status:h.status,_hasUnpublishedChanges:D.status==="draft"}}return h}))),{docs:R,...this.calculatePagination(o,n$1,fe)}}async findByID(t){let{collection:i,id:e,tenantId:s,draft:n$1}=t,o=this.getCollection(i),a=this.getTable(i),r=this.dialect==="postgres"&&typeof e=="string"?C(e):e;if(this.tenantContext&&o.tenantScoped){let p={id:r,tenantId:this.tenantContext.tenantId};if(!d(p,i,this.tenantContext,b$2))return null}let l=[n(a.id,r)];s&&a.tenantId&&l.push(n(a.tenantId,s));let c=o.fields.find(p=>p.name==="status"),u=c?.type==="select"&&Array.isArray(c.options)&&c.options.some(p=>p.value==="published");!n$1&&a.status&&u&&l.push(n(a.status,"published"));let m=l.length>1?p(...l):l[0],g=await this.client.select().from(a).where(m);if(g.length===0)return null;let y=this.processResult(g[0],o);if(n$1){let p=await this.executeRaw(J`
|
|
31
|
+
SELECT * FROM kyro_versions
|
|
32
|
+
WHERE collection_slug = ${i}
|
|
33
|
+
AND document_id = ${y.id}
|
|
34
|
+
ORDER BY created_at DESC
|
|
35
|
+
LIMIT 1
|
|
36
|
+
`);if(p.length>0){let E=p[0],A=E.data;for(;typeof A=="string";)try{A=JSON.parse(A);}catch{break}(!A||typeof A!="object"||Array.isArray(A))&&(A={}),y={...y,...A,status:y.status,_hasUnpublishedChanges:E.status==="draft"};}}return y}async create(t){let{collection:i,data:e,tenantId:s}=t,n=this.getCollection(i),o=this.getTable(i),a=this.prepareData(e,n);s&&n.tenantScoped&&(a.tenantId=s);let r=await this.client.insert(o).values(a).returning();return this.processResult(r[0],n)}async update(t){let{collection:i,id:e,data:s,tenantId:n$1}=t,o=this.getCollection(i),a=this.getTable(i),r=this.prepareData(s,o),l=this.dialect==="postgres"&&typeof e=="string"?C(e):e,c=[n(a.id,l)];n$1&&a.tenantId&&c.push(n(a.tenantId,n$1));let u=await this.client.update(a).set(r).where(p(...c)).returning();if(u.length===0)throw new Error(`Document not found: ${i}/${e}`);return this.processResult(u[0],o)}async delete(t){let{collection:i,id:e,tenantId:s}=t,n$1=this.getCollection(i),o=this.getTable(i),a=this.dialect==="postgres"&&typeof e=="string"?C(e):e,r=[n(o.id,a)];s&&o.tenantId&&r.push(n(o.tenantId,s));let l=await this.client.delete(o).where(p(...r)).returning();if(l.length===0)throw new Error(`Document not found: ${i}/${e}`);return this.processResult(l[0],n$1)}async count(t){let{collection:i,where:e={},tenantId:s}=t,n=this.getCollection(i),o=this.getTable(i),a=this.buildWhereClause(e,n,o,s);try{let r=this.client.select({count:J`count(*)`}).from(o);a.length>0&&(r=r.where(p(...a)));let l=await r;return Number(l[0]?.count||0)}catch{return 0}}async findOne(t){let{collection:i,where:e={},tenantId:s,draft:n$1}=t;if(i.startsWith("_globals_")){let a=i.replace("_globals_",""),r=this.globals.get(a);if(!r)throw new Error(`Global "${a}" not found`);let l=this.getTable(i),c=this.client.select().from(l),u=r.fields.find(p=>p.name==="status"),m=u?.type==="select"&&Array.isArray(u.options)&&u.options.some(p=>p.value==="published");!n$1&&l.status&&m&&(c=c.where(n(l.status,"published")));let g=await c.limit(1);if(g.length===0)return null;let y=this.processResult(g[0],r);if(n$1){let p=await this.executeRaw(J`
|
|
37
|
+
SELECT * FROM kyro_versions
|
|
38
|
+
WHERE collection_slug = ${i}
|
|
39
|
+
AND document_id = ${a}
|
|
40
|
+
ORDER BY created_at DESC
|
|
41
|
+
LIMIT 1
|
|
42
|
+
`);if(p.length>0){let E=p[0],A=typeof E.data=="string"?JSON.parse(E.data):E.data;y={...y,...A,status:y.status,_hasUnpublishedChanges:E.status==="draft"};}}return y}return (await this.find({...t,limit:1})).docs[0]||null}async findVersions(t){await this.ensureVersionsTable();let{collection:i,documentId:e,limit:s=10,page:n=1,tenantId:o}=t,a=(n-1)*s,r=this.getCollection(i),l=await this.executeRaw(J`
|
|
43
|
+
SELECT count(*) as count
|
|
44
|
+
FROM kyro_versions
|
|
45
|
+
WHERE collection_slug = ${i}
|
|
46
|
+
AND document_id = ${e}
|
|
47
|
+
AND autosave = 0
|
|
48
|
+
${o&&r.tenantScoped?J`AND tenant_id = ${o}`:J``}
|
|
49
|
+
`),c=parseInt(l[0]?.count||"0");return {docs:(await this.executeRaw(J`
|
|
50
|
+
SELECT *
|
|
51
|
+
FROM kyro_versions
|
|
52
|
+
WHERE collection_slug = ${i}
|
|
53
|
+
AND document_id = ${e}
|
|
54
|
+
AND autosave = 0
|
|
55
|
+
${o&&r.tenantScoped?J`AND tenant_id = ${o}`:J``}
|
|
56
|
+
ORDER BY created_at DESC
|
|
57
|
+
LIMIT ${s}
|
|
58
|
+
OFFSET ${a}
|
|
59
|
+
`)).map(m=>({...m,data:typeof m.data=="string"?JSON.parse(m.data):m.data})),...this.calculatePagination(n,s,c)}}async findVersionByID(t){await this.ensureVersionsTable();let i=this.getCollection(t.collection),e=await this.executeRaw(J`
|
|
60
|
+
SELECT * FROM kyro_versions
|
|
61
|
+
WHERE id = ${t.versionId}
|
|
62
|
+
AND collection_slug = ${t.collection}
|
|
63
|
+
${t.tenantId&&i.tenantScoped?J`AND tenant_id = ${t.tenantId}`:J``}
|
|
64
|
+
LIMIT 1
|
|
65
|
+
`);if(e.length===0)return null;let s=e[0];return {...s,data:typeof s.data=="string"?JSON.parse(s.data):s.data}}async createVersion(t){await this.ensureVersionsTable();let i=this.getCollection(t.collection),e=new Date().toISOString();if(t.autosave){let o=await this.executeRaw(J`
|
|
66
|
+
SELECT * FROM kyro_versions
|
|
67
|
+
WHERE collection_slug = ${t.collection}
|
|
68
|
+
AND document_id = ${t.documentId}
|
|
69
|
+
AND autosave = 1
|
|
70
|
+
${t.tenantId&&i.tenantScoped?J`AND tenant_id = ${t.tenantId}`:J``}
|
|
71
|
+
LIMIT 1
|
|
72
|
+
`);if(o.length>0)return await this.executeRaw(J`
|
|
73
|
+
UPDATE kyro_versions
|
|
74
|
+
SET data = ${JSON.stringify(t.data)},
|
|
75
|
+
status = ${t.status},
|
|
76
|
+
updated_at = ${e}
|
|
77
|
+
WHERE id = ${o[0].id}
|
|
78
|
+
`),this.findVersionByID({collection:t.collection,versionId:o[0].id,tenantId:t.tenantId})}let s=Math.random().toString(36).substring(2,15),n=typeof t.data=="string"?t.data:JSON.stringify(t.data);if(await this.executeRaw(J`
|
|
79
|
+
INSERT INTO kyro_versions (
|
|
80
|
+
id, collection_slug, document_id, tenant_id, data, status, autosave, created_by, change_description, created_at, updated_at
|
|
81
|
+
) VALUES (
|
|
82
|
+
${s}, ${t.collection}, ${t.documentId}, ${t.tenantId&&i.tenantScoped?t.tenantId:null},
|
|
83
|
+
${n}, ${t.status}, ${t.autosave?1:0}, ${t.createdBy||null},
|
|
84
|
+
${t.changeDescription||null}, ${e}, ${e}
|
|
85
|
+
)
|
|
86
|
+
`),!t.autosave){let o=this.getCollection(t.collection);o.versions?.maxPerDoc&&await this.deleteVersions({collection:t.collection,documentId:t.documentId,keepLatest:o.versions.maxPerDoc,tenantId:t.tenantId});}return this.findVersionByID({collection:t.collection,versionId:s,tenantId:t.tenantId})}async updateLatestVersion(t){return this.createVersion({...t,autosave:true})}async deleteVersions(t){await this.ensureVersionsTable();let i=this.getCollection(t.collection);if(t.keepLatest){let s=(await this.executeRaw(J`
|
|
87
|
+
SELECT id FROM kyro_versions
|
|
88
|
+
WHERE collection_slug = ${t.collection}
|
|
89
|
+
AND document_id = ${t.documentId}
|
|
90
|
+
AND autosave = 0
|
|
91
|
+
${t.tenantId&&i.tenantScoped?J`AND tenant_id = ${t.tenantId}`:J``}
|
|
92
|
+
ORDER BY created_at DESC
|
|
93
|
+
LIMIT ${t.keepLatest}
|
|
94
|
+
`)).map(n=>n.id);s.length>0&&await this.executeRaw(J`
|
|
95
|
+
DELETE FROM kyro_versions
|
|
96
|
+
WHERE collection_slug = ${t.collection}
|
|
97
|
+
AND document_id = ${t.documentId}
|
|
98
|
+
AND autosave = 0
|
|
99
|
+
AND id NOT IN (${J.join(s.map(n=>J`${n}`),J`, `)})
|
|
100
|
+
`);}else await this.executeRaw(J`
|
|
101
|
+
DELETE FROM kyro_versions
|
|
102
|
+
WHERE collection_slug = ${t.collection}
|
|
103
|
+
AND document_id = ${t.documentId}
|
|
104
|
+
${t.tenantId&&i.tenantScoped?J`AND tenant_id = ${t.tenantId}`:J``}
|
|
105
|
+
`);}getTable(t){let i=this.getTableName(t),e=this.schema[i];if(!e)throw new Error(`Table "${i}" not found in schema`);return e}buildWhereClause(t$1,i,e,s$1){let n$1=[];s$1&&i.tenantScoped&&e.tenantId&&n$1.push(n(e.tenantId,s$1));for(let[o$1,a]of Object.entries(t$1)){let r=o$1,l=r.toUpperCase();if(r==="id"&&this.dialect==="postgres"&&(typeof a=="string"?a=C(a):a&&typeof a=="object"&&(a.equals!==void 0&&typeof a.equals=="string"&&(a={...a,equals:C(a.equals)}),a.in&&Array.isArray(a.in)&&(a={...a,in:a.in.map(c=>typeof c=="string"?C(c):c)}))),l==="AND"&&Array.isArray(a)){let c=a.map(u=>this.buildWhereClause(u,i,e)).flat().filter(Boolean);c.length>0&&n$1.push(p(...c));}else if(l==="OR"&&Array.isArray(a)){let c=a.map(u=>this.buildWhereClause(u,i,e)).flat().filter(Boolean);c.length>0&&n$1.push(q(...c));}else if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let c=e[r]||e[r.replace(/-/g,"_")]||e[r.replace(/([A-Z])/g,"_$1").toLowerCase()]||(r==="created_at"?e.createdAt:void 0)||(r==="createdAt"?e.created_at:void 0)||(r==="updated_at"?e.updatedAt:void 0)||(r==="updatedAt"?e.updated_at:void 0);if(!c)continue;a.equals!==void 0&&n$1.push(n(c,a.equals)),a.not_equals!==void 0&&n$1.push(o(c,a.not_equals)),a.in&&Array.isArray(a.in)&&(a.in.length===0?n$1.push(J`1 = 0`):n$1.push(w(c,a.in))),a.like!==void 0&&(this.dialect==="postgres"?n$1.push(G(c,a.like)):n$1.push(E(c,a.like))),a.contains!==void 0&&(this.dialect==="postgres"?n$1.push(G(c,`%${a.contains}%`)):n$1.push(E(c,`%${a.contains}%`))),a.greater_than!==void 0&&n$1.push(s(c,a.greater_than)),a.greater_than_equal!==void 0&&n$1.push(t(c,a.greater_than_equal)),a.less_than!==void 0&&n$1.push(u(c,a.less_than)),a.less_than_equal!==void 0&&n$1.push(v(c,a.less_than_equal));}else {let c=e[r]||e[r.replace(/-/g,"_")]||e[r.replace(/([A-Z])/g,"_$1").toLowerCase()];c&&n$1.push(n(c,a));}}return n$1}processResult(t,i){if(!t)return null;let e={...t};for(let s of Object.keys(e))/^\d+$/.test(s)&&delete e[s];t.id&&(e.id=String(t.id));for(let s of i.fields){if(!s.name)continue;let n=s.name.replace(/-/g,"_").replace(/([A-Z])/g,"_$1").toLowerCase();n!==s.name&&e[n]!==void 0&&e[s.name]===void 0&&(e[s.name]=e[n],delete e[n]);}for(let s of i.fields){if(["json","richtext","array","group","blocks","upload","image","list","relationship-block"].includes(s.type)){let n=s;if(e[n.name]&&typeof e[n.name]=="string")try{let o=JSON.parse(e[n.name]);e[n.name]=o;}catch{}if(s.type==="blocks"&&e[n.name]&&Array.isArray(e[n.name])){let o=n.blocks||[];e[n.name]=j(e[n.name],o);}}if(s.type==="tabs"&&"tabs"in s&&s.name){if(typeof e[s.name]=="object"&&e[s.name]!==null&&!Array.isArray(e[s.name])){for(let o of s.tabs)for(let a of o.fields)if((a.type==="upload"||a.type==="image")&&a.name){let r=e[s.name][a.name];if(typeof r=="string")try{let l=JSON.parse(r);e[s.name][a.name]=Array.isArray(l)?l.map(c=>c&&typeof c=="object"&&typeof c.id=="string"?c.id:String(c||"")):typeof l.id=="string"?l.id:String(l.id||"");}catch{}else r&&typeof r=="object"&&(e[s.name][a.name]=Array.isArray(r)?r.map(l=>l&&typeof l=="object"&&typeof l.id=="string"?l.id:String(l||"")):typeof r.id=="string"?r.id:String(r.id||""));}continue}if(typeof e[s.name]=="string")try{let o=JSON.parse(e[s.name]);if(typeof o=="object"&&o!==null){e[s.name]=o;continue}}catch{}let n={};for(let o of s.tabs)for(let a of o.fields)if(a.name&&e[a.name]!==void 0){let r=e[a.name];if(["json","richtext","array","group","blocks","upload","image","list","relationship-block"].includes(a.type)){if(r&&typeof r=="string")try{r=JSON.parse(r);}catch{}(a.type==="upload"||a.type==="image")&&r&&typeof r=="object"&&(r=Array.isArray(r)?r.map(l=>l&&typeof l=="object"&&typeof l.id=="string"?l.id:String(l||"")):typeof r.id=="string"?r.id:String(r.id||""));}n[a.name]=r,delete e[a.name];}e[s.name]=n;}}return e.createdAt&&(e.createdAt=new Date(e.createdAt).toISOString()),e.updatedAt&&(e.updatedAt=new Date(e.updatedAt).toISOString()),a$3(e)}async ensureVersionsTable(){if(this.versionsTableReady)return;let t;this.dialect==="sqlite"?t=`
|
|
106
|
+
CREATE TABLE IF NOT EXISTS kyro_versions (
|
|
107
|
+
id text PRIMARY KEY,
|
|
108
|
+
collection_slug text NOT NULL,
|
|
109
|
+
document_id text NOT NULL,
|
|
110
|
+
tenant_id text,
|
|
111
|
+
data text NOT NULL,
|
|
112
|
+
status text NOT NULL DEFAULT 'draft',
|
|
113
|
+
autosave integer NOT NULL DEFAULT 0,
|
|
114
|
+
created_by text,
|
|
115
|
+
change_description text,
|
|
116
|
+
created_at text DEFAULT (datetime('now')),
|
|
117
|
+
updated_at text DEFAULT (datetime('now'))
|
|
118
|
+
)
|
|
119
|
+
`:t=`
|
|
120
|
+
CREATE TABLE IF NOT EXISTS kyro_versions (
|
|
121
|
+
id text PRIMARY KEY,
|
|
122
|
+
collection_slug text NOT NULL,
|
|
123
|
+
document_id text NOT NULL,
|
|
124
|
+
tenant_id text,
|
|
125
|
+
data text NOT NULL,
|
|
126
|
+
status text NOT NULL,
|
|
127
|
+
autosave integer NOT NULL DEFAULT 0,
|
|
128
|
+
created_by text,
|
|
129
|
+
change_description text,
|
|
130
|
+
created_at text NOT NULL,
|
|
131
|
+
updated_at text NOT NULL
|
|
132
|
+
)
|
|
133
|
+
`,await this.executeRaw(J.raw(t));try{this.dialect==="postgres"?await this.executeRaw(J.raw("ALTER TABLE kyro_versions ADD COLUMN IF NOT EXISTS autosave integer NOT NULL DEFAULT 0")):await this.executeRaw(J.raw("ALTER TABLE kyro_versions ADD COLUMN autosave integer NOT NULL DEFAULT 0"));}catch{}this.versionsTableReady=true;}async execute(t){return this.executeRaw(t)}async executeRaw(t){let i="",e=[];if(typeof t=="string")i=t;else if(t&&(t.queryChunks||t.decoder))if(this.dialect==="postgres"){let n=new a$4().sqlToQuery(t);i=n.sql,e=n.params;}else {let n=new h().sqlToQuery(t);i=n.sql,e=n.params;}else if(t&&typeof t.toSQL=="function"){let n=t.toSQL();i=n.sql,e=n.params||[];}else i=String(t);let s=this.rawClient||this.client;if(s?.prepare&&typeof s.prepare=="function"){let n=s.prepare(i);return (e.length>0?await n.bind(...e).all():await n.all()).results||[]}if(typeof this.client?.execute=="function"){let n=await this.client.execute(t);return Array.isArray(n)?n:Array.isArray(n?.rows)?n.rows:Array.isArray(n?.[0])?n[0]:[]}return []}};function he(f){return new O(f)}export{b as a,ue as b,O as c,he as d};
|