@tscircuit/fake-snippets 0.0.1 → 0.0.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 (37) hide show
  1. package/.github/workflows/bun-pver-release.yml +27 -0
  2. package/bun.lockb +0 -0
  3. package/dist/bundle.js +19 -3
  4. package/fake-snippets-api/routes/api/snippets/create.ts +24 -2
  5. package/package.json +3 -3
  6. package/src/components/ViewSnippetHeader.tsx +21 -0
  7. package/src/lib/download-fns/download-gltf.ts +1 -1
  8. package/dist/assets/editor_example_1-1000w.webp +0 -0
  9. package/dist/assets/editor_example_1-1200w.webp +0 -0
  10. package/dist/assets/editor_example_1-1600w.webp +0 -0
  11. package/dist/assets/editor_example_1-2000w.webp +0 -0
  12. package/dist/assets/editor_example_1-400w.webp +0 -0
  13. package/dist/assets/editor_example_1-600w.webp +0 -0
  14. package/dist/assets/editor_example_1-800w.webp +0 -0
  15. package/dist/assets/editor_example_1_more_square-1000w.webp +0 -0
  16. package/dist/assets/editor_example_1_more_square-1200w.webp +0 -0
  17. package/dist/assets/editor_example_1_more_square-1600w.webp +0 -0
  18. package/dist/assets/editor_example_1_more_square-2000w.webp +0 -0
  19. package/dist/assets/editor_example_1_more_square-400w.webp +0 -0
  20. package/dist/assets/editor_example_1_more_square-600w.webp +0 -0
  21. package/dist/assets/editor_example_1_more_square-800w.webp +0 -0
  22. package/dist/assets/editor_example_2-1000w.webp +0 -0
  23. package/dist/assets/editor_example_2-1200w.webp +0 -0
  24. package/dist/assets/editor_example_2-1600w.webp +0 -0
  25. package/dist/assets/editor_example_2-2000w.webp +0 -0
  26. package/dist/assets/editor_example_2-400w.webp +0 -0
  27. package/dist/assets/editor_example_2-600w.webp +0 -0
  28. package/dist/assets/editor_example_2-800w.webp +0 -0
  29. package/dist/assets/example_schematic-1000w.webp +0 -0
  30. package/dist/assets/example_schematic-1200w.webp +0 -0
  31. package/dist/assets/example_schematic-1600w.webp +0 -0
  32. package/dist/assets/example_schematic-2000w.webp +0 -0
  33. package/dist/assets/example_schematic-400w.webp +0 -0
  34. package/dist/assets/example_schematic-600w.webp +0 -0
  35. package/dist/assets/example_schematic-800w.webp +0 -0
  36. package/dist/robots.txt +0 -9
  37. package/dist/sitemap.xml +0 -118
@@ -16,7 +16,7 @@ export default withRouteSpec({
16
16
  }),
17
17
  jsonResponse: z.object({
18
18
  ok: z.boolean(),
19
- snippet: snippetSchema,
19
+ snippet: snippetSchema.optional(),
20
20
  }),
