@sankhyalabs/core 5.20.0-dev.7 → 5.20.0-dev.71
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/.docs/classes/Change.md +11 -11
- package/.docs/classes/ColumnFilterManager.md +145 -0
- package/.docs/classes/DataUnit.md +405 -137
- package/.docs/classes/DataUnitInMemoryLoader.md +303 -0
- package/.docs/classes/DataUnitLoaderUtils.md +151 -0
- package/.docs/classes/DateUtils.md +8 -8
- package/.docs/classes/FieldComparator.md +2 -2
- package/.docs/classes/IDBRepository.md +22 -0
- package/.docs/classes/LockManager.md +249 -0
- package/.docs/classes/MaskFormatter.md +66 -14
- package/.docs/classes/ObjectUtils.md +141 -0
- package/.docs/classes/OverflowWatcher.md +533 -0
- package/.docs/classes/SelectionInfo.md +25 -11
- package/.docs/classes/ServiceCanceledException.md +193 -0
- package/.docs/classes/ServiceUtils.md +67 -0
- package/.docs/classes/SilentException.md +193 -0
- package/.docs/classes/UserAgentUtils.md +15 -1
- package/.docs/enumerations/Action.md +41 -21
- package/.docs/enumerations/ChangeOperation.md +4 -4
- package/.docs/enumerations/LockManagerOperation.md +33 -0
- package/.docs/enumerations/OverflowDirection.md +29 -0
- package/.docs/enumerations/RECORD_DATE_FORMAT.md +27 -0
- package/.docs/enumerations/SelectionMode.md +2 -2
- package/.docs/enumerations/StorageType.md +37 -0
- package/.docs/globals.md +24 -0
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/DataUnitInMemoryLoaderConfig.md +37 -0
- package/.docs/interfaces/IRepository.md +18 -0
- package/.docs/interfaces/LoadDataRequest.md +1 -1
- package/.docs/interfaces/OverFlowWatcherParams.md +67 -0
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/PaginationInfo.md +25 -0
- package/.docs/interfaces/PaginationInfoBuilderParams.md +37 -0
- package/.docs/interfaces/QuickFilter.md +3 -3
- package/.docs/interfaces/Record.md +4 -4
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +1 -1
- package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +1 -1
- package/.docs/type-aliases/DataUnitEventOptions.md +17 -0
- package/.docs/type-aliases/OnOverflowCallBack.md +25 -0
- package/.docs/variables/OVERFLOWED_CLASS_NAME.md +13 -0
- package/.releaserc +1 -0
- package/bun.lockb +0 -0
- package/dist/dataunit/DataUnit.d.ts +82 -12
- package/dist/dataunit/DataUnit.js +209 -67
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/DataUnitHelper.js +6 -5
- package/dist/dataunit/DataUnitHelper.js.map +1 -1
- package/dist/dataunit/formatting/PrettyFormatter.js +14 -6
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.d.ts +9 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js +6 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js.map +1 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.d.ts +25 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js +131 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js.map +1 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +20 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js +62 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -0
- package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
- package/dist/dataunit/loading/PaginationInfo.d.ts +8 -0
- package/dist/dataunit/metadata/DataType.js +3 -0
- package/dist/dataunit/metadata/DataType.js.map +1 -1
- package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
- package/dist/dataunit/sorting/FieldComparator.js +4 -9
- package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
- package/dist/dataunit/state/action/DataUnitAction.d.ts +2 -0
- package/dist/dataunit/state/action/DataUnitAction.js +2 -0
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- package/dist/dataunit/state/slice/InvalidFieldsSlice.js +2 -0
- package/dist/dataunit/state/slice/InvalidFieldsSlice.js.map +1 -1
- package/dist/dataunit/state/slice/LoadingControlSlice.js +16 -0
- package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SelectionSlice.js +4 -4
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
- package/dist/exceptions/ServiceCanceledException.d.ts +14 -0
- package/dist/exceptions/ServiceCanceledException.js +13 -0
- package/dist/exceptions/ServiceCanceledException.js.map +1 -0
- package/dist/exceptions/SilentException.d.ts +14 -0
- package/dist/exceptions/SilentException.js +13 -0
- package/dist/exceptions/SilentException.js.map +1 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/repository/IRepository.d.ts +6 -0
- package/dist/repository/indexeddb/IDBRepository.d.ts +1 -0
- package/dist/repository/indexeddb/IDBRepository.js +3 -0
- package/dist/repository/indexeddb/IDBRepository.js.map +1 -1
- package/dist/utils/CacheManager/index.d.ts +52 -0
- package/dist/utils/CacheManager/index.js +101 -0
- package/dist/utils/CacheManager/index.js.map +1 -0
- package/dist/utils/CacheManager/interfaces/index.d.ts +5 -0
- package/dist/utils/CacheManager/interfaces/index.js +7 -0
- package/dist/utils/CacheManager/interfaces/index.js.map +1 -0
- package/dist/utils/ColumnFilterManager.d.ts +19 -0
- package/dist/utils/ColumnFilterManager.js +73 -0
- package/dist/utils/ColumnFilterManager.js.map +1 -0
- package/dist/utils/DateUtils.js +3 -0
- package/dist/utils/DateUtils.js.map +1 -1
- package/dist/utils/ElementUtils.d.ts +2 -0
- package/dist/utils/ElementUtils.js +9 -0
- package/dist/utils/ElementUtils.js.map +1 -0
- package/dist/utils/LockManager.d.ts +58 -0
- package/dist/utils/LockManager.js +191 -0
- package/dist/utils/LockManager.js.map +1 -0
- package/dist/utils/MaskFormatter.d.ts +16 -1
- package/dist/utils/MaskFormatter.js +82 -2
- package/dist/utils/MaskFormatter.js.map +1 -1
- package/dist/utils/ObjectUtils.d.ts +38 -0
- package/dist/utils/ObjectUtils.js +51 -0
- package/dist/utils/ObjectUtils.js.map +1 -1
- package/dist/utils/OnboardingUtils.js +1 -1
- package/dist/utils/OnboardingUtils.js.map +1 -1
- package/dist/utils/OverflowWatcher/index.d.ts +59 -0
- package/dist/utils/OverflowWatcher/index.js +188 -0
- package/dist/utils/OverflowWatcher/index.js.map +1 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.d.ts +6 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.js +2 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.js.map +1 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.d.ts +7 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.js +9 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.js.map +1 -0
- package/dist/utils/ServiceUtils.d.ts +24 -0
- package/dist/utils/ServiceUtils.js +40 -0
- package/dist/utils/ServiceUtils.js.map +1 -0
- package/dist/utils/SortingUtils.d.ts +9 -0
- package/dist/utils/SortingUtils.js +24 -0
- package/dist/utils/SortingUtils.js.map +1 -0
- package/dist/utils/UserAgentUtils/index.d.ts +1 -0
- package/dist/utils/UserAgentUtils/index.js +5 -0
- package/dist/utils/UserAgentUtils/index.js.map +1 -1
- package/jest.config.ts +2 -0
- package/package.json +2 -1
- package/reports/test-report.xml +215 -0
- package/setupTests.js +7 -0
- package/sonar-project.properties +6 -3
- package/src/dataunit/DataUnit.ts +250 -82
- package/src/dataunit/DataUnitHelper.ts +6 -5
- package/src/dataunit/formatting/PrettyFormatter.ts +15 -6
- package/src/dataunit/loader/DataUnitInMemoryLoaderConfig.ts +10 -0
- package/src/dataunit/loader/dataUnitInMemoryLoader.ts +176 -0
- package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +86 -0
- package/src/dataunit/loading/LoadDataRequest.ts +1 -1
- package/src/dataunit/loading/PaginationInfo.ts +10 -0
- package/src/dataunit/metadata/DataType.ts +3 -0
- package/src/dataunit/sorting/FieldComparator.ts +18 -32
- package/src/dataunit/state/action/DataUnitAction.ts +2 -0
- package/src/dataunit/state/slice/InvalidFieldsSlice.ts +2 -0
- package/src/dataunit/state/slice/LoadingControlSlice.ts +42 -0
- package/src/dataunit/state/slice/RecordsSlice.ts +1 -1
- package/src/dataunit/state/slice/SelectionSlice.ts +4 -4
- package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +45 -0
- package/src/dataunit/test/DataUnit.spec.ts +44 -0
- package/src/exceptions/ServiceCanceledException.ts +25 -0
- package/src/exceptions/SilentException.ts +25 -0
- package/src/index.ts +29 -1
- package/src/repository/IRepository.ts +7 -0
- package/src/repository/indexeddb/IDBRepository.ts +4 -0
- package/src/utils/CacheManager/index.ts +103 -0
- package/src/utils/CacheManager/interfaces/index.ts +5 -0
- package/src/utils/ColumnFilterManager.ts +104 -0
- package/src/utils/DateUtils.ts +3 -0
- package/src/utils/ElementUtils.ts +10 -0
- package/src/utils/LockManager.ts +213 -0
- package/src/utils/MaskFormatter.ts +93 -2
- package/src/utils/ObjectUtils.ts +56 -0
- package/src/utils/OnboardingUtils.ts +1 -1
- package/src/utils/OverflowWatcher/index.ts +243 -0
- package/src/utils/OverflowWatcher/types/overflow-callback.ts +6 -0
- package/src/utils/OverflowWatcher/types/overflow-direction.ts +7 -0
- package/src/utils/ServiceUtils.ts +36 -0
- package/src/utils/SortingUtils.ts +30 -0
- package/src/utils/UserAgentUtils/index.ts +6 -1
- package/src/utils/test/objectUtils.spec.ts +109 -0
- package/test/dataunit/formatting/PrettyFormatter.spec.ts +177 -0
- package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +221 -0
- package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +158 -0
- package/test/util/ColumnFilterManager.spec.ts +133 -0
- package/test/util/ElementUtils.spec.ts +34 -0
- package/test/util/OverflowWatcher.spec.ts +152 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import DataUnit from '../DataUnit';
|
|
2
|
+
import { Action } from '../state/action/DataUnitAction';
|
|
3
|
+
|
|
4
|
+
describe('DataUnit', () => {
|
|
5
|
+
|
|
6
|
+
let dataUnit: DataUnit;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
dataUnit = new DataUnit();
|
|
10
|
+
|
|
11
|
+
dataUnit['dispatchAction'] = jest.fn();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should return false when not waiting to reload', () => {
|
|
15
|
+
expect(dataUnit.isWaitingToReload()).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should set waitingToReload to true', () => {
|
|
19
|
+
dataUnit.setWaitingToReload(true);
|
|
20
|
+
expect(dataUnit.isWaitingToReload()).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should set waitingToReload to false', () => {
|
|
24
|
+
dataUnit.setWaitingToReload(true);
|
|
25
|
+
dataUnit.setWaitingToReload(false);
|
|
26
|
+
expect(dataUnit.isWaitingToReload()).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should dispatch SAVING_CANCELED action with correct fields and recordId', () => {
|
|
30
|
+
const fields = [
|
|
31
|
+
{ name: 'field1', message: 'error1' },
|
|
32
|
+
{ name: 'field2', message: 'error2' }
|
|
33
|
+
];
|
|
34
|
+
const recordId = '12345';
|
|
35
|
+
|
|
36
|
+
dataUnit.savingCanceled(fields, recordId);
|
|
37
|
+
|
|
38
|
+
expect(dataUnit['dispatchAction']).toHaveBeenCalledWith(
|
|
39
|
+
Action.SAVING_CANCELED,
|
|
40
|
+
{ fields, recordId },
|
|
41
|
+
undefined
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ServiceCanceledException`: Exceção lançada quando ocorre o cancelamento de um serviço.
|
|
3
|
+
*/
|
|
4
|
+
export default class ServiceCanceledException extends Error {
|
|
5
|
+
|
|
6
|
+
/** Nome da exceção. */
|
|
7
|
+
public name: string;
|
|
8
|
+
|
|
9
|
+
/** Titulo do erro. */
|
|
10
|
+
public title: string;
|
|
11
|
+
|
|
12
|
+
/** Descrição do erro. */
|
|
13
|
+
public message: string;
|
|
14
|
+
|
|
15
|
+
/** Código do erro, indica o erro disparado pelo backend. */
|
|
16
|
+
public errorCode: string;
|
|
17
|
+
|
|
18
|
+
constructor(title: string, message: string, errorCode: string = "") {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "Service Canceled";
|
|
21
|
+
this.title = title;
|
|
22
|
+
this.message = message;
|
|
23
|
+
this.errorCode = errorCode;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `SilentException`: Exceção lançada quando uma exception silenciosa é.
|
|
3
|
+
*/
|
|
4
|
+
export default class SilentException extends Error {
|
|
5
|
+
|
|
6
|
+
/** Nome da exceção. */
|
|
7
|
+
public name: string;
|
|
8
|
+
|
|
9
|
+
/** Titulo do erro. */
|
|
10
|
+
public title: string;
|
|
11
|
+
|
|
12
|
+
/** Descrição do erro. */
|
|
13
|
+
public message: string;
|
|
14
|
+
|
|
15
|
+
/** Código do erro, indica o erro disparado pelo backend. */
|
|
16
|
+
public errorCode: string;
|
|
17
|
+
|
|
18
|
+
constructor(title: string = "", message: string = "", errorCode: string = "") {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "SilentException";
|
|
21
|
+
this.title = title;
|
|
22
|
+
this.message = message;
|
|
23
|
+
this.errorCode = errorCode;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { HttpProvider } from "./http/HttpProvider.js";
|
|
|
9
9
|
import { SkwHttpProvider } from "./http/SkwHttpProvider.js";
|
|
10
10
|
import { RequestMetadata } from "./http/RequestMetadata.js";
|
|
11
11
|
import { AuthorizedServiceCaller } from "./http/AuthorizedServiceCaller.js";
|
|
12
|
-
import DataUnit, {SavedRecord, Record, Change, ChangeOperation, DUActionInterceptor, WaitingChange, PageRequest, QuickFilter, SelectionMode, SelectionInfo} from "./dataunit/DataUnit.js";
|
|
12
|
+
import DataUnit, {SavedRecord, Record, Change, ChangeOperation, DUActionInterceptor, WaitingChange, PageRequest, QuickFilter, SelectionMode, SelectionInfo, DataUnitEventOptions} from "./dataunit/DataUnit.js";
|
|
13
13
|
import { DataType } from "./dataunit/metadata/DataType.js";
|
|
14
14
|
import { UnitMetadata, FieldDescriptor, UserInterface, Sort, SortMode, SortingProvider, Filter, DependencyType, ChildDescriptor, ChildLink } from "./dataunit/metadata/UnitMetadata.js";
|
|
15
15
|
import { DataUnitAction, Action, ExecutionContext } from "./dataunit/state/action/DataUnitAction.js";
|
|
@@ -19,6 +19,8 @@ import ObjectUtils from "./utils/ObjectUtils.js";
|
|
|
19
19
|
import WarningException from "./exceptions/WarningException.js";
|
|
20
20
|
import WaitingChangeException from "./exceptions/WaitingChangeException.js";
|
|
21
21
|
import ErrorException from "./exceptions/ErrorException.js";
|
|
22
|
+
import ServiceCanceledException from "./exceptions/ServiceCanceledException.js";
|
|
23
|
+
import SilentException from "./exceptions/SilentException.js";
|
|
22
24
|
import { ErrorTracking } from "./traking/ErrorTraking.js";
|
|
23
25
|
import { PaginationInfo } from "./dataunit/loading/PaginationInfo.js";
|
|
24
26
|
import { LoadDataRequest } from "./dataunit/loading/LoadDataRequest.js";
|
|
@@ -39,9 +41,19 @@ import { IRepositoryIndex } from "./repository/indexeddb/IRepositoryIndex.js"
|
|
|
39
41
|
import { FieldComparator } from "./dataunit/sorting/FieldComparator.js";
|
|
40
42
|
import { KeyboardManager } from "./utils/KeyboardManager/index.js";
|
|
41
43
|
import { SearchUtils } from "./utils/SearchUtils.js";
|
|
44
|
+
import { ServiceUtils } from "./utils/ServiceUtils.js";
|
|
45
|
+
import { StorageType } from "./utils/CacheManager/index.js";
|
|
46
|
+
import OverflowWatcher, { OnOverflowCallBack, OverflowDirection, OverFlowWatcherParams, OVERFLOWED_CLASS_NAME } from "./utils/OverflowWatcher/index.js";
|
|
47
|
+
import {LockManager, LockManagerOperation} from "./utils/LockManager.js";
|
|
48
|
+
import { DataUnitInMemoryLoader } from "./dataunit/loader/dataUnitInMemoryLoader.js";
|
|
49
|
+
import { DataUnitLoaderUtils, PaginationInfoBuilderParams } from "./dataunit/loader/utils/dataUnitLoaderUtils.js";
|
|
50
|
+
import { ColumnFilterManager } from "./utils/ColumnFilterManager.js";
|
|
51
|
+
import { DataUnitInMemoryLoaderConfig, RECORD_DATE_FORMAT } from "./dataunit/loader/DataUnitInMemoryLoaderConfig.js";
|
|
42
52
|
|
|
43
53
|
/*Classes públicas no pacote*/
|
|
44
54
|
export {
|
|
55
|
+
LockManager,
|
|
56
|
+
LockManagerOperation,
|
|
45
57
|
StringUtils,
|
|
46
58
|
MaskFormatter,
|
|
47
59
|
NumberUtils,
|
|
@@ -106,4 +118,20 @@ export {
|
|
|
106
118
|
defaultDataLoader,
|
|
107
119
|
KeyboardManager,
|
|
108
120
|
SearchUtils,
|
|
121
|
+
ServiceUtils,
|
|
122
|
+
StorageType,
|
|
123
|
+
OverflowWatcher,
|
|
124
|
+
OnOverflowCallBack,
|
|
125
|
+
OverflowDirection,
|
|
126
|
+
OverFlowWatcherParams,
|
|
127
|
+
OVERFLOWED_CLASS_NAME,
|
|
128
|
+
DataUnitEventOptions,
|
|
129
|
+
ServiceCanceledException,
|
|
130
|
+
SilentException,
|
|
131
|
+
DataUnitInMemoryLoader,
|
|
132
|
+
DataUnitLoaderUtils,
|
|
133
|
+
PaginationInfoBuilderParams,
|
|
134
|
+
ColumnFilterManager,
|
|
135
|
+
DataUnitInMemoryLoaderConfig,
|
|
136
|
+
RECORD_DATE_FORMAT
|
|
109
137
|
};
|
|
@@ -79,4 +79,11 @@ export interface IRepository<T>{
|
|
|
79
79
|
* @returns Promessa de quantidade
|
|
80
80
|
*/
|
|
81
81
|
count(): Promise<number>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Retorna todos os registros que estão em cache no momento
|
|
85
|
+
*
|
|
86
|
+
* @returns Todos registros que estão em cache no momento
|
|
87
|
+
*/
|
|
88
|
+
getFromCache(): Array<T> | undefined
|
|
82
89
|
}
|
|
@@ -320,6 +320,10 @@ export class IDBRepository<T> implements IRepository<T>{
|
|
|
320
320
|
const tx = db.transaction(this._addedStoreName);
|
|
321
321
|
return tx.objectStore(this._addedStoreName).getAll();
|
|
322
322
|
}
|
|
323
|
+
|
|
324
|
+
public getFromCache(): Array<T> | undefined{
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
323
327
|
}
|
|
324
328
|
|
|
325
329
|
/**
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { StorageType } from './interfaces/index.js';
|
|
2
|
+
|
|
3
|
+
export * from "./interfaces/index.js";
|
|
4
|
+
|
|
5
|
+
export class CacheManager {
|
|
6
|
+
/**
|
|
7
|
+
* Nome da chave utilizada para armazenar o cache no armazenamento.
|
|
8
|
+
*/
|
|
9
|
+
private static readonly storageKey = 'cacheManager';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Estrutura de armazenamento em memória.
|
|
13
|
+
*/
|
|
14
|
+
private static inMemoryCache = new Map<string, any>();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Recupera ou define o valor no cache.
|
|
18
|
+
*
|
|
19
|
+
* @param key Identificador único para armazenar e recuperar o valor.
|
|
20
|
+
* @param fetchCallback Função que retorna uma `Promise` com o valor a ser armazenado no cache caso ele não exista ou tenha expirado.
|
|
21
|
+
* @param storageType Tipo de armazenamento: `'inMemoryCache'`, `'sessionStorage'` ou `'localStorage'`.
|
|
22
|
+
* @returns Uma `Promise` com o valor armazenado ou obtido via `fetchCallback`.
|
|
23
|
+
*/
|
|
24
|
+
public static async getOrSet<T>(
|
|
25
|
+
key: string,
|
|
26
|
+
fetchCallback: () => Promise<T>,
|
|
27
|
+
storageType: StorageType = StorageType.IN_MEMORY_CACHE
|
|
28
|
+
): Promise<T> {
|
|
29
|
+
const cache = this.getCache(storageType);
|
|
30
|
+
|
|
31
|
+
if (cache[key]) {
|
|
32
|
+
return cache[key].data;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const data = await fetchCallback();
|
|
36
|
+
cache[key] = { data };
|
|
37
|
+
this.saveCache(cache, storageType);
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Remove uma entrada específica do cache.
|
|
43
|
+
*
|
|
44
|
+
* @param key Identificador único da entrada a ser removida.
|
|
45
|
+
* @param storageType Tipo de armazenamento: `'inMemoryCache'`, `'sessionStorage'` ou `'localStorage'`.
|
|
46
|
+
*/
|
|
47
|
+
public static clear(key: string, storageType: StorageType = StorageType.IN_MEMORY_CACHE): void {
|
|
48
|
+
const cache = this.getCache(storageType);
|
|
49
|
+
delete cache[key];
|
|
50
|
+
this.saveCache(cache, storageType);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Remove todas as entradas do cache.
|
|
55
|
+
*
|
|
56
|
+
* @param storageType Tipo de armazenamento: `'inMemoryCache'`, `'sessionStorage'` ou `'localStorage'`.
|
|
57
|
+
*/
|
|
58
|
+
public static clearAll(storageType: StorageType = StorageType.IN_MEMORY_CACHE): void {
|
|
59
|
+
if (storageType === StorageType.IN_MEMORY_CACHE) {
|
|
60
|
+
this.inMemoryCache.clear();
|
|
61
|
+
} else {
|
|
62
|
+
this.getStorage(storageType).removeItem(this.storageKey);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Obtém o cache armazenado no armazenamento especificado.
|
|
68
|
+
* @param storageType Tipo de armazenamento: `'inMemoryCache'`, `'sessionStorage'` ou `'localStorage'`.
|
|
69
|
+
* @returns Um objeto representando o cache armazenado.
|
|
70
|
+
*/
|
|
71
|
+
private static getCache(storageType: StorageType): Record<string, any> {
|
|
72
|
+
if (storageType === StorageType.IN_MEMORY_CACHE) {
|
|
73
|
+
return Object.fromEntries(this.inMemoryCache);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const storage = this.getStorage(storageType);
|
|
77
|
+
const cache = storage.getItem(this.storageKey);
|
|
78
|
+
return cache ? JSON.parse(cache) : {};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Salva o cache no armazenamento especificado.
|
|
83
|
+
* @param cache O objeto representando o cache a ser salvo.
|
|
84
|
+
* @param storageType Tipo de armazenamento: `'inMemoryCache'`, `'sessionStorage'` ou `'localStorage'`.
|
|
85
|
+
*/
|
|
86
|
+
private static saveCache(cache: Record<string, any>, storageType: StorageType): void {
|
|
87
|
+
if (storageType === StorageType.IN_MEMORY_CACHE) {
|
|
88
|
+
this.inMemoryCache = new Map(Object.entries(cache));
|
|
89
|
+
} else {
|
|
90
|
+
const storage = this.getStorage(storageType);
|
|
91
|
+
storage.setItem(this.storageKey, JSON.stringify(cache));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Retorna o armazenamento correspondente ao tipo especificado.
|
|
97
|
+
* @param storageType Tipo de armazenamento: `'sessionStorage'` ou `'localStorage'`.
|
|
98
|
+
* @returns O objeto de armazenamento correspondente.
|
|
99
|
+
*/
|
|
100
|
+
private static getStorage(storageType: StorageType): Storage {
|
|
101
|
+
return storageType === StorageType.LOCAL_STORAGE ? localStorage : sessionStorage;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Filter } from '../dataunit/metadata/UnitMetadata.js';
|
|
2
|
+
import DataUnit, { Record } from '../dataunit/DataUnit.js';
|
|
3
|
+
import { FieldComparator } from '../dataunit/sorting/FieldComparator.js';
|
|
4
|
+
import { LoadDataRequest } from '../dataunit/loading/LoadDataRequest.js';
|
|
5
|
+
|
|
6
|
+
const COLUMN_FILTER_PATTERN = /FILTRO_COLUNA_(.+)/;
|
|
7
|
+
|
|
8
|
+
export class ColumnFilterManager {
|
|
9
|
+
|
|
10
|
+
public static getColumnFilters(filters: Array<Filter>, fieldName: string): Map<string, IColumnFilter> {
|
|
11
|
+
const columnFilters: Map<string, IColumnFilter> = new Map();
|
|
12
|
+
|
|
13
|
+
if (!filters?.length) {
|
|
14
|
+
return columnFilters;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
filters.forEach(filter => {
|
|
18
|
+
const result = COLUMN_FILTER_PATTERN.exec(filter.name);
|
|
19
|
+
if (result) {
|
|
20
|
+
if (fieldName !== result[1]) {
|
|
21
|
+
columnFilters.set(filter.name, { columnName: result[1], ...filter });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return columnFilters;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static getFilterFunction(dataUnit: DataUnit, filters?: Array<IColumnFilter>): ((record: Record) => boolean) | undefined {
|
|
30
|
+
if (!filters?.length) return undefined;
|
|
31
|
+
|
|
32
|
+
return record => {
|
|
33
|
+
for (const filter of filters) {
|
|
34
|
+
if (!ColumnFilterManager.recordMatchesFilter(dataUnit, record, filter)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private static recordMatchesFilter(dataUnit: DataUnit, record: Record, columnFilter: IColumnFilter): boolean {
|
|
43
|
+
const fieldDescriptor = dataUnit.getField(columnFilter.columnName);
|
|
44
|
+
|
|
45
|
+
if (!columnFilter.params || !fieldDescriptor) return false;
|
|
46
|
+
|
|
47
|
+
const fieldValue = record[columnFilter.columnName];
|
|
48
|
+
|
|
49
|
+
for (let param of columnFilter.params) {
|
|
50
|
+
const paramValue = dataUnit.valueFromString(columnFilter.columnName, param.value);
|
|
51
|
+
if (FieldComparator.compareValues(fieldDescriptor, fieldValue, paramValue) === 0) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public static compileDistinct(fieldName: string, dataUnit: DataUnit): Array<IMultiSelectionOption> {
|
|
60
|
+
const request = dataUnit.getLastLoadRequest();
|
|
61
|
+
let list = dataUnit.records;
|
|
62
|
+
return this.doCompileDistinct(request, fieldName, dataUnit, list);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public static compileDistinctFromArray(fieldName: string, dataUnit: DataUnit, records: Array<Record>): Array<IMultiSelectionOption> {
|
|
66
|
+
const request = dataUnit.getLastLoadRequest();
|
|
67
|
+
return this.doCompileDistinct(request, fieldName, dataUnit, records);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private static doCompileDistinct(request: LoadDataRequest | undefined, fieldName: string, dataUnit: DataUnit, list: Array<Record>) {
|
|
71
|
+
if (request != undefined) {
|
|
72
|
+
const columnFilters: Array<IColumnFilter> = Array.from(ColumnFilterManager.getColumnFilters(request?.filters ?? [], fieldName).values());
|
|
73
|
+
const filterFunction = ColumnFilterManager.getFilterFunction(dataUnit, columnFilters);
|
|
74
|
+
if (filterFunction != undefined) {
|
|
75
|
+
list = list.filter(filterFunction);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const distinct: Map<string, IMultiSelectionOption> = new Map(
|
|
80
|
+
list.map(record => {
|
|
81
|
+
const fieldValue = record[fieldName];
|
|
82
|
+
if (fieldValue == undefined) {
|
|
83
|
+
return [null, { label: null, value: null, check: true }];
|
|
84
|
+
}
|
|
85
|
+
const item = { label: dataUnit.getFormattedValue(fieldName, fieldValue), value: fieldValue, check: true };
|
|
86
|
+
return [item.label, item];
|
|
87
|
+
}) as any,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return Array.from(distinct.values());
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
interface IMultiSelectionOption {
|
|
97
|
+
value: string;
|
|
98
|
+
label: string;
|
|
99
|
+
check: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface IColumnFilter extends Filter {
|
|
103
|
+
columnName: string;
|
|
104
|
+
}
|
package/src/utils/DateUtils.ts
CHANGED
|
@@ -39,6 +39,9 @@ export default class DateUtils{
|
|
|
39
39
|
* @returns - Uma string com as horas no formato HH:MM ou HH:MM:SS.
|
|
40
40
|
*/
|
|
41
41
|
public static formatTime(date: Date, showSeconds: boolean = false): string{
|
|
42
|
+
if (date == null){
|
|
43
|
+
return '';
|
|
44
|
+
}
|
|
42
45
|
const timeOptions:Intl.DateTimeFormatOptions = {hour: "2-digit", minute: "2-digit", second: showSeconds ? "2-digit" : undefined};
|
|
43
46
|
return new Intl.DateTimeFormat("pt-BR", timeOptions).format(date);
|
|
44
47
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OverflowDirection } from './OverflowWatcher/types/overflow-direction.js';
|
|
2
|
+
|
|
3
|
+
export function calcMarginSize(el:Element, scrollDirection: OverflowDirection){
|
|
4
|
+
const computedStyle = getComputedStyle(el);
|
|
5
|
+
if(OverflowDirection.HORIZONTAL === scrollDirection){
|
|
6
|
+
return (parseInt(computedStyle.marginLeft || '0') + parseInt(computedStyle.marginRight || '0'));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return (parseInt(computedStyle.marginTop || '0') + parseInt(computedStyle.marginBottom || '0'));
|
|
10
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { StringUtils } from "./StringUtils.js";
|
|
2
|
+
/**
|
|
3
|
+
* Define os tipos de operação que o locker pode controlar
|
|
4
|
+
*/
|
|
5
|
+
export enum LockManagerOperation {
|
|
6
|
+
/**
|
|
7
|
+
Operação de lock utilizada para controlar cliques nos botoes da taskbar.
|
|
8
|
+
*/
|
|
9
|
+
TASKBAR_CLICK = "taskbar_click",
|
|
10
|
+
/**
|
|
11
|
+
Operação de lock utilizada para controlar carregamento da aplicação.
|
|
12
|
+
*/
|
|
13
|
+
APP_LOADING = "app_loading"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type Lock = {
|
|
17
|
+
promise?: Promise<unknown>,
|
|
18
|
+
resolve?: () => void,
|
|
19
|
+
done: boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class LockManager{
|
|
23
|
+
private static _locks = new Map<string, Array<Lock>>();
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Nome do atributo que será utilizado para controlar contexto de locks nos elementos da DOM.
|
|
27
|
+
*/
|
|
28
|
+
public static ATTRIBUTE_NAME = "data-locker-manger-context-id";
|
|
29
|
+
|
|
30
|
+
private static buildContextID(): string{
|
|
31
|
+
return StringUtils.generateUUID();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private static buildLockerID(ctxId:string|HTMLElement, operation: LockManagerOperation): string | undefined{
|
|
35
|
+
if(ctxId == undefined) return undefined;
|
|
36
|
+
|
|
37
|
+
let resolvedID:any = ctxId;
|
|
38
|
+
|
|
39
|
+
if(resolvedID instanceof HTMLElement){
|
|
40
|
+
resolvedID = (ctxId as HTMLElement).getAttribute(LockManager.ATTRIBUTE_NAME);
|
|
41
|
+
if(!resolvedID) return undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return `${resolvedID}_${operation}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private static findExistingCtxId = (element: HTMLElement): string | null => {
|
|
48
|
+
let currentElement: HTMLElement | null = element;
|
|
49
|
+
|
|
50
|
+
while (currentElement) {
|
|
51
|
+
if (currentElement.hasAttribute(LockManager.ATTRIBUTE_NAME)) {
|
|
52
|
+
return currentElement.getAttribute(LockManager.ATTRIBUTE_NAME);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const childWithCtxId = Array.from(currentElement.children).find(child =>
|
|
56
|
+
(child instanceof HTMLElement) && child.hasAttribute(LockManager.ATTRIBUTE_NAME)
|
|
57
|
+
) as HTMLElement | undefined;
|
|
58
|
+
|
|
59
|
+
if (childWithCtxId) {
|
|
60
|
+
return childWithCtxId.getAttribute(LockManager.ATTRIBUTE_NAME);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
currentElement = currentElement.parentElement;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private static traverseAndAddAttr = (element: HTMLElement, ctxId: string): void => {
|
|
70
|
+
if (element.tagName.startsWith('EZ-') || element.tagName.startsWith('SNK-')) {
|
|
71
|
+
element.setAttribute(LockManager.ATTRIBUTE_NAME, ctxId);
|
|
72
|
+
}
|
|
73
|
+
Array.from(element.children).forEach((child) => {
|
|
74
|
+
if (child instanceof HTMLElement) {
|
|
75
|
+
LockManager.traverseAndAddAttr(child, ctxId);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Cria um contexto de locker, caso nao exista, para todos elementos pais iniciados com ez- ou snk-.
|
|
82
|
+
*
|
|
83
|
+
* @param startElement - Elemento de de onde o lock deve começar.
|
|
84
|
+
*
|
|
85
|
+
* @returns - O id do locker, que pode ser usado para iniciar ou aguardar um lock do contexto.
|
|
86
|
+
*/
|
|
87
|
+
public static addLockManagerCtxId(startElement: HTMLElement): string {
|
|
88
|
+
try{
|
|
89
|
+
if (!startElement) {
|
|
90
|
+
console.error("Elemento inicial não fornecido.");
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const ctxId = LockManager.findExistingCtxId(startElement) ?? LockManager.buildContextID();
|
|
95
|
+
|
|
96
|
+
let currentElement: HTMLElement | null = startElement;
|
|
97
|
+
|
|
98
|
+
while (currentElement && currentElement.tagName != 'BODY') {
|
|
99
|
+
LockManager.traverseAndAddAttr(currentElement, ctxId);
|
|
100
|
+
currentElement = currentElement.parentElement;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return ctxId;
|
|
104
|
+
}catch(err){
|
|
105
|
+
console.warn(`Erro ao registrar locks para o elemento: ${startElement?.tagName}`, err);
|
|
106
|
+
return "";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Reseta todos os locks existentes para um determinado contexto e operação de forma assíncrona
|
|
112
|
+
* @param id - ID do contexto ou elemento HTML contendo contexto
|
|
113
|
+
* @param operation - Operação específica para resetar os locks
|
|
114
|
+
* @returns Promise que será resolvida quando todos os locks forem resetados
|
|
115
|
+
*/
|
|
116
|
+
public static async resetLocks(id: string | HTMLElement, operation: LockManagerOperation): Promise<void> {
|
|
117
|
+
const lockerId = this.buildLockerID(id, operation);
|
|
118
|
+
if (!lockerId) return;
|
|
119
|
+
|
|
120
|
+
const currentLocks = this._locks.get(lockerId);
|
|
121
|
+
|
|
122
|
+
if (currentLocks?.length) {
|
|
123
|
+
await Promise.all(currentLocks.map(lock => {
|
|
124
|
+
lock.done = true;
|
|
125
|
+
lock.resolve?.();
|
|
126
|
+
return lock.promise;
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
this._locks.delete(lockerId);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Inicia um locker baseado em um contexto e uma operação.
|
|
136
|
+
*
|
|
137
|
+
* @param id - Pode ser um ID do contexto de locker, ou, o elemento contendo um contexto de locker.
|
|
138
|
+
* @param operation - Operação do contexto que o lock deve ser feito.
|
|
139
|
+
*
|
|
140
|
+
* @returns - Uma função que fara a liberação do lock.
|
|
141
|
+
*/
|
|
142
|
+
public static lock(id:string|HTMLElement, operation:LockManagerOperation): () => void {
|
|
143
|
+
const lockerId = LockManager.buildLockerID(id, operation);
|
|
144
|
+
|
|
145
|
+
if(!lockerId) return () => {};
|
|
146
|
+
|
|
147
|
+
const lock:Lock = { done: false };
|
|
148
|
+
const promise = new Promise<void>(resolve => lock.resolve = resolve);
|
|
149
|
+
lock.promise = promise;
|
|
150
|
+
|
|
151
|
+
const currentLocks = LockManager._locks.get(lockerId) ?? [];
|
|
152
|
+
currentLocks.push(lock);
|
|
153
|
+
LockManager._locks.set(lockerId, currentLocks);
|
|
154
|
+
|
|
155
|
+
return () => {
|
|
156
|
+
lock.done = true;
|
|
157
|
+
lock.resolve?.();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Aguarda todos os lockers de um contexto e operação serem resolvidos.
|
|
163
|
+
*
|
|
164
|
+
* @param id - Pode ser um ID do contexto de locker, ou, o elemento contendo um contexto de locker.
|
|
165
|
+
* @param operation - Operação do contexto que devera aguardar.
|
|
166
|
+
*
|
|
167
|
+
* @returns - Promise que será resolvida quando todos lockers forem finalizados.
|
|
168
|
+
*/
|
|
169
|
+
public static async whenResolve(id:string|HTMLElement, operation:LockManagerOperation, debounce?: number, timeOut?: number): Promise<void> {
|
|
170
|
+
const lockerId = LockManager.buildLockerID(id, operation);
|
|
171
|
+
|
|
172
|
+
if(!lockerId) return;
|
|
173
|
+
|
|
174
|
+
if(debounce) await new Promise(resolve => setTimeout(resolve, debounce));
|
|
175
|
+
|
|
176
|
+
const startTime = Date.now();
|
|
177
|
+
|
|
178
|
+
while (LockManager._locks.get(lockerId)?.length) {
|
|
179
|
+
|
|
180
|
+
if (timeOut && Date.now() - startTime >= timeOut) {
|
|
181
|
+
await this.resetLocks(id, operation);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const locks:Array<Lock> = LockManager._locks.get(lockerId) ?? [];
|
|
186
|
+
await Promise.all(locks.map(lock => lock.promise));
|
|
187
|
+
|
|
188
|
+
//Aguarda listeners da tela reagirem as mudancas de estado do dataunit
|
|
189
|
+
await new Promise(resolve => setTimeout(resolve, debounce || 200));
|
|
190
|
+
|
|
191
|
+
LockManager._locks.set(lockerId, locks.filter(lock => !lock.done));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public static async whenHasLock(id:string|HTMLElement, operation:LockManagerOperation, timeOut?: number): Promise<void> {
|
|
197
|
+
const lockerId = LockManager.buildLockerID(id, operation);
|
|
198
|
+
|
|
199
|
+
if(!lockerId) return;
|
|
200
|
+
|
|
201
|
+
const startTime = Date.now();
|
|
202
|
+
|
|
203
|
+
while (!LockManager._locks.get(lockerId)?.length) {
|
|
204
|
+
|
|
205
|
+
if (timeOut && Date.now() - startTime >= timeOut) {
|
|
206
|
+
await this.resetLocks(id, operation);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|