feat(core): P3.1-A Add metrics contract infrastructure

Created src/core/metrics.ts with:
- PerformanceMetric interface
- MetricsCollector interface
- InMemoryMetricsCollector implementation

Updated src/core/index.ts to export metrics.

Note: Web stub (src/web.ts) doesn't need timing instrumentation since it throws immediately. Real instrumentation will be in platform implementations (P3.1-C).

Verification:
- TypeScript compiles 
- Core purity check passes 
- No new dependencies 
This commit is contained in:
Matthew Raymer
2025-12-23 06:37:56 +00:00
parent 6297281d2d
commit 04cf801b09
3 changed files with 69 additions and 0 deletions

View File

@@ -61,3 +61,10 @@ export {
isValidTimestamp,
} from './guards';
// Metrics
export {
type PerformanceMetric,
type MetricsCollector,
InMemoryMetricsCollector,
} from './metrics';

59
src/core/metrics.ts Normal file
View File

@@ -0,0 +1,59 @@
/**
* Core Metrics
*
* Performance metrics contract and lightweight collector.
* Platform-agnostic, no dependencies.
*
* @author Matthew Raymer
* @version 1.0.0
*/
/**
* Performance metric entry
*/
export interface PerformanceMetric {
/** Operation name (e.g., 'schedule.create', 'recovery.coldStart') */
operation: string;
/** Duration in milliseconds */
duration: number;
/** Timestamp when metric was recorded (milliseconds since epoch) */
timestamp: number;
/** Whether operation succeeded */
success: boolean;
/** Optional metadata */
metadata?: Record<string, unknown>;
}
/**
* Metrics collector interface
*/
export interface MetricsCollector {
record(metric: PerformanceMetric): void;
getMetrics(): PerformanceMetric[];
clear(): void;
}
/**
* Lightweight in-memory metrics collector
* No dependencies, platform-agnostic
*/
export class InMemoryMetricsCollector implements MetricsCollector {
private metrics: PerformanceMetric[] = [];
private maxMetrics = 100;
record(metric: PerformanceMetric): void {
this.metrics.push(metric);
if (this.metrics.length > this.maxMetrics) {
this.metrics = this.metrics.slice(-this.maxMetrics);
}
}
getMetrics(): PerformanceMetric[] {
return [...this.metrics];
}
clear(): void {
this.metrics = [];
}
}

View File

@@ -332,14 +332,17 @@ export class DailyNotificationWeb implements DailyNotificationPlugin {
}
async createSchedule(_schedule: CreateScheduleInput): Promise<Schedule> {
// Web stub: no timing needed (throws immediately)
this.throwNotSupported();
}
async updateSchedule(_id: string, _updates: unknown): Promise<Schedule> {
// Web stub: no timing needed (throws immediately)
this.throwNotSupported();
}
async deleteSchedule(_id: string): Promise<void> {
// Web stub: no timing needed (throws immediately)
this.throwNotSupported();
}