bunsane 0.1.4 → 0.2.0

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 (257) hide show
  1. package/.claude/settings.local.json +47 -0
  2. package/.claude/skills/update-memory.md +74 -0
  3. package/.prettierrc +4 -0
  4. package/.serena/memories/architectural-decision-no-dependency-injection.md +76 -0
  5. package/.serena/memories/architecture.md +154 -0
  6. package/.serena/memories/cache-interface-refactoring-2026-01-24.md +165 -0
  7. package/.serena/memories/code_style_and_conventions.md +76 -0
  8. package/.serena/memories/project_overview.md +43 -0
  9. package/.serena/memories/schema-dsl-plan.md +107 -0
  10. package/.serena/memories/suggested_commands.md +80 -0
  11. package/.serena/memories/typescript-compilation-status.md +54 -0
  12. package/.serena/project.yml +114 -0
  13. package/TODO.md +1 -7
  14. package/bun.lock +150 -4
  15. package/bunfig.toml +10 -0
  16. package/config/cache.config.ts +77 -0
  17. package/config/upload.config.ts +4 -5
  18. package/core/App.ts +870 -123
  19. package/core/ArcheType.ts +2268 -377
  20. package/core/BatchLoader.ts +181 -71
  21. package/core/Config.ts +153 -0
  22. package/core/Decorators.ts +4 -1
  23. package/core/Entity.ts +621 -92
  24. package/core/EntityHookManager.ts +1 -1
  25. package/core/EntityInterface.ts +3 -1
  26. package/core/EntityManager.ts +1 -13
  27. package/core/ErrorHandler.ts +8 -2
  28. package/core/Logger.ts +9 -0
  29. package/core/Middleware.ts +34 -0
  30. package/core/RequestContext.ts +5 -1
  31. package/core/RequestLoaders.ts +227 -93
  32. package/core/SchedulerManager.ts +193 -52
  33. package/core/cache/CacheAnalytics.ts +399 -0
  34. package/core/cache/CacheFactory.ts +145 -0
  35. package/core/cache/CacheManager.ts +520 -0
  36. package/core/cache/CacheProvider.ts +34 -0
  37. package/core/cache/CacheWarmer.ts +157 -0
  38. package/core/cache/CompressionUtils.ts +110 -0
  39. package/core/cache/MemoryCache.ts +251 -0
  40. package/core/cache/MultiLevelCache.ts +180 -0
  41. package/core/cache/NoOpCache.ts +53 -0
  42. package/core/cache/RedisCache.ts +464 -0
  43. package/core/cache/TTLStrategy.ts +254 -0
  44. package/core/cache/index.ts +6 -0
  45. package/core/components/BaseComponent.ts +120 -0
  46. package/core/{ComponentRegistry.ts → components/ComponentRegistry.ts} +148 -54
  47. package/core/components/Decorators.ts +88 -0
  48. package/core/components/Interfaces.ts +7 -0
  49. package/core/components/index.ts +5 -0
  50. package/core/decorators/EntityHooks.ts +0 -3
  51. package/core/decorators/IndexedField.ts +26 -0
  52. package/core/decorators/ScheduledTask.ts +0 -47
  53. package/core/events/EntityLifecycleEvents.ts +1 -1
  54. package/core/health.ts +112 -0
  55. package/core/metadata/definitions/ArcheType.ts +14 -0
  56. package/core/metadata/definitions/Component.ts +9 -0
  57. package/core/metadata/definitions/gqlObject.ts +1 -1
  58. package/core/metadata/index.ts +42 -1
  59. package/core/metadata/metadata-storage.ts +28 -2
  60. package/core/middleware/AccessLog.ts +59 -0
  61. package/core/middleware/RequestId.ts +38 -0
  62. package/core/middleware/SecurityHeaders.ts +62 -0
  63. package/core/middleware/index.ts +3 -0
  64. package/core/scheduler/DistributedLock.ts +266 -0
  65. package/core/scheduler/index.ts +15 -0
  66. package/core/validateEnv.ts +92 -0
  67. package/database/DatabaseHelper.ts +416 -40
  68. package/database/IndexingStrategy.ts +342 -0
  69. package/database/PreparedStatementCache.ts +226 -0
  70. package/database/index.ts +32 -7
  71. package/database/sqlHelpers.ts +14 -2
  72. package/endpoints/archetypes.ts +362 -0
  73. package/endpoints/components.ts +58 -0
  74. package/endpoints/entity.ts +80 -0
  75. package/endpoints/index.ts +27 -0
  76. package/endpoints/query.ts +93 -0
  77. package/endpoints/stats.ts +76 -0
  78. package/endpoints/tables.ts +212 -0
  79. package/endpoints/types.ts +155 -0
  80. package/gql/ArchetypeOperations.ts +32 -86
  81. package/gql/Generator.ts +27 -315
  82. package/gql/GeneratorV2.ts +37 -0
  83. package/gql/builders/InputTypeBuilder.ts +99 -0
  84. package/gql/builders/ResolverBuilder.ts +234 -0
  85. package/gql/builders/TypeDefBuilder.ts +105 -0
  86. package/gql/builders/index.ts +3 -0
  87. package/gql/decorators/Upload.ts +1 -1
  88. package/gql/depthLimit.ts +85 -0
  89. package/gql/graph/GraphNode.ts +224 -0
  90. package/gql/graph/SchemaGraph.ts +278 -0
  91. package/gql/helpers.ts +8 -2
  92. package/gql/index.ts +56 -4
  93. package/gql/middleware.ts +79 -0
  94. package/gql/orchestration/GraphQLSchemaOrchestrator.ts +241 -0
  95. package/gql/orchestration/index.ts +1 -0
  96. package/gql/scanner/ServiceScanner.ts +347 -0
  97. package/gql/schema/index.ts +458 -0
  98. package/gql/strategies/TypeGenerationStrategy.ts +329 -0
  99. package/gql/types.ts +1 -0
  100. package/gql/utils/TypeSignature.ts +220 -0
  101. package/gql/utils/index.ts +1 -0
  102. package/gql/visitors/ArchetypePreprocessorVisitor.ts +80 -0
  103. package/gql/visitors/DeduplicationVisitor.ts +82 -0
  104. package/gql/visitors/GraphVisitor.ts +78 -0
  105. package/gql/visitors/ResolverGeneratorVisitor.ts +122 -0
  106. package/gql/visitors/SchemaGeneratorVisitor.ts +851 -0
  107. package/gql/visitors/TypeCollectorVisitor.ts +79 -0
  108. package/gql/visitors/VisitorComposer.ts +96 -0
  109. package/gql/visitors/index.ts +7 -0
  110. package/package.json +59 -37
  111. package/plugins/index.ts +2 -2
  112. package/query/CTENode.ts +97 -0
  113. package/query/ComponentInclusionNode.ts +689 -0
  114. package/query/FilterBuilder.ts +127 -0
  115. package/query/FilterBuilderRegistry.ts +202 -0
  116. package/query/OrNode.ts +517 -0
  117. package/query/OrQuery.ts +42 -0
  118. package/query/Query.ts +1022 -0
  119. package/query/QueryContext.ts +170 -0
  120. package/query/QueryDAG.ts +122 -0
  121. package/query/QueryNode.ts +65 -0
  122. package/query/SourceNode.ts +53 -0
  123. package/query/builders/FullTextSearchBuilder.ts +236 -0
  124. package/query/index.ts +21 -0
  125. package/scheduler/index.ts +40 -8
  126. package/service/Service.ts +2 -1
  127. package/service/ServiceRegistry.ts +6 -5
  128. package/{core/storage → storage}/LocalStorageProvider.ts +2 -2
  129. package/storage/S3StorageProvider.ts +316 -0
  130. package/{core/storage → storage}/StorageProvider.ts +7 -3
  131. package/studio/bun.lock +482 -0
  132. package/studio/index.html +13 -0
  133. package/studio/package.json +39 -0
  134. package/studio/postcss.config.js +6 -0
  135. package/studio/src/components/DataTable.tsx +211 -0
  136. package/studio/src/components/Layout.tsx +13 -0
  137. package/studio/src/components/PageContainer.tsx +9 -0
  138. package/studio/src/components/PageHeader.tsx +13 -0
  139. package/studio/src/components/SearchBar.tsx +57 -0
  140. package/studio/src/components/Sidebar.tsx +294 -0
  141. package/studio/src/components/ui/button.tsx +56 -0
  142. package/studio/src/components/ui/checkbox.tsx +26 -0
  143. package/studio/src/components/ui/input.tsx +25 -0
  144. package/studio/src/hooks/useDataTable.ts +131 -0
  145. package/studio/src/index.css +36 -0
  146. package/studio/src/lib/api.ts +186 -0
  147. package/studio/src/lib/utils.ts +13 -0
  148. package/studio/src/main.tsx +17 -0
  149. package/studio/src/pages/ArcheType.tsx +239 -0
  150. package/studio/src/pages/Components.tsx +124 -0
  151. package/studio/src/pages/EntityInspector.tsx +302 -0
  152. package/studio/src/pages/QueryRunner.tsx +246 -0
  153. package/studio/src/pages/Table.tsx +94 -0
  154. package/studio/src/pages/Welcome.tsx +241 -0
  155. package/studio/src/routes.tsx +45 -0
  156. package/studio/src/store/archeTypeSettings.ts +30 -0
  157. package/studio/src/store/studio.ts +65 -0
  158. package/studio/src/utils/columnHelpers.tsx +114 -0
  159. package/studio/studio-instructions.md +81 -0
  160. package/studio/tailwind.config.js +77 -0
  161. package/studio/tsconfig.json +24 -0
  162. package/studio/utils.ts +54 -0
  163. package/studio/vite.config.js +19 -0
  164. package/swagger/generator.ts +1 -1
  165. package/tests/e2e/http.test.ts +126 -0
  166. package/tests/fixtures/archetypes/TestUserArchetype.ts +21 -0
  167. package/tests/fixtures/components/TestOrder.ts +23 -0
  168. package/tests/fixtures/components/TestProduct.ts +23 -0
  169. package/tests/fixtures/components/TestUser.ts +20 -0
  170. package/tests/fixtures/components/index.ts +6 -0
  171. package/tests/graphql/SchemaGeneration.test.ts +90 -0
  172. package/tests/graphql/builders/ResolverBuilder.test.ts +223 -0
  173. package/tests/graphql/builders/TypeDefBuilder.test.ts +153 -0
  174. package/tests/integration/archetype/ArcheType.persistence.test.ts +241 -0
  175. package/tests/integration/cache/CacheInvalidation.test.ts +259 -0
  176. package/tests/integration/entity/Entity.persistence.test.ts +333 -0
  177. package/tests/integration/query/Query.exec.test.ts +523 -0
  178. package/tests/pglite-setup.ts +61 -0
  179. package/tests/setup.ts +164 -0
  180. package/tests/stress/BenchmarkRunner.ts +203 -0
  181. package/tests/stress/DataSeeder.ts +190 -0
  182. package/tests/stress/StressTestReporter.ts +229 -0
  183. package/tests/stress/cursor-perf-test.ts +171 -0
  184. package/tests/stress/fixtures/StressTestComponents.ts +58 -0
  185. package/tests/stress/index.ts +7 -0
  186. package/tests/stress/scenarios/query-benchmarks.test.ts +285 -0
  187. package/tests/unit/BatchLoader.test.ts +82 -0
  188. package/tests/unit/archetype/ArcheType.test.ts +107 -0
  189. package/tests/unit/cache/CacheManager.test.ts +347 -0
  190. package/tests/unit/cache/MemoryCache.test.ts +260 -0
  191. package/tests/unit/cache/RedisCache.test.ts +411 -0
  192. package/tests/unit/entity/Entity.components.test.ts +244 -0
  193. package/tests/unit/entity/Entity.test.ts +345 -0
  194. package/tests/unit/gql/depthLimit.test.ts +203 -0
  195. package/tests/unit/gql/operationMiddleware.test.ts +293 -0
  196. package/tests/unit/health/Health.test.ts +129 -0
  197. package/tests/unit/middleware/AccessLog.test.ts +37 -0
  198. package/tests/unit/middleware/Middleware.test.ts +98 -0
  199. package/tests/unit/middleware/RequestId.test.ts +54 -0
  200. package/tests/unit/middleware/SecurityHeaders.test.ts +66 -0
  201. package/tests/unit/query/FilterBuilder.test.ts +111 -0
  202. package/tests/unit/query/Query.test.ts +308 -0
  203. package/tests/unit/scheduler/DistributedLock.test.ts +274 -0
  204. package/tests/unit/schema/schema-integration.test.ts +426 -0
  205. package/tests/unit/schema/schema.test.ts +580 -0
  206. package/tests/unit/storage/S3StorageProvider.test.ts +571 -0
  207. package/tests/unit/upload/RestUpload.test.ts +267 -0
  208. package/tests/unit/validateEnv.test.ts +82 -0
  209. package/tests/utils/entity-tracker.ts +57 -0
  210. package/tests/utils/index.ts +13 -0
  211. package/tests/utils/test-context.ts +149 -0
  212. package/tsconfig.json +5 -1
  213. package/types/archetype.types.ts +6 -0
  214. package/types/hooks.types.ts +1 -1
  215. package/types/query.types.ts +110 -0
  216. package/types/scheduler.types.ts +68 -7
  217. package/types/upload.types.ts +1 -0
  218. package/{core → upload}/FileValidator.ts +10 -1
  219. package/upload/RestUpload.ts +130 -0
  220. package/{core/components → upload}/UploadComponent.ts +11 -11
  221. package/{core → upload}/UploadManager.ts +3 -3
  222. package/upload/index.ts +23 -7
  223. package/utils/UploadHelper.ts +27 -6
  224. package/utils/cronParser.ts +16 -6
  225. package/.github/workflows/deploy-docs.yml +0 -57
  226. package/core/Components.ts +0 -202
  227. package/core/EntityCache.ts +0 -15
  228. package/core/Query.ts +0 -880
  229. package/docs/README.md +0 -149
  230. package/docs/_coverpage.md +0 -36
  231. package/docs/_sidebar.md +0 -23
  232. package/docs/api/core.md +0 -568
  233. package/docs/api/hooks.md +0 -554
  234. package/docs/api/index.md +0 -222
  235. package/docs/api/query.md +0 -678
  236. package/docs/api/service.md +0 -744
  237. package/docs/core-concepts/archetypes.md +0 -512
  238. package/docs/core-concepts/components.md +0 -498
  239. package/docs/core-concepts/entity.md +0 -314
  240. package/docs/core-concepts/hooks.md +0 -683
  241. package/docs/core-concepts/query.md +0 -588
  242. package/docs/core-concepts/services.md +0 -647
  243. package/docs/examples/code-examples.md +0 -425
  244. package/docs/getting-started.md +0 -337
  245. package/docs/index.html +0 -97
  246. package/tests/bench/insert.bench.ts +0 -60
  247. package/tests/bench/relations.bench.ts +0 -270
  248. package/tests/bench/sorting.bench.ts +0 -416
  249. package/tests/component-hooks-simple.test.ts +0 -117
  250. package/tests/component-hooks.test.ts +0 -1461
  251. package/tests/component.test.ts +0 -339
  252. package/tests/errorHandling.test.ts +0 -155
  253. package/tests/hooks.test.ts +0 -667
  254. package/tests/query-sorting.test.ts +0 -101
  255. package/tests/query.test.ts +0 -81
  256. package/tests/relations.test.ts +0 -170
  257. package/tests/scheduler.test.ts +0 -724
