/** * Field Modifier Type Alignment * * Issue: db4-8bur.5, db4-ston.2 * * Provides unified handling of field modifiers between @db4/core and @icetype/core. * * ## Canonical Forms * * ### @db4/core Canonical Form * ```typescript * type DB4FieldModifier = '!' | '?' | '#' | '[]' | null; * ``` * - `'!'` - Required field * - `'?'` - Optional field * - `'#'` - Indexed field * - `'[]'` - Array type modifier * - `null` - No modifier (canonical "empty" representation) * * ### @icetype/core Canonical Form * ```typescript * type FieldModifier = '!' | '#' | '?' | ''; * ``` * - `'!'` - Required field * - `'?'` - Optional field * - `'#'` - Indexed/unique field * - `''` - No modifier (empty string representation) * * Note: In @icetype/core, arrays are handled via a separate `isArray: boolean` * flag on FieldDefinition, not as a modifier. * * ## Key Differences * * | Concept | @db4/core | @icetype/core | * |----------------|-----------|---------------| * | No modifier | `null` | `''` | * | Array | `'[]'` | `isArray` flag| * | Required | `'!'` | `'!'` | * | Optional | `'?'` | `'?'` | * | Indexed/Unique | `'#'` | `'#'` | * * ## Conversion Guidelines * * - Use `toDb4FieldModifier()` when converting from @icetype/core to @db4/core * - Use `toIceTypeFieldModifier()` when converting from @db4/core to @icetype/core * - Use `normalizeFieldModifier()` to canonicalize any modifier to @db4/core format * - Use `isNoModifier()` to check if a value represents "no modifier" in either format * - Use `modifiersEqual()` to compare modifiers across formats * * ## Array Handling Note * * The `[]` modifier in @db4/core has no direct equivalent in @icetype/core because * arrays are represented via a separate `isArray: boolean` flag on FieldDefinition. * * When converting: * - DB4 `'[]'` -> IceType `''` (with separate `isArray: true` flag) * - IceType `{ modifier: '', isArray: true }` -> DB4 requires tracking array status separately * * This means the roundtrip for `[]` is lossy unless the `isArray` flag is tracked: * ```typescript * // DB4 -> IceType -> DB4 roundtrip for arrays * toIceTypeFieldModifier('[]') // returns '' * toDb4FieldModifier('') // returns null (array info lost without isArray flag) * ``` * * @packageDocumentation */ /** * Field modifier type used by @db4/core. * * - '!' marks a field as required * - '?' marks a field as optional * - '#' marks a field as indexed * - '[]' marks a field as an array * - null indicates no modifier */ export type DB4FieldModifier = '!' | '?' | '#' | '[]' | null; /** * Field modifier type used by @icetype/core. * * - '!' marks a field as required * - '?' marks a field as optional * - '#' marks a field as indexed * - '' indicates no modifier (empty string) * * Note: Arrays are handled via a separate `isArray` flag in IceType, * not as a modifier. */ export type IceTypeFieldModifier = '!' | '?' | '#' | ''; /** * Unified field modifier type that encompasses both formats. * Use this type when you need to accept either format. */ export type UnifiedFieldModifier = '!' | '?' | '#' | '[]' | '' | null; /** * The canonical "no modifier" representation. * We use null as the canonical form internally. */ export type NoModifier = null; /** * All valid modifier symbols (excluding null and empty string). * Useful for validation and parsing. */ export declare const FIELD_MODIFIER_SYMBOLS: readonly ["!", "?", "#", "[]"]; /** * Type for modifier symbols (string modifiers only, no null/empty). */ export type FieldModifierSymbol = (typeof FIELD_MODIFIER_SYMBOLS)[number]; /** * Checks if a value represents "no modifier". * * Both null (db4) and '' (icetype) represent the absence of a modifier. * undefined is also treated as no modifier for convenience. * * @param value - The value to check * @returns true if the value represents no modifier */ export declare function isNoModifier(value: unknown): value is null | '' | undefined; /** * Type guard for checking if a value is a valid modifier symbol. * * @param value - The value to check * @returns true if the value is a valid modifier symbol */ export declare function isModifierSymbol(value: unknown): value is FieldModifierSymbol; /** * Type guard for DB4FieldModifier type. * * @param value - The value to check * @returns true if the value is a valid DB4FieldModifier */ export declare function isDB4FieldModifier(value: unknown): value is DB4FieldModifier; /** * Type guard for IceTypeFieldModifier type. * * @param value - The value to check * @returns true if the value is a valid IceTypeFieldModifier */ export declare function isIceTypeFieldModifier(value: unknown): value is IceTypeFieldModifier; /** * Type guard for UnifiedFieldModifier type. * * @param value - The value to check * @returns true if the value is a valid UnifiedFieldModifier */ export declare function isUnifiedFieldModifier(value: unknown): value is UnifiedFieldModifier; /** * Normalizes a field modifier to the canonical @db4/core format. * * This function converts: * - '' (empty string) -> null * - undefined -> null * - All other modifiers are preserved * * @param modifier - The modifier to normalize * @returns The normalized modifier in @db4/core format */ export declare function normalizeFieldModifier(modifier: UnifiedFieldModifier | undefined): DB4FieldModifier; /** * Converts an IceType field modifier to DB4 format. * * Conversion rules: * - '' (empty string) -> null * - '!', '?', '#' -> preserved * * @param modifier - The IceType modifier to convert * @returns The equivalent DB4 modifier */ export declare function toDb4FieldModifier(modifier: IceTypeFieldModifier): DB4FieldModifier; /** * Converts a DB4 field modifier to IceType format. * * Conversion rules: * - null -> '' (empty string) * - '[]' -> '' (arrays are handled via isArray flag in IceType) * - '!', '?', '#' -> preserved * * @param modifier - The DB4 modifier to convert * @returns The equivalent IceType modifier */ export declare function toIceTypeFieldModifier(modifier: DB4FieldModifier): IceTypeFieldModifier; /** * Result of parsing a type string for its modifier. */ export interface ParsedFieldModifier { /** The base type without the modifier */ baseType: string; /** The extracted modifier (null if none) */ modifier: DB4FieldModifier; } /** * Parses a type string to extract the base type and modifier. * * Examples: * - 'string!' -> { baseType: 'string', modifier: '!' } * - 'int?' -> { baseType: 'int', modifier: '?' } * - 'string#' -> { baseType: 'string', modifier: '#' } * - 'string[]' -> { baseType: 'string', modifier: '[]' } * - 'uuid' -> { baseType: 'uuid', modifier: null } * - 'string[]!' -> { baseType: 'string[]', modifier: '!' } * * @param typeString - The type string to parse * @returns The parsed base type and modifier */ export declare function parseFieldModifier(typeString: string): ParsedFieldModifier; /** * Appends a modifier to a base type string. * * @param baseType - The base type string * @param modifier - The modifier to append * @returns The type string with modifier appended */ export declare function appendModifier(baseType: string, modifier: DB4FieldModifier): string; /** * Compares two field modifiers for equality, treating null and '' as equivalent. * * @param a - First modifier * @param b - Second modifier * @returns true if the modifiers are equivalent */ export declare function modifiersEqual(a: UnifiedFieldModifier | undefined, b: UnifiedFieldModifier | undefined): boolean; /** * Returns a human-readable description of a modifier. * * @param modifier - The modifier to describe * @returns A description string */ export declare function describeModifier(modifier: UnifiedFieldModifier | undefined): string; //# sourceMappingURL=field-modifier.d.ts.map