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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@magnet-cms/adapter-db-mongoose

v4.0.0

Published

Mongoose database adapter for Magnet CMS

Readme

Mongoose Adapter for Magnet

This package provides a Mongoose adapter for Magnet, including internationalization support for schemas.

Internationalization

The Mongoose adapter includes built-in support for internationalization of schema properties, similar to the mongoose-intl package.

Usage

To use the internationalization feature, simply add the intl: true option to the properties that should be internationalized:

import { Prop, Schema } from '@magnet-cms/adapter-db-mongoose'

@Schema()
export class Product {
  @Prop({ required: true, intl: true })
  name!: string

  @Prop({ intl: true })
  description?: string

  @Prop({ required: true })
  price!: number
}

The schema will be automatically transformed to support multiple languages. The internationalization plugin will:

  1. Transform properties with intl: true to objects with locales as keys
  2. Add virtual getters and setters for the properties
  3. Add methods to switch between languages
  4. Ensure required fields are set in the default language

Data Structure

For each property with intl: true, the data will be stored in the following format:

{
  name: {
    en: 'Product Name in English',
    es: 'Nombre del Producto en Español',
    pt: 'Nome do Produto em Português'
  }
}

API

Model API

When working with models, you can specify the locale for queries:

// Get products with default locale
const products = await this.productModel.find();

// Get products with Spanish locale
const spanishProducts = await this.productModel.locale('es').find();

// Get a specific product with Spanish locale
const spanishProduct = await this.productModel.locale('es').findById('123');

The locale method can be chained with any query method:

// Find products with a specific query in Spanish
const spanishProducts = await this.productModel.locale('es').findMany({ price: { $gt: 100 } });

// Update a product and get the result in Spanish
const updatedProduct = await this.productModel.locale('es').update({ id: '123' }, { price: 150 });

Document API

The internationalization plugin adds the following methods to your documents:

Instance Methods
  • setLocale(locale: string): Set the locale for the current document
  • getLocale(): Get the current locale for the document
  • getAllTranslations(field: string): Get all translations for a specific field
  • setAllTranslations(field: string, translations: Record<string, any>): Set all translations for a specific field
Static Methods
  • setDefaultLocale(locale: string): Set the default locale for all documents
  • getDefaultLocale(): Get the default locale

Example

// Import the schema
import { Product } from './product'

// Create a new product
const product = new Product()
product.name = 'Product Name in English'
await product.save()

// Get the product in a different locale
const productES = await Product.findById(product.id).setLocale('es')
productES.name = 'Nombre del Producto en Español'
await productES.save()

// Get the product in the default locale
const productEN = await Product.findById(product.id)
console.log(productEN.name) // 'Product Name in English'

// Get the product in Spanish
const productES2 = await Product.findById(product.id).setLocale('es')
console.log(productES2.name) // 'Nombre del Producto en Español'

// Get all translations for a field
const allTranslations = product.getAllTranslations('name')
console.log(allTranslations)
// {
//   en: 'Product Name in English',
//   es: 'Nombre del Producto en Español'
// }

// Set all translations for a field
product.setAllTranslations('name', {
  en: 'New Product Name in English',
  es: 'Nuevo Nombre del Producto en Español',
  pt: 'Novo Nome do Produto em Português'
})
await product.save()

// Using the model API to query with a specific locale
const spanishProducts = await this.productModel.locale('es').find();
console.log(spanishProducts[0].name); // 'Nombre del Producto en Español'

Configuration

By default, the internationalization plugin uses the following configuration:

{
  locales: ['en', 'es', 'fr', 'de'],
  defaultLocale: 'en'
}

You can customize these settings by providing internationalization options in your MagnetModuleOptions:

import { MagnetModule } from '@magnet-cms/core'

@Module({
  imports: [
    MagnetModule.forRoot({
      db: { /* database config */ },
      jwt: { /* jwt config */ },
      internationalization: {
        locales: ['en', 'pt', 'es'],
        defaultLocale: 'en'
      }
    })
  ]
})
export class AppModule {}

License

MIT