@jlcpcb/core 0.1.0

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 (44) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +474 -0
  3. package/package.json +48 -0
  4. package/src/api/easyeda-community.ts +259 -0
  5. package/src/api/easyeda.ts +153 -0
  6. package/src/api/index.ts +7 -0
  7. package/src/api/jlc.ts +185 -0
  8. package/src/constants/design-rules.ts +119 -0
  9. package/src/constants/footprints.ts +68 -0
  10. package/src/constants/index.ts +7 -0
  11. package/src/constants/kicad.ts +147 -0
  12. package/src/converter/category-router.ts +638 -0
  13. package/src/converter/footprint-mapper.ts +236 -0
  14. package/src/converter/footprint.ts +949 -0
  15. package/src/converter/global-lib-table.ts +394 -0
  16. package/src/converter/index.ts +46 -0
  17. package/src/converter/lib-table.ts +181 -0
  18. package/src/converter/svg-arc.ts +179 -0
  19. package/src/converter/symbol-templates.ts +214 -0
  20. package/src/converter/symbol.ts +1682 -0
  21. package/src/converter/value-normalizer.ts +262 -0
  22. package/src/index.ts +25 -0
  23. package/src/parsers/easyeda-shapes.ts +628 -0
  24. package/src/parsers/http-client.ts +96 -0
  25. package/src/parsers/index.ts +38 -0
  26. package/src/parsers/utils.ts +29 -0
  27. package/src/services/component-service.ts +100 -0
  28. package/src/services/fix-service.ts +50 -0
  29. package/src/services/index.ts +9 -0
  30. package/src/services/library-service.ts +696 -0
  31. package/src/types/component.ts +61 -0
  32. package/src/types/easyeda-community.ts +78 -0
  33. package/src/types/easyeda.ts +356 -0
  34. package/src/types/index.ts +12 -0
  35. package/src/types/jlc.ts +84 -0
  36. package/src/types/kicad.ts +136 -0
  37. package/src/types/mcp.ts +77 -0
  38. package/src/types/project.ts +60 -0
  39. package/src/utils/conversion.ts +104 -0
  40. package/src/utils/file-system.ts +143 -0
  41. package/src/utils/index.ts +8 -0
  42. package/src/utils/logger.ts +96 -0
  43. package/src/utils/validation.ts +110 -0
  44. package/tsconfig.json +9 -0
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Schema validation helpers using Zod
3
+ */
4
+
5
+ import { z } from 'zod';
6
+
7
+ // Component validation schemas
8
+ export const LCSCPartNumberSchema = z.string().regex(/^C\d+$/, 'Invalid LCSC part number format (expected C followed by digits)');
9
+
10
+ export const PackageSchema = z.string().min(1, 'Package cannot be empty');
11
+
12
+ export const PriceTierSchema = z.object({
13
+ quantity: z.number().positive(),
14
+ price: z.number().nonnegative(),
15
+ currency: z.string().default('USD'),
16
+ });
17
+
18
+ export const ComponentSchema = z.object({
19
+ lcscPartNumber: LCSCPartNumberSchema,
20
+ manufacturerPart: z.string().min(1),
21
+ manufacturer: z.string().min(1),
22
+ description: z.string(),
23
+ category: z.string(),
24
+ subcategory: z.string(),
25
+ package: PackageSchema,
26
+ stock: z.number().nonnegative(),
27
+ price: z.array(PriceTierSchema),
28
+ datasheet: z.string().url().optional(),
29
+ });
30
+
31
+ // Project validation schemas
32
+ export const BoardSizeSchema = z.object({
33
+ width: z.number().positive(),
34
+ height: z.number().positive(),
35
+ unit: z.enum(['mm', 'inch']).default('mm'),
36
+ });
37
+
38
+ export const PowerSourceSchema = z.object({
39
+ type: z.enum(['usb', 'battery', 'dc_jack', 'poe', 'other']),
40
+ voltage: z.object({
41
+ min: z.number(),
42
+ max: z.number(),
43
+ }),
44
+ current: z.number().positive().optional(),
45
+ details: z.string().optional(),
46
+ });
47
+
48
+ export const DesignConstraintsSchema = z.object({
49
+ boardSize: BoardSizeSchema.optional(),
50
+ layers: z.number().min(1).max(32).default(2),
51
+ powerSource: PowerSourceSchema,
52
+ interfaces: z.array(z.object({
53
+ type: z.string(),
54
+ count: z.number().positive().optional(),
55
+ details: z.string().optional(),
56
+ })),
57
+ environment: z.object({
58
+ tempMin: z.number().default(-20),
59
+ tempMax: z.number().default(70),
60
+ indoor: z.boolean().default(true),
61
+ certifications: z.array(z.string()).optional(),
62
+ }).optional(),
63
+ manufacturingClass: z.number().min(1).max(3).optional(),
64
+ });
65
+
66
+ // KiCad validation schemas
67
+ export const KiCadPinTypeSchema = z.enum([
68
+ 'input',
69
+ 'output',
70
+ 'bidirectional',
71
+ 'power_in',
72
+ 'power_out',
73
+ 'passive',
74
+ 'unspecified',
75
+ 'open_collector',
76
+ 'open_emitter',
77
+ 'no_connect',
78
+ ]);
79
+
80
+ export const KiCadPadTypeSchema = z.enum([
81
+ 'thru_hole',
82
+ 'smd',
83
+ 'connect',
84
+ 'np_thru_hole',
85
+ ]);
86
+
87
+ export const KiCadPadShapeSchema = z.enum([
88
+ 'circle',
89
+ 'rect',
90
+ 'oval',
91
+ 'trapezoid',
92
+ 'roundrect',
93
+ 'custom',
94
+ ]);
95
+
96
+ // Validation helper functions
97
+ export function validateLCSCPartNumber(partNumber: string): boolean {
98
+ return LCSCPartNumberSchema.safeParse(partNumber).success;
99
+ }
100
+
101
+ export function validateComponent(component: unknown): boolean {
102
+ return ComponentSchema.safeParse(component).success;
103
+ }
104
+
105
+ export function validateDesignConstraints(constraints: unknown): boolean {
106
+ return DesignConstraintsSchema.safeParse(constraints).success;
107
+ }
108
+
109
+ export type ValidatedComponent = z.infer<typeof ComponentSchema>;
110
+ export type ValidatedDesignConstraints = z.infer<typeof DesignConstraintsSchema>;
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "emitDeclarationOnly": true
7
+ },
8
+ "include": ["src/**/*"]
9
+ }