Metadata for schemas, kept beside them in a registry so a schema stays the
three-field object it is and a bundle that attaches none pays nothing.
meta returns a copy of a schema with metadata attached, and get_meta
reads it back. The metadata belongs to that one object:
- flavor and brand return the object they were given, so its metadata
is still there.
- message builds a new schema and carries the metadata over to it, the
same object, so it is found on either.
- Every wrapper and container builds a new schema, which has none. A
wrapper holds the schema it was given under
def.schema, so metadata
on a wrapped schema is found by walking to it.
SchemaMeta has description built in and takes other keys by
declaration merging.
The registry is one for the whole JS realm, on globalThis under
Symbol.for('@fuzdev/fuz_schema/meta'), so every copy of this module
shares it: a second install of the package, a bundler's duplicate, another
version that keeps it there. Metadata attached through one copy is read through any other.
That makes the registry's shape a contract between versions: a WeakMap
from schema object to its metadata object, which meta replaces with a
merged copy and never mutates. A version that changes it takes a new key.
message in schema.ts reads and writes it by the same key.
Import as a namespace or by name:
import {meta, get_meta} from '@fuzdev/fuz_schema/meta.ts'.