@grayhaven/nerve-rules 0.2.1 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -56,4 +56,37 @@ declare const isShieldSignal: (signal: string) => boolean;
56
56
  */
57
57
  declare const differentialPartner: (signal: string) => string | undefined;
58
58
 
59
- export { AMPACITY_BY_AWG, branchMissingLabel, builtinRules, differentialPairNotTwisted, differentialPartner, gaugeCurrentMismatch, gaugeOutsideConnectorRange, isGroundSignal, isPowerSignal, isShieldSignal, missingGroundReturn, missingRevision, missingSeal, missingWireColor, missingWireGauge, missingWireLength, parseAwg, requireApprovedParts, requiredAwgForCurrent, sealIncompatible, shieldDrainUnconnected, spliceMissingNotes, terminalIncompatible, twistGroupTooSmall, unconnectedAssignedPin, wireSignalMismatch };
59
+ /**
60
+ * Numeric view of rule codes, for computation: sorting, bitsets, category
61
+ * math, compact storage. Derived — not a registry — so it can never drift
62
+ * from the codes and never needs maintenance when rules are added.
63
+ *
64
+ * Scheme: HK-<CATEGORY>-<NNN> → band(category) + NNN.
65
+ * HK-DOC-001 → 1001
66
+ * HK-MFG-004 → 2004
67
+ * HK-WIRE-004 → 3004
68
+ * HK-ELEC-003 → 4003
69
+ * HK-CONN-011 → 5011
70
+ *
71
+ * The string code remains the public contract (CI gates, waivers, docs);
72
+ * numbers are an internal computational view. Custom rule codes (ORG-*,
73
+ * SHOP-*) deliberately return undefined — callers fall back to strings.
74
+ */
75
+ declare const RULE_CATEGORY_BANDS: {
76
+ readonly DOC: 1000;
77
+ readonly MFG: 2000;
78
+ readonly WIRE: 3000;
79
+ readonly ELEC: 4000;
80
+ readonly CONN: 5000;
81
+ };
82
+ type RuleCategory = keyof typeof RULE_CATEGORY_BANDS;
83
+ /** `"HK-CONN-011"` → `5011`. Undefined for non-HK codes. */
84
+ declare const ruleCodeNumber: (code: string) => number | undefined;
85
+ /** `5011` → `"HK-CONN-011"`. Undefined for numbers outside the bands. */
86
+ declare const ruleCodeFromNumber: (n: number) => string | undefined;
87
+ /** Category of a code (or its number): `"HK-MFG-004"` / `2004` → `"MFG"`. */
88
+ declare const ruleCategory: (code: string | number) => RuleCategory | undefined;
89
+ /** Compact set of fired rules for telemetry / waiver storage. */
90
+ declare const codesToNumbers: (codes: ReadonlyArray<string>) => ReadonlyArray<number>;
91
+
92
+ export { AMPACITY_BY_AWG, RULE_CATEGORY_BANDS, type RuleCategory, branchMissingLabel, builtinRules, codesToNumbers, differentialPairNotTwisted, differentialPartner, gaugeCurrentMismatch, gaugeOutsideConnectorRange, isGroundSignal, isPowerSignal, isShieldSignal, missingGroundReturn, missingRevision, missingSeal, missingWireColor, missingWireGauge, missingWireLength, parseAwg, requireApprovedParts, requiredAwgForCurrent, ruleCategory, ruleCodeFromNumber, ruleCodeNumber, sealIncompatible, shieldDrainUnconnected, spliceMissingNotes, terminalIncompatible, twistGroupTooSmall, unconnectedAssignedPin, wireSignalMismatch };
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var requiredAwgForCurrent = (current) => {
32
32
  return candidates.length > 0 ? Math.max(...candidates) : void 0;
33
33
  };
34
34
  var POWER_SIGNAL = /^(VBAT|VCC|VDD|VIN|VSYS|PWR|\+?\d+(\.\d+)?V)/i;
35
- var GROUND_SIGNAL = /^(GND|GROUND|0V|RTN|RETURN|VSS)/i;
35
+ var GROUND_SIGNAL = /(^|_)([ADPSC]?GND|GROUND|0V|RTN|RETURN|VSS)(_|$)/i;
36
36
  var SHIELD_SIGNAL = /(SHIELD|DRAIN|SHLD)/i;
37
37
  var isPowerSignal = (signal) => POWER_SIGNAL.test(signal);
38
38
  var isGroundSignal = (signal) => GROUND_SIGNAL.test(signal);
