@tscircuit/fake-snippets 0.0.84 → 0.0.86

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 (25) hide show
  1. package/bun-tests/fake-snippets-api/routes/ai_reviews/create.test.ts +11 -2
  2. package/bun-tests/fake-snippets-api/routes/datasheets/create.test.ts +15 -0
  3. package/bun-tests/fake-snippets-api/routes/datasheets/get.test.ts +17 -0
  4. package/bun-tests/fake-snippets-api/routes/datasheets/process_all_datasheets.test.ts +21 -0
  5. package/bun-tests/fake-snippets-api/routes/datasheets/run_async_tasks.test.ts +18 -0
  6. package/bun-tests/fake-snippets-api/routes/package_releases/get.test.ts +25 -0
  7. package/dist/bundle.js +602 -427
  8. package/dist/index.d.ts +86 -2
  9. package/dist/index.js +47 -1
  10. package/dist/schema.d.ts +138 -1
  11. package/dist/schema.js +18 -1
  12. package/fake-snippets-api/lib/db/db-client.ts +36 -0
  13. package/fake-snippets-api/lib/db/schema.ts +18 -0
  14. package/fake-snippets-api/lib/public-mapping/public-map-package-release.ts +23 -0
  15. package/fake-snippets-api/routes/api/_fake/datasheets/process_all_datasheets.ts +37 -0
  16. package/fake-snippets-api/routes/api/_fake/run_async_tasks.ts +12 -0
  17. package/fake-snippets-api/routes/api/ai_reviews/create.ts +20 -0
  18. package/fake-snippets-api/routes/api/datasheets/create.ts +18 -0
  19. package/fake-snippets-api/routes/api/datasheets/get.ts +25 -0
  20. package/fake-snippets-api/routes/api/package_releases/create.ts +1 -1
  21. package/fake-snippets-api/routes/api/package_releases/get.ts +4 -0
  22. package/fake-snippets-api/routes/api/package_releases/list.ts +1 -0
  23. package/package.json +1 -1
  24. package/src/components/SearchComponent.tsx +47 -2
  25. package/src/hooks/use-request-ai-review-mutation.ts +7 -6
@@ -0,0 +1,18 @@
1
+ import { datasheetSchema } from "fake-snippets-api/lib/db/schema"
2
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
3
+ import { z } from "zod"
4
+
5
+ export default withRouteSpec({
6
+ methods: ["POST"],
7
+ auth: "session",
8
+ jsonBody: z.object({
9
+ chip_name: z.string(),
10
+ }),
11
+ jsonResponse: z.object({
12
+ datasheet: datasheetSchema,
13
+ }),
14
+ })(async (req, ctx) => {
15
+ const { chip_name } = req.jsonBody
16
+ const datasheet = ctx.db.addDatasheet({ chip_name })
17
+ return ctx.json({ datasheet })
18
+ })
@@ -0,0 +1,25 @@
1
+ import { datasheetSchema } from "fake-snippets-api/lib/db/schema"
2
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
3
+ import { z } from "zod"
4
+
5
+ export default withRouteSpec({
6
+ methods: ["GET", "POST"],
7
+ auth: "session",
8
+ queryParams: z.object({
9
+ datasheet_id: z.string(),
10
+ }),
11
+ jsonBody: z.any().optional(),
12
+ jsonResponse: z.object({
13
+ datasheet: datasheetSchema,
14
+ }),
15
+ })(async (req, ctx) => {
16
+ const { datasheet_id } = req.query
17
+ const datasheet = ctx.db.getDatasheetById(datasheet_id)
18
+ if (!datasheet) {
19
+ return ctx.error(404, {
20
+ error_code: "datasheet_not_found",
21
+ message: "Datasheet not found",
22
+ })
23
+ }
24
+ return ctx.json({ datasheet })
25
+ })
@@ -104,6 +104,6 @@ export default withRouteSpec({
104
104
 
105
105
  return ctx.json({
106
106
  ok: true,
107
- package_release: publicMapPackageRelease(newPackageRelease),
107
+ package_release: publicMapPackageRelease(newPackageRelease, { db: ctx.db }),
108
108
  })
109
109
  })
@@ -61,6 +61,7 @@ export default withRouteSpec({
61
61
  ok: true,
62
62
  package_release: publicMapPackageRelease(packageReleases[0], {
63
63
  include_ai_review: req.commonParams?.include_ai_review,
64
+ db: ctx.db,
64
65
  }),
65
66
  })
66
67
  }
@@ -87,6 +88,7 @@ export default withRouteSpec({
87
88
  ok: true,
88
89
  package_release: publicMapPackageRelease(packageReleases[0], {
89
90
  include_ai_review: req.commonParams?.include_ai_review,
91
+ db: ctx.db,
90
92
  }),
91
93
  })
92
94
  }
@@ -109,6 +111,7 @@ export default withRouteSpec({
109
111
  ok: true,
110
112
  package_release: publicMapPackageRelease(pkgRelease, {
111
113
  include_ai_review: req.commonParams?.include_ai_review,
114
+ db: ctx.db,
112
115
  }),
113
116
  })
114
117
  }
@@ -128,6 +131,7 @@ export default withRouteSpec({
128
131
  package_release: publicMapPackageRelease(foundRelease, {
129
132
  include_logs: req.commonParams?.include_logs,
130
133
  include_ai_review: req.commonParams?.include_ai_review,
134
+ db: ctx.db,
131
135
  }),
132
136
  })
