@verisoft/core 18.7.0 → 19.0.0-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 (50) hide show
  1. package/README.md +7 -56
  2. package/fesm2022/verisoft-core.mjs +465 -0
  3. package/fesm2022/verisoft-core.mjs.map +1 -0
  4. package/{src/index.ts → index.d.ts} +3 -3
  5. package/{src/lib/models/all-item.datasource.ts → lib/models/all-item.datasource.d.ts} +4 -5
  6. package/lib/models/base-http.models.d.ts +41 -0
  7. package/lib/models/constants.d.ts +3 -0
  8. package/lib/models/datasource.model.d.ts +8 -0
  9. package/{src/lib/models/environment.model.ts → lib/models/environment.model.d.ts} +5 -5
  10. package/lib/models/error-provider.model.d.ts +11 -0
  11. package/{src/lib/models/event.models.ts → lib/models/event.models.d.ts} +5 -7
  12. package/{src/lib/models/index.ts → lib/models/index.d.ts} +7 -7
  13. package/lib/services/base-http.service.d.ts +21 -0
  14. package/lib/services/error-provider.service.d.ts +12 -0
  15. package/{src/lib/services/index.ts → lib/services/index.d.ts} +3 -3
  16. package/lib/services/local-storage.service.d.ts +5 -0
  17. package/lib/utils/array.utils.d.ts +5 -0
  18. package/lib/utils/clear.utils.d.ts +7 -0
  19. package/lib/utils/data.utils.d.ts +3 -0
  20. package/lib/utils/date.utils.d.ts +1 -0
  21. package/{src/lib/utils/index.ts → lib/utils/index.d.ts} +6 -6
  22. package/lib/utils/keyOrFn.utils.d.ts +1 -0
  23. package/lib/utils/object.utils.d.ts +2 -0
  24. package/package.json +27 -14
  25. package/.eslintrc.json +0 -43
  26. package/jest.config.ts +0 -22
  27. package/ng-package.json +0 -7
  28. package/project.json +0 -36
  29. package/src/lib/index.ts +0 -1
  30. package/src/lib/models/base-http.models.ts +0 -144
  31. package/src/lib/models/constants.ts +0 -8
  32. package/src/lib/models/datasource.model.ts +0 -77
  33. package/src/lib/models/error-provider.model.ts +0 -20
  34. package/src/lib/services/base-http.service.ts +0 -114
  35. package/src/lib/services/error-provider.service.ts +0 -29
  36. package/src/lib/services/local-storage.service.ts +0 -13
  37. package/src/lib/services/storage.service.ts +0 -13
  38. package/src/lib/utils/array.utils.spec.ts +0 -49
  39. package/src/lib/utils/array.utils.ts +0 -54
  40. package/src/lib/utils/clear.utils.ts +0 -53
  41. package/src/lib/utils/data.utils.ts +0 -34
  42. package/src/lib/utils/date.utils.ts +0 -30
  43. package/src/lib/utils/keyOrFn.utils.ts +0 -15
  44. package/src/lib/utils/object.utils.spec.ts +0 -69
  45. package/src/lib/utils/object.utils.ts +0 -47
  46. package/src/test-setup.ts +0 -8
  47. package/tsconfig.json +0 -29
  48. package/tsconfig.lib.json +0 -20
  49. package/tsconfig.lib.prod.json +0 -9
  50. package/tsconfig.spec.json +0 -16
