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,146 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, it, spyOn } from "bun:test";
2
- import fs from "node:fs";
3
- import { resolve } from "node:path";
4
- import { initCommand } from "../src/cli/commands/init";
5
- import { migrateCreateCommand, migrateRunCommand, migrateStatusCommand } from "../src/cli/commands/migrate-commands";
6
- import { seedCommand } from "../src/cli/commands/seed-command";
7
- import { loadConfig } from "../src/cli/index";
8
-
9
- const TEST_DIR = resolve("packages/opacacms/test/integration-tmp");
10
-
11
- // Helper to capture console output
12
- function captureConsole() {
13
- const logs: string[] = [];
14
- const errors: string[] = [];
15
- const logSpy = spyOn(console, "log").mockImplementation((...args) => logs.push(args.join(" ")));
16
- const infoSpy = spyOn(console, "info").mockImplementation((...args) => logs.push(args.join(" ")));
17
- const errorSpy = spyOn(console, "error").mockImplementation((...args) => errors.push(args.join(" ")));
18
-
19
- return {
20
- get logs() { return logs.join("\n"); },
21
- get errors() { return errors.join("\n"); },
22
- restore: () => {
23
- logSpy.mockRestore();
24
- infoSpy.mockRestore();
25
- errorSpy.mockRestore();
26
- }
27
- };
28
- }
29
-
30
- describe("CLI Integration Tests (Direct Calls)", () => {
31
- beforeAll(() => {
32
- if (fs.existsSync(TEST_DIR)) fs.rmSync(TEST_DIR, { recursive: true, force: true });
33
- fs.mkdirSync(TEST_DIR, { recursive: true });
34
- // Change CWD to TEST_DIR for the duration of tests
35
- process.chdir(TEST_DIR);
36
- });
37
-
38
- afterAll(() => {
39
- // Restore CWD
40
- process.chdir(resolve("../../.."));
41
- });
42
-
43
- describe("init command", () => {
44
- it("should initialize a new project from boilerplate", async () => {
45
- const consoleC = captureConsole();
46
- try {
47
- await initCommand("my-test-app", "");
48
- expect(fs.existsSync(resolve("my-test-app", "opacacms.config.ts"))).toBe(true);
49
- expect(fs.existsSync(resolve("my-test-app", "package.json"))).toBe(true);
50
- } finally {
51
- consoleC.restore();
52
- }
53
- });
54
-
55
- it("should initialize a new project from an example", async () => {
56
- const consoleC = captureConsole();
57
- try {
58
- await initCommand("my-sqlite-app", "sqlite-basic");
59
- expect(fs.existsSync(resolve("my-sqlite-app", "opacacms.config.ts"))).toBe(true);
60
- const configContent = fs.readFileSync(resolve("my-sqlite-app", "opacacms.config.ts"), "utf-8");
61
- expect(configContent).toContain("Opaca Blog (SQLite)");
62
- } finally {
63
- consoleC.restore();
64
- }
65
- });
66
- });
67
-
68
- describe("database commands", () => {
69
- let opaca: any;
70
- const appDir = resolve(TEST_DIR, "db-app");
71
-
72
- beforeAll(async () => {
73
- await initCommand("db-app", "sqlite-basic");
74
- process.chdir(appDir);
75
-
76
- // FIX: Overwrite config for tests to use relative imports
77
- const testConfig = `
78
- import { defineConfig } from "../../../src/index";
79
- import { createBunSQLiteAdapter } from "../../../src/db/bun-sqlite";
80
- import { Field } from "../../../src/schema/index";
81
-
82
- export default defineConfig({
83
- appName: "Test App",
84
- db: createBunSQLiteAdapter(":memory:"), // Use memory for speed
85
- collections: [
86
- {
87
- slug: "posts",
88
- fields: [Field.text("title").required()]
89
- }
90
- ]
91
- });`;
92
- fs.writeFileSync("opacacms.config.ts", testConfig);
93
-
94
- // We need to load the config.
95
- opaca = await loadConfig(resolve("opacacms.config.ts"));
96
- });
97
-
98
- afterAll(() => {
99
- process.chdir(TEST_DIR);
100
- });
101
-
102
- it("should create a migration", async () => {
103
- const consoleC = captureConsole();
104
- try {
105
- await migrateCreateCommand(opaca, "initial", "");
106
- const migrationsDir = resolve("migrations");
107
- expect(fs.existsSync(migrationsDir)).toBe(true);
108
- const files = fs.readdirSync(migrationsDir);
109
- expect(files.some(f => f.endsWith("_initial.ts"))).toBe(true);
110
- } finally {
111
- consoleC.restore();
112
- }
113
- });
114
-
115
- it("should run migrations", async () => {
116
- const consoleC = captureConsole();
117
- try {
118
- await migrateRunCommand(opaca.db);
119
- expect(consoleC.logs).toContain("Migrations applied successfully");
120
- } finally {
121
- consoleC.restore();
122
- }
123
- });
124
-
125
- it("should show migration status", async () => {
126
- const consoleC = captureConsole();
127
- try {
128
- await migrateStatusCommand(opaca);
129
- expect(consoleC.logs).toContain("Checking migration status");
130
- expect(consoleC.logs).toContain("initial.ts");
131
- } finally {
132
- consoleC.restore();
133
- }
134
- });
135
-
136
- it("should seed the database", async () => {
137
- const consoleC = captureConsole();
138
- try {
139
- await seedCommand(opaca, 5, true, "collections");
140
- expect(consoleC.logs).toContain("Seeding completed successfully");
141
- } finally {
142
- consoleC.restore();
143
- }
144
- });
145
- });
146
- });
package/test/cli.test.ts DELETED
@@ -1,25 +0,0 @@
1
- import { describe, expect, it, mock, spyOn } from "bun:test";
2
- import { execSync } from "child_process";
3
- import fs from "fs";
4
- import { resolve } from "path";
5
-
6
- describe("CLI Tool", () => {
7
- it("should output usage if no command is provided", () => {
8
- try {
9
- execSync("bun ./src/cli/index.ts", { encoding: "utf-8", cwd: process.cwd() });
10
- } catch (e: any) {
11
- expect(e.stdout || e.stderr || e.message).toContain("Usage: opacacms <command> [options]");
12
- }
13
- });
14
-
15
- it("should fail if config is not found", () => {
16
- try {
17
- execSync("bun ./src/cli/index.ts migrate:create -c missing.ts", {
18
- encoding: "utf-8",
19
- cwd: process.cwd(),
20
- });
21
- } catch (e: any) {
22
- expect(e.stderr || e.stdout || e.message).toContain("Config file not found");
23
- }
24
- });
25
- });
@@ -1,95 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, it } from "bun:test";
2
- import { PostgresAdapter } from "../../src/db/postgres";
3
- import type { Collection } from "../../src/types";
4
-
5
- // These tests require a running Postgres instance (e.g. via docker compose up -d)
6
- // We skip if connection fails to avoid breaking CI environments without Docker
7
- describe("PostgresAdapter", () => {
8
- let db: PostgresAdapter;
9
- let isConnected = false;
10
- const testCollection: Collection = {
11
- slug: "test_posts",
12
- fields: [
13
- { name: "title", type: "text" },
14
- { name: "views", type: "number" },
15
- { name: "published", type: "boolean" },
16
- ],
17
- timestamps: true,
18
- };
19
-
20
- const config = {
21
- host: "localhost",
22
- port: 5433,
23
- database: "opacacms",
24
- username: "postgres",
25
- password: "postgres",
26
- };
27
-
28
- beforeAll(async () => {
29
- db = new PostgresAdapter(config, { push: true });
30
- try {
31
- await db.connect();
32
- // Try to run a simple query to see if it's really connected
33
- await (db as any).sql`SELECT 1`;
34
- await db.migrate([testCollection]);
35
- isConnected = true;
36
- } catch (e) {
37
- console.warn("Postgres connection failed, skipping tests.");
38
- }
39
- });
40
-
41
- afterAll(async () => {
42
- if (db && isConnected) {
43
- await db.disconnect();
44
- }
45
- });
46
-
47
- it("should create and retrieve a document", async () => {
48
- if (!isConnected) return;
49
- const data = { title: "Hello Postgres", views: 42, published: true };
50
- const created = await db.create("test_posts", data);
51
-
52
- expect(created).toBeDefined();
53
- expect((created as any).id).toBeDefined();
54
- expect((created as any).title).toBe("Hello Postgres");
55
-
56
- const found = await db.findOne("test_posts", { id: (created as any).id });
57
- expect(found).toMatchObject(data);
58
- });
59
-
60
- it("should update a document", async () => {
61
- if (!isConnected) return;
62
- const created = await db.create("test_posts", { title: "Old Title", views: 5 });
63
- const id = (created as any).id;
64
-
65
- const updated = await db.update("test_posts", { id }, { title: "New Title" });
66
- expect((updated as any).title).toBe("New Title");
67
-
68
- const found = await db.findOne("test_posts", { id });
69
- expect((found as any).title).toBe("New Title");
70
- expect((found as any).views).toBe(5);
71
- });
72
-
73
- it("should delete a document", async () => {
74
- if (!isConnected) return;
75
- const created = await db.create("test_posts", { title: "To Delete" });
76
- const id = (created as any).id;
77
-
78
- const success = await db.delete("test_posts", { id });
79
- expect(success).toBe(true);
80
-
81
- const found = await db.findOne("test_posts", { id });
82
- expect(found).toBeNull();
83
- });
84
-
85
- it("should find documents with query operators", async () => {
86
- if (!isConnected) return;
87
- await db.create("test_posts", { title: "Low", views: 10 });
88
- await db.create("test_posts", { title: "Medium", views: 50 });
89
- await db.create("test_posts", { title: "High", views: 100 });
90
-
91
- const result = await db.find("test_posts", { views: { gt: 40 } });
92
- expect(result.docs.length).toBeGreaterThanOrEqual(2);
93
- expect(result.totalDocs).toBeGreaterThanOrEqual(2);
94
- });
95
- });
@@ -1,53 +0,0 @@
1
- import { afterAll, beforeAll, expect, test } from "bun:test";
2
- import { BunSQLiteAdapter } from "../../src/db/bun-sqlite";
3
- import type { Collection } from "../../src/types";
4
-
5
- const db = new BunSQLiteAdapter(":memory:", { push: true });
6
-
7
- beforeAll(async () => {
8
- await db.connect();
9
- await db.migrate([
10
- {
11
- slug: "test_users",
12
- fields: [
13
- { name: "name", type: "text" },
14
- { name: "age", type: "number" },
15
- ],
16
- },
17
- ]);
18
-
19
- await db.create("test_users", { name: "Alice", age: 25 });
20
- await db.create("test_users", { name: "Bob", age: 30 });
21
- await db.create("test_users", { name: "Charlie", age: 35 });
22
- });
23
-
24
- afterAll(async () => {
25
- await db.disconnect();
26
- });
27
-
28
- test("SQLite find - simple equality", async () => {
29
- const result = await db.find<{ name: string; age: number }>("test_users", { name: "Alice" });
30
- expect(result.docs.length).toBe(1);
31
- expect(result.docs[0]?.name).toBe("Alice");
32
- });
33
-
34
- test("SQLite find - advanced operators (gt)", async () => {
35
- const result = await db.find<{ name: string; age: number }>("test_users", { age: { gt: 28 } });
36
- expect(result.docs.length).toBe(2);
37
- });
38
-
39
- test("SQLite find - advanced operators (like)", async () => {
40
- const result = await db.find<{ name: string; age: number }>("test_users", {
41
- name: { like: "%li%" },
42
- });
43
- expect(result.docs.length).toBe(2); // Alice, Charlie
44
- });
45
-
46
- test("SQLite find - multiple conditions", async () => {
47
- const result = await db.find<{ name: string; age: number }>("test_users", {
48
- name: { like: "%li%" },
49
- age: { gt: 30 },
50
- });
51
- expect(result.docs.length).toBe(1);
52
- expect(result.docs[0]?.name).toBe("Charlie");
53
- });
@@ -1,82 +0,0 @@
1
- import { afterEach, beforeEach, 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", () => {
6
- let db: BunSQLiteAdapter;
7
- const testCollection: Collection = {
8
- slug: "posts",
9
- fields: [
10
- { name: "title", type: "text" },
11
- { name: "views", type: "number" },
12
- { name: "published", type: "boolean" },
13
- ],
14
- timestamps: true,
15
- };
16
-
17
- beforeEach(async () => {
18
- db = new BunSQLiteAdapter(":memory:", { push: true });
19
- await db.migrate([testCollection]);
20
- });
21
-
22
- afterEach(async () => {
23
- await db.disconnect();
24
- });
25
-
26
- interface TestPost {
27
- id: number;
28
- title: string;
29
- views?: number;
30
- published?: boolean;
31
- }
32
-
33
- it("should create and retrieve a document", async () => {
34
- const data = { title: "Hello World", views: 10, published: true };
35
- const created = (await db.create("posts", data)) as unknown as TestPost;
36
-
37
- expect(created).toBeDefined();
38
- expect(created.id).toBeDefined();
39
- expect(created.title).toBe("Hello World");
40
-
41
- const found = await db.findOne("posts", { id: created.id });
42
- expect(found).toEqual(created as unknown as typeof found);
43
- });
44
-
45
- it("should update a document", async () => {
46
- const created = (await db.create("posts", {
47
- title: "Old Title",
48
- views: 5,
49
- })) as unknown as TestPost;
50
-
51
- const updated = (await db.update(
52
- "posts",
53
- { id: created.id },
54
- { title: "New Title" },
55
- )) as unknown as TestPost;
56
- expect(updated.title).toBe("New Title");
57
-
58
- const found = (await db.findOne("posts", { id: created.id })) as unknown as TestPost;
59
- expect(found?.title).toBe("New Title");
60
- expect(found?.views).toBe(5);
61
- });
62
-
63
- it("should delete a document", async () => {
64
- const created = (await db.create("posts", { title: "To Delete" })) as unknown as TestPost;
65
-
66
- const success = await db.delete("posts", { id: created.id });
67
- expect(success).toBe(true);
68
-
69
- const found = await db.findOne("posts", { id: created.id });
70
- expect(found).toBeNull();
71
- });
72
-
73
- it("should find documents with query", async () => {
74
- await db.create("posts", { title: "Post 1", published: true });
75
- await db.create("posts", { title: "Post 2", published: false });
76
- await db.create("posts", { title: "Post 3", published: true });
77
-
78
- const result = await db.find("posts", { published: 1 }); // SQLite boolean is 0/1
79
- expect(result.docs).toHaveLength(2);
80
- expect(result.totalDocs).toBe(2);
81
- });
82
- });
@@ -1,79 +0,0 @@
1
- import { describe, expect, mock, test } from "bun:test";
2
- import { Collection, Field } from "../src/schema";
3
- import { hydrateDoc } from "../src/server/handlers";
4
-
5
- describe("Engine Features Runtime", () => {
6
- test("hydrateDoc should correctly filter localized fields based on locale query", async () => {
7
- const fields = [Field.text("title").localized().build(), Field.text("description").build()];
8
-
9
- const doc = {
10
- title: { en: "Hello", pt: "Olá" },
11
- description: "Non-localized",
12
- };
13
-
14
- const mockContext = {
15
- req: {
16
- query: (key: string) => (key === "locale" ? "pt" : null),
17
- header: () => null,
18
- },
19
- get: () => null,
20
- } as any;
21
-
22
- const mockConfig = {
23
- i18n: { defaultLocale: "en" },
24
- } as any;
25
-
26
- const result = await (hydrateDoc as any)(doc, fields, mockContext, mockConfig);
27
-
28
- expect(result.title).toBe("Olá");
29
- expect(result.description).toBe("Non-localized");
30
- });
31
-
32
- test("hydrateDoc should fallback to default locale if requested locale is missing", async () => {
33
- const fields = [Field.text("title").localized().build()];
34
-
35
- const doc = {
36
- title: { en: "Hello", pt: "Olá" },
37
- };
38
-
39
- const mockContext = {
40
- req: {
41
- query: () => "fr", // French missing
42
- header: () => null,
43
- },
44
- get: () => null,
45
- } as any;
46
-
47
- const mockConfig = {
48
- i18n: { defaultLocale: "en" },
49
- } as any;
50
-
51
- const result = await (hydrateDoc as any)(doc, fields, mockContext, mockConfig);
52
-
53
- expect(result.title).toBe("Hello");
54
- });
55
-
56
- test("hydrateDoc should return all locales if locale=all is passed", async () => {
57
- const fields = [Field.text("title").localized().build()];
58
-
59
- const doc = {
60
- title: { en: "Hello", pt: "Olá" },
61
- };
62
-
63
- const mockContext = {
64
- req: {
65
- query: () => "all",
66
- header: () => null,
67
- },
68
- get: () => null,
69
- } as any;
70
-
71
- const mockConfig = {
72
- i18n: { defaultLocale: "en" },
73
- } as any;
74
-
75
- const result = await (hydrateDoc as any)(doc, fields, mockContext, mockConfig);
76
-
77
- expect(result.title).toEqual({ en: "Hello", pt: "Olá" });
78
- });
79
- });
@@ -1,74 +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
- globals: [
16
- {
17
- slug: "settings",
18
- fields: [
19
- { name: "siteName", type: "text", required: true },
20
- { name: "maintenanceMode", type: "boolean", defaultValue: false },
21
- ],
22
- },
23
- ],
24
- });
25
-
26
- app = new Hono();
27
- // Don't nest inside /api again, createAPIRouter already handles /api
28
- app.route("/", createAPIRouter(config));
29
-
30
- // ensure tables are created
31
- await db.connect();
32
- await db.migrate(config.collections, config.globals);
33
- });
34
-
35
- afterAll(async () => {
36
- await db.disconnect();
37
- });
38
-
39
- test("GET /api/globals/settings should return 404 initially (or empty JSON if null)", async () => {
40
- const res = await app.request("/api/globals/settings");
41
- expect(res.status).toBe(404);
42
- });
43
-
44
- test("POST /api/globals/settings should create the global", async () => {
45
- const res = await app.request("/api/globals/settings", {
46
- method: "POST",
47
- headers: { "Content-Type": "application/json" },
48
- body: JSON.stringify({ siteName: "My Website" }),
49
- });
50
- expect(res.status).toBe(200);
51
- const data = (await res.json()) as any;
52
- expect(data.siteName).toBe("My Website");
53
- // SQLite might return 0, better to just check falsy or explicitly
54
- expect(!!data.maintenanceMode).toBe(false);
55
- });
56
-
57
- test("PATCH /api/globals/settings should update the global", async () => {
58
- const res = await app.request("/api/globals/settings", {
59
- method: "PATCH",
60
- headers: { "Content-Type": "application/json" },
61
- body: JSON.stringify({ maintenanceMode: true }),
62
- });
63
- expect(res.status).toBe(200);
64
- const data = (await res.json()) as any;
65
- expect(data.siteName).toBe("My Website"); // Unchanged
66
- expect(!!data.maintenanceMode).toBe(true);
67
- });
68
-
69
- test("GET /api/globals/settings should return the global", async () => {
70
- const res = await app.request("/api/globals/settings");
71
- expect(res.status).toBe(200);
72
- const data = (await res.json()) as any;
73
- expect(data.siteName).toBe("My Website");
74
- });
@@ -1,15 +0,0 @@
1
-
2
- import { defineConfig } from "../../../src/index";
3
- import { createBunSQLiteAdapter } from "../../../src/db/bun-sqlite";
4
- import { Field } from "../../../src/schema/index";
5
-
6
- export default defineConfig({
7
- appName: "Test App",
8
- db: createBunSQLiteAdapter(":memory:"), // Use memory for speed
9
- collections: [
10
- {
11
- slug: "posts",
12
- fields: [Field.text("title").required()]
13
- }
14
- ]
15
- });
@@ -1,25 +0,0 @@
1
- import { defineConfig } from "opacacms";
2
- import { createSQLiteAdapter } from 'opacacms/db/sqlite';
3
- import { Field } from 'opacacms/schema';
4
-
5
- export default defineConfig({
6
- appName: 'Opaca Blog (SQLite)',
7
- db: createSQLiteAdapter('blog.db'),
8
- collections: [
9
- {
10
- slug: 'posts',
11
- fields: [
12
- Field.text('title').required(),
13
- Field.textarea('content'),
14
- Field.relationship('author').to('users'),
15
- ],
16
- },
17
- {
18
- slug: 'users',
19
- fields: [
20
- Field.text('name').required(),
21
- Field.text('email').required(),
22
- ],
23
- },
24
- ],
25
- });
@@ -1,8 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { createAPIRouter } from 'opacacms/server';
3
- import config from './opacacms.config';
4
-
5
- const app = new Hono();
6
- app.route('/api', createAPIRouter(config));
7
-
8
- export default app;
@@ -1,16 +0,0 @@
1
- import { defineConfig } from 'opacacms';
2
- import { createSQLiteAdapter } from 'opacacms/db/sqlite';
3
-
4
- export default defineConfig({
5
- appName: "My OpacaCMS App",
6
- db: createSQLiteAdapter('local.db'),
7
- collections: [
8
- {
9
- slug: 'posts',
10
- fields: [
11
- { name: 'title', type: 'text', required: true },
12
- { name: 'content', type: 'text' }
13
- ]
14
- }
15
- ]
16
- });
@@ -1,12 +0,0 @@
1
- {
2
- "name": "my-test-app",
3
- "type": "module",
4
- "scripts": {
5
- "start": "bun run index.ts",
6
- "dev": "bun run --watch index.ts"
7
- },
8
- "dependencies": {
9
- "opacacms": "latest",
10
- "hono": "^4.0.0"
11
- }
12
- }