133
137
  })
@@ -78,6 +78,7 @@ export default withRouteSpec({
78
78
  package_releases: releases.map((pr) =>
79
79
  publicMapPackageRelease(pr, {
80
80
  include_ai_review: req.commonParams?.include_ai_review,
81
+ db: ctx.db,
81
82
  }),
82
83
  ),
83
84
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/fake-snippets",
3
- "version": "0.0.84",
3
+ "version": "0.0.86",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -7,6 +7,7 @@ import { Alert } from "./ui/alert"
7
7
  import { useSnippetsBaseApiUrl } from "@/hooks/use-snippets-base-api-url"
8
8
  import { PrefetchPageLink } from "./PrefetchPageLink"
9
9
  import { CircuitBoard } from "lucide-react"
10
+ import { cn } from "@/lib/utils"
10
11
 
11
12
  interface SearchComponentProps {
12
13
  onResultsFetched?: (results: any[]) => void
@@ -51,6 +52,7 @@ const SearchComponent: React.FC<SearchComponentProps> = ({
51
52
  }) => {
52
53
  const [searchQuery, setSearchQuery] = useState("")
53
54
  const [showResults, setShowResults] = useState(false)
55
+ const [highlightedIndex, setHighlightedIndex] = useState(-1)
54
56
  const axios = useAxios()
55
57
  const resultsRef = useRef<HTMLDivElement>(null)
56
58
  const inputRef = useRef<HTMLInputElement>(null)
@@ -72,6 +74,10 @@ const SearchComponent: React.FC<SearchComponentProps> = ({
72
74
  { enabled: Boolean(searchQuery) },
73
75
  )
74
76
 
77
+ useEffect(() => {
78
+ setHighlightedIndex(-1)
79
+ }, [searchResults])
80
+
75
81
  const handleSearch = (e: React.FormEvent) => {
76
82
  e.preventDefault()
77
83
  if (searchQuery.trim()) {
@@ -86,6 +92,13 @@ const SearchComponent: React.FC<SearchComponentProps> = ({
86
92
  }
87
93
  }, [])
88
94
 
95
+ useEffect(() => {
96
+ if (highlightedIndex < 0) return
97
+ const items = resultsRef.current?.querySelectorAll("li")
98
+ const item = items?.[highlightedIndex] as HTMLElement | undefined
99
+ item?.scrollIntoView({ block: "nearest" })
100
+ }, [highlightedIndex])
101
+
89
102
  useEffect(() => {
90
103
  const handleClickOutside = (event: MouseEvent) => {
91
104
  if (
@@ -133,6 +146,32 @@ const SearchComponent: React.FC<SearchComponentProps> = ({
133
146
  onKeyDown={(e) => {
134
147
  if (e.key === "Backspace" && !searchQuery && closeOnClick) {
135
148
  closeOnClick()
149
+ return
150
+ }
151
+ if (!searchResults) return
152
+ if (e.key === "ArrowDown") {
153
+ e.preventDefault()
154
+ setShowResults(true)
155
+ setHighlightedIndex((prev) =>
156
+ Math.min(prev + 1, searchResults.length - 1),
157
+ )
158
+ } else if (e.key === "ArrowUp") {
159
+ e.preventDefault()
160
+ setHighlightedIndex((prev) => Math.max(prev - 1, 0))
161
+ } else if (e.key === "Enter" && highlightedIndex >= 0) {
162
+ e.preventDefault()
163
+ const pkg = searchResults[highlightedIndex]
164
+ if (pkg) {
165
+ const href = shouldOpenInEditor
166
+ ? `/editor?package_id=${pkg.package_id}`
167
+ : `/${pkg.name}`
168
+ if (shouldOpenInNewTab) {
169
+ window.open(href, "_blank")
170
+ } else {
171
+ setLocation(href)
172
+ }
173
+ setShowResults(false)
174
+ }
136
175
  }
137
176
  }}
138
177
  aria-label="Search packages"
@@ -154,8 +193,14 @@ const SearchComponent: React.FC<SearchComponentProps> = ({
154
193
  >
155
194
  {searchResults.length > 0 ? (
156
195
  <ul className="divide-y divide-gray-200">
157
- {searchResults.map((pkg: any) => (
158
- <li key={pkg.package_id} className="p-2 hover:bg-gray-50">
196
+ {searchResults.map((pkg: any, index: number) => (
197
+ <li
198
+ key={pkg.package_id}
199
+ className={cn(
200
+ "p-2 hover:bg-gray-50",
201
+ index === highlightedIndex && "bg-gray-100",
202
+ )}
203
+ >
159
204
  <LinkWithNewTabHandling
160
205
  href={
161
206
  shouldOpenInEditor
@@ -12,13 +12,14 @@ export const useRequestAiReviewMutation = ({
12
12
 
13
13
  return useMutation(
14
14
  async ({ package_release_id }: { package_release_id: string }) => {
15
- await axios.post("/package_releases/update", {
16
- package_release_id,
17
- ai_review_requested: true,
18
- })
19
- const { data } = await axios.post("/package_releases/get", {
20
- package_release_id,
15
+ await axios.post("/ai_reviews/create", null, {
16
+ params: { package_release_id },
21
17
  })
18
+ const { data } = await axios.post(
19
+ "/package_releases/get",
20
+ { package_release_id },
21
+ { params: { include_ai_review: true } },
22
+ )
22
23
  return data.package_release as PackageRelease
23
24
  },
24
25
  {