21
21
  })(async (req, ctx) => {
22
22
  let {
@@ -28,9 +28,24 @@ export default withRouteSpec({
28
28
  circuit_json,
29
29
  dts,
30
30
  } = req.jsonBody
31
+
31
32
  if (!unscoped_name) {
32
33
  unscoped_name = `untitled-${snippet_type}-${ctx.db.idCounter + 1}`
33
34
  }
35
+
36
+ const existingSnippet = ctx.db.snippets.find(
37
+ (snippet) =>
38
+ snippet.unscoped_name === unscoped_name &&
39
+ snippet.owner_name === ctx.auth.github_username,
40
+ )
41
+
42
+ if (existingSnippet) {
43
+ return ctx.error(400, {
44
+ error_code: "snippet_already_exists",
45
+ message: "You have already forked this snippet in your account.",
46
+ })
47
+ }
48
+
34
49
  const newSnippet: z.input<typeof snippetSchema> = {
35
50
  snippet_id: `snippet_${ctx.db.idCounter + 1}`,
36
51
  name: `${ctx.auth.github_username}/${unscoped_name}`,
@@ -46,7 +61,14 @@ export default withRouteSpec({
46
61
  dts,
47
62
  }
48
63
 
49
- ctx.db.addSnippet(newSnippet)
64
+ try {
65
+ ctx.db.addSnippet(newSnippet)
66
+ } catch (error) {
67
+ return ctx.error(500, {
68
+ error_code: "snippet_creation_failed",
69
+ message: `Failed to create snippet: ${error}`,
70
+ })
71
+ }
50
72
 
51
73
  return ctx.json({
52
74
  ok: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/fake-snippets",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -61,7 +61,7 @@
61
61
  "@radix-ui/react-toggle": "^1.1.0",
62
62
  "@radix-ui/react-toggle-group": "^1.1.0",
63
63
  "@radix-ui/react-tooltip": "^1.1.2",
64
- "@tscircuit/3d-viewer": "^0.0.94",
64
+ "@tscircuit/3d-viewer": "^0.0.95",
65
65
  "@tscircuit/footprinter": "^0.0.99",
66
66
  "@tscircuit/layout": "^0.0.29",
67
67
  "@tscircuit/math-utils": "^0.0.10",
@@ -87,7 +87,7 @@
87
87
  "codemirror": "^6.0.1",
88
88
  "country-list": "^2.3.0",
89
89
  "date-fns": "^4.1.0",
90
- "dsn-converter": "^0.0.54",
90
+ "dsn-converter": "^0.0.57",
91
91
  "easyeda": "^0.0.62",
92
92
  "embla-carousel-react": "^8.3.0",
93
93
  "extract-codefence": "^0.0.4",
@@ -40,6 +40,13 @@ export default function ViewSnippetHeader() {
40
40
  owner_name: session.github_username,
41
41
  code: snippet.code,
42
42
  })
43
+
44
+ if (!data.ok) {
45
+ throw new Error(
46
+ data.error || "Unknown error occurred while forking snippet.",
47
+ )
48
+ }
49
+
43
50
  return data.snippet
44
51
  },
45
52
  {
@@ -51,6 +58,20 @@ export default function ViewSnippetHeader() {
51
58
  onSuccess?.(forkedSnippet)
52
59
  },
53
60
  onError: (error: any) => {
61
+ // Check if the error message contains 'already exists'
62
+ if (error.message?.includes("already forked")) {
63
+ toast({
64
+ title: "Snippet already exists",
65
+ description: error.message,
66
+ variant: "destructive", // You can style this variant differently
67
+ })
68
+ } else {
69
+ toast({
70
+ title: "Error",
71
+ description: "Failed to fork snippet. Please try again.",
72
+ variant: "destructive", // Use destructive variant for errors
73
+ })
74
+ }
54
75
  console.error("Error forking snippet:", error)
55
76
  },
56
77
  },
@@ -13,7 +13,7 @@ export const downloadGltf = async (
13
13
 
14
14
  if (!threeJsObject) {
15
15
  throw new Error(
16
- "No 3D object found, run the snippet before downloading the 3d model",
16
+ "To download the 3D model, please open the 3D view first and run the snippet",
17
17
  )
18
18
  }
19
19
 
package/dist/robots.txt DELETED
@@ -1,9 +0,0 @@
1
- # Allow all crawlers
2
- User-agent: *
3
- Allow: /
4
-
5
- # Sitemaps
6
- Sitemap: https://tscircuit.com/sitemap.xml
7
-
8
- # Crawl-delay
9
- Crawl-delay: 10
package/dist/sitemap.xml DELETED
@@ -1,118 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
- <url>
4
- <loc>https://tscircuit.com/</loc>
5
- <changefreq>weekly</changefreq>
6
- <priority>1.0</priority>
7
- </url>
8
- <url>
9
- <loc>https://tscircuit.com/editor</loc>
10
- <changefreq>weekly</changefreq>
11
- <priority>0.9</priority>
12
- </url>
13
- <url>
14
- <loc>https://tscircuit.com/playground</loc>
15
- <changefreq>weekly</changefreq>
16
- <priority>0.9</priority>
17
- </url>
18
- <url>
19
- <loc>https://tscircuit.com/quickstart</loc>
20
- <changefreq>monthly</changefreq>
21
- <priority>0.8</priority>
22
- </url>
23
- <url>
24
- <loc>https://tscircuit.com/dashboard</loc>
25
- <changefreq>weekly</changefreq>
26
- <priority>0.7</priority>
27
- </url>
28
- <url>
29
- <loc>https://tscircuit.com/newest</loc>
30
- <changefreq>daily</changefreq>
31
- <priority>0.8</priority>
32
- </url>
33
- <url>
34
- <loc>https://tscircuit.com/search</loc>
35
- <changefreq>weekly</changefreq>
36
- <priority>0.7</priority>
37
- </url>
38
- <url>
39
- <loc>https://tscircuit.com/settings</loc>
40
- <changefreq>monthly</changefreq>
41
- <priority>0.6</priority>
42
- </url>
43
- <url>
44
- <loc>https://tscircuit.com/community/join-redirect</loc>
45
- <changefreq>monthly</changefreq>
46
- <priority>0.6</priority>
47
- </url>
48
- <url>
49
- <loc>https://tscircuit.com/legal/terms-of-service</loc>
50
- <changefreq>yearly</changefreq>
51
- <priority>0.3</priority>
52
- </url>
53
- <url>
54
- <loc>https://tscircuit.com/legal/privacy-policy</loc>
55
- <changefreq>yearly</changefreq>
56
- <priority>0.3</priority>
57
- </url>
58
- <url>
59
- <loc>https://tscircuit.com/techmannih/regulator-SPX1117M3L50TR</loc>
60
- <lastmod>2025-01-07T02:12:09.440Z</lastmod>
61
- <changefreq>weekly</changefreq>
62
- <priority>0.7</priority>
63
- </url>
64
- <url>
65
- <loc>https://tscircuit.com/seveibar/HS91L02W2C01</loc>
66
- <lastmod>2025-01-06T01:41:28.137Z</lastmod>
67
- <changefreq>weekly</changefreq>
68
- <priority>0.7</priority>
69
- </url>
70
- <url>
71
- <loc>https://tscircuit.com/AnasSarkiz/grid-of-LEDs-with-an-ESP32</loc>
72
- <lastmod>2025-01-15T12:29:08.815Z</lastmod>
73
- <changefreq>weekly</changefreq>
74
- <priority>0.7</priority>
75
- </url>
76
- <url>
77
- <loc>https://tscircuit.com/techmannih/blinking-led-circuit</loc>
78
- <lastmod>2025-01-05T02:51:31.724Z</lastmod>
79
- <changefreq>weekly</changefreq>
80
- <priority>0.7</priority>
81
- </url>
82
- <url>
83
- <loc>https://tscircuit.com/imrishabh18/testing-123456</loc>
84
- <lastmod>2024-12-03T11:47:21.770Z</lastmod>
85
- <changefreq>weekly</changefreq>
86
- <priority>0.7</priority>
87
- </url>
88
- <url>
89
- <loc>https://tscircuit.com/Abse2001/OR-Gate-Chip</loc>
90
- <lastmod>2024-12-01T19:50:12.221Z</lastmod>
91
- <changefreq>weekly</changefreq>
92
- <priority>0.7</priority>
93
- </url>
94
- <url>
95
- <loc>https://tscircuit.com/anas-sarkez/Arduino_Nano</loc>
96
- <lastmod>2024-11-23T21:51:52.436Z</lastmod>
97
- <changefreq>weekly</changefreq>
98
- <priority>0.7</priority>
99
- </url>
100
- <url>
101
- <loc>https://tscircuit.com/seveibar/smd-usb-c</loc>
102
- <lastmod>2024-11-14T21:18:02.296Z</lastmod>
103
- <changefreq>weekly</changefreq>
104
- <priority>0.7</priority>
105
- </url>
106
- <url>
107
- <loc>https://tscircuit.com/seveibar/a555timer</loc>
108
- <lastmod>2024-10-14T17:46:25.789Z</lastmod>
109
- <changefreq>weekly</changefreq>
110
- <priority>0.7</priority>
111
- </url>
112
- <url>
113
- <loc>https://tscircuit.com/seveibar/Key</loc>
114
- <lastmod>2025-01-02T19:16:31.127Z</lastmod>
115
- <changefreq>weekly</changefreq>
116
- <priority>0.7</priority>
117
- </url>
118
- </urlset>