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 by
resources_module`.authorization_module
- The module that implements theCalcinator.Authorization
behaviour. Defaults toCalcinator.Authorization.Subjectless
.resources_module
- The module that implements theCalcinator.Resources
behaviour.subject
- the subject that is trying to do the action and needs to be authorized byauthorization_module
view_module
- The module that implements theCalcinator.View
behaviour
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 by
resources_module`.authorization_module
- The module that implements theCalcinator.Authorization
behaviour. Defaults toCalcinator.Authorization.Subjectless
.resources_module
- The module that implements theCalcinator.Resources
behaviour.subject
- the subject that is trying to do the action and needs to be authorized byauthorization_module
view_module
- The module that implements theCalcinator.View
behaviour.
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
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
{: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 (becausestate
resources_module
Calcinator.Resources.sandboxed?/0
returnedtrue
), butparams["meta"]["beam"]
was not present.{:error, :timeout}
- if the backing store forstate
resources_module
times out when callingCalcinator.Resources.insert/2
.{: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
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/2
state
resources_module
get(id, ...)
state
authorization_module
can?(subject, :delete, struct)
state
resources_module
delete(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 (becausestate
resources_module
Calcinator.Resources.sandboxed?/0
returnedtrue
), butparams["meta"]["beam"]
was not present.{:error, :timeout}
- if the backing store forstate
resources_module
times out when callingCalcinator.Resources.get/2
orCalcinator.Resources.delete/1
.{:error, :unauthorized}
- Thestate
subject
is not authorized to delete the resource{:error, Alembic.Document.t}
- JSONAPI error document withparams
errors{: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
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
{: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 (becausestate
resources_module
Calcinator.Resources.sandboxed?/0
returnedtrue
), butparams["meta"]["beam"]
was not present.{: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.
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/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
{: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 (becausestate
resources_module
Calcinator.Resources.sandboxed?/0
returnedtrue
), butparams["meta"]["beam"]
was not present.{:error, :timeout}
- if the backing store forstate
resources_module
times out when callingCalcinator.Resources.get/2
.{:error, :unauthorized}
-state
authorization_module
can?(subject, :show, got)
returnsfalse
{:error, Alembic.Document.t}
-params
is 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
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
{:ok, rendered}
- rendered view of relationship{: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, :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 (becausestate
resources_module
Calcinator.Resources.sandboxed?/0
returnedtrue
), butparams["meta"]["beam"]
was not present.{:error, :timeout}
- if the backing store forstate
resources_module
times 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 withparams
errors{: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/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
{: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 (becausestate
resources_module
Calcinator.Resources.sandboxed?/0
returnedtrue
), butparams["meta"]["beam"]
was not present.{:error, :timeout}
- if the backing store forstate
resources_module
times out when callingCalcinator.Resources.get/2
orCalcinator.Resources.update/2
.{: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{: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}