npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wedesk/pipeline

v0.1.3

Published

The `Pipelines` package is designed to help you build and manage MongoDB aggregation pipelines with ease. This package allows you to create complex aggregation stages programmatically, making it simple to generate and update your pipeline data.

Downloads

20

Readme

Pipelines Package

The Pipelines package is designed to help you build and manage MongoDB aggregation pipelines with ease. This package allows you to create complex aggregation stages programmatically, making it simple to generate and update your pipeline data.

Installation

You can install the package via npm:

npm install @wedesk/pipeline

Usage

Importing the Package

import { Pipelines } from '@wedesk/pipeline';
import { PipelineData } from './pipeline-data';

Creating a Pipeline Instance

To create a new instance of the Pipelines class, you need to pass an array of PipelineData.

const data: PipelineData[] = [
  // Your pipeline data here
];

const pipelines = new Pipelines(data);

Updating Pipeline Data

You can update the pipeline data using the updateData method.

const newData: PipelineData[] = [
  // Your new pipeline data here
];

pipelines.updateData(newData);

Generating Aggregates

To generate the aggregation stages, use the toAggregates method.

const aggregates = pipelines.toAggregates();
console.log(aggregates);

Pipeline Data Structure

The pipeline data structure consists of several types, each representing a different aggregation stage. Below are the types of pipeline stages you can create:

Add Field

type PipelineAddFieldData = {
  key: 'addField';
  property: string;
  name: string;
  operator: OperatorType;
};

Group

type PipelineGroupData = {
  key: 'group';
  property: string;
  group: {
    field: string;
    operator: OperatorType;
    value: string;
  }[];
};

Filter

type PipelineFilterData = {
  key: 'filter';
  property: string;
  operator: OperatorType;
  value: string;
};

Formula

type PipelineFormulaData = {
  key: 'formula';
  name: string;
  property: string;
  operator: OperatorType;
};

Sort

type PipelineSortData = {
  key: 'sort';
  property: string;
  direction: 'asc' | 'desc';
};

Count

type PipelineCountData = {
  key: 'count';
};

Custom

type PipelineCustomData = {
  key: 'custom';
  pipeline: Record<string, string | number | object>;
};

Operator Types

The OperatorType defines various operators you can use in your pipeline stages. Here are the available operators:

type OperatorType =
  | 'add'
  | 'subtract'
  | 'multiply'
  | 'divide'
  | 'mod'
  | 'arrayElemAt'
  | 'concatArrays'
  | 'filter'
  | 'isArray'
  | 'size'
  | 'slice'
  | 'concat'
  | 'substr'
  | 'toLower'
  | 'toUpper'
  | 'strLenCP'
  | 'regexMatch'
  | 'and'
  | 'or'
  | 'not'
  | 'nor'
  | 'eq'
  | 'ne'
  | 'gt'
  | 'gte'
  | 'lt'
  | 'lte'
  | 'cmp'
  | 'dateFromString'
  | 'dateToString'
  | 'dayOfMonth'
  | 'dayOfWeek'
  | 'dayOfYear'
  | 'month'
  | 'year'
  | 'hour'
  | 'minute'
  | 'second'
  | 'millisecond'
  | 'isoWeek'
  | 'isoWeekYear'
  | 'convert'
  | 'toString'
  | 'toInt'
  | 'toLong'
  | 'toDouble'
  | 'toDecimal'
  | 'toBool'
  | 'toDate'
  | 'type'
  | 'literal'
  | 'mergeObjects'
  | 'cond'
  | 'ifNull'
  | 'sum'
  | 'avg'
  | 'min'
  | 'max'
  | 'push'
  | 'addToSet'
  | 'first'
  | 'last'
  | 'isNumber'
  | 'isString'
  | 'isBoolean'
  | 'isDate'
  | 'isArray'
  | 'isObject'
  | 'text'
  | 'search'
  | 'match'
  | 'group'
  | 'project'
  | 'limit'
  | 'skip'
  | 'unwind'
  | 'sort'
  | 'lookup'
  | 'graphLookup'
  | 'facet'
  | 'bucket'
  | 'bucketAuto'
  | 'count'
  | 'merge'
  | 'out'
  | 'replaceRoot'
  | 'replaceWith'
  | 'sortByCount'
  | 'redact'
  | 'sample'
  | 'indexStats'
  | 'listSessions'
  | 'listLocalSessions'
  | 'planCacheStats';

Example

Here is an example of how to use the package:

import { Pipelines } from '@wedesk/pipeline';
import { PipelineData } from './pipeline-data';

const data: PipelineData[] = [
  {
    key: 'addField',
    property: 'totalPrice',
    name: 'totalPriceWithTax',
    operator: 'multiply',
    include: true,
  },
  {
    key: 'group',
    property: 'category',
    group: [
      {
        field: 'totalSales',
        operator: 'sum',
        value: 'price',
      },
    ],
    include: true,
  },
  {
    key: 'sort',
    property: 'totalSales',
    direction: 'desc',
    include: true,
  },
];

const pipelines = new Pipelines(data);
const aggregates = pipelines.toAggregates();

console.log(JSON.stringify(aggregates, null, 2));

License

This project is licensed under the MIT License.


Feel free to customize the above README to match your specific package details, such as the package name and any additional instructions or information you want to include.