@sankhyalabs/core 6.1.0-dev.2 → 6.1.0-dev.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.
Files changed (95) hide show
  1. package/.docs/classes/Change.md +11 -11
  2. package/.docs/classes/ColumnFilterManager.md +6 -6
  3. package/.docs/classes/DataUnit.md +157 -157
  4. package/.docs/classes/DataUnitLoaderUtils.md +6 -6
  5. package/.docs/classes/SelectionInfo.md +16 -16
  6. package/.docs/enumerations/ChangeOperation.md +4 -4
  7. package/.docs/enumerations/SelectionMode.md +2 -2
  8. package/.docs/functions/defaultDataLoader.md +1 -1
  9. package/.docs/interfaces/DUActionInterceptor.md +1 -1
  10. package/.docs/interfaces/PageRequest.md +3 -3
  11. package/.docs/interfaces/PaginationInfoBuilderParams.md +3 -3
  12. package/.docs/interfaces/QuickFilter.md +3 -3
  13. package/.docs/interfaces/Record.md +4 -4
  14. package/.docs/interfaces/SavedRecord.md +5 -5
  15. package/.docs/interfaces/WaitingChange.md +3 -3
  16. package/.docs/type-aliases/DataUnitEventOptions.md +1 -1
  17. package/dist/dataunit/Changes.d.ts +52 -0
  18. package/dist/dataunit/Changes.js +64 -0
  19. package/dist/dataunit/Changes.js.map +1 -0
  20. package/dist/dataunit/DataUnit.d.ts +9 -129
  21. package/dist/dataunit/DataUnit.js +87 -177
  22. package/dist/dataunit/DataUnit.js.map +1 -1
  23. package/dist/dataunit/DataUnitHelper.d.ts +2 -1
  24. package/dist/dataunit/DataUnitHelper.js.map +1 -1
  25. package/dist/dataunit/SelectionInfo.d.ts +16 -0
  26. package/dist/dataunit/SelectionInfo.js +39 -0
  27. package/dist/dataunit/SelectionInfo.js.map +1 -0
  28. package/dist/dataunit/interfaces/dataUnit.d.ts +61 -0
  29. package/dist/dataunit/interfaces/dataUnit.js +13 -0
  30. package/dist/dataunit/interfaces/dataUnit.js.map +1 -0
  31. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +2 -1
  32. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -1
  33. package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
  34. package/dist/dataunit/loading/LoadDataResponse.d.ts +1 -1
  35. package/dist/dataunit/sorting/FieldComparator.d.ts +1 -1
  36. package/dist/dataunit/state/slice/AddedRecordsSlice.d.ts +1 -1
  37. package/dist/dataunit/state/slice/ChangesSlice.d.ts +2 -1
  38. package/dist/dataunit/state/slice/ChangesSlice.js +2 -1
  39. package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
  40. package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
  41. package/dist/dataunit/state/slice/RecordsSlice.d.ts +1 -1
  42. package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
  43. package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
  44. package/dist/dataunit/state/slice/SelectionSlice.d.ts +2 -1
  45. package/dist/dataunit/state/slice/SelectionSlice.js +2 -1
  46. package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
  47. package/dist/dataunit/state/slice/SnapshotSlice.d.ts +1 -1
  48. package/dist/dataunit/state/slice/WaitingChangesSlice.d.ts +1 -1
  49. package/dist/index.d.ts +4 -1
  50. package/dist/index.js +4 -1
  51. package/dist/index.js.map +1 -1
  52. package/dist/utils/ColumnFilterManager.d.ts +2 -1
  53. package/dist/utils/ColumnFilterManager.js.map +1 -1
  54. package/dist/utils/SortingUtils.d.ts +1 -1
  55. package/package.json +2 -1
  56. package/reports/test-report.xml +648 -447
  57. package/src/dataunit/Changes.ts +77 -0
  58. package/src/dataunit/DataUnit.ts +242 -397
  59. package/src/dataunit/DataUnitHelper.ts +2 -1
  60. package/src/dataunit/SelectionInfo.ts +55 -0
  61. package/src/dataunit/interfaces/dataUnit.ts +71 -0
  62. package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +2 -1
  63. package/src/dataunit/loading/LoadDataRequest.ts +1 -1
  64. package/src/dataunit/loading/LoadDataResponse.ts +1 -1
  65. package/src/dataunit/sorting/FieldComparator.ts +1 -1
  66. package/src/dataunit/state/slice/AddedRecordsSlice.ts +1 -1
  67. package/src/dataunit/state/slice/ChangesSlice.ts +2 -1
  68. package/src/dataunit/state/slice/LoadingControlSlice.ts +1 -2
  69. package/src/dataunit/state/slice/RecordsSlice.ts +3 -2
  70. package/src/dataunit/state/slice/SelectionSlice.ts +2 -1
  71. package/src/dataunit/state/slice/SnapshotSlice.ts +1 -1
  72. package/src/dataunit/state/slice/WaitingChangesSlice.ts +1 -1
  73. package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +1 -1
  74. package/src/index.ts +4 -1
  75. package/src/utils/ColumnFilterManager.ts +2 -1
  76. package/src/utils/SortingUtils.ts +1 -1
  77. package/test/dataunit/AccessParentsDataUnit.spec.ts +69 -0
  78. package/test/dataunit/Actions.spec.ts +74 -0
  79. package/test/dataunit/Change.spec.ts +66 -0
  80. package/test/dataunit/FieldManager.spec.ts +286 -0
  81. package/test/dataunit/FilterSortsLockersAndObservers.spec.ts +339 -0
  82. package/test/dataunit/InfoManager.spec.ts +254 -0
  83. package/test/dataunit/LoadDataAndMetadata.spec.ts +269 -0
  84. package/test/dataunit/RecodsSelection.spec.ts +229 -0
  85. package/test/dataunit/RecordsManager.spec.ts +323 -0
  86. package/test/dataunit/SavingData.spec.ts +206 -0
  87. package/test/dataunit/SelectionInfo.spec.ts +143 -0
  88. package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +2 -1
  89. package/test/dataunit/loader/utils/createDataUnitMock.ts +34 -0
  90. package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +1 -1
  91. package/test/dataunit/resources/metadata.ts +39 -0
  92. package/test/dataunit/resources/records.ts +29 -0
  93. package/test/util/ColumnFilterManager.spec.ts +2 -1
  94. package/tsconfig.json +1 -0
  95. package/src/dataunit/test/DataUnit.spec.ts +0 -44
