import { TypeList } from "docs-ui"

# DevServerUtils

## Functions

- [registerDevServerResource](page.mdx#registerdevserverresource)
- [registerResourceTypeHandler](page.mdx#registerresourcetypehandler)

## Interfaces

- [BaseResourceData](../DevServerUtils/interfaces/utils.DevServerUtils.BaseResourceData/page.mdx)
- [ResourceTypeHandler](../DevServerUtils/interfaces/utils.DevServerUtils.ResourceTypeHandler/page.mdx)

## Type Aliases

- [ResourceEntry](../DevServerUtils/types/utils.DevServerUtils.ResourceEntry/page.mdx)
- [ResourceMap](../DevServerUtils/types/utils.DevServerUtils.ResourceMap/page.mdx)
- [ResourcePath](../DevServerUtils/types/utils.DevServerUtils.ResourcePath/page.mdx)
- [ResourceType](../DevServerUtils/types/utils.DevServerUtils.ResourceType/page.mdx)

## Variables

- [globalDevServerRegistry](page.mdx#globaldevserverregistry)
- [inverseDevServerRegistry](page.mdx#inversedevserverregistry)

## Functions

### registerDevServerResource

`**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:
- Validating the registration data
- Resolving the source path
- Creating the registry entry
- Generating the inverse registry key

#### Example

```typescript
// 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"
})
```

#### Parameters

<TypeList types={[{"name":"data","type":"[ResourceRegistrationData](../types/utils.ResourceRegistrationData/page.mdx)","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"/>

#### Throws

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:
- Validating the registration data
- Resolving the source path
- Creating the registry entry
- Generating the inverse registry key

#### Example

```typescript
// 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"
})
```

#### Type Parameters

<TypeList types={[{"name":"T","type":"[BaseResourceData](../DevServerUtils/interfaces/utils.DevServerUtils.BaseResourceData/page.mdx)","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"/>

#### Parameters

<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"/>

#### Throws

Error if validation fails or handler is not found

### registerResourceTypeHandler

Register a resource type handler

#### Example

```typescript
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())
```

#### Parameters

<TypeList types={[{"name":"handler","type":"[ResourceTypeHandler](../DevServerUtils/interfaces/utils.DevServerUtils.ResourceTypeHandler/page.mdx)&#60;[BaseResourceData](../DevServerUtils/interfaces/utils.DevServerUtils.BaseResourceData/page.mdx)&#62;","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"/>

___

## Variables

### globalDevServerRegistry

 `Const` **globalDevServerRegistry**: Map&#60;string, [ResourceMap](../DevServerUtils/types/utils.DevServerUtils.ResourceMap/page.mdx)&#62;

Maps source file paths to their registered resources
Structure: sourcePath -&#62; Map&#60;resourceType, ResourceEntry[]&#62;

### inverseDevServerRegistry

 `Const` **inverseDevServerRegistry**: Map&#60;string, string[]&#62;

Inverse registry for looking up source paths by resource
Structure: "type:id" -&#62; sourcePath[]
Used to find which files contain a specific resource
