Skip to content

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.

TFieldMeta extends object = { }

Metadata on each field definition.

TGlobalMeta extends object = { }

Metadata on the global config itself.

TGlobalSlug extends string = string

The slug string literal (inferred by TypeScript).

TFieldSlug extends string = string

Union of field key string literals.

TComponent extends ComponentHKT = ComponentHKT

Framework HKT binding.

string extends TFieldSlug ? GlobalConfigInput<TFieldMeta, TGlobalMeta, TGlobalSlug, TFieldSlug, TComponent> : [TFieldSlug & ReservedGlobalFieldKey] extends [never] ? GlobalConfigInput<TFieldMeta, TGlobalMeta, TGlobalSlug, TFieldSlug, TComponent> : object

The raw global configuration.

GlobalConfig<TFieldMeta, TGlobalMeta, TGlobalSlug, TFieldSlug, TComponent>

The resolved GlobalConfig with all defaults applied.

When config.fields contains one of the reserved keys _id, _creationTime, or _slug.

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" },
});