Skip to content

LeDDGroup/typescript-transform-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published