@springfield/ham-radio-utils 4.1.1 → 4.2.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.
@@ -0,0 +1,151 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Radio Memory-Map DSL Schema",
4
+ "description": "Schema for defining radio EEPROM settings layout as JSON (Chirp MEM_FORMAT as data)",
5
+ "type": "object",
6
+ "required": ["structs"],
7
+ "properties": {
8
+ "version": {
9
+ "type": "string",
10
+ "description": "Optional map version"
11
+ },
12
+ "description": {
13
+ "type": "string"
14
+ },
15
+ "structs": {
16
+ "type": "array",
17
+ "minItems": 1,
18
+ "items": {
19
+ "$ref": "#/definitions/struct"
20
+ }
21
+ }
22
+ },
23
+ "definitions": {
24
+ "seek": {
25
+ "oneOf": [
26
+ { "type": "integer", "minimum": 0 },
27
+ { "type": "string", "pattern": "^(0[xX][0-9a-fA-F]+|[0-9]+)$" }
28
+ ]
29
+ },
30
+ "ui": {
31
+ "type": "object",
32
+ "required": ["group", "label", "widget"],
33
+ "properties": {
34
+ "group": { "type": "string" },
35
+ "label": { "type": "string" },
36
+ "widget": {
37
+ "type": "string",
38
+ "enum": ["integer", "select", "switch", "text", "number"]
39
+ },
40
+ "description": { "type": "string" },
41
+ "writable": { "type": "boolean" }
42
+ },
43
+ "additionalProperties": false
44
+ },
45
+ "value": {
46
+ "oneOf": [
47
+ {
48
+ "type": "object",
49
+ "required": ["kind"],
50
+ "properties": {
51
+ "kind": { "const": "integer" },
52
+ "min": { "type": "number" },
53
+ "max": { "type": "number" }
54
+ },
55
+ "additionalProperties": false
56
+ },
57
+ {
58
+ "type": "object",
59
+ "required": ["kind"],
60
+ "properties": {
61
+ "kind": { "const": "boolean" }
62
+ },
63
+ "additionalProperties": false
64
+ },
65
+ {
66
+ "type": "object",
67
+ "required": ["kind", "values"],
68
+ "properties": {
69
+ "kind": { "const": "enum" },
70
+ "values": {
71
+ "type": "array",
72
+ "items": { "type": "string" },
73
+ "minItems": 1
74
+ }
75
+ },
76
+ "additionalProperties": false
77
+ },
78
+ {
79
+ "type": "object",
80
+ "required": ["kind", "length"],
81
+ "properties": {
82
+ "kind": { "const": "ascii" },
83
+ "length": { "type": "integer", "minimum": 1 }
84
+ },
85
+ "additionalProperties": false
86
+ },
87
+ {
88
+ "type": "object",
89
+ "required": ["kind", "length"],
90
+ "properties": {
91
+ "kind": { "const": "digits" },
92
+ "length": { "type": "integer", "minimum": 1 },
93
+ "scale": { "type": "number" }
94
+ },
95
+ "additionalProperties": false
96
+ },
97
+ {
98
+ "type": "object",
99
+ "required": ["kind", "length"],
100
+ "properties": {
101
+ "kind": { "const": "dtmf" },
102
+ "length": { "type": "integer", "minimum": 1 },
103
+ "charset": { "type": "string" }
104
+ },
105
+ "additionalProperties": false
106
+ },
107
+ {
108
+ "type": "object",
109
+ "required": ["kind", "length"],
110
+ "properties": {
111
+ "kind": { "const": "bbcd" },
112
+ "length": { "type": "integer", "minimum": 1 }
113
+ },
114
+ "additionalProperties": false
115
+ }
116
+ ]
117
+ },
118
+ "field": {
119
+ "type": "object",
120
+ "required": ["id", "type"],
121
+ "properties": {
122
+ "id": { "type": "string", "minLength": 1 },
123
+ "type": {
124
+ "type": "string",
125
+ "enum": ["u8", "u16", "bits", "char"]
126
+ },
127
+ "width": { "type": "integer", "minimum": 1, "maximum": 8 },
128
+ "reserved": { "type": "boolean" },
129
+ "value": { "$ref": "#/definitions/value" },
130
+ "ui": { "$ref": "#/definitions/ui" }
131
+ },
132
+ "additionalProperties": false
133
+ },
134
+ "struct": {
135
+ "type": "object",
136
+ "required": ["id", "seek", "fields"],
137
+ "properties": {
138
+ "id": { "type": "string", "minLength": 1 },
139
+ "seek": { "$ref": "#/definitions/seek" },
140
+ "fields": {
141
+ "type": "array",
142
+ "minItems": 1,
143
+ "items": { "$ref": "#/definitions/field" }
144
+ },
145
+ "count": { "type": "integer", "minimum": 1 },
146
+ "stride": { "type": "integer", "minimum": 1 }
147
+ },
148
+ "additionalProperties": false
149
+ }
150
+ }
151
+ }
@@ -4,11 +4,18 @@ interface LicenseClass {
4
4
  name: string;
5
5
  }
