@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/product": patch
|
||||
"@medusajs/types": patch
|
||||
---
|
||||
|
||||
fix(product): Serialize typings
|
||||
@@ -74,16 +74,13 @@ const updateDeletedAtRecursively = async <T extends object = any>(
|
||||
}
|
||||
}
|
||||
|
||||
const serializer = <
|
||||
T extends object | object[],
|
||||
TResult extends object | object[]
|
||||
>(
|
||||
data: T,
|
||||
const serializer = <TOutput extends object>(
|
||||
data: any,
|
||||
options?: any
|
||||
): Promise<TResult> => {
|
||||
): Promise<TOutput> => {
|
||||
options ??= {}
|
||||
const result = serialize(data, options)
|
||||
return Array.isArray(data) ? result : result[0]
|
||||
return result as unknown as Promise<TOutput>
|
||||
}
|
||||
|
||||
export abstract class AbstractBaseRepository<T = any>
|
||||
@@ -110,11 +107,11 @@ export abstract class AbstractBaseRepository<T = any>
|
||||
return await transactionWrapper.apply(this, arguments)
|
||||
}
|
||||
|
||||
serialize<
|
||||
TData extends object | object[] = object[],
|
||||
TResult extends object | object[] = object[]
|
||||
>(data: TData, options?: any): Promise<TResult> {
|
||||
return serializer<TData, TResult>(data, options)
|
||||
async serialize<TOutput extends object | object[]>(
|
||||
data: any,
|
||||
options?: any
|
||||
): Promise<TOutput> {
|
||||
return await serializer<TOutput>(data, options)
|
||||
}
|
||||
|
||||
abstract find(options?: DAL.FindOptions<T>, context?: Context)
|
||||
@@ -203,13 +200,6 @@ export class BaseRepository extends AbstractBaseRepository {
|
||||
super(...arguments)
|
||||
}
|
||||
|
||||
serialize<
|
||||
TData extends object | object[] = object[],
|
||||
TResult extends object | object[] = object[]
|
||||
>(data: TData, options?: any): Promise<TResult> {
|
||||
return serializer<TData, TResult>(data, options)
|
||||
}
|
||||
|
||||
create(data: unknown[], context?: Context): Promise<any[]> {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
|
||||
@@ -285,10 +285,7 @@ export default class ProductModuleService<
|
||||
async create(data: ProductTypes.CreateProductDTO[], sharedContext?: Context) {
|
||||
const products = await this.create_(data, sharedContext)
|
||||
|
||||
return this.baseRepository_.serialize<
|
||||
TProduct[],
|
||||
ProductTypes.ProductDTO[]
|
||||
>(products, {
|
||||
return this.baseRepository_.serialize<ProductTypes.ProductDTO[]>(products, {
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
@@ -425,10 +422,7 @@ export default class ProductModuleService<
|
||||
): Promise<ProductTypes.ProductDTO[]> {
|
||||
const products = await this.softDelete_(productIds, sharedContext)
|
||||
|
||||
return this.baseRepository_.serialize<
|
||||
TProduct[],
|
||||
ProductTypes.ProductDTO[]
|
||||
>(products, {
|
||||
return this.baseRepository_.serialize<ProductTypes.ProductDTO[]>(products, {
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
@@ -447,10 +441,7 @@ export default class ProductModuleService<
|
||||
): Promise<ProductTypes.ProductDTO[]> {
|
||||
const products = await this.restore_(productIds, sharedContext)
|
||||
|
||||
return this.baseRepository_.serialize<
|
||||
TProduct[],
|
||||
ProductTypes.ProductDTO[]
|
||||
>(products, {
|
||||
return this.baseRepository_.serialize<ProductTypes.ProductDTO[]>(products, {
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -17,15 +17,10 @@ export interface RepositoryService<T = any> {
|
||||
}
|
||||
): Promise<any>
|
||||
|
||||
serialize<TData extends object, TResult extends object, TOptions = any>(
|
||||
data: TData,
|
||||
options?: TOptions
|
||||
): Promise<TResult>
|
||||
|
||||
serialize<TData extends object[], TResult extends object[], TOptions = any>(
|
||||
data: TData[],
|
||||
options?: TOptions
|
||||
): Promise<TResult>
|
||||
serialize<TOutput extends object | object[]>(
|
||||
data: any,
|
||||
options?: any
|
||||
): Promise<TOutput>
|
||||
|
||||
find(options?: FindOptions<T>, context?: Context): Promise<T[]>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user