Socket
Socket
Sign inDemoInstall

@mongez/monpulse

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mongez/monpulse - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

10

cjs/aggregate/expressions.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var reinforcements = require("@mongez/reinforcements"),
Is = require("@mongez/supportive-is");
function _interopDefault(e) {
return e && e.__esModule ? e : { default: e };
}
var Is__default = /*#__PURE__*/ _interopDefault(Is);
supportiveIs = require("@mongez/supportive-is");
/**

@@ -315,3 +311,3 @@ * Get count expression

function like(value, column) {
if (Is__default.default.scalar(value)) {
if (Is.scalar(value)) {
value = new RegExp(value, "i");

@@ -330,3 +326,3 @@ }

function notLike(value, column) {
if (Is__default.default.scalar(value)) {
if (supportiveIs.isScalar(value)) {
value = new RegExp(value, "i");

@@ -333,0 +329,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Is = require("@mongez/supportive-is"),
var supportiveIs = require("@mongez/supportive-is"),
timeWizard = require("@mongez/time-wizard"),
expressions = require("./expressions.js");
function _interopDefault(e) {
return e && e.__esModule ? e : { default: e };
}
var Is__default = /*#__PURE__*/ _interopDefault(Is);
function escapeString(value) {

@@ -68,3 +64,3 @@ return String(value).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");

static parse(...args) {
if (args.length === 1 && Is__default.default.plainObject(args[0]))
if (args.length === 1 && supportiveIs.isPlainObject(args[0]))
return parseValuesInObject(args[0]);

@@ -71,0 +67,0 @@ const column = args[0];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Is = require("@mongez/supportive-is");
function _interopDefault(e) {
return e && e.__esModule ? e : { default: e };
}
var Is__default = /*#__PURE__*/ _interopDefault(Is);
var supportiveIs = require("@mongez/supportive-is");
function castEmail(value) {
if (!Is__default.default.email(value)) return null;
if (!supportiveIs.isEmail(value)) return null;
return String(value).toLowerCase();
}
exports.castEmail = castEmail;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Is = require("@mongez/supportive-is");
var supportiveIs = require("@mongez/supportive-is");
require("@mongez/reinforcements"),

@@ -15,6 +15,2 @@ require("@mongez/time-wizard"),

var model = require("../model/model.js");
function _interopDefault(e) {
return e && e.__esModule ? e : { default: e };
}
var Is__default = /*#__PURE__*/ _interopDefault(Is);
function castModel(model$1, embeddedKey = "embeddedData") {

@@ -43,3 +39,3 @@ return async function injectEmbeddedData(value) {

})
.filter((value) => !Is__default.default.empty(value));
.filter((value) => !supportiveIs.isEmpty(value));
// now we need to order documents same as the value

@@ -46,0 +42,0 @@ const orderedDocuments = [];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Is = require("@mongez/supportive-is"),
var supportiveIs = require("@mongez/supportive-is"),
commander = require("commander"),

@@ -20,6 +20,2 @@ blueprint = require("../blueprint/blueprint.js"),

require("process"), require("console-table-printer");
function _interopDefault(e) {
return e && e.__esModule ? e : { default: e };
}
var Is__default = /*#__PURE__*/ _interopDefault(Is);
function parseBlueprint(data) {

@@ -33,7 +29,7 @@ const schema = {};

columnType = parseBlueprint(columnType.schema);
} else if (Is__default.default.plainObject(columnType)) {
} else if (supportiveIs.isPlainObject(columnType)) {
columnType = parseBlueprint(columnType);
} else if (
typeof columnType !== "string" &&
!Is__default.default.plainObject(columnType)
!supportiveIs.isPlainObject(columnType)
) {

@@ -40,0 +36,0 @@ columnType = columnType.name;

@@ -88,2 +88,6 @@ import { BaseModel } from "./base-model";

/**
* Check if document exists for the given filter
*/
static exists<T>(this: ChildModel<T>, filter?: Filter): Promise<boolean>;
/**
* Get distinct values for the given column

@@ -90,0 +94,0 @@ */

@@ -302,2 +302,11 @@ "use strict";

/**
* Check if document exists for the given filter
*/
static async exists(filter = {}) {
return await this.query.exists(
this.collection,
this.prepareFilters(filter)
);
}
/**
* Get distinct values for the given column

@@ -304,0 +313,0 @@ */

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var reinforcements = require("@mongez/reinforcements"),
Is = require("@mongez/supportive-is"),
supportiveIs = require("@mongez/supportive-is"),
timeWizard = require("@mongez/time-wizard"),

@@ -13,3 +13,2 @@ dayjs = require("dayjs"),

}
var Is__default = /*#__PURE__*/ _interopDefault(Is);
var dayjs__default = /*#__PURE__*/ _interopDefault(dayjs);

@@ -394,8 +393,9 @@ class Model extends relationships.RelationshipModel {

const duplicateField = error.keyValue;
const errorMessage = `A user with the same ${
Object.keys(duplicateField)[0]
} already exists.`;
const fieldName = Object.keys(duplicateField)[0];
const errorMessage = `A record with the same ${fieldName} already exists.`;
if (this.autoGeneratedId) {
this.unset("id");
}
throw new Error(errorMessage);
}
this.unset("id");
tries--;

@@ -541,8 +541,8 @@ }

castValue(value, castType) {
const isEmpty = Is__default.default.empty(value);
const isEmptyValue = supportiveIs.isEmpty(value);
switch (castType) {
case "string":
return isEmpty ? "" : String(value).trim();
return isEmptyValue ? "" : String(value).trim();
case "localized":
if (isEmpty) return [];
if (isEmptyValue) return [];
if (!Array.isArray(value)) return [];

@@ -552,4 +552,3 @@ return value

(value) =>
!Is__default.default.empty(value) &&
Is__default.default.plainObject(value)
!supportiveIs.isEmpty(value) && supportiveIs.isPlainObject(value)
)

@@ -563,11 +562,11 @@ .map((item) => {

case "number":
return isEmpty ? 0 : Number(value);
return isEmptyValue ? 0 : Number(value);
case "int":
case "integer":
return isEmpty ? 0 : parseInt(value);
return isEmptyValue ? 0 : parseInt(value);
case "float":
return isEmpty ? 0 : parseFloat(value);
return isEmptyValue ? 0 : parseFloat(value);
case "bool":
case "boolean": {
if (isEmpty) return false;
if (isEmptyValue) return false;
if (value === "true") return true;

@@ -581,3 +580,3 @@ if (value === "false" || value === "0" || value === 0) return false;

}
if (isEmpty) return null;
if (isEmptyValue) return null;
if (dayjs__default.default.isDayjs(value)) {

@@ -607,3 +606,3 @@ return timeWizard.toUTC(value.toDate());

case "location": {
if (isEmpty) return null;
if (isEmptyValue) return null;
const lat = value?.[0] || value?.lat;

@@ -619,3 +618,3 @@ const lng = value?.[1] || value?.lng;

case "object": {
if (isEmpty) return {};
if (isEmptyValue) return {};
if (typeof value === "string") {

@@ -631,3 +630,3 @@ try {

case "array": {
if (isEmpty) return [];
if (isEmptyValue) return [];
if (typeof value === "string") {

@@ -649,3 +648,3 @@ return JSON.parse(value);

// if default value is empty, then do nothing
if (Is__default.default.empty(this.defaultValue)) return;
if (supportiveIs.isEmpty(this.defaultValue)) return;
const defaultValue = { ...this.defaultValue };

@@ -652,0 +651,0 @@ for (const key in defaultValue) {

@@ -87,2 +87,8 @@ import { AggregateOptions, ClientSession, CountDocumentsOptions, ExplainVerbosityLike, FindCursor, FindOptions, UpdateFilter, UpdateOptions } from "mongodb";

/**
* Check if document exists for the given collection with the given filter
*/
exists(collection: string, filter?: Filter, { session }?: {
session?: ClientSession;
}): Promise<boolean>;
/**
* Find a single document for the given collection with the given filter

@@ -89,0 +95,0 @@ */

@@ -303,2 +303,26 @@ "use strict";

/**
* Check if document exists for the given collection with the given filter
*/
async exists(
collection,
filter = {},
{ session = this.getCurrentSession() } = {}
) {
const query = this.query(collection);
await this.trigger("counting", {
collection,
filter,
query,
});
const output = await query.countDocuments(filter, {
session,
});
await this.trigger("counted", {
collection,
filter,
output,
});
return output > 0;
}
/**
* Find a single document for the given collection with the given filter

@@ -305,0 +329,0 @@ */

import { ltrim } from "@mongez/reinforcements";
import Is from "@mongez/supportive-is";
import { isScalar } from "@mongez/supportive-is";
/**

@@ -323,3 +323,3 @@ * Get count expression

function notLike(value, column) {
if (Is.scalar(value)) {
if (isScalar(value)) {
value = new RegExp(value, "i");

@@ -326,0 +326,0 @@ }

@@ -1,2 +0,2 @@

import Is from "@mongez/supportive-is";
import { isPlainObject } from "@mongez/supportive-is";
import { toUTC } from "@mongez/time-wizard";

@@ -62,3 +62,3 @@ import { $agg } from "./expressions.js";

static parse(...args) {
if (args.length === 1 && Is.plainObject(args[0]))
if (args.length === 1 && isPlainObject(args[0]))
return parseValuesInObject(args[0]);

@@ -65,0 +65,0 @@ const column = args[0];

@@ -1,6 +0,6 @@

import Is from "@mongez/supportive-is";
import { isEmail } from "@mongez/supportive-is";
function castEmail(value) {
if (!Is.email(value)) return null;
if (!isEmail(value)) return null;
return String(value).toLowerCase();
}
export { castEmail };

@@ -1,2 +0,2 @@

import Is from "@mongez/supportive-is";
import { isEmpty } from "@mongez/supportive-is";
import "@mongez/reinforcements";

@@ -36,3 +36,3 @@ import "@mongez/time-wizard";

})
.filter((value) => !Is.empty(value));
.filter((value) => !isEmpty(value));
// now we need to order documents same as the value

@@ -39,0 +39,0 @@ const orderedDocuments = [];

@@ -1,2 +0,2 @@

import Is from "@mongez/supportive-is";
import { isPlainObject } from "@mongez/supportive-is";
import { Command } from "commander";

@@ -27,5 +27,5 @@ import { Blueprint } from "../blueprint/blueprint.js";

columnType = parseBlueprint(columnType.schema);
} else if (Is.plainObject(columnType)) {
} else if (isPlainObject(columnType)) {
columnType = parseBlueprint(columnType);
} else if (typeof columnType !== "string" && !Is.plainObject(columnType)) {
} else if (typeof columnType !== "string" && !isPlainObject(columnType)) {
columnType = columnType.name;

@@ -32,0 +32,0 @@ }

@@ -88,2 +88,6 @@ import { BaseModel } from "./base-model";

/**
* Check if document exists for the given filter
*/
static exists<T>(this: ChildModel<T>, filter?: Filter): Promise<boolean>;
/**
* Get distinct values for the given column

@@ -90,0 +94,0 @@ */

@@ -300,2 +300,11 @@ import { ObjectId } from "mongodb";

/**
* Check if document exists for the given filter
*/
static async exists(filter = {}) {
return await this.query.exists(
this.collection,
this.prepareFilters(filter)
);
}
/**
* Get distinct values for the given column

@@ -302,0 +311,0 @@ */

@@ -10,3 +10,3 @@ import {

} from "@mongez/reinforcements";
import Is from "@mongez/supportive-is";
import { isEmpty, isPlainObject } from "@mongez/supportive-is";
import { fromUTC, toUTC, now } from "@mongez/time-wizard";

@@ -395,8 +395,9 @@ import dayjs from "dayjs";

const duplicateField = error.keyValue;
const errorMessage = `A user with the same ${
Object.keys(duplicateField)[0]
} already exists.`;
const fieldName = Object.keys(duplicateField)[0];
const errorMessage = `A record with the same ${fieldName} already exists.`;
if (this.autoGeneratedId) {
this.unset("id");
}
throw new Error(errorMessage);
}
this.unset("id");
tries--;

@@ -542,11 +543,11 @@ }

castValue(value, castType) {
const isEmpty = Is.empty(value);
const isEmptyValue = isEmpty(value);
switch (castType) {
case "string":
return isEmpty ? "" : String(value).trim();
return isEmptyValue ? "" : String(value).trim();
case "localized":
if (isEmpty) return [];
if (isEmptyValue) return [];
if (!Array.isArray(value)) return [];
return value
.filter((value) => !Is.empty(value) && Is.plainObject(value))
.filter((value) => !isEmpty(value) && isPlainObject(value))
.map((item) => {

@@ -559,11 +560,11 @@ return {

case "number":
return isEmpty ? 0 : Number(value);
return isEmptyValue ? 0 : Number(value);
case "int":
case "integer":
return isEmpty ? 0 : parseInt(value);
return isEmptyValue ? 0 : parseInt(value);
case "float":
return isEmpty ? 0 : parseFloat(value);
return isEmptyValue ? 0 : parseFloat(value);
case "bool":
case "boolean": {
if (isEmpty) return false;
if (isEmptyValue) return false;
if (value === "true") return true;

@@ -577,3 +578,3 @@ if (value === "false" || value === "0" || value === 0) return false;

}
if (isEmpty) return null;
if (isEmptyValue) return null;
if (dayjs.isDayjs(value)) {

@@ -601,3 +602,3 @@ return toUTC(value.toDate());

case "location": {
if (isEmpty) return null;
if (isEmptyValue) return null;
const lat = value?.[0] || value?.lat;

@@ -613,3 +614,3 @@ const lng = value?.[1] || value?.lng;

case "object": {
if (isEmpty) return {};
if (isEmptyValue) return {};
if (typeof value === "string") {

@@ -625,3 +626,3 @@ try {

case "array": {
if (isEmpty) return [];
if (isEmptyValue) return [];
if (typeof value === "string") {

@@ -643,3 +644,3 @@ return JSON.parse(value);

// if default value is empty, then do nothing
if (Is.empty(this.defaultValue)) return;
if (isEmpty(this.defaultValue)) return;
const defaultValue = { ...this.defaultValue };

@@ -646,0 +647,0 @@ for (const key in defaultValue) {

@@ -87,2 +87,8 @@ import { AggregateOptions, ClientSession, CountDocumentsOptions, ExplainVerbosityLike, FindCursor, FindOptions, UpdateFilter, UpdateOptions } from "mongodb";

/**
* Check if document exists for the given collection with the given filter
*/
exists(collection: string, filter?: Filter, { session }?: {
session?: ClientSession;
}): Promise<boolean>;
/**
* Find a single document for the given collection with the given filter

@@ -89,0 +95,0 @@ */

@@ -297,2 +297,26 @@ import events from "@mongez/events";

/**
* Check if document exists for the given collection with the given filter
*/
async exists(
collection,
filter = {},
{ session = this.getCurrentSession() } = {}
) {
const query = this.query(collection);
await this.trigger("counting", {
collection,
filter,
query,
});
const output = await query.countDocuments(filter, {
session,
});
await this.trigger("counted", {
collection,
filter,
output,
});
return output > 0;
}
/**
* Find a single document for the given collection with the given filter

@@ -299,0 +323,0 @@ */

{
"name": "@mongez/monpulse",
"version": "1.0.7",
"version": "1.0.8",
"description": "Powerful Mongodb Database Manager for Node Js",

@@ -8,9 +8,9 @@ "main": "./cjs/index.js",

"@mongez/events": "^2.1.0",
"@mongez/logger": "^1.0.9",
"@mongez/reinforcements": "^2.3.7",
"@mongez/supportive-is": "^1.0.12",
"@mongez/logger": "^1.0.10",
"@mongez/reinforcements": "^2.3.8",
"@mongez/supportive-is": "^2.0.0",
"@mongez/time-wizard": "^1.0.6",
"dayjs": "^1.11.9",
"pluralize": "^8.0.0",
"mongodb": "^5.7.0"
"mongodb": "^6.0.0"
},

@@ -17,0 +17,0 @@ "scripts": {

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