@lenne.tech/nest-server 9.0.27 → 9.0.28

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "9.0.27",
3
+ "version": "9.0.28",
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",
@@ -702,3 +702,19 @@ export function processDeep(
702
702
  // Process others
703
703
  return func(data);
704
704
  }
705
+
706
+ /**
707
+ * Helper to avoid very slow merge of serviceOptions
708
+ */
709
+ export function prepareServiceOptionsForCreate(serviceOptions: any) {
710
+ if (!serviceOptions) {
711
+ serviceOptions = {};
712
+ }
713
+ if (!serviceOptions.prepareInput) {
714
+ serviceOptions.prepareInput = {};
715
+ }
716
+ if (serviceOptions.prepareInput.create === undefined) {
717
+ serviceOptions.prepareInput.create;
718
+ }
719
+ return serviceOptions;
720
+ }
@@ -303,7 +303,7 @@ export function prepareServiceOptions(
303
303
  ): ServiceOptions {
304
304
  // Set default values
305
305
  const config = {
306
- clone: true,
306
+ clone: false,
307
307
  circles: true,
308
308
  proto: false,
309
309
  ...options,
@@ -1,10 +1,9 @@
1
1
  import { NotFoundException } from '@nestjs/common';
2
2
  import { FilterQuery, PipelineStage, QueryOptions } from 'mongoose';
3
3
  import { FilterArgs } from '../args/filter.args';
4
- import { merge } from '../helpers/config.helper';
5
4
  import { getStringIds } from '../helpers/db.helper';
6
5
  import { convertFilterArgsToQuery } from '../helpers/filter.helper';
7
- import { mergePlain } from '../helpers/input.helper';
6
+ import { mergePlain, prepareServiceOptionsForCreate } from '../helpers/input.helper';
8
7
  import { ServiceOptions } from '../interfaces/service-options.interface';
9
8
  import { CoreModel } from '../models/core-model.model';
10
9
  import { ConfigService } from './config.service';
@@ -15,7 +14,7 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
15
14
  * Create item
16
15
  */
17
16
  async create(input: any, serviceOptions?: ServiceOptions): Promise<T> {
18
- serviceOptions = merge({ prepareInput: { create: true } }, serviceOptions);
17
+ serviceOptions = prepareServiceOptionsForCreate(serviceOptions);
19
18
  return this.process(
20
19
  async (data) => {
21
20
  const currentUserId = serviceOptions?.currentUser?.id;
@@ -30,7 +29,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
30
29
  * Warning: Disables the handling of rights and restrictions!
31
30
  */
32
31
  async createForce(input: any, serviceOptions: ServiceOptions = {}): Promise<T> {
33
- serviceOptions = merge(serviceOptions, { force: true });
32
+ serviceOptions = serviceOptions || {};
33
+ serviceOptions.force = true;
34
34
  return this.create(input, serviceOptions);
35
35
  }
36
36
 
@@ -39,7 +39,10 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
39
39
  * Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
40
40
  */
41
41
  async createRaw(input: any, serviceOptions: ServiceOptions = {}): Promise<T> {
42
- serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
42
+ if (serviceOptions) {
43
+ serviceOptions.prepareInput = null;
44
+ serviceOptions.prepareOutput = null;
45
+ }
43
46
  return this.createForce(input, serviceOptions);
44
47
  }
45
48
 
@@ -59,7 +62,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
59
62
  * Warning: Disables the handling of rights and restrictions!
60
63
  */
61
64
  async getForce(id: string, serviceOptions: ServiceOptions = {}): Promise<T> {
62
- serviceOptions = merge(serviceOptions, { force: true });
65
+ serviceOptions = serviceOptions || {};
66
+ serviceOptions.force = true;
63
67
  return this.get(id, serviceOptions);
64
68
  }
65
69
 
@@ -68,7 +72,10 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
68
72
  * Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
69
73
  */
70
74
  async getRaw(id: string, serviceOptions: ServiceOptions = {}): Promise<T> {
71
- serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
75
+ if (serviceOptions) {
76
+ serviceOptions.prepareInput = null;
77
+ serviceOptions.prepareOutput = null;
78
+ }
72
79
  return this.getForce(id, serviceOptions);
73
80
  }
74
81
 
@@ -120,7 +127,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
120
127
  filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
121
128
  serviceOptions: ServiceOptions = {}
122
129
  ): Promise<T[]> {
123
- serviceOptions = merge(serviceOptions, { force: true });
130
+ serviceOptions = serviceOptions || {};
131
+ serviceOptions.force = true;
124
132
  return this.find(filter, serviceOptions);
125
133
  }
126
134
 
@@ -132,7 +140,10 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
132
140
  filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
133
141
  serviceOptions: ServiceOptions = {}
134
142
  ): Promise<T[]> {
135
- serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
143
+ if (serviceOptions) {
144
+ serviceOptions.prepareInput = null;
145
+ serviceOptions.prepareOutput = null;
146
+ }
136
147
  return this.findForce(filter, serviceOptions);
137
148
  }
138
149
 
@@ -222,7 +233,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
222
233
  filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
223
234
  serviceOptions: ServiceOptions = {}
224
235
  ): Promise<{ items: T[]; totalCount: number }> {
225
- serviceOptions = merge(serviceOptions, { force: true });
236
+ serviceOptions = serviceOptions || {};
237
+ serviceOptions.force = true;
226
238
  return this.findAndCount(filter, serviceOptions);
227
239
  }
228
240
 
@@ -234,7 +246,10 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
234
246
  filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
235
247
  serviceOptions: ServiceOptions = {}
236
248
  ): Promise<{ items: T[]; totalCount: number }> {
237
- serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
249
+ if (serviceOptions) {
250
+ serviceOptions.prepareInput = null;
251
+ serviceOptions.prepareOutput = null;
252
+ }
238
253
  return this.findAndCountForce(filter, serviceOptions);
239
254
  }
240
255
 
@@ -274,7 +289,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
274
289
  filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
275
290
  serviceOptions: ServiceOptions = {}
276
291
  ): Promise<T[]> {
277
- serviceOptions = merge(serviceOptions, { force: true });
292
+ serviceOptions = serviceOptions || {};
293
+ serviceOptions.force = true;
278
294
  return this.findAndUpdate(filter, serviceOptions);
279
295
  }
