@nest-yalc-2/utils 1.0.0 → 2.1.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.
Files changed (133) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/object-mapper.helper.spec.ts +1 -1
  3. package/src/__tests__/object-mapper.interceptor.spec.ts +1 -1
  4. package/src/index.d.ts +19 -19
  5. package/src/index.js +22 -35
  6. package/src/index.js.map +1 -1
  7. package/src/index.ts +21 -21
  8. package/src/object-mapper.interceptor.d.ts +1 -1
  9. package/src/object-mapper.interceptor.js +5 -10
  10. package/src/object-mapper.interceptor.js.map +1 -1
  11. package/src/object-mapper.interceptor.ts +1 -1
  12. package/src/simple-mapper.interceptor.js +2 -7
  13. package/src/simple-mapper.interceptor.js.map +1 -1
  14. package/src/__mocks__/enum.mock.ts +0 -9
  15. package/src/__tests__/class.helper.spec.ts +0 -32
  16. package/src/__tests__/command.helper.spec.ts +0 -35
  17. package/src/__tests__/config-manager.helper.spec.ts +0 -93
  18. package/src/__tests__/custom-validator.spec.ts +0 -34
  19. package/src/__tests__/data-structure.helper.spec.ts +0 -30
  20. package/src/__tests__/date.helper.spec.ts +0 -78
  21. package/src/__tests__/encryption.helper.spec.ts +0 -45
  22. package/src/__tests__/enum.helper.spec.ts +0 -53
  23. package/src/__tests__/env.helper.spec.ts +0 -68
  24. package/src/__tests__/error.helper.spec.ts +0 -20
  25. package/src/__tests__/faker-helper.spec.ts +0 -187
  26. package/src/__tests__/files.helper.spec.ts +0 -22
  27. package/src/__tests__/http.helper.spec.ts +0 -15
  28. package/src/__tests__/interval.helper.spec.ts +0 -29
  29. package/src/__tests__/math.helper.spec.ts +0 -24
  30. package/src/__tests__/object.helper.spec.ts +0 -181
  31. package/src/__tests__/plugin.helper.spec.ts +0 -85
  32. package/src/__tests__/promise.helper.spec.ts +0 -76
  33. package/src/__tests__/returnValue.spec.ts +0 -49
  34. package/src/__tests__/rxjs.helper.spec.ts +0 -79
  35. package/src/__tests__/tsconfig.json +0 -3
  36. package/src/__tests__/validator-helper.spec.ts +0 -34
  37. package/src/__tests__/zlib.helper.spec.ts +0 -20
  38. package/src/class.helper.d.ts +0 -4
  39. package/src/class.helper.js +0 -19
  40. package/src/class.helper.js.map +0 -1
  41. package/src/class.helper.ts +0 -33
  42. package/src/command.helper.d.ts +0 -1
  43. package/src/command.helper.js +0 -16
  44. package/src/command.helper.js.map +0 -1
  45. package/src/command.helper.ts +0 -19
  46. package/src/config-manager.helper.d.ts +0 -12
  47. package/src/config-manager.helper.js +0 -60
  48. package/src/config-manager.helper.js.map +0 -1
  49. package/src/config-manager.helper.ts +0 -122
  50. package/src/custom-validator.d.ts +0 -3
  51. package/src/custom-validator.js +0 -13
  52. package/src/custom-validator.js.map +0 -1
  53. package/src/custom-validator.ts +0 -13
  54. package/src/data-structure.helper.d.ts +0 -1
  55. package/src/data-structure.helper.js +0 -13
  56. package/src/data-structure.helper.js.map +0 -1
  57. package/src/data-structure.helper.ts +0 -14
  58. package/src/date.helper.d.ts +0 -12
  59. package/src/date.helper.js +0 -47
  60. package/src/date.helper.js.map +0 -1
  61. package/src/date.helper.ts +0 -65
  62. package/src/encryption.helper.d.ts +0 -2
  63. package/src/encryption.helper.js +0 -58
  64. package/src/encryption.helper.js.map +0 -1
  65. package/src/encryption.helper.ts +0 -29
  66. package/src/enum.helper.d.ts +0 -8
  67. package/src/enum.helper.js +0 -21
  68. package/src/enum.helper.js.map +0 -1
  69. package/src/enum.helper.ts +0 -34
  70. package/src/env.helper.d.ts +0 -3
  71. package/src/env.helper.js +0 -23
  72. package/src/env.helper.js.map +0 -1
  73. package/src/env.helper.ts +0 -35
  74. package/src/error.helper.d.ts +0 -1
  75. package/src/error.helper.js +0 -12
  76. package/src/error.helper.js.map +0 -1
  77. package/src/error.helper.ts +0 -12
  78. package/src/faker-helper.d.ts +0 -16
  79. package/src/faker-helper.js +0 -73
  80. package/src/faker-helper.js.map +0 -1
  81. package/src/faker-helper.ts +0 -98
  82. package/src/files.helper.d.ts +0 -2
  83. package/src/files.helper.js +0 -13
  84. package/src/files.helper.js.map +0 -1
  85. package/src/files.helper.ts +0 -20
  86. package/src/http.helper.d.ts +0 -26
  87. package/src/http.helper.js +0 -84
  88. package/src/http.helper.js.map +0 -1
  89. package/src/http.helper.ts +0 -152
  90. package/src/interval.helper.d.ts +0 -5
  91. package/src/interval.helper.js +0 -16
  92. package/src/interval.helper.js.map +0 -1
  93. package/src/interval.helper.ts +0 -13
  94. package/src/math.helper.d.ts +0 -1
  95. package/src/math.helper.js +0 -8
  96. package/src/math.helper.js.map +0 -1
  97. package/src/math.helper.ts +0 -4
  98. package/src/nest.decorator.d.ts +0 -3
  99. package/src/nest.decorator.js +0 -10
  100. package/src/nest.decorator.js.map +0 -1
  101. package/src/nest.decorator.ts +0 -10
  102. package/src/object-mapper.helper.d.ts +0 -16
  103. package/src/object-mapper.helper.js +0 -47
  104. package/src/object-mapper.helper.js.map +0 -1
  105. package/src/object-mapper.helper.ts +0 -148
  106. package/src/object.helper.d.ts +0 -18
  107. package/src/object.helper.js +0 -91
  108. package/src/object.helper.js.map +0 -1
  109. package/src/object.helper.ts +0 -173
  110. package/src/plugin.helper.d.ts +0 -22
  111. package/src/plugin.helper.js +0 -26
  112. package/src/plugin.helper.js.map +0 -1
  113. package/src/plugin.helper.ts +0 -42
  114. package/src/promise.helper.d.ts +0 -13
  115. package/src/promise.helper.js +0 -71
  116. package/src/promise.helper.js.map +0 -1
  117. package/src/promise.helper.ts +0 -65
  118. package/src/returnValue.d.ts +0 -14
  119. package/src/returnValue.js +0 -17
  120. package/src/returnValue.js.map +0 -1
  121. package/src/returnValue.ts +0 -26
  122. package/src/rxjs.helper.d.ts +0 -7
  123. package/src/rxjs.helper.js +0 -33
  124. package/src/rxjs.helper.js.map +0 -1
  125. package/src/rxjs.helper.ts +0 -71
  126. package/src/validator-helper.d.ts +0 -2
  127. package/src/validator-helper.js +0 -22
  128. package/src/validator-helper.js.map +0 -1
  129. package/src/validator-helper.ts +0 -26
  130. package/src/zlib.helper.d.ts +0 -3
  131. package/src/zlib.helper.js +0 -25
  132. package/src/zlib.helper.js.map +0 -1
  133. package/src/zlib.helper.ts +0 -19
