@fgv/ts-json 5.0.0-24 → 5.0.0-25

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.
@@ -0,0 +1,2341 @@
1
+ import { Conversion } from '@fgv/ts-utils';
2
+ import { Converter } from '@fgv/ts-utils';
3
+ import { DetailedFailure } from '@fgv/ts-utils';
4
+ import { DetailedResult } from '@fgv/ts-utils';
5
+ import { JsonArray } from '@fgv/ts-json-base';
6
+ import { JsonObject } from '@fgv/ts-json-base';
7
+ import { JsonValue } from '@fgv/ts-json-base';
8
+ import { Result } from '@fgv/ts-utils';
9
+
10
+ /**
11
+ * Array merge behavior options for a {@link JsonEditor | JsonEditor}.
12
+ * @public
13
+ */
14
+ export declare type ArrayMergeBehavior = 'append' | 'replace';
15
+
16
+ /**
17
+ * A {@link CompositeJsonMap | CompositeJsonMap} presents a composed view of one or more other
18
+ * {@link IJsonReferenceMap | JSON reference maps}.
19
+ * @public
20
+ */
21
+ export declare class CompositeJsonMap implements IJsonReferenceMap {
22
+ /**
23
+ * The {@link IJsonReferenceMap | reference maps} from which this map is composed.
24
+ * @internal
25
+ */
26
+ protected _maps: IJsonReferenceMap[];
27
+ /**
28
+ * The {@link IJsonReferenceMap | reference maps} from which this map is to be composed.
29
+ * @param maps - An array o {@link IJsonReferenceMap | IJsonReferenceMap} containing the maps
30
+ * from which this map is to be composed.
31
+ * @internal
32
+ */
33
+ protected constructor(maps: IJsonReferenceMap[]);
34
+ /**
35
+ * Creates a new {@link CompositeJsonMap | CompositeJsonMap} from supplied
36
+ * {@link IJsonReferenceMap | maps}.
37
+ * @param maps - one or more {@link IJsonReferenceMap | object maps} to be composed.
38
+ */
39
+ static create(maps: IJsonReferenceMap[]): Result<CompositeJsonMap>;
40
+ /**
41
+ * Determine if a key might be valid for this map but does not determine
42
+ * if key actually exists. Allows key range to be constrained.
43
+ * @param key - The key to be tested.
44
+ * @returns `true` if the key is in the valid range, `false` otherwise.
45
+ */
46
+ keyIsInRange(key: string): boolean;
47
+ /**
48
+ * Determines if an object with the specified key actually exists in the map.
49
+ * @param key - The key to be tested.
50
+ * @returns `true` if an object with the specified key exists, `false` otherwise.
51
+ */
52
+ has(key: string): boolean;
53
+ /**
54
+ * Gets a JSON object specified by key.
55
+ * @param key - The key of the object to be retrieved.
56
+ * @param context - An optional {@link IJsonContext | JSON Context} used to format the object.
57
+ * @returns `Success` with the formatted object if successful. `Failure` with detail `'unknown'`
58
+ * if no such object exists, or `Failure` with detail `'error'` if the object was found but
59
+ * could not be formatted.
60
+ */
61
+ getJsonObject(key: string, context?: IJsonContext): DetailedResult<JsonObject, JsonReferenceMapFailureReason>;
62
+ /**
63
+ * Gets a JSON value specified by key.
64
+ * @param key - The key of the object to be retrieved.
65
+ * @param context - An optional {@link IJsonContext | JSON Context} used to format the value.
66
+ * @returns `Success` with the formatted object if successful. `Failure` with detail `'unknown'`
67
+ * if no such object exists, or failure with detail `'error'` if the object was found but
68
+ * could not be formatted.
69
+ */
70
+ getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
71
+ }
72
+
73
+ /**
74
+ * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
75
+ * supplied `unknown` to strongly-typed JSON, by first rendering any property
76
+ * names or string values using mustache with the supplied context, then applying
77
+ * multi-value property expansion and conditional flattening based on property names.
78
+ * @param options - {@link ConditionalJsonConverterOptions | Options and context} for
79
+ * the conversion.
80
+ * @public
81
+ */
82
+ declare function conditionalJson(options?: Partial<ConditionalJsonConverterOptions>): JsonConverter;
83
+
84
+ /**
85
+ * An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache
86
+ * template rendering, multi-value property name and conditional property
87
+ * name rules enabled regardless of initial context.
88
+ * @public
89
+ */
90
+ export declare class ConditionalJsonConverter extends JsonEditorConverter {
91
+ /**
92
+ * Default {@link IJsonConverterOptions | JSON converter options}
93
+ * to enable conditional conversion.
94
+ */
95
+ static readonly conditionalOptions: Partial<IJsonConverterOptions>;
96
+ /**
97
+ * Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or
98
+ * default options.
99
+ * @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}
100
+ * for the converter.
101
+ */
102
+ constructor(options?: Partial<ConditionalJsonConverterOptions>);
103
+ /**
104
+ * Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or
105
+ * default options.
106
+ * @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}
107
+ * for the converter.
108
+ */
109
+ static create(options?: Partial<ConditionalJsonConverterOptions>): Result<JsonConverter>;
110
+ }
111
+
112
+ /**
113
+ * Options for a {@link ConditionalJsonConverter | ConditionalJsonConverter}.
114
+ * @public
115
+ */
116
+ export declare type ConditionalJsonConverterOptions = Omit<TemplatedJsonConverterOptions, 'useConditionalNames'>;
117
+
118
+ /**
119
+ * The {@link EditorRules.ConditionalJsonEditorRule | ConditionalJsonEditorRule} evaluates
120
+ * properties with conditional keys, omitting non-matching keys and merging keys that match,
121
+ * or default keys only if no other keys match.
122
+ *
123
+ * The default syntax for a conditional key is:
124
+ * "?value1=value2" - matches if value1 and value2 are the same, is ignored otherwise.
125
+ * "?value" - matches if value is a non-empty, non-whitespace string. Is ignored otherwise.
126
+ * "?default" - matches only if no other conditional blocks in the same object were matched.
127
+ * @public
128
+ */
129
+ declare class ConditionalJsonEditorRule extends JsonEditorRuleBase {
130
+ /**
131
+ * Stored fully-resolved {@link EditorRules.IConditionalJsonRuleOptions | options} for this
132
+ * rule.
133
+ * @public
134
+ */
135
+ protected _options?: IConditionalJsonRuleOptions;
136
+ /**
137
+ * Creates a new {@link EditorRules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}.
138
+ * @param options - Optional {@link EditorRules.IConditionalJsonRuleOptions | configuration options}
139
+ * used for this rule.
140
+ */
141
+ constructor(options?: IConditionalJsonRuleOptions);
142
+ /**
143
+ * Creates a new {@link EditorRules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}.
144
+ * @param options - Optional {@link EditorRules.IConditionalJsonRuleOptions | configuration options}
145
+ * used for this rule.
146
+ */
147
+ static create(options?: IConditionalJsonRuleOptions): Result<ConditionalJsonEditorRule>;
148
+ /**
149
+ * Evaluates a property for conditional application.
150
+ * @param key - The key of the property to be considered
151
+ * @param value - The `JsonValue` of the property to be considered.
152
+ * @param state - The {@link JsonEditorState | editor state} for the object being edited.
153
+ * @returns Returns `Success` with detail `'deferred'` and a
154
+ * {@link EditorRules.IConditionalJsonDeferredObject | IConditionalJsonDeferredObject}.
155
+ * for a matching, default or unconditional key. Returns `Failure` with detail `'ignore'` for
156
+ * a non-matching conditional, or with detail `'error'` if an error occurs. Otherwise
157
+ * fails with detail `'inapplicable'`.
158
+ */
159
+ editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
160
+ /**
161
+ * Finalizes any deferred conditional properties. If the only deferred property is
162
+ * default, that property is emitted. Otherwise all matching properties are emitted.
163
+ * @param finalized - The deferred properties to be considered for merge.
164
+ * @param __state - The {@link JsonEditorState | editor state} for the object
165
+ * being edited.
166
+ */
167
+ finalizeProperties(finalized: JsonObject[], __state: JsonEditorState): DetailedResult<JsonObject[], JsonEditFailureReason>;
168
+ /**
169
+ * Determines if a given property key is conditional. Derived classes can override this
170
+ * method to use a different format for conditional properties.
171
+ * @param value - The `JsonValue` of the property to be considered.
172
+ * @param state - The {@link JsonEditorState | editor state} for the object being edited.
173
+ * @returns `Success` with detail `'deferred'` and a
174
+ * {@link EditorRules.IConditionalJsonKeyResult | IConditionalJsonKeyResult} describing the
175
+ * match for a default or matching conditional property. Returns `Failure` with detail `'ignore'`
176
+ * for a non-matching conditional property. Fails with detail `'error'` if an error occurs
177
+ * or with detail `'inapplicable'` if the key does not represent a conditional property.
178
+ * @public
179
+ */
180
+ protected _tryParseCondition(key: string, state: JsonEditorState): DetailedResult<IConditionalJsonKeyResult, JsonPropertyEditFailureReason>;
181
+ /**
182
+ * Compares two strings using a supplied operator.
183
+ * @param left - The first string to be compared.
184
+ * @param right - The second string to be compared.
185
+ * @param operator - The operator to be applied.
186
+ * @returns `true` if the condition is met, `false` otherwise.
187
+ * @internal
188
+ */
189
+ protected _compare(left: string, right: string, operator: string): boolean;
190
+ }
191
+
192
+ /**
193
+ * Creates a new {@link IJsonContext | JSON context} using values supplied in an optional partial
194
+ * {@link IJsonConverterOptions | converter options}.
195
+ * @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions} used to
196
+ * populate the context.
197
+ * @public
198
+ */
199
+ export declare function contextFromConverterOptions(partial?: Partial<IJsonConverterOptions>): IJsonContext | undefined;
200
+
201
+ /**
202
+ * Creates a new {@link JsonEditor | JsonEditor} from an optionally supplied partial
203
+ * {@link IJsonConverterOptions | JSON converter options}.
204
+ * Expands supplied options with default values and constructs an editor with
205
+ * matching configuration and defined rules.
206
+ * @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions}
207
+ * used to create the editor.
208
+ * @public
209
+ */
210
+ export declare function converterOptionsToEditor(partial?: Partial<IJsonConverterOptions>): Result<JsonEditor>;
211
+
212
+ declare namespace Converters {
213
+ export {
214
+ templatedJson,
215
+ conditionalJson,
216
+ richJson,
217
+ json,
218
+ jsonObject,
219
+ jsonArray
220
+ }
221
+ }
222
+ export { Converters }
223
+
224
+ /**
225
+ * This default implementation of a {@link TemplateVarsExtendFunction | TemplateVarsExtendFunction}
226
+ * creates a new collection via inheritance from the supplied collection.
227
+ * @param base - The base {@link TemplateVars | variables} to be extended.
228
+ * @param values - The {@link VariableValue | values} to be added or overridden in the new variables.
229
+ * @public
230
+ */
231
+ export declare function defaultExtendVars(base: TemplateVars | undefined, values: VariableValue[]): Result<TemplateVars | undefined>;
232
+
233
+ declare namespace Diff {
234
+ export {
235
+ jsonDiff,
236
+ jsonEquals,
237
+ DiffChangeType,
238
+ IDiffChange,
239
+ IDiffResult,
240
+ IJsonDiffOptions,
241
+ jsonThreeWayDiff,
242
+ IThreeWayDiffMetadata,
243
+ IThreeWayDiff
244
+ }
245
+ }
246
+ export { Diff }
247
+
248
+ /**
249
+ * JSON Diff Utilities for TypeScript
250
+ *
251
+ * This module provides comprehensive tools for comparing JSON values and identifying
252
+ * differences between them. It offers two complementary approaches:
253
+ *
254
+ * ## **Detailed Diff API** (`jsonDiff`)
255
+ * Best for analysis, debugging, and understanding specific changes:
256
+ * - Returns a list of individual changes with exact paths and values
257
+ * - Ideal for logging, change tracking, and detailed analysis
258
+ * - Configurable options for array handling and path notation
259
+ *
260
+ * ## **Three-Way Diff API** (`jsonThreeWayDiff`)
261
+ * Best for applying changes and programmatic manipulation:
262
+ * - Returns three objects representing removed, unchanged, and added data
263
+ * - Perfect for merging, UI displays, and actionable results
264
+ * - Treats arrays as atomic units for simpler handling
265
+ *
266
+ * ## **Simple Equality** (`jsonEquals`)
267
+ * Fast boolean check for JSON equality without change details.
268
+ *
269
+ * **Key Features:**
270
+ * - Deep recursive comparison of nested structures
271
+ * - Support for all JSON types: objects, arrays, primitives, null
272
+ * - TypeScript-first with comprehensive type safety
273
+ * - Result pattern for consistent error handling
274
+ * - Extensive TSDoc documentation with practical examples
275
+ *
276
+ * @example Quick comparison of the two main APIs
277
+ * ```typescript
278
+ * const before = { name: "John", age: 30, city: "NYC" };
279
+ * const after = { name: "Jane", age: 30, country: "USA" };
280
+ *
281
+ * // Detailed analysis
282
+ * const detailed = jsonDiff(before, after);
283
+ * // Returns: [
284
+ * // { path: "name", type: "modified", oldValue: "John", newValue: "Jane" },
285
+ * // { path: "city", type: "removed", oldValue: "NYC" },
286
+ * // { path: "country", type: "added", newValue: "USA" }
287
+ * // ]
288
+ *
289
+ * // Actionable objects
290
+ * const actionable = jsonThreeWayDiff(before, after);
291
+ * // Returns: {
292
+ * // onlyInA: { name: "John", city: "NYC" },
293
+ * // unchanged: { age: 30 },
294
+ * // onlyInB: { name: "Jane", country: "USA" }
295
+ * // }
296
+ *
297
+ * // Apply changes: { ...unchanged, ...onlyInB }
298
+ * // Revert changes: { ...unchanged, ...onlyInA }
299
+ * ```
300
+ */
301
+ /**
302
+ * Type of change detected in a JSON diff operation.
303
+ *
304
+ * - `'added'` - Property exists only in the second object
305
+ * - `'removed'` - Property exists only in the first object
306
+ * - `'modified'` - Property exists in both objects but with different values
307
+ * - `'unchanged'` - Property exists in both objects with identical values (only included when `includeUnchanged` is true)
308
+ *
309
+ * @public
310
+ */
311
+ declare type DiffChangeType = 'added' | 'removed' | 'modified' | 'unchanged';
312
+
313
+ declare namespace EditorRules {
314
+ export {
315
+ IConditionalJsonKeyResult,
316
+ IConditionalJsonDeferredObject,
317
+ IConditionalJsonRuleOptions,
318
+ ConditionalJsonEditorRule,
319
+ IMultiValuePropertyParts,
320
+ MultiValueJsonEditorRule,
321
+ ReferenceJsonEditorRule,
322
+ ITemplatedJsonRuleOptions,
323
+ TemplatedJsonEditorRule
324
+ }
325
+ }
326
+ export { EditorRules }
327
+
328
+ /**
329
+ * On a successful match, the {@link EditorRules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}
330
+ * stores a {@link EditorRules.IConditionalJsonDeferredObject | IConditionalJsonDeferredObject} describing the
331
+ * matching result, to be resolved at finalization time.
332
+ * @public
333
+ */
334
+ declare interface IConditionalJsonDeferredObject extends IConditionalJsonKeyResult {
335
+ value: JsonValue;
336
+ }
337
+
338
+ /**
339
+ * Returned by {@link EditorRules.ConditionalJsonEditorRule._tryParseCondition | ConditionalJsonEditorRule._tryParseCondition}
340
+ * to indicate whether a successful match was due to a matching condition or a default value.
341
+ * @public
342
+ */
343
+ declare interface IConditionalJsonKeyResult extends JsonObject {
344
+ matchType: 'default' | 'match' | 'unconditional';
345
+ }
346
+
347
+ /**
348
+ * Configuration options for the {@link EditorRules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}.
349
+ * @public
350
+ */
351
+ declare interface IConditionalJsonRuleOptions extends Partial<IJsonEditorOptions> {
352
+ /**
353
+ * If true (default) then properties with unconditional names
354
+ * (which start with !) are flattened.
355
+ */
356
+ flattenUnconditionalValues?: boolean;
357
+ }
358
+
359
+ /**
360
+ * Represents a single change in a JSON diff operation.
361
+ *
362
+ * Each change describes a specific difference between two JSON values, including
363
+ * the location of the change and the old/new values involved.
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * // Example changes from diffing { name: "John", age: 30 } vs { name: "Jane", city: "NYC" }
368
+ * const changes: IDiffChange[] = [
369
+ * { path: "name", type: "modified", oldValue: "John", newValue: "Jane" },
370
+ * { path: "age", type: "removed", oldValue: 30 },
371
+ * { path: "city", type: "added", newValue: "NYC" }
372
+ * ];
373
+ * ```
374
+ *
375
+ * @public
376
+ */
377
+ declare interface IDiffChange {
378
+ /**
379
+ * The path to the changed value using dot notation.
380
+ *
381
+ * For nested objects, uses dots to separate levels (e.g., "user.profile.name").
382
+ * For arrays, uses numeric indices (e.g., "items.0.id", "tags.2").
383
+ * Empty string indicates the root value itself changed.
384
+ *
385
+ * @example "user.name", "items.0.id", "settings.theme", ""
386
+ */
387
+ path: string;
388
+ /**
389
+ * The type of change that occurred.
390
+ *
391
+ * @see {@link DiffChangeType} for detailed descriptions of each change type.
392
+ */
393
+ type: DiffChangeType;
394
+ /**
395
+ * The value in the first object.
396
+ *
397
+ * - Present for `'removed'` and `'modified'` changes
398
+ * - Present for `'unchanged'` changes when `includeUnchanged` is true
399
+ * - Undefined for `'added'` changes
400
+ */
401
+ oldValue?: JsonValue;
402
+ /**
403
+ * The value in the second object.
404
+ *
405
+ * - Present for `'added'` and `'modified'` changes
406
+ * - Present for `'unchanged'` changes when `includeUnchanged` is true
407
+ * - Undefined for `'removed'` changes
408
+ */
409
+ newValue?: JsonValue;
410
+ }
411
+
412
+ /**
413
+ * Result of a JSON diff operation containing all detected changes.
414
+ *
415
+ * This interface provides detailed information about every difference found
416
+ * between two JSON values, making it ideal for analysis, debugging, and
417
+ * understanding exactly what changed.
418
+ *
419
+ * @example
420
+ * ```typescript
421
+ * const result: IDiffResult = {
422
+ * changes: [
423
+ * { path: "name", type: "modified", oldValue: "John", newValue: "Jane" },
424
+ * { path: "hobbies.1", type: "added", newValue: "gaming" }
425
+ * ],
426
+ * identical: false
427
+ * };
428
+ * ```
429
+ *
430
+ * @see {@link IDiffChange} for details about individual change objects
431
+ * @see {@link Diff.jsonDiff} for the function that produces this result
432
+ * @public
433
+ */
434
+ declare interface IDiffResult {
435
+ /**
436
+ * Array of all changes detected between the two JSON objects.
437
+ *
438
+ * Changes are ordered by the path where they occur. For nested structures,
439
+ * parent changes appear before child changes.
440
+ */
441
+ changes: IDiffChange[];
442
+ /**
443
+ * True if the objects are identical, false otherwise.
444
+ *
445
+ * When true, the `changes` array will be empty (unless `includeUnchanged`
446
+ * option was used, in which case it may contain 'unchanged' entries).
447
+ */
448
+ identical: boolean;
449
+ }
450
+
451
+ /**
452
+ * A specialized JSON editor which does a deep clone of a supplied `JsonValue`.
453
+ * @public
454
+ */
455
+ export declare interface IJsonCloneEditor {
456
+ /**
457
+ * Returns a deep clone of a supplied `JsonValue`.
458
+ * @param src - The `JsonValue` to be cloned.
459
+ * @param context - An optional {@link IJsonContext | JSON context} used for clone
460
+ * conversion operations.
461
+ */
462
+ clone(src: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonEditFailureReason>;
463
+ }
464
+
465
+ /**
466
+ * Context used to convert or edit JSON objects.
467
+ * @public
468
+ */
469
+ export declare interface IJsonContext {
470
+ vars?: TemplateVars;
471
+ refs?: IJsonReferenceMap;
472
+ extendVars?: TemplateVarsExtendFunction;
473
+ }
474
+
475
+ /**
476
+ * Conversion options for {@link JsonConverter | JsonConverter}.
477
+ * @public
478
+ */
479
+ export declare interface IJsonConverterOptions {
480
+ /**
481
+ * If `true` and if template variables are available,
482
+ * then string property values will be rendered using
483
+ * mustache and those variable values. Otherwise string
484
+ * properties are copied without modification.
485
+ *
486
+ * Defaults to `true` if vars are supplied with options,
487
+ * `false` otherwise.
488
+ */
489
+ useValueTemplates: boolean;
490
+ /**
491
+ * If `true` and if template variables are available,
492
+ * then property names will be rendered using
493
+ * mustache and those variable values. Otherwise
494
+ * property names are copied without modification.
495
+ *
496
+ * Defaults to `true` if vars are supplied with options,
497
+ * `false` otherwise.
498
+ */
499
+ useNameTemplates: boolean;
500
+ /**
501
+ * If `true` and if template variables are available,
502
+ * then string property names will be considered for
503
+ * conditionals.
504
+ *
505
+ * Default is to match {@link IJsonConverterOptions.useNameTemplates | useNameTemplates}.
506
+ */
507
+ useConditionalNames: boolean;
508
+ /**
509
+ * If `true` (default) then properties with unconditional names
510
+ * (which start with !) are flattened.
511
+ */
512
+ flattenUnconditionalValues: boolean;
513
+ /**
514
+ * If `true` and if both template variables and a
515
+ * context derivation function is available, then properties
516
+ * which match the multi-value name pattern will be expanded.
517
+ * Default matches {@link IJsonConverterOptions.useNameTemplates | useNameTemplates}.
518
+ *
519
+ * Default is `true` unless {@link IJsonConverterOptions.extendVars | extendVars} is
520
+ * explicitly set to `undefined`.
521
+ */
522
+ useMultiValueTemplateNames: boolean;
523
+ /**
524
+ * The variables (mustache view) used to render templated string names
525
+ * and properties. See the mustache documentation for details of mustache
526
+ * syntax and the template view.
527
+ */
528
+ vars?: TemplateVars;
529
+ /**
530
+ * Method used to extend variables for children of an array node during
531
+ * expansion. Default is to use a built-in extension function unless
532
+ * {@link IJsonConverterOptions.extendVars | extendVars} is explicitly set to undefined.
533
+ */
534
+ extendVars?: TemplateVarsExtendFunction;
535
+ /**
536
+ * If `true` and if a {@link IJsonReferenceMap | references map} is supplied
537
+ * in {@link IJsonConverterOptions.refs | refs}, then references in the source
538
+ * object will be replaced with the corresponding value from the reference map.
539
+ *
540
+ * Default is `true` if {@link IJsonConverterOptions.refs | refs} are present in options,
541
+ * `false` otherwise.
542
+ */
543
+ useReferences: boolean;
544
+ /**
545
+ * An optional {@link IJsonReferenceMap | reference map} used to insert any references
546
+ * in the converted JSON.
547
+ */
548
+ refs?: IJsonReferenceMap;
549
+ /**
550
+ * If {@link IJsonConverterOptions.onInvalidPropertyName | onInvalidPropertyName} is `'error'`
551
+ * (default) then any property name that is invalid after template rendering causes an error
552
+ * and stops conversion. If {@link IJsonConverterOptions.onInvalidPropertyName | onInvalidPropertyName}
553
+ * is `'ignore'`, then names which are invalid after template rendering are passed through unchanged.
554
+ */
555
+ onInvalidPropertyName: 'error' | 'ignore';
556
+ /**
557
+ * If {@link IJsonConverterOptions.onInvalidPropertyValue | onInvalidPropertyValue} is `'error'`
558
+ * (default) then any illegal property value causes an error and stops conversion. If
559
+ * {@link IJsonConverterOptions.onInvalidPropertyValue | onInvalidPropertyValue} is `'ignore'` then
560
+ * any invalid property values are silently ignored.
561
+ */
562
+ onInvalidPropertyValue: 'error' | 'ignore';
563
+ /**
564
+ * If {@link IJsonConverterOptions.onUndefinedPropertyValue | onUndefinedPropertyValue} is `'error'`,
565
+ * then any property with value `undefined` will cause an error and stop conversion. If
566
+ * {@link IJsonConverterOptions.onUndefinedPropertyValue | onUndefinedPropertyValue} is `'ignore'` (default)
567
+ * then any property with value `undefined` is silently ignored.
568
+ */
569
+ onUndefinedPropertyValue: 'error' | 'ignore';
570
+ }
571
+
572
+ /**
573
+ * Options for customizing JSON diff behavior.
574
+ *
575
+ * These options allow you to control how the diff algorithm processes
576
+ * different types of JSON structures and what information is included
577
+ * in the results.
578
+ *
579
+ * @example
580
+ * ```typescript
581
+ * // Include unchanged values and use custom path separator
582
+ * const options: IJsonDiffOptions = {
583
+ * includeUnchanged: true,
584
+ * pathSeparator: '/',
585
+ * arrayOrderMatters: false
586
+ * };
587
+ *
588
+ * const result = jsonDiff(obj1, obj2, options);
589
+ * ```
590
+ *
591
+ * @public
592
+ */
593
+ declare interface IJsonDiffOptions {
594
+ /**
595
+ * If true, includes unchanged values in the result.
596
+ *
597
+ * When enabled, the diff result will include entries with `type: 'unchanged'`
598
+ * for properties that exist in both objects with identical values. This can
599
+ * be useful for displaying complete side-by-side comparisons.
600
+ *
601
+ * @defaultValue false
602
+ */
603
+ includeUnchanged?: boolean;
604
+ /**
605
+ * Custom path separator for nested property paths.
606
+ *
607
+ * Controls the character used to separate levels in nested object paths.
608
+ * For example, with separator `'/'`, a nested property would be reported
609
+ * as `"user/profile/name"` instead of `"user.profile.name"`.
610
+ *
611
+ * @defaultValue "."
612
+ * @example "/", "-\>", "::"
613
+ */
614
+ pathSeparator?: string;
615
+ /**
616
+ * If true, treats arrays as ordered lists where position matters.
617
+ * If false, treats arrays as unordered sets.
618
+ *
619
+ * When `true` (default), array changes are reported by index position:
620
+ * `[1,2,3]` vs `[1,3,2]` shows modifications at indices 1 and 2.
621
+ *
622
+ * When `false`, arrays are compared as sets: `[1,2,3]` vs `[1,3,2]`
623
+ * may be considered equivalent (simplified unordered comparison).
624
+ *
625
+ * @defaultValue true
626
+ */
627
+ arrayOrderMatters?: boolean;
628
+ }
629
+
630
+ /**
631
+ * Merge options for a {@link JsonEditor | JsonEditor}.
632
+ * @public
633
+ */
634
+ export declare interface IJsonEditorMergeOptions {
635
+ /**
636
+ * Controls how arrays are merged when combining JSON values.
637
+ * - `'append'` (default): Existing array elements are preserved and new elements are appended
638
+ * - `'replace'`: Existing array is completely replaced with the new array
639
+ */
640
+ arrayMergeBehavior: ArrayMergeBehavior;
641
+ /**
642
+ * Controls whether null values should be treated as property deletion during merge operations.
643
+ * - `false` (default): Null values are merged normally, setting the property to null
644
+ * - `true`: Null values delete the property from the target object during merge
645
+ */
646
+ nullAsDelete?: boolean;
647
+ }
648
+
649
+ /**
650
+ * Initialization options for a {@link JsonEditor | JsonEditor}.
651
+ * @public
652
+ */
653
+ export declare interface IJsonEditorOptions {
654
+ context?: IJsonContext;
655
+ validation: IJsonEditorValidationOptions;
656
+ merge?: IJsonEditorMergeOptions;
657
+ }
658
+
659
+ /**
660
+ * An {@link IJsonEditorRule | IJsonEditorRule} represents a single configurable
661
+ * rule to be applied by a {@link JsonEditor | JsonEditor}.
662
+ * @public
663
+ */
664
+ export declare interface IJsonEditorRule {
665
+ /**
666
+ * Called by a {@link JsonEditor | JsonEditor} to possibly edit one of the properties being
667
+ * merged into a target object.
668
+ * @param key - The key of the property to be edited.
669
+ * @param value - The `JsonValue` of the property to be edited.
670
+ * @param state - {@link JsonEditorState | Editor state} which applies to the edit.
671
+ * @returns If the property was edited, returns `Success` with a `JsonObject` containing
672
+ * the edited results and with detail `'edited'`. If this property should be deferred for later consideration
673
+ * or merge, `Success` with detail `'deferred'` and a `JsonObject` to be finalized. If
674
+ * the rule does not affect this property, returns `Failure` with detail `'inapplicable'`. If an error occurred
675
+ * while processing the error, returns `Failure` with detail `'error'`.
676
+ */
677
+ editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
678
+ /**
679
+ * Called by a {@link JsonEditor | JsonEditor} to possibly edit a property value or array element.
680
+ * @param value - The `JsonValue` of the property to be edited.
681
+ * @param state - {@link JsonEditorState | Editor state} which applies to the edit.
682
+ * @returns Returns `Success` with the `JsonValue` to be inserted, with detail `'edited'` if
683
+ * the value was edited. Returns `Failure` with `'inapplicable'` if the rule does not affect this value.
684
+ * Fails with detail `'ignore'` if the value is to be ignored, or with `'error'` if an error occurs.
685
+ */
686
+ editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
687
+ /**
688
+ * Called for each rule after all properties have been merged. Any properties that were deferred
689
+ * during the initial edit pass are supplied as input.
690
+ * @param deferred - Any JSON objects that were deferred during the first edit pass.
691
+ * @param state - {@link JsonEditorState | Editor state} which applies to the edit.
692
+ * @returns On `Success` return, any returned objects are merged in order and finalization
693
+ * is stopped. Finalization is also stopped on `Failure` with detail `'ignore'`. On `Failure`
694
+ * with detail `'inapplicable'`, finalization continues with the next rule. Fails with an
695
+ * error detail `'error'` and an informative message if an error occurs.
696
+ */
697
+ finalizeProperties(deferred: JsonObject[], state: JsonEditorState): DetailedResult<JsonObject[], JsonEditFailureReason>;
698
+ }
699
+
700
+ /**
701
+ * Validation options for a {@link JsonEditor | JsonEditor}.
702
+ * @public
703
+ */
704
+ export declare interface IJsonEditorValidationOptions {
705
+ /**
706
+ * If `onInvalidPropertyName` is `'error'` (default) then any property name
707
+ * that is invalid after template rendering causes an error and stops
708
+ * conversion. If `onInvalidPropertyName` is `'ignore'`, then names which
709
+ * are invalid after template rendering are passed through unchanged.
710
+ */
711
+ onInvalidPropertyName: 'error' | 'ignore';
712
+ /**
713
+ * If `onInvalidPropertyValue` is `'error'` (default) then any illegal
714
+ * property value other than `undefined` causes an error and stops
715
+ * conversion. If `onInvalidPropertyValue` is `'ignore'` then any
716
+ * invalid property values are silently ignored.
717
+ */
718
+ onInvalidPropertyValue: 'error' | 'ignore';
719
+ /**
720
+ * If `onUndefinedPropertyValue` is `'error'`, then any property with
721
+ * value `undefined` will cause an error and stop conversion. If
722
+ * `onUndefinedPropertyValue` is `'ignore'` (default) then any
723
+ * property with value `undefined` is silently ignored.
724
+ */
725
+ onUndefinedPropertyValue: 'error' | 'ignore';
726
+ }
727
+
728
+ /**
729
+ * Interface for a simple map that returns named `JsonValue` values with templating,
730
+ * conditional logic, and external reference lookups applied using an optionally supplied context.
731
+ * @public
732
+ */
733
+ export declare interface IJsonReferenceMap {
734
+ /**
735
+ * Determine if a key might be valid for this map but does not determine if key actually
736
+ * exists. Allows key range to be constrained.
737
+ * @param key - The key to be tested.
738
+ * @returns `true` if the key is in the valid range, `false` otherwise.
739
+ */
740
+ keyIsInRange(key: string): boolean;
741
+ /**
742
+ * Determines if an object with the specified key actually exists in the map.
743
+ * @param key - The key to be tested.
744
+ * @returns `true` if an object with the specified key exists, `false` otherwise.
745
+ */
746
+ has(key: string): boolean;
747
+ /**
748
+ * Gets a `JsonObject` specified by key.
749
+ * @param key - The key of the object to be retrieved.
750
+ * @param context - Optional {@link IJsonContext | IJsonContext} used to construct
751
+ * the object.
752
+ * @returns `Success` with the formatted JsonObject if successful. `Failure`
753
+ * with detail `'unknown'` if no such object exists, or `Failure` with detail `'error'` if
754
+ * the object was found but could not be formatted.
755
+ */
756
+ getJsonObject(key: string, context?: IJsonContext): DetailedResult<JsonObject, JsonReferenceMapFailureReason>;
757
+ /**
758
+ * Gets a `JsonValue` specified by key.
759
+ * @param key - The key of the object to be retrieved.
760
+ * @param context - Optional {@link IJsonContext | JSON Context} used to format the value
761
+ * @returns `Success` with the formatted `JsonValue` if successful. `Failure`
762
+ * with detail `'unknown'` if no such object exists, or `Failure` with detail `'error'` if
763
+ * the object was found but could not be formatted.
764
+ */
765
+ getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
766
+ }
767
+
768
+ /**
769
+ * Initialization options for a {@link PrefixedJsonMap | PrefixedJsonMap}
770
+ * @public
771
+ */
772
+ declare interface IKeyPrefixOptions {
773
+ /**
774
+ * Indicates whether the prefix should be added automatically as needed (default true)
775
+ */
776
+ addPrefix?: boolean;
777
+ /**
778
+ * The prefix to be enforced
779
+ */
780
+ prefix: string;
781
+ }
782
+
783
+ /**
784
+ * Represents the parts of a multi-value property key.
785
+ * @public
786
+ */
787
+ declare interface IMultiValuePropertyParts {
788
+ /**
789
+ * The original matched token.
790
+ */
791
+ readonly token: string;
792
+ /**
793
+ * The name of the variable used to project each possible
794
+ * property value into the child values or objects being
795
+ * resolved.
796
+ */
797
+ readonly propertyVariable: string;
798
+ /**
799
+ * The set of property values to be expanded.
800
+ */
801
+ readonly propertyValues: string[];
802
+ /**
803
+ * If `true`, the resolved values are added as an array
804
+ * with the name of the {@link EditorRules.IMultiValuePropertyParts.propertyVariable | propertyVariable}.
805
+ * If false, values are added as individual properties with names that correspond the value.
806
+ */
807
+ readonly asArray: boolean;
808
+ }
809
+
810
+ /**
811
+ * Options for creating a {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} object.
812
+ * @public
813
+ */
814
+ export declare interface IReferenceMapKeyPolicyValidateOptions {
815
+ /**
816
+ * If `true`, the validator coerces keys to some valid value.
817
+ * If `false`, invalid keys cause an error.
818
+ */
819
+ makeValid?: boolean;
820
+ }
821
+
822
+ /**
823
+ * Initialization options for a {@link SimpleJsonMap | SimpleJsonMap}.
824
+ * @public
825
+ */
826
+ export declare interface ISimpleJsonMapOptions {
827
+ keyPolicy?: ReferenceMapKeyPolicy<JsonValue>;
828
+ editor?: JsonEditor;
829
+ }
830
+
831
+ /**
832
+ * Configuration options for the {@link EditorRules.TemplatedJsonEditorRule | Templated JSON editor rule}.
833
+ * @public
834
+ */
835
+ declare interface ITemplatedJsonRuleOptions extends Partial<IJsonEditorOptions> {
836
+ /**
837
+ * If `true` (default) then templates in property names are rendered
838
+ */
839
+ useNameTemplates?: boolean;
840
+ /**
841
+ * If `true` (default) then templates in property values are rendered
842
+ */
843
+ useValueTemplates?: boolean;
844
+ }
845
+
846
+ /**
847
+ * Result of a three-way JSON diff operation.
848
+ *
849
+ * This interface provides an actionable representation of differences between
850
+ * two JSON values by separating them into three distinct objects. This approach
851
+ * makes it easy to apply changes, display side-by-side comparisons, perform
852
+ * merges, or programmatically work with the differences.
853
+ *
854
+ * **Key Benefits:**
855
+ * - **Actionable Results**: Objects can be directly used for merging or applying changes
856
+ * - **UI-Friendly**: Perfect for side-by-side diff displays with clear visual separation
857
+ * - **Merge-Ready**: Simplified three-way merge operations
858
+ * - **Structured Data**: Maintains original JSON structure rather than flattened paths
859
+ *
860
+ * @example Basic usage
861
+ * ```typescript
862
+ * const result: IThreeWayDiff = {
863
+ * onlyInA: { name: "John", city: "NYC" }, // Original or removed data
864
+ * unchanged: { age: 30 }, // Stable data
865
+ * onlyInB: { name: "Jane", country: "USA" }, // New or modified data
866
+ * metadata: { added: 1, removed: 1, modified: 1, unchanged: 1 },
867
+ * identical: false
868
+ * };
869
+ *
870
+ * // Apply changes: merge unchanged + onlyInB
871
+ * const updated = { ...result.unchanged, ...result.onlyInB };
872
+ * // Result: { age: 30, name: "Jane", country: "USA" }
873
+ *
874
+ * // Revert changes: merge unchanged + onlyInA
875
+ * const reverted = { ...result.unchanged, ...result.onlyInA };
876
+ * // Result: { age: 30, name: "John", city: "NYC" }
877
+ * ```
878
+ *
879
+ * @see {@link IThreeWayDiffMetadata} for metadata structure details
880
+ * @see {@link jsonThreeWayDiff} for the function that produces this result
881
+ * @see {@link Diff.jsonDiff} for an alternative detailed change-list approach
882
+ *
883
+ * @public
884
+ */
885
+ declare interface IThreeWayDiff {
886
+ /**
887
+ * Contains properties that exist only in the first object, plus the first object's
888
+ * version of any properties that exist in both but have different values.
889
+ *
890
+ * This object represents the "old" or "source" state and can be used for:
891
+ * - Reverting changes by merging with `unchanged`
892
+ * - Displaying what was removed or changed from the original
893
+ * - Understanding the baseline state before modifications
894
+ *
895
+ * Will be `null` if no properties are unique to the first object.
896
+ */
897
+ onlyInA: JsonValue;
898
+ /**
899
+ * Contains properties that exist in both objects with identical values.
900
+ *
901
+ * This object represents the stable, consistent data between both inputs
902
+ * and can be used for:
903
+ * - The foundation for merging operations
904
+ * - Identifying what remained constant during changes
905
+ * - Building complete objects by combining with other parts
906
+ *
907
+ * Will be `null` if no properties are shared between the objects.
908
+ */
909
+ unchanged: JsonValue;
910
+ /**
911
+ * Contains properties that exist only in the second object, plus the second object's
912
+ * version of any properties that exist in both but have different values.
913
+ *
914
+ * This object represents the "new" or "target" state and can be used for:
915
+ * - Applying changes by merging with `unchanged`
916
+ * - Displaying what was added or changed in the update
917
+ * - Understanding the desired end state after modifications
918
+ *
919
+ * Will be `null` if no properties are unique to the second object.
920
+ */
921
+ onlyInB: JsonValue;
922
+ /**
923
+ * Summary metadata about the differences found.
924
+ *
925
+ * Provides counts of added, removed, modified, and unchanged properties
926
+ * for quick assessment of the scope and nature of changes.
927
+ */
928
+ metadata: IThreeWayDiffMetadata;
929
+ /**
930
+ * True if the objects are identical, false otherwise.
931
+ *
932
+ * When `true`, both `onlyInA` and `onlyInB` will be `null`, and `unchanged`
933
+ * will contain the complete shared structure. The metadata will show zero
934
+ * added, removed, and modified properties.
935
+ */
936
+ identical: boolean;
937
+ }
938
+
939
+ /**
940
+ * Metadata about the differences found in a three-way diff.
941
+ *
942
+ * Provides summary statistics about the types and quantities of changes
943
+ * detected between two JSON values, making it easy to understand the
944
+ * overall scope of differences at a glance.
945
+ *
946
+ * @example
947
+ * ```typescript
948
+ * const metadata: IThreeWayDiffMetadata = {
949
+ * removed: 2, // 2 properties only in first object
950
+ * added: 1, // 1 property only in second object
951
+ * modified: 3, // 3 properties changed between objects
952
+ * unchanged: 5 // 5 properties identical in both objects
953
+ * };
954
+ *
955
+ * console.log(`Total changes: ${metadata.added + metadata.removed + metadata.modified}`);
956
+ * console.log(`Stability: ${metadata.unchanged / (metadata.unchanged + metadata.modified) * 100}%`);
957
+ * ```
958
+ *
959
+ * @public
960
+ */
961
+ declare interface IThreeWayDiffMetadata {
962
+ /**
963
+ * Number of properties that exist only in the first object.
964
+ *
965
+ * These represent data that was removed when transitioning from
966
+ * the first object to the second object.
967
+ */
968
+ removed: number;
969
+ /**
970
+ * Number of properties that exist only in the second object.
971
+ *
972
+ * These represent new data that was added when transitioning from
973
+ * the first object to the second object.
974
+ */
975
+ added: number;
976
+ /**
977
+ * Number of properties that exist in both objects but have different values.
978
+ *
979
+ * These represent data that was modified during the transition between objects.
980
+ * For arrays, this counts entire array replacements as single modifications.
981
+ */
982
+ modified: number;
983
+ /**
984
+ * Number of properties that exist in both objects with identical values.
985
+ *
986
+ * These represent stable data that remained consistent between the two objects.
987
+ */
988
+ unchanged: number;
989
+ }
990
+
991
+ /**
992
+ * A simple validating {@link JsonConverter | JSON converter}. Converts unknown to
993
+ * JSON or fails if the unknown contains any invalid JSON values.
994
+ * @public
995
+ */
996
+ declare const json: JsonConverter;
997
+
998
+ /**
999
+ * A simple validating {@link JsonConverter | JSON converter}. Converts `unknown` to a
1000
+ * `JsonArray`, or fails if the unknown contains invalid JSON or is
1001
+ * not an array.
1002
+ * @public
1003
+ */
1004
+ declare const jsonArray: Converter<JsonArray, IJsonContext>;
1005
+
1006
+ /**
1007
+ * Helper class for working with {@link IJsonContext | IJsonContext} objects.
1008
+ * @public
1009
+ */
1010
+ export declare class JsonContextHelper {
1011
+ /**
1012
+ * The base {@link IJsonContext | context} on which we are operating.
1013
+ * @internal
1014
+ */
1015
+ protected _context?: IJsonContext;
1016
+ /**
1017
+ * Constructs a new {@link JsonContextHelper | JsonContextHelper}.
1018
+ * @param context - The base {@link IJsonContext | IJsonContext} on
1019
+ * which to operate.
1020
+ */
1021
+ constructor(context?: IJsonContext);
1022
+ /**
1023
+ * Creates a new {@link IJsonContext | context}.
1024
+ * @param context - The base {@link IJsonContext | IJsonContext} on
1025
+ * which to operate.
1026
+ * @returns `Success` with the new {@link IJsonContext | IJsonContext},
1027
+ * or `Failure` with more information if an error occurs.
1028
+ */
1029
+ static create(context?: IJsonContext): Result<JsonContextHelper>;
1030
+ /**
1031
+ * Static helper to extend context variables for a supplied {@link IJsonContext | IJsonContext}.
1032
+ * @param baseContext - The {@link IJsonContext | IJsonContext} to be extended, or `undefined`
1033
+ * to start from an empty context.
1034
+ * @param vars - Optional {@link VariableValue | variable values} to be added to the
1035
+ * {@link IJsonContext | context}.
1036
+ * @returns `Success` with a new {@link TemplateVars | TemplateVars} containing the variables
1037
+ * from the base context, merged with and overridden by any that were passed in, or `Failure`
1038
+ * with a message if an error occurs.
1039
+ */
1040
+ static extendContextVars(baseContext: IJsonContext | undefined, vars?: VariableValue[]): Result<TemplateVars | undefined>;
1041
+ /**
1042
+ * Static helper to extend context references for a supplied {@link IJsonContext | IJsonContext}.
1043
+ * @param baseContext - The {@link IJsonContext | IJsonContext} to be extended, or `undefined`
1044
+ * to start from an empty context.
1045
+ * @param refs - Optional {@link IJsonReferenceMap | reference maps} to be added to the
1046
+ * {@link IJsonContext | context}.
1047
+ * @returns `Success` with a new {@link IJsonReferenceMap | reference map} which projects
1048
+ * the references from the base context, merged with and overridden by any that were passed in,
1049
+ * or `Failure` with a message if an error occurs.
1050
+ */
1051
+ static extendContextRefs(baseContext: IJsonContext | undefined, refs?: IJsonReferenceMap[]): Result<IJsonReferenceMap | undefined>;
1052
+ /**
1053
+ * Static helper to extend context variables and references for a supplied {@link IJsonContext | IJsonContext}.
1054
+ * @param baseContext - The {@link IJsonContext | IJsonContext} to be extended, or `undefined`
1055
+ * to start from an empty context.
1056
+ * @param add - Optional initializer containing {@link VariableValue | variable values} and/or
1057
+ * {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
1058
+ * @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
1059
+ * references from the base context, merged with and overridden by any that were passed in, or
1060
+ * `Failure` with a message if an error occurs.
1061
+ */
1062
+ static extendContext(baseContext?: IJsonContext | undefined, add?: {
1063
+ vars?: VariableValue[];
1064
+ refs?: IJsonReferenceMap[];
1065
+ }): Result<IJsonContext | undefined>;
1066
+ /**
1067
+ * Static helper to merge context variables and references for a supplied {@link IJsonContext | IJsonContext}.
1068
+ * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables and references
1069
+ * are to be merged, or `undefined` to start from an empty context.
1070
+ * @param add - Optional initializer containing {@link VariableValue | variable values} and/or
1071
+ * {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
1072
+ * @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
1073
+ * references from the base context, merged with and overridden by any that were passed in, or
1074
+ * `Failure` with a message if an error occurs.
1075
+ */
1076
+ static mergeContext(baseContext: IJsonContext | undefined, add: IJsonContext | undefined): Result<IJsonContext | undefined>;
1077
+ /**
1078
+ * Applies {@link JsonContextHelper.extendContextVars | extendContextVars} to the
1079
+ * {@link IJsonContext | IJsonContext} associated with this helper.
1080
+ * @param vars - Optional {@link VariableValue | variable values} to be added to the
1081
+ * @returns `Success` with a new {@link TemplateVars | TemplateVars} containing the variables
1082
+ * from the base context, merged with and overridden by any that were passed in, or `Failure`
1083
+ * with a message if an error occurs.
1084
+ */
1085
+ extendVars(vars?: VariableValue[]): Result<TemplateVars | undefined>;
1086
+ /**
1087
+ * Applies {@link JsonContextHelper.extendContextRefs | extendContextRefs} to the
1088
+ * {@link IJsonContext | IJsonContext} associated with this helper.
1089
+ * @param refs - Optional {@link IJsonReferenceMap | reference maps} to be added to the
1090
+ * @returns `Success` with a new {@link IJsonReferenceMap | reference map} which projects
1091
+ * the references from the base context, merged with and overridden by any that were passed in,
1092
+ * or `Failure` with a message if an error occurs.
1093
+ */
1094
+ extendRefs(refs?: IJsonReferenceMap[]): Result<IJsonReferenceMap | undefined>;
1095
+ /**
1096
+ * Applies static `JsonContextHelper.extendContext` to the
1097
+ * {@link IJsonContext | IJsonContext} associated with this helper.
1098
+ * @param add - Optional initializer containing {@link VariableValue | variable values} and/or
1099
+ * {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
1100
+ * @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
1101
+ * references from the base context, merged with and overridden by any that were passed in, or
1102
+ * `Failure` with a message if an error occurs.
1103
+ */
1104
+ extendContext(add?: {
1105
+ vars?: VariableValue[];
1106
+ refs?: IJsonReferenceMap[];
1107
+ }): Result<IJsonContext | undefined>;
1108
+ /**
1109
+ * Applies static `JsonContextHelper.mergeContext` to the
1110
+ * {@link IJsonContext | IJsonContext} associated with this helper.
1111
+ * @param add - Optional initializer containing {@link VariableValue | variable values} and/or
1112
+ * {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
1113
+ * @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
1114
+ * references from the base context, merged with and overridden by any that were passed in, or
1115
+ * `Failure` with a message if an error occurs.
1116
+ */
1117
+ mergeContext(merge?: IJsonContext): Result<IJsonContext | undefined>;
1118
+ }
1119
+
1120
+ /**
1121
+ * An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON, optionally
1122
+ * rendering any string property names or values using mustache with a supplied view.
1123
+ * @public
1124
+ */
1125
+ export declare class JsonConverter extends JsonEditorConverter {
1126
+ /**
1127
+ * Constructs a new {@link JsonConverter | JsonConverter} with
1128
+ * supplied or default options.
1129
+ * @param options - Optional partial {@link IJsonConverterOptions | options}
1130
+ * to configure the converter.
1131
+ */
1132
+ constructor(options?: Partial<IJsonConverterOptions>);
1133
+ /**
1134
+ * Creates a new {@link JsonConverter | JsonConverter}.
1135
+ * @param options - Optional partial {@link IJsonConverterOptions | options}
1136
+ * to configure the converter.
1137
+ * @returns `Success` with a new {@link JsonConverter | JsonConverter}, or `Failure`
1138
+ * with an informative message if an error occurs.
1139
+ */
1140
+ static create(options?: Partial<IJsonConverterOptions>): Result<JsonConverter>;
1141
+ }
1142
+
1143
+ /**
1144
+ * Performs a deep diff comparison between two JSON values.
1145
+ *
1146
+ * This function provides detailed change tracking by analyzing every difference
1147
+ * between two JSON structures. It returns a list of specific changes with paths,
1148
+ * making it ideal for debugging, logging, change analysis, and understanding
1149
+ * exactly what has changed between two data states.
1150
+ *
1151
+ * **Key Features:**
1152
+ * - Deep recursive comparison of nested objects and arrays
1153
+ * - Precise path tracking using dot notation (e.g., "user.profile.name")
1154
+ * - Support for all JSON value types: objects, arrays, primitives, null
1155
+ * - Configurable array comparison (ordered vs unordered)
1156
+ * - Optional inclusion of unchanged values for complete comparisons
1157
+ *
1158
+ * **Use Cases:**
1159
+ * - Debugging data changes in applications
1160
+ * - Generating change logs or audit trails
1161
+ * - Validating API responses against expected data
1162
+ * - Creating detailed diff reports for data synchronization
1163
+ *
1164
+ * @param obj1 - The first JSON value to compare (often the "before" state)
1165
+ * @param obj2 - The second JSON value to compare (often the "after" state)
1166
+ * @param options - Optional configuration for customizing diff behavior
1167
+ * @returns A Result containing the diff result with all detected changes
1168
+ *
1169
+ * @example Basic usage with objects
1170
+ * ```typescript
1171
+ * const before = { name: "John", age: 30, city: "NYC" };
1172
+ * const after = { name: "Jane", age: 30, country: "USA" };
1173
+ *
1174
+ * const result = jsonDiff(before, after);
1175
+ * if (result.success) {
1176
+ * result.value.changes.forEach(change => {
1177
+ * console.log(`${change.path}: ${change.type}`);
1178
+ * // Output:
1179
+ * // name: modified
1180
+ * // city: removed
1181
+ * // country: added
1182
+ * });
1183
+ * }
1184
+ * ```
1185
+ *
1186
+ * @example With arrays and nested structures
1187
+ * ```typescript
1188
+ * const user1 = {
1189
+ * profile: { name: "John", hobbies: ["reading"] },
1190
+ * settings: { theme: "dark" }
1191
+ * };
1192
+ * const user2 = {
1193
+ * profile: { name: "John", hobbies: ["reading", "gaming"] },
1194
+ * settings: { theme: "light", notifications: true }
1195
+ * };
1196
+ *
1197
+ * const result = jsonDiff(user1, user2);
1198
+ * if (result.success) {
1199
+ * console.log(result.value.changes);
1200
+ * // [
1201
+ * // { path: "profile.hobbies.1", type: "added", newValue: "gaming" },
1202
+ * // { path: "settings.theme", type: "modified", oldValue: "dark", newValue: "light" },
1203
+ * // { path: "settings.notifications", type: "added", newValue: true }
1204
+ * // ]
1205
+ * }
1206
+ * ```
1207
+ *
1208
+ * @example Using options for custom behavior
1209
+ * ```typescript
1210
+ * const options: IJsonDiffOptions = {
1211
+ * includeUnchanged: true, // Include unchanged properties
1212
+ * pathSeparator: '/', // Use '/' instead of '.' in paths
1213
+ * arrayOrderMatters: false // Treat arrays as unordered sets
1214
+ * };
1215
+ *
1216
+ * const result = jsonDiff(obj1, obj2, options);
1217
+ * ```
1218
+ *
1219
+ * @see {@link IDiffResult} for the structure of returned results
1220
+ * @see {@link IDiffChange} for details about individual changes
1221
+ * @see {@link IJsonDiffOptions} for available configuration options
1222
+ * @see {@link jsonThreeWayDiff} for an alternative API focused on actionable results
1223
+ * @see {@link jsonEquals} for simple equality checking without change details
1224
+ *
1225
+ * @public
1226
+ */
1227
+ declare function jsonDiff(obj1: JsonValue, obj2: JsonValue, options?: IJsonDiffOptions): Result<IDiffResult>;
1228
+
1229
+ /**
1230
+ * Possible `DetailedResult` details for various editor operations.
1231
+ * @public
1232
+ */
1233
+ export declare type JsonEditFailureReason = 'ignore' | 'inapplicable' | 'edited' | 'error';
1234
+
1235
+ /**
1236
+ * A {@link JsonEditor | JsonEditor} can be used to edit JSON objects in place or to
1237
+ * clone any JSON value, applying a default context and optional set of editor rules that
1238
+ * were supplied at initialization.
1239
+ * @public
1240
+ */
1241
+ export declare class JsonEditor implements IJsonCloneEditor {
1242
+ /**
1243
+ * Default singleton {@link JsonEditor | JsonEditor}.
1244
+ * @internal
1245
+ */
1246
+ protected static _default?: JsonEditor;
1247
+ /**
1248
+ * Full set of {@link IJsonEditorOptions | editor options} in effect for this editor.
1249
+ */
1250
+ options: IJsonEditorOptions;
1251
+ /**
1252
+ * The set of {@link IJsonEditorRule | editor rules} applied by this editor.
1253
+ * @internal
1254
+ */
1255
+ protected _rules: IJsonEditorRule[];
1256
+ /**
1257
+ * Protected constructor for {@link JsonEditor | JsonEditor} and derived classes.
1258
+ * External consumers should instantiate via the {@link JsonEditor.create | create static method}.
1259
+ * @param options - Optional partial {@link IJsonEditorOptions | editor options} for the
1260
+ * constructed editor.
1261
+ * @param rules - Any {@link IJsonEditorRule | editor rules} to be applied by the editor.
1262
+ * @internal
1263
+ */
1264
+ protected constructor(options?: Partial<IJsonEditorOptions>, rules?: IJsonEditorRule[]);
1265
+ /**
1266
+ * Default singleton {@link JsonEditor | JsonEditor} for simple use. Applies all rules
1267
+ * but with no default context.
1268
+ */
1269
+ static get default(): JsonEditor;
1270
+ /**
1271
+ * Constructs a new {@link JsonEditor | JsonEditor}.
1272
+ * @param options - Optional partial {@link IJsonEditorOptions | editor options} for the
1273
+ * constructed editor.
1274
+ * @param rules - Optional set of {@link IJsonEditorRule | editor rules} to be applied by the editor.
1275
+ * @readonly A new {@link JsonEditor | JsonEditor}.
1276
+ */
1277
+ static create(options?: Partial<IJsonEditorOptions>, rules?: IJsonEditorRule[]): Result<JsonEditor>;
1278
+ /**
1279
+ * Gets the default set of rules to be applied for a given set of options.
1280
+ * By default, all available rules (templates, conditionals, multi-value and references)
1281
+ * are applied.
1282
+ * @param options - Optional partial {@link IJsonEditorOptions | editor options} for
1283
+ * all rules.
1284
+ * @returns Default {@link IJsonEditorRule | editor rules} with any supplied options
1285
+ * applied.
1286
+ */
1287
+ static getDefaultRules(options?: IJsonEditorOptions): Result<IJsonEditorRule[]>;
1288
+ /**
1289
+ * Creates a complete IJsonEditorOptions object from partial options, filling in
1290
+ * default values for any missing properties. This ensures all editor instances
1291
+ * have consistent, complete configuration including validation rules and merge behavior.
1292
+ * @param options - Optional partial editor options to merge with defaults
1293
+ * @returns Success with complete editor options, or Failure if validation fails
1294
+ * @internal
1295
+ */
1296
+ protected static _getDefaultOptions(options?: Partial<IJsonEditorOptions>): Result<IJsonEditorOptions>;
1297
+ /**
1298
+ * Merges a supplied source object into a supplied target, updating the target object.
1299
+ * @param target - The target `JsonObject` to be updated
1300
+ * @param src - The source `JsonObject` to be merged
1301
+ * @param runtimeContext - An optional {@link IJsonContext | IJsonContext} supplying variables
1302
+ * and references.
1303
+ * @returns `Success` with the original source `JsonObject` if merge was successful.
1304
+ * Returns `Failure` with details if an error occurs.
1305
+ */
1306
+ mergeObjectInPlace(target: JsonObject, src: JsonObject, runtimeContext?: IJsonContext): Result<JsonObject>;
1307
+ /**
1308
+ * Merges multiple supplied source objects into a supplied target, updating the target
1309
+ * object and using the default context supplied at creation time.
1310
+ * @param target - The target `JsonObject` to be updated
1311
+ * @param srcObjects - `JsonObject`s to be merged into the target object, in the order
1312
+ * supplied.
1313
+ * @returns `Success` with the original source `JsonObject` if merge was successful.
1314
+ * Returns `Failure` with details if an error occurs.
1315
+ */
1316
+ mergeObjectsInPlace(target: JsonObject, srcObjects: JsonObject[]): Result<JsonObject>;
1317
+ /**
1318
+ * Merges multiple supplied source objects into a supplied target, updating the target
1319
+ * object and using an optional {@link IJsonContext | context} supplied in the call.
1320
+ * @param context - An optional {@link IJsonContext | IJsonContext} supplying variables and
1321
+ * references.
1322
+ * @param base - The base `JsonObject` to be updated
1323
+ * @param srcObjects - Objects to be merged into the target object, in the order supplied.
1324
+ * @returns `Success` with the original source `JsonObject` if merge was successful.
1325
+ * Returns `Failure` with details if an error occurs.
1326
+ */
1327
+ mergeObjectsInPlaceWithContext(context: IJsonContext | undefined, base: JsonObject, srcObjects: JsonObject[]): Result<JsonObject>;
1328
+ /**
1329
+ * Deep clones a supplied `JsonValue`, applying all editor rules and a default
1330
+ * or optionally supplied context
1331
+ * @param src - The `JsonValue` to be cloned.
1332
+ * @param context - An optional {@link IJsonContext | JSON context} supplying variables and references.
1333
+ */
1334
+ clone(src: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonEditFailureReason>;
1335
+ /**
1336
+ * Merges properties from a source object into a target object, applying editor rules and
1337
+ * null-as-delete logic. This is the core merge implementation that handles property-by-property
1338
+ * merging with rule processing and deferred property handling.
1339
+ * @param target - The target object to merge properties into
1340
+ * @param src - The source object containing properties to merge
1341
+ * @param state - The editor state containing options and context
1342
+ * @returns Success with the modified target object, or Failure with error details
1343
+ * @internal
1344
+ */
1345
+ protected _mergeObjectInPlace(target: JsonObject, src: JsonObject, state: JsonEditorState): Result<JsonObject>;
1346
+ /**
1347
+ * Creates a deep clone of a JSON array by recursively cloning each element.
1348
+ * Each array element is cloned using the main clone method, preserving the
1349
+ * editor's rules and validation settings.
1350
+ * @param src - The source JSON array to clone
1351
+ * @param context - Optional JSON context for cloning operations
1352
+ * @returns Success with the cloned array, or Failure with error details
1353
+ * @internal
1354
+ */
1355
+ protected _cloneArray(src: JsonArray, context?: IJsonContext): DetailedResult<JsonArray, JsonEditFailureReason>;
1356
+ /**
1357
+ * Merges a single cloned property value into a target object. This method handles
1358
+ * the core merge logic including null-as-delete behavior, array merging, and
1359
+ * recursive object merging. The null-as-delete check occurs before primitive
1360
+ * handling to ensure null values can signal property deletion.
1361
+ * @param target - The target object to merge the property into
1362
+ * @param key - The property key being merged
1363
+ * @param newValue - The cloned value to merge (from source object)
1364
+ * @param state - The editor state containing merge options and context
1365
+ * @returns Success with the merged value, or Failure with error details
1366
+ * @internal
1367
+ */
1368
+ protected _mergeClonedProperty(target: JsonObject, key: string, newValue: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
1369
+ /**
1370
+ * Applies editor rules to a single property during merge operations. This method
1371
+ * iterates through all configured editor rules to process the property, handling
1372
+ * templates, conditionals, multi-value properties, and references.
1373
+ * @param key - The property key to edit
1374
+ * @param value - The property value to edit
1375
+ * @param state - The editor state containing rules and context
1376
+ * @returns Success with transformed property object, or Failure if rules cannot process
1377
+ * @internal
1378
+ */
1379
+ protected _editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
1380
+ /**
1381
+ * Applies editor rules to a single JSON value during clone operations. This method
1382
+ * iterates through all configured editor rules to process the value, handling
1383
+ * templates, conditionals, multi-value expressions, and references.
1384
+ * @param value - The JSON value to edit and transform
1385
+ * @param state - The editor state containing rules and context
1386
+ * @returns Success with transformed value, or Failure if rules cannot process
1387
+ * @internal
1388
+ */
1389
+ protected _editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
1390
+ /**
1391
+ * Clone an object without applying null-as-delete behavior.
1392
+ * This preserves null values during cloning so they can be used for deletion signaling during merge.
1393
+ * @param target - The target object to clone into
1394
+ * @param src - The source object to clone
1395
+ * @param state - The editor state
1396
+ * @returns The cloned object
1397
+ * @internal
1398
+ */
1399
+ protected _cloneObjectWithoutNullAsDelete(target: JsonObject, src: JsonObject, state: JsonEditorState): DetailedResult<JsonObject, JsonEditFailureReason>;
1400
+ /**
1401
+ * Finalizes the merge operation by processing any deferred properties and merging
1402
+ * them into the target object. Deferred properties are those that require special
1403
+ * processing after the initial merge phase, such as references that depend on
1404
+ * other properties being resolved first.
1405
+ * @param target - The target object that has been merged
1406
+ * @param state - The editor state containing deferred properties and rules
1407
+ * @returns Success with the finalized target object, or Failure with error details
1408
+ * @internal
1409
+ */
1410
+ protected _finalizeAndMerge(target: JsonObject, state: JsonEditorState): DetailedResult<JsonObject, JsonEditFailureReason>;
1411
+ }
1412
+
1413
+ /**
1414
+ * A thin wrapper to allow an arbitrary {@link JsonEditor | JsonEditor} to be used via the
1415
+ * \@fgv/ts-utils `Converter` pattern.
1416
+ * @public
1417
+ */
1418
+ export declare class JsonEditorConverter extends Conversion.BaseConverter<JsonValue, IJsonContext> {
1419
+ readonly editor: JsonEditor;
1420
+ /**
1421
+ * Constructs a new {@link JsonEditor | JsonEditor}Converter which uses the supplied editor
1422
+ * @param editor -
1423
+ */
1424
+ constructor(editor: JsonEditor);
1425
+ /**
1426
+ * Constructs a new {@link JsonEditor | JsonEditor}Converter which uses the supplied editor
1427
+ * @param editor -
1428
+ */
1429
+ static createWithEditor(editor: JsonEditor): Result<JsonEditorConverter>;
1430
+ /**
1431
+ * Gets a derived converter which fails if the resulting converted
1432
+ * `JsonValue` is not a `JsonObject`.
1433
+ */
1434
+ object(): Converter<JsonObject, IJsonContext>;
1435
+ /**
1436
+ * Gets a derived converter which fails if the resulting converted
1437
+ * `JsonValue` is not a `JsonArray`.
1438
+ */
1439
+ array(): Converter<JsonArray, IJsonContext>;
1440
+ protected _convert(from: unknown, context?: IJsonContext): Result<JsonValue>;
1441
+ }
1442
+
1443
+ /**
1444
+ * Default base implementation of {@link IJsonEditorRule | IJsonEditorRule} returns inapplicable for all operations so that
1445
+ * derived classes need only implement the operations they actually support.
1446
+ * @public
1447
+ */
1448
+ export declare class JsonEditorRuleBase implements IJsonEditorRule {
1449
+ /**
1450
+ * {@inheritdoc IJsonEditorRule.editProperty}
1451
+ */
1452
+ editProperty(__key: string, __value: JsonValue, __state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
1453
+ /**
1454
+ * {@inheritdoc IJsonEditorRule.editValue}
1455
+ */
1456
+ editValue(__value: JsonValue, __state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
1457
+ /**
1458
+ * {@inheritdoc IJsonEditorRule.finalizeProperties}
1459
+ */
1460
+ finalizeProperties(__deferred: JsonObject[], __state: JsonEditorState): DetailedResult<JsonObject[], JsonEditFailureReason>;
1461
+ }
1462
+
1463
+ /**
1464
+ * Represents the internal state of a {@link JsonEditor | JsonEditor}.
1465
+ * @public
1466
+ */
1467
+ export declare class JsonEditorState {
1468
+ /**
1469
+ * Static global counter used to assign each {@link JsonEditorState | JsonEditorState}
1470
+ * a unique identifier.
1471
+ * @internal
1472
+ */
1473
+ protected static _nextId: number;
1474
+ /**
1475
+ * The {@link IJsonCloneEditor | editor} for which this state applies.
1476
+ */
1477
+ readonly editor: IJsonCloneEditor;
1478
+ /**
1479
+ * Fully resolved {@link IJsonEditorOptions | editor options} that apply
1480
+ * to the operation for which this state applies.
1481
+ */
1482
+ readonly options: IJsonEditorOptions;
1483
+ /**
1484
+ * Any deferred JSON objects to be merged during finalization.
1485
+ * @internal
1486
+ */
1487
+ protected readonly _deferred: JsonObject[];
1488
+ /**
1489
+ * Unique global identifier for this {@link JsonEditorState | state object}.
1490
+ * @internal
1491
+ */
1492
+ protected readonly _id: number;
1493
+ /**
1494
+ * Constructs a new {@link JsonEditorState | JsonEditorState}.
1495
+ * @param editor - The {@link IJsonCloneEditor | editor} to which this state
1496
+ * applies.
1497
+ * @param baseOptions - The {@link IJsonEditorOptions | editor options} that
1498
+ * apply to this rule.
1499
+ * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used
1500
+ * for json value conversion.
1501
+ */
1502
+ constructor(editor: IJsonCloneEditor, baseOptions: IJsonEditorOptions, runtimeContext?: IJsonContext);
1503
+ /**
1504
+ * The optional {@link IJsonContext | JSON context} for this state.
1505
+ */
1506
+ get context(): IJsonContext | undefined;
1507
+ /**
1508
+ * An array of JSON objects that were deferred for merge during
1509
+ * finalization.
1510
+ */
1511
+ get deferred(): JsonObject[];
1512
+ /**
1513
+ * Merges an optional {@link IJsonContext | JSON context} into a supplied set
1514
+ * of {@link IJsonEditorOptions | JSON editor options}.
1515
+ * @param options - The {@link IJsonEditorOptions | IJsonEditorOptions} into
1516
+ * which the the new context is to be merged.
1517
+ * @param context - The {@link IJsonContext | JSON context} to be merged into the
1518
+ * editor options.
1519
+ * @returns `Success` with the supplied {@link IJsonEditorOptions | options} if
1520
+ * there was nothing to merge, or aa new {@link IJsonEditorOptions | IJsonEditorOptions}
1521
+ * constructed from the base options merged with the supplied context. Returns `Failure`
1522
+ * with more information if an error occurs.
1523
+ * @internal
1524
+ */
1525
+ protected static _getEffectiveOptions(options: IJsonEditorOptions, context?: IJsonContext): Result<IJsonEditorOptions>;
1526
+ /**
1527
+ * Adds a supplied `JsonObject` to the deferred list.
1528
+ * @param obj - The `JsonObject` to be deferred.
1529
+ */
1530
+ defer(obj: JsonObject): void;
1531
+ /**
1532
+ * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link JsonEditorState | JsonEditorState},
1533
+ * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default
1534
+ * context.
1535
+ * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`
1536
+ * if the current state does not have context.
1537
+ * @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or
1538
+ * `undefined` if no vars are found.
1539
+ */
1540
+ getVars(defaultContext?: IJsonContext): TemplateVars | undefined;
1541
+ /**
1542
+ * Gets an {@link IJsonReferenceMap | reference map} containing any other values
1543
+ * referenced during the operation.
1544
+ * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as
1545
+ * {@link TemplateVars | TemplateVars} if the current state does not have context.
1546
+ * @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced
1547
+ * during this operation.
1548
+ */
1549
+ getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined;
1550
+ /**
1551
+ * Gets the context of this {@link JsonEditorState | JsonEditorState} or an optionally
1552
+ * supplied default context if this state has no context.
1553
+ * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default
1554
+ * if this state has no context.
1555
+ * @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context
1556
+ * is available.
1557
+ */
1558
+ getContext(defaultContext?: IJsonContext): IJsonContext | undefined;
1559
+ /**
1560
+ * Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables
1561
+ * and references into a supplied existing context.
1562
+ * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables
1563
+ * and references are to be merged, or `undefined` to start with a default empty context.
1564
+ * @param add - The {@link VariableValue | variable values} and/or
1565
+ * {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.
1566
+ * @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.
1567
+ */
1568
+ extendContext(baseContext: IJsonContext | undefined, add: {
1569
+ vars?: VariableValue[];
1570
+ refs?: IJsonReferenceMap[];
1571
+ }): Result<IJsonContext | undefined>;
1572
+ /**
1573
+ * Helper method to constructs `DetailedFailure` with appropriate details and messaging
1574
+ * for various validation failures.
1575
+ * @param rule - The {@link JsonEditorValidationRules | validation rule} that failed.
1576
+ * @param message - A string message describing the failed validation.
1577
+ * @param validation - The {@link IJsonEditorValidationOptions | validation options}
1578
+ * in effect.
1579
+ * @returns A `DetailedFailure` with appropriate detail and message.
1580
+ */
1581
+ failValidation<T = JsonObject>(rule: JsonEditorValidationRules, message?: string, validation?: IJsonEditorValidationOptions): DetailedFailure<T, JsonEditFailureReason>;
1582
+ }
1583
+
1584
+ /**
1585
+ * Possible validation rules for a {@link JsonEditor | JsonEditor}.
1586
+ * @public
1587
+ */
1588
+ export declare type JsonEditorValidationRules = 'invalidPropertyName' | 'invalidPropertyValue' | 'undefinedPropertyValue';
1589
+
1590
+ /**
1591
+ * A simpler helper function that returns true if two JSON values are deeply equal.
1592
+ *
1593
+ * This function provides a fast boolean check for JSON equality without the overhead
1594
+ * of tracking individual changes. It performs the same deep comparison logic as
1595
+ * {@link Diff.jsonDiff} but returns only a true/false result, making it ideal for
1596
+ * conditional logic and validation scenarios.
1597
+ *
1598
+ * **Key Features:**
1599
+ * - Deep recursive comparison of all nested structures
1600
+ * - Handles all JSON types: objects, arrays, primitives, null
1601
+ * - Object property order independence
1602
+ * - Array order significance (index positions matter)
1603
+ * - Performance optimized for equality checking
1604
+ *
1605
+ * **Use Cases:**
1606
+ * - Conditional logic based on data equality
1607
+ * - Input validation and testing assertions
1608
+ * - Caching and memoization keys
1609
+ * - Quick checks before expensive diff operations
1610
+ *
1611
+ * @param obj1 - The first JSON value to compare
1612
+ * @param obj2 - The second JSON value to compare
1613
+ * @returns True if the values are deeply equal, false otherwise
1614
+ *
1615
+ * @example Basic equality checking
1616
+ * ```typescript
1617
+ * // Objects with same structure and values
1618
+ * const user1 = { name: "John", hobbies: ["reading", "gaming"] };
1619
+ * const user2 = { name: "John", hobbies: ["reading", "gaming"] };
1620
+ * console.log(jsonEquals(user1, user2)); // true
1621
+ *
1622
+ * // Different property order (still equal)
1623
+ * const obj1 = { a: 1, b: 2 };
1624
+ * const obj2 = { b: 2, a: 1 };
1625
+ * console.log(jsonEquals(obj1, obj2)); // true
1626
+ *
1627
+ * // Different values
1628
+ * const before = { status: "pending" };
1629
+ * const after = { status: "completed" };
1630
+ * console.log(jsonEquals(before, after)); // false
1631
+ * ```
1632
+ *
1633
+ * @example With nested structures
1634
+ * ```typescript
1635
+ * const config1 = {
1636
+ * database: { host: "localhost", port: 5432 },
1637
+ * features: ["auth", "cache"]
1638
+ * };
1639
+ * const config2 = {
1640
+ * database: { host: "localhost", port: 5432 },
1641
+ * features: ["auth", "cache"]
1642
+ * };
1643
+ *
1644
+ * if (jsonEquals(config1, config2)) {
1645
+ * console.log("Configurations are identical");
1646
+ * }
1647
+ * ```
1648
+ *
1649
+ * @example Array order sensitivity
1650
+ * ```typescript
1651
+ * const list1 = [1, 2, 3];
1652
+ * const list2 = [3, 2, 1];
1653
+ * console.log(jsonEquals(list1, list2)); // false - order matters
1654
+ *
1655
+ * const list3 = [1, 2, 3];
1656
+ * const list4 = [1, 2, 3];
1657
+ * console.log(jsonEquals(list3, list4)); // true - same order
1658
+ * ```
1659
+ *
1660
+ * @see {@link Diff.jsonDiff} for detailed change analysis when equality fails
1661
+ * @see {@link jsonThreeWayDiff} for actionable difference results
1662
+ *
1663
+ * @public
1664
+ */
1665
+ declare function jsonEquals(obj1: JsonValue, obj2: JsonValue): boolean;
1666
+
1667
+ /**
1668
+ * A simple validating {@link JsonConverter | JSON converter}. Converts unknown
1669
+ * to a `JsonObject`, or fails if the `unknown` contains invalid
1670
+ * JSON or is not an object.
1671
+ * @public
1672
+ */
1673
+ declare const jsonObject: Converter<JsonObject, IJsonContext>;
1674
+
1675
+ /**
1676
+ * Possible `DetailedResult` details for property edit operations.
1677
+ * @public
1678
+ */
1679
+ export declare type JsonPropertyEditFailureReason = JsonEditFailureReason | 'deferred';
1680
+
1681
+ /**
1682
+ * Failure reason for {@link IJsonReferenceMap | IJsonReferenceMap} lookup, where `'unknown'`
1683
+ * means that the object is not present in the map and `'error'` means
1684
+ * that an error occurred while retrieving or converting it.
1685
+ * @public
1686
+ */
1687
+ export declare type JsonReferenceMapFailureReason = 'unknown' | 'error';
1688
+
1689
+ /**
1690
+ * Performs a three-way diff comparison between two JSON values, returning separate
1691
+ * objects containing the differences and similarities.
1692
+ *
1693
+ * This function provides an alternative to {@link Diff.jsonDiff} that focuses on actionable
1694
+ * results rather than detailed change analysis. Instead of a list of individual changes,
1695
+ * it returns three objects that can be directly used for merging, UI display, or
1696
+ * programmatic manipulation.
1697
+ *
1698
+ * **Key Features:**
1699
+ * - **Actionable Results**: Returns objects ready for immediate use in merging operations
1700
+ * - **Simplified Array Handling**: Arrays are treated as atomic values for cleaner results
1701
+ * - **Structural Preservation**: Maintains original JSON structure rather than flattened paths
1702
+ * - **UI-Optimized**: Perfect for side-by-side diff displays and change visualization
1703
+ * - **Merge-Friendly**: Designed specifically for three-way merge scenarios
1704
+ *
1705
+ * **Array Handling:**
1706
+ * Unlike {@link Diff.jsonDiff}, this function treats arrays as complete units. If arrays differ,
1707
+ * the entire array appears in the appropriate result object rather than computing
1708
+ * element-by-element deltas. This approach is simpler and more predictable for most
1709
+ * use cases involving data updates and synchronization.
1710
+ *
1711
+ * **Use Cases:**
1712
+ * - Applying configuration updates while preserving unchanged settings
1713
+ * - Creating side-by-side diff displays in user interfaces
1714
+ * - Building three-way merge tools for data synchronization
1715
+ * - Implementing undo/redo functionality with granular control
1716
+ * - Generating patch objects for API updates
1717
+ *
1718
+ * @param obj1 - The first JSON value to compare (often the "before" or "source" state)
1719
+ * @param obj2 - The second JSON value to compare (often the "after" or "target" state)
1720
+ * @returns A Result containing the three-way diff with separate objects and metadata
1721
+ *
1722
+ * @example Basic usage for applying changes
1723
+ * ```typescript
1724
+ * const original = { name: "John", age: 30, city: "NYC", active: true };
1725
+ * const updated = { name: "Jane", age: 30, country: "USA", active: true };
1726
+ *
1727
+ * const result = jsonThreeWayDiff(original, updated);
1728
+ * if (result.success) {
1729
+ * const { onlyInA, unchanged, onlyInB } = result.value;
1730
+ *
1731
+ * // Apply changes: merge unchanged + onlyInB
1732
+ * const applied = { ...unchanged, ...onlyInB };
1733
+ * console.log(applied); // { age: 30, active: true, name: "Jane", country: "USA" }
1734
+ *
1735
+ * // Revert changes: merge unchanged + onlyInA
1736
+ * const reverted = { ...unchanged, ...onlyInA };
1737
+ * console.log(reverted); // { age: 30, active: true, name: "John", city: "NYC" }
1738
+ * }
1739
+ * ```
1740
+ *
1741
+ * @example UI-friendly diff display
1742
+ * ```typescript
1743
+ * const result = jsonThreeWayDiff(userBefore, userAfter);
1744
+ * if (result.success) {
1745
+ * const { onlyInA, unchanged, onlyInB, metadata } = result.value;
1746
+ *
1747
+ * // Display summary
1748
+ * console.log(`Changes: ${metadata.added} added, ${metadata.removed} removed, ${metadata.modified} modified`);
1749
+ *
1750
+ * // Show removed/old values in red
1751
+ * if (onlyInA) displayInColor(onlyInA, 'red');
1752
+ *
1753
+ * // Show unchanged values in gray
1754
+ * if (unchanged) displayInColor(unchanged, 'gray');
1755
+ *
1756
+ * // Show added/new values in green
1757
+ * if (onlyInB) displayInColor(onlyInB, 'green');
1758
+ * }
1759
+ * ```
1760
+ *
1761
+ * @example Nested objects and array handling
1762
+ * ```typescript
1763
+ * const config1 = {
1764
+ * database: { host: "localhost", port: 5432 },
1765
+ * features: ["auth", "logging"],
1766
+ * version: "1.0"
1767
+ * };
1768
+ * const config2 = {
1769
+ * database: { host: "production.db", port: 5432 },
1770
+ * features: ["auth", "logging", "metrics"], // Array treated as complete unit
1771
+ * version: "1.1"
1772
+ * };
1773
+ *
1774
+ * const result = jsonThreeWayDiff(config1, config2);
1775
+ * if (result.success) {
1776
+ * // result.value.onlyInA = { database: { host: "localhost" }, features: ["auth", "logging"], version: "1.0" }
1777
+ * // result.value.unchanged = { database: { port: 5432 } }
1778
+ * // result.value.onlyInB = { database: { host: "production.db" }, features: ["auth", "logging", "metrics"], version: "1.1" }
1779
+ * }
1780
+ * ```
1781
+ *
1782
+ * @example Conditional updates based on changes
1783
+ * ```typescript
1784
+ * const result = jsonThreeWayDiff(currentState, newState);
1785
+ * if (result.success && !result.value.identical) {
1786
+ * const { metadata } = result.value;
1787
+ *
1788
+ * if (metadata.modified > 0) {
1789
+ * console.log("Critical settings changed - requires restart");
1790
+ * } else if (metadata.added > 0) {
1791
+ * console.log("New features enabled");
1792
+ * } else if (metadata.removed > 0) {
1793
+ * console.log("Features disabled");
1794
+ * }
1795
+ * }
1796
+ * ```
1797
+ *
1798
+ * @see {@link IThreeWayDiff} for the structure of returned results
1799
+ * @see {@link IThreeWayDiffMetadata} for metadata details
1800
+ * @see {@link Diff.jsonDiff} for detailed change-by-change analysis
1801
+ * @see {@link jsonEquals} for simple equality checking
1802
+ *
1803
+ * @public
1804
+ */
1805
+ declare function jsonThreeWayDiff(obj1: JsonValue, obj2: JsonValue): Result<IThreeWayDiff>;
1806
+
1807
+ /**
1808
+ * Type representing either a `Map\<string, T\>` or a `Record\<string, T\>`.
1809
+ * @public
1810
+ */
1811
+ declare type MapOrRecord<T> = Map<string, T> | Record<string, T>;
1812
+
1813
+ /**
1814
+ * Merges an optionally supplied partial set of {@link IJsonConverterOptions | options} with
1815
+ * the default converter options and taking all dynamic rules into account (e.g. template usage enabled
1816
+ * if variables are supplied and disabled if not), producing a fully-resolved set of
1817
+ * {@link IJsonConverterOptions | IJsonConverterOptions}.
1818
+ * @param partial - An optional partial {@link IJsonConverterOptions | IJsonConverterOptions}
1819
+ * to be merged.
1820
+ * @public
1821
+ */
1822
+ export declare function mergeDefaultJsonConverterOptions(partial?: Partial<IJsonConverterOptions>): IJsonConverterOptions;
1823
+
1824
+ /**
1825
+ * The {@link EditorRules.MultiValueJsonEditorRule | Multi-Value JSON editor rule}
1826
+ * expands matching keys multiple times, projecting the value into the template
1827
+ * context for any child objects rendered by the rule.
1828
+ *
1829
+ * The default syntax for a multi-value key is:
1830
+ * "[[var]]=value1,value2,value3"
1831
+ * Where "var" is the name of the variable that will be passed to
1832
+ * child template resolution, and "value1,value2,value3" is a
1833
+ * comma-separated list of values to be expanded.
1834
+ * @public
1835
+ */
1836
+ declare class MultiValueJsonEditorRule extends JsonEditorRuleBase {
1837
+ /**
1838
+ * Stored fully-resolved {@link IJsonEditorOptions | editor options}
1839
+ * for this rule.
1840
+ * @public
1841
+ */
1842
+ protected _options?: IJsonEditorOptions;
1843
+ /**
1844
+ * Creates a new {@link EditorRules.MultiValueJsonEditorRule | MultiValueJsonEditorRule}.
1845
+ * @param options - Optional {@link IJsonEditorOptions | configuration options}.
1846
+ */
1847
+ constructor(options?: IJsonEditorOptions);
1848
+ /**
1849
+ * Creates a new {@link EditorRules.MultiValueJsonEditorRule | MultiValueJsonEditorRule}.
1850
+ * @param options - Optional {@link IJsonEditorOptions | configuration options}.
1851
+ */
1852
+ static create(options?: IJsonEditorOptions): Result<MultiValueJsonEditorRule>;
1853
+ /**
1854
+ * Evaluates a property for multi-value expansion.
1855
+ * @param key - The key of the property to be considered
1856
+ * @param value - The `JsonValue` of the property to be considered.
1857
+ * @param state - The {@link JsonEditorState | editor state} for the object being edited.
1858
+ * @returns `Success` with an object containing the fully-resolved child values to be merged for
1859
+ * matching multi-value property. Returns `Failure` with detail `'error'` if an error occurs or
1860
+ * with detail `'inapplicable'` if the property key is not a conditional property.
1861
+ */
1862
+ editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
1863
+ /**
1864
+ * Extends the {@link IJsonContext | current context} with a supplied state and values.
1865
+ * @param state - The {@link JsonEditorState | editor state} for the object being edited.
1866
+ * @param values - An array of {@link VariableValue | VariableValue} to be added to the
1867
+ * context.
1868
+ * @returns The extended {@link IJsonContext | context}.
1869
+ * @public
1870
+ */
1871
+ protected _deriveContext(state: JsonEditorState, ...values: VariableValue[]): Result<IJsonContext | undefined>;
1872
+ /**
1873
+ * Determines if a given property key is multi-value. Derived classes can override this
1874
+ * method to use a different format for multi-value properties.
1875
+ * @param value - The `JsonValue` of the property to be considered.
1876
+ * @param state - The {@link JsonEditorState | editor state} for the object being edited.
1877
+ * @returns `Success` with detail `'deferred'` and an
1878
+ * {@link EditorRules.IMultiValuePropertyParts | IMultiValuePropertyParts}
1879
+ * describing the match for matching multi-value property. Returns `Failure` with detail `'error'` if an error occurs
1880
+ * or with detail `'inapplicable'` if the key does not represent a multi-value property.
1881
+ * @public
1882
+ */
1883
+ protected _tryParse(token: string, state: JsonEditorState): DetailedResult<IMultiValuePropertyParts, JsonEditFailureReason>;
1884
+ }
1885
+
1886
+ /**
1887
+ * A {@link PrefixedJsonMap | PrefixedJsonMap} enforces a supplied prefix for all contained values,
1888
+ * optionally adding the prefix as necessary (default `true`).
1889
+ * @public
1890
+ */
1891
+ export declare class PrefixedJsonMap extends SimpleJsonMap {
1892
+ /**
1893
+ * Constructs a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
1894
+ * @param prefix - A string prefix to be enforced for and added to key names as necessary
1895
+ * @param values - A string-keyed Map or Record of the `JsonValue` to be returned
1896
+ * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values
1897
+ * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values
1898
+ * @public
1899
+ */
1900
+ protected constructor(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions);
1901
+ /**
1902
+ * Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
1903
+ * @param prefix - A string prefix to be enforced for and added to key names as necessary
1904
+ * @param values - A string-keyed Map or Record of the `JsonValue` to be returned
1905
+ * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values
1906
+ * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values
1907
+ * @returns `Success` with a {@link PrefixedJsonMap | PrefixedJsonMap} or `Failure` with a message
1908
+ * if an error occurs.
1909
+ */
1910
+ static createPrefixed(prefix: string, values?: MapOrRecord<JsonValue>, context?: IJsonContext, editor?: JsonEditor): Result<PrefixedJsonMap>;
1911
+ /**
1912
+ * Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
1913
+ * @param prefixOptions - A KeyPrefixOptions indicating the prefix to enforce and whether that prefix should
1914
+ * be added automatically if necessary (default true)
1915
+ * @param values - A string-keyed Map or record of the `JsonValue` to be returned
1916
+ * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values
1917
+ * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values
1918
+ */
1919
+ static createPrefixed(prefixOptions: IKeyPrefixOptions, values?: MapOrRecord<JsonValue>, context?: IJsonContext, editor?: JsonEditor): Result<PrefixedJsonMap>;
1920
+ /**
1921
+ * Constructs a new {@link PrefixKeyPolicy | PrefixKeyPolicy} from a supplied prefix
1922
+ * or set of {@link IKeyPrefixOptions | prefix options}.
1923
+ * @param prefixOptions - The prefix or {@link IKeyPrefixOptions | prefix options} or options
1924
+ * for the new policy.
1925
+ * @returns A new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} which enforces the
1926
+ * supplied prefix or options.
1927
+ * @internal
1928
+ */
1929
+ protected static _toPolicy(prefixOptions: string | IKeyPrefixOptions): ReferenceMapKeyPolicy<JsonValue>;
1930
+ }
1931
+
1932
+ /**
1933
+ * The {@link EditorRules.ReferenceJsonEditorRule | Reference JSON editor rule} replaces property
1934
+ * keys or values that match some known object with a copy of that referenced object, formatted
1935
+ * according to the current context.
1936
+ *
1937
+ * A property key is matched if it matches any known referenced value.
1938
+ * - If the value of the matched key is `'default'`, then the entire object is formatted
1939
+ * with the current context, flattened and merged into the current object.
1940
+ * - If the value of the matched key is some other string, then the entire
1941
+ * object is formatted with the current context, and the child of the resulting
1942
+ * object at the specified path is flattened and merged into the current object.
1943
+ * - If the value of the matched key is an object, then the entire object is
1944
+ * formatted with the current context extended to include any properties of
1945
+ * that object, flattened, and merged into the current object.
1946
+ * - It is an error if the referenced value is not an object.
1947
+ *
1948
+ * Any property, array or literal value is matched if it matches any known
1949
+ * value reference. The referenced value is replaced by the referenced
1950
+ * value, formatted using the current editor context.
1951
+ * @public
1952
+ */
1953
+ declare class ReferenceJsonEditorRule extends JsonEditorRuleBase {
1954
+ /**
1955
+ * Stored fully-resolved {@link IJsonEditorOptions | editor options} for this rule.
1956
+ * @public
1957
+ */
1958
+ protected _options?: IJsonEditorOptions;
1959
+ /**
1960
+ * Creates a new {@link EditorRules.ReferenceJsonEditorRule | ReferenceJsonEditorRule}.
1961
+ * @param options - Optional {@link IJsonEditorOptions | configuration options} for this rule.
1962
+ */
1963
+ constructor(options?: IJsonEditorOptions);
1964
+ /**
1965
+ * Creates a new {@link EditorRules.ReferenceJsonEditorRule | ReferenceJsonEditorRule}.
1966
+ * @param options - Optional {@link IJsonEditorOptions | configuration options} for this rule.
1967
+ */
1968
+ static create(options?: IJsonEditorOptions): Result<ReferenceJsonEditorRule>;
1969
+ /**
1970
+ * Evaluates a property for reference expansion.
1971
+ * @param key - The key of the property to be considered.
1972
+ * @param value - The `JsonValue` of the property to be considered.
1973
+ * @param state - The {@link JsonEditorState | editor state} for the object being edited.
1974
+ * @returns If the reference is successful, returns `Success` with a `JsonObject`
1975
+ * to be flattened and merged into the current object. Returns `Failure` with detail `'inapplicable'`
1976
+ * for non-reference keys or with detail `'error'` if an error occurs.
1977
+ */
1978
+ editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
1979
+ /**
1980
+ * Evaluates a property, array or literal value for reference replacement.
1981
+ * @param value - The `JsonValue` of the property to be considered.
1982
+ * @param state - The {@link JsonEditorState | editor state} for the object being edited.
1983
+ */
1984
+ editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
1985
+ /**
1986
+ * Gets the template variables to use given the value of some property whose name matched a
1987
+ * resource plus the base template context.
1988
+ * @param state - The {@link JsonEditorState | editor state} to be extended.
1989
+ * @param supplied - The string or object supplied in the source json.
1990
+ * @internal
1991
+ */
1992
+ protected _extendContext(state: JsonEditorState, supplied: JsonValue): Result<IJsonContext | undefined>;
1993
+ }
1994
+
1995
+ /**
1996
+ * Policy object responsible for validating or correcting
1997
+ * keys in a {@link IJsonReferenceMap | reference map}.
1998
+ * @public
1999
+ */
2000
+ export declare class ReferenceMapKeyPolicy<T> {
2001
+ /**
2002
+ * @internal
2003
+ */
2004
+ protected readonly _defaultOptions?: IReferenceMapKeyPolicyValidateOptions;
2005
+ /**
2006
+ * @internal
2007
+ */
2008
+ protected readonly _isValid: (key: string, item?: T) => boolean;
2009
+ /**
2010
+ * Constructs a new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy}.
2011
+ * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options}
2012
+ * used to construct the {@link ReferenceMapKeyPolicy}.
2013
+ * @param isValid - An optional predicate to test a supplied key for validity.
2014
+ */
2015
+ constructor(options?: IReferenceMapKeyPolicyValidateOptions, isValid?: (key: string, item?: T) => boolean);
2016
+ /**
2017
+ * The static default key name validation predicate rejects keys that contain
2018
+ * mustache templates or which start with the default conditional prefix
2019
+ * `'?'`.
2020
+ * @param key - The key to test.
2021
+ * @returns `true` if the key is valid, `false` otherwise.
2022
+ */
2023
+ static defaultKeyPredicate(key: string): boolean;
2024
+ /**
2025
+ * Determines if a supplied key and item are valid according to the current policy.
2026
+ * @param key - The key to be tested.
2027
+ * @param item - The item to be tested.
2028
+ * @returns `true` if the key and value are valid, `false` otherwise.
2029
+ */
2030
+ isValid(key: string, item?: T): boolean;
2031
+ /**
2032
+ * Determines if a supplied key and item are valid according to the current policy.
2033
+ * @param key - The key to be tested.
2034
+ * @param item - The item to be tested.
2035
+ * @returns `Success` with the key if valid, `Failure` with an error message if invalid.
2036
+ */
2037
+ validate(key: string, item?: T, __options?: IReferenceMapKeyPolicyValidateOptions): Result<string>;
2038
+ /**
2039
+ * Validates an array of entries using the validation rules for this policy.
2040
+ * @param items - The array of entries to be validated.
2041
+ * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control
2042
+ * validation.
2043
+ * @returns `Success` with an array of validated entries, or `Failure` with an error message
2044
+ * if validation fails.
2045
+ */
2046
+ validateItems(items: [string, T][], options?: IReferenceMapKeyPolicyValidateOptions): Result<[string, T][]>;
2047
+ /**
2048
+ * Validates a `Map\<string, T\>` using the validation rules for this policy.
2049
+ * @param items - The `Map\<string, T\>` to be validated.
2050
+ * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control
2051
+ * validation.
2052
+ * @returns `Success` with a new `Map\<string, T\>`, or `Failure` with an error message
2053
+ * if validation fails.
2054
+ */
2055
+ validateMap(map: Map<string, T>, options?: IReferenceMapKeyPolicyValidateOptions): Result<Map<string, T>>;
2056
+ }
2057
+
2058
+ /**
2059
+ * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
2060
+ * supplied `unknown` to strongly-typed JSON, by first rendering any property
2061
+ * names or string values using mustache with the supplied context, then applying
2062
+ * multi-value property expansion and conditional flattening based on property names.
2063
+ * @param options - {@link RichJsonConverterOptions | Options and context} for
2064
+ * the conversion.
2065
+ * @public
2066
+ */
2067
+ declare function richJson(options?: Partial<RichJsonConverterOptions>): JsonConverter;
2068
+
2069
+ /**
2070
+ * A \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache
2071
+ * template rendering, multi-value property name, conditional property
2072
+ * name, and external reference rules enabled regardless of initial context.
2073
+ * @public
2074
+ */
2075
+ export declare class RichJsonConverter extends JsonEditorConverter {
2076
+ /**
2077
+ * Default {@link IJsonConverterOptions | JSON converter options}
2078
+ * to enable rich conversion.
2079
+ */
2080
+ static readonly richOptions: Partial<IJsonConverterOptions>;
2081
+ /**
2082
+ * Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or
2083
+ * default options.
2084
+ * @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}
2085
+ * for the converter.
2086
+ */
2087
+ constructor(options?: Partial<RichJsonConverterOptions>);
2088
+ /**
2089
+ * Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or
2090
+ * default options
2091
+ * @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}
2092
+ * for the converter.
2093
+ */
2094
+ static create(options?: Partial<RichJsonConverterOptions>): Result<JsonConverter>;
2095
+ }
2096
+
2097
+ /**
2098
+ * Initialization options for a {@link RichJsonConverter | RichJsonConverter}.
2099
+ * @public
2100
+ */
2101
+ export declare type RichJsonConverterOptions = Omit<ConditionalJsonConverterOptions, 'useReferences'>;
2102
+
2103
+ /**
2104
+ * A {@link SimpleJsonMap | SimpleJsonMap } presents a view of a simple map
2105
+ * of JSON values.
2106
+ * @public
2107
+ */
2108
+ export declare class SimpleJsonMap extends SimpleJsonMapBase<JsonValue> {
2109
+ /**
2110
+ * @internal
2111
+ */
2112
+ protected _editor?: JsonEditor;
2113
+ /**
2114
+ * Constructs a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects
2115
+ * @param values - A string-keyed `Map` or `Record` of the `JsonValue`
2116
+ * to be returned.
2117
+ * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.
2118
+ * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.
2119
+ * @public
2120
+ */
2121
+ protected constructor(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions);
2122
+ /**
2123
+ * Creates a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects
2124
+ * @param values - A string-keyed `Map` or `Record` of the `JsonValue`
2125
+ * to be returned.
2126
+ * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.
2127
+ * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.
2128
+ * @returns `Success` with a {@link SimpleJsonMap | SimpleJsonMap} or `Failure` with a message if
2129
+ * an error occurs.
2130
+ */
2131
+ static createSimple(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions): Result<SimpleJsonMap>;
2132
+ /**
2133
+ * Gets a `JsonValue` specified by key.
2134
+ * @param key - key of the value to be retrieved
2135
+ * @param context - Optional {@link IJsonContext | JSON context} used to format the value
2136
+ * @returns Success with the formatted object if successful. Failure with detail 'unknown'
2137
+ * if no such object exists, or failure with detail 'error' if the object was found but
2138
+ * could not be formatted.
2139
+ */
2140
+ getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
2141
+ /**
2142
+ * @internal
2143
+ */
2144
+ protected _clone(value: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
2145
+ }
2146
+
2147
+ /**
2148
+ * Abstract base class with common functionality for simple
2149
+ * {@link IJsonReferenceMap | reference map} implementations.
2150
+ * @public
2151
+ */
2152
+ declare abstract class SimpleJsonMapBase<T> implements IJsonReferenceMap {
2153
+ /**
2154
+ * The {@link ReferenceMapKeyPolicy | key policy} in effect for this map.
2155
+ * @internal
2156
+ */
2157
+ protected readonly _keyPolicy: ReferenceMapKeyPolicy<T>;
2158
+ /**
2159
+ * A map containing keys and values already present in this map.
2160
+ * @internal
2161
+ */
2162
+ protected readonly _values: Map<string, T>;
2163
+ /**
2164
+ * An optional {@link IJsonContext | IJsonContext} used for any conversions
2165
+ * involving items in this map.
2166
+ * @internal
2167
+ */
2168
+ protected readonly _context?: IJsonContext;
2169
+ /**
2170
+ * Constructs a new {@link SimpleJsonMap | SimpleJsonMap}.
2171
+ * @param values - Initial values for the map.
2172
+ * @param context - An optional {@link IJsonContext | IJsonContext} used for any conversions
2173
+ * involving items in this map.
2174
+ * @param keyPolicy - The {@link ReferenceMapKeyPolicy | key policy} to use for this map.
2175
+ * @internal
2176
+ */
2177
+ protected constructor(values?: MapOrRecord<T>, context?: IJsonContext, keyPolicy?: ReferenceMapKeyPolicy<T>);
2178
+ /**
2179
+ * Returns a `Map\<string, T\>` derived from a supplied {@link MapOrRecord | MapOrRecord}
2180
+ * @param values - The {@link MapOrRecord | MapOrRecord} to be returned as a map.
2181
+ * @returns `Success` with the corresponding `Map\<string, T\>` or `Failure` with a
2182
+ * message if an error occurs.
2183
+ * @internal
2184
+ */
2185
+ protected static _toMap<T>(values?: MapOrRecord<T>): Result<Map<string, T>>;
2186
+ /**
2187
+ * Determine if a key might be valid for this map but does not determine if key actually
2188
+ * exists. Allows key range to be constrained.
2189
+ * @param key - key to be tested
2190
+ * @returns `true` if the key is in the valid range, `false` otherwise.
2191
+ */
2192
+ keyIsInRange(key: string): boolean;
2193
+ /**
2194
+ * Determines if an entry with the specified key actually exists in the map.
2195
+ * @param key - key to be tested
2196
+ * @returns `true` if an object with the specified key exists, `false` otherwise.
2197
+ */
2198
+ has(key: string): boolean;
2199
+ /**
2200
+ * Gets a `JsonObject` specified by key.
2201
+ * @param key - key of the object to be retrieved
2202
+ * @param context - optional {@link IJsonContext | JSON context} used to format the
2203
+ * returned object.
2204
+ * @returns {@link ts-utils#Success | `Success`} with the formatted object if successful.
2205
+ * {@link ts-utils#Failure | `Failure`} with detail 'unknown' if no such object exists,
2206
+ * or {@link ts-utils#Failure | `Failure`} with detail 'error' if the object was found
2207
+ * but could not be formatted.
2208
+ */
2209
+ getJsonObject(key: string, context?: IJsonContext): DetailedResult<JsonObject, JsonReferenceMapFailureReason>;
2210
+ /**
2211
+ * Gets a `JsonValue` specified by key.
2212
+ * @param key - key of the value to be retrieved
2213
+ * @param context - Optional {@link IJsonContext | JSON context} used to format the value
2214
+ * @returns Success with the formatted object if successful. Failure with detail 'unknown'
2215
+ * if no such object exists, or failure with detail 'error' if the object was found but
2216
+ * could not be formatted.
2217
+ */
2218
+ abstract getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
2219
+ }
2220
+
2221
+ /**
2222
+ * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts an
2223
+ * `unknown` value to JSON, rendering any property names or string values using mustache with
2224
+ * the supplied context. See the mustache documentation for details of mustache syntax and view.
2225
+ * @param options - {@link TemplatedJsonConverterOptions | Options and context} for
2226
+ * the conversion.
2227
+ * @public
2228
+ */
2229
+ declare function templatedJson(options?: Partial<TemplatedJsonConverterOptions>): JsonConverter;
2230
+
2231
+ /**
2232
+ * An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON
2233
+ * with mustache template rendering and multi-value property name rules enabled
2234
+ * regardless of initial context.
2235
+ * @public
2236
+ */
2237
+ export declare class TemplatedJsonConverter extends JsonEditorConverter {
2238
+ /**
2239
+ * Default {@link IJsonConverterOptions | JSON converter options}
2240
+ * to enable templated conversion.
2241
+ */
2242
+ static readonly templateOptions: Partial<IJsonConverterOptions>;
2243
+ /**
2244
+ * Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with
2245
+ * supplied or default options.
2246
+ * @param options - Optional partial {@link TemplatedJsonConverterOptions | options}
2247
+ * to configure the converter.
2248
+ */
2249
+ constructor(options?: Partial<TemplatedJsonConverterOptions>);
2250
+ /**
2251
+ * Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with
2252
+ * supplied or default options.
2253
+ * @param options - Optional partial {@link TemplatedJsonConverterOptions | options}
2254
+ * to configure the converter.
2255
+ */
2256
+ static create(options?: Partial<TemplatedJsonConverterOptions>): Result<JsonConverter>;
2257
+ }
2258
+
2259
+ /**
2260
+ * Initialization options for a {@link TemplatedJsonConverter | TemplatedJsonConverter}.
2261
+ * @public
2262
+ */
2263
+ export declare type TemplatedJsonConverterOptions = Omit<IJsonConverterOptions, 'useNameTemplates' | 'useValueTemplates' | 'useMultiValueTemplateNames'>;
2264
+
2265
+ /**
2266
+ * The {@link EditorRules.TemplatedJsonEditorRule | Templated JSON editor rule} applies mustache rendering as
2267
+ * appropriate to any keys or values in the object being edited.
2268
+ * @public
2269
+ */
2270
+ declare class TemplatedJsonEditorRule extends JsonEditorRuleBase {
2271
+ /**
2272
+ * Fully-resolved {@link EditorRules.ITemplatedJsonRuleOptions | configuration options} for this rule.
2273
+ * @public
2274
+ */
2275
+ protected _options?: ITemplatedJsonRuleOptions;
2276
+ /**
2277
+ * Creates a new {@link EditorRules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.
2278
+ * @param options - Optional {@link EditorRules.ITemplatedJsonRuleOptions | configuration options}
2279
+ * for this rule.
2280
+ */
2281
+ constructor(options?: ITemplatedJsonRuleOptions);
2282
+ /**
2283
+ * Creates a new {@link EditorRules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.
2284
+ * @param options - Optional {@link EditorRules.ITemplatedJsonRuleOptions | configuration options}
2285
+ * for this rule.
2286
+ */
2287
+ static create(options?: ITemplatedJsonRuleOptions): Result<TemplatedJsonEditorRule>;
2288
+ /**
2289
+ * Evaluates a property name for template rendering.
2290
+ * @param key - The key of the property to be considered.
2291
+ * @param value - The `JsonValue` of the property to be considered.
2292
+ * @param state - The {@link JsonEditorState | editor state} for the object being edited.
2293
+ * @returns `Success` with detail `'edited'` and an `JsonObject` to
2294
+ * be flattened and merged if the key contained a template. Returns `Failure` with detail `'error'`
2295
+ * if an error occurred or with detail `'inapplicable'` if the property key does not contain
2296
+ * a template or if name rendering is disabled.
2297
+ */
2298
+ editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
2299
+ /**
2300
+ * Evaluates a property, array or literal value for template rendering.
2301
+ * @param value - The `JsonValue` to be edited.
2302
+ * @param state - The {@link JsonEditorState | editor state} for the object being edited.
2303
+ * @returns `Success` with detail `'edited'` if the value contained a template and was edited.
2304
+ * Returns `Failure` with `'ignore'` if the rendered value should be ignored, with `'error'` if
2305
+ * an error occurs, or with `'inapplicable'` if the value was not a string with a template.
2306
+ */
2307
+ editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
2308
+ /**
2309
+ * Renders a single template string for a supplied {@link JsonEditorState | editor state}.
2310
+ * @param template - The mustache template to be rendered.
2311
+ * @param state - The {@link JsonEditorState | editor state} used to render the template.
2312
+ * @returns `Success` if the template is rendered. Returns `Failure` with detail `'error'` if the
2313
+ * template could not be rendered (e.g. due to syntax errors) or with detail `'inapplicable'` if the
2314
+ * string is not a template.
2315
+ * @internal
2316
+ */
2317
+ protected _render(template: string, state: JsonEditorState): DetailedResult<string, JsonEditFailureReason>;
2318
+ }
2319
+
2320
+ /**
2321
+ * Collection of variables used for template replacement in a JSON edit or
2322
+ * conversion.
2323
+ * @public
2324
+ */
2325
+ export declare type TemplateVars = Record<string, unknown>;
2326
+
2327
+ /**
2328
+ * Function used to create a new collection of {@link TemplateVars | TemplateVars} with
2329
+ * one or more new or changed values.
2330
+ * @public
2331
+ */
2332
+ export declare type TemplateVarsExtendFunction = (base: TemplateVars | undefined, values: VariableValue[]) => Result<TemplateVars | undefined>;
2333
+
2334
+ /**
2335
+ * Describes one value in a {@link TemplateVars | TemplateVars} collection of
2336
+ * variables.
2337
+ * @public
2338
+ */
2339
+ export declare type VariableValue = [string, unknown];
2340
+
2341
+ export { }