@fgv/ts-json 4.0.2 → 4.2.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 +24 -0
- package/CHANGELOG.md +18 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/context/jsonContext.d.ts.map +1 -1
- package/lib/packlets/context/jsonContext.js +2 -2
- package/lib/packlets/context/jsonContext.js.map +1 -1
- package/lib/packlets/converters/converters.js +4 -4
- package/lib/packlets/converters/converters.js.map +1 -1
- package/lib/packlets/converters/index.js +17 -7
- package/lib/packlets/converters/index.js.map +1 -1
- package/lib/packlets/converters/jsonConverter.js +4 -4
- package/lib/packlets/converters/jsonConverter.js.map +1 -1
- package/lib/packlets/editor/index.js +17 -7
- package/lib/packlets/editor/index.js.map +1 -1
- package/lib/packlets/editor/jsonEditorState.d.ts.map +1 -1
- package/lib/packlets/editor/jsonEditorState.js +2 -0
- package/lib/packlets/editor/jsonEditorState.js.map +1 -1
- package/lib/packlets/editor/rules/templates.d.ts.map +1 -1
- package/lib/packlets/editor/rules/templates.js +3 -2
- package/lib/packlets/editor/rules/templates.js.map +1 -1
- package/package.json +18 -19
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-json",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "4.2.0",
|
|
6
|
+
"tag": "@fgv/ts-json_v4.2.0",
|
|
7
|
+
"date": "Mon, 20 Jan 2025 09:46:53 GMT",
|
|
8
|
+
"comments": {}
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "4.1.0",
|
|
12
|
+
"tag": "@fgv/ts-json_v4.1.0",
|
|
13
|
+
"date": "Thu, 09 Jan 2025 05:33:39 GMT",
|
|
14
|
+
"comments": {
|
|
15
|
+
"none": [
|
|
16
|
+
{
|
|
17
|
+
"comment": "update dependencies"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"version": "4.0.2",
|
|
24
|
+
"tag": "@fgv/ts-json_v4.0.2",
|
|
25
|
+
"date": "Tue, 14 May 2024 14:45:53 GMT",
|
|
26
|
+
"comments": {}
|
|
27
|
+
},
|
|
4
28
|
{
|
|
5
29
|
"version": "4.0.1",
|
|
6
30
|
"tag": "@fgv/ts-json_v4.0.1",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
# Change Log - @fgv/ts-json
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 20 Jan 2025 09:46:53 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.2.0
|
|
6
|
+
Mon, 20 Jan 2025 09:46:53 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.1.0
|
|
11
|
+
Thu, 09 Jan 2025 05:33:39 GMT
|
|
12
|
+
|
|
13
|
+
### Updates
|
|
14
|
+
|
|
15
|
+
- update dependencies
|
|
16
|
+
|
|
17
|
+
## 4.0.2
|
|
18
|
+
Tue, 14 May 2024 14:45:53 GMT
|
|
19
|
+
|
|
20
|
+
_Version update only_
|
|
4
21
|
|
|
5
22
|
## 4.0.1
|
|
6
23
|
Tue, 14 May 2024 05:02:20 GMT
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonContext.d.ts","sourceRoot":"","sources":["../../../src/packlets/context/jsonContext.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,EAAW,MAAM,eAAe,CAAC;AAEhE;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;A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KG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAEnC;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAE1B;;;;;;;;OAQG;IAEH,aAAa,CACX,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,YAAY,GACrB,cAAc,CAAC,UAAU,EAAE,6BAA6B,CAAC,CAAC;IAE7D;;;;;;;OAOG;IAEH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,SAAS,EAAE,6BAA6B,CAAC,CAAC;CAC7G;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,UAAU,CAAC,EAAE,0BAA0B,CAAC;CACzC"}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.defaultExtendVars =
|
|
24
|
+
exports.defaultExtendVars = defaultExtendVars;
|
|
25
25
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
26
|
/**
|
|
27
27
|
* This default implementation of a {@link TemplateVarsExtendFunction | TemplateVarsExtendFunction}
|
|
@@ -31,11 +31,11 @@ const ts_utils_1 = require("@fgv/ts-utils");
|
|
|
31
31
|
* @public
|
|
32
32
|
*/
|
|
33
33
|
function defaultExtendVars(base, values) {
|
|
34
|
+
/* c8 ignore next 1 */
|
|
34
35
|
const rtrn = base ? Object.create(base) : {};
|
|
35
36
|
for (const v of values) {
|
|
36
37
|
rtrn[v[0]] = v[1];
|
|
37
38
|
}
|
|
38
39
|
return (0, ts_utils_1.succeed)(rtrn);
|
|
39
40
|
}
|
|
40
|
-
exports.defaultExtendVars = defaultExtendVars;
|
|
41
41
|
//# sourceMappingURL=jsonContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonContext.js","sourceRoot":"","sources":["../../../src/packlets/context/jsonContext.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG
|
|
1
|
+
{"version":3,"file":"jsonContext.js","sourceRoot":"","sources":["../../../src/packlets/context/jsonContext.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAoCH,8CAUC;AA3CD,4CAAgE;AA0BhE;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,IAA8B,EAC9B,MAAuB;IAEvB,sBAAsB;IACtB,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7C,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC;AACvB,CAAC","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, succeed } from '@fgv/ts-utils';\n\n/**\n * Collection of variables used for template replacement in a JSON edit or\n * conversion.\n * @public\n */\nexport type TemplateVars = Record<string, unknown>;\n\n/**\n * Describes one value in a {@link TemplateVars | TemplateVars} collection of\n * variables.\n * @public\n */\nexport type VariableValue = [string, unknown];\n\n/**\n * Function used to create a new collection of {@link TemplateVars | TemplateVars} with\n * one or more new or changed values.\n * @public\n */\nexport type TemplateVarsExtendFunction = (\n base: TemplateVars | undefined,\n values: VariableValue[]\n) => Result<TemplateVars | undefined>;\n\n/**\n * This default implementation of a {@link TemplateVarsExtendFunction | TemplateVarsExtendFunction}\n * creates a new collection via inheritance from the supplied collection.\n * @param base - The base {@link TemplateVars | variables} to be extended.\n * @param values - The {@link VariableValue | values} to be added or overridden in the new variables.\n * @public\n */\nexport function defaultExtendVars(\n base: TemplateVars | undefined,\n values: VariableValue[]\n): Result<TemplateVars | undefined> {\n /* c8 ignore next 1 */\n const rtrn = base ? Object.create(base) : {};\n for (const v of values) {\n rtrn[v[0]] = v[1];\n }\n return succeed(rtrn);\n}\n\n/**\n * Failure reason for {@link IJsonReferenceMap | IJsonReferenceMap} lookup, where `'unknown'`\n * means that the object is not present in the map and `'error'` means\n * that an error occurred while retrieving or converting it.\n * @public\n */\nexport type JsonReferenceMapFailureReason = 'unknown' | 'error';\n\n/**\n * Interface for a simple map that returns named `JsonValue` values with templating,\n * conditional logic, and external reference lookups applied using an optionally supplied context.\n * @public\n */\nexport interface IJsonReferenceMap {\n /**\n * Determine if a key might be valid for this map but does not determine if key actually\n * exists. Allows key range to be constrained.\n * @param key - The key to be tested.\n * @returns `true` if the key is in the valid range, `false` otherwise.\n */\n keyIsInRange(key: string): boolean;\n\n /**\n * Determines if an object with the specified key actually exists in the map.\n * @param key - The key to be tested.\n * @returns `true` if an object with the specified key exists, `false` otherwise.\n */\n has(key: string): boolean;\n\n /**\n * Gets a `JsonObject` specified by key.\n * @param key - The key of the object to be retrieved.\n * @param context - Optional {@link IJsonContext | IJsonContext} used to construct\n * the object.\n * @returns `Success` with the formatted JsonObject if successful. `Failure`\n * with detail `'unknown'` if no such object exists, or `Failure` with detail `'error'` if\n * the object was found but could not be formatted.\n */\n // eslint-disable-next-line no-use-before-define\n getJsonObject(\n key: string,\n context?: IJsonContext\n ): DetailedResult<JsonObject, JsonReferenceMapFailureReason>;\n\n /**\n * Gets a `JsonValue` specified by key.\n * @param key - The key of the object to be retrieved.\n * @param context - Optional {@link IJsonContext | JSON Context} used to format the value\n * @returns `Success` with the formatted `JsonValue` if successful. `Failure`\n * with detail `'unknown'` if no such object exists, or `Failure` with detail `'error'` if\n * the object was found but could not be formatted.\n */\n // eslint-disable-next-line no-use-before-define\n getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;\n}\n\n/**\n * Context used to convert or edit JSON objects.\n * @public\n */\nexport interface IJsonContext {\n vars?: TemplateVars;\n refs?: IJsonReferenceMap;\n extendVars?: TemplateVarsExtendFunction;\n}\n"]}
|
|
@@ -21,7 +21,10 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.
|
|
24
|
+
exports.jsonArray = exports.jsonObject = exports.json = void 0;
|
|
25
|
+
exports.templatedJson = templatedJson;
|
|
26
|
+
exports.conditionalJson = conditionalJson;
|
|
27
|
+
exports.richJson = richJson;
|
|
25
28
|
const jsonConverter_1 = require("./jsonConverter");
|
|
26
29
|
/**
|
|
27
30
|
* A simple validating {@link JsonConverter | JSON converter}. Converts unknown to
|
|
@@ -63,7 +66,6 @@ function templatedJson(options) {
|
|
|
63
66
|
}
|
|
64
67
|
return new jsonConverter_1.TemplatedJsonConverter(options);
|
|
65
68
|
}
|
|
66
|
-
exports.templatedJson = templatedJson;
|
|
67
69
|
/**
|
|
68
70
|
* Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
|
|
69
71
|
* supplied `unknown` to strongly-typed JSON, by first rendering any property
|
|
@@ -82,7 +84,6 @@ function conditionalJson(options) {
|
|
|
82
84
|
}
|
|
83
85
|
return new jsonConverter_1.ConditionalJsonConverter(options);
|
|
84
86
|
}
|
|
85
|
-
exports.conditionalJson = conditionalJson;
|
|
86
87
|
/**
|
|
87
88
|
* Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
|
|
88
89
|
* supplied `unknown` to strongly-typed JSON, by first rendering any property
|
|
@@ -101,5 +102,4 @@ function richJson(options) {
|
|
|
101
102
|
}
|
|
102
103
|
return new jsonConverter_1.RichJsonConverter(options);
|
|
103
104
|
}
|
|
104
|
-
exports.richJson = richJson;
|
|
105
105
|
//# sourceMappingURL=converters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converters.js","sourceRoot":"","sources":["../../../src/packlets/converters/converters.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;
|
|
1
|
+
{"version":3,"file":"converters.js","sourceRoot":"","sources":["../../../src/packlets/converters/converters.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAkDH,sCAQC;AAWD,0CAQC;AAWD,4BAQC;AA3FD,mDAQyB;AAEzB;;;;GAIG;AACU,QAAA,IAAI,GAAkB,IAAI,6BAAa,EAAE,CAAC;AAEvD;;;;;GAKG;AACU,QAAA,UAAU,GAAwC,YAAI,CAAC,MAAM,EAAE,CAAC;AAE7E;;;;;GAKG;AACU,QAAA,SAAS,GAAuC,YAAI,CAAC,KAAK,EAAE,CAAC;AAE1E,IAAI,oBAA+C,CAAC;AACpD,IAAI,sBAAiD,CAAC;AACtD,IAAI,eAA0C,CAAC;AAE/C;;;;;;;GAOG;AACH,SAAgB,aAAa,CAAC,OAAgD;IAC5E,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC1B,oBAAoB,GAAG,IAAI,sCAAsB,EAAE,CAAC;QACtD,CAAC;QACD,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IACD,OAAO,IAAI,sCAAsB,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,OAAkD;IAChF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAC5B,sBAAsB,GAAG,IAAI,wCAAwB,EAAE,CAAC;QAC1D,CAAC;QACD,OAAO,sBAAsB,CAAC;IAChC,CAAC;IACD,OAAO,IAAI,wCAAwB,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,QAAQ,CAAC,OAA2C;IAClE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,eAAe,GAAG,IAAI,iCAAiB,EAAE,CAAC;QAC5C,CAAC;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,iCAAiB,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC","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 { JsonArray, JsonObject } from '@fgv/ts-json-base';\nimport { Converter } from '@fgv/ts-utils';\nimport { IJsonContext } from '../context';\nimport {\n ConditionalJsonConverter,\n ConditionalJsonConverterOptions,\n JsonConverter,\n RichJsonConverter,\n RichJsonConverterOptions,\n TemplatedJsonConverter,\n TemplatedJsonConverterOptions\n} from './jsonConverter';\n\n/**\n * A simple validating {@link JsonConverter | JSON converter}. Converts unknown to\n * JSON or fails if the unknown contains any invalid JSON values.\n * @public\n */\nexport const json: JsonConverter = new JsonConverter();\n\n/**\n * A simple validating {@link JsonConverter | JSON converter}. Converts unknown\n * to a `JsonObject`, or fails if the `unknown` contains invalid\n * JSON or is not an object.\n * @public\n */\nexport const jsonObject: Converter<JsonObject, IJsonContext> = json.object();\n\n/**\n * A simple validating {@link JsonConverter | JSON converter}. Converts `unknown` to a\n * `JsonArray`, or fails if the unknown contains invalid JSON or is\n * not an array.\n * @public\n */\nexport const jsonArray: Converter<JsonArray, IJsonContext> = json.array();\n\nlet templatedJsonDefault: JsonConverter | undefined;\nlet conditionalJsonDefault: JsonConverter | undefined;\nlet richJsonDefault: JsonConverter | undefined;\n\n/**\n * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts an\n * `unknown` value to JSON, rendering any property names or string values using mustache with\n * the supplied context. See the mustache documentation for details of mustache syntax and view.\n * @param options - {@link TemplatedJsonConverterOptions | Options and context} for\n * the conversion.\n * @public\n */\nexport function templatedJson(options?: Partial<TemplatedJsonConverterOptions>): JsonConverter {\n if (!options) {\n if (!templatedJsonDefault) {\n templatedJsonDefault = new TemplatedJsonConverter();\n }\n return templatedJsonDefault;\n }\n return new TemplatedJsonConverter(options);\n}\n\n/**\n * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a\n * supplied `unknown` to strongly-typed JSON, by first rendering any property\n * names or string values using mustache with the supplied context, then applying\n * multi-value property expansion and conditional flattening based on property names.\n * @param options - {@link ConditionalJsonConverterOptions | Options and context} for\n * the conversion.\n * @public\n */\nexport function conditionalJson(options?: Partial<ConditionalJsonConverterOptions>): JsonConverter {\n if (!options) {\n if (!conditionalJsonDefault) {\n conditionalJsonDefault = new ConditionalJsonConverter();\n }\n return conditionalJsonDefault;\n }\n return new ConditionalJsonConverter(options);\n}\n\n/**\n * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a\n * supplied `unknown` to strongly-typed JSON, by first rendering any property\n * names or string values using mustache with the supplied context, then applying\n * multi-value property expansion and conditional flattening based on property names.\n * @param options - {@link RichJsonConverterOptions | Options and context} for\n * the conversion.\n * @public\n */\nexport function richJson(options?: Partial<RichJsonConverterOptions>): JsonConverter {\n if (!options) {\n if (!richJsonDefault) {\n richJsonDefault = new RichJsonConverter();\n }\n return richJsonDefault;\n }\n return new RichJsonConverter(options);\n}\n"]}
|
|
@@ -36,13 +36,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
36
36
|
}) : function(o, v) {
|
|
37
37
|
o["default"] = v;
|
|
38
38
|
});
|
|
39
|
-
var __importStar = (this && this.__importStar) || function (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
46
56
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
47
57
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
48
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/converters/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/converters/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yDAA2C;AAGlC,gCAAU;AADnB,kDAAgC","sourcesContent":["/*\n * Copyright (c) 2023 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 * as Converters from './converters';\n\nexport * from './jsonConverter';\nexport { Converters };\n"]}
|
|
@@ -21,7 +21,10 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.RichJsonConverter = exports.ConditionalJsonConverter = exports.TemplatedJsonConverter = exports.JsonConverter = exports.JsonEditorConverter =
|
|
24
|
+
exports.RichJsonConverter = exports.ConditionalJsonConverter = exports.TemplatedJsonConverter = exports.JsonConverter = exports.JsonEditorConverter = void 0;
|
|
25
|
+
exports.mergeDefaultJsonConverterOptions = mergeDefaultJsonConverterOptions;
|
|
26
|
+
exports.contextFromConverterOptions = contextFromConverterOptions;
|
|
27
|
+
exports.converterOptionsToEditor = converterOptionsToEditor;
|
|
25
28
|
const ts_json_base_1 = require("@fgv/ts-json-base");
|
|
26
29
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
27
30
|
const context_1 = require("../context");
|
|
@@ -63,7 +66,6 @@ function mergeDefaultJsonConverterOptions(partial) {
|
|
|
63
66
|
}
|
|
64
67
|
return options;
|
|
65
68
|
}
|
|
66
|
-
exports.mergeDefaultJsonConverterOptions = mergeDefaultJsonConverterOptions;
|
|
67
69
|
/**
|
|
68
70
|
* Creates a new {@link IJsonContext | JSON context} using values supplied in an optional partial
|
|
69
71
|
* {@link IJsonConverterOptions | converter options}.
|
|
@@ -84,7 +86,6 @@ function contextFromConverterOptions(partial) {
|
|
|
84
86
|
}
|
|
85
87
|
return context.vars || context.refs || context.extendVars ? context : undefined;
|
|
86
88
|
}
|
|
87
|
-
exports.contextFromConverterOptions = contextFromConverterOptions;
|
|
88
89
|
/**
|
|
89
90
|
* Creates a new {@link JsonEditor | JsonEditor} from an optionally supplied partial
|
|
90
91
|
* {@link IJsonConverterOptions | JSON converter options}.
|
|
@@ -120,7 +121,6 @@ function converterOptionsToEditor(partial) {
|
|
|
120
121
|
}
|
|
121
122
|
return editor_1.JsonEditor.create(editorOptions, rules);
|
|
122
123
|
}
|
|
123
|
-
exports.converterOptionsToEditor = converterOptionsToEditor;
|
|
124
124
|
/**
|
|
125
125
|
* A thin wrapper to allow an arbitrary {@link JsonEditor | JsonEditor} to be used via the
|
|
126
126
|
* \@fgv/ts-utils `Converter` pattern.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonConverter.js","sourceRoot":"","sources":["../../../src/packlets/converters/jsonConverter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,oDAAmF;AACnF,4CAA4F;AAC5F,wCAMoB;AAEpB,sCAAyF;AA8GzF;;;;;;;;GAQG;AACH,SAAgB,gCAAgC,CAC9C,OAAwC;;IAExC,MAAM,QAAQ,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,SAAS,CAAC;IAC7C,MAAM,QAAQ,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,SAAS,CAAC;IAC7C,MAAM,QAAQ,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,CAAC,YAAY,CAAC,EAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,2BAAiB,CAAC;IAChG,MAAM,YAAY,GAAG,QAAQ,KAAK,SAAS,CAAC;IAC5C,MAAM,YAAY,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,mCAAI,QAAQ,CAAC;IAC3D,MAAM,iBAAiB,GAAG,MAAA,OAAO,a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UxD;;;;;OAKG;IACH,YAAmB,OAA2C;QAC5D,OAAO,mCAAQ,OAAO,GAAK,iBAAiB,CAAC,WAAW,CAAE,CAAC;QAC3D,MAAM,MAAM,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3D,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAA2C;QAC9D,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,CAAC;;AA9BH,8CA+BC;AA9BC;;;GAGG;AACoB,6BAAW,mCAC7B,wBAAwB,CAAC,kBAAkB,KAC9C,aAAa,EAAE,IAAI,IACnB","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 { JsonArray, JsonObject, JsonValue, isJsonObject } from '@fgv/ts-json-base';\nimport { Conversion, Converter, Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport {\n IJsonContext,\n IJsonReferenceMap,\n TemplateVars,\n TemplateVarsExtendFunction,\n defaultExtendVars\n} from '../context';\n\nimport { EditorRules, IJsonEditorOptions, IJsonEditorRule, JsonEditor } from '../editor';\n\n/**\n * Conversion options for {@link JsonConverter | JsonConverter}.\n * @public\n */\nexport interface IJsonConverterOptions {\n /**\n * If `true` and if template variables are available,\n * then string property values will be rendered using\n * mustache and those variable values. Otherwise string\n * properties are copied without modification.\n *\n * Defaults to `true` if vars are supplied with options,\n * `false` otherwise.\n */\n useValueTemplates: boolean;\n\n /**\n * If `true` and if template variables are available,\n * then property names will be rendered using\n * mustache and those variable values. Otherwise\n * property names are copied without modification.\n *\n * Defaults to `true` if vars are supplied with options,\n * `false` otherwise.\n */\n useNameTemplates: boolean;\n\n /**\n * If `true` and if template variables are available,\n * then string property names will be considered for\n * conditionals.\n *\n * Default is to match {@link IJsonConverterOptions.useNameTemplates | useNameTemplates}.\n */\n useConditionalNames: boolean;\n\n /**\n * If `true` (default) then properties with unconditional names\n * (which start with !) are flattened.\n */\n flattenUnconditionalValues: boolean;\n\n /**\n * If `true` and if both template variables and a\n * context derivation function is available, then properties\n * which match the multi-value name pattern will be expanded.\n * Default matches {@link IJsonConverterOptions.useNameTemplates | useNameTemplates}.\n *\n * Default is `true` unless {@link IJsonConverterOptions.extendVars | extendVars} is\n * explicitly set to `undefined`.\n */\n useMultiValueTemplateNames: boolean;\n\n /**\n * The variables (mustache view) used to render templated string names\n * and properties. See the mustache documentation for details of mustache\n * syntax and the template view.\n */\n vars?: TemplateVars;\n\n /**\n * Method used to extend variables for children of an array node during\n * expansion. Default is to use a built-in extension function unless\n * {@link IJsonConverterOptions.extendVars | extendVars} is explicitly set to undefined.\n */\n extendVars?: TemplateVarsExtendFunction;\n\n /**\n * If `true` and if a {@link IJsonReferenceMap | references map} is supplied\n * in {@link IJsonConverterOptions.refs | refs}, then references in the source\n * object will be replaced with the corresponding value from the reference map.\n *\n * Default is `true` if {@link IJsonConverterOptions.refs | refs} are present in options,\n * `false` otherwise.\n */\n useReferences: boolean;\n\n /**\n * An optional {@link IJsonReferenceMap | reference map} used to insert any references\n * in the converted JSON.\n */\n refs?: IJsonReferenceMap;\n\n /**\n * If {@link IJsonConverterOptions.onInvalidPropertyName | onInvalidPropertyName} is `'error'`\n * (default) then any property name that is invalid after template rendering causes an error\n * and stops conversion. If {@link IJsonConverterOptions.onInvalidPropertyName | onInvalidPropertyName}\n * is `'ignore'`, then names which are invalid after template rendering are passed through unchanged.\n */\n onInvalidPropertyName: 'error' | 'ignore';\n\n /**\n * If {@link IJsonConverterOptions.onInvalidPropertyValue | onInvalidPropertyValue} is `'error'`\n * (default) then any illegal property value causes an error and stops conversion. If\n * {@link IJsonConverterOptions.onInvalidPropertyValue | onInvalidPropertyValue} is `'ignore'` then\n * any invalid property values are silently ignored.\n */\n onInvalidPropertyValue: 'error' | 'ignore';\n\n /**\n * If {@link IJsonConverterOptions.onUndefinedPropertyValue | onUndefinedPropertyValue} is `'error'`,\n * then any property with value `undefined` will cause an error and stop conversion. If\n * {@link IJsonConverterOptions.onUndefinedPropertyValue | onUndefinedPropertyValue} is `'ignore'` (default)\n * then any property with value `undefined` is silently ignored.\n */\n onUndefinedPropertyValue: 'error' | 'ignore';\n}\n\n/**\n * Merges an optionally supplied partial set of {@link IJsonConverterOptions | options} with\n * the default converter options and taking all dynamic rules into account (e.g. template usage enabled\n * if variables are supplied and disabled if not), producing a fully-resolved set of\n * {@link IJsonConverterOptions | IJsonConverterOptions}.\n * @param partial - An optional partial {@link IJsonConverterOptions | IJsonConverterOptions}\n * to be merged.\n * @public\n */\nexport function mergeDefaultJsonConverterOptions(\n partial?: Partial<IJsonConverterOptions>\n): IJsonConverterOptions {\n const haveVars = partial?.vars !== undefined;\n const haveRefs = partial?.refs !== undefined;\n const extender = partial?.hasOwnProperty('extendVars') ? partial.extendVars : defaultExtendVars;\n const haveExtender = extender !== undefined;\n const namesDefault = partial?.useNameTemplates ?? haveVars;\n const conditionsDefault = partial?.useConditionalNames ?? namesDefault;\n\n const options: IJsonConverterOptions = {\n useValueTemplates: partial?.useValueTemplates ?? haveVars,\n useNameTemplates: namesDefault,\n useConditionalNames: conditionsDefault,\n flattenUnconditionalValues: partial?.flattenUnconditionalValues ?? conditionsDefault,\n useMultiValueTemplateNames: partial?.useMultiValueTemplateNames ?? (haveExtender && namesDefault),\n useReferences: partial?.useReferences ?? haveRefs,\n onInvalidPropertyName: partial?.onInvalidPropertyName ?? 'error',\n onInvalidPropertyValue: partial?.onInvalidPropertyValue ?? 'error',\n onUndefinedPropertyValue: partial?.onUndefinedPropertyValue ?? 'ignore',\n extendVars: extender\n };\n if (partial?.vars) {\n options.vars = partial.vars;\n }\n if (partial?.refs) {\n options.refs = partial.refs;\n }\n return options;\n}\n\n/**\n * Creates a new {@link IJsonContext | JSON context} using values supplied in an optional partial\n * {@link IJsonConverterOptions | converter options}.\n * @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions} used to\n * populate the context.\n * @public\n */\nexport function contextFromConverterOptions(\n partial?: Partial<IJsonConverterOptions>\n): IJsonContext | undefined {\n const context: IJsonContext = {};\n if (partial?.vars) {\n context.vars = partial.vars;\n }\n if (partial?.refs) {\n context.refs = partial.refs;\n }\n if (partial?.hasOwnProperty('extendVars')) {\n context.extendVars = partial.extendVars;\n }\n return context.vars || context.refs || context.extendVars ? context : undefined;\n}\n\n/**\n * Creates a new {@link JsonEditor | JsonEditor} from an optionally supplied partial\n * {@link IJsonConverterOptions | JSON converter options}.\n * Expands supplied options with default values and constructs an editor with\n * matching configuration and defined rules.\n * @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions}\n * used to create the editor.\n * @public\n */\nexport function converterOptionsToEditor(partial?: Partial<IJsonConverterOptions>): Result<JsonEditor> {\n const converterOptions = mergeDefaultJsonConverterOptions(partial);\n const context = contextFromConverterOptions(partial);\n const validation = {\n onInvalidPropertyName: converterOptions.onInvalidPropertyName,\n onInvalidPropertyValue: converterOptions.onInvalidPropertyValue,\n onUndefinedPropertyValue: converterOptions.onUndefinedPropertyValue\n };\n const editorOptions: IJsonEditorOptions = { context, validation };\n\n const rules: IJsonEditorRule[] = [];\n if (converterOptions.useNameTemplates || converterOptions.useValueTemplates) {\n const templateOptions = {\n ...editorOptions,\n useNameTemplates: converterOptions.useNameTemplates,\n useValueTemplates: converterOptions.useValueTemplates\n };\n rules.push(new EditorRules.TemplatedJsonEditorRule(templateOptions));\n }\n if (converterOptions.useConditionalNames || converterOptions.flattenUnconditionalValues) {\n const conditionalOptions = {\n ...editorOptions,\n flattenUnconditionalValues: converterOptions.flattenUnconditionalValues\n };\n rules.push(new EditorRules.ConditionalJsonEditorRule(conditionalOptions));\n }\n if (converterOptions.useMultiValueTemplateNames) {\n rules.push(new EditorRules.MultiValueJsonEditorRule(editorOptions));\n }\n if (converterOptions.useReferences) {\n rules.push(new EditorRules.ReferenceJsonEditorRule(editorOptions));\n }\n\n return JsonEditor.create(editorOptions, rules);\n}\n\n/**\n * A thin wrapper to allow an arbitrary {@link JsonEditor | JsonEditor} to be used via the\n * \\@fgv/ts-utils `Converter` pattern.\n * @public\n */\nexport class JsonEditorConverter extends Conversion.BaseConverter<JsonValue, IJsonContext> {\n public readonly editor: JsonEditor;\n\n /**\n * Constructs a new {@link JsonEditor | JsonEditor}Converter which uses the supplied editor\n * @param editor -\n */\n public constructor(editor: JsonEditor) {\n super((from, __self, context) => this._convert(from, context), editor.options.context);\n this.editor = editor;\n }\n\n /**\n * Constructs a new {@link JsonEditor | JsonEditor}Converter which uses the supplied editor\n * @param editor -\n */\n public static createWithEditor(editor: JsonEditor): Result<JsonEditorConverter> {\n return captureResult(() => new JsonEditorConverter(editor));\n }\n\n /**\n * Gets a derived converter which fails if the resulting converted\n * `JsonValue` is not a `JsonObject`.\n */\n public object(): Converter<JsonObject, IJsonContext> {\n return this.map((jv) => {\n if (!isJsonObject(jv)) {\n return fail(`Cannot convert \"${JSON.stringify(jv)}\" to JSON object.`);\n }\n return succeed(jv);\n });\n }\n\n /**\n * Gets a derived converter which fails if the resulting converted\n * `JsonValue` is not a `JsonArray`.\n */\n public array(): Converter<JsonArray, IJsonContext> {\n return this.map((jv) => {\n if (!Array.isArray(jv) || typeof jv !== 'object') {\n return fail(`Cannot convert \"${JSON.stringify(jv)}\" to JSON array.`);\n }\n return succeed(jv);\n });\n }\n\n protected _convert(from: unknown, context?: IJsonContext): Result<JsonValue> {\n return this.editor.clone(from as JsonValue, context);\n }\n}\n\n/**\n * An \\@fgv/ts-utils `Converter` from `unknown` to type-safe JSON, optionally\n * rendering any string property names or values using mustache with a supplied view.\n * @public\n */\nexport class JsonConverter extends JsonEditorConverter {\n /**\n * Constructs a new {@link JsonConverter | JsonConverter} with\n * supplied or default options.\n * @param options - Optional partial {@link IJsonConverterOptions | options}\n * to configure the converter.\n */\n public constructor(options?: Partial<IJsonConverterOptions>) {\n const editor = converterOptionsToEditor(options).orThrow();\n super(editor);\n }\n\n /**\n * Creates a new {@link JsonConverter | JsonConverter}.\n * @param options - Optional partial {@link IJsonConverterOptions | options}\n * to configure the converter.\n * @returns `Success` with a new {@link JsonConverter | JsonConverter}, or `Failure`\n * with an informative message if an error occurs.\n */\n public static create(options?: Partial<IJsonConverterOptions>): Result<JsonConverter> {\n return captureResult(() => new JsonConverter(options));\n }\n}\n\n/**\n * Initialization options for a {@link TemplatedJsonConverter | TemplatedJsonConverter}.\n * @public\n */\nexport type TemplatedJsonConverterOptions = Omit<\n IJsonConverterOptions,\n 'useNameTemplates' | 'useValueTemplates' | 'useMultiValueTemplateNames'\n>;\n\n/**\n * An \\@fgv/ts-utils `Converter` from `unknown` to type-safe JSON\n * with mustache template rendering and multi-value property name rules enabled\n * regardless of initial context.\n * @public\n */\nexport class TemplatedJsonConverter extends JsonEditorConverter {\n /**\n * Default {@link IJsonConverterOptions | JSON converter options}\n * to enable templated conversion.\n */\n public static readonly templateOptions: Partial<IJsonConverterOptions> = {\n useNameTemplates: true,\n useValueTemplates: true,\n useMultiValueTemplateNames: true,\n useConditionalNames: false,\n flattenUnconditionalValues: false\n };\n\n /**\n * Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with\n * supplied or default options.\n * @param options - Optional partial {@link TemplatedJsonConverterOptions | options}\n * to configure the converter.\n */\n public constructor(options?: Partial<TemplatedJsonConverterOptions>) {\n options = { ...options, ...TemplatedJsonConverter.templateOptions };\n const editor = converterOptionsToEditor(options).orThrow();\n super(editor);\n }\n\n /**\n * Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with\n * supplied or default options.\n * @param options - Optional partial {@link TemplatedJsonConverterOptions | options}\n * to configure the converter.\n */\n public static create(options?: Partial<TemplatedJsonConverterOptions>): Result<JsonConverter> {\n return captureResult(() => new TemplatedJsonConverter(options));\n }\n}\n\n/**\n * Options for a {@link ConditionalJsonConverter | ConditionalJsonConverter}.\n * @public\n */\nexport type ConditionalJsonConverterOptions = Omit<TemplatedJsonConverterOptions, 'useConditionalNames'>;\n\n/**\n * An \\@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache\n * template rendering, multi-value property name and conditional property\n * name rules enabled regardless of initial context.\n * @public\n */\nexport class ConditionalJsonConverter extends JsonEditorConverter {\n /**\n * Default {@link IJsonConverterOptions | JSON converter options}\n * to enable conditional conversion.\n */\n public static readonly conditionalOptions: Partial<IJsonConverterOptions> = {\n ...TemplatedJsonConverter.templateOptions,\n useConditionalNames: true,\n flattenUnconditionalValues: true\n };\n\n /**\n * Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or\n * default options.\n * @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}\n * for the converter.\n */\n public constructor(options?: Partial<ConditionalJsonConverterOptions>) {\n options = { ...options, ...ConditionalJsonConverter.conditionalOptions };\n const editor = converterOptionsToEditor(options).orThrow();\n super(editor);\n }\n\n /**\n * Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or\n * default options.\n * @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}\n * for the converter.\n */\n public static create(options?: Partial<ConditionalJsonConverterOptions>): Result<JsonConverter> {\n return captureResult(() => new ConditionalJsonConverter(options));\n }\n}\n\n/**\n * Initialization options for a {@link RichJsonConverter | RichJsonConverter}.\n * @public\n */\nexport type RichJsonConverterOptions = Omit<ConditionalJsonConverterOptions, 'useReferences'>;\n\n/**\n * A \\@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache\n * template rendering, multi-value property name, conditional property\n * name, and external reference rules enabled regardless of initial context.\n * @public\n */\nexport class RichJsonConverter extends JsonEditorConverter {\n /**\n * Default {@link IJsonConverterOptions | JSON converter options}\n * to enable rich conversion.\n */\n public static readonly richOptions: Partial<IJsonConverterOptions> = {\n ...ConditionalJsonConverter.conditionalOptions,\n useReferences: true\n };\n\n /**\n * Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or\n * default options.\n * @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}\n * for the converter.\n */\n public constructor(options?: Partial<RichJsonConverterOptions>) {\n options = { ...options, ...RichJsonConverter.richOptions };\n const editor = converterOptionsToEditor(options).orThrow();\n super(editor);\n }\n\n /**\n * Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or\n * default options\n * @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}\n * for the converter.\n */\n public static create(options?: Partial<RichJsonConverterOptions>): Result<JsonConverter> {\n return captureResult(() => new RichJsonConverter(options));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"jsonConverter.js","sourceRoot":"","sources":["../../../src/packlets/converters/jsonConverter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAmIH,4EA6BC;AASD,kEAcC;AAWD,4DAkCC;AAlOD,oDAAmF;AACnF,4CAA4F;AAC5F,wCAMoB;AAEpB,sCAAyF;AA8GzF;;;;;;;;GAQG;AACH,SAAgB,gCAAgC,CA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BAAwB,CAAC,kBAAkB,CAAE,CAAC;QACzE,MAAM,MAAM,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3D,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAAkD;QACrE,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;IACpE,CAAC;;AA/BH,4DAgCC;AA/BC;;;GAGG;AACoB,2CAAkB,mCACpC,sBAAsB,CAAC,eAAe,KACzC,mBAAmB,EAAE,IAAI,EACzB,0BAA0B,EAAE,IAAI,IAChC;AA+BJ;;;;;GAKG;AACH,MAAa,iBAAkB,SAAQ,mBAAmB;IAUxD;;;;;OAKG;IACH,YAAmB,OAA2C;QAC5D,OAAO,mCAAQ,OAAO,GAAK,iBAAiB,CAAC,WAAW,CAAE,CAAC;QAC3D,MAAM,MAAM,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3D,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAA2C;QAC9D,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,CAAC;;AA9BH,8CA+BC;AA9BC;;;GAGG;AACoB,6BAAW,mCAC7B,wBAAwB,CAAC,kBAAkB,KAC9C,aAAa,EAAE,IAAI,IACnB","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 { JsonArray, JsonObject, JsonValue, isJsonObject } from '@fgv/ts-json-base';\nimport { Conversion, Converter, Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport {\n IJsonContext,\n IJsonReferenceMap,\n TemplateVars,\n TemplateVarsExtendFunction,\n defaultExtendVars\n} from '../context';\n\nimport { EditorRules, IJsonEditorOptions, IJsonEditorRule, JsonEditor } from '../editor';\n\n/**\n * Conversion options for {@link JsonConverter | JsonConverter}.\n * @public\n */\nexport interface IJsonConverterOptions {\n /**\n * If `true` and if template variables are available,\n * then string property values will be rendered using\n * mustache and those variable values. Otherwise string\n * properties are copied without modification.\n *\n * Defaults to `true` if vars are supplied with options,\n * `false` otherwise.\n */\n useValueTemplates: boolean;\n\n /**\n * If `true` and if template variables are available,\n * then property names will be rendered using\n * mustache and those variable values. Otherwise\n * property names are copied without modification.\n *\n * Defaults to `true` if vars are supplied with options,\n * `false` otherwise.\n */\n useNameTemplates: boolean;\n\n /**\n * If `true` and if template variables are available,\n * then string property names will be considered for\n * conditionals.\n *\n * Default is to match {@link IJsonConverterOptions.useNameTemplates | useNameTemplates}.\n */\n useConditionalNames: boolean;\n\n /**\n * If `true` (default) then properties with unconditional names\n * (which start with !) are flattened.\n */\n flattenUnconditionalValues: boolean;\n\n /**\n * If `true` and if both template variables and a\n * context derivation function is available, then properties\n * which match the multi-value name pattern will be expanded.\n * Default matches {@link IJsonConverterOptions.useNameTemplates | useNameTemplates}.\n *\n * Default is `true` unless {@link IJsonConverterOptions.extendVars | extendVars} is\n * explicitly set to `undefined`.\n */\n useMultiValueTemplateNames: boolean;\n\n /**\n * The variables (mustache view) used to render templated string names\n * and properties. See the mustache documentation for details of mustache\n * syntax and the template view.\n */\n vars?: TemplateVars;\n\n /**\n * Method used to extend variables for children of an array node during\n * expansion. Default is to use a built-in extension function unless\n * {@link IJsonConverterOptions.extendVars | extendVars} is explicitly set to undefined.\n */\n extendVars?: TemplateVarsExtendFunction;\n\n /**\n * If `true` and if a {@link IJsonReferenceMap | references map} is supplied\n * in {@link IJsonConverterOptions.refs | refs}, then references in the source\n * object will be replaced with the corresponding value from the reference map.\n *\n * Default is `true` if {@link IJsonConverterOptions.refs | refs} are present in options,\n * `false` otherwise.\n */\n useReferences: boolean;\n\n /**\n * An optional {@link IJsonReferenceMap | reference map} used to insert any references\n * in the converted JSON.\n */\n refs?: IJsonReferenceMap;\n\n /**\n * If {@link IJsonConverterOptions.onInvalidPropertyName | onInvalidPropertyName} is `'error'`\n * (default) then any property name that is invalid after template rendering causes an error\n * and stops conversion. If {@link IJsonConverterOptions.onInvalidPropertyName | onInvalidPropertyName}\n * is `'ignore'`, then names which are invalid after template rendering are passed through unchanged.\n */\n onInvalidPropertyName: 'error' | 'ignore';\n\n /**\n * If {@link IJsonConverterOptions.onInvalidPropertyValue | onInvalidPropertyValue} is `'error'`\n * (default) then any illegal property value causes an error and stops conversion. If\n * {@link IJsonConverterOptions.onInvalidPropertyValue | onInvalidPropertyValue} is `'ignore'` then\n * any invalid property values are silently ignored.\n */\n onInvalidPropertyValue: 'error' | 'ignore';\n\n /**\n * If {@link IJsonConverterOptions.onUndefinedPropertyValue | onUndefinedPropertyValue} is `'error'`,\n * then any property with value `undefined` will cause an error and stop conversion. If\n * {@link IJsonConverterOptions.onUndefinedPropertyValue | onUndefinedPropertyValue} is `'ignore'` (default)\n * then any property with value `undefined` is silently ignored.\n */\n onUndefinedPropertyValue: 'error' | 'ignore';\n}\n\n/**\n * Merges an optionally supplied partial set of {@link IJsonConverterOptions | options} with\n * the default converter options and taking all dynamic rules into account (e.g. template usage enabled\n * if variables are supplied and disabled if not), producing a fully-resolved set of\n * {@link IJsonConverterOptions | IJsonConverterOptions}.\n * @param partial - An optional partial {@link IJsonConverterOptions | IJsonConverterOptions}\n * to be merged.\n * @public\n */\nexport function mergeDefaultJsonConverterOptions(\n partial?: Partial<IJsonConverterOptions>\n): IJsonConverterOptions {\n const haveVars = partial?.vars !== undefined;\n const haveRefs = partial?.refs !== undefined;\n const extender = partial?.hasOwnProperty('extendVars') ? partial.extendVars : defaultExtendVars;\n const haveExtender = extender !== undefined;\n const namesDefault = partial?.useNameTemplates ?? haveVars;\n const conditionsDefault = partial?.useConditionalNames ?? namesDefault;\n\n const options: IJsonConverterOptions = {\n useValueTemplates: partial?.useValueTemplates ?? haveVars,\n useNameTemplates: namesDefault,\n useConditionalNames: conditionsDefault,\n flattenUnconditionalValues: partial?.flattenUnconditionalValues ?? conditionsDefault,\n useMultiValueTemplateNames: partial?.useMultiValueTemplateNames ?? (haveExtender && namesDefault),\n useReferences: partial?.useReferences ?? haveRefs,\n onInvalidPropertyName: partial?.onInvalidPropertyName ?? 'error',\n onInvalidPropertyValue: partial?.onInvalidPropertyValue ?? 'error',\n onUndefinedPropertyValue: partial?.onUndefinedPropertyValue ?? 'ignore',\n extendVars: extender\n };\n if (partial?.vars) {\n options.vars = partial.vars;\n }\n if (partial?.refs) {\n options.refs = partial.refs;\n }\n return options;\n}\n\n/**\n * Creates a new {@link IJsonContext | JSON context} using values supplied in an optional partial\n * {@link IJsonConverterOptions | converter options}.\n * @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions} used to\n * populate the context.\n * @public\n */\nexport function contextFromConverterOptions(\n partial?: Partial<IJsonConverterOptions>\n): IJsonContext | undefined {\n const context: IJsonContext = {};\n if (partial?.vars) {\n context.vars = partial.vars;\n }\n if (partial?.refs) {\n context.refs = partial.refs;\n }\n if (partial?.hasOwnProperty('extendVars')) {\n context.extendVars = partial.extendVars;\n }\n return context.vars || context.refs || context.extendVars ? context : undefined;\n}\n\n/**\n * Creates a new {@link JsonEditor | JsonEditor} from an optionally supplied partial\n * {@link IJsonConverterOptions | JSON converter options}.\n * Expands supplied options with default values and constructs an editor with\n * matching configuration and defined rules.\n * @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions}\n * used to create the editor.\n * @public\n */\nexport function converterOptionsToEditor(partial?: Partial<IJsonConverterOptions>): Result<JsonEditor> {\n const converterOptions = mergeDefaultJsonConverterOptions(partial);\n const context = contextFromConverterOptions(partial);\n const validation = {\n onInvalidPropertyName: converterOptions.onInvalidPropertyName,\n onInvalidPropertyValue: converterOptions.onInvalidPropertyValue,\n onUndefinedPropertyValue: converterOptions.onUndefinedPropertyValue\n };\n const editorOptions: IJsonEditorOptions = { context, validation };\n\n const rules: IJsonEditorRule[] = [];\n if (converterOptions.useNameTemplates || converterOptions.useValueTemplates) {\n const templateOptions = {\n ...editorOptions,\n useNameTemplates: converterOptions.useNameTemplates,\n useValueTemplates: converterOptions.useValueTemplates\n };\n rules.push(new EditorRules.TemplatedJsonEditorRule(templateOptions));\n }\n if (converterOptions.useConditionalNames || converterOptions.flattenUnconditionalValues) {\n const conditionalOptions = {\n ...editorOptions,\n flattenUnconditionalValues: converterOptions.flattenUnconditionalValues\n };\n rules.push(new EditorRules.ConditionalJsonEditorRule(conditionalOptions));\n }\n if (converterOptions.useMultiValueTemplateNames) {\n rules.push(new EditorRules.MultiValueJsonEditorRule(editorOptions));\n }\n if (converterOptions.useReferences) {\n rules.push(new EditorRules.ReferenceJsonEditorRule(editorOptions));\n }\n\n return JsonEditor.create(editorOptions, rules);\n}\n\n/**\n * A thin wrapper to allow an arbitrary {@link JsonEditor | JsonEditor} to be used via the\n * \\@fgv/ts-utils `Converter` pattern.\n * @public\n */\nexport class JsonEditorConverter extends Conversion.BaseConverter<JsonValue, IJsonContext> {\n public readonly editor: JsonEditor;\n\n /**\n * Constructs a new {@link JsonEditor | JsonEditor}Converter which uses the supplied editor\n * @param editor -\n */\n public constructor(editor: JsonEditor) {\n super((from, __self, context) => this._convert(from, context), editor.options.context);\n this.editor = editor;\n }\n\n /**\n * Constructs a new {@link JsonEditor | JsonEditor}Converter which uses the supplied editor\n * @param editor -\n */\n public static createWithEditor(editor: JsonEditor): Result<JsonEditorConverter> {\n return captureResult(() => new JsonEditorConverter(editor));\n }\n\n /**\n * Gets a derived converter which fails if the resulting converted\n * `JsonValue` is not a `JsonObject`.\n */\n public object(): Converter<JsonObject, IJsonContext> {\n return this.map((jv) => {\n if (!isJsonObject(jv)) {\n return fail(`Cannot convert \"${JSON.stringify(jv)}\" to JSON object.`);\n }\n return succeed(jv);\n });\n }\n\n /**\n * Gets a derived converter which fails if the resulting converted\n * `JsonValue` is not a `JsonArray`.\n */\n public array(): Converter<JsonArray, IJsonContext> {\n return this.map((jv) => {\n if (!Array.isArray(jv) || typeof jv !== 'object') {\n return fail(`Cannot convert \"${JSON.stringify(jv)}\" to JSON array.`);\n }\n return succeed(jv);\n });\n }\n\n protected _convert(from: unknown, context?: IJsonContext): Result<JsonValue> {\n return this.editor.clone(from as JsonValue, context);\n }\n}\n\n/**\n * An \\@fgv/ts-utils `Converter` from `unknown` to type-safe JSON, optionally\n * rendering any string property names or values using mustache with a supplied view.\n * @public\n */\nexport class JsonConverter extends JsonEditorConverter {\n /**\n * Constructs a new {@link JsonConverter | JsonConverter} with\n * supplied or default options.\n * @param options - Optional partial {@link IJsonConverterOptions | options}\n * to configure the converter.\n */\n public constructor(options?: Partial<IJsonConverterOptions>) {\n const editor = converterOptionsToEditor(options).orThrow();\n super(editor);\n }\n\n /**\n * Creates a new {@link JsonConverter | JsonConverter}.\n * @param options - Optional partial {@link IJsonConverterOptions | options}\n * to configure the converter.\n * @returns `Success` with a new {@link JsonConverter | JsonConverter}, or `Failure`\n * with an informative message if an error occurs.\n */\n public static create(options?: Partial<IJsonConverterOptions>): Result<JsonConverter> {\n return captureResult(() => new JsonConverter(options));\n }\n}\n\n/**\n * Initialization options for a {@link TemplatedJsonConverter | TemplatedJsonConverter}.\n * @public\n */\nexport type TemplatedJsonConverterOptions = Omit<\n IJsonConverterOptions,\n 'useNameTemplates' | 'useValueTemplates' | 'useMultiValueTemplateNames'\n>;\n\n/**\n * An \\@fgv/ts-utils `Converter` from `unknown` to type-safe JSON\n * with mustache template rendering and multi-value property name rules enabled\n * regardless of initial context.\n * @public\n */\nexport class TemplatedJsonConverter extends JsonEditorConverter {\n /**\n * Default {@link IJsonConverterOptions | JSON converter options}\n * to enable templated conversion.\n */\n public static readonly templateOptions: Partial<IJsonConverterOptions> = {\n useNameTemplates: true,\n useValueTemplates: true,\n useMultiValueTemplateNames: true,\n useConditionalNames: false,\n flattenUnconditionalValues: false\n };\n\n /**\n * Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with\n * supplied or default options.\n * @param options - Optional partial {@link TemplatedJsonConverterOptions | options}\n * to configure the converter.\n */\n public constructor(options?: Partial<TemplatedJsonConverterOptions>) {\n options = { ...options, ...TemplatedJsonConverter.templateOptions };\n const editor = converterOptionsToEditor(options).orThrow();\n super(editor);\n }\n\n /**\n * Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with\n * supplied or default options.\n * @param options - Optional partial {@link TemplatedJsonConverterOptions | options}\n * to configure the converter.\n */\n public static create(options?: Partial<TemplatedJsonConverterOptions>): Result<JsonConverter> {\n return captureResult(() => new TemplatedJsonConverter(options));\n }\n}\n\n/**\n * Options for a {@link ConditionalJsonConverter | ConditionalJsonConverter}.\n * @public\n */\nexport type ConditionalJsonConverterOptions = Omit<TemplatedJsonConverterOptions, 'useConditionalNames'>;\n\n/**\n * An \\@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache\n * template rendering, multi-value property name and conditional property\n * name rules enabled regardless of initial context.\n * @public\n */\nexport class ConditionalJsonConverter extends JsonEditorConverter {\n /**\n * Default {@link IJsonConverterOptions | JSON converter options}\n * to enable conditional conversion.\n */\n public static readonly conditionalOptions: Partial<IJsonConverterOptions> = {\n ...TemplatedJsonConverter.templateOptions,\n useConditionalNames: true,\n flattenUnconditionalValues: true\n };\n\n /**\n * Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or\n * default options.\n * @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}\n * for the converter.\n */\n public constructor(options?: Partial<ConditionalJsonConverterOptions>) {\n options = { ...options, ...ConditionalJsonConverter.conditionalOptions };\n const editor = converterOptionsToEditor(options).orThrow();\n super(editor);\n }\n\n /**\n * Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or\n * default options.\n * @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}\n * for the converter.\n */\n public static create(options?: Partial<ConditionalJsonConverterOptions>): Result<JsonConverter> {\n return captureResult(() => new ConditionalJsonConverter(options));\n }\n}\n\n/**\n * Initialization options for a {@link RichJsonConverter | RichJsonConverter}.\n * @public\n */\nexport type RichJsonConverterOptions = Omit<ConditionalJsonConverterOptions, 'useReferences'>;\n\n/**\n * A \\@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache\n * template rendering, multi-value property name, conditional property\n * name, and external reference rules enabled regardless of initial context.\n * @public\n */\nexport class RichJsonConverter extends JsonEditorConverter {\n /**\n * Default {@link IJsonConverterOptions | JSON converter options}\n * to enable rich conversion.\n */\n public static readonly richOptions: Partial<IJsonConverterOptions> = {\n ...ConditionalJsonConverter.conditionalOptions,\n useReferences: true\n };\n\n /**\n * Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or\n * default options.\n * @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}\n * for the converter.\n */\n public constructor(options?: Partial<RichJsonConverterOptions>) {\n options = { ...options, ...RichJsonConverter.richOptions };\n const editor = converterOptionsToEditor(options).orThrow();\n super(editor);\n }\n\n /**\n * Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or\n * default options\n * @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}\n * for the converter.\n */\n public static create(options?: Partial<RichJsonConverterOptions>): Result<JsonConverter> {\n return captureResult(() => new RichJsonConverter(options));\n }\n}\n"]}
|
|
@@ -36,13 +36,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
36
36
|
}) : function(o, v) {
|
|
37
37
|
o["default"] = v;
|
|
38
38
|
});
|
|
39
|
-
var __importStar = (this && this.__importStar) || function (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
46
56
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
47
57
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
48
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/editor/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/editor/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,qDAAuC;AAa9B,kCAAW;AAXpB,2CAAyB;AACzB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,mDAAuE;AAA7C,oHAAA,kBAAkB,OAAA;AAC5C,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,uDAM4B;AAH1B,mHAAA,eAAe,OAAA;AACf,yHAAA,qBAAqB,OAAA;AACrB,iHAAA,aAAa,OAAA","sourcesContent":["/*\n * Copyright (c) 2023 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 * as EditorRules from './rules';\n\nexport * from './common';\nexport { JsonEditor } from './jsonEditor';\nexport { IJsonEditorRule, JsonEditorRuleBase } from './jsonEditorRule';\nexport { JsonEditorState } from './jsonEditorState';\nexport {\n IReferenceMapKeyPolicyValidateOptions,\n ISimpleJsonMapOptions,\n PrefixedJsonMap,\n ReferenceMapKeyPolicy,\n SimpleJsonMap\n} from './jsonReferenceMap';\nexport { EditorRules };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonEditorState.d.ts","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorState.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,EAA2B,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAqB,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC7G,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,4BAA4B,EAC5B,qBAAqB,EACrB,yBAAyB,EAE1B,MAAM,UAAU,CAAC;AAElB;;;GAGG;AACH,qBAAa,eAAe;IAC1B;;;;OAIG;IACH,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAK;IAErC;;OAEG;IACH,SAAgB,MAAM,EAAE,gBAAgB,CAAC;IAEzC;;;OAGG;IACH,SAAgB,OAAO,EAAE,kBAAkB,CAAC;IAE5C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,CAAM;IAEhD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAE/B;;;;;;;;OAQG;gBAED,MAAM,EAAE,gBAAgB,EACxB,WAAW,EAAE,kBAAkB,EAC/B,cAAc,CAAC,EAAE,YAAY;IAO/B;;OAEG;IACH,IAAW,OAAO,IAAI,YAAY,GAAG,SAAS,CAE7C;IAED;;;OAGG;IACH,IAAW,QAAQ,IAAI,UAAU,EAAE,CAElC;IAED;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,MAAM,CAAC,oBAAoB,CACn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;;;;;;;;OAYG;IACH,SAAS,CAAC,MAAM,CAAC,oBAAoB,CACnC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,CAAC,EAAE,YAAY,GACrB,MAAM,CAAC,kBAAkB,CAAC;IAS7B;;;OAGG;IACI,KAAK,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IAInC;;;;;;;;OAQG;IACI,OAAO,CAAC,cAAc,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,SAAS;IAKvE;;;;;;;OAOG;IACI,OAAO,CAAC,cAAc,CAAC,EAAE,YAAY,GAAG,iBAAiB,GAAG,SAAS;IAK5E;;;;;;;OAOG;IACI,UAAU,CAAC,cAAc,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,SAAS;IAI1E;;;;;;;;OAQG;IACI,aAAa,CAClB,WAAW,EAAE,YAAY,GAAG,SAAS,EACrC,GAAG,EAAE;QAAE,IAAI,CAAC,EAAE,aAAa,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,iBAAiB,EAAE,CAAA;KAAE,GAC1D,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC;IAKnC;;;;;;;;OAQG;IACI,cAAc,CAAC,CAAC,GAAG,UAAU,EAClC,IAAI,EAAE,yBAAyB,EAC/B,OAAO,CAAC,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,4BAA4B,GACxC,eAAe,CAAC,CAAC,EAAE,qBAAqB,CAAC;CAmB7C"}
|
|
@@ -100,6 +100,7 @@ class JsonEditorState {
|
|
|
100
100
|
*/
|
|
101
101
|
getVars(defaultContext) {
|
|
102
102
|
var _a, _b;
|
|
103
|
+
/* c8 ignore next */ // c8 seems to be struggling atm
|
|
103
104
|
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
|
}
|
|
105
106
|
/**
|
|
@@ -112,6 +113,7 @@ class JsonEditorState {
|
|
|
112
113
|
*/
|
|
113
114
|
getRefs(defaultContext) {
|
|
114
115
|
var _a, _b;
|
|
116
|
+
/* c8 ignore next */ // c8 seems to be struggling atm
|
|
115
117
|
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
118
|
}
|
|
117
119
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonEditorState.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorState.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAAiF;AACjF,wCAA6G;AAU7G;;;GAGG;AACH,MAAa,eAAe;IA+B1B;;;;;;;;OAQG;IACH,YACE,MAAwB,EACxB,WAA+B,EAC/B,cAA6B;QAxB/B;;;WAGG;QACgB,cAAS,GAAiB,EAAE,CAAC;QAsB9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,oBAAoB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3F,IAAI,CAAC,GAAG,GAAG,eAAe,CAAC,OAAO,EAAE,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;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,CAAC;YACb,OAAO,IAAA,kBAAO,EAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,2BAAiB,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,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D,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,qBAAqB;gBACxB,MAAM,GAAG,SAAS,CAAC,qBAAqB,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC;gBACjF,MAAM;YACR,KAAK,sBAAsB;gBACzB,MAAM,GAAG,SAAS,CAAC,sBAAsB,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAC5E,MAAM;YACR,KAAK,wBAAwB;gBAC3B,MAAM,GAAG,SAAS,CAAC,wBAAwB,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;gBAC7E,oBAAoB;gBACpB,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,kCAAkC,CAAC;gBACxD,MAAM;QACV,CAAC;QACD,oBAAoB;QACpB,OAAO,IAAA,yBAAc,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;;AAvLH,0CAwLC;AAvLC;;;;GAIG;AACc,uBAAO,GAAW,CAAC,AAAZ,CAAa","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonObject } from '@fgv/ts-json-base';\nimport { DetailedFailure, Result, failWithDetail, succeed } from '@fgv/ts-utils';\nimport { IJsonContext, IJsonReferenceMap, JsonContextHelper, TemplateVars, VariableValue } from '../context';\nimport {\n IJsonCloneEditor,\n IJsonEditorOptions,\n IJsonEditorValidationOptions,\n JsonEditFailureReason,\n JsonEditorValidationRules,\n JsonPropertyEditFailureReason\n} from './common';\n\n/**\n * Represents the internal state of a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport class JsonEditorState {\n /**\n * Static global counter used to assign each {@link JsonEditorState | JsonEditorState}\n * a unique identifier.\n * @internal\n */\n protected static _nextId: number = 0;\n\n /**\n * The {@link IJsonCloneEditor | editor} for which this state applies.\n */\n public readonly editor: IJsonCloneEditor;\n\n /**\n * Fully resolved {@link IJsonEditorOptions | editor options} that apply\n * to the operation for which this state applies.\n */\n public readonly options: IJsonEditorOptions;\n\n /**\n * Any deferred JSON objects to be merged during finalization.\n * @internal\n */\n protected readonly _deferred: JsonObject[] = [];\n\n /**\n * Unique global identifier for this {@link JsonEditorState | state object}.\n * @internal\n */\n protected readonly _id: number;\n\n /**\n * Constructs a new {@link JsonEditorState | JsonEditorState}.\n * @param editor - The {@link IJsonCloneEditor | editor} to which this state\n * applies.\n * @param baseOptions - The {@link IJsonEditorOptions | editor options} that\n * apply to this rule.\n * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used\n * for json value conversion.\n */\n public constructor(\n editor: IJsonCloneEditor,\n baseOptions: IJsonEditorOptions,\n runtimeContext?: IJsonContext\n ) {\n this.editor = editor;\n this.options = JsonEditorState._getEffectiveOptions(baseOptions, runtimeContext).orThrow();\n this._id = JsonEditorState._nextId++;\n }\n\n /**\n * The optional {@link IJsonContext | JSON context} for this state.\n */\n public get context(): IJsonContext | undefined {\n return this.options.context;\n }\n\n /**\n * An array of JSON objects that were deferred for merge during\n * finalization.\n */\n public get deferred(): JsonObject[] {\n return this._deferred;\n }\n\n /**\n * Merges an optional {@link IJsonContext | JSON context} into a supplied set\n * of {@link IJsonEditorOptions | JSON editor options}.\n * @param options - The {@link IJsonEditorOptions | IJsonEditorOptions} into\n * which the the new context is to be merged.\n * @param context - The {@link IJsonContext | JSON context} to be merged into the\n * editor options.\n * @returns `Success` with the supplied {@link IJsonEditorOptions | options} if\n * there was nothing to merge, or aa new {@link IJsonEditorOptions | IJsonEditorOptions}\n * constructed from the base options merged with the supplied context. Returns `Failure`\n * with more information if an error occurs.\n * @internal\n */\n protected static _getEffectiveOptions(\n options: IJsonEditorOptions,\n context?: IJsonContext\n ): Result<IJsonEditorOptions> {\n if (!context) {\n return succeed(options);\n }\n return JsonContextHelper.mergeContext(options.context, context).onSuccess((merged) => {\n return succeed({ context: merged, validation: options.validation });\n });\n }\n\n /**\n * Adds a supplied `JsonObject` to the deferred list.\n * @param obj - The `JsonObject` to be deferred.\n */\n public defer(obj: JsonObject): void {\n this._deferred.push(obj);\n }\n\n /**\n * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link JsonEditorState | JsonEditorState},\n * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default\n * context.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`\n * if the current state does not have context.\n * @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or\n * `undefined` if no vars are found.\n */\n public getVars(defaultContext?: IJsonContext): TemplateVars | undefined {\n return this.options.context?.vars ?? defaultContext?.vars;\n }\n\n /**\n * Gets an {@link IJsonReferenceMap | reference map} containing any other values\n * referenced during the operation.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as\n * {@link TemplateVars | TemplateVars} if the current state does not have context.\n * @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced\n * during this operation.\n */\n public getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined {\n return this.options.context?.refs ?? defaultContext?.refs;\n }\n\n /**\n * Gets the context of this {@link JsonEditorState | JsonEditorState} or an optionally\n * supplied default context if this state has no context.\n * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default\n * if this state has no context.\n * @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context\n * is available.\n */\n public getContext(defaultContext?: IJsonContext): IJsonContext | undefined {\n return JsonContextHelper.mergeContext(defaultContext, this.options.context).orDefault();\n }\n\n /**\n * Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables\n * and references into a supplied existing context.\n * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables\n * and references are to be merged, or `undefined` to start with a default empty context.\n * @param add - The {@link VariableValue | variable values} and/or\n * {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.\n * @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.\n */\n public extendContext(\n baseContext: IJsonContext | undefined,\n add: { vars?: VariableValue[]; refs?: IJsonReferenceMap[] }\n ): Result<IJsonContext | undefined> {\n const context = this.getContext(baseContext);\n return JsonContextHelper.extendContext(context, add);\n }\n\n /**\n * Helper method to constructs `DetailedFailure` with appropriate details and messaging\n * for various validation failures.\n * @param rule - The {@link JsonEditorValidationRules | validation rule} that failed.\n * @param message - A string message describing the failed validation.\n * @param validation - The {@link IJsonEditorValidationOptions | validation options}\n * in effect.\n * @returns A `DetailedFailure` with appropriate detail and message.\n */\n public failValidation<T = JsonObject>(\n rule: JsonEditorValidationRules,\n message?: string,\n validation?: IJsonEditorValidationOptions\n ): DetailedFailure<T, JsonEditFailureReason> {\n let detail: JsonPropertyEditFailureReason = 'error';\n const effective = validation ?? this.options.validation;\n switch (rule) {\n case 'invalidPropertyName':\n detail = effective.onInvalidPropertyName !== 'ignore' ? 'error' : 'inapplicable';\n break;\n case 'invalidPropertyValue':\n detail = effective.onInvalidPropertyValue !== 'ignore' ? 'error' : 'ignore';\n break;\n case 'undefinedPropertyValue':\n detail = effective.onUndefinedPropertyValue !== 'error' ? 'ignore' : 'error';\n /* c8 ignore next */\n message = message ?? 'Cannot convert undefined to JSON';\n break;\n }\n /* c8 ignore next */\n return failWithDetail(message ?? rule, detail);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"jsonEditorState.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorState.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAAiF;AACjF,wCAA6G;AAU7G;;;GAGG;AACH,MAAa,eAAe;IA+B1B;;;;;;;;OAQG;IACH,YACE,MAAwB,EACxB,WAA+B,EAC/B,cAA6B;QAxB/B;;;WAGG;QACgB,cAAS,GAAiB,EAAE,CAAC;QAsB9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,oBAAoB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3F,IAAI,CAAC,GAAG,GAAG,eAAe,CAAC,OAAO,EAAE,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;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,CAAC;YACb,OAAO,IAAA,kBAAO,EAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,2BAAiB,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACnF,OAAO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,UAAU,CAAC;QACxD,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,qBAAqB;gBACxB,MAAM,GAAG,SAAS,CAAC,qBAAqB,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC;gBACjF,MAAM;YACR,KAAK,sBAAsB;gBACzB,MAAM,GAAG,SAAS,CAAC,sBAAsB,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAC5E,MAAM;YACR,KAAK,wBAAwB;gBAC3B,MAAM,GAAG,SAAS,CAAC,wBAAwB,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;gBAC7E,oBAAoB;gBACpB,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,kCAAkC,CAAC;gBACxD,MAAM;QACV,CAAC;QACD,oBAAoB;QACpB,OAAO,IAAA,yBAAc,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;;AAzLH,0CA0LC;AAzLC;;;;GAIG;AACc,uBAAO,GAAW,CAAC,AAAZ,CAAa","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonObject } from '@fgv/ts-json-base';\nimport { DetailedFailure, Result, failWithDetail, succeed } from '@fgv/ts-utils';\nimport { IJsonContext, IJsonReferenceMap, JsonContextHelper, TemplateVars, VariableValue } from '../context';\nimport {\n IJsonCloneEditor,\n IJsonEditorOptions,\n IJsonEditorValidationOptions,\n JsonEditFailureReason,\n JsonEditorValidationRules,\n JsonPropertyEditFailureReason\n} from './common';\n\n/**\n * Represents the internal state of a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport class JsonEditorState {\n /**\n * Static global counter used to assign each {@link JsonEditorState | JsonEditorState}\n * a unique identifier.\n * @internal\n */\n protected static _nextId: number = 0;\n\n /**\n * The {@link IJsonCloneEditor | editor} for which this state applies.\n */\n public readonly editor: IJsonCloneEditor;\n\n /**\n * Fully resolved {@link IJsonEditorOptions | editor options} that apply\n * to the operation for which this state applies.\n */\n public readonly options: IJsonEditorOptions;\n\n /**\n * Any deferred JSON objects to be merged during finalization.\n * @internal\n */\n protected readonly _deferred: JsonObject[] = [];\n\n /**\n * Unique global identifier for this {@link JsonEditorState | state object}.\n * @internal\n */\n protected readonly _id: number;\n\n /**\n * Constructs a new {@link JsonEditorState | JsonEditorState}.\n * @param editor - The {@link IJsonCloneEditor | editor} to which this state\n * applies.\n * @param baseOptions - The {@link IJsonEditorOptions | editor options} that\n * apply to this rule.\n * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used\n * for json value conversion.\n */\n public constructor(\n editor: IJsonCloneEditor,\n baseOptions: IJsonEditorOptions,\n runtimeContext?: IJsonContext\n ) {\n this.editor = editor;\n this.options = JsonEditorState._getEffectiveOptions(baseOptions, runtimeContext).orThrow();\n this._id = JsonEditorState._nextId++;\n }\n\n /**\n * The optional {@link IJsonContext | JSON context} for this state.\n */\n public get context(): IJsonContext | undefined {\n return this.options.context;\n }\n\n /**\n * An array of JSON objects that were deferred for merge during\n * finalization.\n */\n public get deferred(): JsonObject[] {\n return this._deferred;\n }\n\n /**\n * Merges an optional {@link IJsonContext | JSON context} into a supplied set\n * of {@link IJsonEditorOptions | JSON editor options}.\n * @param options - The {@link IJsonEditorOptions | IJsonEditorOptions} into\n * which the the new context is to be merged.\n * @param context - The {@link IJsonContext | JSON context} to be merged into the\n * editor options.\n * @returns `Success` with the supplied {@link IJsonEditorOptions | options} if\n * there was nothing to merge, or aa new {@link IJsonEditorOptions | IJsonEditorOptions}\n * constructed from the base options merged with the supplied context. Returns `Failure`\n * with more information if an error occurs.\n * @internal\n */\n protected static _getEffectiveOptions(\n options: IJsonEditorOptions,\n context?: IJsonContext\n ): Result<IJsonEditorOptions> {\n if (!context) {\n return succeed(options);\n }\n return JsonContextHelper.mergeContext(options.context, context).onSuccess((merged) => {\n return succeed({ context: merged, validation: options.validation });\n });\n }\n\n /**\n * Adds a supplied `JsonObject` to the deferred list.\n * @param obj - The `JsonObject` to be deferred.\n */\n public defer(obj: JsonObject): void {\n this._deferred.push(obj);\n }\n\n /**\n * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link JsonEditorState | JsonEditorState},\n * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default\n * context.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`\n * if the current state does not have context.\n * @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or\n * `undefined` if no vars are found.\n */\n public getVars(defaultContext?: IJsonContext): TemplateVars | undefined {\n /* c8 ignore next */ // c8 seems to be struggling atm\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 /* c8 ignore next */ // c8 seems to be struggling atm\n return this.options.context?.refs ?? defaultContext?.refs;\n }\n\n /**\n * Gets the context of this {@link JsonEditorState | JsonEditorState} or an optionally\n * supplied default context if this state has no context.\n * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default\n * if this state has no context.\n * @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context\n * is available.\n */\n public getContext(defaultContext?: IJsonContext): IJsonContext | undefined {\n return JsonContextHelper.mergeContext(defaultContext, this.options.context).orDefault();\n }\n\n /**\n * Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables\n * and references into a supplied existing context.\n * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables\n * and references are to be merged, or `undefined` to start with a default empty context.\n * @param add - The {@link VariableValue | variable values} and/or\n * {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.\n * @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.\n */\n public extendContext(\n baseContext: IJsonContext | undefined,\n add: { vars?: VariableValue[]; refs?: IJsonReferenceMap[] }\n ): Result<IJsonContext | undefined> {\n const context = this.getContext(baseContext);\n return JsonContextHelper.extendContext(context, add);\n }\n\n /**\n * Helper method to constructs `DetailedFailure` with appropriate details and messaging\n * for various validation failures.\n * @param rule - The {@link JsonEditorValidationRules | validation rule} that failed.\n * @param message - A string message describing the failed validation.\n * @param validation - The {@link IJsonEditorValidationOptions | validation options}\n * in effect.\n * @returns A `DetailedFailure` with appropriate detail and message.\n */\n public failValidation<T = JsonObject>(\n rule: JsonEditorValidationRules,\n message?: string,\n validation?: IJsonEditorValidationOptions\n ): DetailedFailure<T, JsonEditFailureReason> {\n let detail: JsonPropertyEditFailureReason = 'error';\n const effective = validation ?? this.options.validation;\n switch (rule) {\n case 'invalidPropertyName':\n detail = effective.onInvalidPropertyName !== 'ignore' ? 'error' : 'inapplicable';\n break;\n case 'invalidPropertyValue':\n detail = effective.onInvalidPropertyValue !== 'ignore' ? 'error' : 'ignore';\n break;\n case 'undefinedPropertyValue':\n detail = effective.onUndefinedPropertyValue !== 'error' ? 'ignore' : 'error';\n /* c8 ignore next */\n message = message ?? 'Cannot convert undefined to JSON';\n break;\n }\n /* c8 ignore next */\n return failWithDetail(message ?? rule, detail);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../../src/packlets/editor/rules/templates.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,EAAoD,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AACrG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD;;;GAGG;AACH,MAAM,WAAW,yBAA0B,SAAQ,OAAO,CAAC,kBAAkB,CAAC;IAC5E;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,kBAAkB;IAC7D;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,yBAAyB,CAAC;IAE/C;;;;OAIG;gBACgB,OAAO,CAAC,EAAE,yBAAyB;IAKtD;;;;OAIG;WACW,MAAM,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,MAAM,CAAC,uBAAuB,CAAC;IAI1F;;;;;;;;;OASG;IACI,YAAY,CACjB,GAAG,EAAE,MAAM,E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ACH,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,cAAc,CAAC,MAAM,EAAE,qBAAqB,CAAC;CAO3G"}
|
|
@@ -63,9 +63,10 @@ class TemplatedJsonEditorRule extends jsonEditorRule_1.JsonEditorRuleBase {
|
|
|
63
63
|
*/
|
|
64
64
|
editProperty(key, value, state) {
|
|
65
65
|
var _a, _b;
|
|
66
|
-
/* c8 ignore next */
|
|
66
|
+
/* c8 ignore next 2 */
|
|
67
67
|
const validation = (_a = this._options) === null || _a === void 0 ? void 0 : _a.validation;
|
|
68
|
-
|
|
68
|
+
const useNameTemplates = ((_b = this._options) === null || _b === void 0 ? void 0 : _b.useNameTemplates) !== false;
|
|
69
|
+
if (useNameTemplates !== false) {
|
|
69
70
|
const result = this._render(key, state).onSuccess((newKey) => {
|
|
70
71
|
if (newKey.length < 1) {
|
|
71
72
|
return state.failValidation('invalidPropertyName', `Template "${key}" renders empty name.`);
|
|
@@ -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;IACI,YAAY,CACjB,GAAW,EACX,KAAgB,EAChB,KAAsB;;QAEtB,
|
|
1
|
+
{"version":3,"file":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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;AA5GD,0DA4GC","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 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 2 */\n const validation = this._options?.validation;\n const useNameTemplates = this._options?.useNameTemplates !== false;\n\n if (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": "4.0
|
|
3
|
+
"version": "4.2.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,42 +16,41 @@
|
|
|
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": "4.0
|
|
20
|
-
"@fgv/ts-utils-jest": "4.0
|
|
21
|
-
"@types/jest": "^29.5.
|
|
19
|
+
"@fgv/ts-utils": "4.2.0",
|
|
20
|
+
"@fgv/ts-utils-jest": "4.2.0",
|
|
21
|
+
"@types/jest": "^29.5.14",
|
|
22
22
|
"@types/mustache": "^4.2.5",
|
|
23
|
-
"@types/node": "^20.
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
25
|
-
"@typescript-eslint/parser": "^7.
|
|
23
|
+
"@types/node": "^20.14.9",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^7.14.1",
|
|
25
|
+
"@typescript-eslint/parser": "^7.14.1",
|
|
26
26
|
"eslint": "^8.57.0",
|
|
27
|
-
"eslint-
|
|
28
|
-
"eslint-plugin-import": "^2.29.1",
|
|
27
|
+
"eslint-plugin-import": "^2.31.0",
|
|
29
28
|
"eslint-plugin-node": "^11.1.0",
|
|
30
|
-
"eslint-plugin-promise": "^6.
|
|
29
|
+
"eslint-plugin-promise": "^6.2.0",
|
|
31
30
|
"jest": "^29.7.0",
|
|
32
31
|
"jest-extended": "^4.0.2",
|
|
33
32
|
"mustache": "^4.2.0",
|
|
34
33
|
"rimraf": "^5.0.7",
|
|
35
|
-
"ts-jest": "^29.
|
|
34
|
+
"ts-jest": "^29.2.5",
|
|
36
35
|
"ts-node": "^10.9.2",
|
|
37
|
-
"typescript": "^5.
|
|
36
|
+
"typescript": "^5.7.3",
|
|
38
37
|
"eslint-plugin-n": "^16.6.2",
|
|
39
|
-
"@rushstack/heft-node-rig": "~2.6.
|
|
40
|
-
"@rushstack/heft": "~0.
|
|
38
|
+
"@rushstack/heft-node-rig": "~2.6.49",
|
|
39
|
+
"@rushstack/heft": "~0.68.13",
|
|
41
40
|
"heft-jest": "~1.0.2",
|
|
42
41
|
"@types/heft-jest": "1.0.6",
|
|
43
|
-
"@microsoft/api-documenter": "^7.
|
|
44
|
-
"@fgv/ts-json-base": "4.0
|
|
42
|
+
"@microsoft/api-documenter": "^7.26.5",
|
|
43
|
+
"@fgv/ts-json-base": "4.2.0"
|
|
45
44
|
},
|
|
46
45
|
"peerDependencies": {
|
|
47
|
-
"@fgv/ts-utils": "4.0
|
|
48
|
-
"@fgv/ts-json-base": "4.0
|
|
46
|
+
"@fgv/ts-utils": "4.2.0",
|
|
47
|
+
"@fgv/ts-json-base": "4.2.0",
|
|
49
48
|
"mustache": "^4.2.0"
|
|
50
49
|
},
|
|
51
50
|
"scripts": {
|
|
52
51
|
"build": "heft test --clean",
|
|
53
52
|
"clean": "heft clean",
|
|
54
|
-
"test": "heft test",
|
|
53
|
+
"test": "heft test --clean",
|
|
55
54
|
"build-docs": "api-documenter markdown --input-folder ./temp --output-folder docs",
|
|
56
55
|
"build-all": "rushx build; rushx build-docs",
|
|
57
56
|
"test-handles": "jest --runInBand --detectOpenHandles",
|