@fgv/ts-json 3.0.1-alpha.5 → 4.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.
Files changed (50) hide show
  1. package/CHANGELOG.json +15 -0
  2. package/CHANGELOG.md +9 -1
  3. package/dist/ts-json.d.ts +154 -155
  4. package/dist/tsdoc-metadata.json +1 -1
  5. package/lib/packlets/context/compositeJsonMap.d.ts +2 -2
  6. package/lib/packlets/context/compositeJsonMap.js +2 -2
  7. package/lib/packlets/context/compositeJsonMap.js.map +1 -1
  8. package/lib/packlets/context/contextHelpers.d.ts +2 -2
  9. package/lib/packlets/context/contextHelpers.js +2 -2
  10. package/lib/packlets/context/contextHelpers.js.map +1 -1
  11. package/lib/packlets/context/jsonContext.d.ts +5 -5
  12. package/lib/packlets/context/jsonContext.js.map +1 -1
  13. package/lib/packlets/converters/converters.d.ts +2 -2
  14. package/lib/packlets/converters/converters.js +2 -2
  15. package/lib/packlets/converters/converters.js.map +1 -1
  16. package/lib/packlets/converters/jsonConverter.d.ts +6 -6
  17. package/lib/packlets/converters/jsonConverter.js +6 -6
  18. package/lib/packlets/converters/jsonConverter.js.map +1 -1
  19. package/lib/packlets/editor/common.d.ts +6 -6
  20. package/lib/packlets/editor/common.js.map +1 -1
  21. package/lib/packlets/editor/index.d.ts +2 -2
  22. package/lib/packlets/editor/index.d.ts.map +1 -1
  23. package/lib/packlets/editor/index.js +3 -1
  24. package/lib/packlets/editor/index.js.map +1 -1
  25. package/lib/packlets/editor/jsonEditor.d.ts +24 -24
  26. package/lib/packlets/editor/jsonEditor.js +21 -21
  27. package/lib/packlets/editor/jsonEditor.js.map +1 -1
  28. package/lib/packlets/editor/jsonEditorRule.d.ts +17 -17
  29. package/lib/packlets/editor/jsonEditorRule.js +4 -4
  30. package/lib/packlets/editor/jsonEditorRule.js.map +1 -1
  31. package/lib/packlets/editor/jsonEditorState.d.ts +20 -20
  32. package/lib/packlets/editor/jsonEditorState.js +17 -17
  33. package/lib/packlets/editor/jsonEditorState.js.map +1 -1
  34. package/lib/packlets/editor/jsonReferenceMap.d.ts +12 -13
  35. package/lib/packlets/editor/jsonReferenceMap.d.ts.map +1 -1
  36. package/lib/packlets/editor/jsonReferenceMap.js +7 -8
  37. package/lib/packlets/editor/jsonReferenceMap.js.map +1 -1
  38. package/lib/packlets/editor/rules/conditional.d.ts +17 -17
  39. package/lib/packlets/editor/rules/conditional.js +12 -12
  40. package/lib/packlets/editor/rules/conditional.js.map +1 -1
  41. package/lib/packlets/editor/rules/multivalue.d.ts +13 -13
  42. package/lib/packlets/editor/rules/multivalue.js +11 -11
  43. package/lib/packlets/editor/rules/multivalue.js.map +1 -1
  44. package/lib/packlets/editor/rules/references.d.ts +12 -12
  45. package/lib/packlets/editor/rules/references.js +11 -11
  46. package/lib/packlets/editor/rules/references.js.map +1 -1
  47. package/lib/packlets/editor/rules/templates.d.ts +14 -14
  48. package/lib/packlets/editor/rules/templates.js +12 -12
  49. package/lib/packlets/editor/rules/templates.js.map +1 -1
  50. package/package.json +15 -15
@@ -1,8 +1,8 @@
1
1
  import * as EditorRules from './rules';
2
2
  export * from './common';
3
3
  export { JsonEditor } from './jsonEditor';
4
- export { IJsonEditorRule } from './jsonEditorRule';
4
+ export { IJsonEditorRule, JsonEditorRuleBase } from './jsonEditorRule';
5
5
  export { JsonEditorState } from './jsonEditorState';
6
- export { IReferenceMapKeyPolicyValidateOptions, PrefixedJsonMap, ReferenceMapKeyPolicy, SimpleJsonMap } from './jsonReferenceMap';
6
+ export { IReferenceMapKeyPolicyValidateOptions, ISimpleJsonMapOptions, PrefixedJsonMap, ReferenceMapKeyPolicy, SimpleJsonMap } from './jsonReferenceMap';
7
7
  export { EditorRules };
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/editor/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,WAAW,MAAM,SAAS,CAAC;AAEvC,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACL,qCAAqC,EACrC,eAAe,EACf,qBAAqB,EACrB,aAAa,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/editor/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,WAAW,MAAM,SAAS,CAAC;AAEvC,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACL,qCAAqC,EACrC,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACrB,aAAa,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -47,12 +47,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
47
47
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.EditorRules = exports.SimpleJsonMap = exports.ReferenceMapKeyPolicy = exports.PrefixedJsonMap = exports.JsonEditorState = exports.JsonEditor = void 0;
50
+ exports.EditorRules = exports.SimpleJsonMap = exports.ReferenceMapKeyPolicy = exports.PrefixedJsonMap = exports.JsonEditorState = exports.JsonEditorRuleBase = exports.JsonEditor = void 0;
51
51
  const EditorRules = __importStar(require("./rules"));
