Skip to content

defineGlobal

defineGlobal<TFieldMeta, TGlobalMeta, TGlobalSlug, TFields, TComponent, TDrafts>(config): GlobalConfig<TFieldMeta, TGlobalMeta, TGlobalSlug, TFields, TComponent, TDrafts>

Defined in: packages/core/src/globals/config.ts:52

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).

TFields extends Record<string, AdminField<TFieldMeta>> = Record<string, AdminField<TFieldMeta>>

TComponent extends ComponentHKT = ComponentHKT

Framework HKT binding.

TDrafts extends boolean = false

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

The raw global configuration.

GlobalConfig<TFieldMeta, TGlobalMeta, TGlobalSlug, TFields, TComponent, TDrafts>

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