Skip to content

Use rescript-schema V9 - #428

Merged
DZakh merged 2 commits into
mainfrom
dz/rescript-schema-v9
Jan 21, 2025
Merged

Use rescript-schema V9#428
DZakh merged 2 commits into
mainfrom
dz/rescript-schema-v9

Conversation

@DZakh

@DZakh DZakh commented Jan 20, 2025

Copy link
Copy Markdown
Member

No description provided.

@DZakh
DZakh requested a review from JonoPrest January 20, 2025 12:26
~shouldCopyCurrentEntity,
) => {
let row = historyRow->S.serializeOrRaiseWith(self.schema)
let row = historyRow->S.reverseConvertToJsonOrThrow(self.schema)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is reverseConvertToJsonOrThrow again?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the same as serializeOrRaiseWith but with a different name. I've written about the change here https://dev.to/dzakh/rescript-schema-v9-zod-like-library-to-the-next-level-1dn6

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok cool, I'm still trying to wrap my head around what is the convert step and why is it reversed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's convert because there's no type validation - otherwise it'd be called parse
It's reversed since we're turning 'value to Js.Json.t instead of Js.Json.t to 'value

Comment on lines +245 to +251
let parseOrThrow = S.compile(
S.array(schema),
~input=Value,
~output=Json,
~mode=Sync,
~typeValidation=true,
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Going to need to some explanations on these new features

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

// This is not super expensive, but don't want to do it on every event
| None => {
transactionSchema->Utils.Schema.removeTypeValidationInPlace
let transactionSchema = transactionSchema->S.removeTypeValidation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this now an immutable version of the function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep

@JonoPrest JonoPrest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks cool Dmitry 👍🏼, I'm going to need to wrap my head around the new API but lets go for.

@DZakh
DZakh force-pushed the dz/rescript-schema-v9 branch from 68e7968 to 7cd4458 Compare January 21, 2025 10:10
@DZakh
DZakh enabled auto-merge (squash) January 21, 2025 10:12
@DZakh
DZakh merged commit 09176e3 into main Jan 21, 2025
@DZakh
DZakh deleted the dz/rescript-schema-v9 branch January 21, 2025 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants