import { defineComponent, withApiName, detachedManifestScope, type ComponentDefinition } from './component'; import { CustomField, type CustomFieldProps } from '../custom-field'; import type { DefinedCustomFieldSection } from './custom-field-section'; export type DefineCustomFieldProps = WithoutLegacyCustomFieldIdentity< CustomFieldProps > & { modelName: string; section: DefinedCustomFieldSection> }; export function defineCustomField( props: DefineCustomFieldProps, ): CustomField { return customFieldComponent.register( withApiName( new CustomField(detachedManifestScope, { ...props, ...(props.rqlDefinitionFormula == null ? { collectDuring: props.collectDuring ?? 'NONE' } : {}), fieldId: props.apiName, } as unknown as CustomFieldProps), props.apiName, { model_name: props.modelName }, ), props, ); } type WithoutLegacyCustomFieldIdentity = T extends unknown ? Omit : never; const customFieldComponent: ComponentDefinition = defineComponent({ type: 'CUSTOM_FIELD_V2', define: defineCustomField, references: (_definition, props) => [props.section], });