@@ -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
  */
@@ -594,7 +597,7 @@ export default class DataUnit {
594
597
  * @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
595
598
  * @returns - Informações sobre a seleção.
596
599
  */
597
- updatePageSelection(selection: Array<string>, executionCtx?: ExecutionContext): Promise<SelectionInfo | undefined>;
600
+ updatePageSelection(selection?: Array<string>, executionCtx?: ExecutionContext): Promise<SelectionInfo | undefined>;
598
601
  private updatePageSelectionAll;
599
602
  /**
600
603
  * Seleciona todos os registros da página.
@@ -645,7 +648,7 @@ export default class DataUnit {
645
648
  *
646
649
  *
647
650
  */
648
- nextRecord(executionCtx?: ExecutionContext): void;
651
+ nextRecord(executionCtx?: ExecutionContext): Promise<void>;
649
652
  /**
650
653
  *
651
654
  * Seleciona o registro anterior.
@@ -653,7 +656,7 @@ export default class DataUnit {
653
656
  * @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
654
657
  *
655
658
  */
656
- previousRecord(executionCtx?: ExecutionContext): void;
659
+ previousRecord(executionCtx?: ExecutionContext): Promise<void>;
657
660
  /**
658
661
  *
659
662
  * Cancela edição do registro atual.
@@ -902,7 +905,7 @@ export default class DataUnit {
902
905
  * @param fieldName - nome do campo para ficar invisível.
903
906
  *
904
907
  */
905
- hideField(fieldName: string, options: HideFieldOptions): void;
908
+ hideField(fieldName: string, options?: HideFieldOptions): void;
906
909
  /**
907
910
  *
908
911
  * Deixa um campo do DataUnit visível
@@ -959,130 +962,7 @@ export default class DataUnit {
959
962
  /**
960
963
  * Retornar o campo de origem dos dados caso exista mapeamento
961
964
  */
962
- getSourceFieldValue(targetFieldName: string): string | undefined;
965
+ getSourceFieldValue(sourceFieldName: string): string | undefined;
963
966
  private processLoadingLockers;
964
967
  }
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
- };
968
+ 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
  /**
@@ -859,14 +864,12 @@ export default class DataUnit {
859
864
  */
