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

Open
wants to merge 10 commits into
base: master
Choose a base branch
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
5 changes: 5 additions & 0 deletions cases/aeria/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Collection } from '@aeriajs/types'

declare global {
type Collections = Record<string, Collection>
}
110 changes: 110 additions & 0 deletions cases/aeria/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { silentValidator } from '@aeriajs/validation';
import { createCase } from '../../benchmarks';

import {} from './index.d'

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;
};
});
14 changes: 14 additions & 0 deletions cases/aeria/modules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
declare module '@phosphor-icons/core' {
type PhosphorIcon = any
type IconStyle = any
}

declare module 'mongodb' {
type ObjectId = any
type Collection<_T> = any
type OptionalId<_T> = any
type WithId<_T> = any
type FilterOperators<_T> = any
type UpdateFilter<_T> = any
}

1 change: 1 addition & 0 deletions 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
Loading