@fgv/ts-json 1.9.5 → 2.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/dist/ts-json.d.ts +1826 -0
  2. package/dist/tsdoc-metadata.json +11 -0
  3. package/lib/index.d.ts +5 -0
  4. package/lib/index.d.ts.map +1 -0
  5. package/lib/index.js +42 -0
  6. package/lib/index.js.map +1 -0
  7. package/lib/packlets/context/compositeJsonMap.d.ts +60 -0
  8. package/lib/packlets/context/compositeJsonMap.d.ts.map +1 -0
  9. package/lib/packlets/context/compositeJsonMap.js +105 -0
  10. package/lib/packlets/context/compositeJsonMap.js.map +1 -0
  11. package/lib/packlets/context/contextHelpers.d.ts +116 -0
  12. package/lib/packlets/context/contextHelpers.d.ts.map +1 -0
  13. package/lib/packlets/context/contextHelpers.js +191 -0
  14. package/lib/packlets/context/contextHelpers.js.map +1 -0
  15. package/lib/packlets/context/index.d.ts +4 -0
  16. package/lib/packlets/context/index.d.ts.map +1 -0
  17. package/lib/packlets/context/index.js +31 -0
  18. package/lib/packlets/context/index.js.map +1 -0
  19. package/lib/packlets/context/jsonContext.d.ts +84 -0
  20. package/lib/packlets/context/jsonContext.d.ts.map +1 -0
  21. package/lib/packlets/context/jsonContext.js +41 -0
  22. package/lib/packlets/context/jsonContext.js.map +1 -0
  23. package/lib/packlets/converters/converters.d.ts +54 -0
  24. package/lib/packlets/converters/converters.d.ts.map +1 -0
  25. package/lib/packlets/converters/converters.js +105 -0
  26. package/lib/packlets/converters/converters.js.map +1 -0
  27. package/lib/packlets/converters/file.d.ts +83 -0
  28. package/lib/packlets/converters/file.d.ts.map +1 -0
  29. package/lib/packlets/converters/file.js +162 -0
  30. package/lib/packlets/converters/file.js.map +1 -0
  31. package/lib/packlets/converters/index.d.ts +5 -0
  32. package/lib/packlets/converters/index.d.ts.map +1 -0
  33. package/{jsonEditor → lib/packlets/converters}/index.js +10 -10
  34. package/lib/packlets/converters/index.js.map +1 -0
  35. package/lib/packlets/converters/jsonConverter.d.ts +276 -0
  36. package/lib/packlets/converters/jsonConverter.d.ts.map +1 -0
  37. package/lib/packlets/converters/jsonConverter.js +310 -0
  38. package/lib/packlets/converters/jsonConverter.js.map +1 -0
  39. package/lib/packlets/editor/common.d.ts +67 -0
  40. package/lib/packlets/editor/common.d.ts.map +1 -0
  41. package/lib/packlets/editor/common.js +3 -0
  42. package/lib/packlets/editor/common.js.map +1 -0
  43. package/lib/packlets/editor/index.d.ts +8 -0
  44. package/lib/packlets/editor/index.d.ts.map +1 -0
  45. package/lib/packlets/editor/index.js +58 -0
  46. package/lib/packlets/editor/index.js.map +1 -0
  47. package/lib/packlets/editor/jsonEditor.d.ts +155 -0
  48. package/lib/packlets/editor/jsonEditor.d.ts.map +1 -0
  49. package/lib/packlets/editor/jsonEditor.js +333 -0
  50. package/lib/packlets/editor/jsonEditor.js.map +1 -0
  51. package/lib/packlets/editor/jsonEditorRule.d.ts +64 -0
  52. package/lib/packlets/editor/jsonEditorRule.d.ts.map +1 -0
  53. package/lib/packlets/editor/jsonEditorRule.js +54 -0
  54. package/lib/packlets/editor/jsonEditorRule.js.map +1 -0
  55. package/lib/packlets/editor/jsonEditorState.d.ts +125 -0
  56. package/lib/packlets/editor/jsonEditorState.d.ts.map +1 -0
  57. package/lib/packlets/editor/jsonEditorState.js +177 -0
  58. package/lib/packlets/editor/jsonEditorState.js.map +1 -0
  59. package/lib/packlets/editor/jsonReferenceMap.d.ts +303 -0
  60. package/lib/packlets/editor/jsonReferenceMap.d.ts.map +1 -0
  61. package/lib/packlets/editor/jsonReferenceMap.js +324 -0
  62. package/lib/packlets/editor/jsonReferenceMap.js.map +1 -0
  63. package/lib/packlets/editor/rules/conditional.d.ts +107 -0
  64. package/lib/packlets/editor/rules/conditional.d.ts.map +1 -0
  65. package/lib/packlets/editor/rules/conditional.js +167 -0
  66. package/lib/packlets/editor/rules/conditional.js.map +1 -0
  67. package/{jsonEditor → lib/packlets/editor}/rules/index.d.ts +1 -0
  68. package/lib/packlets/editor/rules/index.d.ts.map +1 -0
  69. package/lib/packlets/editor/rules/index.js +42 -0
  70. package/lib/packlets/editor/rules/index.js.map +1 -0
  71. package/lib/packlets/editor/rules/multivalue.d.ts +94 -0
  72. package/lib/packlets/editor/rules/multivalue.d.ts.map +1 -0
  73. package/lib/packlets/editor/rules/multivalue.js +141 -0
  74. package/lib/packlets/editor/rules/multivalue.js.map +1 -0
  75. package/lib/packlets/editor/rules/references.d.ts +69 -0
  76. package/lib/packlets/editor/rules/references.d.ts.map +1 -0
  77. package/lib/packlets/editor/rules/references.js +160 -0
  78. package/lib/packlets/editor/rules/references.js.map +1 -0
  79. package/lib/packlets/editor/rules/templates.d.ts +74 -0
  80. package/lib/packlets/editor/rules/templates.d.ts.map +1 -0
  81. package/lib/packlets/editor/rules/templates.js +127 -0
  82. package/lib/packlets/editor/rules/templates.js.map +1 -0
  83. package/lib/packlets/json/common.d.ts +85 -0
  84. package/lib/packlets/json/common.d.ts.map +1 -0
  85. package/lib/packlets/json/common.js +123 -0
  86. package/lib/packlets/json/common.js.map +1 -0
  87. package/lib/packlets/json/index.d.ts +2 -0
  88. package/lib/packlets/json/index.d.ts.map +1 -0
  89. package/lib/packlets/json/index.js +39 -0
  90. package/lib/packlets/json/index.js.map +1 -0
  91. package/package.json +57 -49
  92. package/common.d.ts +0 -58
  93. package/common.js +0 -116
  94. package/contextHelpers.d.ts +0 -21
  95. package/contextHelpers.js +0 -101
  96. package/converters.d.ts +0 -37
  97. package/converters.js +0 -92
  98. package/file.d.ts +0 -60
  99. package/file.js +0 -140
  100. package/index.d.ts +0 -9
  101. package/index.js +0 -61
  102. package/jsonContext.d.ts +0 -74
  103. package/jsonContext.js +0 -40
  104. package/jsonConverter.d.ts +0 -229
  105. package/jsonConverter.js +0 -292
  106. package/jsonEditor/common.d.ts +0 -36
  107. package/jsonEditor/common.js +0 -3
  108. package/jsonEditor/index.d.ts +0 -5
  109. package/jsonEditor/jsonEditor.d.ts +0 -74
  110. package/jsonEditor/jsonEditor.js +0 -259
  111. package/jsonEditor/jsonEditorRule.d.ts +0 -47
  112. package/jsonEditor/jsonEditorRule.js +0 -44
  113. package/jsonEditor/jsonEditorState.d.ts +0 -24
  114. package/jsonEditor/jsonEditorState.js +0 -86
  115. package/jsonEditor/rules/conditional.d.ts +0 -84
  116. package/jsonEditor/rules/conditional.js +0 -146
  117. package/jsonEditor/rules/index.js +0 -21
  118. package/jsonEditor/rules/multivalue.d.ts +0 -78
  119. package/jsonEditor/rules/multivalue.js +0 -129
  120. package/jsonEditor/rules/references.d.ts +0 -62
  121. package/jsonEditor/rules/references.js +0 -158
  122. package/jsonEditor/rules/templates.d.ts +0 -56
  123. package/jsonEditor/rules/templates.js +0 -115
  124. package/jsonReferenceMap.d.ts +0 -182
  125. package/jsonReferenceMap.js +0 -272
