Add option to load schemas from file in generate command#160
Open
akmalmzamri wants to merge 10 commits intovercel:masterfrom
Open
Add option to load schemas from file in generate command#160akmalmzamri wants to merge 10 commits intovercel:masterfrom
akmalmzamri wants to merge 10 commits intovercel:masterfrom
Conversation
|
this is pretty great @akmalmzamri ! I am also interested in this for a project of mine, perhaps we can connect if you are also still interested in this? Can you send me a dm on twitter or an email flip[@]shareworks.nl? cheers Flip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Background
This PR will allow users to load schemas from a JSON file when running
generatecommand, hence skipping the manual data entry. This will make it easy to move from one project to another that has shared schemasSample usage
Notable changes
-f, --from-filetogeneratecommandsrc/types.d.tstosrc/utils.tsso it can be reused in schema validationbuildSchemawill process array of schemas instead of a single one. ThegenerateResourceswill process the schema array one by oneprintGenerateNextStepsfunction now process schema array. The output is updated accordinglyInput sample
Here's a sample of a valid
schema.json(basically the shape ofSchema)[ { "tableName": "products", "fields": [ { "name": "name", "type": "varchar", "notNull": true }, { "name": "price", "type": "number", "notNull": true } ], "index": "name", "belongsToUser": false, "includeTimestamps": true, "children": [] } ]Validation
This PR also comes with the necessary validation such as requiring the table name to be snakeCase. The validation is done by Zod. If errors are present in the schema, Kirimase will stop the execution and log the errors appropriately, such as
[ { "message": "Field name must be in snake_case if more than one word.", "field": "fields.0.name", "tableName": "products.product_discounts.product_discount_analytics" }, { "message": "Table name must be in snake_case if more than one word, and plural.", "field": "tableName", "tableName": "products.productReviews" } ]Note on using Zod
Since strict mode is not enabled in this project, we will not be able to fully utilize Zod, such as type inferring