@sankhyalabs/core 6.1.0 → 6.2.0-dev.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 (106) hide show
  1. package/.docs/classes/Change.md +11 -11
  2. package/.docs/classes/ColumnFilterManager.md +6 -6
  3. package/.docs/classes/DataUnit.md +178 -157
  4. package/.docs/classes/DataUnitLoaderUtils.md +6 -6
  5. package/.docs/classes/LangUtils.md +195 -0
  6. package/.docs/classes/SelectionInfo.md +16 -16
  7. package/.docs/enumerations/ChangeOperation.md +4 -4
  8. package/.docs/enumerations/SelectionMode.md +2 -2
  9. package/.docs/functions/defaultDataLoader.md +1 -1
  10. package/.docs/globals.md +1 -0
  11. package/.docs/interfaces/DUActionInterceptor.md +1 -1
  12. package/.docs/interfaces/PageRequest.md +3 -3
  13. package/.docs/interfaces/PaginationInfoBuilderParams.md +3 -3
  14. package/.docs/interfaces/QuickFilter.md +3 -3
  15. package/.docs/interfaces/Record.md +4 -4
  16. package/.docs/interfaces/SavedRecord.md +5 -5
  17. package/.docs/interfaces/WaitingChange.md +3 -3
  18. package/.docs/type-aliases/DataUnitEventOptions.md +1 -1
  19. package/dist/dataunit/Changes.d.ts +52 -0
  20. package/dist/dataunit/Changes.js +64 -0
  21. package/dist/dataunit/Changes.js.map +1 -0
  22. package/dist/dataunit/DataUnit.d.ts +16 -129
  23. package/dist/dataunit/DataUnit.js +97 -177
  24. package/dist/dataunit/DataUnit.js.map +1 -1
  25. package/dist/dataunit/DataUnitHelper.d.ts +2 -1
  26. package/dist/dataunit/DataUnitHelper.js.map +1 -1
  27. package/dist/dataunit/SelectionInfo.d.ts +16 -0
  28. package/dist/dataunit/SelectionInfo.js +39 -0
  29. package/dist/dataunit/SelectionInfo.js.map +1 -0
  30. package/dist/dataunit/formatting/PrettyFormatter.js +5 -3
  31. package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
  32. package/dist/dataunit/interfaces/dataUnit.d.ts +61 -0
  33. package/dist/dataunit/interfaces/dataUnit.js +13 -0
  34. package/dist/dataunit/interfaces/dataUnit.js.map +1 -0
  35. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +2 -1
  36. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -1
  37. package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
  38. package/dist/dataunit/loading/LoadDataResponse.d.ts +1 -1
  39. package/dist/dataunit/sorting/FieldComparator.d.ts +1 -1
  40. package/dist/dataunit/state/slice/AddedRecordsSlice.d.ts +1 -1
  41. package/dist/dataunit/state/slice/ChangesSlice.d.ts +2 -1
  42. package/dist/dataunit/state/slice/ChangesSlice.js +2 -1
  43. package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
  44. package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
  45. package/dist/dataunit/state/slice/RecordsSlice.d.ts +1 -1
  46. package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
  47. package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
  48. package/dist/dataunit/state/slice/SelectionSlice.d.ts +2 -1
  49. package/dist/dataunit/state/slice/SelectionSlice.js +2 -1
  50. package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
  51. package/dist/dataunit/state/slice/SnapshotSlice.d.ts +1 -1
  52. package/dist/dataunit/state/slice/WaitingChangesSlice.d.ts +1 -1
  53. package/dist/index.d.ts +6 -2
  54. package/dist/index.js +6 -2
  55. package/dist/index.js.map +1 -1
  56. package/dist/utils/ColumnFilterManager.d.ts +2 -1
  57. package/dist/utils/ColumnFilterManager.js.map +1 -1
  58. package/dist/utils/LangUtils.d.ts +83 -0
  59. package/dist/utils/LangUtils.js +121 -0
  60. package/dist/utils/LangUtils.js.map +1 -0
  61. package/dist/utils/SortingUtils.d.ts +1 -1
  62. package/package.json +3 -2
  63. package/reports/test-report.xml +741 -524
  64. package/src/dataunit/Changes.ts +77 -0
  65. package/src/dataunit/DataUnit.ts +253 -397
  66. package/src/dataunit/DataUnitHelper.ts +2 -1
  67. package/src/dataunit/SelectionInfo.ts +55 -0
  68. package/src/dataunit/formatting/PrettyFormatter.ts +4 -5
  69. package/src/dataunit/interfaces/dataUnit.ts +71 -0
  70. package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +2 -1
  71. package/src/dataunit/loading/LoadDataRequest.ts +1 -1
  72. package/src/dataunit/loading/LoadDataResponse.ts +1 -1
  73. package/src/dataunit/sorting/FieldComparator.ts +1 -1
  74. package/src/dataunit/state/slice/AddedRecordsSlice.ts +1 -1
  75. package/src/dataunit/state/slice/ChangesSlice.ts +2 -1
  76. package/src/dataunit/state/slice/LoadingControlSlice.ts +1 -2
  77. package/src/dataunit/state/slice/RecordsSlice.ts +3 -2
  78. package/src/dataunit/state/slice/SelectionSlice.ts +2 -1
  79. package/src/dataunit/state/slice/SnapshotSlice.ts +1 -1
  80. package/src/dataunit/state/slice/WaitingChangesSlice.ts +1 -1
  81. package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +1 -1
  82. package/src/index.ts +6 -2
  83. package/src/utils/ColumnFilterManager.ts +2 -1
  84. package/src/utils/LangUtils.ts +129 -0
  85. package/src/utils/SortingUtils.ts +1 -1
  86. package/test/dataunit/AccessParentsDataUnit.spec.ts +69 -0
  87. package/test/dataunit/Actions.spec.ts +74 -0
  88. package/test/dataunit/Change.spec.ts +66 -0
  89. package/test/dataunit/FieldManager.spec.ts +286 -0
  90. package/test/dataunit/FilterSortsLockersAndObservers.spec.ts +339 -0
  91. package/test/dataunit/InfoManager.spec.ts +254 -0
  92. package/test/dataunit/LoadDataAndMetadata.spec.ts +269 -0
  93. package/test/dataunit/RecodsSelection.spec.ts +229 -0
  94. package/test/dataunit/RecordsManager.spec.ts +323 -0
  95. package/test/dataunit/SavingData.spec.ts +206 -0
  96. package/test/dataunit/SelectionInfo.spec.ts +143 -0
  97. package/test/dataunit/formatting/PrettyFormatter.spec.ts +1 -1
  98. package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +2 -1
  99. package/test/dataunit/loader/utils/createDataUnitMock.ts +34 -0
  100. package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +1 -1
  101. package/test/dataunit/resources/metadata.ts +39 -0
  102. package/test/dataunit/resources/records.ts +29 -0
  103. package/test/util/ColumnFilterManager.spec.ts +2 -1
  104. package/test/util/LangUtils.spec.ts +117 -0
  105. package/tsconfig.json +1 -0
  106. package/src/dataunit/test/DataUnit.spec.ts +0 -44
