Skip to content
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

feat(utils): implement nested field extraction #91

Merged
merged 8 commits into from
Oct 14, 2024

Conversation

tharropoulos
Copy link
Collaborator

What is this?

This pull request enhances our Firestore to Typesense synchronization by adding support for nested field extraction. It allows users to specify nested fields using dot notation, making it easier to sync complex data structures from Firestore to Typesense.

Rationale

This change resolves issue #90, which requests dot notation support for the "Firestore Collection Fields" parameter. By implementing this feature, we enable users to access any level property on fields they want to explicitly include in the trigger.

Changes

Added Features:

  1. New dependency in functions/package.json:
    • Added lodash.get (version 4.4.2) for safe nested property access.

Code Changes:

  1. In functions/src/utils.js:
    • Imported lodash.get for nested field extraction.
    • Refactored typesenseDocumentFromSnapshot function to use lodash.get for accessing nested fields.
    • Updated field extraction logic to support dot notation for nested fields.

Test Updates:

  1. In test/utils.spec.js:
    • Added new test suite "Nested fields extraction" with four new test cases:
      • Extracting nested fields using dot notation
      • Handling missing nested fields gracefully
      • Extracting nested fields alongside top-level fields
      • Handling array indexing in dot notation

Context

This change improves the flexibility of our Firestore to Typesense synchronization extension. Users can now easily map nested Firestore fields to Typesense, allowing for more complex data structures to be indexed and searched efficiently. This feature is particularly useful for projects with deeply nested document structures, enabling fine-grained control over which specific nested fields are synchronized to Typesense.

PR Checklist

- Simplify field extraction in `typesenseDocumentFromSnapshot` by
utilizing lodash.get for safe property access.
- Remove redundant filtering of entries and streamline the mapping process
for improved clarity and efficiency.
- Expand test coverage for `typesenseDocumentFromSnapshot` function to
include scenarios with nested fields, dot notation, missing fields,
and array indexing.
- Ensure proper extraction of complex data structures from Firestore documents.
test/utils.spec.js Show resolved Hide resolved
- Replace external 'flat' library with a custom flattenDocument function
for improved control over nested object and array handling in Typesense
document preparation.
- Implement custom nested value handling functions to replace lodash.get.
- Add support for array fields and improve object flattening.
- Refactor test case for nested arrays inside fields, to more properly
match real world cases
- Rename spec files that include test cases with flattening to reflect
that
@jasonbosco jasonbosco merged commit 0fadc7f into typesense:master Oct 14, 2024
2 checks passed
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