diff --git a/apps/emqx_connector_aggregator/src/emqx_connector_aggregator_schema.erl b/apps/emqx_connector_aggregator/src/emqx_connector_aggregator_schema.erl new file mode 100644 index 000000000..d5cf4e9cf --- /dev/null +++ b/apps/emqx_connector_aggregator/src/emqx_connector_aggregator_schema.erl @@ -0,0 +1,89 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2024 EMQ Technologies Co., Ltd. All Rights Reserved. +%%-------------------------------------------------------------------- + +-module(emqx_connector_aggregator_schema). + +-behaviour(hocon_schema). + +-include_lib("typerefl/include/types.hrl"). +-include_lib("hocon/include/hoconsc.hrl"). + +%% API +-export([ + container/0 +]). + +%% `hocon_schema' API +-export([ + namespace/0, + roots/0, + fields/1, + desc/1 +]). + +%%------------------------------------------------------------------------------ +%% Type declarations +%%------------------------------------------------------------------------------ + +%%------------------------------------------------------------------------------ +%% API +%%------------------------------------------------------------------------------ + +container() -> + {container, + hoconsc:mk( + %% TODO: Support selectors once there are more than one container. + hoconsc:union(fun + (all_union_members) -> [ref(container_csv)]; + ({value, _Value}) -> [ref(container_csv)] + end), + #{ + required => true, + default => #{<<"type">> => <<"csv">>}, + desc => ?DESC("container") + } + )}. + +%%------------------------------------------------------------------------------ +%% `hocon_schema' API +%%------------------------------------------------------------------------------ + +namespace() -> "connector_aggregator". + +roots() -> []. + +fields(container_csv) -> + [ + {type, + mk( + csv, + #{ + required => true, + desc => ?DESC("container_csv") + } + )}, + {column_order, + mk( + hoconsc:array(string()), + #{ + required => false, + default => [], + desc => ?DESC("container_csv_column_order") + } + )} + ]. + +desc(Name) when + Name == container_csv +-> + ?DESC(Name); +desc(_Name) -> + undefined. + +%%------------------------------------------------------------------------------ +%% Internal fns +%%------------------------------------------------------------------------------ + +mk(Type, Meta) -> hoconsc:mk(Type, Meta). +ref(Name) -> hoconsc:ref(?MODULE, Name). diff --git a/rel/i18n/emqx_connector_aggregator_schema.hocon b/rel/i18n/emqx_connector_aggregator_schema.hocon new file mode 100644 index 000000000..556705d03 --- /dev/null +++ b/rel/i18n/emqx_connector_aggregator_schema.hocon @@ -0,0 +1,19 @@ +emqx_connector_aggregator_schema { + +container.label: +"""Container for aggregated events""" +container.desc: +"""Settings governing the file format of an upload containing aggregated events.""" + +container_csv.label: +"""CSV container""" +container_csv.desc: +"""Records (events) will be aggregated and uploaded as a CSV file.""" + +container_csv_column_order.label: +"""CSV column order""" +container_csv_column_order.desc: +"""Event fields that will be ordered first as columns in the resulting CSV file.
+Regardless of this setting, resulting CSV will contain all the fields of aggregated events, but all the columns not explicitly mentioned here will be ordered after the ones listed here in the lexicographical order.""" + +}