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

added spectypes #856

Merged
merged 5 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/node_modules
docs/dist
compiled/spectypes/build
1 change: 1 addition & 0 deletions cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import './purify-ts';
import './rulr';
import './runtypes';
import './simple-runtypes';
import './spectypes';
import './superstruct';
import './suretype';
import './toi';
Expand Down
7 changes: 7 additions & 0 deletions cases/spectypes/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": ["@babel/preset-env", "@babel/preset-typescript"],
"plugins": ["babel-plugin-spectypes"],
"targets": {
"node": 12
}
}
1 change: 1 addition & 0 deletions cases/spectypes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
42 changes: 42 additions & 0 deletions cases/spectypes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { parseSafe, parseStrict, assertLoose } from './build';
import { addCase } from '../../benchmarks';

addCase('spectypes', 'parseSafe', data => {
const parsed = parseSafe(data);

if (parsed.tag === 'failure') {
throw new Error(JSON.stringify(parsed.failure));
}

return parsed.success;
});

addCase('spectypes', 'parseStrict', data => {
const parsed = parseStrict(data);

if (parsed.tag === 'failure') {
throw new Error(JSON.stringify(parsed.failure));
}

return parsed.success;
});

addCase('spectypes', 'assertLoose', data => {
const parsed = assertLoose(data);

if (parsed.tag === 'failure') {
throw new Error(JSON.stringify(parsed.failure));
}

return true;
});

addCase('spectypes', 'assertStrict', data => {
const parsed = parseStrict(data);

if (parsed.tag === 'failure') {
throw new Error(JSON.stringify(parsed.failure));
}

return true;
});
58 changes: 58 additions & 0 deletions cases/spectypes/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
object,
number,
string,
boolean,
struct,
merge,
UNSAFE_record,
unknown,
} from 'spectypes';

export const parseStrict = object({
number,
negNumber: number,
maxNumber: number,
string,
longString: string,
boolean,
deeplyNested: object({
foo: string,
num: number,
bool: boolean,
}),
});

export const parseSafe = struct({
number,
negNumber: number,
maxNumber: number,
string,
longString: string,
boolean,
deeplyNested: struct({
foo: string,
num: number,
bool: boolean,
}),
});

