@fgv/ts-json 1.9.5 → 2.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) 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/{jsonEditor → lib/packlets/converters}/index.js +10 -10
  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/lib/packlets/editor/index.js +58 -0
  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 +333 -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 +160 -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 +57 -49
  92. package/common.d.ts +0 -58
  93. package/common.js +0 -116
  94. package/contextHelpers.d.ts +0 -21
  95. package/contextHelpers.js +0 -101
  96. package/converters.d.ts +0 -37
  97. package/converters.js +0 -92
  98. package/file.d.ts +0 -60
  99. package/file.js +0 -140
  100. package/index.d.ts +0 -9
  101. package/index.js +0 -61
  102. package/jsonContext.d.ts +0 -74
  103. package/jsonContext.js +0 -40
  104. package/jsonConverter.d.ts +0 -229
  105. package/jsonConverter.js +0 -292
  106. package/jsonEditor/common.d.ts +0 -36
  107. package/jsonEditor/common.js +0 -3
  108. package/jsonEditor/index.d.ts +0 -5
  109. package/jsonEditor/jsonEditor.d.ts +0 -74
  110. package/jsonEditor/jsonEditor.js +0 -259
  111. package/jsonEditor/jsonEditorRule.d.ts +0 -47
  112. package/jsonEditor/jsonEditorRule.js +0 -44
  113. package/jsonEditor/jsonEditorState.d.ts +0 -24
  114. package/jsonEditor/jsonEditorState.js +0 -86
  115. package/jsonEditor/rules/conditional.d.ts +0 -84
  116. package/jsonEditor/rules/conditional.js +0 -146
  117. package/jsonEditor/rules/index.js +0 -21
  118. package/jsonEditor/rules/multivalue.d.ts +0 -78
  119. package/jsonEditor/rules/multivalue.js +0 -129
  120. package/jsonEditor/rules/references.d.ts +0 -62
  121. package/jsonEditor/rules/references.js +0 -158
  122. package/jsonEditor/rules/templates.d.ts +0 -56
  123. package/jsonEditor/rules/templates.js +0 -115
  124. package/jsonReferenceMap.d.ts +0 -182
  125. package/jsonReferenceMap.js +0 -272
@@ -36,9 +36,6 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
36
36
  }) : function(o, v) {
37
37
  o["default"] = v;
38
38
  });
39
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
40
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
41
- };
42
39
  var __importStar = (this && this.__importStar) || function (mod) {
43
40
  if (mod && mod.__esModule) return mod;
44
41
  var result = {};
@@ -46,11 +43,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
46
43
  __setModuleDefault(result, mod);
47
44
  return result;
48
45
  };