@@ -0,0 +1,64 @@
1
+ import { ChangeOperation } from "./interfaces/dataUnit.js";
2
+ /***
3
+ * `Change`: Dados que representam uma alteração.
4
+ */
5
+ export class Change {
6
+ constructor(dataUnit, record, updates, operation, sourceId) {
7
+ this.dataUnit = dataUnit;
8
+ this.record = record;
9
+ this.sourceId = sourceId;
10
+ this.updatingFields = updates;
11
+ this._operation = operation;
12
+ }
13
+ /**
14
+ *
15
+ * Obtém o tipo de operação que está sendo realizada.
16
+ *
17
+ * @returns - Ação que está sendo executada.
18
+ *
19
+ */
20
+ get operation() {
21
+ return this._operation.toString();
22
+ }
23
+ /**
24
+ *
25
+ * Retorna se o DataUnit está em uma operação de inserção.
26
+ *
27
+ * @returns - Verdadeiro se a operação for de inserção.
28
+ *
29
+ */
30
+ isInsert() {
31
+ return this._operation === ChangeOperation.INSERT;
32
+ }
33
+ /**
34
+ *
35
+ * Retorna se o DataUnit está em uma operação de cópia.
36
+ *
37
+ * @returns - Verdadeiro se a operação for de cópia.
38
+ *
39
+ */
40
+ isCopy() {
41
+ return this._operation === ChangeOperation.COPY;
42
+ }
43
+ /**
44
+ *
45
+ * Retorna se o DataUnit está em uma operação de deleção.
46
+ *
47
+ * @returns - Verdadeiro se a operação for de deleção.
48
+ *
49
+ */
50
+ isDelete() {
51
+ return this._operation === ChangeOperation.DELETE;
52
+ }
53
+ /**
54
+ *
55
+ * Retorna se o DataUnit está em uma operação de atualização.
56
+ *
57
+ * @returns - Verdadeiro se a operação for de atualização.
58
+ *
59
+ */
60
+ isUpdate() {
61
+ return this._operation === ChangeOperation.UPDATE;
62
+ }
63
+ }
64
+ //# sourceMappingURL=Changes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Changes.js","sourceRoot":"","sources":["../../src/dataunit/Changes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAU,MAAM,0BAA0B,CAAC;AAEnE;;GAEG;AACH,MAAM,OAAO,MAAM;IASf,YAAY,QAAgB,EAAE,MAAc,EAAE,OAAY,EAAE,SAA0B,EAAE,QAAiB;QACrG,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACX,OAAO,IAAI,CAAC,UAAU,KAAK,eAAe,CAAC,MAAM,CAAC;IACtD,CAAC;IAED;;;;;;OAMG;IACI,MAAM;QACT,OAAO,IAAI,CAAC,UAAU,KAAK,eAAe,CAAC,IAAI,CAAC;IACpD,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACX,OAAO,IAAI,CAAC,UAAU,KAAK,eAAe,CAAC,MAAM,CAAC;IACtD,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACX,OAAO,IAAI,CAAC,UAAU,KAAK,eAAe,CAAC,MAAM,CAAC;IACtD,CAAC;CACJ"}
@@ -3,6 +3,9 @@ import { DataUnitAction, ExecutionContext } from "./state/action/DataUnitAction.
3
3
  import { LoadDataRequest } from "./loading/LoadDataRequest.js";
