opacacms 0.1.11 → 0.1.13

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 (246) hide show
  1. package/dist/admin/index.js +9464 -21
  2. package/dist/admin/webcomponent.d.ts +1 -1
  3. package/dist/admin/webcomponent.js +9620 -6
  4. package/dist/admin.css +1 -0
  5. package/dist/{chunk-6dhs73zq.js → chunk-0am1m47g.js} +1 -1
  6. package/dist/{chunk-0nf7fe26.js → chunk-0d9aqz6z.js} +1 -1
  7. package/dist/{chunk-cvdd4eqh.js → chunk-2kyhqvhc.js} +5 -1
  8. package/dist/{chunk-gjjcc4hm.js → chunk-2z8wxx9g.js} +21 -6
  9. package/dist/{chunk-xg35h5a3.js → chunk-7fyepksb.js} +1 -1
  10. package/dist/{chunk-njytmdb4.js → chunk-pxh5encs.js} +34 -24
  11. package/dist/{chunk-n8aekdnr.js → chunk-qkn1ykrj.js} +33 -23
  12. package/dist/{chunk-kwp83w8b.js → chunk-wmvjvn7b.js} +4 -4
  13. package/dist/{chunk-qrt22f6e.js → chunk-wq314kkx.js} +35 -25
  14. package/dist/{chunk-eqtsfyjf.js → chunk-x2ejaftz.js} +52 -28
  15. package/dist/{chunk-6ew02s0c.js → chunk-xtwc125q.js} +18 -18
  16. package/dist/cli/index.js +5 -5
  17. package/dist/db/better-sqlite.d.ts +1 -0
  18. package/dist/db/better-sqlite.js +3 -3
  19. package/dist/db/bun-sqlite.d.ts +1 -0
  20. package/dist/db/bun-sqlite.js +3 -3
  21. package/dist/db/d1.js +3 -3
  22. package/dist/db/index.d.ts +3 -0
  23. package/dist/db/index.js +17 -13
  24. package/dist/db/postgres.js +3 -3
  25. package/dist/db/sqlite.js +3 -3
  26. package/dist/runtimes/bun.js +2 -2
  27. package/dist/runtimes/cloudflare-workers.js +2 -2
  28. package/dist/runtimes/next.js +2 -2
  29. package/dist/runtimes/node.js +2 -2
  30. package/dist/server.js +2 -2
  31. package/package.json +8 -2
  32. package/bun.lock +0 -34
  33. package/dist/admin/index.css +0 -47
  34. package/dist/api.d.ts +0 -6
  35. package/dist/api.js +0 -27
  36. package/dist/chunk-2zm8cy1w.js +0 -9482
  37. package/global.d.ts +0 -11
  38. package/src/admin/api-client.ts +0 -63
  39. package/src/admin/auth-client.ts +0 -40
  40. package/src/admin/custom-field.ts +0 -179
  41. package/src/admin/index.ts +0 -15
  42. package/src/admin/react.tsx +0 -72
  43. package/src/admin/router.ts +0 -9
  44. package/src/admin/stores/admin-queries.ts +0 -121
  45. package/src/admin/stores/auth.ts +0 -61
  46. package/src/admin/stores/column-visibility.ts +0 -67
  47. package/src/admin/stores/config.ts +0 -15
  48. package/src/admin/stores/media.ts +0 -95
  49. package/src/admin/stores/query.ts +0 -13
  50. package/src/admin/stores/ui.ts +0 -29
  51. package/src/admin/ui/admin-client.tsx +0 -283
  52. package/src/admin/ui/admin-layout.tsx +0 -276
  53. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  54. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  55. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  56. package/src/admin/ui/components/Table.tsx +0 -67
  57. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  58. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  59. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  60. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  61. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  62. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  63. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  64. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  65. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  66. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  67. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  68. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  69. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  70. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  71. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  72. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  73. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  74. package/src/admin/ui/components/fields/index.tsx +0 -371
  75. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  76. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  77. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  78. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  79. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  80. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  81. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  82. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  83. package/src/admin/ui/components/fields/utils.ts +0 -1
  84. package/src/admin/ui/components/link.tsx +0 -41
  85. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  86. package/src/admin/ui/components/toast.tsx +0 -72
  87. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  88. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  89. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  90. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  91. package/src/admin/ui/components/ui/button.tsx +0 -26
  92. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  93. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  94. package/src/admin/ui/components/ui/group.tsx +0 -20
  95. package/src/admin/ui/components/ui/index.ts +0 -17
  96. package/src/admin/ui/components/ui/input.tsx +0 -12
  97. package/src/admin/ui/components/ui/join.tsx +0 -53
  98. package/src/admin/ui/components/ui/label.tsx +0 -11
  99. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  100. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  101. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  102. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  103. package/src/admin/ui/components/ui/select.tsx +0 -187
  104. package/src/admin/ui/components/ui/separator.tsx +0 -21
  105. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  106. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  107. package/src/admin/ui/components/ui/utils.ts +0 -3
  108. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  109. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  110. package/src/admin/ui/styles/accordion.scss +0 -60
  111. package/src/admin/ui/styles/animations.scss +0 -41
  112. package/src/admin/ui/styles/asset-manager.scss +0 -547
  113. package/src/admin/ui/styles/badge.scss +0 -13
  114. package/src/admin/ui/styles/base.scss +0 -22
  115. package/src/admin/ui/styles/button.scss +0 -161
  116. package/src/admin/ui/styles/card.scss +0 -13
  117. package/src/admin/ui/styles/collapsible.scss +0 -75
  118. package/src/admin/ui/styles/data-detail.scss +0 -92
  119. package/src/admin/ui/styles/dialog.scss +0 -102
  120. package/src/admin/ui/styles/empty-state.scss +0 -22
  121. package/src/admin/ui/styles/group.scss +0 -19
  122. package/src/admin/ui/styles/index.scss +0 -33
  123. package/src/admin/ui/styles/input.scss +0 -80
  124. package/src/admin/ui/styles/label.scss +0 -12
  125. package/src/admin/ui/styles/layout.scss +0 -56
  126. package/src/admin/ui/styles/lexical.scss +0 -469
  127. package/src/admin/ui/styles/loading.scss +0 -102
  128. package/src/admin/ui/styles/media-registry.scss +0 -597
  129. package/src/admin/ui/styles/pagination.scss +0 -20
  130. package/src/admin/ui/styles/radio-group.scss +0 -66
  131. package/src/admin/ui/styles/row.scss +0 -17
  132. package/src/admin/ui/styles/scrollbar.scss +0 -36
  133. package/src/admin/ui/styles/select.scss +0 -121
  134. package/src/admin/ui/styles/separator.scss +0 -14
  135. package/src/admin/ui/styles/sheet.scss +0 -152
  136. package/src/admin/ui/styles/sidebar.scss +0 -148
  137. package/src/admin/ui/styles/switch.scss +0 -59
  138. package/src/admin/ui/styles/table.scss +0 -207
  139. package/src/admin/ui/styles/tabs.scss +0 -62
  140. package/src/admin/ui/styles/toast.scss +0 -45
  141. package/src/admin/ui/styles/variables.scss +0 -24
  142. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  143. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  144. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  145. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  146. package/src/admin/ui/views/init-view.tsx +0 -182
  147. package/src/admin/ui/views/login-view.tsx +0 -123
  148. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  149. package/src/admin/ui/views/settings-view.tsx +0 -729
  150. package/src/admin/webcomponent.tsx +0 -15
  151. package/src/api.ts +0 -9
  152. package/src/auth/index.ts +0 -194
  153. package/src/auth/migrations.ts +0 -87
  154. package/src/auth/premissions.ts +0 -46
  155. package/src/cli/commands/generate-types.ts +0 -116
  156. package/src/cli/commands/init.ts +0 -95
  157. package/src/cli/commands/migrate-commands.ts +0 -160
  158. package/src/cli/commands/seed-command.ts +0 -11
  159. package/src/cli/d1-mock.ts +0 -101
  160. package/src/cli/index.test.ts +0 -84
  161. package/src/cli/index.ts +0 -183
  162. package/src/cli/r2-mock.ts +0 -217
  163. package/src/cli/seeding.ts +0 -409
  164. package/src/client.ts +0 -181
  165. package/src/config-utils.ts +0 -102
  166. package/src/config.ts +0 -49
  167. package/src/db/adapter.ts +0 -53
  168. package/src/db/better-sqlite.ts +0 -632
  169. package/src/db/bun-sqlite.ts +0 -646
  170. package/src/db/d1.ts +0 -711
  171. package/src/db/index.ts +0 -6
  172. package/src/db/kysely/data-mapper.ts +0 -142
  173. package/src/db/kysely/field-mapper.ts +0 -148
  174. package/src/db/kysely/migration-generator.ts +0 -223
  175. package/src/db/kysely/query-builder.ts +0 -92
  176. package/src/db/kysely/schema-builder.ts +0 -439
  177. package/src/db/kysely/sql-utils.ts +0 -13
  178. package/src/db/postgres.ts +0 -621
  179. package/src/db/sqlite.ts +0 -660
  180. package/src/db/system-schema.ts +0 -121
  181. package/src/index.ts +0 -13
  182. package/src/runtimes/README.md +0 -59
  183. package/src/runtimes/bun.ts +0 -49
  184. package/src/runtimes/cloudflare-workers.ts +0 -38
  185. package/src/runtimes/next.ts +0 -26
  186. package/src/runtimes/node.ts +0 -52
  187. package/src/schema/collection.ts +0 -184
  188. package/src/schema/fields/base.ts +0 -164
  189. package/src/schema/fields/index.ts +0 -427
  190. package/src/schema/global.ts +0 -145
  191. package/src/schema/index.ts +0 -4
  192. package/src/schema/infer.ts +0 -72
  193. package/src/server/admin-router.ts +0 -20
  194. package/src/server/admin.ts +0 -142
  195. package/src/server/assets.ts +0 -306
  196. package/src/server/collection-router.ts +0 -55
  197. package/src/server/handlers.ts +0 -722
  198. package/src/server/middlewares/admin.ts +0 -27
  199. package/src/server/middlewares/auth.ts +0 -89
  200. package/src/server/middlewares/context.ts +0 -17
  201. package/src/server/middlewares/cors.ts +0 -24
  202. package/src/server/middlewares/database-init.ts +0 -74
  203. package/src/server/middlewares/rate-limit.ts +0 -77
  204. package/src/server/router.ts +0 -47
  205. package/src/server/setup-middlewares.ts +0 -58
  206. package/src/server/system-router.ts +0 -35
  207. package/src/server.ts +0 -9
  208. package/src/storage/adapters/cloudflare-r2.ts +0 -136
  209. package/src/storage/adapters/local.ts +0 -146
  210. package/src/storage/adapters/s3.ts +0 -186
  211. package/src/storage/errors.ts +0 -46
  212. package/src/storage/index.ts +0 -5
  213. package/src/storage/types.ts +0 -39
  214. package/src/types.ts +0 -577
  215. package/src/utils/lexical.ts +0 -37
  216. package/src/utils/logger.ts +0 -73
  217. package/src/validation.ts +0 -429
  218. package/src/validator.ts +0 -179
  219. package/test/admin-custom-field.test.ts +0 -162
  220. package/test/admin-react-field.test.tsx +0 -134
  221. package/test/api-features.test.ts +0 -78
  222. package/test/api.test.ts +0 -178
  223. package/test/auth.test.ts +0 -62
  224. package/test/cli-integration.test.ts +0 -148
  225. package/test/cli.test.ts +0 -25
  226. package/test/db/postgres.test.ts +0 -95
  227. package/test/db/sqlite-filter.test.ts +0 -53
  228. package/test/db/sqlite.test.ts +0 -82
  229. package/test/engine-features.test.ts +0 -79
  230. package/test/globals.test.ts +0 -74
  231. package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
  232. package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
  233. package/test/integration-tmp/my-test-app/index.ts +0 -8
  234. package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
  235. package/test/integration-tmp/my-test-app/package.json +0 -12
  236. package/test/populate.test.ts +0 -79
  237. package/test/runtimes.test.ts +0 -43
  238. package/test/schema-builder.test.ts +0 -107
  239. package/test/schema-features.test.ts +0 -63
  240. package/test/seeding.test.ts +0 -68
  241. package/test/storage/local.test.ts +0 -72
  242. package/test/storage/s3.test.ts +0 -60
  243. package/test/structural-data.test.ts +0 -100
  244. package/test/test-setup.ts +0 -11
  245. package/test/validation.test.ts +0 -162
  246. package/tsconfig.json +0 -42
