@grayhaven/nerve 0.1.0 → 0.2.1

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 (4) hide show
  1. package/dist/index.d.ts +181 -20
  2. package/dist/index.js +86 -28
  3. package/package.json +19 -15
  4. package/LICENSE +0 -202
package/dist/index.d.ts CHANGED
@@ -12,6 +12,15 @@ import { Schema } from 'effect';
12
12
  */
13
13
  type Units = "mm" | "in";
14
14
  type ConnectorGender = "plug" | "receptacle" | "hermaphroditic";
15
+ /** Datasheet/source provenance and verification state (PRD §30, §38). */
16
+ interface PartProvenance {
17
+ readonly source?: string;
18
+ readonly datasheet?: string;
19
+ /** "verified" requires a review pass; library seed data is "inspired-by". */
20
+ readonly verification: "unverified" | "inspired-by" | "verified";
21
+ /** ISO date of last verification. */
22
+ readonly lastVerified?: string;
23
+ }
15
24
  /**
16
25
  * Component master data for a connector housing (PRD §9.2, §30).
17
26
  * Instances reference a part; parts live in libraries such as
@@ -32,10 +41,19 @@ interface ConnectorPart {
32
41
  readonly matingMpn?: string;
33
42
  readonly compatibleTerminals?: ReadonlyArray<string>;
34
43
  readonly compatibleSeals?: ReadonlyArray<string>;
44
+ readonly compatibleBackshells?: ReadonlyArray<string>;
35
45
  readonly wireGaugeRange?: {
36
46
  readonly min: string;
37
47
  readonly max: string;
38
48
  };
49
+ /** Environmentally sealed housing: every populated cavity needs a seal. */
50
+ readonly sealed?: boolean;
51
+ readonly currentLimitA?: number;
52
+ readonly voltageLimitV?: number;
53
+ readonly crimpTool?: string;
54
+ readonly insertionTool?: string;
55
+ readonly extractionTool?: string;
56
+ readonly provenance?: PartProvenance;
39
57
  }
40
58
  /** A reference to a specific pin/cavity on a connector instance. */
