Skip to content

Conversation

@AbdelrahmanHafez
Copy link
Collaborator

Summary

  • Add flattenUUIDs option to toObject() and toJSON() that converts UUID instances to 36-character hex strings, similar to flattenObjectIds
  • Add TypeScript support with UUIDToString<T> type helper and method overloads
  • Rename UUIDToJSON to UUIDToString for consistency with ObjectIdToString, keeping UUIDToJSON as a deprecated alias for backwards compatibility

Fixes #15021

Copy link
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 adds a flattenUUIDs option to the toObject() and toJSON() document methods, enabling conversion of UUID instances to 36-character hex strings. This feature mirrors the existing flattenObjectIds functionality and is useful for JSON serialization scenarios where UUID objects need to be represented as strings.

Key Changes

  • Added flattenUUIDs option to ToObjectOptions interface and document transformation methods
  • Implemented UUID-to-string conversion logic in the clone helper
  • Renamed UUIDToJSON type to UUIDToString with backward-compatible alias
  • Added comprehensive tests for UUID flattening with nested objects, subdocuments, and document arrays

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
types/index.d.ts Added flattenUUIDs option to ToObjectOptions interface, implemented UUIDToString<T> type helper, and added deprecated UUIDToJSON alias
types/document.d.ts Added method overloads for toObject() and toJSON() supporting flattenUUIDs option with and without virtuals
test/types/document.test.ts Added TypeScript type tests verifying UUID-to-string conversion behavior
test/document.test.js Added comprehensive JavaScript tests covering UUID flattening in various scenarios including nested objects, subdocuments, and arrays
lib/options.js Added flattenUUIDs: false to default internal options
lib/helpers/clone.js Implemented UUID instance detection and conversion to string when flattenUUIDs option is enabled
lib/document.js Added JSDoc documentation for the new flattenUUIDs option in both toObject() and toJSON() methods

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

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.

flattenUUIDs

3 participants