@nest-yalc-2/utils 1.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/LICENSE +661 -0
- package/README.md +9 -0
- package/package.json +29 -0
- package/src/__mocks__/enum.mock.ts +9 -0
- package/src/__tests__/class.helper.spec.ts +32 -0
- package/src/__tests__/command.helper.spec.ts +35 -0
- package/src/__tests__/config-manager.helper.spec.ts +93 -0
- package/src/__tests__/custom-validator.spec.ts +34 -0
- package/src/__tests__/data-structure.helper.spec.ts +30 -0
- package/src/__tests__/date.helper.spec.ts +78 -0
- package/src/__tests__/encryption.helper.spec.ts +45 -0
- package/src/__tests__/enum.helper.spec.ts +53 -0
- package/src/__tests__/env.helper.spec.ts +68 -0
- package/src/__tests__/error.helper.spec.ts +20 -0
- package/src/__tests__/faker-helper.spec.ts +187 -0
- package/src/__tests__/files.helper.spec.ts +22 -0
- package/src/__tests__/http.helper.spec.ts +15 -0
- package/src/__tests__/interval.helper.spec.ts +29 -0
- package/src/__tests__/math.helper.spec.ts +24 -0
- package/src/__tests__/nest.decorator.spec.ts +29 -0
- package/src/__tests__/nest.helper.spec.ts +26 -0
- package/src/__tests__/object-mapper.helper.spec.ts +167 -0
- package/src/__tests__/object-mapper.interceptor.spec.ts +104 -0
- package/src/__tests__/object.helper.spec.ts +181 -0
- package/src/__tests__/plugin.helper.spec.ts +85 -0
- package/src/__tests__/promise.helper.spec.ts +76 -0
- package/src/__tests__/returnValue.spec.ts +49 -0
- package/src/__tests__/rxjs.helper.spec.ts +79 -0
- package/src/__tests__/simple-mapper.interceptor.spec.ts +82 -0
- package/src/__tests__/tsconfig.json +3 -0
- package/src/__tests__/validator-helper.spec.ts +34 -0
- package/src/__tests__/zlib.helper.spec.ts +20 -0
- package/src/class.helper.d.ts +4 -0
- package/src/class.helper.js +19 -0
- package/src/class.helper.js.map +1 -0
- package/src/class.helper.ts +33 -0
- package/src/command.helper.d.ts +1 -0
- package/src/command.helper.js +16 -0
- package/src/command.helper.js.map +1 -0
- package/src/command.helper.ts +19 -0
- package/src/config-manager.helper.d.ts +12 -0
- package/src/config-manager.helper.js +60 -0
- package/src/config-manager.helper.js.map +1 -0
- package/src/config-manager.helper.ts +122 -0
- package/src/custom-validator.d.ts +3 -0
- package/src/custom-validator.js +13 -0
- package/src/custom-validator.js.map +1 -0
- package/src/custom-validator.ts +13 -0
- package/src/data-structure.helper.d.ts +1 -0
- package/src/data-structure.helper.js +13 -0
- package/src/data-structure.helper.js.map +1 -0
- package/src/data-structure.helper.ts +14 -0
- package/src/date.helper.d.ts +12 -0
- package/src/date.helper.js +47 -0
- package/src/date.helper.js.map +1 -0
- package/src/date.helper.ts +65 -0
- package/src/encryption.helper.d.ts +2 -0
- package/src/encryption.helper.js +58 -0
- package/src/encryption.helper.js.map +1 -0
- package/src/encryption.helper.ts +29 -0
- package/src/enum.helper.d.ts +8 -0
- package/src/enum.helper.js +21 -0
- package/src/enum.helper.js.map +1 -0
- package/src/enum.helper.ts +34 -0
- package/src/env.helper.d.ts +3 -0
- package/src/env.helper.js +23 -0
- package/src/env.helper.js.map +1 -0
- package/src/env.helper.ts +35 -0
- package/src/error.helper.d.ts +1 -0
- package/src/error.helper.js +12 -0
- package/src/error.helper.js.map +1 -0
- package/src/error.helper.ts +12 -0
- package/src/faker-helper.d.ts +16 -0
- package/src/faker-helper.js +73 -0
- package/src/faker-helper.js.map +1 -0
- package/src/faker-helper.ts +98 -0
- package/src/files.helper.d.ts +2 -0
- package/src/files.helper.js +13 -0
- package/src/files.helper.js.map +1 -0
- package/src/files.helper.ts +20 -0
- package/src/http.helper.d.ts +26 -0
- package/src/http.helper.js +84 -0
- package/src/http.helper.js.map +1 -0
- package/src/http.helper.ts +152 -0
- package/src/index.d.ts +21 -0
- package/src/index.js +38 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +23 -0
- package/src/interval.helper.d.ts +5 -0
- package/src/interval.helper.js +16 -0
- package/src/interval.helper.js.map +1 -0
- package/src/interval.helper.ts +13 -0
- package/src/math.helper.d.ts +1 -0
- package/src/math.helper.js +8 -0
- package/src/math.helper.js.map +1 -0
- package/src/math.helper.ts +4 -0
- package/src/nest.decorator.d.ts +3 -0
- package/src/nest.decorator.js +10 -0
- package/src/nest.decorator.js.map +1 -0
- package/src/nest.decorator.ts +10 -0
- package/src/nestjs/nest.decorator.d.ts +3 -0
- package/src/nestjs/nest.decorator.js +10 -0
- package/src/nestjs/nest.decorator.js.map +1 -0
- package/src/nestjs/nest.decorator.ts +10 -0
- package/src/nestjs/nest.helper.d.ts +2 -0
- package/src/nestjs/nest.helper.js +7 -0
- package/src/nestjs/nest.helper.js.map +1 -0
- package/src/nestjs/nest.helper.ts +5 -0
- package/src/object-mapper.helper.d.ts +16 -0
- package/src/object-mapper.helper.js +47 -0
- package/src/object-mapper.helper.js.map +1 -0
- package/src/object-mapper.helper.ts +148 -0
- package/src/object-mapper.interceptor.d.ts +16 -0
- package/src/object-mapper.interceptor.js +36 -0
- package/src/object-mapper.interceptor.js.map +1 -0
- package/src/object-mapper.interceptor.ts +51 -0
- package/src/object.helper.d.ts +18 -0
- package/src/object.helper.js +91 -0
- package/src/object.helper.js.map +1 -0
- package/src/object.helper.ts +173 -0
- package/src/plugin.helper.d.ts +22 -0
- package/src/plugin.helper.js +26 -0
- package/src/plugin.helper.js.map +1 -0
- package/src/plugin.helper.ts +42 -0
- package/src/promise.helper.d.ts +13 -0
- package/src/promise.helper.js +71 -0
- package/src/promise.helper.js.map +1 -0
- package/src/promise.helper.ts +65 -0
- package/src/returnValue.d.ts +14 -0
- package/src/returnValue.js +17 -0
- package/src/returnValue.js.map +1 -0
- package/src/returnValue.ts +26 -0
- package/src/rxjs.helper.d.ts +7 -0
- package/src/rxjs.helper.js +33 -0
- package/src/rxjs.helper.js.map +1 -0
- package/src/rxjs.helper.ts +71 -0
- package/src/simple-mapper.interceptor.d.ts +7 -0
- package/src/simple-mapper.interceptor.js +29 -0
- package/src/simple-mapper.interceptor.js.map +1 -0
- package/src/simple-mapper.interceptor.ts +43 -0
- package/src/validator-helper.d.ts +2 -0
- package/src/validator-helper.js +22 -0
- package/src/validator-helper.js.map +1 -0
- package/src/validator-helper.ts +26 -0
- package/src/zlib.helper.d.ts +3 -0
- package/src/zlib.helper.js +25 -0
- package/src/zlib.helper.js.map +1 -0
- package/src/zlib.helper.ts +19 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This method can be used to convert a comma separated list of elements from process.env to an array
|
|
3
|
+
* @param key
|
|
4
|
+
*/
|
|
5
|
+
export const envToArray = <T>(key: string): T[] => {
|
|
6
|
+
// for testing purpose we need to specify only the case of empty string here
|
|
7
|
+
if (process.env[key] === '') return [];
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<T[]>(<unknown>process.env[key]?.split(',').map((v) => v.trim())) ?? []
|
|
11
|
+
);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function envIsTrue(value?: string) {
|
|
15
|
+
if (!value) return false;
|
|
16
|
+
|
|
17
|
+
const val = value.toLowerCase();
|
|
18
|
+
return val === 'true' || val === '1' || val === 'on';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Check that the current env is in production by
|
|
23
|
+
* checking the explicit case first, and the implicit case after (if requested)
|
|
24
|
+
* @param implicitCheck enable implicit check by default
|
|
25
|
+
* @returns boolean
|
|
26
|
+
*/
|
|
27
|
+
export function isProduction(implicitCheck = true) {
|
|
28
|
+
return (
|
|
29
|
+
process.env.NODE_ENV === 'production' ||
|
|
30
|
+
(implicitCheck &&
|
|
31
|
+
['test', 'pipeline', 'development'].every(
|
|
32
|
+
(v) => process.env.NODE_ENV !== v,
|
|
33
|
+
))
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function throwWrap(error: any): never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwWrap = throwWrap;
|
|
4
|
+
function throwWrap(error) {
|
|
5
|
+
if (error instanceof Error) {
|
|
6
|
+
throw error;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
throw new Error(error);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=error.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.helper.js","sourceRoot":"","sources":["error.helper.ts"],"names":[],"mappings":";;AAKA,8BAMC;AAND,SAAgB,SAAS,CAAC,KAAU;IAClC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,MAAM,KAAK,CAAC;IACd,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,KAAe,CAAC,CAAC;IACnC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* If the argument of the function is an instance of Error the function throw it,
|
|
3
|
+
* else it throw a new error instance
|
|
4
|
+
* @throws a wrapped error, avoiding a double wrap of the error
|
|
5
|
+
*/
|
|
6
|
+
export function throwWrap(error: any): never {
|
|
7
|
+
if (error instanceof Error) {
|
|
8
|
+
throw error;
|
|
9
|
+
} else {
|
|
10
|
+
throw new Error(error as string);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const DEF_FAKER_MAX_RETRIES = 1500;
|
|
2
|
+
export declare const DEF_FAKER_MAX_TIME = 250;
|
|
3
|
+
export declare class FakerHelper {
|
|
4
|
+
private readonly generatedEmails;
|
|
5
|
+
createPerson(): {
|
|
6
|
+
gender: string;
|
|
7
|
+
firstName: string;
|
|
8
|
+
lastName: string;
|
|
9
|
+
email: string;
|
|
10
|
+
};
|
|
11
|
+
generateNewEmail(firstName: string, lastName: string, provider?: string): string;
|
|
12
|
+
randomFromEnum<T extends Record<string, string | number>>(inputEnum: T): T[keyof T];
|
|
13
|
+
randomDecimal: (min: number, max: number, precision: number) => string;
|
|
14
|
+
randomBirthDate: (start?: number, end?: number) => string;
|
|
15
|
+
randomLockDate: () => Date | undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FakerHelper = exports.DEF_FAKER_MAX_TIME = exports.DEF_FAKER_MAX_RETRIES = void 0;
|
|
4
|
+
const faker_1 = require("@faker-js/faker");
|
|
5
|
+
exports.DEF_FAKER_MAX_RETRIES = 1500;
|
|
6
|
+
exports.DEF_FAKER_MAX_TIME = 250;
|
|
7
|
+
class FakerHelper {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.generatedEmails = new Set();
|
|
10
|
+
this.randomDecimal = (min, max, precision) => {
|
|
11
|
+
return faker_1.faker.number
|
|
12
|
+
.float({ multipleOf: precision, min: min, max: max })
|
|
13
|
+
.toString();
|
|
14
|
+
};
|
|
15
|
+
this.randomBirthDate = (start = 18, end = 100) => {
|
|
16
|
+
const birthDate = faker_1.faker.date.past({ years: end - start });
|
|
17
|
+
birthDate.setUTCFullYear(birthDate.getUTCFullYear() - start);
|
|
18
|
+
const yyyy = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(birthDate);
|
|
19
|
+
const mm = new Intl.DateTimeFormat('en', { month: 'numeric' }).format(birthDate);
|
|
20
|
+
const dd = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(birthDate);
|
|
21
|
+
return `${yyyy}-${mm}-${dd}`;
|
|
22
|
+
};
|
|
23
|
+
this.randomLockDate = () => {
|
|
24
|
+
const random = faker_1.faker.number.int(2);
|
|
25
|
+
if (random === 0) {
|
|
26
|
+
return faker_1.faker.date.past({ years: 3 });
|
|
27
|
+
}
|
|
28
|
+
else if (random === 1) {
|
|
29
|
+
return faker_1.faker.date.future({ years: 1 });
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
createPerson() {
|
|
37
|
+
const gender = faker_1.faker.number.int(1) === 0 ? 'male' : 'female';
|
|
38
|
+
const firstName = faker_1.faker.person.firstName(gender);
|
|
39
|
+
const lastName = faker_1.faker.person.lastName(gender);
|
|
40
|
+
return {
|
|
41
|
+
gender,
|
|
42
|
+
firstName,
|
|
43
|
+
lastName,
|
|
44
|
+
email: this.generateNewEmail(firstName, lastName, 'gmail.test'),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
generateNewEmail(firstName, lastName, provider) {
|
|
48
|
+
const startTime = Date.now();
|
|
49
|
+
for (let attempt = 0; attempt < exports.DEF_FAKER_MAX_RETRIES; attempt++) {
|
|
50
|
+
const email = faker_1.faker.internet.email({ firstName, lastName, provider });
|
|
51
|
+
if (!this.generatedEmails.has(email)) {
|
|
52
|
+
this.generatedEmails.add(email);
|
|
53
|
+
return email;
|
|
54
|
+
}
|
|
55
|
+
if (Date.now() - startTime > exports.DEF_FAKER_MAX_TIME) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const fallbackEmail = faker_1.faker.internet.email({
|
|
60
|
+
firstName,
|
|
61
|
+
lastName,
|
|
62
|
+
provider,
|
|
63
|
+
});
|
|
64
|
+
this.generatedEmails.add(fallbackEmail);
|
|
65
|
+
return fallbackEmail;
|
|
66
|
+
}
|
|
67
|
+
randomFromEnum(inputEnum) {
|
|
68
|
+
const randInt = faker_1.faker.number.int(Object.keys(inputEnum).length - 1);
|
|
69
|
+
return inputEnum[Object.keys(inputEnum)[randInt]];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.FakerHelper = FakerHelper;
|
|
73
|
+
//# sourceMappingURL=faker-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faker-helper.js","sourceRoot":"","sources":["faker-helper.ts"],"names":[],"mappings":";;;AAAA,2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Ae,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAChC,OAAO,KAAK,CAAC;YACf,CAAC;YAED,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,0BAAkB,EAAE,CAAC;gBAChD,MAAM;YACR,CAAC;QACH,CAAC;QAED,MAAM,aAAa,GAAG,aAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;YACzC,SAAS;YACT,QAAQ;YACR,QAAQ;SACT,CAAC,CAAC;QACH,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACxC,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,cAAc,CACZ,SAAY;QAEZ,MAAM,OAAO,GAAG,aAAK,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACpE,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAA2B,CAAC,CAAC;IAC9E,CAAC;CAyCF;AAzFD,kCAyFC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker';
|
|
2
|
+
|
|
3
|
+
// TODO: Probably we can use the internal faker of typeorm-seeding to create uniqueness, like we do here
|
|
4
|
+
// (mentioned in https://github.com/w3tecch/typeorm-seeding/issues/98#issuecomment-849585576)
|
|
5
|
+
|
|
6
|
+
export const DEF_FAKER_MAX_RETRIES = 1500;
|
|
7
|
+
export const DEF_FAKER_MAX_TIME = 250;
|
|
8
|
+
|
|
9
|
+
export class FakerHelper {
|
|
10
|
+
private readonly generatedEmails = new Set<string>();
|
|
11
|
+
|
|
12
|
+
// We could also create a new email from the same person,
|
|
13
|
+
// however we assume when this function is called we actually want a different person.
|
|
14
|
+
createPerson() {
|
|
15
|
+
const gender = faker.number.int(1) === 0 ? 'male' : 'female';
|
|
16
|
+
const firstName = faker.person.firstName(gender);
|
|
17
|
+
const lastName = faker.person.lastName(gender);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
gender,
|
|
21
|
+
firstName,
|
|
22
|
+
lastName,
|
|
23
|
+
email: this.generateNewEmail(firstName, lastName, 'gmail.test'),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
generateNewEmail(firstName: string, lastName: string, provider?: string) {
|
|
28
|
+
const startTime = Date.now();
|
|
29
|
+
|
|
30
|
+
for (let attempt = 0; attempt < DEF_FAKER_MAX_RETRIES; attempt++) {
|
|
31
|
+
const email = faker.internet.email({ firstName, lastName, provider });
|
|
32
|
+
|
|
33
|
+
if (!this.generatedEmails.has(email)) {
|
|
34
|
+
this.generatedEmails.add(email);
|
|
35
|
+
return email;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (Date.now() - startTime > DEF_FAKER_MAX_TIME) {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const fallbackEmail = faker.internet.email({
|
|
44
|
+
firstName,
|
|
45
|
+
lastName,
|
|
46
|
+
provider,
|
|
47
|
+
});
|
|
48
|
+
this.generatedEmails.add(fallbackEmail);
|
|
49
|
+
return fallbackEmail;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
randomFromEnum<T extends Record<string, string | number>>(
|
|
53
|
+
inputEnum: T,
|
|
54
|
+
): T[keyof T] {
|
|
55
|
+
const randInt = faker.number.int(Object.keys(inputEnum).length - 1);
|
|
56
|
+
return inputEnum[Object.keys(inputEnum)[randInt] as keyof typeof inputEnum];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
randomDecimal = (min: number, max: number, precision: number): string => {
|
|
60
|
+
return faker.number
|
|
61
|
+
.float({ multipleOf: precision, min: min, max: max })
|
|
62
|
+
.toString();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Creates a random birthdate for people between 18-82 years of age.
|
|
66
|
+
// Date is returned in format YYYY-MM-DD
|
|
67
|
+
randomBirthDate = (start = 18, end = 100) => {
|
|
68
|
+
const birthDate = faker.date.past({ years: end - start });
|
|
69
|
+
birthDate.setUTCFullYear(birthDate.getUTCFullYear() - start);
|
|
70
|
+
// const [mm, dd, yyyy] = birthDate.format('yyyy-MM-dd').toLocaleString().split(',')[0].split('/');
|
|
71
|
+
const yyyy = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(
|
|
72
|
+
birthDate,
|
|
73
|
+
);
|
|
74
|
+
const mm = new Intl.DateTimeFormat('en', { month: 'numeric' }).format(
|
|
75
|
+
birthDate,
|
|
76
|
+
);
|
|
77
|
+
const dd = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(
|
|
78
|
+
birthDate,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return `${yyyy}-${mm}-${dd}`;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Returns one of three values:
|
|
85
|
+
// * a date in the past (expired lock)
|
|
86
|
+
// * a date in the future (locked till then)
|
|
87
|
+
// * null (db)/undefined (in code) (no locks)
|
|
88
|
+
randomLockDate = () => {
|
|
89
|
+
const random = faker.number.int(2);
|
|
90
|
+
if (random === 0) {
|
|
91
|
+
return faker.date.past({ years: 3 });
|
|
92
|
+
} else if (random === 1) {
|
|
93
|
+
return faker.date.future({ years: 1 });
|
|
94
|
+
} else {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__filename = __filename;
|
|
4
|
+
exports.___dirname = ___dirname;
|
|
5
|
+
const node_url_1 = require("node:url");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
function __filename(path) {
|
|
8
|
+
return (0, node_url_1.fileURLToPath)(path);
|
|
9
|
+
}
|
|
10
|
+
function ___dirname(path) {
|
|
11
|
+
return (0, node_path_1.dirname)(__filename(path));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=files.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.helper.js","sourceRoot":"","sources":["files.helper.ts"],"names":[],"mappings":";;AAQA,gCAEC;AAOD,gCAEC;AAnBD,uCAAyC;AACzC,yCAAoC;AAOpC,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAA,wBAAa,EAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAOD,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAA,mBAAO,EAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Util function to replace the commonjs __filename
|
|
6
|
+
* @param path
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export function __filename(path: string) {
|
|
10
|
+
return fileURLToPath(path);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Util function to replace the commonjs __dirname
|
|
15
|
+
* @param path
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export function ___dirname(path: string) {
|
|
19
|
+
return dirname(__filename(path));
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BadGatewayException, BadRequestException, ConflictException, ForbiddenException, GatewayTimeoutException, GoneException, HttpException, HttpStatus, InternalServerErrorException, MethodNotAllowedException, MisdirectedException, NotAcceptableException, NotFoundException, NotImplementedException, PayloadTooLargeException, PreconditionFailedException, RequestTimeoutException, ServiceUnavailableException, UnauthorizedException, UnprocessableEntityException, UnsupportedMediaTypeException } from '@nestjs/common';
|
|
2
|
+
export declare const HttpStatusCodes: Record<string, any>;
|
|
3
|
+
export type HttpStatusCodes = (typeof HttpStatusCodes)[keyof typeof HttpStatusCodes];
|
|
4
|
+
export declare const getHttpStatusDescription: (status: HttpStatusCodes, fallbackDescription?: string) => string;
|
|
5
|
+
export declare const httpExceptionStatusCodes: {
|
|
6
|
+
[BadRequestException.name]: HttpStatus;
|
|
7
|
+
[UnauthorizedException.name]: HttpStatus;
|
|
8
|
+
[ForbiddenException.name]: HttpStatus;
|
|
9
|
+
[NotFoundException.name]: HttpStatus;
|
|
10
|
+
[MethodNotAllowedException.name]: HttpStatus;
|
|
11
|
+
[NotAcceptableException.name]: HttpStatus;
|
|
12
|
+
[RequestTimeoutException.name]: HttpStatus;
|
|
13
|
+
[ConflictException.name]: HttpStatus;
|
|
14
|
+
[GoneException.name]: HttpStatus;
|
|
15
|
+
[PreconditionFailedException.name]: HttpStatus;
|
|
16
|
+
[PayloadTooLargeException.name]: HttpStatus;
|
|
17
|
+
[UnsupportedMediaTypeException.name]: HttpStatus;
|
|
18
|
+
[UnprocessableEntityException.name]: HttpStatus;
|
|
19
|
+
[InternalServerErrorException.name]: HttpStatus;
|
|
20
|
+
[NotImplementedException.name]: HttpStatus;
|
|
21
|
+
[BadGatewayException.name]: HttpStatus;
|
|
22
|
+
[ServiceUnavailableException.name]: HttpStatus;
|
|
23
|
+
[GatewayTimeoutException.name]: HttpStatus;
|
|
24
|
+
[HttpException.name]: HttpStatus;
|
|
25
|
+
[MisdirectedException.name]: HttpStatus;
|
|
26
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpExceptionStatusCodes = exports.getHttpStatusDescription = exports.HttpStatusCodes = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const axios_1 = require("axios");
|
|
6
|
+
exports.HttpStatusCodes = {
|
|
7
|
+
...common_1.HttpStatus,
|
|
8
|
+
...axios_1.HttpStatusCode,
|
|
9
|
+
};
|
|
10
|
+
const httpStatusDescriptions = {
|
|
11
|
+
[common_1.HttpStatus.CONTINUE]: '100: Request received, server awaiting further info.',
|
|
12
|
+
[common_1.HttpStatus.SWITCHING_PROTOCOLS]: '101: Client asked server to switch protocols.',
|
|
13
|
+
[common_1.HttpStatus.PROCESSING]: '102: Server processing request, no response yet.',
|
|
14
|
+
[common_1.HttpStatus.OK]: '200: Request successful and response provided.',
|
|
15
|
+
[common_1.HttpStatus.CREATED]: '201: Request completed, and resource created.',
|
|
16
|
+
[common_1.HttpStatus.ACCEPTED]: '202: Request accepted but processing not complete.',
|
|
17
|
+
[common_1.HttpStatus.NON_AUTHORITATIVE_INFORMATION]: '203: Info from another source returned.',
|
|
18
|
+
[common_1.HttpStatus.NO_CONTENT]: '204: Request succeeded with no content to send.',
|
|
19
|
+
[common_1.HttpStatus.RESET_CONTENT]: '205: Client should reset document view.',
|
|
20
|
+
[common_1.HttpStatus.PARTIAL_CONTENT]: '206: Partial resource returned due to range header.',
|
|
21
|
+
[common_1.HttpStatus.MOVED_PERMANENTLY]: '301: Resource moved permanently.',
|
|
22
|
+
[common_1.HttpStatus.FOUND]: '302: Resource temporarily moved, use given URI.',
|
|
23
|
+
[common_1.HttpStatus.SEE_OTHER]: '303: Response found elsewhere, use GET for that.',
|
|
24
|
+
[common_1.HttpStatus.NOT_MODIFIED]: '304: Resource not modified since last request.',
|
|
25
|
+
[common_1.HttpStatus.TEMPORARY_REDIRECT]: '307: Resource temporarily moved, but use same method.',
|
|
26
|
+
[common_1.HttpStatus.PERMANENT_REDIRECT]: '308: Resource moved permanently, use same method.',
|
|
27
|
+
[common_1.HttpStatus.BAD_REQUEST]: "400: Server couldn't understand request due to invalid syntax.",
|
|
28
|
+
[common_1.HttpStatus.UNAUTHORIZED]: '401: Authentication needed for request.',
|
|
29
|
+
[common_1.HttpStatus.PAYMENT_REQUIRED]: '402: Payment required for this resource.',
|
|
30
|
+
[common_1.HttpStatus.FORBIDDEN]: '403: Server understood but refuses to authorize.',
|
|
31
|
+
[common_1.HttpStatus.NOT_FOUND]: "404: Server can't find the requested resource.",
|
|
32
|
+
[common_1.HttpStatus.METHOD_NOT_ALLOWED]: '405: HTTP method not allowed for resource.',
|
|
33
|
+
[common_1.HttpStatus.NOT_ACCEPTABLE]: "406: Resource doesn't match criteria.",
|
|
34
|
+
[common_1.HttpStatus.PROXY_AUTHENTICATION_REQUIRED]: '407: Proxy authentication required.',
|
|
35
|
+
[common_1.HttpStatus.REQUEST_TIMEOUT]: '408: Server timed out waiting for request.',
|
|
36
|
+
[common_1.HttpStatus.CONFLICT]: '409: Request conflict with server state.',
|
|
37
|
+
[common_1.HttpStatus.GONE]: '410: Resource requested is no longer available.',
|
|
38
|
+
[common_1.HttpStatus.LENGTH_REQUIRED]: '411: Length of request not specified.',
|
|
39
|
+
[common_1.HttpStatus.PRECONDITION_FAILED]: '412: Precondition for request not met.',
|
|
40
|
+
[common_1.HttpStatus.PAYLOAD_TOO_LARGE]: '413: Request payload too large.',
|
|
41
|
+
[common_1.HttpStatus.URI_TOO_LONG]: '414: URI requested is too long.',
|
|
42
|
+
[common_1.HttpStatus.UNSUPPORTED_MEDIA_TYPE]: '415: Media type not supported.',
|
|
43
|
+
[common_1.HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE]: '416: Range specified is invalid.',
|
|
44
|
+
[common_1.HttpStatus.EXPECTATION_FAILED]: "417: Server can't meet request expectation.",
|
|
45
|
+
[common_1.HttpStatus.I_AM_A_TEAPOT]: "418: I'm a teapot (April Fools joke).",
|
|
46
|
+
[common_1.HttpStatus.UNPROCESSABLE_ENTITY]: '422: Request understandable, but semantically wrong.',
|
|
47
|
+
[common_1.HttpStatus.FAILED_DEPENDENCY]: "424: Request failed due to server's previous request.",
|
|
48
|
+
[common_1.HttpStatus.PRECONDITION_REQUIRED]: '428: Precondition required for request.',
|
|
49
|
+
[common_1.HttpStatus.TOO_MANY_REQUESTS]: '429: Too many requests from this client.',
|
|
50
|
+
[axios_1.HttpStatusCode.UnavailableForLegalReasons]: '451: Unavailable due to legal reasons.',
|
|
51
|
+
[common_1.HttpStatus.INTERNAL_SERVER_ERROR]: "500: Server faced an error and can't provide response.",
|
|
52
|
+
[common_1.HttpStatus.NOT_IMPLEMENTED]: "501: Server doesn't support functionality needed.",
|
|
53
|
+
[common_1.HttpStatus.BAD_GATEWAY]: '502: Server got invalid response from upstream server.',
|
|
54
|
+
[common_1.HttpStatus.SERVICE_UNAVAILABLE]: '503: Server not ready to handle request.',
|
|
55
|
+
[common_1.HttpStatus.GATEWAY_TIMEOUT]: "504: Server didn't get response from another server.",
|
|
56
|
+
[common_1.HttpStatus.HTTP_VERSION_NOT_SUPPORTED]: "505: Server doesn't support HTTP protocol version.",
|
|
57
|
+
};
|
|
58
|
+
const getHttpStatusDescription = (status, fallbackDescription = 'Unknown status code') => {
|
|
59
|
+
return httpStatusDescriptions[status] ?? fallbackDescription;
|
|
60
|
+
};
|
|
61
|
+
exports.getHttpStatusDescription = getHttpStatusDescription;
|
|
62
|
+
exports.httpExceptionStatusCodes = {
|
|
63
|
+
[common_1.BadRequestException.name]: common_1.HttpStatus.BAD_REQUEST,
|
|
64
|
+
[common_1.UnauthorizedException.name]: common_1.HttpStatus.UNAUTHORIZED,
|
|
65
|
+
[common_1.ForbiddenException.name]: common_1.HttpStatus.FORBIDDEN,
|
|
66
|
+
[common_1.NotFoundException.name]: common_1.HttpStatus.NOT_FOUND,
|
|
67
|
+
[common_1.MethodNotAllowedException.name]: common_1.HttpStatus.METHOD_NOT_ALLOWED,
|
|
68
|
+
[common_1.NotAcceptableException.name]: common_1.HttpStatus.NOT_ACCEPTABLE,
|
|
69
|
+
[common_1.RequestTimeoutException.name]: common_1.HttpStatus.REQUEST_TIMEOUT,
|
|
70
|
+
[common_1.ConflictException.name]: common_1.HttpStatus.CONFLICT,
|
|
71
|
+
[common_1.GoneException.name]: common_1.HttpStatus.GONE,
|
|
72
|
+
[common_1.PreconditionFailedException.name]: common_1.HttpStatus.PRECONDITION_FAILED,
|
|
73
|
+
[common_1.PayloadTooLargeException.name]: common_1.HttpStatus.PAYLOAD_TOO_LARGE,
|
|
74
|
+
[common_1.UnsupportedMediaTypeException.name]: common_1.HttpStatus.UNSUPPORTED_MEDIA_TYPE,
|
|
75
|
+
[common_1.UnprocessableEntityException.name]: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
|
|
76
|
+
[common_1.InternalServerErrorException.name]: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
77
|
+
[common_1.NotImplementedException.name]: common_1.HttpStatus.NOT_IMPLEMENTED,
|
|
78
|
+
[common_1.BadGatewayException.name]: common_1.HttpStatus.BAD_GATEWAY,
|
|
79
|
+
[common_1.ServiceUnavailableException.name]: common_1.HttpStatus.SERVICE_UNAVAILABLE,
|
|
80
|
+
[common_1.GatewayTimeoutException.name]: common_1.HttpStatus.GATEWAY_TIMEOUT,
|
|
81
|
+
[common_1.HttpException.name]: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
82
|
+
[common_1.MisdirectedException.name]: common_1.HttpStatus.MISDIRECTED,
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=http.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.helper.js","sourceRoot":"","sources":["http.helper.ts"],"names":[],"mappings":";;;AAAA,2CAsBwB;AACxB,iCAAuC;AAE1B,QAAA,eAAe,GAAwB;IAClD,GAAG,mBAAU;IACb,GAAG,sBAAc;CAClB,CAAC;AAKF,MAAM,sBAAsB,GAExB;IACF,CAAC,mBAAU,CAAC,QAAQ,CAAC,EAAE,sDAAsD;IAC7E,CAAC,mBAAU,CAAC,mBAAmB,CAAC,EAC9B,+CAA+C;IACjD,CAAC,mBAAU,CAAC,UAAU,CAAC,EAAE,kDAAkD;IAC3E,CAAC,mBAAU,CAAC,EAAE,CAAC,EAAE,gDAAgD;IACjE,CAAC,mBAAU,CAAC,OAAO,CAAC,EA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BAAoB,CAAC,IAAI,CAAC,EAAE,mBAAU,CAAC,WAAW;CACpD,CAAC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BadGatewayException,
|
|
3
|
+
BadRequestException,
|
|
4
|
+
ConflictException,
|
|
5
|
+
ForbiddenException,
|
|
6
|
+
GatewayTimeoutException,
|
|
7
|
+
GoneException,
|
|
8
|
+
HttpException,
|
|
9
|
+
HttpStatus,
|
|
10
|
+
InternalServerErrorException,
|
|
11
|
+
MethodNotAllowedException,
|
|
12
|
+
MisdirectedException,
|
|
13
|
+
NotAcceptableException,
|
|
14
|
+
NotFoundException,
|
|
15
|
+
NotImplementedException,
|
|
16
|
+
PayloadTooLargeException,
|
|
17
|
+
PreconditionFailedException,
|
|
18
|
+
RequestTimeoutException,
|
|
19
|
+
ServiceUnavailableException,
|
|
20
|
+
UnauthorizedException,
|
|
21
|
+
UnprocessableEntityException,
|
|
22
|
+
UnsupportedMediaTypeException,
|
|
23
|
+
} from '@nestjs/common';
|
|
24
|
+
import { HttpStatusCode } from 'axios';
|
|
25
|
+
|
|
26
|
+
export const HttpStatusCodes: Record<string, any> = {
|
|
27
|
+
...HttpStatus,
|
|
28
|
+
...HttpStatusCode,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type HttpStatusCodes =
|
|
32
|
+
(typeof HttpStatusCodes)[keyof typeof HttpStatusCodes];
|
|
33
|
+
|
|
34
|
+
const httpStatusDescriptions: {
|
|
35
|
+
[key in HttpStatusCodes]?: string;
|
|
36
|
+
} = {
|
|
37
|
+
[HttpStatus.CONTINUE]: '100: Request received, server awaiting further info.',
|
|
38
|
+
[HttpStatus.SWITCHING_PROTOCOLS]:
|
|
39
|
+
'101: Client asked server to switch protocols.',
|
|
40
|
+
[HttpStatus.PROCESSING]: '102: Server processing request, no response yet.',
|
|
41
|
+
[HttpStatus.OK]: '200: Request successful and response provided.',
|
|
42
|
+
[HttpStatus.CREATED]: '201: Request completed, and resource created.',
|
|
43
|
+
[HttpStatus.ACCEPTED]: '202: Request accepted but processing not complete.',
|
|
44
|
+
[HttpStatus.NON_AUTHORITATIVE_INFORMATION]:
|
|
45
|
+
'203: Info from another source returned.',
|
|
46
|
+
[HttpStatus.NO_CONTENT]: '204: Request succeeded with no content to send.',
|
|
47
|
+
[HttpStatus.RESET_CONTENT]: '205: Client should reset document view.',
|
|
48
|
+
[HttpStatus.PARTIAL_CONTENT]:
|
|
49
|
+
'206: Partial resource returned due to range header.',
|
|
50
|
+
// [HttpStatus.MULTI_STATUS]: '207: Multiple status responses for request.',
|
|
51
|
+
// [HttpStatus.ALREADY_REPORTED]:
|
|
52
|
+
// '208: Resource state already sent in earlier request.',
|
|
53
|
+
// [HttpStatus.IM_USED]: '226: Request fulfilled and resource modified.',
|
|
54
|
+
// [HttpStatus.MULTIPLE_CHOICES]: '300: Multiple options for the resource.',
|
|
55
|
+
[HttpStatus.MOVED_PERMANENTLY]: '301: Resource moved permanently.',
|
|
56
|
+
[HttpStatus.FOUND]: '302: Resource temporarily moved, use given URI.',
|
|
57
|
+
[HttpStatus.SEE_OTHER]: '303: Response found elsewhere, use GET for that.',
|
|
58
|
+
[HttpStatus.NOT_MODIFIED]: '304: Resource not modified since last request.',
|
|
59
|
+
// [HttpStatus.USE_PROXY]: '305: Must access resource via specified proxy.',
|
|
60
|
+
[HttpStatus.TEMPORARY_REDIRECT]:
|
|
61
|
+
'307: Resource temporarily moved, but use same method.',
|
|
62
|
+
[HttpStatus.PERMANENT_REDIRECT]:
|
|
63
|
+
'308: Resource moved permanently, use same method.',
|
|
64
|
+
[HttpStatus.BAD_REQUEST]:
|
|
65
|
+
"400: Server couldn't understand request due to invalid syntax.",
|
|
66
|
+
[HttpStatus.UNAUTHORIZED]: '401: Authentication needed for request.',
|
|
67
|
+
[HttpStatus.PAYMENT_REQUIRED]: '402: Payment required for this resource.',
|
|
68
|
+
[HttpStatus.FORBIDDEN]: '403: Server understood but refuses to authorize.',
|
|
69
|
+
[HttpStatus.NOT_FOUND]: "404: Server can't find the requested resource.",
|
|
70
|
+
[HttpStatus.METHOD_NOT_ALLOWED]: '405: HTTP method not allowed for resource.',
|
|
71
|
+
[HttpStatus.NOT_ACCEPTABLE]: "406: Resource doesn't match criteria.",
|
|
72
|
+
[HttpStatus.PROXY_AUTHENTICATION_REQUIRED]:
|
|
73
|
+
'407: Proxy authentication required.',
|
|
74
|
+
[HttpStatus.REQUEST_TIMEOUT]: '408: Server timed out waiting for request.',
|
|
75
|
+
[HttpStatus.CONFLICT]: '409: Request conflict with server state.',
|
|
76
|
+
[HttpStatus.GONE]: '410: Resource requested is no longer available.',
|
|
77
|
+
[HttpStatus.LENGTH_REQUIRED]: '411: Length of request not specified.',
|
|
78
|
+
[HttpStatus.PRECONDITION_FAILED]: '412: Precondition for request not met.',
|
|
79
|
+
[HttpStatus.PAYLOAD_TOO_LARGE]: '413: Request payload too large.',
|
|
80
|
+
[HttpStatus.URI_TOO_LONG]: '414: URI requested is too long.',
|
|
81
|
+
[HttpStatus.UNSUPPORTED_MEDIA_TYPE]: '415: Media type not supported.',
|
|
82
|
+
[HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE]:
|
|
83
|
+
'416: Range specified is invalid.',
|
|
84
|
+
[HttpStatus.EXPECTATION_FAILED]:
|
|
85
|
+
"417: Server can't meet request expectation.",
|
|
86
|
+
[HttpStatus.I_AM_A_TEAPOT]: "418: I'm a teapot (April Fools joke).",
|
|
87
|
+
// [HttpStatus.MISDIRECTED_REQUEST]:
|
|
88
|
+
// "421: Request misdirected, can't produce response.",
|
|
89
|
+
[HttpStatus.UNPROCESSABLE_ENTITY]:
|
|
90
|
+
'422: Request understandable, but semantically wrong.',
|
|
91
|
+
// [HttpStatus.LOCKED]: "423: Resource you're accessing is locked.",
|
|
92
|
+
[HttpStatus.FAILED_DEPENDENCY]:
|
|
93
|
+
"424: Request failed due to server's previous request.",
|
|
94
|
+
// [HttpStatus.TOO_EARLY]: '425: Request might be replayed.',
|
|
95
|
+
// [HttpStatus.UPGRADE_REQUIRED]:
|
|
96
|
+
// '426: Client should switch to another protocol.',
|
|
97
|
+
[HttpStatus.PRECONDITION_REQUIRED]: '428: Precondition required for request.',
|
|
98
|
+
[HttpStatus.TOO_MANY_REQUESTS]: '429: Too many requests from this client.',
|
|
99
|
+
// [HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE]: '431: Headers too long.',
|
|
100
|
+
[HttpStatusCode.UnavailableForLegalReasons]:
|
|
101
|
+
'451: Unavailable due to legal reasons.',
|
|
102
|
+
[HttpStatus.INTERNAL_SERVER_ERROR]:
|
|
103
|
+
"500: Server faced an error and can't provide response.",
|
|
104
|
+
[HttpStatus.NOT_IMPLEMENTED]:
|
|
105
|
+
"501: Server doesn't support functionality needed.",
|
|
106
|
+
[HttpStatus.BAD_GATEWAY]:
|
|
107
|
+
'502: Server got invalid response from upstream server.',
|
|
108
|
+
[HttpStatus.SERVICE_UNAVAILABLE]: '503: Server not ready to handle request.',
|
|
109
|
+
[HttpStatus.GATEWAY_TIMEOUT]:
|
|
110
|
+
"504: Server didn't get response from another server.",
|
|
111
|
+
[HttpStatus.HTTP_VERSION_NOT_SUPPORTED]:
|
|
112
|
+
"505: Server doesn't support HTTP protocol version.",
|
|
113
|
+
// [HttpStatus.VARIANT_ALSO_NEGOTIATES]:
|
|
114
|
+
// '506: Server has internal configuration error.',
|
|
115
|
+
// [HttpStatus.INSUFFICIENT_STORAGE]:
|
|
116
|
+
// "507: Server can't store the representation.",
|
|
117
|
+
// [HttpStatus.LOOP_DETECTED]:
|
|
118
|
+
// '508: Server detected an infinite loop while processing.',
|
|
119
|
+
// [HttpStatus.NOT_EXTENDED]: '510: Further extensions needed for request.',
|
|
120
|
+
// [HttpStatus.NETWORK_AUTHENTICATION_REQUIRED]:
|
|
121
|
+
// '511: Client needs to authenticate for network access.',
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const getHttpStatusDescription = (
|
|
125
|
+
status: HttpStatusCodes,
|
|
126
|
+
fallbackDescription = 'Unknown status code',
|
|
127
|
+
): string => {
|
|
128
|
+
return httpStatusDescriptions[status] ?? fallbackDescription;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const httpExceptionStatusCodes = {
|
|
132
|
+
[BadRequestException.name]: HttpStatus.BAD_REQUEST,
|
|
133
|
+
[UnauthorizedException.name]: HttpStatus.UNAUTHORIZED,
|
|
134
|
+
[ForbiddenException.name]: HttpStatus.FORBIDDEN,
|
|
135
|
+
[NotFoundException.name]: HttpStatus.NOT_FOUND,
|
|
136
|
+
[MethodNotAllowedException.name]: HttpStatus.METHOD_NOT_ALLOWED,
|
|
137
|
+
[NotAcceptableException.name]: HttpStatus.NOT_ACCEPTABLE,
|
|
138
|
+
[RequestTimeoutException.name]: HttpStatus.REQUEST_TIMEOUT,
|
|
139
|
+
[ConflictException.name]: HttpStatus.CONFLICT,
|
|
140
|
+
[GoneException.name]: HttpStatus.GONE,
|
|
141
|
+
[PreconditionFailedException.name]: HttpStatus.PRECONDITION_FAILED,
|
|
142
|
+
[PayloadTooLargeException.name]: HttpStatus.PAYLOAD_TOO_LARGE,
|
|
143
|
+
[UnsupportedMediaTypeException.name]: HttpStatus.UNSUPPORTED_MEDIA_TYPE,
|
|
144
|
+
[UnprocessableEntityException.name]: HttpStatus.UNPROCESSABLE_ENTITY,
|
|
145
|
+
[InternalServerErrorException.name]: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
146
|
+
[NotImplementedException.name]: HttpStatus.NOT_IMPLEMENTED,
|
|
147
|
+
[BadGatewayException.name]: HttpStatus.BAD_GATEWAY,
|
|
148
|
+
[ServiceUnavailableException.name]: HttpStatus.SERVICE_UNAVAILABLE,
|
|
149
|
+
[GatewayTimeoutException.name]: HttpStatus.GATEWAY_TIMEOUT,
|
|
150
|
+
[HttpException.name]: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
151
|
+
[MisdirectedException.name]: HttpStatus.MISDIRECTED,
|
|
152
|
+
};
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from './class.helper.js';
|
|
2
|
+
export * from './custom-validator.js';
|
|
3
|
+
export * from './data-structure.helper.js';
|
|
4
|
+
export * from './date.helper.js';
|
|
5
|
+
export * from './encryption.helper.js';
|
|
6
|
+
export * from './enum.helper.js';
|
|
7
|
+
export * from './env.helper.js';
|
|
8
|
+
export * from './error.helper.js';
|
|
9
|
+
export * from './interval.helper.js';
|
|
10
|
+
export * from './nestjs/nest.decorator.js';
|
|
11
|
+
export * from './object.helper.js';
|
|
12
|
+
export * from './object-mapper.helper.js';
|
|
13
|
+
export * from './object-mapper.interceptor.js';
|
|
14
|
+
export * from './returnValue.js';
|
|
15
|
+
export * from './validator-helper.js';
|
|
16
|
+
export * from './zlib.helper.js';
|
|
17
|
+
export * from './command.helper.js';
|
|
18
|
+
export * from './files.helper.js';
|
|
19
|
+
export * from './rxjs.helper.js';
|
|
20
|
+
export * from './math.helper.js';
|
|
21
|
+
export * from './config-manager.helper.js';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./class.helper.js"), exports);
|
|
18
|
+
__exportStar(require("./custom-validator.js"), exports);
|
|
19
|
+
__exportStar(require("./data-structure.helper.js"), exports);
|
|
20
|
+
__exportStar(require("./date.helper.js"), exports);
|
|
21
|
+
__exportStar(require("./encryption.helper.js"), exports);
|
|
22
|
+
__exportStar(require("./enum.helper.js"), exports);
|
|
23
|
+
__exportStar(require("./env.helper.js"), exports);
|
|
24
|
+
__exportStar(require("./error.helper.js"), exports);
|
|
25
|
+
__exportStar(require("./interval.helper.js"), exports);
|
|
26
|
+
__exportStar(require("./nestjs/nest.decorator.js"), exports);
|
|
27
|
+
__exportStar(require("./object.helper.js"), exports);
|
|
28
|
+
__exportStar(require("./object-mapper.helper.js"), exports);
|
|
29
|
+
__exportStar(require("./object-mapper.interceptor.js"), exports);
|
|
30
|
+
__exportStar(require("./returnValue.js"), exports);
|
|
31
|
+
__exportStar(require("./validator-helper.js"), exports);
|
|
32
|
+
__exportStar(require("./zlib.helper.js"), exports);
|
|
33
|
+
__exportStar(require("./command.helper.js"), exports);
|
|
34
|
+
__exportStar(require("./files.helper.js"), exports);
|
|
35
|
+
__exportStar(require("./rxjs.helper.js"), exports);
|
|
36
|
+
__exportStar(require("./math.helper.js"), exports);
|
|
37
|
+
__exportStar(require("./config-manager.helper.js"), exports);
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,wDAAsC;AACtC,6DAA2C;AAC3C,mDAAiC;AACjC,yDAAuC;AACvC,mDAAiC;AACjC,kDAAgC;AAChC,oDAAkC;AAElC,uDAAqC;AACrC,6DAA2C;AAC3C,qDAAmC;AACnC,4DAA0C;AAC1C,iEAA+C;AAE/C,mDAAiC;AACjC,wDAAsC;AACtC,mDAAiC;AACjC,sDAAoC;AACpC,oDAAkC;AAClC,mDAAiC;AACjC,mDAAiC;AACjC,6DAA2C"}
|