@villedemontreal/mongo 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +226 -0
- package/dist/src/config/configs.d.ts +16 -0
- package/dist/src/config/configs.js +26 -0
- package/dist/src/config/configs.js.map +1 -0
- package/dist/src/config/constants.d.ts +85 -0
- package/dist/src/config/constants.js +104 -0
- package/dist/src/config/constants.js.map +1 -0
- package/dist/src/config/init.d.ts +9 -0
- package/dist/src/config/init.js +24 -0
- package/dist/src/config/init.js.map +1 -0
- package/dist/src/config/mongooseConfigs.d.ts +73 -0
- package/dist/src/config/mongooseConfigs.js +107 -0
- package/dist/src/config/mongooseConfigs.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +24 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mongoClient.d.ts +19 -0
- package/dist/src/mongoClient.js +111 -0
- package/dist/src/mongoClient.js.map +1 -0
- package/dist/src/mongoUpdater.d.ts +103 -0
- package/dist/src/mongoUpdater.js +297 -0
- package/dist/src/mongoUpdater.js.map +1 -0
- package/dist/src/mongoUpdater.test.d.ts +1 -0
- package/dist/src/mongoUpdater.test.js +232 -0
- package/dist/src/mongoUpdater.test.js.map +1 -0
- package/dist/src/mongoUtils.d.ts +68 -0
- package/dist/src/mongoUtils.js +280 -0
- package/dist/src/mongoUtils.js.map +1 -0
- package/dist/src/mongoUtils.test.d.ts +1 -0
- package/dist/src/mongoUtils.test.js +24 -0
- package/dist/src/mongoUtils.test.js.map +1 -0
- package/dist/src/plugins/pagination/index.d.ts +11 -0
- package/dist/src/plugins/pagination/index.js +79 -0
- package/dist/src/plugins/pagination/index.js.map +1 -0
- package/dist/src/plugins/pagination/index.test.d.ts +1 -0
- package/dist/src/plugins/pagination/index.test.js +129 -0
- package/dist/src/plugins/pagination/index.test.js.map +1 -0
- package/dist/src/plugins/pagination/specs/IPaginateOptions.d.ts +51 -0
- package/dist/src/plugins/pagination/specs/IPaginateOptions.js +3 -0
- package/dist/src/plugins/pagination/specs/IPaginateOptions.js.map +1 -0
- package/dist/src/utils/logger.d.ts +11 -0
- package/dist/src/utils/logger.js +54 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/testingConfigurations.d.ts +8 -0
- package/dist/src/utils/testingConfigurations.js +17 -0
- package/dist/src/utils/testingConfigurations.js.map +1 -0
- package/dist/tests/testingMongoUpdates/1.0.0.d.ts +5 -0
- package/dist/tests/testingMongoUpdates/1.0.0.js +27 -0
- package/dist/tests/testingMongoUpdates/1.0.0.js.map +1 -0
- package/dist/tests/testingMongoUpdates/1.0.1.d.ts +5 -0
- package/dist/tests/testingMongoUpdates/1.0.1.js +22 -0
- package/dist/tests/testingMongoUpdates/1.0.1.js.map +1 -0
- package/package.json +63 -0
- package/src/config/configs.ts +27 -0
- package/src/config/constants.ts +122 -0
- package/src/config/init.ts +23 -0
- package/src/config/mongooseConfigs.ts +178 -0
- package/src/index.ts +13 -0
- package/src/mongoClient.ts +122 -0
- package/src/mongoUpdater.test.ts +286 -0
- package/src/mongoUpdater.ts +423 -0
- package/src/mongoUtils.test.ts +23 -0
- package/src/mongoUtils.ts +322 -0
- package/src/plugins/pagination/index.test.ts +140 -0
- package/src/plugins/pagination/index.ts +96 -0
- package/src/plugins/pagination/specs/IPaginateOptions.ts +51 -0
- package/src/utils/logger.ts +53 -0
- package/src/utils/testingConfigurations.ts +13 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mongoUtils = exports.MongoUtils = void 0;
|
|
4
|
+
// ==========================================
|
|
5
|
+
// Mongo utilities
|
|
6
|
+
// ==========================================
|
|
7
|
+
const general_utils_1 = require("@villedemontreal/general-utils");
|
|
8
|
+
const logger_1 = require("@villedemontreal/logger");
|
|
9
|
+
const fs = require("fs-extra");
|
|
10
|
+
const HttpStatusCodes = require("http-status-codes");
|
|
11
|
+
const _ = require("lodash");
|
|
12
|
+
const mongodb_memory_server_core_1 = require("mongodb-memory-server-core");
|
|
13
|
+
const mongoose = require("mongoose");
|
|
14
|
+
const constants_1 = require("./config/constants");
|
|
15
|
+
/**
|
|
16
|
+
* Mongo utilities
|
|
17
|
+
*/
|
|
18
|
+
class MongoUtils {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.useReplSet = false;
|
|
21
|
+
this.mockgosseMockedFlag = 'mocked';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Mocks the Mongo databases created through Mongoose.
|
|
25
|
+
*
|
|
26
|
+
* IMPORTANT!!
|
|
27
|
+
* For the "mochaInstance" parameter to be the proper
|
|
28
|
+
* one, this function must be called from a *regular function* in a
|
|
29
|
+
* test file, not from an *arrow function*! For more informations,
|
|
30
|
+
* see : https://github.com/mochajs/mocha/issues/2018
|
|
31
|
+
*
|
|
32
|
+
* Note that, currently, once this mocking is in place,
|
|
33
|
+
* it can't be removed. You should only call this function
|
|
34
|
+
* during testing!
|
|
35
|
+
*
|
|
36
|
+
* If Mongoose is already mocked, the function does nothing.
|
|
37
|
+
*
|
|
38
|
+
* @param mocha from a Mocha test file, pass "this" as the value
|
|
39
|
+
* for this parameter or "null" from elsewhere.
|
|
40
|
+
*
|
|
41
|
+
* @param mongoServerVersion the Mongo version to use.
|
|
42
|
+
* Pass null (or undefined) to use the default version
|
|
43
|
+
* downloaded by mongodb-memory-server.
|
|
44
|
+
*/
|
|
45
|
+
async mockMongoose(mochaInstance, mongoServerVersion, useReplSet = false) {
|
|
46
|
+
// ==========================================
|
|
47
|
+
// We only mock the database if it's
|
|
48
|
+
// not already so.
|
|
49
|
+
// ==========================================
|
|
50
|
+
if (!this.mongoMemServer) {
|
|
51
|
+
// this.useReplSet = useReplSet;
|
|
52
|
+
// ==========================================
|
|
53
|
+
// Path to download the mocked Mongo server to.
|
|
54
|
+
// We make sure this folder is wihtin the application
|
|
55
|
+
// so when the application is mounted in a Docker
|
|
56
|
+
// container, the server will not be downloaded
|
|
57
|
+
// over and over.
|
|
58
|
+
// ==========================================
|
|
59
|
+
const downloadDirPath = constants_1.constants.appRoot + '/temp/mockServer';
|
|
60
|
+
if (!fs.existsSync(downloadDirPath)) {
|
|
61
|
+
fs.mkdirsSync(downloadDirPath);
|
|
62
|
+
}
|
|
63
|
+
// ==========================================
|
|
64
|
+
// Data directory
|
|
65
|
+
// ==========================================
|
|
66
|
+
const dataRootPath = downloadDirPath + '/data';
|
|
67
|
+
if (!fs.existsSync(dataRootPath)) {
|
|
68
|
+
fs.mkdirsSync(dataRootPath);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
await general_utils_1.utils.clearDir(dataRootPath);
|
|
72
|
+
}
|
|
73
|
+
const dataPath = `${dataRootPath}/${Date.now()}`;
|
|
74
|
+
fs.mkdirsSync(dataPath);
|
|
75
|
+
// ==========================================
|
|
76
|
+
// Increases the Mocha timeout to allow more time to
|
|
77
|
+
// download the test server, if required.
|
|
78
|
+
// ==========================================
|
|
79
|
+
if (mochaInstance) {
|
|
80
|
+
if (!mochaInstance.timeout || !_.isFunction(mochaInstance.timeout)) {
|
|
81
|
+
throw new Error(`The "mocha" parameter passed to the "mockMongoose(...)" method ` +
|
|
82
|
+
`doesn't seems to be of the correct type. Make sure the function in which you ` +
|
|
83
|
+
`call "mockMongoose(...)" is itself a *regular* function, not an *arrow* function. ` +
|
|
84
|
+
`Have a look at https://github.com/mochajs/mocha/issues/2018 for more infos.`);
|
|
85
|
+
}
|
|
86
|
+
mochaInstance.timeout(120000);
|
|
87
|
+
}
|
|
88
|
+
// Voir https://www.npmjs.com/package/mongodb-memory-server pour les options
|
|
89
|
+
const memoryServerOption = {
|
|
90
|
+
instance: {
|
|
91
|
+
dbPath: dataPath // by default create in temp directory,
|
|
92
|
+
},
|
|
93
|
+
binary: {
|
|
94
|
+
version: mongoServerVersion ? mongoServerVersion : 'latest',
|
|
95
|
+
downloadDir: downloadDirPath // by default node_modules/.cache/mongodb-memory-server/mongodb-binaries
|
|
96
|
+
},
|
|
97
|
+
debug: false
|
|
98
|
+
};
|
|
99
|
+
if (useReplSet) {
|
|
100
|
+
const replSetOptions = Object.assign(Object.assign({}, memoryServerOption), { replSet: { count: 3 } });
|
|
101
|
+
this.mongoMemServer = await mongodb_memory_server_core_1.MongoMemoryReplSet.create(replSetOptions);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// Create mock
|
|
105
|
+
this.mongoMemServer = await mongodb_memory_server_core_1.MongoMemoryServer.create(memoryServerOption);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return this.mongoMemServer;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Drop all mocked Mongo databases.
|
|
112
|
+
*
|
|
113
|
+
*/
|
|
114
|
+
async dropMockedDatabases() {
|
|
115
|
+
if (this.mongoMemServer) {
|
|
116
|
+
await mongoose.disconnect();
|
|
117
|
+
await this.mongoMemServer.stop();
|
|
118
|
+
this.mongoMemServer = null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async getMockedServerPort() {
|
|
122
|
+
const mongooseConnection = mongoose[this.mockgosseMockedFlag];
|
|
123
|
+
if (mongooseConnection && this.mongoMemServer && !this.useReplSet) {
|
|
124
|
+
return this.mongoMemServer.instanceInfo.port;
|
|
125
|
+
}
|
|
126
|
+
if (mongooseConnection && this.mongoMemServer && this.useReplSet) {
|
|
127
|
+
const servers = this.mongoMemServer.servers;
|
|
128
|
+
let port = null;
|
|
129
|
+
for (const serv of servers) {
|
|
130
|
+
if (serv.instanceInfo.instance.isInstancePrimary) {
|
|
131
|
+
port = serv.instanceInfo.port;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return port;
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Validates if an object is a Mongoose
|
|
141
|
+
* error.
|
|
142
|
+
*/
|
|
143
|
+
isMongooseError(obj) {
|
|
144
|
+
if (_.isEmpty(obj)) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (_.isEmpty(obj.errors) && 'kind' in obj && 'path' in obj && 'message' in obj) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
Object.keys(obj.errors).forEach(errorKey => {
|
|
151
|
+
const errorObject = obj.errors[errorKey];
|
|
152
|
+
if (!('kind' in errorObject) || !('path' in errorObject) || !('message' in errorObject)) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
});
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Validates if an object is a plain
|
|
161
|
+
* Mongo error.
|
|
162
|
+
*/
|
|
163
|
+
isPlainMongoError(errorObject) {
|
|
164
|
+
if (_.isEmpty(errorObject)) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
if (!('code' in errorObject) ||
|
|
168
|
+
!('name' in errorObject) ||
|
|
169
|
+
!('errmsg' in errorObject) ||
|
|
170
|
+
!('message' in errorObject)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Creates an Api eror from an error thrown
|
|
177
|
+
* by Mongoose.
|
|
178
|
+
*
|
|
179
|
+
* If the specified error is not a Mongo/Mongoose error, it
|
|
180
|
+
* will be returned as is.
|
|
181
|
+
*
|
|
182
|
+
* @param error the Mongo/Mongoose error object
|
|
183
|
+
* @param publicMessage a public message to be used in the
|
|
184
|
+
* generated error. Fopr example : "The user is invalid".
|
|
185
|
+
*/
|
|
186
|
+
convertMongoOrMongooseErrorToApiError(err, publicMessage) {
|
|
187
|
+
if (!err) {
|
|
188
|
+
return general_utils_1.createServerError('Empty error object');
|
|
189
|
+
}
|
|
190
|
+
let errClean = err;
|
|
191
|
+
// ==========================================
|
|
192
|
+
// Plain Mongo error
|
|
193
|
+
// ==========================================
|
|
194
|
+
if (this.isPlainMongoError(errClean)) {
|
|
195
|
+
// ==========================================
|
|
196
|
+
// Duplicate key error?
|
|
197
|
+
// We create an error with a "Conflit" http status
|
|
198
|
+
// code.
|
|
199
|
+
// ==========================================
|
|
200
|
+
if (errClean.code === constants_1.constants.mongo.mongoErrorCodes.DUPLICATE_KEY) {
|
|
201
|
+
return general_utils_1.createError(general_utils_1.globalConstants.errors.apiGeneralErrors.codes.DUPLICATE_KEY, publicMessage)
|
|
202
|
+
.httpStatus(HttpStatusCodes.CONFLICT)
|
|
203
|
+
.publicMessage(publicMessage)
|
|
204
|
+
.logLevel(logger_1.LogLevel.INFO)
|
|
205
|
+
.logStackTrace(false)
|
|
206
|
+
.build();
|
|
207
|
+
}
|
|
208
|
+
// ==========================================
|
|
209
|
+
// Unmanaged Mongo error, we return it as is.
|
|
210
|
+
// ==========================================
|
|
211
|
+
return errClean;
|
|
212
|
+
}
|
|
213
|
+
if (this.isMongooseError(errClean)) {
|
|
214
|
+
// ==========================================
|
|
215
|
+
// Mongoose error
|
|
216
|
+
// ==========================================
|
|
217
|
+
if (_.isEmpty(errClean.errors)) {
|
|
218
|
+
// ==========================================
|
|
219
|
+
// Invalid id
|
|
220
|
+
// ==========================================
|
|
221
|
+
if (errClean.kind === constants_1.constants.mongo.mongoose.errorKinds.OBJECT_ID &&
|
|
222
|
+
errClean.name === constants_1.constants.mongo.mongoose.errorNames.CAST_ERROR) {
|
|
223
|
+
throw general_utils_1.createNotFoundError('Invalid ObjectId id', publicMessage);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
const error = errClean;
|
|
227
|
+
errClean = {
|
|
228
|
+
errors: [error]
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
let errorDetails;
|
|
233
|
+
if (errClean.errors && !_.isEmpty(errClean.errors)) {
|
|
234
|
+
errorDetails = [];
|
|
235
|
+
Object.keys(errClean.errors).forEach(errorKey => {
|
|
236
|
+
const errorMessage = errClean.errors[errorKey];
|
|
237
|
+
const errorDetail = {
|
|
238
|
+
code: errorMessage.kind,
|
|
239
|
+
target: errorMessage.path,
|
|
240
|
+
message: errorMessage.message
|
|
241
|
+
};
|
|
242
|
+
errorDetails.push(errorDetail);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
throw general_utils_1.createInvalidParameterError(publicMessage, errorDetails);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
// ==========================================
|
|
249
|
+
// Not a Mongo or Mongoose error, we return it
|
|
250
|
+
// as is.
|
|
251
|
+
// ==========================================
|
|
252
|
+
return errClean;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Converts a Mongoose Document to a plain Pojo.
|
|
257
|
+
*/
|
|
258
|
+
convertMongooseDocumentToPlainObject(document) {
|
|
259
|
+
if (!document) {
|
|
260
|
+
return document;
|
|
261
|
+
}
|
|
262
|
+
const pojo = document.toObject();
|
|
263
|
+
// ==========================================
|
|
264
|
+
// Converts the "_id" property to "id"
|
|
265
|
+
// ==========================================
|
|
266
|
+
// tslint:disable-next-line:no-string-literal
|
|
267
|
+
pojo['id'] = pojo['_id'].toString();
|
|
268
|
+
// tslint:disable-next-line:no-string-literal
|
|
269
|
+
delete pojo['_id'];
|
|
270
|
+
// ==========================================
|
|
271
|
+
// Removes the "__v"
|
|
272
|
+
// ==========================================
|
|
273
|
+
// tslint:disable-next-line:no-string-literal
|
|
274
|
+
delete pojo['__v'];
|
|
275
|
+
return pojo;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
exports.MongoUtils = MongoUtils;
|
|
279
|
+
exports.mongoUtils = new MongoUtils();
|
|
280
|
+
//# sourceMappingURL=mongoUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoUtils.js","sourceRoot":"","sources":["../../src/mongoUtils.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAC7C,kBAAkB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C;SAChE;aAAM;YACL,6CAA6C;YAC7C,8CAA8C;YAC9C,SAAS;YACT,6CAA6C;YAC7C,OAAO,QAAQ,CAAC;SACjB;IACH,CAAC;IAED;;OAEG;IACI,oCAAoC,CAAI,QAA+B;QAC5E,IAAI,CAAC,QAAQ,EAAE;YACb,OAAO,QAAQ,CAAC;SACjB;QAED,MAAM,IAAI,GAAM,QAAQ,CAAC,QAAQ,EAAO,CAAC;QAEzC,6CAA6C;QAC7C,sCAAsC;QACtC,6CAA6C;QAC7C,6CAA6C;QAC7C,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;QACpC,6CAA6C;QAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;QAEnB,6CAA6C;QAC7C,oBAAoB;QACpB,6CAA6C;QAC7C,6CAA6C;QAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;QAEnB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAvSD,gCAuSC;AACU,QAAA,UAAU,GAAe,IAAI,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const mongodb_memory_server_core_1 = require("mongodb-memory-server-core");
|
|
5
|
+
const mongoUtils_1 = require("./mongoUtils");
|
|
6
|
+
describe('MongoUtils - #mockMongoose', () => {
|
|
7
|
+
/*
|
|
8
|
+
It is mandatory to create a new instance of MongoUtils to test the function mockMongoose as the singleton will keep its parameters instanced if used again. The parameter mongoMemServer, if instanciated by a first call,
|
|
9
|
+
won't be changed on a second one, as if the memory server is already mocked, nothing happens.
|
|
10
|
+
*/
|
|
11
|
+
it('should return a mongo memory server', async function () {
|
|
12
|
+
const mongoUtils = new mongoUtils_1.MongoUtils();
|
|
13
|
+
const memServ = await mongoUtils.mockMongoose(this, null, false);
|
|
14
|
+
chai_1.assert.isDefined(memServ);
|
|
15
|
+
chai_1.assert.instanceOf(memServ, mongodb_memory_server_core_1.MongoMemoryServer);
|
|
16
|
+
});
|
|
17
|
+
it('should return a mongo memory replica set', async function () {
|
|
18
|
+
const mongoUtils = new mongoUtils_1.MongoUtils();
|
|
19
|
+
const memServ = await mongoUtils.mockMongoose(this, null, true);
|
|
20
|
+
chai_1.assert.isDefined(memServ);
|
|
21
|
+
chai_1.assert.instanceOf(memServ, mongodb_memory_server_core_1.MongoMemoryReplSet);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=mongoUtils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoUtils.test.js","sourceRoot":"","sources":["../../src/mongoUtils.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,2EAAmF;AACnF,6CAA0C;AAE1C,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C;;;MAGE;IACF,EAAE,CAAC,qCAAqC,EAAE,KAAK;QAC7C,MAAM,UAAU,GAAG,IAAI,uBAAU,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACjE,aAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC1B,aAAM,CAAC,UAAU,CAAC,OAAO,EAAE,8CAAiB,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAE,KAAK;QAClD,MAAM,UAAU,GAAG,IAAI,uBAAU,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAChE,aAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC1B,aAAM,CAAC,UAAU,CAAC,OAAO,EAAE,+CAAkB,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IPaginateOptions } from './specs/IPaginateOptions';
|
|
2
|
+
/**
|
|
3
|
+
* @param {Schema} schema
|
|
4
|
+
*/
|
|
5
|
+
export declare function mongoosePaginate(schema: any): void;
|
|
6
|
+
export declare class PaginateBuilder {
|
|
7
|
+
private static readonly defaultOptions;
|
|
8
|
+
static getOptions(...options: IPaginateOptions[]): IPaginateOptions;
|
|
9
|
+
static executeQueries(model: any, query: any, options: IPaginateOptions): [Promise<any[]>, Promise<number>];
|
|
10
|
+
static processResult(promises: any[], options: IPaginateOptions, callback: (error: Error, result: any) => void): Promise<any>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaginateBuilder = exports.mongoosePaginate = void 0;
|
|
4
|
+
function paginate(q, options, callback) {
|
|
5
|
+
const optionsClean = PaginateBuilder.getOptions(paginate.options, options);
|
|
6
|
+
const query = q || {};
|
|
7
|
+
const promises = PaginateBuilder.executeQueries(this, query, optionsClean);
|
|
8
|
+
return PaginateBuilder.processResult(promises, optionsClean, callback);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @param {Schema} schema
|
|
12
|
+
*/
|
|
13
|
+
function mongoosePaginate(schema) {
|
|
14
|
+
schema.statics.paginate = paginate;
|
|
15
|
+
}
|
|
16
|
+
exports.mongoosePaginate = mongoosePaginate;
|
|
17
|
+
class PaginateBuilder {
|
|
18
|
+
static getOptions(...options) {
|
|
19
|
+
return Object.assign({}, PaginateBuilder.defaultOptions, ...options);
|
|
20
|
+
}
|
|
21
|
+
static executeQueries(model, query, options) {
|
|
22
|
+
const { select, sort, populate, lean, leanWithId, limit, offset } = options;
|
|
23
|
+
let itemsQuery;
|
|
24
|
+
if (leanWithId) {
|
|
25
|
+
// only to prevent "'leanWithId' is declared but its value is never read"
|
|
26
|
+
}
|
|
27
|
+
if (limit > 0) {
|
|
28
|
+
itemsQuery = model
|
|
29
|
+
.find(query)
|
|
30
|
+
.select(select)
|
|
31
|
+
.sort(sort)
|
|
32
|
+
.skip(offset)
|
|
33
|
+
.limit(limit)
|
|
34
|
+
.lean(lean);
|
|
35
|
+
if (populate) {
|
|
36
|
+
[].concat(populate).forEach(item => itemsQuery.populate(item));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return [itemsQuery && limit > 0 ? itemsQuery.exec() : Promise.resolve([]), model.countDocuments(query).exec()];
|
|
40
|
+
}
|
|
41
|
+
static processResult(promises, options, callback) {
|
|
42
|
+
const { lean, leanWithId, limit, offset } = options;
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
Promise.all(promises).then(data => {
|
|
45
|
+
const items = data[0];
|
|
46
|
+
const count = data[1];
|
|
47
|
+
const result = { paging: { limit, offset, totalCount: count } };
|
|
48
|
+
if (lean && leanWithId) {
|
|
49
|
+
result.items = items.map((doc) => {
|
|
50
|
+
doc.id = String(doc._id);
|
|
51
|
+
delete doc._id;
|
|
52
|
+
delete doc.__v;
|
|
53
|
+
return doc;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
result.items = items;
|
|
58
|
+
}
|
|
59
|
+
if (typeof callback === 'function') {
|
|
60
|
+
return callback(null, result);
|
|
61
|
+
}
|
|
62
|
+
resolve(result);
|
|
63
|
+
}, error => {
|
|
64
|
+
if (typeof callback === 'function') {
|
|
65
|
+
return callback(error, null);
|
|
66
|
+
}
|
|
67
|
+
reject(error);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.PaginateBuilder = PaginateBuilder;
|
|
73
|
+
PaginateBuilder.defaultOptions = Object.freeze({
|
|
74
|
+
lean: false,
|
|
75
|
+
leanWithId: true,
|
|
76
|
+
limit: 10,
|
|
77
|
+
offset: 0
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/pagination/index.ts"],"names":[],"mappings":";;;AAEA,SAAS,QAAQ,CAAC,CAAM,EAAE,OAAyB,EAAE,QAA6C;IAChG,MAAM,YAAY,GAAG,eAAe,CAAC,UAAU,CAAE,QAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAEpF,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;IACtB,MAAM,QAAQ,GAAG,eAAe,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;IAE3E,OAAO,eAAe,CAAC,aAAa,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;AACzE,CAAC;AAED;;GAEG;AAEH,SAAgB,gBAAgB,CAAC,MAAW;IAC1C,MAAM,CAAC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACrC,CAAC;AAFD,4CAEC;AAED,MAAa,eAAe;IAQnB,MAAM,CAAC,UAAU,CAAC,GAAG,OAA2B;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,eAAe,CAAC,cAAc,EAAE,GAAG,OAAO,CAAC,CAAC;IACvE,CAAC;IAEM,MAAM,CAAC,cAAc,CAAC,KAAU,EAAE,KAAU,EAAE,OAAyB;QAC5E,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAC5E,IAAI,UAAe,CAAC;QAEpB,IAAI,UAAU,EAAE;YACd,yEAAyE;SAC1E;QAED,IAAI,KAAK,GAAG,CAAC,EAAE;YACb,UAAU,GAAG,KAAK;iBACf,IAAI,CAAC,KAAK,CAAC;iBACX,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,CAAC,GAAG,CAAC,CAAC;wBACzB,OAAO,GAAG,CAAC,GAAG,CAAC;wBACf,OAAO,GAAG,CAAC,GAAG,CAAC;wBACf,OAAO,GAAG,CAAC;oBACb,CAAC,CAAC,CAAC;iBACJ;qBAAM;oBACL,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;iBACtB;gBAED,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;oBAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;iBAC/B;gBAED,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,EACD,KAAK,CAAC,EAAE;gBACN,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;oBAClC,OAAO,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;iBAC9B;gBACD,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;;AA3EH,0CA4EC;AA3EyB,8BAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IACrD,IAAI,EAAE,KAAK;IACX,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,CAAC;CACV,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Some way of using chai requires disabling this rule:
|
|
3
|
+
// tslint:disable:no-unused-expression
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const chai = require("chai");
|
|
6
|
+
const mongoose = require("mongoose");
|
|
7
|
+
const constants_1 = require("../../config/constants");
|
|
8
|
+
const mongoUtils_1 = require("../../mongoUtils");
|
|
9
|
+
const index_1 = require("./index");
|
|
10
|
+
const expect = chai.expect;
|
|
11
|
+
const authorSchema = new mongoose.Schema({ name: String });
|
|
12
|
+
const authorModel = mongoose.model('Author', authorSchema);
|
|
13
|
+
const bookSchema = new mongoose.Schema({
|
|
14
|
+
title: String,
|
|
15
|
+
date: Date,
|
|
16
|
+
author: {
|
|
17
|
+
type: String,
|
|
18
|
+
ref: 'Author'
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
bookSchema.plugin(index_1.mongoosePaginate);
|
|
22
|
+
const bookModel = mongoose.model('Book', bookSchema);
|
|
23
|
+
describe('plugin pagination', () => {
|
|
24
|
+
before(async function () {
|
|
25
|
+
this.timeout(120000);
|
|
26
|
+
// Makes sure Mongoose is mocked, but not in Jenkins as we will start a dedicated mongodb container.
|
|
27
|
+
const mockedDb = await mongoUtils_1.mongoUtils.mockMongoose(this, constants_1.constants.testsConfig.mockServer.serverVersion);
|
|
28
|
+
const connString = mockedDb.getUri();
|
|
29
|
+
await mongoose.connect(connString, { useNewUrlParser: true });
|
|
30
|
+
});
|
|
31
|
+
before(async function () {
|
|
32
|
+
this.timeout(10000);
|
|
33
|
+
let book;
|
|
34
|
+
const books = [];
|
|
35
|
+
const date = new Date();
|
|
36
|
+
return authorModel.create({ name: 'Arthur Conan Doyle' }).then(author => {
|
|
37
|
+
for (let i = 1; i <= 100; i++) {
|
|
38
|
+
book = new bookModel({
|
|
39
|
+
title: 'Book #' + i,
|
|
40
|
+
date: new Date(date.getTime() + i),
|
|
41
|
+
author: author._id
|
|
42
|
+
});
|
|
43
|
+
books.push(book);
|
|
44
|
+
}
|
|
45
|
+
return bookModel.create(books);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
it('returns promise', () => {
|
|
49
|
+
const promise = bookModel.paginate();
|
|
50
|
+
expect(promise.then).to.be.an.instanceof(Function);
|
|
51
|
+
});
|
|
52
|
+
it('calls callback', done => {
|
|
53
|
+
bookModel.paginate({}, {}, (err, result) => {
|
|
54
|
+
expect(err).to.be.null;
|
|
55
|
+
expect(result).to.be.an.instanceOf(Object);
|
|
56
|
+
done();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('paginates', () => {
|
|
60
|
+
it('with criteria', () => {
|
|
61
|
+
return bookModel.paginate({ title: 'Book #10' }).then((result) => {
|
|
62
|
+
expect(result.items).to.have.length(1);
|
|
63
|
+
expect(result.items[0].title).to.equal('Book #10');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
it('with default options (limit=10, lean=false)', () => {
|
|
67
|
+
return bookModel.paginate().then((result) => {
|
|
68
|
+
expect(result.items).to.have.length(10);
|
|
69
|
+
expect(result.items[0]).to.be.an.instanceof(mongoose.Document);
|
|
70
|
+
expect(result.paging.totalCount).to.equal(100);
|
|
71
|
+
expect(result.paging.limit).to.equal(10);
|
|
72
|
+
expect(result.paging.offset).to.equal(0);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
it('with offset and limit', () => {
|
|
76
|
+
return bookModel.paginate({}, { offset: 30, limit: 20 }).then((result) => {
|
|
77
|
+
expect(result.items).to.have.length(20);
|
|
78
|
+
expect(result.paging.totalCount).to.equal(100);
|
|
79
|
+
expect(result.paging.limit).to.equal(20);
|
|
80
|
+
expect(result.paging.offset).to.equal(30);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
it('with zero limit', () => {
|
|
84
|
+
return bookModel.paginate({}, { page: 1, limit: 0 }).then((result) => {
|
|
85
|
+
expect(result.items).to.have.length(0);
|
|
86
|
+
expect(result.paging.totalCount).to.equal(100);
|
|
87
|
+
expect(result.paging.limit).to.equal(0);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
it('with select', () => {
|
|
91
|
+
return bookModel.paginate({}, { select: 'title' }).then((result) => {
|
|
92
|
+
expect(result.items[0].title).to.exist;
|
|
93
|
+
expect(result.items[0].date).to.not.exist;
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
it('with sort', () => {
|
|
97
|
+
return bookModel.paginate({}, { sort: { date: -1 } }).then((result) => {
|
|
98
|
+
expect(result.items[0].title).to.equal('Book #100');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
it('with populate', () => {
|
|
102
|
+
return bookModel.paginate({}, { populate: 'author' }).then((result) => {
|
|
103
|
+
expect(result.items[0].author.name).to.equal('Arthur Conan Doyle');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
describe('with lean', () => {
|
|
107
|
+
it('with default leanWithId=true', () => {
|
|
108
|
+
return bookModel.paginate({}, { lean: true }).then((result) => {
|
|
109
|
+
expect(result.items[0]).to.not.be.an.instanceof(mongoose.Document);
|
|
110
|
+
expect(result.items[0].id).to.exist;
|
|
111
|
+
expect(result.items[0]).to.not.have.property('_id');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
it('with leanWithId=false', () => {
|
|
115
|
+
return bookModel.paginate({}, { lean: true, leanWithId: false }).then((result) => {
|
|
116
|
+
expect(result.items[0]).to.not.be.an.instanceof(mongoose.Document);
|
|
117
|
+
expect(result.items[0]).to.not.have.property('id');
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
after(done => {
|
|
123
|
+
mongoose.connection.db.dropDatabase(done);
|
|
124
|
+
});
|
|
125
|
+
after(done => {
|
|
126
|
+
mongoose.disconnect(done);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../../../src/plugins/pagination/index.test.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,sCAAsC;;AAGtC,6BAA6B;AAC7B,qCAAqC;AACrC,sDAAmD;AACnD,iDAA8C;AAC9C,mCAA2C;AAE3C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;AAE3B,MAAM,YAAY,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3D,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,YAAY,CAAC,CA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type {string}
|
|
6
|
+
* @memberof IPaginateOptions
|
|
7
|
+
*/
|
|
8
|
+
select?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Sort order
|
|
11
|
+
* http://mongoosejs.com/docs/api.html#query_Query-sort
|
|
12
|
+
* @type {*}
|
|
13
|
+
* @memberof IPaginateOptions
|
|
14
|
+
*/
|
|
15
|
+
sort?: any;
|
|
16
|
+
/**
|
|
17
|
+
* Paths which should be populated with other documents.
|
|
18
|
+
* http://mongoosejs.com/docs/api.html#query_Query-populate
|
|
19
|
+
* @type {string}
|
|
20
|
+
* @memberof IPaginateOptions
|
|
21
|
+
*/
|
|
22
|
+
populate?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Should return plain javascript objects instead of Mongoose documents?
|
|
25
|
+
* default false
|
|
26
|
+
* @type {boolean}
|
|
27
|
+
* @memberof IPaginateOptions
|
|
28
|
+
*/
|
|
29
|
+
lean?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* If lean and leanWithId are true, adds id field with string representation of _id to every document
|
|
32
|
+
* default true
|
|
33
|
+
* @type {boolean}
|
|
34
|
+
* @memberof IPaginateOptions
|
|
35
|
+
*/
|
|
36
|
+
leanWithId?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Use offset to set skip position
|
|
39
|
+
* default 0
|
|
40
|
+
* @type {number}
|
|
41
|
+
* @memberof IPaginateOptions
|
|
42
|
+
*/
|
|
43
|
+
offset?: number;
|
|
44
|
+
/**
|
|
45
|
+
* limit the items returned
|
|
46
|
+
* default 10
|
|
47
|
+
* @type {number}
|
|
48
|
+
* @memberof IPaginateOptions
|
|
49
|
+
*/
|
|
50
|
+
limit?: number;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPaginateOptions.js","sourceRoot":"","sources":["../../../../../src/plugins/pagination/specs/IPaginateOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ILogger } from '@villedemontreal/logger';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Logger.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createLogger(name: string): ILogger;
|
|
6
|
+
/**
|
|
7
|
+
* A Logger that uses a dummy cid provider.
|
|
8
|
+
*
|
|
9
|
+
* Only use this when running the tests!
|
|
10
|
+
*/
|
|
11
|
+
export declare function getTestingLoggerCreator(): (name: string) => ILogger;
|