UNPKG

legal-markdown-js

Version:

Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version

160 lines 4.88 kB
/** * Core Field State Management for Legal Markdown Processing * * This module provides the fundamental field tracking interfaces and basic implementation * that form the foundation for field tracking throughout the Legal Markdown processing * pipeline. It defines the core contracts for tracking field usage, status, and metadata. * * Features: * - Basic field state interface compatible with existing field-tracker * - Core field tracking functionality * - Portable implementation suitable for any Legal Markdown implementation * - Foundation for extended field tracking in extensions * - Backward compatibility with existing field tracking systems * * @example * ```typescript * import { CoreFieldState, FieldTrackingOptions } from './field-state.js'; * * const fieldState = new CoreFieldState(); * fieldState.trackField('client.name', { * value: 'Acme Corporation', * hasLogic: false * }); * * const fields = fieldState.getFields(); * console.log(`Tracked ${fields.size} fields`); * ``` */ /** * Enumeration of possible field statuses during processing * * @example * ```typescript * import { FieldStatus } from './field-state.js'; * * // Check field status * if (field.status === FieldStatus.FILLED) { * console.log('Field has a value'); * } else if (field.status === FieldStatus.EMPTY) { * console.log('Field needs a value'); * } else if (field.status === FieldStatus.LOGIC) { * console.log('Field uses conditional logic'); * } * ``` */ export var FieldStatus; (function (FieldStatus) { /** Field has been filled with a value */ FieldStatus["FILLED"] = "filled"; /** Field is empty or missing a value */ FieldStatus["EMPTY"] = "empty"; /** Field contains logic or uses mixins */ FieldStatus["LOGIC"] = "logic"; /** Field is declared in YAML but never referenced in the template */ FieldStatus["DECLARED"] = "declared"; })(FieldStatus || (FieldStatus = {})); /** * Core implementation of field state management * * This class provides a basic, portable implementation of field tracking * that can be used as a foundation for more advanced field tracking systems. * * @class CoreFieldState * @example * ```typescript * const fieldState = new CoreFieldState(); * * // Track field processing * fieldState.trackField('client.name', { * value: 'Acme Corp', * originalValue: '{{client.name}}', * hasLogic: false * }); * * // Get tracking report * const fields = fieldState.getFields(); * const emptyFields = fieldState.getFieldsByStatus(FieldStatus.EMPTY); * ``` */ export class CoreFieldState { _fields = new Map(); /** * Get the internal fields map (read-only access) */ get fields() { return this._fields; } /** * Track a field that has been processed * * @param name - The name/identifier of the field to track * @param options - Options for field tracking */ trackField(name, options) { const { value, originalValue, hasLogic = false, mixinUsed } = options; let status; if (hasLogic || mixinUsed) { status = FieldStatus.LOGIC; } else if (value === undefined || value === null || value === '') { status = FieldStatus.EMPTY; } else { status = FieldStatus.FILLED; } const field = { name, status, value, originalValue, hasLogic, mixinUsed, }; this._fields.set(name, field); } /** * Get all tracked fields * * @returns A copy of the tracked fields map */ getFields() { return new Map(this._fields); } /** * Get fields filtered by status * * @param status - The status to filter by * @returns Array of fields with the specified status */ getFieldsByStatus(status) { return Array.from(this._fields.values()).filter(field => field.status === status); } /** * Clear all tracked fields */ clear() { this._fields.clear(); } /** * Generate a summary report of tracked fields * * @returns Summary statistics of field tracking * @example * ```typescript * const report = fieldState.generateReport(); * console.log(`Total: ${report.total}, Filled: ${report.filled}, Empty: ${report.empty}`); * ``` */ generateReport() { const fields = Array.from(this._fields.values()); return { total: fields.length, filled: fields.filter(f => f.status === FieldStatus.FILLED).length, empty: fields.filter(f => f.status === FieldStatus.EMPTY).length, logic: fields.filter(f => f.status === FieldStatus.LOGIC).length, fields, }; } } //# sourceMappingURL=field-state.js.map