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

@pagodas/typegoose

v0.0.1

Published

It's PAGODA company customized version of typegoose. Define Mongoose models using TypeScript classes.

Downloads

3

Readme

@pagodas/typegoose

This is the pagoda's customized version of typegoose.All the code is base on [email protected].

changes

change class extends Typegoose to extends Model(mongoose)

// old
class A extends Typegoose{
}

// new
import {Model} from mongoose;
class A extends Model{
}

change model create function

// old

const UserModel = new User().getModelForClass(User);

// new


const UserModel = createModelForClass(User);

use subSchema with @schemaOptions({_id:false}) define the sub class prop.

// old

class Car extends Typegoose {}
class Person{
    @prop({ _id: false })
    car?: Car;
}

// new

class Car extends Model {}
class Person extends Model{
    @prop({type:()=>Car})
    car?: Car;
}

use {ref:()=>User} and {type:()=>User} to avoid interdependence error.

// old

// file a.ts
import {B} from ./B;
export class A extends Typegoose{
    @prop({ref:B})
    b:B
}

// file b.ts
import {A} from ./A;
export class A extends Typegoose{
    @prop({ref:A})
    a:A
}

// file createModels.ts
import {A} from ./A;
const AModel = new A().getModelForClass(A);
// In this situation it will use error ref as undefined.


// new
// file a.ts
import {B} from ./B;
export class A extends Model{
    @prop({ref:()=>B})
    b:B
}

// file b.ts
import {A} from ./A;
export class A extends Typegoose{
    @prop({ref:()=>A})
    a:A
}

// file createModels.ts
import {A} from ./A;
const AModel = createModelForClass(A);
// In this situation we use function to delay the depend class use.

new features

support recursive nesting schema.

    class Box extends Model {
      @prop({ type: () => Box })
      innerBoxes: Box[]; // box nesting box
      @prop()
      name: string;
    }

support pass any prop options that mongoose support.

this is an example use the refpath to populate the different instance depend type.

class Cock extends Model {
      @prop()
      name: string;

      get legCount() {
        return 2;
      }
    }

    class Rabbit extends Model {
      @prop()
      name: string;

      get legCount() {
        return 4;
      }
    }

    @schemaOptions({ _id: false })
    class AnimalInCage extends Model {
      @prop()
      type: string; // Here,we depend the model name create by default lowerFirst.
      @prop({
        refPath: 'animals.type', type: () => Schema.Types.ObjectId,
      })
      id: Schema.Types.ObjectId | mongooseDocument<Cock> | mongooseDocument<Rabbit>;
    }

    class Cage extends Model {
      @prop({ type: () => AnimalInCage })
      animals: AnimalInCage[];
    }

    const CockModel = createModelForClass(Cock);
    const RabbitModel = createModelForClass(Rabbit);
    const CageModel = createModelForClass(Cage);
    const cockInfo = await CockModel.create({
      name: 'xiao hua',
    } as Cock);
    const rabbitInfo = await RabbitModel.create({ name: 'xiao bai' } as Rabbit);
    const cageInfo = await CageModel.create({
      animals: [
        { type: 'cock', id: cockInfo._id },
        { type: 'rabbit', id: rabbitInfo._id },
      ],
    } as Cage);
    const retCageInfo = await CageModel.findById(cageInfo._id).populate('animals.id');

support explicitly define the type

    class Tmp1 extends Model {
      @prop({ type: () => Schema.Types.ObjectId })
      commonId: Ref<Tmp1>;
    }

LICENCE

MIT