Skip to content

Conversation

@hammo92
Copy link
Collaborator

@hammo92 hammo92 commented Dec 5, 2025

Body:

Summary

  • Handle dot-star array syntax: SurrealDB uses both field[*] and field.* syntax for array element definitions. The generator now correctly detects arrays using either syntax, fixing cases where optional arrays
    with nested object properties were missing the .array() modifier.

  • Fix NONE literals and trailing parentheses in assertions: Strip $value = NONE OR prefix since NONE is handled by .optional(). 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.

  • 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

  • All 183 existing tests pass
  • New tests added for dot-star array syntax handling
  • New tests added for NONE/NULL filtering in assertions
  • Verified optional arrays generate correct .array().optional() pattern

Copy link

Copilot AI left a 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[*] and field.* syntax patterns in field definitions
  • Added preprocessing to strip $value = NONE OR prefixes 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.

Copy link

Copilot AI commented Dec 5, 2025

@hammo92 I've opened a new pull request, #89, to work on those changes. Once the pull request is ready, I'll request review from you.

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.
Copy link

Copilot AI left a 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.

@sebastianwessel sebastianwessel merged commit 69095d6 into main Dec 21, 2025
8 checks passed
@sebastianwessel sebastianwessel deleted the fix/schema-generation-bugs branch December 21, 2025 11:53
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.

3 participants