-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtypes.ts
More file actions
201 lines (177 loc) · 6.55 KB
/
Copy pathtypes.ts
File metadata and controls
201 lines (177 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import {
errorTypeSchema,
jsonSchemaDirectionSchema,
jsonSchemaTargetSchema,
optimizeTypeSchema,
stringFormatSchema,
} from "@schema-benchmarks/schemas";
import type { OneOf } from "@schema-benchmarks/utils";
import { unsafeFromEntries } from "@schema-benchmarks/utils";
import * as v from "valibot";
export const dataTypeSchema = v.picklist(["invalid", "valid"]);
export type DataType = v.InferOutput<typeof dataTypeSchema>;
export const baseBenchResultSchema = v.object({
id: v.string(),
libraryName: v.string(),
version: v.string(),
note: v.optional(v.string()),
snippet: v.string(),
throws: v.optional(v.boolean()),
mean: v.number(),
});
export type BaseBenchResult = v.InferOutput<typeof baseBenchResultSchema>;
export const runtimeBenchResultSchema = v.object({
...baseBenchResultSchema.entries,
optimizeType: optimizeTypeSchema,
});
export type RuntimeBenchResult = v.InferOutput<typeof runtimeBenchResultSchema>;
export const initializationResultSchema = v.object({
...runtimeBenchResultSchema.entries,
type: v.literal("initialization"),
});
export type InitializationResult = v.InferOutput<typeof initializationResultSchema>;
export const validationResultSchema = v.object({
...runtimeBenchResultSchema.entries,
type: v.literal("validation"),
});
export type ValidationResult = v.InferOutput<typeof validationResultSchema>;
export const parsingResultSchema = v.object({
...runtimeBenchResultSchema.entries,
type: v.literal("parsing"),
errorType: errorTypeSchema,
});
export type ParsingResult = v.InferOutput<typeof parsingResultSchema>;
const standardResultSchema = v.object({
...runtimeBenchResultSchema.entries,
errorType: errorTypeSchema,
type: v.literal("standard"),
});
export type StandardResult = v.InferOutput<typeof standardResultSchema>;
const jsonSchemaSourceResultSchema = v.union([
v.picklist(["native", "opt-in"]),
v.object({
type: v.literal("package"),
package: v.string(),
}),
]);
export type JsonSchemaSourceResult = v.InferOutput<typeof jsonSchemaSourceResultSchema>;
const schemaConversionToJsonResultSchema = v.object({
...v.omit(baseBenchResultSchema, ["throws"]).entries,
target: jsonSchemaTargetSchema,
direction: jsonSchemaDirectionSchema,
/** The JSON schema the library generated, so it can be compared with the others. */
jsonSchema: v.string(),
});
export type SchemaToJsonResult = v.InferOutput<typeof schemaConversionToJsonResultSchema>;
const schemaConversionFromJsonResultSchema = v.object({
...v.omit(baseBenchResultSchema, ["throws"]).entries,
});
export type SchemaFromJsonResult = v.InferOutput<typeof schemaConversionFromJsonResultSchema>;
export type JsonSchemaConversionResult = OneOf<SchemaToJsonResult | SchemaFromJsonResult>;
export const jsonSchemaSupportMatrixSchema = v.object(
v.entriesFromList(
jsonSchemaTargetSchema.options,
v.optional(
v.object(v.entriesFromList(jsonSchemaDirectionSchema.options, v.optional(v.string()))),
),
),
);
export type JsonSchemaSupportMatrix = v.InferOutput<typeof jsonSchemaSupportMatrixSchema>;
export const jsonSchemaSupportMatricesSchema = v.record(
v.string(),
v.object({
version: v.string(),
source: jsonSchemaSourceResultSchema,
standardJsonSchema: v.optional(jsonSchemaSourceResultSchema),
matrix: jsonSchemaSupportMatrixSchema,
}),
);
export type JsonSchemaSupportMatrices = v.InferOutput<typeof jsonSchemaSupportMatricesSchema>;
export const jsonSchemaBenchResultsSchema = v.object({
conversion: v.object({
toJson: v.array(schemaConversionToJsonResultSchema),
fromJson: v.array(schemaConversionFromJsonResultSchema),
toJsonSupport: jsonSchemaSupportMatricesSchema,
}),
});
export type JsonSchemaBenchResults = v.InferOutput<typeof jsonSchemaBenchResultsSchema>;
export const getEmptyJsonSchemaResults = (): JsonSchemaBenchResults => ({
conversion: {
toJson: [],
fromJson: [],
toJsonSupport: {},
},
});
const stringResultSchema = v.object({
...runtimeBenchResultSchema.entries,
type: v.literal("string"),
});
export type StringResult = v.InferOutput<typeof stringResultSchema>;
export const codecResultSchema = v.object({
...v.omit(runtimeBenchResultSchema, ["snippet", "mean"]).entries,
encode: v.object({
snippet: v.string(),
mean: v.number(),
}),
decode: v.object({
snippet: v.string(),
mean: v.number(),
}),
type: v.literal("codec"),
acceptsUnknown: v.optional(v.boolean()),
});
export type CodecResult = v.InferOutput<typeof codecResultSchema>;
export type RuntimeResult = OneOf<
InitializationResult | ValidationResult | ParsingResult | StandardResult | StringResult
>;
export const benchResultsSchema = v.object({
initialization: v.array(initializationResultSchema),
parsing: v.object(v.entriesFromList(dataTypeSchema.options, v.array(parsingResultSchema))),
validation: v.object(v.entriesFromList(dataTypeSchema.options, v.array(validationResultSchema))),
standard: v.object(v.entriesFromList(dataTypeSchema.options, v.array(standardResultSchema))),
string: v.object(
v.entriesFromList(
stringFormatSchema.options,
v.object(v.entriesFromList(dataTypeSchema.options, v.array(stringResultSchema))),
),
),
codec: v.array(codecResultSchema),
});
export type BenchResults = v.InferOutput<typeof benchResultsSchema>;
export const getEmptyResults = (): BenchResults => ({
initialization: [],
parsing: { valid: [], invalid: [] },
validation: { valid: [], invalid: [] },
standard: { valid: [], invalid: [] },
string: unsafeFromEntries(
stringFormatSchema.options.map((format) => [format, { valid: [], invalid: [] }]),
),
codec: [],
});
export const minifyTypeSchema = v.picklist(["minified", "unminified"]);
export type MinifyType = v.InferOutput<typeof minifyTypeSchema>;
export const downloadResultSchema = v.object({
fileName: v.string(),
libraryName: v.string(),
version: v.string(),
note: v.optional(v.string()),
bytes: v.number(),
gzipBytes: v.number(),
});
export type DownloadResult = v.InferOutput<typeof downloadResultSchema>;
export const downloadResultsSchema = v.object({
minified: v.array(downloadResultSchema),
unminified: v.array(downloadResultSchema),
});
export type DownloadResults = v.InferOutput<typeof downloadResultsSchema>;
const resultTypeSchema = v.picklist(["success", "not an error", "no stack", "not found"]);
export const stackResultSchema = v.object({
type: resultTypeSchema,
libraryName: v.string(),
version: v.string(),
snippet: v.string(),
frame: v.optional(v.number()),
output: v.string(),
lineCount: v.number(),
});
export type StackResult = v.InferOutput<typeof stackResultSchema>;