@verisoft/core 18.1.0 → 18.3.1

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 (38) hide show
  1. package/.eslintrc.json +43 -43
  2. package/README.md +7 -7
  3. package/jest.config.ts +22 -22
  4. package/ng-package.json +7 -7
  5. package/package.json +14 -11
  6. package/project.json +36 -36
  7. package/src/index.ts +3 -7
  8. package/src/lib/index.ts +1 -0
  9. package/src/lib/{base/models → models}/all-item.datasource.ts +5 -5
  10. package/src/lib/models/base-http.models.ts +144 -0
  11. package/src/lib/models/constants.ts +8 -0
  12. package/src/lib/models/datasource.model.ts +77 -0
  13. package/src/lib/models/environment.model.ts +5 -0
  14. package/src/lib/models/error-provider.model.ts +20 -0
  15. package/src/lib/models/event.models.ts +7 -0
  16. package/src/lib/models/index.ts +7 -0
  17. package/src/lib/services/base-http.service.ts +114 -104
  18. package/src/lib/services/error-provider.service.ts +29 -0
  19. package/src/lib/services/index.ts +3 -0
  20. package/src/lib/services/local-storage.service.ts +13 -0
  21. package/src/lib/services/storage.service.ts +13 -0
  22. package/src/lib/utils/array.utils.spec.ts +49 -0
  23. package/src/lib/utils/array.utils.ts +54 -9
  24. package/src/lib/utils/clear.utils.ts +53 -53
  25. package/src/lib/utils/data.utils.ts +34 -34
  26. package/src/lib/utils/date.utils.ts +30 -0
  27. package/src/lib/utils/index.ts +1 -0
  28. package/src/lib/utils/keyOrFn.utils.ts +15 -15
  29. package/src/lib/utils/object.utils.spec.ts +36 -1
  30. package/src/lib/utils/object.utils.ts +16 -0
  31. package/src/test-setup.ts +8 -8
  32. package/tsconfig.json +29 -29
  33. package/tsconfig.lib.json +17 -17
  34. package/tsconfig.lib.prod.json +9 -9
  35. package/tsconfig.spec.json +16 -16
  36. package/src/lib/base/models/base-http.models.ts +0 -96
  37. package/src/lib/base/models/table-datasource.models.ts +0 -9
  38. package/src/lib/models/lazy-load.model.ts +0 -4
@@ -1,4 +1,4 @@
1
- import { sortBy } from './object.utils';
1
+ import { getValueByPath, sortBy } from './object.utils';
2
2
 
3
3
  describe('object.utils', () => {
4
4
  describe('sortBy', () => {
@@ -31,4 +31,39 @@ describe('object.utils', () => {
31
31
  expect(sortedItems?.[3].name).toBeUndefined();
32
32
  });
33
33
  });
34
+
35
+ describe('getValueByPath', () => {
36
+ const complexObject = {
37
+ name: 'Martin',
38
+ age: 40,
39
+ address: {
40
+ city: 'Brno',
41
+ street: 'Kralova',
42
+ },
43
+ };
44
+
45
+ test('Should return property value when name of property is provided.', () => {
46
+ const value = getValueByPath(complexObject, 'name');
47
+
48
+ expect(value).toBe('Martin');
49
+ });
50
+
51
+ test('Should return undefined when name is nonexistent.', () => {
52
+ const value = getValueByPath(complexObject, 'nonexistentProperty');
53
+
54
+ expect(value).toBeUndefined();
55
+ });
56
+
57
+ test('Should return property value when name of property is complex path.', () => {
58
+ const value = getValueByPath(complexObject, 'address.city');
59
+
60
+ expect(value).toBe('Brno');
61
+ });
62
+
63
+ test('Should return undefined when some object on complex path missing.', () => {
64
+ const value = getValueByPath(complexObject, 'car.model');
65
+
66
+ expect(value).toBeUndefined();
67
+ });
68
+ });
34
69
  });
@@ -29,3 +29,19 @@ export function sortBy<TEntity, TProperty>(
29
29
  return 0;
30
30
  });
31
31
  }
32
+
33
+ export function getValueByPath<T, TValue>(
34
+ obj: T,
35
+ path: string | undefined,
36
+ ): TValue | undefined {
37
+ if (path == undefined || path == ''){
38
+ return obj as unknown as TValue;
39
+ }
40
+
41
+ return path.split('.').reduce((acc, key) => {
42
+ if (acc && typeof acc === 'object' && key in acc) {
43
+ return (acc as Record<string, TValue>)[key];
44
+ }
45
+ return undefined;
46
+ }, obj as unknown) as TValue;
47
+ }
package/src/test-setup.ts CHANGED
@@ -1,8 +1,8 @@
1
- // @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
2
- globalThis.ngJest = {
3
- testEnvironmentOptions: {
4
- errorOnUnknownElements: true,
5
- errorOnUnknownProperties: true,
6
- },
7
- };
8
- import 'jest-preset-angular/setup-jest';
1
+ // @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
2
+ globalThis.ngJest = {
3
+ testEnvironmentOptions: {
4
+ errorOnUnknownElements: true,
5
+ errorOnUnknownProperties: true,
6
+ },
7
+ };
8
+ import 'jest-preset-angular/setup-jest';
package/tsconfig.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2022",
4
- "useDefineForClassFields": false,
5
- "forceConsistentCasingInFileNames": true,
6
- "strict": true,
7
- "noImplicitOverride": true,
8
- "noPropertyAccessFromIndexSignature": true,
9
- "noImplicitReturns": true,
10
- "noFallthroughCasesInSwitch": true
11
- },
12
- "files": [],
13
- "include": [],
14
- "references": [
15
- {
16
- "path": "./tsconfig.lib.json"
17
- },
18
- {
19
- "path": "./tsconfig.spec.json"
20
- }
21
- ],
22
- "extends": "../../../tsconfig.base.json",
23
- "angularCompilerOptions": {
24
- "enableI18nLegacyMessageIdFormat": false,
25
- "strictInjectionParameters": true,
26
- "strictInputAccessModifiers": true,
27
- "strictTemplates": true
28
- }
29
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2022",
4
+ "useDefineForClassFields": false,
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": true,
7
+ "noImplicitOverride": true,
8
+ "noPropertyAccessFromIndexSignature": true,
9
+ "noImplicitReturns": true,
10
+ "noFallthroughCasesInSwitch": true
11
+ },
12
+ "files": [],
13
+ "include": [],
14
+ "references": [
15
+ {
16
+ "path": "./tsconfig.lib.json"
17
+ },
18
+ {
19
+ "path": "./tsconfig.spec.json"
20
+ }
21
+ ],
22
+ "extends": "../../../tsconfig.base.json",
23
+ "angularCompilerOptions": {
24
+ "enableI18nLegacyMessageIdFormat": false,
25
+ "strictInjectionParameters": true,
26
+ "strictInputAccessModifiers": true,
27
+ "strictTemplates": true
28
+ }
29
+ }
package/tsconfig.lib.json CHANGED
@@ -1,17 +1,17 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../dist/out-tsc",
5
- "declaration": true,
6
- "declarationMap": true,
7
- "inlineSources": true,
8
- "types": []
9
- },
10
- "exclude": [
11
- "src/**/*.spec.ts",
12
- "src/test-setup.ts",
13
- "jest.config.ts",
14
- "src/**/*.test.ts"
15
- ],
16
- "include": ["src/**/*.ts"]
17
- }
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../../dist/out-tsc",
5
+ "declaration": true,
6
+ "declarationMap": true,
7
+ "inlineSources": true,
8
+ "types": []
9
+ },
10
+ "exclude": [
11
+ "src/**/*.spec.ts",
12
+ "src/test-setup.ts",
13
+ "jest.config.ts",
14
+ "src/**/*.test.ts"
15
+ ],
16
+ "include": ["src/**/*.ts"]
17
+ }
@@ -1,9 +1,9 @@
1
- {
2
- "extends": "./tsconfig.lib.json",
3
- "compilerOptions": {
4
- "declarationMap": false
5
- },
6
- "angularCompilerOptions": {
7
- "compilationMode": "partial"
8
- }
9
- }
1
+ {
2
+ "extends": "./tsconfig.lib.json",
3
+ "compilerOptions": {
4
+ "declarationMap": false
5
+ },
6
+ "angularCompilerOptions": {
7
+ "compilationMode": "partial"
8
+ }
9
+ }
@@ -1,16 +1,16 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../dist/out-tsc",
5
- "module": "commonjs",
6
- "target": "es2016",
7
- "types": ["jest", "node"]
8
- },
9
- "files": ["src/test-setup.ts"],
10
- "include": [
11
- "jest.config.ts",
12
- "src/**/*.test.ts",
13
- "src/**/*.spec.ts",
14
- "src/**/*.d.ts"
15
- ]
16
- }
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "target": "es2016",
7
+ "types": ["jest", "node"]
8
+ },
9
+ "files": ["src/test-setup.ts"],
10
+ "include": [
11
+ "jest.config.ts",
12
+ "src/**/*.test.ts",
13
+ "src/**/*.spec.ts",
14
+ "src/**/*.d.ts"
15
+ ]
16
+ }
@@ -1,96 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { HttpParams, HttpResponse } from '@angular/common/http';
3
- import { InjectionToken } from '@angular/core';
4
-
5
- export const BASE_URL_PATH = new InjectionToken("BASE_URL_PATH");
6
-
7
- export function requestParamsToHttpParams<T>(
8
- requestParams: RequestParams<T>,
9
- httpParams: HttpParams = new HttpParams()
10
- ): HttpParams {
11
- httpParams = httpParams
12
- .append('Limit', requestParams.size.toString())
13
- .append('Offset', (requestParams.page * requestParams.size).toString());
14
- if (requestParams.id != '' && requestParams.id != undefined) {
15
- httpParams = httpParams.append('Id', requestParams.id as any);
16
- }
17
-
18
- httpParams = getFilter(requestParams, httpParams);
19
- httpParams = getSort(requestParams, httpParams);
20
-
21
- return httpParams;
22
- }
23
-
24
- function getFilter<T>(
25
- requestParams: RequestParams<any>,
26
- httpParams: HttpParams
27
- ): HttpParams {
28
- if (!requestParams.filter) {
29
- return httpParams;
30
- }
31
- Object.keys(requestParams?.filter).forEach((key) => {
32
- if (requestParams.filter?.[key as keyof Partial<T>]) {
33
- httpParams = httpParams.append(
34
- 'Filter.' + key,
35
- requestParams.filter?.[key as keyof Partial<T>]
36
- );
37
- }
38
- });
39
- return httpParams;
40
- }
41
-
42
- function getSort(
43
- requestParams: RequestParams<any>,
44
- httpParams: HttpParams
45
- ): HttpParams {
46
- if (!requestParams.sort) {
47
- return httpParams;
48
- }
49
-
50
- requestParams.sort?.forEach((sort) => {
51
- httpParams = httpParams
52
- .append('Sort.Field', sort.field)
53
- .append('Sort.Direction', sort.direction === -1 ? 'Desc' : 'Asc');
54
- });
55
- return httpParams;
56
- }
57
-
58
- export function saveFile(response: HttpResponse<Blob>) {
59
- const fileName = response.headers
60
- .get('Content-Disposition')
61
- ?.split(';')[1]
62
- .split('=')[1];
63
- const blob: Blob = response.body as Blob;
64
- const a = document.createElement('a');
65
- a.download = fileName ?? 'undefined';
66
- a.href = window.URL.createObjectURL(blob);
67
- a.click();
68
- }
69
-
70
- export declare interface Sort<T> {
71
- field: string;
72
- direction: number;
73
- }
74
-
75
- export interface RequestParams<T> {
76
- page: number;
77
- size: number;
78
- id?: string;
79
- filter?: Partial<T>;
80
- sort?: Sort<T>[];
81
- }
82
-
83
- export interface Page<T> {
84
- data: T[];
85
- total: number;
86
- size: number;
87
- number: number;
88
- }
89
-
90
- export const DEFAULT_SEARCH_LIMIT = 50;
91
-
92
- export const DEFAULT_SEARCH_PARAMS: RequestParams<any> = {
93
- page: 0,
94
- size: DEFAULT_SEARCH_LIMIT,
95
- id: '',
96
- };
@@ -1,9 +0,0 @@
1
- import { RequestParams } from "./base-http.models";
2
-
3
- export const DEFAULT_SEARCH_LIMIT = 50;
4
-
5
- export const DEFAULT_SEARCH_PARAMS: RequestParams<any> = {
6
- page: 0,
7
- size: DEFAULT_SEARCH_LIMIT,
8
- id: '',
9
- };
@@ -1,4 +0,0 @@
1
- export interface LazyLoad {
2
- offset: number;
3
- limit: number;
4
- }