@mongez/mongodb
Advanced tools
Comparing version 1.0.71 to 1.0.72
@@ -0,1 +1,2 @@ | ||
import { GenericObject } from "@mongez/reinforcements"; | ||
/** | ||
@@ -2,0 +3,0 @@ * Get count expression |
@@ -82,3 +82,8 @@ import { GenericObject } from "@mongez/reinforcements"; | ||
*/ | ||
static baseSchemaWith(schema: GenericObject): any; | ||
static baseSchemaWith(schema: GenericObject): { | ||
_id: any; | ||
id: string; | ||
createdAt: DateConstructor; | ||
updatedAt: DateConstructor; | ||
}; | ||
} | ||
@@ -85,0 +90,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
export declare function randomString(length?: number): () => any; | ||
export declare function randomString(length?: number): () => string; | ||
//# sourceMappingURL=random-string.d.ts.map |
@@ -37,3 +37,3 @@ import { MongoClient, MongoClientOptions } from "mongodb"; | ||
*/ | ||
on(eventName: ConnectionEvent, callback: any): any; | ||
on(eventName: ConnectionEvent, callback: any): import("@mongez/events").EventSubscription; | ||
/** | ||
@@ -40,0 +40,0 @@ * Use another database |
@@ -56,7 +56,7 @@ import { Database } from "../database"; | ||
*/ | ||
static getIncrementIdBy(): any; | ||
static getIncrementIdBy(): number; | ||
/** | ||
* Get initial id | ||
*/ | ||
static getInitialId(): any; | ||
static getInitialId(): number; | ||
/** | ||
@@ -63,0 +63,0 @@ * Generate next id |
@@ -34,2 +34,10 @@ import { BaseModel } from "./base-model"; | ||
/** | ||
* Get deleted document by id | ||
*/ | ||
static getDeleted<T>(this: ChildModel<T>, id: PrimaryIdType): Promise<T | null>; | ||
/** | ||
* Get all deleted documents | ||
*/ | ||
static getAllDeleted<T>(this: ChildModel<T>, filter?: Filter): Promise<any>; | ||
/** | ||
* Find and update the document for the given filter with the given data or create a new document/record | ||
@@ -36,0 +44,0 @@ * if filter has no matching |
@@ -77,2 +77,3 @@ "use strict"; | ||
const model = this.self(document); | ||
model.unset("deletedAt"); | ||
model.markAsRestored(); | ||
@@ -119,2 +120,48 @@ await model.save(); // save again in the same collection | ||
/** | ||
* Get deleted document by id | ||
*/ | ||
static async getDeleted(id) { | ||
const deleteStrategy = this.deleteStrategy; | ||
if (deleteStrategy === types.ModelDeleteStrategy.softDelete) { | ||
const model = await this.query.first(this.collection, { | ||
id, | ||
}); | ||
if (!model) return null; | ||
return model; | ||
} | ||
const result = await this.query.first( | ||
this.collection + "Trash", | ||
this.prepareFilters({ | ||
[this.primaryIdColumn]: id, | ||
}) | ||
); | ||
if (!result) return null; | ||
const document = result.document; | ||
// otherwise, create a new model with it | ||
const model = this.self(document); | ||
return model; | ||
} | ||
/** | ||
* Get all deleted documents | ||
*/ | ||
static async getAllDeleted(filter) { | ||
const deleteStrategy = this.deleteStrategy; | ||
if (deleteStrategy === types.ModelDeleteStrategy.softDelete) { | ||
return await this.query.list(this.collection, filter); | ||
} | ||
if (filter) { | ||
for (const key in filter) { | ||
filter[`document.` + key] = filter[key]; | ||
delete filter[key]; | ||
} | ||
} | ||
const documents = await this.query.list(this.collection + "Trash", filter); | ||
const models = []; | ||
for (const document of documents) { | ||
const model = this.self(document.document); | ||
models.push(model); | ||
} | ||
return models; | ||
} | ||
/** | ||
* Find and update the document for the given filter with the given data or create a new document/record | ||
@@ -121,0 +168,0 @@ * if filter has no matching |
@@ -95,3 +95,3 @@ import { AggregateOptions, CountDocumentsOptions, ExplainVerbosityLike, FindCursor, FindOptions, UpdateFilter, UpdateOptions } from "mongodb"; | ||
*/ | ||
trigger(eventName: string, payload?: Record<string, any>): Promise<any[]>; | ||
trigger(eventName: string, payload?: Record<string, any>): Promise<import("@mongez/events").EventTriggerResponse[]>; | ||
/** | ||
@@ -98,0 +98,0 @@ * Listen on creating event |
@@ -0,1 +1,2 @@ | ||
import { GenericObject } from "@mongez/reinforcements"; | ||
/** | ||
@@ -2,0 +3,0 @@ * Get count expression |
@@ -82,3 +82,8 @@ import { GenericObject } from "@mongez/reinforcements"; | ||
*/ | ||
static baseSchemaWith(schema: GenericObject): any; | ||
static baseSchemaWith(schema: GenericObject): { | ||
_id: any; | ||
id: string; | ||
createdAt: DateConstructor; | ||
updatedAt: DateConstructor; | ||
}; | ||
} | ||
@@ -85,0 +90,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
export declare function randomString(length?: number): () => any; | ||
export declare function randomString(length?: number): () => string; | ||
//# sourceMappingURL=random-string.d.ts.map |
@@ -37,3 +37,3 @@ import { MongoClient, MongoClientOptions } from "mongodb"; | ||
*/ | ||
on(eventName: ConnectionEvent, callback: any): any; | ||
on(eventName: ConnectionEvent, callback: any): import("@mongez/events").EventSubscription; | ||
/** | ||
@@ -40,0 +40,0 @@ * Use another database |
@@ -56,7 +56,7 @@ import { Database } from "../database"; | ||
*/ | ||
static getIncrementIdBy(): any; | ||
static getIncrementIdBy(): number; | ||
/** | ||
* Get initial id | ||
*/ | ||
static getInitialId(): any; | ||
static getInitialId(): number; | ||
/** | ||
@@ -63,0 +63,0 @@ * Generate next id |
@@ -34,2 +34,10 @@ import { BaseModel } from "./base-model"; | ||
/** | ||
* Get deleted document by id | ||
*/ | ||
static getDeleted<T>(this: ChildModel<T>, id: PrimaryIdType): Promise<T | null>; | ||
/** | ||
* Get all deleted documents | ||
*/ | ||
static getAllDeleted<T>(this: ChildModel<T>, filter?: Filter): Promise<any>; | ||
/** | ||
* Find and update the document for the given filter with the given data or create a new document/record | ||
@@ -36,0 +44,0 @@ * if filter has no matching |
@@ -75,2 +75,3 @@ import { ObjectId } from "mongodb"; | ||
const model = this.self(document); | ||
model.unset("deletedAt"); | ||
model.markAsRestored(); | ||
@@ -117,2 +118,48 @@ await model.save(); // save again in the same collection | ||
/** | ||
* Get deleted document by id | ||
*/ | ||
static async getDeleted(id) { | ||
const deleteStrategy = this.deleteStrategy; | ||
if (deleteStrategy === ModelDeleteStrategy.softDelete) { | ||
const model = await this.query.first(this.collection, { | ||
id, | ||
}); | ||
if (!model) return null; | ||
return model; | ||
} | ||
const result = await this.query.first( | ||
this.collection + "Trash", | ||
this.prepareFilters({ | ||
[this.primaryIdColumn]: id, | ||
}) | ||
); | ||
if (!result) return null; | ||
const document = result.document; | ||
// otherwise, create a new model with it | ||
const model = this.self(document); | ||
return model; | ||
} | ||
/** | ||
* Get all deleted documents | ||
*/ | ||
static async getAllDeleted(filter) { | ||
const deleteStrategy = this.deleteStrategy; | ||
if (deleteStrategy === ModelDeleteStrategy.softDelete) { | ||
return await this.query.list(this.collection, filter); | ||
} | ||
if (filter) { | ||
for (const key in filter) { | ||
filter[`document.` + key] = filter[key]; | ||
delete filter[key]; | ||
} | ||
} | ||
const documents = await this.query.list(this.collection + "Trash", filter); | ||
const models = []; | ||
for (const document of documents) { | ||
const model = this.self(document.document); | ||
models.push(model); | ||
} | ||
return models; | ||
} | ||
/** | ||
* Find and update the document for the given filter with the given data or create a new document/record | ||
@@ -119,0 +166,0 @@ * if filter has no matching |
@@ -95,3 +95,3 @@ import { AggregateOptions, CountDocumentsOptions, ExplainVerbosityLike, FindCursor, FindOptions, UpdateFilter, UpdateOptions } from "mongodb"; | ||
*/ | ||
trigger(eventName: string, payload?: Record<string, any>): Promise<any[]>; | ||
trigger(eventName: string, payload?: Record<string, any>): Promise<import("@mongez/events").EventTriggerResponse[]>; | ||
/** | ||
@@ -98,0 +98,0 @@ * Listen on creating event |
{ | ||
"name": "@mongez/mongodb", | ||
"version": "1.0.71", | ||
"version": "1.0.72", | ||
"description": "Powerful Mongodb Database Manager for Node Js", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
415040
15688