PhoenixKitSync.Web.ApiController.Validators (PhoenixKitSync v0.1.4)

Copy Markdown View Source

Parameter validators for the sync REST API endpoints.

Each validator accepts the raw params map from the Phoenix controller action, checks that the required fields are present and non-empty, and returns either {:ok, validated_struct} (with typed field names as atoms) or {:error, :missing_fields, [String.t()]}.

validate_status_params/1 additionally checks that "status" is one of "active", "suspended", or "revoked" and returns {:error, :invalid_status} if not.

Extracted from ApiController in 2026-04 to shrink the controller module without changing any request/response behavior. The validators are stateless and have no dependency on Phoenix or Connections — they're pure param shape checks.

Summary

Functions

Validates a PostgreSQL table identifier: must start with a letter or underscore and contain only alphanumerics and underscores. Mirrors SchemaInspector.valid_identifier?/1 but is the entry-point guard the controller uses before attempting any introspection.

Functions

parse_int(val, default)

@spec parse_int(any(), integer()) :: integer()

valid_table_name?(name)

@spec valid_table_name?(any()) :: boolean()

Validates a PostgreSQL table identifier: must start with a letter or underscore and contain only alphanumerics and underscores. Mirrors SchemaInspector.valid_identifier?/1 but is the entry-point guard the controller uses before attempting any introspection.

validate_delete(params)

@spec validate_delete(map()) ::
  {:ok, %{sender_url: String.t(), auth_token_hash: String.t()}}
  | {:error, :missing_fields, [String.t()]}

validate_get_status(params)

@spec validate_get_status(map()) ::
  {:ok, %{receiver_url: String.t(), auth_token_hash: String.t()}}
  | {:error, :missing_fields, [String.t()]}

validate_list_tables(params)

@spec validate_list_tables(map()) ::
  {:ok, %{auth_token_hash: String.t()}}
  | {:error, :missing_fields, [String.t()]}

validate_pull_data(params)

@spec validate_pull_data(map()) ::
  {:ok, map()} | {:error, :missing_fields, [String.t()]}

validate_records(params)

@spec validate_records(map()) ::
  {:ok, map()} | {:error, :missing_fields, [String.t()]}

validate_register(params)

@spec validate_register(map()) ::
  {:ok,
   %{
     sender_url: String.t(),
     connection_name: String.t(),
     auth_token: String.t()
   }}
  | {:error, :missing_fields, [String.t()]}

validate_schema(params)

@spec validate_schema(map()) ::
  {:ok, %{auth_token_hash: String.t(), table_name: String.t()}}
  | {:error, :missing_fields, [String.t()]}

validate_status(params)

@spec validate_status(map()) ::
  {:ok,
   %{sender_url: String.t(), auth_token_hash: String.t(), status: String.t()}}
  | {:error, :missing_fields, [String.t()]}
  | {:error, :invalid_status}