@fgv/ts-json 1.9.6 → 2.0.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/ts-json.d.ts +1826 -0
  2. package/dist/tsdoc-metadata.json +11 -0
  3. package/lib/index.d.ts +5 -0
  4. package/lib/index.d.ts.map +1 -0
  5. package/lib/index.js +42 -0
  6. package/lib/index.js.map +1 -0
  7. package/lib/packlets/context/compositeJsonMap.d.ts +60 -0
  8. package/lib/packlets/context/compositeJsonMap.d.ts.map +1 -0
  9. package/lib/packlets/context/compositeJsonMap.js +105 -0
  10. package/lib/packlets/context/compositeJsonMap.js.map +1 -0
  11. package/lib/packlets/context/contextHelpers.d.ts +116 -0
  12. package/lib/packlets/context/contextHelpers.d.ts.map +1 -0
  13. package/lib/packlets/context/contextHelpers.js +191 -0
  14. package/lib/packlets/context/contextHelpers.js.map +1 -0
  15. package/lib/packlets/context/index.d.ts +4 -0
  16. package/lib/packlets/context/index.d.ts.map +1 -0
  17. package/lib/packlets/context/index.js +31 -0
  18. package/lib/packlets/context/index.js.map +1 -0
  19. package/lib/packlets/context/jsonContext.d.ts +84 -0
  20. package/lib/packlets/context/jsonContext.d.ts.map +1 -0
  21. package/lib/packlets/context/jsonContext.js +41 -0
  22. package/lib/packlets/context/jsonContext.js.map +1 -0
  23. package/lib/packlets/converters/converters.d.ts +54 -0
  24. package/lib/packlets/converters/converters.d.ts.map +1 -0
  25. package/lib/packlets/converters/converters.js +105 -0
  26. package/lib/packlets/converters/converters.js.map +1 -0
  27. package/lib/packlets/converters/file.d.ts +83 -0
  28. package/lib/packlets/converters/file.d.ts.map +1 -0
  29. package/lib/packlets/converters/file.js +162 -0
  30. package/lib/packlets/converters/file.js.map +1 -0
  31. package/lib/packlets/converters/index.d.ts +5 -0
  32. package/lib/packlets/converters/index.d.ts.map +1 -0
  33. package/lib/packlets/converters/index.js +56 -0
  34. package/lib/packlets/converters/index.js.map +1 -0
  35. package/lib/packlets/converters/jsonConverter.d.ts +276 -0
  36. package/lib/packlets/converters/jsonConverter.d.ts.map +1 -0
  37. package/lib/packlets/converters/jsonConverter.js +310 -0
  38. package/lib/packlets/converters/jsonConverter.js.map +1 -0
  39. package/lib/packlets/editor/common.d.ts +67 -0
  40. package/lib/packlets/editor/common.d.ts.map +1 -0
  41. package/lib/packlets/editor/common.js +3 -0
  42. package/lib/packlets/editor/common.js.map +1 -0
  43. package/lib/packlets/editor/index.d.ts +8 -0
  44. package/lib/packlets/editor/index.d.ts.map +1 -0
  45. package/{jsonEditor → lib/packlets/editor}/index.js +15 -9
  46. package/lib/packlets/editor/index.js.map +1 -0
  47. package/lib/packlets/editor/jsonEditor.d.ts +155 -0
  48. package/lib/packlets/editor/jsonEditor.d.ts.map +1 -0
  49. package/lib/packlets/editor/jsonEditor.js +332 -0
  50. package/lib/packlets/editor/jsonEditor.js.map +1 -0
  51. package/lib/packlets/editor/jsonEditorRule.d.ts +64 -0
  52. package/lib/packlets/editor/jsonEditorRule.d.ts.map +1 -0
  53. package/lib/packlets/editor/jsonEditorRule.js +54 -0
  54. package/lib/packlets/editor/jsonEditorRule.js.map +1 -0
  55. package/lib/packlets/editor/jsonEditorState.d.ts +125 -0
  56. package/lib/packlets/editor/jsonEditorState.d.ts.map +1 -0
  57. package/lib/packlets/editor/jsonEditorState.js +177 -0
  58. package/lib/packlets/editor/jsonEditorState.js.map +1 -0
  59. package/lib/packlets/editor/jsonReferenceMap.d.ts +303 -0
  60. package/lib/packlets/editor/jsonReferenceMap.d.ts.map +1 -0
  61. package/lib/packlets/editor/jsonReferenceMap.js +324 -0
  62. package/lib/packlets/editor/jsonReferenceMap.js.map +1 -0
  63. package/lib/packlets/editor/rules/conditional.d.ts +107 -0
  64. package/lib/packlets/editor/rules/conditional.d.ts.map +1 -0
  65. package/lib/packlets/editor/rules/conditional.js +167 -0
  66. package/lib/packlets/editor/rules/conditional.js.map +1 -0
  67. package/{jsonEditor → lib/packlets/editor}/rules/index.d.ts +1 -0
  68. package/lib/packlets/editor/rules/index.d.ts.map +1 -0
  69. package/lib/packlets/editor/rules/index.js +42 -0
  70. package/lib/packlets/editor/rules/index.js.map +1 -0
  71. package/lib/packlets/editor/rules/multivalue.d.ts +94 -0
  72. package/lib/packlets/editor/rules/multivalue.d.ts.map +1 -0
  73. package/lib/packlets/editor/rules/multivalue.js +141 -0
  74. package/lib/packlets/editor/rules/multivalue.js.map +1 -0
  75. package/lib/packlets/editor/rules/references.d.ts +69 -0
  76. package/lib/packlets/editor/rules/references.d.ts.map +1 -0
  77. package/lib/packlets/editor/rules/references.js +159 -0
  78. package/lib/packlets/editor/rules/references.js.map +1 -0
  79. package/lib/packlets/editor/rules/templates.d.ts +74 -0
  80. package/lib/packlets/editor/rules/templates.d.ts.map +1 -0
  81. package/lib/packlets/editor/rules/templates.js +127 -0
  82. package/lib/packlets/editor/rules/templates.js.map +1 -0
  83. package/lib/packlets/json/common.d.ts +85 -0
  84. package/lib/packlets/json/common.d.ts.map +1 -0
  85. package/lib/packlets/json/common.js +123 -0
  86. package/lib/packlets/json/common.js.map +1 -0
  87. package/lib/packlets/json/index.d.ts +2 -0
  88. package/lib/packlets/json/index.d.ts.map +1 -0
  89. package/lib/packlets/json/index.js +39 -0
  90. package/lib/packlets/json/index.js.map +1 -0
  91. package/package.json +58 -49
  92. package/common.d.ts +0 -58
  93. package/common.js +0 -116
  94. package/compositeJsonMap.d.ts +0 -47
  95. package/compositeJsonMap.js +0 -97
  96. package/contextHelpers.d.ts +0 -21
  97. package/contextHelpers.js +0 -101
  98. package/converters.d.ts +0 -37
  99. package/converters.js +0 -92
  100. package/file.d.ts +0 -60
  101. package/file.js +0 -140
  102. package/index.d.ts +0 -10
  103. package/index.js +0 -62
  104. package/jsonContext.d.ts +0 -74
  105. package/jsonContext.js +0 -40
  106. package/jsonConverter.d.ts +0 -229
  107. package/jsonConverter.js +0 -292
  108. package/jsonEditor/common.d.ts +0 -36
  109. package/jsonEditor/common.js +0 -3
  110. package/jsonEditor/index.d.ts +0 -5
  111. package/jsonEditor/jsonEditor.d.ts +0 -74
  112. package/jsonEditor/jsonEditor.js +0 -259
  113. package/jsonEditor/jsonEditorRule.d.ts +0 -47
  114. package/jsonEditor/jsonEditorRule.js +0 -44
  115. package/jsonEditor/jsonEditorState.d.ts +0 -24
  116. package/jsonEditor/jsonEditorState.js +0 -86
  117. package/jsonEditor/rules/conditional.d.ts +0 -84
  118. package/jsonEditor/rules/conditional.js +0 -146
  119. package/jsonEditor/rules/index.js +0 -21
  120. package/jsonEditor/rules/multivalue.d.ts +0 -78
  121. package/jsonEditor/rules/multivalue.js +0 -129
  122. package/jsonEditor/rules/references.d.ts +0 -62
  123. package/jsonEditor/rules/references.js +0 -158
  124. package/jsonEditor/rules/templates.d.ts +0 -56
  125. package/jsonEditor/rules/templates.js +0 -115
  126. package/jsonReferenceMap.d.ts +0 -138
  127. package/jsonReferenceMap.js +0 -202
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.defaultExtendVars = exports.JsonContextHelper = exports.CompositeJsonMap = void 0;
25
+ var compositeJsonMap_1 = require("./compositeJsonMap");
26
+ Object.defineProperty(exports, "CompositeJsonMap", { enumerable: true, get: function () { return compositeJsonMap_1.CompositeJsonMap; } });
27
+ var contextHelpers_1 = require("./contextHelpers");
28
+ Object.defineProperty(exports, "JsonContextHelper", { enumerable: true, get: function () { return contextHelpers_1.JsonContextHelper; } });
29
+ var jsonContext_1 = require("./jsonContext");
30
+ Object.defineProperty(exports, "defaultExtendVars", { enumerable: true, get: function () { return jsonContext_1.defaultExtendVars; } });
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/context/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,mDAAqD;AAA5C,mHAAA,iBAAiB,OAAA;AAC1B,6CAQuB;AADrB,gHAAA,iBAAiB,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\nexport { CompositeJsonMap } from './compositeJsonMap';\nexport { JsonContextHelper } from './contextHelpers';\nexport {\n IJsonContext,\n IJsonReferenceMap,\n JsonReferenceMapFailureReason,\n TemplateVars,\n TemplateVarsExtendFunction,\n VariableValue,\n defaultExtendVars\n} from './jsonContext';\n"]}
@@ -0,0 +1,84 @@
1
+ import { DetailedResult, Result } from '@fgv/ts-utils';
2
+ import { JsonObject, JsonValue } from '../json';
3
+ /**
4
+ * Collection of variables used for template replacement in a JSON edit or
5
+ * conversion.
6
+ * @public
7
+ */
8
+ export type TemplateVars = Record<string, unknown>;
9
+ /**
10
+ * Describes one value in a {@link TemplateVars | TemplateVars} collection of
11
+ * variables.
12
+ * @public
13
+ */
14
+ export type VariableValue = [string, unknown];
15
+ /**
16
+ * Function used to create a new collection of {@link TemplateVars | TemplateVars} with
17
+ * one or more new or changed values.
18
+ * @public
19
+ */
20
+ export type TemplateVarsExtendFunction = (base: TemplateVars | undefined, values: VariableValue[]) => Result<TemplateVars | undefined>;
21
+ /**
22
+ * This default implementation of a {@link TemplateVarsExtendFunction | TemplateVarsExtendFunction}
23
+ * creates a new collection via inheritance from the supplied collection.
24
+ * @param base - The base {@link TemplateVars | variables} to be extended.
25
+ * @param values - The {@link VariableValue | values} to be added or overridden in the new variables.
26
+ * @public
27
+ */
28
+ export declare function defaultExtendVars(base: TemplateVars | undefined, values: VariableValue[]): Result<TemplateVars | undefined>;
29
+ /**
30
+ * Failure reason for {@link IJsonReferenceMap | IJsonReferenceMap} lookup, where `'unknown'`
31
+ * means that the object is not present in the map and `'error'` means
32
+ * that an error occurred while retrieving or converting it.
33
+ * @public
34
+ */
35
+ export type JsonReferenceMapFailureReason = 'unknown' | 'error';
36
+ /**
37
+ * Interface for a simple map that returns named {@link JsonValue | JsonValue} values with templating,
38
+ * conditional logic, and external reference lookups applied using an optionally supplied context.
39
+ * @public
40
+ */
41
+ export interface IJsonReferenceMap {
42
+ /**
43
+ * Determine if a key might be valid for this map but does not determine if key actually
44
+ * exists. Allows key range to be constrained.
45
+ * @param key - The key to be tested.
46
+ * @returns `true` if the key is in the valid range, `false` otherwise.
47
+ */
48
+ keyIsInRange(key: string): boolean;
49
+ /**
50
+ * Determines if an object with the specified key actually exists in the map.
51
+ * @param key - The key to be tested.
52
+ * @returns `true` if an object with the specified key exists, `false` otherwise.
53
+ */
54
+ has(key: string): boolean;
55
+ /**
56
+ * Gets a {@link JsonObject | JsonObject} specified by key.
57
+ * @param key - The key of the object to be retrieved.
58
+ * @param context - Optional {@link IJsonContext | IJsonContext} used to construct
59
+ * the object.
60
+ * @returns `Success` with the formatted {@link JsonObject | object} if successful. `Failure`
61
+ * with detail `'unknown'` if no such object exists, or `Failure` with detail `'error'` if
62
+ * the object was found but could not be formatted.
63
+ */
64
+ getJsonObject(key: string, context?: IJsonContext): DetailedResult<JsonObject, JsonReferenceMapFailureReason>;
65
+ /**
66
+ * Gets a {@link JsonValue | JsonValue} specified by key.
67
+ * @param key - The key of the object to be retrieved.
68
+ * @param context - Optional {@link IJsonContext | JSON Context} used to format the value
69
+ * @returns `Success` with the formatted {@link JsonValue | value} if successful. `Failure`
70
+ * with detail `'unknown'` if no such object exists, or `Failure` with detail `'error'` if
71
+ * the object was found but could not be formatted.
72
+ */
73
+ getJsonValue(key: string, context?: IJsonContext): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;
74
+ }
75
+ /**
76
+ * Context used to convert or edit JSON objects.
77
+ * @public
78
+ */
79
+ export interface IJsonContext {
80
+ vars?: TemplateVars;
81
+ refs?: IJsonReferenceMap;
82
+ extendVars?: TemplateVarsExtendFunction;
83
+ }
84
+ //# sourceMappingURL=jsonContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonContext.d.ts","sourceRoot":"","sources":["../../../src/packlets/context/jsonContext.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAW,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnD;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE9C;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG,CACvC,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,MAAM,EAAE,aAAa,EAAE,KACpB,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;AAEtC;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,MAAM,EAAE,aAAa,EAAE,GACtB,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC,CAMlC;AAED;;;;;GAKG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,OAAO,CAAC;AAEhE;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;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"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2020 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.defaultExtendVars = void 0;
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ /**
27
+ * This default implementation of a {@link TemplateVarsExtendFunction | TemplateVarsExtendFunction}
28
+ * creates a new collection via inheritance from the supplied collection.
29
+ * @param base - The base {@link TemplateVars | variables} to be extended.
30
+ * @param values - The {@link VariableValue | values} to be added or overridden in the new variables.
31
+ * @public
32
+ */
33
+ function defaultExtendVars(base, values) {
34
+ const rtrn = base ? Object.create(base) : {};
35
+ for (const v of values) {
36
+ rtrn[v[0]] = v[1];
37
+ }
38
+ return (0, ts_utils_1.succeed)(rtrn);
39
+ }
40
+ exports.defaultExtendVars = defaultExtendVars;
41
+ //# sourceMappingURL=jsonContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonContext.js","sourceRoot":"","sources":["../../../src/packlets/context/jsonContext.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAgE;AA2BhE;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,IAA8B,EAC9B,MAAuB;IAEvB,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;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KACnB;IACD,OAAO,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC;AACvB,CAAC;AATD,8CASC","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 { DetailedResult, Result, succeed } from '@fgv/ts-utils';\nimport { JsonObject, JsonValue } from '../json';\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 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 {@link JsonValue | 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 {@link JsonObject | 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 {@link JsonObject | object} 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 {@link JsonValue | 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 {@link JsonValue | value} 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"]}
@@ -0,0 +1,54 @@
1
+ import { Converter } from '@fgv/ts-utils';
2
+ import { IJsonContext } from '../context';
3
+ import { JsonArray, JsonObject } from '../json';
4
+ import { ConditionalJsonConverterOptions, JsonConverter, RichJsonConverterOptions, TemplatedJsonConverterOptions } from './jsonConverter';
5
+ /**
6
+ * A simple validating {@link JsonConverter | JSON converter}. Converts unknown to
7
+ * JSON or fails if the unknown contains any invalid JSON values.
8
+ * @public
9
+ */
10
+ export declare const json: JsonConverter;
11
+ /**
12
+ * A simple validating {@link JsonConverter | JSON converter}. Converts unknown
13
+ * to a {@link JsonObject | JsonObject}, or fails if the `unknown` contains invalid
14
+ * JSON or is not an object.
15
+ * @public
16
+ */
17
+ export declare const jsonObject: Converter<JsonObject, IJsonContext>;
18
+ /**
19
+ * A simple validating {@link JsonConverter | JSON converter}. Converts `unknown` to a
20
+ * {@link JsonArray | JsonArray}, or fails if the unknown contains invalid JSON or is
21
+ * not an array.
22
+ * @public
23
+ */
24
+ export declare const jsonArray: Converter<JsonArray, IJsonContext>;
25
+ /**
26
+ * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts an
27
+ * `unknown` value to JSON, rendering any property names or string values using mustache with
28
+ * the supplied context. See the mustache documentation for details of mustache syntax and view.
29
+ * @param options - {@link TemplatedJsonConverterOptions | Options and context} for
30
+ * the conversion.
31
+ * @public
32
+ */
33
+ export declare function templatedJson(options?: Partial<TemplatedJsonConverterOptions>): JsonConverter;
34
+ /**
35
+ * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
36
+ * supplied `unknown` to strongly-typed JSON, by first rendering any property
37
+ * names or string values using mustache with the supplied context, then applying
38
+ * multi-value property expansion and conditional flattening based on property names.
39
+ * @param options - {@link ConditionalJsonConverterOptions | Options and context} for
40
+ * the conversion.
41
+ * @public
42
+ */
43
+ export declare function conditionalJson(options?: Partial<ConditionalJsonConverterOptions>): JsonConverter;
44
+ /**
45
+ * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
46
+ * supplied `unknown` to strongly-typed JSON, by first rendering any property
47
+ * names or string values using mustache with the supplied context, then applying
48
+ * multi-value property expansion and conditional flattening based on property names.
49
+ * @param options - {@link RichJsonConverterOptions | Options and context} for
50
+ * the conversion.
51
+ * @public
52
+ */
53
+ export declare function richJson(options?: Partial<RichJsonConverterOptions>): JsonConverter;
54
+ //# sourceMappingURL=converters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/packlets/converters/converters.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAEL,+BAA+B,EAC/B,aAAa,EAEb,wBAAwB,EAExB,6BAA6B,EAC9B,MAAM,iBAAiB,CAAC;AAEzB;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,aAAmC,CAAC;AAEvD;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE,SAAS,CAAC,UAAU,EAAE,YAAY,CAAiB,CAAC;AAE7E;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,YAAY,CAAgB,CAAC;AAM1E;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,6BAA6B,CAAC,GAAG,aAAa,CAQ7F;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,+BAA+B,CAAC,GAAG,aAAa,CAQjG;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,aAAa,CAQnF"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2020 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.richJson = exports.conditionalJson = exports.templatedJson = exports.jsonArray = exports.jsonObject = exports.json = void 0;
25
+ const jsonConverter_1 = require("./jsonConverter");
26
+ /**
27
+ * A simple validating {@link JsonConverter | JSON converter}. Converts unknown to
28
+ * JSON or fails if the unknown contains any invalid JSON values.
29
+ * @public
30
+ */
31
+ exports.json = new jsonConverter_1.JsonConverter();
32
+ /**
33
+ * A simple validating {@link JsonConverter | JSON converter}. Converts unknown
34
+ * to a {@link JsonObject | JsonObject}, or fails if the `unknown` contains invalid
35
+ * JSON or is not an object.
36
+ * @public
37
+ */
38
+ exports.jsonObject = exports.json.object();
39
+ /**
40
+ * A simple validating {@link JsonConverter | JSON converter}. Converts `unknown` to a
41
+ * {@link JsonArray | JsonArray}, or fails if the unknown contains invalid JSON or is
42
+ * not an array.
43
+ * @public
44
+ */
45
+ exports.jsonArray = exports.json.array();
46
+ let templatedJsonDefault;
47
+ let conditionalJsonDefault;
48
+ let richJsonDefault;
49
+ /**
50
+ * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts an
51
+ * `unknown` value to JSON, rendering any property names or string values using mustache with
52
+ * the supplied context. See the mustache documentation for details of mustache syntax and view.
53
+ * @param options - {@link TemplatedJsonConverterOptions | Options and context} for
54
+ * the conversion.
55
+ * @public
56
+ */
57
+ function templatedJson(options) {
58
+ if (!options) {
59
+ if (!templatedJsonDefault) {
60
+ templatedJsonDefault = new jsonConverter_1.TemplatedJsonConverter();
61
+ }
62
+ return templatedJsonDefault;
63
+ }
64
+ return new jsonConverter_1.TemplatedJsonConverter(options);
65
+ }
66
+ exports.templatedJson = templatedJson;
67
+ /**
68
+ * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
69
+ * supplied `unknown` to strongly-typed JSON, by first rendering any property
70
+ * names or string values using mustache with the supplied context, then applying
71
+ * multi-value property expansion and conditional flattening based on property names.
72
+ * @param options - {@link ConditionalJsonConverterOptions | Options and context} for
73
+ * the conversion.
74
+ * @public
75
+ */
76
+ function conditionalJson(options) {
77
+ if (!options) {
78
+ if (!conditionalJsonDefault) {
79
+ conditionalJsonDefault = new jsonConverter_1.ConditionalJsonConverter();
80
+ }
81
+ return conditionalJsonDefault;
82
+ }
83
+ return new jsonConverter_1.ConditionalJsonConverter(options);
84
+ }
85
+ exports.conditionalJson = conditionalJson;
86
+ /**
87
+ * Helper function which creates a new {@link JsonConverter | JsonConverter} which converts a
88
+ * supplied `unknown` to strongly-typed JSON, by first rendering any property
89
+ * names or string values using mustache with the supplied context, then applying
90
+ * multi-value property expansion and conditional flattening based on property names.
91
+ * @param options - {@link RichJsonConverterOptions | Options and context} for
92
+ * the conversion.
93
+ * @public
94
+ */
95
+ function richJson(options) {
96
+ if (!options) {
97
+ if (!richJsonDefault) {
98
+ richJsonDefault = new jsonConverter_1.RichJsonConverter();
99
+ }
100
+ return richJsonDefault;
101
+ }
102
+ return new jsonConverter_1.RichJsonConverter(options);
103
+ }
104
+ exports.richJson = richJson;
105
+ //# sourceMappingURL=converters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converters.js","sourceRoot":"","sources":["../../../src/packlets/converters/converters.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAKH,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;QACZ,IAAI,CAAC,oBAAoB,EAAE;YACzB,oBAAoB,GAAG,IAAI,sCAAsB,EAAE,CAAC;SACrD;QACD,OAAO,oBAAoB,CAAC;KAC7B;IACD,OAAO,IAAI,sCAAsB,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC;AARD,sCAQC;AAED;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,OAAkD;IAChF,IAAI,CAAC,OAAO,EAAE;QACZ,IAAI,CAAC,sBAAsB,EAAE;YAC3B,sBAAsB,GAAG,IAAI,wCAAwB,EAAE,CAAC;SACzD;QACD,OAAO,sBAAsB,CAAC;KAC/B;IACD,OAAO,IAAI,wCAAwB,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC;AARD,0CAQC;AAED;;;;;;;;GAQG;AACH,SAAgB,QAAQ,CAAC,OAA2C;IAClE,IAAI,CAAC,OAAO,EAAE;QACZ,IAAI,CAAC,eAAe,EAAE;YACpB,eAAe,GAAG,IAAI,iCAAiB,EAAE,CAAC;SAC3C;QACD,OAAO,eAAe,CAAC;KACxB;IACD,OAAO,IAAI,iCAAiB,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC;AARD,4BAQC","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 { Converter } from '@fgv/ts-utils';\nimport { IJsonContext } from '../context';\nimport { JsonArray, JsonObject } from '../json';\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 {@link JsonObject | 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 * {@link JsonArray | 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"]}
@@ -0,0 +1,83 @@
1
+ import { Converter, Result } from '@fgv/ts-utils';
2
+ import { JsonValue } from '../json';
3
+ /**
4
+ * Convenience function to read type-safe JSON from a file
5
+ * @param srcPath - Path of the file to read
6
+ * @returns `Success` with a {@link JsonValue | JsonValue} or `Failure`
7
+ * with a message if an error occurs.
8
+ * @public
9
+ */
10
+ export declare function readJsonFileSync(srcPath: string): Result<JsonValue>;
11
+ /**
12
+ * Convenience function to read a JSON file and apply a supplied converter.
13
+ * @param srcPath - Path of the file to read.
14
+ * @param converter - `Converter` used to convert the file contents
15
+ * @returns `Success` with a result of type `<T>`, or `Failure`
16
+ * with a message if an error occurs.
17
+ * @public
18
+ */
19
+ export declare function convertJsonFileSync<T>(srcPath: string, converter: Converter<T>): Result<T>;
20
+ /**
21
+ * Options for directory conversion.
22
+ * TODO: add filtering, allowed and excluded.
23
+ * @public
24
+ */
25
+ export interface IDirectoryConvertOptions<T, TC = unknown> {
26
+ /**
27
+ * The converter used to convert incoming JSON objects.
28
+ */
29
+ converter: Converter<T, TC>;
30
+ }
31
+ /**
32
+ * Return value for one item in a directory conversion.
33
+ * @public
34
+ */
35
+ export interface IReadDirectoryItem<T> {
36
+ /**
37
+ * Relative name of the file that was processed
38
+ */
39
+ filename: string;
40
+ /**
41
+ * The payload of the file.
42
+ */
43
+ item: T;
44
+ }
45
+ /**
46
+ * Reads all JSON files from a directory and apply a supplied converter.
47
+ * @param srcPath - The path of the folder to be read.
48
+ * @param options - {@link Files.IDirectoryConvertOptions | Options} to control
49
+ * conversion and filtering
50
+ * @public
51
+ */
52
+ export declare function convertJsonDirectorySync<T>(srcPath: string, options: IDirectoryConvertOptions<T>): Result<IReadDirectoryItem<T>[]>;
53
+ /**
54
+ * Function to transform the name of a some entity, given an original name
55
+ * and the contents of the entity.
56
+ * @public
57
+ */
58
+ export type ItemNameTransformFunction<T> = (name: string, item: T) => Result<string>;
59
+ /**
60
+ * Options controlling conversion of a directory.
61
+ * @public
62
+ */
63
+ export interface IDirectoryToMapConvertOptions<T, TC = unknown> extends IDirectoryConvertOptions<T, TC> {
64
+ transformName?: ItemNameTransformFunction<T>;
65
+ }
66
+ /**
67
+ * Reads and converts all JSON files from a directory, returning a
68
+ * `Map<string, T>` indexed by file base name (i.e. minus the extension)
69
+ * with an optional name transformation applied if present.
70
+ * @param srcPath - The path of the folder to be read.
71
+ * @param options - {@link Files.IDirectoryToMapConvertOptions | Options} to control conversion,
72
+ * filtering and naming.
73
+ * @public
74
+ */
75
+ export declare function convertJsonDirectoryToMapSync<T, TC = unknown>(srcPath: string, options: IDirectoryToMapConvertOptions<T, TC>): Result<Map<string, T>>;
76
+ /**
77
+ * Convenience function to write type-safe JSON to a file.
78
+ * @param srcPath - Path of the file to write.
79
+ * @param value - The {@link JsonValue | JsonValue} to be written.
80
+ * @public
81
+ */
82
+ export declare function writeJsonFileSync(srcPath: string, value: JsonValue): Result<boolean>;
83
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/packlets/converters/file.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,EAA4C,MAAM,eAAe,CAAC;AAI5F,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAMnE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAI1F;AAED;;;;GAIG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO;IACvD;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC;CACT;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAC,GACnC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC,CA2BjC;AAED;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC;AAErF;;;GAGG;AACH,MAAM,WAAW,6BAA6B,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAAE,SAAQ,wBAAwB,CAAC,CAAC,EAAE,EAAE,CAAC;IACrG,aAAa,CAAC,EAAE,yBAAyB,CAAC,CAAC,CAAC,CAAC;CAC9C;AAWD;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EAC3D,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,6BAA6B,CAAC,CAAC,EAAE,EAAE,CAAC,GAC5C,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAcxB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAMpF"}
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2020 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
35
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
36
+ }) : function(o, v) {
37
+ o["default"] = v;
38
+ });
39
+ var __importStar = (this && this.__importStar) || function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.writeJsonFileSync = exports.convertJsonDirectoryToMapSync = exports.convertJsonDirectorySync = exports.convertJsonFileSync = exports.readJsonFileSync = void 0;
48
+ const ts_utils_1 = require("@fgv/ts-utils");
49
+ const fs = __importStar(require("fs"));
50
+ const path = __importStar(require("path"));
51
+ /**
52
+ * Convenience function to read type-safe JSON from a file
53
+ * @param srcPath - Path of the file to read
54
+ * @returns `Success` with a {@link JsonValue | JsonValue} or `Failure`
55
+ * with a message if an error occurs.
56
+ * @public
57
+ */
58
+ function readJsonFileSync(srcPath) {
59
+ return (0, ts_utils_1.captureResult)(() => {
60
+ const fullPath = path.resolve(srcPath);
61
+ const body = fs.readFileSync(fullPath, 'utf8').toString();
62
+ return JSON.parse(body);
63
+ });
64
+ }
65
+ exports.readJsonFileSync = readJsonFileSync;
66
+ /**
67
+ * Convenience function to read a JSON file and apply a supplied converter.
68
+ * @param srcPath - Path of the file to read.
69
+ * @param converter - `Converter` used to convert the file contents
70
+ * @returns `Success` with a result of type `<T>`, or `Failure`
71
+ * with a message if an error occurs.
72
+ * @public
73
+ */
74
+ function convertJsonFileSync(srcPath, converter) {
75
+ return readJsonFileSync(srcPath).onSuccess((json) => {
76
+ return converter.convert(json);
77
+ });
78
+ }
79
+ exports.convertJsonFileSync = convertJsonFileSync;
80
+ /**
81
+ * Reads all JSON files from a directory and apply a supplied converter.
82
+ * @param srcPath - The path of the folder to be read.
83
+ * @param options - {@link Files.IDirectoryConvertOptions | Options} to control
84
+ * conversion and filtering
85
+ * @public
86
+ */
87
+ function convertJsonDirectorySync(srcPath, options) {
88
+ return (0, ts_utils_1.captureResult)(() => {
89
+ const fullPath = path.resolve(srcPath);
90
+ if (!fs.statSync(fullPath).isDirectory()) {
91
+ throw new Error(`${fullPath}: Not a directory`);
92
+ }
93
+ const files = fs.readdirSync(fullPath, { withFileTypes: true });
94
+ const results = files
95
+ .map((fi) => {
96
+ if (fi.isFile() && path.extname(fi.name) === '.json') {
97
+ const filePath = path.resolve(fullPath, fi.name);
98
+ return convertJsonFileSync(filePath, options.converter)
99
+ .onSuccess((payload) => {
100
+ return (0, ts_utils_1.succeed)({
101
+ filename: fi.name,
102
+ item: payload
103
+ });
104
+ })
105
+ .onFailure((message) => {
106
+ return (0, ts_utils_1.fail)(`${fi.name}: ${message}`);
107
+ });
108
+ }
109
+ return undefined;
110
+ })
111
+ .filter((r) => r !== undefined);
112
+ return (0, ts_utils_1.mapResults)(results).orThrow();
113
+ });
114
+ }
115
+ exports.convertJsonDirectorySync = convertJsonDirectorySync;
116
+ /**
117
+ * Function to transform the name of some entity, given only a previous name. This
118
+ * default implementation always returns `Success` with the value that was passed in.
119
+ * @param n - The name to be transformed.
120
+ * @returns - `Success` with the string that was passed in.
121
+ * @public
122
+ */
123
+ const defaultNameTransformer = (n) => (0, ts_utils_1.succeed)(n);
124
+ /**
125
+ * Reads and converts all JSON files from a directory, returning a
126
+ * `Map<string, T>` indexed by file base name (i.e. minus the extension)
127
+ * with an optional name transformation applied if present.
128
+ * @param srcPath - The path of the folder to be read.
129
+ * @param options - {@link Files.IDirectoryToMapConvertOptions | Options} to control conversion,
130
+ * filtering and naming.
131
+ * @public
132
+ */
133
+ function convertJsonDirectoryToMapSync(srcPath, options) {
134
+ return convertJsonDirectorySync(srcPath, options).onSuccess((items) => {
135
+ var _a;
136
+ const transformName = (_a = options.transformName) !== null && _a !== void 0 ? _a : defaultNameTransformer;
137
+ return (0, ts_utils_1.mapResults)(items.map((item) => {
138
+ const basename = path.basename(item.filename, '.json');
139
+ return transformName(basename, item.item).onSuccess((name) => {
140
+ return (0, ts_utils_1.succeed)([name, item.item]);
141
+ });
142
+ })).onSuccess((items) => {
143
+ return (0, ts_utils_1.succeed)(new Map(items));
144
+ });
145
+ });
146
+ }
147
+ exports.convertJsonDirectoryToMapSync = convertJsonDirectoryToMapSync;
148
+ /**
149
+ * Convenience function to write type-safe JSON to a file.
150
+ * @param srcPath - Path of the file to write.
151
+ * @param value - The {@link JsonValue | JsonValue} to be written.
152
+ * @public
153
+ */
154
+ function writeJsonFileSync(srcPath, value) {
155
+ return (0, ts_utils_1.captureResult)(() => {
156
+ const fullPath = path.resolve(srcPath);
157
+ fs.writeFileSync(fullPath, JSON.stringify(value, undefined, 2));
158
+ return true;
159
+ });
160
+ }
161
+ exports.writeJsonFileSync = writeJsonFileSync;
162
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/packlets/converters/file.ts"],"names":[],"mappings":"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","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 { Converter, Result, captureResult, fail, mapResults, succeed } from '@fgv/ts-utils';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport { JsonValue } from '../json';\n\n/**\n * Convenience function to read type-safe JSON from a file\n * @param srcPath - Path of the file to read\n * @returns `Success` with a {@link JsonValue | JsonValue} or `Failure`\n * with a message if an error occurs.\n * @public\n */\nexport function readJsonFileSync(srcPath: string): Result<JsonValue> {\n return captureResult(() => {\n const fullPath = path.resolve(srcPath);\n const body = fs.readFileSync(fullPath, 'utf8').toString();\n return JSON.parse(body) as JsonValue;\n });\n}\n\n/**\n * Convenience function to read a JSON file and apply a supplied converter.\n * @param srcPath - Path of the file to read.\n * @param converter - `Converter` used to convert the file contents\n * @returns `Success` with a result of type `<T>`, or `Failure`\n * with a message if an error occurs.\n * @public\n */\nexport function convertJsonFileSync<T>(srcPath: string, converter: Converter<T>): Result<T> {\n return readJsonFileSync(srcPath).onSuccess((json) => {\n return converter.convert(json);\n });\n}\n\n/**\n * Options for directory conversion.\n * TODO: add filtering, allowed and excluded.\n * @public\n */\nexport interface IDirectoryConvertOptions<T, TC = unknown> {\n /**\n * The converter used to convert incoming JSON objects.\n */\n converter: Converter<T, TC>;\n}\n\n/**\n * Return value for one item in a directory conversion.\n * @public\n */\nexport interface IReadDirectoryItem<T> {\n /**\n * Relative name of the file that was processed\n */\n filename: string;\n\n /**\n * The payload of the file.\n */\n item: T;\n}\n\n/**\n * Reads all JSON files from a directory and apply a supplied converter.\n * @param srcPath - The path of the folder to be read.\n * @param options - {@link Files.IDirectoryConvertOptions | Options} to control\n * conversion and filtering\n * @public\n */\nexport function convertJsonDirectorySync<T>(\n srcPath: string,\n options: IDirectoryConvertOptions<T>\n): Result<IReadDirectoryItem<T>[]> {\n return captureResult<IReadDirectoryItem<T>[]>(() => {\n const fullPath = path.resolve(srcPath);\n if (!fs.statSync(fullPath).isDirectory()) {\n throw new Error(`${fullPath}: Not a directory`);\n }\n const files = fs.readdirSync(fullPath, { withFileTypes: true });\n const results = files\n .map((fi) => {\n if (fi.isFile() && path.extname(fi.name) === '.json') {\n const filePath = path.resolve(fullPath, fi.name);\n return convertJsonFileSync(filePath, options.converter)\n .onSuccess((payload) => {\n return succeed({\n filename: fi.name,\n item: payload\n });\n })\n .onFailure((message) => {\n return fail(`${fi.name}: ${message}`);\n });\n }\n return undefined;\n })\n .filter((r): r is Result<IReadDirectoryItem<T>> => r !== undefined);\n return mapResults(results).orThrow();\n });\n}\n\n/**\n * Function to transform the name of a some entity, given an original name\n * and the contents of the entity.\n * @public\n */\nexport type ItemNameTransformFunction<T> = (name: string, item: T) => Result<string>;\n\n/**\n * Options controlling conversion of a directory.\n * @public\n */\nexport interface IDirectoryToMapConvertOptions<T, TC = unknown> extends IDirectoryConvertOptions<T, TC> {\n transformName?: ItemNameTransformFunction<T>;\n}\n\n/**\n * Function to transform the name of some entity, given only a previous name. This\n * default implementation always returns `Success` with the value that was passed in.\n * @param n - The name to be transformed.\n * @returns - `Success` with the string that was passed in.\n * @public\n */\nconst defaultNameTransformer = (n: string): Result<string> => succeed(n);\n\n/**\n * Reads and converts all JSON files from a directory, returning a\n * `Map<string, T>` indexed by file base name (i.e. minus the extension)\n * with an optional name transformation applied if present.\n * @param srcPath - The path of the folder to be read.\n * @param options - {@link Files.IDirectoryToMapConvertOptions | Options} to control conversion,\n * filtering and naming.\n * @public\n */\nexport function convertJsonDirectoryToMapSync<T, TC = unknown>(\n srcPath: string,\n options: IDirectoryToMapConvertOptions<T, TC>\n): Result<Map<string, T>> {\n return convertJsonDirectorySync(srcPath, options).onSuccess((items) => {\n const transformName = options.transformName ?? defaultNameTransformer;\n return mapResults(\n items.map((item) => {\n const basename = path.basename(item.filename, '.json');\n return transformName(basename, item.item).onSuccess((name) => {\n return succeed<[string, T]>([name, item.item]);\n });\n })\n ).onSuccess((items) => {\n return succeed(new Map<string, T>(items));\n });\n });\n}\n\n/**\n * Convenience function to write type-safe JSON to a file.\n * @param srcPath - Path of the file to write.\n * @param value - The {@link JsonValue | JsonValue} to be written.\n * @public\n */\nexport function writeJsonFileSync(srcPath: string, value: JsonValue): Result<boolean> {\n return captureResult(() => {\n const fullPath = path.resolve(srcPath);\n fs.writeFileSync(fullPath, JSON.stringify(value, undefined, 2));\n return true;\n });\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import * as Converters from './converters';
2
+ import * as File from './file';
3
+ export * from './jsonConverter';
4
+ export { Converters, File };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/converters/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAE/B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC"}