opacacms 0.1.0 → 0.1.2

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 (247) hide show
  1. package/dist/admin/index.js +49 -0
  2. package/dist/{chunk-2zm8cy1w.js → admin/webcomponent.js} +116 -168
  3. package/dist/{chunk-6dhs73zq.js → chunk-2yz1nsxs.js} +1 -1
  4. package/dist/chunk-fa5mg0hr.js +96 -0
  5. package/dist/{chunk-kwp83w8b.js → chunk-m09hahe2.js} +7 -7
  6. package/dist/{chunk-hmhcense.js → chunk-ry15hke8.js} +253 -4
  7. package/dist/chunk-vtvqfhgy.js +2442 -0
  8. package/dist/{chunk-f3nvxn63.js → chunk-y8hc6nm4.js} +1 -1
  9. package/dist/{src/cli → cli}/index.js +10 -10
  10. package/dist/{src/client.js → client.js} +2 -2
  11. package/dist/{src/db → db}/bun-sqlite.js +10 -10
  12. package/dist/{src/db → db}/d1.js +8 -8
  13. package/dist/db/index.d.ts +2 -0
  14. package/dist/db/index.js +7 -0
  15. package/dist/db/migration.d.ts +39 -0
  16. package/dist/{src/db → db}/postgres.js +10 -10
  17. package/dist/{src/db → db}/sqlite.js +8 -8
  18. package/dist/index.d.ts +0 -2
  19. package/dist/index.js +13 -0
  20. package/dist/{src/runtimes → runtimes}/bun.js +5 -6
  21. package/dist/{src/runtimes → runtimes}/cloudflare-workers.js +5 -6
  22. package/dist/{src/runtimes → runtimes}/next.js +5 -6
  23. package/dist/{src/runtimes → runtimes}/node.js +5 -6
  24. package/dist/{src/server.js → server.js} +7 -8
  25. package/dist/storage/index.d.ts +0 -3
  26. package/dist/storage/index.js +35 -0
  27. package/dist/types.d.ts +5 -2
  28. package/package.json +161 -39
  29. package/bun.lock +0 -34
  30. package/dist/api.d.ts +0 -6
  31. package/dist/chunk-8gkhn1d4.js +0 -309
  32. package/dist/chunk-dy5t83hr.js +0 -261
  33. package/dist/src/admin/index.js +0 -176
  34. package/dist/src/admin/webcomponent.js +0 -19
  35. package/dist/src/api.js +0 -27
  36. package/dist/src/index.js +0 -20
  37. package/dist/src/storage/index.js +0 -355
  38. package/global.d.ts +0 -11
  39. package/src/admin/api-client.ts +0 -63
  40. package/src/admin/auth-client.ts +0 -40
  41. package/src/admin/custom-field.ts +0 -179
  42. package/src/admin/index.ts +0 -15
  43. package/src/admin/react.tsx +0 -72
  44. package/src/admin/router.ts +0 -9
  45. package/src/admin/stores/admin-queries.ts +0 -121
  46. package/src/admin/stores/auth.ts +0 -61
  47. package/src/admin/stores/column-visibility.ts +0 -67
  48. package/src/admin/stores/config.ts +0 -15
  49. package/src/admin/stores/media.ts +0 -95
  50. package/src/admin/stores/query.ts +0 -13
  51. package/src/admin/stores/ui.ts +0 -29
  52. package/src/admin/ui/admin-client.tsx +0 -283
  53. package/src/admin/ui/admin-layout.tsx +0 -276
  54. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  55. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  56. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  57. package/src/admin/ui/components/Table.tsx +0 -67
  58. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  59. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  60. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  61. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  62. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  63. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  64. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  65. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  66. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  67. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  68. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  69. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  70. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  71. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  72. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  73. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  74. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  75. package/src/admin/ui/components/fields/index.tsx +0 -371
  76. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  77. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  78. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  79. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  80. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  81. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  82. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  83. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  84. package/src/admin/ui/components/fields/utils.ts +0 -1
  85. package/src/admin/ui/components/link.tsx +0 -41
  86. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  87. package/src/admin/ui/components/toast.tsx +0 -72
  88. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  89. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  90. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  91. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  92. package/src/admin/ui/components/ui/button.tsx +0 -26
  93. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  94. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  95. package/src/admin/ui/components/ui/group.tsx +0 -20
  96. package/src/admin/ui/components/ui/index.ts +0 -17
  97. package/src/admin/ui/components/ui/input.tsx +0 -12
  98. package/src/admin/ui/components/ui/join.tsx +0 -53
  99. package/src/admin/ui/components/ui/label.tsx +0 -11
  100. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  101. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  102. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  103. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  104. package/src/admin/ui/components/ui/select.tsx +0 -187
  105. package/src/admin/ui/components/ui/separator.tsx +0 -21
  106. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  107. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  108. package/src/admin/ui/components/ui/utils.ts +0 -3
  109. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  110. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  111. package/src/admin/ui/styles/accordion.scss +0 -60
  112. package/src/admin/ui/styles/animations.scss +0 -41
  113. package/src/admin/ui/styles/asset-manager.scss +0 -547
  114. package/src/admin/ui/styles/badge.scss +0 -13
  115. package/src/admin/ui/styles/base.scss +0 -22
  116. package/src/admin/ui/styles/button.scss +0 -161
  117. package/src/admin/ui/styles/card.scss +0 -13
  118. package/src/admin/ui/styles/collapsible.scss +0 -75
  119. package/src/admin/ui/styles/data-detail.scss +0 -92
  120. package/src/admin/ui/styles/dialog.scss +0 -102
  121. package/src/admin/ui/styles/empty-state.scss +0 -22
  122. package/src/admin/ui/styles/group.scss +0 -19
  123. package/src/admin/ui/styles/index.scss +0 -33
  124. package/src/admin/ui/styles/input.scss +0 -80
  125. package/src/admin/ui/styles/label.scss +0 -12
  126. package/src/admin/ui/styles/layout.scss +0 -56
  127. package/src/admin/ui/styles/lexical.scss +0 -469
  128. package/src/admin/ui/styles/loading.scss +0 -102
  129. package/src/admin/ui/styles/media-registry.scss +0 -597
  130. package/src/admin/ui/styles/pagination.scss +0 -20
  131. package/src/admin/ui/styles/radio-group.scss +0 -66
  132. package/src/admin/ui/styles/row.scss +0 -17
  133. package/src/admin/ui/styles/scrollbar.scss +0 -36
  134. package/src/admin/ui/styles/select.scss +0 -121
  135. package/src/admin/ui/styles/separator.scss +0 -14
  136. package/src/admin/ui/styles/sheet.scss +0 -152
  137. package/src/admin/ui/styles/sidebar.scss +0 -148
  138. package/src/admin/ui/styles/switch.scss +0 -59
  139. package/src/admin/ui/styles/table.scss +0 -207
  140. package/src/admin/ui/styles/tabs.scss +0 -62
  141. package/src/admin/ui/styles/toast.scss +0 -45
  142. package/src/admin/ui/styles/variables.scss +0 -24
  143. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  144. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  145. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  146. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  147. package/src/admin/ui/views/init-view.tsx +0 -182
  148. package/src/admin/ui/views/login-view.tsx +0 -123
  149. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  150. package/src/admin/ui/views/settings-view.tsx +0 -729
  151. package/src/admin/webcomponent.tsx +0 -15
  152. package/src/api.ts +0 -9
  153. package/src/auth/index.ts +0 -194
  154. package/src/auth/migrations.ts +0 -87
  155. package/src/auth/premissions.ts +0 -46
  156. package/src/cli/commands/generate-types.ts +0 -116
  157. package/src/cli/commands/init.ts +0 -95
  158. package/src/cli/commands/migrate-commands.ts +0 -160
  159. package/src/cli/commands/seed-command.ts +0 -11
  160. package/src/cli/d1-mock.ts +0 -101
  161. package/src/cli/index.test.ts +0 -84
  162. package/src/cli/index.ts +0 -183
  163. package/src/cli/r2-mock.ts +0 -217
  164. package/src/cli/seeding.ts +0 -405
  165. package/src/client.ts +0 -181
  166. package/src/config-utils.ts +0 -102
  167. package/src/config.ts +0 -49
  168. package/src/db/adapter.ts +0 -53
  169. package/src/db/better-sqlite.ts +0 -630
  170. package/src/db/bun-sqlite.ts +0 -646
  171. package/src/db/d1.ts +0 -711
  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 -658
  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 -71
  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 -146
  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
  247. /package/dist/{src/admin/index.css → admin/webcomponent.css} +0 -0
