ArtefactoryNeo4j.Util (ArtefactoryNeo4j v0.3.0)

Copy Markdown View Source

Case conversion and validation for the Neo4j boundary.

Artefactory is Elixir country — names follow Elixir conventions internally. At the Neo4j boundary, ArtefactoryNeo4j adapts to Neo4j conventions:

ThingElixir (artefactory)Neo4j
Property keyssnake_case stringcamelCase string
Node labelsPascalCase stringPascalCase string
Relationship typesMACRO_CASE stringMACRO_CASE string
Database namessnake_case atom/stringkebab-case string

Node labels and relationship types are already in Neo4j convention in %Artefact{} structs — they pass through unchanged.

Property keys and database names are converted at the boundary.

Adapted from AshNeo4j.Util by diffo-dev.

Summary

Functions

Converts property map keys from Neo4j camelCase back to Elixir snake_case. Applied to properties returned by fetch/3.

Converts property map keys from Elixir snake_case to Neo4j camelCase. Applied to %Artefact.Node{} property maps at the write boundary.

Converts a snake_case string or atom to Neo4j camelCase string. Used for property keys at the write boundary.

Converts a snake_case atom or string to a valid Neo4j database name (kebab-case). Neo4j database names may contain ASCII letters, numbers, dots, and dashes — not underscores.

Converts a Neo4j camelCase string to Elixir snake_case string. Used for property keys at the read boundary.

Returns true if the string is a valid Neo4j database name (letters, numbers, dots, dashes).

Returns true if the string is a valid Neo4j node label (PascalCase).

Returns true if the string is a valid Neo4j property key (camelCase, starts lowercase).

Returns true if the string is a valid Neo4j relationship type (MACRO_CASE).

Functions

properties_from_neo4j(props)

Converts property map keys from Neo4j camelCase back to Elixir snake_case. Applied to properties returned by fetch/3.

Examples

iex> ArtefactoryNeo4j.Util.properties_from_neo4j(%{"firstName" => "Matt", "age" => 42})
%{"first_name" => "Matt", "age" => 42}

properties_to_neo4j(props)

Converts property map keys from Elixir snake_case to Neo4j camelCase. Applied to %Artefact.Node{} property maps at the write boundary.

Examples

iex> ArtefactoryNeo4j.Util.properties_to_neo4j(%{"first_name" => "Matt", "age" => 42})
%{"firstName" => "Matt", "age" => 42}

to_camel_case(value)

Converts a snake_case string or atom to Neo4j camelCase string. Used for property keys at the write boundary.

Examples

iex> ArtefactoryNeo4j.Util.to_camel_case("first_name")
"firstName"
iex> ArtefactoryNeo4j.Util.to_camel_case("name")
"name"
iex> ArtefactoryNeo4j.Util.to_camel_case(:first_name)
"firstName"

to_database_name(value)

Converts a snake_case atom or string to a valid Neo4j database name (kebab-case). Neo4j database names may contain ASCII letters, numbers, dots, and dashes — not underscores.

Examples

iex> ArtefactoryNeo4j.Util.to_database_name(:matt_me)
"matt-me"
iex> ArtefactoryNeo4j.Util.to_database_name("diffo_mob")
"diffo-mob"
iex> ArtefactoryNeo4j.Util.to_database_name("already-fine")
"already-fine"

to_snake_case(value)

Converts a Neo4j camelCase string to Elixir snake_case string. Used for property keys at the read boundary.

Examples

iex> ArtefactoryNeo4j.Util.to_snake_case("firstName")
"first_name"
iex> ArtefactoryNeo4j.Util.to_snake_case("name")
"name"

valid_database_name?(value)

Returns true if the string is a valid Neo4j database name (letters, numbers, dots, dashes).

Examples

iex> ArtefactoryNeo4j.Util.valid_database_name?("matt-me")
true
iex> ArtefactoryNeo4j.Util.valid_database_name?("matt_me")
false

valid_label?(value)

Returns true if the string is a valid Neo4j node label (PascalCase).

Examples

iex> ArtefactoryNeo4j.Util.valid_label?("Agent")
true
iex> ArtefactoryNeo4j.Util.valid_label?("agent")
false

valid_property_key?(value)

Returns true if the string is a valid Neo4j property key (camelCase, starts lowercase).

Examples

iex> ArtefactoryNeo4j.Util.valid_property_key?("firstName")
true
iex> ArtefactoryNeo4j.Util.valid_property_key?("first_name")
false

valid_relationship_type?(value)

Returns true if the string is a valid Neo4j relationship type (MACRO_CASE).

Examples

iex> ArtefactoryNeo4j.Util.valid_relationship_type?("US_TWO")
true
iex> ArtefactoryNeo4j.Util.valid_relationship_type?("us_two")
false