feat(medusa): List products with Remote Query (#4969)

**What**
- includes some type fixes in the DAL layer
- List products including their prices and filtered by the sales channel as well as q parameter and category scope and all other filters
- Assign shipping profile
- ordering
- Add missing columns in the product module
- update product module migrations

**Comment**
-  In regards to the fields, we can pass whatever we want the module will only return the one that exists (default behavior), but on the other hand, that is not possible for the relations.

**question**
- To simplify usage, should we expose the fields/relations available from the module to simplify building a query for the user and be aware of what the module provides

**todo**
- Add back the support for the user to ask for fields/relations
This commit is contained in:
Adrien de Peretti
2023-09-12 15:55:05 +00:00
committed by GitHub
parent afd4e72cdf
commit 30863fee52
34 changed files with 1066 additions and 124 deletions
+2
View File
@@ -0,0 +1,2 @@
export type EntityDateColumns = "created_at" | "updated_at"
export type SoftDeletableEntityDateColumns = "deleted_at" | EntityDateColumns
+4 -3
View File
@@ -2,8 +2,8 @@ import { Dictionary, FilterQuery, Order } from "./utils"
export { FilterQuery } from "./utils"
export interface BaseFilterable<T> {
$and?: T
$or?: T
$and?: (T | BaseFilterable<T>)[]
$or?: (T | BaseFilterable<T>)[]
}
export interface OptionsQuery<T, P extends string = never> {
@@ -17,8 +17,9 @@ export interface OptionsQuery<T, P extends string = never> {
}
export type FindOptions<T = any> = {
where: FilterQuery<T>
where: FilterQuery<T> & BaseFilterable<FilterQuery<T>>
options?: OptionsQuery<T, any>
}
export * from "./repository-service"
export * from "./entity"
+28 -7
View File
@@ -3,19 +3,37 @@ export type JoinerRelationship = {
foreignKey: string
primaryKey: string
serviceName: string
inverse?: boolean // In an inverted relationship the foreign key is on the other service and the primary key is on the current service
isList?: boolean // Force the relationship to return a list
args?: Record<string, any> // Extra arguments to pass to the remoteFetchData callback
/**
* In an inverted relationship the foreign key is on the other service and the primary key is on the current service
*/
inverse?: boolean
/**
* Force the relationship to return a list
*/
isList?: boolean
/**
* Extra arguments to pass to the remoteFetchData callback
*/
args?: Record<string, any>
}
export interface JoinerServiceConfigAlias {
name: string
args?: Record<string, any> // Extra arguments to pass to the remoteFetchData callback
/**
* Extra arguments to pass to the remoteFetchData callback
*/
args?: Record<string, any>
}
export interface JoinerServiceConfig {
serviceName: string
alias?: JoinerServiceConfigAlias | JoinerServiceConfigAlias[] // Property name to use as entrypoint to the service
/**
* Property name to use as entrypoint to the service
*/
alias?: JoinerServiceConfigAlias | JoinerServiceConfigAlias[]
/**
* alias for deeper nested relationships (e.g. { 'price': 'prices.calculated_price_set.amount' })
*/
fieldAlias?: Record<
string,
| string
@@ -23,14 +41,17 @@ export interface JoinerServiceConfig {
path: string
forwardArgumentsOnPath: string[]
}
> // alias for deeper nested relationships (e.g. { 'price': 'prices.calculated_price_set.amount' })
>
primaryKeys: string[]
relationships?: JoinerRelationship[]
extends?: {
serviceName: string
relationship: JoinerRelationship
}[]
args?: Record<string, any> // Extra arguments to pass to the remoteFetchData callback
/**
* Extra arguments to pass to the remoteFetchData callback
*/
args?: Record<string, any>
}
export interface JoinerArgument {
+52 -13
View File
@@ -36,8 +36,14 @@ export type InternalModuleDeclaration = {
*/
resolve?: string
options?: Record<string, unknown>
alias?: string // If multiple modules are registered with the same key, the alias can be used to differentiate them
main?: boolean // If the module is the main module for the key when multiple ones are registered
/**
* If multiple modules are registered with the same key, the alias can be used to differentiate them
*/
alias?: string
/**
* If the module is the main module for the key when multiple ones are registered
*/
main?: boolean
}
export type ExternalModuleDeclaration = {
@@ -48,8 +54,14 @@ export type ExternalModuleDeclaration = {
keepAlive: boolean
}
options?: Record<string, unknown>
alias?: string // If multiple modules are registered with the same key, the alias can be used to differentiate them
main?: boolean // If the module is the main module for the key when multiple ones are registered
/**
* If multiple modules are registered with the same key, the alias can be used to differentiate them
*/
alias?: string
/**
* If the module is the main module for the key when multiple ones are registered
*/
main?: boolean
}
export type ModuleResolution = {
@@ -74,7 +86,10 @@ export type ModuleDefinition = {
* @deprecated property will be removed in future versions
*/
isRequired?: boolean
isQueryable?: boolean // If the module is queryable via Remote Joiner
/**
* If the module is queryable via Remote Joiner
*/
isQueryable?: boolean
dependencies?: string[]
defaultModuleDeclaration:
| InternalModuleDeclaration
@@ -136,12 +151,27 @@ export type ModuleJoinerConfig = Omit<
}[]
serviceName?: string
primaryKeys?: string[]
isLink?: boolean // If the module is a link module
linkableKeys?: string[] // Keys that can be used to link to other modules
isReadOnlyLink?: boolean // If true it expands a RemoteQuery property but doesn't create a pivot table
/**
* If the module is a link module
*/
isLink?: boolean
/**
* Keys that can be used to link to other modules
*/
linkableKeys?: string[]
/**
* If true it expands a RemoteQuery property but doesn't create a pivot table
*/
isReadOnlyLink?: boolean
databaseConfig?: {
tableName?: string // Name of the pivot table. If not provided it is auto generated
idPrefix?: string // Prefix for the id column. If not provided it is "link"
/**
* Name of the pivot table. If not provided it is auto generated
*/
tableName?: string
/**
* Prefix for the id column. If not provided it is "link"
*/
idPrefix?: string
extraFields?: Record<
string,
{
@@ -169,15 +199,24 @@ export type ModuleJoinerConfig = Omit<
| "text"
defaultValue?: string
nullable?: boolean
options?: Record<string, unknown> // Mikro-orm options for the column
/**
* Mikro-orm options for the column
*/
options?: Record<string, unknown>
}
>
}
}
export declare type ModuleJoinerRelationship = JoinerRelationship & {
isInternalService?: boolean // If true, the relationship is an internal service from the medusa core TODO: Remove when there are no more "internal" services
deleteCascade?: boolean // If true, the link joiner will cascade deleting the relationship
/**
* If true, the relationship is an internal service from the medusa core TODO: Remove when there are no more "internal" services
*/
isInternalService?: boolean
/**
* If true, the link joiner will cascade deleting the relationship
*/
deleteCascade?: boolean
}
export type ModuleExports = {
+3
View File
@@ -158,11 +158,14 @@ export interface ProductOptionValueDTO {
*/
export interface FilterableProductProps
extends BaseFilterable<FilterableProductProps> {
q?: string
handle?: string | string[]
id?: string | string[]
tags?: { value?: string[] }
categories?: {
id?: string | string[] | OperatorMap<string>
is_internal?: boolean
is_active?: boolean
}
category_id?: string | string[] | OperatorMap<string>
collection_id?: string | string[] | OperatorMap<string>