280
296
 
@@ -286,7 +302,10 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
286
302
  filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
287
303
  serviceOptions: ServiceOptions = {}
288
304
  ): Promise<T[]> {
289
- serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
305
+ if (serviceOptions) {
306
+ serviceOptions.prepareInput = null;
307
+ serviceOptions.prepareOutput = null;
308
+ }
290
309
  return this.findAndUpdateForce(filter, serviceOptions);
291
310
  }
292
311
 
@@ -399,7 +418,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
399
418
  * Warning: Disables the handling of rights and restrictions!
400
419
  */
401
420
  async updateForce(id: string, input: any, serviceOptions?: ServiceOptions): Promise<T> {
402
- serviceOptions = merge(serviceOptions, { force: true });
421
+ serviceOptions = serviceOptions || {};
422
+ serviceOptions.force = true;
403
423
  return this.update(id, input, serviceOptions);
404
424
  }
405
425
 
@@ -408,7 +428,10 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
408
428
  * Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
409
429
  */
410
430
  async updateRaw(id: string, input: any, serviceOptions?: ServiceOptions): Promise<T> {
411
- serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
431
+ if (serviceOptions) {
432
+ serviceOptions.prepareInput = null;
433
+ serviceOptions.prepareOutput = null;
434
+ }
412
435
  return this.updateForce(id, input, serviceOptions);
413
436
  }
414
437
 
@@ -434,7 +457,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
434
457
  * Warning: Disables the handling of rights and restrictions!
435
458
  */
436
459
  async deleteForce(id: string, serviceOptions?: ServiceOptions): Promise<T> {
437
- serviceOptions = merge(serviceOptions, { force: true });
460
+ serviceOptions = serviceOptions || {};
461
+ serviceOptions.force = true;
438
462
  return this.delete(id, serviceOptions);
439
463
  }
440
464
 
@@ -443,7 +467,10 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
443
467
  * Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
444
468
  */
445
469
  async deleteRaw(id: string, serviceOptions?: ServiceOptions): Promise<T> {
446
- serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
470
+ if (serviceOptions) {
471
+ serviceOptions.prepareInput = null;
472
+ serviceOptions.prepareOutput = null;
473
+ }
447
474
  return this.deleteForce(id, serviceOptions);
448
475
  }
449
476
  }
@@ -2,7 +2,6 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
2
2
  import { JwtService } from '@nestjs/jwt';
3
3
  import * as bcrypt from 'bcrypt';
4
4
  import { sha256 } from 'js-sha256';
5
- import { merge } from '../../../common/helpers/config.helper';
6
5
  import { ServiceOptions } from '../../../common/interfaces/service-options.interface';
7
6
  import { ICoreAuthUser } from '../interfaces/core-auth-user.interface';
8
7
  import { JwtPayload } from '../interfaces/jwt-payload.interface';
@@ -23,7 +22,8 @@ export class CoreAuthService {
23
22
  password: string,
24
23
  serviceOptions?: ServiceOptions
25
24
  ): Promise<{ token: string; user: ICoreAuthUser }> {
26
- serviceOptions = merge(serviceOptions || {}, { prepareOutput: null });
25
+ serviceOptions = serviceOptions || {};
26
+ serviceOptions.prepareOutput = null;
27
27
 
28
28
  // Get user
29
29
  const user = await this.userService.getViaEmail(email, serviceOptions);
@@ -3,8 +3,7 @@ import * as bcrypt from 'bcrypt';
3
3
  import * as crypto from 'crypto';
4
4
  import { sha256 } from 'js-sha256';
5
5
  import { Document, Model } from 'mongoose';
6
- import { merge } from '../../common/helpers/config.helper';
7
- import { assignPlain } from '../../common/helpers/input.helper';
6
+ import { assignPlain, prepareServiceOptionsForCreate } from '../../common/helpers/input.helper';
8
7
  import { ServiceOptions } from '../../common/interfaces/service-options.interface';
9
8
  import { ConfigService } from '../../common/services/config.service';
10
9
  import { CrudService } from '../../common/services/crud.service';
@@ -39,7 +38,7 @@ export abstract class CoreUserService<
39
38
  * Create user
40
39
  */
41
40
  override async create(input: any, serviceOptions?: ServiceOptions): Promise<TUser> {
42
- serviceOptions = merge({ prepareInput: { create: true } }, serviceOptions);
41
+ serviceOptions = prepareServiceOptionsForCreate(serviceOptions);
43
42
  return this.process(
44
43
  async (data) => {
45
44
  // Create user with verification token