Update test framework: fix run_tests.py to support all test files, add auto-import-check for test files

This commit is contained in:
qiaoxinjiu
2026-05-09 15:11:30 +08:00
parent eb053a347f
commit eaba8328da
21739 changed files with 2236758 additions and 719 deletions

View File

@@ -0,0 +1,29 @@
import BaseFormatter from './base.js';
import type { BaseFormatterContext, DeltaType, NodeType } from './base.js';
import type { AddedDelta, ArrayDelta, DeletedDelta, Delta, ModifiedDelta, MovedDelta, ObjectDelta, TextDiffDelta } from '../types.js';
interface AnnotatedFormatterContext extends BaseFormatterContext {
indentLevel?: number;
indentPad?: string;
indent: (levels?: number) => void;
row: (json: string, htmlNote?: string) => void;
}
declare class AnnotatedFormatter extends BaseFormatter<AnnotatedFormatterContext> {
constructor();
prepareContext(context: Partial<AnnotatedFormatterContext>): void;
typeFormattterErrorFormatter(context: AnnotatedFormatterContext, err: unknown): void;
formatTextDiffString(context: AnnotatedFormatterContext, value: string): void;
rootBegin(context: AnnotatedFormatterContext, type: DeltaType, nodeType: NodeType): void;
rootEnd(context: AnnotatedFormatterContext, type: DeltaType): void;
nodeBegin(context: AnnotatedFormatterContext, key: string, leftKey: string | number, type: DeltaType, nodeType: NodeType): void;
nodeEnd(context: AnnotatedFormatterContext, key: string, leftKey: string | number, type: DeltaType, nodeType: NodeType, isLast: boolean): void;
format_unchanged(): void;
format_movedestination(): void;
format_node(context: AnnotatedFormatterContext, delta: ObjectDelta | ArrayDelta, left: unknown): void;
format_added(context: AnnotatedFormatterContext, delta: AddedDelta, left: unknown, key: string | undefined, leftKey: string | number | undefined): void;
format_modified(context: AnnotatedFormatterContext, delta: ModifiedDelta, left: unknown, key: string | undefined, leftKey: string | number | undefined): void;
format_deleted(context: AnnotatedFormatterContext, delta: DeletedDelta, left: unknown, key: string | undefined, leftKey: string | number | undefined): void;
format_moved(context: AnnotatedFormatterContext, delta: MovedDelta, left: unknown, key: string | undefined, leftKey: string | number | undefined): void;
format_textdiff(context: AnnotatedFormatterContext, delta: TextDiffDelta, left: unknown, key: string | undefined, leftKey: string | number | undefined): void;
}
export default AnnotatedFormatter;
export declare function format(delta: Delta, left?: unknown): string | undefined;

169
node_modules/jsondiffpatch/lib/formatters/annotated.js generated vendored Normal file
View File

@@ -0,0 +1,169 @@
import BaseFormatter from './base.js';
class AnnotatedFormatter extends BaseFormatter {
constructor() {
super();
this.includeMoveDestinations = false;
}
prepareContext(context) {
super.prepareContext(context);
context.indent = function (levels) {
this.indentLevel =
(this.indentLevel || 0) + (typeof levels === 'undefined' ? 1 : levels);
this.indentPad = new Array(this.indentLevel + 1).join('&nbsp;&nbsp;');
};
context.row = (json, htmlNote) => {
context.out('<tr><td style="white-space: nowrap;">' +
'<pre class="jsondiffpatch-annotated-indent"' +
' style="display: inline-block">');
if (context.indentPad != null)
context.out(context.indentPad);
context.out('</pre><pre style="display: inline-block">');
context.out(json);
context.out('</pre></td><td class="jsondiffpatch-delta-note"><div>');
if (htmlNote != null)
context.out(htmlNote);
context.out('</div></td></tr>');
};
}
typeFormattterErrorFormatter(context, err) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
context.row('', `<pre class="jsondiffpatch-error">${err}</pre>`);
}
formatTextDiffString(context, value) {
const lines = this.parseTextDiff(value);
context.out('<ul class="jsondiffpatch-textdiff">');
for (let i = 0, l = lines.length; i < l; i++) {
const line = lines[i];
context.out('<li><div class="jsondiffpatch-textdiff-location">' +
`<span class="jsondiffpatch-textdiff-line-number">${line.location.line}</span><span class="jsondiffpatch-textdiff-char">${line.location.chr}</span></div><div class="jsondiffpatch-textdiff-line">`);
const pieces = line.pieces;
for (let pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
const piece = pieces[pieceIndex];
context.out(`<span class="jsondiffpatch-textdiff-${piece.type}">${piece.text}</span>`);
}
context.out('</div></li>');
}
context.out('</ul>');
}
rootBegin(context, type, nodeType) {
context.out('<table class="jsondiffpatch-annotated-delta">');
if (type === 'node') {
context.row('{');
context.indent();
}
if (nodeType === 'array') {
context.row('"_t": "a",', 'Array delta (member names indicate array indices)');
}
}
rootEnd(context, type) {
if (type === 'node') {
context.indent(-1);
context.row('}');
}
context.out('</table>');
}
nodeBegin(context, key, leftKey, type, nodeType) {
context.row(`&quot;${key}&quot;: {`);
if (type === 'node') {
context.indent();
}
if (nodeType === 'array') {
context.row('"_t": "a",', 'Array delta (member names indicate array indices)');
}
}
nodeEnd(context, key, leftKey, type, nodeType, isLast) {
if (type === 'node') {
context.indent(-1);
}
context.row(`}${isLast ? '' : ','}`);
}
format_unchanged() { }
format_movedestination() { }
format_node(context, delta, left) {
// recurse
this.formatDeltaChildren(context, delta, left);
}
format_added(context, delta, left, key, leftKey) {
formatAnyChange.call(this, context, delta, left, key, leftKey);
}
format_modified(context, delta, left, key, leftKey) {
formatAnyChange.call(this, context, delta, left, key, leftKey);
}
format_deleted(context, delta, left, key, leftKey) {
formatAnyChange.call(this, context, delta, left, key, leftKey);
}
format_moved(context, delta, left, key, leftKey) {
formatAnyChange.call(this, context, delta, left, key, leftKey);
}
format_textdiff(context, delta, left, key, leftKey) {
formatAnyChange.call(this, context, delta, left, key, leftKey);
}
}
const wrapPropertyName = (name) => `<pre style="display:inline-block">&quot;${name}&quot;</pre>`;
const deltaAnnotations = {
added(delta, left, key, leftKey) {
const formatLegend = ' <pre>([newValue])</pre>';
if (typeof leftKey === 'undefined') {
return `new value${formatLegend}`;
}
if (typeof leftKey === 'number') {
return `insert at index ${leftKey}${formatLegend}`;
}
return `add property ${wrapPropertyName(leftKey)}${formatLegend}`;
},
modified(delta, left, key, leftKey) {
const formatLegend = ' <pre>([previousValue, newValue])</pre>';
if (typeof leftKey === 'undefined') {
return `modify value${formatLegend}`;
}
if (typeof leftKey === 'number') {
return `modify at index ${leftKey}${formatLegend}`;
}
return `modify property ${wrapPropertyName(leftKey)}${formatLegend}`;
},
deleted(delta, left, key, leftKey) {
const formatLegend = ' <pre>([previousValue, 0, 0])</pre>';
if (typeof leftKey === 'undefined') {
return `delete value${formatLegend}`;
}
if (typeof leftKey === 'number') {
return `remove index ${leftKey}${formatLegend}`;
}
return `delete property ${wrapPropertyName(leftKey)}${formatLegend}`;
},
moved(delta, left, key, leftKey) {
return ('move from <span title="(position to remove at original state)">' +
`index ${leftKey}</span> to <span title="(position to insert at final` +
` state)">index ${delta[1]}</span>`);
},
textdiff(delta, left, key, leftKey) {
const location = typeof leftKey === 'undefined'
? ''
: typeof leftKey === 'number'
? ` at index ${leftKey}`
: ` at property ${wrapPropertyName(leftKey)}`;
return (`text diff${location}, format is <a href="https://code.google.com/` +
'p/google-diff-match-patch/wiki/Unidiff">a variation of Unidiff</a>');
},
};
const formatAnyChange = function (context, delta, left, key, leftKey) {
const deltaType = this.getDeltaType(delta);
const annotator = deltaAnnotations[deltaType];
const htmlNote = annotator && annotator(delta, left, key, leftKey);
let json = JSON.stringify(delta, null, 2);
if (deltaType === 'textdiff') {
// split text diffs lines
json = json.split('\\n').join('\\n"+\n "');
}
context.indent();
context.row(json, htmlNote);
context.indent(-1);
};
export default AnnotatedFormatter;
let defaultInstance;
export function format(delta, left) {
if (!defaultInstance) {
defaultInstance = new AnnotatedFormatter();
}
return defaultInstance.format(delta, left);
}

