import { type Any, type ClassInstance, getClass } from '@travetto/runtime'; import type { SchemaFieldConfig } from '../service/types.ts'; import { SchemaRegistryIndex } from '../service/registry-index.ts'; type PropType = (>, K extends string>( instance: T, property: K, idx?: TypedPropertyDescriptor | number ) => void); function field(...configs: Partial[]): PropType { return (instance: ClassInstance, property: string): void => { SchemaRegistryIndex.getForRegister(getClass(instance)).registerField(property, ...configs); }; } /** * Registering a field * @param type The type for the field * @param configs The field configuration * @augments `@travetto/schema:Input` * @augments `@travetto/schema:Field` * @kind decorator */ export function Field(type?: Pick, ...configs: Partial[]): PropType { return field(type!, ...configs); } /** * Mark a field as writeonly * @augments `@travetto/schema:Input` * @kind decorator */ export function Writeonly(): PropType { return field({ access: 'writeonly' }); } /** * Mark a field as readonly * @augments `@travetto/schema:Input` * @kind decorator */ export function Readonly(): PropType { return field({ access: 'readonly' }); } /** * Mark a field as sensitive * @param active This determines if this field is sensitive or not. * @augments `@travetto/schema:Input` * @kind decorator */ export function Secret(active = true): PropType { return field({ secret: active }); }