forked from medusajs/medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Move container bindings declaration merging within the framework (
- Loading branch information
1 parent
58f9b2e
commit f1759f0
Showing
13 changed files
with
119 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import "../types/container" | ||
|
||
export * from "./loader" | ||
export * from "./config" | ||
export * from "./types" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,4 @@ | ||
export * from "./types/container" | ||
import { createMedusaContainer } from "@medusajs/utils" | ||
import { AwilixContainer, ResolveOptions } from "awilix" | ||
import { ModuleImplementations } from "@medusajs/types" | ||
|
||
/** | ||
* The Medusa Container extends [Awilix](https://github.com/jeffijoe/awilix) to | ||
* provide dependency injection functionalities. | ||
*/ | ||
// export type MedusaContainer<Cradle extends object = TransformObjectMethodToAsync<ModuleImplementations>> = | ||
export type MedusaContainer<Cradle extends object = ModuleImplementations> = | ||
Omit<AwilixContainer, "resolve"> & { | ||
resolve<K extends keyof Cradle>( | ||
key: K, | ||
resolveOptions?: ResolveOptions | ||
): Cradle[K] | ||
resolve<T>(key: string, resolveOptions?: ResolveOptions): T | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
registerAdd: <T>(name: string, registration: T) => MedusaContainer | ||
/** | ||
* @ignore | ||
*/ | ||
createScope: () => MedusaContainer | ||
} | ||
|
||
export type ContainerLike = { | ||
resolve<T = unknown>(key: string): T | ||
} | ||
|
||
export const container = createMedusaContainer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import "../types/container" | ||
export * from "./pg-connection-loader" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import "../types/container" | ||
|
||
export * from "./types" | ||
export * from "./feature-flag-loader" | ||
export * from "./flag-router" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import "../types/container" | ||
|
||
export * from "./express-loader" | ||
export * from "./router" | ||
export * from "./types" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Knex } from "@mikro-orm/knex" | ||
import { RemoteLink } from "@medusajs/modules-sdk" | ||
import { AwilixContainer, ResolveOptions } from "awilix" | ||
import { Modules, ContainerRegistrationKeys } from "@medusajs/utils" | ||
import { | ||
Logger, | ||
ConfigModule, | ||
ModuleImplementations, | ||
RemoteQueryFunction, | ||
IAuthModuleService, | ||
ICacheService, | ||
ICartModuleService, | ||
ICustomerModuleService, | ||
IEventBusModuleService, | ||
IInventoryService, | ||
IPaymentModuleService, | ||
IPricingModuleService, | ||
IProductModuleService, | ||
IPromotionModuleService, | ||
ISalesChannelModuleService, | ||
ITaxModuleService, | ||
IFulfillmentModuleService, | ||
IStockLocationService, | ||
IUserModuleService, | ||
IWorkflowEngineService, | ||
IRegionModuleService, | ||
IOrderModuleService, | ||
IApiKeyModuleService, | ||
IStoreModuleService, | ||
ICurrencyModuleService, | ||
IFileModuleService, | ||
INotificationModuleService, | ||
} from "@medusajs/types" | ||
|
||
declare module "@medusajs/types" { | ||
export interface ModuleImplementations { | ||
[ContainerRegistrationKeys.REMOTE_LINK]: RemoteLink | ||
[ContainerRegistrationKeys.CONFIG_MODULE]: ConfigModule | ||
[ContainerRegistrationKeys.PG_CONNECTION]: Knex<any> | ||
[ContainerRegistrationKeys.REMOTE_QUERY]: RemoteQueryFunction | ||
[ContainerRegistrationKeys.QUERY]: Omit<RemoteQueryFunction, symbol> | ||
[ContainerRegistrationKeys.LOGGER]: Logger | ||
[Modules.AUTH]: IAuthModuleService | ||
[Modules.CACHE]: ICacheService | ||
[Modules.CART]: ICartModuleService | ||
[Modules.CUSTOMER]: ICustomerModuleService | ||
[Modules.EVENT_BUS]: IEventBusModuleService | ||
[Modules.INVENTORY]: IInventoryService | ||
[Modules.PAYMENT]: IPaymentModuleService | ||
[Modules.PRICING]: IPricingModuleService | ||
[Modules.PRODUCT]: IProductModuleService | ||
[Modules.PROMOTION]: IPromotionModuleService | ||
[Modules.SALES_CHANNEL]: ISalesChannelModuleService | ||
[Modules.TAX]: ITaxModuleService | ||
[Modules.FULFILLMENT]: IFulfillmentModuleService | ||
[Modules.STOCK_LOCATION]: IStockLocationService | ||
[Modules.USER]: IUserModuleService | ||
[Modules.WORKFLOW_ENGINE]: IWorkflowEngineService | ||
[Modules.REGION]: IRegionModuleService | ||
[Modules.ORDER]: IOrderModuleService | ||
[Modules.API_KEY]: IApiKeyModuleService | ||
[Modules.STORE]: IStoreModuleService | ||
[Modules.CURRENCY]: ICurrencyModuleService | ||
[Modules.FILE]: IFileModuleService | ||
[Modules.NOTIFICATION]: INotificationModuleService | ||
} | ||
} | ||
|
||
export type MedusaContainer<Cradle extends object = ModuleImplementations> = | ||
Omit<AwilixContainer, "resolve"> & { | ||
resolve<K extends keyof Cradle>( | ||
key: K, | ||
resolveOptions?: ResolveOptions | ||
): Cradle[K] | ||
resolve<T>(key: string, resolveOptions?: ResolveOptions): T | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
registerAdd: <T>(name: string, registration: T) => MedusaContainer | ||
/** | ||
* @ignore | ||
*/ | ||
createScope: () => MedusaContainer | ||
} | ||
|
||
export type ContainerLike = { | ||
resolve<T = unknown>(key: string): T | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import "../types/container" | ||
|
||
export * from "@medusajs/utils" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import "../types/container" | ||
|
||
export * from "@medusajs/workflows-sdk" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import "../types/container" | ||
|
||
export * from "./workflow-loader" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters