Skip to content

Commit

Permalink
Merge pull request #1271 from DZakh-forks/rescript-schema-v8
Browse files Browse the repository at this point in the history
Update rescript-schema up to V8
  • Loading branch information
hoeck authored Jul 19, 2024
2 parents 705c43f + 7949759 commit 4feb0ad
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 72 deletions.
79 changes: 25 additions & 54 deletions cases/rescript-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as S from 'rescript-schema';

import { createCase } from '../benchmarks';

createCase('rescript-schema', 'parseSafe', () => {
const schema = S.object({
const makeSchema = () =>
S.object({
number: S.number,
negNumber: S.number,
maxNumber: S.number,
Expand All @@ -17,79 +17,50 @@ createCase('rescript-schema', 'parseSafe', () => {
}),
});

createCase('rescript-schema', 'parseSafe', () => {
S.setGlobalConfig({
disableNanNumberCheck: true,
});
const schema = makeSchema();

return data => {
return S.parseOrThrow(schema, data);
return schema.parseOrThrow(data);
};
});

createCase('rescript-schema', 'parseStrict', () => {
const schema = S.Object.strict(
S.object({
number: S.number,
negNumber: S.number,
maxNumber: S.number,
string: S.string,
longString: S.string,
boolean: S.boolean,
deeplyNested: S.Object.strict(
S.object({
foo: S.string,
num: S.number,
bool: S.boolean,
})
),
})
);
S.setGlobalConfig({
disableNanNumberCheck: true,
defaultUnknownKeys: 'Strict',
});
const schema = makeSchema();

return data => {
return S.parseOrThrow(schema, data);
return schema.parseOrThrow(data);
};
});

createCase('rescript-schema', 'assertLoose', () => {
const schema = S.object({
number: S.number,
negNumber: S.number,
maxNumber: S.number,
string: S.string,
longString: S.string,
boolean: S.boolean,
deeplyNested: S.object({
foo: S.string,
num: S.number,
bool: S.boolean,
}),
S.setGlobalConfig({
disableNanNumberCheck: true,
});
const schema = makeSchema();

return data => {
S.parseOrThrow(schema, data);

schema.assert(data)!;
return true;
};
});

createCase('rescript-schema', 'assertStrict', () => {
const schema = S.Object.strict(
S.object({
number: S.number,
negNumber: S.number,
maxNumber: S.number,
string: S.string,
longString: S.string,
boolean: S.boolean,
deeplyNested: S.Object.strict(
S.object({
foo: S.string,
num: S.number,
bool: S.boolean,
})
),
})
);
S.setGlobalConfig({
disableNanNumberCheck: true,
defaultUnknownKeys: 'Strict',
});
const schema = makeSchema();

return data => {
S.parseOrThrow(schema, data);

schema.assert(data)!;
return true;
};
});
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@
"jointz": "7.0.4",
"json-decoder": "1.4.1",
"mol_data_all": "1.1.1123",
"@mondrian-framework/model": "2.0.43",
"myzod": "1.11.0",
"ok-computer": "1.0.4",
"parse-dont-validate": "4.0.0",
"preact": "10.22.0",
"purify-ts": "2.0.3",
"r-assign": "1.9.0",
"reflect-metadata": "0.2.2",
"rescript": "11.0.0-rc.6",
"rescript-schema": "6.1.0",
"rescript": "11.1.2",
"rescript-schema": "8.0.0",
"rulr": "8.7.6",
"runtypes": "6.7.0",
"serve": "14.2.3",
Expand Down

0 comments on commit 4feb0ad

Please sign in to comment.