@tscircuit/fake-snippets 0.0.91 → 0.0.93
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.
- package/api/generated-index.js +20 -3
- package/bun-tests/fake-snippets-api/routes/datasheets/list.test.ts +49 -0
- package/dist/bundle.js +420 -378
- package/dist/index.d.ts +10 -2
- package/dist/index.js +18 -2
- package/fake-snippets-api/lib/db/autoload-dev-packages.ts +1 -0
- package/fake-snippets-api/lib/db/db-client.ts +18 -1
- package/fake-snippets-api/routes/api/autocomplete/create_autocomplete.ts +0 -1
- package/fake-snippets-api/routes/api/datasheets/list.ts +29 -0
- package/fake-snippets-api/routes/api/packages/list_trending.ts +1 -1
- package/package.json +1 -1
- package/src/components/CmdKMenu.tsx +1 -1
- package/src/components/PackageBuildsPage/LogContent.tsx +4 -2
- package/src/components/PackageCard.tsx +4 -2
- package/src/components/package-port/CodeAndPreview.tsx +27 -28
- package/src/components/package-port/CodeEditor.tsx +84 -9
- package/src/components/package-port/EditorNav.tsx +14 -14
- package/src/components/package-port/GlobalFindReplace.tsx +2 -2
- package/src/pages/dashboard.tsx +5 -1
package/api/generated-index.js
CHANGED
|
@@ -160,18 +160,35 @@ async function handleCustomPackageHtml(req, res) {
|
|
|
160
160
|
throw new Error("Invalid author/package URL")
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
const
|
|
163
|
+
const packageNotFoundHtml = getHtmlWithModifiedSeoTags({
|
|
164
|
+
title: "Package Not Found - tscircuit",
|
|
165
|
+
description: `The package ${author}/${unscopedPackageName} could not be found.`,
|
|
166
|
+
canonicalUrl: `${BASE_URL}/${he.encode(author)}/${he.encode(unscopedPackageName)}`,
|
|
167
|
+
})
|
|
168
|
+
const packageDetails = await ky
|
|
164
169
|
.get(`${REGISTRY_URL}/packages/get`, {
|
|
165
170
|
searchParams: {
|
|
166
171
|
name: `${author}/${unscopedPackageName}`,
|
|
167
172
|
},
|
|
168
173
|
})
|
|
169
174
|
.json()
|
|
175
|
+
.catch((e) => {
|
|
176
|
+
if (String(e).includes("404")) {
|
|
177
|
+
return null
|
|
178
|
+
}
|
|
179
|
+
throw e
|
|
180
|
+
})
|
|
170
181
|
|
|
171
|
-
if (!
|
|
172
|
-
|
|
182
|
+
if (!packageDetails) {
|
|
183
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8")
|
|
184
|
+
res.setHeader("Cache-Control", cacheControlHeader)
|
|
185
|
+
res.setHeader("Vary", "Accept-Encoding")
|
|
186
|
+
res.status(404).send(packageNotFoundHtml)
|
|
187
|
+
return
|
|
173
188
|
}
|
|
174
189
|
|
|
190
|
+
const { package: packageInfo } = packageDetails
|
|
191
|
+
|
|
175
192
|
let packageRelease = null
|
|
176
193
|
let packageFiles = null
|
|
177
194
|
try {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
|
|
2
|
+
import { test, expect } from "bun:test"
|
|
3
|
+
|
|
4
|
+
// Test listing datasheets by chip name
|
|
5
|
+
|
|
6
|
+
test("list datasheets", async () => {
|
|
7
|
+
const { axios } = await getTestServer()
|
|
8
|
+
|
|
9
|
+
await axios.post("/api/datasheets/create", { chip_name: "Chip" })
|
|
10
|
+
await axios.post("/api/datasheets/create", { chip_name: "Chip" })
|
|
11
|
+
await axios.post("/api/datasheets/create", { chip_name: "Other" })
|
|
12
|
+
|
|
13
|
+
const res = await axios.get("/api/datasheets/list", {
|
|
14
|
+
params: { chip_name: "Chip" },
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
expect(res.status).toBe(200)
|
|
18
|
+
expect(res.data.datasheets).toHaveLength(2)
|
|
19
|
+
expect(res.data.datasheets.every((d: any) => d.chip_name === "Chip")).toBe(
|
|
20
|
+
true,
|
|
21
|
+
)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test("list datasheets is_popular returns all", async () => {
|
|
25
|
+
const { axios } = await getTestServer()
|
|
26
|
+
|
|
27
|
+
await axios.post("/api/datasheets/create", { chip_name: "Chip" })
|
|
28
|
+
await axios.post("/api/datasheets/create", { chip_name: "Other" })
|
|
29
|
+
|
|
30
|
+
const res = await axios.get("/api/datasheets/list", {
|
|
31
|
+
params: { is_popular: true },
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
expect(res.status).toBe(200)
|
|
35
|
+
expect(res.data.datasheets).toHaveLength(2)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test("list datasheets empty", async () => {
|
|
39
|
+
const { axios } = await getTestServer()
|
|
40
|
+
|
|
41
|
+
await axios.post("/api/datasheets/create", { chip_name: "Other" })
|
|
42
|
+
|
|
43
|
+
const res = await axios.get("/api/datasheets/list", {
|
|
44
|
+
params: { chip_name: "Chip" },
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
expect(res.status).toBe(200)
|
|
48
|
+
expect(res.data.datasheets).toHaveLength(0)
|
|
49
|
+
})
|