52
52
  exports.EditorRules = EditorRules;
53
53
  __exportStar(require("./common"), exports);
54
54
  var jsonEditor_1 = require("./jsonEditor");
55
55
  Object.defineProperty(exports, "JsonEditor", { enumerable: true, get: function () { return jsonEditor_1.JsonEditor; } });
56
+ var jsonEditorRule_1 = require("./jsonEditorRule");
57
+ Object.defineProperty(exports, "JsonEditorRuleBase", { enumerable: true, get: function () { return jsonEditorRule_1.JsonEditorRuleBase; } });
56
58
  var jsonEditorState_1 = require("./jsonEditorState");
57
59
  Object.defineProperty(exports, "JsonEditorState", { enumerable: true, get: function () { return jsonEditorState_1.JsonEditorState; } });
58
60
  var jsonReferenceMap_1 = require("./jsonReferenceMap");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/editor/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,qDAAuC;AAY9B,kCAAW;AAVpB,2CAAyB;AACzB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AAEnB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,uDAK4B;AAH1B,mHAAA,eAAe,OAAA;AACf,yHAAA,qBAAqB,OAAA;AACrB,iHAAA,aAAa,OAAA","sourcesContent":["/*\n * Copyright (c) 2023 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 * as EditorRules from './rules';\n\nexport * from './common';\nexport { JsonEditor } from './jsonEditor';\nexport { IJsonEditorRule } from './jsonEditorRule';\nexport { JsonEditorState } from './jsonEditorState';\nexport {\n IReferenceMapKeyPolicyValidateOptions,\n PrefixedJsonMap,\n ReferenceMapKeyPolicy,\n SimpleJsonMap\n} from './jsonReferenceMap';\nexport { EditorRules };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/editor/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,qDAAuC;AAa9B,kCAAW;AAXpB,2CAAyB;AACzB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,mDAAuE;AAA7C,oHAAA,kBAAkB,OAAA;AAC5C,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,uDAM4B;AAH1B,mHAAA,eAAe,OAAA;AACf,yHAAA,qBAAqB,OAAA;AACrB,iHAAA,aAAa,OAAA","sourcesContent":["/*\n * Copyright (c) 2023 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 * as EditorRules from './rules';\n\nexport * from './common';\nexport { JsonEditor } from './jsonEditor';\nexport { IJsonEditorRule, JsonEditorRuleBase } from './jsonEditorRule';\nexport { JsonEditorState } from './jsonEditorState';\nexport {\n IReferenceMapKeyPolicyValidateOptions,\n ISimpleJsonMapOptions,\n PrefixedJsonMap,\n ReferenceMapKeyPolicy,\n SimpleJsonMap\n} from './jsonReferenceMap';\nexport { EditorRules };\n"]}
@@ -12,48 +12,48 @@ import { JsonEditorState } from './jsonEditorState';
12
12
  */
