@fgv/ts-json 5.0.1-8 → 5.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.
- package/dist/index.browser.js +24 -0
- package/dist/index.js +27 -0
- package/dist/packlets/context/compositeJsonMap.js +100 -0
- package/dist/packlets/context/contextHelpers.js +187 -0
- package/dist/packlets/context/index.js +25 -0
- package/dist/packlets/context/jsonContext.js +38 -0
- package/dist/packlets/converters/converters.js +99 -0
- package/dist/packlets/converters/index.js +25 -0
- package/dist/packlets/converters/jsonConverter.js +299 -0
- package/dist/packlets/diff/detailedDiff.js +338 -0
- package/dist/packlets/diff/index.js +24 -0
- package/dist/packlets/diff/threeWayDiff.js +258 -0
- package/dist/packlets/diff/utils.js +59 -0
- package/dist/packlets/editor/common.js +2 -0
- package/dist/packlets/editor/index.js +29 -0
- package/dist/packlets/editor/jsonEditor.js +416 -0
- package/dist/packlets/editor/jsonEditorRule.js +50 -0
- package/dist/packlets/editor/jsonEditorState.js +175 -0
- package/dist/packlets/editor/jsonReferenceMap.js +315 -0
- package/dist/packlets/editor/rules/conditional.js +163 -0
- package/dist/packlets/editor/rules/index.js +26 -0
- package/dist/packlets/editor/rules/multivalue.js +137 -0
- package/dist/packlets/editor/rules/references.js +155 -0
- package/dist/packlets/editor/rules/templates.js +121 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +2 -0
- package/lib/index.browser.js +40 -0
- package/package.json +21 -6
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
// Browser entry point - re-exports everything from main index
|
|
23
|
+
export * from './index';
|
|
24
|
+
//# sourceMappingURL=index.browser.js.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
export * from './packlets/context';
|
|
23
|
+
export * from './packlets/converters';
|
|
24
|
+
export * from './packlets/editor';
|
|
25
|
+
import * as Diff from './packlets/diff';
|
|
26
|
+
export { Diff };
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { isJsonObject } from '@fgv/ts-json-base';
|
|
23
|
+
import { captureResult, failWithDetail, succeedWithDetail } from '@fgv/ts-utils';
|
|
24
|
+
/**
|
|
25
|
+
* A {@link CompositeJsonMap | CompositeJsonMap} presents a composed view of one or more other
|
|
26
|
+
* {@link IJsonReferenceMap | JSON reference maps}.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export class CompositeJsonMap {
|
|
30
|
+
/**
|
|
31
|
+
* The {@link IJsonReferenceMap | reference maps} from which this map is to be composed.
|
|
32
|
+
* @param maps - An array o {@link IJsonReferenceMap | IJsonReferenceMap} containing the maps
|
|
33
|
+
* from which this map is to be composed.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
constructor(maps) {
|
|
37
|
+
this._maps = maps;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new {@link CompositeJsonMap | CompositeJsonMap} from supplied
|
|
41
|
+
* {@link IJsonReferenceMap | maps}.
|
|
42
|
+
* @param maps - one or more {@link IJsonReferenceMap | object maps} to be composed.
|
|
43
|
+
*/
|
|
44
|
+
static create(maps) {
|
|
45
|
+
return captureResult(() => new CompositeJsonMap(maps));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Determine if a key might be valid for this map but does not determine
|
|
49
|
+
* if key actually exists. Allows key range to be constrained.
|
|
50
|
+
* @param key - The key to be tested.
|
|
51
|
+
* @returns `true` if the key is in the valid range, `false` otherwise.
|
|
52
|
+
*/
|
|
53
|
+
keyIsInRange(key) {
|
|
54
|
+
return this._maps.find((map) => map.keyIsInRange(key)) !== undefined;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Determines if an object with the specified key actually exists in the map.
|
|
58
|
+
* @param key - The key to be tested.
|
|
59
|
+
* @returns `true` if an object with the specified key exists, `false` otherwise.
|
|
60
|
+
*/
|
|
61
|
+
has(key) {
|
|
62
|
+
return this._maps.find((map) => map.has(key)) !== undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Gets a JSON object specified by key.
|
|
66
|
+
* @param key - The key of the object to be retrieved.
|
|
67
|
+
* @param context - An optional {@link IJsonContext | JSON Context} used to format the object.
|
|
68
|
+
* @returns `Success` with the formatted object if successful. `Failure` with detail `'unknown'`
|
|
69
|
+
* if no such object exists, or `Failure` with detail `'error'` if the object was found but
|
|
70
|
+
* could not be formatted.
|
|
71
|
+
*/
|
|
72
|
+
getJsonObject(key, context) {
|
|
73
|
+
return this.getJsonValue(key, context).onSuccess((jv) => {
|
|
74
|
+
if (!isJsonObject(jv)) {
|
|
75
|
+
return failWithDetail(`${key}: not an object`, 'error');
|
|
76
|
+
}
|
|
77
|
+
return succeedWithDetail(jv);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets a JSON value specified by key.
|
|
82
|
+
* @param key - The key of the object to be retrieved.
|
|
83
|
+
* @param context - An optional {@link IJsonContext | JSON Context} used to format the value.
|
|
84
|
+
* @returns `Success` with the formatted object if successful. `Failure` with detail `'unknown'`
|
|
85
|
+
* if no such object exists, or failure with detail `'error'` if the object was found but
|
|
86
|
+
* could not be formatted.
|
|
87
|
+
*/
|
|
88
|
+
getJsonValue(key, context) {
|
|
89
|
+
for (const map of this._maps) {
|
|
90
|
+
if (map.keyIsInRange(key)) {
|
|
91
|
+
const result = map.getJsonValue(key, context);
|
|
92
|
+
if (result.isSuccess() || result.detail === 'error') {
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return failWithDetail(`${key}: value not found`, 'unknown');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=compositeJsonMap.js.map
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { captureResult, succeed } from '@fgv/ts-utils';
|
|
23
|
+
import { CompositeJsonMap } from './compositeJsonMap';
|
|
24
|
+
import { defaultExtendVars } from './jsonContext';
|
|
25
|
+
/**
|
|
26
|
+
* Helper class for working with {@link IJsonContext | IJsonContext} objects.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export class JsonContextHelper {
|
|
30
|
+
/**
|
|
31
|
+
* Constructs a new {@link JsonContextHelper | JsonContextHelper}.
|
|
32
|
+
* @param context - The base {@link IJsonContext | IJsonContext} on
|
|
33
|
+
* which to operate.
|
|
34
|
+
*/
|
|
35
|
+
constructor(context) {
|
|
36
|
+
this._context = context;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new {@link IJsonContext | context}.
|
|
40
|
+
* @param context - The base {@link IJsonContext | IJsonContext} on
|
|
41
|
+
* which to operate.
|
|
42
|
+
* @returns `Success` with the new {@link IJsonContext | IJsonContext},
|
|
43
|
+
* or `Failure` with more information if an error occurs.
|
|
44
|
+
*/
|
|
45
|
+
static create(context) {
|
|
46
|
+
return captureResult(() => new JsonContextHelper(context));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Static helper to extend context variables for a supplied {@link IJsonContext | IJsonContext}.
|
|
50
|
+
* @param baseContext - The {@link IJsonContext | IJsonContext} to be extended, or `undefined`
|
|
51
|
+
* to start from an empty context.
|
|
52
|
+
* @param vars - Optional {@link VariableValue | variable values} to be added to the
|
|
53
|
+
* {@link IJsonContext | context}.
|
|
54
|
+
* @returns `Success` with a new {@link TemplateVars | TemplateVars} containing the variables
|
|
55
|
+
* from the base context, merged with and overridden by any that were passed in, or `Failure`
|
|
56
|
+
* with a message if an error occurs.
|
|
57
|
+
*/
|
|
58
|
+
static extendContextVars(baseContext, vars) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
if (vars && vars.length > 0) {
|
|
61
|
+
const extend = (_a = baseContext === null || baseContext === void 0 ? void 0 : baseContext.extendVars) !== null && _a !== void 0 ? _a : defaultExtendVars;
|
|
62
|
+
return extend((_b = baseContext === null || baseContext === void 0 ? void 0 : baseContext.vars) !== null && _b !== void 0 ? _b : {}, vars);
|
|
63
|
+
}
|
|
64
|
+
return succeed(baseContext === null || baseContext === void 0 ? void 0 : baseContext.vars);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Static helper to extend context references for a supplied {@link IJsonContext | IJsonContext}.
|
|
68
|
+
* @param baseContext - The {@link IJsonContext | IJsonContext} to be extended, or `undefined`
|
|
69
|
+
* to start from an empty context.
|
|
70
|
+
* @param refs - Optional {@link IJsonReferenceMap | reference maps} to be added to the
|
|
71
|
+
* {@link IJsonContext | context}.
|
|
72
|
+
* @returns `Success` with a new {@link IJsonReferenceMap | reference map} which projects
|
|
73
|
+
* the references from the base context, merged with and overridden by any that were passed in,
|
|
74
|
+
* or `Failure` with a message if an error occurs.
|
|
75
|
+
*/
|
|
76
|
+
static extendContextRefs(baseContext, refs) {
|
|
77
|
+
if (refs && refs.length > 0) {
|
|
78
|
+
const full = (baseContext === null || baseContext === void 0 ? void 0 : baseContext.refs) ? [...refs, baseContext.refs] : refs;
|
|
79
|
+
if (full.length > 1) {
|
|
80
|
+
return CompositeJsonMap.create(full);
|
|
81
|
+
}
|
|
82
|
+
return succeed(full[0]);
|
|
83
|
+
}
|
|
84
|
+
return succeed(baseContext === null || baseContext === void 0 ? void 0 : baseContext.refs);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Static helper to extend context variables and references for a supplied {@link IJsonContext | IJsonContext}.
|
|
88
|
+
* @param baseContext - The {@link IJsonContext | IJsonContext} to be extended, or `undefined`
|
|
89
|
+
* to start from an empty context.
|
|
90
|
+
* @param add - Optional initializer containing {@link VariableValue | variable values} and/or
|
|
91
|
+
* {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
|
|
92
|
+
* @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
|
|
93
|
+
* references from the base context, merged with and overridden by any that were passed in, or
|
|
94
|
+
* `Failure` with a message if an error occurs.
|
|
95
|
+
*/
|
|
96
|
+
static extendContext(baseContext, add) {
|
|
97
|
+
return JsonContextHelper.extendContextVars(baseContext, (add === null || add === void 0 ? void 0 : add.vars) || []).onSuccess((vars) => {
|
|
98
|
+
return JsonContextHelper.extendContextRefs(baseContext, (add === null || add === void 0 ? void 0 : add.refs) || []).onSuccess((refs) => {
|
|
99
|
+
if (!vars && !refs && !(baseContext === null || baseContext === void 0 ? void 0 : baseContext.extendVars)) {
|
|
100
|
+
return succeed(undefined);
|
|
101
|
+
}
|
|
102
|
+
const rtrn = { vars, refs };
|
|
103
|
+
if (baseContext === null || baseContext === void 0 ? void 0 : baseContext.extendVars) {
|
|
104
|
+
rtrn.extendVars = baseContext.extendVars;
|
|
105
|
+
}
|
|
106
|
+
return succeed(rtrn);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Static helper to merge context variables and references for a supplied {@link IJsonContext | IJsonContext}.
|
|
112
|
+
* @param baseContext - The {@link IJsonContext | IJsonContext} into which variables and references
|
|
113
|
+
* are to be merged, or `undefined` to start from an empty context.
|
|
114
|
+
* @param add - Optional initializer containing {@link VariableValue | variable values} and/or
|
|
115
|
+
* {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
|
|
116
|
+
* @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
|
|
117
|
+
* references from the base context, merged with and overridden by any that were passed in, or
|
|
118
|
+
* `Failure` with a message if an error occurs.
|
|
119
|
+
*/
|
|
120
|
+
static mergeContext(baseContext, add) {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
if (baseContext) {
|
|
123
|
+
if (add) {
|
|
124
|
+
const rtrn = {
|
|
125
|
+
vars: (_a = add.vars) !== null && _a !== void 0 ? _a : baseContext.vars,
|
|
126
|
+
refs: (_b = add.refs) !== null && _b !== void 0 ? _b : baseContext.refs
|
|
127
|
+
};
|
|
128
|
+
if (add.hasOwnProperty('extendVars')) {
|
|
129
|
+
rtrn.extendVars = add.extendVars;
|
|
130
|
+
}
|
|
131
|
+
else if (baseContext.hasOwnProperty('extendVars')) {
|
|
132
|
+
rtrn.extendVars = baseContext.extendVars;
|
|
133
|
+
}
|
|
134
|
+
return succeed(rtrn);
|
|
135
|
+
}
|
|
136
|
+
return succeed(baseContext);
|
|
137
|
+
}
|
|
138
|
+
return succeed(add);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Applies {@link JsonContextHelper.extendContextVars | extendContextVars} to the
|
|
142
|
+
* {@link IJsonContext | IJsonContext} associated with this helper.
|
|
143
|
+
* @param vars - Optional {@link VariableValue | variable values} to be added to the
|
|
144
|
+
* @returns `Success` with a new {@link TemplateVars | TemplateVars} containing the variables
|
|
145
|
+
* from the base context, merged with and overridden by any that were passed in, or `Failure`
|
|
146
|
+
* with a message if an error occurs.
|
|
147
|
+
*/
|
|
148
|
+
extendVars(vars) {
|
|
149
|
+
return JsonContextHelper.extendContextVars(this._context, vars);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Applies {@link JsonContextHelper.extendContextRefs | extendContextRefs} to the
|
|
153
|
+
* {@link IJsonContext | IJsonContext} associated with this helper.
|
|
154
|
+
* @param refs - Optional {@link IJsonReferenceMap | reference maps} to be added to the
|
|
155
|
+
* @returns `Success` with a new {@link IJsonReferenceMap | reference map} which projects
|
|
156
|
+
* the references from the base context, merged with and overridden by any that were passed in,
|
|
157
|
+
* or `Failure` with a message if an error occurs.
|
|
158
|
+
*/
|
|
159
|
+
extendRefs(refs) {
|
|
160
|
+
return JsonContextHelper.extendContextRefs(this._context, refs);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Applies static `JsonContextHelper.extendContext` to the
|
|
164
|
+
* {@link IJsonContext | IJsonContext} associated with this helper.
|
|
165
|
+
* @param add - Optional initializer containing {@link VariableValue | variable values} and/or
|
|
166
|
+
* {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
|
|
167
|
+
* @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
|
|
168
|
+
* references from the base context, merged with and overridden by any that were passed in, or
|
|
169
|
+
* `Failure` with a message if an error occurs.
|
|
170
|
+
*/
|
|
171
|
+
extendContext(add) {
|
|
172
|
+
return JsonContextHelper.extendContext(this._context, add);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Applies static `JsonContextHelper.mergeContext` to the
|
|
176
|
+
* {@link IJsonContext | IJsonContext} associated with this helper.
|
|
177
|
+
* @param add - Optional initializer containing {@link VariableValue | variable values} and/or
|
|
178
|
+
* {@link IJsonReferenceMap | reference maps} to be added to the {@link IJsonContext | context}.
|
|
179
|
+
* @returns `Success` with a new {@link IJsonContext | IJsonContext} containing the variables and
|
|
180
|
+
* references from the base context, merged with and overridden by any that were passed in, or
|
|
181
|
+
* `Failure` with a message if an error occurs.
|
|
182
|
+
*/
|
|
183
|
+
mergeContext(merge) {
|
|
184
|
+
return JsonContextHelper.mergeContext(this._context, merge);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=contextHelpers.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
export { CompositeJsonMap } from './compositeJsonMap';
|
|
23
|
+
export { JsonContextHelper } from './contextHelpers';
|
|
24
|
+
export { defaultExtendVars } from './jsonContext';
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { succeed } from '@fgv/ts-utils';
|
|
23
|
+
/**
|
|
24
|
+
* This default implementation of a {@link TemplateVarsExtendFunction | TemplateVarsExtendFunction}
|
|
25
|
+
* creates a new collection via inheritance from the supplied collection.
|
|
26
|
+
* @param base - The base {@link TemplateVars | variables} to be extended.
|
|
27
|
+
* @param values - The {@link VariableValue | values} to be added or overridden in the new variables.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export function defaultExtendVars(base, values) {
|
|
31
|
+
/* c8 ignore next 1 */
|
|
32
|
+
const rtrn = base ? Object.create(base) : {};
|
|
33
|
+
for (const v of values) {
|
|
34
|
+
rtrn[v[0]] = v[1];
|
|
35
|
+
}
|
|
36
|
+
return succeed(rtrn);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=jsonContext.js.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { ConditionalJsonConverter, JsonConverter, RichJsonConverter, TemplatedJsonConverter } from './jsonConverter';
|
|
23
|
+
/**
|
|
24
|
+
* A simple validating {@link JsonConverter | JSON converter}. Converts unknown to
|
|
25
|
+
* JSON or fails if the unknown contains any invalid JSON values.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export const json = new JsonConverter();
|
|
29
|
+
/**
|
|
30
|
+
* A simple validating {@link JsonConverter | JSON converter}. Converts unknown
|
|
31
|
+
* to a `JsonObject`, or fails if the `unknown` contains invalid
|
|
32
|
+
* JSON or is not an object.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export const jsonObject = json.object();
|
|
36
|
+
/**
|
|
37
|
+
* A simple validating {@link JsonConverter | JSON converter}. Converts `unknown` to a
|
|
38
|
+
* `JsonArray`, or fails if the unknown contains invalid JSON or is
|
|
39
|
+
* not an array.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export const jsonArray = json.array();
|
|
43
|
+
let templatedJsonDefault;
|
|
44
|
+
let conditionalJsonDefault;
|
|
45
|
+
let richJsonDefault;
|
|
46
|
+
/**
|
|
47
|
+
* Helper function which creates a new {@link JsonConverter | JsonConverter} which converts an
|
|
48
|
+
* `unknown` value to JSON, rendering any property names or string values using mustache with
|
|
49
|
+
* the supplied context. See the mustache documentation for details of mustache syntax and view.
|
|
50
|
+
* @param options - {@link TemplatedJsonConverterOptions | Options and context} for
|
|
51
|
+
* the conversion.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export function templatedJson(options) {
|
|
55
|
+
if (!options) {
|
|
56
|
+
if (!templatedJsonDefault) {
|
|
57
|
+
templatedJsonDefault = new TemplatedJsonConverter();
|
|
58
|
+
}
|
|
59
|
+
return templatedJsonDefault;
|
|
60
|
+
}
|
|
61
|
+
return new TemplatedJsonConverter(options);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
|
|
65
|
+
* supplied `unknown` to strongly-typed JSON, by first rendering any property
|
|
66
|
+
* names or string values using mustache with the supplied context, then applying
|
|
67
|
+
* multi-value property expansion and conditional flattening based on property names.
|
|
68
|
+
* @param options - {@link ConditionalJsonConverterOptions | Options and context} for
|
|
69
|
+
* the conversion.
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export function conditionalJson(options) {
|
|
73
|
+
if (!options) {
|
|
74
|
+
if (!conditionalJsonDefault) {
|
|
75
|
+
conditionalJsonDefault = new ConditionalJsonConverter();
|
|
76
|
+
}
|
|
77
|
+
return conditionalJsonDefault;
|
|
78
|
+
}
|
|
79
|
+
return new ConditionalJsonConverter(options);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
|
|
83
|
+
* supplied `unknown` to strongly-typed JSON, by first rendering any property
|
|
84
|
+
* names or string values using mustache with the supplied context, then applying
|
|
85
|
+
* multi-value property expansion and conditional flattening based on property names.
|
|
86
|
+
* @param options - {@link RichJsonConverterOptions | Options and context} for
|
|
87
|
+
* the conversion.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export function richJson(options) {
|
|
91
|
+
if (!options) {
|
|
92
|
+
if (!richJsonDefault) {
|
|
93
|
+
richJsonDefault = new RichJsonConverter();
|
|
94
|
+
}
|
|
95
|
+
return richJsonDefault;
|
|
96
|
+
}
|
|
97
|
+
return new RichJsonConverter(options);
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=converters.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import * as Converters from './converters';
|
|
23
|
+
export * from './jsonConverter';
|
|
24
|
+
export { Converters };
|
|
25
|
+
//# sourceMappingURL=index.js.map
|