@lenne.tech/nest-server 9.0.12 → 9.0.14
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/config.env.js +18 -0
- package/dist/config.env.js.map +1 -1
- package/dist/core/common/helpers/filter.helper.js +3 -3
- package/dist/core/common/helpers/filter.helper.js.map +1 -1
- package/dist/core/common/helpers/input.helper.js +1 -1
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +5 -0
- package/dist/core/common/interfaces/service-options.interface.d.ts +2 -0
- package/dist/core/common/services/crud.service.js +9 -2
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/config.env.ts +18 -0
- package/src/core/common/helpers/filter.helper.ts +3 -3
- package/src/core/common/helpers/input.helper.ts +1 -1
- package/src/core/common/interfaces/server-options.interface.ts +24 -1
- package/src/core/common/interfaces/service-options.interface.ts +5 -0
- package/src/core/common/services/crud.service.ts +10 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.14",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -99,15 +99,15 @@
|
|
|
99
99
|
"@nestjs/testing": "9.1.4",
|
|
100
100
|
"@types/cron": "2.0.0",
|
|
101
101
|
"@types/ejs": "3.1.1",
|
|
102
|
-
"@types/jest": "29.
|
|
102
|
+
"@types/jest": "29.2.0",
|
|
103
103
|
"@types/lodash": "4.14.186",
|
|
104
104
|
"@types/multer": "1.4.7",
|
|
105
|
-
"@types/node": "18.
|
|
105
|
+
"@types/node": "18.11.2",
|
|
106
106
|
"@types/nodemailer": "6.4.6",
|
|
107
107
|
"@types/passport": "1.0.11",
|
|
108
108
|
"@types/supertest": "2.0.12",
|
|
109
|
-
"@typescript-eslint/eslint-plugin": "5.40.
|
|
110
|
-
"@typescript-eslint/parser": "5.40.
|
|
109
|
+
"@typescript-eslint/eslint-plugin": "5.40.1",
|
|
110
|
+
"@typescript-eslint/parser": "5.40.1",
|
|
111
111
|
"coffeescript": "2.7.0",
|
|
112
112
|
"eslint": "8.25.0",
|
|
113
113
|
"eslint-config-prettier": "8.5.0",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"grunt-contrib-watch": "1.1.0",
|
|
119
119
|
"grunt-sync": "0.8.2",
|
|
120
120
|
"husky": "8.0.1",
|
|
121
|
-
"jest": "29.2.
|
|
121
|
+
"jest": "29.2.1",
|
|
122
122
|
"pm2": "5.2.2",
|
|
123
123
|
"prettier": "2.7.1",
|
|
124
124
|
"pretty-quick": "3.1.3",
|
package/src/config.env.ts
CHANGED
|
@@ -44,6 +44,9 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
44
44
|
},
|
|
45
45
|
env: 'local',
|
|
46
46
|
execAfterInit: 'npm run docs:bootstrap',
|
|
47
|
+
filter: {
|
|
48
|
+
maxLimit: null,
|
|
49
|
+
},
|
|
47
50
|
graphQl: {
|
|
48
51
|
driver: {
|
|
49
52
|
debug: true,
|
|
@@ -55,6 +58,9 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
55
58
|
},
|
|
56
59
|
loadLocalConfig: false,
|
|
57
60
|
mongoose: {
|
|
61
|
+
collation: {
|
|
62
|
+
locale: 'de',
|
|
63
|
+
},
|
|
58
64
|
uri: 'mongodb://127.0.0.1/nest-server-dev',
|
|
59
65
|
},
|
|
60
66
|
port: 3000,
|
|
@@ -97,6 +103,9 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
97
103
|
},
|
|
98
104
|
env: 'development',
|
|
99
105
|
execAfterInit: 'npm run docs:bootstrap',
|
|
106
|
+
filter: {
|
|
107
|
+
maxLimit: null,
|
|
108
|
+
},
|
|
100
109
|
graphQl: {
|
|
101
110
|
driver: {
|
|
102
111
|
debug: true,
|
|
@@ -108,6 +117,9 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
108
117
|
},
|
|
109
118
|
loadLocalConfig: false,
|
|
110
119
|
mongoose: {
|
|
120
|
+
collation: {
|
|
121
|
+
locale: 'de',
|
|
122
|
+
},
|
|
111
123
|
uri: 'mongodb://127.0.0.1/nest-server-dev',
|
|
112
124
|
},
|
|
113
125
|
port: 3000,
|
|
@@ -150,6 +162,9 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
150
162
|
},
|
|
151
163
|
env: 'productive',
|
|
152
164
|
execAfterInit: 'npm run docs:bootstrap',
|
|
165
|
+
filter: {
|
|
166
|
+
maxLimit: null,
|
|
167
|
+
},
|
|
153
168
|
graphQl: {
|
|
154
169
|
driver: {
|
|
155
170
|
debug: false,
|
|
@@ -161,6 +176,9 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
161
176
|
},
|
|
162
177
|
loadLocalConfig: false,
|
|
163
178
|
mongoose: {
|
|
179
|
+
collation: {
|
|
180
|
+
locale: 'de',
|
|
181
|
+
},
|
|
164
182
|
uri: 'mongodb://127.0.0.1/nest-server-prod',
|
|
165
183
|
},
|
|
166
184
|
port: 3000,
|
|
@@ -226,7 +226,7 @@ export function generateFindOptions<T = any>(
|
|
|
226
226
|
|
|
227
227
|
// Config
|
|
228
228
|
const config = {
|
|
229
|
-
maxLimit:
|
|
229
|
+
maxLimit: ConfigService.get('filter.maxLimit'),
|
|
230
230
|
...options,
|
|
231
231
|
};
|
|
232
232
|
|
|
@@ -243,8 +243,8 @@ export function generateFindOptions<T = any>(
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
// Check limit
|
|
246
|
-
if (!queryOptions.limit || queryOptions.limit > config.maxLimit) {
|
|
247
|
-
queryOptions.limit =
|
|
246
|
+
if (config.maxLimit && (!queryOptions.limit || queryOptions.limit > config.maxLimit)) {
|
|
247
|
+
queryOptions.limit = config.maxLimit;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
// Prepare order
|
|
@@ -347,7 +347,7 @@ export function combinePlain(...args: Record<any, any>[]): any {
|
|
|
347
347
|
* Get deep frozen object
|
|
348
348
|
*/
|
|
349
349
|
export function deepFreeze(object: any) {
|
|
350
|
-
if (typeof object !== 'object') {
|
|
350
|
+
if (!object || typeof object !== 'object') {
|
|
351
351
|
return object;
|
|
352
352
|
}
|
|
353
353
|
for (const [key, value] of Object.entries(object)) {
|
|
@@ -4,6 +4,7 @@ import { JwtModuleOptions } from '@nestjs/jwt';
|
|
|
4
4
|
import { MongooseModuleOptions } from '@nestjs/mongoose';
|
|
5
5
|
import { ServeStaticOptions } from '@nestjs/platform-express/interfaces/serve-static-options.interface';
|
|
6
6
|
import { CronExpression } from '@nestjs/schedule';
|
|
7
|
+
import { CollationOptions } from 'mongodb';
|
|
7
8
|
import * as SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
8
9
|
import { Falsy } from '../types/falsy.type';
|
|
9
10
|
import { CronJobConfig } from './cron-job-config.interface';
|
|
@@ -78,6 +79,16 @@ export interface IServerOptions {
|
|
|
78
79
|
*/
|
|
79
80
|
execAfterInit?: string;
|
|
80
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Filter configuration and defaults
|
|
84
|
+
*/
|
|
85
|
+
filter?: {
|
|
86
|
+
/**
|
|
87
|
+
* Maximum limit for the number of results
|
|
88
|
+
*/
|
|
89
|
+
maxLimit?: number;
|
|
90
|
+
};
|
|
91
|
+
|
|
81
92
|
/**
|
|
82
93
|
* Configuration of the GraphQL module
|
|
83
94
|
* see https://docs.nestjs.com/graphql/quick-start
|
|
@@ -146,7 +157,19 @@ export interface IServerOptions {
|
|
|
146
157
|
/**
|
|
147
158
|
* Configuration for Mongoose
|
|
148
159
|
*/
|
|
149
|
-
mongoose?: {
|
|
160
|
+
mongoose?: {
|
|
161
|
+
collation?: CollationOptions;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Mongoose connection string
|
|
165
|
+
*/
|
|
166
|
+
uri: string;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Mongoose module options
|
|
170
|
+
*/
|
|
171
|
+
options?: MongooseModuleOptions;
|
|
172
|
+
};
|
|
150
173
|
|
|
151
174
|
/**
|
|
152
175
|
* Port number of the server
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CollationOptions } from 'mongodb';
|
|
1
2
|
import { Model, PopulateOptions } from 'mongoose';
|
|
2
3
|
import { FieldSelection } from '../types/field-selection.type';
|
|
3
4
|
import { PrepareInputOptions } from './prepare-input-options.interface';
|
|
@@ -15,6 +16,10 @@ export interface ServiceOptions {
|
|
|
15
16
|
// If truly (default): input data will be checked
|
|
16
17
|
checkRights?: boolean;
|
|
17
18
|
|
|
19
|
+
// Collation for mongodb
|
|
20
|
+
// See https://www.mongodb.com/docs/manual/reference/collation/
|
|
21
|
+
collation?: CollationOptions;
|
|
22
|
+
|
|
18
23
|
// Current user to set ownership, check rights and other things
|
|
19
24
|
currentUser?: {
|
|
20
25
|
[key: string]: any;
|
|
@@ -7,6 +7,7 @@ import { convertFilterArgsToQuery } from '../helpers/filter.helper';
|
|
|
7
7
|
import { assignPlain } from '../helpers/input.helper';
|
|
8
8
|
import { ServiceOptions } from '../interfaces/service-options.interface';
|
|
9
9
|
import { CoreModel } from '../models/core-model.model';
|
|
10
|
+
import { ConfigService } from './config.service';
|
|
10
11
|
import { ModuleService } from './module.service';
|
|
11
12
|
|
|
12
13
|
export abstract class CrudService<T extends CoreModel = any> extends ModuleService<T> {
|
|
@@ -100,7 +101,12 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
// Find in DB
|
|
103
|
-
|
|
104
|
+
let find = this.mainDbModel.find(filterQuery.filterQuery, null, filterQuery.queryOptions);
|
|
105
|
+
const collation = serviceOptions?.collation || ConfigService.get('mongoose.collation');
|
|
106
|
+
if (collation) {
|
|
107
|
+
find = find.collation(collation);
|
|
108
|
+
}
|
|
109
|
+
return find.exec();
|
|
104
110
|
},
|
|
105
111
|
{ input: filter, serviceOptions }
|
|
106
112
|
);
|
|
@@ -197,7 +203,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
197
203
|
aggregation.push({ $facet: facet });
|
|
198
204
|
|
|
199
205
|
// Find and process db items
|
|
200
|
-
const
|
|
206
|
+
const collation = serviceOptions?.collation || ConfigService.get('mongoose.collation');
|
|
207
|
+
const dbResult =
|
|
208
|
+
(await this.mainDbModel.aggregate(aggregation, collation ? { collation } : {}).exec())[0] || {};
|
|
201
209
|
dbResult.totalCount = dbResult.totalCount?.[0]?.total || 0;
|
|
202
210
|
dbResult.items = dbResult.items?.map((item) => this.mainDbModel.hydrate(item)) || [];
|
|
203
211
|
return dbResult;
|