@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.
- package/dist/config.env.js +4 -2
- package/dist/config.env.js.map +1 -1
- package/dist/core/common/decorators/restricted.decorator.js +4 -4
- package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
- package/dist/core/common/helpers/db.helper.js +3 -2
- package/dist/core/common/helpers/db.helper.js.map +1 -1
- package/dist/core/common/helpers/file.helper.js +4 -7
- package/dist/core/common/helpers/file.helper.js.map +1 -1
- package/dist/core/common/helpers/filter.helper.d.ts +7 -0
- package/dist/core/common/helpers/filter.helper.js +38 -1
- package/dist/core/common/helpers/filter.helper.js.map +1 -1
- package/dist/core/common/helpers/input.helper.d.ts +6 -0
- package/dist/core/common/helpers/input.helper.js +28 -6
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/common/helpers/service.helper.d.ts +2 -0
- package/dist/core/common/helpers/service.helper.js +7 -9
- package/dist/core/common/helpers/service.helper.js.map +1 -1
- package/dist/core/common/inputs/filter.input.js.map +1 -1
- package/dist/core/common/interfaces/prepare-input-options.interface.d.ts +1 -0
- package/dist/core/common/interfaces/prepare-output-options.interface.d.ts +1 -0
- package/dist/core/common/interfaces/server-options.interface.d.ts +16 -13
- package/dist/core/common/interfaces/service-options.interface.d.ts +3 -1
- package/dist/core/common/models/core-model.model.js +4 -1
- package/dist/core/common/models/core-model.model.js.map +1 -1
- package/dist/core/common/services/crud.service.js +9 -4
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/core/common/services/module.service.js +14 -2
- package/dist/core/common/services/module.service.js.map +1 -1
- package/dist/core/common/types/field-selection.type.d.ts +1 -1
- package/dist/core/modules/auth/guards/roles.guard.js +2 -1
- package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
- package/dist/core/modules/user/core-user.service.js +9 -13
- package/dist/core/modules/user/core-user.service.js.map +1 -1
- package/dist/core.module.d.ts +3 -2
- package/dist/core.module.js +26 -4
- package/dist/core.module.js.map +1 -1
- package/dist/main.js +13 -0
- package/dist/main.js.map +1 -1
- package/dist/server/modules/auth/auth.module.js +1 -2
- package/dist/server/modules/auth/auth.module.js.map +1 -1
- package/dist/server/modules/file/file.controller.js +1 -1
- package/dist/server/modules/file/file.controller.js.map +1 -1
- package/dist/server/modules/file/file.resolver.d.ts +5 -0
- package/dist/server/modules/file/file.resolver.js +51 -0
- package/dist/server/modules/file/file.resolver.js.map +1 -0
- package/dist/server/modules/user/user.model.d.ts +14 -1
- package/dist/server/modules/user/user.resolver.js +2 -1
- package/dist/server/modules/user/user.resolver.js.map +1 -1
- package/dist/server/server.module.js +3 -1
- package/dist/server/server.module.js.map +1 -1
- package/dist/test/test.helper.d.ts +4 -1
- package/dist/test/test.helper.js +51 -25
- package/dist/test/test.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +43 -37
- package/src/config.env.ts +4 -2
- package/src/core/common/decorators/restricted.decorator.ts +1 -2
- package/src/core/common/helpers/db.helper.ts +7 -2
- package/src/core/common/helpers/file.helper.ts +9 -11
- package/src/core/common/helpers/filter.helper.ts +66 -1
- package/src/core/common/helpers/input.helper.ts +61 -2
- package/src/core/common/helpers/service.helper.ts +8 -9
- package/src/core/common/inputs/filter.input.ts +0 -1
- package/src/core/common/interfaces/prepare-input-options.interface.ts +1 -0
- package/src/core/common/interfaces/prepare-output-options.interface.ts +1 -0
- package/src/core/common/interfaces/server-options.interface.ts +68 -52
- package/src/core/common/interfaces/service-options.interface.ts +8 -2
- package/src/core/common/models/core-model.model.ts +4 -1
- package/src/core/common/services/crud.service.ts +7 -4
- package/src/core/common/services/module.service.ts +17 -1
- package/src/core/common/types/field-selection.type.ts +1 -1
- package/src/core/modules/auth/guards/roles.guard.ts +1 -1
- package/src/core/modules/user/core-user.service.ts +13 -22
- package/src/core.module.ts +38 -6
- package/src/main.ts +16 -0
- package/src/server/modules/auth/auth.module.ts +1 -2
- package/src/server/modules/file/file.controller.ts +1 -1
- package/src/server/modules/file/file.resolver.ts +55 -0
- package/src/server/modules/user/user.resolver.ts +1 -1
- package/src/server/server.module.ts +5 -1
- package/src/test/test.helper.ts +92 -34
package/src/test/test.helper.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { INestApplication } from '@nestjs/common';
|
|
2
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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 } =
|
|
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 (
|
|
179
|
-
if (Array.isArray(
|
|
180
|
-
for (const key of Object.values(
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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 } =
|
|
251
|
+
const { token, statusCode, log, logError } = config;
|
|
242
252
|
|
|
243
253
|
// Request configuration
|
|
244
254
|
const requestConfig: LightMyRequest.InjectOptions = {
|
|
245
|
-
method:
|
|
255
|
+
method: config.method,
|
|
246
256
|
url,
|
|
247
257
|
};
|
|
248
|
-
if (
|
|
249
|
-
requestConfig.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
|
}
|