46
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
47
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
48
+ };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.Rules = void 0;
51
- __exportStar(require("./common"), exports);
52
- __exportStar(require("./jsonEditorRule"), exports);
53
- __exportStar(require("./jsonEditor"), exports);
54
- __exportStar(require("./jsonEditorState"), exports);
55
- exports.Rules = __importStar(require("./rules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exports.Converters = void 0;
51
+ const Converters = __importStar(require("./converters"));
52
+ exports.Converters = Converters;
53
+ const File = __importStar(require("./file"));
54
+ exports.File = File;
55
+ __exportStar(require("./jsonConverter"), exports);
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/converters/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yDAA2C;AAIlC,gCAAU;AAHnB,6CAA+B;AAGV,oBAAI;AADzB,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';\nimport * as File from './file';\n\nexport * from './jsonConverter';\nexport { Converters, File };\n"]}
@@ -0,0 +1,276 @@
1
+ import { Conversion, Converter, Result } from '@fgv/ts-utils';
2
+ import { IJsonContext, IJsonReferenceMap, TemplateVars, TemplateVarsExtendFunction } from '../context';
3
+ import { JsonArray, JsonObject, JsonValue } from '../json';
4
+ import { JsonEditor } from '../editor';
5
+ /**
6
+ * Conversion options for {@link JsonConverter | JsonConverter}.
7
+ * @public
8
+ */
9
+ export interface IJsonConverterOptions {
10
+ /**
11
+ * If `true` and if template variables are available,
12
+ * then string property values will be rendered using
13
+ * mustache and those variable values. Otherwise string
14
+ * properties are copied without modification.
15
+ *
16
+ * Defaults to `true` if vars are supplied with options,
17
+ * `false` otherwise.
18
+ */
19
+ useValueTemplates: boolean;
20
+ /**
21
+ * If `true` and if template variables are available,
22
+ * then property names will be rendered using
23
+ * mustache and those variable values. Otherwise
24
+ * property names are copied without modification.
25
+ *
26
+ * Defaults to `true` if vars are supplied with options,
27
+ * `false` otherwise.
28
+ */
29
+ useNameTemplates: boolean;
30
+ /**
31
+ * If `true` and if template variables are available,
32
+ * then string property names will be considered for
33
+ * conditionals.
34
+ *
35
+ * Default is to match {@link IJsonConverterOptions.useNameTemplates | useNameTemplates}.
36
+ */
37
+ useConditionalNames: boolean;
38
+ /**
39
+ * If `true` (default) then properties with unconditional names
40
+ * (which start with !) are flattened.
41
+ */
42
+ flattenUnconditionalValues: boolean;
43
+ /**
44
+ * If `true` and if both template variables and a
45
+ * context derivation function is available, then properties
46
+ * which match the multi-value name pattern will be expanded.
47
+ * Default matches {@link IJsonConverterOptions.useNameTemplates | useNameTemplates}.
48
+ *
49
+ * Default is `true` unless {@link IJsonConverterOptions.extendVars | extendVars} is
50
+ * explicitly set to `undefined`.
51
+ */
52
+ useMultiValueTemplateNames: boolean;
53
+ /**
54
+ * The variables (mustache view) used to render templated string names
55
+ * and properties. See the mustache documentation for details of mustache
56
+ * syntax and the template view.
57
+ */
58
+ vars?: TemplateVars;
59
+ /**
60
+ * Method used to extend variables for children of an array node during
61
+ * expansion. Default is to use a built-in extension function unless
62
+ * {@link IJsonConverterOptions.extendVars | extendVars} is explicitly set to undefined.
63
+ */
64
+ extendVars?: TemplateVarsExtendFunction;
65
+ /**
66
+ * If `true` and if a {@link IJsonReferenceMap | references map} is supplied
67
+ * in {@link IJsonConverterOptions.refs | refs}, then references in the source
68
+ * object will be replaced with the corresponding value from the reference map.
69
+ *
70
+ * Default is `true` if {@link IJsonConverterOptions.refs | refs} are present in options,
71
+ * `false` otherwise.
72
+ */
73
+ useReferences: boolean;
74
+ /**
75
+ * An optional {@link IJsonReferenceMap | reference map} used to insert any references
76
+ * in the converted JSON.
77
+ */
78
+ refs?: IJsonReferenceMap;
79
+ /**
80
+ * If {@link IJsonConverterOptions.onInvalidPropertyName | onInvalidPropertyName} is `'error'`
81
+ * (default) then any property name that is invalid after template rendering causes an error
82
+ * and stops conversion. If {@link IJsonConverterOptions.onInvalidPropertyName | onInvalidPropertyName}
83
+ * is `'ignore'`, then names which are invalid after template rendering are passed through unchanged.
84
+ */
85
+ onInvalidPropertyName: 'error' | 'ignore';
86
+ /**
87
+ * If {@link IJsonConverterOptions.onInvalidPropertyValue | onInvalidPropertyValue} is `'error'`
88
+ * (default) then any illegal property value causes an error and stops conversion. If
89
+ * {@link IJsonConverterOptions.onInvalidPropertyValue | onInvalidPropertyValue} is `'ignore'` then
90
+ * any invalid property values are silently ignored.
91
+ */
92
+ onInvalidPropertyValue: 'error' | 'ignore';
93
+ /**
94
+ * If {@link IJsonConverterOptions.onUndefinedPropertyValue | onUndefinedPropertyValue} is `'error'`,
95
+ * then any property with value `undefined` will cause an error and stop conversion. If
96
+ * {@link IJsonConverterOptions.onUndefinedPropertyValue | onUndefinedPropertyValue} is `'ignore'` (default)
97
+ * then any property with value `undefined` is silently ignored.
98
+ */
99
+ onUndefinedPropertyValue: 'error' | 'ignore';
100
+ }
101
+ /**
102
+ * Merges an optionally supplied partial set of {@link IJsonConverterOptions | options} with
103
+ * the default converter options and taking all dynamic rules into account (e.g. template usage enabled
104
+ * if variables are supplied and disabled if not), producing a fully-resolved set of
105
+ * {@link IJsonConverterOptions | IJsonConverterOptions}.
106
+ * @param partial - An optional partial {@link IJsonConverterOptions | IJsonConverterOptions}
107
+ * to be merged.
108
+ * @public
109
+ */
110
+ export declare function mergeDefaultJsonConverterOptions(partial?: Partial<IJsonConverterOptions>): IJsonConverterOptions;
111
+ /**
112
+ * Creates a new {@link IJsonContext | JSON context} using values supplied in an optional partial
113
+ * {@link IJsonConverterOptions | converter options}.
114
+ * @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions} used to
115
+ * populate the context.
116
+ * @public
117
+ */
118
+ export declare function contextFromConverterOptions(partial?: Partial<IJsonConverterOptions>): IJsonContext | undefined;
119
+ /**
120
+ * Creates a new {@link Editor.JsonEditor | JsonEditor} from an optionally supplied partial
121
+ * {@link IJsonConverterOptions | JSON converter options}.
122
+ * Expands supplied options with default values and constructs an editor with
123
+ * matching configuration and defined rules.
124
+ * @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions}
125
+ * used to create the editor.
126
+ * @public
127
+ */
128
+ export declare function converterOptionsToEditor(partial?: Partial<IJsonConverterOptions>): Result<JsonEditor>;
129
+ /**
130
+ * A thin wrapper to allow an arbitrary {@link Editor.JsonEditor | JsonEditor} to be used via the
131
+ * \@fgv/ts-utils `Converter` pattern.
132
+ * @public
133
+ */
134
+ export declare class JsonEditorConverter extends Conversion.BaseConverter<JsonValue, IJsonContext> {
135
+ readonly editor: JsonEditor;
136
+ /**
137
+ * Constructs a new {@link Editor.JsonEditor | JsonEditor}Converter which uses the supplied editor
138
+ * @param editor -
139
+ */
140
+ constructor(editor: JsonEditor);
141
+ /**
142
+ * Constructs a new {@link Editor.JsonEditor | JsonEditor}Converter which uses the supplied editor
143
+ * @param editor -
144
+ */
145
+ static createWithEditor(editor: JsonEditor): Result<JsonEditorConverter>;
146
+ /**
147
+ * Gets a derived converter which fails if the resulting converted
148
+ * {@link JsonValue | JsonValue} is not a {@link JsonObject | JsonObject}.
149
+ */
150
+ object(): Converter<JsonObject, IJsonContext>;
151
+ /**
152
+ * Gets a derived converter which fails if the resulting converted
153
+ * {@link JsonValue | JsonValue} is not a {@link JsonArray | JsonArray}.
154
+ */
155
+ array(): Converter<JsonArray, IJsonContext>;
156
+ protected _convert(from: unknown, context?: IJsonContext): Result<JsonValue>;
157
+ }
158
+ /**
159
+ * An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON, optionally
160
+ * rendering any string property names or values using mustache with a supplied view.
161
+ * @public
162
+ */
163
+ export declare class JsonConverter extends JsonEditorConverter {
164
+ /**
165
+ * Constructs a new {@link JsonConverter | JsonConverter} with
166
+ * supplied or default options.
167
+ * @param options - Optional partial {@link IJsonConverterOptions | options}
168
+ * to configure the converter.
169
+ */
170
+ constructor(options?: Partial<IJsonConverterOptions>);
171
+ /**
172
+ * Creates a new {@link JsonConverter | JsonConverter}.
173
+ * @param options - Optional partial {@link IJsonConverterOptions | options}
174
+ * to configure the converter.
175
+ * @returns `Success` with a new {@link JsonConverter | JsonConverter}, or `Failure`
176
+ * with an informative message if an error occurs.
177
+ */
178
+ static create(options?: Partial<IJsonConverterOptions>): Result<JsonConverter>;
179
+ }
180
+ /**
181
+ * Initialization options for a {@link TemplatedJsonConverter | TemplatedJsonConverter}.
182
+ * @public
183
+ */
184
+ export type TemplatedJsonConverterOptions = Omit<IJsonConverterOptions, 'useNameTemplates' | 'useValueTemplates' | 'useMultiValueTemplateNames'>;
185
+ /**
186
+ * An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON
187
+ * with mustache template rendering and multi-value property name rules enabled
188
+ * regardless of initial context.
189
+ * @public
190
+ */
191
+ export declare class TemplatedJsonConverter extends JsonEditorConverter {
192
+ /**
193
+ * Default {@link IJsonConverterOptions | JSON converter options}
194
+ * to enable templated conversion.
195
+ */
196
+ static readonly templateOptions: Partial<IJsonConverterOptions>;
197
+ /**
198
+ * Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with
199
+ * supplied or default options.
200
+ * @param options - Optional partial {@link TemplatedJsonConverterOptions | options}
201
+ * to configure the converter.
202
+ */
203
+ constructor(options?: Partial<TemplatedJsonConverterOptions>);
204
+ /**
205
+ * Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with
206
+ * supplied or default options.
207
+ * @param options - Optional partial {@link TemplatedJsonConverterOptions | options}
208
+ * to configure the converter.
209
+ */
210
+ static create(options?: Partial<TemplatedJsonConverterOptions>): Result<JsonConverter>;
211
+ }
212
+ /**
213
+ * Options for a {@link ConditionalJsonConverter | ConditionalJsonConverter}.
214
+ * @public
215
+ */
216
+ export type ConditionalJsonConverterOptions = Omit<TemplatedJsonConverterOptions, 'useConditionalNames'>;
217
+ /**
218
+ * An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache
219
+ * template rendering, multi-value property name and conditional property
220
+ * name rules enabled regardless of initial context.
221
+ * @public
222
+ */
223
+ export declare class ConditionalJsonConverter extends JsonEditorConverter {
224
+ /**
225
+ * Default {@link IJsonConverterOptions | JSON converter options}
226
+ * to enable conditional conversion.
227
+ */
228
+ static readonly conditionalOptions: Partial<IJsonConverterOptions>;
229
+ /**
230
+ * Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or
231
+ * default options.
232
+ * @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}
233
+ * for the converter.
234
+ */
235
+ constructor(options?: Partial<ConditionalJsonConverterOptions>);
236
+ /**
237
+ * Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or
238
+ * default options.
239
+ * @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}
240
+ * for the converter.
241
+ */
242
+ static create(options?: Partial<ConditionalJsonConverterOptions>): Result<JsonConverter>;
243
+ }
244
+ /**
245
+ * Initialization options for a {@link RichJsonConverter | RichJsonConverter}.
246
+ * @public
247
+ */
248
+ export type RichJsonConverterOptions = Omit<ConditionalJsonConverterOptions, 'useReferences'>;
249
+ /**
250
+ * A \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache
251
+ * template rendering, multi-value property name, conditional property
252
+ * name, and external reference rules enabled regardless of initial context.
253
+ * @public
254
+ */
255
+ export declare class RichJsonConverter extends JsonEditorConverter {
256
+ /**
257
+ * Default {@link IJsonConverterOptions | JSON converter options}
258
+ * to enable rich conversion.
259
+ */
260
+ static readonly richOptions: Partial<IJsonConverterOptions>;
261
+ /**
262
+ * Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or
263
+ * default options.
264
+ * @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}
265
+ * for the converter.
266
+ */
267
+ constructor(options?: Partial<RichJsonConverterOptions>);
268
+ /**
269
+ * Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or
270
+ * default options
271
+ * @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}
272
+ * for the converter.
273
+ */
274
+ static create(options?: Partial<RichJsonConverterOptions>): Result<JsonConverter>;
275
+ }
276
+ //# sourceMappingURL=jsonConverter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonConverter.d.ts","sourceRoot":"","sources":["../../../src/packlets/converters/jsonConverter.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAgC,MAAM,eAAe,CAAC;AAC5F,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,0BAA0B,EAE3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAgB,MAAM,SAAS,CAAC;AAEzE,OAAO,EAAoD,UAAU,EAAE,MAAM,WAAW,CAAC;AAEzF;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;OAQG;IACH,iBAAiB,EAAE,OAAO,CAAC;IAE3B;;;;;;;;OAQG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAE1B;;;;;;OAMG;IACH,mBAAmB,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,0BAA0B,EAAE,OAAO,CAAC;IAEpC;;;;;;;;OAQG;IACH,0BAA0B,EAAE,OAAO,CAAC;IA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Aa,iBAAkB,SAAQ,mBAAmB;IACxD;;;OAGG;IACH,gBAAuB,WAAW,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAGhE;IAEF;;;;;OAKG;gBACgB,OAAO,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC;IAM9D;;;;;OAKG;WACW,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC;CAGzF"}
@@ -0,0 +1,310 @@
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.RichJsonConverter = exports.ConditionalJsonConverter = exports.TemplatedJsonConverter = exports.JsonConverter = exports.JsonEditorConverter = exports.converterOptionsToEditor = exports.contextFromConverterOptions = exports.mergeDefaultJsonConverterOptions = void 0;
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ const context_1 = require("../context");
27
+ const json_1 = require("../json");
28
+ const editor_1 = require("../editor");
29
+ /**
30
+ * Merges an optionally supplied partial set of {@link IJsonConverterOptions | options} with
31
+ * the default converter options and taking all dynamic rules into account (e.g. template usage enabled
32
+ * if variables are supplied and disabled if not), producing a fully-resolved set of
33
+ * {@link IJsonConverterOptions | IJsonConverterOptions}.
34
+ * @param partial - An optional partial {@link IJsonConverterOptions | IJsonConverterOptions}
35
+ * to be merged.
36
+ * @public
37
+ */
38
+ function mergeDefaultJsonConverterOptions(partial) {
39
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
40
+ const haveVars = (partial === null || partial === void 0 ? void 0 : partial.vars) !== undefined;
41
+ const haveRefs = (partial === null || partial === void 0 ? void 0 : partial.refs) !== undefined;
42
+ const extender = (partial === null || partial === void 0 ? void 0 : partial.hasOwnProperty('extendVars')) ? partial.extendVars : context_1.defaultExtendVars;
43
+ const haveExtender = extender !== undefined;
44
+ const namesDefault = (_a = partial === null || partial === void 0 ? void 0 : partial.useNameTemplates) !== null && _a !== void 0 ? _a : haveVars;
45
+ const conditionsDefault = (_b = partial === null || partial === void 0 ? void 0 : partial.useConditionalNames) !== null && _b !== void 0 ? _b : namesDefault;
46
+ const options = {
47
+ useValueTemplates: (_c = partial === null || partial === void 0 ? void 0 : partial.useValueTemplates) !== null && _c !== void 0 ? _c : haveVars,
48
+ useNameTemplates: namesDefault,
49
+ useConditionalNames: conditionsDefault,
50
+ flattenUnconditionalValues: (_d = partial === null || partial === void 0 ? void 0 : partial.flattenUnconditionalValues) !== null && _d !== void 0 ? _d : conditionsDefault,
51
+ useMultiValueTemplateNames: (_e = partial === null || partial === void 0 ? void 0 : partial.useMultiValueTemplateNames) !== null && _e !== void 0 ? _e : (haveExtender && namesDefault),
52
+ useReferences: (_f = partial === null || partial === void 0 ? void 0 : partial.useReferences) !== null && _f !== void 0 ? _f : haveRefs,
53
+ onInvalidPropertyName: (_g = partial === null || partial === void 0 ? void 0 : partial.onInvalidPropertyName) !== null && _g !== void 0 ? _g : 'error',
54
+ onInvalidPropertyValue: (_h = partial === null || partial === void 0 ? void 0 : partial.onInvalidPropertyValue) !== null && _h !== void 0 ? _h : 'error',
55
+ onUndefinedPropertyValue: (_j = partial === null || partial === void 0 ? void 0 : partial.onUndefinedPropertyValue) !== null && _j !== void 0 ? _j : 'ignore',
56
+ extendVars: extender
57
+ };
58
+ if (partial === null || partial === void 0 ? void 0 : partial.vars) {
59
+ options.vars = partial.vars;
60
+ }
61
+ if (partial === null || partial === void 0 ? void 0 : partial.refs) {
62
+ options.refs = partial.refs;
63
+ }
64
+ return options;
65
+ }
66
+ exports.mergeDefaultJsonConverterOptions = mergeDefaultJsonConverterOptions;
67
+ /**
68
+ * Creates a new {@link IJsonContext | JSON context} using values supplied in an optional partial
69
+ * {@link IJsonConverterOptions | converter options}.
70
+ * @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions} used to
71
+ * populate the context.
72
+ * @public
73
+ */
74
+ function contextFromConverterOptions(partial) {
75
+ const context = {};
76
+ if (partial === null || partial === void 0 ? void 0 : partial.vars) {
77
+ context.vars = partial.vars;
78
+ }
79
+ if (partial === null || partial === void 0 ? void 0 : partial.refs) {
80
+ context.refs = partial.refs;
81
+ }
82
+ if (partial === null || partial === void 0 ? void 0 : partial.hasOwnProperty('extendVars')) {
83
+ context.extendVars = partial.extendVars;
84
+ }
85
+ return context.vars || context.refs || context.extendVars ? context : undefined;
86
+ }
87
+ exports.contextFromConverterOptions = contextFromConverterOptions;
88
+ /**
89
+ * Creates a new {@link Editor.JsonEditor | JsonEditor} from an optionally supplied partial
90
+ * {@link IJsonConverterOptions | JSON converter options}.
91
+ * Expands supplied options with default values and constructs an editor with
92
+ * matching configuration and defined rules.
93
+ * @param partial - Optional partial {@link IJsonConverterOptions | IJsonConverterOptions}
94
+ * used to create the editor.
95
+ * @public
96
+ */
97
+ function converterOptionsToEditor(partial) {
98
+ const converterOptions = mergeDefaultJsonConverterOptions(partial);
99
+ const context = contextFromConverterOptions(partial);
100
+ const validation = {
101
+ onInvalidPropertyName: converterOptions.onInvalidPropertyName,
102
+ onInvalidPropertyValue: converterOptions.onInvalidPropertyValue,
103
+ onUndefinedPropertyValue: converterOptions.onUndefinedPropertyValue
104
+ };
105
+ const editorOptions = { context, validation };
106
+ const rules = [];
107
+ if (converterOptions.useNameTemplates || converterOptions.useValueTemplates) {
108
+ const templateOptions = Object.assign(Object.assign({}, editorOptions), { useNameTemplates: converterOptions.useNameTemplates, useValueTemplates: converterOptions.useValueTemplates });
109
+ rules.push(new editor_1.EditorRules.TemplatedJsonEditorRule(templateOptions));
110
+ }
111
+ if (converterOptions.useConditionalNames || converterOptions.flattenUnconditionalValues) {
112
+ const conditionalOptions = Object.assign(Object.assign({}, editorOptions), { flattenUnconditionalValues: converterOptions.flattenUnconditionalValues });
113
+ rules.push(new editor_1.EditorRules.ConditionalJsonEditorRule(conditionalOptions));
114
+ }
115
+ if (converterOptions.useMultiValueTemplateNames) {
116
+ rules.push(new editor_1.EditorRules.MultiValueJsonEditorRule(editorOptions));
117
+ }
118
+ if (converterOptions.useReferences) {
119
+ rules.push(new editor_1.EditorRules.ReferenceJsonEditorRule(editorOptions));
120
+ }
121
+ return editor_1.JsonEditor.create(editorOptions, rules);
122
+ }
123
+ exports.converterOptionsToEditor = converterOptionsToEditor;
124
+ /**
125
+ * A thin wrapper to allow an arbitrary {@link Editor.JsonEditor | JsonEditor} to be used via the
126
+ * \@fgv/ts-utils `Converter` pattern.
127
+ * @public
128
+ */
129
+ class JsonEditorConverter extends ts_utils_1.Conversion.BaseConverter {
130
+ /**
131
+ * Constructs a new {@link Editor.JsonEditor | JsonEditor}Converter which uses the supplied editor
132
+ * @param editor -
133
+ */
134
+ constructor(editor) {
135
+ super((from, __self, context) => this._convert(from, context), editor.options.context);
136
+ this.editor = editor;
137
+ }
138
+ /**
139
+ * Constructs a new {@link Editor.JsonEditor | JsonEditor}Converter which uses the supplied editor
140
+ * @param editor -
141
+ */
142
+ static createWithEditor(editor) {
143
+ return (0, ts_utils_1.captureResult)(() => new JsonEditorConverter(editor));
144
+ }
145
+ /**
146
+ * Gets a derived converter which fails if the resulting converted
147
+ * {@link JsonValue | JsonValue} is not a {@link JsonObject | JsonObject}.
148
+ */
149
+ object() {
150
+ return this.map((jv) => {
151
+ if (!(0, json_1.isJsonObject)(jv)) {
152
+ return (0, ts_utils_1.fail)(`Cannot convert "${JSON.stringify(jv)}" to JSON object.`);
153
+ }
154
+ return (0, ts_utils_1.succeed)(jv);
155
+ });
156
+ }
157
+ /**
158
+ * Gets a derived converter which fails if the resulting converted
159
+ * {@link JsonValue | JsonValue} is not a {@link JsonArray | JsonArray}.
160
+ */
161
+ array() {
162
+ return this.map((jv) => {
163
+ if (!Array.isArray(jv) || typeof jv !== 'object') {
164
+ return (0, ts_utils_1.fail)(`Cannot convert "${JSON.stringify(jv)}" to JSON array.`);
165
+ }
166
+ return (0, ts_utils_1.succeed)(jv);
167
+ });
168
+ }
169
+ _convert(from, context) {
170
+ return this.editor.clone(from, context);
171
+ }
172
+ }
173
+ exports.JsonEditorConverter = JsonEditorConverter;
174
+ /**
175
+ * An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON, optionally
176
+ * rendering any string property names or values using mustache with a supplied view.
177
+ * @public
178
+ */
179
+ class JsonConverter extends JsonEditorConverter {
180
+ /**
181
+ * Constructs a new {@link JsonConverter | JsonConverter} with
182
+ * supplied or default options.
183
+ * @param options - Optional partial {@link IJsonConverterOptions | options}
184
+ * to configure the converter.
185
+ */
186
+ constructor(options) {
187
+ const editor = converterOptionsToEditor(options).orThrow();
188
+ super(editor);
189
+ }
190
+ /**
191
+ * Creates a new {@link JsonConverter | JsonConverter}.
192
+ * @param options - Optional partial {@link IJsonConverterOptions | options}
193
+ * to configure the converter.
194
+ * @returns `Success` with a new {@link JsonConverter | JsonConverter}, or `Failure`
195
+ * with an informative message if an error occurs.
196
+ */
197
+ static create(options) {
198
+ return (0, ts_utils_1.captureResult)(() => new JsonConverter(options));
199
+ }
200
+ }
201
+ exports.JsonConverter = JsonConverter;
202
+ /**
203
+ * An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON
204
+ * with mustache template rendering and multi-value property name rules enabled
205
+ * regardless of initial context.
206
+ * @public
207
+ */
208
+ class TemplatedJsonConverter extends JsonEditorConverter {
209
+ /**
210
+ * Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with
211
+ * supplied or default options.
212
+ * @param options - Optional partial {@link TemplatedJsonConverterOptions | options}
213
+ * to configure the converter.
214
+ */
215
+ constructor(options) {
216
+ options = Object.assign(Object.assign({}, options), TemplatedJsonConverter.templateOptions);
217
+ const editor = converterOptionsToEditor(options).orThrow();
218
+ super(editor);
219
+ }
220
+ /**
221
+ * Constructs a new {@link TemplatedJsonConverter | TemplatedJsonConverter} with
222
+ * supplied or default options.
223
+ * @param options - Optional partial {@link TemplatedJsonConverterOptions | options}
224
+ * to configure the converter.
225
+ */
226
+ static create(options) {
227
+ return (0, ts_utils_1.captureResult)(() => new TemplatedJsonConverter(options));
228
+ }
229
+ }
230
+ /**
231
+ * Default {@link IJsonConverterOptions | JSON converter options}
232
+ * to enable templated conversion.
233
+ */
234
+ TemplatedJsonConverter.templateOptions = {
235
+ useNameTemplates: true,
236
+ useValueTemplates: true,
237
+ useMultiValueTemplateNames: true,
238
+ useConditionalNames: false,
239
+ flattenUnconditionalValues: false
240
+ };
241
+ exports.TemplatedJsonConverter = TemplatedJsonConverter;
242
+ /**
243
+ * An \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache
244
+ * template rendering, multi-value property name and conditional property
245
+ * name rules enabled regardless of initial context.
246
+ * @public
247
+ */
248
+ class ConditionalJsonConverter extends JsonEditorConverter {
249
+ /**
250
+ * Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or
251
+ * default options.
252
+ * @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}
253
+ * for the converter.
254
+ */
255
+ constructor(options) {
256
+ options = Object.assign(Object.assign({}, options), ConditionalJsonConverter.conditionalOptions);
257
+ const editor = converterOptionsToEditor(options).orThrow();
258
+ super(editor);
259
+ }
260
+ /**
261
+ * Constructs a new {@link ConditionalJsonConverter | ConditionalJsonConverter} with supplied or
262
+ * default options.
263
+ * @param options - Optional partial {@link ConditionalJsonConverterOptions | configuration or context}
264
+ * for the converter.
265
+ */
266
+ static create(options) {
267
+ return (0, ts_utils_1.captureResult)(() => new ConditionalJsonConverter(options));
268
+ }
269
+ }
270
+ /**
271
+ * Default {@link IJsonConverterOptions | JSON converter options}
272
+ * to enable conditional conversion.
273
+ */
274
+ ConditionalJsonConverter.conditionalOptions = Object.assign(Object.assign({}, TemplatedJsonConverter.templateOptions), { useConditionalNames: true, flattenUnconditionalValues: true });
275
+ exports.ConditionalJsonConverter = ConditionalJsonConverter;
276
+ /**
277
+ * A \@fgv/ts-utils `Converter` from `unknown` to type-safe JSON with mustache
278
+ * template rendering, multi-value property name, conditional property
279
+ * name, and external reference rules enabled regardless of initial context.
280
+ * @public
281
+ */
282
+ class RichJsonConverter extends JsonEditorConverter {
283
+ /**
284
+ * Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or
285
+ * default options.
286
+ * @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}
287
+ * for the converter.
288
+ */
289
+ constructor(options) {
290
+ options = Object.assign(Object.assign({}, options), RichJsonConverter.richOptions);
291
+ const editor = converterOptionsToEditor(options).orThrow();
292
+ super(editor);
293
+ }
294
+ /**
295
+ * Constructs a new {@link RichJsonConverter | RichJsonConverter} with supplied or
296
+ * default options
297
+ * @param options - Optional partial {@link RichJsonConverterOptions | configuration or context}
298
+ * for the converter.
299
+ */
300
+ static create(options) {
301
+ return (0, ts_utils_1.captureResult)(() => new RichJsonConverter(options));
302
+ }
303
+ }
304
+ /**
305
+ * Default {@link IJsonConverterOptions | JSON converter options}
306
+ * to enable rich conversion.
307
+ */
308
+ RichJsonConverter.richOptions = Object.assign(Object.assign({}, ConditionalJsonConverter.conditionalOptions), { useReferences: true });
309
+ exports.RichJsonConverter = RichJsonConverter;
310
+ //# sourceMappingURL=jsonConverter.js.map