@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,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commandWithErrors = void 0;
|
|
4
|
+
const commandWithErrors = (command) => {
|
|
5
|
+
return async (...args) => {
|
|
6
|
+
try {
|
|
7
|
+
await command(...args);
|
|
8
|
+
}
|
|
9
|
+
catch (e) {
|
|
10
|
+
console.error(e);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.commandWithErrors = commandWithErrors;
|
|
16
|
+
//# sourceMappingURL=command.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.helper.js","sourceRoot":"","sources":["command.helper.ts"],"names":[],"mappings":";;;AAMO,MAAM,iBAAiB,GAAG,CAC/B,OAAyC,EACzC,EAAE;IACF,OAAO,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;QAC9B,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YAEX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,iBAAiB,qBAY5B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* It captures errors from the command line and exits the process
|
|
3
|
+
*
|
|
4
|
+
* @param command
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export const commandWithErrors = (
|
|
8
|
+
command: (...args: any[]) => Promise<any>,
|
|
9
|
+
) => {
|
|
10
|
+
return async (...args: any[]) => {
|
|
11
|
+
try {
|
|
12
|
+
await command(...args);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
// eslint-disable-next-line no-console
|
|
15
|
+
console.error(e);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReturnOrFunctionReturnType } from '@nest-yalc-2/types/globals.d.js';
|
|
2
|
+
export type ConfigTuple<K, T> = {
|
|
3
|
+
k: K | K[];
|
|
4
|
+
v: T;
|
|
5
|
+
};
|
|
6
|
+
export declare function checkForDuplicateKeys<K>(keys: K[]): void;
|
|
7
|
+
export declare class ConfigValueManager {
|
|
8
|
+
static value: <K, T, TDefault = undefined>(currentKey: K, configurations: ConfigTuple<K, T> | ConfigTuple<K, T>[], defaultValue?: TDefault) => ReturnOrFunctionReturnType<T> | ReturnOrFunctionReturnType<TDefault>;
|
|
9
|
+
static is: <K>(currentKey: K, keys: K[] | K, isNegative?: boolean) => boolean;
|
|
10
|
+
static only: <K, T>(currentKey: K, keys: K[] | K, value: T) => ReturnOrFunctionReturnType<T> | undefined;
|
|
11
|
+
static skip: <K, T>(currentKey: K, keys: K[] | K, value: T) => ReturnOrFunctionReturnType<T> | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigValueManager = void 0;
|
|
4
|
+
exports.checkForDuplicateKeys = checkForDuplicateKeys;
|
|
5
|
+
function checkForDuplicateKeys(keys) {
|
|
6
|
+
const keySet = new Set();
|
|
7
|
+
for (const key of keys) {
|
|
8
|
+
if (keySet.has(key)) {
|
|
9
|
+
throw new Error(`Duplicate key found in configuration: ${key}`);
|
|
10
|
+
}
|
|
11
|
+
keySet.add(key);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const normalizeKeys = (keyOrKeys) => Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];
|
|
15
|
+
class ConfigValueManager {
|
|
16
|
+
static { this.value = (currentKey, configurations, defaultValue) => {
|
|
17
|
+
const foundKeys = new Set();
|
|
18
|
+
const normalizeReturnValue = (returnValue) => {
|
|
19
|
+
if (typeof returnValue === 'function') {
|
|
20
|
+
return returnValue();
|
|
21
|
+
}
|
|
22
|
+
return returnValue;
|
|
23
|
+
};
|
|
24
|
+
const _configurations = Array.isArray(configurations)
|
|
25
|
+
? configurations
|
|
26
|
+
: [configurations];
|
|
27
|
+
const allKeys = _configurations
|
|
28
|
+
.map((tuple) => normalizeKeys(tuple.k))
|
|
29
|
+
.flat();
|
|
30
|
+
checkForDuplicateKeys(allKeys);
|
|
31
|
+
for (const { k: keys, v: value } of _configurations) {
|
|
32
|
+
const normalizedKeys = normalizeKeys(keys);
|
|
33
|
+
normalizedKeys.forEach((key) => foundKeys.add(key));
|
|
34
|
+
if (normalizedKeys.includes(currentKey)) {
|
|
35
|
+
return normalizeReturnValue(value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return normalizeReturnValue(defaultValue);
|
|
39
|
+
}; }
|
|
40
|
+
static { this.is = (currentKey, keys, isNegative = false) => {
|
|
41
|
+
const _tuple = {
|
|
42
|
+
k: normalizeKeys(keys),
|
|
43
|
+
v: !isNegative,
|
|
44
|
+
};
|
|
45
|
+
return this.value(currentKey, _tuple, isNegative);
|
|
46
|
+
}; }
|
|
47
|
+
static { this.only = (currentKey, keys, value) => {
|
|
48
|
+
const _tuple = { k: normalizeKeys(keys), v: value };
|
|
49
|
+
return this.value(currentKey, _tuple, undefined);
|
|
50
|
+
}; }
|
|
51
|
+
static { this.skip = (currentKey, keys, value) => {
|
|
52
|
+
const _tuple = {
|
|
53
|
+
k: normalizeKeys(keys),
|
|
54
|
+
v: undefined,
|
|
55
|
+
};
|
|
56
|
+
return this.value(currentKey, _tuple, value);
|
|
57
|
+
}; }
|
|
58
|
+
}
|
|
59
|
+
exports.ConfigValueManager = ConfigValueManager;
|
|
60
|
+
//# sourceMappingURL=config-manager.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-manager.helper.js","sourceRoot":"","sources":["config-manager.helper.ts"],"names":[],"mappings":";;;AAKA,sDAQC;AARD,SAAgB,qBAAqB,CAAI,IAAS;IAChD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAK,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,yCAAyC,GAAG,EAAE,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,MAAM,aAAa,GAAG,CAAI,SAAkB,EAAO,EAAE,CACnD,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAErD,MAAa,kBAAkB;aAWtB,UAAK,GAAG,CACb,UAAa,EACb,cAAuD,EACvD,YAAuB,EAC+C,EAAE;QACxE,MAAM,SAAS,GAAG,IAAI,GAAG,EAAK,CAAC;QAE/B,MAAM,oBAAoB,GAAG,CAC3B,WAAyB,EAC6C,EAAE;YACxE,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;gBAEtC,OAAQ,WAAwB,EAAE,CAAC;YACrC,CAAC;YAED,OAAO,WAEiC,CAAC;QAC3C,CAAC,CAAC;QAKF,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC;YACnD,CAAC,CAAC,cAAc;YAChB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;QAErB,MAAM,OAAO,GAAG,eAAe;aAC5B,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACtC,IAAI,EAAE,CAAC;QACV,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAE/B,KAAK,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,eAAe,EAAE,CAAC;YACpD,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;YAE3C,cAAc,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAEpD,IAAI,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBACxC,OAAO,oBAAoB,CAAC,KAAK,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;QAED,OAAO,oBAAoB,CAAC,YAAwB,CAAC,CAAC;IACxD,CAAC,CAAC;aAOK,OAAE,GAAG,CAAI,UAAa,EAAE,IAAa,EAAE,UAAU,GAAG,KAAK,EAAE,EAAE;QAClE,MAAM,MAAM,GAA4B;YACtC,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC;YACtB,CAAC,EAAE,CAAC,UAAU;SACf,CAAC;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC;aAOK,SAAI,GAAG,CACZ,UAAa,EACb,IAAa,EACb,KAAQ,EACmC,EAAE;QAC7C,MAAM,MAAM,GAAsB,EAAE,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;QACvE,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACnD,CAAC,CAAC;aAOK,SAAI,GAAG,CACZ,UAAa,EACb,IAAa,EACb,KAAQ,EACmC,EAAE;QAC7C,MAAM,MAAM,GAA8B;YACxC,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC;YACtB,CAAC,EAAE,SAAS;SACb,CAAC;QACF,OAAO,IAAI,CAAC,KAAK,CACf,UAAU,EACV,MAAM,EACN,KAAK,CAC2B,CAAC;IACrC,CAAC,CAAC;;AAtGJ,gDAuGC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ReturnOrFunctionReturnType } from '@nest-yalc-2/types/globals.d.js';
|
|
2
|
+
|
|
3
|
+
export type ConfigTuple<K, T> = { k: K | K[]; v: T };
|
|
4
|
+
|
|
5
|
+
// Error message enhancement
|
|
6
|
+
export function checkForDuplicateKeys<K>(keys: K[]): void {
|
|
7
|
+
const keySet = new Set<K>();
|
|
8
|
+
for (const key of keys) {
|
|
9
|
+
if (keySet.has(key)) {
|
|
10
|
+
throw new Error(`Duplicate key found in configuration: ${key}`);
|
|
11
|
+
}
|
|
12
|
+
keySet.add(key);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const normalizeKeys = <K>(keyOrKeys: K | K[]): K[] =>
|
|
17
|
+
Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];
|
|
18
|
+
|
|
19
|
+
export class ConfigValueManager {
|
|
20
|
+
/**
|
|
21
|
+
* Examples:
|
|
22
|
+
*
|
|
23
|
+
value(['myKey', true], false); // boolean example
|
|
24
|
+
value(['myKey', 'myValue']); // string with default undefined
|
|
25
|
+
value(['myKey', undefined], 'myDefaultValue'); // undefined with default string
|
|
26
|
+
|
|
27
|
+
value(['myKey', 'myValue'], 'myDefaultValue'); // string example
|
|
28
|
+
value(['myKey', (): string => 'myValue'], () => 'myDefaultValue'); // string example as function
|
|
29
|
+
*/
|
|
30
|
+
static value = <K, T, TDefault = undefined>(
|
|
31
|
+
currentKey: K,
|
|
32
|
+
configurations: ConfigTuple<K, T> | ConfigTuple<K, T>[],
|
|
33
|
+
defaultValue?: TDefault,
|
|
34
|
+
): ReturnOrFunctionReturnType<T> | ReturnOrFunctionReturnType<TDefault> => {
|
|
35
|
+
const foundKeys = new Set<K>();
|
|
36
|
+
|
|
37
|
+
const normalizeReturnValue = (
|
|
38
|
+
returnValue: T | TDefault,
|
|
39
|
+
): ReturnOrFunctionReturnType<T> | ReturnOrFunctionReturnType<TDefault> => {
|
|
40
|
+
if (typeof returnValue === 'function') {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
42
|
+
return (returnValue as Function)(); // needed for dealing with dynamic types
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return returnValue as
|
|
46
|
+
| ReturnOrFunctionReturnType<T>
|
|
47
|
+
| ReturnOrFunctionReturnType<TDefault>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Check if it's a ConfigTuple or an array of ConfigTuples
|
|
52
|
+
*/
|
|
53
|
+
const _configurations = Array.isArray(configurations)
|
|
54
|
+
? configurations
|
|
55
|
+
: [configurations];
|
|
56
|
+
|
|
57
|
+
const allKeys = _configurations
|
|
58
|
+
.map((tuple) => normalizeKeys(tuple.k))
|
|
59
|
+
.flat();
|
|
60
|
+
checkForDuplicateKeys(allKeys);
|
|
61
|
+
|
|
62
|
+
for (const { k: keys, v: value } of _configurations) {
|
|
63
|
+
const normalizedKeys = normalizeKeys(keys);
|
|
64
|
+
|
|
65
|
+
normalizedKeys.forEach((key) => foundKeys.add(key));
|
|
66
|
+
|
|
67
|
+
if (normalizedKeys.includes(currentKey)) {
|
|
68
|
+
return normalizeReturnValue(value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return normalizeReturnValue(defaultValue as TDefault);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Examples:
|
|
77
|
+
*
|
|
78
|
+
* Key.is('myKey'); // true for 'myKey', and false for other keys
|
|
79
|
+
*/
|
|
80
|
+
static is = <K>(currentKey: K, keys: K[] | K, isNegative = false) => {
|
|
81
|
+
const _tuple: ConfigTuple<K, boolean> = {
|
|
82
|
+
k: normalizeKeys(keys),
|
|
83
|
+
v: !isNegative,
|
|
84
|
+
};
|
|
85
|
+
return this.value(currentKey, _tuple, isNegative);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Examples:
|
|
90
|
+
*
|
|
91
|
+
* Key.only('myKey', 'myValue'); // this will return 'myValue' for 'myKey', and undefined for other keys
|
|
92
|
+
*/
|
|
93
|
+
static only = <K, T>(
|
|
94
|
+
currentKey: K,
|
|
95
|
+
keys: K[] | K,
|
|
96
|
+
value: T,
|
|
97
|
+
): ReturnOrFunctionReturnType<T> | undefined => {
|
|
98
|
+
const _tuple: ConfigTuple<K, T> = { k: normalizeKeys(keys), v: value };
|
|
99
|
+
return this.value(currentKey, _tuple, undefined);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Examples:
|
|
104
|
+
*
|
|
105
|
+
* Key.skip('myKey', 'myValue'); // this will return undefined for 'myKey', and 'myValue' for other keys
|
|
106
|
+
*/
|
|
107
|
+
static skip = <K, T>(
|
|
108
|
+
currentKey: K,
|
|
109
|
+
keys: K[] | K,
|
|
110
|
+
value: T,
|
|
111
|
+
): ReturnOrFunctionReturnType<T> | undefined => {
|
|
112
|
+
const _tuple: ConfigTuple<K, undefined> = {
|
|
113
|
+
k: normalizeKeys(keys),
|
|
114
|
+
v: undefined,
|
|
115
|
+
};
|
|
116
|
+
return this.value(
|
|
117
|
+
currentKey,
|
|
118
|
+
_tuple,
|
|
119
|
+
value,
|
|
120
|
+
) as ReturnOrFunctionReturnType<T>;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringIsInEnumValidatorFactory = void 0;
|
|
4
|
+
const validator_helper_js_1 = require("./validator-helper.js");
|
|
5
|
+
const stringIsInEnumValidatorFactory = (property) => {
|
|
6
|
+
return {
|
|
7
|
+
validate(value) {
|
|
8
|
+
return (0, validator_helper_js_1.stringIsInEnum)(value, property);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
exports.stringIsInEnumValidatorFactory = stringIsInEnumValidatorFactory;
|
|
13
|
+
//# sourceMappingURL=custom-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-validator.js","sourceRoot":"","sources":["custom-validator.ts"],"names":[],"mappings":";;;AAAA,+DAAuD;AAEhD,MAAM,8BAA8B,GAAG,CAG5C,QAAW,EACX,EAAE;IACF,OAAO;QACL,QAAQ,CAAC,KAAU;YACjB,OAAO,IAAA,oCAAc,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACzC,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,8BAA8B,kCAUzC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { stringIsInEnum } from './validator-helper.js';
|
|
2
|
+
|
|
3
|
+
export const stringIsInEnumValidatorFactory = <
|
|
4
|
+
T extends Record<string, string | number>,
|
|
5
|
+
>(
|
|
6
|
+
property: T,
|
|
7
|
+
) => {
|
|
8
|
+
return {
|
|
9
|
+
validate(value: any) {
|
|
10
|
+
return stringIsInEnum(value, property);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const arrayGroupByField: <T, K extends string | number | symbol>(entityArray: T[], getKey: (item: T) => K) => Record<K, T[]>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.arrayGroupByField = void 0;
|
|
4
|
+
const arrayGroupByField = (entityArray, getKey) => {
|
|
5
|
+
return entityArray.reduce((acc, current) => {
|
|
6
|
+
const property = getKey(current);
|
|
7
|
+
acc[property] ??= [];
|
|
8
|
+
acc[property].push(current);
|
|
9
|
+
return acc;
|
|
10
|
+
}, {});
|
|
11
|
+
};
|
|
12
|
+
exports.arrayGroupByField = arrayGroupByField;
|
|
13
|
+
//# sourceMappingURL=data-structure.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-structure.helper.js","sourceRoot":"","sources":["data-structure.helper.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,CAC/B,WAAgB,EAChB,MAAsB,EACN,EAAE;IAClB,OAAO,WAAW,CAAC,MAAM,CACvB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QACf,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QACjC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACrB,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAoB,CACrB,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,iBAAiB,qBAa5B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const arrayGroupByField = <T, K extends string | number | symbol>(
|
|
2
|
+
entityArray: T[],
|
|
3
|
+
getKey: (item: T) => K,
|
|
4
|
+
): Record<K, T[]> => {
|
|
5
|
+
return entityArray.reduce(
|
|
6
|
+
(acc, current) => {
|
|
7
|
+
const property = getKey(current);
|
|
8
|
+
acc[property] ??= [];
|
|
9
|
+
acc[property].push(current);
|
|
10
|
+
return acc;
|
|
11
|
+
},
|
|
12
|
+
{} as Record<K, T[]>,
|
|
13
|
+
);
|
|
14
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class DateHelper {
|
|
2
|
+
static getWeekEdgeDates(): {
|
|
3
|
+
startDate: string;
|
|
4
|
+
endDate: string;
|
|
5
|
+
};
|
|
6
|
+
static formatMonth(month: number): string;
|
|
7
|
+
static formatDay(day: number): string;
|
|
8
|
+
static subsMinutes(date: Date, minutes: number): Date;
|
|
9
|
+
static addMinutes(date: Date, minutes: number): Date;
|
|
10
|
+
static dateToSQLDateTime(date: Date): string;
|
|
11
|
+
static dateToPlainISO(date: Date): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateHelper = void 0;
|
|
4
|
+
class DateHelper {
|
|
5
|
+
static getWeekEdgeDates() {
|
|
6
|
+
const currentDate = Date.now();
|
|
7
|
+
const weekInMs = 1000 * 60 * 60 * 24 * 7;
|
|
8
|
+
const startDate = new Date(new Date(currentDate).getTime() - weekInMs);
|
|
9
|
+
const endDate = new Date(currentDate);
|
|
10
|
+
const startDateMonth = DateHelper.formatMonth(startDate.getMonth());
|
|
11
|
+
const startDateDay = DateHelper.formatDay(startDate.getDate());
|
|
12
|
+
const endDateMonth = DateHelper.formatMonth(endDate.getMonth());
|
|
13
|
+
const endDateDay = DateHelper.formatDay(endDate.getDate());
|
|
14
|
+
const queryStartDate = `${startDate.getFullYear()}-${startDateMonth}-${startDateDay}`;
|
|
15
|
+
const queryEndDate = `${endDate.getFullYear()}-${endDateMonth}-${endDateDay}`;
|
|
16
|
+
return { startDate: queryStartDate, endDate: queryEndDate };
|
|
17
|
+
}
|
|
18
|
+
static formatMonth(month) {
|
|
19
|
+
const fixedMonth = month + 1;
|
|
20
|
+
return fixedMonth < 10 ? `0${fixedMonth}` : `${fixedMonth}`;
|
|
21
|
+
}
|
|
22
|
+
static formatDay(day) {
|
|
23
|
+
return day < 10 ? `0${day}` : `${day}`;
|
|
24
|
+
}
|
|
25
|
+
static subsMinutes(date, minutes) {
|
|
26
|
+
const result = new Date(date.getTime());
|
|
27
|
+
result.setMinutes(result.getMinutes() - minutes);
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
static addMinutes(date, minutes) {
|
|
31
|
+
const result = new Date(date.getTime());
|
|
32
|
+
result.setMinutes(result.getMinutes() + minutes);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
static dateToSQLDateTime(date) {
|
|
36
|
+
return date.toISOString().slice(0, 19).replace('T', ' ');
|
|
37
|
+
}
|
|
38
|
+
static dateToPlainISO(date) {
|
|
39
|
+
return date
|
|
40
|
+
.toISOString()
|
|
41
|
+
.replace(/:/g, '')
|
|
42
|
+
.replace(/-/g, '')
|
|
43
|
+
.replace(/\./g, '');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.DateHelper = DateHelper;
|
|
47
|
+
//# sourceMappingURL=date.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.helper.js","sourceRoot":"","sources":["date.helper.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAU;IAKrB,MAAM,CAAC,gBAAgB;QACrB,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAEzC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC;QACvE,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;QAEtC,MAAM,cAAc,GAAG,UAAU,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEpE,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;QAE/D,MAAM,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEhE,MAAM,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAE3D,MAAM,cAAc,GAAG,GAAG,SAAS,CAAC,WAAW,EAAE,IAAI,cAAc,IAAI,YAAY,EAAE,CAAC;QAEtF,MAAM,YAAY,GAAG,GAAG,OAAO,CAAC,WAAW,EAAE,IAAI,YAAY,IAAI,UAAU,EAAE,CAAC;QAE9E,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IAC9D,CAAC;IAOD,MAAM,CAAC,WAAW,CAAC,KAAa;QAC9B,MAAM,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC;QAC7B,OAAO,UAAU,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC,CAAC,GAAG,UAAU,EAAE,CAAC;IAC9D,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,GAAW;QAC1B,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAAU,EAAE,OAAe;QAC5C,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACxC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,OAAO,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,IAAU,EAAE,OAAe;QAC3C,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACxC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,OAAO,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,IAAU;QACjC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,IAAU;QAC9B,OAAO,IAAI;aACR,WAAW,EAAE;aACb,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;aACjB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;aACjB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACxB,CAAC;CACF;AAhED,gCAgEC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export class DateHelper {
|
|
2
|
+
/**
|
|
3
|
+
* Function that returns interface of startDate being current date and endDate being 1 week earlier
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
static getWeekEdgeDates(): { startDate: string; endDate: string } {
|
|
7
|
+
const currentDate = Date.now();
|
|
8
|
+
const weekInMs = 1000 * 60 * 60 * 24 * 7;
|
|
9
|
+
|
|
10
|
+
const startDate = new Date(new Date(currentDate).getTime() - weekInMs);
|
|
11
|
+
const endDate = new Date(currentDate);
|
|
12
|
+
|
|
13
|
+
const startDateMonth = DateHelper.formatMonth(startDate.getMonth());
|
|
14
|
+
|
|
15
|
+
const startDateDay = DateHelper.formatDay(startDate.getDate());
|
|
16
|
+
|
|
17
|
+
const endDateMonth = DateHelper.formatMonth(endDate.getMonth());
|
|
18
|
+
|
|
19
|
+
const endDateDay = DateHelper.formatDay(endDate.getDate());
|
|
20
|
+
|
|
21
|
+
const queryStartDate = `${startDate.getFullYear()}-${startDateMonth}-${startDateDay}`;
|
|
22
|
+
|
|
23
|
+
const queryEndDate = `${endDate.getFullYear()}-${endDateMonth}-${endDateDay}`;
|
|
24
|
+
|
|
25
|
+
return { startDate: queryStartDate, endDate: queryEndDate };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param num number of day or month
|
|
31
|
+
* @returns formatted number, like 3rd month (number 3 passed) returns string '03'
|
|
32
|
+
*/
|
|
33
|
+
static formatMonth(month: number): string {
|
|
34
|
+
const fixedMonth = month + 1;
|
|
35
|
+
return fixedMonth < 10 ? `0${fixedMonth}` : `${fixedMonth}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static formatDay(day: number): string {
|
|
39
|
+
return day < 10 ? `0${day}` : `${day}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static subsMinutes(date: Date, minutes: number): Date {
|
|
43
|
+
const result = new Date(date.getTime());
|
|
44
|
+
result.setMinutes(result.getMinutes() - minutes);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static addMinutes(date: Date, minutes: number): Date {
|
|
49
|
+
const result = new Date(date.getTime());
|
|
50
|
+
result.setMinutes(result.getMinutes() + minutes);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static dateToSQLDateTime(date: Date) {
|
|
55
|
+
return date.toISOString().slice(0, 19).replace('T', ' ');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static dateToPlainISO(date: Date) {
|
|
59
|
+
return date
|
|
60
|
+
.toISOString()
|
|
61
|
+
.replace(/:/g, '')
|
|
62
|
+
.replace(/-/g, '')
|
|
63
|
+
.replace(/\./g, '');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.decryptAes = exports.encryptAes = void 0;
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
38
|
+
const encryptAes = (toEncrypt, key) => {
|
|
39
|
+
const iv = crypto.randomBytes(16);
|
|
40
|
+
const cipher = crypto.createCipheriv('aes-256-ctr', Buffer.from(key, 'hex'), iv);
|
|
41
|
+
let encrypted = cipher.update(toEncrypt, 'utf8', 'hex');
|
|
42
|
+
encrypted += cipher.final('hex');
|
|
43
|
+
return iv.toString('hex') + ':' + encrypted;
|
|
44
|
+
};
|
|
45
|
+
exports.encryptAes = encryptAes;
|
|
46
|
+
const decryptAes = (toDecrypt, key) => {
|
|
47
|
+
if (toDecrypt === '') {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
const split = toDecrypt.split(':');
|
|
51
|
+
const iv = split[0];
|
|
52
|
+
const decipher = crypto.createDecipheriv('aes-256-ctr', Buffer.from(key, 'hex'), Buffer.from(iv, 'hex'));
|
|
53
|
+
let decrypted = decipher.update(split[1], 'hex', 'utf8');
|
|
54
|
+
decrypted += decipher.final('utf8');
|
|
55
|
+
return decrypted;
|
|
56
|
+
};
|
|
57
|
+
exports.decryptAes = decryptAes;
|
|
58
|
+
//# sourceMappingURL=encryption.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.helper.js","sourceRoot":"","sources":["encryption.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAE1B,MAAM,UAAU,GAAG,CAAC,SAAiB,EAAE,GAAW,EAAE,EAAE;IAC3D,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAClC,aAAa,EACb,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,EACvB,EAAE,CACH,CAAC;IACF,IAAI,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACxD,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,SAAS,CAAC;AAC9C,CAAC,CAAC;AAVW,QAAA,UAAU,cAUrB;AAEK,MAAM,UAAU,GAAG,CAAC,SAAiB,EAAE,GAAW,EAAE,EAAE;IAC3D,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CACtC,aAAa,EACb,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,EACvB,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CACvB,CAAC;IACF,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACzD,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAdW,QAAA,UAAU,cAcrB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
export const encryptAes = (toEncrypt: string, key: string) => {
|
|
4
|
+
const iv = crypto.randomBytes(16);
|
|
5
|
+
const cipher = crypto.createCipheriv(
|
|
6
|
+
'aes-256-ctr',
|
|
7
|
+
Buffer.from(key, 'hex'),
|
|
8
|
+
iv,
|
|
9
|
+
);
|
|
10
|
+
let encrypted = cipher.update(toEncrypt, 'utf8', 'hex');
|
|
11
|
+
encrypted += cipher.final('hex');
|
|
12
|
+
return iv.toString('hex') + ':' + encrypted;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const decryptAes = (toDecrypt: string, key: string) => {
|
|
16
|
+
if (toDecrypt === '') {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
const split = toDecrypt.split(':');
|
|
20
|
+
const iv = split[0];
|
|
21
|
+
const decipher = crypto.createDecipheriv(
|
|
22
|
+
'aes-256-ctr',
|
|
23
|
+
Buffer.from(key, 'hex'),
|
|
24
|
+
Buffer.from(iv, 'hex'),
|
|
25
|
+
);
|
|
26
|
+
let decrypted = decipher.update(split[1], 'hex', 'utf8');
|
|
27
|
+
decrypted += decipher.final('utf8');
|
|
28
|
+
return decrypted;
|
|
29
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Spread } from '@nest-yalc-2/types/globals.d.js';
|
|
2
|
+
export declare const belongsToEnum: <T extends Record<string, string | number>>(enumObj: T, value: string | number) => boolean;
|
|
3
|
+
type Merge<T extends readonly any[]> = T extends readonly [infer H, ...infer R] ? Spread<H, Merge<R>> : {};
|
|
4
|
+
export declare const mergeEnums: <T extends any[]>(...enums: T) => Merge<T>;
|
|
5
|
+
export declare const getEnumValueByEnumKey: <T extends {
|
|
6
|
+
[index: string]: string;
|
|
7
|
+
}>(myEnum: T, enumKey: string | undefined) => any | null;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnumValueByEnumKey = exports.mergeEnums = exports.belongsToEnum = void 0;
|
|
4
|
+
const belongsToEnum = (enumObj, value) => {
|
|
5
|
+
return Object.values(enumObj).includes(value);
|
|
6
|
+
};
|
|
7
|
+
exports.belongsToEnum = belongsToEnum;
|
|
8
|
+
const mergeEnums = (...enums) => {
|
|
9
|
+
let merged = {};
|
|
10
|
+
enums.forEach((e) => (merged = { ...merged, ...e }));
|
|
11
|
+
return merged;
|
|
12
|
+
};
|
|
13
|
+
exports.mergeEnums = mergeEnums;
|
|
14
|
+
const getEnumValueByEnumKey = (myEnum, enumKey) => {
|
|
15
|
+
if (!enumKey)
|
|
16
|
+
return undefined;
|
|
17
|
+
const idx = Object.keys(myEnum).find((x) => x === enumKey);
|
|
18
|
+
return idx ? myEnum[idx] : undefined;
|
|
19
|
+
};
|
|
20
|
+
exports.getEnumValueByEnumKey = getEnumValueByEnumKey;
|
|
21
|
+
//# sourceMappingURL=enum.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.helper.js","sourceRoot":"","sources":["enum.helper.ts"],"names":[],"mappings":";;;AAQO,MAAM,aAAa,GAAG,CAC3B,OAAU,EACV,KAAsB,EACb,EAAE;IACX,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC,CAAC;AALW,QAAA,aAAa,iBAKxB;AAOK,MAAM,UAAU,GAAG,CAAkB,GAAG,KAAQ,EAAE,EAAE;IACzD,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,OAAO,MAAyB,CAAC;AACnC,CAAC,CAAC;AAJW,QAAA,UAAU,cAIrB;AAEK,MAAM,qBAAqB,GAAG,CACnC,MAAS,EACT,OAA2B,EACf,EAAE;IACd,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC;IAC3D,OAAO,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACvC,CAAC,CAAC;AAPW,QAAA,qBAAqB,yBAOhC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Spread } from '@nest-yalc-2/types/globals.d.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Used to check if a value is contained in a enum object
|
|
5
|
+
* @param enumObj
|
|
6
|
+
* @param value
|
|
7
|
+
* @returns `boolean`
|
|
8
|
+
*/
|
|
9
|
+
export const belongsToEnum = <T extends Record<string, string | number>>(
|
|
10
|
+
enumObj: T,
|
|
11
|
+
value: string | number,
|
|
12
|
+
): boolean => {
|
|
13
|
+
return Object.values(enumObj).includes(value);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type Merge<T extends readonly any[]> = T extends readonly [infer H, ...infer R]
|
|
17
|
+
? Spread<H, Merge<R>>
|
|
18
|
+
: // eslint-disable-next-line @typescript-eslint/ban-types
|
|
19
|
+
{};
|
|
20
|
+
|
|
21
|
+
export const mergeEnums = <T extends any[]>(...enums: T) => {
|
|
22
|
+
let merged = {};
|
|
23
|
+
enums.forEach((e) => (merged = { ...merged, ...e }));
|
|
24
|
+
return merged as any as Merge<T>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getEnumValueByEnumKey = <T extends { [index: string]: string }>(
|
|
28
|
+
myEnum: T,
|
|
29
|
+
enumKey: string | undefined,
|
|
30
|
+
): any | null => {
|
|
31
|
+
if (!enumKey) return undefined;
|
|
32
|
+
const idx = Object.keys(myEnum).find((x) => x === enumKey);
|
|
33
|
+
return idx ? myEnum[idx] : undefined;
|
|
34
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.envToArray = void 0;
|
|
4
|
+
exports.envIsTrue = envIsTrue;
|
|
5
|
+
exports.isProduction = isProduction;
|
|
6
|
+
const envToArray = (key) => {
|
|
7
|
+
if (process.env[key] === '')
|
|
8
|
+
return [];
|
|
9
|
+
return (process.env[key]?.split(',').map((v) => v.trim()) ?? []);
|
|
10
|
+
};
|
|
11
|
+
exports.envToArray = envToArray;
|
|
12
|
+
function envIsTrue(value) {
|
|
13
|
+
if (!value)
|
|
14
|
+
return false;
|
|
15
|
+
const val = value.toLowerCase();
|
|
16
|
+
return val === 'true' || val === '1' || val === 'on';
|
|
17
|
+
}
|
|
18
|
+
function isProduction(implicitCheck = true) {
|
|
19
|
+
return (process.env.NODE_ENV === 'production' ||
|
|
20
|
+
(implicitCheck &&
|
|
21
|
+
['test', 'pipeline', 'development'].every((v) => process.env.NODE_ENV !== v)));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=env.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.helper.js","sourceRoot":"","sources":["env.helper.ts"],"names":[],"mappings":";;;AAaA,8BAKC;AAQD,oCAQC;AA9BM,MAAM,UAAU,GAAG,CAAI,GAAW,EAAO,EAAE;IAEhD,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAEvC,OAAO,CACU,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAE,IAAI,EAAE,CACxE,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,UAAU,cAOrB;AAEF,SAAgB,SAAS,CAAC,KAAc;IACtC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IAEzB,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAChC,OAAO,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,IAAI,CAAC;AACvD,CAAC;AAQD,SAAgB,YAAY,CAAC,aAAa,GAAG,IAAI;IAC/C,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QACrC,CAAC,aAAa;YACZ,CAAC,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,KAAK,CACvC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,CAAC,CAClC,CAAC,CACL,CAAC;AACJ,CAAC"}
|