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

Instrument schematized vars #349

Closed
ikitommi opened this issue Jan 25, 2021 · 7 comments
Closed

Instrument schematized vars #349

ikitommi opened this issue Jan 25, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@ikitommi
Copy link
Member

ikitommi commented Jan 25, 2021

Way to turn schematized functions into wrapped ones that do runtime validation for input & outputs. See https://github.com/jeaye/orchestra

@ikitommi ikitommi added the enhancement New feature or request label Jan 25, 2021
@ikitommi
Copy link
Member Author

see #369.

@ianffcs
Copy link

ianffcs commented Apr 11, 2021

Hi, I was wondering with @narocath and @LeaveNhA about on how move forward on implementing this feature, we got into those
questions:

  1. Do we need to add the functions to the default-registry? or create a separate registry for functions?
  2. Do we need another m/=> like macro for register data-validators? (like m/def)
  3. Do we need to make a global atom for the default-registry? (to swap and add the functions-schemas / to swap and add data-validators schemas)
  4. Can we use nsed keyowrds for registering function-schemas / data-validator schemas?
  5. Do we want a switch to enable a type of instrumentation of malli?

@ikitommi
Copy link
Member Author

ikitommi commented Apr 20, 2021

Hi, sorry for keeping you waiting. My 2 cents:

  1. all function (var) definitions should be in the m/-function-schemas* (e.g. via m/=>) and instrument should use that
  2. have wanted to postpone that for malli 1.0.0, or add an optional malli.global ns before that. Not clear yet
  3. see 1, function schemas already have a global registry
  4. let's start with just instrumenting vars?
  5. maybe later, could start with just malli.instrument/instrument!

the api:

  • malli.instrument sounds like a good idea - an optional ns
  • instrument! and uninstrument! could be the only public api
    • 0-arity => everything
    • 1-arity => options-map, which should later have namespaced options on how to do things: fail on error, just log errors, filter based on schema properties, inputs, outputs or both, error printer, ...
  • nothing fancy for error printing needed now, just bare-bones (e.g. miu/-fail)

the bare minimum would be (adopted from https://github.com/setzer22/malli-instrument):

(require '[malli.core :as m])
(require '[malli.instrument :as mi])

(m/=> foo [:=> [:cat int? int?] string?)
(defn foo [x, y] (+ x y))

;; no implementation needed
(m/=> bar [:=> [:cat int? int?] string?)
  
(mi/instrument!)

(foo 1 2) 
;; =throws=> :malli.instrument.invalid-output {:error ["should be a string"], :value 3, :fn user/foo} 

(bar 1 2) 
;; =throws=> :malli.instrument.invalid-output {:error ["should be a string"], :value 3, :fn user/bar} 

what do you think?

@ikitommi ikitommi added the help wanted Help most welcome label Apr 30, 2021
@viebel
Copy link
Contributor

viebel commented Jun 22, 2021

Is someone working on this issue?

@ikitommi ikitommi removed the help wanted Help most welcome label Jul 4, 2021
@ikitommi
Copy link
Member Author

ikitommi commented Jul 4, 2021

this seemed stalled so started working on this, see #471.

@ikitommi
Copy link
Member Author

#471 merged in master. the new function schema guide found here: https://github.com/metosin/malli/blob/master/docs/function-schemas.md. This will be released after vacations along with many small changes.

Testing, feedback an improvements most welcome.

@viebel
Copy link
Contributor

viebel commented Jul 15, 2021

That's awesome @ikitommi.
Where will you be back from vacations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants