PaperTiger.ListFilters (PaperTiger v1.1.1)

Copy Markdown View Source

Shared helpers for Stripe-style list endpoint filtering.

Resource modules still declare their own supported filters. This module only provides typed matching, created-range filtering, and list-item expansion so filtering happens before cursor pagination consistently across resources.

Summary

Functions

Applies a resource's declared list filters to items.

Expands objects inside a list response.

Rejects unsupported parameter combinations before filtering.

Types

filter()

@type filter() ::
  {:boolean, atom()}
  | {:boolean, atom(), atom()}
  | {:string, atom()}
  | {:string, atom(), atom()}
  | {:enum, atom(), [String.t()]}
  | {:enum, atom(), atom(), [String.t()]}
  | {:string_in, atom(), atom(), keyword()}
  | {:nested_enum, [atom()], [String.t()]}
  | {:nested_string, [atom()]}
  | {:created, atom()}

Functions

apply(items, params, filters)

@spec apply([map()], map(), [filter()]) ::
  {:ok, [map()]} | {:error, PaperTiger.Error.t()}

Applies a resource's declared list filters to items.

expand_page(page, params)

@spec expand_page(PaperTiger.List.t(), map()) :: PaperTiger.List.t()

Expands objects inside a list response.

Stripe list expansion paths are usually prefixed with data., for example expand[]=data.product. Single-object paths are accepted too because tests and clients sometimes reuse retrieve-style params with list endpoints.

reject_combination(params, primary, forbidden)

@spec reject_combination(map(), atom(), [atom()]) ::
  :ok | {:error, PaperTiger.Error.t()}

Rejects unsupported parameter combinations before filtering.