Appwrite. Utils. Service
(appwrite v1.0.0)
View Source
Utility functions shared across Appwrite service modules.
Note on flatten/2
flatten/2 delegates to Appwrite.Utils.Client.flatten/2 to ensure a
single, consistent implementation throughout the SDK. Callers should prefer
Client.flatten/2 directly; this function exists as a convenience alias.
Summary
Functions
Returns the maximum chunk size (in bytes) used for file uploads.
Returns data unchanged, or raises ArgumentError if data is nil.
Flattens a nested map or indexed list into a single-level string-keyed map using bracket notation, suitable for URI query encoding.
Functions
@spec chunk_size() :: non_neg_integer()
Returns the maximum chunk size (in bytes) used for file uploads.
Examples
iex> Appwrite.Utils.Service.chunk_size()
5_242_880
Returns data unchanged, or raises ArgumentError if data is nil.
Prefer inline is_nil/1 checks and {:error, ...} tuples in service
functions. This helper is useful for validating values in pipeline-heavy
code where raising is acceptable.
Examples
iex> Appwrite.Utils.Service.ensure_not_nil("hello")
"hello"
iex> Appwrite.Utils.Service.ensure_not_nil(nil)
** (ArgumentError) Input cannot be nil
@spec flatten(Appwrite.Types.Client.Payload.t(), String.t()) :: map()
Flattens a nested map or indexed list into a single-level string-keyed map using bracket notation, suitable for URI query encoding.
Delegates to Appwrite.Utils.Client.flatten/2 to avoid duplicating logic.
Examples
iex> Appwrite.Utils.Service.flatten(%{"a" => %{"b" => "v"}})
%{"a[b]" => "v"}
iex> Appwrite.Utils.Service.flatten(%{"list" => ["x", "y"]})
%{"list[0]" => "x", "list[1]" => "y"}
iex> Appwrite.Utils.Service.flatten(["a", "b"], "items")
%{"items[0]" => "a", "items[1]" => "b"}