@@ -1,121 +0,0 @@
1
- import type { Collection } from "../types";
2
-
3
- export const getSystemCollections = (): Collection[] => [
4
- {
5
- slug: "_opaca_assets",
6
- label: "Assets",
7
- apiPath: "assets",
8
- fields: [
9
- { name: "id", type: "text", required: true },
10
- { name: "key", type: "text", required: true },
11
- { name: "filename", type: "text", required: true },
12
- { name: "originalFilename", type: "text", required: true },
13
- { name: "mimeType", type: "text", required: true },
14
- { name: "filesize", type: "number", required: true },
15
- { name: "bucket", type: "text", required: true },
16
- { name: "folder", type: "text" },
17
- { name: "altText", type: "text" },
18
- { name: "caption", type: "text" },
19
- { name: "uploadedBy", type: "text" },
20
- ],
21
- timestamps: true,
22
- },
23
-
24
- // AUTH
25
- {
26
- slug: "_users",
27
- apiPath: "users",
28
- fields: [
29
- { name: "id", type: "text", required: true },
30
- { name: "name", type: "text", required: true },
31
- { name: "email", type: "text", required: true, unique: true },
32
- { name: "emailVerified", type: "boolean", required: true, defaultValue: false },
33
- { name: "image", type: "text" },
34
- { name: "role", type: "text" },
35
- { name: "banned", type: "boolean" },
36
- { name: "banReason", type: "text" },
37
- { name: "banExpires", type: "date" },
38
- ],
39
- timestamps: true,
40
- },
41
- {
42
- slug: "_sessions",
43
- fields: [
44
- { name: "id", type: "text", required: true },
45
- { name: "expiresAt", type: "date", required: true },
46
- { name: "token", type: "text", required: true, unique: true },
47
- { name: "ipAddress", type: "text" },
48
- { name: "userAgent", type: "text" },
49
- {
50
- name: "userId",
51
- type: "text",
52
- required: true,
53
- references: { table: "_users", column: "id", onDelete: "cascade" },
54
- },
55
- { name: "impersonatedBy", type: "text" },
56
- ],
57
- timestamps: true,
58
- hidden: true,
59
- },
60
- {
61
- slug: "_accounts",
62
- fields: [
63
- { name: "id", type: "text", required: true },
64
- { name: "accountId", type: "text", required: true },
65
- { name: "providerId", type: "text", required: true },
66
- {
67
- name: "userId",
68
- type: "text",
69
- required: true,
70
- references: { table: "_users", column: "id", onDelete: "cascade" },
71
- },
72
- { name: "accessToken", type: "text" },
73
- { name: "refreshToken", type: "text" },
74
- { name: "idToken", type: "text" },
75
- { name: "accessTokenExpiresAt", type: "date" },
76
- { name: "refreshTokenExpiresAt", type: "date" },
77
- { name: "scope", type: "text" },
78
- { name: "password", type: "text" },
79
- ],
80
- timestamps: true,
81
- hidden: true,
82
- },
83
- {
84
- slug: "_verifications",
85
- fields: [
86
- { name: "id", type: "text", required: true },
87
- { name: "identifier", type: "text", required: true },
88
- { name: "value", type: "text", required: true },
89
- { name: "expiresAt", type: "date", required: true },
90
- ],
91
- timestamps: true,
92
- hidden: true,
93
- },
94
- {
95
- slug: "_api_keys",
96
- fields: [
97
- { name: "id", type: "text", required: true },
98
- { name: "configId", type: "text", required: true },
99
- { name: "name", type: "text" },
100
- { name: "start", type: "text" },
101
- { name: "prefix", type: "text" },
102
- { name: "key", type: "text", required: true },
103
- { name: "referenceId", type: "text", required: true },
104
- { name: "refillInterval", type: "number" },
105
- { name: "refillAmount", type: "number" },
106
- { name: "lastRefillAt", type: "date" },
107
- { name: "enabled", type: "boolean", required: true },
108
- { name: "rateLimitEnabled", type: "boolean", required: true },
109
- { name: "rateLimitTimeWindow", type: "number" },
110
- { name: "rateLimitMax", type: "number" },
111
- { name: "requestCount", type: "number", required: true },
112
- { name: "remaining", type: "number" },
113
- { name: "lastRequest", type: "date" },
114
- { name: "expiresAt", type: "date" },
115
- { name: "permissions", type: "text" },
116
- { name: "metadata", type: "text" },
117
- ],
118
- timestamps: { createdAt: "createdAt", updatedAt: "updatedAt" },
119
- hidden: true,
120
- },
121
- ];
package/src/index.ts DELETED
@@ -1,13 +0,0 @@
1
- // Client-friendly index (safe for browser)
2
-
3
- export * from "./auth";
4
- export * from "./client";
5
- export * from "./config";
6
- export * from "./config-utils";
7
- export * from "./types";
8
- // Export everything from validation EXCEPT what conflicts with types
9
- export type {
10
- AdminConfig,
11
- CollectionHooks,
12
- FieldType,
13
- } from "./validation";
@@ -1,59 +0,0 @@
1
- # OpacaCMS Runtimes
2
-
3
- The `runtimes` directory contains adapters for different JavaScript environments where you can deploy your OpacaCMS project.
4
-
5
- Since OpacaCMS is built on top of [Hono](https://hono.dev), it is highly portable and can run anywhere Hono can run. Instead of writing boilerplate code to mount the OpacaCMS router (`createAPIRouter`) into your preferred framework or runtime, we provide pre-configured handlers here to keep your setup clean and simple.
6
-
7
- This approach ensures zero redundancy. The core logic lives in our internal router, while these runtime handlers simply wrap the router with the specific bindings needed for their environment.
8
-
9
- ## Available Runtimes
10
-
11
- ### 1. Next.js (`next.ts`)
12
- Creates an App Router compatible Route Handler. It leverages `hono/vercel` to wrap the API natively for Vercel's Node or Edge runtimes.
13
-
14
- **Usage (`app/api/[[...route]]/route.ts`):**
15
- ```ts
16
- import opacaConfig from "@opacacms-config";
17
- import { createNextHandler } from "opacacms/runtimes/next";
18
-
19
- export const { GET, POST, PUT, DELETE, PATCH, OPTIONS } = createNextHandler(opacaConfig);
20
- ```
21
-
22
- ### 2. Bun (`bun.ts`)
23
- Creates a native, ultra-fast server using `Bun.serve()`. Best for standalone deployments running natively with Bun.
24
-
25
- **Usage (`server.ts`):**
26
- ```ts
27
- import opacaConfig from "./opacacms.config";
28
- import { createBunHandler } from "opacacms/runtimes/bun";
29
-
30
- const { init } = createBunHandler(opacaConfig, { port: 3000 });
31
- init(); // Connects DB, runs migrations, and starts the server
32
- ```
33
-
34
- ### 3. Node.js (`node.ts`)
35
- Creates a standard Node.js standalone server using `@hono/node-server`. Use this if you want to deploy as a vanilla Node.js application (e.g. on Render, Railway, AWS EC2).
36
-
37
- **Usage (`server.js` / `server.ts`):**
38
- ```ts
39
- import opacaConfig from "./opacacms.config";
40
- import { createNodeHandler } from "opacacms/runtimes/node";
41
-
42
- const { init } = createNodeHandler(opacaConfig, { port: 3000 });
43
- init(); // Connects DB, runs migrations, and starts the server
44
- ```
45
-
46
- ### 4. Cloudflare Workers (`cloudflare-workers.ts`)
47
- Provides a native `fetch` handler optimized for Cloudflare Workers. It injects Cloudflare's `env` and `ctx` directly into the Hono instance.
48
-
49
- **Usage (`src/index.ts`):**
50
- ```ts
51
- import opacaConfig from "./opacacms.config";
52
- import { createCloudflareWorkersHandler } from "opacacms/runtimes/cloudflare-workers";
53
-
54
- export default createCloudflareWorkersHandler(opacaConfig);
55
- ```
56
-
57
- ---
58
-
59
- *Need support for another environment like Deno, AWS Lambda, or Netlify? Check out the [Hono Adapters Documentation](https://hono.dev/docs/getting-started/basic) and feel free to contribute!*
@@ -1,49 +0,0 @@
1
- import { Hono } from "hono";
2
- import { createAPIRouter } from "../server/router";
3
- import type { OpacaConfig } from "../types";
4
-
5
- export interface BunServerOptions {
6
- port?: number;
7
- }
8
-
9
- /**
10
- * Creates a standalone Bun server running OpacaCMS.
11
- * Bun has native support for the `fetch` API, making it extremely fast.
12
- *
13
- * @param config - The OpacaCMS configuration object.
14
- * @param options - Options for the Bun server (e.g., port).
15
- * @returns The Hono application instance and an `init` function to start the server.
16
- */
17
- export function createBunHandler(config: OpacaConfig, options?: BunServerOptions) {
18
- const app = new Hono();
19
-
20
- // Base router
21
- const apiRouter = createAPIRouter(config);
22
- app.route("/api", apiRouter);
23
-
24
- const init = async () => {
25
- console.log("🚀 Initializing OpacaCMS (Bun runtime)...");
26
-
27
- if (config.db) {
28
- await config.db.connect();
29
- console.log(`📦 Database "${config.db.name}" connected`);
30
-
31
- await config.db.migrate(config.collections);
32
- console.log("✅ Migrations completed");
33
- }
34
-
35
- const port = options?.port || 3000;
36
-
37
- // Using Bun's global server
38
- Bun.serve({
39
- fetch: app.fetch,
40
- port,
41
- });
42
-
43
- console.log(`Listening on http://localhost:${port}`);
44
-
45
- return app;
46
- };
47
-
48
- return { app, init };
49
- }
@@ -1,38 +0,0 @@
1
- import { Hono } from "hono";
2
- import { createAPIRouter } from "../server/router";
3
- import type { OpacaConfig } from "../types";
4
-
5
- let cachedApp: Hono | undefined;
6
-
7
- /**
8
- * Creates a Cloudflare Workers compatible handler for OpacaCMS.
9
- * Returns an object with a `fetch` method, perfectly matched for CF Workers.
10
- *
11
- * @param configOrFactory - Either the OpacaCMS configuration object or a function that returns it.
12
- * @returns An object with a standard `fetch` method signature.
13
- */
14
- export function createCloudflareWorkersHandler(
15
- configOrFactory:
16
- | OpacaConfig
17
- | ((env: any, request: Request) => OpacaConfig | Promise<OpacaConfig>),
18
- ) {
19
- const app = new Hono();
20
-
21
- app.use("/api/*", async (c, next) => {
22
- if (cachedApp) return cachedApp.fetch(c.req.raw, c.env, c.executionCtx);
23
-
24
- const config =
25
- typeof configOrFactory === "function"
26
- ? await configOrFactory(c.env, c.req.raw)
27
- : configOrFactory;
28
-
29
- const apiRouter = createAPIRouter(config);
30
- const innerApp = new Hono();
31
- innerApp.route("/", apiRouter);
32
- cachedApp = innerApp;
33
-
34
- return cachedApp.fetch(c.req.raw, c.env, c.executionCtx);
35
- });
36
-
37
- return app;
38
- }
@@ -1,26 +0,0 @@
1
- import { handle } from "hono/vercel";
2
- import { createAPIRouter } from "../server/router";
3
- import type { OpacaConfig } from "../types";
4
-
5
- /**
6
- * Creates a Next.js App Router compatible route handler for OpacaCMS.
7
- * Wraps the internal Hono router using `hono/vercel`.
8
- *
9
- * @param config - The OpacaCMS configuration object.
10
- * @returns An object containing the HTTP methods to be exported in `app/api/[[...route]]/route.ts`.
11
- */
12
- export function createNextHandler(config: OpacaConfig) {
13
- const app = createAPIRouter(config);
14
-
15
- // Vercel's edge/node runtime handles all these methods natively via `handle`
16
- const handler = handle(app);
17
-
18
- return {
19
- GET: handler,
20
- POST: handler,
21
- PUT: handler,
22
- DELETE: handler,
23
- PATCH: handler,
24
- OPTIONS: handler,
25
- };
26
- }
@@ -1,52 +0,0 @@
1
- import { serve } from "@hono/node-server";
2
- import { Hono } from "hono";
3
- import { createAPIRouter } from "../server/router";
4
- import type { OpacaConfig } from "../types";
5
-
6
- export interface NodeServerOptions {
7
- port?: number;
8
- fetch?: (request: Request) => Promise<Response>;
9
- }
10
-
11
- /**
12
- * Creates a standalone Node.js server running OpacaCMS.
13
- * Uses `@hono/node-server` to serve the API.
14
- *
15
- * @param config - The OpacaCMS configuration object.
16
- * @param options - Options for the Node server (e.g., port).
17
- * @returns The Hono application instance and an `init` function to start the server.
18
- */
19
- export function createNodeHandler(config: OpacaConfig, options?: NodeServerOptions) {
20
- const app = new Hono();
21
-
22
- // Base router
23
- const apiRouter = createAPIRouter(config);
24
- app.route("/api", apiRouter);
25
-
26
- const init = async () => {
27
- console.log("🚀 Initializing OpacaCMS (Node.js runtime)...");
28
-
29
- if (config.db) {
30
- await config.db.connect();
31
- console.log(`📦 Database "${config.db.name}" connected`);
32
-
33
- await config.db.migrate(config.collections);
34
- console.log("✅ Migrations completed");
35
- }
36
-
37
- const port = options?.port || 3000;
38
- serve(
39
- {
40
- fetch: app.fetch,
41
- port,
42
- },
43
- (info) => {
44
- console.log(`Listening on http://localhost:${info.port}`);
45
- },
46
- );
47
-
48
- return app;
49
- };
50
-
51
- return { app, init };
52
- }
@@ -1,184 +0,0 @@
1
- import { icons } from "lucide-react";
2
- import type { Collection as BaseCollection, IconName } from "../types";
3
- import { type FieldBuilder, VirtualFieldBuilder } from "./fields";
4
- import type { AccessRules, InferFields } from "./infer";
5
-
6
- /**
7
- * The Fluent API Collection Builder.
8
- */
9
- export class CollectionBuilder<TFields extends Record<string, any> = {}> {
10
- private config: Partial<BaseCollection> = {
11
- fields: [],
12
- timestamps: true,
13
- };
14
-
15
- private fieldBuilders: FieldBuilder<any, any>[] = [];
16
-
17
- constructor(public readonly slug: string) {
18
- this.config.slug = slug;
19
- }
20
-
21
- /**
22
- * Sets the user-friendly label for the Collection.
23
- */
24
- public label(label: string): this {
25
- this.config.label = label;
26
- return this;
27
- }
28
-
29
- /**
30
- * Sets the Lucide icon for this collection.
31
- */
32
- public icon(iconName: IconName): this {
33
- this.config.icon = iconName;
34
- return this;
35
- }
36
-
37
- /**
38
- * Defines which field should be used as the title in the Admin UI.
39
- */
40
- public useAsTitle(fieldName: keyof TFields | (string & {})): this {
41
- this._ensureAdmin();
42
- (this.config.admin as any).useAsTitle = fieldName;
43
- return this;
44
- }
45
-
46
- /**
47
- * Enables or disables automatic timestamps (createdAt, updatedAt).
48
- */
49
- public timestamps(val = true): this {
50
- this.config.timestamps = val;
51
- return this;
52
- }
53
-
54
- /**
55
- * Defines the fields for this Collection.
56
- * Re-instantiates the builder to capture the strong types of the fields.
57
- */
58
- public fields<T extends readonly any[]>(fields: [...T]): CollectionBuilder<InferFields<T>> {
59
- // We clone the current builder state to a newly typed instance.
60
- const nextBuilder = new CollectionBuilder<InferFields<T>>(this.config.slug!);
61
- nextBuilder.config = { ...this.config };
62
- nextBuilder.fieldBuilders = [...fields];
63
- return nextBuilder;
64
- }
65
-
66
- /**
67
- * Type-safe access control rules.
68
- */
69
- public access(rules: AccessRules<TFields>): this {
70
- this.config.access = rules as any;
71
- return this;
72
- }
73
-
74
- /**
75
- * Defines a virtual/computed field with full type inference of the current collection data.
76
- */
77
- public virtual<TName extends string, TReturn = any>(
78
- name: TName,
79
- options: {
80
- label?: string;
81
- resolve: (args: {
82
- data: TFields;
83
- req: any;
84
- user: any;
85
- session: any;
86
- apiKey?: any;
87
- }) => TReturn | Promise<TReturn>;
88
- returnType?: "string" | "number" | "boolean" | "json";
89
- },
90
- ): CollectionBuilder<TFields & { [K in TName]: TReturn }> {
91
- const builder = new VirtualFieldBuilder<TName, TFields>(name);
92
- if (options.label) builder.label(options.label);
93
- if (options.resolve) builder.resolve(options.resolve as any);
94
- if (options.returnType) builder.returnType(options.returnType);
95
-
96
- const nextBuilder = new CollectionBuilder<TFields & { [K in TName]: TReturn }>(
97
- this.config.slug!,
98
- );
99
- nextBuilder.config = { ...this.config };
100
- nextBuilder.fieldBuilders = [...this.fieldBuilders, builder];
101
- return nextBuilder;
102
- }
103
-
104
- /**
105
- * Alias for .virtual()
106
- */
107
- public computed<TName extends string, TReturn = any>(
108
- name: TName,
109
- options: {
110
- label?: string;
111
- resolve: (args: {
112
- data: TFields;
113
- req: any;
114
- user: any;
115
- session: any;
116
- apiKey?: any;
117
- }) => TReturn | Promise<TReturn>;
118
- returnType?: "string" | "number" | "boolean" | "json";
119
- },
120
- ): CollectionBuilder<TFields & { [K in TName]: TReturn }> {
121
- return this.virtual<TName, TReturn>(name, options);
122
- }
123
-
124
- /**
125
- * Advanced Admin UI configuration.
126
- */
127
- public admin(opts: BaseCollection["admin"]): this {
128
- if (typeof opts === "boolean") {
129
- this.config.admin = opts;
130
- } else {
131
- this.config.admin = { ...(this.config.admin as object), ...opts };
132
- }
133
- return this;
134
- }
135
-
136
- /**
137
- * Adds automated versioning and drafts.
138
- */
139
- public versions(opts: { drafts?: boolean; maxRevisions?: number; autosave?: boolean }): this {
140
- this.config.versions = opts;
141
- return this;
142
- }
143
-
144
- /**
145
- * Adds webhooks to be triggered on document lifecycle events.
146
- */
147
- public webhooks(
148
- webhooks: { events: string[]; url: string; headers?: Record<string, string> }[],
149
- ): this {
150
- this.config.webhooks = webhooks;
151
- return this;
152
- }
153
-
154
- /**
155
- * Spreads configuration from presets (Proposed Feature stub)
156
- */
157
- public extend(preset: any): this {
158
- // Deep merge logic would go here
159
- return this;
160
- }
161
-
162
- protected _ensureAdmin() {
163
- if (!this.config.admin || typeof this.config.admin === "boolean") {
164
- this.config.admin = {};
165
- }
166
- }
167
-
168
- /**
169
- * Compiles the collection builder down into the raw Object structure expected by OpacaCMS.
170
- */
171
- public build(): BaseCollection {
172
- // Build all fields into raw JSON objects
173
- const compiledFields = this.fieldBuilders.map((builder) => builder.build());
174
-
175
- return {
176
- ...this.config,
177
- fields: compiledFields,
178
- } as BaseCollection;
179
- }
180
- }
181
-
182
- export const Collection = {
183
- create: (slug: string) => new CollectionBuilder(slug),
184
- };