documentation/dsls/DSL-AshTypescript.Rpc.md

<!--
This file was generated by Spark. Do not edit it by hand.
-->
# AshTypescript.Rpc



## typescript_rpc
Define available RPC-actions for resources in this domain.

The error handler will be called with (error, context) and should return a modified error map.
If a module is provided, it must export a handle_error/2 function.

Default error handler: {AshTypescript.Rpc.DefaultErrorHandler, :handle_error, []}

Example:
```elixir
error_handler {MyApp.CustomErrorHandler, :handle_error, []}
### or
error_handler MyApp.CustomErrorHandler

show_raised_errors?:
Set to true in development to see full error details.
Keep false in production for security.
```


### Nested DSLs
 * [resource](#typescript_rpc-resource)
   * rpc_action
   * typed_query





### Options

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`error_handler`](#typescript_rpc-error_handler){: #typescript_rpc-error_handler } | `mfa \| module` | `{AshTypescript.Rpc.DefaultErrorHandler, :handle_error, []}` | An MFA or module that implements error handling for RPC operations. |
| [`show_raised_errors?`](#typescript_rpc-show_raised_errors?){: #typescript_rpc-show_raised_errors? } | `boolean` | `false` | Whether to show detailed information for raised exceptions. |



### typescript_rpc.resource
```elixir
resource resource
```


Define available RPC-actions for a resource

### Nested DSLs
 * [rpc_action](#typescript_rpc-resource-rpc_action)
 * [typed_query](#typescript_rpc-resource-typed_query)




### Arguments

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`resource`](#typescript_rpc-resource-resource){: #typescript_rpc-resource-resource } | `module` |  | The resource being configured |



### typescript_rpc.resource.rpc_action
```elixir
rpc_action name, action
```


Define an RPC action that exposes a resource action to TypeScript clients.

Metadata fields: Action metadata can be exposed via `show_metadata` option.
Set to `nil` (default) to expose all metadata fields, `false` or `[]` to disable,
or provide a list of atoms to expose specific fields.

Metadata field naming: Use `metadata_field_names` to map invalid metadata field names
(e.g., `field_1`, `is_valid?`) to valid TypeScript identifiers.
Example: `metadata_field_names [field_1: "field1", is_valid?: "isValid"]`

Get options:
- `get?` - When true, retrieves a single resource by primary key. Requires primary key
in the RPC call and returns a single result or null.
- `get_by` - Retrieves a single resource by the specified fields. The fields must be
valid resource attributes. Returns a single result or null.






### Arguments

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`name`](#typescript_rpc-resource-rpc_action-name){: #typescript_rpc-resource-rpc_action-name } | `atom` |  | The name of the RPC-action |
| [`action`](#typescript_rpc-resource-rpc_action-action){: #typescript_rpc-resource-rpc_action-action } | `atom` |  | The resource action to expose |
### Options

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`read_action`](#typescript_rpc-resource-rpc_action-read_action){: #typescript_rpc-resource-rpc_action-read_action } | `atom` |  | The read action to use for update and destroy operations when finding records |
| [`show_metadata`](#typescript_rpc-resource-rpc_action-show_metadata){: #typescript_rpc-resource-rpc_action-show_metadata } | `nil \| boolean \| list(atom)` |  | Which metadata fields to expose (nil=all, false/[]=none, list=specific fields) |
| [`metadata_field_names`](#typescript_rpc-resource-rpc_action-metadata_field_names){: #typescript_rpc-resource-rpc_action-metadata_field_names } | `list({atom, String.t})` | `[]` | Map metadata field names to valid TypeScript identifiers (string values) |
| [`get?`](#typescript_rpc-resource-rpc_action-get?){: #typescript_rpc-resource-rpc_action-get? } | `boolean` | `false` | When true, retrieves a single resource by primary key. Returns single result or null. |
| [`get_by`](#typescript_rpc-resource-rpc_action-get_by){: #typescript_rpc-resource-rpc_action-get_by } | `list(atom)` | `[]` | Retrieves a single resource by the specified fields (must be resource attributes). Returns single result or null. |
| [`not_found_error?`](#typescript_rpc-resource-rpc_action-not_found_error?){: #typescript_rpc-resource-rpc_action-not_found_error? } | `true \| false \| nil` |  | When true (default from global config), returns an error if no record is found. When false, returns null. Only applies to get actions (get?, get_by, or action.get?). If not specified, uses the global config `config :ash_typescript, not_found_error?: true`. |
| [`identities`](#typescript_rpc-resource-rpc_action-identities){: #typescript_rpc-resource-rpc_action-identities } | `list(atom)` | `[:_primary_key]` | List of identities that can be used to look up records for update/destroy actions. Use `:_primary_key` for the primary key, or identity names like `:email`. Defaults to `[:_primary_key]`. Use `[]` for actor-scoped actions that don't need a lookup key. |
| [`enable_filter?`](#typescript_rpc-resource-rpc_action-enable_filter?){: #typescript_rpc-resource-rpc_action-enable_filter? } | `boolean` | `true` | When false, disables filter support for this read action. The filter key will not be included in the generated TypeScript config, the action's filter type won't be generated, and any filter sent by the client will be dropped. Defaults to true. |
| [`enable_sort?`](#typescript_rpc-resource-rpc_action-enable_sort?){: #typescript_rpc-resource-rpc_action-enable_sort? } | `boolean` | `true` | When false, disables sort support for this read action. The sort key will not be included in the generated TypeScript config, and any sort sent by the client will be dropped. Defaults to true. |
| [`allowed_loads`](#typescript_rpc-resource-rpc_action-allowed_loads){: #typescript_rpc-resource-rpc_action-allowed_loads } | `list(any)` |  | Restricts loadable fields to only those specified. Accepts atoms for simple fields or keyword lists for nested fields (e.g., `[:user, comments: [:author]]`). Mutually exclusive with `denied_loads`. |
| [`denied_loads`](#typescript_rpc-resource-rpc_action-denied_loads){: #typescript_rpc-resource-rpc_action-denied_loads } | `list(any)` |  | Denies loading of the specified fields. Accepts atoms for simple fields or keyword lists for nested fields (e.g., `[:user, comments: [:author]]`). Mutually exclusive with `allowed_loads`. |





### Introspection

Target: `AshTypescript.Rpc.RpcAction`

### typescript_rpc.resource.typed_query
```elixir
typed_query name, action
```








### Arguments

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`name`](#typescript_rpc-resource-typed_query-name){: #typescript_rpc-resource-typed_query-name } | `atom` |  | The name of the RPC-action |
| [`action`](#typescript_rpc-resource-typed_query-action){: #typescript_rpc-resource-typed_query-action } | `atom` |  | The read action on the resource to query |
### Options

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`ts_result_type_name`](#typescript_rpc-resource-typed_query-ts_result_type_name){: #typescript_rpc-resource-typed_query-ts_result_type_name } | `String.t` |  | The name of the TypeScript type for the query result |
| [`ts_fields_const_name`](#typescript_rpc-resource-typed_query-ts_fields_const_name){: #typescript_rpc-resource-typed_query-ts_fields_const_name } | `String.t` |  | The name of the constant for the fields, that can be reused by the client to re-run the query |
| [`fields`](#typescript_rpc-resource-typed_query-fields){: #typescript_rpc-resource-typed_query-fields } | `list(any)` |  | The fields to query |





### Introspection

Target: `AshTypescript.Rpc.TypedQuery`




### Introspection

Target: `AshTypescript.Rpc.Resource`





<style type="text/css">.spark-required::after { content: "*"; color: red !important; }</style>