
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Monjoi - A lightweight alternative to Mongoose.
npm i monjoi
# or with Yarn
yarn add monjoi
* Monjoi has peer dependencies on Joi and node mongodb driver.
// person.model.ts
import Joi from 'joi'
import { collection } from 'monjoi'
export type Person = {
name: string
age?: number
}
const PersonSchema = Joi.object<Person>({
name: Joi.string().required(),
age: Joi.number()
})
// Person - Data Access Object
export const PersonDAO = collection('person', PersonSchema)
// TODO: Example needed
// person.service.ts
import { Person, PersonDAO } from './person.model.ts'
class PersonService {
constructor(
// Dependency Injected `personDAO`
private personDAO: PersonDAO
) {}
public async createPerson(person: Person): Promise<Person> {
// Automatically validates `person` against Joi schema
// and returns the newly inserted mongo document with _id
return this.personDAO.insertOne(person)
}
}
There are 2 types of hooks available:
Hooks can return regular values or even Promises.
Useful for triggering other operations before accessing the db. If a hook returns a rejected promise, then the main db operation will not execute, neither will the Post hooks.
Useful for formatting db responses or triggering other operations. Post hooks should generally return objects because they will be passed to the next hook.
Any hook that returns a rejected promise will cancel the hook chain.
Hooks are declared when defining your DAO. You can hook into any standard mongodb collection operation.
export const PersonDAO = collection('person', PersonSchema, {
insertOne: {
pre: [
() => console.log('I will run before any insertOne operation for person collection'),
() => console.log('me too!')
],
post: [
(insertedDoc) => {
console.log(`Document ${insertedDoc._id} created!`)
return insertedDoc // <-- Don't forget to return objects from post hooks
},
(insertedDoc) => {
// formatting example, removing mongo __v field
return omit(insertedDoc, ['__v'])
}
]
}
})
FAQs
MongoDB + Joi
The npm package monjoi receives a total of 2 weekly downloads. As such, monjoi popularity was classified as not popular.
We found that monjoi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.