json-diff-ts 4.10.0 → 5.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +461 -284
- package/dist/index.cjs +753 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +99 -1
- package/dist/index.d.ts +99 -1
- package/dist/index.js +741 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,9 @@ interface IAtomicChange {
|
|
|
25
25
|
oldValue?: any;
|
|
26
26
|
}
|
|
27
27
|
interface Options {
|
|
28
|
+
/** Identify array elements by a stable key instead of index. */
|
|
29
|
+
arrayIdentityKeys?: EmbeddedObjKeysType | EmbeddedObjKeysMapType;
|
|
30
|
+
/** @deprecated Use `arrayIdentityKeys` instead. */
|
|
28
31
|
embeddedObjKeys?: EmbeddedObjKeysType | EmbeddedObjKeysMapType;
|
|
29
32
|
keysToSkip?: readonly string[];
|
|
30
33
|
treatTypeChangeAsReplace?: boolean;
|
|
@@ -119,4 +122,99 @@ declare const enrich: (object: any) => IComparisonEnrichedNode;
|
|
|
119
122
|
declare const applyChangelist: (object: IComparisonEnrichedNode, changelist: IAtomicChange[]) => IComparisonEnrichedNode;
|
|
120
123
|
declare const compare: (oldObject: any, newObject: any) => IComparisonEnrichedNode;
|
|
121
124
|
|
|
122
|
-
|
|
125
|
+
type DeltaPathSegment = {
|
|
126
|
+
type: 'root';
|
|
127
|
+
} | {
|
|
128
|
+
type: 'property';
|
|
129
|
+
name: string;
|
|
130
|
+
} | {
|
|
131
|
+
type: 'index';
|
|
132
|
+
index: number;
|
|
133
|
+
} | {
|
|
134
|
+
type: 'keyFilter';
|
|
135
|
+
property: string;
|
|
136
|
+
value: unknown;
|
|
137
|
+
} | {
|
|
138
|
+
type: 'valueFilter';
|
|
139
|
+
value: unknown;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Format a value as a canonical JSON Delta filter literal.
|
|
143
|
+
* Strings → single-quoted with doubled-quote escaping.
|
|
144
|
+
* Numbers, booleans, null → plain JSON representation.
|
|
145
|
+
*/
|
|
146
|
+
declare function formatFilterLiteral(value: unknown): string;
|
|
147
|
+
/**
|
|
148
|
+
* Parse a filter literal string into a typed JS value.
|
|
149
|
+
* Reverse of formatFilterLiteral.
|
|
150
|
+
*/
|
|
151
|
+
declare function parseFilterLiteral(s: string): unknown;
|
|
152
|
+
/**
|
|
153
|
+
* Parse a JSON Delta Path string into an array of typed segments.
|
|
154
|
+
* Follows the grammar from the JSON Delta spec Section 5.1.
|
|
155
|
+
*/
|
|
156
|
+
declare function parseDeltaPath(path: string): DeltaPathSegment[];
|
|
157
|
+
/**
|
|
158
|
+
* Build a canonical JSON Delta Path string from an array of segments.
|
|
159
|
+
*/
|
|
160
|
+
declare function buildDeltaPath(segments: DeltaPathSegment[]): string;
|
|
161
|
+
|
|
162
|
+
type DeltaOp = 'add' | 'remove' | 'replace';
|
|
163
|
+
interface IDeltaOperation {
|
|
164
|
+
op: DeltaOp;
|
|
165
|
+
path: string;
|
|
166
|
+
value?: any;
|
|
167
|
+
oldValue?: any;
|
|
168
|
+
[key: string]: any;
|
|
169
|
+
}
|
|
170
|
+
interface IJsonDelta {
|
|
171
|
+
format: 'json-delta';
|
|
172
|
+
version: number;
|
|
173
|
+
operations: IDeltaOperation[];
|
|
174
|
+
[key: string]: any;
|
|
175
|
+
}
|
|
176
|
+
interface DeltaOptions extends Options {
|
|
177
|
+
/** Include oldValue for reversibility. Default: true */
|
|
178
|
+
reversible?: boolean;
|
|
179
|
+
}
|
|
180
|
+
declare function validateDelta(delta: unknown): {
|
|
181
|
+
valid: boolean;
|
|
182
|
+
errors: string[];
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Compute a canonical JSON Delta between two objects.
|
|
186
|
+
* This is the spec-conformant delta producer.
|
|
187
|
+
*/
|
|
188
|
+
declare function diffDelta(oldObj: any, newObj: any, options?: DeltaOptions): IJsonDelta;
|
|
189
|
+
/**
|
|
190
|
+
* Convert an existing v4 changeset or atomic changes to a JSON Delta document.
|
|
191
|
+
* Best-effort bridge — filter literals will always be string-quoted.
|
|
192
|
+
* Use `diffDelta()` for canonical spec-conformant output.
|
|
193
|
+
*/
|
|
194
|
+
declare function toDelta(changeset: Changeset | IAtomicChange[], options?: {
|
|
195
|
+
reversible?: boolean;
|
|
196
|
+
}): IJsonDelta;
|
|
197
|
+
/**
|
|
198
|
+
* Convert a JSON Delta document to v4 atomic changes.
|
|
199
|
+
* Returns IAtomicChange[] — one atom per delta operation.
|
|
200
|
+
* Use `unatomizeChangeset(fromDelta(delta))` if you need a hierarchical Changeset.
|
|
201
|
+
*/
|
|
202
|
+
declare function fromDelta(delta: IJsonDelta): IAtomicChange[];
|
|
203
|
+
/**
|
|
204
|
+
* Compute the inverse of a JSON Delta document (spec Section 9.2).
|
|
205
|
+
* Requires all replace/remove operations to have oldValue.
|
|
206
|
+
*/
|
|
207
|
+
declare function invertDelta(delta: IJsonDelta): IJsonDelta;
|
|
208
|
+
/**
|
|
209
|
+
* Apply a JSON Delta document to an object.
|
|
210
|
+
* Processes operations sequentially. Handles root operations directly.
|
|
211
|
+
* Returns the result (MUST use return value for root primitive replacements).
|
|
212
|
+
*/
|
|
213
|
+
declare function applyDelta(obj: any, delta: IJsonDelta): any;
|
|
214
|
+
/**
|
|
215
|
+
* Revert a JSON Delta by computing its inverse and applying it.
|
|
216
|
+
* Requires all replace/remove operations to have oldValue.
|
|
217
|
+
*/
|
|
218
|
+
declare function revertDelta(obj: any, delta: IJsonDelta): any;
|
|
219
|
+
|
|
220
|
+
export { type Changeset, CompareOperation, type DeltaOp, type DeltaOptions, type DeltaPathSegment, type EmbeddedObjKeysMapType, type EmbeddedObjKeysType, type IAtomicChange, type IChange, type IComparisonEnrichedNode, type IDeltaOperation, type IJsonDelta, Operation, type Options, applyChangelist, applyChangeset, applyDelta, atomizeChangeset, buildDeltaPath, compare, createContainer, createValue, diff, diffDelta, enrich, formatFilterLiteral, fromDelta, getTypeOfObj, invertDelta, parseDeltaPath, parseFilterLiteral, revertChangeset, revertDelta, toDelta, unatomizeChangeset, validateDelta };
|