Creating or updating documents in Fireorm adds the id field to the actual document. Certain reserved fields in Firestore, such as exists, id, and hasPendingWrites, should not be stored within documents. The presence of these fields can trigger warnings from packages like @nandorojo/swr-firestore.
Steps to Reproduce
Create or update a document using Fireorm.
Check the stored document and observe the presence of the id field.
Use a package like @nandorojo/swr-firestore and observe warnings about reserved fields.
Expected Behavior
Firestore documents should not store reserved fields such as id, exists, and hasPendingWrites.
Actual Behavior
Firestore documents store the id field, leading to warnings and potential inconsistencies.
Acceptance Criteria
Provide an option to prevent storing the id field within documents.
Ensure reserved fields (exists, id, hasPendingWrites) are not stored in Firestore documents.
Add a warning mechanism if reserved fields are being used within documents.
Additional Context
November 12, 2020: Initial issue raised about storing reserved fields.
November 12, 2020: Discussion about the potential need to exclude reserved fields.
April 20, 2021: Comment about the need for a solution to stay consistent with documents not created with Fireorm.
May 11, 2021: Acknowledgment of the design perspective and openness to PRs that address the issue.
Proposed API Changes
Update serializeEntity Function:
Modify the serializeEntity function to exclude reserved fields from being stored in Firestore documents.
Add a configuration option to control whether the id field should be excluded from documents.
// Example configuration
initialize({ excludeReservedFields: true });
Add Warning Mechanism:
Implement a warning mechanism that alerts developers if reserved fields are detected within documents.
function checkForReservedFields(entity: any): void {
['exists', 'hasPendingWrites'].forEach(field => {
if (entity.hasOwnProperty(field)) {
console.warn(`Warning: Reserved field "${field}" detected in document.`);
}
});
}
Example Implementation
@Collection()
class User {
id: string;
display_name: string;
username: string;
}
// Initialize Fireorm with configuration to exclude reserved fields
initialize({ excludeReservedFields: true });
// Repository instance
const repo = getRepository(User);
// Create or update user document
const user = new User();
user.id = 'user123';
user.display_name = 'John Doe';
user.username = 'johndoe';
repo.create(user); // The `id` field will not be stored in the document
Description
Creating or updating documents in Fireorm adds the
id
field to the actual document. Certain reserved fields in Firestore, such asexists
,id
, andhasPendingWrites
, should not be stored within documents. The presence of these fields can trigger warnings from packages like@nandorojo/swr-firestore
.Steps to Reproduce
id
field.@nandorojo/swr-firestore
and observe warnings about reserved fields.Expected Behavior
Firestore documents should not store reserved fields such as
id
,exists
, andhasPendingWrites
.Actual Behavior
Firestore documents store the
id
field, leading to warnings and potential inconsistencies.Acceptance Criteria
id
field within documents.exists
,id
,hasPendingWrites
) are not stored in Firestore documents.Additional Context
Proposed API Changes
Update serializeEntity Function:
serializeEntity
function to exclude reserved fields from being stored in Firestore documents.Provide Configuration Option:
id
field should be excluded from documents.Add Warning Mechanism:
Example Implementation
Original Issue