bkper-js 1.35.2 → 1.35.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +6 -4
- package/lib/model/Book.js +7 -1
- package/lib/model/Group.js +21 -4
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -723,6 +723,7 @@ export declare class Book {
|
|
|
723
723
|
|
|
724
724
|
|
|
725
725
|
|
|
726
|
+
|
|
726
727
|
constructor(payload?: bkper.Book);
|
|
727
728
|
/**
|
|
728
729
|
* @returns An immutable copy of the json payload
|
|
@@ -1737,10 +1738,10 @@ export declare class File {
|
|
|
1737
1738
|
*/
|
|
1738
1739
|
export declare class Group {
|
|
1739
1740
|
payload: bkper.Group;
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1741
|
+
|
|
1742
|
+
|
|
1743
|
+
|
|
1744
|
+
|
|
1744
1745
|
|
|
1745
1746
|
|
|
1746
1747
|
constructor(book: Book, payload?: bkper.Group);
|
|
@@ -1855,6 +1856,7 @@ export declare class Group {
|
|
|
1855
1856
|
getChildren(): Group[];
|
|
1856
1857
|
|
|
1857
1858
|
|
|
1859
|
+
|
|
1858
1860
|
/**
|
|
1859
1861
|
* Retrieves all descendant Groups of the current Group.
|
|
1860
1862
|
*
|
package/lib/model/Book.js
CHANGED
|
@@ -579,12 +579,17 @@ export class Book {
|
|
|
579
579
|
return this.idGroupMap;
|
|
580
580
|
}
|
|
581
581
|
/** @internal */
|
|
582
|
-
updateGroupCache(group) {
|
|
582
|
+
updateGroupCache(group, previousParentId) {
|
|
583
|
+
var _a;
|
|
583
584
|
if (this.idGroupMap) {
|
|
584
585
|
const id = group.getId();
|
|
585
586
|
if (id) {
|
|
586
587
|
this.idGroupMap.set(id, group);
|
|
587
588
|
}
|
|
589
|
+
const parentId = (_a = group.payload.parent) === null || _a === void 0 ? void 0 : _a.id;
|
|
590
|
+
if ((previousParentId || '') !== (parentId || '')) {
|
|
591
|
+
group.destroyGroupTree(this.idGroupMap, previousParentId);
|
|
592
|
+
}
|
|
588
593
|
group.buildGroupTree(this.idGroupMap);
|
|
589
594
|
}
|
|
590
595
|
}
|
|
@@ -704,6 +709,7 @@ export class Book {
|
|
|
704
709
|
}
|
|
705
710
|
let groupsObj = groups.map(group => new Group(this, group));
|
|
706
711
|
this.idGroupMap = new Map();
|
|
712
|
+
this.parentIdGroupsMap = new Map();
|
|
707
713
|
for (const group of groupsObj) {
|
|
708
714
|
this.updateGroupCache(group);
|
|
709
715
|
}
|
package/lib/model/Group.js
CHANGED
|
@@ -21,6 +21,7 @@ import { Account } from './Account.js';
|
|
|
21
21
|
*/
|
|
22
22
|
export class Group {
|
|
23
23
|
constructor(book, payload) {
|
|
24
|
+
/** @internal */
|
|
24
25
|
this.children = new Map();
|
|
25
26
|
this.book = book;
|
|
26
27
|
this.payload = payload || {
|
|
@@ -221,6 +222,7 @@ export class Group {
|
|
|
221
222
|
const id = child.getId();
|
|
222
223
|
if (id) {
|
|
223
224
|
this.children.set(id, child);
|
|
225
|
+
this.updateBookParentIdGroupsMap();
|
|
224
226
|
}
|
|
225
227
|
}
|
|
226
228
|
/** @internal */
|
|
@@ -228,6 +230,15 @@ export class Group {
|
|
|
228
230
|
const id = child.getId();
|
|
229
231
|
if (id) {
|
|
230
232
|
this.children.delete(id);
|
|
233
|
+
this.updateBookParentIdGroupsMap();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/** @internal */
|
|
237
|
+
updateBookParentIdGroupsMap() {
|
|
238
|
+
var _a;
|
|
239
|
+
const id = this.getId();
|
|
240
|
+
if (id) {
|
|
241
|
+
(_a = this.book.parentIdGroupsMap) === null || _a === void 0 ? void 0 : _a.set(id, this.children);
|
|
231
242
|
}
|
|
232
243
|
}
|
|
233
244
|
/**
|
|
@@ -340,9 +351,13 @@ export class Group {
|
|
|
340
351
|
}
|
|
341
352
|
}
|
|
342
353
|
/** @internal */
|
|
343
|
-
destroyGroupTree(groupsMap) {
|
|
344
|
-
|
|
345
|
-
|
|
354
|
+
destroyGroupTree(groupsMap, parentId) {
|
|
355
|
+
var _a;
|
|
356
|
+
if (!parentId) {
|
|
357
|
+
parentId = (_a = this.payload.parent) === null || _a === void 0 ? void 0 : _a.id;
|
|
358
|
+
}
|
|
359
|
+
if (parentId) {
|
|
360
|
+
const parentGroup = groupsMap.get(parentId);
|
|
346
361
|
if (parentGroup) {
|
|
347
362
|
parentGroup.removeChild(this);
|
|
348
363
|
}
|
|
@@ -387,8 +402,10 @@ export class Group {
|
|
|
387
402
|
*/
|
|
388
403
|
update() {
|
|
389
404
|
return __awaiter(this, void 0, void 0, function* () {
|
|
405
|
+
var _a;
|
|
406
|
+
const previousParentId = (_a = this.payload.parent) === null || _a === void 0 ? void 0 : _a.id;
|
|
390
407
|
this.payload = yield GroupService.updateGroup(this.book.getId(), this.payload);
|
|
391
|
-
this.book.updateGroupCache(this);
|
|
408
|
+
this.book.updateGroupCache(this, previousParentId);
|
|
392
409
|
return this;
|
|
393
410
|
});
|
|
394
411
|
}
|