@fgv/ts-json 3.0.1-alpha.6 → 4.0.1

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 +27 -0
  2. package/CHANGELOG.md +16 -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 +14 -14
@@ -3,40 +3,40 @@ import { DetailedFailure, Result } from '@fgv/ts-utils';
3
3
  import { IJsonContext, IJsonReferenceMap, TemplateVars, VariableValue } from '../context';
4
4
  import { IJsonCloneEditor, IJsonEditorOptions, IJsonEditorValidationOptions, JsonEditFailureReason, JsonEditorValidationRules } from './common';
5
5
  /**
6
- * Represents the internal state of a {@link Editor.JsonEditor | JsonEditor}.
6
+ * Represents the internal state of a {@link JsonEditor | JsonEditor}.
7
7
  * @public
8
8
  */
9
9
  export declare class JsonEditorState {
10
10
  /**
11
- * Static global counter used to assign each {@link Editor.JsonEditorState | JsonEditorState}
11
+ * Static global counter used to assign each {@link JsonEditorState | JsonEditorState}
12
12
  * a unique identifier.
13
13
  * @internal
14
14
  */
15
15
  protected static _nextId: number;
16
16
  /**
17
- * The {@link Editor.IJsonCloneEditor | editor} for which this state applies.
17
+ * The {@link IJsonCloneEditor | editor} for which this state applies.
18
18
  */
19
19
  readonly editor: IJsonCloneEditor;
20
20
  /**
21
- * Fully resolved {@link Editor.IJsonEditorOptions | editor options} that apply
21
+ * Fully resolved {@link IJsonEditorOptions | editor options} that apply
22
22
  * to the operation for which this state applies.
23
23
  */
24
24
  readonly options: IJsonEditorOptions;
25
25
  /**
26
- * Any deferred {@link JsonObject | objects} to be merged during finalization.
26
+ * Any deferred JSON objects to be merged during finalization.
27
27
  * @internal
28
28
  */
29
29
  protected readonly _deferred: JsonObject[];
30
30
  /**
31
- * Unique global identifier for this {@link Editor.JsonEditorState | state object}.
31
+ * Unique global identifier for this {@link JsonEditorState | state object}.
32
32
  * @internal
33
33
  */
34
34
  protected readonly _id: number;
35
35
  /**
36
- * Constructs a new {@link Editor.JsonEditorState | JsonEditorState}.
37
- * @param editor - The {@link Editor.IJsonCloneEditor | editor} to which this state
36
+ * Constructs a new {@link JsonEditorState | JsonEditorState}.
37
+ * @param editor - The {@link IJsonCloneEditor | editor} to which this state
38
38
  * applies.
39
- * @param baseOptions - The {@link Editor.IJsonEditorOptions | editor options} that
39
+ * @param baseOptions - The {@link IJsonEditorOptions | editor options} that
40
40
  * apply to this rule.
41
41
  * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used
42
42
  * for json value conversion.
@@ -47,31 +47,31 @@ export declare class JsonEditorState {
47
47
  */
48
48
  get context(): IJsonContext | undefined;
49
49
  /**
50
- * An array of {@link JsonObject | objects} that are deferred for merge during
50
+ * An array of JSON objects that were deferred for merge during
51
51
  * finalization.
52
52
  */
53
53
  get deferred(): JsonObject[];
54
54
  /**
55
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
56
+ * of {@link IJsonEditorOptions | JSON editor options}.
57
+ * @param options - The {@link IJsonEditorOptions | IJsonEditorOptions} into
58
58
  * which the the new context is to be merged.
59
59
  * @param context - The {@link IJsonContext | JSON context} to be merged into the
60
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}
61
+ * @returns `Success` with the supplied {@link IJsonEditorOptions | options} if
62
+ * there was nothing to merge, or aa new {@link IJsonEditorOptions | IJsonEditorOptions}
63
63
  * constructed from the base options merged with the supplied context. Returns `Failure`
64
64
  * with more information if an error occurs.
65
65
  * @internal
66
66
  */
67
67
  protected static _getEffectiveOptions(options: IJsonEditorOptions, context?: IJsonContext): Result<IJsonEditorOptions>;
68
68
  /**
69
- * Adds a supplied {@link JsonObject | object} to the deferred list.
70
- * @param obj - The {@link JsonObject | object} to be deferred.
69
+ * Adds a supplied `JsonObject` to the deferred list.
70
+ * @param obj - The `JsonObject` to be deferred.
71
71
  */
72
72
  defer(obj: JsonObject): void;
73
73
  /**
74
- * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link Editor.JsonEditorState | JsonEditorState},
74
+ * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link JsonEditorState | JsonEditorState},
75
75
  * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default
76
76
  * context.
77
77
  * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`
@@ -90,7 +90,7 @@ export declare class JsonEditorState {
90
90
  */
91
91
  getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined;
92
92
  /**
93
- * Gets the context of this {@link Editor.JsonEditorState | JsonEditorState} or an optionally
93
+ * Gets the context of this {@link JsonEditorState | JsonEditorState} or an optionally
94
94
  * supplied default context if this state has no context.
95
95
  * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default
96
96
  * if this state has no context.
@@ -114,9 +114,9 @@ export declare class JsonEditorState {
114
114
  /**
115
115
  * Helper method to constructs `DetailedFailure` with appropriate details and messaging
116
116
  * for various validation failures.
117
- * @param rule - The {@link Editor.JsonEditorValidationRules | validation rule} that failed.
117
+ * @param rule - The {@link JsonEditorValidationRules | validation rule} that failed.
118
118
  * @param message - A string message describing the failed validation.
119
- * @param validation - The {@link Editor.IJsonEditorValidationOptions | validation options}
119
+ * @param validation - The {@link IJsonEditorValidationOptions | validation options}
120
120
  * in effect.
121
121
  * @returns A `DetailedFailure` with appropriate detail and message.
122
122
  */
@@ -25,22 +25,22 @@ exports.JsonEditorState = void 0;
25
25
  const ts_utils_1 = require("@fgv/ts-utils");
26
26
  const context_1 = require("../context");
27
27
  /**
28
- * Represents the internal state of a {@link Editor.JsonEditor | JsonEditor}.
28
+ * Represents the internal state of a {@link JsonEditor | JsonEditor}.
29
29
  * @public
30
30
  */
31
31
  class JsonEditorState {
32
32
  /**
33
- * Constructs a new {@link Editor.JsonEditorState | JsonEditorState}.
34
- * @param editor - The {@link Editor.IJsonCloneEditor | editor} to which this state
33
+ * Constructs a new {@link JsonEditorState | JsonEditorState}.
34
+ * @param editor - The {@link IJsonCloneEditor | editor} to which this state
35
35
  * applies.
36
- * @param baseOptions - The {@link Editor.IJsonEditorOptions | editor options} that
36
+ * @param baseOptions - The {@link IJsonEditorOptions | editor options} that
37
37
  * apply to this rule.
38
38
  * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used
39
39
  * for json value conversion.
40
40
  */
41
41
  constructor(editor, baseOptions, runtimeContext) {
42
42
  /**
43
- * Any deferred {@link JsonObject | objects} to be merged during finalization.
43
+ * Any deferred JSON objects to be merged during finalization.
44
44
  * @internal
45
45
  */
46
46
  this._deferred = [];
@@ -55,7 +55,7 @@ class JsonEditorState {
55
55
  return this.options.context;
56
56
  }
57
57
  /**
58
- * An array of {@link JsonObject | objects} that are deferred for merge during
58
+ * An array of JSON objects that were deferred for merge during
59
59
  * finalization.
60
60
  */
61
61
  get deferred() {
@@ -63,13 +63,13 @@ class JsonEditorState {
63
63
  }
64
64
  /**
65
65
  * Merges an optional {@link IJsonContext | JSON context} into a supplied set
66
- * of {@link Editor.IJsonEditorOptions | JSON editor options}.
67
- * @param options - The {@link Editor.IJsonEditorOptions | IJsonEditorOptions} into
66
+ * of {@link IJsonEditorOptions | JSON editor options}.
67
+ * @param options - The {@link IJsonEditorOptions | IJsonEditorOptions} into
68
68
  * which the the new context is to be merged.
69
69
  * @param context - The {@link IJsonContext | JSON context} to be merged into the
70
70
  * editor options.
71
- * @returns `Success` with the supplied {@link Editor.IJsonEditorOptions | options} if
72
- * there was nothing to merge, or aa new {@link Editor.IJsonEditorOptions | IJsonEditorOptions}
71
+ * @returns `Success` with the supplied {@link IJsonEditorOptions | options} if
72
+ * there was nothing to merge, or aa new {@link IJsonEditorOptions | IJsonEditorOptions}
73
73
  * constructed from the base options merged with the supplied context. Returns `Failure`
74
74
  * with more information if an error occurs.
75
75
  * @internal
@@ -83,14 +83,14 @@ class JsonEditorState {
83
83
  });
84
84
  }
85
85
  /**
86
- * Adds a supplied {@link JsonObject | object} to the deferred list.
87
- * @param obj - The {@link JsonObject | object} to be deferred.
86
+ * Adds a supplied `JsonObject` to the deferred list.
87
+ * @param obj - The `JsonObject` to be deferred.
88
88
  */
89
89
  defer(obj) {
90
90
  this._deferred.push(obj);
91
91
  }
92
92
  /**
93
- * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link Editor.JsonEditorState | JsonEditorState},
93
+ * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link JsonEditorState | JsonEditorState},
94
94
  * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default
95
95
  * context.
96
96
  * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`
@@ -115,7 +115,7 @@ class JsonEditorState {
115
115
  return (_b = (_a = this.options.context) === null || _a === void 0 ? void 0 : _a.refs) !== null && _b !== void 0 ? _b : defaultContext === null || defaultContext === void 0 ? void 0 : defaultContext.refs;
116
116
  }
117
117
  /**
118
- * Gets the context of this {@link Editor.JsonEditorState | JsonEditorState} or an optionally
118
+ * Gets the context of this {@link JsonEditorState | JsonEditorState} or an optionally
119
119
  * supplied default context if this state has no context.
120
120
  * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default
121
121
  * if this state has no context.
@@ -141,9 +141,9 @@ class JsonEditorState {
141
141
  /**
142
142
  * Helper method to constructs `DetailedFailure` with appropriate details and messaging
143
143
  * for various validation failures.
144
- * @param rule - The {@link Editor.JsonEditorValidationRules | validation rule} that failed.
144
+ * @param rule - The {@link JsonEditorValidationRules | validation rule} that failed.
145
145
  * @param message - A string message describing the failed validation.
146
- * @param validation - The {@link Editor.IJsonEditorValidationOptions | validation options}
146
+ * @param validation - The {@link IJsonEditorValidationOptions | validation options}
147
147
  * in effect.
148
148
  * @returns A `DetailedFailure` with appropriate detail and message.
149
149
  */
@@ -169,7 +169,7 @@ class JsonEditorState {
169
169
  }
170
170
  exports.JsonEditorState = JsonEditorState;
171
171
  /**
172
- * Static global counter used to assign each {@link Editor.JsonEditorState | JsonEditorState}
172
+ * Static global counter used to assign each {@link JsonEditorState | JsonEditorState}
173
173
  * a unique identifier.
174
174
  * @internal
175
175
  */
@@ -1 +1 @@
1
- {"version":3,"file":"jsonEditorState.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorState.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAAiF;AACjF,wCAA6G;AAU7G;;;GAGG;AACH,MAAa,eAAe;IA+B1B;;;;;;;;OAQG;IACH,YACE,MAAwB,EACxB,WAA+B,EAC/B,cAA6B;QAxB/B;;;WAGG;QACgB,cAAS,GAAiB,EAAE,CAAC;QAsB9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,oBAAoB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3F,IAAI,CAAC,GAAG,GAAG,eAAe,CAAC,OAAO,EAAE,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IAC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AAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC7C,OAAO,2BAAiB,CAAC,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;OAQG;IACI,cAAc,CACnB,IAA+B,EAC/B,OAAgB,EAChB,UAAyC;QAEzC,IAAI,MAAM,GAAkC,OAAO,CAAC;QACpD,MAAM,SAAS,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QACxD,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,qBAAqB;gBACxB,MAAM,GAAG,SAAS,CAAC,qBAAqB,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC;gBACjF,MAAM;YACR,KAAK,sBAAsB;gBACzB,MAAM,GAAG,SAAS,CAAC,sBAAsB,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAC5E,MAAM;YACR,KAAK,wBAAwB;gBAC3B,MAAM,GAAG,SAAS,CAAC,wBAAwB,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;gBAC7E,oBAAoB;gBACpB,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,kCAAkC,CAAC;gBACxD,MAAM;QACV,CAAC;QACD,oBAAoB;QACpB,OAAO,IAAA,yBAAc,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;;AAvLH,0CAwLC;AAvLC;;;;GAIG;AACc,uBAAO,GAAW,CAAC,AAAZ,CAAa","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonObject } from '@fgv/ts-json-base';\nimport { DetailedFailure, Result, failWithDetail, succeed } from '@fgv/ts-utils';\nimport { IJsonContext, IJsonReferenceMap, JsonContextHelper, TemplateVars, VariableValue } from '../context';\nimport {\n IJsonCloneEditor,\n IJsonEditorOptions,\n IJsonEditorValidationOptions,\n JsonEditFailureReason,\n JsonEditorValidationRules,\n JsonPropertyEditFailureReason\n} from './common';\n\n/**\n * Represents the internal state of a {@link Editor.JsonEditor | JsonEditor}.\n * @public\n */\nexport class JsonEditorState {\n /**\n * Static global counter used to assign each {@link Editor.JsonEditorState | JsonEditorState}\n * a unique identifier.\n * @internal\n */\n protected static _nextId: number = 0;\n\n /**\n * The {@link Editor.IJsonCloneEditor | editor} for which this state applies.\n */\n public readonly editor: IJsonCloneEditor;\n\n /**\n * Fully resolved {@link Editor.IJsonEditorOptions | editor options} that apply\n * to the operation for which this state applies.\n */\n public readonly options: IJsonEditorOptions;\n\n /**\n * Any deferred {@link JsonObject | objects} to be merged during finalization.\n * @internal\n */\n protected readonly _deferred: JsonObject[] = [];\n\n /**\n * Unique global identifier for this {@link Editor.JsonEditorState | state object}.\n * @internal\n */\n protected readonly _id: number;\n\n /**\n * Constructs a new {@link Editor.JsonEditorState | JsonEditorState}.\n * @param editor - The {@link Editor.IJsonCloneEditor | editor} to which this state\n * applies.\n * @param baseOptions - The {@link Editor.IJsonEditorOptions | editor options} that\n * apply to this rule.\n * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used\n * for json value conversion.\n */\n public constructor(\n editor: IJsonCloneEditor,\n baseOptions: IJsonEditorOptions,\n runtimeContext?: IJsonContext\n ) {\n this.editor = editor;\n this.options = JsonEditorState._getEffectiveOptions(baseOptions, runtimeContext).orThrow();\n this._id = JsonEditorState._nextId++;\n }\n\n /**\n * The optional {@link IJsonContext | JSON context} for this state.\n */\n public get context(): IJsonContext | undefined {\n return this.options.context;\n }\n\n /**\n * An array of {@link JsonObject | objects} that are deferred for merge during\n * finalization.\n */\n public get deferred(): JsonObject[] {\n return this._deferred;\n }\n\n /**\n * Merges an optional {@link IJsonContext | JSON context} into a supplied set\n * of {@link Editor.IJsonEditorOptions | JSON editor options}.\n * @param options - The {@link Editor.IJsonEditorOptions | IJsonEditorOptions} into\n * which the the new context is to be merged.\n * @param context - The {@link IJsonContext | JSON context} to be merged into the\n * editor options.\n * @returns `Success` with the supplied {@link Editor.IJsonEditorOptions | options} if\n * there was nothing to merge, or aa new {@link Editor.IJsonEditorOptions | IJsonEditorOptions}\n * constructed from the base options merged with the supplied context. Returns `Failure`\n * with more information if an error occurs.\n * @internal\n */\n protected static _getEffectiveOptions(\n options: IJsonEditorOptions,\n context?: IJsonContext\n ): Result<IJsonEditorOptions> {\n if (!context) {\n return succeed(options);\n }\n return JsonContextHelper.mergeContext(options.context, context).onSuccess((merged) => {\n return succeed({ context: merged, validation: options.validation });\n });\n }\n\n /**\n * Adds a supplied {@link JsonObject | object} to the deferred list.\n * @param obj - The {@link JsonObject | object} to be deferred.\n */\n public defer(obj: JsonObject): void {\n this._deferred.push(obj);\n }\n\n /**\n * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link Editor.JsonEditorState | JsonEditorState},\n * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default\n * context.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`\n * if the current state does not have context.\n * @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or\n * `undefined` if no vars are found.\n */\n public getVars(defaultContext?: IJsonContext): TemplateVars | undefined {\n return this.options.context?.vars ?? defaultContext?.vars;\n }\n\n /**\n * Gets an {@link IJsonReferenceMap | reference map} containing any other values\n * referenced during the operation.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as\n * {@link TemplateVars | TemplateVars} if the current state does not have context.\n * @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced\n * during this operation.\n */\n public getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined {\n return this.options.context?.refs ?? defaultContext?.refs;\n }\n\n /**\n * Gets the context of this {@link Editor.JsonEditorState | JsonEditorState} or an optionally\n * supplied default context if this state has no context.\n * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default\n * if this state has no context.\n * @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context\n * is available.\n */\n public getContext(defaultContext?: IJsonContext): IJsonContext | undefined {\n return JsonContextHelper.mergeContext(defaultContext, this.options.context).orDefault();\n }\n\n /**\n * Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables\n * and references into a supplied existing context.\n * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables\n * and references are to be merged, or `undefined` to start with a default empty context.\n * @param add - The {@link VariableValue | variable values} and/or\n * {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.\n * @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.\n */\n public extendContext(\n baseContext: IJsonContext | undefined,\n add: { vars?: VariableValue[]; refs?: IJsonReferenceMap[] }\n ): Result<IJsonContext | undefined> {\n const context = this.getContext(baseContext);\n return JsonContextHelper.extendContext(context, add);\n }\n\n /**\n * Helper method to constructs `DetailedFailure` with appropriate details and messaging\n * for various validation failures.\n * @param rule - The {@link Editor.JsonEditorValidationRules | validation rule} that failed.\n * @param message - A string message describing the failed validation.\n * @param validation - The {@link Editor.IJsonEditorValidationOptions | validation options}\n * in effect.\n * @returns A `DetailedFailure` with appropriate detail and message.\n */\n public failValidation<T = JsonObject>(\n rule: JsonEditorValidationRules,\n message?: string,\n validation?: IJsonEditorValidationOptions\n ): DetailedFailure<T, JsonEditFailureReason> {\n let detail: JsonPropertyEditFailureReason = 'error';\n const effective = validation ?? this.options.validation;\n switch (rule) {\n case 'invalidPropertyName':\n detail = effective.onInvalidPropertyName !== 'ignore' ? 'error' : 'inapplicable';\n break;\n case 'invalidPropertyValue':\n detail = effective.onInvalidPropertyValue !== 'ignore' ? 'error' : 'ignore';\n break;\n case 'undefinedPropertyValue':\n detail = effective.onUndefinedPropertyValue !== 'error' ? 'ignore' : 'error';\n /* c8 ignore next */\n message = message ?? 'Cannot convert undefined to JSON';\n break;\n }\n /* c8 ignore next */\n return failWithDetail(message ?? rule, detail);\n }\n}\n"]}
1
+ {"version":3,"file":"jsonEditorState.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorState.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAAiF;AACjF,wCAA6G;AAU7G;;;GAGG;AACH,MAAa,eAAe;IA+B1B;;;;;;;;OAQG;IACH,YACE,MAAwB,EACxB,WAA+B,EAC/B,cAA6B;QAxB/B;;;WAGG;QACgB,cAAS,GAAiB,EAAE,CAAC;QAsB9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,oBAAoB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3F,IAAI,CAAC,GAAG,GAAG,eAAe,CAAC,OAAO,EAAE,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,IAAW,OA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;;;OAQG;IACI,aAAa,CAClB,WAAqC,EACrC,GAA2D;QAE3D,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC7C,OAAO,2BAAiB,CAAC,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;OAQG;IACI,cAAc,CACnB,IAA+B,EAC/B,OAAgB,EAChB,UAAyC;QAEzC,IAAI,MAAM,GAAkC,OAAO,CAAC;QACpD,MAAM,SAAS,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QACxD,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,qBAAqB;gBACxB,MAAM,GAAG,SAAS,CAAC,qBAAqB,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC;gBACjF,MAAM;YACR,KAAK,sBAAsB;gBACzB,MAAM,GAAG,SAAS,CAAC,sBAAsB,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAC5E,MAAM;YACR,KAAK,wBAAwB;gBAC3B,MAAM,GAAG,SAAS,CAAC,wBAAwB,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;gBAC7E,oBAAoB;gBACpB,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,kCAAkC,CAAC;gBACxD,MAAM;QACV,CAAC;QACD,oBAAoB;QACpB,OAAO,IAAA,yBAAc,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;;AAvLH,0CAwLC;AAvLC;;;;GAIG;AACc,uBAAO,GAAW,CAAC,AAAZ,CAAa","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonObject } from '@fgv/ts-json-base';\nimport { DetailedFailure, Result, failWithDetail, succeed } from '@fgv/ts-utils';\nimport { IJsonContext, IJsonReferenceMap, JsonContextHelper, TemplateVars, VariableValue } from '../context';\nimport {\n IJsonCloneEditor,\n IJsonEditorOptions,\n IJsonEditorValidationOptions,\n JsonEditFailureReason,\n JsonEditorValidationRules,\n JsonPropertyEditFailureReason\n} from './common';\n\n/**\n * Represents the internal state of a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport class JsonEditorState {\n /**\n * Static global counter used to assign each {@link JsonEditorState | JsonEditorState}\n * a unique identifier.\n * @internal\n */\n protected static _nextId: number = 0;\n\n /**\n * The {@link IJsonCloneEditor | editor} for which this state applies.\n */\n public readonly editor: IJsonCloneEditor;\n\n /**\n * Fully resolved {@link IJsonEditorOptions | editor options} that apply\n * to the operation for which this state applies.\n */\n public readonly options: IJsonEditorOptions;\n\n /**\n * Any deferred JSON objects to be merged during finalization.\n * @internal\n */\n protected readonly _deferred: JsonObject[] = [];\n\n /**\n * Unique global identifier for this {@link JsonEditorState | state object}.\n * @internal\n */\n protected readonly _id: number;\n\n /**\n * Constructs a new {@link JsonEditorState | JsonEditorState}.\n * @param editor - The {@link IJsonCloneEditor | editor} to which this state\n * applies.\n * @param baseOptions - The {@link IJsonEditorOptions | editor options} that\n * apply to this rule.\n * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used\n * for json value conversion.\n */\n public constructor(\n editor: IJsonCloneEditor,\n baseOptions: IJsonEditorOptions,\n runtimeContext?: IJsonContext\n ) {\n this.editor = editor;\n this.options = JsonEditorState._getEffectiveOptions(baseOptions, runtimeContext).orThrow();\n this._id = JsonEditorState._nextId++;\n }\n\n /**\n * The optional {@link IJsonContext | JSON context} for this state.\n */\n public get context(): IJsonContext | undefined {\n return this.options.context;\n }\n\n /**\n * An array of JSON objects that were deferred for merge during\n * finalization.\n */\n public get deferred(): JsonObject[] {\n return this._deferred;\n }\n\n /**\n * Merges an optional {@link IJsonContext | JSON context} into a supplied set\n * of {@link IJsonEditorOptions | JSON editor options}.\n * @param options - The {@link IJsonEditorOptions | IJsonEditorOptions} into\n * which the the new context is to be merged.\n * @param context - The {@link IJsonContext | JSON context} to be merged into the\n * editor options.\n * @returns `Success` with the supplied {@link IJsonEditorOptions | options} if\n * there was nothing to merge, or aa new {@link IJsonEditorOptions | IJsonEditorOptions}\n * constructed from the base options merged with the supplied context. Returns `Failure`\n * with more information if an error occurs.\n * @internal\n */\n protected static _getEffectiveOptions(\n options: IJsonEditorOptions,\n context?: IJsonContext\n ): Result<IJsonEditorOptions> {\n if (!context) {\n return succeed(options);\n }\n return JsonContextHelper.mergeContext(options.context, context).onSuccess((merged) => {\n return succeed({ context: merged, validation: options.validation });\n });\n }\n\n /**\n * Adds a supplied `JsonObject` to the deferred list.\n * @param obj - The `JsonObject` to be deferred.\n */\n public defer(obj: JsonObject): void {\n this._deferred.push(obj);\n }\n\n /**\n * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link JsonEditorState | JsonEditorState},\n * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default\n * context.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`\n * if the current state does not have context.\n * @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or\n * `undefined` if no vars are found.\n */\n public getVars(defaultContext?: IJsonContext): TemplateVars | undefined {\n return this.options.context?.vars ?? defaultContext?.vars;\n }\n\n /**\n * Gets an {@link IJsonReferenceMap | reference map} containing any other values\n * referenced during the operation.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as\n * {@link TemplateVars | TemplateVars} if the current state does not have context.\n * @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced\n * during this operation.\n */\n public getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined {\n return this.options.context?.refs ?? defaultContext?.refs;\n }\n\n /**\n * Gets the context of this {@link JsonEditorState | JsonEditorState} or an optionally\n * supplied default context if this state has no context.\n * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default\n * if this state has no context.\n * @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context\n * is available.\n */\n public getContext(defaultContext?: IJsonContext): IJsonContext | undefined {\n return JsonContextHelper.mergeContext(defaultContext, this.options.context).orDefault();\n }\n\n /**\n * Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables\n * and references into a supplied existing context.\n * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables\n * and references are to be merged, or `undefined` to start with a default empty context.\n * @param add - The {@link VariableValue | variable values} and/or\n * {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.\n * @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.\n */\n public extendContext(\n baseContext: IJsonContext | undefined,\n add: { vars?: VariableValue[]; refs?: IJsonReferenceMap[] }\n ): Result<IJsonContext | undefined> {\n const context = this.getContext(baseContext);\n return JsonContextHelper.extendContext(context, add);\n }\n\n /**\n * Helper method to constructs `DetailedFailure` with appropriate details and messaging\n * for various validation failures.\n * @param rule - The {@link JsonEditorValidationRules | validation rule} that failed.\n * @param message - A string message describing the failed validation.\n * @param validation - The {@link IJsonEditorValidationOptions | validation options}\n * in effect.\n * @returns A `DetailedFailure` with appropriate detail and message.\n */\n public failValidation<T = JsonObject>(\n rule: JsonEditorValidationRules,\n message?: string,\n validation?: IJsonEditorValidationOptions\n ): DetailedFailure<T, JsonEditFailureReason> {\n let detail: JsonPropertyEditFailureReason = 'error';\n const effective = validation ?? this.options.validation;\n switch (rule) {\n case 'invalidPropertyName':\n detail = effective.onInvalidPropertyName !== 'ignore' ? 'error' : 'inapplicable';\n break;\n case 'invalidPropertyValue':\n detail = effective.onInvalidPropertyValue !== 'ignore' ? 'error' : 'ignore';\n break;\n case 'undefinedPropertyValue':\n detail = effective.onUndefinedPropertyValue !== 'error' ? 'ignore' : 'error';\n /* c8 ignore next */\n message = message ?? 'Cannot convert undefined to JSON';\n break;\n }\n /* c8 ignore next */\n return failWithDetail(message ?? rule, detail);\n }\n}\n"]}
@@ -119,7 +119,6 @@ export type MapOrRecord<T> = Map<string, T> | Record<string, T>;
119
119
  /**
120
120
  * Abstract base class with common functionality for simple
121
121
  * {@link IJsonReferenceMap | reference map} implementations.
122
- * {@link JsonValue | json values}.
123
122
  * @public
124
123
  */
125
124
  export declare abstract class SimpleJsonMapBase<T> implements IJsonReferenceMap {
@@ -170,7 +169,7 @@ export declare abstract class SimpleJsonMapBase<T> implements IJsonReferenceMap
170
169
  */
171
170
  has(key: string): boolean;
172
171
  /**
173
- * Gets a {@link JsonObject | JSON object} specified by key.
172
+ * Gets a `JsonObject` specified by key.
174
173
  * @param key - key of the object to be retrieved
175
174
  * @param context - optional {@link IJsonContext | JSON context} used to format the
176
175
  * returned object.
@@ -181,7 +180,7 @@ export declare abstract class SimpleJsonMapBase<T> implements IJsonReferenceMap
181
180
  */
182
181
  getJsonObject(key: string, context?: IJsonContext): DetailedResult<JsonObject, JsonReferenceMapFailureReason>;
183
182
  /**
184
- * Gets a {@link JsonValue | JSON value} specified by key.
183
+ * Gets a `JsonValue` specified by key.
185
184
  * @param key - key of the value to be retrieved
186
185
  * @param context - Optional {@link IJsonContext | JSON context} used to format the value
187
186
  * @returns Success with the formatted object if successful. Failure with detail 'unknown'
@@ -200,7 +199,7 @@ export interface ISimpleJsonMapOptions {
200
199
  }
201
200
  /**
202
201
  * A {@link SimpleJsonMap | SimpleJsonMap } presents a view of a simple map
203
- * of {@link JsonValue | JSON values}.
202
+ * of JSON values.
204
203
  * @public
205
204
  */
206
205
  export declare class SimpleJsonMap extends SimpleJsonMapBase<JsonValue> {
@@ -210,7 +209,7 @@ export declare class SimpleJsonMap extends SimpleJsonMapBase<JsonValue> {
210
209
  protected _editor?: JsonEditor;
211
210
  /**
212
211
  * Constructs a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects
213
- * @param values - A string-keyed `Map` or `Record` of the {@link JsonValue | JSON values}
212
+ * @param values - A string-keyed `Map` or `Record` of the `JsonValue`
214
213
  * to be returned.
215
214
  * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.
216
215
  * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.
@@ -219,7 +218,7 @@ export declare class SimpleJsonMap extends SimpleJsonMapBase<JsonValue> {
219
218
  protected constructor(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions);
220
219
  /**
221
220
  * Creates a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects
222
- * @param values - A string-keyed `Map` or `Record` of the {@link JsonValue | JSON values}
221
+ * @param values - A string-keyed `Map` or `Record` of the `JsonValue`
223
222
  * to be returned.
224
223
  * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.
225
224
  * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.
@@ -228,7 +227,7 @@ export declare class SimpleJsonMap extends SimpleJsonMapBase<JsonValue> {
228
227
  */
229
228
  static createSimple(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions): Result<SimpleJsonMap>;
230
229
  /**
231
- * Gets a {@link JsonValue | JSON value} specified by key.
230
+ * Gets a `JsonValue` specified by key.
232
231
  * @param key - key of the value to be retrieved
233
232
  * @param context - Optional {@link IJsonContext | JSON context} used to format the value
234
233
  * @returns Success with the formatted object if successful. Failure with detail 'unknown'
@@ -264,18 +263,18 @@ export declare class PrefixedJsonMap extends SimpleJsonMap {
264
263
  /**
265
264
  * Constructs a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
266
265
  * @param prefix - A string prefix to be enforced for and added to key names as necessary
267
- * @param values - A string-keyed Map or Record of the {@link JsonValue | JsonValue} to be returned
266
+ * @param values - A string-keyed Map or Record of the `JsonValue` to be returned
268
267
  * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values
269
- * @param editor - Optional {@link Editor.JsonEditor | JsonEditor} used to format returned values
268
+ * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values
270
269
  * @public
271
270
  */
272
271
  protected constructor(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions);
273
272
  /**
274
273
  * Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
275
274
  * @param prefix - A string prefix to be enforced for and added to key names as necessary
276
- * @param values - A string-keyed Map or Record of the {@link JsonValue | JsonValue} to be returned
275
+ * @param values - A string-keyed Map or Record of the `JsonValue` to be returned
277
276
  * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values
278
- * @param editor - Optional {@link Editor.JsonEditor | JsonEditor} used to format returned values
277
+ * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values
279
278
  * @returns `Success` with a {@link PrefixedJsonMap | PrefixedJsonMap} or `Failure` with a message
280
279
  * if an error occurs.
281
280
  */
@@ -284,9 +283,9 @@ export declare class PrefixedJsonMap extends SimpleJsonMap {
284
283
  * Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
285
284
  * @param prefixOptions - A KeyPrefixOptions indicating the prefix to enforce and whether that prefix should
286
285
  * be added automatically if necessary (default true)
287
- * @param values - A string-keyed Map or record of the {@link JsonValue | JsonValue} to be returned
286
+ * @param values - A string-keyed Map or record of the `JsonValue` to be returned
288
287
  * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values
289
- * @param editor - Optional {@link Editor.JsonEditor | JsonEditor} used to format returned values
288
+ * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values
290
289
  */
291
290
  static createPrefixed(prefixOptions: IKeyPrefixOptions, values?: MapOrRecord<JsonValue>, context?: IJsonContext, editor?: JsonEditor): Result<PrefixedJsonMap>;
292
291
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"jsonReferenceMap.d.ts","sourceRoot":"","sources":["../../../src/packlets/editor/jsonReferenceMap.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,cAAc,EACd,MAAM,EAQP,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAgB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,qCAAqC;IACpD;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;GAIG;AACH,qBAAa,qBAAqB,CAAC,CAAC;IAClC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,qCAAqC,CAAC;IAE3E;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;IAEhE;;;;;OAKG;gBAED,OAAO,CAAC,EAAE,qCAAqC,EAC/C,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,C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AC,eAAe,CAAC;IAE1B;;;;;;;OAOG;WACW,cAAc,CAC1B,aAAa,EAAE,iBAAiB,EAChC,MAAM,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,EAC/B,OAAO,CAAC,EAAE,YAAY,EACtB,MAAM,CAAC,EAAE,UAAU,GAClB,MAAM,CAAC,eAAe,CAAC;IAY1B;;;;;;;;OAQG;IACH,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,GAAG,iBAAiB,GAAG,qBAAqB,CAAC,SAAS,CAAC;CAMxG"}
@@ -151,7 +151,6 @@ exports.PrefixKeyPolicy = PrefixKeyPolicy;
151
151
  /**
152
152
  * Abstract base class with common functionality for simple
153
153
  * {@link IJsonReferenceMap | reference map} implementations.
154
- * {@link JsonValue | json values}.
155
154
  * @public
156
155
  */
157
156
  class SimpleJsonMapBase {
@@ -203,7 +202,7 @@ class SimpleJsonMapBase {
203
202
  return this._values.has(key);
204
203
  }
205
204
  /**
206
- * Gets a {@link JsonObject | JSON object} specified by key.
205
+ * Gets a `JsonObject` specified by key.
207
206
  * @param key - key of the object to be retrieved
208
207
  * @param context - optional {@link IJsonContext | JSON context} used to format the
209
208
  * returned object.
@@ -224,13 +223,13 @@ class SimpleJsonMapBase {
224
223
  exports.SimpleJsonMapBase = SimpleJsonMapBase;
225
224
  /**
226
225
  * A {@link SimpleJsonMap | SimpleJsonMap } presents a view of a simple map
227
- * of {@link JsonValue | JSON values}.
226
+ * of JSON values.
228
227
  * @public
229
228
  */
230
229
  class SimpleJsonMap extends SimpleJsonMapBase {
231
230
  /**
232
231
  * Constructs a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects
233
- * @param values - A string-keyed `Map` or `Record` of the {@link JsonValue | JSON values}
232
+ * @param values - A string-keyed `Map` or `Record` of the `JsonValue`
234
233
  * to be returned.
235
234
  * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.
236
235
  * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.
@@ -242,7 +241,7 @@ class SimpleJsonMap extends SimpleJsonMapBase {
242
241
  }
243
242
  /**
244
243
  * Creates a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects
245
- * @param values - A string-keyed `Map` or `Record` of the {@link JsonValue | JSON values}
244
+ * @param values - A string-keyed `Map` or `Record` of the `JsonValue`
246
245
  * to be returned.
247
246
  * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.
248
247
  * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.
@@ -253,7 +252,7 @@ class SimpleJsonMap extends SimpleJsonMapBase {
253
252
  return (0, ts_utils_1.captureResult)(() => new SimpleJsonMap(values, context, options));
254
253
  }
255
254
  /**
256
- * Gets a {@link JsonValue | JSON value} specified by key.
255
+ * Gets a `JsonValue` specified by key.
257
256
  * @param key - key of the value to be retrieved
258
257
  * @param context - Optional {@link IJsonContext | JSON context} used to format the value
259
258
  * @returns Success with the formatted object if successful. Failure with detail 'unknown'
@@ -293,9 +292,9 @@ class PrefixedJsonMap extends SimpleJsonMap {
293
292
  /**
294
293
  * Constructs a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
295
294
  * @param prefix - A string prefix to be enforced for and added to key names as necessary
296
- * @param values - A string-keyed Map or Record of the {@link JsonValue | JsonValue} to be returned
295
+ * @param values - A string-keyed Map or Record of the `JsonValue` to be returned
297
296
  * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values
298
- * @param editor - Optional {@link Editor.JsonEditor | JsonEditor} used to format returned values
297
+ * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values
299
298
  * @public
300
299
  */
301
300
  constructor(values, context, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"jsonReferenceMap.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonReferenceMap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAUuB;AAEvB,oDAAwE;AAExE,6CAA0C;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C;YACtC,OAAO,IAAI,eAAe,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,eAAe,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,aAAa,CAAC,SAAS,KAAK,KAAK,EAAE,CAAC,CAAC;IACrG,CAAC;CACF;AAzED,0CAyEC","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 mapResults,\n recordToMap,\n succeed,\n succeedWithDetail\n} from '@fgv/ts-utils';\n\nimport { JsonObject, JsonValue, isJsonObject } from '@fgv/ts-json-base';\nimport { IJsonContext, IJsonReferenceMap, JsonReferenceMapFailureReason } from '../context';\nimport { JsonEditor } from './jsonEditor';\n\n/**\n * Options for creating a {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} object.\n * @public\n */\nexport interface IReferenceMapKeyPolicyValidateOptions {\n /**\n * If `true`, the validator coerces keys to some valid value.\n * If `false`, invalid keys cause an error.\n */\n makeValid?: boolean;\n}\n\n/**\n * Policy object responsible for validating or correcting\n * keys in a {@link IJsonReferenceMap | reference map}.\n * @public\n */\nexport class ReferenceMapKeyPolicy<T> {\n /**\n * @internal\n */\n protected readonly _defaultOptions?: IReferenceMapKeyPolicyValidateOptions;\n\n /**\n * @internal\n */\n protected readonly _isValid: (key: string, item?: T) => boolean;\n\n /**\n * Constructs a new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy}.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options}\n * used to construct the {@link ReferenceMapKeyPolicy}.\n * @param isValid - An optional predicate to test a supplied key for validity.\n */\n public constructor(\n options?: IReferenceMapKeyPolicyValidateOptions,\n isValid?: (key: string, item?: T) => boolean\n ) {\n this._defaultOptions = options;\n this._isValid = isValid ?? ReferenceMapKeyPolicy.defaultKeyPredicate;\n }\n\n /**\n * The static default key name validation predicate rejects keys that contain\n * mustache templates or which start with the default conditional prefix\n * `'?'`.\n * @param key - The key to test.\n * @returns `true` if the key is valid, `false` otherwise.\n */\n public static defaultKeyPredicate(key: string): boolean {\n return key.length > 0 && !key.includes('{{') && !key.startsWith('?');\n }\n\n /**\n * Determines if a supplied key and item are valid according to the current policy.\n * @param key - The key to be tested.\n * @param item - The item to be tested.\n * @returns `true` if the key and value are valid, `false` otherwise.\n */\n public isValid(key: string, item?: T): boolean {\n return this._isValid(key, item);\n }\n\n /**\n * Determines if a supplied key and item are valid according to the current policy.\n * @param key - The key to be tested.\n * @param item - The item to be tested.\n * @returns `Success` with the key if valid, `Failure` with an error message if invalid.\n */\n public validate(key: string, item?: T, __options?: IReferenceMapKeyPolicyValidateOptions): Result<string> {\n return this.isValid(key, item) ? succeed(key) : fail(`${key}: invalid key`);\n }\n\n /**\n * Validates an array of entries using the validation rules for this policy.\n * @param items - The array of entries to be validated.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control\n * validation.\n * @returns `Success` with an array of validated entries, or `Failure` with an error message\n * if validation fails.\n */\n public validateItems(\n items: [string, T][],\n options?: IReferenceMapKeyPolicyValidateOptions\n ): Result<[string, T][]> {\n return mapResults(\n items.map((item) => {\n return this.validate(...item, options).onSuccess((valid) => {\n return succeed([valid, item[1]]);\n });\n })\n );\n }\n\n /**\n * Validates a `Map\\<string, T\\>` using the validation rules for this policy.\n * @param items - The `Map\\<string, T\\>` to be validated.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control\n * validation.\n * @returns `Success` with a new `Map\\<string, T\\>`, or `Failure` with an error message\n * if validation fails.\n */\n public validateMap(\n map: Map<string, T>,\n options?: IReferenceMapKeyPolicyValidateOptions\n ): Result<Map<string, T>> {\n return this.validateItems(Array.from(map.entries()), options).onSuccess((valid) => {\n return captureResult(() => new Map(valid));\n });\n }\n}\n\n/**\n * A {@link PrefixKeyPolicy | PrefixKeyPolicy} enforces that all keys start with a supplied\n * prefix, optionally adding the prefix as necessary.\n * @public\n */\nexport class PrefixKeyPolicy<T> extends ReferenceMapKeyPolicy<T> {\n /**\n * The string prefix to be enforced by this policy.\n */\n public readonly prefix: string;\n\n /**\n * Constructs a new {@link PrefixKeyPolicy | PrefixKeyPolicy}.\n * @param prefix - The string prefix to be enforced or applied.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to\n * configure the policy.\n */\n public constructor(prefix: string, options?: IReferenceMapKeyPolicyValidateOptions) {\n super(options);\n this.prefix = prefix;\n }\n\n /**\n * Determines if a key is valid according to policy.\n * @param key - The key to be tested.\n * @param __item - The item to be tested.\n * @returns `true` if the key starts with the expected prefix, `false` otherwise.\n */\n public isValid(key: string, __item?: T): boolean {\n return (\n key.startsWith(this.prefix) && key !== this.prefix && ReferenceMapKeyPolicy.defaultKeyPredicate(key)\n );\n }\n\n /**\n * Determines if a key is valid according to policy, optionally coercing to a valid value by\n * adding the required prefix.\n * @param key - The key to be tested.\n * @param item - The item which corresponds to the key.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to guide\n * validation.\n * @returns `Success` with a valid key name if the supplied key is valid or if `makeValid` is set\n * in the policy options. Returns `Failure` with an error message if an error occurs.\n */\n public validate(key: string, item?: T, options?: IReferenceMapKeyPolicyValidateOptions): Result<string> {\n /* c8 ignore next */\n const makeValid = (options ?? this._defaultOptions)?.makeValid === true;\n if (this.isValid(key, item)) {\n return succeed(key);\n } else if (makeValid && ReferenceMapKeyPolicy.defaultKeyPredicate(key)) {\n return succeed(`${this.prefix}${key}`);\n }\n return fail(`${key}: invalid key`);\n }\n}\n\n/**\n * Type representing either a `Map\\<string, T\\>` or a `Record\\<string, T\\>`.\n * @public\n */\nexport type MapOrRecord<T> = Map<string, T> | Record<string, T>;\n\n/**\n * Abstract base class with common functionality for simple\n * {@link IJsonReferenceMap | reference map} implementations.\n * {@link JsonValue | json values}.\n * @public\n */\nexport abstract class SimpleJsonMapBase<T> implements IJsonReferenceMap {\n /**\n * The {@link ReferenceMapKeyPolicy | key policy} in effect for this map.\n * @internal\n */\n protected readonly _keyPolicy: ReferenceMapKeyPolicy<T>;\n\n /**\n * A map containing keys and values already present in this map.\n * @internal\n */\n protected readonly _values: Map<string, T>;\n\n /**\n * An optional {@link IJsonContext | IJsonContext} used for any conversions\n * involving items in this map.\n * @internal\n */\n protected readonly _context?: IJsonContext;\n\n /**\n * Constructs a new {@link SimpleJsonMap | SimpleJsonMap}.\n * @param values - Initial values for the map.\n * @param context - An optional {@link IJsonContext | IJsonContext} used for any conversions\n * involving items in this map.\n * @param keyPolicy - The {@link ReferenceMapKeyPolicy | key policy} to use for this map.\n * @internal\n */\n protected constructor(\n values?: MapOrRecord<T>,\n context?: IJsonContext,\n keyPolicy?: ReferenceMapKeyPolicy<T>\n ) {\n values = SimpleJsonMapBase._toMap(values).orThrow();\n this._keyPolicy = keyPolicy ?? new ReferenceMapKeyPolicy();\n this._values = this._keyPolicy.validateMap(values).orThrow();\n this._context = context;\n }\n\n /**\n * Returns a `Map\\<string, T\\>` derived from a supplied {@link MapOrRecord | MapOrRecord}\n * @param values - The {@link MapOrRecord | MapOrRecord} to be returned as a map.\n * @returns `Success` with the corresponding `Map\\<string, T\\>` or `Failure` with a\n * message if an error occurs.\n * @internal\n */\n protected static _toMap<T>(values?: MapOrRecord<T>): Result<Map<string, T>> {\n if (values === undefined) {\n return captureResult(() => new Map<string, T>());\n } else if (!(values instanceof Map)) {\n return recordToMap(values, (__k, v) => succeed(v));\n }\n return succeed(values);\n }\n\n /**\n * Determine if a key might be valid for this map but does not determine if key actually\n * exists. Allows key range to be constrained.\n * @param key - key to be tested\n * @returns `true` if the key is in the valid range, `false` otherwise.\n */\n public keyIsInRange(key: string): boolean {\n return this._keyPolicy.isValid(key);\n }\n\n /**\n * Determines if an entry with the specified key actually exists in the map.\n * @param key - key to be tested\n * @returns `true` if an object with the specified key exists, `false` otherwise.\n */\n public has(key: string): boolean {\n return this._values.has(key);\n }\n\n /**\n * Gets a {@link JsonObject | JSON object} specified by key.\n * @param key - key of the object to be retrieved\n * @param context - optional {@link IJsonContext | JSON context} used to format the\n * returned object.\n * @returns {@link ts-utils#Success | `Success`} with the formatted object if successful.\n * {@link ts-utils#Failure | `Failure`} with detail 'unknown' if no such object exists,\n * or {@link ts-utils#Failure | `Failure`} with detail 'error' if the object was found\n * but could not be formatted.\n */\n public getJsonObject(\n key: string,\n context?: IJsonContext\n ): DetailedResult<JsonObject, JsonReferenceMapFailureReason> {\n return this.getJsonValue(key, context).onSuccess((jv) => {\n if (!isJsonObject(jv)) {\n return failWithDetail(`${key}: not an object`, 'error');\n }\n return succeedWithDetail(jv);\n });\n }\n\n /**\n * Gets a {@link JsonValue | JSON value} specified by key.\n * @param key - key of the value to be retrieved\n * @param context - Optional {@link IJsonContext | JSON context} used to format the value\n * @returns Success with the formatted object if successful. Failure with detail 'unknown'\n * if no such object exists, or failure with detail 'error' if the object was found but\n * could not be formatted.\n */\n // eslint-disable-next-line no-use-before-define\n public abstract getJsonValue(\n key: string,\n context?: IJsonContext\n ): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;\n}\n\n/**\n * Initialization options for a {@link SimpleJsonMap | SimpleJsonMap}.\n * @public\n */\nexport interface ISimpleJsonMapOptions {\n keyPolicy?: ReferenceMapKeyPolicy<JsonValue>;\n editor?: JsonEditor;\n}\n\n/**\n * A {@link SimpleJsonMap | SimpleJsonMap } presents a view of a simple map\n * of {@link JsonValue | JSON values}.\n * @public\n */\nexport class SimpleJsonMap extends SimpleJsonMapBase<JsonValue> {\n /**\n * @internal\n */\n protected _editor?: JsonEditor;\n\n /**\n * Constructs a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects\n * @param values - A string-keyed `Map` or `Record` of the {@link JsonValue | JSON values}\n * to be returned.\n * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.\n * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.\n * @public\n */\n protected constructor(\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n options?: ISimpleJsonMapOptions\n ) {\n super(values, context, options?.keyPolicy);\n this._editor = options?.editor;\n }\n\n /**\n * Creates a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects\n * @param values - A string-keyed `Map` or `Record` of the {@link JsonValue | JSON values}\n * to be returned.\n * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.\n * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.\n * @returns `Success` with a {@link SimpleJsonMap | SimpleJsonMap} or `Failure` with a message if\n * an error occurs.\n */\n public static createSimple(\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n options?: ISimpleJsonMapOptions\n ): Result<SimpleJsonMap> {\n return captureResult(() => new SimpleJsonMap(values, context, options));\n }\n\n /**\n * Gets a {@link JsonValue | JSON value} specified by key.\n * @param key - key of the value to be retrieved\n * @param context - Optional {@link IJsonContext | JSON context} used to format the value\n * @returns Success with the formatted object if successful. Failure with detail 'unknown'\n * if no such object exists, or failure with detail 'error' if the object was found but\n * could not be formatted.\n */\n public getJsonValue(\n key: string,\n context?: IJsonContext\n ): DetailedResult<JsonValue, JsonReferenceMapFailureReason> {\n context = context ?? this._context;\n const value = this._values.get(key);\n if (!value) {\n return failWithDetail(`${key}: JSON value not found`, 'unknown');\n }\n return this._clone(value, context);\n }\n\n /**\n * @internal\n */\n protected _clone(\n value: JsonValue,\n context?: IJsonContext\n ): DetailedResult<JsonValue, JsonReferenceMapFailureReason> {\n if (!this._editor) {\n const result = JsonEditor.create();\n /* c8 ignore next 3 - nearly impossible to reproduce */\n if (result.isFailure()) {\n return failWithDetail(result.message, 'error');\n }\n this._editor = result.value;\n }\n return this._editor.clone(value, context).withFailureDetail('error');\n }\n}\n\n/**\n * Initialization options for a {@link PrefixedJsonMap | PrefixedJsonMap}\n * @public\n */\nexport interface IKeyPrefixOptions {\n /**\n * Indicates whether the prefix should be added automatically as needed (default true)\n */\n addPrefix?: boolean;\n\n /**\n * The prefix to be enforced\n */\n prefix: string;\n}\n\n/**\n * A {@link PrefixedJsonMap | PrefixedJsonMap} enforces a supplied prefix for all contained values,\n * optionally adding the prefix as necessary (default `true`).\n * @public\n */\nexport class PrefixedJsonMap extends SimpleJsonMap {\n /**\n * Constructs a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values\n * @param prefix - A string prefix to be enforced for and added to key names as necessary\n * @param values - A string-keyed Map or Record of the {@link JsonValue | JsonValue} to be returned\n * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values\n * @param editor - Optional {@link Editor.JsonEditor | JsonEditor} used to format returned values\n * @public\n */\n protected constructor(\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n options?: ISimpleJsonMapOptions\n ) {\n super(values, context, options);\n }\n\n /**\n * Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values\n * @param prefix - A string prefix to be enforced for and added to key names as necessary\n * @param values - A string-keyed Map or Record of the {@link JsonValue | JsonValue} to be returned\n * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values\n * @param editor - Optional {@link Editor.JsonEditor | JsonEditor} used to format returned values\n * @returns `Success` with a {@link PrefixedJsonMap | PrefixedJsonMap} or `Failure` with a message\n * if an error occurs.\n */\n public static createPrefixed(\n prefix: string,\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n editor?: JsonEditor\n ): Result<PrefixedJsonMap>;\n\n /**\n * Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values\n * @param prefixOptions - A KeyPrefixOptions indicating the prefix to enforce and whether that prefix should\n * be added automatically if necessary (default true)\n * @param values - A string-keyed Map or record of the {@link JsonValue | JsonValue} to be returned\n * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values\n * @param editor - Optional {@link Editor.JsonEditor | JsonEditor} used to format returned values\n */\n public static createPrefixed(\n prefixOptions: IKeyPrefixOptions,\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n editor?: JsonEditor\n ): Result<PrefixedJsonMap>;\n public static createPrefixed(\n prefixOptions: string | IKeyPrefixOptions,\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n editor?: JsonEditor\n ): Result<PrefixedJsonMap> {\n return captureResult(\n () => new PrefixedJsonMap(values, context, { keyPolicy: this._toPolicy(prefixOptions), editor })\n );\n }\n\n /**\n * Constructs a new {@link PrefixKeyPolicy | PrefixKeyPolicy} from a supplied prefix\n * or set of {@link IKeyPrefixOptions | prefix options}.\n * @param prefixOptions - The prefix or {@link IKeyPrefixOptions | prefix options} or options\n * for the new policy.\n * @returns A new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} which enforces the\n * supplied prefix or options.\n * @internal\n */\n protected static _toPolicy(prefixOptions: string | IKeyPrefixOptions): ReferenceMapKeyPolicy<JsonValue> {\n if (typeof prefixOptions === 'string') {\n return new PrefixKeyPolicy(prefixOptions, { makeValid: true });\n }\n return new PrefixKeyPolicy(prefixOptions.prefix, { makeValid: prefixOptions.addPrefix !== false });\n }\n}\n"]}
1
+ {"version":3,"file":"jsonReferenceMap.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonReferenceMap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAUuB;AAEvB,oDAAwE;AAExE,6CAA0C;AAc1C;;;;GAIG;AACH,MAAa,qBAAqB;IAWhC;;;;;OAKG;IACH,YACE,OAA+C,EAC/C,OAA4C;QAE5C,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,qBAAqB,CAAC,mBAAmB,CAAC;IACvE,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,mBAAmB,CAAC,GAAW;QAC3C,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACvE,CAAC;IAED;;;;;OAKG;IACI,OAAO,CAAC,GAAW,EAAE,IAAQ;QAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACI,QAAQ,CAAC,GAAW,EAAE,IAAQ,EAAE,SAAiD;QACtF,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAA,eAAI,EAAC,GAAG,GAAG,eAAe,CAAC,CAAC;IAC9E,CAAC;IAED;;;;;;;OAOG;IACI,aAAa,CAClB,KAAoB,EACpB,OAA+C;QAE/C,OAAO,IAAA,qBAAU,EACf,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,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AAE,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,CACjG,CAAC;IACJ,CAAC;IAED;;;;;;;;OAQG;IACO,MAAM,CAAC,SAAS,CAAC,aAAyC;QAClE,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;YACtC,OAAO,IAAI,eAAe,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,eAAe,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,aAAa,CAAC,SAAS,KAAK,KAAK,EAAE,CAAC,CAAC;IACrG,CAAC;CACF;AAzED,0CAyEC","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 mapResults,\n recordToMap,\n succeed,\n succeedWithDetail\n} from '@fgv/ts-utils';\n\nimport { JsonObject, JsonValue, isJsonObject } from '@fgv/ts-json-base';\nimport { IJsonContext, IJsonReferenceMap, JsonReferenceMapFailureReason } from '../context';\nimport { JsonEditor } from './jsonEditor';\n\n/**\n * Options for creating a {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} object.\n * @public\n */\nexport interface IReferenceMapKeyPolicyValidateOptions {\n /**\n * If `true`, the validator coerces keys to some valid value.\n * If `false`, invalid keys cause an error.\n */\n makeValid?: boolean;\n}\n\n/**\n * Policy object responsible for validating or correcting\n * keys in a {@link IJsonReferenceMap | reference map}.\n * @public\n */\nexport class ReferenceMapKeyPolicy<T> {\n /**\n * @internal\n */\n protected readonly _defaultOptions?: IReferenceMapKeyPolicyValidateOptions;\n\n /**\n * @internal\n */\n protected readonly _isValid: (key: string, item?: T) => boolean;\n\n /**\n * Constructs a new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy}.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options}\n * used to construct the {@link ReferenceMapKeyPolicy}.\n * @param isValid - An optional predicate to test a supplied key for validity.\n */\n public constructor(\n options?: IReferenceMapKeyPolicyValidateOptions,\n isValid?: (key: string, item?: T) => boolean\n ) {\n this._defaultOptions = options;\n this._isValid = isValid ?? ReferenceMapKeyPolicy.defaultKeyPredicate;\n }\n\n /**\n * The static default key name validation predicate rejects keys that contain\n * mustache templates or which start with the default conditional prefix\n * `'?'`.\n * @param key - The key to test.\n * @returns `true` if the key is valid, `false` otherwise.\n */\n public static defaultKeyPredicate(key: string): boolean {\n return key.length > 0 && !key.includes('{{') && !key.startsWith('?');\n }\n\n /**\n * Determines if a supplied key and item are valid according to the current policy.\n * @param key - The key to be tested.\n * @param item - The item to be tested.\n * @returns `true` if the key and value are valid, `false` otherwise.\n */\n public isValid(key: string, item?: T): boolean {\n return this._isValid(key, item);\n }\n\n /**\n * Determines if a supplied key and item are valid according to the current policy.\n * @param key - The key to be tested.\n * @param item - The item to be tested.\n * @returns `Success` with the key if valid, `Failure` with an error message if invalid.\n */\n public validate(key: string, item?: T, __options?: IReferenceMapKeyPolicyValidateOptions): Result<string> {\n return this.isValid(key, item) ? succeed(key) : fail(`${key}: invalid key`);\n }\n\n /**\n * Validates an array of entries using the validation rules for this policy.\n * @param items - The array of entries to be validated.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control\n * validation.\n * @returns `Success` with an array of validated entries, or `Failure` with an error message\n * if validation fails.\n */\n public validateItems(\n items: [string, T][],\n options?: IReferenceMapKeyPolicyValidateOptions\n ): Result<[string, T][]> {\n return mapResults(\n items.map((item) => {\n return this.validate(...item, options).onSuccess((valid) => {\n return succeed([valid, item[1]]);\n });\n })\n );\n }\n\n /**\n * Validates a `Map\\<string, T\\>` using the validation rules for this policy.\n * @param items - The `Map\\<string, T\\>` to be validated.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control\n * validation.\n * @returns `Success` with a new `Map\\<string, T\\>`, or `Failure` with an error message\n * if validation fails.\n */\n public validateMap(\n map: Map<string, T>,\n options?: IReferenceMapKeyPolicyValidateOptions\n ): Result<Map<string, T>> {\n return this.validateItems(Array.from(map.entries()), options).onSuccess((valid) => {\n return captureResult(() => new Map(valid));\n });\n }\n}\n\n/**\n * A {@link PrefixKeyPolicy | PrefixKeyPolicy} enforces that all keys start with a supplied\n * prefix, optionally adding the prefix as necessary.\n * @public\n */\nexport class PrefixKeyPolicy<T> extends ReferenceMapKeyPolicy<T> {\n /**\n * The string prefix to be enforced by this policy.\n */\n public readonly prefix: string;\n\n /**\n * Constructs a new {@link PrefixKeyPolicy | PrefixKeyPolicy}.\n * @param prefix - The string prefix to be enforced or applied.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to\n * configure the policy.\n */\n public constructor(prefix: string, options?: IReferenceMapKeyPolicyValidateOptions) {\n super(options);\n this.prefix = prefix;\n }\n\n /**\n * Determines if a key is valid according to policy.\n * @param key - The key to be tested.\n * @param __item - The item to be tested.\n * @returns `true` if the key starts with the expected prefix, `false` otherwise.\n */\n public isValid(key: string, __item?: T): boolean {\n return (\n key.startsWith(this.prefix) && key !== this.prefix && ReferenceMapKeyPolicy.defaultKeyPredicate(key)\n );\n }\n\n /**\n * Determines if a key is valid according to policy, optionally coercing to a valid value by\n * adding the required prefix.\n * @param key - The key to be tested.\n * @param item - The item which corresponds to the key.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to guide\n * validation.\n * @returns `Success` with a valid key name if the supplied key is valid or if `makeValid` is set\n * in the policy options. Returns `Failure` with an error message if an error occurs.\n */\n public validate(key: string, item?: T, options?: IReferenceMapKeyPolicyValidateOptions): Result<string> {\n /* c8 ignore next */\n const makeValid = (options ?? this._defaultOptions)?.makeValid === true;\n if (this.isValid(key, item)) {\n return succeed(key);\n } else if (makeValid && ReferenceMapKeyPolicy.defaultKeyPredicate(key)) {\n return succeed(`${this.prefix}${key}`);\n }\n return fail(`${key}: invalid key`);\n }\n}\n\n/**\n * Type representing either a `Map\\<string, T\\>` or a `Record\\<string, T\\>`.\n * @public\n */\nexport type MapOrRecord<T> = Map<string, T> | Record<string, T>;\n\n/**\n * Abstract base class with common functionality for simple\n * {@link IJsonReferenceMap | reference map} implementations.\n * @public\n */\nexport abstract class SimpleJsonMapBase<T> implements IJsonReferenceMap {\n /**\n * The {@link ReferenceMapKeyPolicy | key policy} in effect for this map.\n * @internal\n */\n protected readonly _keyPolicy: ReferenceMapKeyPolicy<T>;\n\n /**\n * A map containing keys and values already present in this map.\n * @internal\n */\n protected readonly _values: Map<string, T>;\n\n /**\n * An optional {@link IJsonContext | IJsonContext} used for any conversions\n * involving items in this map.\n * @internal\n */\n protected readonly _context?: IJsonContext;\n\n /**\n * Constructs a new {@link SimpleJsonMap | SimpleJsonMap}.\n * @param values - Initial values for the map.\n * @param context - An optional {@link IJsonContext | IJsonContext} used for any conversions\n * involving items in this map.\n * @param keyPolicy - The {@link ReferenceMapKeyPolicy | key policy} to use for this map.\n * @internal\n */\n protected constructor(\n values?: MapOrRecord<T>,\n context?: IJsonContext,\n keyPolicy?: ReferenceMapKeyPolicy<T>\n ) {\n values = SimpleJsonMapBase._toMap(values).orThrow();\n this._keyPolicy = keyPolicy ?? new ReferenceMapKeyPolicy();\n this._values = this._keyPolicy.validateMap(values).orThrow();\n this._context = context;\n }\n\n /**\n * Returns a `Map\\<string, T\\>` derived from a supplied {@link MapOrRecord | MapOrRecord}\n * @param values - The {@link MapOrRecord | MapOrRecord} to be returned as a map.\n * @returns `Success` with the corresponding `Map\\<string, T\\>` or `Failure` with a\n * message if an error occurs.\n * @internal\n */\n protected static _toMap<T>(values?: MapOrRecord<T>): Result<Map<string, T>> {\n if (values === undefined) {\n return captureResult(() => new Map<string, T>());\n } else if (!(values instanceof Map)) {\n return recordToMap(values, (__k, v) => succeed(v));\n }\n return succeed(values);\n }\n\n /**\n * Determine if a key might be valid for this map but does not determine if key actually\n * exists. Allows key range to be constrained.\n * @param key - key to be tested\n * @returns `true` if the key is in the valid range, `false` otherwise.\n */\n public keyIsInRange(key: string): boolean {\n return this._keyPolicy.isValid(key);\n }\n\n /**\n * Determines if an entry with the specified key actually exists in the map.\n * @param key - key to be tested\n * @returns `true` if an object with the specified key exists, `false` otherwise.\n */\n public has(key: string): boolean {\n return this._values.has(key);\n }\n\n /**\n * Gets a `JsonObject` specified by key.\n * @param key - key of the object to be retrieved\n * @param context - optional {@link IJsonContext | JSON context} used to format the\n * returned object.\n * @returns {@link ts-utils#Success | `Success`} with the formatted object if successful.\n * {@link ts-utils#Failure | `Failure`} with detail 'unknown' if no such object exists,\n * or {@link ts-utils#Failure | `Failure`} with detail 'error' if the object was found\n * but could not be formatted.\n */\n public getJsonObject(\n key: string,\n context?: IJsonContext\n ): DetailedResult<JsonObject, JsonReferenceMapFailureReason> {\n return this.getJsonValue(key, context).onSuccess((jv) => {\n if (!isJsonObject(jv)) {\n return failWithDetail(`${key}: not an object`, 'error');\n }\n return succeedWithDetail(jv);\n });\n }\n\n /**\n * Gets a `JsonValue` specified by key.\n * @param key - key of the value to be retrieved\n * @param context - Optional {@link IJsonContext | JSON context} used to format the value\n * @returns Success with the formatted object if successful. Failure with detail 'unknown'\n * if no such object exists, or failure with detail 'error' if the object was found but\n * could not be formatted.\n */\n // eslint-disable-next-line no-use-before-define\n public abstract getJsonValue(\n key: string,\n context?: IJsonContext\n ): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;\n}\n\n/**\n * Initialization options for a {@link SimpleJsonMap | SimpleJsonMap}.\n * @public\n */\nexport interface ISimpleJsonMapOptions {\n keyPolicy?: ReferenceMapKeyPolicy<JsonValue>;\n editor?: JsonEditor;\n}\n\n/**\n * A {@link SimpleJsonMap | SimpleJsonMap } presents a view of a simple map\n * of JSON values.\n * @public\n */\nexport class SimpleJsonMap extends SimpleJsonMapBase<JsonValue> {\n /**\n * @internal\n */\n protected _editor?: JsonEditor;\n\n /**\n * Constructs a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects\n * @param values - A string-keyed `Map` or `Record` of the `JsonValue`\n * to be returned.\n * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.\n * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.\n * @public\n */\n protected constructor(\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n options?: ISimpleJsonMapOptions\n ) {\n super(values, context, options?.keyPolicy);\n this._editor = options?.editor;\n }\n\n /**\n * Creates a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects\n * @param values - A string-keyed `Map` or `Record` of the `JsonValue`\n * to be returned.\n * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.\n * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.\n * @returns `Success` with a {@link SimpleJsonMap | SimpleJsonMap} or `Failure` with a message if\n * an error occurs.\n */\n public static createSimple(\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n options?: ISimpleJsonMapOptions\n ): Result<SimpleJsonMap> {\n return captureResult(() => new SimpleJsonMap(values, context, options));\n }\n\n /**\n * Gets a `JsonValue` specified by key.\n * @param key - key of the value to be retrieved\n * @param context - Optional {@link IJsonContext | JSON context} used to format the value\n * @returns Success with the formatted object if successful. Failure with detail 'unknown'\n * if no such object exists, or failure with detail 'error' if the object was found but\n * could not be formatted.\n */\n public getJsonValue(\n key: string,\n context?: IJsonContext\n ): DetailedResult<JsonValue, JsonReferenceMapFailureReason> {\n context = context ?? this._context;\n const value = this._values.get(key);\n if (!value) {\n return failWithDetail(`${key}: JSON value not found`, 'unknown');\n }\n return this._clone(value, context);\n }\n\n /**\n * @internal\n */\n protected _clone(\n value: JsonValue,\n context?: IJsonContext\n ): DetailedResult<JsonValue, JsonReferenceMapFailureReason> {\n if (!this._editor) {\n const result = JsonEditor.create();\n /* c8 ignore next 3 - nearly impossible to reproduce */\n if (result.isFailure()) {\n return failWithDetail(result.message, 'error');\n }\n this._editor = result.value;\n }\n return this._editor.clone(value, context).withFailureDetail('error');\n }\n}\n\n/**\n * Initialization options for a {@link PrefixedJsonMap | PrefixedJsonMap}\n * @public\n */\nexport interface IKeyPrefixOptions {\n /**\n * Indicates whether the prefix should be added automatically as needed (default true)\n */\n addPrefix?: boolean;\n\n /**\n * The prefix to be enforced\n */\n prefix: string;\n}\n\n/**\n * A {@link PrefixedJsonMap | PrefixedJsonMap} enforces a supplied prefix for all contained values,\n * optionally adding the prefix as necessary (default `true`).\n * @public\n */\nexport class PrefixedJsonMap extends SimpleJsonMap {\n /**\n * Constructs a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values\n * @param prefix - A string prefix to be enforced for and added to key names as necessary\n * @param values - A string-keyed Map or Record of the `JsonValue` to be returned\n * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values\n * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values\n * @public\n */\n protected constructor(\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n options?: ISimpleJsonMapOptions\n ) {\n super(values, context, options);\n }\n\n /**\n * Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values\n * @param prefix - A string prefix to be enforced for and added to key names as necessary\n * @param values - A string-keyed Map or Record of the `JsonValue` to be returned\n * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values\n * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values\n * @returns `Success` with a {@link PrefixedJsonMap | PrefixedJsonMap} or `Failure` with a message\n * if an error occurs.\n */\n public static createPrefixed(\n prefix: string,\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n editor?: JsonEditor\n ): Result<PrefixedJsonMap>;\n\n /**\n * Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values\n * @param prefixOptions - A KeyPrefixOptions indicating the prefix to enforce and whether that prefix should\n * be added automatically if necessary (default true)\n * @param values - A string-keyed Map or record of the `JsonValue` to be returned\n * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values\n * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values\n */\n public static createPrefixed(\n prefixOptions: IKeyPrefixOptions,\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n editor?: JsonEditor\n ): Result<PrefixedJsonMap>;\n public static createPrefixed(\n prefixOptions: string | IKeyPrefixOptions,\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n editor?: JsonEditor\n ): Result<PrefixedJsonMap> {\n return captureResult(\n () => new PrefixedJsonMap(values, context, { keyPolicy: this._toPolicy(prefixOptions), editor })\n );\n }\n\n /**\n * Constructs a new {@link PrefixKeyPolicy | PrefixKeyPolicy} from a supplied prefix\n * or set of {@link IKeyPrefixOptions | prefix options}.\n * @param prefixOptions - The prefix or {@link IKeyPrefixOptions | prefix options} or options\n * for the new policy.\n * @returns A new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} which enforces the\n * supplied prefix or options.\n * @internal\n */\n protected static _toPolicy(prefixOptions: string | IKeyPrefixOptions): ReferenceMapKeyPolicy<JsonValue> {\n if (typeof prefixOptions === 'string') {\n return new PrefixKeyPolicy(prefixOptions, { makeValid: true });\n }\n return new PrefixKeyPolicy(prefixOptions.prefix, { makeValid: prefixOptions.addPrefix !== false });\n }\n}\n"]}