Skip to content

fix/tschema field order#66

Merged
solidsnakedev merged 3 commits into
mainfrom
fix/tschema-field-order
Nov 21, 2025
Merged

fix/tschema field order#66
solidsnakedev merged 3 commits into
mainfrom
fix/tschema-field-order

Conversation

@solidsnakedev
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings November 21, 2025 20:00
Copy link
Copy Markdown
Contributor

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 a field ordering bug in the TSchema.Struct encode function that caused fields to be incorrectly ordered during CBOR encoding when using NullOr/UndefinedOr wrappers. The fix ensures that field order matches the schema definition order by using Object.keys(fields) instead of iterating over the encoded struct's properties.

Key Changes:

  • Fixed field ordering in Struct encode function by using schema definition order (Object.keys(fields)) instead of runtime object order
  • Added regression test to verify field order preservation with NullOr fields
  • Converted Struct and Variant from function declarations to arrow function expressions

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/evolution/src/core/TSchema.ts Core fix to preserve field order in Struct encoding; converted Struct and Variant to arrow functions
packages/evolution/test/TSchema.test.ts Added regression test for field ordering with NullOr fields
packages/evolution/docs/modules/core/TSchema.ts.md Updated type signatures for Struct and Variant to reflect arrow function syntax
docs/content/docs/modules/core/TSchema.mdx Updated Variant type signature to match source code changes
docs/next-env.d.ts Auto-generated Next.js file that should not be committed (in .gitignore)
.changeset/chilly-brooms-end.md Documented the bug fix with before/after examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/evolution/src/core/TSchema.ts Outdated
const fieldEntries = Object.entries(encodedStruct).filter(([key]) => key !== detectedTagField)
const fieldValues = fieldEntries.map(([_, value]) => value) as ReadonlyArray<Data.Data>
// Use Object.keys(fields) to preserve schema definition order
// (Object.entries doesn't guarantee property order)
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is technically inaccurate. Since ES2015, Object.entries() does guarantee property order for string keys (insertion order is preserved). The real issue is that you need to ensure the order comes from the schema definition (fields) rather than the runtime object (encodedStruct). Consider revising to: "Use Object.keys(fields) to preserve schema definition order"

Suggested change
// (Object.entries doesn't guarantee property order)
// (Preserve the order as defined in the schema, not the runtime object)

Copilot uses AI. Check for mistakes.
@solidsnakedev solidsnakedev merged commit 537aff1 into main Nov 21, 2025
4 checks passed
@solidsnakedev solidsnakedev deleted the fix/tschema-field-order branch November 21, 2025 20:07
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.

2 participants