docs: use tooling convention across docs (#10512)
This commit is contained in:
1 parent
7c76ee24cb
commit
3409953c4f
76 files changed
+283
-265
No files matched your search
@@ -26,7 +26,7 @@ Modules are created in a sub-directory of `src/modules`. So, start by creating t
|
||||
|
||||
## 2. Create Data Model
|
||||
|
||||
A data model represents a table in the database. You create data models using Medusa's data modeling utility, which is built to improve readability and provide an intuitive developer experience.
|
||||
A data model represents a table in the database. You create data models using Medusa's Data Model Language (DML). It simplifies defining a table's columns, relations, and indexes with straightforward methods and configurations.
|
||||
|
||||
<Note>
|
||||
|
||||
@@ -49,7 +49,7 @@ export const Brand = model.define("brand", {
|
||||
|
||||
You create a `Brand` data model which has an `id` primary key property, and a `name` text property.
|
||||
|
||||
You define the data model using the `define` method of the `model` utility imported from `@medusajs/framework/utils`. It accepts two parameters:
|
||||
You define the data model using the `define` method of the DML. It accepts two parameters:
|
||||
|
||||
1. The first one is the name of the data model's table in the database. Use snake-case names.
|
||||
2. The second is an object, which is the data model's schema.
|
||||
@@ -95,7 +95,7 @@ class BrandModuleService extends MedusaService({
|
||||
export default BrandModuleService
|
||||
```
|
||||
|
||||
The `BrandModuleService` extends a class returned by the `MedusaService` function imported from `@medusajs/framework/utils`. This function generates a class with data-management methods for your module's data models.
|
||||
The `BrandModuleService` extends a class returned by `MedusaService` from the Modules SDK. This function generates a class with data-management methods for your module's data models.
|
||||
|
||||
The `MedusaService` function receives an object of the module's data models as a parameter, and generates methods to manage those data models. So, the `BrandModuleService` now has methods like `createBrands` and `retrieveBrand` to manage the `Brand` data model.
|
||||
|
||||
@@ -128,7 +128,7 @@ export default Module(BRAND_MODULE, {
|
||||
})
|
||||
```
|
||||
|
||||
You use the `Module` function imported from `@medusajs/framework/utils` to create the module's definition. It accepts two parameters:
|
||||
You use `Module` from the Modules SDK to create the module's definition. It accepts two parameters:
|
||||
|
||||
1. The module's name (`brand`). You'll use this name when you use this module in other customizations.
|
||||
2. An object with a required property `service` indicating the module's main service.
|
||||
|
||||
@@ -31,7 +31,7 @@ Learn more about workflows in [this chapter](../../../fundamentals/workflows/pag
|
||||
|
||||
## 1. Create createBrandStep
|
||||
|
||||
A workflow consists of a series of steps, each step created in a TypeScript or JavaScript file under the `src/workflows` directory. A step is defined using the `createStep` utility function imported from `@medusajs/framework/workflows-sdk`.
|
||||
A workflow consists of a series of steps, each step created in a TypeScript or JavaScript file under the `src/workflows` directory. A step is defined using `createStep` from the Workflows SDK
|
||||
|
||||
The workflow you're creating in this guide has one step to create the brand. So, create the file `src/workflows/create-brand.ts` with the following content:
|
||||
|
||||
@@ -120,7 +120,7 @@ So, if an error occurs during the workflow's execution, the brand that was creat
|
||||
|
||||
## 2. Create createBrandWorkflow
|
||||
|
||||
You can now create the workflow that runs the `createBrandStep`. A workflow is created in a TypeScript or JavaScript file under the `src/workflows` directory. In the file, you use the `createWorkflow` function imported from `@medusajs/framework/workflows-sdk` to create the workflow.
|
||||
You can now create the workflow that runs the `createBrandStep`. A workflow is created in a TypeScript or JavaScript file under the `src/workflows` directory. In the file, you use `createWorkflow` from the Workflows SDK to create the workflow.
|
||||
|
||||
Add the following content in the same `src/workflows/create-brand.ts` file:
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ export default defineMiddlewares({
|
||||
|
||||
You apply the `validateAndTransformQuery` middleware on the `GET /admin/brands` API route. The middleware accepts two parameters:
|
||||
|
||||
- A [Zod](https://zod.dev/) schema that a request's query parameters must satisfy. Medusa provides a `createFindParams` utility that generates a Zod schema with the following properties:
|
||||
- A [Zod](https://zod.dev/) schema that a request's query parameters must satisfy. Medusa provides `createFindParams` that generates a Zod schema with the following properties:
|
||||
- `fields`: A comma-separated string indicating the fields to retrieve.
|
||||
- `limit`: The maximum number of items to retrieve.
|
||||
- `offset`: The number of items to skip before retrieving the returned items.
|
||||
|
||||
@@ -75,7 +75,7 @@ In the `instrumentation.ts` file, you export a `register` function that uses Med
|
||||
|
||||
You also initialize an instance of the exporter, such as Zipkin, and pass it to the `registerOtel` function.
|
||||
|
||||
The `registerOtel` utility function accepts an object having the following properties:
|
||||
`registerOtel` accepts an object having the following properties:
|
||||
|
||||
<TypeList
|
||||
types={[
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you'll learn how to write integration tests for API routes using the [medusaIntegrationTestRunner utility function](../page.mdx).
|
||||
In this chapter, you'll learn how to write integration tests for API routes using [medusaIntegrationTestRunner](../page.mdx) from Medusa's Testing Framework.
|
||||
|
||||
<Prerequisites
|
||||
items={[
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you'll learn about the `medusaIntegrationTestRunner` utility function used to write integration tests.
|
||||
In this chapter, you'll learn about `medusaIntegrationTestRunner` from Medusa's Testing Framework and how to use it to write integration tests.
|
||||
|
||||
<Prerequisites
|
||||
items={[
|
||||
@@ -19,7 +19,7 @@ In this chapter, you'll learn about the `medusaIntegrationTestRunner` utility fu
|
||||
|
||||
## medusaIntegrationTestRunner Utility
|
||||
|
||||
The `medusaIntegrationTestRunner` utility function is provided by the `@medusajs/test-utils` package to create integration tests in your Medusa project. It runs a full Medusa application, allowing you test API routes, workflows, or other customizations.
|
||||
The `medusaIntegrationTestRunner` is from Medusa's Testing Framework and it's used to create integration tests in your Medusa project. It runs a full Medusa application, allowing you test API routes, workflows, or other customizations.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you'll learn how to write integration tests for workflows using the [medusaIntegrationTestRunner utility function](../page.mdx).
|
||||
In this chapter, you'll learn how to write integration tests for workflows using [medusaIntegrationTestRunner](../page.mdx) from Medusa's Testing Framwork.
|
||||
|
||||
<Prerequisites
|
||||
items={[
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, find an example of writing an integration test for a module using the [moduleIntegrationTestRunner utility function](../page.mdx).
|
||||
In this chapter, find an example of writing an integration test for a module using [moduleIntegrationTestRunner](../page.mdx) from Medusa's Testing Framework.
|
||||
|
||||
<Prerequisites
|
||||
items={[
|
||||
|
||||
@@ -6,7 +6,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you'll learn about the `moduleIntegrationTestRunner` utility function and how to use it to write integration tests for a module's main service.
|
||||
In this chapter, you'll learn about `moduleIntegrationTestRunner` from Medusa's Testing Framework and how to use it to write integration tests for a module's main service.
|
||||
|
||||
<Prerequisites
|
||||
items={[
|
||||
@@ -19,7 +19,7 @@ In this chapter, you'll learn about the `moduleIntegrationTestRunner` utility fu
|
||||
|
||||
## moduleIntegrationTestRunner Utility
|
||||
|
||||
The `moduleIntegrationTestRunner` utility function is provided by the `@medusajs/test-utils` package to create integration tests for a module. The integration tests run on a test Medusa application with only the specified module enabled.
|
||||
`moduleIntegrationTestRunner` creates integration tests for a module. The integration tests run on a test Medusa application with only the specified module enabled.
|
||||
|
||||
For example, assuming you have a `hello` module, create a test file at `src/modules/hello/__tests__/service.spec.ts`:
|
||||
|
||||
|
||||
@@ -8,11 +8,9 @@ In this chapter, you'll learn about Medusa's testing tools and how to install an
|
||||
|
||||
## @medusajs/test-utils Package
|
||||
|
||||
Medusa provides a `@medusajs/test-utils` package with utility tools to create integration tests for your custom API routes, modules, or other Medusa customizations.
|
||||
Medusa provides a Testing Framework to create integration tests for your custom API routes, modules, or other Medusa customizations.
|
||||
|
||||
### Install @medusajs/test-utils
|
||||
|
||||
To use the `@medusajs/test-utils` package, install it as a `devDependency`:
|
||||
To use the Testing Framework, install `@medusajs/test-utils` as a `devDependency`:
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save-dev @medusajs/test-utils@latest
|
||||
@@ -92,7 +90,7 @@ You now have two commands:
|
||||
|
||||
<Note>
|
||||
|
||||
Medusa provides utility tools for integration tests only. You can write unit tests using Jest.
|
||||
Medusa's Testing Framework works for integration tests only. You can write unit tests using Jest.
|
||||
|
||||
</Note>
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ export const config = defineRouteConfig({
|
||||
export default CustomPage
|
||||
```
|
||||
|
||||
The configuration object is created using the `defineRouteConfig` function imported from `@medusajs/admin-sdk`. It accepts the following properties:
|
||||
The configuration object is created using `defineRouteConfig` from the Medusa Framework. It accepts the following properties:
|
||||
|
||||
- `label`: the sidebar item’s label.
|
||||
- `icon`: an optional React component used as an icon in the sidebar.
|
||||
|
||||
@@ -61,7 +61,7 @@ export default ProductWidget
|
||||
|
||||
You export the `ProductWidget` component, which shows the heading `Product Widget`. In the widget, you use [Medusa UI](!ui!), a package that Medusa maintains to allow you to customize the dashboard with the same components used to build it.
|
||||
|
||||
To export the widget's configurations, you use the `defineWidgetConfig` function imported from `@medusajs/admin-sdk`. It accepts as a parameter an object with the `zone` property, whose value is a string or an array of strings, each being the name of the zone to inject the widget into.
|
||||
To export the widget's configurations, you use `defineWidgetConfig` from the Admin Extension SDK. It accepts as a parameter an object with the `zone` property, whose value is a string or an array of strings, each being the name of the zone to inject the widget into.
|
||||
|
||||
In the example above, the widget is injected at the top of a product’s details.
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ In this guide, you'll learn how to throw errors in your Medusa application, how
|
||||
|
||||
## Throw MedusaError
|
||||
|
||||
When throwing an error in your API routes, middlewares, workflows, or any customization, throw a `MedusaError`, which is imported from `@medusajs/framework/utils`.
|
||||
When throwing an error in your API routes, middlewares, workflows, or any customization, throw a `MedusaError` from the Medusa Framework.
|
||||
|
||||
The Medusa application's API route error handler then wraps your thrown error in a uniform object and returns it in the response.
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ Refer to the API Reference for [Admin](!api!/admin#authentication) and [Store](!
|
||||
|
||||
## Protect Custom API Routes
|
||||
|
||||
To protect custom API Routes to only allow authenticated customer or admin users, use the `authenticate` middleware imported from `@medusajs/medusa`.
|
||||
To protect custom API Routes to only allow authenticated customer or admin users, use the `authenticate` middleware from the Medusa Framework.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ You use Query to retrieve the stock location, to use the first location in the a
|
||||
|
||||
Then, you generate inventory levels for each inventory item, associating it with the first stock location.
|
||||
|
||||
Finally, you use the `createInventoryLevelsWorkflow` imported from `@medusajs/medusa/core-flows` to create the inventory levels.
|
||||
Finally, you use the `createInventoryLevelsWorkflow` from Medusa's core workflows to create the inventory levels.
|
||||
|
||||
### Test Script
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ In this chapter, you'll learn how to infer the type of a data model.
|
||||
|
||||
Consider you have a `MyCustom` data model. You can't reference this data model in a type, such as a workflow input or service method output types, since it's a variable.
|
||||
|
||||
Instead, Medusa provides an `InferTypeOf` utility imported from `@medusajs/framework/types` that transforms your data model to a type.
|
||||
Instead, Medusa provides `InferTypeOf` that transforms your data model to a type.
|
||||
|
||||
For example:
|
||||
|
||||
@@ -21,7 +21,7 @@ import { MyCustom } from "../models/my-custom" // relative path to the model
|
||||
export type MyCustom = InferTypeOf<typeof MyCustom>
|
||||
```
|
||||
|
||||
The `InferTypeOf` utility accepts as a type argument the type of the data model.
|
||||
`InferTypeOf` accepts as a type argument the type of the data model.
|
||||
|
||||
Since the `MyCustom` data model is a variable, use the `typeof` operator to pass the data model as a type argument to `InferTypeOf`.
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ export const metadata = {
|
||||
|
||||
In this chapter, you’ll learn about the types of properties in a data model’s schema.
|
||||
|
||||
These types are available as methods on the `model` utility imported from `@medusajs/framework/utils`.
|
||||
|
||||
## id
|
||||
|
||||
The `id` method defines an automatically generated string ID property. The generated ID is a unique string that has a mix of letters and numbers.
|
||||
|
||||
@@ -8,7 +8,7 @@ In this chapter, you’ll learn how to define relationships between data models
|
||||
|
||||
## What is a Relationship Property?
|
||||
|
||||
A relationship property defines an association in the database between two models. It's created using methods on the `models` utility, such as `hasOne` or `belongsTo`.
|
||||
A relationship property defines an association in the database between two models. It's created using the Data Model Language (DML) methods, such as `hasOne` or `belongsTo`.
|
||||
|
||||
When you generate a migration for these data models, the migrations include foreign key columns or pivot tables, based on the relationship's type.
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Instead, you use a module link. A module link forms an association between two d
|
||||
|
||||
### 1. Create Link File
|
||||
|
||||
Links are defined in a TypeScript or JavaScript file under the `src/links` directory. The file defines the link using the `defineLink` function imported from `@medusajs/framework/utils` and exports it.
|
||||
Links are defined in a TypeScript or JavaScript file under the `src/links` directory. The file defines the link using `defineLink` from the Modules SDK and exports it.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you’ll learn about the Query utility and how to use it to fetch data from modules.
|
||||
In this chapter, you’ll learn about Query and how to use it to fetch data from modules.
|
||||
|
||||
## What is Query?
|
||||
|
||||
|
||||
@@ -18,12 +18,12 @@ This chapter is intended for more advanced database use-cases where you need mor
|
||||
|
||||
[MikroORM's entity manager](https://mikro-orm.io/docs/entity-manager) is a class that has methods to run queries on the database and perform operations.
|
||||
|
||||
Medusa provides an `InjectManager` decorator imported from `@medusajs/utils` that injects a service's method with a [forked entity manager](https://mikro-orm.io/docs/identity-map#forking-entity-manager).
|
||||
Medusa provides an `InjectManager` decorator from the Modules SDK that injects a service's method with a [forked entity manager](https://mikro-orm.io/docs/identity-map#forking-entity-manager).
|
||||
|
||||
So, to run database queries in a service:
|
||||
|
||||
1. Add the `InjectManager` decorator to the method.
|
||||
2. Add as a last parameter an optional `sharedContext` parameter that has the `MedusaContext` decorator imported from `@medusajs/utils`. This context holds database-related context, including the manager injected by `InjectManager`
|
||||
2. Add as a last parameter an optional `sharedContext` parameter that has the `MedusaContext` decorator from the Modules SDK. This context holds database-related context, including the manager injected by `InjectManager`
|
||||
|
||||
For example, in your service, add the following methods:
|
||||
|
||||
@@ -81,10 +81,10 @@ Refer to [MikroORM's reference](https://mikro-orm.io/api/5.9/knex/class/EntityMa
|
||||
|
||||
To wrap database operations in a transaction, you create two methods:
|
||||
|
||||
1. A private or protected method that's wrapped in a transaction. To wrap it in a transaction, you use the `InjectTransactionManager` decorator imported from `@medusajs/utils`.
|
||||
1. A private or protected method that's wrapped in a transaction. To wrap it in a transaction, you use the `InjectTransactionManager` decorator from the Modules SDK.
|
||||
2. A public method that calls the transactional method. You use on it the `InjectManager` decorator as explained in the previous section.
|
||||
|
||||
Both methods must accept as a last parameter an optional `sharedContext` parameter that has the `MedusaContext` decorator imported from `@medusajs/utils`. It holds database-related contexts passed through the Medusa application.
|
||||
Both methods must accept as a last parameter an optional `sharedContext` parameter that has the `MedusaContext` decorator from the Modules SDK. It holds database-related contexts passed through the Medusa application.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ Modules are created in a sub-directory of `src/modules`. So, start by creating t
|
||||
|
||||
### 1. Create Data Model
|
||||
|
||||
A data model represents a table in the database. You create data models using Medusa's data modeling utility. It simplifies defining a table's columns, relations, and indexes with straightforward methods and configurations.
|
||||
A data model represents a table in the database. You create data models using Medusa's data modeling language (DML). It simplifies defining a table's columns, relations, and indexes with straightforward methods and configurations.
|
||||
|
||||
You create a data model in a TypeScript or JavaScript file under the `models` directory of a module. So, to create a `Post` data model in the Blog Module, create the file `src/modules/blog/models/post.ts` with the following content:
|
||||
|
||||
@@ -45,7 +45,7 @@ const Post = model.define("post", {
|
||||
export default Post
|
||||
```
|
||||
|
||||
You define the data model using the `define` method of the `model` utility imported from `@medusajs/framework/utils`. It accepts two parameters:
|
||||
You define the data model using the `define` method of the DML. It accepts two parameters:
|
||||
|
||||
1. The first one is the name of the data model's table in the database. Use snake-case names.
|
||||
2. The second is an object, which is the data model's schema. The schema's properties are defined using the `model`'s methods, such as `text` and `id`.
|
||||
@@ -84,7 +84,7 @@ class BlogModuleService extends MedusaService({
|
||||
export default BlogModuleService
|
||||
```
|
||||
|
||||
Your module's service extends a class generated by the `MedusaService` utility function. This class comes with generated methods for data-management Create, Read, Update, and Delete (CRUD) operations on each of your modules, saving your time that can be spent on building custom business logic.
|
||||
Your module's service extends a class generated by `MedusaService` from the Modules SDK. This class comes with generated methods for data-management Create, Read, Update, and Delete (CRUD) operations on each of your modules, saving your time that can be spent on building custom business logic.
|
||||
|
||||
The `MedusaService` function accepts an object of data models to generate methods for. You can pass all data models in your module in this object.
|
||||
|
||||
@@ -123,7 +123,7 @@ export default Module(BLOG_MODULE, {
|
||||
})
|
||||
```
|
||||
|
||||
You use the `Module` function imported from `@medusajs/framework/utils` to create the module's definition. It accepts two parameters:
|
||||
You use `Module` from the Modules SDK to create the module's definition. It accepts two parameters:
|
||||
|
||||
1. The name that the module's main service is registered under (`blog`).
|
||||
2. An object with a required property `service` indicating the module's main service.
|
||||
|
||||
@@ -24,7 +24,7 @@ Your workflow isn't reusable by other applications. Use a step that performs wha
|
||||
|
||||
## How to Expose a Hook in a Workflow?
|
||||
|
||||
To expose a hook in your workflow, use the `createHook` function imported from `@medusajs/framework/workflows-sdk`.
|
||||
To expose a hook in your workflow, use `createHook` from the Workflows SDK.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you'll learn how to execute an action based on a condition in a workflow using the when-then utility.
|
||||
In this chapter, you'll learn how to execute an action based on a condition in a workflow using when-then from the Workflows SDK.
|
||||
|
||||
## Why If-Conditions Aren't Allowed in Workflows?
|
||||
|
||||
@@ -14,15 +14,13 @@ At that point, variables in the workflow don't have any values. They only do whe
|
||||
|
||||
So, you can't use an if-condition that checks a variable's value, as the condition will be evaluated when Medusa creates the internal representation of the workflow, rather than during execution.
|
||||
|
||||
Instead, use the when-then utility.
|
||||
Instead, use when-then from the Workflows SDK.
|
||||
|
||||
---
|
||||
|
||||
## What is the When-Then Utility?
|
||||
|
||||
The when-then utility functions execute an action if a condition is satisfied.
|
||||
|
||||
The `when` function accepts as a parameter a function that returns a boolean value, and the `then` function is chained to `when`. `then` accepts as a parameter a function that's executed if `when`'s parameter function returns a `true` value.
|
||||
when-then from the Workflows SDK executes an action if a condition is satisfied. The `when` function accepts as a parameter a function that returns a boolean value, and the `then` function is chained to `when`. `then` accepts as a parameter a function that's executed if `when`'s parameter function returns a `true` value.
|
||||
|
||||
For example:
|
||||
|
||||
@@ -70,7 +68,7 @@ In this code snippet, you execute the `isActiveStep` only if the `input.is_activ
|
||||
|
||||
### When Parameters
|
||||
|
||||
`when` utility is a function imported from `@medusajs/framework/workflows-sdk`. It accepts the following parameters:
|
||||
`when` accepts the following parameters:
|
||||
|
||||
1. The first parameter is either an object or the workflow's input. This data is passed as a parameter to the function in `when`'s second parameter.
|
||||
2. The second parameter is a function that returns a boolean indicating whether to execute the action in `then`.
|
||||
|
||||
@@ -38,7 +38,7 @@ Learn more about why you can't manipulate variables [in this chapter](../variabl
|
||||
|
||||
</Note>
|
||||
|
||||
Instead, use the `transform` utility function imported from `@medusajs/framework/workflows-sdk`:
|
||||
Instead, use `transform` from the Workflows SDK:
|
||||
|
||||
export const highlights = [
|
||||
["9", "", "Don't manipulate variables directly."],
|
||||
@@ -132,7 +132,7 @@ Learn more about why you can't use if-conditions [in this chapter](../conditions
|
||||
|
||||
</Note>
|
||||
|
||||
Instead, use the when-then utility function imported from `@medusajs/framework/workflows-sdk`:
|
||||
Instead, use when-then from the Workflows SDK:
|
||||
|
||||
```ts
|
||||
// Don't
|
||||
|
||||
@@ -49,11 +49,11 @@ The object has an `input` property to pass input to the workflow.
|
||||
|
||||
## Preparing Input Data
|
||||
|
||||
If you need to perform some data manipulation to prepare the other workflow's input data, use the `transform` utility function imported from `@medusajs/framework/workflows-sdk`.
|
||||
If you need to perform some data manipulation to prepare the other workflow's input data, use `transform` from the Workflows SDK.
|
||||
|
||||
<Note>
|
||||
|
||||
Learn about the transform utility in [this chapter](../variable-manipulation/page.mdx).
|
||||
Learn about transform in [this chapter](../variable-manipulation/page.mdx).
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -105,11 +105,11 @@ In this example, you use the `transform` function to prepend `Hello` to the titl
|
||||
|
||||
## Run Workflow Conditionally
|
||||
|
||||
To run a workflow in another based on a condition, use the when-then utility functions imported from `@medusajs/framework/workflows-sdk`.
|
||||
To run a workflow in another based on a condition, use when-then from the Workflows SDK.
|
||||
|
||||
<Note>
|
||||
|
||||
Learn about the when-then utility in [this chapter](../conditions/page.mdx).
|
||||
Learn about when-then in [this chapter](../conditions/page.mdx).
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -152,4 +152,4 @@ const workflow = createWorkflow(
|
||||
)
|
||||
```
|
||||
|
||||
In this example, you use the `when` utility to run the `createProductsWorkflow` only if `should_create` (passed in the `input`) is enabled.
|
||||
In this example, you use when-then to run the `createProductsWorkflow` only if `should_create` (passed in the `input`) is enabled.
|
||||
@@ -30,7 +30,7 @@ You implement all custom flows within workflows, then execute them from [API rou
|
||||
|
||||
### 1. Create the Steps
|
||||
|
||||
A workflow is made of a series of steps. A step is created using the `createStep` utility function imported from `@medusajs/framework/workflows-sdk`.
|
||||
A workflow is made of a series of steps. A step is created using `createStep` from the Workflows SDK.
|
||||
|
||||
Create the file `src/workflows/hello-world.ts` with the following content:
|
||||
|
||||
@@ -245,7 +245,7 @@ export const highlights = [
|
||||
[
|
||||
"11",
|
||||
`"product"`,
|
||||
"The resource registration name imported from `@medusajs/framework/utils`.",
|
||||
"The resource registration name.",
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ In this chapter, you’ll learn how to run workflow steps in parallel.
|
||||
|
||||
## parallelize Utility Function
|
||||
|
||||
If your workflow has steps that don’t rely on one another’s results, run them in parallel using the `parallelize` utility function imported from the `@medusajs/framework/workflows-sdk`.
|
||||
If your workflow has steps that don’t rely on one another’s results, run them in parallel using `parallelize` from the Workflows SDK.
|
||||
|
||||
The workflow waits until all steps passed to the `parallelize` function finish executing before continuing to the next step.
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you'll learn how to use the `transform` utility to manipulate variables in a workflow.
|
||||
In this chapter, you'll learn how to use `transform` from the Workflows SDK to manipulate variables in a workflow.
|
||||
|
||||
## Why Variable Manipulation isn't Allowed in Workflows
|
||||
|
||||
@@ -14,13 +14,13 @@ At that point, variables in the workflow don't have any values. They only do whe
|
||||
|
||||
So, you can only pass variables as parameters to steps. But, in a workflow, you can't change a variable's value or, if the variable is an array, loop over its items.
|
||||
|
||||
Instead, use the transform utility.
|
||||
Instead, use `transform` from the Workflows SDK.
|
||||
|
||||
---
|
||||
|
||||
## What is the transform Utility?
|
||||
|
||||
The `transform` utility function creates a new variable as the result of manipulating other variables.
|
||||
`transform` creates a new variable as the result of manipulating other variables.
|
||||
|
||||
For example, consider you have two strings as the output of two steps:
|
||||
|
||||
@@ -62,7 +62,7 @@ const myWorkflow = createWorkflow(
|
||||
)
|
||||
```
|
||||
|
||||
The `transform` utility function is imported from `@medusajs/framework/workflows-sdk`. It accepts two parameters:
|
||||
`transform` accepts two parameters:
|
||||
|
||||
1. The first parameter is an object of variables to manipulate. The object is passed as a parameter to `transform`'s second parameter function.
|
||||
2. The second parameter is the function performing the variable manipulation.
|
||||
@@ -111,7 +111,7 @@ const myWorkflow = createWorkflow(
|
||||
|
||||
This workflow receives an `items` array in its input.
|
||||
|
||||
You use the `transform` utility to create an `ids` variable, which is an array of strings holding the `id` of each item in the `items` array.
|
||||
You use `transform` to create an `ids` variable, which is an array of strings holding the `id` of each item in the `items` array.
|
||||
|
||||
You then pass the `ids` variable as a parameter to the `doSomethingStep`.
|
||||
|
||||
@@ -144,7 +144,7 @@ In this workflow, `today` is only evaluated when the workflow is executed.
|
||||
|
||||
### Transform Evaluation
|
||||
|
||||
The transform utility's value is only evaluated if you pass its output to a step or in the workflow response.
|
||||
`transform`'s value is only evaluated if you pass its output to a step or in the workflow response.
|
||||
|
||||
For example, if you have the following workflow:
|
||||
|
||||
@@ -166,9 +166,9 @@ Since `str`'s value isn't used as a step's input or passed to `WorkflowResponse`
|
||||
|
||||
### Data Validation
|
||||
|
||||
The `transform` utility should only be used to perform variable or data manipulation.
|
||||
`transform` should only be used to perform variable or data manipulation.
|
||||
|
||||
If you want to perform some validation on the data, use a step or the [when-then utility](../conditions/page.mdx) instead.
|
||||
If you want to perform some validation on the data, use a step or [when-then](../conditions/page.mdx) instead.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ const HomepageCodeTabs = () => {
|
||||
[
|
||||
"5",
|
||||
`query`,
|
||||
"Query utility to retrieve data from a graph of\nall data models and their relations.",
|
||||
"use Query that retrieves data from a graph of\nall data models and their relations.",
|
||||
],
|
||||
["8", `"company"`, "Retrieve records of the `company` data model"],
|
||||
["13", "res.json", "Return a JSON response"],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const generatedEditDates = {
|
||||
"app/learn/fundamentals/scheduled-jobs/page.mdx": "2024-12-09T10:51:40.570Z",
|
||||
"app/learn/fundamentals/workflows/page.mdx": "2024-12-09T10:52:19.379Z",
|
||||
"app/learn/fundamentals/workflows/page.mdx": "2024-12-09T14:45:17.837Z",
|
||||
"app/learn/deployment/page.mdx": "2024-11-25T14:32:44.949Z",
|
||||
"app/learn/page.mdx": "2024-11-28T14:17:53.023Z",
|
||||
"app/learn/fundamentals/modules/commerce-modules/page.mdx": "2024-12-09T10:46:29.339Z",
|
||||
@@ -13,7 +13,7 @@ export const generatedEditDates = {
|
||||
"app/learn/fundamentals/page.mdx": "2024-07-04T17:26:03+03:00",
|
||||
"app/learn/fundamentals/admin-customizations/page.mdx": "2024-10-07T12:41:39.218Z",
|
||||
"app/learn/fundamentals/workflows/workflow-timeout/page.mdx": "2024-10-21T13:30:21.372Z",
|
||||
"app/learn/fundamentals/workflows/parallel-steps/page.mdx": "2024-10-21T13:30:21.372Z",
|
||||
"app/learn/fundamentals/workflows/parallel-steps/page.mdx": "2024-12-09T14:45:13.801Z",
|
||||
"app/learn/debugging-and-testing/page.mdx": "2024-05-03T17:36:38+03:00",
|
||||
"app/learn/fundamentals/medusa-container/page.mdx": "2024-12-09T11:02:38.225Z",
|
||||
"app/learn/fundamentals/api-routes/page.mdx": "2024-12-04T11:02:57.134Z",
|
||||
@@ -21,27 +21,27 @@ export const generatedEditDates = {
|
||||
"app/learn/fundamentals/workflows/access-workflow-errors/page.mdx": "2024-10-21T13:30:21.371Z",
|
||||
"app/learn/fundamentals/events-and-subscribers/page.mdx": "2024-12-09T10:48:09.285Z",
|
||||
"app/learn/fundamentals/modules/container/page.mdx": "2024-11-21T09:22:27.898Z",
|
||||
"app/learn/fundamentals/workflows/execute-another-workflow/page.mdx": "2024-10-23T07:08:55.900Z",
|
||||
"app/learn/fundamentals/workflows/execute-another-workflow/page.mdx": "2024-12-09T15:56:22.895Z",
|
||||
"app/learn/fundamentals/modules/loaders/page.mdx": "2024-12-09T10:32:29.221Z",
|
||||
"app/learn/fundamentals/admin/widgets/page.mdx": "2024-12-04T11:02:57.133Z",
|
||||
"app/learn/fundamentals/admin/widgets/page.mdx": "2024-12-09T16:43:24.260Z",
|
||||
"app/learn/fundamentals/data-models/page.mdx": "2024-12-09T11:34:51.065Z",
|
||||
"app/learn/fundamentals/modules/remote-link/page.mdx": "2024-09-30T08:43:53.127Z",
|
||||
"app/learn/fundamentals/api-routes/protected-routes/page.mdx": "2024-12-09T13:04:03.071Z",
|
||||
"app/learn/fundamentals/workflows/add-workflow-hook/page.mdx": "2024-10-21T13:30:21.371Z",
|
||||
"app/learn/fundamentals/api-routes/protected-routes/page.mdx": "2024-12-09T16:44:32.277Z",
|
||||
"app/learn/fundamentals/workflows/add-workflow-hook/page.mdx": "2024-12-09T14:42:39.693Z",
|
||||
"app/learn/fundamentals/events-and-subscribers/data-payload/page.mdx": "2024-10-21T13:30:21.369Z",
|
||||
"app/learn/fundamentals/data-models/default-properties/page.mdx": "2024-10-21T13:30:21.368Z",
|
||||
"app/learn/fundamentals/workflows/advanced-example/page.mdx": "2024-09-11T10:46:59.975Z",
|
||||
"app/learn/fundamentals/events-and-subscribers/emit-event/page.mdx": "2024-11-25T16:19:32.168Z",
|
||||
"app/learn/fundamentals/workflows/conditions/page.mdx": "2024-10-21T13:30:21.371Z",
|
||||
"app/learn/fundamentals/workflows/conditions/page.mdx": "2024-12-09T15:55:51.565Z",
|
||||
"app/learn/fundamentals/modules/module-link-directions/page.mdx": "2024-07-24T09:16:01+02:00",
|
||||
"app/learn/fundamentals/admin/page.mdx": "2024-10-23T07:08:55.898Z",
|
||||
"app/learn/fundamentals/workflows/long-running-workflow/page.mdx": "2024-12-04T07:37:59.822Z",
|
||||
"app/learn/fundamentals/workflows/constructor-constraints/page.mdx": "2024-11-25T16:19:32.168Z",
|
||||
"app/learn/fundamentals/workflows/constructor-constraints/page.mdx": "2024-12-09T14:43:35.160Z",
|
||||
"app/learn/fundamentals/data-models/write-migration/page.mdx": "2024-11-11T15:27:59.794Z",
|
||||
"app/learn/fundamentals/data-models/manage-relationships/page.mdx": "2024-10-28T04:22:21.328Z",
|
||||
"app/learn/fundamentals/modules/remote-query/page.mdx": "2024-07-21T21:20:24+02:00",
|
||||
"app/learn/fundamentals/modules/options/page.mdx": "2024-11-19T16:37:47.253Z",
|
||||
"app/learn/fundamentals/data-models/relationships/page.mdx": "2024-12-06T14:34:50.384Z",
|
||||
"app/learn/fundamentals/data-models/relationships/page.mdx": "2024-12-09T15:54:30.304Z",
|
||||
"app/learn/fundamentals/workflows/compensation-function/page.mdx": "2024-12-06T14:34:50.384Z",
|
||||
"app/learn/fundamentals/modules/service-factory/page.mdx": "2024-10-21T13:30:21.371Z",
|
||||
"app/learn/fundamentals/data-models/primary-key/page.mdx": "2024-10-21T13:30:21.368Z",
|
||||
@@ -52,44 +52,44 @@ export const generatedEditDates = {
|
||||
"app/learn/fundamentals/api-routes/http-methods/page.mdx": "2024-10-21T13:30:21.367Z",
|
||||
"app/learn/fundamentals/admin/tips/page.mdx": "2024-11-19T16:43:01.662Z",
|
||||
"app/learn/fundamentals/api-routes/cors/page.mdx": "2024-12-09T13:04:04.357Z",
|
||||
"app/learn/fundamentals/admin/ui-routes/page.mdx": "2024-12-04T11:02:57.133Z",
|
||||
"app/learn/fundamentals/admin/ui-routes/page.mdx": "2024-12-09T16:44:40.198Z",
|
||||
"app/learn/fundamentals/api-routes/middlewares/page.mdx": "2024-12-09T13:04:03.712Z",
|
||||
"app/learn/fundamentals/modules/isolation/page.mdx": "2024-12-09T11:02:38.087Z",
|
||||
"app/learn/fundamentals/data-models/configure-properties/page.mdx": "2024-10-21T13:30:21.368Z",
|
||||
"app/learn/fundamentals/data-models/index/page.mdx": "2024-10-21T13:30:21.368Z",
|
||||
"app/learn/fundamentals/custom-cli-scripts/page.mdx": "2024-10-23T07:08:55.898Z",
|
||||
"app/learn/fundamentals/data-models/property-types/page.mdx": "2024-10-28T04:22:27.540Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/integration-tests/api-routes/page.mdx": "2024-09-30T08:43:53.136Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/integration-tests/page.mdx": "2024-09-10T11:39:51.170Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/integration-tests/workflows/page.mdx": "2024-09-30T08:43:53.139Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/page.mdx": "2024-09-30T08:43:53.139Z",
|
||||
"app/learn/fundamentals/data-models/property-types/page.mdx": "2024-12-09T14:39:01.906Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/integration-tests/api-routes/page.mdx": "2024-12-09T15:34:08.049Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/integration-tests/page.mdx": "2024-12-09T15:52:01.019Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/integration-tests/workflows/page.mdx": "2024-12-09T15:51:15.422Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/page.mdx": "2024-12-09T15:53:56.878Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/unit-tests/module-example/page.mdx": "2024-09-02T11:04:27.232Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/unit-tests/page.mdx": "2024-09-02T11:03:26.997Z",
|
||||
"app/learn/fundamentals/modules/service-constraints/page.mdx": "2024-11-19T16:37:47.253Z",
|
||||
"app/learn/fundamentals/api-routes/responses/page.mdx": "2024-10-21T13:30:21.367Z",
|
||||
"app/learn/fundamentals/api-routes/validation/page.mdx": "2024-12-09T13:04:02.426Z",
|
||||
"app/learn/fundamentals/api-routes/errors/page.mdx": "2024-10-21T13:30:21.367Z",
|
||||
"app/learn/fundamentals/api-routes/errors/page.mdx": "2024-12-09T16:44:19.781Z",
|
||||
"app/learn/fundamentals/admin/constraints/page.mdx": "2024-10-21T13:30:21.366Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/modules-tests/module-example/page.mdx": "2024-10-16T08:50:03.061Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/modules-tests/page.mdx": "2024-10-16T08:50:23.232Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/modules-tests/module-example/page.mdx": "2024-12-09T15:52:22.185Z",
|
||||
"app/learn/debugging-and-testing/testing-tools/modules-tests/page.mdx": "2024-12-09T15:52:57.091Z",
|
||||
"app/learn/fundamentals/module-links/custom-columns/page.mdx": "2024-11-20T14:32:09.764Z",
|
||||
"app/learn/fundamentals/module-links/directions/page.mdx": "2024-10-21T13:30:21.369Z",
|
||||
"app/learn/fundamentals/module-links/page.mdx": "2024-10-28T04:22:27.541Z",
|
||||
"app/learn/fundamentals/module-links/query/page.mdx": "2024-12-09T13:04:01.779Z",
|
||||
"app/learn/fundamentals/module-links/page.mdx": "2024-12-09T14:39:26.668Z",
|
||||
"app/learn/fundamentals/module-links/query/page.mdx": "2024-12-09T15:54:44.798Z",
|
||||
"app/learn/fundamentals/module-links/remote-link/page.mdx": "2024-10-28T04:22:21.328Z",
|
||||
"app/learn/fundamentals/modules/db-operations/page.mdx": "2024-12-04T11:02:57.134Z",
|
||||
"app/learn/fundamentals/modules/db-operations/page.mdx": "2024-12-09T14:40:50.581Z",
|
||||
"app/learn/fundamentals/modules/multiple-services/page.mdx": "2024-10-21T13:30:21.370Z",
|
||||
"app/learn/fundamentals/modules/page.mdx": "2024-12-09T11:02:37.696Z",
|
||||
"app/learn/debugging-and-testing/instrumentation/page.mdx": "2024-09-17T08:53:15.910Z",
|
||||
"app/learn/fundamentals/modules/page.mdx": "2024-12-09T15:55:25.858Z",
|
||||
"app/learn/debugging-and-testing/instrumentation/page.mdx": "2024-12-09T15:33:05.121Z",
|
||||
"app/learn/fundamentals/api-routes/additional-data/page.mdx": "2024-12-09T13:04:04.995Z",
|
||||
"app/learn/fundamentals/workflows/variable-manipulation/page.mdx": "2024-11-19T16:43:01.663Z",
|
||||
"app/learn/fundamentals/workflows/variable-manipulation/page.mdx": "2024-12-09T15:57:54.506Z",
|
||||
"app/learn/customization/custom-features/api-route/page.mdx": "2024-12-09T10:39:30.046Z",
|
||||
"app/learn/customization/custom-features/module/page.mdx": "2024-12-09T11:02:39.826Z",
|
||||
"app/learn/customization/custom-features/workflow/page.mdx": "2024-12-09T10:46:47.051Z",
|
||||
"app/learn/customization/custom-features/module/page.mdx": "2024-12-09T14:36:02.100Z",
|
||||
"app/learn/customization/custom-features/workflow/page.mdx": "2024-12-09T14:36:29.482Z",
|
||||
"app/learn/customization/extend-features/extend-create-product/page.mdx": "2024-12-09T12:59:23.364Z",
|
||||
"app/learn/customization/custom-features/page.mdx": "2024-12-09T10:46:28.593Z",
|
||||
"app/learn/customization/customize-admin/page.mdx": "2024-12-09T11:02:38.801Z",
|
||||
"app/learn/customization/customize-admin/route/page.mdx": "2024-12-09T11:02:38.969Z",
|
||||
"app/learn/customization/customize-admin/route/page.mdx": "2024-12-09T15:32:46.656Z",
|
||||
"app/learn/customization/customize-admin/widget/page.mdx": "2024-12-09T11:02:39.108Z",
|
||||
"app/learn/customization/extend-features/define-link/page.mdx": "2024-12-09T11:02:39.346Z",
|
||||
"app/learn/customization/extend-features/page.mdx": "2024-12-09T11:02:39.244Z",
|
||||
@@ -101,8 +101,8 @@ export const generatedEditDates = {
|
||||
"app/learn/customization/next-steps/page.mdx": "2024-12-06T14:34:53.356Z",
|
||||
"app/learn/fundamentals/modules/architectural-modules/page.mdx": "2024-10-21T13:30:21.367Z",
|
||||
"app/learn/introduction/architecture/page.mdx": "2024-10-21T13:30:21.368Z",
|
||||
"app/learn/fundamentals/data-models/infer-type/page.mdx": "2024-10-21T13:30:21.368Z",
|
||||
"app/learn/fundamentals/custom-cli-scripts/seed-data/page.mdx": "2024-10-21T13:30:21.368Z",
|
||||
"app/learn/fundamentals/data-models/infer-type/page.mdx": "2024-12-09T15:54:08.713Z",
|
||||
"app/learn/fundamentals/custom-cli-scripts/seed-data/page.mdx": "2024-12-09T14:38:06.385Z",
|
||||
"app/learn/fundamentals/environment-variables/page.mdx": "2024-12-09T11:00:57.428Z",
|
||||
"app/learn/build/page.mdx": "2024-12-09T11:05:17.383Z",
|
||||
"app/learn/deployment/general/page.mdx": "2024-11-25T14:33:50.439Z",
|
||||
|
||||
Reference in new issue
Block a user