Skip to content

Commit 6320239

Browse files
committed
fix(rpc): apply output formatter to channel field in channel functions
1 parent 45d7d8a commit 6320239

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

lib/ash_typescript/rpc/codegen/function_generators/channel_renderer.ex

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ defmodule AshTypescript.Rpc.Codegen.FunctionGenerators.ChannelRenderer do
1313
alias AshTypescript.Rpc.Codegen.FunctionGenerators.{FunctionCore, JsdocGenerator}
1414
alias AshTypescript.Rpc.Codegen.Helpers.PayloadBuilder
1515

16-
import AshTypescript.Helpers,
17-
only: [
18-
formatted_result_handler_field: 0,
19-
formatted_error_handler_field: 0,
20-
formatted_timeout_handler_field: 0,
21-
formatted_timeout_field: 0
22-
]
16+
import AshTypescript.Helpers, only: [format_output_field: 1]
2317

2418
@doc """
2519
Renders a Channel execution function (handler-based).
@@ -43,23 +37,24 @@ defmodule AshTypescript.Rpc.Codegen.FunctionGenerators.ChannelRenderer do
4337
AshTypescript.Rpc.output_field_formatter()
4438
)
4539

46-
channel_config_fields = [" channel: Channel;"] ++ shape.config_fields
40+
channel_config_fields =
41+
[" #{format_output_field(:channel)}: Channel;"] ++ shape.config_fields
4742

4843
{result_handler_type, error_handler_type, timeout_handler_type, generic_part} =
4944
build_handler_types(shape)
5045

5146
config_fields =
5247
channel_config_fields ++
5348
[
54-
" #{formatted_result_handler_field()}: #{result_handler_type};",
55-
" #{formatted_error_handler_field()}?: (error: #{error_handler_type}) => void;",
56-
" #{formatted_timeout_handler_field()}?: #{timeout_handler_type};",
57-
" #{formatted_timeout_field()}?: number;"
49+
" #{format_output_field(:result_handler)}: #{result_handler_type};",
50+
" #{format_output_field(:error_handler)}?: (error: #{error_handler_type}) => void;",
51+
" #{format_output_field(:timeout_handler)}?: #{timeout_handler_type};",
52+
" #{format_output_field(:timeout)}?: number;"
5853
]
5954

6055
config_type_def = "{\n#{Enum.join(config_fields, "\n")}\n}"
6156

62-
timeout_field = formatted_timeout_field()
57+
timeout_field = format_output_field(:timeout)
6358

6459
payload_fields =
6560
PayloadBuilder.build_payload_fields(rpc_action_name, shape.context,
@@ -78,7 +73,7 @@ defmodule AshTypescript.Rpc.Codegen.FunctionGenerators.ChannelRenderer do
7873
#{jsdoc}
7974
export async function #{function_name}#{generic_part}(config: #{config_type_def}) {
8075
executeActionChannelPush<#{result_type_for_handler}>(
81-
config.channel,
76+
config.#{format_output_field(:channel)},
8277
#{payload_def},
8378
config.#{timeout_field},
8479
config
@@ -111,7 +106,7 @@ defmodule AshTypescript.Rpc.Codegen.FunctionGenerators.ChannelRenderer do
111106
)
112107

113108
config_fields =
114-
[" channel: Channel;"] ++
109+
[" #{format_output_field(:channel)}: Channel;"] ++
115110
ConfigBuilder.build_common_config_fields(resource, action, shape.context,
116111
rpc_action_name: rpc_action_name,
117112
validation_function?: true,
@@ -126,15 +121,15 @@ defmodule AshTypescript.Rpc.Codegen.FunctionGenerators.ChannelRenderer do
126121
config_fields =
127122
config_fields ++
128123
[
129-
" #{formatted_result_handler_field()}: #{result_handler_type};",
130-
" #{formatted_error_handler_field()}?: (error: #{error_handler_type}) => void;",
131-
" #{formatted_timeout_handler_field()}?: #{timeout_handler_type};",
132-
" #{formatted_timeout_field()}?: number;"
124+
" #{format_output_field(:result_handler)}: #{result_handler_type};",
125+
" #{format_output_field(:error_handler)}?: (error: #{error_handler_type}) => void;",
126+
" #{format_output_field(:timeout_handler)}?: #{timeout_handler_type};",
127+
" #{format_output_field(:timeout)}?: number;"
133128
]
134129

135130
config_type_def = "{\n#{Enum.join(config_fields, "\n")}\n}"
136131

137-
timeout_field = formatted_timeout_field()
132+
timeout_field = format_output_field(:timeout)
138133

139134
payload_fields =
140135
PayloadBuilder.build_payload_fields(rpc_action_name, shape.context,
@@ -150,7 +145,7 @@ defmodule AshTypescript.Rpc.Codegen.FunctionGenerators.ChannelRenderer do
150145
#{jsdoc}
151146
export async function #{function_name}(config: #{config_type_def}) {
152147
executeValidationChannelPush<ValidationResult>(
153-
config.channel,
148+
config.#{format_output_field(:channel)},
154149
#{payload_def},
155150
config.#{timeout_field},
156151
config

0 commit comments

Comments
 (0)