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

sendit-mongoose-repository

v2.0.9

Published

A mongoose Repository based

Downloads

50

Readme

Mongoose-Repository

A mongoose Repository based Include Plugin:

  • mongoose
  • mongoose-delete (default options: { deletedAt: true, indexFields: true, overrideMethods: true })
  • mongoose-history
  • mongoose-paginate
  • ~~mongoose-timestamp~~ Deprecated version 1.1.10 change use mongoose provide timestamps
  • mongoose-aggregate-paginate
  • rascal

install

npm install sendit-mongoose-repository --save

publish (maintainer permission required)

npm version x.y.z
git push --follow-tags

Create repo Example

bar.repository.js file

import mongoose from 'mongoose'
import RepositoryBuilder from 'sendit-mongoose-repository'

const schemaDefinition = {
  name: {
    type: String,
    require: true
  },
  foos: {
    type: [Number],
    require: true
  },
  company: { type: Mongoose.Schema.Types.ObjectId, ref: 'Company' },
}

export const builder = RepositoryBuilder('Bar', schemaDefinition)
export default builder.Repository
// builder provides:
//  {
//      Model,
//      Schema,
//      Repository,
//      schemaDefinition
//  }

BaseRepostory provides functions

.findOne(query: any, options: any)
.find(query: any = {}, options: any = {})
.create(data: any)
.update(query: any, data: any)
.upsert(query: any, data: any)
  (default options: {upsert: true, new: true})
.delete(data: any)
.aggregate(data: any)
.aggregatePaginate(query: any, options)

Usage Example

Find one

import BarRepository from './bar.repository.js'
export default async function list() {
  var filter = {
    name: 'default'
  }
  var options = {
    populate: 'company' //optional
  }
  return BarRepository.findOne(filter, options)
}

Find all

import BarRepository from './bar.repository.js'

export default async function list() {
  var filter = {
    name: 'default'
  }
  var options = {
    populate: 'company' //optional
  }
  return BarRepository.find(filter, options)
}

Find with Paginate (required options.limit and options.page)

var filter = {
  name: 'default'
}
var options = {
  limit: 10, // required
  page: 1, // required, start 1
  sort: {name: -1}, // optional, default: {_id: 1}, (ex. sort descending name)
  populate: 'company', // optional
  select: '-_id -__v -password' // optional omit _id, __v, password
}
return BarRepository.find(filter, options)

Create

await BarRepository.create({ name: 'default' })

Update

await BarRepository.update({ name: 'default' }, { foos: [12, 69] })

Delete

await BarRepository.delete({ name: 'default' })

Aggregate

import BarRepository from './bar.repository.js'

export default async function list() {
  var filter = {
    name: 'default'
  }
  var options = {
    populate: 'company' //optional
  }
  return BarRepository.find(filter, options)
}

Aggregate Paginate

var aggregateQuery = [
  { $match : { name: 'default' } },
  { $project: { foos: 1 } }
]
var options = {
  limit: 10, // required
  page: 1, // required, start 1
  sort: {name: -1}
}
return BarRepository.aggregatePaginate(filter, options)

AMQP Feature

The feature will connect to a message broker (RabbitMQ) using AMQP Protocol. When you enable this feature, it will create queues automatically from the base repository from your custom

🔥 Version 2.x.x 🔥

From version 2.x.x onward, `We deprecated the configuration environment of MONGOOSE_AMQP_PORT`. We would like to change how to connect to RabbitMQ to increase the flexibility of cluster connection, `In addition, initialize function is also deprecated`

In Additional

  • Configuration Environment

    MONGOOSE_ENABLE_AMQP=true # default false, If you want to enable setting to true
    MONGOOSE_AMQP_URI=amqp://localhost:5672//staging?heartbeat=5,amqp://localhost:5673//staging?heartbeat=5,amqp://   localhost:5674//staging?heartbeat=5
    MONGOOSE_AMQP_USERNAME=admin
    MONGOOSE_AMQP_PASSWORD=admin
    MONGOOSE_AMQP_SERVICE=users-management-api # Application Name
    MONGOOSE_AMQP_MODEL=user,address,cars # Name of Schema Model on Base Repository
    MONGOOSE_AMQP_EXCHANGE=elasticsearch.caller # Name of Exchange on RabbitMQ
  • Generate Pattern Queue Name

    Deprecated environment NODE_ENV By we use virtual hosts of RabbitMQ In case separate NODE_ENV

    # Pattern
    SERVICE_NAME.create.MODEL_NAME
    SERVICE_NAME.update.MODEL_NAME
    SERVICE_NAME.delete.MODEL_NAME
    
    # Example
    user-management-api.create.user
    user-management-api.update.user
    user-management-api.delete.user

⛔️ Version 1.x.x ⛔️

Old Version not support new cluster

  • Configuration Environment

    MONGOOSE_ENABLE_AMQP=true # default false, If you want to enable setting to true
    MONGOOSE_AMQP_URI=127.0.0.1
    MONGOOSE_AMQP_USERNAME=admin
    MONGOOSE_AMQP_PASSWORD=admin
    MONGOOSE_AMQP_SERVICE=users-management-api # Application Name
    MONGOOSE_AMQP_PORT=5672
    MONGOOSE_AMQP_MODEL=user,address,cars # Name of Schema Model on Base Repository
    MONGOOSE_AMQP_EXCHANGE=elasticsearch.caller # Name of Exchange on RabbitMQ
    MONGOOSE_AMQP_TTL=50000000000000000 #  x-message-ttl or Time-To-Live and Expiration
  • Generate Pattern Queue Name

    # Pattern
    ENV.SERVICE_NAME.create.MODEL_NAME
    ENV.SERVICE_NAME.update.MODEL_NAME
    ENV.SERVICE_NAME.delete.MODEL_NAME
    
    # Example
    staging.user-management-api.create.user
    staging.user-management-api.update.user
    staging.user-management-api.delete.user
  • Initialize Connection with RabbitMQ

    import { init } from 'sendit-mongoose-repository'
    
    init({
      exchange: 'exchange-name',
      models: ['model'],
      ttl: 50000000000000, //millisecond
      service: 'serviceName',
      vhosts: 'local',
      connection: {
        slashes: true,
        protocol: 'amqp',
        hostname: '127.0.0.1',
        user: 'guest',
        password: 'guest',
        vhost: `//local`,
        port: 5672,
        options: {
          heartbeat: 5,
        },
        socketOptions: {
          timeout: 1000,
        },
      },
    })
  • Example For cluster connections

    connections: [
            "amqp://guest:[email protected]:5672/v1?heartbeat=10",
            "amqp://guest:[email protected]:5672/v1?heartbeat=10",
            "amqp://guest:[email protected]:5672/v1?heartbeat=10"
    ]