Drarig29 / brackets-manager.js

A simple library to manage tournament brackets (round-robin, single elimination, double elimination).
https://drarig29.github.io/brackets-docs
MIT License
245 stars 38 forks source link

Get <Table> not found for the case import data without normalizeIds #134

Closed yongshun950824 closed 2 years ago

yongshun950824 commented 2 years ago

The opt-in normalized Ids feature is introduced in 1.4.1.


Issue:

However, when I go through the code example:

https://github.com/Drarig29/brackets-manager.js/blob/18900570b0d60a9c2bb9cdf1233672e25ddfe859/src/reset.ts#L14-L15

I think the below part will lead to the error:

"Stage/Group/Round/Match/Match Game not found"

when the id not supposed to be index.

if (typeof arg === 'number') {
    return new Promise<T[]>((resolve) => {
        // @ts-ignore
        resolve(clone(this.data[table][arg]));
    });
}

https://github.com/Drarig29/brackets-storage/blob/30f45dc8eb4fa5b0df411d517aa78ab473560d75/brackets-memory-db/index.ts#L136-L141

Step to trigger:

  1. Import data without normalizeIds = true.
  2. Having data with Id with large number, example: 634

Affected code:

Within 380 references

image

Propose idea / solution:

Either in brackets-manager.js for the related code (mentioned in Screenshot) have to modify as:

await this.storage.select(/* Table */, { id: /* id */ });

Or search by id instead of by index.

P.S.: The below code is just a concept

if (typeof arg === 'number') {
    return new Promise<T[]>((resolve) => {
        // @ts-ignore
        resolve(clone(this.data[table].find(x => x.id == args)));
    });
}

Note:

This issue is not urgent as currently, I force the ids must be normalized.

await manager.import(data, true);

Hope you take time to fix it. Thanks in advance. =)

Drarig29 commented 2 years ago

It's funny because I fixed this on the same day without reading your issue.

It was fixed the evening of the same day: https://github.com/Drarig29/brackets-storage/commit/d8631f3cb11841eab2ff965cfd6b07e107af3019

Thanks for the issue though 😉