feat: loosely typed container

This commit is contained in:
Harminder Virk
2024-05-31 15:22:03 +05:30
committed by GitHub
parent 2d956931b3
commit 11528526fa
41 changed files with 255 additions and 114 deletions
@@ -13,10 +13,9 @@ export default async ({
// TODO: Add default logger to the container when running tests
const logger =
container.resolve<Logger>(ContainerRegistrationKeys.LOGGER) ?? console
const {
currencyService_,
}: { currencyService_: ModulesSdkTypes.InternalModuleService<Currency> } =
container.resolve(ModuleRegistrationName.CURRENCY)
const { currencyService_ } = container.resolve<{
currencyService_: ModulesSdkTypes.InternalModuleService<Currency>
}>(ModuleRegistrationName.CURRENCY)
try {
const normalizedCurrencies = Object.values(defaultCurrencies).map((c) => ({
@@ -1,11 +1,11 @@
import {
CreatePaymentProviderDTO,
LoaderOptions
} from "@medusajs/types"
import { CreatePaymentProviderDTO, LoaderOptions } from "@medusajs/types"
import { PaymentProviderService } from "@services"
export default async ({ container }: LoaderOptions): Promise<void> => {
const providersToLoad = container.resolve("payment_providers")
const paymentProviderService = container.resolve("paymentProviderService")
const providersToLoad = container.resolve<string[]>("payment_providers")
const paymentProviderService = container.resolve<PaymentProviderService>(
"paymentProviderService"
)
const providers = await paymentProviderService.list({
id: providersToLoad,
@@ -57,8 +57,8 @@ export default class PaymentProviderService {
@InjectManager("paymentProviderRepository_")
async list(
filters: FilterablePaymentProviderProps,
config: FindConfig<PaymentProviderDTO>,
filters?: FilterablePaymentProviderProps,
config?: FindConfig<PaymentProviderDTO>,
@MedusaContext() sharedContext?: Context
): Promise<PaymentProvider[]> {
const queryOptions = ModulesSdkUtils.buildQuery<PaymentProvider>(
@@ -6,7 +6,6 @@ import {
ModuleJoinerConfig,
StockLocationAddressInput,
StockLocationTypes,
UpdateStockLocationInput,
ModulesSdkTypes,
DAL,
IStockLocationServiceNext,
@@ -2,9 +2,11 @@ import {
Context,
DAL,
FindConfig,
IWorkflowEngineService,
InternalModuleDeclaration,
ModuleJoinerConfig,
ModulesSdkTypes,
WorkflowsSdkTypes,
} from "@medusajs/types"
import {
InjectManager,
@@ -14,10 +16,8 @@ import {
MedusaError,
} from "@medusajs/utils"
import type {
IWorkflowEngineService,
ReturnWorkflow,
UnwrapWorkflowInputDataType,
WorkflowOrchestratorTypes,
} from "@medusajs/workflows-sdk"
import { WorkflowOrchestratorService } from "@services"
import { joinerConfig } from "../joiner-config"
@@ -58,9 +58,9 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
workflow_id: string
transaction_id: string
},
config: FindConfig<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
@MedusaContext() sharedContext: Context = {}
): Promise<WorkflowOrchestratorTypes.WorkflowExecutionDTO> {
): Promise<WorkflowsSdkTypes.WorkflowExecutionDTO> {
const objValue = isString(idOrObject)
? { id: idOrObject }
: {
@@ -84,7 +84,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
}
// eslint-disable-next-line max-len
return await this.baseRepository_.serialize<WorkflowOrchestratorTypes.WorkflowExecutionDTO>(
return await this.baseRepository_.serialize<WorkflowsSdkTypes.WorkflowExecutionDTO>(
wfExecution[0],
{
populate: true,
@@ -94,10 +94,10 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
@InjectManager("baseRepository_")
async listWorkflowExecution(
filters: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps = {},
config: FindConfig<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {},
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
@MedusaContext() sharedContext: Context = {}
): Promise<WorkflowOrchestratorTypes.WorkflowExecutionDTO[]> {
): Promise<WorkflowsSdkTypes.WorkflowExecutionDTO[]> {
if (filters.transaction_id) {
if (Array.isArray(filters.transaction_id)) {
filters.transaction_id = {
@@ -121,7 +121,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
)
return await this.baseRepository_.serialize<
WorkflowOrchestratorTypes.WorkflowExecutionDTO[]
WorkflowsSdkTypes.WorkflowExecutionDTO[]
>(wfExecutions, {
populate: true,
})
@@ -129,10 +129,10 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
@InjectManager("baseRepository_")
async listAndCountWorkflowExecution(
filters: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps = {},
config: FindConfig<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {},
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
@MedusaContext() sharedContext: Context = {}
): Promise<[WorkflowOrchestratorTypes.WorkflowExecutionDTO[], number]> {
): Promise<[WorkflowsSdkTypes.WorkflowExecutionDTO[], number]> {
if (filters.transaction_id) {
if (Array.isArray(filters.transaction_id)) {
filters.transaction_id = {
@@ -158,7 +158,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
return [
await this.baseRepository_.serialize<
WorkflowOrchestratorTypes.WorkflowExecutionDTO[]
WorkflowsSdkTypes.WorkflowExecutionDTO[]
>(wfExecutions, {
populate: true,
}),
@@ -169,7 +169,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
@InjectSharedContext()
async run<TWorkflow extends string | ReturnWorkflow<any, any, any>>(
workflowIdOrWorkflow: TWorkflow,
options: WorkflowOrchestratorTypes.WorkflowOrchestratorRunDTO<
options: WorkflowsSdkTypes.WorkflowOrchestratorRunDTO<
TWorkflow extends ReturnWorkflow<any, any, any>
? UnwrapWorkflowInputDataType<TWorkflow>
: unknown
@@ -2,9 +2,11 @@ import {
Context,
DAL,
FindConfig,
IWorkflowEngineService,
InternalModuleDeclaration,
ModuleJoinerConfig,
ModulesSdkTypes,
WorkflowsSdkTypes,
} from "@medusajs/types"
import {
InjectManager,
@@ -14,10 +16,8 @@ import {
isString,
} from "@medusajs/utils"
import type {
IWorkflowEngineService,
ReturnWorkflow,
UnwrapWorkflowInputDataType,
WorkflowOrchestratorTypes,
} from "@medusajs/workflows-sdk"
import { WorkflowOrchestratorService } from "@services"
import { joinerConfig } from "../joiner-config"
@@ -72,9 +72,9 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
workflow_id: string
transaction_id: string
},
config: FindConfig<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
@MedusaContext() sharedContext: Context = {}
): Promise<WorkflowOrchestratorTypes.WorkflowExecutionDTO> {
): Promise<WorkflowsSdkTypes.WorkflowExecutionDTO> {
const objValue = isString(idOrObject)
? { id: idOrObject }
: {
@@ -98,7 +98,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
}
// eslint-disable-next-line max-len
return await this.baseRepository_.serialize<WorkflowOrchestratorTypes.WorkflowExecutionDTO>(
return await this.baseRepository_.serialize<WorkflowsSdkTypes.WorkflowExecutionDTO>(
wfExecution[0],
{
populate: true,
@@ -108,10 +108,10 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
@InjectManager("baseRepository_")
async listWorkflowExecution(
filters: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps = {},
config: FindConfig<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {},
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
@MedusaContext() sharedContext: Context = {}
): Promise<WorkflowOrchestratorTypes.WorkflowExecutionDTO[]> {
): Promise<WorkflowsSdkTypes.WorkflowExecutionDTO[]> {
if (filters.transaction_id) {
if (Array.isArray(filters.transaction_id)) {
filters.transaction_id = {
@@ -135,7 +135,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
)
return await this.baseRepository_.serialize<
WorkflowOrchestratorTypes.WorkflowExecutionDTO[]
WorkflowsSdkTypes.WorkflowExecutionDTO[]
>(wfExecutions, {
populate: true,
})
@@ -143,10 +143,10 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
@InjectManager("baseRepository_")
async listAndCountWorkflowExecution(
filters: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps = {},
config: FindConfig<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {},
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
@MedusaContext() sharedContext: Context = {}
): Promise<[WorkflowOrchestratorTypes.WorkflowExecutionDTO[], number]> {
): Promise<[WorkflowsSdkTypes.WorkflowExecutionDTO[], number]> {
if (filters.transaction_id) {
if (Array.isArray(filters.transaction_id)) {
filters.transaction_id = {
@@ -172,7 +172,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
return [
await this.baseRepository_.serialize<
WorkflowOrchestratorTypes.WorkflowExecutionDTO[]
WorkflowsSdkTypes.WorkflowExecutionDTO[]
>(wfExecutions, {
populate: true,
}),
@@ -183,7 +183,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
@InjectSharedContext()
async run<TWorkflow extends string | ReturnWorkflow<any, any, any>>(
workflowIdOrWorkflow: TWorkflow,
options: WorkflowOrchestratorTypes.WorkflowOrchestratorRunDTO<
options: WorkflowsSdkTypes.WorkflowOrchestratorRunDTO<
TWorkflow extends ReturnWorkflow<any, any, any>
? UnwrapWorkflowInputDataType<TWorkflow>
: unknown