AshTypescript.Rpc

View Source

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:

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

Options

NameTypeDefaultDocs
error_handlermfa | module{AshTypescript.Rpc.DefaultErrorHandler, :handle_error, []}An MFA or module that implements error handling for RPC operations.
show_raised_errors?booleanfalseWhether to show detailed information for raised exceptions.

typescript_rpc.resource

resource resource

Define available RPC-actions for a resource

Nested DSLs

Arguments

NameTypeDefaultDocs
resourcemoduleThe resource being configured

typescript_rpc.resource.rpc_action

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

NameTypeDefaultDocs
nameatomThe name of the RPC-action
actionatomThe resource action to expose

Options

NameTypeDefaultDocs
read_actionatomThe read action to use for update and destroy operations when finding records
show_metadatanil | boolean | list(atom)Which metadata fields to expose (nil=all, false/[]=none, list=specific fields)
metadata_field_nameslist({atom, String.t})[]Map metadata field names to valid TypeScript identifiers (string values)
get?booleanfalseWhen true, retrieves a single resource by primary key. Returns single result or null.
get_bylist(atom)[]Retrieves a single resource by the specified fields (must be resource attributes). Returns single result or null.
not_found_error?true | false | nilWhen 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.
identitieslist(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.

Introspection

Target: AshTypescript.Rpc.RpcAction

typescript_rpc.resource.typed_query

typed_query name, action

Arguments

NameTypeDefaultDocs
nameatomThe name of the RPC-action
actionatomThe read action on the resource to query

Options

NameTypeDefaultDocs
ts_result_type_nameString.tThe name of the TypeScript type for the query result
ts_fields_const_nameString.tThe name of the constant for the fields, that can be reused by the client to re-run the query
fieldslist(any)The fields to query

Introspection

Target: AshTypescript.Rpc.TypedQuery

Introspection

Target: AshTypescript.Rpc.Resource