feat(medusa): Move some typings into the common types
This commit is contained in:
@@ -9,6 +9,20 @@ export type PartialPick<T, K extends keyof T> = {
|
||||
|
||||
export type Writable<T> = { -readonly [key in keyof T]: T[key] }
|
||||
|
||||
export type ExtendedFindConfig<TEntity> = FindConfig<TEntity> & {
|
||||
where: Partial<Writable<TEntity>>
|
||||
withDeleted?: boolean
|
||||
}
|
||||
|
||||
export type Selector<TEntity> = {
|
||||
[key in keyof TEntity]?:
|
||||
| TEntity[key]
|
||||
| TEntity[key][]
|
||||
| DateComparisonOperator
|
||||
| StringComparisonOperator
|
||||
| NumericalComparisonOperator
|
||||
}
|
||||
|
||||
export type TotalField =
|
||||
| "shipping_total"
|
||||
| "discount_total"
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
import {
|
||||
DateComparisonOperator,
|
||||
ExtendedFindConfig,
|
||||
FindConfig,
|
||||
NumericalComparisonOperator,
|
||||
StringComparisonOperator,
|
||||
Selector,
|
||||
Writable,
|
||||
} from "../types/common"
|
||||
import { FindOperator, In, Raw } from "typeorm"
|
||||
|
||||
type Selector<TEntity> = {
|
||||
[key in keyof TEntity]?: TEntity[key]
|
||||
| TEntity[key][]
|
||||
| DateComparisonOperator
|
||||
| StringComparisonOperator
|
||||
| NumericalComparisonOperator
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to build TypeORM queries.
|
||||
* @param selector The selector
|
||||
@@ -24,10 +15,7 @@ type Selector<TEntity> = {
|
||||
export function buildQuery<TEntity = unknown>(
|
||||
selector: Selector<TEntity>,
|
||||
config: FindConfig<TEntity> = {}
|
||||
): FindConfig<TEntity> & {
|
||||
where: Partial<Writable<TEntity>>
|
||||
withDeleted?: boolean
|
||||
} {
|
||||
): ExtendedFindConfig<TEntity> {
|
||||
const build = (
|
||||
obj: Selector<TEntity>
|
||||
): Partial<Writable<TEntity>> => {
|
||||
|
||||
Reference in New Issue
Block a user