4
4
  import { LoadDataResponse } from "./loading/LoadDataResponse.js";
5
5
  import { PaginationInfo } from "./loading/PaginationInfo.js";
6
+ import { DataUnitEventOptions, DUActionInterceptor, HideFieldOptions, LoadDataParams, QuickFilter, Record, SavedRecord, SelectionMode, WaitingChange } from "./interfaces/dataUnit.js";
7
+ import { Change } from "./Changes.js";
8
+ import { SelectionInfo } from "./SelectionInfo.js";
6
9
  /***
7
10
  * `DataUnit`: Atua como uma camada de abstração entre o back-end e a interface do usuário.
8
11
  */
@@ -375,6 +378,13 @@ export default class DataUnit {
375
378
  *
376
379
  */
377
380
  getChildInfo(name: string): ChildDescriptor | undefined;
381
+ /**
382
+ *
383
+ * Define a propriedade records da instância da classe com um novo valor e chama o método dispatchAction para notificar os observers da aplicação sobre a mudança,
384
+ * mantendo a seleção definida anteriormente.
385
+ *
386
+ */
387
+ setRecordsKeepingSelection(records: Array<Record>): void;
378
388
  /**
379
389
  *
380
390
  * Define a propriedade records da instância da classe com um novo valor e chama o método dispatchAction para notificar os observers da aplicação sobre a mudança.
@@ -594,7 +604,7 @@ export default class DataUnit {
594
604
  * @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
595
605
  * @returns - Informações sobre a seleção.
596
606
  */
597
- updatePageSelection(selection: Array<string>, executionCtx?: ExecutionContext): Promise<SelectionInfo | undefined>;
607
+ updatePageSelection(selection?: Array<string>, executionCtx?: ExecutionContext): Promise<SelectionInfo | undefined>;
598
608
  private updatePageSelectionAll;
599
609
  /**
600
610
  * Seleciona todos os registros da página.
@@ -645,7 +655,7 @@ export default class DataUnit {
645
655
  *
646
656
  *
647
657
  */
648
- nextRecord(executionCtx?: ExecutionContext): void;
658
+ nextRecord(executionCtx?: ExecutionContext): Promise<void>;
649
659
  /**
650
660
  *
651
661
  * Seleciona o registro anterior.
@@ -653,7 +663,7 @@ export default class DataUnit {
653
663
  * @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
654
664
  *
655
665
  */
656
- previousRecord(executionCtx?: ExecutionContext): void;
666
+ previousRecord(executionCtx?: ExecutionContext): Promise<void>;
657
667
  /**
658
668
  *
659
669
  * Cancela edição do registro atual.
@@ -902,7 +912,7 @@ export default class DataUnit {
902
912
  * @param fieldName - nome do campo para ficar invisível.
903
913
  *
904
914
  */
905
- hideField(fieldName: string, options: HideFieldOptions): void;
915
+ hideField(fieldName: string, options?: HideFieldOptions): void;
906
916
  /**
907
917
  *
908
918
  * Deixa um campo do DataUnit visível
@@ -959,130 +969,7 @@ export default class DataUnit {
959
969
  /**
960
970
  * Retornar o campo de origem dos dados caso exista mapeamento
961
971
  */
962
- getSourceFieldValue(targetFieldName: string): string | undefined;
972
+ getSourceFieldValue(sourceFieldName: string): string | undefined;
963
973
  private processLoadingLockers;
964
974
  }
