This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

21
node_modules/combine-promises/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Sébastien Lorber
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.

105
node_modules/combine-promises/README.md generated vendored Normal file
View File

@@ -0,0 +1,105 @@
# Combine-Promises
[![NPM](https://img.shields.io/npm/dm/combine-promises.svg)](https://www.npmjs.com/package/combine-promises)
[![CI](https://github.com/slorber/combine-promises/actions/workflows/main.yml/badge.svg)](https://github.com/slorber/combine-promises/actions/workflows/main.yml)
![Size min](https://img.shields.io/bundlephobia/min/combine-promises.svg)
![Size minzip](https://img.shields.io/bundlephobia/minzip/combine-promises.svg)
Like `Promise.all([])` but for objects.
```ts
import combinePromises from 'combine-promises';
const { user, company } = await combinePromises({
user: fetchUser(),
company: fetchCompany(),
});
```
Why:
- Insensitive to destructuring order
- Simpler async functional code
Features:
- TypeScript support
- Lightweight
- Feature complete
- Well-tested
- ESM / CJS
---
# Sponsor
**[ThisWeekInReact.com](https://thisweekinreact.com)**: the best newsletter to stay up-to-date with the React ecosystem:
[![ThisWeekInReact.com banner](https://user-images.githubusercontent.com/749374/136185889-ebdb67cd-ec78-4655-b88b-79a6c134acd2.png)](https://thisweekinreact.com)
---
## Install
```
npm install combine-promises
// OR
yarn add combine-promises
```
## TypeScript support
Good, native and strict TypeScript support:
- Return type correctly inferred from the input object
- All object values should be async
- Only accept objects (reject arrays, null, undefined...)
```ts
const result: { user: User; company: Company } = await combinePromises({
user: fetchUser(),
company: fetchCompany(),
});
```
## Insensitive to destructuring order
A common error with `Promise.all` is to have a typo in the destructuring order.
```js
// Bad: destructuring order reversed
const [company, user] = await Promise.all([fetchUser(), fetchCompany()]);
```
This becomes more dangerous as size of the promises array grows.
With `combinePromises`, you are using explicit names instead of array indices, which makes the code more robust and not sensitive to destructuring order:
```js
// Good: we don't care about the order anymore
const { company, user } = await combinePromises({
user: fetchUser(),
company: fetchCompany(),
});
```
## Simpler async functional code
Suppose you have an object representing a friendship like `{user1: "userId-1", user2: "userId-2"}`, and you want to transform it to `{user1: User, user2: User}`.
You can easily do that:
```js
import combinePromises from 'combine-promises';
import { mapValues } from 'lodash'; // can be replaced by vanilla ES if you prefer
const friendsIds = { user1: 'userId-1', user2: 'userId-2' };
const friends = await combinePromises(mapValues(friendsIds, fetchUserById));
```
Without this library: good luck to keep your code simple.
## Inspirations
Name inspired by [combineReducers](https://redux.js.org/api/combinereducers) from Redux.

View File

@@ -0,0 +1,26 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function combinePromises(obj) {
if (obj === null) {
return Promise.reject(new Error('combinePromises does not handle null argument'));
}
if (typeof obj !== 'object') {
return Promise.reject(new Error("combinePromises does not handle argument of type " + typeof obj));
}
var keys = Object.keys(obj); // not using async/await on purpose, otherwise lib outputs large _asyncToGenerator code in dist
return Promise.all(Object.values(obj)).then(function (values) {
var result = {};
values.forEach(function (v, i) {
result[keys[i]] = v;
});
return result;
});
}
exports.default = combinePromises;
//# sourceMappingURL=combine-promises.cjs.development.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"combine-promises.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["type UnwrapPromise<P extends unknown> = P extends PromiseLike<infer V> ? V : P;\n\ntype Input = Record<string | number | symbol, unknown>;\n\ntype Result<Obj extends Input> = {\n [P in keyof Obj]: UnwrapPromise<Obj[P]>;\n};\n\nexport default function combinePromises<Obj extends Input>(\n obj: Obj\n): Promise<Result<Obj>> {\n if (obj === null) {\n return Promise.reject(\n new Error('combinePromises does not handle null argument')\n );\n }\n if (typeof obj !== 'object') {\n return Promise.reject(\n new Error(\n `combinePromises does not handle argument of type ${typeof obj}`\n )\n );\n }\n\n const keys = Object.keys(obj);\n\n // not using async/await on purpose, otherwise lib outputs large _asyncToGenerator code in dist\n return Promise.all(Object.values(obj)).then(values => {\n const result: any = {};\n values.forEach((v, i) => {\n result[keys[i]] = v;\n });\n return result;\n });\n}\n"],"names":["combinePromises","obj","Promise","reject","Error","keys","Object","all","values","then","result","forEach","v","i"],"mappings":";;;;SAQwBA,gBACtBC;AAEA,MAAIA,GAAG,KAAK,IAAZ,EAAkB;AAChB,WAAOC,OAAO,CAACC,MAAR,CACL,IAAIC,KAAJ,CAAU,+CAAV,CADK,CAAP;AAGD;;AACD,MAAI,OAAOH,GAAP,KAAe,QAAnB,EAA6B;AAC3B,WAAOC,OAAO,CAACC,MAAR,CACL,IAAIC,KAAJ,uDACsD,OAAOH,GAD7D,CADK,CAAP;AAKD;;AAED,MAAMI,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAYJ,GAAZ,CAAb;;AAGA,SAAOC,OAAO,CAACK,GAAR,CAAYD,MAAM,CAACE,MAAP,CAAcP,GAAd,CAAZ,EAAgCQ,IAAhC,CAAqC,UAAAD,MAAM;AAChD,QAAME,MAAM,GAAQ,EAApB;AACAF,IAAAA,MAAM,CAACG,OAAP,CAAe,UAACC,CAAD,EAAIC,CAAJ;AACbH,MAAAA,MAAM,CAACL,IAAI,CAACQ,CAAD,CAAL,CAAN,GAAkBD,CAAlB;AACD,KAFD;AAGA,WAAOF,MAAP;AACD,GANM,CAAP;AAOD;;;;"}

View File

@@ -0,0 +1,2 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(e){if(null===e)return Promise.reject(new Error("combinePromises does not handle null argument"));if("object"!=typeof e)return Promise.reject(new Error("combinePromises does not handle argument of type "+typeof e));var r=Object.keys(e);return Promise.all(Object.values(e)).then((function(e){var t={};return e.forEach((function(e,o){t[r[o]]=e})),t}))};
//# sourceMappingURL=combine-promises.cjs.production.min.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"combine-promises.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["type UnwrapPromise<P extends unknown> = P extends PromiseLike<infer V> ? V : P;\n\ntype Input = Record<string | number | symbol, unknown>;\n\ntype Result<Obj extends Input> = {\n [P in keyof Obj]: UnwrapPromise<Obj[P]>;\n};\n\nexport default function combinePromises<Obj extends Input>(\n obj: Obj\n): Promise<Result<Obj>> {\n if (obj === null) {\n return Promise.reject(\n new Error('combinePromises does not handle null argument')\n );\n }\n if (typeof obj !== 'object') {\n return Promise.reject(\n new Error(\n `combinePromises does not handle argument of type ${typeof obj}`\n )\n );\n }\n\n const keys = Object.keys(obj);\n\n // not using async/await on purpose, otherwise lib outputs large _asyncToGenerator code in dist\n return Promise.all(Object.values(obj)).then(values => {\n const result: any = {};\n values.forEach((v, i) => {\n result[keys[i]] = v;\n });\n return result;\n });\n}\n"],"names":["obj","Promise","reject","Error","keys","Object","all","values","then","result","forEach","v","i"],"mappings":"6FASEA,MAEY,OAARA,SACKC,QAAQC,OACb,IAAIC,MAAM,qDAGK,iBAARH,SACFC,QAAQC,OACb,IAAIC,iEACyDH,QAK3DI,EAAOC,OAAOD,KAAKJ,UAGlBC,QAAQK,IAAID,OAAOE,OAAOP,IAAMQ,MAAK,SAAAD,OACpCE,EAAc,UACpBF,EAAOG,SAAQ,SAACC,EAAGC,GACjBH,EAAOL,EAAKQ,IAAMD,KAEbF"}

View File

@@ -0,0 +1,22 @@
function combinePromises(obj) {
if (obj === null) {
return Promise.reject(new Error('combinePromises does not handle null argument'));
}
if (typeof obj !== 'object') {
return Promise.reject(new Error("combinePromises does not handle argument of type " + typeof obj));
}
var keys = Object.keys(obj); // not using async/await on purpose, otherwise lib outputs large _asyncToGenerator code in dist
return Promise.all(Object.values(obj)).then(function (values) {
var result = {};
values.forEach(function (v, i) {
result[keys[i]] = v;
});
return result;
});
}
export default combinePromises;
//# sourceMappingURL=combine-promises.esm.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"combine-promises.esm.js","sources":["../src/index.ts"],"sourcesContent":["type UnwrapPromise<P extends unknown> = P extends PromiseLike<infer V> ? V : P;\n\ntype Input = Record<string | number | symbol, unknown>;\n\ntype Result<Obj extends Input> = {\n [P in keyof Obj]: UnwrapPromise<Obj[P]>;\n};\n\nexport default function combinePromises<Obj extends Input>(\n obj: Obj\n): Promise<Result<Obj>> {\n if (obj === null) {\n return Promise.reject(\n new Error('combinePromises does not handle null argument')\n );\n }\n if (typeof obj !== 'object') {\n return Promise.reject(\n new Error(\n `combinePromises does not handle argument of type ${typeof obj}`\n )\n );\n }\n\n const keys = Object.keys(obj);\n\n // not using async/await on purpose, otherwise lib outputs large _asyncToGenerator code in dist\n return Promise.all(Object.values(obj)).then(values => {\n const result: any = {};\n values.forEach((v, i) => {\n result[keys[i]] = v;\n });\n return result;\n });\n}\n"],"names":["combinePromises","obj","Promise","reject","Error","keys","Object","all","values","then","result","forEach","v","i"],"mappings":"SAQwBA,gBACtBC;AAEA,MAAIA,GAAG,KAAK,IAAZ,EAAkB;AAChB,WAAOC,OAAO,CAACC,MAAR,CACL,IAAIC,KAAJ,CAAU,+CAAV,CADK,CAAP;AAGD;;AACD,MAAI,OAAOH,GAAP,KAAe,QAAnB,EAA6B;AAC3B,WAAOC,OAAO,CAACC,MAAR,CACL,IAAIC,KAAJ,uDACsD,OAAOH,GAD7D,CADK,CAAP;AAKD;;AAED,MAAMI,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAYJ,GAAZ,CAAb;;AAGA,SAAOC,OAAO,CAACK,GAAR,CAAYD,MAAM,CAACE,MAAP,CAAcP,GAAd,CAAZ,EAAgCQ,IAAhC,CAAqC,UAAAD,MAAM;AAChD,QAAME,MAAM,GAAQ,EAApB;AACAF,IAAAA,MAAM,CAACG,OAAP,CAAe,UAACC,CAAD,EAAIC,CAAJ;AACbH,MAAAA,MAAM,CAACL,IAAI,CAACQ,CAAD,CAAL,CAAN,GAAkBD,CAAlB;AACD,KAFD;AAGA,WAAOF,MAAP;AACD,GANM,CAAP;AAOD;;;;"}

7
node_modules/combine-promises/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,7 @@
declare type UnwrapPromise<P extends unknown> = P extends PromiseLike<infer V> ? V : P;
declare type Input = Record<string | number | symbol, unknown>;
declare type Result<Obj extends Input> = {
[P in keyof Obj]: UnwrapPromise<Obj[P]>;
};
export default function combinePromises<Obj extends Input>(obj: Obj): Promise<Result<Obj>>;
export {};

8
node_modules/combine-promises/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,8 @@
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./combine-promises.cjs.production.min.js')
} else {
module.exports = require('./combine-promises.cjs.development.js')
}

59
node_modules/combine-promises/package.json generated vendored Normal file
View File

@@ -0,0 +1,59 @@
{
"name": "combine-promises",
"author": "slorber",
"version": "1.2.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"module": "dist/combine-promises.esm.js",
"files": [
"dist",
"src"
],
"engines": {
"node": ">=10"
},
"repository": {
"type": "git",
"url": "https://github.com/slorber/combine-promises.git"
},
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint",
"prepare": "tsdx build",
"size": "size-limit",
"analyze": "size-limit --why"
},
"peerDependencies": {},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
},
"size-limit": [
{
"path": "dist/combine-promises.cjs.production.min.js",
"limit": "150 B"
},
{
"path": "dist/combine-promises.esm.js",
"limit": "150 B"
}
],
"devDependencies": {
"@size-limit/preset-small-lib": "^4.10.2",
"husky": "^6.0.0",
"size-limit": "^4.10.2",
"tsdx": "^0.14.1",
"tslib": "^2.2.0",
"typescript": "^4.2.3"
}
}

35
node_modules/combine-promises/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1,35 @@
type UnwrapPromise<P extends unknown> = P extends PromiseLike<infer V> ? V : P;
type Input = Record<string | number | symbol, unknown>;
type Result<Obj extends Input> = {
[P in keyof Obj]: UnwrapPromise<Obj[P]>;
};
export default function combinePromises<Obj extends Input>(
obj: Obj
): Promise<Result<Obj>> {
if (obj === null) {
return Promise.reject(
new Error('combinePromises does not handle null argument')
);
}
if (typeof obj !== 'object') {
return Promise.reject(
new Error(
`combinePromises does not handle argument of type ${typeof obj}`
)
);
}
const keys = Object.keys(obj);
// not using async/await on purpose, otherwise lib outputs large _asyncToGenerator code in dist
return Promise.all(Object.values(obj)).then(values => {
const result: any = {};
values.forEach((v, i) => {
result[keys[i]] = v;
});
return result;
});
}