@@ -1,114 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { HttpClient } from '@angular/common/http';
3
- import { map, Observable } from 'rxjs';
4
- import {
5
- AllDataRequestParams,
6
- DEFAULT_SEARCH_PARAMS,
7
- Page,
8
- RequestParams,
9
- requestParamsToHttpParams,
10
- } from '../models/base-http.models';
11
- import { LazyLoadEvent } from '../models/event.models';
12
- import { ClearUtils } from '../utils/clear.utils';
13
-
14
- export class BaseHttpService<T, TKey = number | string> {
15
- constructor(
16
- readonly http: HttpClient,
17
- readonly basePath: string,
18
- readonly entityName: string
19
- ) {
20
- this.basePath = basePath;
21
- }
22
-
23
- protected get apiPath() {
24
- return this.basePath ? this.basePath + this.entityName : this.entityName;
25
- }
26
-
27
- fetchList(requestParams: RequestParams<T>): Observable<Page<T>> {
28
- const params = requestParamsToHttpParams<T>(requestParams);
29
- return this.http.get<Page<T>>(this.apiPath, { params }).pipe(
30
- map((response: Page<T>) => {
31
- response.limit = requestParams.limit;
32
- return response;
33
- })
34
- );
35
- }
36
-
37
- getData$(
38
- entityName: keyof T,
39
- searchTerm?: string | undefined,
40
- lazyLoad?: LazyLoadEvent
41
- ): Observable<T[]> {
42
- const filter: Partial<T> = { [entityName]: searchTerm } as Partial<T>;
43
- const params = lazyLoad
44
- ? requestParamsToHttpParams<T>({
45
- ...DEFAULT_SEARCH_PARAMS,
46
- offset: lazyLoad.offset,
47
- limit: lazyLoad.limit,
48
- filter,
49
- })
50
- : requestParamsToHttpParams<T>({
51
- ...DEFAULT_SEARCH_PARAMS,
52
- filter,
53
- });
54
-
55
- return this.http.get<T[]>(this.apiPath, { params });
56
- }
57
-
58
- get(id: TKey): Observable<T> {
59
- const url = `${this.apiPath}/${id}`;
60
- return this.http.get<T>(url);
61
- }
62
-
63
- post(entity: Partial<T>): Observable<T> {
64
- return this.http.post<T>(this.apiPath, entity);
65
- }
66
-
67
- put(id: TKey, entity: Partial<T>): Observable<T> {
68
- const url = `${this.apiPath}/${id}`;
69
- return this.http.put<T>(url, entity);
70
- }
71
-
72
- delete(id: TKey): Observable<T> {
73
- const url = `${this.apiPath}/${id}`;
74
- return this.http.delete<T>(url);
75
- }
76
-
77
- export(requestParams: AllDataRequestParams<T>): Observable<Blob> {
78
- const httpParams = requestParamsToHttpParams<T>(requestParams);
79
- const url = `${this.apiPath}/export`;
80
- return this.http.get(url, { responseType: 'blob', params: httpParams });
81
- }
82
-
83
- removeRange(entity: string[]) {
84
- return this.http.delete(this.apiPath, {
85
- body: entity,
86
- });
87
- }
88
-
89
- createParams<T>(requestParams: RequestParams<T>): any {
90
- const sorter = this.createSorter(requestParams);
91
- const filter = JSON.parse(JSON.stringify(requestParams.filter));
92
- const transformedFilter = filter;
93
- ClearUtils.recursiveObjectAttributesDeletation(transformedFilter);
94
- return {
95
- paging: {
96
- offset: requestParams.offset,
97
- limit: requestParams.limit,
98
- },
99
- ...(sorter && { sorting: sorter }),
100
- ...(transformedFilter && { filter: transformedFilter }),
101
- };
102
- }
103
-
104
- private createSorter<T>(requestParams: RequestParams<T>) {
105
- if (requestParams?.sort?.length === 1) {
106
- const sorter = requestParams.sort[0];
107
- return {
108
- sortField: sorter.field,
109
- sortOrder: sorter.direction,
110
- };
111
- }
112
- return null;
113
- }
114
- }
@@ -1,29 +0,0 @@
1
- import { inject, Injectable } from '@angular/core';
2
- import { ValidationErrors } from '@angular/forms';
3
- import { TranslateService } from '@ngx-translate/core';
4
- import { Observable } from 'rxjs';
5
- import { ErrorProvider, ErrorMap } from '../models/error-provider.model';
6
-
7
- @Injectable({
8
- providedIn: 'root'
9
- })
10
- export class LocalizableErrorProviderService implements ErrorProvider {
11
- private readonly translateService = inject(TranslateService);
12
- readonly errors: Record<string, (value?: any) => string> = ErrorMap;
13
-
14
- mapError(errors: ValidationErrors): Observable<string> {
15
- const error = this.getFirstValue(errors);
16
- try {
17
- const value = this.errors[error.key](error.value);
18
- return this.translateService.get(value);
19
- } catch (_) {
20
- throw new Error(`Key "${error.key}" is not specified in the current error map!`);
21
- }
22
- }
23
-
24
- private getFirstValue(errors: ValidationErrors): { key: string; value: string } {
25
- const key = Object.keys(errors)[0];
26
- const value = errors[key];
27
- return { key, value };
28
- }
29
- }
@@ -1,13 +0,0 @@
1
- export class LocalStorageService {
2
- setItem(key: string, value: string) {
3
- localStorage.setItem(key, value);
4
- }
5
-
6
- getItem(key: string): string | null {
7
- return localStorage.getItem(key);
8
- }
9
-
10
- removeItem(key: string) {
11
- localStorage.removeItem(key);
12
- }
13
- }
@@ -1,13 +0,0 @@
1
- export class StorageService {
2
- setItem(key: string, value: string) {
3
- localStorage.setItem(key, value);
4
- }
5
-
6
- getItem(key: string): string | null {
7
- return localStorage.getItem(key);
8
- }
9
-
10
- removeItem(key: string) {
11
- localStorage.removeItem(key);
12
- }
13
- }
@@ -1,49 +0,0 @@
1
- import { applyFilter } from './array.utils';
2
- describe('array.utils', () => {
3
- describe('applyFilter', () => {
4
- interface TestData {
5
- id: number;
6
- name: string;
7
- tags: string[];
8
- age: number;
9
- }
10
-
11
- const data: TestData[] = [
12
- { id: 1, name: 'Alice', tags: ['developer', 'angular'], age: 25 },
13
- { id: 2, name: 'Bob', tags: ['designer', 'figma'], age: 30 },
14
- { id: 3, name: 'Charlie', tags: ['developer'], age: 25 },
15
- { id: 4, name: 'Dave', tags: ['developer', 'react'], age: 35 },
16
- ];
17
-
18
- const [alice, , charlie] = data;
19
-
20
- test('Should filter data by contains string value when a single string filter is applied', () => {
21
- const filter = { name: 'lice' };
22
- const result = applyFilter(data, filter);
23
- expect(result).toEqual([alice]);
24
- });
25
-
26
- test('Should filter data when filter contains an array value', () => {
27
- const filter = { tags: ['develop'] };
28
- const result = applyFilter(data, filter);
29
- expect(result).toHaveLength(3);
30
- });
31
-
32
- test('Should filter data with multiple conditions when filter properties use AND logic', () => {
33
- const filter = { age: 25, tags: ['developer'] };
34
- const result = applyFilter(data, filter);
35
- expect(result).toEqual([alice, charlie]);
36
- });
37
-
38
- test('Should return all data when the filter is empty', () => {
39
- const result = applyFilter(data, {});
40
- expect(result).toEqual(data);
41
- });
42
-
43
- test('Should return no data when no items match the filter', () => {
44
- const filter = { name: 'Zoe' };
45
- const result = applyFilter(data, filter);
46
- expect(result).toHaveLength(0);
47
- });
48
- });
49
- });
@@ -1,54 +0,0 @@
1
- import { Sort } from "../models";
2
- import { getValueByPath } from "./object.utils";
3
-
4
- type ArrayIntersectionType = (string | number)[]
5
-
6
- export function isArrayIntersected(
7
- array1: ArrayIntersectionType,
8
- array2: ArrayIntersectionType,
9
- ) {
10
- const filteredArray = array1.filter(value => array2.includes(value));
11
- return filteredArray.length > 0;
12
- }
13
-
14
- export function multiSort<T>(values: T[], sorts: Sort[]): T[] {
15
- return [...values].sort((a, b) => {
16
- for (const sort of sorts) {
17
- const { field, direction } = sort;
18
- const valueA = getValueByPath(a, field);
19
- const valueB = getValueByPath(b, field);
20
-
21
- if (valueA !== valueB) {
22
- if (isComparable(valueA) && isComparable(valueB)) {
23
- if (typeof valueA === 'string' && typeof valueB === 'string') {
24
- const baseCompare = valueA.localeCompare(valueB, undefined, {
25
- sensitivity: 'base',
26
- });
27
-
28
- if (baseCompare === 0) {
29
- return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
30
- }
31
-
32
- return direction === 'asc' ? baseCompare : -baseCompare;
33
- } else {
34
- if (valueA < valueB) {
35
- return direction === 'asc' ? -1 : 1;
36
- }
37
- if (valueA > valueB) {
38
- return direction === 'asc' ? 1 : -1;
39
- }
40
- }
41
- }
42
- }
43
- }
44
-
45
- return 0;
46
- });
47
- }
48
-
49
- function isComparable(value: unknown): value is string | number | Date {
50
- return typeof value === 'string'
51
- || typeof value === 'number'
52
- || typeof value === 'boolean'
53
- || value instanceof Date;
54
- }
@@ -1,53 +0,0 @@
1
- export class ClearUtils {
2
-
3
- static recursiveObjectAttributesTransformation(obj: any): void {
4
- ClearUtils.recursiveObjectAttributesTraversal(
5
- obj,
6
- ClearUtils.transformEmptyStringToNullStringFn
7
- );
8
- }
9
- static recursiveObjectAttributesDeletation(obj: any): void {
10
- ClearUtils.recursiveObjectAttributesTraversal(
11
- obj,
12
- ClearUtils.deleteEmptyStringToNullStringFn
13
- );
14
- }
15
-
16
- static transformEmptyStringToNullStringFn(obj: any, key: string) {
17
- if (typeof obj[key] === 'string' && obj[key] === '') {
18
- obj[key] = null;
19
- }
20
- }
21
- static deleteEmptyStringToNullStringFn(obj: any, key: string) {
22
- if (obj[key] === '' || obj[key] === null || obj[key] === undefined) {
23
- delete obj[key]
24
- }
25
- }
26
-
27
-
28
- static recursiveObjectAttributesTraversal(
29
- obj: any,
30
- transformationFn: (obj: any, key: string) => void
31
- ) {
32
- if (
33
- obj === null ||
34
- transformationFn === null ||
35
- typeof transformationFn !== 'function'
36
- ) {
37
- return;
38
- }
39
-
40
- Object.keys(obj).forEach((key) => {
41
- transformationFn(obj, key);
42
-
43
- if (typeof obj[key] === 'object') {
44
- this.recursiveObjectAttributesTraversal(obj[key], transformationFn);
45
-
46
- if (!Object.keys(obj[key]).length) {
47
- delete obj[key];
48
- }
49
- }
50
- });
51
- }
52
-
53
- }
@@ -1,34 +0,0 @@
1
- import moment from 'moment';
2
-
3
- export function transformData(data: any) {
4
- if (data) {
5
- if (moment.isMoment(data)) {
6
- return moment(data)
7
- .toDate()
8
- .toISOString();
9
- }
10
- else if (data instanceof Date) {
11
- return data.toISOString();
12
- }
13
- }
14
- return data;
15
- }
16
-
17
- export function convertToDate(data: any) {
18
- if (data) {
19
- if (!isNaN(Date.parse(data))) {
20
- return new Date(data);
21
- }
22
- }
23
- return data;
24
- }
25
-
26
- export function convertToDateTime(data: any) {
27
- if (data) {
28
- if (!isNaN(Date.parse(data))) {
29
- const date = new Date(data);
30
- return moment(date).format('DD.MM.yyyy HH:mm');
31
- }
32
- }
33
- return data;
34
- }
@@ -1,30 +0,0 @@
1
- const czechDateFormat = new Intl.DateTimeFormat("cs-CZ", {
2
- day: "numeric",
3
- month: "numeric",
4
- year: "numeric"
5
- });
6
-
7
- const czechDateTimeFormat = new Intl.DateTimeFormat("cs-CZ", {
8
- second: "numeric",
9
- minute: "numeric",
10
- hour: "numeric",
11
- day: "numeric",
12
- month: "numeric",
13
- year: "numeric"
14
- });
15
-
16
- export function toCzechDateTimeString(value?: Date | string, time = false): string {
17
- if (!value) {
18
- return "";
19
- }
20
-
21
- if (typeof value === "string") {
22
- value = new Date(value);
23
- }
24
-
25
- if (time) {
26
- return czechDateTimeFormat.format(value);
27
- }
28
-
29
- return czechDateFormat.format(value);
30
- }
@@ -1,15 +0,0 @@
1
- export function keyOrFn(keyOrFn: ((row: any) => string | undefined) | string, row: any) {
2
- if (keyOrFn instanceof Function) {
3
- return keyOrFn(row);
4
- }
5
- else if (typeof keyOrFn === 'string') {
6
- const value = row[keyOrFn];
7
- if (value) {
8
- return value;
9
- }
10
- }
11
- else if (typeof keyOrFn === 'boolean') {
12
- return keyOrFn;
13
- }
14
- return '';
15
- }
@@ -1,69 +0,0 @@
1
- import { getValueByPath, sortBy } from './object.utils';
2
-
3
- describe('object.utils', () => {
4
- describe('sortBy', () => {
5
- const items = [
6
- { name: undefined, age: 60 },
7
- { name: 'Martin', age: 40 },
8
- { name: 'Alena', age: 28 },
9
- { name: 'Karel', age: 15 },
10
- ];
11
-
12
- test('Should sort items by name ascending.', () => {
13
- const sortedItems = sortBy(items, (x) => x.name);
14
-
15
- expect(items).not.toBe(sortedItems);
16
- expect(sortedItems).toBeDefined();
17
- expect(sortedItems?.[0].name).toBeUndefined();
18
- expect(sortedItems?.[1].name).toBe('Alena');
19
- expect(sortedItems?.[2].name).toBe('Karel');
20
- expect(sortedItems?.[3].name).toBe('Martin');
21
- });
22
-
23
- test('Should sort items by name descending.', () => {
24
- const sortedItems = sortBy(items, (x) => x.name, false);
25
-
26
- expect(items).not.toBe(sortedItems);
27
- expect(sortedItems).toBeDefined();
28
- expect(sortedItems?.[0].name).toBe('Martin');
29
- expect(sortedItems?.[1].name).toBe('Karel');
30
- expect(sortedItems?.[2].name).toBe('Alena');
31
- expect(sortedItems?.[3].name).toBeUndefined();
32
- });
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
- });
69
- });
@@ -1,47 +0,0 @@
1
- export function sortBy<TEntity, TProperty>(
2
- items: TEntity[],
3
- selector: (item: TEntity) => TProperty,
4
- ascending = true
5
- ): TEntity[] {
6
- return [...items].sort((item, other) => {
7
- const value = selector(item);
8
- const otherValue = selector(other);
9
- const direction = ascending ? 1 : -1;
10
- if (value == undefined && other == undefined) {
11
- return 0;
12
- }
13
-
14
- if (value == undefined) {
15
- return -1 * direction;
16
- }
17
- if (otherValue == undefined) {
18
- return 1 * direction;
19
- }
20
-
21
- if (value < otherValue) {
22
- return -1 * direction;
23
- }
24
-
25
- if (value > otherValue) {
26
- return 1 * direction;
27
- }
28
-
29
- return 0;
30
- });
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 DELETED
@@ -1,8 +0,0 @@
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 DELETED
@@ -1,29 +0,0 @@
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 DELETED
@@ -1,20 +0,0 @@
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
- "angularCompilerOptions": {
11
- "compilationMode": "partial"
12
- },
13
- "exclude": [
14
- "src/**/*.spec.ts",
15
- "src/test-setup.ts",
16
- "jest.config.ts",
17
- "src/**/*.test.ts"
18
- ],
19
- "include": ["src/**/*.ts"]
20
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.lib.json",
3
- "compilerOptions": {
4
- "declarationMap": false
5
- },
6
- "angularCompilerOptions": {
7
- "compilationMode": "partial"
8
- }
9
- }
@@ -1,16 +0,0 @@
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
- }