@tscircuit/fake-snippets 0.0.120 → 0.0.121

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 (131) hide show
  1. package/.github/workflows/bun-pver-release.yml +29 -4
  2. package/dist/assets/404-CnNkOMw-.js +1 -0
  3. package/dist/assets/Analytics-DIw7l2gi.js +84 -0
  4. package/dist/assets/BuildsList-CeqVVhbz.js +1 -0
  5. package/dist/assets/CodeAndPreview-Dycd0s15.js +722 -0
  6. package/dist/assets/DownloadButtonAndMenu-OIUhbKkj.js +194 -0
  7. package/dist/assets/FileSaver.min-BDsOlqKl.js +1 -0
  8. package/dist/assets/Footer-DU-HdqGk.js +1 -0
  9. package/dist/assets/GithubAvatarWithFallback-CQhrBiKP.js +6 -0
  10. package/dist/assets/Header-CI4GZVOv.js +1 -0
  11. package/dist/assets/Header2-CrMDmo3P.js +5 -0
  12. package/dist/assets/NotFound-DaXtEPsC.js +1 -0
  13. package/dist/assets/OrganizationCard-Bs2dw-AL.js +1 -0
  14. package/dist/assets/PackageBreadcrumb-DpOpPbGc.js +6 -0
  15. package/dist/assets/PackageCard-ejE2dLlA.js +16 -0
  16. package/dist/assets/PackageSearchResults-BI3Rtmr2.js +1 -0
  17. package/dist/assets/ProfileRouter-4xNgtXr5.js +6 -0
  18. package/dist/assets/alert-dialog-DrOB4Tui.js +1 -0
  19. package/dist/assets/authorize-D-5R3QHA.js +16 -0
  20. package/dist/assets/badge-Bk-k6kyg.js +1 -0
  21. package/dist/assets/card-CzXDit7x.js +1 -0
  22. package/dist/assets/circle-alert-Du9-4of0.js +6 -0
  23. package/dist/assets/circle-check-big-KaRyRsht.js +6 -0
  24. package/dist/assets/cpu-BnvjzmIA.js +6 -0
  25. package/dist/assets/create-organization-BHNFvE7B.js +1 -0
  26. package/dist/assets/dashboard-DDH4V91X.js +11 -0
  27. package/dist/assets/datasheet-DqKtWt-O.js +1 -0
  28. package/dist/assets/datasheets-4W6pEMf3.js +1 -0
  29. package/dist/assets/dev-login-CbHdDthp.js +1 -0
  30. package/dist/assets/editor-bqg9Yv91.js +1 -0
  31. package/dist/assets/editor_example_1-1000w.webp +0 -0
  32. package/dist/assets/editor_example_1-1200w.webp +0 -0
  33. package/dist/assets/editor_example_1-1600w.webp +0 -0
  34. package/dist/assets/editor_example_1-2000w.webp +0 -0
  35. package/dist/assets/editor_example_1-400w.webp +0 -0
  36. package/dist/assets/editor_example_1-600w.webp +0 -0
  37. package/dist/assets/editor_example_1-800w.webp +0 -0
  38. package/dist/assets/editor_example_1_more_square-1000w.webp +0 -0
  39. package/dist/assets/editor_example_1_more_square-1200w.webp +0 -0
  40. package/dist/assets/editor_example_1_more_square-1600w.webp +0 -0
  41. package/dist/assets/editor_example_1_more_square-2000w.webp +0 -0
  42. package/dist/assets/editor_example_1_more_square-400w.webp +0 -0
  43. package/dist/assets/editor_example_1_more_square-600w.webp +0 -0
  44. package/dist/assets/editor_example_1_more_square-800w.webp +0 -0
  45. package/dist/assets/editor_example_2-1000w.webp +0 -0
  46. package/dist/assets/editor_example_2-1200w.webp +0 -0
  47. package/dist/assets/editor_example_2-1600w.webp +0 -0
  48. package/dist/assets/editor_example_2-2000w.webp +0 -0
  49. package/dist/assets/editor_example_2-400w.webp +0 -0
  50. package/dist/assets/editor_example_2-600w.webp +0 -0
  51. package/dist/assets/editor_example_2-800w.webp +0 -0
  52. package/dist/assets/example_schematic-1000w.webp +0 -0
  53. package/dist/assets/example_schematic-1200w.webp +0 -0
  54. package/dist/assets/example_schematic-1600w.webp +0 -0
  55. package/dist/assets/example_schematic-2000w.webp +0 -0
  56. package/dist/assets/example_schematic-400w.webp +0 -0
  57. package/dist/assets/example_schematic-600w.webp +0 -0
  58. package/dist/assets/example_schematic-800w.webp +0 -0
  59. package/dist/assets/eye-B_NMTTT7.js +6 -0
  60. package/dist/assets/fallback-image.svg +1 -0
  61. package/dist/assets/favicon-BwEjZKGP.ico +0 -0
  62. package/dist/assets/formatTimeAgo-CawXna5h.js +6 -0
  63. package/dist/assets/github-DjKGjbX1.js +6 -0
  64. package/dist/assets/github-dark-DHJKELXO.js +1 -0
  65. package/dist/assets/github-light-DAi9KRSo.js +1 -0
  66. package/dist/assets/hash-DfKYpqTm.js +6 -0
  67. package/dist/assets/index-B17tE1vy.js +1 -0
  68. package/dist/assets/index-BQPj88OW.js +6051 -0
  69. package/dist/assets/index-DvNLZBaq.js +6 -0
  70. package/dist/assets/keyboard-4b_qLHIF.js +11 -0
  71. package/dist/assets/label-CTudXc4q.js +1 -0
  72. package/dist/assets/landing-Cjvvx-9q.js +11 -0
  73. package/dist/assets/latest-DMk4BmXW.js +1 -0
  74. package/dist/assets/layers-BJ1iwaVM.js +6 -0
  75. package/dist/assets/load-prettier-DgbV1Jgu.js +1 -0
  76. package/dist/assets/lock-BOZRJdUv.js +6 -0
  77. package/dist/assets/main-DPEM9abA.js +26 -0
  78. package/dist/assets/main-MTKdI4FA.css +1 -0
  79. package/dist/assets/my-orders-B7lEyNR9.js +1 -0
  80. package/dist/assets/organization-settings-rNvhYFgZ.js +6 -0
  81. package/dist/assets/package-editor-T4WIRP49.js +1 -0
  82. package/dist/assets/pen-D54fxNRf.js +6 -0
  83. package/dist/assets/plus-KkE_6Dq2.js +6 -0
  84. package/dist/assets/preview-release-DWhKHFWp.js +1 -0
  85. package/dist/assets/quickstart-WF3HR9Dc.js +1 -0
  86. package/dist/assets/refresh-cw-aWASTRku.js +6 -0
  87. package/dist/assets/release-builds-COa5ndHa.js +1 -0
  88. package/dist/assets/release-detail-iclJPUO-.js +6 -0
  89. package/dist/assets/releases-Clsyp-7n.js +1 -0
  90. package/dist/assets/role-badge-BGF_IMlO.js +16 -0
  91. package/dist/assets/search-CwH23pAU.js +1 -0
  92. package/dist/assets/select-BN8AF1J7.js +1 -0
  93. package/dist/assets/settings-B2bMEtS4.js +6 -0
  94. package/dist/assets/skeleton-DLAS40-y.js +1 -0
  95. package/dist/assets/svg-to-png-BX4YEHCP-JcDm8Hc5.js +1 -0
  96. package/dist/assets/svg-to-png-BX4YEHCP-pNo9Afg8.js +1 -0
  97. package/dist/assets/tabs-Ce0NFuwd.js +1 -0
  98. package/dist/assets/timeAgo-VY0F2EV9.js +10 -0
  99. package/dist/assets/tooltip-C1pwvC0K.js +11 -0
  100. package/dist/assets/trash-2-BW3eClHz.js +6 -0
  101. package/dist/assets/trending-C8246HGf.js +1 -0
  102. package/dist/assets/triangle-alert-BMIBEO1D.js +6 -0
  103. package/dist/assets/tsx-COt5Ahok.js +1 -0
  104. package/dist/assets/use-create-datasheet-B7TDsTUt.js +1 -0
  105. package/dist/assets/use-delete-package-DLKtoTOj.js +1 -0
  106. package/dist/assets/use-download-zip-CAOKjGXW.js +1 -0
  107. package/dist/assets/use-list-user-orgs-CgJIT7N4.js +1 -0
  108. package/dist/assets/use-organization-XwYYTFck.js +1 -0
  109. package/dist/assets/use-package-builds-Bx8rfxi1.js +1 -0
  110. package/dist/assets/use-package-by-package-name-1s1Pcarw.js +1 -0
  111. package/dist/assets/use-package-files-CmmWVuGn.js +1 -0
  112. package/dist/assets/use-package-release-by-id-or-version-BuuXcSZq.js +1 -0
  113. package/dist/assets/use-package-release-images-BMaZtvmk.js +1 -0
  114. package/dist/assets/use-packages-base-api-url-DA1hucM7.js +1 -0
  115. package/dist/assets/useQueries-BJ7Ue7HV.js +1 -0
  116. package/dist/assets/user-settings-BqO5FkMf.js +1 -0
  117. package/dist/assets/view-package-C-OvJr_Q.js +165 -0
  118. package/dist/assets/vitesse-light-CVO1_9PV.js +1 -0
  119. package/dist/assets/wasm-CG6Dc4jp.js +1 -0
  120. package/dist/index.html +127 -0
  121. package/dist/landing.html +34 -0
  122. package/dist/robots.txt +9 -0
  123. package/dist/sitemap.xml +118 -0
  124. package/dist/stats.html +4949 -0
  125. package/package.json +1 -1
  126. package/dist/bundle.js +0 -9288
  127. package/dist/index.d.ts +0 -2190
  128. package/dist/index.js +0 -3826
  129. package/dist/schema.d.ts +0 -3142
  130. package/dist/schema.js +0 -454
  131. package/fake-snippets-api/bun.lockb +0 -0
