Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4b86994
feat: bulk operations
ilyichv May 30, 2024
722e98e
feat: handle bulk update
ilyichv May 31, 2024
617d546
feat: bulk delete
ilyichv Jun 3, 2024
a366234
fix: adjust check uniques
ilyichv Jun 4, 2024
a0ce435
fix: add multiple input unique validation
ilyichv Jun 5, 2024
0859c3d
fix: add unique nil parameter validation
ilyichv Jun 5, 2024
76bfd2b
fix: validate_unique_input
ilyichv Jun 7, 2024
4c02e4e
fix: delete return
ilyichv Jun 18, 2024
85245c4
feat: bulk persistence hooks (#100)
ilyichv Jul 22, 2024
870d4c6
Merge remote-tracking branch 'origin/main' into feat/bulk-operations
ErikFerrari Jul 31, 2024
86d621d
Merge remote-tracking branch 'origin/main' into feat/bulk-operations
ilyichv Aug 26, 2024
7df3e16
fix: unit load link type (#104)
ilyichv Aug 30, 2024
6220682
fix: return units in bulk operations (#105)
ilyichv Aug 30, 2024
974cee6
fix: add mode to get_header_for_import and get_all_units_for_import
ilyichv Sep 26, 2024
b9812ac
feat: add nested filters and sort (#109)
ilyichv Oct 16, 2024
47c7b5e
fix: add current_unit to before_update
ilyichv Oct 22, 2024
a374502
fix: optimize find speed
ilyichv Oct 28, 2024
4f29b4d
fix: utf8
ilyichv Nov 4, 2024
fcf933a
wip
ilyichv Nov 30, 2024
1e1f013
fix: single result validator
ilyichv Nov 30, 2024
906415d
Merge remote-tracking branch 'origin/main' into feat/bulk-operations
ilyichv Feb 10, 2025
adfc40e
Merge remote-tracking branch 'origin/main' into feat/bulk-operations
ilyichv Feb 10, 2025
b9e5359
wip: bulk operations on topology (#119)
ilyichv Feb 10, 2025
67c6cf6
wip: bulk links (#118)
ilyichv Feb 10, 2025
e3af42f
wip
ilyichv Feb 11, 2025
91b885c
wip
ilyichv Feb 18, 2025
2a1fa72
wip
ilyichv Feb 21, 2025
988da39
fix: import use bulk actions
ilyichv Feb 28, 2025
d10db7f
wip
ilyichv Apr 18, 2025
411e46e
chore: version
ilyichv Jun 23, 2025
3531bac
fix: seed
ilyichv Nov 3, 2025
ff3e689
v0.4.0-bulk.1
ilyichv Nov 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/publish_hex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish package to Hex 📦
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]*"

jobs:
publish:
Expand All @@ -14,10 +14,10 @@ jobs:
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.13.4'
otp-version: '24.3'
elixir-version: "1.13.4"
otp-version: "24.3"
- name: Restore dependencies cache
uses: actions/cache@v3.3.1
uses: actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
Expand All @@ -31,4 +31,4 @@ jobs:
- name: Release & Publish
run: mix hex.publish --yes
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
20 changes: 20 additions & 0 deletions lib/arke/core/link.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ defmodule Arke.Core.Link do
arke id: :arke_link do
end

@enforce_keys [:parent_id, :child_id, :type]
defstruct [:parent_id, :child_id, :type, metadata: %{}]

def new(parent_id, child_id, type, metadata \\ %{}) do
__struct__(parent_id: parent_id, child_id: child_id, type: type, metadata: metadata)
end

def load(arke_link, %Arke.Core.Unit{arke_id: :arke_link} = unit) do
new(unit.data.parent_id, unit.data.child_id, unit.data.type, unit.metadata)
end

def load(arke_link, opts) do
{parent_id, opts} = Map.pop(opts, :parent_id, nil)
{child_id, opts} = Map.pop(opts, :child_id, nil)
{type, opts} = Map.pop(opts, :type, nil)
{metadata, opts} = Map.pop(opts, :metadata, arke_link.metadata)

new(parent_id, child_id, type, metadata)
end

def on_create(
_,
%{
Expand Down
57 changes: 37 additions & 20 deletions lib/arke/core/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ defmodule Arke.Core.Query do
- parameter => %Arke.Core.Parameter.`ParameterType` => refer to `Arke.Core.Parameter`
- operator => refer to [operators](#module-operators)
- value => any => the value that the query will search for
- negate => boolean => used to figure out whether the condition is to be denied \n
- negate => boolean => used to figure out whether the condition is to be denied
- path => [Arke.Core.Parameter.ParameterType] => the path of the parameter
\n
It is used to keep the same logic structure across all the Filter
"""

defstruct ~w[parameter operator value negate]a
defstruct ~w[parameter operator value negate path]a
@type t() :: %Arke.Core.Query.BaseFilter{}

@doc """
Expand All @@ -79,14 +81,16 @@ defmodule Arke.Core.Query do
parameter :: Arke.Core.Parameter.ParameterType,
operator :: atom(),
value :: any,
negate :: boolean
negate :: boolean(),
path :: [Arke.Core.Parameter.ParameterType]
) :: Arke.Core.Query.BaseFilter.t()
def new(parameter, operator, value, negate) do
def new(parameter, operator, value, negate, path) do
%__MODULE__{
parameter: parameter,
operator: operator,
value: cast_value(parameter, value),
negate: negate
negate: negate,
path: path
}
end

Expand All @@ -111,10 +115,12 @@ defmodule Arke.Core.Query do
@moduledoc """
Base struct Order:
- parameter => %Arke.Core.Parameter.`ParameterType` => refer to `Arke.Core.Parameter`
- direction => "child" | "parent" => the direction the query will use to search \n
- direction => "child" | "parent" => the direction the query will use to search
- path => [Arke.Core.Parameter.ParameterType] => the path of the parameter
\n
It is used to define the return order of a Query
"""
defstruct ~w[parameter direction]a
defstruct ~w[parameter direction path]a
@type t() :: %Arke.Core.Query.Order{}
end

Expand All @@ -133,18 +139,19 @@ defmodule Arke.Core.Query do
%Arke.Core.Query{}

"""
@spec new(arke :: %Arke.Core.Arke{}, project :: atom(), distinct :: atom()) :: Arke.Core.Query.t()
@spec new(arke :: %Arke.Core.Arke{}, project :: atom(), distinct :: atom()) ::
Arke.Core.Query.t()
def new(arke, project, distinct \\ nil),
do: %__MODULE__{
project: project,
arke: arke,
distinct: distinct,
persistence: nil,
filters: [],
orders: [],
offset: nil,
limit: nil
}
do: %__MODULE__{
project: project,
arke: arke,
distinct: distinct,
persistence: nil,
filters: [],
orders: [],
offset: nil,
limit: nil
}

@doc """
Add a new link filter
Expand Down Expand Up @@ -303,8 +310,8 @@ defmodule Arke.Core.Query do
# TODO: standardize parameter
# if it is a string convert it to existing atom and get it from paramater manager
# if it is an atom get it from paramater manaager
def new_base_filter(parameter, operator, value, negate) do
BaseFilter.new(parameter, operator, value, negate)
def new_base_filter(parameter, operator, value, negate, path \\ []) do
BaseFilter.new(parameter, operator, value, negate, path)
end

defp parse_base_filters(base_filters) when is_list(base_filters), do: base_filters
Expand All @@ -327,6 +334,16 @@ defmodule Arke.Core.Query do
## Return
%Arke.Core.Query{ ... orders: [ %Arke.Core.Query.Order{} ] ... }
"""

def add_order(query, parameter, direction) when is_list(parameter) do
{parameter, path} = List.pop_at(parameter, -1)

%{
query
| orders: [%Order{parameter: parameter, direction: direction, path: path} | query.orders]
}
end

def add_order(query, parameter, direction) do
%{
query
Expand Down
24 changes: 16 additions & 8 deletions lib/arke/core/unit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
metadata: metadata,
inserted_at: DatetimeHandler.parse_datetime(inserted_at, true),
updated_at: DatetimeHandler.parse_datetime(updated_at, true),
__module__: __module__,

Check warning on line 50 in lib/arke/core/unit.ex

View workflow job for this annotation

GitHub Actions / publish

the underscored variable "__module__" is used after being set. A leading underscore indicates that the value of the variable should be ignored. If this is intended please rename the variable to remove the underscore
runtime_data: runtime_data
)
end
Expand Down Expand Up @@ -99,26 +99,26 @@
metadata,
inserted_at,
updated_at,
__module__,

Check warning on line 102 in lib/arke/core/unit.ex

View workflow job for this annotation

GitHub Actions / publish

the underscored variable "__module__" is used after being set. A leading underscore indicates that the value of the variable should be ignored. If this is intended please rename the variable to remove the underscore
runtime_data
)
end
end
end

def load_data(%{data: %{parameters: parameters}} = arke, unit_data, opts) do

Check warning on line 109 in lib/arke/core/unit.ex

View workflow job for this annotation

GitHub Actions / publish

variable "parameters" is unused (if the variable is not meant to be used, prefix it with an underscore)
Enum.reduce(ArkeManager.get_parameters(arke), unit_data, fn %{
id: parameter_id,

Check warning on line 111 in lib/arke/core/unit.ex

View workflow job for this annotation

GitHub Actions / publish

variable "parameter_id" is unused (if the variable is not meant to be used, prefix it with an underscore)
arke_id: parameter_type

Check warning on line 112 in lib/arke/core/unit.ex

View workflow job for this annotation

GitHub Actions / publish

variable "parameter_type" is unused (if the variable is not meant to be used, prefix it with an underscore)
} = parameter,
new_unit_data ->
load_parameter_value(parameter, new_unit_data, opts)
end)
end

def load_parameter_value(%{id: :id} = _, data, opts), do: data

Check warning on line 119 in lib/arke/core/unit.ex

View workflow job for this annotation

GitHub Actions / publish

variable "opts" is unused (if the variable is not meant to be used, prefix it with an underscore)
def load_parameter_value(%{id: :metadata} = _, data, opts), do: data

Check warning on line 120 in lib/arke/core/unit.ex

View workflow job for this annotation

GitHub Actions / publish

variable "opts" is unused (if the variable is not meant to be used, prefix it with an underscore)
def load_parameter_value(%{id: :metadata} = _, data, opts), do: data

Check warning on line 121 in lib/arke/core/unit.ex

View workflow job for this annotation

GitHub Actions / publish

variable "opts" is unused (if the variable is not meant to be used, prefix it with an underscore)
def load_parameter_value(%{id: :arke_id} = _, data, opts), do: data
def load_parameter_value(%{id: :inserted_at} = _, data, opts), do: data
def load_parameter_value(%{id: :updated_at} = _, data, opts), do: data
Expand Down Expand Up @@ -169,8 +169,17 @@

defp handle_default_value(_), do: nil

defp get_link(%{depth: depth, link_metadata: link_metadata,starting_unit: starting_unit} = args),
do: {%{depth: depth, metadata: link_metadata,starting_unit: starting_unit}, args}
defp get_link(
%{
depth: depth,
link_metadata: link_metadata,
starting_unit: starting_unit,
link_type: link_type
} = args
),
do:
{%{depth: depth, metadata: link_metadata, starting_unit: starting_unit, type: link_type},
args}

defp get_link(args), do: {nil, args}

Expand Down Expand Up @@ -289,11 +298,11 @@
defp update_encoded_unit_data(%{data: %{only_runtime: true}}, data, _), do: data

defp update_encoded_unit_data(%{id: id}, data, value),
do:
Map.put_new(data, Atom.to_string(id), %{
:value => value,
:datetime => Arke.DatetimeHandler.now(:datetime)
})
do:
Map.put_new(data, Atom.to_string(id), %{
:value => value,
:datetime => Arke.DatetimeHandler.now(:datetime)
})

defp update_encoded_unit_data(_, data, _), do: data

Expand Down Expand Up @@ -373,7 +382,6 @@
defp parse_value(value, %{arke_id: :atom}) when is_binary(value),
do: String.to_existing_atom(value)


defp parse_value(value, %{arke_id: :date}) do
with {:ok, date} <- DatetimeHandler.parse_date(value),
do: date,
Expand Down
26 changes: 21 additions & 5 deletions lib/arke/group.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ defmodule Arke.System.Group do

# @before_compile unquote(__MODULE__)

def group_from_attr(), do: Keyword.get(__MODULE__.__info__(:attributes), :group, []) |> List.first()
def is_group?(), do: Keyword.get(__MODULE__.__info__(:attributes), :system_group, []) |> List.first()
def group_from_attr(),
do: Keyword.get(__MODULE__.__info__(:attributes), :group, []) |> List.first()

def is_group?(),
do: Keyword.get(__MODULE__.__info__(:attributes), :system_group, []) |> List.first()

def on_unit_load(arke, data, _persistence_fn), do: {:ok, data}
def before_unit_load(_arke, data, _persistence_fn), do: {:ok, data}
Expand All @@ -41,6 +44,13 @@ defmodule Arke.System.Group do
def on_unit_delete(_arke, unit), do: {:ok, unit}
def before_unit_delete(_arke, unit), do: {:ok, unit}

def before_unit_bulk_create(_arke, valid, errors), do: {:ok, valid, errors}
def on_unit_bulk_create(_arke, valid, errors), do: {:ok, valid, errors}
def before_unit_bulk_update(_arke, valid, errors), do: {:ok, valid, errors}
def on_unit_bulk_update(_arke, valid, errors), do: {:ok, valid, errors}
def before_unit_bulk_delete(_arke, valid, errors), do: {:ok, valid, errors}
def on_unit_bulk_delete(_arke, valid, errors), do: {:ok, valid, errors}

defoverridable on_unit_load: 3,
before_unit_load: 3,
on_unit_validate: 2,
Expand All @@ -51,7 +61,13 @@ defmodule Arke.System.Group do
on_unit_update: 2,
before_unit_update: 2,
on_unit_delete: 2,
before_unit_delete: 2
before_unit_delete: 2,
before_unit_bulk_create: 3,
on_unit_bulk_create: 3,
before_unit_bulk_update: 3,
on_unit_bulk_update: 3,
before_unit_bulk_delete: 3,
on_unit_bulk_delete: 3
end
end

Expand Down Expand Up @@ -96,7 +112,7 @@ defmodule Arke.System.Group do
unquote(block)

@group %{
id: id,
id: id
}
end
end
Expand All @@ -114,7 +130,7 @@ defmodule Arke.System.Group do
See example above `arke/2`

"""
@spec parameter(id :: atom(), type:: atom(), opts :: list()) :: Macro.t()
@spec parameter(id :: atom(), type :: atom(), opts :: list()) :: Macro.t()
defmacro parameter(id, type, opts \\ []) do
# parameter_dict = Arke.System.BaseParameter.parameter_options(opts, id, type)
quote bind_quoted: [id: id, type: type, opts: opts] do
Expand Down
Loading
Loading