/**
 * Read the per-process Actuate CMS config that `handleActuateAPI()` stashed
 * on `globalThis`. Returns `undefined` when no config has been registered
 * yet (e.g. during early test setup or when the API handler has never been
 * invoked).
 *
 * **Why a helper instead of reading `globalThis.__actuateConfig` directly?**
 * - Centralizes the unsafe cast so we never sprinkle `as any` across the
 *   codebase. If the storage strategy ever moves off `globalThis` (issue M8
 *   from the engineering audit), only this file changes.
 * - Gives every caller the same typed handle, which makes mocking in tests
 *   straightforward (set the global once, all readers see it).
 *
 * **Mutability warning:** the returned object is the *same reference* the
 * platform handler holds. Callers must not mutate it. For mutations (e.g.
 * a plugin registering a new collection at init time), use the platform's
 * own plugin lifecycle — not this getter.
 */
export function getActuateConfig() {
    return globalThis.__actuateConfig;
}
/**
 * One-time, boot-time sanity check for collection configs.
 *
 * `cms-core` reads `collection.fields` as an **object map** keyed by field name
 * (`getCollectionFields` → `applyFieldAccess` → `sanitizeDocumentData`). If a
 * consumer declares `fields` as an **array** (a natural mistake, and the shape
 * some docs/examples imply), `Object.entries()` yields numeric keys (`"0"`,
 * `"1"`, …) that never match real data keys, so every custom field is silently
 * stripped on write — the document saves but its body vanishes.
 *
 * That failure is invisible (no error, empty data), so we surface it loudly at
 * registration. We only warn (never throw): a misconfigured field map must not
 * take down the whole instance at boot.
 */
function warnOnArrayFields(config) {
    try {
        const collections = config
            .collections;
        if (!collections || typeof collections !== 'object')
            return;
        for (const [slug, def] of Object.entries(collections)) {
            if (Array.isArray(def?.fields)) {
                console.warn(`[actuate] Collection "${slug}" declares \`fields\` as an array. ` +
                    'cms-core expects an object map keyed by field name ' +
                    '(e.g. `fields: { title: { type: "text" } }`). ' +
                    'Array fields are ignored, so custom field values will be dropped on write. ' +
                    'Convert this collection to the object-map shape.');
            }
        }
    }
    catch {
        /* Config validation must never break boot; a bad shape is the caller's bug. */
    }
}
/**
 * Register the running config on `globalThis`. Only the platform-level API
 * handler should call this; plugins and feature code should read the config
 * via `getActuateConfig()` instead.
 */
export function setActuateConfig(config) {
    warnOnArrayFields(config);
    globalThis.__actuateConfig =
        config;
}
/**
 * Read the cms-core version that was stamped onto `globalThis` at handler
 * init. Used by `/api/cms/health` and the `/updates/check` endpoint.
 */
export function getActuateCoreVersion() {
    return globalThis.__actuateCoreVersion;
}
export function setActuateCoreVersion(version) {
    ;
    globalThis.__actuateCoreVersion = version;
}
//# sourceMappingURL=runtime.js.map