Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support additional ways to specify observables. #77

Merged
merged 10 commits into from
Apr 3, 2024
Merged
4 changes: 2 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ config :schema_server, SchemaWeb.Endpoint,
#
# config :phoenix, :serve_endpoints, true

# Do not include metadata nor timestamps in development logs
config :logger, :console,
level: :debug,
format: "[$level] $message\n"
format: "[$level] $message\n $metadata\n",
# metadata: [:pid, :mfa, :line]
metadata: [:mfa, :line]

# Set a higher stacktrace during development. Avoid configuring such
# in production as building large stacktraces may be expensive.
Expand Down
79 changes: 60 additions & 19 deletions lib/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ defmodule Schema do
@spec all_classes() :: map()
def all_classes(), do: Repo.all_classes()

@spec all_objects() :: map()
def all_objects(), do: Repo.all_objects()

@doc """
Returns a single event class.
"""
Expand Down Expand Up @@ -300,6 +303,38 @@ defmodule Schema do
# Export Functions #
# ------------------#

defp cleanup_dictionary_attributes(attributes) do
Enum.reduce(
attributes,
%{},
fn {attribute_key, attribute}, attributes ->
Map.put(
attributes,
attribute_key,
Enum.reduce(
attribute,
%{},
fn {k, v}, attribute ->
if Atom.to_string(k) |> String.starts_with?("_") do
attribute
else
Map.put(attribute, k, v)
end
end
)
)
end
)
end

defp export_dictionary_attributes() do
dictionary()[:attributes] |> cleanup_dictionary_attributes()
end

defp export_dictionary_attributes(extensions) do
dictionary(extensions)[:attributes] |> cleanup_dictionary_attributes()
end

@doc """
Exports the schema, including data types, objects, and classes.
"""
Expand All @@ -308,15 +343,17 @@ defmodule Schema do
classes: map(),
objects: map(),
types: map(),
version: binary()
dictionary_attributes: map(),
version: String.t()
}
def export_schema() do
%{
:base_event => Schema.export_base_event(),
:classes => Schema.export_classes(),
:objects => Schema.export_objects(),
:types => Schema.export_data_types(),
:version => Schema.version()
base_event: Schema.export_base_event(),
classes: Schema.export_classes(),
objects: Schema.export_objects(),
types: Schema.export_data_types(),
dictionary_attributes: export_dictionary_attributes(),
version: Schema.version()
}
end

Expand All @@ -325,15 +362,17 @@ defmodule Schema do
classes: map(),
objects: map(),
types: map(),
version: binary()
dictionary_attributes: map(),
version: String.t()
}
def export_schema(extensions) do
%{
:base_event => Schema.export_base_event(),
:classes => Schema.export_classes(extensions),
:objects => Schema.export_objects(extensions),
:types => Schema.export_data_types(),
:version => Schema.version()
base_event: Schema.export_base_event(),
classes: Schema.export_classes(extensions),
objects: Schema.export_objects(extensions),
types: Schema.export_data_types(),
dictionary_attributes: export_dictionary_attributes(extensions),
version: Schema.version()
}
end

Expand All @@ -342,19 +381,21 @@ defmodule Schema do
classes: map(),
objects: map(),
types: map(),
version: binary()
dictionary_attributes: map(),
version: String.t()
}
def export_schema(extensions, nil) do
export_schema(extensions)
end

def export_schema(extensions, profiles) do
%{
:base_event => Schema.export_base_event(profiles),
:classes => Schema.export_classes(extensions, profiles),
:objects => Schema.export_objects(extensions, profiles),
:types => Schema.export_data_types(),
:version => Schema.version()
base_event: Schema.export_base_event(profiles),
classes: Schema.export_classes(extensions, profiles),
objects: Schema.export_objects(extensions, profiles),
types: Schema.export_data_types(),
dictionary_attributes: export_dictionary_attributes(extensions),
version: Schema.version()
}
end

Expand Down Expand Up @@ -509,7 +550,7 @@ defmodule Schema do
end

defp reduce_data(object) do
delete_links(object) |> Map.delete(:_source)
delete_links(object) |> Map.drop([:_source, :_source_patched])
end

defp reduce_attributes(data) do
Expand Down
Loading
Loading