Entity / foldkit-entity
Attaching metadata
An interpreter declares a foldkit-metadata key and
attaches entries to the entity or to members. Entity core never reads them.
ts
import { Metadata } from 'foldkit-metadata'
const Labels = Metadata.key<string>('my-admin/labels', {
merge: labels => [...new Set(labels)],
summarize: label => label,
})
const CmsPost = Blog.Post.pipe(
Entity.annotate(Labels.of('Post')),
Entity.annotateMembers({ title: Labels.of('Title'), author: Labels.of('Byline') }),
)
Labels.get(CmsPost.fields.title.metadata) // ['Title']
Entity.same(CmsPost, Blog.Post) // true: the metadata changed, the entity did notAnnotating again combines with what is there, using the key's own merge.
A schema's own words
A label or a help text written on a schema (annotate({ title, description }))
is read with Words.of(schema), which gives each as an Option. Under Effect 4 a
schema with checks resolves to its last check's annotations, which say what
the check expects and carry no title, so
Schema.String.annotate({ title: 'Name' }).check(Schema.isMinLength(1)) resolved
directly has no title. Words.of falls back to the schema's own annotations. A
form's labels, Crud's columns and the page Builder's inspector read words
through it.
ts
import { Schema } from 'effect'
import { Words } from 'foldkit-entity'
Words.of(Schema.String.annotate({ title: 'Name' }).check(Schema.isMinLength(1))).title
// Option.some('Name')