Current section
Files
Jump to
Current section
Files
src/butterbidi@script@types@remote_value.erl
-module(butterbidi@script@types@remote_value).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/butterbidi/script/types/remote_value.gleam").
-export([node_remote_value_decoder/0, node_remote_decoder/0, error_remote_value_decoder/0, list_remote_value_decoder/0, array_remote_value_decoder/0, remote_value_decoder/0, to_string/1, to_string_list/1, to_bool/1, new_node_remote_value/1]).
-export_type([remote_value/0, list_remote_value/0, array_remote_value/0, error_remote_value/0, node_remote_value/0, node_properties/0, mode/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
"\n"
" [w3c link](https://w3c.github.io/webdriver-bidi/#type-script-RemoteValue)\n"
"\n"
).
-type remote_value() :: {primitive_protocol,
butterbidi@script@types@primitive_protocol_value:primitive_protocol_value()} |
{array_remote, array_remote_value()} |
{error_remote, error_remote_value()} |
{node_remote, node_remote_value()}.
-type list_remote_value() :: {list_remote_value, list(remote_value())}.
-type array_remote_value() :: {array_remote_value,
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(list_remote_value())}.
-type error_remote_value() :: {error_remote_value,
binary(),
gleam@option:option(binary()),
gleam@option:option(binary())}.
-type node_remote_value() :: {node_remote_value,
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(node_properties())}.
-type node_properties() :: {node_properties,
integer(),
integer(),
gleam@option:option(gleam@dict:dict(binary(), binary())),
gleam@option:option(list(node_remote_value())),
gleam@option:option(binary()),
gleam@option:option(mode()),
gleam@option:option(binary()),
gleam@option:option(gleam@option:option(node_remote_value()))}.
-type mode() :: mode_open | mode_closed.
-file("src/butterbidi/script/types/remote_value.gleam", 299).
-spec mode_decoder() -> gleam@dynamic@decode:decoder(mode()).
mode_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Variant) -> case Variant of
<<"open"/utf8>> ->
gleam@dynamic@decode:success(mode_open);
<<"closed"/utf8>> ->
gleam@dynamic@decode:success(mode_closed);
_ ->
gleam@dynamic@decode:failure(mode_open, <<"Mode"/utf8>>)
end end
).
-file("src/butterbidi/script/types/remote_value.gleam", 249).
-spec node_properties_decoder() -> gleam@dynamic@decode:decoder(node_properties()).
node_properties_decoder() ->
gleam@dynamic@decode:field(
<<"nodeType"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Node_type) ->
gleam@dynamic@decode:field(
<<"childNodeCount"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Child_node_count) ->
gleam@dynamic@decode:optional_field(
<<"attributes"/utf8>>,
none,
gleam@dynamic@decode:optional(
gleam@dynamic@decode:dict(
{decoder,
fun gleam@dynamic@decode:decode_string/1},
{decoder,
fun gleam@dynamic@decode:decode_string/1}
)
),
fun(Attributes) ->
gleam@dynamic@decode:optional_field(
<<"children"/utf8>>,
none,
gleam@dynamic@decode:optional(
gleam@dynamic@decode:list(
node_remote_value_decoder()
)
),
fun(Children) ->
gleam@dynamic@decode:optional_field(
<<"localName"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(Local_name) ->
gleam@dynamic@decode:optional_field(
<<"mode"/utf8>>,
none,
gleam@dynamic@decode:optional(
mode_decoder()
),
fun(Mode) ->
gleam@dynamic@decode:optional_field(
<<"nodeValue"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(Node_value) ->
gleam@dynamic@decode:optional_field(
<<"shadow_root"/utf8>>,
none,
gleam@dynamic@decode:optional(
gleam@dynamic@decode:optional(
node_remote_value_decoder(
)
)
),
fun(Shadow_root) ->
gleam@dynamic@decode:success(
{node_properties,
Node_type,
Child_node_count,
Attributes,
Children,
Local_name,
Mode,
Node_value,
Shadow_root}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
).
-file("src/butterbidi/script/types/remote_value.gleam", 205).
-spec node_remote_value_decoder() -> gleam@dynamic@decode:decoder(node_remote_value()).
node_remote_value_decoder() ->
gleam@dynamic@decode:field(
<<"type"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Remote_type) ->
gleam@dynamic@decode:optional_field(
<<"sharedId"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Shared_id) ->
gleam@dynamic@decode:optional_field(
<<"handle"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Handle) ->
gleam@dynamic@decode:optional_field(
<<"internalId"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(Internal_id) ->
gleam@dynamic@decode:optional_field(
<<"value"/utf8>>,
none,
gleam@dynamic@decode:optional(
node_properties_decoder()
),
fun(Value) ->
gleam@dynamic@decode:success(
{node_remote_value,
Remote_type,
Shared_id,
Handle,
Internal_id,
Value}
)
end
)
end
)
end
)
end
)
end
).
-file("src/butterbidi/script/types/remote_value.gleam", 200).
-spec node_remote_decoder() -> gleam@dynamic@decode:decoder(remote_value()).
node_remote_decoder() ->
gleam@dynamic@decode:then(
node_remote_value_decoder(),
fun(Node_remote_value) ->
gleam@dynamic@decode:success({node_remote, Node_remote_value})
end
).
-file("src/butterbidi/script/types/remote_value.gleam", 163).
-spec error_remote_value_decoder() -> gleam@dynamic@decode:decoder(remote_value()).
error_remote_value_decoder() ->
gleam@dynamic@decode:field(
<<"type"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Remote_type) ->
gleam@dynamic@decode:optional_field(
<<"handle"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Handle) ->
gleam@dynamic@decode:optional_field(
<<"internalId"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Internal_id) ->
gleam@dynamic@decode:success(
{error_remote,
{error_remote_value,
Remote_type,
Handle,
Internal_id}}
)
end
)
end
)
end
).
-file("src/butterbidi/script/types/remote_value.gleam", 119).
-spec list_remote_value_decoder() -> gleam@dynamic@decode:decoder(list_remote_value()).
list_remote_value_decoder() ->
gleam@dynamic@decode:then(
gleam@dynamic@decode:list(remote_value_decoder()),
fun(Value) ->
gleam@dynamic@decode:success({list_remote_value, Value})
end
).
-file("src/butterbidi/script/types/remote_value.gleam", 133).
-spec array_remote_value_decoder() -> gleam@dynamic@decode:decoder(remote_value()).
array_remote_value_decoder() ->
gleam@dynamic@decode:field(
<<"type"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Remote_type) ->
gleam@dynamic@decode:optional_field(
<<"handle"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Handle) ->
gleam@dynamic@decode:optional_field(
<<"internalId"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Internal_id) ->
gleam@dynamic@decode:optional_field(
<<"value"/utf8>>,
none,
gleam@dynamic@decode:optional(
list_remote_value_decoder()
),
fun(Value) ->
gleam@dynamic@decode:success(
{array_remote,
{array_remote_value,
Remote_type,
Handle,
Internal_id,
Value}}
)
end
)
end
)
end
)
end
).
-file("src/butterbidi/script/types/remote_value.gleam", 23).
-spec remote_value_decoder() -> gleam@dynamic@decode:decoder(remote_value()).
remote_value_decoder() ->
gleam@dynamic@decode:field(
<<"type"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Remote_type) -> case Remote_type of
<<"undefined"/utf8>> ->
gleam@dynamic@decode:success(
{primitive_protocol,
{undefined, {undefined_value, Remote_type}}}
);
<<"null"/utf8>> ->
gleam@dynamic@decode:success(
{primitive_protocol, {null, {null_value, Remote_type}}}
);
<<"string"/utf8>> ->
gleam@dynamic@decode:field(
<<"value"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Value) ->
gleam@dynamic@decode:success(
{primitive_protocol,
{string, {string_value, Remote_type, Value}}}
)
end
);
<<"number"/utf8>> ->
gleam@dynamic@decode:field(
<<"value"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_dynamic/1},
fun(Value@1) ->
Value@2 = butterbidi@script@types@primitive_protocol_value:number_value_classifier(
Value@1
),
gleam@dynamic@decode:success(
{primitive_protocol,
{number,
{number_value, Remote_type, Value@2}}}
)
end
);
<<"boolean"/utf8>> ->
gleam@dynamic@decode:field(
<<"value"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_bool/1},
fun(Value@3) ->
gleam@dynamic@decode:success(
{primitive_protocol,
{boolean,
{boolean_value, Remote_type, Value@3}}}
)
end
);
<<"bigint"/utf8>> ->
gleam@dynamic@decode:field(
<<"value"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Value@4) ->
gleam@dynamic@decode:success(
{primitive_protocol,
{big_int,
{big_int_value, Remote_type, Value@4}}}
)
end
);
<<"error"/utf8>> ->
error_remote_value_decoder();
<<"array"/utf8>> ->
array_remote_value_decoder();
<<"node"/utf8>> ->
node_remote_decoder();
_ ->
_pipe = palabres:error(<<"Unknown remote value type"/utf8>>),
_pipe@1 = palabres:string(
_pipe,
<<"type"/utf8>>,
Remote_type
),
palabres:log(_pipe@1),
gleam@dynamic@decode:failure(
{error_remote,
{error_remote_value, Remote_type, none, none}},
<<"Unknown remote value type"/utf8>>
)
end end
).
-file("src/butterbidi/script/types/remote_value.gleam", 69).
-spec to_string(remote_value()) -> binary().
to_string(Remote_value) ->
case Remote_value of
{primitive_protocol, Primitive} ->
butterbidi@script@types@primitive_protocol_value:to_string(
Primitive
);
_ ->
_pipe = palabres:error(<<"expected primitive"/utf8>>),
_pipe@1 = palabres:string(
_pipe,
<<"value"/utf8>>,
gleam@string:inspect(Remote_value)
),
palabres:log(_pipe@1),
butterbidi@script@types@primitive_protocol_value:to_string(
{undefined, {undefined_value, <<""/utf8>>}}
)
end.
-file("src/butterbidi/script/types/remote_value.gleam", 82).
-spec to_string_list(remote_value()) -> list(binary()).
to_string_list(Remote_value) ->
case Remote_value of
{array_remote, Array} ->
case erlang:element(5, Array) of
none ->
_pipe = palabres:error(<<"expected primitive"/utf8>>),
palabres:string(
_pipe,
<<"value"/utf8>>,
gleam@string:inspect(Remote_value)
),
[];
{some, List} ->
gleam@list:map(
erlang:element(2, List),
fun(Remote_value@1) -> to_string(Remote_value@1) end
)
end;
_ ->
_pipe@1 = palabres:error(<<"expected array"/utf8>>),
_pipe@2 = palabres:string(
_pipe@1,
<<"value"/utf8>>,
gleam@string:inspect(Remote_value)
),
palabres:log(_pipe@2),
[]
end.
-file("src/butterbidi/script/types/remote_value.gleam", 103).
-spec to_bool(remote_value()) -> boolean().
to_bool(Remote_value) ->
case Remote_value of
{primitive_protocol, Primitive} ->
butterbidi@script@types@primitive_protocol_value:to_bool(Primitive);
_ ->
_pipe = palabres:error(<<"expected primitive"/utf8>>),
_pipe@1 = palabres:string(
_pipe,
<<"value"/utf8>>,
gleam@string:inspect(Remote_value)
),
palabres:log(_pipe@1),
false
end.
-file("src/butterbidi/script/types/remote_value.gleam", 190).
-spec new_node_remote_value(binary()) -> node_remote_value().
new_node_remote_value(Remote_type) ->
{node_remote_value, Remote_type, none, none, none, none}.