@fgv/ts-json 4.5.0 → 5.0.0-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/CHANGELOG.json +33 -0
- package/CHANGELOG.md +21 -1
- package/dist/ts-json.d.ts +20 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/editor/common.d.ts +18 -0
- package/lib/packlets/editor/common.d.ts.map +1 -1
- package/lib/packlets/editor/common.js.map +1 -1
- package/lib/packlets/editor/jsonEditor.d.ts.map +1 -1
- package/lib/packlets/editor/jsonEditor.js +21 -2
- package/lib/packlets/editor/jsonEditor.js.map +1 -1
- package/lib/packlets/editor/jsonEditorState.js +1 -1
- package/lib/packlets/editor/jsonEditorState.js.map +1 -1
- package/package.json +63 -61
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-json",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "5.0.0",
|
|
6
|
+
"tag": "@fgv/ts-json_v5.0.0",
|
|
7
|
+
"date": "Thu, 17 Jul 2025 00:13:24 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"none": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "upgrade dependencies"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"comment": "bump version"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"version": "4.6.0",
|
|
21
|
+
"tag": "@fgv/ts-json_v4.6.0",
|
|
22
|
+
"date": "Wed, 02 Jul 2025 05:48:16 GMT",
|
|
23
|
+
"comments": {}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"version": "4.5.1",
|
|
27
|
+
"tag": "@fgv/ts-json_v4.5.1",
|
|
28
|
+
"date": "Wed, 02 Jul 2025 05:47:11 GMT",
|
|
29
|
+
"comments": {
|
|
30
|
+
"none": [
|
|
31
|
+
{
|
|
32
|
+
"comment": "update rushstack"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
4
37
|
{
|
|
5
38
|
"version": "4.5.0",
|
|
6
39
|
"tag": "@fgv/ts-json_v4.5.0",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
# Change Log - @fgv/ts-json
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 17 Jul 2025 00:13:24 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.0.0
|
|
6
|
+
Thu, 17 Jul 2025 00:13:24 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- upgrade dependencies
|
|
11
|
+
- bump version
|
|
12
|
+
|
|
13
|
+
## 4.6.0
|
|
14
|
+
Wed, 02 Jul 2025 05:48:16 GMT
|
|
15
|
+
|
|
16
|
+
_Version update only_
|
|
17
|
+
|
|
18
|
+
## 4.5.1
|
|
19
|
+
Wed, 02 Jul 2025 05:47:11 GMT
|
|
20
|
+
|
|
21
|
+
### Updates
|
|
22
|
+
|
|
23
|
+
- update rushstack
|
|
4
24
|
|
|
5
25
|
## 4.5.0
|
|
6
26
|
Tue, 01 Jul 2025 03:26:11 GMT
|
package/dist/ts-json.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ import { JsonObject } from '@fgv/ts-json-base';
|
|
|
7
7
|
import { JsonValue } from '@fgv/ts-json-base';
|
|
8
8
|
import { Result } from '@fgv/ts-utils';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Array merge behavior options for a {@link JsonEditor | JsonEditor}.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare type ArrayMergeBehavior = 'append' | 'replace';
|
|
15
|
+
|
|
10
16
|
/**
|
|
11
17
|
* A {@link CompositeJsonMap | CompositeJsonMap} presents a composed view of one or more other
|
|
12
18
|
* {@link IJsonReferenceMap | JSON reference maps}.
|
|
@@ -391,6 +397,19 @@ export declare interface IJsonConverterOptions {
|
|
|
391
397
|
onUndefinedPropertyValue: 'error' | 'ignore';
|
|
392
398
|
}
|
|
393
399
|
|
|
400
|
+
/**
|
|
401
|
+
* Merge options for a {@link JsonEditor | JsonEditor}.
|
|
402
|
+
* @public
|
|
403
|
+
*/
|
|
404
|
+
export declare interface IJsonEditorMergeOptions {
|
|
405
|
+
/**
|
|
406
|
+
* Controls how arrays are merged when combining JSON values.
|
|
407
|
+
* - `'append'` (default): Existing array elements are preserved and new elements are appended
|
|
408
|
+
* - `'replace'`: Existing array is completely replaced with the new array
|
|
409
|
+
*/
|
|
410
|
+
arrayMergeBehavior: ArrayMergeBehavior;
|
|
411
|
+
}
|
|
412
|
+
|
|
394
413
|
/**
|
|
395
414
|
* Initialization options for a {@link JsonEditor | JsonEditor}.
|
|
396
415
|
* @public
|
|
@@ -398,6 +417,7 @@ export declare interface IJsonConverterOptions {
|
|
|
398
417
|
export declare interface IJsonEditorOptions {
|
|
399
418
|
context?: IJsonContext;
|
|
400
419
|
validation: IJsonEditorValidationOptions;
|
|
420
|
+
merge?: IJsonEditorMergeOptions;
|
|
401
421
|
}
|
|
402
422
|
|
|
403
423
|
/**
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -16,6 +16,23 @@ export type JsonPropertyEditFailureReason = JsonEditFailureReason | 'deferred';
|
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
18
|
export type JsonEditorValidationRules = 'invalidPropertyName' | 'invalidPropertyValue' | 'undefinedPropertyValue';
|
|
19
|
+
/**
|
|
20
|
+
* Array merge behavior options for a {@link JsonEditor | JsonEditor}.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export type ArrayMergeBehavior = 'append' | 'replace';
|
|
24
|
+
/**
|
|
25
|
+
* Merge options for a {@link JsonEditor | JsonEditor}.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export interface IJsonEditorMergeOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Controls how arrays are merged when combining JSON values.
|
|
31
|
+
* - `'append'` (default): Existing array elements are preserved and new elements are appended
|
|
32
|
+
* - `'replace'`: Existing array is completely replaced with the new array
|
|
33
|
+
*/
|
|
34
|
+
arrayMergeBehavior: ArrayMergeBehavior;
|
|
35
|
+
}
|
|
19
36
|
/**
|
|
20
37
|
* Validation options for a {@link JsonEditor | JsonEditor}.
|
|
21
38
|
* @public
|
|
@@ -50,6 +67,7 @@ export interface IJsonEditorValidationOptions {
|
|
|
50
67
|
export interface IJsonEditorOptions {
|
|
51
68
|
context?: IJsonContext;
|
|
52
69
|
validation: IJsonEditorValidationOptions;
|
|
70
|
+
merge?: IJsonEditorMergeOptions;
|
|
53
71
|
}
|
|
54
72
|
/**
|
|
55
73
|
* A specialized JSON editor which does a deep clone of a supplied `JsonValue`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/packlets/editor/common.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,cAAc,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEnF;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG,qBAAqB,GAAG,UAAU,CAAC;AAE/E;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GACjC,qBAAqB,GACrB,sBAAsB,GACtB,wBAAwB,CAAC;AAE7B;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;;;;OAKG;IACH,qBAAqB,EAAE,OAAO,GAAG,QAAQ,CAAC;IAE1C;;;;;OAKG;IACH,sBAAsB,EAAE,OA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AuB,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;CACjG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/packlets/editor/common.ts"],"names":[],"mappings":"","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nimport { JsonValue } from '@fgv/ts-json-base';\nimport { DetailedResult } from '@fgv/ts-utils';\nimport { IJsonContext } from '../context';\n\n/**\n * Possible `DetailedResult` details for various editor operations.\n * @public\n */\nexport type JsonEditFailureReason = 'ignore' | 'inapplicable' | 'edited' | 'error';\n\n/**\n * Possible `DetailedResult` details for property edit operations.\n * @public\n */\nexport type JsonPropertyEditFailureReason = JsonEditFailureReason | 'deferred';\n\n/**\n * Possible validation rules for a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport type JsonEditorValidationRules =\n | 'invalidPropertyName'\n | 'invalidPropertyValue'\n | 'undefinedPropertyValue';\n\n/**\n * Validation options for a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport interface IJsonEditorValidationOptions {\n /**\n * If `onInvalidPropertyName` is `'error'` (default) then any property name\n * that is invalid after template rendering causes an error and stops\n * conversion. If `onInvalidPropertyName` is `'ignore'`, then names which\n * are invalid after template rendering are passed through unchanged.\n */\n onInvalidPropertyName: 'error' | 'ignore';\n\n /**\n * If `onInvalidPropertyValue` is `'error'` (default) then any illegal\n * property value other than `undefined` causes an error and stops\n * conversion. If `onInvalidPropertyValue` is `'ignore'` then any\n * invalid property values are silently ignored.\n */\n onInvalidPropertyValue: 'error' | 'ignore';\n\n /**\n * If `onUndefinedPropertyValue` is `'error'`, then any property with\n * value `undefined` will cause an error and stop conversion. If\n * `onUndefinedPropertyValue` is `'ignore'` (default) then any\n * property with value `undefined` is silently ignored.\n */\n onUndefinedPropertyValue: 'error' | 'ignore';\n}\n\n/**\n * Initialization options for a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport interface IJsonEditorOptions {\n context?: IJsonContext;\n validation: IJsonEditorValidationOptions;\n}\n\n/**\n * A specialized JSON editor which does a deep clone of a supplied `JsonValue`.\n * @public\n */\nexport interface IJsonCloneEditor {\n /**\n * Returns a deep clone of a supplied `JsonValue`.\n * @param src - The `JsonValue` to be cloned.\n * @param context - An optional {@link IJsonContext | JSON context} used for clone\n * conversion operations.\n */\n clone(src: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonEditFailureReason>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/packlets/editor/common.ts"],"names":[],"mappings":"","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nimport { JsonValue } from '@fgv/ts-json-base';\nimport { DetailedResult } from '@fgv/ts-utils';\nimport { IJsonContext } from '../context';\n\n/**\n * Possible `DetailedResult` details for various editor operations.\n * @public\n */\nexport type JsonEditFailureReason = 'ignore' | 'inapplicable' | 'edited' | 'error';\n\n/**\n * Possible `DetailedResult` details for property edit operations.\n * @public\n */\nexport type JsonPropertyEditFailureReason = JsonEditFailureReason | 'deferred';\n\n/**\n * Possible validation rules for a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport type JsonEditorValidationRules =\n | 'invalidPropertyName'\n | 'invalidPropertyValue'\n | 'undefinedPropertyValue';\n\n/**\n * Array merge behavior options for a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport type ArrayMergeBehavior = 'append' | 'replace';\n\n/**\n * Merge options for a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport interface IJsonEditorMergeOptions {\n /**\n * Controls how arrays are merged when combining JSON values.\n * - `'append'` (default): Existing array elements are preserved and new elements are appended\n * - `'replace'`: Existing array is completely replaced with the new array\n */\n arrayMergeBehavior: ArrayMergeBehavior;\n}\n\n/**\n * Validation options for a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport interface IJsonEditorValidationOptions {\n /**\n * If `onInvalidPropertyName` is `'error'` (default) then any property name\n * that is invalid after template rendering causes an error and stops\n * conversion. If `onInvalidPropertyName` is `'ignore'`, then names which\n * are invalid after template rendering are passed through unchanged.\n */\n onInvalidPropertyName: 'error' | 'ignore';\n\n /**\n * If `onInvalidPropertyValue` is `'error'` (default) then any illegal\n * property value other than `undefined` causes an error and stops\n * conversion. If `onInvalidPropertyValue` is `'ignore'` then any\n * invalid property values are silently ignored.\n */\n onInvalidPropertyValue: 'error' | 'ignore';\n\n /**\n * If `onUndefinedPropertyValue` is `'error'`, then any property with\n * value `undefined` will cause an error and stop conversion. If\n * `onUndefinedPropertyValue` is `'ignore'` (default) then any\n * property with value `undefined` is silently ignored.\n */\n onUndefinedPropertyValue: 'error' | 'ignore';\n}\n\n/**\n * Initialization options for a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport interface IJsonEditorOptions {\n context?: IJsonContext;\n validation: IJsonEditorValidationOptions;\n merge?: IJsonEditorMergeOptions;\n}\n\n/**\n * A specialized JSON editor which does a deep clone of a supplied `JsonValue`.\n * @public\n */\nexport interface IJsonCloneEditor {\n /**\n * Returns a deep clone of a supplied `JsonValue`.\n * @param src - The `JsonValue` to be cloned.\n * @param context - An optional {@link IJsonContext | JSON context} used for clone\n * conversion operations.\n */\n clone(src: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonEditFailureReason>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonEditor.d.ts","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditor.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,cAAc,EACd,MAAM,EAQP,MAAM,eAAe,CAAC;AAQvB,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EAIV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EA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cAAc,CAAC,UAAU,EAAE,6BAA6B,CAAC;IAU5D;;;;;;OAMG;IACH,SAAS,CAAC,UAAU,CAClB,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,eAAe,GACrB,cAAc,CAAC,SAAS,EAAE,qBAAqB,CAAC;IAUnD;;;;;;OAMG;IACH,SAAS,CAAC,iBAAiB,CACzB,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,eAAe,GACrB,cAAc,CAAC,UAAU,EAAE,qBAAqB,CAAC;CAoBrD"}
|
|
@@ -96,7 +96,13 @@ class JsonEditor {
|
|
|
96
96
|
onUndefinedPropertyValue: 'ignore'
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
let merge = options === null || options === void 0 ? void 0 : options.merge;
|
|
100
|
+
if (merge === undefined) {
|
|
101
|
+
merge = {
|
|
102
|
+
arrayMergeBehavior: 'append'
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return (0, ts_utils_1.succeed)({ context, validation, merge });
|
|
100
106
|
}
|
|
101
107
|
/**
|
|
102
108
|
* Merges a supplied source object into a supplied target, updating the target object.
|
|
@@ -243,6 +249,7 @@ class JsonEditor {
|
|
|
243
249
|
* @internal
|
|
244
250
|
*/
|
|
245
251
|
_mergeClonedProperty(target, key, newValue, state) {
|
|
252
|
+
var _a, _b;
|
|
246
253
|
const existing = target[key];
|
|
247
254
|
// merge is called right after clone so this should never happen
|
|
248
255
|
// since clone itself will have failed
|
|
@@ -260,7 +267,19 @@ class JsonEditor {
|
|
|
260
267
|
/* c8 ignore else */
|
|
261
268
|
if ((0, ts_json_base_1.isJsonArray)(newValue)) {
|
|
262
269
|
if ((0, ts_json_base_1.isJsonArray)(existing)) {
|
|
263
|
-
|
|
270
|
+
/* c8 ignore next 1 - ?? is defense in depth */
|
|
271
|
+
const arrayMergeBehavior = (_b = (_a = state.options.merge) === null || _a === void 0 ? void 0 : _a.arrayMergeBehavior) !== null && _b !== void 0 ? _b : 'append';
|
|
272
|
+
switch (arrayMergeBehavior) {
|
|
273
|
+
case 'append':
|
|
274
|
+
target[key] = existing.concat(...newValue);
|
|
275
|
+
break;
|
|
276
|
+
case 'replace':
|
|
277
|
+
target[key] = newValue;
|
|
278
|
+
break;
|
|
279
|
+
/* c8 ignore next 2 - exhaustive switch for ArrayMergeBehavior type */
|
|
280
|
+
default:
|
|
281
|
+
return (0, ts_utils_1.failWithDetail)(`Invalid array merge behavior: ${arrayMergeBehavior}`, 'error');
|
|
282
|
+
}
|
|
264
283
|
return (0, ts_utils_1.succeedWithDetail)(target[key], 'edited');
|
|
265
284
|
}
|
|
266
285
|
target[key] = newValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonEditor.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAUuB;AACvB,mCAKiB;AAEjB,oDAO2B;AAW3B,uDAAoD;AAEpD;;;;;GAKG;AACH,MAAa,UAAU;IAkBrB;;;;;;;OAOG;IACH,YAAsB,OAAqC,EAAE,KAAyB;QACpF,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;QAChE,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACI,MAAM,KAAK,OAAO;QACvB,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,SAAS,EAAE,CAAC;YACjD,UAAU,CAAC,QAAQ,GAAG,IAAI,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED;;;;;;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AkB,EAClB,KAAsB;QAEtB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC/B,MAAM,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;gBAC5D,IAAI,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC;oBAC3B,OAAO,IAAI,CAAC,8BAA8B,CACxC,KAAK,CAAC,OAAO,EACb,MAAM,EACN,UAAU,CAAC,KAAK,CACjB,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;gBAC/B,CAAC;qBAAM,IAAI,UAAU,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;oBAC1C,IAAA,4BAAiB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBACtC,CAAC;qBAAM,IAAI,UAAU,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;oBAChD,OAAO,IAAA,yBAAc,EAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;gBAC/D,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAA,4BAAiB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;CACF;AA3WD,gCA2WC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n DetailedResult,\n Result,\n captureResult,\n fail,\n failWithDetail,\n mapDetailedResults,\n mapResults,\n succeed,\n succeedWithDetail\n} from '@fgv/ts-utils';\nimport {\n ConditionalJsonEditorRule,\n MultiValueJsonEditorRule,\n ReferenceJsonEditorRule,\n TemplatedJsonEditorRule\n} from './rules';\n\nimport {\n JsonArray,\n JsonObject,\n JsonValue,\n isJsonArray,\n isJsonObject,\n isJsonPrimitive\n} from '@fgv/ts-json-base';\nimport { IJsonContext } from '../context';\nimport {\n IJsonCloneEditor,\n IJsonEditorOptions,\n IJsonEditorValidationOptions,\n JsonEditFailureReason,\n JsonPropertyEditFailureReason\n} from './common';\n\nimport { IJsonEditorRule } from './jsonEditorRule';\nimport { JsonEditorState } from './jsonEditorState';\n\n/**\n * A {@link JsonEditor | JsonEditor} can be used to edit JSON objects in place or to\n * clone any JSON value, applying a default context and optional set of editor rules that\n * were supplied at initialization.\n * @public\n */\nexport class JsonEditor implements IJsonCloneEditor {\n /**\n * Default singleton {@link JsonEditor | JsonEditor}.\n * @internal\n */\n protected static _default?: JsonEditor;\n\n /**\n * Full set of {@link IJsonEditorOptions | editor options} in effect for this editor.\n */\n public options: IJsonEditorOptions;\n\n /**\n * The set of {@link IJsonEditorRule | editor rules} applied by this editor.\n * @internal\n */\n protected _rules: IJsonEditorRule[];\n\n /**\n * Protected constructor for {@link JsonEditor | JsonEditor} and derived classes.\n * External consumers should instantiate via the {@link JsonEditor.create | create static method}.\n * @param options - Optional partial {@link IJsonEditorOptions | editor options} for the\n * constructed editor.\n * @param rules - Any {@link IJsonEditorRule | editor rules} to be applied by the editor.\n * @internal\n */\n protected constructor(options?: Partial<IJsonEditorOptions>, rules?: IJsonEditorRule[]) {\n this.options = JsonEditor._getDefaultOptions(options).orThrow();\n this._rules = rules || JsonEditor.getDefaultRules(this.options).orThrow();\n }\n\n /**\n * Default singleton {@link JsonEditor | JsonEditor} for simple use. Applies all rules\n * but with no default context.\n */\n public static get default(): JsonEditor {\n if (!JsonEditor._default) {\n const rules = this.getDefaultRules().orDefault();\n JsonEditor._default = new JsonEditor(undefined, rules);\n }\n return JsonEditor._default;\n }\n\n /**\n * Constructs a new {@link JsonEditor | JsonEditor}.\n * @param options - Optional partial {@link IJsonEditorOptions | editor options} for the\n * constructed editor.\n * @param rules - Optional set of {@link IJsonEditorRule | editor rules} to be applied by the editor.\n * @readonly A new {@link JsonEditor | JsonEditor}.\n */\n public static create(options?: Partial<IJsonEditorOptions>, rules?: IJsonEditorRule[]): Result<JsonEditor> {\n return captureResult(() => new JsonEditor(options, rules));\n }\n\n /**\n * Gets the default set of rules to be applied for a given set of options.\n * By default, all available rules (templates, conditionals, multi-value and references)\n * are applied.\n * @param options - Optional partial {@link IJsonEditorOptions | editor options} for\n * all rules.\n * @returns Default {@link IJsonEditorRule | editor rules} with any supplied options\n * applied.\n */\n public static getDefaultRules(options?: IJsonEditorOptions): Result<IJsonEditorRule[]> {\n return mapResults<IJsonEditorRule>([\n TemplatedJsonEditorRule.create(options),\n ConditionalJsonEditorRule.create(options),\n MultiValueJsonEditorRule.create(options),\n ReferenceJsonEditorRule.create(options)\n ]);\n }\n\n /**\n * @internal\n */\n protected static _getDefaultOptions(options?: Partial<IJsonEditorOptions>): Result<IJsonEditorOptions> {\n const context: IJsonContext | undefined = options?.context;\n let validation: IJsonEditorValidationOptions | undefined = options?.validation;\n if (validation === undefined) {\n validation = {\n onInvalidPropertyName: 'error',\n onInvalidPropertyValue: 'error',\n onUndefinedPropertyValue: 'ignore'\n };\n }\n return succeed({ context, validation });\n }\n\n /**\n * Merges a supplied source object into a supplied target, updating the target object.\n * @param target - The target `JsonObject` to be updated\n * @param src - The source `JsonObject` to be merged\n * @param runtimeContext - An optional {@link IJsonContext | IJsonContext} supplying variables\n * and references.\n * @returns `Success` with the original source `JsonObject` if merge was successful.\n * Returns `Failure` with details if an error occurs.\n */\n public mergeObjectInPlace(\n target: JsonObject,\n src: JsonObject,\n runtimeContext?: IJsonContext\n ): Result<JsonObject> {\n const state = new JsonEditorState(this, this.options, runtimeContext);\n return this._mergeObjectInPlace(target, src, state).onSuccess((merged) => {\n return this._finalizeAndMerge(merged, state);\n });\n }\n\n /**\n * Merges multiple supplied source objects into a supplied target, updating the target\n * object and using the default context supplied at creation time.\n * @param target - The target `JsonObject` to be updated\n * @param srcObjects - `JsonObject`s to be merged into the target object, in the order\n * supplied.\n * @returns `Success` with the original source `JsonObject` if merge was successful.\n * Returns `Failure` with details if an error occurs.\n */\n public mergeObjectsInPlace(target: JsonObject, srcObjects: JsonObject[]): Result<JsonObject> {\n return this.mergeObjectsInPlaceWithContext(this.options.context, target, srcObjects);\n }\n\n /**\n * Merges multiple supplied source objects into a supplied target, updating the target\n * object and using an optional {@link IJsonContext | context} supplied in the call.\n * @param context - An optional {@link IJsonContext | IJsonContext} supplying variables and\n * references.\n * @param base - The base `JsonObject` to be updated\n * @param srcObjects - Objects to be merged into the target object, in the order supplied.\n * @returns `Success` with the original source `JsonObject` if merge was successful.\n * Returns `Failure` with details if an error occurs.\n */\n public mergeObjectsInPlaceWithContext(\n context: IJsonContext | undefined,\n base: JsonObject,\n srcObjects: JsonObject[]\n ): Result<JsonObject> {\n for (const src of srcObjects) {\n const mergeResult = this.mergeObjectInPlace(base, src, context);\n if (mergeResult.isFailure()) {\n return mergeResult.withFailureDetail('error');\n }\n }\n return succeedWithDetail(base);\n }\n\n /**\n * Deep clones a supplied `JsonValue`, applying all editor rules and a default\n * or optionally supplied context\n * @param src - The `JsonValue` to be cloned.\n * @param context - An optional {@link IJsonContext | JSON context} supplying variables and references.\n */\n public clone(src: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonEditFailureReason> {\n const state = new JsonEditorState(this, this.options, context);\n let value = src;\n let valueResult = this._editValue(src, state);\n\n while (valueResult.isSuccess()) {\n value = valueResult.value;\n valueResult = this._editValue(value, state);\n }\n\n if (valueResult.detail === 'error' || valueResult.detail === 'ignore') {\n return valueResult;\n }\n\n if (isJsonPrimitive(value) || value === null) {\n return succeedWithDetail(value, 'edited');\n } else if (isJsonObject(value)) {\n return this.mergeObjectInPlace({}, value, state.context).withFailureDetail('error');\n } else if (isJsonArray(value)) {\n return this._cloneArray(value, state.context);\n } else if (value === undefined) {\n return state.failValidation('undefinedPropertyValue');\n }\n return state.failValidation(\n 'invalidPropertyValue',\n `Cannot convert invalid JSON: \"${JSON.stringify(value)}\"`\n );\n }\n\n /**\n *\n * @param target -\n * @param src -\n * @param state -\n * @returns\n * @internal\n */\n protected _mergeObjectInPlace(\n target: JsonObject,\n src: JsonObject,\n state: JsonEditorState\n ): Result<JsonObject> {\n for (const key in src) {\n if (src.hasOwnProperty(key)) {\n const propResult = this._editProperty(key, src[key], state);\n if (propResult.isSuccess()) {\n if (propResult.detail === 'deferred') {\n state.defer(propResult.value);\n } else {\n const mergeResult = this._mergeObjectInPlace(target, propResult.value, state);\n if (mergeResult.isFailure()) {\n return mergeResult;\n }\n }\n } else if (propResult.detail === 'inapplicable') {\n const valueResult = this.clone(src[key], state.context).onSuccess((cloned) => {\n return this._mergeClonedProperty(target, key, cloned, state);\n });\n\n if (valueResult.isFailure() && valueResult.detail === 'error') {\n return fail(`${key}: ${valueResult.message}`);\n }\n } else if (propResult.detail !== 'ignore') {\n return fail(`${key}: ${propResult.message}`);\n }\n } else {\n return fail(`${key}: Cannot merge inherited properties`);\n }\n }\n return succeed(target);\n }\n\n /**\n *\n * @param src -\n * @param context -\n * @returns\n * @internal\n */\n protected _cloneArray(\n src: JsonArray,\n context?: IJsonContext\n ): DetailedResult<JsonArray, JsonEditFailureReason> {\n const results = src.map((v) => {\n return this.clone(v, context);\n });\n\n return mapDetailedResults<JsonValue, JsonEditFailureReason>(results, ['ignore'])\n .onSuccess((converted) => {\n return succeed(converted);\n })\n .withFailureDetail('error');\n }\n\n /**\n *\n * @param target -\n * @param key -\n * @param newValue -\n * @param state -\n * @returns\n * @internal\n */\n protected _mergeClonedProperty(\n target: JsonObject,\n key: string,\n newValue: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonValue, JsonEditFailureReason> {\n const existing = target[key];\n\n // merge is called right after clone so this should never happen\n // since clone itself will have failed\n\n if (isJsonPrimitive(newValue)) {\n target[key] = newValue;\n return succeedWithDetail(newValue, 'edited');\n }\n\n if (isJsonObject(newValue)) {\n if (isJsonObject(existing)) {\n return this.mergeObjectInPlace(existing, newValue, state.context).withFailureDetail('error');\n }\n target[key] = newValue;\n return succeedWithDetail(newValue, 'edited');\n }\n\n /* c8 ignore else */\n if (isJsonArray(newValue)) {\n if (isJsonArray(existing)) {\n target[key] = existing.concat(...newValue);\n return succeedWithDetail(target[key], 'edited');\n }\n target[key] = newValue;\n return succeedWithDetail(newValue, 'edited');\n }\n /* c8 ignore start */\n return failWithDetail(`Invalid JSON: ${JSON.stringify(newValue)}`, 'error');\n } /* c8 ignore stop */\n\n /**\n *\n * @param key -\n * @param value -\n * @param state -\n * @returns\n * @internal\n */\n protected _editProperty(\n key: string,\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason> {\n for (const rule of this._rules) {\n const ruleResult = rule.editProperty(key, value, state);\n if (ruleResult.isSuccess() || ruleResult.detail !== 'inapplicable') {\n return ruleResult;\n }\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n *\n * @param value -\n * @param state -\n * @returns\n * @internal\n */\n protected _editValue(\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonValue, JsonEditFailureReason> {\n for (const rule of this._rules) {\n const ruleResult = rule.editValue(value, state);\n if (ruleResult.isSuccess() || ruleResult.detail !== 'inapplicable') {\n return ruleResult;\n }\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n *\n * @param target -\n * @param state -\n * @returns\n * @internal\n */\n protected _finalizeAndMerge(\n target: JsonObject,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonEditFailureReason> {\n const deferred = state.deferred;\n if (deferred.length > 0) {\n for (const rule of this._rules) {\n const ruleResult = rule.finalizeProperties(deferred, state);\n if (ruleResult.isSuccess()) {\n return this.mergeObjectsInPlaceWithContext(\n state.context,\n target,\n ruleResult.value\n ).withFailureDetail('error');\n } else if (ruleResult.detail === 'ignore') {\n succeedWithDetail(target, 'edited');\n } else if (ruleResult.detail !== 'inapplicable') {\n return failWithDetail(ruleResult.message, ruleResult.detail);\n }\n }\n }\n return succeedWithDetail(target, 'edited');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"jsonEditor.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAUuB;AACvB,mCAKiB;AAEjB,oDAO2B;AAY3B,uDAAoD;AAEpD;;;;;GAKG;AACH,MAAa,UAAU;IAkBrB;;;;;;;OAOG;IACH,YAAsB,OAAqC,EAAE,KAAyB;QACpF,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;QAChE,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACI,MAAM,KAAK,OAAO;QACvB,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,SAAS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I,UAAU,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;oBAC1C,IAAA,4BAAiB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBACtC,CAAC;qBAAM,IAAI,UAAU,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;oBAChD,OAAO,IAAA,yBAAc,EAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;gBAC/D,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAA,4BAAiB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;CACF;AA7XD,gCA6XC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n DetailedResult,\n Result,\n captureResult,\n fail,\n failWithDetail,\n mapDetailedResults,\n mapResults,\n succeed,\n succeedWithDetail\n} from '@fgv/ts-utils';\nimport {\n ConditionalJsonEditorRule,\n MultiValueJsonEditorRule,\n ReferenceJsonEditorRule,\n TemplatedJsonEditorRule\n} from './rules';\n\nimport {\n JsonArray,\n JsonObject,\n JsonValue,\n isJsonArray,\n isJsonObject,\n isJsonPrimitive\n} from '@fgv/ts-json-base';\nimport { IJsonContext } from '../context';\nimport {\n IJsonCloneEditor,\n IJsonEditorMergeOptions,\n IJsonEditorOptions,\n IJsonEditorValidationOptions,\n JsonEditFailureReason,\n JsonPropertyEditFailureReason\n} from './common';\n\nimport { IJsonEditorRule } from './jsonEditorRule';\nimport { JsonEditorState } from './jsonEditorState';\n\n/**\n * A {@link JsonEditor | JsonEditor} can be used to edit JSON objects in place or to\n * clone any JSON value, applying a default context and optional set of editor rules that\n * were supplied at initialization.\n * @public\n */\nexport class JsonEditor implements IJsonCloneEditor {\n /**\n * Default singleton {@link JsonEditor | JsonEditor}.\n * @internal\n */\n protected static _default?: JsonEditor;\n\n /**\n * Full set of {@link IJsonEditorOptions | editor options} in effect for this editor.\n */\n public options: IJsonEditorOptions;\n\n /**\n * The set of {@link IJsonEditorRule | editor rules} applied by this editor.\n * @internal\n */\n protected _rules: IJsonEditorRule[];\n\n /**\n * Protected constructor for {@link JsonEditor | JsonEditor} and derived classes.\n * External consumers should instantiate via the {@link JsonEditor.create | create static method}.\n * @param options - Optional partial {@link IJsonEditorOptions | editor options} for the\n * constructed editor.\n * @param rules - Any {@link IJsonEditorRule | editor rules} to be applied by the editor.\n * @internal\n */\n protected constructor(options?: Partial<IJsonEditorOptions>, rules?: IJsonEditorRule[]) {\n this.options = JsonEditor._getDefaultOptions(options).orThrow();\n this._rules = rules || JsonEditor.getDefaultRules(this.options).orThrow();\n }\n\n /**\n * Default singleton {@link JsonEditor | JsonEditor} for simple use. Applies all rules\n * but with no default context.\n */\n public static get default(): JsonEditor {\n if (!JsonEditor._default) {\n const rules = this.getDefaultRules().orDefault();\n JsonEditor._default = new JsonEditor(undefined, rules);\n }\n return JsonEditor._default;\n }\n\n /**\n * Constructs a new {@link JsonEditor | JsonEditor}.\n * @param options - Optional partial {@link IJsonEditorOptions | editor options} for the\n * constructed editor.\n * @param rules - Optional set of {@link IJsonEditorRule | editor rules} to be applied by the editor.\n * @readonly A new {@link JsonEditor | JsonEditor}.\n */\n public static create(options?: Partial<IJsonEditorOptions>, rules?: IJsonEditorRule[]): Result<JsonEditor> {\n return captureResult(() => new JsonEditor(options, rules));\n }\n\n /**\n * Gets the default set of rules to be applied for a given set of options.\n * By default, all available rules (templates, conditionals, multi-value and references)\n * are applied.\n * @param options - Optional partial {@link IJsonEditorOptions | editor options} for\n * all rules.\n * @returns Default {@link IJsonEditorRule | editor rules} with any supplied options\n * applied.\n */\n public static getDefaultRules(options?: IJsonEditorOptions): Result<IJsonEditorRule[]> {\n return mapResults<IJsonEditorRule>([\n TemplatedJsonEditorRule.create(options),\n ConditionalJsonEditorRule.create(options),\n MultiValueJsonEditorRule.create(options),\n ReferenceJsonEditorRule.create(options)\n ]);\n }\n\n /**\n * @internal\n */\n protected static _getDefaultOptions(options?: Partial<IJsonEditorOptions>): Result<IJsonEditorOptions> {\n const context: IJsonContext | undefined = options?.context;\n let validation: IJsonEditorValidationOptions | undefined = options?.validation;\n if (validation === undefined) {\n validation = {\n onInvalidPropertyName: 'error',\n onInvalidPropertyValue: 'error',\n onUndefinedPropertyValue: 'ignore'\n };\n }\n let merge: IJsonEditorMergeOptions | undefined = options?.merge;\n if (merge === undefined) {\n merge = {\n arrayMergeBehavior: 'append'\n };\n }\n return succeed({ context, validation, merge });\n }\n\n /**\n * Merges a supplied source object into a supplied target, updating the target object.\n * @param target - The target `JsonObject` to be updated\n * @param src - The source `JsonObject` to be merged\n * @param runtimeContext - An optional {@link IJsonContext | IJsonContext} supplying variables\n * and references.\n * @returns `Success` with the original source `JsonObject` if merge was successful.\n * Returns `Failure` with details if an error occurs.\n */\n public mergeObjectInPlace(\n target: JsonObject,\n src: JsonObject,\n runtimeContext?: IJsonContext\n ): Result<JsonObject> {\n const state = new JsonEditorState(this, this.options, runtimeContext);\n return this._mergeObjectInPlace(target, src, state).onSuccess((merged) => {\n return this._finalizeAndMerge(merged, state);\n });\n }\n\n /**\n * Merges multiple supplied source objects into a supplied target, updating the target\n * object and using the default context supplied at creation time.\n * @param target - The target `JsonObject` to be updated\n * @param srcObjects - `JsonObject`s to be merged into the target object, in the order\n * supplied.\n * @returns `Success` with the original source `JsonObject` if merge was successful.\n * Returns `Failure` with details if an error occurs.\n */\n public mergeObjectsInPlace(target: JsonObject, srcObjects: JsonObject[]): Result<JsonObject> {\n return this.mergeObjectsInPlaceWithContext(this.options.context, target, srcObjects);\n }\n\n /**\n * Merges multiple supplied source objects into a supplied target, updating the target\n * object and using an optional {@link IJsonContext | context} supplied in the call.\n * @param context - An optional {@link IJsonContext | IJsonContext} supplying variables and\n * references.\n * @param base - The base `JsonObject` to be updated\n * @param srcObjects - Objects to be merged into the target object, in the order supplied.\n * @returns `Success` with the original source `JsonObject` if merge was successful.\n * Returns `Failure` with details if an error occurs.\n */\n public mergeObjectsInPlaceWithContext(\n context: IJsonContext | undefined,\n base: JsonObject,\n srcObjects: JsonObject[]\n ): Result<JsonObject> {\n for (const src of srcObjects) {\n const mergeResult = this.mergeObjectInPlace(base, src, context);\n if (mergeResult.isFailure()) {\n return mergeResult.withFailureDetail('error');\n }\n }\n return succeedWithDetail(base);\n }\n\n /**\n * Deep clones a supplied `JsonValue`, applying all editor rules and a default\n * or optionally supplied context\n * @param src - The `JsonValue` to be cloned.\n * @param context - An optional {@link IJsonContext | JSON context} supplying variables and references.\n */\n public clone(src: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonEditFailureReason> {\n const state = new JsonEditorState(this, this.options, context);\n let value = src;\n let valueResult = this._editValue(src, state);\n\n while (valueResult.isSuccess()) {\n value = valueResult.value;\n valueResult = this._editValue(value, state);\n }\n\n if (valueResult.detail === 'error' || valueResult.detail === 'ignore') {\n return valueResult;\n }\n\n if (isJsonPrimitive(value) || value === null) {\n return succeedWithDetail(value, 'edited');\n } else if (isJsonObject(value)) {\n return this.mergeObjectInPlace({}, value, state.context).withFailureDetail('error');\n } else if (isJsonArray(value)) {\n return this._cloneArray(value, state.context);\n } else if (value === undefined) {\n return state.failValidation('undefinedPropertyValue');\n }\n return state.failValidation(\n 'invalidPropertyValue',\n `Cannot convert invalid JSON: \"${JSON.stringify(value)}\"`\n );\n }\n\n /**\n *\n * @param target -\n * @param src -\n * @param state -\n * @returns\n * @internal\n */\n protected _mergeObjectInPlace(\n target: JsonObject,\n src: JsonObject,\n state: JsonEditorState\n ): Result<JsonObject> {\n for (const key in src) {\n if (src.hasOwnProperty(key)) {\n const propResult = this._editProperty(key, src[key], state);\n if (propResult.isSuccess()) {\n if (propResult.detail === 'deferred') {\n state.defer(propResult.value);\n } else {\n const mergeResult = this._mergeObjectInPlace(target, propResult.value, state);\n if (mergeResult.isFailure()) {\n return mergeResult;\n }\n }\n } else if (propResult.detail === 'inapplicable') {\n const valueResult = this.clone(src[key], state.context).onSuccess((cloned) => {\n return this._mergeClonedProperty(target, key, cloned, state);\n });\n\n if (valueResult.isFailure() && valueResult.detail === 'error') {\n return fail(`${key}: ${valueResult.message}`);\n }\n } else if (propResult.detail !== 'ignore') {\n return fail(`${key}: ${propResult.message}`);\n }\n } else {\n return fail(`${key}: Cannot merge inherited properties`);\n }\n }\n return succeed(target);\n }\n\n /**\n *\n * @param src -\n * @param context -\n * @returns\n * @internal\n */\n protected _cloneArray(\n src: JsonArray,\n context?: IJsonContext\n ): DetailedResult<JsonArray, JsonEditFailureReason> {\n const results = src.map((v) => {\n return this.clone(v, context);\n });\n\n return mapDetailedResults<JsonValue, JsonEditFailureReason>(results, ['ignore'])\n .onSuccess((converted) => {\n return succeed(converted);\n })\n .withFailureDetail('error');\n }\n\n /**\n *\n * @param target -\n * @param key -\n * @param newValue -\n * @param state -\n * @returns\n * @internal\n */\n protected _mergeClonedProperty(\n target: JsonObject,\n key: string,\n newValue: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonValue, JsonEditFailureReason> {\n const existing = target[key];\n\n // merge is called right after clone so this should never happen\n // since clone itself will have failed\n\n if (isJsonPrimitive(newValue)) {\n target[key] = newValue;\n return succeedWithDetail(newValue, 'edited');\n }\n\n if (isJsonObject(newValue)) {\n if (isJsonObject(existing)) {\n return this.mergeObjectInPlace(existing, newValue, state.context).withFailureDetail('error');\n }\n target[key] = newValue;\n return succeedWithDetail(newValue, 'edited');\n }\n\n /* c8 ignore else */\n if (isJsonArray(newValue)) {\n if (isJsonArray(existing)) {\n /* c8 ignore next 1 - ?? is defense in depth */\n const arrayMergeBehavior = state.options.merge?.arrayMergeBehavior ?? 'append';\n switch (arrayMergeBehavior) {\n case 'append':\n target[key] = existing.concat(...newValue);\n break;\n case 'replace':\n target[key] = newValue;\n break;\n /* c8 ignore next 2 - exhaustive switch for ArrayMergeBehavior type */\n default:\n return failWithDetail(`Invalid array merge behavior: ${arrayMergeBehavior as string}`, 'error');\n }\n return succeedWithDetail(target[key], 'edited');\n }\n target[key] = newValue;\n return succeedWithDetail(newValue, 'edited');\n }\n /* c8 ignore start */\n return failWithDetail(`Invalid JSON: ${JSON.stringify(newValue)}`, 'error');\n } /* c8 ignore stop */\n\n /**\n *\n * @param key -\n * @param value -\n * @param state -\n * @returns\n * @internal\n */\n protected _editProperty(\n key: string,\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason> {\n for (const rule of this._rules) {\n const ruleResult = rule.editProperty(key, value, state);\n if (ruleResult.isSuccess() || ruleResult.detail !== 'inapplicable') {\n return ruleResult;\n }\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n *\n * @param value -\n * @param state -\n * @returns\n * @internal\n */\n protected _editValue(\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonValue, JsonEditFailureReason> {\n for (const rule of this._rules) {\n const ruleResult = rule.editValue(value, state);\n if (ruleResult.isSuccess() || ruleResult.detail !== 'inapplicable') {\n return ruleResult;\n }\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n *\n * @param target -\n * @param state -\n * @returns\n * @internal\n */\n protected _finalizeAndMerge(\n target: JsonObject,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonEditFailureReason> {\n const deferred = state.deferred;\n if (deferred.length > 0) {\n for (const rule of this._rules) {\n const ruleResult = rule.finalizeProperties(deferred, state);\n if (ruleResult.isSuccess()) {\n return this.mergeObjectsInPlaceWithContext(\n state.context,\n target,\n ruleResult.value\n ).withFailureDetail('error');\n } else if (ruleResult.detail === 'ignore') {\n succeedWithDetail(target, 'edited');\n } else if (ruleResult.detail !== 'inapplicable') {\n return failWithDetail(ruleResult.message, ruleResult.detail);\n }\n }\n }\n return succeedWithDetail(target, 'edited');\n }\n}\n"]}
|
|
@@ -79,7 +79,7 @@ class JsonEditorState {
|
|
|
79
79
|
return (0, ts_utils_1.succeed)(options);
|
|
80
80
|
}
|
|
81
81
|
return context_1.JsonContextHelper.mergeContext(options.context, context).onSuccess((merged) => {
|
|
82
|
-
return (0, ts_utils_1.succeed)({ context: merged, validation: options.validation });
|
|
82
|
+
return (0, ts_utils_1.succeed)({ context: merged, validation: options.validation, merge: options.merge });
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonEditorState.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorState.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAAiF;AACjF,wCAA6G;AAU7G;;;GAGG;AACH,MAAa,eAAe;IA+B1B;;;;;;;;OAQG;IACH,YACE,MAAwB,EACxB,WAA+B,EAC/B,cAA6B;QAxB/B;;;WAGG;QACgB,cAAS,GAAiB,EAAE,CAAC;QAsB9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,oBAAoB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,OAAO,EAAE,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CAAC;;AAzLH,0CA0LC;AAzLC;;;;GAIG;AACc,uBAAO,GAAW,CAAC,AAAZ,CAAa","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonObject } from '@fgv/ts-json-base';\nimport { DetailedFailure, Result, failWithDetail, succeed } from '@fgv/ts-utils';\nimport { IJsonContext, IJsonReferenceMap, JsonContextHelper, TemplateVars, VariableValue } from '../context';\nimport {\n IJsonCloneEditor,\n IJsonEditorOptions,\n IJsonEditorValidationOptions,\n JsonEditFailureReason,\n JsonEditorValidationRules,\n JsonPropertyEditFailureReason\n} from './common';\n\n/**\n * Represents the internal state of a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport class JsonEditorState {\n /**\n * Static global counter used to assign each {@link JsonEditorState | JsonEditorState}\n * a unique identifier.\n * @internal\n */\n protected static _nextId: number = 0;\n\n /**\n * The {@link IJsonCloneEditor | editor} for which this state applies.\n */\n public readonly editor: IJsonCloneEditor;\n\n /**\n * Fully resolved {@link IJsonEditorOptions | editor options} that apply\n * to the operation for which this state applies.\n */\n public readonly options: IJsonEditorOptions;\n\n /**\n * Any deferred JSON objects to be merged during finalization.\n * @internal\n */\n protected readonly _deferred: JsonObject[] = [];\n\n /**\n * Unique global identifier for this {@link JsonEditorState | state object}.\n * @internal\n */\n protected readonly _id: number;\n\n /**\n * Constructs a new {@link JsonEditorState | JsonEditorState}.\n * @param editor - The {@link IJsonCloneEditor | editor} to which this state\n * applies.\n * @param baseOptions - The {@link IJsonEditorOptions | editor options} that\n * apply to this rule.\n * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used\n * for json value conversion.\n */\n public constructor(\n editor: IJsonCloneEditor,\n baseOptions: IJsonEditorOptions,\n runtimeContext?: IJsonContext\n ) {\n this.editor = editor;\n this.options = JsonEditorState._getEffectiveOptions(baseOptions, runtimeContext).orThrow();\n this._id = JsonEditorState._nextId++;\n }\n\n /**\n * The optional {@link IJsonContext | JSON context} for this state.\n */\n public get context(): IJsonContext | undefined {\n return this.options.context;\n }\n\n /**\n * An array of JSON objects that were deferred for merge during\n * finalization.\n */\n public get deferred(): JsonObject[] {\n return this._deferred;\n }\n\n /**\n * Merges an optional {@link IJsonContext | JSON context} into a supplied set\n * of {@link IJsonEditorOptions | JSON editor options}.\n * @param options - The {@link IJsonEditorOptions | IJsonEditorOptions} into\n * which the the new context is to be merged.\n * @param context - The {@link IJsonContext | JSON context} to be merged into the\n * editor options.\n * @returns `Success` with the supplied {@link IJsonEditorOptions | options} if\n * there was nothing to merge, or aa new {@link IJsonEditorOptions | IJsonEditorOptions}\n * constructed from the base options merged with the supplied context. Returns `Failure`\n * with more information if an error occurs.\n * @internal\n */\n protected static _getEffectiveOptions(\n options: IJsonEditorOptions,\n context?: IJsonContext\n ): Result<IJsonEditorOptions> {\n if (!context) {\n return succeed(options);\n }\n return JsonContextHelper.mergeContext(options.context, context).onSuccess((merged) => {\n return succeed({ context: merged, validation: options.validation });\n });\n }\n\n /**\n * Adds a supplied `JsonObject` to the deferred list.\n * @param obj - The `JsonObject` to be deferred.\n */\n public defer(obj: JsonObject): void {\n this._deferred.push(obj);\n }\n\n /**\n * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link JsonEditorState | JsonEditorState},\n * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default\n * context.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`\n * if the current state does not have context.\n * @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or\n * `undefined` if no vars are found.\n */\n public getVars(defaultContext?: IJsonContext): TemplateVars | undefined {\n /* c8 ignore next */ // c8 seems to be struggling atm\n return this.options.context?.vars ?? defaultContext?.vars;\n }\n\n /**\n * Gets an {@link IJsonReferenceMap | reference map} containing any other values\n * referenced during the operation.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as\n * {@link TemplateVars | TemplateVars} if the current state does not have context.\n * @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced\n * during this operation.\n */\n public getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined {\n /* c8 ignore next */ // c8 seems to be struggling atm\n return this.options.context?.refs ?? defaultContext?.refs;\n }\n\n /**\n * Gets the context of this {@link JsonEditorState | JsonEditorState} or an optionally\n * supplied default context if this state has no context.\n * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default\n * if this state has no context.\n * @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context\n * is available.\n */\n public getContext(defaultContext?: IJsonContext): IJsonContext | undefined {\n return JsonContextHelper.mergeContext(defaultContext, this.options.context).orDefault();\n }\n\n /**\n * Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables\n * and references into a supplied existing context.\n * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables\n * and references are to be merged, or `undefined` to start with a default empty context.\n * @param add - The {@link VariableValue | variable values} and/or\n * {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.\n * @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.\n */\n public extendContext(\n baseContext: IJsonContext | undefined,\n add: { vars?: VariableValue[]; refs?: IJsonReferenceMap[] }\n ): Result<IJsonContext | undefined> {\n const context = this.getContext(baseContext);\n return JsonContextHelper.extendContext(context, add);\n }\n\n /**\n * Helper method to constructs `DetailedFailure` with appropriate details and messaging\n * for various validation failures.\n * @param rule - The {@link JsonEditorValidationRules | validation rule} that failed.\n * @param message - A string message describing the failed validation.\n * @param validation - The {@link IJsonEditorValidationOptions | validation options}\n * in effect.\n * @returns A `DetailedFailure` with appropriate detail and message.\n */\n public failValidation<T = JsonObject>(\n rule: JsonEditorValidationRules,\n message?: string,\n validation?: IJsonEditorValidationOptions\n ): DetailedFailure<T, JsonEditFailureReason> {\n let detail: JsonPropertyEditFailureReason = 'error';\n const effective = validation ?? this.options.validation;\n switch (rule) {\n case 'invalidPropertyName':\n detail = effective.onInvalidPropertyName !== 'ignore' ? 'error' : 'inapplicable';\n break;\n case 'invalidPropertyValue':\n detail = effective.onInvalidPropertyValue !== 'ignore' ? 'error' : 'ignore';\n break;\n case 'undefinedPropertyValue':\n detail = effective.onUndefinedPropertyValue !== 'error' ? 'ignore' : 'error';\n /* c8 ignore next */\n message = message ?? 'Cannot convert undefined to JSON';\n break;\n }\n /* c8 ignore next */\n return failWithDetail(message ?? rule, detail);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"jsonEditorState.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorState.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAAiF;AACjF,wCAA6G;AAU7G;;;GAGG;AACH,MAAa,eAAe;IA+B1B;;;;;;;;OAQG;IACH,YACE,MAAwB,EACxB,WAA+B,EAC/B,cAA6B;QAxB/B;;;WAGG;QACgB,cAAS,GAAiB,EAAE,CAAC;QAsB9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,O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QACD,oBAAoB;QACpB,OAAO,IAAA,yBAAc,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;;AAzLH,0CA0LC;AAzLC;;;;GAIG;AACc,uBAAO,GAAW,CAAC,AAAZ,CAAa","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonObject } from '@fgv/ts-json-base';\nimport { DetailedFailure, Result, failWithDetail, succeed } from '@fgv/ts-utils';\nimport { IJsonContext, IJsonReferenceMap, JsonContextHelper, TemplateVars, VariableValue } from '../context';\nimport {\n IJsonCloneEditor,\n IJsonEditorOptions,\n IJsonEditorValidationOptions,\n JsonEditFailureReason,\n JsonEditorValidationRules,\n JsonPropertyEditFailureReason\n} from './common';\n\n/**\n * Represents the internal state of a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport class JsonEditorState {\n /**\n * Static global counter used to assign each {@link JsonEditorState | JsonEditorState}\n * a unique identifier.\n * @internal\n */\n protected static _nextId: number = 0;\n\n /**\n * The {@link IJsonCloneEditor | editor} for which this state applies.\n */\n public readonly editor: IJsonCloneEditor;\n\n /**\n * Fully resolved {@link IJsonEditorOptions | editor options} that apply\n * to the operation for which this state applies.\n */\n public readonly options: IJsonEditorOptions;\n\n /**\n * Any deferred JSON objects to be merged during finalization.\n * @internal\n */\n protected readonly _deferred: JsonObject[] = [];\n\n /**\n * Unique global identifier for this {@link JsonEditorState | state object}.\n * @internal\n */\n protected readonly _id: number;\n\n /**\n * Constructs a new {@link JsonEditorState | JsonEditorState}.\n * @param editor - The {@link IJsonCloneEditor | editor} to which this state\n * applies.\n * @param baseOptions - The {@link IJsonEditorOptions | editor options} that\n * apply to this rule.\n * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used\n * for json value conversion.\n */\n public constructor(\n editor: IJsonCloneEditor,\n baseOptions: IJsonEditorOptions,\n runtimeContext?: IJsonContext\n ) {\n this.editor = editor;\n this.options = JsonEditorState._getEffectiveOptions(baseOptions, runtimeContext).orThrow();\n this._id = JsonEditorState._nextId++;\n }\n\n /**\n * The optional {@link IJsonContext | JSON context} for this state.\n */\n public get context(): IJsonContext | undefined {\n return this.options.context;\n }\n\n /**\n * An array of JSON objects that were deferred for merge during\n * finalization.\n */\n public get deferred(): JsonObject[] {\n return this._deferred;\n }\n\n /**\n * Merges an optional {@link IJsonContext | JSON context} into a supplied set\n * of {@link IJsonEditorOptions | JSON editor options}.\n * @param options - The {@link IJsonEditorOptions | IJsonEditorOptions} into\n * which the the new context is to be merged.\n * @param context - The {@link IJsonContext | JSON context} to be merged into the\n * editor options.\n * @returns `Success` with the supplied {@link IJsonEditorOptions | options} if\n * there was nothing to merge, or aa new {@link IJsonEditorOptions | IJsonEditorOptions}\n * constructed from the base options merged with the supplied context. Returns `Failure`\n * with more information if an error occurs.\n * @internal\n */\n protected static _getEffectiveOptions(\n options: IJsonEditorOptions,\n context?: IJsonContext\n ): Result<IJsonEditorOptions> {\n if (!context) {\n return succeed(options);\n }\n return JsonContextHelper.mergeContext(options.context, context).onSuccess((merged) => {\n return succeed({ context: merged, validation: options.validation, merge: options.merge });\n });\n }\n\n /**\n * Adds a supplied `JsonObject` to the deferred list.\n * @param obj - The `JsonObject` to be deferred.\n */\n public defer(obj: JsonObject): void {\n this._deferred.push(obj);\n }\n\n /**\n * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link JsonEditorState | JsonEditorState},\n * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default\n * context.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`\n * if the current state does not have context.\n * @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or\n * `undefined` if no vars are found.\n */\n public getVars(defaultContext?: IJsonContext): TemplateVars | undefined {\n /* c8 ignore next */ // c8 seems to be struggling atm\n return this.options.context?.vars ?? defaultContext?.vars;\n }\n\n /**\n * Gets an {@link IJsonReferenceMap | reference map} containing any other values\n * referenced during the operation.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as\n * {@link TemplateVars | TemplateVars} if the current state does not have context.\n * @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced\n * during this operation.\n */\n public getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined {\n /* c8 ignore next */ // c8 seems to be struggling atm\n return this.options.context?.refs ?? defaultContext?.refs;\n }\n\n /**\n * Gets the context of this {@link JsonEditorState | JsonEditorState} or an optionally\n * supplied default context if this state has no context.\n * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default\n * if this state has no context.\n * @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context\n * is available.\n */\n public getContext(defaultContext?: IJsonContext): IJsonContext | undefined {\n return JsonContextHelper.mergeContext(defaultContext, this.options.context).orDefault();\n }\n\n /**\n * Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables\n * and references into a supplied existing context.\n * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables\n * and references are to be merged, or `undefined` to start with a default empty context.\n * @param add - The {@link VariableValue | variable values} and/or\n * {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.\n * @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.\n */\n public extendContext(\n baseContext: IJsonContext | undefined,\n add: { vars?: VariableValue[]; refs?: IJsonReferenceMap[] }\n ): Result<IJsonContext | undefined> {\n const context = this.getContext(baseContext);\n return JsonContextHelper.extendContext(context, add);\n }\n\n /**\n * Helper method to constructs `DetailedFailure` with appropriate details and messaging\n * for various validation failures.\n * @param rule - The {@link JsonEditorValidationRules | validation rule} that failed.\n * @param message - A string message describing the failed validation.\n * @param validation - The {@link IJsonEditorValidationOptions | validation options}\n * in effect.\n * @returns A `DetailedFailure` with appropriate detail and message.\n */\n public failValidation<T = JsonObject>(\n rule: JsonEditorValidationRules,\n message?: string,\n validation?: IJsonEditorValidationOptions\n ): DetailedFailure<T, JsonEditFailureReason> {\n let detail: JsonPropertyEditFailureReason = 'error';\n const effective = validation ?? this.options.validation;\n switch (rule) {\n case 'invalidPropertyName':\n detail = effective.onInvalidPropertyName !== 'ignore' ? 'error' : 'inapplicable';\n break;\n case 'invalidPropertyValue':\n detail = effective.onInvalidPropertyValue !== 'ignore' ? 'error' : 'ignore';\n break;\n case 'undefinedPropertyValue':\n detail = effective.onUndefinedPropertyValue !== 'error' ? 'ignore' : 'error';\n /* c8 ignore next */\n message = message ?? 'Cannot convert undefined to JSON';\n break;\n }\n /* c8 ignore next */\n return failWithDetail(message ?? rule, detail);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,62 +1,64 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
2
|
+
"name": "@fgv/ts-json",
|
|
3
|
+
"version": "5.0.0-0",
|
|
4
|
+
"description": "Typescript utilities for working with JSON",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "dist/ts-json.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"typescript",
|
|
9
|
+
"json"
|
|
10
|
+
],
|
|
11
|
+
"author": "Erik Fortune",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/ErikFortune/fgv/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-json#readme",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/jest": "^29.5.14",
|
|
20
|
+
"@types/mustache": "^4.2.5",
|
|
21
|
+
"@types/node": "^20.14.9",
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "^7.14.1",
|
|
23
|
+
"@typescript-eslint/parser": "^7.14.1",
|
|
24
|
+
"eslint": "^8.57.0",
|
|
25
|
+
"eslint-plugin-import": "^2.32.0",
|
|
26
|
+
"eslint-plugin-node": "^11.1.0",
|
|
27
|
+
"eslint-plugin-promise": "^6.2.0",
|
|
28
|
+
"jest": "^29.7.0",
|
|
29
|
+
"jest-extended": "^4.0.2",
|
|
30
|
+
"mustache": "^4.2.0",
|
|
31
|
+
"rimraf": "^5.0.7",
|
|
32
|
+
"ts-jest": "^29.4.0",
|
|
33
|
+
"ts-node": "^10.9.2",
|
|
34
|
+
"typescript": "^5.7.3",
|
|
35
|
+
"eslint-plugin-n": "^16.6.2",
|
|
36
|
+
"@rushstack/heft-node-rig": "~2.9.0",
|
|
37
|
+
"@rushstack/heft": "~0.74.0",
|
|
38
|
+
"heft-jest": "~1.0.2",
|
|
39
|
+
"@types/heft-jest": "1.0.6",
|
|
40
|
+
"@microsoft/api-documenter": "^7.26.29",
|
|
41
|
+
"@rushstack/eslint-config": "~4.4.0",
|
|
42
|
+
"eslint-plugin-tsdoc": "~0.4.0",
|
|
43
|
+
"@fgv/ts-utils": "5.0.0-0",
|
|
44
|
+
"@fgv/ts-json-base": "5.0.0-0",
|
|
45
|
+
"@fgv/ts-utils-jest": "5.0.0-0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"mustache": "^4.2.0",
|
|
49
|
+
"@fgv/ts-utils": "5.0.0-0",
|
|
50
|
+
"@fgv/ts-json-base": "5.0.0-0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "heft build --clean",
|
|
54
|
+
"clean": "heft clean",
|
|
55
|
+
"test": "heft test --clean",
|
|
56
|
+
"build-docs": "api-documenter markdown --input-folder ./temp --output-folder docs",
|
|
57
|
+
"build-all": "rushx build; rushx build-docs",
|
|
58
|
+
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
59
|
+
"clean-jest": "jest --clear-cache",
|
|
60
|
+
"coverage": "jest --coverage --no-cache",
|
|
61
|
+
"lint": "eslint src --ext .ts",
|
|
62
|
+
"fixlint": "eslint src --ext .ts --fix"
|
|
63
|
+
}
|
|
64
|
+
}
|