Skip to content

Commit

Permalink
v9.2.3 - fix preprocessed tags
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Feb 13, 2025
1 parent c5811fc commit f3f1ce4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rescript-schema",
"version": "9.2.2",
"version": "9.2.3",
"private": true,
"description": "🧬 The fastest parser in the entire JavaScript ecosystem with a focus on small bundle size and top-notch DX",
"keywords": [
Expand Down
27 changes: 27 additions & 0 deletions packages/tests/src/core/S_object_nested_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,33 @@ test("S.schema object with a deep strict applied to the nested field parent", t
t->U.assertCompiledCode(~schema, ~op=#ReverseConvert, `i=>{let v0=i["nested"];return i}`)
})

test("Nested tags on reverse convert", t => {
let schema = S.object(s => {
s.nested("nested").tag("tag", "value")
})

t->Assert.deepEqual(()->S.reverseConvertOrThrow(schema), %raw(`{"nested":{"tag":"value"}}`), ())
})

test("Nested preprocessed tags on reverse convert", t => {
let schema = S.object(s => {
let _ = s.nested("nested").field(
"tag",
S.literal("value")->S.preprocess(_ => {serializer: v => "_" ++ v->Obj.magic}),
)
let _ = s.nested("nested").field(
"intTag",
S.literal(1)->S.preprocess(_ => {serializer: v => "_" ++ v->Obj.magic}),
)
})

t->Assert.deepEqual(
()->S.reverseConvertOrThrow(schema),
%raw(`{"nested":{"tag":"_value", "intTag":"_1"}}`),
(),
)
})

test("S.schema object with a deep strict applied to the nested field parent + reverse", t => {
let schema =
S.schema(s =>
Expand Down
15 changes: 14 additions & 1 deletion packages/tests/src/core/S_preprocess_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,20 @@ test("Reverse schema to the original schema", t => {
parser: _ => 1->Int.toFloat,
serializer: _ => 1.->Int.fromFloat,
})
t->U.assertEqualSchemas(schema->S.reverse, S.unknown->S.toUnknown)
t->Assert.truthy(
switch schema->S.classify {
| Int => true
| _ => false
},
(),
)
t->Assert.truthy(
switch schema->S.reverse->S.classify {
| Int => true
| _ => false
},
(),
)
})

test("Succesfully uses reversed schema for parsing back to initial value", t => {
Expand Down
2 changes: 1 addition & 1 deletion src/S_Core.res
Original file line number Diff line number Diff line change
Expand Up @@ -2688,7 +2688,7 @@ let rec preprocess = (schema, transformer) => {
let reversed = schema.reverse()
makeReverseSchema(
~name=primitiveName,
~tagged=Unknown,
~tagged=reversed.tagged,
~builder=(b, ~input, ~selfSchema as _, ~path) => {
let input = b->B.parse(~schema=reversed, ~input, ~path)
switch transformer(b->B.effectCtx(~selfSchema=schema, ~path)) {
Expand Down
2 changes: 1 addition & 1 deletion src/S_Core.res.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ function preprocess(schema, transformer) {
}
}), undefined, (function () {
var reversed = schema["~r"]();
return makeReverseSchema(primitiveName, "unknown", empty, (function (b, input, param, path) {
return makeReverseSchema(primitiveName, reversed.t, empty, (function (b, input, param, path) {
var input$1 = reversed.b(b, input, reversed, path);
var match = transformer(effectCtx(b, schema, path));
var serializer = match.s;
Expand Down

1 comment on commit f3f1ce4

@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: f3f1ce4 Previous: a44eee7 Ratio
S.schema - make 1328079 ops/sec (±2.18%) 1354467 ops/sec (±1.69%) 1.02
S.schema - make + parse 108245 ops/sec (±0.65%) 107084 ops/sec (±0.76%) 0.99
S.schema - parse 59964469 ops/sec (±2.40%) 59295398 ops/sec (±2.15%) 0.99
S.schema - parse strict 23130882 ops/sec (±1.02%) 23128983 ops/sec (±1.08%) 1.00
S.schema - make + reverse 935630 ops/sec (±0.67%) 485145 ops/sec (±1.01%) 0.52
S.schema - make + reverse convert 175050 ops/sec (±1.12%) 153040 ops/sec (±1.04%) 0.87
S.schema - reverse convert 66226606 ops/sec (±2.50%) 67243399 ops/sec (±2.39%) 1.02
S.schema - reverse convert (compiled) 134811914 ops/sec (±4.69%) 132052574 ops/sec (±4.16%) 0.98
S.schema - assert 61623973 ops/sec (±2.01%) 63079730 ops/sec (±3.00%) 1.02
S.schema - assert (compiled) 71684370 ops/sec (±2.17%) 72857233 ops/sec (±2.59%) 1.02
S.schema - assert strict 22664297 ops/sec (±1.53%) 23133197 ops/sec (±1.07%) 1.02
S.object - make 915831 ops/sec (±0.39%) 995948 ops/sec (±0.34%) 1.09
S.object - make + parse 87570 ops/sec (±0.45%) 91218 ops/sec (±0.17%) 1.04
S.object - parse 36000641 ops/sec (±1.46%) 35466302 ops/sec (±1.60%) 0.99
S.object - make + reverse 121327 ops/sec (±1.39%) 131621 ops/sec (±1.09%) 1.08
S.object - make + reverse convert 84762 ops/sec (±1.14%) 83663 ops/sec (±0.93%) 0.99
S.object - reverse convert 46583167 ops/sec (±1.89%) 47267567 ops/sec (±1.74%) 1.01
S.string - parse 67541379 ops/sec (±2.21%) 67102209 ops/sec (±2.23%) 0.99
S.string - reverse convert 68261139 ops/sec (±2.61%) 69673135 ops/sec (±2.34%) 1.02

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

Please sign in to comment.