A few refactors #1
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Generate a function to provide value for fields using
auth()in@defaultso we don't need to evaluate at runtimeE.g., for model:
The following function is generated to facilitate the runtime evaluation:
I think this approach will allow more flexibility in the future, e.g., we may allow calling other functions over
auth()inside the@default(). The existingTypeScriptExpressionTransformerclass is used to generate the function body. The file needed to be moved to the "@zenstackhq/sdk" package to be accessible. Many other updates in the PR are moving helper functions around too.Correct the way of visiting nested create payload
The
NestedWriteVisistoris meant to do in-place updates to the payload. I've changed that part of logic, and also added thecreateManyhook.Removed logic that turns direct
auth()usage in@default()into stringified textI haven't thought about a real-world case this would be useful. Please let me know if you have one in your mind. If we would to support that, the ZModel validation part also needs to be adjusted to allow the type compatibility.