860
865
  copySelected(executionCtx) {
861
866
  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
- }
867
+ if (selectionInfo.isAllRecords()) {
868
+ throw new Error("Erro interno: Impossível copiar os registros selecionados pois a seleção atual é virtual.");
869
+ }
870
+ const selectedRecords = selectionInfo.records;
871
+ if (selectedRecords.length) {
872
+ this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
870
873
  }
871
874
  }
872
875
  getRecordsByDataUnit(records) {
@@ -1147,7 +1150,6 @@ export default class DataUnit {
1147
1150
  *
1148
1151
  **/
1149
1152
  getSelectionInfo() {
1150
- var _a;
1151
1153
  const selectionInfo = getSelectionInfo(this._stateManager);
1152
1154
  selectionInfo.getAllRecords = () => {
1153
1155
  var _a, _b;
@@ -1160,7 +1162,7 @@ export default class DataUnit {
1160
1162
  };
1161
1163
  if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
1162
1164
  const sortingFunction = SortingUtils.getSortingFunction(this, selectionInfo.sort);
1163
- (_a = selectionInfo.records) === null || _a === void 0 ? void 0 : _a.sort(sortingFunction);
1165
+ selectionInfo.records.sort(sortingFunction);
1164
1166
  }
1165
1167
  return selectionInfo;
1166
1168
  }
@@ -1200,24 +1202,26 @@ export default class DataUnit {
1200
1202
  *
1201
1203
  */
1202
1204
  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);
1205
+ return __awaiter(this, void 0, void 0, function* () {
1206
+ if (!hasNext(this._stateManager)) {
1207
+ if (hasMorePages(this._stateManager)) {
1208
+ yield this.nextPage({
1209
+ before: (act) => {
1210
+ if (executionCtx && executionCtx.before) {
1211
+ act = executionCtx.before(act);
1212
+ }
1213
+ return act;
1214
+ },
1215
+ after: () => {
1216
+ this.selectFirst(executionCtx);
1209
1217
  }
1210
- return act;
1211
- },
1212
- after: act => {
1213
- this.selectFirst(executionCtx);
1214
- }
1215
- });
1218
+ });
1219
+ }
1216
1220
  }
1217
- }
1218
- else {
1219
- this.dispatchAction(Action.NEXT_SELECTED, undefined, executionCtx);
1220
- }
1221
+ else {
1222
+ this.dispatchAction(Action.NEXT_SELECTED, undefined, executionCtx);
1223
+ }
1224
+ });
1221
1225
  }
1222
1226
  /**
1223
1227
  *
@@ -1227,24 +1231,26 @@ export default class DataUnit {
1227
1231
  *
1228
1232
  */
1229
1233
  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);
1234
+ return __awaiter(this, void 0, void 0, function* () {
1235
+ if (!hasPrevious(this._stateManager)) {
1236
+ if (hasPreviousPages(this._stateManager)) {
1237
+ yield this.previousPage({
1238
+ before: (act) => {
1239
+ if (executionCtx && executionCtx.before) {
1240
+ act = executionCtx.before(act);
1241
+ }
1242
+ return act;
1243
+ },
1244
+ after: () => {
1245
+ this.selectLast(executionCtx);
1236
1246
  }
1237
- return act;
1238
- },
1239
- after: act => {
1240
- this.selectLast(executionCtx);
1241
- }
1242
- });
1247
+ });
1248
+ }
1243
1249
  }
1244
- }
1245
- else {
1246
- this.dispatchAction(Action.PREVIOUS_SELECTED, undefined, executionCtx);
1247
- }
1250
+ else {
1251
+ this.dispatchAction(Action.PREVIOUS_SELECTED, undefined, executionCtx);
1252
+ }
1253
+ });
1248
1254
  }
1249
1255
  /**
1250
1256
  *
@@ -1296,7 +1302,7 @@ export default class DataUnit {
1296
1302
  *
1297
1303
  */
