@lenne.tech/nest-server 8.6.9 → 8.6.12

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.
Files changed (48) hide show
  1. package/dist/core/common/helpers/db.helper.d.ts +1 -1
  2. package/dist/core/common/helpers/db.helper.js +6 -2
  3. package/dist/core/common/helpers/db.helper.js.map +1 -1
  4. package/dist/core/common/interfaces/service-options.interface.d.ts +1 -1
  5. package/dist/core/common/types/field-selection.type.d.ts +1 -1
  6. package/dist/core/modules/auth/core-auth.model.d.ts +1 -0
  7. package/dist/core/modules/auth/core-auth.model.js +4 -0
  8. package/dist/core/modules/auth/core-auth.model.js.map +1 -1
  9. package/dist/core/modules/user/core-user.model.d.ts +1 -0
  10. package/dist/core/modules/user/core-user.model.js +4 -0
  11. package/dist/core/modules/user/core-user.model.js.map +1 -1
  12. package/dist/core.module.js +1 -1
  13. package/dist/core.module.js.map +1 -1
  14. package/dist/index.d.ts +4 -0
  15. package/dist/index.js +4 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/server/common/models/persistence.model.d.ts +3 -3
  18. package/dist/server/common/models/persistence.model.js +8 -4
  19. package/dist/server/common/models/persistence.model.js.map +1 -1
  20. package/dist/server/modules/auth/auth.model.d.ts +1 -0
  21. package/dist/server/modules/auth/auth.model.js +5 -0
  22. package/dist/server/modules/auth/auth.model.js.map +1 -1
  23. package/dist/server/modules/file/file.controller.js +1 -1
  24. package/dist/server/modules/file/file.controller.js.map +1 -1
  25. package/dist/server/modules/user/inputs/user-create.input.js.map +1 -1
  26. package/dist/server/modules/user/inputs/user.input.js.map +1 -1
  27. package/dist/server/modules/user/user.model.d.ts +3 -3
  28. package/dist/server/modules/user/user.model.js +4 -4
  29. package/dist/server/modules/user/user.model.js.map +1 -1
  30. package/dist/test/test.helper.d.ts +4 -1
  31. package/dist/test/test.helper.js +2 -2
  32. package/dist/test/test.helper.js.map +1 -1
  33. package/dist/tsconfig.build.tsbuildinfo +1 -1
  34. package/package.json +1 -1
  35. package/src/core/common/helpers/db.helper.ts +7 -3
  36. package/src/core/common/interfaces/service-options.interface.ts +1 -1
  37. package/src/core/common/types/field-selection.type.ts +6 -1
  38. package/src/core/modules/auth/core-auth.model.ts +11 -1
  39. package/src/core/modules/user/core-user.model.ts +10 -0
  40. package/src/core.module.ts +1 -2
  41. package/src/index.ts +9 -0
  42. package/src/server/common/models/persistence.model.ts +25 -11
  43. package/src/server/modules/auth/auth.model.ts +9 -0
  44. package/src/server/modules/file/file.controller.ts +2 -2
  45. package/src/server/modules/user/inputs/user-create.input.ts +0 -4
  46. package/src/server/modules/user/inputs/user.input.ts +0 -4
  47. package/src/server/modules/user/user.model.ts +8 -8
  48. package/src/test/test.helper.ts +7 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "8.6.9",
3
+ "version": "8.6.12",
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",
@@ -543,7 +543,7 @@ export function removeIds(source: any[], ids: StringOrObjectId | StringOrObjectI
543
543
  */
544
544
  export async function setPopulates<T = Query<any, any> | Document>(
545
545
  queryOrDocument: T,
546
- populateOptions: PopulateOptions[],
546
+ populateOptions: string[] | PopulateOptions[] | (string | PopulateOptions)[],
547
547
  modelSchemaPaths?: { [key: string]: SchemaType }
548
548
  ): Promise<T> {
549
549
  // Check parameters
@@ -553,8 +553,12 @@ export async function setPopulates<T = Query<any, any> | Document>(
553
553
 
554
554
  // Filter populate options via model schema paths
555
555
  if (modelSchemaPaths) {
556
- populateOptions = populateOptions.filter((options) => {
557
- return Object.keys(modelSchemaPaths).includes(options.path);
556
+ populateOptions = populateOptions.filter((option: string | PopulateOptions) => {
557
+ let key: string = option as string;
558
+ if ((option as PopulateOptions)?.path) {
559
+ key = (option as PopulateOptions)?.path;
560
+ }
561
+ return Object.keys(modelSchemaPaths).includes(key);
558
562
  });
559
563
  }
560
564
 
@@ -35,7 +35,7 @@ export interface ServiceOptions {
35
35
  outputType?: new (...params: any[]) => any;
36
36
 
37
37
  // Alias for fieldSelection (if both are set fieldSelection is overwritten by populate)
38
- populate?: PopulateOptions | (PopulateOptions | string)[];
38
+ populate?: string | PopulateOptions | (PopulateOptions | string)[];
39
39
 
40
40
  // Process field selection
41
41
  // If {} or not set, then the field selection runs with defaults
@@ -5,4 +5,9 @@ import { ResolveSelector } from '../interfaces/resolve-selector.interface';
5
5
  /**
6
6
  * Field selection to set fields of (populated) result
7
7
  */
8
- export type FieldSelection = PopulateOptions | (PopulateOptions | string)[] | SelectionNode[] | ResolveSelector;
8
+ export type FieldSelection =
9
+ | string
10
+ | PopulateOptions
11
+ | (PopulateOptions | string)[]
12
+ | SelectionNode[]
13
+ | ResolveSelector;
@@ -17,7 +17,7 @@ export class CoreAuthModel extends CoreModel {
17
17
  token: string = undefined;
18
18
 
19
19
  // ===================================================================================================================
20
- // Properties
20
+ // Methods
21
21
  // ===================================================================================================================
22
22
 
23
23
  /**
@@ -28,4 +28,14 @@ export class CoreAuthModel extends CoreModel {
28
28
  // Nothing more to initialize yet
29
29
  return this;
30
30
  }
31
+
32
+ /**
33
+ * Map input
34
+ */
35
+ map(input) {
36
+ super.map(input);
37
+ // There is nothing to map yet. Non-primitive variables should always be mapped.
38
+ // If something comes up, you can use `mapClasses` / `mapClassesAsync` from ModelHelper.
39
+ return this;
40
+ }
31
41
  }
@@ -122,4 +122,14 @@ export abstract class CoreUserModel extends CorePersistenceModel {
122
122
  this.roles = this.roles === undefined ? [] : this.roles;
123
123
  return this;
124
124
  }
125
+
126
+ /**
127
+ * Map input
128
+ */
129
+ map(input) {
130
+ super.map(input);
131
+ // There is nothing to map yet. Non-primitive variables should always be mapped.
132
+ // If something comes up, you can use `mapClasses` / `mapClassesAsync` from ModelHelper.
133
+ return this;
134
+ }
125
135
  }
@@ -79,8 +79,7 @@ export class CoreModule implements NestModule {
79
79
  const { connectionParams, extra } = context;
80
80
  if (config.graphQl.enableSubscriptionAuth) {
81
81
  // get authToken from authorization header
82
- const authToken: string =
83
- 'Authorization' in connectionParams && connectionParams?.Authorization?.split(' ')[1];
82
+ const authToken: string = connectionParams?.Authorization?.split(' ')[1];
84
83
  if (authToken) {
85
84
  // verify authToken/getJwtPayLoad
86
85
  const payload = authService.decodeJwt(authToken);
package/src/index.ts CHANGED
@@ -78,6 +78,15 @@ export * from './core/modules/auth/core-auth.module';
78
78
  export * from './core/modules/auth/core-auth.resolver';
79
79
  export * from './core/modules/auth/jwt.strategy';
80
80
 
81
+ // =====================================================================================================================
82
+ // Core - Modules - File
83
+ // =====================================================================================================================
84
+
85
+ export * from './core/modules/file/interfaces/file-service-options.interface';
86
+ export * from './core/modules/file/interfaces/file-upload.interface';
87
+ export * from './core/modules/file/core-file.service';
88
+ export * from './core/modules/file/file-info.output';
89
+
81
90
  // =====================================================================================================================
82
91
  // Core - Modules - User
83
92
  // =====================================================================================================================
@@ -15,33 +15,37 @@ import { User } from '../../modules/user/user.model';
15
15
  isAbstract: true,
16
16
  })
17
17
  export abstract class PersistenceModel extends CorePersistenceModel {
18
+ // ===================================================================================================================
19
+ // Properties
20
+ // ===================================================================================================================
21
+
18
22
  /**
19
- * User who created the object
23
+ * ID of the user who created the object
20
24
  *
21
25
  * Not set when created by system
22
26
  */
23
- @Field((type) => User, {
24
- description: 'User who created the object',
27
+ @Field(() => User, {
28
+ description: 'ID of the user who created the object',
25
29
  nullable: true,
26
30
  })
27
31
  @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User' })
28
- createdBy?: Types.ObjectId | User = undefined;
32
+ createdBy?: Types.ObjectId | string = undefined;
29
33
 
30
34
  /**
31
- * User who last updated the object
35
+ * ID of the user who updated the object
32
36
  *
33
37
  * Not set when updated by system
34
38
  */
35
- @Field((type) => User, {
36
- description: 'User who last updated the object',
39
+ @Field(() => User, {
40
+ description: 'ID of the user who updated the object',
37
41
  nullable: true,
38
42
  })
39
43
  @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User' })
40
- updatedBy?: Types.ObjectId | User = undefined;
44
+ updatedBy?: Types.ObjectId | string = undefined;
41
45
 
42
- // ===========================================================================
43
- // Properties
44
- // ===========================================================================
46
+ // ===================================================================================================================
47
+ // Methods
48
+ // ===================================================================================================================
45
49
 
46
50
  /**
47
51
  * Initialize instance with default values instead of undefined
@@ -51,4 +55,14 @@ export abstract class PersistenceModel extends CorePersistenceModel {
51
55
  // Nothing more to initialize yet
52
56
  return this;
53
57
  }
58
+
59
+ /**
60
+ * Map input
61
+ */
62
+ map(input) {
63
+ super.map(input);
64
+ // There is nothing to map yet. Non-primitive variables should always be mapped.
65
+ // If something comes up, you can use `mapClasses` / `mapClassesAsync` from ModelHelper.
66
+ return this;
67
+ }
54
68
  }
@@ -1,4 +1,5 @@
1
1
  import { Field, ObjectType } from '@nestjs/graphql';
2
+ import { mapClasses } from '../../../core/common/helpers/model.helper';
2
3
  import { CoreAuthModel } from '../../../core/modules/auth/core-auth.model';
3
4
  import { User } from '../user/user.model';
4
5
 
@@ -29,4 +30,12 @@ export class Auth extends CoreAuthModel {
29
30
  // Nothing more to initialize yet
30
31
  return this;
31
32
  }
33
+
34
+ /**
35
+ * Map input
36
+ */
37
+ map(input) {
38
+ super.map(input);
39
+ return mapClasses(input, { user: User }, this);
40
+ }
32
41
  }
@@ -21,7 +21,7 @@ import { User } from '../user/user.model';
21
21
  import { FileService } from './file.service';
22
22
 
23
23
  /**
24
- * File controller for
24
+ * File controller
25
25
  */
26
26
  @Controller('files')
27
27
  export class FileController {
@@ -51,7 +51,7 @@ export class FileController {
51
51
  })
52
52
  )
53
53
  uploadFiles(@UploadedFiles() files, @Body() fields: any) {
54
- console.log(JSON.stringify({ files, fields }, null, 2));
54
+ console.log('Saved file info', JSON.stringify({ files, fields }, null, 2));
55
55
  }
56
56
 
57
57
  /**
@@ -3,10 +3,6 @@ import { CoreUserCreateInput } from '../../../../core/modules/user/inputs/core-u
3
3
 
4
4
  /**
5
5
  * User input to create a new user
6
- *
7
- * HINT: All properties (in this class and all classes that extend this class) must be initialized with undefined,
8
- * otherwise the property will not be recognized via Object.keys (this is necessary for mapping) or will be initialized
9
- * with a default value that may overwrite an existing value in the DB.
10
6
  */
11
7
  @InputType({ description: 'User input to create a new user' })
12
8
  export class UserCreateInput extends CoreUserCreateInput {
@@ -3,10 +3,6 @@ import { CoreUserInput } from '../../../../core/modules/user/inputs/core-user.in
3
3
 
4
4
  /**
5
5
  * User input to update a user
6
- *
7
- * HINT: All properties (in this class and all classes that extend this class) must be initialized with undefined,
8
- * otherwise the property will not be recognized via Object.keys (this is necessary for mapping) or will be initialized
9
- * with a default value that may overwrite an existing value in the DB.
10
6
  */
11
7
  @InputType({ description: 'User input' })
12
8
  export class UserInput extends CoreUserInput {
@@ -1,6 +1,6 @@
1
1
  import { Field, ObjectType } from '@nestjs/graphql';
2
2
  import { Prop, Schema as MongooseSchema, SchemaFactory } from '@nestjs/mongoose';
3
- import { Document, Schema } from 'mongoose';
3
+ import { Document, Schema, Types } from 'mongoose';
4
4
  import { mapClasses } from '../../../core/common/helpers/model.helper';
5
5
  import { CoreUserModel } from '../../../core/modules/user/core-user.model';
6
6
  import { PersistenceModel } from '../../common/models/persistence.model';
@@ -8,7 +8,7 @@ import { PersistenceModel } from '../../common/models/persistence.model';
8
8
  export type UserDocument = User & Document;
9
9
 
10
10
  /**
11
- * User schema
11
+ * User model
12
12
  */
13
13
  @ObjectType({ description: 'User' })
14
14
  @MongooseSchema({ timestamps: true })
@@ -25,28 +25,28 @@ export class User extends CoreUserModel implements PersistenceModel {
25
25
  avatar: string = undefined;
26
26
 
27
27
  /**
28
- * Editor who created the object
28
+ * ID of the user who created the object
29
29
  *
30
30
  * Not set when created by system
31
31
  */
32
- @Field((type) => User, {
32
+ @Field(() => String, {
33
33
  description: 'ID of the user who created the object',
34
34
  nullable: true,
35
35
  })
36
36
  @Prop({ type: Schema.Types.ObjectId, ref: 'User' })
37
- createdBy: User = undefined;
37
+ createdBy: Types.ObjectId | string = undefined;
38
38
 
39
39
  /**
40
- * Editor who last updated the object
40
+ * ID of the user who updated the object
41
41
  *
42
42
  * Not set when updated by system
43
43
  */
44
- @Field((type) => User, {
44
+ @Field(() => String, {
45
45
  description: 'ID of the user who last updated the object',
46
46
  nullable: true,
47
47
  })
48
48
  @Prop({ type: Schema.Types.ObjectId, ref: 'User' })
49
- updatedBy: User = undefined;
49
+ updatedBy: Types.ObjectId | string = undefined;
50
50
 
51
51
  // ===================================================================================================================
52
52
  // Methods
@@ -4,6 +4,7 @@ import * as fs from 'fs';
4
4
  import { createClient } from 'graphql-ws';
5
5
  import { jsonToGraphQLQuery } from 'json-to-graphql-query';
6
6
  import * as LightMyRequest from 'light-my-request';
7
+ import * as superagent from 'superagent';
7
8
  import * as supertest from 'supertest';
8
9
  import * as util from 'util';
9
10
  import * as ws from 'ws';
@@ -146,8 +147,9 @@ export class TestHelper {
146
147
 
147
148
  /**
148
149
  * Download file from URL
150
+ * @return Superagent response with additional data field containing the content of the file
149
151
  */
150
- download(url: string, token?: string) {
152
+ download(url: string, token?: string): Promise<superagent.Response & { data: string }> {
151
153
  return new Promise((resolve, reject) => {
152
154
  const request = supertest((this.app as INestApplication).getHttpServer()).get(url);
153
155
  if (token) {
@@ -166,9 +168,9 @@ export class TestHelper {
166
168
  err ? reject(err) : callback(null, null);
167
169
  });
168
170
  })
169
- .end((err, res: unknown) => {
170
- (res as Response & { data: string }).data = new Buffer(data, 'binary').toString();
171
- err ? reject(err) : resolve(res);
171
+ .end((err, res: superagent.Response) => {
172
+ (res as superagent.Response & { data: string }).data = Buffer.from(data, 'binary').toString();
173
+ err ? reject(err) : resolve(res as superagent.Response & { data: string });
172
174
  });
173
175
  });
174
176
  }
@@ -480,7 +482,7 @@ export class TestHelper {
480
482
  processResponse(response, statusCode, log, logError) {
481
483
  // Log response
482
484
  if (log) {
483
- console.log(JSON.stringify(response, null, 2));
485
+ console.log('Response', JSON.stringify(response, null, 2));
484
486
  }
485
487
 
486
488
  // Log error