@lenne.tech/nest-server 8.6.4 → 8.6.7

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 (81) hide show
  1. package/dist/config.env.js +4 -2
  2. package/dist/config.env.js.map +1 -1
  3. package/dist/core/common/decorators/restricted.decorator.js +4 -4
  4. package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
  5. package/dist/core/common/helpers/db.helper.js +3 -2
  6. package/dist/core/common/helpers/db.helper.js.map +1 -1
  7. package/dist/core/common/helpers/file.helper.js +4 -7
  8. package/dist/core/common/helpers/file.helper.js.map +1 -1
  9. package/dist/core/common/helpers/filter.helper.d.ts +7 -0
  10. package/dist/core/common/helpers/filter.helper.js +38 -1
  11. package/dist/core/common/helpers/filter.helper.js.map +1 -1
  12. package/dist/core/common/helpers/input.helper.d.ts +6 -0
  13. package/dist/core/common/helpers/input.helper.js +28 -6
  14. package/dist/core/common/helpers/input.helper.js.map +1 -1
  15. package/dist/core/common/helpers/service.helper.d.ts +2 -0
  16. package/dist/core/common/helpers/service.helper.js +7 -9
  17. package/dist/core/common/helpers/service.helper.js.map +1 -1
  18. package/dist/core/common/inputs/filter.input.js.map +1 -1
  19. package/dist/core/common/interfaces/prepare-input-options.interface.d.ts +1 -0
  20. package/dist/core/common/interfaces/prepare-output-options.interface.d.ts +1 -0
  21. package/dist/core/common/interfaces/server-options.interface.d.ts +16 -13
  22. package/dist/core/common/interfaces/service-options.interface.d.ts +3 -1
  23. package/dist/core/common/models/core-model.model.js +4 -1
  24. package/dist/core/common/models/core-model.model.js.map +1 -1
  25. package/dist/core/common/services/crud.service.js +9 -4
  26. package/dist/core/common/services/crud.service.js.map +1 -1
  27. package/dist/core/common/services/module.service.js +14 -2
  28. package/dist/core/common/services/module.service.js.map +1 -1
  29. package/dist/core/common/types/field-selection.type.d.ts +1 -1
  30. package/dist/core/modules/auth/guards/roles.guard.js +2 -1
  31. package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
  32. package/dist/core/modules/user/core-user.service.js +9 -13
  33. package/dist/core/modules/user/core-user.service.js.map +1 -1
  34. package/dist/core.module.d.ts +3 -2
  35. package/dist/core.module.js +26 -4
  36. package/dist/core.module.js.map +1 -1
  37. package/dist/main.js +13 -0
  38. package/dist/main.js.map +1 -1
  39. package/dist/server/modules/auth/auth.module.js +1 -2
  40. package/dist/server/modules/auth/auth.module.js.map +1 -1
  41. package/dist/server/modules/file/file.controller.js +1 -1
  42. package/dist/server/modules/file/file.controller.js.map +1 -1
  43. package/dist/server/modules/file/file.resolver.d.ts +5 -0
  44. package/dist/server/modules/file/file.resolver.js +51 -0
  45. package/dist/server/modules/file/file.resolver.js.map +1 -0
  46. package/dist/server/modules/user/user.model.d.ts +14 -1
  47. package/dist/server/modules/user/user.resolver.js +2 -1
  48. package/dist/server/modules/user/user.resolver.js.map +1 -1
  49. package/dist/server/server.module.js +3 -1
  50. package/dist/server/server.module.js.map +1 -1
  51. package/dist/test/test.helper.d.ts +4 -1
  52. package/dist/test/test.helper.js +51 -25
  53. package/dist/test/test.helper.js.map +1 -1
  54. package/dist/tsconfig.build.tsbuildinfo +1 -1
  55. package/package.json +43 -37
  56. package/src/config.env.ts +4 -2
  57. package/src/core/common/decorators/restricted.decorator.ts +1 -2
  58. package/src/core/common/helpers/db.helper.ts +7 -2
  59. package/src/core/common/helpers/file.helper.ts +9 -11
  60. package/src/core/common/helpers/filter.helper.ts +66 -1
  61. package/src/core/common/helpers/input.helper.ts +61 -2
  62. package/src/core/common/helpers/service.helper.ts +8 -9
  63. package/src/core/common/inputs/filter.input.ts +0 -1
  64. package/src/core/common/interfaces/prepare-input-options.interface.ts +1 -0
  65. package/src/core/common/interfaces/prepare-output-options.interface.ts +1 -0
  66. package/src/core/common/interfaces/server-options.interface.ts +68 -52
  67. package/src/core/common/interfaces/service-options.interface.ts +8 -2
  68. package/src/core/common/models/core-model.model.ts +4 -1
  69. package/src/core/common/services/crud.service.ts +7 -4
  70. package/src/core/common/services/module.service.ts +17 -1
  71. package/src/core/common/types/field-selection.type.ts +1 -1
  72. package/src/core/modules/auth/guards/roles.guard.ts +1 -1
  73. package/src/core/modules/user/core-user.service.ts +13 -22
  74. package/src/core.module.ts +38 -6
  75. package/src/main.ts +16 -0
  76. package/src/server/modules/auth/auth.module.ts +1 -2
  77. package/src/server/modules/file/file.controller.ts +1 -1
  78. package/src/server/modules/file/file.resolver.ts +55 -0
  79. package/src/server/modules/user/user.resolver.ts +1 -1
  80. package/src/server/server.module.ts +5 -1
  81. package/src/test/test.helper.ts +92 -34
