@cbnsndwch/zero-sources

PipelineTableMapping interface

Home > @cbnsndwch/zero-contracts > PipelineTableMapping

PipelineTableMapping interface

Modern pipeline-based table mapping configuration.

This approach supports composable transformation stages similar to MongoDB's aggregation pipeline, enabling array unwinding, computed fields, and complex transformations.

Pipeline stages execute in array order, with projection applied last.

TTable - The target Zero table type (provides type hints for consumers)

Signature:

interface PipelineTableMapping<TTable = Dict>

Example

const mapping: TableMapping<IAccountMember> = {
    source: 'accounts',
    pipeline: [
        { $match: { bundle: 'ENTERPRISE' } },
        { $unwind: '$members' },
        { $match: { 'members.role': { $in: ['admin', 'owner'] } } }
    ],
    projection: {
        _id: { $concat: ['$_id', '_', '$members.id'] },
        accountId: '$_id',
        userId: '$members.id',
        name: '$members.name',
        role: '$members.role'
    }
};

Properties

Property

Modifiers

Type

Description

filter?

never

(Optional)

pipeline

PipelineStage<TTable>[]

Aggregation pipeline stages executed in order before projection.

Stages are processed sequentially: 1. Each stage transforms the document 2. Stages execute in array order 3. Projection applies last (if specified)

Common patterns: - Filter before unwinding for performance: [{ $match: ... }, { $unwind: ... }] - Filter unwound elements: [{ $unwind: ... }, { $match: ... }] - Add computed fields: [{ $addFields: ... }]

projection?

never

(Optional)

source

string

MongoDB collection name

How was this page?