export const assertLoose = merge(
object({
number,
negNumber: number,
maxNumber: number,
string,
longString: string,
boolean,
deeplyNested: merge(
object({
foo: string,
num: number,
bool: boolean,
}),
UNSAFE_record(unknown)
),
}),
UNSAFE_record(unknown)
);
10 changes: 10 additions & 0 deletions cases/spectypes/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../build",
"declaration": true,
"emitDeclarationOnly": true
},
"include": ["index.ts"]
}
2 changes: 1 addition & 1 deletion docs/results/node-17.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"results":[{"benchmark":"assertLoose","name":"ajv","ops":16906585,"margin":0.74,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"bueno","ops":287184,"margin":1.33,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"class-transformer-validator-sync","ops":49044,"margin":7.94,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"io-ts","ops":1214944,"margin":0.8,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"jointz","ops":606563,"margin":0.27,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"marshal","ops":19376493,"margin":2.26,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"runtypes","ops":103474,"margin":1.67,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"superstruct","ops":117290,"margin":1.37,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"suretype","ops":16901832,"margin":1.65,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"tson","ops":400764,"margin":0.25,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"ts-interface-checker","ops":1938767,"margin":2,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"ts-json-validator","ops":17006934,"margin":1.37,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"@typeofweb/schema","ops":777582,"margin":1.79,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"valita","ops":2895317,"margin":0.77,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"yup","ops":27823,"margin":0.27,"nodeVersion":"v17.7.2"},{"benchmark":"assertLoose","name":"zod","ops":75010,"margin":0.34,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"ajv","ops":9765029,"margin":2.71,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"bueno","ops":270552,"margin":0.95,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"computed-types","ops":584502,"margin":1.08,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"decoders","ops":123914,"margin":0.33,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"jointz","ops":596532,"margin":0.26,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"myzod","ops":1272246,"margin":2.39,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"simple-runtypes","ops":1421289,"margin":1.79,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"superstruct","ops":100849,"margin":1.51,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"toi","ops":508817,"margin":1.81,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"tson","ops":398809,"margin":0.37,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"valita","ops":1822449,"margin":1.09,"nodeVersion":"v17.7.2"},{"benchmark":"assertStrict","name":"zod","ops":78819,"margin":1.26,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"bueno","ops":145224,"margin":1.61,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"computed-types","ops":686100,"margin":0.97,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"decoders","ops":209882,"margin":0.72,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"json-decoder","ops":709496,"margin":1.06,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"@mojotech/json-type-validation","ops":1150737,"margin":1.8,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"myzod","ops":1005506,"margin":1.64,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"purify-ts","ops":656489,"margin":1.31,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"rulr","ops":493626,"margin":0.83,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"simple-runtypes","ops":1059781,"margin":1.01,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"tson","ops":371056,"margin":1.9,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"ts-utils","ops":179672,"margin":0.85,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"valita","ops":1865788,"margin":1.28,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"yup","ops":26492,"margin":2.62,"nodeVersion":"v17.7.2"},{"benchmark":"parseSafe","name":"zod","ops":76268,"margin":0.75,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"bueno","ops":141140,"margin":0.25,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"computed-types","ops":562097,"margin":1.14,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"decoders","ops":127904,"margin":1.77,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"jointz","ops":1234171,"margin":1.83,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"myzod","ops":1207949,"margin":1.51,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"simple-runtypes","ops":1366416,"margin":0.65,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"superstruct","ops":92224,"margin":0.41,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"toi","ops":512974,"margin":2.02,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"tson","ops":395006,"margin":0.97,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"@typeofweb/schema","ops":755497,"margin":1.43,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"valita","ops":1853495,"margin":1.16,"nodeVersion":"v17.7.2"},{"benchmark":"parseStrict","name":"zod","ops":73029,"margin":0.47,"nodeVersion":"v17.7.2"}]}
{"results":[{"benchmark":"assertLoose","name":"ajv","ops":57384838,"margin":1.2,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"bueno","ops":793051,"margin":0.47,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"class-transformer-validator-sync","ops":144728,"margin":0.39,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"io-ts","ops":3283405,"margin":0.28,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"jointz","ops":1654378,"margin":0.12,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"marshal","ops":52299920,"margin":0.34,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"runtypes","ops":263966,"margin":0.41,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"spectypes","ops":92718958,"margin":3.24,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"superstruct","ops":256340,"margin":1.58,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"suretype","ops":58835450,"margin":0.87,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"tson","ops":1110204,"margin":0.17,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"ts-interface-checker","ops":4925304,"margin":0.37,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"ts-json-validator","ops":58885292,"margin":1.17,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"@typeofweb/schema","ops":2094010,"margin":0.29,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"valita","ops":6182730,"margin":10.89,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"yup","ops":69888,"margin":1.34,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"zod","ops":190964,"margin":1.3,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"ajv","ops":20893132,"margin":1.17,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"bueno","ops":569606,"margin":14.94,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"computed-types","ops":1446367,"margin":4.67,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"decoders","ops":315106,"margin":0.26,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"jointz","ops":1563827,"margin":0.34,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"myzod","ops":3287794,"margin":0.26,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"simple-runtypes","ops":3562750,"margin":0.13,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"spectypes","ops":27412995,"margin":0.5,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"superstruct","ops":213262,"margin":0.33,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"toi","ops":1316120,"margin":0.18,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"tson","ops":1083331,"margin":0.18,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"valita","ops":6390136,"margin":0.24,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"zod","ops":207860,"margin":0.13,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"bueno","ops":410735,"margin":0.12,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"computed-types","ops":1818314,"margin":0.14,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"decoders","ops":460105,"margin":10.57,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"json-decoder","ops":1517999,"margin":10.72,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"@mojotech/json-type-validation","ops":2896284,"margin":0.1,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"myzod","ops":2573882,"margin":0.28,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"purify-ts","ops":1650719,"margin":0.66,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"rulr","ops":1321334,"margin":13.09,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"simple-runtypes","ops":2845237,"margin":7.78,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"spectypes","ops":32809094,"margin":0.67,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"tson","ops":929726,"margin":0.37,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"ts-utils","ops":448574,"margin":0.36,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"valita","ops":6271387,"margin":0.79,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"yup","ops":70685,"margin":0.15,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"zod","ops":204731,"margin":0.18,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"bueno","ops":398340,"margin":0.09,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"computed-types","ops":1423977,"margin":1.56,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"decoders","ops":275701,"margin":12.69,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"jointz","ops":2968583,"margin":13.09,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"myzod","ops":3232897,"margin":0.18,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"simple-runtypes","ops":3498223,"margin":0.32,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"spectypes","ops":27065101,"margin":0.6,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"superstruct","ops":198506,"margin":0.43,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"toi","ops":1269103,"margin":0.28,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"tson","ops":1049672,"margin":0.21,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"@typeofweb/schema","ops":2000805,"margin":0.19,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"valita","ops":6367170,"margin":0.26,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"zod","ops":200211,"margin":3.86,"nodeVersion":"v17.9.0"}]}
Loading