Skip to content

Commit

Permalink
Remove SerializeToJsonString operation
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Jul 7, 2024
1 parent f7f9502 commit 0930dea
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 29 deletions.
4 changes: 2 additions & 2 deletions packages/tests/src/core/S_jsonString_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test("Fails to serialize Option schema", t => {
None->S.serializeToUnknownWith(schema),
{
code: InvalidJsonStruct(S.option(S.bool)->S.toUnknown),
operation: SerializeToJsonString,
operation: SerializeToJson,
path: S.Path.empty,
},
)
Expand Down Expand Up @@ -74,7 +74,7 @@ test(
%raw(`"foo"`)->S.serializeToUnknownWith(S.jsonString(schema, ~space=2)),
{
code: InvalidJsonStruct(S.unknown),
operation: SerializeToJsonString,
operation: SerializeToJson,
path: S.Path.empty,
},
)
Expand Down
3 changes: 1 addition & 2 deletions src/S.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ type Operation =
| "Parse"
| "ParseAsync"
| "SerializeToJson"
| "SerializeToUnknown"
| "SerializeToJsonString";
| "SerializeToUnknown";

export class Error extends S_Error_class {
constructor(code: unknown, operation: Operation, path: string);
Expand Down
1 change: 0 additions & 1 deletion src/S.resi
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ and operation =
| ParseAsync
| SerializeToJson
| SerializeToUnknown
| SerializeToJsonString
and unknownKeys = Strip | Strict
type exn += private Raised(error)

Expand Down
21 changes: 7 additions & 14 deletions src/S_Core.bs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,13 @@ function effectCtx(b, selfSchema, path) {
}

function registerInvalidJson(b, selfSchema, path) {
var match = b.g.o;
switch (match) {
case "SerializeToJson" :
case "SerializeToJsonString" :
return raise(b, {
TAG: "InvalidJsonStruct",
_0: selfSchema
}, path);
default:
return ;
if (b.g.o === "SerializeToJson") {
return raise(b, {
TAG: "InvalidJsonStruct",
_0: selfSchema
}, path);
}

}

function invalidOperation(b, path, description) {
Expand Down Expand Up @@ -1696,7 +1692,7 @@ function factory$4(schema, spaceOpt) {
return val;
}), (function (b, input, param, path) {
var prevOperation = b.g.o;
b.g.o = "SerializeToJsonString";
b.g.o = "SerializeToJson";
if (schema.r.TAG === "Option") {
raise(b, {
TAG: "InvalidJsonStruct",
Expand Down Expand Up @@ -2213,9 +2209,6 @@ function message(error) {
case "SerializeToUnknown" :
operation = "serializing";
break;
case "SerializeToJsonString" :
operation = "serializing to JSON string";
break;

}
var nonEmptyPath = error.path;
Expand Down
11 changes: 2 additions & 9 deletions src/S_Core.res
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ and operation =
| ParseAsync
| SerializeToJson
| SerializeToUnknown
| SerializeToJsonString
and schema<'a> = t<'a>
and error = private {operation: operation, code: errorCode, path: Path.t}
and errorCode =
Expand Down Expand Up @@ -588,13 +587,8 @@ module Builder = {
}

let registerInvalidJson = (b, ~selfSchema, ~path) => {
switch b.global.operation {
| SerializeToJson
| SerializeToJsonString =>
if b.global.operation === SerializeToJson {
b->raise(~path, ~code=InvalidJsonStruct(selfSchema))
| Parse
| ParseAsync
| SerializeToUnknown => ()
}
}

Expand Down Expand Up @@ -2436,7 +2430,7 @@ module JsonString = {
}),
~serializeOperationBuilder=Builder.make((b, ~input, ~selfSchema as _, ~path) => {
let prevOperation = b.global.operation
b.global.operation = SerializeToJsonString
b.global.operation = SerializeToJson
if schema.rawTagged->unsafeGetVarianTag === "Option" {
b->B.raise(~code=InvalidJsonStruct(schema), ~path=Path.empty)
}
Expand Down Expand Up @@ -3169,7 +3163,6 @@ module Error = {
let operation = switch error.operation {
| SerializeToUnknown => "serializing"
| SerializeToJson => "serializing to JSON"
| SerializeToJsonString => "serializing to JSON string"
| Parse => "parsing"
| ParseAsync => "parsing async"
}
Expand Down
1 change: 0 additions & 1 deletion src/S_Core.resi
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ and operation =
| ParseAsync
| SerializeToJson
| SerializeToUnknown
| SerializeToJsonString
and unknownKeys = Strip | Strict
type exn += private Raised(error)

Expand Down

2 comments on commit 0930dea

@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: 0930dea Previous: 06df40b Ratio
Parse string 819785855 ops/sec (±0.17%) 818372259 ops/sec (±0.13%) 1.00
Serialize string 820011360 ops/sec (±0.06%) 819110535 ops/sec (±0.05%) 1.00
Advanced object schema factory 462866 ops/sec (±0.60%) 449156 ops/sec (±0.56%) 0.97
Parse advanced object 51413059 ops/sec (±1.44%) 45100200 ops/sec (±0.16%) 0.88
Create and parse advanced object 90718 ops/sec (±1.21%) 35041 ops/sec (±1.18%) 0.39
Parse advanced strict object 24367090 ops/sec (±0.23%) 22748126 ops/sec (±0.24%) 0.93
Serialize advanced object 76325957 ops/sec (±0.20%) 806595235 ops/sec (±0.11%) 10.57

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: 0930dea Previous: 06df40b Ratio
Serialize advanced object 76325957 ops/sec (±0.20%) 806595235 ops/sec (±0.11%) 10.57

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

Please sign in to comment.