Define a factory for creating entities via user code.
The factory's create function receives a validated map of fields
(with unknown keys stripped and required fields checked) and a
FactoryContext, and must return a record map that includes at
least "id".
input_fields is required because the SDK derives the discover
schema from it (no DB introspection).
Summary
Functions
Validate and return a factory definition map.
Validate a map of fields against the factory's input_fields definition.
Functions
Validate and return a factory definition map.
Options
:create(required) — a 2-arity function(data, ctx) -> record:input_fields(required) — a list of%{name: string, type: atom, required: boolean}:teardown(optional) — a 2-arity function(record, ctx) -> any:ref_fields(optional) — field defs for teardown record validation
Examples
Autonoma.Factory.define_factory(%{
create: fn data, ctx -> %{"id" => UUID.uuid4(), "name" => data["name"]} end,
input_fields: [
%{name: "name", type: :string, required: true},
%{name: "email", type: :string, required: true}
],
teardown: fn record, ctx -> MyApp.cleanup(record) end
})
Validate a map of fields against the factory's input_fields definition.
Strips unknown keys and checks that all required fields are present.
Returns {:ok, validated_map} or {:error, reason}.