@fgv/ts-json 1.9.5 → 2.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ts-json.d.ts +1826 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +42 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/context/compositeJsonMap.d.ts +60 -0
- package/lib/packlets/context/compositeJsonMap.d.ts.map +1 -0
- package/lib/packlets/context/compositeJsonMap.js +105 -0
- package/lib/packlets/context/compositeJsonMap.js.map +1 -0
- package/lib/packlets/context/contextHelpers.d.ts +116 -0
- package/lib/packlets/context/contextHelpers.d.ts.map +1 -0
- package/lib/packlets/context/contextHelpers.js +191 -0
- package/lib/packlets/context/contextHelpers.js.map +1 -0
- package/lib/packlets/context/index.d.ts +4 -0
- package/lib/packlets/context/index.d.ts.map +1 -0
- package/lib/packlets/context/index.js +31 -0
- package/lib/packlets/context/index.js.map +1 -0
- package/lib/packlets/context/jsonContext.d.ts +84 -0
- package/lib/packlets/context/jsonContext.d.ts.map +1 -0
- package/lib/packlets/context/jsonContext.js +41 -0
- package/lib/packlets/context/jsonContext.js.map +1 -0
- package/lib/packlets/converters/converters.d.ts +54 -0
- package/lib/packlets/converters/converters.d.ts.map +1 -0
- package/lib/packlets/converters/converters.js +105 -0
- package/lib/packlets/converters/converters.js.map +1 -0
- package/lib/packlets/converters/file.d.ts +83 -0
- package/lib/packlets/converters/file.d.ts.map +1 -0
- package/lib/packlets/converters/file.js +162 -0
- package/lib/packlets/converters/file.js.map +1 -0
- package/lib/packlets/converters/index.d.ts +5 -0
- package/lib/packlets/converters/index.d.ts.map +1 -0
- package/{jsonEditor → lib/packlets/converters}/index.js +10 -10
- package/lib/packlets/converters/index.js.map +1 -0
- package/lib/packlets/converters/jsonConverter.d.ts +276 -0
- package/lib/packlets/converters/jsonConverter.d.ts.map +1 -0
- package/lib/packlets/converters/jsonConverter.js +310 -0
- package/lib/packlets/converters/jsonConverter.js.map +1 -0
- package/lib/packlets/editor/common.d.ts +67 -0
- package/lib/packlets/editor/common.d.ts.map +1 -0
- package/lib/packlets/editor/common.js +3 -0
- package/lib/packlets/editor/common.js.map +1 -0
- package/lib/packlets/editor/index.d.ts +8 -0
- package/lib/packlets/editor/index.d.ts.map +1 -0
- package/lib/packlets/editor/index.js +58 -0
- package/lib/packlets/editor/index.js.map +1 -0
- package/lib/packlets/editor/jsonEditor.d.ts +155 -0
- package/lib/packlets/editor/jsonEditor.d.ts.map +1 -0
- package/lib/packlets/editor/jsonEditor.js +333 -0
- package/lib/packlets/editor/jsonEditor.js.map +1 -0
- package/lib/packlets/editor/jsonEditorRule.d.ts +64 -0
- package/lib/packlets/editor/jsonEditorRule.d.ts.map +1 -0
- package/lib/packlets/editor/jsonEditorRule.js +54 -0
- package/lib/packlets/editor/jsonEditorRule.js.map +1 -0
- package/lib/packlets/editor/jsonEditorState.d.ts +125 -0
- package/lib/packlets/editor/jsonEditorState.d.ts.map +1 -0
- package/lib/packlets/editor/jsonEditorState.js +177 -0
- package/lib/packlets/editor/jsonEditorState.js.map +1 -0
- package/lib/packlets/editor/jsonReferenceMap.d.ts +303 -0
- package/lib/packlets/editor/jsonReferenceMap.d.ts.map +1 -0
- package/lib/packlets/editor/jsonReferenceMap.js +324 -0
- package/lib/packlets/editor/jsonReferenceMap.js.map +1 -0
- package/lib/packlets/editor/rules/conditional.d.ts +107 -0
- package/lib/packlets/editor/rules/conditional.d.ts.map +1 -0
- package/lib/packlets/editor/rules/conditional.js +167 -0
- package/lib/packlets/editor/rules/conditional.js.map +1 -0
- package/{jsonEditor → lib/packlets/editor}/rules/index.d.ts +1 -0
- package/lib/packlets/editor/rules/index.d.ts.map +1 -0
- package/lib/packlets/editor/rules/index.js +42 -0
- package/lib/packlets/editor/rules/index.js.map +1 -0
- package/lib/packlets/editor/rules/multivalue.d.ts +94 -0
- package/lib/packlets/editor/rules/multivalue.d.ts.map +1 -0
- package/lib/packlets/editor/rules/multivalue.js +141 -0
- package/lib/packlets/editor/rules/multivalue.js.map +1 -0
- package/lib/packlets/editor/rules/references.d.ts +69 -0
- package/lib/packlets/editor/rules/references.d.ts.map +1 -0
- package/lib/packlets/editor/rules/references.js +160 -0
- package/lib/packlets/editor/rules/references.js.map +1 -0
- package/lib/packlets/editor/rules/templates.d.ts +74 -0
- package/lib/packlets/editor/rules/templates.d.ts.map +1 -0
- package/lib/packlets/editor/rules/templates.js +127 -0
- package/lib/packlets/editor/rules/templates.js.map +1 -0
- package/lib/packlets/json/common.d.ts +85 -0
- package/lib/packlets/json/common.d.ts.map +1 -0
- package/lib/packlets/json/common.js +123 -0
- package/lib/packlets/json/common.js.map +1 -0
- package/lib/packlets/json/index.d.ts +2 -0
- package/lib/packlets/json/index.d.ts.map +1 -0
- package/lib/packlets/json/index.js +39 -0
- package/lib/packlets/json/index.js.map +1 -0
- package/package.json +57 -49
- package/common.d.ts +0 -58
- package/common.js +0 -116
- package/contextHelpers.d.ts +0 -21
- package/contextHelpers.js +0 -101
- package/converters.d.ts +0 -37
- package/converters.js +0 -92
- package/file.d.ts +0 -60
- package/file.js +0 -140
- package/index.d.ts +0 -9
- package/index.js +0 -61
- package/jsonContext.d.ts +0 -74
- package/jsonContext.js +0 -40
- package/jsonConverter.d.ts +0 -229
- package/jsonConverter.js +0 -292
- package/jsonEditor/common.d.ts +0 -36
- package/jsonEditor/common.js +0 -3
- package/jsonEditor/index.d.ts +0 -5
- package/jsonEditor/jsonEditor.d.ts +0 -74
- package/jsonEditor/jsonEditor.js +0 -259
- package/jsonEditor/jsonEditorRule.d.ts +0 -47
- package/jsonEditor/jsonEditorRule.js +0 -44
- package/jsonEditor/jsonEditorState.d.ts +0 -24
- package/jsonEditor/jsonEditorState.js +0 -86
- package/jsonEditor/rules/conditional.d.ts +0 -84
- package/jsonEditor/rules/conditional.js +0 -146
- package/jsonEditor/rules/index.js +0 -21
- package/jsonEditor/rules/multivalue.d.ts +0 -78
- package/jsonEditor/rules/multivalue.js +0 -129
- package/jsonEditor/rules/references.d.ts +0 -62
- package/jsonEditor/rules/references.js +0 -158
- package/jsonEditor/rules/templates.d.ts +0 -56
- package/jsonEditor/rules/templates.js +0 -115
- package/jsonReferenceMap.d.ts +0 -182
- package/jsonReferenceMap.js +0 -272
|
@@ -0,0 +1,1826 @@
|
|
|
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 { Result } from '@fgv/ts-utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Identifies whether some `unknown` value is a {@link JsonPrimitive | primitive},
|
|
9
|
+
* {@link JsonObject | object} or {@link JsonArray | array}. Fails for any value
|
|
10
|
+
* that cannot be converted to JSON (e.g. a function) _but_ this is a shallow test -
|
|
11
|
+
* it does not test the properties of an object or elements in an array.
|
|
12
|
+
* @param from - The `unknown` value to be tested
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare function classifyJsonValue(from: unknown): Result<JsonValueType>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A {@link CompositeJsonMap | CompositeJsonMap} presents a composed view of one or more other
|
|
19
|
+
* {@link IJsonReferenceMap | JSON reference maps}.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare class CompositeJsonMap implements IJsonReferenceMap {
|
|
23
|
+
/**
|
|
24
|
+
* The {@link IJsonReferenceMap | reference maps} from which this map is composed.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
protected _maps: IJsonReferenceMap[];
|
|
28
|
+
/**
|
|
29
|
+
* The {@link IJsonReferenceMap | reference maps} from which this map is to be composed.
|
|
30
|
+
* @param maps - An array o {@link IJsonReferenceMap | IJsonReferenceMap} containing the maps
|
|
31
|
+
* from which this map is to be composed.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
protected constructor(maps: IJsonReferenceMap[]);
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new {@link CompositeJsonMap | CompositeJsonMap} from supplied
|
|
37
|
+
* {@link IJsonReferenceMap | maps}.
|
|
38
|
+
* @param maps - one or more {@link IJsonReferenceMap | object maps} to be composed.
|
|
39
|
+
*/
|
|
40
|
+
static create(maps: IJsonReferenceMap[]): Result<CompositeJsonMap>;
|
|
41
|
+
/**
|
|
42
|
+
* Determine if a key might be valid for this map but does not determine
|
|
43
|
+
* if key actually exists. Allows key range to be constrained.
|
|
44
|
+
* @param key - The key to be tested.
|
|
45
|
+
* @returns `true` if the key is in the valid range, `false` otherwise.
|
|
46
|
+
*/
|
|
47
|
+
keyIsInRange(key: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Determines if an object with the specified key actually exists in the map.
|
|
50
|
+
* @param key - The key to be tested.
|
|
51
|
+
* @returns `true` if an object with the specified key exists, `false` otherwise.
|
|
52
|
+
*/
|
|
53
|
+
has(key: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Gets a {@link JsonObject | JSON object} specified by key.
|
|
56
|
+
* @param key - The key of the object to be retrieved.
|
|
57
|
+
* @param context - An optional {@link IJsonContext | JSON Context} used to format the object.
|
|
58
|
+
* @returns `Success` with the formatted object if successful. `Failure` with detail `'unknown'`
|
|
59
|
+
* if no such object exists, or `Failure` with detail `'error'` if the object was found but
|
|
60
|
+
* could not be formatted.
|
|
61
|
+
*/
|
|
62
|
+
getJsonObject(key: string, context?: IJsonContext): DetailedResult<JsonObject, JsonReferenceMapFailureReason>;
|
|
63
|
+
/**
|
|
64
|
+
* Gets a {@link JsonValue | JSON value} specified by key.
|
|
65
|
+
* @param key - The key of the object to be retrieved.
|
|
66
|
+
* @param context - An optional {@link IJsonContext | JSON Context} used to format the value.
|
|
67
|
+
* @returns `Success` with the formatted object if successful. `Failure` with detail `'unknown'`
|
|
68
|
+
* if no such object exists, or failure with detail `'error'` if the object was found but
|
|
69
|
+
* could not be formatted.
|
|
70
|
+
*/
|
|
71
|
+
getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
|
|
76
|
+
* supplied `unknown` to strongly-typed JSON, by first rendering any property
|
|
77
|
+
* names or string values using mustache with the supplied context, then applying
|
|
78
|
+
* multi-value property expansion and conditional flattening based on property names.
|
|
79
|
+
* @param options - {@link ConditionalJsonConverterOptions | Options and context} for
|
|
80
|
+
* the conversion.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
declare function conditionalJson(options?: Partial<ConditionalJsonConverterOptions>): JsonConverter;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache
|
|
87
|
+
* template rendering, multi-value property name and conditional property
|
|
88
|
+
* name rules enabled regardless of initial context.
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export declare class ConditionalJsonConverter extends JsonEditorConverter {
|
|
92
|
+
/**
|
|
93
|
+
* Default {@link IJsonConverterOptions | JSON converter options}
|
|
94
|
+
* to enable conditional conversion.
|
|
95
|
+
*/
|
|
96
|
+
static readonly conditionalOptions: Partial<IJsonConverterOptions>;
|
|
97
|
+
/**
|
|
98
|
+
* Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or
|
|
99
|
+
* default options.
|
|
100
|
+
* @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}
|
|
101
|
+
* for the converter.
|
|
102
|
+
*/
|
|
103
|
+
constructor(options?: Partial<ConditionalJsonConverterOptions>);
|
|
104
|
+
/**
|
|
105
|
+
* Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or
|
|
106
|
+
* default options.
|
|
107
|
+
* @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}
|
|
108
|
+
* for the converter.
|
|
109
|
+
*/
|
|
110
|
+
static create(options?: Partial<ConditionalJsonConverterOptions>): Result<JsonConverter>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Options for a {@link ConditionalJsonConverter | ConditionalJsonConverter}.
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export declare type ConditionalJsonConverterOptions = Omit<TemplatedJsonConverterOptions, 'useConditionalNames'>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The {@link Editor.Rules.ConditionalJsonEditorRule | ConditionalJsonEditorRule} evaluates
|
|
121
|
+
* properties with conditional keys, omitting non-matching keys and merging keys that match,
|
|
122
|
+
* or default keys only if no other keys match.
|
|
123
|
+
*
|
|
124
|
+
* The default syntax for a conditional key is:
|
|
125
|
+
* "?value1=value2" - matches if value1 and value2 are the same, is ignored otherwise.
|
|
126
|
+
* "?value" - matches if value is a non-empty, non-whitespace string. Is ignored otherwise.
|
|
127
|
+
* "?default" - matches only if no other conditional blocks in the same object were matched.
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
declare class ConditionalJsonEditorRule extends JsonEditorRuleBase {
|
|
131
|
+
/**
|
|
132
|
+
* Stored fully-resolved {@link Editor.Rules.IConditionalJsonRuleOptions | options} for this
|
|
133
|
+
* rule.
|
|
134
|
+
* @public
|
|
135
|
+
*/
|
|
136
|
+
protected _options?: IConditionalJsonRuleOptions;
|
|
137
|
+
/**
|
|
138
|
+
* Creates a new {@link Editor.Rules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}.
|
|
139
|
+
* @param options - Optional {@link Editor.Rules.IConditionalJsonRuleOptions | configuration options}
|
|
140
|
+
* used for this rule.
|
|
141
|
+
*/
|
|
142
|
+
constructor(options?: IConditionalJsonRuleOptions);
|
|
143
|
+
/**
|
|
144
|
+
* Creates a new {@link Editor.Rules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}.
|
|
145
|
+
* @param options - Optional {@link Editor.Rules.IConditionalJsonRuleOptions | configuration options}
|
|
146
|
+
* used for this rule.
|
|
147
|
+
*/
|
|
148
|
+
static create(options?: IConditionalJsonRuleOptions): Result<ConditionalJsonEditorRule>;
|
|
149
|
+
/**
|
|
150
|
+
* Evaluates a property for conditional application.
|
|
151
|
+
* @param key - The key of the property to be considered
|
|
152
|
+
* @param value - The {@link JsonValue | value} of the property to be considered.
|
|
153
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} for the object being edited.
|
|
154
|
+
* @returns Returns `Success` with detail `'deferred'` and a
|
|
155
|
+
* {@link Editor.Rules.IConditionalJsonDeferredObject | IConditionalJsonDeferredObject}.
|
|
156
|
+
* for a matching, default or unconditional key. Returns `Failure` with detail `'ignore'` for
|
|
157
|
+
* a non-matching conditional, or with detail `'error'` if an error occurs. Otherwise
|
|
158
|
+
* fails with detail `'inapplicable'`.
|
|
159
|
+
*/
|
|
160
|
+
editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
|
|
161
|
+
/**
|
|
162
|
+
* Finalizes any deferred conditional properties. If the only deferred property is
|
|
163
|
+
* default, that property is emitted. Otherwise all matching properties are emitted.
|
|
164
|
+
* @param finalized - The deferred properties to be considered for merge.
|
|
165
|
+
* @param __state - The {@link Editor.JsonEditorState | editor state} for the object
|
|
166
|
+
* being edited.
|
|
167
|
+
*/
|
|
168
|
+
finalizeProperties(finalized: JsonObject[], __state: JsonEditorState): DetailedResult<JsonObject[], JsonEditFailureReason>;
|
|
169
|
+
/**
|
|
170
|
+
* Determines if a given property key is conditional. Derived classes can override this
|
|
171
|
+
* method to use a different format for conditional properties.
|
|
172
|
+
* @param value - The {@link JsonValue | value} of the property to be considered.
|
|
173
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} for the object being edited.
|
|
174
|
+
* @returns `Success` with detail `'deferred'` and a
|
|
175
|
+
* {@link Editor.Rules.IConditionalJsonKeyResult | IConditionalJsonKeyResult} describing the
|
|
176
|
+
* match for a default or matching conditional property. Returns `Failure` with detail `'ignore'`
|
|
177
|
+
* for a non-matching conditional property. Fails with detail `'error'` if an error occurs
|
|
178
|
+
* or with detail `'inapplicable'` if the key does not represent a conditional property.
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
181
|
+
protected _tryParseCondition(key: string, state: JsonEditorState): DetailedResult<IConditionalJsonKeyResult, JsonPropertyEditFailureReason>;
|
|
182
|
+
/**
|
|
183
|
+
* Compares two strings using a supplied operator.
|
|
184
|
+
* @param left - The first string to be compared.
|
|
185
|
+
* @param right - The second string to be compared.
|
|
186
|
+
* @param operator - The operator to be applied.
|
|
187
|
+
* @returns `true` if the condition is met, `false` otherwise.
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
protected _compare(left: string, right: string, operator: string): boolean;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Creates a new {@link IJsonContext | JSON context} using values supplied in an optional partial
|
|
195
|
+
* {@link IJsonConverterOptions | converter options}.
|
|
196
|
+
* @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions} used to
|
|
197
|
+
* populate the context.
|
|
198
|
+
* @public
|
|
199
|
+
*/
|
|
200
|
+
export declare function contextFromConverterOptions(partial?: Partial<IJsonConverterOptions>): IJsonContext | undefined;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Creates a new {@link Editor.JsonEditor | JsonEditor} from an optionally supplied partial
|
|
204
|
+
* {@link IJsonConverterOptions | JSON converter options}.
|
|
205
|
+
* Expands supplied options with default values and constructs an editor with
|
|
206
|
+
* matching configuration and defined rules.
|
|
207
|
+
* @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions}
|
|
208
|
+
* used to create the editor.
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
export declare function converterOptionsToEditor(partial?: Partial<IJsonConverterOptions>): Result<JsonEditor>;
|
|
212
|
+
|
|
213
|
+
declare namespace Converters {
|
|
214
|
+
export {
|
|
215
|
+
templatedJson,
|
|
216
|
+
conditionalJson,
|
|
217
|
+
richJson,
|
|
218
|
+
json,
|
|
219
|
+
jsonObject,
|
|
220
|
+
jsonArray
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
export { Converters }
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Reads all JSON files from a directory and apply a supplied converter.
|
|
227
|
+
* @param srcPath - The path of the folder to be read.
|
|
228
|
+
* @param options - {@link Files.IDirectoryConvertOptions | Options} to control
|
|
229
|
+
* conversion and filtering
|
|
230
|
+
* @public
|
|
231
|
+
*/
|
|
232
|
+
declare function convertJsonDirectorySync<T>(srcPath: string, options: IDirectoryConvertOptions<T>): Result<IReadDirectoryItem<T>[]>;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Reads and converts all JSON files from a directory, returning a
|
|
236
|
+
* `Map<string, T>` indexed by file base name (i.e. minus the extension)
|
|
237
|
+
* with an optional name transformation applied if present.
|
|
238
|
+
* @param srcPath - The path of the folder to be read.
|
|
239
|
+
* @param options - {@link Files.IDirectoryToMapConvertOptions | Options} to control conversion,
|
|
240
|
+
* filtering and naming.
|
|
241
|
+
* @public
|
|
242
|
+
*/
|
|
243
|
+
declare function convertJsonDirectoryToMapSync<T, TC = unknown>(srcPath: string, options: IDirectoryToMapConvertOptions<T, TC>): Result<Map<string, T>>;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Convenience function to read a JSON file and apply a supplied converter.
|
|
247
|
+
* @param srcPath - Path of the file to read.
|
|
248
|
+
* @param converter - `Converter` used to convert the file contents
|
|
249
|
+
* @returns `Success` with a result of type `<T>`, or `Failure`
|
|
250
|
+
* with a message if an error occurs.
|
|
251
|
+
* @public
|
|
252
|
+
*/
|
|
253
|
+
declare function convertJsonFileSync<T>(srcPath: string, converter: Converter<T>): Result<T>;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* This default implementation of a {@link TemplateVarsExtendFunction | TemplateVarsExtendFunction}
|
|
257
|
+
* creates a new collection via inheritance from the supplied collection.
|
|
258
|
+
* @param base - The base {@link TemplateVars | variables} to be extended.
|
|
259
|
+
* @param values - The {@link VariableValue | values} to be added or overridden in the new variables.
|
|
260
|
+
* @public
|
|
261
|
+
*/
|
|
262
|
+
export declare function defaultExtendVars(base: TemplateVars | undefined, values: VariableValue[]): Result<TemplateVars | undefined>;
|
|
263
|
+
|
|
264
|
+
declare namespace EditorRules {
|
|
265
|
+
export {
|
|
266
|
+
IConditionalJsonKeyResult,
|
|
267
|
+
IConditionalJsonDeferredObject,
|
|
268
|
+
IConditionalJsonRuleOptions,
|
|
269
|
+
ConditionalJsonEditorRule,
|
|
270
|
+
IMultiValuePropertyParts,
|
|
271
|
+
MultiValueJsonEditorRule,
|
|
272
|
+
ReferenceJsonEditorRule,
|
|
273
|
+
ITemplatedJsonRuleOptions,
|
|
274
|
+
TemplatedJsonEditorRule
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
export { EditorRules }
|
|
278
|
+
|
|
279
|
+
declare namespace File_2 {
|
|
280
|
+
export {
|
|
281
|
+
readJsonFileSync,
|
|
282
|
+
convertJsonFileSync,
|
|
283
|
+
convertJsonDirectorySync,
|
|
284
|
+
convertJsonDirectoryToMapSync,
|
|
285
|
+
writeJsonFileSync,
|
|
286
|
+
IDirectoryConvertOptions,
|
|
287
|
+
IReadDirectoryItem,
|
|
288
|
+
ItemNameTransformFunction,
|
|
289
|
+
IDirectoryToMapConvertOptions
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
export { File_2 as File }
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* On a successful match, the {@link Editor.Rules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}
|
|
296
|
+
* stores a {@link Editor.Rules.IConditionalJsonDeferredObject | IConditionalJsonDeferredObject} describing the
|
|
297
|
+
* matching result, to be resolved at finalization time.
|
|
298
|
+
* @public
|
|
299
|
+
*/
|
|
300
|
+
declare interface IConditionalJsonDeferredObject extends IConditionalJsonKeyResult {
|
|
301
|
+
value: JsonValue;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Returned by {@link Editor.Rules.ConditionalJsonEditorRule._tryParseCondition | ConditionalJsonEditorRule._tryParseCondition}
|
|
306
|
+
* to indicate whether a successful match was due to a matching condition or a default value.
|
|
307
|
+
* @public
|
|
308
|
+
*/
|
|
309
|
+
declare interface IConditionalJsonKeyResult extends JsonObject {
|
|
310
|
+
matchType: 'default' | 'match' | 'unconditional';
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Configuration options for the {@link Editor.Rules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}.
|
|
315
|
+
* @public
|
|
316
|
+
*/
|
|
317
|
+
declare interface IConditionalJsonRuleOptions extends Partial<IJsonEditorOptions> {
|
|
318
|
+
/**
|
|
319
|
+
* If true (default) then properties with unconditional names
|
|
320
|
+
* (which start with !) are flattened.
|
|
321
|
+
*/
|
|
322
|
+
flattenUnconditionalValues?: boolean;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Options for directory conversion.
|
|
327
|
+
* TODO: add filtering, allowed and excluded.
|
|
328
|
+
* @public
|
|
329
|
+
*/
|
|
330
|
+
declare interface IDirectoryConvertOptions<T, TC = unknown> {
|
|
331
|
+
/**
|
|
332
|
+
* The converter used to convert incoming JSON objects.
|
|
333
|
+
*/
|
|
334
|
+
converter: Converter<T, TC>;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Options controlling conversion of a directory.
|
|
339
|
+
* @public
|
|
340
|
+
*/
|
|
341
|
+
declare interface IDirectoryToMapConvertOptions<T, TC = unknown> extends IDirectoryConvertOptions<T, TC> {
|
|
342
|
+
transformName?: ItemNameTransformFunction<T>;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* A specialized JSON editor which does a deep clone of a supplied {@link JsonValue | JsonValue}.
|
|
347
|
+
* @public
|
|
348
|
+
*/
|
|
349
|
+
declare interface IJsonCloneEditor {
|
|
350
|
+
/**
|
|
351
|
+
* Returns a deep clone of a supplied {@link JsonValue | JsonValue}.
|
|
352
|
+
* @param src - The {@link JsonValue | JsonValue} to be cloned.
|
|
353
|
+
* @param context - An optional {@link IJsonContext | JSON context} used for clone
|
|
354
|
+
* conversion operations.
|
|
355
|
+
*/
|
|
356
|
+
clone(src: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Context used to convert or edit JSON objects.
|
|
361
|
+
* @public
|
|
362
|
+
*/
|
|
363
|
+
export declare interface IJsonContext {
|
|
364
|
+
vars?: TemplateVars;
|
|
365
|
+
refs?: IJsonReferenceMap;
|
|
366
|
+
extendVars?: TemplateVarsExtendFunction;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Conversion options for {@link JsonConverter | JsonConverter}.
|
|
371
|
+
* @public
|
|
372
|
+
*/
|
|
373
|
+
export declare interface IJsonConverterOptions {
|
|
374
|
+
/**
|
|
375
|
+
* If `true` and if template variables are available,
|
|
376
|
+
* then string property values will be rendered using
|
|
377
|
+
* mustache and those variable values. Otherwise string
|
|
378
|
+
* properties are copied without modification.
|
|
379
|
+
*
|
|
380
|
+
* Defaults to `true` if vars are supplied with options,
|
|
381
|
+
* `false` otherwise.
|
|
382
|
+
*/
|
|
383
|
+
useValueTemplates: boolean;
|
|
384
|
+
/**
|
|
385
|
+
* If `true` and if template variables are available,
|
|
386
|
+
* then property names will be rendered using
|
|
387
|
+
* mustache and those variable values. Otherwise
|
|
388
|
+
* property names are copied without modification.
|
|
389
|
+
*
|
|
390
|
+
* Defaults to `true` if vars are supplied with options,
|
|
391
|
+
* `false` otherwise.
|
|
392
|
+
*/
|
|
393
|
+
useNameTemplates: boolean;
|
|
394
|
+
/**
|
|
395
|
+
* If `true` and if template variables are available,
|
|
396
|
+
* then string property names will be considered for
|
|
397
|
+
* conditionals.
|
|
398
|
+
*
|
|
399
|
+
* Default is to match {@link IJsonConverterOptions.useNameTemplates | useNameTemplates}.
|
|
400
|
+
*/
|
|
401
|
+
useConditionalNames: boolean;
|
|
402
|
+
/**
|
|
403
|
+
* If `true` (default) then properties with unconditional names
|
|
404
|
+
* (which start with !) are flattened.
|
|
405
|
+
*/
|
|
406
|
+
flattenUnconditionalValues: boolean;
|
|
407
|
+
/**
|
|
408
|
+
* If `true` and if both template variables and a
|
|
409
|
+
* context derivation function is available, then properties
|
|
410
|
+
* which match the multi-value name pattern will be expanded.
|
|
411
|
+
* Default matches {@link IJsonConverterOptions.useNameTemplates | useNameTemplates}.
|
|
412
|
+
*
|
|
413
|
+
* Default is `true` unless {@link IJsonConverterOptions.extendVars | extendVars} is
|
|
414
|
+
* explicitly set to `undefined`.
|
|
415
|
+
*/
|
|
416
|
+
useMultiValueTemplateNames: boolean;
|
|
417
|
+
/**
|
|
418
|
+
* The variables (mustache view) used to render templated string names
|
|
419
|
+
* and properties. See the mustache documentation for details of mustache
|
|
420
|
+
* syntax and the template view.
|
|
421
|
+
*/
|
|
422
|
+
vars?: TemplateVars;
|
|
423
|
+
/**
|
|
424
|
+
* Method used to extend variables for children of an array node during
|
|
425
|
+
* expansion. Default is to use a built-in extension function unless
|
|
426
|
+
* {@link IJsonConverterOptions.extendVars | extendVars} is explicitly set to undefined.
|
|
427
|
+
*/
|
|
428
|
+
extendVars?: TemplateVarsExtendFunction;
|
|
429
|
+
/**
|
|
430
|
+
* If `true` and if a {@link IJsonReferenceMap | references map} is supplied
|
|
431
|
+
* in {@link IJsonConverterOptions.refs | refs}, then references in the source
|
|
432
|
+
* object will be replaced with the corresponding value from the reference map.
|
|
433
|
+
*
|
|
434
|
+
* Default is `true` if {@link IJsonConverterOptions.refs | refs} are present in options,
|
|
435
|
+
* `false` otherwise.
|
|
436
|
+
*/
|
|
437
|
+
useReferences: boolean;
|
|
438
|
+
/**
|
|
439
|
+
* An optional {@link IJsonReferenceMap | reference map} used to insert any references
|
|
440
|
+
* in the converted JSON.
|
|
441
|
+
*/
|
|
442
|
+
refs?: IJsonReferenceMap;
|
|
443
|
+
/**
|
|
444
|
+
* If {@link IJsonConverterOptions.onInvalidPropertyName | onInvalidPropertyName} is `'error'`
|
|
445
|
+
* (default) then any property name that is invalid after template rendering causes an error
|
|
446
|
+
* and stops conversion. If {@link IJsonConverterOptions.onInvalidPropertyName | onInvalidPropertyName}
|
|
447
|
+
* is `'ignore'`, then names which are invalid after template rendering are passed through unchanged.
|
|
448
|
+
*/
|
|
449
|
+
onInvalidPropertyName: 'error' | 'ignore';
|
|
450
|
+
/**
|
|
451
|
+
* If {@link IJsonConverterOptions.onInvalidPropertyValue | onInvalidPropertyValue} is `'error'`
|
|
452
|
+
* (default) then any illegal property value causes an error and stops conversion. If
|
|
453
|
+
* {@link IJsonConverterOptions.onInvalidPropertyValue | onInvalidPropertyValue} is `'ignore'` then
|
|
454
|
+
* any invalid property values are silently ignored.
|
|
455
|
+
*/
|
|
456
|
+
onInvalidPropertyValue: 'error' | 'ignore';
|
|
457
|
+
/**
|
|
458
|
+
* If {@link IJsonConverterOptions.onUndefinedPropertyValue | onUndefinedPropertyValue} is `'error'`,
|
|
459
|
+
* then any property with value `undefined` will cause an error and stop conversion. If
|
|
460
|
+
* {@link IJsonConverterOptions.onUndefinedPropertyValue | onUndefinedPropertyValue} is `'ignore'` (default)
|
|
461
|
+
* then any property with value `undefined` is silently ignored.
|
|
462
|
+
*/
|
|
463
|
+
onUndefinedPropertyValue: 'error' | 'ignore';
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Initialization options for a {@link Editor.JsonEditor | JsonEditor}.
|
|
468
|
+
* @public
|
|
469
|
+
*/
|
|
470
|
+
export declare interface IJsonEditorOptions {
|
|
471
|
+
context?: IJsonContext;
|
|
472
|
+
validation: IJsonEditorValidationOptions;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* An {@link Editor.IJsonEditorRule | IJsonEditorRule} represents a single configurable
|
|
477
|
+
* rule to be applied by a {@link Editor.JsonEditor | JsonEditor}.
|
|
478
|
+
* @public
|
|
479
|
+
*/
|
|
480
|
+
export declare interface IJsonEditorRule {
|
|
481
|
+
/**
|
|
482
|
+
* Called by a {@link Editor.JsonEditor | JsonEditor} to possibly edit one of the properties being
|
|
483
|
+
* merged into a target object.
|
|
484
|
+
* @param key - The key of the property to be edited.
|
|
485
|
+
* @param value - The {@link JsonValue | value} of the property to be edited.
|
|
486
|
+
* @param state - {@link Editor.JsonEditorState | Editor state} which applies to the edit.
|
|
487
|
+
* @returns If the property was edited, returns `Success` with a {@link JsonObject | JsonObject} containing
|
|
488
|
+
* the edited results and with detail `'edited'`. If this property should be deferred for later consideration
|
|
489
|
+
* or merge, `Success` with detail `'deferred'` and a {@link JsonObject | JsonObject} to be finalized. If
|
|
490
|
+
* the rule does not affect this property, returns `Failure` with detail `'inapplicable'`. If an error occurred
|
|
491
|
+
* while processing the error, returns `Failure` with detail `'error'`.
|
|
492
|
+
*/
|
|
493
|
+
editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
|
|
494
|
+
/**
|
|
495
|
+
* Called by a {@link Editor.JsonEditor | JsonEditor} to possibly edit a property value or array element.
|
|
496
|
+
* @param value - The {@link JsonValue | value} of the property to be edited.
|
|
497
|
+
* @param state - {@link Editor.JsonEditorState | Editor state} which applies to the edit.
|
|
498
|
+
* @returns Returns `Success` with the {@link JsonValue | JsonValue} to be inserted, with detail `'edited'` if
|
|
499
|
+
* the value was edited. Returns `Failure` with `'inapplicable'` if the rule does not affect this value.
|
|
500
|
+
* Fails with detail `'ignore'` if the value is to be ignored, or with `'error'` if an error occurs.
|
|
501
|
+
*/
|
|
502
|
+
editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
503
|
+
/**
|
|
504
|
+
* Called for each rule after all properties have been merged. Any properties that were deferred
|
|
505
|
+
* during the initial edit pass are supplied as input.
|
|
506
|
+
* @param deferred - Any {@link JsonObject | objects} that were deferred during the first edit pass.
|
|
507
|
+
* @param state - {@link Editor.JsonEditorState | Editor state} which applies to the edit.
|
|
508
|
+
* @returns On `Success` return, any returned objects are merged in order and finalization
|
|
509
|
+
* is stopped. Finalization is also stopped on `Failure` with detail `'ignore'`. On `Failure`
|
|
510
|
+
* with detail `'inapplicable'`, finalization continues with the next rule. Fails with an
|
|
511
|
+
* error detail `'error'` and an informative message if an error occurs.
|
|
512
|
+
*/
|
|
513
|
+
finalizeProperties(deferred: JsonObject[], state: JsonEditorState): DetailedResult<JsonObject[], JsonEditFailureReason>;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Validation options for a {@link Editor.JsonEditor | JsonEditor}.
|
|
518
|
+
* @public
|
|
519
|
+
*/
|
|
520
|
+
export declare interface IJsonEditorValidationOptions {
|
|
521
|
+
/**
|
|
522
|
+
* If `onInvalidPropertyName` is `'error'` (default) then any property name
|
|
523
|
+
* that is invalid after template rendering causes an error and stops
|
|
524
|
+
* conversion. If `onInvalidPropertyName` is `'ignore'`, then names which
|
|
525
|
+
* are invalid after template rendering are passed through unchanged.
|
|
526
|
+
*/
|
|
527
|
+
onInvalidPropertyName: 'error' | 'ignore';
|
|
528
|
+
/**
|
|
529
|
+
* If `onInvalidPropertyValue` is `'error'` (default) then any illegal
|
|
530
|
+
* property value other than `undefined` causes an error and stops
|
|
531
|
+
* conversion. If `onInvalidPropertyValue` is `'ignore'` then any
|
|
532
|
+
* invalid property values are silently ignored.
|
|
533
|
+
*/
|
|
534
|
+
onInvalidPropertyValue: 'error' | 'ignore';
|
|
535
|
+
/**
|
|
536
|
+
* If `onUndefinedPropertyValue` is `'error'`, then any property with
|
|
537
|
+
* value `undefined` will cause an error and stop conversion. If
|
|
538
|
+
* `onUndefinedPropertyValue` is `'ignore'` (default) then any
|
|
539
|
+
* property with value `undefined` is silently ignored.
|
|
540
|
+
*/
|
|
541
|
+
onUndefinedPropertyValue: 'error' | 'ignore';
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Interface for a simple map that returns named {@link JsonValue | JsonValue} values with templating,
|
|
546
|
+
* conditional logic, and external reference lookups applied using an optionally supplied context.
|
|
547
|
+
* @public
|
|
548
|
+
*/
|
|
549
|
+
export declare interface IJsonReferenceMap {
|
|
550
|
+
/**
|
|
551
|
+
* Determine if a key might be valid for this map but does not determine if key actually
|
|
552
|
+
* exists. Allows key range to be constrained.
|
|
553
|
+
* @param key - The key to be tested.
|
|
554
|
+
* @returns `true` if the key is in the valid range, `false` otherwise.
|
|
555
|
+
*/
|
|
556
|
+
keyIsInRange(key: string): boolean;
|
|
557
|
+
/**
|
|
558
|
+
* Determines if an object with the specified key actually exists in the map.
|
|
559
|
+
* @param key - The key to be tested.
|
|
560
|
+
* @returns `true` if an object with the specified key exists, `false` otherwise.
|
|
561
|
+
*/
|
|
562
|
+
has(key: string): boolean;
|
|
563
|
+
/**
|
|
564
|
+
* Gets a {@link JsonObject | JsonObject} specified by key.
|
|
565
|
+
* @param key - The key of the object to be retrieved.
|
|
566
|
+
* @param context - Optional {@link IJsonContext | IJsonContext} used to construct
|
|
567
|
+
* the object.
|
|
568
|
+
* @returns `Success` with the formatted {@link JsonObject | object} if successful. `Failure`
|
|
569
|
+
* with detail `'unknown'` if no such object exists, or `Failure` with detail `'error'` if
|
|
570
|
+
* the object was found but could not be formatted.
|
|
571
|
+
*/
|
|
572
|
+
getJsonObject(key: string, context?: IJsonContext): DetailedResult<JsonObject, JsonReferenceMapFailureReason>;
|
|
573
|
+
/**
|
|
574
|
+
* Gets a {@link JsonValue | JsonValue} specified by key.
|
|
575
|
+
* @param key - The key of the object to be retrieved.
|
|
576
|
+
* @param context - Optional {@link IJsonContext | JSON Context} used to format the value
|
|
577
|
+
* @returns `Success` with the formatted {@link JsonValue | value} if successful. `Failure`
|
|
578
|
+
* with detail `'unknown'` if no such object exists, or `Failure` with detail `'error'` if
|
|
579
|
+
* the object was found but could not be formatted.
|
|
580
|
+
*/
|
|
581
|
+
getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Initialization options for a {@link PrefixedJsonMap | PrefixedJsonMap}
|
|
586
|
+
* @public
|
|
587
|
+
*/
|
|
588
|
+
declare interface IKeyPrefixOptions {
|
|
589
|
+
/**
|
|
590
|
+
* Indicates whether the prefix should be added automatically as needed (default true)
|
|
591
|
+
*/
|
|
592
|
+
addPrefix?: boolean;
|
|
593
|
+
/**
|
|
594
|
+
* The prefix to be enforced
|
|
595
|
+
*/
|
|
596
|
+
prefix: string;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Represents the parts of a multi-value property key.
|
|
601
|
+
* @public
|
|
602
|
+
*/
|
|
603
|
+
declare interface IMultiValuePropertyParts {
|
|
604
|
+
/**
|
|
605
|
+
* The original matched token.
|
|
606
|
+
*/
|
|
607
|
+
readonly token: string;
|
|
608
|
+
/**
|
|
609
|
+
* The name of the variable used to project each possible
|
|
610
|
+
* property value into the child values or objects being
|
|
611
|
+
* resolved.
|
|
612
|
+
*/
|
|
613
|
+
readonly propertyVariable: string;
|
|
614
|
+
/**
|
|
615
|
+
* The set of property values to be expanded.
|
|
616
|
+
*/
|
|
617
|
+
readonly propertyValues: string[];
|
|
618
|
+
/**
|
|
619
|
+
* If `true`, the resolved values are added as an array
|
|
620
|
+
* with the name of the {@link Editor.Rules.IMultiValuePropertyParts.propertyVariable | propertyVariable}.
|
|
621
|
+
* If false, values are added as individual properties with names that correspond the value.
|
|
622
|
+
*/
|
|
623
|
+
readonly asArray: boolean;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Return value for one item in a directory conversion.
|
|
628
|
+
* @public
|
|
629
|
+
*/
|
|
630
|
+
declare interface IReadDirectoryItem<T> {
|
|
631
|
+
/**
|
|
632
|
+
* Relative name of the file that was processed
|
|
633
|
+
*/
|
|
634
|
+
filename: string;
|
|
635
|
+
/**
|
|
636
|
+
* The payload of the file.
|
|
637
|
+
*/
|
|
638
|
+
item: T;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Options for creating a {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} object.
|
|
643
|
+
* @public
|
|
644
|
+
*/
|
|
645
|
+
export declare interface IReferenceMapKeyPolicyValidateOptions {
|
|
646
|
+
/**
|
|
647
|
+
* If `true`, the validator coerces keys to some valid value.
|
|
648
|
+
* If `false`, invalid keys cause an error.
|
|
649
|
+
*/
|
|
650
|
+
makeValid?: boolean;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Initialization options for a {@link SimpleJsonMap | SimpleJsonMap}.
|
|
655
|
+
* @public
|
|
656
|
+
*/
|
|
657
|
+
declare interface ISimpleJsonMapOptions {
|
|
658
|
+
keyPolicy?: ReferenceMapKeyPolicy<JsonValue>;
|
|
659
|
+
editor?: JsonEditor;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Test if an `unknown` is potentially a {@link JsonArray | JsonArray}.
|
|
664
|
+
* @param from - The `unknown` to be tested.
|
|
665
|
+
* @returns `true` if the supplied parameter is an array object,
|
|
666
|
+
* `false` otherwise.
|
|
667
|
+
* @public
|
|
668
|
+
*/
|
|
669
|
+
export declare function isJsonArray(from: unknown): from is JsonArray;
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Test if an `unknown` is potentially a {@link JsonObject | JsonObject}.
|
|
673
|
+
* @param from - The `unknown` to be tested.
|
|
674
|
+
* @returns `true` if the supplied parameter is a non-array, non-special object,
|
|
675
|
+
* `false` otherwise.
|
|
676
|
+
* @public
|
|
677
|
+
*/
|
|
678
|
+
export declare function isJsonObject(from: unknown): from is JsonObject;
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Test if an `unknown` is a {@link JsonValue | JsonValue}.
|
|
682
|
+
* @param from - The `unknown` to be tested
|
|
683
|
+
* @returns `true` if the supplied parameter is a valid {@link JsonPrimitive | JsonPrimitive},
|
|
684
|
+
* `false` otherwise.
|
|
685
|
+
* @public
|
|
686
|
+
*/
|
|
687
|
+
export declare function isJsonPrimitive(from: unknown): from is JsonPrimitive;
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Function to transform the name of a some entity, given an original name
|
|
691
|
+
* and the contents of the entity.
|
|
692
|
+
* @public
|
|
693
|
+
*/
|
|
694
|
+
declare type ItemNameTransformFunction<T> = (name: string, item: T) => Result<string>;
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Configuration options for the {@link Editor.Rules.TemplatedJsonEditorRule | Templated JSON editor rule}.
|
|
698
|
+
* @public
|
|
699
|
+
*/
|
|
700
|
+
declare interface ITemplatedJsonRuleOptions extends Partial<IJsonEditorOptions> {
|
|
701
|
+
/**
|
|
702
|
+
* If `true` (default) then templates in property names are rendered
|
|
703
|
+
*/
|
|
704
|
+
useNameTemplates?: boolean;
|
|
705
|
+
/**
|
|
706
|
+
* If `true` (default) then templates in property values are rendered
|
|
707
|
+
*/
|
|
708
|
+
useValueTemplates?: boolean;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* A simple validating {@link JsonConverter | JSON converter}. Converts unknown to
|
|
713
|
+
* JSON or fails if the unknown contains any invalid JSON values.
|
|
714
|
+
* @public
|
|
715
|
+
*/
|
|
716
|
+
declare const json: JsonConverter;
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* A {@link JsonArray | JsonArray} is an array containing only valid {@link JsonValue | JsonValues}.
|
|
720
|
+
* @public
|
|
721
|
+
*/
|
|
722
|
+
export declare interface JsonArray extends Array<JsonValue> {
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* A simple validating {@link JsonConverter | JSON converter}. Converts `unknown` to a
|
|
727
|
+
* {@link JsonArray | JsonArray}, or fails if the unknown contains invalid JSON or is
|
|
728
|
+
* not an array.
|
|
729
|
+
* @public
|
|
730
|
+
*/
|
|
731
|
+
declare const jsonArray: Converter<JsonArray, IJsonContext>;
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Helper class for working with {@link IJsonContext | IJsonContext} objects.
|
|
735
|
+
* @public
|
|
736
|
+
*/
|
|
737
|
+
export declare class JsonContextHelper {
|
|
738
|
+
/**
|
|
739
|
+
* The base {@link IJsonContext | context} on which we are operating.
|
|
740
|
+
* @internal
|
|
741
|
+
*/
|
|
742
|
+
protected _context?: IJsonContext;
|
|
743
|
+
/**
|
|
744
|
+
* Constructs a new {@link JsonContextHelper | JsonContextHelper}.
|
|
745
|
+
* @param context - The base {@link IJsonContext | IJsonContext} on
|
|
746
|
+
* which to operate.
|
|
747
|
+
*/
|
|
748
|
+
constructor(context?: IJsonContext);
|
|
749
|
+
/**
|
|
750
|
+
* Creates a new {@link IJsonContext | context}.
|
|
751
|
+
* @param context - The base {@link IJsonContext | IJsonContext} on
|
|
752
|
+
* which to operate.
|
|
753
|
+
* @returns `Success` with the new {@link IJsonContext | IJsonContext},
|
|
754
|
+
* or `Failure` with more information if an error occurs.
|
|
755
|
+
*/
|
|
756
|
+
static create(context?: IJsonContext): Result<JsonContextHelper>;
|
|
757
|
+
/**
|
|
758
|
+
* Static helper to extend context variables for a supplied {@link IJsonContext | IJsonContext}.
|
|
759
|
+
* @param baseContext - The {@link IJsonContext | IJsonContext} to be extended, or `undefined`
|
|
760
|
+
* to start from an empty context.
|
|
761
|
+
* @param vars - Optional {@link VariableValue | variable values} to be added to the
|
|
762
|
+
* {@link IJsonContext | context}.
|
|
763
|
+
* @returns `Success` with a new {@link TemplateVars | TemplateVars} containing the variables
|
|
764
|
+
* from the base context, merged with and overridden by any that were passed in, or `Failure`
|
|
765
|
+
* with a message if an error occurs.
|
|
766
|
+
*/
|
|
767
|
+
static extendContextVars(baseContext: IJsonContext | undefined, vars?: VariableValue[]): Result<TemplateVars | undefined>;
|
|
768
|
+
/**
|
|
769
|
+
* Static helper to extend context references for a supplied {@link IJsonContext | IJsonContext}.
|
|
770
|
+
* @param baseContext - The {@link IJsonContext | IJsonContext} to be extended, or `undefined`
|
|
771
|
+
* to start from an empty context.
|
|
772
|
+
* @param refs - Optional {@link IJsonReferenceMap | reference maps} to be added to the
|
|
773
|
+
* {@link IJsonContext | context}.
|
|
774
|
+
* @returns `Success` with a new {@link IJsonReferenceMap | reference map} which projects
|
|
775
|
+
* the references from the base context, merged with and overridden by any that were passed in,
|
|
776
|
+
* or `Failure` with a message if an error occurs.
|
|
777
|
+
*/
|
|
778
|
+
static extendContextRefs(baseContext: IJsonContext | undefined, refs?: IJsonReferenceMap[]): Result<IJsonReferenceMap | undefined>;
|
|
779
|
+
/**
|
|
780
|
+
* Static helper to extend context variables and references for a supplied {@link IJsonContext | IJsonContext}.
|
|
781
|
+
* @param baseContext - The {@link IJsonContext | IJsonContext} to be extended, or `undefined`
|
|
782
|
+
* to start from an empty context.
|
|
783
|
+
* @param add - Optional initializer containing {@link VariableValue | variable values} and/or
|
|
784
|
+
* {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
|
|
785
|
+
* @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
|
|
786
|
+
* references from the base context, merged with and overridden by any that were passed in, or
|
|
787
|
+
* `Failure` with a message if an error occurs.
|
|
788
|
+
*/
|
|
789
|
+
static extendContext(baseContext?: IJsonContext | undefined, add?: {
|
|
790
|
+
vars?: VariableValue[];
|
|
791
|
+
refs?: IJsonReferenceMap[];
|
|
792
|
+
}): Result<IJsonContext | undefined>;
|
|
793
|
+
/**
|
|
794
|
+
* Static helper to merge context variables and references for a supplied {@link IJsonContext | IJsonContext}.
|
|
795
|
+
* @param baseContext - The {@link IJsonContext | IJsonContext} into which variables and references
|
|
796
|
+
* are to be merged, or `undefined` to start from an empty context.
|
|
797
|
+
* @param add - Optional initializer containing {@link VariableValue | variable values} and/or
|
|
798
|
+
* {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
|
|
799
|
+
* @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
|
|
800
|
+
* references from the base context, merged with and overridden by any that were passed in, or
|
|
801
|
+
* `Failure` with a message if an error occurs.
|
|
802
|
+
*/
|
|
803
|
+
static mergeContext(baseContext: IJsonContext | undefined, add: IJsonContext | undefined): Result<IJsonContext | undefined>;
|
|
804
|
+
/**
|
|
805
|
+
* Applies {@link JsonContextHelper.extendContextVars | extendContextVars} to the
|
|
806
|
+
* {@link IJsonContext | IJsonContext} associated with this helper.
|
|
807
|
+
* @param vars - Optional {@link VariableValue | variable values} to be added to the
|
|
808
|
+
* @returns `Success` with a new {@link TemplateVars | TemplateVars} containing the variables
|
|
809
|
+
* from the base context, merged with and overridden by any that were passed in, or `Failure`
|
|
810
|
+
* with a message if an error occurs.
|
|
811
|
+
*/
|
|
812
|
+
extendVars(vars?: VariableValue[]): Result<TemplateVars | undefined>;
|
|
813
|
+
/**
|
|
814
|
+
* Applies {@link JsonContextHelper.extendContextRefs | extendContextRefs} to the
|
|
815
|
+
* {@link IJsonContext | IJsonContext} associated with this helper.
|
|
816
|
+
* @param refs - Optional {@link IJsonReferenceMap | reference maps} to be added to the
|
|
817
|
+
* @returns `Success` with a new {@link IJsonReferenceMap | reference map} which projects
|
|
818
|
+
* the references from the base context, merged with and overridden by any that were passed in,
|
|
819
|
+
* or `Failure` with a message if an error occurs.
|
|
820
|
+
*/
|
|
821
|
+
extendRefs(refs?: IJsonReferenceMap[]): Result<IJsonReferenceMap | undefined>;
|
|
822
|
+
/**
|
|
823
|
+
* Applies {@link JsonContextHelper.(extendContext:static) | extendContext} to the
|
|
824
|
+
* {@link IJsonContext | IJsonContext} associated with this helper.
|
|
825
|
+
* @param add - Optional initializer containing {@link VariableValue | variable values} and/or
|
|
826
|
+
* {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
|
|
827
|
+
* @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
|
|
828
|
+
* references from the base context, merged with and overridden by any that were passed in, or
|
|
829
|
+
* `Failure` with a message if an error occurs.
|
|
830
|
+
*/
|
|
831
|
+
extendContext(add?: {
|
|
832
|
+
vars?: VariableValue[];
|
|
833
|
+
refs?: IJsonReferenceMap[];
|
|
834
|
+
}): Result<IJsonContext | undefined>;
|
|
835
|
+
/**
|
|
836
|
+
* Applies {@link JsonContextHelper.(mergeContext:static) | mergeContext} to the
|
|
837
|
+
* {@link IJsonContext | IJsonContext} associated with this helper.
|
|
838
|
+
* @param add - Optional initializer containing {@link VariableValue | variable values} and/or
|
|
839
|
+
* {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
|
|
840
|
+
* @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
|
|
841
|
+
* references from the base context, merged with and overridden by any that were passed in, or
|
|
842
|
+
* `Failure` with a message if an error occurs.
|
|
843
|
+
*/
|
|
844
|
+
mergeContext(merge?: IJsonContext): Result<IJsonContext | undefined>;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON, optionally
|
|
849
|
+
* rendering any string property names or values using mustache with a supplied view.
|
|
850
|
+
* @public
|
|
851
|
+
*/
|
|
852
|
+
export declare class JsonConverter extends JsonEditorConverter {
|
|
853
|
+
/**
|
|
854
|
+
* Constructs a new {@link JsonConverter | JsonConverter} with
|
|
855
|
+
* supplied or default options.
|
|
856
|
+
* @param options - Optional partial {@link IJsonConverterOptions | options}
|
|
857
|
+
* to configure the converter.
|
|
858
|
+
*/
|
|
859
|
+
constructor(options?: Partial<IJsonConverterOptions>);
|
|
860
|
+
/**
|
|
861
|
+
* Creates a new {@link JsonConverter | JsonConverter}.
|
|
862
|
+
* @param options - Optional partial {@link IJsonConverterOptions | options}
|
|
863
|
+
* to configure the converter.
|
|
864
|
+
* @returns `Success` with a new {@link JsonConverter | JsonConverter}, or `Failure`
|
|
865
|
+
* with an informative message if an error occurs.
|
|
866
|
+
*/
|
|
867
|
+
static create(options?: Partial<IJsonConverterOptions>): Result<JsonConverter>;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Possible `DetailedResult` details for various editor operations.
|
|
872
|
+
* @public
|
|
873
|
+
*/
|
|
874
|
+
export declare type JsonEditFailureReason = 'ignore' | 'inapplicable' | 'edited' | 'error';
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* A {@link JsonEditor | JsonEditor} can be used to edit JSON objects in place or to
|
|
878
|
+
* clone any JSON value, applying a default context and optional set of editor rules that
|
|
879
|
+
* were supplied at initialization.
|
|
880
|
+
* @public
|
|
881
|
+
*/
|
|
882
|
+
export declare class JsonEditor implements IJsonCloneEditor {
|
|
883
|
+
/**
|
|
884
|
+
* Default singleton {@link Editor.JsonEditor | JsonEditor}.
|
|
885
|
+
* @internal
|
|
886
|
+
*/
|
|
887
|
+
protected static _default?: JsonEditor;
|
|
888
|
+
/**
|
|
889
|
+
* Full set of {@link Editor.IJsonEditorOptions | editor options} in effect for this editor.
|
|
890
|
+
*/
|
|
891
|
+
options: IJsonEditorOptions;
|
|
892
|
+
/**
|
|
893
|
+
* The set of {@link Editor.IJsonEditorRule | editor rules} applied by this editor.
|
|
894
|
+
* @internal
|
|
895
|
+
*/
|
|
896
|
+
protected _rules: IJsonEditorRule[];
|
|
897
|
+
/**
|
|
898
|
+
* Protected constructor for {@link Editor.JsonEditor | JsonEditor} and derived classes.
|
|
899
|
+
* External consumers should instantiate via the {@link Editor.JsonEditor.create | create static method}.
|
|
900
|
+
* @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for the
|
|
901
|
+
* constructed editor.
|
|
902
|
+
* @param rules - Any {@link Editor.IJsonEditorRule | editor rules} to be applied by the editor.
|
|
903
|
+
* @internal
|
|
904
|
+
*/
|
|
905
|
+
protected constructor(options?: Partial<IJsonEditorOptions>, rules?: IJsonEditorRule[]);
|
|
906
|
+
/**
|
|
907
|
+
* Default singleton {@link Editor.JsonEditor | JsonEditor} for simple use. Applies all rules
|
|
908
|
+
* but with no default context.
|
|
909
|
+
*/
|
|
910
|
+
static get default(): JsonEditor;
|
|
911
|
+
/**
|
|
912
|
+
* Constructs a new {@link Editor.JsonEditor | JsonEditor}.
|
|
913
|
+
* @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for the
|
|
914
|
+
* constructed editor.
|
|
915
|
+
* @param rules - Optional set of {@link Editor.IJsonEditorRule | editor rules} to be applied by the editor.
|
|
916
|
+
* @readonly A new {@link Editor.JsonEditor | JsonEditor}.
|
|
917
|
+
*/
|
|
918
|
+
static create(options?: Partial<IJsonEditorOptions>, rules?: IJsonEditorRule[]): Result<JsonEditor>;
|
|
919
|
+
/**
|
|
920
|
+
* Gets the default set of rules to be applied for a given set of options.
|
|
921
|
+
* By default, all available rules (templates, conditionals, multi-value and references)
|
|
922
|
+
* are applied.
|
|
923
|
+
* @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for
|
|
924
|
+
* all rules.
|
|
925
|
+
* @returns Default {@link Editor.IJsonEditorRule | editor rules} with any supplied options
|
|
926
|
+
* applied.
|
|
927
|
+
*/
|
|
928
|
+
static getDefaultRules(options?: IJsonEditorOptions): Result<IJsonEditorRule[]>;
|
|
929
|
+
/**
|
|
930
|
+
* @internal
|
|
931
|
+
*/
|
|
932
|
+
protected static _getDefaultOptions(options?: Partial<IJsonEditorOptions>): Result<IJsonEditorOptions>;
|
|
933
|
+
/**
|
|
934
|
+
* Merges a supplied source object into a supplied target, updating the target object.
|
|
935
|
+
* @param target - The target {@link JsonObject | object} to be updated
|
|
936
|
+
* @param src - The source {@link JsonObject | object} to be merged
|
|
937
|
+
* @param runtimeContext - An optional {@link IJsonContext | IJsonContext} supplying variables
|
|
938
|
+
* and references.
|
|
939
|
+
* @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
|
|
940
|
+
* Returns `Failure` with details if an error occurs.
|
|
941
|
+
*/
|
|
942
|
+
mergeObjectInPlace(target: JsonObject, src: JsonObject, runtimeContext?: IJsonContext): Result<JsonObject>;
|
|
943
|
+
/**
|
|
944
|
+
* Merges multiple supplied source objects into a supplied target, updating the target
|
|
945
|
+
* object and using the default context supplied at creation time.
|
|
946
|
+
* @param target - The target {@link JsonObject | object} to be updated
|
|
947
|
+
* @param srcObjects - {@link JsonObject | Objects} to be merged into the target object, in the order
|
|
948
|
+
* supplied.
|
|
949
|
+
* @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
|
|
950
|
+
* Returns `Failure` with details if an error occurs.
|
|
951
|
+
*/
|
|
952
|
+
mergeObjectsInPlace(target: JsonObject, srcObjects: JsonObject[]): Result<JsonObject>;
|
|
953
|
+
/**
|
|
954
|
+
* Merges multiple supplied source objects into a supplied target, updating the target
|
|
955
|
+
* object and using an optional {@link IJsonContext | context} supplied in the call.
|
|
956
|
+
* @param context - An optional {@link IJsonContext | IJsonContext} supplying variables and
|
|
957
|
+
* references.
|
|
958
|
+
* @param base - The base {@link JsonObject | object} to be updated
|
|
959
|
+
* @param srcObjects - Objects to be merged into the target object, in the order supplied.
|
|
960
|
+
* @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
|
|
961
|
+
* Returns `Failure` with details if an error occurs.
|
|
962
|
+
*/
|
|
963
|
+
mergeObjectsInPlaceWithContext(context: IJsonContext | undefined, base: JsonObject, srcObjects: JsonObject[]): Result<JsonObject>;
|
|
964
|
+
/**
|
|
965
|
+
* Deep clones a supplied {@link JsonValue | JSON value}, applying all editor rules and a default
|
|
966
|
+
* or optionally supplied context
|
|
967
|
+
* @param src - The {@link JsonValue | JsonValue} to be cloned.
|
|
968
|
+
* @param context - An optional {@link IJsonContext | JSON context} supplying variables and references.
|
|
969
|
+
*/
|
|
970
|
+
clone(src: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
971
|
+
/**
|
|
972
|
+
*
|
|
973
|
+
* @param target -
|
|
974
|
+
* @param src -
|
|
975
|
+
* @param state -
|
|
976
|
+
* @returns
|
|
977
|
+
* @internal
|
|
978
|
+
*/
|
|
979
|
+
protected _mergeObjectInPlace(target: JsonObject, src: JsonObject, state: JsonEditorState): Result<JsonObject>;
|
|
980
|
+
/**
|
|
981
|
+
*
|
|
982
|
+
* @param src -
|
|
983
|
+
* @param context -
|
|
984
|
+
* @returns
|
|
985
|
+
* @internal
|
|
986
|
+
*/
|
|
987
|
+
protected _cloneArray(src: JsonArray, context?: IJsonContext): DetailedResult<JsonArray, JsonEditFailureReason>;
|
|
988
|
+
/**
|
|
989
|
+
*
|
|
990
|
+
* @param target -
|
|
991
|
+
* @param key -
|
|
992
|
+
* @param newValue -
|
|
993
|
+
* @param state -
|
|
994
|
+
* @returns
|
|
995
|
+
* @internal
|
|
996
|
+
*/
|
|
997
|
+
protected _mergeClonedProperty(target: JsonObject, key: string, newValue: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
998
|
+
/**
|
|
999
|
+
*
|
|
1000
|
+
* @param key -
|
|
1001
|
+
* @param value -
|
|
1002
|
+
* @param state -
|
|
1003
|
+
* @returns
|
|
1004
|
+
* @internal
|
|
1005
|
+
*/
|
|
1006
|
+
protected _editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
|
|
1007
|
+
/**
|
|
1008
|
+
*
|
|
1009
|
+
* @param value -
|
|
1010
|
+
* @param state -
|
|
1011
|
+
* @returns
|
|
1012
|
+
* @internal
|
|
1013
|
+
*/
|
|
1014
|
+
protected _editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
1015
|
+
/**
|
|
1016
|
+
*
|
|
1017
|
+
* @param target -
|
|
1018
|
+
* @param state -
|
|
1019
|
+
* @returns
|
|
1020
|
+
* @internal
|
|
1021
|
+
*/
|
|
1022
|
+
protected _finalizeAndMerge(target: JsonObject, state: JsonEditorState): DetailedResult<JsonObject, JsonEditFailureReason>;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* A thin wrapper to allow an arbitrary {@link Editor.JsonEditor | JsonEditor} to be used via the
|
|
1027
|
+
* \@fgv/ts-utils `Converter` pattern.
|
|
1028
|
+
* @public
|
|
1029
|
+
*/
|
|
1030
|
+
export declare class JsonEditorConverter extends Conversion.BaseConverter<JsonValue, IJsonContext> {
|
|
1031
|
+
readonly editor: JsonEditor;
|
|
1032
|
+
/**
|
|
1033
|
+
* Constructs a new {@link Editor.JsonEditor | JsonEditor}Converter which uses the supplied editor
|
|
1034
|
+
* @param editor -
|
|
1035
|
+
*/
|
|
1036
|
+
constructor(editor: JsonEditor);
|
|
1037
|
+
/**
|
|
1038
|
+
* Constructs a new {@link Editor.JsonEditor | JsonEditor}Converter which uses the supplied editor
|
|
1039
|
+
* @param editor -
|
|
1040
|
+
*/
|
|
1041
|
+
static createWithEditor(editor: JsonEditor): Result<JsonEditorConverter>;
|
|
1042
|
+
/**
|
|
1043
|
+
* Gets a derived converter which fails if the resulting converted
|
|
1044
|
+
* {@link JsonValue | JsonValue} is not a {@link JsonObject | JsonObject}.
|
|
1045
|
+
*/
|
|
1046
|
+
object(): Converter<JsonObject, IJsonContext>;
|
|
1047
|
+
/**
|
|
1048
|
+
* Gets a derived converter which fails if the resulting converted
|
|
1049
|
+
* {@link JsonValue | JsonValue} is not a {@link JsonArray | JsonArray}.
|
|
1050
|
+
*/
|
|
1051
|
+
array(): Converter<JsonArray, IJsonContext>;
|
|
1052
|
+
protected _convert(from: unknown, context?: IJsonContext): Result<JsonValue>;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Default base implementation of {@link Editor.IJsonEditorRule | IJsonEditorRule} returns inapplicable for all operations so that
|
|
1057
|
+
* derived classes need only implement the operations they actually support.
|
|
1058
|
+
* @public
|
|
1059
|
+
*/
|
|
1060
|
+
declare class JsonEditorRuleBase implements IJsonEditorRule {
|
|
1061
|
+
/**
|
|
1062
|
+
* {@inheritdoc Editor.IJsonEditorRule.editProperty}
|
|
1063
|
+
*/
|
|
1064
|
+
editProperty(__key: string, __value: JsonValue, __state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
|
|
1065
|
+
/**
|
|
1066
|
+
* {@inheritdoc Editor.IJsonEditorRule.editValue}
|
|
1067
|
+
*/
|
|
1068
|
+
editValue(__value: JsonValue, __state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
1069
|
+
/**
|
|
1070
|
+
* {@inheritdoc Editor.IJsonEditorRule.finalizeProperties}
|
|
1071
|
+
*/
|
|
1072
|
+
finalizeProperties(__deferred: JsonObject[], __state: JsonEditorState): DetailedResult<JsonObject[], JsonEditFailureReason>;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* Represents the internal state of a {@link Editor.JsonEditor | JsonEditor}.
|
|
1077
|
+
* @public
|
|
1078
|
+
*/
|
|
1079
|
+
export declare class JsonEditorState {
|
|
1080
|
+
/**
|
|
1081
|
+
* Static global counter used to assign each {@link Editor.JsonEditorState | JsonEditorState}
|
|
1082
|
+
* a unique identifier.
|
|
1083
|
+
* @internal
|
|
1084
|
+
*/
|
|
1085
|
+
protected static _nextId: number;
|
|
1086
|
+
/**
|
|
1087
|
+
* The {@link Editor.IJsonCloneEditor | editor} for which this state applies.
|
|
1088
|
+
*/
|
|
1089
|
+
readonly editor: IJsonCloneEditor;
|
|
1090
|
+
/**
|
|
1091
|
+
* Fully resolved {@link Editor.IJsonEditorOptions | editor options} that apply
|
|
1092
|
+
* to the operation for which this state applies.
|
|
1093
|
+
*/
|
|
1094
|
+
readonly options: IJsonEditorOptions;
|
|
1095
|
+
/**
|
|
1096
|
+
* Any deferred {@link JsonObject | objects} to be merged during finalization.
|
|
1097
|
+
* @internal
|
|
1098
|
+
*/
|
|
1099
|
+
protected readonly _deferred: JsonObject[];
|
|
1100
|
+
/**
|
|
1101
|
+
* Unique global identifier for this {@link Editor.JsonEditorState | state object}.
|
|
1102
|
+
* @internal
|
|
1103
|
+
*/
|
|
1104
|
+
protected readonly _id: number;
|
|
1105
|
+
/**
|
|
1106
|
+
* Constructs a new {@link Editor.JsonEditorState | JsonEditorState}.
|
|
1107
|
+
* @param editor - The {@link Editor.IJsonCloneEditor | editor} to which this state
|
|
1108
|
+
* applies.
|
|
1109
|
+
* @param baseOptions - The {@link Editor.IJsonEditorOptions | editor options} that
|
|
1110
|
+
* apply to this rule.
|
|
1111
|
+
* @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used
|
|
1112
|
+
* for json value conversion.
|
|
1113
|
+
*/
|
|
1114
|
+
constructor(editor: IJsonCloneEditor, baseOptions: IJsonEditorOptions, runtimeContext?: IJsonContext);
|
|
1115
|
+
/**
|
|
1116
|
+
* The optional {@link IJsonContext | JSON context} for this state.
|
|
1117
|
+
*/
|
|
1118
|
+
get context(): IJsonContext | undefined;
|
|
1119
|
+
/**
|
|
1120
|
+
* An array of {@link JsonObject | objects} that are deferred for merge during
|
|
1121
|
+
* finalization.
|
|
1122
|
+
*/
|
|
1123
|
+
get deferred(): JsonObject[];
|
|
1124
|
+
/**
|
|
1125
|
+
* Merges an optional {@link IJsonContext | JSON context} into a supplied set
|
|
1126
|
+
* of {@link Editor.IJsonEditorOptions | JSON editor options}.
|
|
1127
|
+
* @param options - The {@link Editor.IJsonEditorOptions | IJsonEditorOptions} into
|
|
1128
|
+
* which the the new context is to be merged.
|
|
1129
|
+
* @param context - The {@link IJsonContext | JSON context} to be merged into the
|
|
1130
|
+
* editor options.
|
|
1131
|
+
* @returns `Success` with the supplied {@link Editor.IJsonEditorOptions | options} if
|
|
1132
|
+
* there was nothing to merge, or aa new {@link Editor.IJsonEditorOptions | IJsonEditorOptions}
|
|
1133
|
+
* constructed from the base options merged with the supplied context. Returns `Failure`
|
|
1134
|
+
* with more information if an error occurs.
|
|
1135
|
+
* @internal
|
|
1136
|
+
*/
|
|
1137
|
+
protected static _getEffectiveOptions(options: IJsonEditorOptions, context?: IJsonContext): Result<IJsonEditorOptions>;
|
|
1138
|
+
/**
|
|
1139
|
+
* Adds a supplied {@link JsonObject | object} to the deferred list.
|
|
1140
|
+
* @param obj - The {@link JsonObject | object} to be deferred.
|
|
1141
|
+
*/
|
|
1142
|
+
defer(obj: JsonObject): void;
|
|
1143
|
+
/**
|
|
1144
|
+
* Gets a {@link TemplateVars | TemplateVars} from the context of this {@link Editor.JsonEditorState | JsonEditorState},
|
|
1145
|
+
* or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default
|
|
1146
|
+
* context.
|
|
1147
|
+
* @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`
|
|
1148
|
+
* if the current state does not have context.
|
|
1149
|
+
* @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or
|
|
1150
|
+
* `undefined` if no vars are found.
|
|
1151
|
+
*/
|
|
1152
|
+
getVars(defaultContext?: IJsonContext): TemplateVars | undefined;
|
|
1153
|
+
/**
|
|
1154
|
+
* Gets an {@link IJsonReferenceMap | reference map} containing any other values
|
|
1155
|
+
* referenced during the operation.
|
|
1156
|
+
* @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as
|
|
1157
|
+
* {@link TemplateVars | TemplateVars} if the current state does not have context.
|
|
1158
|
+
* @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced
|
|
1159
|
+
* during this operation.
|
|
1160
|
+
*/
|
|
1161
|
+
getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined;
|
|
1162
|
+
/**
|
|
1163
|
+
* Gets the context of this {@link Editor.JsonEditorState | JsonEditorState} or an optionally
|
|
1164
|
+
* supplied default context if this state has no context.
|
|
1165
|
+
* @param defaultContext - The default {@link IJsonContext | JSON context} to use as default
|
|
1166
|
+
* if this state has no context.
|
|
1167
|
+
* @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context
|
|
1168
|
+
* is available.
|
|
1169
|
+
*/
|
|
1170
|
+
getContext(defaultContext?: IJsonContext): IJsonContext | undefined;
|
|
1171
|
+
/**
|
|
1172
|
+
* Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables
|
|
1173
|
+
* and references into a supplied existing context.
|
|
1174
|
+
* @param baseContext - The {@link IJsonContext | IJsonContext} into which variables
|
|
1175
|
+
* and references are to be merged, or `undefined` to start with a default empty context.
|
|
1176
|
+
* @param add - The {@link VariableValue | variable values} and/or
|
|
1177
|
+
* {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.
|
|
1178
|
+
* @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.
|
|
1179
|
+
*/
|
|
1180
|
+
extendContext(baseContext: IJsonContext | undefined, add: {
|
|
1181
|
+
vars?: VariableValue[];
|
|
1182
|
+
refs?: IJsonReferenceMap[];
|
|
1183
|
+
}): Result<IJsonContext | undefined>;
|
|
1184
|
+
/**
|
|
1185
|
+
* Helper method to constructs `DetailedFailure` with appropriate details and messaging
|
|
1186
|
+
* for various validation failures.
|
|
1187
|
+
* @param rule - The {@link Editor.JsonEditorValidationRules | validation rule} that failed.
|
|
1188
|
+
* @param message - A string message describing the failed validation.
|
|
1189
|
+
* @param validation - The {@link Editor.IJsonEditorValidationOptions | validation options}
|
|
1190
|
+
* in effect.
|
|
1191
|
+
* @returns A `DetailedFailure` with appropriate detail and message.
|
|
1192
|
+
*/
|
|
1193
|
+
failValidation<T = JsonObject>(rule: JsonEditorValidationRules, message?: string, validation?: IJsonEditorValidationOptions): DetailedFailure<T, JsonEditFailureReason>;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
/**
|
|
1197
|
+
* Possible validation rules for a {@link Editor.JsonEditor | JsonEditor}.
|
|
1198
|
+
* @public
|
|
1199
|
+
*/
|
|
1200
|
+
declare type JsonEditorValidationRules = 'invalidPropertyName' | 'invalidPropertyValue' | 'undefinedPropertyValue';
|
|
1201
|
+
|
|
1202
|
+
/**
|
|
1203
|
+
* A {@link JsonObject | JsonObject} is a string-keyed object
|
|
1204
|
+
* containing only valid {@link JsonValue | JSON values}.
|
|
1205
|
+
* @public
|
|
1206
|
+
*/
|
|
1207
|
+
export declare interface JsonObject {
|
|
1208
|
+
[key: string]: JsonValue;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
/**
|
|
1212
|
+
* A simple validating {@link JsonConverter | JSON converter}. Converts unknown
|
|
1213
|
+
* to a {@link JsonObject | JsonObject}, or fails if the `unknown` contains invalid
|
|
1214
|
+
* JSON or is not an object.
|
|
1215
|
+
* @public
|
|
1216
|
+
*/
|
|
1217
|
+
declare const jsonObject: Converter<JsonObject, IJsonContext>;
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Primitive (terminal) values allowed in by JSON.
|
|
1221
|
+
* @public
|
|
1222
|
+
*/
|
|
1223
|
+
export declare type JsonPrimitive = boolean | number | string | null;
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* Possible `DetailedResult` details for property edit operations.
|
|
1227
|
+
* @public
|
|
1228
|
+
*/
|
|
1229
|
+
export declare type JsonPropertyEditFailureReason = JsonEditFailureReason | 'deferred';
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* Failure reason for {@link IJsonReferenceMap | IJsonReferenceMap} lookup, where `'unknown'`
|
|
1233
|
+
* means that the object is not present in the map and `'error'` means
|
|
1234
|
+
* that an error occurred while retrieving or converting it.
|
|
1235
|
+
* @public
|
|
1236
|
+
*/
|
|
1237
|
+
export declare type JsonReferenceMapFailureReason = 'unknown' | 'error';
|
|
1238
|
+
|
|
1239
|
+
/**
|
|
1240
|
+
* A {@link JsonValue | JsonValue} is one of: a {@link JsonPrimitive | JsonPrimitive},
|
|
1241
|
+
* a {@link JsonObject | JsonObject} or an {@link JsonArray | JsonArray}.
|
|
1242
|
+
* @public
|
|
1243
|
+
*/
|
|
1244
|
+
export declare type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
1245
|
+
|
|
1246
|
+
/**
|
|
1247
|
+
* Classes of {@link JsonValue | JsonValue}.
|
|
1248
|
+
* @public
|
|
1249
|
+
*/
|
|
1250
|
+
export declare type JsonValueType = 'primitive' | 'object' | 'array';
|
|
1251
|
+
|
|
1252
|
+
/**
|
|
1253
|
+
* Type representing either a `Map\<string, T\>` or a `Record\<string, T\>`.
|
|
1254
|
+
* @public
|
|
1255
|
+
*/
|
|
1256
|
+
declare type MapOrRecord<T> = Map<string, T> | Record<string, T>;
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Merges an optionally supplied partial set of {@link IJsonConverterOptions | options} with
|
|
1260
|
+
* the default converter options and taking all dynamic rules into account (e.g. template usage enabled
|
|
1261
|
+
* if variables are supplied and disabled if not), producing a fully-resolved set of
|
|
1262
|
+
* {@link IJsonConverterOptions | IJsonConverterOptions}.
|
|
1263
|
+
* @param partial - An optional partial {@link IJsonConverterOptions | IJsonConverterOptions}
|
|
1264
|
+
* to be merged.
|
|
1265
|
+
* @public
|
|
1266
|
+
*/
|
|
1267
|
+
export declare function mergeDefaultJsonConverterOptions(partial?: Partial<IJsonConverterOptions>): IJsonConverterOptions;
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* The {@link Editor.Rules.MultiValueJsonEditorRule | Multi-Value JSON editor rule}
|
|
1271
|
+
* expands matching keys multiple times, projecting the value into the template
|
|
1272
|
+
* context for any child objects rendered by the rule.
|
|
1273
|
+
*
|
|
1274
|
+
* The default syntax for a multi-value key is:
|
|
1275
|
+
* "[[var]]=value1,value2,value3"
|
|
1276
|
+
* Where "var" is the name of the variable that will be passed to
|
|
1277
|
+
* child template resolution, and "value1,value2,value3" is a
|
|
1278
|
+
* comma-separated list of values to be expanded.
|
|
1279
|
+
* @public
|
|
1280
|
+
*/
|
|
1281
|
+
declare class MultiValueJsonEditorRule extends JsonEditorRuleBase {
|
|
1282
|
+
/**
|
|
1283
|
+
* Stored fully-resolved {@link Editor.IJsonEditorOptions | editor options}
|
|
1284
|
+
* for this rule.
|
|
1285
|
+
* @public
|
|
1286
|
+
*/
|
|
1287
|
+
protected _options?: IJsonEditorOptions;
|
|
1288
|
+
/**
|
|
1289
|
+
* Creates a new {@link Editor.Rules.MultiValueJsonEditorRule | MultiValueJsonEditorRule}.
|
|
1290
|
+
* @param options - Optional {@link Editor.IJsonEditorOptions | configuration options}.
|
|
1291
|
+
*/
|
|
1292
|
+
constructor(options?: IJsonEditorOptions);
|
|
1293
|
+
/**
|
|
1294
|
+
* Creates a new {@link Editor.Rules.MultiValueJsonEditorRule | MultiValueJsonEditorRule}.
|
|
1295
|
+
* @param options - Optional {@link Editor.IJsonEditorOptions | configuration options}.
|
|
1296
|
+
*/
|
|
1297
|
+
static create(options?: IJsonEditorOptions): Result<MultiValueJsonEditorRule>;
|
|
1298
|
+
/**
|
|
1299
|
+
* Evaluates a property for multi-value expansion.
|
|
1300
|
+
* @param key - The key of the property to be considered
|
|
1301
|
+
* @param value - The {@link JsonValue | value} of the property to be considered.
|
|
1302
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} for the object being edited.
|
|
1303
|
+
* @returns `Success` with an object containing the fully-resolved child values to be merged for
|
|
1304
|
+
* matching multi-value property. Returns `Failure` with detail `'error'` if an error occurs or
|
|
1305
|
+
* with detail `'inapplicable'` if the property key is not a conditional property.
|
|
1306
|
+
*/
|
|
1307
|
+
editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
|
|
1308
|
+
/**
|
|
1309
|
+
* Extends the {@link IJsonContext | current context} with a supplied state and values.
|
|
1310
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} for the object being edited.
|
|
1311
|
+
* @param values - An array of {@link VariableValue | VariableValue} to be added to the
|
|
1312
|
+
* context.
|
|
1313
|
+
* @returns The extended {@link IJsonContext | context}.
|
|
1314
|
+
* @public
|
|
1315
|
+
*/
|
|
1316
|
+
protected _deriveContext(state: JsonEditorState, ...values: VariableValue[]): Result<IJsonContext | undefined>;
|
|
1317
|
+
/**
|
|
1318
|
+
* Determines if a given property key is multi-value. Derived classes can override this
|
|
1319
|
+
* method to use a different format for multi-value properties.
|
|
1320
|
+
* @param value - The {@link JsonValue | value} of the property to be considered.
|
|
1321
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} for the object being edited.
|
|
1322
|
+
* @returns `Success` with detail `'deferred'` and an
|
|
1323
|
+
* {@link Editor.Rules.IMultiValuePropertyParts | IMultiValuePropertyParts}
|
|
1324
|
+
* describing the match for matching multi-value property. Returns `Failure` with detail `'error'` if an error occurs
|
|
1325
|
+
* or with detail `'inapplicable'` if the key does not represent a multi-value property.
|
|
1326
|
+
* @public
|
|
1327
|
+
*/
|
|
1328
|
+
protected _tryParse(token: string, state: JsonEditorState): DetailedResult<IMultiValuePropertyParts, JsonEditFailureReason>;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* Picks a nested {@link JsonObject | JsonObject} from a supplied
|
|
1333
|
+
* {@link JsonObject | JsonObject}.
|
|
1334
|
+
* @param src - The {@link JsonObject | object} from which the field is
|
|
1335
|
+
* to be picked.
|
|
1336
|
+
* @param path - Dot-separated path of the member to be picked.
|
|
1337
|
+
* @returns `Success` with the property if the path is valid and the value
|
|
1338
|
+
* is an object. Returns `Failure` with details if an error occurs.
|
|
1339
|
+
* @public
|
|
1340
|
+
*/
|
|
1341
|
+
export declare function pickJsonObject(src: JsonObject, path: string): Result<JsonObject>;
|
|
1342
|
+
|
|
1343
|
+
/**
|
|
1344
|
+
* Picks a nested field from a supplied {@link JsonObject | JsonObject}.
|
|
1345
|
+
* @param src - The {@link JsonObject | object} from which the field is to be picked.
|
|
1346
|
+
* @param path - Dot-separated path of the member to be picked.
|
|
1347
|
+
* @returns `Success` with the property if the path is valid, `Failure`
|
|
1348
|
+
* with an error message otherwise.
|
|
1349
|
+
* @public
|
|
1350
|
+
*/
|
|
1351
|
+
export declare function pickJsonValue(src: JsonObject, path: string): Result<JsonValue>;
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* A {@link PrefixedJsonMap | PrefixedJsonMap} enforces a supplied prefix for all contained values,
|
|
1355
|
+
* optionally adding the prefix as necessary (default `true`).
|
|
1356
|
+
* @public
|
|
1357
|
+
*/
|
|
1358
|
+
export declare class PrefixedJsonMap extends SimpleJsonMap {
|
|
1359
|
+
/**
|
|
1360
|
+
* Constructs a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
|
|
1361
|
+
* @param prefix - A string prefix to be enforced for and added to key names as necessary
|
|
1362
|
+
* @param values - A string-keyed Map or Record of the {@link JsonValue | JsonValue} to be returned
|
|
1363
|
+
* @param context - Optional {@link IJsonContext | JSON Context} used to format returned values
|
|
1364
|
+
* @param editor - Optional {@link Editor.JsonEditor | JsonEditor} used to format returned values
|
|
1365
|
+
* @public
|
|
1366
|
+
*/
|
|
1367
|
+
protected constructor(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions);
|
|
1368
|
+
/**
|
|
1369
|
+
* Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
|
|
1370
|
+
* @param prefix - A string prefix to be enforced for and added to key names as necessary
|
|
1371
|
+
* @param values - A string-keyed Map or Record of the {@link JsonValue | JsonValue} to be returned
|
|
1372
|
+
* @param context - Optional {@link IJsonContext | JSON Context} used to format returned values
|
|
1373
|
+
* @param editor - Optional {@link Editor.JsonEditor | JsonEditor} used to format returned values
|
|
1374
|
+
* @returns `Success` with a {@link PrefixedJsonMap | PrefixedJsonMap} or `Failure` with a message
|
|
1375
|
+
* if an error occurs.
|
|
1376
|
+
*/
|
|
1377
|
+
static createPrefixed(prefix: string, values?: MapOrRecord<JsonValue>, context?: IJsonContext, editor?: JsonEditor): Result<PrefixedJsonMap>;
|
|
1378
|
+
/**
|
|
1379
|
+
* Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
|
|
1380
|
+
* @param prefixOptions - A KeyPrefixOptions indicating the prefix to enforce and whether that prefix should
|
|
1381
|
+
* be added automatically if necessary (default true)
|
|
1382
|
+
* @param values - A string-keyed Map or record of the {@link JsonValue | JsonValue} to be returned
|
|
1383
|
+
* @param context - Optional {@link IJsonContext | JSON Context} used to format returned values
|
|
1384
|
+
* @param editor - Optional {@link Editor.JsonEditor | JsonEditor} used to format returned values
|
|
1385
|
+
*/
|
|
1386
|
+
static createPrefixed(prefixOptions: IKeyPrefixOptions, values?: MapOrRecord<JsonValue>, context?: IJsonContext, editor?: JsonEditor): Result<PrefixedJsonMap>;
|
|
1387
|
+
/**
|
|
1388
|
+
* Constructs a new {@link PrefixKeyPolicy | PrefixKeyPolicy} from a supplied prefix
|
|
1389
|
+
* or set of {@link IKeyPrefixOptions | prefix options}.
|
|
1390
|
+
* @param prefixOptions - The prefix or {@link IKeyPrefixOptions | prefix options} or options
|
|
1391
|
+
* for the new policy.
|
|
1392
|
+
* @returns A new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} which enforces the
|
|
1393
|
+
* supplied prefix or options.
|
|
1394
|
+
* @internal
|
|
1395
|
+
*/
|
|
1396
|
+
protected static _toPolicy(prefixOptions: string | IKeyPrefixOptions): ReferenceMapKeyPolicy<JsonValue>;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
/**
|
|
1400
|
+
* Convenience function to read type-safe JSON from a file
|
|
1401
|
+
* @param srcPath - Path of the file to read
|
|
1402
|
+
* @returns `Success` with a {@link JsonValue | JsonValue} or `Failure`
|
|
1403
|
+
* with a message if an error occurs.
|
|
1404
|
+
* @public
|
|
1405
|
+
*/
|
|
1406
|
+
declare function readJsonFileSync(srcPath: string): Result<JsonValue>;
|
|
1407
|
+
|
|
1408
|
+
/**
|
|
1409
|
+
* The {@link Editor.Rules.ReferenceJsonEditorRule | Reference JSON editor rule} replaces property
|
|
1410
|
+
* keys or values that match some known object with a copy of that referenced object, formatted
|
|
1411
|
+
* according to the current context.
|
|
1412
|
+
*
|
|
1413
|
+
* A property key is matched if it matches any known referenced value.
|
|
1414
|
+
* - If the value of the matched key is `'default'`, then the entire object is formatted
|
|
1415
|
+
* with the current context, flattened and merged into the current object.
|
|
1416
|
+
* - If the value of the matched key is some other string, then the entire
|
|
1417
|
+
* object is formatted with the current context, and the child of the resulting
|
|
1418
|
+
* object at the specified path is flattened and merged into the current object.
|
|
1419
|
+
* - If the value of the matched key is an object, then the entire object is
|
|
1420
|
+
* formatted with the current context extended to include any properties of
|
|
1421
|
+
* that object, flattened, and merged into the current object.
|
|
1422
|
+
* - It is an error if the referenced value is not an object.
|
|
1423
|
+
*
|
|
1424
|
+
* Any property, array or literal value is matched if it matches any known
|
|
1425
|
+
* value reference. The referenced value is replaced by the referenced
|
|
1426
|
+
* value, formatted using the current editor context.
|
|
1427
|
+
* @public
|
|
1428
|
+
*/
|
|
1429
|
+
declare class ReferenceJsonEditorRule extends JsonEditorRuleBase {
|
|
1430
|
+
/**
|
|
1431
|
+
* Stored fully-resolved {@link Editor.IJsonEditorOptions | editor options} for this rule.
|
|
1432
|
+
* @public
|
|
1433
|
+
*/
|
|
1434
|
+
protected _options?: IJsonEditorOptions;
|
|
1435
|
+
/**
|
|
1436
|
+
* Creates a new {@link Editor.Rules.ReferenceJsonEditorRule | ReferenceJsonEditorRule}.
|
|
1437
|
+
* @param options - Optional {@link Editor.IJsonEditorOptions | configuration options} for this rule.
|
|
1438
|
+
*/
|
|
1439
|
+
constructor(options?: IJsonEditorOptions);
|
|
1440
|
+
/**
|
|
1441
|
+
* Creates a new {@link Editor.Rules.ReferenceJsonEditorRule | ReferenceJsonEditorRule}.
|
|
1442
|
+
* @param options - Optional {@link Editor.IJsonEditorOptions | configuration options} for this rule.
|
|
1443
|
+
*/
|
|
1444
|
+
static create(options?: IJsonEditorOptions): Result<ReferenceJsonEditorRule>;
|
|
1445
|
+
/**
|
|
1446
|
+
* Evaluates a property for reference expansion.
|
|
1447
|
+
* @param key - The key of the property to be considered.
|
|
1448
|
+
* @param value - The {@link JsonValue | value} of the property to be considered.
|
|
1449
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} for the object being edited.
|
|
1450
|
+
* @returns If the reference is successful, returns `Success` with a {@link JsonObject | JsonObject}
|
|
1451
|
+
* to be flattened and merged into the current object. Returns `Failure` with detail `'inapplicable'`
|
|
1452
|
+
* for non-reference keys or with detail `'error'` if an error occurs.
|
|
1453
|
+
*/
|
|
1454
|
+
editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
|
|
1455
|
+
/**
|
|
1456
|
+
* Evaluates a property, array or literal value for reference replacement.
|
|
1457
|
+
* @param value - The {@link JsonValue | value} of the property to be considered.
|
|
1458
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} for the object being edited.
|
|
1459
|
+
*/
|
|
1460
|
+
editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
1461
|
+
/**
|
|
1462
|
+
* Gets the template variables to use given the value of some property whose name matched a
|
|
1463
|
+
* resource plus the base template context.
|
|
1464
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} to be extended.
|
|
1465
|
+
* @param supplied - The string or object supplied in the source json.
|
|
1466
|
+
* @internal
|
|
1467
|
+
*/
|
|
1468
|
+
protected _extendContext(state: JsonEditorState, supplied: JsonValue): Result<IJsonContext | undefined>;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
/**
|
|
1472
|
+
* Policy object responsible for validating or correcting
|
|
1473
|
+
* keys in a {@link IJsonReferenceMap | reference map}.
|
|
1474
|
+
* @public
|
|
1475
|
+
*/
|
|
1476
|
+
export declare class ReferenceMapKeyPolicy<T> {
|
|
1477
|
+
/**
|
|
1478
|
+
* @internal
|
|
1479
|
+
*/
|
|
1480
|
+
protected readonly _defaultOptions?: IReferenceMapKeyPolicyValidateOptions;
|
|
1481
|
+
/**
|
|
1482
|
+
* @internal
|
|
1483
|
+
*/
|
|
1484
|
+
protected readonly _isValid: (key: string, item?: T) => boolean;
|
|
1485
|
+
/**
|
|
1486
|
+
* Constructs a new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy}.
|
|
1487
|
+
* @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options}
|
|
1488
|
+
* used to construct the {@link ReferenceMapKeyPolicy}.
|
|
1489
|
+
* @param isValid - An optional predicate to test a supplied key for validity.
|
|
1490
|
+
*/
|
|
1491
|
+
constructor(options?: IReferenceMapKeyPolicyValidateOptions, isValid?: (key: string, item?: T) => boolean);
|
|
1492
|
+
/**
|
|
1493
|
+
* The static default key name validation predicate rejects keys that contain
|
|
1494
|
+
* mustache templates or which start with the default conditional prefix
|
|
1495
|
+
* `'?'`.
|
|
1496
|
+
* @param key - The key to test.
|
|
1497
|
+
* @returns `true` if the key is valid, `false` otherwise.
|
|
1498
|
+
*/
|
|
1499
|
+
static defaultKeyPredicate(key: string): boolean;
|
|
1500
|
+
/**
|
|
1501
|
+
* Determines if a supplied key and item are valid according to the current policy.
|
|
1502
|
+
* @param key - The key to be tested.
|
|
1503
|
+
* @param item - The item to be tested.
|
|
1504
|
+
* @returns `true` if the key and value are valid, `false` otherwise.
|
|
1505
|
+
*/
|
|
1506
|
+
isValid(key: string, item?: T): boolean;
|
|
1507
|
+
/**
|
|
1508
|
+
* Determines if a supplied key and item are valid according to the current policy.
|
|
1509
|
+
* @param key - The key to be tested.
|
|
1510
|
+
* @param item - The item to be tested.
|
|
1511
|
+
* @returns `Success` with the key if valid, `Failure` with an error message if invalid.
|
|
1512
|
+
*/
|
|
1513
|
+
validate(key: string, item?: T, __options?: IReferenceMapKeyPolicyValidateOptions): Result<string>;
|
|
1514
|
+
/**
|
|
1515
|
+
* Validates an array of entries using the validation rules for this policy.
|
|
1516
|
+
* @param items - The array of entries to be validated.
|
|
1517
|
+
* @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control
|
|
1518
|
+
* validation.
|
|
1519
|
+
* @returns `Success` with an array of validated entries, or `Failure` with an error message
|
|
1520
|
+
* if validation fails.
|
|
1521
|
+
*/
|
|
1522
|
+
validateItems(items: [string, T][], options?: IReferenceMapKeyPolicyValidateOptions): Result<[string, T][]>;
|
|
1523
|
+
/**
|
|
1524
|
+
* Validates a `Map\<string, T\>` using the validation rules for this policy.
|
|
1525
|
+
* @param items - The `Map\<string, T\>` to be validated.
|
|
1526
|
+
* @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control
|
|
1527
|
+
* validation.
|
|
1528
|
+
* @returns `Success` with a new `Map\<string, T\>`, or `Failure` with an error message
|
|
1529
|
+
* if validation fails.
|
|
1530
|
+
*/
|
|
1531
|
+
validateMap(map: Map<string, T>, options?: IReferenceMapKeyPolicyValidateOptions): Result<Map<string, T>>;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
/**
|
|
1535
|
+
* Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
|
|
1536
|
+
* supplied `unknown` to strongly-typed JSON, by first rendering any property
|
|
1537
|
+
* names or string values using mustache with the supplied context, then applying
|
|
1538
|
+
* multi-value property expansion and conditional flattening based on property names.
|
|
1539
|
+
* @param options - {@link RichJsonConverterOptions | Options and context} for
|
|
1540
|
+
* the conversion.
|
|
1541
|
+
* @public
|
|
1542
|
+
*/
|
|
1543
|
+
declare function richJson(options?: Partial<RichJsonConverterOptions>): JsonConverter;
|
|
1544
|
+
|
|
1545
|
+
/**
|
|
1546
|
+
* A \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache
|
|
1547
|
+
* template rendering, multi-value property name, conditional property
|
|
1548
|
+
* name, and external reference rules enabled regardless of initial context.
|
|
1549
|
+
* @public
|
|
1550
|
+
*/
|
|
1551
|
+
export declare class RichJsonConverter extends JsonEditorConverter {
|
|
1552
|
+
/**
|
|
1553
|
+
* Default {@link IJsonConverterOptions | JSON converter options}
|
|
1554
|
+
* to enable rich conversion.
|
|
1555
|
+
*/
|
|
1556
|
+
static readonly richOptions: Partial<IJsonConverterOptions>;
|
|
1557
|
+
/**
|
|
1558
|
+
* Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or
|
|
1559
|
+
* default options.
|
|
1560
|
+
* @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}
|
|
1561
|
+
* for the converter.
|
|
1562
|
+
*/
|
|
1563
|
+
constructor(options?: Partial<RichJsonConverterOptions>);
|
|
1564
|
+
/**
|
|
1565
|
+
* Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or
|
|
1566
|
+
* default options
|
|
1567
|
+
* @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}
|
|
1568
|
+
* for the converter.
|
|
1569
|
+
*/
|
|
1570
|
+
static create(options?: Partial<RichJsonConverterOptions>): Result<JsonConverter>;
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
/**
|
|
1574
|
+
* Initialization options for a {@link RichJsonConverter | RichJsonConverter}.
|
|
1575
|
+
* @public
|
|
1576
|
+
*/
|
|
1577
|
+
export declare type RichJsonConverterOptions = Omit<ConditionalJsonConverterOptions, 'useReferences'>;
|
|
1578
|
+
|
|
1579
|
+
/**
|
|
1580
|
+
* A {@link SimpleJsonMap | SimpleJsonMap } presents a view of a simple map
|
|
1581
|
+
* of {@link JsonValue | JSON values}.
|
|
1582
|
+
* @public
|
|
1583
|
+
*/
|
|
1584
|
+
export declare class SimpleJsonMap extends SimpleJsonMapBase<JsonValue> {
|
|
1585
|
+
/**
|
|
1586
|
+
* @internal
|
|
1587
|
+
*/
|
|
1588
|
+
protected _editor?: JsonEditor;
|
|
1589
|
+
/**
|
|
1590
|
+
* Constructs a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects
|
|
1591
|
+
* @param values - A string-keyed `Map` or `Record` of the {@link JsonValue | JSON values}
|
|
1592
|
+
* to be returned.
|
|
1593
|
+
* @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.
|
|
1594
|
+
* @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.
|
|
1595
|
+
* @public
|
|
1596
|
+
*/
|
|
1597
|
+
protected constructor(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions);
|
|
1598
|
+
/**
|
|
1599
|
+
* Creates a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects
|
|
1600
|
+
* @param values - A string-keyed `Map` or `Record` of the {@link JsonValue | JSON values}
|
|
1601
|
+
* to be returned.
|
|
1602
|
+
* @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.
|
|
1603
|
+
* @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.
|
|
1604
|
+
* @returns `Success` with a {@link SimpleJsonMap | SimpleJsonMap} or `Failure` with a message if
|
|
1605
|
+
* an error occurs.
|
|
1606
|
+
*/
|
|
1607
|
+
static createSimple(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions): Result<SimpleJsonMap>;
|
|
1608
|
+
/**
|
|
1609
|
+
* Gets a {@link JsonValue | JSON value} specified by key.
|
|
1610
|
+
* @param key - key of the value to be retrieved
|
|
1611
|
+
* @param context - Optional {@link IJsonContext | JSON context} used to format the value
|
|
1612
|
+
* @returns Success with the formatted object if successful. Failure with detail 'unknown'
|
|
1613
|
+
* if no such object exists, or failure with detail 'error' if the object was found but
|
|
1614
|
+
* could not be formatted.
|
|
1615
|
+
*/
|
|
1616
|
+
getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
|
|
1617
|
+
/**
|
|
1618
|
+
* @internal
|
|
1619
|
+
*/
|
|
1620
|
+
protected _clone(value: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
/**
|
|
1624
|
+
* Abstract base class with common functionality for simple
|
|
1625
|
+
* {@link IJsonReferenceMap | reference map} implementations.
|
|
1626
|
+
* {@link JsonValue | json values}.
|
|
1627
|
+
* @public
|
|
1628
|
+
*/
|
|
1629
|
+
declare abstract class SimpleJsonMapBase<T> implements IJsonReferenceMap {
|
|
1630
|
+
/**
|
|
1631
|
+
* The {@link ReferenceMapKeyPolicy | key policy} in effect for this map.
|
|
1632
|
+
* @internal
|
|
1633
|
+
*/
|
|
1634
|
+
protected readonly _keyPolicy: ReferenceMapKeyPolicy<T>;
|
|
1635
|
+
/**
|
|
1636
|
+
* A map containing keys and values already present in this map.
|
|
1637
|
+
* @internal
|
|
1638
|
+
*/
|
|
1639
|
+
protected readonly _values: Map<string, T>;
|
|
1640
|
+
/**
|
|
1641
|
+
* An optional {@link IJsonContext | IJsonContext} used for any conversions
|
|
1642
|
+
* involving items in this map.
|
|
1643
|
+
* @internal
|
|
1644
|
+
*/
|
|
1645
|
+
protected readonly _context?: IJsonContext;
|
|
1646
|
+
/**
|
|
1647
|
+
* Constructs a new {@link SimpleJsonMap | SimpleJsonMap}.
|
|
1648
|
+
* @param values - Initial values for the map.
|
|
1649
|
+
* @param context - An optional {@link IJsonContext | IJsonContext} used for any conversions
|
|
1650
|
+
* involving items in this map.
|
|
1651
|
+
* @param keyPolicy - The {@link ReferenceMapKeyPolicy | key policy} to use for this map.
|
|
1652
|
+
* @internal
|
|
1653
|
+
*/
|
|
1654
|
+
protected constructor(values?: MapOrRecord<T>, context?: IJsonContext, keyPolicy?: ReferenceMapKeyPolicy<T>);
|
|
1655
|
+
/**
|
|
1656
|
+
* Returns a `Map\<string, T\>` derived from a supplied {@link MapOrRecord | MapOrRecord}
|
|
1657
|
+
* @param values - The {@link MapOrRecord | MapOrRecord} to be returned as a map.
|
|
1658
|
+
* @returns `Success` with the corresponding `Map\<string, T\>` or `Failure` with a
|
|
1659
|
+
* message if an error occurs.
|
|
1660
|
+
* @internal
|
|
1661
|
+
*/
|
|
1662
|
+
protected static _toMap<T>(values?: MapOrRecord<T>): Result<Map<string, T>>;
|
|
1663
|
+
/**
|
|
1664
|
+
* Determine if a key might be valid for this map but does not determine if key actually
|
|
1665
|
+
* exists. Allows key range to be constrained.
|
|
1666
|
+
* @param key - key to be tested
|
|
1667
|
+
* @returns `true` if the key is in the valid range, `false` otherwise.
|
|
1668
|
+
*/
|
|
1669
|
+
keyIsInRange(key: string): boolean;
|
|
1670
|
+
/**
|
|
1671
|
+
* Determines if an entry with the specified key actually exists in the map.
|
|
1672
|
+
* @param key - key to be tested
|
|
1673
|
+
* @returns `true` if an object with the specified key exists, `false` otherwise.
|
|
1674
|
+
*/
|
|
1675
|
+
has(key: string): boolean;
|
|
1676
|
+
/**
|
|
1677
|
+
* Gets a {@link JsonObject | JSON object} specified by key.
|
|
1678
|
+
* @param key - key of the object to be retrieved
|
|
1679
|
+
* @param context - optional {@link IJsonContext | JSON context} used to format the
|
|
1680
|
+
* returned object.
|
|
1681
|
+
* @returns {@link ts-utils#Success | `Success`} with the formatted object if successful.
|
|
1682
|
+
* {@link ts-utils#Failure | `Failure`} with detail 'unknown' if no such object exists,
|
|
1683
|
+
* or {@link ts-utils#Failure | `Failure`} with detail 'error' if the object was found
|
|
1684
|
+
* but could not be formatted.
|
|
1685
|
+
*/
|
|
1686
|
+
getJsonObject(key: string, context?: IJsonContext): DetailedResult<JsonObject, JsonReferenceMapFailureReason>;
|
|
1687
|
+
/**
|
|
1688
|
+
* Gets a {@link JsonValue | JSON value} specified by key.
|
|
1689
|
+
* @param key - key of the value to be retrieved
|
|
1690
|
+
* @param context - Optional {@link IJsonContext | JSON context} used to format the value
|
|
1691
|
+
* @returns Success with the formatted object if successful. Failure with detail 'unknown'
|
|
1692
|
+
* if no such object exists, or failure with detail 'error' if the object was found but
|
|
1693
|
+
* could not be formatted.
|
|
1694
|
+
*/
|
|
1695
|
+
abstract getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
/**
|
|
1699
|
+
* Helper function which creates a new {@link JsonConverter | JsonConverter} which converts an
|
|
1700
|
+
* `unknown` value to JSON, rendering any property names or string values using mustache with
|
|
1701
|
+
* the supplied context. See the mustache documentation for details of mustache syntax and view.
|
|
1702
|
+
* @param options - {@link TemplatedJsonConverterOptions | Options and context} for
|
|
1703
|
+
* the conversion.
|
|
1704
|
+
* @public
|
|
1705
|
+
*/
|
|
1706
|
+
declare function templatedJson(options?: Partial<TemplatedJsonConverterOptions>): JsonConverter;
|
|
1707
|
+
|
|
1708
|
+
/**
|
|
1709
|
+
* An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON
|
|
1710
|
+
* with mustache template rendering and multi-value property name rules enabled
|
|
1711
|
+
* regardless of initial context.
|
|
1712
|
+
* @public
|
|
1713
|
+
*/
|
|
1714
|
+
export declare class TemplatedJsonConverter extends JsonEditorConverter {
|
|
1715
|
+
/**
|
|
1716
|
+
* Default {@link IJsonConverterOptions | JSON converter options}
|
|
1717
|
+
* to enable templated conversion.
|
|
1718
|
+
*/
|
|
1719
|
+
static readonly templateOptions: Partial<IJsonConverterOptions>;
|
|
1720
|
+
/**
|
|
1721
|
+
* Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with
|
|
1722
|
+
* supplied or default options.
|
|
1723
|
+
* @param options - Optional partial {@link TemplatedJsonConverterOptions | options}
|
|
1724
|
+
* to configure the converter.
|
|
1725
|
+
*/
|
|
1726
|
+
constructor(options?: Partial<TemplatedJsonConverterOptions>);
|
|
1727
|
+
/**
|
|
1728
|
+
* Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with
|
|
1729
|
+
* supplied or default options.
|
|
1730
|
+
* @param options - Optional partial {@link TemplatedJsonConverterOptions | options}
|
|
1731
|
+
* to configure the converter.
|
|
1732
|
+
*/
|
|
1733
|
+
static create(options?: Partial<TemplatedJsonConverterOptions>): Result<JsonConverter>;
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
/**
|
|
1737
|
+
* Initialization options for a {@link TemplatedJsonConverter | TemplatedJsonConverter}.
|
|
1738
|
+
* @public
|
|
1739
|
+
*/
|
|
1740
|
+
export declare type TemplatedJsonConverterOptions = Omit<IJsonConverterOptions, 'useNameTemplates' | 'useValueTemplates' | 'useMultiValueTemplateNames'>;
|
|
1741
|
+
|
|
1742
|
+
/**
|
|
1743
|
+
* The {@link Editor.Rules.TemplatedJsonEditorRule | Templated JSON editor rule} applies mustache rendering as
|
|
1744
|
+
* appropriate to any keys or values in the object being edited.
|
|
1745
|
+
* @public
|
|
1746
|
+
*/
|
|
1747
|
+
declare class TemplatedJsonEditorRule extends JsonEditorRuleBase {
|
|
1748
|
+
/**
|
|
1749
|
+
* Fully-resolved {@link Editor.Rules.ITemplatedJsonRuleOptions | configuration options} for this rule.
|
|
1750
|
+
* @public
|
|
1751
|
+
*/
|
|
1752
|
+
protected _options?: ITemplatedJsonRuleOptions;
|
|
1753
|
+
/**
|
|
1754
|
+
* Creates a new {@link Editor.Rules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.
|
|
1755
|
+
* @param options - Optional {@link Editor.Rules.ITemplatedJsonRuleOptions | configuration options}
|
|
1756
|
+
* for this rule.
|
|
1757
|
+
*/
|
|
1758
|
+
constructor(options?: ITemplatedJsonRuleOptions);
|
|
1759
|
+
/**
|
|
1760
|
+
* Creates a new {@link Editor.Rules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.
|
|
1761
|
+
* @param options - Optional {@link Editor.Rules.ITemplatedJsonRuleOptions | configuration options}
|
|
1762
|
+
* for this rule.
|
|
1763
|
+
*/
|
|
1764
|
+
static create(options?: ITemplatedJsonRuleOptions): Result<TemplatedJsonEditorRule>;
|
|
1765
|
+
/**
|
|
1766
|
+
* Evaluates a property name for template rendering.
|
|
1767
|
+
* @param key - The key of the property to be considered.
|
|
1768
|
+
* @param value - The {@link JsonValue | value} of the property to be considered.
|
|
1769
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} for the object being edited.
|
|
1770
|
+
* @returns `Success` with detail `'edited'` and an {@link JsonObject | object} to
|
|
1771
|
+
* be flattened and merged if the key contained a template. Returns `Failure` with detail `'error'`
|
|
1772
|
+
* if an error occurred or with detail `'inapplicable'` if the property key does not contain
|
|
1773
|
+
* a template or if name rendering is disabled.
|
|
1774
|
+
*/
|
|
1775
|
+
editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
|
|
1776
|
+
/**
|
|
1777
|
+
* Evaluates a property, array or literal value for template rendering.
|
|
1778
|
+
* @param value - The {@link JsonValue | value} to be edited.
|
|
1779
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} for the object being edited.
|
|
1780
|
+
* @returns `Success` with detail `'edited'` if the value contained a template and was edited.
|
|
1781
|
+
* Returns `Failure` with `'ignore'` if the rendered value should be ignored, with `'error'` if
|
|
1782
|
+
* an error occurs, or with `'inapplicable'` if the value was not a string with a template.
|
|
1783
|
+
*/
|
|
1784
|
+
editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
1785
|
+
/**
|
|
1786
|
+
* Renders a single template string for a supplied {@link Editor.JsonEditorState | editor state}.
|
|
1787
|
+
* @param template - The mustache template to be rendered.
|
|
1788
|
+
* @param state - The {@link Editor.JsonEditorState | editor state} used to render the template.
|
|
1789
|
+
* @returns `Success` if the template is rendered. Returns `Failure` with detail `'error'` if the
|
|
1790
|
+
* template could not be rendered (e.g. due to syntax errors) or with detail `'inapplicable'` if the
|
|
1791
|
+
* string is not a template.
|
|
1792
|
+
* @internal
|
|
1793
|
+
*/
|
|
1794
|
+
protected _render(template: string, state: JsonEditorState): DetailedResult<string, JsonEditFailureReason>;
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
/**
|
|
1798
|
+
* Collection of variables used for template replacement in a JSON edit or
|
|
1799
|
+
* conversion.
|
|
1800
|
+
* @public
|
|
1801
|
+
*/
|
|
1802
|
+
export declare type TemplateVars = Record<string, unknown>;
|
|
1803
|
+
|
|
1804
|
+
/**
|
|
1805
|
+
* Function used to create a new collection of {@link TemplateVars | TemplateVars} with
|
|
1806
|
+
* one or more new or changed values.
|
|
1807
|
+
* @public
|
|
1808
|
+
*/
|
|
1809
|
+
export declare type TemplateVarsExtendFunction = (base: TemplateVars | undefined, values: VariableValue[]) => Result<TemplateVars | undefined>;
|
|
1810
|
+
|
|
1811
|
+
/**
|
|
1812
|
+
* Describes one value in a {@link TemplateVars | TemplateVars} collection of
|
|
1813
|
+
* variables.
|
|
1814
|
+
* @public
|
|
1815
|
+
*/
|
|
1816
|
+
export declare type VariableValue = [string, unknown];
|
|
1817
|
+
|
|
1818
|
+
/**
|
|
1819
|
+
* Convenience function to write type-safe JSON to a file.
|
|
1820
|
+
* @param srcPath - Path of the file to write.
|
|
1821
|
+
* @param value - The {@link JsonValue | JsonValue} to be written.
|
|
1822
|
+
* @public
|
|
1823
|
+
*/
|
|
1824
|
+
declare function writeJsonFileSync(srcPath: string, value: JsonValue): Result<boolean>;
|
|
1825
|
+
|
|
1826
|
+
export { }
|