New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

base-schema

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-schema

a base schema for mongoose

latest
Source
npmnpm
Version
0.3.2
Version published
Weekly downloads
14
133.33%
Maintainers
1
Weekly downloads
 
Created
Source

base-schema

Build Status

NPM

base-schema

:smile: mongoose base schema simply

functions

  • give schema append created_at updated_at and manage them
  • delete _id __v fields from output json
  • add the page method for paging

install

npm i base-schema -S

usage

const Schema = require('base-schema')
const Foo = Schema('Foo', {
    name: String
})
await Foo.create({ name: 'foo' })
await Foo.find({}).page(1, 10)

attribute

namerefdescription
Schema.ObjectIdmongoose.Schema.Types.ObjectIdA ref to mongoose.Schema.Types.ObjectId
Schema.Int32mongoose.Schema.Types.Int32A ref to mongoose-int32 module
Schema.Decimal128mongoose.Schema.Types.Decimal128A ref to mongoose.Schema.Types.Decimal128
Schema.Doublemongoose.Schema.Types.DoubleA ref to @mongoosejs/double module

default field

namerefdescription
phoneSchema.Field.phoneadd the phone and used_phones fields to Shema
passwordSchema.Field.passwordadd the password field and the compwd method to Shema
const { phone, password } = Schema.Field
const User = Schema('User', { phone: phone, password: password })
const user = await User.create({
    phone: '13812345678',
    password: '@lili520'
})
// user.phone = '13812345678'
// user.used_phones = ['13812345678']
// user.password = hash
// await user.compwd('@lili520') is true
// await User.findOne().select('+password +used_phones') 
// password and used_phones default no select

ObjectId used in the aggregation

const A = Schema('A', {
    name: String
})

const B = Schema('B', {
    name: String,
    a: {
        type: Schema.ObjectId,
        ref: 'A'
    }
})
// origin {a: new mongoose.Types.Object('5cf8e018e5fd67512487be2e')}
await B.aggregate().match({ a: Schema.Id('5cf8e018e5fd67512487be2e') })

test

npm test

FAQs

Package last updated on 12 Jun 2019

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