@mongez/monpulse
Advanced tools
Comparing version 1.0.35 to 1.0.36
@@ -155,4 +155,24 @@ import { ObjectId } from "mongodb"; | ||
*/ | ||
get(column: keyof ModelSchema, defaultValue?: any): any; | ||
get<ValueType = any>(column: keyof ModelSchema, defaultValue?: any): ValueType; | ||
/** | ||
* Return the value of the given column as a string | ||
*/ | ||
string(column: keyof ModelSchema, defaultValue?: any): string; | ||
/** | ||
* Return the value of the given column as an integer | ||
*/ | ||
int(column: keyof ModelSchema, defaultValue?: any): number; | ||
/** | ||
* Return the value of the given column as a float | ||
*/ | ||
float(column: keyof ModelSchema, defaultValue?: any): number; | ||
/** | ||
* Return the value of the given column as a number | ||
*/ | ||
number(column: keyof ModelSchema, defaultValue?: any): number; | ||
/** | ||
* Return the value of the given column as a boolean | ||
*/ | ||
bool(column: keyof ModelSchema, defaultValue?: any): boolean; | ||
/** | ||
* Determine whether the given column exists in the document | ||
@@ -192,2 +212,6 @@ */ | ||
/** | ||
* Push the given values to the given column only if not exists | ||
*/ | ||
pushOnce(column: keyof ModelSchema, ...values: any[]): this; | ||
/** | ||
* Add the given values to the beginning of the given column | ||
@@ -199,2 +223,6 @@ * If the given column does not exists, it will be created | ||
/** | ||
* Add the given values to the beginning of the given column only if not exists | ||
*/ | ||
unshiftOnce(column: keyof ModelSchema, ...values: any[]): this; | ||
/** | ||
* Perform saving operation either by updating or creating a new record in database | ||
@@ -258,2 +286,10 @@ */ | ||
/** | ||
* Return only the given columns to be used in output | ||
*/ | ||
outputOnly(columns: string[]): this; | ||
/** | ||
* Return all columns except the given columns to be used in output | ||
*/ | ||
outputExcept(columns: string[]): this; | ||
/** | ||
* Cast the given value based on the given cast type | ||
@@ -287,3 +323,3 @@ */ | ||
*/ | ||
clone(): this; | ||
clone(data?: Document): this; | ||
} | ||
@@ -290,0 +326,0 @@ export type ModelType = typeof Model; |
@@ -203,2 +203,32 @@ 'use strict';var reinforcements=require('@mongez/reinforcements'),supportiveIs=require('@mongez/supportive-is'),timeWizard=require('@mongez/time-wizard'),dayjs=require('dayjs'),mongodb=require('mongodb'),castModel=require('../casts/castModel.js'),oneOf=require('../casts/oneOf.js');require('../casts/shapedArray.js');var relationships=require('./relationships.js'),types=require('./types.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var dayjs__default=/*#__PURE__*/_interopDefault(dayjs);class Model | ||
/** | ||
* Return the value of the given column as a string | ||
*/ | ||
string(column, defaultValue) { | ||
return String(this.get(column, defaultValue)); | ||
} | ||
/** | ||
* Return the value of the given column as an integer | ||
*/ | ||
int(column, defaultValue) { | ||
return parseInt(this.get(column, defaultValue)); | ||
} | ||
/** | ||
* Return the value of the given column as a float | ||
*/ | ||
float(column, defaultValue) { | ||
return parseFloat(this.get(column, defaultValue)); | ||
} | ||
/** | ||
* Return the value of the given column as a number | ||
*/ | ||
number(column, defaultValue) { | ||
return Number(this.get(column, defaultValue)); | ||
} | ||
/** | ||
* Return the value of the given column as a boolean | ||
*/ | ||
bool(column, defaultValue) { | ||
return Boolean(this.get(column, defaultValue)); | ||
} | ||
/** | ||
* Determine whether the given column exists in the document | ||
@@ -270,2 +300,16 @@ */ | ||
/** | ||
* Push the given values to the given column only if not exists | ||
*/ | ||
pushOnce(column, ...values) { | ||
const currentValue = this.get(column); | ||
if (Array.isArray(currentValue)) { | ||
const newValues = Array.from(new Set([...currentValue, ...values])); | ||
this.set(column, newValues); | ||
} | ||
else if (!currentValue) { | ||
this.set(column, values); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Add the given values to the beginning of the given column | ||
@@ -286,2 +330,16 @@ * If the given column does not exists, it will be created | ||
/** | ||
* Add the given values to the beginning of the given column only if not exists | ||
*/ | ||
unshiftOnce(column, ...values) { | ||
const currentValue = this.get(column); | ||
if (Array.isArray(currentValue)) { | ||
const newValues = Array.from(new Set([...values, ...currentValue])); | ||
this.set(column, newValues); | ||
} | ||
else if (!currentValue) { | ||
this.set(column, values); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Perform saving operation either by updating or creating a new record in database | ||
@@ -582,2 +640,14 @@ */ | ||
/** | ||
* Return only the given columns to be used in output | ||
*/ | ||
outputOnly(columns) { | ||
return this.clone(this.only(columns)); | ||
} | ||
/** | ||
* Return all columns except the given columns to be used in output | ||
*/ | ||
outputExcept(columns) { | ||
return this.clone(this.except(columns)); | ||
} | ||
/** | ||
* Cast the given value based on the given cast type | ||
@@ -775,5 +845,5 @@ */ | ||
*/ | ||
clone() { | ||
return new this.constructor(reinforcements.clone(this.data)); | ||
clone(data = this.data) { | ||
return new this.constructor(reinforcements.clone(data)); | ||
} | ||
}exports.Model=Model;//# sourceMappingURL=model.js.map |
@@ -13,2 +13,10 @@ import { LogChannel, LogLevel } from "@mongez/logger"; | ||
/** | ||
* Allowed log levels | ||
*/ | ||
protected allowedLogLevels: LogLevel[]; | ||
/** | ||
* Set the allowed log levels | ||
*/ | ||
setAllowedLogLevels(levels: LogLevel[]): this; | ||
/** | ||
* {@inheritdoc} | ||
@@ -15,0 +23,0 @@ */ |
@@ -11,2 +11,13 @@ 'use strict';var logger=require('@mongez/logger'),Log=require('../models/Log.js');class DatabaseLog extends logger.LogChannel { | ||
/** | ||
* Allowed log levels | ||
*/ | ||
allowedLogLevels = []; | ||
/** | ||
* Set the allowed log levels | ||
*/ | ||
setAllowedLogLevels(levels) { | ||
this.allowedLogLevels = levels; | ||
return this; | ||
} | ||
/** | ||
* {@inheritdoc} | ||
@@ -17,2 +28,4 @@ */ | ||
return; | ||
if (this.allowedLogLevels.length && !this.allowedLogLevels.includes(level)) | ||
return; | ||
const data = { | ||
@@ -19,0 +32,0 @@ module, |
@@ -155,4 +155,24 @@ import { ObjectId } from "mongodb"; | ||
*/ | ||
get(column: keyof ModelSchema, defaultValue?: any): any; | ||
get<ValueType = any>(column: keyof ModelSchema, defaultValue?: any): ValueType; | ||
/** | ||
* Return the value of the given column as a string | ||
*/ | ||
string(column: keyof ModelSchema, defaultValue?: any): string; | ||
/** | ||
* Return the value of the given column as an integer | ||
*/ | ||
int(column: keyof ModelSchema, defaultValue?: any): number; | ||
/** | ||
* Return the value of the given column as a float | ||
*/ | ||
float(column: keyof ModelSchema, defaultValue?: any): number; | ||
/** | ||
* Return the value of the given column as a number | ||
*/ | ||
number(column: keyof ModelSchema, defaultValue?: any): number; | ||
/** | ||
* Return the value of the given column as a boolean | ||
*/ | ||
bool(column: keyof ModelSchema, defaultValue?: any): boolean; | ||
/** | ||
* Determine whether the given column exists in the document | ||
@@ -192,2 +212,6 @@ */ | ||
/** | ||
* Push the given values to the given column only if not exists | ||
*/ | ||
pushOnce(column: keyof ModelSchema, ...values: any[]): this; | ||
/** | ||
* Add the given values to the beginning of the given column | ||
@@ -199,2 +223,6 @@ * If the given column does not exists, it will be created | ||
/** | ||
* Add the given values to the beginning of the given column only if not exists | ||
*/ | ||
unshiftOnce(column: keyof ModelSchema, ...values: any[]): this; | ||
/** | ||
* Perform saving operation either by updating or creating a new record in database | ||
@@ -258,2 +286,10 @@ */ | ||
/** | ||
* Return only the given columns to be used in output | ||
*/ | ||
outputOnly(columns: string[]): this; | ||
/** | ||
* Return all columns except the given columns to be used in output | ||
*/ | ||
outputExcept(columns: string[]): this; | ||
/** | ||
* Cast the given value based on the given cast type | ||
@@ -287,3 +323,3 @@ */ | ||
*/ | ||
clone(): this; | ||
clone(data?: Document): this; | ||
} | ||
@@ -290,0 +326,0 @@ export type ModelType = typeof Model; |
@@ -203,2 +203,32 @@ import {clone,get,except,only,set,merge,areEqual}from'@mongez/reinforcements';import {isEmpty,isPlainObject}from'@mongez/supportive-is';import {toUTC}from'@mongez/time-wizard';import dayjs from'dayjs';import {ObjectId,MongoServerError}from'mongodb';import {castModel}from'../casts/castModel.js';import {castEnum}from'../casts/oneOf.js';import'../casts/shapedArray.js';import {RelationshipModel}from'./relationships.js';import {ModelDeleteStrategy}from'./types.js';class Model | ||
/** | ||
* Return the value of the given column as a string | ||
*/ | ||
string(column, defaultValue) { | ||
return String(this.get(column, defaultValue)); | ||
} | ||
/** | ||
* Return the value of the given column as an integer | ||
*/ | ||
int(column, defaultValue) { | ||
return parseInt(this.get(column, defaultValue)); | ||
} | ||
/** | ||
* Return the value of the given column as a float | ||
*/ | ||
float(column, defaultValue) { | ||
return parseFloat(this.get(column, defaultValue)); | ||
} | ||
/** | ||
* Return the value of the given column as a number | ||
*/ | ||
number(column, defaultValue) { | ||
return Number(this.get(column, defaultValue)); | ||
} | ||
/** | ||
* Return the value of the given column as a boolean | ||
*/ | ||
bool(column, defaultValue) { | ||
return Boolean(this.get(column, defaultValue)); | ||
} | ||
/** | ||
* Determine whether the given column exists in the document | ||
@@ -270,2 +300,16 @@ */ | ||
/** | ||
* Push the given values to the given column only if not exists | ||
*/ | ||
pushOnce(column, ...values) { | ||
const currentValue = this.get(column); | ||
if (Array.isArray(currentValue)) { | ||
const newValues = Array.from(new Set([...currentValue, ...values])); | ||
this.set(column, newValues); | ||
} | ||
else if (!currentValue) { | ||
this.set(column, values); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Add the given values to the beginning of the given column | ||
@@ -286,2 +330,16 @@ * If the given column does not exists, it will be created | ||
/** | ||
* Add the given values to the beginning of the given column only if not exists | ||
*/ | ||
unshiftOnce(column, ...values) { | ||
const currentValue = this.get(column); | ||
if (Array.isArray(currentValue)) { | ||
const newValues = Array.from(new Set([...values, ...currentValue])); | ||
this.set(column, newValues); | ||
} | ||
else if (!currentValue) { | ||
this.set(column, values); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Perform saving operation either by updating or creating a new record in database | ||
@@ -582,2 +640,14 @@ */ | ||
/** | ||
* Return only the given columns to be used in output | ||
*/ | ||
outputOnly(columns) { | ||
return this.clone(this.only(columns)); | ||
} | ||
/** | ||
* Return all columns except the given columns to be used in output | ||
*/ | ||
outputExcept(columns) { | ||
return this.clone(this.except(columns)); | ||
} | ||
/** | ||
* Cast the given value based on the given cast type | ||
@@ -775,5 +845,5 @@ */ | ||
*/ | ||
clone() { | ||
return new this.constructor(clone(this.data)); | ||
clone(data = this.data) { | ||
return new this.constructor(clone(data)); | ||
} | ||
}export{Model};//# sourceMappingURL=model.js.map |
@@ -13,2 +13,10 @@ import { LogChannel, LogLevel } from "@mongez/logger"; | ||
/** | ||
* Allowed log levels | ||
*/ | ||
protected allowedLogLevels: LogLevel[]; | ||
/** | ||
* Set the allowed log levels | ||
*/ | ||
setAllowedLogLevels(levels: LogLevel[]): this; | ||
/** | ||
* {@inheritdoc} | ||
@@ -15,0 +23,0 @@ */ |
@@ -11,2 +11,13 @@ import {LogChannel}from'@mongez/logger';import {Log}from'../models/Log.js';class DatabaseLog extends LogChannel { | ||
/** | ||
* Allowed log levels | ||
*/ | ||
allowedLogLevels = []; | ||
/** | ||
* Set the allowed log levels | ||
*/ | ||
setAllowedLogLevels(levels) { | ||
this.allowedLogLevels = levels; | ||
return this; | ||
} | ||
/** | ||
* {@inheritdoc} | ||
@@ -17,2 +28,4 @@ */ | ||
return; | ||
if (this.allowedLogLevels.length && !this.allowedLogLevels.includes(level)) | ||
return; | ||
const data = { | ||
@@ -19,0 +32,0 @@ module, |
{ | ||
"name": "@mongez/monpulse", | ||
"version": "1.0.35", | ||
"version": "1.0.36", | ||
"description": "Powerful Mongodb Database Manager for Node Js", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
944342
17148