59
node_modules/jsondiffpatch/lib/formatters/base.d.ts generated vendored Normal file
View File

@@ -0,0 +1,59 @@
import type { AddedDelta, ArrayDelta, DeletedDelta, Delta, ModifiedDelta, MovedDelta, ObjectDelta, TextDiffDelta } from '../types.js';
export interface BaseFormatterContext {
buffer: string[];
out: (...args: string[]) => void;
}
export type DeltaType = 'movedestination' | 'unchanged' | 'added' | 'modified' | 'deleted' | 'textdiff' | 'moved' | 'node' | 'unknown';
export type NodeType = 'array' | 'object' | '';
interface DeltaTypeMap {
movedestination: undefined;
unchanged: undefined;
added: AddedDelta;
modified: ModifiedDelta;
deleted: DeletedDelta;
textdiff: TextDiffDelta;
moved: MovedDelta;
node: ObjectDelta | ArrayDelta;
}
interface MoveDestination {
key: `_${number}`;
value: unknown;
}
interface LineOutputPiece {
type: 'context' | 'added' | 'deleted';
text: string;
}
interface LineOutputLocation {
line: string;
chr: string;
}
interface LineOutput {
pieces: LineOutputPiece[];
location: LineOutputLocation;
}
declare abstract class BaseFormatter<TContext extends BaseFormatterContext, TFormatted = string | undefined> {
includeMoveDestinations?: boolean;
format(delta: Delta, left?: unknown): TFormatted;
prepareContext(context: Partial<TContext>): void;
typeFormattterNotFound(context: TContext, deltaType: 'unknown'): never;
typeFormattterErrorFormatter(context: TContext, err: unknown, delta: Delta, leftValue: unknown, key: string | undefined, leftKey: string | number | undefined, movedFrom: MoveDestination | undefined): void;
finalize({ buffer }: TContext): string | undefined;
recurse<TDeltaType extends keyof DeltaTypeMap>(context: TContext, delta: DeltaTypeMap[TDeltaType], left: unknown, key?: string, leftKey?: string | number, movedFrom?: MoveDestination | undefined, isLast?: boolean): undefined;
formatDeltaChildren(context: TContext, delta: ObjectDelta | ArrayDelta, left: unknown): void;
forEachDeltaKey(delta: ObjectDelta | ArrayDelta, left: unknown, fn: (key: string, leftKey: string | number, moveDestination: MoveDestination | undefined, isLast: boolean) => void): void;
getDeltaType(delta: Delta, movedFrom?: MoveDestination | undefined): "unknown" | "movedestination" | "unchanged" | "added" | "modified" | "deleted" | "textdiff" | "moved" | "node";
parseTextDiff(value: string): LineOutput[];
abstract rootBegin(context: TContext, type: DeltaType, nodeType: NodeType): void;
abstract rootEnd(context: TContext, type: DeltaType, nodeType: NodeType): void;
abstract nodeBegin(context: TContext, key: string, leftKey: string | number, type: DeltaType, nodeType: NodeType, isLast: boolean): void;
abstract nodeEnd(context: TContext, key: string, leftKey: string | number, type: DeltaType, nodeType: NodeType, isLast: boolean): void;
abstract format_unchanged(context: TContext, delta: undefined, leftValue: unknown, key: string | undefined, leftKey: string | number | undefined, movedFrom: MoveDestination | undefined): void;
abstract format_movedestination(context: TContext, delta: undefined, leftValue: unknown, key: string | undefined, leftKey: string | number | undefined, movedFrom: MoveDestination | undefined): void;
abstract format_node(context: TContext, delta: ObjectDelta | ArrayDelta, leftValue: unknown, key: string | undefined, leftKey: string | number | undefined, movedFrom: MoveDestination | undefined): void;
abstract format_added(context: TContext, delta: AddedDelta, leftValue: unknown, key: string | undefined, leftKey: string | number | undefined, movedFrom: MoveDestination | undefined): void;
abstract format_modified(context: TContext, delta: ModifiedDelta, leftValue: unknown, key: string | undefined, leftKey: string | number | undefined, movedFrom: MoveDestination | undefined): void;
abstract format_deleted(context: TContext, delta: DeletedDelta, leftValue: unknown, key: string | undefined, leftKey: string | number | undefined, movedFrom: MoveDestination | undefined): void;
abstract format_moved(context: TContext, delta: MovedDelta, leftValue: unknown, key: string | undefined, leftKey: string | number | undefined, movedFrom: MoveDestination | undefined): void;
abstract format_textdiff(context: TContext, delta: TextDiffDelta, leftValue: unknown, key: string | undefined, leftKey: string | number | undefined, movedFrom: MoveDestination | undefined): void;
}
export default BaseFormatter;

