calcinator v5.0.0 Calcinator View Source
Converts actions from a controller or RPC server using JSONAPI formatted params to calls on a Calcinator.Resources
module.
Link to this section Summary
Types
Nested params format used by Ecto.Changeset.t
The name of the parameter that was used for the query and was not found
The raw request params that need to be validated as a JSONAPI document and converted to an Alembic.Document.t
A rendered JSONAPI document as a map
asociation_by_include- maps JSONAPI nested includes (`%{String.t => String.tmap}` to the nested associations (`atom Keyword.t ) that are understood byresources_module`.authorization_module- The module that implements theCalcinator.Authorizationbehaviour. Defaults toCalcinator.Authorization.Subjectless.resources_module- The module that implements theCalcinator.Resourcesbehaviour.subject- the subject that is trying to do the action and needs to be authorized byauthorization_moduleview_module- The module that implements theCalcinator.Viewbehaviour
Functions
Creates resource from params
Deletes resource with "id" in params
[Gets a resource related through a relationship] (http://jsonapi.org/format/#document-resource-object-related-resource-links)
Gets index of a resource with
(optional) pagination depending on whether the state
resources_module supports pagination
Shows resource with the "id" in params
Updates a resource with the "id" in params
Link to this section Types
insertable_params() :: %{optional(String.t) => term}
Nested params format used by Ecto.Changeset.t.
The name of the parameter that was used for the query and was not found.
The raw request params that need to be validated as a JSONAPI document and converted to an Alembic.Document.t
A rendered JSONAPI document as a map
t() :: %Calcinator{associations_by_include: map, authorization_module: module, ecto_schema_module: module, params: term, resources_module: module, subject: Calcinator.Authorization.subject, view_module: module}
asociation_by_include- maps JSONAPI nested includes (`%{String.t => String.tmap}` to the nested associations (`atom Keyword.t ) that are understood byresources_module`.authorization_module- The module that implements theCalcinator.Authorizationbehaviour. Defaults toCalcinator.Authorization.Subjectless.resources_module- The module that implements theCalcinator.Resourcesbehaviour.subject- the subject that is trying to do the action and needs to be authorized byauthorization_moduleview_module- The module that implements theCalcinator.Viewbehaviour.
Link to this section Functions
can(t, Calcinator.Authorization.action, Authorizaton.target) :: :ok | {:error, :unauthorized}
changeset(t, Ecto.Schema.t, insertable_params) :: {:ok, Ecto.Changeset.t} | {:error, Ecto.Changeset.t} | {:error, :ownership}
create(t, params) :: {:ok, rendered} | {:error, :ownership} | {:error, :sandbox_access_disallowed} | {:error, :sandbox_token_missing} | {:error, :timeout} | {:error, :unauthorized} | {:error, Alembic.Document.t} | {:error, Ecto.Changeset.t}
Creates resource from params.
Steps
stateauthorization_modulecan?(subject, :create, ecto_schema_module)- Check
paramsare a valid JSONAPI document stateauthorization_modulecan?(subject, :create, Ecto.Changeset.t)allow_sandbox_access/2stateauthorization_modulefilter_associations_can(created, subject, :show)stateview_moduleshow(authorized, ...)
Returns
{:ok, rendereded}- rendered view of created resource{:error, :ownership}- connection to backing store was not owned by the calling process{:error, :sandbox_access_disallowed}- Sandbox token was required and present, but did not have the correct information to grant access.{:error, :sandbox_token_missing}- Sandbox token was required (becausestateresources_moduleCalcinator.Resources.sandboxed?/0returnedtrue), butparams["meta"]["beam"]was not present.{:error, :timeout}- if the backing store forstateresources_moduletimes out when callingCalcinator.Resources.insert/2.{:error, :unauthorized}- ifstateauthorization_modulecan?(subject, :create, ecto_schema_module)orcan?(subject, :create, %Ecto.Changeset{})returnsfalse{:error, Alembic.Document.t}- ifparamsis not a valid JSONAPI document{:error, Ecto.Changeset.t}- if validations errors insertingEcto.Changeset.t
delete(t, params) :: :ok | {:error, {:not_found, parameter}} | {:error, :ownership} | {:error, :sandbox_access_disallowed} | {:error, :sandbox_token_missing} | {:error, :timeout} | {:error, :unauthorized} | {:error, Alembic.Document.t} | {:error, Ecto.Changeset.t} | {:error, reason :: term}
Deletes resource with "id" in params.
Steps
allow_sandbox_access/2stateresources_moduleget(id, ...)stateauthorization_modulecan?(subject, :delete, struct)stateresources_moduledelete(struct)
Returns
:ok- resource was successfully deleted{:error, {:not_found, "id"}}- The “id” did not correspond to resource in the backing store{:error, :ownership}- connection to backing store was not owned by the calling process{:error, :sandbox_access_disallowed}- Sandbox token was required and present, but did not have the correct information to grant access.{:error, :sandbox_token_missing}- Sandbox token was required (becausestateresources_moduleCalcinator.Resources.sandboxed?/0returnedtrue), butparams["meta"]["beam"]was not present.{:error, :timeout}- if the backing store forstateresources_moduletimes out when callingCalcinator.Resources.get/2orCalcinator.Resources.delete/1.{:error, :unauthorized}- Thestatesubjectis not authorized to delete the resource{:error, Alembic.Document.t}- JSONAPI error document withparamserrors{:error, Ecto.Changeset.t}- the deletion failed with the errors inEcto.Changeset.t{:error, reason}- a backing store-specific error
get(t, params, id_key :: String.t, Resources.query_options) :: {:ok, Ecto.Schema.t} | {:error, {:not_found, parameter}} | {:error, :ownership} | {:error, :timeout} | {:error, reason :: term}
index(t, params, %{base_uri: URI.t}) :: {:ok, rendered} | {:error, :ownership} | {:error, :sandbox_access_disallowed} | {:error, :sandbox_token_missing} | {:error, :timeout} | {:error, :unauthorized} | {:error, Alembic.Document.t}
Gets index of a resource with
(optional) pagination depending on whether the state
resources_module supports pagination.
Steps
stateauthorization_modulecan?(subject, :index, ecto_schema_module)allow_sandbox_access/2stateresources_modulelist/1stateauthorization_modulefilter_can(listed, subject, :show)stateauthorization_modulefilter_associations_can(filtered_listed, subject, :show)stateview_moduleindex(association_filtered, ...)
Returns
{:ok, rendered}- the rendered resources with (optional) pagination in the"meta".{:error, :ownership}- connection to backing store was not owned by the calling process{:error, :sandbox_access_disallowed}- Sandbox token was required and present, but did not have the correct information to grant access.{:error, :sandbox_token_missing}- Sandbox token was required (becausestateresources_moduleCalcinator.Resources.sandboxed?/0returnedtrue), butparams["meta"]["beam"]was not present.{:error, :timeout}- if the backing store forstateresources_moduletimes out when callinglist/1.{:error, :unauthorized}- ifstateauthorization_modulecan?(subject, :index, ecto_schema_module)returnsfalse{:error, Alembic.Document.t}- ifparamsare not valid JSONAPI.
show(t, params) :: {:ok, rendered} | {:error, {:not_found, parameter}} | {:error, :ownership} | {:error, :sandbox_access_disallowed} | {:error, :sandbox_token_missing} | {:error, :timeout} | {:error, :unauthorized} | {:error, Alembic.Document.t} | {:error, reason :: term}
Shows resource with the "id" in params.
Steps
allow_sandbox_acces/2stateresources_moduleget(id, ...)stateauthorization_modulecan?(subject, :show, got)stateauthorization_modulefilter_associations_can(got, subject, :show)stateview_moduleshow(authorized, ...)
Returns
{:ok, rendered}- rendered resource{:error, {:not_found, "id"}}- The “id” did not correspond to resource in the backing store{:error, :ownership}- connection to backing store was not owned by the calling process{:error, :sandbox_access_disallowed}- Sandbox token was required and present, but did not have the correct information to grant access.{:error, :sandbox_token_missing}- Sandbox token was required (becausestateresources_moduleCalcinator.Resources.sandboxed?/0returnedtrue), butparams["meta"]["beam"]was not present.{:error, :timeout}- if the backing store forstateresources_moduletimes out when callingCalcinator.Resources.get/2.{:error, :unauthorized}-stateauthorization_modulecan?(subject, :show, got)returnsfalse{:error, Alembic.Document.t}-paramsis not valid JSONAPI{:error, reason}- a backing store-specific error
show_relationship(t, params, map) :: {:ok, rendered} | {:error, {:not_found, parameter}} | {:error, :ownership} | {:error, :sandbox_access_disallowed} | {:error, :sandbox_token_missing} | {:error, :timeout} | {:error, :unauthorized} | {:error, Alembic.Document.t} | {:error, reason :: term}
Steps
- Gets source
stateauthorization_modulecan?(subject, :show, source)- Get related
stateauthorization_modulecan?(subject, :show, [related, source])stateauthorization_modulefilter_associations_can(related, subject, :show)stateview_moduleshow_relationship(authorized, ...)
Returns
{:ok, rendered}- rendered view of relationship{:error, {:not_found, id_key}}- The value of theid_keykey inparamsdid not correspond to a resource in the backing store.{:error, :ownership}- connection to backing store was not owned by the calling process{:error, :sandbox_access_disallowed}- Sandbox token was required and present, but did not have the correct information to grant access.{:error, :sandbox_token_missing}- Sandbox token was required (becausestateresources_moduleCalcinator.Resources.sandboxed?/0returnedtrue), butparams["meta"]["beam"]was not present.{:error, :timeout}- if the backing store forstateresources_moduletimes out when callingCalcinator.Resources.get/2.{:error, :unauthorized}- if the either the source or related resource cannot be shown{:error, Alembic.Document.t}- JSONAPI error document withparamserrors{:error, reason}- a backing store-specific error
update(t, params) :: {:ok, rendered} | {:error, :bad_gateway} | {:error, {:not_found, parameter}} | {:error, :ownership} | {:error, :sandbox_access_disallowed} | {:error, :sandbox_token_missing} | {:error, :unauthorized} | {:error, Alembic.Document.t} | {:error, Ecto.Changeset.t} | {:error, reason :: term}
Updates a resource with the "id" in params
Steps
allow_sandbox_access/2stateresources_moduleget(id, ...)- Check
paramsare a valid JSONAPI document stateauthorization_modulecan?(subject, :update, Ecto.Changeset.t)stateresources_moduleupdate(Ecto.Changeset.t, ...)stateauthorization_modulefilter_associations_can(updated, subject, :show)stateview_moduleshow(authorized, ...)
Returns
{:ok, rendered}- the rendered updated resource{:error, :bad_gateway}- backing store as internal error that can’t be represented in any other format. Try again later or call support.{:error, {:not_found, "id"}}- get failed or update failed because the resource was deleted between the get and update.{:error, :ownership}- connection to backing store was not owned by the calling process{:error, :sandbox_access_disallowed}- Sandbox token was required and present, but did not have the correct information to grant access.{:error, :sandbox_token_missing}- Sandbox token was required (becausestateresources_moduleCalcinator.Resources.sandboxed?/0returnedtrue), butparams["meta"]["beam"]was not present.{:error, :timeout}- if the backing store forstateresources_moduletimes out when callingCalcinator.Resources.get/2orCalcinator.Resources.update/2.{:error, :unauthorized}- the resource either can’t be shown or can’t be updated{:error, Alembic.Document.t}- theparamsare not valid JSONAPI{:error, Ecto.Changeset.t}- validations error when updating{:error, reason}- a backing store-specific error
update_changeset(t, Ecto.Changeset.t, params) :: {:ok, Ecto.Schema.t} | {:error, Alembic.Document.t} | {:error, Ecto.Changeset.t} | {:error, :bad_gateway} | {:error, :not_found}