/** * Relationship Operator Parsing * * Provides parseOperator() for extracting relationship semantics from field definitions. * * @packageDocumentation */ import type { ParsedRelationship, RelationshipOperator } from './types.js'; /** * Relationship operator semantics * * | Operator | Direction | Match Mode | Use Case | * |----------|-----------|------------|----------| * | `->` | forward | exact | Foreign key reference | * | `~>` | forward | fuzzy | AI-matched semantic reference | * | `<-` | backward | exact | Backlink/parent reference | * | `<~` | backward | fuzzy | AI-matched backlink | */ export declare const OPERATOR_SEMANTICS: Record; /** * All supported relationship operators (in order of specificity for parsing) */ export declare const OPERATORS: readonly RelationshipOperator[]; /** * Parse relationship operator from field definition * * Extracts operator semantics from a field definition string. Supports * four relationship operators with different semantics. * * ## Supported Formats * * - `'->Type'` - Forward exact reference to Type * - `'~>Type'` - Forward fuzzy (semantic search) to Type * - `'<-Type'` - Backward exact reference from Type * - `'<~Type'` - Backward fuzzy reference from Type * - `'Prompt text ->Type'` - With generation prompt (text before operator) * - `'->TypeA|TypeB'` - Union types (polymorphic reference) * - `'->Type.backref'` - With explicit backref field name * - `'->Type?'` - Optional reference * - `'->Type[]'` - Array of references * - `'~>Type(0.8)'` - Fuzzy with threshold * - `'->Type!'` - Required/unique reference * - `'->Type#'` - Indexed reference * * ## Field Modifiers * * Modifiers can be combined in any order at the end of the type: * - `?` - Optional (field may be null/undefined) * - `[]` - Array (field contains multiple values) * - `!` - Required/Unique (field must have a value and be unique) * - `#` - Indexed (field should be indexed for fast lookup) * * @param definition - The field definition string to parse * @returns Parsed relationship, or null if no operator found * * @example Basic usage * ```ts * parseOperator('->Author') * // => { operator: '->', direction: 'forward', matchMode: 'exact', targetType: 'Author' } * * parseOperator('~>Category') * // => { operator: '~>', direction: 'forward', matchMode: 'fuzzy', targetType: 'Category' } * * parseOperator('<-Post') * // => { operator: '<-', direction: 'backward', matchMode: 'exact', targetType: 'Post' } * ``` * * @example With prompt * ```ts * parseOperator('What is the main category? ~>Category') * // => { * // prompt: 'What is the main category?', * // operator: '~>', * // direction: 'forward', * // matchMode: 'fuzzy', * // targetType: 'Category' * // } * ``` * * @example Union types * ```ts * parseOperator('->Person|Company|Organization') * // => { * // operator: '->', * // direction: 'forward', * // matchMode: 'exact', * // targetType: 'Person', * // unionTypes: ['Person', 'Company', 'Organization'] * // } * ``` * * @example With backref * ```ts * parseOperator('->User.posts') * // => { * // operator: '->', * // direction: 'forward', * // matchMode: 'exact', * // targetType: 'User', * // backref: 'posts' * // } * ``` * * @example With threshold * ```ts * parseOperator('~>Category(0.8)') * // => { * // operator: '~>', * // direction: 'forward', * // matchMode: 'fuzzy', * // targetType: 'Category', * // threshold: 0.8 * // } * ``` * * @example With modifiers * ```ts * parseOperator('->User!#') * // => { * // operator: '->', * // direction: 'forward', * // matchMode: 'exact', * // targetType: 'User', * // isRequired: true, * // isUnique: true, * // isIndexed: true * // } * ``` */ export declare function parseOperator(definition: string): ParsedRelationship | null; /** * Check if a string contains a relationship operator */ export declare function hasOperator(definition: string): boolean; /** * Get the operator from a definition, if present */ export declare function getOperator(definition: string): RelationshipOperator | null; /** * Check if an operator is forward-direction */ export declare function isForwardOperator(op: RelationshipOperator): boolean; /** * Check if an operator is backward-direction */ export declare function isBackwardOperator(op: RelationshipOperator): boolean; /** * Check if an operator is fuzzy-match */ export declare function isFuzzyOperator(op: RelationshipOperator): boolean; /** * Check if an operator is exact-match */ export declare function isExactOperator(op: RelationshipOperator): boolean; //# sourceMappingURL=relationship.d.ts.map