LeDDGroup / typescript-transform-mongo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

typescript-transform-mongo

Conventional Commits code style: prettier

Transform typescript (or javascript) snippets to mongodb aggregation pipeline objects https://docs.mongodb.com/manual/aggregation/

Install

npm i -D typescript-transform-mongo # Soon!

Usage with ttypescript

Add it to plugins in your tsconfig.json

{
  "compilerOptions": {
    "plugins": [{ "transform": "typescript-transform-mongo" }]
  }
}

Example

declare function aggregateOp(fn: any): object;

const pipeline = [
  {
    $addFields: {
      x: aggregateOp(function (this: { y: number }) {
        return this.y + 3;
      }),
    },
  },
];

Gets compiled to:

const pipeline = [
  {
    $addFields: {
      x: { $add: ["$y", { $literal: 3 }] },
    },
  },
];

Compiling example folder

dir: https://github.com/LeDDGroup/typescript-transform-mongo/tree/master/examples

make sure to build the project first:

npm run build
cd examples
npx ttsc

Contributing

Checkout the test files under src/ for failing and pending tests. PRs and issues are welcome.

We are using jest for tests, so:

npm test            # or npx jest
npm test -- --watch # or npx jest --watch

About


Languages

Language:TypeScript 99.6%Language:JavaScript 0.4%