Skip to content

Commit

Permalink
Js/Ts move operation to Schema methods
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Jul 6, 2024
1 parent b86ddea commit e61d4a8
Show file tree
Hide file tree
Showing 11 changed files with 957 additions and 1,103 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_NEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
- Fix serialization to JSON or JSON string for nested recursive schema
- S.jsonString doesn't fail on getting non-jsonable schema anymore. It will fail on the first serialization run instead
- When serializing to JSON or JSON string the S.union now tries to serialize other items when encounters a non-jsonable schema. Before it used to fail the whole union.
- For JS/TS users
- Move operations from functions to Schema methods
- Add `serializeToJsonOrThrow`
4 changes: 2 additions & 2 deletions packages/tests/src/benchmark/comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ new B.Suite()
});
})
.add("rescript-schema (parse)", () => {
return S.parseOrThrow(schema, data);
return schema.parseOrThrow(data);
})
.add("rescript-schema (create + parse)", () => {
const schema = S.object({
Expand All @@ -162,7 +162,7 @@ new B.Suite()
bool: S.boolean,
}),
});
return S.parseOrThrow(schema, data);
return schema.parseOrThrow(data);
})
.on("cycle", (event) => {
console.log(String(event.target));
Expand Down
12 changes: 12 additions & 0 deletions packages/tests/src/core/S_jsonString_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ test("Successfully serializes JSON object", t => {
)
})

test("Fails to serialize Option schema", t => {
let schema = S.jsonString(S.option(S.bool))
t->U.assertErrorResult(
None->S.serializeToUnknownWith(schema),
{
code: InvalidJsonStruct(S.option(S.bool)->S.toUnknown),
operation: Serializing,
path: S.Path.empty,
},
)
})

test("Successfully serializes JSON object with space", t => {
let schema = S.schema(_ =>
{
Expand Down
Loading

2 comments on commit e61d4a8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: e61d4a8 Previous: 06df40b Ratio
Parse string 818022668 ops/sec (±0.14%) 818372259 ops/sec (±0.13%) 1.00
Serialize string 819765526 ops/sec (±0.05%) 819110535 ops/sec (±0.05%) 1.00
Advanced object schema factory 453042 ops/sec (±0.51%) 449156 ops/sec (±0.56%) 0.99
Parse advanced object 51400513 ops/sec (±0.55%) 45100200 ops/sec (±0.16%) 0.88
Create and parse advanced object 91147 ops/sec (±0.86%) 35041 ops/sec (±1.18%) 0.38
Parse advanced strict object 24358408 ops/sec (±0.22%) 22748126 ops/sec (±0.24%) 0.93
Serialize advanced object 75874694 ops/sec (±0.32%) 806595235 ops/sec (±0.11%) 10.63

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: e61d4a8 Previous: 06df40b Ratio
Serialize advanced object 75874694 ops/sec (±0.32%) 806595235 ops/sec (±0.11%) 10.63

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.