965
- export interface LoadDataParams {
966
- quickFilter?: QuickFilter;
967
- executionCtx?: ExecutionContext;
968
- checkLastFilter?: boolean;
969
- source?: string;
970
- selectFirstRecord?: boolean;
971
- keepSelection?: boolean;
972
- }
973
- export interface DUActionInterceptor {
974
- interceptAction(action: DataUnitAction): DataUnitAction | Promise<DataUnitAction>;
975
- }
976
- export interface Record {
977
- __record__id__: string;
978
- __record__label__?: string;
979
- __parent__record__id__?: string;
980
- __owner__dataunit__name__?: string;
981
- [key: string]: any;
982
- }
983
- export interface SavedRecord extends Record {
984
- __old__id__?: string;
985
- }
986
- export declare enum ChangeOperation {
987
- INSERT = "INSERT",
988
- COPY = "COPY",
989
- UPDATE = "UPDATE",
990
- DELETE = "DELETE"
991
- }
992
- /***
993
- * `Change`: Dados que representam uma alteração.
994
- */
995
- export declare class Change {
996
- dataUnit: string;
997
- record: Record;
998
- sourceId: string | undefined;
999
- updatingFields: any;
1000
- private _operation;
1001
- constructor(dataUnit: string, record: Record, updates: any, operation: ChangeOperation, sourceId?: string);
1002
- /**
1003
- *
1004
- * Obtém o tipo de operação que está sendo realizada.
1005
- *
1006
- * @returns - Ação que está sendo executada.
1007
- *
1008
- */
1009
- get operation(): string;
1010
- /**
1011
- *
1012
- * Retorna se o DataUnit está em uma operação de inserção.
1013
- *
1014
- * @returns - Verdadeiro se a operação for de inserção.
1015
- *
1016
- */
1017
- isInsert(): boolean;
1018
- /**
1019
- *
1020
- * Retorna se o DataUnit está em uma operação de cópia.
1021
- *
1022
- * @returns - Verdadeiro se a operação for de cópia.
1023
- *
1024
- */
1025
- isCopy(): boolean;
1026
- /**
1027
- *
1028
- * Retorna se o DataUnit está em uma operação de deleção.
1029
- *
1030
- * @returns - Verdadeiro se a operação for de deleção.
1031
- *
1032
- */
1033
- isDelete(): boolean;
1034
- /**
1035
- *
1036
- * Retorna se o DataUnit está em uma operação de atualização.
1037
- *
1038
- * @returns - Verdadeiro se a operação for de atualização.
1039
- *
1040
- */
1041
- isUpdate(): boolean;
1042
- }
1043
- export interface WaitingChange {
1044
- waitmessage: string;
1045
- blocking: boolean;
1046
- promise?: Promise<any>;
1047
- }
1048
- export interface PageRequest {
1049
- limit: number;
1050
- offset: number;
1051
- quickFilter?: QuickFilter;
1052
- }
1053
- export interface QuickFilter {
1054
- term: string;
1055
- fields?: Array<string>;
1056
- filter?: Filter;
1057
- }
1058
- export interface PageResponse {
1059
- limit: number;
1060
- offset: number;
1061
- total: number;
1062
- hasMore: boolean;
1063
- records: Array<Record>;
1064
- }
1065
- export declare enum SelectionMode {
1066
- ALL_RECORDS = "ALL_RECORDS",
1067
- SOME_RECORDS = "SOME_RECORDS"
1068
- }
1069
- export declare class SelectionInfo {
1070
- mode: SelectionMode;
1071
- filters?: Array<Filter>;
1072
- sort?: Array<Sort>;
1073
- getAllRecords?: () => Array<Record> | undefined;
1074
- private _records;
1075
- private _total?;
1076
- constructor(records: Array<Record>, mode?: SelectionMode, total?: number, filters?: Array<Filter>, sort?: Array<Sort>);
1077
- get records(): Array<Record> | undefined;
1078
- get recordIds(): Array<string> | undefined;
1079
- get length(): number;
1080
- isAllRecords(): boolean;
1081
- isEmpty(): boolean;
1082
- }
1083
- export type DataUnitEventOptions = {
1084
- [key: string]: any;
1085
- };
1086
- export type HideFieldOptions = {
1087
- visibleOnConfig: boolean;
1088
- };
975
+ export { Record, Change, SelectionInfo, SelectionMode, LoadDataParams, DUActionInterceptor, SavedRecord, WaitingChange, QuickFilter, DataUnitEventOptions, HideFieldOptions };
@@ -32,6 +32,9 @@ import { getLoadingProperties, LoadingPropertiesReducer } from "./state/slice/Lo
32
32
  import SortingUtils from "../utils/SortingUtils.js";