1298
1304
  childrenIsDirty() {
1299
- for (let [key, dataUnitChild] of this._childByName) {
1305
+ for (let [_, dataUnitChild] of this._childByName) {
1300
1306
  if (dataUnitChild.isDirty())
1301
1307
  return true;
1302
1308
  }
@@ -1656,7 +1662,10 @@ export default class DataUnit {
1656
1662
  */
1657
1663
  enableField(fieldName) {
1658
1664
  const fieldDescriptor = this.getField(fieldName);
1659
- if ((fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.readOnly) === true) {
1665
+ if (!fieldDescriptor) {
1666
+ return;
1667
+ }
1668
+ if (fieldDescriptor.readOnly) {
1660
1669
  fieldDescriptor.readOnly = false;
1661
1670
  this.metadata = Object.assign({}, this.metadata);
1662
1671
  }
@@ -1669,7 +1678,10 @@ export default class DataUnit {
1669
1678
  */
1670
1679
  disableField(fieldName) {
1671
1680
  const fieldDescriptor = this.getField(fieldName);
1672
- if ((fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.readOnly) === false) {
1681
+ if (!fieldDescriptor) {
1682
+ return;
1683
+ }
1684
+ if (!fieldDescriptor.readOnly) {
1673
1685
  fieldDescriptor.readOnly = true;
1674
1686
  this.metadata = Object.assign({}, this.metadata);
1675
1687
  }
@@ -1682,9 +1694,14 @@ export default class DataUnit {
1682
1694
  */
1683
1695
  hideField(fieldName, options) {
1684
1696
  const fieldDescriptor = this.getField(fieldName);
1685
- if ((fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.visible) === true) {
1697
+ if (!fieldDescriptor) {
1698
+ return;
1699
+ }
1700
+ if (fieldDescriptor.visible) {
1686
1701
  fieldDescriptor.visible = false;
1687
- fieldDescriptor.properties = Object.assign(Object.assign({}, fieldDescriptor.properties), { visibleOnConfig: options === null || options === void 0 ? void 0 : options.visibleOnConfig });
1702
+ if (options) {
1703
+ fieldDescriptor.properties = Object.assign(Object.assign({}, fieldDescriptor.properties), { visibleOnConfig: options.visibleOnConfig });
1704
+ }
1688
1705
  this.metadata = Object.assign({}, this.metadata);
1689
1706
  }
1690
1707
  }
@@ -1696,7 +1713,10 @@ export default class DataUnit {
1696
1713
  */
1697
1714
  showField(fieldName) {
1698
1715
  const fieldDescriptor = this.getField(fieldName);
1699
- if ((fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.visible) === false) {
1716
+ if (!fieldDescriptor) {
1717
+ return;
1718
+ }
1719
+ if (!fieldDescriptor.visible) {
1700
1720
  fieldDescriptor.visible = true;
1701
1721
  this.metadata = Object.assign({}, this.metadata);
1702
1722
  }
@@ -1766,11 +1786,11 @@ export default class DataUnit {
1766
1786
  * @returns Retorna uma função responsável por liberar o lock adicionado.
1767
1787
  */
1768
1788
  addLoadingLocker() {
1769
- let loadingLockerResolver;
1789
+ let loadingLockerResolver = () => { };
1770
1790
  this._loadingLockers.push(new Promise((resolve) => {
1771
1791
  loadingLockerResolver = resolve;
1772
1792
  }));
1773
- return loadingLockerResolver || Promise.resolve;
1793
+ return loadingLockerResolver;
1774
1794
  }
1775
1795
  set allowReleaseCallbacks(allow) {
1776
1796
  this._allowReleaseCallbacks = allow;
@@ -1784,8 +1804,8 @@ export default class DataUnit {
1784
1804
  /**
1785
1805
  * Retornar o campo de origem dos dados caso exista mapeamento
1786
1806
  */
1787
- getSourceFieldValue(targetFieldName) {
1788
- return this._fieldSourceValue.get(targetFieldName);
1807
+ getSourceFieldValue(sourceFieldName) {
1808
+ return this._fieldSourceValue.get(sourceFieldName);
1789
1809
  }
1790
1810
  processLoadingLockers() {
1791
1811
  return __awaiter(this, void 0, void 0, function* () {
@@ -1799,115 +1819,5 @@ export default class DataUnit {
1799
1819
  DataUnit.CHANGING_PAGE_LOADING_SOURCE = "CHANGING_PAGE_LOADING_SOURCE";
1800
1820
  DataUnit.ALL_RECORDS_SELECTION_SOURCE = "ALL_RECORDS_SELECTION_SOURCE";
1801
1821
  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
- }
1822
+ export { Change, SelectionInfo, SelectionMode };
1913
1823
  //# sourceMappingURL=DataUnit.js.map