@@ -1,76 +0,0 @@
1
- import {
2
- describe,
3
- expect,
4
- it,
5
- jest,
6
- beforeAll,
7
- beforeEach,
8
- test,
9
- } from '@jest/globals';
10
- import { PromiseTracker, promiseMap } from '../promise.helper.js';
11
-
12
- describe('promise helper test', () => {
13
- const elements = [1, 2];
14
-
15
- it('It should resolve promises correctly with explicit options', async () => {
16
- const result = await promiseMap(elements, async (element) => element, {
17
- concurrency: 10,
18
- stopOnError: false,
19
- });
20
-
21
- expect(result).toEqual(elements);
22
- });
23
-
24
- it('It should resolve promises correctly with implicit options', async () => {
25
- const result = await promiseMap(elements, async (element) => element);
26
-
27
- expect(result).toEqual(elements);
28
- });
29
- });
30
-
31
- describe('promise tracker test', () => {
32
- it('It should wait for all promises to resolve', async () => {
33
- const promiseTracker = new PromiseTracker();
34
-
35
- const promises = [Promise.resolve(1), Promise.resolve(2)];
36
-
37
- promises.forEach((promise) => promiseTracker.add(promise));
38
-
39
- await promiseTracker.waitForAll();
40
-
41
- expect(promiseTracker['promises']).toHaveLength(0);
42
- });
43
-
44
- it('It should run deferred callbacks after tracked promises', async () => {
45
- const promiseTracker = new PromiseTracker();
46
- const calls: string[] = [];
47
-
48
- promiseTracker.add(
49
- Promise.resolve('ok').then((value) => {
50
- calls.push(value);
51
- return value;
52
- }),
53
- );
54
-
55
- promiseTracker.addDeferred(() => {
56
- calls.push('deferred');
57
- });
58
-
59
- await promiseTracker.waitForAll();
60
-
61
- expect(calls).toEqual(['ok', 'deferred']);
62
- expect(promiseTracker['promises']).toHaveLength(0);
63
- });
64
-
65
- it('It should clean up tracked promises when they reject', async () => {
66
- const promiseTracker = new PromiseTracker();
67
- const error = new Error('boom');
68
-
69
- promiseTracker.add(Promise.reject(error));
70
-
71
- await expect(promiseTracker.waitForAll()).rejects.toThrow(error);
72
- await new Promise((resolve) => setTimeout(resolve, 0));
73
-
74
- expect(promiseTracker['promises']).toHaveLength(0);
75
- });
76
- });
@@ -1,49 +0,0 @@
1
- import {
2
- expect,
3
- jest,
4
- describe,
5
- it,
6
- beforeEach,
7
- beforeAll,
8
- afterAll,
9
- afterEach,
10
- test,
11
- } from '@jest/globals';
12
-
13
- import returnValue, { returnAsyncValue, returnProperty } from '../returnValue.js';
14
-
15
- test('returnValue should return a constant function', () => {
16
- class TypeTest {}
17
-
18
- const testArgSamples = [
19
- 'pass',
20
- [],
21
- TypeTest,
22
- undefined,
23
- null,
24
- () => 'Another Function',
25
- ];
26
-
27
- testArgSamples.forEach((value) => {
28
- const returnTypeTest = returnValue(value);
29
- expect(returnTypeTest).toBeInstanceOf(Function);
30
- expect(returnTypeTest()).toEqual(value);
31
- });
32
- });
33
-
34
- test('returnAsyncValue should resolve the provided value', async () => {
35
- const fn = returnAsyncValue('async-value');
36
- await expect(fn()).resolves.toBe('async-value');
37
- });
38
-
39
- test('returnProperty should return a property of a class', () => {
40
- class TypeTest {
41
- validProperty = 'something';
42
- }
43
-
44
- const returnTypeTest = returnProperty<TypeTest>('validProperty');
45
- expect(returnTypeTest(new TypeTest())).toBe('something');
46
-
47
- const returnTypeBadTest = returnProperty<any>('invalidProperty');
48
- expect(returnTypeBadTest(new TypeTest())).toBeUndefined();
49
- });
@@ -1,79 +0,0 @@
1
- import {
2
- expect,
3
- jest,
4
- describe,
5
- it,
6
- beforeEach,
7
- beforeAll,
8
- afterAll,
9
- afterEach,
10
- } from '@jest/globals';
11
- import * as rxjs from 'rxjs';
12
-
13
- import * as rxjsHelper from '../rxjs.helper.js';
14
-
15
- describe('test rxjs helper', () => {
16
- it('should execute switchTap', async () => {
17
- const subject = rxjs.of(1).pipe(
18
- rxjsHelper.switchTap(async (value: any, index: number) => {
19
- return value;
20
- }),
21
- );
22
-
23
- await expect(rxjs.lastValueFrom(subject)).resolves.toEqual(1);
24
- });
25
-
26
- it('should execute switchTap without return any values', async () => {
27
- const subject = rxjs
28
- .of(1)
29
- .pipe(rxjsHelper.switchTap(async (value: any, index: number) => {}));
30
-
31
- await expect(rxjs.lastValueFrom(subject)).resolves.toEqual(1);
32
- });
33
-
34
- it('should execute switchTap returning a null value', async () => {
35
- const subject = rxjs
36
- .of(1)
37
- .pipe(rxjsHelper.switchTap(async (value: any, index: number) => null));
38
-
39
- await expect(rxjs.lastValueFrom(subject)).resolves.toEqual(null);
40
- });
41
-
42
- it('should execute wrapIntoObservable', () => {
43
- const subject = rxjsHelper.wrapIntoObservable(new rxjs.Observable());
44
- expect(subject).toBeDefined();
45
- });
46
-
47
- it('should execute wrapIntoObservable with async function', () => {
48
- const subject = rxjsHelper.wrapIntoObservable(async () => {});
49
- expect(subject).toBeDefined();
50
- });
51
-
52
- it('should execute wrapIntoObservable with non-async function', () => {
53
- const subject = rxjsHelper.wrapIntoObservable(() => {});
54
- expect(subject).toBeDefined();
55
- });
56
-
57
- it('should execute wrapIntoObservable with null', () => {
58
- const subject = rxjsHelper.wrapIntoObservable(null);
59
- expect(subject).toBeDefined();
60
- });
61
-
62
- it('should execute wrapIntoAnOperator', () => {
63
- const subject = rxjsHelper.wrapIntoAnOperator(
64
- (value: any, index: number) => {
65
- return value;
66
- },
67
- );
68
- expect(subject(new rxjs.Observable())).toBeDefined();
69
- });
70
-
71
- it('should execute wrapIntoAnOperator with async function', () => {
72
- const subject = rxjsHelper.wrapIntoAnOperator(
73
- async (value: any, index: number) => {
74
- return value;
75
- },
76
- );
77
- expect(subject(new rxjs.Observable())).toBeDefined();
78
- });
79
- });
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.test.json"
3
- }
@@ -1,34 +0,0 @@
1
- import { describe, expect, it } from '@jest/globals';
2
- import {
3
- stringIsInEnum,
4
- stringIsInEnumOrThrow,
5
- } from '../validator-helper.js';
6
-
7
- enum TestEnum {
8
- FOO = 'FOO',
9
- BAR = 'BAR',
10
- }
11
-
12
- describe('validator-helper', () => {
13
- it('should match enum values case-insensitively', () => {
14
- expect(stringIsInEnum('foo', TestEnum)).toBe(true);
15
- expect(stringIsInEnum('Bar', TestEnum)).toBe(true);
16
- expect(stringIsInEnum('baz', TestEnum)).toBe(false);
17
- });
18
-
19
- it('should throw with default message when value is invalid', () => {
20
- expect(() => stringIsInEnumOrThrow('missing', TestEnum)).toThrow(
21
- 'Invalid value missing',
22
- );
23
- });
24
-
25
- it('should allow custom error messages', () => {
26
- expect(() =>
27
- stringIsInEnumOrThrow('invalid', TestEnum, 'custom message'),
28
- ).toThrow('custom message');
29
- });
30
-
31
- it('should return true when value is valid', () => {
32
- expect(stringIsInEnumOrThrow('foo', TestEnum)).toBe(true);
33
- });
34
- });
@@ -1,20 +0,0 @@
1
- import { describe, expect, it } from '@jest/globals';
2
- import { inflate, deflate } from '../zlib.helper.js';
3
-
4
- describe('zlib helpers', () => {
5
- it('should return input when inflate/deflate fail', () => {
6
- const plain = 'not-base64';
7
- expect(inflate(plain)).toBe(plain);
8
-
9
- const invalidInput: any = { invalid: true };
10
- expect(deflate(invalidInput)).toBe(invalidInput);
11
- });
12
-
13
- it('should deflate and inflate valid payloads', () => {
14
- const payload = 'hello';
15
- const deflated = deflate(payload) as Buffer;
16
- expect(deflated).toBeInstanceOf(Buffer);
17
- const inflated = inflate(deflated.toString('base64'));
18
- expect(inflated).toBe(payload);
19
- });
20
- });
@@ -1,4 +0,0 @@
1
- import { ClassType } from '@nest-yalc-2/types/globals.d.js';
2
- export declare function isNativeClass<T = any>(func: any, className?: string): func is ClassType<T>;
3
- export declare function isES6Class<T = any>(func: any, className?: string): func is ClassType<T>;
4
- export declare function isClass<T = any>(func: any, className?: string): func is ClassType<T>;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNativeClass = isNativeClass;
4
- exports.isES6Class = isES6Class;
5
- exports.isClass = isClass;
6
- function isNativeClass(func, className) {
7
- return (typeof func === 'function' &&
8
- func.prototype?.constructor === func &&
9
- (className ? func.name === className : true));
10
- }
11
- function isES6Class(func, className) {
12
- return (typeof func === 'function' &&
13
- /^class\s/.test(func.toString()) &&
14
- (className ? func.name === className : true));
15
- }
16
- function isClass(func, className) {
17
- return isNativeClass(func, className) || isES6Class(func, className);
18
- }
19
- //# sourceMappingURL=class.helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"class.helper.js","sourceRoot":"","sources":["class.helper.ts"],"names":[],"mappings":";;AAGA,sCASC;AAGD,gCASC;AAGD,0BAKC;AA7BD,SAAgB,aAAa,CAC3B,IAAS,EACT,SAAkB;IAElB,OAAO,CACL,OAAO,IAAI,KAAK,UAAU;QAC1B,IAAI,CAAC,SAAS,EAAE,WAAW,KAAK,IAAI;QACpC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7C,CAAC;AACJ,CAAC;AAGD,SAAgB,UAAU,CACxB,IAAS,EACT,SAAkB;IAElB,OAAO,CACL,OAAO,IAAI,KAAK,UAAU;QAC1B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7C,CAAC;AACJ,CAAC;AAGD,SAAgB,OAAO,CACrB,IAAS,EACT,SAAkB;IAElB,OAAO,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AACvE,CAAC"}
@@ -1,33 +0,0 @@
1
- import { ClassType } from '@nest-yalc-2/types/globals.d.js';
2
-
3
- // Check if the class is a native class (like Error, Array, etc.)
4
- export function isNativeClass<T = any>(
5
- func: any,
6
- className?: string,
7
- ): func is ClassType<T> {
8
- return (
9
- typeof func === 'function' &&
10
- func.prototype?.constructor === func && // Native class constructors have this prototype constructor link
11
- (className ? func.name === className : true)
12
- );
13
- }
14
-
15
- // Check if the class is an ES6-style class
16
- export function isES6Class<T = any>(
17
- func: any,
18
- className?: string,
19
- ): func is ClassType<T> {
20
- return (
21
- typeof func === 'function' &&
22
- /^class\s/.test(func.toString()) && // ES6 classes start with the keyword "class"
23
- (className ? func.name === className : true)
24
- );
25
- }
26
-
27
- // Check if the class is either native or ES6
28
- export function isClass<T = any>(
29
- func: any,
30
- className?: string,
31
- ): func is ClassType<T> {
32
- return isNativeClass(func, className) || isES6Class(func, className);
33
- }
@@ -1 +0,0 @@
1
- export declare const commandWithErrors: (command: (...args: any[]) => Promise<any>) => (...args: any[]) => Promise<void>;
@@ -1,16 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,19 +0,0 @@
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
- };
@@ -1,12 +0,0 @@
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
- }
@@ -1,60 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-manager.helper.js","sourceRoot":"","sources":["config-manager.helper.ts"],"names":[],"mappings":"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"}
@@ -1,122 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- export declare const stringIsInEnumValidatorFactory: <T extends Record<string, string | number>>(property: T) => {
2
- validate(value: any): boolean;
3
- };
@@ -1,13 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,13 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- export declare const arrayGroupByField: <T, K extends string | number | symbol>(entityArray: T[], getKey: (item: T) => K) => Record<K, T[]>;
@@ -1,13 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,14 +0,0 @@
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
- };
@@ -1,12 +0,0 @@
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
- }