Jsonpatch.Types (Jsonpatch v2.3.3)

Copy Markdown View Source

Types

Summary

Types

casted_array_index()

@type casted_array_index() :: :- | non_neg_integer()

casted_fragment()

@type casted_fragment() :: casted_array_index() | casted_object_key()

casted_object_key()

@type casted_object_key() :: atom() | String.t()

convert_fn()

@type convert_fn() :: (fragment :: term(),
                 target_path :: [term()],
                 target :: json_container(),
                 opts() ->
                   {:ok, converted_fragment :: term()} | :error)

error()

@type error() :: {:error, error_reason()}

error_reason()

@type error_reason() ::
  {:invalid_spec, String.t()}
  | {:invalid_path, [casted_fragment()]}
  | {:test_failed, String.t()}

json_container()

@type json_container() :: map() | list()

opt_keys()

@type opt_keys() ::
  :strings
  | :atoms
  | {:custom, convert_fn()}
  | {:ignore_invalid_paths, :boolean}

Keys options:

  • :strings (default) - decodes path fragments as binary strings
  • :atoms - path fragments are converted to atoms
  • :atoms! - path fragments are converted to existing atoms
  • {:custom, convert_fn} - path fragments are converted with convert_fn

opts()

@type opts() :: [{:keys, opt_keys()}]

Apply patch options:

  • :keys - controls how path fragments are decoded

opts_diff()

@type opts_diff() :: [
  ancestor_path: String.t(),
  prepare_map: (struct() | map() -> map()),
  object_hash: (term() -> term())
]

Diff options:

  • :ancestor_path - path to the ancestor of the current node
  • :prepare_map - function to prepare the map for diffing
  • :object_hash - function to extract unique identifier from list items for optimized diffing.