I want to write an ash extension that works with ANY action. it is a custom validator + resolver
Aim: Validates that file exits and resolves the relative path to absolute path.
Ideally this DSL would do
actions do # Example action that validates a document upload action :process_document, :map do>>>>>>>>>>>>>>>>>> validate_file :document_path, max_size: "5.megabytes", allowed_types: [:pdf], base_path: "priv/uploads">>>>>>>>>>>>>>>>> argument :document_path, :string, allow_nil?: false run fn input, _context -> # By the time we get here, document_path has been validated and # converted to an absolute path path = input.arguments.document_path {:ok, %{ status: :processed, path: path, size: File.stat!(path).size }} end end
actions do # Example action that validates a document upload action :process_document, :map do>>>>>>>>>>>>>>>>>> validate_file :document_path, max_size: "5.megabytes", allowed_types: [:pdf], base_path: "priv/uploads">>>>>>>>>>>>>>>>> argument :document_path, :string, allow_nil?: false run fn input, _context -> # By the time we get here, document_path has been validated and # converted to an absolute path path = input.arguments.document_path {:ok, %{ status: :processed, path: path, size: File.stat!(path).size }} end end
The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.