import { defineComponent, withApiName, detachedManifestScope, type ComponentDefinition } from './component'; import { CustomFieldSection, type CustomFieldSectionProps } from '../custom-field-section'; export type DefinedCustomFieldSection = CustomFieldSection & { readonly [modelScope]: TModel; }; export type DefineCustomFieldSectionProps = Omit< CustomFieldSectionProps, 'sectionId' | 'apiName' | 'modelRqlName' > & { apiName: `${string}__cfs`; modelName: string; modelRqlName: TModel; }; export function defineCustomFieldSection( props: DefineCustomFieldSectionProps, ): DefinedCustomFieldSection { if (!/^[A-Za-z][A-Za-z0-9_]*__cfs$/.test(props.apiName)) throw new Error( `Native field section apiName must start with a letter, contain only letters, digits or underscores, and end with __cfs: ${props.apiName}`, ); return customFieldSectionComponent.register( withApiName( new CustomFieldSection(detachedManifestScope, { ...props, sectionId: props.apiName }), props.apiName, { model_name: props.modelName }, ) as unknown as DefinedCustomFieldSection, props, ); } declare const modelScope: unique symbol; const customFieldSectionComponent: ComponentDefinition = defineComponent({ type: 'CUSTOM_FIELD_SECTION', define: defineCustomFieldSection, });