docs: added how-to guides for architectural modules (#11883)
* added initial how-tos * finished changes * generated sidebars
This commit is contained in:
@@ -9,6 +9,7 @@ import { TypeList } from "docs-ui"
|
||||
- [auth](modules/auth/page.mdx)
|
||||
- [auth-models](modules/auth_models/page.mdx)
|
||||
- [auth-provider](modules/auth_provider/page.mdx)
|
||||
- [cache](modules/cache/page.mdx)
|
||||
- [cart](modules/cart/page.mdx)
|
||||
- [cart-models](modules/cart_models/page.mdx)
|
||||
- [core-flows](modules/core_flows/page.mdx)
|
||||
@@ -17,7 +18,9 @@ import { TypeList } from "docs-ui"
|
||||
- [customer](modules/customer/page.mdx)
|
||||
- [customer-models](modules/customer_models/page.mdx)
|
||||
- [dml](modules/dml/page.mdx)
|
||||
- [event](modules/event/page.mdx)
|
||||
- [file](modules/file/page.mdx)
|
||||
- [file-service](modules/file_service/page.mdx)
|
||||
- [fulfillment](modules/fulfillment/page.mdx)
|
||||
- [fulfillment-models](modules/fulfillment_models/page.mdx)
|
||||
- [fulfillment-provider](modules/fulfillment_provider/page.mdx)
|
||||
@@ -30,6 +33,7 @@ import { TypeList } from "docs-ui"
|
||||
- [medusa-config](modules/medusa_config/page.mdx)
|
||||
- [modules-sdk](modules/modules_sdk/page.mdx)
|
||||
- [notification](modules/notification/page.mdx)
|
||||
- [notification-service](modules/notification_service/page.mdx)
|
||||
- [order](modules/order/page.mdx)
|
||||
- [order-models](modules/order_models/page.mdx)
|
||||
- [payment](modules/payment/page.mdx)
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
---
|
||||
slug: /references/cache-service
|
||||
tags:
|
||||
- cache
|
||||
- server
|
||||
- how to
|
||||
sidebar_label: Use Cache Module
|
||||
---
|
||||
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# How to Use Cache Module
|
||||
|
||||
In this document, you’ll learn about the different methods in the Cache Module's service and how to use them.
|
||||
|
||||
---
|
||||
|
||||
## Resolve Cache Module's Service
|
||||
|
||||
In your workflow's step, you can resolve the Cache Module's service from the Medusa container:
|
||||
|
||||
```ts
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
const step1 = createStep(
|
||||
"step-1",
|
||||
async ({}, { container }) => {
|
||||
const cacheModuleService = container.resolve(
|
||||
Modules.CACHE
|
||||
)
|
||||
|
||||
// TODO use cacheModuleService
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
This will resolve the service of the configured Cache Module, which is the [In-Memory Cache Module](https://docs.medusajs.com/resources/architectural-modules/cache/in-memory) by default.
|
||||
|
||||
You can then use the Cache Module's service's methods in the step. The rest of this guide details these methods.
|
||||
|
||||
---
|
||||
|
||||
## get
|
||||
|
||||
This method retrieves data from the cache.
|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
const data = await cacheModuleService.get("my-key")
|
||||
```
|
||||
|
||||
### Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"T","type":"`object`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="get"/>
|
||||
|
||||
### Parameters
|
||||
|
||||
<TypeList types={[{"name":"key","type":"`string`","description":"The key of the item to retrieve.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="get"/>
|
||||
|
||||
### Returns
|
||||
|
||||
<TypeList types={[{"name":"Promise","type":"Promise<null \\| T>","optional":false,"defaultValue":"","description":"The item that was stored in the cache. If the item was not found, null is returned.","expandable":false,"children":[{"name":"null \\| T","type":"`null` \\| T","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="get"/>
|
||||
|
||||
___
|
||||
|
||||
## set
|
||||
|
||||
This method stores data in the cache.
|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
await cacheModuleService.set("my-key", { product_id: "prod_123" }, 60)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
<TypeList types={[{"name":"key","type":"`string`","description":"The key of the item to store.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`unknown`","description":"The data to store in the cache.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"ttl","type":"`number`","description":"The time-to-live (TTL) value in seconds. If not provided, the default TTL value is used. The default value is based on the used Cache Module.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="set"/>
|
||||
|
||||
### Returns
|
||||
|
||||
<TypeList types={[{"name":"Promise","type":"Promise<void>","optional":false,"defaultValue":"","description":"This method stores data in the cache.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="set"/>
|
||||
|
||||
___
|
||||
|
||||
## invalidate
|
||||
|
||||
This method removes an item from the cache.
|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
await cacheModuleService.invalidate("my-key")
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
<TypeList types={[{"name":"key","type":"`string`","description":"The key of the item to remove.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="invalidate"/>
|
||||
|
||||
### Returns
|
||||
|
||||
<TypeList types={[{"name":"Promise","type":"Promise<void>","optional":false,"defaultValue":"","description":"This method removes an item from the cache.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="invalidate"/>
|
||||
@@ -0,0 +1,155 @@
|
||||
---
|
||||
slug: /references/event-service
|
||||
tags:
|
||||
- event
|
||||
- server
|
||||
- how to
|
||||
sidebar_label: Use Event Module
|
||||
---
|
||||
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# How to Use Event Module
|
||||
|
||||
In this document, you’ll learn about the different methods in the Event Module's service and how to use them.
|
||||
|
||||
---
|
||||
|
||||
## Resolve Event Module's Service
|
||||
|
||||
In your workflow's step, you can resolve the Event Module's service from the Medusa container:
|
||||
|
||||
```ts
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
const step1 = createStep(
|
||||
"step-1",
|
||||
async ({}, { container }) => {
|
||||
const eventModuleService = container.resolve(
|
||||
Modules.EVENT
|
||||
)
|
||||
|
||||
// TODO use eventModuleService
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
This will resolve the service of the configured Event Module, which is the [Local Event Module](https://docs.medusajs.com/resources/architectural-modules/event/local) by default.
|
||||
|
||||
You can then use the Event Module's service's methods in the step. The rest of this guide details these methods.
|
||||
|
||||
---
|
||||
|
||||
## emit
|
||||
|
||||
This method emits one or more events. Subscribers listening to the event(s) are executed asynchronously.
|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
await eventModuleService.emit({
|
||||
name: "user.created",
|
||||
data: {
|
||||
user_id: "user_123"
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"T","type":"`object`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="emit"/>
|
||||
|
||||
### Parameters
|
||||
|
||||
<TypeList types={[{"name":"data","type":"[Message](../../../types/EventBusTypes/types/types.EventBusTypes.Message/page.mdx)<T> \\| [Message](../../../types/EventBusTypes/types/types.EventBusTypes.Message/page.mdx)<T>[]","description":"The details of the events to emit.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"TData","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"[EventMetadata](../../../types/EventBusTypes/types/types.EventBusTypes.EventMetadata/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"eventGroupId","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"`Record<string, unknown>`","description":"Additional options for the event.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="emit"/>
|
||||
|
||||
### Returns
|
||||
|
||||
<TypeList types={[{"name":"Promise","type":"Promise<void>","optional":false,"defaultValue":"","description":"This method emits one or more events. Subscribers listening to the event(s) are executed asynchronously.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="emit"/>
|
||||
|
||||
___
|
||||
|
||||
## subscribe
|
||||
|
||||
This method adds a subscriber to an event. It's mainly used internally to register subscribers.
|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
eventModuleService.subscribe("user.created", async (data) => {
|
||||
console.log("User created", data)
|
||||
})
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
<TypeList types={[{"name":"eventName","type":"`string` \\| `symbol`","description":"The name of the event to subscribe to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subscriber","type":"[Subscriber](../../../types/EventBusTypes/types/types.EventBusTypes.Subscriber/page.mdx)","description":"The subscriber function to execute when the event is emitted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"context","type":"[SubscriberContext](../../../types/EventBusTypes/types/types.EventBusTypes.SubscriberContext/page.mdx)","description":"The context of the subscriber.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"subscriberId","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="subscribe"/>
|
||||
|
||||
### Returns
|
||||
|
||||
<TypeList types={[{"name":"this","type":"`this`","optional":false,"defaultValue":"","description":"The instance of the Event Module","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="subscribe"/>
|
||||
|
||||
___
|
||||
|
||||
## unsubscribe
|
||||
|
||||
This method removes a subscriber from an event. It's mainly used internally to unregister subscribers.
|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
eventModuleService.unsubscribe("user.created", async (data) => {
|
||||
console.log("User created", data)
|
||||
})
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
<TypeList types={[{"name":"eventName","type":"`string` \\| `symbol`","description":"The name of the event to unsubscribe from.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subscriber","type":"[Subscriber](../../../types/EventBusTypes/types/types.EventBusTypes.Subscriber/page.mdx)","description":"The subscriber function to remove.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"context","type":"[SubscriberContext](../../../types/EventBusTypes/types/types.EventBusTypes.SubscriberContext/page.mdx)","description":"The context of the subscriber.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"subscriberId","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="unsubscribe"/>
|
||||
|
||||
### Returns
|
||||
|
||||
<TypeList types={[{"name":"this","type":"`this`","optional":false,"defaultValue":"","description":"The instance of the Event Module","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="unsubscribe"/>
|
||||
|
||||
___
|
||||
|
||||
## releaseGroupedEvents
|
||||
|
||||
This method emits all events in the specified group. Grouped events are useful when you have distributed transactions
|
||||
where you need to explicitly group, release and clear events upon lifecycle events of a transaction.
|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
await eventModuleService.releaseGroupedEvents("group_123")
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
<TypeList types={[{"name":"eventGroupId","type":"`string`","description":"The ID of the event group.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="releaseGroupedEvents"/>
|
||||
|
||||
### Returns
|
||||
|
||||
<TypeList types={[{"name":"Promise","type":"Promise<void>","optional":false,"defaultValue":"","description":"This method emits all events in the specified group. Grouped events are useful when you have distributed transactions\nwhere you need to explicitly group, release and clear events upon lifecycle events of a transaction.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="releaseGroupedEvents"/>
|
||||
|
||||
___
|
||||
|
||||
## clearGroupedEvents
|
||||
|
||||
This method removes all events in the specified group. Grouped events are useful when you have distributed transactions
|
||||
where you need to explicitly group, release and clear events upon lifecycle events of a transaction.
|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
await eventModuleService.clearGroupedEvents("group_123")
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
<TypeList types={[{"name":"eventGroupId","type":"`string`","description":"The ID of the event group.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="clearGroupedEvents"/>
|
||||
|
||||
### Returns
|
||||
|
||||
<TypeList types={[{"name":"Promise","type":"Promise<void>","optional":false,"defaultValue":"","description":"This method removes all events in the specified group. Grouped events are useful when you have distributed transactions\nwhere you need to explicitly group, release and clear events upon lifecycle events of a transaction.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="clearGroupedEvents"/>
|
||||
+186
File diff suppressed because one or more lines are too long
@@ -0,0 +1,7 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# cache
|
||||
|
||||
## Interfaces
|
||||
|
||||
- [ICacheService](../../cache/interfaces/cache.ICacheService/page.mdx)
|
||||
@@ -0,0 +1,7 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# event
|
||||
|
||||
## Interfaces
|
||||
|
||||
- [IEventBusModuleService](../../event/interfaces/event.IEventBusModuleService/page.mdx)
|
||||
@@ -0,0 +1,7 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# file-service
|
||||
|
||||
## Interfaces
|
||||
|
||||
- [IFileModuleService](../../file_service/interfaces/file_service.IFileModuleService/page.mdx)
|
||||
@@ -0,0 +1,7 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# notification-service
|
||||
|
||||
## Interfaces
|
||||
|
||||
- [INotificationModuleService](../../notification_service/interfaces/notification_service.INotificationModuleService/page.mdx)
|
||||
+234
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user