@verisoft/core 20.1.1 → 20.1.3
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/fesm2022/verisoft-core.mjs +465 -0
- package/fesm2022/verisoft-core.mjs.map +1 -0
- package/index.d.ts +135 -0
- package/package.json +16 -2
- package/.eslintrc.json +0 -43
- package/jest.config.ts +0 -22
- package/ng-package.json +0 -7
- package/project.json +0 -36
- package/src/index.ts +0 -3
- package/src/lib/index.ts +0 -1
- package/src/lib/models/all-item.datasource.ts +0 -5
- package/src/lib/models/base-http.models.ts +0 -144
- package/src/lib/models/constants.ts +0 -8
- package/src/lib/models/datasource.model.ts +0 -77
- package/src/lib/models/environment.model.ts +0 -5
- package/src/lib/models/error-provider.model.ts +0 -20
- package/src/lib/models/event.models.ts +0 -7
- package/src/lib/models/index.ts +0 -7
- package/src/lib/services/base-http.service.ts +0 -114
- package/src/lib/services/error-provider.service.ts +0 -33
- package/src/lib/services/index.ts +0 -3
- package/src/lib/services/local-storage.service.ts +0 -13
- package/src/lib/services/storage.service.ts +0 -13
- package/src/lib/utils/array.utils.spec.ts +0 -49
- package/src/lib/utils/array.utils.ts +0 -54
- package/src/lib/utils/clear.utils.ts +0 -53
- package/src/lib/utils/data.utils.ts +0 -34
- package/src/lib/utils/date.utils.ts +0 -30
- package/src/lib/utils/index.ts +0 -6
- package/src/lib/utils/keyOrFn.utils.ts +0 -15
- package/src/lib/utils/object.utils.spec.ts +0 -69
- package/src/lib/utils/object.utils.ts +0 -47
- package/src/test-setup.ts +0 -8
- package/tsconfig.json +0 -29
- package/tsconfig.lib.json +0 -17
- package/tsconfig.lib.prod.json +0 -9
- package/tsconfig.spec.json +0 -16
package/index.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { HttpParams, HttpResponse, HttpClient } from '@angular/common/http';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { InjectionToken } from '@angular/core';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
import { ValidationErrors } from '@angular/forms';
|
|
6
|
+
|
|
7
|
+
interface EnvironmentConfig {
|
|
8
|
+
production: boolean;
|
|
9
|
+
apiUrl: string;
|
|
10
|
+
appVersion: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare const BASE_URL_PATH: InjectionToken<string>;
|
|
14
|
+
declare function requestParamsToHttpParams<T>(requestParams: Partial<RequestParams<T>>, httpParams?: HttpParams): HttpParams;
|
|
15
|
+
declare function saveFile(response: HttpResponse<Blob>): void;
|
|
16
|
+
declare enum SortDirection {
|
|
17
|
+
asc = "asc",
|
|
18
|
+
desc = "desc"
|
|
19
|
+
}
|
|
20
|
+
declare type SortDirectionType = keyof typeof SortDirection;
|
|
21
|
+
declare interface Sort {
|
|
22
|
+
field: string;
|
|
23
|
+
direction: SortDirectionType;
|
|
24
|
+
}
|
|
25
|
+
interface RequestParams<T> extends AllDataRequestParams<T> {
|
|
26
|
+
offset: number;
|
|
27
|
+
limit: number;
|
|
28
|
+
id?: string;
|
|
29
|
+
}
|
|
30
|
+
interface AllDataRequestParams<T> {
|
|
31
|
+
filter?: Partial<T>;
|
|
32
|
+
sort?: Sort[];
|
|
33
|
+
}
|
|
34
|
+
interface Page<T> {
|
|
35
|
+
data: T[];
|
|
36
|
+
total: number;
|
|
37
|
+
limit: number;
|
|
38
|
+
offset: number;
|
|
39
|
+
}
|
|
40
|
+
interface CustomExport<T> {
|
|
41
|
+
sortDefinition?: Sort;
|
|
42
|
+
filter?: Partial<T>;
|
|
43
|
+
columnsToExport: ColumnExportSpecification[];
|
|
44
|
+
}
|
|
45
|
+
interface ColumnExportSpecification {
|
|
46
|
+
name: string;
|
|
47
|
+
header: string;
|
|
48
|
+
}
|
|
49
|
+
declare const DEFAULT_SEARCH_LIMIT = 50;
|
|
50
|
+
declare const DEFAULT_SEARCH_PARAMS: RequestParams<any>;
|
|
51
|
+
declare function normalizeRequest<T>(request: Partial<RequestParams<T>>, minLimit?: number | undefined): RequestParams<T>;
|
|
52
|
+
|
|
53
|
+
type LazyLoadEvent = RequestParams<unknown>;
|
|
54
|
+
interface FilterEvent {
|
|
55
|
+
filter?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare const DEFAULT_PAGE_SIZE = 50;
|
|
59
|
+
declare const DEFAULT_LAZYLOAD_OPTIONS: LazyLoadEvent;
|
|
60
|
+
|
|
61
|
+
interface AllItemDatasource<T> {
|
|
62
|
+
getData$: () => Observable<T[]>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare class BaseHttpService<T, TKey = number | string> {
|
|
66
|
+
readonly http: HttpClient;
|
|
67
|
+
readonly basePath: string;
|
|
68
|
+
readonly entityName: string;
|
|
69
|
+
constructor(http: HttpClient, basePath: string, entityName: string);
|
|
70
|
+
protected get apiPath(): string;
|
|
71
|
+
fetchList(requestParams: RequestParams<T>): Observable<Page<T>>;
|
|
72
|
+
getData$(entityName: keyof T, searchTerm?: string | undefined, lazyLoad?: LazyLoadEvent): Observable<T[]>;
|
|
73
|
+
get(id: TKey): Observable<T>;
|
|
74
|
+
post(entity: Partial<T>): Observable<T>;
|
|
75
|
+
put(id: TKey, entity: Partial<T>): Observable<T>;
|
|
76
|
+
delete(id: TKey): Observable<T>;
|
|
77
|
+
export(requestParams: AllDataRequestParams<T>): Observable<Blob>;
|
|
78
|
+
removeRange(entity: string[]): Observable<Object>;
|
|
79
|
+
createParams<T>(requestParams: RequestParams<T>): any;
|
|
80
|
+
private createSorter;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
type DatasourceType<T> = string | Observable<T[]> | Observable<Page<T>> | BaseHttpService<T> | T[] | Page<T> | AllItemDatasource<T>;
|
|
84
|
+
type DataSourceFunctionType<T> = (requestParams: RequestParams<T>) => Observable<Page<T>>;
|
|
85
|
+
declare function convertDatasource<T>(datasource: DatasourceType<T>, basePath: string, httpClient: HttpClient): DataSourceFunctionType<T>;
|
|
86
|
+
|
|
87
|
+
interface ErrorProvider {
|
|
88
|
+
mapError(errors: ValidationErrors): Observable<string | undefined>;
|
|
89
|
+
errors: Record<string, (value?: any) => string>;
|
|
90
|
+
}
|
|
91
|
+
declare const ERROR_PROVIDER_TOKEN: InjectionToken<ErrorProvider>;
|
|
92
|
+
declare enum CustomValidationCodes {
|
|
93
|
+
}
|
|
94
|
+
declare const ErrorMap: Record<string, (value?: any) => string>;
|
|
95
|
+
|
|
96
|
+
declare class LocalStorageService {
|
|
97
|
+
setItem(key: string, value: string): void;
|
|
98
|
+
getItem(key: string): string | null;
|
|
99
|
+
removeItem(key: string): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
declare class LocalizableErrorProviderService implements ErrorProvider {
|
|
103
|
+
private readonly translateService;
|
|
104
|
+
readonly errors: Record<string, (value?: any) => string>;
|
|
105
|
+
mapError(errors: ValidationErrors): Observable<string | undefined>;
|
|
106
|
+
private getFirstValue;
|
|
107
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LocalizableErrorProviderService, never>;
|
|
108
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<LocalizableErrorProviderService>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
declare class ClearUtils {
|
|
112
|
+
static recursiveObjectAttributesTransformation(obj: any): void;
|
|
113
|
+
static recursiveObjectAttributesDeletation(obj: any): void;
|
|
114
|
+
static transformEmptyStringToNullStringFn(obj: any, key: string): void;
|
|
115
|
+
static deleteEmptyStringToNullStringFn(obj: any, key: string): void;
|
|
116
|
+
static recursiveObjectAttributesTraversal(obj: any, transformationFn: (obj: any, key: string) => void): void;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
declare function keyOrFn(keyOrFn: ((row: any) => string | undefined) | string, row: any): any;
|
|
120
|
+
|
|
121
|
+
type ArrayIntersectionType = (string | number)[];
|
|
122
|
+
declare function isArrayIntersected(array1: ArrayIntersectionType, array2: ArrayIntersectionType): boolean;
|
|
123
|
+
declare function multiSort<T>(values: T[], sorts: Sort[]): T[];
|
|
124
|
+
|
|
125
|
+
declare function transformData(data: any): any;
|
|
126
|
+
declare function convertToDate(data: any): any;
|
|
127
|
+
declare function convertToDateTime(data: any): any;
|
|
128
|
+
|
|
129
|
+
declare function sortBy<TEntity, TProperty>(items: TEntity[], selector: (item: TEntity) => TProperty, ascending?: boolean): TEntity[];
|
|
130
|
+
declare function getValueByPath<T, TValue>(obj: T, path: string | undefined): TValue | undefined;
|
|
131
|
+
|
|
132
|
+
declare function toCzechDateTimeString(value?: Date | string, time?: boolean): string;
|
|
133
|
+
|
|
134
|
+
export { BASE_URL_PATH, BaseHttpService, ClearUtils, CustomValidationCodes, DEFAULT_LAZYLOAD_OPTIONS, DEFAULT_PAGE_SIZE, DEFAULT_SEARCH_LIMIT, DEFAULT_SEARCH_PARAMS, ERROR_PROVIDER_TOKEN, ErrorMap, LocalStorageService, LocalizableErrorProviderService, SortDirection, convertDatasource, convertToDate, convertToDateTime, getValueByPath, isArrayIntersected, keyOrFn, multiSort, normalizeRequest, requestParamsToHttpParams, saveFile, sortBy, toCzechDateTimeString, transformData };
|
|
135
|
+
export type { AllDataRequestParams, AllItemDatasource, ColumnExportSpecification, CustomExport, DataSourceFunctionType, DatasourceType, EnvironmentConfig, ErrorProvider, FilterEvent, LazyLoadEvent, Page, RequestParams, Sort, SortDirectionType };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verisoft/core",
|
|
3
|
-
"version": "20.1.
|
|
3
|
+
"version": "20.1.3",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@angular/common": "~20.2.0",
|
|
@@ -9,5 +9,19 @@
|
|
|
9
9
|
"@ngx-translate/core": "^17.0.0",
|
|
10
10
|
"moment": "^2.30.1",
|
|
11
11
|
"rxjs": "~7.8.0"
|
|
12
|
+
},
|
|
13
|
+
"module": "fesm2022/verisoft-core.mjs",
|
|
14
|
+
"typings": "index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
"./package.json": {
|
|
17
|
+
"default": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"default": "./fesm2022/verisoft-core.mjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"tslib": "^2.3.0"
|
|
12
26
|
}
|
|
13
|
-
}
|
|
27
|
+
}
|
package/.eslintrc.json
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["../../../.eslintrc.base.json"],
|
|
3
|
-
"ignorePatterns": ["!**/*"],
|
|
4
|
-
"overrides": [
|
|
5
|
-
{
|
|
6
|
-
"files": ["*.ts"],
|
|
7
|
-
"extends": [
|
|
8
|
-
"plugin:@nx/angular",
|
|
9
|
-
"plugin:@angular-eslint/template/process-inline-templates"
|
|
10
|
-
],
|
|
11
|
-
"rules": {
|
|
12
|
-
"@angular-eslint/directive-selector": [
|
|
13
|
-
"error",
|
|
14
|
-
{
|
|
15
|
-
"type": "attribute",
|
|
16
|
-
"prefix": "v",
|
|
17
|
-
"style": "camelCase"
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
"@angular-eslint/component-selector": [
|
|
21
|
-
"error",
|
|
22
|
-
{
|
|
23
|
-
"type": "element",
|
|
24
|
-
"prefix": "v",
|
|
25
|
-
"style": "kebab-case"
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"files": ["*.html"],
|
|
32
|
-
"extends": ["plugin:@nx/angular-template"],
|
|
33
|
-
"rules": {}
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"files": ["*.json"],
|
|
37
|
-
"parser": "jsonc-eslint-parser",
|
|
38
|
-
"rules": {
|
|
39
|
-
"@nx/dependency-checks": "error"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
]
|
|
43
|
-
}
|
package/jest.config.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
export default {
|
|
3
|
-
displayName: 'core',
|
|
4
|
-
preset: '../../../jest.preset.js',
|
|
5
|
-
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
|
6
|
-
coverageDirectory: '../../../coverage/src/libs/core',
|
|
7
|
-
transform: {
|
|
8
|
-
'^.+\\.(ts|mjs|js|html)$': [
|
|
9
|
-
'jest-preset-angular',
|
|
10
|
-
{
|
|
11
|
-
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
12
|
-
stringifyContentPathRegex: '\\.(html|svg)$',
|
|
13
|
-
},
|
|
14
|
-
],
|
|
15
|
-
},
|
|
16
|
-
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
|
17
|
-
snapshotSerializers: [
|
|
18
|
-
'jest-preset-angular/build/serializers/no-ng-attributes',
|
|
19
|
-
'jest-preset-angular/build/serializers/ng-snapshot',
|
|
20
|
-
'jest-preset-angular/build/serializers/html-comment',
|
|
21
|
-
],
|
|
22
|
-
};
|
package/ng-package.json
DELETED
package/project.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "core",
|
|
3
|
-
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "src/libs/core/src",
|
|
5
|
-
"prefix": "lib",
|
|
6
|
-
"projectType": "library",
|
|
7
|
-
"tags": [],
|
|
8
|
-
"targets": {
|
|
9
|
-
"build": {
|
|
10
|
-
"executor": "@nx/angular:package",
|
|
11
|
-
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
|
|
12
|
-
"options": {
|
|
13
|
-
"project": "src/libs/core/ng-package.json"
|
|
14
|
-
},
|
|
15
|
-
"configurations": {
|
|
16
|
-
"production": {
|
|
17
|
-
"tsConfig": "src/libs/core/tsconfig.lib.prod.json"
|
|
18
|
-
},
|
|
19
|
-
"development": {
|
|
20
|
-
"tsConfig": "src/libs/core/tsconfig.lib.json"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"defaultConfiguration": "production"
|
|
24
|
-
},
|
|
25
|
-
"test": {
|
|
26
|
-
"executor": "@nx/jest:jest",
|
|
27
|
-
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
28
|
-
"options": {
|
|
29
|
-
"jestConfig": "src/libs/core/jest.config.ts"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"lint": {
|
|
33
|
-
"executor": "@nx/eslint:lint"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
package/src/index.ts
DELETED
package/src/lib/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './models';
|
|
@@ -1,144 +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<string>('BASE_URL_PATH');
|
|
6
|
-
|
|
7
|
-
export function requestParamsToHttpParams<T>(
|
|
8
|
-
requestParams: Partial<RequestParams<T>>,
|
|
9
|
-
httpParams: HttpParams = new HttpParams()
|
|
10
|
-
): HttpParams {
|
|
11
|
-
if (requestParams.limit != undefined) {
|
|
12
|
-
httpParams = httpParams.append('limit', requestParams.limit.toString());
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (requestParams.offset != undefined) {
|
|
16
|
-
httpParams = httpParams.append('offset', requestParams.offset.toString());
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (requestParams.id != '' && requestParams.id != undefined) {
|
|
20
|
-
httpParams = httpParams.append('id', requestParams.id as any);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
httpParams = getFilter(requestParams, httpParams);
|
|
24
|
-
httpParams = getSort(requestParams, httpParams);
|
|
25
|
-
|
|
26
|
-
return httpParams;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getFilter<T>(
|
|
30
|
-
requestParams: Partial<RequestParams<any>>,
|
|
31
|
-
httpParams: HttpParams
|
|
32
|
-
): HttpParams {
|
|
33
|
-
if (!requestParams.filter) {
|
|
34
|
-
return httpParams;
|
|
35
|
-
}
|
|
36
|
-
Object.keys(requestParams?.filter).forEach((key) => {
|
|
37
|
-
const value = requestParams.filter?.[key as keyof Partial<T>];
|
|
38
|
-
if (value != undefined && !(typeof value === 'string' && value.trim() === "")) {
|
|
39
|
-
if (Array.isArray(value)) {
|
|
40
|
-
value.forEach((valueItem: any) => {
|
|
41
|
-
httpParams = httpParams.append(
|
|
42
|
-
'Filter.' + key, valueItem
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
httpParams = httpParams.append('Filter.' + key, value);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return httpParams;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getSort(
|
|
54
|
-
requestParams: Partial<RequestParams<any>>,
|
|
55
|
-
httpParams: HttpParams
|
|
56
|
-
): HttpParams {
|
|
57
|
-
if (!requestParams.sort) {
|
|
58
|
-
return httpParams;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
requestParams.sort?.forEach((sort) => {
|
|
62
|
-
httpParams = httpParams
|
|
63
|
-
.append('Sort.Field', sort.field)
|
|
64
|
-
.append('Sort.Direction', sort.direction);
|
|
65
|
-
});
|
|
66
|
-
return httpParams;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function saveFile(response: HttpResponse<Blob>) {
|
|
70
|
-
const fileName = response.headers
|
|
71
|
-
.get('Content-Disposition')
|
|
72
|
-
?.split(';')[1]
|
|
73
|
-
.split('=')[1];
|
|
74
|
-
const blob: Blob = response.body as Blob;
|
|
75
|
-
const a = document.createElement('a');
|
|
76
|
-
a.download = fileName ?? 'undefined';
|
|
77
|
-
a.href = window.URL.createObjectURL(blob);
|
|
78
|
-
a.click();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export enum SortDirection {
|
|
82
|
-
asc = 'asc',
|
|
83
|
-
desc = 'desc',
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export declare type SortDirectionType = keyof typeof SortDirection;
|
|
87
|
-
|
|
88
|
-
export declare interface Sort {
|
|
89
|
-
field: string;
|
|
90
|
-
direction: SortDirectionType;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface RequestParams<T> extends AllDataRequestParams<T> {
|
|
94
|
-
offset: number;
|
|
95
|
-
limit: number;
|
|
96
|
-
id?: string;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface AllDataRequestParams<T> {
|
|
100
|
-
filter?: Partial<T>;
|
|
101
|
-
sort?: Sort[];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface Page<T> {
|
|
105
|
-
data: T[];
|
|
106
|
-
total: number;
|
|
107
|
-
limit: number;
|
|
108
|
-
offset: number;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export interface CustomExport<T> {
|
|
112
|
-
sortDefinition?: Sort;
|
|
113
|
-
filter?: Partial<T>;
|
|
114
|
-
columnsToExport: ColumnExportSpecification[];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export interface ColumnExportSpecification {
|
|
118
|
-
name: string;
|
|
119
|
-
header: string;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export const DEFAULT_SEARCH_LIMIT = 50;
|
|
123
|
-
|
|
124
|
-
export const DEFAULT_SEARCH_PARAMS: RequestParams<any> = {
|
|
125
|
-
offset: 0,
|
|
126
|
-
limit: DEFAULT_SEARCH_LIMIT,
|
|
127
|
-
id: '',
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export function normalizeRequest<T>(
|
|
131
|
-
request: Partial<RequestParams<T>>,
|
|
132
|
-
minLimit: number | undefined = undefined
|
|
133
|
-
): RequestParams<T> {
|
|
134
|
-
return {
|
|
135
|
-
offset: request?.offset ?? 0,
|
|
136
|
-
limit: !request?.limit
|
|
137
|
-
? DEFAULT_SEARCH_LIMIT
|
|
138
|
-
: minLimit && request.limit < minLimit
|
|
139
|
-
? minLimit
|
|
140
|
-
: request.limit,
|
|
141
|
-
filter: request?.filter,
|
|
142
|
-
sort: request?.sort,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { HttpClient } from '@angular/common/http';
|
|
2
|
-
import { isObservable, map, Observable, of } from 'rxjs';
|
|
3
|
-
import { BaseHttpService } from '../services/base-http.service';
|
|
4
|
-
import { AllItemDatasource } from './all-item.datasource';
|
|
5
|
-
import { Page, RequestParams } from './base-http.models';
|
|
6
|
-
import { DEFAULT_PAGE_SIZE } from './constants';
|
|
7
|
-
|
|
8
|
-
export type DatasourceType<T> =
|
|
9
|
-
| string
|
|
10
|
-
| Observable<T[]>
|
|
11
|
-
| Observable<Page<T>>
|
|
12
|
-
| BaseHttpService<T>
|
|
13
|
-
| T[]
|
|
14
|
-
| Page<T>
|
|
15
|
-
| AllItemDatasource<T>;
|
|
16
|
-
|
|
17
|
-
export type DataSourceFunctionType<T> = (
|
|
18
|
-
requestParams: RequestParams<T>
|
|
19
|
-
) => Observable<Page<T>>;
|
|
20
|
-
|
|
21
|
-
export function convertDatasource<T>(
|
|
22
|
-
datasource: DatasourceType<T>,
|
|
23
|
-
basePath: string,
|
|
24
|
-
httpClient: HttpClient
|
|
25
|
-
): DataSourceFunctionType<T> {
|
|
26
|
-
if (!datasource) {
|
|
27
|
-
throw new Error('Datasource is not defined');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (typeof datasource === 'string') {
|
|
31
|
-
const service = new BaseHttpService<T>(httpClient, basePath, datasource);
|
|
32
|
-
return (requestParams: RequestParams<T>) =>
|
|
33
|
-
service.fetchList(requestParams);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (datasource instanceof BaseHttpService) {
|
|
37
|
-
return (requestParams: RequestParams<T>) =>
|
|
38
|
-
datasource.fetchList(requestParams);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (isObservable(datasource)) {
|
|
42
|
-
return () =>
|
|
43
|
-
(datasource as Observable<Page<T> | T[]>).pipe(map(convertArrayToPage));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const allItemDatasource = <AllItemDatasource<T>>datasource;
|
|
47
|
-
if (allItemDatasource.getData$) {
|
|
48
|
-
return () =>
|
|
49
|
-
allItemDatasource
|
|
50
|
-
.getData$()
|
|
51
|
-
.pipe(map((data) => convertArrayToPage(data)));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const page = <Page<T>>datasource;
|
|
55
|
-
if (page.data) {
|
|
56
|
-
return () => of(page);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (Array.isArray(datasource)) {
|
|
60
|
-
return () => of(convertArrayToPage(datasource));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
throw new Error('Datasource is not supported');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function convertArrayToPage<T>(data: Page<T> | T[]): Page<T> {
|
|
67
|
-
if (Array.isArray(data)) {
|
|
68
|
-
return {
|
|
69
|
-
data: data ?? [],
|
|
70
|
-
total: data?.length ?? 0,
|
|
71
|
-
limit: data?.length ?? DEFAULT_PAGE_SIZE,
|
|
72
|
-
offset: 0,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return data as Page<T>;
|
|
77
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { InjectionToken } from '@angular/core';
|
|
2
|
-
import { ValidationErrors } from '@angular/forms';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
|
|
5
|
-
export interface ErrorProvider {
|
|
6
|
-
mapError(errors: ValidationErrors): Observable<string | undefined>;
|
|
7
|
-
errors: Record<string, (value?: any) => string>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const ERROR_PROVIDER_TOKEN
|
|
11
|
-
= new InjectionToken<ErrorProvider>('ERROR_PROVIDER_TOKEN');
|
|
12
|
-
|
|
13
|
-
export enum CustomValidationCodes {}
|
|
14
|
-
|
|
15
|
-
export const ErrorMap: Record<string, (value?: any) => string> = {
|
|
16
|
-
required: () => `VALIDATIONS.REQUIRED`,
|
|
17
|
-
email: () => `VALIDATIONS.EMAIL`,
|
|
18
|
-
minLength: () => 'VALIDATIONS.MIN_LENGTH',
|
|
19
|
-
maxLength: () => 'VALIDATIONS.MAX_LENGTH',
|
|
20
|
-
};
|
package/src/lib/models/index.ts
DELETED
|
@@ -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
|
-
}
|