@stacksjs/cms 0.75.318 → 0.75.321

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.
@@ -1 +1 @@
1
- import{sqlDateTime}from"@stacksjs/database/runtime";import{getDb}from"../database";import{resolveWrittenRow}from"../results";async function readComment(db,id){const row=await db.selectFrom("commentables").where("id","=",id).selectAll().executeTakeFirst();if(!row)throw Error(`Comment ${id} not found after write`);return row}export async function createComment(data){const db=await getDb(),now=new Date,commentData={title:data.title,body:data.body,commentables_id:data.commentables_id,commentables_type:data.commentables_type,status:"pending",created_at:sqlDateTime(now)},written=await db.insertInto("commentables").values(commentData).returningAll().executeTakeFirst(),comment=await resolveWrittenRow(db,"commentables",written);if(!comment)throw Error("Failed to create comment");return comment}export async function updateComment(id,input){const db=await getDb();await db.updateTable("commentables").set({...input,updated_at:sqlDateTime()}).where("id","=",id).execute();return readComment(db,id)}export async function approveComment(id){const db=await getDb();await db.updateTable("commentables").set({status:"approved",approved_at:Date.now(),updated_at:sqlDateTime()}).where("id","=",id).execute();return readComment(db,id)}export async function rejectComment(id){const db=await getDb();await db.updateTable("commentables").set({status:"rejected",rejected_at:Date.now(),updated_at:sqlDateTime()}).where("id","=",id).execute();return readComment(db,id)}export async function deleteComment(id){await(await getDb()).deleteFrom("commentables").where("id","=",id).execute()}export async function store(data){const db=await getDb();try{if(!data.title||data.title.trim()==="")throw Error("Comment title is required");if(!data.body||data.body.trim()==="")throw Error("Comment body is required");if(!data.commentables_type||data.commentables_type.trim()==="")throw Error("Comment commentables_type is required");const validStatuses=["pending","approved","rejected"];if(data.status&&!validStatuses.includes(data.status))throw Error(`Invalid comment status: ${data.status}`);const commentData={title:data.title,body:data.body,status:data.status,commentables_id:data.commentables_id,commentables_type:data.commentables_type,user_id:data.user_id,is_active:data.is_active},written=await db.insertInto("commentables").values(commentData).returningAll().executeTakeFirst(),result=await resolveWrittenRow(db,"commentables",written);if(!result)throw Error("Failed to create comment");return result}catch(error){if(error instanceof Error)throw TypeError(`Failed to store comment: ${error.message}`);throw error}}
1
+ import{sqlDateTime}from"@stacksjs/database/runtime";import{getDb}from"../database";import{resolveWrittenRow}from"../results";async function readComment(db,id){const row=await db.selectFrom("commentables").where("id","=",id).selectAll().executeTakeFirst();if(!row)throw Error(`Comment ${id} not found after write`);return row}export async function createComment(data){const db=await getDb(),now=new Date,commentData={title:data.title,body:data.body,commentables_id:data.commentables_id,commentables_type:data.commentables_type,status:"pending",created_at:sqlDateTime(now)},written=await db.insertInto("commentables").values(commentData).returningAll().executeTakeFirst(),comment=await resolveWrittenRow(db,"commentables",written);if(!comment)throw Error("Failed to create comment");return comment}export async function updateComment(id,input){const db=await getDb();await db.updateTable("commentables").set({...input,updated_at:sqlDateTime()}).where("id","=",id).execute();return readComment(db,id)}export async function approveComment(id){const db=await getDb();await db.updateTable("commentables").set({status:"approved",approved_at:Date.now(),updated_at:sqlDateTime()}).where("id","=",id).execute();return readComment(db,id)}export async function rejectComment(id){const db=await getDb();await db.updateTable("commentables").set({status:"rejected",rejected_at:Date.now(),updated_at:sqlDateTime()}).where("id","=",id).execute();return readComment(db,id)}export async function deleteComment(id){await(await getDb()).deleteFrom("commentables").where("id","=",id).execute()}export async function store(data){const db=await getDb();try{if(!data.title||data.title.trim()==="")throw Error("Comment title is required");if(!data.body||data.body.trim()==="")throw Error("Comment body is required");if(!data.commentables_type||data.commentables_type.trim()==="")throw Error("Comment commentables_type is required");const validStatuses=["pending","approved","rejected"];if(data.status&&!validStatuses.includes(data.status))throw Error(`Invalid comment status: ${data.status}`);const commentData={title:data.title,body:data.body,commentables_id:data.commentables_id,commentables_type:data.commentables_type,user_id:data.user_id,...data.status!==void 0&&{status:data.status},...data.is_active!==void 0&&{is_active:data.is_active}},written=await db.insertInto("commentables").values(commentData).returningAll().executeTakeFirst(),result=await resolveWrittenRow(db,"commentables",written);if(!result)throw Error("Failed to create comment");return result}catch(error){if(error instanceof Error)throw TypeError(`Failed to store comment: ${error.message}`);throw error}}
package/dist/results.js CHANGED
@@ -1 +1 @@
1
- export function isRow(value){return!!value&&typeof value==="object"&&"id"in value}export function insertedId(result){if(isRow(result)&&typeof result.id==="number")return result.id;const rowid=result?.lastInsertRowid;if(rowid===void 0||rowid===null)return;const id=Number(rowid);return Number.isSafeInteger(id)&&id>0?id:void 0}export async function resolveWrittenRow(db,table,result){if(isRow(result))return result;const id=insertedId(result);if(id===void 0)return;return await db.selectFrom(table).where("id","=",id).selectAll().executeTakeFirst()}export function affectedRows(result,key){const raw=result?.[key]??result?.changes;if(typeof raw==="number"||typeof raw==="bigint")return Number(raw);const changes=raw?.changes;return typeof changes==="number"||typeof changes==="bigint"?Number(changes):0}
1
+ export function isRow(value){return!!value&&typeof value==="object"&&"id"in value}export function insertedId(result){if(isRow(result)){const id=Number(result.id);if(Number.isSafeInteger(id)&&id>0)return id}const rowid=result?.lastInsertRowid;if(rowid===void 0||rowid===null)return;const id=Number(rowid);return Number.isSafeInteger(id)&&id>0?id:void 0}export async function resolveWrittenRow(db,table,result){if(isRow(result))return result;const id=insertedId(result);if(id===void 0)return;return await db.selectFrom(table).where("id","=",id).selectAll().executeTakeFirst()}export function affectedRows(result,key){const raw=result?.[key]??result?.changes;if(typeof raw==="number"||typeof raw==="bigint")return Number(raw);const changes=raw?.changes;return typeof changes==="number"||typeof changes==="bigint"?Number(changes):0}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/cms",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.318",
5
+ "version": "0.75.321",
6
6
  "description": "Stacks cms utilities.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -58,14 +58,14 @@
58
58
  "prepublishOnly": "bun run build"
59
59
  },
60
60
  "dependencies": {
61
- "@stacksjs/database": "0.75.318",
62
- "@stacksjs/error-handling": "0.75.318",
63
- "@stacksjs/orm": "0.75.318",
64
- "@stacksjs/path": "0.75.318",
65
- "@stacksjs/sites": "0.75.318",
66
- "@stacksjs/slug": "0.75.318",
67
- "@stacksjs/stx": "0.2.691",
68
- "@stacksjs/validation": "0.75.318",
61
+ "@stacksjs/database": "0.75.321",
62
+ "@stacksjs/error-handling": "0.75.321",
63
+ "@stacksjs/orm": "0.75.321",
64
+ "@stacksjs/path": "0.75.321",
65
+ "@stacksjs/sites": "0.75.321",
66
+ "@stacksjs/slug": "0.75.321",
67
+ "@stacksjs/stx": "0.2.711",
68
+ "@stacksjs/validation": "0.75.321",
69
69
  "ts-medium-editor": "^0.2.0",
70
70
  "ts-slug": "^0.1.2",
71
71
  "ts-spreadsheets": "^0.2.5"