/** * Progressive rule builder. * * This module provides the main builder class for creating Progressive DSL policies. */ import type { DSLRule, DSLPolicy, IntentExpression, PatternTemplate, TransformOptions, DimensionalRule } from '../dsl-types'; import type { ReleaseType } from '../../types'; import { DimensionalRuleBuilder, type ProgressiveRuleBuilderInterface } from './dimensional-builder'; /** * Progressive rule builder supporting all three DSL levels. * * The main entry point for building Progressive DSL policies. Supports mixing * rules at all three levels (intent, pattern, dimensional) with fluent API. * * ## Real-World Policy Examples * * ### Strict Library Policy * For stable libraries where any breaking change should be carefully considered: * * ```typescript * const strictLibraryPolicy = createProgressivePolicy() * .intent('export removal is breaking', 'major') * .intent('member removal is breaking', 'major') * .intent('type narrowing is breaking', 'major') * .intent('required addition is breaking', 'major') * .intent('optional addition is safe', 'none') * .intent('deprecation is patch', 'patch') * .build('strict-library', 'major') * ``` * * ### Agile Development Policy * For rapidly evolving APIs where some changes are acceptable in minor versions: * * ```typescript * const agilePolicy = createProgressivePolicy() * .intent('export removal is breaking', 'major') * .pattern('renamed {target}', { target: 'property' }, 'minor') * .intent('type widening is safe', 'minor') * .intent('deprecation is patch', 'patch') * .dimensional('internal-changes') * .hasTag('internal') * .returns('patch') * .build('agile-development', 'patch') * ``` * * @see {@link createProgressivePolicy} - Factory function to create a new builder * @see {@link createStandardPolicy} - Factory for pre-configured common policies * * @alpha */ export declare class ProgressiveRuleBuilder implements ProgressiveRuleBuilderInterface { private rules; private pendingDimensionalRules; /** * Add a rule using natural language intent. * * Intent rules are the highest-level, most readable way to express change rules. * They use natural language expressions that capture semantic meaning directly. * * @param expression - Natural language expression (e.g., 'export removal is breaking') * @param returns - Release type for this rule ('major', 'minor', 'patch', 'none') * @param description - Optional human-readable description * @returns This builder for chaining * * @example * ```typescript * builder * .intent('export removal is breaking', 'major', 'Public API removal') * .intent('optional addition is safe', 'none') * .intent('deprecation is patch', 'patch') * ``` */ intent(expression: IntentExpression, returns: ReleaseType, description?: string): this; /** * Add a rule using pattern template. * * Pattern rules use `\{placeholder\}` syntax for variable substitution, offering * more flexibility than intent expressions while remaining readable. * * @param template - Pattern template with placeholders (e.g., `'removed \{target\}'`) * @param variables - Object mapping placeholder names to values * @param returns - Release type for this rule ('major', 'minor', 'patch', 'none') * @param description - Optional human-readable description * @returns This builder for chaining * * @example Basic patterns * ```typescript * builder * .pattern('removed {target}', { target: 'export' }, 'major') * .pattern('added optional {target}', { target: 'parameter' }, 'none') * .pattern('{target} type narrowed', { target: 'return-type' }, 'major') * ``` * * @example Conditional patterns * ```typescript * builder.pattern('removed {target} when {condition}', { * target: 'property', * condition: 'not inherited' * }, 'major') * ``` * * @example Node-specific patterns * ```typescript * builder.pattern('{pattern} for {nodeKind}', { * pattern: 'modified', * nodeKind: 'interface' * }, 'major') * ``` */ pattern(template: PatternTemplate, variables: Record, returns: ReleaseType, description?: string): this; /** * Start building a dimensional rule with the fluent API. * * Dimensional rules provide the most precise control by directly specifying * multi-dimensional change characteristics. Use this when you need: * - Maximum precision for complex rules * - Legacy compatibility with RuleBuilder-based policies * - Rules with multiple intersecting dimensions * * @param name - Rule name (used as description) * @returns A DimensionalRuleBuilder for specifying dimensions * * @example * ```typescript * builder * .dimensional('complex-rule') * .action('modified') * .target('export') * .aspect('type') * .impact('narrowing') * .returns('major') * ``` * * @example With tags and nested flag * ```typescript * builder * .dimensional('internal-api-changes') * .hasTag('internal') * .nested(true) * .returns('patch') * ``` */ dimensional(name: string): DimensionalRuleBuilder; /** * Internal method to add a dimensional rule (called by proxy) */ addDimensionalRule(rule: DimensionalRule): void; /** * Transform existing rules to a different DSL level. * * This enables converting rules between the three abstraction levels: * - `'intent'` - Natural language expressions (highest level) * - `'pattern'` - Template-based rules (middle level) * - `'dimensional'` - Multi-dimensional specifications (lowest level) * * **Note:** Transforming to higher levels (dimensional \> pattern \> intent) may * result in some information loss, as higher levels are less expressive. * * @param options - Transformation options including target level * @returns This builder for chaining * * @example * ```typescript * // Transform all rules to dimensional representation * builder.transform({ targetLevel: 'dimensional' }) * * // Transform to pattern level for better readability * builder.transform({ * targetLevel: 'pattern', * preserveMetadata: true, * validate: true * }) * ``` */ transform(options: TransformOptions): this; /** * Build the final policy from all configured rules. * * This method finalizes the builder, processing all rules and creating * a complete DSLPolicy that can be used for change classification. * * @param name - Unique name identifying this policy * @param defaultReleaseType - Release type to use when no rule matches * @param description - Optional human-readable description * @returns The finalized DSLPolicy * * @example * ```typescript * const policy = builder.build('my-policy', 'patch', 'My API policy') * ``` * * @example Conservative default (unmatched changes are breaking) * ```typescript * const strictPolicy = builder.build('strict-library', 'major') * ``` */ build(name: string, defaultReleaseType: ReleaseType, description?: string): DSLPolicy; /** * Add a custom DSL rule directly. * * This is useful when you have a pre-constructed rule object, or when * programmatically generating rules. * * @param rule - The DSL rule to add (IntentRule, PatternRule, or DimensionalRule) * @returns This builder for chaining * * @example * ```typescript * builder.addRule({ * type: 'intent', * expression: 'breaking removal', * returns: 'major' * }) * ``` */ addRule(rule: DSLRule): this; /** * Get the current rules for inspection or debugging. * * @returns Read-only array of all configured rules * * @example * ```typescript * const rules = builder.getRules() * console.log(`Policy has ${rules.length} rules`) * ``` */ getRules(): ReadonlyArray; /** * Clear all rules from the builder. * * Useful when creating variations of a policy or resetting the builder. * * @returns This builder for chaining * * @example * ```typescript * builder.clear() * ``` */ clear(): this; /** * Clone the builder with all current rules. * * Useful for creating policy variations without modifying the original. * * @returns A new ProgressiveRuleBuilder with copies of all rules * * @example Multi-stage policy with variations * ```typescript * const basePolicy = createProgressivePolicy() * .intent('export removal is breaking', 'major') * .intent('deprecation is patch', 'patch') * * // Create stricter variation * const stricterPolicy = basePolicy.clone() * .intent('rename is breaking', 'major') * .build('stricter-policy', 'major') * ``` */ clone(): ProgressiveRuleBuilder; } //# sourceMappingURL=progressive-builder.d.ts.map