13
13
  export declare class JsonEditor implements IJsonCloneEditor {
14
14
  /**
15
- * Default singleton {@link Editor.JsonEditor | JsonEditor}.
15
+ * Default singleton {@link JsonEditor | JsonEditor}.
16
16
  * @internal
17
17
  */
18
18
  protected static _default?: JsonEditor;
19
19
  /**
20
- * Full set of {@link Editor.IJsonEditorOptions | editor options} in effect for this editor.
20
+ * Full set of {@link IJsonEditorOptions | editor options} in effect for this editor.
21
21
  */
22
22
  options: IJsonEditorOptions;
23
23
  /**
24
- * The set of {@link Editor.IJsonEditorRule | editor rules} applied by this editor.
24
+ * The set of {@link IJsonEditorRule | editor rules} applied by this editor.
25
25
  * @internal
26
26
  */
27
27
  protected _rules: IJsonEditorRule[];
28
28
  /**
29
- * Protected constructor for {@link Editor.JsonEditor | JsonEditor} and derived classes.
30
- * External consumers should instantiate via the {@link Editor.JsonEditor.create | create static method}.
31
- * @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for the
29
+ * Protected constructor for {@link JsonEditor | JsonEditor} and derived classes.
30
+ * External consumers should instantiate via the {@link JsonEditor.create | create static method}.
31
+ * @param options - Optional partial {@link IJsonEditorOptions | editor options} for the
32
32
  * constructed editor.
33
- * @param rules - Any {@link Editor.IJsonEditorRule | editor rules} to be applied by the editor.
33
+ * @param rules - Any {@link IJsonEditorRule | editor rules} to be applied by the editor.
34
34
  * @internal
35
35
  */
36
36
  protected constructor(options?: Partial<IJsonEditorOptions>, rules?: IJsonEditorRule[]);
37
37
  /**
38
- * Default singleton {@link Editor.JsonEditor | JsonEditor} for simple use. Applies all rules
38
+ * Default singleton {@link JsonEditor | JsonEditor} for simple use. Applies all rules
39
39
  * but with no default context.
40
40
  */
41
41
  static get default(): JsonEditor;
42
42
  /**
43
- * Constructs a new {@link Editor.JsonEditor | JsonEditor}.
44
- * @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for the
43
+ * Constructs a new {@link JsonEditor | JsonEditor}.
44
+ * @param options - Optional partial {@link IJsonEditorOptions | editor options} for the
45
45
  * constructed editor.
46
- * @param rules - Optional set of {@link Editor.IJsonEditorRule | editor rules} to be applied by the editor.
47
- * @readonly A new {@link Editor.JsonEditor | JsonEditor}.
46
+ * @param rules - Optional set of {@link IJsonEditorRule | editor rules} to be applied by the editor.
47
+ * @readonly A new {@link JsonEditor | JsonEditor}.
48
48
  */
49
49
  static create(options?: Partial<IJsonEditorOptions>, rules?: IJsonEditorRule[]): Result<JsonEditor>;
50
50
  /**
51
51
  * Gets the default set of rules to be applied for a given set of options.
52
52
  * By default, all available rules (templates, conditionals, multi-value and references)
53
53
  * are applied.
54
- * @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for
54
+ * @param options - Optional partial {@link IJsonEditorOptions | editor options} for
55
55
  * all rules.
56
- * @returns Default {@link Editor.IJsonEditorRule | editor rules} with any supplied options
56
+ * @returns Default {@link IJsonEditorRule | editor rules} with any supplied options
57
57
  * applied.
58
58
  */
59
59
  static getDefaultRules(options?: IJsonEditorOptions): Result<IJsonEditorRule[]>;
@@ -63,21 +63,21 @@ export declare class JsonEditor implements IJsonCloneEditor {
63
63
  protected static _getDefaultOptions(options?: Partial<IJsonEditorOptions>): Result<IJsonEditorOptions>;
64
64
  /**
65
65
  * Merges a supplied source object into a supplied target, updating the target object.
66
- * @param target - The target {@link JsonObject | object} to be updated
67
- * @param src - The source {@link JsonObject | object} to be merged
66
+ * @param target - The target `JsonObject` to be updated
67
+ * @param src - The source `JsonObject` to be merged
68
68
  * @param runtimeContext - An optional {@link IJsonContext | IJsonContext} supplying variables
69
69
  * and references.
70
- * @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
70
+ * @returns `Success` with the original source `JsonObject` if merge was successful.
71
71
  * Returns `Failure` with details if an error occurs.
72
72
  */
73
73
  mergeObjectInPlace(target: JsonObject, src: JsonObject, runtimeContext?: IJsonContext): Result<JsonObject>;
74
74
  /**
75
75
  * Merges multiple supplied source objects into a supplied target, updating the target
76
76
  * object and using the default context supplied at creation time.
77
- * @param target - The target {@link JsonObject | object} to be updated
78
- * @param srcObjects - {@link JsonObject | Objects} to be merged into the target object, in the order
77
+ * @param target - The target `JsonObject` to be updated
78
+ * @param srcObjects - `JsonObject`s to be merged into the target object, in the order
79
79
  * supplied.
80
- * @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
80
+ * @returns `Success` with the original source `JsonObject` if merge was successful.
81
81
  * Returns `Failure` with details if an error occurs.
82
82
  */
83
83
  mergeObjectsInPlace(target: JsonObject, srcObjects: JsonObject[]): Result<JsonObject>;
@@ -86,16 +86,16 @@ export declare class JsonEditor implements IJsonCloneEditor {
86
86
  * object and using an optional {@link IJsonContext | context} supplied in the call.
87
87
  * @param context - An optional {@link IJsonContext | IJsonContext} supplying variables and
88
88
  * references.
89
- * @param base - The base {@link JsonObject | object} to be updated
89
+ * @param base - The base `JsonObject` to be updated
90
90
  * @param srcObjects - Objects to be merged into the target object, in the order supplied.
91
- * @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
91
+ * @returns `Success` with the original source `JsonObject` if merge was successful.
92
92
  * Returns `Failure` with details if an error occurs.
93
93
  */
94
94
  mergeObjectsInPlaceWithContext(context: IJsonContext | undefined, base: JsonObject, srcObjects: JsonObject[]): Result<JsonObject>;
95
95
  /**
96
- * Deep clones a supplied {@link JsonValue | JSON value}, applying all editor rules and a default
96
+ * Deep clones a supplied `JsonValue`, applying all editor rules and a default
97
97
  * or optionally supplied context
98
- * @param src - The {@link JsonValue | JsonValue} to be cloned.
98
+ * @param src - The `JsonValue` to be cloned.
99
99
  * @param context - An optional {@link IJsonContext | JSON context} supplying variables and references.
100
100
  */
101
101
  clone(src: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonEditFailureReason>;
@@ -34,11 +34,11 @@ const jsonEditorState_1 = require("./jsonEditorState");
34
34
  */
35
35
  class JsonEditor {
36
36
  /**
37
- * Protected constructor for {@link Editor.JsonEditor | JsonEditor} and derived classes.
38
- * External consumers should instantiate via the {@link Editor.JsonEditor.create | create static method}.
39
- * @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for the
37
+ * Protected constructor for {@link JsonEditor | JsonEditor} and derived classes.
38
+ * External consumers should instantiate via the {@link JsonEditor.create | create static method}.
39
+ * @param options - Optional partial {@link IJsonEditorOptions | editor options} for the
40
40
  * constructed editor.
41
- * @param rules - Any {@link Editor.IJsonEditorRule | editor rules} to be applied by the editor.
41
+ * @param rules - Any {@link IJsonEditorRule | editor rules} to be applied by the editor.
42
42
  * @internal
43
43
  */
44
44
  constructor(options, rules) {
@@ -46,7 +46,7 @@ class JsonEditor {
46
46
  this._rules = rules || JsonEditor.getDefaultRules(this.options).orThrow();
47
47
  }
48
48
  /**
49
- * Default singleton {@link Editor.JsonEditor | JsonEditor} for simple use. Applies all rules
49
+ * Default singleton {@link JsonEditor | JsonEditor} for simple use. Applies all rules
50
50
  * but with no default context.
51
51
  */
52
52
  static get default() {
@@ -57,11 +57,11 @@ class JsonEditor {
57
57
  return JsonEditor._default;
58
58
  }
59
59
  /**
60
- * Constructs a new {@link Editor.JsonEditor | JsonEditor}.
61
- * @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for the
60
+ * Constructs a new {@link JsonEditor | JsonEditor}.
61
+ * @param options - Optional partial {@link IJsonEditorOptions | editor options} for the
62
62
  * constructed editor.
63
- * @param rules - Optional set of {@link Editor.IJsonEditorRule | editor rules} to be applied by the editor.
64
- * @readonly A new {@link Editor.JsonEditor | JsonEditor}.
63
+ * @param rules - Optional set of {@link IJsonEditorRule | editor rules} to be applied by the editor.
64
+ * @readonly A new {@link JsonEditor | JsonEditor}.
65
65
  */
66
66
  static create(options, rules) {
67
67
  return (0, ts_utils_1.captureResult)(() => new JsonEditor(options, rules));
@@ -70,9 +70,9 @@ class JsonEditor {
70
70
  * Gets the default set of rules to be applied for a given set of options.
71
71
  * By default, all available rules (templates, conditionals, multi-value and references)
72
72
  * are applied.
73
- * @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for
73
+ * @param options - Optional partial {@link IJsonEditorOptions | editor options} for
74
74
  * all rules.
75
- * @returns Default {@link Editor.IJsonEditorRule | editor rules} with any supplied options
75
+ * @returns Default {@link IJsonEditorRule | editor rules} with any supplied options
76
76
  * applied.
77
77
  */
78
78
  static getDefaultRules(options) {
@@ -100,11 +100,11 @@ class JsonEditor {
100
100
  }
101
101
  /**
102
102
  * Merges a supplied source object into a supplied target, updating the target object.
103
- * @param target - The target {@link JsonObject | object} to be updated
104
- * @param src - The source {@link JsonObject | object} to be merged
103
+ * @param target - The target `JsonObject` to be updated
104
+ * @param src - The source `JsonObject` to be merged
105
105
  * @param runtimeContext - An optional {@link IJsonContext | IJsonContext} supplying variables
106
106
  * and references.
107
- * @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
107
+ * @returns `Success` with the original source `JsonObject` if merge was successful.
108
108
  * Returns `Failure` with details if an error occurs.
109
109
  */
110
110
  mergeObjectInPlace(target, src, runtimeContext) {
@@ -116,10 +116,10 @@ class JsonEditor {
116
116
  /**
117
117
  * Merges multiple supplied source objects into a supplied target, updating the target
118
118
  * object and using the default context supplied at creation time.
119
- * @param target - The target {@link JsonObject | object} to be updated
120
- * @param srcObjects - {@link JsonObject | Objects} to be merged into the target object, in the order
119
+ * @param target - The target `JsonObject` to be updated
120
+ * @param srcObjects - `JsonObject`s to be merged into the target object, in the order
121
121
  * supplied.
122
- * @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
122
+ * @returns `Success` with the original source `JsonObject` if merge was successful.
123
123
  * Returns `Failure` with details if an error occurs.
124
124
  */
125
125
  mergeObjectsInPlace(target, srcObjects) {
@@ -130,9 +130,9 @@ class JsonEditor {
130
130
  * object and using an optional {@link IJsonContext | context} supplied in the call.
131
131
  * @param context - An optional {@link IJsonContext | IJsonContext} supplying variables and
132
132
  * references.
133
- * @param base - The base {@link JsonObject | object} to be updated
133
+ * @param base - The base `JsonObject` to be updated
134
134
  * @param srcObjects - Objects to be merged into the target object, in the order supplied.
135
- * @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
135
+ * @returns `Success` with the original source `JsonObject` if merge was successful.
136
136
  * Returns `Failure` with details if an error occurs.
137
137
  */
138
138
  mergeObjectsInPlaceWithContext(context, base, srcObjects) {
@@ -145,9 +145,9 @@ class JsonEditor {
145
145
  return (0, ts_utils_1.succeedWithDetail)(base);
146
146
  }
147
147
  /**
148
- * Deep clones a supplied {@link JsonValue | JSON value}, applying all editor rules and a default
148
+ * Deep clones a supplied `JsonValue`, applying all editor rules and a default
149
149
  * or optionally supplied context
150
- * @param src - The {@link JsonValue | JsonValue} to be cloned.
150
+ * @param src - The `JsonValue` to be cloned.
151
151
  * @param context - An optional {@link IJsonContext | JSON context} supplying variables and references.
152
152
  */
153
153
  clone(src, context) {
@@ -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;A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C;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 Editor.JsonEditor | JsonEditor}.\n * @internal\n */\n protected static _default?: JsonEditor;\n\n /**\n * Full set of {@link Editor.IJsonEditorOptions | editor options} in effect for this editor.\n */\n public options: IJsonEditorOptions;\n\n /**\n * The set of {@link Editor.IJsonEditorRule | editor rules} applied by this editor.\n * @internal\n */\n protected _rules: IJsonEditorRule[];\n\n /**\n * Protected constructor for {@link Editor.JsonEditor | JsonEditor} and derived classes.\n * External consumers should instantiate via the {@link Editor.JsonEditor.create | create static method}.\n * @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for the\n * constructed editor.\n * @param rules - Any {@link Editor.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 Editor.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 Editor.JsonEditor | JsonEditor}.\n * @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for the\n * constructed editor.\n * @param rules - Optional set of {@link Editor.IJsonEditorRule | editor rules} to be applied by the editor.\n * @readonly A new {@link Editor.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 Editor.IJsonEditorOptions | editor options} for\n * all rules.\n * @returns Default {@link Editor.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 {@link JsonObject | object} to be updated\n * @param src - The source {@link JsonObject | object} to be merged\n * @param runtimeContext - An optional {@link IJsonContext | IJsonContext} supplying variables\n * and references.\n * @returns `Success` with the original source {@link JsonObject | object} 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 {@link JsonObject | object} to be updated\n * @param srcObjects - {@link JsonObject | Objects} to be merged into the target object, in the order\n * supplied.\n * @returns `Success` with the original source {@link JsonObject | object} 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 {@link JsonObject | object} 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 {@link JsonObject | object} 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 {@link JsonValue | JSON value}, applying all editor rules and a default\n * or optionally supplied context\n * @param src - The {@link JsonValue | 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;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;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,OAAqC,EAAE,KAAyB;QACnF,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,eAAe,CAAC,OAA4B;QACxD,OAAO,IAAA,qBAAU,EAAkB;YACjC,+BAAuB,CAAC,MAAM,CAAC,OAAO,CAAC;YACvC,iCAAy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AC;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"]}
@@ -3,29 +3,29 @@ import { DetailedResult } from '@fgv/ts-utils';
3
3
  import { JsonEditFailureReason, JsonPropertyEditFailureReason } from './common';
4
4
  import { JsonEditorState } from './jsonEditorState';
5
5
  /**
6
- * An {@link Editor.IJsonEditorRule | IJsonEditorRule} represents a single configurable
7
- * rule to be applied by a {@link Editor.JsonEditor | JsonEditor}.
6
+ * An {@link IJsonEditorRule | IJsonEditorRule} represents a single configurable
7
+ * rule to be applied by a {@link JsonEditor | JsonEditor}.
8
8
  * @public
9
9
  */
10
10
  export interface IJsonEditorRule {
11
11
  /**
12
- * Called by a {@link Editor.JsonEditor | JsonEditor} to possibly edit one of the properties being
12
+ * Called by a {@link JsonEditor | JsonEditor} to possibly edit one of the properties being
13
13
  * merged into a target object.
14
14
  * @param key - The key of the property to be edited.
15
- * @param value - The {@link JsonValue | value} of the property to be edited.
16
- * @param state - {@link Editor.JsonEditorState | Editor state} which applies to the edit.
17
- * @returns If the property was edited, returns `Success` with a {@link JsonObject | JsonObject} containing
15
+ * @param value - The `JsonValue` of the property to be edited.
16
+ * @param state - {@link JsonEditorState | Editor state} which applies to the edit.
17
+ * @returns If the property was edited, returns `Success` with a `JsonObject` containing
18
18
  * the edited results and with detail `'edited'`. If this property should be deferred for later consideration
19
- * or merge, `Success` with detail `'deferred'` and a {@link JsonObject | JsonObject} to be finalized. If
19
+ * or merge, `Success` with detail `'deferred'` and a `JsonObject` to be finalized. If
20
20
  * the rule does not affect this property, returns `Failure` with detail `'inapplicable'`. If an error occurred
21
21
  * while processing the error, returns `Failure` with detail `'error'`.
22
22
  */
23
23
  editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
24
24
  /**
25
- * Called by a {@link Editor.JsonEditor | JsonEditor} to possibly edit a property value or array element.
26
- * @param value - The {@link JsonValue | value} of the property to be edited.
27
- * @param state - {@link Editor.JsonEditorState | Editor state} which applies to the edit.
28
- * @returns Returns `Success` with the {@link JsonValue | JsonValue} to be inserted, with detail `'edited'` if
25
+ * Called by a {@link JsonEditor | JsonEditor} to possibly edit a property value or array element.
26
+ * @param value - The `JsonValue` of the property to be edited.
27
+ * @param state - {@link JsonEditorState | Editor state} which applies to the edit.
28
+ * @returns Returns `Success` with the `JsonValue` to be inserted, with detail `'edited'` if
29
29
  * the value was edited. Returns `Failure` with `'inapplicable'` if the rule does not affect this value.
30
30
  * Fails with detail `'ignore'` if the value is to be ignored, or with `'error'` if an error occurs.
31
31
  */
@@ -33,8 +33,8 @@ export interface IJsonEditorRule {
33
33
  /**
34
34
  * Called for each rule after all properties have been merged. Any properties that were deferred
35
35
  * during the initial edit pass are supplied as input.
36
- * @param deferred - Any {@link JsonObject | objects} that were deferred during the first edit pass.
37
- * @param state - {@link Editor.JsonEditorState | Editor state} which applies to the edit.
36
+ * @param deferred - Any JSON objects that were deferred during the first edit pass.
37
+ * @param state - {@link JsonEditorState | Editor state} which applies to the edit.
38
38
  * @returns On `Success` return, any returned objects are merged in order and finalization
39
39
  * is stopped. Finalization is also stopped on `Failure` with detail `'ignore'`. On `Failure`
40
40
  * with detail `'inapplicable'`, finalization continues with the next rule. Fails with an
@@ -43,21 +43,21 @@ export interface IJsonEditorRule {
43
43
  finalizeProperties(deferred: JsonObject[], state: JsonEditorState): DetailedResult<JsonObject[], JsonEditFailureReason>;
44
44
  }
45
45
  /**
46
- * Default base implementation of {@link Editor.IJsonEditorRule | IJsonEditorRule} returns inapplicable for all operations so that
46
+ * Default base implementation of {@link IJsonEditorRule | IJsonEditorRule} returns inapplicable for all operations so that
47
47
  * derived classes need only implement the operations they actually support.
48
48
  * @public
49
49
  */
50
50
  export declare class JsonEditorRuleBase implements IJsonEditorRule {
51
51
  /**
52
- * {@inheritdoc Editor.IJsonEditorRule.editProperty}
52
+ * {@inheritdoc IJsonEditorRule.editProperty}
53
53
  */
54
54
  editProperty(__key: string, __value: JsonValue, __state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
55
55
  /**
56
- * {@inheritdoc Editor.IJsonEditorRule.editValue}
56
+ * {@inheritdoc IJsonEditorRule.editValue}
57
57
  */
58
58
  editValue(__value: JsonValue, __state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
59
59
  /**
60
- * {@inheritdoc Editor.IJsonEditorRule.finalizeProperties}
60
+ * {@inheritdoc IJsonEditorRule.finalizeProperties}
61
61
  */
62
62
  finalizeProperties(__deferred: JsonObject[], __state: JsonEditorState): DetailedResult<JsonObject[], JsonEditFailureReason>;
63
63
  }
@@ -24,13 +24,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.JsonEditorRuleBase = void 0;
25
25
  const ts_utils_1 = require("@fgv/ts-utils");
26
26
  /**
27
- * Default base implementation of {@link Editor.IJsonEditorRule | IJsonEditorRule} returns inapplicable for all operations so that
27
+ * Default base implementation of {@link IJsonEditorRule | IJsonEditorRule} returns inapplicable for all operations so that
28
28
  * derived classes need only implement the operations they actually support.
29
29
  * @public
30
30
  */
31
31
  class JsonEditorRuleBase {
32
32
  /**
33
- * {@inheritdoc Editor.IJsonEditorRule.editProperty}
33
+ * {@inheritdoc IJsonEditorRule.editProperty}
34
34
  */
35
35
  /* c8 ignore start */
36
36
  editProperty(__key, __value, __state) {
@@ -38,13 +38,13 @@ class JsonEditorRuleBase {
38
38
  }
39
39
  /* c8 ignore stop */
40
40
  /**
41
- * {@inheritdoc Editor.IJsonEditorRule.editValue}
41
+ * {@inheritdoc IJsonEditorRule.editValue}
42
42
  */
43
43
  editValue(__value, __state) {
44
44
  return (0, ts_utils_1.failWithDetail)('inapplicable', 'inapplicable');
45
45
  }
46
46
  /**
47
- * {@inheritdoc Editor.IJsonEditorRule.finalizeProperties}
47
+ * {@inheritdoc IJsonEditorRule.finalizeProperties}
48
48
  */
49
49
  finalizeProperties(__deferred, __state) {
50
50
  return (0, ts_utils_1.failWithDetail)('inapplicable', 'inapplicable');
@@ -1 +1 @@
1
- {"version":3,"file":"jsonEditorRule.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorRule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAA+D;AAuD/D;;;;GAIG;AACH,MAAa,kBAAkB;IAC7B;;OAEG;IACH,qBAAqB;IACd,YAAY,CACjB,KAAa,EACb,OAAkB,EAClB,OAAwB;QAExB,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IACD,oBAAoB;IAEpB;;OAEG;IACI,SAAS,CACd,OAAkB,EAClB,OAAwB;QAExB,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACI,kBAAkB,CACvB,UAAwB,EACxB,OAAwB;QAExB,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;CACF;AAjCD,gDAiCC","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, JsonValue } from '@fgv/ts-json-base';\nimport { DetailedResult, failWithDetail } from '@fgv/ts-utils';\nimport { JsonEditFailureReason, JsonPropertyEditFailureReason } from './common';\n\nimport { JsonEditorState } from './jsonEditorState';\n\n/**\n * An {@link Editor.IJsonEditorRule | IJsonEditorRule} represents a single configurable\n * rule to be applied by a {@link Editor.JsonEditor | JsonEditor}.\n * @public\n */\nexport interface IJsonEditorRule {\n /**\n * Called by a {@link Editor.JsonEditor | JsonEditor} to possibly edit one of the properties being\n * merged into a target object.\n * @param key - The key of the property to be edited.\n * @param value - The {@link JsonValue | value} of the property to be edited.\n * @param state - {@link Editor.JsonEditorState | Editor state} which applies to the edit.\n * @returns If the property was edited, returns `Success` with a {@link JsonObject | JsonObject} containing\n * the edited results and with detail `'edited'`. If this property should be deferred for later consideration\n * or merge, `Success` with detail `'deferred'` and a {@link JsonObject | JsonObject} to be finalized. If\n * the rule does not affect this property, returns `Failure` with detail `'inapplicable'`. If an error occurred\n * while processing the error, returns `Failure` with detail `'error'`.\n */\n editProperty(\n key: string,\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;\n\n /**\n * Called by a {@link Editor.JsonEditor | JsonEditor} to possibly edit a property value or array element.\n * @param value - The {@link JsonValue | value} of the property to be edited.\n * @param state - {@link Editor.JsonEditorState | Editor state} which applies to the edit.\n * @returns Returns `Success` with the {@link JsonValue | JsonValue} to be inserted, with detail `'edited'` if\n * the value was edited. Returns `Failure` with `'inapplicable'` if the rule does not affect this value.\n * Fails with detail `'ignore'` if the value is to be ignored, or with `'error'` if an error occurs.\n */\n editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;\n\n /**\n * Called for each rule after all properties have been merged. Any properties that were deferred\n * during the initial edit pass are supplied as input.\n * @param deferred - Any {@link JsonObject | objects} that were deferred during the first edit pass.\n * @param state - {@link Editor.JsonEditorState | Editor state} which applies to the edit.\n * @returns On `Success` return, any returned objects are merged in order and finalization\n * is stopped. Finalization is also stopped on `Failure` with detail `'ignore'`. On `Failure`\n * with detail `'inapplicable'`, finalization continues with the next rule. Fails with an\n * error detail `'error'` and an informative message if an error occurs.\n */\n finalizeProperties(\n deferred: JsonObject[],\n state: JsonEditorState\n ): DetailedResult<JsonObject[], JsonEditFailureReason>;\n}\n\n/**\n * Default base implementation of {@link Editor.IJsonEditorRule | IJsonEditorRule} returns inapplicable for all operations so that\n * derived classes need only implement the operations they actually support.\n * @public\n */\nexport class JsonEditorRuleBase implements IJsonEditorRule {\n /**\n * {@inheritdoc Editor.IJsonEditorRule.editProperty}\n */\n /* c8 ignore start */\n public editProperty(\n __key: string,\n __value: JsonValue,\n __state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason> {\n return failWithDetail('inapplicable', 'inapplicable');\n }\n /* c8 ignore stop */\n\n /**\n * {@inheritdoc Editor.IJsonEditorRule.editValue}\n */\n public editValue(\n __value: JsonValue,\n __state: JsonEditorState\n ): DetailedResult<JsonValue, JsonEditFailureReason> {\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n * {@inheritdoc Editor.IJsonEditorRule.finalizeProperties}\n */\n public finalizeProperties(\n __deferred: JsonObject[],\n __state: JsonEditorState\n ): DetailedResult<JsonObject[], JsonEditFailureReason> {\n return failWithDetail('inapplicable', 'inapplicable');\n }\n}\n"]}
1
+ {"version":3,"file":"jsonEditorRule.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorRule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAA+D;AAuD/D;;;;GAIG;AACH,MAAa,kBAAkB;IAC7B;;OAEG;IACH,qBAAqB;IACd,YAAY,CACjB,KAAa,EACb,OAAkB,EAClB,OAAwB;QAExB,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IACD,oBAAoB;IAEpB;;OAEG;IACI,SAAS,CACd,OAAkB,EAClB,OAAwB;QAExB,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACI,kBAAkB,CACvB,UAAwB,EACxB,OAAwB;QAExB,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;CACF;AAjCD,gDAiCC","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, JsonValue } from '@fgv/ts-json-base';\nimport { DetailedResult, failWithDetail } from '@fgv/ts-utils';\nimport { JsonEditFailureReason, JsonPropertyEditFailureReason } from './common';\n\nimport { JsonEditorState } from './jsonEditorState';\n\n/**\n * An {@link IJsonEditorRule | IJsonEditorRule} represents a single configurable\n * rule to be applied by a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport interface IJsonEditorRule {\n /**\n * Called by a {@link JsonEditor | JsonEditor} to possibly edit one of the properties being\n * merged into a target object.\n * @param key - The key of the property to be edited.\n * @param value - The `JsonValue` of the property to be edited.\n * @param state - {@link JsonEditorState | Editor state} which applies to the edit.\n * @returns If the property was edited, returns `Success` with a `JsonObject` containing\n * the edited results and with detail `'edited'`. If this property should be deferred for later consideration\n * or merge, `Success` with detail `'deferred'` and a `JsonObject` to be finalized. If\n * the rule does not affect this property, returns `Failure` with detail `'inapplicable'`. If an error occurred\n * while processing the error, returns `Failure` with detail `'error'`.\n */\n editProperty(\n key: string,\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;\n\n /**\n * Called by a {@link JsonEditor | JsonEditor} to possibly edit a property value or array element.\n * @param value - The `JsonValue` of the property to be edited.\n * @param state - {@link JsonEditorState | Editor state} which applies to the edit.\n * @returns Returns `Success` with the `JsonValue` to be inserted, with detail `'edited'` if\n * the value was edited. Returns `Failure` with `'inapplicable'` if the rule does not affect this value.\n * Fails with detail `'ignore'` if the value is to be ignored, or with `'error'` if an error occurs.\n */\n editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;\n\n /**\n * Called for each rule after all properties have been merged. Any properties that were deferred\n * during the initial edit pass are supplied as input.\n * @param deferred - Any JSON objects that were deferred during the first edit pass.\n * @param state - {@link JsonEditorState | Editor state} which applies to the edit.\n * @returns On `Success` return, any returned objects are merged in order and finalization\n * is stopped. Finalization is also stopped on `Failure` with detail `'ignore'`. On `Failure`\n * with detail `'inapplicable'`, finalization continues with the next rule. Fails with an\n * error detail `'error'` and an informative message if an error occurs.\n */\n finalizeProperties(\n deferred: JsonObject[],\n state: JsonEditorState\n ): DetailedResult<JsonObject[], JsonEditFailureReason>;\n}\n\n/**\n * Default base implementation of {@link IJsonEditorRule | IJsonEditorRule} returns inapplicable for all operations so that\n * derived classes need only implement the operations they actually support.\n * @public\n */\nexport class JsonEditorRuleBase implements IJsonEditorRule {\n /**\n * {@inheritdoc IJsonEditorRule.editProperty}\n */\n /* c8 ignore start */\n public editProperty(\n __key: string,\n __value: JsonValue,\n __state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason> {\n return failWithDetail('inapplicable', 'inapplicable');\n }\n /* c8 ignore stop */\n\n /**\n * {@inheritdoc IJsonEditorRule.editValue}\n */\n public editValue(\n __value: JsonValue,\n __state: JsonEditorState\n ): DetailedResult<JsonValue, JsonEditFailureReason> {\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n * {@inheritdoc IJsonEditorRule.finalizeProperties}\n */\n public finalizeProperties(\n __deferred: JsonObject[],\n __state: JsonEditorState\n ): DetailedResult<JsonObject[], JsonEditFailureReason> {\n return failWithDetail('inapplicable', 'inapplicable');\n }\n}\n"]}