Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mayajs/mongo

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mayajs/mongo - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

9

interfaces.d.ts

@@ -20,6 +20,3 @@ /// <reference types="mongoose-paginate" />

interface MongoModelOptions {
discriminators?: Array<{
key: string;
schema: Schema;
}>;
discriminators?: DiscriminatorObject[];
}

@@ -33,2 +30,6 @@ export interface MongoInstance extends MongoInstanceProps {

}
export declare type DiscriminatorObject = {
key: string;
schema: Schema;
};
export {};
/// <reference types="mongoose-paginate" />
import { MongodbOptions, MongoInstance } from "./interfaces";
import mongoose from "mongoose";
import { Services } from "@mayajs/router";
import mongoose from "mongoose";
export declare class MongoDbServices extends Services {

@@ -12,2 +12,3 @@ private list;

mapSchemas(name: string): void;
private addDiscriminatorModel;
}

@@ -27,4 +27,4 @@ "use strict";

exports.MongoDbServices = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
const router_1 = require("@mayajs/router");
const mongoose_1 = __importDefault(require("mongoose"));
class MongoDbServices extends router_1.Services {

@@ -41,3 +41,3 @@ constructor() {

this.list[name].instance = instance;
console.log(`${name} is connected!`);
console.log(`\x1b[32m[mayajs] ${name} is connected!\x1b[0m`);
return instance;

@@ -51,4 +51,5 @@ }

set options(value) {
const { name } = value, options = __rest(value, ["name"]);
this.list[name] = Object.assign(Object.assign({}, options), { options: Object.assign({ useUnifiedTopology: true, useNewUrlParser: true, useFindAndModify: false }, options.options), instance: mongoose_1.default, models: {} });
const { name } = value, rest = __rest(value, ["name"]);
const options = Object.assign({ useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true, useFindAndModify: true }, rest.options);
this.list[name] = Object.assign(Object.assign({}, rest), { options, instance: mongoose_1.default, models: {} });
}

@@ -62,5 +63,7 @@ database(name) {

if (db.schemas && ((_a = db.schemas) === null || _a === void 0 ? void 0 : _a.length) > 0) {
db.schemas.map((_a) => {
var { name, schema } = _a, options = __rest(_a, ["name", "schema"]);
db.schemas.map(({ name, schema, options }) => {
const model = db.instance.model(name, schema);
if (options && (options === null || options === void 0 ? void 0 : options.discriminators) && (options === null || options === void 0 ? void 0 : options.discriminators.length) > 0) {
options.discriminators.map(this.addDiscriminatorModel(db, model));
}
db.models[name] = model;

@@ -70,3 +73,9 @@ });

}
addDiscriminatorModel(db, modelInstance) {
return (discriminator) => {
const model = modelInstance.discriminator(discriminator.key, discriminator.schema);
db.models[discriminator.key] = model;
};
}
}
exports.MongoDbServices = MongoDbServices;
{
"name": "@mayajs/mongo",
"version": "0.5.0",
"version": "0.5.1",
"description": "MayaJS Mongo decorators and modules",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -37,3 +37,7 @@ <p align="center"><img src="https://github.com/mayajs/maya/blob/master/maya.svg"></p>

schemas: [
User, // Add mongoose schema object
{
name: "User", // Name of model
schema: User, // Mongoose Schema
},
,
],

@@ -40,0 +44,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc