defineGlobal
defineGlobal<
TFieldMeta,TGlobalMeta,TGlobalSlug,TFieldSlug,TComponent>(config):GlobalConfig<TFieldMeta,TGlobalMeta,TGlobalSlug,TFieldSlug,TComponent>
Defined in: packages/core/src/globals/config.ts:44
Defines a singleton global document for the VexCMS project.
Flat API: globals.get({ slug: "siteSettings" }) returns a flat document
where user fields (siteName, activeTheme, …) are at root level alongside
_id, _creationTime, and _slug. The DB stores data nested in a data
field; the VexCMS API layer handles flattening on read and re-nesting on write.
Reserved field keys: _id, _creationTime, and _slug may not be used
as field names. A compile-time error is emitted on the offending field when
they are used. A runtime error is also thrown for JS consumers.
Type Parameters
Section titled “Type Parameters”TFieldMeta
Section titled “TFieldMeta”TFieldMeta extends object = { }
Metadata on each field definition.
TGlobalMeta
Section titled “TGlobalMeta”TGlobalMeta extends object = { }
Metadata on the global config itself.
TGlobalSlug
Section titled “TGlobalSlug”TGlobalSlug extends string = string
The slug string literal (inferred by TypeScript).
TFieldSlug
Section titled “TFieldSlug”TFieldSlug extends string = string
Union of field key string literals.
TComponent
Section titled “TComponent”TComponent extends ComponentHKT = ComponentHKT
Framework HKT binding.
Parameters
Section titled “Parameters”config
Section titled “config”string extends TFieldSlug ? GlobalConfigInput<TFieldMeta, TGlobalMeta, TGlobalSlug, TFieldSlug, TComponent> : [TFieldSlug & ReservedGlobalFieldKey] extends [never] ? GlobalConfigInput<TFieldMeta, TGlobalMeta, TGlobalSlug, TFieldSlug, TComponent> : object
The raw global configuration.
Returns
Section titled “Returns”GlobalConfig<TFieldMeta, TGlobalMeta, TGlobalSlug, TFieldSlug, TComponent>
The resolved GlobalConfig with all defaults applied.
Throws
Section titled “Throws”When config.fields contains one of the reserved keys
_id, _creationTime, or _slug.
Example
Section titled “Example”export const siteSettings = defineGlobal({ slug: "siteSettings", label: "Site Settings", fields: { siteName: text({ label: "Site Name", required: true }), activeTheme: relationship({ label: "Active Theme", collection: "themes" }), }, admin: { group: "Site Builder" },});- GlobalConfigInput for the user-facing input type
- GlobalConfig for the resolved return type