@nestjs/common 8.4.7 → 9.0.0
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/Readme.md +2 -0
- package/cache/cache.constants.d.ts +0 -1
- package/cache/cache.constants.js +1 -2
- package/cache/cache.module-definition.d.ts +2 -0
- package/cache/cache.module-definition.js +10 -0
- package/cache/cache.module.d.ts +2 -3
- package/cache/cache.module.js +6 -43
- package/cache/cache.providers.js +2 -1
- package/cache/interfaces/cache-module.interface.d.ts +6 -2
- package/decorators/core/controller.decorator.js +1 -1
- package/exceptions/http.exception.d.ts +9 -0
- package/exceptions/http.exception.js +13 -0
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/interfaces/http/http-server.interface.d.ts +3 -1
- package/interfaces/http/index.d.ts +1 -0
- package/interfaces/http/index.js +1 -0
- package/{http/interfaces → interfaces/http}/raw-body-request.interface.d.ts +0 -0
- package/{http/interfaces → interfaces/http}/raw-body-request.interface.js +0 -0
- package/interfaces/modules/provider.interface.d.ts +27 -1
- package/interfaces/nest-application-context.interface.d.ts +1 -1
- package/interfaces/nest-application.interface.d.ts +0 -16
- package/interfaces/nest-microservice.interface.d.ts +0 -7
- package/interfaces/scope-options.interface.d.ts +7 -0
- package/interfaces/version-options.interface.d.ts +1 -1
- package/module-utils/configurable-module.builder.d.ts +93 -0
- package/module-utils/configurable-module.builder.js +195 -0
- package/module-utils/constants.d.ts +4 -0
- package/module-utils/constants.js +7 -0
- package/module-utils/index.d.ts +2 -0
- package/{http → module-utils}/index.js +1 -2
- package/module-utils/interfaces/configurable-module-async-options.interface.d.ts +36 -0
- package/{http/interfaces/http-module.interface.js → module-utils/interfaces/configurable-module-async-options.interface.js} +0 -0
- package/module-utils/interfaces/configurable-module-cls.interface.d.ts +13 -0
- package/module-utils/interfaces/configurable-module-cls.interface.js +2 -0
- package/module-utils/interfaces/configurable-module-host.interface.d.ts +62 -0
- package/module-utils/interfaces/configurable-module-host.interface.js +2 -0
- package/module-utils/interfaces/index.d.ts +3 -0
- package/module-utils/interfaces/index.js +6 -0
- package/module-utils/utils/generate-options-injection-token.util.d.ts +1 -0
- package/module-utils/utils/generate-options-injection-token.util.js +9 -0
- package/package.json +1 -2
- package/pipes/file/file-type.validator.d.ts +19 -0
- package/pipes/file/file-type.validator.js +30 -0
- package/pipes/file/file-validator.interface.d.ts +17 -0
- package/pipes/file/file-validator.interface.js +12 -0
- package/pipes/file/index.d.ts +6 -0
- package/pipes/file/index.js +9 -0
- package/pipes/file/max-file-size.validator.d.ts +15 -0
- package/pipes/file/max-file-size.validator.js +23 -0
- package/pipes/file/parse-file-options.interface.d.ts +7 -0
- package/pipes/file/parse-file-options.interface.js +2 -0
- package/pipes/file/parse-file-pipe.builder.d.ts +10 -0
- package/pipes/file/parse-file-pipe.builder.js +25 -0
- package/pipes/file/parse-file.pipe.d.ts +25 -0
- package/pipes/file/parse-file.pipe.js +57 -0
- package/pipes/index.d.ts +1 -0
- package/pipes/index.js +1 -0
- package/pipes/parse-uuid.pipe.d.ts +7 -0
- package/pipes/parse-uuid.pipe.js +19 -5
- package/services/console-logger.service.js +2 -2
- package/services/logger.service.js +1 -1
- package/utils/cli-colors.util.d.ts +1 -0
- package/utils/cli-colors.util.js +1 -0
- package/utils/shared.utils.d.ts +0 -5
- package/utils/shared.utils.js +1 -6
- package/http/http.constants.d.ts +0 -3
- package/http/http.constants.js +0 -6
- package/http/http.module.d.ts +0 -11
- package/http/http.module.js +0 -88
- package/http/http.service.d.ts +0 -19
- package/http/http.service.js +0 -74
- package/http/index.d.ts +0 -3
- package/http/interfaces/http-module.interface.d.ts +0 -13
- package/http/interfaces/index.d.ts +0 -2
- package/http/interfaces/index.js +0 -5
- package/utils/is-uuid.d.ts +0 -1
- package/utils/is-uuid.js +0 -19
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseFilePipe = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("../../decorators/core");
|
|
6
|
+
const enums_1 = require("../../enums");
|
|
7
|
+
const http_error_by_code_util_1 = require("../../utils/http-error-by-code.util");
|
|
8
|
+
/**
|
|
9
|
+
* Defines the built-in ParseFile Pipe. This pipe can be used to validate incoming files
|
|
10
|
+
* with `@UploadedFile()` decorator. You can use either other specific built-in validators
|
|
11
|
+
* or provide one of your own, simply implementing it through {@link FileValidator}
|
|
12
|
+
* interface and adding it to ParseFilePipe's constructor.
|
|
13
|
+
*
|
|
14
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
15
|
+
*
|
|
16
|
+
* @publicApi
|
|
17
|
+
*/
|
|
18
|
+
let ParseFilePipe = class ParseFilePipe {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
const { exceptionFactory, errorHttpStatusCode = enums_1.HttpStatus.BAD_REQUEST, validators = [], } = options;
|
|
21
|
+
this.exceptionFactory =
|
|
22
|
+
exceptionFactory ||
|
|
23
|
+
(error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
|
24
|
+
this.validators = validators;
|
|
25
|
+
}
|
|
26
|
+
async transform(value) {
|
|
27
|
+
if (this.validators.length) {
|
|
28
|
+
await this.validate(value);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
async validate(file) {
|
|
33
|
+
for (const validator of this.validators) {
|
|
34
|
+
await this.validateOrThrow(file, validator);
|
|
35
|
+
}
|
|
36
|
+
return file;
|
|
37
|
+
}
|
|
38
|
+
async validateOrThrow(file, validator) {
|
|
39
|
+
const isValid = await validator.isValid(file);
|
|
40
|
+
if (!isValid) {
|
|
41
|
+
const errorMessage = validator.buildErrorMessage(file);
|
|
42
|
+
throw this.exceptionFactory(errorMessage);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @returns list of validators used in this pipe.
|
|
47
|
+
*/
|
|
48
|
+
getValidators() {
|
|
49
|
+
return this.validators;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
ParseFilePipe = tslib_1.__decorate([
|
|
53
|
+
(0, core_1.Injectable)(),
|
|
54
|
+
tslib_1.__param(0, (0, core_1.Optional)()),
|
|
55
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
56
|
+
], ParseFilePipe);
|
|
57
|
+
exports.ParseFilePipe = ParseFilePipe;
|
package/pipes/index.d.ts
CHANGED
package/pipes/index.js
CHANGED
|
@@ -9,3 +9,4 @@ tslib_1.__exportStar(require("./parse-float.pipe"), exports);
|
|
|
9
9
|
tslib_1.__exportStar(require("./parse-enum.pipe"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./parse-uuid.pipe"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./validation.pipe"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./file"), exports);
|
|
@@ -6,8 +6,15 @@ export interface ParseUUIDPipeOptions {
|
|
|
6
6
|
exceptionFactory?: (errors: string) => any;
|
|
7
7
|
}
|
|
8
8
|
export declare class ParseUUIDPipe implements PipeTransform<string> {
|
|
9
|
+
protected static uuidRegExps: {
|
|
10
|
+
3: RegExp;
|
|
11
|
+
4: RegExp;
|
|
12
|
+
5: RegExp;
|
|
13
|
+
all: RegExp;
|
|
14
|
+
};
|
|
9
15
|
private readonly version;
|
|
10
16
|
protected exceptionFactory: (errors: string) => any;
|
|
11
17
|
constructor(options?: ParseUUIDPipeOptions);
|
|
12
18
|
transform(value: string, metadata: ArgumentMetadata): Promise<string>;
|
|
19
|
+
protected isUUID(str: unknown, version?: string): any;
|
|
13
20
|
}
|
package/pipes/parse-uuid.pipe.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var ParseUUIDPipe_1;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.ParseUUIDPipe = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
@@ -6,8 +7,8 @@ const injectable_decorator_1 = require("../decorators/core/injectable.decorator"
|
|
|
6
7
|
const optional_decorator_1 = require("../decorators/core/optional.decorator");
|
|
7
8
|
const http_status_enum_1 = require("../enums/http-status.enum");
|
|
8
9
|
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
9
|
-
const
|
|
10
|
-
let ParseUUIDPipe = class ParseUUIDPipe {
|
|
10
|
+
const shared_utils_1 = require("../utils/shared.utils");
|
|
11
|
+
let ParseUUIDPipe = ParseUUIDPipe_1 = class ParseUUIDPipe {
|
|
11
12
|
constructor(options) {
|
|
12
13
|
options = options || {};
|
|
13
14
|
const { exceptionFactory, errorHttpStatusCode = http_status_enum_1.HttpStatus.BAD_REQUEST, version, } = options;
|
|
@@ -17,13 +18,26 @@ let ParseUUIDPipe = class ParseUUIDPipe {
|
|
|
17
18
|
(error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
|
18
19
|
}
|
|
19
20
|
async transform(value, metadata) {
|
|
20
|
-
if (!
|
|
21
|
-
throw this.exceptionFactory(`Validation failed (uuid
|
|
21
|
+
if (!this.isUUID(value, this.version)) {
|
|
22
|
+
throw this.exceptionFactory(`Validation failed (uuid${this.version ? ` v ${this.version}` : ''} is expected)`);
|
|
22
23
|
}
|
|
23
24
|
return value;
|
|
24
25
|
}
|
|
26
|
+
isUUID(str, version = 'all') {
|
|
27
|
+
if (!(0, shared_utils_1.isString)(str)) {
|
|
28
|
+
throw this.exceptionFactory('The value passed as UUID is not a string');
|
|
29
|
+
}
|
|
30
|
+
const pattern = ParseUUIDPipe_1.uuidRegExps[version];
|
|
31
|
+
return pattern === null || pattern === void 0 ? void 0 : pattern.test(str);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
ParseUUIDPipe.uuidRegExps = {
|
|
35
|
+
3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
36
|
+
4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
37
|
+
5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
38
|
+
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
25
39
|
};
|
|
26
|
-
ParseUUIDPipe = tslib_1.__decorate([
|
|
40
|
+
ParseUUIDPipe = ParseUUIDPipe_1 = tslib_1.__decorate([
|
|
27
41
|
(0, injectable_decorator_1.Injectable)(),
|
|
28
42
|
tslib_1.__param(0, (0, optional_decorator_1.Optional)()),
|
|
29
43
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
@@ -119,8 +119,8 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
|
|
|
119
119
|
const contextMessage = context ? (0, cli_colors_util_1.yellow)(`[${context}] `) : '';
|
|
120
120
|
const timestampDiff = this.updateAndGetTimestampDiff();
|
|
121
121
|
const formattedLogLevel = logLevel.toUpperCase().padStart(7, ' ');
|
|
122
|
-
const
|
|
123
|
-
process[writeStreamType !== null && writeStreamType !== void 0 ? writeStreamType : 'stdout'].write(
|
|
122
|
+
const formattedMessage = this.formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff);
|
|
123
|
+
process[writeStreamType !== null && writeStreamType !== void 0 ? writeStreamType : 'stdout'].write(formattedMessage);
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
formatPid(pid) {
|
|
@@ -122,7 +122,7 @@ let Logger = Logger_1 = class Logger {
|
|
|
122
122
|
}
|
|
123
123
|
if ((0, shared_utils_1.isObject)(logger)) {
|
|
124
124
|
if (logger instanceof Logger_1 && logger.constructor !== Logger_1) {
|
|
125
|
-
const errorMessage = `Using the "extends Logger" instruction is not allowed in Nest
|
|
125
|
+
const errorMessage = `Using the "extends Logger" instruction is not allowed in Nest v9. Please, use "extends ConsoleLogger" instead.`;
|
|
126
126
|
this.staticInstanceRef.error(errorMessage);
|
|
127
127
|
throw new Error(errorMessage);
|
|
128
128
|
}
|
package/utils/cli-colors.util.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.yellow = exports.clc = void 0;
|
|
|
4
4
|
const isColorAllowed = () => !process.env.NO_COLOR;
|
|
5
5
|
const colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
|
|
6
6
|
exports.clc = {
|
|
7
|
+
bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
|
|
7
8
|
green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
|
|
8
9
|
yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
|
|
9
10
|
red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
|
package/utils/shared.utils.d.ts
CHANGED
|
@@ -2,11 +2,6 @@ export declare const isUndefined: (obj: any) => obj is undefined;
|
|
|
2
2
|
export declare const isObject: (fn: any) => fn is object;
|
|
3
3
|
export declare const isPlainObject: (fn: any) => fn is object;
|
|
4
4
|
export declare const addLeadingSlash: (path?: string) => string;
|
|
5
|
-
/**
|
|
6
|
-
* Deprecated. Use the "addLeadingSlash" function instead.
|
|
7
|
-
* @deprecated
|
|
8
|
-
*/
|
|
9
|
-
export declare const validatePath: (path?: string) => string;
|
|
10
5
|
export declare const normalizePath: (path?: string) => string;
|
|
11
6
|
export declare const stripEndSlash: (path: string) => string;
|
|
12
7
|
export declare const isFunction: (val: any) => boolean;
|
package/utils/shared.utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSymbol = exports.isEmpty = exports.isNil = exports.isConstructor = exports.isNumber = exports.isString = exports.isFunction = exports.stripEndSlash = exports.normalizePath = exports.
|
|
3
|
+
exports.isSymbol = exports.isEmpty = exports.isNil = exports.isConstructor = exports.isNumber = exports.isString = exports.isFunction = exports.stripEndSlash = exports.normalizePath = exports.addLeadingSlash = exports.isPlainObject = exports.isObject = exports.isUndefined = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
5
5
|
const isUndefined = (obj) => typeof obj === 'undefined';
|
|
6
6
|
exports.isUndefined = isUndefined;
|
|
@@ -28,11 +28,6 @@ const addLeadingSlash = (path) => path && typeof path === 'string'
|
|
|
28
28
|
: path
|
|
29
29
|
: '';
|
|
30
30
|
exports.addLeadingSlash = addLeadingSlash;
|
|
31
|
-
/**
|
|
32
|
-
* Deprecated. Use the "addLeadingSlash" function instead.
|
|
33
|
-
* @deprecated
|
|
34
|
-
*/
|
|
35
|
-
exports.validatePath = exports.addLeadingSlash;
|
|
36
31
|
const normalizePath = (path) => path
|
|
37
32
|
? path.startsWith('/')
|
|
38
33
|
? ('/' + path.replace(/\/+$/, '')).replace(/\/+/g, '/')
|
package/http/http.constants.d.ts
DELETED
package/http/http.constants.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HTTP_MODULE_OPTIONS = exports.HTTP_MODULE_ID = exports.AXIOS_INSTANCE_TOKEN = void 0;
|
|
4
|
-
exports.AXIOS_INSTANCE_TOKEN = 'AXIOS_INSTANCE_TOKEN';
|
|
5
|
-
exports.HTTP_MODULE_ID = 'HTTP_MODULE_ID';
|
|
6
|
-
exports.HTTP_MODULE_OPTIONS = 'HTTP_MODULE_OPTIONS';
|
package/http/http.module.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { DynamicModule } from '../interfaces';
|
|
2
|
-
import { HttpModuleAsyncOptions, HttpModuleOptions } from './interfaces';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.
|
|
5
|
-
*/
|
|
6
|
-
export declare class HttpModule {
|
|
7
|
-
static register(config: HttpModuleOptions): DynamicModule;
|
|
8
|
-
static registerAsync(options: HttpModuleAsyncOptions): DynamicModule;
|
|
9
|
-
private static createAsyncProviders;
|
|
10
|
-
private static createAsyncOptionsProvider;
|
|
11
|
-
}
|
package/http/http.module.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var HttpModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.HttpModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const axios_1 = require("axios");
|
|
7
|
-
const module_decorator_1 = require("../decorators/modules/module.decorator");
|
|
8
|
-
const random_string_generator_util_1 = require("../utils/random-string-generator.util");
|
|
9
|
-
const http_constants_1 = require("./http.constants");
|
|
10
|
-
const http_service_1 = require("./http.service");
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.
|
|
13
|
-
*/
|
|
14
|
-
let HttpModule = HttpModule_1 = class HttpModule {
|
|
15
|
-
static register(config) {
|
|
16
|
-
return {
|
|
17
|
-
module: HttpModule_1,
|
|
18
|
-
providers: [
|
|
19
|
-
{
|
|
20
|
-
provide: http_constants_1.AXIOS_INSTANCE_TOKEN,
|
|
21
|
-
useValue: axios_1.default.create(config),
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
provide: http_constants_1.HTTP_MODULE_ID,
|
|
25
|
-
useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
static registerAsync(options) {
|
|
31
|
-
return {
|
|
32
|
-
module: HttpModule_1,
|
|
33
|
-
imports: options.imports,
|
|
34
|
-
providers: [
|
|
35
|
-
...this.createAsyncProviders(options),
|
|
36
|
-
{
|
|
37
|
-
provide: http_constants_1.AXIOS_INSTANCE_TOKEN,
|
|
38
|
-
useFactory: (config) => axios_1.default.create(config),
|
|
39
|
-
inject: [http_constants_1.HTTP_MODULE_OPTIONS],
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
provide: http_constants_1.HTTP_MODULE_ID,
|
|
43
|
-
useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
|
|
44
|
-
},
|
|
45
|
-
...(options.extraProviders || []),
|
|
46
|
-
],
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
static createAsyncProviders(options) {
|
|
50
|
-
if (options.useExisting || options.useFactory) {
|
|
51
|
-
return [this.createAsyncOptionsProvider(options)];
|
|
52
|
-
}
|
|
53
|
-
return [
|
|
54
|
-
this.createAsyncOptionsProvider(options),
|
|
55
|
-
{
|
|
56
|
-
provide: options.useClass,
|
|
57
|
-
useClass: options.useClass,
|
|
58
|
-
},
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
|
-
static createAsyncOptionsProvider(options) {
|
|
62
|
-
if (options.useFactory) {
|
|
63
|
-
return {
|
|
64
|
-
provide: http_constants_1.HTTP_MODULE_OPTIONS,
|
|
65
|
-
useFactory: options.useFactory,
|
|
66
|
-
inject: options.inject || [],
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
provide: http_constants_1.HTTP_MODULE_OPTIONS,
|
|
71
|
-
useFactory: async (optionsFactory) => optionsFactory.createHttpOptions(),
|
|
72
|
-
inject: [options.useExisting || options.useClass],
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
HttpModule = HttpModule_1 = tslib_1.__decorate([
|
|
77
|
-
(0, module_decorator_1.Module)({
|
|
78
|
-
providers: [
|
|
79
|
-
http_service_1.HttpService,
|
|
80
|
-
{
|
|
81
|
-
provide: http_constants_1.AXIOS_INSTANCE_TOKEN,
|
|
82
|
-
useValue: axios_1.default,
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
exports: [http_service_1.HttpService],
|
|
86
|
-
})
|
|
87
|
-
], HttpModule);
|
|
88
|
-
exports.HttpModule = HttpModule;
|
package/http/http.service.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.
|
|
5
|
-
*/
|
|
6
|
-
export declare class HttpService {
|
|
7
|
-
private readonly instance;
|
|
8
|
-
private readonly logger;
|
|
9
|
-
constructor(instance?: AxiosInstance);
|
|
10
|
-
request<T = any>(config: AxiosRequestConfig): Observable<AxiosResponse<T>>;
|
|
11
|
-
get<T = any>(url: string, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
|
|
12
|
-
delete<T = any>(url: string, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
|
|
13
|
-
head<T = any>(url: string, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
|
|
14
|
-
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
|
|
15
|
-
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
|
|
16
|
-
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
|
|
17
|
-
get axiosRef(): AxiosInstance;
|
|
18
|
-
private makeObservable;
|
|
19
|
-
}
|
package/http/http.service.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const axios_1 = require("axios");
|
|
6
|
-
const rxjs_1 = require("rxjs");
|
|
7
|
-
const decorators_1 = require("../decorators");
|
|
8
|
-
const services_1 = require("../services");
|
|
9
|
-
const http_constants_1 = require("./http.constants");
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.
|
|
12
|
-
*/
|
|
13
|
-
let HttpService = class HttpService {
|
|
14
|
-
constructor(instance = axios_1.default) {
|
|
15
|
-
this.instance = instance;
|
|
16
|
-
this.logger = new services_1.Logger(HttpService.name);
|
|
17
|
-
this.logger.warn('DEPRECATED! "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.');
|
|
18
|
-
}
|
|
19
|
-
request(config) {
|
|
20
|
-
return this.makeObservable(this.instance.request, config);
|
|
21
|
-
}
|
|
22
|
-
get(url, config) {
|
|
23
|
-
return this.makeObservable(this.instance.get, url, config);
|
|
24
|
-
}
|
|
25
|
-
delete(url, config) {
|
|
26
|
-
return this.makeObservable(this.instance.delete, url, config);
|
|
27
|
-
}
|
|
28
|
-
head(url, config) {
|
|
29
|
-
return this.makeObservable(this.instance.head, url, config);
|
|
30
|
-
}
|
|
31
|
-
post(url, data, config) {
|
|
32
|
-
return this.makeObservable(this.instance.post, url, data, config);
|
|
33
|
-
}
|
|
34
|
-
put(url, data, config) {
|
|
35
|
-
return this.makeObservable(this.instance.put, url, data, config);
|
|
36
|
-
}
|
|
37
|
-
patch(url, data, config) {
|
|
38
|
-
return this.makeObservable(this.instance.patch, url, data, config);
|
|
39
|
-
}
|
|
40
|
-
get axiosRef() {
|
|
41
|
-
return this.instance;
|
|
42
|
-
}
|
|
43
|
-
makeObservable(axios, ...args) {
|
|
44
|
-
return new rxjs_1.Observable(subscriber => {
|
|
45
|
-
const config = Object.assign({}, (args[args.length - 1] || {}));
|
|
46
|
-
let cancelSource;
|
|
47
|
-
if (!config.cancelToken) {
|
|
48
|
-
cancelSource = axios_1.default.CancelToken.source();
|
|
49
|
-
config.cancelToken = cancelSource.token;
|
|
50
|
-
}
|
|
51
|
-
axios(...args)
|
|
52
|
-
.then(res => {
|
|
53
|
-
subscriber.next(res);
|
|
54
|
-
subscriber.complete();
|
|
55
|
-
})
|
|
56
|
-
.catch(err => {
|
|
57
|
-
subscriber.error(err);
|
|
58
|
-
});
|
|
59
|
-
return () => {
|
|
60
|
-
if (config.responseType === 'stream') {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (cancelSource) {
|
|
64
|
-
cancelSource.cancel();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
HttpService = tslib_1.__decorate([
|
|
71
|
-
tslib_1.__param(0, (0, decorators_1.Inject)(http_constants_1.AXIOS_INSTANCE_TOKEN)),
|
|
72
|
-
tslib_1.__metadata("design:paramtypes", [Function])
|
|
73
|
-
], HttpService);
|
|
74
|
-
exports.HttpService = HttpService;
|
package/http/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { ModuleMetadata, Provider, Type } from '../../interfaces';
|
|
3
|
-
export declare type HttpModuleOptions = AxiosRequestConfig;
|
|
4
|
-
export interface HttpModuleOptionsFactory {
|
|
5
|
-
createHttpOptions(): Promise<HttpModuleOptions> | HttpModuleOptions;
|
|
6
|
-
}
|
|
7
|
-
export interface HttpModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
8
|
-
useExisting?: Type<HttpModuleOptionsFactory>;
|
|
9
|
-
useClass?: Type<HttpModuleOptionsFactory>;
|
|
10
|
-
useFactory?: (...args: any[]) => Promise<HttpModuleOptions> | HttpModuleOptions;
|
|
11
|
-
inject?: any[];
|
|
12
|
-
extraProviders?: Provider[];
|
|
13
|
-
}
|
package/http/interfaces/index.js
DELETED
package/utils/is-uuid.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isUUID(str: any, version?: string): any;
|
package/utils/is-uuid.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUUID = void 0;
|
|
4
|
-
const exceptions_1 = require("../exceptions");
|
|
5
|
-
const shared_utils_1 = require("./shared.utils");
|
|
6
|
-
const uuid = {
|
|
7
|
-
3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
8
|
-
4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
9
|
-
5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
10
|
-
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
11
|
-
};
|
|
12
|
-
function isUUID(str, version = 'all') {
|
|
13
|
-
if (!(0, shared_utils_1.isString)(str)) {
|
|
14
|
-
throw new exceptions_1.BadRequestException('The value passed as UUID is not a string');
|
|
15
|
-
}
|
|
16
|
-
const pattern = uuid[version];
|
|
17
|
-
return pattern && pattern.test(str);
|
|
18
|
-
}
|
|
19
|
-
exports.isUUID = isUUID;
|