UNPKG

@drip_sync/drip

Version:

Scalable incremental sync for MongoDB aggregation pipelines

48 lines (47 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parsePipeline = parsePipeline; const invalid_stage_1 = require("./invalid_stage"); function parseStage(s) { const keys = Object.keys(s); if (keys.length !== 1) { throw new invalid_stage_1.InvalidStage("A pipeline stage specification object must contain exactly one field."); } if ("$replaceRoot" in s) { return { type: "replaceRoot", newRoot: s.$replaceRoot.newRoot, }; } if ("$replaceWith" in s) { return { type: "replaceWith", expr: s.$replaceWith, }; } if ("$addFields" in s) { return { type: "addFields", fields: s.$addFields, }; } if ("$project" in s) { return { type: "project", fields: s.$project, }; } if ("$set" in s) { return { type: "set", fields: s.$set, }; } if ("$match" in s) { return { type: "match", filter: s.$match }; } return { type: "unset", fields: s.$unset }; } function parsePipeline(pipeline) { return pipeline.map(parseStage); }