@@ -0,0 +1,211 @@
1
+ import {
2
+ useReactTable,
3
+ getCoreRowModel,
4
+ getSortedRowModel,
5
+ type ColumnDef,
6
+ flexRender,
7
+ type SortingState,
8
+ } from '@tanstack/react-table'
9
+ import { Loader2 } from "lucide-react";
10
+ import { toast } from "sonner";
11
+
12
+ interface DataTableProps<T> {
13
+ data: T[];
14
+ columns: ColumnDef<T>[];
15
+ loading: boolean;
16
+ hasMore: boolean;
17
+ sorting: SortingState;
18
+ onSortingChange: (
19
+ updater: SortingState | ((old: SortingState) => SortingState)
20
+ ) => void;
21
+ selectedRecords: Set<string>;
22
+ onSelectionChange: (selected: Set<string>) => void;
23
+ getRecordId: (record: T) => string;
24
+ loadMoreRef: (node?: Element | null) => void;
25
+ emptyMessage?: string;
26
+ loadingMessage?: string;
27
+ getRowClassName?: (record: T) => string;
28
+ }
29
+
30
+ export function DataTable<T extends Record<string, any>>({
31
+ data,
32
+ columns,
33
+ loading,
34
+ hasMore,
35
+ sorting,
36
+ onSortingChange,
37
+ selectedRecords,
38
+ onSelectionChange,
39
+ getRecordId,
40
+ loadMoreRef,
41
+ emptyMessage = "No records found",
42
+ loadingMessage = "Loading more records...",
43
+ getRowClassName,
44
+ }: DataTableProps<T>) {
45
+ const table = useReactTable({
46
+ data,
47
+ columns,
48
+ getCoreRowModel: getCoreRowModel(),
49
+ getSortedRowModel: getSortedRowModel(),
50
+ onSortingChange,
51
+ state: {
52
+ sorting,
53
+ rowSelection: Object.fromEntries(
54
+ Array.from(selectedRecords).map((id) => [
55
+ data.findIndex((d) => getRecordId(d) === id),
56
+ true,
57
+ ])
58
+ ),
59
+ },
60
+ onRowSelectionChange: (updater) => {
61
+ const currentSelection = Object.fromEntries(
62
+ Array.from(selectedRecords).map((id) => [
63
+ data.findIndex((d) => getRecordId(d) === id),
64
+ true,
65
+ ])
66
+ );
67
+ const newSelection =
68
+ typeof updater === "function"
69
+ ? updater(currentSelection)
70
+ : updater;
71
+ const newSelectedRecords = new Set<string>();
72
+ Object.entries(newSelection).forEach(([index, selected]) => {
73
+ if (selected) {
74
+ const record = data[parseInt(index)];
75
+ if (record) {
76
+ newSelectedRecords.add(getRecordId(record));
77
+ }
78
+ }
79
+ });
80
+ onSelectionChange(newSelectedRecords);
81
+ },
82
+ });
83
+
84
+ const handleCellClick = (cell: any, event: React.MouseEvent) => {
85
+ // Skip copy for select column
86
+ if (cell.column.id === "select") return;
87
+
88
+ // Prevent event bubbling
89
+ event.stopPropagation();
90
+
91
+ const value = cell.getValue();
92
+ let textToCopy = "";
93
+
94
+ // Extract the actual value if it has a .value property
95
+ let actualValue = value;
96
+ if (typeof value === "object" && value !== null && "value" in value) {
97
+ actualValue = value.value;
98
+ }
99
+
100
+ // Only copy primitive values (not objects)
101
+ if (typeof actualValue === "object" && actualValue !== null) {
102
+ return; // Don't copy objects, let ReactJson handle it
103
+ } else {
104
+ textToCopy = String(actualValue ?? "");
105
+ }
106
+
107
+ if (textToCopy) {
108
+ navigator.clipboard
109
+ .writeText(textToCopy)
110
+ .then(() => {
111
+ toast.success("Copied to clipboard", {
112
+ position: "top-center",
113
+ });
114
+ })
115
+ .catch(() => {
116
+ toast.error("Failed to copy", { position: "top-center" });
117
+ });
118
+ }
119
+ };
120
+
121
+ return (
122
+ <div className="bg-card rounded-lg border border-border overflow-hidden">
123
+ <div className="overflow-x-auto">
124
+ <table className="w-full">
125
+ <thead className="bg-muted/50">
126
+ {table.getHeaderGroups().map((headerGroup) => (
127
+ <tr key={headerGroup.id}>
128
+ {headerGroup.headers.map((header) => (
129
+ <th
130
+ key={header.id}
131
+ className="px-4 py-3 text-left text-sm font-medium text-muted-foreground border-b border-border"
132
+ >
133
+ {header.isPlaceholder ? null : (
134
+ <div
135
+ className={
136
+ header.column.getCanSort()
137
+ ? "cursor-pointer select-none flex items-center gap-2"
138
+ : ""
139
+ }
140
+ onClick={header.column.getToggleSortingHandler()}
141
+ >
142
+ {flexRender(
143
+ header.column.columnDef
144
+ .header,
145
+ header.getContext()
146
+ )}
147
+ {{
148
+ asc: "↑",
149
+ desc: "↓",
150
+ }[
151
+ header.column.getIsSorted() as string
152
+ ] ?? null}
153
+ </div>
154
+ )}
155
+ </th>
156
+ ))}
157
+ </tr>
158
+ ))}
159
+ </thead>
160
+ <tbody>
161
+ {table.getRowModel().rows.map((row) => {
162
+ const extraClass = getRowClassName ? getRowClassName(row.original) : '';
163
+ return (
164
+ <tr
165
+ key={row.id}
166
+ className={`border-b border-border hover:bg-muted/50 ${extraClass}`}
167
+ >
168
+ {row.getVisibleCells().map((cell) => (
169
+ <td
170
+ key={cell.id}
171
+ className="px-4 py-3 text-sm cursor-pointer hover:bg-muted/30"
172
+ onClick={(e) =>
173
+ handleCellClick(cell, e)
174
+ }
175
+ >
176
+ {flexRender(
177
+ cell.column.columnDef.cell,
178
+ cell.getContext()
179
+ )}
180
+ </td>
181
+ ))}
182
+ </tr>
183
+ );
184
+ })}
185
+ </tbody>
186
+ </table>
187
+ </div>
188
+
189
+ {(loading || hasMore) && (
190
+ <div ref={loadMoreRef} className="p-4 text-center">
191
+ {loading ? (
192
+ <div className="flex items-center justify-center gap-2">
193
+ <Loader2 className="h-4 w-4 animate-spin" />
194
+ {loadingMessage}
195
+ </div>
196
+ ) : (
197
+ <div className="text-muted-foreground">
198
+ Scroll for more
199
+ </div>
200
+ )}
201
+ </div>
202
+ )}
203
+
204
+ {!loading && data.length === 0 && (
205
+ <div className="p-8 text-center text-muted-foreground">
206
+ {emptyMessage}
207
+ </div>
208
+ )}
209
+ </div>
210
+ );
211
+ }
@@ -0,0 +1,13 @@
1
+ import { Outlet } from 'react-router'
2
+ import { Sidebar } from './Sidebar'
3
+
4
+ export function Layout() {
5
+ return (
6
+ <div className="flex h-screen bg-background">
7
+ <Sidebar />
8
+ <main className="flex-1 overflow-auto">
9
+ <Outlet />
10
+ </main>
11
+ </div>
12
+ )
13
+ }
@@ -0,0 +1,9 @@
1
+ import { type ReactNode } from 'react'
2
+
3
+ interface PageContainerProps {
4
+ children: ReactNode
5
+ }
6
+
7
+ export function PageContainer({ children }: PageContainerProps) {
8
+ return <div className="p-8">{children}</div>
9
+ }
@@ -0,0 +1,13 @@
1
+ interface PageHeaderProps {
2
+ title: string
3
+ description: string
4
+ }
5
+
6
+ export function PageHeader({ title, description }: PageHeaderProps) {
7
+ return (
8
+ <div className="mb-6">
9
+ <h1 className="text-3xl font-bold text-primary mb-2">{title}</h1>
10
+ <p className="text-muted-foreground">{description}</p>
11
+ </div>
12
+ )
13
+ }
@@ -0,0 +1,57 @@
1
+ import { Search, Trash2 } from 'lucide-react'
2
+ import { Button } from './ui/button'
3
+ import { Input } from './ui/input'
4
+ import { pluralize } from '../lib/utils'
5
+
6
+ interface SearchBarProps {
7
+ search: string
8
+ onSearchChange: (value: string) => void
9
+ placeholder?: string
10
+ selectedCount?: number
11
+ onDelete?: () => void
12
+ itemSingular?: string
13
+ itemPlural?: string
14
+ }
15
+
16
+ export function SearchBar({
17
+ search,
18
+ onSearchChange,
19
+ placeholder = 'Search...',
20
+ selectedCount = 0,
21
+ onDelete,
22
+ itemSingular = 'record',
23
+ itemPlural = 'records',
24
+ }: SearchBarProps) {
25
+ return (
26
+ <div className="flex items-center gap-4 mb-6">
27
+ <div className="relative flex-1 max-w-sm">
28
+ <Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
29
+ <Input
30
+ placeholder={placeholder}
31
+ value={search}
32
+ onChange={(e) => onSearchChange(e.target.value)}
33
+ className="pl-10"
34
+ />
35
+ </div>
36
+
37
+ {onDelete && selectedCount > 0 && (
38
+ <Button
39
+ variant="destructive"
40
+ onClick={() => {
41
+ if (
42
+ window.confirm(
43
+ `Are you sure you want to delete ${selectedCount} ${pluralize(selectedCount, itemSingular, itemPlural)}? This action cannot be undone.`
44
+ )
45
+ ) {
46
+ onDelete()
47
+ }
48
+ }}
49
+ className="flex items-center gap-2"
50
+ >
51
+ <Trash2 className="h-4 w-4" />
52
+ Delete Selected ({selectedCount})
53
+ </Button>
54
+ )}
55
+ </div>
56
+ )
57
+ }
@@ -0,0 +1,294 @@
1
+ import { useEffect } from "react";
2
+ import { Link, useLocation } from "react-router-dom";
3
+ import {
4
+ Database,
5
+ Home,
6
+ ChevronDown,
7
+ ChevronRight,
8
+ PanelLeftOpenIcon,
9
+ PanelLeftCloseIcon,
10
+ FlameIcon,
11
+ Search,
12
+ Layers,
13
+ Terminal,
14
+ } from "lucide-react";
15
+ import { useStudioStore } from "../store/studio";
16
+ import { fetchTables } from "../lib/api";
17
+ import { cn } from "../lib/utils";
18
+ import { Button } from "./ui/button";
19
+
20
+ declare global {
21
+ interface Window {
22
+ bunsaneMetadata?: {
23
+ archeTypes: Record<
24
+ string,
25
+ {
26
+ fieldName: string;
27
+ componentName: string;
28
+ fieldLabel: string;
29
+ nullable?: boolean;
30
+ }[]
31
+ >;
32
+ };
33
+ }
34
+ }
35
+
36
+ type SidebarSection = {
37
+ id: string;
38
+ title: string;
39
+ icon: typeof Database;
40
+ items: string[];
41
+ getRoutePath: (item: string) => string;
42
+ };
43
+
44
+ export function Sidebar() {
45
+ const location = useLocation();
46
+ const {
47
+ metadata,
48
+ tables,
49
+ setMetadata,
50
+ setTables,
51
+ setLoading,
52
+ setError,
53
+ isSidebarCollapsed,
54
+ expandedSections,
55
+ setSidebarCollapsed,
56
+ toggleSection,
57
+ } = useStudioStore();
58
+
59
+ useEffect(() => {
60
+ // Load metadata from window
61
+ if (window.bunsaneMetadata) {
62
+ setMetadata(window.bunsaneMetadata);
63
+ }
64
+
65
+ // Load tables
66
+ const loadTables = async () => {
67
+ try {
68
+ setLoading(true);
69
+ const tablesData = await fetchTables();
70
+ setTables(tablesData);
71
+ } catch (error) {
72
+ setError(
73
+ error instanceof Error
74
+ ? error.message
75
+ : "Failed to load tables"
76
+ );
77
+ } finally {
78
+ setLoading(false);
79
+ }
80
+ };
81
+
82
+ loadTables();
83
+ }, [setMetadata, setTables, setLoading, setError]);
84
+
85
+ const archeTypeNames = metadata ? Object.keys(metadata.archeTypes) : [];
86
+
87
+ const sections: SidebarSection[] = [
88
+ {
89
+ id: "archeTypes",
90
+ title: "ArcheTypes",
91
+ icon: FlameIcon,
92
+ items: archeTypeNames,
93
+ getRoutePath: (archeTypeName) => `/archetype/${archeTypeName}`,
94
+ },
95
+ {
96
+ id: "tables",
97
+ title: "Tables",
98
+ icon: Database,
99
+ items: tables,
100
+ getRoutePath: (tableName) => `/table/${tableName}`,
101
+ },
102
+ ];
103
+
104
+ const handleToggleSection = (section: string) => {
105
+ if (isSidebarCollapsed) {
106
+ setSidebarCollapsed(false);
107
+ if (!expandedSections[section]) {
108
+ toggleSection(section);
109
+ }
110
+ return;
111
+ }
112
+
113
+ toggleSection(section);
114
+ };
115
+
116
+ const handleToggleSidebar = () => {
117
+ setSidebarCollapsed(!isSidebarCollapsed);
118
+ };
119
+
120
+ return (
121
+ <aside
122
+ className={cn(
123
+ "bg-card border-r border-border flex flex-col transition-all duration-300",
124
+ isSidebarCollapsed ? "w-16" : "w-80"
125
+ )}
126
+ >
127
+ <div
128
+ className={cn(
129
+ "p-6 border-b border-border flex items-center justify-between",
130
+ isSidebarCollapsed && "p-4"
131
+ )}
132
+ >
133
+ {!isSidebarCollapsed && (
134
+ <div>
135
+ <h1 className="text-2xl font-bold text-primary">
136
+ BunSane Studio
137
+ </h1>
138
+ <p className="text-sm text-muted-foreground mt-1">
139
+ Database Management
140
+ </p>
141
+ </div>
142
+ )}
143
+ <Button
144
+ variant="ghost"
145
+ size="icon"
146
+ onClick={handleToggleSidebar}
147
+ className={cn(
148
+ "text-muted-foreground hover:text-foreground",
149
+ isSidebarCollapsed && "mx-auto"
150
+ )}
151
+ >
152
+ {isSidebarCollapsed ? (
153
+ <PanelLeftOpenIcon className="h-5 w-5" />
154
+ ) : (
155
+ <PanelLeftCloseIcon className="h-5 w-5" />
156
+ )}
157
+ </Button>
158
+ </div>
159
+
160
+ <nav className="flex-1 overflow-auto p-4">
161
+ <div className="space-y-2">
162
+ {/* Welcome */}
163
+ <Link
164
+ to="/"
165
+ className={cn(
166
+ "flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-colors",
167
+ location.pathname === "/"
168
+ ? "bg-primary text-primary-foreground"
169
+ : "text-muted-foreground hover:bg-accent hover:text-accent-foreground",
170
+ isSidebarCollapsed && "justify-center px-0"
171
+ )}
172
+ title={isSidebarCollapsed ? "Welcome" : undefined}
173
+ >
174
+ <Home className="h-4 w-4" />
175
+ {!isSidebarCollapsed && "Welcome"}
176
+ </Link>
177
+
178
+ {/* Entity Inspector */}
179
+ <Link
180
+ to="/entity"
181
+ className={cn(
182
+ "flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-colors",
183
+ location.pathname.startsWith("/entity")
184
+ ? "bg-primary text-primary-foreground"
185
+ : "text-muted-foreground hover:bg-accent hover:text-accent-foreground",
186
+ isSidebarCollapsed && "justify-center px-0"
187
+ )}
188
+ title={isSidebarCollapsed ? "Entity Inspector" : undefined}
189
+ >
190
+ <Search className="h-4 w-4" />
191
+ {!isSidebarCollapsed && "Entity Inspector"}
192
+ </Link>
193
+
194
+ {/* Components */}
195
+ <Link
196
+ to="/components"
197
+ className={cn(
198
+ "flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-colors",
199
+ location.pathname === "/components"
200
+ ? "bg-primary text-primary-foreground"
201
+ : "text-muted-foreground hover:bg-accent hover:text-accent-foreground",
202
+ isSidebarCollapsed && "justify-center px-0"
203
+ )}
204
+ title={isSidebarCollapsed ? "Components" : undefined}
205
+ >
206
+ <Layers className="h-4 w-4" />
207
+ {!isSidebarCollapsed && "Components"}
208
+ </Link>
209
+
210
+ {/* Query Runner */}
211
+ <Link
212
+ to="/query"
213
+ className={cn(
214
+ "flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-colors",
215
+ location.pathname === "/query"
216
+ ? "bg-primary text-primary-foreground"
217
+ : "text-muted-foreground hover:bg-accent hover:text-accent-foreground",
218
+ isSidebarCollapsed && "justify-center px-0"
219
+ )}
220
+ title={isSidebarCollapsed ? "SQL Query" : undefined}
221
+ >
222
+ <Terminal className="h-4 w-4" />
223
+ {!isSidebarCollapsed && "SQL Query"}
224
+ </Link>
225
+
226
+ {/* Dynamic Sections */}
227
+ {sections.map((section) => {
228
+ const Icon = section.icon;
229
+ const isExpanded = expandedSections[section.id];
230
+
231
+ return (
232
+ <div key={section.id} className="space-y-1">
233
+ <button
234
+ onClick={() =>
235
+ handleToggleSection(section.id)
236
+ }
237
+ className={cn(
238
+ "w-full flex items-center gap-2 px-3 py-2 text-sm font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground rounded-md transition-colors",
239
+ isSidebarCollapsed &&
240
+ "justify-center px-0"
241
+ )}
242
+ title={
243
+ isSidebarCollapsed
244
+ ? `${section.title} (${section.items.length})`
245
+ : undefined
246
+ }
247
+ >
248
+ <Icon className="h-4 w-4" />
249
+ {!isSidebarCollapsed && (
250
+ <>
251
+ <span className="flex-1 text-left">
252
+ {section.title} (
253
+ {section.items.length})
254
+ </span>
255
+ {isExpanded ? (
256
+ <ChevronDown className="h-4 w-4" />
257
+ ) : (
258
+ <ChevronRight className="h-4 w-4" />
259
+ )}
260
+ </>
261
+ )}
262
+ </button>
263
+ {!isSidebarCollapsed && isExpanded && (
264
+ <div className="ml-4 space-y-1">
265
+ {section.items.map((item) => {
266
+ const routePath =
267
+ section.getRoutePath(item);
268
+
269
+ return (
270
+ <Link
271
+ key={item}
272
+ to={routePath}
273
+ className={cn(
274
+ "block px-3 py-2 rounded-md text-sm transition-colors",
275
+ location.pathname ===
276
+ routePath
277
+ ? "bg-primary text-primary-foreground"
278
+ : "text-muted-foreground hover:bg-accent hover:text-accent-foreground"
279
+ )}
280
+ >
281
+ {item}
282
+ </Link>
283
+ );
284
+ })}
285
+ </div>
286
+ )}
287
+ </div>
288
+ );
289
+ })}
290
+ </div>
291
+ </nav>
292
+ </aside>
293
+ );
294
+ }
@@ -0,0 +1,56 @@
1
+ import * as React from "react"
2
+ import { Slot } from "@radix-ui/react-slot"
3
+ import { cva, type VariantProps } from "class-variance-authority"
4
+
5
+ import { cn } from "../../lib/utils"
6
+
7
+ const buttonVariants = cva(
8
+ "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
13
+ destructive:
14
+ "bg-destructive text-destructive-foreground hover:bg-destructive/90",
15
+ outline:
16
+ "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
17
+ secondary:
18
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80",
19
+ ghost: "hover:bg-accent hover:text-accent-foreground",
20
+ link: "text-primary underline-offset-4 hover:underline",
21
+ },
22
+ size: {
23
+ default: "h-10 px-4 py-2",
24
+ sm: "h-9 rounded-md px-3",
25
+ lg: "h-11 rounded-md px-8",
26
+ icon: "h-10 w-10",
27
+ },
28
+ },
29
+ defaultVariants: {
30
+ variant: "default",
31
+ size: "default",
32
+ },
33
+ }
34
+ )
35
+
36
+ export interface ButtonProps
37
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
38
+ VariantProps<typeof buttonVariants> {
39
+ asChild?: boolean
40
+ }
41
+
42
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
43
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
44
+ const Comp = asChild ? Slot : "button"
45
+ return (
46
+ <Comp
47
+ className={cn(buttonVariants({ variant, size, className }))}
48
+ ref={ref}
49
+ {...props}
50
+ />
51
+ )
52
+ }
53
+ )
54
+ Button.displayName = "Button"
55
+
56
+ export { Button, buttonVariants }
@@ -0,0 +1,26 @@
1
+ import { type InputHTMLAttributes } from 'react'
2
+
3
+ interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
4
+ label?: string
5
+ }
6
+
7
+ export function Checkbox({ label, id, className = '', ...props }: CheckboxProps) {
8
+ return (
9
+ <div className="flex items-center gap-2">
10
+ <input
11
+ type="checkbox"
12
+ id={id}
13
+ className={`h-4 w-4 rounded border-border text-primary focus:ring-2 focus:ring-primary focus:ring-offset-2 cursor-pointer ${className}`}
14
+ {...props}
15
+ />
16
+ {label && (
17
+ <label
18
+ htmlFor={id}
19
+ className="text-sm font-medium text-foreground cursor-pointer select-none"
20
+ >
21
+ {label}
22
+ </label>
23
+ )}
24
+ </div>
25
+ )
26
+ }