xpress-mongo
Advanced tools
Comparing version 0.0.22 to 0.0.23
@@ -12,3 +12,3 @@ "use strict"; | ||
const ObjectCollection = require("object-collection"); | ||
const ModelDataType = require("./XMongoDataType"); | ||
const XMongoDataType = require("./XMongoDataType"); | ||
const mongodb_1 = require("mongodb"); | ||
@@ -81,2 +81,7 @@ const XMongoSchemaBuilder_1 = require("./XMongoSchemaBuilder"); | ||
} | ||
/** | ||
* Empties data in current model. | ||
* @param replaceWith | ||
* @returns {this} | ||
*/ | ||
emptyData(replaceWith) { | ||
@@ -105,3 +110,3 @@ this.data = { | ||
* @param value | ||
* @return {XMongoModel} | ||
* @return {this} | ||
*/ | ||
@@ -147,3 +152,3 @@ set(key, value) { | ||
* @param data | ||
* @return {XMongoModel} | ||
* @return {this} | ||
*/ | ||
@@ -164,3 +169,3 @@ setOriginal(data) { | ||
* @param {Object} schema | ||
* @return {XMongoModel} | ||
* @return {this} | ||
*/ | ||
@@ -178,3 +183,3 @@ addSchema(name, schema) { | ||
* @param {Object|string} schema | ||
* @returns {XMongoModel} | ||
* @returns {this} | ||
* | ||
@@ -193,3 +198,3 @@ * @deprecated | ||
* @param {Object|String} schema | ||
* @returns {XMongoModel} | ||
* @returns {this} | ||
*/ | ||
@@ -224,3 +229,3 @@ useSchema(schema) { | ||
let schemaVal = schema[key]; | ||
if (schemaVal instanceof ModelDataType) { | ||
if (schemaVal instanceof XMongoDataType) { | ||
this.schema[key] = schemaVal['schema']; | ||
@@ -255,3 +260,3 @@ } | ||
* Get id of current model instance | ||
* @returns {*|null} | ||
* @returns {*|ObjectID|null} | ||
*/ | ||
@@ -428,3 +433,3 @@ id() { | ||
* Schema Definition of current schema | ||
* @type {*|ModelDataType} | ||
* @type {*|XMongoDataType} | ||
*/ | ||
@@ -559,2 +564,7 @@ const schema = this.schema[schemaKey]; | ||
; | ||
/** | ||
* Has One relationship | ||
* @param relationship | ||
* @param extend | ||
*/ | ||
hasOne(relationship, extend = {}) { | ||
@@ -634,2 +644,7 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
/** | ||
* Converts this.data to json using JSON.stringify() | ||
* @param replacer | ||
* @param space | ||
*/ | ||
toJson(replacer = undefined, space = undefined) { | ||
@@ -636,0 +651,0 @@ return JSON.stringify(this.data, replacer, space); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const XMongoDataType_1 = __importDefault(require("./XMongoDataType")); | ||
const XMongoDataType = require("./XMongoDataType"); | ||
const mongodb_1 = require("mongodb"); | ||
@@ -18,6 +15,6 @@ const isString = (v) => typeof v === 'string'; | ||
* ObjectId | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
ObjectId: () => { | ||
return new XMongoDataType_1.default('ObjectId', undefined) | ||
return new XMongoDataType('ObjectId', undefined) | ||
.validator({ | ||
@@ -42,6 +39,6 @@ or: [isString, isObjectId] | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
Array: (def = () => []) => { | ||
return new XMongoDataType_1.default('Array', def) | ||
return new XMongoDataType('Array', def) | ||
.validator(isArray) | ||
@@ -53,6 +50,6 @@ .validatorError((key) => `(${key}) is not an Array`); | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
Object: (def = () => ({})) => { | ||
return new XMongoDataType_1.default('Object', def) | ||
return new XMongoDataType('Object', def) | ||
.validator(isObject) | ||
@@ -64,6 +61,6 @@ .validatorError((key) => `(${key}) is not an Object`); | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
String: (def = undefined) => { | ||
return new XMongoDataType_1.default('String', def) | ||
return new XMongoDataType('String', def) | ||
.validator(isString) | ||
@@ -75,6 +72,6 @@ .validatorError((key) => `(${key}) is not a String`); | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
Boolean: (def = false) => { | ||
return new XMongoDataType_1.default('Boolean', def) | ||
return new XMongoDataType('Boolean', def) | ||
.validator(isBoolean) | ||
@@ -86,6 +83,6 @@ .validatorError((key) => `(${key}) is not a Boolean`); | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
Date: (def = () => new Date()) => { | ||
return new XMongoDataType_1.default('Date', def) | ||
return new XMongoDataType('Date', def) | ||
.validator(isDate) | ||
@@ -97,6 +94,6 @@ .validatorError((key) => `(${key}) is not a Date`); | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
Number: (def = 0) => { | ||
return new XMongoDataType_1.default('Number', def) | ||
return new XMongoDataType('Number', def) | ||
.validator(isNumber) | ||
@@ -108,7 +105,7 @@ .cast((v) => Number(v)) | ||
* Is Multiple types | ||
* @param {ModelDataType[]} types | ||
* @return {ModelDataType} | ||
* @param {XMongoDataType[]} types | ||
* @return {XMongoDataType} | ||
*/ | ||
Types: (types) => { | ||
const multipleType = new XMongoDataType_1.default('MultipleDataTypes'); | ||
const multipleType = new XMongoDataType('MultipleDataTypes'); | ||
const mainSchema = types[0].schema; | ||
@@ -115,0 +112,0 @@ // Set default function to first type default |
{ | ||
"name": "xpress-mongo", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"description": "Light Weight ODM for mongoDb", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
@@ -28,3 +28,3 @@ import {ValidatorType, CastFunctionType, SchemaPropertiesType} from "./CustomTypes"; | ||
} | ||
validator(validator: ValidatorType) { | ||
@@ -31,0 +31,0 @@ this.schema.validator = validator; |
import ObjectCollection = require('object-collection'); | ||
import ModelDataType = require('./XMongoDataType'); | ||
import XMongoDataType = require('./XMongoDataType'); | ||
@@ -122,3 +122,8 @@ import { | ||
emptyData(replaceWith?: StringToAnyObject) { | ||
/** | ||
* Empties data in current model. | ||
* @param replaceWith | ||
* @returns {this} | ||
*/ | ||
emptyData(replaceWith?: StringToAnyObject): this { | ||
this.data = { | ||
@@ -148,3 +153,3 @@ _id: this.id() | ||
* @param value | ||
* @return {XMongoModel} | ||
* @return {this} | ||
*/ | ||
@@ -188,3 +193,3 @@ set(key: string | StringToAnyObject, value?: any): this { | ||
* @param data | ||
* @return {XMongoModel} | ||
* @return {this} | ||
*/ | ||
@@ -208,3 +213,3 @@ setOriginal(data: StringToAnyObject): this { | ||
* @param {Object} schema | ||
* @return {XMongoModel} | ||
* @return {this} | ||
*/ | ||
@@ -222,3 +227,3 @@ addSchema(name: string, schema: StringToAnyObject): this { | ||
* @param {Object|string} schema | ||
* @returns {XMongoModel} | ||
* @returns {this} | ||
* | ||
@@ -237,3 +242,3 @@ * @deprecated | ||
* @param {Object|String} schema | ||
* @returns {XMongoModel} | ||
* @returns {this} | ||
*/ | ||
@@ -276,3 +281,3 @@ useSchema(schema: string | StringToAnyObject | { (is: XMongoSchemaBuilder): StringToAnyObject }): this { | ||
if (schemaVal instanceof ModelDataType) { | ||
if (schemaVal instanceof XMongoDataType) { | ||
@@ -314,3 +319,3 @@ this.schema[key] = schemaVal['schema']; | ||
* Get id of current model instance | ||
* @returns {*|null} | ||
* @returns {*|ObjectID|null} | ||
*/ | ||
@@ -376,5 +381,5 @@ id(): any | ObjectID | null { | ||
*/ | ||
update(set: StringToAnyObject, options: UpdateOneOptions) { | ||
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."; | ||
return this.set(set).save(options) | ||
return <Promise<UpdateWriteOpResult>>this.set(set).save(options) | ||
}; | ||
@@ -523,3 +528,3 @@ | ||
* Schema Definition of current schema | ||
* @type {*|ModelDataType} | ||
* @type {*|XMongoDataType} | ||
*/ | ||
@@ -672,2 +677,7 @@ const schema = this.schema[schemaKey]; | ||
/** | ||
* Has One relationship | ||
* @param relationship | ||
* @param extend | ||
*/ | ||
async hasOne(relationship: string, extend: StringToAnyObject = {}): Promise<StringToAnyObject | XMongoModel> { | ||
@@ -756,2 +766,7 @@ let config = (<typeof XMongoModel>this.constructor).relationships; | ||
/** | ||
* Converts this.data to json using JSON.stringify() | ||
* @param replacer | ||
* @param space | ||
*/ | ||
toJson(replacer = undefined, space = undefined): string { | ||
@@ -925,3 +940,3 @@ return JSON.stringify(this.data, replacer, space); | ||
*/ | ||
static count(query: StringToAnyObject, options?: FindOneOptions) { | ||
static count(query: StringToAnyObject, options?: FindOneOptions): Promise<number> { | ||
return this.raw.find(query, options).count() | ||
@@ -928,0 +943,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import ModelDataType from "./XMongoDataType"; | ||
import XMongoDataType = require("./XMongoDataType"); | ||
import {ObjectID} from "mongodb"; | ||
@@ -15,10 +15,10 @@ import {StringToAnyObject} from "./CustomTypes"; | ||
type XMongoSchemaBuilder = { | ||
ObjectId: () => ModelDataType, | ||
Array: { (def?: () => Array<any>): ModelDataType }, | ||
Object: { (def?: () => StringToAnyObject): ModelDataType }, | ||
String: { (def?: string): ModelDataType }, | ||
Boolean: { (def?: boolean): ModelDataType }, | ||
Date: { (def?: () => Date): ModelDataType }, | ||
Number: { (def?: 0): ModelDataType }, | ||
Types: { (types: ModelDataType[]): ModelDataType }, | ||
ObjectId: () => XMongoDataType, | ||
Array: { (def?: () => Array<any>): XMongoDataType }, | ||
Object: { (def?: () => StringToAnyObject): XMongoDataType }, | ||
String: { (def?: string): XMongoDataType }, | ||
Boolean: { (def?: boolean): XMongoDataType }, | ||
Date: { (def?: () => Date): XMongoDataType }, | ||
Number: { (def?: 0): XMongoDataType }, | ||
Types: { (types: XMongoDataType[]): XMongoDataType }, | ||
}; | ||
@@ -29,6 +29,6 @@ | ||
* ObjectId | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
ObjectId: () => { | ||
return new ModelDataType('ObjectId', undefined) | ||
ObjectId: (): XMongoDataType => { | ||
return new XMongoDataType('ObjectId', undefined) | ||
.validator({ | ||
@@ -56,6 +56,6 @@ or: [isString, isObjectId] | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
Array: (def = () => []) => { | ||
return new ModelDataType('Array', def) | ||
Array: (def = () => []): XMongoDataType => { | ||
return new XMongoDataType('Array', def) | ||
.validator(isArray) | ||
@@ -69,6 +69,6 @@ .validatorError((key) => `(${key}) is not an Array`); | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
Object: (def = () => ({})) => { | ||
return new ModelDataType('Object', def) | ||
Object: (def = () => ({})): XMongoDataType => { | ||
return new XMongoDataType('Object', def) | ||
.validator(isObject) | ||
@@ -82,6 +82,6 @@ .validatorError((key) => `(${key}) is not an Object`); | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
String: (def = undefined) => { | ||
return new ModelDataType('String', def) | ||
String: (def = undefined): XMongoDataType => { | ||
return new XMongoDataType('String', def) | ||
.validator(isString) | ||
@@ -94,6 +94,6 @@ .validatorError((key) => `(${key}) is not a String`); | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
Boolean: (def = false) => { | ||
return new ModelDataType('Boolean', def) | ||
Boolean: (def = false): XMongoDataType => { | ||
return new XMongoDataType('Boolean', def) | ||
.validator(isBoolean) | ||
@@ -107,6 +107,6 @@ .validatorError((key) => `(${key}) is not a Boolean`); | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
Date: (def = () => new Date()) => { | ||
return new ModelDataType('Date', def) | ||
Date: (def = () => new Date()): XMongoDataType => { | ||
return new XMongoDataType('Date', def) | ||
.validator(isDate) | ||
@@ -118,6 +118,6 @@ .validatorError((key) => `(${key}) is not a Date`); | ||
* @param def | ||
* @return {ModelDataType} | ||
* @return {XMongoDataType} | ||
*/ | ||
Number: (def = 0) => { | ||
return new ModelDataType('Number', def) | ||
Number: (def = 0): XMongoDataType => { | ||
return new XMongoDataType('Number', def) | ||
.validator(isNumber) | ||
@@ -130,7 +130,7 @@ .cast((v) => Number(v)) | ||
* Is Multiple types | ||
* @param {ModelDataType[]} types | ||
* @return {ModelDataType} | ||
* @param {XMongoDataType[]} types | ||
* @return {XMongoDataType} | ||
*/ | ||
Types: (types: ModelDataType[]) => { | ||
const multipleType = new ModelDataType('MultipleDataTypes'); | ||
Types: (types: XMongoDataType[]): XMongoDataType => { | ||
const multipleType = new XMongoDataType('MultipleDataTypes'); | ||
const mainSchema = types[0].schema; | ||
@@ -137,0 +137,0 @@ |
@@ -68,2 +68,7 @@ import ObjectCollection = require('object-collection'); | ||
constructor(); | ||
/** | ||
* Empties data in current model. | ||
* @param replaceWith | ||
* @returns {this} | ||
*/ | ||
emptyData(replaceWith?: StringToAnyObject): this; | ||
@@ -81,3 +86,3 @@ /** | ||
* @param value | ||
* @return {XMongoModel} | ||
* @return {this} | ||
*/ | ||
@@ -101,3 +106,3 @@ set(key: string | StringToAnyObject, value?: any): this; | ||
* @param data | ||
* @return {XMongoModel} | ||
* @return {this} | ||
*/ | ||
@@ -109,3 +114,3 @@ setOriginal(data: StringToAnyObject): this; | ||
* @param {Object} schema | ||
* @return {XMongoModel} | ||
* @return {this} | ||
*/ | ||
@@ -118,3 +123,3 @@ addSchema(name: string, schema: StringToAnyObject): this; | ||
* @param {Object|string} schema | ||
* @returns {XMongoModel} | ||
* @returns {this} | ||
* | ||
@@ -129,3 +134,3 @@ * @deprecated | ||
* @param {Object|String} schema | ||
* @returns {XMongoModel} | ||
* @returns {this} | ||
*/ | ||
@@ -137,3 +142,3 @@ useSchema(schema: string | StringToAnyObject | { | ||
* Get id of current model instance | ||
* @returns {*|null} | ||
* @returns {*|ObjectID|null} | ||
*/ | ||
@@ -159,3 +164,3 @@ id(): any | ObjectID | null; | ||
*/ | ||
update(set: StringToAnyObject, options: UpdateOneOptions): Promise<boolean | UpdateWriteOpResult | InsertOneWriteOpResult<any>>; | ||
update(set: StringToAnyObject, options: UpdateOneOptions): Promise<UpdateWriteOpResult>; | ||
/** | ||
@@ -197,2 +202,7 @@ * Create Model if not id is missing or save document if id is found. | ||
static use(data: StringToAnyObject): XMongoModel; | ||
/** | ||
* Has One relationship | ||
* @param relationship | ||
* @param extend | ||
*/ | ||
hasOne(relationship: string, extend?: StringToAnyObject): Promise<StringToAnyObject | XMongoModel>; | ||
@@ -204,2 +214,7 @@ /** | ||
toJSON(): StringToAnyObject; | ||
/** | ||
* Converts this.data to json using JSON.stringify() | ||
* @param replacer | ||
* @param space | ||
*/ | ||
toJson(replacer?: undefined, space?: undefined): string; | ||
@@ -206,0 +221,0 @@ /** |
@@ -1,25 +0,25 @@ | ||
import ModelDataType from "./XMongoDataType"; | ||
import XMongoDataType = require("./XMongoDataType"); | ||
import { StringToAnyObject } from "./CustomTypes"; | ||
declare type XMongoSchemaBuilder = { | ||
ObjectId: () => ModelDataType; | ||
ObjectId: () => XMongoDataType; | ||
Array: { | ||
(def?: () => Array<any>): ModelDataType; | ||
(def?: () => Array<any>): XMongoDataType; | ||
}; | ||
Object: { | ||
(def?: () => StringToAnyObject): ModelDataType; | ||
(def?: () => StringToAnyObject): XMongoDataType; | ||
}; | ||
String: { | ||
(def?: string): ModelDataType; | ||
(def?: string): XMongoDataType; | ||
}; | ||
Boolean: { | ||
(def?: boolean): ModelDataType; | ||
(def?: boolean): XMongoDataType; | ||
}; | ||
Date: { | ||
(def?: () => Date): ModelDataType; | ||
(def?: () => Date): XMongoDataType; | ||
}; | ||
Number: { | ||
(def?: 0): ModelDataType; | ||
(def?: 0): XMongoDataType; | ||
}; | ||
Types: { | ||
(types: ModelDataType[]): ModelDataType; | ||
(types: XMongoDataType[]): XMongoDataType; | ||
}; | ||
@@ -26,0 +26,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120996
3276