41
59
  interface PinRef {
@@ -58,6 +76,10 @@ interface ConnectorInstance {
58
76
  readonly ref: string;
59
77
  readonly part: ConnectorPart;
60
78
  readonly pins: Readonly<Record<string, string>>;
79
+ /** Terminal MPN per pin (PRD §30). */
80
+ readonly terminals: Readonly<Record<string, string>>;
81
+ /** Seal MPN per pin. */
82
+ readonly seals: Readonly<Record<string, string>>;
61
83
  /** Build a `PinRef` for a pin on this connector. */
62
84
  pin(pin: string | number): PinRef;
63
85
  }
@@ -183,9 +205,16 @@ interface HarnessDesign {
183
205
  * diagnostics instead of throwing mid-definition.
184
206
  */
185
207
 
186
- /** Place a connector in the harness: `connector("J1", MolexMicroFit["43025-0800"], { pins: {...} })`. */
208
+ /**
209
+ * Per-pin part assignment: a map of pin → MPN, or a single MPN applied to
210
+ * every assigned pin (the common case — one terminal type per housing).
211
+ */
212
+ type PinPartAssignment = string | Readonly<Record<string | number, string>>;
213
+ /** Place a connector in the harness: `connector("J1", MolexMicroFit["43025-0800"], { pins: {...}, terminals: "43030-0007" })`. */
187
214
  declare const connector: (ref: string, part: ConnectorPart, opts: {
188
215
  readonly pins: PinAssignments;
216
+ readonly terminals?: PinPartAssignment;
217
+ readonly seals?: PinPartAssignment;
189
218
  }) => ConnectorInstance;
190
219
  /** Anything a wire can terminate on: a pin ref, a splice (def or ref). */
191
220
  type EndpointInput = PinRef | SpliceDef | {
@@ -249,7 +278,6 @@ declare const Codes: {
249
278
  };
250
279
  declare const hasErrors: (diagnostics: ReadonlyArray<Diagnostic>) => boolean;
251
280
 
252
- declare const HIR_SCHEMA_VERSION: "0.1.0";
253
281
  declare const Hir: Schema.Struct<{
254
282
  schemaVersion: Schema.Literal<["0.1.0"]>;
255
283
  harness: Schema.Struct<{
@@ -270,9 +298,21 @@ declare const Hir: Schema.Struct<{
270
298
  min: typeof Schema.String;
271
299
  max: typeof Schema.String;
272
300
  }>>;
301
+ sealed: Schema.optional<typeof Schema.Boolean>;
302
+ compatibleTerminals: Schema.optional<Schema.Array$<typeof Schema.String>>;
303
+ compatibleSeals: Schema.optional<Schema.Array$<typeof Schema.String>>;
304
+ crimpTool: Schema.optional<typeof Schema.String>;
305
+ provenance: Schema.optional<Schema.Struct<{
306
+ source: Schema.optional<typeof Schema.String>;
307
+ datasheet: Schema.optional<typeof Schema.String>;
308
+ verification: Schema.Literal<["unverified", "inspired-by", "verified"]>;
309
+ lastVerified: Schema.optional<typeof Schema.String>;
310
+ }>>;
273
311
  pins: Schema.Array$<Schema.Struct<{
274
312
  pin: typeof Schema.String;
275
313
  signal: Schema.optional<typeof Schema.String>;
314
+ terminal: Schema.optional<typeof Schema.String>;
315
+ seal: Schema.optional<typeof Schema.String>;
276
316
  }>>;
277
317
  }>>;
278
318
  wires: Schema.Array$<Schema.Struct<{
@@ -379,9 +419,21 @@ declare const HirConnector: Schema.Struct<{
379
419
  min: typeof Schema.String;
380
420
  max: typeof Schema.String;
381
421
  }>>;
422
+ sealed: Schema.optional<typeof Schema.Boolean>;
423
+ compatibleTerminals: Schema.optional<Schema.Array$<typeof Schema.String>>;
424
+ compatibleSeals: Schema.optional<Schema.Array$<typeof Schema.String>>;
425
+ crimpTool: Schema.optional<typeof Schema.String>;
426
+ provenance: Schema.optional<Schema.Struct<{
427
+ source: Schema.optional<typeof Schema.String>;
428
+ datasheet: Schema.optional<typeof Schema.String>;
429
+ verification: Schema.Literal<["unverified", "inspired-by", "verified"]>;
430
+ lastVerified: Schema.optional<typeof Schema.String>;
431
+ }>>;
382
432
  pins: Schema.Array$<Schema.Struct<{
383
433
  pin: typeof Schema.String;
384
434
  signal: Schema.optional<typeof Schema.String>;
435
+ terminal: Schema.optional<typeof Schema.String>;
436
+ seal: Schema.optional<typeof Schema.String>;
385
437
  }>>;
386
438
  }>;
387
439
  type HirConnector = Schema.Schema.Type<typeof HirConnector>;
@@ -490,10 +542,6 @@ declare const HirCable: Schema.Struct<{
490
542
  wires: Schema.Array$<typeof Schema.String>;
491
543
  }>;
492
544
  type HirCable = Schema.Schema.Type<typeof HirCable>;
493
- /** Narrow an endpoint to a pin ref. */
494
- declare const isPinEndpoint: (e: HirEndpoint) => e is HirPinRef;
495
- /** Stable display form: `J1.1` or `S1`. */
496
- declare const endpointLabel: (e: HirEndpoint) => string;
497
545
  /** Decode an untrusted value (e.g. a cached `harness.json`) into HIR. Throws `ParseError`. */
498
546
  declare const decodeHir: (u: unknown, overrideOptions?: effect_SchemaAST.ParseOptions) => {
499
547
  readonly harness: {
@@ -537,8 +585,8 @@ declare const decodeHir: (u: unknown, overrideOptions?: effect_SchemaAST.ParseOp
537
585
  }[];
538
586
  readonly schemaVersion: "0.1.0";
539
587
  readonly connectors: readonly {
540
- readonly ref: string;
541
588
  readonly mpn: string;
589
+ readonly ref: string;
542
590
  readonly manufacturer?: string | undefined;
543
591
  readonly family?: string | undefined;
544
592
  readonly description?: string | undefined;
@@ -548,9 +596,21 @@ declare const decodeHir: (u: unknown, overrideOptions?: effect_SchemaAST.ParseOp
548
596
  readonly min: string;
549
597
  readonly max: string;
550
598
  } | undefined;
599
+ readonly sealed?: boolean | undefined;
600
+ readonly compatibleTerminals?: readonly string[] | undefined;
601
+ readonly compatibleSeals?: readonly string[] | undefined;
602
+ readonly crimpTool?: string | undefined;
603
+ readonly provenance?: {
604
+ readonly source?: string | undefined;
605
+ readonly datasheet?: string | undefined;
606
+ readonly verification: "unverified" | "inspired-by" | "verified";
607
+ readonly lastVerified?: string | undefined;
608
+ } | undefined;
551
609
  readonly pins: readonly {
552
610
  readonly pin: string;
553
611
  readonly signal?: string | undefined;
612
+ readonly terminal?: string | undefined;
613
+ readonly seal?: string | undefined;
554
614
  }[];
555
615
  }[];
556
616
  readonly cables: readonly {
@@ -591,8 +651,8 @@ declare const decodeHir: (u: unknown, overrideOptions?: effect_SchemaAST.ParseOp
591
651
  readonly quantity?: number | undefined;
592
652
  }[];
593
653
  readonly bom: readonly {
594
- readonly quantity: number;
595
654
  readonly mpn: string;
655
+ readonly quantity: number;
596
656
  readonly manufacturer?: string | undefined;
597
657
  readonly description?: string | undefined;
598
658
  readonly notes?: string | undefined;
@@ -655,8 +715,8 @@ declare const decodeHirEffect: (u: unknown, overrideOptions?: effect_SchemaAST.P
655
715
  }[];
656
716
  readonly schemaVersion: "0.1.0";
657
717
  readonly connectors: readonly {
658
- readonly ref: string;
659
718
  readonly mpn: string;
719
+ readonly ref: string;
660
720
  readonly manufacturer?: string | undefined;
661
721
  readonly family?: string | undefined;
662
722
  readonly description?: string | undefined;
@@ -666,9 +726,21 @@ declare const decodeHirEffect: (u: unknown, overrideOptions?: effect_SchemaAST.P
666
726
  readonly min: string;
667
727
  readonly max: string;
668
728
  } | undefined;
729
+ readonly sealed?: boolean | undefined;
730
+ readonly compatibleTerminals?: readonly string[] | undefined;
731
+ readonly compatibleSeals?: readonly string[] | undefined;
732
+ readonly crimpTool?: string | undefined;
733
+ readonly provenance?: {
734
+ readonly source?: string | undefined;
735
+ readonly datasheet?: string | undefined;
736
+ readonly verification: "unverified" | "inspired-by" | "verified";
737
+ readonly lastVerified?: string | undefined;
738
+ } | undefined;
669
739
  readonly pins: readonly {
670
740
  readonly pin: string;
671
741
  readonly signal?: string | undefined;
742
+ readonly terminal?: string | undefined;
743
+ readonly seal?: string | undefined;
672
744
  }[];
673
745
  }[];
674
746
  readonly cables: readonly {
@@ -709,8 +781,8 @@ declare const decodeHirEffect: (u: unknown, overrideOptions?: effect_SchemaAST.P
709
781
  readonly quantity?: number | undefined;
710
782
  }[];
711
783
  readonly bom: readonly {
712
- readonly quantity: number;
713
784
  readonly mpn: string;
785
+ readonly quantity: number;
714
786
  readonly manufacturer?: string | undefined;
715
787
  readonly description?: string | undefined;
716
788
  readonly notes?: string | undefined;
@@ -773,8 +845,8 @@ declare const encodeHir: (a: {
773
845
  }[];
774
846
  readonly schemaVersion: "0.1.0";
775
847
  readonly connectors: readonly {
776
- readonly ref: string;
777
848
  readonly mpn: string;
849
+ readonly ref: string;
778
850
  readonly manufacturer?: string | undefined;
779
851
  readonly family?: string | undefined;
780
852
  readonly description?: string | undefined;
@@ -784,9 +856,21 @@ declare const encodeHir: (a: {
784
856
  readonly min: string;
785
857
  readonly max: string;
786
858
  } | undefined;
859
+ readonly sealed?: boolean | undefined;
860
+ readonly compatibleTerminals?: readonly string[] | undefined;
861
+ readonly compatibleSeals?: readonly string[] | undefined;
862
+ readonly crimpTool?: string | undefined;
863
+ readonly provenance?: {
864
+ readonly source?: string | undefined;
865
+ readonly datasheet?: string | undefined;
866
+ readonly verification: "unverified" | "inspired-by" | "verified";
867
+ readonly lastVerified?: string | undefined;
868
+ } | undefined;
787
869
  readonly pins: readonly {
788
870
  readonly pin: string;
789
871
  readonly signal?: string | undefined;
872
+ readonly terminal?: string | undefined;
873
+ readonly seal?: string | undefined;
790
874
  }[];
791
875
  }[];
792
876
  readonly cables: readonly {
@@ -827,8 +911,8 @@ declare const encodeHir: (a: {
827
911
  readonly quantity?: number | undefined;
828
912
  }[];
829
913
  readonly bom: readonly {
830
- readonly quantity: number;
831
914
  readonly mpn: string;
915
+ readonly quantity: number;
832
916
  readonly manufacturer?: string | undefined;
833
917
  readonly description?: string | undefined;
834
918
  readonly notes?: string | undefined;
@@ -889,12 +973,14 @@ declare const encodeHir: (a: {
889
973
  }[];
890
974
  readonly schemaVersion: "0.1.0";
891
975
  readonly connectors: readonly {
892
- readonly ref: string;
893
976
  readonly mpn: string;
977
+ readonly ref: string;
894
978
  readonly pinCount: number;
895
979
  readonly pins: readonly {
896
980
  readonly pin: string;
897
981
  readonly signal?: string | undefined;
982
+ readonly terminal?: string | undefined;
983
+ readonly seal?: string | undefined;
898
984
  }[];
899
985
  readonly manufacturer?: string | undefined;
900
986
  readonly family?: string | undefined;
@@ -904,6 +990,16 @@ declare const encodeHir: (a: {
904
990
  readonly min: string;
905
991
  readonly max: string;
906
992
  } | undefined;
993
+ readonly sealed?: boolean | undefined;
994
+ readonly compatibleTerminals?: readonly string[] | undefined;
995
+ readonly compatibleSeals?: readonly string[] | undefined;
996
+ readonly crimpTool?: string | undefined;
997
+ readonly provenance?: {
998
+ readonly verification: "unverified" | "inspired-by" | "verified";
999
+ readonly source?: string | undefined;
1000
+ readonly datasheet?: string | undefined;
1001
+ readonly lastVerified?: string | undefined;
1002
+ } | undefined;
907
1003
  }[];
908
1004
  readonly cables: readonly {
909
1005
  readonly id: string;
@@ -943,8 +1039,8 @@ declare const encodeHir: (a: {
943
1039
  readonly quantity?: number | undefined;
944
1040
  }[];
945
1041
  readonly bom: readonly {
946
- readonly quantity: number;
947
1042
  readonly mpn: string;
1043
+ readonly quantity: number;
948
1044
  readonly unitOfMeasure: string;
949
1045
  readonly usedBy: readonly string[];
950
1046
  readonly manufacturer?: string | undefined;
@@ -964,6 +1060,19 @@ declare const encodeHir: (a: {
964
1060
  readonly [x: string]: unknown;
965
1061
  };
966
1062
  };
1063
+
1064
+ /**
1065
+ * Effect-free HIR values. Lives apart from schema.ts (whose top-level
1066
+ * Schema.Struct construction pins the effect runtime into any chunk that
1067
+ * includes it) so pure consumers — formatters, the web client, rules —
1068
+ * tree-shake cleanly. Types import from schema.ts type-only (erased).
1069
+ */
1070
+
1071
+ declare const HIR_SCHEMA_VERSION: "0.1.0";
1072
+ /** Narrow an endpoint to a pin ref. */
1073
+ declare const isPinEndpoint: (e: HirEndpoint) => e is HirPinRef;
1074
+ /** Stable display form: `J1.1` or `S1`. */
1075
+ declare const endpointLabel: (e: HirEndpoint) => string;
967
1076
  /** Stable object references (PRD §19), e.g. `connector:J1.pin:1`. */
968
1077
  declare const refs: {
969
1078
  readonly connector: (ref: string) => string;
@@ -1052,11 +1161,47 @@ declare const runRules: (hir: Hir, rules: ReadonlyArray<Rule>, config?: RuleConf
1052
1161
  * ```
1053
1162
  */
1054
1163
 
1164
+ /** Lifecycle risk per PRD §29 supplier/lifecycle fields. */
1165
+ type PartLifecycle = "active" | "nrnd" | "obsolete";
1166
+ interface PartCost {
1167
+ readonly unitCost: number;
1168
+ readonly supplier?: string;
1169
+ readonly leadTimeDays?: number;
1170
+ readonly lifecycle?: PartLifecycle;
1171
+ }
1172
+ /**
1173
+ * Cost and quote model (PRD §29). Prices are organization data, not design
1174
+ * data — they live in config (or a future part-data provider, §42), never
1175
+ * in the HIR.
1176
+ */
1177
+ interface CostModel {
1178
+ readonly currency?: string;
1179
+ readonly laborRatePerHour: number;
1180
+ /** Fraction of material lost to scrap, e.g. 0.05. */
1181
+ readonly scrapFactor?: number;
1182
+ /** First-pass yield, e.g. 0.97 — per-unit cost divides by this. */
1183
+ readonly yield?: number;
1184
+ /** Days at/above which a part is flagged long-lead. Default 60. */
1185
+ readonly longLeadThresholdDays?: number;
1186
+ /** Part costs by MPN (connectors, terminals, seals, splice parts...). */
1187
+ readonly parts?: Readonly<Record<string, PartCost>>;
1188
+ /** Wire cost per meter by gauge, e.g. { "18AWG": 0.22 }. */
1189
+ readonly wireCostPerMeter?: Readonly<Record<string, number>>;
1190
+ readonly defaultWireCostPerMeter?: number;
1191
+ readonly sleeveCostPerMeter?: number;
1192
+ readonly labelUnitCost?: number;
1193
+ readonly spliceUnitCost?: number;
1194
+ /** Fallback for parts with no entry; also flags the line as unpriced. */
1195
+ readonly defaultPartCost?: number;
1196
+ }
1055
1197
  interface NerveConfig {
1056
1198
  readonly units?: Units;
1057
1199
  readonly defaultWireTolerance?: number;
1058
1200
  readonly outputDir?: string;
1059
1201
  readonly rules?: RuleConfig;
1202
+ readonly costing?: CostModel;
1203
+ /** Plugin module paths (relative to the harness file) — rule packs etc. (PRD §40). */
1204
+ readonly plugins?: ReadonlyArray<string>;
1060
1205
  readonly exports?: {
1061
1206
  readonly csv?: boolean;
1062
1207
  readonly svg?: boolean;
@@ -1102,14 +1247,30 @@ interface VariantOptions {
1102
1247
  declare const variant: (base: HarnessDesign, opts: VariantOptions) => HarnessDesign;
1103
1248
 
1104
1249
  /**
1105
- * Revision diff (PRD §21, DoD #9).
1250
+ * Plugin SDK (PRD §40).
1251
+ *
1252
+ * Typed extension boundary. The contract:
1253
+ * - plugins declare which HIR schema versions they support — the compiler
1254
+ * refuses mismatches with a diagnostic instead of undefined behavior,
1255
+ * - plugin rules report through the standard typed diagnostic channel,
1256
+ * - plugins MUST NOT mutate the HIR (rules receive it read-only),
1257
+ * - plugins are plain modules, executable locally and in CI.
1106
1258
  *
1107
- * Pure structural comparison of two HIR documents. Identifies added,
1108
- * removed, and changed connectors, pinouts, wires, branches, labels, and
1109
- * BOM rows — the categories §21 requires. Deterministic: output order
1110
- * follows canonical HIR ordering.
1259
+ * First plugin surface: rule packs (the §38 standards-pack vehicle).
1260
+ * Importers/exporters/renderers join as their host seams stabilize.
1111
1261
  */
1112
1262
 
1263
+ interface NervePlugin {
1264
+ readonly name: string;
1265
+ readonly version?: string;
1266
+ /** HIR schema versions this plugin understands. */
1267
+ readonly hirSchemaVersions: ReadonlyArray<string>;
1268
+ readonly rules?: ReadonlyArray<Rule>;
1269
+ }
1270
+ /** Identity helper for typed plugin modules: `export default definePlugin({...})`. */
1271
+ declare const definePlugin: (plugin: NervePlugin) => NervePlugin;
1272
+ declare const isNervePlugin: (value: unknown) => value is NervePlugin;
1273
+
1113
1274
  interface FieldChange {
1114
1275
  readonly field: string;
1115
1276
  readonly from: string;
@@ -1146,4 +1307,4 @@ declare const isEmptyDiff: (d: HirDiff) => boolean;
1146
1307
  /** Human-readable diff (git-diff-flavored prefixes). */
1147
1308
  declare const formatDiff: (d: HirDiff) => string;
1148
1309
 
1149
- export { type BranchDef, type BranchProps, type CableDef, type CableProps, Codes, type CompileResult, type ConnectorGender, type ConnectorInstance, type ConnectorPart, type Diagnostic, DiagnosticSeverity, type EndpointInput, type EntityChange, type FieldChange, HIR_SCHEMA_VERSION, type HarnessDesign, type HarnessProps, Hir, HirBomItem, HirBranch, HirCable, HirConnector, type HirDiff, HirEndpoint, HirLabel, HirPinRef, HirSplice, HirSpliceRef, HirWire, type LabelDef, type LabelProps, type NerveConfig, type PinAssignments, type PinRef, type PinoutChange, type Rule, type RuleConfig, type RuleContext, type RuleOptions, type RuleReport, type SectionDiff, type SpliceDef, type SpliceProps, type SpliceRef, type Units, type VariantOptions, type WireDef, type WireEndpoint, type WireProps, branch, cable, compileDesign, connector, decodeHir, decodeHirEffect, defineConfig, diffHir, encodeHir, endpointLabel, formatDiff, harness, hasErrors, isEmptyDiff, isPinEndpoint, label, refs, rule, runRules, splice, variant, wire };
1310
+ export { type BranchDef, type BranchProps, type CableDef, type CableProps, Codes, type CompileResult, type ConnectorGender, type ConnectorInstance, type ConnectorPart, type CostModel, type Diagnostic, DiagnosticSeverity, type EndpointInput, type EntityChange, type FieldChange, HIR_SCHEMA_VERSION, type HarnessDesign, type HarnessProps, Hir, HirBomItem, HirBranch, HirCable, HirConnector, type HirDiff, HirEndpoint, HirLabel, HirPinRef, HirSplice, HirSpliceRef, HirWire, type LabelDef, type LabelProps, type NerveConfig, type NervePlugin, type PartCost, type PartLifecycle, type PartProvenance, type PinAssignments, type PinPartAssignment, type PinRef, type PinoutChange, type Rule, type RuleConfig, type RuleContext, type RuleOptions, type RuleReport, type SectionDiff, type SpliceDef, type SpliceProps, type SpliceRef, type Units, type VariantOptions, type WireDef, type WireEndpoint, type WireProps, branch, cable, compileDesign, connector, decodeHir, decodeHirEffect, defineConfig, definePlugin, diffHir, encodeHir, endpointLabel, formatDiff, harness, hasErrors, isEmptyDiff, isNervePlugin, isPinEndpoint, label, refs, rule, runRules, splice, variant, wire };
package/dist/index.js CHANGED
@@ -1,5 +1,14 @@
1
1
  // src/dsl.ts
2
2
  var toRef = (target) => typeof target === "string" ? target : target.ref;
3
+ var expandPinParts = (assignment, pins) => {
4
+ if (assignment === void 0) return {};
5
+ if (typeof assignment === "string") {
6
+ return Object.fromEntries(Object.keys(pins).map((pin) => [pin, assignment]));
7
+ }
8
+ return Object.fromEntries(
9
+ Object.entries(assignment).map(([pin, mpn]) => [String(pin), mpn])
10
+ );
11
+ };
3
12
  var connector = (ref, part, opts) => {
4
13
  const pins = {};
5
14
  for (const [pin, signal] of Object.entries(opts.pins)) {
@@ -10,6 +19,8 @@ var connector = (ref, part, opts) => {
10
19
  ref,
11
20
  part,
12
21
  pins,
22
+ terminals: expandPinParts(opts.terminals, pins),
23
+ seals: expandPinParts(opts.seals, pins),
13
24
  pin: (pin) => ({
14
25
  kind: "pin-ref",
15
26
  connector: ref,
@@ -93,9 +104,22 @@ var Codes = {
93
104
  };
94
105
  var hasErrors = (diagnostics) => diagnostics.some((d) => d.severity === DiagnosticSeverity.Error);
95
106
 
107
+ // src/hir/core.ts
108
+ var HIR_SCHEMA_VERSION = "0.1.0";
109
+ var isPinEndpoint = (e) => "connector" in e;
110
+ var endpointLabel = (e) => isPinEndpoint(e) ? `${e.connector}.${e.pin}` : e.splice;
111
+ var refs = {
112
+ connector: (ref) => `connector:${ref}`,
113
+ pin: (connector2, pin) => `connector:${connector2}.pin:${pin}`,
114
+ wire: (id) => `wire:${id}`,
115
+ branch: (id) => `branch:${id}`,
116
+ splice: (id) => `splice:${id}`,
117
+ label: (id) => `label:${id}`,
118
+ bom: (mpn) => `bom:${mpn}`
119
+ };
120
+
96
121
  // src/hir/schema.ts
97
122
  import { Schema } from "effect";
98
- var HIR_SCHEMA_VERSION = "0.1.0";
99
123
  var HirUnits = Schema.Literal("mm", "in");
100
124
  var HirPinRef = Schema.Struct({
101
125
  connector: Schema.String,
@@ -107,7 +131,15 @@ var HirSpliceRef = Schema.Struct({
107
131
  var HirEndpoint = Schema.Union(HirPinRef, HirSpliceRef);
108
132
  var HirPin = Schema.Struct({
109
133
  pin: Schema.String,
110
- signal: Schema.optional(Schema.String)
134
+ signal: Schema.optional(Schema.String),
135
+ terminal: Schema.optional(Schema.String),
136
+ seal: Schema.optional(Schema.String)
137
+ });
138
+ var HirProvenance = Schema.Struct({
139
+ source: Schema.optional(Schema.String),
140
+ datasheet: Schema.optional(Schema.String),
141
+ verification: Schema.Literal("unverified", "inspired-by", "verified"),
142
+ lastVerified: Schema.optional(Schema.String)
111
143
  });
112
144
  var HirConnector = Schema.Struct({
113
145
  ref: Schema.String,
@@ -120,6 +152,11 @@ var HirConnector = Schema.Struct({
120
152
  wireGaugeRange: Schema.optional(
121
153
  Schema.Struct({ min: Schema.String, max: Schema.String })
122
154
  ),
155
+ sealed: Schema.optional(Schema.Boolean),
156
+ compatibleTerminals: Schema.optional(Schema.Array(Schema.String)),
157
+ compatibleSeals: Schema.optional(Schema.Array(Schema.String)),
158
+ crimpTool: Schema.optional(Schema.String),
159
+ provenance: Schema.optional(HirProvenance),
123
160
  pins: Schema.Array(HirPin)
124
161
  });
125
162
  var HirWire = Schema.Struct({
@@ -219,20 +256,9 @@ var Hir = Schema.Struct({
219
256
  layoutHints: Schema.Array(Schema.Unknown),
220
257
  exports: Schema.Record({ key: Schema.String, value: Schema.Unknown })
221
258
  });
222
- var isPinEndpoint = (e) => "connector" in e;
223
- var endpointLabel = (e) => isPinEndpoint(e) ? `${e.connector}.${e.pin}` : e.splice;
224
259
  var decodeHir = Schema.decodeUnknownSync(Hir);
225
260
  var decodeHirEffect = Schema.decodeUnknown(Hir);
226
261
  var encodeHir = Schema.encodeSync(Hir);
227
- var refs = {
228
- connector: (ref) => `connector:${ref}`,
229
- pin: (connector2, pin) => `connector:${connector2}.pin:${pin}`,
230
- wire: (id) => `wire:${id}`,
231
- branch: (id) => `branch:${id}`,
232
- splice: (id) => `splice:${id}`,
233
- label: (id) => `label:${id}`,
234
- bom: (mpn) => `bom:${mpn}`
235
- };
236
262
 
237
263
  // src/compile.ts
238
264
  var comparePins = (a, b) => {
@@ -278,7 +304,19 @@ var compileDesign = (design) => {
278
304
  gender: c.part.gender,
279
305
  pinCount: c.part.pinCount,
280
306
  wireGaugeRange: c.part.wireGaugeRange ? { min: c.part.wireGaugeRange.min, max: c.part.wireGaugeRange.max } : void 0,
281
- pins: Object.entries(c.pins).sort(([a], [b]) => comparePins(a, b)).map(([pin, signal]) => compact({ pin, signal }))
307
+ sealed: c.part.sealed,
308
+ compatibleTerminals: c.part.compatibleTerminals ? [...c.part.compatibleTerminals] : void 0,
309
+ compatibleSeals: c.part.compatibleSeals ? [...c.part.compatibleSeals] : void 0,
310
+ crimpTool: c.part.crimpTool,
311
+ provenance: c.part.provenance ? { ...c.part.provenance } : void 0,
312
+ pins: Object.entries(c.pins).sort(([a], [b]) => comparePins(a, b)).map(
313
+ ([pin, signal]) => compact({
314
+ pin,
315
+ signal,
316
+ terminal: c.terminals[pin],
317
+ seal: c.seals[pin]
318
+ })
319
+ )
282
320
  })
283
321
  );
284
322
  const pinExists = (connectorRef, pin) => {
@@ -524,25 +562,39 @@ var compileDesign = (design) => {
524
562
  }
525
563
  labels.sort((a, b) => compareStrings(a.id, b.id));
526
564
  const bomByMpn = /* @__PURE__ */ new Map();
527
- for (const c of [...connectorByRef.values()].sort((a, b) => compareStrings(a.ref, b.ref))) {
528
- const existing = bomByMpn.get(c.part.mpn);
565
+ const bomAdd = (mpn, category, usedBy, extra = {}) => {
566
+ const existing = bomByMpn.get(mpn);
529
567
  if (existing) {
530
- existing.usedBy.push(refs.connector(c.ref));
568
+ existing.qty += 1;
569
+ existing.usedBy.push(usedBy);
531
570
  } else {
532
- bomByMpn.set(c.part.mpn, {
533
- item: compact({
534
- mpn: c.part.mpn,
535
- manufacturer: c.part.manufacturer,
536
- description: c.part.description,
537
- category: "connector",
538
- quantity: 0,
539
- unitOfMeasure: "ea"
540
- }),
541
- usedBy: [refs.connector(c.ref)]
571
+ bomByMpn.set(mpn, {
572
+ item: compact({ mpn, category, unitOfMeasure: "ea", ...extra }),
573
+ usedBy: [usedBy],
574
+ qty: 1
542
575
  });
543
576
  }
577
+ };
578
+ for (const c of [...connectorByRef.values()].sort((a, b) => compareStrings(a.ref, b.ref))) {
579
+ bomAdd(c.part.mpn, "connector", refs.connector(c.ref), {
580
+ manufacturer: c.part.manufacturer,
581
+ description: c.part.description
582
+ });
583
+ for (const [pin, terminal] of Object.entries(c.terminals).sort(
584
+ ([a], [b]) => comparePins(a, b)
585
+ )) {
586
+ bomAdd(terminal, "terminal", refs.pin(c.ref, pin));
587
+ }
588
+ for (const [pin, seal] of Object.entries(c.seals).sort(
589
+ ([a], [b]) => comparePins(a, b)
590
+ )) {
591
+ bomAdd(seal, "seal", refs.pin(c.ref, pin));
592
+ }
544
593
  }
545
- const bom = [...bomByMpn.values()].map(({ item, usedBy }) => ({ ...item, quantity: usedBy.length, usedBy })).sort((a, b) => compareStrings(a.mpn, b.mpn));
594
+ for (const s of splices) {
595
+ if (s.part !== void 0) bomAdd(s.part, "splice", refs.splice(s.id));
596
+ }
597
+ const bom = [...bomByMpn.values()].map(({ item, usedBy, qty }) => ({ ...item, quantity: qty, usedBy })).sort((a, b) => compareStrings(a.mpn, b.mpn));
546
598
  diagnostics.sort(
547
599
  (a, b) => compareStrings(a.target ?? "", b.target ?? "") || compareStrings(a.code, b.code) || compareStrings(a.message, b.message)
548
600
  );
@@ -603,6 +655,10 @@ var variant = (base, opts) => ({
603
655
  cables: apply(base.cables, opts.cables)
604
656
  });
605
657
 
658
+ // src/plugin.ts
659
+ var definePlugin = (plugin) => plugin;
660
+ var isNervePlugin = (value) => typeof value === "object" && value !== null && typeof value.name === "string" && Array.isArray(value.hirSchemaVersions);
661
+
606
662
  // src/diff.ts
607
663
  var show = (v) => v === void 0 ? "(none)" : typeof v === "string" ? v : JSON.stringify(v);
608
664
  var fieldChanges = (a, b, fields) => {
@@ -781,6 +837,7 @@ export {
781
837
  decodeHir,
782
838
  decodeHirEffect,
783
839
  defineConfig,
840
+ definePlugin,
784
841
  diffHir,
785
842
  encodeHir,
786
843
  endpointLabel,
@@ -788,6 +845,7 @@ export {
788
845
  harness,
789
846
  hasErrors,
790
847
  isEmptyDiff,
848
+ isNervePlugin,
791
849
  isPinEndpoint,
792
850
  label,
793
851
  refs,
package/package.json CHANGED
@@ -1,38 +1,42 @@
1
1
  {
2
2
  "name": "@grayhaven/nerve",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
+ "sideEffects": false,
5
6
  "description": "Grayhaven Nerve core: domain model, DSL builders, HIR types and schema, compiler interface, validation primitives.",
6
7
  "exports": {
7
- ".": {
8
- "types": "./dist/index.d.ts",
9
- "import": "./dist/index.js"
10
- }
8
+ ".": "./src/index.ts"
11
9
  },
12
10
  "dependencies": {
13
11
  "effect": "^3.16.0"
14
12
  },
15
13
  "devDependencies": {
14
+ "@grayhaven/nerve-rules": "0.2.0",
16
15
  "typescript": "^5.8.3",
17
- "vitest": "^3.2.4",
18
- "@grayhaven/nerve-rules": "0.1.0"
16
+ "vitest": "^3.2.4"
19
17
  },
20
18
  "license": "Apache-2.0",
19
+ "scripts": {
20
+ "build": "tsup src/index.ts --format esm --dts --clean"
21
+ },
21
22
  "files": [
22
23
  "dist"
23
24
  ],
24
25
  "publishConfig": {
25
- "access": "public"
26
+ "access": "public",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js"
31
+ }
32
+ },
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts"
26
35
  },
27
36
  "repository": {
28
37
  "type": "git",
29
38
  "url": "git+https://github.com/tylergibbs1/nerve.git",
30
39
  "directory": "packages/nerve"
31
40
  },
32
- "homepage": "https://github.com/tylergibbs1/nerve#readme",
33
- "scripts": {
34
- "build": "tsup src/index.ts --format esm --dts --clean"
35
- },
36
- "main": "./dist/index.js",
37
- "types": "./dist/index.d.ts"
38
- }
41
+ "homepage": "https://github.com/tylergibbs1/nerve#readme"
42
+ }
package/LICENSE DELETED
@@ -1,202 +0,0 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright [yyyy] [name of copyright owner]
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.