docs: improvements + additions to module docs (#9152)

- Split Module and Module Links to their own chapters
- Add new docs on db operations and transactions in modules, multiple services, links with custom columns, etc...
- Added a list of registered dependencies in a module container
This commit is contained in:
Shahed Nasser
2024-10-01 11:20:54 +00:00
committed by GitHub
parent 1ad7e7583f
commit fb67d90b64
32 changed files with 1138 additions and 102 deletions
@@ -8,7 +8,7 @@ export const metadata = {
# {metadata.title}
In this document, you'll learn how to retrieve product variant prices in the Medusa application using the [Query](!docs!/advanced-development/modules/query).
In this document, you'll learn how to retrieve product variant prices in the Medusa application using the [Query](!docs!/advanced-development/module-links/query).
<Note title="Why use Query?">
@@ -1,16 +1,20 @@
import { Table } from "docs-ui"
export const metadata = {
title: `Medusa Container Resources`,
title: `Medusa and Module Container Dependencies`,
}
# {metadata.title}
This documentation page includes the list of resources registered in the Medusa container of your Medusa application.
This documentation page includes the list of dependencies registered in the container of the Medusa application and a module.
## Medusa Container Dependencies
The following list of dependencies are resources that can be resolved by all resources (such as API route or workflow) except of a module's.
<Note>
Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/utils` to resolve these resources' names.
Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/utils` where specified.
</Note>
@@ -121,8 +125,134 @@ Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/util
</Table.Cell>
<Table.Cell>
- For custom modules, the registration name is the key of the module in the `modules` configuration.
- For Medusa's commerce modules, you can use the `Modules` enum imported from `@medusajs/framework/utils`.
- For custom modules, the registration name is the key of the module in the `modules` configuration in `medusa-config.js`.
- For Medusa's commerce modules, use the `Modules` enum imported from `@medusajs/framework/utils`.
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
---
## Module Container Dependencies
The following resources are resources that can be resolved by a module's services and loaders.
<Note>
Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/utils` where specified.
</Note>
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>
Resource
</Table.HeaderCell>
<Table.HeaderCell>
Description
</Table.HeaderCell>
<Table.HeaderCell>
Registration Name
</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>
Logger
</Table.Cell>
<Table.Cell>
An instance of Medusa CLIs logger. You can use it to log messages to the terminal.
</Table.Cell>
<Table.Cell>
`logger` or `ContainerRegistrationKeys.LOGGER`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
Entity Manager
</Table.Cell>
<Table.Cell>
An instance of [MikroORM's entity manager](https://mikro-orm.io/api/5.9/knex/class/EntityManager).
</Table.Cell>
<Table.Cell>
`manager` or `ContainerRegistrationKeys.MANAGER`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
Base Repository
</Table.Cell>
<Table.Cell>
An instance of the base repository, used to run transactions or perform other database operations.
</Table.Cell>
<Table.Cell>
`baseRepository`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
Configurations
</Table.Cell>
<Table.Cell>
The configurations exported from `medusa-config.js`.
</Table.Cell>
<Table.Cell>
`configModule` or `ContainerRegistrationKeys.CONFIG_MODULE`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
Modules' services
</Table.Cell>
<Table.Cell>
All services exported by the `services/index.ts` file of a module.
</Table.Cell>
<Table.Cell>
Each service is registered by its camel-case name. For example, if the service's class name is `ClientService`, its registration name is `clientService`.
</Table.Cell>
</Table.Row>
@@ -170,7 +170,7 @@ class DigitalProductModuleService extends MedusaService({
export default DigitalProductModuleService
```
The service extends the [service factory](https://docs.medusajs.com/v2/advanced-development/modules/service-factory), which provides basic data-management features.
The service extends the [service factory](!docs!/advanced-development/modules/service-factory), which provides basic data-management features.
### Create Module Definition
@@ -255,7 +255,7 @@ This defines a link between `DigitalProductOrder` and the Order Modules `Orde
### Further Read
- [How to Define Module Links](!docs!/advanced-development/modules/module-links)
- [How to Define Module Links](!docs!/advanced-development/module-links)
---
@@ -362,7 +362,7 @@ Make sure to replace `{token}` with the JWT token you retrieved.
### Further Reads
- [How to Create an API Route](!docs!/basics/api-routes)
- [Learn more about Query](!docs!/advanced-development/modules/query)
- [Learn more about Query](!docs!/advanced-development/module-links/query)
---
@@ -611,7 +611,7 @@ Youll test out the workflow in the next section.
- [How to Create a Workflow](!docs!/basics/workflows)
- [What is the Compensation Function](!docs!/advanced-development/workflows/compensation-function)
- [Learn more about the remote link function](!docs!/advanced-development/modules/remote-link)
- [Learn more about the remote link function](!docs!/advanced-development/module-links/remote-link)
---
@@ -69,7 +69,7 @@ Then, you can link your custom data model to data models from other modules. For
icon: AcademicCapSolid,
},
{
href: "!docs!/advanced-development/modules/module-links",
href: "!docs!/advanced-development/module-links",
title: "Module Links",
text: "Learn how to link data models of different modules.",
icon: AcademicCapSolid,
@@ -129,13 +129,13 @@ Use the remote link to create a link between two records, and use Query to fetch
<CardList itemsPerRow={2} items={[
{
href: "!docs!/advanced-development/modules/remote-link",
href: "!docs!/advanced-development/module-links/remote-link",
title: "How to Use the Remote Link",
text: "Learn how to link data models of different modules.",
icon: AcademicCapSolid,
},
{
href: "!docs!/advanced-development/modules/query",
href: "!docs!/advanced-development/module-links/query",
title: "How to Use Query",
text: "Learn how to fetch data across modules with Medusa's Query.",
icon: AcademicCapSolid,
@@ -401,7 +401,7 @@ This defines a link between the Delivery Modules `delivery` data model and th
### Further Reads
- [How to Define Links](!docs!/advanced-development/modules/module-links)
- [How to Define Links](!docs!/advanced-development/module-links)
---
@@ -688,7 +688,7 @@ This returns the list of restaurants in the response.
### Further Reads
- [What is and how to use it](!docs!/advanced-development/modules/query)
- [What is and how to use it](!docs!/advanced-development/module-links/query)
- [How to Retrieve Prices for Product Variants](../../../../commerce-modules/product/guides/price/page.mdx)
---
@@ -203,7 +203,7 @@ This adds a list link between the `Vendor` and `Order` data models, indicating t
### Further Read
- [How to Define Module Links](!docs!/advanced-development/modules/module-links)
- [How to Define Module Links](!docs!/advanced-development/module-links)
---
@@ -778,8 +778,8 @@ curl 'http://localhost:9000/vendors/products' \
### Further Reads
- [How to use Query](!docs!/advanced-development/modules/query)
- [How to use the Remote Link](!docs!/advanced-development/modules/remote-link)
- [How to use Query](!docs!/advanced-development/module-links/query)
- [How to use the Remote Link](!docs!/advanced-development/module-links/remote-link)
---
@@ -1361,7 +1361,7 @@ For example, you can link sales channels to vendors or other settings.
<Note>
[Learn more about module links](!docs!/advanced-development/modules/module-links).
[Learn more about module links](!docs!/advanced-development/module-links).
</Note>
@@ -57,7 +57,7 @@ Since a vendor has products, orders, and other models based on your use case, de
For example, if you defined a vendor data model in a marketplace module, you can define a module link between the vendor and the Product Module's product data model.
<Card
href="!docs!/advanced-development/modules/module-links"
href="!docs!/advanced-development/module-links"
title="Define a Module Link"
text="Learn how to define a module link."
icon={AcademicCapSolid}
@@ -243,7 +243,7 @@ This defines a list link to the `Order` data model since a subscription has mult
### Further Reads
- [How to Define a Link](!docs!/advanced-development/modules/module-links)
- [How to Define a Link](!docs!/advanced-development/module-links)
---
@@ -642,7 +642,7 @@ The workflow returns the created subscription and order.
- [How to Create a Workflow](!docs!/basics/workflows)
- [Learn more about the compensation function](!docs!/advanced-development/workflows/compensation-function)
- [How to use the Remote Link](!docs!/advanced-development/modules/remote-link)
- [How to use the Remote Link](!docs!/advanced-development/module-links/remote-link)
---
@@ -57,7 +57,7 @@ For example, you can link the subscription data model to the Order Module's `Ord
If you want to create subscriptions on the product level, you can link the subscription data model to the Product Module's `Product` data model.
<Card
href="!docs!/advanced-development/modules/module-links"
href="!docs!/advanced-development/module-links"
title="Define a Module Link"
text="Learn how to define a module link."
icon={AcademicCapSolid}
@@ -48,7 +48,7 @@ The method returns an array of the first `15` records matching the filters.
<Note>
This applies to relations between data models of the same module. To retrieve linked records of different modules, use [Query](!docs!/advanced-development/modules/query).
This applies to relations between data models of the same module. To retrieve linked records of different modules, use [Query](!docs!/advanced-development/module-links/query).
</Note>
@@ -54,7 +54,7 @@ The method returns an array with two items:
<Note>
This applies to relations between data models of the same module. To retrieve linked records of different modules, use [Query](!docs!/advanced-development/modules/query).
This applies to relations between data models of the same module. To retrieve linked records of different modules, use [Query](!docs!/advanced-development/module-links/query).
</Note>
@@ -30,7 +30,7 @@ The method returns the record as an object.
<Note>
This applies to relations between data models of the same module. To retrieve linked records of different modules, use [Query](!docs!/advanced-development/modules/query).
This applies to relations between data models of the same module. To retrieve linked records of different modules, use [Query](!docs!/advanced-development/module-links/query).
</Note>
+1 -1
View File
@@ -8745,7 +8745,7 @@ export const generatedSidebar = [
"isPathHref": true,
"type": "link",
"path": "/medusa-container-resources",
"title": "Medusa Container Resources",
"title": "Container Dependencies",
"children": []
},
{
+1 -1
View File
@@ -2200,7 +2200,7 @@ export const sidebar = sidebarAttachHrefCommonOptions([
{
type: "link",
path: "/medusa-container-resources",
title: "Medusa Container Resources",
title: "Container Dependencies",
},
{
type: "link",