@@ -1,9 +1,10 @@
1
1
  import { INestApplication } from '@nestjs/common';
2
- // import { FastifyInstance } from 'fastify';
2
+ import { createClient } from 'graphql-ws';
3
3
  import { jsonToGraphQLQuery } from 'json-to-graphql-query';
4
4
  import * as LightMyRequest from 'light-my-request';
5
5
  import * as supertest from 'supertest';
6
6
  import * as util from 'util';
7
+ import * as ws from 'ws';
7
8
 
8
9
  /**
9
10
  * GraphQL request type
@@ -64,6 +65,11 @@ export interface TestGraphQLOptions {
64
65
  */
65
66
  convertEnums?: boolean | string[];
66
67
 
68
+ /**
69
+ * Count of subscription messages, specifies how many messages are to be received on subscription
70
+ */
71
+ countOfSubscriptionMessages?: number;
72
+
67
73
  /**
68
74
  * Print console logs
69
75
  */
@@ -104,33 +110,35 @@ export class TestHelper {
104
110
  // app: FastifyInstance | INestApplication;
105
111
  app: INestApplication;
106
112
 
113
+ // URL with port and directory to subscription endpoint
114
+ // e.g.: ws://localhost:3030/graphql
115
+ subscriptionUrl: string;
116
+
107
117
  /**
108
118
  * Constructor
109
119
  */
110
- constructor(app: any) {
120
+ constructor(app: any, subscriptionUrl?: string) {
111
121
  this.app = app;
122
+ this.subscriptionUrl = subscriptionUrl;
112
123
  }
113
124
 
114
125
  /**
115
126
  * GraphQL request
116
- * @param graphql
117
- * @param options
118
127
  */
119
128
  async graphQl(graphql: string | TestGraphQLConfig, options: TestGraphQLOptions = {}): Promise<any> {
120
129
  // Default options
121
- options = Object.assign(
122
- {
123
- convertEnums: true,
124
- token: null,
125
- statusCode: 200,
126
- log: false,
127
- logError: false,
128
- },
129
- options
130
- );
130
+ const config = {
131
+ convertEnums: true,
132
+ countOfSubscriptionMessages: 1,
133
+ token: null,
134
+ statusCode: 200,
135
+ log: false,
136
+ logError: false,
137
+ ...options,
138
+ };
131
139
 
132
140
  // Init vars
133
- const { token, statusCode, log, logError } = options;
141
+ const { token, statusCode, log, logError } = config;
134
142
 
135
143
  // Init
136
144
  let query = '';
@@ -174,10 +182,14 @@ export class TestHelper {
174
182
  query = jsonToGraphQLQuery(queryObj, { pretty: true });
175
183
  }
176
184
 
185
+ if ((graphql as TestGraphQLConfig).type === TestGraphQLType.SUBSCRIPTION) {
186
+ return this.getSubscription(graphql as TestGraphQLConfig, query, config);
187
+ }
188
+
177
189
  // Convert uppercase strings in arguments of query to enums
178
- if (options.convertEnums) {
179
- if (Array.isArray(options.convertEnums)) {
180
- for (const key of Object.values(options.convertEnums)) {
190
+ if (config.convertEnums) {
191
+ if (Array.isArray(config.convertEnums)) {
192
+ for (const key of Object.values(config.convertEnums)) {
181
193
  const regExpStr = '(' + key + ': )\\"([_A-Z][_0-9A-Z]*)\\"';
182
194
  const regExp = new RegExp(regExpStr, 'g');
183
195
  query = query.replace(regExp, '$1$2');
@@ -225,28 +237,26 @@ export class TestHelper {
225
237
  */
226
238
  async rest(url: string, options: TestRestOptions = {}): Promise<any> {
227
239
  // Default options
228
- options = Object.assign(
229
- {
230
- token: null,
231
- statusCode: 200,
232
- log: false,
233
- logError: false,
234
- payload: null,
235
- method: 'GET',
236
- },
237
- options
238
- );
240
+ const config: TestRestOptions = {
241
+ token: null,
242
+ statusCode: 200,
243
+ log: false,
244
+ logError: false,
245
+ payload: null,
246
+ method: 'GET',
247
+ ...options,
248
+ };
239
249
 
240
250
  // Init vars
241
- const { token, statusCode, log, logError } = options;
251
+ const { token, statusCode, log, logError } = config;
242
252
 
243
253
  // Request configuration
244
254
  const requestConfig: LightMyRequest.InjectOptions = {
245
- method: options.method,
255
+ method: config.method,
246
256
  url,
247
257
  };
248
- if (options.payload) {
249
- requestConfig.payload = options.payload;
258
+ if (config.payload) {
259
+ requestConfig.payload = config.payload;
250
260
  }
251
261
 
252
262
  // Process response
@@ -354,7 +364,7 @@ export class TestHelper {
354
364
 
355
365
  // Log response
356
366
  if (log) {
357
- console.log(response);
367
+ console.log(JSON.stringify(response, null, 2));
358
368
  }
359
369
 
360
370
  // Log error
@@ -373,4 +383,52 @@ export class TestHelper {
373
383
  // Return response
374
384
  return response;
375
385
  }
386
+
387
+ /**
388
+ * Get subscription
389
+ */
390
+ async getSubscription(graphql: TestGraphQLConfig, query: string, options?: TestGraphQLOptions) {
391
+ // Check url
392
+ if (!this.subscriptionUrl) {
393
+ throw new Error("Missing subscriptionUrl in TestHelper: new TestHelper(app, 'ws://localhost:3030/graphql')");
394
+ }
395
+
396
+ // Prepare subscription
397
+ let connectionParams;
398
+ if (options?.token) {
399
+ connectionParams = { Authorization: `Bearer ${options?.token}` };
400
+ }
401
+
402
+ // Init client
403
+ if (options.log) {
404
+ console.log('Subscription query', JSON.stringify(query, null, 2));
405
+ }
406
+ const client = createClient({ url: this.subscriptionUrl, connectionParams, webSocketImpl: ws });
407
+ const messages: any[] = [];
408
+ let unsubscribe: () => void;
409
+ const onNext = (message) => {
410
+ if (options.log) {
411
+ console.log('Subscription message', JSON.stringify(message, null, 2));
412
+ }
413
+ messages.push(message?.data?.[graphql.name]);
414
+ if (messages.length <= options.countOfSubscriptionMessages) {
415
+ unsubscribe();
416
+ }
417
+ };
418
+
419
+ // Subscribe
420
+ await new Promise((resolve, reject) => {
421
+ unsubscribe = client.subscribe(
422
+ { query },
423
+ {
424
+ next: onNext,
425
+ error: reject,
426
+ complete: resolve as any,
427
+ }
428
+ );
429
+ });
430
+
431
+ // Return subscribed messages
432
+ return messages;
433
+ }
376
434
  }