feat(utils): Introduce promiseAll util (#5543)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { promiseAll } from "@medusajs/utils"
|
||||
import { flatten, groupBy, map, merge } from "lodash"
|
||||
import {
|
||||
EntityMetadata,
|
||||
@@ -43,7 +44,7 @@ export async function queryEntityWithIds<T extends ObjectLiteral>({
|
||||
) => false | undefined)[]
|
||||
}): Promise<T[]> {
|
||||
const alias = repository.metadata.name.toLowerCase()
|
||||
return await Promise.all(
|
||||
return await promiseAll(
|
||||
Object.entries(groupedRelations).map(
|
||||
async ([toplevel, topLevelRelations]) => {
|
||||
let querybuilder = repository.createQueryBuilder(alias)
|
||||
@@ -191,7 +192,7 @@ export async function queryEntityWithoutRelations<T extends ObjectLiteral>({
|
||||
let entities: T[]
|
||||
let count = 0
|
||||
if (shouldCount) {
|
||||
const result = await Promise.all([qb.getMany(), qb.getCount()])
|
||||
const result = await promiseAll([qb.getMany(), qb.getCount()])
|
||||
entities = result[0]
|
||||
count = result[1]
|
||||
} else {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import { isDate } from "lodash"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { validator } from "../validator"
|
||||
import { promiseAll } from "@medusajs/utils"
|
||||
|
||||
async function typeValidator(
|
||||
typedClass: any,
|
||||
@@ -43,7 +44,7 @@ async function typeValidator(
|
||||
if (isArray(typedClass) && isArray(plain)) {
|
||||
const errors: Map<any, string> = new Map()
|
||||
const result = (
|
||||
await Promise.all(
|
||||
await promiseAll(
|
||||
(plain as any[]).map(
|
||||
async (p) =>
|
||||
await typeValidator(typedClass[0], p).catch((e) => {
|
||||
@@ -80,7 +81,7 @@ export function IsType(types: any[], validationOptions?: ValidationOptions) {
|
||||
validator: {
|
||||
async validate(value: unknown, args: ValidationArguments) {
|
||||
const errors: Map<any, string> = new Map()
|
||||
const results = await Promise.all(
|
||||
const results = await promiseAll(
|
||||
types.map(
|
||||
async (v) =>
|
||||
await typeValidator(v, value).catch((e) => {
|
||||
|
||||
Reference in New Issue
Block a user