6
6
  export declare class BandPlan {
7
- private bands;
8
- private licenseClasses;
7
+ private readonly bands;
8
+ private readonly licenseClasses;
9
+ private readonly frsLicenseClassId;
9
10
  constructor();
10
11
  /**
11
- * Finds the spectrum band that contains the given frequency
12
+ * Finds the spectrum band that contains the given frequency.
13
+ *
14
+ * Channelized allocations (FRS, GMRS, weather) interleave in the same
15
+ * MHz range. An exact channel match is preferred over a surrounding
16
+ * band envelope so FRS interstitial frequencies are not treated as GMRS
17
+ * repeater inputs.
18
+ *
12
19
  * @param frequency The frequency in Hz to find the band for
13
20
  * @returns The spectrum band containing the frequency, or undefined if no band contains it
14
21
  */
@@ -23,7 +30,9 @@ export declare class BandPlan {
23
30
  * Returns whether the given license class may transmit on the frequency.
24
31
  *
25
32
  * Looks up the band that contains the frequency and checks that band's
26
- * privileges list. Frequencies outside every known band return false.
33
+ * privileges list. FRS is a license-free service, so any band that
34
+ * includes the FRS privilege is allowed for every operator. Frequencies
35
+ * outside every known band return false.
27
36
  *
28
37
  * @param frequencyHz - Frequency in Hz
29
38
  * @param licenseClassId - Springfield license-class ID
@@ -1 +1 @@
1
- {"version":3,"file":"band-plan.d.ts","sourceRoot":"","sources":["../../src/utils/band-plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI/D,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,KAAK,CAAiB;IAC9B,OAAO,CAAC,cAAc,CAA4B;IAElD,cAGC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAE/D;IAED;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEtD;IAED;;;;;;;;;OASG;IACH,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAQjE;CACF"}
1
+ {"version":3,"file":"band-plan.d.ts","sourceRoot":"","sources":["../../src/utils/band-plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI/D,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiB;IACvC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4B;IAC3D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAqB;IAEvD,cAIC;IAED;;;;;;;;;;OAUG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAS/D;IAED;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEtD;IAED;;;;;;;;;;;OAWG;IACH,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAcjE;CACF"}
@@ -3,17 +3,30 @@ import licenseClassesData from '../db/license-classes.json' with { type: 'json'
3
3
  export class BandPlan {
4
4
  bands;
5
5
  licenseClasses;
6
+ frsLicenseClassId;
6
7
  constructor() {
7
8
  this.bands = bandsData;
8
9
  this.licenseClasses = new Map(licenseClassesData.map((licenseClass) => [licenseClass.id, licenseClass]));
10
+ this.frsLicenseClassId = [...this.licenseClasses.values()].find((licenseClass) => licenseClass.name === 'FRS')?.id;
9
11
  }
10
12
  /**
11
- * Finds the spectrum band that contains the given frequency
13
+ * Finds the spectrum band that contains the given frequency.
14
+ *
15
+ * Channelized allocations (FRS, GMRS, weather) interleave in the same
16
+ * MHz range. An exact channel match is preferred over a surrounding
17
+ * band envelope so FRS interstitial frequencies are not treated as GMRS
18
+ * repeater inputs.
19
+ *
12
20
  * @param frequency The frequency in Hz to find the band for
13
21
  * @returns The spectrum band containing the frequency, or undefined if no band contains it
14
22
  */
15
23
  findBandByFrequency(frequency) {
16
- return this.bands.find((band) => frequency >= band.lowerFrequency && frequency <= band.upperFrequency);
24
+ const frequencyHz = Math.round(frequency);
25
+ const channelMatch = this.bands.find((band) => band.channels?.some((channel) => channel.frequency === frequencyHz));
26
+ if (channelMatch) {
27
+ return channelMatch;
28
+ }
29
+ return this.bands.find((band) => frequencyHz >= band.lowerFrequency && frequencyHz <= band.upperFrequency);
17
30
  }
18
31
  /**
19
32
  * Finds a license class by its ID
@@ -27,7 +40,9 @@ export class BandPlan {
27
40
  * Returns whether the given license class may transmit on the frequency.
28
41
  *
29
42
  * Looks up the band that contains the frequency and checks that band's
30
- * privileges list. Frequencies outside every known band return false.
43
+ * privileges list. FRS is a license-free service, so any band that
44
+ * includes the FRS privilege is allowed for every operator. Frequencies
45
+ * outside every known band return false.
31
46
  *
32
47
  * @param frequencyHz - Frequency in Hz
33
48
  * @param licenseClassId - Springfield license-class ID
@@ -38,7 +53,11 @@ export class BandPlan {
38
53
  if (!band) {
39
54
  return false;
40
55
  }
41
- return band.privileges.includes(licenseClassId);
56
+ const privileges = band.privileges;
57
+ if (this.frsLicenseClassId && privileges.includes(this.frsLicenseClassId)) {
58
+ return true;
59
+ }
60
+ return privileges.includes(licenseClassId);
42
61
  }
43
62
  }
44
63
  //# sourceMappingURL=band-plan.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"band-plan.js","sourceRoot":"","sources":["../../src/utils/band-plan.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,kBAAkB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC/D,OAAO,kBAAkB,MAAM,4BAA4B,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAOlF,MAAM,OAAO,QAAQ;IACX,KAAK,CAAiB;IACtB,cAAc,CAA4B;IAElD;QACE,IAAI,CAAC,KAAK,GAAG,SAA2B,CAAC;QACzC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,CAAE,kBAAqC,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC/H,CAAC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,SAAiB;QACnC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,IAAI,IAAI,CAAC,cAAc,IAAI,SAAS,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC;IACzG,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,EAAU;QAC1B,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;;;;OASG;IACH,YAAY,CAAC,WAAmB,EAAE,cAAsB;QACtD,MAAM,IAAI,GAAG,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;QAEnD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAQ,IAAI,CAAC,UAAuB,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["import type { SpectrumBand } from '@springfield/ham-radio-api';\nimport bandsData from '../db/bands.json' with { type: 'json' };\nimport licenseClassesData from '../db/license-classes.json' with { type: 'json' };\n\ninterface LicenseClass {\n id: string;\n name: string;\n}\n\nexport class BandPlan {\n private bands: SpectrumBand[];\n private licenseClasses: Map<string, LicenseClass>;\n\n constructor() {\n this.bands = bandsData as SpectrumBand[];\n this.licenseClasses = new Map((licenseClassesData as LicenseClass[]).map((licenseClass) => [licenseClass.id, licenseClass]));\n }\n\n /**\n * Finds the spectrum band that contains the given frequency\n * @param frequency The frequency in Hz to find the band for\n * @returns The spectrum band containing the frequency, or undefined if no band contains it\n */\n findBandByFrequency(frequency: number): SpectrumBand | undefined {\n return this.bands.find((band) => frequency >= band.lowerFrequency && frequency <= band.upperFrequency);\n }\n\n /**\n * Finds a license class by its ID\n * @param id The ID of the license class to find\n * @returns The license class with the given ID, or undefined if not found\n */\n findPrivilegeById(id: string): LicenseClass | undefined {\n return this.licenseClasses.get(id);\n }\n\n /**\n * Returns whether the given license class may transmit on the frequency.\n *\n * Looks up the band that contains the frequency and checks that band's\n * privileges list. Frequencies outside every known band return false.\n *\n * @param frequencyHz - Frequency in Hz\n * @param licenseClassId - Springfield license-class ID\n * @returns true when the class has privilege on that frequency\n */\n hasPrivilege(frequencyHz: number, licenseClassId: string): boolean {\n const band = this.findBandByFrequency(frequencyHz);\n\n if (!band) {\n return false;\n }\n\n return (band.privileges as string[]).includes(licenseClassId);\n }\n}\n"]}
1
+ {"version":3,"file":"band-plan.js","sourceRoot":"","sources":["../../src/utils/band-plan.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,kBAAkB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC/D,OAAO,kBAAkB,MAAM,4BAA4B,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAOlF,MAAM,OAAO,QAAQ;IACF,KAAK,CAAiB;IACtB,cAAc,CAA4B;IAC1C,iBAAiB,CAAqB;IAEvD;QACE,IAAI,CAAC,KAAK,GAAG,SAA2B,CAAC;QACzC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,CAAE,kBAAqC,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;QAC7H,IAAI,CAAC,iBAAiB,GAAG,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,KAAK,KAAK,CAAC,EAAE,EAAE,CAAC;IACrH,CAAC;IAED;;;;;;;;;;OAUG;IACH,mBAAmB,CAAC,SAAiB;QACnC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC;QAEpH,IAAI,YAAY,EAAE,CAAC;YACjB,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,IAAI,IAAI,CAAC,cAAc,IAAI,WAAW,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC;IAC7G,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,EAAU;QAC1B,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,YAAY,CAAC,WAAmB,EAAE,cAAsB;QACtD,MAAM,IAAI,GAAG,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;QAEnD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,UAAsB,CAAC;QAE/C,IAAI,IAAI,CAAC,iBAAiB,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC1E,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,UAAU,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC7C,CAAC;CACF","sourcesContent":["import type { SpectrumBand } from '@springfield/ham-radio-api';\nimport bandsData from '../db/bands.json' with { type: 'json' };\nimport licenseClassesData from '../db/license-classes.json' with { type: 'json' };\n\ninterface LicenseClass {\n id: string;\n name: string;\n}\n\nexport class BandPlan {\n private readonly bands: SpectrumBand[];\n private readonly licenseClasses: Map<string, LicenseClass>;\n private readonly frsLicenseClassId: string | undefined;\n\n constructor() {\n this.bands = bandsData as SpectrumBand[];\n this.licenseClasses = new Map((licenseClassesData as LicenseClass[]).map((licenseClass) => [licenseClass.id, licenseClass]));\n this.frsLicenseClassId = [...this.licenseClasses.values()].find((licenseClass) => licenseClass.name === 'FRS')?.id;\n }\n\n /**\n * Finds the spectrum band that contains the given frequency.\n *\n * Channelized allocations (FRS, GMRS, weather) interleave in the same\n * MHz range. An exact channel match is preferred over a surrounding\n * band envelope so FRS interstitial frequencies are not treated as GMRS\n * repeater inputs.\n *\n * @param frequency The frequency in Hz to find the band for\n * @returns The spectrum band containing the frequency, or undefined if no band contains it\n */\n findBandByFrequency(frequency: number): SpectrumBand | undefined {\n const frequencyHz = Math.round(frequency);\n const channelMatch = this.bands.find((band) => band.channels?.some((channel) => channel.frequency === frequencyHz));\n\n if (channelMatch) {\n return channelMatch;\n }\n\n return this.bands.find((band) => frequencyHz >= band.lowerFrequency && frequencyHz <= band.upperFrequency);\n }\n\n /**\n * Finds a license class by its ID\n * @param id The ID of the license class to find\n * @returns The license class with the given ID, or undefined if not found\n */\n findPrivilegeById(id: string): LicenseClass | undefined {\n return this.licenseClasses.get(id);\n }\n\n /**\n * Returns whether the given license class may transmit on the frequency.\n *\n * Looks up the band that contains the frequency and checks that band's\n * privileges list. FRS is a license-free service, so any band that\n * includes the FRS privilege is allowed for every operator. Frequencies\n * outside every known band return false.\n *\n * @param frequencyHz - Frequency in Hz\n * @param licenseClassId - Springfield license-class ID\n * @returns true when the class has privilege on that frequency\n */\n hasPrivilege(frequencyHz: number, licenseClassId: string): boolean {\n const band = this.findBandByFrequency(frequencyHz);\n\n if (!band) {\n return false;\n }\n\n const privileges = band.privileges as string[];\n\n if (this.frsLicenseClassId && privileges.includes(this.frsLicenseClassId)) {\n return true;\n }\n\n return privileges.includes(licenseClassId);\n }\n}\n"]}
@@ -6,5 +6,7 @@ export declare class SchemaValidator {
6
6
  private ajv;
7
7
  constructor();
8
8
  validateRadioProtocol(config: unknown): ValidationResult;
9
+ validateMemoryMap(memoryMap: unknown): ValidationResult;
10
+ private validateAgainst;
9
11
  }
10
12
  //# sourceMappingURL=schema-validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema-validator.d.ts","sourceRoot":"","sources":["../../src/utils/schema-validator.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAOD,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAM;IAEjB,cAMC;IAED,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAoBvD;CACF"}
1
+ {"version":3,"file":"schema-validator.d.ts","sourceRoot":"","sources":["../../src/utils/schema-validator.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAOD,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAM;IAEjB,cAMC;IAED,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAEvD;IAED,iBAAiB,CAAC,SAAS,EAAE,OAAO,GAAG,gBAAgB,CAEtD;IAED,OAAO,CAAC,eAAe;CAqBxB"}
@@ -1,6 +1,7 @@
1
1
  import { Ajv } from 'ajv';
2
2
  import addFormats from 'ajv-formats';
3
3
  import radioProtocolSchema from '../schemas/radio-protocol-schema.json' with { type: 'json' };
4
+ import radioMemoryMapSchema from '../schemas/radio-memory-map-schema.json' with { type: 'json' };
4
5
  export class SchemaValidator {
5
6
  ajv;
6
7
  constructor() {
@@ -11,8 +12,14 @@ export class SchemaValidator {
11
12
  addFormats(this.ajv);
12
13
  }
13
14
  validateRadioProtocol(config) {
14
- const validate = this.ajv.compile(radioProtocolSchema);
15
- const valid = validate(config);
15
+ return this.validateAgainst(radioProtocolSchema, config);
16
+ }
17
+ validateMemoryMap(memoryMap) {
18
+ return this.validateAgainst(radioMemoryMapSchema, memoryMap);
19
+ }
20
+ validateAgainst(schema, data) {
21
+ const validate = this.ajv.compile(schema);
22
+ const valid = validate(data);
16
23
  if (valid) {
17
24
  return { valid: true };
18
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema-validator.js","sourceRoot":"","sources":["../../src/utils/schema-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,mBAAmB,MAAM,uCAAuC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAY9F,MAAM,OAAO,eAAe;IAClB,GAAG,CAAM;IAEjB;QACE,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC;YACjB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QACF,UAA2C,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzD,CAAC;IAED,qBAAqB,CAAC,MAAe;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QACvD,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;QAE/B,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzB,CAAC;QAED,IAAI,MAAM,GAAa,EAAE,CAAC;QAC1B,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClD,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAe,EAAE,EAAE;gBAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,IAAI,MAAM,CAAC;gBAC1C,OAAO,GAAG,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;YACrC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,MAAM;YACN,KAAK,EAAE,KAAK;SACb,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Ajv } from 'ajv';\nimport addFormats from 'ajv-formats';\nimport radioProtocolSchema from '../schemas/radio-protocol-schema.json' with { type: 'json' };\n\nexport interface ValidationResult {\n valid: boolean;\n errors?: string[];\n}\n\ninterface AjvError {\n instancePath?: string;\n message?: string;\n}\n\nexport class SchemaValidator {\n private ajv: Ajv;\n\n constructor() {\n this.ajv = new Ajv({\n allErrors: true,\n verbose: true,\n });\n (addFormats as unknown as (ajv: Ajv) => Ajv)(this.ajv);\n }\n\n validateRadioProtocol(config: unknown): ValidationResult {\n const validate = this.ajv.compile(radioProtocolSchema);\n const valid = validate(config);\n\n if (valid) {\n return { valid: true };\n }\n\n let errors: string[] = [];\n if (validate.errors && validate.errors.length > 0) {\n errors = validate.errors.map((error: AjvError) => {\n const path = error.instancePath || 'root';\n return `${path}: ${error.message}`;\n });\n }\n\n return {\n errors,\n valid: false,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"schema-validator.js","sourceRoot":"","sources":["../../src/utils/schema-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,mBAAmB,MAAM,uCAAuC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC9F,OAAO,oBAAoB,MAAM,yCAAyC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAYjG,MAAM,OAAO,eAAe;IAClB,GAAG,CAAM;IAEjB;QACE,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC;YACjB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QACF,UAA2C,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzD,CAAC;IAED,qBAAqB,CAAC,MAAe;QACnC,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;IAED,iBAAiB,CAAC,SAAkB;QAClC,OAAO,IAAI,CAAC,eAAe,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IAC/D,CAAC;IAEO,eAAe,CAAC,MAAc,EAAE,IAAa;QACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAE7B,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzB,CAAC;QAED,IAAI,MAAM,GAAa,EAAE,CAAC;QAC1B,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClD,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAe,EAAE,EAAE;gBAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,IAAI,MAAM,CAAC;gBAC1C,OAAO,GAAG,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;YACrC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,MAAM;YACN,KAAK,EAAE,KAAK;SACb,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Ajv } from 'ajv';\nimport addFormats from 'ajv-formats';\nimport radioProtocolSchema from '../schemas/radio-protocol-schema.json' with { type: 'json' };\nimport radioMemoryMapSchema from '../schemas/radio-memory-map-schema.json' with { type: 'json' };\n\nexport interface ValidationResult {\n valid: boolean;\n errors?: string[];\n}\n\ninterface AjvError {\n instancePath?: string;\n message?: string;\n}\n\nexport class SchemaValidator {\n private ajv: Ajv;\n\n constructor() {\n this.ajv = new Ajv({\n allErrors: true,\n verbose: true,\n });\n (addFormats as unknown as (ajv: Ajv) => Ajv)(this.ajv);\n }\n\n validateRadioProtocol(config: unknown): ValidationResult {\n return this.validateAgainst(radioProtocolSchema, config);\n }\n\n validateMemoryMap(memoryMap: unknown): ValidationResult {\n return this.validateAgainst(radioMemoryMapSchema, memoryMap);\n }\n\n private validateAgainst(schema: object, data: unknown): ValidationResult {\n const validate = this.ajv.compile(schema);\n const valid = validate(data);\n\n if (valid) {\n return { valid: true };\n }\n\n let errors: string[] = [];\n if (validate.errors && validate.errors.length > 0) {\n errors = validate.errors.map((error: AjvError) => {\n const path = error.instancePath || 'root';\n return `${path}: ${error.message}`;\n });\n }\n\n return {\n errors,\n valid: false,\n };\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@springfield/ham-radio-utils",
3
- "version": "4.1.1",
3
+ "version": "4.2.0",
4
4
  "author": "Bryan Hunt",
5
5
  "license": "MIT",
6
6
  "readme": "README.md",
@@ -30,7 +30,7 @@
30
30
  "test:unit": "tsx --test test/unit/**/*.test.ts"
31
31
  },
32
32
  "dependencies": {
33
- "@springfield/ham-radio-api": "^17.0.0",
33
+ "@springfield/ham-radio-api": "^17.1.0",
34
34
  "ajv": "^8.20.0",
35
35
  "ajv-formats": "^3.0.1",
36
36
  "fishery": "^2.4.0",
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './memory/segmented-memory.js';
2
+ export * from './memory/memory-map-codec.js';
3
+ export * from './memory/memory-map-ui.js';
2
4
 
3
5
  export * from './test-utils/radio-channel-factory.js';
4
6
  export * from './test-utils/radio-programmed-channel-factory.js';
@@ -15,3 +17,4 @@ export * from './utils/ui-logger-factory.js';
15
17
 
16
18
  // Export the radio protocol schema
17
19
  export { default as radioProtocolSchema } from './schemas/radio-protocol-schema.json' with { type: 'json' };
20
+ export { default as radioMemoryMapSchema } from './schemas/radio-memory-map-schema.json' with { type: 'json' };