🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

manggis

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

manggis

Mongoose schema and ref integrity validator

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

manggis

Mongoose schema and ref integrity validator

Motivation: create simple tool to validate mongoose schema and references integrity

How it works: It takes a mongoose connection instance from your code and interate thru each model and each document using async iterable interface provided by mongoose. Due to limitations of mongoose api, it will create custom model clone if verifyRefs option set to true to avoid mutating original model. This models will be automatically deleted later.

Additional features:

  • No external dependencies except mongoose as a peer dependency
  • Simple programmatic API allowing you to create any logging or data processing
  • Typescript typings

Installation

npm i -S manggis

Example (Typescript)

import { Connection } from 'mongoose';
import { validate } from 'manggis'

async function main() {
  /* !!! place your mongoose connection instance here !!! */
  const connection: Connection = {} as Connection

  await validate(connection, {
    onError: ({ model, path, message }) => {
      console.log(`    error [${model}.${path}]: ${message}`)
    },
    onModel(model) {
      console.log('validating model:', model.modelName);
    },
    onDocument(doc) {
      console.log('  validating document:', doc._id);
    }
  });

  console.log('all models has been verified');
  process.exit();
}

if (require.main === module) {
  main()
}

Contributions

Feel free to send PR's or suggest new features in Issues.

Keywords

mongoose

FAQs

Package last updated on 13 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts