@stacksjs/cms 0.70.84 → 0.70.85

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- var Df=Object.defineProperty;var uf=(f)=>f;function lf(f,M){this[f]=uf.bind(null,M)}var Q=(f,M)=>{for(var B in M)Df(f,B,{get:M[B],enumerable:!0,configurable:!0,set:lf.bind(M,B)})};var nf=import.meta.require;var V={};Q(V,{update:()=>u,store:()=>p,findOrCreate:()=>m,findByUuid:()=>q,findByUserId:()=>c,findByName:()=>I,findByEmail:()=>T,fetchById:()=>R,fetchAll:()=>v,destroy:()=>N});var h;async function x(){return h??=import("@stacksjs/database").then((f)=>f.db),h}async function N(f){let M=await x();try{let B=await M.deleteFrom("authors").where("id","=",f).returningAll().executeTakeFirst();if(!B)throw Error(`Author with ID ${f} not found`);return B}catch(B){if(B instanceof Error)throw TypeError(`Author with ID ${f} not found`);throw B}}async function R(f){return await(await x()).selectFrom("authors").where("id","=",f).selectAll().executeTakeFirst()}async function v(){return await(await x()).selectFrom("authors").selectAll().execute()}async function I(f){return await(await x()).selectFrom("authors").where("name","=",f).selectAll().executeTakeFirst()}async function T(f){return await(await x()).selectFrom("authors").where("email","=",f).selectAll().executeTakeFirst()}async function q(f){return await(await x()).selectFrom("authors").where("uuid","=",f).selectAll().executeTakeFirst()}async function c(f){return await(await x()).selectFrom("authors").where("user_id","=",f).selectAll().executeTakeFirst()}var{randomUUIDv7:w}=globalThis.Bun;import{HttpError as Z}from"@stacksjs/error-handling";import{formatDate as X,isUniqueViolation as y}from"@stacksjs/orm";async function m(f){let M=await x();try{let B=await M.selectFrom("authors").where((S)=>S.or([S("email","=",f.email),S("name","=",f.name)])).selectAll().executeTakeFirst();if(B)return B;let P=await M.selectFrom("users").where("email","=",f.email).selectAll().executeTakeFirst();if(!P){let S=await M.insertInto("users").values({email:f.email,name:f.name,password:w(),uuid:w(),created_at:X(new Date),updated_at:X(new Date)}).returningAll().executeTakeFirst();if(!S)throw Error("Failed to create user");P=S}let C={user_id:P.id,name:f.name,email:f.email,created_at:X(new Date),updated_at:X(new Date)},G=await M.insertInto("authors").values(C).returningAll().executeTakeFirst();if(!G)throw Error("Failed to create author");return G}catch(B){if(B instanceof Z)throw B;if(y(B))throw new Z(409,"An author with this email already exists");if(B instanceof Error)throw TypeError(`Failed to find or create author: ${B.message}`);throw B}}async function p(f){let M=await x();try{let B=await M.selectFrom("authors").where((G)=>G.or([G("email","=",f.email),G("name","=",f.name)])).selectAll().executeTakeFirst();if(B)return B;let P={user_id:f.user_id,name:f.name,email:f.email,created_at:X(new Date),updated_at:X(new Date)},C=await M.insertInto("authors").values(P).returningAll().executeTakeFirst();if(!C)throw Error("Failed to create author");return C}catch(B){if(B instanceof Z)throw B;if(y(B))throw new Z(409,"An author with this email already exists");if(B instanceof Error)throw TypeError(`Failed to find or create author: ${B.message}`);throw B}}import{HttpError as D}from"@stacksjs/error-handling";import{formatDate as gf,isUniqueViolation as bf}from"@stacksjs/orm";async function u(f,M){let B=await x();try{let P={...M,updated_at:gf(new Date)};return await B.updateTable("authors").set(P).where("id","=",f).returningAll().executeTakeFirst()}catch(P){if(P instanceof D)throw P;if(bf(P))throw new D(409,"An author with this email already exists");if(P instanceof Error)throw TypeError(`Failed to update author: ${P.message}`);throw P}}var E={};Q(E,{update:()=>t,storeCategorizableModel:()=>r,store:()=>d,fetchWithPosts:()=>b,fetchBySlug:()=>g,fetchByName:()=>n,fetchById:()=>$,fetchAll:()=>l,destroy:()=>s,bulkStore:()=>e,bulkDestroy:()=>i});import{slugify as EB}from"ts-slug";async function $(f){return await(await x()).selectFrom("categorizables").where("id","=",f).where("is_active","=",!0).selectAll().executeTakeFirst()}async function l(){return await(await x()).selectFrom("categorizables").selectAll().execute()}async function n(f){return await(await x()).selectFrom("categorizables").where("name","=",f).where("is_active","=",!0).selectAll().execute()}async function g(f){return await(await x()).selectFrom("categorizables").where("slug","=",f).where("is_active","=",!0).selectAll().executeTakeFirst()}async function b(f){return await(await x()).selectFrom("categorizables").where("id","=",f).where("is_active","=",!0).selectAll().executeTakeFirst()}async function s(f){let M=await x();try{if(!await $(f))throw Error(`Category with ID ${f} not found`);return(await M.deleteFrom("categorizables").where("id","=",f).executeTakeFirst()).numDeletedRows>0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete category: ${B.message}`);throw B}}async function i(f){let M=await x();if(!f.length)return 0;try{let B=await M.deleteFrom("categorizables").where("id","in",f).executeTakeFirst();return Number(B.numDeletedRows)||0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete categories in bulk: ${B.message}`);throw B}}import{slugify as o}from"ts-slug";async function d(f){let M=await x();try{if(!f.name||f.name.trim()==="")throw Error("Category name is required");if(!f.categorizable_type||f.categorizable_type.trim()==="")throw Error("Category categorizable_type is required");let B={name:f.name,slug:o(f.name),description:f.description,categorizable_type:f.categorizable_type,is_active:f.is_active??!0},P=await M.insertInto("categorizables").values(B).returningAll().executeTakeFirst();if(!P)throw Error("Failed to create category");return P}catch(B){if(B instanceof Error)throw TypeError(`Failed to create category: ${B.message}`);throw B}}async function r(f){let M=await x();try{let B={category_id:f.category_id,categorizable_type:f.categorizable_type},P=await M.insertInto("categorizable_models").values(B).returningAll().executeTakeFirst();if(!P)throw Error("Failed to create categorizable model relationship");return P}catch(B){if(B instanceof Error)throw TypeError(`Failed to create categorizable model relationship: ${B.message}`);throw B}}async function e(f){let M=await x();try{return await M.transaction(async(P)=>{let C=[];for(let G of f){let S={name:G.name,slug:o(G.name),description:G.description,categorizable_type:G.categorizable_type,is_active:G.is_active??!0},A=await P.insertInto("categorizables").values(S).returningAll().executeTakeFirst();if(!A)throw Error(`Failed to create category: ${G.name}`);C.push(A)}return C})}catch(B){if(B instanceof Error)throw TypeError(`Failed to create categories: ${B.message}`);throw B}}import{slugify as sf}from"ts-slug";async function t(f){let M=await x();try{let B=f.id;if(!B)throw Error("Category ID is required for update");if(f.name!==void 0){if(f.name.trim()==="")throw Error("Category name cannot be empty");f.slug=sf(f.name)}let{id:P,...C}=f,G=await M.updateTable("categorizables").set(C).where("id","=",B).returningAll().executeTakeFirst();if(!G)throw Error("Failed to update category");return G}catch(B){if(B instanceof Error)throw TypeError(`Failed to update category: ${B.message}`);throw B}}var _={};Q(_,{update:()=>Jf,store:()=>Af,fetchStatusDistributionDonut:()=>Cf,fetchPostsWithMostComments:()=>H,fetchMonthlyCommentCounts:()=>Gf,fetchCommentsByStatus:()=>Mf,fetchCommentsByCommentables:()=>ff,fetchComments:()=>a,fetchCommentCountByPeriod:()=>Bf,fetchCommentCountBarGraph:()=>xf,fetchCommentById:()=>z,destroy:()=>Sf,calculateApprovalRate:()=>Pf,bulkDestroy:()=>Wf});import{formatDate as Y}from"@stacksjs/orm";async function a(f={}){let B=(await x()).selectFrom("commentables");if(f.status)B=B.where("status","=",f.status);if(f.commentables_id)B=B.where("commentables_id","=",f.commentables_id);if(f.commentables_type)B=B.where("commentables_type","=",f.commentables_type);if(f.limit)B=B.limit(f.limit);if(f.offset)B=B.offset(f.offset);return B.selectAll().execute()}async function z(f){return(await x()).selectFrom("commentables").where("id","=",f).selectAll().executeTakeFirst()}async function ff(f,M,B={}){let C=(await x()).selectFrom("commentables").where("commentables_id","=",f).where("commentables_type","=",M);if(B.status)C=C.where("status","=",B.status);if(B.limit)C=C.limit(B.limit);if(B.offset)C=C.offset(B.offset);return C.selectAll().execute()}async function Bf(f){let M=await x();try{let B=await M.selectFrom("commentables").where("created_at",">=",new Date(Date.now()-f*24*60*60*1000).toISOString()).count();return Number(B)||0}catch(B){if(B instanceof Error)throw TypeError(`Failed to fetch comment count: ${B.message}`);throw B}}async function Mf(f,M={}){let B=await x();try{let P=B.selectFrom("commentables").where("status","=",f);if(M.limit)P=P.limit(M.limit);if(M.offset)P=P.offset(M.offset);return P.selectAll().execute()}catch(P){if(P instanceof Error)throw TypeError(`Failed to fetch comments by status: ${P.message}`);throw P}}async function Pf(){let f=await x();try{let[M,B]=await Promise.all([f.selectFrom("commentables").where("status","=","approved").count(),f.selectFrom("commentables").count()]),P=Number(M||0),C=Number(B||0),G=C>0?P/C*100:0;return{approved:P,total:C,rate:G}}catch(M){if(M instanceof Error)throw TypeError(`Failed to calculate approval rate: ${M.message}`);throw M}}async function H(f,M={}){let B=await x();try{let P=B.selectFrom("posts").leftJoin("commentables","posts.id","=","commentables.commentables_id").where("commentables.created_at",">=",Y(f.startDate)).where("commentables.created_at","<=",Y(f.endDate)).select(["posts.id","posts.title"]).groupBy("posts.id","posts.title").orderBy("posts.id","desc");if(M.limit)P=P.limit(M.limit);return(await P.execute()).map((G)=>({id:Number(G.id),title:String(G.title),comment_count:Number(G.comment_count||0)}))}catch(P){if(P instanceof Error)throw TypeError(`Failed to fetch posts with most comments: ${P.message}`);throw P}}async function xf(f,M={}){try{let B=await H(f,M);return{labels:B.map((P)=>P.title),values:B.map((P)=>P.comment_count)}}catch(B){if(B instanceof Error)throw TypeError(`Failed to fetch bar graph data: ${B.message}`);throw B}}async function Cf(f){let M=await x();try{let P=await M.selectFrom("commentables").where("created_at",">=",Y(f.startDate)).where("created_at","<=",Y(f.endDate)).select(["status"]).groupBy("status").execute(),C=P.reduce((W,L)=>W+Number(L.count||0),0),G=P.map((W)=>String(W.status)),S=P.map((W)=>Number(W.count||0)),A=S.map((W)=>C>0?W/C*100:0);return{labels:G,values:S,percentages:A}}catch(B){if(B instanceof Error)throw TypeError(`Failed to fetch status distribution: ${B.message}`);throw B}}async function Gf(f){let M=await x();try{let B=await M.selectFrom("commentables").where("created_at",">=",Y(f.startDate)).where("created_at","<=",Y(f.endDate)).select(["created_at"]).groupBy("created_at").orderBy("created_at","asc").execute(),P=new Map;B.forEach((S)=>{if(!S.created_at)return;let A=new Date(S.created_at),W=`${A.getFullYear()}-${String(A.getMonth()+1).padStart(2,"0")}`;P.set(W,(P.get(W)||0)+Number(S.count||0))});let C=[],G=[];return P.forEach((S,A)=>{let[W,L]=A.split("-");C.push(new Date(Number(W),Number(L)-1).toLocaleString("default",{month:"short",year:"numeric"})),G.push(S)}),{labels:C,values:G}}catch(B){if(B instanceof Error)throw TypeError(`Failed to fetch monthly comment counts: ${B.message}`);throw B}}async function Sf(f){let M=await x();try{if(!await z(f))throw Error(`Comment with ID ${f} not found`);return(await M.deleteFrom("commentables").where("id","=",f).executeTakeFirst()).numDeletedRows>0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete comment: ${B.message}`);throw B}}async function Wf(f){let M=await x();if(!f.length)return 0;try{let B=await M.deleteFrom("commentables").where("id","in",f).executeTakeFirst();return Number(B.numDeletedRows)||0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete comments in bulk: ${B.message}`);throw B}}async function Af(f){let M=await x();try{if(!f.title||f.title.trim()==="")throw Error("Comment title is required");if(!f.body||f.body.trim()==="")throw Error("Comment body is required");if(!f.commentables_type||f.commentables_type.trim()==="")throw Error("Comment commentables_type is required");let B=["pending","approved","rejected"];if(f.status&&!B.includes(f.status))throw Error(`Invalid comment status: ${f.status}`);let P={title:f.title,body:f.body,status:f.status,commentables_id:f.commentables_id,commentables_type:f.commentables_type,user_id:f.user_id,is_active:f.is_active},C=await M.insertInto("commentables").values(P).returningAll().executeTakeFirst();if(!C)throw Error("Failed to create comment");return C}catch(B){if(B instanceof Error)throw TypeError(`Failed to store comment: ${B.message}`);throw B}}import{formatDate as of}from"@stacksjs/orm";async function Jf(f,M){let B=await x();try{if(M.title!==void 0&&M.title.trim()==="")throw Error("Comment title cannot be empty");if(M.body!==void 0&&M.body.trim()==="")throw Error("Comment body cannot be empty");let P=["pending","approved","rejected"];if(M.status!==void 0&&!P.includes(M.status))throw Error(`Invalid comment status: ${M.status}`);let C={updated_at:of(new Date)};if(M.title!==void 0)C.title=M.title;if(M.body!==void 0)C.body=M.body;if(M.status!==void 0)C.status=M.status;if(M.commentables_id!==void 0)C.commentables_id=M.commentables_id;if(M.commentables_type!==void 0)C.commentables_type=M.commentables_type;if(M.approved_at!==void 0)C.approved_at=M.approved_at;if(M.rejected_at!==void 0)C.rejected_at=M.rejected_at;return await B.updateTable("commentables").set(C).where("id","=",f).execute(),await B.selectFrom("commentables").where("id","=",f).selectAll().executeTakeFirst()}catch(P){if(P instanceof Error)throw TypeError(`Failed to update comment: ${P.message}`);throw P}}var j={};Q(j,{update:()=>Kf,store:()=>kf,fetchPublishedAfter:()=>Zf,fetchByMinViews:()=>Xf,fetchByMinConversions:()=>Yf,fetchById:()=>O,fetchByAuthor:()=>Qf,fetchAll:()=>Lf,destroy:()=>$f,bulkDestroy:()=>zf});async function O(f){return await(await x()).selectFrom("pages").where("id","=",f).selectAll().executeTakeFirst()}async function Lf(){return await(await x()).selectFrom("pages").selectAll().execute()}async function Qf(f){return await(await x()).selectFrom("pages").where("author_id","=",f).selectAll().execute()}async function Xf(f){return await(await x()).selectFrom("pages").where("views",">=",f).selectAll().execute()}async function Yf(f){return await(await x()).selectFrom("pages").where("conversions",">=",f).selectAll().execute()}async function Zf(f){return await(await x()).selectFrom("pages").where("published_at",">",f).selectAll().execute()}async function $f(f){let M=await x();try{if(!await O(f))throw Error(`Page with ID ${f} not found`);return(await M.deleteFrom("pages").where("id","=",f).executeTakeFirst()).numDeletedRows>0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete page: ${B.message}`);throw B}}async function zf(f){let M=await x();if(!f.length)return 0;try{let B=await M.deleteFrom("pages").where("id","in",f).executeTakeFirst();return Number(B.numDeletedRows)||0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete pages in bulk: ${B.message}`);throw B}}import{formatDate as Of}from"@stacksjs/orm";async function kf(f){let M=await x();try{let B={author_id:f.author_id,title:f.title,template:f.template,views:f.views||0,conversions:f.conversions||0,created_at:Of(new Date),updated_at:Of(new Date)},P=await M.insertInto("pages").values(B).returningAll().executeTakeFirst();if(!P)throw Error("Failed to create page");return P}catch(B){if(B instanceof Error)throw TypeError(`Failed to create page: ${B.message}`);throw B}}import{formatDate as df}from"@stacksjs/orm";async function Kf(f,M){let B=await x();try{let P={...M,updated_at:df(new Date)},C=await B.updateTable("pages").set(P).where("id","=",f).returningAll().executeTakeFirst();if(!C)throw Error("Failed to update page");return C}catch(P){if(P instanceof Error)throw TypeError(`Failed to update page: ${P.message}`);throw P}}var U={};Q(U,{update:()=>Tf,sync:()=>If,store:()=>Nf,fetchPublishedAfter:()=>Uf,fetchByStatus:()=>Ef,fetchByMinViews:()=>jf,fetchById:()=>k,fetchByCategory:()=>Hf,fetchByAuthor:()=>_f,fetchAll:()=>Vf,detach:()=>vf,destroy:()=>Ff,bulkDestroy:()=>hf,attach:()=>Rf});async function k(f){return await(await x()).selectFrom("posts").where("id","=",f).selectAll().executeTakeFirst()}async function Vf(){return await(await x()).selectFrom("posts").selectAll().execute()}async function Ef(f){return await(await x()).selectFrom("posts").where("status","=",f).selectAll().execute()}async function Hf(f){return await(await x()).selectFrom("posts").where("category","=",f).selectAll().execute()}async function _f(f){return await(await x()).selectFrom("posts").where("author","=",f).selectAll().execute()}async function jf(f){return await(await x()).selectFrom("posts").where("views",">=",f).selectAll().execute()}async function Uf(f){return await(await x()).selectFrom("posts").where("published_at",">",f).selectAll().execute()}async function Ff(f){let M=await x();try{if(!await k(f))throw Error(`Post with ID ${f} not found`);await M.deleteFrom("categorizable_models").where("categorizable_id","=",f).where("categorizable_type","=","posts").execute();let P=await M.deleteFrom("posts").where("id","=",f).executeTakeFirst();return P?.numDeletedRows?P.numDeletedRows>0:!1}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete post: ${B.message}`);throw B}}async function hf(f){let M=await x();if(!f.length)return 0;try{let P=(await M.selectFrom("posts").select(["id"]).where("id","in",f).execute()).map((G)=>G.id);if(!P.length)return 0;await M.deleteFrom("categorizable_models").where("categorizable_id","in",P).where("categorizable_type","=","posts").execute();let C=await M.deleteFrom("posts").where("id","in",P).executeTakeFirst();return Number(C?.numDeletedRows)||0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete posts in bulk: ${B.message}`);throw B}}var{randomUUIDv7:rf}=globalThis.Bun;import{formatDate as K}from"@stacksjs/orm";var ef="Draft";async function Nf(f){let M=await x();try{if(!f.title||typeof f.title==="string"&&f.title.trim()==="")throw Error("Post title is required");let B=f.content||f.body,P=f,C={author_id:P.author_id,uuid:rf(),title:f.title,poster:f.poster,content:B,body:f.body,category:f.category,excerpt:f.excerpt,is_featured:P.is_featured?Date.now():void 0,views:f.views||0,published_at:P.published_at||Date.now(),status:f.status||ef},G=await M.insertInto("posts").values(C).returningAll().executeTakeFirst();if(!G)throw Error("Failed to create post");return G}catch(B){if(B instanceof Error)throw TypeError(`Failed to create post: ${B.message}`);throw B}}async function Rf(f,M,B){let P=await x();try{let C=M==="categorizable_models"?"categorizable_id":"taggable_id",G=M==="categorizable_models"?"categorizable_type":"taggable_type",S=M==="categorizable_models"?"category_id":"tag_id",A=B.map((W)=>({[S]:W,[C]:f,[G]:"posts",created_at:K(new Date),updated_at:K(new Date)}));for(let W of A)await P.insertInto(M).values(W).execute()}catch(C){if(C instanceof Error)throw TypeError(`Failed to attach records: ${C.message}`);throw C}}async function vf(f,M,B){let P=await x();try{let C=M==="categorizable_models"?"categorizable_id":"taggable_id",G=M==="categorizable_models"?"categorizable_type":"taggable_type",S=P.deleteFrom(M).where(C,"=",f).where(G,"=","posts");if(B)S=S.where("id","in",B);await S.execute()}catch(C){if(C instanceof Error)throw TypeError(`Failed to detach records: ${C.message}`);throw C}}async function If(f,M,B){let P=await x();try{let C=M==="categorizable_models"?"categorizable_id":"taggable_id",G=M==="categorizable_models"?"categorizable_type":"taggable_type",A=(await P.selectFrom(M).select(["id"]).where(C,"=",f).where(G,"=","posts").execute()).map((J)=>J.id),W=A.filter((J)=>!B.includes(J)),L=B.filter((J)=>!A.includes(J));if(W.length>0)await P.deleteFrom(M).where(C,"=",f).where(G,"=","posts").where("id","in",W).execute();if(L.length>0){let J=L.map(()=>({[C]:f,[G]:"posts",created_at:K(new Date),updated_at:K(new Date)}));await P.insertInto(M).values(J).execute()}}catch(C){if(C instanceof Error)throw TypeError(`Failed to sync records: ${C.message}`);throw C}}async function Tf(f,M){let B=await x();try{if(M.title!==void 0&&typeof M.title==="string"&&M.title.trim()==="")throw Error("Post title cannot be empty");let P=["published","draft","archived"];if(M.status!==void 0&&typeof M.status==="string"&&!P.includes(M.status))throw Error(`Invalid post status: ${M.status}`);if(M.views!==void 0&&typeof M.views==="number"&&M.views<0)throw Error("Views count cannot be negative");let C=await B.updateTable("posts").set(M).where("id","=",f).returningAll().executeTakeFirst();if(!C)throw Error("Failed to update post");return C}catch(P){if(P instanceof Error)throw TypeError(`Failed to update post: ${P.message}`);throw P}}var F={};Q(F,{update:()=>pf,store:()=>wf,fetchTags:()=>mf,fetchTagById:()=>yf,destroy:()=>qf,bulkDestroy:()=>cf});async function qf(f){let M=await x();if(!await M.selectFrom("taggables").where("id","=",f).selectAll().executeTakeFirst())throw Error(`Tag with ID ${f} not found`);await M.deleteFrom("taggables").where("id","=",f).executeTakeFirst()}async function cf(f){let M=await x();try{await M.deleteFrom("taggables").where("id","in",f).execute()}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete tags: ${B.message}`);throw B}}import{slugify as tf}from"ts-slug";async function wf(f){let M=await x();try{if(!f.name||f.name.trim()==="")throw Error("Tag name is required");if(!f.taggable_type||f.taggable_type.trim()==="")throw Error("Tag taggable_type is required");let B=tf(f.name);if(await M.selectFrom("taggables").selectAll().where("slug","=",B).executeTakeFirst())throw Error(`Tag with unique slug "${B}" already exists`);let C={name:f.name,slug:B,description:f.description,is_active:f.is_active??!0,taggable_type:f.taggable_type};if(f.taggable_id!==void 0)C.taggable_id=f.taggable_id;let G=await M.insertInto("taggables").values(C).returningAll().executeTakeFirst();if(!G)throw Error("Failed to create tag");return G}catch(B){if(B instanceof Error)throw TypeError(`Failed to store tag: ${B.message}`);throw B}}async function yf(f){let M=await x();try{let B=await M.selectFrom("taggables").where("id","=",f).selectAll().executeTakeFirst();if(!B)return;return B}catch(B){if(B instanceof Error)throw TypeError(`Failed to fetch tag: ${B.message}`);throw B}}async function mf(){let f=await x();try{return await f.selectFrom("taggables").where("is_active","=",!0).selectAll().execute()}catch(M){if(M instanceof Error)throw TypeError(`Failed to fetch tags: ${M.message}`);throw M}}import{uniqueSlug as af}from"@stacksjs/slug";async function pf(f){let M=await x();try{let B=f.id;if(!B)throw Error("Tag ID is required for update");if(f.name!==void 0){if(f.name.trim()==="")throw Error("Tag name cannot be empty");let S=await af(f.name,{table:"taggables",column:"slug"});if(await M.selectFrom("taggables").selectAll().where("slug","=",S).where("id","!=",B).executeTakeFirst())throw Error(`Tag with unique slug "${S}" already exists`);f.slug=S}let{id:P,...C}=f,G=await M.updateTable("taggables").set(C).where("id","=",B).returningAll().executeTakeFirst();if(!G)throw Error("Failed to update tag");return G}catch(B){if(B instanceof Error)throw TypeError(`Failed to update tag: ${B.message}`);throw B}}var fB={posts:U,postCategories:E,tags:F,comments:_,authors:V,pages:j},bM=fB;export{F as tags,U as posts,j as pages,bM as default,_ as comments,fB as cms,E as categorizable,V as authors};
2
+ var Df=Object.defineProperty;var uf=(f)=>f;function lf(f,M){this[f]=uf.bind(null,M)}var Q=(f,M)=>{for(var B in M)Df(f,B,{get:M[B],enumerable:!0,configurable:!0,set:lf.bind(M,B)})};var nf=import.meta.require;var V={};Q(V,{update:()=>u,store:()=>p,findOrCreate:()=>m,findByUuid:()=>q,findByUserId:()=>c,findByName:()=>I,findByEmail:()=>T,fetchById:()=>R,fetchAll:()=>v,destroy:()=>N});var h;async function x(){return h??=import("@stacksjs/database").then((f)=>f.db),h}async function N(f){let M=await x();try{let B=await M.deleteFrom("authors").where("id","=",f).returningAll().executeTakeFirst();if(!B)throw Error(`Author with ID ${f} not found`);return B}catch(B){if(B instanceof Error)throw TypeError(`Author with ID ${f} not found`);throw B}}async function R(f){return await(await x()).selectFrom("authors").where("id","=",f).selectAll().executeTakeFirst()}async function v(){return await(await x()).selectFrom("authors").selectAll().execute()}async function I(f){return await(await x()).selectFrom("authors").where("name","=",f).selectAll().executeTakeFirst()}async function T(f){return await(await x()).selectFrom("authors").where("email","=",f).selectAll().executeTakeFirst()}async function q(f){return await(await x()).selectFrom("authors").where("uuid","=",f).selectAll().executeTakeFirst()}async function c(f){return await(await x()).selectFrom("authors").where("user_id","=",f).selectAll().executeTakeFirst()}var{randomUUIDv7:w}=globalThis.Bun;import{HttpError as Z}from"@stacksjs/error-handling";import{formatDate as X,isUniqueViolation as y}from"@stacksjs/orm";async function m(f){let M=await x();try{let B=await M.selectFrom("authors").where((S)=>S.or([S("email","=",f.email),S("name","=",f.name)])).selectAll().executeTakeFirst();if(B)return B;let P=await M.selectFrom("users").where("email","=",f.email).selectAll().executeTakeFirst();if(!P){let S=await M.insertInto("users").values({email:f.email,name:f.name,password:w(),uuid:w(),created_at:X(new Date),updated_at:X(new Date)}).returningAll().executeTakeFirst();if(!S)throw Error("Failed to create user");P=S}let C={user_id:P.id,name:f.name,email:f.email,created_at:X(new Date),updated_at:X(new Date)},G=await M.insertInto("authors").values(C).returningAll().executeTakeFirst();if(!G)throw Error("Failed to create author");return G}catch(B){if(B instanceof Z)throw B;if(y(B))throw new Z(409,"An author with this email already exists");if(B instanceof Error)throw TypeError(`Failed to find or create author: ${B.message}`);throw B}}async function p(f){let M=await x();try{let B=await M.selectFrom("authors").where((G)=>G.or([G("email","=",f.email),G("name","=",f.name)])).selectAll().executeTakeFirst();if(B)return B;let P={user_id:f.user_id,name:f.name,email:f.email,created_at:X(new Date),updated_at:X(new Date)},C=await M.insertInto("authors").values(P).returningAll().executeTakeFirst();if(!C)throw Error("Failed to create author");return C}catch(B){if(B instanceof Z)throw B;if(y(B))throw new Z(409,"An author with this email already exists");if(B instanceof Error)throw TypeError(`Failed to find or create author: ${B.message}`);throw B}}import{HttpError as D}from"@stacksjs/error-handling";import{formatDate as gf,isUniqueViolation as bf}from"@stacksjs/orm";async function u(f,M){let B=await x();try{let P={...M,updated_at:gf(new Date)};return await B.updateTable("authors").set(P).where("id","=",f).returningAll().executeTakeFirst()}catch(P){if(P instanceof D)throw P;if(bf(P))throw new D(409,"An author with this email already exists");if(P instanceof Error)throw TypeError(`Failed to update author: ${P.message}`);throw P}}var E={};Q(E,{update:()=>t,storeCategorizableModel:()=>r,store:()=>d,fetchWithPosts:()=>b,fetchBySlug:()=>g,fetchByName:()=>n,fetchById:()=>$,fetchAll:()=>l,destroy:()=>s,bulkStore:()=>e,bulkDestroy:()=>i});import{slugify as EB}from"ts-slug";async function $(f){return await(await x()).selectFrom("categorizables").where("id","=",f).where("is_active","=",!0).selectAll().executeTakeFirst()}async function l(){return await(await x()).selectFrom("categorizables").selectAll().execute()}async function n(f){return await(await x()).selectFrom("categorizables").where("name","=",f).where("is_active","=",!0).selectAll().execute()}async function g(f){return await(await x()).selectFrom("categorizables").where("slug","=",f).where("is_active","=",!0).selectAll().executeTakeFirst()}async function b(f){return await(await x()).selectFrom("categorizables").where("id","=",f).where("is_active","=",!0).selectAll().executeTakeFirst()}async function s(f){let M=await x();try{if(!await $(f))throw Error(`Category with ID ${f} not found`);return(await M.deleteFrom("categorizables").where("id","=",f).executeTakeFirst()).numDeletedRows>0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete category: ${B.message}`);throw B}}async function i(f){let M=await x();if(!f.length)return 0;try{let B=await M.deleteFrom("categorizables").where("id","in",f).executeTakeFirst();return Number(B.numDeletedRows)||0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete categories in bulk: ${B.message}`);throw B}}import{slugify as o}from"ts-slug";async function d(f){let M=await x();try{if(!f.name||f.name.trim()==="")throw Error("Category name is required");if(!f.categorizable_type||f.categorizable_type.trim()==="")throw Error("Category categorizable_type is required");let B={name:f.name,slug:o(f.name),description:f.description,categorizable_type:f.categorizable_type,is_active:f.is_active??!0},P=await M.insertInto("categorizables").values(B).returningAll().executeTakeFirst();if(!P)throw Error("Failed to create category");return P}catch(B){if(B instanceof Error)throw TypeError(`Failed to create category: ${B.message}`);throw B}}async function r(f){let M=await x();try{let B={category_id:f.category_id,categorizable_type:f.categorizable_type},P=await M.insertInto("categorizable_models").values(B).returningAll().executeTakeFirst();if(!P)throw Error("Failed to create categorizable model relationship");return P}catch(B){if(B instanceof Error)throw TypeError(`Failed to create categorizable model relationship: ${B.message}`);throw B}}async function e(f){let M=await x();try{return await M.transaction(async(P)=>{let C=[];for(let G of f){let S={name:G.name,slug:o(G.name),description:G.description,categorizable_type:G.categorizable_type,is_active:G.is_active??!0},A=await P.insertInto("categorizables").values(S).returningAll().executeTakeFirst();if(!A)throw Error(`Failed to create category: ${G.name}`);C.push(A)}return C})}catch(B){if(B instanceof Error)throw TypeError(`Failed to create categories: ${B.message}`);throw B}}import{slugify as sf}from"ts-slug";async function t(f){let M=await x();try{let B=f.id;if(!B)throw Error("Category ID is required for update");if(f.name!==void 0){if(f.name.trim()==="")throw Error("Category name cannot be empty");f.slug=sf(f.name)}let{id:P,...C}=f,G=await M.updateTable("categorizables").set(C).where("id","=",B).returningAll().executeTakeFirst();if(!G)throw Error("Failed to update category");return G}catch(B){if(B instanceof Error)throw TypeError(`Failed to update category: ${B.message}`);throw B}}var _={};Q(_,{update:()=>Jf,store:()=>Af,fetchStatusDistributionDonut:()=>Cf,fetchPostsWithMostComments:()=>H,fetchMonthlyCommentCounts:()=>Gf,fetchCommentsByStatus:()=>Mf,fetchCommentsByCommentables:()=>ff,fetchComments:()=>a,fetchCommentCountByPeriod:()=>Bf,fetchCommentCountBarGraph:()=>xf,fetchCommentById:()=>z,destroy:()=>Sf,calculateApprovalRate:()=>Pf,bulkDestroy:()=>Wf});import{formatDate as Y}from"@stacksjs/orm";async function a(f={}){let B=(await x()).selectFrom("commentables");if(f.status)B=B.where("status","=",f.status);if(f.commentables_id)B=B.where("commentables_id","=",f.commentables_id);if(f.commentables_type)B=B.where("commentables_type","=",f.commentables_type);if(f.limit)B=B.limit(f.limit);if(f.offset)B=B.offset(f.offset);return B.selectAll().execute()}async function z(f){return(await x()).selectFrom("commentables").where("id","=",f).selectAll().executeTakeFirst()}async function ff(f,M,B={}){let C=(await x()).selectFrom("commentables").where("commentables_id","=",f).where("commentables_type","=",M);if(B.status)C=C.where("status","=",B.status);if(B.limit)C=C.limit(B.limit);if(B.offset)C=C.offset(B.offset);return C.selectAll().execute()}async function Bf(f){let M=await x();try{let B=await M.selectFrom("commentables").where("created_at",">=",new Date(Date.now()-f*24*60*60*1000).toISOString()).count();return Number(B)||0}catch(B){if(B instanceof Error)throw TypeError(`Failed to fetch comment count: ${B.message}`);throw B}}async function Mf(f,M={}){let B=await x();try{let P=B.selectFrom("commentables").where("status","=",f);if(M.limit)P=P.limit(M.limit);if(M.offset)P=P.offset(M.offset);return P.selectAll().execute()}catch(P){if(P instanceof Error)throw TypeError(`Failed to fetch comments by status: ${P.message}`);throw P}}async function Pf(){let f=await x();try{let[M,B]=await Promise.all([f.selectFrom("commentables").where("status","=","approved").count(),f.selectFrom("commentables").count()]),P=Number(M||0),C=Number(B||0),G=C>0?P/C*100:0;return{approved:P,total:C,rate:G}}catch(M){if(M instanceof Error)throw TypeError(`Failed to calculate approval rate: ${M.message}`);throw M}}async function H(f,M={}){let B=await x();try{let P=B.selectFrom("posts").leftJoin("commentables","posts.id","=","commentables.commentables_id").where("commentables.created_at",">=",Y(f.startDate)).where("commentables.created_at","<=",Y(f.endDate)).select(["posts.id","posts.title"]).groupBy("posts.id","posts.title").orderBy("posts.id","desc");if(M.limit)P=P.limit(M.limit);return(await P.execute()).map((G)=>({id:Number(G.id),title:String(G.title),comment_count:Number(G.comment_count||0)}))}catch(P){if(P instanceof Error)throw TypeError(`Failed to fetch posts with most comments: ${P.message}`);throw P}}async function xf(f,M={}){try{let B=await H(f,M);return{labels:B.map((P)=>P.title),values:B.map((P)=>P.comment_count)}}catch(B){if(B instanceof Error)throw TypeError(`Failed to fetch bar graph data: ${B.message}`);throw B}}async function Cf(f){let M=await x();try{let P=await M.selectFrom("commentables").where("created_at",">=",Y(f.startDate)).where("created_at","<=",Y(f.endDate)).select(["status"]).groupBy("status").execute(),C=P.reduce((W,L)=>W+Number(L.count||0),0),G=P.map((W)=>String(W.status)),S=P.map((W)=>Number(W.count||0)),A=S.map((W)=>C>0?W/C*100:0);return{labels:G,values:S,percentages:A}}catch(B){if(B instanceof Error)throw TypeError(`Failed to fetch status distribution: ${B.message}`);throw B}}async function Gf(f){let M=await x();try{let B=await M.selectFrom("commentables").where("created_at",">=",Y(f.startDate)).where("created_at","<=",Y(f.endDate)).select(["created_at"]).groupBy("created_at").orderBy("created_at","asc").execute(),P=new Map;B.forEach((S)=>{if(!S.created_at)return;let A=new Date(S.created_at),W=`${A.getFullYear()}-${String(A.getMonth()+1).padStart(2,"0")}`;P.set(W,(P.get(W)||0)+Number(S.count||0))});let C=[],G=[];return P.forEach((S,A)=>{let[W,L]=A.split("-");C.push(new Date(Number(W),Number(L)-1).toLocaleString("default",{month:"short",year:"numeric"})),G.push(S)}),{labels:C,values:G}}catch(B){if(B instanceof Error)throw TypeError(`Failed to fetch monthly comment counts: ${B.message}`);throw B}}async function Sf(f){let M=await x();try{if(!await z(f))throw Error(`Comment with ID ${f} not found`);return(await M.deleteFrom("commentables").where("id","=",f).executeTakeFirst()).numDeletedRows>0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete comment: ${B.message}`);throw B}}async function Wf(f){let M=await x();if(!f.length)return 0;try{let B=await M.deleteFrom("commentables").where("id","in",f).executeTakeFirst();return Number(B.numDeletedRows)||0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete comments in bulk: ${B.message}`);throw B}}async function Af(f){let M=await x();try{if(!f.title||f.title.trim()==="")throw Error("Comment title is required");if(!f.body||f.body.trim()==="")throw Error("Comment body is required");if(!f.commentables_type||f.commentables_type.trim()==="")throw Error("Comment commentables_type is required");let B=["pending","approved","rejected"];if(f.status&&!B.includes(f.status))throw Error(`Invalid comment status: ${f.status}`);let P={title:f.title,body:f.body,status:f.status,commentables_id:f.commentables_id,commentables_type:f.commentables_type,user_id:f.user_id,is_active:f.is_active},C=await M.insertInto("commentables").values(P).returningAll().executeTakeFirst();if(!C)throw Error("Failed to create comment");return C}catch(B){if(B instanceof Error)throw TypeError(`Failed to store comment: ${B.message}`);throw B}}import{formatDate as of}from"@stacksjs/orm";async function Jf(f,M){let B=await x();try{if(M.title!==void 0&&M.title.trim()==="")throw Error("Comment title cannot be empty");if(M.body!==void 0&&M.body.trim()==="")throw Error("Comment body cannot be empty");let P=["pending","approved","rejected"];if(M.status!==void 0&&!P.includes(M.status))throw Error(`Invalid comment status: ${M.status}`);let C={updated_at:of(new Date)};if(M.title!==void 0)C.title=M.title;if(M.body!==void 0)C.body=M.body;if(M.status!==void 0)C.status=M.status;if(M.commentables_id!==void 0)C.commentables_id=M.commentables_id;if(M.commentables_type!==void 0)C.commentables_type=M.commentables_type;if(M.approved_at!==void 0)C.approved_at=M.approved_at;if(M.rejected_at!==void 0)C.rejected_at=M.rejected_at;return await B.updateTable("commentables").set(C).where("id","=",f).execute(),await B.selectFrom("commentables").where("id","=",f).selectAll().executeTakeFirst()}catch(P){if(P instanceof Error)throw TypeError(`Failed to update comment: ${P.message}`);throw P}}var j={};Q(j,{update:()=>Kf,store:()=>kf,fetchPublishedAfter:()=>Zf,fetchByMinViews:()=>Xf,fetchByMinConversions:()=>Yf,fetchById:()=>O,fetchByAuthor:()=>Qf,fetchAll:()=>Lf,destroy:()=>$f,bulkDestroy:()=>zf});async function O(f){return await(await x()).selectFrom("pages").where("id","=",f).selectAll().executeTakeFirst()}async function Lf(){return await(await x()).selectFrom("pages").selectAll().execute()}async function Qf(f){return await(await x()).selectFrom("pages").where("author_id","=",f).selectAll().execute()}async function Xf(f){return await(await x()).selectFrom("pages").where("views",">=",f).selectAll().execute()}async function Yf(f){return await(await x()).selectFrom("pages").where("conversions",">=",f).selectAll().execute()}async function Zf(f){return await(await x()).selectFrom("pages").where("published_at",">",f).selectAll().execute()}async function $f(f){let M=await x();try{if(!await O(f))throw Error(`Page with ID ${f} not found`);return(await M.deleteFrom("pages").where("id","=",f).executeTakeFirst()).numDeletedRows>0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete page: ${B.message}`);throw B}}async function zf(f){let M=await x();if(!f.length)return 0;try{let B=await M.deleteFrom("pages").where("id","in",f).executeTakeFirst();return Number(B.numDeletedRows)||0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete pages in bulk: ${B.message}`);throw B}}import{formatDate as Of}from"@stacksjs/orm";async function kf(f){let M=await x();try{let B={author_id:f.author_id,title:f.title,template:f.template,views:f.views||0,conversions:f.conversions||0,created_at:Of(new Date),updated_at:Of(new Date)},P=await M.insertInto("pages").values(B).returningAll().executeTakeFirst();if(!P)throw Error("Failed to create page");return P}catch(B){if(B instanceof Error)throw TypeError(`Failed to create page: ${B.message}`);throw B}}import{formatDate as df}from"@stacksjs/orm";async function Kf(f,M){let B=await x();try{let P={...M,updated_at:df(new Date)},C=await B.updateTable("pages").set(P).where("id","=",f).returningAll().executeTakeFirst();if(!C)throw Error("Failed to update page");return C}catch(P){if(P instanceof Error)throw TypeError(`Failed to update page: ${P.message}`);throw P}}var U={};Q(U,{update:()=>Tf,sync:()=>If,store:()=>Nf,fetchPublishedAfter:()=>Uf,fetchByStatus:()=>Ef,fetchByMinViews:()=>jf,fetchById:()=>k,fetchByCategory:()=>Hf,fetchByAuthor:()=>_f,fetchAll:()=>Vf,detach:()=>vf,destroy:()=>Ff,bulkDestroy:()=>hf,attach:()=>Rf});async function k(f){return await(await x()).selectFrom("posts").where("id","=",f).selectAll().executeTakeFirst()}async function Vf(){return await(await x()).selectFrom("posts").selectAll().execute()}async function Ef(f){return await(await x()).selectFrom("posts").where("status","=",f).selectAll().execute()}async function Hf(f){return await(await x()).selectFrom("posts").where("category","=",f).selectAll().execute()}async function _f(f){return await(await x()).selectFrom("posts").where("author","=",f).selectAll().execute()}async function jf(f){return await(await x()).selectFrom("posts").where("views",">=",f).selectAll().execute()}async function Uf(f){return await(await x()).selectFrom("posts").where("published_at",">",f).selectAll().execute()}async function Ff(f){let M=await x();try{if(!await k(f))throw Error(`Post with ID ${f} not found`);await M.deleteFrom("categorizable_models").where("categorizable_id","=",f).where("categorizable_type","=","posts").execute();let P=await M.deleteFrom("posts").where("id","=",f).executeTakeFirst();return P?.numDeletedRows?P.numDeletedRows>0:!1}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete post: ${B.message}`);throw B}}async function hf(f){let M=await x();if(!f.length)return 0;try{let P=(await M.selectFrom("posts").select(["id"]).where("id","in",f).execute()).map((G)=>G.id);if(!P.length)return 0;await M.deleteFrom("categorizable_models").where("categorizable_id","in",P).where("categorizable_type","=","posts").execute();let C=await M.deleteFrom("posts").where("id","in",P).executeTakeFirst();return Number(C?.numDeletedRows)||0}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete posts in bulk: ${B.message}`);throw B}}var{randomUUIDv7:rf}=globalThis.Bun;import{formatDate as K}from"@stacksjs/orm";var ef="Draft";async function Nf(f){let M=await x();try{if(!f.title||typeof f.title==="string"&&f.title.trim()==="")throw Error("Post title is required");let B=f.content||f.body,P=f,C={author_id:P.author_id,uuid:rf(),title:f.title,poster:f.poster,content:B,body:f.body,category:f.category,excerpt:f.excerpt,is_featured:P.is_featured?Date.now():void 0,views:f.views||0,published_at:P.published_at||Date.now(),status:f.status||ef},G=await M.insertInto("posts").values(C).returningAll().executeTakeFirst();if(!G)throw Error("Failed to create post");return G}catch(B){if(B instanceof Error)throw TypeError(`Failed to create post: ${B.message}`);throw B}}async function Rf(f,M,B){let P=await x();try{let C=M==="categorizable_models"?"categorizable_id":"taggable_id",G=M==="categorizable_models"?"categorizable_type":"taggable_type",S=M==="categorizable_models"?"category_id":"tag_id",A=B.map((W)=>({[S]:W,[C]:f,[G]:"posts",created_at:K(new Date),updated_at:K(new Date)}));for(let W of A)await P.insertInto(M).values(W).execute()}catch(C){if(C instanceof Error)throw TypeError(`Failed to attach records: ${C.message}`);throw C}}async function vf(f,M,B){let P=await x();try{let C=M==="categorizable_models"?"categorizable_id":"taggable_id",G=M==="categorizable_models"?"categorizable_type":"taggable_type",S=P.deleteFrom(M).where(C,"=",f).where(G,"=","posts");if(B)S=S.where("id","in",B);await S.execute()}catch(C){if(C instanceof Error)throw TypeError(`Failed to detach records: ${C.message}`);throw C}}async function If(f,M,B){let P=await x();try{let C=M==="categorizable_models"?"categorizable_id":"taggable_id",G=M==="categorizable_models"?"categorizable_type":"taggable_type",A=(await P.selectFrom(M).select(["id"]).where(C,"=",f).where(G,"=","posts").execute()).map((J)=>J.id),W=A.filter((J)=>!B.includes(J)),L=B.filter((J)=>!A.includes(J));if(W.length>0)await P.deleteFrom(M).where(C,"=",f).where(G,"=","posts").where("id","in",W).execute();if(L.length>0){let J=L.map(()=>({[C]:f,[G]:"posts",created_at:K(new Date),updated_at:K(new Date)}));await P.insertInto(M).values(J).execute()}}catch(C){if(C instanceof Error)throw TypeError(`Failed to sync records: ${C.message}`);throw C}}async function Tf(f,M){let B=await x();try{if(M.title!==void 0&&typeof M.title==="string"&&M.title.trim()==="")throw Error("Post title cannot be empty");let P=["published","draft","archived"];if(M.status!==void 0&&typeof M.status==="string"&&!P.includes(M.status))throw Error(`Invalid post status: ${M.status}`);if(M.views!==void 0&&typeof M.views==="number"&&M.views<0)throw Error("Views count cannot be negative");let C=await B.updateTable("posts").set(M).where("id","=",f).returningAll().executeTakeFirst();if(!C)throw Error("Failed to update post");return C}catch(P){if(P instanceof Error)throw TypeError(`Failed to update post: ${P.message}`);throw P}}var F={};Q(F,{update:()=>pf,store:()=>wf,fetchTags:()=>mf,fetchTagById:()=>yf,destroy:()=>qf,bulkDestroy:()=>cf});async function qf(f){let M=await x();if(!await M.selectFrom("taggables").where("id","=",f).selectAll().executeTakeFirst())throw Error(`Tag with ID ${f} not found`);await M.deleteFrom("taggables").where("id","=",f).executeTakeFirst()}async function cf(f){let M=await x();try{await M.deleteFrom("taggables").where("id","in",f).execute()}catch(B){if(B instanceof Error)throw TypeError(`Failed to delete tags: ${B.message}`);throw B}}import{slugify as tf}from"ts-slug";async function wf(f){let M=await x();try{if(!f.name||f.name.trim()==="")throw Error("Tag name is required");if(!f.taggable_type||f.taggable_type.trim()==="")throw Error("Tag taggable_type is required");let B=tf(f.name);if(await M.selectFrom("taggables").selectAll().where("slug","=",B).executeTakeFirst())throw Error(`Tag with unique slug "${B}" already exists`);let C={name:f.name,slug:B,description:f.description,is_active:f.is_active??!0,taggable_type:f.taggable_type};if(f.taggable_id!==void 0)C.taggable_id=f.taggable_id;let G=await M.insertInto("taggables").values(C).returningAll().executeTakeFirst();if(!G)throw Error("Failed to create tag");return G}catch(B){if(B instanceof Error)throw TypeError(`Failed to store tag: ${B.message}`);throw B}}async function yf(f){let M=await x();try{let B=await M.selectFrom("taggables").where("id","=",f).selectAll().executeTakeFirst();if(!B)return;return B}catch(B){if(B instanceof Error)throw TypeError(`Failed to fetch tag: ${B.message}`);throw B}}async function mf(){let f=await x();try{return await f.selectFrom("taggables").where("is_active","=",!0).selectAll().execute()}catch(M){if(M instanceof Error)throw TypeError(`Failed to fetch tags: ${M.message}`);throw M}}import{uniqueSlug as af}from"@stacksjs/slug";async function pf(f){let M=await x();try{let B=f.id;if(!B)throw Error("Tag ID is required for update");if(f.name!==void 0){if(f.name.trim()==="")throw Error("Tag name cannot be empty");let S=await af(f.name,{table:"taggables",column:"slug"});if(await M.selectFrom("taggables").selectAll().where("slug","=",S).where("id","!=",B).executeTakeFirst())throw Error(`Tag with unique slug "${S}" already exists`);f.slug=S}let{id:P,...C}=f,G=await M.updateTable("taggables").set(C).where("id","=",B).returningAll().executeTakeFirst();if(!G)throw Error("Failed to update tag");return G}catch(B){if(B instanceof Error)throw TypeError(`Failed to update tag: ${B.message}`);throw B}}var fB={posts:U,postCategories:E,tags:F,comments:_,authors:V,pages:j},nM=fB;export{F as tags,U as posts,j as pages,nM as default,_ as comments,fB as cms,E as categorizable,V as authors};
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@stacksjs/cms",
3
3
  "type": "module",
4
- "version": "0.70.84",
4
+ "sideEffects": false,
5
+ "version": "0.70.85",
5
6
  "description": "Stacks cms utilities.",
6
7
  "author": "Chris Breuer",
7
8
  "contributors": [