package/dist/index.js DELETED
@@ -1,3826 +0,0 @@
1
- // fake-snippets-api/lib/db/db-client.ts
2
- import { randomUUID } from "crypto";
3
- import { hoist } from "zustand-hoist";
4
- import { createStore } from "zustand/vanilla";
5
- import { combine } from "zustand/middleware";
6
-
7
- // fake-snippets-api/lib/db/schema.ts
8
- import { z } from "zod";
9
- var errorSchema = z.object({
10
- error_code: z.string(),
11
- message: z.string()
12
- }).passthrough();
13
- var errorResponseSchema = z.object({
14
- error: errorSchema
15
- });
16
- var snippetSchema = z.object({
17
- snippet_id: z.string(),
18
- package_release_id: z.string(),
19
- name: z.string(),
20
- unscoped_name: z.string(),
21
- owner_name: z.string(),
22
- is_starred: z.boolean().default(false),
23
- code: z.string(),
24
- dts: z.string().optional(),
25
- compiled_js: z.string().optional().nullable(),
26
- circuit_json: z.array(z.record(z.any())).optional().nullable(),
27
- manual_edits_json_content: z.string().optional().nullable(),
28
- created_at: z.string(),
29
- updated_at: z.string(),
30
- starred_at: z.string().optional(),
31
- snippet_type: z.enum(["board", "package", "model", "footprint"]),
32
- description: z.string().optional(),
33
- version: z.string().default("0.0.1"),
34
- star_count: z.number().default(0),
35
- is_private: z.boolean().default(false),
36
- is_public: z.boolean().default(true),
37
- is_unlisted: z.boolean().default(false),
38
- tags: z.array(z.string()).optional()
39
- });
40
- var sessionSchema = z.object({
41
- session_id: z.string(),
42
- account_id: z.string(),
43
- expires_at: z.string(),
44
- is_cli_session: z.boolean()
45
- });
46
- var loginPageSchema = z.object({
47
- login_page_id: z.string(),
48
- login_page_auth_token: z.string(),
49
- was_login_successful: z.boolean(),
50
- has_been_used_to_create_session: z.boolean(),
51
- created_at: z.string(),
52
- expires_at: z.string()
53
- });
54
- var shippingInfoSchema = z.object({
55
- firstName: z.string(),
56
- lastName: z.string(),
57
- companyName: z.string().optional(),
58
- address: z.string(),
59
- apartment: z.string().optional(),
60
- city: z.string(),
61
- state: z.string(),
62
- zipCode: z.string(),
63
- country: z.string(),
64
- phone: z.string()
65
- });
66
- var accountSchema = z.object({
67
- account_id: z.string(),
68
- github_username: z.string(),
69
- shippingInfo: shippingInfoSchema.optional(),
70
- personal_org_id: z.string().optional(),
71
- is_tscircuit_staff: z.boolean().default(false)
72
- });
73
- var orderSchema = z.object({
74
- order_id: z.string(),
75
- account_id: z.string().nullable(),
76
- is_running: z.boolean(),
77
- is_started: z.boolean(),
78
- is_finished: z.boolean(),
79
- error: errorSchema.nullable(),
80
- has_error: z.boolean(),
81
- created_at: z.string(),
82
- started_at: z.string().nullable(),
83
- completed_at: z.string().nullable(),
84
- circuit_json: z.any()
85
- });
86
- var orderFileSchema = z.object({
87
- order_file_id: z.string(),
88
- order_id: z.string(),
89
- is_gerbers_zip: z.boolean(),
90
- content_type: z.string(),
91
- for_provider: z.string().nullable(),
92
- uploaded_at: z.string(),
93
- content_text: z.string().nullable(),
94
- content_bytes: z.instanceof(Uint8Array).nullable()
95
- });
96
- var bugReportSchema = z.object({
97
- bug_report_id: z.string().uuid(),
98
- reporter_account_id: z.string(),
99
- text: z.string().nullable(),
100
- is_auto_deleted: z.boolean().default(false),
101
- delete_at: z.string().datetime().nullable(),
102
- created_at: z.string().datetime(),
103
- file_count: z.number().int()
104
- });
105
- var bugReportFileSchema = z.object({
106
- bug_report_file_id: z.string().uuid(),
107
- bug_report_id: z.string().uuid(),
108
- file_path: z.string(),
109
- content_mimetype: z.string(),
110
- is_text: z.boolean(),
111
- created_at: z.string().datetime(),
112
- content_text: z.string().nullable(),
113
- content_bytes: z.instanceof(Uint8Array).nullable()
114
- });
115
- var bugReportFileResponseSchema = bugReportFileSchema.omit({
116
- content_text: true,
117
- content_bytes: true
118
- });
119
- var shippingOptionSchema = z.object({
120
- carrier: z.string(),
121
- service: z.string(),
122
- cost: z.number()
123
- });
124
- var quotedComponentSchema = z.object({
125
- manufacturer_part_number: z.string().nullable(),
126
- supplier_part_number: z.string().nullable(),
127
- quantity: z.number().default(0),
128
- unit_price: z.number().default(0),
129
- total_price: z.number().default(0),
130
- available: z.boolean().default(true)
131
- });
132
- var orderQuoteSchema = z.object({
133
- order_quote_id: z.string(),
134
- account_id: z.string().nullable(),
135
- package_release_id: z.string().nullable(),
136
- is_completed: z.boolean().default(false),
137
- is_processing: z.boolean().default(true),
138
- vendor_name: z.string(),
139
- error: errorSchema.nullable(),
140
- has_error: z.boolean().default(false),
141
- created_at: z.string(),
142
- updated_at: z.string(),
143
- completed_at: z.string().nullable(),
144
- quoted_components: z.array(quotedComponentSchema).nullable(),
145
- bare_pcb_cost: z.number().default(0),
146
- shipping_options: z.array(shippingOptionSchema),
147
- total_cost_without_shipping: z.number().default(0)
148
- });
149
- var aiReviewSchema = z.object({
150
- ai_review_id: z.string().uuid(),
151
- package_release_id: z.string().optional(),
152
- ai_review_text: z.string().nullable(),
153
- start_processing_at: z.string().datetime().nullable(),
154
- finished_processing_at: z.string().datetime().nullable(),
155
- processing_error: z.any().nullable(),
156
- created_at: z.string().datetime(),
157
- display_status: z.enum(["pending", "completed", "failed"])
158
- });
159
- var datasheetPinInformationSchema = z.object({
160
- pin_number: z.string(),
161
- name: z.string(),
162
- description: z.string(),
163
- capabilities: z.array(z.string())
164
- });
165
- var datasheetSchema = z.object({
166
- datasheet_id: z.string(),
167
- chip_name: z.string(),
168
- created_at: z.string(),
169
- pin_information: datasheetPinInformationSchema.array().nullable(),
170
- datasheet_pdf_urls: z.array(z.string()).nullable(),
171
- ai_description: z.string().nullable()
172
- });
173
- var githubInstallationSchema = z.object({
174
- github_installation_id: z.string(),
175
- account_id: z.string(),
176
- installation_id: z.string(),
177
- // GitHub App installation ID
178
- github_username: z.string(),
179
- created_at: z.string().datetime(),
180
- updated_at: z.string().datetime(),
181
- is_active: z.boolean().default(true),
182
- access_token: z.string().nullable().optional(),
183
- // For storing GitHub access token
184
- access_token_expires_at: z.string().datetime().nullable().optional()
185
- });
186
- var accountSnippetSchema = z.object({
187
- account_id: z.string(),
188
- snippet_id: z.string(),
189
- has_starred: z.boolean(),
190
- created_at: z.string(),
191
- updated_at: z.string()
192
- });
193
- var accountPackageSchema = z.object({
194
- account_package_id: z.string(),
195
- account_id: z.string(),
196
- package_id: z.string(),
197
- is_starred: z.boolean(),
198
- created_at: z.string(),
199
- updated_at: z.string()
200
- });
201
- var packageReleaseSchema = z.object({
202
- package_release_id: z.string(),
203
- package_id: z.string(),
204
- version: z.string().nullable(),
205
- is_locked: z.boolean(),
206
- is_latest: z.boolean(),
207
- created_at: z.string().datetime(),
208
- commit_sha: z.string().nullable().optional(),
209
- license: z.string().nullable().optional(),
210
- circuit_json_build_error: z.string().nullable().optional(),
211
- circuit_json_build_error_last_updated_at: z.string().datetime().nullable().optional(),
212
- has_transpiled: z.boolean().default(false),
213
- transpilation_error: z.string().nullable().optional(),
214
- fs_sha: z.string().nullable().optional(),
215
- // Build Status and Display
216
- display_status: z.enum(["pending", "building", "complete", "error"]).default("pending"),
217
- total_build_duration_ms: z.number().nullable().optional(),
218
- // Transpilation Process
219
- transpilation_display_status: z.enum(["pending", "building", "complete", "error"]).default("pending"),
220
- transpilation_in_progress: z.boolean().default(false),
221
- transpilation_started_at: z.string().datetime().nullable().optional(),
222
- transpilation_completed_at: z.string().datetime().nullable().optional(),
223
- transpilation_logs: z.array(z.any()).default([]),
224
- transpilation_is_stale: z.boolean().default(false),
225
- // Circuit JSON Build Process
226
- circuit_json_build_display_status: z.enum(["pending", "building", "complete", "error"]).default("pending"),
227
- circuit_json_build_in_progress: z.boolean().default(false),
228
- circuit_json_build_started_at: z.string().datetime().nullable().optional(),
229
- circuit_json_build_completed_at: z.string().datetime().nullable().optional(),
230
- circuit_json_build_logs: z.array(z.any()).default([]),
231
- circuit_json_build_is_stale: z.boolean().default(false),
232
- // Image Generation Process
233
- image_generation_display_status: z.enum(["pending", "building", "complete", "error"]).default("pending"),
234
- image_generation_in_progress: z.boolean().default(false),
235
- image_generation_started_at: z.string().datetime().nullable().optional(),
236
- image_generation_completed_at: z.string().datetime().nullable().optional(),
237
- image_generation_logs: z.array(z.any()).nullable().default(null),
238
- image_generation_is_stale: z.boolean().default(false),
239
- image_generation_error: z.string().nullable().optional(),
240
- image_generation_error_last_updated_at: z.string().datetime().nullable().optional(),
241
- // AI Review
242
- ai_review_text: z.string().nullable().default(null).optional(),
243
- ai_review_started_at: z.string().datetime().nullable().optional(),
244
- ai_review_completed_at: z.string().datetime().nullable().optional(),
245
- ai_review_error: z.any().optional().nullable(),
246
- ai_review_logs: z.array(z.any()).optional().nullable(),
247
- ai_review_requested: z.boolean().default(false),
248
- // Preview
249
- is_pr_preview: z.boolean().default(false),
250
- github_pr_number: z.number().nullable().optional(),
251
- // Latest Build Reference
252
- latest_package_build_id: z.string().nullable().optional(),
253
- branch_name: z.string().nullable().optional(),
254
- commit_message: z.string().nullable().optional(),
255
- commit_author: z.string().nullable().optional(),
256
- // Preview images url
257
- pcb_preview_image_url: z.string().nullable().default(null),
258
- sch_preview_image_url: z.string().nullable().default(null),
259
- cad_preview_image_url: z.string().nullable().default(null)
260
- });
261
- var packageFileSchema = z.object({
262
- package_file_id: z.string(),
263
- package_release_id: z.string(),
264
- file_path: z.string(),
265
- content_text: z.string().nullable().optional(),
266
- created_at: z.string().datetime(),
267
- content_mimetype: z.string().nullable().optional(),
268
- is_release_tarball: z.boolean().optional(),
269
- npm_pack_output: z.any().nullable().optional()
270
- });
271
- var packageSchema = z.object({
272
- package_id: z.string(),
273
- creator_account_id: z.string(),
274
- owner_org_id: z.string(),
275
- owner_github_username: z.string().nullable(),
276
- github_repo_full_name: z.string().nullable(),
277
- name: z.string(),
278
- unscoped_name: z.string(),
279
- description: z.string().nullable(),
280
- created_at: z.string().datetime(),
281
- updated_at: z.string().datetime(),
282
- is_snippet: z.boolean().default(false),
283
- is_board: z.boolean().default(false),
284
- is_package: z.boolean().default(false),
285
- is_model: z.boolean().default(false),
286
- is_footprint: z.boolean().default(false),
287
- is_private: z.boolean().nullable().default(false),
288
- is_public: z.boolean().nullable().default(true),
289
- is_unlisted: z.boolean().nullable().default(false),
290
- is_source_from_github: z.boolean().default(false),
291
- snippet_type: z.enum(["board", "package", "model", "footprint"]).optional(),
292
- latest_package_release_id: z.string().nullable(),
293
- latest_version: z.string().nullable(),
294
- license: z.string().nullable(),
295
- website: z.string().nullable().default(null),
296
- star_count: z.number().default(0),
297
- ai_description: z.string().nullable(),
298
- latest_license: z.string().nullable().optional(),
299
- ai_usage_instructions: z.string().nullable(),
300
- latest_package_release_fs_sha: z.string().nullable().default(null),
301
- default_view: z.enum(["files", "3d", "pcb", "schematic"]).default("files").optional(),
302
- allow_pr_previews: z.boolean().default(false).optional(),
303
- is_starred: z.boolean().default(false).optional(),
304
- latest_pcb_preview_image_url: z.string().nullable().optional(),
305
- latest_sch_preview_image_url: z.string().nullable().optional(),
306
- latest_cad_preview_image_url: z.string().nullable().optional()
307
- });
308
- var jlcpcbOrderStateSchema = z.object({
309
- jlcpcb_order_state_id: z.string(),
310
- order_id: z.string(),
311
- are_gerbers_uploaded: z.boolean().default(false),
312
- is_gerber_analyzed: z.boolean().default(false),
313
- are_initial_costs_calculated: z.boolean().default(false),
314
- is_pcb_added_to_cart: z.boolean().default(false),
315
- is_bom_uploaded: z.boolean().default(false),
316
- is_pnp_uploaded: z.boolean().default(false),
317
- is_bom_pnp_analyzed: z.boolean().default(false),
318
- is_bom_parsing_complete: z.boolean().default(false),
319
- are_components_available: z.boolean().default(false),
320
- is_patch_map_generated: z.boolean().default(false),
321
- is_json_merge_file_created: z.boolean().default(false),
322
- is_dfm_result_generated: z.boolean().default(false),
323
- are_files_downloaded: z.boolean().default(false),
324
- are_product_categories_fetched: z.boolean().default(false),
325
- are_final_costs_calculated: z.boolean().default(false),
326
- is_json_merge_file_updated: z.boolean().default(false),
327
- is_added_to_cart: z.boolean().default(false),
328
- uploaded_gerber_metadata: z.any().nullable().default(null),
329
- gerber_analysis: z.any().nullable().default(null),
330
- created_at: z.string(),
331
- are_gerbers_generated: z.boolean().default(false),
332
- current_step: z.string().nullable().default(null)
333
- });
334
- var jlcpcbOrderStepRunSchema = z.object({
335
- jlcpcb_order_step_run_id: z.string(),
336
- is_running: z.boolean().nullable().default(null),
337
- step_function_name: z.string().nullable().default(null),
338
- jlcpcb_order_state_id: z.string().nullable().default(null),
339
- error_message: z.string().nullable().default(null),
340
- created_at: z.string()
341
- });
342
- var packageBuildSchema = z.object({
343
- package_build_id: z.string().uuid(),
344
- package_release_id: z.string(),
345
- created_at: z.string().datetime(),
346
- transpilation_in_progress: z.boolean().default(false),
347
- transpilation_started_at: z.string().datetime().nullable().optional(),
348
- transpilation_completed_at: z.string().datetime().nullable().optional(),
349
- transpilation_logs: z.array(z.any()).default([]),
350
- transpilation_error: z.string().nullable().optional(),
351
- circuit_json_build_in_progress: z.boolean().default(false),
352
- circuit_json_build_started_at: z.string().datetime().nullable().optional(),
353
- circuit_json_build_completed_at: z.string().datetime().nullable().optional(),
354
- circuit_json_build_logs: z.array(z.any()).default([]),
355
- circuit_json_build_error: z.string().nullable().optional(),
356
- image_generation_in_progress: z.boolean().default(false),
357
- image_generation_started_at: z.string().datetime().nullable().optional(),
358
- image_generation_completed_at: z.string().datetime().nullable().optional(),
359
- image_generation_logs: z.array(z.any()).default([]),
360
- image_generation_error: z.string().nullable().optional(),
361
- build_in_progress: z.boolean().default(false),
362
- build_started_at: z.string().datetime().nullable().optional(),
363
- build_completed_at: z.string().datetime().nullable().optional(),
364
- build_error: z.string().nullable().optional(),
365
- build_error_last_updated_at: z.string().datetime(),
366
- preview_url: z.string().nullable().optional(),
367
- build_logs: z.string().nullable().optional()
368
- });
369
- var orgSchema = z.object({
370
- org_id: z.string(),
371
- github_handle: z.string().optional(),
372
- owner_account_id: z.string(),
373
- is_personal_org: z.boolean().default(false),
374
- created_at: z.string().datetime(),
375
- org_display_name: z.string().optional(),
376
- org_name: z.string()
377
- });
378
- var orgAccountSchema = z.object({
379
- org_account_id: z.string(),
380
- org_id: z.string(),
381
- account_id: z.string(),
382
- is_owner: z.boolean().default(false),
383
- created_at: z.string().datetime()
384
- });
385
- var userPermissionsSchema = z.object({
386
- can_manage_org: z.boolean().optional(),
387
- can_manage_package: z.boolean().optional()
388
- });
389
- var publicOrgSchema = z.object({
390
- org_id: z.string(),
391
- //.uuid(),
392
- owner_account_id: z.string(),
393
- //.uuid(),
394
- name: z.string().nullable(),
395
- member_count: z.number(),
396
- is_personal_org: z.boolean(),
397
- display_name: z.string().optional(),
398
- package_count: z.number(),
399
- github_handle: z.string().optional(),
400
- created_at: z.string(),
401
- user_permissions: userPermissionsSchema.optional()
402
- });
403
- var databaseSchema = z.object({
404
- idCounter: z.number().default(0),
405
- snippets: z.array(snippetSchema).default([]),
406
- packageReleases: z.array(packageReleaseSchema).default([]),
407
- packageFiles: z.array(packageFileSchema).default([]),
408
- sessions: z.array(sessionSchema).default([]),
409
- loginPages: z.array(loginPageSchema).default([]),
410
- accounts: z.array(accountSchema).default([]),
411
- packages: z.array(packageSchema).default([]),
412
- orders: z.array(orderSchema).default([]),
413
- organizations: z.array(orgSchema).default([]),
414
- orgAccounts: z.array(orgAccountSchema).default([]),
415
- orderFiles: z.array(orderFileSchema).default([]),
416
- accountSnippets: z.array(accountSnippetSchema).default([]),
417
- accountPackages: z.array(accountPackageSchema).default([]),
418
- jlcpcbOrderState: z.array(jlcpcbOrderStateSchema).default([]),
419
- jlcpcbOrderStepRuns: z.array(jlcpcbOrderStepRunSchema).default([]),
420
- orderQuotes: z.array(orderQuoteSchema).default([]),
421
- aiReviews: z.array(aiReviewSchema).default([]),
422
- datasheets: z.array(datasheetSchema).default([]),
423
- githubInstallations: z.array(githubInstallationSchema).default([]),
424
- packageBuilds: z.array(packageBuildSchema).default([]),
425
- bugReports: z.array(bugReportSchema).default([]),
426
- bugReportFiles: z.array(bugReportFileSchema).default([])
427
- });
428
-
429
- // fake-snippets-api/lib/db/autoload-dev-packages.ts
430
- import fs from "fs";
431
- import path from "path";
432
- import axios from "redaxios";
433
- var extractTsciDependencies = (code) => {
434
- const regex = /@tsci\/([^.]+)\.([^"'\s]+)/g;
435
- const matches = Array.from(code.matchAll(regex));
436
- return matches.map((match) => ({
437
- owner: match[1],
438
- name: match[2]
439
- }));
440
- };
441
- var registryApi = axios.create({
442
- baseURL: "https://api.tscircuit.com",
443
- headers: {
444
- Accept: "application/json",
445
- "Content-Type": "application/json"
446
- }
447
- });
448
- var fetchPackageFromRegistry = async (owner, name) => {
449
- const fullName = `${owner}/${name}`;
450
- console.log(`[autoload-dev-pkgs] \u{1F4E6} Fetching package ${fullName}...`);
451
- let packageData;
452
- try {
453
- const response = await registryApi.post("/packages/get", {
454
- name: fullName
455
- });
456
- packageData = response.data;
457
- } catch (e) {
458
- console.error(`Failed to fetch package data for ${fullName}:`, e);
459
- throw e;
460
- }
461
- let releaseData;
462
- try {
463
- const response = await registryApi.post("/package_releases/get", {
464
- package_id: packageData.package.package_id,
465
- is_latest: true
466
- });
467
- releaseData = response.data;
468
- } catch (e) {
469
- console.error(
470
- `[autoload-dev-pkgs] \u274C Failed to fetch release data for ${fullName}:`,
471
- e
472
- );
473
- throw e;
474
- }
475
- let filesData;
476
- try {
477
- const response = await registryApi.post(
478
- `package_files/list?package_release_id=${releaseData.package_release.package_release_id}`,
479
- {}
480
- );
481
- filesData = response.data;
482
- for (const file of filesData.package_files) {
483
- try {
484
- const fileResponse = await registryApi.post(
485
- `/package_files/get?package_file_id=${file.package_file_id}`,
486
- {}
487
- );
488
- file.content_text = fileResponse.data.package_file.content_text;
489
- } catch (e) {
490
- console.error(
491
- `[autoload-dev-pkgs] \u274C Failed to fetch content for file ${file.file_path} in package ${fullName}:`,
492
- e
493
- );
494
- throw e;
495
- }
496
- }
497
- } catch (e) {
498
- console.error(
499
- `[autoload-dev-pkgs] \u274C Failed to fetch files data for ${fullName}:`,
500
- e
501
- );
502
- throw e;
503
- }
504
- return {
505
- package: packageData.package,
506
- release: releaseData.package_release,
507
- files: filesData.package_files
508
- };
509
- };
510
- var loadPackageWithDependencies = async (db, owner, name, loadedPackages = /* @__PURE__ */ new Set()) => {
511
- const packageKey = `${owner}/${name}`;
512
- if (loadedPackages.has(packageKey)) {
513
- return true;
514
- }
515
- let result;
516
- try {
517
- result = await fetchPackageFromRegistry(owner, name);
518
- } catch (e) {
519
- console.error(`[autoload-dev-pkgs] \u274C Failed to load ${packageKey}`);
520
- return false;
521
- }
522
- const { package: pkg, release, files } = result;
523
- if (db.getPackageById(pkg.package_id)) {
524
- console.log(`[autoload-dev-pkgs] \u26A1 Package ${packageKey} already exists`);
525
- return true;
526
- }
527
- db.addPackage({
528
- ...pkg,
529
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
530
- updated_at: (/* @__PURE__ */ new Date()).toISOString(),
531
- latest_package_release_id: release.package_release_id,
532
- star_count: Math.floor(Math.random() * 11)
533
- });
534
- db.addPackageRelease({
535
- ...release,
536
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
537
- transpilation_logs: Array.isArray(release.transpilation_logs) ? release.transpilation_logs : [],
538
- circuit_json_build_logs: Array.isArray(release.circuit_json_build_logs) ? release.circuit_json_build_logs : [],
539
- transpilation_display_status: release.transpilation_display_status ?? "pending"
540
- });
541
- for (const file of files) {
542
- db.addPackageFile({
543
- ...file,
544
- created_at: (/* @__PURE__ */ new Date()).toISOString()
545
- });
546
- }
547
- loadedPackages.add(packageKey);
548
- console.log(`[autoload-dev-pkgs] \u{1F4E6} Loaded ${packageKey}`);
549
- const mainFile = files.find(
550
- (f) => f.file_path === "index.tsx" || f.file_path === "index.ts"
551
- );
552
- if (!mainFile?.content_text) {
553
- return true;
554
- }
555
- const dependencies = extractTsciDependencies(mainFile.content_text);
556
- let allDepsLoaded = true;
557
- for (const dep of dependencies) {
558
- const depLoaded = await loadPackageWithDependencies(
559
- db,
560
- dep.owner,
561
- dep.name,
562
- loadedPackages
563
- );
564
- if (!depLoaded) {
565
- allDepsLoaded = false;
566
- console.warn(
567
- `[autoload-dev-pkgs] \u26A0\uFE0F Failed to load dependency ${dep.owner}/${dep.name} for ${packageKey}`
568
- );
569
- }
570
- }
571
- return allDepsLoaded;
572
- };
573
- var loadAutoloadPackages = async (db) => {
574
- const autoloadPath = path.join(
575
- path.dirname(__dirname),
576
- "db",
577
- "autoload-packages.json"
578
- );
579
- if (!fs.existsSync(autoloadPath)) {
580
- console.error("[autoload-dev-pkgs] \u274C No autoload-packages.json found");
581
- return;
582
- }
583
- const autoloadContent = JSON.parse(fs.readFileSync(autoloadPath, "utf8"));
584
- const loadedPackages = /* @__PURE__ */ new Set();
585
- let successCount = 0;
586
- let failureCount = 0;
587
- for (const packageRef of autoloadContent.packages) {
588
- const success = await loadPackageWithDependencies(
589
- db,
590
- packageRef.owner,
591
- packageRef.name,
592
- loadedPackages
593
- );
594
- if (success) {
595
- successCount++;
596
- } else {
597
- failureCount++;
598
- }
599
- }
600
- console.log(`
601
- [autoload-dev-pkgs] \u{1F4CB} Package loading complete:`);
602
- console.log(
603
- `[autoload-dev-pkgs] \u2705 Successfully loaded: ${successCount} packages`
604
- );
605
- if (failureCount > 0) {
606
- console.log(
607
- `[autoload-dev-pkgs] \u274C Failed to load: ${failureCount} packages`
608
- );
609
- }
610
- };
611
-
612
- // fake-snippets-api/lib/db/seed.ts
613
- var seed = (db) => {
614
- const { account_id } = db.addAccount({
615
- account_id: "account-1234",
616
- github_username: "testuser",
617
- shippingInfo: {
618
- firstName: "Test",
619
- lastName: "User",
620
- companyName: "Test Company",
621
- address: "123 Test St",
622
- apartment: "Apt 4B",
623
- city: "Testville",
624
- state: "NY",
625
- zipCode: "10001",
626
- country: "United States of America",
627
- phone: "555-123-4567"
628
- }
629
- });
630
- const seveibarAcc = db.addAccount({
631
- github_username: "seveibar"
632
- });
633
- if (process.env.AUTOLOAD_PACKAGES === "true") {
634
- loadAutoloadPackages(db);
635
- }
636
- const { package_release_id: packageReleaseId1 } = db.addSnippet({
637
- name: "testuser/my-test-board",
638
- unscoped_name: "my-test-board",
639
- github_repo_full_name: "testuser/my-test-board",
640
- owner_name: "testuser",
641
- branch_name: "main",
642
- commit_message: "Attempted build of a555timer-square-wave package",
643
- commit_author: "testuser",
644
- creator_account_id: account_id,
645
- code: `
646
- import { A555Timer } from "@tsci/seveibar.a555timer"
647
-
648
- export default () => (
649
- <board width="10mm" height="10mm">
650
- <A555Timer name="U1" />
651
- </board>
652
- )`.trim(),
653
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
654
- updated_at: (/* @__PURE__ */ new Date()).toISOString(),
655
- snippet_type: "board",
656
- description: "A simple board with an A555 Timer component",
657
- circuit_json: [
658
- {
659
- type: "source_port",
660
- source_port_id: "source_port_0",
661
- name: "pin1",
662
- pin_number: 1,
663
- port_hints: ["pin1", "1"],
664
- source_component_id: "source_component_0"
665
- },
666
- {
667
- type: "source_port",
668
- source_port_id: "source_port_1",
669
- name: "pin2",
670
- pin_number: 2,
671
- port_hints: ["pin2", "2"],
672
- source_component_id: "source_component_0"
673
- },
674
- {
675
- type: "source_port",
676
- source_port_id: "source_port_2",
677
- name: "pin3",
678
- pin_number: 3,
679
- port_hints: ["pin3", "3"],
680
- source_component_id: "source_component_0"
681
- },
682
- {
683
- type: "source_port",
684
- source_port_id: "source_port_3",
685
- name: "pin4",
686
- pin_number: 4,
687
- port_hints: ["pin4", "4"],
688
- source_component_id: "source_component_0"
689
- },
690
- {
691
- type: "source_port",
692
- source_port_id: "source_port_4",
693
- name: "pin5",
694
- pin_number: 5,
695
- port_hints: ["pin5", "5"],
696
- source_component_id: "source_component_0"
697
- },
698
- {
699
- type: "source_port",
700
- source_port_id: "source_port_5",
701
- name: "pin6",
702
- pin_number: 6,
703
- port_hints: ["pin6", "6"],
704
- source_component_id: "source_component_0"
705
- },
706
- {
707
- type: "source_port",
708
- source_port_id: "source_port_6",
709
- name: "pin7",
710
- pin_number: 7,
711
- port_hints: ["pin7", "7"],
712
- source_component_id: "source_component_0"
713
- },
714
- {
715
- type: "source_port",
716
- source_port_id: "source_port_7",
717
- name: "pin8",
718
- pin_number: 8,
719
- port_hints: ["pin8", "8"],
720
- source_component_id: "source_component_0"
721
- },
722
- {
723
- type: "source_component",
724
- source_component_id: "source_component_0",
725
- ftype: "simple_chip",
726
- name: "U1",
727
- supplier_part_numbers: {}
728
- },
729
- {
730
- type: "schematic_component",
731
- schematic_component_id: "schematic_component_0",
732
- center: {
733
- x: 0,
734
- y: 0
735
- },
736
- rotation: 0,
737
- size: {
738
- width: 1.1,
739
- height: 1
740
- },
741
- pin_spacing: 0.2,
742
- port_labels: {},
743
- source_component_id: "source_component_0"
744
- },
745
- {
746
- type: "schematic_port",
747
- schematic_port_id: "schematic_port_0",
748
- schematic_component_id: "schematic_component_0",
749
- center: {
750
- x: -0.9500000000000001,
751
- y: 0.30000000000000004
752
- },
753
- source_port_id: "source_port_0",
754
- facing_direction: "left",
755
- distance_from_component_edge: 0.4,
756
- side_of_component: "left",
757
- pin_number: 1,
758
- true_ccw_index: 0
759
- },
760
- {
761
- type: "schematic_port",
762
- schematic_port_id: "schematic_port_1",
763
- schematic_component_id: "schematic_component_0",
764
- center: {
765
- x: -0.9500000000000001,
766
- y: 0.10000000000000003
767
- },
768
- source_port_id: "source_port_1",
769
- facing_direction: "left",
770
- distance_from_component_edge: 0.4,
771
- side_of_component: "left",
772
- pin_number: 2,
773
- true_ccw_index: 1
774
- },
775
- {
776
- type: "schematic_port",
777
- schematic_port_id: "schematic_port_2",
778
- schematic_component_id: "schematic_component_0",
779
- center: {
780
- x: -0.9500000000000001,
781
- y: -0.09999999999999998
782
- },
783
- source_port_id: "source_port_2",
784
- facing_direction: "left",
785
- distance_from_component_edge: 0.4,
786
- side_of_component: "left",
787
- pin_number: 3,
788
- true_ccw_index: 2
789
- },
790
- {
791
- type: "schematic_port",
792
- schematic_port_id: "schematic_port_3",
793
- schematic_component_id: "schematic_component_0",
794
- center: {
795
- x: -0.9500000000000001,
796
- y: -0.30000000000000004
797
- },
798
- source_port_id: "source_port_3",
799
- facing_direction: "left",
800
- distance_from_component_edge: 0.4,
801
- side_of_component: "left",
802
- pin_number: 4,
803
- true_ccw_index: 3
804
- },
805
- {
806
- type: "schematic_port",
807
- schematic_port_id: "schematic_port_4",
808
- schematic_component_id: "schematic_component_0",
809
- center: {
810
- x: 0.9500000000000001,
811
- y: -0.30000000000000004
812
- },
813
- source_port_id: "source_port_4",
814
- facing_direction: "right",
815
- distance_from_component_edge: 0.4,
816
- side_of_component: "right",
817
- pin_number: 5,
818
- true_ccw_index: 4
819
- },
820
- {
821
- type: "schematic_port",
822
- schematic_port_id: "schematic_port_5",
823
- schematic_component_id: "schematic_component_0",
824
- center: {
825
- x: 0.9500000000000001,
826
- y: -0.10000000000000003
827
- },
828
- source_port_id: "source_port_5",
829
- facing_direction: "right",
830
- distance_from_component_edge: 0.4,
831
- side_of_component: "right",
832
- pin_number: 6,
833
- true_ccw_index: 5
834
- },
835
- {
836
- type: "schematic_port",
837
- schematic_port_id: "schematic_port_6",
838
- schematic_component_id: "schematic_component_0",
839
- center: {
840
- x: 0.9500000000000001,
841
- y: 0.09999999999999998
842
- },
843
- source_port_id: "source_port_6",
844
- facing_direction: "right",
845
- distance_from_component_edge: 0.4,
846
- side_of_component: "right",
847
- pin_number: 7,
848
- true_ccw_index: 6
849
- },
850
- {
851
- type: "schematic_port",
852
- schematic_port_id: "schematic_port_7",
853
- schematic_component_id: "schematic_component_0",
854
- center: {
855
- x: 0.9500000000000001,
856
- y: 0.30000000000000004
857
- },
858
- source_port_id: "source_port_7",
859
- facing_direction: "right",
860
- distance_from_component_edge: 0.4,
861
- side_of_component: "right",
862
- pin_number: 8,
863
- true_ccw_index: 7
864
- },
865
- {
866
- type: "pcb_component",
867
- pcb_component_id: "pcb_component_0",
868
- center: {
869
- x: 0,
870
- y: 0
871
- },
872
- width: 8.82,
873
- height: 8.82,
874
- layer: "top",
875
- rotation: 0,
876
- source_component_id: "source_component_0"
877
- },
878
- {
879
- type: "pcb_board",
880
- pcb_board_id: "pcb_board_0",
881
- center: {
882
- x: 0,
883
- y: 0
884
- },
885
- thickness: 1.4,
886
- num_layers: 4,
887
- width: 10,
888
- height: 10
889
- },
890
- {
891
- type: "pcb_plated_hole",
892
- pcb_plated_hole_id: "pcb_plated_hole_0",
893
- pcb_component_id: "pcb_component_0",
894
- pcb_port_id: "pcb_port_0",
895
- outer_diameter: 1.2,
896
- hole_diameter: 1,
897
- shape: "circle",
898
- port_hints: ["1"],
899
- x: -3.81,
900
- y: 3.81,
901
- layers: ["top", "bottom"]
902
- },
903
- {
904
- type: "pcb_plated_hole",
905
- pcb_plated_hole_id: "pcb_plated_hole_1",
906
- pcb_component_id: "pcb_component_0",
907
- pcb_port_id: "pcb_port_1",
908
- outer_diameter: 1.2,
909
- hole_diameter: 1,
910
- shape: "circle",
911
- port_hints: ["2"],
912
- x: -3.81,
913
- y: 1.27,
914
- layers: ["top", "bottom"]
915
- },
916
- {
917
- type: "pcb_plated_hole",
918
- pcb_plated_hole_id: "pcb_plated_hole_2",
919
- pcb_component_id: "pcb_component_0",
920
- pcb_port_id: "pcb_port_2",
921
- outer_diameter: 1.2,
922
- hole_diameter: 1,
923
- shape: "circle",
924
- port_hints: ["3"],
925
- x: -3.81,
926
- y: -1.27,
927
- layers: ["top", "bottom"]
928
- },
929
- {
930
- type: "pcb_plated_hole",
931
- pcb_plated_hole_id: "pcb_plated_hole_3",
932
- pcb_component_id: "pcb_component_0",
933
- pcb_port_id: "pcb_port_3",
934
- outer_diameter: 1.2,
935
- hole_diameter: 1,
936
- shape: "circle",
937
- port_hints: ["4"],
938
- x: -3.81,
939
- y: -3.81,
940
- layers: ["top", "bottom"]
941
- },
942
- {
943
- type: "pcb_plated_hole",
944
- pcb_plated_hole_id: "pcb_plated_hole_4",
945
- pcb_component_id: "pcb_component_0",
946
- pcb_port_id: "pcb_port_4",
947
- outer_diameter: 1.2,
948
- hole_diameter: 1,
949
- shape: "circle",
950
- port_hints: ["5"],
951
- x: 3.81,
952
- y: -3.81,
953
- layers: ["top", "bottom"]
954
- },
955
- {
956
- type: "pcb_plated_hole",
957
- pcb_plated_hole_id: "pcb_plated_hole_5",
958
- pcb_component_id: "pcb_component_0",
959
- pcb_port_id: "pcb_port_5",
960
- outer_diameter: 1.2,
961
- hole_diameter: 1,
962
- shape: "circle",
963
- port_hints: ["6"],
964
- x: 3.81,
965
- y: -1.27,
966
- layers: ["top", "bottom"]
967
- },
968
- {
969
- type: "pcb_plated_hole",
970
- pcb_plated_hole_id: "pcb_plated_hole_6",
971
- pcb_component_id: "pcb_component_0",
972
- pcb_port_id: "pcb_port_6",
973
- outer_diameter: 1.2,
974
- hole_diameter: 1,
975
- shape: "circle",
976
- port_hints: ["7"],
977
- x: 3.81,
978
- y: 1.27,
979
- layers: ["top", "bottom"]
980
- },
981
- {
982
- type: "pcb_plated_hole",
983
- pcb_plated_hole_id: "pcb_plated_hole_7",
984
- pcb_component_id: "pcb_component_0",
985
- pcb_port_id: "pcb_port_7",
986
- outer_diameter: 1.2,
987
- hole_diameter: 1,
988
- shape: "circle",
989
- port_hints: ["8"],
990
- x: 3.81,
991
- y: 3.81,
992
- layers: ["top", "bottom"]
993
- },
994
- {
995
- type: "pcb_silkscreen_path",
996
- pcb_silkscreen_path_id: "pcb_silkscreen_path_0",
997
- pcb_component_id: "pcb_component_0",
998
- layer: "top",
999
- route: [
1000
- {
1001
- x: -3.01,
1002
- y: -4.61
1003
- },
1004
- {
1005
- x: -3.01,
1006
- y: 4.61
1007
- },
1008
- {
1009
- x: -1.0033333333333332,
1010
- y: 4.61
1011
- },
1012
- {
1013
- x: -0.9269591309529909,
1014
- y: 4.226040956193693
1015
- },
1016
- {
1017
- x: -0.7094638037905026,
1018
- y: 3.9005361962094978
1019
- },
1020
- {
1021
- x: -0.3839590438063067,
1022
- y: 3.6830408690470096
1023
- },
1024
- {
1025
- x: 6143644775722556e-32,
1026
- y: 3.6066666666666674
1027
- },
1028
- {
1029
- x: 0.38395904380630674,
1030
- y: 3.6830408690470096
1031
- },
1032
- {
1033
- x: 0.7094638037905027,
1034
- y: 3.9005361962094978
1035
- },
1036
- {
1037
- x: 0.9269591309529909,
1038
- y: 4.226040956193693
1039
- },
1040
- {
1041
- x: 1.0033333333333332,
1042
- y: 4.61
1043
- },
1044
- {
1045
- x: 3.01,
1046
- y: 4.61
1047
- },
1048
- {
1049
- x: 3.01,
1050
- y: -4.61
1051
- },
1052
- {
1053
- x: -3.01,
1054
- y: -4.61
1055
- }
1056
- ],
1057
- stroke_width: 0.1
1058
- },
1059
- {
1060
- type: "pcb_port",
1061
- pcb_port_id: "pcb_port_0",
1062
- pcb_component_id: "pcb_component_0",
1063
- layers: ["top", "inner1", "inner2", "bottom"],
1064
- x: -3.81,
1065
- y: 3.81,
1066
- source_port_id: "source_port_0"
1067
- },
1068
- {
1069
- type: "pcb_port",
1070
- pcb_port_id: "pcb_port_1",
1071
- pcb_component_id: "pcb_component_0",
1072
- layers: ["top", "inner1", "inner2", "bottom"],
1073
- x: -3.81,
1074
- y: 1.27,
1075
- source_port_id: "source_port_1"
1076
- },
1077
- {
1078
- type: "pcb_port",
1079
- pcb_port_id: "pcb_port_2",
1080
- pcb_component_id: "pcb_component_0",
1081
- layers: ["top", "inner1", "inner2", "bottom"],
1082
- x: -3.81,
1083
- y: -1.27,
1084
- source_port_id: "source_port_2"
1085
- },
1086
- {
1087
- type: "pcb_port",
1088
- pcb_port_id: "pcb_port_3",
1089
- pcb_component_id: "pcb_component_0",
1090
- layers: ["top", "inner1", "inner2", "bottom"],
1091
- x: -3.81,
1092
- y: -3.81,
1093
- source_port_id: "source_port_3"
1094
- },
1095
- {
1096
- type: "pcb_port",
1097
- pcb_port_id: "pcb_port_4",
1098
- pcb_component_id: "pcb_component_0",
1099
- layers: ["top", "inner1", "inner2", "bottom"],
1100
- x: 3.81,
1101
- y: -3.81,
1102
- source_port_id: "source_port_4"
1103
- },
1104
- {
1105
- type: "pcb_port",
1106
- pcb_port_id: "pcb_port_5",
1107
- pcb_component_id: "pcb_component_0",
1108
- layers: ["top", "inner1", "inner2", "bottom"],
1109
- x: 3.81,
1110
- y: -1.27,
1111
- source_port_id: "source_port_5"
1112
- },
1113
- {
1114
- type: "pcb_port",
1115
- pcb_port_id: "pcb_port_6",
1116
- pcb_component_id: "pcb_component_0",
1117
- layers: ["top", "inner1", "inner2", "bottom"],
1118
- x: 3.81,
1119
- y: 1.27,
1120
- source_port_id: "source_port_6"
1121
- },
1122
- {
1123
- type: "pcb_port",
1124
- pcb_port_id: "pcb_port_7",
1125
- pcb_component_id: "pcb_component_0",
1126
- layers: ["top", "inner1", "inner2", "bottom"],
1127
- x: 3.81,
1128
- y: 3.81,
1129
- source_port_id: "source_port_7"
1130
- },
1131
- {
1132
- type: "cad_component",
1133
- cad_component_id: "cad_component_0",
1134
- position: {
1135
- x: 0,
1136
- y: 0,
1137
- z: 0.7
1138
- },
1139
- rotation: {
1140
- x: 0,
1141
- y: 0,
1142
- z: 0
1143
- },
1144
- pcb_component_id: "pcb_component_0",
1145
- source_component_id: "source_component_0",
1146
- footprinter_string: "dip8"
1147
- }
1148
- ]
1149
- });
1150
- const firstBuild = db.addPackageBuild({
1151
- package_release_id: packageReleaseId1,
1152
- created_at: new Date(Date.now() - 15e3).toISOString(),
1153
- // 15 seconds ago
1154
- transpilation_in_progress: false,
1155
- transpilation_started_at: new Date(Date.now() - 15e3).toISOString(),
1156
- transpilation_completed_at: new Date(Date.now() - 14e3).toISOString(),
1157
- transpilation_logs: [
1158
- "[INFO] Starting transpilation...",
1159
- "[INFO] Parsing package code",
1160
- "[ERROR] Failed to parse TypeScript definitions",
1161
- "[ERROR] Invalid syntax in component declaration"
1162
- ],
1163
- transpilation_error: "TypeScript compilation failed: Syntax error in component declaration",
1164
- circuit_json_build_in_progress: false,
1165
- circuit_json_build_started_at: null,
1166
- circuit_json_build_completed_at: null,
1167
- circuit_json_build_logs: [],
1168
- circuit_json_build_error: "Build cancelled due to transpilation failure",
1169
- build_in_progress: false,
1170
- build_started_at: new Date(Date.now() - 15e3).toISOString(),
1171
- build_completed_at: new Date(Date.now() - 14e3).toISOString(),
1172
- build_error: "Build failed: Unable to complete transpilation step",
1173
- build_error_last_updated_at: new Date(Date.now() - 14e3).toISOString(),
1174
- preview_url: null,
1175
- build_logs: "Build process:\n1. Environment setup - OK\n2. Dependency resolution - OK\n3. Code compilation - FAILED\nError: Invalid syntax in component declaration\nBuild terminated with errors"
1176
- });
1177
- const release1 = db.getPackageReleaseById(packageReleaseId1);
1178
- db.updatePackageRelease({
1179
- ...release1,
1180
- latest_package_build_id: firstBuild.package_build_id
1181
- });
1182
- db.addSnippet({
1183
- name: "seveibar/a555timer",
1184
- unscoped_name: "a555timer",
1185
- owner_name: "seveibar",
1186
- code: `
1187
- export const A555Timer = ({ name }: { name: string }) => (
1188
- <chip name={name} footprint="dip8" />
1189
- )
1190
- `.trim(),
1191
- dts: `
1192
- declare module "@tsci/seveibar.a555timer" {
1193
- export const A555Timer: ({ name }: {
1194
- name: string;
1195
- }) => any;
1196
- }
1197
- `.trim(),
1198
- compiled_js: `
1199
- "use strict";
1200
-
1201
- Object.defineProperty(exports, "__esModule", {
1202
- value: true
1203
- });
1204
- exports.A555Timer = void 0;
1205
- const A555Timer = ({
1206
- name
1207
- }) => /*#__PURE__*/React.createElement("chip", {
1208
- name: name,
1209
- footprint: "dip8"
1210
- });
1211
- exports.A555Timer = A555Timer;
1212
- `.trim(),
1213
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
1214
- updated_at: (/* @__PURE__ */ new Date()).toISOString(),
1215
- snippet_type: "package",
1216
- description: "A simple package with an A555 Timer component",
1217
- circuit_json: [
1218
- {
1219
- type: "source_port",
1220
- source_port_id: "source_port_0",
1221
- name: "pin1",
1222
- pin_number: 1,
1223
- port_hints: ["pin1", "1"],
1224
- source_component_id: "source_component_0"
1225
- },
1226
- {
1227
- type: "source_port",
1228
- source_port_id: "source_port_1",
1229
- name: "pin2",
1230
- pin_number: 2,
1231
- port_hints: ["pin2", "2"],
1232
- source_component_id: "source_component_0"
1233
- },
1234
- {
1235
- type: "source_port",
1236
- source_port_id: "source_port_2",
1237
- name: "pin3",
1238
- pin_number: 3,
1239
- port_hints: ["pin3", "3"],
1240
- source_component_id: "source_component_0"
1241
- },
1242
- {
1243
- type: "source_port",
1244
- source_port_id: "source_port_3",
1245
- name: "pin4",
1246
- pin_number: 4,
1247
- port_hints: ["pin4", "4"],
1248
- source_component_id: "source_component_0"
1249
- },
1250
- {
1251
- type: "source_port",
1252
- source_port_id: "source_port_4",
1253
- name: "pin5",
1254
- pin_number: 5,
1255
- port_hints: ["pin5", "5"],
1256
- source_component_id: "source_component_0"
1257
- },
1258
- {
1259
- type: "source_port",
1260
- source_port_id: "source_port_5",
1261
- name: "pin6",
1262
- pin_number: 6,
1263
- port_hints: ["pin6", "6"],
1264
- source_component_id: "source_component_0"
1265
- },
1266
- {
1267
- type: "source_port",
1268
- source_port_id: "source_port_6",
1269
- name: "pin7",
1270
- pin_number: 7,
1271
- port_hints: ["pin7", "7"],
1272
- source_component_id: "source_component_0"
1273
- },
1274
- {
1275
- type: "source_port",
1276
- source_port_id: "source_port_7",
1277
- name: "pin8",
1278
- pin_number: 8,
1279
- port_hints: ["pin8", "8"],
1280
- source_component_id: "source_component_0"
1281
- },
1282
- {
1283
- type: "source_component",
1284
- source_component_id: "source_component_0",
1285
- ftype: "simple_chip",
1286
- name: "U1"
1287
- },
1288
- {
1289
- type: "schematic_component",
1290
- schematic_component_id: "schematic_component_0",
1291
- center: {
1292
- x: 0,
1293
- y: 0
1294
- },
1295
- rotation: 0,
1296
- size: {
1297
- width: 1.1,
1298
- height: 1
1299
- },
1300
- pin_spacing: 0.2,
1301
- port_labels: {},
1302
- source_component_id: "source_component_0"
1303
- },
1304
- {
1305
- type: "schematic_port",
1306
- schematic_port_id: "schematic_port_0",
1307
- schematic_component_id: "schematic_component_0",
1308
- center: {
1309
- x: -0.9500000000000001,
1310
- y: 0.30000000000000004
1311
- },
1312
- source_port_id: "source_port_0",
1313
- facing_direction: "left",
1314
- distance_from_component_edge: 0.4,
1315
- side_of_component: "left",
1316
- pin_number: 1,
1317
- true_ccw_index: 0
1318
- },
1319
- {
1320
- type: "schematic_port",
1321
- schematic_port_id: "schematic_port_1",
1322
- schematic_component_id: "schematic_component_0",
1323
- center: {
1324
- x: -0.9500000000000001,
1325
- y: 0.10000000000000003
1326
- },
1327
- source_port_id: "source_port_1",
1328
- facing_direction: "left",
1329
- distance_from_component_edge: 0.4,
1330
- side_of_component: "left",
1331
- pin_number: 2,
1332
- true_ccw_index: 1
1333
- },
1334
- {
1335
- type: "schematic_port",
1336
- schematic_port_id: "schematic_port_2",
1337
- schematic_component_id: "schematic_component_0",
1338
- center: {
1339
- x: -0.9500000000000001,
1340
- y: -0.09999999999999998
1341
- },
1342
- source_port_id: "source_port_2",
1343
- facing_direction: "left",
1344
- distance_from_component_edge: 0.4,
1345
- side_of_component: "left",
1346
- pin_number: 3,
1347
- true_ccw_index: 2
1348
- },
1349
- {
1350
- type: "schematic_port",
1351
- schematic_port_id: "schematic_port_3",
1352
- schematic_component_id: "schematic_component_0",
1353
- center: {
1354
- x: -0.9500000000000001,
1355
- y: -0.30000000000000004
1356
- },
1357
- source_port_id: "source_port_3",
1358
- facing_direction: "left",
1359
- distance_from_component_edge: 0.4,
1360
- side_of_component: "left",
1361
- pin_number: 4,
1362
- true_ccw_index: 3
1363
- },
1364
- {
1365
- type: "schematic_port",
1366
- schematic_port_id: "schematic_port_4",
1367
- schematic_component_id: "schematic_component_0",
1368
- center: {
1369
- x: 0.9500000000000001,
1370
- y: -0.30000000000000004
1371
- },
1372
- source_port_id: "source_port_4",
1373
- facing_direction: "right",
1374
- distance_from_component_edge: 0.4,
1375
- side_of_component: "right",
1376
- pin_number: 5,
1377
- true_ccw_index: 4
1378
- },
1379
- {
1380
- type: "schematic_port",
1381
- schematic_port_id: "schematic_port_5",
1382
- schematic_component_id: "schematic_component_0",
1383
- center: {
1384
- x: 0.9500000000000001,
1385
- y: -0.10000000000000003
1386
- },
1387
- source_port_id: "source_port_5",
1388
- facing_direction: "right",
1389
- distance_from_component_edge: 0.4,
1390
- side_of_component: "right",
1391
- pin_number: 6,
1392
- true_ccw_index: 5
1393
- },
1394
- {
1395
- type: "schematic_port",
1396
- schematic_port_id: "schematic_port_6",
1397
- schematic_component_id: "schematic_component_0",
1398
- center: {
1399
- x: 0.9500000000000001,
1400
- y: 0.09999999999999998
1401
- },
1402
- source_port_id: "source_port_6",
1403
- facing_direction: "right",
1404
- distance_from_component_edge: 0.4,
1405
- side_of_component: "right",
1406
- pin_number: 7,
1407
- true_ccw_index: 6
1408
- },
1409
- {
1410
- type: "schematic_port",
1411
- schematic_port_id: "schematic_port_7",
1412
- schematic_component_id: "schematic_component_0",
1413
- center: {
1414
- x: 0.9500000000000001,
1415
- y: 0.30000000000000004
1416
- },
1417
- source_port_id: "source_port_7",
1418
- facing_direction: "right",
1419
- distance_from_component_edge: 0.4,
1420
- side_of_component: "right",
1421
- pin_number: 8,
1422
- true_ccw_index: 7
1423
- },
1424
- {
1425
- type: "pcb_component",
1426
- pcb_component_id: "pcb_component_0",
1427
- center: {
1428
- x: 0,
1429
- y: 0
1430
- },
1431
- width: 8.82,
1432
- height: 8.82,
1433
- layer: "top",
1434
- rotation: 0,
1435
- source_component_id: "source_component_0"
1436
- },
1437
- {
1438
- type: "pcb_board",
1439
- pcb_board_id: "pcb_board_0",
1440
- center: {
1441
- x: 0,
1442
- y: 0
1443
- },
1444
- thickness: 1.4,
1445
- num_layers: 4,
1446
- width: 50,
1447
- height: 50
1448
- },
1449
- {
1450
- type: "pcb_plated_hole",
1451
- pcb_plated_hole_id: "pcb_plated_hole_0",
1452
- pcb_component_id: "pcb_component_0",
1453
- pcb_port_id: "pcb_port_0",
1454
- outer_diameter: 1.2,
1455
- hole_diameter: 1,
1456
- shape: "circle",
1457
- port_hints: ["1"],
1458
- x: -3.81,
1459
- y: 3.81,
1460
- layers: ["top", "bottom"]
1461
- },
1462
- {
1463
- type: "pcb_plated_hole",
1464
- pcb_plated_hole_id: "pcb_plated_hole_1",
1465
- pcb_component_id: "pcb_component_0",
1466
- pcb_port_id: "pcb_port_1",
1467
- outer_diameter: 1.2,
1468
- hole_diameter: 1,
1469
- shape: "circle",
1470
- port_hints: ["2"],
1471
- x: -3.81,
1472
- y: 1.27,
1473
- layers: ["top", "bottom"]
1474
- },
1475
- {
1476
- type: "pcb_plated_hole",
1477
- pcb_plated_hole_id: "pcb_plated_hole_2",
1478
- pcb_component_id: "pcb_component_0",
1479
- pcb_port_id: "pcb_port_2",
1480
- outer_diameter: 1.2,
1481
- hole_diameter: 1,
1482
- shape: "circle",
1483
- port_hints: ["3"],
1484
- x: -3.81,
1485
- y: -1.27,
1486
- layers: ["top", "bottom"]
1487
- },
1488
- {
1489
- type: "pcb_plated_hole",
1490
- pcb_plated_hole_id: "pcb_plated_hole_3",
1491
- pcb_component_id: "pcb_component_0",
1492
- pcb_port_id: "pcb_port_3",
1493
- outer_diameter: 1.2,
1494
- hole_diameter: 1,
1495
- shape: "circle",
1496
- port_hints: ["4"],
1497
- x: -3.81,
1498
- y: -3.81,
1499
- layers: ["top", "bottom"]
1500
- },
1501
- {
1502
- type: "pcb_plated_hole",
1503
- pcb_plated_hole_id: "pcb_plated_hole_4",
1504
- pcb_component_id: "pcb_component_0",
1505
- pcb_port_id: "pcb_port_4",
1506
- outer_diameter: 1.2,
1507
- hole_diameter: 1,
1508
- shape: "circle",
1509
- port_hints: ["5"],
1510
- x: 3.81,
1511
- y: -3.81,
1512
- layers: ["top", "bottom"]
1513
- },
1514
- {
1515
- type: "pcb_plated_hole",
1516
- pcb_plated_hole_id: "pcb_plated_hole_5",
1517
- pcb_component_id: "pcb_component_0",
1518
- pcb_port_id: "pcb_port_5",
1519
- outer_diameter: 1.2,
1520
- hole_diameter: 1,
1521
- shape: "circle",
1522
- port_hints: ["6"],
1523
- x: 3.81,
1524
- y: -1.27,
1525
- layers: ["top", "bottom"]
1526
- },
1527
- {
1528
- type: "pcb_plated_hole",
1529
- pcb_plated_hole_id: "pcb_plated_hole_6",
1530
- pcb_component_id: "pcb_component_0",
1531
- pcb_port_id: "pcb_port_6",
1532
- outer_diameter: 1.2,
1533
- hole_diameter: 1,
1534
- shape: "circle",
1535
- port_hints: ["7"],
1536
- x: 3.81,
1537
- y: 1.27,
1538
- layers: ["top", "bottom"]
1539
- },
1540
- {
1541
- type: "pcb_plated_hole",
1542
- pcb_plated_hole_id: "pcb_plated_hole_7",
1543
- pcb_component_id: "pcb_component_0",
1544
- pcb_port_id: "pcb_port_7",
1545
- outer_diameter: 1.2,
1546
- hole_diameter: 1,
1547
- shape: "circle",
1548
- port_hints: ["8"],
1549
- x: 3.81,
1550
- y: 3.81,
1551
- layers: ["top", "bottom"]
1552
- },
1553
- {
1554
- type: "pcb_silkscreen_path",
1555
- pcb_silkscreen_path_id: "pcb_silkscreen_path_0",
1556
- pcb_component_id: "pcb_component_0",
1557
- layer: "top",
1558
- route: [
1559
- {
1560
- x: -3.01,
1561
- y: -4.61
1562
- },
1563
- {
1564
- x: -3.01,
1565
- y: 4.61
1566
- },
1567
- {
1568
- x: -1.0033333333333332,
1569
- y: 4.61
1570
- },
1571
- {
1572
- x: -0.9269591309529909,
1573
- y: 4.226040956193693
1574
- },
1575
- {
1576
- x: -0.7094638037905026,
1577
- y: 3.9005361962094978
1578
- },
1579
- {
1580
- x: -0.3839590438063067,
1581
- y: 3.6830408690470096
1582
- },
1583
- {
1584
- x: 6143644775722556e-32,
1585
- y: 3.6066666666666674
1586
- },
1587
- {
1588
- x: 0.38395904380630674,
1589
- y: 3.6830408690470096
1590
- },
1591
- {
1592
- x: 0.7094638037905027,
1593
- y: 3.9005361962094978
1594
- },
1595
- {
1596
- x: 0.9269591309529909,
1597
- y: 4.226040956193693
1598
- },
1599
- {
1600
- x: 1.0033333333333332,
1601
- y: 4.61
1602
- },
1603
- {
1604
- x: 3.01,
1605
- y: 4.61
1606
- },
1607
- {
1608
- x: 3.01,
1609
- y: -4.61
1610
- },
1611
- {
1612
- x: -3.01,
1613
- y: -4.61
1614
- }
1615
- ],
1616
- stroke_width: 0.1
1617
- },
1618
- {
1619
- type: "pcb_port",
1620
- pcb_port_id: "pcb_port_0",
1621
- pcb_component_id: "pcb_component_0",
1622
- layers: ["top", "inner1", "inner2", "bottom"],
1623
- x: -3.81,
1624
- y: 3.81,
1625
- source_port_id: "source_port_0"
1626
- },
1627
- {
1628
- type: "pcb_port",
1629
- pcb_port_id: "pcb_port_1",
1630
- pcb_component_id: "pcb_component_0",
1631
- layers: ["top", "inner1", "inner2", "bottom"],
1632
- x: -3.81,
1633
- y: 1.27,
1634
- source_port_id: "source_port_1"
1635
- },
1636
- {
1637
- type: "pcb_port",
1638
- pcb_port_id: "pcb_port_2",
1639
- pcb_component_id: "pcb_component_0",
1640
- layers: ["top", "inner1", "inner2", "bottom"],
1641
- x: -3.81,
1642
- y: -1.27,
1643
- source_port_id: "source_port_2"
1644
- },
1645
- {
1646
- type: "pcb_port",
1647
- pcb_port_id: "pcb_port_3",
1648
- pcb_component_id: "pcb_component_0",
1649
- layers: ["top", "inner1", "inner2", "bottom"],
1650
- x: -3.81,
1651
- y: -3.81,
1652
- source_port_id: "source_port_3"
1653
- },
1654
- {
1655
- type: "pcb_port",
1656
- pcb_port_id: "pcb_port_4",
1657
- pcb_component_id: "pcb_component_0",
1658
- layers: ["top", "inner1", "inner2", "bottom"],
1659
- x: 3.81,
1660
- y: -3.81,
1661
- source_port_id: "source_port_4"
1662
- },
1663
- {
1664
- type: "pcb_port",
1665
- pcb_port_id: "pcb_port_5",
1666
- pcb_component_id: "pcb_component_0",
1667
- layers: ["top", "inner1", "inner2", "bottom"],
1668
- x: 3.81,
1669
- y: -1.27,
1670
- source_port_id: "source_port_5"
1671
- },
1672
- {
1673
- type: "pcb_port",
1674
- pcb_port_id: "pcb_port_6",
1675
- pcb_component_id: "pcb_component_0",
1676
- layers: ["top", "inner1", "inner2", "bottom"],
1677
- x: 3.81,
1678
- y: 1.27,
1679
- source_port_id: "source_port_6"
1680
- },
1681
- {
1682
- type: "pcb_port",
1683
- pcb_port_id: "pcb_port_7",
1684
- pcb_component_id: "pcb_component_0",
1685
- layers: ["top", "inner1", "inner2", "bottom"],
1686
- x: 3.81,
1687
- y: 3.81,
1688
- source_port_id: "source_port_7"
1689
- },
1690
- {
1691
- type: "cad_component",
1692
- cad_component_id: "cad_component_0",
1693
- position: {
1694
- x: 0,
1695
- y: 0,
1696
- z: 0.7
1697
- },
1698
- rotation: {
1699
- x: 0,
1700
- y: 0,
1701
- z: 0
1702
- },
1703
- pcb_component_id: "pcb_component_0",
1704
- source_component_id: "source_component_0",
1705
- footprinter_string: "dip8"
1706
- }
1707
- ]
1708
- });
1709
- const { package_release_id: packageReleaseId2 } = db.addSnippet({
1710
- name: "testuser/a555timer-square-wave",
1711
- unscoped_name: "a555timer-square-wave",
1712
- owner_name: "testuser",
1713
- branch_name: "main",
1714
- commit_message: "Attempted build of a555timer-square-wave package",
1715
- commit_author: "testuser",
1716
- creator_account_id: account_id,
1717
- code: `
1718
- import { A555Timer } from "@tsci/seveibar.a555timer"
1719
-
1720
- export const SquareWaveModule = () => (
1721
- <A555Timer name="U1" />
1722
- )
1723
- `.trim(),
1724
- dts: 'export declare const SquareWaveModule: () => import("react/jsx-runtime").JSX.Element;\n',
1725
- compiled_js: '"use strict";\n\nObject.defineProperty(exports, "__esModule", {\n value: true\n});\nexports.SquareWaveModule = void 0;\nvar _seveibar = require("@tsci/seveibar.a555timer");\nconst SquareWaveModule = () => /*#__PURE__*/React.createElement(_seveibar.A555Timer, {\n name: "U1"\n});\nexports.SquareWaveModule = SquareWaveModule;',
1726
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
1727
- updated_at: (/* @__PURE__ */ new Date()).toISOString(),
1728
- snippet_type: "package",
1729
- github_repo_full_name: "testuser/test",
1730
- description: "A simple package that outputs a square waveform using the a555timer",
1731
- circuit_json: [
1732
- {
1733
- type: "source_port",
1734
- source_port_id: "source_port_0",
1735
- name: "pin1",
1736
- pin_number: 1,
1737
- port_hints: ["pin1", "1"],
1738
- source_component_id: "source_component_0"
1739
- },
1740
- {
1741
- type: "source_port",
1742
- source_port_id: "source_port_1",
1743
- name: "pin2",
1744
- pin_number: 2,
1745
- port_hints: ["pin2", "2"],
1746
- source_component_id: "source_component_0"
1747
- },
1748
- {
1749
- type: "source_port",
1750
- source_port_id: "source_port_2",
1751
- name: "pin3",
1752
- pin_number: 3,
1753
- port_hints: ["pin3", "3"],
1754
- source_component_id: "source_component_0"
1755
- },
1756
- {
1757
- type: "source_port",
1758
- source_port_id: "source_port_3",
1759
- name: "pin4",
1760
- pin_number: 4,
1761
- port_hints: ["pin4", "4"],
1762
- source_component_id: "source_component_0"
1763
- },
1764
- {
1765
- type: "source_port",
1766
- source_port_id: "source_port_4",
1767
- name: "pin5",
1768
- pin_number: 5,
1769
- port_hints: ["pin5", "5"],
1770
- source_component_id: "source_component_0"
1771
- },
1772
- {
1773
- type: "source_port",
1774
- source_port_id: "source_port_5",
1775
- name: "pin6",
1776
- pin_number: 6,
1777
- port_hints: ["pin6", "6"],
1778
- source_component_id: "source_component_0"
1779
- },
1780
- {
1781
- type: "source_port",
1782
- source_port_id: "source_port_6",
1783
- name: "pin7",
1784
- pin_number: 7,
1785
- port_hints: ["pin7", "7"],
1786
- source_component_id: "source_component_0"
1787
- },
1788
- {
1789
- type: "source_port",
1790
- source_port_id: "source_port_7",
1791
- name: "pin8",
1792
- pin_number: 8,
1793
- port_hints: ["pin8", "8"],
1794
- source_component_id: "source_component_0"
1795
- },
1796
- {
1797
- type: "source_component",
1798
- source_component_id: "source_component_0",
1799
- ftype: "simple_chip",
1800
- name: "U1"
1801
- },
1802
- {
1803
- type: "schematic_component",
1804
- schematic_component_id: "schematic_component_0",
1805
- center: {
1806
- x: 0,
1807
- y: 0
1808
- },
1809
- rotation: 0,
1810
- size: {
1811
- width: 1.1,
1812
- height: 1
1813
- },
1814
- pin_spacing: 0.2,
1815
- port_labels: {},
1816
- source_component_id: "source_component_0"
1817
- },
1818
- {
1819
- type: "schematic_port",
1820
- schematic_port_id: "schematic_port_0",
1821
- schematic_component_id: "schematic_component_0",
1822
- center: {
1823
- x: -0.9500000000000001,
1824
- y: 0.30000000000000004
1825
- },
1826
- source_port_id: "source_port_0",
1827
- facing_direction: "left",
1828
- distance_from_component_edge: 0.4,
1829
- side_of_component: "left",
1830
- pin_number: 1,
1831
- true_ccw_index: 0
1832
- },
1833
- {
1834
- type: "schematic_port",
1835
- schematic_port_id: "schematic_port_1",
1836
- schematic_component_id: "schematic_component_0",
1837
- center: {
1838
- x: -0.9500000000000001,
1839
- y: 0.10000000000000003
1840
- },
1841
- source_port_id: "source_port_1",
1842
- facing_direction: "left",
1843
- distance_from_component_edge: 0.4,
1844
- side_of_component: "left",
1845
- pin_number: 2,
1846
- true_ccw_index: 1
1847
- },
1848
- {
1849
- type: "schematic_port",
1850
- schematic_port_id: "schematic_port_2",
1851
- schematic_component_id: "schematic_component_0",
1852
- center: {
1853
- x: -0.9500000000000001,
1854
- y: -0.09999999999999998
1855
- },
1856
- source_port_id: "source_port_2",
1857
- facing_direction: "left",
1858
- distance_from_component_edge: 0.4,
1859
- side_of_component: "left",
1860
- pin_number: 3,
1861
- true_ccw_index: 2
1862
- },
1863
- {
1864
- type: "schematic_port",
1865
- schematic_port_id: "schematic_port_3",
1866
- schematic_component_id: "schematic_component_0",
1867
- center: {
1868
- x: -0.9500000000000001,
1869
- y: -0.30000000000000004
1870
- },
1871
- source_port_id: "source_port_3",
1872
- facing_direction: "left",
1873
- distance_from_component_edge: 0.4,
1874
- side_of_component: "left",
1875
- pin_number: 4,
1876
- true_ccw_index: 3
1877
- },
1878
- {
1879
- type: "schematic_port",
1880
- schematic_port_id: "schematic_port_4",
1881
- schematic_component_id: "schematic_component_0",
1882
- center: {
1883
- x: 0.9500000000000001,
1884
- y: -0.30000000000000004
1885
- },
1886
- source_port_id: "source_port_4",
1887
- facing_direction: "right",
1888
- distance_from_component_edge: 0.4,
1889
- side_of_component: "right",
1890
- pin_number: 5,
1891
- true_ccw_index: 4
1892
- },
1893
- {
1894
- type: "schematic_port",
1895
- schematic_port_id: "schematic_port_5",
1896
- schematic_component_id: "schematic_component_0",
1897
- center: {
1898
- x: 0.9500000000000001,
1899
- y: -0.10000000000000003
1900
- },
1901
- source_port_id: "source_port_5",
1902
- facing_direction: "right",
1903
- distance_from_component_edge: 0.4,
1904
- side_of_component: "right",
1905
- pin_number: 6,
1906
- true_ccw_index: 5
1907
- },
1908
- {
1909
- type: "schematic_port",
1910
- schematic_port_id: "schematic_port_6",
1911
- schematic_component_id: "schematic_component_0",
1912
- center: {
1913
- x: 0.9500000000000001,
1914
- y: 0.09999999999999998
1915
- },
1916
- source_port_id: "source_port_6",
1917
- facing_direction: "right",
1918
- distance_from_component_edge: 0.4,
1919
- side_of_component: "right",
1920
- pin_number: 7,
1921
- true_ccw_index: 6
1922
- },
1923
- {
1924
- type: "schematic_port",
1925
- schematic_port_id: "schematic_port_7",
1926
- schematic_component_id: "schematic_component_0",
1927
- center: {
1928
- x: 0.9500000000000001,
1929
- y: 0.30000000000000004
1930
- },
1931
- source_port_id: "source_port_7",
1932
- facing_direction: "right",
1933
- distance_from_component_edge: 0.4,
1934
- side_of_component: "right",
1935
- pin_number: 8,
1936
- true_ccw_index: 7
1937
- },
1938
- {
1939
- type: "pcb_component",
1940
- pcb_component_id: "pcb_component_0",
1941
- center: {
1942
- x: 0,
1943
- y: 0
1944
- },
1945
- width: 8.82,
1946
- height: 8.82,
1947
- layer: "top",
1948
- rotation: 0,
1949
- source_component_id: "source_component_0"
1950
- },
1951
- {
1952
- type: "pcb_board",
1953
- pcb_board_id: "pcb_board_0",
1954
- center: {
1955
- x: 0,
1956
- y: 0
1957
- },
1958
- thickness: 1.4,
1959
- num_layers: 4,
1960
- width: 50,
1961
- height: 50
1962
- },
1963
- {
1964
- type: "pcb_plated_hole",
1965
- pcb_plated_hole_id: "pcb_plated_hole_0",
1966
- pcb_component_id: "pcb_component_0",
1967
- pcb_port_id: "pcb_port_0",
1968
- outer_diameter: 1.2,
1969
- hole_diameter: 1,
1970
- shape: "circle",
1971
- port_hints: ["1"],
1972
- x: -3.81,
1973
- y: 3.81,
1974
- layers: ["top", "bottom"]
1975
- },
1976
- {
1977
- type: "pcb_plated_hole",
1978
- pcb_plated_hole_id: "pcb_plated_hole_1",
1979
- pcb_component_id: "pcb_component_0",
1980
- pcb_port_id: "pcb_port_1",
1981
- outer_diameter: 1.2,
1982
- hole_diameter: 1,
1983
- shape: "circle",
1984
- port_hints: ["2"],
1985
- x: -3.81,
1986
- y: 1.27,
1987
- layers: ["top", "bottom"]
1988
- },
1989
- {
1990
- type: "pcb_plated_hole",
1991
- pcb_plated_hole_id: "pcb_plated_hole_2",
1992
- pcb_component_id: "pcb_component_0",
1993
- pcb_port_id: "pcb_port_2",
1994
- outer_diameter: 1.2,
1995
- hole_diameter: 1,
1996
- shape: "circle",
1997
- port_hints: ["3"],
1998
- x: -3.81,
1999
- y: -1.27,
2000
- layers: ["top", "bottom"]
2001
- },
2002
- {
2003
- type: "pcb_plated_hole",
2004
- pcb_plated_hole_id: "pcb_plated_hole_3",
2005
- pcb_component_id: "pcb_component_0",
2006
- pcb_port_id: "pcb_port_3",
2007
- outer_diameter: 1.2,
2008
- hole_diameter: 1,
2009
- shape: "circle",
2010
- port_hints: ["4"],
2011
- x: -3.81,
2012
- y: -3.81,
2013
- layers: ["top", "bottom"]
2014
- },
2015
- {
2016
- type: "pcb_plated_hole",
2017
- pcb_plated_hole_id: "pcb_plated_hole_4",
2018
- pcb_component_id: "pcb_component_0",
2019
- pcb_port_id: "pcb_port_4",
2020
- outer_diameter: 1.2,
2021
- hole_diameter: 1,
2022
- shape: "circle",
2023
- port_hints: ["5"],
2024
- x: 3.81,
2025
- y: -3.81,
2026
- layers: ["top", "bottom"]
2027
- },
2028
- {
2029
- type: "pcb_plated_hole",
2030
- pcb_plated_hole_id: "pcb_plated_hole_5",
2031
- pcb_component_id: "pcb_component_0",
2032
- pcb_port_id: "pcb_port_5",
2033
- outer_diameter: 1.2,
2034
- hole_diameter: 1,
2035
- shape: "circle",
2036
- port_hints: ["6"],
2037
- x: 3.81,
2038
- y: -1.27,
2039
- layers: ["top", "bottom"]
2040
- },
2041
- {
2042
- type: "pcb_plated_hole",
2043
- pcb_plated_hole_id: "pcb_plated_hole_6",
2044
- pcb_component_id: "pcb_component_0",
2045
- pcb_port_id: "pcb_port_6",
2046
- outer_diameter: 1.2,
2047
- hole_diameter: 1,
2048
- shape: "circle",
2049
- port_hints: ["7"],
2050
- x: 3.81,
2051
- y: 1.27,
2052
- layers: ["top", "bottom"]
2053
- },
2054
- {
2055
- type: "pcb_plated_hole",
2056
- pcb_plated_hole_id: "pcb_plated_hole_7",
2057
- pcb_component_id: "pcb_component_0",
2058
- pcb_port_id: "pcb_port_7",
2059
- outer_diameter: 1.2,
2060
- hole_diameter: 1,
2061
- shape: "circle",
2062
- port_hints: ["8"],
2063
- x: 3.81,
2064
- y: 3.81,
2065
- layers: ["top", "bottom"]
2066
- },
2067
- {
2068
- type: "pcb_silkscreen_path",
2069
- pcb_silkscreen_path_id: "pcb_silkscreen_path_0",
2070
- pcb_component_id: "pcb_component_0",
2071
- layer: "top",
2072
- route: [
2073
- {
2074
- x: -3.01,
2075
- y: -4.61
2076
- },
2077
- {
2078
- x: -3.01,
2079
- y: 4.61
2080
- },
2081
- {
2082
- x: -1.0033333333333332,
2083
- y: 4.61
2084
- },
2085
- {
2086
- x: -0.9269591309529909,
2087
- y: 4.226040956193693
2088
- },
2089
- {
2090
- x: -0.7094638037905026,
2091
- y: 3.9005361962094978
2092
- },
2093
- {
2094
- x: -0.3839590438063067,
2095
- y: 3.6830408690470096
2096
- },
2097
- {
2098
- x: 6143644775722556e-32,
2099
- y: 3.6066666666666674
2100
- },
2101
- {
2102
- x: 0.38395904380630674,
2103
- y: 3.6830408690470096
2104
- },
2105
- {
2106
- x: 0.7094638037905027,
2107
- y: 3.9005361962094978
2108
- },
2109
- {
2110
- x: 0.9269591309529909,
2111
- y: 4.226040956193693
2112
- },
2113
- {
2114
- x: 1.0033333333333332,
2115
- y: 4.61
2116
- },
2117
- {
2118
- x: 3.01,
2119
- y: 4.61
2120
- },
2121
- {
2122
- x: 3.01,
2123
- y: -4.61
2124
- },
2125
- {
2126
- x: -3.01,
2127
- y: -4.61
2128
- }
2129
- ],
2130
- stroke_width: 0.1
2131
- },
2132
- {
2133
- type: "pcb_port",
2134
- pcb_port_id: "pcb_port_0",
2135
- pcb_component_id: "pcb_component_0",
2136
- layers: ["top", "inner1", "inner2", "bottom"],
2137
- x: -3.81,
2138
- y: 3.81,
2139
- source_port_id: "source_port_0"
2140
- },
2141
- {
2142
- type: "pcb_port",
2143
- pcb_port_id: "pcb_port_1",
2144
- pcb_component_id: "pcb_component_0",
2145
- layers: ["top", "inner1", "inner2", "bottom"],
2146
- x: -3.81,
2147
- y: 1.27,
2148
- source_port_id: "source_port_1"
2149
- },
2150
- {
2151
- type: "pcb_port",
2152
- pcb_port_id: "pcb_port_2",
2153
- pcb_component_id: "pcb_component_0",
2154
- layers: ["top", "inner1", "inner2", "bottom"],
2155
- x: -3.81,
2156
- y: -1.27,
2157
- source_port_id: "source_port_2"
2158
- },
2159
- {
2160
- type: "pcb_port",
2161
- pcb_port_id: "pcb_port_3",
2162
- pcb_component_id: "pcb_component_0",
2163
- layers: ["top", "inner1", "inner2", "bottom"],
2164
- x: -3.81,
2165
- y: -3.81,
2166
- source_port_id: "source_port_3"
2167
- },
2168
- {
2169
- type: "pcb_port",
2170
- pcb_port_id: "pcb_port_4",
2171
- pcb_component_id: "pcb_component_0",
2172
- layers: ["top", "inner1", "inner2", "bottom"],
2173
- x: 3.81,
2174
- y: -3.81,
2175
- source_port_id: "source_port_4"
2176
- },
2177
- {
2178
- type: "pcb_port",
2179
- pcb_port_id: "pcb_port_5",
2180
- pcb_component_id: "pcb_component_0",
2181
- layers: ["top", "inner1", "inner2", "bottom"],
2182
- x: 3.81,
2183
- y: -1.27,
2184
- source_port_id: "source_port_5"
2185
- },
2186
- {
2187
- type: "pcb_port",
2188
- pcb_port_id: "pcb_port_6",
2189
- pcb_component_id: "pcb_component_0",
2190
- layers: ["top", "inner1", "inner2", "bottom"],
2191
- x: 3.81,
2192
- y: 1.27,
2193
- source_port_id: "source_port_6"
2194
- },
2195
- {
2196
- type: "pcb_port",
2197
- pcb_port_id: "pcb_port_7",
2198
- pcb_component_id: "pcb_component_0",
2199
- layers: ["top", "inner1", "inner2", "bottom"],
2200
- x: 3.81,
2201
- y: 3.81,
2202
- source_port_id: "source_port_7"
2203
- },
2204
- {
2205
- type: "cad_component",
2206
- cad_component_id: "cad_component_0",
2207
- position: {
2208
- x: 0,
2209
- y: 0,
2210
- z: 0.7
2211
- },
2212
- rotation: {
2213
- x: 0,
2214
- y: 0,
2215
- z: 0
2216
- },
2217
- pcb_component_id: "pcb_component_0",
2218
- source_component_id: "source_component_0",
2219
- footprinter_string: "dip8"
2220
- }
2221
- ]
2222
- });
2223
- const failedBuild = db.addPackageBuild({
2224
- package_release_id: packageReleaseId2,
2225
- created_at: new Date(Date.now() - 15e3).toISOString(),
2226
- // 15 seconds ago
2227
- transpilation_in_progress: false,
2228
- transpilation_started_at: new Date(Date.now() - 15e3).toISOString(),
2229
- transpilation_completed_at: new Date(Date.now() - 14e3).toISOString(),
2230
- transpilation_logs: [
2231
- "[INFO] Starting transpilation...",
2232
- "[INFO] Parsing package code",
2233
- "[ERROR] Failed to parse TypeScript definitions",
2234
- "[ERROR] Invalid syntax in component declaration"
2235
- ],
2236
- transpilation_error: "TypeScript compilation failed: Syntax error in component declaration",
2237
- circuit_json_build_in_progress: false,
2238
- circuit_json_build_started_at: null,
2239
- circuit_json_build_completed_at: null,
2240
- circuit_json_build_logs: [],
2241
- circuit_json_build_error: "Build cancelled due to transpilation failure",
2242
- build_in_progress: false,
2243
- build_started_at: new Date(Date.now() - 15e3).toISOString(),
2244
- build_completed_at: new Date(Date.now() - 14e3).toISOString(),
2245
- build_error: "Build failed: Unable to complete transpilation step",
2246
- build_error_last_updated_at: new Date(Date.now() - 14e3).toISOString(),
2247
- preview_url: null,
2248
- build_logs: "Build process:\n1. Environment setup - OK\n2. Dependency resolution - OK\n3. Code compilation - FAILED\nError: Invalid syntax in component declaration\nBuild terminated with errors"
2249
- });
2250
- const successfulBuild = db.addPackageBuild({
2251
- package_release_id: packageReleaseId2,
2252
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
2253
- transpilation_in_progress: false,
2254
- transpilation_started_at: new Date(Date.now() - 5e3).toISOString(),
2255
- // Started 5 seconds ago
2256
- transpilation_completed_at: new Date(Date.now() - 3e3).toISOString(),
2257
- // Completed 3 seconds ago
2258
- transpilation_logs: [
2259
- "[INFO] Starting transpilation...",
2260
- "[INFO] Parsing package code",
2261
- "[INFO] Generating TypeScript definitions",
2262
- "[INFO] Compiling to JavaScript",
2263
- "[SUCCESS] Transpilation completed successfully"
2264
- ],
2265
- transpilation_error: null,
2266
- circuit_json_build_in_progress: false,
2267
- circuit_json_build_started_at: new Date(Date.now() - 3e3).toISOString(),
2268
- // Started after transpilation
2269
- circuit_json_build_completed_at: new Date(Date.now() - 1e3).toISOString(),
2270
- // Completed 1 second ago
2271
- circuit_json_build_logs: [
2272
- "[INFO] Starting circuit JSON build...",
2273
- "[INFO] Analyzing component structure",
2274
- "[INFO] Generating port configurations",
2275
- "[INFO] Validating circuit connections",
2276
- "[SUCCESS] Circuit JSON build completed"
2277
- ],
2278
- circuit_json_build_error: null,
2279
- build_in_progress: false,
2280
- build_started_at: new Date(Date.now() - 1e4).toISOString(),
2281
- // Started 10 seconds ago
2282
- build_completed_at: (/* @__PURE__ */ new Date()).toISOString(),
2283
- // Just completed
2284
- build_error: null,
2285
- build_error_last_updated_at: (/* @__PURE__ */ new Date()).toISOString(),
2286
- preview_url: "http://localhost:3000/preview/package_build_1",
2287
- build_logs: "Build process:\n1. Environment setup - OK\n2. Dependency resolution - OK\n3. Code compilation - OK\n4. Circuit validation - OK\n5. Package assembly - OK\nBuild completed successfully"
2288
- });
2289
- const release2 = db.getPackageReleaseById(packageReleaseId2);
2290
- db.updatePackageRelease({
2291
- ...release2,
2292
- latest_package_build_id: successfulBuild.package_build_id
2293
- });
2294
- db.addOrder({
2295
- account_id,
2296
- is_running: false,
2297
- is_started: false,
2298
- is_finished: false,
2299
- error: null,
2300
- has_error: false,
2301
- circuit_json: [
2302
- {
2303
- type: "source_component",
2304
- ftype: "simple_resistor",
2305
- source_component_id: "source_component_1",
2306
- name: "R1",
2307
- resistane: "1k"
2308
- }
2309
- ],
2310
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
2311
- started_at: null,
2312
- completed_at: null
2313
- });
2314
- const testOrg = db.addOrganization({
2315
- name: "test-organization",
2316
- github_handle: "tscircuit",
2317
- owner_account_id: account_id
2318
- });
2319
- db.addOrganizationAccount({
2320
- org_id: testOrg.org_id,
2321
- account_id,
2322
- is_owner: true
2323
- });
2324
- const { package_release_id: orgPackageReleaseId } = db.addSnippet({
2325
- name: "test-organization/test-package",
2326
- unscoped_name: "test-package",
2327
- owner_name: "test-organization",
2328
- code: `
2329
- export const TestComponent = ({ name }: { name: string }) => (
2330
- <resistor name={name} resistance="10k" />
2331
- )
2332
- `.trim(),
2333
- dts: `
2334
- declare module "@tsci/test-organization.test-package" {
2335
- export const TestComponent: ({ name }: {
2336
- name: string;
2337
- }) => any;
2338
- }
2339
- `.trim(),
2340
- compiled_js: `
2341
- "use strict";
2342
-
2343
- Object.defineProperty(exports, "__esModule", {
2344
- value: true
2345
- });
2346
- exports.TestComponent = void 0;
2347
- const TestComponent = ({
2348
- name
2349
- }) => /*#__PURE__*/React.createElement("resistor", {
2350
- name: name,
2351
- resistance: "10k"
2352
- });
2353
- exports.TestComponent = TestComponent;
2354
- `.trim(),
2355
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
2356
- updated_at: (/* @__PURE__ */ new Date()).toISOString(),
2357
- snippet_type: "package",
2358
- description: "Test package for organization",
2359
- circuit_json: [
2360
- {
2361
- type: "source_component",
2362
- source_component_id: "source_component_0",
2363
- ftype: "simple_resistor",
2364
- name: "R1",
2365
- resistance: "10k"
2366
- }
2367
- ]
2368
- });
2369
- const orgPackageBuild = db.addPackageBuild({
2370
- package_release_id: orgPackageReleaseId,
2371
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
2372
- transpilation_in_progress: false,
2373
- transpilation_started_at: new Date(Date.now() - 5e3).toISOString(),
2374
- transpilation_completed_at: new Date(Date.now() - 3e3).toISOString(),
2375
- transpilation_logs: [
2376
- "[INFO] Starting transpilation...",
2377
- "[SUCCESS] Transpilation completed successfully"
2378
- ],
2379
- transpilation_error: null,
2380
- circuit_json_build_in_progress: false,
2381
- circuit_json_build_started_at: new Date(Date.now() - 3e3).toISOString(),
2382
- circuit_json_build_completed_at: new Date(Date.now() - 1e3).toISOString(),
2383
- circuit_json_build_logs: [
2384
- "[INFO] Starting circuit JSON build...",
2385
- "[SUCCESS] Circuit JSON build completed"
2386
- ],
2387
- circuit_json_build_error: null,
2388
- build_in_progress: false,
2389
- build_started_at: new Date(Date.now() - 1e4).toISOString(),
2390
- build_completed_at: (/* @__PURE__ */ new Date()).toISOString(),
2391
- build_error: null,
2392
- build_error_last_updated_at: (/* @__PURE__ */ new Date()).toISOString(),
2393
- preview_url: "http://localhost:3000/preview/org_package_build",
2394
- build_logs: "Build completed successfully"
2395
- });
2396
- const orgRelease = db.getPackageReleaseById(orgPackageReleaseId);
2397
- db.updatePackageRelease({
2398
- ...orgRelease,
2399
- latest_package_build_id: orgPackageBuild.package_build_id
2400
- });
2401
- db.addOrganization({
2402
- name: "testuser",
2403
- owner_account_id: account_id,
2404
- github_handle: "tscircuit",
2405
- is_personal_org: true
2406
- });
2407
- db.addOrganizationAccount({
2408
- org_id: testOrg.org_id,
2409
- account_id: seveibarAcc.account_id
2410
- });
2411
- };
2412
-
2413
- // fake-snippets-api/lib/package_file/generate-fs-sha.ts
2414
- import md5 from "md5";
2415
- function generateFsSha(packageFiles) {
2416
- const fsMap = {};
2417
- packageFiles.filter((file) => file.content_text).forEach((file) => {
2418
- fsMap[file.file_path] = file.content_text || "";
2419
- });
2420
- const hash = md5(JSON.stringify(fsMap));
2421
- return `md5-${hash}`;
2422
- }
2423
-
2424
- // fake-snippets-api/lib/db/db-client.ts
2425
- var createDatabase = ({ seed: seed2 } = {}) => {
2426
- const db = hoist(createStore(initializer));
2427
- if (seed2) {
2428
- seed(db);
2429
- }
2430
- return db;
2431
- };
2432
- var initializer = combine(databaseSchema.parse({}), (set, get) => ({
2433
- addOrder: (order) => {
2434
- const newOrder = { order_id: `order_${get().idCounter + 1}`, ...order };
2435
- set((state) => {
2436
- return {
2437
- orders: [...state.orders, newOrder],
2438
- idCounter: state.idCounter + 1
2439
- };
2440
- });
2441
- return newOrder;
2442
- },
2443
- getOrderById: (orderId) => {
2444
- const state = get();
2445
- return state.orders.find((order) => order.order_id === orderId);
2446
- },
2447
- getOrderFilesByOrderId: (orderId) => {
2448
- const state = get();
2449
- return state.orderFiles.filter((file) => file.order_id === orderId);
2450
- },
2451
- addOrderQuote: ({
2452
- account_id,
2453
- package_release_id,
2454
- vendor_name
2455
- }) => {
2456
- const newOrderQuote = {
2457
- order_quote_id: `order_quote_${get().idCounter + 1}`,
2458
- account_id,
2459
- package_release_id: package_release_id ?? null,
2460
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
2461
- updated_at: (/* @__PURE__ */ new Date()).toISOString(),
2462
- completed_at: null,
2463
- error: null,
2464
- has_error: false,
2465
- is_completed: false,
2466
- is_processing: true,
2467
- vendor_name,
2468
- quoted_components: [],
2469
- bare_pcb_cost: 0,
2470
- shipping_options: [],
2471
- total_cost_without_shipping: 0
2472
- };
2473
- set((state) => {
2474
- return {
2475
- orderQuotes: [...state.orderQuotes, newOrderQuote],
2476
- idCounter: state.idCounter + 1
2477
- };
2478
- });
2479
- return newOrderQuote.order_quote_id;
2480
- },
2481
- getOrderQuoteById: (orderQuoteId) => {
2482
- const state = get();
2483
- return state.orderQuotes.find(
2484
- (quote) => quote.order_quote_id === orderQuoteId
2485
- );
2486
- },
2487
- getJlcpcbOrderStatesByOrderId: (orderId) => {
2488
- const state = get();
2489
- return state.jlcpcbOrderState.find((state2) => state2.order_id === orderId);
2490
- },
2491
- getJlcpcbOrderStepRunsByJlcpcbOrderStateId: (jlcpcbOrderStateId) => {
2492
- const state = get();
2493
- return state.jlcpcbOrderStepRuns.filter((stepRun) => {
2494
- const orderState = state.jlcpcbOrderState.find(
2495
- (state2) => state2.jlcpcb_order_state_id === stepRun.jlcpcb_order_state_id
2496
- );
2497
- return orderState?.order_id === jlcpcbOrderStateId;
2498
- }).sort(
2499
- (a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
2500
- );
2501
- },
2502
- updateOrder: (orderId, updates) => {
2503
- set((state) => ({
2504
- orders: state.orders.map(
2505
- (order) => order.order_id === orderId ? { ...order, ...updates } : order
2506
- )
2507
- }));
2508
- },
2509
- addJlcpcbOrderState: (orderState) => {
2510
- const newOrderState = {
2511
- jlcpcb_order_state_id: `order_state_${get().idCounter + 1}`,
2512
- ...orderState
2513
- };
2514
- set((state) => {
2515
- return {
2516
- jlcpcbOrderState: [...state.jlcpcbOrderState, newOrderState],
2517
- idCounter: state.idCounter + 1
2518
- };
2519
- });
2520
- return newOrderState;
2521
- },
2522
- updateJlcpcbOrderState: (orderId, updates) => {
2523
- set((state) => ({
2524
- jlcpcbOrderState: state.jlcpcbOrderState.map(
2525
- (orderState) => orderState.order_id === orderId ? { ...orderState, ...updates } : orderState
2526
- )
2527
- }));
2528
- },
2529
- addOrderFile: (orderFile) => {
2530
- const newOrderFile = {
2531
- order_file_id: `order_file_${get().idCounter + 1}`,
2532
- ...orderFile
2533
- };
2534
- set((state) => {
2535
- return {
2536
- orderFiles: [...state.orderFiles, newOrderFile],
2537
- idCounter: state.idCounter + 1
2538
- };
2539
- });
2540
- return newOrderFile;
2541
- },
2542
- getOrderFileById: (orderFileId) => {
2543
- const state = get();
2544
- return state.orderFiles.find((file) => file.order_file_id === orderFileId);
2545
- },
2546
- addBugReport: ({
2547
- reporter_account_id,
2548
- text,
2549
- is_auto_deleted,
2550
- delete_at
2551
- }) => {
2552
- const normalizedIsAutoDeleted = Boolean(is_auto_deleted);
2553
- if (normalizedIsAutoDeleted && !delete_at) {
2554
- throw new Error("delete_at is required when is_auto_deleted is true");
2555
- }
2556
- const normalizedDeleteAt = normalizedIsAutoDeleted ? delete_at ?? null : null;
2557
- const bugReport = bugReportSchema.parse({
2558
- bug_report_id: randomUUID(),
2559
- reporter_account_id,
2560
- text: text ?? null,
2561
- is_auto_deleted: normalizedIsAutoDeleted,
2562
- delete_at: normalizedDeleteAt,
2563
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
2564
- file_count: 0
2565
- });
2566
- set((state) => ({
2567
- bugReports: [...state.bugReports, bugReport]
2568
- }));
2569
- return bugReport;
2570
- },
2571
- getBugReportById: (bugReportId) => {
2572
- const state = get();
2573
- return state.bugReports.find(
2574
- (bugReport) => bugReport.bug_report_id === bugReportId
2575
- );
2576
- },
2577
- addBugReportFile: ({
2578
- bug_report_id,
2579
- file_path,
2580
- content_mimetype,
2581
- is_text,
2582
- content_text,
2583
- content_bytes
2584
- }) => {
2585
- const bugReportFile = bugReportFileSchema.parse({
2586
- bug_report_file_id: randomUUID(),
2587
- bug_report_id,
2588
- file_path,
2589
- content_mimetype,
2590
- is_text,
2591
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
2592
- content_text,
2593
- content_bytes
2594
- });
2595
- set((state) => ({
2596
- bugReportFiles: [...state.bugReportFiles, bugReportFile],
2597
- bugReports: state.bugReports.map(
2598
- (bugReport) => bugReport.bug_report_id === bug_report_id ? { ...bugReport, file_count: bugReport.file_count + 1 } : bugReport
2599
- )
2600
- }));
2601
- return bugReportFile;
2602
- },
2603
- getBugReportFilesByBugReportId: (bugReportId) => {
2604
- const state = get();
2605
- return state.bugReportFiles.filter(
2606
- (file) => file.bug_report_id === bugReportId
2607
- );
2608
- },
2609
- addAccount: (account) => {
2610
- const newAccount = {
2611
- account_id: account.account_id || `account_${get().idCounter + 1}`,
2612
- ...account,
2613
- is_tscircuit_staff: Boolean(account.is_tscircuit_staff)
2614
- };
2615
- set((state) => {
2616
- return {
2617
- accounts: [...state.accounts, newAccount],
2618
- idCounter: state.idCounter + 1
2619
- };
2620
- });
2621
- return newAccount;
2622
- },
2623
- addAccountPackage: (accountPackage) => {
2624
- const newAccountPackage = {
2625
- account_package_id: `ap_${get().idCounter + 1}`,
2626
- ...accountPackage
2627
- };
2628
- set((state) => {
2629
- return {
2630
- accountPackages: [...state.accountPackages, newAccountPackage],
2631
- idCounter: state.idCounter + 1
2632
- };
2633
- });
2634
- return newAccountPackage;
2635
- },
2636
- getAccountPackageById: (accountPackageId) => {
2637
- const state = get();
2638
- return state.accountPackages.find(
2639
- (ap) => ap.account_package_id === accountPackageId
2640
- );
2641
- },
2642
- updateAccountPackage: (accountPackageId, updates) => {
2643
- set((state) => ({
2644
- accountPackages: state.accountPackages.map(
2645
- (ap) => ap.account_package_id === accountPackageId ? { ...ap, ...updates } : ap
2646
- )
2647
- }));
2648
- },
2649
- deleteAccountPackage: (accountPackageId) => {
2650
- let deleted = false;
2651
- set((state) => {
2652
- const index = state.accountPackages.findIndex(
2653
- (ap) => ap.account_package_id === accountPackageId
2654
- );
2655
- if (index !== -1) {
2656
- state.accountPackages.splice(index, 1);
2657
- deleted = true;
2658
- }
2659
- return state;
2660
- });
2661
- return deleted;
2662
- },
2663
- addSnippet: (snippet) => {
2664
- const timestamp = Date.now();
2665
- const currentTime = new Date(timestamp).toISOString();
2666
- const newState = get();
2667
- const nextId = newState.idCounter + 1;
2668
- const newPackage = {
2669
- package_id: `pkg_${nextId}`,
2670
- creator_account_id: snippet.creator_account_id ?? snippet.owner_name,
2671
- // Using owner_name as account_id since we don't have context
2672
- owner_org_id: "",
2673
- // Empty string instead of null to match type
2674
- owner_github_username: snippet.owner_name,
2675
- is_source_from_github: false,
2676
- description: snippet.description || "",
2677
- name: `${snippet.owner_name}/${snippet.unscoped_name}`,
2678
- unscoped_name: snippet.unscoped_name,
2679
- latest_version: "0.0.1",
2680
- license: null,
2681
- website: null,
2682
- star_count: 0,
2683
- created_at: currentTime,
2684
- updated_at: currentTime,
2685
- github_repo_full_name: snippet.github_repo_full_name || null,
2686
- ai_description: "placeholder ai description",
2687
- ai_usage_instructions: "placeholder ai usage instructions",
2688
- is_snippet: true,
2689
- is_board: snippet.snippet_type === "board",
2690
- is_package: snippet.snippet_type === "package",
2691
- is_model: snippet.snippet_type === "model",
2692
- is_footprint: snippet.snippet_type === "footprint",
2693
- snippet_type: snippet.snippet_type,
2694
- is_private: false,
2695
- is_public: true,
2696
- is_unlisted: false,
2697
- latest_package_release_id: `package_release_${nextId}`,
2698
- latest_package_release_fs_sha: null
2699
- };
2700
- const newPackageRelease = packageReleaseSchema.parse({
2701
- package_release_id: `package_release_${nextId}`,
2702
- package_id: newPackage.package_id,
2703
- version: "0.0.1",
2704
- is_latest: true,
2705
- is_locked: false,
2706
- created_at: currentTime,
2707
- updated_at: currentTime,
2708
- branch_name: snippet.branch_name,
2709
- commit_message: snippet.commit_message,
2710
- commit_author: snippet.commit_author,
2711
- has_transpiled: true,
2712
- transpilation_error: null,
2713
- ...snippet.name == "testuser/my-test-board" ? { is_pr_preview: true, github_pr_number: 69 } : {}
2714
- });
2715
- const packageFiles = [];
2716
- let fileIdCounter = nextId;
2717
- packageFiles.push({
2718
- package_file_id: `package_file_${fileIdCounter++}`,
2719
- package_release_id: newPackageRelease.package_release_id,
2720
- file_path: "index.tsx",
2721
- content_text: snippet.code || "",
2722
- created_at: currentTime
2723
- });
2724
- if (snippet.dts) {
2725
- packageFiles.push({
2726
- package_file_id: `package_file_${fileIdCounter++}`,
2727
- package_release_id: newPackageRelease.package_release_id,
2728
- file_path: "/dist/index.d.ts",
2729
- content_text: snippet.dts,
2730
- created_at: currentTime
2731
- });
2732
- }
2733
- if (snippet.compiled_js) {
2734
- packageFiles.push({
2735
- package_file_id: `package_file_${fileIdCounter++}`,
2736
- package_release_id: newPackageRelease.package_release_id,
2737
- file_path: "/dist/index.js",
2738
- content_text: snippet.compiled_js,
2739
- created_at: currentTime
2740
- });
2741
- }
2742
- if (snippet.circuit_json && snippet.circuit_json.length > 0) {
2743
- packageFiles.push({
2744
- package_file_id: `package_file_${fileIdCounter++}`,
2745
- package_release_id: newPackageRelease.package_release_id,
2746
- file_path: "/dist/circuit.json",
2747
- content_text: JSON.stringify(snippet.circuit_json),
2748
- created_at: currentTime
2749
- });
2750
- }
2751
- set((state) => ({
2752
- ...state,
2753
- packages: [...state.packages, newPackage],
2754
- packageReleases: [...state.packageReleases, newPackageRelease],
2755
- packageFiles: [...state.packageFiles, ...packageFiles],
2756
- idCounter: fileIdCounter
2757
- }));
2758
- const dbState = get();
2759
- const releaseFiles = dbState.packageFiles.filter(
2760
- (pf) => pf.package_release_id === newPackageRelease.package_release_id
2761
- );
2762
- const fsSha = generateFsSha(releaseFiles);
2763
- set((state) => ({
2764
- ...state,
2765
- packageReleases: state.packageReleases.map(
2766
- (pr) => pr.package_release_id === newPackageRelease.package_release_id ? { ...pr, fs_sha: fsSha } : pr
2767
- ),
2768
- packages: state.packages.map(
2769
- (pkg) => pkg.latest_package_release_id === newPackageRelease.package_release_id ? { ...pkg, latest_package_release_fs_sha: fsSha } : pkg
2770
- )
2771
- }));
2772
- return {
2773
- snippet_id: newPackage.package_id,
2774
- package_release_id: newPackageRelease.package_release_id,
2775
- name: newPackage.name,
2776
- unscoped_name: newPackage.unscoped_name,
2777
- owner_name: snippet.owner_name,
2778
- code: snippet.code || "",
2779
- dts: snippet.dts,
2780
- compiled_js: snippet.compiled_js,
2781
- star_count: 0,
2782
- created_at: currentTime,
2783
- updated_at: currentTime,
2784
- snippet_type: snippet.snippet_type,
2785
- circuit_json: snippet.circuit_json || [],
2786
- description: snippet.description || "",
2787
- is_starred: false,
2788
- version: "0.0.1",
2789
- is_private: false,
2790
- is_public: true,
2791
- is_unlisted: false
2792
- };
2793
- },
2794
- getLatestSnippets: (limit) => {
2795
- const state = get();
2796
- const snippetPackages = state.packages.filter((pkg) => pkg.is_snippet === true).map((pkg) => {
2797
- const packageRelease = state.packageReleases.find(
2798
- (pr) => pr.package_release_id === pkg.latest_package_release_id && pr.is_latest === true
2799
- );
2800
- if (!packageRelease) return null;
2801
- const packageFiles = state.packageFiles.filter(
2802
- (file) => file.package_release_id === packageRelease.package_release_id
2803
- );
2804
- const codeFile = packageFiles.find(
2805
- (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
2806
- );
2807
- const isStarred = state.accountPackages.some(
2808
- (ap) => ap.package_id === pkg.package_id && ap.is_starred
2809
- );
2810
- return {
2811
- snippet_id: pkg.package_id,
2812
- package_release_id: pkg.latest_package_release_id || "",
2813
- unscoped_name: pkg.unscoped_name,
2814
- name: pkg.name,
2815
- owner_name: pkg.owner_github_username || "",
2816
- description: pkg.description || "",
2817
- snippet_type: pkg.snippet_type || "board",
2818
- code: codeFile?.content_text || "",
2819
- dts: packageFiles.find((file) => file.file_path === "/dist/index.d.ts")?.content_text || "",
2820
- compiled_js: packageFiles.find((file) => file.file_path === "/dist/index.js")?.content_text || "",
2821
- created_at: pkg.created_at,
2822
- updated_at: pkg.updated_at,
2823
- star_count: pkg.star_count || 0,
2824
- is_starred: isStarred,
2825
- version: pkg.latest_version || "0.0.1",
2826
- circuit_json: packageFiles.filter((file) => file.file_path === "/dist/circuit.json").flatMap((file) => JSON.parse(file.content_text || "[]")) || [],
2827
- is_private: pkg.is_private || false,
2828
- is_public: pkg.is_public || true,
2829
- is_unlisted: pkg.is_unlisted || false
2830
- };
2831
- }).filter(
2832
- (snippet) => snippet !== null
2833
- ).map((snippet) => ({
2834
- ...snippet,
2835
- description: snippet.description || ""
2836
- })).sort(
2837
- (a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
2838
- ).slice(0, limit);
2839
- return snippetPackages;
2840
- },
2841
- getTrendingSnippets: (limit, since) => {
2842
- const state = get();
2843
- const sinceDate = new Date(since).getTime();
2844
- const recentStars = /* @__PURE__ */ new Map();
2845
- state.accountPackages.forEach((ap) => {
2846
- if (ap.is_starred && new Date(ap.created_at).getTime() >= sinceDate) {
2847
- recentStars.set(
2848
- ap.package_id,
2849
- (recentStars.get(ap.package_id) || 0) + 1
2850
- );
2851
- }
2852
- });
2853
- const packagesWithStarCount = [...state.packages].map((pkg) => ({
2854
- ...pkg,
2855
- star_count: recentStars.get(pkg.package_id) || 0
2856
- })).sort((a, b) => b.star_count - a.star_count).slice(0, limit);
2857
- const trendingSnippets = packagesWithStarCount.map((pkg) => {
2858
- const packageRelease = state.packageReleases.find(
2859
- (pr) => pr.package_release_id === pkg.latest_package_release_id && pr.is_latest === true
2860
- );
2861
- if (!packageRelease) return null;
2862
- const packageFiles = state.packageFiles.filter(
2863
- (file) => file.package_release_id === packageRelease.package_release_id
2864
- );
2865
- const codeFile = packageFiles.find(
2866
- (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
2867
- );
2868
- return {
2869
- snippet_id: pkg.package_id,
2870
- package_release_id: pkg.latest_package_release_id || "",
2871
- unscoped_name: pkg.unscoped_name,
2872
- name: pkg.name,
2873
- owner_name: pkg.owner_github_username || "",
2874
- code: codeFile ? codeFile.content_text || "" : "",
2875
- created_at: pkg.created_at,
2876
- updated_at: pkg.updated_at,
2877
- snippet_type: pkg.is_snippet ? "board" : "package",
2878
- star_count: pkg.star_count
2879
- };
2880
- }).filter((snippet) => snippet !== null);
2881
- return trendingSnippets;
2882
- },
2883
- getPackagesByAuthor: (authorName) => {
2884
- const state = get();
2885
- const packages = authorName ? state.packages.filter((pkg) => pkg.owner_github_username === authorName) : state.packages;
2886
- return packages.map((pkg) => ({
2887
- ...pkg,
2888
- star_count: state.accountPackages.filter(
2889
- (ap) => ap.package_id === pkg.package_id && ap.is_starred
2890
- ).length
2891
- }));
2892
- },
2893
- getSnippetByAuthorAndName: (authorName, snippetName) => {
2894
- const state = get();
2895
- const _package = state.packages.find(
2896
- (pkg) => pkg.owner_github_username?.toLowerCase() === authorName.toLowerCase() && pkg.name.toLowerCase() === snippetName.toLowerCase() && pkg.is_snippet === true
2897
- );
2898
- if (!_package) return void 0;
2899
- const packageRelease = state.packageReleases.find(
2900
- (pr) => pr.package_release_id === _package.latest_package_release_id && pr.is_latest === true
2901
- );
2902
- if (!packageRelease) return void 0;
2903
- const packageFiles = state.packageFiles.filter(
2904
- (file) => file.package_release_id === packageRelease.package_release_id
2905
- );
2906
- const codeFile = packageFiles.find(
2907
- (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
2908
- );
2909
- return {
2910
- snippet_id: _package.package_id,
2911
- package_release_id: _package.latest_package_release_id || "",
2912
- unscoped_name: _package.unscoped_name,
2913
- name: _package.name,
2914
- owner_name: _package.owner_github_username || "",
2915
- description: _package.description || "",
2916
- snippet_type: _package.snippet_type || "board",
2917
- code: codeFile?.content_text || "",
2918
- dts: packageFiles.find((file) => file.file_path === "/dist/index.d.ts")?.content_text || "",
2919
- compiled_js: packageFiles.find((file) => file.file_path === "/dist/index.js")?.content_text || "",
2920
- created_at: _package.created_at,
2921
- updated_at: _package.updated_at,
2922
- star_count: _package.star_count || 0,
2923
- is_starred: false,
2924
- version: _package.latest_version || "0.0.1",
2925
- circuit_json: packageFiles.find(
2926
- (file) => file.file_path === "/dist/circuit.json"
2927
- )?.content_text ? JSON.parse(
2928
- packageFiles.find((file) => file.file_path === "/dist/circuit.json")?.content_text || "[]"
2929
- ) : [],
2930
- is_private: _package.is_private || false,
2931
- is_public: _package.is_public || true,
2932
- is_unlisted: _package.is_unlisted || false
2933
- };
2934
- },
2935
- updateSnippet: (snippetId, updates) => {
2936
- set((state) => {
2937
- const packageIndex = state.packages.findIndex(
2938
- (pkg) => pkg.package_id === snippetId && pkg.is_snippet === true
2939
- );
2940
- if (packageIndex === -1) {
2941
- return state;
2942
- }
2943
- const timestamp = Date.now();
2944
- const currentTime = new Date(timestamp).toISOString();
2945
- const updatedPackages = [...state.packages];
2946
- const currentPackage = updatedPackages[packageIndex];
2947
- updatedPackages[packageIndex] = {
2948
- ...currentPackage,
2949
- description: updates.description ?? currentPackage.description,
2950
- is_private: updates.is_private ?? currentPackage.is_private,
2951
- is_public: updates.is_private !== void 0 ? !updates.is_private : currentPackage.is_public,
2952
- is_unlisted: updates.is_private ? true : updates.is_unlisted ?? currentPackage.is_unlisted,
2953
- updated_at: currentTime
2954
- };
2955
- const packageRelease2 = state.packageReleases.find(
2956
- (pr) => pr.package_release_id === currentPackage.latest_package_release_id
2957
- );
2958
- if (!packageRelease2) return state;
2959
- const updatedFiles = [...state.packageFiles];
2960
- const packageFiles2 = updatedFiles.filter(
2961
- (file) => file.package_release_id === packageRelease2.package_release_id
2962
- );
2963
- if (updates.code !== void 0) {
2964
- const codeFileIndex = packageFiles2.findIndex(
2965
- (file) => file.file_path === "index.tsx" || file.file_path === "index.ts"
2966
- );
2967
- if (codeFileIndex >= 0) {
2968
- updatedFiles[codeFileIndex] = {
2969
- ...packageFiles2[codeFileIndex],
2970
- content_text: updates.code,
2971
- created_at: currentTime
2972
- };
2973
- } else {
2974
- updatedFiles.push({
2975
- package_file_id: `package_file_${timestamp}`,
2976
- package_release_id: packageRelease2.package_release_id,
2977
- file_path: "index.tsx",
2978
- content_text: updates.code,
2979
- created_at: currentTime
2980
- });
2981
- }
2982
- }
2983
- if (updates.dts !== void 0) {
2984
- const dtsFileIndex = packageFiles2.findIndex(
2985
- (file) => file.file_path === "/dist/index.d.ts"
2986
- );
2987
- if (dtsFileIndex >= 0) {
2988
- updatedFiles[dtsFileIndex] = {
2989
- ...packageFiles2[dtsFileIndex],
2990
- content_text: updates.dts,
2991
- created_at: currentTime
2992
- };
2993
- } else {
2994
- updatedFiles.push({
2995
- package_file_id: `package_file_${timestamp}`,
2996
- package_release_id: packageRelease2.package_release_id,
2997
- file_path: "/dist/index.d.ts",
2998
- content_text: updates.dts,
2999
- created_at: currentTime
3000
- });
3001
- }
3002
- }
3003
- if (updates.compiled_js !== void 0) {
3004
- const jsFileIndex = packageFiles2.findIndex(
3005
- (file) => file.file_path === "/dist/index.js"
3006
- );
3007
- if (jsFileIndex >= 0) {
3008
- updatedFiles[jsFileIndex] = {
3009
- ...packageFiles2[jsFileIndex],
3010
- content_text: updates.compiled_js,
3011
- created_at: currentTime
3012
- };
3013
- } else {
3014
- updatedFiles.push({
3015
- package_file_id: `package_file_${timestamp}`,
3016
- package_release_id: packageRelease2.package_release_id,
3017
- file_path: "/dist/index.js",
3018
- content_text: updates.compiled_js,
3019
- created_at: currentTime
3020
- });
3021
- }
3022
- }
3023
- if (updates.circuit_json !== void 0) {
3024
- const circuitFileIndex = packageFiles2.findIndex(
3025
- (file) => file.file_path === "/dist/circuit.json"
3026
- );
3027
- if (circuitFileIndex >= 0) {
3028
- updatedFiles[circuitFileIndex] = {
3029
- ...packageFiles2[circuitFileIndex],
3030
- content_text: JSON.stringify(updates.circuit_json),
3031
- created_at: (/* @__PURE__ */ new Date()).toISOString()
3032
- };
3033
- }
3034
- }
3035
- return {
3036
- ...state,
3037
- packages: updatedPackages,
3038
- packageFiles: updatedFiles
3039
- };
3040
- });
3041
- const updatedPackage = get().packages.find(
3042
- (pkg) => pkg.package_id === snippetId
3043
- );
3044
- if (!updatedPackage) return void 0;
3045
- const packageRelease = get().packageReleases.find(
3046
- (pr) => pr.package_release_id === updatedPackage.latest_package_release_id
3047
- );
3048
- if (!packageRelease) return void 0;
3049
- const packageFiles = get().packageFiles.filter(
3050
- (file) => file.package_release_id === packageRelease.package_release_id
3051
- );
3052
- const codeFile = packageFiles.find(
3053
- (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
3054
- );
3055
- const dtsFile = packageFiles.find(
3056
- (file) => file.file_path === "/dist/index.d.ts"
3057
- );
3058
- const jsFile = packageFiles.find(
3059
- (file) => file.file_path === "/dist/index.js"
3060
- );
3061
- const circuitFile = packageFiles.find(
3062
- (file) => file.file_path === "/dist/circuit.json"
3063
- );
3064
- return {
3065
- snippet_id: updatedPackage.package_id,
3066
- package_release_id: updatedPackage.latest_package_release_id || "",
3067
- unscoped_name: updatedPackage.unscoped_name,
3068
- name: updatedPackage.name,
3069
- owner_name: updatedPackage.owner_github_username || "",
3070
- description: updatedPackage.description || "",
3071
- snippet_type: updatedPackage.snippet_type || "board",
3072
- code: codeFile?.content_text || "",
3073
- dts: dtsFile?.content_text || "",
3074
- compiled_js: jsFile?.content_text || "",
3075
- created_at: updatedPackage.created_at,
3076
- updated_at: updatedPackage.updated_at,
3077
- star_count: updatedPackage.star_count || 0,
3078
- is_starred: false,
3079
- version: updatedPackage.latest_version || "0.0.1",
3080
- circuit_json: circuitFile ? JSON.parse(circuitFile.content_text || "[]") : [],
3081
- is_private: updatedPackage.is_private ?? false,
3082
- is_public: updatedPackage.is_public ?? true,
3083
- is_unlisted: updatedPackage.is_unlisted ?? false
3084
- };
3085
- },
3086
- getSnippetById: (snippetId, auth) => {
3087
- const state = get();
3088
- const _package = state.packages.find(
3089
- (pkg) => pkg.package_id === snippetId && pkg.is_snippet === true
3090
- );
3091
- if (!_package) return void 0;
3092
- if (!auth) {
3093
- if (!_package.is_public || _package.is_unlisted) {
3094
- return void 0;
3095
- }
3096
- } else {
3097
- const isOwnPackage = _package.owner_github_username === auth?.github_username;
3098
- const isPublicAndNotUnlisted = _package.is_public && !_package.is_unlisted;
3099
- const isOwnUnlisted = _package.is_unlisted && isOwnPackage;
3100
- const isOwnPrivate = _package.is_private && isOwnPackage;
3101
- if (!isPublicAndNotUnlisted && !isOwnUnlisted && !isOwnPrivate) {
3102
- return void 0;
3103
- }
3104
- }
3105
- const packageRelease = state.packageReleases.find(
3106
- (pr) => pr.package_release_id === _package.latest_package_release_id && pr.is_latest === true
3107
- );
3108
- if (!packageRelease) return void 0;
3109
- const packageFiles = state.packageFiles.filter(
3110
- (file) => file.package_release_id === packageRelease.package_release_id
3111
- );
3112
- const codeFile = packageFiles.find(
3113
- (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
3114
- );
3115
- const isStarred = state.accountPackages.some(
3116
- (ap) => ap.package_id === snippetId && ap.is_starred
3117
- );
3118
- return {
3119
- snippet_id: _package.package_id,
3120
- package_release_id: _package.latest_package_release_id || "",
3121
- unscoped_name: _package.unscoped_name,
3122
- name: _package.name,
3123
- owner_name: _package.owner_github_username || "",
3124
- description: _package.description || "",
3125
- snippet_type: _package.snippet_type || "board",
3126
- code: codeFile?.content_text || "",
3127
- dts: packageFiles.find((file) => file.file_path === "/dist/index.d.ts")?.content_text || "",
3128
- compiled_js: packageFiles.find((file) => file.file_path === "/dist/index.js")?.content_text || "",
3129
- created_at: _package.created_at,
3130
- updated_at: _package.updated_at,
3131
- star_count: _package.star_count || 0,
3132
- is_starred: isStarred,
3133
- version: _package.latest_version || "0.0.1",
3134
- circuit_json: packageFiles.find(
3135
- (file) => file.file_path === "/dist/circuit.json"
3136
- )?.content_text ? JSON.parse(
3137
- packageFiles.find((file) => file.file_path === "/dist/circuit.json")?.content_text || "[]"
3138
- ) : [],
3139
- is_private: _package.is_private || false,
3140
- is_public: _package.is_public || true,
3141
- is_unlisted: _package.is_unlisted || false
3142
- };
3143
- },
3144
- searchSnippets: (query) => {
3145
- const state = get();
3146
- const lowercaseQuery = query.toLowerCase();
3147
- const packages = state.packages.filter((pkg) => pkg.is_snippet === true);
3148
- const matchingPackagesByMetadata = packages.filter(
3149
- (pkg) => pkg.name.toLowerCase().includes(lowercaseQuery) || pkg.description?.toLowerCase().includes(lowercaseQuery)
3150
- );
3151
- const matchingFilesByContent = state.packageFiles.filter(
3152
- (file) => file.content_text?.toLowerCase().includes(lowercaseQuery) ?? false
3153
- );
3154
- const matchingPackagesByContent = matchingFilesByContent.map((file) => {
3155
- const packageRelease = state.packageReleases.find(
3156
- (pr) => pr.package_release_id === file.package_release_id
3157
- );
3158
- if (!packageRelease) return null;
3159
- return packages.find(
3160
- (pkg) => pkg.latest_package_release_id === packageRelease.package_release_id
3161
- );
3162
- }).filter((pkg) => pkg !== null);
3163
- const matchingPackages = [
3164
- .../* @__PURE__ */ new Set([...matchingPackagesByMetadata, ...matchingPackagesByContent])
3165
- ];
3166
- return matchingPackages.map((pkg) => {
3167
- const packageRelease = state.packageReleases.find(
3168
- (pr) => pr.package_release_id === pkg.latest_package_release_id && pr.is_latest === true
3169
- );
3170
- if (!packageRelease) return null;
3171
- const packageFiles = state.packageFiles.filter(
3172
- (file) => file.package_release_id === packageRelease.package_release_id
3173
- );
3174
- const codeFile = packageFiles.find(
3175
- (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
3176
- );
3177
- const isStarred = state.accountPackages.some(
3178
- (ap) => ap.package_id === pkg.package_id && ap.is_starred
3179
- );
3180
- return {
3181
- snippet_id: pkg.package_id,
3182
- package_release_id: pkg.latest_package_release_id || "",
3183
- unscoped_name: pkg.unscoped_name,
3184
- name: pkg.name,
3185
- owner_name: pkg.owner_github_username || "",
3186
- description: pkg.description || "",
3187
- snippet_type: pkg.snippet_type || "board",
3188
- code: codeFile?.content_text || "",
3189
- dts: packageFiles.find((file) => file.file_path === "/dist/index.d.ts")?.content_text || "",
3190
- compiled_js: packageFiles.find((file) => file.file_path === "/dist/index.js")?.content_text || "",
3191
- created_at: pkg.created_at,
3192
- updated_at: pkg.updated_at,
3193
- star_count: pkg.star_count || 0,
3194
- is_starred: isStarred,
3195
- version: pkg.latest_version || "0.0.1",
3196
- circuit_json: packageFiles.filter((file) => file.file_path === "/dist/circuit.json").flatMap((file) => JSON.parse(file.content_text || "[]")) || []
3197
- };
3198
- }).filter((snippet) => snippet !== null);
3199
- },
3200
- searchPackages: (query) => {
3201
- const state = get();
3202
- const lowercaseQuery = query.toLowerCase();
3203
- const packages = state.packages.filter((pkg) => pkg.is_public === true);
3204
- const matchingPackagesByMetadata = packages.filter(
3205
- (pkg) => pkg.name.toLowerCase().includes(lowercaseQuery) || pkg.description?.toLowerCase().includes(lowercaseQuery)
3206
- );
3207
- const matchingFilesByContent = state.packageFiles.filter(
3208
- (file) => file.content_text?.toLowerCase().includes(lowercaseQuery) ?? false
3209
- );
3210
- const matchingPackagesByContent = matchingFilesByContent.map((file) => {
3211
- const packageRelease = state.packageReleases.find(
3212
- (pr) => pr.package_release_id === file.package_release_id
3213
- );
3214
- if (!packageRelease) return null;
3215
- return packages.find(
3216
- (pkg) => pkg.latest_package_release_id === packageRelease.package_release_id
3217
- );
3218
- }).filter((pkg) => pkg !== null);
3219
- const matchingPackages = [
3220
- .../* @__PURE__ */ new Set([...matchingPackagesByMetadata, ...matchingPackagesByContent])
3221
- ];
3222
- return matchingPackages;
3223
- },
3224
- searchAccounts: (query, limit) => {
3225
- const state = get();
3226
- const lowercaseQuery = query.toLowerCase();
3227
- const accountsWithPublicPackages = /* @__PURE__ */ new Set();
3228
- state.packages.filter((pkg) => pkg.is_public === true).forEach((pkg) => {
3229
- if (pkg.creator_account_id) {
3230
- accountsWithPublicPackages.add(pkg.creator_account_id);
3231
- }
3232
- if (pkg.owner_github_username) {
3233
- const account = state.accounts.find(
3234
- (acc) => acc.github_username === pkg.owner_github_username
3235
- );
3236
- if (account) {
3237
- accountsWithPublicPackages.add(account.account_id);
3238
- }
3239
- }
3240
- });
3241
- const matchingAccounts = state.accounts.filter((account) => {
3242
- if (!accountsWithPublicPackages.has(account.account_id)) {
3243
- return false;
3244
- }
3245
- return account.github_username.toLowerCase().includes(lowercaseQuery);
3246
- }).slice(0, limit || 50);
3247
- return matchingAccounts;
3248
- },
3249
- deleteSnippet: (snippetId) => {
3250
- let deleted = false;
3251
- set((state) => {
3252
- const index = state.snippets.findIndex((s) => s.snippet_id === snippetId);
3253
- if (index !== -1) {
3254
- state.snippets.splice(index, 1);
3255
- deleted = true;
3256
- }
3257
- return state;
3258
- });
3259
- return deleted;
3260
- },
3261
- addSession: (session) => {
3262
- const newSession = { session_id: `session_${Date.now()}`, ...session };
3263
- set((state) => ({
3264
- sessions: [...state.sessions, newSession]
3265
- }));
3266
- return newSession;
3267
- },
3268
- getSessions: ({
3269
- account_id,
3270
- is_cli_session
3271
- }) => {
3272
- const state = get();
3273
- return state.sessions.filter(
3274
- (session) => session.account_id === account_id && (is_cli_session === void 0 || session.is_cli_session === is_cli_session)
3275
- );
3276
- },
3277
- createLoginPage: () => {
3278
- const newLoginPage = {
3279
- login_page_id: `login_page_${Date.now()}`,
3280
- login_page_auth_token: `token_${Date.now()}`,
3281
- was_login_successful: false,
3282
- has_been_used_to_create_session: false,
3283
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
3284
- expires_at: new Date(Date.now() + 30 * 60 * 1e3).toISOString()
3285
- // 30 minutes expiration
3286
- };
3287
- set((state) => ({
3288
- loginPages: [...state.loginPages, newLoginPage]
3289
- }));
3290
- return newLoginPage;
3291
- },
3292
- getLoginPage: (loginPageId) => {
3293
- const state = get();
3294
- return state.loginPages.find((lp) => lp.login_page_id === loginPageId);
3295
- },
3296
- updateLoginPage: (loginPageId, updates) => {
3297
- set((state) => ({
3298
- loginPages: state.loginPages.map(
3299
- (lp) => lp.login_page_id === loginPageId ? { ...lp, ...updates } : lp
3300
- )
3301
- }));
3302
- },
3303
- getAccount: (accountId) => {
3304
- const state = get();
3305
- return state.accounts.find((account) => account.account_id === accountId);
3306
- },
3307
- updateAccount: (accountId, updates) => {
3308
- let updatedAccount;
3309
- set((state) => {
3310
- const accountIndex = state.accounts.findIndex(
3311
- (account) => account.account_id === accountId
3312
- );
3313
- if (accountIndex !== -1) {
3314
- updatedAccount = { ...state.accounts[accountIndex] };
3315
- if (updates.shippingInfo) {
3316
- updatedAccount.shippingInfo = {
3317
- ...updatedAccount.shippingInfo,
3318
- ...updates.shippingInfo
3319
- };
3320
- delete updates.shippingInfo;
3321
- }
3322
- updatedAccount = { ...updatedAccount, ...updates };
3323
- const updatedAccounts = [...state.accounts];
3324
- updatedAccounts[accountIndex] = updatedAccount;
3325
- return { ...state, accounts: updatedAccounts };
3326
- }
3327
- return state;
3328
- });
3329
- return updatedAccount;
3330
- },
3331
- createSession: (session) => {
3332
- const newSession = { session_id: `session_${Date.now()}`, ...session };
3333
- set((state) => ({
3334
- sessions: [...state.sessions, newSession]
3335
- }));
3336
- return newSession;
3337
- },
3338
- addStar: (accountId, packageId) => {
3339
- const now = (/* @__PURE__ */ new Date()).toISOString();
3340
- const accountPackage = {
3341
- account_package_id: `ap_${Date.now()}`,
3342
- account_id: accountId,
3343
- package_id: packageId,
3344
- is_starred: true,
3345
- created_at: now,
3346
- updated_at: now
3347
- };
3348
- set((state) => {
3349
- const packageIndex = state.packages.findIndex(
3350
- (pkg) => pkg.package_id === packageId
3351
- );
3352
- if (packageIndex >= 0) {
3353
- const updatedPackages = [...state.packages];
3354
- updatedPackages[packageIndex] = {
3355
- ...updatedPackages[packageIndex],
3356
- star_count: (updatedPackages[packageIndex].star_count || 0) + 1
3357
- };
3358
- return {
3359
- packages: updatedPackages,
3360
- accountPackages: [...state.accountPackages, accountPackage]
3361
- };
3362
- }
3363
- return {
3364
- accountPackages: [...state.accountPackages, accountPackage]
3365
- };
3366
- });
3367
- return accountPackage;
3368
- },
3369
- removeStar: (accountId, packageId) => {
3370
- set((state) => {
3371
- const packageIndex = state.packages.findIndex(
3372
- (pkg) => pkg.package_id === packageId
3373
- );
3374
- if (packageIndex >= 0) {
3375
- const updatedPackages = [...state.packages];
3376
- updatedPackages[packageIndex] = {
3377
- ...updatedPackages[packageIndex],
3378
- star_count: Math.max(
3379
- 0,
3380
- (updatedPackages[packageIndex].star_count || 0) - 1
3381
- )
3382
- };
3383
- return {
3384
- packages: updatedPackages,
3385
- accountPackages: state.accountPackages.filter(
3386
- (ap) => !(ap.account_id === accountId && ap.package_id === packageId)
3387
- )
3388
- };
3389
- }
3390
- return {
3391
- accountPackages: state.accountPackages.filter(
3392
- (ap) => !(ap.account_id === accountId && ap.package_id === packageId)
3393
- )
3394
- };
3395
- });
3396
- },
3397
- hasStarred: (accountId, packageId) => {
3398
- const state = get();
3399
- return state.accountPackages.some(
3400
- (ap) => ap.account_id === accountId && ap.package_id === packageId && ap.is_starred
3401
- );
3402
- },
3403
- addPackage: (_package) => {
3404
- const timestamp = Date.now();
3405
- const newPackage = {
3406
- package_id: `package_${timestamp}`,
3407
- github_repo_full_name: null,
3408
- latest_pcb_preview_image_url: _package.latest_pcb_preview_image_url ?? `/api/packages/images/${_package.name}`,
3409
- latest_cad_preview_image_url: _package.latest_cad_preview_image_url ?? `/api/packages/images/${_package.name}`,
3410
- latest_sch_preview_image_url: _package.latest_sch_preview_image_url ?? `/api/packages/images/${_package.name}`,
3411
- ..._package
3412
- };
3413
- set((state) => ({
3414
- packages: [...state.packages, newPackage]
3415
- }));
3416
- return newPackage;
3417
- },
3418
- updatePackage: (packageId, updates) => {
3419
- let updatedPackage;
3420
- set((state) => {
3421
- const packageIndex = state.packages.findIndex(
3422
- (pkg) => pkg.package_id === packageId
3423
- );
3424
- if (packageIndex === -1) return state;
3425
- const updatedPackages = [...state.packages];
3426
- updatedPackages[packageIndex] = {
3427
- ...updatedPackages[packageIndex],
3428
- ...updates
3429
- };
3430
- updatedPackage = updatedPackages[packageIndex];
3431
- return { ...state, packages: updatedPackages };
3432
- });
3433
- return updatedPackage;
3434
- },
3435
- getPackageById: (packageId) => {
3436
- const state = get();
3437
- const pkg = state.packages.find((pkg2) => pkg2.package_id === packageId);
3438
- if (!pkg) return void 0;
3439
- return {
3440
- ...pkg
3441
- };
3442
- },
3443
- getPackageReleaseById: (packageReleaseId) => {
3444
- const state = get();
3445
- return state.packageReleases.find(
3446
- (pr) => pr.package_release_id === packageReleaseId
3447
- );
3448
- },
3449
- addPackageRelease: (packageRelease) => {
3450
- const parsed = packageReleaseSchema.parse({
3451
- package_release_id: `package_release_${Date.now()}`,
3452
- ...packageRelease
3453
- });
3454
- set((state) => ({
3455
- packageReleases: [...state.packageReleases, parsed]
3456
- }));
3457
- return parsed;
3458
- },
3459
- updatePackageRelease: (packageRelease) => {
3460
- set((state) => ({
3461
- packageReleases: state.packageReleases.map(
3462
- (pr) => pr.package_release_id === packageRelease.package_release_id ? packageRelease : pr
3463
- )
3464
- }));
3465
- },
3466
- deletePackageFile: (packageFileId) => {
3467
- let deleted = false;
3468
- set((state) => {
3469
- const index = state.packageFiles.findIndex(
3470
- (file) => file.package_file_id === packageFileId
3471
- );
3472
- if (index !== -1) {
3473
- state.packageFiles.splice(index, 1);
3474
- deleted = true;
3475
- }
3476
- return state;
3477
- });
3478
- return deleted;
3479
- },
3480
- addPackageFile: (packageFile) => {
3481
- const newPackageFile = {
3482
- package_file_id: `package_file_${Date.now()}`,
3483
- ...packageFile
3484
- };
3485
- set((state) => ({
3486
- packageFiles: [...state.packageFiles, newPackageFile]
3487
- }));
3488
- return newPackageFile;
3489
- },
3490
- updatePackageFile: (packageFileId, updates) => {
3491
- set((state2) => ({
3492
- packageFiles: state2.packageFiles.map(
3493
- (file) => file.package_file_id === packageFileId ? { ...file, ...updates } : file
3494
- )
3495
- }));
3496
- const state = get();
3497
- return state.packageFiles.find(
3498
- (file) => file.package_file_id === packageFileId
3499
- );
3500
- },
3501
- getStarCount: (packageId) => {
3502
- const state = get();
3503
- return state.accountPackages.filter(
3504
- (ap) => ap.package_id === packageId && ap.is_starred
3505
- ).length;
3506
- },
3507
- getPackageFilesByReleaseId: (packageReleaseId) => {
3508
- const state = get();
3509
- return state.packageFiles.filter(
3510
- (pf) => pf.package_release_id === packageReleaseId
3511
- );
3512
- },
3513
- /**
3514
- * Update fs_sha for a package release based on its files
3515
- */
3516
- updatePackageReleaseFsSha: (packageReleaseId) => {
3517
- const state = get();
3518
- const packageFiles = state.packageFiles.filter(
3519
- (pf) => pf.package_release_id === packageReleaseId
3520
- );
3521
- const fsSha = generateFsSha(packageFiles);
3522
- set((currentState) => ({
3523
- ...currentState,
3524
- packageReleases: currentState.packageReleases.map(
3525
- (pr) => pr.package_release_id === packageReleaseId ? { ...pr, fs_sha: fsSha } : pr
3526
- ),
3527
- packages: currentState.packages.map(
3528
- (pkg) => pkg.latest_package_release_id === packageReleaseId ? { ...pkg, latest_package_release_fs_sha: fsSha } : pkg
3529
- )
3530
- }));
3531
- },
3532
- addAiReview: (review) => {
3533
- const base = aiReviewSchema.omit({ ai_review_id: true }).parse(review);
3534
- const newReview = {
3535
- ai_review_id: crypto.randomUUID(),
3536
- ...base
3537
- };
3538
- set((state) => ({
3539
- aiReviews: [...state.aiReviews, newReview],
3540
- idCounter: state.idCounter + 1
3541
- }));
3542
- return newReview;
3543
- },
3544
- updateAiReview: (aiReviewId, updates) => {
3545
- let updated;
3546
- set((state) => {
3547
- const index = state.aiReviews.findIndex(
3548
- (ar) => ar.ai_review_id === aiReviewId
3549
- );
3550
- if (index === -1) return state;
3551
- const aiReviews = [...state.aiReviews];
3552
- aiReviews[index] = { ...aiReviews[index], ...updates };
3553
- updated = aiReviews[index];
3554
- return { ...state, aiReviews };
3555
- });
3556
- return updated;
3557
- },
3558
- getAiReviewById: (aiReviewId) => {
3559
- const state = get();
3560
- return state.aiReviews.find((ar) => ar.ai_review_id === aiReviewId);
3561
- },
3562
- listAiReviews: () => {
3563
- const state = get();
3564
- return state.aiReviews;
3565
- },
3566
- addDatasheet: ({ chip_name }) => {
3567
- const newDatasheet = datasheetSchema.parse({
3568
- datasheet_id: crypto.randomUUID(),
3569
- chip_name,
3570
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
3571
- pin_information: null,
3572
- datasheet_pdf_urls: null,
3573
- ai_description: null
3574
- });
3575
- set((state) => ({
3576
- datasheets: [...state.datasheets, newDatasheet]
3577
- }));
3578
- return newDatasheet;
3579
- },
3580
- getDatasheetById: (datasheetId) => {
3581
- const state = get();
3582
- return state.datasheets.find((d) => d.datasheet_id === datasheetId);
3583
- },
3584
- getDatasheetByChipName: (chipName) => {
3585
- const state = get();
3586
- return state.datasheets.find(
3587
- (d) => d.chip_name.toLowerCase() === chipName.toLowerCase()
3588
- );
3589
- },
3590
- listDatasheets: ({
3591
- chip_name,
3592
- is_popular
3593
- } = {}) => {
3594
- const state = get();
3595
- if (is_popular) {
3596
- return state.datasheets;
3597
- }
3598
- if (chip_name) {
3599
- return state.datasheets.filter(
3600
- (d) => d.chip_name.toLowerCase() === chip_name.toLowerCase()
3601
- );
3602
- }
3603
- return state.datasheets;
3604
- },
3605
- updateDatasheet: (datasheetId, updates) => {
3606
- let updated;
3607
- set((state) => {
3608
- const index = state.datasheets.findIndex(
3609
- (d) => d.datasheet_id === datasheetId
3610
- );
3611
- if (index === -1) return state;
3612
- const datasheets = [...state.datasheets];
3613
- datasheets[index] = { ...datasheets[index], ...updates };
3614
- updated = datasheets[index];
3615
- return { ...state, datasheets };
3616
- });
3617
- return updated;
3618
- },
3619
- addPackageBuild: (packageBuild) => {
3620
- const newPackageBuild = packageBuildSchema.parse({
3621
- package_build_id: crypto.randomUUID(),
3622
- ...packageBuild
3623
- });
3624
- set((state) => ({
3625
- packageBuilds: [...state.packageBuilds, newPackageBuild],
3626
- // Automatically update the package release to reference this as the latest build
3627
- packageReleases: state.packageReleases.map(
3628
- (release) => release.package_release_id === packageBuild.package_release_id ? {
3629
- ...release,
3630
- latest_package_build_id: newPackageBuild.package_build_id
3631
- } : release
3632
- )
3633
- }));
3634
- return newPackageBuild;
3635
- },
3636
- getPackageBuildById: (packageBuildId) => {
3637
- const state = get();
3638
- return state.packageBuilds.find(
3639
- (pb) => pb.package_build_id === packageBuildId
3640
- );
3641
- },
3642
- getPackageBuildsByReleaseId: (packageReleaseId) => {
3643
- const state = get();
3644
- return state.packageBuilds.filter((pb) => pb.package_release_id === packageReleaseId).sort(
3645
- (a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
3646
- );
3647
- },
3648
- updatePackageBuild: (packageBuildId, updates) => {
3649
- let updated;
3650
- set((state) => {
3651
- const index = state.packageBuilds.findIndex(
3652
- (pb) => pb.package_build_id === packageBuildId
3653
- );
3654
- if (index === -1) return state;
3655
- const packageBuilds = [...state.packageBuilds];
3656
- packageBuilds[index] = { ...packageBuilds[index], ...updates };
3657
- updated = packageBuilds[index];
3658
- return { ...state, packageBuilds };
3659
- });
3660
- return updated;
3661
- },
3662
- addOrganization: (organization) => {
3663
- const newOrganization = {
3664
- org_name: organization.name,
3665
- org_id: organization.org_id || `org_${get().idCounter + 1}`,
3666
- github_handle: organization.github_handle,
3667
- is_personal_org: organization.is_personal_org || false,
3668
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
3669
- ...organization
3670
- };
3671
- set((state) => ({
3672
- idCounter: state.idCounter + 1,
3673
- organizations: [...state.organizations, newOrganization],
3674
- // Add the creator as a member of the new org by setting their personal_org_id
3675
- accounts: state.accounts.map(
3676
- (account) => account.account_id === organization.owner_account_id ? { ...account, personal_org_id: newOrganization.org_id } : account
3677
- )
3678
- }));
3679
- return newOrganization;
3680
- },
3681
- getOrgs: (filters, auth) => {
3682
- let orgs = get().organizations;
3683
- if (filters?.owner_account_id) {
3684
- orgs = orgs.filter(
3685
- (org) => org.owner_account_id === filters.owner_account_id
3686
- );
3687
- }
3688
- if (filters?.github_handle) {
3689
- orgs = orgs.filter((org) => {
3690
- const account = get().accounts.find(
3691
- (account2) => account2.account_id === org.owner_account_id
3692
- );
3693
- return account?.github_username === filters.github_handle;
3694
- });
3695
- }
3696
- if (filters?.name) {
3697
- orgs = orgs.filter((org) => org.github_handle === filters.name);
3698
- }
3699
- return orgs.map((org) => {
3700
- const member_count = get().accounts.filter(
3701
- (account) => account.personal_org_id === org.org_id
3702
- ).length;
3703
- const package_count = get().packages.filter(
3704
- (pkg) => pkg.owner_org_id === org.org_id
3705
- ).length;
3706
- const can_manage_org = auth ? org.owner_account_id === auth.account_id : false;
3707
- return {
3708
- ...org,
3709
- member_count,
3710
- package_count,
3711
- can_manage_org
3712
- };
3713
- });
3714
- },
3715
- getOrg: (filters, auth) => {
3716
- let orgs = get().organizations;
3717
- if (filters?.org_id) {
3718
- orgs = orgs.filter((org2) => org2.org_id === filters.org_id);
3719
- }
3720
- if (filters?.org_name) {
3721
- orgs = orgs.filter((org2) => org2.org_name === filters.org_name);
3722
- }
3723
- if (filters?.github_handle) {
3724
- orgs = orgs.filter((org2) => org2.github_handle === filters.github_handle);
3725
- }
3726
- if (orgs.length === 0) {
3727
- return null;
3728
- }
3729
- const org = orgs[0];
3730
- const member_count = get().accounts.filter(
3731
- (account) => account.personal_org_id === org.org_id
3732
- ).length;
3733
- const package_count = get().packages.filter(
3734
- (pkg) => pkg.owner_org_id === org.org_id
3735
- ).length;
3736
- const can_manage_org = auth ? org.owner_account_id === auth.account_id : false;
3737
- return {
3738
- ...org,
3739
- member_count,
3740
- package_count,
3741
- can_manage_org
3742
- };
3743
- },
3744
- addOrganizationAccount: (organizationAccount) => {
3745
- const newOrgAccount = {
3746
- org_account_id: `org_account_${get().idCounter + 1}`,
3747
- org_id: organizationAccount.org_id,
3748
- account_id: organizationAccount.account_id,
3749
- is_owner: organizationAccount.is_owner || false,
3750
- created_at: (/* @__PURE__ */ new Date()).toISOString()
3751
- };
3752
- set((state) => ({
3753
- orgAccounts: [...state.orgAccounts, newOrgAccount],
3754
- idCounter: state.idCounter + 1
3755
- }));
3756
- return newOrgAccount;
3757
- },
3758
- getOrganizationAccount: (filters) => {
3759
- const state = get();
3760
- return state.orgAccounts.find((orgAccount) => {
3761
- if (filters.org_id && orgAccount.org_id !== filters.org_id) {
3762
- return false;
3763
- }
3764
- if (filters.account_id && orgAccount.account_id !== filters.account_id) {
3765
- return false;
3766
- }
3767
- return true;
3768
- });
3769
- },
3770
- getOrganizationAccounts: (filters) => {
3771
- const state = get();
3772
- return state.orgAccounts.filter((orgAccount) => {
3773
- if (filters?.org_id && orgAccount.org_id !== filters.org_id) {
3774
- return false;
3775
- }
3776
- if (filters?.account_id && orgAccount.account_id !== filters.account_id) {
3777
- return false;
3778
- }
3779
- return true;
3780
- });
3781
- },
3782
- removeOrganizationAccount: (filters) => {
3783
- let removed = false;
3784
- set((state) => {
3785
- const index = state.orgAccounts.findIndex(
3786
- (orgAccount) => orgAccount.org_id === filters.org_id && orgAccount.account_id === filters.account_id
3787
- );
3788
- if (index !== -1) {
3789
- state.orgAccounts.splice(index, 1);
3790
- removed = true;
3791
- }
3792
- return state;
3793
- });
3794
- return removed;
3795
- },
3796
- updateOrganization: (orgId, updates) => {
3797
- let updatedOrg;
3798
- set((state) => {
3799
- const orgIndex = state.organizations.findIndex(
3800
- (org) => org.org_id === orgId
3801
- );
3802
- if (orgIndex === -1) return state;
3803
- const updatedOrganizations = [...state.organizations];
3804
- updatedOrganizations[orgIndex] = {
3805
- ...updatedOrganizations[orgIndex],
3806
- ...updates
3807
- };
3808
- updatedOrg = updatedOrganizations[orgIndex];
3809
- return { ...state, organizations: updatedOrganizations };
3810
- });
3811
- return updatedOrg;
3812
- }
3813
- }));
3814
-
3815
- // fake-snippets-api/lib/middleware/with-db.ts
3816
- var withDb = async (req, ctx, next) => {
3817
- if (!ctx.db) {
3818
- ctx.db = createDatabase();
3819
- }
3820
- return next(req, ctx);
3821
- };
3822
- export {
3823
- createDatabase,
3824
- seed,
3825
- withDb
3826
- };