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 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 =
|
export type TotalField =
|
||||||
| "shipping_total"
|
| "shipping_total"
|
||||||
| "discount_total"
|
| "discount_total"
|
||||||
|
|||||||
@@ -1,20 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
DateComparisonOperator,
|
ExtendedFindConfig,
|
||||||
FindConfig,
|
FindConfig,
|
||||||
NumericalComparisonOperator,
|
Selector,
|
||||||
StringComparisonOperator,
|
|
||||||
Writable,
|
Writable,
|
||||||
} from "../types/common"
|
} from "../types/common"
|
||||||
import { FindOperator, In, Raw } from "typeorm"
|
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.
|
* Used to build TypeORM queries.
|
||||||
* @param selector The selector
|
* @param selector The selector
|
||||||
@@ -24,10 +15,7 @@ type Selector<TEntity> = {
|
|||||||
export function buildQuery<TEntity = unknown>(
|
export function buildQuery<TEntity = unknown>(
|
||||||
selector: Selector<TEntity>,
|
selector: Selector<TEntity>,
|
||||||
config: FindConfig<TEntity> = {}
|
config: FindConfig<TEntity> = {}
|
||||||
): FindConfig<TEntity> & {
|
): ExtendedFindConfig<TEntity> {
|
||||||
where: Partial<Writable<TEntity>>
|
|
||||||
withDeleted?: boolean
|
|
||||||
} {
|
|
||||||
const build = (
|
const build = (
|
||||||
obj: Selector<TEntity>
|
obj: Selector<TEntity>
|
||||||
): Partial<Writable<TEntity>> => {
|
): Partial<Writable<TEntity>> => {
|
||||||
|
|||||||
Reference in New Issue
Block a user