207
node_modules/jsondiffpatch/lib/formatters/base.js generated vendored Normal file
View File

@@ -0,0 +1,207 @@
const trimUnderscore = (str) => {
if (str.substring(0, 1) === '_') {
return str.slice(1);
}
return str;
};
const arrayKeyToSortNumber = (key) => {
if (key === '_t') {
return -1;
}
else {
if (key.substring(0, 1) === '_') {
return parseInt(key.slice(1), 10);
}
else {
return parseInt(key, 10) + 0.1;
}
}
};
const arrayKeyComparer = (key1, key2) => arrayKeyToSortNumber(key1) - arrayKeyToSortNumber(key2);
class BaseFormatter {
format(delta, left) {
const context = {};
this.prepareContext(context);
const preparedContext = context;
this.recurse(preparedContext, delta, left);
return this.finalize(preparedContext);
}
prepareContext(context) {
context.buffer = [];
context.out = function (...args) {
this.buffer.push(...args);
};
}
typeFormattterNotFound(context, deltaType) {
throw new Error(`cannot format delta type: ${deltaType}`);
}
/* eslint-disable @typescript-eslint/no-unused-vars */
typeFormattterErrorFormatter(context, err, delta, leftValue, key, leftKey, movedFrom) { }
/* eslint-enable @typescript-eslint/no-unused-vars */
finalize({ buffer }) {
if (Array.isArray(buffer)) {
return buffer.join('');
}
}
recurse(context, delta, left, key, leftKey, movedFrom, isLast) {
const useMoveOriginHere = delta && movedFrom;
const leftValue = useMoveOriginHere ? movedFrom.value : left;
if (typeof delta === 'undefined' && typeof key === 'undefined') {
return undefined;
}
const type = this.getDeltaType(delta, movedFrom);
const nodeType = type === 'node'
? delta._t === 'a'
? 'array'
: 'object'
: '';
if (typeof key !== 'undefined') {
this.nodeBegin(context, key, leftKey, type, nodeType, isLast);
}
else {
this.rootBegin(context, type, nodeType);
}
let typeFormattter;
try {
typeFormattter =
type !== 'unknown'
? this[`format_${type}`]
: this.typeFormattterNotFound(context, type);
typeFormattter.call(this, context, delta, leftValue, key, leftKey, movedFrom);
}
catch (err) {
this.typeFormattterErrorFormatter(context, err, delta, leftValue, key, leftKey, movedFrom);
if (typeof console !== 'undefined' && console.error) {
console.error(err.stack);
}
}
if (typeof key !== 'undefined') {
this.nodeEnd(context, key, leftKey, type, nodeType, isLast);
}
else {
this.rootEnd(context, type, nodeType);
}
}
formatDeltaChildren(context, delta, left) {
this.forEachDeltaKey(delta, left, (key, leftKey, movedFrom, isLast) => {
this.recurse(context, delta[key], left ? left[leftKey] : undefined, key, leftKey, movedFrom, isLast);
});
}
forEachDeltaKey(delta, left, fn) {
const keys = Object.keys(delta);
const arrayKeys = delta._t === 'a';
const moveDestinations = {};
let name;
if (typeof left !== 'undefined') {
for (name in left) {
if (Object.prototype.hasOwnProperty.call(left, name)) {
if (typeof delta[name] === 'undefined' &&
(!arrayKeys ||
typeof delta[`_${name}`] ===
'undefined')) {
keys.push(name);
}
}
}
}
// look for move destinations
for (name in delta) {
if (Object.prototype.hasOwnProperty.call(delta, name)) {
const value = delta[name];
if (Array.isArray(value) && value[2] === 3) {
const movedDelta = value;
moveDestinations[`${movedDelta[1]}`] = {
key: name,
value: left && left[parseInt(name.substring(1), 10)],
};
if (this.includeMoveDestinations !== false) {
if (typeof left === 'undefined' &&
typeof delta[movedDelta[1]] === 'undefined') {
keys.push(movedDelta[1].toString());
}
}
}
}
}
if (arrayKeys) {
keys.sort(arrayKeyComparer);
}
else {
keys.sort();
}
for (let index = 0, length = keys.length; index < length; index++) {
const key = keys[index];
if (arrayKeys && key === '_t') {
continue;
}
const leftKey = arrayKeys ? parseInt(trimUnderscore(key), 10) : key;
const isLast = index === length - 1;
fn(key, leftKey, moveDestinations[leftKey], isLast);
}
}
getDeltaType(delta, movedFrom) {
if (typeof delta === 'undefined') {
if (typeof movedFrom !== 'undefined') {
return 'movedestination';
}
return 'unchanged';
}
if (Array.isArray(delta)) {
if (delta.length === 1) {
return 'added';
}
if (delta.length === 2) {
return 'modified';
}
if (delta.length === 3 && delta[2] === 0) {
return 'deleted';
}
if (delta.length === 3 && delta[2] === 2) {
return 'textdiff';
}
if (delta.length === 3 && delta[2] === 3) {
return 'moved';
}
}
else if (typeof delta === 'object') {
return 'node';
}
return 'unknown';
}
parseTextDiff(value) {
const output = [];
const lines = value.split('\n@@ ');
for (let i = 0, l = lines.length; i < l; i++) {
const line = lines[i];
const lineOutput = {
pieces: [],
};
const location = /^(?:@@ )?[-+]?(\d+),(\d+)/.exec(line).slice(1);
lineOutput.location = {
line: location[0],
chr: location[1],
};
const pieces = line.split('\n').slice(1);
for (let pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
const piece = pieces[pieceIndex];
if (!piece.length) {
continue;
}
const pieceOutput = {
type: 'context',
};
if (piece.substring(0, 1) === '+') {
pieceOutput.type = 'added';
}
else if (piece.substring(0, 1) === '-') {
pieceOutput.type = 'deleted';
}
pieceOutput.text = piece.slice(1);
lineOutput.pieces.push(pieceOutput);
}
output.push(lineOutput);
}
return output;
}
}
export default BaseFormatter;

35
node_modules/jsondiffpatch/lib/formatters/console.d.ts generated vendored Normal file
View File

@@ -0,0 +1,35 @@
import type { ChalkInstance } from 'chalk';
import BaseFormatter from './base.js';
import type { BaseFormatterContext, DeltaType, NodeType } from './base.js';
import type { AddedDelta, ArrayDelta, DeletedDelta, Delta, ModifiedDelta, MovedDelta, ObjectDelta, TextDiffDelta } from '../types.js';
interface ConsoleFormatterContext extends BaseFormatterContext {
indentLevel?: number;
indentPad?: string;
outLine: () => void;
indent: (levels?: number) => void;
color?: (ChalkInstance | undefined)[];
pushColor: (color: ChalkInstance | undefined) => void;
popColor: () => void;
}
declare class ConsoleFormatter extends BaseFormatter<ConsoleFormatterContext> {
constructor();
prepareContext(context: Partial<ConsoleFormatterContext>): void;
typeFormattterErrorFormatter(context: ConsoleFormatterContext, err: unknown): void;
formatValue(context: ConsoleFormatterContext, value: unknown): void;
formatTextDiffString(context: ConsoleFormatterContext, value: string): void;
rootBegin(context: ConsoleFormatterContext, type: DeltaType, nodeType: NodeType): void;
rootEnd(context: ConsoleFormatterContext, type: DeltaType, nodeType: NodeType): void;
nodeBegin(context: ConsoleFormatterContext, key: string, leftKey: string | number, type: DeltaType, nodeType: NodeType): void;
nodeEnd(context: ConsoleFormatterContext, key: string, leftKey: string | number, type: DeltaType, nodeType: NodeType, isLast: boolean): void;
format_unchanged(context: ConsoleFormatterContext, delta: undefined, left: unknown): void;
format_movedestination(context: ConsoleFormatterContext, delta: undefined, left: unknown): void;
format_node(context: ConsoleFormatterContext, delta: ObjectDelta | ArrayDelta, left: unknown): void;
format_added(context: ConsoleFormatterContext, delta: AddedDelta): void;
format_modified(context: ConsoleFormatterContext, delta: ModifiedDelta): void;
format_deleted(context: ConsoleFormatterContext, delta: DeletedDelta): void;
format_moved(context: ConsoleFormatterContext, delta: MovedDelta): void;
format_textdiff(context: ConsoleFormatterContext, delta: TextDiffDelta): void;
}
export default ConsoleFormatter;
export declare const format: (delta: Delta, left?: unknown) => string | undefined;
export declare function log(delta: Delta, left?: unknown): void;

157
node_modules/jsondiffpatch/lib/formatters/console.js generated vendored Normal file
View File

@@ -0,0 +1,157 @@
import chalk from 'chalk';
import BaseFormatter from './base.js';
const colors = {
added: chalk.green,
deleted: chalk.red,
movedestination: chalk.gray,
moved: chalk.yellow,
unchanged: chalk.gray,
error: chalk.white.bgRed,
textDiffLine: chalk.gray,
};
class ConsoleFormatter extends BaseFormatter {
constructor() {
super();
this.includeMoveDestinations = false;
}
prepareContext(context) {
super.prepareContext(context);
context.indent = function (levels) {
this.indentLevel =
(this.indentLevel || 0) + (typeof levels === 'undefined' ? 1 : levels);
this.indentPad = new Array(this.indentLevel + 1).join(' ');
this.outLine();
};
context.outLine = function () {
this.buffer.push(`\n${this.indentPad || ''}`);
};
context.out = function (...args) {
for (let i = 0, l = args.length; i < l; i++) {
const lines = args[i].split('\n');
let text = lines.join(`\n${this.indentPad || ''}`);
if (this.color && this.color[0]) {
text = this.color[0](text);
}
this.buffer.push(text);
}
};
context.pushColor = function (color) {
this.color = this.color || [];
this.color.unshift(color);
};
context.popColor = function () {
this.color = this.color || [];
this.color.shift();
};
}
typeFormattterErrorFormatter(context, err) {
context.pushColor(colors.error);
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
context.out(`[ERROR]${err}`);
context.popColor();
}
formatValue(context, value) {
context.out(JSON.stringify(value, null, 2));
}
formatTextDiffString(context, value) {
const lines = this.parseTextDiff(value);
context.indent();
for (let i = 0, l = lines.length; i < l; i++) {
const line = lines[i];
context.pushColor(colors.textDiffLine);
context.out(`${line.location.line},${line.location.chr} `);
context.popColor();
const pieces = line.pieces;
for (let pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
const piece = pieces[pieceIndex];
context.pushColor(colors[piece.type]);
context.out(piece.text);
context.popColor();
}
if (i < l - 1) {
context.outLine();
}
}
context.indent(-1);
}
rootBegin(context, type, nodeType) {
context.pushColor(colors[type]);
if (type === 'node') {
context.out(nodeType === 'array' ? '[' : '{');
context.indent();
}
}
rootEnd(context, type, nodeType) {
if (type === 'node') {
context.indent(-1);
context.out(nodeType === 'array' ? ']' : '}');
}
context.popColor();
}
nodeBegin(context, key, leftKey, type, nodeType) {
context.pushColor(colors[type]);
context.out(`${leftKey}: `);
if (type === 'node') {
context.out(nodeType === 'array' ? '[' : '{');
context.indent();
}
}
nodeEnd(context, key, leftKey, type, nodeType, isLast) {
if (type === 'node') {
context.indent(-1);
context.out(nodeType === 'array' ? ']' : `}${isLast ? '' : ','}`);
}
if (!isLast) {
context.outLine();
}
context.popColor();
}
format_unchanged(context, delta, left) {
if (typeof left === 'undefined') {
return;
}
this.formatValue(context, left);
}
format_movedestination(context, delta, left) {
if (typeof left === 'undefined') {
return;
}
this.formatValue(context, left);
}
format_node(context, delta, left) {
// recurse
this.formatDeltaChildren(context, delta, left);
}
format_added(context, delta) {
this.formatValue(context, delta[0]);
}
format_modified(context, delta) {
context.pushColor(colors.deleted);
this.formatValue(context, delta[0]);
context.popColor();
context.out(' => ');
context.pushColor(colors.added);
this.formatValue(context, delta[1]);
context.popColor();
}
format_deleted(context, delta) {
this.formatValue(context, delta[0]);
}
format_moved(context, delta) {
context.out(`==> ${delta[1]}`);
}
format_textdiff(context, delta) {
this.formatTextDiffString(context, delta[0]);
}
}
export default ConsoleFormatter;
let defaultInstance;
export const format = (delta, left) => {
if (!defaultInstance) {
defaultInstance = new ConsoleFormatter();
}
return defaultInstance.format(delta, left);
};
export function log(delta, left) {
console.log(format(delta, left));
}

27
node_modules/jsondiffpatch/lib/formatters/html.d.ts generated vendored Normal file
View File

@@ -0,0 +1,27 @@
import BaseFormatter from './base.js';
import type { BaseFormatterContext, DeltaType, NodeType } from './base.js';
import type { AddedDelta, ArrayDelta, DeletedDelta, Delta, ModifiedDelta, MovedDelta, ObjectDelta, TextDiffDelta } from '../types.js';
interface HtmlFormatterContext extends BaseFormatterContext {
hasArrows?: boolean;
}
declare class HtmlFormatter extends BaseFormatter<HtmlFormatterContext> {
typeFormattterErrorFormatter(context: HtmlFormatterContext, err: unknown): void;
formatValue(context: HtmlFormatterContext, value: unknown): void;
formatTextDiffString(context: HtmlFormatterContext, value: string): void;
rootBegin(context: HtmlFormatterContext, type: DeltaType, nodeType: NodeType): void;
rootEnd(context: HtmlFormatterContext): void;
nodeBegin(context: HtmlFormatterContext, key: string, leftKey: string | number, type: DeltaType, nodeType: NodeType): void;
nodeEnd(context: HtmlFormatterContext): void;
format_unchanged(context: HtmlFormatterContext, delta: undefined, left: unknown): void;
format_movedestination(context: HtmlFormatterContext, delta: undefined, left: unknown): void;
format_node(context: HtmlFormatterContext, delta: ObjectDelta | ArrayDelta, left: unknown): void;
format_added(context: HtmlFormatterContext, delta: AddedDelta): void;
format_modified(context: HtmlFormatterContext, delta: ModifiedDelta): void;
format_deleted(context: HtmlFormatterContext, delta: DeletedDelta): void;
format_moved(context: HtmlFormatterContext, delta: MovedDelta): void;
format_textdiff(context: HtmlFormatterContext, delta: TextDiffDelta): void;
}
export declare const showUnchanged: (show?: boolean, node?: Element | null, delay?: number) => void;
export declare const hideUnchanged: (node?: Element, delay?: number) => void;
export default HtmlFormatter;
export declare function format(delta: Delta, left?: unknown): string | undefined;

238
node_modules/jsondiffpatch/lib/formatters/html.js generated vendored Normal file
View File

