react-monaco-json-merge
Version:
A powerful React component for 3-way JSON merging with semantic comparison, built on Monaco Editor. Features schema-aware conflict detection, interactive resolution, and real-time validation.
99 lines • 4.33 kB
TypeScript
import { type Operation as JsonPatchOperation } from "fast-json-patch";
import type { JSONSchema } from "../types";
import { ConflictType, type ModifiedBaseRange } from "../types";
/**
* Represents a conflict analysis result for a JSON path
*/
export interface ConflictAnalysis {
path: string;
baseValue: unknown;
input1Value: unknown;
input2Value: unknown;
conflictType: ConflictType;
patches1?: JsonPatchOperation[];
patches2?: JsonPatchOperation[];
}
/**
* Format JSON with sorted keys (objects only, arrays unchanged)
* @param json - JSON object to format
* @returns Formatted JSON string with 2-space indentation
*/
export declare function formatJsonForComparison(json: unknown): string;
/**
* Determine conflict type based on semantic comparison of values
* @param base - Base value
* @param input1 - Input1 (theirs) value
* @param input2 - Input2 (ours) value
* @returns Conflict type
*/
export declare function determineConflictType(base: unknown, input1: unknown, input2: unknown): ConflictType;
/**
* Get line numbers for a JSON node at a given path
* @param text - Formatted JSON text
* @param path - JSON Pointer path
* @returns Start and end line numbers (1-indexed), or {1, 1} if not found
*/
export declare function getNodeLines(text: string, path: string): {
start: number;
end: number;
};
/**
* Analyze conflicts using JSON Patches (RFC 6902)
*
* This function uses semantic JSON comparison, NOT line-based text comparison:
* 1. Generates JSON Patch operations from base?input1 and base?input2
* 2. Groups patches by root path (e.g., /awards/resource/0/count ? /awards)
* 3. For each group, determines conflict type based on actual JSON values
* 4. Returns conflicts with patch operations that will be mapped to line ranges
*
* The patches contain JSON Pointer paths (e.g., /resource/0/type) that reference
* the actual JSON structure, not arbitrary text lines.
*
* @param base - Base JSON object
* @param input1 - Input1 (theirs) JSON object
* @param input2 - Input2 (ours) JSON object
* @returns Array of conflict analyses with JSON Patch operations
*/
/**
* Resolve schema at a given JSON Pointer path, handling oneOf/anyOf/allOf
* @param schema - Root JSON Schema
* @param path - JSON Pointer path (e.g., "/awards/resource/0/type")
* @param data - The actual data at the path (for oneOf/anyOf resolution)
* @returns The resolved schema for the path, or null if not found
*/
export declare function getSchemaAtPath(schema: JSONSchema | undefined, path: string, data?: unknown): JSONSchema | null;
export declare function analyzeConflicts(base: unknown, input1: unknown, input2: unknown, schema?: JSONSchema): ConflictAnalysis[];
/**
* Analyze conflicts for 2-column mode (input1 vs input2, no base)
*
* Uses JSON Patch comparison (semantic, not line-based):
* - Generates patches from input1?input2
* - Groups by root path
* - Maps to conflict ranges
*
* @param input1 - Input1 JSON object (left column)
* @param input2 - Input2 JSON object (right column)
* @returns Array of conflict analyses with JSON Patch operations
*/
export declare function analyzeTwoWayConflicts(input1: unknown, input2: unknown, schema?: JSONSchema): ConflictAnalysis[];
export declare function mapConflictsToRanges(conflicts: ConflictAnalysis[], baseText: string, input1Text: string, input2Text: string): ModifiedBaseRange[];
/**
* Compute diffs using JSON Patch approach
* @param baseText - Base version (JSON string, can be empty if no base)
* @param input1Text - Input1 version (JSON string)
* @param input2Text - Input2 version (JSON string)
* @param options - Optional configuration
* @param options.comparisonMode - How to compare: "split" or "sequential" (default: "split")
* @param options.schema - Optional JSON Schema for schema-aware comparison
* @param options.patches - Optional pre-computed patches (use instead of computing)
* @returns Array of ModifiedBaseRange objects
*/
export declare function computeDiffsJsonPatch(baseText: string, input1Text: string, input2Text: string, options?: {
comparisonMode?: "split" | "sequential";
schema?: JSONSchema;
patches?: {
theirs?: JsonPatchOperation[];
ours?: JsonPatchOperation[];
};
}): ModifiedBaseRange[];
//# sourceMappingURL=jsonPatchDiff.d.ts.map