Numerous Bug Fixes
Some checks failed
Automated Container Build / build-and-push (push) Failing after 8s
Some checks failed
Automated Container Build / build-and-push (push) Failing after 8s
This commit is contained in:
parent
02eefdac0e
commit
267d429122
959 changed files with 145571 additions and 221 deletions
21
frontend/node_modules/make-cancellable-promise/LICENSE
generated
vendored
Normal file
21
frontend/node_modules/make-cancellable-promise/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019–2024 Wojciech Maj
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
80
frontend/node_modules/make-cancellable-promise/README.md
generated
vendored
Normal file
80
frontend/node_modules/make-cancellable-promise/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
[](https://www.npmjs.com/package/make-cancellable-promise)  [](https://github.com/wojtekmaj/make-cancellable-promise/actions)
|
||||
|
||||
# Make-Cancellable-Promise
|
||||
|
||||
Make any Promise cancellable.
|
||||
|
||||
## tl;dr
|
||||
|
||||
- Install by executing `npm install make-cancellable-promise` or `yarn add make-cancellable-promise`.
|
||||
- Import by adding `import makeCancellablePromise from 'make-cancellable-promise`.
|
||||
- Do stuff with it!
|
||||
```ts
|
||||
const { promise, cancel } = makeCancellablePromise(myPromise);
|
||||
```
|
||||
|
||||
## User guide
|
||||
|
||||
### makeCancellablePromise(myPromise)
|
||||
|
||||
A function that returns an object with two properties:
|
||||
|
||||
`promise` and `cancel`. `promise` is a wrapped around your promise. `cancel` is a function which stops `.then()` and `.catch()` from working on `promise`, even if promise passed to `makeCancellablePromise` resolves or rejects.
|
||||
|
||||
#### Usage
|
||||
|
||||
```ts
|
||||
const { promise, cancel } = makeCancellablePromise(myPromise);
|
||||
```
|
||||
|
||||
Typically, you'd want to use `makeCancellablePromise` in React components. If you call `setState` on an unmounted component, React will throw an error.
|
||||
|
||||
Here's how you can use `makeCancellablePromise` with React:
|
||||
|
||||
```tsx
|
||||
function MyComponent() {
|
||||
const [status, setStatus] = useState('initial');
|
||||
|
||||
useEffect(() => {
|
||||
const { promise, cancel } = makeCancellable(fetchData());
|
||||
|
||||
promise.then(() => setStatus('success')).catch(() => setStatus('error'));
|
||||
|
||||
return () => {
|
||||
cancel();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const text = (() => {
|
||||
switch (status) {
|
||||
case 'pending':
|
||||
return 'Fetching…';
|
||||
case 'success':
|
||||
return 'Success';
|
||||
case 'error':
|
||||
return 'Error!';
|
||||
default:
|
||||
return 'Click to fetch';
|
||||
}
|
||||
})();
|
||||
|
||||
return <p>{text}</p>;
|
||||
}
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The MIT License.
|
||||
|
||||
## Author
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td >
|
||||
<img src="https://avatars.githubusercontent.com/u/5426427?v=4&s=128" width="64" height="64" alt="Wojciech Maj">
|
||||
</td>
|
||||
<td>
|
||||
<a href="https://github.com/wojtekmaj">Wojciech Maj</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
54
frontend/node_modules/make-cancellable-promise/package.json
generated
vendored
Normal file
54
frontend/node_modules/make-cancellable-promise/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"name": "make-cancellable-promise",
|
||||
"version": "2.0.0",
|
||||
"description": "Make any Promise cancellable.",
|
||||
"type": "module",
|
||||
"sideEffects": false,
|
||||
"main": "./dist/index.js",
|
||||
"source": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./*": "./*"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc --project tsconfig.build.json",
|
||||
"clean": "rimraf dist",
|
||||
"format": "biome format",
|
||||
"lint": "biome lint",
|
||||
"prepack": "yarn clean && yarn build",
|
||||
"test": "yarn lint && yarn tsc && yarn format && yarn unit",
|
||||
"tsc": "tsc",
|
||||
"unit": "vitest"
|
||||
},
|
||||
"keywords": [
|
||||
"promise",
|
||||
"promise-cancelling"
|
||||
],
|
||||
"author": {
|
||||
"name": "Wojciech Maj",
|
||||
"email": "kontakt@wojtekmaj.pl"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.9.0",
|
||||
"husky": "^9.0.0",
|
||||
"rimraf": "^6.0.0",
|
||||
"typescript": "^5.5.2",
|
||||
"vitest": "^3.0.5"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"provenance": true
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/wojtekmaj/make-cancellable-promise.git"
|
||||
},
|
||||
"funding": "https://github.com/wojtekmaj/make-cancellable-promise?sponsor=1",
|
||||
"packageManager": "yarn@4.3.1"
|
||||
}
|
||||
79
frontend/node_modules/make-cancellable-promise/src/index.spec.ts
generated
vendored
Normal file
79
frontend/node_modules/make-cancellable-promise/src/index.spec.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import makeCancellablePromise from './index.js';
|
||||
|
||||
vi.useFakeTimers();
|
||||
|
||||
describe('makeCancellablePromise()', () => {
|
||||
function resolveInFiveSeconds(): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve('Success');
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
function rejectInFiveSeconds() {
|
||||
return new Promise((_resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
reject(new Error('Error'));
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
it('resolves promise if not cancelled', async () => {
|
||||
const resolve = vi.fn();
|
||||
const reject = vi.fn();
|
||||
|
||||
const { promise } = makeCancellablePromise(resolveInFiveSeconds());
|
||||
|
||||
vi.advanceTimersByTime(5000);
|
||||
await promise.then(resolve).catch(reject);
|
||||
|
||||
expect(resolve).toHaveBeenCalledWith('Success');
|
||||
expect(reject).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects promise if not cancelled', async () => {
|
||||
const resolve = vi.fn();
|
||||
const reject = vi.fn();
|
||||
|
||||
const { promise } = makeCancellablePromise(rejectInFiveSeconds());
|
||||
|
||||
vi.runAllTimers();
|
||||
await promise.then(resolve).catch(reject);
|
||||
|
||||
expect(resolve).not.toHaveBeenCalled();
|
||||
expect(reject).toHaveBeenCalledWith(expect.any(Error));
|
||||
});
|
||||
|
||||
it('does not resolve promise if cancelled', async () => {
|
||||
const resolve = vi.fn();
|
||||
const reject = vi.fn();
|
||||
|
||||
const { promise, cancel } = makeCancellablePromise(rejectInFiveSeconds());
|
||||
promise.then(resolve).catch(reject);
|
||||
|
||||
vi.advanceTimersByTime(2500);
|
||||
cancel();
|
||||
vi.advanceTimersByTime(2500);
|
||||
|
||||
expect(resolve).not.toHaveBeenCalled();
|
||||
expect(reject).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not reject promise if cancelled', () => {
|
||||
const resolve = vi.fn();
|
||||
const reject = vi.fn();
|
||||
|
||||
const { promise, cancel } = makeCancellablePromise(rejectInFiveSeconds());
|
||||
promise.then(resolve).catch(reject);
|
||||
|
||||
vi.advanceTimersByTime(2500);
|
||||
cancel();
|
||||
vi.advanceTimersByTime(2500);
|
||||
|
||||
expect(resolve).not.toHaveBeenCalled();
|
||||
expect(reject).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
19
frontend/node_modules/make-cancellable-promise/src/index.ts
generated
vendored
Normal file
19
frontend/node_modules/make-cancellable-promise/src/index.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
export default function makeCancellablePromise<T>(promise: Promise<T>): {
|
||||
promise: Promise<T>;
|
||||
cancel(): void;
|
||||
} {
|
||||
let isCancelled = false;
|
||||
|
||||
const wrappedPromise: Promise<T> = new Promise((resolve, reject) => {
|
||||
promise
|
||||
.then((value) => !isCancelled && resolve(value))
|
||||
.catch((error) => !isCancelled && reject(error));
|
||||
});
|
||||
|
||||
return {
|
||||
promise: wrappedPromise,
|
||||
cancel() {
|
||||
isCancelled = true;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in a new issue