@fgv/ts-json 3.0.1-alpha.6 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +15 -0
- package/CHANGELOG.md +9 -1
- package/dist/ts-json.d.ts +154 -155
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/context/compositeJsonMap.d.ts +2 -2
- package/lib/packlets/context/compositeJsonMap.js +2 -2
- package/lib/packlets/context/compositeJsonMap.js.map +1 -1
- package/lib/packlets/context/contextHelpers.d.ts +2 -2
- package/lib/packlets/context/contextHelpers.js +2 -2
- package/lib/packlets/context/contextHelpers.js.map +1 -1
- package/lib/packlets/context/jsonContext.d.ts +5 -5
- package/lib/packlets/context/jsonContext.js.map +1 -1
- package/lib/packlets/converters/converters.d.ts +2 -2
- package/lib/packlets/converters/converters.js +2 -2
- package/lib/packlets/converters/converters.js.map +1 -1
- package/lib/packlets/converters/jsonConverter.d.ts +6 -6
- package/lib/packlets/converters/jsonConverter.js +6 -6
- package/lib/packlets/converters/jsonConverter.js.map +1 -1
- package/lib/packlets/editor/common.d.ts +6 -6
- package/lib/packlets/editor/common.js.map +1 -1
- package/lib/packlets/editor/index.d.ts +2 -2
- package/lib/packlets/editor/index.d.ts.map +1 -1
- package/lib/packlets/editor/index.js +3 -1
- package/lib/packlets/editor/index.js.map +1 -1
- package/lib/packlets/editor/jsonEditor.d.ts +24 -24
- package/lib/packlets/editor/jsonEditor.js +21 -21
- package/lib/packlets/editor/jsonEditor.js.map +1 -1
- package/lib/packlets/editor/jsonEditorRule.d.ts +17 -17
- package/lib/packlets/editor/jsonEditorRule.js +4 -4
- package/lib/packlets/editor/jsonEditorRule.js.map +1 -1
- package/lib/packlets/editor/jsonEditorState.d.ts +20 -20
- package/lib/packlets/editor/jsonEditorState.js +17 -17
- package/lib/packlets/editor/jsonEditorState.js.map +1 -1
- package/lib/packlets/editor/jsonReferenceMap.d.ts +12 -13
- package/lib/packlets/editor/jsonReferenceMap.d.ts.map +1 -1
- package/lib/packlets/editor/jsonReferenceMap.js +7 -8
- package/lib/packlets/editor/jsonReferenceMap.js.map +1 -1
- package/lib/packlets/editor/rules/conditional.d.ts +17 -17
- package/lib/packlets/editor/rules/conditional.js +12 -12
- package/lib/packlets/editor/rules/conditional.js.map +1 -1
- package/lib/packlets/editor/rules/multivalue.d.ts +13 -13
- package/lib/packlets/editor/rules/multivalue.js +11 -11
- package/lib/packlets/editor/rules/multivalue.js.map +1 -1
- package/lib/packlets/editor/rules/references.d.ts +12 -12
- package/lib/packlets/editor/rules/references.js +11 -11
- package/lib/packlets/editor/rules/references.js.map +1 -1
- package/lib/packlets/editor/rules/templates.d.ts +14 -14
- package/lib/packlets/editor/rules/templates.js +12 -12
- package/lib/packlets/editor/rules/templates.js.map +1 -1
- package/package.json +14 -14
|
@@ -4,7 +4,7 @@ import { IJsonEditorOptions, JsonEditFailureReason, JsonPropertyEditFailureReaso
|
|
|
4
4
|
import { JsonEditorRuleBase } from '../jsonEditorRule';
|
|
5
5
|
import { JsonEditorState } from '../jsonEditorState';
|
|
6
6
|
/**
|
|
7
|
-
* Configuration options for the {@link
|
|
7
|
+
* Configuration options for the {@link EditorRules.TemplatedJsonEditorRule | Templated JSON editor rule}.
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
10
|
export interface ITemplatedJsonRuleOptions extends Partial<IJsonEditorOptions> {
|
|
@@ -18,34 +18,34 @@ export interface ITemplatedJsonRuleOptions extends Partial<IJsonEditorOptions> {
|
|
|
18
18
|
useValueTemplates?: boolean;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* The {@link
|
|
21
|
+
* The {@link EditorRules.TemplatedJsonEditorRule | Templated JSON editor rule} applies mustache rendering as
|
|
22
22
|
* appropriate to any keys or values in the object being edited.
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
25
|
export declare class TemplatedJsonEditorRule extends JsonEditorRuleBase {
|
|
26
26
|
/**
|
|
27
|
-
* Fully-resolved {@link
|
|
27
|
+
* Fully-resolved {@link EditorRules.ITemplatedJsonRuleOptions | configuration options} for this rule.
|
|
28
28
|
* @public
|
|
29
29
|
*/
|
|
30
30
|
protected _options?: ITemplatedJsonRuleOptions;
|
|
31
31
|
/**
|
|
32
|
-
* Creates a new {@link
|
|
33
|
-
* @param options - Optional {@link
|
|
32
|
+
* Creates a new {@link EditorRules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.
|
|
33
|
+
* @param options - Optional {@link EditorRules.ITemplatedJsonRuleOptions | configuration options}
|
|
34
34
|
* for this rule.
|
|
35
35
|
*/
|
|
36
36
|
constructor(options?: ITemplatedJsonRuleOptions);
|
|
37
37
|
/**
|
|
38
|
-
* Creates a new {@link
|
|
39
|
-
* @param options - Optional {@link
|
|
38
|
+
* Creates a new {@link EditorRules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.
|
|
39
|
+
* @param options - Optional {@link EditorRules.ITemplatedJsonRuleOptions | configuration options}
|
|
40
40
|
* for this rule.
|
|
41
41
|
*/
|
|
42
42
|
static create(options?: ITemplatedJsonRuleOptions): Result<TemplatedJsonEditorRule>;
|
|
43
43
|
/**
|
|
44
44
|
* Evaluates a property name for template rendering.
|
|
45
45
|
* @param key - The key of the property to be considered.
|
|
46
|
-
* @param value - The
|
|
47
|
-
* @param state - The {@link
|
|
48
|
-
* @returns `Success` with detail `'edited'` and an
|
|
46
|
+
* @param value - The `JsonValue` of the property to be considered.
|
|
47
|
+
* @param state - The {@link JsonEditorState | editor state} for the object being edited.
|
|
48
|
+
* @returns `Success` with detail `'edited'` and an `JsonObject` to
|
|
49
49
|
* be flattened and merged if the key contained a template. Returns `Failure` with detail `'error'`
|
|
50
50
|
* if an error occurred or with detail `'inapplicable'` if the property key does not contain
|
|
51
51
|
* a template or if name rendering is disabled.
|
|
@@ -53,17 +53,17 @@ export declare class TemplatedJsonEditorRule extends JsonEditorRuleBase {
|
|
|
53
53
|
editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
|
|
54
54
|
/**
|
|
55
55
|
* Evaluates a property, array or literal value for template rendering.
|
|
56
|
-
* @param value - The
|
|
57
|
-
* @param state - The {@link
|
|
56
|
+
* @param value - The `JsonValue` to be edited.
|
|
57
|
+
* @param state - The {@link JsonEditorState | editor state} for the object being edited.
|
|
58
58
|
* @returns `Success` with detail `'edited'` if the value contained a template and was edited.
|
|
59
59
|
* Returns `Failure` with `'ignore'` if the rendered value should be ignored, with `'error'` if
|
|
60
60
|
* an error occurs, or with `'inapplicable'` if the value was not a string with a template.
|
|
61
61
|
*/
|
|
62
62
|
editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
63
63
|
/**
|
|
64
|
-
* Renders a single template string for a supplied {@link
|
|
64
|
+
* Renders a single template string for a supplied {@link JsonEditorState | editor state}.
|
|
65
65
|
* @param template - The mustache template to be rendered.
|
|
66
|
-
* @param state - The {@link
|
|
66
|
+
* @param state - The {@link JsonEditorState | editor state} used to render the template.
|
|
67
67
|
* @returns `Success` if the template is rendered. Returns `Failure` with detail `'error'` if the
|
|
68
68
|
* template could not be rendered (e.g. due to syntax errors) or with detail `'inapplicable'` if the
|
|
69
69
|
* string is not a template.
|
|
@@ -29,14 +29,14 @@ const ts_utils_1 = require("@fgv/ts-utils");
|
|
|
29
29
|
const jsonEditorRule_1 = require("../jsonEditorRule");
|
|
30
30
|
const mustache_1 = __importDefault(require("mustache"));
|
|
31
31
|
/**
|
|
32
|
-
* The {@link
|
|
32
|
+
* The {@link EditorRules.TemplatedJsonEditorRule | Templated JSON editor rule} applies mustache rendering as
|
|
33
33
|
* appropriate to any keys or values in the object being edited.
|
|
34
34
|
* @public
|
|
35
35
|
*/
|
|
36
36
|
class TemplatedJsonEditorRule extends jsonEditorRule_1.JsonEditorRuleBase {
|
|
37
37
|
/**
|
|
38
|
-
* Creates a new {@link
|
|
39
|
-
* @param options - Optional {@link
|
|
38
|
+
* Creates a new {@link EditorRules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.
|
|
39
|
+
* @param options - Optional {@link EditorRules.ITemplatedJsonRuleOptions | configuration options}
|
|
40
40
|
* for this rule.
|
|
41
41
|
*/
|
|
42
42
|
constructor(options) {
|
|
@@ -44,8 +44,8 @@ class TemplatedJsonEditorRule extends jsonEditorRule_1.JsonEditorRuleBase {
|
|
|
44
44
|
this._options = options;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* Creates a new {@link
|
|
48
|
-
* @param options - Optional {@link
|
|
47
|
+
* Creates a new {@link EditorRules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.
|
|
48
|
+
* @param options - Optional {@link EditorRules.ITemplatedJsonRuleOptions | configuration options}
|
|
49
49
|
* for this rule.
|
|
50
50
|
*/
|
|
51
51
|
static create(options) {
|
|
@@ -54,9 +54,9 @@ class TemplatedJsonEditorRule extends jsonEditorRule_1.JsonEditorRuleBase {
|
|
|
54
54
|
/**
|
|
55
55
|
* Evaluates a property name for template rendering.
|
|
56
56
|
* @param key - The key of the property to be considered.
|
|
57
|
-
* @param value - The
|
|
58
|
-
* @param state - The {@link
|
|
59
|
-
* @returns `Success` with detail `'edited'` and an
|
|
57
|
+
* @param value - The `JsonValue` of the property to be considered.
|
|
58
|
+
* @param state - The {@link JsonEditorState | editor state} for the object being edited.
|
|
59
|
+
* @returns `Success` with detail `'edited'` and an `JsonObject` to
|
|
60
60
|
* be flattened and merged if the key contained a template. Returns `Failure` with detail `'error'`
|
|
61
61
|
* if an error occurred or with detail `'inapplicable'` if the property key does not contain
|
|
62
62
|
* a template or if name rendering is disabled.
|
|
@@ -84,8 +84,8 @@ class TemplatedJsonEditorRule extends jsonEditorRule_1.JsonEditorRuleBase {
|
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* Evaluates a property, array or literal value for template rendering.
|
|
87
|
-
* @param value - The
|
|
88
|
-
* @param state - The {@link
|
|
87
|
+
* @param value - The `JsonValue` to be edited.
|
|
88
|
+
* @param state - The {@link JsonEditorState | editor state} for the object being edited.
|
|
89
89
|
* @returns `Success` with detail `'edited'` if the value contained a template and was edited.
|
|
90
90
|
* Returns `Failure` with `'ignore'` if the rendered value should be ignored, with `'error'` if
|
|
91
91
|
* an error occurs, or with `'inapplicable'` if the value was not a string with a template.
|
|
@@ -106,9 +106,9 @@ class TemplatedJsonEditorRule extends jsonEditorRule_1.JsonEditorRuleBase {
|
|
|
106
106
|
return (0, ts_utils_1.failWithDetail)('inapplicable', 'inapplicable');
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
|
-
* Renders a single template string for a supplied {@link
|
|
109
|
+
* Renders a single template string for a supplied {@link JsonEditorState | editor state}.
|
|
110
110
|
* @param template - The mustache template to be rendered.
|
|
111
|
-
* @param state - The {@link
|
|
111
|
+
* @param state - The {@link JsonEditorState | editor state} used to render the template.
|
|
112
112
|
* @returns `Success` if the template is rendered. Returns `Failure` with detail `'error'` if the
|
|
113
113
|
* template could not be rendered (e.g. due to syntax errors) or with detail `'inapplicable'` if the
|
|
114
114
|
* string is not a template.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../../src/packlets/editor/rules/templates.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;AAGH,4CAAyG;AAEzG,sDAAuD;AAGvD,wDAAgC;AAiBhC;;;;GAIG;AACH,MAAa,uBAAwB,SAAQ,mCAAkB;IAO7D;;;;OAIG;IACH,YAAmB,OAAmC;QACpD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,OAAmC;QACtD,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC,CAAC;IACnE,CAAC;IAED;;;;;;;;;OASG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,EAAE,CAAC;YACpG,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACrE,OAAO,IAAA,4BAAiB,EAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;YAEH,IAAI,YAAY,CAAC,SAAS,EAAE,IAAI,YAAY,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;gBAChE,MAAM,OAAO,GAAG,wBAAwB,YAAY,CAAC,OAAO,EAAE,CAAC;gBAC/D,oBAAoB;gBACpB,OAAO,KAAK,CAAC,cAAc,CAAC,sBAAsB,EAAE,OAAO,EAAE,MAAA,IAAI,CAAC,QAAQ,0CAAE,UAAU,CAAC,CAAC;YAC1F,CAAC;YACD,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IAED;;;;;;;;OAQG;IACO,OAAO,CAAC,QAAgB,EAAE,KAAsB;;QACxD,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAA,IAAI,CAAC,QAAQ,0CAAE,OAAO,CAAC,CAAC;QACnD,IAAI,IAAI,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACpC,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,kBAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5F,CAAC;QACD,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;CACF;AA3GD,0DA2GC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonObject, JsonValue } from '@fgv/ts-json-base';\nimport { DetailedResult, Result, captureResult, failWithDetail, succeedWithDetail } from '@fgv/ts-utils';\nimport { IJsonEditorOptions, JsonEditFailureReason, JsonPropertyEditFailureReason } from '../common';\nimport { JsonEditorRuleBase } from '../jsonEditorRule';\nimport { JsonEditorState } from '../jsonEditorState';\n\nimport Mustache from 'mustache';\n\n/**\n * Configuration options for the {@link
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../../src/packlets/editor/rules/templates.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;AAGH,4CAAyG;AAEzG,sDAAuD;AAGvD,wDAAgC;AAiBhC;;;;GAIG;AACH,MAAa,uBAAwB,SAAQ,mCAAkB;IAO7D;;;;OAIG;IACH,YAAmB,OAAmC;QACpD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,OAAmC;QACtD,OAAO,IAAA,w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* Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonObject, JsonValue } from '@fgv/ts-json-base';\nimport { DetailedResult, Result, captureResult, failWithDetail, succeedWithDetail } from '@fgv/ts-utils';\nimport { IJsonEditorOptions, JsonEditFailureReason, JsonPropertyEditFailureReason } from '../common';\nimport { JsonEditorRuleBase } from '../jsonEditorRule';\nimport { JsonEditorState } from '../jsonEditorState';\n\nimport Mustache from 'mustache';\n\n/**\n * Configuration options for the {@link EditorRules.TemplatedJsonEditorRule | Templated JSON editor rule}.\n * @public\n */\nexport interface ITemplatedJsonRuleOptions extends Partial<IJsonEditorOptions> {\n /**\n * If `true` (default) then templates in property names are rendered\n */\n useNameTemplates?: boolean;\n /**\n * If `true` (default) then templates in property values are rendered\n */\n useValueTemplates?: boolean;\n}\n\n/**\n * The {@link EditorRules.TemplatedJsonEditorRule | Templated JSON editor rule} applies mustache rendering as\n * appropriate to any keys or values in the object being edited.\n * @public\n */\nexport class TemplatedJsonEditorRule extends JsonEditorRuleBase {\n /**\n * Fully-resolved {@link EditorRules.ITemplatedJsonRuleOptions | configuration options} for this rule.\n * @public\n */\n protected _options?: ITemplatedJsonRuleOptions;\n\n /**\n * Creates a new {@link EditorRules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.\n * @param options - Optional {@link EditorRules.ITemplatedJsonRuleOptions | configuration options}\n * for this rule.\n */\n public constructor(options?: ITemplatedJsonRuleOptions) {\n super();\n this._options = options;\n }\n\n /**\n * Creates a new {@link EditorRules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.\n * @param options - Optional {@link EditorRules.ITemplatedJsonRuleOptions | configuration options}\n * for this rule.\n */\n public static create(options?: ITemplatedJsonRuleOptions): Result<TemplatedJsonEditorRule> {\n return captureResult(() => new TemplatedJsonEditorRule(options));\n }\n\n /**\n * Evaluates a property name for template rendering.\n * @param key - The key of the property to be considered.\n * @param value - The `JsonValue` of the property to be considered.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n * @returns `Success` with detail `'edited'` and an `JsonObject` to\n * be flattened and merged if the key contained a template. Returns `Failure` with detail `'error'`\n * if an error occurred or with detail `'inapplicable'` if the property key does not contain\n * a template or if name rendering is disabled.\n */\n public editProperty(\n key: string,\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason> {\n /* c8 ignore next */\n const validation = this._options?.validation;\n\n if (this._options?.useNameTemplates !== false) {\n const result = this._render(key, state).onSuccess((newKey) => {\n if (newKey.length < 1) {\n return state.failValidation('invalidPropertyName', `Template \"${key}\" renders empty name.`);\n }\n\n const rtrn: JsonObject = {};\n rtrn[newKey] = value;\n return succeedWithDetail<JsonObject, JsonEditFailureReason>(rtrn, 'edited');\n });\n\n if (result.isFailure() && result.detail === 'error') {\n const message = `Cannot render name ${key}: ${result.message}`;\n return state.failValidation('invalidPropertyName', message, validation);\n }\n return result;\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n * Evaluates a property, array or literal value for template rendering.\n * @param value - The `JsonValue` to be edited.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n * @returns `Success` with detail `'edited'` if the value contained a template and was edited.\n * Returns `Failure` with `'ignore'` if the rendered value should be ignored, with `'error'` if\n * an error occurs, or with `'inapplicable'` if the value was not a string with a template.\n */\n public editValue(\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonValue, JsonEditFailureReason> {\n if (this._options?.useValueTemplates !== false && typeof value === 'string' && value.includes('{{')) {\n const renderResult = this._render(value, state).onSuccess((newValue) => {\n return succeedWithDetail(newValue, 'edited');\n });\n\n if (renderResult.isFailure() && renderResult.detail === 'error') {\n const message = `Cannot render value: ${renderResult.message}`;\n /* c8 ignore next */\n return state.failValidation('invalidPropertyValue', message, this._options?.validation);\n }\n return renderResult;\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n * Renders a single template string for a supplied {@link JsonEditorState | editor state}.\n * @param template - The mustache template to be rendered.\n * @param state - The {@link JsonEditorState | editor state} used to render the template.\n * @returns `Success` if the template is rendered. Returns `Failure` with detail `'error'` if the\n * template could not be rendered (e.g. due to syntax errors) or with detail `'inapplicable'` if the\n * string is not a template.\n * @internal\n */\n protected _render(template: string, state: JsonEditorState): DetailedResult<string, JsonEditFailureReason> {\n const vars = state.getVars(this._options?.context);\n if (vars && template.includes('{{')) {\n return captureResult(() => Mustache.render(template, vars)).withDetail('error', 'edited');\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-json",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Typescript utilities for working with JSON",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-json.d.ts",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-json#readme",
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@fgv/ts-utils": "
|
|
20
|
-
"@fgv/ts-utils-jest": "
|
|
19
|
+
"@fgv/ts-utils": "4.0.0",
|
|
20
|
+
"@fgv/ts-utils-jest": "4.0.0",
|
|
21
21
|
"@types/jest": "^29.5.12",
|
|
22
22
|
"@types/mustache": "^4.2.5",
|
|
23
|
-
"@types/node": "^20.11
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
25
|
-
"@typescript-eslint/parser": "^7.
|
|
23
|
+
"@types/node": "^20.12.11",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
|
25
|
+
"@typescript-eslint/parser": "^7.9.0",
|
|
26
26
|
"eslint": "^8.57.0",
|
|
27
27
|
"eslint-config-standard": "^17.1.0",
|
|
28
28
|
"eslint-plugin-import": "^2.29.1",
|
|
@@ -31,21 +31,21 @@
|
|
|
31
31
|
"jest": "^29.7.0",
|
|
32
32
|
"jest-extended": "^4.0.2",
|
|
33
33
|
"mustache": "^4.2.0",
|
|
34
|
-
"rimraf": "^5.0.
|
|
34
|
+
"rimraf": "^5.0.7",
|
|
35
35
|
"ts-jest": "^29.1.2",
|
|
36
36
|
"ts-node": "^10.9.2",
|
|
37
|
-
"typescript": "^5.
|
|
37
|
+
"typescript": "^5.4.5",
|
|
38
38
|
"eslint-plugin-n": "^16.6.2",
|
|
39
|
-
"@rushstack/heft-node-rig": "~2.
|
|
40
|
-
"@rushstack/heft": "~0.
|
|
39
|
+
"@rushstack/heft-node-rig": "~2.6.3",
|
|
40
|
+
"@rushstack/heft": "~0.66.6",
|
|
41
41
|
"heft-jest": "~1.0.2",
|
|
42
42
|
"@types/heft-jest": "1.0.6",
|
|
43
|
-
"@microsoft/api-documenter": "^7.
|
|
44
|
-
"@fgv/ts-json-base": "
|
|
43
|
+
"@microsoft/api-documenter": "^7.24.5",
|
|
44
|
+
"@fgv/ts-json-base": "4.0.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@fgv/ts-utils": "
|
|
48
|
-
"@fgv/ts-json-base": "
|
|
47
|
+
"@fgv/ts-utils": "4.0.0",
|
|
48
|
+
"@fgv/ts-json-base": "4.0.0",
|
|
49
49
|
"mustache": "^4.2.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|