@stacksjs/cms 0.70.55 → 0.70.57

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 (68) hide show
  1. package/package.json +10 -7
  2. package/src/authors/destroy.ts +0 -55
  3. package/src/authors/fetch.ts +0 -70
  4. package/src/authors/index.ts +0 -21
  5. package/src/authors/store.ts +0 -150
  6. package/src/authors/update.ts +0 -42
  7. package/src/build.ts +0 -1382
  8. package/src/categorizables/destroy.ts +0 -64
  9. package/src/categorizables/fetch.ts +0 -121
  10. package/src/categorizables/index.ts +0 -22
  11. package/src/categorizables/store.ts +0 -140
  12. package/src/categorizables/update.ts +0 -57
  13. package/src/commentables/destroy.ts +0 -64
  14. package/src/commentables/fetch.ts +0 -319
  15. package/src/commentables/index.ts +0 -25
  16. package/src/commentables/store.ts +0 -156
  17. package/src/commentables/update.ts +0 -75
  18. package/src/database.ts +0 -9
  19. package/src/index.ts +0 -42
  20. package/src/pages/destroy.ts +0 -64
  21. package/src/pages/fetch.ts +0 -82
  22. package/src/pages/index.ts +0 -21
  23. package/src/pages/store.ts +0 -42
  24. package/src/pages/update.ts +0 -39
  25. package/src/posts/destroy.ts +0 -90
  26. package/src/posts/fetch.ts +0 -82
  27. package/src/posts/index.ts +0 -25
  28. package/src/posts/store.ts +0 -213
  29. package/src/posts/update.ts +0 -46
  30. package/src/taggables/destroy.ts +0 -49
  31. package/src/taggables/fetch.ts +0 -282
  32. package/src/taggables/index.ts +0 -17
  33. package/src/taggables/store.ts +0 -122
  34. package/src/taggables/update.ts +0 -74
  35. package/src/tests/categorizables.test.ts +0 -66
  36. package/src/tests/setup.ts +0 -120
  37. /package/dist/{src/authors → authors}/destroy.d.ts +0 -0
  38. /package/dist/{src/authors → authors}/fetch.d.ts +0 -0
  39. /package/dist/{src/authors → authors}/index.d.ts +0 -0
  40. /package/dist/{src/authors → authors}/store.d.ts +0 -0
  41. /package/dist/{src/authors → authors}/update.d.ts +0 -0
  42. /package/dist/{src/categorizables → categorizables}/destroy.d.ts +0 -0
  43. /package/dist/{src/categorizables → categorizables}/fetch.d.ts +0 -0
  44. /package/dist/{src/categorizables → categorizables}/index.d.ts +0 -0
  45. /package/dist/{src/categorizables → categorizables}/store.d.ts +0 -0
  46. /package/dist/{src/categorizables → categorizables}/update.d.ts +0 -0
  47. /package/dist/{src/commentables → commentables}/destroy.d.ts +0 -0
  48. /package/dist/{src/commentables → commentables}/fetch.d.ts +0 -0
  49. /package/dist/{src/commentables → commentables}/index.d.ts +0 -0
  50. /package/dist/{src/commentables → commentables}/store.d.ts +0 -0
  51. /package/dist/{src/commentables → commentables}/update.d.ts +0 -0
  52. /package/dist/{src/database.d.ts → database.d.ts} +0 -0
  53. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  54. /package/dist/{src/pages → pages}/destroy.d.ts +0 -0
  55. /package/dist/{src/pages → pages}/fetch.d.ts +0 -0
  56. /package/dist/{src/pages → pages}/index.d.ts +0 -0
  57. /package/dist/{src/pages → pages}/store.d.ts +0 -0
  58. /package/dist/{src/pages → pages}/update.d.ts +0 -0
  59. /package/dist/{src/posts → posts}/destroy.d.ts +0 -0
  60. /package/dist/{src/posts → posts}/fetch.d.ts +0 -0
  61. /package/dist/{src/posts → posts}/index.d.ts +0 -0
  62. /package/dist/{src/posts → posts}/store.d.ts +0 -0
  63. /package/dist/{src/posts → posts}/update.d.ts +0 -0
  64. /package/dist/{src/taggables → taggables}/destroy.d.ts +0 -0
  65. /package/dist/{src/taggables → taggables}/fetch.d.ts +0 -0
  66. /package/dist/{src/taggables → taggables}/index.d.ts +0 -0
  67. /package/dist/{src/taggables → taggables}/store.d.ts +0 -0
  68. /package/dist/{src/taggables → taggables}/update.d.ts +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/cms",
