/** * Compile-time contract between this application's collection schemas and its * generated collection-type projection. * * ```text * collections/index.ts generated/collection-types.ts * `typeof collections` `CollectionFields*ByPath` * | | * v v * inferred registry ----------- Exact -------- generated registry * | * v * TypeScript error on drift * ``` * * The generated file is deliberately a standalone projection for typed clients * and frontend code; it does not import the runtime schemas. This module joins * those two app-owned sources at compile time and requires their collection * keys, ordinary field shapes, and all-locale field shapes to match exactly. * * This file has no runtime behavior. Keep it application-owned: `@byline/core` * provides the inference and code-generation machinery, but only this * application knows its concrete collection tuple and generated output. */ import type { CollectionFieldData, CollectionFieldDataAllLocales } from '@byline/core' import type { collections } from './collections/index.js' import type { CollectionFieldsAllLocalesByPath, CollectionFieldsByPath, } from '@byline/generated-types' type InferredFieldsByPath = { [Definition in (typeof collections)[number] as Definition['path']]: CollectionFieldData } type InferredFieldsAllLocalesByPath = { [Definition in (typeof collections)[number] as Definition['path']]: CollectionFieldDataAllLocales } type IsAny = 0 extends 1 & Value ? true : false type Exact = IsAny extends true ? IsAny : IsAny extends true ? false : (() => Value extends Left ? 1 : 2) extends () => Value extends Right ? 1 : 2 ? (() => Value extends Right ? 1 : 2) extends () => Value extends Left ? 1 : 2 ? true : false : false type Assert = Value type GeneratedKeysMatchRuntimeRegistry = Assert< Exact > type GeneratedFieldsMatchRuntimeRegistry = Assert< Exact > type GeneratedAllLocalesKeysMatchRuntimeRegistry = Assert< Exact > type GeneratedAllLocalesFieldsMatchRuntimeRegistry = Assert< Exact >