Skip to content

Commit a9698b6

Browse files
hoeckmoltar
authored andcommitted
draft: support for multiple benchmarks
1 parent 5aa381b commit a9698b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+815
-2205
lines changed

cases/abstract.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import clone from 'clone';
22
import { Data } from '../data';
33

4-
export abstract class Case implements Case {
4+
export abstract class Case {
55
// eslint-disable-next-line @typescript-eslint/no-explicit-any
66
protected readonly data: any;
77

@@ -15,9 +15,16 @@ export abstract class Case implements Case {
1515
}
1616

1717
/**
18-
* Validation implementation method.
18+
* Non-Strict validation.
1919
*
2020
* Method returns a `Data` object or throws when invalid data is provided.
2121
*/
22-
abstract validate(): PromiseLike<Data> | Data;
22+
validate?: () => PromiseLike<Data> | Data;
23+
24+
/**
25+
* Strict validation.
26+
*
27+
* Method returns a `Data` object or throws when invalid data is provided.
28+
*/
29+
validateStrict?: () => PromiseLike<Data> | Data;
2330
}

cases/index.ts

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
1-
import { BuenoCase } from './bueno';
2-
import {
3-
ClassValidatorAsyncCase,
4-
ClassValidatorSyncCase,
5-
} from './class-validator';
6-
import { ComputedTypesCase } from './computed-types';
7-
import { DecodersCase } from './decoders';
8-
import { IoTsCase } from './io-ts';
9-
import { JointzCase } from './jointz';
10-
import { JsonDecoderCase } from './json-decoder';
11-
import { MarshalCase } from './marshal';
12-
import { MojoTechJsonTypeValidationCase } from './mojotech-json-type-validation';
13-
import { MyzodCase } from './myzod';
14-
import { PurifyCase } from './purify-ts';
15-
import { RulrCase } from './rulr';
16-
import { RuntypesCase } from './runtypes';
1+
// import { BuenoCase } from './bueno';
2+
// import {
3+
// ClassValidatorAsyncCase,
4+
// ClassValidatorSyncCase,
5+
// } from './class-validator';
6+
// import { ComputedTypesCase } from './computed-types';
7+
// import { DecodersCase } from './decoders';
8+
// import { IoTsCase } from './io-ts';
9+
// import { JointzCase } from './jointz';
10+
// import { JsonDecoderCase } from './json-decoder';
11+
// import { MarshalCase } from './marshal';
12+
// import { MojoTechJsonTypeValidationCase } from './mojotech-json-type-validation';
13+
// import { MyzodCase } from './myzod';
14+
// import { PurifyCase } from './purify-ts';
15+
// import { RulrCase } from './rulr';
16+
// import { RuntypesCase } from './runtypes';
1717
import { SimpleRuntypesCase } from './simple-runtypes';
18-
import { SuperstructCase } from './superstruct';
19-
import { SuretypeCase } from './suretype';
20-
import { ToiCase } from './toi';
18+
// import { SuperstructCase } from './superstruct';
19+
// import { SuretypeCase } from './suretype';
20+
// import { ToiCase } from './toi';
2121
import { TsInterfaceCheckerCase } from './ts-interface-checker';
22-
import { TsJsonValidatorCase } from './ts-json-validator';
23-
import { TsUtilsCase } from './ts-utils';
24-
import { TypeOfWebSchemaCase } from './typeofweb-schema';
22+
// import { TsJsonValidatorCase } from './ts-json-validator';
23+
// import { TsUtilsCase } from './ts-utils';
24+
// import { TypeOfWebSchemaCase } from './typeofweb-schema';
2525
import { ValitaCase } from './valita';
26-
import { YupCase } from './yup';
27-
import { ZodCase } from './zod';
28-
import { AjvCase } from './ajv';
26+
// import { YupCase } from './yup';
27+
// import { ZodCase } from './zod';
2928

3029
export const cases = [
31-
BuenoCase,
32-
ClassValidatorAsyncCase,
33-
ClassValidatorSyncCase,
34-
ComputedTypesCase,
35-
DecodersCase,
36-
IoTsCase,
37-
JointzCase,
38-
JsonDecoderCase,
39-
MarshalCase,
40-
MojoTechJsonTypeValidationCase,
41-
MyzodCase,
42-
PurifyCase,
43-
RulrCase,
44-
RuntypesCase,
30+
// BuenoCase,
31+
// ClassValidatorAsyncCase,
32+
// ClassValidatorSyncCase,
33+
// ComputedTypesCase,
34+
// DecodersCase,
35+
// IoTsCase,
36+
// JointzCase,
37+
// JsonDecoderCase,
38+
// MarshalCase,
39+
// MojoTechJsonTypeValidationCase,
40+
// MyzodCase,
41+
// PurifyCase,
42+
// RulrCase,
43+
// RuntypesCase,
4544
SimpleRuntypesCase,
46-
SuperstructCase,
47-
SuretypeCase,
48-
ToiCase,
45+
// SuperstructCase,
46+
// SuretypeCase,
47+
// ToiCase,
4948
TsInterfaceCheckerCase,
50-
TsJsonValidatorCase,
51-
TsUtilsCase,
52-
TypeOfWebSchemaCase,
49+
// TsJsonValidatorCase,
50+
// TsUtilsCase,
51+
// TypeOfWebSchemaCase,
5352
ValitaCase,
54-
YupCase,
55-
ZodCase,
56-
AjvCase,
53+
// YupCase,
54+
// ZodCase,
5755
];

cases/simple-runtypes.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ const checkData = rt.record({
1515
}),
1616
});
1717

18-
export class SimpleRuntypesCase extends Case implements Case {
18+
export class SimpleRuntypesCase extends Case {
1919
name = 'simple-runtypes';
2020

21-
validate() {
21+
validate = () => {
2222
return checkData(this.data);
23-
}
23+
};
24+
25+
validateStrict = () => {
26+
return checkData(this.data);
27+
};
2428
}

cases/ts-interface-checker.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const dataTypeChecker = t.createCheckers(suite).dataType as t.CheckerT<Data>;
2222
export class TsInterfaceCheckerCase extends Case implements Case {
2323
name = 'ts-interface-checker';
2424

25-
validate() {
25+
validate = () => {
2626
const { data } = this;
2727

2828
if (dataTypeChecker.test(data)) {
@@ -33,5 +33,15 @@ export class TsInterfaceCheckerCase extends Case implements Case {
3333
// typescript type guard like .test() above.
3434
dataTypeChecker.check(data);
3535
throw new Error('Invalid');
36-
}
36+
};
37+
38+
validateStrict = () => {
39+
const { data } = this;
40+
41+
// Calling .check() provides a more helpful error, but does not (at the moment) include a
42+
// typescript type guard like .test() above.
43+
dataTypeChecker.strictCheck(data);
44+
45+
return data;
46+
};
3747
}

cases/valita.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ const dataType = v.object({
1818
export class ValitaCase extends Case implements Case {
1919
name = 'valita';
2020

21-
validate() {
21+
validate = () => {
2222
return dataType.parse(this.data);
23-
}
23+
};
24+
25+
validateStrict = () => {
26+
return dataType.parse(this.data, { mode: 'strict' });
27+
};
2428
}

0 commit comments

Comments
 (0)