@tscircuit/fake-snippets 0.0.21 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,2759 @@
1
+ // fake-snippets-api/lib/db/db-client.ts
2
+ import { hoist } from "zustand-hoist";
3
+ import { createStore } from "zustand/vanilla";
4
+ import { combine } from "zustand/middleware";
5
+
6
+ // fake-snippets-api/lib/db/schema.ts
7
+ import { z } from "zod";
8
+ var errorSchema = z.object({
9
+ error_code: z.string(),
10
+ message: z.string()
11
+ }).passthrough();
12
+ var errorResponseSchema = z.object({
13
+ error: errorSchema
14
+ });
15
+ var snippetSchema = z.object({
16
+ snippet_id: z.string(),
17
+ package_release_id: z.string(),
18
+ name: z.string(),
19
+ unscoped_name: z.string(),
20
+ owner_name: z.string(),
21
+ is_starred: z.boolean().default(false),
22
+ code: z.string(),
23
+ dts: z.string().optional(),
24
+ compiled_js: z.string().optional().nullable(),
25
+ circuit_json: z.array(z.record(z.any())).optional().nullable(),
26
+ manual_edits_json_content: z.string().optional().nullable(),
27
+ created_at: z.string(),
28
+ updated_at: z.string(),
29
+ snippet_type: z.enum(["board", "package", "model", "footprint"]),
30
+ description: z.string().optional(),
31
+ version: z.string().default("0.0.1"),
32
+ star_count: z.number().default(0),
33
+ is_private: z.boolean().default(false),
34
+ is_public: z.boolean().default(true),
35
+ is_unlisted: z.boolean().default(false)
36
+ });
37
+ var sessionSchema = z.object({
38
+ session_id: z.string(),
39
+ account_id: z.string(),
40
+ expires_at: z.string(),
41
+ is_cli_session: z.boolean()
42
+ });
43
+ var loginPageSchema = z.object({
44
+ login_page_id: z.string(),
45
+ login_page_auth_token: z.string(),
46
+ was_login_successful: z.boolean(),
47
+ has_been_used_to_create_session: z.boolean(),
48
+ created_at: z.string(),
49
+ expires_at: z.string()
50
+ });
51
+ var shippingInfoSchema = z.object({
52
+ firstName: z.string(),
53
+ lastName: z.string(),
54
+ companyName: z.string().optional(),
55
+ address: z.string(),
56
+ apartment: z.string().optional(),
57
+ city: z.string(),
58
+ state: z.string(),
59
+ zipCode: z.string(),
60
+ country: z.string(),
61
+ phone: z.string()
62
+ });
63
+ var accountSchema = z.object({
64
+ account_id: z.string(),
65
+ github_username: z.string(),
66
+ shippingInfo: shippingInfoSchema.optional()
67
+ });
68
+ var orderSchema = z.object({
69
+ order_id: z.string(),
70
+ account_id: z.string().nullable(),
71
+ is_running: z.boolean(),
72
+ is_started: z.boolean(),
73
+ is_finished: z.boolean(),
74
+ error: errorSchema.nullable(),
75
+ has_error: z.boolean(),
76
+ created_at: z.string(),
77
+ started_at: z.string().nullable(),
78
+ completed_at: z.string().nullable(),
79
+ circuit_json: z.any()
80
+ });
81
+ var orderFileSchema = z.object({
82
+ order_file_id: z.string(),
83
+ order_id: z.string(),
84
+ is_gerbers_zip: z.boolean(),
85
+ content_type: z.string(),
86
+ for_provider: z.string().nullable(),
87
+ uploaded_at: z.string(),
88
+ content_text: z.string().nullable(),
89
+ content_bytes: z.instanceof(Uint8Array).nullable()
90
+ });
91
+ var accountSnippetSchema = z.object({
92
+ account_id: z.string(),
93
+ snippet_id: z.string(),
94
+ has_starred: z.boolean(),
95
+ created_at: z.string(),
96
+ updated_at: z.string()
97
+ });
98
+ var accountPackageSchema = z.object({
99
+ account_package_id: z.string(),
100
+ account_id: z.string(),
101
+ package_id: z.string(),
102
+ is_starred: z.boolean(),
103
+ created_at: z.string(),
104
+ updated_at: z.string()
105
+ });
106
+ var packageReleaseSchema = z.object({
107
+ package_release_id: z.string(),
108
+ package_id: z.string(),
109
+ version: z.string().nullable(),
110
+ is_locked: z.boolean(),
111
+ is_latest: z.boolean(),
112
+ created_at: z.string().datetime(),
113
+ commit_sha: z.string().nullable().optional(),
114
+ license: z.string().nullable().optional()
115
+ });
116
+ var packageFileSchema = z.object({
117
+ package_file_id: z.string(),
118
+ package_release_id: z.string(),
119
+ file_path: z.string(),
120
+ content_text: z.string().nullable().optional(),
121
+ created_at: z.string().datetime()
122
+ });
123
+ var packageSchema = z.object({
124
+ package_id: z.string(),
125
+ creator_account_id: z.string(),
126
+ owner_org_id: z.string(),
127
+ owner_github_username: z.string().nullable(),
128
+ name: z.string(),
129
+ unscoped_name: z.string(),
130
+ description: z.string().nullable(),
131
+ created_at: z.string().datetime(),
132
+ updated_at: z.string().datetime(),
133
+ is_snippet: z.boolean().default(false),
134
+ is_board: z.boolean().default(false),
135
+ is_package: z.boolean().default(false),
136
+ is_model: z.boolean().default(false),
137
+ is_footprint: z.boolean().default(false),
138
+ is_private: z.boolean().nullable().default(false),
139
+ is_public: z.boolean().nullable().default(true),
140
+ is_unlisted: z.boolean().nullable().default(false),
141
+ is_source_from_github: z.boolean().default(false),
142
+ snippet_type: z.enum(["board", "package", "model", "footprint"]).optional(),
143
+ latest_package_release_id: z.string().nullable(),
144
+ latest_version: z.string().nullable(),
145
+ license: z.string().nullable(),
146
+ star_count: z.number().default(0),
147
+ ai_description: z.string().nullable()
148
+ });
149
+ var jlcpcbOrderStateSchema = z.object({
150
+ jlcpcb_order_state_id: z.string(),
151
+ order_id: z.string(),
152
+ are_gerbers_uploaded: z.boolean().default(false),
153
+ is_gerber_analyzed: z.boolean().default(false),
154
+ are_initial_costs_calculated: z.boolean().default(false),
155
+ is_pcb_added_to_cart: z.boolean().default(false),
156
+ is_bom_uploaded: z.boolean().default(false),
157
+ is_pnp_uploaded: z.boolean().default(false),
158
+ is_bom_pnp_analyzed: z.boolean().default(false),
159
+ is_bom_parsing_complete: z.boolean().default(false),
160
+ are_components_available: z.boolean().default(false),
161
+ is_patch_map_generated: z.boolean().default(false),
162
+ is_json_merge_file_created: z.boolean().default(false),
163
+ is_dfm_result_generated: z.boolean().default(false),
164
+ are_files_downloaded: z.boolean().default(false),
165
+ are_product_categories_fetched: z.boolean().default(false),
166
+ are_final_costs_calculated: z.boolean().default(false),
167
+ is_json_merge_file_updated: z.boolean().default(false),
168
+ is_added_to_cart: z.boolean().default(false),
169
+ uploaded_gerber_metadata: z.any().nullable().default(null),
170
+ gerber_analysis: z.any().nullable().default(null),
171
+ created_at: z.string(),
172
+ are_gerbers_generated: z.boolean().default(false),
173
+ current_step: z.string().nullable().default(null)
174
+ });
175
+ var jlcpcbOrderStepRunSchema = z.object({
176
+ jlcpcb_order_step_run_id: z.string(),
177
+ is_running: z.boolean().nullable().default(null),
178
+ step_function_name: z.string().nullable().default(null),
179
+ jlcpcb_order_state_id: z.string().nullable().default(null),
180
+ error_message: z.string().nullable().default(null),
181
+ created_at: z.string()
182
+ });
183
+ var databaseSchema = z.object({
184
+ idCounter: z.number().default(0),
185
+ snippets: z.array(snippetSchema).default([]),
186
+ packageReleases: z.array(packageReleaseSchema).default([]),
187
+ packageFiles: z.array(packageFileSchema).default([]),
188
+ sessions: z.array(sessionSchema).default([]),
189
+ loginPages: z.array(loginPageSchema).default([]),
190
+ accounts: z.array(accountSchema).default([]),
191
+ packages: z.array(packageSchema).default([]),
192
+ orders: z.array(orderSchema).default([]),
193
+ orderFiles: z.array(orderFileSchema).default([]),
194
+ accountSnippets: z.array(accountSnippetSchema).default([]),
195
+ accountPackages: z.array(accountPackageSchema).default([]),
196
+ jlcpcbOrderState: z.array(jlcpcbOrderStateSchema).default([]),
197
+ jlcpcbOrderStepRuns: z.array(jlcpcbOrderStepRunSchema).default([])
198
+ });
199
+
200
+ // fake-snippets-api/lib/db/autoload-dev-snippets.ts
201
+ import axios from "redaxios";
202
+ import fs from "fs";
203
+ import path from "path";
204
+ var extractTsciDependencies = (code) => {
205
+ const regex = /@tsci\/([^.]+)\.([^"'\s]+)/g;
206
+ const matches = Array.from(code.matchAll(regex));
207
+ return matches.map((match) => ({
208
+ owner: match[1],
209
+ name: match[2]
210
+ }));
211
+ };
212
+ var registryApi = axios.create({
213
+ baseURL: "https://registry-api.tscircuit.com",
214
+ headers: {
215
+ Accept: "application/json",
216
+ "Content-Type": "application/json"
217
+ }
218
+ });
219
+ var fetchSnippetFromRegistry = async (owner, name) => {
220
+ const response = await registryApi.get(
221
+ `/snippets/get?owner_name=${owner}&unscoped_name=${name}`
222
+ );
223
+ return response.data.snippet;
224
+ };
225
+ var loadSnippetWithDependencies = async (db, owner, name, loadedSnippets = /* @__PURE__ */ new Set()) => {
226
+ const snippetKey = `${owner}/${name}`;
227
+ if (loadedSnippets.has(snippetKey)) {
228
+ return;
229
+ }
230
+ try {
231
+ const snippet = await fetchSnippetFromRegistry(owner, name);
232
+ if (db.getSnippetByAuthorAndName(owner, name)) return;
233
+ db.addSnippet(snippet);
234
+ loadedSnippets.add(snippetKey);
235
+ const dependencies = extractTsciDependencies(snippet.code);
236
+ for (const dep of dependencies) {
237
+ loadSnippetWithDependencies(db, dep.owner, dep.name, loadedSnippets);
238
+ }
239
+ } catch (e) {
240
+ console.error(`\u2717 Failed to load ${snippetKey}:`, e);
241
+ }
242
+ };
243
+ var loadAutoloadSnippets = async (db) => {
244
+ try {
245
+ const autoloadPath = path.join(
246
+ path.dirname(__dirname),
247
+ "db",
248
+ "autoload-snippets.json"
249
+ );
250
+ if (fs.existsSync(autoloadPath)) {
251
+ const autoloadContent = JSON.parse(fs.readFileSync(autoloadPath, "utf8"));
252
+ console.log("Loading development snippets from registry...");
253
+ const loadedSnippets = /* @__PURE__ */ new Set();
254
+ for (const snippetRef of autoloadContent.snippets) {
255
+ loadSnippetWithDependencies(
256
+ db,
257
+ snippetRef.owner,
258
+ snippetRef.name,
259
+ loadedSnippets
260
+ );
261
+ }
262
+ }
263
+ } catch (e) {
264
+ console.error("Failed to load autoload-snippets.json:", e);
265
+ }
266
+ };
267
+
268
+ // fake-snippets-api/lib/db/seed.ts
269
+ var seed = (db) => {
270
+ const { account_id } = db.addAccount({
271
+ account_id: "account-1234",
272
+ github_username: "testuser",
273
+ shippingInfo: {
274
+ firstName: "Test",
275
+ lastName: "User",
276
+ companyName: "Test Company",
277
+ address: "123 Test St",
278
+ apartment: "Apt 4B",
279
+ city: "Testville",
280
+ state: "NY",
281
+ zipCode: "10001",
282
+ country: "United States of America",
283
+ phone: "555-123-4567"
284
+ }
285
+ });
286
+ db.addAccount({
287
+ github_username: "seveibar"
288
+ });
289
+ if (process.env.AUTOLOAD_SNIPPETS === "true") {
290
+ loadAutoloadSnippets(db);
291
+ }
292
+ db.addSnippet({
293
+ name: "testuser/my-test-board",
294
+ unscoped_name: "my-test-board",
295
+ owner_name: "testuser",
296
+ code: `
297
+ import { A555Timer } from "@tsci/seveibar.a555timer"
298
+
299
+ export default () => (
300
+ <board width="10mm" height="10mm">
301
+ <A555Timer name="U1" />
302
+ </board>
303
+ )`.trim(),
304
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
305
+ updated_at: (/* @__PURE__ */ new Date()).toISOString(),
306
+ snippet_type: "board",
307
+ description: "A simple board with an A555 Timer component",
308
+ circuit_json: [
309
+ {
310
+ type: "source_port",
311
+ source_port_id: "source_port_0",
312
+ name: "pin1",
313
+ pin_number: 1,
314
+ port_hints: ["pin1", "1"],
315
+ source_component_id: "source_component_0"
316
+ },
317
+ {
318
+ type: "source_port",
319
+ source_port_id: "source_port_1",
320
+ name: "pin2",
321
+ pin_number: 2,
322
+ port_hints: ["pin2", "2"],
323
+ source_component_id: "source_component_0"
324
+ },
325
+ {
326
+ type: "source_port",
327
+ source_port_id: "source_port_2",
328
+ name: "pin3",
329
+ pin_number: 3,
330
+ port_hints: ["pin3", "3"],
331
+ source_component_id: "source_component_0"
332
+ },
333
+ {
334
+ type: "source_port",
335
+ source_port_id: "source_port_3",
336
+ name: "pin4",
337
+ pin_number: 4,
338
+ port_hints: ["pin4", "4"],
339
+ source_component_id: "source_component_0"
340
+ },
341
+ {
342
+ type: "source_port",
343
+ source_port_id: "source_port_4",
344
+ name: "pin5",
345
+ pin_number: 5,
346
+ port_hints: ["pin5", "5"],
347
+ source_component_id: "source_component_0"
348
+ },
349
+ {
350
+ type: "source_port",
351
+ source_port_id: "source_port_5",
352
+ name: "pin6",
353
+ pin_number: 6,
354
+ port_hints: ["pin6", "6"],
355
+ source_component_id: "source_component_0"
356
+ },
357
+ {
358
+ type: "source_port",
359
+ source_port_id: "source_port_6",
360
+ name: "pin7",
361
+ pin_number: 7,
362
+ port_hints: ["pin7", "7"],
363
+ source_component_id: "source_component_0"
364
+ },
365
+ {
366
+ type: "source_port",
367
+ source_port_id: "source_port_7",
368
+ name: "pin8",
369
+ pin_number: 8,
370
+ port_hints: ["pin8", "8"],
371
+ source_component_id: "source_component_0"
372
+ },
373
+ {
374
+ type: "source_component",
375
+ source_component_id: "source_component_0",
376
+ ftype: "simple_chip",
377
+ name: "U1",
378
+ supplier_part_numbers: {}
379
+ },
380
+ {
381
+ type: "schematic_component",
382
+ schematic_component_id: "schematic_component_0",
383
+ center: {
384
+ x: 0,
385
+ y: 0
386
+ },
387
+ rotation: 0,
388
+ size: {
389
+ width: 1.1,
390
+ height: 1
391
+ },
392
+ pin_spacing: 0.2,
393
+ port_labels: {},
394
+ source_component_id: "source_component_0"
395
+ },
396
+ {
397
+ type: "schematic_port",
398
+ schematic_port_id: "schematic_port_0",
399
+ schematic_component_id: "schematic_component_0",
400
+ center: {
401
+ x: -0.9500000000000001,
402
+ y: 0.30000000000000004
403
+ },
404
+ source_port_id: "source_port_0",
405
+ facing_direction: "left",
406
+ distance_from_component_edge: 0.4,
407
+ side_of_component: "left",
408
+ pin_number: 1,
409
+ true_ccw_index: 0
410
+ },
411
+ {
412
+ type: "schematic_port",
413
+ schematic_port_id: "schematic_port_1",
414
+ schematic_component_id: "schematic_component_0",
415
+ center: {
416
+ x: -0.9500000000000001,
417
+ y: 0.10000000000000003
418
+ },
419
+ source_port_id: "source_port_1",
420
+ facing_direction: "left",
421
+ distance_from_component_edge: 0.4,
422
+ side_of_component: "left",
423
+ pin_number: 2,
424
+ true_ccw_index: 1
425
+ },
426
+ {
427
+ type: "schematic_port",
428
+ schematic_port_id: "schematic_port_2",
429
+ schematic_component_id: "schematic_component_0",
430
+ center: {
431
+ x: -0.9500000000000001,
432
+ y: -0.09999999999999998
433
+ },
434
+ source_port_id: "source_port_2",
435
+ facing_direction: "left",
436
+ distance_from_component_edge: 0.4,
437
+ side_of_component: "left",
438
+ pin_number: 3,
439
+ true_ccw_index: 2
440
+ },
441
+ {
442
+ type: "schematic_port",
443
+ schematic_port_id: "schematic_port_3",
444
+ schematic_component_id: "schematic_component_0",
445
+ center: {
446
+ x: -0.9500000000000001,
447
+ y: -0.30000000000000004
448
+ },
449
+ source_port_id: "source_port_3",
450
+ facing_direction: "left",
451
+ distance_from_component_edge: 0.4,
452
+ side_of_component: "left",
453
+ pin_number: 4,
454
+ true_ccw_index: 3
455
+ },
456
+ {
457
+ type: "schematic_port",
458
+ schematic_port_id: "schematic_port_4",
459
+ schematic_component_id: "schematic_component_0",
460
+ center: {
461
+ x: 0.9500000000000001,
462
+ y: -0.30000000000000004
463
+ },
464
+ source_port_id: "source_port_4",
465
+ facing_direction: "right",
466
+ distance_from_component_edge: 0.4,
467
+ side_of_component: "right",
468
+ pin_number: 5,
469
+ true_ccw_index: 4
470
+ },
471
+ {
472
+ type: "schematic_port",
473
+ schematic_port_id: "schematic_port_5",
474
+ schematic_component_id: "schematic_component_0",
475
+ center: {
476
+ x: 0.9500000000000001,
477
+ y: -0.10000000000000003
478
+ },
479
+ source_port_id: "source_port_5",
480
+ facing_direction: "right",
481
+ distance_from_component_edge: 0.4,
482
+ side_of_component: "right",
483
+ pin_number: 6,
484
+ true_ccw_index: 5
485
+ },
486
+ {
487
+ type: "schematic_port",
488
+ schematic_port_id: "schematic_port_6",
489
+ schematic_component_id: "schematic_component_0",
490
+ center: {
491
+ x: 0.9500000000000001,
492
+ y: 0.09999999999999998
493
+ },
494
+ source_port_id: "source_port_6",
495
+ facing_direction: "right",
496
+ distance_from_component_edge: 0.4,
497
+ side_of_component: "right",
498
+ pin_number: 7,
499
+ true_ccw_index: 6
500
+ },
501
+ {
502
+ type: "schematic_port",
503
+ schematic_port_id: "schematic_port_7",
504
+ schematic_component_id: "schematic_component_0",
505
+ center: {
506
+ x: 0.9500000000000001,
507
+ y: 0.30000000000000004
508
+ },
509
+ source_port_id: "source_port_7",
510
+ facing_direction: "right",
511
+ distance_from_component_edge: 0.4,
512
+ side_of_component: "right",
513
+ pin_number: 8,
514
+ true_ccw_index: 7
515
+ },
516
+ {
517
+ type: "pcb_component",
518
+ pcb_component_id: "pcb_component_0",
519
+ center: {
520
+ x: 0,
521
+ y: 0
522
+ },
523
+ width: 8.82,
524
+ height: 8.82,
525
+ layer: "top",
526
+ rotation: 0,
527
+ source_component_id: "source_component_0"
528
+ },
529
+ {
530
+ type: "pcb_board",
531
+ pcb_board_id: "pcb_board_0",
532
+ center: {
533
+ x: 0,
534
+ y: 0
535
+ },
536
+ thickness: 1.4,
537
+ num_layers: 4,
538
+ width: 10,
539
+ height: 10
540
+ },
541
+ {
542
+ type: "pcb_plated_hole",
543
+ pcb_plated_hole_id: "pcb_plated_hole_0",
544
+ pcb_component_id: "pcb_component_0",
545
+ pcb_port_id: "pcb_port_0",
546
+ outer_diameter: 1.2,
547
+ hole_diameter: 1,
548
+ shape: "circle",
549
+ port_hints: ["1"],
550
+ x: -3.81,
551
+ y: 3.81,
552
+ layers: ["top", "bottom"]
553
+ },
554
+ {
555
+ type: "pcb_plated_hole",
556
+ pcb_plated_hole_id: "pcb_plated_hole_1",
557
+ pcb_component_id: "pcb_component_0",
558
+ pcb_port_id: "pcb_port_1",
559
+ outer_diameter: 1.2,
560
+ hole_diameter: 1,
561
+ shape: "circle",
562
+ port_hints: ["2"],
563
+ x: -3.81,
564
+ y: 1.27,
565
+ layers: ["top", "bottom"]
566
+ },
567
+ {
568
+ type: "pcb_plated_hole",
569
+ pcb_plated_hole_id: "pcb_plated_hole_2",
570
+ pcb_component_id: "pcb_component_0",
571
+ pcb_port_id: "pcb_port_2",
572
+ outer_diameter: 1.2,
573
+ hole_diameter: 1,
574
+ shape: "circle",
575
+ port_hints: ["3"],
576
+ x: -3.81,
577
+ y: -1.27,
578
+ layers: ["top", "bottom"]
579
+ },
580
+ {
581
+ type: "pcb_plated_hole",
582
+ pcb_plated_hole_id: "pcb_plated_hole_3",
583
+ pcb_component_id: "pcb_component_0",
584
+ pcb_port_id: "pcb_port_3",
585
+ outer_diameter: 1.2,
586
+ hole_diameter: 1,
587
+ shape: "circle",
588
+ port_hints: ["4"],
589
+ x: -3.81,
590
+ y: -3.81,
591
+ layers: ["top", "bottom"]
592
+ },
593
+ {
594
+ type: "pcb_plated_hole",
595
+ pcb_plated_hole_id: "pcb_plated_hole_4",
596
+ pcb_component_id: "pcb_component_0",
597
+ pcb_port_id: "pcb_port_4",
598
+ outer_diameter: 1.2,
599
+ hole_diameter: 1,
600
+ shape: "circle",
601
+ port_hints: ["5"],
602
+ x: 3.81,
603
+ y: -3.81,
604
+ layers: ["top", "bottom"]
605
+ },
606
+ {
607
+ type: "pcb_plated_hole",
608
+ pcb_plated_hole_id: "pcb_plated_hole_5",
609
+ pcb_component_id: "pcb_component_0",
610
+ pcb_port_id: "pcb_port_5",
611
+ outer_diameter: 1.2,
612
+ hole_diameter: 1,
613
+ shape: "circle",
614
+ port_hints: ["6"],
615
+ x: 3.81,
616
+ y: -1.27,
617
+ layers: ["top", "bottom"]
618
+ },
619
+ {
620
+ type: "pcb_plated_hole",
621
+ pcb_plated_hole_id: "pcb_plated_hole_6",
622
+ pcb_component_id: "pcb_component_0",
623
+ pcb_port_id: "pcb_port_6",
624
+ outer_diameter: 1.2,
625
+ hole_diameter: 1,
626
+ shape: "circle",
627
+ port_hints: ["7"],
628
+ x: 3.81,
629
+ y: 1.27,
630
+ layers: ["top", "bottom"]
631
+ },
632
+ {
633
+ type: "pcb_plated_hole",
634
+ pcb_plated_hole_id: "pcb_plated_hole_7",
635
+ pcb_component_id: "pcb_component_0",
636
+ pcb_port_id: "pcb_port_7",
637
+ outer_diameter: 1.2,
638
+ hole_diameter: 1,
639
+ shape: "circle",
640
+ port_hints: ["8"],
641
+ x: 3.81,
642
+ y: 3.81,
643
+ layers: ["top", "bottom"]
644
+ },
645
+ {
646
+ type: "pcb_silkscreen_path",
647
+ pcb_silkscreen_path_id: "pcb_silkscreen_path_0",
648
+ pcb_component_id: "pcb_component_0",
649
+ layer: "top",
650
+ route: [
651
+ {
652
+ x: -3.01,
653
+ y: -4.61
654
+ },
655
+ {
656
+ x: -3.01,
657
+ y: 4.61
658
+ },
659
+ {
660
+ x: -1.0033333333333332,
661
+ y: 4.61
662
+ },
663
+ {
664
+ x: -0.9269591309529909,
665
+ y: 4.226040956193693
666
+ },
667
+ {
668
+ x: -0.7094638037905026,
669
+ y: 3.9005361962094978
670
+ },
671
+ {
672
+ x: -0.3839590438063067,
673
+ y: 3.6830408690470096
674
+ },
675
+ {
676
+ x: 6143644775722556e-32,
677
+ y: 3.6066666666666674
678
+ },
679
+ {
680
+ x: 0.38395904380630674,
681
+ y: 3.6830408690470096
682
+ },
683
+ {
684
+ x: 0.7094638037905027,
685
+ y: 3.9005361962094978
686
+ },
687
+ {
688
+ x: 0.9269591309529909,
689
+ y: 4.226040956193693
690
+ },
691
+ {
692
+ x: 1.0033333333333332,
693
+ y: 4.61
694
+ },
695
+ {
696
+ x: 3.01,
697
+ y: 4.61
698
+ },
699
+ {
700
+ x: 3.01,
701
+ y: -4.61
702
+ },
703
+ {
704
+ x: -3.01,
705
+ y: -4.61
706
+ }
707
+ ],
708
+ stroke_width: 0.1
709
+ },
710
+ {
711
+ type: "pcb_port",
712
+ pcb_port_id: "pcb_port_0",
713
+ pcb_component_id: "pcb_component_0",
714
+ layers: ["top", "inner1", "inner2", "bottom"],
715
+ x: -3.81,
716
+ y: 3.81,
717
+ source_port_id: "source_port_0"
718
+ },
719
+ {
720
+ type: "pcb_port",
721
+ pcb_port_id: "pcb_port_1",
722
+ pcb_component_id: "pcb_component_0",
723
+ layers: ["top", "inner1", "inner2", "bottom"],
724
+ x: -3.81,
725
+ y: 1.27,
726
+ source_port_id: "source_port_1"
727
+ },
728
+ {
729
+ type: "pcb_port",
730
+ pcb_port_id: "pcb_port_2",
731
+ pcb_component_id: "pcb_component_0",
732
+ layers: ["top", "inner1", "inner2", "bottom"],
733
+ x: -3.81,
734
+ y: -1.27,
735
+ source_port_id: "source_port_2"
736
+ },
737
+ {
738
+ type: "pcb_port",
739
+ pcb_port_id: "pcb_port_3",
740
+ pcb_component_id: "pcb_component_0",
741
+ layers: ["top", "inner1", "inner2", "bottom"],
742
+ x: -3.81,
743
+ y: -3.81,
744
+ source_port_id: "source_port_3"
745
+ },
746
+ {
747
+ type: "pcb_port",
748
+ pcb_port_id: "pcb_port_4",
749
+ pcb_component_id: "pcb_component_0",
750
+ layers: ["top", "inner1", "inner2", "bottom"],
751
+ x: 3.81,
752
+ y: -3.81,
753
+ source_port_id: "source_port_4"
754
+ },
755
+ {
756
+ type: "pcb_port",
757
+ pcb_port_id: "pcb_port_5",
758
+ pcb_component_id: "pcb_component_0",
759
+ layers: ["top", "inner1", "inner2", "bottom"],
760
+ x: 3.81,
761
+ y: -1.27,
762
+ source_port_id: "source_port_5"
763
+ },
764
+ {
765
+ type: "pcb_port",
766
+ pcb_port_id: "pcb_port_6",
767
+ pcb_component_id: "pcb_component_0",
768
+ layers: ["top", "inner1", "inner2", "bottom"],
769
+ x: 3.81,
770
+ y: 1.27,
771
+ source_port_id: "source_port_6"
772
+ },
773
+ {
774
+ type: "pcb_port",
775
+ pcb_port_id: "pcb_port_7",
776
+ pcb_component_id: "pcb_component_0",
777
+ layers: ["top", "inner1", "inner2", "bottom"],
778
+ x: 3.81,
779
+ y: 3.81,
780
+ source_port_id: "source_port_7"
781
+ },
782
+ {
783
+ type: "cad_component",
784
+ cad_component_id: "cad_component_0",
785
+ position: {
786
+ x: 0,
787
+ y: 0,
788
+ z: 0.7
789
+ },
790
+ rotation: {
791
+ x: 0,
792
+ y: 0,
793
+ z: 0
794
+ },
795
+ pcb_component_id: "pcb_component_0",
796
+ source_component_id: "source_component_0",
797
+ footprinter_string: "dip8"
798
+ }
799
+ ]
800
+ });
801
+ db.addSnippet({
802
+ name: "seveibar/a555timer",
803
+ unscoped_name: "a555timer",
804
+ owner_name: "seveibar",
805
+ code: `
806
+ export const A555Timer = ({ name }: { name: string }) => (
807
+ <chip name={name} footprint="dip8" />
808
+ )
809
+ `.trim(),
810
+ dts: `
811
+ declare module "@tsci/seveibar.a555timer" {
812
+ export const A555Timer: ({ name }: {
813
+ name: string;
814
+ }) => any;
815
+ }
816
+ `.trim(),
817
+ compiled_js: `
818
+ "use strict";
819
+
820
+ Object.defineProperty(exports, "__esModule", {
821
+ value: true
822
+ });
823
+ exports.A555Timer = void 0;
824
+ const A555Timer = ({
825
+ name
826
+ }) => /*#__PURE__*/React.createElement("chip", {
827
+ name: name,
828
+ footprint: "dip8"
829
+ });
830
+ exports.A555Timer = A555Timer;
831
+ `.trim(),
832
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
833
+ updated_at: (/* @__PURE__ */ new Date()).toISOString(),
834
+ snippet_type: "package",
835
+ description: "A simple package with an A555 Timer component",
836
+ circuit_json: [
837
+ {
838
+ type: "source_port",
839
+ source_port_id: "source_port_0",
840
+ name: "pin1",
841
+ pin_number: 1,
842
+ port_hints: ["pin1", "1"],
843
+ source_component_id: "source_component_0"
844
+ },
845
+ {
846
+ type: "source_port",
847
+ source_port_id: "source_port_1",
848
+ name: "pin2",
849
+ pin_number: 2,
850
+ port_hints: ["pin2", "2"],
851
+ source_component_id: "source_component_0"
852
+ },
853
+ {
854
+ type: "source_port",
855
+ source_port_id: "source_port_2",
856
+ name: "pin3",
857
+ pin_number: 3,
858
+ port_hints: ["pin3", "3"],
859
+ source_component_id: "source_component_0"
860
+ },
861
+ {
862
+ type: "source_port",
863
+ source_port_id: "source_port_3",
864
+ name: "pin4",
865
+ pin_number: 4,
866
+ port_hints: ["pin4", "4"],
867
+ source_component_id: "source_component_0"
868
+ },
869
+ {
870
+ type: "source_port",
871
+ source_port_id: "source_port_4",
872
+ name: "pin5",
873
+ pin_number: 5,
874
+ port_hints: ["pin5", "5"],
875
+ source_component_id: "source_component_0"
876
+ },
877
+ {
878
+ type: "source_port",
879
+ source_port_id: "source_port_5",
880
+ name: "pin6",
881
+ pin_number: 6,
882
+ port_hints: ["pin6", "6"],
883
+ source_component_id: "source_component_0"
884
+ },
885
+ {
886
+ type: "source_port",
887
+ source_port_id: "source_port_6",
888
+ name: "pin7",
889
+ pin_number: 7,
890
+ port_hints: ["pin7", "7"],
891
+ source_component_id: "source_component_0"
892
+ },
893
+ {
894
+ type: "source_port",
895
+ source_port_id: "source_port_7",
896
+ name: "pin8",
897
+ pin_number: 8,
898
+ port_hints: ["pin8", "8"],
899
+ source_component_id: "source_component_0"
900
+ },
901
+ {
902
+ type: "source_component",
903
+ source_component_id: "source_component_0",
904
+ ftype: "simple_chip",
905
+ name: "U1"
906
+ },
907
+ {
908
+ type: "schematic_component",
909
+ schematic_component_id: "schematic_component_0",
910
+ center: {
911
+ x: 0,
912
+ y: 0
913
+ },
914
+ rotation: 0,
915
+ size: {
916
+ width: 1.1,
917
+ height: 1
918
+ },
919
+ pin_spacing: 0.2,
920
+ port_labels: {},
921
+ source_component_id: "source_component_0"
922
+ },
923
+ {
924
+ type: "schematic_port",
925
+ schematic_port_id: "schematic_port_0",
926
+ schematic_component_id: "schematic_component_0",
927
+ center: {
928
+ x: -0.9500000000000001,
929
+ y: 0.30000000000000004
930
+ },
931
+ source_port_id: "source_port_0",
932
+ facing_direction: "left",
933
+ distance_from_component_edge: 0.4,
934
+ side_of_component: "left",
935
+ pin_number: 1,
936
+ true_ccw_index: 0
937
+ },
938
+ {
939
+ type: "schematic_port",
940
+ schematic_port_id: "schematic_port_1",
941
+ schematic_component_id: "schematic_component_0",
942
+ center: {
943
+ x: -0.9500000000000001,
944
+ y: 0.10000000000000003
945
+ },
946
+ source_port_id: "source_port_1",
947
+ facing_direction: "left",
948
+ distance_from_component_edge: 0.4,
949
+ side_of_component: "left",
950
+ pin_number: 2,
951
+ true_ccw_index: 1
952
+ },
953
+ {
954
+ type: "schematic_port",
955
+ schematic_port_id: "schematic_port_2",
956
+ schematic_component_id: "schematic_component_0",
957
+ center: {
958
+ x: -0.9500000000000001,
959
+ y: -0.09999999999999998
960
+ },
961
+ source_port_id: "source_port_2",
962
+ facing_direction: "left",
963
+ distance_from_component_edge: 0.4,
964
+ side_of_component: "left",
965
+ pin_number: 3,
966
+ true_ccw_index: 2
967
+ },
968
+ {
969
+ type: "schematic_port",
970
+ schematic_port_id: "schematic_port_3",
971
+ schematic_component_id: "schematic_component_0",
972
+ center: {
973
+ x: -0.9500000000000001,
974
+ y: -0.30000000000000004
975
+ },
976
+ source_port_id: "source_port_3",
977
+ facing_direction: "left",
978
+ distance_from_component_edge: 0.4,
979
+ side_of_component: "left",
980
+ pin_number: 4,
981
+ true_ccw_index: 3
982
+ },
983
+ {
984
+ type: "schematic_port",
985
+ schematic_port_id: "schematic_port_4",
986
+ schematic_component_id: "schematic_component_0",
987
+ center: {
988
+ x: 0.9500000000000001,
989
+ y: -0.30000000000000004
990
+ },
991
+ source_port_id: "source_port_4",
992
+ facing_direction: "right",
993
+ distance_from_component_edge: 0.4,
994
+ side_of_component: "right",
995
+ pin_number: 5,
996
+ true_ccw_index: 4
997
+ },
998
+ {
999
+ type: "schematic_port",
1000
+ schematic_port_id: "schematic_port_5",
1001
+ schematic_component_id: "schematic_component_0",
1002
+ center: {
1003
+ x: 0.9500000000000001,
1004
+ y: -0.10000000000000003
1005
+ },
1006
+ source_port_id: "source_port_5",
1007
+ facing_direction: "right",
1008
+ distance_from_component_edge: 0.4,
1009
+ side_of_component: "right",
1010
+ pin_number: 6,
1011
+ true_ccw_index: 5
1012
+ },
1013
+ {
1014
+ type: "schematic_port",
1015
+ schematic_port_id: "schematic_port_6",
1016
+ schematic_component_id: "schematic_component_0",
1017
+ center: {
1018
+ x: 0.9500000000000001,
1019
+ y: 0.09999999999999998
1020
+ },
1021
+ source_port_id: "source_port_6",
1022
+ facing_direction: "right",
1023
+ distance_from_component_edge: 0.4,
1024
+ side_of_component: "right",
1025
+ pin_number: 7,
1026
+ true_ccw_index: 6
1027
+ },
1028
+ {
1029
+ type: "schematic_port",
1030
+ schematic_port_id: "schematic_port_7",
1031
+ schematic_component_id: "schematic_component_0",
1032
+ center: {
1033
+ x: 0.9500000000000001,
1034
+ y: 0.30000000000000004
1035
+ },
1036
+ source_port_id: "source_port_7",
1037
+ facing_direction: "right",
1038
+ distance_from_component_edge: 0.4,
1039
+ side_of_component: "right",
1040
+ pin_number: 8,
1041
+ true_ccw_index: 7
1042
+ },
1043
+ {
1044
+ type: "pcb_component",
1045
+ pcb_component_id: "pcb_component_0",
1046
+ center: {
1047
+ x: 0,
1048
+ y: 0
1049
+ },
1050
+ width: 8.82,
1051
+ height: 8.82,
1052
+ layer: "top",
1053
+ rotation: 0,
1054
+ source_component_id: "source_component_0"
1055
+ },
1056
+ {
1057
+ type: "pcb_board",
1058
+ pcb_board_id: "pcb_board_0",
1059
+ center: {
1060
+ x: 0,
1061
+ y: 0
1062
+ },
1063
+ thickness: 1.4,
1064
+ num_layers: 4,
1065
+ width: 50,
1066
+ height: 50
1067
+ },
1068
+ {
1069
+ type: "pcb_plated_hole",
1070
+ pcb_plated_hole_id: "pcb_plated_hole_0",
1071
+ pcb_component_id: "pcb_component_0",
1072
+ pcb_port_id: "pcb_port_0",
1073
+ outer_diameter: 1.2,
1074
+ hole_diameter: 1,
1075
+ shape: "circle",
1076
+ port_hints: ["1"],
1077
+ x: -3.81,
1078
+ y: 3.81,
1079
+ layers: ["top", "bottom"]
1080
+ },
1081
+ {
1082
+ type: "pcb_plated_hole",
1083
+ pcb_plated_hole_id: "pcb_plated_hole_1",
1084
+ pcb_component_id: "pcb_component_0",
1085
+ pcb_port_id: "pcb_port_1",
1086
+ outer_diameter: 1.2,
1087
+ hole_diameter: 1,
1088
+ shape: "circle",
1089
+ port_hints: ["2"],
1090
+ x: -3.81,
1091
+ y: 1.27,
1092
+ layers: ["top", "bottom"]
1093
+ },
1094
+ {
1095
+ type: "pcb_plated_hole",
1096
+ pcb_plated_hole_id: "pcb_plated_hole_2",
1097
+ pcb_component_id: "pcb_component_0",
1098
+ pcb_port_id: "pcb_port_2",
1099
+ outer_diameter: 1.2,
1100
+ hole_diameter: 1,
1101
+ shape: "circle",
1102
+ port_hints: ["3"],
1103
+ x: -3.81,
1104
+ y: -1.27,
1105
+ layers: ["top", "bottom"]
1106
+ },
1107
+ {
1108
+ type: "pcb_plated_hole",
1109
+ pcb_plated_hole_id: "pcb_plated_hole_3",
1110
+ pcb_component_id: "pcb_component_0",
1111
+ pcb_port_id: "pcb_port_3",
1112
+ outer_diameter: 1.2,
1113
+ hole_diameter: 1,
1114
+ shape: "circle",
1115
+ port_hints: ["4"],
1116
+ x: -3.81,
1117
+ y: -3.81,
1118
+ layers: ["top", "bottom"]
1119
+ },
1120
+ {
1121
+ type: "pcb_plated_hole",
1122
+ pcb_plated_hole_id: "pcb_plated_hole_4",
1123
+ pcb_component_id: "pcb_component_0",
1124
+ pcb_port_id: "pcb_port_4",
1125
+ outer_diameter: 1.2,
1126
+ hole_diameter: 1,
1127
+ shape: "circle",
1128
+ port_hints: ["5"],
1129
+ x: 3.81,
1130
+ y: -3.81,
1131
+ layers: ["top", "bottom"]
1132
+ },
1133
+ {
1134
+ type: "pcb_plated_hole",
1135
+ pcb_plated_hole_id: "pcb_plated_hole_5",
1136
+ pcb_component_id: "pcb_component_0",
1137
+ pcb_port_id: "pcb_port_5",
1138
+ outer_diameter: 1.2,
1139
+ hole_diameter: 1,
1140
+ shape: "circle",
1141
+ port_hints: ["6"],
1142
+ x: 3.81,
1143
+ y: -1.27,
1144
+ layers: ["top", "bottom"]
1145
+ },
1146
+ {
1147
+ type: "pcb_plated_hole",
1148
+ pcb_plated_hole_id: "pcb_plated_hole_6",
1149
+ pcb_component_id: "pcb_component_0",
1150
+ pcb_port_id: "pcb_port_6",
1151
+ outer_diameter: 1.2,
1152
+ hole_diameter: 1,
1153
+ shape: "circle",
1154
+ port_hints: ["7"],
1155
+ x: 3.81,
1156
+ y: 1.27,
1157
+ layers: ["top", "bottom"]
1158
+ },
1159
+ {
1160
+ type: "pcb_plated_hole",
1161
+ pcb_plated_hole_id: "pcb_plated_hole_7",
1162
+ pcb_component_id: "pcb_component_0",
1163
+ pcb_port_id: "pcb_port_7",
1164
+ outer_diameter: 1.2,
1165
+ hole_diameter: 1,
1166
+ shape: "circle",
1167
+ port_hints: ["8"],
1168
+ x: 3.81,
1169
+ y: 3.81,
1170
+ layers: ["top", "bottom"]
1171
+ },
1172
+ {
1173
+ type: "pcb_silkscreen_path",
1174
+ pcb_silkscreen_path_id: "pcb_silkscreen_path_0",
1175
+ pcb_component_id: "pcb_component_0",
1176
+ layer: "top",
1177
+ route: [
1178
+ {
1179
+ x: -3.01,
1180
+ y: -4.61
1181
+ },
1182
+ {
1183
+ x: -3.01,
1184
+ y: 4.61
1185
+ },
1186
+ {
1187
+ x: -1.0033333333333332,
1188
+ y: 4.61
1189
+ },
1190
+ {
1191
+ x: -0.9269591309529909,
1192
+ y: 4.226040956193693
1193
+ },
1194
+ {
1195
+ x: -0.7094638037905026,
1196
+ y: 3.9005361962094978
1197
+ },
1198
+ {
1199
+ x: -0.3839590438063067,
1200
+ y: 3.6830408690470096
1201
+ },
1202
+ {
1203
+ x: 6143644775722556e-32,
1204
+ y: 3.6066666666666674
1205
+ },
1206
+ {
1207
+ x: 0.38395904380630674,
1208
+ y: 3.6830408690470096
1209
+ },
1210
+ {
1211
+ x: 0.7094638037905027,
1212
+ y: 3.9005361962094978
1213
+ },
1214
+ {
1215
+ x: 0.9269591309529909,
1216
+ y: 4.226040956193693
1217
+ },
1218
+ {
1219
+ x: 1.0033333333333332,
1220
+ y: 4.61
1221
+ },
1222
+ {
1223
+ x: 3.01,
1224
+ y: 4.61
1225
+ },
1226
+ {
1227
+ x: 3.01,
1228
+ y: -4.61
1229
+ },
1230
+ {
1231
+ x: -3.01,
1232
+ y: -4.61
1233
+ }
1234
+ ],
1235
+ stroke_width: 0.1
1236
+ },
1237
+ {
1238
+ type: "pcb_port",
1239
+ pcb_port_id: "pcb_port_0",
1240
+ pcb_component_id: "pcb_component_0",
1241
+ layers: ["top", "inner1", "inner2", "bottom"],
1242
+ x: -3.81,
1243
+ y: 3.81,
1244
+ source_port_id: "source_port_0"
1245
+ },
1246
+ {
1247
+ type: "pcb_port",
1248
+ pcb_port_id: "pcb_port_1",
1249
+ pcb_component_id: "pcb_component_0",
1250
+ layers: ["top", "inner1", "inner2", "bottom"],
1251
+ x: -3.81,
1252
+ y: 1.27,
1253
+ source_port_id: "source_port_1"
1254
+ },
1255
+ {
1256
+ type: "pcb_port",
1257
+ pcb_port_id: "pcb_port_2",
1258
+ pcb_component_id: "pcb_component_0",
1259
+ layers: ["top", "inner1", "inner2", "bottom"],
1260
+ x: -3.81,
1261
+ y: -1.27,
1262
+ source_port_id: "source_port_2"
1263
+ },
1264
+ {
1265
+ type: "pcb_port",
1266
+ pcb_port_id: "pcb_port_3",
1267
+ pcb_component_id: "pcb_component_0",
1268
+ layers: ["top", "inner1", "inner2", "bottom"],
1269
+ x: -3.81,
1270
+ y: -3.81,
1271
+ source_port_id: "source_port_3"
1272
+ },
1273
+ {
1274
+ type: "pcb_port",
1275
+ pcb_port_id: "pcb_port_4",
1276
+ pcb_component_id: "pcb_component_0",
1277
+ layers: ["top", "inner1", "inner2", "bottom"],
1278
+ x: 3.81,
1279
+ y: -3.81,
1280
+ source_port_id: "source_port_4"
1281
+ },
1282
+ {
1283
+ type: "pcb_port",
1284
+ pcb_port_id: "pcb_port_5",
1285
+ pcb_component_id: "pcb_component_0",
1286
+ layers: ["top", "inner1", "inner2", "bottom"],
1287
+ x: 3.81,
1288
+ y: -1.27,
1289
+ source_port_id: "source_port_5"
1290
+ },
1291
+ {
1292
+ type: "pcb_port",
1293
+ pcb_port_id: "pcb_port_6",
1294
+ pcb_component_id: "pcb_component_0",
1295
+ layers: ["top", "inner1", "inner2", "bottom"],
1296
+ x: 3.81,
1297
+ y: 1.27,
1298
+ source_port_id: "source_port_6"
1299
+ },
1300
+ {
1301
+ type: "pcb_port",
1302
+ pcb_port_id: "pcb_port_7",
1303
+ pcb_component_id: "pcb_component_0",
1304
+ layers: ["top", "inner1", "inner2", "bottom"],
1305
+ x: 3.81,
1306
+ y: 3.81,
1307
+ source_port_id: "source_port_7"
1308
+ },
1309
+ {
1310
+ type: "cad_component",
1311
+ cad_component_id: "cad_component_0",
1312
+ position: {
1313
+ x: 0,
1314
+ y: 0,
1315
+ z: 0.7
1316
+ },
1317
+ rotation: {
1318
+ x: 0,
1319
+ y: 0,
1320
+ z: 0
1321
+ },
1322
+ pcb_component_id: "pcb_component_0",
1323
+ source_component_id: "source_component_0",
1324
+ footprinter_string: "dip8"
1325
+ }
1326
+ ]
1327
+ });
1328
+ db.addSnippet({
1329
+ name: "testuser/a555timer-square-wave",
1330
+ unscoped_name: "a555timer-square-wave",
1331
+ owner_name: "testuser",
1332
+ code: `
1333
+ import { A555Timer } from "@tsci/seveibar.a555timer"
1334
+
1335
+ export const SquareWaveModule = () => (
1336
+ <A555Timer name="U1" />
1337
+ )
1338
+ `.trim(),
1339
+ dts: 'export declare const SquareWaveModule: () => import("react/jsx-runtime").JSX.Element;\n',
1340
+ 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;',
1341
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1342
+ updated_at: (/* @__PURE__ */ new Date()).toISOString(),
1343
+ snippet_type: "package",
1344
+ description: "A simple package that outputs a square waveform using the a555timer",
1345
+ circuit_json: [
1346
+ {
1347
+ type: "source_port",
1348
+ source_port_id: "source_port_0",
1349
+ name: "pin1",
1350
+ pin_number: 1,
1351
+ port_hints: ["pin1", "1"],
1352
+ source_component_id: "source_component_0"
1353
+ },
1354
+ {
1355
+ type: "source_port",
1356
+ source_port_id: "source_port_1",
1357
+ name: "pin2",
1358
+ pin_number: 2,
1359
+ port_hints: ["pin2", "2"],
1360
+ source_component_id: "source_component_0"
1361
+ },
1362
+ {
1363
+ type: "source_port",
1364
+ source_port_id: "source_port_2",
1365
+ name: "pin3",
1366
+ pin_number: 3,
1367
+ port_hints: ["pin3", "3"],
1368
+ source_component_id: "source_component_0"
1369
+ },
1370
+ {
1371
+ type: "source_port",
1372
+ source_port_id: "source_port_3",
1373
+ name: "pin4",
1374
+ pin_number: 4,
1375
+ port_hints: ["pin4", "4"],
1376
+ source_component_id: "source_component_0"
1377
+ },
1378
+ {
1379
+ type: "source_port",
1380
+ source_port_id: "source_port_4",
1381
+ name: "pin5",
1382
+ pin_number: 5,
1383
+ port_hints: ["pin5", "5"],
1384
+ source_component_id: "source_component_0"
1385
+ },
1386
+ {
1387
+ type: "source_port",
1388
+ source_port_id: "source_port_5",
1389
+ name: "pin6",
1390
+ pin_number: 6,
1391
+ port_hints: ["pin6", "6"],
1392
+ source_component_id: "source_component_0"
1393
+ },
1394
+ {
1395
+ type: "source_port",
1396
+ source_port_id: "source_port_6",
1397
+ name: "pin7",
1398
+ pin_number: 7,
1399
+ port_hints: ["pin7", "7"],
1400
+ source_component_id: "source_component_0"
1401
+ },
1402
+ {
1403
+ type: "source_port",
1404
+ source_port_id: "source_port_7",
1405
+ name: "pin8",
1406
+ pin_number: 8,
1407
+ port_hints: ["pin8", "8"],
1408
+ source_component_id: "source_component_0"
1409
+ },
1410
+ {
1411
+ type: "source_component",
1412
+ source_component_id: "source_component_0",
1413
+ ftype: "simple_chip",
1414
+ name: "U1"
1415
+ },
1416
+ {
1417
+ type: "schematic_component",
1418
+ schematic_component_id: "schematic_component_0",
1419
+ center: {
1420
+ x: 0,
1421
+ y: 0
1422
+ },
1423
+ rotation: 0,
1424
+ size: {
1425
+ width: 1.1,
1426
+ height: 1
1427
+ },
1428
+ pin_spacing: 0.2,
1429
+ port_labels: {},
1430
+ source_component_id: "source_component_0"
1431
+ },
1432
+ {
1433
+ type: "schematic_port",
1434
+ schematic_port_id: "schematic_port_0",
1435
+ schematic_component_id: "schematic_component_0",
1436
+ center: {
1437
+ x: -0.9500000000000001,
1438
+ y: 0.30000000000000004
1439
+ },
1440
+ source_port_id: "source_port_0",
1441
+ facing_direction: "left",
1442
+ distance_from_component_edge: 0.4,
1443
+ side_of_component: "left",
1444
+ pin_number: 1,
1445
+ true_ccw_index: 0
1446
+ },
1447
+ {
1448
+ type: "schematic_port",
1449
+ schematic_port_id: "schematic_port_1",
1450
+ schematic_component_id: "schematic_component_0",
1451
+ center: {
1452
+ x: -0.9500000000000001,
1453
+ y: 0.10000000000000003
1454
+ },
1455
+ source_port_id: "source_port_1",
1456
+ facing_direction: "left",
1457
+ distance_from_component_edge: 0.4,
1458
+ side_of_component: "left",
1459
+ pin_number: 2,
1460
+ true_ccw_index: 1
1461
+ },
1462
+ {
1463
+ type: "schematic_port",
1464
+ schematic_port_id: "schematic_port_2",
1465
+ schematic_component_id: "schematic_component_0",
1466
+ center: {
1467
+ x: -0.9500000000000001,
1468
+ y: -0.09999999999999998
1469
+ },
1470
+ source_port_id: "source_port_2",
1471
+ facing_direction: "left",
1472
+ distance_from_component_edge: 0.4,
1473
+ side_of_component: "left",
1474
+ pin_number: 3,
1475
+ true_ccw_index: 2
1476
+ },
1477
+ {
1478
+ type: "schematic_port",
1479
+ schematic_port_id: "schematic_port_3",
1480
+ schematic_component_id: "schematic_component_0",
1481
+ center: {
1482
+ x: -0.9500000000000001,
1483
+ y: -0.30000000000000004
1484
+ },
1485
+ source_port_id: "source_port_3",
1486
+ facing_direction: "left",
1487
+ distance_from_component_edge: 0.4,
1488
+ side_of_component: "left",
1489
+ pin_number: 4,
1490
+ true_ccw_index: 3
1491
+ },
1492
+ {
1493
+ type: "schematic_port",
1494
+ schematic_port_id: "schematic_port_4",
1495
+ schematic_component_id: "schematic_component_0",
1496
+ center: {
1497
+ x: 0.9500000000000001,
1498
+ y: -0.30000000000000004
1499
+ },
1500
+ source_port_id: "source_port_4",
1501
+ facing_direction: "right",
1502
+ distance_from_component_edge: 0.4,
1503
+ side_of_component: "right",
1504
+ pin_number: 5,
1505
+ true_ccw_index: 4
1506
+ },
1507
+ {
1508
+ type: "schematic_port",
1509
+ schematic_port_id: "schematic_port_5",
1510
+ schematic_component_id: "schematic_component_0",
1511
+ center: {
1512
+ x: 0.9500000000000001,
1513
+ y: -0.10000000000000003
1514
+ },
1515
+ source_port_id: "source_port_5",
1516
+ facing_direction: "right",
1517
+ distance_from_component_edge: 0.4,
1518
+ side_of_component: "right",
1519
+ pin_number: 6,
1520
+ true_ccw_index: 5
1521
+ },
1522
+ {
1523
+ type: "schematic_port",
1524
+ schematic_port_id: "schematic_port_6",
1525
+ schematic_component_id: "schematic_component_0",
1526
+ center: {
1527
+ x: 0.9500000000000001,
1528
+ y: 0.09999999999999998
1529
+ },
1530
+ source_port_id: "source_port_6",
1531
+ facing_direction: "right",
1532
+ distance_from_component_edge: 0.4,
1533
+ side_of_component: "right",
1534
+ pin_number: 7,
1535
+ true_ccw_index: 6
1536
+ },
1537
+ {
1538
+ type: "schematic_port",
1539
+ schematic_port_id: "schematic_port_7",
1540
+ schematic_component_id: "schematic_component_0",
1541
+ center: {
1542
+ x: 0.9500000000000001,
1543
+ y: 0.30000000000000004
1544
+ },
1545
+ source_port_id: "source_port_7",
1546
+ facing_direction: "right",
1547
+ distance_from_component_edge: 0.4,
1548
+ side_of_component: "right",
1549
+ pin_number: 8,
1550
+ true_ccw_index: 7
1551
+ },
1552
+ {
1553
+ type: "pcb_component",
1554
+ pcb_component_id: "pcb_component_0",
1555
+ center: {
1556
+ x: 0,
1557
+ y: 0
1558
+ },
1559
+ width: 8.82,
1560
+ height: 8.82,
1561
+ layer: "top",
1562
+ rotation: 0,
1563
+ source_component_id: "source_component_0"
1564
+ },
1565
+ {
1566
+ type: "pcb_board",
1567
+ pcb_board_id: "pcb_board_0",
1568
+ center: {
1569
+ x: 0,
1570
+ y: 0
1571
+ },
1572
+ thickness: 1.4,
1573
+ num_layers: 4,
1574
+ width: 50,
1575
+ height: 50
1576
+ },
1577
+ {
1578
+ type: "pcb_plated_hole",
1579
+ pcb_plated_hole_id: "pcb_plated_hole_0",
1580
+ pcb_component_id: "pcb_component_0",
1581
+ pcb_port_id: "pcb_port_0",
1582
+ outer_diameter: 1.2,
1583
+ hole_diameter: 1,
1584
+ shape: "circle",
1585
+ port_hints: ["1"],
1586
+ x: -3.81,
1587
+ y: 3.81,
1588
+ layers: ["top", "bottom"]
1589
+ },
1590
+ {
1591
+ type: "pcb_plated_hole",
1592
+ pcb_plated_hole_id: "pcb_plated_hole_1",
1593
+ pcb_component_id: "pcb_component_0",
1594
+ pcb_port_id: "pcb_port_1",
1595
+ outer_diameter: 1.2,
1596
+ hole_diameter: 1,
1597
+ shape: "circle",
1598
+ port_hints: ["2"],
1599
+ x: -3.81,
1600
+ y: 1.27,
1601
+ layers: ["top", "bottom"]
1602
+ },
1603
+ {
1604
+ type: "pcb_plated_hole",
1605
+ pcb_plated_hole_id: "pcb_plated_hole_2",
1606
+ pcb_component_id: "pcb_component_0",
1607
+ pcb_port_id: "pcb_port_2",
1608
+ outer_diameter: 1.2,
1609
+ hole_diameter: 1,
1610
+ shape: "circle",
1611
+ port_hints: ["3"],
1612
+ x: -3.81,
1613
+ y: -1.27,
1614
+ layers: ["top", "bottom"]
1615
+ },
1616
+ {
1617
+ type: "pcb_plated_hole",
1618
+ pcb_plated_hole_id: "pcb_plated_hole_3",
1619
+ pcb_component_id: "pcb_component_0",
1620
+ pcb_port_id: "pcb_port_3",
1621
+ outer_diameter: 1.2,
1622
+ hole_diameter: 1,
1623
+ shape: "circle",
1624
+ port_hints: ["4"],
1625
+ x: -3.81,
1626
+ y: -3.81,
1627
+ layers: ["top", "bottom"]
1628
+ },
1629
+ {
1630
+ type: "pcb_plated_hole",
1631
+ pcb_plated_hole_id: "pcb_plated_hole_4",
1632
+ pcb_component_id: "pcb_component_0",
1633
+ pcb_port_id: "pcb_port_4",
1634
+ outer_diameter: 1.2,
1635
+ hole_diameter: 1,
1636
+ shape: "circle",
1637
+ port_hints: ["5"],
1638
+ x: 3.81,
1639
+ y: -3.81,
1640
+ layers: ["top", "bottom"]
1641
+ },
1642
+ {
1643
+ type: "pcb_plated_hole",
1644
+ pcb_plated_hole_id: "pcb_plated_hole_5",
1645
+ pcb_component_id: "pcb_component_0",
1646
+ pcb_port_id: "pcb_port_5",
1647
+ outer_diameter: 1.2,
1648
+ hole_diameter: 1,
1649
+ shape: "circle",
1650
+ port_hints: ["6"],
1651
+ x: 3.81,
1652
+ y: -1.27,
1653
+ layers: ["top", "bottom"]
1654
+ },
1655
+ {
1656
+ type: "pcb_plated_hole",
1657
+ pcb_plated_hole_id: "pcb_plated_hole_6",
1658
+ pcb_component_id: "pcb_component_0",
1659
+ pcb_port_id: "pcb_port_6",
1660
+ outer_diameter: 1.2,
1661
+ hole_diameter: 1,
1662
+ shape: "circle",
1663
+ port_hints: ["7"],
1664
+ x: 3.81,
1665
+ y: 1.27,
1666
+ layers: ["top", "bottom"]
1667
+ },
1668
+ {
1669
+ type: "pcb_plated_hole",
1670
+ pcb_plated_hole_id: "pcb_plated_hole_7",
1671
+ pcb_component_id: "pcb_component_0",
1672
+ pcb_port_id: "pcb_port_7",
1673
+ outer_diameter: 1.2,
1674
+ hole_diameter: 1,
1675
+ shape: "circle",
1676
+ port_hints: ["8"],
1677
+ x: 3.81,
1678
+ y: 3.81,
1679
+ layers: ["top", "bottom"]
1680
+ },
1681
+ {
1682
+ type: "pcb_silkscreen_path",
1683
+ pcb_silkscreen_path_id: "pcb_silkscreen_path_0",
1684
+ pcb_component_id: "pcb_component_0",
1685
+ layer: "top",
1686
+ route: [
1687
+ {
1688
+ x: -3.01,
1689
+ y: -4.61
1690
+ },
1691
+ {
1692
+ x: -3.01,
1693
+ y: 4.61
1694
+ },
1695
+ {
1696
+ x: -1.0033333333333332,
1697
+ y: 4.61
1698
+ },
1699
+ {
1700
+ x: -0.9269591309529909,
1701
+ y: 4.226040956193693
1702
+ },
1703
+ {
1704
+ x: -0.7094638037905026,
1705
+ y: 3.9005361962094978
1706
+ },
1707
+ {
1708
+ x: -0.3839590438063067,
1709
+ y: 3.6830408690470096
1710
+ },
1711
+ {
1712
+ x: 6143644775722556e-32,
1713
+ y: 3.6066666666666674
1714
+ },
1715
+ {
1716
+ x: 0.38395904380630674,
1717
+ y: 3.6830408690470096
1718
+ },
1719
+ {
1720
+ x: 0.7094638037905027,
1721
+ y: 3.9005361962094978
1722
+ },
1723
+ {
1724
+ x: 0.9269591309529909,
1725
+ y: 4.226040956193693
1726
+ },
1727
+ {
1728
+ x: 1.0033333333333332,
1729
+ y: 4.61
1730
+ },
1731
+ {
1732
+ x: 3.01,
1733
+ y: 4.61
1734
+ },
1735
+ {
1736
+ x: 3.01,
1737
+ y: -4.61
1738
+ },
1739
+ {
1740
+ x: -3.01,
1741
+ y: -4.61
1742
+ }
1743
+ ],
1744
+ stroke_width: 0.1
1745
+ },
1746
+ {
1747
+ type: "pcb_port",
1748
+ pcb_port_id: "pcb_port_0",
1749
+ pcb_component_id: "pcb_component_0",
1750
+ layers: ["top", "inner1", "inner2", "bottom"],
1751
+ x: -3.81,
1752
+ y: 3.81,
1753
+ source_port_id: "source_port_0"
1754
+ },
1755
+ {
1756
+ type: "pcb_port",
1757
+ pcb_port_id: "pcb_port_1",
1758
+ pcb_component_id: "pcb_component_0",
1759
+ layers: ["top", "inner1", "inner2", "bottom"],
1760
+ x: -3.81,
1761
+ y: 1.27,
1762
+ source_port_id: "source_port_1"
1763
+ },
1764
+ {
1765
+ type: "pcb_port",
1766
+ pcb_port_id: "pcb_port_2",
1767
+ pcb_component_id: "pcb_component_0",
1768
+ layers: ["top", "inner1", "inner2", "bottom"],
1769
+ x: -3.81,
1770
+ y: -1.27,
1771
+ source_port_id: "source_port_2"
1772
+ },
1773
+ {
1774
+ type: "pcb_port",
1775
+ pcb_port_id: "pcb_port_3",
1776
+ pcb_component_id: "pcb_component_0",
1777
+ layers: ["top", "inner1", "inner2", "bottom"],
1778
+ x: -3.81,
1779
+ y: -3.81,
1780
+ source_port_id: "source_port_3"
1781
+ },
1782
+ {
1783
+ type: "pcb_port",
1784
+ pcb_port_id: "pcb_port_4",
1785
+ pcb_component_id: "pcb_component_0",
1786
+ layers: ["top", "inner1", "inner2", "bottom"],
1787
+ x: 3.81,
1788
+ y: -3.81,
1789
+ source_port_id: "source_port_4"
1790
+ },
1791
+ {
1792
+ type: "pcb_port",
1793
+ pcb_port_id: "pcb_port_5",
1794
+ pcb_component_id: "pcb_component_0",
1795
+ layers: ["top", "inner1", "inner2", "bottom"],
1796
+ x: 3.81,
1797
+ y: -1.27,
1798
+ source_port_id: "source_port_5"
1799
+ },
1800
+ {
1801
+ type: "pcb_port",
1802
+ pcb_port_id: "pcb_port_6",
1803
+ pcb_component_id: "pcb_component_0",
1804
+ layers: ["top", "inner1", "inner2", "bottom"],
1805
+ x: 3.81,
1806
+ y: 1.27,
1807
+ source_port_id: "source_port_6"
1808
+ },
1809
+ {
1810
+ type: "pcb_port",
1811
+ pcb_port_id: "pcb_port_7",
1812
+ pcb_component_id: "pcb_component_0",
1813
+ layers: ["top", "inner1", "inner2", "bottom"],
1814
+ x: 3.81,
1815
+ y: 3.81,
1816
+ source_port_id: "source_port_7"
1817
+ },
1818
+ {
1819
+ type: "cad_component",
1820
+ cad_component_id: "cad_component_0",
1821
+ position: {
1822
+ x: 0,
1823
+ y: 0,
1824
+ z: 0.7
1825
+ },
1826
+ rotation: {
1827
+ x: 0,
1828
+ y: 0,
1829
+ z: 0
1830
+ },
1831
+ pcb_component_id: "pcb_component_0",
1832
+ source_component_id: "source_component_0",
1833
+ footprinter_string: "dip8"
1834
+ }
1835
+ ]
1836
+ });
1837
+ db.addOrder({
1838
+ account_id,
1839
+ is_running: false,
1840
+ is_started: false,
1841
+ is_finished: false,
1842
+ error: null,
1843
+ has_error: false,
1844
+ circuit_json: [
1845
+ {
1846
+ type: "source_component",
1847
+ ftype: "simple_resistor",
1848
+ source_component_id: "source_component_1",
1849
+ name: "R1",
1850
+ resistane: "1k"
1851
+ }
1852
+ ],
1853
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1854
+ started_at: null,
1855
+ completed_at: null
1856
+ });
1857
+ };
1858
+
1859
+ // fake-snippets-api/lib/db/db-client.ts
1860
+ var createDatabase = ({ seed: seed2 } = {}) => {
1861
+ const db = hoist(createStore(initializer));
1862
+ if (seed2) {
1863
+ seed(db);
1864
+ }
1865
+ return db;
1866
+ };
1867
+ var initializer = combine(databaseSchema.parse({}), (set, get) => ({
1868
+ addOrder: (order) => {
1869
+ const newOrder = { order_id: `order_${get().idCounter + 1}`, ...order };
1870
+ set((state) => {
1871
+ return {
1872
+ orders: [...state.orders, newOrder],
1873
+ idCounter: state.idCounter + 1
1874
+ };
1875
+ });
1876
+ return newOrder;
1877
+ },
1878
+ getOrderById: (orderId) => {
1879
+ const state = get();
1880
+ return state.orders.find((order) => order.order_id === orderId);
1881
+ },
1882
+ getOrderFilesByOrderId: (orderId) => {
1883
+ const state = get();
1884
+ return state.orderFiles.filter((file) => file.order_id === orderId);
1885
+ },
1886
+ getJlcpcbOrderStatesByOrderId: (orderId) => {
1887
+ const state = get();
1888
+ return state.jlcpcbOrderState.find((state2) => state2.order_id === orderId);
1889
+ },
1890
+ getJlcpcbOrderStepRunsByJlcpcbOrderStateId: (jlcpcbOrderStateId) => {
1891
+ const state = get();
1892
+ return state.jlcpcbOrderStepRuns.filter((stepRun) => {
1893
+ const orderState = state.jlcpcbOrderState.find(
1894
+ (state2) => state2.jlcpcb_order_state_id === stepRun.jlcpcb_order_state_id
1895
+ );
1896
+ return orderState?.order_id === jlcpcbOrderStateId;
1897
+ }).sort(
1898
+ (a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
1899
+ );
1900
+ },
1901
+ updateOrder: (orderId, updates) => {
1902
+ set((state) => ({
1903
+ orders: state.orders.map(
1904
+ (order) => order.order_id === orderId ? { ...order, ...updates } : order
1905
+ )
1906
+ }));
1907
+ },
1908
+ addJlcpcbOrderState: (orderState) => {
1909
+ const newOrderState = {
1910
+ jlcpcb_order_state_id: `order_state_${get().idCounter + 1}`,
1911
+ ...orderState
1912
+ };
1913
+ set((state) => {
1914
+ return {
1915
+ jlcpcbOrderState: [...state.jlcpcbOrderState, newOrderState],
1916
+ idCounter: state.idCounter + 1
1917
+ };
1918
+ });
1919
+ return newOrderState;
1920
+ },
1921
+ updateJlcpcbOrderState: (orderId, updates) => {
1922
+ set((state) => ({
1923
+ jlcpcbOrderState: state.jlcpcbOrderState.map(
1924
+ (orderState) => orderState.order_id === orderId ? { ...orderState, ...updates } : orderState
1925
+ )
1926
+ }));
1927
+ },
1928
+ addOrderFile: (orderFile) => {
1929
+ const newOrderFile = {
1930
+ order_file_id: `order_file_${get().idCounter + 1}`,
1931
+ ...orderFile
1932
+ };
1933
+ set((state) => {
1934
+ return {
1935
+ orderFiles: [...state.orderFiles, newOrderFile],
1936
+ idCounter: state.idCounter + 1
1937
+ };
1938
+ });
1939
+ return newOrderFile;
1940
+ },
1941
+ getOrderFileById: (orderFileId) => {
1942
+ const state = get();
1943
+ return state.orderFiles.find((file) => file.order_file_id === orderFileId);
1944
+ },
1945
+ addAccount: (account) => {
1946
+ const newAccount = {
1947
+ account_id: account.account_id || `account_${get().idCounter + 1}`,
1948
+ ...account
1949
+ };
1950
+ set((state) => {
1951
+ return {
1952
+ accounts: [...state.accounts, newAccount],
1953
+ idCounter: state.idCounter + 1
1954
+ };
1955
+ });
1956
+ return newAccount;
1957
+ },
1958
+ addAccountPackage: (accountPackage) => {
1959
+ const newAccountPackage = {
1960
+ account_package_id: `ap_${get().idCounter + 1}`,
1961
+ ...accountPackage
1962
+ };
1963
+ set((state) => {
1964
+ return {
1965
+ accountPackages: [...state.accountPackages, newAccountPackage],
1966
+ idCounter: state.idCounter + 1
1967
+ };
1968
+ });
1969
+ return newAccountPackage;
1970
+ },
1971
+ getAccountPackageById: (accountPackageId) => {
1972
+ const state = get();
1973
+ return state.accountPackages.find(
1974
+ (ap) => ap.account_package_id === accountPackageId
1975
+ );
1976
+ },
1977
+ updateAccountPackage: (accountPackageId, updates) => {
1978
+ set((state) => ({
1979
+ accountPackages: state.accountPackages.map(
1980
+ (ap) => ap.account_package_id === accountPackageId ? { ...ap, ...updates } : ap
1981
+ )
1982
+ }));
1983
+ },
1984
+ deleteAccountPackage: (accountPackageId) => {
1985
+ let deleted = false;
1986
+ set((state) => {
1987
+ const index = state.accountPackages.findIndex(
1988
+ (ap) => ap.account_package_id === accountPackageId
1989
+ );
1990
+ if (index !== -1) {
1991
+ state.accountPackages.splice(index, 1);
1992
+ deleted = true;
1993
+ }
1994
+ return state;
1995
+ });
1996
+ return deleted;
1997
+ },
1998
+ addSnippet: (snippet) => {
1999
+ const timestamp = Date.now();
2000
+ const currentTime = new Date(timestamp).toISOString();
2001
+ const newState = get();
2002
+ const nextId = newState.idCounter + 1;
2003
+ const newPackage = {
2004
+ package_id: `pkg_${nextId}`,
2005
+ creator_account_id: snippet.owner_name,
2006
+ // Using owner_name as account_id since we don't have context
2007
+ owner_org_id: "",
2008
+ // Empty string instead of null to match type
2009
+ owner_github_username: snippet.owner_name,
2010
+ is_source_from_github: false,
2011
+ description: snippet.description || "",
2012
+ name: `${snippet.owner_name}/${snippet.unscoped_name}`,
2013
+ unscoped_name: snippet.unscoped_name,
2014
+ latest_version: "0.0.1",
2015
+ license: null,
2016
+ star_count: 0,
2017
+ created_at: currentTime,
2018
+ updated_at: currentTime,
2019
+ ai_description: null,
2020
+ is_snippet: true,
2021
+ is_board: snippet.snippet_type === "board",
2022
+ is_package: snippet.snippet_type === "package",
2023
+ is_model: snippet.snippet_type === "model",
2024
+ is_footprint: snippet.snippet_type === "footprint",
2025
+ snippet_type: snippet.snippet_type,
2026
+ is_private: false,
2027
+ is_public: true,
2028
+ is_unlisted: false,
2029
+ latest_package_release_id: `package_release_${nextId}`
2030
+ };
2031
+ const newPackageRelease = {
2032
+ package_release_id: `package_release_${nextId}`,
2033
+ package_id: newPackage.package_id,
2034
+ version: "0.0.1",
2035
+ is_latest: true,
2036
+ is_locked: false,
2037
+ created_at: currentTime,
2038
+ updated_at: currentTime
2039
+ };
2040
+ const packageFiles = [];
2041
+ let fileIdCounter = nextId;
2042
+ packageFiles.push({
2043
+ package_file_id: `package_file_${fileIdCounter++}`,
2044
+ package_release_id: newPackageRelease.package_release_id,
2045
+ file_path: "index.tsx",
2046
+ content_text: snippet.code || "",
2047
+ created_at: currentTime
2048
+ });
2049
+ if (snippet.dts) {
2050
+ packageFiles.push({
2051
+ package_file_id: `package_file_${fileIdCounter++}`,
2052
+ package_release_id: newPackageRelease.package_release_id,
2053
+ file_path: "/dist/index.d.ts",
2054
+ content_text: snippet.dts,
2055
+ created_at: currentTime
2056
+ });
2057
+ }
2058
+ if (snippet.compiled_js) {
2059
+ packageFiles.push({
2060
+ package_file_id: `package_file_${fileIdCounter++}`,
2061
+ package_release_id: newPackageRelease.package_release_id,
2062
+ file_path: "/dist/index.js",
2063
+ content_text: snippet.compiled_js,
2064
+ created_at: currentTime
2065
+ });
2066
+ }
2067
+ if (snippet.circuit_json && snippet.circuit_json.length > 0) {
2068
+ packageFiles.push({
2069
+ package_file_id: `package_file_${fileIdCounter++}`,
2070
+ package_release_id: newPackageRelease.package_release_id,
2071
+ file_path: "/dist/circuit.json",
2072
+ content_text: JSON.stringify(snippet.circuit_json),
2073
+ created_at: currentTime
2074
+ });
2075
+ }
2076
+ set((state) => ({
2077
+ ...state,
2078
+ packages: [...state.packages, newPackage],
2079
+ packageReleases: [...state.packageReleases, newPackageRelease],
2080
+ packageFiles: [...state.packageFiles, ...packageFiles],
2081
+ idCounter: fileIdCounter
2082
+ }));
2083
+ return {
2084
+ snippet_id: newPackage.package_id,
2085
+ package_release_id: newPackageRelease.package_release_id,
2086
+ name: newPackage.name,
2087
+ unscoped_name: newPackage.unscoped_name,
2088
+ owner_name: snippet.owner_name,
2089
+ code: snippet.code || "",
2090
+ dts: snippet.dts,
2091
+ compiled_js: snippet.compiled_js,
2092
+ star_count: 0,
2093
+ created_at: currentTime,
2094
+ updated_at: currentTime,
2095
+ snippet_type: snippet.snippet_type,
2096
+ circuit_json: snippet.circuit_json || [],
2097
+ description: snippet.description || "",
2098
+ is_starred: false,
2099
+ version: "0.0.1",
2100
+ is_private: false,
2101
+ is_public: true,
2102
+ is_unlisted: false
2103
+ };
2104
+ },
2105
+ getNewestSnippets: (limit) => {
2106
+ const state = get();
2107
+ const snippetPackages = state.packages.filter((pkg) => pkg.is_snippet === true).map((pkg) => {
2108
+ const packageRelease = state.packageReleases.find(
2109
+ (pr) => pr.package_release_id === pkg.latest_package_release_id && pr.is_latest === true
2110
+ );
2111
+ if (!packageRelease) return null;
2112
+ const packageFiles = state.packageFiles.filter(
2113
+ (file) => file.package_release_id === packageRelease.package_release_id
2114
+ );
2115
+ const codeFile = packageFiles.find(
2116
+ (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
2117
+ );
2118
+ const isStarred = state.accountPackages.some(
2119
+ (ap) => ap.package_id === pkg.package_id && ap.is_starred
2120
+ );
2121
+ return {
2122
+ snippet_id: pkg.package_id,
2123
+ package_release_id: pkg.latest_package_release_id || "",
2124
+ unscoped_name: pkg.unscoped_name,
2125
+ name: pkg.name,
2126
+ owner_name: pkg.owner_github_username || "",
2127
+ description: pkg.description || "",
2128
+ snippet_type: pkg.snippet_type || "board",
2129
+ code: codeFile?.content_text || "",
2130
+ dts: packageFiles.find((file) => file.file_path === "/dist/index.d.ts")?.content_text || "",
2131
+ compiled_js: packageFiles.find((file) => file.file_path === "/dist/index.js")?.content_text || "",
2132
+ created_at: pkg.created_at,
2133
+ updated_at: pkg.updated_at,
2134
+ star_count: pkg.star_count || 0,
2135
+ is_starred: isStarred,
2136
+ version: pkg.latest_version || "0.0.1",
2137
+ circuit_json: packageFiles.filter((file) => file.file_path === "/dist/circuit.json").flatMap((file) => JSON.parse(file.content_text || "[]")) || [],
2138
+ is_private: pkg.is_private || false,
2139
+ is_public: pkg.is_public || true,
2140
+ is_unlisted: pkg.is_unlisted || false
2141
+ };
2142
+ }).filter(
2143
+ (snippet) => snippet !== null
2144
+ ).map((snippet) => ({
2145
+ ...snippet,
2146
+ description: snippet.description || ""
2147
+ })).sort(
2148
+ (a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
2149
+ ).slice(0, limit);
2150
+ return snippetPackages;
2151
+ },
2152
+ getTrendingSnippets: (limit, since) => {
2153
+ const state = get();
2154
+ const sinceDate = new Date(since).getTime();
2155
+ const recentStars = /* @__PURE__ */ new Map();
2156
+ state.accountPackages.forEach((ap) => {
2157
+ if (ap.is_starred && new Date(ap.created_at).getTime() >= sinceDate) {
2158
+ recentStars.set(
2159
+ ap.package_id,
2160
+ (recentStars.get(ap.package_id) || 0) + 1
2161
+ );
2162
+ }
2163
+ });
2164
+ const packagesWithStarCount = [...state.packages].map((pkg) => ({
2165
+ ...pkg,
2166
+ star_count: recentStars.get(pkg.package_id) || 0
2167
+ })).sort((a, b) => b.star_count - a.star_count).slice(0, limit);
2168
+ const trendingSnippets = packagesWithStarCount.map((pkg) => {
2169
+ const packageRelease = state.packageReleases.find(
2170
+ (pr) => pr.package_release_id === pkg.latest_package_release_id && pr.is_latest === true
2171
+ );
2172
+ if (!packageRelease) return null;
2173
+ const packageFiles = state.packageFiles.filter(
2174
+ (file) => file.package_release_id === packageRelease.package_release_id
2175
+ );
2176
+ const codeFile = packageFiles.find(
2177
+ (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
2178
+ );
2179
+ return {
2180
+ snippet_id: pkg.package_id,
2181
+ package_release_id: pkg.latest_package_release_id || "",
2182
+ unscoped_name: pkg.unscoped_name,
2183
+ name: pkg.name,
2184
+ owner_name: pkg.owner_github_username || "",
2185
+ code: codeFile ? codeFile.content_text || "" : "",
2186
+ created_at: pkg.created_at,
2187
+ updated_at: pkg.updated_at,
2188
+ snippet_type: pkg.is_snippet ? "board" : "package",
2189
+ star_count: pkg.star_count
2190
+ };
2191
+ }).filter((snippet) => snippet !== null);
2192
+ return trendingSnippets;
2193
+ },
2194
+ getPackagesByAuthor: (authorName) => {
2195
+ const state = get();
2196
+ const packages = authorName ? state.packages.filter((pkg) => pkg.owner_github_username === authorName) : state.packages;
2197
+ return packages.map((pkg) => ({
2198
+ ...pkg,
2199
+ star_count: state.accountPackages.filter(
2200
+ (ap) => ap.package_id === pkg.package_id && ap.is_starred
2201
+ ).length
2202
+ }));
2203
+ },
2204
+ getSnippetByAuthorAndName: (authorName, snippetName) => {
2205
+ const state = get();
2206
+ const _package = state.packages.find(
2207
+ (pkg) => pkg.owner_github_username?.toLowerCase() === authorName.toLowerCase() && pkg.name.toLowerCase() === snippetName.toLowerCase() && pkg.is_snippet === true
2208
+ );
2209
+ if (!_package) return void 0;
2210
+ const packageRelease = state.packageReleases.find(
2211
+ (pr) => pr.package_release_id === _package.latest_package_release_id && pr.is_latest === true
2212
+ );
2213
+ if (!packageRelease) return void 0;
2214
+ const packageFiles = state.packageFiles.filter(
2215
+ (file) => file.package_release_id === packageRelease.package_release_id
2216
+ );
2217
+ const codeFile = packageFiles.find(
2218
+ (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
2219
+ );
2220
+ return {
2221
+ snippet_id: _package.package_id,
2222
+ package_release_id: _package.latest_package_release_id || "",
2223
+ unscoped_name: _package.unscoped_name,
2224
+ name: _package.name,
2225
+ owner_name: _package.owner_github_username || "",
2226
+ description: _package.description || "",
2227
+ snippet_type: _package.snippet_type || "board",
2228
+ code: codeFile?.content_text || "",
2229
+ dts: packageFiles.find((file) => file.file_path === "/dist/index.d.ts")?.content_text || "",
2230
+ compiled_js: packageFiles.find((file) => file.file_path === "/dist/index.js")?.content_text || "",
2231
+ created_at: _package.created_at,
2232
+ updated_at: _package.updated_at,
2233
+ star_count: _package.star_count || 0,
2234
+ is_starred: false,
2235
+ version: _package.latest_version || "0.0.1",
2236
+ circuit_json: packageFiles.find(
2237
+ (file) => file.file_path === "/dist/circuit.json"
2238
+ )?.content_text ? JSON.parse(
2239
+ packageFiles.find((file) => file.file_path === "/dist/circuit.json")?.content_text || "[]"
2240
+ ) : [],
2241
+ is_private: _package.is_private || false,
2242
+ is_public: _package.is_public || true,
2243
+ is_unlisted: _package.is_unlisted || false
2244
+ };
2245
+ },
2246
+ updateSnippet: (snippetId, updates) => {
2247
+ set((state) => {
2248
+ const packageIndex = state.packages.findIndex(
2249
+ (pkg) => pkg.package_id === snippetId && pkg.is_snippet === true
2250
+ );
2251
+ if (packageIndex === -1) {
2252
+ return state;
2253
+ }
2254
+ const timestamp = Date.now();
2255
+ const currentTime = new Date(timestamp).toISOString();
2256
+ const updatedPackages = [...state.packages];
2257
+ const currentPackage = updatedPackages[packageIndex];
2258
+ updatedPackages[packageIndex] = {
2259
+ ...currentPackage,
2260
+ description: updates.description ?? currentPackage.description,
2261
+ is_private: updates.is_private ?? currentPackage.is_private,
2262
+ is_public: updates.is_private !== void 0 ? !updates.is_private : currentPackage.is_public,
2263
+ is_unlisted: updates.is_private ? true : updates.is_unlisted ?? currentPackage.is_unlisted,
2264
+ updated_at: currentTime
2265
+ };
2266
+ const packageRelease2 = state.packageReleases.find(
2267
+ (pr) => pr.package_release_id === currentPackage.latest_package_release_id
2268
+ );
2269
+ if (!packageRelease2) return state;
2270
+ const updatedFiles = [...state.packageFiles];
2271
+ const packageFiles2 = updatedFiles.filter(
2272
+ (file) => file.package_release_id === packageRelease2.package_release_id
2273
+ );
2274
+ if (updates.code !== void 0) {
2275
+ const codeFileIndex = packageFiles2.findIndex(
2276
+ (file) => file.file_path === "index.tsx" || file.file_path === "index.ts"
2277
+ );
2278
+ if (codeFileIndex >= 0) {
2279
+ updatedFiles[codeFileIndex] = {
2280
+ ...packageFiles2[codeFileIndex],
2281
+ content_text: updates.code,
2282
+ created_at: currentTime
2283
+ };
2284
+ } else {
2285
+ updatedFiles.push({
2286
+ package_file_id: `package_file_${timestamp}`,
2287
+ package_release_id: packageRelease2.package_release_id,
2288
+ file_path: "index.tsx",
2289
+ content_text: updates.code,
2290
+ created_at: currentTime
2291
+ });
2292
+ }
2293
+ }
2294
+ if (updates.dts !== void 0) {
2295
+ const dtsFileIndex = packageFiles2.findIndex(
2296
+ (file) => file.file_path === "/dist/index.d.ts"
2297
+ );
2298
+ if (dtsFileIndex >= 0) {
2299
+ updatedFiles[dtsFileIndex] = {
2300
+ ...packageFiles2[dtsFileIndex],
2301
+ content_text: updates.dts,
2302
+ created_at: currentTime
2303
+ };
2304
+ } else {
2305
+ updatedFiles.push({
2306
+ package_file_id: `package_file_${timestamp}`,
2307
+ package_release_id: packageRelease2.package_release_id,
2308
+ file_path: "/dist/index.d.ts",
2309
+ content_text: updates.dts,
2310
+ created_at: currentTime
2311
+ });
2312
+ }
2313
+ }
2314
+ if (updates.compiled_js !== void 0) {
2315
+ const jsFileIndex = packageFiles2.findIndex(
2316
+ (file) => file.file_path === "/dist/index.js"
2317
+ );
2318
+ if (jsFileIndex >= 0) {
2319
+ updatedFiles[jsFileIndex] = {
2320
+ ...packageFiles2[jsFileIndex],
2321
+ content_text: updates.compiled_js,
2322
+ created_at: currentTime
2323
+ };
2324
+ } else {
2325
+ updatedFiles.push({
2326
+ package_file_id: `package_file_${timestamp}`,
2327
+ package_release_id: packageRelease2.package_release_id,
2328
+ file_path: "/dist/index.js",
2329
+ content_text: updates.compiled_js,
2330
+ created_at: currentTime
2331
+ });
2332
+ }
2333
+ }
2334
+ if (updates.circuit_json !== void 0) {
2335
+ const circuitFileIndex = packageFiles2.findIndex(
2336
+ (file) => file.file_path === "/dist/circuit.json"
2337
+ );
2338
+ if (circuitFileIndex >= 0) {
2339
+ updatedFiles[circuitFileIndex] = {
2340
+ ...packageFiles2[circuitFileIndex],
2341
+ content_text: JSON.stringify(updates.circuit_json),
2342
+ created_at: (/* @__PURE__ */ new Date()).toISOString()
2343
+ };
2344
+ }
2345
+ }
2346
+ return {
2347
+ ...state,
2348
+ packages: updatedPackages,
2349
+ packageFiles: updatedFiles
2350
+ };
2351
+ });
2352
+ const updatedPackage = get().packages.find(
2353
+ (pkg) => pkg.package_id === snippetId
2354
+ );
2355
+ if (!updatedPackage) return void 0;
2356
+ const packageRelease = get().packageReleases.find(
2357
+ (pr) => pr.package_release_id === updatedPackage.latest_package_release_id
2358
+ );
2359
+ if (!packageRelease) return void 0;
2360
+ const packageFiles = get().packageFiles.filter(
2361
+ (file) => file.package_release_id === packageRelease.package_release_id
2362
+ );
2363
+ const codeFile = packageFiles.find(
2364
+ (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
2365
+ );
2366
+ const dtsFile = packageFiles.find(
2367
+ (file) => file.file_path === "/dist/index.d.ts"
2368
+ );
2369
+ const jsFile = packageFiles.find(
2370
+ (file) => file.file_path === "/dist/index.js"
2371
+ );
2372
+ const circuitFile = packageFiles.find(
2373
+ (file) => file.file_path === "/dist/circuit.json"
2374
+ );
2375
+ return {
2376
+ snippet_id: updatedPackage.package_id,
2377
+ package_release_id: updatedPackage.latest_package_release_id || "",
2378
+ unscoped_name: updatedPackage.unscoped_name,
2379
+ name: updatedPackage.name,
2380
+ owner_name: updatedPackage.owner_github_username || "",
2381
+ description: updatedPackage.description || "",
2382
+ snippet_type: updatedPackage.snippet_type || "board",
2383
+ code: codeFile?.content_text || "",
2384
+ dts: dtsFile?.content_text || "",
2385
+ compiled_js: jsFile?.content_text || "",
2386
+ created_at: updatedPackage.created_at,
2387
+ updated_at: updatedPackage.updated_at,
2388
+ star_count: updatedPackage.star_count || 0,
2389
+ is_starred: false,
2390
+ version: updatedPackage.latest_version || "0.0.1",
2391
+ circuit_json: circuitFile ? JSON.parse(circuitFile.content_text || "[]") : [],
2392
+ is_private: updatedPackage.is_private ?? false,
2393
+ is_public: updatedPackage.is_public ?? true,
2394
+ is_unlisted: updatedPackage.is_unlisted ?? false
2395
+ };
2396
+ },
2397
+ getSnippetById: (snippetId, auth) => {
2398
+ const state = get();
2399
+ const _package = state.packages.find(
2400
+ (pkg) => pkg.package_id === snippetId && pkg.is_snippet === true
2401
+ );
2402
+ if (!_package) return void 0;
2403
+ if (!auth) {
2404
+ if (!_package.is_public || _package.is_unlisted) {
2405
+ return void 0;
2406
+ }
2407
+ } else {
2408
+ const isOwnPackage = _package.owner_github_username === auth?.github_username;
2409
+ const isPublicAndNotUnlisted = _package.is_public && !_package.is_unlisted;
2410
+ const isOwnUnlisted = _package.is_unlisted && isOwnPackage;
2411
+ const isOwnPrivate = _package.is_private && isOwnPackage;
2412
+ if (!isPublicAndNotUnlisted && !isOwnUnlisted && !isOwnPrivate) {
2413
+ return void 0;
2414
+ }
2415
+ }
2416
+ const packageRelease = state.packageReleases.find(
2417
+ (pr) => pr.package_release_id === _package.latest_package_release_id && pr.is_latest === true
2418
+ );
2419
+ if (!packageRelease) return void 0;
2420
+ const packageFiles = state.packageFiles.filter(
2421
+ (file) => file.package_release_id === packageRelease.package_release_id
2422
+ );
2423
+ const codeFile = packageFiles.find(
2424
+ (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
2425
+ );
2426
+ const isStarred = state.accountPackages.some(
2427
+ (ap) => ap.package_id === snippetId && ap.is_starred
2428
+ );
2429
+ return {
2430
+ snippet_id: _package.package_id,
2431
+ package_release_id: _package.latest_package_release_id || "",
2432
+ unscoped_name: _package.unscoped_name,
2433
+ name: _package.name,
2434
+ owner_name: _package.owner_github_username || "",
2435
+ description: _package.description || "",
2436
+ snippet_type: _package.snippet_type || "board",
2437
+ code: codeFile?.content_text || "",
2438
+ dts: packageFiles.find((file) => file.file_path === "/dist/index.d.ts")?.content_text || "",
2439
+ compiled_js: packageFiles.find((file) => file.file_path === "/dist/index.js")?.content_text || "",
2440
+ created_at: _package.created_at,
2441
+ updated_at: _package.updated_at,
2442
+ star_count: _package.star_count || 0,
2443
+ is_starred: isStarred,
2444
+ version: _package.latest_version || "0.0.1",
2445
+ circuit_json: packageFiles.find(
2446
+ (file) => file.file_path === "/dist/circuit.json"
2447
+ )?.content_text ? JSON.parse(
2448
+ packageFiles.find((file) => file.file_path === "/dist/circuit.json")?.content_text || "[]"
2449
+ ) : [],
2450
+ is_private: _package.is_private || false,
2451
+ is_public: _package.is_public || true,
2452
+ is_unlisted: _package.is_unlisted || false
2453
+ };
2454
+ },
2455
+ searchSnippets: (query) => {
2456
+ const state = get();
2457
+ const lowercaseQuery = query.toLowerCase();
2458
+ const packages = state.packages.filter((pkg) => pkg.is_snippet === true);
2459
+ const matchingPackagesByMetadata = packages.filter(
2460
+ (pkg) => pkg.name.toLowerCase().includes(lowercaseQuery) || pkg.description?.toLowerCase().includes(lowercaseQuery)
2461
+ );
2462
+ const matchingFilesByContent = state.packageFiles.filter(
2463
+ (file) => file.content_text?.toLowerCase().includes(lowercaseQuery) ?? false
2464
+ );
2465
+ const matchingPackagesByContent = matchingFilesByContent.map((file) => {
2466
+ const packageRelease = state.packageReleases.find(
2467
+ (pr) => pr.package_release_id === file.package_release_id
2468
+ );
2469
+ if (!packageRelease) return null;
2470
+ return packages.find(
2471
+ (pkg) => pkg.latest_package_release_id === packageRelease.package_release_id
2472
+ );
2473
+ }).filter((pkg) => pkg !== null);
2474
+ const matchingPackages = [
2475
+ .../* @__PURE__ */ new Set([...matchingPackagesByMetadata, ...matchingPackagesByContent])
2476
+ ];
2477
+ return matchingPackages.map((pkg) => {
2478
+ const packageRelease = state.packageReleases.find(
2479
+ (pr) => pr.package_release_id === pkg.latest_package_release_id && pr.is_latest === true
2480
+ );
2481
+ if (!packageRelease) return null;
2482
+ const packageFiles = state.packageFiles.filter(
2483
+ (file) => file.package_release_id === packageRelease.package_release_id
2484
+ );
2485
+ const codeFile = packageFiles.find(
2486
+ (file) => file.file_path === "index.ts" || file.file_path === "index.tsx"
2487
+ );
2488
+ const isStarred = state.accountPackages.some(
2489
+ (ap) => ap.package_id === pkg.package_id && ap.is_starred
2490
+ );
2491
+ return {
2492
+ snippet_id: pkg.package_id,
2493
+ package_release_id: pkg.latest_package_release_id || "",
2494
+ unscoped_name: pkg.unscoped_name,
2495
+ name: pkg.name,
2496
+ owner_name: pkg.owner_github_username || "",
2497
+ description: pkg.description || "",
2498
+ snippet_type: pkg.snippet_type || "board",
2499
+ code: codeFile?.content_text || "",
2500
+ dts: packageFiles.find((file) => file.file_path === "/dist/index.d.ts")?.content_text || "",
2501
+ compiled_js: packageFiles.find((file) => file.file_path === "/dist/index.js")?.content_text || "",
2502
+ created_at: pkg.created_at,
2503
+ updated_at: pkg.updated_at,
2504
+ star_count: pkg.star_count || 0,
2505
+ is_starred: isStarred,
2506
+ version: pkg.latest_version || "0.0.1",
2507
+ circuit_json: packageFiles.filter((file) => file.file_path === "/dist/circuit.json").flatMap((file) => JSON.parse(file.content_text || "[]")) || []
2508
+ };
2509
+ }).filter((snippet) => snippet !== null);
2510
+ },
2511
+ deleteSnippet: (snippetId) => {
2512
+ let deleted = false;
2513
+ set((state) => {
2514
+ const index = state.snippets.findIndex((s) => s.snippet_id === snippetId);
2515
+ if (index !== -1) {
2516
+ state.snippets.splice(index, 1);
2517
+ deleted = true;
2518
+ }
2519
+ return state;
2520
+ });
2521
+ return deleted;
2522
+ },
2523
+ addSession: (session) => {
2524
+ const newSession = { session_id: `session_${Date.now()}`, ...session };
2525
+ set((state) => ({
2526
+ sessions: [...state.sessions, newSession]
2527
+ }));
2528
+ return newSession;
2529
+ },
2530
+ getSessions: ({
2531
+ account_id,
2532
+ is_cli_session
2533
+ }) => {
2534
+ const state = get();
2535
+ return state.sessions.filter(
2536
+ (session) => session.account_id === account_id && (is_cli_session === void 0 || session.is_cli_session === is_cli_session)
2537
+ );
2538
+ },
2539
+ createLoginPage: () => {
2540
+ const newLoginPage = {
2541
+ login_page_id: `login_page_${Date.now()}`,
2542
+ login_page_auth_token: `token_${Date.now()}`,
2543
+ was_login_successful: false,
2544
+ has_been_used_to_create_session: false,
2545
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
2546
+ expires_at: new Date(Date.now() + 30 * 60 * 1e3).toISOString()
2547
+ // 30 minutes expiration
2548
+ };
2549
+ set((state) => ({
2550
+ loginPages: [...state.loginPages, newLoginPage]
2551
+ }));
2552
+ return newLoginPage;
2553
+ },
2554
+ getLoginPage: (loginPageId) => {
2555
+ const state = get();
2556
+ return state.loginPages.find((lp) => lp.login_page_id === loginPageId);
2557
+ },
2558
+ updateLoginPage: (loginPageId, updates) => {
2559
+ set((state) => ({
2560
+ loginPages: state.loginPages.map(
2561
+ (lp) => lp.login_page_id === loginPageId ? { ...lp, ...updates } : lp
2562
+ )
2563
+ }));
2564
+ },
2565
+ getAccount: (accountId) => {
2566
+ const state = get();
2567
+ return state.accounts.find((account) => account.account_id === accountId);
2568
+ },
2569
+ updateAccount: (accountId, updates) => {
2570
+ let updatedAccount;
2571
+ set((state) => {
2572
+ const accountIndex = state.accounts.findIndex(
2573
+ (account) => account.account_id === accountId
2574
+ );
2575
+ if (accountIndex !== -1) {
2576
+ updatedAccount = { ...state.accounts[accountIndex] };
2577
+ if (updates.shippingInfo) {
2578
+ updatedAccount.shippingInfo = {
2579
+ ...updatedAccount.shippingInfo,
2580
+ ...updates.shippingInfo
2581
+ };
2582
+ delete updates.shippingInfo;
2583
+ }
2584
+ updatedAccount = { ...updatedAccount, ...updates };
2585
+ const updatedAccounts = [...state.accounts];
2586
+ updatedAccounts[accountIndex] = updatedAccount;
2587
+ return { ...state, accounts: updatedAccounts };
2588
+ }
2589
+ return state;
2590
+ });
2591
+ return updatedAccount;
2592
+ },
2593
+ createSession: (session) => {
2594
+ const newSession = { session_id: `session_${Date.now()}`, ...session };
2595
+ set((state) => ({
2596
+ sessions: [...state.sessions, newSession]
2597
+ }));
2598
+ return newSession;
2599
+ },
2600
+ addStar: (accountId, packageId) => {
2601
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2602
+ const accountPackage = {
2603
+ account_package_id: `ap_${Date.now()}`,
2604
+ account_id: accountId,
2605
+ package_id: packageId,
2606
+ is_starred: true,
2607
+ created_at: now,
2608
+ updated_at: now
2609
+ };
2610
+ set((state) => {
2611
+ const packageIndex = state.packages.findIndex(
2612
+ (pkg) => pkg.package_id === packageId
2613
+ );
2614
+ if (packageIndex >= 0) {
2615
+ const updatedPackages = [...state.packages];
2616
+ updatedPackages[packageIndex] = {
2617
+ ...updatedPackages[packageIndex],
2618
+ star_count: (updatedPackages[packageIndex].star_count || 0) + 1
2619
+ };
2620
+ return {
2621
+ packages: updatedPackages,
2622
+ accountPackages: [...state.accountPackages, accountPackage]
2623
+ };
2624
+ }
2625
+ return {
2626
+ accountPackages: [...state.accountPackages, accountPackage]
2627
+ };
2628
+ });
2629
+ return accountPackage;
2630
+ },
2631
+ removeStar: (accountId, packageId) => {
2632
+ set((state) => {
2633
+ const packageIndex = state.packages.findIndex(
2634
+ (pkg) => pkg.package_id === packageId
2635
+ );
2636
+ if (packageIndex >= 0) {
2637
+ const updatedPackages = [...state.packages];
2638
+ updatedPackages[packageIndex] = {
2639
+ ...updatedPackages[packageIndex],
2640
+ star_count: Math.max(
2641
+ 0,
2642
+ (updatedPackages[packageIndex].star_count || 0) - 1
2643
+ )
2644
+ };
2645
+ return {
2646
+ packages: updatedPackages,
2647
+ accountPackages: state.accountPackages.filter(
2648
+ (ap) => !(ap.account_id === accountId && ap.package_id === packageId)
2649
+ )
2650
+ };
2651
+ }
2652
+ return {
2653
+ accountPackages: state.accountPackages.filter(
2654
+ (ap) => !(ap.account_id === accountId && ap.package_id === packageId)
2655
+ )
2656
+ };
2657
+ });
2658
+ },
2659
+ hasStarred: (accountId, packageId) => {
2660
+ const state = get();
2661
+ return state.accountPackages.some(
2662
+ (ap) => ap.account_id === accountId && ap.package_id === packageId && ap.is_starred
2663
+ );
2664
+ },
2665
+ addPackage: (_package) => {
2666
+ const timestamp = Date.now();
2667
+ const newPackage = {
2668
+ package_id: `package_${timestamp}`,
2669
+ ..._package
2670
+ };
2671
+ set((state) => ({
2672
+ packages: [...state.packages, newPackage]
2673
+ }));
2674
+ return newPackage;
2675
+ },
2676
+ updatePackage: (packageId, updates) => {
2677
+ let updatedPackage;
2678
+ set((state) => {
2679
+ const packageIndex = state.packages.findIndex(
2680
+ (pkg) => pkg.package_id === packageId
2681
+ );
2682
+ if (packageIndex === -1) return state;
2683
+ const updatedPackages = [...state.packages];
2684
+ updatedPackages[packageIndex] = {
2685
+ ...updatedPackages[packageIndex],
2686
+ ...updates
2687
+ };
2688
+ updatedPackage = updatedPackages[packageIndex];
2689
+ return { ...state, packages: updatedPackages };
2690
+ });
2691
+ return updatedPackage;
2692
+ },
2693
+ getPackageById: (packageId) => {
2694
+ const state = get();
2695
+ const pkg = state.packages.find((pkg2) => pkg2.package_id === packageId);
2696
+ if (!pkg) return void 0;
2697
+ return {
2698
+ ...pkg
2699
+ };
2700
+ },
2701
+ getPackageReleaseById: (packageReleaseId) => {
2702
+ const state = get();
2703
+ return state.packageReleases.find(
2704
+ (pr) => pr.package_release_id === packageReleaseId
2705
+ );
2706
+ },
2707
+ addPackageRelease: (packageRelease) => {
2708
+ const newPackageRelease = {
2709
+ package_release_id: `package_release_${Date.now()}`,
2710
+ ...packageRelease
2711
+ };
2712
+ set((state) => ({
2713
+ packageReleases: [...state.packageReleases, newPackageRelease]
2714
+ }));
2715
+ return newPackageRelease;
2716
+ },
2717
+ updatePackageRelease: (packageRelease) => {
2718
+ set((state) => ({
2719
+ packageReleases: state.packageReleases.map(
2720
+ (pr) => pr.package_release_id === packageRelease.package_release_id ? packageRelease : pr
2721
+ )
2722
+ }));
2723
+ },
2724
+ addPackageFile: (packageFile) => {
2725
+ const newPackageFile = {
2726
+ package_file_id: `package_file_${Date.now()}`,
2727
+ ...packageFile
2728
+ };
2729
+ set((state) => ({
2730
+ packageFiles: [...state.packageFiles, newPackageFile]
2731
+ }));
2732
+ return newPackageFile;
2733
+ },
2734
+ getStarCount: (packageId) => {
2735
+ const state = get();
2736
+ return state.accountPackages.filter(
2737
+ (ap) => ap.package_id === packageId && ap.is_starred
2738
+ ).length;
2739
+ },
2740
+ getPackageFilesByReleaseId: (packageReleaseId) => {
2741
+ const state = get();
2742
+ return state.packageFiles.filter(
2743
+ (pf) => pf.package_release_id === packageReleaseId
2744
+ );
2745
+ }
2746
+ }));
2747
+
2748
+ // fake-snippets-api/lib/middleware/with-db.ts
2749
+ var withDb = async (req, ctx, next) => {
2750
+ if (!ctx.db) {
2751
+ ctx.db = createDatabase();
2752
+ }
2753
+ return next(req, ctx);
2754
+ };
2755
+ export {
2756
+ createDatabase,
2757
+ seed,
2758
+ withDb
2759
+ };