Fix beta example
Fix analyst docstring position
Data can be empty
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.
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?>}
It is working, but there will be definitely API and other changes.