@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
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) Ville de Montréal and other contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# @villedemontreal/mongo
|
|
2
|
+
Module d'utilitaires pour les connections de Mongo.
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
|
|
6
|
+
Installer la bibliothèque:
|
|
7
|
+
|
|
8
|
+
```shell
|
|
9
|
+
npm install --save @villedemontreal/mongo
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Configuration pour utilisation dans Docker
|
|
13
|
+
|
|
14
|
+
À lire si les tests fonctionnent bien en local mais timeout lors du build sur Jenkins.
|
|
15
|
+
|
|
16
|
+
Il est conseiller d'activer les traces de débogage si cela se produit. Voir plus bas dans ce document.
|
|
17
|
+
|
|
18
|
+
Mongo a une dépendance sur la libcurl. Cette librairie doit être présente dans l'image docker
|
|
19
|
+
|
|
20
|
+
`apt-get install -y curl &&`
|
|
21
|
+
|
|
22
|
+
Il faut veiller à utiliser une version de mongo compatible avec la libcurl sur l'OS du conteneur.
|
|
23
|
+
|
|
24
|
+
La version 4.4.0 fonction avec les versions récentes de node (ex node-14-buster-slim)
|
|
25
|
+
``
|
|
26
|
+
|
|
27
|
+
### Références
|
|
28
|
+
|
|
29
|
+
https://github.com/nodkz/mongodb-memory-server/issues/204
|
|
30
|
+
https://jira.mongodb.org/browse/SERVER-37768
|
|
31
|
+
https://jira.mongodb.org/browse/SERVER-44491
|
|
32
|
+
|
|
33
|
+
## Utilisation
|
|
34
|
+
|
|
35
|
+
Il faut premièrement initialiser la librairie elle-même. Par exemple, dans un projet d'API basé sur le générateur, ceci sera effectué dans le
|
|
36
|
+
fichier "`src/init.ts`", au début de la fonction `initComponents()` :
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { init as initMongoUtilsLib } from '@villedemontreal/mongo';
|
|
40
|
+
import { createLogger } from './utils/logger';
|
|
41
|
+
|
|
42
|
+
// ...
|
|
43
|
+
|
|
44
|
+
export async function initComponents() {
|
|
45
|
+
initMongoUtilsLib(createLogger);
|
|
46
|
+
|
|
47
|
+
//...
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Puis si, en plus des simples utilitaire, vous désirez utiliser la gestion de Mongoose fournie par la librairie (pour
|
|
52
|
+
profiter de la fonctionalité de migrations par exemple), il faut appeller `initMongoose(...)` avec les configurations
|
|
53
|
+
appropriées.
|
|
54
|
+
|
|
55
|
+
Par exemple :
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { initMongoose, IMongooseConfigs } from "@villedemontreal/mongo";
|
|
59
|
+
import { configs } from "../../../../config/configs";
|
|
60
|
+
|
|
61
|
+
await initMongoose( new IMongooseConfigs {
|
|
62
|
+
applyUpdates: true,
|
|
63
|
+
connectionString: configs.mongo.connectionString,
|
|
64
|
+
connectionOptions: configs.mongo.connectionOptions,
|
|
65
|
+
//...
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
# Débogage
|
|
70
|
+
|
|
71
|
+
En cas de problème avec mongo-memory-server-core, vous pouvez activer les traces de debogage en utilisant une varible
|
|
72
|
+
d'environnement.
|
|
73
|
+
|
|
74
|
+
`DEBUG=MongoMS:*`
|
|
75
|
+
|
|
76
|
+
Voir https://www.npmjs.com/package/debug pour les détails d'utilisation
|
|
77
|
+
|
|
78
|
+
# Versions
|
|
79
|
+
|
|
80
|
+
Importe les dépendances suivantes:
|
|
81
|
+
|
|
82
|
+
- Mongo 3.5.9 [Détails](https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#node-js-driver-compatibility)
|
|
83
|
+
- Mongoose 5.9.19 [Détails](https://mongoosejs.com/docs/compatibility.html)
|
|
84
|
+
- MongoMemoryServer 6.6.1
|
|
85
|
+
- @types/mongodb: 3.5.22
|
|
86
|
+
- @types/mongoose: 5.7.24
|
|
87
|
+
|
|
88
|
+
## Notes
|
|
89
|
+
|
|
90
|
+
- Lorsque vous appellez la méthode `MongoUtils#mockMongoose(...)` en passant une instance de "`mocha`", assurez-vous de le
|
|
91
|
+
faire dans une function _régulière_ et non dans une _arrow_ function ou alors une erreur sera lancée! Par exemple :
|
|
92
|
+
|
|
93
|
+
Ceci ne fonctionnera **pas** :
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
before(async () => {
|
|
97
|
+
// ...
|
|
98
|
+
await mongoUtils.mockMongoose(this, testconfig.mockServer.serverVersion);
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Mais ceci va fonctionner :
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
before(async function() {
|
|
106
|
+
// ...
|
|
107
|
+
await mongoUtils.mockMongoose(this, testconfig.mockServer.serverVersion);
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Voir [cette issue](https://github.com/mochajs/mocha/issues/2018) pour plus de détails.
|
|
112
|
+
|
|
113
|
+
# Plugins
|
|
114
|
+
|
|
115
|
+
## Pagination
|
|
116
|
+
|
|
117
|
+
Le but du plugin est de faciliter l'intégration de la pagination dans nos systèmes et de standardiser l'output afin de faciliter la consomation.
|
|
118
|
+
|
|
119
|
+
### Utilisation
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { mongoosePaginate } from '@villedemontreal/mongo';
|
|
123
|
+
var schema = new mongoose.Schema({
|
|
124
|
+
/* schema definition */
|
|
125
|
+
});
|
|
126
|
+
schema.plugin(mongoosePaginate);
|
|
127
|
+
|
|
128
|
+
var Model = mongoose.model('Model', schema); // Model.paginate()
|
|
129
|
+
const result = Model.paginate({}, { offset: 0, limit: 10 });
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Output
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"paging": {
|
|
137
|
+
"totalCount": 4,
|
|
138
|
+
"limit": 25,
|
|
139
|
+
"offset": 0
|
|
140
|
+
},
|
|
141
|
+
"items": [
|
|
142
|
+
// your items
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
# Builder le projet
|
|
148
|
+
|
|
149
|
+
**Note**: Sur Linux/Mac assurz-vous que le fichier `run` est exécutable. Autrement, lancez `chmod +x ./run`.
|
|
150
|
+
|
|
151
|
+
Pour lancer le build :
|
|
152
|
+
|
|
153
|
+
- > `run compile` ou `./run compile` (sur Linux/Mac)
|
|
154
|
+
|
|
155
|
+
Pour lancer les tests :
|
|
156
|
+
|
|
157
|
+
- > `run test` ou `./run test` (sur Linux/Mac)
|
|
158
|
+
|
|
159
|
+
# Mode Watch
|
|
160
|
+
|
|
161
|
+
Lors du développement, il est possible de lancer `run watch` (ou `./run watch` sur Linux/mac) dans un terminal
|
|
162
|
+
externe pour démarrer la compilation incrémentale. Il est alors possible de lancer certaines _launch configuration_
|
|
163
|
+
comme `Debug current tests file - fast` dans VsCode et ainsi déboguer le fichier de tests présentement ouvert sans
|
|
164
|
+
avoir à (re)compiler au préalable (la compilation incrémentale s'en sera chargé).
|
|
165
|
+
|
|
166
|
+
Notez que, par défaut, des _notifications desktop_ sont activées pour indiquer visuellement si la compilation
|
|
167
|
+
incrémentale est un succès ou si une erreur a été trouvée. Vous pouvez désactiver ces notifications en utilisant
|
|
168
|
+
`run watch --dn` (`d`isable `n`otifications).
|
|
169
|
+
|
|
170
|
+
# Déboguer le projet
|
|
171
|
+
|
|
172
|
+
Trois "_launch configurations_" sont founies pour déboguer le projet dans VSCode :
|
|
173
|
+
|
|
174
|
+
- "`Debug all tests`", la launch configuration par défaut. Lance les tests en mode debug. Vous pouvez mettre
|
|
175
|
+
des breakpoints et ils seront respectés.
|
|
176
|
+
|
|
177
|
+
- "`Debug a test file`". Lance _un_ fichier de tests en mode debug. Vous pouvez mettre
|
|
178
|
+
des breakpoints et ils seront respectés. Pour changer le fichier de tests à être exécuté, vous devez modifier la ligne appropriée dans le fichier "`.vscode/launch.json`".
|
|
179
|
+
|
|
180
|
+
- "`Debug current tests file`". Lance le fichier de tests _présentement ouvert_ dans VSCode en mode debug. Effectue la compîlation au préalable.
|
|
181
|
+
|
|
182
|
+
- "`Debug current tests file - fast`". Lance le fichier de tests _présentement ouvert_ dans VSCode en mode debug. Aucune compilation
|
|
183
|
+
n'est effectuée au préalable. Cette launch configuration doit être utilisée lorsque la compilation incrémentale roule (voir la section "`Mode Watch`" plus haut)
|
|
184
|
+
|
|
185
|
+
# Test et publication de la librairie sur Nexus
|
|
186
|
+
|
|
187
|
+
En mergant une pull request dans la branche `develop`, un artifact "`-pre.build`" sera créé automatiquement dans Nexus. Vous
|
|
188
|
+
pouvez utiliser cette version temporaire de la librairie pour bien la tester dans un réel projet.
|
|
189
|
+
|
|
190
|
+
Une fois mergée dans `master`, la librairie est définitiement publiée dans Nexus, en utilisant la version spécifiée dans
|
|
191
|
+
le `package.json`.
|
|
192
|
+
|
|
193
|
+
## Artifact Nexus privé, lors du développement
|
|
194
|
+
|
|
195
|
+
Lors du développement d'une nouvelle fonctionnalité, sur une branche `feature`, il peut parfois être
|
|
196
|
+
utile de déployer une version temporaire de la librairie dans Nexus. Ceci permet de bien tester
|
|
197
|
+
l'utilisation de la librairie modifiée dans un vrai projet, ou même dans une autre librairie
|
|
198
|
+
elle-même par la suite utilisée dans un vrai projet.
|
|
199
|
+
|
|
200
|
+
Si le code à tester est terminé et prêt à être mis en commun avec d'autres développeurs, la solution
|
|
201
|
+
de base, comme spécifiée à la section précédante, est de merger sur `develop`: ceci créera
|
|
202
|
+
automatiquement un artifact "`-pre-build`" dans Nexus. Cependant, si le code est encore en développement
|
|
203
|
+
et vous désirez éviter de polluer la branche commune `develop` avec du code temporaire, il y a une
|
|
204
|
+
solution permettant de générer un artifact "`[votre prénom]-pre-build`" temporaire dans Nexus,
|
|
205
|
+
à partir d'une branche `feature` directement:
|
|
206
|
+
|
|
207
|
+
1. Checkoutez votre branche `feature` dans une branche nommée "`nexus`". Ce nom est
|
|
208
|
+
important et correspond à une entrée dans le `Jenkinsfile`.
|
|
209
|
+
2. Une fois sur la branche `nexus`, ajoutez un suffixe "`-[votre prénom]`" à
|
|
210
|
+
la version dans le `package.json`, par exemple: "`5.15.0-roger`".
|
|
211
|
+
Ceci permet d'éviter tout conflit dans Nexus et exprime clairement qu'il
|
|
212
|
+
s'agit d'une version temporaire pour votre développement privé.
|
|
213
|
+
3. Commitez et poussez la branche `nexus`.
|
|
214
|
+
4. Une fois le build Jenkins terminé, un artifact pour votre version aura été
|
|
215
|
+
déployé dans Nexus. Détruire votre branche dans Bitbucket pour permettre aux
|
|
216
|
+
autres developpeurs d'utiliser cette approche.
|
|
217
|
+
|
|
218
|
+
**Notez** que, lors du développement dans une branche `feature`, l'utilisation d'un simple
|
|
219
|
+
`npm link` local peut souvent être suffisant! Mais cette solution a ses limites, par exemple si
|
|
220
|
+
vous désirez tester la librairie modifiée _dans un container Docker_.
|
|
221
|
+
|
|
222
|
+
# Aide / Contributions
|
|
223
|
+
|
|
224
|
+
Pour obtenir de l'aide avec cette librairie, vous pouvez poster sur la salle Google Chat [dev-discussions]
|
|
225
|
+
|
|
226
|
+
Notez que les contributions sous forme de pull requests sont bienvenues.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ILogger } from '@villedemontreal/logger';
|
|
2
|
+
/**
|
|
3
|
+
* Lib configs
|
|
4
|
+
*/
|
|
5
|
+
export declare class Configs {
|
|
6
|
+
private _loggerCreator;
|
|
7
|
+
/**
|
|
8
|
+
* The Logger creator
|
|
9
|
+
*/
|
|
10
|
+
get loggerCreator(): (name: string) => ILogger;
|
|
11
|
+
/**
|
|
12
|
+
* Sets the Logger creator.
|
|
13
|
+
*/
|
|
14
|
+
setLoggerCreator(loggerCreator: (name: string) => ILogger): void;
|
|
15
|
+
}
|
|
16
|
+
export declare let configs: Configs;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configs = exports.Configs = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Lib configs
|
|
6
|
+
*/
|
|
7
|
+
class Configs {
|
|
8
|
+
/**
|
|
9
|
+
* The Logger creator
|
|
10
|
+
*/
|
|
11
|
+
get loggerCreator() {
|
|
12
|
+
if (!this._loggerCreator) {
|
|
13
|
+
throw new Error(`The Logger Creator HAS to be set as a configuration`);
|
|
14
|
+
}
|
|
15
|
+
return this._loggerCreator;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Sets the Logger creator.
|
|
19
|
+
*/
|
|
20
|
+
setLoggerCreator(loggerCreator) {
|
|
21
|
+
this._loggerCreator = loggerCreator;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.Configs = Configs;
|
|
25
|
+
exports.configs = new Configs();
|
|
26
|
+
//# sourceMappingURL=configs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/config/configs.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,OAAO;IAGlB;;OAEG;IACH,IAAI,aAAa;QACf,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;SACxE;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,gBAAgB,CAAC,aAAwC;QAC9D,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;CACF;AAnBD,0BAmBC;AAEU,QAAA,OAAO,GAAY,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -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 let constants: Constants;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constants = exports.Constants = void 0;
|
|
4
|
+
// ==========================================
|
|
5
|
+
// Application constants
|
|
6
|
+
// ==========================================
|
|
7
|
+
const app_root_path_1 = require("app-root-path");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
/**
|
|
10
|
+
* Library constants
|
|
11
|
+
*/
|
|
12
|
+
class Constants {
|
|
13
|
+
constructor() {
|
|
14
|
+
// From the "dist/src/config" folder
|
|
15
|
+
this.libRoot = path.normalize(__dirname + '/../../..');
|
|
16
|
+
this.appRoot = app_root_path_1.path;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Base config to 'mock' a mongo server
|
|
20
|
+
*/
|
|
21
|
+
get testsConfig() {
|
|
22
|
+
return {
|
|
23
|
+
applyUpdates: false,
|
|
24
|
+
connectionString: 'mock',
|
|
25
|
+
connectionOptions: {
|
|
26
|
+
useNewUrlParser: true,
|
|
27
|
+
useUnifiedTopology: true
|
|
28
|
+
},
|
|
29
|
+
updater: {
|
|
30
|
+
lockMaxAgeSeconds: 30,
|
|
31
|
+
mongoSchemaUpdatesDirPath: '/dist/tests/testingMongoUpdates',
|
|
32
|
+
appSchemaCollectionName: 'testAppSchema'
|
|
33
|
+
},
|
|
34
|
+
mockServer: {
|
|
35
|
+
serverVersion: '4.0.16'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Mongo constants
|
|
41
|
+
*/
|
|
42
|
+
get mongo() {
|
|
43
|
+
return {
|
|
44
|
+
testing: {
|
|
45
|
+
/**
|
|
46
|
+
* The "connectionString" to use for a mock
|
|
47
|
+
* Mongo server to be used instead of a real one.
|
|
48
|
+
* This option is only available on the "development"
|
|
49
|
+
* environment, or when tests are ran.
|
|
50
|
+
*/
|
|
51
|
+
MOCK_CONNECTION_STRING: 'mock'
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* The names of the Mongo collections used in
|
|
55
|
+
* this application.
|
|
56
|
+
*/
|
|
57
|
+
collectionNames: {
|
|
58
|
+
/**
|
|
59
|
+
* Special collection that stores informations about the
|
|
60
|
+
* schema currently installed for the application.
|
|
61
|
+
*/
|
|
62
|
+
APP_SCHEMA: 'appSchema'
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Mongo error codes
|
|
66
|
+
*/
|
|
67
|
+
mongoErrorCodes: {
|
|
68
|
+
/**
|
|
69
|
+
* The code for a Mongo "duplicate key" error.
|
|
70
|
+
*/
|
|
71
|
+
DUPLICATE_KEY: 11000
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Mongoose constants
|
|
75
|
+
*/
|
|
76
|
+
mongoose: {
|
|
77
|
+
/**
|
|
78
|
+
* Mongoose error codes
|
|
79
|
+
*/
|
|
80
|
+
errorCodes: {
|
|
81
|
+
/**
|
|
82
|
+
* The code for a Mongoose "required" error.
|
|
83
|
+
*/
|
|
84
|
+
REQUIRED_FIELD: 'required'
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Mongoose error kinds
|
|
88
|
+
*/
|
|
89
|
+
errorKinds: {
|
|
90
|
+
OBJECT_ID: 'ObjectId'
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Mongoose error names
|
|
94
|
+
*/
|
|
95
|
+
errorNames: {
|
|
96
|
+
CAST_ERROR: 'CastError'
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.Constants = Constants;
|
|
103
|
+
exports.constants = new Constants();
|
|
104
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/config/constants.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAC7C,wBAAwB;AACxB,6CAA6C;AAC7C,iDAAgD;AAChD,6BAA6B;AAG7B;;GAEG;AACH,MAAa,SAAS;IAgBpB;QACE,oCAAoC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,GAAG,WAAW,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,oBAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACb,OAAO;YACL,YAAY,EAAE,KAAK;YACnB,gBAAgB,EAAE,MAAM;YACxB,iBAAiB,EAAE;gBACjB,eAAe,EAAE,IAAI;gBACrB,kBAAkB,EAAE,IAAI;aACzB;YACD,OAAO,EAAE;gBACP,iBAAiB,EAAE,EAAE;gBACrB,yBAAyB,EAAE,iCAAiC;gBAC5D,uBAAuB,EAAE,eAAe;aACzC;YACD,UAAU,EAAE;gBACV,aAAa,EAAE,QAAQ;aACxB;SACF,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACP,OAAO;YACL,OAAO,EAAE;gBACP;;;;;mBAKG;gBACH,sBAAsB,EAAE,MAAM;aAC/B;YACD;;;eAGG;YACH,eAAe,EAAE;gBACf;;;mBAGG;gBACH,UAAU,EAAE,WAAW;aACxB;YACD;;eAEG;YACH,eAAe,EAAE;gBACf;;mBAEG;gBACH,aAAa,EAAE,KAAK;aACrB;YAED;;eAEG;YACH,QAAQ,EAAE;gBACR;;mBAEG;gBACH,UAAU,EAAE;oBACV;;uBAEG;oBACH,cAAc,EAAE,UAAU;iBAC3B;gBAED;;mBAEG;gBACH,UAAU,EAAE;oBACV,SAAS,EAAE,UAAU;iBACtB;gBAED;;mBAEG;gBACH,UAAU,EAAE;oBACV,UAAU,EAAE,WAAW;iBACxB;aACF;SACF,CAAC;IACJ,CAAC;CACF;AA7GD,8BA6GC;AAEU,QAAA,SAAS,GAAc,IAAI,SAAS,EAAE,CAAC"}
|
|
@@ -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,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInited = exports.init = void 0;
|
|
4
|
+
const configs_1 = require("./configs");
|
|
5
|
+
let libIsInitialized = false;
|
|
6
|
+
/**
|
|
7
|
+
* Inits the library.
|
|
8
|
+
*/
|
|
9
|
+
function init(loggerCreator) {
|
|
10
|
+
if (!loggerCreator) {
|
|
11
|
+
throw new Error(`The Logger Creator is required.`);
|
|
12
|
+
}
|
|
13
|
+
configs_1.configs.setLoggerCreator(loggerCreator);
|
|
14
|
+
libIsInitialized = true;
|
|
15
|
+
}
|
|
16
|
+
exports.init = init;
|
|
17
|
+
/**
|
|
18
|
+
* checks if the library has been initialized.
|
|
19
|
+
*/
|
|
20
|
+
function isInited() {
|
|
21
|
+
return libIsInitialized;
|
|
22
|
+
}
|
|
23
|
+
exports.isInited = isInited;
|
|
24
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/config/init.ts"],"names":[],"mappings":";;;AACA,uCAAoC;AAEpC,IAAI,gBAAgB,GAAY,KAAK,CAAC;AACtC;;GAEG;AACH,SAAgB,IAAI,CAAC,aAAwC;IAC3D,IAAI,CAAC,aAAa,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;IAED,iBAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAExC,gBAAgB,GAAG,IAAI,CAAC;AAC1B,CAAC;AARD,oBAQC;AAED;;GAEG;AACH,SAAgB,QAAQ;IACtB,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAFD,4BAEC"}
|
|
@@ -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
|
+
}
|