@springfield/ham-radio-utils 2.0.2 → 2.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,48 @@
1
+ import { BaseTransport } from '@loglayer/transport';
2
+ import { LogLayer } from 'loglayer';
3
+ import { UILogger } from './ui-logger.js';
4
+ /**
5
+ * Custom LogLayer transport for capturing UI log entries.
6
+ */
7
+ const UILogTransport = class extends BaseTransport {
8
+ #callback;
9
+ constructor(callback) {
10
+ // Pass a dummy logger to BaseTransport
11
+ super({ enabled: true, id: 'ui-logger-transport', logger: { log: () => { } } });
12
+ this.#callback = callback;
13
+ }
14
+ shipToLogger(params) {
15
+ const logEntry = {
16
+ data: params.data,
17
+ hasData: params.hasData,
18
+ level: params.logLevel,
19
+ message: params.messages.join(' '),
20
+ timestamp: new Date().toISOString(),
21
+ };
22
+ this.#callback(logEntry);
23
+ return [];
24
+ }
25
+ };
26
+ export const createUILogger = function createUILogger(config = {}) {
27
+ // By default, just print to console as JSON
28
+ const defaultCallback = (logEntry) => {
29
+ console.log(JSON.stringify(logEntry));
30
+ };
31
+ const transport = config.customTransport || new UILogTransport(defaultCallback);
32
+ const logger = new LogLayer({
33
+ consoleDebug: config.enableConsoleDebug ?? false,
34
+ transport,
35
+ });
36
+ logger.setLevel('debug');
37
+ return new UILogger(logger);
38
+ };
39
+ export const createUILoggerWithCallback = function createUILoggerWithCallback(callback, config = {}) {
40
+ const transport = new UILogTransport(callback);
41
+ const logger = new LogLayer({
42
+ consoleDebug: config.enableConsoleDebug ?? false,
43
+ transport,
44
+ });
45
+ logger.setLevel('debug');
46
+ return new UILogger(logger);
47
+ };
48
+ //# sourceMappingURL=ui-logger-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-logger-factory.js","sourceRoot":"","sources":["../../src/utils/ui-logger-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,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C,CAAC;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzB,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,SAAS,0BAA0B,CAAC,QAAiC,EAAE,SAAyB,EAAE;IAC1I,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC,kBAAkB,IAAI,KAAK;QAChD,SAAS;KACV,CAAC,CAAC;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzB,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC,CAAC","sourcesContent":["import { BaseTransport } from '@loglayer/transport';\nimport { LogLayer } from 'loglayer';\nimport { UILogger } from './ui-logger.js';\n\n/**\n * Custom LogLayer transport for capturing UI log entries.\n */\nconst UILogTransport = class extends BaseTransport<any> {\n #callback: (logEntry: any) => void;\n\n constructor(callback: (logEntry: any) => void) {\n // Pass a dummy logger to BaseTransport\n super({ enabled: true, id: 'ui-logger-transport', logger: { log: () => {} } });\n this.#callback = callback;\n }\n\n shipToLogger(params: any) {\n const logEntry = {\n data: params.data,\n hasData: params.hasData,\n level: params.logLevel,\n message: params.messages.join(' '),\n timestamp: new Date().toISOString(),\n };\n this.#callback(logEntry);\n return [];\n }\n};\n\nexport interface UILoggerConfig {\n customTransport?: any;\n enableConsoleDebug?: boolean;\n}\n\nexport const createUILogger = function createUILogger(config: UILoggerConfig = {}): UILogger {\n // By default, just print to console as JSON\n const defaultCallback = (logEntry: any) => {\n console.log(JSON.stringify(logEntry));\n };\n const transport = config.customTransport || new UILogTransport(defaultCallback);\n const logger = new LogLayer({\n consoleDebug: config.enableConsoleDebug ?? false,\n transport,\n });\n logger.setLevel('debug');\n return new UILogger(logger);\n};\n\nexport const createUILoggerWithCallback = function createUILoggerWithCallback(callback: (logEntry: any) => void, config: UILoggerConfig = {}): UILogger {\n const transport = new UILogTransport(callback);\n const logger = new LogLayer({\n consoleDebug: config.enableConsoleDebug ?? false,\n transport,\n });\n logger.setLevel('debug');\n return new UILogger(logger);\n};\n"]}
@@ -0,0 +1,43 @@
1
+ import type { ILogLayer } from 'loglayer';
2
+ /**
3
+ * UI Logger: Command-Level Logging for UI Display
4
+ *
5
+ * This module provides a specialized logger for capturing command-level information
6
+ * that can be easily parsed and displayed in a UI. It captures details about
7
+ * commands, data sent, data expected, and data received in a structured format.
8
+ *
9
+ * Purpose:
10
+ * - Captures command-level information for UI display
11
+ * - Provides structured JSON logging for easy parsing
12
+ * - Tracks command execution details including timing
13
+ * - Supports protocol debugging in UI environments
14
+ * - Maintains separation from debug logging
15
+ *
16
+ * Design Rationale:
17
+ * - Single log entry per command provides clean UI display
18
+ * - JSON structure enables easy parsing and filtering
19
+ * - Command-level granularity is appropriate for UI debugging
20
+ * - Structured data supports rich UI representations
21
+ * - Separate from debug logging avoids UI noise
22
+ */
23
+ /**
24
+ * Generic protocol step interface for UI logging
25
+ */
26
+ export interface UIProtocolStep {
27
+ [key: string]: any;
28
+ }
29
+ /**
30
+ * UI Logger for capturing command-level information for UI display
31
+ */
32
+ export declare class UILogger {
33
+ private logger;
34
+ private commandStartTimes;
35
+ constructor(logger: ILogLayer);
36
+ startCommand(stepIndex: number, totalSteps: number, operation: string, step: UIProtocolStep): void;
37
+ logCommandSuccess(stepIndex: number, totalSteps: number, operation: string, step: UIProtocolStep, context: any): void;
38
+ logCommandFailure(stepIndex: number, totalSteps: number, operation: string, step: UIProtocolStep, error: Error, context: any): void;
39
+ private getCommandType;
40
+ private getStepDescription;
41
+ private getExpectedData;
42
+ }
43
+ //# sourceMappingURL=ui-logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-logger.d.ts","sourceRoot":"","sources":["../../src/utils/ui-logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,iBAAiB,CAA6B;gBAE1C,MAAM,EAAE,SAAS;IAK7B,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI;IAsBlG,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI;IA6CrH,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI;IAkCnI,OAAO,CAAC,cAAc;IAsBtB,OAAO,CAAC,kBAAkB;IAmB1B,OAAO,CAAC,eAAe;CAiBxB"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * UI Logger for capturing command-level information for UI display
3
+ */
4
+ export class UILogger {
5
+ logger;
6
+ commandStartTimes = new Map();
7
+ constructor(logger) {
8
+ this.logger = logger;
9
+ }
10
+ // eslint-disable-next-line max-params
11
+ startCommand(stepIndex, totalSteps, operation, step) {
12
+ const commandId = `${operation}-${stepIndex}`;
13
+ const startTime = Date.now();
14
+ this.commandStartTimes.set(commandId, startTime);
15
+ const commandType = this.getCommandType(step);
16
+ const description = this.getStepDescription(step);
17
+ this.logger
18
+ .withMetadata({
19
+ commandId,
20
+ commandType,
21
+ description,
22
+ operation,
23
+ startTime,
24
+ stepIndex,
25
+ totalSteps,
26
+ })
27
+ .info('Command started');
28
+ }
29
+ // eslint-disable-next-line max-params
30
+ logCommandSuccess(stepIndex, totalSteps, operation, step, context) {
31
+ const commandId = `${operation}-${stepIndex}`;
32
+ const startTime = this.commandStartTimes.get(commandId) || Date.now();
33
+ const endTime = Date.now();
34
+ const duration = endTime - startTime;
35
+ const commandType = this.getCommandType(step);
36
+ const description = this.getStepDescription(step);
37
+ // Extract sent and received data from context
38
+ const dataSent = context.variables?.get('lastSentData');
39
+ const dataReceived = context.variables?.get('lastReceivedData');
40
+ const dataExpected = this.getExpectedData(step);
41
+ // For readSegment, also extract chunk logs if present
42
+ let dataChunks = undefined;
43
+ if ('readSegment' === commandType) {
44
+ dataChunks = context.variables?.get('lastReadSegmentChunks');
45
+ // For readSegment, we don't need the flattened dataSent/dataReceived since we have dataChunks
46
+ }
47
+ // Convert dataSent and dataReceived to byte array format if they exist
48
+ const dataSentArray = dataSent ? [...dataSent] : undefined;
49
+ const dataReceivedArray = dataReceived ? [...dataReceived] : undefined;
50
+ this.logger
51
+ .withMetadata({
52
+ commandType,
53
+ dataChunks,
54
+ dataExpected,
55
+ dataReceived: dataReceivedArray,
56
+ dataSent: dataSentArray,
57
+ description,
58
+ duration,
59
+ endTime,
60
+ operation,
61
+ startTime,
62
+ stepIndex,
63
+ success: true,
64
+ totalSteps,
65
+ })
66
+ .info('Command completed successfully');
67
+ }
68
+ // eslint-disable-next-line max-params
69
+ logCommandFailure(stepIndex, totalSteps, operation, step, error, context) {
70
+ const commandId = `${operation}-${stepIndex}`;
71
+ const startTime = this.commandStartTimes.get(commandId) || Date.now();
72
+ const endTime = Date.now();
73
+ const duration = endTime - startTime;
74
+ const commandType = this.getCommandType(step);
75
+ const description = this.getStepDescription(step);
76
+ // Extract sent data from context
77
+ const dataSent = context.variables?.get('lastSentData');
78
+ const dataExpected = this.getExpectedData(step);
79
+ // Convert dataSent to byte array format if it exists
80
+ const dataSentArray = dataSent ? [...dataSent] : undefined;
81
+ this.logger
82
+ .withMetadata({
83
+ commandType,
84
+ dataExpected,
85
+ dataSent: dataSentArray,
86
+ description,
87
+ duration,
88
+ endTime,
89
+ error: error.message,
90
+ operation,
91
+ startTime,
92
+ stepIndex,
93
+ success: false,
94
+ totalSteps,
95
+ })
96
+ .info('Command failed');
97
+ }
98
+ getCommandType(step) {
99
+ if ('sendReceive' in step) {
100
+ return 'sendReceive';
101
+ }
102
+ if ('send' in step) {
103
+ return 'send';
104
+ }
105
+ if ('receive' in step) {
106
+ return 'receive';
107
+ }
108
+ if ('readSegment' in step) {
109
+ return 'readSegment';
110
+ }
111
+ if ('writeSegment' in step) {
112
+ return 'writeSegment';
113
+ }
114
+ if ('setVariable' in step) {
115
+ return 'setVariable';
116
+ }
117
+ return 'unknown';
118
+ }
119
+ getStepDescription(step) {
120
+ if ('sendReceive' in step && step.sendReceive.description) {
121
+ return step.sendReceive.description;
122
+ }
123
+ if ('send' in step && step.send.description) {
124
+ return step.send.description;
125
+ }
126
+ if ('receive' in step && step.receive.description) {
127
+ return step.receive.description;
128
+ }
129
+ if ('readSegment' in step && step.readSegment.description) {
130
+ return step.readSegment.description;
131
+ }
132
+ if ('writeSegment' in step && step.writeSegment.description) {
133
+ return step.writeSegment.description;
134
+ }
135
+ return 'No description';
136
+ }
137
+ getExpectedData(step) {
138
+ if ('sendReceive' in step && step.sendReceive.receive) {
139
+ return step.sendReceive.receive;
140
+ }
141
+ if ('receive' in step) {
142
+ return step.receive;
143
+ }
144
+ if ('readSegment' in step) {
145
+ // For readSegment, return both start and end chunk receive patterns
146
+ return {
147
+ endChunk: step.readSegment.endChunk.receive,
148
+ startChunk: step.readSegment.startChunk.receive,
149
+ type: 'readSegment',
150
+ };
151
+ }
152
+ return undefined;
153
+ }
154
+ }
155
+ //# sourceMappingURL=ui-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-logger.js","sourceRoot":"","sources":["../../src/utils/ui-logger.ts"],"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OAAO;gBACL,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO;gBAC3C,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO;gBAC/C,IAAI,EAAE,aAAa;aACpB,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import type { ILogLayer } from 'loglayer';\n\n/**\n * UI Logger: Command-Level Logging for UI Display\n *\n * This module provides a specialized logger for capturing command-level information\n * that can be easily parsed and displayed in a UI. It captures details about\n * commands, data sent, data expected, and data received in a structured format.\n *\n * Purpose:\n * - Captures command-level information for UI display\n * - Provides structured JSON logging for easy parsing\n * - Tracks command execution details including timing\n * - Supports protocol debugging in UI environments\n * - Maintains separation from debug logging\n *\n * Design Rationale:\n * - Single log entry per command provides clean UI display\n * - JSON structure enables easy parsing and filtering\n * - Command-level granularity is appropriate for UI debugging\n * - Structured data supports rich UI representations\n * - Separate from debug logging avoids UI noise\n */\n\n/**\n * Generic protocol step interface for UI logging\n */\nexport interface UIProtocolStep {\n [key: string]: any;\n}\n\n/**\n * UI Logger for capturing command-level information for UI display\n */\nexport class UILogger {\n private logger: ILogLayer;\n private commandStartTimes = new Map<string, number>();\n\n constructor(logger: ILogLayer) {\n this.logger = logger;\n }\n\n // eslint-disable-next-line max-params\n startCommand(stepIndex: number, totalSteps: number, operation: string, step: UIProtocolStep): void {\n const commandId = `${operation}-${stepIndex}`;\n const startTime = Date.now();\n this.commandStartTimes.set(commandId, startTime);\n\n const commandType = this.getCommandType(step);\n const description = this.getStepDescription(step);\n\n this.logger\n .withMetadata({\n commandId,\n commandType,\n description,\n operation,\n startTime,\n stepIndex,\n totalSteps,\n })\n .info('Command started');\n }\n\n // eslint-disable-next-line max-params\n logCommandSuccess(stepIndex: number, totalSteps: number, operation: string, step: UIProtocolStep, context: any): void {\n const commandId = `${operation}-${stepIndex}`;\n const startTime = this.commandStartTimes.get(commandId) || Date.now();\n const endTime = Date.now();\n const duration = endTime - startTime;\n\n const commandType = this.getCommandType(step);\n const description = this.getStepDescription(step);\n\n // Extract sent and received data from context\n const dataSent = context.variables?.get('lastSentData');\n const dataReceived = context.variables?.get('lastReceivedData');\n const dataExpected = this.getExpectedData(step);\n\n // For readSegment, also extract chunk logs if present\n let dataChunks = undefined;\n if ('readSegment' === commandType) {\n dataChunks = context.variables?.get('lastReadSegmentChunks');\n // For readSegment, we don't need the flattened dataSent/dataReceived since we have dataChunks\n }\n\n // Convert dataSent and dataReceived to byte array format if they exist\n const dataSentArray = dataSent ? [...dataSent] : undefined;\n const dataReceivedArray = dataReceived ? [...dataReceived] : undefined;\n\n this.logger\n .withMetadata({\n commandType,\n dataChunks,\n dataExpected,\n dataReceived: dataReceivedArray,\n dataSent: dataSentArray,\n description,\n duration,\n endTime,\n operation,\n startTime,\n stepIndex,\n success: true,\n totalSteps,\n })\n .info('Command completed successfully');\n }\n\n // eslint-disable-next-line max-params\n logCommandFailure(stepIndex: number, totalSteps: number, operation: string, step: UIProtocolStep, error: Error, context: any): void {\n const commandId = `${operation}-${stepIndex}`;\n const startTime = this.commandStartTimes.get(commandId) || Date.now();\n const endTime = Date.now();\n const duration = endTime - startTime;\n\n const commandType = this.getCommandType(step);\n const description = this.getStepDescription(step);\n\n // Extract sent data from context\n const dataSent = context.variables?.get('lastSentData');\n const dataExpected = this.getExpectedData(step);\n\n // Convert dataSent to byte array format if it exists\n const dataSentArray = dataSent ? [...dataSent] : undefined;\n\n this.logger\n .withMetadata({\n commandType,\n dataExpected,\n dataSent: dataSentArray,\n description,\n duration,\n endTime,\n error: error.message,\n operation,\n startTime,\n stepIndex,\n success: false,\n totalSteps,\n })\n .info('Command failed');\n }\n\n private getCommandType(step: UIProtocolStep): string {\n if ('sendReceive' in step) {\n return 'sendReceive';\n }\n if ('send' in step) {\n return 'send';\n }\n if ('receive' in step) {\n return 'receive';\n }\n if ('readSegment' in step) {\n return 'readSegment';\n }\n if ('writeSegment' in step) {\n return 'writeSegment';\n }\n if ('setVariable' in step) {\n return 'setVariable';\n }\n return 'unknown';\n }\n\n private getStepDescription(step: UIProtocolStep): string {\n if ('sendReceive' in step && step.sendReceive.description) {\n return step.sendReceive.description;\n }\n if ('send' in step && step.send.description) {\n return step.send.description;\n }\n if ('receive' in step && step.receive.description) {\n return step.receive.description;\n }\n if ('readSegment' in step && step.readSegment.description) {\n return step.readSegment.description;\n }\n if ('writeSegment' in step && step.writeSegment.description) {\n return step.writeSegment.description;\n }\n return 'No description';\n }\n\n private getExpectedData(step: UIProtocolStep): any {\n if ('sendReceive' in step && step.sendReceive.receive) {\n return step.sendReceive.receive;\n }\n if ('receive' in step) {\n return step.receive;\n }\n if ('readSegment' in step) {\n // For readSegment, return both start and end chunk receive patterns\n return {\n endChunk: step.readSegment.endChunk.receive,\n startChunk: step.readSegment.startChunk.receive,\n type: 'readSegment',\n };\n }\n return undefined;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@springfield/ham-radio-utils",
3
- "version": "2.0.2",
3
+ "version": "2.2.0",
4
4
  "author": "Bryan Hunt",
