@villedemontreal/mongo 6.7.2 → 6.7.3
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/dist/scripts/index.d.ts +6 -0
- package/dist/scripts/lint.d.ts +6 -0
- package/dist/scripts/lintFix.d.ts +6 -0
- package/dist/scripts/showCoverage.d.ts +13 -0
- package/dist/scripts/test.d.ts +13 -0
- package/dist/scripts/testUnits.d.ts +15 -0
- package/dist/scripts/watch.d.ts +14 -0
- package/dist/src/config/configs.d.ts +19 -0
- package/dist/src/config/constants.d.ts +85 -0
- package/dist/src/config/init.d.ts +9 -0
- package/dist/src/config/mongooseConfigs.d.ts +73 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/mongoClient.d.ts +19 -0
- package/dist/src/mongoUpdater.d.ts +103 -0
- package/dist/src/mongoUpdater.test.d.ts +1 -0
- package/dist/src/mongoUtils.d.ts +68 -0
- package/dist/src/mongoUtils.test.d.ts +0 -0
- package/dist/src/plugins/pagination/index.d.ts +11 -0
- package/dist/src/plugins/pagination/index.test.d.ts +1 -0
- package/dist/src/plugins/pagination/specs/IPaginateOptions.d.ts +51 -0
- package/dist/src/utils/logger.d.ts +11 -0
- package/dist/src/utils/testingConfigurations.d.ts +8 -0
- package/dist/tests/testingMongoUpdates/1.0.0.d.ts +5 -0
- package/dist/tests/testingMongoUpdates/1.0.1.d.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from '@caporal/core';
|
|
2
|
+
import { ScriptBase } from '@villedemontreal/scripting/dist/src';
|
|
3
|
+
export interface Options {
|
|
4
|
+
report?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class ShowCoverageScript extends ScriptBase<Options> {
|
|
7
|
+
get name(): string;
|
|
8
|
+
get description(): string;
|
|
9
|
+
protected get requiredDependencies(): string[];
|
|
10
|
+
protected configure(command: Command): Promise<void>;
|
|
11
|
+
protected main(): Promise<void>;
|
|
12
|
+
protected getReportDir(): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from '@caporal/core';
|
|
2
|
+
import { ScriptBase } from '@villedemontreal/scripting/dist/src';
|
|
3
|
+
export interface Options {
|
|
4
|
+
bail?: boolean;
|
|
5
|
+
jenkins?: boolean;
|
|
6
|
+
report?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class TestScript extends ScriptBase<Options> {
|
|
9
|
+
get name(): string;
|
|
10
|
+
get description(): string;
|
|
11
|
+
protected configure(command: Command): Promise<void>;
|
|
12
|
+
protected main(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command } from '@caporal/core';
|
|
2
|
+
import { ScriptBase } from '@villedemontreal/scripting/dist/src';
|
|
3
|
+
export interface Options {
|
|
4
|
+
bail?: boolean;
|
|
5
|
+
jenkins?: boolean;
|
|
6
|
+
report?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class TestUnitsScript extends ScriptBase<Options> {
|
|
9
|
+
get name(): string;
|
|
10
|
+
get description(): string;
|
|
11
|
+
protected configure(command: Command): Promise<void>;
|
|
12
|
+
protected get requiredDependencies(): string[];
|
|
13
|
+
private addQuotes;
|
|
14
|
+
protected main(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from '@caporal/core';
|
|
2
|
+
import { ScriptBase } from '@villedemontreal/scripting/dist/src';
|
|
3
|
+
export interface Options {
|
|
4
|
+
/**
|
|
5
|
+
* Disable the visual notification
|
|
6
|
+
*/
|
|
7
|
+
dn?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class WatchScript extends ScriptBase<Options> {
|
|
10
|
+
get name(): string;
|
|
11
|
+
get description(): string;
|
|
12
|
+
protected configure(command: Command): Promise<void>;
|
|
13
|
+
protected main(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ILogger } from '@villedemontreal/logger';
|
|
2
|
+
/**
|
|
3
|
+
* Lib configs
|
|
4
|
+
*/
|
|
5
|
+
export declare class Configs {
|
|
6
|
+
isWindows: boolean;
|
|
7
|
+
libRoot: string;
|
|
8
|
+
private _loggerCreator;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* The Logger creator
|
|
12
|
+
*/
|
|
13
|
+
get loggerCreator(): (name: string) => ILogger;
|
|
14
|
+
/**
|
|
15
|
+
* Sets the Logger creator.
|
|
16
|
+
*/
|
|
17
|
+
setLoggerCreator(loggerCreator: (name: string) => ILogger): void;
|
|
18
|
+
}
|
|
19
|
+
export declare const configs: Configs;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { IMongooseConfigs } from './mongooseConfigs';
|
|
2
|
+
/**
|
|
3
|
+
* Library constants
|
|
4
|
+
*/
|
|
5
|
+
export declare class Constants {
|
|
6
|
+
/**
|
|
7
|
+
* The library root. When this library is used
|
|
8
|
+
* as a dependency in a project, the "libRoot"
|
|
9
|
+
* will be the path to the dependency folder,
|
|
10
|
+
* inside the "node_modules".
|
|
11
|
+
*/
|
|
12
|
+
libRoot: string;
|
|
13
|
+
/**
|
|
14
|
+
* The app root. When this library is used
|
|
15
|
+
* as a dependency in a project, the "appRoot"
|
|
16
|
+
* will be the path to the root project!
|
|
17
|
+
*/
|
|
18
|
+
appRoot: string;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Base config to 'mock' a mongo server
|
|
22
|
+
*/
|
|
23
|
+
get testsConfig(): IMongooseConfigs;
|
|
24
|
+
/**
|
|
25
|
+
* Mongo constants
|
|
26
|
+
*/
|
|
27
|
+
get mongo(): {
|
|
28
|
+
testing: {
|
|
29
|
+
/**
|
|
30
|
+
* The "connectionString" to use for a mock
|
|
31
|
+
* Mongo server to be used instead of a real one.
|
|
32
|
+
* This option is only available on the "development"
|
|
33
|
+
* environment, or when tests are ran.
|
|
34
|
+
*/
|
|
35
|
+
MOCK_CONNECTION_STRING: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The names of the Mongo collections used in
|
|
39
|
+
* this application.
|
|
40
|
+
*/
|
|
41
|
+
collectionNames: {
|
|
42
|
+
/**
|
|
43
|
+
* Special collection that stores informations about the
|
|
44
|
+
* schema currently installed for the application.
|
|
45
|
+
*/
|
|
46
|
+
APP_SCHEMA: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Mongo error codes
|
|
50
|
+
*/
|
|
51
|
+
mongoErrorCodes: {
|
|
52
|
+
/**
|
|
53
|
+
* The code for a Mongo "duplicate key" error.
|
|
54
|
+
*/
|
|
55
|
+
DUPLICATE_KEY: number;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Mongoose constants
|
|
59
|
+
*/
|
|
60
|
+
mongoose: {
|
|
61
|
+
/**
|
|
62
|
+
* Mongoose error codes
|
|
63
|
+
*/
|
|
64
|
+
errorCodes: {
|
|
65
|
+
/**
|
|
66
|
+
* The code for a Mongoose "required" error.
|
|
67
|
+
*/
|
|
68
|
+
REQUIRED_FIELD: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Mongoose error kinds
|
|
72
|
+
*/
|
|
73
|
+
errorKinds: {
|
|
74
|
+
OBJECT_ID: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Mongoose error names
|
|
78
|
+
*/
|
|
79
|
+
errorNames: {
|
|
80
|
+
CAST_ERROR: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export declare const constants: Constants;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ILogger } from '@villedemontreal/logger';
|
|
2
|
+
/**
|
|
3
|
+
* Inits the library.
|
|
4
|
+
*/
|
|
5
|
+
export declare function init(loggerCreator: (name: string) => ILogger): void;
|
|
6
|
+
/**
|
|
7
|
+
* checks if the library has been initialized.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isInited(): boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export interface IMongooseConfigs {
|
|
2
|
+
/**
|
|
3
|
+
* The updater.mongoSchemaUpdatesDirPath
|
|
4
|
+
* is a required config.
|
|
5
|
+
*/
|
|
6
|
+
updater?: {
|
|
7
|
+
/**
|
|
8
|
+
* Name of the app schema collection name to use.
|
|
9
|
+
* Useful when multiple components use the same database.
|
|
10
|
+
*/
|
|
11
|
+
appSchemaCollectionName?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The path where to find update files.
|
|
14
|
+
*/
|
|
15
|
+
mongoSchemaUpdatesDirPath: string;
|
|
16
|
+
lockMaxAgeSeconds?: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @param applyUpdates Should the database be checked for missing
|
|
20
|
+
* updates and have them applied if required?
|
|
21
|
+
* Defaults to true.
|
|
22
|
+
*/
|
|
23
|
+
applyUpdates?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* If no connectionString is provided, "mock" will be
|
|
26
|
+
* used by default and a temporary Mongo server will
|
|
27
|
+
* be used.
|
|
28
|
+
*/
|
|
29
|
+
connectionString?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The Mongoose connection options.
|
|
32
|
+
*/
|
|
33
|
+
connectionOptions?: any;
|
|
34
|
+
mockServer?: {
|
|
35
|
+
/**
|
|
36
|
+
* @param mongoServerVersion the Mongo version to use.
|
|
37
|
+
*
|
|
38
|
+
* Pass null (or undefined) to use the default version
|
|
39
|
+
* downloaded by mockServer.
|
|
40
|
+
*/
|
|
41
|
+
serverVersion?: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Mongoose configs with default values.
|
|
46
|
+
*/
|
|
47
|
+
export declare class MongooseConfigs implements IMongooseConfigs {
|
|
48
|
+
/**
|
|
49
|
+
* @param applyUpdates Should the database be checked for missing
|
|
50
|
+
* updates and have them applied if required?
|
|
51
|
+
*/
|
|
52
|
+
applyUpdates: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* If no connectionString is provided, "mock" will be
|
|
55
|
+
* used by default and a temporary Mongo server will
|
|
56
|
+
* be used.
|
|
57
|
+
*/
|
|
58
|
+
connectionString: string;
|
|
59
|
+
connectionOptions: any;
|
|
60
|
+
updater: {
|
|
61
|
+
lockMaxAgeSeconds: number;
|
|
62
|
+
mongoSchemaUpdatesDirPath: string;
|
|
63
|
+
appSchemaCollectionName: string;
|
|
64
|
+
};
|
|
65
|
+
mockServer: {
|
|
66
|
+
serverVersion: string;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Overrides default configurations using the ones passed
|
|
70
|
+
* as parameters.
|
|
71
|
+
*/
|
|
72
|
+
constructor(overridingConfigs: IMongooseConfigs);
|
|
73
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as mongoose from 'mongoose';
|
|
2
|
+
import { IMongooseConfigs } from './config/mongooseConfigs';
|
|
3
|
+
/**
|
|
4
|
+
* This is the entry point to use this library to manage your
|
|
5
|
+
* Mongoose connections.
|
|
6
|
+
*
|
|
7
|
+
* It *must* be called when the application starts, before any
|
|
8
|
+
* connection is made to Mongo.
|
|
9
|
+
*
|
|
10
|
+
* @returns the Mongoose connection to Mongo.
|
|
11
|
+
*/
|
|
12
|
+
export declare function initMongoose(mongooseConfig: IMongooseConfigs): Promise<mongoose.Connection>;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the Mongoose connection.
|
|
15
|
+
*
|
|
16
|
+
* Will throw an error if Mongo haass not been initialized
|
|
17
|
+
* using the "initMongo()" function.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getMongooseConnection(): mongoose.Connection;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as MongoDb from 'mongodb';
|
|
2
|
+
/**
|
|
3
|
+
* Mongo updater
|
|
4
|
+
* Manages the updates of the mongo schemas
|
|
5
|
+
*/
|
|
6
|
+
export interface IMongoUpdater {
|
|
7
|
+
/**
|
|
8
|
+
* Validates that the application has been installed.
|
|
9
|
+
* This involves creating a special "appSchema" collection
|
|
10
|
+
* and document to track the application version and being able
|
|
11
|
+
* to update its schemas and documents...
|
|
12
|
+
*/
|
|
13
|
+
checkInstallation(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if the application needs update or not. Installs the updates
|
|
16
|
+
* if so.
|
|
17
|
+
*/
|
|
18
|
+
checkUpdates(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Locks the appSchema document.
|
|
21
|
+
*
|
|
22
|
+
* @returns true if the lock has been acquired succesfully
|
|
23
|
+
* or false if the document was already locked.
|
|
24
|
+
*/
|
|
25
|
+
lockAppSchemaDocument(): Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Unlocks the appSchema document.
|
|
28
|
+
*
|
|
29
|
+
* @returns true if the lock has been removed succesfully
|
|
30
|
+
* or false if the document was not locked.
|
|
31
|
+
*/
|
|
32
|
+
unlockAppSchemaDocument(): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Updates the app schema version stored in mongo database
|
|
35
|
+
*/
|
|
36
|
+
updateAppSchemaVersion(currentVersion: string, newVersion: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Installs the appSchema collection.
|
|
39
|
+
*/
|
|
40
|
+
installAppSchemaCollection(): Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets a list of available app schema update files.
|
|
43
|
+
*/
|
|
44
|
+
getAppSchemaUpdateFiles(currentVersion: string, newVersion: string): Promise<string[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Updates the app schema
|
|
47
|
+
*/
|
|
48
|
+
applyAppSchemaUpdates(currentVersion: string, newVersion: string): Promise<any>;
|
|
49
|
+
/**
|
|
50
|
+
* Gets the appSchema collection
|
|
51
|
+
*/
|
|
52
|
+
getAppSchemaCollection(): Promise<MongoDb.Collection>;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the current version from the appSchema document.
|
|
55
|
+
*/
|
|
56
|
+
getAppSchemaVersion(): Promise<string>;
|
|
57
|
+
}
|
|
58
|
+
export interface ISchemeInfo {
|
|
59
|
+
version: string;
|
|
60
|
+
lock: boolean;
|
|
61
|
+
lockTimestamp: number;
|
|
62
|
+
}
|
|
63
|
+
export declare class MongoUpdater implements IMongoUpdater {
|
|
64
|
+
private mongoDb;
|
|
65
|
+
/**
|
|
66
|
+
* The *relative* path to the directory where the
|
|
67
|
+
* update files are.
|
|
68
|
+
*/
|
|
69
|
+
private mongoSchemaUpdatesDirPath;
|
|
70
|
+
private lockMaxAgeSeconds;
|
|
71
|
+
private appSchemaCollectionName;
|
|
72
|
+
constructor(mongoDb: MongoDb.Db,
|
|
73
|
+
/**
|
|
74
|
+
* The *relative* path to the directory where the
|
|
75
|
+
* update files are.
|
|
76
|
+
*/
|
|
77
|
+
mongoSchemaUpdatesDirPath: string, lockMaxAgeSeconds: number, appSchemaCollectionName: string);
|
|
78
|
+
installAppSchemaCollection(): Promise<any>;
|
|
79
|
+
updateAppSchemaVersion(currentVersion: string, newVersion: string): Promise<void>;
|
|
80
|
+
getAppSchemaUpdateFiles(currentAppSchemaVersion: string, targetAppSchemaVersion: string): Promise<string[]>;
|
|
81
|
+
applyAppSchemaUpdates(currentVersion: string, newVersion: string): Promise<void>;
|
|
82
|
+
getAppSchemaCollection(): Promise<MongoDb.Collection>;
|
|
83
|
+
getAppSchemaVersion(): Promise<string>;
|
|
84
|
+
/**
|
|
85
|
+
* Tries to get the lock to modify Mongo's schemas.
|
|
86
|
+
*
|
|
87
|
+
* If a lock already exists, checks if it is too old.
|
|
88
|
+
* If too old, will create a new one... This is to prevents
|
|
89
|
+
* situations where a lock would have been taken by an app
|
|
90
|
+
* but that app *crashed* while the lock was on. We don't want
|
|
91
|
+
* suck lock to be active forever...
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
lockAppSchemaDocument(): Promise<boolean>;
|
|
95
|
+
unlockAppSchemaDocument(): Promise<boolean>;
|
|
96
|
+
checkInstallation(): Promise<void>;
|
|
97
|
+
checkUpdates: () => Promise<void>;
|
|
98
|
+
protected getAppSchemaFilesDirPath(): string;
|
|
99
|
+
/**
|
|
100
|
+
* Finds the latest Mongo update file version.
|
|
101
|
+
*/
|
|
102
|
+
protected findMongoAppSchemaTargetVersion(): string;
|
|
103
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ApiErrorAndInfo } from '@villedemontreal/general-utils';
|
|
2
|
+
import * as mocha from 'mocha';
|
|
3
|
+
import { MongoMemoryReplSet, MongoMemoryServer } from 'mongodb-memory-server-core';
|
|
4
|
+
import * as mongoose from 'mongoose';
|
|
5
|
+
/**
|
|
6
|
+
* Mongo utilities
|
|
7
|
+
*/
|
|
8
|
+
export declare class MongoUtils {
|
|
9
|
+
private mongoMemServer;
|
|
10
|
+
private useReplSet;
|
|
11
|
+
private mockgosseMockedFlag;
|
|
12
|
+
/**
|
|
13
|
+
* Mocks the Mongo databases created through Mongoose.
|
|
14
|
+
*
|
|
15
|
+
* IMPORTANT!!
|
|
16
|
+
* For the "mochaInstance" parameter to be the proper
|
|
17
|
+
* one, this function must be called from a *regular function* in a
|
|
18
|
+
* test file, not from an *arrow function*! For more informations,
|
|
19
|
+
* see : https://github.com/mochajs/mocha/issues/2018
|
|
20
|
+
*
|
|
21
|
+
* Note that, currently, once this mocking is in place,
|
|
22
|
+
* it can't be removed. You should only call this function
|
|
23
|
+
* during testing!
|
|
24
|
+
*
|
|
25
|
+
* If Mongoose is already mocked, the function does nothing.
|
|
26
|
+
*
|
|
27
|
+
* @param mocha from a Mocha test file, pass "this" as the value
|
|
28
|
+
* for this parameter or "null" from elsewhere.
|
|
29
|
+
*
|
|
30
|
+
* @param mongoServerVersion the Mongo version to use.
|
|
31
|
+
* Pass null (or undefined) to use the default version
|
|
32
|
+
* downloaded by mongodb-memory-server.
|
|
33
|
+
*/
|
|
34
|
+
mockMongoose(mochaInstance: mocha.Context, mongoServerVersion: string, useReplSet?: boolean): Promise<MongoMemoryServer | MongoMemoryReplSet>;
|
|
35
|
+
/**
|
|
36
|
+
* Drop all mocked Mongo databases.
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
dropMockedDatabases(): Promise<void>;
|
|
40
|
+
getMockedServerPort(): Promise<number>;
|
|
41
|
+
/**
|
|
42
|
+
* Validates if an object is a Mongoose
|
|
43
|
+
* error.
|
|
44
|
+
*/
|
|
45
|
+
isMongooseError(obj: any): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Validates if an object is a plain
|
|
48
|
+
* Mongo error.
|
|
49
|
+
*/
|
|
50
|
+
isPlainMongoError(errorObject: any): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Creates an Api eror from an error thrown
|
|
53
|
+
* by Mongoose.
|
|
54
|
+
*
|
|
55
|
+
* If the specified error is not a Mongo/Mongoose error, it
|
|
56
|
+
* will be returned as is.
|
|
57
|
+
*
|
|
58
|
+
* @param error the Mongo/Mongoose error object
|
|
59
|
+
* @param publicMessage a public message to be used in the
|
|
60
|
+
* generated error. Fopr example : "The user is invalid".
|
|
61
|
+
*/
|
|
62
|
+
convertMongoOrMongooseErrorToApiError(err: any, publicMessage: string): ApiErrorAndInfo | any;
|
|
63
|
+
/**
|
|
64
|
+
* Converts a Mongoose Document to a plain Pojo.
|
|
65
|
+
*/
|
|
66
|
+
convertMongooseDocumentToPlainObject<T>(document: T & mongoose.Document): T;
|
|
67
|
+
}
|
|
68
|
+
export declare const mongoUtils: MongoUtils;
|
|
File without changes
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface IPaginateOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Fields to return (by default returns all fields)
|
|
4
|
+
* http://mongoosejs.com/docs/api.html#query_Query-select
|
|
5
|
+
* @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,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;
|