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

xpress-mongo

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xpress-mongo - npm Package Compare versions

Comparing version 0.0.43 to 0.0.44

20

js/src/XMongoModel.js

@@ -107,5 +107,12 @@ "use strict";

emptyData(replaceWith) {
this.data = {
_id: this.id()
};
const _id = this.id();
/**
* if _id exists then add it.
*/
if (_id) {
this.data = { _id };
}
else {
this.data = {};
}
if (replaceWith && typeof replaceWith === 'object')

@@ -393,3 +400,3 @@ this.data = Object.assign(Object.assign({}, this.data), replaceWith);

if (!this.id())
throw "UPDATE_ERROR: Model does not have an _id, so we assume it is not from the database.";
throw Error("UPDATE_ERROR: Model does not have an _id, so we assume it is not from the database.");
return this.set(set).save(options);

@@ -405,3 +412,3 @@ }

if (!this.id())
throw "UPDATE_RAW_ERROR: Model does not have an _id, so we assume it is not from the database.";
throw Error("UPDATE_RAW_ERROR: Model does not have an _id, so we assume it is not from the database.");
return new Promise((resolve, reject) => {

@@ -414,5 +421,6 @@ return this.constructor.native().updateOne({ _id: this.id() }, update, options, (error, res) => error ? reject(error) : resolve(res.connection));

* @param options
* @param create
* @return {Promise<UpdateWriteOpResult | InsertOneWriteOpResult<*>>}
*/
save(options = {}) {
save(options = {}, create = false) {
return new Promise((resolve, reject) => {

@@ -419,0 +427,0 @@ const id = this.id();

{
"name": "xpress-mongo",
"version": "0.0.43",
"version": "0.0.44",
"description": "Light Weight ODM for mongoDb",

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

@@ -152,6 +152,14 @@ import ObjectCollection = require('object-collection');

emptyData(replaceWith?: StringToAnyObject): this {
this.data = {
_id: this.id()
};
const _id = this.id();
/**
* if _id exists then add it.
*/
if (_id) {
this.data = {_id};
} else {
this.data = {};
}
if (replaceWith && typeof replaceWith === 'object') this.data = {...this.data, ...replaceWith};

@@ -480,3 +488,3 @@

update(set: StringToAnyObject, options?: UpdateOneOptions): Promise<UpdateWriteOpResult> {
if (!this.id()) throw "UPDATE_ERROR: Model does not have an _id, so we assume it is not from the database.";
if (!this.id()) throw Error("UPDATE_ERROR: Model does not have an _id, so we assume it is not from the database.");
return <Promise<UpdateWriteOpResult>>this.set(set).save(options)

@@ -492,3 +500,3 @@ }

updateRaw(update: UpdateQuery<any> | Partial<any>, options?: UpdateOneOptions): Promise<UpdateWriteOpResult> {
if (!this.id()) throw "UPDATE_RAW_ERROR: Model does not have an _id, so we assume it is not from the database.";
if (!this.id()) throw Error("UPDATE_RAW_ERROR: Model does not have an _id, so we assume it is not from the database.");
return new Promise((resolve, reject) => {

@@ -506,5 +514,6 @@ return (<typeof XMongoModel>this.constructor).native().updateOne(

* @param options
* @param create
* @return {Promise<UpdateWriteOpResult | InsertOneWriteOpResult<*>>}
*/
save(options: UpdateOneOptions | CollectionInsertOneOptions = {}): Promise<boolean | UpdateWriteOpResult | InsertOneWriteOpResult<any>> {
save(options: UpdateOneOptions | CollectionInsertOneOptions = {}, create = false): Promise<boolean | UpdateWriteOpResult | InsertOneWriteOpResult<any>> {
return new Promise((resolve, reject) => {

@@ -778,3 +787,3 @@ const id = this.id();

static use(data: StringToAnyObject): XMongoModel {
const model: typeof XMongoModel | StringToAnyObject = new this();
const model: XMongoModel | any = new this();
model.emptyData();

@@ -787,4 +796,4 @@ // Set Original Property

for (const key of this.append) {
if (typeof model[key] === "function") {
model.set(key, model[key]())
if (typeof <StringToAnyObject>model[key] === "function") {
model.set(key, <StringToAnyObject>model[key]())
}

@@ -791,0 +800,0 @@ }

const connection = require('./connection');
const Chance = require('chance');
const chance = new Chance();

@@ -9,6 +7,12 @@ async function run() {

const user = await Users.findById('5e5acba088ebeef8a715ca43', {
projection: {_id: 0}
});
console.log(user);
/**
* Async Space
*/
const guest = new Users().set({
/*const guest = new Users().set({
type: 'guest',

@@ -22,3 +26,3 @@ first_name: 'Hello',

// console.log(guest.data);
console.log(guest.validate());
console.log(guest.validate());*/

@@ -25,0 +29,0 @@

@@ -200,5 +200,6 @@ import ObjectCollection = require('object-collection');

* @param options
* @param create
* @return {Promise<UpdateWriteOpResult | InsertOneWriteOpResult<*>>}
*/
save(options?: UpdateOneOptions | CollectionInsertOneOptions): Promise<boolean | UpdateWriteOpResult | InsertOneWriteOpResult<any>>;
save(options?: UpdateOneOptions | CollectionInsertOneOptions, create?: boolean): Promise<boolean | UpdateWriteOpResult | InsertOneWriteOpResult<any>>;
/**

@@ -205,0 +206,0 @@ * Unset a key or keys from this collection

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