host: relations-as-posts slice 5 — refinement types (schemas on the type-post)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
A type-post carries its schema in a :schema slot (a list of {:block :msg} rules — a
refinement {x : T | x has these blocks}). host/blog-schema-of reads it off the post;
the hardcoded host/blog-type-schemas table is gone. A NEW refinement type is pure
data: give a type-post a :schema and its instances are validated on save — no code
(tested with a 'guide' type requiring a 'pre' block). article's schema is migrated
onto the article post at boot (host/blog--set-schema!, a single read+write).
host/blog-put! now MERGES over the previous record, so editing a post's
title/content doesn't nuke its :schema/:rel metadata (also closes the Slice 2
'edit drops :rel' gap). schema-of reads the post (a durable read) — only the SAVE
path calls it (a write request, never a render that would VmSuspend).
conformance 299/299 (+4: article h1 enforced from the post, a new refinement type
validates its instances, schema read off the post, edit preserves :schema).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -550,6 +550,32 @@
|
||||
(host-bl-test "nested type expression: (tag ∧ article) ∧ tag still admits ocaml"
|
||||
(host/blog-is-a-expr? "ocaml" "nested-and") true)
|
||||
|
||||
;; -- Slice 5: refinement types — schemas live ON the type-post --
|
||||
;; article's schema (now on the article post) is still enforced for its instances.
|
||||
(host/blog-put! "art-test" "Art Test" "(p \"x\")" "published")
|
||||
(host/blog-relate! "art-test" "article" "is-a")
|
||||
(host-bl-test "article (refinement type, schema on the post) requires an h1"
|
||||
(list (host/blog-type-valid? "art-test" "(p \"no heading\")") ;; missing h1
|
||||
(host/blog-type-valid? "art-test" "(article (h1 \"H\") (p \"x\"))")) ;; has h1
|
||||
(list false true))
|
||||
;; a NEW refinement type is pure data: give a type-post a :schema and its instances
|
||||
;; are validated against it — no code, no hardcoded table.
|
||||
(host/blog-seed! "guide" "Guide" "(article (h1 \"Guide\") (p \"A guide.\"))" "published")
|
||||
(host/blog-relate! "guide" "type" "subtype-of")
|
||||
(host/blog--set-schema! "guide" (list {:block "pre" :msg "a guide needs a code block (pre)"}))
|
||||
(host/blog-put! "g1" "G1" "(p \"x\")" "published")
|
||||
(host/blog-relate! "g1" "guide" "is-a")
|
||||
(host-bl-test "a NEW refinement type validates its instances against its :schema"
|
||||
(list (host/blog-type-valid? "g1" "(p \"no code\")") ;; missing pre
|
||||
(host/blog-type-valid? "g1" "(article (pre \"x\") (p \"y\"))")) ;; has pre
|
||||
(list false true))
|
||||
(host-bl-test "the schema is read off the type-post (data, not a hardcoded table)"
|
||||
(contains? (str (host/blog-schema-of "guide")) "code block") true)
|
||||
;; editing a refinement type preserves its :schema (put! merges over the record).
|
||||
(host/blog-put! "guide" "Guide v2" "(article (h1 \"Guide\") (p \"edited\"))" "published")
|
||||
(host-bl-test "editing a type-post preserves its :schema (and metadata survives edits)"
|
||||
(contains? (str (host/blog-schema-of "guide")) "code block") true)
|
||||
|
||||
;; -- Phase 3: tags as posts -- (ocaml is-a tag, from the seed-types test above)
|
||||
(host-bl-test "is-tag?: a post that is-a tag is a tag; others are not"
|
||||
(list (host/blog-is-tag? "ocaml") (host/blog-is-tag? "ppost"))
|
||||
|
||||
Reference in New Issue
Block a user