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.40 to 0.0.41

23

js/src/XMongoClient.js

@@ -71,3 +71,2 @@ "use strict";

model(collection) {
var _a;
const connection = this.collection(collection);

@@ -77,8 +76,22 @@ /**

*/
return _a = class extends XMongoModel {
},
_a.thisCollection = () => connection,
_a;
return class extends XMongoModel {
/**
* Use `.native()` instead
* @deprecated (v 0.0.40)
*/
static thisCollection() {
console.error('Model.thisCollection() is deprecated, use .native() instead.');
return connection;
}
;
/**
* Returns native mongodb instance to run native queries
*/
static native() {
return connection;
}
;
};
}
}
module.exports = XMongoClient;

@@ -84,3 +84,6 @@ "use strict";

}
// @ts-ignore
/**
* Use `.native()` instead
* @deprecated (v 0.0.40)
*/
static thisCollection() {

@@ -92,2 +95,10 @@ // @ts-ignore

/**
* Returns native mongodb instance to run native queries
*/
static native() {
// @ts-ignore
return null;
}
;
/**
* Empties data in current model.

@@ -396,3 +407,3 @@ * @param replaceWith

return new Promise((resolve, reject) => {
return this.constructor.thisCollection().updateOne({ _id: this.id() }, update, options, (error, res) => error ? reject(error) : resolve(res.connection));
return this.constructor.native().updateOne({ _id: this.id() }, update, options, (error, res) => error ? reject(error) : resolve(res.connection));
});

@@ -419,3 +430,3 @@ }

}
return this.constructor.thisCollection().updateOne({ _id: this.id() }, { $set }, options, (error, res) => error ? reject(error) : resolve(res.connection));
return this.constructor.native().updateOne({ _id: this.id() }, { $set }, options, (error, res) => error ? reject(error) : resolve(res.connection));
}

@@ -430,3 +441,3 @@ else {

}
return this.constructor.thisCollection().insertOne(this.data, options, (error, res) => {
return this.constructor.native().insertOne(this.data, options, (error, res) => {
if (error)

@@ -465,3 +476,3 @@ return reject(error);

return new Promise((resolve, reject) => {
return this.constructor.thisCollection().updateOne({ _id: this.id() }, { $unset }, options, (error, res) => {
return this.constructor.native().updateOne({ _id: this.id() }, { $unset }, options, (error, res) => {
if (error)

@@ -606,3 +617,3 @@ return reject(error);

this.emptyData();
return this.constructor.thisCollection().deleteOne({ _id });
return this.constructor.native().deleteOne({ _id });
}

@@ -699,3 +710,3 @@ else {

model = model[0]();
let relatedData = yield model.thisCollection().findOne(where, options);
let relatedData = yield model.native().findOne(where, options);
if (cast && relatedData)

@@ -721,2 +732,3 @@ relatedData = model.use(relatedData);

/**
* toJSON converter.
* @private

@@ -767,3 +779,3 @@ * @return {*}

static find(query = {}, options = {}, raw = false) {
const result = this.thisCollection().find(query, options);
const result = this.native().find(query, options);
if (raw)

@@ -791,3 +803,3 @@ return result;

return new Promise((resolve, reject) => {
return this.thisCollection().findOne(query, options, (error, data) => {
return this.native().findOne(query, options, (error, data) => {
if (error)

@@ -828,3 +840,3 @@ return reject(error);

static count(query = {}, options) {
return this.thisCollection().find(query, options).count();
return this.native().find(query, options).count();
}

@@ -869,3 +881,3 @@ /**

}
let result = yield this.thisCollection().aggregate([
let result = yield this.native().aggregate([
{ $match: match },

@@ -893,3 +905,3 @@ { $group }

query.push({ $count: "count_aggregate" });
const data = yield this.thisCollection().aggregate(query, options).toArray();
const data = yield this.native().aggregate(query, options).toArray();
if (data.length) {

@@ -916,3 +928,3 @@ return data[0]['count_aggregate'];

const skips = perPage * (page - 1);
const data = yield this.thisCollection().find(query, options).skip(skips).limit(perPage).toArray();
const data = yield this.native().find(query, options).skip(skips).limit(perPage).toArray();
return {

@@ -945,3 +957,3 @@ total,

query.push({ $limit: perPage });
const data = yield this.thisCollection().aggregate(query, options).toArray();
const data = yield this.native().aggregate(query, options).toArray();
return {

@@ -972,3 +984,3 @@ total,

*
* Model.thisCollection().find().limit(10).toArray((err, lists) => {
* Model.native().find().limit(10).toArray((err, lists) => {
* Model.fromArray(lists);

@@ -988,3 +1000,3 @@ * })

return new Promise((resolve, reject) => {
return query(this.thisCollection()).toArray((error, lists) => {
return query(this.native()).toArray((error, lists) => {
if (error)

@@ -1019,3 +1031,3 @@ return reject(error);

return reject(Error('.toArray expects a function as argument'));
query(this.thisCollection()).toArray((error, data) => {
query(this.native()).toArray((error, data) => {
if (error)

@@ -1022,0 +1034,0 @@ return reject(error);

{
"name": "xpress-mongo",
"version": "0.0.40",
"version": "0.0.41",
"description": "Light Weight ODM for mongoDb",

@@ -28,12 +28,12 @@ "main": "js/index.js",

"deep-object-diff": "^1.1.0",
"mongodb": "^3.5.9",
"object-collection": "^1.0.25",
"typescript": "^3.9.5"
"mongodb": "^3.6.2",
"object-collection": "^1.0.29",
"typescript": "^4.0.3"
},
"devDependencies": {
"@types/lodash": "^4.14.155",
"@types/mongodb": "^3.5.22",
"@types/node": "^14.0.13",
"chance": "^1.1.6"
"@types/lodash": "^4.14.161",
"@types/mongodb": "^3.5.27",
"@types/node": "^14.11.2",
"chance": "^1.1.7"
}
}

@@ -96,3 +96,17 @@ import XMongoModel = require('./XMongoModel');

return <typeof XMongoModel><unknown>class extends XMongoModel {
static thisCollection = () => connection;
/**
* Use `.native()` instead
* @deprecated (v 0.0.40)
*/
static thisCollection(): Collection {
console.error('Model.thisCollection() is deprecated, use .native() instead.')
return connection;
};
/**
* Returns native mongodb instance to run native queries
*/
static native(): Collection {
return connection;
};
}

@@ -99,0 +113,0 @@ }

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

CollectionInsertOneOptions,
CollectionAggregationOptions, AggregationCursor, UpdateQuery
CollectionAggregationOptions, AggregationCursor, UpdateQuery, FilterQuery
} from 'mongodb';

@@ -130,3 +130,6 @@

// @ts-ignore
/**
* Use `.native()` instead
* @deprecated (v 0.0.40)
*/
static thisCollection(): Collection {

@@ -138,2 +141,10 @@ // @ts-ignore

/**
* Returns native mongodb instance to run native queries
*/
static native(): Collection {
// @ts-ignore
return null;
};
/**
* Empties data in current model.

@@ -484,3 +495,3 @@ * @param replaceWith

return new Promise((resolve, reject) => {
return (<typeof XMongoModel>this.constructor).thisCollection().updateOne(
return (<typeof XMongoModel>this.constructor).native().updateOne(
{_id: this.id()},

@@ -514,3 +525,3 @@ update,

return (<typeof XMongoModel>this.constructor).thisCollection().updateOne(
return (<typeof XMongoModel>this.constructor).native().updateOne(
{_id: this.id()},

@@ -528,3 +539,3 @@ {$set},

return (<typeof XMongoModel>this.constructor).thisCollection().insertOne(
return (<typeof XMongoModel>this.constructor).native().insertOne(
this.data,

@@ -573,3 +584,3 @@ <CollectionInsertOneOptions>options,

return new Promise((resolve, reject) => {
return (<typeof XMongoModel>this.constructor).thisCollection().updateOne(
return (<typeof XMongoModel>this.constructor).native().updateOne(
{_id: this.id()},

@@ -741,3 +752,3 @@ {$unset},

this.emptyData();
return (<typeof XMongoModel>this.constructor).thisCollection().deleteOne({_id})
return (<typeof XMongoModel>this.constructor).native().deleteOne({_id})
} else {

@@ -847,3 +858,3 @@ throw "DELETE_ERROR: Model does not have an _id, so we assume it is not from the database.";

let relatedData: StringToAnyObject | void = await (<typeof XMongoModel>model).thisCollection().findOne(where, options);
let relatedData: StringToAnyObject | void = await (<typeof XMongoModel>model).native().findOne(where, options);

@@ -870,2 +881,3 @@ if (cast && relatedData) relatedData = (<typeof XMongoModel>model).use(relatedData);

/**
* toJSON converter.
* @private

@@ -918,4 +930,4 @@ * @return {*}

*/
static find(query: StringToAnyObject = {}, options: FindOneOptions = {}, raw = false): Promise<XMongoModel[]> | Cursor {
const result = this.thisCollection().find(query, options);
static find(query: (StringToAnyObject | FilterQuery<any>) = {}, options: FindOneOptions<any> = {}, raw = false): Promise<XMongoModel[]> | Cursor {
const result = this.native().find(query, options);
if (raw) return result;

@@ -937,3 +949,3 @@

*/
static findOne<T extends XMongoModel>(query: StringToAnyObject = {}, options: FindOneOptions | boolean = {}, raw = false): Promise<T | null> {
static findOne<T extends XMongoModel>(query: (StringToAnyObject | FilterQuery<any>) = {}, options: FindOneOptions<any> | boolean = {}, raw = false): Promise<T | null> {

@@ -946,3 +958,3 @@ if (typeof options === "boolean") {

return new Promise((resolve, reject) => {
return this.thisCollection().findOne(query, <FindOneOptions>options, (error, data) => {
return this.native().findOne(query, <FindOneOptions<any>>options, (error, data) => {
if (error) return reject(error);

@@ -966,3 +978,3 @@ // Return new instance of Model

*/
static findById(_id: any, options: FindOneOptions = {}, isTypeObjectId = true): Promise<XMongoModel | null> {
static findById(_id: any, options: FindOneOptions<any> = {}, isTypeObjectId = true): Promise<XMongoModel | null> {
let where;

@@ -985,4 +997,4 @@ if (typeof _id === "string" || !isTypeObjectId) {

*/
static count(query: StringToAnyObject = {}, options?: FindOneOptions): Promise<number> {
return this.thisCollection().find(query, options).count()
static count(query: (StringToAnyObject | FilterQuery<any>) = {}, options?: FindOneOptions<any>): Promise<number> {
return this.native().find(query, options).count()
}

@@ -1029,3 +1041,3 @@

let result = await this.thisCollection().aggregate([
let result = await this.native().aggregate([
{$match: match},

@@ -1056,3 +1068,3 @@ {$group}

const data = await this.thisCollection().aggregate(query, options).toArray();
const data = await this.native().aggregate(query, options).toArray();

@@ -1074,3 +1086,3 @@ if (data.length) {

*/
static async paginate(page: number = 1, perPage: number = 20, query = {}, options: FindOneOptions = {}): Promise<PaginationData> {
static async paginate(page: number = 1, perPage: number = 20, query = {}, options: FindOneOptions<any> = {}): Promise<PaginationData> {
page = Number(page);

@@ -1082,3 +1094,3 @@ perPage = Number(perPage);

const skips = perPage * (page - 1);
const data = await this.thisCollection().find(query, options).skip(skips).limit(perPage).toArray();
const data = await this.native().find(query, options).skip(skips).limit(perPage).toArray();

@@ -1115,3 +1127,3 @@ return {

const data = await this.thisCollection().aggregate(query, options).toArray();
const data = await this.native().aggregate(query, options).toArray();

@@ -1143,3 +1155,3 @@ return {

*
* Model.thisCollection().find().limit(10).toArray((err, lists) => {
* Model.native().find().limit(10).toArray((err, lists) => {
* Model.fromArray(lists);

@@ -1159,3 +1171,3 @@ * })

return new Promise((resolve, reject) => {
return (<Cursor>query(this.thisCollection())).toArray((error, lists) => {
return (<Cursor>query(this.native())).toArray((error, lists) => {
if (error) return reject(error);

@@ -1190,3 +1202,3 @@

(<Cursor>query(this.thisCollection())).toArray((error, data) => {
(<Cursor>query(this.native())).toArray((error, data) => {
if (error) return reject(error);

@@ -1193,0 +1205,0 @@ return resolve(data);

@@ -36,5 +36,6 @@ const {is, ModelDataType} = require('../');

guestId: is.Types([
is.String().required(),
is.ObjectId().required(),
]),
is.Number(),
is.Array(),
]).default(() => ['en']).required(),
// guestId: is.ObjectId().required(),
updated_at: is.Date().required()

@@ -45,8 +46,5 @@ };

class Users extends Database.model("users") {
constructor() {
super();
// this.addSchema('GuestSchema', GuestSchema);
// this.addSchema('UserSchema', UserSchema);
//
this.useSchema(GuestSchema);

@@ -53,0 +51,0 @@ }

@@ -16,3 +16,3 @@ const connection = require('./connection');

last_name: 'World',
guestId: Users.id('5e5acba088ebeef8a715ca43'),
guestId: '678',
updated_at: 'Fri, 03 Apr 2020 00:00:00 GMT'

@@ -19,0 +19,0 @@ });

import ObjectCollection = require('object-collection');
import { ObjectID, Collection, UpdateWriteOpResult, InsertOneWriteOpResult, DeleteWriteOpResultObject, Cursor, FindOneOptions, UpdateOneOptions, CollectionInsertOneOptions, CollectionAggregationOptions, AggregationCursor, UpdateQuery } from 'mongodb';
import { ObjectID, Collection, UpdateWriteOpResult, InsertOneWriteOpResult, DeleteWriteOpResultObject, Cursor, FindOneOptions, UpdateOneOptions, CollectionInsertOneOptions, CollectionAggregationOptions, AggregationCursor, UpdateQuery, FilterQuery } from 'mongodb';
import { XMongoSchemaBuilder } from './XMongoSchemaBuilder';

@@ -69,4 +69,12 @@ import { PaginationData, StringToAnyObject } from "./CustomTypes";

constructor();
/**
* Use `.native()` instead
* @deprecated (v 0.0.40)
*/
static thisCollection(): Collection;
/**
* Returns native mongodb instance to run native queries
*/
static native(): Collection;
/**
* Empties data in current model.

@@ -232,2 +240,3 @@ * @param replaceWith

/**
* toJSON converter.
* @private

@@ -259,3 +268,3 @@ * @return {*}

*/
static find(query?: StringToAnyObject, options?: FindOneOptions, raw?: boolean): Promise<XMongoModel[]> | Cursor;
static find(query?: (StringToAnyObject | FilterQuery<any>), options?: FindOneOptions<any>, raw?: boolean): Promise<XMongoModel[]> | Cursor;
/**

@@ -267,3 +276,3 @@ * Fetches the first document that matches the query

*/
static findOne<T extends XMongoModel>(query?: StringToAnyObject, options?: FindOneOptions | boolean, raw?: boolean): Promise<T | null>;
static findOne<T extends XMongoModel>(query?: (StringToAnyObject | FilterQuery<any>), options?: FindOneOptions<any> | boolean, raw?: boolean): Promise<T | null>;
/**

@@ -276,3 +285,3 @@ * Fetches the first document that matches id provided.

*/
static findById(_id: any, options?: FindOneOptions, isTypeObjectId?: boolean): Promise<XMongoModel | null>;
static findById(_id: any, options?: FindOneOptions<any>, isTypeObjectId?: boolean): Promise<XMongoModel | null>;
/**

@@ -284,3 +293,3 @@ * Count All the documents that match query.

*/
static count(query?: StringToAnyObject, options?: FindOneOptions): Promise<number>;
static count(query?: (StringToAnyObject | FilterQuery<any>), options?: FindOneOptions<any>): Promise<number>;
/**

@@ -321,3 +330,3 @@ * Sum fields in this collection.

*/
static paginate(page?: number, perPage?: number, query?: {}, options?: FindOneOptions): Promise<PaginationData>;
static paginate(page?: number, perPage?: number, query?: {}, options?: FindOneOptions<any>): Promise<PaginationData>;
/**

@@ -348,3 +357,3 @@ * Paginate Aggregation.

*
* Model.thisCollection().find().limit(10).toArray((err, lists) => {
* Model.native().find().limit(10).toArray((err, lists) => {
* Model.fromArray(lists);

@@ -351,0 +360,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