@@ -1,79 +0,0 @@
1
- import { afterAll, beforeAll, expect, test } from "bun:test";
2
- import { Hono } from "hono";
3
- import { defineConfig } from "../src/config";
4
- import { createBunSQLiteAdapter } from "../src/db/bun-sqlite";
5
- import { createAPIRouter } from "../src/server/router";
6
-
7
- let app: Hono;
8
- const dbPath = ":memory:";
9
- const db = createBunSQLiteAdapter(dbPath, { push: true });
10
-
11
- beforeAll(async () => {
12
- const config = defineConfig({
13
- db,
14
- collections: [
15
- {
16
- slug: "authors",
17
- fields: [{ name: "name", type: "text" }],
18
- },
19
- {
20
- slug: "posts",
21
- fields: [
22
- { name: "title", type: "text" },
23
- { name: "authorId", type: "relationship", relationTo: "authors" },
24
- ],
25
- },
26
- ],
27
- });
28
-
29
- app = new Hono();
30
- app.route("/", createAPIRouter(config));
31
-
32
- await db.connect();
33
- });
34
-
35
- afterAll(async () => {
36
- await db.disconnect();
37
- });
38
-
39
- test("POST /api/authors - create author", async () => {
40
- const res = await app.request("/api/authors", {
41
- method: "POST",
42
- headers: { "Content-Type": "application/json" },
43
- body: JSON.stringify({ name: "Jane Doe" }),
44
- });
45
- expect(res.status).toBe(201);
46
- const data = (await res.json()) as any;
47
- expect(data.id).toBeDefined();
48
- // store id for next test
49
- process.env.TEST_AUTHOR_ID = data.id.toString();
50
- });
51
-
52
- test("POST /api/posts - create post with authorId", async () => {
53
- const authorId = process.env.TEST_AUTHOR_ID;
54
- const res = await app.request("/api/posts", {
55
- method: "POST",
56
- headers: { "Content-Type": "application/json" },
57
- body: JSON.stringify({ title: "Hello World", authorId }),
58
- });
59
- expect(res.status).toBe(201);
60
- const data = (await res.json()) as any;
61
- expect(data.authorId).toBe(authorId);
62
- process.env.TEST_POST_ID = data.id.toString();
63
- });
64
-
65
- test("GET /api/posts/:id?populate=authorId - retrieves populated data", async () => {
66
- const postId = process.env.TEST_POST_ID;
67
- const res = await app.request(`/api/posts/${postId}?populate=authorId`);
68
- expect(res.status).toBe(200);
69
- const data = (await res.json()) as any;
70
- expect(data.authorId).toBeObject();
71
- expect(data.authorId.name).toBe("Jane Doe");
72
- });
73
-
74
- test("GET /api/posts - handles populate for multiple docs", async () => {
75
- const res = await app.request(`/api/posts?populate=authorId`);
76
- expect(res.status).toBe(200);
77
- const data = (await res.json()) as any;
78
- expect(data.docs[0].authorId.name).toBe("Jane Doe");
79
- });
@@ -1,43 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { createBunSQLiteAdapter } from "../src/db/bun-sqlite";
3
- import { createBunHandler } from "../src/runtimes/bun";
4
- import { createCloudflareWorkersHandler } from "../src/runtimes/cloudflare-workers";
5
- import { createNextHandler } from "../src/runtimes/next";
6
- import { createNodeHandler } from "../src/runtimes/node";
7
- import type { OpacaConfig } from "../src/types";
8
-
9
- describe("Runtimes", () => {
10
- const mockConfig: OpacaConfig = {
11
- db: createBunSQLiteAdapter(":memory:"),
12
- collections: [],
13
- };
14
-
15
- test("Next.js handler should export proper HTTP methods", () => {
16
- const handler = createNextHandler(mockConfig);
17
- expect(handler.GET).toBeDefined();
18
- expect(handler.POST).toBeDefined();
19
- expect(handler.PUT).toBeDefined();
20
- expect(handler.DELETE).toBeDefined();
21
- expect(handler.PATCH).toBeDefined();
22
- expect(handler.OPTIONS).toBeDefined();
23
- expect(typeof handler.GET).toBe("function");
24
- });
25
-
26
- test("Bun handler should expose app and init function", () => {
27
- const handler = createBunHandler(mockConfig);
28
- expect(handler.app).toBeDefined();
29
- expect(typeof handler.init).toBe("function");
30
- });
31
-
32
- test("Node handler should expose app and init function", () => {
33
- const handler = createNodeHandler(mockConfig);
34
- expect(handler.app).toBeDefined();
35
- expect(typeof handler.init).toBe("function");
36
- });
37
-
38
- test("Cloudflare Workers handler should expose a fetch method", () => {
39
- const handler = createCloudflareWorkersHandler(mockConfig);
40
- expect(handler.fetch).toBeDefined();
41
- expect(typeof handler.fetch).toBe("function");
42
- });
43
- });
@@ -1,107 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { Collection, Field } from "../src/schema";
3
-
4
- describe("Fluent API Schema Builder", () => {
5
- test("Should build a valid OpacaCMS Collection object matching perfectly with legacy JSON", () => {
6
- const builder = Collection.create("posts")
7
- .label("Blog Posts")
8
- .useAsTitle("title")
9
- .timestamps(true)
10
- .fields([
11
- Field.text("title").required().description("The post title"),
12
- Field.richText("content").mode("notion"),
13
- Field.relationship("author").to("users").single(),
14
- ])
15
- .access({
16
- read: () => true,
17
- update: ({ data }) => {
18
- // Type Test: Ensure 'data' has inferred types.
19
- // Because of TypeScript generics, data.title, data.content, data.author should be recognized.
20
- // Hovering over 'data' in an IDE would show: { title: string; content: any; author: string | string[] }
21
- const _title: string = data.title;
22
- const _auth: string | string[] = data.author;
23
-
24
- return true;
25
- },
26
- });
27
-
28
- const schema = builder.build();
29
-
30
- expect(schema).toEqual({
31
- slug: "posts",
32
- label: "Blog Posts",
33
- timestamps: true,
34
- admin: {
35
- useAsTitle: "title",
36
- },
37
- fields: [
38
- {
39
- type: "text",
40
- name: "title",
41
- required: true,
42
- admin: { description: "The post title" },
43
- },
44
- {
45
- type: "richtext",
46
- name: "content",
47
- options: { defaultMode: "notion" },
48
- },
49
- {
50
- type: "relationship",
51
- name: "author",
52
- relationTo: "users",
53
- hasMany: false,
54
- },
55
- ],
56
- access: expect.any(Object), // Access object is present containing the functions
57
- });
58
- });
59
-
60
- test("Should build complex nested fields (Array, Group, Blocks)", () => {
61
- const builder = Collection.create("settings").fields([
62
- Field.group("contact").fields(Field.text("email").required(), Field.text("phone")),
63
- Field.array("links").of(Field.row().fields(Field.text("label"), Field.text("url"))),
64
- Field.blocks("layout").blocks(
65
- Field.block("hero").label("Hero Section").fields(Field.text("headline")),
66
- ),
67
- ]);
68
-
69
- const schema = builder.build();
70
-
71
- expect(schema.fields).toEqual([
72
- {
73
- type: "group",
74
- name: "contact",
75
- fields: [
76
- { type: "text", name: "email", required: true },
77
- { type: "text", name: "phone" },
78
- ],
79
- },
80
- {
81
- type: "array",
82
- name: "links",
83
- fields: [
84
- {
85
- type: "row",
86
- name: "",
87
- fields: [
88
- { type: "text", name: "label" },
89
- { type: "text", name: "url" },
90
- ],
91
- },
92
- ],
93
- },
94
- {
95
- type: "blocks",
96
- name: "layout",
97
- blocks: [
98
- {
99
- slug: "hero",
100
- label: "Hero Section",
101
- fields: [{ type: "text", name: "headline" }],
102
- },
103
- ],
104
- },
105
- ]);
106
- });
107
- });
@@ -1,63 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { Collection, Field } from "../src/schema";
3
-
4
- describe("Fluent API Schema Features", () => {
5
- test("Should support Slug fields correctly", () => {
6
- const posts = Collection.create("posts")
7
- .fields([Field.text("title"), Field.slug("slug").from("title").unique()])
8
- .build();
9
-
10
- expect(posts.slug).toBe("posts");
11
- expect(posts.fields).toHaveLength(2);
12
- expect(posts.fields[1]!.type).toBe("slug");
13
- expect((posts.fields[1] as any).from).toBe("title");
14
- expect(posts.fields[1]!.unique).toBe(true);
15
- });
16
-
17
- test("Should support field localization", () => {
18
- const pages = Collection.create("pages")
19
- .fields([Field.text("title").localized()])
20
- .build();
21
-
22
- expect(pages.fields[0]!.localized).toBe(true);
23
- });
24
-
25
- test("Should support versions and drafts", () => {
26
- const pages = Collection.create("pages")
27
- .versions({ drafts: true, maxRevisions: 10, autosave: true })
28
- .build();
29
-
30
- expect(pages.versions).toBeDefined();
31
- expect(pages.versions!.drafts).toBe(true);
32
- expect(pages.versions!.maxRevisions).toBe(10);
33
- });
34
-
35
- test("Should support webhooks", () => {
36
- const subs = Collection.create("subscribers")
37
- .webhooks([
38
- {
39
- events: ["afterCreate"],
40
- url: "https://example.com/webhook",
41
- },
42
- ])
43
- .build();
44
-
45
- expect(subs.webhooks).toBeDefined();
46
- expect(subs.webhooks![0]!.events).toContain("afterCreate");
47
- expect(subs.webhooks![0]!.url).toBe("https://example.com/webhook");
48
- });
49
-
50
- test("Should support admin UI views and bulk actions", () => {
51
- const orders = Collection.create("orders")
52
- .admin({
53
- views: [{ name: "Pending", filter: { status: "pending" } }],
54
- bulkActions: [{ label: "Approve", action: async () => true }],
55
- })
56
- .build();
57
-
58
- expect(orders.admin).toBeDefined();
59
- expect((orders.admin as any).views).toBeDefined();
60
- expect((orders.admin as any).views![0]!.name).toBe("Pending");
61
- expect((orders.admin as any).bulkActions).toBeDefined();
62
- });
63
- });
@@ -1,68 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { generateRecord, sortCollections } from "../src/cli/seeding";
3
- import { createBunSQLiteAdapter } from "../src/db/bun-sqlite";
4
- import type { Collection, DatabaseAdapter } from "../src/types";
5
-
6
- describe("Seeding Logic", () => {
7
- const mockDb = {
8
- find: async () => ({ docs: [{ id: "123" }], totalDocs: 1 }),
9
- create: async () => ({ id: "456" }),
10
- } as unknown as DatabaseAdapter;
11
-
12
- const collections: Collection[] = [
13
- {
14
- slug: "users",
15
- fields: [
16
- { name: "name", type: "text" },
17
- { name: "email", type: "text" },
18
- ],
19
- },
20
- {
21
- slug: "posts",
22
- fields: [
23
- { name: "title", type: "text" },
24
- { name: "author", type: "relationship", relationTo: "users" },
25
- ],
26
- },
27
- ];
28
-
29
- test("sortCollections handles dependencies", () => {
30
- const sorted = sortCollections(collections);
31
- const userIndex = sorted.findIndex((c) => c.slug === "users");
32
- const postIndex = sorted.findIndex((c) => c.slug === "posts");
33
- expect(userIndex).toBeLessThan(postIndex);
34
- });
35
-
36
- test("generateRecord creates mock data", async () => {
37
- const userRecord = await generateRecord(mockDb, collections[0]!);
38
- expect(userRecord.name).toBeString();
39
- expect(userRecord.email).toBeString();
40
- });
41
-
42
- test("generateRecord handles relationships", async () => {
43
- const postRecord = await generateRecord(mockDb, collections[1]!);
44
- expect(postRecord.title).toBeString();
45
- expect(postRecord.author).toBe("123");
46
- });
47
-
48
- test("integrates with real database", async () => {
49
- const db = createBunSQLiteAdapter(":memory:", { push: true });
50
- await db.connect();
51
-
52
- try {
53
- // Create tables
54
- await db.unsafe("CREATE TABLE users (id TEXT PRIMARY KEY, name TEXT, email TEXT)");
55
- await db.migrate(collections as Collection[]);
56
-
57
- const record = await generateRecord(db, collections[0]!);
58
- const created = (await db.create("users", record)) as any;
59
-
60
- expect(created.name).toBe(record.name);
61
-
62
- const found = await db.find("users");
63
- expect(found.docs.length).toBe(1);
64
- } finally {
65
- await db.disconnect();
66
- }
67
- });
68
- });
@@ -1,72 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
- import { createLocalAdapter } from "../../src/storage/adapters/local";
5
- import { FileTooLargeError, Invalidmime_typeError } from "../../src/storage/errors";
6
-
7
- const TEST_DIR = path.resolve(process.cwd(), ".test_uploads");
8
-
9
- describe("Local Storage Adapter", () => {
10
- const adapter = createLocalAdapter({
11
- uploadDir: TEST_DIR,
12
- publicUrl: "/media",
13
- });
14
-
15
- const mockBuffer = Buffer.from("fake image data");
16
- const mockFile = {
17
- filename: "test-image.jpg",
18
- original_filename: "test-image.jpg",
19
- mime_type: "image/jpeg",
20
- filesize: mockBuffer.length,
21
- buffer: mockBuffer,
22
- };
23
-
24
- beforeAll(async () => {
25
- await fs.mkdir(TEST_DIR, { recursive: true });
26
- });
27
-
28
- afterAll(async () => {
29
- await fs.rm(TEST_DIR, { recursive: true, force: true });
30
- });
31
-
32
- test("successfully writes a file to disk and returns correct URL", async () => {
33
- const result = await adapter.upload(mockFile);
34
-
35
- expect(result.filename).toBe("test-image.jpg");
36
- expect(result.url).toBe("/media/test-image.jpg");
37
-
38
- const fileExists = await adapter.exists!("test-image.jpg");
39
- expect(fileExists).toBe(true);
40
-
41
- const content = await fs.readFile(path.join(TEST_DIR, "test-image.jpg"));
42
- expect(content.toString()).toBe("fake image data");
43
- });
44
-
45
- test("successfully deletes a file from disk", async () => {
46
- await adapter.upload({ ...mockFile, filename: "to-delete.png" });
47
- expect(await adapter.exists!("to-delete.png")).toBe(true);
48
-
49
- await adapter.delete("to-delete.png");
50
-
51
- expect(await adapter.exists!("to-delete.png")).toBe(false);
52
- });
53
-
54
- test("generates unique filenames to prevent collisions", async () => {
55
- const options = { generateUniqueName: true };
56
- const result1 = await adapter.upload(mockFile, options);
57
- const result2 = await adapter.upload(mockFile, options);
58
-
59
- expect(result1.filename).not.toBe(result2.filename);
60
- expect(result1.filename).toMatch(/^test-image-[a-z0-9-]+\.jpg$/);
61
- });
62
-
63
- test("enforces maxFileSize limit", async () => {
64
- const options = { maxFileSize: 5 }; // Very small limit
65
- expect(adapter.upload(mockFile, options)).rejects.toBeInstanceOf(FileTooLargeError);
66
- });
67
-
68
- test("enforces mime_type limit", async () => {
69
- const options = { allowedmime_types: ["image/png"] };
70
- expect(adapter.upload(mockFile, options)).rejects.toBeInstanceOf(Invalidmime_typeError);
71
- });
72
- });
@@ -1,60 +0,0 @@
1
- import { describe, expect, mock, test } from "bun:test";
2
- import { createS3Adapter } from "../../src/storage/adapters/s3";
3
- import { FileTooLargeError, Invalidmime_typeError } from "../../src/storage/errors";
4
-
5
- // Mock the AWS SDK
6
- mock.module("@aws-sdk/client-s3", () => {
7
- return {
8
- S3Client: mock().mockImplementation(() => ({
9
- send: mock().mockResolvedValue({}), // Simulate a successful HTTP response
10
- })),
11
- PutObjectCommand: mock(),
12
- DeleteObjectCommand: mock(),
13
- GetObjectCommand: mock(),
14
- HeadObjectCommand: mock(),
15
- };
16
- });
17
-
18
- describe("S3 Storage Adapter", () => {
19
- const config = {
20
- region: "us-east-1",
21
- bucket: "test-bucket",
22
- credentials: { accessKeyId: "test", secretAccessKey: "test" },
23
- };
24
- const adapter = createS3Adapter(config);
25
-
26
- const mockFile = {
27
- filename: "test.jpg",
28
- original_filename: "test.jpg",
29
- mime_type: "image/jpeg",
30
- filesize: 1024,
31
- buffer: Buffer.from("fake image data"),
32
- };
33
-
34
- test("throws FileTooLargeError if file exceeds maxFileSize limit", async () => {
35
- const options = { maxFileSize: 500 }; // Limit is 500 bytes
36
- expect(adapter.upload(mockFile, options)).rejects.toBeInstanceOf(FileTooLargeError);
37
- });
38
-
39
- test("throws Invalidmime_typeError if mime type is not allowed", async () => {
40
- const options = { allowedmime_types: ["image/png"] }; // Only allow PNG
41
- expect(adapter.upload(mockFile, options)).rejects.toBeInstanceOf(Invalidmime_typeError);
42
- });
43
-
44
- test("generates a unique filename if generateUniqueName is true", async () => {
45
- const options = { generateUniqueName: true };
46
- const result = await adapter.upload(mockFile, options);
47
-
48
- expect(result.filename).not.toBe("test.jpg");
49
- expect(result.filename).toMatch(/^test-[a-z0-9-]+\.jpg$/);
50
- });
51
-
52
- test("applies the prefix correctly to the generated URL", async () => {
53
- const prefixedAdapter = createS3Adapter({ ...config, prefix: "uploads/images" });
54
- const result = await prefixedAdapter.upload(mockFile);
55
-
56
- expect(result.url).toBe(
57
- "https://test-bucket.s3.us-east-1.amazonaws.com/uploads/images/test.jpg",
58
- );
59
- });
60
- });
@@ -1,100 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, it } from "bun:test";
2
- import { BunSQLiteAdapter } from "../src/db/bun-sqlite";
3
- import type { Collection } from "../src/types";
4
-
5
- describe("BunSQLiteAdapter Structural Data", () => {
6
- let db: BunSQLiteAdapter;
7
-
8
- const complexCollection: Collection = {
9
- slug: "complex_docs",
10
- fields: [
11
- { name: "title", type: "text" },
12
- {
13
- name: "seo",
14
- type: "group",
15
- fields: [
16
- { name: "title", type: "text" },
17
- { name: "desc", type: "text" },
18
- ],
19
- },
20
- {
21
- name: "contentBlocks",
22
- type: "blocks",
23
- blocks: [
24
- {
25
- slug: "hero",
26
- fields: [{ name: "headline", type: "text" }],
27
- },
28
- {
29
- slug: "text",
30
- fields: [{ name: "body", type: "text" }],
31
- },
32
- ],
33
- },
34
- ],
35
- };
36
-
37
- beforeAll(async () => {
38
- db = new BunSQLiteAdapter(":memory:", { push: true });
39
- await db.connect();
40
- await db.migrate([complexCollection]);
41
- });
42
-
43
- afterAll(async () => {
44
- await db.disconnect();
45
- });
46
-
47
- it("should create and retrieve a document with group fields and nested blocks properly", async () => {
48
- const data = {
49
- title: "Main Title",
50
- seo: { title: "SEO Title", desc: "SEO Desc" },
51
- contentBlocks: [
52
- { blockType: "hero", headline: "Welcome" },
53
- { blockType: "text", body: "Some body text" },
54
- ],
55
- };
56
-
57
- const created = await db.create("complex_docs", data);
58
-
59
- expect(created).toBeDefined();
60
- expect((created as any).title).toBe("Main Title");
61
- expect((created as any).seo).toEqual({ title: "SEO Title", desc: "SEO Desc" });
62
- expect((created as any).contentBlocks).toHaveLength(2);
63
- expect((created as any).contentBlocks[0].blockType).toBe("hero");
64
- expect((created as any).contentBlocks[0].headline).toBe("Welcome");
65
-
66
- const found = await db.findOne("complex_docs", { id: (created as any).id });
67
- expect((found as any).seo).toEqual({ title: "SEO Title", desc: "SEO Desc" });
68
- expect((found as any).contentBlocks).toHaveLength(2);
69
- });
70
-
71
- it("should update a document with group fields and nested blocks properly", async () => {
72
- const created = await db.create("complex_docs", {
73
- title: "Old Title",
74
- seo: { title: "Old SEO", desc: "Old Desc" },
75
- contentBlocks: [{ blockType: "text", body: "Old text" }],
76
- });
77
-
78
- const updated = await db.update(
79
- "complex_docs",
80
- { id: (created as any).id },
81
- {
82
- title: "New Title",
83
- seo: { title: "New SEO", desc: "New Desc" },
84
- contentBlocks: [
85
- { blockType: "hero", headline: "New Hero" },
86
- { blockType: "text", body: "New Text" },
87
- ],
88
- },
89
- );
90
-
91
- expect((updated as any).title).toBe("New Title");
92
- expect((updated as any).seo.title).toBe("New SEO");
93
- expect((updated as any).contentBlocks).toHaveLength(2);
94
- expect((updated as any).contentBlocks[0].blockType).toBe("hero");
95
-
96
- const found = await db.findOne("complex_docs", { id: (created as any).id });
97
- expect((found as any).seo).toEqual({ title: "New SEO", desc: "New Desc" });
98
- expect((found as any).contentBlocks).toHaveLength(2);
99
- });
100
- });
@@ -1,11 +0,0 @@
1
- import { mock } from "bun:test";
2
- import { GlobalRegistrator } from "@happy-dom/global-registrator";
3
-
4
- GlobalRegistrator.register();
5
-
6
- // Mock Cloudflare workers for tests so @hono-rate-limiter/cloudflare doesn't crash
7
- mock.module("cloudflare:workers", () => {
8
- return {
9
- DurableObject: class {},
10
- };
11
- });