@@ -0,0 +1,333 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2020 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.JsonEditor = void 0;
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ const rules_1 = require("./rules");
27
+ const json_1 = require("../json");
28
+ const jsonEditorState_1 = require("./jsonEditorState");
29
+ /**
30
+ * A {@link JsonEditor | JsonEditor} can be used to edit JSON objects in place or to
31
+ * clone any JSON value, applying a default context and optional set of editor rules that
32
+ * were supplied at initialization.
33
+ * @public
34
+ */
35
+ class JsonEditor {
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
40
+ * constructed editor.
41
+ * @param rules - Any {@link Editor.IJsonEditorRule | editor rules} to be applied by the editor.
42
+ * @internal
43
+ */
44
+ constructor(options, rules) {
45
+ this.options = JsonEditor._getDefaultOptions(options).orThrow();
46
+ this._rules = rules || JsonEditor.getDefaultRules(this.options).orThrow();
47
+ }
48
+ /**
49
+ * Default singleton {@link Editor.JsonEditor | JsonEditor} for simple use. Applies all rules
50
+ * but with no default context.
51
+ */
52
+ static get default() {
53
+ if (!JsonEditor._default) {
54
+ const rules = this.getDefaultRules().orDefault();
55
+ JsonEditor._default = new JsonEditor(undefined, rules);
56
+ }
57
+ return JsonEditor._default;
58
+ }
59
+ /**
60
+ * Constructs a new {@link Editor.JsonEditor | JsonEditor}.
61
+ * @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for the
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}.
65
+ */
66
+ static create(options, rules) {
67
+ return (0, ts_utils_1.captureResult)(() => new JsonEditor(options, rules));
68
+ }
69
+ /**
70
+ * Gets the default set of rules to be applied for a given set of options.
71
+ * By default, all available rules (templates, conditionals, multi-value and references)
72
+ * are applied.
73
+ * @param options - Optional partial {@link Editor.IJsonEditorOptions | editor options} for
74
+ * all rules.
75
+ * @returns Default {@link Editor.IJsonEditorRule | editor rules} with any supplied options
76
+ * applied.
77
+ */
78
+ static getDefaultRules(options) {
79
+ return (0, ts_utils_1.mapResults)([
80
+ rules_1.TemplatedJsonEditorRule.create(options),
81
+ rules_1.ConditionalJsonEditorRule.create(options),
82
+ rules_1.MultiValueJsonEditorRule.create(options),
83
+ rules_1.ReferenceJsonEditorRule.create(options)
84
+ ]);
85
+ }
86
+ /**
87
+ * @internal
88
+ */
89
+ static _getDefaultOptions(options) {
90
+ const context = options === null || options === void 0 ? void 0 : options.context;
91
+ let validation = options === null || options === void 0 ? void 0 : options.validation;
92
+ if (validation === undefined) {
93
+ validation = {
94
+ onInvalidPropertyName: 'error',
95
+ onInvalidPropertyValue: 'error',
96
+ onUndefinedPropertyValue: 'ignore'
97
+ };
98
+ }
99
+ return (0, ts_utils_1.succeed)({ context, validation });
100
+ }
101
+ /**
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
105
+ * @param runtimeContext - An optional {@link IJsonContext | IJsonContext} supplying variables
106
+ * and references.
107
+ * @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
108
+ * Returns `Failure` with details if an error occurs.
109
+ */
110
+ mergeObjectInPlace(target, src, runtimeContext) {
111
+ const state = new jsonEditorState_1.JsonEditorState(this, this.options, runtimeContext);
112
+ return this._mergeObjectInPlace(target, src, state).onSuccess((merged) => {
113
+ return this._finalizeAndMerge(merged, state);
114
+ });
115
+ }
116
+ /**
117
+ * Merges multiple supplied source objects into a supplied target, updating the target
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
121
+ * supplied.
122
+ * @returns `Success` with the original source {@link JsonObject | object} if merge was successful.
123
+ * Returns `Failure` with details if an error occurs.
124
+ */
125
+ mergeObjectsInPlace(target, srcObjects) {
126
+ return this.mergeObjectsInPlaceWithContext(this.options.context, target, srcObjects);
127
+ }
128
+ /**
129
+ * Merges multiple supplied source objects into a supplied target, updating the target
130
+ * object and using an optional {@link IJsonContext | context} supplied in the call.
131
+ * @param context - An optional {@link IJsonContext | IJsonContext} supplying variables and
132
+ * references.
133
+ * @param base - The base {@link JsonObject | object} to be updated
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.
136
+ * Returns `Failure` with details if an error occurs.
137
+ */
138
+ mergeObjectsInPlaceWithContext(context, base, srcObjects) {
139
+ for (const src of srcObjects) {
140
+ const mergeResult = this.mergeObjectInPlace(base, src, context);
141
+ if (mergeResult.isFailure()) {
142
+ return mergeResult.withFailureDetail('error');
143
+ }
144
+ }
145
+ return (0, ts_utils_1.succeedWithDetail)(base);
146
+ }
147
+ /**
148
+ * Deep clones a supplied {@link JsonValue | JSON value}, applying all editor rules and a default
149
+ * or optionally supplied context
150
+ * @param src - The {@link JsonValue | JsonValue} to be cloned.
151
+ * @param context - An optional {@link IJsonContext | JSON context} supplying variables and references.
152
+ */
153
+ clone(src, context) {
154
+ const state = new jsonEditorState_1.JsonEditorState(this, this.options, context);
155
+ let value = src;
156
+ let valueResult = this._editValue(src, state);
157
+ while (valueResult.isSuccess()) {
158
+ value = valueResult.value;
159
+ valueResult = this._editValue(value, state);
160
+ }
161
+ if (valueResult.detail === 'error' || valueResult.detail === 'ignore') {
162
+ return valueResult;
163
+ }
164
+ if ((0, json_1.isJsonPrimitive)(value) || value === null) {
165
+ return (0, ts_utils_1.succeedWithDetail)(value, 'edited');
166
+ }
167
+ else if ((0, json_1.isJsonObject)(value)) {
168
+ return this.mergeObjectInPlace({}, value, state.context).withFailureDetail('error');
169
+ }
170
+ else if ((0, json_1.isJsonArray)(value)) {
171
+ return this._cloneArray(value, state.context);
172
+ }
173
+ else if (value === undefined) {
174
+ return state.failValidation('undefinedPropertyValue');
175
+ }
176
+ return state.failValidation('invalidPropertyValue', `Cannot convert invalid JSON: "${JSON.stringify(value)}"`);
177
+ }
178
+ /**
179
+ *
180
+ * @param target -
181
+ * @param src -
182
+ * @param state -
183
+ * @returns
184
+ * @internal
185
+ */
186
+ _mergeObjectInPlace(target, src, state) {
187
+ for (const key in src) {
188
+ if (src.hasOwnProperty(key)) {
189
+ const propResult = this._editProperty(key, src[key], state);
190
+ if (propResult.isSuccess()) {
191
+ if (propResult.detail === 'deferred') {
192
+ state.defer(propResult.value);
193
+ }
194
+ else {
195
+ const mergeResult = this._mergeObjectInPlace(target, propResult.value, state);
196
+ if (mergeResult.isFailure()) {
197
+ return mergeResult;
198
+ }
199
+ }
200
+ }
201
+ else if (propResult.detail === 'inapplicable') {
202
+ const valueResult = this.clone(src[key], state.context).onSuccess((cloned) => {
203
+ return this._mergeClonedProperty(target, key, cloned, state);
204
+ });
205
+ if (valueResult.isFailure() && valueResult.detail === 'error') {
206
+ return (0, ts_utils_1.fail)(`${key}: ${valueResult.message}`);
207
+ }
208
+ }
209
+ else if (propResult.detail !== 'ignore') {
210
+ return (0, ts_utils_1.fail)(`${key}: ${propResult.message}`);
211
+ }
212
+ }
213
+ else {
214
+ return (0, ts_utils_1.fail)(`${key}: Cannot merge inherited properties`);
215
+ }
216
+ }
217
+ return (0, ts_utils_1.succeed)(target);
218
+ }
219
+ /**
220
+ *
221
+ * @param src -
222
+ * @param context -
223
+ * @returns
224
+ * @internal
225
+ */
226
+ _cloneArray(src, context) {
227
+ const results = src.map((v) => {
228
+ return this.clone(v, context);
229
+ });
230
+ return (0, ts_utils_1.mapDetailedResults)(results, ['ignore'])
231
+ .onSuccess((converted) => {
232
+ return (0, ts_utils_1.succeed)(converted);
233
+ })
234
+ .withFailureDetail('error');
235
+ }
236
+ /**
237
+ *
238
+ * @param target -
239
+ * @param key -
240
+ * @param newValue -
241
+ * @param state -
242
+ * @returns
243
+ * @internal
244
+ */
245
+ _mergeClonedProperty(target, key, newValue, state) {
246
+ const existing = target[key];
247
+ // merge is called right after clone so this should never happen
248
+ // since clone itself will have failed
249
+ // istanbul ignore else
250
+ if ((0, json_1.isJsonPrimitive)(newValue)) {
251
+ target[key] = newValue;
252
+ return (0, ts_utils_1.succeedWithDetail)(newValue, 'edited');
253
+ }
254
+ else if ((0, json_1.isJsonObject)(newValue)) {
255
+ if ((0, json_1.isJsonObject)(existing)) {
256
+ return this.mergeObjectInPlace(existing, newValue, state.context).withFailureDetail('error');
257
+ }
258
+ target[key] = newValue;
259
+ return (0, ts_utils_1.succeedWithDetail)(newValue, 'edited');
260
+ }
261
+ else if ((0, json_1.isJsonArray)(newValue)) {
262
+ if ((0, json_1.isJsonArray)(existing)) {
263
+ target[key] = existing.concat(...newValue);
264
+ return (0, ts_utils_1.succeedWithDetail)(target[key], 'edited');
265
+ }
266
+ target[key] = newValue;
267
+ return (0, ts_utils_1.succeedWithDetail)(newValue, 'edited');
268
+ }
269
+ else {
270
+ return (0, ts_utils_1.failWithDetail)(`Invalid JSON: ${JSON.stringify(newValue)}`, 'error');
271
+ }
272
+ }
273
+ /**
274
+ *
275
+ * @param key -
276
+ * @param value -
277
+ * @param state -
278
+ * @returns
279
+ * @internal
280
+ */
281
+ _editProperty(key, value, state) {
282
+ for (const rule of this._rules) {
283
+ const ruleResult = rule.editProperty(key, value, state);
284
+ if (ruleResult.isSuccess() || ruleResult.detail !== 'inapplicable') {
285
+ return ruleResult;
286
+ }
287
+ }
288
+ return (0, ts_utils_1.failWithDetail)('inapplicable', 'inapplicable');
289
+ }
290
+ /**
291
+ *
292
+ * @param value -
293
+ * @param state -
294
+ * @returns
295
+ * @internal
296
+ */
297
+ _editValue(value, state) {
298
+ for (const rule of this._rules) {
299
+ const ruleResult = rule.editValue(value, state);
300
+ if (ruleResult.isSuccess() || ruleResult.detail !== 'inapplicable') {
301
+ return ruleResult;
302
+ }
303
+ }
304
+ return (0, ts_utils_1.failWithDetail)('inapplicable', 'inapplicable');
305
+ }
306
+ /**
307
+ *
308
+ * @param target -
309
+ * @param state -
310
+ * @returns
311
+ * @internal
312
+ */
313
+ _finalizeAndMerge(target, state) {
314
+ const deferred = state.deferred;
315
+ if (deferred.length > 0) {
316
+ for (const rule of this._rules) {
317
+ const ruleResult = rule.finalizeProperties(deferred, state);
318
+ if (ruleResult.isSuccess()) {
319
+ return this.mergeObjectsInPlaceWithContext(state.context, target, ruleResult.value).withFailureDetail('error');
320
+ }
321
+ else if (ruleResult.detail === 'ignore') {
322
+ (0, ts_utils_1.succeedWithDetail)(target, 'edited');
323
+ }
324
+ else if (ruleResult.detail !== 'inapplicable') {
325
+ return (0, ts_utils_1.failWithDetail)(ruleResult.message, ruleResult.detail);
326
+ }
327
+ }
328
+ }
329
+ return (0, ts_utils_1.succeedWithDetail)(target, 'edited');
330
+ }
331
+ }
332
+ exports.JsonEditor = JsonEditor;
333
+ //# sourceMappingURL=jsonEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonEditor.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAUuB;AACvB,mCAKiB;AAGjB,kCAAuG;AAUvG,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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,CAAC,EAAE;YACvB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;gBAC5D,IAAI,UAAU,CAAC,SAAS,EAAE,EAAE;oBAC1B,OAAO,IAAI,CAAC,8BAA8B,CACxC,KAAK,CAAC,OAAO,EACb,MAAM,EACN,UAAU,CAAC,KAAK,CACjB,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;iBAC9B;qBAAM,IAAI,UAAU,CAAC,MAAM,KAAK,QAAQ,EAAE;oBACzC,IAAA,4BAAiB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;iBACrC;qBAAM,IAAI,UAAU,CAAC,MAAM,KAAK,cAAc,EAAE;oBAC/C,OAAO,IAAA,yBAAc,EAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;iBAC9D;aACF;SACF;QACD,OAAO,IAAA,4BAAiB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;CACF;AAtWD,gCAsWC","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 { IJsonContext } from '../context';\nimport { JsonArray, JsonObject, JsonValue, isJsonArray, isJsonObject, isJsonPrimitive } from '../json';\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 // istanbul ignore else\n if (isJsonPrimitive(newValue)) {\n target[key] = newValue;\n return succeedWithDetail(newValue, 'edited');\n } else 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 } else 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 } else {\n return failWithDetail(`Invalid JSON: ${JSON.stringify(newValue)}`, 'error');\n }\n }\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"]}
@@ -0,0 +1,64 @@
1
+ import { DetailedResult } from '@fgv/ts-utils';
2
+ import { JsonObject, JsonValue } from '../json';
3
+ import { JsonEditFailureReason, JsonPropertyEditFailureReason } from './common';
4
+ import { JsonEditorState } from './jsonEditorState';
5
+ /**
6
+ * An {@link Editor.IJsonEditorRule | IJsonEditorRule} represents a single configurable
7
+ * rule to be applied by a {@link Editor.JsonEditor | JsonEditor}.
8
+ * @public
9
+ */
10
+ export interface IJsonEditorRule {
11
+ /**
12
+ * Called by a {@link Editor.JsonEditor | JsonEditor} to possibly edit one of the properties being
13
+ * merged into a target object.
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
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
20
+ * the rule does not affect this property, returns `Failure` with detail `'inapplicable'`. If an error occurred
21
+ * while processing the error, returns `Failure` with detail `'error'`.
22
+ */
23
+ editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
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
29
+ * the value was edited. Returns `Failure` with `'inapplicable'` if the rule does not affect this value.
30
+ * Fails with detail `'ignore'` if the value is to be ignored, or with `'error'` if an error occurs.
31
+ */
32
+ editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
33
+ /**
34
+ * Called for each rule after all properties have been merged. Any properties that were deferred
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.
38
+ * @returns On `Success` return, any returned objects are merged in order and finalization
39
+ * is stopped. Finalization is also stopped on `Failure` with detail `'ignore'`. On `Failure`
40
+ * with detail `'inapplicable'`, finalization continues with the next rule. Fails with an
41
+ * error detail `'error'` and an informative message if an error occurs.
42
+ */
43
+ finalizeProperties(deferred: JsonObject[], state: JsonEditorState): DetailedResult<JsonObject[], JsonEditFailureReason>;
44
+ }
45
+ /**
46
+ * Default base implementation of {@link Editor.IJsonEditorRule | IJsonEditorRule} returns inapplicable for all operations so that
47
+ * derived classes need only implement the operations they actually support.
48
+ * @public
49
+ */
50
+ export declare class JsonEditorRuleBase implements IJsonEditorRule {
51
+ /**
52
+ * {@inheritdoc Editor.IJsonEditorRule.editProperty}
53
+ */
54
+ editProperty(__key: string, __value: JsonValue, __state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
55
+ /**
56
+ * {@inheritdoc Editor.IJsonEditorRule.editValue}
57
+ */
58
+ editValue(__value: JsonValue, __state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
59
+ /**
60
+ * {@inheritdoc Editor.IJsonEditorRule.finalizeProperties}
61
+ */
62
+ finalizeProperties(__deferred: JsonObject[], __state: JsonEditorState): DetailedResult<JsonObject[], JsonEditFailureReason>;
63
+ }
64
+ //# sourceMappingURL=jsonEditorRule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonEditorRule.d.ts","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorRule.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,cAAc,EAAkB,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;;;OAWG;IACH,YAAY,CACV,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,eAAe,GACrB,cAAc,CAAC,UAAU,EAAE,6BAA6B,CAAC,CAAC;IAE7D;;;;;;;OAOG;IACH,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;IAEtG;;;;;;;;;OASG;IACH,kBAAkB,CAChB,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,EAAE,eAAe,GACrB,cAAc,CAAC,UAAU,EAAE,EAAE,qBAAqB,CAAC,CAAC;CACxD;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,eAAe;IACxD;;OAEG;IAEI,YAAY,CACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,eAAe,GACvB,cAAc,CAAC,UAAU,EAAE,6BAA6B,CAAC;IAK5D;;OAEG;IACI,SAAS,CACd,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,eAAe,GACvB,cAAc,CAAC,SAAS,EAAE,qBAAqB,CAAC;IAInD;;OAEG;IACI,kBAAkB,CACvB,UAAU,EAAE,UAAU,EAAE,EACxB,OAAO,EAAE,eAAe,GACvB,cAAc,CAAC,UAAU,EAAE,EAAE,qBAAqB,CAAC;CAGvD"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2020 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.JsonEditorRuleBase = void 0;
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ /**
27
+ * Default base implementation of {@link Editor.IJsonEditorRule | IJsonEditorRule} returns inapplicable for all operations so that
28
+ * derived classes need only implement the operations they actually support.
29
+ * @public
30
+ */
31
+ class JsonEditorRuleBase {
32
+ /**
33
+ * {@inheritdoc Editor.IJsonEditorRule.editProperty}
34
+ */
35
+ // istanbul ignore next
36
+ editProperty(__key, __value, __state) {
37
+ // istanbul ignore next
38
+ return (0, ts_utils_1.failWithDetail)('inapplicable', 'inapplicable');
39
+ }
40
+ /**
41
+ * {@inheritdoc Editor.IJsonEditorRule.editValue}
42
+ */
43
+ editValue(__value, __state) {
44
+ return (0, ts_utils_1.failWithDetail)('inapplicable', 'inapplicable');
45
+ }
46
+ /**
47
+ * {@inheritdoc Editor.IJsonEditorRule.finalizeProperties}
48
+ */
49
+ finalizeProperties(__deferred, __state) {
50
+ return (0, ts_utils_1.failWithDetail)('inapplicable', 'inapplicable');
51
+ }
52
+ }
53
+ exports.JsonEditorRuleBase = JsonEditorRuleBase;
54
+ //# sourceMappingURL=jsonEditorRule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonEditorRule.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorRule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAA+D;AAwD/D;;;;GAIG;AACH,MAAa,kBAAkB;IAC7B;;OAEG;IACH,uBAAuB;IAChB,YAAY,CACjB,KAAa,EACb,OAAkB,EAClB,OAAwB;QAExB,uBAAuB;QACvB,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IAED;;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 { DetailedResult, failWithDetail } from '@fgv/ts-utils';\nimport { JsonObject, JsonValue } from '../json';\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 // istanbul ignore next\n public editProperty(\n __key: string,\n __value: JsonValue,\n __state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason> {\n // istanbul ignore next\n return failWithDetail('inapplicable', 'inapplicable');\n }\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"]}
@@ -0,0 +1,125 @@
1
+ import { DetailedFailure, Result } from '@fgv/ts-utils';
2
+ import { IJsonContext, IJsonReferenceMap, TemplateVars, VariableValue } from '../context';
3
+ import { JsonObject } from '../json';
4
+ import { IJsonCloneEditor, IJsonEditorOptions, IJsonEditorValidationOptions, JsonEditFailureReason, JsonEditorValidationRules } from './common';
5
+ /**
6
+ * Represents the internal state of a {@link Editor.JsonEditor | JsonEditor}.
7
+ * @public
8
+ */
9
+ export declare class JsonEditorState {
10
+ /**
11
+ * Static global counter used to assign each {@link Editor.JsonEditorState | JsonEditorState}
12
+ * a unique identifier.
13
+ * @internal
14
+ */
15
+ protected static _nextId: number;
16
+ /**
17
+ * The {@link Editor.IJsonCloneEditor | editor} for which this state applies.
18
+ */
19
+ readonly editor: IJsonCloneEditor;
20
+ /**
21
+ * Fully resolved {@link Editor.IJsonEditorOptions | editor options} that apply
22
+ * to the operation for which this state applies.
23
+ */
24
+ readonly options: IJsonEditorOptions;
25
+ /**
26
+ * Any deferred {@link JsonObject | objects} to be merged during finalization.
27
+ * @internal
28
+ */
29
+ protected readonly _deferred: JsonObject[];
30
+ /**
31
+ * Unique global identifier for this {@link Editor.JsonEditorState | state object}.
32
+ * @internal
33
+ */
34
+ protected readonly _id: number;
35
+ /**
36
+ * Constructs a new {@link Editor.JsonEditorState | JsonEditorState}.
37
+ * @param editor - The {@link Editor.IJsonCloneEditor | editor} to which this state
38
+ * applies.
39
+ * @param baseOptions - The {@link Editor.IJsonEditorOptions | editor options} that
40
+ * apply to this rule.
41
+ * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used
42
+ * for json value conversion.
43
+ */
44
+ constructor(editor: IJsonCloneEditor, baseOptions: IJsonEditorOptions, runtimeContext?: IJsonContext);
45
+ /**
46
+ * The optional {@link IJsonContext | JSON context} for this state.
47
+ */
48
+ get context(): IJsonContext | undefined;
49
+ /**
50
+ * An array of {@link JsonObject | objects} that are deferred for merge during
51
+ * finalization.
52
+ */
53
+ get deferred(): JsonObject[];
54
+ /**
55
+ * Merges an optional {@link IJsonContext | JSON context} into a supplied set
56
+ * of {@link Editor.IJsonEditorOptions | JSON editor options}.
57
+ * @param options - The {@link Editor.IJsonEditorOptions | IJsonEditorOptions} into
58
+ * which the the new context is to be merged.
59
+ * @param context - The {@link IJsonContext | JSON context} to be merged into the
60
+ * editor options.
61
+ * @returns `Success` with the supplied {@link Editor.IJsonEditorOptions | options} if
62
+ * there was nothing to merge, or aa new {@link Editor.IJsonEditorOptions | IJsonEditorOptions}
63
+ * constructed from the base options merged with the supplied context. Returns `Failure`
64
+ * with more information if an error occurs.
65
+ * @internal
66
+ */
67
+ protected static _getEffectiveOptions(options: IJsonEditorOptions, context?: IJsonContext): Result<IJsonEditorOptions>;
68
+ /**
69
+ * Adds a supplied {@link JsonObject | object} to the deferred list.
70
+ * @param obj - The {@link JsonObject | object} to be deferred.
71
+ */
72
+ defer(obj: JsonObject): void;
73
+ /**
74
+ * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link Editor.JsonEditorState | JsonEditorState},
75
+ * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default
76
+ * context.
77
+ * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`
78
+ * if the current state does not have context.
79
+ * @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or
80
+ * `undefined` if no vars are found.
81
+ */
82
+ getVars(defaultContext?: IJsonContext): TemplateVars | undefined;
83
+ /**
84
+ * Gets an {@link IJsonReferenceMap | reference map} containing any other values
85
+ * referenced during the operation.
86
+ * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as
87
+ * {@link TemplateVars | TemplateVars} if the current state does not have context.
88
+ * @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced
89
+ * during this operation.
90
+ */
91
+ getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined;
92
+ /**
93
+ * Gets the context of this {@link Editor.JsonEditorState | JsonEditorState} or an optionally
94
+ * supplied default context if this state has no context.
95
+ * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default
96
+ * if this state has no context.
97
+ * @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context
98
+ * is available.
99
+ */
100
+ getContext(defaultContext?: IJsonContext): IJsonContext | undefined;
101
+ /**
102
+ * Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables
103
+ * and references into a supplied existing context.
104
+ * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables
105
+ * and references are to be merged, or `undefined` to start with a default empty context.
106
+ * @param add - The {@link VariableValue | variable values} and/or
107
+ * {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.
108
+ * @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.
109
+ */
110
+ extendContext(baseContext: IJsonContext | undefined, add: {
111
+ vars?: VariableValue[];
112
+ refs?: IJsonReferenceMap[];
113
+ }): Result<IJsonContext | undefined>;
114
+ /**
115
+ * Helper method to constructs `DetailedFailure` with appropriate details and messaging
116
+ * for various validation failures.
117
+ * @param rule - The {@link Editor.JsonEditorValidationRules | validation rule} that failed.
118
+ * @param message - A string message describing the failed validation.
119
+ * @param validation - The {@link Editor.IJsonEditorValidationOptions | validation options}
120
+ * in effect.
121
+ * @returns A `DetailedFailure` with appropriate detail and message.
122
+ */
123
+ failValidation<T = JsonObject>(rule: JsonEditorValidationRules, message?: string, validation?: IJsonEditorValidationOptions): DetailedFailure<T, JsonEditFailureReason>;
124
+ }
125
+ //# sourceMappingURL=jsonEditorState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonEditorState.d.ts","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorState.ts"],"names":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