mongodb-paginate
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -1,5 +0,34 @@ | ||
import dbConnection, { mongoDB } from "@imtiazchowdhury/mongopool"; | ||
/// <reference types="mongoose/types/aggregate" /> | ||
/// <reference types="mongoose/types/callback" /> | ||
/// <reference types="mongoose/types/collection" /> | ||
/// <reference types="mongoose/types/connection" /> | ||
/// <reference types="mongoose/types/cursor" /> | ||
/// <reference types="mongoose/types/document" /> | ||
/// <reference types="mongoose/types/error" /> | ||
/// <reference types="mongoose/types/expressions" /> | ||
/// <reference types="mongoose/types/helpers" /> | ||
/// <reference types="mongoose/types/middlewares" /> | ||
/// <reference types="mongoose/types/indexes" /> | ||
/// <reference types="mongoose/types/models" /> | ||
/// <reference types="mongoose/types/mongooseoptions" /> | ||
/// <reference types="mongoose/types/pipelinestage" /> | ||
/// <reference types="mongoose/types/populate" /> | ||
/// <reference types="mongoose/types/query" /> | ||
/// <reference types="mongoose/types/schemaoptions" /> | ||
/// <reference types="mongoose/types/schematypes" /> | ||
/// <reference types="mongoose/types/session" /> | ||
/// <reference types="mongoose/types/types" /> | ||
/// <reference types="mongoose/types/utility" /> | ||
/// <reference types="mongoose/types/validation" /> | ||
/// <reference types="mongoose/types/virtuals" /> | ||
/// <reference types="mongoose" /> | ||
/// <reference types="mongoose/types/inferschematype" /> | ||
import dbConnection from "@imtiazchowdhury/mongopool"; | ||
import * as mongodb from "mongodb"; | ||
import { Paginate } from "./types/types"; | ||
declare const paginate: Paginate; | ||
export default paginate; | ||
export { dbConnection, mongoDB }; | ||
export { dbConnection, mongodb }; | ||
export type { Document } from "mongodb"; | ||
export type { PipelineStage } from "mongoose"; | ||
export type * from "./types/types"; |
@@ -34,7 +34,11 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mongoDB = exports.dbConnection = void 0; | ||
const mongopool_1 = __importStar(require("@imtiazchowdhury/mongopool")); | ||
exports.mongodb = exports.dbConnection = void 0; | ||
const mongopool_1 = __importDefault(require("@imtiazchowdhury/mongopool")); | ||
exports.dbConnection = mongopool_1.default; | ||
Object.defineProperty(exports, "mongoDB", { enumerable: true, get: function () { return mongopool_1.mongoDB; } }); | ||
const mongodb = __importStar(require("mongodb")); | ||
exports.mongodb = mongodb; | ||
const paginate = function (collection, prePagingStage, postPagingStage, options, facet, aggregateOptions) { | ||
@@ -91,2 +95,4 @@ return __awaiter(this, void 0, void 0, function* () { | ||
let aggregateResult; | ||
console.log({ mongodb }); | ||
console.log({ a: collection instanceof mongodb.Collection }); | ||
if (typeof collection === "string") { | ||
@@ -96,8 +102,11 @@ let db = yield mongopool_1.default.getDB(); | ||
} | ||
else if (collection instanceof mongopool_1.mongoDB.Collection) { | ||
else if (typeof collection.collectionName === "string" && typeof collection.aggregate === "function") { //mongodb | ||
aggregateResult = yield collection.aggregate(aggregatePipeLine, aggregateOptions).toArray(); | ||
} | ||
else { | ||
else if (typeof collection.aggregate === "function") { //mongoose | ||
aggregateResult = yield collection.aggregate(aggregatePipeLine, aggregateOptions).exec(); | ||
} | ||
else { | ||
throw new Error("Invalid collection type provided"); | ||
} | ||
let result = aggregateResult[0]; | ||
@@ -104,0 +113,0 @@ if (!result || !result["page"] || !result["page"][0]) |
@@ -0,3 +1,27 @@ | ||
/// <reference types="mongoose/types/aggregate" /> | ||
/// <reference types="mongoose/types/callback" /> | ||
/// <reference types="mongoose/types/collection" /> | ||
/// <reference types="mongoose/types/connection" /> | ||
/// <reference types="mongoose/types/cursor" /> | ||
/// <reference types="mongoose/types/document" /> | ||
/// <reference types="mongoose/types/error" /> | ||
/// <reference types="mongoose/types/expressions" /> | ||
/// <reference types="mongoose/types/helpers" /> | ||
/// <reference types="mongoose/types/middlewares" /> | ||
/// <reference types="mongoose/types/indexes" /> | ||
/// <reference types="mongoose/types/models" /> | ||
/// <reference types="mongoose/types/mongooseoptions" /> | ||
/// <reference types="mongoose/types/pipelinestage" /> | ||
/// <reference types="mongoose/types/populate" /> | ||
/// <reference types="mongoose/types/query" /> | ||
/// <reference types="mongoose/types/schemaoptions" /> | ||
/// <reference types="mongoose/types/schematypes" /> | ||
/// <reference types="mongoose/types/session" /> | ||
/// <reference types="mongoose/types/types" /> | ||
/// <reference types="mongoose/types/utility" /> | ||
/// <reference types="mongoose/types/validation" /> | ||
/// <reference types="mongoose/types/virtuals" /> | ||
/// <reference types="mongoose/types/inferschematype" /> | ||
import { mongoDB } from "@imtiazchowdhury/mongopool"; | ||
import mongoose, { PipelineStage } from "mongoose"; | ||
import { PipelineStage } from "mongoose"; | ||
export interface PaginationOptions { | ||
@@ -41,2 +65,2 @@ sort?: string; | ||
} | ||
export type Paginate = (collection: string | mongoose.Model<mongoDB.Document> | mongoDB.Collection, prePagingState: PipelineStage[], postPagingStage: PipelineStage[], options: PaginationOptions, facet?: FacetBucketQuery[], aggregateOptions?: mongoDB.AggregateOptions) => Promise<PaginateResult | EmptyPaginateResult>; | ||
export type Paginate = (collection: any, prePagingState: PipelineStage[], postPagingStage: PipelineStage[], options: PaginationOptions, facet?: FacetBucketQuery[], aggregateOptions?: mongoDB.AggregateOptions) => Promise<PaginateResult | EmptyPaginateResult>; |
{ | ||
"name": "mongodb-paginate", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "mongodb aggregation with pagination library for efficient and fast aggregations", | ||
@@ -15,2 +15,3 @@ "main": "dist/index", | ||
"@imtiazchowdhury/mongopool": "^1.5.1", | ||
"mongodb": "^6.5.0", | ||
"mongoose": "^8.0.0" | ||
@@ -17,0 +18,0 @@ }, |
@@ -1,2 +0,3 @@ | ||
import dbConnection, { mongoDB } from "@imtiazchowdhury/mongopool"; | ||
import dbConnection from "@imtiazchowdhury/mongopool"; | ||
import * as mongodb from "mongodb"; | ||
import { Paginate, PaginatePageInfo } from "./types/types"; | ||
@@ -54,3 +55,3 @@ | ||
const facetStage: mongoDB.Document = { | ||
const facetStage: mongodb.Document = { | ||
page: [ | ||
@@ -72,3 +73,3 @@ { | ||
let aggregateResult: mongoDB.Document[]; | ||
let aggregateResult: mongodb.Document[]; | ||
@@ -78,6 +79,11 @@ if (typeof collection === "string") { | ||
aggregateResult = await db.collection(collection).aggregate(aggregatePipeLine, aggregateOptions).toArray(); | ||
} else if (collection instanceof mongoDB.Collection) { | ||
} else if (typeof collection.collectionName === "string" && typeof collection.aggregate === "function") { //mongodb | ||
aggregateResult = await collection.aggregate(aggregatePipeLine, aggregateOptions).toArray() | ||
} else if (typeof collection.aggregate === "function") { //mongoose | ||
aggregateResult = await collection.aggregate(aggregatePipeLine, aggregateOptions).exec() | ||
} else { | ||
aggregateResult = await collection.aggregate(aggregatePipeLine, aggregateOptions).exec() | ||
throw new Error("Invalid collection type provided") | ||
} | ||
@@ -123,4 +129,7 @@ | ||
dbConnection, | ||
mongoDB | ||
mongodb | ||
}; | ||
export type { Document } from "mongodb"; | ||
export type { PipelineStage } from "mongoose"; | ||
export type * from "./types/types"; |
import { mongoDB } from "@imtiazchowdhury/mongopool" | ||
import mongoose, { PipelineStage } from "mongoose" | ||
import { PipelineStage } from "mongoose" | ||
@@ -51,3 +51,3 @@ export interface PaginationOptions { | ||
export type Paginate = ( | ||
collection: string | mongoose.Model<mongoDB.Document> | mongoDB.Collection, | ||
collection: any, | ||
prePagingState: PipelineStage[], | ||
@@ -59,2 +59,1 @@ postPagingStage: PipelineStage[], | ||
) => Promise<PaginateResult | EmptyPaginateResult> | ||
35486
483
3
9
+ Addedmongodb@^6.5.0