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

infer-mongoose-schema

v0.0.5

Published

Enables automatic generation of Mongoose schemas from sample objects

Downloads

7

Readme

Installation

npm install --save infer-mongoose-schema

or

yarn add infer-mongoose-schema

Purpose

To enable generation of Mongoose Schema based on an object, array of objects, class, or function.

This is an early alpha version released for a specific use case in another repository. Highly recommend waiting until v 1.0.0 to install. Currently only object inference is implemented.

Roadmap

0.0.x

Building out & refining object inference.

Provide a sample object to inferSchema, along with an optional 'options' config object, and a valid mongoose schema will automatically be generated from the object. This helps reduce redundant code. Ideally, a project will have a central data model with the ability to generate sample objects of each entity (useful for unit testing), this sample object (or, eventually its class constructor) can then be used to generate a schema for mongoose.

This is an early alpha version released for a specific use case in another repository. Highly recommend waiting until v 1.0.0 to install. Currently only object inference is implemented.

1.0.0

Will add the ability to infer schema based on a class constructor function. Caveat: this package can only be successfully consumed by TypeScript projects compiling to ES6/ES2015.

1.1.0

Will add the ability to infer schema based on an array of sample objects. For example, if a project contains a type of entity that has many optional properties, both a 'full' and a 'minimal' version of the entity can be provided to inferSchema and the fact that certain properties are optional will be interpreted from that input.

1.2.0

Will add the ability to infer schema based on a function that generates an object of the intended entity type. Useful for certain dependency injection use cases.

Example

// User.js
import mongoose, { Schema } from mongoose;
import inferSchema from infer-mongoose-schema;

const SampleUser = {
  firstName: "John",
  lastName: "Smith",
  nickNames: ["JJ", "Smithy"],
  subscriptionTier: 1
}

const options = {
  defaultValues: {
    subscriptionTier: 0
  },
  stronglyTypeArrays: true
}

const userSchema = inferSchema(SampleUser, options)

export default mongoose.model('User', userSchema)