-
Notifications
You must be signed in to change notification settings - Fork 14
Fix: schema generation bugs for arrays, assertions, and index exports #88
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes three distinct bugs in the schema generation system: handling dot-star array syntax (field.*) alongside bracket syntax (field[*]), cleaning up NONE literals and trailing parentheses in assertion processing, and ensuring the generated index file is always updated when tables are added.
Key Changes:
- Extended array detection to support both
field[*]andfield.*syntax patterns in field definitions - Added preprocessing to strip
$value = NONE ORprefixes and filter unquoted NONE/NULL from enum arrays in assertions - Changed index file generation from conditional to always regenerate to capture new table exports
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/genSchema/handleAssertions.ts | Added cleanEnumArray function to filter unquoted NONE/NULL values; updated parseComparison to extract numeric values; added NONE prefix stripping and parentheses cleanup in assertion handlers |
| src/genSchema/handleAssertions.test.ts | Added comprehensive test cases for NONE/NULL filtering, trailing parentheses handling, and enum array edge cases |
| src/genSchema/generateZodSchemaCode.ts | Extended field name patterns to detect dot-star syntax; added .* filtering in parts array; updated isArray detection to check both bracket and dot-star patterns |
| src/genSchema/generateZodSchemaCode.test.ts | Added test coverage for dot-star array syntax with various edge cases including backtick-wrapped fields and deeply nested structures |
| src/genSchema/generateTableSchema.ts | Removed conditional check to always regenerate _generated/index.ts instead of skipping when it exists |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
SurrealDB uses both bracket syntax (field[*]) and dot-star syntax (field.*) for array element definitions. The schema generator now correctly detects arrays using either syntax, fixing cases where optional arrays with nested object properties were missing the .array() modifier.
- Strip $value = NONE OR prefix from assertions since NONE is handled by .optional() rather than as a constraint value - Filter unquoted NONE/NULL from enum arrays while preserving quoted 'NONE' as valid string values - Extract only numeric portion from comparison values to handle trailing parentheses from split conditions like ($value >= 0 AND $value <= 100)
Previously the index file was only created if it didn't exist, which caused missing exports when new tables were added to the database. Now the index is always regenerated to ensure all schemas are properly exported.
- Improve backtick regex to ensure proper pairing - Update createArraySuffixRegex to handle both [*] and .* patterns - Fix misleading test name and remove inaccurate comment
- Test optional arrays with dot-star nested objects generate .array().optional() - Test optional arrays with bracket nested objects generate .array().optional() - Test optional object arrays with nested properties using dot-star syntax Note: Uses 'grants' instead of 'permissions' as field name to avoid triggering a pre-existing tokenizer bug where field names matching clause keywords are incorrectly parsed.
05c2476 to
218fd13
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Body:
Summary
Handle dot-star array syntax: SurrealDB uses both
field[*]andfield.*syntax for array element definitions. The generator now correctly detects arrays using either syntax, fixing cases where optional arrayswith nested object properties were missing the
.array()modifier.Fix NONE literals and trailing parentheses in assertions: Strip
$value = NONE ORprefix since NONE is handled by.optional(). Filter unquoted NONE/NULL from enum arrays while preserving quoted'NONE'as validstring values. Extract only numeric portion from comparison values to handle trailing parentheses.
Always regenerate
_generated/index.ts: Previously the index file was only created if it didn't exist, causing missing exports when new tables were added.Test plan
.array().optional()pattern