33
33
  import ServiceCanceledException from "../exceptions/ServiceCanceledException.js";
34
34
  import SilentException from "../exceptions/SilentException.js";
35
+ import { SelectionMode } from "./interfaces/dataUnit.js";
36
+ import { Change } from "./Changes.js";
37
+ import { SelectionInfo } from "./SelectionInfo.js";
35
38
  /***
36
39
  * `DataUnit`: Atua como uma camada de abstração entre o back-end e a interface do usuário.
37
40
  */
@@ -237,7 +240,7 @@ export default class DataUnit {
237
240
  */
238
241
  executeLoadData(request, executionCtx, checkLastFilter, selectFirstRecord) {
239
242
  if (checkLastFilter && this.isSameRequest(request)) {
240
- const paginationInfo = getPaginationInfo(this._stateManager);
243
+ const paginationInfo = this.getPaginationInfo();
241
244
  if (paginationInfo) {
242
245
  const response = {
243
246
  records: getRecords(this._stateManager),
@@ -441,15 +444,18 @@ export default class DataUnit {
441
444
  return __awaiter(this, void 0, void 0, function* () {
442
445
  const blockingWaitingChanges = getBlockingWaitingChanges(this._stateManager);
443
446
  if (blockingWaitingChanges && blockingWaitingChanges.size > 0) {
444
- const [_, waitingChange] = blockingWaitingChanges.entries().next().value;
445
- return Promise.reject(new WaitingChangeException("Aguardando alteração de campo", waitingChange.waitmessage));
447
+ const entry = blockingWaitingChanges.entries().next().value;
448
+ if (entry) {
449
+ const [_, waitingChange] = entry;
450
+ return Promise.reject(new WaitingChangeException("Aguardando alteração de campo", waitingChange.waitmessage));
451
+ }
446
452
  }
447
453
  else {
448
454
  if (this.isDirty()) {
449
455
  if (yield this.notifySavingData(executionCtx)) {
450
456
  const promisses = this.getBeforeSavePromisses();
451
457
  return new Promise((resolve, fail) => {
452
- Promise.all(promisses || []).then(() => {
458
+ Promise.all(promisses).then(() => {
453
459
  this._savingLockers = [];
454
460
  if (this.saveLoader) {
455
461
  const changes = this.getAllChangesToSave();
@@ -505,8 +511,7 @@ export default class DataUnit {
505
511
  return getChangesToSave(this._name, this._stateManager);
506
512
  }
507
513
  buildChangesToSaveFromChild(allChanges, dataUnit) {
508
- var _a;
509
- (_a = dataUnit._childByName) === null || _a === void 0 ? void 0 : _a.forEach((dataUnitChild) => {
514
+ dataUnit._childByName.forEach((dataUnitChild) => {
510
515
  if (dataUnitChild.isDirty()) {
511
516
  allChanges.push(...getChangesToSave(dataUnitChild.name, dataUnitChild._stateManager));
512
517
  this.buildChangesToSaveFromChild(allChanges, dataUnitChild);
@@ -541,15 +546,15 @@ export default class DataUnit {
541
546
  removeSelectedRecords(buffered = false, silent = false) {
542
547
  return __awaiter(this, void 0, void 0, function* () {
543
548
  const selection = this.getSelectionInfo();
544
- if (selection) {
545
- if (selection.isAllRecords()) {
546
- throw new Error("Exclusão remota não implementada.");
547
- }
548
- const records = (selection === null || selection === void 0 ? void 0 : selection.records) || [];
549
- const recordIds = (selection === null || selection === void 0 ? void 0 : selection.recordIds) || [];
550
- return this.removeRecords(recordIds, records, buffered, undefined, silent);
549
+ if (selection.isAllRecords()) {
550
+ throw new Error("Exclusão remota não implementada.");
551
551
  }
552
- return Promise.resolve([]);
552
+ if (!selection.records || !selection.records.length) {
553
+ return Promise.resolve([]);
554
+ }
555
+ const records = selection.records;
556
+ const recordIds = selection.recordIds;
557
+ return this.removeRecords(recordIds, records, buffered, undefined, silent);
553
558
  });
554
559
  }
555
560
  /**
@@ -766,6 +771,16 @@ export default class DataUnit {
766
771
  }
767
772
  return children.find(child => child.name === name);
768
773
  }
774
+ /**
775
+ *
776
+ * Define a propriedade records da instância da classe com um novo valor e chama o método dispatchAction para notificar os observers da aplicação sobre a mudança,
777
+ * mantendo a seleção definida anteriormente.
778
+ *
779
+ */
780
+ setRecordsKeepingSelection(records) {
781
+ const paginationInfo = this.getPaginationInfo();
782
+ this.dispatchAction(Action.DATA_LOADED, { records, paginationInfo, keepSelection: true }, undefined);
783
+ }
769
784
  /**
770
785
  *
771
786
  * Define a propriedade records da instância da classe com um novo valor e chama o método dispatchAction para notificar os observers da aplicação sobre a mudança.
@@ -859,14 +874,12 @@ export default class DataUnit {
859
874
  */
860
875
  copySelected(executionCtx) {
861
876
  const selectionInfo = this.getSelectionInfo();
862
- if (selectionInfo) {
863
- if (selectionInfo.isAllRecords()) {
864
- throw new Error("Erro interno: Impossível copiar os registros selecionados pois a seleção atual é virtual.");
865
- }
866
- const selectedRecords = selectionInfo.records;
867
- if (selectedRecords) {
868
- this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
869
- }
877
+ if (selectionInfo.isAllRecords()) {
878
+ throw new Error("Erro interno: Impossível copiar os registros selecionados pois a seleção atual é virtual.");
879
+ }
880
+ const selectedRecords = selectionInfo.records;
881
+ if (selectedRecords.length) {
882
+ this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
870
883
  }
871
884
  }
872
885
  getRecordsByDataUnit(records) {
@@ -1147,7 +1160,6 @@ export default class DataUnit {
1147
1160
  *
1148
1161
  **/
1149
1162
  getSelectionInfo() {
1150
- var _a;
1151
1163
  const selectionInfo = getSelectionInfo(this._stateManager);
1152
1164
  selectionInfo.getAllRecords = () => {
1153
1165
  var _a, _b;
@@ -1160,7 +1172,7 @@ export default class DataUnit {
1160
1172
  };
1161
1173
  if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
1162
1174
  const sortingFunction = SortingUtils.getSortingFunction(this, selectionInfo.sort);
1163
- (_a = selectionInfo.records) === null || _a === void 0 ? void 0 : _a.sort(sortingFunction);
1175
+ selectionInfo.records.sort(sortingFunction);
1164
1176
  }
1165
1177
  return selectionInfo;
1166
1178
  }
@@ -1200,24 +1212,26 @@ export default class DataUnit {
1200
1212
  *
1201
1213
  */
1202
1214
  nextRecord(executionCtx) {
1203
- if (!hasNext(this._stateManager)) {
1204
- if (hasMorePages(this._stateManager)) {
1205
- this.nextPage({
1206
- before: act => {
1207
- if (executionCtx && executionCtx.before) {
1208
- act = executionCtx.before(act);
1215
+ return __awaiter(this, void 0, void 0, function* () {
1216
+ if (!hasNext(this._stateManager)) {
1217
+ if (hasMorePages(this._stateManager)) {
1218
+ yield this.nextPage({
1219
+ before: (act) => {
1220
+ if (executionCtx && executionCtx.before) {
1221
+ act = executionCtx.before(act);
1222
+ }
1223
+ return act;
1224
+ },
1225
+ after: () => {
1226
+ this.selectFirst(executionCtx);
1209
1227
  }
1210
- return act;
1211
- },
1212
- after: act => {
1213
- this.selectFirst(executionCtx);
1214
- }
1215
- });
1228
+ });
1229
+ }
1216
1230
  }
1217
- }
1218
- else {
1219
- this.dispatchAction(Action.NEXT_SELECTED, undefined, executionCtx);
1220
- }
1231
+ else {
1232
+ this.dispatchAction(Action.NEXT_SELECTED, undefined, executionCtx);
1233
+ }
1234
+ });
1221
1235
  }
1222
1236
  /**
1223
1237
  *
@@ -1227,24 +1241,26 @@ export default class DataUnit {
1227
1241
  *
1228
1242
  */
1229
1243
  previousRecord(executionCtx) {
1230
- if (!hasPrevious(this._stateManager)) {
1231
- if (hasPreviousPages(this._stateManager)) {
1232
- this.previousPage({
1233
- before: act => {
1234
- if (executionCtx && executionCtx.before) {
1235
- act = executionCtx.before(act);
1244
+ return __awaiter(this, void 0, void 0, function* () {
1245
+ if (!hasPrevious(this._stateManager)) {
1246
+ if (hasPreviousPages(this._stateManager)) {
1247
+ yield this.previousPage({
1248
+ before: (act) => {
1249
+ if (executionCtx && executionCtx.before) {
1250
+ act = executionCtx.before(act);
1251
+ }
1252
+ return act;
1253
+ },
1254
+ after: () => {
1255
+ this.selectLast(executionCtx);
1236
1256
  }
1237
- return act;
1238
- },
1239
- after: act => {
1240
- this.selectLast(executionCtx);
1241
- }
1242
- });
1257
+ });
1258
+ }
1243
1259
  }
1244
- }
1245
- else {
1246
- this.dispatchAction(Action.PREVIOUS_SELECTED, undefined, executionCtx);
1247
- }
1260
+ else {
1261
+ this.dispatchAction(Action.PREVIOUS_SELECTED, undefined, executionCtx);
1262
+ }
1263
+ });
1248
1264
  }
1249
1265
  /**
1250
1266
  *
@@ -1296,7 +1312,7 @@ export default class DataUnit {
1296
1312
  *
1297
1313
  */
1298
1314
  childrenIsDirty() {
1299
- for (let [key, dataUnitChild] of this._childByName) {
1315
+ for (let [_, dataUnitChild] of this._childByName) {
1300
1316
  if (dataUnitChild.isDirty())
1301
1317
  return true;
1302
1318
  }
@@ -1656,7 +1672,10 @@ export default class DataUnit {
1656
1672
  */
1657
1673
  enableField(fieldName) {
1658
1674
  const fieldDescriptor = this.getField(fieldName);
1659
- if ((fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.readOnly) === true) {
1675
+ if (!fieldDescriptor) {
1676
+ return;
1677
+ }
1678
+ if (fieldDescriptor.readOnly) {
1660
1679
  fieldDescriptor.readOnly = false;
1661
1680
  this.metadata = Object.assign({}, this.metadata);
1662
1681
  }
@@ -1669,7 +1688,10 @@ export default class DataUnit {
1669
1688
  */
1670
1689
  disableField(fieldName) {
1671
1690
  const fieldDescriptor = this.getField(fieldName);
1672
- if ((fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.readOnly) === false) {
1691
+ if (!fieldDescriptor) {
1692
+ return;
1693
+ }
1694
+ if (!fieldDescriptor.readOnly) {
1673
1695
  fieldDescriptor.readOnly = true;
1674
1696
  this.metadata = Object.assign({}, this.metadata);
1675
1697
  }
@@ -1682,9 +1704,14 @@ export default class DataUnit {
1682
1704
  */
1683
1705
  hideField(fieldName, options) {
1684
1706
  const fieldDescriptor = this.getField(fieldName);
1685
- if ((fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.visible) === true) {
1707
+ if (!fieldDescriptor) {
1708
+ return;
1709
+ }
1710
+ if (fieldDescriptor.visible) {
1686
1711
  fieldDescriptor.visible = false;
1687
- fieldDescriptor.properties = Object.assign(Object.assign({}, fieldDescriptor.properties), { visibleOnConfig: options === null || options === void 0 ? void 0 : options.visibleOnConfig });
1712
+ if (options) {
1713
+ fieldDescriptor.properties = Object.assign(Object.assign({}, fieldDescriptor.properties), { visibleOnConfig: options.visibleOnConfig });
1714
+ }
1688
1715
  this.metadata = Object.assign({}, this.metadata);
1689
1716
  }
1690
1717
  }
@@ -1696,7 +1723,10 @@ export default class DataUnit {
1696
1723
  */
1697
1724
  showField(fieldName) {
1698
1725
  const fieldDescriptor = this.getField(fieldName);
1699
- if ((fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.visible) === false) {
1726
+ if (!fieldDescriptor) {
1727
+ return;
1728
+ }
1729
+ if (!fieldDescriptor.visible) {
1700
1730
  fieldDescriptor.visible = true;
1701
1731
  this.metadata = Object.assign({}, this.metadata);
1702
1732
  }
@@ -1766,11 +1796,11 @@ export default class DataUnit {
1766
1796
  * @returns Retorna uma função responsável por liberar o lock adicionado.
1767
1797
  */
1768
1798
  addLoadingLocker() {
1769
- let loadingLockerResolver;
1799
+ let loadingLockerResolver = () => { };
1770
1800
  this._loadingLockers.push(new Promise((resolve) => {
1771
1801
  loadingLockerResolver = resolve;
1772
1802
  }));
1773
- return loadingLockerResolver || Promise.resolve;
1803
+ return loadingLockerResolver;
1774
1804
  }
1775
1805
  set allowReleaseCallbacks(allow) {
1776
1806
  this._allowReleaseCallbacks = allow;
@@ -1784,8 +1814,8 @@ export default class DataUnit {
1784
1814
  /**
1785
1815
  * Retornar o campo de origem dos dados caso exista mapeamento
1786
1816
  */
1787
- getSourceFieldValue(targetFieldName) {
1788
- return this._fieldSourceValue.get(targetFieldName);
1817
+ getSourceFieldValue(sourceFieldName) {
1818
+ return this._fieldSourceValue.get(sourceFieldName);
1789
1819
  }
1790
1820
  processLoadingLockers() {
1791
1821
  return __awaiter(this, void 0, void 0, function* () {
@@ -1799,115 +1829,5 @@ export default class DataUnit {
1799
1829
  DataUnit.CHANGING_PAGE_LOADING_SOURCE = "CHANGING_PAGE_LOADING_SOURCE";
1800
1830
  DataUnit.ALL_RECORDS_SELECTION_SOURCE = "ALL_RECORDS_SELECTION_SOURCE";
1801
1831
  DataUnit.DEFAULT_DATAUNIT_NAME = "dataunit";
1802
- export var ChangeOperation;
1803
- (function (ChangeOperation) {
1804
- ChangeOperation["INSERT"] = "INSERT";
1805
- ChangeOperation["COPY"] = "COPY";
1806
- ChangeOperation["UPDATE"] = "UPDATE";
1807
- ChangeOperation["DELETE"] = "DELETE";
1808
- })(ChangeOperation || (ChangeOperation = {}));
1809
- /***
1810
- * `Change`: Dados que representam uma alteração.
1811
- */
1812
- export class Change {
1813
- constructor(dataUnit, record, updates, operation, sourceId) {
1814
- this.dataUnit = dataUnit;
1815
- this.record = record;
1816
- this.sourceId = sourceId;
1817
- this.updatingFields = updates;
1818
- this._operation = operation;
1819
- }
1820
- /**
1821
- *
1822
- * Obtém o tipo de operação que está sendo realizada.
1823
- *
1824
- * @returns - Ação que está sendo executada.
1825
- *
1826
- */
1827
- get operation() {
1828
- return this._operation.toString();
1829
- }
1830
- /**
1831
- *
1832
- * Retorna se o DataUnit está em uma operação de inserção.
1833
- *
1834
- * @returns - Verdadeiro se a operação for de inserção.
1835
- *
1836
- */
1837
- isInsert() {
1838
- return this._operation === ChangeOperation.INSERT;
1839
- }
1840
- /**
1841
- *
1842
- * Retorna se o DataUnit está em uma operação de cópia.
1843
- *
1844
- * @returns - Verdadeiro se a operação for de cópia.
1845
- *
1846
- */
1847
- isCopy() {
1848
- return this._operation === ChangeOperation.COPY;
1849
- }
1850
- /**
1851
- *
1852
- * Retorna se o DataUnit está em uma operação de deleção.
1853
- *
1854
- * @returns - Verdadeiro se a operação for de deleção.
1855
- *
1856
- */
1857
- isDelete() {
1858
- return this._operation === ChangeOperation.DELETE;
1859
- }
1860
- /**
1861
- *
1862
- * Retorna se o DataUnit está em uma operação de atualização.
1863
- *
1864
- * @returns - Verdadeiro se a operação for de atualização.
1865
- *
1866
- */
1867
- isUpdate() {
1868
- return this._operation === ChangeOperation.UPDATE;
1869
- }
1870
- }
1871
- export var SelectionMode;
1872
- (function (SelectionMode) {
1873
- SelectionMode["ALL_RECORDS"] = "ALL_RECORDS";
1874
- SelectionMode["SOME_RECORDS"] = "SOME_RECORDS";
1875
- })(SelectionMode || (SelectionMode = {}));
1876
- export class SelectionInfo {
1877
- constructor(records, mode = SelectionMode.SOME_RECORDS, total, filters, sort) {
1878
- this._records = records;
1879
- this._total = total;
1880
- this.mode = mode;
1881
- this.filters = filters;
1882
- this.sort = sort;
1883
- }
1884
- get records() {
1885
- if (this.isAllRecords()) {
1886
- if (this.getAllRecords != undefined) {
1887
- return this.getAllRecords();
1888
- }
1889
- throw new Error("Erro interno: Impossível retornar os registros selecionados numa seleção virtual.");
1890
- }
1891
- return this._records;
1892
- }
1893
- get recordIds() {
1894
- const records = this.records;
1895
- if (records == undefined) {
1896
- return undefined;
1897
- }
1898
- return records.map(record => record.__record__id__);
1899
- }
1900
- get length() {
1901
- if (this.isAllRecords()) {
1902
- return this._total || 0;
1903
- }
1904
- return this.records == undefined ? 0 : this.records.length;
1905
- }
1906
- isAllRecords() {
1907
- return this.mode === SelectionMode.ALL_RECORDS;
1908
- }
1909
- isEmpty() {
1910
- return this.length === 0;
1911
- }
1912
- }
1832
+ export { Change, SelectionInfo, SelectionMode };
1913
1833
  //# sourceMappingURL=DataUnit.js.map