Skip to content

feat: Define metric schema and TypeScript types#2

Open
charliewwdev wants to merge 2 commits intomainfrom
feat/define-metric-schema-and-typescript-types
Open

feat: Define metric schema and TypeScript types#2
charliewwdev wants to merge 2 commits intomainfrom
feat/define-metric-schema-and-typescript-types

Conversation

@charliewwdev
Copy link
Copy Markdown
Member

Create shared types for MetricEvent, MetricSeries, and AggregatedMetric. Types must be shared between the server WebSocket emitter and the client consumer to prevent payload drift.


Generated by OpenDev AI

All types are derived from Zod schemas using z.infer<>, consistent with the existing prd-decompose.ts / task-codegen.ts pattern. This gives both compile-time safety and runtime validation on WebSocket frames — preventing payload drift because the same schema object is the single source of truth for both sides. Key decisions: (1) MetricEvent is the atomic unit; MetricSeries batches historical points on subscribe; AggregatedMetric carries pre-computed stats so clients stay thin. (2) All three are wrapped in a ServerMetricMessage discriminated union so client switch statements are exhaustive. (3) ClientMetricMessage mirrors the pattern for subscription control messages. (4) Refinements enforce invariants (window_end >= window_start, min <= max) at the schema level so invalid shapes are rejected at the boundary. (5) Three parse helpers are exported: strict parse* for startup-time validation, and safeParse* for high-throughput loops where a bad frame should be skipped rather than crashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant