@fgv/ts-json 1.9.6 → 2.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ts-json.d.ts +1826 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +42 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/context/compositeJsonMap.d.ts +60 -0
- package/lib/packlets/context/compositeJsonMap.d.ts.map +1 -0
- package/lib/packlets/context/compositeJsonMap.js +105 -0
- package/lib/packlets/context/compositeJsonMap.js.map +1 -0
- package/lib/packlets/context/contextHelpers.d.ts +116 -0
- package/lib/packlets/context/contextHelpers.d.ts.map +1 -0
- package/lib/packlets/context/contextHelpers.js +191 -0
- package/lib/packlets/context/contextHelpers.js.map +1 -0
- package/lib/packlets/context/index.d.ts +4 -0
- package/lib/packlets/context/index.d.ts.map +1 -0
- package/lib/packlets/context/index.js +31 -0
- package/lib/packlets/context/index.js.map +1 -0
- package/lib/packlets/context/jsonContext.d.ts +84 -0
- package/lib/packlets/context/jsonContext.d.ts.map +1 -0
- package/lib/packlets/context/jsonContext.js +41 -0
- package/lib/packlets/context/jsonContext.js.map +1 -0
- package/lib/packlets/converters/converters.d.ts +54 -0
- package/lib/packlets/converters/converters.d.ts.map +1 -0
- package/lib/packlets/converters/converters.js +105 -0
- package/lib/packlets/converters/converters.js.map +1 -0
- package/lib/packlets/converters/file.d.ts +83 -0
- package/lib/packlets/converters/file.d.ts.map +1 -0
- package/lib/packlets/converters/file.js +162 -0
- package/lib/packlets/converters/file.js.map +1 -0
- package/lib/packlets/converters/index.d.ts +5 -0
- package/lib/packlets/converters/index.d.ts.map +1 -0
- package/{jsonEditor → lib/packlets/converters}/index.js +10 -10
- package/lib/packlets/converters/index.js.map +1 -0
- package/lib/packlets/converters/jsonConverter.d.ts +276 -0
- package/lib/packlets/converters/jsonConverter.d.ts.map +1 -0
- package/lib/packlets/converters/jsonConverter.js +310 -0
- package/lib/packlets/converters/jsonConverter.js.map +1 -0
- package/lib/packlets/editor/common.d.ts +67 -0
- package/lib/packlets/editor/common.d.ts.map +1 -0
- package/lib/packlets/editor/common.js +3 -0
- package/lib/packlets/editor/common.js.map +1 -0
- package/lib/packlets/editor/index.d.ts +8 -0
- package/lib/packlets/editor/index.d.ts.map +1 -0
- package/lib/packlets/editor/index.js +58 -0
- package/lib/packlets/editor/index.js.map +1 -0
- package/lib/packlets/editor/jsonEditor.d.ts +155 -0
- package/lib/packlets/editor/jsonEditor.d.ts.map +1 -0
- package/lib/packlets/editor/jsonEditor.js +333 -0
- package/lib/packlets/editor/jsonEditor.js.map +1 -0
- package/lib/packlets/editor/jsonEditorRule.d.ts +64 -0
- package/lib/packlets/editor/jsonEditorRule.d.ts.map +1 -0
- package/lib/packlets/editor/jsonEditorRule.js +54 -0
- package/lib/packlets/editor/jsonEditorRule.js.map +1 -0
- package/lib/packlets/editor/jsonEditorState.d.ts +125 -0
- package/lib/packlets/editor/jsonEditorState.d.ts.map +1 -0
- package/lib/packlets/editor/jsonEditorState.js +177 -0
- package/lib/packlets/editor/jsonEditorState.js.map +1 -0
- package/lib/packlets/editor/jsonReferenceMap.d.ts +303 -0
- package/lib/packlets/editor/jsonReferenceMap.d.ts.map +1 -0
- package/lib/packlets/editor/jsonReferenceMap.js +324 -0
- package/lib/packlets/editor/jsonReferenceMap.js.map +1 -0
- package/lib/packlets/editor/rules/conditional.d.ts +107 -0
- package/lib/packlets/editor/rules/conditional.d.ts.map +1 -0
- package/lib/packlets/editor/rules/conditional.js +167 -0
- package/lib/packlets/editor/rules/conditional.js.map +1 -0
- package/{jsonEditor → lib/packlets/editor}/rules/index.d.ts +1 -0
- package/lib/packlets/editor/rules/index.d.ts.map +1 -0
- package/lib/packlets/editor/rules/index.js +42 -0
- package/lib/packlets/editor/rules/index.js.map +1 -0
- package/lib/packlets/editor/rules/multivalue.d.ts +94 -0
- package/lib/packlets/editor/rules/multivalue.d.ts.map +1 -0
- package/lib/packlets/editor/rules/multivalue.js +141 -0
- package/lib/packlets/editor/rules/multivalue.js.map +1 -0
- package/lib/packlets/editor/rules/references.d.ts +69 -0
- package/lib/packlets/editor/rules/references.d.ts.map +1 -0
- package/lib/packlets/editor/rules/references.js +160 -0
- package/lib/packlets/editor/rules/references.js.map +1 -0
- package/lib/packlets/editor/rules/templates.d.ts +74 -0
- package/lib/packlets/editor/rules/templates.d.ts.map +1 -0
- package/lib/packlets/editor/rules/templates.js +127 -0
- package/lib/packlets/editor/rules/templates.js.map +1 -0
- package/lib/packlets/json/common.d.ts +85 -0
- package/lib/packlets/json/common.d.ts.map +1 -0
- package/lib/packlets/json/common.js +123 -0
- package/lib/packlets/json/common.js.map +1 -0
- package/lib/packlets/json/index.d.ts +2 -0
- package/lib/packlets/json/index.d.ts.map +1 -0
- package/lib/packlets/json/index.js +39 -0
- package/lib/packlets/json/index.js.map +1 -0
- package/package.json +57 -49
- package/common.d.ts +0 -58
- package/common.js +0 -116
- package/compositeJsonMap.d.ts +0 -47
- package/compositeJsonMap.js +0 -97
- package/contextHelpers.d.ts +0 -21
- package/contextHelpers.js +0 -101
- package/converters.d.ts +0 -37
- package/converters.js +0 -92
- package/file.d.ts +0 -60
- package/file.js +0 -140
- package/index.d.ts +0 -10
- package/index.js +0 -62
- package/jsonContext.d.ts +0 -74
- package/jsonContext.js +0 -40
- package/jsonConverter.d.ts +0 -229
- package/jsonConverter.js +0 -292
- package/jsonEditor/common.d.ts +0 -36
- package/jsonEditor/common.js +0 -3
- package/jsonEditor/index.d.ts +0 -5
- package/jsonEditor/jsonEditor.d.ts +0 -74
- package/jsonEditor/jsonEditor.js +0 -259
- package/jsonEditor/jsonEditorRule.d.ts +0 -47
- package/jsonEditor/jsonEditorRule.js +0 -44
- package/jsonEditor/jsonEditorState.d.ts +0 -24
- package/jsonEditor/jsonEditorState.js +0 -86
- package/jsonEditor/rules/conditional.d.ts +0 -84
- package/jsonEditor/rules/conditional.js +0 -146
- package/jsonEditor/rules/index.js +0 -21
- package/jsonEditor/rules/multivalue.d.ts +0 -78
- package/jsonEditor/rules/multivalue.js +0 -129
- package/jsonEditor/rules/references.d.ts +0 -62
- package/jsonEditor/rules/references.js +0 -158
- package/jsonEditor/rules/templates.d.ts +0 -56
- package/jsonEditor/rules/templates.js +0 -115
- package/jsonReferenceMap.d.ts +0 -138
- package/jsonReferenceMap.js +0 -202
|
@@ -0,0 +1,177 @@
|
|
|
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.JsonEditorState = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const context_1 = require("../context");
|
|
27
|
+
/**
|
|
28
|
+
* Represents the internal state of a {@link Editor.JsonEditor | JsonEditor}.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
class JsonEditorState {
|
|
32
|
+
/**
|
|
33
|
+
* Constructs a new {@link Editor.JsonEditorState | JsonEditorState}.
|
|
34
|
+
* @param editor - The {@link Editor.IJsonCloneEditor | editor} to which this state
|
|
35
|
+
* applies.
|
|
36
|
+
* @param baseOptions - The {@link Editor.IJsonEditorOptions | editor options} that
|
|
37
|
+
* apply to this rule.
|
|
38
|
+
* @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used
|
|
39
|
+
* for json value conversion.
|
|
40
|
+
*/
|
|
41
|
+
constructor(editor, baseOptions, runtimeContext) {
|
|
42
|
+
/**
|
|
43
|
+
* Any deferred {@link JsonObject | objects} to be merged during finalization.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
this._deferred = [];
|
|
47
|
+
this.editor = editor;
|
|
48
|
+
this.options = JsonEditorState._getEffectiveOptions(baseOptions, runtimeContext).orThrow();
|
|
49
|
+
this._id = JsonEditorState._nextId++;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The optional {@link IJsonContext | JSON context} for this state.
|
|
53
|
+
*/
|
|
54
|
+
get context() {
|
|
55
|
+
return this.options.context;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* An array of {@link JsonObject | objects} that are deferred for merge during
|
|
59
|
+
* finalization.
|
|
60
|
+
*/
|
|
61
|
+
get deferred() {
|
|
62
|
+
return this._deferred;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
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
|
|
68
|
+
* which the the new context is to be merged.
|
|
69
|
+
* @param context - The {@link IJsonContext | JSON context} to be merged into the
|
|
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}
|
|
73
|
+
* constructed from the base options merged with the supplied context. Returns `Failure`
|
|
74
|
+
* with more information if an error occurs.
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
static _getEffectiveOptions(options, context) {
|
|
78
|
+
if (!context) {
|
|
79
|
+
return (0, ts_utils_1.succeed)(options);
|
|
80
|
+
}
|
|
81
|
+
return context_1.JsonContextHelper.mergeContext(options.context, context).onSuccess((merged) => {
|
|
82
|
+
return (0, ts_utils_1.succeed)({ context: merged, validation: options.validation });
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Adds a supplied {@link JsonObject | object} to the deferred list.
|
|
87
|
+
* @param obj - The {@link JsonObject | object} to be deferred.
|
|
88
|
+
*/
|
|
89
|
+
defer(obj) {
|
|
90
|
+
this._deferred.push(obj);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Gets a {@link TemplateVars | TemplateVars} from the context of this {@link Editor.JsonEditorState | JsonEditorState},
|
|
94
|
+
* or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default
|
|
95
|
+
* context.
|
|
96
|
+
* @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`
|
|
97
|
+
* if the current state does not have context.
|
|
98
|
+
* @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or
|
|
99
|
+
* `undefined` if no vars are found.
|
|
100
|
+
*/
|
|
101
|
+
getVars(defaultContext) {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
return (_b = (_a = this.options.context) === null || _a === void 0 ? void 0 : _a.vars) !== null && _b !== void 0 ? _b : defaultContext === null || defaultContext === void 0 ? void 0 : defaultContext.vars;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Gets an {@link IJsonReferenceMap | reference map} containing any other values
|
|
107
|
+
* referenced during the operation.
|
|
108
|
+
* @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as
|
|
109
|
+
* {@link TemplateVars | TemplateVars} if the current state does not have context.
|
|
110
|
+
* @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced
|
|
111
|
+
* during this operation.
|
|
112
|
+
*/
|
|
113
|
+
getRefs(defaultContext) {
|
|
114
|
+
var _a, _b;
|
|
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
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets the context of this {@link Editor.JsonEditorState | JsonEditorState} or an optionally
|
|
119
|
+
* supplied default context if this state has no context.
|
|
120
|
+
* @param defaultContext - The default {@link IJsonContext | JSON context} to use as default
|
|
121
|
+
* if this state has no context.
|
|
122
|
+
* @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context
|
|
123
|
+
* is available.
|
|
124
|
+
*/
|
|
125
|
+
getContext(defaultContext) {
|
|
126
|
+
return context_1.JsonContextHelper.mergeContext(defaultContext, this.options.context).orDefault();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables
|
|
130
|
+
* and references into a supplied existing context.
|
|
131
|
+
* @param baseContext - The {@link IJsonContext | IJsonContext} into which variables
|
|
132
|
+
* and references are to be merged, or `undefined` to start with a default empty context.
|
|
133
|
+
* @param add - The {@link VariableValue | variable values} and/or
|
|
134
|
+
* {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.
|
|
135
|
+
* @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.
|
|
136
|
+
*/
|
|
137
|
+
extendContext(baseContext, add) {
|
|
138
|
+
const context = this.getContext(baseContext);
|
|
139
|
+
return context_1.JsonContextHelper.extendContext(context, add);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Helper method to constructs `DetailedFailure` with appropriate details and messaging
|
|
143
|
+
* for various validation failures.
|
|
144
|
+
* @param rule - The {@link Editor.JsonEditorValidationRules | validation rule} that failed.
|
|
145
|
+
* @param message - A string message describing the failed validation.
|
|
146
|
+
* @param validation - The {@link Editor.IJsonEditorValidationOptions | validation options}
|
|
147
|
+
* in effect.
|
|
148
|
+
* @returns A `DetailedFailure` with appropriate detail and message.
|
|
149
|
+
*/
|
|
150
|
+
failValidation(rule, message, validation) {
|
|
151
|
+
let detail = 'error';
|
|
152
|
+
const effective = validation !== null && validation !== void 0 ? validation : this.options.validation;
|
|
153
|
+
switch (rule) {
|
|
154
|
+
case 'invalidPropertyName':
|
|
155
|
+
detail = effective.onInvalidPropertyName !== 'ignore' ? 'error' : 'inapplicable';
|
|
156
|
+
break;
|
|
157
|
+
case 'invalidPropertyValue':
|
|
158
|
+
detail = effective.onInvalidPropertyValue !== 'ignore' ? 'error' : 'ignore';
|
|
159
|
+
break;
|
|
160
|
+
case 'undefinedPropertyValue':
|
|
161
|
+
detail = effective.onUndefinedPropertyValue !== 'error' ? 'ignore' : 'error';
|
|
162
|
+
// istanbul ignore next
|
|
163
|
+
message = message !== null && message !== void 0 ? message : 'Cannot convert undefined to JSON';
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
// istanbul ignore next
|
|
167
|
+
return (0, ts_utils_1.failWithDetail)(message !== null && message !== void 0 ? message : rule, detail);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Static global counter used to assign each {@link Editor.JsonEditorState | JsonEditorState}
|
|
172
|
+
* a unique identifier.
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
JsonEditorState._nextId = 0;
|
|
176
|
+
exports.JsonEditorState = JsonEditorState;
|
|
177
|
+
//# sourceMappingURL=jsonEditorState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonEditorState.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorState.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAiF;AACjF,wCAA6G;AAW7G;;;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;IAC9B,CAAC;IAED;;;OAGG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;;;;;;;;;OAYG;IACO,MAAM,CAAC,oBAAoB,CACnC,OAA2B,EAC3B,OAAsB;QAEtB,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,IAAA,kBAAO,EAAC,OAAO,CAAC,CAAC;SACzB;QACD,OAAO,2BAAiB,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACnF,OAAO,IAAA,kBAAO,EAAC,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IAC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,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,uBAAuB;gBACvB,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,kCAAkC,CAAC;gBACxD,MAAM;SACT;QACD,uBAAuB;QACvB,OAAO,IAAA,yBAAc,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;;AAtLD;;;;GAIG;AACc,uBAAO,GAAW,CAAC,AAAZ,CAAa;AAN1B,0CAAe","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 { DetailedFailure, Result, failWithDetail, succeed } from '@fgv/ts-utils';\nimport { IJsonContext, IJsonReferenceMap, JsonContextHelper, TemplateVars, VariableValue } from '../context';\nimport { JsonObject } from '../json';\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 // istanbul ignore next\n message = message ?? 'Cannot convert undefined to JSON';\n break;\n }\n // istanbul ignore next\n return failWithDetail(message ?? rule, detail);\n }\n}\n"]}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { DetailedResult, Result } from '@fgv/ts-utils';
|
|
2
|
+
import { IJsonContext, IJsonReferenceMap, JsonReferenceMapFailureReason } from '../context';
|
|
3
|
+
import { JsonObject, JsonValue } from '../json';
|
|
4
|
+
import { JsonEditor } from './jsonEditor';
|
|
5
|
+
/**
|
|
6
|
+
* Options for creating a {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} object.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IReferenceMapKeyPolicyValidateOptions {
|
|
10
|
+
/**
|
|
11
|
+
* If `true`, the validator coerces keys to some valid value.
|
|
12
|
+
* If `false`, invalid keys cause an error.
|
|
13
|
+
*/
|
|
14
|
+
makeValid?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Policy object responsible for validating or correcting
|
|
18
|
+
* keys in a {@link IJsonReferenceMap | reference map}.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare class ReferenceMapKeyPolicy<T> {
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
protected readonly _defaultOptions?: IReferenceMapKeyPolicyValidateOptions;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
protected readonly _isValid: (key: string, item?: T) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Constructs a new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy}.
|
|
32
|
+
* @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options}
|
|
33
|
+
* used to construct the {@link ReferenceMapKeyPolicy}.
|
|
34
|
+
* @param isValid - An optional predicate to test a supplied key for validity.
|
|
35
|
+
*/
|
|
36
|
+
constructor(options?: IReferenceMapKeyPolicyValidateOptions, isValid?: (key: string, item?: T) => boolean);
|
|
37
|
+
/**
|
|
38
|
+
* The static default key name validation predicate rejects keys that contain
|
|
39
|
+
* mustache templates or which start with the default conditional prefix
|
|
40
|
+
* `'?'`.
|
|
41
|
+
* @param key - The key to test.
|
|
42
|
+
* @returns `true` if the key is valid, `false` otherwise.
|
|
43
|
+
*/
|
|
44
|
+
static defaultKeyPredicate(key: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Determines if a supplied key and item are valid according to the current policy.
|
|
47
|
+
* @param key - The key to be tested.
|
|
48
|
+
* @param item - The item to be tested.
|
|
49
|
+
* @returns `true` if the key and value are valid, `false` otherwise.
|
|
50
|
+
*/
|
|
51
|
+
isValid(key: string, item?: T): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Determines if a supplied key and item are valid according to the current policy.
|
|
54
|
+
* @param key - The key to be tested.
|
|
55
|
+
* @param item - The item to be tested.
|
|
56
|
+
* @returns `Success` with the key if valid, `Failure` with an error message if invalid.
|
|
57
|
+
*/
|
|
58
|
+
validate(key: string, item?: T, __options?: IReferenceMapKeyPolicyValidateOptions): Result<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Validates an array of entries using the validation rules for this policy.
|
|
61
|
+
* @param items - The array of entries to be validated.
|
|
62
|
+
* @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control
|
|
63
|
+
* validation.
|
|
64
|
+
* @returns `Success` with an array of validated entries, or `Failure` with an error message
|
|
65
|
+
* if validation fails.
|
|
66
|
+
*/
|
|
67
|
+
validateItems(items: [string, T][], options?: IReferenceMapKeyPolicyValidateOptions): Result<[string, T][]>;
|
|
68
|
+
/**
|
|
69
|
+
* Validates a `Map\<string, T\>` using the validation rules for this policy.
|
|
70
|
+
* @param items - The `Map\<string, T\>` to be validated.
|
|
71
|
+
* @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control
|
|
72
|
+
* validation.
|
|
73
|
+
* @returns `Success` with a new `Map\<string, T\>`, or `Failure` with an error message
|
|
74
|
+
* if validation fails.
|
|
75
|
+
*/
|
|
76
|
+
validateMap(map: Map<string, T>, options?: IReferenceMapKeyPolicyValidateOptions): Result<Map<string, T>>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A {@link PrefixKeyPolicy | PrefixKeyPolicy} enforces that all keys start with a supplied
|
|
80
|
+
* prefix, optionally adding the prefix as necessary.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export declare class PrefixKeyPolicy<T> extends ReferenceMapKeyPolicy<T> {
|
|
84
|
+
/**
|
|
85
|
+
* The string prefix to be enforced by this policy.
|
|
86
|
+
*/
|
|
87
|
+
readonly prefix: string;
|
|
88
|
+
/**
|
|
89
|
+
* Constructs a new {@link PrefixKeyPolicy | PrefixKeyPolicy}.
|
|
90
|
+
* @param prefix - The string prefix to be enforced or applied.
|
|
91
|
+
* @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to
|
|
92
|
+
* configure the policy.
|
|
93
|
+
*/
|
|
94
|
+
constructor(prefix: string, options?: IReferenceMapKeyPolicyValidateOptions);
|
|
95
|
+
/**
|
|
96
|
+
* Determines if a key is valid according to policy.
|
|
97
|
+
* @param key - The key to be tested.
|
|
98
|
+
* @param __item - The item to be tested.
|
|
99
|
+
* @returns `true` if the key starts with the expected prefix, `false` otherwise.
|
|
100
|
+
*/
|
|
101
|
+
isValid(key: string, __item?: T): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Determines if a key is valid according to policy, optionally coercing to a valid value by
|
|
104
|
+
* adding the required prefix.
|
|
105
|
+
* @param key - The key to be tested.
|
|
106
|
+
* @param item - The item which corresponds to the key.
|
|
107
|
+
* @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to guide
|
|
108
|
+
* validation.
|
|
109
|
+
* @returns `Success` with a valid key name if the supplied key is valid or if `makeValid` is set
|
|
110
|
+
* in the policy options. Returns `Failure` with an error message if an error occurs.
|
|
111
|
+
*/
|
|
112
|
+
validate(key: string, item?: T, options?: IReferenceMapKeyPolicyValidateOptions): Result<string>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Type representing either a `Map\<string, T\>` or a `Record\<string, T\>`.
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
export type MapOrRecord<T> = Map<string, T> | Record<string, T>;
|
|
119
|
+
/**
|
|
120
|
+
* Abstract base class with common functionality for simple
|
|
121
|
+
* {@link IJsonReferenceMap | reference map} implementations.
|
|
122
|
+
* {@link JsonValue | json values}.
|
|
123
|
+
* @public
|
|
124
|
+
*/
|
|
125
|
+
export declare abstract class SimpleJsonMapBase<T> implements IJsonReferenceMap {
|
|
126
|
+
/**
|
|
127
|
+
* The {@link ReferenceMapKeyPolicy | key policy} in effect for this map.
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
protected readonly _keyPolicy: ReferenceMapKeyPolicy<T>;
|
|
131
|
+
/**
|
|
132
|
+
* A map containing keys and values already present in this map.
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
protected readonly _values: Map<string, T>;
|
|
136
|
+
/**
|
|
137
|
+
* An optional {@link IJsonContext | IJsonContext} used for any conversions
|
|
138
|
+
* involving items in this map.
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
protected readonly _context?: IJsonContext;
|
|
142
|
+
/**
|
|
143
|
+
* Constructs a new {@link SimpleJsonMap | SimpleJsonMap}.
|
|
144
|
+
* @param values - Initial values for the map.
|
|
145
|
+
* @param context - An optional {@link IJsonContext | IJsonContext} used for any conversions
|
|
146
|
+
* involving items in this map.
|
|
147
|
+
* @param keyPolicy - The {@link ReferenceMapKeyPolicy | key policy} to use for this map.
|
|
148
|
+
* @internal
|
|
149
|
+
*/
|
|
150
|
+
protected constructor(values?: MapOrRecord<T>, context?: IJsonContext, keyPolicy?: ReferenceMapKeyPolicy<T>);
|
|
151
|
+
/**
|
|
152
|
+
* Returns a `Map\<string, T\>` derived from a supplied {@link MapOrRecord | MapOrRecord}
|
|
153
|
+
* @param values - The {@link MapOrRecord | MapOrRecord} to be returned as a map.
|
|
154
|
+
* @returns `Success` with the corresponding `Map\<string, T\>` or `Failure` with a
|
|
155
|
+
* message if an error occurs.
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
protected static _toMap<T>(values?: MapOrRecord<T>): Result<Map<string, T>>;
|
|
159
|
+
/**
|
|
160
|
+
* Determine if a key might be valid for this map but does not determine if key actually
|
|
161
|
+
* exists. Allows key range to be constrained.
|
|
162
|
+
* @param key - key to be tested
|
|
163
|
+
* @returns `true` if the key is in the valid range, `false` otherwise.
|
|
164
|
+
*/
|
|
165
|
+
keyIsInRange(key: string): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Determines if an entry with the specified key actually exists in the map.
|
|
168
|
+
* @param key - key to be tested
|
|
169
|
+
* @returns `true` if an object with the specified key exists, `false` otherwise.
|
|
170
|
+
*/
|
|
171
|
+
has(key: string): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Gets a {@link JsonObject | JSON object} specified by key.
|
|
174
|
+
* @param key - key of the object to be retrieved
|
|
175
|
+
* @param context - optional {@link IJsonContext | JSON context} used to format the
|
|
176
|
+
* returned object.
|
|
177
|
+
* @returns {@link ts-utils#Success | `Success`} with the formatted object if successful.
|
|
178
|
+
* {@link ts-utils#Failure | `Failure`} with detail 'unknown' if no such object exists,
|
|
179
|
+
* or {@link ts-utils#Failure | `Failure`} with detail 'error' if the object was found
|
|
180
|
+
* but could not be formatted.
|
|
181
|
+
*/
|
|
182
|
+
getJsonObject(key: string, context?: IJsonContext): DetailedResult<JsonObject, JsonReferenceMapFailureReason>;
|
|
183
|
+
/**
|
|
184
|
+
* Gets a {@link JsonValue | JSON value} specified by key.
|
|
185
|
+
* @param key - key of the value to be retrieved
|
|
186
|
+
* @param context - Optional {@link IJsonContext | JSON context} used to format the value
|
|
187
|
+
* @returns Success with the formatted object if successful. Failure with detail 'unknown'
|
|
188
|
+
* if no such object exists, or failure with detail 'error' if the object was found but
|
|
189
|
+
* could not be formatted.
|
|
190
|
+
*/
|
|
191
|
+
abstract getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Initialization options for a {@link SimpleJsonMap | SimpleJsonMap}.
|
|
195
|
+
* @public
|
|
196
|
+
*/
|
|
197
|
+
export interface ISimpleJsonMapOptions {
|
|
198
|
+
keyPolicy?: ReferenceMapKeyPolicy<JsonValue>;
|
|
199
|
+
editor?: JsonEditor;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* A {@link SimpleJsonMap | SimpleJsonMap } presents a view of a simple map
|
|
203
|
+
* of {@link JsonValue | JSON values}.
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
export declare class SimpleJsonMap extends SimpleJsonMapBase<JsonValue> {
|
|
207
|
+
/**
|
|
208
|
+
* @internal
|
|
209
|
+
*/
|
|
210
|
+
protected _editor?: JsonEditor;
|
|
211
|
+
/**
|
|
212
|
+
* 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}
|
|
214
|
+
* to be returned.
|
|
215
|
+
* @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.
|
|
216
|
+
* @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.
|
|
217
|
+
* @public
|
|
218
|
+
*/
|
|
219
|
+
protected constructor(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions);
|
|
220
|
+
/**
|
|
221
|
+
* 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}
|
|
223
|
+
* to be returned.
|
|
224
|
+
* @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.
|
|
225
|
+
* @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.
|
|
226
|
+
* @returns `Success` with a {@link SimpleJsonMap | SimpleJsonMap} or `Failure` with a message if
|
|
227
|
+
* an error occurs.
|
|
228
|
+
*/
|
|
229
|
+
static createSimple(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions): Result<SimpleJsonMap>;
|
|
230
|
+
/**
|
|
231
|
+
* Gets a {@link JsonValue | JSON value} specified by key.
|
|
232
|
+
* @param key - key of the value to be retrieved
|
|
233
|
+
* @param context - Optional {@link IJsonContext | JSON context} used to format the value
|
|
234
|
+
* @returns Success with the formatted object if successful. Failure with detail 'unknown'
|
|
235
|
+
* if no such object exists, or failure with detail 'error' if the object was found but
|
|
236
|
+
* could not be formatted.
|
|
237
|
+
*/
|
|
238
|
+
getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
|
|
239
|
+
/**
|
|
240
|
+
* @internal
|
|
241
|
+
*/
|
|
242
|
+
protected _clone(value: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Initialization options for a {@link PrefixedJsonMap | PrefixedJsonMap}
|
|
246
|
+
* @public
|
|
247
|
+
*/
|
|
248
|
+
export interface IKeyPrefixOptions {
|
|
249
|
+
/**
|
|
250
|
+
* Indicates whether the prefix should be added automatically as needed (default true)
|
|
251
|
+
*/
|
|
252
|
+
addPrefix?: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* The prefix to be enforced
|
|
255
|
+
*/
|
|
256
|
+
prefix: string;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* A {@link PrefixedJsonMap | PrefixedJsonMap} enforces a supplied prefix for all contained values,
|
|
260
|
+
* optionally adding the prefix as necessary (default `true`).
|
|
261
|
+
* @public
|
|
262
|
+
*/
|
|
263
|
+
export declare class PrefixedJsonMap extends SimpleJsonMap {
|
|
264
|
+
/**
|
|
265
|
+
* Constructs a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
|
|
266
|
+
* @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
|
|
268
|
+
* @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
|
|
270
|
+
* @public
|
|
271
|
+
*/
|
|
272
|
+
protected constructor(values?: MapOrRecord<JsonValue>, context?: IJsonContext, options?: ISimpleJsonMapOptions);
|
|
273
|
+
/**
|
|
274
|
+
* Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
|
|
275
|
+
* @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
|
|
277
|
+
* @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
|
|
279
|
+
* @returns `Success` with a {@link PrefixedJsonMap | PrefixedJsonMap} or `Failure` with a message
|
|
280
|
+
* if an error occurs.
|
|
281
|
+
*/
|
|
282
|
+
static createPrefixed(prefix: string, values?: MapOrRecord<JsonValue>, context?: IJsonContext, editor?: JsonEditor): Result<PrefixedJsonMap>;
|
|
283
|
+
/**
|
|
284
|
+
* Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values
|
|
285
|
+
* @param prefixOptions - A KeyPrefixOptions indicating the prefix to enforce and whether that prefix should
|
|
286
|
+
* be added automatically if necessary (default true)
|
|
287
|
+
* @param values - A string-keyed Map or record of the {@link JsonValue | JsonValue} to be returned
|
|
288
|
+
* @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
|
|
290
|
+
*/
|
|
291
|
+
static createPrefixed(prefixOptions: IKeyPrefixOptions, values?: MapOrRecord<JsonValue>, context?: IJsonContext, editor?: JsonEditor): Result<PrefixedJsonMap>;
|
|
292
|
+
/**
|
|
293
|
+
* Constructs a new {@link PrefixKeyPolicy | PrefixKeyPolicy} from a supplied prefix
|
|
294
|
+
* or set of {@link IKeyPrefixOptions | prefix options}.
|
|
295
|
+
* @param prefixOptions - The prefix or {@link IKeyPrefixOptions | prefix options} or options
|
|
296
|
+
* for the new policy.
|
|
297
|
+
* @returns A new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} which enforces the
|
|
298
|
+
* supplied prefix or options.
|
|
299
|
+
* @internal
|
|
300
|
+
*/
|
|
301
|
+
protected static _toPolicy(prefixOptions: string | IKeyPrefixOptions): ReferenceMapKeyPolicy<JsonValue>;
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=jsonReferenceMap.d.ts.map
|
|
@@ -0,0 +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,YAAY,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,SAAS,EAAgB,MAAM,SAAS,CAAC;AAC9D,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;I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