@typeslayer/validate 0.0.0 → 0.1.10
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.
- package/README.md +66 -0
- package/dist/index.d.ts +1939 -0
- package/dist/index.js +1023 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +5 -0
- package/dist/node.js +21 -0
- package/dist/node.js.map +1 -0
- package/package.json +45 -3
- package/src/grab-file.ts +25 -0
- package/src/index.ts +41 -0
- package/src/node.ts +1 -0
- package/src/package-name.test.ts +20 -0
- package/src/package-name.ts +50 -0
- package/src/trace-json.ts +1126 -0
- package/src/tsc-cpuprofile.ts +1 -0
- package/src/type-registry.ts +17 -0
- package/src/types-json.ts +144 -0
- package/src/utils.ts +20 -0
- package/tsconfig.json +16 -0
- package/tsup.config.ts +11 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @typeslayer/validate
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
### Trace JSON Validation
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { traceJsonSchema, type TraceEvent } from '@typeslayer/validate';
|
|
11
|
+
|
|
12
|
+
// Validate trace.json output from TypeScript compiler
|
|
13
|
+
const events: TraceEvent[] = traceJsonSchema.parse(jsonData);
|
|
14
|
+
|
|
15
|
+
// Or use with Node.js streams
|
|
16
|
+
import { createReadStream } from 'fs';
|
|
17
|
+
import { validateTraceJson } from '@typeslayer/validate/node';
|
|
18
|
+
|
|
19
|
+
const stream = createReadStream('trace.json');
|
|
20
|
+
const events = await validateTraceJson(stream);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Types JSON Validation
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { typesJsonSchema, type TypesJsonSchema } from '@typeslayer/validate';
|
|
27
|
+
|
|
28
|
+
const types: TypesJsonSchema = typesJsonSchema.parse(jsonData);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### CPU Profile Validation
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { tscCpuProfileSchema } from '@typeslayer/validate';
|
|
35
|
+
|
|
36
|
+
const profile = tscCpuProfileSchema.parse(jsonData);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Exports
|
|
40
|
+
|
|
41
|
+
- **Main export (`@typeslayer/validate`)**: Browser-compatible validation schemas
|
|
42
|
+
- `traceJsonSchema` - Validates TypeScript trace events
|
|
43
|
+
- `typesJsonSchema` - Validates type information
|
|
44
|
+
- `tscCpuProfileSchema` - Validates CPU profile data
|
|
45
|
+
|
|
46
|
+
- **Node export (`@typeslayer/validate/node`)**: Node.js-specific utilities
|
|
47
|
+
- `validateTraceJson()` - Stream-based trace validation
|
|
48
|
+
- `readTraceJson()` - Read and parse trace.json files
|
|
49
|
+
|
|
50
|
+
## TypeScript Support
|
|
51
|
+
|
|
52
|
+
Full TypeScript support with type inference from schemas:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import type { TraceEvent } from '@typeslayer/validate';
|
|
56
|
+
|
|
57
|
+
// Type-safe event handling
|
|
58
|
+
function processEvent(event: TraceEvent) {
|
|
59
|
+
switch (event.name) {
|
|
60
|
+
case 'createSourceFile':
|
|
61
|
+
console.log('Creating source file:', event.args.path);
|
|
62
|
+
break;
|
|
63
|
+
// ... other event types
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|