@@ -0,0 +1,238 @@
import BaseFormatter from './base.js';
class HtmlFormatter extends BaseFormatter {
typeFormattterErrorFormatter(context, err) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
context.out(`<pre class="jsondiffpatch-error">${err}</pre>`);
}
formatValue(context, value) {
context.out(`<pre>${htmlEscape(JSON.stringify(value, null, 2))}</pre>`);
}
formatTextDiffString(context, value) {
const lines = this.parseTextDiff(value);
context.out('<ul class="jsondiffpatch-textdiff">');
for (let i = 0, l = lines.length; i < l; i++) {
const line = lines[i];
context.out('<li><div class="jsondiffpatch-textdiff-location">' +
`<span class="jsondiffpatch-textdiff-line-number">${line.location.line}</span><span class="jsondiffpatch-textdiff-char">${line.location.chr}</span></div><div class="jsondiffpatch-textdiff-line">`);
const pieces = line.pieces;
for (let pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
const piece = pieces[pieceIndex];
context.out(`<span class="jsondiffpatch-textdiff-${piece.type}">${htmlEscape(decodeURI(piece.text))}</span>`);
}
context.out('</div></li>');
}
context.out('</ul>');
}
rootBegin(context, type, nodeType) {
const nodeClass = `jsondiffpatch-${type}${nodeType ? ` jsondiffpatch-child-node-type-${nodeType}` : ''}`;
context.out(`<div class="jsondiffpatch-delta ${nodeClass}">`);
}
rootEnd(context) {
context.out(`</div>${context.hasArrows
? '<script type="text/javascript">setTimeout(' +
`${adjustArrows.toString()},10);</script>`
: ''}`);
}
nodeBegin(context, key, leftKey, type, nodeType) {
const nodeClass = `jsondiffpatch-${type}${nodeType ? ` jsondiffpatch-child-node-type-${nodeType}` : ''}`;
context.out(`<li class="${nodeClass}" data-key="${leftKey}">` +
`<div class="jsondiffpatch-property-name">${leftKey}</div>`);
}
nodeEnd(context) {
context.out('</li>');
}
format_unchanged(context, delta, left) {
if (typeof left === 'undefined') {
return;
}
context.out('<div class="jsondiffpatch-value">');
this.formatValue(context, left);
context.out('</div>');
}
format_movedestination(context, delta, left) {
if (typeof left === 'undefined') {
return;
}
context.out('<div class="jsondiffpatch-value">');
this.formatValue(context, left);
context.out('</div>');
}
format_node(context, delta, left) {
// recurse
const nodeType = delta._t === 'a' ? 'array' : 'object';
context.out(`<ul class="jsondiffpatch-node jsondiffpatch-node-type-${nodeType}">`);
this.formatDeltaChildren(context, delta, left);
context.out('</ul>');
}
format_added(context, delta) {
context.out('<div class="jsondiffpatch-value">');
this.formatValue(context, delta[0]);
context.out('</div>');
}
format_modified(context, delta) {
context.out('<div class="jsondiffpatch-value jsondiffpatch-left-value">');
this.formatValue(context, delta[0]);
context.out('</div>' + '<div class="jsondiffpatch-value jsondiffpatch-right-value">');
this.formatValue(context, delta[1]);
context.out('</div>');
}
format_deleted(context, delta) {
context.out('<div class="jsondiffpatch-value">');
this.formatValue(context, delta[0]);
context.out('</div>');
}
format_moved(context, delta) {
context.out('<div class="jsondiffpatch-value">');
this.formatValue(context, delta[0]);
context.out(`</div><div class="jsondiffpatch-moved-destination">${delta[1]}</div>`);
// draw an SVG arrow from here to move destination
context.out(
/* jshint multistr: true */
'<div class="jsondiffpatch-arrow" ' +
`style="position: relative; left: -34px;">
<svg width="30" height="60" ` +
`style="position: absolute; display: none;">
<defs>
<marker id="markerArrow" markerWidth="8" markerHeight="8"
refx="2" refy="4"
orient="auto" markerUnits="userSpaceOnUse">
<path d="M1,1 L1,7 L7,4 L1,1" style="fill: #339;" />
</marker>
</defs>
<path d="M30,0 Q-10,25 26,50"
style="stroke: #88f; stroke-width: 2px; fill: none; ` +
`stroke-opacity: 0.5; marker-end: url(#markerArrow);"
></path>
</svg>
</div>`);
context.hasArrows = true;
}
format_textdiff(context, delta) {
context.out('<div class="jsondiffpatch-value">');
this.formatTextDiffString(context, delta[0]);
context.out('</div>');
}
}
function htmlEscape(text) {
let html = text;
const replacements = [
[/&/g, '&amp;'],
[/</g, '&lt;'],
[/>/g, '&gt;'],
[/'/g, '&apos;'],
[/"/g, '&quot;'],
];
for (let i = 0; i < replacements.length; i++) {
html = html.replace(replacements[i][0], replacements[i][1]);
}
return html;
}
const adjustArrows = function jsondiffpatchHtmlFormatterAdjustArrows(nodeArg) {
const node = nodeArg || document;
const getElementText = ({ textContent, innerText }) => textContent || innerText;
const eachByQuery = (el, query, fn) => {
const elems = el.querySelectorAll(query);
for (let i = 0, l = elems.length; i < l; i++) {
fn(elems[i]);
}
};
const eachChildren = ({ children }, fn) => {
for (let i = 0, l = children.length; i < l; i++) {
fn(children[i], i);
}
};
eachByQuery(node, '.jsondiffpatch-arrow', ({ parentNode, children, style }) => {
const arrowParent = parentNode;
const svg = children[0];
const path = svg.children[1];
svg.style.display = 'none';
const destination = getElementText(arrowParent.querySelector('.jsondiffpatch-moved-destination'));
const container = arrowParent.parentNode;
let destinationElem;
eachChildren(container, (child) => {
if (child.getAttribute('data-key') === destination) {
destinationElem = child;
}
});
if (!destinationElem) {
return;
}
try {
const distance = destinationElem.offsetTop - arrowParent.offsetTop;
svg.setAttribute('height', `${Math.abs(distance) + 6}`);
style.top = `${-8 + (distance > 0 ? 0 : distance)}px`;
const curve = distance > 0
? `M30,0 Q-10,${Math.round(distance / 2)} 26,${distance - 4}`
: `M30,${-distance} Q-10,${Math.round(-distance / 2)} 26,4`;
path.setAttribute('d', curve);
svg.style.display = '';
}
catch (err) {
// continue regardless of error
}
});
};
export const showUnchanged = (show, node, delay) => {
const el = node || document.body;
const prefix = 'jsondiffpatch-unchanged-';
const classes = {
showing: `${prefix}showing`,
hiding: `${prefix}hiding`,
visible: `${prefix}visible`,
hidden: `${prefix}hidden`,
};
const list = el.classList;
if (!list) {
return;
}
if (!delay) {
list.remove(classes.showing);
list.remove(classes.hiding);
list.remove(classes.visible);
list.remove(classes.hidden);
if (show === false) {
list.add(classes.hidden);
}
return;
}
if (show === false) {
list.remove(classes.showing);
list.add(classes.visible);
setTimeout(() => {
list.add(classes.hiding);
}, 10);
}
else {
list.remove(classes.hiding);
list.add(classes.showing);
list.remove(classes.hidden);
}
const intervalId = setInterval(() => {
adjustArrows(el);
}, 100);
setTimeout(() => {
list.remove(classes.showing);
list.remove(classes.hiding);
if (show === false) {
list.add(classes.hidden);
list.remove(classes.visible);
}
else {
list.add(classes.visible);
list.remove(classes.hidden);
}
setTimeout(() => {
list.remove(classes.visible);
clearInterval(intervalId);
}, delay + 400);
}, delay);
};
export const hideUnchanged = (node, delay) => showUnchanged(false, node, delay);
export default HtmlFormatter;
let defaultInstance;
export function format(delta, left) {
if (!defaultInstance) {
defaultInstance = new HtmlFormatter();
}
return defaultInstance.format(delta, left);
}

View File

@@ -0,0 +1,61 @@
import BaseFormatter from './base.js';
import type { BaseFormatterContext } from './base.js';
import type { AddedDelta, ArrayDelta, Delta, ModifiedDelta, MovedDelta, ObjectDelta } from '../types.js';
export interface AddOp {
op: 'add';
path: string;
value: unknown;
}
export interface RemoveOp {
op: 'remove';
path: string;
}
export interface ReplaceOp {
op: 'replace';
path: string;
value: unknown;
}
export interface MoveOp {
op: 'move';
from: string;
path: string;
}
export type Op = AddOp | RemoveOp | ReplaceOp | MoveOp;
interface JSONFormatterContext extends BaseFormatterContext {
result: Op[];
path: (string | number)[];
pushCurrentOp: (obj: {
op: 'add';
value: unknown;
} | {
op: 'remove';
} | {
op: 'replace';
value: unknown;
}) => void;
pushMoveOp: (to: number) => void;
currentPath: () => string;
toPath: (to: number) => string;
}
declare class JSONFormatter extends BaseFormatter<JSONFormatterContext, Op[]> {
constructor();
prepareContext(context: Partial<JSONFormatterContext>): void;
typeFormattterErrorFormatter(context: JSONFormatterContext, err: unknown): void;
rootBegin(): void;
rootEnd(): void;
nodeBegin({ path }: JSONFormatterContext, key: string, leftKey: string | number): void;
nodeEnd({ path }: JSONFormatterContext): void;
format_unchanged(): void;
format_movedestination(): void;
format_node(context: JSONFormatterContext, delta: ObjectDelta | ArrayDelta, left: unknown): void;
format_added(context: JSONFormatterContext, delta: AddedDelta): void;
format_modified(context: JSONFormatterContext, delta: ModifiedDelta): void;
format_deleted(context: JSONFormatterContext): void;
format_moved(context: JSONFormatterContext, delta: MovedDelta): void;
format_textdiff(): void;
format(delta: Delta, left?: unknown): Op[];
}
export default JSONFormatter;
export declare const partitionOps: (arr: Op[], fns: ((op: Op) => boolean)[]) => Op[][];
export declare const format: (delta: Delta, left?: unknown) => Op[];
export declare const log: (delta: Delta, left?: unknown) => void;

152
node_modules/jsondiffpatch/lib/formatters/jsonpatch.js generated vendored Normal file
View File

@@ -0,0 +1,152 @@
import BaseFormatter from './base.js';
const OPERATIONS = {
add: 'add',
remove: 'remove',
replace: 'replace',
move: 'move',
};
class JSONFormatter extends BaseFormatter {
constructor() {
super();
this.includeMoveDestinations = true;
}
prepareContext(context) {
super.prepareContext(context);
context.result = [];
context.path = [];
context.pushCurrentOp = function (obj) {
if (obj.op === 'add' || obj.op === 'replace') {
this.result.push({
op: obj.op,
path: this.currentPath(),
value: obj.value,
});
}
else if (obj.op === 'remove') {
this.result.push({ op: obj.op, path: this.currentPath() });
}
else {
obj;
}
};
context.pushMoveOp = function (to) {
const from = this.currentPath();
this.result.push({
op: OPERATIONS.move,
from,
path: this.toPath(to),
});
};
context.currentPath = function () {
return `/${this.path.join('/')}`;
};
context.toPath = function (toPath) {
const to = this.path.slice();
to[to.length - 1] = toPath;
return `/${to.join('/')}`;
};
}
typeFormattterErrorFormatter(context, err) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
context.out(`[ERROR] ${err}`);
}
rootBegin() { }
rootEnd() { }
nodeBegin({ path }, key, leftKey) {
path.push(leftKey);
}
nodeEnd({ path }) {
path.pop();
}
format_unchanged() { }
format_movedestination() { }
format_node(context, delta, left) {
this.formatDeltaChildren(context, delta, left);
}
format_added(context, delta) {
context.pushCurrentOp({ op: OPERATIONS.add, value: delta[0] });
}
format_modified(context, delta) {
context.pushCurrentOp({ op: OPERATIONS.replace, value: delta[1] });
}
format_deleted(context) {
context.pushCurrentOp({ op: OPERATIONS.remove });
}
format_moved(context, delta) {
const to = delta[1];
context.pushMoveOp(to);
}
format_textdiff() {
throw new Error('Not implemented');
}
format(delta, left) {
const context = {};
this.prepareContext(context);
const preparedContext = context;
this.recurse(preparedContext, delta, left);
return preparedContext.result;
}
}
export default JSONFormatter;
const last = (arr) => arr[arr.length - 1];
const sortBy = (arr, pred) => {
arr.sort(pred);
return arr;
};
const compareByIndexDesc = (indexA, indexB) => {
const lastA = parseInt(indexA, 10);
const lastB = parseInt(indexB, 10);
if (!(isNaN(lastA) || isNaN(lastB))) {
return lastB - lastA;
}
else {
return 0;
}
};
const opsByDescendingOrder = (removeOps) => sortBy(removeOps, (a, b) => {
const splitA = a.path.split('/');
const splitB = b.path.split('/');
if (splitA.length !== splitB.length) {
return splitA.length - splitB.length;
}
else {
return compareByIndexDesc(last(splitA), last(splitB));
}
});
export const partitionOps = (arr, fns) => {
const initArr = Array(fns.length + 1)
.fill(undefined)
.map(() => []);
return arr
.map((item) => {
let position = fns.map((fn) => fn(item)).indexOf(true);
if (position < 0) {
position = fns.length;
}
return { item, position };
})
.reduce((acc, item) => {
acc[item.position].push(item.item);
return acc;
}, initArr);
};
const isMoveOp = ({ op }) => op === 'move';
const isRemoveOp = ({ op }) => op === 'remove';
const reorderOps = (diff) => {
const [moveOps, removedOps, restOps] = partitionOps(diff, [
isMoveOp,
isRemoveOp,
]);
const removeOpsReverse = opsByDescendingOrder(removedOps);
return [...removeOpsReverse, ...moveOps, ...restOps];
};
let defaultInstance;
export const format = (delta, left) => {
if (!defaultInstance) {
defaultInstance = new JSONFormatter();
}
return reorderOps(defaultInstance.format(delta, left));
};
export const log = (delta, left) => {
console.log(format(delta, left));
};

View File

@@ -0,0 +1,48 @@
.jsondiffpatch-annotated-delta {
font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Monaco, Courier,
monospace;
font-size: 12px;
margin: 0;
padding: 0 0 0 12px;
display: inline-block;
}
.jsondiffpatch-annotated-delta pre {
font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Monaco, Courier,
monospace;
font-size: 12px;
margin: 0;
padding: 0;
display: inline-block;
}
.jsondiffpatch-annotated-delta td {
margin: 0;
padding: 0;
}
.jsondiffpatch-annotated-delta td pre:hover {
font-weight: bold;
}
td.jsondiffpatch-delta-note {
font-style: italic;
padding-left: 10px;
}
.jsondiffpatch-delta-note > div {
margin: 0;
padding: 0;
}
.jsondiffpatch-delta-note pre {
font-style: normal;
}
.jsondiffpatch-annotated-delta .jsondiffpatch-delta-note {
color: #777;
}
.jsondiffpatch-annotated-delta tr:hover {
background: #ffc;
}
.jsondiffpatch-annotated-delta tr:hover > td.jsondiffpatch-delta-note {
color: black;
}
.jsondiffpatch-error {
background: red;
color: white;
font-weight: bold;
}

View File

@@ -0,0 +1,163 @@
.jsondiffpatch-delta {
font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Monaco, Courier,
monospace;
font-size: 12px;
margin: 0;
padding: 0 0 0 12px;
display: inline-block;
}
.jsondiffpatch-delta pre {
font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Monaco, Courier,
monospace;
font-size: 12px;
margin: 0;
padding: 0;
display: inline-block;
}
ul.jsondiffpatch-delta {
list-style-type: none;
padding: 0 0 0 20px;
margin: 0;
}
.jsondiffpatch-delta ul {
list-style-type: none;
padding: 0 0 0 20px;
margin: 0;
}
.jsondiffpatch-added .jsondiffpatch-property-name,
.jsondiffpatch-added .jsondiffpatch-value pre,
.jsondiffpatch-modified .jsondiffpatch-right-value pre,
.jsondiffpatch-textdiff-added {
background: #bbffbb;
}
.jsondiffpatch-deleted .jsondiffpatch-property-name,
.jsondiffpatch-deleted pre,
.jsondiffpatch-modified .jsondiffpatch-left-value pre,
.jsondiffpatch-textdiff-deleted {
background: #ffbbbb;
text-decoration: line-through;
}
.jsondiffpatch-unchanged,
.jsondiffpatch-movedestination {
color: gray;
}
.jsondiffpatch-unchanged,
.jsondiffpatch-movedestination > .jsondiffpatch-value {
transition: all 0.5s;
-webkit-transition: all 0.5s;
overflow-y: hidden;
}
.jsondiffpatch-unchanged-showing .jsondiffpatch-unchanged,
.jsondiffpatch-unchanged-showing
.jsondiffpatch-movedestination
> .jsondiffpatch-value {
max-height: 100px;
}
.jsondiffpatch-unchanged-hidden .jsondiffpatch-unchanged,
.jsondiffpatch-unchanged-hidden
.jsondiffpatch-movedestination
> .jsondiffpatch-value {
max-height: 0;
}
.jsondiffpatch-unchanged-hiding
.jsondiffpatch-movedestination
> .jsondiffpatch-value,
.jsondiffpatch-unchanged-hidden
.jsondiffpatch-movedestination
> .jsondiffpatch-value {
display: block;
}
.jsondiffpatch-unchanged-visible .jsondiffpatch-unchanged,
.jsondiffpatch-unchanged-visible
.jsondiffpatch-movedestination
> .jsondiffpatch-value {
max-height: 100px;
}
.jsondiffpatch-unchanged-hiding .jsondiffpatch-unchanged,
.jsondiffpatch-unchanged-hiding
.jsondiffpatch-movedestination
> .jsondiffpatch-value {
max-height: 0;
}
.jsondiffpatch-unchanged-showing .jsondiffpatch-arrow,
.jsondiffpatch-unchanged-hiding .jsondiffpatch-arrow {
display: none;
}
.jsondiffpatch-value {
display: inline-block;
}
.jsondiffpatch-property-name {
display: inline-block;
padding-right: 5px;
vertical-align: top;
}
.jsondiffpatch-property-name:after {
content: ': ';
}
.jsondiffpatch-child-node-type-array > .jsondiffpatch-property-name:after {
content: ': [';
}
.jsondiffpatch-child-node-type-array:after {
content: '],';
}
div.jsondiffpatch-child-node-type-array:before {
content: '[';
}
div.jsondiffpatch-child-node-type-array:after {
content: ']';
}
.jsondiffpatch-child-node-type-object > .jsondiffpatch-property-name:after {
content: ': {';
}
.jsondiffpatch-child-node-type-object:after {
content: '},';
}
div.jsondiffpatch-child-node-type-object:before {
content: '{';
}
div.jsondiffpatch-child-node-type-object:after {
content: '}';
}
.jsondiffpatch-value pre:after {
content: ',';
}
li:last-child > .jsondiffpatch-value pre:after,
.jsondiffpatch-modified > .jsondiffpatch-left-value pre:after {
content: '';
}
.jsondiffpatch-modified .jsondiffpatch-value {
display: inline-block;
}
.jsondiffpatch-modified .jsondiffpatch-right-value {
margin-left: 5px;
}
.jsondiffpatch-moved .jsondiffpatch-value {
display: none;
}
.jsondiffpatch-moved .jsondiffpatch-moved-destination {
display: inline-block;
background: #ffffbb;
color: #888;
}
.jsondiffpatch-moved .jsondiffpatch-moved-destination:before {
content: ' => ';
}
ul.jsondiffpatch-textdiff {
padding: 0;
}
.jsondiffpatch-textdiff-location {
color: #bbb;
display: inline-block;
min-width: 60px;
}
.jsondiffpatch-textdiff-line {
display: inline-block;
}
.jsondiffpatch-textdiff-line-number:after {
content: ',';
}
.jsondiffpatch-error {
background: red;
color: white;
font-weight: bold;
}