@typeslayer/validate
v0.1.31
Published
Validation schemas and utilities for TypeScript compiler trace analysis
Maintainers
Readme
@typeslayer/validate
Validation schemas and utilities for TypeScript compiler trace analysis. This package provides comprehensive Zod-based schema validation (and types!!) for trace events, type metrics, and analysis results.
Usage
Trace JSON Validation
import { traceJsonSchema, type TraceEvent } from '@typeslayer/validate';
// Validate trace.json output from TypeScript compiler
const events: TraceEvent[] = traceJsonSchema.parse(jsonData);
// Or use with Node.js streams
import { createReadStream } from 'fs';
import { validateTraceJson } from '@typeslayer/validate/node';
const stream = createReadStream('trace.json');
const events = await validateTraceJson(stream);Types JSON Validation
import { typesJsonSchema, type TypesJsonSchema } from '@typeslayer/validate';
const types: TypesJsonSchema = typesJsonSchema.parse(jsonData);CPU Profile Validation
import { tscCpuProfileSchema } from '@typeslayer/validate';
const profile = tscCpuProfileSchema.parse(jsonData);Exports
- Main export (
@typeslayer/validate): Browser-compatible validation schemastraceJsonSchema- Validates TypeScript trace eventstypesJsonSchema- Validates type informationtscCpuProfileSchema- Validates CPU profile data
- Node export (
@typeslayer/validate/node): Node.js-specific utilitiesvalidateTraceJson()- Stream-based trace validationreadTraceJson()- Read and parse trace.json files
TypeScript Support
Full TypeScript support with type inference from schemas:
import type { TraceEvent } from '@typeslayer/validate';
// Type-safe event handling
function processEvent(event: TraceEvent) {
switch (event.name) {
case 'createSourceFile':
console.log('Creating source file:', event.args.path);
break;
// ... other event types
}
}