3
3
  "type": "module",
4
- "version": "0.70.55",
4
+ "version": "0.70.57",
5
5
  "description": "Stacks cms utilities.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -28,20 +28,23 @@
28
28
  "exports": {
29
29
  ".": {
30
30
  "types": "./dist/index.d.ts",
31
- "bun": "./src/index.ts",
32
- "import": "./dist/index.js"
31
+ "development": "./src/index.ts",
32
+ "bun": "./dist/index.js",
33
+ "import": "./dist/index.js",
34
+ "default": "./dist/index.js"
33
35
  },
34
36
  "./*": {
35
- "bun": "./src/*",
36
- "import": "./dist/*"
37
+ "development": "./src/*",
38
+ "bun": "./dist/*",
39
+ "import": "./dist/*",
40
+ "default": "./dist/*"
37
41
  }
38
42
  },
39
43
  "module": "dist/index.js",
40
44
  "types": "dist/index.d.ts",
41
45
  "files": [
42
46
  "README.md",
43
- "dist",
44
- "src"
47
+ "dist"
45
48
  ],
46
49
  "scripts": {
47
50
  "build": "bun build.ts",
@@ -1,55 +0,0 @@
1
- type AuthorJsonResponse = ModelRow<typeof Author>
2
- import { getDb } from '../database'
3
-
4
- /**
5
- * Delete an author by ID
6
- *
7
- * @param id The ID of the author to delete
8
- * @returns The deleted author record
9
- */
10
- export async function destroy(id: number): Promise<AuthorJsonResponse> {
11
- const db = await getDb()
12
- try {
13
- const result = await db
14
- .deleteFrom('authors')
15
- .where('id', '=', id)
16
- .returningAll()
17
- .executeTakeFirst()
18
-
19
- if (!result) {
20
- throw new Error(`Author with ID ${id} not found`)
21
- }
22
-
23
- return result as AuthorJsonResponse
24
- }
25
- catch (error) {
26
- if (error instanceof Error)
27
- throw new TypeError(`Author with ID ${id} not found`)
28
-
29
- throw error
30
- }
31
- }
32
-
33
- /**
34
- * Delete multiple authors by IDs
35
- *
36
- * @param ids Array of author IDs to delete
37
- * @returns The number of deleted authors
38
- */
39
- export async function destroyMany(ids: number[]): Promise<number> {
40
- const db = await getDb()
41
- try {
42
- const result = await db
43
- .deleteFrom('authors')
44
- .where('id', 'in', ids)
45
- .execute()
46
-
47
- return Number(result) || 0
48
- }
49
- catch (error) {
50
- if (error instanceof Error)
51
- throw new TypeError(`Failed to delete authors: ${error.message}`)
52
-
53
- throw error
54
- }
55
- }
@@ -1,70 +0,0 @@
1
- type AuthorJsonResponse = ModelRow<typeof Author>
2
- import { getDb } from '../database'
3
-
4
- /**
5
- * Fetch an author by ID
6
- */
7
- export async function fetchById(id: number): Promise<AuthorJsonResponse | undefined> {
8
- const db = await getDb()
9
- return await db
10
- .selectFrom('authors')
11
- .where('id', '=', id)
12
- .selectAll()
13
- .executeTakeFirst() as AuthorJsonResponse | undefined
14
- }
15
-
16
- /**
17
- * Fetch all authors
18
- */
19
- export async function fetchAll(): Promise<AuthorJsonResponse[]> {
20
- const db = await getDb()
21
- return await db.selectFrom('authors').selectAll().execute() as AuthorJsonResponse[]
22
- }
23
-
24
- /**
25
- * Fetch authors by name
26
- */
27
- export async function findByName(name: string): Promise<AuthorJsonResponse | undefined> {
28
- const db = await getDb()
29
- return await db
30
- .selectFrom('authors')
31
- .where('name', '=', name)
32
- .selectAll()
33
- .executeTakeFirst() as AuthorJsonResponse | undefined
34
- }
35
-
36
- /**
37
- * Fetch authors by email
38
- */
39
- export async function findByEmail(email: string): Promise<AuthorJsonResponse | undefined> {
40
- const db = await getDb()
41
- return await db
42
- .selectFrom('authors')
43
- .where('email', '=', email)
44
- .selectAll()
45
- .executeTakeFirst() as AuthorJsonResponse | undefined
46
- }
47
-
48
- /**
49
- * Fetch author by UUID
50
- */
51
- export async function findByUuid(uuid: string): Promise<AuthorJsonResponse | undefined> {
52
- const db = await getDb()
53
- return await db
54
- .selectFrom('authors')
55
- .where('uuid', '=', uuid)
56
- .selectAll()
57
- .executeTakeFirst() as AuthorJsonResponse | undefined
58
- }
59
-
60
- /**
61
- * Fetch authors by user ID
62
- */
63
- export async function findByUserId(userId: number): Promise<AuthorJsonResponse | undefined> {
64
- const db = await getDb()
65
- return await db
66
- .selectFrom('authors')
67
- .where('user_id', '=', userId)
68
- .selectAll()
69
- .executeTakeFirst() as AuthorJsonResponse | undefined
70
- }
@@ -1,21 +0,0 @@
1
- export {
2
- destroy,
3
- } from './destroy'
4
-
5
- export {
6
- fetchAll,
7
- fetchById,
8
- findByEmail,
9
- findByName,
10
- findByUserId,
11
- findByUuid,
12
- } from './fetch'
13
-
14
- export {
15
- findOrCreate,
16
- store,
17
- } from './store'
18
-
19
- export {
20
- update,
21
- } from './update'
@@ -1,150 +0,0 @@
1
- type AuthorJsonResponse = ModelRow<typeof Author>
2
- type NewAuthor = NewModelData<typeof Author>
3
- import { randomUUIDv7 } from 'bun'
4
- import { getDb } from '../database'
5
- import { HttpError } from '@stacksjs/error-handling'
6
- import { formatDate, isUniqueViolation } from '@stacksjs/orm'
7
-
8
- interface AuthorData {
9
- name: string
10
- email: string
11
- }
12
- /**
13
- * Find an existing author by name or email, or create a new one if not found
14
- *
15
- * @param data The author data to find or create
16
- * @returns The found or created author record
17
- */
18
- export async function findOrCreate(data: AuthorData): Promise<AuthorJsonResponse> {
19
- const db = await getDb()
20
- try {
21
- // First, try to find an existing author by email or name
22
- const existingAuthor = await db
23
- .selectFrom('authors')
24
- .where((eb: any) => eb.or([
25
- eb('email', '=', data.email),
26
- eb('name', '=', data.name),
27
- ]))
28
- .selectAll()
29
- .executeTakeFirst()
30
-
31
- // If author exists, return it
32
- if (existingAuthor)
33
- return existingAuthor as AuthorJsonResponse
34
-
35
- // Look up or create the associated user
36
- let user = await db
37
- .selectFrom('users')
38
- .where('email', '=', data.email)
39
- .selectAll()
40
- .executeTakeFirst()
41
-
42
- if (!user) {
43
- // Create a new user if one doesn't exist
44
- const result = await db
45
- .insertInto('users')
46
- .values({
47
- email: data.email,
48
- name: data.name,
49
- password: randomUUIDv7(),
50
- uuid: randomUUIDv7(),
51
- created_at: formatDate(new Date()),
52
- updated_at: formatDate(new Date()),
53
- })
54
- .returningAll()
55
- .executeTakeFirst()
56
-
57
- if (!result)
58
- throw new Error('Failed to create user')
59
-
60
- user = result
61
- }
62
-
63
- // Create a new author with the user_id
64
- const authorData = {
65
- user_id: (user as Record<string, unknown>).id as number,
66
- name: data.name,
67
- email: data.email,
68
- created_at: formatDate(new Date()),
69
- updated_at: formatDate(new Date()),
70
- }
71
-
72
- const result = await db
73
- .insertInto('authors')
74
- .values(authorData)
75
- .returningAll()
76
- .executeTakeFirst()
77
-
78
- if (!result)
79
- throw new Error('Failed to create author')
80
-
81
- return result as AuthorJsonResponse
82
- }
83
- catch (error) {
84
- if (error instanceof HttpError)
85
- throw error
86
- // A concurrent insert can lose the find-then-insert race on the
87
- // authors.email / users.email unique index (#1957).
88
- if (isUniqueViolation(error))
89
- throw new HttpError(409, 'An author with this email already exists')
90
- if (error instanceof Error)
91
- throw new TypeError(`Failed to find or create author: ${error.message}`)
92
-
93
- throw error
94
- }
95
- }
96
-
97
- /**
98
- * Find or create an author by name or email
99
- *
100
- * @param data The author data to find or create
101
- * @returns The found or created author record
102
- */
103
- export async function store(data: NewAuthor): Promise<AuthorJsonResponse> {
104
- const db = await getDb()
105
- try {
106
- // First, try to find an existing author by email or name
107
- const existingAuthor = await db
108
- .selectFrom('authors')
109
- .where((eb: any) => eb.or([
110
- eb('email', '=', data.email),
111
- eb('name', '=', data.name),
112
- ]))
113
- .selectAll()
114
- .executeTakeFirst()
115
-
116
- // If author exists, return it
117
- if (existingAuthor)
118
- return existingAuthor as AuthorJsonResponse
119
-
120
- // If no existing author, create a new one
121
- const authorData = {
122
- user_id: data.user_id,
123
- name: data.name,
124
- email: data.email,
125
- created_at: formatDate(new Date()),
126
- updated_at: formatDate(new Date()),
127
- }
128
-
129
- const result = await db
130
- .insertInto('authors')
131
- .values(authorData)
132
- .returningAll()
133
- .executeTakeFirst()
134
-
135
- if (!result)
136
- throw new Error('Failed to create author')
137
-
138
- return result as AuthorJsonResponse
139
- }
140
- catch (error) {
141
- if (error instanceof HttpError)
142
- throw error
143
- if (isUniqueViolation(error))
144
- throw new HttpError(409, 'An author with this email already exists')
145
- if (error instanceof Error)
146
- throw new TypeError(`Failed to find or create author: ${error.message}`)
147
-
148
- throw error
149
- }
150
- }
@@ -1,42 +0,0 @@
1
- type AuthorJsonResponse = ModelRow<typeof Author>
2
- type NewAuthor = NewModelData<typeof Author>
3
- import { getDb } from '../database'
4
- import { HttpError } from '@stacksjs/error-handling'
5
- import { formatDate, isUniqueViolation } from '@stacksjs/orm'
6
-
7
- /**
8
- * Update an existing author
9
- *
10
- * @param id The ID of the author to update
11
- * @param data The author data to update
12
- * @returns The updated author record
13
- */
14
- export async function update(id: number, data: Partial<NewAuthor>): Promise<AuthorJsonResponse | undefined> {
15
- const db = await getDb()
16
- try {
17
- const updateData = {
18
- ...data,
19
- updated_at: formatDate(new Date()),
20
- }
21
-
22
- const result = await db
23
- .updateTable('authors')
24
- .set(updateData)
25
- .where('id', '=', id)
26
- .returningAll()
27
- .executeTakeFirst()
28
-
29
- return result as AuthorJsonResponse | undefined
30
- }
31
- catch (error) {
32
- if (error instanceof HttpError)
33
- throw error
34
- // Duplicate authors.email on update (#1957).
35
- if (isUniqueViolation(error))
36
- throw new HttpError(409, 'An author with this email already exists')
37
- if (error instanceof Error)
38
- throw new TypeError(`Failed to update author: ${error.message}`)
39
-
40
- throw error
41
- }
42
- }