Skip to content

Conversation

@shafeeqd959
Copy link
Contributor

@shafeeqd959 shafeeqd959 commented Jul 16, 2025

Add Query Filtering Support to Export Command

🎯 Overview

Adds support for a new --query flag in the cm:stacks:export command to enable filtered exports of modules using JSON query parameters.

✨ What's New

  • New --query flag: Accepts inline JSON or file path for filtering module exports
  • Flexible input: Supports both --query '{"modules": {...}}' and --query ./query.json
  • Multi-module filtering: Query multiple modules simultaneously
  • Extensible architecture: Base class method for easy module integration

🔧 Changes Made

1. Export Command Updates

  • Added hidden --query flag to src/commands/cm/stacks/export.ts - for now this will be hidden
  • Flag accepts JSON string or file path for query configuration

2. Configuration Handling

  • Updated ExportConfig interface to include optional query field
  • Enhanced export-config-handler.ts with robust JSON parsing logic
  • Supports both inline JSON and file-based queries with fallback handling

3. Base Architecture

  • Added applyQueryFilters() method to base-class.ts
  • Provides reusable query application for all module exporters
  • Merges query parameters with existing API request objects

4. Module Integration

  • Content-types: Added query filtering support
  • Global-fields: ✅ Already supported (uses applyQueryFilters)
  • Extensions: ✅ Already supported (uses applyQueryFilters)
  • Taxonomies: ✅ Already supported (uses applyQueryFilters)
  • assets: ✅ Already supported (uses applyQueryFilters)

📖 Usage Examples

Inline JSON Query

# Filter content-types by title
cm:stacks:export --query '{"modules": {"content-types": {"title": {"$in": ["Blog", "Author"]}}}}'

# Multiple modules
cm:stacks:export --query '{"modules": {"content-types": {"title": {"$regex": "^Blog"}}, "global-fields": {"data_type": "group"}}}'

File-based Query

# Using external JSON file
cm:stacks:export --query ./filters.json

Example filters.json:

{
  "modules": {
    "content-types": {
      "title": {"$in": ["Blog", "Author"]},
      "updated_at": {"$gte": "2024-01-01"}
    },
    "extensions": {
      "type": "field"
    }
  }
}

🎨 Query Structure

{
  "modules": {
    "module-name": {
      // Standard Contentstack API query parameters
      "field": {"$operator": "value"},
      "limit": 10,
      "skip": 0
    }
  }
}

✅ Supported Modules

  • content-types: Filter by title, uid, data_type, dates
  • global-fields: Filter by title, uid, data_type, dates
  • extensions: Filter by title, uid, type, dates
  • taxonomies: Filter by name, uid, dates, limit
  • assets: Filter by name, uid, dates, limit
  • 🔄 Other modules: Easily extensible using applyQueryFilters()

🛡️ Error Handling

  • Graceful fallback from file-path to inline JSON parsing
  • Clear error messages for invalid JSON syntax
  • Backward compatibility

@shafeeqd959 shafeeqd959 requested a review from Copilot July 17, 2025 12:26
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 query filtering support to the export command, allowing users to filter module exports using JSON query parameters via a new --query flag. The implementation includes both inline JSON and file-based query input methods, with robust error handling and backward compatibility.

  • Added --query flag to the export command with support for both inline JSON and file path inputs
  • Implemented query filtering infrastructure through a new applyQueryFilters method in the base class
  • Integrated query filtering across all supported modules (content-types, global-fields, extensions, taxonomies, assets)

Reviewed Changes

Copilot reviewed 26 out of 28 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/contentstack-export/src/commands/cm/stacks/export.ts Added the new hidden --query flag to the export command
packages/contentstack-export/src/utils/export-config-handler.ts Added query parsing logic for both inline JSON and file-based inputs
packages/contentstack-export/src/types/export-config.ts Extended ExportConfig interface to include query field and additional boolean flags
packages/contentstack-export/src/export/modules/base-class.ts Added applyQueryFilters method for reusable query application
packages/contentstack-export/src/export/modules/*.ts Integrated query filtering into individual module exporters
packages/contentstack-export/src/export/module-exporter.ts Added logic to conditionally skip stack settings and dependencies
packages/contentstack/package.json Version bump for the export package dependency
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

packages/contentstack-export/src/utils/export-config-handler.ts:106

  • [nitpick] The error message could be more specific about what constitutes a valid query format. Consider providing examples of valid formats in the error message.
      throw new Error(`Invalid query format: ${error.message}`);

@shafeeqd959 shafeeqd959 marked this pull request as ready for review July 18, 2025 06:55
@shafeeqd959 shafeeqd959 requested a review from a team as a code owner July 18, 2025 06:55
harshithad0703
harshithad0703 previously approved these changes Jul 21, 2025
@shafeeqd959 shafeeqd959 requested review from cs-raj and harshithad0703 and removed request for a team July 21, 2025 05:02
Copy link
Contributor

@sunil-lakshman sunil-lakshman left a comment

Choose a reason for hiding this comment

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

LGTM

@shafeeqd959 shafeeqd959 merged commit 4d964f9 into development Jul 21, 2025
10 checks passed
@shafeeqd959 shafeeqd959 deleted the feat/query-support branch July 21, 2025 11:49
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.

5 participants