-
Notifications
You must be signed in to change notification settings - Fork 271
feat(typescript): refactor serialization pipeline #11049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🌱 Seed Test SelectorSelect languages to run seed tests for:
How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR. |
generators/typescript/utils/commons/src/serialization-pipeline/SerializationFormat.ts
Outdated
Show resolved
Hide resolved
|
Note that tests will fail until seed tests are regenerated. |
|
There's a lot of casting, which makes me nervous that at runtime, the result is actually different than what is typed. type _Check = z.infer<typeof UserSchema> satisfies User;This gives you a |
Description
Linear ticket: Closes FER-4068.
Note: The majority of the lines of code come from:
Problem Statement
Currently, end users are limited to adding schema serialization and validation via our own proprietary tool,
zurg. Unfortunately zurg and the code it produces suffers from performance issues, the inability to tree shake, and bundle size increases. Customers typically have to disable the option which is not ideal because they're not getting fully what they want and it will over time cause feature and api drift.Proposal
Introduce a new
SerializationPipelineandSerializationFormatabstraction to make the serialization system more extensible and unlock the ability to start targeting performance optimizations. I also propose in a future PR to movezurgto be a public npm package because it will:Changes Made
SerializationPipelineclassSerializationFormattypeSerializationFormati.e.SchemaetcHow It Works
The SDK and Express configs both now take a new config option,
serializationFormat. Users can supplyzurg,zod, ornone(equivalent ofnoSerdeLayertrue). Internally, the generator will take that format type and construct a full concrete formatter from it and use that to transform the internal Fern representation into generated ASTs. There's a fair amount of complex AST generation code happening but at the top level, it's relatively simple. There's the pipeline, the different formats, and thats about it.Future Work
This PR is already quite large and there's a lot more work that could have scoped creeped but I believe this is an excellent first step. The next objective would be:
Testing