Skip to content

Commit

Permalink
added spectypes
Browse files Browse the repository at this point in the history
  • Loading branch information
iyegoroff authored and moltar committed Apr 21, 2022
1 parent 0e6a4ff commit 016517c
Show file tree
Hide file tree
Showing 11 changed files with 11,115 additions and 8,292 deletions.
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
46 changes: 46 additions & 0 deletions cases/spectypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
parseSafe,
parseStrict,
assertLoose,
} from '../compiled/spectypes/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;
});
7 changes: 7 additions & 0 deletions compiled/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 compiled/spectypes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
58 changes: 58 additions & 0 deletions compiled/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 compiled/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":56832003,"margin":0.38,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"bueno","ops":718405,"margin":11.46,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"class-transformer-validator-sync","ops":125722,"margin":10.9,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"io-ts","ops":3171960,"margin":0.19,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"jointz","ops":1590619,"margin":0.44,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"marshal","ops":51372217,"margin":0.24,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"runtypes","ops":265070,"margin":0.24,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"spectypes","ops":97445120,"margin":4.12,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"superstruct","ops":259970,"margin":0.14,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"suretype","ops":56285633,"margin":1.58,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"tson","ops":1084221,"margin":0.29,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"ts-interface-checker","ops":4934118,"margin":0.28,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"ts-json-validator","ops":58280641,"margin":1.32,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"@typeofweb/schema","ops":2053582,"margin":0.15,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"valita","ops":7467583,"margin":0.24,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"yup","ops":74245,"margin":0.3,"nodeVersion":"v17.9.0"},{"benchmark":"assertLoose","name":"zod","ops":203737,"margin":0.24,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"ajv","ops":21989995,"margin":0.46,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"bueno","ops":561940,"margin":16.01,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"computed-types","ops":1488555,"margin":0.24,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"decoders","ops":315488,"margin":0.15,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"jointz","ops":1532749,"margin":0.36,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"myzod","ops":3218178,"margin":0.67,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"simple-runtypes","ops":3486145,"margin":0.24,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"spectypes","ops":26965391,"margin":0.62,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"superstruct","ops":216559,"margin":0.12,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"toi","ops":1317024,"margin":0.15,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"tson","ops":1054972,"margin":0.41,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"valita","ops":6459235,"margin":0.24,"nodeVersion":"v17.9.0"},{"benchmark":"assertStrict","name":"zod","ops":207587,"margin":0.19,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"bueno","ops":407944,"margin":0.14,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"computed-types","ops":1804676,"margin":0.17,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"decoders","ops":495302,"margin":0.19,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"json-decoder","ops":1670496,"margin":0.29,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"@mojotech/json-type-validation","ops":2908509,"margin":0.18,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"myzod","ops":2580890,"margin":0.14,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"purify-ts","ops":1522695,"margin":13.14,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"rulr","ops":1356653,"margin":9.75,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"simple-runtypes","ops":3061228,"margin":0.19,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"spectypes","ops":32655331,"margin":0.83,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"tson","ops":927248,"margin":0.28,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"ts-utils","ops":456927,"margin":0.14,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"valita","ops":6667686,"margin":0.22,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"yup","ops":70557,"margin":0.15,"nodeVersion":"v17.9.0"},{"benchmark":"parseSafe","name":"zod","ops":204009,"margin":0.15,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"bueno","ops":397284,"margin":0.1,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"computed-types","ops":1455976,"margin":0.1,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"decoders","ops":303181,"margin":0.14,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"jointz","ops":3321562,"margin":0.2,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"myzod","ops":3240480,"margin":0.18,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"simple-runtypes","ops":3517193,"margin":0.34,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"spectypes","ops":26973567,"margin":0.58,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"superstruct","ops":200937,"margin":0.13,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"toi","ops":1281476,"margin":0.14,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"tson","ops":1044410,"margin":0.14,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"@typeofweb/schema","ops":1984955,"margin":2.57,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"valita","ops":6911916,"margin":0.19,"nodeVersion":"v17.9.0"},{"benchmark":"parseStrict","name":"zod","ops":208441,"margin":0.13,"nodeVersion":"v17.9.0"}]}
Loading

0 comments on commit 016517c

Please sign in to comment.