bunsane 0.3.1 → 0.4.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 (224) hide show
  1. package/CHANGELOG.md +445 -318
  2. package/config/cache.config.ts +35 -1
  3. package/core/App.ts +24 -1064
  4. package/core/ArcheType.ts +78 -2110
  5. package/core/BatchLoader.ts +56 -32
  6. package/core/Entity.ts +85 -1043
  7. package/core/EntityHookManager.ts +52 -754
  8. package/core/Logger.ts +10 -0
  9. package/core/RequestContext.ts +64 -6
  10. package/core/RequestLoaders.ts +187 -36
  11. package/core/SchedulerManager.ts +28 -600
  12. package/core/app/bootstrap.ts +133 -0
  13. package/core/app/cors.ts +85 -0
  14. package/core/app/graphqlSetup.ts +56 -0
  15. package/core/app/healthEndpoints.ts +31 -0
  16. package/core/app/metricsCollector.ts +27 -0
  17. package/core/app/preparedStatementWarmup.ts +15 -0
  18. package/core/app/processHandlers.ts +43 -0
  19. package/core/app/requestRouter.ts +310 -0
  20. package/core/app/restRegistry.ts +80 -0
  21. package/core/app/shutdown.ts +97 -0
  22. package/core/app/studioRouter.ts +83 -0
  23. package/core/archetype/customTypes.ts +100 -0
  24. package/core/archetype/decorators.ts +171 -0
  25. package/core/archetype/fieldResolvers.ts +666 -0
  26. package/core/archetype/helpers.ts +29 -0
  27. package/core/archetype/relationLoader.ts +161 -0
  28. package/core/archetype/schemaBuilder.ts +141 -0
  29. package/core/archetype/weaver.ts +218 -0
  30. package/core/archetype/zodSchemaBuilder.ts +527 -0
  31. package/core/cache/CacheManager.ts +173 -267
  32. package/core/cache/CompressionUtils.ts +34 -3
  33. package/core/cache/MemoryCache.ts +40 -37
  34. package/core/cache/RedisCache.ts +4 -4
  35. package/core/cache/health.ts +30 -0
  36. package/core/cache/invalidation.ts +96 -0
  37. package/core/cache/strategies/writeInvalidate.ts +111 -0
  38. package/core/cache/strategies/writeThrough.ts +233 -0
  39. package/core/components/BaseComponent.ts +16 -8
  40. package/core/components/ComponentRegistry.ts +28 -0
  41. package/core/decorators/IndexedField.ts +1 -1
  42. package/core/entity/cacheStrategies.ts +97 -0
  43. package/core/entity/componentAccess.ts +364 -0
  44. package/core/entity/finders.ts +202 -0
  45. package/core/entity/pendingOps.ts +72 -0
  46. package/core/entity/saveEntity.ts +377 -0
  47. package/core/hooks/dispatcher.ts +439 -0
  48. package/core/hooks/guards.ts +155 -0
  49. package/core/hooks/registry.ts +247 -0
  50. package/core/metadata/definitions/Component.ts +1 -1
  51. package/core/metadata/index.ts +15 -4
  52. package/core/middleware/AccessLog.ts +8 -1
  53. package/core/middleware/RateLimit.ts +102 -105
  54. package/core/middleware/RequestId.ts +2 -9
  55. package/core/middleware/SecurityHeaders.ts +2 -11
  56. package/core/middleware/headers.ts +28 -0
  57. package/core/remote/OutboxWorker.ts +213 -183
  58. package/core/remote/RemoteManager.ts +401 -400
  59. package/core/remote/types.ts +153 -151
  60. package/core/requestScope.ts +34 -0
  61. package/core/scheduler/cronEvaluator.ts +174 -0
  62. package/core/scheduler/lifecycleHooks.ts +21 -0
  63. package/core/scheduler/lockCoordinator.ts +27 -0
  64. package/core/scheduler/metrics.ts +14 -0
  65. package/core/scheduler/taskRunner.ts +420 -0
  66. package/database/DatabaseHelper.ts +128 -101
  67. package/database/IndexingStrategy.ts +72 -2
  68. package/database/PreparedStatementCache.ts +20 -5
  69. package/database/cancellable.ts +35 -0
  70. package/database/index.ts +15 -3
  71. package/database/instrumentedDb.ts +141 -0
  72. package/endpoints/archetypes.ts +2 -8
  73. package/endpoints/tables.ts +6 -1
  74. package/gql/index.ts +1 -1
  75. package/gql/visitors/ResolverGeneratorVisitor.ts +25 -4
  76. package/package.json +22 -1
  77. package/query/CTENode.ts +5 -3
  78. package/query/ComponentInclusionNode.ts +240 -13
  79. package/query/OrNode.ts +6 -5
  80. package/query/Query.ts +203 -59
  81. package/query/QueryContext.ts +6 -0
  82. package/query/QueryDAG.ts +7 -2
  83. package/query/membershipSource.ts +66 -0
  84. package/storage/LocalStorageProvider.ts +8 -3
  85. package/studio/dist/assets/index-BMZ67Npg.js +254 -0
  86. package/studio/dist/assets/index-BpbuYz9g.css +1 -0
  87. package/studio/{index.html → dist/index.html} +3 -2
  88. package/swagger/generator.ts +11 -1
  89. package/upload/UploadManager.ts +8 -6
  90. package/utils/uuid.ts +40 -10
  91. package/.claude/settings.local.json +0 -47
  92. package/.prettierrc +0 -4
  93. package/.serena/memories/architectural-decision-no-dependency-injection.md +0 -76
  94. package/.serena/memories/architecture.md +0 -154
  95. package/.serena/memories/cache-interface-refactoring-2026-01-24.md +0 -165
  96. package/.serena/memories/code_style_and_conventions.md +0 -76
  97. package/.serena/memories/project_overview.md +0 -43
  98. package/.serena/memories/schema-dsl-plan.md +0 -107
  99. package/.serena/memories/suggested_commands.md +0 -80
  100. package/.serena/memories/typescript-compilation-status.md +0 -54
  101. package/.serena/project.yml +0 -114
  102. package/BunSane.jpg +0 -0
  103. package/CLAUDE.md +0 -198
  104. package/TODO.md +0 -2
  105. package/bun.lock +0 -302
  106. package/bunfig.toml +0 -10
  107. package/docs/SCALABILITY_PLAN.md +0 -175
  108. package/studio/bun.lock +0 -482
  109. package/studio/package.json +0 -39
  110. package/studio/postcss.config.js +0 -6
  111. package/studio/src/components/DataTable.tsx +0 -211
  112. package/studio/src/components/Layout.tsx +0 -13
  113. package/studio/src/components/PageContainer.tsx +0 -9
  114. package/studio/src/components/PageHeader.tsx +0 -13
  115. package/studio/src/components/SearchBar.tsx +0 -57
  116. package/studio/src/components/Sidebar.tsx +0 -294
  117. package/studio/src/components/ui/button.tsx +0 -56
  118. package/studio/src/components/ui/checkbox.tsx +0 -26
  119. package/studio/src/components/ui/input.tsx +0 -25
  120. package/studio/src/hooks/useDataTable.ts +0 -131
  121. package/studio/src/index.css +0 -36
  122. package/studio/src/lib/api.ts +0 -186
  123. package/studio/src/lib/utils.ts +0 -13
  124. package/studio/src/main.tsx +0 -17
  125. package/studio/src/pages/ArcheType.tsx +0 -239
  126. package/studio/src/pages/Components.tsx +0 -124
  127. package/studio/src/pages/EntityInspector.tsx +0 -302
  128. package/studio/src/pages/QueryRunner.tsx +0 -246
  129. package/studio/src/pages/Table.tsx +0 -94
  130. package/studio/src/pages/Welcome.tsx +0 -241
  131. package/studio/src/routes.tsx +0 -45
  132. package/studio/src/store/archeTypeSettings.ts +0 -30
  133. package/studio/src/store/studio.ts +0 -65
  134. package/studio/src/utils/columnHelpers.tsx +0 -114
  135. package/studio/studio-instructions.md +0 -81
  136. package/studio/tailwind.config.js +0 -77
  137. package/studio/utils.ts +0 -54
  138. package/studio/vite.config.js +0 -19
  139. package/tests/benchmark/BENCHMARK_DATABASES_PLAN.md +0 -338
  140. package/tests/benchmark/bunfig.toml +0 -9
  141. package/tests/benchmark/fixtures/EcommerceComponents.ts +0 -283
  142. package/tests/benchmark/fixtures/EcommerceDataGenerators.ts +0 -301
  143. package/tests/benchmark/fixtures/RelationTracker.ts +0 -159
  144. package/tests/benchmark/fixtures/index.ts +0 -6
  145. package/tests/benchmark/index.ts +0 -22
  146. package/tests/benchmark/noop-preload.ts +0 -3
  147. package/tests/benchmark/query-lateral-benchmark.test.ts +0 -372
  148. package/tests/benchmark/runners/BenchmarkLoader.ts +0 -132
  149. package/tests/benchmark/runners/index.ts +0 -4
  150. package/tests/benchmark/scenarios/query-benchmarks.test.ts +0 -465
  151. package/tests/benchmark/scripts/generate-db.ts +0 -344
  152. package/tests/benchmark/scripts/run-benchmarks.ts +0 -97
  153. package/tests/e2e/http.test.ts +0 -130
  154. package/tests/fixtures/archetypes/TestUserArchetype.ts +0 -21
  155. package/tests/fixtures/components/TestOrder.ts +0 -23
  156. package/tests/fixtures/components/TestProduct.ts +0 -23
  157. package/tests/fixtures/components/TestUser.ts +0 -20
  158. package/tests/fixtures/components/index.ts +0 -6
  159. package/tests/graphql/SchemaGeneration.test.ts +0 -90
  160. package/tests/graphql/builders/ResolverBuilder.test.ts +0 -223
  161. package/tests/graphql/builders/TypeDefBuilder.test.ts +0 -153
  162. package/tests/helpers/MockRedisClient.ts +0 -113
  163. package/tests/helpers/MockRedisStreamServer.ts +0 -448
  164. package/tests/integration/archetype/ArcheType.persistence.test.ts +0 -241
  165. package/tests/integration/cache/CacheInvalidation.test.ts +0 -259
  166. package/tests/integration/entity/Entity.persistence.test.ts +0 -333
  167. package/tests/integration/entity/Entity.saveTimeout.test.ts +0 -110
  168. package/tests/integration/query/Query.complexAnalysis.test.ts +0 -557
  169. package/tests/integration/query/Query.edgeCases.test.ts +0 -595
  170. package/tests/integration/query/Query.exec.test.ts +0 -576
  171. package/tests/integration/query/Query.explainAnalyze.test.ts +0 -233
  172. package/tests/integration/query/Query.jsonbArray.test.ts +0 -214
  173. package/tests/integration/remote/dlq.test.ts +0 -175
  174. package/tests/integration/remote/event-dispatch.test.ts +0 -114
  175. package/tests/integration/remote/outbox.test.ts +0 -130
  176. package/tests/integration/remote/rpc.test.ts +0 -177
  177. package/tests/pglite-setup.ts +0 -62
  178. package/tests/setup.ts +0 -164
  179. package/tests/stress/BenchmarkRunner.ts +0 -203
  180. package/tests/stress/DataSeeder.ts +0 -190
  181. package/tests/stress/StressTestReporter.ts +0 -229
  182. package/tests/stress/cursor-perf-test.ts +0 -171
  183. package/tests/stress/fixtures/RealisticComponents.ts +0 -235
  184. package/tests/stress/fixtures/StressTestComponents.ts +0 -58
  185. package/tests/stress/index.ts +0 -7
  186. package/tests/stress/scenarios/query-benchmarks.test.ts +0 -285
  187. package/tests/stress/scenarios/realistic-scenarios.test.ts +0 -1081
  188. package/tests/stress/scenarios/timeout-investigation.test.ts +0 -522
  189. package/tests/unit/BatchLoader.test.ts +0 -196
  190. package/tests/unit/archetype/ArcheType.test.ts +0 -107
  191. package/tests/unit/cache/CacheManager.test.ts +0 -367
  192. package/tests/unit/cache/MemoryCache.test.ts +0 -260
  193. package/tests/unit/cache/RedisCache.test.ts +0 -411
  194. package/tests/unit/entity/Entity.components.test.ts +0 -317
  195. package/tests/unit/entity/Entity.drainSideEffects.test.ts +0 -51
  196. package/tests/unit/entity/Entity.reload.test.ts +0 -63
  197. package/tests/unit/entity/Entity.requireComponents.test.ts +0 -72
  198. package/tests/unit/entity/Entity.test.ts +0 -345
  199. package/tests/unit/gql/depthLimit.test.ts +0 -203
  200. package/tests/unit/gql/operationMiddleware.test.ts +0 -293
  201. package/tests/unit/health/Health.test.ts +0 -129
  202. package/tests/unit/middleware/AccessLog.test.ts +0 -37
  203. package/tests/unit/middleware/Middleware.test.ts +0 -98
  204. package/tests/unit/middleware/RequestId.test.ts +0 -54
  205. package/tests/unit/middleware/SecurityHeaders.test.ts +0 -66
  206. package/tests/unit/query/FilterBuilder.test.ts +0 -111
  207. package/tests/unit/query/JsonbArrayBuilder.test.ts +0 -178
  208. package/tests/unit/query/Query.emptyString.test.ts +0 -69
  209. package/tests/unit/query/Query.test.ts +0 -310
  210. package/tests/unit/remote/CircuitBreaker.test.ts +0 -159
  211. package/tests/unit/remote/RemoteError.test.ts +0 -55
  212. package/tests/unit/remote/decorators.test.ts +0 -195
  213. package/tests/unit/remote/metrics.test.ts +0 -115
  214. package/tests/unit/remote/mockRedisStreamServer.test.ts +0 -104
  215. package/tests/unit/scheduler/DistributedLock.test.ts +0 -274
  216. package/tests/unit/scheduler/SchedulerManager.timeBased.test.ts +0 -95
  217. package/tests/unit/schema/schema-integration.test.ts +0 -426
  218. package/tests/unit/schema/schema.test.ts +0 -580
  219. package/tests/unit/storage/S3StorageProvider.test.ts +0 -567
  220. package/tests/unit/upload/RestUpload.test.ts +0 -267
  221. package/tests/unit/validateEnv.test.ts +0 -82
  222. package/tests/utils/entity-tracker.ts +0 -57
  223. package/tests/utils/index.ts +0 -13
  224. package/tests/utils/test-context.ts +0 -149
@@ -1,211 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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
- }
@@ -1,57 +0,0 @@
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
- }
@@ -1,294 +0,0 @@
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
- }
@@ -1,56 +0,0 @@
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 }
@@ -1,26 +0,0 @@
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
- }