calcinator v1.5.0 Calcinator
Converts actions from a controller or RPC server using JSONAPI formatted params to calls on a Calcinator.Resources
module.
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
authorization_module
- The module that implements theCalcinator.Authorization
behavioursubject
- the subject that is trying to do the action and needs to be authorized byauthorization_module
target
- the target ofsubject
’s action
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
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
t() :: %Calcinator{associations_by_include: term, authorization_module: module, ecto_schema_module: module, params: term, resources_module: term, subject: Calcinator.Authorization.subject, view_module: module}
authorization_module
- The module that implements theCalcinator.Authorization
behavioursubject
- the subject that is trying to do the action and needs to be authorized byauthorization_module
target
- the target ofsubject
’s action
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}
create(t, params) :: {:error, :ownership} | {:error, :unauthorized} | {:error, Alembic.Document.t} | {:error, Ecto.Changeset.t} | {:ok, rendered}
Creates resource from params
.
Steps
state
authorization_module
can?(subject, :create, ecto_schema_module)
- Check
params
are a valid JSONAPI document state
authorization_module
can?(subject, :create, Ecto.Changeset.t)
allow_sandbox_access/2
state
authorization_module
filter_associations_can(created, subject, :show)
state
view_module
show(authorized, ...)
Returns
{:error, :ownership}
- connection to backing store was not owned by the calling process{:error, :unauthorized}
- ifstate
authorization_module
can?(subject, :create, ecto_schema_module)
orcan?(subject, :create, %Ecto.Changeset{})
returnsfalse
{:error, Alembic.Document.t}
- ifparams
is not a valid JSONAPI document{:error, Ecto.Changeset.t}
- if validations errors insertingEcto.Changeset.t
{:ok, rendereded}
- rendered view of created resource
delete(t, params) :: :ok | {:error, {:not_found, parameter}} | {:error, :ownership} | {:error, :unauthorized} | {:error, Ecto.Changeset.t}
Deletes resource with "id"
in params
.
Steps
allow_sandbox_access/2
state
resources_module
get(id, ...)
state
authorization_module
can?(subject, :delete, struct)
state
resources_module
delete(struct)
Returns
{: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, :unauthorized}
- Thestate
subject
is not authorized to delete the resource{:error, Ecto.Changeset.t}
- the deletion failed with the errors inEcto.Changeset.t
:ok
- resource was successfully deleted
get(module, params, id_key :: String.t, Resources.query_options) :: {:error, {:not_found, parameter} | :timeout | term} | {:ok, Ecto.Schema.t}
index(t, params, %{base_uri: URI.t}) :: {:error, :timeout} | {:error, :unauthorized} | {:error, Alembic.Document.t} | {:ok, rendered}
Gets index of a resource with
(optional) pagination depending on whether the state
resources_module
supports pagination.
Steps
state
authorization_module
can?(subject, :index, ecto_schema_module)
allow_sandbox_access/2
state
resources_module
list/1
state
authorization_module
filter_can(listed, subject, :show)
state
authorization_module
filter_associations_can(filtered_listed, subject, :show)
state
view_module
index(association_filtered, ...)
Returns
{:error, :ownership}
- connection to backing store was not owned by the calling process{:error, :timeout}
- if the backing store forstate
resources_module
times out when callinglist/1
.{:error, :unauthorized}
- ifstate
authorization_module
can?(subject, :index, ecto_schema_module)
returnsfalse
{:error, Alembic.Document.t}
- ifparams
are not valid JSONAPI.{:ok, rendered}
- the rendered resources with (optional) pagination in the"meta"
.
show(t, params) :: {:error, {:not_found, parameter}} | {:error, :ownership} | {:error, :unauthorized} | {:error, Alembic.Document.t} | {:ok, rendered}
Shows resource with the "id"
in params
.
Steps
allow_sandbox_acces/2
state
resources_module
get(id, ...)
state
authorization_module
can?(subject, :show, got)
state
authorization_module
filter_associations_can(got, subject, :show)
state
view_module
show(authorized, ...)
Returns
{: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, :unauthorized}
-state
authorization_module
can?(subject, :show, got)
returnsfalse
{:error, Alembic.Document.t}
-params
is not valid JSONAPI{:ok, rendered}
- rendered resource
Steps
- Gets source
state
authorization_module
can?(subject, :show, source)
- Get related
state
authorization_module
can?(subject, :show, [related, source])
state
authorization_module
filter_associations_can(related, subject, :show)
state
view_module
show_relationship(authorized, ...)
Returns
{:error, {:not_found, id_key}}
- The value of theid_key
key inparams
did not correspond to a resource in the backing store.{:error, :ownership}
- connection to backing store was not owned by the calling process{:error, :unauthorized}
- if the either the source or related resource cannot be shown{:ok, rendered}
- rendered view of relationship
update(t, params) :: {:error, :bad_gateway} | {:error, {:not_found, parameter}} | {:error, :ownership} | {:error, :unauthorized} | {:error, Alembic.Document.t} | {:error, Ecto.Changeset.t} | {:ok, rendered}
Updates a resource with the "id"
in params
Steps
allow_sandbox_access/2
state
resources_module
get(id, ...)
- Check
params
are a valid JSONAPI document state
authorization_module
can?(subject, :update, Ecto.Changeset.t)
state
resources_module
update(Ecto.Changeset.t, ...)
state
authorization_module
filter_associations_can(updated, subject, :show)
state
view_module
show(authorized, ...)
Returns
{: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, :unauthorized}
- the resource either can’t be shown or can’t be updated{:error, Alembic.Document.t}
- theparams
are not valid JSONAPI{:error, Ecto.Changeset.t}
- validations error when updating{:ok, rendered}
- the rendered updated resource
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}