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

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()]}. A required field that is not a string (a number, a list, an object) counts as missing.

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

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, the entry-point guard the controller uses before any introspection. Same rule as SchemaInspector.valid_identifier?/1, which it delegates to.

Functions

valid_table_name?(name)

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

Validates a PostgreSQL table identifier, the entry-point guard the controller uses before any introspection. Same rule as SchemaInspector.valid_identifier?/1, which it delegates to.

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}