JSON.LD.SafeMode (JSON-LD.ex v1.1.0)

Copy Markdown View Source

The handlers of the :safe option and the codes they are called with.

See the section on safe mode in JSON.LD.Options for what the option checks.

With a function as the value of the option, processing does not fail where data is dropped: the function is called with a code for what is dropped and with a map of details, and when it returns, processing goes on as without the option. What it raises ends processing. fail/2 is the handler of safe: true, so that a handler can delegate to it what it does not handle itself:

JSON.LD.to_rdf(document,
  safe: fn
    :blank_node_predicate, _details -> :ok
    code, details -> JSON.LD.SafeMode.fail(code, details)
  end
)

What a handler lets pass is not part of the RDF, and a signature over the RDF does not cover it. The same data can be reported twice: a reference to a node whose identifier is not a valid IRI is reported as a value and as a node.

Codes

The codes and the keys of their details:

CodeDroppedDetails
:invalid_propertya property that does not expand to an IRI or a keyword:property, :expanded_property
:free_floating_scalara free-floating scalar:value
:free_floating_valuea free-floating value object:value
:free_floating_lista free-floating list:value
:free_floating_nodea free-floating node object with nothing but an @id:value
:null_valuea value object without a value but with other entries:value
:object_with_only_languagean object with nothing but @language:value
:map_key_without_valuea key of a language, index, id or type map that has no value:key, :property
:unprocessed_keywordthe value of a keyword that is not processed in a node object:keyword, :value
:relative_graph_referencea graph name that is not a valid IRI:graph
:relative_subject_referencea node identifier that is not a valid IRI:subject
:relative_type_referencethe types of a node that are not valid IRIs:subject, :types
:relative_predicate_referencea property that is not a valid IRI:property
:blank_node_predicatea blank node as property:property, the identifier as in the expanded input; :path, the keys and array indexes from the top of the input to the key that is dropped
:relative_object_referencea node reference that is not a valid IRI:value, outside of a list also :subject and :property
:invalid_language_valuea value with a language tag that is not well-formed:value, outside of a list also :subject and :property
:rdf_direction_not_seta base direction, when :rdf_direction is not set:value
:node_without_statementa node identifier that is not part of any statement:subject

A blank node as :subject has the identifier of the node map, not the one of the document.

Summary

Functions

Fails with the JSON.LD.Error of safe mode for the data that is dropped.

Types

code()

@type code() ::
  :free_floating_scalar
  | :free_floating_value
  | :free_floating_list
  | :free_floating_node
  | :invalid_property
  | :unprocessed_keyword
  | :map_key_without_value
  | :null_value
  | :object_with_only_language
  | :relative_graph_reference
  | :relative_subject_reference
  | :relative_type_reference
  | :blank_node_predicate
  | :relative_predicate_reference
  | :relative_object_reference
  | :invalid_language_value
  | :rdf_direction_not_set
  | :node_without_statement

handler()

@type handler() :: (code(), map() -> any())

Functions

fail(code, details)

@spec fail(code(), map()) :: no_return()

Fails with the JSON.LD.Error of safe mode for the data that is dropped.

This is the handler of safe: true. A handler of its own delegates to it what it does not handle itself.

Examples

iex> JSON.LD.SafeMode.fail(:free_floating_scalar, %{value: 1})
** (JSON.LD.Error) safe mode: Free-floating scalar 1 is dropped