Skip to content

New native mapper - #141

Merged
AhmadRAbuhussein merged 2 commits into
releases/r8.0from
new-native-mapper
Apr 5, 2026
Merged

New native mapper#141
AhmadRAbuhussein merged 2 commits into
releases/r8.0from
new-native-mapper

Conversation

@hamzahalq

@hamzahalq hamzahalq commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added mapper preview functionality allowing users to test mapper configurations before applying them.
    • Added ability to save and configure mapper settings for subscriptions.
  • Refactor

    • Replaced the previous JSON mapping implementation with a template-based approach for more flexible data transformations.

@coderabbitai

coderabbitai Bot commented Apr 5, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

A PR that replaces the rule-based JSON field mapper with a Scriban template-based mapper implementation. Adds mapper preview and persistence functionality, removes the deprecated field mapper, introduces a new template rendering utility, and updates dependency injection and models to support the migration.

Changes

Cohort / File(s) Summary
Mapper Preview & Persistence
SW.Bitween.Api/Resources/Mappers/Preview.cs, SW.Bitween.Api/Resources/Subscriptions/SaveMapper.cs
New command handlers for previewing mapper output and persisting mapper configurations; SaveMapper includes async custom validation of required mapper properties fetched from native adapters or serverless service.
Mapper Removal
SW.Bitween.NativeAdapters/JsonFieldMapper/*
Removed legacy rule-based JSON field mapper implementation (NativeJsonFieldMapper, JsonFieldMapperInput) and associated mapping logic.
Scriban Template Mapper
SW.Bitween.NativeAdapters/JsonMapper/NativeJSONMapper.cs, SW.Bitween.NativeAdapters/JsonMapper/JsonMapperInput.cs, SW.Bitween.NativeAdapters/JsonMapper/ScribanJsonHelper.cs
New template-based mapper using Scriban; includes template rendering utility with JSON parsing, dot-notation expansion, and trailing comma cleanup.
Infrastructure & Models
SW.Bitween.NativeAdapters/ServiceCollectionExtensions.cs, SW.Bitween.Sdk/Model/Subscription.cs, SW.Bitween.NativeAdapters/SW.Bitween.NativeAdapters.csproj
Updated DI to resolve to new NativeJSONMapper; added SubscriptionSaveMapper model; added Scriban 7.0.6 NuGet dependency.

Sequence Diagram

sequenceDiagram
    participant Client
    participant SaveMapper as SaveMapper Handler
    participant RequestContext
    participant Database as BitweenDbContext
    participant Validator as Async Validator
    participant Mapper as Native Adapter/Serverless
    participant Cache as BitweenCache
    
    Client->>SaveMapper: Handle(key, SubscriptionSaveMapper)
    SaveMapper->>RequestContext: EnsureAccess(Admin/Member)
    RequestContext-->>SaveMapper: ✓ Access granted
    SaveMapper->>Validator: Validate MapperProperties
    Validator->>Mapper: Fetch expected startup values<br/>(native or serverless)
    Mapper-->>Validator: Expected properties list
    Validator-->>SaveMapper: Validation result
    alt Validation fails
        SaveMapper-->>Client: Response with validation errors
    else Validation passes
        SaveMapper->>Database: Load Subscription by key
        Database-->>SaveMapper: Subscription entity
        SaveMapper->>Database: Update MapperId & properties
        SaveMapper->>Database: SaveChangesAsync()
        Database-->>SaveMapper: Changes persisted
        SaveMapper->>Cache: BroadcastRevoke()
        Cache-->>SaveMapper: ✓ Cache invalidated
        SaveMapper-->>Client: Response with null
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • AhmadRAbuhussein
  • mmalkhatib

Poem

🐰 From rigid rules to flexible templates we hop,
Scriban's magic makes JSON transformations stop.
Old mapper fades, new mapper springs to light,
Cache invalidates, validation shines bright,
Preview before persist—a previewful sight! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'New native mapper' accurately summarizes the main change: introducing a new NativeJSONMapper implementation alongside supporting infrastructure for Scriban-based JSON transformation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch new-native-mapper

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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