firestore-typesense-search icon indicating copy to clipboard operation
firestore-typesense-search copied to clipboard

Add document transformation capability for indexing

Open tharropoulos opened this issue 10 months ago • 0 comments

TLDR

New options to transform Firestore documents before indexing to Typesense.

Change Summary

Added Configuration:

  1. In extension.yaml:
    • Added 4 new configuration parameters:
      • TRANSFORM_FUNCTION_NAME: Name of Cloud Function for document transformation
      • TRANSFORM_FUNCTION_PROJECT_ID: Project where transform function is deployed
      • TRANSFORM_FUNCTION_REGION: Region of transform function
      • TRANSFORM_FUNCTION_SECRET: Auth secret for transform function

Added Functionality:

  1. In utils.js:

    • Added transformDocument(): Calls external transform function with error handling
    • Implements fallback to original document when transformation fails
  2. In indexOnWrite.js:

    • Updated to conditionally use document transformation before indexing
    • Added branch to handle transformed vs. non-transformed document flow

Added Tests:

  1. New file test/utilsTransform.spec.js:

    • Tests for transform function with various scenarios:
      • Success path with proper transformation
      • Handling missing transform function configuration
      • Error handling for failed transformations
      • Edge cases like documents without IDs
  2. In package.json:

    • Added new test command: test:utils

PR Checklist

tharropoulos avatar Apr 14 '25 12:04 tharropoulos