www/apps/resources/references/utils/utils.DevServerUtils/page.mdx
import { TypeList } from "docs-ui"
**registerDevServerResource**(data): void``
Register a resource in the dev server for hot module reloading
This function uses a strategy pattern where each resource type has its own handler. The handler is responsible for:
// Register a workflow
registerDevServerResource({
type: "workflow",
id: "create-product",
sourcePath: "/src/workflows/create-product.ts"
})
// Register a step
registerDevServerResource({
type: "step",
id: "validate-product",
workflowId: "create-product"
})
<TypeList types={[{"name":"data","type":"ResourceRegistrationData","description":"Resource registration data","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"string","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"\"workflow\"","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sourcePath","type":"string","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subscriberId","type":"string","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"events","type":"string[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"workflowId","type":"string","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="registerDevServerResource"/>
Error if validation fails or handler is not found
**registerDevServerResource**<TypeParameter T>(data): void``
Register a resource in the dev server for hot module reloading
This function uses a strategy pattern where each resource type has its own handler. The handler is responsible for:
// Register a workflow
registerDevServerResource({
type: "workflow",
id: "create-product",
sourcePath: "/src/workflows/create-product.ts"
})
// Register a step
registerDevServerResource({
type: "step",
id: "validate-product",
workflowId: "create-product"
})
<TypeList types={[{"name":"T","type":"BaseResourceData","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"type","type":"string","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"string","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sourcePath","type":"string","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="registerDevServerResource"/>
<TypeList types={[{"name":"data","type":"T","description":"Resource registration data","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="registerDevServerResource"/>
Error if validation fails or handler is not found
Register a resource type handler
class RouteHandler implements ResourceTypeHandler<RouteData> {
readonly type = "route"
validate(data: RouteData): void { ... }
resolveSourcePath(data: RouteData): string { ... }
createEntry(data: RouteData): ResourceEntry { ... }
getInverseKey(data: RouteData): string { ... }
}
registerResourceTypeHandler(new RouteHandler())
<TypeList types={[{"name":"handler","type":"ResourceTypeHandler","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"type","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="registerResourceTypeHandler"/>
Const globalDevServerRegistry: Map<string, ResourceMap>
Maps source file paths to their registered resources Structure: sourcePath -> Map<resourceType, ResourceEntry[]>
Const inverseDevServerRegistry: Map<string, string[]>
Inverse registry for looking up source paths by resource Structure: "type:id" -> sourcePath[] Used to find which files contain a specific resource