@@ -40,8 +40,9 @@ var isShieldSignal = (signal) => SHIELD_SIGNAL.test(signal);
40
40
  var differentialPartner = (signal) => {
41
41
  const s = signal.toUpperCase();
42
42
  const table = [
43
- [/^(.*)CAN_?H$/, (m) => m.replace(/CAN_?H$/, (h) => h.replace("H", "L"))],
44
- [/^(.*)CAN_?L$/, (m) => m.replace(/CAN_?L$/, (l) => l.replace("L", "H"))],
43
+ // Bus index allowed: CAN_H, CANH, CAN1_H, MOTOR_CAN2_H all pair.
44
+ [/^(.*)CAN\d*_?H$/, (m) => m.slice(0, -1) + "L"],
45
+ [/^(.*)CAN\d*_?L$/, (m) => m.slice(0, -1) + "H"],
45
46
  [/^(.*)RS485_?A$/, (m) => m.slice(0, -1) + "B"],
46
47
  [/^(.*)RS485_?B$/, (m) => m.slice(0, -1) + "A"],
47
48
  [/^(.*)_P$/, (m) => m.slice(0, -2) + "_N"],
@@ -419,10 +420,45 @@ var builtinRules = [
419
420
  missingSeal,
420
421
  sealIncompatible
421
422
  ];
423
+
424
+ // src/code-numbers.ts
425
+ var RULE_CATEGORY_BANDS = {
426
+ DOC: 1e3,
427
+ MFG: 2e3,
428
+ WIRE: 3e3,
429
+ ELEC: 4e3,
430
+ CONN: 5e3
431
+ };
432
+ var CODE_PATTERN = /^HK-(DOC|MFG|WIRE|ELEC|CONN)-(\d{3})$/;
433
+ var ruleCodeNumber = (code) => {
434
+ const m = CODE_PATTERN.exec(code);
435
+ if (m === null) return void 0;
436
+ return RULE_CATEGORY_BANDS[m[1]] + Number(m[2]);
437
+ };
438
+ var ruleCodeFromNumber = (n) => {
439
+ if (!Number.isInteger(n)) return void 0;
440
+ const band = Math.floor(n / 1e3) * 1e3;
441
+ const suffix = n - band;
442
+ if (suffix < 1 || suffix > 999) return void 0;
443
+ const category = Object.entries(RULE_CATEGORY_BANDS).find(([, b]) => b === band)?.[0];
444
+ if (category === void 0) return void 0;
445
+ return `HK-${category}-${String(suffix).padStart(3, "0")}`;
446
+ };
447
+ var ruleCategory = (code) => {
448
+ const n = typeof code === "number" ? code : ruleCodeNumber(code);
449
+ if (n === void 0) return void 0;
450
+ const band = Math.floor(n / 1e3) * 1e3;
451
+ return Object.entries(RULE_CATEGORY_BANDS).find(([, b]) => b === band)?.[0];
452
+ };
453
+ var codesToNumbers = (codes) => [...new Set(codes.map(ruleCodeNumber).filter((n) => n !== void 0))].sort(
454
+ (a, b) => a - b
455
+ );
422
456
  export {
423
457
  AMPACITY_BY_AWG,
458
+ RULE_CATEGORY_BANDS,
424
459
  branchMissingLabel,
425
460
  builtinRules,
461
+ codesToNumbers,
426
462
  differentialPairNotTwisted,
427
463
  differentialPartner,
428
464
  gaugeCurrentMismatch,
@@ -439,6 +475,9 @@ export {
439
475
  parseAwg,
440
476
  requireApprovedParts,
441
477
  requiredAwgForCurrent,
478
+ ruleCategory,
479
+ ruleCodeFromNumber,
480
+ ruleCodeNumber,
442
481
  sealIncompatible,
443
482
  shieldDrainUnconnected,
444
483
  spliceMissingNotes,
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@grayhaven/nerve-rules",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "Built-in validation and linting rules for Grayhaven Nerve.",
6
6
  "exports": {
7
7
  ".": "./src/index.ts"
8
8
  },
9
9
  "dependencies": {
10
- "@grayhaven/nerve": "0.2.0"
10
+ "@grayhaven/nerve": "0.2.1"
11
11
  },
12
12
  "devDependencies": {
13
- "@grayhaven/nerve-connectors": "0.2.0",
13
+ "@grayhaven/nerve-connectors": "0.2.1",
14
14
  "typescript": "^5.8.3",
15
15
  "vitest": "^3.2.4"
16
16
  },