fast-json-schema-patch
Version:
Ultra-fast, schema-aware JSON patch generation and human-readable diffing. A high-performance JSON patch library that leverages schema knowledge to generate efficient, semantic patches with tools for creating human-readable diffs suitable for frontend app
119 lines • 3.12 kB
text/typescript
//#region src/types.d.ts
type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
type JsonObject = { [Key in string]?: JsonValue };
type JsonArray = JsonValue[];
interface StructuredDiffConfig {
pathPrefix: string;
original: JsonValue;
modified: JsonValue;
patches?: Operation[];
}
interface StructuredDiffResult {
parentDiff: FormattedParentDiff;
childDiffs: Record<string, FormattedChildDiff>;
}
interface FormattedParentDiff {
original: JsonValue;
new: JsonValue;
patches: Operation[];
diffLines: StructuredDiffLine[];
addCount: number;
removeCount: number;
}
interface FormattedChildDiff {
id: string;
original: JsonObject;
new: JsonObject;
patches: Operation[];
diffLines: StructuredDiffLine[];
addCount: number;
removeCount: number;
}
interface Operation {
op: "add" | "remove" | "replace" | "move" | "copy" | "test";
path: string;
value?: JsonValue;
from?: string;
oldValue?: JsonValue;
}
interface StructuredDiffLine {
type: "added" | "removed" | "unchanged";
content: string;
oldLineNumber?: number;
newLineNumber?: number;
key: string;
}
//#endregion
//#region src/core/buildPlan.d.ts
interface JSONSchema extends JsonObject {
$ref?: string;
type?: string | string[];
properties?: Record<string, JSONSchema>;
additionalProperties?: boolean | JSONSchema;
items?: JSONSchema;
anyOf?: JSONSchema[];
oneOf?: JSONSchema[];
allOf?: JSONSchema[];
required?: string[];
}
type Schema = JSONSchema;
interface ArrayPlan {
primaryKey: string | null;
itemSchema?: JSONSchema;
requiredFields?: Set<string>;
hashFields?: string[];
strategy?: "primaryKey" | "lcs" | "unique";
}
type Plan = Map<string, ArrayPlan>;
interface BuildPlanOptions {
schema: Schema;
primaryKeyMap?: Record<string, string>;
basePath?: string;
}
declare function buildPlan(options: BuildPlanOptions): Plan;
//#endregion
//#region src/aggregators/StructuredDiff.d.ts
declare class StructuredDiff {
private plan;
constructor(options: {
plan: Plan;
});
private getIdKeyForPath;
private supportsAggregation;
private isArrayPath;
private getArrayPlanForPath;
private aggregateWithoutChildSeparation;
private compareObjects;
execute(config: StructuredDiffConfig): StructuredDiffResult;
private getAndStripChildArray;
}
//#endregion
//#region src/index.d.ts
declare class JsonSchemaPatcher {
private plan;
private planLookupCache;
private wildcardPathCache;
private negativePlanCache;
private readonly planIsEmpty;
private simplePathCache;
constructor(options: {
plan: Plan;
});
private getWildcardPathCached;
execute({
original,
modified
}: {
original: JsonValue;
modified: JsonValue;
}): Operation[];
private diff;
private diffObject;
private diffArray;
private simpleArrayDiff;
private getPlanForPath;
private refine;
}
//#endregion
export { BuildPlanOptions, FormattedChildDiff, FormattedParentDiff, JsonSchemaPatcher, Operation, Plan, StructuredDiff, StructuredDiffConfig, StructuredDiffLine, StructuredDiffResult, buildPlan };
//# sourceMappingURL=index.d.cts.map