~pepe/manisha

Schema and its validation for Good Place
d4f60e81 — Josef Pospíšil a month ago
Return old import
04e4ab5f — Josef Pospíšil a month ago
Reexport predicates
b81f9857 — Josef Pospíšil a month ago
Add num in range predicate

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~pepe/manisha
read/write
git@git.sr.ht:~pepe/manisha

You can also use your local clone with git send-email.

#manisha

This library provides tools for definning the schema for your data. Schema is defined with Janet struct, where keys are keys in the data structure and value is one or more constrains on the data type and presence.

#Ideas

These could be out of sync with the code.

Schema for the Neil database:

# custom predicate
(defn state? [item]
 (some (= $ item) ["active" "completed" "canceled"]))

(def work-interval-appraiser
  (appraiser
    table?
    {:start number?
     :end number?
     :note [some nil? present?]}))

(def work-intervals-appraiser
  (appraiser array? {values work-interval-appraiser}))

(def task-appraiser
  (appraiser
    table?
    {:uuid string?
     :name string?
     :state state?
     :work-intervals work-intervals-appraiser}))

(def tasks-appraiser
  (appraiser table? {keys string? values task-appraiser}))

(def project-appraiser
  table?
   {:uuid string?
    :name string?
    :tasks tasks-appraiser})

(def projects-appraiser
  (appraise table? {keys string? values project-appraiser}))

(def client-appraiser
  (appraiser
    table?
    {:uuid string?
     :name string?
     :abbrev string?
     :note string?
     :projects projects-appraiser}))

(def clients-appraiser
  (appraiser table? {keys string? values client-appraiser}))

(def root-appraiser
  (appraiser table? {:clients clients-appraiser}))

(def index-appraiser
  (appraiser table? {keys string? values tuple?}))

(def neil-db
  table?
  {:root root-appraiser
   :index index-appraiser})

With given schema you can validate:

(work-interval-appraiser @{:end 1233123123123
                           :start 1233123123123
                           :note "Good"})
#> true
(work-interval-appraiser @{:end 1233123123123
                           :start 1233123123123})
#> true

In case of invalid object, you can get validation errors:

((analyst
    table?
    {:start number?
     :end number?
     :note [some nil? present?]})
     @{:start 1233123123123
       :note "Good"})
#> @{:end <function number?>}

#State

It is working, but there will be definitely API and other changes.