feat(modules-sdk): Remote Query (#4463)

* feat: Remote Query
This commit is contained in:
Carlos R. L. Rodrigues
2023-07-19 15:35:36 -03:00
committed by GitHub
parent 95c538c675
commit 5a8a889c6d
57 changed files with 1286 additions and 423 deletions

View File

@@ -15,7 +15,7 @@ export const initialize = async (
}
): Promise<IInventoryService> => {
const serviceKey = Modules.INVENTORY
const loaded = await MedusaModule.bootstrap(
const loaded = await MedusaModule.bootstrap<IInventoryService>(
serviceKey,
"@medusajs/inventory",
options as InternalModuleDeclaration | ExternalModuleDeclaration,
@@ -23,5 +23,5 @@ export const initialize = async (
injectedDependencies
)
return loaded[serviceKey] as IInventoryService
return loaded[serviceKey]
}

View File

@@ -0,0 +1,51 @@
import { Modules } from "@medusajs/modules-sdk"
import { JoinerServiceConfig } from "@medusajs/types"
export const joinerConfig: JoinerServiceConfig = {
serviceName: Modules.INVENTORY,
primaryKeys: ["id"],
alias: [
{
name: "inventory_items",
},
{
name: "inventory",
},
{
name: "inventory_level",
args: {
methodSuffix: "InventoryLevels",
},
},
{
name: "inventory_levels",
args: {
methodSuffix: "InventoryLevels",
},
},
{
name: "reservation_items",
args: {
methodSuffix: "ReservationItems",
},
},
{
name: "reservation_item",
args: {
methodSuffix: "ReservationItems",
},
},
{
name: "reservation",
args: {
methodSuffix: "ReservationItems",
},
},
{
name: "reservations",
args: {
methodSuffix: "ReservationItems",
},
},
],
}

View File

@@ -11,6 +11,7 @@ import {
IInventoryService,
InventoryItemDTO,
InventoryLevelDTO,
JoinerServiceConfig,
MODULE_RESOURCE_TYPE,
ReservationItemDTO,
SharedContext,
@@ -23,6 +24,7 @@ import {
MedusaError,
} from "@medusajs/utils"
import { EntityManager } from "typeorm"
import { joinerConfig } from "../joiner-config"
import InventoryItemService from "./inventory-item"
import InventoryLevelService from "./inventory-level"
import ReservationItemService from "./reservation-item"
@@ -57,6 +59,10 @@ export default class InventoryService implements IInventoryService {
this.reservationItemService_ = reservationItemService
}
__joinerConfig(): JoinerServiceConfig {
return joinerConfig
}
/**
* Lists inventory items that match the given selector
* @param selector - the selector to filter inventory items by
@@ -75,6 +81,13 @@ export default class InventoryService implements IInventoryService {
context
)
}
async list(
selector: FilterableInventoryItemProps,
config: FindConfig<InventoryItemDTO> = { relations: [], skip: 0, take: 10 },
context: SharedContext = {}
): Promise<InventoryItemDTO[]> {
return await this.inventoryItemService_.list(selector, config, context)
}
/**
* Lists inventory levels that match the given selector