Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add aeria #1218

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

## Packages Compared

* [aeria](https://github.com/aeria-org/aeria)
* [ajv](https://ajv.js.org/)
* [ArkType](https://github.com/arktypeio/arktype)
* [bueno](https://github.com/philipnilsson/bueno)
Expand Down
108 changes: 108 additions & 0 deletions cases/aeria.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { silentValidator } from '@aeriajs/validation';
import { createCase } from '../benchmarks';

const schema = <const>{
type: 'object',
properties: {
number: {
type: 'number',
},
negNumber: {
type: 'number',
},
maxNumber: {
type: 'number',
},
string: {
type: 'string',
},
longString: {
type: 'string',
},
boolean: {
type: 'boolean',
},
deeplyNested: {
type: 'object',
properties: {
foo: {
type: 'string',
},
num: {
type: 'number',
},
bool: {
type: 'boolean',
},
},
required: ['foo', 'num', 'bool'],
},
},
required: [
'number',
'negNumber',
'maxNumber',
'string',
'longString',
'boolean',
'deeplyNested',
],
};

createCase('aeria', 'parseSafe', () => {
const [_, validate] = silentValidator(schema, {
extraneous: true,
filterOutExtraneous: true,
coerce: true,
});

return (data: any) => {
const result = validate(data);
if (!result) {
throw new Error();
}

return result;
};
});

createCase('aeria', 'parseStrict', () => {
const [_, validate] = silentValidator(schema, {
coerce: true,
});

return (data: any) => {
const result = validate(data);
if (!result) {
throw new Error();
}

return result;
};
});

createCase('aeria', 'assertLoose', () => {
const [_, validate] = silentValidator(schema, {
extraneous: true,
});

return (data: any) => {
if (!validate(data)) {
throw new Error();
}

return true;
};
});

createCase('aeria', 'assertStrict', () => {
const [_, validate] = silentValidator(schema);

return (data: any) => {
if (!validate(data)) {
throw new Error();
}

return true;
};
});
3 changes: 2 additions & 1 deletion cases/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const cases = [
'aeria',
'ajv',
'arktype',
'bueno',
Expand Down Expand Up @@ -45,7 +46,7 @@ export const cases = [
'deepkit',
] as const;

export type CaseName = typeof cases[number];
export type CaseName = (typeof cases)[number];

export async function importCase(caseName: CaseName) {
await import('./' + caseName);
Expand Down
Loading
Loading