bkper-js 1.46.0 → 1.46.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.
- package/lib/index.d.ts +6 -0
- package/lib/model/Book.js +60 -10
- package/lib/model/Group.js +2 -2
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -745,6 +745,8 @@ export declare class Book {
|
|
|
745
745
|
|
|
746
746
|
|
|
747
747
|
|
|
748
|
+
|
|
749
|
+
|
|
748
750
|
constructor(payload?: bkper.Book);
|
|
749
751
|
/**
|
|
750
752
|
* @returns An immutable copy of the json payload
|
|
@@ -1094,6 +1096,10 @@ export declare class Book {
|
|
|
1094
1096
|
|
|
1095
1097
|
|
|
1096
1098
|
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
|
|
1097
1103
|
/**
|
|
1098
1104
|
* Gets a [[Group]] object
|
|
1099
1105
|
*
|
package/lib/model/Book.js
CHANGED
|
@@ -643,36 +643,75 @@ export class Book {
|
|
|
643
643
|
if (!idOrName || idOrName.trim() == '') {
|
|
644
644
|
return undefined;
|
|
645
645
|
}
|
|
646
|
+
let account;
|
|
647
|
+
// Try to get account by id
|
|
646
648
|
if (this.idAccountMap) {
|
|
647
|
-
|
|
649
|
+
account = this.idAccountMap.get(idOrName);
|
|
648
650
|
}
|
|
649
|
-
|
|
651
|
+
// Try to get account by name
|
|
652
|
+
if (!account && this.nameAccountMap) {
|
|
653
|
+
account = this.nameAccountMap.get(idOrName);
|
|
654
|
+
}
|
|
655
|
+
// Try to fetch account from server
|
|
656
|
+
if (!account) {
|
|
650
657
|
const accountPayload = yield AccountService.getAccount(this.getId(), idOrName);
|
|
651
658
|
if (accountPayload) {
|
|
652
|
-
|
|
659
|
+
account = new Account(this, accountPayload);
|
|
653
660
|
}
|
|
654
661
|
}
|
|
655
|
-
return
|
|
662
|
+
return account;
|
|
656
663
|
});
|
|
657
664
|
}
|
|
658
665
|
/** @internal */
|
|
659
666
|
updateGroupCache(group) {
|
|
667
|
+
this.updateGroupIdMap(group);
|
|
668
|
+
this.updateGroupNameMap(group);
|
|
669
|
+
if (this.idGroupMap) {
|
|
670
|
+
group.buildGroupTree(this.idGroupMap);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
/** @internal */
|
|
674
|
+
updateGroupIdMap(group) {
|
|
660
675
|
if (this.idGroupMap) {
|
|
661
676
|
const id = group.getId();
|
|
662
677
|
if (id) {
|
|
663
678
|
this.idGroupMap.set(id, group);
|
|
664
679
|
}
|
|
665
|
-
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
/** @internal */
|
|
683
|
+
updateGroupNameMap(group) {
|
|
684
|
+
if (this.nameGroupMap) {
|
|
685
|
+
const normalizedName = group.getNormalizedName();
|
|
686
|
+
if (normalizedName) {
|
|
687
|
+
this.nameGroupMap.set(normalizedName, group);
|
|
688
|
+
}
|
|
666
689
|
}
|
|
667
690
|
}
|
|
668
691
|
/** @internal */
|
|
669
692
|
updateAccountCache(account) {
|
|
693
|
+
this.updateAccountIdMap(account);
|
|
694
|
+
this.updateAccountNameMap(account);
|
|
695
|
+
if (this.idAccountMap || this.nameAccountMap) {
|
|
696
|
+
this.linkAccountsAndGroups(account);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
/** @internal */
|
|
700
|
+
updateAccountIdMap(account) {
|
|
670
701
|
if (this.idAccountMap) {
|
|
671
702
|
const id = account.getId();
|
|
672
703
|
if (id) {
|
|
673
704
|
this.idAccountMap.set(id, account);
|
|
674
705
|
}
|
|
675
|
-
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
/** @internal */
|
|
709
|
+
updateAccountNameMap(account) {
|
|
710
|
+
if (this.nameAccountMap) {
|
|
711
|
+
const normalizedName = account.getNormalizedName();
|
|
712
|
+
if (normalizedName) {
|
|
713
|
+
this.nameAccountMap.set(normalizedName, account);
|
|
714
|
+
}
|
|
676
715
|
}
|
|
677
716
|
}
|
|
678
717
|
/** @internal */
|
|
@@ -718,16 +757,23 @@ export class Book {
|
|
|
718
757
|
if (!idOrName || idOrName.trim() == '') {
|
|
719
758
|
return undefined;
|
|
720
759
|
}
|
|
760
|
+
let group;
|
|
761
|
+
// Try to get group by id
|
|
721
762
|
if (this.idGroupMap) {
|
|
722
|
-
|
|
763
|
+
group = this.idGroupMap.get(idOrName);
|
|
723
764
|
}
|
|
724
|
-
|
|
765
|
+
// Try to get group by name
|
|
766
|
+
if (!group && this.nameGroupMap) {
|
|
767
|
+
group = this.nameGroupMap.get(idOrName);
|
|
768
|
+
}
|
|
769
|
+
// Try to fetch group from server
|
|
770
|
+
if (!group) {
|
|
725
771
|
const groupPayload = yield GroupService.getGroup(this.getId(), idOrName);
|
|
726
772
|
if (groupPayload) {
|
|
727
|
-
|
|
773
|
+
group = new Group(this, groupPayload);
|
|
728
774
|
}
|
|
729
775
|
}
|
|
730
|
-
return
|
|
776
|
+
return group;
|
|
731
777
|
});
|
|
732
778
|
}
|
|
733
779
|
/**
|
|
@@ -751,6 +797,7 @@ export class Book {
|
|
|
751
797
|
}
|
|
752
798
|
let groupsObj = groups.map(group => new Group(this, group));
|
|
753
799
|
this.idGroupMap = new Map();
|
|
800
|
+
this.nameGroupMap = new Map();
|
|
754
801
|
for (const group of groupsObj) {
|
|
755
802
|
this.updateGroupCache(group);
|
|
756
803
|
}
|
|
@@ -780,6 +827,7 @@ export class Book {
|
|
|
780
827
|
}
|
|
781
828
|
let accountsObj = accounts.map(account => new Account(this, account));
|
|
782
829
|
this.idAccountMap = new Map();
|
|
830
|
+
this.nameAccountMap = new Map();
|
|
783
831
|
for (const account of accountsObj) {
|
|
784
832
|
this.updateAccountCache(account);
|
|
785
833
|
}
|
|
@@ -804,10 +852,12 @@ export class Book {
|
|
|
804
852
|
/** @internal */
|
|
805
853
|
clearGroupCache() {
|
|
806
854
|
this.idGroupMap = undefined;
|
|
855
|
+
this.nameGroupMap = undefined;
|
|
807
856
|
}
|
|
808
857
|
/** @internal */
|
|
809
858
|
clearAccountCache() {
|
|
810
859
|
this.idAccountMap = undefined;
|
|
860
|
+
this.nameAccountMap = undefined;
|
|
811
861
|
}
|
|
812
862
|
/** @internal */
|
|
813
863
|
setAccount(account, remove) {
|
package/lib/model/Group.js
CHANGED
|
@@ -343,12 +343,12 @@ export class Group {
|
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
/** @internal */
|
|
346
|
-
buildGroupTree(
|
|
346
|
+
buildGroupTree(idGroupMap) {
|
|
347
347
|
this.parent = undefined;
|
|
348
348
|
this.depth = undefined;
|
|
349
349
|
this.root = undefined;
|
|
350
350
|
if (this.payload.parent) {
|
|
351
|
-
const parentGroup =
|
|
351
|
+
const parentGroup = idGroupMap.get(this.payload.parent.id || "");
|
|
352
352
|
if (parentGroup) {
|
|
353
353
|
this.parent = parentGroup;
|
|
354
354
|
parentGroup.addChild(this);
|