@stacksjs/orm 0.75.233 → 0.75.237

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.
@@ -52,6 +52,16 @@ export default defineModel({
52
52
  factory: faker => faker.system.filePath(),
53
53
  },
54
54
 
55
+ /**
56
+ * The HTTP status the error carried, and only that.
57
+ *
58
+ * It used to mean two things: the factory seeds an HTTP status while
59
+ * `resolveGroup` wrote 1 and `ignoreGroup` wrote 2 into the same column
60
+ * to mean resolved and ignored. So resolving an error destroyed its
61
+ * status, and a seeded error could never read as resolved because no
62
+ * factory row is ever 1 (stacksjs/stacks#2923). Triage now lives in
63
+ * `resolution`.
64
+ */
55
65
  status: {
56
66
  fillable: true,
57
67
  validation: {
@@ -63,6 +73,17 @@ export default defineModel({
63
73
  factory: faker => faker.number.int({ min: 400, max: 500 }),
64
74
  },
65
75
 
76
+ /** Where this error sits in triage. Separate from `status`, see above. */
77
+ resolution: {
78
+ required: true,
79
+ fillable: true,
80
+ default: 'unresolved',
81
+ validation: {
82
+ rule: schema.enum(['unresolved', 'resolved', 'ignored']),
83
+ },
84
+ factory: () => 'unresolved',
85
+ },
86
+
66
87
  additional_info: {
67
88
  fillable: true,
68
89
  validation: {
@@ -1,4 +1,15 @@
1
- export declare function createCommentableMethods(tableName: string): boolean;
1
+ export declare function createCommentableMethods(tableName: string): {
2
+ comments: (id: number) => Promise<any[]>;
3
+ commentCount: (id: number) => Promise<number>;
4
+ addComment: (id: number, comment: NewComment, options?: AddCommentOptions) => Promise<any>;
5
+ approvedComments: (id: number) => Promise<any[]>;
6
+ pendingComments: (id: number) => Promise<any[]>;
7
+ rejectedComments: (id: number) => Promise<any[]>;
8
+ upvoteComment: (commentId: number, userId: number) => Promise<any>;
9
+ removeCommentUpvote: (commentId: number, userId: number) => Promise<void>;
10
+ commentUpvoteCount: (commentId: number) => Promise<number>;
11
+ hasUpvotedComment: (commentId: number, userId: number) => Promise<boolean>
12
+ };
2
13
  /** The fields a caller may set on a new comment. */
3
14
  export declare interface NewComment {
4
15
  body: string
@@ -1 +1 @@
1
- import{db as _db,sql,sqlDateTime}from"@stacksjs/database/runtime";function assertId(id,method){if(typeof id!=="number"||!Number.isFinite(id)||id<=0)throw Error(`[orm/commentable] ${method} requires a positive numeric id (received ${String(id)})`)}const UPVOTES_TABLE="commentable_upvotes",COMMENT_UPVOTE_TYPE="commentables";function isDuplicateError(err){const e=err;return e.code==="SQLITE_CONSTRAINT_UNIQUE"||e.code==="SQLITE_CONSTRAINT"||e.code==="23505"||e.errno===1062||/unique|duplicate/i.test(e.message??"")}const COMMENT_STATUSES_ON_CREATE=["pending","approved"];export function createCommentableMethods(tableName){const db=_db;return{async comments(id){assertId(id,"comments");return await db.selectFrom("commentables").where("commentables_id","=",id).where("commentables_type","=",tableName).selectAll().orderBy("id","asc").execute()},async commentCount(id){const result=await db.selectFrom("commentables").select(sql`count(*) as count`).where("commentables_id","=",id).where("commentables_type","=",tableName).executeTakeFirst();return Number(result?.count)||0},async addComment(id,comment,options={}){assertId(id,"addComment");if(!comment||typeof comment.body!=="string"||comment.body.trim().length===0)throw Error("[orm/commentable] addComment requires a non-empty comment.body");if(comment.title!=null&&typeof comment.title!=="string")throw Error("[orm/commentable] addComment requires comment.title to be a string when given");const status=options.status??"pending";if(!COMMENT_STATUSES_ON_CREATE.includes(status))throw Error(`[orm/commentable] addComment status must be one of ${COMMENT_STATUSES_ON_CREATE.join(", ")} (received ${String(status)})`);const values={title:comment.title?.trim()??"",body:comment.body,commentables_id:id,commentables_type:tableName,status,approved_at:status==="approved"?Date.now():null,created_at:sqlDateTime(),updated_at:sqlDateTime()};for(const key of["author_name","author_email","user_id"])if(comment[key]!=null)values[key]=comment[key];const written=await db.insertInto("commentables").values(values).returningAll().executeTakeFirst();if(written&&typeof written==="object"&&"id"in written)return written;const insertedId=written?.lastInsertRowid;if(insertedId==null)return written;return await db.selectFrom("commentables").where("id","=",Number(insertedId)).selectAll().executeTakeFirst()},async approvedComments(id){return await db.selectFrom("commentables").where("commentables_id","=",id).where("commentables_type","=",tableName).where("status","=","approved").selectAll().orderBy("id","asc").execute()},async pendingComments(id){return await db.selectFrom("commentables").where("commentables_id","=",id).where("commentables_type","=",tableName).where("status","=","pending").selectAll().orderBy("id","asc").execute()},async rejectedComments(id){return await db.selectFrom("commentables").where("commentables_id","=",id).where("commentables_type","=",tableName).where("status","=","rejected").selectAll().orderBy("id","asc").execute()},async upvoteComment(commentId,userId){assertId(commentId,"upvoteComment");assertId(userId,"upvoteComment");const existing=()=>db.selectFrom(UPVOTES_TABLE).where("upvoteable_id","=",commentId).where("upvoteable_type","=",COMMENT_UPVOTE_TYPE).where("user_id","=",userId).selectAll().executeTakeFirst(),already=await existing();if(already)return already;try{await db.insertInto(UPVOTES_TABLE).values({upvoteable_id:commentId,upvoteable_type:COMMENT_UPVOTE_TYPE,user_id:userId,created_at:sqlDateTime()}).execute()}catch(err){if(!isDuplicateError(err))throw err}return await existing()},async removeCommentUpvote(commentId,userId){assertId(commentId,"removeCommentUpvote");assertId(userId,"removeCommentUpvote");await db.deleteFrom(UPVOTES_TABLE).where("upvoteable_id","=",commentId).where("upvoteable_type","=",COMMENT_UPVOTE_TYPE).where("user_id","=",userId).execute()},async commentUpvoteCount(commentId){assertId(commentId,"commentUpvoteCount");const result=await db.selectFrom(UPVOTES_TABLE).select("count(*) as count").where("upvoteable_id","=",commentId).where("upvoteable_type","=",COMMENT_UPVOTE_TYPE).executeTakeFirst();return Number(result?.count)||0},async hasUpvotedComment(commentId,userId){assertId(commentId,"hasUpvotedComment");assertId(userId,"hasUpvotedComment");return!!await db.selectFrom(UPVOTES_TABLE).where("upvoteable_id","=",commentId).where("upvoteable_type","=",COMMENT_UPVOTE_TYPE).where("user_id","=",userId).selectAll().executeTakeFirst()}}}
1
+ import{db as _db,sql,sqlDateTime}from"@stacksjs/database/runtime";function assertId(id,method){if(typeof id!=="number"||!Number.isFinite(id)||id<=0)throw Error(`[orm/commentable] ${method} requires a positive numeric id (received ${String(id)})`)}const UPVOTES_TABLE="commentable_upvotes",COMMENT_UPVOTE_TYPE="commentables";function isDuplicateError(err){const e=err;return e.code==="SQLITE_CONSTRAINT_UNIQUE"||e.code==="SQLITE_CONSTRAINT"||e.code==="23505"||e.errno===1062||/unique|duplicate/i.test(e.message??"")}const COMMENT_STATUSES_ON_CREATE=["pending","approved"];export function createCommentableMethods(tableName){const db=_db;return{async comments(id){assertId(id,"comments");return await db.selectFrom("commentables").where("commentables_id","=",id).where("commentables_type","=",tableName).selectAll().orderBy("id","asc").execute()},async commentCount(id){const result=await db.selectFrom("commentables").select(sql`count(*) as count`).where("commentables_id","=",id).where("commentables_type","=",tableName).executeTakeFirst();return Number(result?.count)||0},async addComment(id,comment,options={}){assertId(id,"addComment");if(!comment||typeof comment.body!=="string"||comment.body.trim().length===0)throw Error("[orm/commentable] addComment requires a non-empty comment.body");if(comment.title!=null&&typeof comment.title!=="string")throw Error("[orm/commentable] addComment requires comment.title to be a string when given");const status=options.status??"pending";if(!COMMENT_STATUSES_ON_CREATE.includes(status))throw Error(`[orm/commentable] addComment status must be one of ${COMMENT_STATUSES_ON_CREATE.join(", ")} (received ${String(status)})`);const values={title:comment.title?.trim()??"",body:comment.body,commentables_id:id,commentables_type:tableName,status,approved_at:status==="approved"?Date.now():null,created_at:sqlDateTime(),updated_at:sqlDateTime()};for(const key of["author_name","author_email","user_id"])if(comment[key]!=null)values[key]=comment[key];const written=await db.insertInto("commentables").values(values).returningAll().executeTakeFirst();if(written&&typeof written==="object"&&"id"in written)return written;const insertedId=written?.lastInsertRowid;if(insertedId==null)return written;return await db.selectFrom("commentables").where("id","=",Number(insertedId)).selectAll().executeTakeFirst()},async approvedComments(id){return await db.selectFrom("commentables").where("commentables_id","=",id).where("commentables_type","=",tableName).where("status","=","approved").selectAll().orderBy("id","asc").execute()},async pendingComments(id){return await db.selectFrom("commentables").where("commentables_id","=",id).where("commentables_type","=",tableName).where("status","=","pending").selectAll().orderBy("id","asc").execute()},async rejectedComments(id){return await db.selectFrom("commentables").where("commentables_id","=",id).where("commentables_type","=",tableName).where("status","=","rejected").selectAll().orderBy("id","asc").execute()},async upvoteComment(commentId,userId){assertId(commentId,"upvoteComment");assertId(userId,"upvoteComment");const existing=()=>db.selectFrom(UPVOTES_TABLE).where("upvoteable_id","=",commentId).where("upvoteable_type","=",COMMENT_UPVOTE_TYPE).where("user_id","=",userId).selectAll().executeTakeFirst(),already=await existing();if(already)return already;try{await db.insertInto(UPVOTES_TABLE).values({upvoteable_id:commentId,upvoteable_type:COMMENT_UPVOTE_TYPE,user_id:userId,created_at:sqlDateTime()}).execute()}catch(err){if(!isDuplicateError(err))throw err}return await existing()},async removeCommentUpvote(commentId,userId){assertId(commentId,"removeCommentUpvote");assertId(userId,"removeCommentUpvote");await db.deleteFrom(UPVOTES_TABLE).where("upvoteable_id","=",commentId).where("upvoteable_type","=",COMMENT_UPVOTE_TYPE).where("user_id","=",userId).execute()},async commentUpvoteCount(commentId){assertId(commentId,"commentUpvoteCount");return await db.selectFrom(UPVOTES_TABLE).where("upvoteable_id","=",commentId).where("upvoteable_type","=",COMMENT_UPVOTE_TYPE).count()},async hasUpvotedComment(commentId,userId){assertId(commentId,"hasUpvotedComment");assertId(userId,"hasUpvotedComment");return!!await db.selectFrom(UPVOTES_TABLE).where("upvoteable_id","=",commentId).where("upvoteable_type","=",COMMENT_UPVOTE_TYPE).where("user_id","=",userId).selectAll().executeTakeFirst()}}}
@@ -1 +1 @@
1
- import{db as _db,sqlDateTime}from"@stacksjs/database/runtime";export function createLikeableMethods(tableName,options){const db=_db,likeTable=options?.table||`${tableName}_likes`,foreignKey=options?.foreignKey||`${tableName.replace(/s$/,"")}_id`;return{async likes(id){return await db.selectFrom(likeTable).where(foreignKey,"=",id).selectAll().execute()},async likeCount(id){const result=await db.selectFrom(likeTable).select("count(*) as count").where(foreignKey,"=",id).executeTakeFirst();return Number(result?.count)||0},async like(id,userId){if(typeof id!=="number"||!Number.isFinite(id)||id<=0)throw Error(`[orm/likeable] like requires a positive numeric id (received ${String(id)})`);if(typeof userId!=="number"||!Number.isFinite(userId)||userId<=0)throw Error(`[orm/likeable] like requires a positive numeric userId (received ${String(userId)})`);const now=sqlDateTime();try{return await db.insertInto(likeTable).values({[foreignKey]:id,user_id:userId,created_at:now,updated_at:now}).returningAll().executeTakeFirst()}catch(err){const e=err;if(!(e.code==="SQLITE_CONSTRAINT_UNIQUE"||e.code==="SQLITE_CONSTRAINT"||e.code==="23505"||e.errno===1062||/unique|duplicate/i.test(e.message??"")))throw err;const existing=await db.selectFrom(likeTable).where(foreignKey,"=",id).where("user_id","=",userId).selectAll().executeTakeFirst();if(existing)return existing;throw err}},async unlike(id,userId){await db.deleteFrom(likeTable).where(foreignKey,"=",id).where("user_id","=",userId).execute()},async isLiked(id,userId){return!!await db.selectFrom(likeTable).where(foreignKey,"=",id).where("user_id","=",userId).selectAll().executeTakeFirst()},async likedBy(userId){return(await db.selectFrom(likeTable).select([foreignKey]).where("user_id","=",userId).execute()).map((r)=>Number(r[foreignKey])).filter(Boolean)}}}
1
+ import{db as _db,sqlDateTime}from"@stacksjs/database/runtime";export function createLikeableMethods(tableName,options){const db=_db,likeTable=options?.table||`${tableName}_likes`,foreignKey=options?.foreignKey||`${tableName.replace(/s$/,"")}_id`;return{async likes(id){return await db.selectFrom(likeTable).where(foreignKey,"=",id).selectAll().execute()},async likeCount(id){return await db.selectFrom(likeTable).where(foreignKey,"=",id).count()},async like(id,userId){if(typeof id!=="number"||!Number.isFinite(id)||id<=0)throw Error(`[orm/likeable] like requires a positive numeric id (received ${String(id)})`);if(typeof userId!=="number"||!Number.isFinite(userId)||userId<=0)throw Error(`[orm/likeable] like requires a positive numeric userId (received ${String(userId)})`);const now=sqlDateTime();try{return await db.insertInto(likeTable).values({[foreignKey]:id,user_id:userId,created_at:now,updated_at:now}).returningAll().executeTakeFirst()}catch(err){const e=err;if(!(e.code==="SQLITE_CONSTRAINT_UNIQUE"||e.code==="SQLITE_CONSTRAINT"||e.code==="23505"||e.errno===1062||/unique|duplicate/i.test(e.message??"")))throw err;const existing=await db.selectFrom(likeTable).where(foreignKey,"=",id).where("user_id","=",userId).selectAll().executeTakeFirst();if(existing)return existing;throw err}},async unlike(id,userId){await db.deleteFrom(likeTable).where(foreignKey,"=",id).where("user_id","=",userId).execute()},async isLiked(id,userId){return!!await db.selectFrom(likeTable).where(foreignKey,"=",id).where("user_id","=",userId).selectAll().executeTakeFirst()},async likedBy(userId){return(await db.selectFrom(likeTable).select([foreignKey]).where("user_id","=",userId).execute()).map((r)=>Number(r[foreignKey])).filter(Boolean)}}}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/orm",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.233",
5
+ "version": "0.75.237",
6
6
  "description": "The Stacks ORM integration",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -63,31 +63,31 @@
63
63
  "prepublishOnly": "bun run build"
64
64
  },
65
65
  "dependencies": {
66
- "@stacksjs/cache": "0.75.233",
67
- "@stacksjs/cli": "0.75.233",
68
- "@stacksjs/config": "0.75.233",
69
- "@stacksjs/database": "0.75.233",
70
- "@stacksjs/env": "0.75.233",
71
- "@stacksjs/error-handling": "0.75.233",
72
- "@stacksjs/events": "0.75.233",
73
- "@stacksjs/logging": "0.75.233",
74
- "@stacksjs/model-meta": "0.75.233",
75
- "@stacksjs/pagination": "0.75.233",
76
- "@stacksjs/path": "0.75.233",
77
- "@stacksjs/query-builder": "0.75.233",
78
- "@stacksjs/realtime": "0.75.233",
79
- "@stacksjs/router": "0.75.233",
80
- "@stacksjs/storage": "0.75.233",
81
- "@stacksjs/strings": "0.75.233",
66
+ "@stacksjs/cache": "0.75.237",
67
+ "@stacksjs/cli": "0.75.237",
68
+ "@stacksjs/config": "0.75.237",
69
+ "@stacksjs/database": "0.75.237",
70
+ "@stacksjs/env": "0.75.237",
71
+ "@stacksjs/error-handling": "0.75.237",
72
+ "@stacksjs/events": "0.75.237",
73
+ "@stacksjs/logging": "0.75.237",
74
+ "@stacksjs/model-meta": "0.75.237",
75
+ "@stacksjs/pagination": "0.75.237",
76
+ "@stacksjs/path": "0.75.237",
77
+ "@stacksjs/query-builder": "0.75.237",
78
+ "@stacksjs/realtime": "0.75.237",
79
+ "@stacksjs/router": "0.75.237",
80
+ "@stacksjs/storage": "0.75.237",
81
+ "@stacksjs/strings": "0.75.237",
82
82
  "@stacksjs/ts-validation": "^0.5.6",
83
- "@stacksjs/validation": "0.75.233",
83
+ "@stacksjs/validation": "0.75.237",
84
84
  "bun-query-builder": "^0.3.8"
85
85
  },
86
86
  "peerDependencies": {
87
- "@stacksjs/auth": "0.75.233",
88
- "@stacksjs/payments": "0.75.233",
89
- "@stacksjs/queue": "0.75.233",
90
- "@stacksjs/search-engine": "0.75.233",
87
+ "@stacksjs/auth": "0.75.237",
88
+ "@stacksjs/payments": "0.75.237",
89
+ "@stacksjs/queue": "0.75.237",
90
+ "@stacksjs/search-engine": "0.75.237",
91
91
  "stripe": "23.0.0"
92
92
  },
93
93
  "peerDependenciesMeta": {
@@ -108,7 +108,7 @@
108
108
  }
109
109
  },
110
110
  "devDependencies": {
111
- "@stacksjs/types": "0.75.233",
111
+ "@stacksjs/types": "0.75.237",
112
112
  "better-dx": "^0.2.24",
113
113
  "stripe": "23.0.0"
114
114
  }