5
+ "license": "MIT",
5
6
  "packageManager": "yarn@4.9.2",
6
7
  "readme": "README.md",
7
8
  "type": "module",
@@ -12,7 +13,7 @@
12
13
  "dist/"
13
14
  ],
14
15
  "scripts": {
15
- "build": "tsc && cp src/db/* dist/db/",
16
+ "build": "tsc && cp src/db/* dist/db/ && cp src/schemas/* dist/schemas/",
16
17
  "commitlint": "commitlint --edit",
17
18
  "lint": "oxlint",
18
19
  "lint:fix": "oxlint --fix --fix-suggestions",
@@ -50,7 +51,9 @@
50
51
  "access": "public"
51
52
  },
52
53
  "dependencies": {
53
- "@springfield/ham-radio-api": "^14.0.0",
54
+ "@springfield/ham-radio-api": "^16.1.1",
55
+ "ajv": "^8.17.1",
56
+ "ajv-formats": "^3.0.1",
54
57
  "fishery": "^2.3.1",
55
58
  "loglayer": "^6.4.3",
56
59
  "sprintf-js": "^1.1.3"
@@ -61,9 +64,11 @@
61
64
  "@semantic-release/changelog": "6.0.3",
62
65
  "@semantic-release/git": "10.0.1",
63
66
  "@semantic-release/gitlab": "13.2.6",
67
+ "@types/chai": "^5.2.2",
64
68
  "@types/sprintf-js": "1.1.4",
69
+ "chai": "^5.2.0",
65
70
  "husky": "9.1.7",
66
- "oxlint": "1.1.0",
71
+ "oxlint": "1.3.0",
67
72
  "semantic-release": "23.1.1",
68
73
  "semantic-release-yarn": "3.0.2",
69
74
  "typescript": "5.8.3"
package/src/index.ts CHANGED
@@ -9,4 +9,10 @@ export * from './utils/frequency-display.js';
9
9
  export * from './utils/memory-channel-utils.js';
10
10
  export * from './utils/memory-data-utils.js';
11
11
  export * from './utils/number-to-bcd.js';
12
+ export * from './utils/schema-validator.js';
12
13
  export * from './utils/to-hex-words.js';
14
+ export * from './utils/ui-logger.js';
15
+ export * from './utils/ui-logger-factory.js';
16
+
17
+ // Export the radio protocol schema
18
+ export { default as radioProtocolSchema } from './schemas/radio-protocol-schema.json' with { type: 'json' };